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 = input()
L = len(S)
V = [0] * (13 * L)
A = 0
flag = True

for i in range(L):
  if S[L-i-1] == '?':
    for j in range(13):
      V[i*13+j] = V[(i-1)*13+j]
    
    if flag:
      for j in range(10):
        k = j * pow(10, i) % 13
        V[i*13+k%13] += 1
      flag = False
        
    else:
      for j in range(1, 10):
        k = j * pow(10, i) % 13
        for m in range(13):
          V[i*13+(m+k)%13] += V[(i-1)*13+m]
          
  else:
    A = 10 ** i * int(S[L-i-1]) % 13
    for j in range(13):
       V[i*13+j] = V[(i-1)*13+(j+A)%13]
  
  for j in range(13):
    V[i*13+j] = V[i*13+j] % (10 ** 9 + 7)
    
print(V[-8])

Submission status: Wrong Answer

Solution code:
S = input()
L = len(S)
V = [[0] * 13 for i in range(L)]
A = 0
flag = True

for i in range(L):
  if S[L-i-1] != '?':
    A += 10 ** i * int(S[L-i-1]) % 13
A = A % 13


for i in range(L):
  
  for j in range(13):
    V[i][j] = V[i-1][j]
  
  if S[L-i-1] == '?':
    
    if flag:
      for j in range(10):
        k = j * pow(10, i) % 13
        V[i][k%13] += 1
      flag = False
        
    else:
      for j in range(1, 10):
        k = j * pow(10, i) % 13
        for m in range(13):
          V[i][(m+k)%13] += V[i-1][m]

print(V[-1][(18-A)%13]% (10 ** 9 + 7))

Submission status: Wrong Answer

Solution code:
import numpy as np
def main():
    S=input()
    MOD=10**9+7
    if S[-1]=="?":
        Rem=np.array([1,1,1,1,1,1,1,1,1,1,0,0,0])
    else:
        Rem=np.array([0]*13)
        Rem[int(S[-1])]=1
    for i in range(1,len(S)):
        s=S[-1-i]
        if s!="?":
            Rem=np.roll(Rem,shift=(int(s)*10**i)%13)
        else:
            ret=np.array([0]*13)
            for j in range(10):
                ret+=np.roll(Rem,shift=(j*10**i)%13)
            Rem=ret
    print(Rem[5]%MOD)
if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
S = input()

T = [s if s != "?" else "0" for s in S]
T = int(''.join(T))
SS = T % 13

c = {}
iii = 1
for i in range(len(S)):
    if S[len(S) - i - 1] != "?":
        continue
    tc = {i: 0 for i in range(13)}
    for j in range(0, 10):
        t = j * iii
        tc[t % 13] += 1
    c[i] = tc
    iii *= 10
    iii %= 13

dp = []
tdp = {i: 0 for i in range(13)}
tdp[SS] += 1
dp.append(tdp)
for k, v in c.items():
    tdp = {i: 0 for i in range(13)}
    for r, _ in v.items():
        if _ > 0:
            for _r, _v in dp[-1].items():
                tdp[(_r + r) % 13] += _v
    dp.append(tdp)

ans = dp[-1][5]
print(ans % (10**9 + 7))

Submission status: Wrong Answer

Solution code:
def update(i, j, mul):
    global dp, dpi, N, MOD


#S = input()
S = "?"*(10**4)

MOD=(10**9) + 7
N=13

dp=[[0 for i in range(N)] for j in range(100005)]
dp[0][0] = 1

dpi = 1
mul = 1

for c in S[::-1]:    
    for i in range(N):
        if c=='?':
            for j in range(10):
                ii = (i + (j*mul)) % N
                dp[dpi][ii] += dp[dpi-1][i] % MOD
                #pass
        else:
            j = int(c)
            ii = (i + (j*mul)) % N
            dp[dpi][ii] += dp[dpi-1][i] % MOD
            #pass
    mul *= 10
    mul %= N
    dpi += 1

print(dp[dpi-1][5] % MOD)

Submission status: Wrong Answer

Solution code:
s = ''.join(reversed(input()))
multiplier = 1
divisor = 10 ** 9 + 7
p = [0 for i in range(13)]
np = [0 for i in range(13)]
if s[0] != '?':
  p[int(s[0])] = 1
