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:
import numpy as np
import sys
def input():
    return sys.stdin.readline()[:-1]

S = [int(x) if x!="?" else -1 for x in input()]

div_num = 1000000007
arr = np.arange(13, dtype = np.uint64)
dp = np.zeros([2, 13], dtype = np.uint64)

div13_list = [1]
for ii in range(1, len(S)):
    n = div13_list[-1] * 10 % 13
    if n in div13_list:
        break
    else:
        div13_list.append(n)
div13_mat = np.array([div13_list] * 10, dtype = int)
div13_mat = (div13_mat * np.arange(10)[:, None] % 13).T

if S[-1] == -1:
    dp[0, :10] = 1
else:
    dp[0, S[-1]] = 1

# for ii in range(1, len(S)):
#     ind = -ii-1
#     tmp = div13_mat[ii%6]
#     if S[ind] == -1:
#         for n in range(10):
#             res = np.roll(arr, -tmp[n])
#             # dp[1, res] += dp[0, arr]
#     else:
#         res = np.roll(arr, -tmp[S[ind]])
#         # dp[1, res] += dp[0, arr]
#     dp[0] = dp[1] % div_num
#     dp[1] = 0


print (dp[0, 5])

Submission status: Wrong Answer

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

S = [int(x) if x!="?" else -1 for x in input()]

div_num = 1000000007
arr = np.arange(13, dtype = np.uint64)
dp = np.zeros([2, 13], dtype = np.uint64)

div13_list = [1]
for ii in range(1, len(S)):
    n = div13_list[-1] * 10 % 13
    if n in div13_list:
        break
    else:
        div13_list.append(n)
div13_mat = np.array([div13_list] * 10, dtype = int)
div13_mat = (div13_mat * np.arange(10)[:, None] % 13).T

if S[-1] == -1:
    dp[0, :10] = 1
else:
    dp[0, S[-1]] = 1

for ii in range(1, len(S)):
    ind = -ii-1
    tmp = div13_mat[ii%6]
    if S[ind] == -1:
        for n in range(10):
            res = np.roll(arr, -tmp[n])
            # dp[1, res] += dp[0, arr]
    else:
        res = np.roll(arr, -tmp[S[ind]])
        # dp[1, res] += dp[0, arr]
    dp[0] = dp[1] % div_num
    dp[1] = 0


print (dp[0, 5])

Submission status: Wrong Answer

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

S = input()

div_num = 1000000007
arr = np.arange(13, dtype = int)
# dp = [[0 for _ in range(13)] for _ in range(len(S))]
dp = np.zeros([len(S), 13], dtype = int)

if S[-1] == "?":
    for ii in range(10): dp[0, ii] = 1
else:
    dp[0, int(S[-1])] = 1

for ii in range(1, len(S)):
    ind = -ii-1
    if S[ind] == '?':
        for n in range(10):
            res = ((10 ** ii) * n) % 13
            res = (arr + res) % 13
            for jj in range(13):
                dp[ii, res[jj]] += dp[ii - 1, jj]
                # if dp[ii, res[jj]] > div_num: dp[ii, res[jj]] -= div_num
    else:
        res = ((10 ** ii) * int(S[ind])) % 13
        res = (arr + res) % 13
        for jj in range(13):
            dp[ii, res[jj]] += dp[ii - 1, jj]
            # if dp[ii, res[jj]] > div_num: dp[ii, res[jj]] -= div_num

print (dp[-1, 5])

Submission status: Wrong Answer

Solution code:
S=input()
length=len(S)
mod=[[0 for i in range(13)] for j in range(length)]#length=3とする s[0]~s[2]がある
s=S[::-1]#一桁目が先頭に来た
if s[0]=="?":
    for i in range(10):
        mod[0][i]+=1
else:
    mod[0][int(s[0])]+=1
    #一桁目の設定をした

for n in range(length-1):#n桁目のことを考える nは0から1まで
    p=(10**n)%13
    if s[n+1]=="?":
        list1=[0]*13
        for k in range(10):
            q=(k*p)%13
            list1[q]+=1#あまりがqの場合が何通りあるかを考えた
        for q in range(13):
            if list1[q]!=0:
                for k in range(13):
                    mod[n+1][k]+=(mod[n][(k-q+13)%13])*list1[q]
    else:
        q=(int(s[n+1])*p)%13
        for i in range(13):
            mod[n+1][i]+=mod[n][(i-q+13)%13]
    
    for i in range(13):
        mod[n+1][i]=(mod[n+1][i])%(10**9+7)
    
print(mod[length-1][6])

Submission status: Wrong Answer

