Harryxun/stf_run huggingface dataset:
#sを最高のパターンにして，tを最悪のパターンにすればいい
#continueで強制的に次のループへ
s = list(input())
t = list(input())
condition = 0

s.sort()
t.sort()
t.reverse()

if len(s)  == len(t):
    pattern == -1
elif len(s) < len(t):
    length = len(s)
    pattern = 0
else:#sのほうが長い時 pattern = 1
    length = len(t)
    pattern = 1

if pattern == -1:
    for i in range(length):
        if s[i] == t[i]:
            continue
        elif s[i] > t[i]:
            print("Yes")
            condition =1
            break
        else:
            print("No")
            condition =1
            break
elif pattern == 0:
    for i in range(length):
        if s[i] == t[i]:
            continue
        elif s[i] < t[i]:
            print("Yes")
            condition =1
            break
        else:
            print("No")
            condition =1
            break
    
    if condition == 0:
        print("Yes")
elif pattern == 1:
    for i in range(length):
        if s[i] == t[i]:
            continue
        elif s[i] < t[i]:
            print("Yes")
            ccondition =1
            break
        else:
            print("No")
            condition =1
            break
    if condition == 0:
        print("No")
        
    



### FIXED CODE ###

#sを最高のパターンにして，tを最悪のパターンにすればいい
#continueで強制的に次のループへ
s = list(input())
t = list(input())
condition = 0

s.sort()
t.sort()
t.reverse()

if len(s)  == len(t):
    length = len(s)
    pattern = -1
elif len(s) < len(t):
    length = len(s)
    pattern = 0
else:#sのほうが長い時 pattern = 1
    length = len(t)
    pattern = 1

if pattern == -1:
    for i in range(length):
        if s[i] == t[i]:
            continue
        elif s[i] < t[i]:
            print("Yes")
            condition =1
            break
        else:
            print("No")
            condition =1
            break
    if condition == 0:
        print("No")
elif pattern == 0:
    for i in range(length):
        if s[i] == t[i]:
            continue
        elif s[i] < t[i]:
            print("Yes")
            condition =1
            break
        else:
            print("No")
            condition =1
            break
    
    if condition == 0:
        print("Yes")
elif pattern == 1:
    for i in range(length):
        if s[i] == t[i]:
            continue
        elif s[i] < t[i]:
            print("Yes")
            condition =1
            break
        else:
            print("No")
            condition =1
            break
            
    if condition == 0:
        print("No")
"""
abc141-b
"""

S = input()

ans="Yes"

for i in range(int(len(S))):
    if (i % 2 == 0):
        if (S[i] == "L"):
            ans="No"
            break
    else:
        if (S[i] == "R"):
            ans="No"
            break
