Problem:


Score : 400 points

Problem Statement

Given is a string S. Each character in S is either a digit (0, ..., 9) or ?.

Among the integers obtained by replacing each occurrence of ? with a digit, how many have a remainder of 5 when divided by 13? An integer may begin with 0.

Since the answer can be enormous, print the count modulo 10^9+7.

Constraints

S is a string consisting of digits (0, ..., 9) and ?.

1 \leq |S| \leq 10^5

Input

Input is given from Standard Input in the following format:

S

Output

Print the number of integers satisfying the condition, modulo 10^9+7.

Sample Input 1

??2??5

Sample Output 1

768

For example, 482305, 002865, and 972665 satisfy the condition.

Sample Input 2

?44

Sample Output 2

1

Only 044 satisfies the condition.

Sample Input 3

7?4

Sample Output 3

0

We may not be able to produce an integer satisfying the condition.

Sample Input 4

?6?42???8??2??06243????9??3???7258??5??7???????774????4?1??17???9?5?70???76???

Sample Output 4

153716888



Sample input:
??2??5


Sample output:
768

Submission status: Wrong Answer

Solution code:
s = str(input())
MOD = 1000000007
tmp = 0
for i in range(len(s)):
    if s[i] == "?":
        tmp += 1
    else:
        break

keta = len(s) - tmp
n = 10 ** len(s) // 13 + 1
ans = 0
flg = False
for i in range(n):
    step = str(i * 13 + 5)
    if keta <= len(str(step)) <= len(s):
        print(step)
        for j in range(1, keta+1):
            if s[-j] == "?":
                pass
            elif step[-j] != s[-j]:
                flg = False
                break
            elif step[-j] == s[-j]:
                flg = True
        print(flg)
    if flg:
        ans += 1 % MOD

print(ans)

Submission status: Wrong Answer

Solution code:
#coding: utf-8
import math
import heapq
import bisect

MOD = 10**9+7

S = input()
ans = [0]*13
ans[0]=1
 
for c in S:
    dp=[0]*13
    for i in range(13):
        #dpはansを一桁ずらしたもの
        dp[(i*10)%13]=ans[i]%MOD
    #0~12と13~25と同じものを増設
    dp+=dp
 
    if c=='?':
        for i in range(13):
            #添字を13から26まで増やしたから、ここでこう楽な計算ができる。
            ans[i]=sum(dp[i+4:i+14])
    else:
        for i in range(13):
            ans[i]=dp[i+13-int(c)]

print(ans[5])

Submission status: Wrong Answer

Solution code:
#coding: utf-8
import math
import heapq
import bisect

MOD = 10**9+7

S = input()
ans = [1]+[0]*12
 
for c in S:
    dp=[0]*13
    for i in range(13):
        #dpはansを一桁ずらしたもの
        dp[(i*10)%13]=ans[i]%MOD
    #0~12と13~25と同じものを増設
    dp+=dp
 
    if c=='?':
        for i in range(13):
            #添字を13から26まで増やしたから、ここでこう楽な計算ができる。
            ans[i]=sum(dp[i+4:i+14])
    else:
        for i in range(13):
            ans[i]=dp[i+13-int(c)]

print(ans[5])

Submission status: Wrong Answer

Solution code:
MOD = 10 ** 9 + 7

S = input()
N = len(S)

dp = [[0] * 13 for _ in range(N + 1)]
dp[0][0] = 1

mul = 1

for i, x in enumerate(S[::-1]):
  if x == "?":
    for k in range(10):
      for j in range(13):
        jj = (mul * k + j) % 13
        dp[i + 1][jj] += dp[i][j]
        dp[i + 1][jj] %= MOD
  else:
    k = int(x)
    for j in range(13):
      jj = (mul * k + j) % 13
      dp[i + 1][jj] += dp[i][j]
      dp[i + 1][jj] %= MOD

  mul = (mul * 10) % MOD

print(dp[N][5])

Submission status: Wrong Answer

Solution code:
S = input()

MOD = 10 ** 9 + 7
N = 13

DP = [0] * N

# 初期値
DP[0] = 1
digit = 1

# 0 -> 5 -> ?5 -> ??5 -> ...に対する余りがどこになるかを更新していく
for i in range(len(S) - 1, -1, -1):
    nextDP = [0] * N

    if S[i] == "?":
        for k in range(10):
            for j in range(N):
                nextDP[(k * digit + j) % N] += DP[j]
                nextDP[(k * digit + j) % N] %= MOD
    else:
        k = int(S[i])
        for j in range(N):
            nextDP[(k * digit + j) % N] += DP[j]
            nextDP[(k * digit + j) % N] %= MOD



    digit *= 10
    digit %= N
    DP = nextDP[:]

print(DP)

Submission status: Wrong Answer

