Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

#各都市に行くためのコスト
lift = [int(input()) for i in range(5)]
#各都市にいる人数
city = [0] * 6
city[0] = N

ans = 0
target = []

while 1:
    if city[5] == N:
        break
    for i in range(0,5):
        #今回の操作で動かすもの一覧を作る（i-1に値があるものだけ動かす)
        if city[i] != 0:
            target.append(i+1)
    for i in reversed(target):
        if city[i-1] >= lift[i-1]:
            city[i] += lift[i-1]
            city[i - 1] -= lift[i-1]
        else:
            city[i] += city[i-1]
            city[i-1] = 0
    target = []
    ans += 1
print(ans)

Fixed submission:
N = int(input())

#各都市に行くためのコスト
lift = [int(input()) for i in range(5)]
#各都市にいる人数
city = [0] * 6


print(int((N + min(lift) - 1)  / min(lift) + 4))
Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
s = input()

l = []
r = []

for i in range(q):
    l_tmp,r_tmp = map(int,input().split())
    tmp_s = s[l_tmp-1:r_tmp]
    print(tmp_s.count("AC"))

Fixed submission:
n,q = map(int,input().split())
s = input()


t = [0] * n
for i in range(n-1):
    if s[i] == "A" and s[i+1] == "C":
        t[i+1] = t[i] + 1
    else:
        t[i+1] = t[i]


for i in range(q):
    l, r = map(int,input().split())
    print(t[r-1] - t[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
s = input()

l = []
r = []

for i in range(q):
    l_tmp,r_tmp = map(int,input().split())
    l.append(l_tmp)
    r.append(r_tmp)


for i in range(q):
    tmp_s = s[l[i]-1:r[i]]
    print(tmp_s.count("AC"))


Fixed submission:
n,q = map(int,input().split())
s = input()


t = [0] * n
for i in range(n-1):
    if s[i] == "A" and s[i+1] == "C":
        t[i+1] = t[i] + 1
    else:
        t[i+1] = t[i]


for i in range(q):
    l, r = map(int,input().split())
    print(t[r-1] - t[l-1])
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
ans = 0

while(1):
    before = len(S)
    S = S.replace("01","")
    S = S.replace("10","")
    after = len(S)
    if before - after  == 0:
        break
    else:
        ans += before - after




print(ans)

Fixed submission:
S = input()

one = S.count("1")
zero = S.count("0")

print(min(one,zero)*2)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int,input().split())
h = list(map(int,input().split()))

dp = [float("inf")] * N
dp[0] = 0
dp[1] = abs(h[1] - h[0])

for i in range(2,N):
    for j in range(1,K+1):
        dp[i] = min(dp[i],dp[i-j] + abs(h[i] - h[i-j]))

print(dp[-1])

Fixed submission:
N, K = map(int,input().split())
h = list(map(int,input().split()))

dp = [float("inf")] * N
dp[0] = 0
dp[1] = abs(h[1] - h[0])

for i in range(2,N):
    for j in range(1,K+1):
        dp[i] = min(dp[i],dp[i-j] + abs(h[i] - h[i-j]))

print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int,input().split())

cost = [list(map(int,input().split())) for i in range(N)]
dp = [[0] * (W+1) for i in range(N)]


for i in range(N):
    for sum_w in range(0,W+1):
        if sum_w - cost[i][0] >= 0:
            dp[i][sum_w] = max(dp[i-1][sum_w], dp[i-1][sum_w - cost[i][0]] + cost[i][1])
        dp[i][sum_w] = max(dp[i][sum_w], dp[i-1][sum_w])

print(dp[N-1][W])

Fixed submission:
N, W = map(int,input().split())

cost = [list(map(int,input().split())) for i in range(N)]
dp = [[0] * (W+1) for i in range(N)]


for i in range(N):
    for sum_w in range(0,W+1):
        if sum_w - cost[i][0] >= 0:
            dp[i][sum_w] = max(dp[i-1][sum_w], dp[i-1][sum_w - cost[i][0]] + cost[i][1])
        dp[i][sum_w] = max(dp[i][sum_w], dp[i-1][sum_w])

print(dp[N-1][W])
Buggy python submission (verdict: Runtime Error):
N, W = map(int,input().split())

cost = [list(map(int,input().split())) for i in range(N)]
dp = [[0] * (W+1) for i in range(N)]


for i in range(N):
    for sum_w in range(0,W+1):
        if sum_w - cost[i][0] >= 0:
            dp[i][sum_w] = max(dp[i-1][sum_w], dp[i-1][sum_w - cost[i][0]] + cost[i][1])
        dp[i][sum_w] = max(dp[i][sum_w], dp[i-1][sum_w])

