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

from copy import deepcopy

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

scores = [0] * (D + 1)
lasts = [[0] * 26 for _ in range(D + 1)]

def change(d, q):
    global scores, lasts, T
    T[d - 1] = q
    score = scores[d - 1]
    last = deepcopy(lasts[d - 1])
    for day, t in enumerate(T[d - 1:], d):
        score += S[day - 1][t - 1]
        last[t - 1] = day
        lasts[day] = deepcopy(last)
        for c, l in zip(C, last): score -= c * (day - l)
        scores[day] = score
    return scores[-1]

def init():
    change(1, T[0])
    return

M = int(input())
init()
for _ in range(M):
    d, q = map(int, input().split())
    print(change(d, q))

### FIXED CODE ###

from bisect import bisect_left

D = int(input())
*C, = map(int, input().split())
S = [list(map(int, input().split())) for _ in range(D)]
T = [int(input()) for _ in range(D)]
days = [[0] for _ in range(26)]

def init():
    global T, days
    score = 0
    last = [0] * 26
    for d, t in enumerate(T, 1):
        score += S[d - 1][t - 1]
        last[t - 1] = d
        for c, l in zip(C, last): score -= c * (d - l)
        days[t - 1].append(d)
    for i in range(26): days[i].append(D+1)
    return score

def diff(d, q):
    global score, T, C, S, days
    p = T[d - 1]
    score += S[d - 1][q - 1] - S[d - 1][p - 1]
    idx_p = bisect_left(days[p - 1], d)
    bef_p, aft_p = days[p - 1][idx_p - 1], days[p - 1][idx_p + 1]
    del days[p - 1][idx_p]
    idx_q = bisect_left(days[q - 1], d)
    bef_q, aft_q = days[q - 1][idx_q - 1], days[q - 1][idx_q]
    days[q - 1].insert(idx_q, d)
    score += C[q - 1] * (d - bef_q) * (aft_q - d) - C[p - 1] * (d - bef_p) * (aft_p - d)
    T[d - 1] = q
    return score
    
score = init()
M = int(input())
for _ in range(M):
    d, q = map(int, input().split())
    print(diff(d, q))
### BUGGY CODE ###

from collections import deque
import sys
import copy

def main():
  input = sys.stdin.readline
  n = int(input())
  a = [None]*n
  for i in range(n):
    a[i] = [int(x)-1 for x in input().split()]
  
  count = 0
  ans = 0
  bef_checked = [int(x) for x in range(n)]
  index = [0]*n
  while True:
    ans += 1
    check = copy.deepcopy(bef_checked)
    bef_checked = []
    already = [False]*n
    flag = True
    for v in check:
      if already[v]:
        continue
      flag = False
      v2 = a[v][index[v]]
      if already[v2]:
        continue
      if v != a[v2][index[v2]]:
        continue
      already[v] = True
      already[v2] = True
      index[v] += 1
      index[v2] += 1
      if index[v] == n-1:
        count += 1
      else:
        bef_checked.append(v)
      if index[v2] == n-1:
        count += 1
      else:
        bef_checked.append(v2)
        
    if flag:
      print(-1)
      sys.exit()
    if count == n:
      break
  
  print(ans)
  

if __name__ == "__main__":
  main()


### FIXED CODE ###

import sys
from copy import deepcopy as copy

def main():
    input = sys.stdin.readline
    n = int(input())
    a = [None]*n
    for i in range(n):
        a[i] = [int(x)-1 for x in input().split()]
    
    index = [0]*n
    search = [int(x) for x in range(n)]
    ans = 0
    while True:
        already = set()
        judge = True
        sub = []
        for key in search:
            if index[key] == n-1:
                continue
            key2 = a[key][index[key]]
            if index[key2] == n-1:
                continue
            if key != a[key2][index[key2]]:
                continue
            if key in already or key2 in already:
                continue
            already.add(key)
            already.add(key2)
            index[key] += 1
            index[key2] += 1
            sub.append(key)
            sub.append(key2)
            judge = False
        if judge:
            break
        ans += 1
        search = copy(sub)
        
    for value in index:
        if value != n-1:
            print(-1)
            sys.exit()
    print(ans)
    
if __name__ == "__main__":
    main()
### BUGGY CODE ###

n = int(input())
s = [input() for i in range(n)]

tango = []
count = 0
for i in s:
  if i not in tango:
    count += 1
    tango.append(i)
print(count)
  

