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

n=int(input())
l=list(map(int,input().split()))
l.sort()
ans=0
import bisect
for i in range(n):
    for j in range(n):
        if i<j:
            a=l[i]
            b=l[j]
            x=bisect.bisect_left(l,a+b)
            y=bisect.bisect_right(l,b-a)
            for k in range(y,x):
                c=l[k]
                if a<b and b<c:
                    ans+=1
print(ans)


### FIXED CODE ###

n=int(input())
l=list(map(int,input().split()))
l.sort()
ans=0
import bisect
for i in range(n):
    for j in range(n):
        if i<j:
            a=l[i]
            b=l[j]
            x=bisect.bisect_left(l,a+b)
            y=bisect.bisect_right(l,b-a)
            if b-a>=a:
                ans+=max(0,x-y-1)
            else:
                ans+=max(0,x-y-2)
print(ans//3)
### BUGGY CODE ###

A= input()
cnt = 0
tmp = []
for i in range(2,len(A)+1):
    for j in range(len(A)-i+1):
        t = A[j:j+i]
        flag = 0
        for k in range(i//2):
            if t[k] == t[len(t)-k-1]:
                continue
            else:
                flag = 1
                break
        if flag ==1:
            tmp.append(A[:j]+t[::-1]+A[j+i:])

print(len(set(tmp))+1)


### FIXED CODE ###

import collections
A= input()
Ac = collections.Counter(A)
cnt = 0
for val in Ac.values():
    cnt += val*(val-1)//2
print(len(A)*(len(A)-1)//2-cnt+1)
### BUGGY CODE ###

N = int(input())
ans = 100000
for i in range(1, 3 * 10 ** 7):
    if N % i == 0:
        ans = min(ans, max(len(str(i)), len(str(N // i))))

print(ans)


### FIXED CODE ###

N = int(input())
ans = 100000
for i in range(1, 10 ** 5):
    if N % i == 0:
        ans = min(ans, max(len(str(i)), len(str(N // i))))

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

n,k = map(int,input().split())
a_list = list(map(int,input().split()))
a = 0
t = 1
d = 0
hoge_list = []
while a < k:
  hoge_list.append(t)
  t = a_list[t-1]
  a += 1
  if t in hoge_list:
    b = hoge_list.index(t)
    d += 1
    break
if d == 0:
  print(t)
else:
  e = (k-b)%(a-b)
  print(hoge_list[b+e])

### FIXED CODE ###

n,k = map(int,input().split())
a_list = list(map(int,input().split()))
a = 0
t = 1
d = 0
hoge_list = []
hoge_set = set()
while a < k:
  hoge_list.append(t)
  hoge_set.add(t)
  t = a_list[t-1]
  a += 1
  if t in hoge_set:
    b = hoge_list.index(t)
    d += 1
    break
if d == 0:
  print(t)
else:
  e = (k-b)%(a-b)
  print(hoge_list[b+e])
### BUGGY CODE ###

N, M = map(int, input().strip().split(" "))

edge = []

for m in range(M):
    a, b = map(int, input().strip().split(" "))
    edge.append((a,b))

one_step = [e[1] for e in edge if e[0] == 1]

pos = False
for i, o in enumerate(one_step):
    pos = len([x for x in edge if  x[0] == o and x[1] == N]) > 0
    if pos:
        break

if pos:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

### FIXED CODE ###

N, M = map(int, input().strip().split(" "))

to_one = [False] * N
to_N = [False] * N
for m in range(M):
    a, b = map(int, input().strip().split(" "))
    if a == 1:
        to_one[b] = True
    if b == N:
        to_N[a] = True

res = False
for n in range(2, N):
    if to_N[n] and to_one[n]:
        print("POSSIBLE")
        res = True
        break

if not res:
    print("IMPOSSIBLE")
### BUGGY CODE ###

class combination():
    #素数のmod取るときのみ　速い
    def __init__(self, n, mod):
        self.n = n
        self.fac = [1] * (n + 1)
        self.inv = [1] * (n + 1)
        for j in range(1, n + 1):
            self.fac[j] = self.fac[j - 1] * j % mod

        self.inv[n] = pow(self.fac[n], mod - 2, mod)
        for j in range(n - 1, -1, -1):
            self.inv[j] = self.inv[j + 1] * (j + 1) % mod

    def comb(self, n, r, mod):
        if r > n or n < 0 or r < 0:
            return 0
        return self.fac[n] * self.inv[n - r] * self.inv[r] % mod

def examD(mod):
    N = I()
    a = LI()
    double = []
    for s in a:
        if s in double:
            cur = s
            break
        double.append(s)
    curL = a.index(cur); curR = a[curL+1:].index(cur) + (curL+1)
    L = curL; M = curR-curL-1;  R = N - curR
#    print(curL,curR)
#    print(L,M,R)
    C = combination(N+1,mod)
    ans = []
    ans.append(N)
    for i in range(2,N+2):
        cur = C.comb(N+1,i,mod)
        if N-1-M-(i-1)>=0:
            cur -= C.comb(N-1-M,i-1,mod)
        if cur<0:
            cur += mod
        ans.append(cur)
    for v in ans:
        print(v)

import sys
import copy
import bisect
import heapq
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examD(mod)


### FIXED CODE ###

class combination():
    #素数のmod取るときのみ　速い
    def __init__(self, n, mod):
        self.n = n
        self.fac = [1] * (n + 1)
        self.inv = [1] * (n + 1)
        for j in range(1, n + 1):
            self.fac[j] = self.fac[j - 1] * j % mod

        self.inv[n] = pow(self.fac[n], mod - 2, mod)
        for j in range(n - 1, -1, -1):
            self.inv[j] = self.inv[j + 1] * (j + 1) % mod

    def comb(self, n, r, mod):
        if r > n or n < 0 or r < 0:
            return 0
        return self.fac[n] * self.inv[n - r] * self.inv[r] % mod

def examD(mod):
    N = I()
    a = LI()
    c = Counter(a)
    db = c.most_common()[0][0]
    curL = a.index(db)
    curR = a.index(db, curL + 1)
    L = curL; M = curR-curL-1;  R = N - curR
#    print(curL,curR)
#    print(L,M,R)
    C = combination(N+1,mod)
    ans = []
    ans.append(N)
    for i in range(2,N+2):
        cur = C.comb(N+1,i,mod)
        if N-1-M-(i-1)>=0:
            cur -= C.comb(N-1-M,i-1,mod)
        if cur<0:
            cur += mod
        ans.append(cur)
    for v in ans:
        print(v)

import sys
import copy
import bisect
import heapq
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examD(mod)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10 ** 7)
h,w=[int(j) for j in input().split()]
s=[list(input())for i in range(h)]
ans=0
def f(i,j,se):
    se.add((i,j))
    res=0
    b=True
    for x,y in [(1,0),(-1,0),(0,1),(0,-1)]:
        p,q=i+x,j+y
        if 0<=p<h and 0<=q<w:
            if s[p][q]!=s[i][j] and (p,q) not in se:
                b=False
                res+=f(p,q,se)
    if b:
        if s[i][j]==".":
            return 1
        else:
            return 0
    else:
        if s[i][j]==".":
            return res+1
        else:
            return res

for i in range(h):
    for j in range(w):
        if s[i][j]=="#":
            ans+=f(i,j,set())

print(ans)

### FIXED CODE ###

h,w=[int(j) for j in input().split()]
s=[input()for i in range(h)]
par=[-1 for i in range(h*w)]    #par<0なら自身が親で要素の個数、>0なら子で親の位置示す
def root(a):
    if par[a]<0:
        return a
    else:
        return root(par[a])

def size(a):
    return -par[root(a)]

def connect(a,b):
    a=root(a)
    b=root(b)
    if a==b:
        return False
    if size(a)<size(b):
        a,b=b,a
    par[a]+=par[b]
    par[b]=a
    return True

for i in range(h):
    for j in range(w):
        for x,y in [(1,0),(-1,0),(0,1),(0,-1)]:
            p,q=i+x,j+y
            if 0<=p<h and 0<=q<w:
                if s[p][q]!=s[i][j]:
                    if root(w*p+q)!=root(w*i+j):
                        connect(w*p+q,w*i+j)

from collections import Counter
c=Counter()
for i in range(h):
    for j in range(w):
        p=i*w+j
        q=root(p)
        if c[q]==0:
            c[q]=[0,0]
        if s[i][j]=="#":
            c[q][0]+=1
        else:
            c[q][1]+=1
ans=0
for i in c:
    ans+=c[i][0]*c[i][1]
print(ans)
### BUGGY CODE ###

a, b = [int(i) for i in input().split()]
c = b
while a != b:
    c *= a
    a += 1
print('Positive' if c > 0 else 'Zero' if c == 0 else 'Negative')


### FIXED CODE ###

A, B = map(int, input().split())
if A > 0:
    print("Positive")
elif A <= 0 <= B:
    print("Zero")
else:
    print("Positive" if (B-A+1)%2== 0 else "Negative")
### BUGGY CODE ###

import sys
input = sys.stdin.buffer.readline
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

def ok(x):
    res = 0
    for i in range(N):
        if A[i]<0:
            left, right = -1, N
            while left + 1 < right:
                c = (left + right) // 2
                if A[c]*A[i] < x: right = c
                else:             left  = c
            res += N - right
        else:
            left, right = -1, N
            while left + 1 < right:
                c = (left + right) // 2
                if A[c]*A[i] < x: left  = c
                else:             right = c
            res += right
        if A[i]*A[i] < x:
            res -= 1
    res //= 2
    return res < K

INF = 10**18+1
l, r = -INF, INF
while l+1<r:
    x = (l+r)//2
    if ok(x):
        l = x
    else:
        r = x
print(l)


### FIXED CODE ###

import numpy as np
import sys
input = sys.stdin.buffer.readline

N, K = map(int, input().split())
A = np.array(input().split(), np.int64)

A = np.sort(A)
zero = A[A == 0]
pos = A[A > 0]
neg = A[A < 0]


def f(x):
    """count the number of products , <= x"""
    cnt_tpl = 0
    # zero and ...
    if x >= 0:
        cnt_tpl += len(zero) * N
    # positive and ...
    cnt_tpl += np.searchsorted(A, x // pos, side='right').sum()
    # negative and ...
    cnt_tpl += (N - np.searchsorted(A, (-x - 1) // (-neg), side='right')).sum()
    # a^2
    cnt_tpl -= np.count_nonzero(A * A <= x)
    assert cnt_tpl % 2 == 0
    return cnt_tpl // 2


left = -10 ** 18
right = 10 ** 18
while left + 1 < right:
    x = (left + right) // 2
    if f(x) >= K:
        right = x
    else:
        left = x


print(right)
### BUGGY CODE ###

import sys
from operator import itemgetter
from itertools import accumulate
from collections import defaultdict
import bisect
input = sys.stdin.buffer.readline

N = int(input())
vws = [tuple(map(int, input().split())) for _ in range(N)]

dp_dict = [defaultdict(lambda: 0)]
dp_dict[0][0] = 0
dp_dict[0][vws[0][1]] = vws[0][0]

for i in range(1, min(2**13, N)):
    v, w = vws[i]
    dp_dict.append(dp_dict[(i-1)//2].copy())
    for w_sum, v_sum in dp_dict[(i-1)//2].items():
        dp_dict[i][w_sum + w] = max(v_sum + v, dp_dict[i][w_sum + w])

values_list = []
weights_list = []
for d in dp_dict:
    ls = sorted(d.items(), key = itemgetter(0))
    weights, values = zip(*ls)
    values = list(accumulate(values, max))
    values_list.append(values)
    weights_list.append(weights)
        
Q = int(input())
for _ in range(Q):
    V, L = map(int, input().split())
    if V-1 < len(dp_dict):
        index = bisect.bisect_right(weights_list[V-1], L) - 1
        print(values_list[V-1][index])
    else:
        V -= 1
        d = defaultdict(lambda: 0)
        d[0] = 0
        while V >= len(dp_dict):
            v, w = vws[V]
            iterator = list(d.items())
            for w_sum, v_sum in iterator:
                d[w_sum + w] = max(v_sum + v, d[w_sum + w])
            V = (V-1) // 2

        v_max = 0
        for w1, v1 in d.items():
            index = bisect.bisect_right(weights_list[V], L-w1) - 1
            if index == -1:
                continue
            v_max = max(v_max, v1 + values_list[V][index])
        print(v_max)


### FIXED CODE ###

import sys
import numpy as np
from numba import njit

input = sys.stdin.buffer.readline

N = int(input())
vws = [tuple(map(int, input().split())) for _ in range(N)]

n = min(2**11, N)
vws_arr = np.array(vws, np.int32)

dp = np.zeros((n, 10**5+1), np.int32)
for i in range(n):
    v, w = vws[i]
    dp[i] = dp[(i-1)//2]
    dp[i, w:] = np.maximum(dp[(i-1)//2, :-w]+v, dp[i, w:])


@njit("i4(i4[::1], i4[::1], i4, i4[::1])", cache = True)
def func(vs, ws, L, dp_):
    values = np.zeros(1 << len(vs), np.int32)
    weights = np.zeros(1 << len(vs), np.int32)
    for i in range(len(vs)):
        for bits in range(1 << len(vs)):
            if bits & (1 << i):
                values[bits] += vs[i]
                weights[bits] += ws[i]
    ret = 0
    for v, w in zip(values, weights):
        if w <= L:
            ret = max(dp_[L - w] + v, ret)
    return ret

Q = int(input())
for _ in range(Q):
    V, L = map(int, input().split())
    V -= 1
    if V < n:
        print(dp[V, L])
    else:
        Vs = []
        while V >= n:
            Vs.append(V)
            V = (V-1) // 2
        vs = vws_arr[Vs, 0]
        ws = vws_arr[Vs, 1]
        print(func(vs, ws, L, dp[V]))
### BUGGY CODE ###

import sys

def biser(lst,func):
    n=len(lst)
    nh=n//2
    if n==1:
        if func(lst[0]):
            return lst[0]
        else:
            return -1
    if func(lst[nh]):
        return biser(lst[nh:],func)
    else:
        return biser(lst[:nh],func)

def mkns(a,s,m):
    if a==0:
        return s
    else:
        return (((s+1)<<a)|s) & m

def main():
    N,K=map(int,sys.stdin.readline().strip().split())
    a=list(map(int,sys.stdin.readline().strip().split()))
    a.sort()
    ss=[0]*(N+1)
    pm=(1<<K)-1
    mask=lambda c:(1<<K)-(1<<c)
    nn=0
    def isunnec(i): 
        if a[i]>=K:
            return False
        for j in range(i+1,N):
            if a[j]>=K:
                break
            ss[i]=mkns(a[j],ss[i],pm)
        if ss[i]&mask(K-a[i])==0:
            return True
        return False
    
    for i in range(N):
         if a[i]>=K:
             break
         ss[i+1]=mkns(a[i],ss[i],pm)
         if isunnec(i):
             nn+=1
    print(nn)

if __name__=='__main__':
    main()


### FIXED CODE ###

#4 9
#1 3 5 6
#の時に1（正解は0）と出力されるがACになる

N, K = map(int, input().split())
a=list(map(int, input().split()))
a.sort()
ans = N
t = 0
for i in range(N-1, -1, -1) :
  if t+a[i] < K:
    t += a[i]
  else:
    ans = min(ans, i)
print(ans)
### BUGGY CODE ###

n, k = map(int, input().split())
s = n
while s > 0:
    s = s-k
if s*(-1) > s+k:
    print(s+k)
else:
    print(s*(-1))


### FIXED CODE ###

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

if n%k > k-n%k:
  print(k-n%k)
if n%k <= k-n%k:
  print(n%k)
### BUGGY CODE ###

import sys 
input=sys.stdin.readline
from collections import deque
def main():
    N=int(input())
    L=[[]]
    
    for i in range(N):
        a=deque(map(int,input().split()))
        L.append(a)
    #print(L)
    
    day=0
    cnt=0
    for i in range(10**6+5):
        if cnt==N*(N-1)/2:
            break
        D=dict()
        CNT=0
        for j in range(1,N+1):
            #print(L[j],j)
            if len(L[j])==0 or j in D:
                continue
            elif L[L[j][0]][0]==j and L[j][0] not in D:
                D[j]=1
                D[L[j][0]]=1
                X=L[j][0]
                L[j].popleft()
                L[X].popleft()
                CNT+=1
        if CNT==0:
            print(-1)
            exit()
        cnt+=CNT
        day+=1
    #print(L)
    #print(cnt)
    print(day)

if __name__=='__main__':
    main()

### FIXED CODE ###

N=int(input())
A=[[0]]
for i in range(N):
    a=list(map(int,input().split()))
    a+=[0]
    A.append(a)
    
#print(A)
B=[0 for i in range(N+1)]
C=[a for a in range(1,N+1)]
cnt=0
for i in range(10**6):
    D=[]
    F=0
    for j in C:
        if A[A[j][B[j]]][B[A[j][B[j]]]]==j and j not in D and A[j][B[j]] not in D:
            D.append(j)
            D.append(A[j][B[j]])
            B[A[j][B[j]]]+=1
            B[j]+=1
            F=1
            cnt+=1
            #print("A",i,B,D)
            #print(A[j][B[j]],B,D)
    if F==0:
        break
    D.sort()
    C=D
    
if cnt==N*(N-1)//2:
    print(i)
else:
    print(-1)
### BUGGY CODE ###

n,m = map(int,input().split())
xyz = [list(map(int,input().split())) for i in range(n)]

dp = [[[[0,0,0] for k in range(8)] for j in range(n+1)] for i in range(n+1)]

for i in range(n):
    for j in range(1,i+2):
        for k in range(8):
            l,r = 0,0
            for d in range(3):
                if k>>d&1:
                    l += dp[i][j-1][k][d] + xyz[i][d]
                    r += dp[i][j][k][d]
                else:
                    l -= dp[i][j-1][k][d] + xyz[i][d]
                    r -= dp[i][j][k][d]
            if l > r:
                for d in range(3):
                    dp[i+1][j][k][d] = dp[i][j-1][k][d] + xyz[i][d]
            else:
                dp[i+1][j][k] = dp[i][j][k]

ans = 0
for k in range(8):
    a = 0
    for d in range(3):
        if k>>d&1:
            a += dp[n][m][k][d]
        else:
            a -= dp[n][m][k][d]
    ans = max(ans,a)
print(ans)



### FIXED CODE ###

n,m = map(int,input().split())
xyz = [list(map(int,input().split())) for i in range(n)]
ans = 0
for i in range(8):
    s = []
    for j in range(n):
        a = 0
        for k in range(3):
            if i>>k&1:
                a += xyz[j][k]
            else:
                a -= xyz[j][k]
        s.append(a)
    s.sort()
    ans = max(ans,sum(s[n-m:]))
print(ans)
### BUGGY CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]

A = sorted(A)
BC = sorted(BC, key=lambda x: x[1], reverse=True)

D = []
for i in range(M):
    for j in range(BC[i][0]):
        D.append(BC[i][1])

n = min(len(D), N)

for i in range(n):
    if A[i] < D[i]:
        A[i] = D[i]
    else:
        break

ans = sum(A)

print(ans)


### FIXED CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split())) # 要素数N
BC = [list(map(int, input().split())) for _ in range(M)] # 要素数M

A = sorted(A) # 計算量NlogN
BC = sorted(BC, key=lambda x: x[1], reverse=True) # 計算量MlogM

D = []
for i in range(M): # 計算量N(len(D)<Nまでなので)
    for j in range(BC[i][0]):
        D.append(BC[i][1])
        if len(D) == N:
            break
    else:
        continue
    break

n = min(len(D), N)
for i in range(n): # 計算量N
    if A[i] < D[i]:
        A[i] = D[i]
    else:
        break

ans = sum(A)

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

n,*a=map(int,open(0).read().split())
for i in range(n):
  s=[0]+a[:i]+a[i+1:]+[0]
  print(sum(abs(s[t]-s[t+1])for t in range(n)))

### FIXED CODE ###

n,*a=map(int,open(0).read().split())
c=[0]+a+[0]
y=sum(abs(c[t]-c[t+1])for t in range(n+1))
for i in range(n):
  s,t,r=c[i:i+3]
  print(y+abs(r-s)-abs(t-s)-abs(t-r))
### BUGGY CODE ###

# -*- coding: utf-8 -*-
a, b = map(int, input().split())
c = list(map(int, input().split()))
d = [sum(c[i:b + i]) for i in range(a - b + 1)]
e = 0
g = d.index(max(d))
for i in range(b):
	e += sum(range(1, c[g + i] + 1)) / c[g + i]
print(e)

### FIXED CODE ###

# -*- coding: utf-8 -*-
a, b = map(int, input().split())
c = list(map(int, input().split()))
d = [(i + 1) / 2 for i in c]
e = sum(d[:b])
f = e
for i in range(a - b):
	f -= d[i]
	f += d[i + b]
	if f > e:
		e = f
print(e)
### BUGGY CODE ###

a,b,k = map(int, input().split())
c = []
for x in range(a,b+1):
  if a <= x and x <= b:
    c.append(x)
c1 = []
for x in c[:k]:
  c1.append(x)
for x in c[(len(c)-k):]:
  if x not in c1:
    c1.append(x)
for x in c1:
  print(x)

### FIXED CODE ###

a,b,k = map(int, input().split())
ab = range(a, b+1)
for c in sorted(set(ab[:k])|set(ab[-k:])):
    print(c)
### BUGGY CODE ###

s = input()
n = len(s)
m = 673

w = [[] for _ in range(3)]
ans = 0

for i in range(n):
    z = int(s[i:])%3
    w[z].append(i)

for i in range(3):
    for j in range(len(w[i])):
            for k in range(j,len(w[i])):
                u = w[i][j]
                v = w[i][k]
                if u == v :
                    y = int(s[u:])
                else:
                    y = int(s[u:v])
                if int(y)%m == 0:
                    ans += 1
print(ans)


### FIXED CODE ###

s = input()
n = len(s)
m = 2019

a = 0
r = [0 for _ in range(m+1)]
r[0] = 1
z = 0
j = 1
for i in range(0,n):
    j = j * 10 % m
    ss = int(s[n-i-1])*j + z
    z = ss%m



    a += r[z]
    r[z] += 1

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

N, M = map(int, input().split())
X = list(map(int, input().split()))
X.sort()
dist = [X[i+1] - X[i] for i in range(len(X)-1)]
if N>=M: print(0)
else:
  for i in range(N-1):
    dist.remove(max(dist))
  print(sum(dist))

### FIXED CODE ###

N, M = map(int, input().split())
X = list(map(int, input().split()))
X.sort()
D = [X[i+1] - X[i] for i in range(len(X)-1)]
D.sort()
if N>=M: print(0)
else:
  newD = D[:len(D)-(N-1)]
  print(sum(newD))
### BUGGY CODE ###

N, K = map(int, input().split()) # 横に2個
L = [list(map(int, input().split())) for _ in range(N-1)]

mod = 10**9+7

neardic = {}
for p in range(1, N+1):
    near = []
    for l in L:
        if p in l:
            other = set(l) - {p}
            near.append(list(other)[0])
    neardic[p] = set(near)


def color(p=1, state=[1], prob=K, checked=set()):
    nears = neardic[p]
    checked.add(p)
    unchecked_nears = nears - checked
    A = len(unchecked_nears)
    if A == 0:
        state.pop()
        return prob
    nextprobmax = K-1 if len(state) == 1 else K-2
    for i, near in enumerate(unchecked_nears):
        prob = prob * (nextprobmax - i) % mod
        state.append(near)
        prob = color(near, state, prob, checked)
    return prob

print(color())




### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

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

checked = [False]*N
C = [None]*N
checked[0] = True

def dfs(p, c1, c2, depth):
    C[p] = c1 + c2
    d = 0
    for np in graph[p]:
        if not checked[np]:
            checked[np] = True
            d += 1
            g = 1 if depth > 0 else 0
            dfs(np, d, g, depth+1)
        

dfs(0, 0, 0, 0)
#print(C)

mod = 10**9+7
ans = 1
for n in range(N):
    ans = ans * (K-C[n]) % mod

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

from collections import deque
n,m,*inp=map(int,open(0).read().split())
d=[[] for i in range(n)]
for i in range(m):
    j=2*i
    a,b=inp[j:j+2]
    a-=1
    b-=1
    d[a].append(b)
    d[b].append(a)
l=[-1 for i in range(n)]
q=deque([0])
#print(d)
while len(q)>0:
    x=q.popleft()
    for i in d[x]:
        #print(i)
        if i!=0 and l[i]==-1 and x not in q:
            q.append(i)
            #print(i)
            l[i]=str(x+1)
l=l[1:]
#print(l)
print('No' if 0 in l else 'Yes\n'+'\n'.join(l))


### FIXED CODE ###

from collections import deque
n,m,*inp=map(int,open(0).read().split())
d=[[] for i in range(n)]
for i in range(m):
    j=2*i
    a,b=inp[j:j+2]
    a-=1
    b-=1
    d[a].append(b)
    d[b].append(a)
l=[-1 for i in range(n)]
q=deque([0])
#print(d)
while len(q)>0:
    x=q.popleft()
    for i in d[x]:
        #print(i)
        if l[i]==-1:
            q.append(i)
            #print(i)
            l[i]=str(x+1)
l=l[1:]
#print(l)
print('No' if 0 in l else 'Yes\n'+'\n'.join(l))
### BUGGY CODE ###

# coding: utf-8
N = int(input())
A = input().split()

# total count
dict = set(A)
total_count = 0
for val in dict:
  tmp = A.count(val)
  tmp = int(tmp*(tmp-1)/2)
  total_count += tmp

# substracted count
for k in range(N):
  sub_count = A.count(A[k]) - 1
  print('{}'.format(total_count - sub_count))

### FIXED CODE ###

# coding: utf-8
N = int(input())
A = list(map(int, input().split()))

dict = {}
for i in range(N):
  if A[i] in dict.keys():
    dict[A[i]] += 1
  else:
    dict[A[i]] = 1

def comb(n):
  if n<2:
    return 0
  return int(n * (n - 1) / 2)

# all
ret = 0
for key in dict.keys():
  val = dict[key]
  ret += comb(val)

# i >= 0
for i in range(N):
  val_n = dict[A[i]]
  next_ret = ret - comb(val_n) + comb(val_n - 1)
  print(next_ret)
### BUGGY CODE ###

N = int(input())

nums = [int(input()) for x in range(N)]

copys = nums.copy()

for ind in range(N):
    copys.pop(ind)
    print(max(copys))
    copys = nums.copy()

### FIXED CODE ###

N = int(input())

nums = [int(input()) for x in range(N)]

a = sorted(nums)[-1]#max(nums)
b = sorted(nums)[-2]#max(nums.remove(max_num))



if a == b:
    for _ in nums:
        print(a)
else:
    for x in [b if x == a else a for x in nums]:
        print(x)