Problem:


Score : 300 points

Problem Statement

You are given a sequence of length N: A_1, A_2, ..., A_N.
For each integer i between 1 and N (inclusive), answer the following question:

Find the maximum value among the N-1 elements other than A_i in the sequence.

Constraints

2 \leq N \leq 200000

1 \leq A_i \leq 200000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1
:
A_N

Output

Print N lines. The i-th line (1 \leq i \leq N) should contain the maximum value among the N-1 elements other than A_i in the sequence.

Sample Input 1

3
1
4
3

Sample Output 1

4
3
4

The maximum value among the two elements other than A_1, that is, A_2 = 4 and A_3 = 3, is 4.

The maximum value among the two elements other than A_2, that is, A_1 = 1 and A_3 = 3, is 3.

The maximum value among the two elements other than A_3, that is, A_1 = 1 and A_2 = 4, is 4.

Sample Input 2

2
5
5

Sample Output 2

5
5



Sample input:
3
1
4
3


Sample output:
4
3
4

Submission status: Time Limit Exceeded

Solution code:
from enum import Enum
from queue import Queue
import collections

import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = [int(input()) for i in range(n)]
m = max(l)
for i in l:
    if i == m:
        la = l[:]
        la.remove(i)
        print(max(la))
    else:
        print(m)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
 
 
left_max = [-1] * N
right_max = [0]
all = sum(A)
left_max[0] = A[0]
right_max[0] = A[-1]
for i in range(1, N):
        left_max[i] = max(left_max[i-1], A[i])
for i in reversed(range(0, N-1)):
        right_max.insert(0, max(right_max[0], A[i]))
 
 
print(right_max[1])
for i in range(1,N-1):
        print(max(left_max[i-1], right_max[i+1]))
print(left_max[-2])

Submission status: Time Limit Exceeded

Solution code:
import copy

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

for i in range(N):
    tmp = copy.deepcopy(A)
    tmp[i] = 0
    print(max(tmp))

Submission status: Time Limit Exceeded

Solution code:
def loop(n, a):
    for i in range(n):
        temp = a[i]
        a[i] = 0
        print(max(a))
        a[i] = temp
    

n = int(input())
a = [int(input()) for i in range(n)]
 
loop(n, a)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
 
for i in range(n):
  temp = a[i]
  a[i] = 0
  print(max(a))
  a[i] = temp

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[0 for i in range(n)]
for i in range(n):
	a[i]=int(input())



for i in range(n):
	max=0
	maxno=0
	for e in range(n):
		if e!=i:
			if a[e]>=max:
				max=a[e]
				maxno=e
	print(max)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]

for i in range(n):
  temp = a[i]
  a[i] = 0
  print(max(a))
  a[i] = temp

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = []
for i in range(N):
  a.append(int(input()))

for i in range(N):
  b = a[:]
  b.pop(i)
  print(max(b))

Submission status: Time Limit Exceeded

Solution code:
import copy

n = input("")
n = int(n)
suuaray = []
for i in range(n):
    num = input("")
    num = int(num)
    suuaray.append(num)

max_value = max(suuaray)
max_index = [i for i, x in enumerate(suuaray) if x == max_value]

suuaray.remove(max_value)
second_value = max(suuaray)

ans = []
for i in range(n):
    if i not in max_index:
        ans.append(max_value)
    else:
        ans.append(second_value)

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

Submission status: Time Limit Exceeded

Solution code:
import copy

n = input("")
n = int(n)
suuaray = []
for i in range(n):
    num = input("")
    num = int(num)
    suuaray.append(num)

for i in range(n):
    suuaray2 = copy.copy(suuaray)
    suuaray2.remove(suuaray2[i])
    print(max(suuaray2))

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
ar = [int(input()) for i in range(a)]
br = sorted(ar)
for r in ar:
    if r == max(ar):
        print(br[-2])
    else:
        print(max(ar))

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
ar = [int(input()) for i in range(a)]
for i in range(a):
    b = ar[i]
    del ar[i]
    print(max(ar))
    ar.insert(i,b)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = []
mx=0
for i in range(N):
    A.append(int(input()))


