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

import sys
input = sys.stdin.readline

n = int(input())
a = []
for i in range(n):
    a.append(list(map(int, input().split())) + [-1])
flags = [False for i in range(n)]
nums = [0 for i in range(n)]
day = 0
flag = True
while False in flags:
    if flag == False:
        break
    match = set()
    for i in range(n):
        if nums[i] == n - 1:
            continue
        num = a[i][nums[i]] - 1
        if nums[num] == n - 1:
            flag = False
            break
        if a[num][nums[num]] - 1 == i:
            if i not in match and num not in match:
                match.add(i)
                match.add(num)
                nums[i] += 1
                nums[num] += 1
                if nums[i] == n - 1:
                    flags[i] = True
                if nums[num] == n - 1:
                    flags[num] = True
    if not match:
        flag = False
        break
    day += 1
if flag == True:
    print(day)
else:
    print(-1)

### FIXED CODE ###

import sys, collections
input = sys.stdin.readline

n = int(input())
a = []
for i in range(n):
    a.append(list(map(int, input().split())))
nums = [0 for i in range(n)]
day = 0
match = 0
flag = True
queue = collections.deque([])
temp = set()
for i in range(1, n + 1):
    i2 = a[i - 1][0]
    if a[i2 - 1][0] == i:
        if i not in temp:
            queue.append([i, i2])
            temp.add(i)
            temp.add(i2)
if not queue:
    flag = False
while queue:
    temp = []
    while queue:
        test = queue.popleft()
        match += 1
        num1, num2 = test[0], test[1]
        nums[num1 - 1] += 1
        nums[num2 - 1] += 1
        temp.append(num1)
        temp.append(num2)
    flag2 = False
    temp2 = set()
    for i in temp:
        if nums[i - 1] <= n - 2:
            new_num = a[i - 1][nums[i - 1]]
            if nums[new_num - 1] <= n - 2 and a[new_num - 1][nums[new_num - 1]] == i:
                if i not in temp2:
                    queue.append([i, new_num])
                    flag2 = True
                    temp2.add(i)
                    temp2.add(new_num)
    if flag2 == False and match < n * (n - 1) // 2:
        flag = False
        break
    day += 1

if flag == True:
    print(day)
else:
    print(-1)
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))

ans = 1
for num in a:
  if num == 0:
    ans = 0
    break
  ans = ans * num

if ans > 1000000000000000000:
  ans = -1

print(ans)


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))

if (0 in a):
  print(0)
else:
  ans = 1
  for num in a:
    ans *= num
    if ans > 1000000000000000000:
      print(-1)
      exit()
  print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.buffer.readline

def main():
    R, C, K = map(int, input().split())
    State = [[0]*R for _ in range(C)]
    for _ in range(K):
        r, c, v = map(int, input().split())
        State[c-1][r-1] += v

    dp = [[0]*4 for _ in range((C+1)*(R+1))]

    for r in range(R):
        for c in range(C):
            for n in range(4):
                if dp[(c+1)*(R+1)+r][n] > dp[(c+1)*(R+1)+r+1][0]:
                    dp[(c+1)*(R+1)+r+1][0] = dp[(c+1)*(R+1)+r][n]
                if dp[(c+1)*(R+1)+r][n] + State[c][r] > dp[(c+1)*(R+1)+r+1][1]:
                    dp[(c+1)*(R+1)+r+1][1] = dp[(c+1)*(R+1)+r][n] + State[c][r]
                if dp[c*(R+1)+r+1][n] > dp[(c+1)*(R+1)+r+1][n]:
                    dp[(c+1)*(R+1)+r+1][n] = dp[c*(R+1)+r+1][n]
                if n < 3 and dp[c*(R+1)+r+1][n] + State[c][r] > dp[(c+1)*(R+1)+r+1][n+1]:
                    dp[(c+1)*(R+1)+r+1][n+1] = dp[c*(R+1)+r+1][n] + State[c][r]
        
    print(max(dp[C*(R+1)+R]))

