Harryxun/stf_run huggingface dataset:
#

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

def solve(s, t):
    # print('{} {}'.format(s, t))
    if len(t) == 0:
        return 0
    if s.find(t[0]) == -1:
        return -1
    i = 0
    j = 0
    while i < len(s) and j < len(t):
        target = s[i:]
        pos = target.find(t[j])
        # print('pos = {} t = {}'.format(pos, t[j]))
        if pos == -1:
            break
        i += pos + 1
        j += 1

    if j == len(t):
        return i
    else:
        rest = solve(s, t[j:])
        return len(s) + rest if rest != -1 else -1

def main():
    s = input()
    t = input()

    # check can or cannot
    print(solve(s, t))


if __name__ == '__main__':
    main()


### FIXED CODE ###

#

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


def solve(positions, s, t):

    if not set(t) <= set(s):
        return -1

    loop = 0
    prev = -1

    for tchar in t:
        candidates = positions[tchar]
        pos = bisect.bisect_right(candidates, prev)

        if pos == len(candidates):
            loop += 1
            pos = 0
        prev = candidates[pos]

    return loop * len(s) + prev + 1


def main():
    s = input()
    t = input()

    positions = defaultdict(list)
    for i in range(len(s)):
        positions[s[i]].append(i)

    print(solve(positions, s, t))


if __name__ == '__main__':
    main()
n = int(input())
lr = [0] * n
for i in range(n):
    lr[i] = list(map(int, int().split()))
s = 0
for i, j in lr:
    s += j - i + 1
print(s)


### FIXED CODE ###

n = int(input())
s = 0
for i in range(n):
    l, r = map(int, input().split())
    s += r - l +1
print(s)
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)

N, M = LI()
A = []
for i in range(M):
    A.append(_I())

"""
飛び越える前までの道筋の通りを調べてかけていく
"""

# 連続した壊れた段がある場合は0
B = [i for i in A]
B.remove(B[0])
B.append(10**15)
diffs = [b - a for a, b in zip(A,B)]
#  print(diffs)

if any(i == 1 for i in diffs):
    # 隣同士なので0
    print(0)
    exit()

# 隣り合うものがないので、各区間の通りを出していく
res = [0 for _ in range(N)]
for aidx in range(len(A)+1):
    if aidx == 0:
        start = 0
    else:
        start = A[aidx-1] + 1

    if aidx == len(A):
        # last item
        end = N
    else:
        end = A[aidx] - 1
    #ぐうきで分ける、一箇所を2とびにした場合、2箇所を2とびにした場合などで変える
    r = end - start
    max_2_steps = r // 2
    #  print('ma', max_2_steps)
    for i in range(max_2_steps + 1):
        tmp = r
        tmp -= 2 * i
        #  print('i,r,tmp', i, r, tmp)
        # tmpが1段ずつになる
        res[aidx] += int(math.factorial(i + tmp) / (math.factorial(tmp) * math.factorial(i)))

#  print(res)
ans = 0
for r in res:
    if r == 0:
        continue
    if ans == 0:
        ans = r
    else:
        ans *= r
print(ans % mod)


### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys

mod = 10 ** 9 + 7

def get_nums(n):
    res = [0 for _ in range(n)]
    for i in range(n):
        res[i] = int(input())
    return res


def get_numbers():
    return map(int, input().split())


n, m = get_numbers()
a = set(get_nums(m))

dp = [0 for _ in range(n + 1)]
dp[0] = 1
if 1 not in a:
    dp[1] = 1

for i in range(2, n + 1):
    if i not in a:
        dp[i] = dp[i - 1] + dp[i - 2]
        dp[i] %= mod

print(dp[-1])
n = int(input())
data = []
for i in range(n):
    xi,yi,hi = map(int,input().split())
    data.append((xi,yi,hi))
lst = [[] for _ in range(n)]
data.sort(key = lambda x:x[2],reverse = True)
x,y,h = data[0]
for i in range(101):
    for j in range(101):
        lst[0].append((i,j,h+abs(i-x)+abs(j-y)))
