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

import sys
from heapq import heappush, heappop
#input = sys.stdin.readline

def main():
    s=list(input())
    n=len(s)
    mod=10**9+7
    dp=[[0]*13 for _ in range(n)]
    if s[0]=='?':
        dp[0]=[1,1,1,1,1,1,1,1,1,1,0,0,0]
    else:
        dp[0][int(s[0])]=1
    for i in range(1,n):
        for j in range(13):
            if s[i]=='?':
                for k in range(10):
                    x=(j*10+k)%13
                    dp[i][x]+=dp[i-1][j]
                    dp[i][x]%=mod
            else:
                x=(j*10+int(s[i]))%13
                dp[i][x]+=dp[i-1][j]
                dp[i][x]%=mod
    print(dp[n-1][5])

if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
from heapq import heappush, heappop
#input = sys.stdin.readline

def main():
    s=list(input())
    n=len(s)
    mod=10**9+7
    dp=[[0]*13 for _ in range(n)]
    if s[0]=='?':
        dp[0]=[1,1,1,1,1,1,1,1,1,1,0,0,0]
    else:
        dp[0][int(s[0])]=1
    for i in range(1,n):
        for j in range(13):
            if s[i]=='?':
                for k in range(10):
                    x=(j*10+k)%13
                    dp[i][x]+=dp[i-1][j]
                    dp[i][x]%=mod
            else:
                x=(j*10+int(s[i]))%13
                dp[i][x]+=dp[i-1][j]
                dp[i][x]%=mod
    print(dp[n-1][5])

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

N,X,Y = map(int,input().split())
X -= 1
Y -= 1
aggre= [0] * (N - 1)

for i in range(N):
  for j in range(N):
    if i == j:
      continue
    dist = min(abs(j - i),abs(X - i) + abs(Y - j) + 1,abs(Y - i) + abs(X - j) + 1)
    #if dist >= N // 2:
      #print("dist i j",dist,i,j)
    aggre[dist - 1] += 1
    