print(ans

### FIXED CODE ###

"""
abc141-b
"""

S = input()

ans="Yes"

for i in range(int(len(S))):
    if (i % 2 == 0):
        if (S[i] == "L"):
            ans="No"
            break
    else:
        if (S[i] == "R"):
            ans="No"
            break
print(ans)
x,y = map(int,input().split())	

if x<10:
  r=y+100(10-x)
else:
  r=y
  
print(r)

### FIXED CODE ###

x,y = map(int,input().split())	

if x<11:
  r=y+100*(10-x)
else:
  r=y
  
print(r)
n= int(input())
spot = input().split()
cnt = 0
ans = []
for i in spot:
    spot.append(int(i))
    del spot[cnt]
    cnt += 1
for s in range(min(spot),max(spot)):
    x = 0
    for t in spot:
        x += (t-s)**2
    ans.append(x)
print(min(ans))

### FIXED CODE ###

n= int(input())
spot = input().split()
ans = []
for i in spot:
    spot.append(int(spot[0]))
    del spot[0]
if n == 1:
    print(0)
else:
    if max(spot)==min(spot):
        ans.append(0)
    for s in range(min(spot),max(spot)):
        x = 0
        for t in spot:
            x += (s-t)**2
        ans.append(x)
if n != 1:
    ans.sort(reverse=False)
    print(ans[0])
for i in range(int(input())):
	values = sorted(map(lambda x: int(x)^2, input().split()))
	if values[2] == values[1] + values[0]:
		print 'YES'
	else:
		print 'NO'


### FIXED CODE ###

def judge_triangle(edges):
    edges.sort(reverse = True)
    if edges[0]**2 == edges[1]**2 + edges[2]**2:
        return 'YES'
    else:
        return 'NO'

lines = int(input())

for i in range(lines):
    edges = list(map(int, raw_input().split()))
    print judge_triangle(edges)
import numpy as np

N,M = map(int,input().split())
vector = np.zeros((N, N))

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

depth = np.zeros((1, N))
que = [0]

while not que == []:
	room = que[0]
	que.pop(0)
	search = np.where(vector[room:room+1]==1)[1]
	for next_room in search:
		if not depth[:,next_room:next_room+1] == 0 or next_room == 0:
			continue
		depth[:,next_room:next_room+1] = depth[:,room:room+1]+1
		que.append(next_room)

if 0 in depth[:,1:][0]:
	print("No")
else:
	print("Yes")
	for dep in depth[:,1:][0]:
		print(np.where(depth==dep-1)[1][0]+1)


### FIXED CODE ###

n,m = map(int,input().split())
visited = [-1 for _ in range(n+1)]
visited[1] = 0
will = []
root = [[] for _ in range(n+1)] 
for i in range(m):
    a,b = map(int,input().split())
    root[a].append(b)
    root[b].append(a)

will.append(1)

while will:
    visit = will.pop(0)
    for i in root[visit]:
        if visited[i] != -1:
            continue
        will.append(i)
        visited[i] = visit

if visited[1:] == -1:
    print('No')
else:
    print('Yes')
    for i in range(2,len(visited)):
        print(visited[i])
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools as fts
import itertools as its
import math
import sys
import numpy as np

INF = float('inf')


def solve(N: int, d: "List[int]"):
    return sum(x * y for x, y in its.combinations(d, 2))


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    d = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(f'{solve(N, d)}')


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools as fts
import itertools as its
import math
import sys

INF = float('inf')


def solve(N: int, d: "List[int]"):
    return sum(x * y for x, y in its.combinations(d, 2))


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    d = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(f'{solve(N, d)}')


if __name__ == '__main__':
    main()
S =input()
K =int(input())
x =S*K

count =[]
while len(x)>0:
    if len(x)==1:
        count.append(1)
        x =x[:-1]
        break
    if x[-1] != x[-2]:
        count.append(1)
        x =x[:-1]
    else:
        k = 2
        while True:
            if len(x) == k :
                count.append(k)
                break
            if x[-1] == x[-1-k]:
                k +=1
            else:
                count.append(k)
                break
        x =x[:-k]       
#print(count[::-1])    
ans = sum(list(map(lambda x :x//2,count)))
print(ans)

### FIXED CODE ###

S =input()
K =int(input())

if len(set(S))==1:
    ans =(len(S)*K)//2

else:
    S_ans =  0
    cnt = 1
    for i in range(1,len(S)):
        if S[i] == S[i-1]:
            cnt += 1
            if i ==len(S)-1:
                S_ans += cnt//2
        else:
            S_ans += cnt//2
            cnt = 1
    ans =S_ans*K

    if S[0] == S[-1]:
        a, i =1, 1
        while S[0]==S[i]:
            a += 1
            i += 1
        b, i =1, 1
        while S[-1]==S[-1- i]:
            b += 1
            i += 1
        ans = ans - (a//2 +b//2 -(a+b)//2)*(K-1)        
    

print(ans)
from operator import mul
from functools import reduce

def cmb(n, r):
  if n < r:
    return 0
  r = min(n - r, r)
  if r == 0:
    return 1
  numer = reduce(mul, range(n, n - r, -1))
  denom = reduce(mul, range(1, r + 1))
  return numer // denom % (10 ** 9 + 7)

N,K = map(int,input().split())
MOD = 10**9+7
for i in range(1, K+1):
  print(cmb(K-1,i-1) * cmb(N-K+1, (N-K)-(i-1)))


### FIXED CODE ###

from operator import mul
from functools import reduce

def cmb(n, r):
  if n < r:
    return 0
  r = min(n - r, r)
  if r == 0:
    return 1
  numer = reduce(mul, range(n, n - r, -1))
  denom = reduce(mul, range(1, r + 1))
  return (numer // denom) % (10 ** 9 + 7)

N,K = map(int,input().split())
MOD = 10**9+7
for i in range(1, K+1):
  print(cmb(K-1,i-1)%MOD * cmb(N-K+1, i)%MOD % MOD)
N3 = int(input())
if N3 < 1200:
    print('ABC')
elif N3 > 1999 and N3 < 2800:
    print('ARC')
elif NR > 2799:
    print('AGC')

### FIXED CODE ###

N3 = int(input())
if N3 < 1200:
    print('ABC')
elif 1200 <= N3 < 2800:
    print('ARC')
else:
    print('AGC')
import itertools
n=int(input());S=list(map(sorted,[input() for _ in [1]*n]))
re=[]
for s in S:
    tmp=[]
    for i in range(l):
        li=list(itertools.combinations(s,i))
        for lii in li:tmp.append(lii)
    re.append(tmp)
re2=re[0]
for i in range(1,len(re)):
    re2=list(set(re2)&set(re[i]))
l=max([len(r) for r in re2])
for i in range(len(re2)):
    if len(re2[i])==l:
        print(''.join(re2[i]))
        break

### FIXED CODE ###

n=int(input());S=list(map(sorted,[input() for _ in [1]*n]))
dicList=[]
for s in S:
    dic={}
    for c in list(s):
        dic[c]=dic.get(c,0)+1 
    dicList.append(dic)
result=''
c=[chr(i) for i in range(97, 97+26)]
count=0
while count<26:
    m = min([dic.get(c[count],0) for dic in dicList])
    if m==0:count+=1
    else:
        for dic in dicList:
            dic[c[count]]-=1
        result+=c[count]
print(result)
from collections import deque

N, M = [int(s) for s in input().split()]
edge = [[int(s) - 1 for s in input().split()] for _ in range(M)]
graph = [[] for _ in range(N)]
for i, j in edge:
    graph[i].append(j)
    graph[j].append(i)

dq = deque([0])
visited = [False] * N
visited[0] = True
parent = [0]*N
while(dq):
    search_obj = dq.pop()
    for candidate_obj in graph[search_obj]:
        if not visited[candidate_obj]:
            dq.appendleft(candidate_obj)
            parent[candidate_obj] = search_obj
            visited[candidate_obj] = True

total_visited = sum(visited)
if total_visited < N:
    print('No')
else:
    print('Yes')
    for i in range(1, N):
        print(parent[i]+1)

### FIXED CODE ###

N = input()

if N[-1] == '3':
    print('bon')
elif N[-1] in ['0', '1', '6', '8']:
    print('pon')
else:
    print('hon')
n= int(input())
a = list(int(i) for i in input().split())
import math
import sys

sta=sum(a)/2
sum=0
ans=0
for i in range(0,n-1):
    if sum==sta:
        print(0)
        sys.exit()
    elif sum<sta and sum+a[i]>sta:
        ans=min(sta-sum,sum+a[i]-sta)/0.5
        print(int(ans))
        sys.exit()
    else:
        sum+=a[i]

ans=min(sta-sum,sum+a[n]-sta)/0.5
print(abs(int(ans)))

### FIXED CODE ###

n= int(input())
a = list(int(i) for i in input().split())
import math
import sys

sta=sum(a)/2
sum=0
ans=0
for i in range(0,n-1):
    if sum==sta:
        print(0)
        sys.exit()
    elif sum<sta and sum+a[i]>sta:
        ans=min(sta-sum,sum+a[i]-sta)/0.5
        print(int(ans))
        sys.exit()
    else:
        sum+=a[i]

ans=min(sta-sum,sum+a[n-1]-sta)/0.5
print(abs(int(ans)))
from sys import stdin
N,Y=list(map(int,stdin.readline().strip().split()))
YY=abs(Y)
NN=abs(N)
count=YY-NN
if count<0:
   print(Y-N)
else:
    if N>0 and Y>0:
        print(count)
    elif N>0 and Y<0:
        print(count+1)
    elif N<0 and Y>0:
        print(count+1)
    else:N<0(count+2)

### FIXED CODE ###

from sys import stdin
N,Y=list(map(int,stdin.readline().strip().split()))
count=0
flag=False
if abs(N)-abs(Y)==0:
    print(1)
    exit()
if N>Y and abs(N)>abs(Y) or N>Y and N<0:
    count+=1
    N*=-1
    flag=True
YY=abs(Y)
NN=abs(N)
ans=0
if YY>NN:
    ans=YY-NN
else:
    ans=NN-YY
N+=ans
if Y==N:
    print(count+ans)
else:
    print(count+ans+1)
from collections import deque
 
S = input()
Q = int(input())
S = deque(S)
 
flg_reverse = False
 
for q in range(Q):
  _ = input()
  if _[0] == '1':
    flg_reverse = flg_reverse ^ True
  else:
    _T, _F, _C = _.split()
    ## リバース回数が奇数偶数のいずれかをチェック
    if _F == '1':
      if cnt_reverse % 2 == 0:
        S.appendleft(_C)
      else:
        S.append(_C)
    else:
      if cnt_reverse % 2 == 0:
        S.append(_C)
      else:
        S.appendleft(_C)
 
S = list(S)
# reverseの部分を対応
if flg_reverse:
  S.reverse()
 
print(''.join(S))

### FIXED CODE ###

from collections import deque

S = input()
Q = int(input())
S = deque(S)

cnt_reverse = 0

for q in range(Q):
  _ = input()
  if _[0] == '1':
    cnt_reverse += 1
  else:
    _T, _F, _C = _.split()
    ## リバース回数が奇数偶数のいずれかをチェック
    if _F == '1':
      if cnt_reverse % 2 == 0:
        S.appendleft(_C)
      else:
        S.append(_C)
    else:
      if cnt_reverse % 2 == 0:
        S.append(_C)
      else:
        S.appendleft(_C)

S = list(S)
# reverseの部分を対応
if cnt_reverse % 2 == 1:
  S.reverse()

print(''.join(S))
import math
from functools import reduce

N = int(input())
HP = input().split()

while True:
    a = math.gcd(int(HP[-1]),int(HP[0]))
    del HP[-1]
    del HP[0]
    HP.append(str(a))
    if len(HP) == 2:
        print(math.gcd(int(HP[-1]),int(HP[0])))
        break


### FIXED CODE ###

import fractions
from functools import reduce

N = int(input())
A = list(map(int,input().split()))
print(reduce(lambda a, b: fractions.gcd(a,b), A))
N = int(input())
A = input()
A = eval(A.replace(" ","^"))
print(A)
print("Yes" if A == 0 else "No")



### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
flag = False
x = len(set(A))
if x == 1 and A[0] == 0:
  flag = True
elif x == 2 and A.count(0) == N // 3:
  flag = True
elif x == 3:
  X = A[0]
  Y = -1
  Z = -1
  i = 1
  while i < N:
    if A[i] != X:
      Y = A[i]
      break
    i += 1
  while i < N:
    if A[i] != X and A[i] != Y:
      Z = A[i]
    i += 1
  if X ^ Y ^ Z == 0 and A.count(X)  == N // 3 and A.count(Y)  == N // 3:
    flag = True
print("Yes" if flag else "No")
s=input()
n=len(s)
a=[]
b=""
for i in range(s):
  if s[i]=="B":
    a.pop()
  else:
    a.append(s[i])
for i in range(len(a)):
  b+=a[i]
print(b)
    

### FIXED CODE ###

s=input()
n=len(s)
a=[]
b=""
for i in range(n):
  if s[i]=="B":
    if len(a)!=0:
      a.pop()
  else:
    a.append(s[i])
for i in range(len(a)):
  b+=a[i]
print(b)
n=int(input())
t=[int(input()) for i in range(n)]
#print(n,t)
t.sort(reverse=True)

def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)
        
if n==1:
  ans=t
elif n==2:
  ans=t[0]*t[1]/gcd(t[0],t[1])
else:
  tmp=t[0]*t[1]/gcd(t[0],t[1])
  n=2
  while n < len(t):
    tmp=tmp*t[n]/gcd(tmp,t[n])
    n+=1  
  ans=tmp
  
print(int(ans))

### FIXED CODE ###

import fractions
n=int(input())

ans=1
for i in range(n):
  x=int(input())
  ans=ans//fractions.gcd(ans,x)*x

print(int(ans))
stop=[0,1,2,3,4,5,6,7,8,9,5,4,3,2,1,0]
for i in range(input()):
	sp,ep=map(int,raw_input().split())
	if sp<ep:
		print stop[stop.index(sp):stop.index(ep)+1]
	else:
		print stop[stop.rindex(sp):stop.rindex(ep)+1]

### FIXED CODE ###

p="0123456789543210"
for i in range(input()):
	sp,ep=raw_input().split()
	(sp,ep)=(p.find(sp),p.find(ep)+1) if sp<ep else (p.rfind(sp),p.rfind(ep)+1)
	print " ".join(p[sp:ep]) if sp<ep else " ".join(p[sp:]+p[1:ep])
import math

N,X = (int(i) for i in input().split()) 
x = [abs(int(i)-X) for i in input().split()]

ans = x[0]
for i in range(N):
	ans = math.gcd(ans, x[i])
	if ans == 1:
		break

print(ans)

### FIXED CODE ###

from fractions import gcd

N,X = (int(i) for i in input().split()) 
x = [abs(int(i)-X) for i in input().split()]

ans = x[0]
for i in range(N):
	ans = gcd(ans, x[i])
	if ans == 1:
		break

print(ans)
n = int(input())
a = sorted(list(map(int,input().split())))
b = sorted(list(map(int,input().split())))
c = sorted(list(map(int,input().split())))

cnt = 0

for i in range(len(a)):
    A = a[i]
    j = 0
    while j < len(b):
        if A < b[j]:
            cnt += 1
            j += 1
        else:
            break
		while k < len(c):
           if b > c:
               cnt += 1
print(cnt)


### FIXED CODE ###

from bisect import *

n = int(input())
a,b,c = [sorted(map(int,input().split())) for i in range(3)]

print(sum([bisect_left(a,i)*(n-bisect_right(c,i)) for i in b]))
def resolve():
    A, B, K = list(map(int, input().split()))
    l = list(range(A, B+1))
    mn = l[:K]
    mx = l[-K:]
    ans = (mn + mx)
    ans = list(set(ans))
    ans.sort()
    ans = list(map(str, ans))
    print('\n'.join(ans))

resolve()

### FIXED CODE ###

def resolve():
    A, B, K = list(map(int, input().split()))
    if B - A + 1 >= 2 * K:
        ls = [i for i in range(A, A+K)] + [i for i in range(B-K+1, B+1)]
    else:
        ls = [i for i in range(A, B+1)]

    print('\n'.join(map(str, ls)))
    return

resolve()
import sys  
import numpy as np
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
k = [0] * max(3,(max(a)+1))

for p in a:
    k[p] += 1
ans = 0
for q,r,s in zip(k, k[1:] , k[2:]):
    ans = max(ans, q+r+s)

print(ans)

### FIXED CODE ###

import sys  
import numpy as np
N1 = list(map(int, input().split()))
N2 = list(map(int, input().split()))
N3 = list(map(int, input().split()))

temp = []
for i in range(3):
    a  = N1[i] + N2[i] - 2*N3[i]
    temp.append(a)
temp2 = []

temp2.append(N1[0] + N1[1] - 2*N1[2])

temp2.append(N2[0] + N2[1] - 2*N2[2])

temp2.append(N3[0] + N3[1] - 2*N3[2])


if len(list(set(temp))) == 1 & len(list(set(temp2))) == 1:
    print("Yes")
else :
    print("No")
n,m = map(int, input().split())
abl = []
cdl = []
for _ in range(n):
    a,b = map(int, input().split())
    abl.append((a,b))

for _ in range(n):
    c,d = map(int, input().split())
    cdl.append((c,d))


for a,b in abl:
    cmin = 10**10
    mini = -1
    for i,(c,d) in enumerate(cdl):
        v = abs(a-c)+abs(b-d)
        if v < cmin:
            cmin = v
            minc,mind = c,d
            mini = i+1
    print(mini) 

### FIXED CODE ###

n,m = map(int, input().split())
abl = []
cdl = []
for _ in range(n):
    a,b = map(int, input().split())
    abl.append((a,b))

for _ in range(m):
    c,d = map(int, input().split())
    cdl.append((c,d))


for a,b in abl:
    cmin = 10**10
    mini = -1
    for i,(c,d) in enumerate(cdl):
        v = abs(a-c)+abs(b-d)
        if v < cmin:
            cmin = v
            minc,mind = c,d
            mini = i+1
    print(mini)
if(1<=a<=100 || 1<=b<=100)
	a = int(input())
	b = int(input())
	print(a*b)
else
	print("invail")

### FIXED CODE ###

A,B =map(int,input().split())
print(A*B)
N,M = map(int, input().split())
citys = [list(map(int,input().split()))+[i] for i in range(M)]

citys.sort(key = lambda x:x[1])
nums = [0]*(N+1)
states = [None]*M

for p,y,i in citys:
    nums[p] += 1
    states[i] = [str(p), str(nums[p])]

for s in states:
    print(s[0].zfill(6)+s[1].zfill(6))

### FIXED CODE ###

X,Y = map(int, input().split())

print(int(X+Y/2))
# ARC093D

a,b = map(int, input().split())

if a<=b:
    m = "."
    M = "#"
    mc = a
    Mc = b
else:
    m = "#"
    M = "."
    mc = b
    Mc = a
    
s = [[m]*100 for _ in range(100)]
tmp = [[M,M,M,m],
        [M,m,M,m],
      [M,M,M,m],
      [m,m,m,m]]
tmp2 = [[M,m,m,m],
        [m,m,m,m],
      [m,m,m,m],
      [m,m,m,m]]
for i in range(mc-1):
    u,v = (i*4)//100, (i*4)%100
    u *= 4
    for x in range(4):
        for y in range(4):
            s[u+x][v+y] = tmp[x][y]
for j in range(i+1, i+1+(Mc-(mc-1))):
    u,v = (j*4)//100, (j*4)%100
    u *= 4
    for x in range(4):
        for y in range(4):
            s[u+x][v+y] = tmp2[x][y]
print(100,100)
print("\n".join(["".join(item) for item in s]))

### FIXED CODE ###

# ARC093D

a,b = map(int, input().split())

if a<=b:
    m = "."
    M = "#"
    mc = a
    Mc = b
else:
    m = "#"
    M = "."
    mc = b
    Mc = a
    
s = [[m]*100 for _ in range(100)]
tmp = [[M,M,M,m],
        [M,m,M,m],
      [M,M,M,m],
      [m,m,m,m]]
tmp2 = [[M,m,m,m],
        [m,m,m,m],
      [m,m,m,m],
      [m,m,m,m]]
i = 0
for i in range(mc-1):
    u,v = (i*4)//100, (i*4)%100
    u *= 4
    for x in range(4):
        for y in range(4):
            s[u+x][v+y] = tmp[x][y]

for j in range(i+1, i+1+(Mc-(mc-1))):
    u,v = (j*4)//100, (j*4)%100
    u *= 4
    for x in range(4):
        for y in range(4):
            s[u+x][v+y] = tmp2[x][y]
print(100,100)
print("\n".join(["".join(item) for item in s]))
n = int(input())
a =list(map(int, input().split()))
q = int(input())
b = [0]*q
c = [0]*q
for i in range(q):
    b[i],c[i]=map(int, input().split())

at = [0]*10**5+2
sum = 0

for i in a:
    at[i]= at[i]+1
    sum = sum+i


for  i in range(q):
    m= at[b[i]]
    at[b[i]]=0
    at[c[i]]=at[c[i]]+m

    sum = sum + (c[i]-b[i])*m
    print(sum)

### FIXED CODE ###

n = int(input())
a =list(map(int, input().split()))
q = int(input())
b = [0]*q
c = [0]*q
for i in range(q):
    b[i],c[i]=map(int, input().split())

at = [0]*(10**5+100)
sum = 0

for i in a:
    at[i]= at[i]+1
    sum = sum+i


for  i in range(q):
    m= at[b[i]]
    at[b[i]]=0
    at[c[i]]=at[c[i]]+m

    sum = sum + (c[i]-b[i])*m
    print(sum)
#!/usr/bin/env python3
# coding: utf-8
import time

def main():
    N, K, C = map(int, input().split())
    S = dict(enumerate(str(input()), 1))

    # time.sleep(0.05 * len(str(C)))
    time.sleep(0.05 * int(str(K)[1]))
if __name__ == "__main__":
    main()

### FIXED CODE ###

#!/usr/bin/env python3
# coding: utf-8

def debug(arg):
    if __debug__:
        pass
    else:
        import sys
        print(arg, file=sys.stderr)
        
def main():
    N, K, C = map(int, input().split())
    S = dict(enumerate(str(input()), 1))

    sr = list(k for k, v in S.items() if v == 'o')
    sl = list(reversed(sr.copy()))

    debug(sr)
    debug(sl)

    l = [sl.pop()]
    r = [sr.pop()]
    
    for x in range(1, K):
        while True:
            ll = sl.pop()
            if ll > l[x - 1] + C:
                l.append(ll)
                break
        while True:
            rr = sr.pop()
            if rr < r[x - 1] - C:
                r.append(rr)
                break

    debug(r)
    debug(l)

    # a = sorted(set(l) & set(r))

    # debug(a)
    # for aa in a:
    #     print(aa)
    
    for ll, rr in zip(l, sorted(r)):
        if ll == rr:
            print(ll)

if __name__ == "__main__":
    main()
import sys

def solve(N, S, K):
    char = S[K]

    ans = ''
    for i in xrange(len(S)):
        ans += S[i] if S[i] == char else '*'
    return ans

if __name__ == '__main__':

    N = sys.stdin.readline().strip()
    S = sys.stdin.readline().strip()
    K = sys.stdin.readline().strip()
    ans = solve(int(N), S, int(K))
    print ans

### FIXED CODE ###

import sys

def solve(a, b, c):
    if a > c > b or a < c < b:
        return 'Yes'
    return 'No'

if __name__ == '__main__':

    a, b, c = map(int, sys.stdin.readline().strip().split(" "))
    ans = solve(a, b, c)
    print ans
list = map(int, input().split())
S = list[0]
W = list[1]
if W => S: print("unsafe")
else: print("safe")

### FIXED CODE ###

list = list(map(int, input().split()))
S = list[0]
W = list[1]
if W >= S: print("unsafe")
else: print("safe")