Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = int(input())
I =[list(map(int, input().split())) for i in range(N)]

for Cx in range(101):
    for Cy in range(101):
         ans = []
        for ix, iy, ih in I:
            ans.append(abs(ix - Cx) + abs(iy - Cy) + ih)
            ans = [a for a in ans if a > 0]
        if len(ans) > 1:
            continue
        for ix, iy, ih in I:
            if max(a - abs(ix - Cx) - abs(iy - Cy), 0) != ix:
                break
        else:
            print(Cx, Cy, a)
            exit()
        
                        



Fixed submission:
N = int(input())
Info = [list(map(int, input().split())) for i in range(N)]
Info_nonzero = []
highest = 0
for x, y, h in Info:
    if h != 0:
        Info_nonzero.append([x, y, h])

for x, y, h in Info:
    if h == 0:
        highest = max(highest, x + y)

for Cx in range(101):
    for Cy in range(101):
        candidate_set = set()
        for x, y, h in Info_nonzero:
            H = abs(Cx - x) + abs(Cy - y) + h
            candidate_set.add(H)

        ans_H = list(candidate_set)[0]
        if len(candidate_set) == 1:
            for x, y, h in Info:
                H = abs(Cx - x) + abs(Cy - y) + h
                if h == 0:
                    if not H >= ans_H:
                        break

                if h != 0:
                    if not H <= ans_H:
                        break
            else:
                print(Cx, Cy, abs(Cx - Info_nonzero[0][0]) + abs(Cy - Info_nonzero[0][1]) + Info_nonzero[0][2])
                exit()
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())

if N == 1:
    print(M)
else:
    ans = 1
    for g in range(1, int(M ** 0.5) + 1):
        if M % g == 0 and M / g >= N:
            ans = g
print(ans)


Fixed submission:
N, M = map(int, input().split())
ans = 1
if N == 1:
    print(M)