for i in range(1,n):
    xi,yi,hi = data[i]
    if hi > 0:
        for x,y,h in lst[i-1]:
            if abs(x-xi)+abs(y-yi)+hi == h:
                lst[i].append((x,y,h))
    else:
        for x,y,h in lst[i-1]:
            if abs(x-xi)+abs(y-yi) >= h:
                lst[i+1].append((x,y,h))
print(*lst[n-1][0])

### FIXED CODE ###

n = int(input())
data = []
for i in range(n):
    xi,yi,hi = map(int,input().split())
    data.append((xi,yi,hi))
lst = [[] for _ in range(n)]
data.sort(key = lambda x:x[2],reverse = True)
x,y,h = data[0]
for i in range(101):
    for j in range(101):
        lst[0].append((i,j,h+abs(i-x)+abs(j-y)))
for i in range(1,n):
    xi,yi,hi = data[i]
    if hi > 0:
        for x,y,h in lst[i-1]:
            if abs(x-xi)+abs(y-yi)+hi == h:
                lst[i].append((x,y,h))
    else:
        for x,y,h in lst[i-1]:
            if abs(x-xi)+abs(y-yi) >= h:
                lst[i].append((x,y,h))
print(*lst[n-1][0])
r=int(input())
print(2r*3.14)

### FIXED CODE ###

r=int(input())
print(2*r*3.14)
N, K = map(int, input().split())
A = list(map(int, input().split()))