#ans = [i // 2 for i in aggre]
for a in aggre:
  print(a // 2)

### FIXED CODE ###

N,X,Y = map(int,input().split())
X -= 1
Y -= 1
aggre= [0] * (N - 1)

for i in range(N):
  for j in range(N):
    if i == j:
      continue
    dist = min(abs(j - i),abs(X - i) + abs(Y - j) + 1,abs(Y - i) + abs(X - j) + 1)
    #if dist >= N // 2:
      #print("dist i j",dist,i,j)
    aggre[dist - 1] += 1
    
#ans = [i // 2 for i in aggre]
for a in aggre:
  print(a // 2)
### BUGGY CODE ###

n,x,y = map(int,input().split())
cnt_l = [0 for i in range(0,n)]

def bfs(start):
    queue = [[start,0]]
    isNotSearched = [False]*(n+1)
    
    while(len(queue)>0):
        i,cnt = queue.pop(0)
        
        if(isNotSearched[i]):
            continue
        
        isNotSearched[i]=True
        cnt_l[cnt]+=1
        pre = (i-1)
        nex = (i+1)
        if(i==x):
            queue.append([y,cnt+1])
        if(i==y):
            queue.append([x,cnt+1])
        if(pre>=1):
            queue.append([pre,cnt+1])
        if(nex<=n):
            queue.append([nex,cnt+1])
            
        

        
for i in range(1,n+1):
    bfs(i)


for i in range(1,n):
    print(cnt_l[i]//2)
    


### FIXED CODE ###

n,x,y = map(int,input().split())
cnt_l = [0]*n
from collections import deque
def bfs(start):
    queue = deque()
    queue.append(start)
    isSearched = [-1]*(n+1)
    isSearched[start] = 0
    while(len(queue)>0):
        i = queue.popleft()
        cnt = isSearched[i]
        if(i==x):
            nex_l = (i-1,y,i+1)
        elif(i==y):
            nex_l = (i-1,x,i+1)
        else:
            nex_l = (i-1,i+1)

        cnt += 1
        for j in nex_l:
            if(j < 1 or n < j):
                continue
            if(isSearched[j]!=-1):
                continue
            queue.append(j)
            isSearched[j] = cnt
            cnt_l[cnt] += 1
            
        
 
        
for i in range(1,n+1):
    bfs(i)
 
 
for i in range(1,n):
    print(cnt_l[i]//2)
### BUGGY CODE ###

#!/mnt/c/Users/moiki/bash/env/bin/python
N,M = list(map(int, input().split()))
P =[]
Y = []
for i in range(M):
    P.append(0)
    Y.append(0)
    P[i], Y[i] = list(map(int, input().split()))

dic = {}
for i in range(M):
    dic[P[i]] = [Y[i]] if not P[i] in dic else dic[P[i]] + [Y[i]]

# print(dic)
import numpy as np
for i in range(M):
    num = sorted(dic[P[i]]).index(Y[i]) + 1
    print("{0:06d}{1:06d}".format(P[i], num))

### FIXED CODE ###

#!/mnt/c/Users/moiki/bash/env/bin/python
N,M = list(map(int, input().split()))
P =[]
Y = []
yp = [(0,0,0)] * M
for i in range(M):
    P.append(0)
    Y.append(0)
    P[i], Y[i] = list(map(int, input().split()))
    yp[i] = (Y[i], P[i], i)

yp.sort()
dic = {}
# for i in range(M):
#     dic[P[i]] = [Y[i]] if not P[i] in dic else dic[P[i]] + [Y[i]]
#     dic[P[i]] = sorted(dic[P[i]])

# print(yp)
pre = [0] * (N+1)
ansnum = [0] * M
for (y,p,i) in yp:
    pre[p] += 1
    ansnum[i] = "{0:06d}{1:06d}".format(p, pre[p])

import numpy as np
for i in range(M):
    print(ansnum[i])
    # num = yp[]
    # num = dic[P[i]].index(Y[i]) + 1
    # print("{0:06d}{1:06d}".format(P[i], num))
### BUGGY CODE ###

import sys
n, W = map(int, sys.stdin.readline().split())
L = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]

dp = [[0 for _ in range(W+1)] for _ in range(n)]
for w in range(W+1):
    if w>=L[0][0]:
        dp[0][w] = L[0][1]

#print(dp)
for i in range(1, n):
    for w in range(W+1):
        if w <L[i][0]: #そもそも加えられないとき
            dp[i][w] = dp[i-1][w] #前回の状態を代入。
        else: #加えようとしたら入るとき
            dp[i][w] = max(dp[i-1][w-L[i][0]] + L[i][1], dp[i-1][w]) #max(加えた時の価値, 前回の状態)
            
#print(dp)
print(max(dp[-1]))

### FIXED CODE ###

import sys
n, W = map(int, sys.stdin.readline().split())
L = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]

dp = [[0 for _ in range(W+1)] for _ in range(n)]
for w in range(W+1):
    if w>=L[0][0]:
        dp[0][w] = L[0][1]

#print(dp)
for i in range(1, n):
    for w in range(W+1):
        if w <L[i][0]: #そもそも加えられないとき
            dp[i][w] = dp[i-1][w] #前回の状態を代入。
        else: #加えようとしたら入るとき
            dp[i][w] = max(dp[i-1][w-L[i][0]] + L[i][1], dp[i-1][w]) #max(加えた時の価値, 前回の状態)
            
#print(dp)
print(max(dp[-1]))
### BUGGY CODE ###

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

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

A, B = zip(*AB)

dp = [-1 for _ in range(H+max(A))]
dp[0] = 0

for i in range(H):
	if dp[i] == -1:
		continue
	for j in range(len(A)):
		if dp[i+A[j]] == -1:
			dp[i+A[j]] = dp[i]+B[j]
		else:
			dp[i+A[j]] = min(dp[i+A[j]], dp[i]+B[j])
			
print(min([n for n in dp[H:] if n > 0]))

### FIXED CODE ###

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

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

A, B = zip(*AB)

dp = [-1 for _ in range(H+max(A))]
dp[0] = 0

for i in range(H):
    if dp[i] == -1:
        continue
    for j in range(N):
        k = min(i+A[j], H)
        if dp[k] == -1:
            dp[k] = dp[i]+B[j]
        else:
            dp[k] = min(dp[k], dp[i]+B[j])

print(dp[H])
### BUGGY CODE ###

#dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys;input = sys.stdin.readline
inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]

h,w,m = ip()
y = [0]*h
x = [0]*w
dt = {}
for i in range(m):
    a,b = ip()
    y[a-1] += 1
    x[b-1] += 1
    dt[(a-1,b-1)] = 1
ans = 0
for i in range(h):
    for j in range(w):
        if dt.get((i,j),0):
            ans = max(ans,y[i]+x[j]-1)
        else:
            ans = max(ans,y[i]+x[j])
print(ans)


### FIXED CODE ###

#dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys;input = sys.stdin.readline
inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]

