Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import heapq
from collections import defaultdict
n, k = map(int, input().split())
td = [list(map(int, input().split())) for _ in range(n)]

td = sorted(td, key = lambda x: x[1], reverse = True)
sushi_types = set([])
sushi_tops = []
sushi_remains = []
for t, d in td:
    if not t in sushi_types:
        sushi_types.add(t)
        sushi_tops.append((t, d))
    else:
        sushi_remains.append((t, d))

n_types = len(sushi_types)
ans = sum([d for _, d in sushi_tops][:k]) + k**2
answers = [ans]
eat_types = set([t for t, _ in sushi_tops][:k])
i = 0
for t, d in sushi_tops[::-1]:
    eat_types.remove(t)
    while i < len(sushi_remains):
        t_r, d_r = sushi_remains[i]
        if t_r not in eat_types:
            i += 1
        else:
            ans = ans - d + d_r - (2*len(eat_types)+1)
            answers.append(ans)
            break
    # print(ans, (t, d), len(eat_types))
print(max(answers))

Fixed submission:
n, k = map(int, input().split())
td = [list(map(int, input().split())) for _ in range(n)]

td = sorted(td, key = lambda x: x[1], reverse = True)
eat_types = set()
sushi_dup = []
value = 0
for t, d in td[:k]:
    if not t in eat_types:
        eat_types.add(t)
    else:
        sushi_dup.append(d)
    value += d

ans = value + len(eat_types)**2
for t, d in td[k:]:
    if len(sushi_dup) == 0:
        break
    
    if t in eat_types:
        continue
    else:
        eat_types.add(t)
        r = sushi_dup.pop()
        value += d - r
        ans = max(ans, value + len(eat_types)**2)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
from collections import deque
h, w = map(int, input().split())
s = [input() for _ in range(h)]

segment = np.zeros((h, w), dtype = np.int32)
idx = 1
dxy = [[1, 0], [0, 1], [-1, 0], [0, -1]]
for y in range(h):
    for x in range(w):
        if segment[y, x] == 0:
            segment[y, x] = idx
            state = s[y][x]
            que = deque([[y, x, state]])
            while len(que) > 0:
                y_cur, x_cur, state = que.popleft()
                for dx, dy in dxy:
                    y_next = y_cur + dy
                    x_next = x_cur + dx
                    state_next = '.' if state == '#' else '#'
                    if x_next < 0 or y_next < 0 or x_next >= w or y_next >= h:
                        continue
                    elif s[y_next][x_next] != state_next:
                        continue
                    elif segment[y_next, x_next] == 0:
                        segment[y_next, x_next] = idx
                        que.append((y_next, x_next, state_next))
            idx += 1

# print(segment)
idx_max = np.max(segment)
nbw = [[0, 0] for _ in range(idx_max+1)]
for y in range(h):
    for x in range(w):
        idx = segment[y, x]
        if s[y][x] == '#':
            nbw[idx][0] += 1
        else:
            nbw[idx][1] += 1
ans = 0
for nb, nw in nbw:
    ans += nb*nw
print(ans)


Fixed submission:
import numpy as np
from collections import deque
h, w = map(int, input().split())
s = [input() for _ in range(h)]

segment = [[0]*w for _ in range(h)]
idx = 1
dxy = [[1, 0], [0, 1], [-1, 0], [0, -1]]
for y in range(h):
    for x in range(w):
        if segment[y][x] == 0:
            segment[y][x] = idx
            state = s[y][x]
            que = deque([[y, x, state]])
            while len(que) > 0:
                y_cur, x_cur, state = que.popleft()
                for dx, dy in dxy:
                    y_next = y_cur + dy
                    x_next = x_cur + dx
                    state_next = '.' if state == '#' else '#'
                    if x_next < 0 or y_next < 0 or x_next >= w or y_next >= h:
                        continue
                    elif s[y_next][x_next] != state_next:
                        continue
                    elif segment[y_next][x_next] == 0:
                        segment[y_next][x_next] = idx
                        que.append((y_next, x_next, state_next))
            idx += 1

