Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000)
from collections import deque

INF = -1

nVertices, nEdges = map(int, input().split())
edges = [[] for _ in range(nVertices + 1)]
for _ in range(nEdges):
    u, v = map(int, input().split())
    edges[u].append(v)
s, t = map(int, input().split())

def getNextMoves(from_, v, depth):
    if depth == 3:
        if dist[v] == INF:
            dist[v] = dist[from_] + 1
            q.append(v)
        return
    for child in edges[v]:
        getNextMoves(from_, child, depth + 1)

dist = [INF] * (nVertices + 1)
dist[s] = 0
q = deque()
q.append(s)
while q:
    cur = q.popleft()
    getNextMoves(cur, cur, 0)
print(dist[t])

Fixed submission:
from collections import deque

INF = -1

nVertices, nEdges = map(int, input().split())
edges = [[] for _ in range(nVertices + 1)]
for _ in range(nEdges):
    u, v = map(int, input().split())
    edges[u].append(v)
s, t = map(int, input().split())

dist = [[INF for _ in range(3)] for _ in range(nVertices + 1)]
dist[s][0] = 0
q = deque()
q.append((s, 0))
while q:
    curVertex, curDist = q.popleft()
    for nextVertex in edges[curVertex]:
        nextDist = curDist + 1
        if dist[nextVertex][nextDist % 3] == INF:
            dist[nextVertex][nextDist % 3] = nextDist
            q.append((nextVertex, nextDist))

