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

# coding: utf-8
import sys
from collections import deque

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
P = lr()
dp = [[min(i, N-1-i)] * N for i in range(N)]
people = [[True] * N for i in range(N)]
for j in range(N):
    x = min(j, N-1-j)
    for i in range(N):
        dp[i][j] = min(dp[i][j], x)

answer = 0
for p in P:
    p -= 1
    i = p // N
    j = p % N
    answer += dp[i][j]
    dp[i][j] -= 1
    people[i][j] = False
    used = set()
    def bfs(sy, sx):
        que = deque([(sy, sx)])
        popleft = que.popleft; append = que.append
        while que:
            y, x = popleft()
            if (y, x) in used:
                continue
            used.add((y, x))
            cur = dp[y][x]
            if cur == -1 and not people[y][x]:
                people[y][x] = True
            for dy, dx in zip([0, 1, 0, -1], [1, 0, -1, 0]):
                ny = y + dy
                nx = x + dx
                if 0 <= ny < N and 0 <= nx < N:
                    if dp[ny][nx] > cur + 1:
                        dp[ny][nx] = cur + 1
                        if not people[ny][nx]:
                            dp[ny][nx] = cur
                        append((ny, nx))
                    elif dp[ny][nx] > cur and (not people[ny][nx]):
                        # 人がいない時
                        dp[ny][nx] = cur
                        append((ny, nx))
    bfs(i, j)

print(answer)


### FIXED CODE ###

# coding: utf-8
import sys
from collections import deque

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

