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

def main():
  ans=-float('inf')
  for si in range(n):
    x=si
    S=[]
    tot=0
    while True:
      x=P[x]
      S.append(C[x])
      tot+=C[x]
      if x==si:
        break
    l=len(S)
    t=0
    for i in range(l):
      t+=S[i]
      if i+1>k:
        break
      now=t
      if tot>0:
        e=(k-i-1)//l
        now+=tot*e
      ans=max(ans,now)
  return ans
        
      

n,k=map(int,input().split())
P=list(map(int,input().split()))
P=[p-1 for p in P]
C=list(map(int,input().split()))
flag=[0]*n


print(main())

### FIXED CODE ###

n,k=map(int,input().split())
P=list(map(int,input().split()))
P=[p-1 for p in P]
C=list(map(int,input().split()))

def main():
  ans=-float('inf')
  for si in range(n):
    x=si
    S=[]
    tot=0
    while True:
      x=P[x]
      S.append(C[x])
      tot+=C[x]
      if x==si:
        break
    l=len(S)
    t=0
    for i in range(l):
      t+=S[i]
      if i+1>k:
        break
      now=t
      if tot>0:
        e=(k-i-1)//l
        now+=tot*e
      ans=max(ans,now)
  return ans      


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

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

for nn in range(n - 1, 0, -1):
  t = li.pop(nn)
  if li.count(t) != 0:
    print('NO')
    exit()
print('YES')

### FIXED CODE ###

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

if len(li) == len(set(li)):
  print('YES')
else:
  print('NO')
### BUGGY CODE ###

a, b, x = list(map(int, input().split()))

result = [i % x for i in range(a, b + 1)].count(0)
print(result)

### FIXED CODE ###

a, b, x = list(map(int, input().split()))

result = b // x - ~-a // x
print(result)
# result = [i % x for i in range(a, b + 1)].count(0)
# print(result)
### BUGGY CODE ###

# ここから
import sys
input = sys.stdin.readline

def resolve():
    n, m = map(int, input().split())
    aa = [int(input()) for _ in range(m)]
    dp = [0] * (n+1)
    dp[0] = 1
    dp[1] = 0 if 1 in aa else 1

    for i in range(2, n+1):
        if i in aa:
            dp[i] = 0
        else:
            dp[i] = (dp[i-2] + dp[i-1]) % 1000000007

    print(dp[n])



resolve()

### FIXED CODE ###

# ここから
import sys
input = sys.stdin.readline

def resolve():
    n, m = map(int, input().split())
    aa = [False] * (n+1)

    for i in range(m):
        a = int(input())
        aa[a] = True

    dp = [0] * (n+1)
    dp[0] = 1
    dp[1] = 0 if aa[1] else 1

    for i in range(2, n+1):
        if aa[i]:
            dp[i] = 0
        else:
            dp[i] = (dp[i-2] + dp[i-1]) % 1000000007

    print(dp[n])



resolve()
### BUGGY CODE ###

from collections import deque

def main():
    N=int(input())
    A=list(map(int, input().split()))
    B=list(map(int, input().split()))
    q = deque()
    cq = deque()
    q.appendleft(B)
    cq.appendleft(0)

    while len(q) > 0:
        b = q.pop()
        c = cq.pop()
        if b == A:
            print(c)
            break
        else:
            for i in range(N):
                _tmp = b[0:N]
                _tmp[i] = b[i] - b[i-1 if i>=1 else N-1] - b[i+1 if i<N-1 else 0]
                if  A[i] <= _tmp[i]:
                    #print(_tmp)
                    q.appendleft(_tmp)
                    cq.appendleft(c+1)
    else:
        print(-1)

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    N=int(input())
    A=list(map(int, input().split()))
    B=list(map(int, input().split()))

    count = 0
    prev_count = -1
    while count!=prev_count:
        prev_count = count
        for i in range(N):
            d = B[i-1 if i>=1 else N-1] + B[i+1 if i<N-1 else 0]
            c = (B[i]-A[i]) // d
            B[i] -= d * c
            count += c

    if A == B:
        print(count)
    else:
        print(-1)

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

n = int(input())
l = list(map(int, input().split()))
l.sort()
count = 0
for i in range(len(l) - 2):
    a = l[i]
    for j in range(i + 1, len(l) - 1):
        b = l[j]
        r = a + b
        for k in range(j + 1, len(l)):
            c = l[k]
            if c < r:
                count += 1
            else:
                break
