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

n = int(input())

a = list(map(str, input().split()))
b = []
for i in range(n):
  if i % 2 == 0:
    #後ろに追加する場合
    b.append(a[i])
  else:
    b.insert(0,a[i])
    
if n % 2 != 0:
  b.reverse()
  
print(" ".join(b))

### FIXED CODE ###

from collections import deque

n = int(input())

a = list(map(str, input().split()))
b = deque()
for i in range(n):
  if i % 2 == 0:
    #後ろに追加する場合
    b.append(a[i])
  else:
    b.appendleft(a[i])
    
    
    
if n % 2 != 0:
  b.reverse()
  
print(" ".join(b))
### BUGGY CODE ###

#! -*- coding: utf-8 -*-
import numpy as np

n = int(raw_input())

p = np.zeros([n])
for i in range(n):
    p[i] = int(raw_input())

count = np.zeros([n],int)
for i in range(n):
    check = i+1
    for j in range(n):
        if p[j] == check:
            count[i] += 1
            check += 1

#print count

#print np.max(count)

ans = n-np.max(count)

print ans


### FIXED CODE ###

#! -*- coding: utf-8 -*-
import numpy as np

n = int(raw_input())

p = np.zeros([n],int)
for i in range(n):
    p[i] = int(raw_input())

count = np.zeros([n+1],int)

for i in range(n):
    count[p[i]] = count[p[i]-1]+1

#print count

#print count

#print np.max(count)

ans = n-np.max(count)

print ans
### BUGGY CODE ###

N, M = map(int, input().split())
MOD = 10**9+7


# 逆元
# a^{-1} mod を計算する
def mod_inv(a, m):
    return pow(a, m-2, m)


def combination(a, b):
    if b > a - b:
        return combination(a, a - b)
    # 10C3 = (10*9*8)/(3*2*1)
    # 10*9*8 -> ans_mul
    # 3*2*1 -> ans_div
    ans_mul = 1
    ans_div = 1
    for i in range(b):
        ans_mul *= a - i
        ans_div *= i + 1
        ans_mul %= MOD
        ans_div %= MOD
    # ans_mul / ans_div をやりたい
    # ans_div の逆元を使って求める
    ans = ans_mul * mod_inv(ans_div, MOD)
    return ans


# M を素因数分解
m_nokori = M
ans = 1
for i in range(2, M+1):
    if m_nokori == 1:
        break
    cnt = 0
    while m_nokori % i == 0:
        cnt += 1
        m_nokori //= i
    # cnt が 2^X とか 3^X の X の部分
    ans *= combination(N+cnt-1, N-1)
    ans %= MOD

print(ans)


### FIXED CODE ###

# 逆元
# a^{-1} mod を計算する
def mod_inv(a, m):
    return pow(a, m-2, m)


def combination(a, b):
    if b > a - b:
        return combination(a, a - b)

    # 10C3 = (10*9*8)/(3*2*1)
    # 10*9*8 -> ans_mul
    # 3*2*1 -> ans_div
    ans_mul = 1
    ans_div = 1
    for i in range(b):
        ans_mul *= a - i
        ans_div *= i + 1
        ans_mul %= MOD
        ans_div %= MOD
    # ans_mul / ans_div をやりたい
    # ans_div の逆元を使って求める
    ans = ans_mul * mod_inv(ans_div, MOD)
    return ans


N, M = map(int, input().split())
MOD = 10**9+7
# M を素因数分解
rest = M
ans = 1
for i in range(2, int(M ** 0.5) + 1):
    cnt = 0
    while rest % i == 0:
        cnt += 1
        rest //= i
    # cnt が 2^X 1とか 3^X の X の部分
    ans *= combination(N+cnt-1, N-1)
    ans %= MOD
if rest != 1:
    cnt = 1
    ans *= combination(N+cnt-1, N-1)
    ans %= MOD

print(ans)
### BUGGY CODE ###

n, k = map(int, input().split())
s = [i for i in input()]
zero_one = []
if s[0] == "0":
    zero_one.append(0)