print(dp[N-1][W])

Fixed submission:
N, W = map(int,input().split())

cost = [list(map(int,input().split())) for i in range(N)]


dp = [[float('inf')] * (100001) for i in range(N)]


for i in range(N):
    for j in range(100001):
        if j == 0:
            dp[i][j] = 0

for i in range(N):
    for sum_v in range(0,100001):
        if sum_v - cost[i][1] >= 0:
            dp[i][sum_v] = min(dp[i-1][sum_v], dp[i-1][sum_v - cost[i][1]] + cost[i][0])
        dp[i][sum_v] = min(dp[i][sum_v], dp[i-1][sum_v])

ans = float('inf')

for j in range(0,100001):
    if dp[N-1][j] <= W:
        ans = j
print(ans)
Buggy python submission (verdict: Runtime Error):
N, M = map(int,input().split())
all_city = [list(map(int,input().split())) for i in range(M)]

city = {}
for i in all_city:
    if i[0] in city:
        city[i[0]].append(i[1])
    else:
        city[i[0]] = [i[1]]



for i,k in city.items():
    city[i] = sorted(k)

def change_Prefecture_code(prefecture):
    return str(prefecture).zfill(6)

def change_birth_code(birth_num):
    return str(birth_num).zfill(6)

for i in all_city:
    print(change_Prefecture_code(i[0]) + change_birth_code(city[i[0]].index(i[1]) + 1))

Fixed submission:
X, Y = map(int, input().split())
print(int(X + Y / 2))
Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
T = list(input())

new_S = ""
new_T = ""


def change_word(a,b,S):
    for i in range(len(S)):
        if S[i] == a:
            S[i] = b
        elif S[i] == b:
            S[i] = a
        else:
            S[i] == S[i]
    return S



tmp = []
for i in range(len(S)):
    if S[i] != T[i]:
        #tmp.append([S[i], T[i]])
        S = change_word(S[i], T[i], S)
        #T = change_word(S[i], T[i], T)


#for i in tmp:


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

Fixed submission:
S = list(input())
T = list(input())
 
test = [-1] * 26
test2 = [-1] * 26

for i in range(len(S)):
    a = ord(S[i]) - ord('a')
    b = ord(T[i]) - ord('a')

    if (test[a] != -1) or test2[b] != -1:
        if test[a] != b or test2[b] != a:
           print("No")
           exit()

    else:
        test[a] = b
        test2[b] = a


print("Yes")

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
T = list(input())

new_S = ""
new_T = ""


def change_word(a,b,S):
    for i in range(len(S)):
        if S[i] == a:
            S[i] = b
        elif S[i] == b:
            S[i] = a
        else:
            S[i] == S[i]
    return S




for i in range(len(S)):
    if S[i] != T[i]:
        S = change_word(S[i], T[i], S)
        T = change_word(S[i], T[i], T)

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

Fixed submission:
S = list(input())
T = list(input())
 
test = [-1] * 26
test2 = [-1] * 26

for i in range(len(S)):
    a = ord(S[i]) - ord('a')
    b = ord(T[i]) - ord('a')

    if (test[a] != -1) or test2[b] != -1:
        if test[a] != b or test2[b] != a:
           print("No")
           exit()

    else:
        test[a] = b
        test2[b] = a


print("Yes")

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
T = list(input())

new_S = ""
new_T = ""


def change_word(a,b,S):
    for i in range(len(S)):
        if S[i] == a:
            S[i] = b
        elif S[i] == b:
            S[i] = a
        else:
            S[i] == S[i]
    return S




for i in range(len(S)):
    if S[i] != T[i]:
        S = change_word(S[i], T[i], S)
        T = change_word(S[i], T[i], T)

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

Fixed submission:
S = list(input())
T = list(input())
 
test = [-1] * 26
test2 = [-1] * 26

for i in range(len(S)):
    a = ord(S[i]) - ord('a')
    b = ord(T[i]) - ord('a')

    if (test[a] != -1) or test2[b] != -1:
        if test[a] != b or test2[b] != a:
           print("No")
           exit()

    else:
        test[a] = b
        test2[b] = a


print("Yes")
Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

## 最初に入力回数が与えられて、そのあとデータが入力される。といったパターン
nums = list(map(int, input().split())) # "1 2 3"と入力
N = nums[0]
X = nums[1]

nums = list(map(int, input().split())) # "1 2 3"と入力

a=[]
for item in nums:
	a.append(abs(item - X))


print(gcd (*a))