# print(segment)
idx_max = idx
nbw = [[0, 0] for _ in range(idx_max+1)]
for y in range(h):
    for x in range(w):
        idx = segment[y][x]
        if s[y][x] == '#':
            nbw[idx][0] += 1
        else:
            nbw[idx][1] += 1
ans = 0
for nb, nw in nbw:
    ans += nb*nw
print(ans)
Buggy python submission (verdict: Runtime Error):
n, x = map(int, input().split())

hambs = [(1, 0, 1)]
for l in range(1, n+1):
    n_p, n_b, n_l = hambs[l-1]
    hambs.append((2*n_p+1, 2*n_b+2, 2*n_l+3))
# for h in hambs:
#     print(h)

n_p, _, n_l = hambs[n]
if x == 1:
    print(0)
    exit()
elif x == n_l:
    print(n_p)
    exit()
    
ans = n_p//2+1
y = n_l//2+1
l = n-1
while y != x:
    n_p, _, n_l = hambs[l]
    if y > x:
        ans -= n_p
        y -= n_l
    else:
        ans += n_p
        y += n_l
    l -= 1

print(ans)


Fixed submission:
n, x = map(int, input().split())

hambs = [(1, 1)]
for l in range(1, n+1):
    n_p, n_l = hambs[l-1]
    hambs.append((2*n_p+1, 2*n_l+3))
# for h in hambs:
#     print(h)

def eat(m, y):
    if y == 0:
        return 0
    if m == 0:
        return 1

    if y < 2+hambs[m-1][1]:
        return eat(m-1, y-1)
    elif y == 2+hambs[m-1][1]:
        return hambs[m-1][0] + 1
    elif 2+hambs[m-1][1] < y and y < hambs[m][1]:
        return hambs[m-1][0] + 1 + eat(m-1, y-(2+hambs[m-1][1]))
    else:
        return hambs[m][0]
print(eat(n, x))
Buggy python submission (verdict: Runtime Error):
import numpy as np
MOD = 10**9+7
h, w, k = map(int, input().split())

dp = [[0]*w for _ in range(h+1)]
dp[0][0] = 1

patterns = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]

for i in range(1, h+1):
    # most left
    dp[i][0] = (dp[i-1][0]*patterns[1:][w-2]%MOD + dp[i-1][1]*patterns[w-2]%MOD)%MOD
    for j in range(1, w-1):
        npath = dp[i-1][j-1]*(patterns[j-1]*patterns[1:][w-j-2])%MOD\
                + dp[i-1][j]*(patterns[1:][j-1]*patterns[1:][w-j-2])%MOD\
                + dp[i-1][j+1]*(patterns[1:][j-1]*patterns[w-j-2])%MOD
        dp[i][j] = npath%MOD
    dp[i][w-1] = (dp[i-1][w-2]*patterns[w-2]%MOD + dp[i-1][w-1]*patterns[1:][w-2]%MOD)%MOD

# for p in dp: print(p)

print(dp[-1][k-1])
    


Fixed submission:
MOD = 10**9+7
h, w, k = map(int, input().split())

dp = [[0]*w for _ in range(h+1)]
dp[0][0] = 1

patterns = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]

if w == 1:
    print(1)
    exit()

for i in range(1, h+1):
    # most left
    dp[i][0] = (dp[i-1][0]*patterns[1:][w-2]%MOD + dp[i-1][1]*patterns[w-2]%MOD)%MOD
    for j in range(1, w-1):
        npath = dp[i-1][j-1]*(patterns[j-1]*patterns[1:][w-j-2])%MOD\
                + dp[i-1][j]*(patterns[1:][j-1]*patterns[1:][w-j-2])%MOD\
                + dp[i-1][j+1]*(patterns[1:][j-1]*patterns[w-j-2])%MOD
        dp[i][j] = npath%MOD
    dp[i][w-1] = (dp[i-1][w-2]*patterns[w-2]%MOD + dp[i-1][w-1]*patterns[1:][w-2]%MOD)%MOD

# for p in dp: print(p)

print(dp[-1][k-1])
Buggy python submission (verdict: Time Limit Exceeded):
n, m = list(map(int, input().split()))