else:
  for j in range(10):
    p[j] = 1
for i in range(1, len(s)):
  multiplier = (10 * multiplier) % 13
  if s[i] != '?':
    r = int(s[i]) * multiplier
    for j in range(13):
      np[(j + r) % 13] = p[j]
  else:
    r = 0
    for j in range(10):
      r += multiplier
      for k in range(13):
        np[(k + r) % 13] += p[k]
  for j in range(13):
    p[j] = np[j] % divisor
    np[j] = 0
print(p[5] % divisor)

Submission status: Wrong Answer

Solution code:
S = input()

MOD=(10**9) + 7
N=13

dp=[0]*N
dp[0] = 1

mul = 1
for c in S[::-1]:
    next_dp=[0]*N
    
    for i in range(N):
        if c=='?':
            for j in range(10):
                ii = (i + (int(j)*mul)) % N
                next_dp[ii] += dp[i]
        else:
            ii = (i + (int(c)*mul)) % N
            next_dp[ii] += dp[i]
        next_dp[i] = next_dp[i] % MOD

    mul *= 10
    dp = next_dp

print(dp[5])

Submission status: Wrong Answer

Solution code:
import math
S=input()
dp=[0]*13
dp[0]=1
# dp[k] 13で割った余りkのパターン数
mod = 1000000007

for i in range(len(S)):
    nextDp=[0]*13
    if S[i] == "?":
        for j in range(13):
            for k in range(10):
                nextDp[((10*j) + k) % 13] += dp[j]
                nextDp[((10*j) + k) % 13] %= mod
    else:
        k = int(S[i])
        for j in range(13):
            nextDp[((10*j) + k) % 13] += dp[j]
            nextDp[((10*j) + k) % 13] %= mod
    for j in range(13):
        dp[j] = nextDp[j]
    print(dp)

print(dp[5])

Submission status: Wrong Answer

Solution code:

Submission status: Wrong Answer

Solution code:
import math
S=input()
dp=[0]*13
nextDp=[0]*13
dp[0]=1
# dp[k] 13で割った余りkのパターン数
mod = 1000000007
for i in range(len(S)):
    if S[i] == "?":
        for j in range(13):
            for k in range(10):
                nextDp[(10*j + k) % 13] += dp[k]
                nextDp[(10*j + k) % 13] %= mod
    else:
        k = int(S[i])
        for j in range(13):
            nextDp[(10 * j + k) % 13] += dp[k]
            nextDp[(10 * j + k) % 13] %= mod
    for j in range(13):
        dp[j] = nextDp[j]

print(dp[5])

Submission status: Wrong Answer

Solution code:
import copy

# standart input
# n = int(input())
# a = list(map(int, input().split()))

N = 13
MOD = 10 ** 9 + 7

s = input()
rs = reversed(s)

dp = [0 for i in range(N)]
dp[0] = 1
zeros = [0 for i in range(N)]

for i, si in enumerate(rs):
    nextdp = zeros

    for j in range(10):
        c = 0
        if si == "?":
            c = (j * 10 ** i) % N
        elif j == 0:
            c = (int(si) * 10 ** i) % N
        else:
            break

        for k in range(N):
            nextdp[(k + c) % N] = (nextdp[(k + c) % N] + dp[k]) % MOD

    dp = nextdp

print(dp[5])

Submission status: Wrong Answer

Solution code:
import copy

# standart input
# n = int(input())
# a = list(map(int, input().split()))
N = 13
MOD = 1000000000 + 7
s = input()
dp = [0 for i in range(N)]
dp[0] = 1

for i, si in enumerate(reversed(s)):

    nextdp = [0 for i in range(N)]
    for j in range(10):
        c = 0
        if si == "?":
            c = (j * 10 ** i) % N
        elif j == 0:
            c = (int(si) * (i + 1)) % N
        else:
            break

        for k in range(N):
            nextdp[(k + c) % N] += dp[k]
            nextdp[(k + c) % N] %= MOD

    dp = copy.copy(nextdp)

print(dp[5])

Submission status: Wrong Answer