print(count)

### FIXED CODE ###

from bisect import bisect_left


n = int(input())
l = list(map(int, input().split()))
l.sort()
cnt = 0
for i in range(n-2):
    a = l[i]
    for j in range(i+1, n-1):
        b = l[j]
        cnt += bisect_left(l, a+b) - j - 1
        # bisec_left(l, x)でlの中にxを挿入できる点を探す
print(cnt)
### BUGGY CODE ###

h, n = map(int, input().split())
a = []
b = []

for i in range(n):
    a_e, b_e = map(int, input().split())
    a.append(a_e), b.append(b_e)

h_dp = h + max(a)

dp = [[float("inf")] * (h_dp + 1) for _ in range(n+1)]
dp[0][0] = 0

for i in range(n):
    dp[i][0] = 0
    for j in range(h_dp+1):
        if a[i] > h_dp:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = min(dp[i][j], dp[i+1][j-a[i]] + b[i])

ans = float("inf")
for i in range(h, h_dp+1):
    ans = min(ans, dp[n][i])

print(ans)

### FIXED CODE ###

h, n = map(int, input().split())
a = []
b = []

for i in range(n):
    a_e, b_e = map(int, input().split())
    a.append(a_e), b.append(b_e)

h_dp = h + max(a)

dp = [[float("inf")] * (h_dp + 1) for _ in range(n+1)]
dp[0][0] = 0

for i in range(n):
    dp[i][0] = 0
    for j in range(h_dp+1):
        if a[i] > h_dp:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = min(dp[i][j], dp[i+1][j-a[i]] + b[i])

ans = float("inf")
for i in range(h, h_dp+1):
    ans = min(ans, dp[n][i])

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

N,M=[int(x) for x in input().split()]
set1=set()
setn=set()
for i in [None]*M:
    ipt=[int(x) for x in input().split()]
    if 1 in ipt:
        set1 = set1.union(ipt)
    if N in ipt:
        setn = setn.union(ipt)
if set1 & setn:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

### FIXED CODE ###

N,M=[int(x) for x in input().split()]
set1=[]
setn=[]
for i in [None]*M:
    ipt=[int(x) for x in input().split()]
    if 1 in ipt:
        set1 += ipt
    if N in ipt:
        setn += ipt
if set(set1) & set(setn):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
### BUGGY CODE ###

import bisect


N = int(input())
s = []
memo = [{} for _ in range(N)]
for i in range(N):
    si = list(input())
    si.sort()
    s += [('').join(si)]
s.sort()
ans = 0
while (s):
    t = bisect.bisect_right(s, s.pop(0))
    del s[:t]
    ans += (t * (t + 1)) // 2
print(ans)

### FIXED CODE ###

N = int(input())
memo = {}
ans = 0
for i in range(N):
    si = list(input())
    si.sort()
    si = ('').join(si)
    if si not in memo:
        memo[si] = 1
    else:
        memo[si] += 1
        ans += memo[si] - 1
print(ans)
### BUGGY CODE ###

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from sys import stdin
input = stdin.readline


def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans = 1

    for a in A:
        ans *= a
        if a == 0:
            ans = 0
            break
        
    if ans > 10**18:
        print(-1)
    else:
        print(ans)


if __name__ == '__main__':
    main()

### FIXED CODE ###


def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans = 1

    for a in A:
        if a == 0:
            ans = 0
            break
        elif ans < 10**18:
            ans *= a
        
    if ans > 10**18:
        print(-1)
    else:
        print(ans)


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

s = input()

count = 0
ans = 0

ss = s.replace('BC','X')

ans_list = [0]*len(ss)

for i in range(len(ss)):
    if ss[i] == 'A':

        for j in range(i+1, len(ss)):
            if ss[j] == 'X':
                ans_list[i] += 1

            elif ss[j] == 'A':
                continue
            else:
                break

print(sum(ans_list))

### FIXED CODE ###

s = input()

count = 0
ans = 0

ss = s.replace('BC','X')

flag = 0

for i in ss:
    if i == 'A':
        flag += 1
    elif i == 'X':
        ans += flag
    else:
        flag = 0

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

class Node:
    def __init__(self,v):
        self.v = v
        self.left = None
        self.right = None

def inorder(n):
    if n != None:
        inorder(n.left)
        print n.v,
        inorder(n.right)

