Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(input()) for _ in range(N)]

max_A = sorted(A)[-1]
second_A = sorted(A)[-2]

for n in range(N):
    if A[n] != max_A:
        print(max_A)
    else:
        print(second_A)

Fixed submission:
r = int(input())
print(3 * r **2)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
for n in range(N):
    A.append(int(input()))

max_A = sorted(A)[-1]
second_A = sorted(A)[-2]

for n in range(N):
    if A[n] != max(A):
        print(max(A))
    else:
        print(second_A)

Fixed submission:
N = int(input())
A = [int(input()) for _ in range(N)]

max_A = sorted(A)[-1]
second_A = sorted(A)[-2]

for n in range(N):
    if A[n] != max_A:
        print(max_A)
    else:
        print(second_A)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
for n in range(N):
    A.append(int(input()))

max_A = sorted(A)[-1]
second_A = sorted(A)[-2]
max_list = [i for i, x in enumerate(A) if x == max(A)]

if len(max_list) >= 2:
    for n in range(N):
        print(max_A)

else:
    for n in range(N):
        if A[n] != max(A):
            print(max(A))
        else:
            print(second_A)

Fixed submission:
N = int(input())
A = [int(input()) for _ in range(N)]

max_A = sorted(A)[-1]
second_A = sorted(A)[-2]

for n in range(N):
    if A[n] != max_A:
        print(max_A)
    else:
        print(second_A)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
for n in range(N):
    A.append(int(input()))

for n in range(N):
    max_before = max(A[:n], default=0)
    max_after = max(A[n+1:], default=0)
    ans = max(max_before, max_after)
    print(ans)


Fixed submission:
N = int(input())
A = [int(input()) for _ in range(N)]

max_A = sorted(A)[-1]
second_A = sorted(A)[-2]

for n in range(N):
    if A[n] != max_A:
        print(max_A)
    else:
        print(second_A)

Buggy python submission (verdict: Time Limit Exceeded):
import copy

N = int(input())
A = []
for n in range(N):
    A.append(int(input()))

for n in range(N):
    B = copy.deepcopy(A)
    del B[n]
    print(max(B))

Fixed submission:
N = int(input())
A = [int(input()) for _ in range(N)]

max_A = sorted(A)[-1]
second_A = sorted(A)[-2]

for n in range(N):
    if A[n] != max_A:
        print(max_A)
    else:
        print(second_A)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
from collections import deque

n = int(input())
A = []
count = 0
for _ in range(n):
    a = int(input())
    if len(A) == 0:
        A.append(a)
        count += 1
        continue
    i = bisect.bisect_left(A, a)
    if i == 0:
        dq_A = deque(A)
        dq_A.appendleft(a)
        A = list(dq_A)
        count += 1
    else:
        A[i-1] = a

ans = count
print(ans)

Fixed submission:
import bisect
from collections import deque

n = int(input())
A = []
dq_A = deque(A)
count = 0
for _ in range(n):
    a = int(input())
    if len(dq_A) == 0:
        dq_A.appendleft(a)
        count += 1
        continue
    i = bisect.bisect_left(dq_A, a)
    if i == 0:
        dq_A.appendleft(a)
        count += 1
    else:
        dq_A[i-1] = a

ans = count
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect

n = int(input())
A = []
count = 0
for _ in range(n):
    a = int(input())
    if len(A) == 0:
        A.append(a)
        count += 1
        continue
    i = bisect.bisect_left(A, a)
    if i == 0:
        A = [a] + A
        count += 1
    else:
        A[i-1] = a

ans = count
print(ans)

Fixed submission:
import bisect
from collections import deque

n = int(input())
A = []
dq_A = deque(A)
count = 0
for _ in range(n):
    a = int(input())
    if len(dq_A) == 0:
        dq_A.appendleft(a)
        count += 1
        continue
    i = bisect.bisect_left(dq_A, a)
    if i == 0:
        dq_A.appendleft(a)
        count += 1
    else:
        dq_A[i-1] = a