### FIXED CODE ###

n = int(input())
s = [input() for i in range(n)]

print(len(list(set(s))))
### BUGGY CODE ###

import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))
'''
for i in range(n):
    p = a[:i] + a[i+1:]
    ans = 0
    for j in range(1,len(p)):
        ans += abs(p[j-1] - p[j])
    ans += abs(p[0]) + abs(p[-1])
    print(ans)
'''
abs1 = []
for i in range(1,n):
    abs1.append(abs(a[i-1]-a[i]))

abs2 = []
for i in range(2,n):
    abs2.append(abs(a[i-2]-a[i]))
#print(abs1)
for i in range(n):
    p = a[:i] + a[i+1:]
    if i == 0:
        print(sum(abs1[1:]) + abs(p[0]) + abs(p[-1]))
    elif i == n-1:#
        #print(abs1[:n-2],abs(p[0]),abs(p[-1]))
        print(sum(abs1[:n-2]) + abs(p[0]) + abs(p[-1]))
    else:
        print(abs(p[0]) + abs(p[-1]) + sum(abs1[:i-1] + abs1[i+1:]) + abs2[i-1])

    




### FIXED CODE ###

import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))

abs1 = [0]*(n-1)
abs1_sum = 0
for i in range(1,n):
    abs1[i-1] = abs(a[i-1]-a[i])
    abs1_sum += abs(a[i-1]-a[i])


abs2 = [0]*(n-2)
for i in range(2,n):
    abs2[i-2] = abs(a[i-2]-a[i])
#print(abs1)

b_0 = abs(a[0])
b_1 = abs(a[1])
b_n1 = abs(a[n-1])
b_n2 = abs(a[n-2])
ans = []
for i in range(n):
    if i == 0:
        ans.append(abs1_sum - abs1[0] + b_1 + b_n1)
    elif i == n-1:#
        #print(abs1[:n-2],abs(p[0]),abs(p[-1]))
        ans.append(abs1_sum - abs1[-1] + b_0 + b_n2)
    else:
        ans.append(b_0 + b_n1 + abs1_sum - abs1[i] - abs1[i-1] + abs2[i-1])

for i in range(n):
    print(ans[i])
### BUGGY CODE ###

s = list(map(int,list(input())))

l = [0 for i in range(2019)]
n = len(s)
l[0] = 1
prev = 0
for i in range(n-1,-1,-1):
    a = s[i]
    t = prev + a*10**(n-i-1)
    tmod = t % 2019
    l[tmod] += 1
    prev = tmod

res = 0
for i in l:
    res += i * (i-1) // 2

print(res)

### FIXED CODE ###

s = input()
s = s[::-1]

l = [0 for i in range(2019)]
n = len(s)
l[0] = 1
prev = 0
digit = 1
for c in s:
    t = (int(c) * digit + prev) % 2019
    l[t] += 1
    digit = (digit * 10) % 2019
    prev = t

res = 0
for i in l:
    res += i * (i-1) // 2

print(res)
### BUGGY CODE ###

n = int(input())
S = input()

S = list(S)

ans = 0
S12 = []
for i in range(n-2):
    for j in range(i+1, n-1):
        if len(S12) == 100:
            break
        if S[i]+S[j] not in S12:
            S12.append(S[i]+S[j])
            ans += len(set(S[j+1:]))

print(ans)


### FIXED CODE ###

n = int(input())
S = input()

ans = 0
for i in range(1000):
    a = '{0:03d}'.format(i)
    if a[0] in S:
        idx1 = S.index(a[0])
        S1 = S[idx1+1:]
        if a[1] in S1:
            idx2 = S1.index(a[1])
            S2 = S1[idx2+1:]
            if a[2] in S2:
                ans += 1

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

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

area = []
for i in range(K):
    L, R = map(int, input().split())
    area.append((L, R))


d = [0] * N


def func(pos):
    for a in area:
        for i in range(a[0], a[1]+1):
            if pos - i > -1:
                d[pos-i] += d[pos]


d[N-1] = 1
for i in range(N-1, -1, -1):
    if d[i] > 0:
        func(i)

print(d[0] % 998244353)


### FIXED CODE ###

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

area = []
for i in range(K):
    L, R = map(int, input().split())
    area.append((L, R))

area.sort()
d = [0] * N
a = [0] * N