def preorder(n):
    if n != None:
        print n.v,
        preorder(n.left)
        preorder(n.right)

class BST:
    def __init__(self):
        self.root = None

    def insert(self,v):
        n = Node(v)
        x = self.root
        y = None
        while x != None:
            y = x
            if x.v > v:
                x = x.left
            else:
                x = x.right
        if y == None:
            self.root = n
        else:
            if y.v > v:
                y.left = n
            else:
                y.right = n
    def print_tree(self):
        print '',
        inorder(self.root)
        print
        print '',
        preorder(self.root)
        print


n = int(raw_input())
ops = []
for _ in range(n):
    ops.append(raw_input())

tree = BST()
for op in ops:
    if op[0] == 'i':
        num = op.split(' ')[1]
        num = int(num)
        tree.insert(num)
    else:
        tree.print_tree()

### FIXED CODE ###

def insert(tree,k):
    y = None
    x = tree
    z = {'key':k, 'parent':None, 'left':None, 'right':None}
    while x != None:
        y = x
        if x['key'] > k:
            x = x['left']
        else:
            x = x['right']
    z['parent'] = y
    if y == None:
        tree = z
    elif y['key'] > k:
        y['left'] = z
    else:
        y['right'] = z
    return tree

def middleorder(x):
    if x != None:
        middleorder(x['left'])
        print x['key'],
        middleorder(x['right'])

def preorder(x):
    if x != None:
        print x['key'],
        preorder(x['left'])
        preorder(x['right'])



tree = None
m = int(raw_input())
for i in range(m):
    c = raw_input().strip()
    if c[0] == 'i':
        tree = insert(tree, int(c[7:]))
    elif c[0] == 'p':
        print '',
        middleorder(tree)
        print
        print '',
        preorder(tree)
        print
### BUGGY CODE ###

N, M = map(int, input().split())
P = [0 for i in range(M)]
Y = [0 for i in range(M)]
country = [[] for i in range(N+1)]
for i in range(M):
    P[i], Y[i] = map(int, input().split())
    country[P[i]].append(Y[i])

for i in range(N+1):
    country[i].sort()

for i in range(M):
    num = country[P[i]].index(Y[i]) + 1
    line = str(P[i]).zfill(6) + str(num).zfill(6)
    print(line)

### FIXED CODE ###

import heapq
N, M = map(int, input().split())
P = [0 for i in range(M)]
Y = [0 for i in range(M)]
country = [[] for i in range(N+1)]
for i in range(M):
    P[i], Y[i] = map(int, input().split())
    heapq.heappush(country[P[i]], (Y[i],i))
cs = [0 for i in range(M)]
for i in range(N+1):
    ran = len(country[i])
    for j in range(ran):
        year, num = heapq.heappop(country[i])
        cs[num] = str(j+1).zfill(6)

for i in range(M):
    line = str(P[i]).zfill(6) + cs[i]
    print(line)
### BUGGY CODE ###

K,S=map(int,input().split())
N=0
for X in range(K+1):
    for Y in range(K+1):
        for Z in range(K+1):
            if X+Y+Z==S:
                N+=1
print(N)

### FIXED CODE ###

K,S=map(int,input().split())
N=0
for X in range(K+1):
    for Y in range(K+1):
            if X+Y<=S and S-Y-X<=K:
                N+=1
print(N)
### BUGGY CODE ###

#coding:UTF-8
def FN(n):
    if n==0 or n==1:
        return 1
    else:
        ans=FN(n-1)+FN(n-2)
        return ans
if __name__=="__main__":
    n=int(input())
    ans=FN(n)
    print(ans)

### FIXED CODE ###

#coding:UTF-8
def FN(n):
    if n==0 or n==1:
        F[n]=1
        return F[n]
    if F[n]!=None:
        return F[n]
    F[n]=FN(n-1)+FN(n-2)
    return F[n]

if __name__=="__main__":
    n=int(input())
    F=[None]*(n+1)
    ans=FN(n)
    print(ans)
### BUGGY CODE ###

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

ans = 0

b = [0]
for i in range(n):
    b.append(b[i] + a[i])
for x in list(set(b)):
    b_num = b.count(x)
    ans += int(b_num * (b_num - 1) / 2)
    
print(ans)

### FIXED CODE ###

from collections import Counter

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

ans = 0

b = [0]
for i in range(n):
	b.append(b[i] + a[i])