ans = count
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect

n = int(input())
A = []
count = 0
for _ in range(n):
    a = int(input())
    if len(A) == 0:
        A.append(a)
        count += 1
        continue
    i = bisect.bisect_left(A, a)
    if i == 0:
        A.insert(0, a)
        count += 1
    else:
        A[i-1] = a

ans = count
print(ans)

Fixed submission:
import bisect
from collections import deque

n = int(input())
A = []
dq_A = deque(A)
count = 0
for _ in range(n):
    a = int(input())
    if len(dq_A) == 0:
        dq_A.appendleft(a)
        count += 1
        continue
    i = bisect.bisect_left(dq_A, a)
    if i == 0:
        dq_A.appendleft(a)
        count += 1
    else:
        dq_A[i-1] = a

ans = count
print(ans)
Buggy python submission (verdict: Runtime Error):
A, B, C, D = map(int, input().split())

X = list(range(A, B+1))

c = A % C
d = A % D

if c == 0:
    I = list(range(A, B+1, C))
else:
    I = list(range(A+C-c, B+1, C))
if d == 0:
    J = list(range(A, B+1, D))
else:
    J = list(range(A+D-d, B+1, D))

ans_list = list(set(X) - set(I) - set(J))
print(len(ans_list))


Fixed submission:
import fractions

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

# B以下でC, Dで割り切れるものの個数
b_c = B // C
b_d = B // D

# B以下でCでもDでも割り切れるものの個数
b_c_d = B // ((C*D)//fractions.gcd(C,D))

# A未満でC, Dで割り切れるものの個数
a_c = (A-1) // C
a_d = (A-1) // D

# A未満でCでもDでも割り切れるものの個数
a_c_d = (A-1) // ((C*D)//fractions.gcd(C,D))


count = b_c + b_d - b_c_d - (a_c + a_d - a_c_d)

ans = B-A+1 - count
print(int(ans))

Buggy python submission (verdict: Runtime Error):
A, B, C, D = map(int, input().split())

X = list(range(A, B+1))

c = A % C
d = A % D

if c == 0:
    I = list(range(A, B+1, C))
else:
    I = list(range(A+C-c, B+1, C))
if d == 0:
    J = list(range(A, B+1, D))
else:
    J = list(range(A+D-d, B+1, D))

ans_list = list(set(X) - set(I) - set(J))
print(ans_list)


Fixed submission:
import fractions

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

# B以下でC, Dで割り切れるものの個数
b_c = B // C
b_d = B // D

# B以下でCでもDでも割り切れるものの個数
b_c_d = B // ((C*D)//fractions.gcd(C,D))

# A未満でC, Dで割り切れるものの個数
a_c = (A-1) // C
a_d = (A-1) // D

# A未満でCでもDでも割り切れるものの個数
a_c_d = (A-1) // ((C*D)//fractions.gcd(C,D))


count = b_c + b_d - b_c_d - (a_c + a_d - a_c_d)

ans = B-A+1 - count
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
A, B, C, D = map(int, input().split())

sum = 0
for n in range(A, B+1):
    if (n % C != 0) and (n % D != 0):
        sum += 1
print(sum)

Fixed submission:
import fractions

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

# B以下でC, Dで割り切れるものの個数
b_c = B // C
b_d = B // D

# B以下でCでもDでも割り切れるものの個数
b_c_d = B // ((C*D)//fractions.gcd(C,D))

# A未満でC, Dで割り切れるものの個数
a_c = (A-1) // C
a_d = (A-1) // D

# A未満でCでもDでも割り切れるものの個数
a_c_d = (A-1) // ((C*D)//fractions.gcd(C,D))


count = b_c + b_d - b_c_d - (a_c + a_d - a_c_d)

ans = B-A+1 - count
print(int(ans))
Buggy python submission (verdict: Time Limit Exceeded):
h, w = map(int, input().split())
S = []
for _ in range(h):
    s = str(input())
    S.append(s)

