Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
4
1 2 3 4

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

from collections import Counter
a=Counter(a)
a=sorted(a.items(), reverse=True)

x=0
y=0

for p,q in a:
  if q>=4:
    if x==0:
      x=y=p
      break
    else:
      y=p
      break
  elif q>=2:
    if x==0:
      x=p
    else:
      y=p
      break
print(x*y)

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))

from collections import Counter
a=Counter(a).most_common()

li=[]
li4=[]

for x,y in a:
  if  y>=4:
    li4.append(x)
  elif y>=2:
    li.append(x)

li.sort()
li4.sort()

if len(li4)<1 and len(li)<2:
  print(0)
  exit()

x=0
if li4:
  x=(li4[-1])**2

y=li[-1]*li[-2]

print(max(x,y))

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

from collections import Counter
a=Counter(a)
a=sorted(a.items(), reverse=True)

x=0
y=0

for p,q in a:
  if q>=4:
    if x==0:
      x=y=p
      break
    else:
      y=p
      break
  elif q>=2:
    if x==0:
      x=p
    else:
      y=p
      break
print(x*y)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
li=[0]*n
for i in range(n):
  a,b=map(int,input().split())
  li[a-1]+=1
  li[b-1]+=1
for i in li:
  print(i)

Fixed submission:
n,m=map(int,input().split())
li=[0]*n
for i in range(m):
  a,b=map(int,input().split())
  li[a-1]+=1
  li[b-1]+=1
for i in li:
  print(i)
Buggy python submission (verdict: Time Limit Exceeded):
k,s=map(int,input().split())
ans=0
for i in range(s+1):
  for j in range(i,s+1):
    if i<=k and j-i<=k and s-j<=k:
      ans+=1
print(ans)

Fixed submission:
k,s=map(int,input().split())
ans=0
for i in range(s+1):
  for j in range(i,s+1):
    if i<=k and j-i<=k and s-j<=k:
      ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
h,w=map(int,input().split())
for i in range(w):
  a=input()
  print(a)
  print(a)

Fixed submission:
h,w=map(int,input().split())
for i in range(h):
  a=input()
  print(a)
  print(a)
Buggy python submission (verdict: Runtime Error):
n,x=map(int,input().split())
a=list(map(int,input().split()))
ans=0
for i in range(n-1):
  if a[i]+a[i+1]>x:　#xを上回る時のみ操作を行う
    temp=a[i]+a[i+1]-x #減らさなきゃいけない個数
    ans+=temp
    if a[i+1]>=temp: #減らすのは出来るだけ右側
      a[i+1]-=temp
    else:
      a[i+1]=0
print(ans)

Fixed submission:
n,x=map(int,input().split())
a=list(map(int,input().split()))
ans=0
for i in range(n-1):
  if a[i]+a[i+1]>x: #xを上回る時のみ操作を行う
    temp=a[i]+a[i+1]-x #減らさなきゃいけない個数
    ans+=temp
    if a[i+1]>=temp: #減らすのは出来るだけ右側
      a[i+1]-=temp
    else:
      a[i+1]=0
print(ans)
Buggy python submission (verdict: Runtime Error):
T = list(input())

x = 0
while len(T) != 0:
    x += sum([int(f) for f in T[::2]])

    xmax = 0
    delIdx = 0
    for i in range(len(T)):
        T_copy = T.copy()
        _tmp = T_copy.pop(i)

        _x = sum([int(f) for f in T_copy[::2]])

        if _x > xmax:
            xmax = _x
            delIdx = i

    T.pop(delIdx)

print(x)

Fixed submission:
inputs = input()

H1, M1, H2, M2, K = [int(f) for f in inputs.split(" ")]

elapsedHour = H2 - H1
elapsedMin = M2 - M1

maxStudyStartTimeLength = elapsedHour * 60 + elapsedMin - K

