Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):

import sys
input = sys.stdin.buffer.readline

R, C, K = map(int,input().split())
RC = [[0] * (C+1) for _ in range(R+1)]

for _ in range(K):
    r, c, v = map(int,input().split())
    RC[r-1][c-1] = v


dp = [[[0] * (C+1) for i in range(R+1)] for j in range(4)]

dp[1][0][0] = RC[0][0]
for r in range(R):
    for c in range(C):
        for i in range(4):
            dp[i][r][c+1] = max(dp[i][r][c], dp[i][r][c+1])
            if i <= 2:
                dp[i+1][r][c+1] = max(dp[i][r][c] + RC[r][c+1], dp[i+1][r][c+1])
        dp[0][r+1][c] = max(max(dp[:][r][c]), dp[0][r+1][c])
        dp[1][r+1][c] = max(dp[1][r+1][c], dp[0][r+1][c] + RC[r+1][c])
        
print(max(dp[:][R-1][C-1]))
            

Fixed submission:
import sys
input = sys.stdin.buffer.readline

R, C, K = map(int,input().split())
RC = [[0] * (C+1) for _ in range(R+1)]

for _ in range(K):
    r, c, v = map(int,input().split())
    RC[r-1][c-1] = v


dp = [[[0] * (C+1) for i in range(R+1)] for j in range(4)]

dp[1][0][0] = RC[0][0]
for r in range(R):
    for c in range(C):
        for i in range(4):
            dp[i][r][c+1] = max(dp[i][r][c], dp[i][r][c+1])
            if i <= 2:
                dp[i+1][r][c+1] = max(dp[i][r][c] + RC[r][c+1], dp[i+1][r][c+1])
            dp[0][r+1][c] = max(dp[i][r][c], dp[0][r+1][c])
        dp[1][r+1][c] = max(dp[1][r+1][c], dp[0][r+1][c] + RC[r+1][c])

print(max(dp[0][-2][-2], dp[1][-2][-2], dp[2][-2][-2], dp[3][-2][-2]))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.buffer.readline

R, C, K = map(int,input().split())
RC = [[0] * (C+1) for _ in range(R+1)]

for _ in range(K):
    r, c, v = map(int,input().split())
    RC[r-1][c-1] = v


dp = [[[0] * 4 for _ in range(C+1)] for _ in range(R+1)]

dp[0][0][1] = RC[0][0]
for r in range(R):
    for c in range(C):
        for i in range(4):
            dp[r][c+1][i] = max(dp[r][c][i], dp[r][c+1][i])
            dp[r+1][c][0] = max(dp[r][c][i], dp[r+1][c][0])
            if i <= 2:
                dp[r][c+1][i+1] = max(dp[r][c][i] + RC[r][c+1], dp[r][c+1][i+1])
        dp[r+1][c][1] = max(dp[r+1][c][1], dp[r+1][c][0] + RC[r+1][c])
        
print(max(dp[-2][-2]))
            
                
            
    


Fixed submission:
import sys
input = sys.stdin.buffer.readline

R, C, K = map(int,input().split())
RC = [[0] * (C+1) for _ in range(R+1)]

for _ in range(K):
    r, c, v = map(int,input().split())
    RC[r-1][c-1] = v


dp = [[[0] * (C+1) for i in range(R+1)] for j in range(4)]

dp[1][0][0] = RC[0][0]
for r in range(R):
    for c in range(C):
        for i in range(4):
            dp[i][r][c+1] = max(dp[i][r][c], dp[i][r][c+1])
            if i <= 2:
                dp[i+1][r][c+1] = max(dp[i][r][c] + RC[r][c+1], dp[i+1][r][c+1])
            dp[0][r+1][c] = max(dp[i][r][c], dp[0][r+1][c])
        dp[1][r+1][c] = max(dp[1][r+1][c], dp[0][r+1][c] + RC[r+1][c])

print(max(dp[0][-2][-2], dp[1][-2][-2], dp[2][-2][-2], dp[3][-2][-2]))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

if N%2 == 0 or N == 5:
    print(-1)
    quit()
    
temp = 7%N
ans = 1
while temp != 0:
    temp = (temp*10+7)%N
    ans += 1
print(ans)

Fixed submission:
N = int(input())

if N%2 == 0 or N == 5:
    print(-1)
    quit()
    
temp = 7%N
ans = 1
while temp != 0:
    temp = (temp*10+7)%N
    ans += 1
    if ans >= 10**6+1000:
        print(-1)
        quit()