def get_divisors(n, reverse=False):
    from math import sqrt
    divisors = []
    for num in range(1, int(sqrt(n))+1):
        if n % num == 0:
            divisors.append(num)
            if n//num != num:
                divisors.append(n//num)
    return sorted(divisors, reverse=reverse)

total = sum(A)
divisors = get_divisors(total, reverse=True)
ans = -1
for d in divisors:
    R = [a%d for a in A]
    R.sort(reverse=True)
    pr = 0
    nr = -sum(R)
    for i, r in enumerate(R):
        pr += d-r
        nr += r
        if nr+pr >= 0:
            if pr <= K and nr+pr == 0:
                ans = d
            break
    if ans != -1:
        print(ans)
        break
else:
    print(1)


### FIXED CODE ###

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


def get_divisors(n, reverse=False):
    from math import sqrt
    divisors = []
    for num in range(1, int(sqrt(n))+1):
        if n % num == 0:
            divisors.append(num)
            if n//num != num:
                divisors.append(n//num)
    return sorted(divisors, reverse=reverse)

status = [0] * N
answers = []
for i in range(N, 0, -1):
    if A[i-1] == status[i-1]:
        continue
    answers.append(i)
    divisors = get_divisors(i)
    a = A[i-1]
    for divisor in divisors:
        status[divisor-1] = (1 + status[divisor-1]) % 2

print(len(answers))
for ans in answers:
    print(ans, end=" ")
hoge = input().split()
N = int(hoge[0])
M = int(hoge[1])

if N == 1 and m == 1:
  print(0)
else:
  n = 0
  if N != 0:
    for i in range(N-1):
      n += 1+i
  else:
    n = 0
  if M != 0:
    m = (M * (M-1)) / 2
  else:
    m = 0
  print(int(n + m))

### FIXED CODE ###

hoge = input().split()
N = int(hoge[0])
M = int(hoge[1])

if N == 1 and M == 1:
  print(0)
else:
  n = 0
  if N != 0:
    for i in range(N-1):
      n += 1+i
  else:
    n = 0
  if M != 0:
    m = (M * (M-1)) / 2
  else:
    m = 0
  print(int(n + m))
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value

from collections import deque
N, M = mi()
x = li2(M)

adj = [[] for i in range(N)]
for i in range(M):
    x[i][0] -= 1
    x[i][1] -= 1
    adj[x[i][0]].append(x[i][1])

flag = [0]*N
ans = deque([])

def dfs(x):
    if flag[x]:
        return None
    else:
        flag[x] = 1
        if adj[x]:
            for a in adj[x]:
                dfs(a)
        global ans
        ans.appendleft(x)

for i in range(N):
    dfs(i)

#print(ans)

dp = [0]*N
for a in ans:
    if adj[a]:
        for b in adj[a]:
            dp[b] = max(dp[b], dp[a] + 1)

print(max(dp))

### FIXED CODE ###

import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
'''
N, M = mi()
x = li2(M)

#dp = dp2(0, 2, N)
dp = [[0, []] for i1 in range(N+1)]


for i in range(M):
    dp[x[i][1]][0] = max(dp[x[i][1]][0], dp[x[i][0]][0] + 1)
    dp[x[i][0]][1].append(x[i][1])
    if dp[x[i][1]][1] != []:
        for a in dp[x[i][1]][1]:
            dp[a][0] = max(dp[x[i][1]][0] + 1, dp[a][0])

print(dp)
print(max([row[0] for row in dp])) 
'''
from collections import deque
N, M = mi()
x = li2(M)

h = [0]*N
adj = [[] for i in range(N)]
for i in range(M):
    x[i][0] -= 1
    x[i][1] -= 1
    h[x[i][1]] += 1
    adj[x[i][0]].append(x[i][1])

zeros = deque([])
ans = []
for i in range(N):
    if h[i] == 0:
        zeros.append(i)
        ans.append(i)

while(zeros != deque()):
    a = zeros.popleft()
    if(adj[a]):
        for b in adj[a]:
            h[b] -= 1
            if h[b] == 0:
                zeros.append(b)
                ans.append(b)

#print(ans)

dp = [0]*N
#print(ans)
#print(adj)
for a in ans:
    #print(dp)
    if adj[a]:
        for b in adj[a]:
            dp[b] = max(dp[a] + 1, dp[b])
#print(dp)
print(dp[ans[-1]])
k = int(input())
a,b = map(int, inupt().split())
for i in range(a,b+1):
  if i % k == 0:
    print("OK")
  elif i == b:
    print("NG")
    break


### FIXED CODE ###

k = int(input())
a,b = map(int, input().split())
for i in range(a,b+1):
  if i % k == 0:
    print("OK")
    break
  elif i == b:
    print("NG")
    break
ab = input('')
a = int(ab.split(' ')[0])
b = int(ab.split(' ')[1])
import math
result =  math.floor(a*b)

print(result)


### FIXED CODE ###

import decimal
ab = input('')
a = decimal.Decimal(ab.split(' ')[0])
b = decimal.Decimal(ab.split(' ')[1])
result =  a*b
import math
result = math.floor(result)
print(result)
def func(iro,tree,num,max_color):
  if num not in tree:
    return
  
  my_color = iro[num]
  arr = tree[num]
  
  for i in arr:
    my_color += 1
    iro[i] = my_color % max_color
    func(iro,tree,i,max_color)
    

n = int(input())
tree = {}

b_arr = []
for i in range(n-1):
  a,b = map(int,input().split())
  
  b_arr.append(b)
  if a not in tree:
    tree[a] = []
    
  tree[a].append(b)


color = len(tree[1])
for key in tree.keys():
  if key == 1:
    continue
    
  arr = tree[key]
  color = max(len(arr)+1, color)

print(color)

iro = [0] * (n+1)

func(iro,tree,1,color)

for i in b_arr:
  print(iro[i]+1)
  

### FIXED CODE ###

def func(iro,tree,num,max_color):
  if num not in tree:
    return
  
  my_color = iro[num]
  arr = tree[num]
  
  for i in arr:
    my_color += 1
    iro[i] = my_color % max_color
    func(iro,tree,i,max_color)
    

n = int(input())
tree = {}

b_arr = []
for i in range(n-1):
  a,b = map(int,input().split())
  
  b_arr.append(b)
  if a not in tree:
    tree[a] = []
    
  tree[a].append(b)
  
color = len(tree[1])
for key,arr in sorted(tree.items()):
  if key == 1:
    continue
    
  color = max(len(arr)+1, color)

print(color)

iro = [-1] * (n+1)

for key,arr in sorted(tree.items()):
  my_color = iro[key]
  for i in arr:
    my_color += 1
    iro[i] = my_color % color

for i in b_arr:
  print(iro[i]+1)
N, A, B = map(int, input().split(" "))


balls = ''
for i in range(N):
    balls += 'b'*A + 'r'*B
balls = balls[0:N]
print(balls.count('b'))

### FIXED CODE ###

def main():
    N, A, B = map(int, input().split(" "))
    if (A + B) == 0:
        print(0)
        return
    amari = N % (A+B)
    kaisuu = N // (A+B)
    print(kaisuu*A+min(amari, A))
main()
#!/usr/bin/env python3
import sys
import collections
import itertools


def solve(N: int, S: str):
    dp = [[0 for _ in range(N)] for _ in range(N)]

    for i in range(N):
        if S[i] == S[-1]:
            dp[i][N-1] = 1

    res = 0
    for i in range(N-2,-1,-1):
        for j in range(N-2,i,-1):
            if S[i] == S[j]:
                dp[i][j] = dp[i+1][j+1] + 1
                l = dp[i][j]
                if j >= i+l:
                    res = max(res,l)

    print(res)



# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys


def solve(S: str):
    if S == "Sunny":
        print("Cloudy")
    elif S == "Cloudy":
        print("Rainy")
    else:
        print("Sunny")
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()
n, x = map(int, input().split())
l = list(map(int, input().split()))
cnt = 0
now = 0
for i in range(n + 1):
  if now > x:
    break
  cnt += 1
  now = now + l[i]
print(cnt)

### FIXED CODE ###

n, x = map(int, input().split())
l = list(map(int, input().split()))
d = [0 for _ in range(n + 1)]
ans = 0
for i in range(1, n + 1):
  d[i] = d[i - 1] + l[i - 1]
for j in range(n + 1):
  if d[j] <= x:
    ans += 1
print(ans)
from functools import lru_cache

n = int(input())
heights = [int(x) for x in input().split()]

@lru_cache(None)
def solve(i):
    if i == n - 1:
        return 0
    if i + 2 >= len(heights):
        return abs(heights[i + 1] - heights[i])
    option1 = abs(heights[i] - heights[i + 1])
    option1 += solve(i + 1)
    option2 = abs(heights[i] - heights[i + 2])
    option2 += solve(i + 2)
    return min(option1, option2)

print(solve(0))


### FIXED CODE ###

from functools import lru_cache
import sys

iMaxStackSize = 5000000
sys.setrecursionlimit(iMaxStackSize)
n = int(input())
heights = [int(x) for x in input().split()]

@lru_cache(None)
def solve(i):
    if i == n - 1:
        return 0
    if i + 2 >= len(heights):
        return abs(heights[i + 1] - heights[i])
    option1 = abs(heights[i] - heights[i + 1])
    option1 += solve(i + 1)
    option2 = abs(heights[i] - heights[i + 2])
    option2 += solve(i + 2)
    return min(option1, option2)

print(solve(0))
n,m = map(int, input().split())
PY = [[] for i in range(m)]
for i in range(m):
  PY[i] = list(i,map(int, input().split()))

PY.sort(key = lambda x:x[2])
PY.sort(key = lambda x:x[1])

l = [0]*(n)
for i in range(m):
  l[PY[i][1]-1]+=1

for i in range(n):
  j = 0
  while j < l[i]:
    list(filter(lambda x:x[1]==i+1,PY))[j].append(j+1)
    j += 1
  
PY.sort(key = lambda x:x[0])
for i in range(m):
  print('{:0=6}'.format(PY[i][1])+'{:0=6}'.format(PY[i][3]))
  

### FIXED CODE ###

n,m = map(int, input().split())
PY = [[] for i in range(m)]
for i in range(m):
  PY[i] = list(map(int, input().split()))
  PY[i].append(i)
  
PY.sort(key = lambda x:x[1])

l = [0]*(n)
for i in range(m):
  l[PY[i][0]-1]+=1
  PY[i].append(l[PY[i][0]-1])

  
PY.sort(key = lambda x:x[2])
for i in range(m):
  print('{:0=6}'.format(PY[i][0])+'{:0=6}'.format(PY[i][3]))
n,q=map(int,input().split())
a=list(map(int,input().split()))
size=(1<<18)+1
bit=[0]*size
def bit_update(x,v):
    while x<size:
        bit[x]+=v
        x+=(x&-x)
def bit_sum(n):
    s=0
    if n==0:return 0
    x=n
    while x>0:
        s+=bit[x]
        x-=(x&-x)
    return s
for i,j in enumerate(a,1):
    bit_update(i,j)
for i in range(q):
    a,b,c=map(int,input().split())
    if a==0:
        bit_update(b+1,c)
    else:
        print(bit_sum(c)-bit_sum(b))

### FIXED CODE ###

n,q=map(int,input().split())
a=list(map(int,input().split()))
size=2*n+1
bit=[0]*size
def bit_update(x,v):
    while x<size:
        bit[x]+=v
        x+=(x&-x)
def bit_sum(n):
    s=0
    if n==0:return 0
    x=n
    while x>0:
        s+=bit[x]
        x-=(x&-x)
    return s
for i,j in enumerate(a,1):
    bit_update(i,j)
for i in range(q):
    a,b,c=map(int,input().split())
    if a==0:
        bit_update(b+1,c)
    else:
        print(bit_sum(c)-bit_sum(b))
import sys
import math

num_list = input().split()
ans = int(num_list[0]) * float(num_list[1]) * 100
ans = str(int(ans))[:-2]
print(int(ans))


### FIXED CODE ###

import sys
from decimal import Decimal

num_list = input().split()
ans = Decimal(num_list[0]) * Decimal(num_list[1])
print(int(ans))
S = input()
T = input()
if T = S + T[-1]:
    print("Yes")
else:
    print("No")

    

### FIXED CODE ###

S = input()
T = input()
if T == S + T[-1]:
    print("Yes")
else:
    print("No")
import sys
import heapq


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


def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    for i in range(N):
       AA[i] = A[i] * (-1)
    heapq.heapify(AA)

    for i in range(M):
        maxaa=-1 * heapq.heappop(AA)
        if max(A) == 0:
            print("0")
            exit()
        heapq.heappush(AA,  maxaa // 2 * (-1))
    print(sum(AA) * (-1))


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
import heapq


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


def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    for i in range(N):
        A[i] *= -1
    heapq.heapify(A)

    for i in range(M):
        maxa = -1 * heapq.heappop(A)
        if maxa == 0:
            print("0")
            exit()
        heapq.heappush(A,  maxa // 2 * (-1))
    print(sum(A) * (-1))


if __name__ == '__main__':
    main()
import numpy as np
N, K  = map(int, raw_input().split())
A = np.array(map(int, raw_input().split()))

A_cumsum = np.empty(N+1, dtype=int)
A_cumsum[0] = 0
A_cumsum[1:] = np.cumsum(A)
ans = 0
for i in xrange(1, K):
    seq_sum = A_cumsum[i:] - A_cumsum[:-i]
    ans += np.sum(seq_sum%K==1)
    
print ans

### FIXED CODE ###

Day = {"SUN":7,
       "MON":6,
       "TUE":5,
       "WED":4,
       "THU":3,
       "FRI":2,
       "SAT":1}

S = raw_input()

print Day[S]
#: Author - Soumya Saurav
import sys,io,os,time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect,math,heapq
alphabet = "abcdefghijklmnopqrstuvwxyz"

input = sys.stdin.readline

########################################

n , m , k = map(int , input().split())
a = list(map(int , input().split()))
b = list(map(int , input().split()))
i = 0
j = 0
ans = 0
while k:
	#print(k,i,j,ans)
	f = 1
	if i < n and a[i] < b[j]:
		if k - a[i] >= 0:
			k-=a[i]
			ans+=1
			i+=1
			f = 0
			if i == n: i = n-1
	elif j < m and b[j] < a[i]:
		if k - b[j] >= 0:
			k-=b[j]
			ans+=1
			j+=1
			f = 0
	if f: break
	if i >= n  and j >= m: break
print(ans)
	








### FIXED CODE ###

#: Author - Soumya Saurav
import sys,io,os,time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect,math,heapq
alphabet = "abcdefghijklmnopqrstuvwxyz"

input = sys.stdin.readline

########################################

N, M, K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
a, b=[0], [0]
for i in range(N):
	a.append(a[i]+A[i])
for i in range(M):
	b.append(b[i]+B[i])
	
ans, j=0, M
for i in range(N+1):
	if a[i] > K :
		break
	while b[j] > K - a[i]:
		j-=1
	ans=max(ans, i+j)
print(ans)
N=int(input())
A=list(map(int,input().split()))
Q=int(input())
B=[list(map(int,input().split())) for i in range(Q)]
from bisect import bisect_left,bisect_right
# def 二分探索(リスト, 要素)
def index(lst, e):
    # Step 1. bisect_left して
    i = bisect_left(lst, e)
    
    # Step 2. 変な値を ValueError で弾いて
    if i == len(lst):
        return -1
    if lst[i] != e:
        return -1
    # Step 3. 値を返す。
    return i
def index2(lst, e):
    # Step 1. bisect_left して
    i = bisect_right(lst, e)
    
    # Step 2. 変な値を ValueError で弾いて
    if i == len(lst)+1:
        return -1
    if lst[i-1] != e:
        return -1
    # Step 3. 値を返す。
    return i
def count_sort(arr):
    max_num = max(arr)
    min_num = min(arr)
    count = [0] * (max_num - min_num + 1)
    for ele in arr:
        count[ele - min_num] += 1

    return [ele for ele, cnt in enumerate(count, start=min_num) for __ in range(cnt)]

A=count_sort(A)

for i in B:
    j=index(A,i[0])
    if not j==-1:
        k=index2(A,i[0])
        del A[k:l]
        for i in range(j,k)
            A.append(i[1])
            
    A=count_sort(A)
    print(sum(A))


### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
Q=int(input())
B=[list(map(int,input().split())) for i in range(Q)]

dp=[0 for i in range(1,10**6)]
for i in A:
    dp[i]+=1
S=sum(A)
for i in B:
    S+=(i[1]-i[0])*dp[i[0]]
    print(S)
    dp[i[1]]+=dp[i[0]]
    dp[i[0]]=0
n,l=map(int,input().split())
s=[input() for i in n]
s.sort
print("".join(s))

### FIXED CODE ###

N,L=map(int,input().split())
s=[input() for i in range(N)]
s=sorted(s)
s="".join(s)
print(s)
n,x=map(int,input().split())
a=list(map(int,input().split()))
eat=0
if a[0]>x:
    eat+=(a[0]-x)
    a[0]=x
for i in range(1,n-1):
    if a[i-1]+a[i]>x:
        f=(a[i-1]+a[i]-x)
        eat+=f
        a[i]=a[i-f]
print(eat)

### FIXED CODE ###

n,x = map(int,input().split())
a=list(map(int,input().split()))
ans=0
if a[0]>x:
    ans+=a[0]-x
    a[0]=x
for i in range(len(a)-1):
    if a[i]+a[i+1]>x:  
        b=a[i+1]-x+a[i]
        a[i+1]=x-a[i]
        ans+=b
print(ans)
S = list(input())
Q = int(input())
for i in range(Q):
    query = input().split()
    if int(query[0]) == 1:
        S.reverse()
    else:
        if int(query[1]) == 1:
            S.insert(0, query[2])
        else:
            S.append(query[2])
print("".join(S))


### FIXED CODE ###

S = input()
if len(set(S)) == 2:
  print("Yes")
else:
  print("No")