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

import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(100000)

def main(n,p):
    dx = np.array([0,1,0,-1])
    dy = np.array([1,0,-1,0])
    ans = 0
    def dfs(x,y,dx,dy,grid,dis):
        z = dis[y][x] + grid[y][x]
        for i in range(4):
            next_x = x+dx[i]
            next_y = y+dy[i]
            if dis[next_y][next_x] > z:
                dis[next_y][next_x] = z
                dfs(next_x,next_y,dx,dy,grid,dis)
    grid = np.ones((n+1,n+1),np.int32)
    dis = np.zeros((n+2,n+2),np.int32)
    for i in range(1,n+1):
        for j in range(1,n+1):
            dis[i][j] = min(i,n-i+1,j,n-j+1)-1
    for i in range(n**2):
        pos = p[i]
        x = (pos-1)%n+1
        y = (pos-1)//n+1
        ans += dis[y][x]
        grid[y][x] = 0
        dfs(x,y,dx,dy,grid,dis)
    return ans

n = int(readline())
p = np.array(readline().split(),np.int32)
print(main(n,p))

### FIXED CODE ###

import sys
import numpy as np
from numba import njit

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

@njit('(i4,i4[:])',cache=True)
def main(n,p):
    ans = 0
    w = n+2
    grid = np.ones((w,w),np.int32)
    dis = np.zeros((w,w),np.int32)
    for i in range(1,n+1):
        for j in range(1,n+1):
            dis[i][j] = min(i,n-i+1,j,n-j+1)-1
    grid = grid.ravel()
    dis = dis.ravel()
    stack = np.empty_like(grid)
    for pos in p:
        pos -= 1
        x = pos % n + 1
        y = pos // n + 1
        v = y*w+x
        ans += dis[v]
        grid[v] = 0
        k = min(dis[v-1],dis[v+1],dis[v+w],dis[v-w])
        cur = 0
        stack[0] = v
        while cur >= 0:
            v = stack[cur]
            cur -= 1
            for dx in (-1,1,w,-w):
                next_v = v + dx
                k = dis[v]+grid[v]
                if dis[next_v] > k:
                    dis[next_v] = k
                    cur += 1
                    stack[cur] = next_v
    return ans

n = int(readline())
p = np.array(readline().split(),np.int32)
print(main(n,p))
### BUGGY CODE ###

from scipy.misc import comb
from sys import stdin

N = int(stdin.readline())
count1 = [0] * (N + 1)
count2 = [0] * (N + 1)
A = list(map(int, stdin.readline().split()))

B = list(set(A))

for b in B:
    num_of_b = A.count(b)
    if num_of_b > 2:
        count1[b] = comb(num_of_b, 2, exact=True)
        count2[b] = comb(num_of_b - 1, 2, exact=True)
    elif num_of_b == 2:
        count1[b] = 1


for a in A:
    ans = 0
    ans += sum(count1) - count1[a]
    ans += count2[a]
    print(ans)


### FIXED CODE ###

from sys import stdin

N = int(stdin.readline())
a_dict = {}
A = list(map(int, stdin.readline().split()))
for a in A:
    if a in a_dict:
        a_dict[a] += 1
    else:
        a_dict[a] = 1

sum_comb = 0
B = set(A)
for b in B:
    n = a_dict[b]
    sum_comb += n * (n - 1) // 2

for a in A:
    ans = sum_comb
    n = a_dict[a]
    ans -= n * (n - 1) // 2
    ans += (n - 1) * (n - 2) // 2
    print(ans)
### BUGGY CODE ###

#!/usr/bin/env python

import sys

def getVertex(i,e):
    v= set()
    for v1 in e[i]:
        for v2 in e[v1]:
            for v3 in e[v2]: v.add( v3 )
    #
    return v
#
n,m = [ int(x) for x in sys.stdin.readline().split() ]
e = { i:[] for i in range(n) }
for _ in range(m):
    u,v = [ int(x) for x in sys.stdin.readline().split() ]
    e[u-1].append( v-1 )