Solution code:
S = input()
dp = [[0]*13 for i in range(len(S))]
MOD = 10**9+7

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

t = 1
for i, c in enumerate(S[::-1]):
    t = (t*10) % 13
    for j in range(13):
        if c == "?":
            for k in range(10):
                nj = (k*t+j) % 13
                dp[i][nj] += dp[i-1][j]
                dp[i][nj] %= MOD
        else:
            nj = (int(c)*t+j) % 13
            dp[i][nj] += dp[i-1][j]
            dp[i][nj] %= MOD
print(dp[-1][5])

Submission status: Wrong Answer

Solution code:
S = input()
dp = [[0]*13 for i in range(len(S))]
MOD = 10**9+7

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


for i, c in enumerate(S[::-1]):
    t = (10 ** (i)) % 13
    for j in range(13):
        if c == "?":
            for k in range(10):
                nj = (k*t+j) % 13
                dp[i][nj] += dp[i-1][j]
                dp[i][nj] %= MOD
        else:
            nj = (int(c)*t+j) % 13
            dp[i][nj] += dp[i-1][j]
            dp[i][nj] %= MOD
print(dp[-1][5])

Submission status: Wrong Answer

Solution code:
S=raw_input()
l=len(S)

dp=[ [ 0 for j in range(13)] for i in range(l+1) ]
dp[0][0]=1

mod=10**9+7

keta=1

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

	keta=(keta*4)%13

print dp[-1][5]

Submission status: Wrong Answer

Solution code:
S=raw_input()
l=len(S)

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

mod=10**9+7


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

print dp[-1][5]

Submission status: Wrong Answer

Solution code:
S=raw_input()
l=len(S)

dp=[ [ 0 for j in range(13)] for i in range(l+1) ]
dp[0][0]=1

mod=10**9+7


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

print dp[-1][5]

Submission status: Wrong Answer

Solution code:
s = input()

array = [[0 for i in range(13)] for j in range(len(s)+1)] 

array[0][0] = 1
for i in range(0,len(s)):
  if s[i] == '?':
    c = -1
  else:
    c = int(s[i])
  
  for j in range(10):
    if c != -1 and c != j:
      continue
    for k in range(13):
      array[i+1][(k*10+j) % 13] += array[i][k]
      
  for j in range(13):
    array[i+1][j] %= 1000000007
    
print(array)
print(array[len(s)][5])

Submission status: Wrong Answer

Solution code:
s = input()

array = [[0 for i in range(13)] for j in range(len(s)+1)] 

array[0][0] = 1
for i in range(0,len(s)):
  if s[i] =='?':
    c = -1
  else:
    c = int(s[i])
  
  for j in range(10):
    if c != -1 and c != j:
      continue
    for k in range(13):
      array[i+1][(k*10+j) % 13] = array[i][k]
      
  for j in range(13):
    array[i+1][j] %= 1000000007
    
print(array[len(s)][5])

Submission status: Wrong Answer

Solution code:
S = input()
P = 10**9 + 7

dp = [[0 for _ in range(13)] for _ in range(len(S)+1)]
dp[0][0] = 1
for n, c in enumerate(S):
    for i in range(10):
        if c != '?' and int(c) != i:
            continue
        for j in range(13):
            dp[n+1][(j*10+i)%13] += dp[n][j]
    
    for i in range(13):
        dp[n+1][i] %= 13

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

Submission status: Wrong Answer

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

moo=[1,10,9,12,3,4] #mooはその桁が1の時のあまり
moonine=[[] for i in range(6)] #moonineは[i][j]i桁がｊの時のあまり
for i in range(6):
  for j in range(10):
    moonine[i].append((moo[i]*j)%13)
#print(moonine)
    
A=[[]for i in range(6)] #分類したリスト
for i in range(N):
  A[((i+1)*(-1))%6].append(S[i])
#print(A)
now=0
AA=[0 for i in range(6)]
for i in range(6):
  for j in range(len(A[i])):
    if A[i][j]!="?":
      now=(now+moo[i]*int(A[i][j]))%13
      N-=1
    else:
      AA[i]+=1
#print(now,N)
dp=[[0 for i in range(13)] for i in range(N+1)]
#print(dp)
dp[0][now]=1
n=0 #ｎ回目
for i in range(len(AA)): #iはmoo何番目か
  for j in range(AA[i]):
    if AA[i]!=0:
      for k in range(13):
        for l in range(10):
          dp[n+1][(k+moonine[i][l])%13]+=dp[n][k]
          dp[n+1][(k+moonine[i][l])%13]=dp[n+1][(k+moonine[i][l])%13]%mod
          
      n+=1
    #print("n",n,A[i])

