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

s=input()


i=0
c=0
flag=0
while True:
	if i>len(s)-3: break
	if s[i]=="A" and s[i+1]=="B" and s[i+2]=="C":
		s=s[:i]+"B"+s[i+1:]
		s=s[:i+1]+"C"+s[i+2:]
		s=s[:i+2]+"A"+s[i+3:]
		c+=1
		if i>0:
			i-=1
			flag=1
		continue
	else:
		if flag:
			i+=3
			flag=0
		else: i+=1

print(c)

### FIXED CODE ###

s=input()


i=0
c=0
flag=0
while True:
	if i>len(s)-2: break
	if s[i]=="A":
		flag+=1
		i+=1
	elif flag and s[i:i+2]=="BC":
		c+=flag
		i+=2
	else:
		flag=0
		i+=1

print(c)
### BUGGY CODE ###

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



import sys
############
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def main():
    X = int(input())
    divs = make_divisors(X)
    for d in divs:
        if (X-pow(d,5))%5 !=0:
            continue
        for i in range(-d,X):
            Y=pow(i+d,5)-pow(i,5)
            if Y==X:
                print(i+d,i)
                sys.exit()
            elif Y>X and i>0:
                break

if __name__ == '__main__':
    main()

### FIXED CODE ###

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

import sys

def main():
    X = int(input())
    for a in range(-200, 200):
        a5 = pow(a,5)
        for b in range(-200, 200):
            b5 = pow(b,5)
            if a5-b5 == X:
                print(a,b)
                sys.exit()

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

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

MOD = 10**9 + 7

res = 0
for i in range(N-1):
    for j in range(i+1, N):
        res += A[i] * A[j] % MOD

print(res % MOD)

### FIXED CODE ###

import numpy as np

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

A = np.array(A)
MOD = 10**9 + 7

ruisekiwa = np.zeros(N, dtype='int')
for i in range(1, N):
    ruisekiwa[i] = ruisekiwa[i-1] + A[i]

res = 0
for i in range(N-1):
    # res += np.sum(np.mod(A[i] * A[i+1:], MOD))
    res += (ruisekiwa[N-1] - ruisekiwa[i]) % MOD * A[i] % MOD
print(res % MOD)

# FIXME TLE
### BUGGY CODE ###

n,m,r=map(int,input().split())

ans=3000000000

def permu(ju,now,su,co):
    if now==0:
        global ans
        ans=min(ans,su)
        return
    else:
        for i in range(r):
            if ju[i]:
                ju[i]=False
                su+=dp[co][rute[i]-1]
                permu(ju,now-1,su,rute[i]-1)
                ju[i]=True
                su-=dp[co][rute[i]-1]
    return

rute=list(map(int,input().split()))
dp=[[30000000 for i in range(n)] for i in range(n)]
for i in range(n):
    dp[i][i]=0
for i in range(m):
    a,b,c=map(int,input().split())
    dp[a-1][b-1]=c
    dp[b-1][a-1]=c
for i in range(n):
    for j in range(n):
        for k in range(n):
            dp[j][k]=min(dp[j][i]+dp[i][k],dp[j][k])


ju=[True for i in range(r)]
for i in range(r):
    ju[i]=False
    permu(ju,r-1,0,rute[i]-1)
    ju[i]=True
print(ans)

### FIXED CODE ###

n,m,r=map(int,input().split())

ans=3000000000

def permu(ju,now,su,co):
    if now==0:
        global ans
        ans=min(ans,su)
        return
    else:
        for i in range(r):
            if ju[i]:
                ju[i]=False
                su+=dp[co][rute[i]-1]
                permu(ju,now-1,su,rute[i]-1)
                ju[i]=True
                su-=dp[co][rute[i]-1]
    return

rute=list(map(int,input().split()))
dp=[[30000000 for i in range(n)] for i in range(n)]
for i in range(n):
    dp[i][i]=0
for i in range(m):
    a,b,c=map(int,input().split())
    dp[a-1][b-1]=c
    dp[b-1][a-1]=c
for i in range(n):
    for j in range(n):
        for k in range(n):
            dp[j][k]=min(dp[j][i]+dp[i][k],dp[j][k])


ju=[True for i in range(r)]
for i in range(r):
    ju[i]=False
    permu(ju,r-1,0,rute[i]-1)
    ju[i]=True
print(ans)
### BUGGY CODE ###

# D - RGB Triplets

n = int(input())
s = str(input())