# leftの個数カウントを行う
Left_count = [[0 for _ in range(w)] for _ in range(h)]
for i in range(h):
    s = S[i]
    count = 0
    for j in range(w):
        if s[j] == '#':
            count = 0
            continue
        else:
            count += 1
            Left_count[i][j] = count

# Rightの個数カウントを行う
Right_count = [[0 for _ in range(w)] for _ in range(h)]
for i in range(h):
    s = S[i][::-1]
    count = 0
    for j in range(w):
        if s[j] == '#':
            count = 0
            continue
        else:
            count += 1
            Right_count[i][j] = count
for i in range(h):
    Right_count[i] = Right_count[i][::-1]

# Upの個数カウントを行う
Up_count = [[0 for _ in range(w)] for _ in range(h)]
for j in range(w):
    count = 0
    for i in range(h):
        if S[i][j] == '#':
            count = 0
            continue
        else:
            count += 1
            Up_count[i][j] = count

# Downの個数カウントを行う
Down_count = [[0 for _ in range(w)] for _ in range(h)]
for j in range(w):
    count = 0
    for i in range(h-1,-1,-1):
        if S[i][j] == '#':
            count = 0
            continue
        else:
            count += 1
            Down_count[i][j] = count

ans = 0
for i in range(h):
    for j in range(w):
        tot_ij = Left_count[i][j] + Right_count[i][j] + Down_count[i][j] + Up_count[i][j] -3
        ans = max(tot_ij, ans)
print(ans)

Fixed submission:
h, w = map(int, input().split())
S = []
for _ in range(h):
    s = str(input())
    S.append(s)

# leftの個数カウントを行う
Left_count = [[0 for _ in range(w)] for _ in range(h)]
for i in range(h):
    s = S[i]
    count = 0
    for j in range(w):
        if s[j] == '#':
            count = 0
            continue
        else:
            count += 1
            Left_count[i][j] = count

# Rightの個数カウントを行う
Right_count = [[0 for _ in range(w)] for _ in range(h)]
for i in range(h):
    s = S[i][::-1]
    count = 0
    for j in range(w):
        if s[j] == '#':
            count = 0
            continue
        else:
            count += 1
            Right_count[i][j] = count
for i in range(h):
    Right_count[i] = Right_count[i][::-1]

# Upの個数カウントを行う
Up_count = [[0 for _ in range(w)] for _ in range(h)]
for j in range(w):
    count = 0
    for i in range(h):
        if S[i][j] == '#':
            count = 0
            continue
        else:
            count += 1
            Up_count[i][j] = count

# Downの個数カウントを行う
Down_count = [[0 for _ in range(w)] for _ in range(h)]
for j in range(w):
    count = 0
    for i in range(h-1,-1,-1):
        if S[i][j] == '#':
            count = 0
            continue
        else:
            count += 1
            Down_count[i][j] = count

ans = 0
for i in range(h):
    for j in range(w):
        tot_ij = Left_count[i][j] + Right_count[i][j] + Down_count[i][j] + Up_count[i][j] -3
        ans = max(tot_ij, ans)
print(ans)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)

cb_dict = {}
for _ in range(m):
    b, c = map(int, input().split())
    new = {c:b}
    if c in cb_dict.keys():
        cb_dict[c] += b
    else:
        cb_dict.update(new)

cb_dict = sorted(cb_dict.items(), key=lambda x:x[0], reverse=True)

now_c = 0
now_b = 0
for i in range(n):
    if A[i] =< cb_dict[now_c][0]:
        A[i] = cb_dict[now_c][0]
        now_b += 1
    if now_b == cb_dict[now_c][1]:
        now_c += 1
    if now_c > len(cb_dict)-1:
        break

ans = sum(A)
print(ans)

Fixed submission:
n, m = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)