def main():
    N = ir()
    P = lr()
    P = [((p-1)//N, (p-1)%N) for p in P]
    dp = [[min(i, N-1-i, j, N-1-j) for j in range(N)] for i in range(N)]
    people = [[True] * N for i in range(N)]

    answer = 0
    for i, j in P:
        answer += dp[i][j]
        people[i][j] = False
        que = deque([(i, j, dp[i][j])])
        popleft = que.popleft; append = que.append
        while que:
            y, x, cur = popleft()
            cur += people[y][x]
            if x > 0:
                if dp[y][x-1] > cur:
                    dp[y][x-1] = cur
                    append((y, x-1, cur))
            if x < N-1:
                if dp[y][x+1] > cur:
                    dp[y][x+1] = cur
                    append((y, x+1, cur))
            if y > 0:
                if dp[y-1][x] > cur:
                    dp[y-1][x] = cur
                    append((y-1, x, cur))
            if y < N-1:
                if dp[y+1][x] > cur:
                    dp[y+1][x] = cur
                    append((y+1, x, cur))

    print(answer)
    
if __name__ == "__main__":
    main()
### BUGGY CODE ###

# ABC127C - Prison
n, m = list(map(int, input().rstrip().split()))
lst = [list(map(int, input().rstrip().split())) for _ in range(m)]
gates = [{j for j in range(i[0], i[1] + 1)} for i in lst]
ans = gates[0]
for i in gates[1:]:
    ans = ans & i
print(len(ans))

### FIXED CODE ###

# ABC127C - Prison
n, m = list(map(int, input().rstrip().split()))
lst = [list(map(int, input().rstrip().split())) for _ in range(m)]
ans = 0
l, r = lst[0][0], lst[0][1]
for i in lst[1:]:
    l = max(l, i[0])
    r = min(r, i[1])
for i in range(1, n + 1):
    if l <= i <= r:
        ans += 1
print(ans)
### BUGGY CODE ###

L = input()
ans = 0
n = len(L)
count = 0
for i in range(len(L)):
    if i == 0:
        ans += (3**(n-1) + 2) % 1000000007
        count += 1
    else:
        if L[i] == "1":
            ans += ((3**(n-1)+1)%1000000007*(2**count%1000000007))
            count += 1
    n -= 1
print(ans%1000000007)


### FIXED CODE ###

L = input()
ans = 0
n = len(L)
def power_func(a,n,p):
  bi=str(format(n,"b"))
  res=1
  for i in range(len(bi)):
    res=(res*res) %p
    if bi[i]=="1":
      res=(res*a) %p
  return res

count = 0
for i in range(len(L)):
    if i == 0:
        ans += (power_func(3,n-1,1000000007) + 2)
        ans %= 1000000007
        count += 1
    else:
        if L[i] == "1":
            ans += (power_func(3,n-1,1000000007)+1)*(power_func(2,count,1000000007))
            ans %= 1000000007
            count += 1
    n -= 1
print(ans%1000000007)
### BUGGY CODE ###

S=input()
l=[0 for x in range(len(list(S)))]
for i in range(len(list(S))):
    p_i=i
    p_l=[]
    for j in range(10**100):
        if S[p_i]=="R":
            p_i+=1
            p_l.append(p_i)
        elif S[p_i]=="L":
            p_i-=1
            p_l.append(p_i)
        if j>len(list(S)) and j%2==1:
            if p_l[j]==p_l[j-2]:
                break
            else:
                continue
    l[p_i]+=1

print(*l)

### FIXED CODE ###

s=input()
s="L"+s+"R"
N=len(s)
a=[1]*N
for i in range(1,N-1):
    if s[i]=="R" and s[i+1]=="R":
        a[i+2]+=a[i]
        a[i]=0
for i in range(N-1,1,-1):
    if s[i]=="L" and s[i-1]=="L":
        a[i-2]+=a[i]
        a[i]=0
print(*a[1:-1])
### BUGGY CODE ###

a,n,m=list(map(int,input().split()))
count=0
for x in range(1,m+1):
    xl=[]
    for xi in str(x):
        xl.append(int(xi))
    y=sum(xl)
    if x==(y+a)**n:count+=1
print(count)


### FIXED CODE ###

a,n,m=list(map(int,input().split()))
count=0
check_list=[]
i=0
if a==0:i=1
while (i+a)**n<m:
    check_list.append((i+a)**n)
    i+=1
for x in check_list:
    xl=[int(i) for i in list(str(x))]
    y=sum(xl)
    if x==(y+a)**n:count+=1
print(count)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
n=int(input())
A = [0]*n
B = [int(input())-1 for i in range(n)]
C = [0]

def fun(k):
    if B[k] in C:
        print(-1)
        sys.exit()                      
    else:
        C.append(B[k])
        if B[k] == 1:
            return False                                                    
        else:
            return B[k]
ans = 0
cnt = 0
for i in range(n):
    cnt = fun(cnt)
    ans +=1
    if cnt ==False:
        print(ans)
        sys.exit() 


        

### FIXED CODE ###

import sys
input = sys.stdin.readline
n=int(input())

B = [int(input())-1 for i in range(n)]


def fun(k):
    if B[k] == 1:
     	return -5                                                    
    else:
        return B[k]
ans = 0
cnt = 0
for i in range(n+1):
    cnt = fun(cnt)
    ans +=1
    
    if cnt ==-5:
        print(ans)
        sys.exit() 
print(-1)
sys.exit()
### BUGGY CODE ###

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

order = ""
for i in range(len(A_lis)):
    order+=str(A_lis.index(i+1)+1)
    order+=" "
print(order)


### FIXED CODE ###

import numpy as np

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

order = np.argsort(A_lis)

ans = ""
for elem in order:
    ans+=str(elem+1)
    ans+=" "
print(ans)
### BUGGY CODE ###

from scipy.misc import comb


def solve(string):
    n, m, k = map(int, string.split())
    return str(n * m * ((n + 1) * (m + 1) * (n + m - 2) - n**2 - m**2 + 2) // 6 *
               comb(n * m - 2, k - 2, exact=True) % (10**9 + 7))


if __name__ == '__main__':
    print(solve(input()))


### FIXED CODE ###

mod = 10**9 + 7


def comb(n, k):
    x, y = 1, 1
    k = min(k, n - k)
    for i in range(k):
        x *= n - i
        x %= mod
        y *= i + 1
        y %= mod
    return x * pow(y, mod - 2, mod) % mod


def solve(string):
    n, m, k = map(int, string.split())
    base = n * m * ((n + 1) * (m + 1) * (n + m - 2) - n**2 - m**2 + 2) // 6 % mod
    return str(base * comb(n * m - 2, k - 2) % mod)


if __name__ == '__main__':
    print(solve(input()))
### BUGGY CODE ###

n, k = map(int, input().strip().split(" "))
h = list(map(int, input().split(" ")))

dp = [0] * n
dp[1] = abs(h[0]-h[1])

for i in range(2, n):
    dp[i] = min([abs(h[i]-h[j])+dp[j] for j in range(max(0, i-k), i)])

print(dp[n-1])

### FIXED CODE ###

n, k = map(int, input().strip().split(" "))
h = list(map(int, input().split(" ")))

dp = [0] * n
dp[1] = abs(h[0]-h[1])

for i in range(2, n):
    dp[i] = min([abs(h[i]-h[j])+dp[j] for j in range(max(0, i-k), i)])

print(dp[n-1])
### BUGGY CODE ###

N=int(input())
S=input()
order=list('RGB')
cnt=[[0,0,0] for _ in range(N)]
for i in range(N):
    cnt[i][order.index(S[i])]+=1
    if i!=0:
        for j in range(3):
            cnt[i][j]+=cnt[i-1][j]
ans=0
for j in range(1,N):
    for k in range(j+1,N):
        # print(j,k)
        if S[j]==S[k]:
            continue
        else:
            s=list(set(order)-set([S[j],S[k]]))[0]
            ans+=cnt[j-1][order.index(s)]
            # print('db',ans)
            i=2*j-k
            if i>=0 and S[i]==s:
                # print('!')
                ans-=1
print(ans)


### FIXED CODE ###

# D
N=int(input())
S=input()
order=list('RGB')
cnt=[[0,0,0] for _ in range(N)]
for i in range(N):
    cnt[i][order.index(S[i])]+=1
    if i!=0:
        for j in range(3):
            cnt[i][j]+=cnt[i-1][j]
ans=0
for j in range(1,N):
    for k in range(j+1,N):
        # print(j,k)
        if S[j]==S[k]:
            continue
        else:
            s=list(set(order)-set([S[j],S[k]]))[0]
            ans+=cnt[j-1][order.index(s)]
            # print('db',ans)
            i=2*j-k
            if i>=0 and S[i]==s:
                # print('!')
                ans-=1
print(ans)
### BUGGY CODE ###

n, m = (int(x) for x in input().split())
l = []
d = {}
ds = []
for _ in range(m):
    l.append([int(x) for x in input().split()])
for i in range(m):
    k = str(l[i][0])
    if k not in ds:
        d[k] = [l[i][1]]
        ds.append(k)
    else:
        d[k].append(l[i][1])
for key in ds:
    d[key].sort()
for li in l:
    print(str(li[0]).zfill(6) + str(d[str(li[0])].index(li[1]) + 1).zfill(6))

### FIXED CODE ###

import bisect as bis
n, m = map(int, input().split())
idx = lambda x: x-1
p, y = [], []
for _ in range(m):
    p_, y_ = map(int, input().split())
    p.append(p_)
    y.append(y_)
val = [[] for _ in range(n)]
for i, j in zip(p, y):
    val[idx(i)].append(j)
for i in range(n):
    val[i].sort()
for i in range(m):
    v = p[i]
    id = bis.bisect_right(val[idx(v)], y[i])
    print(str(v).zfill(6) + str(id).zfill(6))
### BUGGY CODE ###

# coding: utf-8
import sys
input = sys.stdin.readline

MOD = int(1e9 + 7)

def f(N, M, s, t):
    cums = [[0] * (M + 1) for _ in range(N + 1)]

    for i in range(N):
        cumsi = cums[i]
        cumsi1 = cums[i+1]
        for j in range(M):
            num = 0
            if s[i] == t[j]:
                num = cumsi[j] + 1
            cumsi1[j+1] = \
                (cumsi1[j] + cumsi[j+1] + MOD - cumsi[j] + num) % MOD
    return((cums[N][M] + 1) % MOD)

n, m = map(int, input().split())
s = list(map(int, input().split()))
t = list(map(int, input().split()))
print(f(n, m, s, t))


### FIXED CODE ###

# coding: utf-8
MOD = int(1e9 + 7)

def f(N, M, s, t):
    dp = [[0] * (M + 1) for _ in range(N + 1)]
    cums = [[0] * (M + 1) for _ in range(N + 1)]

    for i in range(1, N + 1):
        for j in range(1, M + 1):
            dp[i][j] = 0 if s[i-1] != t[j-1] else (cums[i-1][j-1] + 1) % MOD
            cums[i][j] = cums[i-1][j] + cums[i][j-1] - cums[i-1][j-1] + dp[i][j]
    return((cums[N][M] + 1) % MOD)

n, m = map(int, input().split())
s = list(map(int, input().split()))
t = list(map(int, input().split()))
print(f(n, m, s, t))
### BUGGY CODE ###

from collections import deque

def bfs():
    h,w=map(int,input().split())
    sy,sx=map(int,input().split())
    gy,gx=map(int,input().split())
    sy-=1;sx-=1;gy-=1;gx-=1
    s=[list(input()) for _ in range(h)]
    dict={".":10000000,"#":-1}
    s=[[dict[s[y][x]] for x in range(w)]for y in range(h)]
    s[sy][sx]=0
    que=deque([[sy,sx]])
    temp=[(1,0),(0,1),(-1,0),(0,-1),(2,2),(2,1),(2,0),(2,-1),(2,-2),(1,2),(1,1),(1,-1),(1,-2),(0,2),(0,-2),(-1,2),(-1,1),(-1,-1),(-1,-2),(-2,2),(-2,1),(-2,0),(-2,-1),(-2,-2)]
    while que:
        y,x=que.popleft()
        for i,j in temp:
            if 0<=y+i<h and 0<=x+j<w and s[y+i][x+j]>=0:
                nexty,nextx=y+i,x+j
                dist=s[nexty][nextx]
                if abs(i)+abs(j)<=1 and dist>s[y][x]:
                    s[nexty][nextx]=s[y][x]
                    que.append([nexty,nextx])
                elif dist>s[y][x]+1:
                    s[nexty][nextx]=s[y][x]+1
                    que.append([nexty,nextx])

    if s[gy][gx]==10000000:
        print(-1)
    else:
        print(s[gy][gx])

bfs()


### FIXED CODE ###

from collections import deque
from sys import stdin

def bfs():
    readline=stdin.readline
    h,w=map(int,readline().split())
    sy,sx=map(int,readline().split())
    gy,gx=map(int,readline().split())
    sy-=1;sx-=1;gy-=1;gx-=1
    s=[list(readline()) for _ in range(h)]
    dict={".":10000000,"#":-1}
    s=[[dict[s[y][x]] for x in range(w)]for y in range(h)]
    s[sy][sx]=0
    que=deque([[sy,sx]])
    temp=[i for i in range(-2,3)]
    while que:
        y,x=que.popleft()
        s1=s[y][x]
        for i in temp:
            nexty=y+i
            if 0<=nexty<h:
                s2=s[nexty]
                for j in temp:
                    nextx=x+j
                    if 0<=nextx<w and s2[nextx]>=0:
                        dist=s2[nextx]
                        if i*i+j*j<=1 and dist>s1:
                            s[nexty][nextx]=s1
                            que.appendleft([nexty,nextx])
                        elif dist>s1+1:
                            s[nexty][nextx]=s1+1
                            que.append([nexty,nextx])

    if s[gy][gx]==10000000:
        print(-1)
    else:
        print(s[gy][gx])
bfs()
### BUGGY CODE ###

n = int(input())

alist = input().split(" ")

for i in range(1,n+1):
    sum = 0
    for j in range(n-1):
        if int(alist[j]) == i:
            sum = sum + 1
    print(sum)


### FIXED CODE ###

n = int(input())

alist = input().split(" ")

aint = []

sumlist = []

for i in range(n-1):
    aint.append(int(alist[i]))

for i in range(n):
    sumlist.append(0)

for i in aint:
    sumlist[i-1] = sumlist[i-1]+1

for i in sumlist:
    print(i)
### BUGGY CODE ###

S = input()[::-1]
keta = len(S)
mod = 10 ** 9 + 7

dp = [[0 for _ in range(13)] for _ in range(keta + 1)]
dp[0][0] = 1
tmp = 1
for i in range(1, keta + 1):
    if S[i - 1] != "?":
        x = int(S[i - 1]) * (tmp) % 13
        for j in range(13):
            dp[i][(x + j) % 13] += dp[i - 1][j] % mod
    else:
        for k in range(10):
            x = k * (tmp) % 13
            for j in range(13):
                dp[i][(x + j) % 13] += dp[i - 1][j] % mod
    tmp *= 10

print(dp[keta][5] % mod)

### FIXED CODE ###

S = input()[:: -1]
mod = 10 ** 9 + 7
dp = [[0 for _ in range(13)] for _ in range(len(S) + 1)]

if S[0] == "?":
    for k in range(10):
        dp[1][k % 13] += 1
else:
    dp[1][int(S[0]) % 13] += 1

tmp = 1
for i in range(2, len(S) + 1):
    tmp *= 10
    tmp %= 13
    for j in range(13):
        if dp[i - 1][j] > 0:
            if S[i - 1] == "?":
                for k in range(10):
                    dp[i][(tmp * k + j) % 13] += dp[i - 1][j] % mod
            else:
                dp[i][(tmp * int(S[i - 1]) + j) % 13] += dp[i - 1][j] % mod

print(dp[len(S)][5] % mod)
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
B=set(A)
for i in range(1,N+1):
  if i not in B:
    print(0)
  else:
    print(A.count(i))


### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
B=[0]*(N+1)
for i in A:
  B[i]+=1
for j in range(1,N+1):
  print(B[j])
### BUGGY CODE ###

n = int(input())
s = input()
ans = 0
for i in range(n):
    for j in range(i+1,n):
        if s[i] == s[j]:continue
        for k in range(j+1,n):
            if j-i != k-j and s[i] != s[k] and s[j] != s[k]:
                ans += 1 
print(ans)

### FIXED CODE ###

n=int(input())
s=input()

r = 0
r_l = []
g = 0
g_l = []
b = 0
b_l = []

for i in range(n):
    if s[i] == "R":
        r += 1
        r_l.append(i)
    if s[i] == "G":
        g += 1
        g_l.append(i)
    if s[i] == "B":
        b += 1
        b_l.append(i)
        
ans = r*g*b

for i in r_l:
    for j in g_l:
        tmp = abs(i-j)
        if 0 <= i-tmp and s[i-tmp] == "B":
            ans -= 1
        if 0 <= j-tmp and s[j-tmp] == "B":
            ans -= 1
        if i+tmp < n and s[i+tmp] == "B":
            ans -= 1
        if j+tmp < n and s[j+tmp] == "B":
            ans -= 1

        if (tmp / 2).is_integer():
            if s[max(i,j)-(tmp//2)] == "B":
                ans -= 1
            if max(i,j)-(tmp//2) != min(i,j)+(tmp//2) and s[min(i,j)+(tmp//2)] == "B":
                ans -= 1

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

n,k=map(int,input().split())
ans=0
for i in range(1,n+1):
  cnt=0
  tmp=0
  while i*tmp < k:
    tmp*=2
    cnt+=1
  ans+=(1/3)*((1/2)**cnt)
  
print(ans)

### FIXED CODE ###

n,k=map(int,input().split())
ans=0
for i in range(1,n+1):
  cnt=0
  tmp=1
  while i*tmp < k:
    tmp*=2
    cnt+=1
  ans+=(1/n)*((1/2)**cnt)
  
print(ans)
### BUGGY CODE ###

X,Y,Z,K = map(int,input().split())
A = [i for i in map(int,input().split())]
B = [i for i in map(int,input().split())]
C = [i for i in map(int,input().split())]
AB = []
for a in A:
    for b in B:
        AB.append(a+b)
AB.sort(reverse=True)
ABC = []
for i in range(min(K,len(AB))):
    for c in C:
        ABC.append(AB[i]+c)
ABC.sort(reverse=True)
for i in range(K):
    print(ABC[i])

### FIXED CODE ###

X,Y,Z,K = map(int,input().split())
A = [i for i in map(int,input().split())]
B = [i for i in map(int,input().split())]
C = [i for i in map(int,input().split())]
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
ABC = []
for i in range(X):
    for j in range(Y):
        if (i+1) * (j+1) > K:
            break
        for k in range(Z):
            if (i+1) * (j+1) * (k+1) > K:
                break
            ABC.append(A[i] +  B[j] + C[k])
ABC.sort(reverse=True)
for i in range(K):
    print(ABC[i])
### BUGGY CODE ###

n = int(input())
arr = [int(x) for x in input().split(' ')]
ans = 1
for i in arr:
    ans = ans * i
print(-1 if(ans > (10**18)) else ans)


### FIXED CODE ###

n = int(input())
arr = sorted([int(x) for x in input().split(' ')])
ans = 1
for i in arr:
    ans = ans * i
    if(ans > (10**18) or ans == 0):
        break
print(-1 if(ans > (10**18)) else ans)
### BUGGY CODE ###

from queue import LifoQueue

'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''

N = int(input())
A =  [[0 for i in range(N)] for j in range(N)]
q = LifoQueue()
#b = [-1 for i in range(N)]
c = [0 for i in range(N)]
l = [0 for i in range(N)]

for i in range(N-1):
	u, v, w = map(int,input().split())
	A[u-1][v-1] = w
	A[v-1][u-1] = w

q.put(0)
while not q.empty():
	i = q.get()
	c[i] = 1
	for j in range(N):
		if A[i][j] > 0 and c[j] == 0:
			q.put(j)
			#b[j] = i
			l[j] = l[i] + A[i][j]

for i in l:
	print('{}'.format(i%2))


### FIXED CODE ###

N = int(input())
q = []
c = [0 for i in range(N)]
l = [0 for i in range(N)]
A = [[] for i in range(N)]
W = [[] for i in range(N)]

for i in range(N-1):
	u, v, w = map(int,input().split())
	u = u - 1
	v = v - 1
	
	A[u].append(v)
	A[v].append(u)
	W[u].append(w)
	W[v].append(w)

q.append(0)
while len(q):
	i = q.pop(0)
	c[i] = 1
	k = 0
	for j in A[i]:
		if c[j] == 0:
			q.append(j)
			l[j] = l[i] + W[i][k]
		k = k + 1

for i in l:
	print('{}'.format(i%2))
### BUGGY CODE ###

h,w,K = map(int,input().split())
sij = [input() for j in range(h)]

num = 2**(h-1)
hon = 10**18

for i in range(num):
    tmp = format(i,'0'+str(h)+'b')
    #print(tmp,tmp,tmp,tmp)
    yoko_hon = sum(list(map(int,tmp)))+1
    blk = [0]*(yoko_hon)
    #blk_num = 0
    tmp_col = 0
    tmp_hon = yoko_hon-1
    flag = True
    ok_flag = True
    for j in range(w):
        tmp_blk = [0]*(yoko_hon)
        blk_num = 0
        for k in range(h):
            if tmp[k] == str(1):
                blk_num += 1
            #print(blk_num,tmp_blk)
            tmp_blk[blk_num] += int(sij[k][j])
            #print(blk[blk_num] , tmp_blk[blk_num],k)
            if blk[blk_num] + tmp_blk[blk_num] > K:
                flag = False
                continue
        
        #print(ok_flag,flag,tmp_blk,blk)
        if flag == False:
            for l in range(yoko_hon):
                if tmp_blk[l] > K:
                    ok_flag = False
                    break
                blk[l] = tmp_blk[l]
            tmp_hon += 1
            tmp_col = 0
            flag = True
        else:
            for l in range(yoko_hon):
                blk[l] += tmp_blk[l]
                tmp_col += 1
        if ok_flag == False:
            break
            
    #print(ok_flag)
    if ok_flag == False:
        ok_flag = True
        continue
    #exit()
    hon = min(tmp_hon,hon)
    
print(hon)

### FIXED CODE ###

h,w,K = map(int,input().split())
sij = [input() for j in range(h)]

num = 2**(h-1)
hon = 10**18

for i in range(num):
    tmp = format(i,'0'+str(h)+'b')
    #print(tmp,tmp,tmp,tmp)
    yoko_hon = sum(list(map(int,tmp)))+1
    blk = [0]*(yoko_hon)
    #blk_num = 0
    tmp_col = 0
    tmp_hon = yoko_hon-1
    flag = True
    ok_flag = True
    for j in range(w):
        tmp_blk = [0]*(yoko_hon)
        blk_num = 0
        for k in range(h):
            if tmp[k] == str(1):
                blk_num += 1
            #print(blk_num,tmp_blk)
            tmp_blk[blk_num] += int(sij[k][j])
            #print(blk[blk_num] , tmp_blk[blk_num],k)
            if blk[blk_num] + tmp_blk[blk_num] > K:
                flag = False
                continue
        
        #print(ok_flag,flag,tmp_blk,blk)
        if flag == False:
            for l in range(yoko_hon):
                if tmp_blk[l] > K:
                    ok_flag = False
                    break
                blk[l] = tmp_blk[l]
            tmp_hon += 1
            tmp_col = 0
            flag = True
        else:
            for l in range(yoko_hon):
                blk[l] += tmp_blk[l]
                tmp_col += 1
        if ok_flag == False:
            break
            
    #print(ok_flag)
    if ok_flag == False:
        ok_flag = True
        continue
    #exit()
    hon = min(tmp_hon,hon)
    
print(hon)
### BUGGY CODE ###

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

def gcd(m, n) :
    while n :
        m, n = n, m % n
    return m

ret = 0
x = gcd(A, B)
if x % 2 == 0 :
    ret += 1
    while x % 2 == 0 :
        x //= 2
        
i = 3
while x != 1 :
    if x % i == 0 :
        ret += 1
        x //= i
        
    while x % i == 0 :
        x //= i
        
    i += 2
        
print(ret + 1)


### FIXED CODE ###

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

def gcd(m, n) :
    while n :
        m, n = n, m % n
    return m

ret = 0
x = gcd(A, B)
if x % 2 == 0 :
    ret += 1
    while x % 2 == 0 :
        x //= 2
        
i = 3
while i * i <= x :
    if x % i == 0 :
        ret += 1
        x //= i
        
    while x % i == 0 :
        x //= i
        
    i += 2

if x != 1 :
    ret += 1
print(ret + 1)
### BUGGY CODE ###

#C_Snuke Festival
import itertools

def SnukeFestival(N, A, B, C):
    combination = [(a,b,c) for (a,b,c) in itertools.product(A,B,C) if a < b and b < c]
    print(len(combination))

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    SnukeFestival(N, A, B, C)

### FIXED CODE ###

#C_Snuke Festival
import bisect

def SnukeFestival(N, A, B, C):
    A = sorted(A)
    B = sorted(B)
    C = sorted(C)
    count = 0

    for b in B:
        n_a = bisect.bisect_left(A,b)
        n_c = bisect.bisect_right(C,b)
        count += n_a * (N - n_c)

    print(count)

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    SnukeFestival(N, A, B, C)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split(' ')))
for i in range(n):
    rd = a[0: i] + a[i + 1:]
    co = 0
    for j in range(n - 2):
        co += rd[j + 1:].count(rd[j])
    print(co)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split(' ')))
c = [0] * (n + 1)
d = [0] * (n + 1)
for i in a:
    c[i] += 1
    d[i] = c[i] * (c[i] - 1) // 2
t = sum(d)
for i in a:
    if c[i] > 2:
        r = (((c[i] - 1) * (c[i] - 2)) // 2)
    else:
        r = 0
    print(t - d[i] + r)