R = [i for i, x in enumerate(s) if x=='R']
G = [i for i, x in enumerate(s) if x=='G']
B = [i for i, x in enumerate(s) if x=='B']

ans = 0

for r in R:
    for g in G:
        for b in B:
            mi = min(r, g, b)
            ma = max(r, g, b)
            if (r+g+b)==mi+ma+(mi+ma)/2:
                continue
            else:
                ans += 1

print(ans)

### FIXED CODE ###

# D - RGB Triplets

n = int(input())
s = str(input())

r = len([i for i, x in enumerate(s) if x=='R'])
g = len([i for i, x in enumerate(s) if x=='G'])
b = len([i for i, x in enumerate(s) if x=='B'])

ans = r * g * b

for i in range(n):
    for j in range(i+1, n):
        k = j+j-i
        if k >= n:
            break
        if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
            ans -= 1

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

D = int(1e9 + 7)
N = int(input())
M = sorted(map(int, input().split()))

sum_ = 0
for i, x in enumerate(M[:-1]):
    for j, y in enumerate(M[i+1:]):
        sum_ += ((x % D) * (y % D)) % D
        sum_ %= D

print(sum_)


### FIXED CODE ###

D = int(1e9 + 7)
N = int(input())
M = [int(i) for i in input().split()]

R = sum(M[1:])

sum_ = 0
for i, x in enumerate(M[:-1]):
    sum_ += R * x
    sum_ %= D
    R -= M[i+1]

print(sum_)
### BUGGY CODE ###

import sys
def gcd(_a, _b):
	if _b==0:return _a
	return gcd(_b, _a%_b)

def lcm(_a, _b):
	return _a * _b // gcd(_a, _b)

K = int(input())
ans=0
for i in range(K):
	for j in range(K):
		for k in range(K):
			ans+=gcd(gcd(i+1,j+1), k+1)
print(ans)


### FIXED CODE ###

import math
K=int(input())
ans=0
for i in range(1,K+1):
    for j in range(1,K+1):
        tmp=math.gcd(i,j)
        for k in range(1,K+1):
            ans+=math.gcd(tmp,k)         
print(ans)
### BUGGY CODE ###

n,k = map(int, input().split())
a = list(map(int, input().split()))
c = 1
for i  in range(k):
    c *= a[i]
for i in range(n):
    if i>=k:
        c1 = c * a[i] / a[i-k]
        c2 = c
        if c1>c2:
            print("Yes")
        else:
            print("No")
        c = c1

### FIXED CODE ###

n,k = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n):
    if i>=k:
        if a[i]>a[i-k]:
            print("Yes")
        else:
            print("No")
### BUGGY CODE ###

# Nの入力
N = int(input())

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

result = 1
if 0 in A:
    result = 0
else:
    for i in A:
        result *= i
        if result > 10 ** 18:
            result = -1
print(result) 
    

### FIXED CODE ###

# Nの入力
N = int(input())

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

result = 1
if 0 in A:
    result = 0
else:
    for i in A:
        result *= i
        if result > 10 ** 18:
            result = -1
            break
print(result)
### BUGGY CODE ###

import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()

print(0)
k = ns()
if k == 'Vacant':
    exit()

ok,ng = n,-1

def is_ok(p):
    print(p)
    q = ns()
    if q == 'Vacant':
        exit()
    return not p%2 ^ (q == k)

while (abs(ok - ng) > 1):
    mid = (ok + ng) // 2
    if is_ok(mid):
        ok = mid
    else:
        ng = mid


### FIXED CODE ###

import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = int(input())
print(0)
l = input()
r = l
if l == "Vacant":
    exit()

ng,ok = 0,n
while True:
    mid = (ng + ok) // 2
    print(mid)
    q = input()
    if q == "Vacant":
        exit()
    if (q == l) ^ ((mid - ng)%2 == 1):
        ng = mid
        l = q
    else:
        ok = mid
        r = q
### BUGGY CODE ###

import sys
input=sys.stdin.readline
N,Q=map(int,input().split())
#dc={i:[] for i in range(1,N)}
lc=[[] for i in range(N)]#二重リストで木を表現
for i in range(N-1):
    a,b=map(int,input().split())
    lc[a-1].append(b-1)
    lc[b-1].append(a-1)
lf=[0 for i in range(N)]#行ったかどうかのフラグ
lv=[0 for i in range(N)]
#*で初期化するとあまり良くない
for i in range(Q):
    p,x=map(int,input().split())
    lv[p-1]+=x
