n, k = map(int, input().split())
x = list(map(int, input().split()))

for i in range(n):
    if x[i] >= 0:
        ori = i
        break

f_inf = float("inf")
res = f_inf
for i in range(max(ori - k, 0), min(ori + k, n) - k + 1):
    time = abs(0 - x[i]) + abs(x[i + k - 1] - x[i])
    res = min(res, time)

print(res)

n, k = map(int, input().split())
x = list(map(int, input().split()))

if x[0] >= 0:
    print(x[k - 1])
    exit()
elif x[n - 1] < 0:
    print(abs(x[n - k]))
    exit()
else:
    for i in range(n):
        if x[i] >= 0:
            ori = i
            break

f_inf = float("inf")
res = f_inf
for i in range(max(ori - k, 0), min(ori + k, n) - k + 1):
    time = min(
        abs(x[i + k - 1] - x[i]) + abs(x[i + k - 1]),
        abs(x[i]) + abs(x[i + k - 1] - x[i]),
    )
    res = min(res, time)

print(res)


from bisect import bisect_left

n, k = map(int, input().split())
x = list(map(int, input().split()))
# if 0 in x:
#     x.remove(0)
#     k -= 1
#     n -= 1
#
# if n == 0:
#     print(0)

si = bisect_left(x, 0)

ans = x[-1] - x[0]
if si + k - 1 < len(x):
    ans = min(ans, x[si + k - 1])
if si - k >= 0:
    ans = min(ans, abs(x[si - k]))

for i in range(n):
    tmp_ans = 0
    if i < si:
        tmp_ans = abs(x[i]) * 2 + x[i + k - 1]
        ans = min(ans, tmp_ans)
    elif i - k + 1 >= 0:
        tmp_ans = x[i] * 2 + abs(x[i - k + 1])
        ans = min(ans, tmp_ans)

print(ans)

from bisect import bisect_left

n, k = map(int, input().split())
x = list(map(int, input().split()))
if 0 in x:
    x.remove(0)
    k -= 1
    n -= 1

if n == 0:
    print(0)
else:
    si = bisect_left(x, 0)

    ans = (x[-1] - x[0]) * 2
    if si + k - 1 < len(x):
        ans = min(ans, x[si + k - 1])
    if si - k >= 0:
        ans = min(ans, abs(x[si - k]))

    for i in range(n):
        tmp_ans = 0
        if i < si and i + k - 1 < len(x):
            tmp_ans = abs(x[i]) * 2 + x[i + k - 1]
            ans = min(ans, tmp_ans)
        elif i >= si and i - k + 1 >= 0:
            tmp_ans = x[i] * 2 + abs(x[i - k + 1])
            ans = min(ans, tmp_ans)

    print(ans)


N, K = map(int, input().split())
A = list(map(int, input().split()))
ans = ((N - 1) + (K - 1 - 1)) // (K - 1)
print(ans)

import numpy as np

N, K = map(int, input().split())
X = np.array(list(map(int, input().split())))
idx = np.searchsorted(X, 0)
# print('idx', idx)
ans = 10**10
for i in range(N - K + 1):
    l = i
    r = i + K - 1
    d1 = np.abs(X[l]) + np.abs(X[r] - X[l])
    d2 = np.abs(X[r]) + np.abs(X[r] - X[l])
    d = min(d1, d2)
    ans = min(ans, d)
print(ans)


a = int(input())
b = int(input())

ans = (a - 1) * (b - 1)
print(ans)

a, b = map(int, input().split())

ans = (a - 1) * (b - 1)
print(ans)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03280/Python/s458869287.py", line 1, in <module>
    a = int(input())
ValueError: invalid literal for int() with base 10: '2 2'


a = int(input())
b = int(input())

total = a * b - (a + b - 1)

print(total)

a, b = list(map(int, input().split()))

total = a * b - (a + b - 1)

print(total)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03280/Python/s569302437.py", line 1, in <module>
    a = int(input())
ValueError: invalid literal for int() with base 10: '2 2'


number = int(input())

num_eight_divisors = 0

numbers = list(range(9, number + 1, 2))

for i in range(9, number + 1, 2):
    divisors = [1, i]

    for j in range(2, i):
        q, mod = divmod(i, j)

        if mod == 0:
            divisors.append(j, q)

    if len(set(divisors)):
        num_eight_divisors = num_eight_divisors + 1

print(num_eight_divisors)

number = int(input())

num_eight_divisors = 0

numbers = list(range(9, number + 1, 2))

for i in range(9, number + 1, 2):
    divisors = [1, i]

    for j in range(2, i):
        q, mod = divmod(i, j)

        if mod == 0:
            divisors.append(j)
            divisors.append(q)

    if len(set(divisors)) == 8:
        num_eight_divisors = num_eight_divisors + 1

print(num_eight_divisors)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03281/Python/s888176624.py", line 14, in <module>
    divisors.append(j, q)
TypeError: list.append() takes exactly one argument (2 given)


# -*- coding: utf-8 -*-
# モジュールのインポート
import sympy as sp

# 標準入力を取得
N = int(input())

# 求解処理
ans = 0
for n in range(1, N + 1, 2):
    if sp.divisor_count(n) == 8:
        ans += 1

# 結果出力
print(ans)

# -*- coding: utf-8 -*-
# 標準入力を取得
N = int(input())

def divisor_count(n: int) -> int:
    ans = 0
    i = 1
    while i * i <= n:
        if n % i == 0:
            ans += 1
            if i != n // i:
                ans += 1
        i += 1
    return ans

# 求解処理
ans = 0
for n in range(1, N + 1, 2):
    if divisor_count(n) == 8:
        ans += 1

# 結果出力
print(ans)


s = input()
k = int(input())

for i in range(len(s)):
    if s[i] == "1":
        continue
    else:
        ans = s[i]
        break
    ans = "1"

print(ans)

s = input()
k = int(input())

len1s = 0
for i in range(len(s)):
    if s[i] == "1":
        len1s += 1
        continue
    else:
        res = s[i]
        break
else:
    res = "1"

if k <= len1s:
    ans = "1"
else:
    ans = res

print(ans)


S = input()
K = int(input())
key = 1
i = 0
while True:
    if i > 100:
        break
    if int(S[i]) != 1:
        print(S[i])
        key = 1
        break
    i += 1

if key == 0:
    print(S[0])

S = input()
K = int(input())
key = 0
i = 0
while True:
    if i >= K:
        break
    if i >= len(S):
        break
    if int(S[i]) != 1:
        print(S[i])
        key = 1
        break
    i += 1

if key == 0:
    print(S[0])


list_s = list(str(input()))
k = int(input())
for i in range(len(list_s)):
    if list_s[i] != "1":
        bord = i
        break
if k <= bord:
    print(1)
else:
    print(list_s[i])

list_s = list(str(input()))
k = int(input())
bord = 10**9
for i in range(len(list_s)):
    if list_s[i] != "1":
        bord = i
        break
if k <= bord:
    print(1)
else:
    print(list_s[i])


S = input()
K = int(input())

answer = S[1]
print(answer)

S = input()
K = int(input())

are_all_one = True
for i in range(len(S)):
    if S[i] != "1":
        are_all_one = False
        break

nth = i + 1
if are_all_one or K < nth:
    print(1)
    exit()

answer = S[i]
print(answer)


S = input()
K = int(input())

count = 0
while True:
    if S[count] == "1":
        count += 1
    else:
        break

if K > count:
    print(S[count])
else:
    print(1)

S = input()
K = int(input())

count = 0
while count < len(S):
    if S[count] == "1":
        count += 1
    else:
        break
if K > count:
    print(S[count])
else:
    print(1)


s = input()
k = int(input())
onesum = 0
while s[0] == "1" and len(s) > 0:
    s = s[1:]
    onesum += 1
if k <= onesum:
    print(1)
else:
    print(s[0])

s = input()
k = int(input())
onesum = 0
while s[0] == "1":
    onesum += 1
    if len(s) == 1:
        break
    s = s[1:]
if k <= onesum:
    print(1)
else:
    print(s[0])


S = input()
K = int(input())

ans = 1

for i in range(len(S)):
    if int(S[i]) == 1:
        pass
    else:
        ans = int(S[i])
        ones = i
        break

if not ones:
    ones = len(S) + 1
elif K <= ones:
    ans = 1

print(ans)

S = input()
K = int(input())

# S = "111111111"
# K = 6565

ans = 1
ones = -1

for i in range(len(S)):
    if int(S[i]) == 1:
        pass
    else:
        ans = int(S[i])
        ones = i
        break

if ones == -1:
    ones = len(S) + 1

if K <= ones:
    ans = 1

print(ans)


import sys

S = [int(_) for _ in list(input())]
K = int(input())
t = 0
while t <= len(S):
    if S[t] == 1:
        t += 1
    else:
        break

if K <= t:
    print(1)
    sys.exit()
else:
    print(S[t])
    sys.exit()

import sys

S = [int(_) for _ in list(input())]
K = int(input())
t = 0
while t <= len(S) - 1:
    if S[t] == 1:
        t += 1
    else:
        break

if K <= t:
    print(1)
    sys.exit()
else:
    print(S[t])
    sys.exit()


# -*- coding: utf-8 -*-
"""
Created on Sat May  9 16:54:06 2020

@author: shinba
"""

s = input()
k = int(input())

cnt = 0

while s[cnt] == "1":
    cnt += 1

if cnt >= k:
    print(1)
else:
    print(s[cnt])

# -*- coding: utf-8 -*-
"""
Created on Sat May  9 16:54:06 2020

@author: shinba
"""

s = input()
k = int(input())

cnt = 0

while s[cnt] == "1":
    cnt += 1
    if cnt == len(s):
        break

if cnt >= k:
    print(1)
else:
    print(s[cnt])


s = list(input())
k = int(input())
number = 0
count = 0
for i in range(k):
    if s[i] == "1":
        count += 1
        if count == k - 1:
            number = 1
    elif s[i] != "1" and number == 0:
        number = s[i]
print(number)

s = list(input())
k = int(input())
for i in range(min(len(s), k)):
    if s[i] != "1":
        print(s[i])
        exit()
print(1)


s = input()
k = int(input())

for i in range(min(k, len(s))):
    if s[i] != "1":
        ans = s[i]
        break

print(ans)

s = input()
k = int(input())

ans = s[0]
for i in range(min(k, len(s))):
    if s[i] != "1":
        ans = s[i]
        break

print(ans)


S = input()
K = int(input())
ret = "1"
for i in K:
    if len(S) <= K:
        break
    if S[i] != "1":
        ret = S[i]
        break
print(ret)

S = input()
K = int(input())
ret = "1"
for i in range(K):
    if len(S) < i - 1:
        break
    if S[i] != "1":
        ret = S[i]
        break
print(ret)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03282/Python/s935785504.py", line 4, in <module>
    for i in K:
TypeError: 'int' object is not iterable


S = list(input())
K = int(input())
if not S[0] == "1":
    print(S[0])
else:
    print(S[1])

def searchInf(s, k):
    l = k if len(s) >= k else len(s)
    for i in range(l):
        if s[i] == "1":
            continue
        else:
            print(s[i])
            return 0
    print(1)
    return 0

S = list(input())
K = int(input())
searchInf(S, K)


S = str(input())
k = int(input())
if len(S) == 1:
    print(S)
    exit()
for i in range(10):
    if S[i] == "1" and int(S[i]) == k:
        print("1")
        break
    elif S[i] != "1":
        print(S[i])
        break

S = str(input())
k = int(input())
for i in range(k):
    if S[i] != "1":
        print(S[i])
        exit()
print("1")


S = input()
K = int(input())
if S[0] != "1":
    print(S[0])
else:
    ind = 1
    while S[ind] == "1" and ind < len(S) - 1:
        ind += 1
    if ind < K:
        print(S[ind])
    else:
        print("1")

S = input()
K = int(input())
if S[0] != "1":
    print(S[0])
else:
    ind = 0
    while S[ind] == "1" and ind < len(S) - 1:
        ind += 1
    if ind < K:
        print(S[ind])
    else:
        print("1")


S = input()
K = int(input())
if S[0] == "1":
    print(list(set(S))[1])
else:
    print(S[0])

S = input()
K = int(input())
if K == S[:K].count("1"):
    print(1)
else:
    for c in S:
        if c != "1":
            print(c)
            break


s = input()
if "1" == s[0]:
    print(s.replace("1", "")[0])
else:
    print(s[0])

s = input()
k = int(input())
rep = s.replace("1", "")
if len(rep) == 0:
    print("1")
else:
    if s.index(rep[0]) < k:
        print(rep[0])
    else:
        print("1")


S = str(input())
K = int(input())
if S.count("1") == S(len):
    print(1)
    exit(0)
for s in S:
    if s != "1":
        print(s)
        exit()

S = str(input())
K = int(input())
for i in range(0, K):
    if S[i] != "1":
        print(S[i])
        exit()
print(1)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03282/Python/s709061193.py", line 3, in <module>
    if S.count("1") == S(len):
TypeError: 'str' object is not callable


S = input()
S_list = list(map(int, S.split()))
K = int(input())

S_set_under_K = set(S[:K])

if len(S_set_under_K) == 1 and S_list[0] == 1:
    print(1)
else:
    print(S_list[1])

S = input()
S_list = list(map(int, list(S)))
K = int(input())

S_set_under_K = set(S[:K])