Solution code:
def main():
    mod = 10**9+7
    s = list(input())
    n = len(s)
    s = s[::-1]    

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

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

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
d=[0]*13
d[0]=1
mul=1
mulmod=1
t=input()[::-1]
mod=10**9+7
zero=[0]*13

for c in t:
    e=zero[:]
    if c=="?":
        for i in range(10):
            for j in range(13):
                k=(i*mulmod+j)%13
                e[k]+=d[j]
                e[k]%=mod
    else:
        for j in range(13):
            k=(int(c)*mul+j)%13
            e[k]+=d[j]
            e[k]%=mod
    d=e
    mul=mul*10%13
print(d[5])

Submission status: Wrong Answer

Solution code:
d=[0]*13
d[0]=1
mul=1
mulmod=1
t=input()[::-1]

zero=[0]*13
l=len(t)
modlist=[10**i%13 for i in range(l)]
for n,c in enumerate(t):
    e=zero[:]

    for i in (range(10) if c=="?" else[int(c)]):
        for j in range(13):
            #e[(i*mul+j)%13]+=d[j]
            k=(i*mulmod+j)%13
            e[k]+=d[j]
            e[k]%=1000000007
    d=e
    mul*=10
    mulmod=mul%13

Submission status: Wrong Answer

Solution code:
d=[0]*13
d[0]=1
mul=1
mulmod=1
t=list(input())
t.reverse()
zero=[0]*13
l=len(t)
modlist=[10**i%13 for i in range(l)]
for n,c in enumerate(t):
    e=zero[:]

    for i in (range(10) if c=="?" else[int(c)]):
        for j in range(13):
            #e[(i*mul+j)%13]+=d[j]
            k=(i*modlist[n])%13
            e[k]+=d[j]
            e[k]%=1000000007
    d,e=e,d
    mul*=10
    #mulmod=mul%13
print(d[5])

Submission status: Wrong Answer

Solution code:

d=[0]*13
d[0]=1
mul=1
mulmod=1
t=list(input())
#t.reverse()
for c in t:
    e=[0]*13

    for i in (range(10) if c=="?" else[int(c)]):
        for j in range(13):
            #e[(i*mul+j)%13]+=d[j]
            e[(i*mulmod+j)%13]+=d[j]
            
    d=[e%(10**9+7)for e in e]
    mul*=10
    mulmod=mul%13
print(d[5])

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
MAX = 10**5+5
INF = 10**9

def resolve():
    s = input().strip()
    dp = [[0]*13 for _ in range(MAX)]
    dp[0][0]=1
    for i,x in enumerate(s):
        c=ord(x)-48
        for j in range(10):
            if(x!='?' and c!=j):
                continue
            for k in range(13):
                t=(k*10+j)%13
                dp[i+1][t] = dp[i+1][t]+dp[i][k]
    l=len(s)
    print(dp[l][5])


if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
M = 10**9 + 7
a = [1] + [0] * 12
p = 1
for c in reversed(input()):
    x, y = (0, p * 10) if c == '?' else (int(c), int(c) + 1)
    a = [sum(a[(i - j) % 13] for j in range(x, y, p)) % M for i in range(13)]
    p = p * 10 % 13
print(a[5])

Submission status: Wrong Answer

Solution code:
def INT_(n): return int(n)-1
def MI(): return map(int, input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_, input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n: int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split())) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
MOD = 10**9 + 7

import numpy as np

pow_mods = [1, 10, 9, 12, 3, 4]


def main():
    S = input()
    length = len(S)
    dp = np.zeros((length, 13), dtype=np.int64)
    # dp = [[0] * 13 for _ in range(length)]
    for idx, s in enumerate(S[::-1]):
        # power = length - idx - 1
        power = idx
        if s == '?':
            table = get_table(power)
            if idx == 0:
                for mod in table:
                    dp[idx, mod] += 1
                continue
            for mod in table:
                for j in range(13):
                    dp[idx, (j + mod) % 13] += dp[idx - 1, j] % MOD
        else:
            mod = (int(s) * pow_mods[power % 6]) % 13
            for j in range(13):
                dp[idx, (j + mod) % 13] += dp[idx - 1, j] % MOD

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


