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

def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)

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


N, M = [int(_) for _ in input().split()]
S = input()
T = input()

L = lcm(N, M)


X = ['_' for i in range(L)]

j = 0
for i in range(0, L, L // N):
    X[i] = S[j]
    j += 1

j = 0
for i in range(0, L, L // M):
    if X[i] != '_' and X[i] != T[j]:
        print("-1")
        exit()
    X[i] = T[j]
    j += 1

print(L)


### FIXED CODE ###

def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)

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


N, M = [int(_) for _ in input().split()]
S = input()
T = input()

L = lcm(N, M)
D = lcm(L // M, L // N)

for i in range(0, L, D):
    if S[i // (L // N)] != T[i // (L // M)]:
        print("-1")
        exit()
else:
    print(L)
### BUGGY CODE ###

from bisect import bisect_left
n = int(input())
A=[int(input()) for _ in range(n)]
row = [A[0]]
for a in A[1:]:
    if a<=row[-1]:
        row.append(a)
    else:
        row[len(row) - bisect_left(row[::-1],a)] = a
print(len(row))

### FIXED CODE ###

from bisect import bisect_left
from collections import deque
n = int(input())
A=[int(input()) for _ in range(n)]
q=deque()
for a in A:
    i=bisect_left(q,a)
    if not i:
        q.appendleft(a)
    else:
        q[i-1]=a
print(len(q))
### BUGGY CODE ###

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

L = []
for i in range(n):
    a,b = map(int,input().split())
    if a > m:
        continue
    L.append([a,b])

L.sort(reverse = True)

ans = 0
li = []
for i in range(1,m+1):
    while L and L[-1][0] <= i:
        (a,b) = L.pop()
        heapq.heappush(li,b*(-1))

    if li:
        heapq.heapify(li)
        h = heapq.heappop(li)
        ans +=(-1)*h

print(ans)

### FIXED CODE ###

import heapq
n,m = map(int,input().split())
dp = [0]*(n+1)
L = []
days = []
cost = []
for i in range(n):
    a,b = map(int,input().split())
    if a > m:
        continue
    L.append([a,b])

L.sort(reverse = True)

ans = 0
li = []
for i in range(1,m+1):
    while L and L[-1][0] <= i:
        (a,b) = L.pop()
        heapq.heappush(li,b*(-1))

    if li:
        h = heapq.heappop(li)
        ans +=(-1)*h

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

N, K = map(int,input().split())
A = sorted([int(i) for i in input().split()])
F = sorted([int(i) for i in input().split()],reverse=True)
low,high = -1, int(1e12)
while high-low>1:
  mid = (high+low)//2
  k = sum([max(0, a-mid//f) for a,f in zip(A,F)])
  if k>K: low = mid
  else: high = mid
print(high)

### FIXED CODE ###

import numpy as np
N, K = map(int,input().split())
A = np.array(sorted(map(int,input().split())))
F = np.array(sorted(map(int,input().split()) ,reverse=True))
low,high = -1, int(1e12)
while high-low>1:
  mid = (high+low)//2
  k = (A-np.minimum(A,mid//F)).sum()
  if k>K: low = mid
  else: high = mid
print(high)
### BUGGY CODE ###

K, S = map(int, input().split())
count = 0
for z in range(K+1):
    for y in range(K+1):
        x = S - z - y
        if (0 <= x <= K) & (0 <= y <= K) & (0 <= z <= K):
            count += 1

print(count)


### FIXED CODE ###

K, S = map(int, input().split())
count = 0
for z in range(K+1):
    for y in range(K+1):
        x = S - z - y
        if (0 <= x <= K) :
            count += 1

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

N = int(input())
A = list(map(int,input().split()))
Q = int(input())
bcs = []
for i in range(Q):
  j,k = map(int,input().split())
  bcs.append([j,k])
cnts = [0]*100000
for a in A:
  cnts[a-1]+=1
for b,c in bcs:
  t = cnts[b-1]
  cnts[b-1]=0
  cnts[c-1]+=t
  s = 0
  for i in range(1,100001):
    s += cnts[i-1]*i
  print(s)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
Q = int(input())
bcs = []
for i in range(Q):
  j,k = map(int,input().split())
  bcs.append([j,k])
s = sum(A)
cnts = [0]*100000
for a in A:
  cnts[a-1]+=1
for b,c in bcs:
  t = cnts[b-1]
  s -= t * b
  cnts[b-1]=0
  cnts[c-1]+=t
  s += t*c 
  print(s)
### BUGGY CODE ###

s=input()
n=int(input())
r=-1
for i in range(n):
    q=list(input().split())
    if q[0]=='1':
        r*=-1
    else:
        if q[1]=='1':
            if r==-1:
                s=q[2]+s
            else:
                s=s+q[2]
        else:
            if r==-1:
                s=s+q[2]
            else:
                s=q[2]+s
if r==1:
    s=s[::-1]
print(s)
            


### FIXED CODE ###

s=input()
n=int(input())
r=-1
f=[]
b=[]
for i in range(n):
    q=input().split()
    if q[0]=='1':
        r*=-1
    else:
        t=int(q[1])
        if t*r==-1 or t*r==2 :
            f.append(q[2])
        else:
            b.append(q[2])
f=''.join(f)
b=''.join(b)
s=f[::-1]+s+b
if r==1:
    s=s[::-1]
print(s)
### BUGGY CODE ###

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

A.append(0)

B = []
f = True
for i in range(N):
    if f:
        if A[i] < A[i+1]:
            B.append(A[i])
            f = False
    else:
        if A[i] > A[i+1]:
            B.append(A[i])
            f = True


if len(B) == 0:
    print(1000)
else:
    res = 1000
    for i in range(2**len(B)):
        en = 1000
        ka = 0
        for j in range(len(B)):
            if (i>>j)&1:
                if j % 2 == 0:
                    if en // B[j] == 0:
                        break
                    ka = en//B[j]
                    en %= B[j]
                else:
                    if ka == 0:
                        break
                    en += ka*B[j]
                    ka = 0
        else:
            res = max(en, res)

    print(res)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
A.append(0)

kabu = 0
en = 1000

for i in range(N):
    a, b = divmod(en, A[i])
    kabu += a
    en = b
    if A[i+1] < A[i]:
        en += kabu*A[i]
        kabu = 0

print(en)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
"""
C - K-th Substring
https://beta.atcoder.jp/contests/abc097/tasks/arc097_a

"""
import sys
from sys import stdin
input = stdin.readline


def solve(s, K):
    l = len(s)
    substrings = set()

    pre_check = set()
    for ch in s:
        pre_check.add(ch)
    pre_check = list(pre_check)
    pre_check.sort()
    pre_check = pre_check[:5]

    for i in range(l):
        if not s[i] in pre_check:
            continue
        for j in range(l+1):
            t = s[i:j]
            if len(t):
                substrings.add(t)
    ans = list(substrings)
    ans.sort()
    return ans[K - 1]


def main(args):
    s = input().strip()
    K = int(input())
    ans = solve(s, K)
    print(ans)

if __name__ == '__main__':
    main(sys.argv[1:])


### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
C - K-th Substring
https://beta.atcoder.jp/contests/abc097/tasks/arc097_a

"""
import sys
from sys import stdin
input = stdin.readline


def solve(s, K):
    l = len(s)
    substrings = set()
    for i in range(l):
        for j in range(i+K+1):
            t = s[i:j]
            if len(t):
                substrings.add(t)
    ans = list(substrings)
    ans.sort()
    return ans[K - 1]


def main(args):
    s = input().strip()
    K = int(input())
    ans = solve(s, K)
    print(ans)

if __name__ == '__main__':
    main(sys.argv[1:])
### BUGGY CODE ###

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


count = 0
for i in range(K+1):
    for j in range(K+1):
        for k in range(K+1):
            if i+j+k == S:
                count += 1

print(count)

### FIXED CODE ###

k,s = map(int,input().split())
count = 0
for i in range(k+1):
    for j in range(k+1):
        if 0 <= s-(i+j) <=k:
            count += 1
print(count)
### BUGGY CODE ###

from itertools import combinations
n=int(input())
s=input()
ans=0
set_s=len(set([i for i in s]))
for i in range(1,set_s+1):
    koho=tuple(combinations((j for j in s),i))
    for j in koho:
        if len(j)==len(tuple(set(j))):
            ans+=1
print(ans%(10**9+7))

### FIXED CODE ###

from collections import Counter
n=int(input())
s=input()
cnt=Counter(s)
ans=1
for i in cnt.values():
    ans*=i+1
print((ans-1)%(10**9+7))
### BUGGY CODE ###

# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8


def run():
    N = int(input())
    S_ = []

    for i in range(N):
        s = input()
        s = [ord(ss)-96 for ss in s] * 2
        S_.append(s)

    #for s in S_:
    #    print(s)
    S = []
    for s in S_:
        S.append(s)
    for s in S_:
        S.append(s)

    #for s in S:
    #    print(s)


    axises = [(i, 0) for i in range(N)]
    for i in range(1, N):
        axises.append((0, i))

    ans = 0

    #print(axises)
    for axis in axises:
        ci, cj = axis
        done = False
        for i in range(N):
            if done:break
            for j in range(i, N):
                if S[ci+i][cj+j] == S[ci+j][cj+i]:continue
                else:
                    #print((ci, cj), (i, j))
                    done=True
                    break
        if not done:
            ans += min(N-ci, N-cj)


    print(ans)

if __name__ == "__main__":
    run()


### FIXED CODE ###

# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8


def run():
    N = int(input())
    S_ = []

    for i in range(N):
        s = input()
        s = [ord(ss)-96 for ss in s] * 2
        S_.append(s)

    #for s in S_:
    #    print(s)
    S = []
    for s in S_:
        S.append(s)
    for s in S_:
        S.append(s)

    #for s in S:
    #    print(s)


    axises = [(i, 0) for i in range(N)]
    for i in range(1, N):
        axises.append((0, i))

    ans = 0

    #print(axises)
    for axis in axises:
        ci, cj = axis
        done = False
        for i in range(N):
            if done:break
            for j in range(i, N):
                if S[ci+i][cj+j] == S[ci+j][cj+i]:continue
                else:
                    #print((ci, cj), (i, j))
                    done=True
                    break
        if not done:
            ans += min(N-ci, N-cj)


    print(ans)

if __name__ == "__main__":
    run()
### BUGGY CODE ###

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

cnt = 0

for i in range(0, N):
    for j in range(i + 1, N + 1):
        if sum(A[i:j]) == 0:
            cnt += 1

print(cnt)


### FIXED CODE ###

from collections import Counter

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

S = [0]

for i, a in enumerate(A):
    S.append(S[i] + a)

S = sorted(S)
a = Counter(S).most_common()
cnt = 0

for i in range(len(a)):
    cnt += ((a[i][1]-1)*a[i][1])//2

print(cnt)
### BUGGY CODE ###

N, M = [int(x) for x in input().split()]
PY_list = [[int(x)-1 for x in input().split()] for _ in range(M)]
lst = [[] for _ in range(N)] 
for P, Y in PY_list:
    lst[P].append(Y)
for i, Ys in enumerate(lst):
    lst[i] = sorted(Ys)
for p, y in PY_list:
    print('{:06}{:06}'.format(p+1, lst[p].index(y)+1))


### FIXED CODE ###

from bisect import bisect_left
N, M = [int(x) for x in input().split()]
PY_list = [[int(x)-1 for x in input().split()] for _ in range(M)]
lst = [[] for _ in range(N)] 
for P, Y in PY_list:
    lst[P].append(Y)
for l in lst:
    l.sort()
for p, y in PY_list:
    print('{:06}{:06}'.format(p+1, bisect_left(lst[p], y)+1))
### BUGGY CODE ###

n = int(input())

from collections import defaultdict
d = defaultdict(int)

for i in range(1,n+1):
  for j in range(1,n+1):
    for k in range(1,n+1):
      d[i**2+j**2+k**2+i*j+j*k+k*i]+=1

for j in range(1,n+1):
  if d[j]:
    print(d[j])
  else:
    print(0)
    

### FIXED CODE ###

n = int(input())

from collections import defaultdict
d = defaultdict(int)

ul=int(n**0.5)

for i in range(1,ul):
  for j in range(1,ul):
    for k in range(1,ul):
      d[i**2+j**2+k**2+i*j+j*k+k*i]+=1
for j in range(1,n+1):
  print(d.get(j,0))
#  print(d[j] if d[j] else 0)
### BUGGY CODE ###

n, ma, mb = map(int, input().split())
abc = [list(map(int, input().split())) for _ in range(n)]

m = n * 10 + 1

dp = [[[float('inf')] * m for j in range(m)] for i in range(n + 1)]
for i in range(n + 1):
    dp[i][0][0] = 0

for i in range(n):
    for j in range(m):
        for k in range(m):
            dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k])

            # i個目を買う
            jj = j + abc[i][0]
            kk = k + abc[i][1]
            if jj < m and kk < m:
                dp[i+1][jj][kk] = min(dp[i+1][jj][kk], dp[i][j][k] + abc[i][2])

from fractions import gcd
ans = float('inf')
for i in range(1, m):
    for j in range(1, m):
        g = gcd(i, j)
        if i // g == ma and j // g == mb:
            ans = min(ans, dp[-1][i][j])

if ans == float('inf'):
    print(-1)
else:
    print(ans)


### FIXED CODE ###

n, ma, mb = map(int, input().split())
abc = [list(map(int, input().split())) for _ in range(n)]

m = n * 10 + 1

dp = [[[float('inf')] * m for j in range(m)] for i in range(n + 1)]
for i in range(n + 1):
    dp[i][0][0] = 0

for i in range(n):
    for j in range(m):
        for k in range(m):
            dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k])

            # i個目を買う
            jj = j + abc[i][0]
            kk = k + abc[i][1]
            if jj < m and kk < m:
                dp[i+1][jj][kk] = min(dp[i+1][jj][kk], dp[i][j][k] + abc[i][2])

from fractions import gcd
ans = float('inf')
for i in range(1, m):
    for j in range(1, m):
        g = gcd(i, j)
        if i // g == ma and j // g == mb:
            ans = min(ans, dp[-1][i][j])

if ans == float('inf'):
    print(-1)
else:
    print(ans)
### BUGGY CODE ###

from collections import defaultdict

def warshall_floyd(V, E):
    INF = 10 ** 10
    d = [defaultdict(lambda: INF) for i in range(V)]
    for i, j, c in E:
        d[i - 1][j - 1] = c
        d[j - 1][i - 1] = c
    for k in range(V):
        for i in range(V - 1):
            for j in range(i, V):
                dk = d[i][k] + d[k][j]
                if d[i][j] > dk:
                    d[i][j] = dk
                    d[j][i] = dk
    return d

N = int(input())
E = [list(map(int, input().split())) for _ in range(N - 1)]
d = warshall_floyd(N, E)

Q, K = map(int, input().split())
for i in range(Q):
    x, y = map(int, input().split())
    print(d[x - 1][K - 1] + d[K - 1][y - 1])


### FIXED CODE ###

def dfs(i, V, E):
    S = [i]
    while(len(S) > 0):
        vi = S.pop()
        d = V[vi]
        for j, value in E[vi].items():
            if V[j] > value + d:
                V[j] = value + d
                S.append(j)
    return V

INF = 10 ** 14
n = int(input())
V = [INF for _ in range(n + 1)]
E = [{} for _ in range(n + 1)]
for i in range(n - 1):
    ai, bi, ci = map(int, input().split())
    E[ai][bi] = ci
    E[bi][ai] = ci

q, k = map(int, input().split())
z = [list(map(int, input().split())) for _ in range(q)]
V[k] = 0

V = dfs(k, V, E)
for i in range(q):
    x, y = z[i]
    print(V[x] + V[y])
### BUGGY CODE ###

s = input()
n = int(input())
query = []
for i in range(n):
    query.append(input().split())
for i in range(n):
    if query[i] == ['1']:
        s = s[::-1]
    elif query[i][1] == '1':
        s = query[i][2] + s
    else:
        s = s + query[i][2]
print(s)


### FIXED CODE ###

from collections import deque
s = input()
n = int(input())
query = []
for i in range(n):
    query.append(input().split())
cond = 1
word = deque(s)
for i in range(n):
    if query[i] == ['1']:
        cond *= -1
    else:
        if cond == 1:
            if query[i][1] == '1':
                word.appendleft(query[i][2])
            else:
                word.append(query[i][2])
        else:
            if query[i][1] == '2':
                word.appendleft(query[i][2])
            else:
                word.append(query[i][2])

result = ''.join(word)
if cond == -1:
    result = result[::-1]
print(result)
### BUGGY CODE ###

n=int(input())
h_list=list(map(int,input().split()))
cnt=0
mx=0
for i in range(len(h_list)):
    if mx>=(len(h_list)-i):
        break
    num=i
    cnt=0
    for num in range(num,len(h_list)-1):
        if h_list[num]>=h_list[num+1]:
            cnt+=1
        else:
            break
    if cnt>mx:
        mx=cnt
print(mx)

### FIXED CODE ###

n=int(input())
h_list=list(map(int,input().split()))
cnt=0
mx=0
i=0
while i<len(h_list):
    if mx>=(len(h_list)-i):
        break
    num=i
    cnt=0
    for j in range(num,len(h_list)-1):
        if h_list[j]>=h_list[j+1]:
            cnt+=1
        else:
            i=j
            break
    i+=1
    if cnt>mx:
        mx=cnt
print(mx)
### BUGGY CODE ###

import math
K = int(input())
total = 0
for x in range(1, K+1):
    for y in range(1, K+1):
        for z in range(1, K+1):
            total = total+math.gcd(x, math.gcd(y, z))
print(total)


### FIXED CODE ###

import math
K = int(input())
total = 0
for x in range(1, K+1):
    for y in range(1, K+1):
        a=math.gcd(x, y)
        for z in range(1, K+1):
            total = total+math.gcd(z, a)
print(total)
### BUGGY CODE ###

N,M = map(int,input().split())
AB = []
for _ in range(N):
  a,b = map(int,input().split())
  AB.append([b,a])
AB.sort(reverse=True)
ans = 0
used = [False for _ in range(M+1)]
for b,a in AB:
  for i in range(M-a,-1,-1):
    if used[i] == False:
      ans += b
      used[i] = True
      break 
print(ans)

### FIXED CODE ###

import heapq

N, M = map(int, input().split())
jobs = {m: [] for m in range(1, M + 1)}
for _ in range(N):
    a, b = map(int, input().split())
    if a in jobs:
        jobs[a].append(b)

q = []
ans = 0
for m in range(1, M + 1):
    for b in jobs[m]:
        heapq.heappush(q, -b)
    if len(q) > 0:
        neg_b = heapq.heappop(q)
        ans += -neg_b

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

N = int(input())
S = input()
Q = int(input())
query = tuple(map(int, input().split()))

for k in query:
    D = 0
    M = 0
    DM = 0
    res = 0
    for i, s in enumerate(S):
        if i >= k:
            if S[i - k] == "D":
                DM -= M
                D -= 1
            elif S[i - k] == "M":
                M -= 1
        if s == "D":
            D += 1
        elif s == "M":
            M += 1
            DM += D
        elif s == "C":
            res += DM
    print(res)

### FIXED CODE ###

N = int(input())
S = input()
Q = int(input())
query = tuple(map(int, input().split()))

for k in query:
    D = 0
    M = 0
    DM = 0
    res = 0
    for i, s in enumerate(S):
        if i >= k:
            if S[i - k] == "D":
                DM -= M
                D -= 1
            elif S[i - k] == "M":
                M -= 1
        if s == "D":
            D += 1
        elif s == "M":
            M += 1
            DM += D
        elif s == "C":
            res += DM
    print(res)
### BUGGY CODE ###

import sys
input = sys.stdin.buffer.readline

def main():
    n, c = map(int, input().split())
    D = [list(map(int, input().split())) for _ in range(c)]
    C_ = [list(map(int, input().split())) for _ in range(n)]
    C = [0]*n
    for i, c_ in enumerate(C_):
        c_ = [x-1 for x in c_]
        C[i] = c_

    #print(C)
    import itertools
    ans = 10**18
    for p in itertools.permutations(range(c), 3):
        temp = 0
        for i in range(n):
            for j in range(n):
                m = (i+j)%3
                x = C[i][j]
                y = p[m]
                temp += D[x][y]
        ans = min(ans, temp)
    print(ans)

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline

def main():
    n, c = map(int, input().split())
    D = [list(map(int, input().split())) for _ in range(c)]
    C_ = [list(map(int, input().split())) for _ in range(n)]
    C = [0]*n
    for i, c_ in enumerate(C_):
        c_ = [x-1 for x in c_]
        C[i] = c_

    #print(C)
    L = [[0]*c for _ in range(3)]
    for k in range(c):
        for i in range(n):
            for j in range(n):
                m = (i+j)%3
                x = C[i][j]
                L[m][k] += D[x][k]
                
    X = [[] for _ in range(3)]
    for j in range(3):
        for i, x in enumerate(L[j]):
            X[j].append((x, i))
    for i, x in enumerate(X):
        x.sort()
        x = x[0:3]
        X[i] = x

    #print(X)
    import itertools
    ans = 10**18
    for p in itertools.product(range(3), repeat=3):
        used_col = set()
        temp = 0
        for j in range(3):
            x, i =X[j][p[j]]
            if i in used_col:
                break
            else:
                temp += x
                used_col.add(i)
        else:
            ans = min(temp, ans)
    print(ans)

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

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

while True:
  if abs(N-K) < N:
    N = abs(N-K)
  else:
    break
    
print(str(N))


### FIXED CODE ###

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

middle = N % K
answer = middle
while True:
  if abs(answer-K) > N:
    answer = N
    break
  if abs(answer - K) < answer:
    answer = abs(answer-K)
  else:
    break
    
print(str(answer))
### BUGGY CODE ###

n=int(input())
phrase=[tuple(map(int,input().split())) for i in range(n)]
m=int(input())
inf=float('inf')
def main(phrase):
    w=int(input())
    dp=[-1*inf for _ in range(w+1)]
    dp[0]=0
    for i in range(1,w+1):
        for x in phrase:
            s,l,p=x
            for k in range(s,l+1):
                if i-k<0:break
                dp[i]=max(dp[i-k]+p,dp[i])
    return dp[w] if dp[w]>=0 else -1
ans=[]
for i in range(m):
    res=main(phrase)
    if res==-1:
        print(-1)
        break
    ans.append(res)
    if i==m-1:
        for i in range(m):
            print(ans[i])


### FIXED CODE ###

n=int(input())
phrase=[tuple(map(int,input().split())) for i in range(n)]
m=int(input())
inf=float('inf')
def main(phrase):
    point=[-1 for _ in range(394)]
    for x in phrase:
        s,l,p=x
        for k in range(s,l+1):
            point[k]=max(point[k],p)
    point[0]=0
    for i in range(1,394):
        for j in range(i):
            point[i]=max(point[i-j]+point[j],point[i])
    return point
ans=[]
dp=main(phrase)
for i in range(m):
    res=dp[int(input())]
    if res==-1:
        print(-1)
        break
    ans.append(res)
    if i==m-1:
        for i in range(m):
            print(ans[i])
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
for _ in range(Q):
  l = list(map(int, input().split()))
  B.append(l[0])
  C.append(l[1])

for i in range(Q):
  for j in range(len(A)):
    if A[j] == B[i]:
      A[j] = C[i]
  print(sum(A))

### FIXED CODE ###

from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
D = defaultdict(int)
for a in A:
  D[a] += 1
Q = int(input())
B = []
C = []
for _ in range(Q):
  l = list(map(int, input().split()))
  B.append(l[0])
  C.append(l[1])

ans = sum(A)
for i in range(Q):
  k = D[B[i]]
  D[B[i]] = 0
  D[C[i]] += k
  ans = ans - (B[i]*k) + (C[i]*k)
  print(ans)
### BUGGY CODE ###

N = int(input())
alist = list(map(int, input().split()))
for i in range(1,N+1):
  print(alist.count(i))

### FIXED CODE ###

from collections import Counter

N = int(input())
a = list(map(int, input().split()))
c = Counter(a)
for i in range(1,N+1):
  print(c[i])