h,w,m = ip()
y = [0]*h
x = [0]*w
dt = {}
for i in range(m):
    a,b = ip()
    y[a-1] += 1
    x[b-1] += 1
    dt[(a-1,b-1)] = 1
ans = 0
mx = max(x)
my = max(y)
xx = [i for i in range(w) if x[i] == mx]
yy = [i for i in range(h) if y[i] == my]
#print(x,y,xx,yy)
for i in xx:
    for j in yy:
        if dt.get((j,i),0):
            ans = max(ans,x[i]+y[j]-1)
        else:
            ans = max(ans,x[i]+y[j])
        if ans == mx+my:
            break
print(ans)
### BUGGY CODE ###

import bisect

h, w = map(int, input().split())
s = [list(input()) for i in range(h)]
dh = {}
for i in range(h):
    dh[i] = []
    for j in range(w):
        if s[i][j] == "#":
            dh[i].append(j)
dw = {}
for i in range(w):
    dw[i] = []
    for j in range(h):
        if s[j][i] == "#":
            dw[i].append(j)
ans = 0
for i in range(h):
    a = dh[i]
    for j in range(w):
        if s[i][j] == "#":
            continue
        b = dw[j]
        c = bisect.bisect_left(a, j)
        if not a:
            wl = w
        else:
            if c == 0:
                wl = a[0]
            elif c == len(a):
                wl = w - a[-1] - 1
            else:
                wl = a[c] - a[c - 1] - 1
        d = bisect.bisect_left(b, i)
        if not b:
            hl = h
        else:
            if d == 0:
                hl = b[0]
            elif d == len(b):
                hl = h - b[-1] - 1
            else:
                hl = b[d] - b[d - 1] - 1
        ans = max(ans, wl + hl - 1)
print(ans)

### FIXED CODE ###

h, w = map(int, input().split())
s = [list(input()) for i in range(h)]
hc = [[0] * w for i in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            if j > 0:
                hc[i][j] = hc[i][j - 1] + 1
            else:
                hc[i][j] = 1
for i in range(h):
    for j in range(w - 1, -1, -1):
        if s[i][j] == ".":
            if j < w - 1:
                if hc[i][j] < hc[i][j + 1]:
                    hc[i][j] = hc[i][j + 1]
wc = [[0] * h for i in range(w)]
for i in range(w):
    for j in range(h):
        if s[j][i] == ".":
            if j > 0:
                wc[i][j] = wc[i][j - 1] + 1
            else:
                wc[i][j] = 1
for i in range(w):
    for j in range(h - 1, -1, -1):
        if s[j][i] == ".":
            if j < h - 1:
                if wc[i][j] < wc[i][j + 1]:
                    wc[i][j] = wc[i][j + 1]
ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, hc[i][j] + wc[j][i] - 1)
print(ans)
### BUGGY CODE ###