if len(S) == 1:
    print(S)
elif len(S_set_under_K) == 1 and S_list[0] == 1:
    print(1)
else:
    for c in S:
        if c != "1":
            print(c)
            exit()

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03282/Python/s272308200.py", line 10, in <module>
    print(S_list[1])
IndexError: list index out of range


def solve():
    s = input()
    return [c for c in s if c != "1"][0]

if __name__ == "__main__":
    print(solve())

def solve():
    s = input()
    k = int(input())
    head_ones = 0
    for c in s:
        if c != "1":
            break
        else:
            head_ones += 1

    return "1" if head_ones >= k else [c for c in s if c != "1"][0]

if __name__ == "__main__":
    print(solve())


S = str(input())
K = int(input())

if K == 1:
    print(S[0])
elif K >= 2:
    if S[0] != "1":
        print(S[0])
        quit()
    elif S[0:K] == "1" * K:
        print(S[0])
        quit()
    else:
        i = 1
        while S[i] == "1" and len(S) - 2 >= i:
            i += 1
        print(S[i])

S = list(input())
K = int(input())
if K == 1:
    print(S[0])
    quit()

for i in range(K):
    if S[i] != "1":
        print(S[i])
        quit()

print("1")


S = input()
K = int(input())
flag = True

for i in range(K):
    if S[i] != 1:
        print(S[i])
        flag = False

if flag:
    print(1)

S = input()
K = int(input())
flag = True

for i in range(K):
    if S[i] != "1":
        print(S[i])
        flag = False
        break

if flag:
    print(1)


import re

S = input()
K = int(input()[:4])

n1i = re.search("[2-9]", S).start()

print(S[min(n1i, K - 1)])

import re

S = input()
K = int(input())

n1 = re.search("[2-9]", S)
if not n1:
    print("1")
    exit()

n1i = n1.start()
print(S[min(n1i, K - 1)])


s = list(map(int, list(input())))
k = int(input())

if s[0] == 1:
    print(s[1])
else:
    print(s[0])

s = list(map(int, list(input())))
k = int(input())
ans = 1

if len(s) <= k:
    for i in s:
        if i != 1:
            ans = i
            break
else:
    for i in range(0, k):
        if s[i] != 1:
            ans = s[i]
            break

print(ans)


s = input()
k = int(input())

c = 0
for si in s:
    if si == "1":
        c += 0
    else:
        a = si
        break

print("1" if k - c <= 0 else a)

s = input()
k = int(input())

c = 0
a = 1
for si in s:
    if si == "1":
        c += 1
    else:
        a = si
        break

print("1" if k - c <= 0 else a)


S = input()
K = int(input())
counter = 0
num = 0
log = 0
for i in range(101):
    if int(S[i]) != 1:
        log = counter
        num = int(S[i])
        break
    counter += 1

if K <= log:
    print(1)
else:
    print(num)

S = input()
K = int(input())
counter = 0
num = 1
log = 0
for i in S:
    if int(i) != 1:
        log = counter
        num = int(i)
        break
    counter += 1

if K <= log:
    print(1)
else:
    print(num)


N, M, Q = map(int, input().split())

t = [[0] * (N + 1) for _ in range(N + 1)]
for _ in range(M):
    L, R = map(int, input().split())
    t[L][R] += 1

for i in range(N + 1):
    for j in range(N):
        t[i][j + 1] += t[i][j]

for _ in range(Q):
    p, q = map(int, input().split())
    print(sum(t[i][q] - t[i][i - 1] for i in range(p, q + 1)))

N, M, Q = map(int, input().split())

t = [[0] * (N + 1) for _ in range(N + 1)]
for _ in range(M):
    L, R = map(int, input().split())
    t[L][R] += 1

for i in range(N + 1):
    for j in range(N):
        t[i][j + 1] += t[i][j]

result = []
for _ in range(Q):
    p, q = map(int, input().split())
    result.append(sum(t[i][q] - t[i][i - 1] for i in range(p, q + 1)))
print("\\n".join(str(v) for v in result))


N, M, Q = map(int, input().split())

x = [[0 for _ in range(N + 1)] for _ in range(N + 1)]
for _ in range(M):
    L, R = map(int, input().split())
    x[L][R] += 1

c = [[0 for _ in range(N + 1)] for _ in range(N + 1)]
for i in range(1, N + 1):
    for j in range(1, N + 1):
        c[i][j] += c[i][j - 1] + x[i][j]

for _ in range(Q):
    P, Q = map(int, input().split())
    ans = 0
    for i in range(P, Q + 1):
        ans += c[i][Q] - c[i][P - 1]
    print(ans)

import sys

input = sys.stdin.readline

N, M, Q = map(int, input().split())
t = [[0] * (N + 1) for _ in range(N + 1)]
# es[L][R]:=区間[L,R]を走る列車の本数

for _ in range(M):
    l, r = map(int, input().split())
    t[l][r] += 1

for L in range(1, N + 1):
    for R in range(1, N + 1):
        t[L][R] += t[L - 1][R]
        t[L][R] += t[L][R - 1]
        t[L][R] -= t[L - 1][R - 1]
        # 累積和のテーブルを作る
        # 最終的には
        # t[L][R]には区間が[L,R]に含まれる本数を入れるが、
        # 現時点では区間が[L,R]に一致する本数しか入っていない
        # ここに区間が[L-1,R]に含まれる本数と
        # 区間が[L,R-1]に含まれる本数を足すと
        # 区間が[L,R]に含まれる範囲をカバーできるが、
        # 区間が[L-1][R-1]の範囲が重複して足されている

for _ in range(Q):
    p, q = map(int, input().split())
    print(t[q][q] - t[p - 1][q] - t[q][p - 1] + t[p - 1][p - 1])
    # 2次元累積和


a = input().split()
n = int(a[0])
m = int(a[1])
qq = int(a[2])

x = [[0] * n for _ in range(n)]

for _ in range(m):
    a = input().split()
    x[int(a[0]) - 1][int(a[1]) - 1] += 1

c = list()

for i in range(n):
    c.append(list())
    for j in range(n):
        a = x[i][j]

        if 0 < j:
            a += c[i][j - 1]

        c[i].append(a)

for _ in range(qq):
    r = 0
    a = input().split()
    p = int(a[0])
    q = int(a[1])
    for j in range(p - 1, q):
        r += c[j][q - 1]
        if 1 < p:
            r -= c[j][p - 2]

    print(r)

a = input().split()
n = int(a[0])
m = int(a[1])
qq = int(a[2])

x = [[0] * n for _ in range(n)]

for _ in range(m):
    a = input().split()
    x[int(a[0]) - 1][int(a[1]) - 1] += 1

c = list()

for i in range(n):
    c.append(list())
    for j in range(n):
        a = x[i][j]

        if 0 < j:
            a += c[i][j - 1]

        c[i].append(a)

z = list()

for i in range(n):
    z.append(list())
    for j in range(n):
        a = c[i][j]

        if 0 < i:
            a += z[i - 1][j]

        z[i].append(a)

for _ in range(qq):
    r = 0
    a = input().split()
    p = int(a[0])
    q = int(a[1])

    if 0 < q:
        r += z[q - 1][q - 1]

    if 0 < q and 1 < p:
        r -= z[q - 1][p - 2] + z[p - 2][q - 1]

    if 1 < p:
        r += z[p - 2][p - 2]

    print(r)


N, M, Q = map(int, input().split())
trains = [list(map(int, input().split())) for _ in range(M)]
questions = [list(map(int, input().split())) for _ in range(Q)]
for q in questions:
    print(len([t for t in trains if q[0] <= t[0] and q[1] >= t[1]]))

import sys

input = sys.stdin.readline
N, M, Q = map(int, input().split())

sum_table = [[0] * (N + 1) for _ in range(N + 1)]
for _ in range(M):
    l, r = map(int, input().split())
    sum_table[l][r] += 1

for i in range(1, N + 1):
    for j in range(1, N + 1):
        sum_table[i][j] += (
            sum_table[i - 1][j] + sum_table[i][j - 1] - sum_table[i - 1][j - 1]
        )

for _ in range(Q):
    p, q = map(int, input().split())
    print(
        sum_table[q][q]
        - sum_table[q][p - 1]
        - sum_table[p - 1][q]
        + sum_table[p - 1][p - 1]
    )


N, M, Q = map(int, input().split())

x = [[0 for j in range(N + 1)] for i in range(N + 1)]
c = [[0 for j in range(N + 1)] for i in range(N + 1)]

for _ in range(M):
    L, R = map(int, input().split())
    x[L][R] += 1

for i in range(1, N + 1):
    for j in range(1, N + 1):
        x[i][j] += x[i][j - 1]

for _ in range(Q):
    p, q = map(int, input().split())
    print(sum(x[i][q] - x[i][p - 1] for i in range(p, q + 1)))

N, M, Q = map(int, input().split())

x = [[0 for j in range(N + 1)] for i in range(N + 1)]

for _ in range(M):
    L, R = map(int, input().split())
    x[N - L][R] += 1

for i in range(1, N + 1):
    for j in range(1, N + 1):
        x[i][j] += x[i][j - 1]

for j in range(1, N + 1):
    for i in range(1, N + 1):
        x[i][j] += x[i - 1][j]

for _ in range(Q):
    p, q = map(int, input().split())
    print(x[N - p][q])


import sys
from itertools import accumulate

input = sys.stdin.readline

def main():
    N, M, Q = map(int, input().split())
    LR = [None] * M
    for i in range(M):
        LR[i] = tuple(map(int, input().split()))
    pq = [None] * Q
    for i in range(Q):
        pq[i] = tuple(map(int, input().split()))

    S = [[0] * (N + 1) for _ in range(N + 1)]
    for L, R in LR:
        S[L][R] += 1
    for i in range(N + 1):
        S[i] = list(accumulate(S[i]))

    ans = [0] * Q
    for i, (p, q) in enumerate(pq):
        for j in range(p, q + 1):
            ans[i] += S[j][q] - S[j][p - 1]

    print("\\n".join(map(str, ans)))

if __name__ == "__main__":
    main()

import sys

import numba as nb
import numpy as np

input = sys.stdin.readline

@nb.njit("i8[:](i8,i8,i8,i8[:,:],i8[:,:])", cache=True)
def solve(N, M, Q, LR, pq):
    S = np.zeros(shape=(N + 1, N + 1), dtype=np.int64)
    for i in range(M):
        L, R = LR[i]
        S[L][R] += 1
    for i in range(N + 1):
        S[i] = np.cumsum(S[i])

    ans = np.zeros(shape=Q, dtype=np.int64)
    for i in range(Q):
        p, q = pq[i]
        for j in range(p, q + 1):
            ans[i] += S[j][q] - S[j][p - 1]

    return ans

def main():
    N, M, Q = map(int, input().split())
    LR = np.zeros(shape=(M, 2), dtype=np.int64)
    for i in range(M):
        LR[i] = input().split()
    pq = np.zeros(shape=(Q, 2), dtype=np.int64)
    for i in range(Q):
        pq[i] = input().split()

    ans = solve(N, M, Q, LR, pq)

    print("\\n".join(map(str, ans)))

if __name__ == "__main__":
    main()


N, M, Q = map(int, input().split())

LR = [[0 for i in range(2)] for j in range(M)]
pq = [[0 for i in range(2)] for j in range(Q)]

for i in range(M):
    LR[i] = list(map(int, input().split()))

for i in range(Q):
    pq[i] = list(map(int, input().split()))

x = [[0 for i in range(N)] for j in range(N)]

# print(LR[0][0])

for i in range(M):
    # x[LR[i][1] - 1][LR[i][0] - 1] = x[LR[i][1] - 1][LR[i][0] - 1] + 1
    x[LR[i][1] - 1][LR[i][0] - 1] += 1

xacu = [[0 for i in range(N)] for j in range(N)]

for i in range(N):
    for j in range(N):
        if j == 0:
            xacu[i][j] = x[i][j]
        else:
            xacu[i][j] = xacu[i][j - 1] + x[i][j]

# print(xacu)

for i in range(Q):
    count = 0
    p = pq[i][0]
    for j in range(pq[i][1]):
        if p == 1:
            count = count + xacu[j][N - 1]
        else:
            count = count + xacu[j][N - 1] - xacu[j][p - 2]

    print(count)

N, M, Q = map(int, input().split())

x = [[0 for i in range(N + 1)] for j in range(N + 1)]

for i in range(M):
    l, r = map(int, input().split())
    x[l][r] += 1

for i in range(1, N + 1):
    for j in range(1, N + 1):
        x[i][j] += x[i - 1][j] + x[i][j - 1] - x[i - 1][j - 1]

for i in range(Q):
    p, q = map(int, input().split())

    ans = x[N][q] - x[p - 1][q]
    print(ans)


#!/usr/bin/env python
# -*- coding: utf-8 -*-

import bisect
import array

def solve():
    n, m, q = map(int, input().split())
    nl = [[] for j in range(n + 1)]
    for e in (input().split() for _ in [0] * m):
        l, r = int(e[0]), int(e[1])
        bisect.insort_left(nl[l], r)
    table = [array.array("i", [0] * (n + 1)) for j in range(n + 1)]
    ran = array.array("i", range(n + 1))
    for i in ran:
        table[i] = [bisect.bisect_right(nl[i], j) for j in ran]

    a = [0] * q
    s = array.array("i", a)
    for i, e in enumerate(input().split() for _ in a):
        l, r = int(e[0]), int(e[1])
        s[i] = sum(table[j][r] - table[j][l - 1] for j in range(l, r + 1))
    print("\\n".join(str(e) for e in s))