cb_dict = {}
for _ in range(m):
    b, c = map(int, input().split())
    new = {c:b}
    if c in cb_dict.keys():
        cb_dict[c] += b
    else:
        cb_dict.update(new)

cb_dict = sorted(cb_dict.items(), key=lambda x:x[0], reverse=True)

now_c = 0
now_b = 0
for i in range(n):
    if A[i] >= cb_dict[now_c][0]:
        break
    else:
        A[i] = cb_dict[now_c][0]
        now_b += 1
        if now_b == cb_dict[now_c][1]:
            now_c += 1
            now_b = 0
        if now_c > len(cb_dict)-1:
            break

ans = sum(A)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import heapq

x, y, z, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A = sorted(A, reverse=True)
B = sorted(B, reverse=True)
C = sorted(C, reverse=True)


AB = []

for i in range(x):
    for j in range(y):
        AB.append(A[i]+B[j])

AB = sorted(AB, reverse=True)
AB = AB[:min(k, x*y)]
# print(AB)

ABC = []
for l in range(min(k, x*y)):
    for m in range(z):
        ABC.append(AB[l] + C[m])

ABC = sorted(ABC, reverse=True)
for i in range(k):
    print(ABC[i])



# ------------優先度付きキュー----------

# hq = []
# heapq.heapify(hq)
# i, j, l = 0, 0, 0

# heapq.heappush(hq, [(A[i]+B[j]+C[l])*-1, i, j, l])
# Used = []

# for i in range(k):
#     now = heapq.heappop(hq)
#     print(now[0]*-1)
#     i = now[1]
#     j = now[2]
#     l = now[3]

#     if i >= x-1:
#         pass
#     elif [(A[i+1]+B[j]+C[l])*-1, i+1, j, l] not in Used:
#         Used.append([(A[i+1]+B[j]+C[l])*-1, i+1, j, l])
#         heapq.heappush(hq, [(A[i+1]+B[j]+C[l])*-1, i+1, j, l])
        
#     if j >= y-1:
#         pass
#     elif [(A[i]+B[j+1]+C[l])*-1, i, j+1, l] not in Used:
#         Used.append([(A[i]+B[j+1]+C[l])*-1, i, j+1, l])
#         heapq.heappush(hq, [(A[i]+B[j+1]+C[l])*-1, i, j+1, l])
        
#     if l >= z-1:
#         pass
#     elif [(A[i]+B[j]+C[l+1])*-1, i, j, l+1] not in Used:
#         Used.append([(A[i]+B[j]+C[l+1])*-1, i, j, l+1])
#         heapq.heappush(hq, [(A[i]+B[j]+C[l+1])*-1, i, j, l+1])
        
#     # print(hq)

Fixed submission:
import heapq

x, y, z, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A = sorted(A, reverse=True)
B = sorted(B, reverse=True)
C = sorted(C, reverse=True)

hq = []
heapq.heapify(hq)
i, j, l = 0, 0, 0

heapq.heappush(hq, [(A[i]+B[j]+C[l])*-1, i, j, l])
Used = []

for i in range(k):
    now = heapq.heappop(hq)
    print(now[0]*-1)
    i = now[1]
    j = now[2]
    l = now[3]

    if i >= x-1:
        pass
    elif [(A[i+1]+B[j]+C[l])*-1, i+1, j, l] not in Used:
        Used.append([(A[i+1]+B[j]+C[l])*-1, i+1, j, l])
        heapq.heappush(hq, [(A[i+1]+B[j]+C[l])*-1, i+1, j, l])
        
    if j >= y-1:
        pass
    elif [(A[i]+B[j+1]+C[l])*-1, i, j+1, l] not in Used:
        Used.append([(A[i]+B[j+1]+C[l])*-1, i, j+1, l])
        heapq.heappush(hq, [(A[i]+B[j+1]+C[l])*-1, i, j+1, l])
        
    if l >= z-1:
        pass
    elif [(A[i]+B[j]+C[l+1])*-1, i, j, l+1] not in Used:
        Used.append([(A[i]+B[j]+C[l+1])*-1, i, j, l+1])
        heapq.heappush(hq, [(A[i]+B[j]+C[l+1])*-1, i, j, l+1])
        
    # print(hq)