def func(pos):
    for l, r in area:
        if pos + l - 1 < N:
            a[pos + l-1] += d[pos]
        if pos + r < N:
            a[pos + r] -= d[pos]
    d[pos+1] = (d[pos] + a[pos]) % 998244353


d[0] = 1
a[0] = -1
for i in range(0, N-1):
    func(i)

print(d[N-1] % 998244353)
### BUGGY CODE ###

from sys import stdin
s = str(stdin.readline().rstrip())
q = int(stdin.readline().rstrip())
for i in range(q):
    query = input()
    if len(query)==1:
        #反転
        pass
        s = s[::-1]
    else:
        if int(query[2])==2:
            s += query[4]
        else:
            s = query[4] + s

print(s)


### FIXED CODE ###

from sys import stdin
s = str(stdin.readline().rstrip())
#A, B, C = map(int, stdin.readline().rstrip().split())
#S = [list(map(int, stdin.readline().rstrip().split())) for _ in range(h)]#hの定義を忘れずに
q= int(stdin.readline().rstrip())
hanten = 0
t=""
u=""

for i in range(q):
    l = list(map(str, stdin.readline().rstrip().split()))
    if int(l[0]) == 1:
        t,u = u,t
        hanten ^= 1
    else:
        if int(l[1])==1:
            t+=l[2]
        else:
            u+=l[2]


if hanten==0:
    print(t[::-1]+s+u)
else:
    print(t[::-1]+s[::-1]+u)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))

abs1 = [0]*(n-1)
abs1_sum = 0
for i in range(1,n):
    abs1[i-1] = abs(a[i-1]-a[i])
    abs1_sum += abs(a[i-1]-a[i])


abs2 = [0]*(n-2)
for i in range(2,n):
    abs2[i-2] = abs(a[i-2]-a[i])
#print(abs1)

b_0 = abs(a[0])
b_1 = abs(a[1])
b_n1 = abs(a[n-1])
b_n2 = abs(a[n-2])

for i in range(n):
    p = a[:i] + a[i+1:]
    if i == 0:
        print(abs1_sum - abs1[0] + b_1 + b_n1)
    elif i == n-1:#
        #print(abs1[:n-2],abs(p[0]),abs(p[-1]))
        print(abs1_sum - abs1[-1] + b_0 + b_n2)
    else:
        print(b_0 + b_n1 + abs1_sum - abs1[i] - abs1[i-1] + abs2[i-1])

    




### FIXED CODE ###

import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))

abs1 = [0]*(n-1)
abs1_sum = 0
for i in range(1,n):
    abs1[i-1] = abs(a[i-1]-a[i])
    abs1_sum += abs(a[i-1]-a[i])


abs2 = [0]*(n-2)
for i in range(2,n):
    abs2[i-2] = abs(a[i-2]-a[i])
#print(abs1)

b_0 = abs(a[0])
b_1 = abs(a[1])
b_n1 = abs(a[n-1])
b_n2 = abs(a[n-2])
ans = []
for i in range(n):
    if i == 0:
        ans.append(abs1_sum - abs1[0] + b_1 + b_n1)
    elif i == n-1:#
        #print(abs1[:n-2],abs(p[0]),abs(p[-1]))
        ans.append(abs1_sum - abs1[-1] + b_0 + b_n2)
    else:
        ans.append(b_0 + b_n1 + abs1_sum - abs1[i] - abs1[i-1] + abs2[i-1])

for i in range(n):
    print(ans[i])
### BUGGY CODE ###

N,K = map(int,input().split())
note = [list(map(int,input().split())) for i in range(N)]
note = sorted(note,key=lambda x:(x[0],-x[1]))
cnt = 0
head = []
remain = []
for i in range(N):
    if note[i][0] > cnt:
        cnt = note[i][0]
        head.append(note[i][1])
    else:
        remain.append(note[i][1])
head = sorted(head,reverse = True)
remain = sorted(remain,reverse = True)
ans = 0
for i in range(max(1,K-len(remain)),min(K,len(head))+1):
    deli = sum(head[:i]) + sum(remain[:K-i])
    kind = i**2
    res = deli + kind
    if res > ans:
        ans = res
print(ans)

### FIXED CODE ###

N,K = map(int,input().split())
note = [list(map(int,input().split())) for i in range(N)]
note = sorted(note,key=lambda x:(x[0],-x[1]))
cnt = 0
head = []
remain = []
for i in range(N):
    if note[i][0] > cnt:
        cnt = note[i][0]
        head.append(note[i][1])
    else:
        remain.append(note[i][1])