print(maxStudyStartTimeLength)
Buggy python submission (verdict: Time Limit Exceeded):
T = input()

while "?" in T:
    idx = T.find("?")
    if idx == len(T) - 1:
        T = T[:-1] + "D"
    elif idx == 0:
        if T[idx + 1] == "D":
            T = "P" + T[idx + 1 :]
        else:
            T = "D" + T[idx + 1 :]
    else:
        if T[idx + 1] == "D":
            T = T[:idx] + "P" + T[idx + 1 :]
        else:
            T = T[:idx] + "D" + T[idx + 1 :]

print(T)

Fixed submission:
T = list(input())

for i in range(len(T)):
    if T[i] == "?":
        if i == len(T) - 1:
            T[i] = "D"
        else:
            if i > 0 and T[i - 1] == "P":
                T[i] = "D"
            elif T[i + 1] == "D" or T[i + 1] == "?":
                T[i] = "P"
            else:
                T[i] = "D"

print("".join(T))
Buggy python submission (verdict: Runtime Error):
def Int():
    return int(input())
def Ints():
    return map(int,input().split())
def IntList():
    return list(Ints())
def IntMat(N):
    return [IntList() for i in range(N)]

import sys
sys.setrecursionlimit(4100000)
input = sys.stdin.readline

N = Int()
AB = []
mod = 1000000007
ans = 1
C = 0

from collections import defaultdict
XX = defaultdict(list)
YY = defaultdict(list)

for i in range(N):
    A,B = Ints()
    if A!=0 or B!=0:
        AB.append([A,B])
        C += 1
        XX[A/B].append(i)
        YY[-B/A].append(i)

D = {}

for key in XX:
    if not key in D:
        l = len(XX[key])
        m = len(YY[key])
        ans *= (pow(2,l,mod)+pow(2,m,mod)-1)
        ans %= mod
        D[key] = 1
        D[-1/key] = 1
    
ans -= 1
ans %= mod
print(ans)

Fixed submission:
def Int():
    return int(input())
def Ints():
    return map(int,input().split())
def IntList():
    return list(Ints())
def IntMat(N):
    return [IntList() for i in range(N)]

import sys
sys.setrecursionlimit(4100000)
input = sys.stdin.readline

N = Int()
mod = 1000000007
ans = 1
import math

from collections import defaultdict
XX = defaultdict(list)
YY = defaultdict(list)

zeros = 0

for i in range(N):
    A,B = Ints()
    if A!=0 and B!=0:
        GCD = math.gcd(A,B)
        A //=GCD
        B //=GCD
        if A<0 and B<0:
            A *= -1
            B *= -1
        elif A>0 and B<0:
            A *= -1
            B *= -1
        XX[(A,B)].append(i)
        
        B *= -1
        if A<0 and B<0:
            A *= -1
            B *= -1
        elif A<0 and B>0:
            A *= -1
            B *= -1
        YY[(B,A)].append(i)
        
    elif A==0 and B!=0:
        XX[(0,1)].append(i)
        YY[(1,0)].append(i)
    elif A!=0 and B==0:
        XX[(1,0)].append(i)
        YY[(0,1)].append(i)
    else:
        zeros += 1


D = {}

for key in XX:
    if not key in D:
        l = len(XX[key])
        m = len(YY[key])
        ans *= (pow(2,l,mod)+pow(2,m,mod)-1)
        ans %= mod
        D[key] = 1
        
        a,b = key
        if a==0 and b==1:
            D[(1,0)] = 1
        elif a==1 and b==0:
            D[(0,1)] = 1
        else:
            b *= -1
            if a < 0:
                b*=-1
                a*=-1
            D[(b,a)] = 1
    