print(dist[t][0] // 3 if dist[t][0] != INF else INF)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000)
from collections import deque

INF = -1

nVertices, nEdges = map(int, input().split())
edges = [[] for _ in range(nVertices + 1)]
for _ in range(nEdges):
    u, v = map(int, input().split())
    edges[u].append(v)
s, t = map(int, input().split())

def getNextMoves(from_, v, depth):
    if depth == 3:
        if dist[v] == INF:
            dist[v] = dist[from_] + 1
            q.append(v)
        return
    for child in edges[v]:
        getNextMoves(from_, child, depth + 1)

dist = [INF] * (nVertices + 1)
dist[s] = 0
q = deque()
q.append(s)
while q:
    cur = q.popleft()
    getNextMoves(cur, cur, 0)
print(dist[t])

Fixed submission:
from collections import deque

INF = -1

nVertices, nEdges = map(int, input().split())
edges = [[] for _ in range(nVertices + 1)]
for _ in range(nEdges):
    u, v = map(int, input().split())
    edges[u].append(v)
s, t = map(int, input().split())

dist = [[INF for _ in range(3)] for _ in range(nVertices + 1)]
dist[s][0] = 0
q = deque()
q.append((s, 0))
while q:
    curVertex, curDist = q.popleft()
    for nextVertex in edges[curVertex]:
        nextDist = curDist + 1
        if dist[nextVertex][nextDist % 3] == INF:
            dist[nextVertex][nextDist % 3] = nextDist
            q.append((nextVertex, nextDist))

print(dist[t][0] // 3 if dist[t][0] != INF else INF)
Buggy python submission (verdict: Time Limit Exceeded):
MOD = 10 ** 9 + 7

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

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

ret = dp[n][m] + 1
if ret >= MOD:
    ret -= MOD
print(ret)

Fixed submission:
MOD = 10 ** 9 + 7

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

dp = [[0 for _ in range(m + 1)] for _ in range(n + 1)]
for i in range(1, n + 1):
    for j in range(1, m + 1):
        if a[i - 1] == b[j - 1]:
            dp[i][j] = (1 + dp[i - 1][j] + dp[i][j - 1]) % MOD
        else:
            dp[i][j] = (dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]) % MOD

print((dp[n][m] + 1) % MOD)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = sorted([list(map(int, input().split())) for _ in range(n)])
d = {}
ret = float('inf')
for i in range(n - 1):
    for j in range(i + 1, n):
        p, q = a[j][0] - a[i][0], a[j][1] - a[i][1]
        if p == 0 and q == 0:
            continue
        key = (p, q)
        d.setdefault(key, 0)
        d[key] += 1
print(n - max(d.values()))


Fixed submission:
n = int(input())
a = sorted([list(map(int, input().split())) for _ in range(n)])
d = {}
ret = float('inf')
for i in range(n - 1):
    for j in range(i + 1, n):
        p, q = a[j][0] - a[i][0], a[j][1] - a[i][1]
        if p == 0 and q == 0:
            continue
        key = (p, q)
        d.setdefault(key, 0)
        d[key] += 1
print(n - (max(d.values()) if d  else 0))
Buggy python submission (verdict: Time Limit Exceeded):
sizeI, sizeJ = map(int, input().split())
a = [input().strip() for _ in range(sizeI)]
 
rowVal = [[0 for _ in range(sizeJ)] for _ in range(sizeI)]
for i in range(sizeI):
    for j in range(sizeJ):
        if j == 0:
            rowVal[i][j] = 1 if a[i][j] == '.' else 0
        else:
            if a[i][j] == '.':
                rowVal[i][j] = rowVal[i][j - 1] + 1
            else:
                rowVal[i][j] = 0
    for j in range(sizeJ - 2, -1, -1):
        if rowVal[i][j] and rowVal[i][j + 1]:
            rowVal[i][j] = rowVal[i][j + 1]
 
colVal = [[0 for _ in range(sizeJ)] for _ in range(sizeI)]
for j in range(sizeJ):
    for i in range(sizeI):
        if i == 0:
            colVal[i][j] = 1 if a[i][j] == '.' else 0
        else:
            if a[i][j] == '.':
                colVal[i][j] = colVal[i - 1][j] + 1
            else:
                colVal[i][j] = 0
    for i in range(sizeI - 2, -1, -1):
        if colVal[i][j] and colVal[i + 1][j]:
            colVal[i][j] = colVal[i + 1][j]
 
ret = 0
for i in range(sizeI):
    for j in range(sizeJ):
        ret = max(ret, rowVal[i][j] + colVal[i][j] - 1)
print(ret)

Fixed submission:
sizeI, sizeJ = map(int, input().split())
a = [input().strip() for _ in range(sizeI)]

rowVal = [[0 for _ in range(sizeJ)] for _ in range(sizeI)]
for i in range(sizeI):
    for j in range(sizeJ):
        if j == 0:
            rowVal[i][j] = 1 if a[i][j] == '.' else 0
        else:
            if a[i][j] == '.':
                rowVal[i][j] = rowVal[i][j - 1] + 1
            else:
                rowVal[i][j] = 0
    for j in range(sizeJ - 2, -1, -1):
        if rowVal[i][j] and rowVal[i][j + 1]:
            rowVal[i][j] = rowVal[i][j + 1]

colVal = [[0 for _ in range(sizeJ)] for _ in range(sizeI)]
for j in range(sizeJ):
    for i in range(sizeI):
        if i == 0:
            colVal[i][j] = 1 if a[i][j] == '.' else 0
        else:
            if a[i][j] == '.':
                colVal[i][j] = colVal[i - 1][j] + 1
            else:
                colVal[i][j] = 0
    for i in range(sizeI - 2, -1, -1):
        if colVal[i][j] and colVal[i + 1][j]:
            colVal[i][j] = colVal[i + 1][j]

ret = 0
for i in range(sizeI):
    for j in range(sizeJ):
        ret = max(ret, rowVal[i][j] + colVal[i][j] - 1)
print(ret)
Buggy python submission (verdict: Time Limit Exceeded):
s = input().strip()
ret = 0
while 'ABC' in s:
    ret += s.count('ABC')
    s = s.replace('ABC', 'BCA')
print(ret)

Fixed submission:
s = input().strip()
n = len(s)
ret = 0
a = 0
i = 0
while i < n:
    if s[i] == 'A':
        a += 1
        i += 1
    elif s[i] == 'B':
        if i < n - 1 and s[i + 1] == 'C':
            ret += a
            i += 2
        else:
            a = 0
            i += 1
    else:
        a = 0
        i += 1
print(ret)

Buggy python submission (verdict: Time Limit Exceeded):
s = input().strip()
ret = 0
while 'ABC' in s:
    ret += s.count('ABC')
    s = s.replace('ABC', 'BCA')
print(ret)

Fixed submission:
s = input().strip()
n = len(s)
ret = 0
a = 0
i = 0
while i < n:
    if s[i] == 'A':
        a += 1
        i += 1
    elif s[i] == 'B':
        if i < n - 1 and s[i + 1] == 'C':
            ret += a
            i += 2
        else:
            a = 0
            i += 1
    else:
        a = 0
        i += 1
print(ret)
Buggy python submission (verdict: Runtime Error):
from sys import setrecursionlimit
setrecursionlimit(100000)

nVertices, nEdges = map(int, input().split())
g = [[] for _ in range(nVertices + 1)]
for _ in range(nEdges):
    u, v, _ = map(int, input().split())
    g[u].append(v)
    g[v].append(u)

def dfs(v):
    visited[v] = True
    for to in g[v]:
        if not visited[to]:
            dfs(to)

cnt = 0
visited = [False] * (nVertices + 1)
for v in range(1, nVertices + 1):
    if not visited[v]:
        dfs(v)
        cnt += 1
print(cnt)

Fixed submission:
from sys import setrecursionlimit
setrecursionlimit(100000)
from collections import deque

nVertices, nEdges = map(int, input().split())
g = [[] for _ in range(nVertices + 1)]
for _ in range(nEdges):
    u, v, _ = map(int, input().split())
    g[u].append(v)
    g[v].append(u)

def dfs(v):
    visited[v] = True
    for to in g[v]:
        if not visited[to]:
            dfs(to)

def bfs(v):
    visited[v] = True
    q = deque([v])
    while q:
        cur = q.pop()
        for to in g[cur]:
            if not visited[to]:
                visited[to] = True
                q.appendleft(to)

cnt = 0
visited = [False] * (nVertices + 1)
for v in range(1, nVertices + 1):
    if not visited[v]:
        bfs(v)
        cnt += 1
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
value = list(map(int, input().split()))
cost = list(map(int, input().split()))
ret = 0
for state in range((1 << n) - 1):
    values = costs = 0
    for shift in range(n):
        if (state >> shift) & 1 == 1:
            values += value[shift]
            costs += cost[shift]
    ret = max(ret, values - costs)
print(ret)

Fixed submission:
n = int(input())
value = list(map(int, input().split()))
cost = list(map(int, input().split()))
ret = 0
for state in range((1 << n)):
    values = costs = 0
    for shift in range(n):
        if (state >> shift) & 1 == 1:
            values += value[shift]
            costs += cost[shift]
    ret = max(ret, values - costs)
print(ret)
Buggy python submission (verdict: Time Limit Exceeded):
def binarySearch(a, val):
    left, right = -1, len(a)
    while left + 1 < right:
        mid = (left + right) >> 1
        if a[mid] < val:
            left = mid
        else:
            right = mid
    return a[right] if right < len(a) else 1 << 35

def binarySearch2(a, val):
    left, right = -1, len(a)
    while left + 1 < right:
        mid = (left + right) >> 1
        if a[mid] <= val:
            left = mid
        else:
            right = mid
    return a[left] if left >= 0 else -(1 << 35)

nShrines, nTemples, nQueries = map(int, input().split())
shrines = [int(input()) for _ in range(nShrines)]
temples = [int(input()) for _ in range(nTemples)]
starts = [int(input()) for _ in range(nQueries)]
for start in starts:
    shrineToRight = binarySearch(shrines, start)
    templeToRight = binarySearch(temples, start)
    shrineToLeft = binarySearch2(shrines, start)
    templeToLeft = binarySearch2(temples, start)
    ret = min(
        max(shrineToRight, templeToRight) - start,
        start - min(shrineToLeft, templeToLeft),
        templeToRight - start + templeToRight - shrineToLeft,
        shrineToRight - start + shrineToRight - templeToLeft,
        start - shrineToLeft + templeToRight - shrineToLeft,
        start - templeToLeft + shrineToRight - templeToLeft
    )
    print(ret)


Fixed submission:
def binarySearch(a, val):
    left, right = -1, len(a)
    while left + 1 < right:
        mid = (left + right) >> 1
        if a[mid] < val:
            left = mid
        else:
            right = mid
    return a[right] if right < len(a) else 1 << 35

def binarySearch2(a, val):
    left, right = -1, len(a)
    while left + 1 < right:
        mid = (left + right) >> 1
        if a[mid] <= val:
            left = mid
        else:
            right = mid
    return a[left] if left >= 0 else -(1 << 35)

nShrines, nTemples, nQueries = map(int, input().split())
shrines = [int(input()) for _ in range(nShrines)]
temples = [int(input()) for _ in range(nTemples)]
starts = [int(input()) for _ in range(nQueries)]
ret = []
for start in starts:
    shrineToRight = binarySearch(shrines, start)
    templeToRight = binarySearch(temples, start)
    shrineToLeft = binarySearch2(shrines, start)
    templeToLeft = binarySearch2(temples, start)
    ret.append(min(
        max(shrineToRight, templeToRight) - start,
        start - min(shrineToLeft, templeToLeft),
        templeToRight - start + templeToRight - shrineToLeft,
        shrineToRight - start + shrineToRight - templeToLeft,
        start - shrineToLeft + templeToRight - shrineToLeft,
        start - templeToLeft + shrineToRight - templeToLeft
    ))
print('\n'.join(map(str, ret)))
Buggy python submission (verdict: Runtime Error):
from functools import reduce
from math import gcd

input()
print(reduce(gcd, map(int, input().split())))

Fixed submission:
from functools import reduce

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

input()
print(reduce(gcd, map(int, input().split())))
Buggy python submission (verdict: Runtime Error):
NUM = (None, 2, 5, 5, 4, 5, 6, 3, 7, 6)

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

# maximum value to make using exactly sticks
dp = [0] * (nSticks + 1)
for digit in a:
    if NUM[digit] <= nSticks:
        dp[NUM[digit]] = digit
for sticks in range(2, nSticks + 1):
    for digit in a:
        if dp[sticks - NUM[digit]] > 0 and sticks - NUM[digit] >= 0:
            dp[sticks] = max(dp[sticks], dp[sticks - NUM[digit]] * 10 + digit)
print(dp[-1])



Fixed submission:
NUM = (None, 2, 5, 5, 4, 5, 6, 3, 7, 6)

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

# maximum value to make using exactly sticks
dp = [0] * (nSticks + 1)
for digit in a:
    if NUM[digit] <= nSticks:
        dp[NUM[digit]] = max(dp[NUM[digit]], digit)
for sticks in range(2, nSticks + 1):
    for digit in a:
        if sticks - NUM[digit] >= 0 and dp[sticks - NUM[digit]] > 0:
            dp[sticks] = max(dp[sticks], dp[sticks - NUM[digit]] * 10 + digit)
print(dp[-1])
Buggy python submission (verdict: Runtime Error):
n, eat = map(int, input().split())

pattiesCount = lambda level: (1 << (level + 1)) - 1
bunsCount = lambda level: (1 << (level + 1)) - 2
bothCount = lambda level: (1 << (level + 2)) - 3

# for i in range(51):
#     if pattiesCount(i) != p[i]:
#         raise Exception()
#     print(i, '->', pattiesCount(i), bunsCount(i), bothCount(i))

def doit(level, eat):
    if level == 0:
        if eat > 1:
            raise Exception()
        return int(eat == 1)
    both = bothCount(level - 1)
    patties = pattiesCount(level - 1)
    if eat == both + 2:
        return 1 + patties
    if eat < both + 2:
        return doit(level - 1, eat - 1)
    return 1 + patties + doit(level - 1, eat - 2 - both)


print(doit(n, eat))


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

pattiesCount = lambda level: (1 << (level + 1)) - 1
bunsCount = lambda level: (1 << (level + 1)) - 2
bothCount = lambda level: (1 << (level + 2)) - 3

# for i in range(51):
#     if pattiesCount(i) != p[i]:
#         raise Exception()
#     print(i, '->', pattiesCount(i), bunsCount(i), bothCount(i))

def doit(level, eat):
    if level == 0:
        return int(eat >= 1)
    both = bothCount(level - 1)
    patties = pattiesCount(level - 1)
    if eat == both + 2:
        return 1 + patties
    if eat > both + 1:
        return 1 + patties + doit(level - 1, eat - 2 - both)
    return doit(level - 1, eat - 1)

print(doit(n, eat))
Buggy python submission (verdict: Runtime Error):
X, Y, A, B, C = map(int, input().split())
p = sorted([int(i) for i in input().split()], reverse=True)
q = sorted([int(i) for i in input().split()], reverse=True)
r = sorted([int(i) for i in input().split()])

p = p[:X]
q = q[:Y]
plus_r = []

while r != [] and (p != [] and r[-1] > p[-1]) or (q != [] and r[-1] > q[-1]):
    if p[-1] < q[-1]:
        p.pop()
    else:
        q.pop()
    plus_r.append(r.pop())

print(sum(p) + sum(q) + sum(plus_r))


Fixed submission:
X, Y, A, B, C = map(int, input().split())
p = sorted([int(i) for i in input().split()], reverse=True)
q = sorted([int(i) for i in input().split()], reverse=True)
r = sorted([int(i) for i in input().split()])

p = p[:X]
q = q[:Y]
plus_r = []

while r != [] and ((p != [] and r[-1] > p[-1]) or (q != [] and r[-1] > q[-1])):
    if p == []:
        q.pop()
        plus_r.append(r.pop())
        continue
    elif q == []:
        p.pop()
        plus_r.append(r.pop())
        continue

    if p[-1] < q[-1]:
        p.pop()
    else:
        q.pop()
    plus_r.append(r.pop())

print(sum(p) + sum(q) + sum(plus_r))

Buggy python submission (verdict: Runtime Error):
X, Y, A, B, C = map(int, input().split())
p = sorted([int(i) for i in input().split()], reverse=True)
q = sorted([int(i) for i in input().split()], reverse=True)
r = sorted([int(i) for i in input().split()])

p = p[:X]
q = q[:Y]
plus_r = []

while r != [] and ((p != [] and r[-1] > p[-1]) or (q != [] and r[-1] > q[-1])):
    if p[-1] < q[-1]:
        p.pop()
    else:
        q.pop()
    plus_r.append(r.pop())

print(sum(p) + sum(q) + sum(plus_r))


Fixed submission:
X, Y, A, B, C = map(int, input().split())
p = sorted([int(i) for i in input().split()], reverse=True)
q = sorted([int(i) for i in input().split()], reverse=True)
r = sorted([int(i) for i in input().split()])

p = p[:X]
q = q[:Y]
plus_r = []

while r != [] and ((p != [] and r[-1] > p[-1]) or (q != [] and r[-1] > q[-1])):
    if p == []:
        q.pop()
        plus_r.append(r.pop())
        continue
    elif q == []:
        p.pop()
        plus_r.append(r.pop())
        continue

    if p[-1] < q[-1]:
        p.pop()
    else:
        q.pop()
    plus_r.append(r.pop())

print(sum(p) + sum(q) + sum(plus_r))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(i) for i in input().split()]

