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:
K = 1000000007
S = input()
l = len(S)
li = [1] + [0] * 12
work_lists = [[0] * 13] * 6
for i in range(6):
    for x in range(10):
        work_lists[i][x * (10 ** (i % 6)) % 13] = 1
for i in range(l):
    s = S[l - i - 1]
    if s == "?":
        work_li = work_lists[i % 6]
        next_li = [sum([work_li[j] * li[(k - j) % 13] % K for j in range(13)]) for k in range(13)]
    else:
        n = int(s)
        r = (n * (10 ** i)) % 13
        next_li = [li[(j - r) % 13] for j in range(13)]
    li = next_li
print(li[5])

Submission status: Wrong Answer

Solution code:
s = str(input())
dp = [[0] * 13 for i in range(len(s)+1)]
dp[0][0] = 1
Naoppy = 1
mod = 13
ans = 0
for i in range(len(s)):
    if s[i] == "?":
        for j in range(10):
            for k in range(13):
                dp[i+1][(k * 10 +j)%mod] += dp[i][k]
    else:
        for k in range(13):
            dp[i+1][(k * 10 + (int(s[i])))%mod] += dp[i][k]
    for j in range(13):
        dp[i+1][j] %= mod
print(dp[len(s)][5])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

#DP[i][j]=下からi桁目までであまりがj(1<=i<=N,0<=j<=12)の総数
DP=[[0]*13 for index1 in range(N+1)]

#初期
if S[N-1]=='?':
    for index in range(10):
        DP[1][index]=1
else:
    DP[1][int(S[N-1])]=1

#前処理
rest=[[index2 for index2 in range(10)] for index3 in range(13)]
#配る
for index4 in range(1,13):
    for index5 in range(10):
        rest[index4][index5]=(rest[index4-1][index5]*10)%13

for i in range(1,N):#1<=i<=N-1(配る)
    if S[N-(i+1)]=='?':
        for j in range(13):
            for k in range(10):
                DP[i+1][(j+rest[i%13][k])%13]+=DP[i][j]
                DP[i+1][(j+rest[i%13][k])%13]%=P
    else:
        for l in range(13): #lはjと等価
            DP[i+1][(l+rest[i%13][int(S[N-(i+1)])])%13]+=DP[i][l]
            DP[i+1][(l+rest[i%13][int(S[N-(i+1)])])%13]%=P

print(DP[N][5])

Submission status: Wrong Answer

Solution code:
s=list(input())
s.reverse()

dp = [[0 for _ in range(13)] for _ in range(len(s)+1)]
dp[0][0]=1
for i in range(len(s)):
    nd=s[i]
    for mod in range(13):
        dp[i][mod] %=10**9+7
        for d in range(10):
            if nd != "?" and str(d)!=nd:
                continue
            nmod = (mod*10 + d) % 13
            dp[i+1][nmod] += dp[i][mod]

print(dp[-1][5])

Submission status: Wrong Answer

Solution code:
import numpy as np
s = str(input())

mod = 10**9+7

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

m = 1
for c in s[::-1]:
  if c == '?':
    nextdps = []
    for i in range(10):
      idx = m - i*m%13
      nextdps.append(dp[idx:].tolist() + dp[:idx].tolist())
    dp = np.sum(nextdps, axis=0)
  else:
    i = int(c)
    idx = m - i*m%13
    dp = dp[idx:].tolist() + dp[:idx].tolist()
    dp = np.array(dp)
  dp %= mod
  m *= 10
  m %= 13
print(int(dp[5]))

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)
MOD = 10**9 + 7
dp = [[0]*13 for _ in range(n+1)]
# dp[i][j]は先頭からi文字目を見た時の13でわったあまりがjのものの数

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

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)
MOD = 10**9 + 7
dp = [[0]*13 for _ in range(n+1)]
# dp[i][j]は先頭からi文字目を見た時の13でわったあまりがjのものの数

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

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)
MOD = 10**9 + 7
dp = [[0]*13 for _ in range(n+1)]
# dp[i][j]は先頭からi文字目を見た時の13でわったあまりがjのものの数

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

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)
MOD = 10**9 + 7
dp = [[0]*13 for _ in range(n+1)]
# dp[i][j]は先頭からi文字目を見た時の13でわったあまりがjのものの数

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

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)
MOD = 10**9 + 7
dp = [[0]*13 for _ in range(n+1)]
# dp[i][j]は先頭からi文字目を見た時の13でわったあまりがjのものの数

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

            mod = mod % 13
            for j in range(13):
                dp[i+1][j] = dp[i+1][j] + dp[i][(j+mod) % 13] % MOD