else:
    for n in range(2, int(M ** 0.5) + 1):
        if M % n == 0 and M / N >= n:
            ans = max(ans, n)
            if M // n * N <= M:
                ans = max(ans, M // n)
    print(ans)
Buggy python submission (verdict: Runtime Error):
L = int(input())

# 必要な頂点数を出す
N = 0
for i in range(21):
    if 2 ** i > L:
        break
    else:
        N = i
N += 1

# ここから頂点番号は0-indexedとし、出力時に1-indexedにする
G = []
# 頂点iと頂点i+1との間にコスト0の辺とコスト2^(頂点番号)の辺を張る
for i in range(N - 1):
    G.append((i, i + 1, 0))
    G.append((i, i + 1, 2 ** i))

# 表現できてないコストを列挙
R = list(range(2 ** (N - 1), L))[::-1]
marker = 0  # どこまで表現したかを表すマーカー
B = bin(len(R))[2:]  # どこにバイパスを張るか

# バイパスを張っていく
for i in range(len(B)):
    if B[i] == '0':
        continue

    G.append((i, N - 1, R[marker]))
    marker += 2 ** (i + 1)

print(N, len(G))
for u, v, w in G:
    print(u + 1, v + 1, w)


Fixed submission:
L = int(input())
ans = []

# 頂点数はbitの長さ
N = len(bin(L)[2:])

# 頂点間に0の辺と2**iの辺を張る
for i in range(N - 1)[::-1]:
    ans.append([i + 1, i + 2, 2 ** (N - i - 2)])
    ans.append([i + 1, i + 2, 0])

# 表現できてないパスの個数
need = L - (2 ** (N - 1))

# 表現できてないコスト（大きい順）
cost = list(range(2 ** (N - 1), 2 ** (N -1) + need))

# コストのリスト上を移動するマーカー
marker = 0

# どこにバイパスを張るか
bit = bin(need)[2:][::-1]

# バイパスを張っていく
for i in range(len(bit)):
    if bit[i] != "1":
        continue

    # 辺を追加
    ans.append([1, N - i, cost[marker]])

    # マーカーを進める
    marker += 2 ** i

print(N, len(ans))
for a in ans:
    print(" ".join(map(str, a)))
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
X = list(map(int, input().split()))
L = [0] + [x for x in X if x < 0][::-1]
R = [0] + [x for x in X if x >= 0]

ans = float("inf")
for i in range(K-len(R)+1, len(L)):
    if K - i < 0:
        continue

    ans = min(ans, abs(L[i]) * 2 + R[K-i])
print(ans)


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

ans = float('inf')
for i in range(N-K+1):
    ans = min(ans, abs(X[i] - X[i+K-1]) + abs(X[i]))
    ans = min(ans, abs(X[i] - X[i+K-1]) + abs(X[i+K-1]))

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
N = len(S)

mod = 10 ** 9 + 7
A, AB, ABC, ALL = 0, 0, 0, 1
for s in S:
    if s == "A":
        A += ALL

    if s == "B":
        AB += A

    if s == "C":
        ABC += AB

    if s == "?":
        ABC = ABC * 3 + AB
        AB = AB * 3 + A
        A = A * 3 + ALL
        ALL *= 3

print(ABC % mod)


Fixed submission:
S = input()
N = len(S)

mod = 10 ** 9 + 7
A, AB, ABC, ALL = 0, 0, 0, 1
for s in S:
    if s == "A":
        A += ALL

    if s == "B":
        AB += A

    if s == "C":
        ABC += AB

    if s == "?":
        ABC = (ABC * 3 + AB) % mod
        AB = (AB * 3 + A) % mod
        A = (A * 3 + ALL) % mod
        ALL = (ALL * 3) % mod

print(ABC % mod)
Buggy python submission (verdict: Time Limit Exceeded):
import heapq
N, M, s, t = map(int, input().split())
s, t = s - 1, t - 1
G_yen = [[] for i in range(N)]
G_snuuk = [[] for i in range(N)]
for i in range(M):
    u, v, a, b = map(int, input().split())
    u, v = u - 1, v - 1
    G_yen[u].append([v, a])
    G_yen[v].append([u, a])
    G_snuuk[u].append([v, b])
    G_snuuk[v].append([u, b])


def dijkstra(x, G):
    d = [float('inf')] * N
    d[x] = 0
    visited = {x}

    # d, u
    hq = [(0, x)]

    while hq:
        u = heapq.heappop(hq)[1]
        visited.add(u)

        for node, cost in G[u]:
            if (node not in visited) and d[node] > d[u] + cost:
                d[node] = d[u] + cost
                heapq.heappush(hq, (d[u]+cost, node))
    return d


d_yen = dijkstra(s, G_yen)
d_snuuk = dijkstra(t, G_snuuk)

ans = 10 ** 15
ans_list = []
for i in reversed(range(N)):
    ans = min(ans, d_yen[i] + d_snuuk[i])
    ans_list.append(10 ** 15 - ans)

print(*ans_list[::-1], sep='\n')


Fixed submission:
import heapq
N, M, S, T = map(int, input().split())
S, T = S-1, T-1
G1 = [[] for i in range(N)]
G2 = [[] for i in range(N)]
for i in range(M):
    u, v, a, b = map(int, input().split())
    u, v = u-1, v-1
    G1[u].append((v, a))
    G1[v].append((u, a))
    G2[u].append((v, b))
    G2[v].append((u, b))


def dijkstra(x, G):
    d = [float('inf')] * N
    d[x] = 0
    visited = {x}

    # d, u
    hq = [(0, x)]

    while hq:
        u = heapq.heappop(hq)[1]
        visited.add(u)

        for node, cost in G[u]:
            if (node not in visited) and d[node] > d[u] + cost:
                d[node] = d[u] + cost
                heapq.heappush(hq, (d[u]+cost, node))
    return d


toChange = dijkstra(S, G1)
toGoal = dijkstra(T, G2)

ans = [float('inf')]
for i in range(N-1, -1, -1):
    ans.append(min(ans[-1], toChange[i] + toGoal[i]))

del ans[0]
money = 10 ** 15
for cost in ans[::-1]:
    print(money - cost)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import accumulate
from bisect import bisect_left
N = int(input())
A = list(map(int, input().split()))
A = list(accumulate(A))

ans = float('inf')
# 切る位置を全探索
for mid in range(2, N - 1):
    L, R = A[:mid], A[mid:]
    L_target, R_target = L[-1] / 2, (L[-1] + R[-1]) / 2
    L_index, R_index = bisect_left(L, L_target), bisect_left(R, R_target)

    if abs(L[L_index - 1] - L_target) < abs(L[L_index] - L_target):
        L_index -= 1
    if abs(R[R_index - 1] - R_target) < abs(R[R_index] - R_target):
        R_index -= 1

    P, Q, R, S = L[L_index], L[-1]-L[L_index], R[R_index]-L[-1], R[-1]-R[R_index]
    ans = min(ans, max(P, Q, R, S) - min(P, Q, R, S))

print(ans)


Fixed submission:
from itertools import accumulate
from bisect import bisect_left
N = int(input())
A = list(map(int, input().split()))

accSum = list(accumulate(A))
ans = float('inf')
for m in range(1, N):
    # 左
    Lm = accSum[m] // 2
    Lx = bisect_left(accSum, Lm)
    if abs(accSum[Lx] - Lm) > abs(accSum[Lx - 1] - Lm):
        Lx -= 1

    # 右
    Rm = (accSum[m] + accSum[-1]) // 2
    Rx = bisect_left(accSum, Rm)
    if abs(accSum[Rx] - Rm) > abs(accSum[Rx - 1] - Rm):
        Rx -= 1

    P, Q, R, S = accSum[Lx], accSum[m] - accSum[Lx], accSum[Rx] - accSum[m], accSum[-1] - accSum[Rx]
    ans = min(ans, max(P, Q, R, S) - min(P, Q, R, S))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import accumulate
from bisect import bisect_left
N = int(input())
A = list(map(int, input().split()))
A = list(accumulate(A))

ans = float('inf')
# 切る位置を全探索
for mid in range(2, N - 1):
    L, R = A[:mid], A[mid:]
    L_target, R_target = L[-1] / 2, (L[-1] + R[-1]) / 2
    L_index, R_index = bisect_left(L, L_target), bisect_left(R, R_target)

    if abs(L[L_index - 1] - L_target) < abs(L[L_index] - L_target):
        L_index -= 1
    if abs(R[R_index - 1] - R_target) < abs(R[R_index] - R_target):
        R_index -= 1

    P, Q, R, S = L[L_index], L[-1]-L[L_index], R[R_index]-L[-1], R[-1]-R[R_index]
    ans = min(ans, max(P, Q, R, S) - min(P, Q, R, S))

print(ans)


Fixed submission:
from itertools import accumulate
from bisect import bisect_left
N = int(input())
A = list(map(int, input().split()))

accSum = list(accumulate(A))
ans = float('inf')
for m in range(1, N):
    # 左
    Lm = accSum[m] // 2
    Lx = bisect_left(accSum, Lm)
    if abs(accSum[Lx] - Lm) > abs(accSum[Lx - 1] - Lm):
        Lx -= 1

    # 右
    Rm = (accSum[m] + accSum[-1]) // 2
    Rx = bisect_left(accSum, Rm)
    if abs(accSum[Rx] - Rm) > abs(accSum[Rx - 1] - Rm):
        Rx -= 1

    P, Q, R, S = accSum[Lx], accSum[m] - accSum[Lx], accSum[Rx] - accSum[m], accSum[-1] - accSum[Rx]
    ans = min(ans, max(P, Q, R, S) - min(P, Q, R, S))

print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
dp = [float('inf')] * (2*10**5+1)
dp[0] = 0

for i in range(1, N+1):
    dp[i] = min(dp[i-1], dp[i-6], dp[i-6**2], dp[i-6**3], dp[i-6**4], dp[i-6**5], dp[i-6**7],
                dp[i-9], dp[i-9**2], dp[i-9**3], dp[i-9**4], dp[i-9**5]) + 1

print(dp[N])


Fixed submission:
N = int(input())
dp = [float('inf')] * (10**5+1)
dp[0] = 0

for i in range(1, N+1):
    dp[i] = min(dp[i-1], dp[i-6], dp[i-6**2], dp[i-6**3], dp[i-6**4], dp[i-6**5], dp[i-6**6],
                dp[i-9], dp[i-9**2], dp[i-9**3], dp[i-9**4], dp[i-9**5]) + 1

print(dp[N])

Buggy python submission (verdict: Runtime Error):
N = int(input())
dp = [float('inf')] * (10**5+1)
dp[0] = 0

for i in range(1, N+1):
    dp[i] = min(dp[i-1], dp[i-6], dp[i-6**2], dp[i-6**3], dp[i-6**4], dp[i-6**5], dp[i-6**7],
                dp[i-9], dp[i-9**2], dp[i-9**3], dp[i-9**4], dp[i-9**5]) + 1

print(dp[N])


Fixed submission:
N = int(input())
dp = [float('inf')] * (10**5+1)
dp[0] = 0

for i in range(1, N+1):
    dp[i] = min(dp[i-1], dp[i-6], dp[i-6**2], dp[i-6**3], dp[i-6**4], dp[i-6**5], dp[i-6**6],
                dp[i-9], dp[i-9**2], dp[i-9**3], dp[i-9**4], dp[i-9**5]) + 1

print(dp[N])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = [list(input()) for i in range(N)]

ans = 0
flg = False
for a in range(N):
    S2 = S[a:] + S[:a]
    for i in range(N):
        for j in range(N):
            if S2[i][j] != S2[j][i]:
                flg = True
                break
        if flg:
            flg = False
            break
    else:
        ans += 1

print(ans * N)

Fixed submission:
N = int(input())
S = [list(input()) for i in range(N)]

ans = 0
flg = False
for a in range(N):
    S2 = S[a:] + S[:a]
    for i in range(N):
        for j in range(N):
            if S2[i][j] != S2[j][i]:
                flg = True
                break
        if flg:
            flg = False
            break
    else:
        ans += 1

print(ans * N)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N = int(input())
S = np.array([list(input()) for i in range(N)])

ans = 0
flg = False
for a in range(N):
    S = np.roll(S, 1, axis=0)
    for i in range(N):
        for j in range(N):
            if S[i][j] != S[j][i]:
                flg = True
                break
        if flg:
            flg = False
            break
    else:
        ans += 1

print(ans * N)

Fixed submission:
N = int(input())
S = [list(input()) for i in range(N)]

ans = 0
flg = False
for a in range(N):
    S2 = S[a:] + S[:a]
    for i in range(N):
        for j in range(N):
            if S2[i][j] != S2[j][i]:
                flg = True
                break
        if flg:
            flg = False
            break
    else:
        ans += 1

print(ans * N)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N = int(input())
S = np.array([list(input()) for i in range(N)])

ans = 0
flg = False
for a in range(N):
    S2 = np.roll(S, a, axis=0)
    for i in range(N):
        for j in range(N):
            if S2[i][j] != S2[j][i]:
                flg = True
                break
        if flg:
            flg = False
            break
    else:
        ans += 1

print(ans * N)

Fixed submission:
N = int(input())
S = [list(input()) for i in range(N)]

ans = 0
flg = False
for a in range(N):
    S2 = S[a:] + S[:a]
    for i in range(N):
        for j in range(N):
            if S2[i][j] != S2[j][i]:
                flg = True
                break
        if flg:
            flg = False
            break
    else:
        ans += 1

print(ans * N)
Buggy python submission (verdict: Runtime Error):
N, C = map(int, input().split())
X, V = [], []
for i in range(N):
    xi, vi = map(int, input().split())
    X.append(xi)
    V.append(vi)

r_cal = [0]
l_cal = [0]
for i in range(N):
    r_cal.append(r_cal[-1] + V[i])
    l_cal.append(l_cal[-1] + V[N-i-1])

# 折り返さないパターン and 折り返してどこまでいくのか
r_straight = r_cal.copy()
l_straight = l_cal.copy()

for i in range(1, N+1):
    r_straight[i] -= X[i-1]
    l_straight[i] -= (C - X[N-i])

# 折り返すパターン
for i in range(1, N+1):
    r_cal[i] -= 2*X[i-1]
    l_cal[i] -= 2*(C - X[N-i])

# 折り返した後どこまで行くのが最適か
r_max = [0]
l_max = [0]
for i in range(1, N+1):
    r_max.append(max(r_max[-1], r_straight[i]))
    l_max.append(max(l_max[-1], l_straight[i]))

ans = max(r_max[-1], l_max[-1])
for i in range(N):
    ans = max(ans, r_cal[i] + l_max[N-i])
    ans = max(ans, l_cal[N-i] + r_max[i])
print(ans)


Fixed submission:
N, C = map(int, input().split())
X, V = [], []
for i in range(N):
    xi, vi = map(int, input().split())
    X.append(xi)
    V.append(vi)

r_cal = [0]
l_cal = [0]
for i in range(N):
    r_cal.append(r_cal[-1] + V[i])
    l_cal.append(l_cal[-1] + V[N-i-1])

# 折り返さないパターン and 折り返してどこまでいくのか
r_straight = r_cal.copy()
l_straight = l_cal.copy()

for i in range(1, N+1):
    r_straight[i] -= X[i-1]
    l_straight[i] -= (C - X[N-i])

# 折り返すパターン
for i in range(1, N+1):
    r_cal[i] -= 2*X[i-1]
    l_cal[i] -= 2*(C - X[N-i])

# 折り返した後どこまで行くのが最適か
r_max = [0]
l_max = [0]
for i in range(1, N+1):
    r_max.append(max(r_max[-1], r_straight[i]))
    l_max.append(max(l_max[-1], l_straight[i]))

ans = max(r_max[-1], l_max[-1])
for i in range(N):
    ans = max(ans, r_cal[i] + l_max[N-i])
    ans = max(ans, l_cal[N-i] + r_max[i])
    
print(ans)
Buggy python submission (verdict: Runtime Error):
A, B, K = map(int, input().split())
Z = list(range(A, B+1))
Z = Z[:K] + Z[-K:]
A = set()
for z in Z:
    if z not in A:
        print(z)
        A.add(z)

Fixed submission:
A, B, K = map(int, input().split())
ans = []
for a in range(A, min(A+K, B+1)):
    ans.append(a)
for b in range(max(A+K, B-K+1), B+1):
    ans.append(b)
print(*ans, sep="\n")

Buggy python submission (verdict: Runtime Error):
A, B, K = map(int, input().split())
Z = list(range(A, B+1))
Z = Z[:K] + Z[-K:]
Z = set(Z)
Z = sorted(list(Z))
for z in Z:
    print(z)

Fixed submission:
A, B, K = map(int, input().split())
ans = []
for a in range(A, min(A+K, B+1)):
    ans.append(a)
for b in range(max(A+K, B-K+1), B+1):
    ans.append(b)
print(*ans, sep="\n")

Buggy python submission (verdict: Runtime Error):
A, B, K = map(int, input().split())
Z = list(range(A, B+1))
Z = Z[:K] + Z[-K:]
Z = set(Z)
Z = sorted(list(Z))
print(*Z, sep="\n")

Fixed submission:
A, B, K = map(int, input().split())
ans = []
for a in range(A, min(A+K, B+1)):
    ans.append(a)
for b in range(max(A+K, B-K+1), B+1):
    ans.append(b)
print(*ans, sep="\n")
Buggy python submission (verdict: Runtime Error):
S = input()
A = [chr(ord("a")+i) for i in range(26)]

if len(set(S)) != 26:
    for a in A:
        if a not in S:
            print(S + a)
            break
else:
    used = []
    for i in range(1, 26):
        if S[-i] < S[-i-1]:
            used.append(S[-i])
        else:
            used.sort()
            print(S[:-i-1]+used[0])
            break
    else:
        print(-1)


Fixed submission:
S = input()
C = [chr(97+i) for i in range(26)]

if len(S) != 26:
    for c in C:
        if c not in S:
            print(S + c)
            break
else:
    S = list(S)
    for i in range(25, -1, -1):
        if S[i:] != sorted(S[i:], reverse=True):
            Z = sorted(list(filter(lambda x: x > S[i], S[i:])))
            print("".join(S[:i]) + Z[0])
            break
    else:
        print(-1)

Buggy python submission (verdict: Runtime Error):
S = input()
A = [chr(ord("a")+i) for i in range(26)]

if len(set(S)) < 26:
    for a in A:
        if a not in S:
            print(S+a)
            break
else:
    X = []
    for i in range(25, 0, -1):
        if S[i] > S[i-1]:
            X.sort()
            print(S[:i-1]+X[0])
            break
        else:
            X.append(S[i])
    else:
        print(-1)

Fixed submission:
S = input()
C = [chr(97+i) for i in range(26)]

if len(S) != 26:
    for c in C:
        if c not in S:
            print(S + c)
            break
else:
    S = list(S)
    for i in range(25, -1, -1):
        if S[i:] != sorted(S[i:], reverse=True):
            Z = sorted(list(filter(lambda x: x > S[i], S[i:])))
            print("".join(S[:i]) + Z[0])
            break
    else:
        print(-1)

Buggy python submission (verdict: Runtime Error):
S = input()
C = [chr(97+i) for i in range(26)]


if S == "".join(C.sort(reverse=True)):
    print(-1)

elif len(S) != 26:
    for c in C:
        if c not in S:
            print(S + c)
            break
else:
    K = []
    for i in range(25, -1, -1):
        K.append(S[i])
        K.sort()
        for j in range(25, -1, -1):
            if K[0] > S[j]:
                print(S[:j])
                exit()



Fixed submission:
S = input()
C = [chr(97+i) for i in range(26)]

if len(S) != 26:
    for c in C:
        if c not in S:
            print(S + c)
            break
else:
    S = list(S)
    for i in range(25, -1, -1):
        if S[i:] != sorted(S[i:], reverse=True):
            Z = sorted(list(filter(lambda x: x > S[i], S[i:])))
            print("".join(S[:i]) + Z[0])
            break
    else:
        print(-1)
Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())
G1 = [['#'] * 100 for i in range(50)]
G2 = [['.'] * 100 for i in range(50)]