ans = []
for i in range(1, N + 1):
    ans.append(A.index(i) + 1)

print(*ans)


Fixed submission:
N = int(input())
A = [int(i) for i in input().split()]

ans = [0] * N
for i in range(N):
    ans[A[i] - 1] = i + 1

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

ans = 0
for i in range(1,N):
    ans += i
print(ans)

Fixed submission:
N = int(input())

ans = (N - 1) * N // 2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import Fraction


def comb(n: int, k: int) -> int:
    if n < 0 or k < 0:
        pdt = 0
    else:
        pdt = 1
        for s in range(1, k + 1):
            pdt *= Fraction(n - s + 1, s)

    return pdt.numerator


N = int(input())

dic = {}
for i in range(N):
    s = sorted(input())
    s = "".join(s)
    dic.setdefault(s, 0)
    dic[s] += 1

ans = 0
for value in dic.values():
    ans += comb(value, 2)
print(ans)


Fixed submission:
from fractions import Fraction


def comb(n: int, k: int) -> int:
    if n < 0 or k < 0:
        pdt = 0
    else:
        pdt = 1
        for s in range(1, k + 1):
            pdt *= Fraction(n - s + 1, s)

    return pdt.numerator


N = int(input())

dic = {}
for i in range(N):
    s = sorted(input())
    s = "".join(s)
    dic.setdefault(s, 0)
    dic[s] += 1