s,t = [ int(x)-1 for x in sys.stdin.readline().split() ]
#
kkp= { i:[] for i in range(n) }
#
hop= 0
now = {s}
visit = {s}
while True:
    hop+= 1
    n= set()
    for i in now:
        n |= getVertex(i,e) - visit
    #
    if t in n: break
    if not n:
        hop= -1
        break
    now = n
#
print( hop )


### FIXED CODE ###

#!/usr/bin/env python

import sys

v1mask= set()
v2mask= set()

def getVertex(i,e):
    global v1mask, v2mask
    v= set()
    for v1 in e[i]:
        if v1 in v1mask: continue
        v1mask.add( v1 )
        for v2 in e[v1]:
            if v2 in v2mask: continue
            v2mask.add( v2 )
            for v3 in e[v2]: v.add( v3 )
    #
    return v
#
n,m = [ int(x) for x in sys.stdin.readline().split() ]
e = { i:[] for i in range(n) }
for _ in range(m):
    u,v = [ int(x) for x in sys.stdin.readline().split() ]
    e[u-1].append( v-1 )
s,t = [ int(x)-1 for x in sys.stdin.readline().split() ]
#
hop= 0
now = {s}
visit = {s}
while True:
    hop+= 1
    n= set()
    for i in now:
        n |= getVertex(i,e) - visit
        if t in n: break
    #
    if t in n: break
    if not n:
        hop= -1
        break
    now = n
    visit|= n
#
print( hop )
### BUGGY CODE ###

from sys import stdin
import numpy as np
N=list(map(int,(stdin.readline().strip().split())))[0]
A=np.array(list(map(int,(stdin.readline().strip().split()))))
count=np.count_nonzero(A==1)
print(np.count_nonzero(A==1))
flag=True
for i in range(2,N+1):
    count+=np.count_nonzero(A==i)
    if flag:print((np.count_nonzero(A==i)))
    else:print(0)
    if count == N - 1: flag = False


### FIXED CODE ###

from sys import stdin
import numpy as np
N=list(map(int,(stdin.readline().strip().split())))[0]
A=list(map(int,(stdin.readline().strip().split())))
num_list=[0]*N
moji=A[0]
i=0
length=len(A)-1
for i in A:
    num_list[i-1]+=1
for num in num_list:
    print(num)
### BUGGY CODE ###

from scipy.misc import comb

n = int(input())
a = list(map(int,input().split()))
a_s = set(a)
for i in range(n):
    l = a[i]
    a[i] = 'X'
    ans = 0
    for j in a_s:
        ans += comb(a.count(j),2,exact=True)
    print(ans)
    a[i] = l

### FIXED CODE ###

from collections import Counter
n = int(input())
a = list(map(int,input().split()))

c = Counter(a)
key = c.keys()
comb = 0
for i in key:
    comb += (c[i]) * (c[i]-1) // 2

for i in a:
    ans = comb - (c[i]-1)
    print(ans)
### BUGGY CODE ###

import sys
def input(): return sys.stdin.readline().strip()
inf = sys.maxsize

if __name__ == '__main__':
    h, w, k = map(int,input().split())
    s = [[int(i) for i in input()] for _ in range(h)]

    ans = inf
    for i in range(2 ** (h - 1)): #縦方向の割り方を全探索 O(512)
        hdiv = [1 if i & 2 ** j else 0 for j in range(h - 1)]
        hdiv.append(1)
        sh = sum(hdiv)
        tmpans = sh - 1
        partsum = [0 for _ in range(sh)]
        j = 0
        while j < w: #O(2 * 10 ** 3)
            tmp = 0
            idx = 0
            flag = True
            for kk in range(h): #O(10)
                tmp += s[kk][j]
                if hdiv[kk]:
                    partsum[idx] += tmp
                    if partsum[idx] > k:
                        tmpans += 1
                        partsum = [0 for _ in range(sh)]
                        flag = False
                        break
                    tmp = 0
                    idx += 1
            if flag:
                j += 1
        ans = min(ans, tmpans)
    print(ans)

### FIXED CODE ###

import sys
inf = sys.maxsize