A, B = A - 1, B - 1

h, w = 0, 0
for a in range(A):
    if w > 99:
        h += 1
    G1[h][w] = '.'
    w += 2

h, w = 1, 0
for b in range(B):
    if w > 99:
        h += 1
    G2[h][w] = '#'
    w += 2


print(100, 100)
for g in G1:
    print(''.join(g))
for g in G2:
    print(''.join(g))


Fixed submission:
A, B = map(int, input().split())
white = [["#"] * 100 for i in range(50)]
black = [["."] * 100 for i in range(50)]
A, B = A-1, B-1

row = 0
line = 0
for i in range(A):
    white[line][row] = "."
    row += 2
    if row >= 100:
        row = 0
        line += 2

row = 0
line = 1
for i in range(B):
    black[line][row] = "#"
    row += 2
    if row >= 100:
        row = 0
        line += 2

ans = white + black
print(100, 100)
for a in ans:
    print("".join(a))

Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())
G1 = [['#'] * 100 for i in range(100)]
G2 = [['.'] * 100 for i in range(100)]

A, B = A - 1, B - 1

h, w = 0, 0
for a in range(A):
    if w > 99:
        h += 1
    G1[h][w] = '.'
    w += 2

h, w = 1, 0
for b in range(B):
    if w > 99:
        h += 1
    G2[h][w] = '#'
    w += 2