c = Counter(b)

for value in c.values():
	ans += value * (value - 1) // 2
    
print(ans)
### BUGGY CODE ###

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

S = input()
ls = list(S)
ls = [int(x) for x in ls]
offset = 0
count = 0
while len(ls) >= 2:
    if ls[offset] != ls[offset +1]:
        del ls[offset:offset +2]
        count += 2
        offset = 0
    elif offset + 2 == len(ls):
        break
    else:
        offset += 1

print(count)

### FIXED CODE ###

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

S = input()
ls = list(S)
ls = [int(x) for x in ls]

ans = min(ls.count(0),ls.count(1))
print(ans*2)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))
'''
for i in range(n):
    p = a[:i] + a[i+1:]
    ans = 0
    for j in range(1,len(p)):
        ans += abs(p[j-1] - p[j])
    ans += abs(p[0]) + abs(p[-1])
    print(ans)
'''
abs1 = [0]*(n-1)
abs1_sum = 0
for i in range(1,n):
    abs1[i-1] = abs(a[i-1]-a[i])
    abs1_sum += abs(a[i-1]-a[i])


abs2 = [0]*(n-2)
for i in range(2,n):
    abs2[i-2] = abs(a[i-2]-a[i])
#print(abs1)


for i in range(n):
    p = a[:i] + a[i+1:]
    if i == 0:
        print(abs1_sum - abs1[0] + abs(p[0]) + abs(p[-1]))
    elif i == n-1:#
        #print(abs1[:n-2],abs(p[0]),abs(p[-1]))
        print(abs1_sum - abs1[-1] + abs(p[0]) + abs(p[-1]))
    else:
        print(abs(p[0]) + abs(p[-1]) + abs1_sum - abs1[i] - abs1[i-1] + abs2[i-1])

    




### FIXED CODE ###

import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))

abs1 = [0]*(n-1)
abs1_sum = 0
for i in range(1,n):
    abs1[i-1] = abs(a[i-1]-a[i])
    abs1_sum += abs(a[i-1]-a[i])


abs2 = [0]*(n-2)
for i in range(2,n):
    abs2[i-2] = abs(a[i-2]-a[i])
#print(abs1)

b_0 = abs(a[0])
b_1 = abs(a[1])
b_n1 = abs(a[n-1])
b_n2 = abs(a[n-2])
ans = []
for i in range(n):
    if i == 0:
        ans.append(abs1_sum - abs1[0] + b_1 + b_n1)
    elif i == n-1:#
        #print(abs1[:n-2],abs(p[0]),abs(p[-1]))
        ans.append(abs1_sum - abs1[-1] + b_0 + b_n2)
    else:
        ans.append(b_0 + b_n1 + abs1_sum - abs1[i] - abs1[i-1] + abs2[i-1])

for i in range(n):
    print(ans[i])
### BUGGY CODE ###

S = list(input())
T = list(input())

for i in range(len(S)):
    if S[i] != T[i]:
        migawari = S[i]
        index1 = [index for index, x in enumerate(S) if x == S[i]]
        index2 = [index for index, x in enumerate(S) if x == T[i]]
        for k in index1:
            S[k] = T[i]
        for j in index2:
            S[j] = migawari

if S == T:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

S = input()
T = input()

used = []
res  = []

for i in range(len(S)):
    if S[i] not in used:
        used.append(S[i])
    res.append(used.index(S[i]))

#print(used)
#print(res)
used = []
ret = []

for i in range(len(T)):
    if T[i] not in used:
        used.append(T[i])
    ret.append(used.index(T[i]))

if res == ret:
    print('Yes')
else:
    print('No')
### BUGGY CODE ###

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


def f(a, b):
    ans = a
    while a < b:
        a += 1
        ans ^= a
    return ans


print(f(A, B))


### FIXED CODE ###

def get_bin_arr(n):
    arr = []
    while n > 0:
        arr.append(n & 1)
        n >>= 1
    return arr


def bin_arr_to_int(arr):
    return sum([2**i * digit for i, digit in enumerate(arr)])


