Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
A = list(map(int,input().split()))
A_dict = {i:a for i,a in enumerate(A,1)}

History = [1]
History_set = {1}
now = 1
for _ in range(N):
    now = A_dict[now]
    if now not in History_set:
        History.append(now)
        History_set.add(now)
    else:
        break
#print(History,now)
if K < N:
    print(History[K])
else:
    e = History.index(now)
    #print(e)
    #print(History[e:])
    loop_num = len(History[e:])
    #print(loop_num)
    num = (K-e)%loop_num
    #print(num)
    print(History[e:][num])


Fixed submission:
N,K = map(int,input().split())
A = list(map(int,input().split()))
A_dict = {i:a for i,a in enumerate(A,1)}

History = [1]
History_set = {1}
now = 1
for i in range(N):
    now = A_dict[now]
    if now not in History_set:
        History.append(now)
        History_set.add(now)
    else:
        break
#print(History,now)
if K < i:
    print(History[K])
else:
    e = History.index(now)
    #print(e)
    #print(History[e:])
    loop_num = len(History[e:])
    #print(loop_num)
    num = (K-e)%loop_num
    #print(num)
    print(History[e:][num])

Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
A = list(map(int,input().split()))
A_dict = {i:a for i,a in enumerate(A,1)}

History = [1]
History_set = {1}
now = 1
for _ in range(N):
    now = A_dict[now]
    if now not in History_set:
        History.append(now)
        History_set.add(now)
    else:
        break
#print(History,now)
if K <= N:
    print(History[K])
else:
    e = History.index(now)
    #print(e)
    #print(History[e:])
    loop_num = len(History[e:])
    #print(loop_num)
    num = (K-e)%loop_num
    #print(num)
    print(History[e:][num])

Fixed submission:
N,K = map(int,input().split())
A = list(map(int,input().split()))
A_dict = {i:a for i,a in enumerate(A,1)}

History = [1]
History_set = {1}
now = 1
for i in range(N):
    now = A_dict[now]
    if now not in History_set:
        History.append(now)
        History_set.add(now)
    else:
        break
#print(History,now)
if K < i:
    print(History[K])
else:
    e = History.index(now)
    #print(e)
    #print(History[e:])
    loop_num = len(History[e:])
    #print(loop_num)
    num = (K-e)%loop_num
    #print(num)
    print(History[e:][num])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
#print(S)
cnt = 1
S_list = [s for s in S]
#print(S_list)
for i in range(N):
    if S_list[N-1-i] != S_list[N-1-(i+1)] and N-1-(i+1)>=0:
        S_list.insert(N-1-i,"|")
        cnt += 1
    #print(S_list)
print(cnt)

Fixed submission:
N = int(input())
S = input()
#print(S)
cnt = 1
S_list = [s for s in S]
#print(S_list)
for i in range(N):
    if S_list[N-1-i] != S_list[N-1-(i+1)] and N-1-(i+1)>=0:
        #S_list.insert(N-1-i,"|")
        cnt += 1
    #print(S_list)
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
N,K,Q = map(int,input().split())
A = [int(input()) for _ in range(Q)]
Point_0 = [K for _ in range(N)]
for a in A:
    for i in range(N):
        if i != a-1:
            Point_0[i] -= 1
for p in Point_0:
    if p > 0:
        print("Yes")
    else:
        print("No")

Fixed submission:
N,K,Q = map(int,input().split())
A = [int(input()) for _ in range(Q)]

Point_0 = [K-Q for _ in range(N)]
#(Point_0)
Point_Q = [0 for _ in range(N)]
for a in A:
    Point_Q[a-1] += 1
Point = [i+j for i,j in zip(Point_0,Point_Q)]
hantei = [print("Yes") if p>0 else print("No") for p in Point]
Buggy python submission (verdict: Runtime Error):
N = int(input())
B = list(map(int,input().split()))
A = [B[0],*B]
#print(A,B)
for i in range(N-1):
    #print(i,B[i] >= max(A[i],A[i+1]))
    if B[i] < max(A[i],A[i+1]):
        A[i] = A[i+1]