if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline

def main():
    R, C, K = map(int, input().split())
    State = [[0]*R for _ in range(C)]
    for _ in range(K):
        r, c, v = map(int, input().split())
        State[c-1][r-1] += v

    dp = [[0]*4 for _ in range(C+1)]

    for r in range(R):
        ndp = [[0]*4 for _ in range(C+1)]
        for c in range(C):
            ndp[c+1][0] = max(ndp[c+1][0], max(dp[c+1]))
            ndp[c+1][1] = ndp[c+1][0] + State[c][r]
            for n in range(4):
                if ndp[c][n] > ndp[c+1][n]:
                    ndp[c+1][n] = ndp[c][n]
                if n < 3 and ndp[c][n] + State[c][r] > ndp[c+1][n+1]:
                    ndp[c+1][n+1] = ndp[c][n] + State[c][r]
        dp = ndp
        
    print(max(dp[C]))

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

"""
dp[i][j][k] => i行目、j列のマスまで見る。k個取る時の最高値。
"""
def main():
    import sys
    input = sys.stdin.readline
    R,C,K = map(int,input().split())
    items = [[0]*C for _ in range(R)]
    for _ in range(K):
        r,c,v = map(int,input().split())
        items[r-1][c-1] = v

    dp = [[[0]*4 for _ in range(C)]for _ in range(R)]

    for i in range(R):
        for j in range(C):
            v = items[i][j]
            if i == 0 and j == 0 and v != 0:
                dp[i][j][1] = v

            #上から降りてくる場合の価値を求める
            if i != 0:
                #i行目j列のアイテムを取らない場合
                dp[i][j][0] = max(dp[i-1][j])
                #i行目j列のアイテムを取る場合
                if v!=0:
                    dp[i][j][1] = max(dp[i-1][j]) + v

            #左から入ってくる場合の価値を求める
            if j != 0:
                if v == 0:
                    for k in range(4):
                        dp[i][j][k] = max(dp[i][j][k],dp[i][j-1][k])
                else:
                    for k in range(1,4):
                        dp[i][j][k] = max(dp[i][j][k],dp[i][j-1][k],dp[i][j-1][k-1]+v)
        if i > 0:
            tmp = dp[i-1]
            dp[i-1] = []
            del(tmp)
    print(max(dp[-1][-1]))
main()

### FIXED CODE ###

"""
dp[i][j]　=> i行目j列目がゴールの場合の最大値
"""
def main():
    import sys
    input = sys.stdin.readline
    R,C,K = map(int,input().split())
    items = [[0]*(C) for _ in range(R)]

    for _ in range(K):
        r,c,v = map(int,input().split())
        items[r-1][c-1] = v

    dp = [[0]*4 for _ in range(C)]
    dp[0][1] = items[0][0]
    for i in range(R):
        for j in range(C):
            v = items[i][j]
            if i==0 and j == 0:
                continue

            if i!=0:
                #上から入る場合のシミュレート
                dp[j][0] = max(dp[j])
                if v:
                    dp[j][1] = dp[j][0]+v

            if j!=0:
                #左から入る場合のシミュレート
                dp[j][0] = max(dp[j][0],dp[j-1][0])
                if v:
                    #itemが存在する場合の処理
                    for k in range(1,4):
                        dp[j][k] = max(dp[j][k],dp[j-1][k-1]+v,dp[j-1][k])
                else:
                    for k in range(1,4):
                        dp[j][k] = max(dp[j][k],dp[j-1][k])
    print(max(dp[-1]))
main()
### BUGGY CODE ###

n = int(input())
a = 1
for i in map(int, input().split()):
  a *= i

print(-1 if a > 10**18 else a)


### FIXED CODE ###

n = int(input())
ans = 1
a = sorted(map(int, input().split()))
for i in a:
  ans *= i
  if ans > 10**18:
    print(-1)
    break
else:
  print(ans)