print(ans)

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

if N%2 == 0 or N == 5:
    print(-1)
    quit()
    
temp = 7%N
ans = 1
while temp != 0:
    temp = (temp*10+7)%N
    ans += 1
print(ans)

Fixed submission:
N = int(input())

if N%2 == 0 or N == 5:
    print(-1)
    quit()
    
temp = 7%N
ans = 1
while temp != 0:
    temp = (temp*10+7)%N
    ans += 1
    if ans >= 10**6+1000:
        print(-1)
        quit()
print(ans)
Buggy python submission (verdict: Runtime Error):
import itertools
import bisect
N, M, K = map(int,input().split())
A = list(map(int, input().split())) 
B = list(map(int, input().split())) 

A_ = list(itertools.accumulate(A))
B_ = list(itertools.accumulate(B))


l = len(A_)
ans = max(ans, bisect.bisect_right(B_, K))
for idx, i in enumerate(A_):
  if i <= K:
          ans = max(idx+1 + bisect.bisect_right(B_, K-i), ans)
  
print(ans)

Fixed submission:
import itertools
import bisect
N, M, K = map(int,input().split())
A = list(map(int, input().split())) 
B = list(map(int, input().split())) 

A_ = list(itertools.accumulate(A))
B_ = list(itertools.accumulate(B))

ans = 0
l = len(A_)
ans = max(ans, bisect.bisect_right(B_, K))
for idx, i in enumerate(A_):
  if i <= K:
          ans = max(idx+1 + bisect.bisect_right(B_, K-i), ans)
  
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ans = 0
for i in range(1,N+1):
    for j in range(1,i+1):
        ans += i if i%j == 0 else 0
print(ans)