print(sum(A))

Fixed submission:
N = int(input())
B = list(map(int,input().split()))
A = [B[0]] + B
#print(A,B)
for i in range(N-1):
    #print(i,B[i] >= max(A[i],A[i+1]))
    if B[i] < max(A[i],A[i+1]):
        A[i] = A[i+1]
print(sum(A))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
j = 0
for i in range(1,N):
    j += i
print(j)

Fixed submission:
N = int(input())
j = N*(N-1)//2
print(int(j))
Buggy python submission (verdict: Runtime Error):
import heapq

N,M = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]


d_AB = {a:[] for a,b in AB}
for a,b in AB:
    d_AB[a].append(-b)

H = [0]
money = 0
for i in range(1,M+1):
    if i in d_AB.keys():
        H += d_AB[i]
    #else:
        #H += [0]
    #print(H)
    heapq.heapify(H)
    money += heapq.heappop(H)

print(-money)

Fixed submission:
import heapq

N,M = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]


d_AB = {a:[] for a,b in AB}
for a,b in AB:
    d_AB[a].append(-b)
#print(d_AB)
H = []
heapq.heapify(H)
money = 0
for i in range(1,M+1):
    if i in d_AB.keys():
        for ab in d_AB[i]:
            heapq.heappush(H,ab)
        #print(H)
        money += heapq.heappop(H)
        #print(money)
        
    else:
        money += heapq.heappushpop(H,0)

print(-money)

Buggy python submission (verdict: Time Limit Exceeded):
import heapq

N,M = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]


d_AB = {a:[] for a,b in AB}
for a,b in AB:
    d_AB[a].append(-b)

H = []
money = 0
for i in range(1,M+1):
    if i in d_AB.keys():
        H += d_AB[i]
    else:
        H += [0]
    #print(H)
    heapq.heapify(H)
    money += heapq.heappop(H)

print(-money)

Fixed submission:
import heapq

N,M = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]


d_AB = {a:[] for a,b in AB}
for a,b in AB:
    d_AB[a].append(-b)
#print(d_AB)
H = []
heapq.heapify(H)
money = 0
for i in range(1,M+1):
    if i in d_AB.keys():
        for ab in d_AB[i]:
            heapq.heappush(H,ab)
        #print(H)
        money += heapq.heappop(H)
        #print(money)
        
    else:
        money += heapq.heappushpop(H,0)

print(-money)
Buggy python submission (verdict: Runtime Error):
N = int(input())
P = list(map(int,input().split()))
A = []
for i in range(N-1):
    if P[i]>P[i+1]:
        A.append([(P[i],i),(P[i+1],i+1)])
l = len(A)
if l > 2:
    print("NO")
elif l ==1:
    print("NO")
elif l == 0:
    print("YES")
else:
    a = max(A[0])
    b = min(A[1])
    P[a[1]],P[b[1]] = b[0],a[0]
    #print(P)
    for j in range(N-1):
        if P[j] > P[j+1]:
            print("NO")
            break
    if j == N-2:
        print("YES")

Fixed submission:
A,B = map(int,input().split())
C = A+B
if C%2 ==0:
    K = int(C/2)
elif A-B ==0:
    K = 0
else:
    K = "IMPOSSIBLE"
print(K)
Buggy python submission (verdict: Runtime Error):
import collections
N = int(input())
P = list(map(int,input().split()))
A = []
for i in range(N-1):
    if P[i]>P[i+1]:
        A.append([(P[i],i),(P[i+1],i+1)])
l = len(A)
if l > 2:
    print("NO")
elif l == 0:
    print("YES")
else:
    a = max(A[0])
    b = min(A[1])
    P[a[1]],P[b[1]] = b[0],a[0]
    #print(P)
    for j in range(N-1):
        if P[j] > P[j+1]:
            print("NO")
            break
    if j == N-2:
        print("YES")