### BUGGY CODE ###

import fractions
a,b = map(int,input().split())
ans = 1
now = fractions.gcd(a,b)
for num in range(2,fractions.gcd(a,b)+1):
  if num > now:
    break
  if now % num == 0:
    ans += 1
    while now % num == 0:
      now //= num
print(ans)

### FIXED CODE ###

import fractions
a,b = map(int,input().split())
c = fractions.gcd(a,b)

ans = [1]
while c % 2 == 0:
  ans.append(2)
  c //= 2
i = 3
while c >= i ** 2:
  if c % i == 0:
    ans.append(i)
    c //= i
  else:
    i += 2
if c != 1:
  ans.append(c)
print(len(set(ans)))
### BUGGY CODE ###

n = int(input())
A = list(map(int,input().split()))
A.reverse()
ans = []
left = True
while A:
    if left: ans = [A.pop()] + ans
    else: ans.append(A.pop())
    left = not left
if n % 2 == 0: ans.reverse()
print(' '.join(str(a) for a in ans))

### FIXED CODE ###

from collections import deque
n = int(input())
A = list(map(int,input().split()))
A.reverse()

left = True
ans = deque()
while A:
    if left: ans.appendleft(A.pop())
    else: ans.append(A.pop())
    left = not left
if n % 2 == 0: ans.reverse()
print(' '.join(str(a) for a in ans))
### BUGGY CODE ###

h = int(input())
temp = 1
cnt = 0
while(True):
  h = h // 2
  cnt += 1
  if(h == 1):
    break
ans = 1
for i in range(cnt-1):
  temp *= 2
  ans +=temp
  #print(ans)
print(ans + 2**cnt)	
  

### FIXED CODE ###

h = int(input())
if(h == 1):
  print(1)
  exit()
cnt = 1
point = 0
list = [0 for i in range(100)]
while (h>point+1):
  list[cnt] = ((list[cnt-1] * 2) +1)
  point += 2**cnt
  cnt += 1

print(list[cnt-1]*2+1)
### BUGGY CODE ###

N = int(input())
A = [int(input()) for _ in range(N)]

for i in range(N):
    A_copy = A[:]
    removed_A = A_copy.pop(i)
    print(max(A_copy))


### FIXED CODE ###

#ABC-134-C
N = int(input())
A = {}
for i in range(N):
    A[i] = int(input())

value_sorted = sorted(A.items(), key=lambda x:x[1])
max_value = 0

for i in range(N):
    max_value_tapple = value_sorted[-1]
    if max_value_tapple[0] == i:
        max_value_tapple = value_sorted[-2]
        max_value = max_value_tapple[1]
    else:
        max_value = max_value_tapple[1]
    print(max_value)
### BUGGY CODE ###

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

for _ in range(m):
    b,c = map(int, input().split())
    for _ in range(b):
        a.append(c)
        a.sort(reverse=True)
    a = a[:n]
    
print(sum(a))

### FIXED CODE ###

n,m = map(int, input().split())
a = sorted(list(map(int,input().split())))
bc = [list(map(int, input().split())) for _ in range(m)]
bc.sort(key=lambda x: x[1], reverse=True )
count = 0
for b,c in bc:
    for _ in range(b):
        if count == n or a[count] >= c:
            break

        a[count] = c
        count += 1

print(sum(a))
### BUGGY CODE ###

N,M=map(int,input().split())
cakes=[None]*N
for i in range(N):
  x,y,z=map(int,input().split())
  cakes[i]=[x,y,z]
  