if __name__ == "__main__":
    solve()

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import bisect
import array

def solve():
    n, m, q = map(int, input().split())
    nl = [[0 for i in range(n + 1)] for j in range(n + 1)]
    for e in [input().split() for _ in range(m)]:
        l, r = int(e[0]), int(e[1])
        nl[l][r] += 1
    table = [array.array("i", [0] * (n + 2)) for j in range(n + 2)]
    ran = array.array("i", range(n + 1))
    for i in ran:
        for j in ran:
            table[i][j + 1] = table[i][j] + nl[i][j]

    for i, e in enumerate([input().split() for _ in range(q)]):
        l, r = int(e[0]), int(e[1])
        ans = 0
        for j in range(l, r + 1):
            ans += table[j][r + 1] - table[j][l]
        print(ans)

if __name__ == "__main__":
    solve()


import bisect

N = int(input())
root = [4, 7]

if bisect.bisect_right(root, N):
    print("Yes")
else:
    print("No")

N, K = map(int, input().split())

if N % K == 0:
    print(0)

else:
    print(1)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03284/Python/s894069046.py", line 3, in <module>
    N = int(input())
ValueError: invalid literal for int() with base 10: '7 3'


N, K = map(int(input().split()))
if N % K == 0:
    print("0")
else:
    print("1")

N, K = map(int, (input().split()))
if N % K == 0:
    print("0")
else:
    print("1")

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03284/Python/s928688987.py", line 1, in <module>
    N, K = map(int(input().split()))
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'list'


N, K = map(int, input().split())
print([0, 1][N % K])

N, K = map(int, input().split())
print([0, 1][0 < N % K])


(numSenbei, numPeople) = input().split()

if numSenbei % numPeople == 0:
    print(1)
else:
    print(0)

numSenbei, numPeople = [int(i) for i in str(input()).split()]

if numSenbei % numPeople == 0:
    print(0)
else:
    print(1)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03284/Python/s122237530.py", line 3, in <module>
    if numSenbei % numPeople == 0:
TypeError: not all arguments converted during string formatting


# -2進数を求める
N = int(input())

if N == 0:
    print(0)
else:
    ans = ""
    while N != 0:
        if N % 2 != 0:
            N -= 1
            ans = "1" + ans
        else:
            ans = "0" + ans
        N = N // (-2)
print(ans)


# -*- coding: utf-8 -*-
from collections import defaultdict

N, M = map(int, input().split())
A_list = list(map(int, input().split()))

x = defaultdict(int)
y = defaultdict(int)

for i in range(N):
    temp = x.copy()
    x.clear()
    r = A_list[i] % M
    for t in temp.items():
        y[t[0]] = y[t[0]] + t[1]
        x[int(t[0] + r) % M] = t[1]
    x[r] += 1

print(int(x[0] + y[0]))

from collections import Counter
import numpy as np

N, M = map(int, input().split())
A = np.array(list(map(int, input().split())))

A = np.cumsum(A) % M
C = Counter(A)

res = 0
for c in C.items():
    if c[1] > 1:
        res += (c[1] * (c[1] - 1)) // 2
    if c[0] == 0:
        res += c[1]

print(res)


from sys import stdin
import numpy as np

N, M = [int(x) for x in stdin.readline().split()]
A = np.array([int(a) for a in stdin.readline().split()], dtype=np.int64)

cumsum_remainders = (np.hstack([0, A]) % M).cumsum() % M

total = 0
for remainder in np.unique(cumsum_remainders):
    count = (cumsum_remainders == remainder).sum()
    total += count * (count - 1) // 2
print(total)

from sys import stdin
from collections import Counter
import numpy as np

N, M = [int(x) for x in stdin.readline().split()]
A = np.array([int(a) for a in stdin.readline().split()], dtype=np.int64)

cum_remainders = (np.hstack([0, A]) % M).cumsum() % M

remainder_counts = Counter(cum_remainders)
combinations = 0
for count in remainder_counts.values():
    combinations += count * (count - 1) // 2
print(combinations)


# -*- coding: utf-8 -*-

N, M = map(int, input().split())
aN = list(map(int, input().split()))

cnt = 0
for i in range(N):
    ans = 0
    for j in range(i, N):
        ans += aN[j]
        if ans % M == 0:
            cnt += 1
print(cnt)

# -*- coding: utf-8 -*-

"""
参考：https://img.atcoder.jp/abc105/editorial.pdf
　　　http://drken1215.hatenablog.com/entry/2018/08/13/125300
　　　https://www.hamayanhamayan.com/entry/2018/08/12/010816
・左端固定で右端動かすループの累積和だけ取れば、
　(右端の累積和)-(左端-1の累積和)で、どこでも分かるようになる。
・B-AがMの倍数 → BとAのmod Mが等しい(やってみれば分かる)
・各ループ内で、それまでに集計した累積和mod Mから左端として使える場所を数える。
"""

from collections import defaultdict

N, M = map(int, input().split())
aN = list(map(int, input().split()))

# 累積和を一時的に格納する変数
sm = 0
ans = 0
# 累積和のmod Mを格納するdict
d = defaultdict(int)
# 何もない累積和0の分を足しておく
d[0] = 1
for i in range(N):
    sm += +aN[i]
    # 今回のsm%Mを右端として、mod Mが同値になる左端候補の数を答えに加算
    ans += d[sm % M]
    # 今回のsm%Mはこの後左端候補として使うので+1
    d[sm % M] += 1
print(ans)


# -*- coding: utf-8 -*-
from itertools import accumulate, combinations
from collections import defaultdict

n, m = map(int, input().split())
ary = [int(_) for _ in input().split()]

sum_ary = accumulate(ary, lambda x, y: x + y)
mod_table = defaultdict(int)
for mod in [s % m for s in (ary[0], *sum_ary)]:
    mod_table[mod] += 1

print(sum([len(list(combinations(range(v), 2))) for v in mod_table.values()]))

# -*- coding: utf-8 -*-
from itertools import accumulate
from collections import defaultdict

n, m = map(int, input().split())
ary = [int(_) for _ in input().split()]

sum_ary = list(accumulate(ary, lambda x, y: x + y))
mod_ary = [s % m for s in sum_ary]
mod_table = defaultdict(int)
for mod in mod_ary:
    mod_table[mod] += 1
mod_table[0] += 1