print(dp[n][5])

Submission status: Wrong Answer

Solution code:
S=list(input())
MOD=10**9+7
dp=[0]*13
dp[0]=1
for i in range(1,len(S)+1):
    ans=[0]*13
    if S[-i]=="?":
        for j in range(10):
            a=(j*10**(i-1))%13
            for k in range(13):
                ans[(k+a)%13]=ans[(k+a)%13]+dp[k]
    else:
        a=int(S[-i])
        a=(a*10**(i-1))%13
        for k in range(13):
            ans[(k+a)%13]=ans[(k+a)%13]+dp[k]
    dp=ans.copy()
    print(ans)
print(ans[5]%MOD)

Submission status: Wrong Answer

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

MOD = 10 ** 9 + 7

# dp[i][j] i桁までで、あまりjの個数
dp = [[0] * 13 for _ in range(n + 1)]
dp[0][0] = 1

for i, s in enumerate(S):
  if s == "?":
    c = -1
  else:
    c = int(s)
  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 k in range(13):
    dp[i][k] %= MOD
print(dp[n][5])

Submission status: Wrong Answer

Solution code:

def main():
  s=input()
  l=len(s)
  mod = 10**9+7
  dp=[[0]*13 for _ in range(l+1)]
  print(dp)

  dp[0][0]=1 #初期値設定
  for i in range(l):
    if s[i]!="?":
      for k in range(13):
        dp[i+1][(k*10+int(s[i]))%13]+=dp[i][k]
    else:
      for j in range(10):
        for k in range(13):
          dp[i+1][(k*10+j)%13]+=dp[i][k]

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

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
S=input()
n=len(S)
t=[]
for i in range(13):
  t.append(0)
s=t.copy()
t[0]=1
for i in range(n):
  if S[i]=='?':
    tcopy=s.copy()
    for j in range(10):
      for k in range(13):
        tcopy[(j*pow(10,i,13)+k)%13]=(tcopy[(j*pow(10,i,13)+k)%13]+t[k])%(10**9+7)
    t=tcopy.copy()
  else:
    j=int(S[i])
    tcopy=s.copy()
    for k in range(13):
      tcopy[(j*pow(10,i,13)+k)%13]=(tcopy[(j*pow(10,i,13)+k)%13]+t[k])%(10**9+7)
    t=tcopy.copy()
print(t[4])

Submission status: Wrong Answer

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

dp = [0] * 13
for c in s:
  tmp = dp[:]
  if c == '?':
    dp = [0] * 13
    for n in range(10):
      for i in range(13):
        dp[(10 * i + n) % 13] += tmp[i]
  else:
    n = int(c)
    for i in range(13):
      dp[(10 * i + n) % 13] = tmp[i]
print(dp[5])

Submission status: Wrong Answer

Solution code:
mod=10**9+7
S=input()
dp=[0]*13
dp[0]=1

for s in S:
    prev=[x for x in dp]
    if s=='?':
        nx=range(10)
    else:
        nx=[int(s)]
    for i in range(13):
        for j in nx:
            dp[(10*i+j)%13]+=prev[i]
    dp=[x%mod for x in dp]
print(dp[5])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
S=sys.stdin.readline().strip()
N=len(S)
mod=10**9+7
S=S[::-1]

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

for i,x in enumerate(S):  #i桁目
    if i==0:
        if x!="?":
            x=int(x)
            dp[i%2][(x*pow(10,i,13))%13]=1
        else:
            for x in range(10):
                dp[i%2][(x*pow(10,i,13))%13]=1
    else:
        if x!="?":
            x=int(x)
            for j in range(13):
                n=(x*pow(10,i,13)+j)%13
                dp[i%2][n]+=dp[(i-1)%2][j]
                dp[i%2][n]%=mod
        else:
            for j in range(13):
                for x in range(10):
                    n=(x*pow(10,i,13)+j)%13
                    dp[i%2][n]+=dp[(i-1)%2][j]
                    dp[i%2][n]%=mod
print dp[(N-1)%2][5]%mod

Submission status: Wrong Answer

Solution code:
import sys,math,copy
import numpy as np
input = sys.stdin.readline
S = [int(x) if x != '?' else -1 for x in input().strip()]
N = len(S)

