Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

import sys
import math
import itertools
import collections
import numpy as np

rl = sys.stdin.readline

n, k = map(int, rl().split())

li = list(map(int, rl().split()))

dp = np.full(n, 1<<60)

dp[0] = 0
dp[1] = abs(li[0] - li[1])

if k < n:    
    for i in range(2, k):
        for j in range(i):
            a = dp[j] + abs(li[j] - li[i])
            if dp[i] > a:
                dp[i] = a
    for i in range(k, n):
        for j in range(i-k, i):
            a = dp[j] + abs(li[j] - li[i])
            if dp[i] > a:
                dp[i] = a
else:
    for i in range(n):
        for j in range(i):
            a = dp[j] + abs(li[j] - li[i])
            if dp[i] > a:
                dp[i] = a
        
print(int(dp[-1]))




### FIXED CODE ###

import sys

rl = sys.stdin.readline

n, k = map(int, rl().split())

li = list(map(int, rl().split()))

dp = [1<<60]*n

dp[0] = 0
dp[1] = abs(li[0] - li[1])

if k < n:    
    for i in range(2, k):
        for j in range(i):
            a = dp[j] + abs(li[j] - li[i])
            if dp[i] > a:
                dp[i] = a
    for i in range(k, n):
        for j in range(i-k, i):
            a = dp[j] + abs(li[j] - li[i])
            if dp[i] > a:
                dp[i] = a
else:
    for i in range(n):
        for j in range(i):
            a = dp[j] + abs(li[j] - li[i])
            if dp[i] > a:
                dp[i] = a
        
print(int(dp[-1]))
### BUGGY CODE ###

R, G, B, N = map(int, input().split())
LIM = 3003
ans = 0
for r in range(LIM):
    for g in range(LIM):
        if R * r + G * g > N:
            break
        Bb = N - R * r - G * g
        if Bb % B == 0:
            ans += 1
print(ans)


### FIXED CODE ###

def solve():
    R, G, B, N = map(int, input().split())
    LIM = 3001
    ans = 0
    for r in range(LIM):
        for g in range(LIM):
            if R * r + G * g > N:
                break
            Bb = N - R * r - G * g
            if Bb % B == 0:
                ans += 1
    return ans


print(solve())
### BUGGY CODE ###

from itertools import combinations as comb
from collections import deque as dq

def inpl(): return list(map(int, input().split()))


def dijkstra(a, b):
    node = dq()
    node.append(a)
    ncost = [1<<20 for _ in range(N+1)]
    first = a
    ncost[a] = 0
    path = {}
    while b not in node:
        for nb in edge[first]:
            if nb in node:
                continue
            if ncost[nb] > ncost[first] + cost[(first, nb)]:
                # print(nb, ncost[nb])
                path[nb] = first
                ncost[nb] = ncost[first] + cost[(first, nb)]
                # print(nb, ncost[nb])

        nf = 0
        # print(path)
        for t in range(N+1):
            if t in node:
                continue
            # print(nf, t)
            if ncost[nf] > ncost[t]:
                nf = t
        node.append(nf)
        first = nf
        # print(node)
    now = b
    # print(path)
    # print(ncost)
    ret = set()
    while True:
        if now == a:
            break
        ret.add((now, path[now]))
        ret.add((path[now], now))
        now = path[now]
    return ret


N, M = inpl()
cost = {}
edge = [dq() for _ in range(N+1)]
for _ in range(M):
    a, b, c = inpl()
    cost[(a, b)] = c
    cost[(b, a)] = c
    edge[a].append(b)
    edge[b].append(a)

ans = set()
for a, b, in comb([i for i in range(1, N+1)], 2):
    # print(a, b, "check")
    # print(dijkstra(a, b))
    ans = ans | dijkstra(a, b)