# x,y,zをそれぞれマイナスに伸ばすかプラスに伸ばすか、2*3通りをすべて試す。
ans=0
for i in range(2**3):
  plus_or_minus=[False]*3
  for j in range(3):
    if i>>j&1:
      plus_or_minus[j]=1
    else:
      plus_or_minus[j]=-1
  
  # 買った個数に対して、プラスマイナスへの伸びが最も大きい買い方を保持
  dp=[[0 for i in range(3)] for j in range(M+1)]
  dp[0]=[0,0,0]
  
  for c in range(len(cakes)):
    for j in range(c+1,-1,-1):
      if j<len(dp)-1:
        diff=0
        for k in range(3):
          diff+=((dp[j][k]+cakes[c][k])*plus_or_minus[k])-(dp[j+1][k]*plus_or_minus[k])
        if diff>0:
          dp[j+1][0]=dp[j][0]+cakes[c][0]
          dp[j+1][1]=dp[j][1]+cakes[c][1]
          dp[j+1][2]=dp[j][2]+cakes[c][2]
  if abs(dp[-1][0])+abs(dp[-1][1])+abs(dp[-1][2])>ans:
    ans=abs(dp[-1][0])+abs(dp[-1][1])+abs(dp[-1][2])

print(ans)

### FIXED CODE ###

N,M=map(int,input().split())
cakes=[None]*N
for i in range(N):
  x,y,z=map(int,input().split())
  cakes[i]=[x,y,z]
  
# x,y,zをそれぞれマイナスに伸ばすかプラスに伸ばすか、2*3通りをすべて試す。
ans=0
for i in range(2**3):
  plus_or_minus=[1]*3
  for j in range(3):
    if (i>>j)&1:
      plus_or_minus[j]=1
    else:
      plus_or_minus[j]=-1
  # 買った個数に対して、プラスマイナスへの伸びが最も大きい買い方を保持
  dp=[None for j in range(M+1)]
  dp[0]=[0,0,0]
  
  for c in range(len(cakes)):
    for j in range(c+1,-1,-1):
      if j<len(dp)-1 and dp[j]!=None:
        if dp[j+1]==None:
          dp[j+1]=[None]*3
          dp[j+1][0]=dp[j][0]+cakes[c][0]
          dp[j+1][1]=dp[j][1]+cakes[c][1]
          dp[j+1][2]=dp[j][2]+cakes[c][2]
        else:
          diff=0
          for k in range(3):
            diff+=((dp[j][k]+cakes[c][k])*plus_or_minus[k])-(dp[j+1][k]*plus_or_minus[k])
          if diff>0:
            dp[j+1][0]=dp[j][0]+cakes[c][0]
            dp[j+1][1]=dp[j][1]+cakes[c][1]
            dp[j+1][2]=dp[j][2]+cakes[c][2]
  if abs(dp[-1][0])+abs(dp[-1][1])+abs(dp[-1][2])>ans:
    ans=abs(dp[-1][0])+abs(dp[-1][1])+abs(dp[-1][2])

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


# グラフ問題での分析が全然できなかった（初体験）
# 次回は頑張って解く！

N, u, v = map(int, input().split())
edges = [[] for i in range(N+1)]

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

def dfs(u):
  colors = ["white"] * (N+1)
  d = [None] * (N + 1)
  d[u] = 0
  stack = [u]

  while stack:
    u = stack.pop()
    colors[u] = "black"

    for e in edges[u]:
      if colors[e] != "black":
        d[e] = d[u] + 1
        stack.append(e)

  return d

u_dist = dfs(u)
v_dist = dfs(v)

ans = 0
for uu in u_dist:
  if uu == None: continue
  for vv in v_dist:
    if vv == None: continue
    if uu < vv:
      ans = max(ans, vv - 1)

print(ans)

### FIXED CODE ###


# グラフ問題での分析が全然できなかった（初体験）
# 次回は頑張って解く！
# 解説動画をみることがMUST、基本そのまま書いている。

from heapq import heappop, heappush
N, u, v = map(int, input().split())
edges = [[] for i in range(N+1)]

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

def dfs(u):
  colors = ["white"] * (N+1)
  d = [9999999999999999] * (N + 1)
  d[u] = 0
  stack = [u]

  while stack:
    u = stack.pop()
    colors[u] = "black"

    for e in edges[u]:
      if colors[e] != "black":
        d[e] = d[u] + 1
        stack.append(e)

  return d