ans -= 1
ans += zeros
ans %= mod
print(ans)
Buggy python submission (verdict: Runtime Error):
H,W = int(input())
print((H*W+1)//2)

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

if H==1 or W==1:
    print(1)
else:
    print((H*W+1)//2)
Buggy python submission (verdict: Runtime Error):
a,b,c = map(int,input().split())
if 4*a*b < c**2 + (a+b)**2 - 2*(a+b)*c
    print('Yes')
else:
    print('No')

Fixed submission:
a,b,c = map(int,input().split())

if a+b >= c:
    print('No')
elif 4*a*b < c**2 + (a+b)**2 - 2*(a+b)*c:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
muki = 1
one = ''
two = ''

for i in range(Q):
    I = input().split()
    if I[0] == '1':
        muki *= -1
    elif I[0] == '2':
        F = int(I[1])
        C = I[2]
        if F==1:
            if muki == 1:
                t = [one, C ]
                one = ''.join(t)
            else:
                t = [two, C ]
                two = ''.join(t)
        elif F==2:
            if muki == 1:
                t = [two, C ]
                two = ''.join(t)
            else:
                t = [one, C ]
                one = ''.join(t)
if muki == 1:
    ANS = [one[::-1],S,two]
    print(''.join(ANS))
else:
    ANS = [two[::-1],S[::-1],one]
    print(''.join(ANS))

Fixed submission:
S = input()
Q = int(input())
muki = 1
one = ''
two = ''

for i in range(Q):
    I = input().split()
    if I[0] == '1':
        muki *= -1
    elif I[0] == '2':
        F = int(I[1])
        C = I[2]
        if F==1:
            if muki == 1:
                t = [one, C ]
                one = ''.join(t)
            else:
                t = [two, C ]
                two = ''.join(t)
        elif F==2:
            if muki == 1:
                t = [two, C ]
                two = ''.join(t)
            else:
                t = [one, C ]
                one = ''.join(t)
if muki == 1:
    ANS = [one[::-1],S,two]
    print(''.join(ANS))
else:
    ANS = [two[::-1],S[::-1],one]
    print(''.join(ANS))
Buggy python submission (verdict: Runtime Error):
#include <vector> // vectorを使うためにインクルードする
#include <iostream>
using namespace std;

const int MAX_N = 1000;
const int MAX_M = 20000;

int n, H;
int w[MAX_N], v[MAX_N];
// dp[i+1][j]: i番目までの品物から重さの総和がj以下となるように選んだ時の,
// 価値の総和の最大値
int dp[MAX_N + 1][MAX_M + 1];

int main() {
    cin >> H;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> w[i] >> v[i];
    }

    for (int i = 0; i < n+1; i++) {
        for (int j = 0; j <= MAX_M+1; j++) {
            dp[i][j] = 100000000;
        }
    }
  for (int i = 0; i < n+1; i++) {
            dp[i][0] = 0;
    }
    
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= MAX_M; j++) {
            dp[i+1][j] = min(dp[i][j],dp[i+1][j-w[i]]+v[i]);
        }
    }
    int ans = 100000000;
  for (int i=H; i<MAX_M+1; i++){
  	ans = min(ans, dp[n][i]);
  }

    cout << ans << '\n';

    return 0;
}

Fixed submission:
H,N = map(int,input().split())
AB = []
 
for i in range(N):
    a,b = map(int,input().split())
    AB.append([a,b])
INF = 10**15
dp = [[INF]*(2*10**4+1) for i in range(N+1)]
for i in range(N+1):
    dp[i][0] = 0
 
for i in range(N):
    for j in range(1,2*10**4+1):
        dp[i+1][j] = min(dp[i][j],dp[i+1][j-AB[i][0]]+AB[i][1])
        
ans = float('inf')
for i in range(H,2*10**4+1):
    ans = min(ans,dp[N][i])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
H,N = map(int,input().split())
AB = []

for i in range(N):
    a,b = map(int,input().split())
    AB.append([a,b])
    
dp = [[float('inf')]*(2*10**4+1) for i in range(N+1)]
for i in range(N+1):
    dp[i][0] = 0