dp = np.zeros((13), dtype=int)
dp_ = np.zeros((13), dtype=int)
dp_[0] = 1
mod = 1
for i, s in enumerate(S[::-1], start=1):
    if s == -1:
        for d in range(10):
            m = (d * mod) % 13
            for pm in range(13):
                dp[(pm+m)%13] = (dp[(pm+m)%13] + dp_[pm]) % (10 ** 9 + 7)

    else:
        m = (s * mod) % 13
        for pm in range(13):
            dp[(pm+m)%13] = (dp[(pm+m)%13] + dp_[pm]) % (10 ** 9 + 7)
    dp_ = dp
    dp *= 0
    mod = (mod * 10) % 13
print(dp_[5] % (10 ** 9 + 7))

Submission status: Wrong Answer

Solution code:
s = input()
l = len(s)
MOD = 10**(+7)
dp = [[0]*13 for _ in range(100005)]
dp[0][0] = 1
for i in range(l):

    c = -1 if s[i] == '?' else int(s[i])
    for j in range(10):
        if c != -1 and c != j:
            continue
        for r in range(13):
            dp[i+1][(10*r+j)%13] += dp[i][r]
    for k in range(13):
        dp[i+1][k] %= MOD
print(dp[l][5])

Submission status: Wrong Answer

Solution code:
mod = 10 ** 9 + 7
mod2 = 2**61+1
from collections import deque
import heapq
from bisect import bisect_left, insort_left

def iip(listed):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def iip_ord():
    return [ord(i) - ord("a") for i in input()]


def main():
    S = input()
    S = [int(i) if not i == "?" else False for i in S]

    S.reverse()

    table = []
    cur = 1
    for i in range(6):
        cur %= 13
        table.append(cur)
        cur *= 10

    next = [0 for _ in range(13)]
    next[0] = 1
    for keta, s in enumerate(S):
        cur = next
        next = [0 for _ in range(13)]
        kake = table[keta % 6]

        if s:
            for i in range(13):
                idx = (i + kake * s) % 13
                next[idx] += cur[i] % mod

        else:
            for i in range(13):
                for j in range(10):
                    idx = (i + kake * j) % 13
                    next[idx] += cur[i] % mod
                    next[idx] %= mod

        #print(next)

    #print()
    #print(next)
    print(next[5] % mod)





def solve():
    N, M = iip(True)
    lines = {}
    for i in range(N):
        lines[i] = []

    for i in range(M):
        a, b = iip(True)
        lines[a-1].append(b-1)
        lines[b-1].append(a-1)

    c = [[0]]
    for a in range(1, N):
        n = []
        for i in c:
            for j in range(N):
                if j in i:
                    continue
                ct = [k for k in i]
                ct.append(j)
                n.append(ct)
        c = n

    kh = []
    for i in c:
        for j in range(N):
            if j not in i:
                break
        else:
            kh.append(i)

    ans = 0
    for root in kh:
        for i in range(N):
            if i == N-1:
                ans += 1
                break
            else:
                if not root[i+1] in lines[root[i]]:
                    break

    print(ans)

#####################################################ライブラリ集ここから

def split_print_space(s):
    print(" ".join([str(i) for i in s]))


def split_print_enter(s):
    print("\n".join([str(i) for i in s]))


def koenai_saidai_x_index(sorted_list, n):
    l = 0
    r = len(sorted_list)
    if len(sorted_list) == 0:
        return False
    if sorted_list[0] > n:
        return False

    while r - l > 1:
        x = (l + r) // 2
        if sorted_list[x] == n:
            return x
        elif sorted_list[x] > n:
            r = x
        else:
            l = x
    return l


def searchsorted(sorted_list, n, side):
    if side not in ["right", "left"]:
        raise Exception("sideはrightかleftで指定してください")

    l = 0
    r = len(sorted_list)

    if n > sorted_list[-1]:
        # print(sorted_list)
        return len(sorted_list)
    if n < sorted_list[0]:
        return 0

    while r - l > 1:
        x = (l + r) // 2
        if sorted_list[x] > n:
            r = x
        elif sorted_list[x] < n:
            l = x
        else:
            if side == "left":
                r = x
            elif side == "right":
                l = x

    if side == "left":
        if sorted_list[l] == n:
            return r - 1
        else:
            return r

    if side == "right":
        if sorted_list[l] == n:
            return l + 1
        else:
            return l


def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):
    if n <= 0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n - r + 1, n + 1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r + 1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        # print(f"{n}C{r} = {ret}")
        pass
    return ret


def inv(n, mod):
    return power(n, mod - 2)