u_dist = dfs(u)
v_dist = dfs(v)

ans = 0
for i in range(N+1):
  if u_dist[i] < v_dist[i]:
    ans = max(ans, v_dist[i] - 1)

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

import copy

h,w = map(int,input().split())
#a = [input() for _ in range(h)]
a = [list(input()) for _ in range(h)]
#b = [[False]*w for _ in range(h)]
c = []
d = [(-1,0), (1,0), (0,-1), (0,1)]
ans = 0

"""
for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            b[i][j] = True
            c.append((i,j))
"""

for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            c.append((i,j))

while True:
    tmp = []
    cnt = 0
    for i,j in c:
        for d1,d2 in d:
            if 0 <= i + d1 < h and 0 <= j + d2 < w:
                #if not b[i+d1][j+d2]:
                if a[i+d1][j+d2] == '.':
                    tmp.append((i+d1, j+d2))
                    #b[i+d1][j+d2] = True
                    a[i+d1][j+d2] = '#'
                    cnt += 1
    if cnt > 0:
        c = copy.deepcopy(tmp)
        ans += 1
    else:
        break

print(ans)


### FIXED CODE ###

import copy
#import time

h,w = map(int,input().split())
a = [input() for _ in range(h)]
b = [[False]*w for _ in range(h)]
#s = time.time()
c = []
d = [(-1,0), (1,0), (0,-1), (0,1)]
ans = 0

for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            b[i][j] = True
            c.append((i,j))
#print(time.time()-s)

while True:
    tmp = []
    cnt = 0
    for i,j in c:
        for d1,d2 in d:
            if 0 <= i + d1 < h and 0 <= j + d2 < w:
                if not b[i+d1][j+d2]:
                    tmp.append((i+d1, j+d2))
                    b[i+d1][j+d2] = True
                    cnt += 1
    #print(time.time()-s)
    if cnt > 0:
        c = copy.copy(tmp)
        ans += 1
    else:
        break
    #print(time.time()-s)

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

N, M= map(int, input().split())
a =[str(input()) for _ in range(M)]
DP = [0]*(N+2)
num = 1000000007
DP[0] = 1
for i in range(N):
  if str(i) in a:
    DP[i] = 0
  else:
    DP[i] = DP[i] % num 
    if i < N:
      DP[i+1] += DP[i]
      DP[i+2] += DP[i]
print(DP[-2]%num)


### FIXED CODE ###

N, M, = map(int, input().split())
a = set([int(input()) for _ in range(M)])
DP = [0]*(N+2)
num = 1000000007
DP[0] = 1
for i in range(N):
  if i in a:
    DP[i] = 0
  else:
    DP[i] = DP[i] % num 
    if i < N:
      DP[i+1] += DP[i]
      DP[i+2] += DP[i]
print(DP[-2]%num)
### BUGGY CODE ###

N=int(input())
L=list(map(int,input().split()))
counter=0
L.sort()
for i in range(len(L)):
    for j in range(i+1,len(L)):
        for k in range(j+1,len(L)):
            if L[i]>abs(L[j]-L[k]):
                counter+=1
            else:
                break
print(counter)
    

### FIXED CODE ###


N=int(input())
L=list(map(int,input().split()))
counter=0
L.sort()
for i in range(N-2):
    k=i+2
    for j in range(i+1,N-1):    
        while k < N and L[k] < L[i] + L[j]:
            k += 1
        counter += k - j -1
print(counter)
### BUGGY CODE ###

# フェルマーの小定理
K = int(input())
S = input()

m = 1000000007

result = 0
a = 1
b = 1

for i in range(K + 1):
    # result += pow(26, K - i, m) * mcomb(len(S) - 1 + i, i) * pow(25, i, m)
    result += pow(26, K - i, m) * (a * pow(b, m - 2, m)) * pow(25, i, m)
    result %= m
    a *= len(S) - 1 + (i + 1)
    a %= m
    b *= i + 1
    b %= m