Fixed submission:
N = int(input())
P = list(map(int,input().split()))
A = []
for i in range(N-1):
    if P[i]>P[i+1]:
        A.append([(P[i],i),(P[i+1],i+1)])
l = len(A)
if l > 2 or l == 1:
    print("NO")
elif l == 0:
    print("YES")
elif l == 2:
    a = max(A[0])
    b = min(A[1])
    P[a[1]],P[b[1]] = b[0],a[0]
    for j in range(N-1):
        if P[j] > P[j+1]:
            print("NO")
            j = "j"
            break
    if j != "j":
        print("YES")
Buggy python submission (verdict: Time Limit Exceeded):
L,R = map(int, input().split())
t = 2019
for i in range(L,R):
    for j in range(i+1,R+1):
        m = (i*j)%2019
        t = min(m,t)
print(t)

Fixed submission:
L,R = map(int, input().split())
if R-L >= 2019:
  print(0)
else:
  t = 2019
  for i in range(L,R):
    for j in range(i+1,R+1):
        m = (i*j)%2019
        t = min(m,t)
  print(t)
Buggy python submission (verdict: Runtime Error):
N, X = map(int, input().split())
L = list(map(int, input().split()))
#print(L)
D = 0
for i in range(N+1):
    if D > X:
        break
    D += L[i]
print(i)

Fixed submission:
N, X = map(int, input().split())
L = list(map(int, input().split()))
D = 0
jump = 1
for i in range(N):
    D += L[i]
    if D > X:
        break
    else:
        jump += 1
print(jump)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

D = int(input())
cost = list(map(int, input().strip().split()))
S = [list(map(int, input().strip().split())) for _ in range(D)]

last_held = [-1 for i in range(26)]
ans = []
for date, daily_scores in enumerate(S):
    minus_score = 0
    for i in range(D):
        minus_score += cost[i] * (date - last_held[i])

    max_score = daily_scores[0] + cost[0] * (date - last_held[0])
    max_index = 0
    for i, daily_score in enumerate(daily_scores):
        tmp = daily_score + cost[i] * (date - last_held[i])
        if max_score < tmp:
            max_index = i
            max_score = tmp
    if max_score <= minus_score:
        tmp = 0
        max_index = 0
        for i in range(D):
           if tmp < cost[i] * (date - last_held[i]):
               tmp = cost[i] * (date - last_held[i])
               max_index = i
    last_held[max_index] = date
    ans.append(max_index+1)
print("\n".join(map(str, ans)))

Fixed submission:
import sys
input = sys.stdin.readline

D = int(input())
cost = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(D)]

last_held = [-1 for i in range(26)]
ans = []
for date, line in enumerate(S):
    max_score = line[0] - cost[0]*last_held[0]
    max_index = 0
    for i, score in enumerate(line):
        tmp = score - cost[i]*last_held[i]
        if max_score < tmp:
            max_index = i
            max_score = tmp
    last_held[max_index] = date
    ans.append(max_index+1)
print("\n".join(map(str, ans)))

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

D = int(input())
cost = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(D)]

last_held = [-1 for i in range(26)]
ans = []
for date, daily_scores in enumerate(S):
    minus_score = 0
    for i in range(D):
        minus_score += cost[i] * (date - last_held[i])

    max_score = daily_scores[0] + cost[0] * (date - last_held[0])
    max_index = 0
    for i, dayly_score in enumerate(daily_scores):
        tmp = daily_scores[i] + cost[i] * (date - last_held[i])
        if max_score < tmp:
            max_index = i
            max_score = tmp
    last_held[max_index] = date
    ans.append(max_index+1)
print("\n".join(map(str, ans)))


Fixed submission:
import sys
input = sys.stdin.readline

D = int(input())
cost = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(D)]

last_held = [-1 for i in range(26)]
ans = []
for date, line in enumerate(S):
    max_score = line[0] - cost[0]*last_held[0]
    max_index = 0
    for i, score in enumerate(line):
        tmp = score - cost[i]*last_held[i]
        if max_score < tmp:
            max_index = i
            max_score = tmp
    last_held[max_index] = date
    ans.append(max_index+1)