print(int(dp[N][5])%mod)

Submission status: Wrong Answer

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

moo=[1,10,9,12,3,4] #mooはその桁が1の時のあまり
moonine=[[] for i in range(6)] #moonineは[i][j]i桁がｊの時のあまり
for i in range(6):
  for j in range(10):
    moonine[i].append((moo[i]*j)%13)
#print(moonine)
    
A=[[]for i in range(6)] #分類したリスト
for i in range(N):
  A[((i+1)*(-1))%6].append(S[i])
#print(A)
now=0
AA=[0 for i in range(6)]
for i in range(6):
  for j in range(len(A[i])):
    if A[i][j]!="?":
      now=(now+moo[i]*int(A[i][j]))%13
      N-=1
    else:
      AA[i]+=1
#print(now,N)
dp=[[0 for i in range(13)] for i in range(N+1)]
#print(dp)
dp[0][now]=1
n=0 #ｎ回目
for i in range(len(AA)): #iはmoo何番目か
  for j in range(AA[i]):
    if AA[i]!=0:
      for k in range(13):
        for l in range(10):
          dp[n+1][(k+moonine[i][l])%13]+=dp[n][k]
      n+=1
    #print("n",n,A[i])

print(int(dp[N][5])%mod)

Submission status: Wrong Answer

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

moo=[1,10,9,12,3,4] #mooはその桁が1の時のあまり
moonine=[[] for i in range(6)] #moonineは[i][j]i桁がｊの時のあまり
for i in range(6):
  for j in range(10):
    moonine[i].append((moo[i]*j)%13)
#print(moonine)
    
A=[[]for i in range(6)] #分類したリスト
for i in range(N):
  A[((i+1)*(-1))%6].append(S[i])
#print(A)
now=0
AA=[[] for i in range(6)]
for i in range(6):
  for j in range(len(A[i])):
    if A[i][j]!="?":
      now=(now+moo[i]*int(A[i][j]))%13
      N-=1
    else:
      AA[i].append(A[i][j])
#print(now,N)
dp=[[0 for i in range(13)] for i in range(N+1)]
#print(dp)
dp[0][now]=1
n=0 #ｎ回目
for i in range(len(AA)): #iはmoo何番目か
  for j in range(len(AA[i])):
    for k in range(13):
      for l in range(10):
        dp[n+1][(k+moonine[i][l])%13]+=dp[n][k]
    if len(AA[i])!=0:
      n+=1
    #print("n",n,A[i])

print(int(dp[N][5])%mod)

Submission status: Wrong Answer

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

moo=[1,10,9,12,3,4] #mooはその桁が1の時のあまり
moonine=[[] for i in range(6)] #moonineは[i][j]i桁がｊの時のあまり
for i in range(6):
  for j in range(10):
    moonine[i].append((moo[i]*j)%13)
#print(moonine)
    
A=[[]for i in range(6)] #分類したリスト
for i in range(N):
  A[(i+1)%6].append(S[i])
#print(A)
now=0
AA=[[] for i in range(6)]
for i in range(6):
  for j in range(len(A[i])):
    if A[i][j]!="?":
      now=(now+moo[i]*int(A[i][j]))%13
      N-=1
    else:
      AA[i].append(A[i][j])
#print(now,N)
dp=[[0 for i in range(13)] for i in range(N+1)]
#print(dp)
dp[0][now]=1
n=0 #ｎ回目
for i in range(len(AA)): #iはmoo何番目か
  for j in range(len(AA[i])):
    for k in range(13):
      for l in range(10):
        dp[n+1][(k+moonine[i][l])%13]+=dp[n][k]
    if len(AA[i])!=0:
      n+=1
    #print("n",n,A[i])

print(int(dp[N][5])%mod)

Submission status: Wrong Answer

Solution code:
import itertools

def getint(): return int(input())
def getints(): return list(map(int, input().split()))

s = list(reversed(input()))
n = len(s)
mod = 10 ** 9 + 7
digits=[0]*n

digits[0]=1

for i in range(1,n):
    digits[i] = (10 * digits[i-1]) % 13

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

for i in range(n):
    c = -1 if s[i] == '?' else ord(s[i]) - ord('0')
    for j in range(10):
        if c != -1 and c != j:
            continue
        for ki in range(13):
            dp[i+1][(ki*10+j)%13] += dp[i][ki]
    for j in range(13):
        dp[i+1][j] %= mod

res = dp[n][5]

print(res)

Submission status: Wrong Answer