print(result)


### FIXED CODE ###

# フェルマーの小定理
K = int(input())
S = input()

m = 1000000007


def make_factorial_table(n):
    result = [0] * (n + 1)
    result[0] = 1
    for i in range(1, n + 1):
        result[i] = result[i - 1] * i % m
    return result


def mcomb(n, k):
    if n == 0 and k == 0:
        return 1
    if n < k or k < 0:
        return 0
    return fac[n] * pow(fac[n - k], m - 2, m) * pow(fac[k], m - 2, m) % m


fac = make_factorial_table(len(S) + K)

result = 0
for i in range(K + 1):
    result += pow(26, i, m) * mcomb(len(S) - 1 + K - i, len(S) - 1) * pow(25, K - i, m)
    result %= m
print(result)
### BUGGY CODE ###

import copy
n=int(input())
a=[0]*n
for i in range(0,n):
  a[i]=int(input())
temp=copy.copy(a)
for i in range(0,n):
  temp[i]=0
  print(max(temp))
  temp=copy.copy(a)
        

### FIXED CODE ###

n=int(input())
a=[0]*n
for i in range(0,n):
  a[i]=int(input())
temp=sorted(a,reverse=True)
for i in range(0,n):
  if a[i]==temp[0]:
    print(temp[1])
  else:
    print(temp[0])
### BUGGY CODE ###

n,a,b=[int(x) for x in str(input()).split()]
A=[]
for i in range(n):
  A.append([int(x) for x in str(input()).split()])



#print(A)
def f(ma,mb,cost,index):

  newa=ma+A[index][0]
  newb=mb+A[index][1]
  newc=cost+A[index][2]
  
  #print(index,newa,newb,newc)
  if newa*b==a*newb:
    return newc
  elif index==n-1:
    return 100000000000000000000
  else:
    ith=f(newa,newb,newc,index+1)
    return min(ith,f(ma,mb,cost,index+1))



if f(0,0,0,0)<100000000000000000000:
  print(f(0,0,0,0))
else:
  print(-1)


### FIXED CODE ###

N,Ma,Mb=[int(x) for x in input().split()]
A=[]
B=[]
C=[]
for i in range(N):
	a,b,c=[int(x) for x in input().split()]
	A.append(a)
	B.append(b)
	C.append(c)


ANS=[[[-1 for k in range(401)] for j in range(401)] for i in range(41)]

INF=1000000000000000000000

def f(ind,wa,wb):
	global Ma
	global Mb
	global N
	if ANS[ind][wa][wb]==-1:
		if ind==0:
			if (wa+A[0])*Mb==(wb+B[0])*Ma:
				ANS[ind][wa][wb] = C[0]
			elif wa*Mb==wb*Ma and (wa!=0 and wb!=0):
				ANS[ind][wa][wb] = 0
			else:
				ANS[ind][wa][wb] = INF
		else:
			ANS[ind][wa][wb] = min(f(ind-1,wa,wb),f(ind-1,wa+A[ind],wb+B[ind])+C[ind])
	return ANS[ind][wa][wb]

ans=f(N-1,0,0)

if ans==INF:
	print(-1)
else:
	print(ans)
### BUGGY CODE ###

n,m=map(int,input().split())
abc=[list(map(int,input().split())) for _ in [0]*m]
g=[[] for _ in [0]*n]
[g[a-1].append([b-1,c]) for a,b,c in abc]

loop=set()
d=[-10**15 for _ in [0]*n]
d[0]=0
q=[[0,1]]
s=set()
l=[]
while q:
    item,depth=q.pop()
    if depth<=len(s):
        for _ in range(len(s)-depth+1):
            rmv=l.pop()
            s.remove(rmv)
    l.append(item)
    s.add(item)
    for i,dist in g[item]:
        if d[i]<d[item]+dist:
            if i in s:
                loop.add(i)
                continue
            d[i]=d[item]+dist
            q.append([i,depth+1])
    