Solution code:
s=input().rstrip();mod=10**9+7
print(s)
dp = [[0]*13for _ in range(len(s)+1)]
dp[0][0]=1
for i in range(len(s)):
  if s[i]=='?':
    for j in range(13):
      for k in range(10):
        dp[i+1][(10*j+k)%13] += dp[i][j]
        dp[i+1][(10*j+k)%13] %= mod
  else:
    for j in range(13):
      dp[i+1][(10*j+int(s[i]))%13] += dp[i][j]
      dp[i+1][(10*j+int(s[i]))%13] %= mod
print(dp[len(s)][5])

Submission status: Wrong Answer

Solution code:
s=input().strip();mod=10**9+7
print(s)
dp = [[0]*13for _ in range(len(s)+1)]
dp[0][0]=1
for i in range(len(s)):
  if s[i]=='?':
    for j in range(13):
      for k in range(10):
        dp[i+1][(10*j+k)%13] += dp[i][j]
        dp[i+1][(10*j+k)%13] %= mod
  else:
    for j in range(13):
      dp[i+1][(10*j+int(s[i]))%13] += dp[i][j]
      dp[i+1][(10*j+int(s[i]))%13] %= mod
print(dp[len(s)][5])

Submission status: Wrong Answer

Solution code:
s=input()
#temp
n=len(s)
dp=[list(0 for i in range(13)) for j in range(n)]

MOD=10**9+7
if s[0]=="?":
    for k in range(0,10):
        dp[0][k]=1
else:
    dp[0][int(s[0])]=1
for i in range(0,n-1):
    if s[i+1]=="?":
        for j in range(13):
            tmp=dp[i][j]*(10**i+1)%13
            dp[i+1][tmp]+=dp[i][j]
            dp[i+1][tmp]%=MOD
    else:
        for j in range(13):
            tmp=(dp[i][j]*(10**(i+1))+int(s[i+1]))%13
            dp[i+1][tmp]+=dp[i][tmp]
            dp[i+1][tmp]%=MOD

print(dp[n-1][5])

Submission status: Wrong Answer

Solution code:
import copy
s = str(input())
N = len(s)
num = [0,0,0,0,0,0]
all = [76923 for i in range(13)]
all[12] = 76924

num1 = [1,1,1,1,1,1,1,1,1,1,0,0,0]
num2 = [1,1,1,0,1,1,0,1,1,0,1,1,1]
num3 = [1,1,1,1,0,1,1,1,0,1,1,1,0]
num4 = [1,0,0,0,1,1,1,1,1,1,1,1,1]
num5 = [1,1,1,1,0,1,1,0,1,1,0,1,1]
num6 = [1,0,1,1,1,0,1,1,1,0,1,1,1]

tgt = copy.deepcopy(all)

md = 0
for i in range(N):
    t = s[N-i-1]
    if t == '?':
        num[(N-i-1)%6] += 1
    else:
        md += (10**(i%6) *int(t))%13
#print(num)
#print(md)
allnum = min(num)
for i in range(6):
    num[i] -= allnum
#print(num)

if allnum == 0:
    tgt = [0,0,0,0,0,0,0,0,0,0,0,0,0]
    tgt[md%13] = 1
else:
    for i in range(allnum-1):
        tgt2 = [0,0,0,0,0,0,0,0,0,0,0,0,0]
        for j in range(13):
            for k in range(13):
                tgt2[(j+k)%13] += all[j]*tgt[k]
        for j in range(13):
            tgt2[j] = tgt2[j]%(10**9+7)
        tgt = copy.deepcopy(tgt2)

for i in range(num[0]):
    tgt2 = [0,0,0,0,0,0,0,0,0,0,0,0,0]
    for j in range(13):
        for k in range(13):
            tgt2[(j+k)%13] += tgt[j]*num1[k]
    for j in range(13):
        tgt2[j] = tgt2[j]%(10**9+7)
    tgt = copy.deepcopy(tgt2)
for i in range(num[1]):
    tgt2 = [0,0,0,0,0,0,0,0,0,0,0,0,0]
    for j in range(13):
        for k in range(13):
            tgt2[(j+k)%13] += tgt[j]*num2[k]
    for j in range(13):
        tgt2[j] = tgt2[j]%(10**9+7)
    tgt = copy.deepcopy(tgt2)
for i in range(num[2]):
    tgt2 = [0,0,0,0,0,0,0,0,0,0,0,0,0]
    for j in range(13):
        for k in range(13):
            tgt2[(j+k)%13] += tgt[j]*num3[k]
    for j in range(13):
        tgt2[j] = tgt2[j]%(10**9+7)
    tgt = copy.deepcopy(tgt2)
for i in range(num[3]):
    tgt2 = [0,0,0,0,0,0,0,0,0,0,0,0,0]
    for j in range(13):
        for k in range(13):
            tgt2[(j+k)%13] += tgt[j]*num4[k]
    for j in range(13):
        tgt2[j] = tgt2[j]%(10**9+7)
    tgt = copy.deepcopy(tgt2)