# print(ans)
print(M-len(ans)//2)

### FIXED CODE ###

from itertools import combinations as comb
from collections import deque as dq

def inpl(): return list(map(int, input().split()))


def dijkstra(a):
    node = dq()
    node.append(a)
    ncost = [1<<20 for _ in range(N+1)]
    first = a
    ncost[a] = 0
    path = {}
    while len(node) != N:
        for nb in edge[first]:
            if nb in node:
                continue
            if ncost[nb] > ncost[first] + cost[(first, nb)]:
                # print(nb, ncost[nb])
                path[nb] = first
                ncost[nb] = ncost[first] + cost[(first, nb)]
                # print(nb, ncost[nb])

        nf = 0
        # print(path)
        for t in range(N+1):
            if t in node:
                continue
            # print(nf, t)
            if ncost[nf] > ncost[t]:
                nf = t
        node.append(nf)
        first = nf
        # print(node)
    # print(path)
    # print(ncost)
    ret = set()
    for k, v in path.items():
        ret.add((k, v))
        ret.add((v, k))
    return ret


N, M = inpl()
cost = {}
edge = [dq() for _ in range(N+1)]
for _ in range(M):
    a, b, c = inpl()
    cost[(a, b)] = c
    cost[(b, a)] = c
    edge[a].append(b)
    edge[b].append(a)

ans = set()
for a in range(1, N+1):
    # print(a, b, "check")
    # print(dijkstra(a, b))
    ans = ans | dijkstra(a)
# print(ans)
print(M-len(ans)//2)
### BUGGY CODE ###

def digit10_str(n):
    dten_str = ""
    while(n>0):
        dten_str+=str(n%10)
        n/=10
    return dten_str

a,b = map(int,input().split())
c = 0
for i in range(a,b):
    if digit10_str(i)[0]==digit10_str(i)[-1] and digit10_str(i)[1]==digit10_str(i)[-2]:
        c+=1
print(c)

### FIXED CODE ###

a,b = map(int,input().split())
c = 0
for i in range(a,b+1):
    s = str(i)
    if s == s[::-1]:
        c+=1
print(c)
### BUGGY CODE ###

from collections import deque
import sys
import copy
n=int(input())
maxmatch=n*(n-1)
a=[]
for i in range(n):
  a.append(list(map(int,input().split())))
day=0

match=[0]*(n+1)
jyunban=deque(range(n))
jyunban_n=deque()

while match[n]<maxmatch:
  jyunban_n.clear()
  day+=1
  check=[True]*(n+1)
  for i in jyunban:
    if match[i]==n-1 or check[i]==False:
      continue
    else:
      vs=a[i][match[i]]-1
      if check[i] and check[vs]:
        if  a[i][match[i]]-1==vs and a[vs][match[vs]]-1==i:
          match[i]+=1
          match[vs]+=1
          match[n]+=2
          check[i]=False
          check[vs]=False
          check[n]=False
          jyunban_n.append(i)
          jyunban_n.append(vs)
      
    if len(jyunban)==0:
      if check[n]:
        print(-1)
        sys.exit()
  jyunban=copy.copy(jyunban_n)
#  print (jyunban)
        
print(day)


### FIXED CODE ###

import sys
MAX_INT = int(10e9)
MIN_NUM = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()
 
N = I()
a = [IL()[::-1] for i in range(N)]
 
used = [-1]*N
updatelist = [i for i in range(N)]
total = N*(N-1)//2
cnt = 0
days = 0
ul = []
while updatelist:
  ul = []
  for i in updatelist:
    #print(a)
    #print(i+1)
    if len(a[i]) > 0 and used[i] != days:
      numIND = a[i][-1] -1
      #print(numIND+1)
      if a[numIND][-1] == i+1 and used[numIND] != days:
        a[i].pop(-1)
        a[numIND].pop(-1)
        used[i] = days
        used[numIND] = days
        ul.append(i)
        ul.append(numIND)
        cnt += 1
  else:
    updatelist = ul[:]
    if len(ul) != 0:
      days += 1
#print(a)
#print(cnt)
if cnt == total:
  print(days)
else:
  print(-1)
### BUGGY CODE ###

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

# dp[i][w]: i番目の荷物で重さwの状態であるときの最大価値
dp = [[0 for _ in range(W+1)] for _ in range(N+1)]

# 配るDPで考える
for nimotsu in range(N):
    # 行取得
    w_weight, w_val = map(int, input().split())
    
    for w in range(W+1):
        # 品物を選ぶとき (上限超えなければ)
        sum_ = w + w_weight
        if sum_ <= W :
            dp[nimotsu+1][sum_] = max(dp[nimotsu+1][sum_], dp[nimotsu][w] + w_val)
            
        # 品物を選ばないとき
        dp[nimotsu+1][w] = max(dp[nimotsu+1][w] ,dp[nimotsu][w])

print(max(dp[N]))

### FIXED CODE ###

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

# dp[i][w]: i番目の荷物で重さwの状態であるときの最大価値
dp = [[0 for _ in range(W+1)] for _ in range(N+1)]

# 配るDPで考える
for nimotsu in range(N):
    # 行取得
    w_weight, w_val = map(int, input().split())
    
    for w in range(W+1):
        # 品物を選ぶとき (上限超えなければ)
        sum_ = w + w_weight
        if sum_ <= W :
            dp[nimotsu+1][sum_] = max(dp[nimotsu+1][sum_], dp[nimotsu][w] + w_val)
            
        # 品物を選ばないとき
        dp[nimotsu+1][w] = max(dp[nimotsu+1][w] ,dp[nimotsu][w])

print(dp[N][W])
### BUGGY CODE ###

from collections import defaultdict

dic = defaultdict(int)


def count_divisors(n):
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            dic[i] += 1
            if i != n // i:
                dic[n//i] += 1


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

for a in A:
    count_divisors(a)

for key in sorted(dic.keys(), reverse=True):
    if dic[key] in [n, n-1]:
        print(key)
        break

### FIXED CODE ###

import fractions

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

L_gcd = [0]*(n+1)
R_gcd = [0]*(n+1)

for i in range(n):
    L_gcd[i+1] = fractions.gcd(L_gcd[i], A[i])
    R_gcd[n-i-1] = fractions.gcd(R_gcd[n-i], A[n-i-1])

ans = [0]*n

for i in range(n):
    ans[i] = fractions.gcd(L_gcd[i], R_gcd[i+1])

print(max(ans))
### BUGGY CODE ###

n = int(input())
x = list(map(int, input().split()))
x.sort(reverse=True)

ans = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        a, b = x[i], x[j]
        left, right = j + 1, n
        while right - left > 1:
            k = (left + right) // 2
            if a < b + x[k]:
                left = k
            else:
                right = k
        if a < b + x[left]:
            ans += (left - j)

print(ans)

### FIXED CODE ###

n = int(input())
x = list(map(int, input().split()))
x.sort(reverse=True)

ans = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        a, b = x[i], x[j]
        left, right = j + 1, n
        while right - left > 1:
            k = (left + right) // 2
            if a < b + x[k]:
                left = k
            else:
                right = k
        if a < b + x[left]:
            ans += (left - j)

print(ans)
### BUGGY CODE ###


k = int(input())
a = list(range(1, 10))
ans = a + []
while len(ans) < k:
    b = []
    for i in a:
        if i > 323456666:
            break
        il = str(i)[-1]
        intil = int(il)
        if intil == 0:
            ad = [0,1]
        elif intil == 9:
            ad = [8,9]
        else:
            ad = [intil-1, intil, intil+1]
        c = [int(str(i) + str(j)) for j in ad]
        b = b + c
    a = b
    ans = ans + b

print(ans[k-1])

### FIXED CODE ###

k = int(input())
from collections import deque
q = deque()
a = list(map(str, list(range(1, 10))))
ans = a + []
illist = []
for i in range(10):
    if i == 0:
        illist.append(["0","1"])
    elif i == 9:
        illist.append(["8","9"])
    else:
        illist.append([str(i-1),str(i),str(i+1)])
for i in range(1,10):
    q.append(str(i))

node = "0"
while node != "323456667":
    node = q.popleft()
    for j in illist[int(node[-1])]:
        nodej = node+j
        q.append(nodej)
        a.append(nodej)

print(a[k - 1])
### BUGGY CODE ###

def insert(S, string):
    S.add(string)

def find(S, string):
    cnt = 0
    for i in range(len(S)):
        cnt = cnt + 1
        if string in S:
            print 'yes'
            break
        elif cnt == len(S):
            print 'no'
    if cnt == 0:
        print 'no'

n = input()

S = set([])

for i in range(n):
    tmp1, tmp2  = map(str,raw_input().split())
    if tmp1 == 'insert':
        insert(S, tmp2)
    elif tmp1 == 'find':
        find(S, tmp2)
    else:
        print 'error!'

### FIXED CODE ###

def insert(S, string):
    S.add(string)

def find(S, string):
    if string in S:
        print 'yes'
    else:
        print 'no'

n = input()

S = set()

for i in range(n):
    tmp1, tmp2  = map(str, raw_input().split())
    if tmp1 == 'insert':
        insert(S, tmp2)
    elif tmp1 == 'find':
        find(S, tmp2)
    else:
        print 'error!'
### BUGGY CODE ###

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

cnt = 0
for l in range(n):
  for r in range(l, n):
    if sum(a[l:r+1]) % m == 0:
      cnt += 1
print(cnt)


### FIXED CODE ###

n,m = map(int, input().split())
a = list(map(int, input().split()))
# 累積和
s = []
s.append(0)
for idx in range(len(a)):
  s.append((s[idx] + a[idx]) % m)

c = {0:1}
ans = 0
for l in range(1, n+1):
  ans += c.get(s[l],0)
  c[s[l]] = c.get(s[l],0) + 1
print(ans)
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
ans =[]
sum_rain = sum(a)
a_double = [i*2 for i in a]*2
for i in range(n):
  minus = sum(a_double[i+1:i+n-1:2])
  ans.append(sum_rain-minus)

print(' '.join(map(str,ans)))

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
ans =[0]
sum_rain = sum(a)
a_double = [i*2 for i in a]*2
minus = sum(a_double[1:n-1:2])
ans[0] = sum_rain-minus

for i in range(1,n): 
  ans.append(2*a[i-1]-ans[i-1])

print(' '.join(map(str,ans)))
### BUGGY CODE ###

s=input()
q=int(input())
for i in range(q):
    s1=input()
    if s1[0]=='1':
        s=s[::-1]
    else:
        if s1[2]=='1':
            s=s1[4]+s
        else:
            s+=s1[4]
print(s)

### FIXED CODE ###

s=list(input())
q=int(input())
c=0
left=[]
right=[]
for i in range(q):
    s1=input()
    if s1[0]=='1':
        c+=1
    else:
        if s1[2] == '1':
            if c % 2 == 0:
                left.append(s1[4])
            else:
                right.append(s1[4])
        else:
            if c % 2 == 0:
                right.append(s1[4])
            else:
                left.append(s1[4])
left=left[::-1]
left.extend(s)
left.extend(right)
if c%2==0:
    print(''.join(left))
else:
    left=left[::-1]
    print(''.join(left))
### BUGGY CODE ###

_,*p=map(int,open(0).read().split())
i=0
p.sort()
while(len(p)!=0):
  t=p[0]
  p=[m if m!=t else 0 for m in p[1:] if m%t!=0 or m==t ]
  if 0 in p:p=[i for i in p if i!=0]
  else:i+=1
print(i)

### FIXED CODE ###

M=10**6+1
_,*l=map(int,open(0).read().split())
a=[0]*M
for i in sorted(l):
  a[i]+=1
  if a[i]==1:
    for j in range(2*i,M,i): a[j]+=2
print(a.count(1))
### BUGGY CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import dijkstra

N,M,S,T = map(int,input().split())
UVAB = [[int(x) for x in input().split()] for _ in range(M)]
U,V,A,B = zip(*UVAB)

g1 = csr_matrix((A,(U,V)), (N+1,N+1))
g2 = csr_matrix((B,(U,V)), (N+1,N+1))
d1 = dijkstra(g1, indices=S, directed=False)
d2 = dijkstra(g2, indices=T, directed=False)

d = d1 + d2 # 各頂点を両替所に選ぶ場合

d = (np.minimum.accumulate(d[::-1])[::-1]).astype(int)

answer = 10 ** 15 - d[1:]
print('\n'.join(answer.astype(str)))

### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import numpy as np
from heapq import heappush, heappop

N,M,S,T = map(int,input().split())
graph = [[] for _ in range(N+1)]
for _ in range(M):
    u,v,a,b = map(int,input().split())
    graph[u].append((v,a,b))
    graph[v].append((u,a,b))

def dijkstra(start, mode):
    INF = 10 ** 15
    dist = [INF] * (N+1)
    dist[start] = 0
    q = [(0,start)]
    while q:
        d,v = heappop(q)
        if dist[v] < d:
            continue
        for w,*a in graph[v]:
            d1 = d + a[mode]
            if dist[w] > d1:
                dist[w] = d1
                heappush(q, (d1,w))
    return dist

d1 = np.array(dijkstra(S,0))
d2 = np.array(dijkstra(T,1))

d1 += d2
answer = 10 ** 15 - np.minimum.accumulate(d1[::-1])[::-1][1:]

print(*answer, sep='\n')
### BUGGY CODE ###

import re
tg="AC"
n,q=map(int,input().split())
text=input()
ans=[]

def check():
    l,r=map(int,input().split())
    text_=text[l-1:][:r-1]
    count=re.findall(tg,text_)
    ans.append(len(count))
    
for i in range(q):
    check()

for i in ans:
    print(i)

### FIXED CODE ###

n,q=map(int,input().split())
text=input()
sum_=[]
count=0
for i in range(n):
    if text[i-1]=='A' and text[i]=='C':
        count+=1
    sum_.append(count)
for i in range(q):
    l,r=map(int,input().split())
    print(sum_[r-1]-sum_[l-1])
### BUGGY CODE ###

def main():

    import sys
    input = sys.stdin.readline
    from bisect import bisect_left

    N,Q = map(int,input().split())
    info = []
    for _ in range(N):
        s,t,x = map(int,input().split())
        info.append((x,s,t))
    info = sorted(info)
    tmp = sorted([(int(input()),i) for i in range(Q)])
    D = []
    ID = []
    for d,i in tmp:
        D.append(d)
        ID.append(i)

    bit = [1]*Q
    ans = [-1]*Q

    for x,s,t in info:
        left = bisect_left(D,s-x)
        right = bisect_left(D,t-x)
        for j in range(left,right):
            i = ID[j]
            if bit[i]:
                ans[i] = x
                bit[i] = 0

    for a in ans:
        print(a)

if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
input = sys.stdin.readline
from bisect import bisect_left
inf = float('inf')

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

res = 1
while res < Q:
    res <<= 1
N0 = res
data = [inf for _ in range(2*N0-1)]

def update(l, r, x):
    L = l + N0
    R = r + N0
    while L < R:
        if R & 1:
            R -= 1
            data[R] = min(data[R], x)
        if L & 1:
            data[L] = min(data[L], x)
            L += 1
        L >>= 1; R >>= 1

def value(k):
    k += N0
    res = data[k]
    while k != 0:
        k >>= 1
        res = min(res, data[k])
    return res


for S, T, X in STX:
    l = bisect_left(D, S-X)
    r = bisect_left(D, T-X)
    update(l, r, X)

for k in range(Q):
    ans = value(k)
    if ans == inf:
        ans = -1
    print(ans)
### BUGGY CODE ###

N = int(input())
h = list(map(int , input().split()))
dp = [[-1]*10000 for i in range(N)]
import sys
sys.setrecursionlimit(10000000)
def dfs(i,c):
    if i == N:
        return 10000
    if dp[i][c] != -1:
        return dp[i][c]
    else:
        if i == N-1:
            return abs(h[i] - c)
        dp[i][c] = min(dfs(i+1, h[i])+abs(h[i]-c),dfs(i+2, h[i])+abs(h[i]-c))
        return dp[i][c]
print(dfs(0,h[0]))

### FIXED CODE ###

N = int(input())
h = list(map(int , input().split()))
dp = [10**9+1]*N
dp[0] = 0
dp[1] = abs(h[1]-h[0])
for i in range(2,N):
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))
print(dp[N-1])
### BUGGY CODE ###

# coding: utf-8
# Your code here!
import bisect

N=int(input())
l=list(map(int,input().split()))
l.sort()

ans=0
for i in range(N-2):
    for j in range(i+1,N-1):
        insert_index = bisect.bisect_left(l[j+1:N],l[i]+l[j])
        ans+=(insert_index)
        
print(ans)


### FIXED CODE ###

# coding: utf-8
# Your code here!
import bisect

N=int(input())
l=list(map(int,input().split()))
l.sort()

ans=0
for i in range(N-2):
    for j in range(i+1,N-1):
        insert_index = bisect.bisect_left(l,l[i]+l[j])
        ans+=(insert_index-j-1)
        
print(ans)
### BUGGY CODE ###

def comb(val):
    if(val > 0):
        return int(val*(val-1) / 2)
    else:
        return 0
    
def make_map(balls):
    balls_map = {}
    for ball in balls:
        if(ball in balls_map):
            balls_map[ball] += 1
        else:
            balls_map[ball] = 1
    return balls_map

def main():
    args = input().rstrip().split(' ')
    N = int(args[0])
    balls = [val for val in input().rstrip().split(' ')]
    balls_map = make_map(balls)
    
    sum_ = 0
    for ball in balls:
        balls_map[ball] -= 1
        sum_ = 0
        for val in balls_map.values():
            sum_ += comb(val)
        print(sum_)
        balls_map[ball] += 1
    
if __name__ == "__main__":
    main()

### FIXED CODE ###

def comb(val):
    if(val > 0):
        return int(val*(val-1) / 2)
    else:
        return 0
    
def make_map(balls):
    balls_map = {}
    for ball in balls:
        if(ball in balls_map):
            balls_map[ball] += 1
        else:
            balls_map[ball] = 1
    return balls_map

def main():
    args = input().rstrip().split(' ')
    N = int(args[0])
    balls = [val for val in input().rstrip().split(' ')]
    balls_map = make_map(balls)
    
    sum_ = 0
    for val in balls_map.values():
        sum_ += comb(val)
    for ball in balls:
        print(sum_ - (balls_map[ball]-1))
    
if __name__ == "__main__":
    main()
### BUGGY CODE ###

from heapq import heappush, heappop
def main():
    N=int(input())
    road=[[float("inf") for _ in range(N)]for _ in range(N)]
    pq=[]
    ans=0
    for i in range(N):
        road[i][i]=0
        tmp=list(map(int,input().split()))
        for j in range(i+1,N):
            heappush(pq,(tmp[j],i,j))

    while pq:
        v=heappop(pq)
        d,i,j=v[0],v[1],v[2]
        tmp=road[i][j]
        for k in range(N):
            tmp=min(tmp,road[i][k]+road[k][j])
            if tmp==d:
                break
        if tmp>d:
            road[i][j]=d
            road[j][i]=d
            ans+=d
        elif tmp==d:
            road[i][j]=d
            road[j][i]=d
        else:
            print(-1)
            exit()
    print(ans)
main()

### FIXED CODE ###

from heapq import heappush, heappop
def main():
    N=int(input())
    road=[[float("inf") for _ in range(N)]for _ in range(N)]
    pq=[]
    ans=0
    for i in range(N):
        road[i][i]=0
        tmp=list(map(int,input().split()))
        for j in range(i+1,N):
            heappush(pq,(tmp[j],i,j))

    while pq:
        v=heappop(pq)
        d,i,j=v[0],v[1],v[2]
        tmp=road[i][j]
        for k in range(N):
            tmp=min(tmp,road[i][k]+road[k][j])
            if tmp==d:
                break
        if tmp>d:
            road[i][j]=d
            road[j][i]=d
            ans+=d
        elif tmp==d:
            road[i][j]=d
            road[j][i]=d
        else:
            print(-1)
            exit()
    print(ans)
main()
### BUGGY CODE ###

import bisect
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    l = [[] for i in range(31)]
    b.sort()
    for i in range(30):
        mod = 2**(i+1)
        for j in b:
            l[i].append(j%mod)
        l[i].sort()

    ans = [0]*31

    for i in a:
        
        for j in range(30):
            mod = pow(2,j)
            x = i%(mod*2)
            count = bisect.bisect_right(l[j],2*mod-x-1)-bisect.bisect_left(l[j],mod-x)
            count += bisect.bisect_right(l[j],4*mod-x-1)-bisect.bisect_left(l[j],3*mod-x)
            ans[j] += count
    count = 0
    for i in range(31):
        count += pow(2,i)*(ans[i]%2)
    print(count)

if __name__ =="__main__":
    main()

### FIXED CODE ###

import sys
input = sys.stdin.readline


n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
l = [[] for i in range(29)]
for i in range(29):
    mod = 2**(i+1)
    for j in b:
        l[i].append(j%mod)
    l[i].sort()

ans = 0
for i in range(29):
    al = []
    count = 0
    mod = 2**i
    for j in a:
        al.append(j%(2*mod))
    al.sort(reverse = True)
    r1 = r2 = r3 = 0
    for j in al:
        while r1 < n and l[i][r1]+j < mod:
            r1 += 1
        while r2 < n and l[i][r2]+j < 2*mod:
            r2 += 1
        while r3 < n and l[i][r3]+j < 3*mod:
            r3 += 1
        count += n-r3+r2-r1
    ans += (count%2) << i
print(ans)