if __name__ == '__main__':
    h, w, k = map(int, sys.stdin.readline().strip().split())
    s = [[int(i) for i in sys.stdin.readline().strip()] for _ in range(h)]
    
    ans = inf
    for i in range(2 ** (h - 1)): #縦方向の割り方を全探索 O(512)
        hdiv = [1 if i & 2 ** j else 0 for j in range(h - 1)]
        hdiv.append(1)
        sh = sum(hdiv)
        tmpans = sh - 1
        partsum = [0 for _ in range(sh)]
        partsum_p = [0 for _ in range(sh)]
        j = 0
        for j in range(w): #O(10 ** 3)
            tmp = 0
            idx = 0
            flag = False
            for kk in range(h): #O(10)
                tmp += s[kk][j]
                if hdiv[kk]:
                    partsum_p[idx] = partsum[idx]
                    partsum[idx] += tmp
                    if partsum[idx] > k and not flag:
                        tmpans += 1
                        flag = True
                    tmp = 0
                    idx += 1
            if flag:
                partsum = [partsum[l] - partsum_p[l] for l in range(sh)]
                partsum_p = [0 for _ in range(sh)]
                for kk in range(sh):
                    if partsum[kk] > k:
                        tmpans = inf
                        break
        ans = min(ans, tmpans)
    print(ans)
### BUGGY CODE ###

n = int(input())
a = []
ans = 0
for i in range(n):
    a.append(sorted(input()))
for i in range(n-1):
    for j in range(i+1,n):
        if a[i] == a[j]:
            ans += 1
print(ans)

### FIXED CODE ###

n = int(input())
a = []
ans = 0
for i in range(n):
    a.append(sorted(input()))
a.sort()
flg = 0
for i in range(1,n):
    if a[flg] != a[i]:
        z = i - 1 - flg
        ans += (1 + z) * z // 2
        flg = i
z = n - 1 - flg
ans += (1 + z) * z // 2
print(ans)
### BUGGY CODE ###

x,y,z,K = map(int,input().split())
abc = [sorted(list(map(int,input().split())), reverse=True) for i in range(3)]

ans=[0]*K

for i in range(x):
    for j in range(y):
        for l in range(z):
            if i*j*l < K:
                if min(ans) < abc[0][i]+abc[1][j]+abc[2][l]:
                    ans[ans.index(min(ans))] = abc[0][i]+abc[1][j]+abc[2][l]
            
ans.sort(reverse=True)

for i in range(K):
    print(ans[i])

### FIXED CODE ###

x,y,z,K = map(int,input().split())
abc = [sorted(list(map(int,input().split())), reverse=True) for i in range(3)]

ans=[]
ab=[]

for i in range(x):
    for j in range(y):
        if (i+1)*(j+1) <= K:
            ab.append(abc[0][i]+abc[1][j])

ab.sort(reverse=True)

for i in range(min([len(ab),K])):
    for j in range(z):
        if (i+1)*(j+1) <= K:
            ans.append(ab[i]+abc[2][j])
    
ans.sort(reverse=True)

for i in range(K):
    print(ans[i])
### BUGGY CODE ###

from collections import *
from heapq import *
from itertools import *
from fractions import gcd
import sys
from decimal import *
import copy
from bisect import *
input=lambda :sys.stdin.readline().rstrip()


N,X,Y=map(int,input().split())
data=[[] for i in range(N+1)]
for i in range(1,N):
    a=i;b=i+1
    data[a].append(b)
    data[b].append(a)
data[X].append(Y)
data[Y].append(X)


dic=defaultdict(int)
for n in range(1,N+1):
    stack=deque([[n,0]])
    visited=set()
    while stack:
        #print(stack)
        a,m=stack.popleft()
        for p in data[a]:
            if not p in visited:
                visited.add(p)
                stack.append([p,m+1])
                if p>n:
                    dic[m+1]+=1


lst=[]
for i in range(N-1):
    print(dic[i+1])


### FIXED CODE ###

from collections import *
from heapq import *
from itertools import *
from fractions import gcd
import sys
from decimal import *
import copy
from bisect import *
input=lambda :sys.stdin.readline().rstrip()


N,X,Y=map(int,input().split())
data=[[] for i in range(N+1)]
for i in range(1,N):
    a=i;b=i+1
    data[a].append(b)
    data[b].append(a)