def get_table(n):
    return [(i * pow_mods[n % 6]) % 13 for i in range(10)]


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def INT_(n): return int(n)-1
def MI(): return map(int, input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_, input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n: int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split())) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
MOD = 10**9 + 7


def main():
    S = input()
    length = len(S)
    dp = [[0] * 13 for _ in range(length)]
    for idx, s in enumerate(S):
        power = length - idx - 1
        if s == '?':
            table = get_table(power)
            if idx == 0:
                for mod in table:
                    dp[idx][mod] += 1
                continue
            for mod in table:
                for j in range(13):
                    dp[idx][(j + mod) % 13] += dp[idx - 1][j] % MOD
        else:
            mod = int(s) * (10**power) % 13
            for j in range(13):
                dp[idx][(j + mod) % 13] += dp[idx - 1][j] % MOD

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


def get_table(n):
    return [(i * (10**n)) % 13 for i in range(10)]


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
MOD = 10 ** 9 + 7

S = input().strip()
N = 13

dp = [0] * N
dp[0] = 1

for i in range(len(S)):
  next_dp = [0] * N
  c = S[i]
  if c == '?':
    for j in range(10):
      for k in range(N):
        next_dp[(k * i + j) % N] += dp[k]
        next_dp[(k * i + j) % N] %= MOD
  else:
    j = int(c)
    for k in range(N):
      next_dp[(k * i + j) % N] += dp[k]
      next_dp[(k * i + j) % N] %= MOD

  dp = next_dp

print(dp[5])

Submission status: Wrong Answer

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


def main():
    # s = input()[::-1]
    s = '?' * 10 ** 5
    mod = 10 ** 9 + 7

    # DPテーブル（あまりが0～12となる組み合わせを管理）を用意
    n = 13
    dp = [0 for _ in range(n)]
    dp[0] = 1

    # 桁数の初期化
    digit = 1

    # 1文字ずつ見る
    for si in s:
        # 更新用のテーブルnext_dp[n]を用意
        next_dp = [0 for _ in range(n)]

        if si == '?':
            # '?'の取りうる範囲
            for q in range(10):
                # XXX: next_dpの括弧内の理解がかなり怪しい
                # digit - 1桁のときの結果を使って，
                # それぞれのあまりについて組み合わせの数を更新
                for j in range(n):
                    next_dp[(q * digit + j) % n] += dp[j]
                    next_dp[(q * digit + j) % n] %= mod
        else:
            q = int(si)

            for j in range(n):
                next_dp[(q * digit + j) % n] += dp[j]
                next_dp[(q * digit + j) % n] %= mod

        # DPテーブルを上書き
        dp = next_dp

        # 桁数を1つ増やす
        digit *= 10
        digit %= n

    # dp[5]が答え
    print(dp[5])


if __name__ == '__main__':
    main()

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 i in range(len(S)):
  c = -1
  if S[i] != '?':
    c = int(S[i])

  for j in range(10):
    if c != -1 and c != j:
      continue
    for k in range(13):
      dp[i + 1][(k * 10 + j) % 13] += dp[i][k]
      
  for j in range(13):
    dp[i + 1][j] %= MOD
  print(dp)

res = dp[len(S)][5]

print(res)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

def main():
	mod = 10**9 + 7
	N = 13
	dp = [0] * N
	dp[0] = 1
	s = input().strip()
	mul = 1
	for i in reversed(range(len(s))):
		nextdp = [0] * N
		if s[i] == '?':
			for k in range(10):
				for j in range(N):
					nextdp[(k * mul + j) % N] += dp[j]
					nextdp[(k * mul + j) % N] %= mod
		else:
			k = ord(s[i])
			for j in range(N):
				nextdp[(k * mul + j) % N] += dp[j]
				nextdp[(k * mul + j) % N] %= mod
		mul *= 10
		mul %= N
		dp = nextdp
	print(dp[5])

if __name__ == '__main__':
	main()

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
for i in range(n):
    c = -1 if s[i] == '?' else int(s[i])
    for digit in range(10):
        if not (c == -1 or c == digit): continue
        for kisu in range(13):
            dp[i+1][(kisu * 10 + digit) % 13] += dp[i][kisu] % MOD