Buggy python submission (verdict: Runtime Error):
S = str(input())
count = 0
X =[]
for s in S:
    if s == 'A' or s == 'T' or s == 'C' or s == 'G':
        count += 1
    else:
        X.append(count)
        count = 0
print(int(max(X)))

Fixed submission:
S = str(input())

count = 0
X =[]
for n in range(len(S)):
    if n != len(S) -1:
        if S[n] == 'A' or S[n] == 'T' or S[n] == 'C' or S[n] == 'G':
            count += 1
        else:
            X.append(count)
            count = 0
    else:
        if S[n] == 'A' or S[n] == 'T' or S[n] == 'C' or S[n] == 'G':
            count += 1
            X.append(count)
        else:
            X.append(count)
print(int(max(X)))

Buggy python submission (verdict: Runtime Error):
S = str(input())
count = 0
X =[]
for s in S:
    if s == 'A' or s == 'T' or s == 'C' or s == 'G':
        count += 1
    else:
        X.append(count)
print(int(max(X)))

Fixed submission:
S = str(input())

count = 0
X =[]
for n in range(len(S)):
    if n != len(S) -1:
        if S[n] == 'A' or S[n] == 'T' or S[n] == 'C' or S[n] == 'G':
            count += 1
        else:
            X.append(count)
            count = 0
    else:
        if S[n] == 'A' or S[n] == 'T' or S[n] == 'C' or S[n] == 'G':
            count += 1
            X.append(count)
        else:
            X.append(count)
print(int(max(X)))
Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = str(input())
W = []
L = []
R = []
for q in range(Q):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

for s in S:
    W.append(s)

for n in range(N-1):
    if W[n] == 'A' and W[n+1] == 'C':
        W[n] = 'x'

for q in range(Q):
    print(W[L[q]-1:R[q]-1].count('x'))

Fixed submission:
N, Q = map(int, input().split())
S = str(input())
W = [0] * (N+1)
L = []
R = []
for q in range(Q):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

for n in range(N-1):
    W[n+1] = W[n] + (1 if S[n:n+2] == 'AC' else 0)    