Fixed submission:
N = int(input())
ans = 0
for i in range(1,N+1):
    ans += N//i * (N//i + 1) // 2 * i
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
N = int(input())
A = list(map(int, input().split())) 
ans = set(A)
watched = set()
for k, v in Counter(A).items():
    if v != 1:
        ans.remove(k)
    temp = {k*i for i in range(2,10**6//k + 1)}
    ans -= ans&temp
print(len(ans))

Fixed submission:
from collections import Counter
N = int(input())
A = list(map(int, input().split())) 
ans = set(A)
for k, v in Counter(A).items():
    if v != 1:
        ans.discard(k)
    temp = {k*i for i in range(2,10**6//k + 1)}
    ans -= ans&temp
print(len(ans))

Buggy python submission (verdict: Runtime Error):
from collections import Counter
N = int(input())
A = list(map(int, input().split())) 
ans = set(A)
watched = set()
for k, v in Counter(A).items():
    if v != 1:
        ans.remove(k)
    temp = {k*i for i in range(2,10**6//k + 1)}
    ans -= ans&temp
print(len(ans))

Fixed submission:
from collections import Counter
N = int(input())
A = list(map(int, input().split())) 
ans = set(A)
for k, v in Counter(A).items():
    if v != 1:
        ans.discard(k)
    temp = {k*i for i in range(2,10**6//k + 1)}
    ans -= ans&temp
print(len(ans))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split())) 
A.sort()
ans = [0] * (10**6+1)
watched = set()
for i in A:
    ans[i] = 1
for i in range(N-1):
    if A[i] == A[i+1]:
        ans[A[i]] = 0
    temp = A[i]
    if temp in watched:
        continue       
    for j in range(i+1, N):
        if A[j]%temp == 0:
            ans[A[j]] = 0
            watched.add(A[j])
print(sum(ans))

Fixed submission:
from collections import Counter
N = int(input())
A = list(map(int, input().split())) 
ans = set(A)
for k, v in Counter(A).items():
    if v != 1:
        ans.discard(k)
    temp = {k*i for i in range(2,10**6//k + 1)}
    ans -= ans&temp
print(len(ans))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split())) 
lim = 10**18
ans = 1
for i in A:
    ans *= i
if ans > lim:
        print("-1")
else:
    print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split())) 
lim = 10**18
ans = 1
if 0 in A:
    print(0)
    quit()
for i in A:
    ans *= i
    if ans > lim:
        print("-1")
        quit()

print(ans)
Buggy python submission (verdict: Runtime Error):
from decimal import Decimal
A, B = map(input().split())
B = B.replace('.', '')
A = int(A)
B = int(B)

print(int(A*B//100))

Fixed submission:
A, B = input().split()
B = B.replace('.', '')
A = int(A)
B = int(B)

print(int(A*B//100))
Buggy python submission (verdict: Runtime Error):
N, K = map(int,input().split())
A = list(map(int, input().split())) 
check = [0]*N
tele_lis = []
global start
start = []
def tele(x):
    check[x-1] = 1
    tele_lis.append(x)
    if check[A[x-1]-1] == 0:
        tele(A[x-1])
    else:
        start.append(A[x-1])
        return
tele(1)
for i in range(N):
    if start[0] == tele_lis[i]:
        break
    
print(tele_lis[i::][(K-i) % (sum(check)-i)])

Fixed submission:
import sys
sys.setrecursionlimit(10**7)

N, K = map(int,input().split())
A = list(map(int, input().split())) 
check = [0]*N
tele_lis = []
start = []
def tele(x):
    check[x-1] = 1
    tele_lis.append(x)
    if check[A[x-1]-1] == 0:
        tele(A[x-1])
    else:
        start.append(A[x-1])
        return
tele(1)
for i in range(N):
    if start[0] == tele_lis[i]:
        break
if i >= K:
    print(tele_lis[K])
else:
    print(tele_lis[i::][(K-i) % (sum(check)-i)])
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
arg = np.argsort(A)
B = np.sort(A)
count = 0
for i in range(N):
    for j in range(i+1,N):
        if B[i] + B[j] ==  abs(arg[j] - arg[i]):
            count += 1
        if B[i] + B[j] > N:
            break
print(count)

Fixed submission:
from collections import Counter

N = int(input())
A = list(map(int,input().split()))

l = []
r = []
for i,j in enumerate(A):
    l.append(i+j)
    r.append(i-j)

num_l = Counter(l)
num_r = Counter(r)

ans = 0
for k, v in num_l.items():
    ans += num_r[k]*v
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
temp = []
for i in range(N):
    x = input()
    if not x in temp:
        temp.append(x)
print(len(temp))

Fixed submission:

N = int(input())
s = set()
for i in range(N):
    x = input()
    s.add(x)
print(len(s))
Buggy python submission (verdict: Time Limit Exceeded):
import collections
S = input()
N = len(S)
mod = 2019
div = [0]*N
for i in range(1, N+1):
    div[i-1] = int(S[N-i:N])%mod
d = collections.Counter(div)
print(sum(d.values())-len(d)+d[0])   

Fixed submission:
import collections
S = input()
N = len(S)
mod = 2019
div = [0]*(N+1)
for i in range(N):
    div[i+1] = (div[i] + int(S[N-1-i])*pow(10,i,mod))%mod
d = collections.Counter(div[1::])
ans = d[0]
for i in d.values():
    ans += i*(i-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
S = input()
N = len(S)
mod = 2019
div = [0]*N
for i in range(1, N+1):
    div[i-1] = int(S[N-i:N])%mod
d = collections.Counter(div)
print(sum(d.values())-len(d)+d[0])    


Fixed submission:
import collections
S = input()
N = len(S)
mod = 2019
div = [0]*(N+1)
for i in range(N):
    div[i+1] = (div[i] + int(S[N-1-i])*pow(10,i,mod))%mod
d = collections.Counter(div[1::])
ans = d[0]
for i in d.values():
    ans += i*(i-1)//2
print(ans)
Buggy python submission (verdict: Runtime Error):
import networkx as nx
from collections import Counter
import itertools
#import numpy as np

N, X, Y = map(int,input().split())
G = nx.Graph()
Node = range(N)
G.add_nodes_from(Node)
Edge = []
for i in range(N-1):
    Edge.append((i,i+1))
G.add_edges_from(Edge)
G.add_edge(X-1, Y-1)
path = dict(nx.all_pairs_shortest_path_length(G))
length = []

#辞書から値を削除（同じ頂点には行かない）
for i in range(N):
    del path[i][i]
#値だけとりだす
for i in range(N):
    length.append(list(path[i].values()))
#一次元にしてカウント
step = list(itertools.chain.from_iterable(length))
count = Counter(step)
ma = max(step)
for i in range(1,ma+1):
    print(count[i]//2)
for i in range(ma+1, N):
    print(0)

Fixed submission:
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix

N, X, Y = map(int,input().split())
l = [[0]*(N) for _ in range(N)]
for i in range(N-1):
    l[i][i+1] = 1
    l[i+1][i] = 1
l[X-1][Y-1] = 1
l[Y-1][X-1] = 1
csr = csr_matrix(l)
step = np.array(np.ravel(dijkstra(csr, unweighted=True)), dtype=int)
memo = np.bincount(step)//2
ma = np.max(step)
for i in range(1,ma+1):
    print(memo[i])
for i in range(ma+1, N):
    print(0)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix

N, X, Y = map(int,input().split())
l = [[0]*(N) for _ in range(N)]
for i in range(N-1):
    l[i][i+1] = 1
    l[i+1][i] = 1
l[X-1][Y-1] = 1
l[Y-1][X-1] = 1
csr = csr_matrix(l)
step = np.array(np.ravel(floyd_warshall(csr, unweighted=True)), dtype=int)
memo = np.bincount(step)
ma = np.max(step)
for i in range(1,ma+1):
    print(memo[i]//2)
for i in range(ma+1, N):
    print(0)

Fixed submission:
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix

N, X, Y = map(int,input().split())
l = [[0]*(N) for _ in range(N)]
for i in range(N-1):
    l[i][i+1] = 1
    l[i+1][i] = 1
l[X-1][Y-1] = 1
l[Y-1][X-1] = 1
csr = csr_matrix(l)
step = np.array(np.ravel(dijkstra(csr, unweighted=True)), dtype=int)
memo = np.bincount(step)//2
ma = np.max(step)
for i in range(1,ma+1):
    print(memo[i])
for i in range(ma+1, N):
    print(0)
Buggy python submission (verdict: Runtime Error):
h, w = map(int,input().split())
if h == 1 or w == 1:
    print(1)
else h%2 == 1 and w%2 == 1:
    print((h*w+1)//2)
elif:
    print(h*w//2)

Fixed submission:
h, w = map(int,input().split())
if h == 1 or w == 1:
    print(1)
elif h%2 == 1 and w%2 == 1:
    print((h*w+1)//2)
else:
    print(h*w//2)
Buggy python submission (verdict: Runtime Error):
N, M = map(int,input().split())
num = [0,1,2,3,4,5,6,7,8,9]
ans = [str(i) for i in range(10**(N-1), 10**N)]
check = [1 for i in range(10**(N-1), 10**N)]
if N == 1:
    ans.insert(0,0)
    check.insert(0,1)

for i in range(M):
    s, c = map(int,input().split())
    s -= 1
    for idx, j in enumerate(ans):
        if j[s] != str(c):
            check[idx] = 0
for idx, i in enumerate(check):
    if i == 1:
        print(ans[idx])
        quit()
print(-1)

Fixed submission:
N, M = map(int,input().split())
num = [0,1,2,3,4,5,6,7,8,9]
ans = [str(i) for i in range(10**(N-1), 10**N)]
check = [1 for i in range(10**(N-1), 10**N)]
if N == 1:
    ans.insert(0,"0")
    check.insert(0,1)

for i in range(M):
    s, c = map(int,input().split())
    s -= 1
    for idx, j in enumerate(ans):
        if j[s] != str(c):
            check[idx] = 0
for idx, i in enumerate(check):
    if i == 1:
        print(ans[idx])
        quit()
print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0

for i in range(n):
    for j in range(i+1, n):
        ans += bisect.bisect_left(l[j+1:], l[i] + l[j])
print(ans)

Fixed submission:
import bisect
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(n):
    for j in range(i+1, n):
        ans += bisect.bisect_left(l, l[i] + l[j]) - j - 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import bisect
n = int(input())
l = np.array(list(map(int, input().split())))
l = np.sort(l)
ans = 0

for i in range(n):
    for j in range(i+1, n):
        ans += bisect.bisect_left(l[j+1:], l[i] + l[j])
print(ans)

Fixed submission:
import bisect
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(n):
    for j in range(i+1, n):
        ans += bisect.bisect_left(l, l[i] + l[j]) - j - 1
print(ans)

Buggy python submission (verdict: Runtime Error):
import numpy as np
import bisect
n = int(input())
l = np.array(list(map(int, input().split())))
l = np.sort(l)
l_unique, l_uniue_index = np.unique(l, return_counts = True)
m = len(l_unique)
ans = 0

ans += len(np.where(l_uniue_index >= 3)[0])
print(ans)

for a in l_unique[np.where(l_uniue_index >= 2)[0]]:
    ans += bisect.bisect_left(l_unique, a * 2) - 1
print(ans)    
    
for i in range(m):
    for j in range(i+1, m):
        ans += bisect.bisect_left(l_unique[j+1:], l_unique[i] + l_unique[j])
print(ans)

Fixed submission:
import bisect
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(n):
    for j in range(i+1, n):
        ans += bisect.bisect_left(l, l[i] + l[j]) - j - 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n = int(input())
l = np.array(list(map(int, input().split())))
l = np.sort(l)
ans = 0
for i in range(n):
    for j in range(i + 1, n):
        ans += l[j+1:][l[j+1:] < l[i] + l[j]].size
print(ans)

Fixed submission:
import bisect
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(n):
    for j in range(i+1, n):
        ans += bisect.bisect_left(l, l[i] + l[j]) - j - 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math
n, m = map(int,input().split())
a = list(map(int,input().split()))
for i in range(m):
    a[a.index(max(a))] = a[a.index(max(a))]/2
for i in range(len(a)):
    a[i] = math.floor(a[i])
print(sum(a))

Fixed submission:
from heapq import heappop, heappush, heapify

N, M = map(int,input().split())
A = list(map(int, input().split()))
A = list(map(lambda x: x*(-1), A))
heapify(A)

for i in range(M):
    temp = int(heappop(A)/2)
    heappush(A, temp)

print(-sum(A))

Buggy python submission (verdict: Time Limit Exceeded):
import math
n, m = map(int,input().split())
a = list(map(int,input().split()))
for i in range(m):
    a[a.index(max(a))] = a[a.index(max(a))]/2
for i in range(len(a)):
    a[i] = math.floor(a[i])
print(sum(a))

Fixed submission:
from heapq import heappop, heappush, heapify

N, M = map(int,input().split())
A = list(map(int, input().split()))
A = list(map(lambda x: x*(-1), A))
heapify(A)

for i in range(M):
    temp = int(heappop(A)/2)
    heappush(A, temp)

print(-sum(A))
Buggy python submission (verdict: Runtime Error):



def bitsum(bit,i):
    s = 0
    while i > 0:
        s += bit[i]
        i -= i&(-i)
    return s
    

def bitadd(bit,i,x):
    while i <= N:
        bit[i] += x
        i += i&(-i)
    return bit
    
#################################
import math
N, K = map(int,input().split())
a = list(map(int,input().split()))


n_ = int(math.log2(N)) + 1
bit = [0] * (2**n_)
bit.append(0)

################################
ass = 0
for j in range(N):
    ass += j-bitsum(bit,a[j])
    bit = bitadd(bit,a[j],1)

Ans = ass*(K*(K+1)/2)+(N*(N-1)/2-ass)*(K*(K-1)/2)

print(int(Ans%(10^9+7)))

Fixed submission:
N, K = map(int,input().split())
An = list(map(int,input().split()))
f_count = 0
r_count = 0

for i in range(N):
    for j in range(N):
        if i < j:
            if An[i] < An[j]:
                f_count += 1
            elif An[i] > An[j]:
                r_count += 1

Ans = (f_count * K*(K-1)//2 + r_count * (K*(K+1)//2)) % (10**9+7)

print(int(Ans))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
N = int(input())
Si = [input() for _ in range(N)]

count = 0
for i in range(0, N):
    C1 = Counter(Si[i])
    for j in range(i+1, N):
        if C1 == Counter(Si[j]):
            count += 1
        else:
            pass
print(int(count))            

Fixed submission:
from collections import Counter
N = int(input())
S = ["".join(sorted(input())) for i in range(N)]
ans = 0
for i in Counter(S).values():
    ans += i*(i-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
N = int(input())
Si = [input() for _ in range(N)]

count = 0
for i in range(0, N):
    for j in range(i+1, N):
        if Counter(Si[i]) == Counter(Si[j]):
            count += 1
        else:
            pass
print(int(count))   

Fixed submission:
from collections import Counter
N = int(input())
S = ["".join(sorted(input())) for i in range(N)]
ans = 0
for i in Counter(S).values():
    ans += i*(i-1)//2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):

N, M = map(int, input().split())

AB_list = [list(map(int,input().split())) for i in range(N)]
check = [0]*N
B = 0
flag = 0
payment = 0
for i in range(1, M+1):
    for j in range(0, N):
        if (AB_list[j][0] <= i) and (check[j] == 0) and (AB_list[j][1] > B):
            B = AB_list[j][1]
            c = j
            flag = 1
        
    payment = payment + B
    if flag == 1:
        check[c] = 1
    B = 0

print(payment)

Fixed submission:
from heapq import heappush, heappop
import sys
input = sys.stdin.buffer.readline

N, M = map(int,input().split())
work = [[] for _ in range(10**5+1)]
ava = []
ans = 0

for i in range(N):
    A, B = map(int,input().split())
    work[A].append(-B)

for i in range(1, M+1):
    if len(work[i]) > 0:
        for j in work[i]:
            heappush(ava, j)
    if len(ava) > 0:
        ans -= heappop(ava)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
N = len(S)
mod = 10**9+7
dp = [[0] * N for _ in range(13)]

if S[0] == "?":
    for i in range(10):
        dp[i][0] = 1
else:
    dp[int(S[0])][0] = 1
        
for i in range(1, N):
    if S[i] == "?":
        for s in range(10):
            for x in range(13):
                dp[(x*10 + s)%13][i] += dp[x][i-1]
    else:
        for x in range(13):
            dp[(x*10 + int(S[i]))%13][i] += dp[x][i-1] 
    for t in range(13):
        dp[t][i] = dp[t][i]%mod
print(dp[5][N-1])  

Fixed submission:
S = input()
N = len(S)
mod = 10**9+7
dp = [[0] * N for _ in range(13)]

if S[0] == "?":
    for i in range(10):
        dp[i][0] = 1
else:
    dp[int(S[0])][0] = 1
        
for i in range(1, N):
    if S[i] == "?":
        for s in range(10):
            for x in range(13):
                dp[(x*10 + s)%13][i] += dp[x][i-1]
    else:
        for x in range(13):
            dp[(x*10 + int(S[i]))%13][i] += dp[x][i-1] 
    for t in range(13):
        dp[t][i] = dp[t][i]%mod
print(dp[5][N-1])
Buggy python submission (verdict: Runtime Error):
import numpy as np
n = int(input())
a = [input() for _ in range(n)]
a_sort = sorted(a)
for i in range(n):
    if i == np.argmax(a):
        print(a_sort[-2])
    else:
        print(a_sort[-1])

Fixed submission:
import sys
input = sys.stdin.buffer.readline
N = int(input())
A = [int(input()) for _ in range(N)]
B = A[:]
max1 = max(A)
A.remove(max1)
max2 = max(A)

for i in B:
    if i == max1:
        print(max2)
    else:
        print(max1)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import sys
def input():
    return sys.stdin.readline()[:-1]
n = int(input())
a = list(map(int,input().split()))
ans = np.array(a)
k = 2
for i in range(n, 0, -1):
    if n/k < i:
        for x in range(2, k):
            ans[i-1] += ans[x * i - 1]
        ans[i-1] = ans[i-1] % 2
    else:
        while n/k >= i:
            k += 1
        else:
            for x in range(2, k):
                ans[i-1] += ans[x * i - 1]
            ans[i-1] = ans[i-1] % 2
print(np.sum(ans))
for p in np.ndarray.flatten(np.argwhere(ans) + 1):
    print(p, end=' ')

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
ans = []
k = 2
for i in range(n, 0, -1):
    if n/k < i:
        for x in range(2, k):
            a[i-1] += a[x * i - 1]
        a[i-1] = a[i-1] % 2
    else:
        while n/k >= i:
            k += 1
        else:
            for x in range(2, k):
                a[i-1] += a[x * i - 1]
            a[i-1] = a[i-1] % 2
    if a[i-1] == 1:
        ans.append(i)
print(len(ans))
print(*ans)

Buggy python submission (verdict: Time Limit Exceeded):

import numpy as np
n = int(input())
a = list(map(int,input().split()))
ans = np.array(a)
k = 2
for i in reversed(range(1, n+1)):
    if n/k < i:
        for x in range(2, k):
            ans[i-1] += ans[x * i - 1]
        ans[i-1] = ans[i-1] % 2
    else:
        while n/k >= i:
            k += 1
        else:
            for x in range(2, k):
                ans[i-1] += ans[x * i - 1]
            ans[i-1] = ans[i-1] % 2
print(np.sum(ans))
for p in np.ndarray.flatten(np.argwhere(ans) + 1):
    print(p, end=' ')

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
ans = []
k = 2
for i in range(n, 0, -1):
    if n/k < i:
        for x in range(2, k):
            a[i-1] += a[x * i - 1]
        a[i-1] = a[i-1] % 2
    else:
        while n/k >= i:
            k += 1
        else:
            for x in range(2, k):
                a[i-1] += a[x * i - 1]
            a[i-1] = a[i-1] % 2
    if a[i-1] == 1:
        ans.append(i)
print(len(ans))
print(*ans)