#print("lv",lv)
lque=[0]#次に訪れる親を入れておく(キュー(順番通り))
lf[0]=1
#p=0
while len(lque)!=0:
#count=1
#while count<N:
    #for i in range(len(lc[p]))
    p=lque[0]
    for i in lc[p]:#among children
        #lv[lque[0]]+=
        #c=lc[p][i]
        if lf[i]==0:
             lv[i]+=lv[p]
             lf[i]+=1
             lque.append(i)
             #count+=1
    #p=lque[0]
    lque.remove(p)
for i in lv:
    print(i,end=" ")
print()


### FIXED CODE ###

#import collections
N,Q=map(int,input().split())
lc=[[] for i in range(N)]#二重リストで木を表現
for i in range(N-1):
    a,b=map(int,input().split())
    lc[a-1].append(b-1)
    lc[b-1].append(a-1)
lv=[0 for i in range(N)]#値のリスト
for i in range(Q):
    p,x=map(int,input().split())
    lv[p-1]+=x
lf=[0 for i in range(N)]#訪れたかどうか
#d=collections.deque([0])
lp=[0]
lf[0]=1
#for i in range(N):
while len(lp)>0:
    #p=lp[-1]
    p=lp.pop()
    for c in lc[p]:
        if lf[c]==0:
            lv[c]+=lv[p]
            lf[c]=1
            lp.append(c)
for i in range(N-1):
    print(lv[i],end=" ")
print(lv[N-1])
### BUGGY CODE ###

def solve(string):
    h, w, *s = string.split()
    h, w = map(int, [h, w])
    ht = [[0] * w for _ in range(h)]
    vt = [[0] * h for _ in range(w)]
    for i in range(h):
        st = 0
        c = 0
        for j in range(w):
            if s[i][j] == "#":
                ht[i][st:j] = [c] * (j - st)
                st = j + 1
                c = 0
                continue
            c += 1
        ht[i][st:w] = [c] * (w - st)
    for i in range(w):
        st = 0
        c = 0
        for j in range(h):
            if s[j][i] == "#":
                vt[i][st:j] = [c] * (j - st)
                st = j + 1
                c = 0
                continue
            c += 1
        vt[i][st:h] = [c] * (h - st)

    ans = 0
    for i in range(h):
        for j in range(w):
            ans = max(ans, ht[i][j] + vt[j][i])
    return str(ans - 1)


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))


### FIXED CODE ###

def solve(string):
    h, w, *s = string.split()
    h, w = map(int, [h, w])
    hg = []
    hi = []
    vg = []
    vi = []

    for _s in s:
        gn = 0
        _hi = [0] * w
        _hg = []
        c = 0
        for i, __s in enumerate(_s):
            if __s == "#":
                _hi[i] = -1
                gn += 1
                _hg.append(c)
                c = 0
                continue
            _hi[i] = gn
            c += 1
        _hg.append(c)
        hg.append(_hg)
        hi.append(_hi)
    for _s in zip(*s):
        gn = 0
        _vi = [0] * h
        _vg = []
        c = 0
        for i, __s in enumerate(_s):
            if __s == "#":
                _vi[i] = -1
                gn += 1
                _vg.append(c)
                c = 0
                continue
            _vi[i] = gn
            c += 1
        _vg.append(c)
        vg.append(_vg)
        vi.append(_vi)

    ans = 0
    for i in range(h):
        for j in range(w):
            ans = max(ans, hg[i][hi[i][j]] + vg[j][vi[j][i]])
    return str(ans - 1)


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))
### BUGGY CODE ###

import heapq
X, Y, Z, K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
ans = []
for i in range(X):
    for j in range(Y):
        for k in range(Z):
            ans.append(A[i]+B[j]+C[k])

for i in heapq.nlargest(K, ans):
    print(i)

### FIXED CODE ###

import heapq
X, Y, Z, K = map(int,input().split())
A = list(map(lambda x: -1 * int(x),input().split()))
B = list(map(lambda x: -1 * int(x),input().split()))
C = list(map(lambda x: -1 * int(x),input().split()))
A.sort()
B.sort()
C.sort()
Q = []
heapq.heappush(Q, (A[0] + B[0] + C[0], 0, 0, 0))
for _ in range(K):
    SUM, a, b, c = heapq.heappop(Q)
    print(-1 * SUM)
    if a <= X - 2 and not (A[a+1] + B[b] + C[c], a+1, b, c) in Q:
        heapq.heappush(Q, (A[a+1] + B[b] + C[c], a+1, b, c))
    if b <= Y - 2 and not (A[a] + B[b+1] + C[c], a, b+1, c) in Q:
        heapq.heappush(Q, (A[a] + B[b+1] + C[c], a, b+1, c))
    if c <= Z - 2 and not (A[a] + B[b] + C[c+1], a, b, c+1) in Q:
        heapq.heappush(Q, (A[a] + B[b] + C[c+1], a, b, c+1))