for i in range(N):
    for j in range(1,2*10**4+1):
        dp[i+1][j] = min(dp[i][j],dp[i+1][j-AB[i][0]]+AB[i][1])
        
ans = float('inf')
for i in range(H,2*10**4+1):
    ans = min(ans,dp[N][i])
print(ans)

Fixed submission:
H,N = map(int,input().split())
AB = []
 
for i in range(N):
    a,b = map(int,input().split())
    AB.append([a,b])
INF = 10**15
dp = [[INF]*(2*10**4+1) for i in range(N+1)]
for i in range(N+1):
    dp[i][0] = 0
 
for i in range(N):
    for j in range(1,2*10**4+1):
        dp[i+1][j] = min(dp[i][j],dp[i+1][j-AB[i][0]]+AB[i][1])
        
ans = float('inf')
for i in range(H,2*10**4+1):
    ans = min(ans,dp[N][i])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))

mod = 10**9 + 7

from fractions import gcd

def p_prime(n): 
    prime = [2]
    for i in range(3,n+1):
        flag = 0
        for j in prime:
            if i%j == 0:
                flag = 1
                break
            if i**0.5 < j:
                break
        if flag == 0:
            prime.append(i)
    return prime

def soinsuu(M):
    a = {}
    prime = p_prime(int(M**0.5+1))
    for p in prime:
        count = 0
        while M%p ==0:
            count += 1
            M //= p
        if count > 0:
            a[p] = count
    if M != 1:
        a[M] = 1
    return a

from collections import defaultdict
AA = defaultdict(int)

for i in range(N):
    tmp = soinsuu(A[i])
    for j in tmp:
        AA[j] = max(AA[j],tmp[j])

BB = 1
for k in AA:
    BB *= pow(k,AA[k],mod)
    BB %= mod
    
ans = 0
for i in range(N):
    ans += BB*pow(A[i],mod-2,mod)
    ans %= mod

    
print(ans%mod)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
mod = 10**9 + 7
 
from fractions import gcd
 
def lcm(a,b):
    return a//gcd(a,b)*b

AA = 1
for i in range(N):
    AA = lcm(AA,A[i])
AA %= mod

ans = 0
for i in range(N):
    ans += AA*pow(A[i],mod-2,mod)
    
print(ans%mod)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))

from fractions import gcd

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

AA = 1
for i in range(N):
    AA = lcm(AA,A[i])

ans = 0
for i in range(N):
    ans += AA//A[i]
    
mod = 10**9 + 7
print(ans%mod)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
mod = 10**9 + 7
 
from fractions import gcd
 
def lcm(a,b):
    return a//gcd(a,b)*b

AA = 1
for i in range(N):
    AA = lcm(AA,A[i])
AA %= mod

ans = 0
for i in range(N):
    ans += AA*pow(A[i],mod-2,mod)
    
print(ans%mod)
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
R,S,P = map(int,input().split())
win = {'r':P,'s':R,'p':S}
T = input()
WAKE = ['']*K

for i in range(N):
    WAKE[i%K] += T[i]

ans = 0
for i in range(K):
    if len(WAKE[i])>=0:
        pre = WAKE[i][0]
        ans += win[pre]
        for j in range(1,len(WAKE[i])):
            now = WAKE[i][j]
            if pre != now:
                ans += win[now]
                pre = now
            else:
                pre = ''
print(ans)

Fixed submission:
N,K = map(int,input().split())
R,S,P = map(int,input().split())
win = {'r':P,'s':R,'p':S}
T = input()
WAKE = ['']*K

for i in range(N):
    WAKE[i%K] += T[i]

ans = 0
for i in range(K):
    if len(WAKE[i])>=0:
        pre = WAKE[i][0]
        ans += win[pre]
        for j in range(1,len(WAKE[i])):
            now = WAKE[i][j]
            if pre != now:
                ans += win[now]
                pre = now
            else:
                pre = ''