data[X].append(Y)
data[Y].append(X)


dic=defaultdict(int)
for n in range(1,N+1):
    stack=deque([[n,0]])
    visited=set()
    while stack:
        #print(stack)
        a,m=stack.popleft()
        for p in data[a]:
            if not p in visited:
                visited.add(p)
                stack.append([p,m+1])
                if p>n:
                    dic[m+1]+=1


lst=[]
for i in range(N-1):
    print(dic[i+1])
### BUGGY CODE ###

import math,itertools,fractions,heapq,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  h,w=LI()
  q=queue.Queue()

  field=[S() for _ in range(h)]
  counter=[[inf]*w for _ in range(h)]

  sharp_cnt=0
  for x in field:
    sharp_cnt+=x.count('#')

  q.put((0,0,1))

  while not q.empty()>0:
    y,x,cnt=q.get()
    
    if counter[y][x]<cnt:
      continue
    counter[y][x]=cnt

    for dy,dx in dd:
      ny=y+dy
      nx=x+dx

      if 0<=ny and 0<=nx and ny<h and nx<w:
        if field[ny][nx]!='#':

          if counter[ny][nx]==inf:
            q.put((ny,nx,cnt+1))

  step_cnt=counter[h-1][w-1]

  if step_cnt==inf:
    return -1

  return h*w-sharp_cnt-step_cnt

# main()
print(main())


### FIXED CODE ###

import math,itertools,fractions,heapq,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  h,w=LI()
  q=[]

  field=[S() for _ in range(h)]
  counter=[[inf]*w for _ in range(h)]

  sharp_cnt=0
  for x in field:
    sharp_cnt+=x.count('#')

  q.append((0,0,1))

  while len(q)>0:
    y,x,cnt=q.pop()
    if counter[y][x]<cnt:
      continue
    counter[y][x]=cnt

    for dy,dx in dd:
      ny=y+dy
      nx=x+dx

      if 0<=ny and 0<=nx and ny<h and nx<w:
        if field[ny][nx]!='#':

          if counter[ny][nx]>cnt+1:
            q.append((ny,nx,cnt+1))

  step_cnt=counter[h-1][w-1]

  if step_cnt==inf:
    return -1

  return h*w-sharp_cnt-step_cnt

# main()
print(main())
### BUGGY CODE ###

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

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

# A[i], B[i] はまとめてしまう
stores = [list(map(int, input().split())) for n in range(N)]

# 最も安い店を探す
def getCheapest():
  cheapest = 0
  for i in range(1, N):
    if (stores[i][0] < stores[cheapest][0] and stores[i][1] > 0):
      cheapest = i
  return cheapest

bought = 0
money = 0

# M本買うまで繰り返す
while(bought < M):
  index = getCheapest()
  money += stores[index][0]
  stores[index][1] -= 1
  bought += 1

# 最後にかかった金額を出力
print(money)

### FIXED CODE ###

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

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

# A[i], B[i] はまとめてしまう
stores = [list(map(int, input().split())) for n in range(N)]

# 安さ順にソート
stores.sort(key = lambda s: s[0])

remaining = M
cost = 0

while True:
  store = stores[0]
  if store[1] >= remaining: # もしこの店で買いきれるなら
    cost += store[0] * remaining
    break
  else: #買い切れないなら
    cost += store[0] * store[1]
    remaining -= store[1]
    stores.pop(0)

print(cost)
### BUGGY CODE ###

N, M = map(int, input().split())
 
AB = []
 
for i in range(N):
    a, b = map(int, input().split())
    for i in range(b):
        AB.append(a)

AB.sort()

print(sum(AB[:M]))

### FIXED CODE ###

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

AB = []

for i in range(N):
    a, b = map(int, input().split())
    AB.append([a, b])

AB.sort()

ans = 0
cnt = 0

for ab in AB:
    for b in range(ab[1]):
        ans += ab[0]
        cnt += 1
        if cnt==M:
            break
    if cnt==M:
        break

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

n,q =map(int,input().split())
s=input()
l=[list(map(int,input().split())) for _ in range(q)]

p=[s[i]+s[i+1] for i in range(n-1)]