print(dp[n][5])

Submission status: Wrong Answer

Solution code:
mod = 10 ** 9 + 7

s = input()
digt = len(s)

memo = [ [ -1 ] * 13 for i in range(len(s))]

import sys
sys.setrecursionlimit(100000)


def dfs(h, i):
    # 停止条件
    if h == len(s):
        if i == 0:
            return 1
        else:
            return 0
    if memo[h][i] != -1:
        return memo[h][i]
    if s[h] != '?':
        tmp = (int(s[h]) * (10 ** (digt-h-1))) % 13
        ret = dfs(h+1, (i-tmp) % 13) % mod
        memo[h][i] = ret
        return ret
    else:
        ret = 0
        for j in range(10):
            tmp = (j * (10 ** (digt - h - 1))) % 13
            ret += dfs(h+1, (i-tmp) % 13) % mod
        memo[h][i] = ret
        return ret

print(dfs(0, 5))

Submission status: Wrong Answer

Solution code:
S = input()

mod = 10**9+7
N = len(S)
ans = 0

memo = {}
for i in range(1000):
    s = str(i).zfill(3)
    memo[s] = [0 for _ in [0]*13]
    memo[s][i%13] = 1

def rep_Q_count(s):
    memo[s] = [0 for _ in [0]*13]
    for q in range(10):
        s2 = s.replace("?",str(q),1)
        for i,n in enumerate(memo[s2]):
            memo[s][i] += n

for i in range(100):
    s = str(i).zfill(2)
    rep_Q_count(s+"?")
    rep_Q_count(s[0]+"?"+s[1])
    rep_Q_count("?"+s)
for i in range(10):
    s = str(i)
    rep_Q_count(s+"??")
    rep_Q_count("?"+s+"?")
    rep_Q_count("??"+s)
rep_Q_count("???")

s0 = S[N-3:N].zfill(3)
dp = memo[s0][:]
for i in range(1,(N-1)//3+1):
    s = S[max(0,N-(i+1)*3):N-i*3].zfill(3)
    j = i%2
    tmp = memo[s]
    dp2 = [0]*13
    for k,n in enumerate(tmp):
        for l,m in enumerate(dp):
            dp2[(l+k*((-1)**j))%13] += n*m
    dp = dp2
    for i in range(13):
        dp[i] %= mod
print(dp[5])

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
import numpy as np

MOD = 10 ** 9 + 7
S = input().rstrip()

ten = np.zeros(13, dtype=np.int64)
ten[:10] += 1
add_all = [ten]
for _ in range(5):
  add_all.append(add_all[-1][np.arange(0,52,4)%13])

add_single = [[x * 10 ** i for x in range(10)] for i in range(6)]

add_all_count = [0] * 6
constant_term = 0
for i,s in enumerate(S[::-1]):
  if s == '?':
    add_all_count[i%6] += 1
  else:
    constant_term += add_single[i%6][int(s)]

def convolve(x,y):
  z = np.convolve(x,y) % MOD
  z[:12] += z[13:25]
  return z[:13] % MOD

def nth_convolve(arr,n):
  if n == 1:
    return arr
  x = nth_convolve(arr,n>>1)
  x = convolve(x,x)
  return convolve(arr,x) if n & 1 else x

dp = np.zeros(13, dtype=np.uint64)
dp[constant_term % 13] = 1
for arr,n in zip(add_all, add_all_count):
  if n > 0:
    dp = convolve(dp, nth_convolve(arr,n))

print(dp[5])

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
import numpy as np

MOD = 10 ** 9 + 7
S = input().rstrip()

ten = np.zeros(13, dtype=np.int64)
ten[:10] += 1
add_all = [ten]
for _ in range(5):
  add_all.append(add_all[-1][np.arange(0,52,4)%13])

add_single = [[x * 10 ** i for x in range(10)] for i in range(6)]

add_all_count = [0] * 6
constant_term = 0
for i,s in enumerate(S[::-1]):
  if s == '?':
    add_all_count[i%6] += 1
  else:
    constant_term += add_single[i%6][int(s)]

def convolve(x,y):
  z = np.convolve(x,y) % MOD
  z[:12] += z[13:25]
  return z[:13] % MOD

def nth_convolve(arr,n):
  if n == 1:
    return arr
  x = nth_convolve(arr,n>>1)
  x = convolve(x,x)
  return convolve(arr,x) if n & 1 else x

dp = np.zeros(13, dtype=np.int64)
dp[constant_term % 13] = 1
for arr,n in zip(add_all, add_all_count):
  if n > 0:
    dp = convolve(dp, nth_convolve(arr,n))

print(dp[5])

Submission status: Wrong Answer

Solution code:
import numpy as np
MOD = 10 ** 9 + 7

dp = np.zeros(13, dtype = np.int64)
dp[0] = 1

move = np.arange(0,52,4) % 13
ten = np.ones(10, dtype=np.int64)
for s in input():
  dp = dp[move]
  if s == '?':
    dp = np.convolve(dp, ten)
    dp[:9] += dp[13:22]
    dp %= MOD
  else:
    s = int(s)
    dp = np.roll(dp, -s)
  
print(dp[5])

Submission status: Wrong Answer

Solution code:
import numpy as np
MOD = 10 ** 9 + 7

dp = np.zeros(13, dtype = np.int64)
dp[0] = 1

move = np.arange(0,52,4) % 13
for s in input():
  prev = dp#[move]
  dp = np.zeros(13, dtype=np.int64)
  if s == '?':
    add = range(10)
  else:
    add = [int(s)]
  for x in add:
    dp[x:13] += prev[:13-x]
    dp[0:x] += prev[13-x:13]
  dp %= MOD
  
print(dp[5])

Submission status: Wrong Answer

Solution code:
import numpy as np
MOD = 10 ** 9 + 7

dp = np.zeros(13, dtype = np.int64)
dp[0] = 1

move = np.arange(0,130,10) % 13
for s in input():
  prev = dp[move]
  dp = np.zeros(26, dtype=np.int64)
  if s == '?':
    add = range(10)
  else:
    add = [int(s)]
  for x in add:
    dp[x:x+13] += prev
  dp[:13] += dp[13:]
  dp %= MOD
  
print(dp[5])

Submission status: Wrong Answer

Solution code:
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

import re
# import numpy as np
# from scipy.misc import comb

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e18)
MOD = int(1e9)+7 # 10^9 + 7