print(100, 100)
for g in G1:
    print(''.join(g))
for g in G2:
    print(''.join(g))


Fixed submission:
A, B = map(int, input().split())
white = [["#"] * 100 for i in range(50)]
black = [["."] * 100 for i in range(50)]
A, B = A-1, B-1

row = 0
line = 0
for i in range(A):
    white[line][row] = "."
    row += 2
    if row >= 100:
        row = 0
        line += 2

row = 0
line = 1
for i in range(B):
    black[line][row] = "#"
    row += 2
    if row >= 100:
        row = 0
        line += 2

ans = white + black
print(100, 100)
for a in ans:
    print("".join(a))
Buggy python submission (verdict: Time Limit Exceeded):
# prd様のコードを参考にしました
# https://atcoder.jp/contests/abc091/submissions/3282677

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

ans = 0
for k in range(30):
    T = 2 ** k
    A_mod = sorted([a % (2 * T) for a in A])
    B_mod = sorted([b % (2 * T) for b in B])

    tmp = 0

    for a in A_mod:
        # k-bit目が立つ条件 -> [T, 2T), [3T, 4T)の間にai + bj がある
        # しゃくとりっぽいやつ
        r1, r2, r3 = 0, 0, 0
        while r1 < N and a + B_mod[r1] < T:
            r1 += 1
        while r2 < N and a + B_mod[r2] < 2 * T:
            r2 += 1
        while r3 < N and a + B_mod[r3] < 3 * T:
            r3 += 1

        # 差をとると、[T, 2T), [3T, 4T)の間に入っっている数が手に入る
        tmp += (r2 - r1) + (N - r3)

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

print(ans)


Fixed submission:
# prd様のコードを参考にしました
# https://atcoder.jp/contests/abc091/submissions/3282677

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

ans = 0
for k in range(30):
    T = 2 ** k
    A_mod = sorted([a % (2 * T) for a in A])
    B_mod = sorted([b % (2 * T) for b in B])

    tmp = 0

    r1, r2, r3 = 0, 0, 0
    for a in reversed(A_mod):
        # k-bit目が立つ条件 -> [T, 2T), [3T, 4T)の間にai + bj がある
        # しゃくとりっぽいやつ
        # rを毎回初期化すれば小さいほうからaを見てもできるけど、同じ区間を何回も見ることになってしゃくとりにならずTLEする
        while r1 < N and a + B_mod[r1] < T:
            r1 += 1
        while r2 < N and a + B_mod[r2] < 2 * T:
            r2 += 1
        while r3 < N and a + B_mod[r3] < 3 * T:
            r3 += 1

        # 差をとると、[T, 2T), [3T, 4T)の間に入っっている数が手に入る
        tmp += (r2 - r1) + (N - r3)

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

print(ans)