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

from itertools import combinations

N, K=map(int, input().split())
an=list(map(int,input().split()))

if K in an:
    print('POSSIBLE')
    exit()

while True:
    comb=combinations(an, 2)
    prean = an[:]
    for it in comb:
        a = abs(it[0] - it[1])
        if a in an:
            continue
        if a == K:
            print('POSSIBLE')
            exit()
        an.append(a)
    if len(an) == len(prean):
        print('IMPOSSIBLE')
        break

### FIXED CODE ###

from functools import reduce
from fractions import gcd

N, K=map(int, input().split())
an=list(map(int,input().split()))

m = max(an)
g = reduce(lambda x, y: gcd(x, y), an)

if K <=m and K % g == 0:
    print ('POSSIBLE')
else:
    print ('IMPOSSIBLE')
### BUGGY CODE ###

#TLEしてしまう…
(N,D,A) = map(int,input().split())
l = []
for i in range(N):
    l.append([int(x) for x in input().split()])
    l.sort()
k = [0 for i in range(N)]
for i in range(N):
    k[i] = -((-l[i][1])//A)

m = []
for i in range(N):
    cnt = 0
    j = i
    while l[j][0]-l[i][0] <= 2*D:
        cnt += 1
        j += 1
        if j >= N:
            break
    m.append(cnt)

ans = 0
for i in range(N):
    if  k[i] != 0:
        for p in range(1,m[i]):
            if k[i+p] >= k[i]:
                k[i+p] -= k[i]
            else:
                k[i+p] = 0
        ans += k[i]

print(ans)

### FIXED CODE ###

(N,D,A) = map(int,input().split())
l = []
for i in range(N):
    l.append([int(x) for x in input().split()])
l.sort()
k = [0 for i in range(N)]
for i in range(N):
    k[i] = -((-l[i][1])//A)

m = [0] * N
ub = 0
cnt = 1
for i in range(N):
    if ub < N-1:
        while l[ub + 1][0]-l[i][0] <= 2*D:
            cnt += 1
            ub += 1
            if ub == N - 1:
                break
        m[i] = cnt
    else:
        m[i] = cnt
    cnt -= 1

ans = 0
al = 0
s = [0 for i in range(N)]
j = 0
for i in range(N):
    s[i] = max(k[i]-al,0)
    ans += s[i]
    al += s[i]
    if i < N-1:
        while j+m[j]-1 < i+1:
            al -= s[j]
            if j < N-1:
                j += 1

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

from itertools import*
n, *a = map(int, open(0).read().split())
print(sum(a[i] == j + 1 and a[j] == i + 1 for i, j in combinations(range(n), 2)))

### FIXED CODE ###

*a, = map(int, open(0).read().split())
c = 0
for i, j in enumerate(a):
  c += (a[j:j+1] == [i])*(i > 0)
print(c // 2)
### BUGGY CODE ###

n,m = map(int,input().split())
while n <= m:
  if m%n == 0:
    print(m//n)
    break
  n += 1

### FIXED CODE ###

n,m = map(int, input().split())
if n*n <= m:
  k = n
  while k*k <= m:
    if m%k == 0:
      print(m//k)
      exit()
    k += 1
else:
  n = m//n

k = n
while True:
  if m%k == 0:
    print(k)
    exit()
  k -= 1
### BUGGY CODE ###

n, m = map(int, input().split())
py_dict = dict()
ip_dict = dict()

for i in range(m):
    py_list = list(map(int, input().split()))
    py_list.append(i)
    if py_list[0] in py_dict:
        py_dict[py_list[0]].append(py_list)
    else:
        py_dict[py_list[0]] = [py_list]
    ip_dict[i] = py_list[0]

for item in py_dict:
    tmp_list = py_dict[item]
    tmp_list.sort(key=lambda x: x[1])
    for i in range(len(tmp_list)):
        tmp_list[i].append(i+1)
    tmp_list.sort(key=lambda x: x[2])

for i in range(m):
    p = ip_dict[i]
    t_list = py_dict[p].pop(0)
    b = t_list[3]
    print(str(p).zfill(6) + str(b).zfill(6))


### FIXED CODE ###

n, m = map(int, input().split())
py_dict = dict()
ip_dict = dict()
io_dict = dict()

for i in range(m):
    py_list = list(map(int, input().split()))
    py_list.append(i)
    if py_list[0] in py_dict:
        py_dict[py_list[0]].append(py_list)
    else:
        py_dict[py_list[0]] = [py_list]
    ip_dict[i] = py_list[0]

for item in py_dict:
    tmp_list = py_dict[item]
    tmp_list.sort(key=lambda x: x[1])
    for i in range(len(tmp_list)):
        io_dict[tmp_list[i][2]] = str(
            ip_dict[tmp_list[i][2]]).zfill(6) + str(i+1).zfill(6)

for i in range(m):
    print(io_dict[i])
### BUGGY CODE ###

N = int(input())

# A = list(map(int, input().split()))
# print(N, A)
A = []
l = input().split()
total = 0
sub = 0
for i in range(len(l)):
    v = int(l[i])
    A.append(v)
    total += v
    if i % 2 == 1:
        sub += v

M = [0]*N
# total = sum(A)
# sub = 0
# for i in range((N-1)//2):
#     sub += A[2*i + 1]
# print(total, sub)
M[0] = total - 2 * sub
ans = "{} ".format(M[0])
for i in range(1, N):
    m = 2 * A[i - 1] - M[i - 1]
    M[i] = m
    ans += str(m) + " "
# print(M)
print(ans[0:-1])


### FIXED CODE ###

N = int(input())

# A = list(map(int, input().split()))
# print(N, A)
A = []
l = input().split()
total = 0
sub = 0
for i in range(len(l)):
    v = int(l[i])
    A.append(v)
    total += v
    if i % 2 == 1:
        sub += v

M = [0]*N
# total = sum(A)
# sub = 0
# for i in range((N-1)//2):
#     sub += A[2*i + 1]
# print(total, sub)
M[0] = total - 2 * sub
for i in range(1, N):
    m = 2 * A[i - 1] - M[i - 1]
    M[i] = m
# print(M)
ans = " ".join(map(str, M))
print(ans)
### BUGGY CODE ###

def main():
    r, c, k = map(int, input().split())
    vals = [[0]*c for _ in range(r)]
    for _ in range(k):
        x, y, v = map(int, input().split())
        vals[x-1][y-1] = v
    dp = [[[0]*4 for j in range(c)] for i in range(r)]
    for i in range(r):
        for j in range(c):
            if i > 0:
                tmp = 0
                for k in range(4):
                    if tmp < dp[i-1][j][k]:
                        tmp = dp[i-1][j][k]
                dp[i][j][0] = tmp
            if j > 0:
                for k in range(4):
                    if dp[i][j][k] < dp[i][j-1][k]:
                        dp[i][j][k] = dp[i][j-1][k]
            for k in range(3, 0, -1):
                if dp[i][j][k] < dp[i][j][k-1] + vals[i][j]:
                    dp[i][j][k] = dp[i][j][k-1] + vals[i][j]
    print(max(dp[r-1][c-1]))

if __name__ == "__main__":
    main()

### FIXED CODE ###

from sys import stdin
input = stdin.readline

r, c, k = map(int, input().split())
vals = [[0]*c for _ in range(r)]
for _ in range(k):
    x, y, v = map(int, input().split())
    vals[x-1][y-1] = v
dp = [[0]*4 for j in range(c)]
for j in range(c):
    if j > 0:
        for k in range(4):
            dp[j][k] = dp[j-1][k]
    if vals[0][j] > 0:
        for k in reversed(range(3)):
            if dp[j][k+1] < dp[j][k] + vals[0][j]:
                dp[j][k+1] = dp[j][k] + vals[0][j]
for i in range(1, r):
    tmp = [[max(dp[j]), 0, 0, 0] for j in range(c)]
    for j in range(c):
        if j > 0:
            for k in range(4):
                if tmp[j][k] < tmp[j-1][k]:
                    tmp[j][k] = tmp[j-1][k]
        if vals[i][j] > 0:
            for k in reversed(range(3)):
                if tmp[j][k+1] < tmp[j][k] + vals[i][j]:
                    tmp[j][k+1] = tmp[j][k] + vals[i][j]
    dp = tmp
print(max(dp[-1]))
### BUGGY CODE ###

n = int(input())
ss = [[""]]*n
for i in range(n):
    s = list(input())
    s.sort()
    ss[i] = s

def annagram(s1, s2):
    for i in range(10):
        if s1[i] != s2[i]:
            return False
    return True


ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        if annagram(ss[i], ss[j]):
            ans += 1

print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline

n = int(input())
ss = [[""]]*n
for i in range(n):
    s = list(input())
    s.sort()
    ss[i] = s

ss.sort()

ans = 0
while len(ss) != 0:
    f = ss.pop(0)
    c = 1
    while len(ss) > 0:
        d = ss[0]
        if f == d:
            ss.pop(0)
            ans += c
            c += 1
        else:
            break

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

def main():
  H,W,D = map(int,input().split())
  A = [[] for _ in range(H)]
  posi = [[]] * (H * W)
  
  for _ in range(H):
    a = list(map(int,input().split()))
    A[_] = a
    for i,j in enumerate(a):
      k = i + 1
      t = _ + 1
      posi[j - 1] = [t,k]
  
  Q = int(input())
  
  acdist = [0] * (H * W)
  
  for _ in range(0,H * W - D):
    for d in range(_,H * W - D,D):
      acdist[_] += abs(posi[d + D][0] - posi[d][0]) + abs(posi[d + D][1] - posi[d][1])
  
  for i in range(Q):
    l,r = map(int,input().split())
    print(acdist[l - 1] - acdist[r - 1])
    
if __name__ == '__main__':
  main()

### FIXED CODE ###

H,W,D = map(int,input().split())
posi = [[]] * (H * W)

for _ in range(H):
  a = list(map(int,input().split()))
  for i,j in enumerate(a):
    posi[j - 1] = [_ + 1,i + 1]

Q = int(input())

acdist = [0] * (H * W)

for _ in range(0,H * W - D):
  acdist[_ + D] += acdist[_] + abs(posi[_ + D][0] - posi[_][0]) + abs(posi[_ + D][1] - posi[_][1])

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

s  = str(input())

q = int(input())
count_inv = 0
for i in range(q):
  inlis = list(map(str,input().split())) + [0,0]
  # print(inlis)
  # print(inlis[0],inlis[1],inlis[2])
  if inlis[0] ==  "1":
    count_inv += 1
    count_inv %= 2
  if inlis[0] == "2":
    if inlis[1]  == "1":
      if count_inv == 0:
        s = str(inlis[2])+str(s)
      elif count_inv == 1:
        s = s = str(s)+str(inlis[2])
      # print(1)
    if inlis[1] == "2":
      if count_inv == 0:
        s = str(s)+str(inlis[2])
      elif count_inv == 1:
        s = str(inlis[2])+str(s)
      # print(2)
  # print(s)
if count_inv == 1:
  s = s[::-1]
print(s)
     



### FIXED CODE ###

s  = str(input())
t = ""
u = ""
q = int(input())
count_inv = 0
for i in range(q):
  inlis = list(map(str,input().split())) + [0,0]
  if inlis[0] ==  "1":
    count_inv += 1
    count_inv %= 2
  if inlis[0] == "2":
    if inlis[1]  == "1":
      if count_inv == 0:
        u += str(inlis[2])
      else:
        t += str(inlis[2])
      # print(1)
    if inlis[1] == "2":
      if count_inv == 0:
        t += str(inlis[2])
      else:
        u += str(inlis[2])
      # print(2)
  # print(s)
if count_inv == 0:
  u = u[::-1]
  ans = u+s+t
else:
  t = t[::-1]
  s = s[::-1]
  ans = t+s+u
print(ans)
### BUGGY CODE ###

from collections import defaultdict
H, W, M = map(int, input().split())
hw = []
for _ in range(M):
    h, w = map(int, input().split())
    hw.append([h, w])

A = defaultdict(int)
B = defaultdict(int)
for i in range(M):
    A[hw[i][0]] += 1
    B[hw[i][1]] += 1

max_A = max(A.values())
max_B = max(B.values())

new_H = []
for i, v in A.items():
    if v == max_A:
        new_H.append(i - 1)

new_W = []
for i, v in B.items():
    if v == max_B:
        new_W.append(i - 1)

new_H.sort()
new_W.sort()
max_num = max_A + max_B - 1
for i in new_H:
    for j in new_W:
        if A[i + 1] == max_A and B[j + 1] == max_B:
            if [i + 1, j + 1] in hw:
                continue
            else:
                print(max_A + max_B)
                exit()

print(max_num)


### FIXED CODE ###

H, W, M = map(int, input().split())
hw = set()
sum_h = [0] * W
sum_w = [0] * H
for _ in range(M):
    h, w = map(int, input().split())
    hw.add((h, w))
    h -= 1
    w -= 1
    sum_h[w] += 1
    sum_w[h] += 1


max_h = max(sum_h)
max_w = max(sum_w)

new_H = [h for h in range(H) if sum_w[h] == max_w]
new_W = [w for w in range(W) if sum_h[w] == max_h]

max_num = max_h + max_w - 1
for i in new_H:
    for j in new_W:
        if (i + 1, j + 1) not in hw:
            print(max_h + max_w)
            exit()
        else:
            continue
        break

print(max_num)
### BUGGY CODE ###

# coding: utf-8


def solve(*args: str) -> str:
    n, x, m = map(int, args[0].split())

    a = x
    ret = 0
    D = [0]*(m+1)
    for i in range(n):
        if 0 < D[a]:
            j = a
            L = []
            while D[j] != a:
                L.append(j)
                j = D[j]
            L.append(j)
            d, r = divmod(n-i-1, len(L))
            ret += d*sum(L)+sum(L[:r+1])
            break
        ret += a
        p = a
        a = pow(a, 2, m)
        D[p] = a

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


### FIXED CODE ###

# coding: utf-8


def solve(*args: str) -> str:
    n, x, m = map(int, args[0].split())

    a = x
    ret = 0
    D = [-1]*(m+1)
    for i in range(n):
        if 0 <= D[a]:
            j = a
            L = []
            while D[j] != a:
                L.append(j)
                j = D[j]
            L.append(j)
            d, r = divmod(n-i-1, len(L))
            ret += d*sum(L)+sum(L[:r+1])
            break
        ret += a
        p = a
        a = pow(a, 2, m)
        D[p] = a

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))
### BUGGY CODE ###

x = int(input())
x_mod = x % 5
i = 0
j = 10**5
while True:
    if i - (i - x_mod) == x_mod and i ** 5 - (i-x_mod)**5 == x:
        print(i, i-x_mod)
        break
    if j - (j - x_mod) == x_mod and j ** 5 - (j-x_mod)**5 == x:
        print(j, j-x_mod)
        break
    i += 1
    j += 1

### FIXED CODE ###

x = int(input())

for i in range(-120, 120):
    for j in range(-120, 120):
        if x == i ** 5 - j ** 5:
            print(i, j)
            exit()
### BUGGY CODE ###

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

L.sort()
#print(L)

ans=0
for i in range(0, N-2):
    for j in range(i+1, N-1):


        left, right = j, N

        while right-left > 1:
            mid=(left+right) // 2
            if L[i]+L[j] <= L[mid]:
                right=mid
            else:
                left=mid
        ans += left - j
        #print(i,j,left)
print(ans)

### FIXED CODE ###

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

L.sort()
#print(L)

ans=0
for i in range(0, N-2):
    for j in range(i+1, N-1):


        left, right = j, N

        while right-left > 1:
            mid=(left+right) // 2
            if L[i]+L[j] <= L[mid]:
                right=mid
            else:
                left=mid
        ans += left - j
        #print(i,j,left)
print(ans)
### BUGGY CODE ###

N = int(input())
sX = input()

origin_count = sX.count('1')
one_r_count = origin_count -1
zero_r_count = origin_count +1

one_mod = 0
zero_mod =0
for b in sX:
    if(one_r_count != 0):
        one_mod = (one_mod * 2) + int(b) % one_r_count
    zero_mod = (zero_mod * 2 ) + int(b) % zero_r_count

f = [0] * 220000
pop = [0]* 220000

for i in range(1,220000):
    pop[i] = pop[i//2] + i%2
    f[i] = f[i % pop[i]] + 1

onepow = [1] * 220000
zeropow = [1]* 220000

for i in range(1,220000):
    if(one_r_count != 0):
        onepow[i] = onepow[i-1] * 2 % one_r_count
    zeropow[i] = zeropow[i-1] * 2 % zero_r_count

for i in range(1,N+1):
    if(sX[i-1] == '1'):
        if(one_r_count != 0):
            Xi_n = one_mod - onepow[N-i]
            Xi_n %= one_r_count
            print(f[Xi_n]+1)
        else:
            print(0)
    else:
        Xi_n = zero_mod + zeropow[N-i]
        Xi_n %= zero_r_count
        print(f[Xi_n]+1)



### FIXED CODE ###

N = int(input())
sX = input()

origin_count = sX.count('1')
one_r_count = origin_count -1
zero_r_count = origin_count +1

one_mod = 0
zero_mod =0
for b in sX:
    if one_r_count != 0:
        one_mod = (one_mod * 2 + int(b) )% one_r_count
    zero_mod = (zero_mod * 2  + int(b) )% zero_r_count

f = [0] * 220000
pop = [0]* 220000

for i in range(1,220000):
    pop[i] = pop[i//2] + i % 2
    f[i] = f[i % pop[i]] + 1

onepow = [1] * 220000
zeropow = [1]* 220000

for i in range(1,220000):
    if one_r_count != 0:
        onepow[i] = onepow[i-1] * 2 % one_r_count
    zeropow[i] = zeropow[i-1] * 2 % zero_r_count

for i in range(1,N+1):
    if sX[i-1] == '1':
        if one_r_count != 0:
            Xi_n = one_mod - onepow[N-i]
            Xi_n %= one_r_count
            print(f[Xi_n]+1)
        else:
            print(0)
    if sX[i-1] == '0':
        Xi_n = zero_mod + zeropow[N-i]
        Xi_n %= zero_r_count
        print(f[Xi_n]+1)
### BUGGY CODE ###

from sys import stdin, stdout
 
ii = lambda: int(stdin.readline())
mi = lambda: map(int, stdin.readline().strip().split())
li = lambda: list(mi())

mod = int(1e9) + 7

def GCD(x, y): 
  
   while(y): 
       x, y = y, x % y 
  
   return x 

N = ii()
A = li()
lcm = A[0]
for i in range(1, len(A)):
	lcm = (lcm // GCD(lcm, A[i])) * A[i]

ans = 0
for i in range(0, len(A)):
	ans = (ans + (lcm // A[i])) % mod

print(ans)

### FIXED CODE ###

from sys import stdin, stdout
 
ii = lambda: int(stdin.readline())
mi = lambda: map(int, stdin.readline().strip().split())
li = lambda: list(mi())

mod = int(1e9) + 7

def GCD(x, y): 
   while(y): 
       x, y = y, x % y 
   return x 

N = ii()
A = li()
lcm = A[0]
for i in range(1, len(A)):
	lcm = (lcm // GCD(lcm, A[i])) * A[i]

ans = 0
for i in range(0, len(A)):
	ans = (ans + (lcm // A[i]))

ans %= mod

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

s = int(input())
a, b = -1, -1
for i in range(1, int(s**.5)+1):
    if s % i == 0:
        a, b = i, s//i
print(0, 0, 0, a, b, 0)


### FIXED CODE ###

from math import ceil


S = int(raw_input())

x2 = y3 = int(ceil(S ** 0.5))

y2 = x2 * y3 - S 
x3 = 1

print 0, 0, x2, y2, x3, y3
### BUGGY CODE ###

n=int(input())
L_lst=sorted(list(map(int,input().split())))
i=n-2
j=n-1
cnt=0
while j>1:
    x_min=0
    x_max=i
    while x_max>x_min+1:
        x_mid=(x_max+x_min)//2
        if L_lst[x_mid]+L_lst[i]>L_lst[j]:
            x_max=x_mid
        else:
            x_min=x_mid
    if L_lst[x_min]+L_lst[i]>L_lst[j]:
        cnt+=i-x_min
    else:
        cnt+=max(i-x_min-1,0)
    i-=1
    if i==0 or (L_lst[j])//2 >= L_lst[i]:
        j-=1
        i=j-1
print(cnt)


### FIXED CODE ###

n=int(input())
L_lst=sorted(list(map(int,input().split())))
cnt=0
for j in range(n-1,1,-1):
    i=j-1
    x=0
    while x<i:
        if L_lst[i]+L_lst[x]>L_lst[j]:
            cnt+=i-x
            i-=1
        else:
            x+=1
print(cnt)
### BUGGY CODE ###

n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))
q=[a[0]]
c=1
for i in range(1,n):
    x=a[i]
    for j in range(c):
        if q[c-j-1] < x:
            q[c-j-1] =x
            break 
    else:
        q.insert(0,x)
        c+=1
print(c)

### FIXED CODE ###

import bisect
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))
q=[-1 for _ in range(n)]
for i in range(n):
    x=a[i]
    idx = bisect.bisect_left(q,x)
    q[idx-1]=x
print(n-bisect.bisect_right(q,-1))
### BUGGY CODE ###

import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
# from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

h,w=map(int,input().split())
a=[input() for i in range(h)]

cnt=0

itta=[[float('inf')]*w for i in range(h)]

d=deque()
aaa=d.append
for i in range(h):
    for j in range(w):
        if a[i][j]=="#":
            aaa([i,j])
            itta[i][j]=0

# print(d)
# print(itta)

while d:
    cnt+=1
    for l in range(len(d)):
        nh,nw=d.popleft()
        for i in range(4):
            d1,d2=direction[i]
            if 0<=nh+d1<h and 0<=nw+d2<w:
                if itta[nh+d1][nw+d2]==float('inf'):
                    itta[nh+d1][nw+d2]=cnt
                    aaa([nh+d1,nw+d2])
    # print(d)

# print(itta)
print(cnt-1)

### FIXED CODE ###

import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
# from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

h,w=map(int,input().split())
a=[input() for i in range(h)]

cnt=0

itta=[[10**9]*w for i in range(h)]

d=deque()
aaa=d.append
for i in range(h):
    for j in range(w):
        if a[i][j]=="#":
            aaa([i,j])
            itta[i][j]=0

# print(d)
# print(itta)

while d:
    cnt+=1
    for l in range(len(d)):
        nh,nw=d.popleft()
        for i in range(4):
            d1,d2=direction[i]
            if 0<=nh+d1<h and 0<=nw+d2<w:
                if itta[nh+d1][nw+d2]==10**9:
                    itta[nh+d1][nw+d2]=cnt
                    aaa([nh+d1,nw+d2])
    # print(d)

# print(itta)
print(cnt-1)
### BUGGY CODE ###

s = input()
 
ans = 0
s = s.replace("BC","D")
 
while "AD" in s:
    cnt = s.count("AD")
    s = s.replace("AD","DA",cnt)
    ans += cnt
    
print(ans)

### FIXED CODE ###

s = input()
 
ans = 0
s = s.replace("BC","D")
cnt_A = 0
 

for i in s:
    if i == "A":
        cnt_A += 1
    elif i == "D":
        ans += cnt_A
    else:
        cnt_A = 0

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

# -*- coding: utf-8 -*-
import sys
from collections import deque
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    P=tuple(map(int1,input().split()))
    d=[[0]*N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            d[i][j]=min(min(i,N-1-i),min(j,N-1-j))
    used=[[1]*N for _ in range(N)]
    dy,dx=[1,0,-1,0],[0,1,0,-1]
    ans=0
    for p in P:
        y,x=p//N,p%N
        ans+=d[y][x]
        used[y][x]=0
        que=deque([(y,x)])
        while que:
            y,x=que.popleft()
            for k in range(4):
                ny,nx=y+dy[k],x+dx[k]
                if used[y][x]==0:
                    if 0<=ny<N and 0<=nx<N and d[ny][nx]-d[y][x]>=1:
                        d[ny][nx]-=1
                        que.append((ny,nx))
                else:
                    if 0<=ny<N and 0<=nx<N and d[ny][nx]-d[y][x]>=2:
                        d[ny][nx]-=1
                        que.append((ny,nx))
    print(ans)

if __name__ == '__main__':
    main()


### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
from collections import deque
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

N=int(input())
M=N**2
P=tuple(map(int1,input().split()))
d=[0]*M
for i in range(N):
    for j in range(N):
        d[i*N+j]=min(min(i,N-1-i),min(j,N-1-j))
used=[1]*M
ans=0
que=[]
for p in P:
    ans+=d[p]
    used[p]=0
    que.append(p)
    while que:
        x=que.pop()
        for ddx in (-1,1,-N,N):
            nx=x+ddx
            if 0<=nx<M:
                if used[x]==0 and d[nx]-d[x]>=1:
                    d[nx]-=1
                    que.append(nx)
                elif used[x]==1 and d[nx]-d[x]>=2:
                    d[nx]-=1
                    que.append(nx)
print(ans)
### BUGGY CODE ###

n, x, y = map(int, input().split())
ans = [0] * (n-1)
for i in range(1, n+1):
    for j in range(1, n+1):
        if i < j:
            # iとjを固定、rangeでi<jを表現
            d = min(j-i, abs(x-i)+abs(j-y)+1, abs(y-i)+abs(x-j)+1)
            # 長さを示すところに+１
            ans[d-1] += 1
print(*ans, sep="\n")

### FIXED CODE ###

n, x, y = map(int, input().split())
ans = [0] * (n-1)
for i in range(1, n):
    for j in range(i+1, n+1):
        # iとjを固定、rangeでi<jを表現
        d = min(j-i, abs(x-i)+abs(j-y)+1, abs(y-i)+abs(x-j)+1)
        # 長さを示すところに+１
        ans[d-1] += 1
print(*ans, sep="\n")
### BUGGY CODE ###

N,K=map(int,input().split())
ans=0
a=int(2*N/K)
for i in range(1,a+1):
  if i*K%2==1:
    continue
  for j in range(1,a+1):
    if j*K%2==1:
      continue
    for l in range(1,a+1):
      if l*K%2==1:
        continue
      if ((i+j)*K//2)%K==((l+j)*K//2)%K==((i+l)*K//2)%K==0:
        ans+=1
print(ans)

### FIXED CODE ###

N,K=map(int,input().split())
ans=0
if K%2==1:
  print((N//K)**3)
else:
  ans=(N//K)**3
  k=K//2
  j=(N+k)//K
  print(j**3+ans)