Fixed submission:
N, X = map(int, input().split())
x = list(map(int, input().split()))

x = list(map(lambda x: abs(x - X), x))


def gcd(a, b):
    if a % b == 0:
        return b
    else:
        return gcd(b, a % b)

ans = x[0]
for i in x:
    ans = min(ans, gcd(i, ans))
print(ans)

Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

## 最初に入力回数が与えられて、そのあとデータが入力される。といったパターン
nums = list(map(int, input().split())) # "1 2 3"と入力
N = nums[0]
X = nums[1]

nums = list(map(int, input().split())) # "1 2 3"と入力

a=[]
for item in nums:
	a.append(abs(item - X))


print(gcd (*a))


Fixed submission:
N, X = map(int, input().split())
x = list(map(int, input().split()))

x = list(map(lambda x: abs(x - X), x))


def gcd(a, b):
    if a % b == 0:
        return b
    else:
        return gcd(b, a % b)

ans = x[0]
for i in x:
    ans = min(ans, gcd(i, ans))
print(ans)
Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())
maze = [input() for i in range(H)]


delete_candidate = []
for i in range(H):
        flag = False
        for j in maze[i]:
                if j == "#":
                        flag = True
                        continue
        if flag == False:
                delete_candidate.append(i)

for i in delete_candidate:
        del maze[i]

delete_candidate = []
for j in range(W):
        flag = False
        for i in range(len(maze)):
                if maze[i][j] == "#":
                        flag = True
                        continue
        if flag == False:
                delete_candidate.append(j)


for i in range(len(maze)):
        for j in range(len(maze[i])):  
                if j in delete_candidate:
                        continue
                print(maze[i][j], end = "")
        print("")




Fixed submission:
H, W = map(int, input().split())

A = [input() for i in range(H)]

row = []
column = []

for i in range(len(A)):
        for j in range(len(A[i])):
                if A[i][j] == "#":
                        row.append(i)
                        break

for i in range(W):
        for j in range(len(A)):
                if A[j][i] == "#":
                        column.append(i)
                        break


for i in range(len(A)):
        flag = True
        for j in range(len(A[i])):
                if i in row:
                        if j in column:
                                print(A[i][j], end = "")
                else:
                        flag = False
                        continue
        if flag:
                print("")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

ans = 300010
for i in range(N):
    tmp = 0
    for left in range(i):
        if S[left] == 'W':
            tmp += 1
    for right in range(i + 1, N):
        if S[right] == 'E':
            tmp += 1
    ans = min(ans, tmp)

print(ans)

Fixed submission:
N = int(input())
S = input()


left = [0] * N
right = [0] * N

for i in range(0, N):
    if i == 0:
       if S[i] == 'W':
           left[i] = 1
    else:
        if S[i] == 'W':
            left[i] = left[i-1] + 1
        else:
            left[i] = left[i-1]

for i in reversed(range(0, N)):
    if i == N - 1:
        if S[i] == 'E':
            right[i] = 1
    else:
        if S[i] == 'E':
            right[i] = right[i+1] + 1
        else:
            right[i] = right[i+1]

ans = 300010
for i in range(0,N):
    if i == 0:
        ans = min(ans, right[i+1])
    elif i == N -1:
        ans = min(ans, left[i-1])
    else:
        ans = min(ans, left[i-1] + right[i+1])


print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
x = int(input())

ans = 0

for i in range(1, 51):

 tmp = i

 while tmp * i < x + 1:

  tmp = tmp * i

  ans = max(ans, tmp)

print(ans)

Fixed submission:
x = int(input())

ans = 0

if x == 1:

 print(1)

 exit()

for i in range(2, 51):

 tmp = i

 while tmp * i < x + 1:

  tmp = tmp * i

  ans = max(ans, tmp)

print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()
K = int(input())


sub_string = []
for i in range(len(s)):
    for j in range(0, len(s) + 1 - i):
        sub_string.append(s[i:i+j])

#重複の排除
sub_string = set(sub_string)
#辞書順にソートする
sub_string = sorted(sub_string)
#空白を削除
sub_string.remove('')
print(sub_string[K - 1])

Fixed submission:
s = input()
K = int(input())


sub_string = []
for i in range(len(s)):
    for j in range(0, len(s) + 1 - i):
        if j > K:
            break
        sub_string.append(s[i:i+j])

#重複の排除
sub_string = set(sub_string)
#辞書順にソートする
sub_string = sorted(sub_string)
#空白を削除
sub_string.remove('')
print(sub_string[K - 1])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

station = [list(map(int, input().split())) for i in range(N - 1)]