def power(n, p, mod_= mod):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p // 2, mod_) ** 2) % mod_
    if p % 2 == 1:
        return (n * power(n, p - 1, mod_)) % mod_


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
s=input()
n=len(s)
mod=10**9+7
dp=np.array([[0 for _ in range(13)] for _ in range(n)])
for i,x in enumerate(s):
    if i==0:
        if x=='?':
            for j in range(10):
                dp[0][j]=1
        else:
            num=ord(x)-ord('0')
            dp[0][num]=1
    else:
        if x=='?':
            for j in range(10):
                for jj in range(13):
                    if dp[i-1][jj]>0:
                        dp[i][(10*jj+j)%13]=(dp[i][(10*jj+j)%13]+dp[i-1][jj])
        else:
            num=ord(x)-ord('0')
            for j in range(13):
                if dp[i-1][j]>0:
                    dp[i][(10*j+num)%13]=(dp[i][(10*j+num)%13]+dp[i-1][j])
print(dp[-1][5]%mod)

Submission status: Wrong Answer

Solution code:
S=input()
n=len(S)
R=[0]*13
cnt=[0]*13
Pow=[[] for i in range(6)]
mod=10**9+7

for i in range(6):
    c=10**i
    for j in range(10):
        Pow[i].append(c*j%13)
ans=0
flag=0
for i in range(n):
    if S[n-i-1]=="?":
        P=Pow[i%6]
        if flag==0:
            for p in P:
                R[p]=1
                flag=1
        else:
            for j in range(10):
                for k in range(13):
                    cnt[(k+P[j])%13]+=R[k]%mod
            R=cnt
            cnt=[0]*13
    else:
        x=int(S[n-i-1])
        ans+=Pow[i%6][x]
ans%=13
print(R[(18-ans)%13]%mod)

Submission status: Wrong Answer

Solution code:
S=input()
import numpy as np
M=13
MOD=10**9+7
dp = np.zeros(13, dtype=np.int64)
dp[0]=1
idx = np.zeros(13, dtype=np.int8)
for i in range(13):
  idx[i * 10 % 13] = i
for s in S:
  if s=='?':
    tmp=dp[idx]
    x=sum(tmp)
    for i in range(13):
      dp[i]=x-sum([tmp[(i+j)%13] for j in range(1,4)])
  else:
    dp=np.roll(dp[idx],int(s))%MOD
print(dp[5]%MOD)

Submission status: Wrong Answer

Solution code:
import copy
s=input()
a=0
n=len(s)
x=[0]*13
if s[-1]=='?':
  x = [i<=9 for i in range(13)]
else:
  x[int(s[-1])%13]=1
p=1
for i in range(1,n):
  p=10*p%13
  y=[0]*13
  if s[n-1-i]=='?':
    for j in range(13):
      for k in range(10):
        y[(k*p+j)%13]+=x[j]
  else:
    t=int(s[n-1-i])
    for j in range(13):
      y[(t*p+j)%13]+=x[j]
  x=copy.deepcopy(y)
  x = [z%(10**9+7) for z in x]
print(x[5])

Submission status: Wrong Answer

Solution code:
import copy
s=input()
a=0
n=len(s)
x=[0]*13
if s[-1]=='?':
  x = [i<=9 for i in range(13)]
else:
  x[int(s[-1])%13]=1
for i in range(1,n):
  y=[0]*13
  if s[n-1-i]=='?':
    for j in range(13):
      for k in range(10):
        y[(k*10**i+j)%13]+=x[j]
  else:
    t=int(s[n-1-i])
    for j in range(13):
      y[(t*10**i+j)%13]+=x[j]
  x=copy.deepcopy(y)
  x = [z%(10**9+7) for z in x]
print(x[5])

Submission status: Wrong Answer

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

# dp[逆順i桁][j mod 13] := 総数
dp = [[0]*13 for _ in range(len(s)+1)]
dp[0][0] = 1
mul = 1
s_rev = s[::-1]
for i in range(len(s)):
    x = s_rev[i]
    if x == '?':
        for k in range(10):
            for j in range(13):
                dp[i+1][(mul*k+j)%13] += dp[i][j]
                dp[i+1][(mul*k+j)%13] %= mod
    else:
        k = int(x)
        for j in range(13):
            dp[i+1][(mul*k+j)%13] += dp[i][j]
            dp[i+1][(mul*k+j)%13] %= mod
    mul = mul * 10 % mod

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

Submission status: Wrong Answer

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

# dp[逆順i桁][j mod 13] := 総数
dp = [[0]*13 for _ in range(len(s)+1)]
dp[0][0] = 1
mul = 1