### BUGGY CODE ###

import math
import itertools
from scipy.spatial import distance

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

n_fct = math.factorial(n)
d = [0] * n_fct
for i in itertools.permutations(l):
    for j in range(n-1):
        if j+1 < n:
            d[j] += distance.euclidean((i[j][0], i[j][1]), (i[j+1][0], i[j+1][1]))
        else:
            d[j] += distance.euclidean((i[j][0], i[j][1]), (i[0][0], i[0][1]))

print(sum(d)/len(d))


### FIXED CODE ###

import math
import itertools
from scipy.spatial import distance

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

d = 0
for i in itertools.permutations(l):
    for j in range(n-1):
        if j+1 < n:
            d += math.sqrt((i[j][0] - i[j+1][0]) ** 2 + (i[j][1] - i[j+1][1]) ** 2)

print(d/math.factorial(n))
### BUGGY CODE ###

import itertools

a = int(input())

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

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

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

    return arr

arr0 = factorization(a) 


arr1 = [arr0[i][0] for i in range(len(arr0))]
arr2 = [arr0[i][1] for i in range(len(arr0))]

ab = []
for i in range(len(arr1)):
    for j in range(arr2[i]):
        ab.append(arr1[i])

abc = []
for i in range(1,sum(arr2)+1):
    abc.extend(list(itertools.combinations(ab, i)))

abcd = []

for i in range(len(abc)):
    g = 1
    for j in range(len(abc[i])):
        g *= abc[i][j]
    
    abcd.append(g)