def count_ones(idx, tier):
    half_cycle = 2**tier
    full_cycle = half_cycle * 2
    return (idx // full_cycle) * half_cycle \
        + max(idx % full_cycle - half_cycle, 0)


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

a = get_bin_arr(A)
b = get_bin_arr(B)

my_max = 10**12
bin_digits = len(get_bin_arr(my_max))

# fill
a += [0] * (bin_digits - len(a))
b += [0] * (bin_digits - len(b))

ones = [0] * bin_digits

for i in range(bin_digits):
    ones[i] = count_ones(B + 1, i) - count_ones(A, i)

ans = [i % 2 for i in ones]
print(int(bin_arr_to_int(ans)))
### BUGGY CODE ###

N=int(input())
#A=[int(x) for x in input().strip().split(" ")]
A=list(map(int,input().split()))
x=1
c=1000000000000000000
for i in range(N):
    if x<c or x!=0:
        x *=A[i]
if x>c:
    print("-1")
else:
    print(x)

### FIXED CODE ###

def main():
    N=int(input())
    A=list(map(int,input().split()))
    if 0 in A:
        print(0)
        return
    
    prod=1
    for a in A:
        prod *=a
        if prod > 1000000000000000000:
            print(-1)
            return
    
    print(prod)
main()
### BUGGY CODE ###

from collections import deque
h, w = map(int, input().split())
s = [list(input()) for i in range(h)]
work = [[[] for j in range(w)] for i in range(h)]
result = 0
for i in range(h):
    for j in range(w):
        append = work[i][j].append
        if i<h-1 and s[i+1][j] == ".":
            append([i+1,j])
        if i>0 and s[i-1][j] == ".":
            append([i-1,j])
        if j<w-1 and s[i][j+1] == ".":
            append([i,j+1])
        if j>0 and s[i][j-1] == ".":
            append([i,j-1])
for i in range(h):
    for j in range(w):
        if s[i][j] != ".":
            continue
        q = deque([[i, j]])
        temp = [[i, j]]
        popleft = q.popleft
        append = q.append
        d = -1
        count = 1
        counter = 0
        for k in range(h*w):
            x, y = popleft()
            count -= 1
            for el in work[x][y]:
                if el not in temp:
                    counter += 1
                    append(el)
                    temp.append(el)
            if count == 0:
                d += 1
                count = counter
                counter = 0
            if len(q) == 0:
                break
        result = result if result>d else d
print(result)


### FIXED CODE ###

from collections import deque
h, w = map(int, input().split())
s = [list(input()) for i in range(h)]
work = [[[] for j in range(w)] for i in range(h)]
result = 0
for i in range(h):
    for j in range(w):
        append = work[i][j].append
        if i<h-1 and s[i+1][j] == ".":
            append([i+1,j])
        if i>0 and s[i-1][j] == ".":
            append([i-1,j])
        if j<w-1 and s[i][j+1] == ".":
            append([i,j+1])
        if j>0 and s[i][j-1] == ".":
            append([i,j-1])
q = deque()
popleft = q.popleft
append = q.append
for i in range(h):
    for j in range(w):
        if s[i][j] != ".":
            continue
        q.clear()
        q.append([i, j])
        temp = [[i, j]]
        tempappend = temp.append
        d = -1
        count = 1
        counter = 0
        for k in range(w*h):
            x, y = popleft()
            count -= 1
            for el in work[x][y]:
                if el not in temp:
                    counter += 1
                    append(el)
                    tempappend(el)
            if count == 0:
                d += 1
                count = counter
                counter = 0
            if len(q) == 0:
                break
        result = result if result>d else d
    if result == h+w-2:
        break
print(result)
### BUGGY CODE ###

N, K = map(int, input().split(' '))
h = [int(val) for val in input().split(' ')]
dp = [0] + [float('inf')]*(len(h)-1)
for i in range(1, len(h)):
    dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(max(0, i-K), i)])
print(dp[-1])

### FIXED CODE ###

import numpy as np

N, K = map(int, input().split(' '))
h = np.array(list(map(int, input().split(' '))))
dp = np.zeros(len(h), dtype=int)
for i in range(1, len(h)):
    start = max(0, i-K)
    dp[i] = min(dp[start:i] + np.abs(h[i] - h[start:i]))
print(dp[-1])
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import numpy as np

# worst order: 101^6 => 10^8

def check(a, b, c):
    flag = True
    for i in range(3):
        for j in range(3):
           if c[i][j]!=a[i]+b[j]:
               flag = False
               return flag

    return flag

c = []
c.append(list(map(int, input().split())))
c.append(list(map(int, input().split())))
c.append(list(map(int, input().split())))