s_rev = s[::-1]
for i in range(len(s)):
    x = s_rev[i]
    if x == '?':
        for x in range(10):
            for j in range(13):
                dp[i+1][(mul*x+j)%13] += dp[i][j]
                dp[i+1][(mul*x+j)%13] %= mod
    else:
        x = int(x)
        for j in range(13):
            dp[i+1][(mul*x+j)%13] += dp[i][j]
            dp[i+1][(mul*x+j)%13] %= mod
    mul = mul * 10 % mod

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
s = input()
s = s[::-1]
MOD = 10**9+7
mod13_map = [[i for i in range(13)]]
ma = mod13_map.append
for i in range(1,10**5):
    next_digit = list(map(lambda x:x*10%13,mod13_map[i-1]))
    ma(next_digit)

ret = [1] + [0] * 12 #13で割ってi余る数の合計
for i,v in enumerate(s):
    if v!="?":
        #mod13_map[i][v]だけ、右にシフト
        ret *= 2
        sft = mod13_map[i][int(v)]
        ret = ret[sft:sft+13]
    else:
        temp_ret = [0] * 13
        for j in range(10):
            #?がjの場合
            for k,l in enumerate(ret):
                temp_ret[(k+mod13_map[i][j])%13]+=l
        temp_ret = list(map(lambda x:x%MOD,temp_ret))
        ret = temp_ret
print(ret[5]%MOD)

Submission status: Wrong Answer

Solution code:
def main():
    
    s = input()[::-1]
    mod = 10**9+7
    dp = [[0 for j in range(13)] for i in range(len(s)+1)]
    dp[0][0] = 1
    ten = 1


    for i in range(len(s)):
        if s[i] == "?":
            for k in range(10):
                x = k*ten%13
                for j in range(13):
                    dp[i+1][(j+x)%13] = (dp[i][j]+dp[i+1][(j+x)%13])%mod
        
        else:
            x = int(s[i])*ten%13
            for j in range(13):
                dp[i+1][(j+x)%13] = (dp[i][j]+dp[i+1][(j+x)%13])%mod

        ten = (ten*10)%mod

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

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
inp = sys.stdin.buffer.readline
def inpS(): return inp().rstrip().decode()
readlines = sys.stdin.buffer.readlines 
MOD = 10**9+7

S = inpS()
N = len(S)
dp=[[0]*13 for i in range(N+1)]
mul = 1
dp[0][0] = 1 # 余り0は1個
for i in range(N):
  if S[N-i-1] == "?":
    for dgt in range(10):
      for mo in range(13):
        ind = (dgt*mul+mo)%13
        dp[i+1][ind] += dp[i][mo]
        dp[i+1][ind] %= MOD
  else:
    s = int(S[N-i-1])
    for mo in range(13):
      ind = (s*mul+mo)%13
      dp[i+1][ind] += dp[i][mo]
      dp[i+1][ind] %= MOD
  mul *= 10
  mul %= MOD
print(dp[N][5])

Submission status: Wrong Answer

Solution code:
from math import pow
S = input()
S = list(S)
S.reverse()
l = len(S)
dp =[ [0] * 13 for _ in range(l + 1)]
dp[0][0] = 1
MOD = 10 ** 9 + 7
keta = 1
for k,c in enumerate(S):
    if c == "?":
        for i in range(0,10): # ? に入る候補達
            for amari in range(0, 13):
                next_amari = (amari + i * keta ) % MOD  % 13
                dp[k + 1][next_amari] += (dp[k][amari] )
                dp[k + 1][next_amari] %= MOD
    else:
        i = int(c)
        for amari in range(0,13):
            next_amari = (amari + i * keta )% MOD  % 13
            dp[k + 1][ next_amari] += (dp[k][amari] )
            dp[k + 1][next_amari] %= MOD

    keta *= 10
    # keta %= MOD なんで？


print(dp[l][5])

Submission status: Wrong Answer

Solution code:
#from collections import *
#from itertools import *
#from bisect import *
#from heapq import *
#import copy
#import math
#N=int(input())
#X,Y=map(int,input().split())
#S=list(map(int,input().split()))
#S=[list(map(int,input().split())) for i in range(N)]
S=input()
mod=10**9+7
Scount=S.count("?")
X=pow(10,Scount)
count=(X-5)//13
amari=(X-5)%13
print((count-1)%mod)

Submission status: Wrong Answer