if A.count(max(A)) > 1:
    for i in range(N):
        print(max(A))
else:
    for i in range(N):
        if A[i] != max(A):
            print(max(A))
        else:
            print(sorted(A)[-2])

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
a=[]
for i in  range(N):
	a.append(int(input()))
for i in range(N):
	b=[]
	b.extend(a)
	b.pop(i)
	print(max(b))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = [int(input()) for _ in range(n)]
l = []

for i in range(n):
    for j in range(n):
        if i != j:
            l.append(A[j])
    print(max(l))
    l.clear()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = []
for i in range(N):
    a.append(int(input()))

for i in range(N):
    tmp,a[i] = a[i],0
    print(max(a))
    a[i] = tmp

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

for i in range(N):
	ans = max(A[:i] + A[i+1:])
	print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(input()) for _ in range(n)]
for i in range(n):
  p=a[::]
  p.pop(i)
  print(max(p))

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    A = []
    for n in range(N):
        A.append(int(input()))

    max1_A = max(A)
    A_cp = sorted(A)
    A_cp.pop(-1)
    max2_A = max(A_cp)
    argmax_A = [i for i, x in enumerate(A) if x == max(A)]

    for a in A:
        if a == max1_A:
            print(max2_A)
        else:
            print(max1_A)
            
        
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    A = []
    for n in range(N):
        A.append(int(input()))

    max_A = max(A)
    argmax_A = [i for i, x in enumerate(A) if x == max(A)]
    if len(argmax_A) == 1:
        for n in range(N):
            if n in argmax_A:
                tmp = A.pop(n)
                print(max(A))
                A.insert(n, tmp)
            else:
                print(max_A)
    else:
        for n in range(N):
            print(max_A)
        
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    A = []
    for n in range(N):
        A.append(int(input()))
        
    for n in range(N):
        tmp = A.pop(n)
        print(max(A))
        A.insert(n, tmp)
        
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import copy
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))

for i in range(n):
    b = copy.deepcopy(a)
    b.pop(i)
    b.sort()
    print(b[-1])

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
import copy
a = int(input());
b = [int(input()) for i in range(a)];
c = 0;
first = max(b);
g = b.copy();
h = g.index(first);
del g[h];
second = max(g);

for i in range(a):
    if max(b) > b[i]:
        print(first);
    elif first == b[i]:
        print(second);

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

n = int(input())
data = [int(input()) for k in range(n)]
for i in range(n):
	data2 = data.copy()
	data2[i] = 0
	data2.sort()
	print(data2[-1])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
inputs = [int(input()) for _ in range(N)]

for i in range(N):
    sorted_inputs = sorted(inputs, reverse=True)
    if sorted_inputs[0] == inputs[i]:
        print(sorted_inputs[1])
    else:
        print(sorted_inputs[0])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

for i in range(n):
    print(max(max(a[:i],a[i+1:])))

Submission status: Time Limit Exceeded

Solution code:
init_seq = []
length = int(input())
def seq_f():
  for n in range(length):
      num = int(input())
      init_seq.append(num)
  return init_seq
init_seq = seq_f()
for n in range(length):
    seq = init_seq[:]
    del seq[n]
    print(max(set(seq)))

Submission status: Time Limit Exceeded

Solution code:
N = int(input() )
lst=[ int(input()) for n in range(N)]

for n in range(N):
    print( max([ lst[i] for i in range(N) if i != n ] ))

Submission status: Time Limit Exceeded

Solution code:
init_seq = []
length = int(input())
def seq_f():
  for n in range(length):
      num = int(input())
      init_seq.append(num)
  return init_seq
init_seq = seq_f()
for n in range(length):
    seq = init_seq[:]
    del seq[n]
    seq = list(set(seq))
    seq.sort()
    print(seq[-1])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
a =  [int(input()) for i in range(n)]
b = set(a)
c = max(b)
for i in range(n):
  if a[i] != c:
    print(c)
  else:
    print(int(max(np.concatenate([a[:i], a[i+1:]]))))

Submission status: Time Limit Exceeded