print(ans)
Buggy python submission (verdict: Runtime Error):
N,T = map(int,input().split())
AB = [list(map(int,input().split())) for i in range(N)]
AB.sort(key=lambda x: x[1])
#print(AB)

W = T + 1
def dp(AB,W):
    N = len(AB)
    DP = [[0]*W for i in range(N+1)]
    for i in range(N):
        for w in range(W):
            if w != W:
                if AB[i][0] <= w:
                    DP[i+1][w] = max(DP[i][w-AB[i][0]]+AB[i][1],DP[i][w])
                else
                    DP[i+1][W] = DP[i][w]
            else:
                DP[i+1][w] = max(DP[i][w-1]+AB[i][1],DP[i][w])
    return DP

DP1 = dp(AB,W)

ans = DP1[N][W]
print(ans)

Fixed submission:
N,T = map(int,input().split())
AB = [list(map(int,input().split())) for i in range(N)]
AB.sort(key=lambda x: x[0])
#print(AB)

W = T + 1
def dp(AB,W):
    N = len(AB)
    DP = [[0]*W for i in range(N+1)]
    for i in range(N):
        for w in range(W):
            if w != W-1:
                if AB[i][0] <= w:
                    DP[i+1][w] = max(DP[i][w-AB[i][0]]+AB[i][1],DP[i][w])
                else:
                    DP[i+1][w] = DP[i][w]
            else:
                DP[i+1][w] = max(DP[i][w-1]+AB[i][1],DP[i][w])
    return DP

DP1 = dp(AB,W)

ans = DP1[N][T]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    input = sys.stdin.readline
    
    from collections import defaultdict
    import itertools
    import copy
    one = [True, False]
    
    N,M = map(int,input().split())
    dp = []
    for i in range(M+1):
        dp.append(defaultdict(lambda : float("inf")))
    dp[0][(False,)*N] = 0
    
    for i in range(1,M+1):
        #print(dp[M][(True,)*N])
        a,b = map(int,input().split())
        c = list(map(int,input().split()))
        for j in itertools.product(one, repeat = N):
            now = list(copy.deepcopy(j))
            for k in c:
                now[k-1] = True
            now = tuple(now)
            dp[i][j] = dp[i-1][j]
            dp[i][now] = min(dp[i][now],dp[i-1][now], dp[i-1][j]+a)
    
    if dp[M][(True,)*N] == float("inf"):
        print(-1)
    else:
        print(dp[M][(True,)*N])
            
    
    
main()

Fixed submission:
def main():
    import sys
    input = sys.stdin.readline
    
    from collections import defaultdict
    import itertools
    import copy
    
    N,M = map(int,input().split())
    dp = [[float("inf")]*(2**N) for i in range(M+1)]
    dp[0][0] = 0
    
    for i in range(1,M+1):
        #print(dp[M][(True,)*N])
        a,b = map(int,input().split())
        c = list(map(int,input().split()))
        tmp = 0
        for k in c:
            tmp += 2**(k-1)
        for j in range(2**N):
            now = j | tmp
            dp[i][j] = min(dp[i][j],dp[i-1][j])
            dp[i][now] = min(dp[i][now],dp[i-1][now], dp[i-1][j]+a)
            #print(dp[i][now],dp[i-1][now], dp[i-1][j]+a)
    
    if dp[M][2**N-1] == float("inf"):
        print(-1)
    else:
        print(dp[M][2**N-1])
            
    
    
main()
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
from collections import deque
dd = defaultdict(list)
pq = defaultdict(int)
 
N, Q = map(int, input().split())
 
for _ in range(N-1):
    a,b = map(int, input().split())
    dd[a].append(b)
    dd[b].append(a)
 
for _ in range(Q):
    p,q = map(int, input().split())
    pq[p] += q
    
answer = [0]*N
queue = deque()
visited = {}
visited[1] = 1
queue.append(1)
 
