Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03262 (python)

Fixed submission:
import math
from functools import reduce
N, X = map(int, input().split())
x = list(map(int,input().split()))
 
for i in range(N):
    x[i] = abs(x[i]-X)
 
x = sorted(x)[::-1]
cnt = 0
 
for i in range(N):
    cnt = math.gcd(cnt, x[i])
 
print(cnt)

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce
N, X = map(int, input().slpit())
x = list(map(int,input().split()))
 
for i in range(N):
    x[i] = abs(x[i]-X)
 
x = sorted(x)[::-1]
cnt = 0
 
for i in range(N):
    cnt = math.gcd(cnt, x[i])
 
print(cnt)

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce
N, X = map(int, input().slpit())
x = [int(input()) for i in range(N)]

for i in range(N):
    x[i] = abs(x[i]-X)

x = sorted(x)[::-1]
cnt = 0

for i in range(N):
    cnt = math.gcd(cnt, x[i])

print(cnt)

Buggy submission (verdict: Runtime Error):
import fractions
from functools import reduce
N, X = map(int, input().split())
x = [int(input()) for i in range(N)]
 
 
x.insert(0,X)
x = sorted(x)
 
y = [0]*N
 
for i in range(N):
    y[i] = x[i+1]-x[i]
 
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)
 
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
 
print(gcd(*y))

Buggy submission (verdict: Runtime Error):
import fractions
from functools import reduce
N, X = map(int, input().split())
x = [int(input()) for i in range(N)]


x.insert(0,X)
x = sorted(x)

y = [0 for i in range(N)]

for i in range(N):
    y[i] = x[i+1]-x[i]

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

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

print(gcd(*y))
Problem p03400 (python)

Fixed submission:
N=int(input())
D,X=map(int,input().split())
A=[int(input()) for _ in range(N)]
 
ans=0
 
for i in range(len(A)):
    ans = ans + (D-1)//A[i]+1
print(ans+X)

Buggy submission (verdict: Runtime Error):
N=int(input())
D,X=map(int, input().spilt())
A=[int(input()) for i in range(N)]

ans=0

for i in range(len(A)):
    ans += (D-1)//A[i]+1
print(ans+X)
Problem p03423 (python)

Fixed submission:
N=int(input())
 
