Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(input()) for i in range(n)]

# ほとんどは全体のmax?
m1 = max(a)

# max値が多い場合用に2nd max
a2 = list(set(a))
a2.remove(m1)
m2 = max(a2)

for i in range(n):
  if a[i] == m1:
    print(m2)
  elif a[i] == m2:
    print(max(a[:i]+a[i+1:]))
  else:
    print(m1)

Fixed submission:
n = int(input())
a = [int(input()) for i in range(n)]

# ほとんどは全体のmax?
m1 = max(a)

# max値が多い場合用に2nd max
m2 = sorted(a)[n-2]

for i in range(n):
  if a[i] == m1:
    print(m2)
  else:
    print(m1)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(input()) for i in range(n)]

# ほとんどは全体のmax?
m = max(a)
p = a.index(m)

for i in range(n):
  if i == p or a[i] == m:
    print(max(a[:i]+a[i+1:]))
  else:
    print(m)

Fixed submission:
n = int(input())
a = [int(input()) for i in range(n)]

# ほとんどは全体のmax?
m1 = max(a)

# max値が多い場合用に2nd max
m2 = sorted(a)[n-2]

for i in range(n):
  if a[i] == m1:
    print(m2)
  else:
    print(m1)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(input()) for i in range(n)]

# ほとんどは全体のmax
m = max(a)

for i in range(n):
  if a[i] == m:
    print(max(a[:i]+a[i+1:]))
  else:
    print(m)

Fixed submission:
n = int(input())
a = [int(input()) for i in range(n)]

# ほとんどは全体のmax?
m1 = max(a)

# max値が多い場合用に2nd max
m2 = sorted(a)[n-2]

for i in range(n):
  if a[i] == m1:
    print(m2)
  else:
    print(m1)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(input()) for i in range(n)]

# i-1までのmaxはキャッシュする
m1 = 0
for i in range(n):
  p = a[i - 1]
  if i != 0:
    if m1 < p:
      m1 = p
  
  if i != n - 1:
    c = a[i + 1:]
    cm = max(c)
    if m1 < cm:
      print(cm)
    else:
      print(m1)
  else:
    print(m1)
  
  """
  # 遅すぎる
  b = a.copy()
  del b[i]
  print(max(b))
  # 遅すぎる2
  b = a[0:i]
  c = a[i+1:]
  b += c
  print(max(b))
  """

Fixed submission:
n = int(input())
a = [int(input()) for i in range(n)]

# ほとんどは全体のmax?
m1 = max(a)

# max値が多い場合用に2nd max
m2 = sorted(a)[n-2]

for i in range(n):
  if a[i] == m1:
    print(m2)
  else:
    print(m1)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(input()) for i in range(n)]

for i in range(n):
  b = a[0:i]
  c = a[i+1:]
  if len(b) > 0:
    b = max(b)
  else:
    b = 0
  if len(c) > 0:
    c = max(c)
  else:
    c = 0

  if b > c:
    print(b)
  else:
    print(c)
  """
  # 遅すぎる
  b = a.copy()
  del b[i]
  print(max(b))
  # 遅すぎる2
  b = a[0:i]
  c = a[i+1:]
  b += c
  print(max(b))
  """

Fixed submission:
n = int(input())
a = [int(input()) for i in range(n)]

# ほとんどは全体のmax?
m1 = max(a)

# max値が多い場合用に2nd max
m2 = sorted(a)[n-2]

for i in range(n):
  if a[i] == m1:
    print(m2)
  else:
    print(m1)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(input()) for i in range(n)]

for i in range(n):
  b = a[0:i]
  c = a[i+1:]
  b += c
  print(max(b))
  """
  # 遅すぎる
  b = a.copy()
  del b[i]
  print(max(b))
  """

Fixed submission:
n = int(input())
a = [int(input()) for i in range(n)]

# ほとんどは全体のmax?
m1 = max(a)

# max値が多い場合用に2nd max
m2 = sorted(a)[n-2]

for i in range(n):
  if a[i] == m1:
    print(m2)
  else:
    print(m1)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(input()) for i in range(n)]

for i in range(n):
  b = a.copy()
  del b[i]
  print(max(b))

Fixed submission:
n = int(input())
a = [int(input()) for i in range(n)]

# ほとんどは全体のmax?
m1 = max(a)

# max値が多い場合用に2nd max
m2 = sorted(a)[n-2]

for i in range(n):
  if a[i] == m1:
    print(m2)
  else:
    print(m1)