while queue != deque():
    tmp = queue.popleft()
    answer[tmp-1] += pq[tmp]
    for i in dd[tmp]:
        if not i in visited:
            visited[i] = 1
            queue.append(i)
            answer[i-1] += answer[tmp-1]
            
print(*answer)

Fixed submission:
def main():
    from collections import defaultdict
    from collections import deque
    import sys
    input = sys.stdin.readline
    dd = defaultdict(list)
    pq = defaultdict(int)

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

    for _ in range(N-1):
        a,b = map(int, input().split())
        dd[a].append(b)

    for _ in range(Q):
        p,q = map(int, input().split())
        pq[p] += q
    
    answer = [0]*N
    queue = deque()
    queue.append(1)

    while queue != deque():
        tmp = queue.popleft()
        answer[tmp-1] += pq[tmp]
        for i in dd[tmp]:
            queue.append(i)
            answer[i-1] += answer[tmp-1]
            
    print(*answer)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
from collections import deque
dd = defaultdict(list)
pq = defaultdict(int)

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

for _ in range(N-1):
    a,b = map(int, input().split())
    dd[a].append(b)
    dd[b].append(a)

for _ in range(Q):
    p,q = map(int, input().split())
    pq[p] += q
    
answer = [0]*N
queue = deque()
visited = {}
visited[1] = 1
queue.append(1)

while queue != deque():
    tmp = queue.popleft()
    answer[tmp-1] += pq[tmp]
    for i in dd[tmp]:
        if not i in visited:
            visited[i] = 1
            queue.append(i)
            answer[i-1] += answer[tmp-1]
            
print(*answer)



Fixed submission:
def main():
    from collections import defaultdict
    from collections import deque
    import sys
    input = sys.stdin.readline
    dd = defaultdict(list)
    pq = defaultdict(int)

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

    for _ in range(N-1):
        a,b = map(int, input().split())
        dd[a].append(b)

    for _ in range(Q):
        p,q = map(int, input().split())
        pq[p] += q
    
    answer = [0]*N
    queue = deque()
    queue.append(1)

    while queue != deque():
        tmp = queue.popleft()
        answer[tmp-1] += pq[tmp]
        for i in dd[tmp]:
            queue.append(i)
            answer[i-1] += answer[tmp-1]
            
    print(*answer)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    from collections import defaultdict
    import sys
    
    s = input()
    t = input()
    ds = defaultdict(int)
    di = {}

    for i in range(len(s)):
        di[i] = defaultdict(int)
    
    for a in s:
        ds[a] = 1
        
    flag = 0
    for b in t:
        if ds[b] == 0:
            flag = 1
    if flag == 1:
        print(-1)
        sys.exit()

    s2 = s[::-1]
    for i in range(2*len(s)):
        for j in di[len(s) - (i-1)%len(s)-1]:
            di[len(s) - i%len(s)-1][j] = di[len(s) - (i-1)%len(s)-1][j] + 1
        di[len(s) - i%len(s) - 1][s2[(i-1)%len(s)]] = 1
    tmp = t[0]

    for k in range(len(s)):
        if tmp == s[k]:
            answer = k+1
            break
    for k in range(len(t)-1):
        l = k+1
        answer += di[(answer-1)%len(s)][t[l]]
        tmp = t[l]
    print(answer)
      

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    from collections import defaultdict
    import sys
    
    s = input()
    t = input()
    ds = defaultdict(int)
    di = {}

    for i in range(len(s)):
        di[i] = defaultdict(int)
    
    for a in s:
        ds[a] = 1
        
    flag = 0
    for b in t:
        if ds[b] == 0:
            flag = 1
    if flag == 1:
        print(-1)
        sys.exit()

    s2 = s[::-1]
    for i in range(2*len(s)):
        for j in di[len(s) - (i-1)%len(s)-1]:
            di[len(s) - i%len(s)-1][j] = di[len(s) - (i-1)%len(s)-1][j] + 1
        di[len(s) - i%len(s) - 1][s2[(i-1)%len(s)]] = 1
    tmp = t[0]

    for k in range(len(s)):
        if tmp == s[k]:
            answer = k+1
            break
    for k in range(len(t)-1):
        l = k+1
        answer += di[(answer-1)%len(s)][t[l]]
        tmp = t[l]
    print(answer)
      

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())[::-1]
Now = [0 for _ in range(13)]
Next = [0 for _ in range(13)]
for i in range(len(S)):
    Next = [0 for _ in range(13)]
    if i == 0:
        if S[i] != "?":
            Next[int(S[i])] = 1
        else:
            Next = [1,1,1,1,1,1,1,1,1,1,0,0,0]
    else:
        if S[i] != "?":
            mod = (int(S[i])*10**i)%13
            for j in range(len(Now)):
                Next[(mod+j)%13] = (Next[(mod+j)%13] + Now[j])%(10**9+7)
        else:
            mod0 = (10**i)%13
            for j in range(10):
                mod = (mod0*j)%13
                for k in range(len(Now)):
                    Next[(mod+k)%13] = (Next[(mod+k)%13] + Now[k])%(10**9+7)
    Now = Next