for i in range(num[4]):
    tgt2 = [0,0,0,0,0,0,0,0,0,0,0,0,0]
    for j in range(13):
        for k in range(13):
            tgt2[(j+k)%13] += tgt[j]*num5[k]
    for j in range(13):
        tgt2[j] = tgt2[j]%(10**9+7)
    tgt = copy.deepcopy(tgt2)
for i in range(num[5]):
    tgt2 = [0,0,0,0,0,0,0,0,0,0,0,0,0]
    for j in range(13):
        for k in range(13):
            tgt2[(j+k)%13] += tgt[j]*num6[k]
    for j in range(13):
        tgt2[j] = tgt2[j]%(10**9+7)
    tgt = copy.deepcopy(tgt2)
#print(tgt)
print(tgt[5])

Submission status: Wrong Answer

Solution code:
import copy
s = str(input())
N = len(s)
num = [0,0,0,0,0,0]
all = [76923 for i in range(13)]
all[12] = 76924

num1 = [1,1,1,1,1,1,1,1,1,1,0,0,0]
num2 = [1,1,1,0,1,1,0,1,1,0,1,1,1]
num3 = [1,1,1,1,0,1,1,1,0,1,1,1,0]
num4 = [1,0,0,1,1,1,1,1,1,1,1,1,0]
num5 = [1,1,1,1,0,1,1,0,1,1,0,1,1]
num6 = [1,0,1,1,1,0,1,1,1,0,1,1,1]

tgt = copy.deepcopy(all)
md = 0

for i in range(N):
    t = s[N-i-1]
    if t == '?':
        num[(N-i-1)%6] += 1
    else:
        md += (10**(i%6) *int(t))%13

allnum = min(num)

for i in range(6):
    num[i] -= allnum

if allnum == 0:
    tgt = [0,0,0,0,0,0,0,0,0,0,0,0,0]
    tgt[md%13] = 1
else:
    for i in range(allnum-1):
        tgt2 = [0,0,0,0,0,0,0,0,0,0,0,0,0]
        for j in range(13):
            for k in range(13):
                tgt2[(j+k)%13] += all[j]*tgt[k]
        for j in range(13):
            tgt2[j] = tgt2[j]%(10**9+7)
        tgt = copy.deepcopy(tgt2)

for i in range(num[0]):
    tgt2 = [0,0,0,0,0,0,0,0,0,0,0,0,0]
    for j in range(13):
        for k in range(13):
            tgt2[(j+k)%13] += tgt[j]*num1[k]
    for j in range(13):
        tgt2[j] = tgt2[j]%(10**9+7)
    tgt = copy.deepcopy(tgt2)
for i in range(num[1]):
    tgt2 = [0,0,0,0,0,0,0,0,0,0,0,0,0]
    for j in range(13):
        for k in range(13):
            tgt2[(j+k)%13] += tgt[j]*num2[k]
    for j in range(13):
        tgt2[j] = tgt2[j]%(10**9+7)
    tgt = copy.deepcopy(tgt2)
for i in range(num[2]):
    tgt2 = [0,0,0,0,0,0,0,0,0,0,0,0,0]
    for j in range(13):
        for k in range(13):
            tgt2[(j+k)%13] += tgt[j]*num3[k]
    for j in range(13):
        tgt2[j] = tgt2[j]%(10**9+7)
    tgt = copy.deepcopy(tgt2)
for i in range(num[3]):
    tgt2 = [0,0,0,0,0,0,0,0,0,0,0,0,0]
    for j in range(13):
        for k in range(13):
            tgt2[(j+k)%13] += tgt[j]*num4[k]
    for j in range(13):
        tgt2[j] = tgt2[j]%(10**9+7)
    tgt = copy.deepcopy(tgt2)
for i in range(num[4]):
    tgt2 = [0,0,0,0,0,0,0,0,0,0,0,0,0]
    for j in range(13):
        for k in range(13):
            tgt2[(j+k)%13] += tgt[j]*num5[k]
    for j in range(13):
        tgt2[j] = tgt2[j]%(10**9+7)
    tgt = copy.deepcopy(tgt2)
for i in range(num[5]):
    tgt2 = [0,0,0,0,0,0,0,0,0,0,0,0,0]
    for j in range(13):
        for k in range(13):
            tgt2[(j+k)%13] += tgt[j]*num6[k]
    for j in range(13):
        tgt2[j] = tgt2[j]%(10**9+7)
    tgt = copy.deepcopy(tgt2)
print(tgt[5])

Submission status: Wrong Answer

Solution code:
import copy
s = str(input())
N = len(s)
num = [0,0,0,0,0,0]
all = [76923 for i in range(13)]
all[12] = 76924
num1 = [1,1,1,1,1,1,1,1,1,1,0,0,0]
num2 = [0,1,1,0,1,1,0,1,1,1,1,1,1]
num3 = [0,1,1,1,0,1,1,1,0,1,1,1,1]
num4 = [0,0,0,1,1,1,1,1,1,1,1,1,1]
num5 = [0,1,1,1,1,1,1,0,1,1,0,1,1]
num6 = [0,1,1,1,1,0,1,1,1,0,1,1,1]
tgt = copy.deepcopy(all)
md = 0
for i in range(N):
    t = s[N-i-1]
    if t == '?':
        num[(N-i-1)%6] += 1
    else:
        md += (10**(i%6) *int(t))%13
