Harryxun/stf_run huggingface dataset:
A = input()
B = input()
for i in range(len(A)):
if(A == B):
　　print("Yes")
　　exit()
　　A = (A+A[0])[1:]
print("No")


### FIXED CODE ###

A = input()
B = input()
for i in range(len(A)):
    if A == B:
        print("Yes")
        exit()
    A = (A+A[0])[1:]
print("No")
import math
A,B=map(int,input().split())
print(int(A*B/math.gcd(A,B)))

### FIXED CODE ###

import fractions
A,B=map(int,input().split())
print(int(A*B/fractions.gcd(A,B)))
A, B, C = map(int,input().split())

n = 100 * B

for i in range(1, n, B):
  if A * i % B == C:
    print("YES")
    flag = True:
    break
  else:
    continue

if flag != True:
  print("No")
  


### FIXED CODE ###

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

for i in range(B):
  if A * i % B == C:
    print("YES")
    exit()
  else:
    continue
print("NO")
# 方針　union findで解く
n, m = map(int, input().split())  # 入力の受け取り
par = [i for i in range(1, n + 1)]  # 親のリストを作成


# find関数を作成。自分の値とリスト番号を比べ、親ならば返し、子ならば親を探す
# par[x-1]としているのは、例えばpar[0]=1になっているため
def find(x):
    if par[x - 1] == x:
        return x
    else:
        par[x - 1] = find(par[x - 1])
        return par[x - 1]


