Harryxun/stf_run huggingface dataset:
def resolve():
    x, n = list(map(int, input().split()))

    if n > 0:
        p = list(map(int, input().split()))
        q = [i for i in range(1, max(p)+1)]
        for item in p:
            if item in q:
                q.remove(item)

        ans = []
        current_min = float('inf')
        for item in q:
            diff = abs(x-item)
            if diff < current_min:
                current_min = diff
                ans = []
                ans.append(item)
            elif diff == current_min:
                ans.append(item)

        print(min(ans))
    else:
        print(x)


if 'unittest' not in globals():
    resolve()


### FIXED CODE ###

def resolve():
    x, n = list(map(int, input().split()))

    if n > 0:
        p = list(map(int, input().split()))
        q = [i for i in range(min(p)-1, max(p)+2)]
        for item in p:
            if item in q:
                q.remove(item)

        ans = []
        current_min = float('inf')
        for item in q:
            diff = abs(x-item)
            if diff < current_min:
                current_min = diff
                ans.clear()
                ans.append(item)
            elif diff == current_min:
                ans.append(item)

        print(min(ans))
    else:
        print(x)


if 'unittest' not in globals():
    resolve()
from fractions import gcd
def lcm(x,y):
  return int(x*y/gcd(x,y))
n=int(input())
a=list(map(int,input().split()))
for i in range(1,len(a)):
  if i==1:g=lcm(a[0],a[1])
  else:g=lcm(g,a[i])
c=0
for j in range(len(a)):
  c+=(g-1)%a[j]
print(c)

### FIXED CODE ###

input()
a=list(map(int,input().split()))
print(sum(a)-len(a))
import sys
t='X'
for e in sys.stdin:
 for i in'0123456789'[(e[0]==t)*(e[1]!='+')or('+X'in e)*('+X='not in e)or(e[-2:]=='=X'):]:
  if eval(e.replace(t,i).replace('=','==')):print(i);break
 else:print('NA')


### FIXED CODE ###

import sys
p,t='+X'
for e in sys.stdin:
 for i in'0123456789'[(e[0]==t)*(e[1]!=p)or('+X'in e)*('+X='not in e):]:
  l,r=e.replace(t,i).split('=')
  if sum(map(int,l.split(p)))==int(r):print(i);break
 else:print('NA')