Solution code:
def main():
    n = 13
    mod = 1000000007
    r = 5
    in_str = input()

    amari_list = amari(n)
    l = len(amari_list)

    ans_list = initial(in_str[-1:], n)

    for i, s in enumerate(reversed(in_str)):
        if i == 0:
            continue
        if s == "?":
            tmp_list, ans_list = ans_list, [0]*n
            for j in range(10):
                t = j * amari_list[i % l] % n
                ans_list = [tmp_list[(i + l - t) % n] + ans_list[i]
                            for i in range(n)]
        else:
            t = int(s) * amari_list[i % l] % n
            ans_list = [ans_list[(i + l - t) % n] for i in range(n)]

        ans_list = list(map(lambda x: x % mod, ans_list))

    print(ans_list[r] % mod)


def initial(s, n):
    if s == "?":
        return [1 if i < 10 else 0 for i in range(n)]
    else:
        return [1 if i == int(s) else 0 for i in range(n)]


def amari(n):
    ret = []
    for i in range(n+1):
        r = (10**i) % n
        if r in ret:
            return ret
        else:
            ret.append(r)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np


def main():
    n = 13
    mod = 1000000007
    r = 5
    in_str = input()

    amari_list = amari(n)
    l = len(amari_list)

    ans_list = initial(in_str[-1:], n)
    shift_list = np.array([np.array([0 for i in range(n)], dtype='int64')
                           for j in range(10)], dtype='int64')

    for i, s in enumerate(reversed(in_str)):
        if i == 0:
            continue
        if s == "?":
            for j in range(10):
                for k in range(13):
                    shift_list[j][k] = ans_list[(
                        j * amari_list[i % l] + k) % n]
            ans_list = np.mod(np.sum(shift_list, axis=0), mod)

        else:
            t = int(s) * amari_list[i % l] % n
            ans_list = np.roll(ans_list, t)

    print(ans_list[r] % mod)


def initial(s, n):
    if s == "?":
        return np.array([1 if i < 10 else 0 for i in range(n)], dtype='int64')
    else:
        return np.array([1 if i == int(s) else 0 for i in range(n)], dtype='int64')


def amari(n):
    ret = []
    for i in range(n+1):
        r = (10**i) % n
        if r in ret:
            return ret
        else:
            ret.append(r)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = input()
count = 0
for i in range(len(s) - 1):
    if s[i:i+2] == "??":
        count += 1
ans = count * 7
print(ans)

Submission status: Wrong Answer

Solution code:
P=[1,10,9,12,3,4]
def f(A,p,N):
    if p<0:return [1&(i in N) for i in range(13)]
    B=[0]*13
    for n in N:
        for i in range(13):
            c=(i+(n*P[p]))%13
            B[c]=(B[c]+A[i])%(10**9+7)
    return B
S=reversed(input())
A=[]
p=-1
for s in S:
    if s=="?":A=f(A,p,range(10))
    else:A=f(A,p,[int(s)])
    p=(abs(p)+1)%6
print(A[5])

Submission status: Wrong Answer

Solution code:
P=[1,10,9,12,3,4]
def f(A,p,N):
    if p==0:return [1&(i in N) for i in range(13)]
    B=[0]*13
    for n in N:
        for i in range(13):B[(i+(n*P[p%6]))%13]+=A[i]
    return B

S=reversed(input())
A=[0]
for p,s in enumerate(S):
    print(A)
    if s=="?":A=f(A,p,range(10))
    else:A=f(A,p,[int(s)])
print(A)

Submission status: Wrong Answer

Solution code:
S = input()

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

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

ans = dp[-1][5] % M
print(ans)

Submission status: Wrong Answer

Solution code:
def solve(string):
    ans = 0
    for i in range(5, 10**(len(string)) + 1, 13):
        if is_equal(string, i):
            ans += 1
    return str(ans % (10**9 + 7))


def is_equal(s, n):
    nr = str(n)[::-1]
    sr = s[::-1]
    if len(sr) < len(nr):
        return False
    if len(sr) > len(nr) and sr[len(nr):] != "?" * (len(sr) - len(nr)):
        return False
    for _s, _n in zip(sr, nr):
        if _s not in [_n, "?"]:
            return False
    return True


if __name__ == '__main__':
    print(solve(input()))

Submission status: Wrong Answer

Solution code:
s=input()
l=len(s);mod=10**9+7
dp=[[0]*13 for i in range(l)]
rem=[1,10,9,12,3,4]
for i in range(l)[::-1]:
  dig=i%6
  if s[i]=="?":
    if i==l-1:
      for j in range(10):
        dp[-1][(j*rem[dig])%13]=1
    else:
      for j in range(10):
        for h in range(13):
          dp[i][(h+j*rem[dig])%13]+=dp[i+1][h]
          dp[i][(h+j*rem[dig])%13]%=mod
  else:
    a=int(s[i])
    if i==l-1:
      dp[i][(a*rem[dig])%13]=1
    else:
      for j in range(13):
        dp[i][(j+a*rem[dig])%13]+=dp[i+1][j]
        dp[i][(j+a*rem[dig])%13]%=mod