allnum = min(num)
for i in range(6):
    num[i] -= allnum
if allnum == 0:
    tgt = [0,0,0,0,0,0,0,0,0,0,0,0,0]
    tgt[md%13] = 1
else:
    for i in range(allnum-1):
        tgt2 = [0,0,0,0,0,0,0,0,0,0,0,0,0]
        for j in range(13):
            for k in range(13):
                tgt2[(j+k)%13] += all[j]*tgt[k]
        for j in range(13):
            tgt2[j] = tgt2[j]%(10**9+7)
        tgt = copy.deepcopy(tgt2)

for i in range(num[0]):
    tgt2 = [0,0,0,0,0,0,0,0,0,0,0,0,0]
    for j in range(13):
        for k in range(13):
            tgt2[(j+k)%13] += tgt[j]*num1[k]
    for j in range(13):
        tgt2[j] = tgt2[j]%(10**9+7)
    tgt = copy.deepcopy(tgt2)
for i in range(num[1]):
    tgt2 = [0,0,0,0,0,0,0,0,0,0,0,0,0]
    for j in range(13):
        for k in range(13):
            tgt2[(j+k)%13] += tgt[j]*num2[k]
    for j in range(13):
        tgt2[j] = tgt2[j]%(10**9+7)
    tgt = copy.deepcopy(tgt2)
for i in range(num[2]):
    tgt2 = [0,0,0,0,0,0,0,0,0,0,0,0,0]
    for j in range(13):
        for k in range(13):
            tgt2[(j+k)%13] += tgt[j]*num3[k]
    for j in range(13):
        tgt2[j] = tgt2[j]%(10**9+7)
    tgt = copy.deepcopy(tgt2)
for i in range(num[3]):
    tgt2 = [0,0,0,0,0,0,0,0,0,0,0,0,0]
    for j in range(13):
        for k in range(13):
            tgt2[(j+k)%13] += tgt[j]*num4[k]
    for j in range(13):
        tgt2[j] = tgt2[j]%(10**9+7)
    tgt = copy.deepcopy(tgt2)
for i in range(num[4]):
    tgt2 = [0,0,0,0,0,0,0,0,0,0,0,0,0]
    for j in range(13):
        for k in range(13):
            tgt2[(j+k)%13] += tgt[j]*num5[k]
    for j in range(13):
        tgt2[j] = tgt2[j]%(10**9+7)
    tgt = copy.deepcopy(tgt2)
for i in range(num[5]):
    tgt2 = [0,0,0,0,0,0,0,0,0,0,0,0,0]
    for j in range(13):
        for k in range(13):
            tgt2[(j+k)%13] += tgt[j]*num6[k]
    for j in range(13):
        tgt2[j] = tgt2[j]%(10**9+7)
    tgt = copy.deepcopy(tgt2)
print(tgt[5])

Submission status: Wrong Answer

Solution code:
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')
ans = int(0)
S = str(input())
N = len(S)
M = 13
dp = [[0]*M for _ in range(N)]
c = (10**(N-1))%M
if S[0] == "?":
    for l in range(10):
        dp[0][l*c%M] += 1
else:
    m = int(S[0]) * c%M
    dp[0][m] = 1
S = S[1:]
i = int(1)

Submission status: Wrong Answer

Solution code:
S = input()
s = len(S)
mod = 10 ** 9 + 7

dp = [[0] * 13 for _ in range(s)]

if S[0] == '?':
    for i in range(10):
        dp[0][i] += 1
else:
    dp[0][int(S[0]) // 13] += 1

for i in range(1, s):
    if S[i] == '?':
        for j in range(13):
            for k in range(10):
                dp[i][(j * 10 + k) % 13] = (dp[i][(j * 10 + k) % 13] + dp[i - 1][j]) % mod
    else:
        for j in range(13):
            dp[i][(j * 10 + int(S[i])) % 13] = (dp[i][(j * 10 + int(S[i])) % 13] + dp[i - 1][j]) % mod

print(dp[-1][5] % mod)

Submission status: Wrong Answer

Solution code:
def main():
    sts=input()
    n= len(sts)
    mod = 10**9+7
    s = []
    for c in sts:
        s.append(c)

    dp = [[0 for _ in range(13)]for _ in range(n)]

    ss = s[0]
    if ss == '?':
        for i in range(10):
            dp[0][i] = 1
    else:
        ss = int(ss)
        dp[0][ss] = 1

    for i in range(1,n):
        ss = s[i]
        if ss == "?":
            for k in range(10):
                for j in range(13):
                    dp[i][(j * 10 +k) % 13] += dp[i-1][j]
        else:
            for j in range(13):
                dp[i][(j * 10 +int(ss)) % 13] += dp[i-1][j]
        for j in range(13):
            dp[i][j]= mod


    print(dp[n-1][5])

main()

Submission status: Wrong Answer

Solution code:
import numpy as np
a0 = np.array([1,1,1,1,1,1,1,1,1,1,0,0,0])
print(a0[10])

Submission status: Wrong Answer

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]