Solution code:
#from collections import *
#from itertools import *
#from bisect import *
#from heapq import *
#import copy
#import math
#N=int(input())
#X,Y=map(int,input().split())
#S=list(map(int,input().split()))
#S=[list(map(int,input().split())) for i in range(N)]
S=input()
mod=10**9+7
Scount=S.count("?")
X=pow(10,Scount)
count=(X-5)//13
amari=(X-5)%13
print(count%mod)

Submission status: Wrong Answer

Solution code:
s=input()[::-1]
mod=10**9+7
n=13
dp=[0]*n
mul=1
dp[0]=1
for c in s:
  ndp=[0]*n
  if c=='?':
    for k in range(10):
      for j in range(n):
        ndp[(k*mul+j)%n]+=dp[j]%mod
        #ndp[(k*mul+j)%n]%=mod
  else:
    k=int(c)
    for j in range(n):
      ndp[(k*mul+j)%n]+=dp[j]%mod
      #ndp[(k*mul+j)%n]%=mod
  mul*=10
  mul%=n
  dp=ndp
print(dp[5])

Submission status: Wrong Answer

Solution code:
s=input()[::-1]
mod=10**9+7
n=13
dp=[0]*n
mul=1
dp[0]=1
for c in s:
  ndp=[0]*n
  if c=='?':
    for k in range(10):
      for j in range(n):
        ndp[(k*mul+j)%n]+=dp[j]
        ndp[(k*mul+j)%n]%=mod
  else:
    k=int(c)
    for j in range(n):
      ndp[(k*mul+j)%n]+=dp[j]
      ndp[(k*mul+j)%n]%=mod
  mul*=10
  mul%=mod
  dp=ndp
print(dp[5])

Submission status: Wrong Answer

Solution code:
import math
import copy
from copy import deepcopy
import sys
import fractions
import numpy as np
from functools import reduce
import statistics
import heapq

# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

def getInputStr():
    inputStr = str(input())
    return inputStr

data = getInputStr()

a = str(data)
listStr = []
listStr = list(a)

del listStr[len(listStr)-1]
listStr.reverse()

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

INF = 10 ** 9 + 7

for i in range(len(listStr)):
    keta = pow(10, i) % 13
    if i == 0:
        keta = 0

    if listStr[i] == "?":
        for k in range(10):
            for j in range(13):
                dp[i+1][int((k*keta + j) % 13)] += dp[i][j]
                # dp[i+1][int(((k*keta)%13 + j) % 13)] += dp[i][j]
    else:
        k = int(listStr[i])
        for j in range(13):
            dp[i + 1][int((k * keta + j) % 13)] += dp[i][j]


ans = dp[len(listStr)][5] % INF
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import copy
from copy import deepcopy
import sys
import fractions
import numpy as np
from functools import reduce
import statistics
import heapq

# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

def getInputStr():
    inputStr = str(input())
    return inputStr

data = getInputStr()

a = str(data)
listStr = []
listStr = list(a)

del listStr[len(listStr)-1]
listStr.reverse()

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

INF = 10 ** 9 + 7

for i in range(len(listStr)):
    keta = pow(10, i) % 13

    if listStr[i] == "?":
        for k in range(10):
            for j in range(13):
                dp[i+1][int((k%13 + keta + j) % 13)] += dp[i][j]
    else:
        k = int(listStr[i])
        for j in range(13):
            dp[i + 1][int((k%13 + keta + j) % 13)] += dp[i][j]


ans = dp[len(listStr)][5] % INF
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import copy
from copy import deepcopy
import sys
import fractions
import numpy as np
from functools import reduce
import statistics
import heapq

# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

def getInputStr():
    inputStr = str(input())
    return inputStr

data = getInputStr()

a = str(data)
listStr = []
listStr = list(a)

del listStr[len(listStr)-1]
listStr.reverse()

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

INF = 10 ** 9 + 7

for i in range(len(listStr)):
    if i ==0:
        keta = 1
    else:
        keta = pow(10, i)

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


ans = dp[len(listStr)][5] % INF
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import copy
from copy import deepcopy
import sys
import fractions
import numpy as np
from functools import reduce
import statistics
import heapq

input = sys.stdin.readline
sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

def getInputStr():
    inputStr = str(input())
    return inputStr

data = getInputStr()

a = str(data)
listStr = []
listStr = list(a)

del listStr[len(listStr)-1]
listStr.reverse()

dp = [[0]*13 for _ in range(len(listStr)+1)]
dp[0][0] = 1
ordinal = 1

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

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