Solution code:
init_seq = []
length = int(input())
def seq_f():
  for n in range(length):
      num = int(input())
      init_seq.append(num)
  return init_seq
index = 0
init_seq = seq_f()
for n in range(length):
    seq = init_seq[:]
    del seq[index]
    seq.sort()
    print(seq[-1])
    index += 1

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
a =  [int(input()) for i in range(n)]



[print(int(max(set(np.concatenate([a[:i], a[i+1:]]))))) for i in range(n)]

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

n = int(input())

a = list()
for i in range(n):
    a.append(int(input()))

a_sorted = sorted(a, reverse=True)

for i in range(n):
    index = a_sorted.index(a[i])
    if a[i] == a_sorted[0]:
        print(a_sorted[1])
        continue

    print(a_sorted[0])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
a =  [int(input()) for i in range(n)]

[print(int(max(np.concatenate([a[:i], a[i+1:]])))) for i in range(n)]

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
a =  [int(input()) for i in range(n)]

for i in range(n):
  print(int(max(np.concatenate([a[:i], a[i+1:]]))))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a =  [int(input()) for i in range(n)]

for i in range(n):
  b = a.copy()
  b.pop(i)
  print(max(b))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
for i in range(n):
  b = a.copy()
  b.pop(i)
  print(max(b))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = []
for i in range(N):
        x = int(input())
        a.append(x)

for i in range(N):
        b = []
        for j in range(N):
                if i == j: continue
                b.append(a[j])
        print(max(b))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=[]
for i in range(n):
    l.append(int(input()))
ll=l[:]
for j in range(len(l)):
    l=ll[:]
    l.pop(j)
    print(max(l))

Submission status: Time Limit Exceeded

Solution code:

n = int(input())
data = [int(input()) for k in range(n)]
for i in range(n):
	data2 = data.copy()
	data2[i] = 0
	data2.sort()
	print(data2[-1])

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[int(input()) for i in range(N)]
for i in range(N):
  if i==0:
    print(sorted(A[i+1:])[-1])
  if i!=0 and i!=N-1:
    li1=sorted(A[:i])[-1]
    li2=sorted(A[i+1:])[-1]
    print(max(li1,li2))
  if i==N-1:
    print(sorted(A[:i])[-1])

Submission status: Time Limit Exceeded

Solution code:
# def s(i) :
# 	p = data
# 	p[i] = 0
# 	p.sort()
# 	print(p[-1])


n = int(input())
data = [int(input()) for k in range(n)]
for i in range(n):
	data2 = data[:]
	data2[i] = 0
	data2.sort()
	print(data2[-1])
	# s = data
	# s[i] = 0
	# s.sort()
	# print(s[-1])
	# print(s)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import sys
# import bisect
# import math
import numpy as np
# from fractions import gcd
# import itertools

"""Template"""


class IP:
    """
    入力を取得するクラス
    """
    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        # 参考
        # https://blog.rossywhite.com/2018/08/06/bit-search/
        # https://atcoder.jp/contests/abc105/submissions/4088632
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    # output.append(a[j])
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x//y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

    def gcd(self, x, y):
        if y == 0:
            return x
        else:
            return self.gcd(y, x % y)

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


"""ここからメインコード"""


def main():
    # 1文字に省略
    r, e = range, enumerate
    ip = IP()
    id = Idea()
    """この下から書いてね"""
    n = ip.I()
    a = np.array(ip.ILS(n))
    memo = np.ones(n, dtype=bool)
    for i in range(n):
        memo[:] = True
        memo[i] = False
        print(np.max(a[memo]))


main()

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import sys
# import bisect
# import math
import numpy as np
# from fractions import gcd
# import itertools

"""Template"""


class IP:
    """
    入力を取得するクラス
    """
    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        # 参考
        # https://blog.rossywhite.com/2018/08/06/bit-search/
        # https://atcoder.jp/contests/abc105/submissions/4088632
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    # output.append(a[j])
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x//y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

    def gcd(self, x, y):
        if y == 0:
            return x
        else:
            return self.gcd(y, x % y)

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


"""ここからメインコード"""