abcde = [[i,a//i] for i in abcd]
abcdef = [sum(abcde[i]) for i in range(len(abcde))]
print(min(abcdef)-2)

### FIXED CODE ###

import itertools

a = int(input())

def md(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

ab = [[i,a//i] for i in md(a)]
abc = [sum(ab[i]) for i in range(len(ab))]

print(min(abc)-2)
### BUGGY CODE ###

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

n = a[0]
k = a[1]

c = []
bfr = 0
aft = 0
for i in range(k-1, n):
    aft = 0
    if bfr != 0:
        aft = (bfr / b[i - k]) * b[i] 
        if bfr < aft:
            c.append("Yes")
        else:
            c.append("No")
        bfr = aft
    else:
        bfr = 1
        for j in range(0, k):
            bfr *= b[j]
    
            
s_n = '\n'.join(c)
print(s_n)   

### FIXED CODE ###

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

n = a[0]
k = a[1]

c = []
bfr = 0
aft = 0
for i in range(k-1, n):
    if i != k-1:
        if b[i - k] < b[i]:
            c.append("Yes")
        else:
            c.append("No")
    
            
s_n = '\n'.join(c)
print(s_n)
### BUGGY CODE ###

N=int(input())
A = [list(map(int, input().split())) for i in range(N)]
result=0
flag=True
isbreak=False
for m in range(N-1):
    for n in range(m+1,N):
        list_t=list(range(N))
        list_t.remove(m)
        list_t.remove(n)
        for t in list_t:
            if A[m][n]>A[m][t]+A[t][n]:
                result=-1                
                isbreak=True
                break
            elif A[m][n]==A[m][t]+A[t][n] and result!=-1:
                flag=False
                break
        if flag and result!=-1:
            result+=A[m][n]
        else:
            flag=True
        if isbreak:
            break
    if isbreak:
        break
print(result)


### FIXED CODE ###

N=int(input())
A = [list(map(int, input().split())) for i in range(N)]
result=0
flag=True
isbreak=False
for m in range(N-1):
    for n in range(m+1,N):
        list_t=list(range(N))
        list_t.remove(m)
        list_t.remove(n)
        for t in list_t:
            if A[m][n]>A[m][t]+A[t][n]:
                result=-1                
                isbreak=True
                break
            elif A[m][n]==A[m][t]+A[t][n] and result!=-1:
                flag=False
                break
        if flag and result!=-1:
            result+=A[m][n]
        else:
            flag=True
        if isbreak:
            break
    if isbreak:
        break
print(result)
### BUGGY CODE ###

from sys import stdin
input = stdin.readline


def main():
    n, m = map(int, input().split())

    nexts = [[] for i in range(n)]
    
    for i in range(m):
        ai, bi = map(int, input().split())
        ai -= 1
        bi -= 1
        nexts[ai].append(bi)
        nexts[bi].append(ai)

    blues = [1] * n # 1 is in blues
    blues[0] = 0 # 0 is not in blues
    reds = [0] * n
    reds[0] = 1
    new_reds = [0] * n

    arrows = [0] * n

    while 1 in blues:
        for i in range(n):
            if reds[i] == 1:
                for nxt in nexts[i]:
                    if blues[nxt] == 1:
                        blues[nxt] = 0
                        new_reds[nxt] = 1
                        arrows[nxt] = i

        reds = new_reds
        new_reds = [0] * n
    
    print("Yes")
    for arrow in arrows[1:]:
        print(arrow + 1)
    

if __name__ == "__main__":
    main()

### FIXED CODE ###

from sys import stdin
from collections import deque
input = stdin.readline


def main():
    n, m = map(int, input().split())

    nexts = [[] for i in range(n)]
    
    for _ in range(m):
        ai, bi = map(int, input().split())
        ai -= 1
        bi -= 1
        nexts[ai].append(bi)
        nexts[bi].append(ai)

    blues = [-1] * n # 1 is in blues
    blues[0] = 0 # 0 is not in blues
    checked = [0] * n

    red_deque = deque([0])

    while len(red_deque) > 0:
        rd = red_deque[0]
        red_deque.popleft()
        if checked[rd] == 0:
            checked[rd] = 1
            for nxt in nexts[rd]:
                if blues[nxt] == -1:
                    blues[nxt] = rd
                    red_deque.append(nxt)

    print("Yes")
    for blue in blues[1:]:
        print(blue + 1)
    

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

#!/usr/local/bin python
# -*- coding: utf-8 -*-
#
# ~/PycharmProjects/atcoder/C-GuessTheNumber.py
#
k, s = map(int, input().split())
pattern = 0

for x in range(k+1):
    for y in range(k+1):
        for z in range(k+1):
            if x + y + z == s:
                pattern += 1

print(pattern)

### FIXED CODE ###

#!/usr/local/bin python
# -*- coding: utf-8 -*-
#
# ~/PycharmProjects/atcoder/C-GuessTheNumber.py
#
k, s = map(int, input().split())
pattern = 0

if s == 0 or s == 1:
    print(1)
    exit()

if s <= k:
    print((s+2)*(s+1)//2)
    exit()

# elif 2*k < s <= 3*k:
#     for i in range(k+1):
#         x = k - i
#         y = k
#         z = s - x - y
#         if z <= k:
#             pattern += (y - z + 1)
#         else:
#             break

for x in range(k+1):
    for y in range(k+1):
        z = s - x - y
        if 0 <= z <= k:
            pattern += 1


# for x in range(k+1):
#     x_tmp = x
#     for y in range(x_tmp, k+1):
#         y_tmp = y
#         for z in range(y_tmp, s+1-x_tmp-y_tmp):
#             if x_tmp + y_tmp + z == s:
#                 if x_tmp == y_tmp == z:
#                     pattern += 1
#                 elif x_tmp == y_tmp or x_tmp == z or y_tmp == z:
#                     pattern += 3
#                 else:
#                     pattern += 6
#                 break

print(pattern)
### BUGGY CODE ###

from functools import reduce
import copy

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

def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    if x%y == 0:
        return y
    else:
        while x%y != 0:
            z = x%y
            x = y
            y = z
        else:
            return z

def gcd_list(*numbers):
    return reduce(gcd, numbers)

ans = 0
for i in range(N):
    a = copy.copy(A)
    a.pop(i)
    kouyaku = gcd_list(*a)
    ans = max(ans, kouyaku)

print(ans)

### FIXED CODE ###

import fractions

N = int(input())
A = list(map(int,input().split()))
l = [0] * (N+1)
r = [0] * (N+1)

for i in range(1, N+1):
    l[i] = fractions.gcd(l[i-1], A[i-1])
for i in range(1, N+1):
    r[N-i] = fractions.gcd(r[N-i+1], A[N-i])

ans = 0
for i in range(N):
    kouyaku = fractions.gcd(l[i], r[i+1])
    ans = max(ans, kouyaku)

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

# -*- coding: utf-8 -*-
# 整数の入力
N = int(input())
A = [int(a) for a in input().split()]
Q = int(input())
process = []
proc_append = process.append
for i in range(Q):
	proc_append(tuple(input().split()))
	process[i] = tuple(map(int,process[i]))
A.sort()
for b,c in process:
	if b in set(A):
		for i in range(N):
			if b==A[i]:
				begin = i
				break
		for i in range(begin,N):
			if b!=A[i]:
				end = i-1
				break
			if i==N-1:
				end = i
		for i in range(begin,end+1):
			A[i] = c
	print(sum(A))

### FIXED CODE ###

# 整数の入力
N = int(input())
A = [int(a) for a in input().split()]
Q = int(input())
process = []
proc_append = process.append
hash = [0]*100001
for i in range(Q):
    proc_append(tuple(input().split()))
    process[i] = tuple(map(int,process[i]))

goukei = sum(A)

for i in A:
	hash[i] += 1

for b,c in process:
	if hash[b] != 0:
		goukei += (c-b)*hash[b]
		hash[c] += hash[b]
		hash[b] = 0
	print(goukei)
### BUGGY CODE ###

n=int(input())
s=input()
c=[[0,0,0] for _ in range(n+1)]
R=G=B=0
for j,i in enumerate(s):
    if i=="R":
        R+=1
    elif i=="G":
        G+=1
    else:B+=1
    c[j+1]=[R,G,B]
a=0
for i,m in enumerate(s):
    for j,M in enumerate(s[:i]):
        if m!=M:
            k=3-"RGB".index(m)-"RGB".index(s[j])
            a+=c[-1][k]-c[i][k]
            if 2*i-j<=n-1:
                if s[2*i-j]=="RGB"[k]:
                    a-=1
print(a)

### FIXED CODE ###

n=int(input())
s=input()
c=s.count
a=c("R")*c("G")*c("B")
for i in range(n-2):
    for j in range((n-i+1)//2):
        if s[i]!=s[i+j] and s[i+j]!=s[i+2*j] and s[i+2*j]!=s[i]:
            a-=1
print(a)
### BUGGY CODE ###

l,r = map(int,input().split())
mod_min = 2020
mod_set = set()

for i in range(l,r+1):
  mod = i % 2019
  mod_set.add(mod)

mod_list = list(mod_set)
l = len(mod_list)
for i in mod_list:
  for j in mod_list[mod_list.index(i)+1:l]:
    mod_ij = (i*j)%2019
    if mod_ij < mod_min:
      mod_min = mod_ij
    else:
      pass
    
print(mod_min)
  

  
  


    

### FIXED CODE ###

l,r = map(int,input().split())
if r-l > 2017:
  print(0)
else:
  mod_min = 2019
  for i in range(l,r+1):
    for j in range(i+1,r+1):
      mod = (i*j)%2019
      if mod <= mod_min:
        mod_min = mod
      else:
        pass
  print(mod_min)
### BUGGY CODE ###

N = int(input())
s_list = [input() for i in range(N)]

count = 0

for i in range(len(s_list)):
  for j in range(i+1, len(s_list)):
    if sorted(s_list[i]) == sorted(s_list[j]):
      count += 1
      
print(count)

### FIXED CODE ###

import collections

N = int(input())
s_list = ["".join(sorted(input())) for i in range(N)]
s_list = sorted(s_list)

count = 0

c = collections.Counter(s_list)

for item in c:
  for pair in range(c[item]):
    count += pair
        
print(count)
### BUGGY CODE ###

import numpy as np

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

dp = [[0]*(W+1) for _ in range(N+1)]

for i in range(1, N+1):
  w, v = map(int, input().split())
  for j in range(1, W+1):
    if j >= w:
      dp[i][j] = max(dp[i-1][j], dp[i-1][j-w]+v)
    else:
      dp[i][j] = dp[i-1][j]

print(dp[N][W])

### FIXED CODE ###

N, W = map(int, input().split())
items = [list(map(int, input().split())) for _ in range(N)]

table = {i: [0]*(W+1) for i in range(N+1)}
def dp(N, W):
  for i in range(1, N+1):
    w, v = items[i-1]
    for j in range(1, W+1):
      if w <= j:
        table[i][j] = max(table[i-1][j-w]+v, table[i-1][j])
      else:
        table[i][j] = table[i-1][j]
  return table[N][W]

print(dp(N, W))