n = int(input())
l = [int(x) for x in input().split()]
def motomeru(i):
  m = l.count(i)
  return int(m*(m-1)/2)
def herasu(i):
  m = l.count(i)-1
  return int(m*(m-1)/2)
zenbu = 0
for i in range(n):
  zenbu = zenbu + motomeru(i+1)
for i in range(n):
  a = zenbu - motomeru(l[i]) + herasu(l[i])
  print(a)

### FIXED CODE ###

n = int(input())
l = [int(x) for x in input().split()]
k = [0]*n
for i in range(n):
  k[l[i] - 1] = k[l[i] - 1] + 1
def motomeru(i):
  return int((k[i-1])*(k[i-1]-1)/2)
def herasu(i):
  if k[i-1] == 0 or k[i-1] == 1:
    return 0
  else:
    return int((k[i-1]-1)*(k[i-1]-2)/2)
zenbu = 0
for i in range(n):
  zenbu = zenbu + motomeru(i+1)
for i in range(n):
  a = zenbu - motomeru(l[i]) + herasu(l[i])
  print(a)
### BUGGY CODE ###


N, A,B = map(int, input().split())
str = []
for j in range(N//(A+B)+1):
    for i in range(A):
        if len(str)==N+1:
            break
        str.append('b')

    for i in range(B):
        if len(str)==N+1:
            break
        str.append('r')
    if len(str)==N+1:
        break

count = 0
for k in range(N):
    if str[k] == 'b':
        count+=1
print(count)


### FIXED CODE ###

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

count = N//(A+B)
if (N-count*(A+B))>A:
    print(count*A+A)
else:
    print(count*A+(N-count*(A+B)))
### BUGGY CODE ###

import numpy as np

n,m = map(int,input().split())
list_a = list(map(int,input().split()))
#b_list = list(map(int,input().split()))
#print(" ".join(map(str,c_list)))

for i in range(m):
    a = np.argmax(list_a)
    list_a[a] = list_a[a] // 2
    """
    if list_a[0] % 2 != 0:
        list_a[0] = list_a[0] // 2 - 1
    else:
        list_a[0] = list_a[0] // 2
    """
print(sum(list_a))

### FIXED CODE ###

import sys
n,m = map(int,input().split())
lst_a = list(map(int,input().split()))
temp = 0
cnt = 0
fin = 0
loop = 0
debug = 0
temp2 = 0
if n == 1:
    for i in range(m):
        lst_a[0] //= 2
    print(lst_a[0])
    sys.exit()
while debug < 10:
    loop = 0
    #temp2 = temp
    temp = 0
    lst_a.sort(reverse=True)
    while loop < n-1:
        lst_a[loop] //= 2
        cnt += 1
        temp = max(temp,lst_a[loop])
        if cnt == m:
            #print(lst_a)
            print(sum(lst_a))
            sys.exit()
        if temp > max(lst_a[loop],lst_a[loop + 1]):
            break
        if lst_a[loop + 1] > lst_a[loop]:
            loop += 1
        
        
        
"""        if lst_a[loop] >= max(lst_a[loop + 1],temp):
            lst_a[loop] //= 2
            temp = max(lst_a[loop],lst_a[loop+1])
            cnt += 1
            if cnt == m:
                print(sum(lst_a))
                sys.exit()
            if temp > lst_a[loop + 1]:
                break
            
            
        loop += 1
    
    #debug += 1
print(lst_a[99999])
# print(temp)
# print(cnt)
# print(lst_a)
# print(sum(lst_a))
"""
### BUGGY CODE ###

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

for i in range(N):
    X = A[0:i] + A[i+1:]
    MAX = max(X)
    print(MAX)

### FIXED CODE ###

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

B = A[:]

a1 = max(A)
A.remove(a1)
a2 = max(A)

for i in range(N):
    if B[i] != a1:
        print(a1)
    else:
        print(a2)
### BUGGY CODE ###

import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from collections import defaultdict, Counter

    n = int(readline())
    mat = [list(map(int, readline().split())) for _ in range(n)]

    edge = defaultdict(list)
    count = Counter()

    for x in range(1, n + 1):
        for j in range(n - 2):
            y = mat[x - 1][j]
            z = mat[x - 1][j + 1]
            uf, us = min(x, y), max(x, y)
            vf, vs = min(x, z), max(x, z)
            edge[(uf, us)].append((vf, vs))
            count[(uf, us)] += 0
            count[(vf, vs)] += 1

    ans = 0
    rem = n * (n - 1) // 2
    while rem:
        ans += 1
        today = [key for key, val in count.items() if val == 0]
        if not today:
            print(-1)
            return
        for cur_match in today:
            for nx_match in edge[cur_match]:
                count[nx_match] -= 1
            rem -= 1
            count[cur_match] = -1

    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    def calc_id(x, y):
        return min(x, y) * 10007 + max(x, y)

    from collections import defaultdict, Counter, deque
    from copy import copy

    n = int(readline())

    edge = defaultdict(list)
    count = Counter()

    for x in range(1, n + 1):
        a = list(map(int, readline().split()))
        count[calc_id(x, a[0])] += 0
        for j in range(n - 2):
            y = a[j]
            z = a[j + 1]
            u_id = calc_id(x, y)
            v_id = calc_id(x, z)
            edge[u_id].append(v_id)
            count[v_id] += 1

    ans = 0
    rem = n * (n - 1) // 2
    que = deque()
    for key, val in count.items():
        if val == 0:
            que.append(key)
    que_tomorrow = deque()

    while rem:
        ans += 1
        if not que:
            print(-1)
            return
        while que:
            cur_match = que.popleft()
            for nx_match in edge[cur_match]:
                count[nx_match] -= 1
                if count[nx_match] == 0:
                    que_tomorrow.append(nx_match)
            rem -= 1
        que = copy(que_tomorrow)
        que_tomorrow.clear()

    print(ans)


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

string=list(input())
Q=int(input())
def func1(s):
    s.reverse()
    
def func2(s,F,C):
    if F=="1":
        s.insert(0,C)
        #return s
    if F=="2":
        s.append(C)
        #return s

            
for i in range(Q):
    Input=list(map(str,input().split()))
    if Input[0]=='1':
        func1(string)
        
    elif Input[0]=='2':
        func2(string,Input[1],Input[2])
for i in string:
    print(i,end="")

### FIXED CODE ###

S = str(input())
Q = int(input())
 
hanten = 0
front = ""
end = ""
 
for i in range(Q):
    query=list(map(str,input().split()))
    if query[0]=="1":
        hanten+=1
        hanten=hanten%2
    else:
        if query[1]=="1":
            if hanten==0:
                front=query[2]+front
            else:
                end=end+query[2]
        else:
            if hanten==0:
                end=end+query[2]
            else:
                front=query[2]+front
ans=front+S+end
if hanten==1:
    ans=ans[::-1]
print(ans)
### BUGGY CODE ###

import itertools

n, m, R = [int(i) for i in input().split()]
r = [int(i) - 1 for i in input().split()]
dis = [[float("inf") for _ in range(n)] for _ in range(n)]
for i in range(m):
    a, b, c = [int(i) for i in input().split()]
    dis[a - 1][b - 1] = c
    dis[b - 1][a - 1] = c

# 全ての頂点間の最短距離を算出、
for k in range(n):
    for i in range(n):
        for j in range(n):
            if dis[i][j] > dis[i][k] + dis[k][j]:
                dis[i][j] = dis[i][k] + dis[k][j]


_min = float("inf")
it = itertools.permutations(r)
for iterR in it:
    _dis = 0
    start = iterR[0]
    for end in iterR[1:]:
        _dis += dis[start][end]
        start = end
    _min = min(_min, _dis)
print(_min)

"""
print("2 vs "+func(3, 3, [0, 1, 2], [[0, 1, 4], [1, 0, 1], [4, 1, 0]]))
print("4 vs "+func(3, 3, [0, 2], [[0, 2, 6], [2, 0, 2], [6, 2, 0]]))
print("3 vs "+func(4, 6, [1, 2, 3], [[0, 4, 6, 1], [4, 0, 3, 2], [6, 3, 0, 1], [1, 2, 1, 0]]))
# print("print(func({}, {}, {}, {}))".format(n, m, r, adj))
"""


### FIXED CODE ###

import itertools
n, m, R = map(int, input().split())
r = list(map(int, input().split()))
dis = [[float("inf") for _ in range(n)] for _ in range(n)]
for _ in range(m):
    a, b, c = map(int, input().split())
    dis[a - 1][b - 1] = c
    dis[b - 1][a - 1] = c

def war(dis):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if dis[i][j] > dis[i][k] + dis[k][j]:
                    dis[i][j] = dis[i][k] + dis[k][j]
    return dis
dis = war(dis)
_min = float("inf")
it = itertools.permutations(r)
for iterR in it:
    _dis = 0
    start = iterR[0] - 1
    for end in iterR[1:]:
        _dis += dis[start][end - 1]
        start = end - 1
    _min = min(_min, _dis)
print(_min)
### BUGGY CODE ###

n = int(input())
s = list(input())
Count = n
for i in range(n):
    f = s[:i]
    r = s[(i+1):]
    count = f.count("W")+r.count("E")
    if Count > count:
        Count = count
print(Count)
    

### FIXED CODE ###

n = int(input())
s = list(input())
left_w = 0
right_e = s[1:].count("E")
ans = right_e
for i in range(1,n):
    if s[i-1] == "W":
        left_w += 1
    if s[i] == "E":
        right_e -= 1
    ans = min(ans,right_e +left_w)
print(ans)
### BUGGY CODE ###

def judge(x, y, z):
  if y-x != z-y and y>x and z>y:
    return 1
  
  return 0


N = int(input())
S = input()

count = 0

for i in range(0, N-2):
  for j in range(i+1, N-1):
    for k in range(j+1, N):
      if S[i]=='R' and S[j]=='G' and S[k]=='B':
        count += judge(i, j, k)
      elif S[i]=='R' and S[j]=='B' and S[k]=='G':
        count += judge(i, j, k)
      elif S[i]=='G' and S[j]=='R' and S[k]=='B':
        count += judge(i, j, k)
      elif S[i]=='G' and S[j]=='B' and S[k]=='R':
        count += judge(i, j, k)
      elif S[i]=='B' and S[j]=='R' and S[k]=='G':
        count += judge(i, j, k)
      elif S[i]=='B' and S[j]=='G' and S[k]=='R':
        count += judge(i, j, k)        
        
print(count)

### FIXED CODE ###

def func1(x, y, z, a):
  if x == y:
    z.append(a)
    return 1 
  return 0

def func2(x, y):
  if x==y:
    return 1
  return 0

def func3(x, y, z, a):
  l = 0
  for i in x:
    for j in y:
      k = 2 * j - i
      if k <= N-1 and i < j:
        l += func2(z[k], a)
  return l

  
N = int(input())
S = input()
r, g, b, rgb, equal = 0, 0, 0, 0, 0
r0, g0, b0 = [], [], []

for i in range(N):
  r += func1(S[i], 'R', r0, i)
  g += func1(S[i], 'G', g0, i)
  b += func1(S[i], 'B', b0, i)

rgb = r * g * b

# R<G<B
equal += func3(r0, g0, S, 'B')
# R<B<G
equal += func3(r0, b0, S, 'G')
# G<R<B
equal += func3(g0, r0, S, 'B')
# G<B<R
equal += func3(g0, b0, S, 'R')
# B<R<G
equal += func3(b0, r0, S, 'G')
# B<G<R
equal += func3(b0, g0, S, 'R')

print(rgb - equal)
### BUGGY CODE ###

a, b = map(int, input().split(' '))

def cf(x1,x2):
    cf=[]
    for i in range(2,min(x1,x2)+1):
        if x1 % i == 0 and x2 % i == 0:
            cf.append(i)
    return cf

k = cf(a, b)

ans = 0
if len(k) == 0:
  ans = 1
elif len(k) == 1:
  ans = 2
else:
  ans = 2
  for i in range(1, len(k)):
    tmp = k[i]
    for j in range(0, i):
      if (tmp % k[j]) == 0:
        break
    else:
      ans += 1

print(ans)

### FIXED CODE ###

a, b = map(int, input().split(' '))
 
def divisor(n):
  ass = []
  for i in range(1,int(n**0.5)+1):
    if n%i == 0:
      ass.append(i)
      ass.append(n//i)
  return ass #sortされていない
 
a_div = divisor(a)
b_div = divisor(b)

k = []
for val in a_div:
  if val != 1 and val in b_div:
    k.append(val)
k.sort()

ans = 0
if len(k) == 0:
  ans = 1
elif len(k) == 1:
  ans = 2
else:
  ans = 2
  for i in range(1, len(k)):
    tmp = k[i]
    for j in range(0, i):
      if (tmp % k[j]) == 0:
        break
    else:
      ans += 1
 
print(ans)
### BUGGY CODE ###

n = int(input())
S = input().split()
q = int(input())
T = input().split()
cnt = 0
for i in range(q):
    if T[i] in S:
        cnt += 1
print(cnt)

### FIXED CODE ###

n = int(input())
S = [int(i) for i in input().split()]
q = int(input())
T = [int(i) for i in input().split()]

cnt = 0
for t in T:
    low = 0
    high = len(S) - 1
    while low <= high:
        mid = (low + high) // 2
        if t == S[mid]:
            cnt += 1
            break
        elif t < S[mid]:
            high = mid - 1
        else:
            low = mid + 1
print(cnt)
### BUGGY CODE ###

import numpy as np
kn = list(map(int,input().split()))
K = kn[0]
N = kn[1]
As = list(map(int,input().split()))

subtract_list_r = np.array([])
subtract_list_l = np.array([])
#subtract_list = np.append(subtract_list,As[0]-As[N-1])
subtract_value_r = 0
subtract_value_l = 0
for i in range(1,N-1):
    subtract_value_r = K-(As[i]-As[i-1])
    subtract_value_l = K-(As[i+1]-As[i])
    subtract_list_r = np.append(subtract_list_r,subtract_value_r)
    subtract_list_l = np.append(subtract_list_l,subtract_value_l)


subtract_list_r = np.append(subtract_list_r,As[N-1]-As[0])
subtract_list_l = np.append(subtract_list_l,K-(As[1]-As[0]))
subtract_list_r = np.append(subtract_list_r,K-(As[N-1]-As[N-2]))
subtract_list_l = np.append(subtract_list_l,abs(As[0]-As[N-1]))
r_min = min(subtract_list_r)
l_min = min(subtract_list_l)

print("{}".format(int(min([r_min,l_min]))))


### FIXED CODE ###

import numpy as np
kn = list(map(int,input().split()))
K = kn[0]
N = kn[1]
As = list(map(int,input().split()))

subtract_list_r = np.array([])
subtract_list_l = np.array([])
subtract_list_r = list(subtract_list_r)
subtract_list_l = list(subtract_list_l)

subtract_value_r = 0
subtract_value_l = 0
for i in range(1,N-1):
    subtract_value_r = K-(As[i]-As[i-1])
    subtract_value_l = K-(As[i+1]-As[i])
    subtract_list_r.append(subtract_value_r)
    subtract_list_l.append(subtract_value_l)


subtract_list_r.append(As[N-1]-As[0])
subtract_list_l.append(K-(As[1]-As[0]))
subtract_list_r.append(K-(As[N-1]-As[N-2]))
subtract_list_l.append(abs(As[0]-As[N-1]))
r_min = min(subtract_list_r)
l_min = min(subtract_list_l)

print("{}".format(int(min([r_min,l_min]))))