def main():
    # 1文字に省略
    r, e = range, enumerate
    ip = IP()
    id = Idea()
    """この下から書いてね"""
    n = ip.I()
    a = np.array(ip.ILS(n))

    for i in range(n):
        memo = np.ones(n, dtype=bool)
        memo[i] = False
        print(np.max(a[memo]))


main()

Submission status: Time Limit Exceeded

Solution code:
A = [int(input()) for i in range(int(input()))]
max_A = max(A)
for i in A:
    if i == max_A:
        print(sorted(A)[-2])
    else:
        print(max_A)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(input()) for x in range(n)]
b = sorted(a,reverse=True)
for i in range(n):
    if max(a) == a[i]:
        print(b[1])
    else:
        print(b[0])

Submission status: Time Limit Exceeded

Solution code:


import numpy as np
N = int(input())
A=np.array([])
for i in range(N):
    A=np.append(A, int(input()) )

max_index=np.argmax(A)
a_max=int(A[max_index])
a_second=int(np.amax(np.delete(A,max_index)))
A[:]=a_max
A[max_index]=a_second
for a in A:
    print(int(a))

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import sys
# import bisect
# import math
# import numpy as np
# from fractions import gcd
# import itertools

"""Template"""


class IP:
    """
    入力を取得するクラス
    """
    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        # 参考
        # https://blog.rossywhite.com/2018/08/06/bit-search/
        # https://atcoder.jp/contests/abc105/submissions/4088632
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    # output.append(a[j])
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x//y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

    def gcd(self, x, y):
        if y == 0:
            return x
        else:
            return self.gcd(y, x % y)

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


"""ここからメインコード"""


def main():
    # 1文字に省略
    r, e = range, enumerate
    ip = IP()
    id = Idea()
    """この下から書いてね"""
    n = ip.I()
    a = ip.ILS(n)

    for i in range(n):
        # b.pop(i)
        memo = a[0:i] + a[i+1:]
        print(max(memo))


main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
l = []
for i in range(N):
    a = int(input())
    l.append(a)
 
cnt = 0
cnt2 = 0
for i in range(len(l)):
    nl = l
    cnt2 += nl[cnt]
    nl[cnt] = 0
    print(max(nl))
    nl[cnt] = cnt2
    cnt2 = 0
    cnt += 1

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = [int(input()) for i in range(N)]

b = sorted(a)
for i in range(N):
    if i == a.index(max(a)):
        print(b[-2])
    else:
        print(b[-1])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = [int(input()) for i in range(N)]

b = sorted(a)
for i in range(N):
    if i == a.index(max(a)):
        print(b[-2])
    else:
        print(b[-1])

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import sys
# import bisect
# import math
# import numpy as np
# from fractions import gcd
# import itertools

"""Template"""


class IP:
    """
    入力を取得するクラス
    """
    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        # 参考
        # https://blog.rossywhite.com/2018/08/06/bit-search/
        # https://atcoder.jp/contests/abc105/submissions/4088632
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    # output.append(a[j])
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x//y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

    def gcd(self, x, y):
        if y == 0:
            return x
        else:
            return self.gcd(y, x % y)

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


"""ここからメインコード"""


def main():
    # 1文字に省略
    r, e = range, enumerate
    ip = IP()
    id = Idea()
    """この下から書いてね"""
    n = ip.I()
    a = ip.ILS(n)

    for i in range(n):
        b = a.copy()
        b.pop(i)
        print(max(b))


main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(input()) for i in range(n)]
for _ in range(n):
  b=a[0:_]+a[_+1:n]
  print(max(b))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
A = np.array([input() for i in range(N)])

B = np.array([])
for i in range(N):
    print(max(np.delete(A.copy(), i)))

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = input()
    aa = []
    for _ in xrange(n):
        aa.append(input())
    bb = sorted(aa)
    b0, b1 = bb[-1], bb[-2]
    for a in aa:
        if a < b0:
            print b0
        else:
            print b1
 
 
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))
for j in range(N):
  m = 0
  for k in range(N):
    if k == j:
      continue
    if A[k] > m:
      m = A[k]
  print(m)