head = sorted(head,reverse = True)
remain = sorted(remain,reverse = True)
ans = 0
acc_head = [0]
acc_remain = [0]
tmp_head = 0
tmp_remain = 0
for i in range(len(head)):
    tmp_head += head[i]
    acc_head.append(tmp_head)
for i in range(len(remain)):
    tmp_remain += remain[i]
    acc_remain.append(tmp_remain)
for i in range(max(0,K-len(remain)),min(K,len(head))+1):
    deli = acc_head[i] + acc_remain[K-i]
    kind = i**2
    res = deli + kind
    if res > ans:
        ans = res
print(ans)
### BUGGY CODE ###

from collections import deque

N = int(input())
AB = [list(map(int, input().split())) for _ in range(N-1)]
con = [set() for _ in range(N+1)]
res = {}

for ab in AB:
    con[ab[0]].add(ab[1])
    con[ab[1]].add(ab[0])
    res[tuple(ab)] = 0

max_len = 0
for i, c in enumerate(con):
    if max_len <= len(c):
        max_len = len(c)
        max_ind = i

colors = [set() for i in range(N+1)]
all_colors = set([i for i in range(1, max_len+1)])
q = deque()
q.append(max_ind)
node_state = [0]*(N+1)

while q != deque():
    v = q.pop()
    node_state[v] = 1
    for next_v in con[v]:
        if node_state[next_v] == 0:
            q.appendleft(next_v)
        if v < next_v:
            va = v
            vb = next_v
        else:
            va = next_v
            vb = v
        if res[(va, vb)] == 0:
            color = list(all_colors.difference(colors[va].union(colors[vb])))[0]
            res[(va, vb)] = color
            colors[va].add(color)
            colors[vb].add(color)

print(max_len)
for i in range(N-1):
    print(res[tuple(AB[i])])

### FIXED CODE ###

N = int(input())
AB = [list(map(int, input().split())) for _ in range(N-1)]
sortedAB = sorted(AB)
con = {i: [] for i in range(1, N+1)}
color = [0] * (N + 1)
for a, b in sortedAB:
    con[a].append(b)

for i in range(1, N + 1):
    now_c = 1
    for c in con[i]:
        if color[i] == now_c:
            now_c += 1
        color[c] = now_c
        now_c += 1

print(max(color))
for i in range(N-1):
    print(color[AB[i][1]])

a = 0
### BUGGY CODE ###

n = int(input())
a_list = list(map(int, input().split()))
count = 0
Jlist = []
for j in range(2, n+1):
    if j > a_list[j-1]:
        Jlist.append(j)

for j in Jlist:
    
    for i in range(1, j):
        if j -i == a_list[i-1] + a_list[j-1]:
            count += 1

print(count)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
count = 0
d={}
for i in range(n):
    if i - a[i] in d:
        count+=d[i - a[i]]
    if i + a[i] in d:
        d[i+a[i]] += 1
    else:
        d[i+a[i]] = 1

print(count)
### BUGGY CODE ###

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

result = []

def cal(n):
    count = 0
    for i in range(N):
        if i < n:
            if S[i] == "W":
                count += 1
        elif i > n:
            if S[i] == "E":
                count += 1
    return count

for i in range(N):
    result.append(cal(i))
    
# print(result)
print(min(result))

### FIXED CODE ###

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

if S[0] == "E":
    count = S.count("E") -1
    result = count
    for i in range(1,N):
        if S[i-1] == "W" and S[i] == "W":
            count += 1
        elif S[i-1] == "E" and S[i] == "E":
            count -= 1
            if result > count:
                result = count
else:
    count = S.count("E")
    result = count
    for i in range(1,N):
        if S[i-1] == "W" and S[i] == "W":
            count += 1
        elif S[i-1] == "E" and S[i] == "E":
            count -= 1
            if result > count:
                result = count

print(result)
### BUGGY CODE ###

import itertools

N = int(input())
A = list(map(int, input().split()))
MOD = 1000000007

ans = 0

B = list(itertools.combinations(A,2))

for i in range(len(B)):
    ans += (B[i][0] * B[i][1]) % MOD

ans %= MOD

print(ans)

### FIXED CODE ###

MOD = 1000000007
 
N = int(input())
A = list(map(int, input().split())) 
 
ans = 0
s = sum(A)
 
for a in A:
    s -= a
    ans += (a * s)

