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

def fact(X):
    res = 1
    for i in range(1,X+1):
        res *= i
    return res

N, M = map(int,input().split())
N, M = max(N,M), min(N,M)
mod = 10**9 + 7
if N-M != 1 and N != M:
    ans = 0
elif N != M:
    ans = (fact(N)*fact(M))%mod
else:
    ans = (fact(N)*fact(M)*2)%mod
print(ans)

### FIXED CODE ###

import math
N, M = map(int,input().split())
N, M = max(N,M), min(N,M)
mod = 10**9 + 7
if N-M != 1 and N != M:
    ans = 0
elif N != M:
    factN = math.factorial(N)
    ans = (factN*factN//N)%mod
else:
    factN = math.factorial(N)
    ans = (factN*factN*2)%mod
print(ans)
### BUGGY CODE ###

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

if n < k:
    print(min(n,k - n))
else:
    if n % k == 0:
        print(0)
    else:
        while True:
            if abs(n - k) < k:
                print(min(abs(n - k), abs(abs(n - k)-k)))
                break
            else:
                n = n - k


### FIXED CODE ###

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

if n < k:
    print(min(n,k - n))
else:
    if n % k == 0:
        print(0)
    else:
        print(min(n % k,abs((n % k) - k)))
### BUGGY CODE ###

#abc174_e
from math import ceil
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()

if k==0:
    ans=max(a)
    print(ans)
    exit()
if k==1:
    if n==1:
        print(-(-a[0]//2))
        exit()
    ans=max(a[-1]/2,a[-2])
    print(ceil(ans))
    
ok=10**9+1
ng=1
def check(x):
    k_cnt=0
    for q in a:
        k_cnt+=ceil(q/x-1)
    if k_cnt<=k:
        return True
    else:
        return False

    
for i in range(1000):
    mid=(ok+ng)/2
    if check(mid):
        ok=mid
    else:
        ng=mid
    # print(ok,ng)
print(ceil(ok))


### FIXED CODE ###

#abc174_e
from math import ceil
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()

if k==0:
    ans=max(a)
    print(ans)
    exit()
if k==1:
    if n==1:
        print(-(-a[0]//2))
        exit()
    ans=max(a[-1]/2,a[-2])
    print(ceil(ans))
    exit()
    
ok=10**9+1
ng=1
def check(x):
    k_cnt=0
    for q in a:
        k_cnt+=ceil(q/x-1)
    if k_cnt<=k:
        return True
    else:
        return False

    
for i in range(100):
    mid=(ok+ng)/2
    if check(mid):
        ok=mid
    else:
        ng=mid
    # print(ok,ng)
print(ceil(ok))
### BUGGY CODE ###

import copy
import numpy as np
n=int(input())
xl=[list(map(int,input().split()))  for i in  range(n)]

cp=copy.deepcopy(xl)
cp=np.array(cp)
cp=cp.T
#xSort = np.sort(cp[0])[::-1]
dict={k: v for v, k in enumerate(cp[0])}
xr=[x+cp[1][dict[x]] for x in cp[0]]
xl=[x-cp[1][dict[x]] for x in cp[0]]
#print(xr)
#print(xl)
xlc=copy.deepcopy(xl)
xl.sort(reverse=True)
xrs=[xr[xlc.index(x)] for x in xl]
#print("xrs", xrs)
#print("xls", xls)

ans=0
r=10**5+1
for i in range(len(xl)):
  if xrs[i]>r:
    continue
  if xl[i]<=r:
    r=xl[i]
    #print("r",r)
    ans+=1
    
print(ans)

### FIXED CODE ###

import copy
import numpy as np
n=int(input())
xl=[]
for i in range(n):
    x,l = map(int,input().split())
    xl.append([x-l,l+x])
#print(xl)
xl = sorted(xl, key=lambda x: x[0],reverse=True)
#print(xl)

ans=0
r=2*(10**9+1)
for i in range(n):
  if xl[i][1]>r:
    continue
  if xl[i][0]<=r:
    r=xl[i][0]
    #print("r",r)
    ans+=1
print(ans)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import math
import datetime
import itertools
import sys
import copy

# 入力
#N = int(input())
#S = str(input())
#N, A, B = map(int, input().split())
N = int(input())

ans = 1
for i in range(1, N+1) :
  if i % 2 == 0 :
    ans *= i
    #print (i)

cnt = 0
s = str(ans)
for i in range(len(s)) :
  if s[len(s)-i-1] == "0" :
    cnt += 1
  else :
    break
print (cnt)


### FIXED CODE ###

# -*- coding: utf-8 -*-
import math
import datetime
import itertools
import sys
import copy

# 入力
#N = int(input())
#S = str(input())
#N, A, B = map(int, input().split())
N = int(input())

if N%2 == 1 :
  print (0)
  exit()
else :
  cnt = 0
  i = 1
  N //= 2
  while N >= 5**i :
    cnt += N // (5**i)
    i += 1
    
  print (cnt)
### BUGGY CODE ###

N,M = map(int, input().split())
X = [ [int(j) for j in input().split()] for _ in range(N)]
ans = 0
for i in range(1<<3):
    dp = [ [0] * (M+1) for _ in range(N+1)]
 
    for n in range(0,N):
        x,y,z = X[n]
        s = (x if (i & (1<<2)) else -x) \
            + (y if (i & (1<<1)) else -y) \
            + (z if (i & (1<<0)) else -z) \
 
        # for m in range(0, min(n+1,M) ):
        for m in range(min(n,M-1), -1, -1 ):
            dp[n+1][m+1] =  max(dp[n+1][m+1], s + dp[n][m] )
            dp[n+1][m]   =  max(dp[n+1][m], dp[n][m])
 
        dp[n+1][M] = max(dp[n+1][M], dp[n][M])
    ans = max(ans, dp[N][M])
print(ans)

### FIXED CODE ###

N,M = map(int, input().split())
X = [ [int(j) for j in input().split()] for _ in range(N)]
ans = 0
for i in range(1<<3):
    if M==0:
        break
    ss = [None]*N

    for n in range(0,N):
        x,y,z = X[n]
        s = (x if (i & (1<<2)) else -x) \
            + (y if (i & (1<<1)) else -y) \
            + (z if (i & (1<<0)) else -z)
        ss[n] = s
    ss.sort()
    ans = max(ans, sum(ss[N-M:]))
print(ans)
### BUGGY CODE ###

n,k = map(int,input().split())
a = list(map(int,input().split()))
f = list(map(int,input().split()))
a.sort()
f.sort(reverse = True)
def ok(p):
  result = 0
  for i in range(n):
    result += max(a[i]-p//f[i],0)
  if result <= k:
    return True
  return False

L = 0
U = a[-1]*f[0]
while U-L >= 1:
  M = (U+L)//2
  if ok(M):
    U = M
  else:
    L = M+1
    
print(U)

### FIXED CODE ###

n,k = map(int,input().split())
a = list(map(int,input().split()))
f = list(map(int,input().split()))
a.sort()
f.sort(reverse = True)
def ok(p):
  result = 0
  for i in range(n):
    result += max(a[i]-p//f[i],0)
  if result <= k:
    return True
  return False

L = 0
U = a[-1]*f[0]
while U-L >= 1:
  M = (U+L)//2
  if ok(M):
    U = M
  else:
    L = M+1
    
print(U)
### BUGGY CODE ###

from collections import deque
n,k=map(int,input().split())
p=list(map(int,input().split()))
minp=[0]*(n-k+1)
maxp=[0]*(n-k+1)
q1=deque([0])
q2=deque([0])
for i in range(1,k):
    while p[q1[-1]]>p[i]:
        q1.pop()
        if len(q1)==0:
            break
    while p[q2[-1]]<p[i]:
        q2.pop()
        if len(q2)==0:
            break
    q1.append(i)
    q2.append(i)
for i in range(n-k+1):
    minp[i]=p[q1[0]]
    maxp[i]=p[q2[0]]
    if i==n-k:
        break
    if q1[0]==i:
        q1.popleft()
    if q2[0]==i:
        q2.popleft()
    while p[q1[-1]]>p[i+k]:
        q1.pop()
        if len(q1)==0:
            break
    while p[q2[-1]]<p[i+k]:
        q2.pop()
        if len(q2)==0:
            break
    q1.append(i+k)
    q2.append(i+k)

d=[False]*(n-k+1)
d[0]=all(p[i]<p[i+1] for i in range(k-1))
i=1
while i<n-k+1:
    if p[i+k-2]>p[i+k-1]:
        i+=k-1
    else:
        if d[i-1]:
            d[i]=True
        else:
            if p[i]<p[i+1]:
                d[i]=all(p[j]<p[j+1] for j in range(i,i+k-1))
        i+=1

ans=int(any(d))
if not d[0]:
    ans+=1
for i in range(n-k):
    if d[i+1]:
        continue
    if not (p[i]==minp[i] and p[i+k]==maxp[i+1]):
        ans+=1

print(ans)

### FIXED CODE ###

from collections import deque
n,k=map(int,input().split())
p=list(map(int,input().split()))

minp=[0]*(n-k+1)
maxp=[0]*(n-k+1)
q1=deque([0])
q2=deque([0])
for i in range(1,k):
    while p[q1[-1]]>p[i]:
        q1.pop()
        if len(q1)==0:
            break
    while p[q2[-1]]<p[i]:
        q2.pop()
        if len(q2)==0:
            break
    q1.append(i)
    q2.append(i)
for i in range(n-k+1):
    minp[i]=p[q1[0]]
    maxp[i]=p[q2[0]]
    if i==n-k:
        break
    if q1[0]==i:
        q1.popleft()
    if q2[0]==i:
        q2.popleft()
    while p[q1[-1]]>p[i+k]:
        q1.pop()
        if len(q1)==0:
            break
    while p[q2[-1]]<p[i+k]:
        q2.pop()
        if len(q2)==0:
            break
    q1.append(i+k)
    q2.append(i+k)

d=[0]*n
d[0]=1
for i in range(1,n):
    if p[i]>p[i-1]:
        d[i]=d[i-1]+1
    else:
        d[i]=1

ans=int(k in d)
if d[k-1]!=k:
    ans+=1
for i in range(n-k):
    if d[i+k]>=k:
        continue
    if not (p[i]==minp[i] and p[i+k]==maxp[i+1]):
        ans+=1

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

from heapq import  heappush, heappop

H, W, K = map(int, input().split())
x1, y1, x2, y2 = map(int, input().split())
c = [[i for i in input()] for _ in range(H)]

dist = [[[float('inf')] * 2 for _ in range(W)] for _ in range(H)]
dist[x1 - 1][y1 - 1] = [0, 0]

# [cost, x, y, mode]
q = [(0, x1 - 1, y1 - 1, 0), (0, x1 - 1, y1 - 1, 1)]
while q :
  ccost, cx, cy, cmode = heappop(q)
  if ccost > dist[cx][cy][cmode] :
    continue
  for i, (dx, dy) in enumerate(((-1, 0), (0, -1), (1, 0), (0, 1))) :
    nmode = i % 2
    nx, ny = cx + dx, cy + dy
    if cmode == nmode :
      ncost = ccost + 1
    else :
      ncost = (ccost + K) - ccost % K
      
    if 0 <= nx < H and 0 <= ny < W and c[nx][ny] != '@' and dist[nx][ny][nmode] > ncost :
      heappush(q, (ncost, nx, ny, nmode))
      dist[nx][ny][nmode] = ncost
 
if min(dist[x2 - 1][y2 - 1]) == float('inf') :
  print(-1)
else :
  print((min(dist[x2 - 1][y2 - 1]) + K - 1) // K)

### FIXED CODE ###

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

H, W, K = map(int, input().split())
x1, y1, x2, y2 = map(int, input().split())
c = [[i == '.' for i in input()] for _ in range(H)]

x1, y1, x2, y2 = x1 - 1, y1 - 1, x2 - 1, y2 - 1
INF = 1 << 60
dist = [INF] * (H * W * 2)

def pos(x, y, m) :
  return (x * W + y) * 2 + m
dist[pos(x1, y1, 0)] = dist[pos(x1, y1, 1)] = 0

q = [(0, pos(x1, y1, 0)), (0, pos(x1, y1, 1))]
while q :
  ccost, cpos = heappop(q)
  if ccost > dist[cpos] : continue
  cx = cpos // 2 // W
  cy = cpos // 2 % W
  cmode = cpos % 2
  dir = [
    [(-1, 0), (1, 0)],
    [(0, -1), (0, 1)]
  ]
  for dx, dy in dir[cmode] :
    nx, ny = cx + dx, cy + dy
    ncost = ccost + 1
    if 0 <= nx < H and 0 <= ny < W and c[nx][ny] and ncost < dist[pos(nx, ny, cmode)] :
      heappush(q, (ncost, pos(nx, ny, cmode)))
      dist[pos(nx, ny, cmode)] = ncost
      
  ncost = (ccost + K - 1) // K * K
  if ncost < dist[pos(cx, cy, cmode ^ 1)] :
    dist[pos(cx, cy, cmode ^ 1)] = ncost
    heappush(q, (ncost, pos(cx, cy, cmode ^ 1)))

ans = min(dist[pos(x2, y2, 0)], dist[pos(x2, y2, 1)])
if ans == INF :
  print(-1)
else :
  print((ans + K - 1) // K)
### BUGGY CODE ###

_, q = input().split()
s = input()
qs = [list(map(int, input().split())) for _ in range(int(q))]

# def get_num_AC(ccond, s, count):
#     if s == []:
#         return count
#     if ccond:
#         if s.pop() == 'A':
#             return get_num_AC(False, s, count+1)
#         else:
#             if s == []:
#                 return count
#             else:
#                 return get_num_AC(s.pop() == 'C', s, count)
#     return get_num_AC(s.pop() == 'C', s, count)

def get_substr(s, smaller, larger):
    s1 = s[smaller-1:larger]
    return s1

for smaller, larger in qs:
    substr = get_substr(s, smaller, larger)
    count = substr.count('AC')
    print(count)


### FIXED CODE ###

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

s = input()

count = [0] * n

for i in range(1, n):
    if s[i-1] == 'A' and s[i] == 'C':
        count[i] += 1

from itertools import accumulate

accum = list(accumulate(count))

for _ in range(q):
    l, r = map(int, input().split())
    print(accum[r-1] - accum[l-1])
### BUGGY CODE ###

def mi(): return map(int,input().split())
def lmi(): return list(map(int,input().split()))
def ii(): return int(input())
def isp(): return input().split()

n=ii()
a=lmi()
INF=10**9+7
ans=0
for i in range(60):
  x=0
  for j in range(n):

    if (a[j]>>i)&1:
      x+=1

  num=x*(n-x)*2**i
  ans+=num

print(ans%INF)

### FIXED CODE ###

def mi(): return map(int,input().split())
def lmi(): return list(map(int,input().split()))
def ii(): return int(input())
def isp(): return input().split()

n=ii()
a=lmi()
INF=10**9+7
ans=0
for i in range(60):
  x=0
  for j in range(n):

    if (a[j]>>i)&1:
      x+=1

  num=x*(n-x)*2**i
  ans+=num

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

N=int(input())
A=list(map(int,input().split()))
ans=1
for i in A:
    ans*=i
if ans>10**18:
    print(-1)
else:
    print(ans)


    


            
    


    


    
    














    


    














### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
ans=1
if 0 in A:
    print(0)
    exit()
for i in A:
    ans*=i
    if ans>10**18:
        print(-1)
        exit()
print(ans)
### BUGGY CODE ###

import sys
from bisect import *

input = sys.stdin.readline

def f(n, q):
    xst = []
    for i in range(n):
        s, t, x = map(int, input().split())
        xst.append([x, s - x, t - x])
    xst.sort()

    ds = []
    ans = [-1] * q
    for i in range(q):
        d = int(input())
        ds.append(d)

    for x, s, t in xst:
        st = bisect_left(ds, s)
        for i in range(st, q):
            if ds[i] >= t:
                break
            if ans[i] == -1:
                ans[i] = x

    print(*ans, sep="\n")

n, q = map(int, input().split())
f(n, q)


### FIXED CODE ###

import sys
from bisect import *

input = sys.stdin.readline

def f(n, q):
    xst = []
    for i in range(n):
        s, t, x = map(int, input().split())
        xst.append([x, s - x, t - x])
    xst.sort()

    ds = []
    for i in range(q):
        d = int(input())
        ds.append(d)

    ans = [-1] * q
    jump = [-1] * q

    for x, s, t in xst:
        i = bisect_left(ds, s)
        fi = bisect_left(ds, t)
        while i < fi:
            if jump[i] != -1:
                i = jump[i]
            else:
                ans[i] = x
                jump[i] = fi
                i += 1

    print(*ans, sep="\n")

n, q = map(int, input().split())
f(n, q)
### BUGGY CODE ###

import itertools
n = int(input())
score = [ int(input()) for _ in range(n)]
score.reverse()
for i in sorted(range(1, n+1),reverse=True):
  cnt = max([ sum(c) if sum(c) % 10 != 0 else 0 for c in itertools.combinations(score, i)])
  if(cnt != 0):
    print(cnt)
    exit()
print(0)

### FIXED CODE ###

import itertools
n = int(input())
score = [ int(input()) for _ in range(n)]
cnt = max([sum(c) if sum(c) % 10 != 0 else 0 for i in sorted(range(n-1, n+1)) for c in itertools.combinations(score, i)])
print(cnt)
### BUGGY CODE ###

#!/usr/bin/python3
# -*- coding: utf-8 -*-
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

n = int(input())
a_list = list(map(int, input().split()))
a_list.sort()
flag1 = 1
for i in range(n - 1):
    if flag1 == 1:
        for j in range(i + 1, n):
            if gcd(a_list[i], a_list[j]) != 1:
                flag1 = 0
                break
    else:
        break
ans2 = a_list[0]
for i in range(1, n):
    ans2 = gcd(ans2, a_list[i])
    if ans2 == 1:
        break

if flag1 == 1:
    print("pairwise coprime")
elif ans2 == 1:
    print("setwise coprime")
else:
    print("not coprime")

### FIXED CODE ###

#!/usr/bin/python3
# -*- coding: utf-8 -*-
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

n = int(input())
a_list = list(map(int, input().split()))
a_list.sort()
ans2 = a_list[0]
for i in range(1, n):
    ans2 = gcd(ans2, a_list[i])
    if ans2 == 1:
        break

if ans2 != 1:
    print("not coprime")
else:
    flag = 1
    max_a = a_list[n - 1] + 1
    num_flag_list = [True] * max_a
    d_list = list(range(0, max_a))
    d_list[0] = 1
    num_flag_list[0] = num_flag_list[1] = False
    for i in range(2, int(max_a**0.5) + 1):
        if num_flag_list[i]:
            for j in range(i**2, max_a, i):
                if num_flag_list[j] == True:
                    num_flag_list[j] = False
                    d_list[j] = i
    p_set = set()
    for a in a_list:
        if a == 1:
            continue
        temp_p_set = set()
        while True:
            p = d_list[a]
            if p not in temp_p_set:
                if p in p_set:
                    flag = 0
                    break
            temp_p_set.add(p)
            p_set.add(p)
            a = a // p
            if a == 1:
                break
        if flag == 0:
            break
        
    if flag == 1:
        print("pairwise coprime")
    else:
        print("setwise coprime")
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
ans, d = 0, dict()

for i in range(N):
    diff = A[i] + A[0] - i 
    if d.get(diff) == None:
        d[diff] = [i]
    else:
        d[diff].append(i)

diff = 0
if d.get(0) != None:
    ans += len(d[0])

for i in range(1, N):
    diff -= A[i] - A[i-1] + 1
    if d.get(diff) != None:
        j = 0
        while j < len(d[diff]) and d[diff][j] <= i:
            j += 1
        d[diff] = d[diff][j:]
        ans += len(d[diff])

print(ans)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
ans, d = 0, dict()

for i in range(N):
    key = A[i] + i
    if d.get(key) == None:
        d[key] = 1
    else:
        d[key] += 1
    
    key = i - A[i]
    if d.get(key) != None:
        ans += d[key]

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

n,m = map(int,input().split())
H = [int(i) for i in input().split()]

a = [0] * m
b = [0] * m

ans = [1]* n



for i in range(m):
    a[i], b[i] = map(int, input().split())

for i in range(n):

    for j in range(m):
        if a[j] == i+1 and H[i] <= H[b[j]-1]:
            ans[i] = 0
            break
        elif b[j] == i+1 and H[i] <=  H[a[j]-1]:
            ans[i] = 0
            break

print(ans.count(1))


### FIXED CODE ###

n,m = map(int,input().split())
H = [int(i) for i in input().split()]

a = [0] * m
b = [0] * m
ans = [1]* n



for i in range(m):
    a[i], b[i] = map(int, input().split())


for j in range(m):
    if H[a[j]-1] < H[b[j]-1]:
        ans[a[j]-1] = 0
    elif H[a[j]-1] > H[b[j]-1]:
        ans[b[j]-1] = 0
    elif H[a[j]-1] == H[b[j]-1]:
        ans[a[j]-1] = 0
        ans[b[j]-1] = 0


print(ans.count(1))
### BUGGY CODE ###

import itertools
N,K = map(int,input().split())
A = list(map(int,input().split()))
if K >= 50:
    print(*[N]*N)
    exit()
for i in range(K):
    newA = [0]*N
    for j in range(N):
        newA[max(0,j-A[j])] += 1
        if j+A[j]+1 < N:
            newA[min(N-1,j+A[j]+1)] -= 1
    A = list(itertools.accumulate(newA))
    if A == [N]*N:
        break
print(*A)

### FIXED CODE ###

import itertools
N,K = map(int,input().split())
A = list(map(int,input().split()))
if K >= 50:
    print(*[N]*N)
    exit()
for i in range(K):
    newA = [0]*N
    for j in range(N):
        newA[max(0,j-A[j])] += 1
        if j+A[j]+1 < N:
            newA[min(N-1,j+A[j]+1)] -= 1
    A = list(itertools.accumulate(newA))
    if A == [N]*N:
        break
print(*A)
### BUGGY CODE ###

import sys


def main():
    N, P = map(int, input().split())

    left = 0
    right = 10**12
    while left + 1 < right:
        mid = (left + right) // 2
        if mid**N <= P:
            left = mid
        else:
            right = mid

    for j in range(left, 0, -1):
        if P % j**N == 0:
            print(j)
            break


main()


### FIXED CODE ###

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


def main():
    N, P = map(int, input().split())
    A = factorization(P)

    B = []
    for a, b in A:
        if b >= N:
            B.append((a, b // N))

    ans = 1
    for a, b in B:
        ans *= a**b
    print(ans)


main()
### BUGGY CODE ###

R, G, B, N = map(int, input().split())
ans = 0
for r in range(N+1):
  for g in range(N+1):
    if (N - r*R - g*G) % B == 0 and (N - r*R - g*G) >= 0:
      ans += 1
print(ans)

### FIXED CODE ###

R, G, B, N = map(int, input().split())
ans = 0
for r in range(N//R+1):
  for g in range((N-r*R)//G+1):
    if (N - r*R - g*G) % B == 0:
      ans += 1
print(ans)
### BUGGY CODE ###

import math
K = int(input())
cnt = 0

for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            cnt += math.gcd(math.gcd(i,j),k)
print(cnt)

### FIXED CODE ###

from math import gcd

K = int(input())
cnt = 0

for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            cnt += gcd(gcd(i,j),k)
print(cnt)
### BUGGY CODE ###

from collections import deque

s = list(input())
q = int(input())

count = 0
l = []
for i in range(q):
	tmp = list(map(str,input().split()))
	if len(tmp) == 1:
		count += 1
		for j in range(len(l)):
			l[j][0] += 1
	elif tmp[1] == '1':
		l.append([1, tmp[2]])
	elif tmp[1] == '2':
		l.append([2, tmp[2]])

for i in range(len(l)):
	l[i][0] %= 2

if count % 2 == 1:
	s = s[::-1]
s = deque(s)

for i in range(len(l)):
	if l[i][0] == 0:
		s.append(l[i][1])
	else:
		s.appendleft(l[i][1])
print("".join(s))


### FIXED CODE ###

from collections import deque

s = list(input())
s2 = deque(list(reversed(s)))
s = deque(s)
Q = int(input())
q = []
f = []
c = []
count = 0

for _ in range(Q):
    tmp = list(map(str,input().split()))
    if len(tmp) == 1:
        count += 1
        q.append(int(tmp[0]))
        f.append(0)
        c.append('')
    else:
        q.append(int(tmp[0]))
        f.append(int(tmp[1]))
        c.append(tmp[2])


for i in range(Q):
    if q[i] == 1:
        tmp = s
        s = s2
        s2 = tmp
    else:
        if f[i] == 1:
            s.appendleft(c[i])
            s2.append(c[i])
        else:
            s.append(c[i])
            s2.appendleft(c[i])

for i in range(len(s)):
    print(s.popleft(),end="")
print("")
### BUGGY CODE ###

def slove():
    import sys
    import fractions
    input = sys.stdin.readline
    a, b = list(map(int, input().rstrip('\n').split()))
    gcd = fractions.gcd(a, b)
    cnt = 1
    for i in range(2, int(gcd ** 0.5) + 2):
        while True:
            if gcd % i == 0:
                cnt += 1
                while True:
                    if gcd % i == 0:
                        gcd //= i
                    else:
                        break
    print(cnt)


if __name__ == '__main__':
    slove()


### FIXED CODE ###

def slove():
    import sys
    import fractions
    input = sys.stdin.readline
    a, b = list(map(int, input().rstrip('\n').split()))
    gcd = fractions.gcd(a, b)
    cnt = 1
    for i in range(2, int(gcd ** 0.5) + 1):
        if gcd % i == 0:
            cnt += 1
            while True:
                if gcd % i == 0:
                    gcd //= i
                else:
                    break
    if gcd != 1:
        cnt += 1
    print(cnt)


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

from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

x = inp()
for i in range(-2000,2000):
    for j in range(-2000,2000):
        if pow(i,5) - pow(j,5) == x:
            print(i,j)
            quit()

### FIXED CODE ###

from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

x = inp()
for i in range(10**3):
    for j in range(-2000,2000):
        if pow(i,5) - pow(j,5) == x:
            print(i,j)
            quit()
### BUGGY CODE ###

i = int(input())
ii = list(map(int,input().split()))

import collections

c = collections.Counter(ii)
k = list(c.keys())

for a in range(i):
    if k.count(a+1)==0:
        print(0)
    else:
        print(c[a+1])

### FIXED CODE ###

i = int(input())
ii = list(map(int,input().split()))

import collections

c = collections.Counter(ii)
k = list(c.keys())

for a in range(1,i+1):
    print(c[a])