print(sum([mod * (mod - 1) // 2 for mod in mod_table.values()]))


N, M = map(int, input().split())
A = list(map(int, input().split()))

t = {}
c = 0
for a in A:
    c += a
    c %= M
    if c in t:
        t[c] += 1
    else:
        t[c] = 1

result = t[0]
c = 0
for a in A:
    c += a
    c %= M
    t[c] -= 1
    result += t[c]
print(result)

N, M = map(int, input().split())
A = list(map(int, input().split()))

t = {}
c = 0
for a in A:
    c += a
    c %= M
    if c in t:
        t[c] += 1
    else:
        t[c] = 1

result = 0
if 0 in t:
    result += t[0]
c = 0
for a in A:
    c += a
    c %= M
    t[c] -= 1
    result += t[c]
print(result)


#!/usr/bin/env python3

import numpy as np
from scipy.special import comb

n, m = list(map(int, input().split()))
a = list(map(int, input().split()))

a_sum = np.cumsum(a)

re_list = {}
for i in a_sum:
    re = i % m
    if re in re_list:
        re_list[re] += 1
    else:
        re_list[re] = 1
re_list[0] += 1
# print(re_list)
ans = 0
for value in re_list.values():
    ans += comb(value, 2, exact=True)

print(ans)

#!/usr/bin/env python3

import numpy as np
from scipy.special import comb

n, m = list(map(int, input().split()))
a = list(map(int, input().split()))

a_sum = np.cumsum(a)

re_list = {}
re_list[0] = 1
for i in a_sum:
    re = i % m
    if re in re_list:
        re_list[re] += 1
    else:
        re_list[re] = 1

# print(re_list)
ans = 0
for value in re_list.values():
    ans += comb(value, 2, exact=True)

print(ans)


n, m = map(int, input().split())
a = list(map(int, input().split()))

sumList = [0] * n
sumList[0] = a[0] % m
number = {}

for i in range(1, n):
    sumList[i] = (sumList[i - 1] + a[i]) % m
    number[sumList[i]] = 0

for i in range(n):
    number[sumList[i]] += 1

ans = 0

for key, value in number.items():
    ans += value * (value - 1) // 2
    if key == 0:
        ans += value

print(ans)

n, m = map(int, input().split())
a = list(map(int, input().split()))

sumList = [0] * n
sumList[0] = a[0] % m
number = {}
number[sumList[0]] = 0

for i in range(1, n):
    sumList[i] = (sumList[i - 1] + a[i]) % m
    number[sumList[i]] = 0

for i in range(n):
    number[sumList[i]] += 1

ans = 0

for key, value in number.items():
    ans += value * (value - 1) // 2
    if key == 0:
        ans += value

print(ans)


r = input()

if r < 1200:
    print("ABC")
elif r < 2800:
    print("ARC")
else:
    print("AGC")

r = int(input())

if r < 1200:
    print("ABC")
elif r < 2800:
    print("ARC")
else:
    print("AGC")

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03288/Python/s301962316.py", line 3, in <module>
    if r < 1200:
TypeError: '<' not supported between instances of 'str' and 'int'


S = input()
flag = True
Cflag = False
for i, c in enumerate(S):
    if i == 0:
        if c == "A":
            continue
        else:
            flag = False
            break

    if c == "C" and i >= 2:
        if Cflag:
            flag = False
        cflag = True
    elif not (97 <= ord(c) <= 122):
        flag = False

if flag and cflag:
    print("AC")
else:
    print("WA")

S = input()
flag = True
cflag = False
for i, c in enumerate(S):
    if i == 0:
        if c == "A":
            continue
        else:
            flag = False
            break

    if c == "C" and 2 <= i < len(S) - 1:
        if cflag:
            flag = False
        cflag = True

    elif not (97 <= ord(c) <= 122):
        flag = False

if flag and cflag:
    print("AC")
else:
    print("WA")


import sys

s = input()

if s[0] != "A":
    print("WA")
    sys.exit(0)

if s[1] < "a" or s[1] > "z":
    print("WA")
    sys.exit(1)

sub = s[2:-1]
has = False
for c in sub:
    if not has and c == "C":
        has = True

    elif "a" <= c <= "z":
        continue

    else:
        has = False
        break

if not has:
    print("wA")
    sys.exit(0)

if "a" <= s[len(s) - 1] <= "z":
    print("AC")
else:
    print("WA")

import sys

s = input()

if s[0] != "A":
    print("WA")
    sys.exit(0)

if s[1] < "a" or s[1] > "z":
    print("WA")
    sys.exit(0)

sub = s[2:-1]
has = False
for c in sub:
    if not has and c == "C":
        has = True

    elif "a" <= c <= "z":
        continue

    else:
        has = False
        break

if not has:
    print("WA")
    sys.exit(0)

if "a" <= s[-1] <= "z":
    print("AC")
else:
    print("WA")


import string

s = list(input())
flag = True
if s[0] != "A":
    flag = False
s.pop(0)
if s.count("C") > 1:
    flag = False
s_index = s.index("C")
if 2 >= s_index or s_index <= (len(s) - 3):
    flag = False
s.pop(s_index)
for i in s:
    if i not in string.ascii_lowercase:
        flag = False

if flag:
    print("AC")
else:
    print("WA")

import string

s = list(input())
flag = True
if s[0] != "A":
    flag = False
count = 0
for i in range(1, len(s)):
    if s[i] in string.ascii_uppercase:
        if i == 1 or i == len(s) - 1 or s[i] != "C":
            flag = False
        count += 1

if flag and count == 1:
    print("AC")
else:
    print("WA")


# 解法は正しいはずだがコーナーケースに引っかかるらしくWAが1個出る

import itertools
import math

D, G = map(int, input().split())

p = {}
c = {}
s = {}
for i in range(1, D + 1):
    pi, ci = map(int, input().split())
    score = 100 * i * pi + ci
    s[i] = score
    p[i] = pi
    c[i] = ci

def complete(pset):
    score = 0
    solved = 0
    comped_max = 0
    for b in pset:
        if b:
            score += s[i]
            solved += p[i]
            comped_max = max(comped_max, i)
    return score, solved, comped_max

def left(norm, i):
    if norm <= 0:
        return 0
    res = int(math.floor(norm / (100 * i)))
    if res < p[i]:
        return res
    return float("inf")

ans = float("inf")
for pset in itertools.product((True, False), repeat=D):
    score, solved, comped_max = complete(pset)
    solved += left(G - score, comped_max)
    ans = min(ans, solved)

print(ans)

import itertools
import math

D, G = map(int, input().split())

p = {}
c = {}
s = {}
for i in range(1, D + 1):
    pi, ci = map(int, input().split())
    score = 100 * i * pi + ci
    s[i] = score
    p[i] = pi
    c[i] = ci

def complete(pset):
    score = 0
    solved = 0
    comped = set()
    for i, b in zip(range(1, D + 1), pset):
        if b:
            score += s[i]
            solved += p[i]
            comped.add(i)
    leftset = set(list(range(1, D + 1))) - comped
    return score, solved, leftset

def left(norm, leftset):
    if norm <= 0 or len(leftset) == 0:
        return 0
    i = max(leftset)
    res = int(math.ceil(norm / (100 * i)))
    if res < p[i]:
        return res
    return float("inf")

ans = float("inf")
for pset in itertools.product((True, False), repeat=D):
    score, solved, leftset = complete(pset)
    solved += left(G - score, leftset)
    ans = min(ans, solved)

print(ans)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03290/Python/s095921582.py", line 43, in <module>
    solved += left(G - score, comped_max)
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03290/Python/s095921582.py", line 34, in left
    res = int(math.floor(norm / (100 * i)))
ZeroDivisionError: division by zero


mod = 1000000007

S = input()
n = 1
a = 0
ab = 0
abc = 0
for s in S:
    if s in "A":
        a += n
    if s in "B":
        ab += a
    if s == "C":
        abc += ab
    if s in "?":
        n, a, ab, abc = 3 * n, 3 * a + n, 3 * ab + a, 3 * abc + ab

print(abc % mod)

mod = 1000000007

S = input()
n = 1
a = 0
ab = 0
abc = 0
for s in S:
    if s in "A":
        a += n
    if s in "B":
        ab += a
    if s == "C":
        abc += ab
    if s in "?":
        n, a, ab, abc = 3 * n, 3 * a + n, 3 * ab + a, 3 * abc + ab
    n %= mod
    a %= mod
    ab %= mod
    abc %= mod

print(abc % mod)


A = [map(int, input().split())]

print(max(A) - min(A))

A = [int(x) for x in input().split()]

print(max(A) - min(A))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03292/Python/s076740739.py", line 3, in <module>
    print(max(A) - min(A))
TypeError: unsupported operand type(s) for -: 'map' and 'map'


*a = map(int, input().split())
print(max(a) - min(a))

(*a,) = map(int, input().split())
print(max(a) - min(a))

  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03292/Python/s292492907.py", line 1
    *a = map(int, input().split())
    ^^
SyntaxError: starred assignment target must be in a list or tuple


a = map(int, input().split())
print(max(a) - min(a))

a = list(map(int, input().split()))
print(max(a) - min(a))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03292/Python/s403760215.py", line 2, in <module>
    print(max(a) - min(a))
ValueError: min() arg is an empty sequence


A = map(int, input())
A = sorted(A)
ans = 0
for i in range(1, 3):
    ans += abs(A[i - 1] - A[i])
print(ans)

A = map(int, input().split())
A = sorted(A)
ans = 0
for i in range(1, 3):
    ans += abs(A[i - 1] - A[i])
print(ans)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03292/Python/s889909183.py", line 2, in <module>
    A = sorted(A)
ValueError: invalid literal for int() with base 10: ' '


s1 = input()
print("Yes" if input() in tuple(s1[i:] + s1[:i] for i in range(len(s1))) else "No")

import numpy as np

A = np.array(sorted(map(int, input().split())))
print((A[1:] - A[:-1]).sum())

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03292/Python/s772178766.py", line 2, in <module>
    print("Yes" if input() in tuple(s1[i:] + s1[:i] for i in range(len(s1))) else "No")
EOFError: EOF when reading a line


# Modulo Summation
import math
from functools import reduce

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

n = int(input())
a = list(map(int, input().split()))
m = reduce(lcm, a, 1) - 1
print(sum(map(lambda x: m % x, a)))

# Modulo Summation
input()
a = list(map(int, input().split()))
x = 1
for i in a:
    x *= i
print(sum(list(map(lambda j: (x - 1) % j, a))))


import math
from functools import reduce

n = int(input())
a = list(map(int, input().split()))

a_lcm = reduce(lambda x, y: (x * y) // math.gcd(x, y), a)
m = a_lcm - 1
a_mod = [m % ax for ax in a]

print(sum(a_mod))

from functools import reduce

n = int(input())
a = list(map(int, input().split()))

def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)

a_lcm = reduce(lambda x, y: (x * y) // gcd(x, y), a)
m = a_lcm - 1
a_mod = [m % ax for ax in a]

print(sum(a_mod))


from functools import reduce

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm(numbers):
    return reduce(lcm_base, numbers, 1)

N = int(input())
a = list(map(int, input().split()))

mod = []
for m in range(lcm(a)):
    k = [m % a[i] for i in range(N)]
    mod.append(sum(k))
print(max(mod))

N = int(input())
a = list(map(int, input().split()))

f = sum(a) - N
print(f)


from fractions import gcd

def lcm(a, b):
    return int(a * b / gcd(a, b))

N = int(input())
A = list(map(int, input().split()))

cumlcm = A[0]
for a in A[1:]:
    cumlcm = lcm(cumlcm, a)
m = cumlcm - 1
f = sum(map(lambda a: m % a if a != 0 else m, A))
print(f)

from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

N = int(input())
A = list(map(int, input().split()))

cumlcm = A[0]
for a in A[1:]:
    cumlcm = lcm(cumlcm, a)
m = cumlcm - 1
f = sum(map(lambda a: m % a, A))
print(f)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03294/Python/s783858120.py", line 1, in <module>
    from fractions import gcd
ImportError: cannot import name 'gcd' from 'fractions' (/usr/lib/python3.10/fractions.py)


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

n = int(input())
arr = list(map(int, input().split()))
lcm = 1
for e in arr:
    lcm = int(lcm * e / gcd(lcm, e))
lcm -= 1
res = 0
for e in arr:
    res += lcm % e
print(res)

n = int(input())
arr = list(map(int, input().split()))
lcm = 0
for e in arr:
    lcm += e - 1
print(lcm)


N, M = map(int, input().split())

ab = [0] * M
for _ in range(M):
    a, b = map(int, input().split())
    ab[a].append(b)

dp = [0] * (N + 1)
for i in range(1, N + 1):
    dp[i] = max(dp[i], dp[i - 1])
    for j in ab[i]:
        dp[j] = max(dp[j], dp[i] + 1)

print(dp[N])

N, M = map(int, input().split())

ab = [[] for _ in range(N + 1)]
for _ in range(M):
    a, b = map(int, input().split())
    ab[a].append(b)

dp = [0] * (N + 1)
for i in range(1, N + 1):
    dp[i] = max(dp[i], dp[i - 1])
    for j in ab[i]:
        dp[j] = max(dp[j], dp[i] + 1)

print(dp[N])

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03295/Python/s787059904.py", line 6, in <module>
    ab[a].append(b)
AttributeError: 'int' object has no attribute 'append'


N, M = map(int, input().split())
req = [tuple(map(int, input().split())) for _ in range(M)]
req.sort(key=lambda x: x[1])

res = 0
i = 1
while i <= N:
    remain = [x for x in req if i <= x[0]]
    if len(remain):
        i = remain[0][1]
        res += 1
    else:
        break

print(res)

N, M = map(int, input().split())
req = [tuple(map(int, input().split())) for _ in range(M)]
req.sort(key=lambda x: x[1])

res = 0
i = 1
for m in range(M):
    if req[m][0] >= i:
        i = req[m][1]
        res += 1

print(res)


#!/usr/bin/env python
# -*- coding: utf-8 -*-

N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]

count = 0
tmp = 1
for i in range(1, N):
    if A[i] == A[i - 1]:
        tmp += 1
    else:
        # 等しくなくなったら
        count += tmp // 2
        tmp = 1  # tmp のリセット

print(count)

#!/usr/bin/env python
# -*- coding: utf-8 -*-

N = int(input())
A = [int(i) for i in input().split()] + [0]

count = 0
tmp = 1
for i in range(1, N + 1):
    if A[i] == A[i - 1]:
        tmp += 1
    else:
        # 等しくなくなったら
        count += tmp // 2
        tmp = 1  # tmp のリセット

print(count)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03296/Python/s729658845.py", line 5, in <module>
    A = [list(map(int, input().split())) for _ in range(N)]
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03296/Python/s729658845.py", line 5, in <listcomp>
    A = [list(map(int, input().split())) for _ in range(N)]
EOFError: EOF when reading a line


N = int(input())
a = list(map(int, input().split()))

count = 0

for x in range(N):
    if x != N - 1:
        if a[x] == a[x + 1]:
            if x + 1 < N:
                if a[x + 2] == 10000:
                    a[x + 1] = 9999
                    count += 1
                else:
                    a[x + 1] = 10000
                    count += 1
            else:
                a[x + 1] = 10000
                count += 1
print(count)

N = int(input())
a = list(map(int, input().split()))

count = 0

for x in range(N):
    if x != N - 1:
        if a[x] == a[x + 1]:
            if x < N - 2:
                if a[x + 2] == 10000:
                    a[x + 1] = 9999
                    count += 1
                else:
                    a[x + 1] = 10000
                    count += 1
            else:
                a[x + 1] = 10000
                count += 1
print(count)


T = int(input())
for i in range(T):
    A, B, C, D = [int(i) for i in input().split()]

    memo = set()
    while True:
        if A in memo:
            print("Yes")
            break

        if A - B < 0:
            print("No")
            break

        if D - B == 0:
            if C - A + B < 0:
                print("No")
                break
            else:
                print("Yes")
                break

        if D - B < 0:
            print("No")
            break

        n = 1 + (C - A + B) // (D - B)
        r = (A - B) + n * (D - B)
        if r < B:
            print("No")
            break
        else:
            memo.add(A)
            A = B + r % B

    else:
        print("Yes")

    # print(A, B, C, D)

from fractions import gcd

def solve(a, b, c, d):
    if a < b or d < b:
        return False

    if c >= b - 1:
        return True

    g = gcd(b, d)
    return (b + a % g - g) <= c

T, *L = map(int, open(0).read().split())

for t in zip(*[iter(L)] * 4):
    if solve(*t):
        print("Yes")
    else:
        print("No")


a, b = map(int, input())
if a + b == 15:
    print("+")
elif a * b == 15:
    print("*")
else:
    print("x")

a, b = map(int, input().split())
if a + b == 15:
    print("+")
elif a * b == 15:
    print("*")
else:
    print("x")

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03302/Python/s877853063.py", line 1, in <module>
    a, b = map(int, input())
ValueError: invalid literal for int() with base 10: ' '


a, b = input().split()

if a + b == 15:
    print("+")
elif a * b == 15:
    print("*")
else:
    print("x")

a, b = map(int, input().split())

if a + b == 15:
    print("+")
elif a * b == 15:
    print("*")
else:
    print("x")

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03302/Python/s883899606.py", line 5, in <module>
    elif a * b == 15:
TypeError: can't multiply sequence by non-int of type 'str'


def solve():
    n = int(input())
    i = n
    while True:
        if i % 2 == 0 and i % n == 0:
            print(i)
            exit()

if __name__ == "__main__":
    solve()

def solve():
    n = int(input())
    i = n
    while True:
        if i % 2 == 0:
            print(i)
            exit()
        i += n

if __name__ == "__main__":
    solve()


N = int(input())

i = N
while True:
    if i % 2 == 0 and i % N == 0:
        print(i)
        break
    i += 1

N = int(input())

i = N
while True:
    if i % 2 == 0 and i % N == 0:
        print(i)
        break
    i += N


number = int(input())
nums = list(map(int, input().split(" ")))

print(max(nums) - min(nums))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03307/Python/s884311780.py", line 2, in <module>
    nums = list(map(int, input().split(" ")))
EOFError: EOF when reading a line


n = int(input())

if n < 1 or n > 10:
    raise ValueError

print(2 * n if n % 2 != 0 else n)

n = int(input())

print(2 * n if n % 2 != 0 else n)


n = int(input())
ans = 1

while True:
    if ans % n == 0 and ans % 2 == 0:
        print(ans)
        break
    ans += 1

n = int(input())

# a,bの最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

# a,bの最小公倍数
def lcm(a, b):
    return a * b // gcd(a, b)

print(lcm(2, n))


N = int(input())
N1 = []

for n in range(1, (N + 1)):
    N1.append(2 * n)

for i in N1:
    if i % N == 0:
        print(i)
        break

N = int(input())
if N % 2 == 0:
    print(N)
else:
    print(2 * N)


n = int(input())
num = n

while num % 2 != 0 or num % n != 0:
    num += 1

print(num)

a = int(input())
b = 2
x = a * b

if a < b:
    tmp = a
    a = b
    b = tmp

r = a % b
while r != 0:
    a = b
    b = r
    r = a % b

print(int(x / b))


n = int(input())

for i in range(2, 10**9, 2):
    if i % n == 0:
        print(i)

n = int(input())

if n % 2 == 0:
    print(n)
else:
    print(n * 2)


N = input()

if N % 2 != 0:
    answer = N * 2
    print(answer)
else:
    print(N)

N = int(input())

if N % 2 != 0:
    answer = N * 2
    print(answer)
else:
    print(N)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03307/Python/s937616807.py", line 3, in <module>
    if N % 2 != 0:
TypeError: not all arguments converted during string formatting


N = int(input())

A = list(map(int, input().split()))

print(max(A) - min(A))

N = int(input())

if N % 2 == 0:
    print(N)
else:
    print(N * 2)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03307/Python/s608756496.py", line 3, in <module>
    A = list(map(int, input().split()))
EOFError: EOF when reading a line


n = int(input())
a = map(int, input().split())
print(max(a) - min(a))

n = int(input())
a = list(map(int, input().split()))
print(max(a) - min(a))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03308/Python/s261566864.py", line 3, in <module>
    print(max(a) - min(a))
ValueError: min() arg is an empty sequence


N = int(input())
A = list(map(int, input().spllit()))
print(max(A) - min(A))

N = int(input())
A = list(map(int, input().split()))
print(max(A) - min(A))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03308/Python/s562647525.py", line 2, in <module>
    A = list(map(int, input().spllit()))
AttributeError: 'str' object has no attribute 'spllit'. Did you mean: 'split'?


import math

N = int(input())
A = list(map(int, input().split()))
# print(N, A)

_A = [A[i] - (i + 1) for i in range(len(A))]
_A.sort()
median = _A[math.ceil(len(A) / 2)]

sadness = 0
for i in range(len(A)):
    sadness += abs(A[i] - (i + 1 + median))

print(sadness)

import math

N = int(input())
A = list(map(int, input().split()))
# print(N, A)

_A = [A[i] - (i + 1) for i in range(len(A))]
_A.sort()
median = _A[math.floor(len(A) / 2)]

sadness = 0
for i in range(len(A)):
    sadness += abs(A[i] - (i + 1 + median))

print(sadness)


N = int(input())
A = [int(i) for i in input().split()]

sum = 0
ans = []

for b in range(-int(N / 2), int(N / 2)):
    for i in range(N):
        sum += abs(A[i] - (b + i))
    else:
        ans.append(sum)
        sum = 0

print(min(ans))

N = int(input())
A = list(map(int, input().split()))

B = [A[i] - (i + 1) for i in range(N)]

B.sort()

b = B[len(B) // 2]

ans = 0

for j in range(N):
    ans += abs(A[j] - (b + j + 1))

print(ans)


n = int(input().strip())
a = list(map(int, input().split()))
b = [(a[i] - (i + 1)) for i in range(n)]
b.sort()
mid = 0
if n % 2 == 1:
    mid = b[(n - 1) // 2 + 1]
else:
    mid = (b[(n - 1) // 2] + b[(n - 1) // 2]) // 2

ans = 0
for i in range(n):
    ans += abs(b[i] - mid)
print(ans)

n = int(input().strip())
a = list(map(int, input().split()))
b = [(a[i] - (i + 1)) for i in range(n)]
b.sort()
mid = 0
if n == 1:
    mid = b[0]
elif n % 2 == 1:
    mid = b[(n - 1) // 2]
else:
    mid = (b[(n - 1) // 2] + b[(n - 1) // 2 + 1]) // 2
ans = 0
for i in range(n):
    ans += abs(b[i] - mid)
print(ans)


# -*- coding: utf-8 -*-
INF = 10**10
n = int(input())
a = [int(_) - (i + 1) for i, _ in enumerate(input().split())]

grief = INF
for b in set(a):
    tmp = sum([abs(ai - b) for ai in a])
    if tmp < grief:
        bb = b
        grief = tmp

print(grief)

# -*- coding: utf-8 -*-
n = int(input())
a = [int(_) - (i + 1) for i, _ in enumerate(input().split())]

# INF = 10**10
# grief = INF
# for b in set(a):
#     tmp = sum([abs(ai - b) for ai in a])
#     if tmp < grief:
#         bb = b
#         grief = tmp

# print(grief)  # running time limit error

a.sort()
med = a[len(a) // 2]
grief = sum([abs(ai - med) for ai in a])
print(grief)


N = int(input())
A = list(map(int, input().split()))
S = [0] * N
S[0] = A[0]
for i in range(1, N):
    S[i] = S[i - 1] + A[i]

num = float("inf")
a = 0
b = 0
for i in range(1, N - 2):
    while S[a] < S[i] - S[a + 1]:
        a += 1
    b = i
    while S[b] - S[i] < S[N - 1] - S[b + 1]:
        b += 1

    P = [S[a], S[i] - S[a], S[b] - S[i], S[N - 1] - S[b]]
    num = min(num, abs(max(P) - min(P)))

print(num)

N = int(input())
A = list(map(int, input().split()))
S = [0] * N
S[0] = A[0]
for i in range(1, N):
    S[i] = S[i - 1] + A[i]

num = float("inf")
a = 0
b = 2
for i in range(1, N - 2):
    while S[a] < S[i] - S[a + 1]:
        a += 1
    b = max(b, i + 1)
    while S[b] - S[i] < S[N - 1] - S[b + 1]:
        b += 1

    P = [S[a], S[i] - S[a], S[b] - S[i], S[N - 1] - S[b]]
    num = min(num, abs(max(P) - min(P)))

print(num)


N = int(input())
A = [int(i) for i in input().split()]
A = [A[i] - i - 1 for i in range(N)]
A.sort()
# for a in [A[N // 2], A[N // 2 + 1]]:
sum_A = [0, 0]
for i in range(N):
    sum_A[0] += abs(A[i] - A[N // 2])
sum_2 = 0
for i in range(N):
    sum_A[1] += abs(A[i] - A[N // 2 + 1])
print(min(sum_A))

N = int(input())
if N == 1:
    print(0)
    exit()
A = [int(i) for i in input().split()]
A = [A[i] - i - 1 for i in range(N)]
A.sort()
if N == 2:
    print(abs(A[0] - A[1]))
    exit()

sum_A = [0, 0]
for i in range(N):
    sum_A[0] += abs(A[i] - A[N // 2])
sum_2 = 0
for i in range(N):
    sum_A[1] += abs(A[i] - A[N // 2 + 1])
print(min(sum_A))


from heapq import nlargest

n = int(input())
aaa = list(map(int, input().split()))
n2 = 1 << n
dp = [[0, a] for a in aaa]

for j in range(n):
    b = 1 << j
    for i in range(n2):
        if not i & b:
            dp[i | b] = nlargest(2, dp[i] + dp[i | b])

ans = []
tmp = 0
for a in dp[1:]:
    tmp = max(tmp, a)
    ans.append(tmp)
print(*ans)

n = int(input())
aaa = list(map(int, input().split()))
n2 = 1 << n
dp = [[a, 0] for a in aaa]

for j in range(n):
    b = 1 << j
    for i in range(n2):
        if not i & b:
            dpi, dpk = dp[i], dp[i | b]
            if dpk[0] < dpi[0]:
                dpk[1] = max(dpk[0], dpi[1])
                dpk[0] = dpi[0]
            elif dpk[1] < dpi[0]:
                dpk[1] = dpi[0]

ans = []
tmp = 0
for a in dp[1:]:
    tmp = max(tmp, a[0] + a[1])
    ans.append(tmp)
print(*ans)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03313/Python/s524712776.py", line 17, in <module>
    tmp = max(tmp, a)
TypeError: '>' not supported between instances of 'list' and 'int'


N = input()
if int(N) % sum([int(N[i] for i in range(len(N)))]) == 0:
    print("Yes")
else:
    print("No")

N = input()
if int(N) % sum([int(N[i]) for i in range(len(N))]) == 0:
    print("Yes")
else:
    print("No")

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03316/Python/s036030936.py", line 2, in <module>
    if int(N) % sum([int(N[i] for i in range(len(N)))]) == 0:
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'generator'


# Nは最大9桁
n = input()
sn = 0
for ni in n:
    sn += int(ni)
if n % sn == 0:
    print("Yes")
else:
    print("No")

# Nは最大9桁
n = input()
sn = 0
for ni in n:
    sn += int(ni)
if int(n) % sn == 0:
    print("Yes")
else:
    print("No")

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03316/Python/s956814127.py", line 6, in <module>
    if n % sn == 0:
TypeError: not all arguments converted during string formatting


N = input()
S = 0
for i in N:
    S += int(i)
print("Yes" if N % S == 0 else "No")

N = input()
S = 0
for i in N:
    S += int(i)
print("Yes" if int(N) % S == 0 else "No")

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03316/Python/s175898024.py", line 5, in <module>
    print("Yes" if N % S == 0 else "No")
TypeError: not all arguments converted during string formatting


Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03317/Python/s270349250.py", line 1, in <module>
    n, k = map(int, input())
ValueError: invalid literal for int() with base 10: ' '


n, k = map(int, input().split())
print((n - 2) // (k - 2) + 1)

n, k = map(int, input().split())
print((n - 2) // (k - 1) + 1)


A = int(input())
B = int(input())

if A > 8 or B > 8:
    print("Yay!")
else:
    print(":(")

A, B = map(int, input().split())

if A > 8 or B > 8:
    print(":(")
else:
    print("Yay!")

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03323/Python/s618480523.py", line 1, in <module>
    A = int(input())
ValueError: invalid literal for int() with base 10: '5 4'


a = int(input())
b = int(input())

if a >= 9 or b >= 9:
    print(":(")
else:
    print("Yay!")

a, b = map(int, input().split())

if a >= 9 or b >= 9:
    print(":(")
else:
    print("Yay!")

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03323/Python/s393600205.py", line 1, in <module>
    a = int(input())
ValueError: invalid literal for int() with base 10: '5 4'


a, b = int(input()), int(input())
if a <= 8 and b <= 8:
    print("Yay!")
else:
    print(":(")

a, b = map(int, input().split())
if a <= 8 and b <= 8:
    print("Yay!")
else:
    print(":(")

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03323/Python/s102805982.py", line 1, in <module>
    a, b = int(input()), int(input())
ValueError: invalid literal for int() with base 10: '5 4'


#!/usr/bin/env python3
# -*- coding: utf-8 -*-

a = int(input())
b = int(input())
if a <= 8 and b <= 8:
    print("Yay!")
else:
    print(":(")

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

a, b = map(int, input().split())
if a <= 8 and b <= 8:
    print("Yay!")
else:
    print(":(")

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03323/Python/s149144463.py", line 4, in <module>
    a = int(input())
ValueError: invalid literal for int() with base 10: '5 4'


# -*- coding: utf-8 -*-

# スペース区切りの整数の入力
N = int(input())
an = list(map(int, input().split()))

sum_cnt = 0
for a in an:
    tmp = a
    cnt = 0
    while tmp % 2 == 0:
        cnt += 1
        tmp = tmp / 2

    sum_cnt += cnt

print(sum_cnt)

# -*- coding: utf-8 -*-

# スペース区切りの整数の入力
A, B = map(int, input().split())

if A <= 8 and B <= 8:
    print("Yay!")
else:
    print(":(")

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03323/Python/s032769715.py", line 4, in <module>
    N = int(input())
ValueError: invalid literal for int() with base 10: '5 4'


#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3

n = int(input())
a = list(map(int, input().split()))

t = 0
for i in a:
    m = i
    while m % 2 == 0:
        t += 1
        m /= 2

print(t)

#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3

d, n = map(int, input().split())

a = 0
if d == 0:
    a = n
    if n == 100:
        a += 1
elif d == 1:
    a = 100 * n
    if n == 100:
        a += 100
elif d == 2:
    a = 100 * 100 * n
    if n == 100:
        a += 100 * 100

print(a)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03324/Python/s686916597.py", line 3, in <module>
    n = int(input())
ValueError: invalid literal for int() with base 10: '0 5'


input()

a = list(map(int, input().split()))

count = 0
flag = True
while flag:
    flag = False
    for i, aa in enumerate(a):
        if aa % 2 == 0:
            a[i] = int(a[i] / 2)
            flag = True
            break
    if flag:
        count += 1
print(count)

input()

a = list(map(int, input().split()))

count = 0
for i, aa in enumerate(a):
    while aa % 2 == 0:
        aa = int(aa / 2)
        count += 1
print(count)


n = int(input())
a = list(map(int, input().split()))
ans, cnt = 0, 0
b = True

while b:
    cnt = 0
    for i in range(len(a)):
        if cnt == 0:
            if a[i] % 2 == 0:
                a[i] = a[i] // 2
                cnt = 1
            else:
                a[i] = a[i] * 3
        else:
            a[i] = a[i] * 3
    if cnt == 1:
        ans += 1
    else:
        b = False
print(ans)

n = int(input())
a = list(map(int, input().split()))
ans = 0

for i in a:
    while i % 2 == 0:
        i //= 2
        ans += 1
print(ans)


N = int(input())
a = list(map(int, input().split()))

ans = 0
m = 1
for i in a:
    m *= i

while True:
    if m % 2 == 0:
        ans += 1
        m //= 2
    else:
        break

print(ans)

N = int(input())
a = list(map(int, input().split()))

ans = 0
for i in a:
    count = 0
    while True:
        if i % 2 ** (count + 1) == 0:
            count += 1
        else:
            ans += count
            break

print(ans)


N, *a = map(int, open(0).read().split())
ans = 0
flag = True
while flag:
    cnt = 0
    for i in range(N):
        if a[i] % 2 != 0:
            continue
        elif a[i] % 2 == 0 and cnt == 0:
            a[i] //= 2
            cnt += 1
            break

    if cnt == 0:
        flag = False
    else:
        ans += 1

print(ans)

N, *a = map(int, open(0).read().split())
ans = 0
for i in range(N):
    while a[i] % 2 == 0:
        a[i] //= 2
        ans += 1

print(ans)


N, *a = map(int, open(0).read().split())
ans = 0
flag = True
while flag:
    cnt = 0
    for i in range(N):
        if a[i] % 2 == 0 and cnt == 0:
            a[i] //= 2
            cnt += 1
        else:
            a[i] *= 3
    else:
        if cnt == 0:
            flag = False
        else:
            ans += 1

print(ans)

N, *a = map(int, open(0).read().split())
ans = 0
for i in range(N):
    ans += len(bin(a[i])) - bin(a[i]).rfind("1") - 1
print(ans)


def judge():
    four = []
    even = []
    odd = []
    for a in a_list:
        if a % 2 == 1:
            odd.append(a * 3)
        else:
            if a % 4 == 0:
                four.append(a)
            else:
                even.append(a)
    if len(four) > 0:
        odd.append(four.pop() // 2)
        four = [i * 3 for i in four]
        odd.extend(four)
        even = [i * 3 for i in even]
        odd.extend(even)
    else:
        if even:
            odd.append(even.pop() // 2)
            even = [i * 3 for i in even]
            odd.extend(even)
        else:
            return False
    global a_list
    a_list = odd
    return True

N = int(input())
a_list = list(map(int, input().split()))
cnt = 0
while True:
    if judge():
        cnt += 1
    else:
        break
print(cnt)

N = int(input())
a_list = list(map(int, input().split()))
cnt = 0
for a in a_list:
    if a % 2 == 0:
        while a % 2 == 0:
            a /= 2
            cnt += 1
print(cnt)


n = int(input())
A = list(map(int, input().split()))

ans = 0
waru = 0
cnt = 0

while True:
    for i in range(n):
        if A[i] % 2 == 0:
            if waru == 1:
                A[i] *= 3
            else:
                A[i] //= 2
                waru = 1
        else:
            A[i] *= 3
    if waru == 0:
        print(ans)
        exit()
    else:
        ans += 1
    waru = 0

n = int(input())
A = list(map(int, input().split()))

ans = 0

for a in A:
    while a % 2 == 0:
        a /= 2
        ans += 1

print(ans)


N = int(input())
a = list(map(int, input().split()))

cnt = 0

while True:
    has_divided = False
    for i in range(N):
        if not has_divided and a[i] % 2 == 0:
            a[i] = a[i] // 2
            has_divided = True
        else:
            a[i] *= 3
    if has_divided:
        cnt += 1
    else:
        break
print(cnt)

N = int(input())
a = list(map(int, input().split()))

cnt = 0

for i in range(N):
    while True:
        if a[i] % 2 == 0:
            a[i] //= 2
            cnt += 1
        else:
            break
print(cnt)


n = int(input())
a = list(map(int, input().split()))

s = 0
while True:
    divided = False
    for i in range(n):
        if a[i] % 2 == 0:
            a[i] //= 2
            divided = True
            break
    if divided:
        s += 1
    else:
        break
print(s)

n = int(input())
a = list(map(int, input().split()))

s = 0
for i in range(n):
    while a[i] % 2 == 0:
        a[i] //= 2
        s += 1
print(s)


from itertools import combinations

n, m = map(int, input().split())
xyz = [list(map(int, input().split())) for _ in range(n)]
ans = 0

for elem in combinations(xyz, m):
    x = abs(sum([e[0] for e in elem]))
    y = abs(sum([e[1] for e in elem]))
    z = abs(sum([e[2] for e in elem]))
    ans = max(ans, x + y + z)
print(ans)

from itertools import product

n, m = map(int, input().split())
xyz = [list(map(int, input().split())) for _ in range(n)]
ans = 0

for e in product([1, -1], [1, -1], [1, -1]):
    xyz.sort(key=lambda v: (v[0] * e[0]) + (v[1] * e[1]) + (v[2] * e[2]))
    tmp = xyz[:m]
    ans = max(
        ans,
        abs(sum([e[0] for e in tmp]))
        + abs(sum([e[1] for e in tmp]))
        + abs(sum([e[2] for e in tmp])),
    )
print(ans)


from itertools import combinations

def abs_sum(xyz_list):
    s1 = abs(sum([xyz[0] for xyz in xyz_list]))
    s2 = abs(sum([xyz[1] for xyz in xyz_list]))
    s3 = abs(sum([xyz[2] for xyz in xyz_list]))
    return s1 + s2 + s3

n, m = list(map(int, input().split(" ")))
xyz_list = []
for _ in range(n):
    xyz_list.append(list(map(int, input().split(" "))))

combs = combinations(xyz_list, m)
print(max([abs_sum(comb) for comb in combs]))

from itertools import product

import numpy as np

n, m = list(map(int, input().split(" ")))
if m == 0:
    print(0)
    exit()
xyz_list = []
for _ in range(n):
    xyz_list.append(np.array(list(map(int, input().split(" ")))))
arrs = [np.array(x) for x in product([1, -1], repeat=3)]
ans = max([sum(sorted([sum(arr * xyz) for xyz in xyz_list])[-m:]) for arr in arrs])
print(ans)


import itertools

N, M = map(int, input().split())
lst = [list(map(int, input().rstrip().split())) for n in range(N)]
num = [i for i in range(N)]
maximum = -float("inf")
for p in itertools.combinations(num, M):
    m = sum(abs(sum(lst[n][i] for n in p)) for i in range(3))
    maximum = max(maximum, m)

print(maximum)

N, M = map(int, input().split())
lst = [list(map(int, input().rstrip().split())) for n in range(N)]
maximum = -float("inf")
for i in [-1, 1]:
    for j in [-1, 1]:
        for k in [-1, 1]:
            sum_lst = []
            for n in range(N):
                num = lst[n][0] * i + lst[n][1] * j + lst[n][2] * k
                sum_lst.append(num)
            maximum = max(abs(sum(sorted(sum_lst)[:M])), maximum)

print(maximum)


N = input()
if N < 1000:
    print("ABC")
else:
    print("ABD")

N = int(input())
if N < 1000:
    print("ABC")
else:
    print("ABD")

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03327/Python/s497455145.py", line 2, in <module>
    if N < 1000:
TypeError: '<' not supported between instances of 'str' and 'int'


def main():
    a, b = map(int, input().split())

    h = b - a

    i, ans = 0
    while True:
        i += 1
        ans += i

        if h == i:
            break

    print(ans)

if __name__ == "__main__":
    main()

def main():
    a, b = map(int, input().split())

    h = 0
    ans = 0
    for i in range(1, 1000):
        h += i

        if h > b:
            b_h = h - b
            if a_h == b_h:
                ans = b_h
                break
        if h > a:
            a_h = h - a

    print(ans)

if __name__ == "__main__":
    main()

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03328/Python/s567662645.py", line 18, in <module>
    main()
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03328/Python/s567662645.py", line 6, in main
    i, ans = 0
TypeError: cannot unpack non-iterable int object


a, b = list(map(int, input()))
answer = (b - a) * (b - a + 1) / 2 - b
print(int(answer))

a, b = list(map(int, input().split()))
answer = (b - a) * (b - a + 1) / 2 - b
print(int(answer))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03328/Python/s337385384.py", line 1, in <module>
    a, b = list(map(int, input()))
ValueError: invalid literal for int() with base 10: ' '


def func(x):
    if x == 1:
        return 1
    else:
        return x + func(x - 1)

a, b = map(int, input().split())

for i in range(1, 999):
    if func(i) - a == func(i + 1) - b:
        print(func(i) - a)
        break

H = [1]
for i in range(2, 1000):
    H.append(H[-1] + i)

a, b = map(int, input().split())

for i in range(998):
    if H[i] - a == H[i + 1] - b:
        print(H[i] - a)
        break


from collections import deque

max_n = 11000
dp = [-1] * max_n  # -1を未探索とする
dp[0] = 0  # 初期条件の設定
n = int(input())
que = deque([])
que.append(dp[0])
while que:
    v = que.popleft()
    pow = 1
    while v + pow <= n:
        if dp[v + pow] == -1:
            dp[v + pow] = dp[v] + 1
            que.append(v + pow)
        pow *= 6
    pow = 1
    while v + pow <= n:
        if dp[v + pow] == -1:
            dp[v + pow] = dp[v] + 1
            que.append(v + pow)
        pow *= 9
# print(dp)
print(dp[n])

from collections import deque

max_n = 110000
dp = [-1] * max_n  # -1を未探索とする
dp[0] = 0  # 初期条件の設定
n = int(input())
que = deque([])
que.append(dp[0])
while que:
    v = que.popleft()
    pow = 1
    while v + pow <= n:
        if dp[v + pow] == -1:
            dp[v + pow] = dp[v] + 1
            que.append(v + pow)
        pow *= 6
    pow = 1
    while v + pow <= n:
        if dp[v + pow] == -1:
            dp[v + pow] = dp[v] + 1
            que.append(v + pow)
        pow *= 9
# print(dp)
print(dp[n])


import math

money = int(input())

six = [6**i for i in range(1, 8)]
nine = [9**i for i in range(1, 7)]

all = [1] + sorted(six + nine)

dp = [float(math.inf) for i in range(100001)]
dp[0] = 0

for i in range(0, 100001):
    for el in all:
        temp = i + el
        if temp < 100001:
            dp[temp] = min(dp[temp], dp[i] + 1)

print(dp[money])

money = int(input())

six = [6**i for i in range(1, 8)]
nine = [9**i for i in range(1, 7)]

all = [1] + sorted(six + nine)

dp = [100000 for i in range(100001)]
dp[0] = 0

for i in range(0, 100001):
    for el in all:
        temp = i + el
        if temp < 100001:
            dp[temp] = min(dp[temp], dp[i] + 1)

print(dp[money])


n = int(input())
num = [1]

x = 6
while x < 100000:
    num.append(x)
    x *= 6

x = 9
while x < 100000:
    num.append(x)
    x *= 9

dp = [n] * 110000
dp[0] = 0

for i in range(n):
    for j in num:
        dp[i + j] = min(dp[i + j], dp[i] + 1)

print(dp[n])

n = int(input())
num = [1]

x = 6
while x < 100000:
    num.append(x)
    x *= 6

x = 9
while x < 100000:
    num.append(x)
    x *= 9

dp = [n] * 1100000
dp[0] = 0

for i in range(n):
    for j in num:
        dp[i + j] = min(dp[i + j], dp[i] + 1)

print(dp[n])


import itertools

N, C = map(int, input().split())
D = []
for _ in range(C):
    D.append(list(map(int, input().split())))

diff_by_pos_color_pair = [[0 for _ in range(C)] for _ in range(3)]
for i in range(N):
    for j, color_from in enumerate(map(lambda x: int(x) - 1, input().split())):
        pos = (i + j) % 3
        for color_to in range(C):
            diff_by_pos_color_pair[pos][color_to] += D[color_from][color_to]

min_diff = float("inf")
for ccs in itertools.permutations(range(C), 3):
    diff = 0
    for pos, color in enumerate(ccs):
        diff += diff_by_pos_color_pair[pos][ccs[color]]
    min_diff = min(min_diff, diff)

print(min_diff)

import itertools

N, C = map(int, input().split())
# N, C = 500, 30

D = []
for _ in range(C):
    D.append(list(map(int, input().split())))
    # D.append([100] * C)

diff_by_pos_color_pair = [[0 for _ in range(C)] for _ in range(3)]
for i in range(N):
    for j, color_from in enumerate(map(lambda x: int(x) - 1, input().split())):
        # for j, color_from in enumerate([0] * N):
        pos = (i + j) % 3
        for color_to in range(C):
            diff_by_pos_color_pair[pos][color_to] += D[color_from][color_to]

min_diff = float("inf")
for ccs in itertools.permutations(range(C), 3):
    diff = 0
    for pos, color in enumerate(ccs):
        diff += diff_by_pos_color_pair[pos][color]
    min_diff = min(min_diff, diff)

print(min_diff)


import itertools

def get_discomfort(group, color, D):
    s = 0
    for c in group:
        s += D[c - 1][color - 1]
    return s

N, C = map(int, input().split())
D = [list(map(int, input().split())) for _ in range(C)]

grids = [[], [], []]
for i in range(N):
    c = list(map(int, input().split()))
    for j in range(N):
        grids[(i + j) % 3].append(c[j])

ans = float("inf")
for colors in itertools.permutations(list(range(C)), 3):
    colors = list(colors)
    s = 0
    for i, c in enumerate(colors):
        s += get_discomfort(grids[i], c, D)
    ans = min(ans, s)

print(ans)

import itertools

def get_discomfort(group_dic, color, D):
    s = 0
    for c, num in group_dic.items():
        s += D[c - 1][color - 1] * num
    return s

N, C = map(int, input().split())
D = [list(map(int, input().split())) for _ in range(C)]

from collections import Counter

grids = [Counter() for _ in range(3)]

for i in range(N):
    c = list(map(int, input().split()))
    for j in range(N):
        grids[(i + j) % 3][c[j]] += 1

ans = float("inf")
for colors in itertools.permutations(list(range(C)), 3):
    colors = list(colors)
    s = 0
    for i, c in enumerate(colors):
        s += get_discomfort(grids[i], c, D)
    ans = min(ans, s)

print(ans)


n = int(input())

s = []
for i in range(2, n + 1):
    j = n - i
    if j >= 2 and i + j == n:
        a = sum(map(int, str(i)))
        b = sum(map(int, str(j)))
        s.append(a + b)
print(min(s))

n = int(input())

s = []
for i in range(1, n):
    j = n - i
    if i + j == n:
        a = sum(map(int, str(i)))
        b = sum(map(int, str(j)))
        s.append(a + b)
print(min(s))


n = input().split()
if n[0] == 1 and sum(n):
    print(10)
else:
    print(sum(n))

n = list(map(int, list(input())))

if n[0] == 1 and sum(n) == 1:
    print(10)
else:
    print(sum(n))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03331/Python/s509317721.py", line 5, in <module>
    print(sum(n))
TypeError: unsupported operand type(s) for +: 'int' and 'str'


N = input()

ans = 0
for n in N:
    ans += n

print(ans)

N = input()

ans = 0
for n in N:
    ans += int(n)

if ans == 1:
    ans = 10

print(ans)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03331/Python/s099321384.py", line 5, in <module>
    ans += n
TypeError: unsupported operand type(s) for +=: 'int' and 'str'


n = int(input())
print(min([sum(map(int, str(i) + str(n - i))) for i in range(1, n // 2)]))

n = int(input())
print(min([sum(map(int, str(i) + str(n - i))) for i in range(1, n // 2 + 1)]))


N, A, B, K = map(int, input().split())

mod = 998244353
F = [1]
RF = []

def inv(x):
    res = 1
    k = mod - 2
    y = x
    while k:
        if k & 1:
            res = (res * y) % mod
        y = (y * y) % mod
        k //= 2
    return res

def init():
    for i in range(N):
        F.append((F[i] * (i + 1)) % mod)
    for i in F:
        RF.append(inv(i))

def comb(x, y):
    if y < 0 or x < y:
        return 0
    return (F[x] * ((inv(F[x - y]) * inv(F[y])) % mod)) % mod

ans = 0
init()
for a in range(N):
    b = (K - a * A) / B
    if b < 0:
        break
    if b.is_integer():
        ans += (comb(N, a) * (comb(N, int(b)))) % mod
print(ans % mod)

N, A, B, K = map(int, input().split())

mod = 998244353
fact = [1] * (N + 1)
ifact = [1] * (N + 1)

def init():
    for i in range(N):
        fact[i + 1] = fact[i] * (i + 1) % mod
        ifact[i + 1] = pow(fact[i + 1], mod - 2, mod)

def comb(x, y):
    if y < 0 or y > x:
        return 0
    return (fact[x] * ifact[x - y] * ifact[y]) % mod

ans = 0
init()
for a in range(N + 1):
    n = K - a * A
    if n < 0:
        break
    if n % B == 0:
        ans += (comb(N, a) * (comb(N, n // B))) % mod
print(ans % mod)


A, B = map(int, input())

print(max([A + B, A - B, A * B]))

A, B = map(int, input().split())

print(max([A + B, A - B, A * B]))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03337/Python/s268424429.py", line 1, in <module>
    A, B = map(int, input())
ValueError: invalid literal for int() with base 10: ' '


A, B = list(map(int, input().split()))
print(max(A + B, max(A - B.A * B)))

A, B = list(map(int, input().split()))
print(max(A + B, max(A - B, A * B)))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03337/Python/s852904721.py", line 2, in <module>
    print(max(A + B, max(A - B.A * B)))
AttributeError: 'int' object has no attribute 'A'


X = input().split()

A = int(X[0])
B = int(X[1])

p = A + B
m = A - B
k = A * B

if p > m and p > k:
    max_s = p
elif m > p and m > k:
    max_s = m
elif k > p and k > m:
    max_s = k
elif A == B and A == 0:
    max_s = p

print(max_s)

N = input().split()
for i in range(2):
    if i == 0:
        A = int(N[i])
    elif i == 1:
        B = int(N[i])

X_1 = A + B
X_2 = A - B
X_3 = A * B

max = X_1

if max < X_2:
    max = X_2
if max < X_3:
    max = X_3

print(max)


def cut_and_count(N: int, S: str) -> int:
    l, r = set([]), set([])
    for c in S:
        r.add(c)

    max_len = 0
    for c in S:
        l.add(c)
        r.discard(c)

        temp = len(l & r)
        max_len = max(max, temp)

    return max_len

if __name__ == "__main__":
    N = int(input())
    S = input()
    ans = cut_and_count(N, S)
    print(ans)

def cut_and_count(N: int, S: str) -> int:
    l, r = {}, {}
    for c in S:
        if c not in r:
            r[c] = 1
        else:
            r[c] += 1

    max_len = 0
    for c in S:
        if c not in l:
            l[c] = 1
        else:
            l[c] += 1
        r[c] -= 1

        ls = set(k for k, v in l.items() if v > 0)
        rs = set(k for k, v in r.items() if v > 0)

        temp = len(ls & rs)
        max_len = max(max_len, temp)

    return max_len

if __name__ == "__main__":
    N = int(input())
    S = input()
    ans = cut_and_count(N, S)
    print(ans)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03338/Python/s105927214.py", line 20, in <module>
    ans = cut_and_count(N, S)
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03338/Python/s105927214.py", line 12, in cut_and_count
    max_len = max(max, temp)
TypeError: '>' not supported between instances of 'int' and 'builtin_function_or_method'


N = int(input())
S = input()

print(max(len(set(S[:i]) & set(S[i:])) for i in range(1, N - 1)))

N = int(input())
S = input()

print(max(len(set(S[:i]) & set(S[i:])) for i in range(1, N)))


N = input()
S = list(input())

ans = 0
for i in range(1, N):
    left = set(S[:i])
    right = set(S[:i])

    both = left & right
    ans = max(len(both), ans)

print(ans)

N = int(input())
S = list(input())

ans = 0
for i in range(1, N):
    left = set(S[:i])
    right = set(S[i:])
    both = left & right
    ans = max(len(both), ans)

print(ans)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03338/Python/s796551276.py", line 5, in <module>
    for i in range(1, N):
TypeError: 'str' object cannot be interpreted as an integer


n = int(input())
s = input()
ans = max(len(set(s[:i]) & set(s[i:])) for i in range(1, n - 1))
print(ans)

n = int(input())
s = input()
ans = max(len(set(s[:i]) & set(s[i:])) for i in range(1, n))
print(ans)


N = int(input())
S = input()

ret = N
for i in range(N):
    a = S[:i]
    b = S[i + 1 :]
    n = a.count("W") + b.count("E")
    if n == 0:
        continue
    ret = min(ret, n)
print(ret)

N = int(input())
S = input()
x = 0
a = 0
idx = 0

for i in range(N):
    if S[i] == "W":
        x += 1
    else:
        x -= 1

    if x < a:
        a = x
        idx = i

w = S[0:idx].count("W")
e = S[idx + 1 : N].count("E")
print(w + e)


# coding: utf-8

n = int(input())
s = list(input())

for (i, x) in enumerate(s):
    if x == "E":
        s[i] = 1
    elif x == "W":
        s[i] = 0

min_changed_num = sum(s[1:n])

for i in range(1, n):
    left = i - sum(s[0:i])
    right = sum(s[i:n])
    changed_num = left + right
    if min_changed_num > changed_num:
        min_changed_num = changed_num

print(min_changed_num)

# coding: utf-8

n = int(input())
s = list(input())

for (i, x) in enumerate(s):
    if x == "E":
        s[i] = 1
    elif x == "W":
        s[i] = 0

left = 0
right = sum(s[1:n])
center = s[0]
min_changed_num = right

for i in range(1, n):
    left = left + (1 - center)
    center = s[i]
    right = right - center
    changed_num = left + right
    if min_changed_num > changed_num:
        min_changed_num = changed_num

print(min_changed_num)


n = int(input())
s = input()
while s.count("WE"):
    s = s.replace("WE", "")
ans = (n - len(s)) // 2
print(ans)

n = int(input())
s = input()
wcount = 0
wecount = 0
prev = ""
for c in s:
    if c == "W":
        if prev == "E":
            wcount = 0
        wcount += 1
    if wcount and c == "E":
        wcount -= 1
        wecount += 1
print(wecount)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins

def solve(inputs):
    persons = list(map(lambda x: x, inputs[0]))
    N = len(persons)
    counts = []
    for leader, _ in enumerate(persons):
        count = 0
        for p in range(0, leader):
            if persons[p] == "W":
                count += 1
        for p in range(leader + 1, N):
            if persons[p] == "E":
                count += 1
        counts.append(count)
    min = counts[0]
    for count in counts:
        if min > count:
            min = count

    return min

if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)

import sys
from functools import reduce
import copy
import math

sys.setrecursionlimit(4100000)

def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins

def solve(inputs):
    persons = list(inputs[0])

    count = [persons[1:].count("E")]

    for i in range(1, len(persons)):
        if i == 0:
            continue

        tmp = count[-1]
        if persons[i - 1] == "W":
            tmp += 1
        if persons[i] == "E":
            tmp -= 1
        count.append(tmp)

    return min(count)

def string_to_int(string):
    return list(map(int, string.split()))

if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)


n = int(input())
S = input()
s = [0 for i in range(n)]

for i in range(n):
    if S[i] == "E":
        s[i] = 1
min = n

for i in range(n):
    count = 0
    for j in range(n):
        if i < j and s[j] == 1:
            count += 1
        elif i > j and s[j] == 0:
            count += 1
    if count < min:
        min = count
print(min)

n = int(input())
S = input()
s = [0 for i in range(n)]

for i in range(n):
    if S[i] == "E":
        s[i] = 1
min = n

count = 0
for j in range(n):
    i = 0
    if i < j and s[j] == 1:
        count += 1
    elif i > j and s[j] == 0:
        count += 1
if count < min:
    min = count

for i in range(1, n):
    if s[i - 1] == 0:
        count += 1
    if s[i] == 1:
        count -= 1
    if count < min:
        min = count
print(min)


s = input().split()

WtoE = []
wtoec = 0
EtoW = []
etowc = 0

for c in s[1]:
    if c == "W":
        wtoec = wtoec + 1
    WtoE.append(wtoec)

for c in s[1][::-1]:
    if c == "E":
        etowc = etowc + 1
    EtoW.append(etowc)
EtoW.reverse()
print(WtoE)
print(EtoW)

a = []
for i in range(0, int(s[0])):
    ans = WtoE[i] + EtoW[i]
    if WtoE[i] != 0 and s[1][i] == "W" or EtoW[i] != 0 and s[1][i] == "E":
        ans = ans - 1

    a.append(ans)

print(min(a))

s = ["", ""]

s[0] = input()
s[1] = input()

WtoE = []
wtoec = 0
EtoW = []
etowc = 0

for c in s[1]:
    if c == "W":
        wtoec = wtoec + 1
    WtoE.append(wtoec)

for c in s[1][::-1]:
    if c == "E":
        etowc = etowc + 1
    EtoW.append(etowc)
EtoW.reverse()

a = []
for i in range(0, int(s[0])):
    ans = WtoE[i] + EtoW[i]
    if WtoE[i] != 0 and s[1][i] == "W" or EtoW[i] != 0 and s[1][i] == "E":
        ans = ans - 1

    a.append(ans)

print(min(a))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03339/Python/s685616573.py", line 8, in <module>
    for c in s[1]:
IndexError: list index out of range


N = int(input())
S = input()
S_list = list(S)
face = [-1, 1]
ans_index = N // 2
while ans_index != N - 1 and S[ans_index] == S[ans_index + face[S[ans_index] == "E"]]:
    ans_index += face[S[ans_index] == "E"]
# print(ans_index)
ans = 0
for i in range(len(S)):
    if i < ans_index and S[i] == "W":
        ans += 1
    elif ans_index == i:
        continue
    elif i > ans_index and S[i] == "E":
        ans += 1
print(ans)

N = int(input())
S = input()
E_cost = S.count("E")
W_cost = 0
ans = N
for s in S:
    if s == "E":
        E_cost -= 1
    ans = min(ans, E_cost + W_cost)
    if s == "W":
        W_cost += 1
print(ans)


n = int(input())
s = list(input())
cmin = n + 1
for i in range(n):
    c = s[:i].count("W") + s[i:].count("E")
    if cmin > c:
        cmin = c
print(cmin)

n = int(input())
s = list(input())
c = s[1:].count("E")
ans = c
for i in range(1, n):
    c -= 1 if s[i] == "E" else 0
    c += 1 if s[i - 1] == "W" else 0
    ans = min(c, ans)
print(ans)


import sys

N = int(sys.stdin.readline())
P = [int(sys.stdin.readline()) for _ in range(N)]
Q = [P.index(i) for i in range(1, N + 1)]
ans = 0
prv_q = 0
now = 0
for i in range(N):
    if prv_q > Q[i]:
        now = 0
    now += 1
    prv_q = Q[i]
    ans = max(ans, now)
print(N - ans)

import sys

N = int(sys.stdin.readline())
P = {int(sys.stdin.readline()): i for i in range(N)}
Q = [P[i] for i in range(1, N + 1)]

ans = 0
prv_q = 0
now = 0
for i in range(N):
    if prv_q > Q[i]:
        now = 0
    now += 1
    prv_q = Q[i]
    ans = max(ans, now)
print(N - ans)


n = int(input())
p = [0 for i in range(n)]
for i in range(n):
    p[i] = int(input())

visited = [0 for i in range(n)]
n_range = range(n)
for i in reversed(n_range):
    if visited[i] == 0:
        visited[i] = 1
        count = 1
        target = p[i] - 1
        for j in reversed(range(i)):
            if p[j] == target:
                count += 1
                visited[j] = count
                target -= 1
print(n - max(visited))

n = int(input())
p = [0 for i in range(n)]
for i in range(n):
    p[i] = int(input())

visited = [0 for i in range(n + 1)]

"""
for i in reversed(range(n)):
    if visited[i] == 0:
        visited[i] = 1
        count = 1
        target = p[i] - 1

        for j in reversed(range(i)):
            if p[j] == target:
                count += 1
                visited[j] = count
                target -= 1
"""
for i in range(n):
    visited[p[i]] = visited[p[i] - 1] + 1
print(n - max(visited))


n = int(input())
ppp = list(map(int, (input() for _ in range(n))))

tmp = [0] * n
for p in ppp:
    tmp[p] = tmp[p - 1] + 1

print(n - max(tmp))

n = int(input())
ppp = list(map(int, (input() for _ in range(n))))

tmp = [0] * (n + 1)
for p in ppp:
    tmp[p] = tmp[p - 1] + 1

print(n - max(tmp))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03346/Python/s389965586.py", line 6, in <module>
    tmp[p] = tmp[p - 1] + 1
IndexError: list assignment index out of range


def solve(n, aaa):
    if aaa[0] > 0:
        return -1
    if any(a1 - a0 > 1 for a0, a1 in zip(aaa, aaa[1:])):
        return -1
    ans = 0
    aaa.reverse()

    while any(aaa):
        while aaa[-1] == 0:
            aaa.pop()
        aaa.reverse()
        while aaa[-1] == 0:
            aaa.pop()
        aaa.reverse()

        new = [0] * (len(aaa) - 1)
        a1 = aaa[0]
        ap = 0
        for i, a0 in enumerate(aaa[1:]):
            if a1 == 0:
                a1 = a0
                continue
            ans += 1
            if a1 - a0 < 1:
                new[i] = ap = max(a1 - 1, ap)
            else:
                new[i] = ap
            a1 = a0
            if ap:
                ap -= 1
        if a1:
            ans += 1
        aaa = new
    return ans

n = int(input())
aaa = list(map(int, (input() for _ in range(n))))
print(solve(n, aaa))

def solve(n, aaa):
    if aaa[0] > 0:
        return -1
    if any(a1 - a0 > 1 for a0, a1 in zip(aaa, aaa[1:])):
        return -1
    ans = 0
    a0 = 0

    for a1 in aaa[1:]:
        if a1 - a0 != 1:
            ans += a0
        a0 = a1

    return ans + a0

n = int(input())
aaa = list(map(int, (input() for _ in range(n))))
print(solve(n, aaa))


a, b, c, d = map(int, input().split())
x = sorted(a, b)
y = sorted(c, b)

if (x[-1] - x[0]) <= d and (y[-1] - y[0]) <= d:
    print("Yes")
else:
    print("No")

a, b, c, d = map(int, input().split())
x = sorted([a, b])
y = sorted([c, b])

if (max(a, c) - min(a, c)) <= d:
    print("Yes")
elif (x[-1] - x[0]) <= d and (y[-1] - y[0]) <= d:
    print("Yes")
else:
    print("No")

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03351/Python/s078991385.py", line 2, in <module>
    x = sorted(a, b)
TypeError: sorted expected 1 argument, got 2


x = int(input())
ans = 1
for i in range(2, 1000):
    j = 2
    while i**j <= x:
        ans = max(ans, i**j)
    j += 1
    if i > x:
        break
print(ans)

x = int(input())
ans = 1
for i in range(2, 1000):
    j = 2
    while i**j <= x:
        ans = max(ans, i**j)
        j += 1
print(ans)


def pow(x, n):
    if n == 0:
        return 1
    value = pow(x, int(n / 2))
    value *= value
    if n % 2 == 1:
        value *= x
    return value

x = int(input())
li = [False] * (x + 1)
li[1] = True

for i in range(x):
    for j in range(2, x):
        idx = pow(i, j)
        if idx < x + 1:
            li[idx] = True

for i in reversed(range(x + 1)):
    if li[i]:
        print(i)
        break

x = int(input())
li = [False] * (x + 1)
li[1] = True

for i in range(x):
    for j in range(2, x):
        if i**j > x:
            break
        li[i**j] = True

for i in reversed(range(x + 1)):
    if li[i]:
        print(i)
        break


X = int(input())

for i in range(X, 0, -1):
    tmp = i
    if X % tmp:
        continue
    while tmp <= X:
        tmp *= tmp
    if tmp == X:
        print(i)

X = int(input())

ans = 1
for i in range(1, X):
    for j in range(2, X):
        tmp = i**j
        if tmp > X:
            break
        ans = max(tmp, ans)
print(ans)


x = int(input())

if x == 1:
    print("1")
    exit()

def func(p):
    q = p
    while q < x:
        q *= p
        if q == x:
            return q
            break

    if q / p == p:
        return 1
    else:
        return q / p

z = []
a = 1

while a <= x:
    z.append(func(a))
    a += 1

print(max(z))

x = int(input())

if x == 1:
    print("1")
    exit()

def func(p):
    q = p
    while q < x:
        q *= p
        if q == x:
            return q
    if q / p == p:
        return 1
    else:
        return q // p

z = []
a = 2

while a <= x:
    z.append(func(a))
    a += 1

print(max(z))


X = int(input())

ans = []
for i in range(1000):
    for j in range(1000):
        if i**j > X:
            continue
        ans.append(i**j)
print(max(ans))

X = int(input())

ans = []
for i in range(1, 1000):
    for j in range(2, 11):
        if i**j > X:
            continue
        ans.append(i**j)
print(max(ans))


#!/usr/bin/env python3
# -*- coding: utf-8 -*-

def main():
    S = input()
    K = int(input())
    result = set()

    for i in range(len(S) + 1):
        for j in range(i + 1, len(S) + 1):
            result.add(S[i:j])

    print(sorted(result)[K - 1])

if __name__ == "__main__":
    main()

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

def main():
    S = input()
    K = int(input())
    result = set()

    for i in range(5):
        for j in range(len(S)):
            result.add(S[j : j + i + 1])

    print(sorted(result)[K - 1])

if __name__ == "__main__":
    main()


s = str(input())
K = int(input())
# sがabcac の場合、a,bca,ac などは部分列(substring
# abc とabの場合、abの方が辞書順で小さいと判断する。
# abc とabaの場合、abaの方が小さい

substrings = set([])
for i in range(len(s) + 1):
    for j in range(i + 1, len(s) + 1):
        # print(i, j)
        substrings.add(s[i:j])

print(sorted(substrings)[K - 1])

s = str(input())
K = int(input())
# sがabcac の場合、a,bca,ac などは部分列(substring
# abc とabの場合、abの方が辞書順で小さいと判断する。
# abc とabaの場合、abaの方が小さい

substrings = set([])
for i in range(5):
    for j in range(len(s) - i):
        # print(i, j)
        substrings.add(s[j : j + i + 1])
# print(substrings)
print(sorted(substrings)[K - 1])


str_s = input()
int_k = int(input())

result = list()
for f in range(len(str_s)):
    pattern = set()
    if len(result) == int_k and str_s[f] > result[-1][0]:
        continue
    for t in range(f + 1, len(str_s) + 1):
        pattern.add(str_s[f:t])
        result = sorted(set(result + sorted(list(pattern))[:int_k]))[:int_k]

print(result[-1])

str_s = input()
int_k = int(input())

result = list()
for f in range(len(str_s)):
    pattern = set()
    for t in range(f + 1, f + 1 + int_k):
        pattern.add(str_s[f:t])
        result = sorted(set(result + list(pattern)))[:int_k]

print(result[-1])


# https://atcoder.jp/contests/abc097/tasks/arc097_a
# まずは愚直に実装してみる

S = input()
K = int(input())
candi = []
for s in range(len(S)):
    for e in range(s + 1, len(S) + 1):
        candi.append(S[s:e])
candi = list(set(candi))
candi.sort()
print(candi[K - 1])

# https://atcoder.jp/contests/abc097/tasks/arc097_a

# 辞書順に置いては文字の先頭が重要。
# 一文字目が速いやつから注目していく。
# 一文字目が同じだったらさらにその次の文字を注目する。

# atcoderandatcodeer
# a      a  a       # 1種
# at     an at      # 1種 #tは以下のすべてよりも辞書順があと
#        and        # 1種
#        anda       # 1種
#        andat      #

S = input()
K = int(input())

# 一番速い文字を検索してからそこからK文字見るのが一番早そう。
# ただし、K文字ない場合は辻褄合わせが必要
# てか計算量的に、こんなことしなくてもK文字目まで全列挙すればよくね？

# mi = min(S)
candi = []
for s in range(len(S)):
    for add in range(1, K + 1):
        candi.append(S[s : s + add])

candi = list(set(candi))
candi.sort()
print(candi[K - 1])


s = input()
K = int(input())
result = []
alphabet = list("abcdefghijklmnopqrstuvwxyz")

for u in alphabet:
    for i in range(len(s)):
        if s[i] == u:
            for j in range(i + 1, min(i + K + 1, len(s) + 1)):
                result.append(s[i:j])
    if len(result) > K:
        break

result = list(set(result))
result.sort()
# print(result)
# print(len(result))
print(result[K - 1])

s = input()
K = int(input())
subs = []
for i in range(0, len(s)):
    for j in range(i + 1, K + i + 1 if i + K <= len(s) else len(s) + 1):
        subs.append(s[i:j])

subs = list(set(subs))

subs.sort()
print(subs[K - 1])


s = input()
k = int(input())
n = len(list(s))
kouho = set()
for i in range(n):
    for d in range(1, k + 1):
        if i + d < n:
            kouho.add(s[i : i + d])
ans = list(kouho)
ans.sort()
print(ans[k - 1])

s = input()
k = int(input())
n = len(list(s))
kouho = set()
for i in range(n):
    for d in range(1, k + 1):
        if i + d <= n:
            kouho.add(s[i : i + d])
ans = list(kouho)
ans.sort()
# print(ans)
print(ans[k - 1])

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03353/Python/s674016265.py", line 11, in <module>
    print(ans[k - 1])
IndexError: list index out of range


s = input()
K = int(input())

S = set([])
for i in range(len(s)):
    for j in range(i + 1, len(s) + 1):
        # print(f'{s[i:j]=}')
        S.add(s[i:j])
# print(f'{S=}')
# print(f'{sorted(S)=}')
ans = sorted(S)[K - 1]
print(ans)

s = input()
K = int(input())

S = set([])
for i in range(len(s)):
    for j in range(i + 1, i + 1 + K):
        # print(f'{s[i:j]=}')
        S.add(s[i:j])
# print(f'{S=}')
# print(f'{sorted(S)=}')
ans = sorted(S)[K - 1]
print(ans)


s = input()
K = int(input())
alphabet = list("abcdefghijklmnopqrstuvwxyz")
result = []

for u in alphabet:
    for i in range(len(s)):
        if s[i] == u:
            for j in range(i + 1, min(i + K + 1, len(s) + 1)):
                result.append(s[i:j])
    if len(result) > K:
        break

result = list(set(result))
result.sort()
# print(result)
# print(len(result))
print(result[K - 1])

s = input()
K = int(input())
alphabet = list("abcdefghijklmnopqrstuvwxyz")
result = []

for u in alphabet:
    for i in range(len(s)):
        if s[i] == u:
            for j in range(i + 1, min(i + K + 1, len(s) + 1)):
                result.append(s[i:j])
    result = list(set(result))
    if len(result) > K:
        break

result.sort()
print(result[K - 1])


s = input()
K = int(input())

s_set = set()
for i in range(len(s) + 1):
    for j in range(i + 1, len(s) + 1):
        s_set.add(s[i:j])
s_list = list(s_set)
s_list.sort()
print(s_list[K - 1])

s = input()
K = int(input())

s_set = set()
for i in range(len(s)):
    for j in range(i + 1, i + K + 1):
        if j > len(s) + 1:
            break
        s_set.add(s[i:j])
s_list = list(s_set)
s_list.sort()
print(s_list[K - 1])


s = input()
k = int(input())
a = set()
for i in range(len(s)):
    for j in range(i + 1, len(s) + 1):
        a.add(s[i:j])
print(sorted(list(a))[k - 1])

s = input()
k = int(input())
a = set()
for i in range(len(s) + 1):
    for j in range(1, 6):
        a.add(s[i : i + j])
print(sorted(list(a))[k])


from heapq import nsmallest

s = input()
K = int(input())
subs = set()
for i in range(len(s)):
    for j in range(i + 1, len(s) + 1):
        subs.add(s[i:j])
arr = list(subs)
print(nsmallest(K, arr)[-1])

from heapq import nsmallest

s = input()
K = int(input())
subs = set()
for i in range(len(s)):
    for j in range(i + 1, min(i + 6, len(s) + 1)):
        subs.add(s[i:j])
arr = list(subs)
print(nsmallest(K, arr)[-1])


S = input()
K = int(input())
N = len(S)
substrs = set()

for i in range(N):
    cur = S[i]
    if cur not in substrs:
        substrs.add(cur)
    for j in range(i + 1, N):
        cur += S[j]
        if cur not in substrs:
            substrs.add(cur)

substrs = sorted(substrs)
print(substrs[K - 1])

S = input()
K = int(input())
N = len(S)
substrs = set()

for i in range(N):
    cur = S[i]
    if cur not in substrs:
        substrs.add(cur)
    for j in range(i + 1, min(N, i + 6)):
        cur += S[j]
        if cur not in substrs:
            substrs.add(cur)

substrs = sorted(substrs)
print(substrs[K - 1])