print(dp[0][5])

Submission status: Wrong Answer

Solution code:
s=input()
l=len(s);mod=10**9+7
dp=[[0]*13 for i in range(l)]
rem=[1,10,9,12,3,4]
for i in range(l)[::-1]:
  dig=i%6
  if s[i]=="?":
    if i==l-1:
      for j in range(10):
        dp[-1][(j*rem[dig])%13]=1
    else:
      for j in range(10):
        for h in range(13):
          dp[i][(h+j*rem[dig])%13]+=dp[i+1][h]
          dp[i][(h+j*rem[dig])%13]%=mod
  else:
    a=int(s[i])
    if i==l-1:
      dp[i][(a*rem[dig])%13]=1
    else:
      for j in range(13):
        dp[i][(j+a*rem[dig])%13]+=dp[i+1][j]
print(dp[0][5])

Submission status: Wrong Answer

Solution code:
s=input()
mod = 1000000007
 
dp = [[0 for l in range(13)] for m in range(len(s)+1)]
dp[0][0] = 1
p=[]
for i in range(1,13):
  p.append(10**(int((i-1)%12))%13)
print(p)
print(']',end='')
for i in range(1,len(s)+1):
  p = 10**(int((i-1)%12))%13
  print(p,end=' ,')
  if s[-i] == '?':
    for j in range(10):
      for k in range(13):
        dp[i][(k+j*p)%13] += dp[i-1][k]
        dp[i][(k+j*p)%13] %mod
  else:
    for k in range(13):
      dp[i][(int(s[-i])*p +k)%13] += dp[i-1][k]
      dp[i][(int(s[-i])*p +k)%13] %mod
 
print(dp[len(s)][5] %mod)

Submission status: Wrong Answer

Solution code:
s=input()
mod = 1000000007
 
dp = [[0 for l in range(13)] for m in range(len(s)+1)]
dp[0][0] = 1
p=[]
for i in range(1,13):
  p.append(10**(int((i-1)%12))%13)
print(p)
for i in range(1,len(s)+1):
  p = 10**(int((i-1)%12))%13
  print(p,end=' ')
  if s[-i] == '?':
    for j in range(10):
      for k in range(13):
        dp[i][(k+j*p)%13] += dp[i-1][k]
        dp[i][(k+j*p)%13] %mod
  else:
    for k in range(13):
      dp[i][(int(s[-i])*p +k)%13] += dp[i-1][k]
      dp[i][(int(s[-i])*p +k)%13] %mod
 
print(dp[len(s)][5] %mod)

Submission status: Wrong Answer

Solution code:
s=input()
mod = 1000000007
 
dp = [[0 for l in range(13)] for m in range(len(s)+1)]
dp[0][0] = 1
for i in range(1,len(s)+1):
  p = 10**(int((i-1)%12))%mod
  if s[-i] == '?':
    for j in range(10):
      for k in range(13):
        dp[i][(k+j*p)%13] += dp[i-1][k]
        dp[i][(k+j*p)%13] %mod
  else:
    for k in range(13):
      dp[i][(int(s[-i])*p +k)%13] += dp[i-1][k]
      dp[i][(int(s[-i])*p +k)%13] %mod
 
print(dp[len(s)][5] %mod)

Submission status: Wrong Answer

Solution code:
s=input()
mod = 1000000007

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

print(dp[len(s)][5] %mod)

Submission status: Wrong Answer

Solution code:
s=input()
mod = 1000000007

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

print(dp[len(s)][3] %mod)

Submission status: Wrong Answer

Solution code:
s=[int(x) if x!="?" else '?' for x in input()]
mod=10**9+7
n = len(s)
dp=[[0]*(14) for i in range(n+1)]
dp[0][0]=1
for i in range(0,n):
# for i in range(1)
	for j in range(14):
		if s[i]!='?':
		
			if j-(s[i]*(10**(n-i-1)))%13>=0:
				dp[i+1][j]=dp[i][j-(s[i]*(10**(n-i-1)))%13]%mod
			else:
				dp[i+1][j]=dp[i][j-(s[i]*(10**(n-i-1)))%13+13]%mod
		
		else:
			for k in range(10):

				# print(j)
				if j-(k*(10**(n-i-1)))%13>=0:
					dp[i+1][j]+=dp[i][j-(k*(10**(n-i-1)))%13]%mod
				else:
					dp[i+1][j]+=dp[i][j-(k*(10**(n-i-1)))%13+13]%mod
				