def main():
    S = input()
    print(S)

    dp = [[0] * 15 for _ in range(len(S) + 5)]
    MOD = 10**9 + 7

    dp[0][0] = 1

    for i in range(len(S)):
        for j in range(13):
            if S[i] != '?':
                k = int(S[i])
                dp[i+1][(j+k*10**i)%13] += dp[i][j]
                dp[i+1][(j+k*10**i)%13] %= MOD
            else:
                for k in range(10):
                    dp[i+1][(j+k*10**i)%13] += dp[i][j]
                    dp[i+1][(j+k*10**i)%13] %= MOD


    print(dp[len(S)][5])



main()

Submission status: Wrong Answer

Solution code:
s=input()
l=len(s)
a=10**9+7
print(a)

if s[l-1]=='?':
  n=[1,1,1,1,1,1,1,1,1,1,0,0,0]
else:
  n=[0,0,0,0,0,0,0,0,0,0,0,0,0]
  n[int(s[l-1])]=1
d=[0,0,0,0,0,0,0,0,0,0,0,0,0]

m=1
for i in range(1,len(s)):
  m=(m*10)%13
  if s[l-1-i] == '?':
    for j in range(13):
      for k in range(10):
        d[(m*k+j)%13] += n[j]
  else:
    for j in range(13):
      d[(m*int(s[l-1-i])+j)%13] += n[j]

  for j in range(13):
    n[j]=d[j]%a
    d[j]=0

print(n[5])

Submission status: Wrong Answer

Solution code:
s=input()
l=len(s)
a=10*9+7

if s[l-1]=='?':
  n=[1,1,1,1,1,1,1,1,1,1,0,0,0]
else:
  n=[0,0,0,0,0,0,0,0,0,0,0,0,0]
  n[int(s[l-1])]=1
d=[0,0,0,0,0,0,0,0,0,0,0,0,0]

m=1
for i in range(1,len(s)):
  m=(m*10)%13
  if s[l-1-i] == '?':
    for j in range(13):
      for k in range(10):
        d[(m*k+j)%13] += n[j]
  else:
    for j in range(13):
      d[(m*int(s[l-1-i])+j)%13] += n[j]

  for j in range(13):
    n[j]=d[j]%a
    d[j]=0

print(n[5])

Submission status: Wrong Answer

Solution code:
S = list(input())
dp = [[0]*13 for _ in range(len(S)+1)]
dp[0][0] = 1
for digit in range(len(S)):
  if S[digit]=='?':
    for i in range(10):
      for j in range(13):
        dp[digit+1][(j*10+i)%13] += dp[digit][j]
  else:
    for j in range(13):
      dp[digit+1][(j*10)%13] += dp[digit][j]
  

print(dp[-1][5]%(1000000000+7))

Submission status: Wrong Answer

Solution code:
S = list(input())
dp = [[0]*13 for _ in range(len(S)+1)]
dp[0][0] = 1
for digit in range(len(S)-1,-1,-1):
  if S[digit]=='?':
    for i in range(10):
      for j in range(13):
        dp[len(S)-digit][(j+10**(len(S)-1-digit)*i%13)%13] += dp[len(S)-digit-1][j]
  else:
    for j in range(13):
      dp[len(S)-digit][(j+10**(len(S)-1-digit)*digit%13)%13] += dp[len(S)-digit-1][j]
  
  dp[len(S)-digit] = [i%(1000000000+7) for i in dp[len(S)-digit]]

print(dp[-1][5])

Submission status: Wrong Answer

Solution code:
S = list(input())
dp = [[0]*13 for _ in range(len(S)+1)]
dp[0][0] = 1
for digit in range(len(S)-1,-1,-1):
  if S[digit]=='?':
    for i in range(10):
      for j in range(13):
        dp[len(S)-digit][(j+10**(len(S)-1-digit)*i%13)%13] += dp[len(S)-digit-1][j]
  else:
    for j in range(13):
      dp[len(S)-digit][(j+10**(len(S)-1-digit)*digit%13)%13] += dp[len(S)-digit-1][j]

print(dp[-1][5])

Submission status: Wrong Answer

Solution code:
MOD = 10**9 + 7