print(Now[5])

Fixed submission:
S = list(input())[::-1]
Now = [0 for _ in range(13)]
Next = [0 for _ in range(13)]

if S[0] != "?":
    Next[int(S[0])] = 1
else:
    Next = [1,1,1,1,1,1,1,1,1,1,0,0,0]
Now = Next
modq = 1
for i in range(len(S)-1):
    i = i + 1
    Next = [0 for _ in range(13)]
    if S[i] != "?":
        mod = (int(S[i])*10*modq)%13
        for j in range(len(Now)):
            Next[(mod+j)%13] = (Next[(mod+j)%13] + Now[j])%(10**9+7)
        modq = (10*modq)%13
    else:
        modq = (10*modq)%13
        mod = 0
        for j in range(10):
            for k in range(len(Now)):
                Next[(mod+k)%13] = (Next[(mod+k)%13] + Now[k])%(10**9+7)
            mod = (mod + modq)%13
    Now = Next
print(Now[5])
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
answer = [0] * K
mod = 10**9+7
for i in range(1,K+1):
    M = N-K
    if M - (i-1) < 0:
        answer[i-1] = 0
    else:
        tmp = 1
        for j in range(i-1):
            tmp *= K-1-j
        for j in range(i-1):
            tmp /= j+1
        tmp %= mod
        for j in range(i):
            tmp *= M+1-j
        for j in range(i):
            tmp /= j+1
        tmp %= mod
        answer[i-1] = int(tmp)
print(*answer, sep="\n")

Fixed submission:
N, K = map(int, input().split())
answer = [0] * K
mod = 10**9+7
C_2000 = [0]*2001
C_2000[0] = 1
for i in range(1,2001):
    C_2000[i] = (C_2000[i-1] * i)%mod
def pow_r(x, n):
    """
    O(log n)
    """
    if n == 0:  # exit case
        return 1
    if n % 2 == 0:  # standard case ① n is even
        return (pow_r((x ** 2)%mod, n // 2))%mod
    else:  # standard case ② n is odd
        return (x * pow_r((x ** 2)%mod, (n - 1) // 2))%mod

for i in range(1,K+1):
    M = N-K
    if M - (i-1) < 0:
        answer[i-1] = 0
    else:
        tmp = (C_2000[K-1] * pow_r(C_2000[i-1],mod-2)*pow_r(C_2000[K-i],mod-2))%mod
        tmp = (tmp*C_2000[M+1] * pow_r(C_2000[i],mod-2) * pow_r(C_2000[M+1-i],mod-2))%mod
        answer[i-1] = int(tmp)
print(*answer, sep="\n")