print("\n".join(map(str, ans)))
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
from functools import reduce


ans = 0
K = int(input())
for a in (range(1, K+1)):
    for b in range(a, K+1):
        for c in range(b, K+1):
            n = 0
            if a == b == c:
                n = 1
            elif a == b or b == c or c == a:
                n = 3
            else:
                n = 6
            ans += n * reduce(gcd, [a,b,c])
print(ans)


Fixed submission:
from fractions import gcd
from functools import reduce

K = int(input())
tmp = [[0 for _ in range(K+1)] for _ in range(K+1)]
ans = 0
for a in (range(1, K+1)):
    for b in range(a, K+1):
        if tmp[a][b] != 0:
            gcd1 = tmp[a][b]
        else:
            gcd1 = gcd(a, b)
            tmp[a][b] = gcd1
        for c in range(b, K+1):
            n = 0
            if a == b == c:
                n = 1
            elif a == b or b == c or c == a:
                n = 3
            else:
                n = 6
            gcd2 = 0
            if tmp[gcd1][c] != 0:
                gcd2 = tmp[gcd1][c]
            else:
                gcd2 = gcd(gcd1, c)
                tmp[gcd1][c] = gcd2
            ans += n * gcd2
print(ans)
Buggy python submission (verdict: Runtime Error):
S = input()
N = len(S)
S1 = S[:(N-1)//2]
S2 = S[(N+3)//2-1:]


def isloop(S):
    i = 0
    N = len(S)
    if i == N-1-i:
        return True
    while S[i] == S[N-1-i]:
        i += 1
        if i == N-1-i:
            return True
    return False


if isloop(S) and isloop(S1) and isloop(S2):
    print("Yes")
else:
    print("No")


Fixed submission:
S = input()
N = len(S)
S1 = S[:(N-1)//2]
S2 = S[(N+3)//2-1:]


def isloop(S):
    i = 0
    N = len(S)
    if i == N-1-i:
        return True
    while S[i] == S[N-1-i]:
        i += 1
        if i == N-1-i or i == N-i:
            return True
    return False


if isloop(S) and isloop(S1) and isloop(S2):
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
S = input()
N = len(S)
S1 = S[:(N-1)//2]
S2 = S[(N+3)//2-1:]


def isloop(S):
    i = 0
    N = len(S)
    while S[i] == S[N-1-i]:
        i += 1
        if i == N-1-i:
            return True
    return False


if isloop(S) and isloop(S1) and isloop(S2):
    print("Yes")
else:
    print("No")


Fixed submission:
S = input()
N = len(S)
S1 = S[:(N-1)//2]
S2 = S[(N+3)//2-1:]


def isloop(S):
    i = 0
    N = len(S)
    if i == N-1-i:
        return True
    while S[i] == S[N-1-i]:
        i += 1
        if i == N-1-i or i == N-i:
            return True
    return False


if isloop(S) and isloop(S1) and isloop(S2):
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
a, h = map(int, input().split())
print((a+h-1)//h))


Fixed submission:
a, h = map(int, input().split())
print((a+h-1)//h)

Buggy python submission (verdict: Runtime Error):
a, h = map(int, input())
print((a+h-1)//h))


Fixed submission:
a, h = map(int, input().split())
print((a+h-1)//h)

Buggy python submission (verdict: Runtime Error):
a, h = map(int, input())
print((a+h-1)//h)

Fixed submission:
a, h = map(int, input().split())
print((a+h-1)//h)
Buggy python submission (verdict: Time Limit Exceeded):
from operator import itemgetter
import bisect
N, D, A = map(int, input().split())
enemies = sorted([list(map(int, input().split())) for i in range(N)], key=itemgetter(0))
d_enemy = [enemy[0] for enemy in enemies]
b_left = bisect.bisect_left
logs = []
ans = 0
for i, enemy in enumerate(enemies):
    X, hp = enemy
    count = 0
    for log in logs:
        start, end, log_count = log
        if start <= X <= end:
            count += log_count
    hp -= count * A
    if hp > 0:
        attack_num = (hp + A-1) // A
        logs.append((X, X+2*D, attack_num))
        ans += attack_num
print(ans)





Fixed submission:
from operator import itemgetter
import bisect
N, D, A = map(int, input().split())
enemies = sorted([list(map(int, input().split())) for i in range(N)], key=itemgetter(0))
d_enemy = [enemy[0] for enemy in enemies]
b_left = bisect.bisect_left
logs = []
logs_S = [0, ]
ans = 0
for i, enemy in enumerate(enemies):
    X, hp = enemy

    start_i = b_left(logs, X-2*D)
    count = logs_S[-1] - logs_S[start_i]

    hp -= count * A
    if hp > 0:
        attack_num = (hp + A-1) // A
        logs.append(X)
        logs_S.append(logs_S[-1]+attack_num)
        ans += attack_num
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
from math import gcd


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


input = sys.stdin.readline

N, M = map(int, input().split())
A = sorted(map(int, input().split()))
LCM = 1
count = -1
for a in A:
    if a % 2 == 1:
        print(0)
        exit()
    tmp_count = 0
    tmp = a
    while tmp % 2 == 0:
        tmp = tmp//2
        tmp_count += 1
    LCM = lcm_base(LCM, a//2)

    if count == -1:
        count = tmp_count
    if tmp_count != count:
        print(0)
        exit()
tmp = (M//LCM)
if tmp % 2 == 0:
    tmp = tmp//2
else:
    tmp = tmp//2+1
print(tmp)


Fixed submission:
import sys
from fractions import gcd


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


input = sys.stdin.readline

N, M = map(int, input().split())
A = sorted(map(int, input().split()))
LCM = 1
count = -1
for a in A:
    if a % 2 == 1:
        print(0)
        exit()
    tmp_count = 0
    tmp = a
    while tmp % 2 == 0:
        tmp = tmp//2
        tmp_count += 1
    LCM = lcm_base(LCM, a//2)

    if count == -1:
        count = tmp_count
    if tmp_count != count:
        print(0)
        exit()
tmp = (M//LCM)
if tmp % 2 == 0:
    tmp = tmp//2
else:
    tmp = tmp//2+1
print(tmp)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
def main():
    MOD = 10**9+7
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))

    count = [0] * 61

    for a in A:
        for i, c in enumerate(format(a, '061b')):
            if c == '1':
                count[i] += 1
    ans = 0
    for j, a in enumerate(A):
        for i, c in enumerate(format(a, '061b')):
            if c == '1':
                count[i] -= 1
                ans = (ans + pow(2, 60-i, MOD) * (N-1-j-count[i]))%MOD
            else:
                ans = (ans + pow(2, 60-i, MOD) * count[i])%MOD
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
import sys
def main():
    MOD = 10**9+7
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))

    count = [0] * 61
    ans = 0
    for a in A:
        for i, c in enumerate(format(a, 'b')[::-1]):
            if c == '1':
                count[i] += 1

    for i, c in enumerate(count):
        tmp = (c*(N-c) * pow(2, i, MOD))%MOD
        ans = (ans + tmp)%MOD
    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
N = input()
S = list(map(int, input()[:]))
ans = 0
for num in range(1000):
    n1,n2,n3 = 0, 0, num%10
    n2= (num %100-n3)// 10
    n1 = (num-n2*10- n3) //100
    f1 = False
    f2 = False
    f3 = False
    for n in S:
        if not f1:
            if n == n1:
                f1 = True
        elif not f2:
            if n == n2:
                f2 = True
        elif not f3:
            if n == n3:
                f3 = True
                break
    if f1 and f2 and f3:
        ans += 1
print(ans)


Fixed submission:
import copy

N = input()
S = list(map(int, input()[:]))
left = [False for i in range(10)]
right = [0 for i in range(10)]

for n in S[1:]:
    right[n] += 1
left[S[0]] = True
flag = [[[False for i in range(10)] for j in range(10)] for k in range(10)]
for n in S[1:-1]:
    right[n] -= 1
    for i, l in enumerate(left):
        if l:
            for j, r in enumerate(right):
                if r > 0:
                    flag[n][i][j] = True
    left[n] = True
count = 0
for i in flag:
    for j in i:
        for k in j:
            if k:
                count += 1
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
each_edge = [set() for i in range(N)]
ans = []
kouho = set([i+1 for i in range(N)])
for i in range(N-1):
    a, b = map(int, input().split())
    if not each_edge[a-1] and not each_edge[b-1]:
        tmp = 1
    else:
        aset = each_edge[a-1]
        bset = each_edge[b-1]
        tmp = sorted(list(kouho.difference(aset | bset)))[0]
    each_edge[a-1].add(tmp)
    each_edge[b-1].add(tmp)
    ans.append(tmp)
K = -1
for i in each_edge:
    K = max(K, len(i))
print(K)
for line in ans:
    print(line)


Fixed submission:
import sys
from collections import deque
input = sys.stdin.readline


def main():
    N = int(input().strip())
    edges = [[] for _ in range(N)]
    for i in range(N-1):
        a, b = map(int, input().strip().split())
        edges[a-1].append([b-1, i])
        edges[b-1].append([a-1, i])
    color = [-1 for i in range(N-1)]
    trgt = deque([[0, -1], ])
    while len(trgt) > 0:
        now, parent_color = trgt.pop()
        cand_color = 0
        for node, edge_num in edges[now]:
            if color[edge_num] == -1:
                cand_color += 1
                if cand_color == parent_color:
                    cand_color += 1
                color[edge_num] = cand_color
                trgt.append([node, cand_color])
    print(max(color))
    print("\n".join(map(str, color)))


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
MOD = 10**9+7

S = input()
N = len(S)
amari = [0 for _ in range(13)]


for i, s in enumerate(S):
    if i == 0:
        next_amari = [0 for _ in range(13)]
        if s != "?":
            number = int(s)
            now_amari = number * pow(10, N-1-i, 13) % 13
            next_amari[now_amari] = 1
        else:
            for number in range(10):
                now_amari = number * pow(10, N-1-i, 13) % 13
                next_amari[now_amari] += 1
        amari = next_amari
        continue

    next_amari = [0 for _ in range(13)]
    if s != "?":
        number = int(s)
        now_amari = number * pow(10, N-1-i, 13) % 13
        for j, n in enumerate(amari):
            next_amari[(j+now_amari) % 13] = n
    else:
        for number in range(10):
            now_amari = number * pow(10, N-1-i, 13) % 13
            for j, n in enumerate(amari):
                next_amari[(j+now_amari) % 13] = (n+next_amari[(j+now_amari) % 13])%MOD

    amari = next_amari
print(amari[5])


Fixed submission:
MOD = 10**9+7

S = input()
N = len(S)
amari = [0 for _ in range(13)]


for i, s in enumerate(S):
    if i == 0:
        next_amari = [0 for _ in range(13)]
        if s != "?":
            number = int(s)
            now_amari = number * pow(10, N-1-i, 13) % 13
            next_amari[now_amari] = 1
        else:
            for number in range(10):
                now_amari = number * pow(10, N-1-i, 13) % 13
                next_amari[now_amari] += 1
        amari = next_amari
        continue

    next_amari = [0 for _ in range(13)]
    if s != "?":
        number = int(s)
        now_amari = number * pow(10, N-1-i, 13) % 13
        for j, n in enumerate(amari):
            next_amari[(j+now_amari) % 13] = n
    else:
        for number in range(10):
            now_amari = number * pow(10, N-1-i, 13) % 13
            for j, n in enumerate(amari):
                next_amari[(j+now_amari) % 13] = (n+next_amari[(j+now_amari) % 13])%MOD

    amari = next_amari
print(amari[5])