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

def xor(a, b):
    a_bin = bin(a)[2:]
    b_bin = bin(b)[2:]
    a_len = len(a_bin)
    b_len = len(b_bin)
    result = []
    for i in range(1, max(a_len, b_len) + 1):
        if a_len < i:
            result.append(b_bin[b_len - i])
        elif b_len < i is None:
            result.append(a_bin[a_len - i])
        else:
            result.append('0' if a_bin[a_len - i] == b_bin[b_len - i] else '1')
    res_str = ''
    result.reverse()
    for s in result:
        res_str += s
    return int(res_str, 2)


A, B = map(int, input().split())
x = A
for i in range(A + 1, B + 1):
    x = xor(x, i)

print(x)

### FIXED CODE ###

from operator import xor

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


def f(n):
    if n % 2 == 0:
        if n % 4 == 0:
            return n
        else:
            return xor(n, 1)
    else:
        return xor(n, f(n - 1))


print(xor(f(A - 1), f(B)))

# 0,   1,   2,   3,   4,   5,   6,   7
# 000, 001, 010, 011, 100, 101, 110, 111
# 000, 001, 011, 000, 100, 001, 000, 111
# f(A, B) = f(0, A - 1) ^ f(0, B)
# f(0, X) = X ^ (X - 1)
### BUGGY CODE ###

N = int(input())
A = list(map(lambda x: format(int(x), "060b"), input().split()))
Num = 10**9 + 7
digit = [[0, 0] for i in range(60)]
for a in A:
  for i in range(60):
    digit[i][int(a[i])] += 1
#print(digit)
ans = 0
for i in range(60):
  ans = (ans * 2 + digit[i][0] * digit[i][1]) % Num
print(ans)

### FIXED CODE ###

N = int(input())
A = list(map(lambda x: format(int(x), "060b"), input().split()))
Num = 10**9 + 7
digit = [0 for i in range(60)]
for a in A:
  for i in range(60):
    if a[i] == "1":
      digit[i] += 1
#print(digit)
ans = 0
for i in range(60):
  ans = (ans * 2 + digit[i] * (N-digit[i])) %Num
print(ans)
### BUGGY CODE ###

n = int(input())
s = [input() for i in range(n)]

# 辞書作成
s_list = list(set(s))
s_dict = dict()
for i in s:
    if i not in s_dict:
        s_dict[i] = 1
    else:
        s_dict[i] += 1

# 最大値のkeyのみリスト化
max_s_list = [i[0] for i in s_dict.items() if i[1] == max(s_dict.values())]
# ソート
max_s_list.sort(key=lambda x: x[0])
print(*max_s_list, sep="\n")

### FIXED CODE ###

n = int(input())
s = [input() for i in range(n)]

# 辞書作成
s_dict = dict()
for i in s:
    if i not in s_dict:
        s_dict[i] = 1
    else:
        s_dict[i] += 1

m = max(s_dict.values())
ans = []
for k, v in s_dict.items():
    if v == m:
        ans.append(k)
ans.sort()
# ソート
print(*ans, sep="\n")
### BUGGY CODE ###

n, a = map(int, input().split())
x = [int(i) for i in input().split()]

dp = [[[0 for i in range(n+1)] for j in range(n+1)] for k in range(50*n+1)]
count = 0

def dfs(i, j, sum):
    global count
    if dp[sum][j][i] != 0:
        return dp[sum][j][i]

    if i == n:
        if sum == a*j and j != 0:
            return 1
        else:
            return 0

    dp[sum][j][i] = dfs(i+1, j, sum) + dfs(i+1, j+1, sum + x[i])
    return dp[sum][j][i]

print(dfs(0, 0, 0))

### FIXED CODE ###

import collections

n, a = [int(i) for i in input().split()]
x = [int(i) - a for i in input().split()]

ans = 0
sums = collections.Counter([0, x[0]])

for i in x[1:]:
    temp = collections.Counter()
    for s, c in sums.items():
        temp[s + i] += c
    sums += temp
    #print(sums)

print(sums[0] - 1)
### BUGGY CODE ###

mod = 10 ** 9 + 7