# field[H][W]
def create_grid(H, W, value = 0):
    return [[ value for _ in range(W)] for _ in range(H)]

########

S = input()
N = len(S)

# dp[i][k]: i桁目までのkで割った余りの数
dp = create_grid(N+1, 13)

dp[0][0] = 1 # 0桁目

for i in range(N):
    c = S[N-i-1]
    if c == "?":
        v = range(10)
    else:
        v = [int(c)]
    for vi in v:
        for j in range(13):
            amari = (vi*(10**i) % MOD + j) % 13
            dp[i+1][amari] = (dp[i][j] + dp[i+1][amari]) % MOD
            
print(dp[N][5])

Submission status: Wrong Answer

Solution code:
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

import re
# import numpy as np
# from scipy.misc import comb

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e18)
MOD = int(1e9)+7 # 10^9 + 7

# field[H][W]
def create_grid(H, W, value = 0):
    return [[ value for _ in range(W)] for _ in range(H)]

########

S = input()
N = len(S)

# dp[i][k]: i桁目までのkで割った余りの数
dp = create_grid(N+1, 13)

dp[0][0] = 1 # 0桁目

mul = 1
for i in range(N):
    c = S[N-i-1]
    if c == "?":
        v = range(10)
    else:
        v = [int(c)]
    for vi in v:
        for j in range(13):
            amari = (vi*mul % MOD + j) % 13
            dp[i+1][amari] += dp[i][j]
    
    for j in range(13):
        dp[i+1][j] %= MOD

    mul *= 10

print(dp[N][5])

Submission status: Wrong Answer