ans = 0
for value in dic.values():
    ans += comb(value, 2)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
case = sorted([[int(j) for j in input().split()] for i in range(N)], key=lambda x: (-x[0]))

candidate_list = []
ans = 0

for i in range(1, M + 1):
    while case:
        if case[-1][0] <= i:
            candidate_list.append(case.pop(-1))
        else:
            break

    if candidate_list:
        candidate_list.sort(key=lambda x: (x[1]))
        ans += candidate_list.pop(-1)[1]

print(ans)


Fixed submission:
import heapq

N, M = map(int, input().split())
case = sorted([[int(j) for j in input().split()] for i in range(N)], key=lambda x: -x[0])

candidate_queue = []
ans = 0

for i in range(1, M + 1):
    while case:
        if case[-1][0] <= i:
            heapq.heappush(candidate_queue, case.pop(-1)[1] * (-1))
        else:
            break

    if candidate_queue:
        ans += heapq.heappop(candidate_queue) * (-1)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
case = sorted([[int(j) for j in input().split()] for i in range(N)], key=lambda x: (-x[0]))

candidate_list = []
ans = 0

for i in range(1, M + 1):
    while case:
        if case[-1][0] <= i:
            candidate_list.append(case.pop(-1))
        else:
            break

    if candidate_list:
        candidate_list.sort(key=lambda x: (x[1]))
        ans += candidate_list.pop(-1)[1]