print(dp)
# print(s)
print(dp[n][5]%mod)

Submission status: Wrong Answer

Solution code:
import numpy as np
S = input()
INF = 10 ** 9 + 7
dp = [np.array([0 for _ in range(13)]) for l in range(len(S))]
S_li = [_ for _ in S]
S_li = S_li[::-1]
if S_li[0] == '?':
    dp[0][0:10] = [1,1,1,1,1,1,1,1,1,1]
else:
    dp[0][int(S_li[0])] = 1
for _ in range(1,len(S)):
    if S_li[_] == '?':
        for x in range(10):
            mod = (x * (10 ** (_ % 6))) % 13
            add = list(dp[_ - 1][(13 - mod):13]) + list(dp[_ - 1][0:(13 - mod)])
            dp[_] += np.array(add)
    else:
        s = int(S_li[_])
        mod = (s * (10 ** (_ % 6))) % 13
        add = list(dp[_ - 1][(13 - mod):13]) + list(dp[_ - 1][0:(13 - mod)])
        dp[_] += np.array(add)
print(dp[-1][5] % INF)

Submission status: Wrong Answer

Solution code:
import numpy as np
S = input()
INF = 10 ** 9 + 7
dp = [np.array([0 for _ in range(13)]) for l in range(len(S))]
S_li = [_ for _ in S]
S_li = S_li[::-1]
if S_li[0] == '?':
    dp[0][0:10] = [1,1,1,1,1,1,1,1,1,1]
else:
    dp[0][int(S_li[0])] = 1
for _ in range(1,len(S)):
    if S_li[_] == '?':
        for x in range(10):
            mod = (x * (10 ** (_ % 6))) % 13
            add = list(dp[_ - 1][(13 - mod):13]) + list(dp[_ - 1][0:(13 - mod)])
            dp[_] += np.array(add)
    else:
        s = int(S_li[_])
        mod = (s * (10 ** (_ % 6))) % 13
        add = list(dp[_ - 1][(13 - mod):13]) + list(dp[_ - 1][0:(13 - mod)])
        dp[_] += np.array(add)
print(dp[-1][5] % INF)
print(dp[-1])

Submission status: Wrong Answer

Solution code:
import numpy as np
S = "3900"
INF = 10 ** 9 + 7
dp = [np.array([0 for _ in range(13)]) for l in range(len(S))]
S_li = [_ for _ in S]
S_li = S_li[::-1]
if S_li[0] == '?':
    dp[0][0:10] = [1,1,1,1,1,1,1,1,1,1]
else:
    dp[0][int(S_li[0])] = 1
for _ in range(1,len(S)):
    if S_li[_] == '?':
        for x in range(10):
            mod = (x * (10 ** (_ % 6))) % 13
            add = list(dp[_ - 1][(13 - mod):13]) + list(dp[_ - 1][0:(13 - mod)])
            dp[_] += np.array(add)
    else:
        s = int(S_li[_])
        mod = (s * (10 ** (_ % 6))) % 13
        add = list(dp[_ - 1][(13 - mod):13]) + list(dp[_ - 1][0:(13 - mod)])
        dp[_] += np.array(add)
print(dp[-1][5] % INF)
print(dp[-1])

Submission status: Wrong Answer

Solution code:
import numpy as np
S = input()
INF = 10 ** 9 + 7
dp = [np.array([0 for _ in range(13)]) for l in range(len(S))]
S_li = [_ for _ in S]
S_li = S_li[::-1]
if S_li[0] == '?':
    dp[0][0:10] = [1,1,1,1,1,1,1,1,1,1]
else:
    dp[0][int(S_li[0])] = 1
for _ in range(1,len(S)):
    if S_li[_] == '?':
        for x in range(10):
            mod = (x * (10 * (_ % 6))) % 13
            add = list(dp[_ - 1][(13 - mod):13]) + list(dp[_ - 1][0:(13 - mod)])
            dp[_] += np.array(add)
    else:
        s = int(S_li[_])
        mod = (s * (10 * (_ % 6))) % 13
        add = list(dp[_ - 1][(13 - mod):13]) + list(dp[_ - 1][0:(13 - mod)])
        dp[_] += np.array(add)
print(dp[-1][5] % INF)

Submission status: Wrong Answer

