Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from operator import mul
from functools import reduce
n = int(input())
a = list(map(int,input().split()))
m = max(a)
cnt = 0
ans = 0

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under
  
for num in a:
  cal = cmb(m, num)
  if cal >= cnt:
    cnt = cal
    ans = num
print(m,ans)    

  

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
#まず、combの左に来るのは、max(a)
#combの右に来るのは、max(a)//2 or max(a)-max(a)//2　に一番近い数字

m = max(a)
a.sort()
a.pop()
#print(a)
#前から順番に審査していき、現状最高のやつを選んでおく。

dif = 10**9
ans = 0
for num in a:
  d = min(abs(m//2 - num),abs(m//2 + num - m))
  if dif > d:
    dif = d
    ans = num
print(m,ans)
Buggy python submission (verdict: Runtime Error):
import sys
from collections import deque
input = sys.stdin.readline

h, w = map(int, input().split())
maze = [list("#" * (w + 2))]
white = 0
for _ in [0] * h:
    line = "#" + input().strip() + "#"
    maze.append(list(line))
    white += line.count(".")

maze += [list("#" * (w + 2))]

q = deque()
q.append([1, 1])
maze[1][1] = 0
maze[-2][-2] = "goal"
#print(maze)

dir = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dis = 0
while q:
    x, y = q.pop()
    dis += 1

    for dx, dy in dir:
        next_x, next_y = x + dx, y + dy
        if maze[next_y][next_x] == ".":
            #print(next_y, next_x)
            q.append([next_y, next_x])
            maze[next_y][next_x] = dis
            
        if maze[next_y][next_x] == "goal":
            print(white - dis - 1)
            exit()
print(-1)


Fixed submission:
import sys

h,w = map(int,input().split())

# マップを生成する。####で囲う。"."をカウントしておく(white)
m = []
m.append('#'*(w+2))
white = 0
for i in range(h):
  s = input()
  m.append(list('#' + s + '#'))
  white += s.count('.')
m.append('#'*(w+2))

stack = set([(1, 1)])
dist = 0

# stackがある限りループ
while len(stack) > 0:
  
  #ゴールまでの距離をカウントしていく
  dist += 1
  
  # 空のセットを用意
  next_w = set()
  
  for y, x in stack:
    m[y][x] = dist
    
    # ゴールに到着したら
    if (y, x) == (h, w):
      print(white - dist)
      exit()
      
 	# 上下左右に移動。
    for dx,dy in [0,1],[0,-1],[1,0],[-1,0]:
      # "."なら移動可能
      if m[y-dy][x-dx] == '.':
        next_w.add((y-dy,x-dx))
  stack = next_w

print('-1')
Buggy python submission (verdict: Runtime Error):
n,y = map(int,input().split())
ans_a = -1
ans_b = -1
ans_c = -1

for i in range(n+1):
  for j in range(n+1):
    x = y - 10000*i - 5000*j
    if x % 1000 == 0:
      k = x / 10000
      ans_a = i
      ans_b = j
      ans_c = k
print(ans_a,ans_b,ans_c)

Fixed submission:
S = input().split('/')
S[0] = "2018"
ans = '/'.join(S)
print(ans)

Buggy python submission (verdict: Runtime Error):
n,y = map(int,input().split())
ans_a = -1
ans_b = -1
ans_c = -1

for i in range(n+1):
  for j in range(n+1-i):
    x = y - 10000*i - 5000*j
    if x % 10000 == 0:
      k = x / 10000
      ans_a = i
      ans_b = j
      ans_c = k
print(ans_a,ans_b,ans_c)

Fixed submission:
S = input().split('/')
S[0] = "2018"
ans = '/'.join(S)
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
n,h = map(int,input().split())
ab =[list(map(int,input().split())) for _ in range(n)]
lisA = []
lisB = []
#使いまわせるaを記録し、その最大値を見つける
for a,_ in ab:
  lisA.append(a)
m = max(lisA)

#ｍより大きければ収納
for _,b in ab:
  if b > m:
  	lisB.append(b)

s = sum(lisB)
lisB.sort(reverse=True)
#print(lisA,lisB,m,s)

cnt = 0
#もし、m以上のbの合計だけでhを超えられるなら、点数の低い順に抜いていく
if s>=h:
  while s>=H:
    #小さいやつを抜いていく
    s -= lisB.pop()
  cnt = len(lisB)  
else:
  cnt = len(lisB) + math.ceil((h-s)//m)
  
print(cnt)  
      
  
  

  
  
  
  

Fixed submission:
import math
n,h = map(int,input().split())
ab =[list(map(int,input().split())) for _ in range(n)]
lisA = []
lisB = []
#使いまわせるaを記録し、その最大値を見つける
for a,_ in ab:
  lisA.append(a)
m = max(lisA)

#ｍより大きければ収納
for _,b in ab:
  if b > m:
  	lisB.append(b)

s = sum(lisB)
lisB.sort(reverse=True)
#print(lisA,lisB)

cnt = 0
#もし、m以上のbの合計だけでhを超えられるなら、点数の低い順に抜いていく
if s>=h:
  while s>=h:
    #小さいやつを抜いていく
    s -= lisB.pop()
  cnt = len(lisB) + 1 
else:
  cnt = len(lisB) + math.ceil((h-s)/m)
  
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n = int(input())

q = deque()
for _ in range(n):
  num = int(input())
  if num in q:
    q.remove(num)
  else:
    q.append(num)
    
print(len(q))

Fixed submission:
import collections

n = int(input())
a = [int(input()) for _ in range(n)]
c = dict(collections.Counter(a))

ans = 0

for _,val in c.items():
  if val % 2 == 1:
    ans += 1
    
print(ans)
Buggy python submission (verdict: Runtime Error):
import collections

n = int(input())
a = list(map(int,input().split()))
c = dict(collections.Counter(a))

d1 = []
d2 = []
for num,v in c.items():
  if v >= 2:
    d1.append(num)
  if v >= 4:
    d2.append(num)
    
d1.sort()
d2.sort()

if d2:
  ans = max(d2[-1]**2, d1[-1]*d1[-2])
  print(ans)
else:
  print(d1[-1]*d1[-2])
  



Fixed submission:
import collections

n = int(input())
a = list(map(int,input().split()))
c = dict(collections.Counter(a))

d1 = []
d2 = []
for num,v in c.items():
  if v >= 2:
    d1.append(num)
  if v >= 4:
    d2.append(num)
    
d1.sort()
d2.sort()

if d2:
  ans = max(d2[-1]**2, d1[-1]*d1[-2])
  print(ans)
else:
  if len(d1)>=2:
    print(d1[-1]*d1[-2])
  else:
    print(0)
Buggy python submission (verdict: Runtime Error):
n = int(input())
t = [int(input()) for _ in [0]*n]

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

def lcm(x, y):
  return x * y // gcd (x, y)

ans = lcm(t[0],t[1])
if n>=3:
  for i in range(2,n):
    ans = lcm(ans,t[i])
    
print(ans)    

Fixed submission:
n = int(input())
t = [int(input()) for _ in [0]*n]

if n==1:
  print(t[0])
  exit()
  
def gcd(x, y):
	while y:
		x, y = y, x % y
	return x

def lcm(x, y):
  return x * y // gcd (x, y)

ans = lcm(t[0],t[1])
if n>=3:
  for i in range(2,n):
    ans = lcm(ans,t[i])
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))

b = []
for num in a:
  b += [str(num)]
  b = b[::-1]

print(" ".join(b))  

Fixed submission:
from collections import deque

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

b = deque()
if n%2 == 0:
  for i in range(n):
    if i%2 == 0:
      b.append(a[i])
    else:
      b.appendleft(a[i])
else:
  for i in range(n):
    if i%2 == 1:
      b.append(a[i])
    else:
      b.appendleft(a[i])
    
b = list(b)    

for i in range(n):
  print(b[i], end=" ")
Buggy python submission (verdict: Runtime Error):
import numpy as np
n,k = map(int,input().split())
c = [0] * (10**5+1)
for _ in range(n):
  a,b = map(int,input().split())
  c[a] += b

A = np.array(c,dtype=np.int32)
A = A.cumsum()
answer = (A >= k).nonzero()[0].min()
print(answer)

Fixed submission:
import numpy as np
n,k = map(int,input().split())
c = [0] * (10**5+1)
for _ in range(n):
  a,b = map(int,input().split())
  c[a] += b

A = np.array(c,dtype=np.int64)
A = A.cumsum()
answer = (A >= k).nonzero()[0].min()
print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
n = int(input())
a = list(map(int,input().split()))
a.sort()
#print(a)[1, 2, 7, 20, 30, 40]
A = list(itertools.accumulate(a))
#print(A)
cnt = 1
for i in range(n-1):
  s = A[i]
  #print(s)
  for j in range(i+1,n):
    if s*2 >= a[j] :
      s += a[j]
      #print(s)
    else:
      break
  if s == A[-1]:
    cnt += 1
print(cnt)    
      
    
    


Fixed submission:
import itertools
n = int(input())
a = list(map(int,input().split()))
a.sort()
#print(a)[1, 2, 7, 20, 30, 40]
A = list(itertools.accumulate(a))
#print(A)[1, 3, 10, 30, 60, 100]
cnt = 0
for i in range(n-1):
  s = A[i]
  #この条件を満たしていないとそれ以上他のスライムを取り込めない
  if s*2 < a[i+1] :
    cnt = i+1

print(n-cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
a.sort()
cnt = 1
for i in range(n-1):
  s = sum(a[:i+1])
  #print(s)
  for j in range(i+1,n):
    if s*2 >= a[j] :
      s += a[j]
      #print(s)
    else:
      break
  if s == sum(a):
    cnt += 1
print(cnt)

Fixed submission:
import itertools
n = int(input())
a = list(map(int,input().split()))
a.sort()
#print(a)[1, 2, 7, 20, 30, 40]
A = list(itertools.accumulate(a))
#print(A)[1, 3, 10, 30, 60, 100]
cnt = 0
for i in range(n-1):
  s = A[i]
  #この条件を満たしていないとそれ以上他のスライムを取り込めない
  if s*2 < a[i+1] :
    cnt = i+1

print(n-cnt)
Buggy python submission (verdict: Time Limit Exceeded):
K,S = map(int,input().split())
cnt = 0
for i in range(K+1):
  for j in range(K+1):
    for k in range(K+1):
      if i + j + k == S:
        cnt += 1
print(cnt)        

Fixed submission:
K,S = map(int,input().split())
cnt = 0
for i in range(K+1):
  for j in range(K+1):
    if S - i - j <= K and S - i - j >= 0:
      cnt += 1
print(cnt)
Buggy python submission (verdict: Runtime Error):
n = int(input())
t = list(map(int,input().split()))
m = int(input())
PX = [list(map(int,input().split())) for _ in range(m)]
ans = 10**7
s1 = sum(t)
for i in range(m):
  s2 = s1 - t[PX[i][0]] + PX[i][1]
  ans = min(ans,s2)                         
print(ans)  

Fixed submission:
n = int(input())
t = list(map(int,input().split()))
m = int(input())
PX = [list(map(int,input().split())) for _ in range(m)]
s = sum(t)
for i in range(m):
  ans = s - t[PX[i][0]-1] + PX[i][1]   
  print(ans)
Buggy python submission (verdict: Runtime Error):
S = input()
print(S[0],S[1]) 
cnt = len(S) - 1 #数字の間の数
 
ans = 0
 
for i in range(2 ** cnt):
  sign = [""] * cnt
  for j in range(cnt):
    if ((i>>j)&1):
      sign[j] = "+"
            
  formula = ""      
  for k in range(cnt):
    formula += S[k] + sign[k]
    print(sign)
  formula += S[cnt]
  print(formula,i)       
  ans += eval(formula)
print(ans)

Fixed submission:
S = input()
 
cnt = len(S) - 1 #数字の間の数
 
ans = 0
 
for i in range(2 ** cnt):
  sign = [""] * cnt
  for j in range(cnt):
    if ((i>>j)&1):
      sign[j] = "+"
            
  formula = ""      
  for k in range(cnt):
    formula += S[k] + sign[k]
  formula += S[cnt]   
  ans += eval(formula)
print(ans)
Buggy python submission (verdict: Runtime Error):
n, a = map(int, input().split())
x = list(map(int, input().split()))

#aとの差を記録してリストに入れなおす
x = list(map(lambda i: i-a, x))
#print(x)

#dp初期値
dp = {0: 1}

#dpにぶち込む値をxから取り出す
for num in x:
  #dpにあるすべてのkey,valueに対して、すでにdpにkeyがi+kのデータがあればそのvalueなければ,0を返し、それ+vをdpとする。
  for k,v in list(dp.items()):
    dp[i+k]=dp.get(i+k,0)+v
    
  #print(dp)
#全部使わない選択肢だけ引いておく  
print(dp[0]-1)
#print(dp)

Fixed submission:
n, a = map(int, input().split())
x = list(map(int, input().split()))

#aとの差を記録してリストに入れなおす
x = list(map(lambda i: i-a, x))
#print(x)

#dp初期値
dp = {0: 1}

#dpにぶち込む値をxから取り出す
for num in x:
  #dpにあるすべてのkey,valueに対して、すでにdpにkeyがi+kのデータがあればそのvalueなければ,0を返し、それ+vをdpとする。
  for k,v in list(dp.items()):
    dp[num+k]=dp.get(num+k,0)+v
    
  #print(dp)
#全部使わない選択肢だけ引いておく  
print(dp[0]-1)
#print(dp)
Buggy python submission (verdict: Time Limit Exceeded):
from operator import itemgetter
from collections import defaultdict
N = int(input())
A = [int(v) for v in input().split()]
cnt = 0
left_list = [i + a for i, a in enumerate(A, 1)]
right_list = [i - a for i, a in enumerate(A, 1)]
right_dict = defaultdict(set)
for i, right in enumerate(right_list, 1):
    right_dict[right].add(i)
for i, left in enumerate(left_list, 1):
    pair_num = len(right_dict[left] - set([i]))
    cnt += pair_num
print(cnt)

Fixed submission:
from operator import itemgetter
from collections import defaultdict
N = int(input())
A = [int(v) for v in input().split()]
cnt = 0
left_list = [i + a for i, a in enumerate(A, 1)]
right_list = [i - a for i, a in enumerate(A, 1)]
right_dict = defaultdict(set)
for i, right in enumerate(right_list, 1):
    right_dict[right].add(i)
for i, left in enumerate(left_list, 1):
    pair_num = len(right_dict[left])
    cnt += pair_num
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

n = sys.stdin.readline()
l = list(map(int, sys.stdin.readline().split()))
tmp = 1000000000000000000

ans = 1
for i in l:
    if i == 0:
        ans = 0
        break

    ans *= i

if ans <= 1000000000000000000:
    print(ans)
else:
    print(-1)


Fixed submission:
import sys

n = sys.stdin.readline()
l = list(map(int, sys.stdin.readline().split()))
tmp = 1000000000000000000

if 0 in l:
    print(0)
else:
    ans = 1
    for i in l:
        ans *= i
        if 1000000000000000000 < ans:
            break
    if ans <= 1000000000000000000:
        print(ans)
    else:
        print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
m = input()
l = list(map(int, input().split()))
ans = 1
tmp = 1000000000000000000
for i in l:
    ans *= i

if ans <= tmp:
    print(ans)
else:
    print(-1)

Fixed submission:
import sys

n = sys.stdin.readline()
l = list(map(int, sys.stdin.readline().split()))
tmp = 1000000000000000000

if 0 in l:
    print(0)
else:
    ans = 1
    for i in l:
        ans *= i
        if 1000000000000000000 < ans:
            break
    if ans <= 1000000000000000000:
        print(ans)
    else:
        print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
m = input()
l = list(map(int, input().split()))
ans = 1
tmp = pow(10, 18)
for i in l:
    ans *= i

if ans <= tmp:
    print(ans)
else:
    print(-1)

Fixed submission:
import sys

n = sys.stdin.readline()
l = list(map(int, sys.stdin.readline().split()))
tmp = 1000000000000000000

if 0 in l:
    print(0)
else:
    ans = 1
    for i in l:
        ans *= i
        if 1000000000000000000 < ans:
            break
    if ans <= 1000000000000000000:
        print(ans)
    else:
        print(-1)
Buggy python submission (verdict: Runtime Error):
import math
a, b = map(int, input().split())
print(int(a * b / math.gcd(a, b)))


Fixed submission:
from fractions import gcd

a, b = map(int, input().split())
print(int(a * b / gcd(a, b)))
Buggy python submission (verdict: Runtime Error):
A,B,C = map(int,input().split())
if A % 2 == 0 or B % 2 == 0 or C % 2 == 0:
	print(0)
	return
S = A * B * C
mi = min(A,min(B,C))
ma = max(A,max(B,C))
mid = S // ma // mi // 2
ans = ma * mi * mid
print(abs(S - ans * 2))

Fixed submission:
A,B,C = map(int,input().split())
if A % 2 == 0 or B % 2 == 0 or C % 2 == 0:
	print(0)
else:
	S = A * B * C
	mi = min(A,min(B,C))
	ma = max(A,max(B,C))
	mid = S // ma // mi
	ma //= 2
	ans = ma * mi * mid
	print(abs(S - ans * 2))
Buggy python submission (verdict: Time Limit Exceeded):
import math
num = int(input())
count = 0
for a in range(1,num+1):
    for b in range(1,num+1):
        for c in range(1,num+1):
            temp = math.gcd(a,b)
            count += math.gcd(temp,c)
print(count)

Fixed submission:
import math
num = int(input())
count = 0
for a in range(1,num+1):
    for b in range(1,num+1):
        temp = math.gcd(a,b)
        for c in range(1,num+1):
            count += math.gcd(temp,c)
print(count)
Buggy python submission (verdict: Runtime Error):
X,Y,Z = map(int,input())
print(Z,X,Y)

Fixed submission:
X,Y,Z = map(int,input().split())
print(Z,X,Y)
Buggy python submission (verdict: Time Limit Exceeded):
data  = [int(_) for _ in input().split()]
enemy = [int(_) for _ in input().split()]
#print(type(enemy))
#print(enemy)

if len(enemy) < data[1]:
    print(0)
    exit()

for _ in range(data[1]):
#    print(enemy)
    enemy.remove(max(enemy))
#print(enemy)

print(sum(enemy))

Fixed submission:
data  = [int(_) for _ in input().split()]
enemy = [int(_) for _ in input().split()]

if len(enemy) < data[1]:
    print(0)
    exit()
elif data[1] == 0:
    print(sum(enemy))
else:
    enemy.sort()
    
    print(sum(enemy[:-data[1]]))
Buggy python submission (verdict: Runtime Error):
num = int(input())
Flag = False
for x in range(1,10):
    for y in range(x,10):
        if x * y == num:
            Flag = True
            break
    if Flag == True:
        break

if Flag:
    print("Yes")
else:
    print("No")


Fixed submission:
num = [int(_) for _ in input().split(" ")]
if 0<num[0]<10 and 0<num[1]<10:
  print(num[0]*num[1])
else:
  print(-1)

Buggy python submission (verdict: Runtime Error):
num = int(input())
Flag = False
for x in range(2,10):
    for y in range(x,10):
        print("x"+str(x)+":y"+str(y))
        if x * y == num:
            Flag = True
            break
    if Flag == True:
        break

if Flag:
    print("Yes")
else:
    print("No")


Fixed submission:
num = [int(_) for _ in input().split(" ")]
if 0<num[0]<10 and 0<num[1]<10:
  print(num[0]*num[1])
else:
  print(-1)

Buggy python submission (verdict: Runtime Error):
num = int(input())
Flag = True
for x in range(2,10):
  if num % x == 0:
    Flag = False
    break
if flag:
  print("NO")
else:
  print("YES")


Fixed submission:
num = [int(_) for _ in input().split(" ")]
if 0<num[0]<10 and 0<num[1]<10:
  print(num[0]*num[1])
else:
  print(-1)

Buggy python submission (verdict: Runtime Error):
_ = input().split(" ")
if 0<_[0]<10 and 0<_[1]<10:
  print(_[0]*_[1])
else:
  print(-1)

Fixed submission:
num = [int(_) for _ in input().split(" ")]
if 0<num[0]<10 and 0<num[1]<10:
  print(num[0]*num[1])
else:
  print(-1)
Buggy python submission (verdict: Runtime Error):
num = int(input())
Flag = True
for x in range(2,10):
  if num % x == 0:
    Flag = False
    break
if flag:
  print("NO")
else:
  print("YES")

Fixed submission:
num = int(input())
Flag = False
for x in range(1,10):
  for y in range(x,10):
    if x * y == num:
      Flag = True
      break
    if Flag == True:
      break

if Flag:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
num = int(input())
flag = True
for x in range(2,10):
  if num % x == 0:
    print("YES")
	flag = False
if flag:
  print("NO")


Fixed submission:
num = int(input())
Flag = False
for x in range(1,10):
  for y in range(x,10):
    if x * y == num:
      Flag = True
      break
    if Flag == True:
      break

if Flag:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
num = int(input())
flag = True
for _ in range(2,10):
  if num % _ == 0:
    print("YES")
	flag = False
if flag:
  print("NO")

Fixed submission:
num = int(input())
Flag = False
for x in range(1,10):
  for y in range(x,10):
    if x * y == num:
      Flag = True
      break
    if Flag == True:
      break

if Flag:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
data = [int(x) for x in input().split(" ")]
print(max(sum(data),data[0]-data[1],data[0]*data[1])

Fixed submission:
data = [int(x) for x in input().split(" ")]
print(max(sum(data),data[0]-data[1],data[0]*data[1]))
Buggy python submission (verdict: Time Limit Exceeded):
num = int(input())
data = [int(input()) for _ in range(num)]

for i in range(num):
    print(max((data[0:i])+(data[i+1:num])))

Fixed submission:
"""
N = list(map(int,input().split()))
S = [str(input()) for _ in range(N)]
S = [list(map(int,list(input()))) for _ in range(h)] 
print(*S,sep="")
"""

import sys
sys.setrecursionlimit(10**6)
input = lambda: sys.stdin.readline().rstrip()
inf = float("inf") # 無限

n = int(input())
a = []

for _ in range(n):
    var = int(input())
    a.append(var)

first = int(max(a))
if 1<a.count(first):
    second = int(first)
else:
    second = sorted(set(a))[-2]

for _ in a[:]:
    if _ == first:
        print(second)
    else:
        print(first)

Buggy python submission (verdict: Time Limit Exceeded):
num = int(input())
data = []
for i in range(num):
    data.append(int(input()))
for i in range(num):
    print(max((data[0:i])+(data[i+1:num])))

Fixed submission:
"""
N = list(map(int,input().split()))
S = [str(input()) for _ in range(N)]
S = [list(map(int,list(input()))) for _ in range(h)] 
print(*S,sep="")
"""

import sys
sys.setrecursionlimit(10**6)
input = lambda: sys.stdin.readline().rstrip()
inf = float("inf") # 無限

n = int(input())
a = []

for _ in range(n):
    var = int(input())
    a.append(var)

first = int(max(a))
if 1<a.count(first):
    second = int(first)
else:
    second = sorted(set(a))[-2]

for _ in a[:]:
    if _ == first:
        print(second)
    else:
        print(first)

Buggy python submission (verdict: Time Limit Exceeded):
num = int(input())
data = []
for i in range(num):
    tmp = int(input())
    data.append(tmp)
for i in range(num):
    tmp = (data[0:i])+(data[i+1:num])
    print(max(tmp))

Fixed submission:
"""
N = list(map(int,input().split()))
S = [str(input()) for _ in range(N)]
S = [list(map(int,list(input()))) for _ in range(h)] 
print(*S,sep="")
"""

import sys
sys.setrecursionlimit(10**6)
input = lambda: sys.stdin.readline().rstrip()
inf = float("inf") # 無限

n = int(input())
a = []

for _ in range(n):
    var = int(input())
    a.append(var)

first = int(max(a))
if 1<a.count(first):
    second = int(first)
else:
    second = sorted(set(a))[-2]

for _ in a[:]:
    if _ == first:
        print(second)
    else:
        print(first)
Buggy python submission (verdict: Runtime Error):
X = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors
  
for k in yakusu:
    hani = int(math.log(X/k)) + 1
    for A in range(-1000, 1000):
        B = A-k
        if A**4 + (A**3)*B + (A**2)*(B**2) + A*(B**3) + B**4 == X/k:
            print(A, B)
            break

Fixed submission:
X = int(input())
 
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
 
    # divisors.sort()
    return divisors

yakusu = make_divisors(X)
for k in yakusu:
    for A in range(-1000, 1000):
        B = A-k
        if A**4 + (A**3)*B + (A**2)*(B**2) + A*(B**3) + B**4 == X/k:
            print(A, B)
            break
Buggy python submission (verdict: Runtime Error):
from itertools import product

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

A = [0, 1]
combnation = list(product(A, repeat=Q))
abcd.sort()

ans = 0
for comb in combnation:
    print(comb)
    comb_list = [abcd[i] for i, k in enumerate(comb) if k==1]
    check = True
    A = [0 for i in range(N+1)]
    amount = 0
    for a, b, c, d in comb_list:
        amount += d
        if A[a] == 0 and A[b] == 0:
            if A[a] == 0 and A[b] == 0:
                A[a] = 1
                A[b] = 1 + c
    
        elif A[a] == 0 and A[b] != 0:
            if A[b] - c >= 1:
                A[a] = A[b] - c
            else:
                check = False
                break
    
        elif A[a] != 0 and A[b] == 0:
            if c + A[a] <= M:
                A[b] = A[a] + c
            else:
                check = False
                break
        else:
            if A[b] - A[a] != c:
                check = False
                break
    
    if check and amount > ans:
        ans = amount
print(ans)

Fixed submission:
import math
A, B, N = map(int, input().split())

if N < B:
    if N % B == 0:
        x = N-1
    else:
        x = N

else:
    if N % B == 0:
        x = B-1
    else:
        x = B-1

ans = math.modf((x/B))[0]*A
print(int(ans))

Buggy python submission (verdict: Runtime Error):
A, B, N = map(int, input().split())

if N < B:
    if N % B == 0:
        x = N-1
    else:
        x = N
        ans = math.modf((N/B))[0]*A

else:
    if N % B == 0:
        x = (N-1)%B
    else:
        x = N%B

ans = math.modf((x/B))[0]*A
print(int(ans))

Fixed submission:
import math
A, B, N = map(int, input().split())

if N < B:
    if N % B == 0:
        x = N-1
    else:
        x = N

else:
    if N % B == 0:
        x = B-1
    else:
        x = B-1

ans = math.modf((x/B))[0]*A
print(int(ans))