for q in range(Q):
    print(W[R[q]-1]-W[L[q]-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = str(input())
L = []
R = []
for q in range(Q):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

for q in range(Q):
    S_temp = S[L[q]-1:R[q]]
    count = S_temp.count('AC')
    print(count)


Fixed submission:
N, Q = map(int, input().split())
S = str(input())
W = [0] * (N+1)
L = []
R = []
for q in range(Q):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

for n in range(N-1):
    W[n+1] = W[n] + (1 if S[n:n+2] == 'AC' else 0)    

for q in range(Q):
    print(W[R[q]-1]-W[L[q]-1])
Buggy python submission (verdict: Runtime Error):
N = int(input())
X = []
U = []
count = 0

for _ in range(N):
    x, u = map(str, input().split())
    X.append(float(x))
    if u == 'JPY':
        U.append(1)
    else:
        U.append(380000)

for n in range(N):
    count += X[n] * U[n]

print(count)





Fixed submission:
S = str(input())
S = S.replace('/','')

if int(S) <= 20190430:
    print('Heisei')
else:
    print('TBD')
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
H = list(map(int, input().split()))

Dp = [0]

for i in range(1, n):
    can = []
    if i < k:
        for j in range(i):
            c = abs(H[i]-H[i-j-1]) + Dp[i-j-1]
            can.append(c)
    else:
        for j in range(k):
            c = abs(H[i]-H[i-j-1]) + Dp[i-j-1]
            can.append(c)
    Dp.append(min(can))

ans = Dp[-1]
print(ans)

Fixed submission:
n, k = map(int, input().split())
H = list(map(int, input().split()))

Dp = [0]

for i in range(1, n):
    can = []
    if i < k:
        for j in range(i):
            c = abs(H[i]-H[i-j-1]) + Dp[i-j-1]
            can.append(c)
    else:
        for j in range(k):
            c = abs(H[i]-H[i-j-1]) + Dp[i-j-1]
            can.append(c)
    Dp.append(min(can))

ans = Dp[-1]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, w = map(int, input().split())
W = []
V = []
for _ in range(n):
    s, t = map(int, input().split())
    W.append(s)
    V.append(t)

Dp = [[0 for _ in range(w+1)] for _ in range(n+1)]

for i in range(n):
    for j in range(w+1):
        #対象となる重さjよりも、見ているものの重さが小さい時
        if W[i] <= j:
            Dp[i+1][j] = max(Dp[i][j], Dp[i][j-W[i]]+V[i])
        else:
            Dp[i+1][j] = Dp[i][j]

ans = Dp[-1][-1]
print(ans)

Fixed submission:
n, w = map(int, input().split())
W = []
V = []
for _ in range(n):
    s, t = map(int, input().split())
    W.append(s)
    V.append(t)

Dp = [[0 for _ in range(w+1)] for _ in range(n+1)]

for i in range(n):
    for j in range(w+1):
        #対象となる重さjよりも、見ているものの重さが小さい時
        if W[i] <= j:
            Dp[i+1][j] = max(Dp[i][j], Dp[i][j-W[i]]+V[i])
        else:
            Dp[i+1][j] = Dp[i][j]

ans = Dp[-1][-1]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = str(input())
t = str(input())

len_s = len(s)
len_t = len(t)

DP = [[0 for _ in range(len_t+1)] for _ in range(len_s+1)]

for i in range(len_s):
    for j in range(len_t):
        if s[i] == t[j]:
            DP[i+1][j+1] = max(DP[i][j]+1, DP[i+1][j+1])
        else:
            DP[i+1][j+1] = max(DP[i+1][j], DP[i+1][j+1])
            DP[i+1][j+1] = max(DP[i][j+1], DP[i+1][j+1])

i = len_s
j = len_t
ans = ''

while i > 0 and j > 0:
    if DP[i][j] == DP[i-1][j]:
        i -= 1
    elif DP[i][j] == DP[i][j-1]:
        j -= 1
    else:
        ans = s[i-1] + ans
        i -= 1
        j -= 1
print(ans)
 

Fixed submission:
s = str(input())
t = str(input())

len_s = len(s)
len_t = len(t)

DP = [[0 for _ in range(len_t+1)] for _ in range(len_s+1)]

for i in range(len_s):
    for j in range(len_t):
        if s[i] == t[j]:
            DP[i+1][j+1] = max(DP[i][j]+1, DP[i+1][j+1])
        else:
            DP[i+1][j+1] = max(DP[i+1][j], DP[i+1][j+1])
            DP[i+1][j+1] = max(DP[i][j+1], DP[i+1][j+1])

i = len_s
j = len_t
ans = ''

while i > 0 and j > 0:
    if DP[i][j] == DP[i-1][j]:
        i -= 1
    elif DP[i][j] == DP[i][j-1]:
        j -= 1
    else:
        ans = s[i-1] + ans
        i -= 1
        j -= 1
print(ans)
Buggy python submission (verdict: Runtime Error):
S = str(input())
K = int(input())
L = []

count = 0
for s in S:
    count += 1
    if s != '1':
        t = s
        break

if K < count:
    print(1)
else:
    print(int(t)) 



Fixed submission:
S = str(input())
K = int(input())
L = []

count = 0
for s in S:
    count += 1
    if s != '1':
        t = s
        break
    t = s

if K < count:
    print(1)
else:
    print(int(t))
Buggy python submission (verdict: Time Limit Exceeded):
n, m, Q = map(int, input().split())
LR = [[0 for _ in range(n)] for _ in range(n)]
for _ in range(m):
    l, r = map(int, input().split())
    LR[l-1][r-1] += 1

# 各Lについて累積和を取る
LR_rui = [[0] for _ in range(n)]
for i in range(n):
    for j in range(n):
        LR_rui[i].append(LR[i][j]+LR_rui[i][-1])

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



Fixed submission:
n, m, Q = map(int, input().split())
LR = [[0 for _ in range(n)] for _ in range(n)]
for _ in range(m):
    l, r = map(int, input().split())
    LR[l-1][r-1] += 1

# 二次元累積和の作成
LR_rui = [[0 for _ in range(n+1)] for _ in range(n+1)]
# 各Lについての累積
for i in range(n):
    for j in range(n):
        LR_rui[i+1][j+1] = LR_rui[i+1][j]+LR[i][j]
# 各Rについての累積:
for i in range(n):
    for j in range(n):
        LR_rui[i+1][j+1] = LR_rui[i+1][j+1] + LR_rui[i][j+1]

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

Buggy python submission (verdict: Time Limit Exceeded):
n, m, Q = map(int, input().split())
LR = [[0 for _ in range(n)] for _ in range(n)]
for _ in range(m):
    l, r = map(int, input().split())
    LR[l-1][r-1] += 1

# 各Lについて累積和を取る
LR_rui = [[0] for _ in range(n)]
for i in range(n):
    for j in range(n):
        LR_rui[i].append(LR[i][j]+LR_rui[i][-1])

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



Fixed submission:
n, m, Q = map(int, input().split())
LR = [[0 for _ in range(n)] for _ in range(n)]
for _ in range(m):
    l, r = map(int, input().split())
    LR[l-1][r-1] += 1

# 二次元累積和の作成
LR_rui = [[0 for _ in range(n+1)] for _ in range(n+1)]
# 各Lについての累積
for i in range(n):
    for j in range(n):
        LR_rui[i+1][j+1] = LR_rui[i+1][j]+LR[i][j]
# 各Rについての累積:
for i in range(n):
    for j in range(n):
        LR_rui[i+1][j+1] = LR_rui[i+1][j+1] + LR_rui[i][j+1]

for _ in range(Q):
    p, q = map(int, input().split())
    ans = LR_rui[q][q] - LR_rui[p-1][q] - LR_rui[q][p-1] + LR_rui[p-1][p-1]
    print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())

def get_ans(x):
    if x == 0:
        return ['0']
    d = []
    i = 0
    div = 1
    while x != 0:
        if x % (div*2) == 0:
            d.append('0')
        else:
            d.append('1')
            x -= div
        i += 1
        div = div * (-2)
    return d

a = get_ans(N)
b = list(reversed(a))
ans = ''.join(b)
print(ans)

Fixed submission:
N, K = map(int, input().split())

if N % K == 0:
    ans = 0
else:
    ans = 1

print(ans)
Buggy python submission (verdict: Runtime Error):
import bisect

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

for n in range(N):
    A_n.append(A[n]-n)

A_n = sorted(A_n, reverse=True)

can_f = A_n[N//2]
can_s = A_n[N//2 + 1]

ans_f = 0
ans_s = 0

for n in range(N):
    ans_f += abs(A_n[n]-can_f)

for n in range(N):
    ans_s += abs(A_n[n]-can_s)

ans = min(ans_f, ans_s)
print(ans)

Fixed submission:
import bisect

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

for n in range(N):
    A_n.append(A[n]-(n+1))

A_n = sorted(A_n, reverse=True)

can_f = A_n[N//2]
ans_f = 0
for n in range(N):
    ans_f += abs(A_n[n]-can_f)


if N > 1:
    ans_s = 0
    can_s = A_n[N//2+1]
    for n in range(N):
        ans_s += abs(A_n[n]-can_s)
else:
    ans_s = 10**10

ans = min(ans_f, ans_s)
print(ans)