for i in range(m//n, 0, -1):
    if m%i == 0:
        print(i)
        break

    


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

cands = []
for i in range(1, int(m**(1/2))+1):
    if m%i == 0:
        cands.append(i)
        cands.append(m//i)
cands = sorted(cands, reverse = True)
# print(cands)

for c in cands:
    if m//c >= n:
        print(c)
        break
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)

if s[0] == '0' or s[-1] == '1':
    print(-1)
    exit()
for i in range(n-1):
    if s[i] != s[-2-i]:
        print(-1)
        exit()

path = {1:[v for v in range(2, n+1)]}
u_cur, v_cur = 1, 2
for i in range(n//2-1, 0, -1):
    if s[i] == '1':
        path[v_cur] = []
        for _ in range(i):
            v_tar = path[u_cur].pop()
            path[v_cur].append(v_tar)
        u_cur, v_cur = v_cur, path[v_cur][0]
for u, vs in path.items():
    for v in vs:
        print(*(u, v))


Fixed submission:
s = input()
n = len(s)

if s[0] == '0' or s[-1] == '1':
    print(-1)
    exit()
for i in range(n-1):
    if s[i] != s[-2-i]:
        print(-1)
        exit()

path = {1:[v for v in range(2, n+1)]}

ans = []
u_cur, v_cur = 1, 2
n_prev = 0
for i in range(1, n//2):
    if s[i] == '1':
        for _ in range(i-n_prev):
            ans.append((u_cur, v_cur))
            v_cur += 1
        ans.append((v_cur, u_cur))
        u_cur, v_cur = v_cur, v_cur+1
        n_prev = i+1
for v in range(v_cur, n+1):
    ans.append((v_cur-1, v))
for a in ans:
    print(*a)

Buggy python submission (verdict: Runtime Error):
s = input()
n = len(s)

if s[0] == '0' or s[-1] == '1':
    print(-1)
    exit()
for i in range(n-1):
    if s[i] != s[-2-i]:
        print(-1)
        exit()

ans = [(1, v) for v in range(2, n+1)]
u_child = 2
i_replace = -1
for i in range(1, n//2):
    if s[i] == '1':
        for _ in range(i):
            ans[i_replace] = (u_child, ans[i_replace][1])
            i_replace -= 1
        u_child += 1
for a in ans:
    print(*a)


Fixed submission:
s = input()
n = len(s)

if s[0] == '0' or s[-1] == '1':
    print(-1)
    exit()
for i in range(n-1):
    if s[i] != s[-2-i]:
        print(-1)
        exit()

path = {1:[v for v in range(2, n+1)]}

ans = []
u_cur, v_cur = 1, 2
n_prev = 0
for i in range(1, n//2):
    if s[i] == '1':
        for _ in range(i-n_prev):
            ans.append((u_cur, v_cur))
            v_cur += 1
        ans.append((v_cur, u_cur))
        u_cur, v_cur = v_cur, v_cur+1
        n_prev = i+1
for v in range(v_cur, n+1):
    ans.append((v_cur-1, v))
for a in ans:
    print(*a)
Buggy python submission (verdict: Runtime Error):
n = int(input())
d = [int(input()) for i in range(n)]

if sum(d)%2 > 0:
    print(-1)
    exit()

d_to_i = {d[i]:i+1 for i in range(n)}
d_set = set(d)
ans = []
while len(ans) < n-1:
    d_max, d_min = max(d_set), min(d_set)
    for m in range(1, n):
        if m*(n-m-1) == d_max-d_min:
            l = n-m-1
            break
    u = d_to_i[d_max]
    for diff in range(1, m+1):
        d_v = d_max - (m*l - (m-diff)*(l-diff))
        v = d_to_i[d_v]
        ans.append((u, v))
        u = v
        if d_v > d_min:
            d_set.remove(d_v)
    d_set.remove(d_max)

for a in ans:
    print(*a)


Fixed submission:
n = int(input())
d = [int(input()) for i in range(n)]

if sum(d)%2 > 0:
    print(-1)
    exit()

d = sorted([(dd, i) for i, dd in enumerate(d)], reverse = True)
d_to_i = {dd:i for dd, i in d}
n_child = [1]*n
d_child = [0]*n
ans = []
for dd, i in d:
    d_i = dd+2*n_child[i]-n
    if d_i in d_to_i.keys():
        i_next = d_to_i[d_i]
        ans.append((i+1, i_next+1))
        n_child[i_next] += n_child[i]
        d_child[i_next] += d_child[i] + n_child[i]
        if n_child[i_next] == n:
            break
    else:
        print(-1)
        exit()

d_min, i_min = d[-1]
if d_min == d_child[i_min]:
    for a in ans:
        print(*a)
else:
     print(-1)

Buggy python submission (verdict: Runtime Error):
n = int(input())
d = [int(input()) for i in range(n)]

# if sum(d)%2 >= 0:
#     print(-1)
#     exit()

d_to_i = {d[i]:i+1 for i in range(n)}
d_set = set(d)
ans = []
while len(ans) < n-1:
    d_max, d_min = max(d_set), min(d_set)
    for m in range(1, n):
        if m*(n-m-1) == d_max-d_min:
            l = n-m-1
            break
    u = d_to_i[d_max]
    for diff in range(1, m+1):
        d_v = d_max - (m*l - (m-diff)*(l-diff))
        v = d_to_i[d_v]
        ans.append((u, v))
        u = v
        if d_v > d_min:
            d_set.remove(d_v)
    d_set.remove(d_max)

for a in ans:
    print(*a)


Fixed submission:
n = int(input())
d = [int(input()) for i in range(n)]

if sum(d)%2 > 0:
    print(-1)
    exit()

d = sorted([(dd, i) for i, dd in enumerate(d)], reverse = True)
d_to_i = {dd:i for dd, i in d}
n_child = [1]*n
d_child = [0]*n
ans = []
for dd, i in d:
    d_i = dd+2*n_child[i]-n
    if d_i in d_to_i.keys():
        i_next = d_to_i[d_i]
        ans.append((i+1, i_next+1))
        n_child[i_next] += n_child[i]
        d_child[i_next] += d_child[i] + n_child[i]
        if n_child[i_next] == n:
            break
    else:
        print(-1)
        exit()

d_min, i_min = d[-1]
if d_min == d_child[i_min]:
    for a in ans:
        print(*a)
else:
     print(-1)
Buggy python submission (verdict: Runtime Error):
import math
n, X = list(map(int, input().split()))
x = list(map(int, input().split()))

x = sorted(x+[X])
# print(x)
x_diff = [x[i+1]-x[i] for i in range(n)]
ans = x_diff[0]
for i in range(1, len(x_diff)):
    ans = math.gcd(ans, x_diff[i])
print(ans)


Fixed submission:
import fractions
n, X = list(map(int, input().split()))
x = list(map(int, input().split()))

x = sorted(x+[X])
x_diff = [x[i+1]-x[i] for i in range(n)]
# print(x, x_diff)
ans = x_diff[0]
for i in range(1, n):
    ans = fractions.gcd(ans, x_diff[i])
print(ans)
Buggy python submission (verdict: Runtime Error):
l = int(input())

for p in range(19, 0, -1):
    if 2**p < l:
        n = p+1
        break

p = n-1
m = 2*p
ans = []
for i in range(1, n):
    ans.append([i, i+1, 0])
    ans.append([i, i+1, 2**(i-1)])
    
while l > 2**p:
    for i in range(n-1, 0, -1):
        if l-2**(i-1) >= 2**p:
            ans.append([i, n, l-2**(i-1)])
            l = l-2**(i-1)
            m += 1
            break

print(n, m)
for a in ans:
    print(' '.join(list(map(str, a))))


Fixed submission:
l = int(input())

p = 0
while True:
    if 2**p > l:
        p -= 1
        break
    else:
        p += 1
        
n = p+1
m = 2*p
ans = []
for i in range(1, n):
    ans.append([i, i+1, 0])
    ans.append([i, i+1, 2**(i-1)])
    
while l > 2**p:
    for i in range(n-1, 0, -1):
        if l-2**(i-1) >= 2**p:
            ans.append([i, n, l-2**(i-1)])
            l = l-2**(i-1)
            m += 1
            break

print(n, m)
for a in ans:
    print(' '.join(list(map(str, a))))

Buggy python submission (verdict: Runtime Error):
l = int(input())

for p in range(19, 0, -1):
    if 2**p < l:
        n = p+1
        break

p = n-1
m = 2*p
ans = []
for i in range(1, n):
    ans.append([i, i+1, 0])
    ans.append([i, i+1, 2**i])
    
while l > 2**p:
    for i in range(n-1, 0, -1):
        if l-2**(i-1) >= 2**p:
            ans.append([i, n, l-2**(i-1)])
            l = l-2**(i-1)
            m += 1
            break

print(n, m)
for a in ans:
    print(' '.join(list(map(str, a))))


Fixed submission:
l = int(input())

p = 0
while True:
    if 2**p > l:
        p -= 1
        break
    else:
        p += 1
        
n = p+1
m = 2*p
ans = []
for i in range(1, n):
    ans.append([i, i+1, 0])
    ans.append([i, i+1, 2**(i-1)])
    
while l > 2**p:
    for i in range(n-1, 0, -1):
        if l-2**(i-1) >= 2**p:
            ans.append([i, n, l-2**(i-1)])
            l = l-2**(i-1)
            m += 1
            break

print(n, m)
for a in ans:
    print(' '.join(list(map(str, a))))

Buggy python submission (verdict: Runtime Error):
l = int(input())

for p in range(19, 0, -1):
    if 2**p < l:
        n = p+1
        break

p = n-1
m = 2*p
ans = []
for i in range(n-1):
    ans.append([i, i+1, 0])
    ans.append([i, i+1, 2**i])
    
while l > 2**p:
    for i in range(n-1, 0, -1):
        if l-2**(i-1) >= 2**p:
            ans.append([i, n, l-2**(i-1)])
            l = l-2**(i-1)
            m += 1
            break

print(n, m)
for a in ans:
    print(' '.join(list(map(str, a))))


Fixed submission:
l = int(input())

p = 0
while True:
    if 2**p > l:
        p -= 1
        break
    else:
        p += 1
        
n = p+1
m = 2*p
ans = []
for i in range(1, n):
    ans.append([i, i+1, 0])
    ans.append([i, i+1, 2**(i-1)])
    
while l > 2**p:
    for i in range(n-1, 0, -1):
        if l-2**(i-1) >= 2**p:
            ans.append([i, n, l-2**(i-1)])
            l = l-2**(i-1)
            m += 1
            break

print(n, m)
for a in ans:
    print(' '.join(list(map(str, a))))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

class BIT:
    def __init__(self, n):
        self.n = n
        self.bit = [0]*(n+1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.bit[i]
            i -= i&(-i)
        return s

    def add(self, i, x):
        while i <= self.n:
            self.bit[i] += x
            i += i&(-i)
            
left, right = 0, 10**9
geta = n+1
while right-left > 1:
    mid = (left+right)//2
    num = 0
    bit = BIT(2*n+1)
    sum_ = 0
    bit.add(sum_+geta, 1)
    for i in range(n):
        val = 1 if a[i] <= mid else -1
        sum_ += val
        num += bit.sum(sum_+geta-1)
        bit.add(sum_+geta, 1)

    if num > n*(n+1)//4:
        right = mid
    else:
        left = mid
print(right)


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

a_sorted = sorted(set(a))+[10**18]
left, right = 0, len(a_sorted)-1

while right-left > 1:
    mid = (left+right)//2
    x = a_sorted[mid]

    count = [0]*(2*n+1)
    count[n+1] = 1
    i, accum, res = n+1, 1, 0

    for aa in a:
        if aa >= x:
            i += 1
            accum += count[i]
        else:
            accum -= count[i]
            i -= 1

        res += accum
        count[i] += 1
        accum += 1

    if res >= n*(n+1)//4:
        left = mid
    else:
        right = mid

print(a_sorted[left])
Buggy python submission (verdict: Time Limit Exceeded):
MOD = 10**9+7
s = input()

cumsum = {}
for key in ['A', 'B', 'C', '?']:
    cumsum[key] = [0]*(len(s)+1)
for i, ss in enumerate(s):
    for key in cumsum.keys():
        if key == ss:
            cumsum[key][i+1] = cumsum[key][i]+1
        else:
            cumsum[key][i+1] = cumsum[key][i]

ans = 0
for i in range(1, len(s)-1):
    if s[i] == 'A' or s[i] == 'C':
        continue
    
    n_a = cumsum['A'][i]
    n_c = cumsum['C'][-1] - cumsum['C'][i+1]
    n_q_left = cumsum['?'][i]
    n_q_right = cumsum['?'][-1] - cumsum['?'][i+1]

    n_left = n_a*pow(3, n_q_left) + n_q_left*pow(3, max(n_q_left-1, 0))
    n_right = n_c*pow(3, n_q_right) + n_q_right*pow(3, max(n_q_right-1, 0))
    ans += n_left*n_right

print(ans%MOD)


Fixed submission:
MOD = 10**9+7
s = input()

dp = [[0]*4 for _ in range(len(s)+1)]
dp[0][0] = 1
for i, ss in enumerate(s):
    if ss == 'A':
        dp[i+1][0] = dp[i][0]
        dp[i+1][1] = (dp[i][1] + dp[i][0])%MOD
        dp[i+1][2] = dp[i][2]
        dp[i+1][3] = dp[i][3]
    elif ss == 'B':
        dp[i+1][0] = dp[i][0]
        dp[i+1][1] = dp[i][1]
        dp[i+1][2] = (dp[i][2] + dp[i][1])%MOD
        dp[i+1][3] = dp[i][3]
    elif ss == 'C':
        dp[i+1][0] = dp[i][0]
        dp[i+1][1] = dp[i][1]
        dp[i+1][2] = dp[i][2]
        dp[i+1][3] = (dp[i][3] + dp[i][2])%MOD
    else:
        dp[i+1][0] = dp[i][0]*3%MOD
        dp[i+1][1] = (dp[i][1]*3%MOD + dp[i][0])%MOD
        dp[i+1][2] = (dp[i][2]*3%MOD + dp[i][1])%MOD
        dp[i+1][3] = (dp[i][3]*3%MOD + dp[i][2])%MOD

# for dp_ in dp: print(dp_)
print(dp[-1][3])
Buggy python submission (verdict: Runtime Error):
from collections import deque
k = int(input())

digsum = lambda x: sum(list(map(int, list(str(x)))))

que = deque([])
MAX = 800000
min_v = MAX
for i in range(MAX-1, 0, -1):
    v = i/digsum(i)
    if v <= min_v:
        que.append(i)
        # print(i, v)
        min_v = v
        
while k > 0:
    print(que.pop())
    k -= 1


Fixed submission:
# almost the copy of answer #2730510 

def S(n):
    return sum(list(map(int, str(n))))

def norm(n):
    return n/S(n)

k = int(input())
j = 1
order = 1
for i in range(k):
    print(j)
    if norm(j+10**(order-1)) > norm(j+10**(order)):
        order += 1
    j += 10**(order-1)

Buggy python submission (verdict: Runtime Error):
from collections import deque
k = int(input())

digsum = lambda x: sum(list(map(int, list(str(x)))))

que = deque([])
MAX = 500000
min_v = MAX
for i in range(MAX-1, 0, -1):
    v = i/digsum(i)
    if v <= min_v:
        que.append(i)
        # print(i, v)
        min_v = v
        
while k > 0:
    print(que.pop())
    k -= 1


Fixed submission:
# almost the copy of answer #2730510 

def S(n):
    return sum(list(map(int, str(n))))

def norm(n):
    return n/S(n)

k = int(input())
j = 1
order = 1
for i in range(k):
    print(j)
    if norm(j+10**(order-1)) > norm(j+10**(order)):
        order += 1
    j += 10**(order-1)
Buggy python submission (verdict: Time Limit Exceeded):
N = input()
S = list(input())
min_ = 400000
for i in range(len(S)):
    left = S[:i]
    right = S[i+1:]
    num_change = left.count('W')+right.count('E')
    if num_change < min_:
        min_ = num_change
print(min_)



Fixed submission:
N = int(input())
S = list(input())

change = S[1:].count('E')
min_ = change

for i in range(1, N):
    if S[i-1] == 'W':
        change += 1
    if S[i] == 'E':
        change -= 1
    if change < min_:
        min_ = change
print(min_)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split(' ')))

def binxor(x, y):
    x = x.lstrip('0b')
    y = y.lstrip('0b')
    n = max(len(x), len(y))
    x = x.zfill(n)
    y = y.zfill(n)
    z = ''.join(list(map(str, [int(xx)^int(yy) for xx, yy in zip(x, y)])))
    return '0b0'+z

A10sum = [0]
Abinsum = [bin(0)]
for i in range(1, N+1):
    A10sum.append(A10sum[i-1]+A[i-1])
    Abinsum.append(binxor(Abinsum[i-1], bin(A[i-1])))
# print(f'10sum : {A10sum}')
# print(f'binsum : {Abinsum}')

count = 0
for l in range(1, N+1):
    for r in range(l, N+1):
        if(A10sum[r]-A10sum[l-1] == int(binxor(Abinsum[r], Abinsum[l-1]), 2)):
            count+=1
print(count)


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

r = 0
ans = 0
sum_a = 0
for l in range(n):
    while r < n and sum_a&a[r] == 0:
        sum_a += a[r]
        ans += r-l+1
        r += 1
    sum_a -= a[l]
print(ans)
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input.split(' '))
if a <= b:
	print(a)
else:
	print(a-1)

Fixed submission:
a, b = map(int, input().split(' '))
if a <= b:
	print(a)
else:
	print(a-1)
Buggy python submission (verdict: Runtime Error):
a, b, c = list(map(int, input().split(' ')))
N = int(input())
max_ = max([a, b, c]
print(a+b+c+max_**N-max_)


Fixed submission:
a, b, c = list(map(int, input().split(' ')))
N = int(input())
max_ = max([a, b, c])
print(a+b+c+max_*(2**N)-max_)

Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, input().split(' '))
N = int(input())
max_ = max([a, b, c]
print(a+b+c+max_**N-max_)

Fixed submission:
a, b, c = list(map(int, input().split(' ')))
N = int(input())
max_ = max([a, b, c])
print(a+b+c+max_*(2**N)-max_)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0
for k in range(28, -1, -1):
    i_1, i_2, i_3 = 0, 0, 0
    T = 1<<k
    add = 0

    for i in range(n):
        a[i] %= 2*T
        b[i] %= 2*T

    a = sorted(a, reverse = True)
    b = sorted(b)
    for i in range(n):
        while i_1 < n and a[i]+b[i_1] < T:
            i_1 += 1
        while i_2 < n and a[i]+b[i_2] < 2*T:
            i_2 += 1
        while i_3 < n and a[i]+b[i_3] < 3*T:
            i_3 += 1
        add += (i_2-i_1) + (n-i_3)

    if add%2 == 1:
        ans += T

print(ans)


Fixed submission:
# Greatly refered to the solution: https://atcoder.jp/contests/abc091/submissions/3549633
from sys import stdin
import numpy as np
ORD = 28

n = int(stdin.readline())
a = np.array(list(map(int, stdin.readline().split())))
b = np.array(list(map(int, stdin.readline().split())))

def search(a_, b_, pow2):
    c1 = np.searchsorted(a_, pow2 - b_)
    c2 = np.searchsorted(a_, 2*pow2 - b_)
    c3 = np.searchsorted(a_, 3*pow2 - b_)
    return n**2 - np.sum(c3) + np.sum(c2) - np.sum(c1)

a_ord = np.zeros((ORD, n), dtype = int)
b_ord = np.zeros((ORD, n), dtype = int)
for i in range(1, ORD+1):
    a_ord[i-1, :] = a%(2**i)
    b_ord[i-1, :] = b%(2**i)
a_ord = np.sort(a_ord, axis = 1)

ans = ''
for i in range(ORD):
    count = search(a_ord[i], b_ord[i], 2**i)
    ans += '0' if count%2 == 0 else '1'
    
count = search(a_ord[-1], b_ord[-1], 2**ORD)
ans += '0' if count%2 == 0 else '1'

print(int(ans[::-1], 2))