Solution code:
S = "?6?42???8??2??06243????9??3???7258??5??7???????774????4?1??17???9?5?70???76???"
INF = 10 ** 9 + 7
mod = [1,10,9,12,3,4]
dp = [[0 for _ in range(13)] for l in range(len(S))]
S_li = [_ for _ in S]
S_li = S_li[::-1]
if S_li[0] == '?':
    dp[0][0:10] = [1,1,1,1,1,1,1,1,1,1]
else:
    dp[0][int(S_li[0])] = 1
for _ in range(1,len(S)):
    if S_li[_] == '?':
        for x in range(10):
            for y in range(13):
                dp[_][(x * mod[_ % 6] + y) % 13] += dp[_ - 1][y] % INF
    else:
        for y in range(13):
            dp[_][(int(S_li[_]) * mod[_ % 6] + y) % 13] += dp[_ - 1][y] % INF
print(dp[-1][5] % INF)

Submission status: Wrong Answer

Solution code:
N = str(input())

n = list(N)
maxn = eval("9"*len(n))
maxn_n = maxn // 13
maxn_r = maxn % 13

p_name = []
p_number = []
for i in range(0, len(n)):
 if n[i] != "?":
  p_name.append(n[i])
  p_number.append(i)

ns = []
ns_sum = []
for i in range(0, maxn_n):
 p1 = str(13*i + 5)
 p1 = p1.zfill(len(n))
 ns.append(p1)
 p1_str = list(p1)
 all_true = bool(True)
 for j in range(0, len(p_name)):
  if p1_str[p_number[j] ] != p_name[j]:
   all_true = bool(False); break
 if all_true:
  ns_sum.append(p1)

print(len(ns_sum))

Submission status: Wrong Answer

Solution code:
mod = 1000000007

s= [int(x) if x != "?" else -1 for x in input()]

n=len(s)
T=13
dp=[0]*T
c=s[n-1]
if (c!=-1):
	dp[c]=1
else:
	for i in range(10):dp[i]=1
mul = 1
for i in range(2,n+1):
	c=s[n-i]
	nextdp = [0] * T
	if (c==-1):
		for k in range(10):
			for j in range(T):
				nextdp[(k * mul + j)%T] += dp[j]
				nextdp[(k * mul + j)%T] %= mod
	else:
		k = s[n-i]
		for j in range(T):
			nextdp[(k * mul + j) % T] += dp[j]
			nextdp[(k * mul + j) % T] %= mod
	mul *= 10
	mul %= T
	dp = nextdp


print (dp[5]%mod)

Submission status: Wrong Answer

Solution code:
mod = 1000000007

s= [int(x) if x != "?" else -1 for x in input()]

n=len(s)
T=13
dp=[0]*T
c=s[n-1]
if (c!=-1):
	dp[c]=1
else:
	for i in range(10):dp[i]=1
mul = 1
for i in range(0,n-1):
	c=s[n-2-i]
	nextdp = [0] * T
	if (c==-1):
		for k in range(10):
			for j in range(T):
				nextdp[(k * mul + j)%T] += dp[j]
				nextdp[(k * mul + j)%T] %= mod
	else:
		k = s[n-1-i]
		for j in range(T):
			nextdp[(k * mul + j) % T] += dp[j]
			nextdp[(k * mul + j) % T] %= mod
	mul *= 10
	mul %= T
	dp = nextdp


print (dp[5]%mod)

Submission status: Wrong Answer

Solution code:
S = input()

origin = S
dp = [1,0,0,0,0,0,0,0,0,0,0,0,0]

dig = 1
for n in reversed(origin):
    next_dp = [0] * 13
    if n == '?':
        for n in range(10):
            mod = (n * dig) % 13
            for i in range(13):
                next_dp[(i+mod)%13]+=dp[i]
        dp = next_dp[:]
    else:
        mod = (int(n) * dig) % 13
        next_dp = dp[mod:] + dp[:mod]
        dp = next_dp[:]
    dig = dig * 10 % 13
    
ans = dp[5] % (10**9+7)
print(ans)

Submission status: Wrong Answer

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

dp=[[0 for j in range(13)] for i in range(l+1)]
dp[0][0]=1
for i in range(l):
    if s[i] == "?":
        for j in range(10):
            for k in range(13):
                dp[i+1][(k*10+j)%13] += dp[i][k]%mod
    else:
        for k in range(13):
            dp[i+1][(k*10+int(s[i]))%13]+=dp[i][k]%mod
print(dp[-1][5])

Submission status: Wrong Answer

Solution code:
#数字はnumberに格納
number=input()
length=len(number)

#まずはからのDPリストを用意
dp=[[0 for i in range(13)] for j in range(length)]