def main():
    s = [int(in_i) if in_i != '?' else -1 for in_i in list(open(0).read())[:-1]]
    n = len(s)

    cnt = [0] * 13
    if s[0] == -1:
        for j in range(10):
           cnt[j] = 1
    else:
        cnt[s[0]] = 1

    for cur_s in s[1:]:
        print(cnt)
        dp = [0] * 26
        for i in range(13):
            dp[i*10%13] = cnt[i] % MOD
        dp[13:] = dp[:13]

        if cur_s == -1:
            for i in range(13):
                cnt[i] = sum(dp[i+4:i+14])
        else:
            for i in range(13):
                cnt[i] = dp[i+13-cur_s]

    ans = cnt[5] % MOD
    return()

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
mod = 10**9 + 7

def main():
    s = open(0).read()[:-1][::-1]
    n = len(s)

    dp = [[0] * 13 for _ in range(n)]
    if s[0] == '?':
        for j in range(10):
            dp[0][j] = 1
    else:
        dp[0][int(s[0])] = 1

    for i, cur_s in enumerate(s[1:], start=1):
        if cur_s == '?':
            for j in range(10):
                remain = j * 10**i % 13
                for k in range(13):
                    dp[i][(k + remain) % 13] += dp[i-1][k] % mod
        else:
            remain = int(cur_s) * 10**i % 13
            for k in range(13):
                dp[i][(k + remain) % 13] += dp[i-1][k] % mod
    ans = dp[-1][5]
    print(ans)
    return()

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
MOD = 1000000007
#s = (list(input()))
s = [int(x) if x!="?" else -1 for x in reversed(input())]
#s = s[::-1]

print(s)
dp = np.full((len(s), 13), 0, dtype="int64")

if s[0] == -1:
    dp[0][0:10] = 1
else:
    dp[0][int(s[0])] = 1

for index in range(1, len(s)):
    if not s[index] == -1:
        value = int(s[index])
        for old_amari in range(13):
            new_amari = (value * pow(10, index) + old_amari) % 13
            dp[index][new_amari] += dp[index-1][old_amari]
    else:
        for value in range(10):
            for old_amari in range(13):
                new_amari = (value * pow(10, index) + old_amari) % 13
                dp[index][new_amari] += dp[index - 1][old_amari]
    dp[index] = dp[index] % MOD

print(dp[len(s)-1][5])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

S=input()

count = 0
flag = 1

ans = []

for k in range((10**len(S))//13):
    flag = 1
    if len(S) < len(str(13*k+5)):
        flag = 0
    else:
        for i in range(len(S)):
            if not(S[i] == '?' or S[i] == str(13*k+5).zfill(len(S))[i]):
                flag = 0
    if flag == 1:
        count += 1

print(count%(10**9+7))

Submission status: Wrong Answer

Solution code:
def main():
    MOD = 7 + 10**9
    S = tuple(input())
    N = len(S)
    dp = [[0]*13 for _ in range(N+1)]
    dp[0][0] += 1
    for i in range(N):
        for k in range(13):
            if S[-(i+1)] != '?':
                dp[i+1][(k+int(S[-(i+1)])*(10**(i))%13)%13] += dp[i][k] 
                dp[i+1][(k+int(S[-(i+1)])*(10**(i))%13)%13] %= MOD
            else:
                for l in range(10):
                    dp[i+1][(k+l*(10**(i))%13)%13] += dp[i][k]
                    dp[i+1][(k+l*(10**(i))%13)%13] %= MOD
    print(dp[-1][5])

Submission status: Wrong Answer

Solution code:
s=input()
l=len(s)
mod = pow(10,9)+7

dp = [0 for i in range(13)]
dp2 = [0 for i in range(13)]
dp[0] = 1

for i in range(1,l+1):
	num = s[-i]
	keta = pow(10,i-1)
	dp2 = dp.copy()
	if num == '?':
		for j in range(1,10):
			tmp = ( j * keta ) % 13
			#for k in range(13):
				#index = (tmp + k) % 13
				#dp[index] = dp2[k] % mod
			dp = [dp[k] + dp2[(tmp+k)%13]%mod for k in range(13)]
	else:
		tmp = ( int(num) * keta ) % 13
		#for k in range(13):
			#index = (tmp + k) % 13
			#dp[index] = dp2[k] % mod
		dp = [dp2[(tmp+k)%13]%mod for k in range(13)]
print(dp[5] % mod)

Submission status: Wrong Answer

Solution code:
s=input()
l=len(s)

dp = [[0 for i in range(13)] for j in range(l+1)]
dp[0][0] = 1
#dp[i][j]=i桁目までを13で割った時、
#そのあまりがjになる場合の数

for i in range(1,l+1):
	num = s[-i]
	print('num=',num)
	if num == '?':
		for j in range(10):
			tmp = int(j) * pow(10,i-1)
			tmp %= 13
			for k in range(13):
				index = (tmp + k) % 13
				dp[i][index] += dp[i-1][k]
	else:
		tmp = int(num) * pow(10,i-1)
		tmp %= 13
		for k in range(13):
			index = (tmp + k) % 13
			dp[i][index] += dp[i-1][k]
print(dp[l][5] % (pow(10,9)+7))

Submission status: Wrong Answer

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    s = [int(v) if v != "?" else -1 for v in list(str(input().rstrip('\n')))]
    dp = [[0] * 13 for _ in range(2)]
    mod = 10 ** 9 + 7
    for i in range(len(s)):
        if s[-i-1] == -1:
            for j in range(10):
                if i == 0:
                    dp[1][j % 13] += 1
                else:
                    for k in range(13):
                        dp[1][((10 ** i) % 13 * j + k) % 13] += (dp[0][k] % mod)
        else:
            if i == 0:
                dp[1][s[-i-1] % 13] += 1
            else:
                for k in range(13):
                    dp[1][((10 ** i) + 13 * s[-i-1] + k) % 13] += (dp[0][k] % mod)
        for j in range(13):
            dp[0][j] = dp[1][j]
            dp[1][j] = 0
    print(dp[0][5] % mod)


if __name__ == '__main__':
    slove()

Submission status: Wrong Answer

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    s = [int(v) if v != "?" else -1 for v in list(str(input().rstrip('\n')))]
    dp = [[0] * 13 for _ in range(2)]
    mod = 10 ** 9 + 7
    for i in range(len(s)):
        if s[-i-1] == -1:
            for j in range(10):
                if i == 0:
                    dp[1][j % 13] += 1
                else:
                    for k in range(13):
                        dp[1][(10 ** (i % 13) * j + k) % 13] += (dp[0][k] % mod)
        else:
            if i == 0:
                dp[1][s[-i-1] % 13] += 1
            else:
                for k in range(13):
                    dp[1][(10 ** (i % 13) * s[-i-1] + k) % 13] += (dp[0][k] % mod)
        for j in range(13):
            dp[0][j] = dp[1][j]
            dp[1][j] = 0
    print(dp[0][5] % mod)


if __name__ == '__main__':
    slove()

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)