from itertools import takewhile
(lambda *_: None)(*map(print,
                       map(eval,
                           map(lambda s: s.replace('/', '//'),
                               takewhile(lambda s: '?' not in s,
                                         iter(input, '')))))

### FIXED CODE ###

from __future__ import division, print_function
from sys import stdin, exit
from operator import add, sub, mul, floordiv
d = {'+': add, '-': sub, '*': mul, '/': floordiv, '?': lambda a,b: exit(0)}
while True:
    a, op, b = stdin.readline().split()
    print(d[op](int(a), int(b)))
def solve(n,p):
    
    memo = {}
    items = [(0,p)]
    result = 0
    while items:
        step, p = items.pop(0)
        if check(n,p):
            result = step
            break
        else:
            for i in range(n-1):
                candidate = tuple( p[:i] +[ p[i+1] ,p[i]] + p[i+2:] )
                if not candidate in memo:
                    items.append([step +1 , list(candidate)])
                    memo[candidate] = step + 1
                
    return result

if __name__ == '__main__':
    n = int(input())
    p = list(map(int, input().split(" ")))
    print(solve(n, p))


### FIXED CODE ###

def solve(n, p):
    result = 0
    for i in range(n-1):
        if (i+1) == p[i]:
            p[i], p[i+1] = p[i+1],p[i]
            result += 1
    i = n - 1
    if (i+1) == p[i]:
        p[i-1], p[i] = p[i],p[i-1]
        result += 1
    return result

if __name__ == '__main__':
    n = int(input())
    p = list(map(int, input().split(" ")))
    print(solve(n, p))
A, B = map(int, input().split())
 
def common_divisors(a, b):
    a = fractions.gcd(a, b)
    divisors =  [d for d in range(2, a // 2 + 1) if a % d == 0] + [a]
    if not 1 in divisors:
        divisors.append(1) 
    return divisors, a

CommonDivs, _ =  common_divisors(A, B)   
#print(CommonDivs)
 
from collections import deque
CommonDivs.reverse()
q = deque(CommonDivs)
ans = [q.pop()]
max_n = max(CommonDivs)
while len(q) > 0:
    a = q.pop()
    ans.append(a)
    if max_n/2 < a:
        break
    for _ in range(len(q)):
        b = q.pop()
        if b % a != 0:
            q.appendleft(b)

### FIXED CODE ###

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


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors

import math

def is_prime(n):
    if n == 1: return True

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True

import fractions
x = fractions.gcd(A, B)
divisors = make_divisors(x)
ans = 0
for d in divisors:
    if is_prime(d):
        ans += 1
print(ans)
N = int(input())
A = [int(input()) for i in range(N)]
L = [0 for i in range(10*9)]
for j in range(N):
  L[A[j]] += 1
ans = 0
for k in range(len(L)):
  if (L[k] == 0):
    None
  elif (L[k]%2 == 0):
    None
  else:
    ans += 1
print(ans)

### FIXED CODE ###

N = int(input())
A = [int(input()) for i in range(N)]
A.sort()
j = 1
J = 1
ans = 0
for j in range(1,len(A)):
  if (A[j-1] == A[j]):
    J += 1
  else:
    if (J%2 != 0):
      ans += 1
      J = 1
    else:
      J = 1
if (J%2 != 0):
  ans += 1
print(ans)
N = int(input())
A = list(map(int,input().split()))
ck = 10000000000
for b in range(0,max(A)):
    k = 0
    for i in range(0,N):
        k = k + abs(A[i] - (b+i+1))
    if k < ck:
        ck = k
    elif k >= ck:
        print(ck)
        break


### FIXED CODE ###

N = int(input())
print(N if N%2 == 0 else N*2)
A = input()
B = input()
print("Yes") if A == B[:len(A)] and len(A)+1=len(B) else print("No")

### FIXED CODE ###

A = input()
B = input()
print("Yes") if len(A)+1==len(B) and A == B[:len(A)] else print("No")
N = int(input())
num = [0] * (2 * 10 ** 5)
A = list(map(int,input().split()))
for i in range(len(A)):
	num[A[i]] += 1
for i in range(1,N + 1):
	print(num[i])

### FIXED CODE ###

N = int(input())
num = [0] * (3 * 10 ** 5)
A = list(map(int,input().split()))
for i in range(len(A)):
	num[A[i]] += 1
for i in range(1,N + 1):
	print(num[i])
import sys
input = sys.stdin.readline

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

result = None
for i in range(101):
    for j in range(101):
        judge = True
        x, y, h = l[0]
        highest = abs(i - x) + abs(j - y) + h
        for x, y, h in l[1:]:
            if abs(i - x) + abs(j - y) + h != highest:
                judge = False
                break
        if judge:
            result = (i, j, highest)
            break
    if result:
        break

print(result[0], result[1], result[2])

### FIXED CODE ###

import sys
input = sys.stdin.readline

n = int(input())
l = []
for _ in range(n):
    x, y, h = map(int, input().split())
    if h >= 1:
        l.append([x, y, h])

result = None
for i in range(101):
    for j in range(101):
        judge = True
        x, y, h = l[0]
        highest = abs(i - x) + abs(j - y) + h
        if len(l) == 1:
            result = (x, y, h)
            break
        for x, y, h in l[1:]:
            if abs(i - x) + abs(j - y) + h != highest:
                judge = False
                break
        if judge:
            result = (i, j, highest)
            break
    if result:
        break

print(result[0], result[1], result[2])
N, M = int(int, input().split())

def kaizyo(n):
  if n == 1:
    return n
  return n * (n-1) 

if N == M:
  print(2 * kaizyo(N) * kaizyo(M))
else:
  if abs(N-M) == 1:
    print(kaizyo(N) * kaizyo(M))
  else:
    print(0)

### FIXED CODE ###

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

if N == M:
  print((2 * math.factorial(N) * math.factorial(M))%((10**9)+7))
else:
  if abs(N-M) == 1:
    print((math.factorial(N) * math.factorial(M))%((10**9)+7))
  else:
    print(0)
import statistics

while True:
  s=int(input())
  if s==0:
    break
  else:
   lst=list(map(int,input().split()))
  print("{0.8}".format(statitics.pstdev(lst)))
  

### FIXED CODE ###

import statistics

while True:
  s=int(input())
  if s==0:
    break
  else:
   lst=list(map(int,input().split()))
  print("{0:.8}".format(statistics.pstdev(lst)))
*t, = map(int, open(0).read().split())
try:
    m = 10 - min([i%10 for i in t if i%10])
except Value Error:
    m = 0
print(sum([-(-j // 10) for j in t])*10 - m)

### FIXED CODE ###

*t, = map(int, open(0).read().split())
try:
    m = 10 - min([i%10 for i in t if i%10])
except ValueError:
    m = 0
print(sum([-(-j // 10) for j in t])*10 - m)
n,x=map(int,input().split())
a=[int(i)for i in input().split()]
c=0
if a[0]>x:
  c=a[0]-x
  a[0]=x
  for i in range(1,len(a)):
    if a[i]+a[i+1]>x:
      c+=a[i]+a[i+1]-x
      a[i+1]=x-a[i]
print(c)

### FIXED CODE ###

n,x=map(int,input().split())
a=[int(i)for i in input().split()]
c=0
if a[0]>x:
  c=a[0]-x
  a[0]=x
for i in range(n-1):
  if a[i]+a[i+1]>x:
    c+=a[i]+a[i+1]-x
    a[i+1]=x-a[i]
print(c)
n = int)input())
xs = []
for i in range(n): xs.append(input())
m = int(input())
flag = 1
for i in range(m):
    s = input()
    if s in xs:
        print("Opened" if flag == 1 else "Closed", "by", s)
        flag ^= 1
    else:
        print("Unknown", s)

### FIXED CODE ###

n = int(input())
xs = []
for i in range(n): xs.append(input())
m = int(input())
flag = 1
for i in range(m):
    s = input()
    if s in xs:
        print("Opened" if flag == 1 else "Closed", "by", s)
        flag ^= 1
    else:
        print("Unknown", s)
# -*- coding: utf-8 -*-
n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
bc = [list(map(int,input().split())) for i in range(m)]
cb = [[-c,b] for b,c in bc]
from heapq import heappush, heappop, heapify
ret = 0
heapify(a)
heapify(cb)
flg = True
while flg and len(cb)>0:
    c,j = heappop(cb)
    for _ in range(j):
        min_a = heappop(a)
        if min_a < -c:
            ret+=(-c)
        else:
            ret+=min_a
            flg=False
            break
ret+=sum(a)
print(ret)

### FIXED CODE ###

# -*- coding: utf-8 -*-
n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
bc = [list(map(int,input().split())) for i in range(m)]
cb = [[-c,b] for b,c in bc]
from heapq import heappush, heappop, heapify
ret = 0
heapify(a)
heapify(cb)
flg = True
while flg and len(cb)>0:
    c,j = heappop(cb)
    for _ in range(j):
        if len(a)==0:
            flg=False
            break
        min_a = heappop(a)
        if min_a < -c:
            ret+=(-c)
        else:
            ret+=min_a
            flg=False
            break
ret+=sum(a)
print(ret)
def lcs():
???x = raw_input()
  y = raw_input()
???x_len = len(x)
  y_len = len(y)
  z2 = [0 for i in range(y_len+1)]

???for j in range(x_len):
   z1 = z2 + []
   for k in range(y_len):
      if x[i] == y[k]:
         z2[k+1] = z2[k] + 1
      elif z2[k+1] < z2[k]:???
?????????   z2[k+1] = z2[k]

  return z2[-1]

num = input()
for l in range(num):
  print lcs()

### FIXED CODE ###

def lcs():
  x = raw_input()
  y = raw_input()
  x_len = len(x)
  y_len = len(y)
  z2 = [0 for i in range(y_len+1)]

  for i in range(x_len):
    z1 = z2 + []
    ele = x[i]
    for k in range(y_len):
      if ele == y[k]:
        z2[k+1] = z1[k] + 1
      elif z2[k+1] < z2[k]:
        z2[k+1] = z2[k]

  return z2[-1]

num = input()
for j in range(num):
  print lcs()
# -*- coding: utf-8 -*-
n = input()
p = n[-3]+n[-2]+n[-1]
print(int(p))

### FIXED CODE ###

# -*- coding: utf-8 -*-
n = int(input())
a = 1000-n%1000
if a != 1000:
    print(a)
else:
    print(0)
n = int(input())
S = []
for i in range(n):
    s = input()
    S.append(s)
S.sort()
A = list(set(S))
A.sort()
#print(A)
#print(S)
NUM =[0]*len(A)
for j in range(len(A)):
    for i in range(len(S)):
        if (A[int(j)] == S[int(i)]):
            NUM[j] = NUM[j]+ 1
import numpy as np
b = np.argmax(NUM)
#print(NUM,b)
for e,i in enumerate(NUM):
    #print(NUM[b])
    if (i == NUM[b]):
        print(A[e])

### FIXED CODE ###

n = int(input())
S = []
for i in range(n):
    s = input()
    S.append(s)
S.sort()
A = list(set(S))
A.sort()
#print(A)
#print(S)
NUM =[0]*len(A)
j = 0
for i in range(len(S)):
    if(i+1<len(S)):
        if (S[i] == S[int(i)+1]):
            NUM[j] = NUM[j]+ 1
        else:
            j += 1
import numpy as np
b = np.argmax(NUM)
#print(NUM,b)
for e,i in enumerate(NUM):
    #print(NUM[b])
    if (i == NUM[b]):
        print(A[e])
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

#bisect.bisect_left(list,key)はlistのなかでkey未満の数字がいくつあるかを返す
#bisect.bisect_right(list, key)はlistのなかでkey以下の数字がいくつあるかを返す
#これを応用することで
#len(list) - bisect.bisect_left(list,key)はlistのなかでkey以上の数字がいくつあるかを返す
#len(list) - bisect.bisect_right(list,key)はlistのなかでkeyより大きい数字がいくつあるかを返す
#これらを使うときはあらかじめlistをソートしておくこと！

n,k = MI()
a = LI()

def cutting_isOK(x,li,k):
    ans = 0
    for i in range(n):
        ans += math.ceil(li[i]/x) - 1
    if ans <= k:
        return True
    else:
        return False
left = -1
right = 10**9+1
while right != left + 1:
    mid = (left+right)//2
    if cutting_isOK(mid,a,k):
        right = mid
    else:
        left = mid
print(right)



### FIXED CODE ###

#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**7)
import bisect
import heapq
import itertools
import math
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

#bisect.bisect_left(list,key)はlistのなかでkey未満の数字がいくつあるかを返す
#bisect.bisect_right(list, key)はlistのなかでkey以下の数字がいくつあるかを返す
#これを応用することで
#len(list) - bisect.bisect_left(list,key)はlistのなかでkey以上の数字がいくつあるかを返す
#len(list) - bisect.bisect_right(list,key)はlistのなかでkeyより大きい数字がいくつあるかを返す
#これらを使うときはあらかじめlistをソートしておくこと！

n,k = MI()
a = LI()

def cutting_isOK(x,li,k):
    ans = 0
    if x == 0:
      return False
    else:
      for i in range(n):
        ans += math.ceil(li[i]/x) - 1
      if ans <= k:
          return True
      else:
          return False
left = 0
right = 10**9+1
#全丸太の長さはk回以内の操作でright以下にできる
while right != left + 1:
    mid = (left+right)//2
    if cutting_isOK(mid,a,k):
        right = mid
    else:
        left = mid
print(right)
a, b = map(int, input().split())
if a%3==0 or b%3==0 of (a+b)%==0:
    print('Possible')
else:
    print('Impossible')

### FIXED CODE ###

a, b = map(int, input().split())
if a%3==0 or b%3==0 or (a+b)%3==0:
    print('Possible')
else:
    print('Impossible')
N,K=map(int,input().split())
S=input()
X,Y=[],[]
M=0
for i in range(len(S)):
  if(S[i]=='1' and M==0):
    X.append(i)
    M+=1
  elif(S[i]=='1'):
    M+=1
  else:
    if(M):
      Y.append(i-1)
    M=0
if(M):
  Y.append(len(S)-1)
ans=0
if(len(X)>=K):
  for i in range(len(X)-K):
    ans=max(ans,Y[i+K]-X[i]+1)
else:
  ans=len(S)
ans=max(ans,Y[min(K-1,len(X)-1)]+1)
ans=max(ans,len(S)-X[max(len(X)-K,0)])
print(ans)

### FIXED CODE ###

N,K=map(int,input().split())
S=input()
X,Y=[],[]
M=0
for i in range(len(S)):
  if(S[i]=='1' and M==0):
    X.append(i)
    M+=1
  elif(S[i]=='1'):
    M+=1
  else:
    if(M):
      Y.append(i-1)
    M=0
if(M):
  Y.append(len(S)-1)
ans=0
if(len(X)>=K):
  for i in range(len(X)-K):
    ans=max(ans,Y[i+K]-X[i]+1)
else:
  ans=len(S)
if(len(X)):
  ans=max(ans,Y[min(K-1,len(X)-1)]+1)
  ans=max(ans,len(S)-X[max(len(X)-K,0)])
print(ans)
from math import sqrt
inf = 10**10
x_s, y_s, x_t, y_t = map(int, input().split())
N = int(input())
xyr = []
for i in range(N):
	x_i, y_i, r_i = map(int, input().split())
	xyr.append((x_i, y_i, r_i))
p = (x_s, y_s)
goal = (x_t, y_t)
ans = 0
while p != goal and xyr:
	D = inf
	for i in range(N):
		x, y, r = xyr[i]
		d = sqrt((x-p[0])**2+(y-p[1])**2) - 2*r
		if d < D:
			j = i
			D = d
	d = sqrt((goal[0]-p[0])**2+(goal[1]-p[1])**2)
	if d < D:
		ans += d
		p = goal
	else:
		x, y, r = xyr.pop(j)
		p = (x, y)
		N -= 1
		ans += D

if p != goal:
	d = sqrt((goal[0]-p[0])**2+(goal[1]-p[1])**2)
	ans += d

print(max(0, ans))
	

### FIXED CODE ###

N, x = map(int, input().split())
a = [int(i) for i in input().split()]
ans = 0
for i in range(N-1):
	if a[i] + a[i+1] > x:
		d = a[i] + a[i+1] - x
		if d <= a[i+1]:
			a[i+1] -= d
			ans += d
		else:
			a[i] -= d - a[i+1]
			a[i+1] = 0
			ans += d
print(ans)
n=input()
k=input()
S=input()
N=int(n)
K=int(k)
S_list=list(S)
if S[K-1]=="A":
 S_list[K-1]="a"
elif S[K-1]=="B":
 S_list[K-1]="b"
elif S[K-1]=="C":
 S_list[K-1]="c"
S="".join(S_list)
print(S)

### FIXED CODE ###

n=input()
n1=n[:2]
n2=n[2:]
A=int(n1)
B=int(n2)
if 0<A<13:
    if 0<B<13:
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if 0<B<13:
        print("YYMM")
    else:
        print("NA")
a,b,c = map(int,input().split())
print('YES' if b-a=c-b else 'NO')

### FIXED CODE ###

a,b,c = map(int,input().split())
print('YES' if b-a==c-b else 'NO')
import sys

n = input()
ai = raw_input()
ai = map(int, ai.split())

for i in reversed(range(1, n)):
	sys.stdout.write(str(ai[i])+" ")
print ai[i-1]

### FIXED CODE ###

import sys

n = input()
ai = raw_input()
ai = map(int, ai.split())

for i in reversed(range(1, n)):
	sys.stdout.write(str(ai[i])+" ")
print ai[0]
import math
from functools import reduce
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)
# def lcm_list(numbers):
#     return reduce(lcm_base, numbers, 1)
nm=list(map(int, input().split()))
a=list(map(int, input().split()))
n=nm[0]
m=nm[1]
b=0
while a[0]%2==0:
    for i in range(len(a)):
        if a[i]%2==0:
            a[i]=a[i]//2
        else:
            b=1
            break
if b==1:
    print(0)
else:
    amc=lcm_list(a)
    print((m+amc)//(2*amc))



### FIXED CODE ###

import fractions
from functools import reduce
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
nm=list(map(int, input().split()))
a=list(map(int, input().split()))
n=nm[0]
m=nm[1]
b=0
c=a[0]
dnum=0
while c%2==0:
    dnum+=1
    c=c//2
for i in range(len(a)):
    c=a[i]
    dnum1=0
    while c%2==0:
        dnum1+=1
        c=c//2
    #print(dnum)
    if dnum1!=dnum:
        b=1
        break

#print(a)
if b==1:
    print(0)
else:
    for i in range(len(a)):
        a[i]=a[i]//2
    #print(a)
    amc=lcm_list(a)
    #print(amc)
    # version3.5にてgcdがfractionsからmathに移動した
    print(int((m+amc)/(2*amc)))
s=input()
if s[0]=='S':
   print('Cloudy')
else if s[0]=='C':
   print('Rainy')
else:
   print('Sunny')


### FIXED CODE ###

s=input()
if s[0]=='S':
   print('Cloudy')
elif s[0]=='C':
   print('Rainy')
else:
   print('Sunny')
# coding: utf-8
# Your code here!
n = int(input())
l = list(map(int, input().split()))
if len(set(l)) == 3:
    print('Three')
else:
    print('Four')


### FIXED CODE ###

# coding: utf-8
# Your code here!
n = int(input())
l = list(map(str, input().split()))
if len(set(l)) == 3:
    print('Three')
else:
    print('Four')
import sys
input = sys.stdin.readline

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

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

if m==0:
    cnt = 0
    steps = n
    for j in range(steps//2+1):
        if j == 0:
            cnt += 1
        else:
            seat = steps - j
            cnt += combinations_count(seat,j)
    print(cnt % (10**9+7))

l = [-1]+[int(input())]
for i in range(m-1):
    a = int(input())
    if a == l[-1]+1:
        print(0)
        exit()
    l.append(a)
l.append(n+1)
# print(l)

ans = 1
for i in range(m+1):
    cnt = 0
    steps = l[i+1] - l[i] -2
    if steps == 0:
        continue
    for j in range(steps//2+1):
        if j == 0:
            cnt += 1
        else:
            seat = steps - j
            cnt += combinations_count(seat,j)
    ans *= cnt

print(ans % (10**9+7))

### FIXED CODE ###

import sys
input = sys.stdin.readline

n,m = map(int,input().split())
oks = [True]*(n+1)
for i in range(m):
    a = int(input())
    oks[a] = False

dp = [0]*(n+1)
dp[0] = 1
for i in range(n):
    for j in range(i+1,min(n,i+2)+1):
        if oks[j]:
            dp[j] += dp[i]
            dp[j] %= (10**9+7)
print(dp[n])
N,T=map(int,input().split())
l=[]
for i in range(N):
    c,t=map(int,input().split())
    if t<=T:
        l.append(c)
print(min(l))

### FIXED CODE ###

N,T=map(int,input().split())
l=[]
for i in range(N):
    c,t=map(int,input().split())
    if t<=T:
        l.append(c)
if len(l)>=1:
    print(min(l))
else:
    print('TLE')
A, B = map(int, input().split())
return A+B if B % A == 0 else B-A

### FIXED CODE ###

A, B = map(int, input().split())
print(A+B if B % A == 0 else B-A)
import math
n=float(input())
n*=2
print(n*math.pi

### FIXED CODE ###

import math
n=float(input())
n*=2
print(n*math.pi)
x, y = map(int, input().split())

while (x != 0 && y != 0):
    if x <= y :
        print(x, y)
    elif x > y :
        print(y, x)

    x = int(input())
    y = int(input())

### FIXED CODE ###

while 1:
    x,y = map(int,input().split())
    if not x+y:break
    if x > y : x,y = y,x
    print(x,y)
import sys
N = int(input())
array = [ I for I in range(1,10) ]

if not ( 1 <= N <= 100 ): sys.exit()

for J in range(1,10):
    for K in range(1,10):
        if n == J*K:
            print('Yes')
print('No')

### FIXED CODE ###

import sys
N = int(input())
array = [ I for I in range(1,10) ]

if not ( 1 <= N <= 100 ): sys.exit()

if N >= 82:
    print('No'); sys.exit()
else:
    for J in array:
        if (N % J) == 0 and (N // J) <= 9 : print('Yes'); sys.exit()
print('No')
N=input()
for i in range(6):
  if N[i]==N[i+1]:
    print("Yes")
    exit()
  else:
    print("No")

### FIXED CODE ###

N=input()
if N[2]==N[3] and N[4]==N[5]:
  print("Yes")
else:
  print("No")
import numpy as np

def dfs(x,y):
    z = h[y][x] + grid[y][x]
    for i in range(4):
        next_x = x+dx[i]
        next_y = y+dy[i]
        if h[next_y][next_x] > z:
            h[next_y][next_x] = z
            dfs(next_x,next_y)
n = int(input())
h = np.array([[0]*(n+2) for _ in range(n+2)])
for i in range(1,n+1):
    for j in range(1,n+1):
        h[i][j] = min(i,n-i+1,j,n-j+1)-1
grid = np.array([[1]*(n+1) for _ in range(n+1)])
dx = np.array([0,1,0,-1])
dy = np.array([1,0,-1,0])
ans = 0
p = list(map(int,input().split()))
for i in range(n**2):
    pos = p[i]
    x = (pos-1)%n+1
    y = (pos-1)//n+1
    ans += h[y][x]
    grid[y][x] = 0
    dfs(x,y)
print(ans)


### 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))