n, k = map(int, input().split())
gcd_dp = [0] * (k + 1)

for i in range(k, 0, -1):
    gcd_dp[i] = (k // i) ** n
    a = 2
    while i * a <= k:
        gcd_dp[i] -= gcd_dp[i * a]
        a += 1

ret = 0
for i in range(k + 1):
    ret += (i % mod) * (gcd_dp[i] % mod)
    ret %= mod
print(ret)

### FIXED CODE ###

Mod = 10 ** 9 + 7

n, k = map(int, input().split())
gcd_dp = [0] * (k + 1)

for i in range(k, 0, -1):
    gcd_dp[i] = pow(k // i, n, Mod)
    a = 2
    while i * a <= k:
        gcd_dp[i] -= gcd_dp[i * a]
        a += 1

ret = 0
for i in range(k + 1):
    ret += (i % Mod) * (gcd_dp[i] % Mod)
    ret %= Mod
print(ret)
### BUGGY CODE ###

N = int(input())


hash_t = {}
for i in range(N):
    a = "".join(sorted([c for c in input()]))
    if a in hash_t.keys():
        hash_t[a] += 1
    else:
        hash_t[a] = 0


def fac(n):
    """階乗"""
    res = 0
    for i in range(1, n+1):
        res += i
    return res
cnt = 0
for x in hash_t.values():
    if x == 0:
        continue
    cnt += fac(x)
print(cnt)

### FIXED CODE ###

import sys
input = sys.stdin.readline
N = int(input())
l = ["".join(sorted([c for c in input()])) for i in range(N)]
l.sort()


def fac(n):
    """階乗"""
    res = 0
    for i in range(1, n+1):
        res += i
    return res


hash_l = []
for i in range(N-1):
    if l[i] == l[i+1]:
        if i == 0:
            hash_l.append(0)
        if l[i-1] == l[i]:
            hash_l[-1] += 1
        else:
            hash_l.append(1)

cnt = 0
for x in hash_l:
    cnt += fac(x)
print(cnt)
### BUGGY CODE ###

x, y, z, k = map(int, input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

#a.sort(reverse=True)
#b.sort(reverse=True)
c.sort(reverse=True)            

ab=[]

for i in a:
    for j in b:
        ab.append(i+j)
ab.sort(reverse=True)

abc=[]
for i in ab[:k]:
    for j in c[:k]:
        abc.append(i+j)
abc.sort(reverse=True)

for i in abc[:k]:
    print(i)

### FIXED CODE ###

x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

ab = sorted(x+y for x in a for y in b)[:-k-1:-1]
abc = sorted(x+y for x in ab[:k] for y in c)[:-k-1:-1]
print(*abc, sep='\n')
### BUGGY CODE ###

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

# # Bubble Sort
# start = 0
# for i in range(N-1):
#     for index in range(start, N-1):
#         if AB[index][0] > AB[index+1][0]:
#             AB[index], AB[index+1] = AB[index+1], AB[index]
#         else:
#             pass
#         start += 1

AB = sorted(AB, key=lambda x: x[0])

final = 0
sum_bottles = 0
while(M > sum_bottles):
    final += 1
    sum_bottles = 0
    for i in range(final):
        sum_bottles += AB[i][1]

cost = 0
sum_bottles = 0
for i in range(final):
    if i == final - 1:
        cost += AB[i][0] * (M - sum_bottles)
    else:
        cost += AB[i][0] * AB[i][1]
        sum_bottles += AB[i][1]

print(cost)


### FIXED CODE ###

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

# # Bubble Sort
# start = 0
# for i in range(N-1):
#     for index in range(start, N-1):
#         if AB[index][0] > AB[index+1][0]:
#             AB[index], AB[index+1] = AB[index+1], AB[index]
#         else:
#             pass
#         start += 1

AB = sorted(AB, key=lambda x: x[0])

final = 0
sum_bottles = 0
while(M > sum_bottles):
    final += 1
    sum_bottles += AB[final-1][1]

cost = 0
sum_bottles = 0
for i in range(final):
    if i == final - 1:
        cost += AB[i][0] * (M - sum_bottles)
    else:
        cost += AB[i][0] * AB[i][1]
        sum_bottles += AB[i][1]

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

N, Q = map(int, input().split())
S = input()
# cnt = [S[:i].count('AC') for i in range(1, len(S) + 1)]
# print('cnt', cnt)
for _ in range(Q):
    l, r = map(int, input().split())
    ans = S[:r].count('AC') - S[:l].count('AC')
    print(ans)


### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
cnt = [0]
for i in range(2, len(S) + 1):
    if S[i - 2:i] == 'AC':
        v = cnt[-1] + 1
    else:
        v = cnt[-1]
    cnt.append(v)

# print('cnt', cnt)
for _ in range(Q):
    l, r = map(int, input().split())
    ans = cnt[r - 1] - cnt[l - 1]
    print(ans)
### BUGGY CODE ###

N = int(input())
S = list(input())

res = []
pw = ""
for i in range(2 ** N):
    cnt = 0
    for j in range(N):
        if (i >> j) & 1 == 1:
            cnt += 1
            pw += S[j]
        if cnt > 3:
            break
    if cnt == 3:
        res.append(pw)
        pw = ""
    else:
        pw = ""

print(len(set(res)))

### FIXED CODE ###

N = int(input())
S = input()

res = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            x = S.find(str(i))
            y = S.find(str(j), x + 1)
            z = S.find(str(k), y + 1)

            if -1 < x < y < z:
                res += 1

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

N = int(input())
L = list(map(int, input().split()))

ans = 0
for i in range(1,2**N):
  bin_line = str(bin(i))
  bin_line = bin_line.replace('0b', '')

  line = []
  if bin_line.count('1') == 3:
    for j in range(len(bin_line)):
      if bin_line[j] == '1':
        line.append(L[N-len(bin_line)+j])
    if len(set(line)) == 3:
      if line[0]+line[1] > line[2] and line[0]+line[2] > line[1] and line[1]+line[2]>line[0]:
        ans += 1
print(ans)

### FIXED CODE ###

N = int(input())
L = list(map(int, input().split()))

ans = 0
for i in range(0,N-2):
  for j in range(i+1,N-1):
    for k in range(j+1,N):
      if L[i] != L[j] and L[i] != L[k] and L[j] != L[k] and L[i]+L[j] > L[k] and L[i]+L[k] > L[j] and L[j]+L[k] > L[i]:
        ans += 1
print(ans)
### BUGGY CODE ###

N=int(input())
import math
rootN=math.sqrt(N)
if rootN==int(rootN):
    n=int(rootN)
else:
    for m in range(int(rootN)+1,N+1):
        if N%m==0:
            n=m
            break
print(len(str(n)))


### FIXED CODE ###

N=int(input())
import math
rootN=math.sqrt(N)
if rootN==int(rootN):
    n=int(rootN)
else:
    for m in reversed(range(1,int(rootN)+1)):
        if N%m==0:
            n=int(N/m)
            break
print(len(str(n)))
### BUGGY CODE ###

def slove():
    import sys
    input = sys.stdin.readline
    s = str(input().rstrip('\n'))
    is_first = True
    ls = [[0] * 13 for _ in range(len(s))]
    mod = 10 ** 9 + 7
    for i in range(len(s)):
        if is_first:
            is_first = False
            if s[-i-1] == "?":
                for j in range(10):
                    ls[i][j] += 1
            else:
                t = int(s[-i-1])
                ls[i][t] += 1
        else:
            mlt = pow(10, i)
            if s[-i-1] == "?":
                for j in range(13):
                    for k in range(10):
                        r = (j + mlt * k) % 13
                        ls[i][r] += ls[i-1][j]
                        ls[i][r] %= mod
            else:
                t = int(s[-i-1])
                for j in range(13):
                    r = (j + mlt * t) % 13
                    ls[i][r] += ls[i-1][j]
                    ls[i][r] %= mod
    print(ls[-1][5])


if __name__ == '__main__':
    slove()


### FIXED CODE ###

def slove():
    import sys
    input = sys.stdin.readline
    s = [int(v) if v != "?" else -1 for v in list(str(input().rstrip('\n')))]
    dp = [[0] * 13 for _ in range(2)]
    mod = 10 ** 9 + 7

    for i in range(1):
        if s[-i-1] == -1:
            for j in range(10):
                dp[0][j % 13] += 1
        else:
            dp[0][s[-i - 1] % 13] += 1

    for i in range(1, len(s)):
        m = pow(10, i, 13)
        if s[-i-1] == -1:
            for j in range(10):
                mj = m * j
                for k in range(13):
                    dp[1][(mj + k) % 13] += dp[0][k]
        else:
            for k in range(13):
                dp[1][(m * s[-i-1] + k) % 13] += dp[0][k]
        for j in range(13):
            dp[0][j] = dp[1][j] % mod
            dp[1][j] = 0
    print(dp[0][5] % mod)


if __name__ == '__main__':
    slove()
### BUGGY CODE ###

N,K=map(int,input().split())
mod=10**9+7

import math
SQ=int(math.sqrt(N))

DP1=[1]*(SQ+1)
DP1[0]=0


DP2=[]

k=SQ

for i in range(SQ,0,-1):
    DP2.append(N//i-k)
    k=N//i

KOSUU2=[v for v in DP2]

for j in range(K-1):
    NDP1=[0]*(SQ+2)
    NDP2=[0]*(SQ+1)

    for j in range(1,SQ+1):
        NDP2[-j]-=DP1[j]
        NDP1[1]+=DP1[j]


    for j in range(-1,-SQ-1,-1):
        NDP1[-j+1]-=DP2[j]
        NDP1[1]+=DP2[j]

    for j in range(1,SQ+2):
        NDP1[j]+=NDP1[j-1]

    NDP2[0]+=NDP1[-1]

    for j in range(1,SQ+1):
        NDP2[j]+=NDP2[j-1]


    for j in range(SQ):
        NDP2[j]=NDP2[j]*KOSUU2[j]%mod

    DP1=NDP1
    DP2=NDP2
    DP1.pop()
    DP2.pop()

print((sum(DP1)+sum(DP2))%mod)

### FIXED CODE ###

N,K=map(int,input().split())
mod=10**9+7

import math
SQ=int(math.sqrt(N))

DP1=[1]*(SQ+1)
DP1[0]=0


DP2=[]

k=SQ

for i in range(SQ,0,-1):
    DP2.append(N//i-k)
    k=N//i


KOSUU2=[v for v in DP2]

#print(DP1)
#print(DP2)
#print()

for j in range(K-1):
    NDP1=[0]*(SQ+2)
    NDP2=[0]*(SQ+1)

    for j in range(1,SQ+1):
        NDP2[-j]-=DP1[j]
        NDP1[1]+=DP1[j]

    #print(NDP1)
    #print(NDP2)
    #print()

    for j in range(-1,-SQ-1,-1):
        NDP1[-j+1]-=DP2[j]
        NDP1[1]+=DP2[j]

    #print(NDP1)
    #print(NDP2)
    #print()

    for j in range(1,SQ+2):
        NDP1[j]+=NDP1[j-1]

    NDP2[0]+=NDP1[-1]

    for j in range(1,SQ+1):
        NDP2[j]+=NDP2[j-1]

    #print(NDP1)
    #print(NDP2)
    #print()

    for j in range(SQ):
        NDP2[j]=NDP2[j]*KOSUU2[j]

    #print(NDP1)
    #print(NDP2)
    #print()

    DP1=[n%mod for n in NDP1[:SQ+1]]
    DP2=[n%mod for n in NDP2[:SQ]]

    
print((sum(DP1)+sum(DP2))%mod)
### BUGGY CODE ###

N = int(input())
X = list(map(int, list(input())))
#print(X)

def f(n):
  global call
  call += 1
  bit = 0
  m = n
  while m > 0:
    if m % 2 == 1:
      bit += 1
    m //= 2
  next_n = n % bit
  if next_n > 0:
    f(next_n)

def num(A):
  b = 1
  r = 0
  for i in range(len(A)):
    r += b*A[-i-1]
    b *= 2
  return r

for i in range(N):
  A = X.copy()
  A[i] ^= 1
#  print(A)
  n = num(A)
#  print(n)
  call = 0
  if n > 0:
    f(n)
  print(call)

### FIXED CODE ###

N = int(input())
X = input()
B = X.count('1')
#print(B, 'B')

base_mod_1 = [1 for i in range(N)] # 2^i mod B+1
if B > 1:
  base_mod_2 = [1 for i in range(N)] # 2^i mod B-1

for i in range(1, N):
  base_mod_1[i] = (base_mod_1[i-1] * 2) % (B+1)
  if B > 1:
    base_mod_2[i] = (base_mod_2[i-1] * 2) % (B-1)

def num(A):
  b = 1
  r = 0
  for i in range(len(A)):
    r += b * int(A[-i-1])
    b *= 2
  return r

def f(n):
  global call
  call += 1
  bit = 0
  m = n
  while m > 0:
    if m % 2 == 1:
      bit += 1
    m //= 2
  next_n = n % bit
  if next_n > 0:
    f(next_n)

x = num(X)
x1 = x % (B+1)
if B > 1:
  x2 = x % (B-1)
#print('x', len(X))

for i in range(N):
  call = 0
  if X[i] == '0':
    y = (x1 + base_mod_1[-i-1]) % (B+1)
    R = B + 1
    call = 1
  else:
    if B > 1:
      y = (x2 - base_mod_2[-i-1]) % (B-1)
      R = B - 1
      call = 1
    else:
      y = 0
#  print(y, '+', call)
  if y > 0:
    f(y)
  print(call)
### BUGGY CODE ###

l, r = map(int,input().split())
arr = []
if r-l < 2019**2:
  for i in range(l,r):
    for j in range(i+1,r+1):
      a = (i*j)%2019
      arr.append(a)
  print(min(arr))
else:
  print(0)

### FIXED CODE ###

l, r = map(int,input().split())
arr = []
if r-l < 2019**2:
  for i in range(l,r):
    for j in range(i+1,r+1):
      a = (i*j)%2019
      arr.append(a)
    if 0 in arr:
      break
  print(min(arr))
else:
  print(0)
### BUGGY CODE ###


from collections import deque
h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]
dist = [[float('inf')]*w for _ in range(h)]
moves = ((1, 0), (0, 1), (0, -1), (-1, 0))
visited = [[0]*w for _ in range(h)]

def bfs(li):
  q = deque(li)
  while q:
    y, x = q.popleft()
    for dy, dx in moves:
      ny = y + dy 
      nx = x + dx 
      if 0<=ny<h and 0<=nx<w and a[ny][nx]=='.' and visited[ny][nx]==0 and dist[ny][nx]>dist[y][x]+1:
        dist[ny][nx] = dist[y][x] + 1
        visited[ny][nx] = 1
        q += [[ny, nx]]

li = []
for i in range(h):
  for j in range(w):
    if a[i][j] == '#':
      li += [[i, j]]
      dist[i][j] = 0
      visited[i][j] = 1

bfs(li)

ans = 0
for i in range(h):
  for j in range(w):
    ans = max(ans, dist[i][j])

print(ans)

### FIXED CODE ###

from collections import deque
h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]
moves = ((1, 0), (-1, 0), (0, 1), (0, -1))
cnt = [[float('inf') for _ in range(w)] for _ in range(h)]
ans = 0
searched = [[0 for _ in range(w)] for _ in range(h)]
q = deque([])

def bfs():
  while q:
    y, x = q.popleft()
    for dy, dx in moves:
      next_y = y + dy
      next_x = x + dx 
      if 0 <= next_y < h and 0 <= next_x < w and searched[next_y][next_x] == 0 and a[next_y][next_x] == '.' and cnt[next_y][next_x] > cnt[y][x]+1:
        searched[next_y][next_x] = 1
        q.append([next_y, next_x])
        cnt[next_y][next_x] = cnt[y][x]+1

for i in range(h):
  for j in range(w):
    if a[i][j] == '#':
      cnt[i][j] = 0
      searched[i][j] = 1
      q.append([i, j])

bfs()
for i in range(h):
  for j in range(w):
    ans = max(ans, cnt[i][j])

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

N = int(input())
S = [sorted(input()) for i in range(N) ]
counter = 0
for i in range(N):
    for j in range(i+1,N):
        for k in range(10):
            if S[i][k]!=S[j][k]:
                break
            if k == 9:
                counter +=1
print(counter)


### FIXED CODE ###

import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N = int(input())
dic_s = {}
for i in range(N):
    s = "".join(sorted(input()))
    if s in dic_s:
        dic_s[s] += 1
    else:
        dic_s[s] = 1
counter = 0
for key,value in dic_s.items():
    if value >1:
        counter += combinations_count(value,2)
print(counter)
### BUGGY CODE ###

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

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    count = 0

    for x in set(a):
        elements_count = a.count(x)

        if (elements_count >= x) and (x <= 10 ** 5):
            count += elements_count - x
        else:
            count += elements_count

    print(count)


### FIXED CODE ###

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

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    count = 0

    from collections import Counter
    counted_a = Counter(a)

    for x in counted_a:
            if counted_a[x] >= x:
                count += counted_a[x] - x
            else:
                count += counted_a[x]

    print(count)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
N, D, A = map(int, input().split(' '))
X_H_pairs = [list(map(int, input().split(' '))) for _ in range(N)]

X_H_pairs.sort(key=lambda x: x[0])

import math
i, ans = 0, 0
while i < N:
    x, h = X_H_pairs[i]
    if h <= 0:
        i += 1
        continue
    else:
        times = int(math.ceil(h / A))
        ans += times

        dh = times * A
        dx = x + 2*D
        j = i
        while j < N and X_H_pairs[j][0] <= dx:
            X_H_pairs[j][1] -= dh
            j += 1
        i += 1

print(ans)

### FIXED CODE ###

# -*- coding: utf-8 -*-
N, D, A = map(int, input().split(' '))
X_H_pairs = [list(map(int, input().split(' '))) for _ in range(N)]

X_H_pairs.sort(key=lambda x: x[0])

import math
i, ans = 0, 0
powers = []
damage = 0
while i < N:
    x, h = X_H_pairs[i]
    if powers:
        while powers and x - powers[0][0] > 2*D:
            damage -= powers[0][1]
            powers.pop(0)

    h -= damage
    if h <= 0:
        i += 1
        continue
    else:
        times = int(math.ceil(h / A))
        ans += times

        dh = times * A
        damage += dh
        powers.append((x, dh))
        i += 1

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

import sys
input = sys.stdin.readline
from collections import deque
n = int(input())
a = list(map(int,input().split()))
ls = [[0 for i in range(n)] for j in range(n)]
for i in range(n):
  for j in range(n):
    ls[i][j] = min(i,j,n-1-i,n-1-j)
ans = 0
st = set()
for i in a:
  x,y = divmod(i-1,n)
  ans += ls[x][y]
  st.add((x,y))
  q = deque([(x,y)])
  while q:
    px,py = q.popleft()
    for nx,ny in (px-1,py),(px+1,py),(px,py+1),(px,py-1):
      if 0 <= nx < n and 0 <= ny < n:
        if (px,py) in st:
          if ls[px][py] < ls[nx][ny]:
            ls[nx][ny] = ls[px][py]
            q.append((nx,ny))
        elif ls[px][py]+1 < ls[nx][ny]:
          ls[nx][ny] = ls[px][py]+1
          q.append((nx,ny))
print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline
from collections import deque
n = int(input())
a = list(map(int,input().split()))
n += 2
ls = [0 for i in range(n*n)]
for i in range(n):
  for j in range(n):
    ls[i*n+j] = min(i,j,n-1-i,n-1-j)-1
ans = 0
st = [0]*(n*n)
for i in a:
  x,y = divmod(i-1,n-2)
  i = (x+1)*n+(y+1)
  ans += ls[i]
  st[i]=1
  q = deque([i])
  while q:
    j = q.popleft()
    for k in (j-n,j+n,j+1,j-1):
      if st[j]:
        if ls[j] < ls[k]:
          ls[k] = ls[j]
          q.append(k)
      elif ls[j]+1 < ls[k]:
        ls[k] = ls[j]+1
        q.append(k)
print(ans)
### BUGGY CODE ###

import math

H, W, N = map(int, input().split())
count = [0]*10
count[0] = (H-2)*(W-2)
rectmap=[]

#print(board)
for i in range(0,N):
    a, b = input().split()
    a = int(a)
    b = int(b)
    al = max(a-1, 2)
    au = min(a+2, H)
    bl = max(b-1, 2)
    bu = min(b+2, W)

    for j in range(al, au):
        for k in range(bl, bu):
            rectmap.append([j-1, k-1])
##    for j in range(a-1, a+2):
##        for k in range(b-1, b+2):
##            if j>1 and j<H and k>1 and k<W:
##                rectmap.append([j-1, k-1])
#print(rectmap)
rectmap.sort()
rectmap.append([])
while len(rectmap)!=1 :
#    print(rectmap[0])
#    print(rectmap)
    c=0
#    print(rectmap)
    while rectmap[0]==rectmap[1]:
        c+=1
        rectmap.pop(0)
    c+=1
    rectmap.pop(0)
#    print(rectmap)
#    input()
    count[c]+=1
    count[0]-=1
for i in range(0, 10):
    print(count[i])    
#print(H,W,N)
#print(ab)


### FIXED CODE ###

import math

H, W, N = map(int, input().split())
count = [0]*10
count[0] = (H-2)*(W-2)
rectmap={}

#print(board)
for i in range(0,N):
    a, b = input().split()
    a = int(a)
    b = int(b)
    ab = (a, b)
    al = max(a-1, 2)
    au = min(a+2, H)
    bl = max(b-1, 2)
    bu = min(b+2, W)

    for j in range(al, au):
        for k in range(bl, bu):
            if (j,k) in rectmap:
                rectmap[(j,k)] +=1
            else:
                rectmap[(j,k)] = 1
#            print(rectmap)
##    for j in range(a-1, a+2):
##        for k in range(b-1, b+2):
##            if j>1 and j<H and k>1 and k<W:
##                rectmap.append([j-1, k-1])
#print(rectmap)
for i in rectmap.values():
    count[i]+=1
    count[0]-=1
for c in count:
    print(c)
#print(H,W,N)
#print(ab)
### BUGGY CODE ###

n,m = map(int,input().split())
ps_lst = [list(map(str,input().split())) for _ in range(m)]
ac_count = 0
wa_count = 0

ac_prolst = []
for i in range(len(ps_lst)):
    number = ps_lst[i][0]
    answer = ps_lst[i][1]
    if answer=='AC':
        ac_prolst.append(number)
ac_lst = list(set(ac_prolst))

ps_dic = {}
for i in range(m):
    number = ps_lst[i][0]
    if number in ac_lst:
        tmp_dic = {number: 'WA'}
        ps_dic.update(tmp_dic)

for i in range(m):
    number = ps_lst[i][0]
    answer = ps_lst[i][1]

    if number in ac_lst:
        if answer == 'AC' and ps_dic[number] == 'WA':
            ac_count += 1
            tmp_dic = {number: 'AC'}
            ps_dic.update(tmp_dic)
        elif answer == 'WA' and ps_dic[number] == 'WA':
            wa_count += 1

print('{} {}'.format(ac_count, wa_count))

### FIXED CODE ###

def main():
    n, m = map(int, input().split())
    ps_lst = [list(map(str, input().split())) for _ in range(m)]
    judge_lst = [0] * n
    penalty_lst = [0] * n
    correct = 0
    penalty = 0

    for i in range(m):
        problem = int(ps_lst[i][0]) - 1
        result = ps_lst[i][1]
        
        if judge_lst[problem] == 0:
            if result == 'AC':
                judge_lst[problem] = 1
            else:
                penalty_lst[problem] += 1

    for i in range(n):
        if judge_lst[i] == 1:
            correct += 1
            penalty += penalty_lst[i]
            
    print(correct, penalty)


if __name__ == '__main__':
    main()