# union関数を作成。2つの引数の親を比べ、違う場合は一方の親を一方の子にする
def union(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return 0
    par[x - 1] = y


# 入力すべてでunionする
for j in range(m):
    a, b = map(int, input().split())
    union(a, b)

# n人の親を探して、リストsに入れ、それぞれ親の数をカウントし、最頻値をグループ数とする。
#s = [find(i) for i in range(1, n + 1)]
import collections
c = collections.Counter(s)
print(max(c.values()))


### FIXED CODE ###

import collections
n, m = map(int, input().split())
par = list(range(2 * n))

# print(par)


# union find(parには0も入れているので、par[1]=1になる)
def find(x):

    while par[x] != x:
        tmp = par[x]
        par[x] = par[par[x]]
        x = par[x]

    return x


def union(x, y):
    x1 = find(x)
    y1 = find(y)
    if x1 != y1:
        par[x1] = y1


# 各要素をunionする
for j in range(m):
    a, b = map(int, input().split())
    union(a - 1, b - 1)

s = [0 for i in range(n + 5)]

# 1～nの親を探してsに入れていき、一番多い親を答えにする
for k in range(n):
    s[find(k)] += 1

print(max(s))
cache = {0: 1, 1: 1, 2: 2}
combo_cache = {}


def permutuation(n):
    if n in cache:
        return cache[n]
    return n * permutuation(n - 1)


def combo(n, r):
    key = str(n) + "-" + str(r)
    if key in combo_cache:
        return combo_cache[key]

    x = permutuation(n)
    y = permutuation(n-r)
    z = permutuation(r)
    combo_cache[key] = int(x / (y * z))
    return combo_cache[key]


count = int(input())
li = list(map(int, input().split()))

sli = sorted(li)

pair_a = 0
pair_b = 0
current_max = 0

for i in range(1,len(sli)):
    for j in range(0, i):
        val = combo(sli[i], sli[j])
        # print(str(sli[i]) + ", " + str(sli[j]) + ", " + str(val))
        if val > current_max:
            current_max = val
            pair_a = sli[i]
            pair_b = sli[j]

print(str(pair_a) + " " + str(pair_b))

### FIXED CODE ###

count = int(input())
li = list(map(int, input().split()))

sli = sorted(li)

pair_a = sli[len(sli) - 1]
pair_b = 0
current_max = 0

i = sli[len(sli) - 1]

diff = 10**9
for j in range(0, len(sli) - 1):
    h = pair_a / 2
    if abs(h - sli[j]) < diff:
        diff = abs(h - sli[j])
        pair_b = sli[j]

print(str(pair_a) + " " + str(pair_b))
a,b,t=map(int, input().split())
print int((t+0.5)/a*b)

### FIXED CODE ###

a,b,t=map(int, input().split())
print(int((t+0.5)/a)*b)
a,b,c,d=[int(input()) for i in [0]*4]
print(n,k,x,y=(int(input()) for i in [0]*4))

### FIXED CODE ###

n,k,x,y=[int(input()) for i in [0]*4]
print(n*x-(x-y)*max(n-k,0))
# -*- coding: utf-8 -*-
def Palindrome(S):
    if int(len(S)/2)==int((len(S)+1)/2):
        return "No"
    for i in range(int(len(S)/2)):
        if S[i]==S[len(S)-i-1]:
            YorN="Yes"
        else:
            YorN="No"
            break
    return YorN
S = input()
Sl = list(S)
left = right = "No"
if Palindrome(Sl) == "Yes":
    middle=int(len(Sl)/2)
    left  = Palindrome(Sl[:middle])
    right = Palindrome(Sl[middle+1:])
if left == "Yes" and right == "Yes":
    YorN = "Yes"
else:
    YorN = "No"
print(YorN)


### FIXED CODE ###

# -*- coding: utf-8 -*-
def Palindrome(S):
    if len(S)==1:
        return "Yes"
    for i in range(int((len(S))/2)):
        if S[i]==S[len(S)-i-1]:
            YorN="Yes"
        else:
            YorN="No"
            break
    return YorN
S = input()
Sl = list(S)
left = right = "No"
if Palindrome(Sl) == "Yes":
    middle=int((len(Sl)-1)/2)
#    print(Sl[:middle],Sl[middle+1:])
    left  = Palindrome(Sl[:middle])
    right = Palindrome(Sl[middle+1:])
if left == "Yes" and right == "Yes":
    YorN = "Yes"
else:
    YorN = "No"
print(YorN)
#input_f = "3 4 5\n2 1 2\n6 3 4\n1 1 1\n1 2 3"
input_f = input()

counter = [0, 0, 0]

def t_check(a,b,c):
    if a + b > c:
        if b + c > a:
            if a + c > b: return True
    return False



def f_check(a_, b_, c_):
    tmp = []
    tmp.append(a_)
    tmp.append(b_)
    tmp.append(c_)
    sqrts = []
    for i in range(3):
        sqrts.append(tmp[i]**2)
    m = max(sqrts)
    s = sum(sqrts)

    print(m,s)
    
    if m == (s - m): return(0)
    if m > (s - m): return(2)
    if m < (s - m): return(1)
 
    
for i in range(int(len(input_f))):
    t = input_f.split("\n")[i].split()
    fn, sn, tn = int(t[0]),int(t[1]),int(t[2])
    if t_check(fn,sn,tn):
        counter[f_check(fn,sn,tn)] += 1
    else: 
        print(sum(counter),counter[0], counter[1], counter[2])
        break       



### FIXED CODE ###

def t_check(a,b,c):
    if a + b > c:
        if b + c > a:
            if a + c > b: return True
    return False

def f_check(a_, b_, c_):
    tmp = []
    tmp.append(a_)
    tmp.append(b_)
    tmp.append(c_)
    sqrts = []
    for i in range(3):
        sqrts.append(tmp[i]**2)
    m = max(sqrts)
    s = sum(sqrts)

    if m == (s - m): return(0)
    if m > (s - m): return(2)
    if m < (s - m): return(1)
    
counter=[0,0,0]
    
while(1):
    input_f = input()

    t = input_f.split()
    fn, sn, tn = int(t[0]),int(t[1]),int(t[2])
    if t_check(fn,sn,tn):
        counter[f_check(fn,sn,tn)] += 1
    else: break
    
print(sum(counter),counter[0], counter[1], counter[2])
a = input()
b = input()
c = input()
d = input()
 
xy1 = a*c
xy2 = a*d
xy3 = b*c
xy4 = b*d
 
print(max([xy1, xy2, xy3, xy4]))

### FIXED CODE ###

a, b, c, d = input().split() 
a = int(a)
b = int(b)
c = int(c)
d = int(d)
xy1 = a*c
xy2 = a*d
xy3 = b*c
xy4 = b*d
 
print(max([xy1, xy2, xy3, xy4]))
n = int(input())
h = list(map(int, input().split()))
# 増加してるマスのあたりをつけてあたりとあたりの距離で勝負する
check_point = [0]

for i in range(len(h)):
    if i == 0:
        continue
    if h[i-1] < h[i]:
        check_point.append(i)
if len(check_point) == 1:
    print(n-1)
diffs = list()
if check_point[-1] != n-1:
    check_point.append(n-1)
for i in range(len(check_point)):
    if i == 0:
        continue
    if check_point[i] == n-1 and h[n-1] <= h[n-2]:
        ans = check_point[i] - check_point[i - 1]
    else:
        ans = check_point[i] - 1 - check_point[i-1]
    diffs.append(ans)
print(max(diffs))


### FIXED CODE ###

def main():
    n = int(input())
    h = list(map(int, input().split()))
    # 増加してるマスのあたりをつけてあたりとあたりの距離で勝負する
    check_point = [0]
    if len(h) == 1:
        return 0
    for i in range(len(h)):
        if i == 0:
            continue
        if h[i - 1] < h[i]:
            check_point.append(i)
    if len(check_point) == 1:
        return n-1
    diffs = list()
    if check_point[-1] != n - 1:
        check_point.append(n - 1)
    for i in range(len(check_point)):
        if i == 0:
            continue
        if check_point[i] == n - 1 and h[n - 1] <= h[n - 2]:
            ans = check_point[i] - check_point[i - 1]
        else:
            ans = check_point[i] - 1 - check_point[i - 1]
        diffs.append(ans)
    return max(diffs)

# 0 ~ ci-1 間、 c1  ~ c2-1 間、 c2 ~ end間の距離のうちの最大値を求めてみる

answer = main()
print(answer)
S = str(input())
if S = "ABC":
  print("ARC")
elif S = "ARC":
  print("ABC")

### FIXED CODE ###

S = str(input())
if S == "ABC":
  print("ARC")
elif S == "ARC":
  print("ABC")
s = input("")

if s >= 0 and s < 86400:
    h = s / 3600
    m = (s % 3600) / 60
    s = ((s % 3600) % 60) % 60

print("{0:d}:{1:d}:{2:d}".format(h, m, s))

### FIXED CODE ###

second = int(input(""))

if second >= 0 and second < 86400:
    h = int(second / 3600)
    m = int((second % 3600) / 60)
    s = int(((second % 3600) % 60) % 60)

print("{0}:{1}:{2}".format(h, m, s))
n,l=map(int,input().split())
s=[]
for i range(n):
  s.append(input())
s.sort()
ans=''
for x in s:
  ans+=x
print(ans)


### FIXED CODE ###

n,l=map(int,input().split())
s=sorted([input() for i in range(n)])
print(*s,sep="")
def a_kenken_race(N, A, B, C, D, S):
    # cond1: 道のりの途中に岩が2つ連続する場所があると、ゴールに到達できない
    # cond2: ふぬけ君の道のりの途中に空きが3マス分ないと、すぬけ君が追い越せない
    cond1 = S[A:C + 1].count('##') == 0 and S[B:D + 1].count('##') == 0
    cond2 = S[B:D + 1].count('...') >= 1
    if C < D:
        # ふぬけ君をゴールに行かせてからすぬけ君をゴールに行かせればよい
        ans = 'Yes' if cond1 else 'No'
    else:
        # すぬけ君は途中でふぬけ君を追い越せないといけない
        ans = 'Yes' if cond1 and cond2 else 'No'
    return ans

S = input()
print(a_kenken_race(N, A, B, C, D, S))

### FIXED CODE ###

def a_kenken_race(N, A, B, C, D, S):
    # cond1: 道のりの途中に岩が2つ連続する場所があると、ゴールに到達できない
    # cond2: ふぬけ君の道のりの途中に空きが3マス分ないと、すぬけ君が追い越せない
    cond1 = '##' in S[A - 1:C] or '##' in S[B - 1:D]
    cond2 = '...' not in S[B - 2:D + 1]

    if cond1:
        ans = 'No'
    elif C > D and cond2:
        ans = 'No'
    else:
        ans = 'Yes'  # ふぬけ君から順にゴールさせる/すぬけ君が追い越す ことができる
    return ans

N, A, B, C, D = [int(i) for i in input().split()]
S = input()
print(a_kenken_race(N, A, B, C, D, S))
# def makelist(n, m):
# 	return [[0 for i in range(m)] for j in range(n)]

# n = int(input())
# a, b = map(int, input().split())
# s = input()


rei = "CODEFESTIVAL2016"
s = input()

ans = 0
for i in range(s):
	if rei[i] != s[i]:
		ans += 1

print(ans)


### FIXED CODE ###

# def makelist(n, m):
# 	return [[0 for i in range(m)] for j in range(n)]

# n = int(input())
# a, b = map(int, input().split())
# s = input()


rei = "CODEFESTIVAL2016"
s = input()

ans = 0
for i in range(len(s)):
	if rei[i] != s[i]:
		ans += 1

print(ans)
from collections import deque
x,y,a,b,c = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]
q = [int(x) for x in input().split()]
r = [int(x) for x in input().split()]
#入力を受け取った
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
d = deque(r)
#ソートした。rはdequeにした
aka = x-1#赤いリンゴのうち、交換するか調べるもの
midori = y-1#緑リンゴ同上
while True:
  siraberu = d.popleft()#無職リンゴのうち一番美味しいものを取り出す
  if min(p[aka],q[midori]) < siraberu:#調べるリンゴのうちのまずい方がsiraberuよりまずいか
    if p[aka] <= q[midori]:#調べる赤リンゴの方がまずいとき
      p[aka] = siraberu#交換
      aka = aka - 1#調べるものを一個ずらす
    else:
      q[midori] = siraberu
      midori = midori - 1
  if aka == -1:
    aka = 0
  elif midori == -1:
    midori = 0
  else:
    break