print(ans)


Fixed submission:
import heapq

N, M = map(int, input().split())
case = sorted([[int(j) for j in input().split()] for i in range(N)], key=lambda x: -x[0])

candidate_queue = []
ans = 0

for i in range(1, M + 1):
    while case:
        if case[-1][0] <= i:
            heapq.heappush(candidate_queue, case.pop(-1)[1] * (-1))
        else:
            break

    if candidate_queue:
        ans += heapq.heappop(candidate_queue) * (-1)

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

N = len(S)
dp = [[0 for i in range(13)] for j in range(N + 1)]
mod = 10**9 + 7

dp[0][0] = 1
for i in range(N):
    for j in range(13):
        if S[i] != "?":
            dp[i + 1][(j * 10 + int(S[i])) % 13] += dp[i][j]
        else:
            for k in range(10):
                dp[i + 1][(j * 10 + k) % 13] += dp[i][j]
    for j in range(13):
        dp[i + 1][j] %= mod

print(dp[N][5])


Fixed submission:
S = input()

N = len(S)
dp = [[0 for i in range(13)] for j in range(N + 1)]
mod = 10**9 + 7

dp[0][0] = 1
for i in range(N):
    for j in range(13):
        if S[i] != "?":
            dp[i + 1][(j * 10 + int(S[i])) % 13] += dp[i][j]
        else:
            for k in range(10):
                dp[i + 1][(j * 10 + k) % 13] += dp[i][j]
    for j in range(13):
        dp[i + 1][j] %= mod

print(dp[N][5])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(input()) for _ in range(N)]

ans = []
front_max = back_max = 0

for i in reversed(range(N)):
    now = A.pop()
    front_max = max(A) if A else 0
    ans.append(max(front_max, back_max))
    back_max = max(now, back_max)

for i in reversed(range(N)):
    print(ans[i])


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

ans = []
front_max_list, back_max_list = [0], [0]

for i in range(N):
    front_max_list.append(max(front_max_list[i], A[i]))
    back_max_list.append(max(back_max_list[i], A[N - i - 1]))

for i in range(N):
    print(max(front_max_list[i], back_max_list[N - i - 1]))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(input()) for _ in range(N)]

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


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

ans = []
front_max_list, back_max_list = [0], [0]

for i in range(N):
    front_max_list.append(max(front_max_list[i], A[i]))
    back_max_list.append(max(back_max_list[i], A[N - i - 1]))

for i in range(N):
    print(max(front_max_list[i], back_max_list[N - i - 1]))