for i in range(q):
  print(sum([x=='AC' for x in p[l[i][0]-1:l[i][1]-1]]))

### FIXED CODE ###

n,q=map(int,input().split())
s=input()
l=[list(map(int,input().split())) for _ in range(q)]
a=[0]*n

for i in range(n):
  a[i]=a[i-1]
  if s[i-1:i+1]=='AC':
    a[i]+=1

for i in range(q):
  print(a[l[i][1]-1]-a[l[i][0]-1])
### BUGGY CODE ###

import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

n=II()
to=[[] for _ in range(n)]
for _ in range(n-1):
    u,v=MI1()
    to[u].append(v)
    to[v].append(u)

def far(u,pu=-1,d=0):
    res_u,res_d=u,d
    for v in to[u]:
        if v==pu:continue
        u0,d0=far(v,u,d+1)
        if d0>res_d:
            res_d=d0
            res_u=u0
    return res_u,res_d

s,_=far(0)
t,dist=far(s)
#print(s,t,dist)

def makepath(u,pu,t):
    for v in to[u]:
        if v==pu:continue
        path.append(v)
        if v==t or makepath(v,u,t):return True
        path.pop()
    return False

path=[s]
makepath(s,-1,t)
#print(path)

leg=[]
for u in path[1:-1]:leg.append(len(to[u])-2)
#print(leg)

if sum(leg)+dist+1!=n:
    print(-1)
    exit()

ans=[]
ans.append(1)
u=2
for l in leg:
    for v in range(u+1,u+1+l):
        ans.append(v)
    ans.append(u)
    u+=l+1
ans.append(u)

leg.reverse()
ans2=[]
ans2.append(1)
u=2
for l in leg:
    for v in range(u+1,u+1+l):
        ans2.append(v)
    ans2.append(u)
    u+=l+1
ans2.append(u)

if ans2<ans:ans=ans2
print(*ans)


### FIXED CODE ###

import sys

#sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

n=II()
to=[[] for _ in range(n)]
for _ in range(n-1):
    u,v=MI1()
    to[u].append(v)
    to[v].append(u)
#print(to)

def far(u):
    stack=[(u,-1,0)]
    mxd=mxu=-1
    while stack:
        u,pu,d=stack.pop()
        if d>mxd:
            mxd=d
            mxu=u
        for v in to[u]:
            if v==pu:continue
            stack.append((v,u,d+1))
    return mxu,mxd

s,_=far(0)
t,dist=far(s)
#print(s,t,dist)

def makepath(u,t):
    stack=[(u,-1)]
    while stack:
        u,pu=stack.pop()
        while path and path[-1]!=pu:path.pop()
        path.append(u)
        if u==t:return
        for v in to[u]:
            if v==pu:continue
            stack.append((v,u))

path=[s]
makepath(s,t)
#print(path)

leg=[]
for u in path[1:-1]:leg.append(len(to[u])-2)
#print(leg)

if sum(leg)+dist+1!=n:
    print(-1)
    exit()

ans=[]
ans.append(1)
u=2
for l in leg:
    for v in range(u+1,u+1+l):
        ans.append(v)
    ans.append(u)
    u+=l+1
ans.append(u)

leg.reverse()
ans2=[]
ans2.append(1)
u=2
for l in leg:
    for v in range(u+1,u+1+l):
        ans2.append(v)
    ans2.append(u)
    u+=l+1
ans2.append(u)

if ans2<ans:ans=ans2
print(*ans)
### BUGGY CODE ###

s=input()
t=input()

def c(a,b,s):
    t=s.replace(a,"A")
    u=t.replace(b,a)
    v=u.replace("A",b)
    
    return v
    
l=[]

for i in range(len(t)):
    if s[i]!=t[i]:
        for j in l:
            if s[i]==j:
                break
        l.append(t[i])
        s=c(s[i],t[i],s)
    
        

if s==t:
    print("Yes")
else:
    print("No")
        
    

### FIXED CODE ###

s=input()
t=input()