print(N//3)

Buggy submission (verdict: Runtime Error):
N=int(intput())

print(N//3)
Problem p03424 (python)

Fixed submission:
N=int(input())
S=list(input().split())
 
if 'Y' in S:
  print('Four')
else:
  print('Three')

Buggy submission (verdict: Runtime Error):
N=int(input())
S=list(map(string, input().slipt()))

if 'Y' in S:
  print('Four')
else:
  print('Three')
Problem p03425 (python)

Fixed submission:
N=int(input())
S=[input() for _ in range(N)]
cnt=[0]*N
cnt2=[]
flag=0

if len(S)>1:
    for i in range(N):
        if S[i][0]=='M':
            cnt[0]+=1
        elif S[i][0]=='A':
            cnt[1]+=1
        elif S[i][0]=='R':
            cnt[2]+=1
        elif S[i][0]=='C':
            cnt[3]+=1
        elif S[i][0]=='H':
            cnt[4]+=1

for i in range(N):
    if cnt[i]!=0:
        cnt2.append(cnt[i])
        
import math
import itertools
ans=0

for v in itertools.combinations(cnt2, 3):
    ans+=v[0]*v[1]*v[2]

print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
S=[input() for _ in range(N)]
cnt=[0]*N
cnt2=[]
flag=0

for i in range(N):
    if S[i][0]=='M':
        cnt[0]+=1
    elif S[i][0]=='A':
        cnt[1]+=1
    elif S[i][0]=='R':
        cnt[2]+=1
    elif S[i][0]=='C':
        cnt[3]+=1
    elif S[i][0]=='H':
        cnt[4]+=1

for i in range(N):
    if cnt[i]!=0:
        cnt2.append(cnt[i])
        
import math
import itertools
ans=0

for v in itertools.combinations(cnt2, 3):
    ans+=v[0]*v[1]*v[2]

print(ans)
Problem p03435 (python)

Fixed submission:
c = [list(map(int, input().split())) for i in range(3)]

if c[0][0]+c[1][0]-2*c[2][0]+c[0][1]+c[1][1]-2*c[2][1]-2*c[0][2]-2*c[1][2]+4*c[2][2] == 0:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
c = [[int(input()) for i in range(3)] for i in range(3)]

if c[0][0]+c[1][0]-2*c[2][0]+c[0][1]+c[1][1]-2*c[2][1]-2*c[0][2]-2*c[1][2]+4*c[2][2] == 0:
  print("Yes")
else:
  print("No")
Problem p03457 (python)

Fixed submission:
n = int(input())
t=[0]
x=[0]
y=[0]
for i in range(n):
    _t, _x, _y = map(int, input().split())
    t.append(_t)
    x.append(_x)
    y.append(_y)

flag = 0
for i in range(1,n+1):
    dt = t[i] - t[i-1]
    dx = x[i] - x[i-1]
    dy = y[i] - y[i-1]
    dist = abs(dx) + abs(dy)
    if dist > dt:
        flag = flag +1
    elif dist % 2 != dt % 2:
        flag = flag +1
else:
    print("Yes" if flag ==0 else "No")

Buggy submission (verdict: Runtime Error):
N = int(input())
a = [input().split() for _ in range(N)]
flag = 0
 
if N >1: 
  for i in range(N-1):
    dt = a[i+1][0]-a[i][0]
    dist = abs(a[i+1][1]-a[i][1])+abs(a[i+1][2]-a[i][2])
    if dt < dist:
      flag = flag +1
    if dt % 2 != dist % 2:
      flag = flag +1
else:
  dt = a[0]
  dist = abs(a[1])+abs(a[2])
  if dt < dist:
      flag = flag +1
  if dt % 2 != dist % 2:
      flag = flag +1
    
print('Yes' if flag == 0 else 'No')

Buggy submission (verdict: Runtime Error):
N = int(input())
a = [list(map(int, input().split())) for i in range(N)]
flag = 0
 
if N >1: 
  for i in range(N-1):
    dt = a[i+1][0]-a[i][0]
    dist = abs(a[i+1][1]-a[i][1])+abs(a[i+1][2]-a[i][2])
    if dt < dist:
      flag = flag +1
    if dt % 2 != dist % 2:
      flag = flag +1
else:
  dt = a[0]
  dist = abs(a[1])+abs(a[2])
  if dt < dist:
      flag = flag +1
  if dt % 2 != dist % 2:
      flag = flag +1
    
print('Yes' if flag == 0 else 'No')

Buggy submission (verdict: Runtime Error):
N = int(input())
a = [list(map(int, input().split())) for i in range(N)]
flag = 0

for i in range(N):
  dt = a[i+1][0]-a[i][0]
  dist = abs(a[i+1][1]-a[i][1])+abs(a[i+1][2]-a[i][2])
  if dt > dist:
    flag = flag +1
  else dt % 2 != dist % 2:
    flag = flag +1

print('Yes' if flag == 0 else 'No')
Problem p03477 (python)

Fixed submission:
A, B, C, D = map(int, input().split())
print('Left' if A + B > C + D else 'Balanced' if A + B == C + D else 'Right')

Buggy submission (verdict: Runtime Error):
A, B, C, D = map(int, input().split())
print('Left' if A + B > C + D, else 'Balanced' if A + B == C + D else 'Right')
Problem p03497 (python)

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


import collections

c = collections.Counter(a)
c2=sorted(c.values())

sum=0
for i in range(len(c)-K):
        sum+=c2[i]
print(sum)

Buggy submission (verdict: Runtime Error):
N K= map(int, input().split())
A =list(map(int, input().split()))

Aset =list(set(A))
B=[0]*len(Aset)
cnt =0

for i in range(len(Aset)):
  for j in range(len(A)):
    if Aset[i] == A[j]:
      cnt += 1
  B[i] = cnt
  cnt =0

B=sorted(B)[::-1]  

ans =0

for i in range(K,len(B)):
  ans +=B[i]
  
print(ans)
Problem p03501 (python)

Fixed submission:
N, A, B = map(int, input().split())
print(min(N*A, B))

Buggy submission (verdict: Runtime Error):
N, A, B = map(int, input().split())
print(min(N*a, B))
Problem p03502 (python)

Fixed submission:
N = input()
f = sum(map(int, N))
print("Yes" if int(N) % f == 0 else "No")

Buggy submission (verdict: Runtime Error):
N = input()
f = sum(map(int, N))
print("Yes" int(N) % f == 0 else "No")
Problem p03545 (python)

Fixed submission:
S = input()

for i in range(2**3):
    op = ['-']*3
    for j in range(3):
        if (i >> j) &1:
            op[3 - 1 - j] ='+'
    if eval(S[0] +op[0] +S[1]+ op[1]+S[2] +op[2] +S[3]) ==7:
        print(S[0] +op[0] +S[1]+ op[1]+S[2] +op[2] +S[3]+'=7')
        break

Buggy submission (verdict: Runtime Error):
A,B,C,D =input().split()

for i in range(2**3):
    op = ['-']*3
    for j in range(3):
        if (i >> j) &1:
            op[3 - 1 - j] ='+'
    if eval(A +op[0] +B+ op[1]+C +op[2] +D) ==7:
        print(A +op[0] +B+ op[1]+C +op[2] +D+'=7')
        break
Problem p03635 (python)

Fixed submission:
n, m = map(int, input().split())
print((n-1)*(m-1))

Buggy submission (verdict: Runtime Error):
n = int(input())
m = int(input())
print((n-1)*(m-1))

Buggy submission (verdict: Runtime Error):
n = int(input())
m = int(input())
print((n -1 )*(m - 1))
Problem p03636 (python)

Fixed submission:
s = input()
x = len(s)-2
print(s[0] + str(x) + s[-1])

Buggy submission (verdict: Runtime Error):
s = input()
print(str(s[0]) + len(s)-2 + str(s[-1]))
Problem p03643 (python)

Fixed submission:
N = input()
print("ABC" + N)

Buggy submission (verdict: Runtime Error):
N = input()
print(ABC + "N")
Problem p03658 (python)

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

l = sorted(l)[::-1]
print(sum(l[0:K]))

Buggy submission (verdict: Runtime Error):
N, K =map(int, input().split())
l = [map(int, input().split())]

l = sorted(l)[::-1]
ans = 0
for i in range(K):
  ans += l[i]

print(ans)
Problem p03777 (python)

Fixed submission:
a, b = input().split()
print ("H" if a == "H" and b == "H" else "H" if a == "D" and b == "D" else "D")

Buggy submission (verdict: Runtime Error):
a, b = map(input().split())
print ("H" if a == "H" and b == "H" else "H" if a == "D" and b == "D" else "D")
Problem p03778 (python)

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

if a+W<b:
  print(b-(W+a))
elif b+W<a:
  print(a-(W+b))
else:
  print(0)

Buggy submission (verdict: Runtime Error):
W,a,b=map(int,input().split())

if a+W<b:
  print(b-(W+a)):
else:
  print(0)
Problem p03796 (python)

Fixed submission:
import math
N = int(input())
print((math.factorial(N))%(10**9+7))

Buggy submission (verdict: Runtime Error):
import math
N = int(input())
print((math.factorial(N))/(10^9+7))
Problem p03853 (python)

Fixed submission:
h, w = map(int, input().split())  
for i in range(h):
    s = input()
    print(s)
    print(s)

Buggy submission (verdict: Runtime Error):
H,W=map(int, input().split())
c=[list(input()) for i in range(W)]
a=[0]*W
ans=''
   
for i in range(2*H):
    ans=''
    for j in range(W):
        #print((i)//2)
        a[j]=c[int((i)//2)][j]
        ans+=a[j]
    print(ans)

Buggy submission (verdict: Runtime Error):
H,W=map(int, input().split())
c=[input().split() for i in range(W)]
a=[0]*W
ans=''
   
for i in range(2*H):
    ans=''
    for j in range(W):
        #print((i)//2)
        a[j]=c[int((i)//2)][j]
        ans+=a[j]
    print(ans)
Problem p03937 (python)

Fixed submission:
H,W=map(int, input().split())
a = [input() for i in range(H)]

ans=0
cnt=0
 
for i in range(H-1):
    for j in range(W-1):
        if a[i][j] == '#' and a[i+1][j] == '#' and  a[i][j+1] == '#':
            cnt+=1
        elif a[i][j] == '#' and a[i+1][j] == '.' and  a[i][j+1] == '.':
            cnt+=1

            
for i in range(1,H):
    for j in range(1,W):
        if a[i][j] == '#' and a[i-1][j] == '.' and  a[i][j-1] == '.':
            cnt+=1

        
print('Impossible' if cnt>0 else 'Possible')

Buggy submission (verdict: Runtime Error):
H,W=4,5
a = [input() for i in range(H)]


ans=0
cnt=0

for i in range(H-1):
    for j in range(W-1):
        if a[i][j] == '#' and a[i+1][j] == '#' and  a[i][j+1] == '#':
            cnt+=1
            break
        elif a[i][j] == '#' and a[i+1][j] == '.' and  a[i][j+1] == '.':
            cnt+=1
            break
        else:
            continue
 
print('Impossible' if cnt>0 else 'Possible')
Problem p03943 (python)

Fixed submission:
a, b, c = map(int, input().split())
x = [a, b, c]
x = sorted(x)
print("Yes" if x[0] + x[1] == x[2] else "No")

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
x = sorted(list(a, b, c))
print("Yes" if x[0] + x[1] == x[2] else "No")
Problem p03993 (python)

Fixed submission:
N = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(N):
    if a[a[i]-1] == i+1:
        ans += 1
print(ans//2)

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

ans=0

if N%2==0:
    for i in range(N//2):
      if a[a[i]-1]==i+1:
        ans += 1
            
else:
    for i in range(N//2 +1):
        if a[a[i]-1]==i+1:
          ans+=1

print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))
 
ans=0
 
if N%2==0:
    for i in range(N//2):
  	    if a[a[i]-1]==i+1:
          ans += 1
    
else:
    for i in range(N//2 +1):
        if a[a[i]-1]==i+1:
          ans+=1

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

ans=0

if N%2==0:
    for i in range(N//2):
  	    if a[a[i]-1]==i+1:
            ans += 1
    
else:
    for i in range(N//2 +1):
        if a[a[i]-1]==i+1:
          ans+=1
Problem p02615 (python)

Fixed submission:
if __name__ == '__main__':
    n = int(input().strip())
    A = list(map(int, input().strip().split()))
    A.sort(reverse=True)

    score = A[0] + sum([A[1+int(i/2)]for i in range(0, n-2)])

    print(score)

Buggy submission (verdict: Runtime Error):
if __name__ == '__main__':
    n = int(input().strip())
    A = list(map(int, input().strip().split()))
    A.sort(reverse=True)
    score = 0
    if not len(A) < 2:
        min_max_list = [0] * n
        min_max_dict = {A[1]: 2}
        max_value = A[1]
        score = A[0]
        value_list = [A[1]]
        for num, a in enumerate(A[2:]):
            score += max_value
            min_max_dict[max_value] -= 1
            if a in min_max_dict:
                min_max_dict[a] += 2
            else:
                min_max_dict[a] = 2
                value_list.append(a)
            if min_max_dict[max_value] == 0:
                value_list.remove()
                max_value = value_list[0]
    print(score)
Problem p02663 (python)

Fixed submission:
if __name__ == '__main__':
    H1, M1, H2, M2, K = map(int, input().strip().split(" "))

    diff_min = (H2 - H1) * 60 + M2 - M1
    ans = diff_min - K
    print(ans)

Buggy submission (verdict: Runtime Error):
if __name__ == '__main__':
    N = int(input().strip())
    A = list(map(int, input().strip().split(" ")))


    if A[0] != 1 and len(A) == 1:
        print(-1)

    tree = [0] * (sum([2 ** i for i in range(N + 1)]))
    for i, a in enumerate(A[::-1]):
        depth = len(A) - 1 - i
        depth_hierarchy_start_index = sum([2 ** i for i in range(depth)]) if depth != 0 else 0
        depth_hierarchy_end_index = sum([2 ** i for i in range(depth + 1)]) if depth != 0 else 1

        # keisho
        if depth != N:
            for i in range(depth_hierarchy_start_index, depth_hierarchy_end_index):
                if tree[2 * i + 1] != 0 or tree[2 * i + 2] != 0:
                    tree[i] = 2

        # 1 ume
        count = 0
        part = 2
        while True:
            try:
                for i in range(0, 2 ** depth, int(2 ** depth / part) if int(2 ** depth / part) != 0 else 1):
                    if tree[depth_hierarchy_start_index + i] == 0:
                        tree[depth_hierarchy_start_index + i] = 1
                        count += 1
                    if count == a:
                        break
                    part *= 2
                if count == a:
                    break
            except:
                print(-1)

    print(sum([1 if i != 0 else 0 for i in tree]))
Problem p02574 (python)

Fixed submission:
def pf(N):
    A = []
    while N % 2 == 0:
        A.append(2)
        N //= 2
    f = 3
    while f * f <= N:
        if N % f == 0:
            A.append(f)
            N //= f
        else:
            f += 2
    if N != 1:
        A.append(N)
    return A

n = int(input())
a = list(map(int, input().split()))
b = [0]*1000001
for i in range(n):
    x = pf(a[i])
    x = list(set(x))
    for j in x:
        b[j] += 1
#print(b)
tnp = 0
for i in range(1000001):
    if (b[i]>1):
        tnp += 1
        break
if (tnp==0):
    print("pairwise coprime")
    exit()
        
for i in range(1000001):
    if (b[i]==n):
        print("not coprime")
        exit()
print("setwise coprime")

Buggy submission (verdict: Runtime Error):
def pf(N):
    A = []
    while N % 2 == 0:
        A.append(2)
        N //= 2
    f = 3
    while f * f <= N:
        if N % f == 0:
            A.append(f)
            N //= f
        else:
            f += 2
    if N != 1:
        A.append(N)
    return A

n = int(input())
a = list(map(int, input().split()))
b = [0]*1001
for i in range(n):
    x = pf(a[i])
    x = list(set(x))
    for j in x:
        b[j] += 1
#print(b)
tnp = 0
for i in range(1001):
    if (b[i]>1):
        tnp += 1
        break
if (tnp==0):
    print("pairwise coprime")
    exit()
        
for i in range(1001):
    if (b[i]==n):
        print("not coprime")
        exit()
print("setwise coprime")

Buggy submission (verdict: Runtime Error):
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

import sys
input = sys.stdin.readline
n,m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]
uf = UnionFind(n)
for i in range(m):
    uf.union(a[i][0]-1,a[i][1]-1)
ans = 0
x = [True]*n
for i in range(n):
    if (x[i]==False):
        continue
    print(i)
    t = uf.members(i)
    ans = max(ans,len(t))
    for j in t:
        x[j] = False
print(ans)
Problem p02705 (python)

Fixed submission:
import math
r = int(input())
print(r*math.pi*2)

Buggy submission (verdict: Runtime Error):
n,k = map(int, input().split())
m = 1000000007
ans = []
for i in range(1,n+2):
    ans_min = (0+(i-1))*i*0.5
    ans_max = ((n+1-i)+n)*i*0.5
    ans.append(ans_max-ans_min+1)
ans_wa = [ans[0]]
for i in range(1,n+1):
    ans_wa.append(ans_wa[i-1]+ans[i])
print(int((ans_wa[n]-ans_wa[k-2])%m))
Problem p02882 (python)

Fixed submission:
import math
a,b,x = map(int, input().split())
if (x <= (a*a*b)/2):
    p = (2*x)/(a*b)
    print(90-math.degrees(math.atan(p/b)))
elif (x == a*a*b):
    print(0)
    
else:
    p = 2*(a*a*b - x)/(a*a)
    print(90-math.degrees(math.atan(a/p)))

Buggy submission (verdict: Runtime Error):
import math
a,b,x = map(int, input().split())
if (x <= (a*a*b)/2):
    p = (2*x)/(a*b)
    print(90-math.degrees(math.atan(p/b)))
else:
    p = 2*(a*a*b - x)/(a*a)
    print(90-math.degrees(math.atan(a/p)))
Problem p02900 (python)

Fixed submission:
import fractions
a,b = map(int,input().split())
x = fractions.gcd(a,b)

def so(n):
    a = []
    while n%2==0:
        a.append(2)
        n//=2
    f = 3
    while f*f<=n:
        if n%f==0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n!=1:
        a.append(n)
    return a
y = set(so(x))
print(len(y)+1)

Buggy submission (verdict: Runtime Error):
import math
a,b = map(int,input().split())
x = math.gcd(a,b)

def so(n):
    a = []
    while n%2==0:
        a.append(2)
        n//=2
    f = 3
    while f*f<=n:
        if n%f==0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n!=1:
        a.append(n)
    return a
y = set(so(x))
print(len(y)+1)
Problem p02960 (python)

Fixed submission:
s = input()
mod = 10**9+7
dp = [[0]*13 for _ in range(len(s))]
t = [1]
for i in range(len(s)-1):
    t.append(t[-1]*10%13)
t.reverse()
#print(t)
if (s[0]=="?"):
    for i in range(10):
        dp[0][t[0]*i%13] = +1
else:
    dp[0][t[0]*int(s[0])%13] += 1
for i in range(1,len(s)):
    if (s[i]=="?"):
        for j in range(13):
            for k in range(10):
                dp[i][(j + t[i]*k)%13] += dp[i-1][j]
                dp[i][(j + t[i]*k)%13] %= mod
    else:
        for j in range(13):
            #print(i,j,(j + t[i]*int(s[i]))%13)
            dp[i][(j + t[i]*int(s[i]))%13] += dp[i-1][j]
            dp[i][(j + t[i]*int(s[i]))%13] %= mod             
#print(dp)
print(dp[len(s)-1][5])

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

s = input()
mod = 10**9+7
dp = [[0]*13 for _ in range(len(s))]
t = [1]
for i in range(len(s)-1):
    t.append(t[-1]*10%13)
t.reverse()
#print(t)
if (s[0]=="?"):
    for i in range(10):
        dp[0][t[0]*i%13] = +1
else:
    dp[0][t[0]*int(s[0])%13] += 1
for i in range(1,len(s)):
    if (s[i]=="?"):
        for j in range(13):
            for k in range(10):
                dp[i][(j + t[i]*k)%13] += dp[i-1][j]
                dp[i][(j + t[i]*k)%13] %= mod
    else:
        for j in range(13):
            #print(i,j,(j + t[i]*int(s[i]))%13)
            dp[i][(j + t[i]*int(s[i]))%13] += dp[i-1][j]
            dp[i][(j + t[i]*int(s[i]))%13] %= mod             
#print(dp)
print(dp[len(s)-1][5])import sys
input = sys.stdin.readline

s = input()
mod = 10**9+7
dp = [[0]*13 for _ in range(len(s))]
t = [1]
for i in range(len(s)-1):
    t.append(t[-1]*10%13)
t.reverse()
#print(t)
if (s[0]=="?"):
    for i in range(10):
        dp[0][t[0]*i%13] = +1
else:
    dp[0][t[0]*int(s[0])%13] += 1
for i in range(1,len(s)):
    if (s[i]=="?"):
        for j in range(13):
            for k in range(10):
                dp[i][(j + t[i]*k)%13] += dp[i-1][j]
                dp[i][(j + t[i]*k)%13] %= mod
    else:
        for j in range(13):
            #print(i,j,(j + t[i]*int(s[i]))%13)
            dp[i][(j + t[i]*int(s[i]))%13] += dp[i-1][j]
            dp[i][(j + t[i]*int(s[i]))%13] %= mod             
#print(dp)
print(dp[len(s)-1][5])

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

s = input()
mod = 10**9+7
dp = [[0]*13 for _ in range(len(s))]
t = [1]
for i in range(len(s)-1):
    t.append(t[-1]*10%13)
t.reverse()
#print(t)
if (s[0]=="?"):
    for i in range(10):
        dp[0][t[0]*i%13] = +1
else:
    dp[0][t[0]*int(s[0])%13] += 1
for i in range(1,len(s)):
    if (s[i]=="?"):
        for j in range(13):
            for k in range(10):
                dp[i][(j + t[i]*k)%13] += dp[i-1][j]
                dp[i][(j + t[i]*k)%13] %= mod
    else:
        for j in range(13):
            #print(i,j,(j + t[i]*int(s[i]))%13)
            dp[i][(j + t[i]*int(s[i]))%13] += dp[i-1][j]
            dp[i][(j + t[i]*int(s[i]))%13] %= mod             
#print(dp)
print(dp[len(s)-1][5])