Solution code:
def main():
    mod=13
    str=input()

    Ans=[0]*mod

    first=True

    total = int(str.replace('?','0'))
    M=total % mod

    mb=[(10**i)%mod for i in range(6)]

    l=len(str)
    for i in range(l):
        if str[l-1-i]=="?":
            if first:
                first=False
                for j in range(10):
                    Ans[(mb[i%6]*j)%mod]+=1
            else:
                Next=[0]*mod
                for j in range(mod):
                    for k in range(10):
                        next_mod=(mb[i%6]*k)%mod
                        Next[j]+=Ans[(j-next_mod)%mod]
                Ans=list(map(lambda x:x%1000000007 , Next))

    print(Ans[(5-M)%13])

main()

Submission status: Wrong Answer

Solution code:
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

import re
# import numpy as np
# from scipy.misc import comb

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e18)
MOD = int(1e9)+7 # 10^9 + 7

# field[H][W]
def create_grid(H, W, value = 0):
    return [[ value for _ in range(W)] for _ in range(H)]

########

S = input()
N = len(S)

# dp[i][k]: i桁目までのkで割った余りの数
dp = create_grid(N+1, 13)

dp[0][0] = 1 # 0桁目

for i in range(N):
    c = S[N-i-1]
    if c == "?":
        v = range(10)
    else:
        v = [int(c)]
    for vi in v:
        for j in range(13):
            amari = (vi*(10**i) % MOD + j) % 13
            dp[i+1][amari] += dp[i][j]
    
    for j in range(13):
        dp[i+1][j] %= MOD

print(dp[N][5])

Submission status: Wrong Answer

Solution code:
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

import re
# import numpy as np
# from scipy.misc import comb

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e18)
MOD = int(1e9)+7 # 10^9 + 7

# field[H][W]
def create_grid(H, W, value = 0):
    return [[ value for _ in range(W)] for _ in range(H)]

########

S = input()[::-1]
N = len(S)

# dp[i][k]: i桁目までのkで割った余りの数
dp = create_grid(N+1, 13)

dp[0][0] = 1 # 0桁目

for i in range(N):
    c = S[i]
    if c == "?":
        v = range(10)
    else:
        v = [int(c)]
    for vi in v:
        for j in range(13):
            amari = (vi*(10**i) % MOD + j) % 13
            dp[i+1][amari] += dp[i][j] % MOD

print(dp[N][5])

Submission status: Wrong Answer

Solution code:
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

import re
# import numpy as np
# from scipy.misc import comb

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e18)
MOD = int(1e9)+7 # 10^9 + 7

# field[H][W]
def create_grid(H, W, value = 0):
    return [[ value for _ in range(W)] for _ in range(H)]

########

S = input()[::-1]
N = len(S)

# dp[i][k]: i桁目までのkで割った余りの数
dp = create_grid(N+1, 13)

dp[0][0] = 1 # 0桁目

for i in range(N):
    c = S[i]
    if c == "?":
        v = range(10)
    else:
        v = [int(c)]
    for vi in v:
        for j in range(13):
            amari = (vi*(10**i) + j) % 13 % MOD
            dp[i+1][amari] += dp[i][j] % MOD

print(dp[N][5])

Submission status: Wrong Answer

Solution code:
S = input()
S = list(S)
MOD = 1000000007
l = [[0 for j in range(10)] for i in range(6)]
for i in range(6):
    for j in range(10):
        l[i][j] = j * 10**i % 13

print(l)

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

for i in range(len(S)-1, -1, -1):
    ir = len(S)-1 - i
    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):
            dp[ir+1][(k + l[ir%6][j]) % 13] += dp[ir][k]
    for k in range(13):
        dp[ir+1][k] %= MOD

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()
dp = [[0 for i in range(13)] for i in range(len(s))]
if s[-1] != "?":
    dp[0][int(s[-1]) % 13] += 1
else:
    for k in range(10):
        dp[0][k % 13] += 1
d = [1]
for i in range(1,len(s)):
    d.append(d[i-1]*10 % (10**9 + 7))
    
for i in range(1,len(s)):
    for r in range(13):
        if s[-(i+1)] == "?":
            for k in range(10): 
                dp[i][(k * d[i] + r) % 13] += dp[i-1][r]
                
        else:
            dp[i][(int(s[-(i+1)]) * d[i] + r) % 13] += dp[i-1][r]
    for r in range(13):
        dp[i][r]  %= 10**9 + 7
print(dp[len(s)-1][5]%(10**9+7))