#1桁目の情報を入力
if number[-1]=="?":
    for i in range(10):
        dp[0][i]=1
else:
    dp[0][int(number[-1])]=1

#１０〜９０の、13modリストを作る
modlist=[(i*10)%13 for i in range(10)]


        
#二桁目からの情報を更新していく。
for n in range(length-1):
    #n桁目の情報があれば、次のようにn+1行目を更新。

    #n+1のくらいの数をchecknumとする
    checknum=number[-1*(n+1)-1]
#     print(checknum)

    #n+1の位が整数であれば
    if checknum!="?":
        
        #n[m]の値をn+1[m+(その整数)]にすればいい
        for m in range(13):
            dp[n+1][(m+modlist[int(checknum)])%13]+=dp[n][m]
#         print(dp)
        
        
        
        
        
    #n+1のくらいが？の時
    else:
    #？が０〜９までの可能性を全て試す  
    
        for checknum in range(10):
            for m in range(13):
                dp[n+1][(m+modlist[int(checknum)])%13]+=dp[n][m]
#             print(dp)

    #modlistを更新
    modlist=[(j*10)%13 for j in modlist]


print(dp[-1][5])

Submission status: Wrong Answer

Solution code:
#数字はnumberに格納
number=input()
length=len(number)
# print(length)

#まずはからのDPリストを用意
dp=[[0 for i in range(13)] for j in range(length)]

#1桁目の情報を入力
if number[-1]=="?":
    for i in range(10):
        dp[0][i]=1
else:
    dp[0][int(number[-1])]=1
# print(dp)

#１０〜９０の、13modリストを作る

modlist=[(i*10)%13 for i in range(10)]
# print(modlist)


        
#二桁目からの情報を更新していく。
for n in range(length-1):
    #n桁目の情報があれば、次のようにn+1行目を更新。

    #n+1のくらいの数をchecknumとする
    checknum=number[-1*(n+1)-1]
#     print(checknum)

    #n+1の位が整数であれば
    if checknum!="?":
        
        #n[m]の値をn+1[m+(その整数)]にすればいい
        for m in range(13):
            dp[n+1][(m+modlist[int(checknum)])%13]=dp[n][m]
#         print(dp)
        
        
        
        
        
    #n+1のくらいが？の時
    else:
    #？が０〜９までの可能性を全て試す  
    
        for checknum in range(10):
            for m in range(13):
                dp[n+1][(m+modlist[int(checknum)])%13]+=dp[n][m]
#             print(dp)

    #modlistを更新
    modlist=[(j*10)%13 for j in modlist]
        
        
        
# print(dp)

# for i in range(length):
#     if number[-1*(i+1)]!="?":
#         for j in range(13):
#             dp[i]

print(dp[-1][5])

Submission status: Wrong Answer

Solution code:
import numpy as np

mod = 10**9+7
p = list(input())
# p = list("?"*10**4)

# アルゴリズム
dp = np.zeros(13, dtype=int)
new_dp = np.zeros(13, dtype=int)

dp[0] = 1
mul = 1

for key in reversed(p):
    
    if key == "?":
        for i in range(10):
            for j in range(13):
                new_dp[(j + i * mul) % 13] += dp[j]
                new_dp[(j + i * mul) % 13] %= mod
    else:
        
        for j in range(13):
            new_dp[(j + int(key) * mul) % 13] += dp[j]
            new_dp[(j + int(key) * mul) % 13] %= mod
    dp = new_dp.copy()
    mul *= 10

print(dp[5])

Submission status: Wrong Answer

Solution code:
x = 1000000007

S = input()
S = [int(s) if s != '?' else s for s in S]
S = S[::-1]

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

dp[0][0] = 1

for i, s in enumerate(S):
    for j in range(10):
        if s != '?' and s != j:
            continue

        digit_r = ((10 ** i) * j) % 13

        for k in range(13):
            r = (digit_r + k) % 13
            dp[i + 1][r] += dp[i][k]

    dp[i + 1][r] %= 13

print(int(dp[-1][5] % x))

Submission status: Wrong Answer

Solution code:
s = input()
mod = 1000000007


dp = [[0 for i in range(13)] for j in range(len(s)+1)]

dp[0][0] = 1

for i in range(len(s)):
    if s[len(s)-i-1] != "?":
        temp = int(s[len(s)-i-1])*(10**i) % 13
        for j in range(13):
            dp[i+1][j] = dp[i][(j-temp+13)%13]

    else:
        amari = [(t*(10**i))%13 for t in range(10)]
        for j in range(13):
            for a in amari:
                dp[i+1][j] += dp[i][(j-a+13)%13]
                
print(dp[len(s)][5])