arr_c = np.array(c)
a_max = np.amax(arr_c, axis=1)
b_max = np.amax(arr_c, axis=0)

a = []
b = []
for i in range(3):
    if len(list(range(0, a_max[i]+1, 1)))==0:
        a.append([0])
    else:
        a.append(list(range(0, a_max[i]+1, 1)))
    
    if len(list(range(0, b_max[i]+1, 1)))==0:
        b.append([0])
    else:
        b.append(list(range(0, b_max[i]+1, 1)))

ans = 'No'
cnt = 0
for a0 in a[0]:
    for a1 in a[1]:
        for a2 in a[2]:
            for b0 in b[0]:
                for b1 in b[1]:
                    for b2 in b[2]:
                        a_list = [a0, a1, a2]
                        b_list = [b0, b1, b2]
                        flag = check(a_list, b_list, c)
                        if flag == True:
                            print("Yes")
                            exit(0)

print(ans)

### FIXED CODE ###

# -*- coding: utf-8 -*-
import numpy as np

# worst order: 101^6 => 10^8

def check(a, b, c):
    flag = True
    for i in range(3):
        for j in range(3):
           if c[i][j]!=a[i]+b[j]:
               flag = False
               return flag

    return flag

c = []
c.append(list(map(int, input().split())))
c.append(list(map(int, input().split())))
c.append(list(map(int, input().split())))

arr_c = np.array(c)
a_max = np.amax(arr_c, axis=1)
b_max = np.amax(arr_c, axis=0)

a = []
b = []
for i in range(3):
    if len(list(range(0, a_max[i]+1, 1)))==0:
        a.append([0])
    else:
        a.append(list(range(0, a_max[i]+1, 1)))
    
    if len(list(range(0, b_max[i]+1, 1)))==0:
        b.append([0])
    else:
        b.append(list(range(0, b_max[i]+1, 1)))

ans = 'No'
cnt = 0
for a0 in a[0]:
    for b0 in b[0]:
        if c[0][0] != a0 + b0:
            continue
        for a1 in a[1]:
            if c[1][0] != a1 + b0:
                continue
            for b1 in b[1]:
                if c[0][1] != a0 + b1 or c[1][1] != a1 + b1:
                    continue   
                for a2 in a[2]:
                    if c[2][0] != a2 + b0 or c[2][1] != a2 + b1:
                        continue
                    for b2 in b[2]:
                        if c[0][2] != a0 + b2 or c[1][2] != a1 + b2 or c[2][2] != a2 + b2:
                            continue

                        print("Yes")
                        exit(0)

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

import sys
input = sys.stdin.readline
 
n = int(input())
l = list(map(int, input().split()))
l.sort()

cnt = 0
for i in range(n):
  for j in range(n-i-1):
    cnt += len([c for c in l[j+i+2:] if c < l[i] + l[j+i+1]])
print(cnt)

### FIXED CODE ###

import bisect
import sys
input = sys.stdin.readline
 
n = int(input())
l = [int(li) for li in input().split(' ')]
l.sort()

cnt = 0
for i in range(n):
  for j in range(i+1, n):
    cnt += bisect.bisect_left(l, l[i]+l[j])-j-1
    
print(cnt)
### BUGGY CODE ###

n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
tmp = max(a)
for i in range(n):
  if tmp == a[i]:
    a[i] = -1
    print(max(a))
    a[i] = tmp
  else:
    print(tmp)



"""
for i in range(n):
  if i == 0:
    print(max(a[i+1:]))
    continue
  if i == n-1:
    print(max(a[0:n-1]))
    break
  ans = max(max(a[0:i]),max(a[i+1:n]))
  print(ans)
  """

### FIXED CODE ###

n = int(input())
a = [int(input()) for _ in range(n)]
tmpa = a[:] 
tmpa.sort()

for x in a:
  if x == tmpa[n-1]:
    print(tmpa[n-2])
  else:
    print(tmpa[n-1])
"""
if a[0] > a[1]:
  m,m2 = a[0],a[1]
else:
  m,m2 = a[1],a[0]

for x in a[2:]:
  if x > m2:
    if x>m:
      m2,m = 

"""
"""
for i in range(n):
  if i == 0:
    p
    rint(max(a[i+1:]))
    continue
  if i == n-1:
    print(max(a[0:n-1]))
    break
  ans = max(max(a[0:i]),max(a[i+1:n]))
  print(ans)
  """