def next_start_time(arrive, C, S, F):
    for i in range(1000):
        if arrive > S:
            i = (arrive - S) // F
            if arrive <= S + i * F:
                break
            else:
                i = i + 1
        elif arrive <= S + i * F:
            break
    return S + (i * F) + C


for i in range(N - 1):
    ans = 0
    for j in range(i, N - 1):
        ans = next_start_time(ans, station[j][0], station[j][1], station[j][2])
    print(ans)

print(0)

Fixed submission:
N = int(input())

station = [list(map(int, input().split())) for i in range(N - 1)]



def next_start_time(arrive, C, S, F):
    for i in range(1000):
        if arrive > S:
            i = (arrive - S) // F
            if arrive <= S + i * F:
                break
            else:
                i = i + 1
                break
        elif arrive <= S + i * F:
            break
    return S + (i * F) + C


for i in range(N - 1):
    ans = 0
    for j in range(i, N - 1):
        ans = next_start_time(ans, station[j][0], station[j][1], station[j][2])
    print(ans)

print(0)
Buggy python submission (verdict: Runtime Error):
N = int(input())

def fx(N):
  ans = 0
  while N // 10 != 0:
    ans += N % 10
    N = N //10
  return ans
  
if N % fx(N) == 0:
  print("Yes")
else:
  print("No")

Fixed submission:
N = int(input())

def fx(N):
  ans = 0
  for i in str(N):
    ans += int(i)
  return ans
  
if N % fx(N) == 0:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

def ryuka(N):
  if N == 1:
    return 1
  if N == 0:
    return 2
  return ryuka(N-1) + ryuka(N-2)


print(ryuka(N))

Fixed submission:
N = int(input())

ryuka = [0] * 100
ryuka[0] = 2
ryuka[1] = 1

for i in range(2, 87):
  ryuka[i] = ryuka[i-1] + ryuka[i - 2]


print(ryuka[N])
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100000)

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

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

def lcm(a, b):
    return int((a * b) / gcd(a, b))

ans = T[0]
for i in range(1, N):
    ans = lcm(ans, T[i])

print(ans)

Fixed submission:
import sys
sys.setrecursionlimit(100000)

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

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

def lcm(a, b):
    return int((a * b) // gcd(a, b))

ans = T[0]
for i in range(1, N):
    ans = lcm(ans, T[i])

print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100000)

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

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

def lcm(a, b):
    return int((a * b) / gcd(a, b))

ans = T[0]
for i in range(1, len(T)):
    ans = lcm(ans, T[i])

print(ans)

Fixed submission:
import sys
sys.setrecursionlimit(100000)

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

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