for x in loop:
    q=[x]
    c=[False for _ in [0]*n]
    c[x]=True
    while q:
        item=q.pop()
        for i,j in g[item]:
            if c[i]==False:
                c[i]=True
                q.append(i)
    if c[n-1]==True:
        print("inf")
        break
else:
    print(d[n-1])

### FIXED CODE ###

n,m=map(int,input().split())
abc=[list(map(int,input().split())) for _ in [0]*m]
g=[[] for _ in [0]*n]
[g[a-1].append([b-1,c]) for a,b,c in abc]

dist=[-10**15 for _ in [0]*n]
dist[0]=0
a,b=-10**15,-10**15

for _ in range(n):
    for p in range(n):
        for i,j in g[p]:
            dist[i]=max(dist[i],dist[p]+j)
    a,b=b,dist[n-1]

if a==b:
    print(a)
else:
    print("inf")
### BUGGY CODE ###

N = int(input())
A = [0] * (N)
for i in range(N):
	A[i] = int(input())

D=max(A)
for j in range(N):
	if A[j] != D:
		print(D)
	else:
		B = A[:]
		B.pop(j)
		print(max(B))

### FIXED CODE ###

N = int(input())
A = [0] * (N)
for i in range(N):
	A[i] = int(input())

D=max(A)
C=sorted(A)[-2]
for j in range(N):
	if A[j] != D:
		print(D)
	else:
		print(C)
### BUGGY CODE ###

s = list(map(int, input().split()))
h = s[0]
k = s[1]
s = list(map(int,input().split()))
for i in range(k):
    if len(s)>0:
        s.remove(max(s))
    else:
        break
print(sum(s))

### FIXED CODE ###

s = list(map(int, input().split()))
n=s[0]
k=s[1]
s = list(map(int, input().split()))
s.sort()
if n<k:
    print(0)
else:
    print(sum(s[0:n-k]))
### 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)

done = {(i,j,k): False 
        for i in range(X+1) for j in range(Y+1) for k in range(Z+1)}
import heapq
q = [(-A[0]-B[0]-C[0],0,0,0)]
heapq.heapify(q)

for _ in range(K):
    ma,i,j,k = heapq.heappop(q)
    if not done[(i+1,j,k)] and i<X-1:
        done[(i+1,j,k)]=True
        heapq.heappush(q,(-A[i+1]-B[j]-C[k] , i+1,j,k))
    
    if not done[(i,j+1,k)] and j<Y-1:
        done[(i,j+1,k)]=True
        heapq.heappush(q,(-A[i]-B[j+1]-C[k] , i,j+1,k))
    
    if not done[(i,j,k+1)] and k<Z-1:
        done[(i,j,k+1)]=True
        heapq.heappush(q,(-A[i]-B[j]-C[k+1] , i,j,k+1))
    print(-ma)

### FIXED CODE ###

#d
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()))
C.sort(reverse=True)

ab = sorted([aa+bb for aa in A for bb in B ],reverse=True)[:K]
ans = sorted([aabb+cc for aabb in ab for cc in C ],reverse=True)[:K]

for aa in ans:
    print(aa)
### BUGGY CODE ###

import collections

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

n = int(input())
lis = list(map(int, input().split()))

c = collections.Counter(lis)


for i in range(n):
    ans = 0
    a = lis[i]
    for key, value in c.items():
        if key == a:
            if value-1 < 2:
                ans += 0
            else:
                ans += cmb(value-1, 2)
        else:
            if value == 1:
                ans += 0
            else:
                ans += cmb(value, 2)
    
    print(ans)

### FIXED CODE ###


n = int(input())
lis = list(map(int, input().split()))

ban = [0] * n

tmp = 0
for i in lis:
    ban[i-1] += 1

for i in ban:
    tmp += i*(i-1)//2
    
for i in lis:
    print(tmp+(1-ban[i-1]))