ans %= MOD

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

# coding: utf-8
N, K = map(int, input().split())
H = list(map(int, input().split()))
dp = [100000]*N
dp[0] = 0
for i in range(1, N):
    dp[i] = min(dp[j] + abs(H[i] - H[j]) for j in range(max(i-K, 0), i))
print(dp[N-1])


### FIXED CODE ###

def test():
    N, K = map(int, input().split())
    H = list(map(int, input().split()))
    dp = [float('inf')]*N
    dp[0] = 0

    for i in range(1, N):
        dp[i] = min(dp[j] + abs(H[i] - H[j]) for j in range(max(i-K, 0), i))

    print(dp[-1])

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

#

import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop

def main():
    n = int(input())
    agrid = []
    agrid_pointer = [0] * n
    aconditions = {}
    for i in range(n):
        al = list(map(int, input().split()))
        for j in range(len(al)):
            al[j] -= 1
        agrid.append(al)
        aconditions[i] = set(al)

    # print(agrid)
    # print(aconditions)

    ans = 0
    while True:
        match = set()
        for i in range(n):
            if i in match:  # この日対戦済み
                continue
            if len(aconditions[i]) == 0:  # もう全部対戦済み
                continue
            target = agrid[i][agrid_pointer[i]]
            if target in match:  # この日対戦済み
                continue
            if agrid_pointer[target] == n - 1 or agrid[target][agrid_pointer[target]] != i:  # 次対戦できない
                continue
            # can match
            aconditions[i].remove(target)
            agrid_pointer[i] += 1

            aconditions[target].remove(i)
            agrid_pointer[target] += 1

            match.add(i)
            match.add(target)

        # print(match)
        if len(match) == 0:  # 対戦がなくなったら
            break
        ans += 1

    # print(aconditions)
    # 対戦が残ってたら
    for v in aconditions.values():
        if len(v) != 0:
            print(-1)
            return
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#
import sys
import time

def input(): return sys.stdin.readline().strip()