def f(s):
    l=[]
    a="abcdefghijklmnopqrstuvwxyz"
    r=""
    for i in range(len(s)):
        if s[i] in l:
            for j in range(len(l)):
                if s[i]==l[j]:
                    r+=a[j]
        else:
            r+=a[len(l)]
            l.append(s[i])
    return r

if f(s)==f(t):
    print("Yes")
else:
    print("No")
### BUGGY CODE ###

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


possibles = set()
for x in xs:
    possibles.add(x - 1)
    possibles.add(x)
    possibles.add(x + 1)


res = 0
for p in possibles:
    d = 0
    for x in xs:
        c = abs(x - p)
        if c <= 1: d += 1
    if res < d: res = d

print(res)







### FIXED CODE ###


from collections import Counter


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


c = Counter(xs)


res = 0
for i in range(100000):
    res = max(res, c[i] + c[i - 1] + c[i + 1])

print(res)
### BUGGY CODE ###

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

for i, num in enumerate(x):
    x_copy = x.copy()
    x_copy.pop(i)
    x_copy = sorted(x_copy)
    print(x_copy[len(x_copy) // 2])

### FIXED CODE ###

n = int(input())
x = list(map(int, input().split()))
x_sorted = sorted(x)
target = x_sorted[n // 2 - 1]

for num in x:
    if num <= target:
        print(x_sorted[n // 2])
    else:
        print(x_sorted[n // 2 - 1])
### BUGGY CODE ###

class Node:
    def __init__(self,key):
        self.key = key
        self.p = None
        self.left = None
        self.right = None

def insert(tree,k):
    y = None
    x = tree
    z = Node(k)
    while x != None:
        y = x
        if x.key > k:
            x = x.left
        else:
            x = x.right
    z.p = y
    if y == None:
        tree = z
    elif y.key > k:
        y.left = z
    else:
        y.right = z
    return tree

def middleorder(x):
    if x != None:
        middleorder(x.left)
        print x.key,
        middleorder(x.right)

def preorder(x):
    if x != None:
        print x.key,
        preorder(x.left)
        preorder(x.right)



tree = None
m = int(raw_input())
for i in range(m):
    c = raw_input().strip()
    if c[0] == 'i':
        tree = insert(tree, int(c[7:]))
    elif c[0] == 'p':
        print '',
        middleorder(tree)
        print
        print '',
        preorder(tree)
        print

### FIXED CODE ###

def insert(tree,k):
    y = None
    x = tree
    z = {'key':k, 'parent':None, 'left':None, 'right':None}
    while x != None:
        y = x
        if x['key'] > k:
            x = x['left']
        else:
            x = x['right']
    z['parent'] = y
    if y == None:
        tree = z
    elif y['key'] > k:
        y['left'] = z
    else:
        y['right'] = z
    return tree

def middleorder(x):
    if x != None:
        middleorder(x['left'])
        print x['key'],
        middleorder(x['right'])

def preorder(x):
    if x != None:
        print x['key'],
        preorder(x['left'])
        preorder(x['right'])



tree = None
m = int(raw_input())
for i in range(m):
    c = raw_input().strip()
    if c[0] == 'i':
        tree = insert(tree, int(c[7:]))
    elif c[0] == 'p':
        print '',
        middleorder(tree)
        print
        print '',
        preorder(tree)
        print
### BUGGY CODE ###

import numpy as np
A,B=map(int,input().split())
s=[]
for i in range(A,B+1):
    s.append(format(i,'b'))
for i in range(len(s)):
    while len(s[i])<len(s[-1]):
        s[i]='0'+s[i]
a=np.array(s)
b=[list(map(int,a[i])) for i in range(len(a))]
b=np.array(b)
x=[0]*len(s[-1])#x[0]~s[len(s[-1])-1]
ans=''
for i in reversed(range(len(s[-1]))):
    if np.sum(b[:,i])%2==0:
        x[i]='0'
    else:
         x[i]='1'
for i in range(len(s[-1])):
    ans+=x[i]
print(int(ans,2))

### FIXED CODE ###

A,B=map(int,input().split())
def f(n):
    if n%4==0:
        return n
    elif n%4==1:
        return 1
    elif n%4==2:
        return n^1
    else:
        return 0
print(f(A-1)^f(B))