s_ = s[0]
cnt = 0
for i in range(n):
    if s_ == s[i]:
        cnt += 1
    else:
        zero_one.append(cnt)
        cnt = 1
        s_ = s[i]
zero_one.append(cnt)
if s[-1] == "0":
    zero_one.append(0)
ans = 0
for i in range(0, n, 2):
    ans = max(ans, sum(zero_one[i:min(n, i+2*k+1)]))
print(ans)

### FIXED CODE ###

from itertools import accumulate
n, k = map(int, input().split())
s = [i for i in input()]
zero_one = [0]
if s[0] == "0":
    zero_one.append(0)
s_ = s[0]
cnt = 0
for i in range(n):
    if s_ == s[i]:
        cnt += 1
    else:
        zero_one.append(cnt)
        cnt = 1
        s_ = s[i]
zero_one.append(cnt)
if s[-1] == "0":
    zero_one.append(0)
ans = 0
l = len(zero_one)
zero_one = list(accumulate(zero_one))
for i in range(0, l, 2):
    ans = max(ans, zero_one[min(l-1, i+2*k+1)] - zero_one[i])
print(ans)
### BUGGY CODE ###

def check(x,a,b,c):
    if x==a or x==b or x==c:
        return False
    return True


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

ans=[]

for i in range(n):
    for j in range(i+1,n):
        for z in range(j+1,n):
            a1=a[i]
            b1=a[j]
            c1=a[z]

            if a1+b1>c1 and a1+c1>b1 and c1+b1>a1:
                ans.append([i,j,z])
count =0


print(len(ans))
# for i in range(len(ans)):
#     for j in range(i+1,len(ans)):
#         if check(ans[i][0],ans[j][0],ans[j][1],ans[j][2]):
#             count+=1
#         elif check(ans[i][1],ans[j][0],ans[j][1],ans[j][2]):
#             count+=1
#         elif check(ans[i][2],ans[j][0],ans[j][1],ans[j][2]):
#             count+=1
# 
# 
# print(count)


### FIXED CODE ###



def find(arr):

	n = len(arr)
	arr.sort()
	count = 0
	for i in range(0,n-2):

		k = i + 2

		for j in range(i+1,n):
			while (k < n and arr[i] + arr[j] > arr[k]): 
				k += 1
			if(k>j):
				count += k - j - 1

	return count

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


print(find(a))
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import collections
import math


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


n, p = map(int, input().split())
s = input()

if p == 2:
    ret = 0
    for i in range(len(s)):
        if int(s[i]) % 2 == 0:
            ret = ret + i + 1
    print(ret)
elif p == 5:
    ret = 0
    for i in range(len(s)):
        if int(s[i]) % 5 == 0:
            ret = ret + i + 1
    print(ret)
else:
    c_list = [0] * n
    for i in range(len(s)):
        c_list[i] = int(s[-i-1:]) % p
    c_list.append(0)
    c = collections.Counter(c_list)
    ret = 0
    for item in c:
        cnt = c[item]
        if cnt >= 2:
            ret = ret + combinations_count(cnt, 2)
    print(ret)


### FIXED CODE ###

# -*- coding: utf-8 -*-
n, p = map(int, input().split())
s = input()

if p == 2:
    ret = 0
    for i in range(len(s)):
        if int(s[i]) % 2 == 0:
            ret = ret + i + 1
    print(ret)
elif p == 5:
    ret = 0
    for i in range(len(s)):
        if int(s[i]) % 5 == 0:
            ret = ret + i + 1
    print(ret)
