Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

N = input()
a = map(int, raw_input().split())

all = sum(a)

mini = 10000000000

for i in range(1,N):
    x = sum(a[:i])
    y = all - x 
    ret = abs(x-y)

    if(ret < mini): mini=ret

print mini


### FIXED CODE ###

N = input()
a = map(int, raw_input().split())

all = sum(a)

mini = 10000000000

x = 0
y = all

for i in range(0,N-1):
    x += a[i]
    y -= a[i]
    ret = abs(x-y)

    if(ret < mini): mini=ret

print mini
### BUGGY CODE ###

n,m=map(int,input().split())
l=[]
for i in range(1,m//n+1):
  if m%i==0:
    l.append(i)
print(max(l))

### FIXED CODE ###

def make_divisors(n,m):
    divisors = []
    for i in range(1,min(int(m**(1/2))+1,int(m//n)+1)):
      if m % i == 0:
          divisors.append(i)
          if i != m // i and m//i<=m//n:
              divisors.append(m//i)
    return divisors
n,m=map(int,input().split())
print(max(make_divisors(n,m)))
### BUGGY CODE ###

import numpy as np

def calculate(h, w, arr):
    L = np.zeros([h, w])
    U = np.zeros([h, w])
    D = np.zeros([h, w])
    R = np.zeros([h, w])

    for ih in range(h):
        for iw in range(w):
            if ih == 0:
                U[ih][iw] = 1
            if iw == 0:
                L[ih][iw] = 1

            if arr[ih][iw] == "#":
                L[ih][iw] = 0
                U[ih][iw] = 0

            else:
                if iw > 0:
                    L[ih][iw] = L[ih][iw - 1] + 1
                if ih > 0:
                    U[ih][iw] = U[ih - 1][iw] + 1

            rih = h - 1 - ih
            riw = w - 1 - iw

            if rih == h - 1:
                D[rih][riw] = 1
            if riw == w - 1:
                R[rih][riw] = 1

            if arr[rih][riw] == "#":
                D[rih][riw] = 0
                R[rih][riw] = 0
            else:
                if riw < w - 1:
                    R[rih][riw] = R[rih][riw + 1] + 1
                if rih < h - 1:
                    D[rih][riw] = D[rih + 1][riw] + 1

    max = 0
    for ih in range(h):
        for iw in range(w):
            value = L[ih][iw] + R[ih][iw] + U[ih][iw] + D[ih][iw] - 3
            if value > max:
                max = value
    print(int(max))


S = input().split(" ")
H = int(S[0])
W = int(S[1])

arr = []
for i in range(H):
    q = list(input())
    arr.append(q)

calculate(H, W, arr)


### FIXED CODE ###

def calculate(h, w, arr):
    L = [[0]*w for i in range(h)]
    U = [[0]*w for i in range(h)]
    D = [[0]*w for i in range(h)]
    R = [[0]*w for i in range(h)]

    for ih in range(h):
        for iw in range(w):
            if ih == 0:
                U[ih][iw] = 1
            if iw == 0:
                L[ih][iw] = 1

            if arr[ih][iw] == 1:
                L[ih][iw] = 0
                U[ih][iw] = 0

            else:
                if iw > 0:
                    L[ih][iw] = L[ih][iw - 1] + 1
                if ih > 0:
                    U[ih][iw] = U[ih - 1][iw] + 1

            rih = h - 1 - ih
            riw = w - 1 - iw

            if rih == h - 1:
                D[rih][riw] = 1
            if riw == w - 1:
                R[rih][riw] = 1

            if arr[rih][riw] == 1:
                D[rih][riw] = 0
                R[rih][riw] = 0
            else:
                if riw < w - 1:
                    R[rih][riw] = R[rih][riw + 1] + 1
                if rih < h - 1:
                    D[rih][riw] = D[rih + 1][riw] + 1

    max = 0
    for ih in range(h):
        for iw in range(w):
            value = L[ih][iw] + R[ih][iw] + U[ih][iw] + D[ih][iw] - 3
            if value > max:
                max = value
    print(int(max))


S = input().split(" ")
H = int(S[0])
W = int(S[1])

arr = []
for i in range(H):
    q = input()
    tmp = []
    for qs in q:
        if qs == "#":
            tmp.append(1)
        if qs == ".":
            tmp.append(0)
    arr.append(tmp)

calculate(H, W, arr)
### BUGGY CODE ###

for n in range(1, int(input())+1):
 b=0
 for i in range(1, n+2):
  for j in range(1, n+2):
   for k in range(1, n+2):
    if n == (i**2 + j**2 + k**2 + i*j + j*k + i*k):
     b+=1
 print(b)

### FIXED CODE ###

n = int(input())
a = [0]*(n+1)
for i in range(1, 102):
    for j in range(1, 102):
        for k in range(1, 102):
            if (i*i + j*j + k*k + i*j + j*k + i*k) <= n:
                a[i*i + j*j + k*k + i*j + j*k + i*k] +=1
for x in a[1:]:
    print(x)
### BUGGY CODE ###

N = int(input())
S = input()
a,b = '',''
r = S.count('R')
g = S.count('G')
b = len(S)-r-g
rgb = r*g*b
expt = 0
for i in range(N):
  a = S[i]
  for j in range(i,N):
    if S[j] != a:
      b = S[j]
      k = 2*j-i
      if 0<=k<=N-1:
        if S[k]!=b and S[k]!=a:
          expt += 1
print(rgb-expt)

### FIXED CODE ###

N = int(input())
S = input()
a,b = '',''
r = S.count('R')
g = S.count('G')
b = len(S)-r-g
rgb = r*g*b
expt = 0
for i in range(N):
  a = S[i]
  for j in range(i,(N+i-1)//2+1):
    if S[j] != a:
      b = S[j]
      k = 2*j-i
      if S[k]!=b and S[k]!=a:
        expt += 1
print(rgb-expt)
### BUGGY CODE ###

k=int(input())
import itertools
import math
from functools import reduce
def gcd(*numbers):
  return reduce(math.gcd, numbers)
ans=0
for i in range(1, k+1):
  for h in range (1, k+1):
    for j in range (1, k+1):
      ans+=gcd(*[i, h, j])
print(ans)

### FIXED CODE ###

k=int(input())
l=list(range(1, k+1))
import itertools
import math
from functools import reduce
def gcd(*numbers):
  return reduce(math.gcd, numbers)
ans=0
for v in itertools.combinations_with_replacement(l, 3):
  if v[0]==v[1]==v[2]:
    ans+=gcd(*v)
  elif v[0]==v[1]:
    ans+=gcd(*v)*3
  elif v[1]==v[2]:
    ans+=gcd(*v)*3
  elif v[0]==v[2]:
    ans+=gcd(*v)*3
  else:
    ans+=gcd(*v)*6
print(ans)
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
limit=10**18

ans = 1
for i in range(n):
  ans *= a[i]

if ans > limit:
  print(-1)
else:
  print(ans)


### FIXED CODE ###

# from operator import mul
# from functools import reduce

n=int(input())
a=list(map(int, input().split()))
# limit=10**18

# if 0 in a:
#     print(0)
#     exit()

ans = 1
# ans = reduce(mul, a) #=> 1320

for i in range(n):
  ans *= a[i]
  if ans > 10 ** 18:
  # if a[i] == 0:
  #   break
  # elif (ans*a[i]) > limit:
    ans = -1
    break

for i in range(n):
  if a[i] == 0:
      ans = 0

# if ans > limit:
#   print(-1)
# else:
print(ans)
### BUGGY CODE ###

N, M, Q = map(int, input().split())
slst = []
elst = []
for i in range(M):
    a, b = map(int, input().split())
    slst.append(a)
    elst.append(b)

question = []
for k in range(Q):
    cnt = 0
    c, d = map(int, input().split())
    cnt = 0    
    for i, j in zip(slst, elst):
        if i >= c and j<= d:
            cnt += 1
    print(cnt)

### FIXED CODE ###

N, M, Q = map(int, input().split())
lst = []
cnt = [0]*N
ans = [0]*Q
for i in range(M):
    a, b = map(int, input().split())
    lst.append([b, a, 't'])
for i in range(Q):
    a, b = map(int, input().split())
    lst.append([b, a+500, i])
lst.sort()
for i in lst:
    if i[2] == 't':
        cnt[i[1]-1] += 1
    else:
        ans[i[2]] = sum(cnt[i[1]-501:i[0]])
for j in ans:
    print(j)
### BUGGY CODE ###

N = int(input())
Ai = list(map(int,input().split()))
    
def create_list():
  MAXI = N
  
  sn = [0 for _ in range(MAXI+1)]
  judge = 0
  for i in range(1,MAXI+1):
    sn[i] = sn[i-1] + Ai[i-1]
     
  return sn

def iCj(i, j):
  mot = 1
  chi = 1
  for x in range(j):
    chi *= i-x
    mot *= x+1
  comb = int(chi/mot)
  return comb


base = create_list()
count = 0
base.sort()
i = 0
while(i<N+1):
  this = base.count(base[i])
  if(this >= 2):
    count += iCj(this,2)
  i += this
print(count)

### FIXED CODE ###

N = int(input())
Ai = list(map(int,input().split()))
    
#print(Ai)
def create_list():
  MAXI = N
  
  sn = [0 for _ in range(MAXI+1)]
  judge = 0
  for i in range(1,MAXI+1):
    #print(str(i)+'+1 when '+S[i-1])
    sn[i] = sn[i-1] + Ai[i-1]
     
  return sn

def iCj(i, j):
  mot = 1
  chi = 1
  for x in range(j):
    chi *= i-x
    mot *= x+1
  comb = int(chi/mot)
  return comb


base = create_list()
#print(base)
count = 0
base.sort()
#print(base)
#for i in range(N):
#  for j in range(i+1,N+1):
#    if(base[j]-base[i] == 0):
#      count += 1
    #  print(str(j)+' - '+str(i))
    #else:
    #  print(str(j)+' = '+str(i))
#  print( base[r[i]] - base[l[i]] )#sum(rnum)-sum(lnum) )
i = 0
while(i<N+1):
  this = 1
  j = i+1
  while(j < N+1 and base[j] == base[i]):
    this += 1
    j += 1
  if(this >= 2):
    count += iCj(this,2)
  i += this
print(count)
### BUGGY CODE ###

n = int(input())
A = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for s in range(n):
  for g in range(n):
    b = 0
    for via in range(n):
      if A[s][g] > A[s][via] + A[via][g]:
        print(-1)
        exit()
      if A[s][g] == A[s][via] + A[via][g]:
        b += 1
    if b == 2:
      ans += A[s][g]
print(ans//2)

### FIXED CODE ###

n = int(input())
A = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for s in range(n):
  for g in range(n):
    b = 0
    for via in range(n):
      if A[s][g] > A[s][via] + A[via][g]:
        print(-1)
        exit()
      if A[s][g] == A[s][via] + A[via][g]:
        b += 1
    if b == 2:
      ans += A[s][g]
print(ans//2)
### BUGGY CODE ###

A, B, K = map(int, input().split())
for i in range(K):
    if A != 0:
        A -= 1
    elif B != 0:
        B -= 1
    else:
        break
print('{} {}'.format(A, B))

### FIXED CODE ###

A, B, K = map(int, input().split())

if A <= K:
    print('{} {}'.format(0, max(B - (K - A), 0)))
else:
    print('{} {}'.format(A - K, B))
### BUGGY CODE ###

N, K = input().split(" ")
N, K = int(N), int(K)
p_list = [int(i) for i in input().split(" ")]

for i in range(0, N):
  if i+K > N:
    break

  if i == 0:
    max_sum = sum(p_list[0:K])+K
  else:
    if p_list[i-1] < p_list[i-1+K]:
      tmp = sum(p_list[i:i+K])+K
      if max_sum < tmp:
        max_sum = tmp

print(max_sum/2)

### FIXED CODE ###

N, K = input().split(" ")
N, K = int(N), int(K)
p_list = [int(i) for i in input().split(" ")]

for i in range(0, N):
  if i+K > N:
    break

  if i == 0:
    max_sum = sum(p_list[0:K])
    now_sum = max_sum
  else:
    now_sum += (p_list[i-1+K] - p_list[i-1])
    if max_sum < now_sum:
      max_sum = now_sum

print((max_sum + K)/2)
### BUGGY CODE ###

def gcd(a,b):
    while b:
        a,b=b,a%b
    return a

def lcm(a,b):
    return a*b//gcd(a,b)

INF=10**9+7

N=int(input())
A=[int(i) for i in input().split()]

temp=A[0]
for i in range(1,N):
    temp=lcm(temp,A[i])

ans=0
for a in A:
    ans+=(temp//a)%INF

print(ans%INF)


### FIXED CODE ###

def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

def lcm(a,b):
  return a*b//gcd(a,b)

INF=10**9+7

N=int(input())
A=[int(i) for i in input().split()]

temp=A[0]
for i in range(1,N):
    temp=lcm(temp,A[i])

ans=0
for a in A:
    ans+=(temp//a)

print(ans%INF)
### BUGGY CODE ###

# C - pushpush
def main():
    n = int(input())
    a = list(map(int, input().split()))
    ans = []

    for i in range(n):
        if n % 2 == 0:
            if i % 2 == 0:
                ans.append(str(a[i]))
            else:
                ans.insert(0, str(a[i]))
        else:
            if i % 2 == 0:
                ans.insert(0, str(a[i]))
            else:
                ans.append(str(a[i]))

    else:
        print(' '.join(ans))




if __name__ ==  "__main__":
    main()

### FIXED CODE ###

# C - pushpush
def main():
    from collections import deque
    n = int(input())
    a = list(map(int, input().split()))
    ans = deque(maxlen=2*10**5)

    for i in range(n):
        if n % 2 == 0:
            if i % 2 == 0:
                ans.append(str(a[i]))
            else:
                ans.appendleft(str(a[i]))
        else:
            if i % 2 == 0:
                ans.appendleft(str(a[i]))
            else:
                ans.append(str(a[i]))

    else:
        print(' '.join(ans))


if __name__ ==  "__main__":
    main()
### BUGGY CODE ###

import bisect

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
if M > N:
    B = A[:]
    C = []
else:
    B = A[N-M:]
    C = A[:N-M]

for i in range(M):
    x = B.pop()
    bisect.insort(B, x/2)
    if i + 1 > M - N:
        C.append(B.pop(0))
print(sum(map(int, B + C)))

### FIXED CODE ###

import bisect

N, M = list(map(int, input().split()))
A = list(map(lambda x: int(x) * -1, input().split()))
A.sort()

cnt = 1
while cnt <= M:
    x = bisect.bisect(A, A[0]/2)
    for i in range(x):
        A[i] /= 2
        cnt += 1
        if cnt > M:
            break
    if x != 0 or x != len(A):
        A.sort()
print(sum(map(lambda x: int(-x), A)))
### BUGGY CODE ###

N, X = map(int,input().split())
S = list(map(int,input().split()))
S.sort()
S.reverse()
S.insert(0,0) # 1-indexed
MOD = 10**9+7
dp = [[0]*(10**5+1) for i in range(N+1)]
dp[0][X] = 1
for i in range(N):
    for x in range(10**5+1):
        dp[i+1][x%S[i+1]] += dp[i][x]
        dp[i+1][x] += dp[i][x]*(N-(i+1))
ans = 0
for x in range(10**5+1):
    ans += (x*dp[N][x])%MOD
print(ans%MOD)

### FIXED CODE ###

N, X = map(int,input().split())
S = list(map(int,input().split()))
S.sort(reverse=True)
S = [0] + S # 1-indexed 
MOD = 10**9+7
dp = [[0]*(10**5+1) for i in range(N+1)]
dp[0][X] = 1
for i in range(N):
    for x in range(10**5+1):
        dp[i+1][x%S[i+1]] += dp[i][x]
        dp[i+1][x] += dp[i][x]*(N-(i+1))
        dp[i+1][x%S[i+1]] %= MOD
        dp[i+1][x] %= MOD
ans = 0
for x in range(10**5+1):
    ans += (x*dp[N][x])%MOD
print(ans%MOD)
### BUGGY CODE ###

#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
def resolve():
    N,=pin()
    A=lispin()
    sumA=[sum(A[:i+1])for i in range(N)]
    #print(sumA)
    ans=2**32-1
    t=sumA[-1]
    for i in range(N):
        ans=min(ans,abs(t-sumA[i]*2))
        
    print(ans)
#%%submit!
resolve()

### FIXED CODE ###

#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
def resolve():
    N,=pin()
    A=lispin()
    temp=0
    sumA=[0]*N
    sumA[0]=A[0]
    for j in range(1,N):
        sumA[j]=sumA[j-1]+A[j]
    #print(sumA)
    ans=2**32-1
    t=sumA[-1]
    for i in range(N):
        ans=min(ans,abs(t-sumA[i]*2))
        
    print(ans)
#%%submit!
resolve()
### BUGGY CODE ###

n,k,l=map(int,input().split())
road=[list(map(int,input().split())) for i in range(k)]
train=[list(map(int,input().split())) for i in range(l)]

city1=[[i for i in range(n)]]
city2=[[i for i in range(n)]]
rank1=[0 for i in range(n)]
rank2=[0 for i in range(n)]
s1=[{i} for i in range(n)]
s2=[{i} for i in range(n)]
city1.append(rank1)
city1.append(s1)
city2.append(rank2)
city2.append(s2)
def find(c,x,y):
  return root(c,x)==root(c,y)
def root(c,x):
  if x==c[0][x]:
    return x
  else:
    return root(c,c[0][x])
def union(c,x,y):
  if find(c,x,y):
    return
  else:
    rx=root(c,x)
    ry=root(c,y)
    if c[1][x]>c[1][y]:
      c[0][y]=rx
      c[2][rx]=c[2][rx]|c[2][ry]
    elif c[1][y]>c[1][x]:
      c[0][x]=ry
      c[2][ry]=c[2][rx]|c[2][ry]
    else:
      c[0][x]=ry
      c[1][x]+=1
      c[2][ry]=c[2][rx]|c[2][ry]

for i in range(k):
  union(city1,road[i][0]-1,road[i][1]-1)
for i in range(l):
  union(city2,train[i][0]-1,train[i][1]-1)
ans=[0 for i in range(n)]
for i in range(n):
  ans[i]=len(city1[2][root(city1,i)] & city2[2][root(city2,i)])
  if i==n:
    print(ans[i])
  else:
    print(ans[i],end=' ')

### FIXED CODE ###

from collections import Counter
n,k,l=map(int,input().split())
city1=[i for i in range(n)]
city2=[i for i in range(n)]
def root(c,x):
  if x==c[x]:
    return x
  else:
    return root(c,c[x])
def union(c,x,y):
  rx=root(c,x)
  ry=root(c,y)
  if rx>ry:
    c[rx]=ry
  else:
    c[ry]=rx
for i in range(k):
  a,b=map(int,input().split())
  union(city1,a-1,b-1)
for i in range(l):
  a,b=map(int,input().split())
  union(city2,a-1,b-1)
r=[]
for i in range(n):
  r.append((root(city1,i),root(city2,i)))
c=Counter(r)
for i in range(n):
  ans=c[r[i]]
  if i==n-1:
    print(ans)
  else:
    print(ans,end=' ')
### BUGGY CODE ###

n, m, k = map(int, input().split())
mod = 998244353

ans = 0
t = 1
b = 1
for i in range(k+1):
  ans += t * pow(m-1, n-1-i, mod) * pow(b, mod-2, mod)
  ans %= mod
  #n-1Ci * (m-1)**i
  t *= (n-1-i)
  b *= (i+1)
print(ans*m%mod)

### FIXED CODE ###

n, m, k = map(int, input().split())
mod = 998244353

ans = 0
t = 1
b = 1
for i in range(k+1):
  ans += t * pow(m-1, n-1-i, mod) * pow(b, mod-2, mod)
  ans %= mod
  #n-1Ci * (m-1)**i
  t *= (n-1-i)
  t %= mod
  b *= (i+1)
  b %= mod
print(ans*m%mod)
### BUGGY CODE ###

from collections import deque
N, M = map(int, input().split())
P = list(map(int, input().split()))
graph = [[] for _ in range(N)]
can = [[] for _ in range(N)]
xy = list()
for i in range(M):
  x, y = map(int, input().split())
  graph[x-1].append(y-1)
  graph[y-1].append(x-1)
for i in range(N): 
  q = deque([i])
  while q:
    t = q.popleft()
    can[i].append(t)
    for next in graph[t]:
      if next not in can[i]:
        q.append(next)
ans = 0
for i in range(N):
  p = P[i] - 1
  if p in can[i]:
    ans += 1
print(ans)

### FIXED CODE ###

class UnionFind(): 
    def __init__(self, n):
        self.n = n
        self.parents = [-1]*n 
        
    def find(self, x): 
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
            
    def union(self, x, y): 
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x,y = y,x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
        
    def same(self, x, y): 
        return self.find(x) == self.find(y)

N, M = map(int, input().split())
P = list(map(int, input().split()))
uf = UnionFind(N+1)
graph = [[] for _ in range(N)]
can = [[] for _ in range(N)]
xy = list()
for i in range(M):
  x, y = map(int, input().split())
  uf.union(x, y)
ans = 0
for i in range(1, N+1):
  if uf.same(i, P[i-1]):
    ans += 1
print(ans)
### BUGGY CODE ###

import sys
import collections
from math import ceil
ma = lambda : map(int,input().split())
ni = lambda : int(input())

n,m = ma()
gcd = 1
for d in range(1,m//n+1):
    q,r = divmod(m,d)
    if r == 0 and q>=n:gcd = d
print(gcd)


### FIXED CODE ###

import sys
import collections
from math import ceil
ma = lambda : map(int,input().split())
ni = lambda : int(input())
def divisor(n):
    d = []
    for i in range(1,int(n**0.5)+1):
        if n%i == 0:
            d.append(i)
            if i != n//i:
                d.append(n//i)
    #d.sort()
    return d
n,m = ma()
gcd = 1
D = divisor(m)
for d in D:
    q,r = divmod(m,d)
    if q>=n and r==0:gcd = max(gcd,d)
print(gcd)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# https://atcoder.jp/contests/abc135/tasks/abc135_d
# 5あまるじゃなくてn余るできないかな？

'''
dp[i][j] ... [0,i)桁の数字で、余りがjに成る通りの総数
更新則
?じゃないとき
dp[i+1][(j+S[i]*pow(10,i,13))%13] = dp[i][j]
?のとき
dp[i+1][j] += dp[i][k] #すべてのjとkで
'''
mod = 13
S = list(reversed(read()[:-1]))

dp = [[0] * mod for _ in range(len(S) + 1)]
dp[0][0] = 1
for i in range(len(S)):
    for j in range(mod):
        if S[i] != '?':
            dp[i + 1][(j + int(S[i]) * pow(10, i, mod)) % mod] += \
                dp[i][j] % MOD
        else:
            for k in range(10):
                dp[i + 1][(j + k * pow(10, i, mod)) % mod] += \
                    dp[i][j] % MOD

print(dp[-1][5] % MOD)
# print(*dp, sep='\n')


### FIXED CODE ###

# https://atcoder.jp/contests/abc135/tasks/abc135_d

# む ず す ぎ に き あ く ん 笑

# 全探索すると最悪O(10^100000)となり宇宙が崩壊するので桁の独立性について考えてみる。
# まず文字列Sについて式を書き換える。下からi桁目の数字をSi、len(S)=n (桁数)とすると、
# S=S0 + S1*10 + S2*100 + S3*1000 ... となる。これは(mod 13)において
# S≡S0 + S1*10 + S2*9   + S3*12 ... (mod 13)であり、Si=='?' の中でS≡5となる通りの数を求めれば良い。という問題になる。
# 以上により、i番目の項までの余りはi-1番目の項までの余りを足して法を取り直すことで得られることがわかる。
# 具体的には桁DPなるテクニックで、dp[i][j] (n,13) ... i番目の項まで足したときに13で割った余りがjである通りの数 を更新していけば良い。

MOD = 10**9 + 7
S = input()[::-1]
n = len(S)

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

for i, s in enumerate(S):
    mul = pow(10, i, 13)
    if s != '?':
        shift = (int(s) * mul) % 13
        for j in range(13):
            dp[i + 1][(j + shift) % 13] = dp[i][j]
    else:
        for candi in range(10):
            shift = (candi * mul) % 13
            for j in range(13):
                dp[i + 1][(j + shift) % 13] += dp[i][j] % MOD
print(dp[-1][5] % MOD)