def main():
    n = int(input())
    agrid = []
    agrid_pointer = [0] * n

    start = time.time()

    for i in range(n):
        al = list(map(int, input().split()))
        agrid.append(al)

    ans = 0

    while True:
        match = set()
        for i in range(n):
            if agrid_pointer[i] == n - 1 or i in match:  # もう全部対戦済み or この日対戦済み
                continue

            target = agrid[i][agrid_pointer[i]] - 1
            if agrid_pointer[target] == n - 1 or target in match:  # もう全部対戦済み or この日対戦済み
                continue
            # i, target は対戦可能

            if agrid[target][agrid_pointer[target]] - 1 != i:
                continue

            # can match
            agrid_pointer[i] += 1
            agrid_pointer[target] += 1

            match.add(i)
            match.add(target)

            if len(match) == n or len(match) == n - 1:  # 全員試合することが決まったら
                break

        # print(match)
        if len(match) == 0:  # 対戦がなくなったら
            break
        elapsed_time = time.time() - start
        if elapsed_time > 1.5:
            print(n * (n-1)//2)
            return

        ans += 1

    # print(aconditions)
    # 対戦が残ってたら
    for p in agrid_pointer:
        if p != n - 1:
            print(-1)
            return
    print(ans)


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

def search(string,n):
    cnt=0
    for i in range(1000):
        s=str(i)
        if len(s)==1:
            s='00'+s
        elif len(s)==2:
            s='0'+s
        k=0
        for j in range(n):
            if k==2 and s[k]==string[j]:
                cnt+=1
                #print(l[i])
                break
            if s[k]==string[j]:
               k+=1
    
    return cnt
    
    

n=int(input())
s=input()
l=search(s,n)
print(l)


### FIXED CODE ###

def search(string,n):
    cnt=0
    for i in range(1000):
        s=str(i)
        if len(s)==1:
            s='00'+s
        elif len(s)==2:
            s='0'+s
        k=0
        for j in range(n):
            if k==2 and s[k]==string[j]:
                cnt+=1
                #print(l[i])
                break
            if s[k]==string[j]:
               k+=1
    
    return cnt
    
    

n=int(input())
s=input()
l=search(s,n)
print(l)
### BUGGY CODE ###

N, M = list(map(int, input().split()))
A = [0] * M
B = [0] * M
R = [0] * N
for i in range(N):
    R[i] = set()

for i in range(M):
    A[i], B[i] = list(map(int, input().split()))
    R[A[i]-1].add(B[i]-1)
    R[B[i]-1].add(A[i]-1)

stack = []
visited = set()
max_groups = 0

for i in range(N):
    if not i in visited:
        stack.append(i)
        groups = 0
        while True:
            current = stack.pop()
            visited.add(current)
            groups += 1
            stack.extend(list(R[current] - visited - set(stack)))
            if not stack:
                break
        max_groups = max(max_groups,groups)

print(max_groups)

### FIXED CODE ###

N, M = list(map(int, input().split()))
A = [0] * M
B = [0] * M
R = [0] * N
for i in range(N):
    R[i] = set()

for i in range(M):
    A[i], B[i] = list(map(int, input().split()))
    R[A[i]-1].add(B[i]-1)
    R[B[i]-1].add(A[i]-1)

stack = set()
visited = set()
max_groups = 0

for i in range(N):
    if not i in visited:
        stack.add(i)
        groups = 0
        while True:
            current = stack.pop()
            visited.add(current)
            groups += 1
            stack |= (R[current] - visited)
            if not stack:
                break
        max_groups = max(max_groups,groups)

print(max_groups)
### BUGGY CODE ###

import sys
from collections import deque

read = sys.stdin.read
readline = sys.stdin.readline

H, W = map(int, readline().split())
S = tuple(read().split())


def bfs(grid, start):
    distance = [[0] * W for _ in range(H)]
    queue = deque([start])
    visited = set()
    while queue:
        x, y = queue.popleft()
        visited.add((x, y))

        for i, j in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            new_y, new_x = y + j, x + i
            if 0 <= new_y < W and 0 <= new_x < H:
                if grid[new_x][new_y] == '.' and (new_x, new_y) not in visited:
                    distance[new_x][new_y] = distance[x][y] + 1
                    queue.append((new_x, new_y))
    return distance


answer = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            continue
        tmp = max(map(max, bfs(S, (i, j))))
        if tmp > answer:
            answer = tmp

print(answer)


### FIXED CODE ###

import sys
from collections import deque

read = sys.stdin.read
readline = sys.stdin.readline

H, W = map(int, readline().split())
S = [list(input()) for i in range(H)]


def bfs(grid, start):
    distance = [[0] * W for _ in range(H)]
    queue = deque([start])
    visited = [[False] * W for _ in range(H)]
    while queue:
        x, y = queue.popleft()
        if visited[x][y]:
            continue
        visited[x][y] = True

        for i, j in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            new_y, new_x = y + j, x + i
            if 0 <= new_y < W and 0 <= new_x < H:
                if grid[new_x][new_y] == '.' and not visited[new_x][new_y]:
                    distance[new_x][new_y] = distance[x][y] + 1
                    queue.append((new_x, new_y))
    return distance


answer = 0
limit = H - 1 + W - 1
for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            continue

        cnt = 0
        for dx, dy in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            new_y, new_x = dy + j, dx + i
            if 0 <= new_y < W and 0 <= new_x < H:
                if S[new_x][new_y] == '.':
                    cnt += 1

        if cnt > 2:
            continue

        tmp = max(map(max, bfs(S, (i, j))))
        if tmp > answer:
            answer = tmp
        if answer == limit:
            print(answer)
            exit()

print(answer)
### BUGGY CODE ###

def gcd(x,y):
    if x < y:
        x, y = y, x
    if y == 0:
        return x
    if  x % y == 0:
        return y
    else:
        return gcd(y, x%y)

def f(n):
    li = []
    while True:
        for i in range(2, n+1):
            if n % i == 0:
                n = n // i
                li.append(i)
                break
            else:
                continue
        else:
            break
    return li

a, b = list(map(int, input().split()))
d = gcd(a, b)
print(len(set(f(d))) + 1)

### FIXED CODE ###

import math
def gcd(x,y):
    if x < y:
        x, y = y, x
    if y == 0:
        return x
    if  x % y == 0:
        return y
    else:
        return gcd(y, x%y)


a, b = list(map(int, input().split()))
d = gcd(a, b)
if d == 1:
    print(1)
    quit()
li = []
while True:
    for i in range(2, int(math.sqrt(d)) + 1):
        if d % i == 0:
            if not i in li:
                li.append(i)
                d = d // i
                break
            else:
                d = d // i
                break
    else:
        if d != 1:
            li.append(d)
            break

print(len(set(li)) + 1)