else:
    c_list = [0] * n
    power = 1
    for i in range(len(s)):
        c_list[i] = (c_list[i-1] + (int(s[-i-1]) * power)) % p
        power *= 10
        power = power % p
    c_list.append(0)
    counter = [0] * p
    for i in c_list:
        counter[i] += 1
    ret = 0
    for item in counter:
        if item >= 2:
            ret = ret + (item * (item - 1) // 2)
    print(ret)
### BUGGY CODE ###

#AIsing2020 d

def f(n):
        cnt = 0
        while n:
            cnt+= 1
            n = n%bin(n).count('1')
        return cnt

def main():
    N = int(input())
    X = input()
    X10 = int(X,2)
    X10_num1 = X.count('1')
    X10_pulse = X10%(X10_num1+1)
    X10_ninus = X10%(X10_num1-1) if X10_num1 >1 else 0


    for i in range(N,0,-1):
        if (X10>>(i-1) & 1) and X10_num1 >1:
            amari = (X10_ninus - (2**(i-1))%(X10_num1-1))%(X10_num1-1)
        elif (X10>>(i-1) & 1) and X10_num1 ==1:
            print(0)
            continue
        else:
            amari = (X10_pulse + (2**(i-1))%(X10_num1+1))%(X10_num1+1)

        print(1+f(amari))


main()


### FIXED CODE ###

#AIsing2020 d

def f(n):
        cnt = 0
        while n:
            cnt+= 1
            n = n%bin(n).count('1')
        return cnt

def main():
    N = int(input())
    X = input()
    X10 = int(X,2)
    X10_num1 = X.count('1')
    X10_pulse = X10%(X10_num1+1)
    X10_ninus = X10%(X10_num1-1) if X10_num1 >1 else 0


    for i in range(N,0,-1):
        j = N-i
        if (X[j] == '1') and X10_num1 >1:
            mod = X10_num1-1
            amari = (X10_ninus - pow(2,i-1,mod))%(mod) 
        elif (X[j] == '1') and X10_num1 ==1:
            print(0)
            continue
        else:
            mod = X10_num1+1
            amari = (X10_pulse + pow(2,i-1,mod))%(mod)

        print(1+f(amari))


main()
### BUGGY CODE ###

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

ans = 0
num = 0
for i in range(K):
    if num < A:
        ans += 1
    elif num < A+B:
        ans += 0
    else:
        ans -= 1
    num += 1

print(ans)

### FIXED CODE ###

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

if K <= A:
    print(K)
elif K <= A+B:
    print(A)
else:
    print(A+(K-A-B)*-1)
### BUGGY CODE ###

#!/usr/bin/env python
# coding: utf-8

# In[15]:


from collections import deque


# In[9]:


N,M = map(int, input().split())
alist = []
for _ in range(M):
    alist.append(int(input()))


# In[31]:


dp = deque([0]*2)
dp[0] = 1
ans = 0
mod = 1000000007
if N == 1:
    ans = 1
else:
    if 1 in alist:
        dp[1] = 0
    else:
        dp[1] = 1
    for i in range(2,N+1):
        if i in alist:
            dp.append(0)
        else:
            dp.append((dp[0] + dp[1])%mod)
        dp.popleft()
    ans = dp[-1]
print(ans)


# In[ ]:






### FIXED CODE ###

#!/usr/bin/env python
# coding: utf-8

# In[15]:


from collections import deque


# In[38]:


N,M = map(int, input().split())
alist = [False]*N
for _ in range(M):
    alist[int(input())-1] = True


# In[41]:


dp = deque([0]*2)
dp[0] = 1
ans = 0
mod = 10**9+7
if N == 1:
    ans = 1
else:
    if alist[0]:
        dp[1] = 0
    else:
        dp[1] = 1
    for i in range(2,N+1):
        if alist[i-1]:
            dp.append(0)
        else:
            dp.append((dp[0]+dp[1])%mod)
        dp.popleft()
    ans = dp[-1]
print(ans)


# In[ ]:
### BUGGY CODE ###

import bisect

N, M = map(int, input().split())
A_list = sorted( list( int(i) for i in input().split() ))
BC_list = sorted(
  list( list( int(i) for i in input().split() ) for _ in range(M) ),
  key=lambda x:-x[1]
)

n = N
for bc in BC_list:
  for i in range(bc[0]):
    bisect.insort_right(A_list, bc[1])
L = len(A_list)
print(sum(A_list[L:L-N-1:-1]))

### FIXED CODE ###

N, M = map(int, input().split())
A_list = sorted( list( int(i) for i in input().split() ))
BC_list = sorted(
  list( list( int(i) for i in input().split() ) for _ in range(M) ),
  key=lambda x:-x[1]
)

change_list = []
for bc in BC_list:
  change_list += [bc[1]] *  bc[0]
  if len(change_list) >= N :
    break
A_list += change_list
A_list.sort()
L = len(A_list)
print(sum(A_list[L:L-N-1:-1]))
### BUGGY CODE ###

N,K = map(int,input().split())
LR = [list(map(int,input().split())) for i in range(K)]
mod = 998244353
ma = [0] * N
ma[0] = 1
for i in range(N):
    if i >1:
        ma[i] += ma[i-1]
    p = ma[i]
    if p != 0:
        for l,r in LR:
            if i+l <N:
                ma[i+l] += p
            if i+r+1<N:
                ma[i+r+1] -= p
print(ma[N-1]%mod)

### FIXED CODE ###

N,K = map(int,input().split())
LR = [list(map(int,input().split())) for i in range(K)]
LR.sort()
mod = 998244353
ma = [0] * N
ma[0] = 1
for i in range(N):
    if i >1:
        ma[i] += ma[i-1]
    p = ma[i]%mod
    if p != 0:
        for l,r in LR:
            if i+l <N:
                ma[i+l] += p
            else:
                break
            if i+r+1<N:
                ma[i+r+1] -= p
print(ma[N-1]%mod)
### BUGGY CODE ###

S=input()
Q=int(input())
A=[input().split() for i in range(Q)]

guuki=0
ANS=S
for i in range(Q):
  if A[i][0]=="1":
    guuki+=1
  elif int(A[i][1])*guuki%2==1 or (A[i][1]=="2" and guuki%2==0):
    ANS=ANS+A[i][2]
  else:
    ANS=A[i][2]+ANS
re_ans=ANS
if guuki%2==1:
  re_ans=""
  for j in range(len(ANS)):
    re_ans+=ANS[len(ANS)-j-1]
print(re_ans)

### FIXED CODE ###

S=input()
Q=int(input())

guuki=0
ANS=S
ANS_back=""
ANS_front=""
for i in range(Q):
    A=list(input().split())
    if A[0]=="1":
        guuki+=1
    elif int(A[1])*guuki%2==1 or (A[1]=="2" and guuki%2==0):
        ANS_back+=A[2]
    else:
        ANS_front+=A[2]
if guuki%2==1:
    ANS=ANS[::-1]
    ANS_back,ANS_front=ANS_front,ANS_back
print(ANS_front[::-1]+ANS+ANS_back)
### BUGGY CODE ###

import sys
input = sys.stdin.readline


n, m = map(int, input().split())
edges = []
for _ in range(m):
    l, r, c = map(int, input().split())
    edges.append([l-1, r-1, c])

edges.sort()

DP = [float('INF')] * n
DP[0] = 0

for l, r, c in edges:
    for i in range(l+1, r+1):
        DP[i] = min(DP[i], DP[l]+c)

ans = DP[n-1]
if ans == float('INF'):
    ans = -1
print(ans)


### FIXED CODE ###

import heapq
import sys
input = sys.stdin.readline

n, m = map(int, input().split())

edges = [[] for _ in range(n)]
for i in range(1, n):
    _from, to, dist = i, i-1, 0
    edges[_from].append([to, dist])

for _ in range(m):
    _from, to, dist = map(int, input().split())
    edges[_from-1].append([to-1, dist])


D = [float('INF')]*n
D[0] = 0
todo = []
for to, dist in edges[0]:
    heapq.heappush(todo, [dist, to])
    D[to] = dist

while todo:
    total_dist, node = heapq.heappop(todo)

    for to, dist in edges[node]:
        if total_dist + dist < D[to]:
            heapq.heappush(todo, [total_dist+dist, to])
            D[to] = total_dist + dist
        else:
            continue

ans = D[n-1]
if ans == float('INF'):
    ans = -1

print(ans)
### BUGGY CODE ###

import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from bisect import bisect_left
from itertools import accumulate

n,q = li()
a = list(li())
x = [ni() for _ in range(q)]


cum_nor = list(accumulate(a))
cum_odd = list(accumulate(a[::2]))
cum_evn = list(accumulate(a[1::2]))
cum_kog = [cum_odd[i//2] if i%2==0 else cum_evn[i//2] for i in range(n)]

def check(a:list, tak:int, pivot:int):
    rng = a[-tak] - pivot
    left = bisect_left(a, pivot-rng)
    right = bisect_left(a, pivot+rng)
    aok = right-left
    if aok >= tak-1:
        return True
    else:
        return False
    
def binsearch(a:list,xi:int):
    low = 1
    high = len(a)
    while high-low > 1:
        mid = (high+low) // 2
        if check(a,mid,xi):
            low = mid
        else:
            high = mid
            
    return low

for xi in x:
    tak = binsearch(a,xi)
    ans = cum_nor[-1] - cum_nor[-tak-1]
    if 2*tak < n:
        ans += cum_kog[-2*tak-1] 
    
    print(ans)

### FIXED CODE ###

import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from bisect import bisect_left
from itertools import accumulate

n,q = li()
a = list(li())
x = [ni() for _ in range(q)]


cum_nor = list(accumulate(a))
cum_odd = list(accumulate(a[::2]))
cum_evn = list(accumulate(a[1::2]))
cum_kog = [cum_odd[i//2] if i%2==0 else cum_evn[i//2] for i in range(n)]

# 高橋君が左からtak個取れるならTrue そうでないならFalse
def check(a:list, tak:int, pivot:int):
    if tak > (len(a)+1)//2:
        return False
    
    if pivot-a[-2*tak+1] > a[-tak]-pivot:
        return False
    else:
        return True
        
    
def binsearch(a:list,xi:int):
    low = 1
    high = len(a)
    while high-low > 1:
        mid = (high+low) // 2
        if check(a,mid,xi):
            low = mid
        else:
            high = mid
            
    return low


for xi in x:
    tak = binsearch(a,xi)
    ans = cum_nor[-1] - cum_nor[-tak-1]
    if 2*tak < n:
        ans += cum_kog[-2*tak-1] 
    
    print(ans)
### BUGGY CODE ###

N,W = map(int, input().split())

wv = [tuple(map(int, input().split())) for _ in range(N)]

#i番目まで選べる時に価値がｊとなる最小の重み
dp = [{} for _ in range(N+1)]
dp[0][0] = 0

for i, (w, v) in enumerate(wv):
    # i番目のアイテムまで選んで作れる価値とその時の最小重さの組を取り出す
    for v0, w0 in dp[i].items():
        # 価値v0になる組み合わせが、i番目までの中から選ぶ中で既に存在しているばあい
        if v0 in dp[i+1]:
            # 軽い方を残す
            dp[i+1][v0] = min(dp[i+1][v0], w0) #同じ価値で重さが違うとか、組み合わせで価値は同じだが重さが違うみたいな場合
        # i番目まで選んだ時に重さw0になる組がない場合
        else:
            # i番目まで使い、i+1番目は使わない
            dp[i+1][v0] = w0
        
        # i番目（重さw）を使って、或る組み合わせの価値＋i番目で重量制限を超えたらアウト
        if w0 + w > W:
            continue
        # 上と同じ感じで、今まで+i番目の価値と同じ価値の組が、既に存在する場合、軽いほうを残す
        if v0 + v in dp[i+1]:
            dp[i+1][v0 + v] = min(dp[i+1][v0 + v], w0 + w)
        else:
            dp[i+1][v0 + v] = w0 + w

#最後まで選べる中で、最も価値が大きいもの（重さがオーバーするものはcontinueで落ちてるから問題ない）
print(max(dp[-1].keys()))
        


### FIXED CODE ###

N, W = map(int, input().split())
wv = [tuple(map(int, input().split())) for _ in range(N)]

# Wの最大が大きすぎて計算間に合わないので最大最小変換を行う
# dp[i+1][j]：i番目までのアイテムをナップザックに入れられるとき、価値がjとなる最小の重み
dp = [{} for i in range(N+1)]
dp[0][0] = 0


for i, (w,v) in enumerate(wv):
    for v0, w0 in dp[i].items(): # dictのキーと値に対してfor、i-1番目までのアイテムについて考える
        if v0 in dp[i+1]: # 
            dp[i+1][v0] = min(dp[i+1][v0], w0) # 同じ価値でさらに軽いものがある場合はそれを最小の重みに指定
        else:
            dp[i+1][v0] = w0 # 価値v0のものが今までのアイテムになければ、それを最小の重みに指定
        
        if w0+w > W: # 或る価値に対する最小重みに、現在のアイテムの重みを足して上限を超える場合は、今の価値についてそのアイテムは選択対象外
            continue # 
        if v0+v in dp[i+1]: # 今までの価値+新しく選んだものの価値 がi番目までのアイテムを選んだ時に既に存在する場合
            dp[i+1][v0+v] = min(dp[i+1][v0+v], w0+w)
        else:
            dp[i+1][v0+v] = w0+w


print(max(dp[-1].keys())) # 全部選んでいいときに価値として起こりうるものの最大
### BUGGY CODE ###

n, k = map(int, input().split())

def e(x):
    x = int(x)
    return sum(range(1, x+1)) / x

p = list(map(e, input().split()))

s = 0
for i in range(n-k+1):
    s = max(s, sum(p[i:i+k]))
print(s)

### FIXED CODE ###

n, k = map(int, input().split())
e = list(map(lambda x: (int(x)+1)/2, input().split()))

s = [e[0]]
for i in range(1, n):
    s.append(s[i-1]+e[i])

a = 0
for i in range(n-k+1):
    if i == 0:
        a = max(a, s[i+k-1])
    else:
        a = max(a, s[i+k-1] - s[i-1])
print(a)
### BUGGY CODE ###

from collections import deque

h, w = map(int, input().split())
Black = []
White = deque()

for i in range(h):
    a = str(input())
    for j in range(w):
        if a[j] == '#':
            Black.append([i,j])
        else:
            White.append([i,j])

longest = 0
while White:
    white = White.popleft()
    white_x = white[0]
    white_y = white[1]
    shortest_per_white = 10**4
    for black in Black:
        length = abs(black[0]-white_x) + abs(black[1]-white_y)
        shortest_per_white = min(shortest_per_white, length)
    longest = max(shortest_per_white, longest)

print(longest)

### FIXED CODE ###

from collections import deque

h, w = map(int, input().split())
Black = deque([])
Black_grid = [[-1 for _ in range(w)] for _ in range(h)]

for i in range(h):
    a = str(input())
    for j in range(w):
        if a[j] == '#':
            Black.append([j,i])
            Black_grid[i][j] = 0

Move = [[-1,0],[1,0],[0,-1],[0,1]]

while Black:
    now = Black.popleft()
    x = now[0]
    y = now[1]
    for move in Move:
        x_next = x + move[0]
        y_next = y + move[1]
        if x_next < 0 or x_next >= w or y_next < 0 or y_next >= h:
            continue
        elif Black_grid[y_next][x_next] >= 0:
            continue
        else:
            Black.append([x_next, y_next])
            Black_grid[y_next][x_next] = Black_grid[y][x] + 1

ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, Black_grid[i][j])
    
print(ans)
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
def haitteru(l, x):
	if x in set(l):
		return l.index(x)
	else:
		return -1


cnt = n+2
x = haitteru(a, 1)

if x != -1:
	cnt = 2
	while True:
		x = haitteru(a[x+1:], cnt)
		if x == -1:
			break
		cnt += 1

print(n-cnt+1)

### FIXED CODE ###

import bisect
n=int(input())
a=list(map(int,input().split()))
c=max(a)
ct=[[0] for _ in range(c+1)]
for i in range(n):
	ct[a[i]].append(i+1)
ans = -1
memo = -1
for j in range(c+1):
	if max(ct[j])>memo:
		ans += 1
		memo = ct[j][bisect.bisect_right(ct[j], memo)]
	else:
		break
if ct[1]==[0]:
	print(-1)
else:
	print(n-ans)
### BUGGY CODE ###

N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [float('inf')]*N
dp[0] = 0
for i in range(N):
    for j in range(max(0, i - K), i):
        dp[i] = min(dp[i], dp[j] + abs(h[i]-h[j]))
print(dp[-1])

### FIXED CODE ###

N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [float('inf')]*N
dp[0] = 0
for i in range(N):
    for j in range(max(0, i - K), i):
        dp[i] = min(dp[i], dp[j] + abs(h[i]-h[j]))
print(dp[-1])
### BUGGY CODE ###

from itertools import combinations 

n=int(input())
s=input()
con=set()
for i in combinations(s,3):
  con.add(i)
  
print(len(con))

### FIXED CODE ###

n=int(input())
s=input()
ans=0
for i in range(10):
  a=s.find(str(i))
  if a == -1:
    continue
  for j in range(10):
    b=s.find(str(j),a+1)
    if b == -1:
      continue
    for k in range(10):
      if s.find(str(k),b+1) != -1:
        ans+=1
print(ans)
### BUGGY CODE ###

n = int(input())
s = 0
tmp = n
while tmp:
  s += tmp % 10
  tmp // 10
if n % s == 0:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

str_n = input()
n = int(str_n)
s = 0
for digit in str_n:
  s += int(digit)
if n % s == 0:
  print('Yes')
else:
  print('No')
### BUGGY CODE ###

A,B,K = map(int,input().split())
for i in range(A,B+1):
  if i < A+K or i > B-K:
    print(i)

### FIXED CODE ###

A,B,K = map(int,input().split())
for i in range(A,min(A+K,B+1)):
  print(i)
for i in range(max(B-K+1,A+K),B+1):
  print(i)
### BUGGY CODE ###

# -*- coding:utf-8 -*-
"""解説
dp

dp[i][j] := 先頭i文字として考えられるもののうち、13で割ったあまりがjであるものの数

1?2?3 を分解すると、
10000 ≡ 3
 A000 ≡ A*(10**3) % MOD ≡ A*12
  200 ≡ 5
   B0 ≡ B*(10**1) % MOD
    3 ≡ 3
    -----
        11 + ? ≡ 11 + A*12 + B*10

"""


def solve():
    S = input()
    MOD = 10**9+7

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

    for i in range(0, N):
        if S[i] == "?":
            c = -1
        else:
            c = int(S[i])
        
        for j in range(0, 10):
            if c != -1 and c != j: continue
            
            for ki in range(0, 13):
                dp[i+1][(ki* 10 + j)%13] += dp[i][ki]
        
        for j in range(0, 13):
            dp[i+1][j] %= MOD

    res = dp[N][5]
    print(res)


if __name__ == "__main__":
    solve()


### FIXED CODE ###

# -*- coding:utf-8 -*-
"""解説
dp

dp[i][j] := 先頭i文字として考えられるもののうち、13で割ったあまりがjであるものの数

1?2?3 を分解すると、
10000 ≡ 3
 A000 ≡ A*(10**3) % MOD ≡ A*12
  200 ≡ 5
   B0 ≡ B*(10**1) % MOD
    3 ≡ 3
    -----
        11 + ? ≡ 11 + A*12 + B*10

"""


def solve():
    S = input()
    MOD = 10**9+7

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

    for i in range(0, N):
        if S[i] == "?":
            c = -1
        else:
            c = int(S[i])
        
        for j in range(0, 10):
            if c != -1 and c != j: continue
            
            for ki in range(0, 13):
                dp[i+1][(ki* 10 + j)%13] += dp[i][ki]
        
        for j in range(0, 13):
            dp[i+1][j] %= MOD

    res = dp[N][5]
    print(res)


if __name__ == "__main__":
    solve()