dp = [[0 for _ in range(13)] for _ in range(n)]
if s[0]=="?":
    for i in range(10):
        dp[0][i] = 1
else:
    i = int(s[0])
    dp[0][i]=1

for i in range(1,n):
    c = s[i]
    for j in range(13):
        count = 0
        if c!="?":
            cc = int(c)
            for k in range(13):
                if (cc+(10*k)) %13 ==j:
                    count += dp[i-1][k] 
        else:
            for k in range(13):
                for cc in range(10):
                    if (cc+10*k) % 13 == j:
                        count += dp[i-1][k]
        dp[i][j] = count
print(dp[n-1][5])

Submission status: Wrong Answer

Solution code:
r = [[(j - k) * 9 % 13 for j in range(10)] for k in range(13)]
d = [1] + [0] * 12

for c in input():
    if c == '?':
        d = [sum(d[j] for j in k) for k in r]
    else:
        d = [d[(int(c) - k) * 9 % 13] for k in range(13)]
    #print(d)
print(d[5])

Submission status: Wrong Answer

Solution code:
r = [[(j - k) * 9 % 13 for j in range(10)] for k in range(13)]
d = [1] + [0] * 12

for c in input():
    if c == '?':
        d = [sum(d[j] for j in k) for k in r]
    else:
        d = [d[(int(c) - k) * 9 % 13] for k in range(13)]
    print(d)
print(d[5])

Submission status: Wrong Answer

Solution code:
S = input()

MOD = 10**9+7

dp = [[0 for _ in range(13)] for _ in range(len(S) + 1)]


dp[0][0] = 1



for index in range(1, len(S) + 1):
    s = S[len(S) - index ]
    if s == '?':
   	 for i in range(10):
            for pre_index in range(13):
                next_i = (i   +  pre_index * 10 ) % 13
                dp[index][next_i] += dp[index - 1][pre_index] % MOD
    else:
        i = int(s)
        for pre_index in range(13):
            next_i = (i +  pre_index * 10 ) % 13
            dp[index][next_i] += dp[index - 1][pre_index] % MOD




print(dp[len(S)][5] % MOD)

Submission status: Wrong Answer

Solution code:
S = input()

MOD = 10**9+7

dp = [[0 for _ in range(13)] for _ in range(len(S) + 1)]


dp[0][0] = 1

for index in range(1, len(S) + 1):
    s = S[len(S) - index ]
    if s == '?':
        for pre_index in range(13):
            for i in range(10):
                next_i = (i +  pre_index * 10) % 13
                dp[index][next_i] += dp[index - 1][pre_index] 
    else:
        for pre_index in range(13):
            i = int(s)
            next_i = (i +  pre_index * 10) % 13
            dp[index][next_i] += dp[index - 1][pre_index] 

    for i in range(13):
        dp[index][i] %= MOD



print(dp[len(S)][5])

Submission status: Wrong Answer

Solution code:
S = input()

MOD = 10**9+7

dp = [[0 for _ in range(13)] for _ in range(len(S) + 1)]