def lcm(a, b):
    return int((a * b) // gcd(a, b))

ans = T[0]
for i in range(1, N):
    ans = lcm(ans, T[i])

print(ans)

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

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

def lcm(a, b):
    return int((a * b) / gcd(a, b))

ans = T[0]
for i in range(1, len(T)):
    ans = lcm(ans, T[i])

print(ans)

Fixed submission:
import sys
sys.setrecursionlimit(100000)

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

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

def lcm(a, b):
    return int((a * b) // gcd(a, b))

ans = T[0]
for i in range(1, 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 i in range(n):
    if i % 2 == 1:
        b.append(a[i])
    else:
        b.insert(0,a[i])


if n % 2 == 1:
    for i in b:
        print(i, end=" ")
else:
    for i in reversed(b):
        print(i, end=" ")


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

b = [0] * n


if n % 2 == 1:
    for i in reversed(range(n)):
        if i % 2 == 1:
            b[n // 2 + int(i/2 + 0.9)] = a[i]
        else:
            b[n // 2 - int(i/2 + 0.9)] = a[i]
else:
    for i in reversed(range(n)):
        if i % 2 == 1:
            b[n // 2 - 1 + int(i/2 + 0.9)] = a[i]
        else:
            b[n // 2 - 1 - int(i/2 + 0.9)] = a[i]


if n % 2 == 1:
    for i in b:
        print(i, end=" ")
else:
    for i in reversed(b):
        print(i, end=" ")
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))

a.sort()

min_color = [0] * 8
max_color = [0] * 8
extra = 0

for i in a:
    if i >= 3200:
        if sum(min_color) == 0:
            min_color[0] = 1
        if sum(max_color + extra) < 8:
            extra += 1
    else:
        min_color[i // 400] = 1
        max_color[i // 400] = 1


print( sum(min_color), sum(max_color) + extra)

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

a.sort()
min_color = [0] * 8
max_color = [0] * 8
extra = 0

for i in a:
    if i >= 3200:
        if sum(min_color) == 0:
            min_color[0] = 1
        extra += 1
    else:
        min_color[i // 400] = 1
        max_color[i // 400] = 1


print( sum(min_color), sum(max_color) + extra)
Buggy python submission (verdict: Time Limit Exceeded):
K, S = map(int,input().split())

count = 0
for i in range(0,K+1):
    if i > S:
        continue
    for j in  range(0,K+1):
        if i + j > S:
            continue
        for k in  range(0,K+1):
            if i + j + k > S:
                continue
            if i + j + k == S:
                count += 1
print(count)

Fixed submission:
K, S = map(int,input().split())

count = 0
for i in range(0,K+1):
    if i > S:
        continue
    for j in  range(0,K+1):
        if 0 <= (S - i - j) <= K:
            count += 1

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
K, S = map(int,input().split())

count = 0
for i in range(0,K+1):
    if i > S:
        continue
    for j in  range(0,K+1):
        if j > S:
            continue
        for k in  range(0,K+1):
            if i+j > S:
                continue
            if i + j + k == S:
                count += 1
print(count)

Fixed submission:
K, S = map(int,input().split())

count = 0
for i in range(0,K+1):
    if i > S:
        continue
    for j in  range(0,K+1):
        if 0 <= (S - i - j) <= K:
            count += 1

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
K, S = map(int,input().split())

count = 0
for i in range(0,K+1):
    for j in  range(0,K+1):
        for k in  range(0,K+1):
            if i + j + k == S:
                count += 1
print(count)

Fixed submission:
K, S = map(int,input().split())

count = 0
for i in range(0,K+1):
    if i > S:
        continue
    for j in  range(0,K+1):
        if 0 <= (S - i - j) <= K:
            count += 1

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd

def main():
    input()
    aa = list(map(int, raw_input().split()))
    g = 1
    for a in aa:
        g = a * g // gcd(a, g)
    ans = 0
    for a in aa:
        ans = (ans + g // a) % (10 ** 9 + 7)
    print(ans)


main()


Fixed submission:
from fractions import gcd

def main():
    n = input()
    aa = list(map(int, raw_input().split()))
    g = 1
    for a in aa:
        g *= a // gcd(a, g)
    ans = 0
    MOD = 10 ** 9 + 7
    g %= MOD
    for a in aa:
        ans = (ans + g * pow(a, MOD - 2, MOD)) % MOD
    print(ans)


main()

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd

def main():
    n = int(input())
    aa = list(map(int, input().split()))
    g = 1
    for a in aa:
        g = a * g // gcd(a, g)
    ans = 0
    for a in aa:
        ans = (ans + g // a) % (10 ** 9 + 7)
    print(ans)


main()


Fixed submission:
from fractions import gcd

def main():
    n = input()
    aa = list(map(int, raw_input().split()))
    g = 1
    for a in aa:
        g *= a // gcd(a, g)
    ans = 0
    MOD = 10 ** 9 + 7
    g %= MOD
    for a in aa:
        ans = (ans + g * pow(a, MOD - 2, MOD)) % MOD
    print(ans)


main()
Buggy python submission (verdict: Runtime Error):
from math import gcd

a, b = map(int, input().split())
print(a * b // gcd(a, b))

Fixed submission:
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

a, b = map(int, input().split())
print(a * b // gcd(a, b))
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    input()
    s = raw_input()
    a2 = set()
    a3 = set()
    for i, c1 in enumerate(s[:-2]):
        for j, c2 in enumerate(s[i+1:-1], i + 1):
            ss = c1 + c2
            if ss in a2:
                continue
            a2.add(ss)
            for c3 in set(s[j+1:]):
                a3.add(ss + c3)
    print len(a3)

main()


Fixed submission:
def main():
    n = input()
    s = raw_input()
    a1 = set()
    a2 = set()
    a3 = set()
    jj = [set()]
    for j in xrange(n - 1, 1, -1):
        jj.append(jj[-1] | {s[j]})
    jj = jj[::-1]
    for i, c1 in enumerate(s[:-2]):
        if c1 in a1:
            continue
        a1.add(c1)
        for j in xrange(i + 1, n - 1):
            ss = c1 + s[j]
            if ss in a2:
                continue
            a2.add(ss)
            for c3 in jj[j - 1]:
                a3.add(ss + c3)
    print len(a3)

main()
Buggy python submission (verdict: Time Limit Exceeded):
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()

Fixed submission:
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()

Buggy python submission (verdict: Time Limit Exceeded):
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()


Fixed submission:
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()