pd = deque(p)
qd = deque(q)
ans = 0
for i in range(x):
  ans = ans + pd.popleft()
for i in range(y):
  ans = ans + qd.popleft()
print(ans)

### FIXED CODE ###

from collections import deque
x,y,a,b,c = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]
q = [int(x) for x in input().split()]
r = [int(x) for x in input().split()]
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
d = deque(r)
aka = x-1
midori = y-1
ps = p[:x]
qs = q[:y]
li = ps + qs
li.sort(reverse=True)
i = 0
z = d.popleft()
while li[x+y-1-i] < z:
  li[x+y-1-i] = z
  i += 1
  if not d:
    break
  z = d.popleft()
ans = 0
for i in range(x+y):
  ans += li[i]
print(ans)
s=input()
sc=0
tc=0
for i in s:
  if i=="S":
    sc+=1
  elif sc!=0:
    sc-=1
  else tc+=1
print(tc+sc)

### FIXED CODE ###

s=input()
sc=0
tc=0
for i in s:
  if i=='S':
    sc+=1
  elif sc!=0:
    sc-=1
  else :tc+=1
print(tc+sc)
n,m,x = map(int,input().split())
a = list(map(int,input().split()))

a.append(x)
a = sorted(a)

if len(a[:a.index(x)]) >= len(a[-(a.index(x)+1):]):
  print(len(a[-(a.index(x)+1):]))