dp[0][0] = 1

for index in range(1, len(S) + 1):
    s = S[len(S) - index ]
    if s == '?':
        for pre_index in range(13):
            for i in range(10):
                next_i = (i +  pre_index * 10) % 13
                dp[index][next_i] += dp[index - 1][pre_index] 
    else:
        i = int(s)
        for pre_index in range(13):
            next_i = (i +  pre_index * 10) % 13
            dp[index][next_i] += dp[index - 1][pre_index] 

    for i in range(13):
        dp[index][i] %= MOD



print(dp[len(S)][5])

Submission status: Wrong Answer

Solution code:
S = input()
n = len(S)
dp = [[0 for j in range(13)] for i in range(n+1)]
for i in range(n+1):
    for j in range(13):
        if i == 0:
            continue
        else:
            c = S[n-i]
            if i == 1 and c == '?':
                dp[i][j] = 1
            elif i == 1:
                dp[i][j] = 1 if int(c)%13 == j else 0

            else:
                if c == '?':
                    for p in range(13):
                        q = (j-p)%13
                        dp[i][j] += len([a for a in range(10) if a*10**(i-1)%13 == p])*dp[i-1][q]
                else:
                    for p in range(13):
                        q = (j-p)%13
                        dp[i][j] += dp[i-1][q] if int(c)*10**(i-1)%13 == p else 0
else:
    ans = dp[n][5]%(10**9+7)
    print(ans)

Submission status: Wrong Answer

Solution code:
num = input()
num0=num
maxnum = int(num0.replace("?","9"))

numlist = [i for i, x in enumerate(list(num)) if x != '?']

count = 0
for i in range((maxnum-5)//13 +1):
    
    pu = str(13*i + 5).zfill(len(str(maxnum)))
    
    cou = 0
    for j in range(len(numlist)):
        
        if pu[numlist[j]] == num[numlist[j]]:
            cou +=1
        else:
            break
        
        if cou == len(numlist):
            count +=1

print(count % (10**9 +7))

Submission status: Wrong Answer

Solution code:
mod=10**9+7
s=input()
n=[1,10,9,12,3,4]
ns=[[]for i in range(6)]
for i in range(6):
  for j in range(10):
    ns[i].append(n[i]*j%13)
#print(ns)
dp=[[0 for i in range(13)] for j in range(len(s)+1)]

if s[-1]=="?":
  for i in range(10):
    dp[1][i]=1
else:
  dp[1][int(s[-1])]=1

for i in range(2,len(s)+1):
  ii=i%6
  if s[-i]=="?":
    for k in range(10):
      for l in range(13):
        dp[i][(l+ns[ii][k])%13]+=dp[i-1][l]
        dp[i][(l+ns[ii][k])%13]=dp[i][(l+ns[ii][k])%13]%mod
  else:
    for l in range(13):
      dp[i][(l+ns[ii][int(s[-i])])%13]+=dp[i-1][l]
      dp[i][(l+ns[ii][int(s[-i])])%13]=dp[i][(l+ns[ii][int(s[-i])])%13]%mod
#print(ns)
print(dp[len(s)][5])

Submission status: Wrong Answer

Solution code:
s = input()
if s[-1] == "?":
    pre = [1 if i<10 else 0 for i in range(13)]
else:
    pre = [0 for i in range(13)]
    pre[int(s[-1])] = 1
n = 10**9 + 7
t = 1
for i in range(1, len(s)):
    if s[-1*i-1] == "?":
        c = pre.copy()
        for j in range(1,10):
            te = t*j % 13
            for k in range(13):
                c[k] = c[k] + pre[(13+k-te)%13]
        pre = c.copy()
        for k in range(13):
            pre[k] %= n
    else:
        te = int(s[-1*i-1])*t % 13
        pre = pre[13-te:]+pre[:13-te]
    t = t*10%13
print(pre[5])

Submission status: Wrong Answer

Solution code:
import numpy as np
S = input()

dp = np.array([[0] * 13] * (len(S) + 1))
dp[0][0] = 1
for i in range(len(S)):
    if S[i] == '?':
        c = -1
    else:
        c = int(S[i])

    for k in range(10):
        if c == -1 or c == k:
            for j in range(13):
                dp[i + 1][(j * 10 + k) % 13] += dp[i][j]
print(dp[len(S)][5])

Submission status: Wrong Answer

Solution code:
MOD = 10**9 + 7

S = input()
L = len(S)
memo = [[0 for i in range(14)] for j in range(L + 1)]
dp = [[0 for i in range(14)] for j in range(L + 1)]

dp[0][0] = 1

for k in range(L):
    for m in range(13):
        if S[k] == '?':
            for i in range(10):
                dp[k + 1][(m * 10 + i) % 13] += dp[k][m]
        else:
            dp[k + 1][(m * 10 + int(S[k])) % 13] += dp[k][m]

        for i in range(13):
            dp[k][m] %= MOD

print(dp[L][5])