else:
  print(len(a[:a.index(x)]))

### FIXED CODE ###

A,B,X = map(int,input().split())
if A <= X <= A+B :
  print("YES")
else :
  print("NO")
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")



M = 10**9+7
N = 4*10**5+3 # 必要なテーブルサイズ

def cmb(n, r, M):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return (g1[n] * g2[r] * g2[n-r]) % M

g1 = [None] * (N+1) # 元テーブル
g2 = [None] * (N+1) #逆元テーブル
inverse = [None] * (N+1) #逆元テーブル計算用テーブル
g1[0] = g1[1] = g2[0] = g2[1] = 1
inverse[0], inverse[1] = [0, 1] 

for i in range( 2, N + 1 ):
    g1[i] = ( g1[i-1] * i ) % M 
    inverse[i] = ( -inverse[M % i] * (M//i) ) % M # ai+b==0 mod M <=> i==-b*a^(-1) <=> i^(-1)==-b^(-1)*aより
    g2[i] = (g2[i-1] * inverse[i]) % M 

n,k = map(int, input().split())
M = 10**9+7
if k<n:
    ans = 0
    for p in range(k+1):
        ans += cmb(n,p,M) * cmb(n-1+p, p)
        ans %= M
else:
    ans = cmb(2*n-1,n,M)
print(ans)

### FIXED CODE ###

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")



M = 10**9+7
N = 4*10**5+3 # 必要なテーブルサイズ

def cmb(n, r, M):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return (g1[n] * g2[r] * g2[n-r]) % M

g1 = [None] * (N+1) # 元テーブル
g2 = [None] * (N+1) #逆元テーブル
inverse = [None] * (N+1) #逆元テーブル計算用テーブル
g1[0] = g1[1] = g2[0] = g2[1] = 1
inverse[0], inverse[1] = [0, 1] 

for i in range( 2, N + 1 ):
    g1[i] = ( g1[i-1] * i ) % M 
    inverse[i] = ( -inverse[M % i] * (M//i) ) % M # ai+b==0 mod M <=> i==-b*a^(-1) <=> i^(-1)==-b^(-1)*aより
    g2[i] = (g2[i-1] * inverse[i]) % M 

n,k = map(int, input().split())
M = 10**9+7
if k<n:
    ans = 0
    for p in range(k+1):
        ans += cmb(n,p,M) * cmb(n-1, p, M)
        ans %= M
else:
    ans = cmb(2*n-1,n,M)
print(ans)
N,M = map(int,input().split())
sc = {}
flag = False
smax = 0
for i in range(M):
    s,c = map(int,input().split())
    smax = max(s,smax)
    if s > N:
        flag = True
        break
    elif s not in sc:
        sc[s] = c
    else:
        if sc[s] != c:
            flag = True
            break
if flag:
    print(-1)
else:
    ans = [0 for i in range(smax)]
    for s,c in sc.items():
        ans[s-1] = c
    if ans[0] == 0:
        print(-1)
    else:
        print(*ans,sep='')

### FIXED CODE ###

N,M = map(int,input().split())
sc = {}
flag = False
for i in range(M):
    s,c = map(int,input().split())
    if N!=1 and s==1 and c == 0:
        flag =True
        break
    elif s not in sc:
        sc[s] = c
    else:
        if sc[s] != c:
            flag = True
            break
if flag:
    print(-1)
elif N == 1 and M == 0:
    print(0)
else:
    if N == 1:
        print(sc[1])
    else:
        ans = [0 for i in range(N)]
        ans[0] = 1

        for s,c in sc.items():
            ans[s-1] = c
        print(*ans,sep='')
        print()
n=int(input())
a=list(for i in range(n))
b=0
for i in range(n):
  if a[i]-a[i+1]>=2:
    b+=1
if b==0:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
b=0
c=a.reverse()
d=0
for i in range(n-1):
  if a[i]-a[i+1]==-1:
    a[i+1]=a[i+1]-1
  elif a[i]-a[i+1]<=-2:
    b+=1
  else:
    d=d
    
if b==0:
  print("Yes")
else:
  print("No")
N,K = map(int, input().split())
A =[0]
B=list(map(int, input().split()))
for m in range(N):
    A.append(B[m])
place=set([])
p=[]
i=1
count=0
while i not in place:
    place.add(i)
    p.append(i)
    i=A[i]
    count+=1
if count>=K:
    print(p[K])
else:
    loop=[i]
    start=i
    j=A[i]
    count+=1
    while j!=start:
        loop.append(j)
        j=A[j]
        count+=1
    if count>=K:
        print(loop[K-len(p)])
    else:
    num=(K-count)%len(loop)
    print(loop[num])

### FIXED CODE ###

N,K = map(int, input().split())
A =[0]
B=list(map(int, input().split()))
for m in range(N):
    A.append(B[m])
place=set([])
p=[]
i=1
count=0
while i not in place:
    place.add(i)
    p.append(i)
    i=A[i]
    count+=1
if count>K:
    print(p[K])
else:
    loop=[i]
    start=i
    j=A[i]
    count+=1
    while j!=start:
        loop.append(j)
        j=A[j]
        count+=1
    if count>K:
        print(loop[K-len(p)])
    else:
        num=(K-count)%len(loop)
        print(loop[num])
a = input()
    b = input()
    if len(b)> len(a) and a==b[:len(a)]:
      print('Yes')
    else:
      print('No')

### FIXED CODE ###

a = input()
b = input()
if (len(b)>len(a)) and (a==b[:len(a)]):
  print('Yes')
else:
  print('No')
m=input()
a=int(m[0])-1+(len(m)-1)*9
b=0
for i in n:
  b+=i
print(max(b,a))

### FIXED CODE ###

n = input()
a = int(n[0])-1 + (len(n)-1)*9
b = 0
for i in n:
    b += int(i)
print(max(a, b))
N,Q = map(int,input().split())

tree = [[0]*N for _ in range(N)]

for i in range(N-1):
    x,y = map(int,input().split())
    x -= 1
    y -= 1
    tree[y].append(x)
    tree[x].append(y)
ans = [0]*N
for i in range(Q):
    x,y = map(int,input().split())
    ans[x-1] += y
    

def dfs(cur,par):
    for chl in tree[cur]:
        if chl == par: #これで木の流れの逆行を防ぐ
            continue
        ans[chl] += ans[cur]
        dfs(chl,cur)
    
dfs(0,-111111)
print(*ans)

### FIXED CODE ###

n,q=map(int,input().split())
ab=[]
for i in range(n-1):
	x,y=map(int,input().split())
	ab.append([x,y])
ab.sort()
ans=[0]*n
cnt=[0]*n
for i in range(q):
	x,y=map(int,input().split())
	ans[x-1]+=y
for i in range(n-1):
	ans[ab[i][1]-1]+=ans[ab[i][0]-1]
print(*ans)
N, *p = map(int, open(0).read().split())

if sum(p[i] != i + 1 for i in range(N)) <= 2:
    print('YES')
else:
    print('NO')


### FIXED CODE ###

N=int(input())
P=list(map(int,input().split()))
w=0
for i in range(N):
	if P[i]!=i+1:
		w+=1
else:
	print("NO" if w>2 else "YES")
h, n = map(int, input().split())

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

print(S)

dic={}


def rec(magic, nokori,sum_mp):

    if str(magic)+"_"+str(nokori) in dic:
        return dic[str(magic)+"_"+str(nokori)]

    if nokori<=0:
        return sum_mp
    if magic >= len(S):
        return 10**9

    dmg = S[magic][0]
    mp  = S[magic][1]

    min_mp = min(
        rec(magic  ,nokori-dmg,sum_mp+mp), # use this magic, and check this magic again
        rec(magic+1,nokori-dmg,sum_mp+mp), # use this magic, and check next magic                    rec(magic+1,nokori,sum_mp       ), # don't use this magic, and check next magic
        )

    dic[str(magic)+"_"+str(nokori)] = min_mp
    return min_mp

print(rec(0,h,0))

### FIXED CODE ###

h, n = map(int, input().split())
s = []
for _ in range(n):
    D = list(map(int, input().split()))
    s.append(D)

dp = [[10**10 for i in range(h+1)] for j in range(n+1)]
dp[0][0] = 0

for i in range(n):
    dmg=s[i][0]
    mp=s[i][1]
    for j in range(h+1):
        dp[i+1][j] = min(dp[i+1][j],dp[i][j])
        dp[i+1][min(j+dmg,h)] = min(dp[i+1][min(j+dmg,h)], dp[i+1][j]+mp)

print(dp[-1][-1])
import sys
A, B, K= map(int, sys.stdin.buffer)
x = min(A, B, K)
print(A - x, B - x)

### FIXED CODE ###

import sys
A, B, K= map(int, next(sys.stdin.buffer).split())
if K > A:
  a = 0
  b = max(0, B - (K - A))
else:
  a = A - K
  b = B

print(a, b)
import numpy as np

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

dp = np.zeros(W+1, dtype=np.int64)

for _ in range(N):
    w, v = map(int, input().split())
    np.maximum(dp[:-w]+v, dp[w:], out=dp[w:])

print(dp[-1])


### FIXED CODE ###

# import numpy as np
#
# N, W = map(int, input().split())
#
# dp = np.zeros(W+1, dtype=np.int64)
#
# for _ in range(N):
#     w, v = map(int, input().split())
#     np.maximum(dp[:-w]+v, dp[w:], out=dp[w:])
#
# print(dp[-1])


import numpy as np

N, W = map(int, input().split())
dp = np.full(N * 1000 + 1, 10 ** 10, dtype=np.int64)
# print(dp)
# print(len(dp))
dp[0] = 0
for _ in range(N):
    w, v = map(int, input().split())
    np.minimum(dp[:-v] + w, dp[v:], out=dp[v:])
print(((dp <= W) * np.arange(N * 1000 + 1)).max())
import sys

def add_count(addnum, relations, counters, nodelist):
  new_nodelist = []
  for node in nodelist:
    if node not in relations:
      continue
    else:
      new_nodelist = new_nodelist + relations[node]
      for child in relations[node]:
        counters[child-1] += addnum
  
  if len(new_nodelist) == 0:
    return counters
  else:
    return add_count(addnum, relations, counters, new_nodelist)

N, Q = map(int, sys.stdin.readline().split())
alist = list(list(map(int, sys.stdin.readline().split())) for i in range(N-1))
qlist = list(list(map(int, sys.stdin.readline().split())) for i in range(Q))

counters = [0 for i in range(N)]
relations = {}
for a in alist:
  if a[0] not in relations:
    relations[a[0]] = [a[1]]
  else:
    relations[a[0]].append(a[1])
    
for q in qlist:
  counters[q[0]-1] += q[1]
  counters = add_count(q[1], relations, counters, [q[0]])

print(' '.join(map(str,counters)))

### FIXED CODE ###

import sys
a = int(sys.stdin.readline())
if a >= 3200:
  print(sys.stdin.readline())
else:
  print('red')
import sys
sys.setrecursionlimit(200000)
 
n = int(input())
l = list(map(int, input().split(" ")))
 
def dp(i, curr_cost):
	if n -1 < i:
		return curr_cost
	one = dp(i+1, curr_cost + abs(l[i] - l[i+1]))
	two = dp(i+2, curr_cost + abs(l[i] - l[i+2]))	
	return max[one, two]
 
print(dp(0, 0))

### FIXED CODE ###

import sys

n = int(input())
l = list(map(int, input().split(" ")))
dp= [0]*n
dp[1] = abs(l[1] - l[0])

for i in range(2, n):
	one = dp[i - 1] + abs(l[i] - l[i-1])
	two = dp[i - 2] + abs(l[i] - l[i-2])	
	dp[i] = min([one, two])

print(dp[n-1])
class Solution:
	def solve(self, sHeights):
		if not sHeights or len(sHeights) == 0:
			return 0
			
		n = len(sHeights)
			
		dp = [0 for _ in range(n)]
		dp[0] = 0
		dp[1] = abs(sHeights[1] - sHeights[0])
		
		for i in range(2, n):
			dp[i] = min(dp[i-2] + abs(sHeights[i] - sHeights[i-2]), dp[i-1] + abs(sHeights[i] - sHeights[i-1]))
			
		print(dp)
			
		return dp[n-1]
		
sol = Solution()

# s = [10, 30, 40, 20]
# s = [10, 10]
# s = [30,10,60,10,60,50]

int n = int(input().strip())
s = list(map(int, input().strip().split())
print(sol.solve(s))

### FIXED CODE ###

class Solution:
  def solve(self, sHeights):
    if not sHeights or len(sHeights) == 0:
      return 0
    
    n = len(sHeights)
    
    dp = [0 for _ in range(n)]
    dp[0] = 0
    dp[1] = abs(sHeights[1] - sHeights[0])
    
    for i in range(2, n):
      dp[i] = min(dp[i-1] + abs(sHeights[i] - sHeights[i-1]), dp[i-2] + abs(sHeights[i] - sHeights[i-2]))
      
    return dp[n-1]
  
sol = Solution()

n = int(input().strip())

s = list(map(int, input().strip().split()))

print(sol.solve(s))
n,m = map(int,input().split())
a_ls = list(map(int, input().split()))
n_b = 0
b_ls = [[0,0] for _ in range(m)]
for i in range(m):
    num, c = map(int,input().split())
    n_b += num
    b_ls[i] = [num,c]
c_ls = [0] * n_b
j = 0
rest = b_ls[0][0]
i = 0
while j < n_b:
    c_ls[j] = b_ls[i][1]
    j += 1
    rest -= 1
    if rest <= 0:
        i += 1
        if i == m:
            break
        rest = b_ls[i][0]
a_ls = a_ls + c_ls
a_ls.sort(reverse= True)
print(sum(a_ls[:n]))



### FIXED CODE ###

from collections import Counter
n,m = map(int,input().split())
a_ls = list(map(int, input().split()))
counter = Counter(a_ls)
for i in range(m):
    b,c = map(int,input().split())
    counter[c] += b

cards = sorted(counter.items(), key = lambda x:x[0], reverse=True)
rest = n
Sum = 0
for num, count in cards:
    if count < rest:
        Sum += num * count
        rest -= count
    else:
        Sum += rest * num
        break
print(Sum)
import numpy as np

N = int(input())
a = np.array(list(map(int, input().split())))
Q = int(input())
bc = [list(map(int, input().split())) for _ in range(Q)]

for i in range(Q):
    b, c = bc[i]
    a[a == b] = c
    print(np.sum(a))

### FIXED CODE ###

from collections import Counter

N = int(input())
a = Counter(map(int, input().split()))
Q = int(input())

sum_a = sum(a.elements())

for i in range(Q):
    b, c = map(int, input().split())
    a[c] += a[b]
    sum_a += (c-b) * a[b]
    a[b] = 0
    print(sum_a)