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

cnt = 0
S = input()  
for left in range(len(S)-3):
    int_s = int(S[left:left+4])
    
    if int_s % 2019 == 0:
        cnt += 1
    for right in range(left+4,len(S)):
        int_s = int_s * 10 + int(S[right])
        if int_s % 2019 == 0:
            cnt += 1
print(cnt)        



### FIXED CODE ###

from collections import Counter

S = [int(i) for i in input()]
S.reverse()
lst = []
_sum = 0

for i in range(len(S)):
    _sum = (_sum + S[i] * pow(10,i,2019)) % 2019
    lst.append(_sum)
    
C = Counter(lst)    
ans = C[0]

for i in C:
    ans += C[i]*(C[i]-1)//2
print(ans)
### BUGGY CODE ###

S = input()
slist = S.split("LR")
res = [["0"] * len(s) for s in slist]
for i in range(len(slist)):
  if i < len(slist) - 1:
    slist[i] = slist[i] + "L"
    res[i].append("0")
    slist[i + 1] = "R" + slist[i + 1]
    res[i + 1].append("0")
  Rc = slist[i].count("R")
  Lc = slist[i].count("L")
  #print(slist[i], Rc, Lc)
  res[i][Rc - 1] = str(Lc // 2 + (Rc - Rc // 2))
  res[i][Rc] = str(Rc // 2 + (Lc - Lc // 2))
res2 = ""
#print(res)
for i in range(len(slist)):
  #print(res[i])
  res2 = res2 + " ".join(res[i])
  if i < len(slist) -1:
    res2 = res2 + " "
print(res2)

### FIXED CODE ###

S = input()
slist = S.split("LR")
res = [["0"] * len(s) for s in slist]
for i in range(len(slist)):
  if i < len(slist) - 1:
    slist[i] = slist[i] + "L"
    res[i].append("0")
    slist[i + 1] = "R" + slist[i + 1]
    res[i + 1].append("0")
  Rc = slist[i].count("R")
  Lc = slist[i].count("L")
  #print(slist[i], Rc, Lc)
  res[i][Rc - 1] = str(Lc // 2 + (Rc - Rc // 2))
  res[i][Rc] = str(Rc // 2 + (Lc - Lc // 2))
res2 = ""
#print(res)
for i in range(len(slist)):
  #print(res[i])
  res2 = res2 + " ".join(res[i])
  if i < len(slist) -1:
    res2 = res2 + " "
print(res2)
### BUGGY CODE ###

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

S = list(map(int,input().split()))
T = list(map(int,input().split()))

# 累積和参照のために0の行，列を追加
sm = [[0] * (M+1) for _ in range(N+1)]

for i , s in enumerate(S) :
    l1 = sm[i][:]
    l2 = 0
    for j , t in enumerate(T) :
        new = l1[j+1] + l2
        if s == t :
            new += 1  # dp = sm[i-1][j-1] + 1
        else :
            new -= l1[j] # dp = 0
        l2 = new
        sm[i+1][j+1] = new

ans = (sm[-1][-1] + 1) % (10**9 + 7)

print(ans)

### FIXED CODE ###

N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
MOD = 10**9 + 7

dp = [[0] * (M + 1) for _ in range(N + 1)]  # dp[s][t]

for i, s in enumerate(S, start=1):
    for j, t in enumerate(T, start=1):
        v = dp[i - 1][j] + dp[i][j - 1]
        if s == t:
            v += 1
        else:
            v -= dp[i - 1][j - 1]
        dp[i][j] = v % MOD

print((dp[-1][-1] + 1) % MOD)
### BUGGY CODE ###

N = int(input())
power = 1
for i in range(N):
  power *= i+1
print(power % (pow(10, 9) + 7))

### FIXED CODE ###

N = int(input())
power = 1
for i in range(N):
  power = (power*(i+1)) % (10**9+7)
print(power)
### BUGGY CODE ###

N = int(input())
GA, SA, BA = map(int, input().split())
GB, SB, BB = map(int, input().split())

def napsac(x, g1, s1, b1, g2, s2, b2):
    dp = [None for _ in range(x+1)]
    dp[0] = 0

    def case(i, m1, m2):
        return 0 if i - m1 < 0 else dp[i-m1] + m2

    for i in range(1,x+1):
        dp[i] = max(i, case(i, g1, g2), case(i, s1, s2), case(i, b1, b2))

    return dp[-1]

print(napsac(napsac(N, GA, SA, BA, GB, SB, BB), GB, SB, BB, GA, SA, BA))


### FIXED CODE ###

N = int(input())
GA, SA, BA = map(int, input().split())
GB, SB, BB = map(int, input().split())

def napsac(x, g1, s1, b1, g2, s2, b2):
    dp = [0 for _ in range(x+1)]
    dp[0] = 0

    def case(i, m1, m2):
        return 0 if i - m1 < 0 else dp[i-m1] + m2

    for i in range(1,x+1):
        dp[i] = max(i, case(i, g1, g2), case(i, s1, s2), case(i, b1, b2))

    return dp[-1]

print(napsac(napsac(N, GA, SA, BA, GB, SB, BB), GB, SB, BB, GA, SA, BA))
### BUGGY CODE ###

# -*- coding: utf-8 -*-
# !/usr/bin/env python
# vim: set fileencoding=utf-8 :

"""
#
# Author:   Noname
# URL:      https://github.com/pettan0818
# License:  MIT License
# Created:  2016-10-07
#

# Usage
#
"""
from __future__ import division
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import absolute_import

def read():
    """Read like as below.
    N A B
    t_1
    t_n
    """
    line_1 = input().split(" ")
    num_of_class = int(line_1[0])
    blocked_class = line_1[1:2]
    blocked_class = range(int(line_1[1]), int(line_1[2]))

    following_class = [int(input()) for _ in range(num_of_class)]

    return following_class, blocked_class


def check_available_class(following_class, blocked_class):
    """Check how many class you can attend.
    >>> check_available_class([4,3,6,9,1], [5,6,7,8])
    4
    >>> check_available_class([5,6,7,8,9], [4,5,6,7,8])
    1
    """
    print(len(set(following_class) - set(blocked_class)))


if __name__ == "__main__":
    f, b = read()
    check_available_class(f,b)


### FIXED CODE ###

# -*- coding: utf-8 -*-
# !/usr/bin/env python
# vim: set fileencoding=utf-8 :

"""
#
# Author:   Noname
# URL:      https://github.com/pettan0818
# License:  MIT License
# Created:  2016-10-07
#

# Usage
#
"""

def read():
    """Read like as below.
    N A B
    t_1
    t_n
    """
    line_1 = input().split(" ")
    num_of_class = int(line_1[0])
    blocked_class = line_1[1:2]
    blocked_class = range(int(line_1[1]), int(line_1[2]))

    following_class = {int(input()) for _ in range(num_of_class)}

    return following_class, blocked_class


def check_available_class(following_class, blocked_class):
    """Check how many class you can attend.
    >>> check_available_class([4,3,6,9,1], [5,6,7,8])
    4
    >>> check_available_class([5,6,7,8,9], [4,5,6,7,8])
    1
    """
    # return len(set(following_class).difference(blocked_class))
    attendable = [i for i in following_class if not i in blocked_class]
    return len(attendable)

if __name__ == "__main__":
    import doctest
    doctest.testmod()
    f, b = read()
    print(check_available_class(f,b))
### BUGGY CODE ###

def main():
    n,k=map(int,input().split())
    A=list(map(int,input().split()))
    L=set(A)
    m=len(L)-k
    if m<=0:
        print(0)
    else:
        D=[0]*len(L)
        for i, l in enumerate(L):
            D[i]=A.count(l)
        print(sum(sorted(D)[:m]))
main()

### FIXED CODE ###

from collections import Counter
def main():
    n,k=map(int,input().split())
    A=Counter(list(map(int,input().split())))
    # Aの重複元の個数を降順に並べてk番以降の和を数える.
    print(sum(sorted(A.values())[::-1][k:]))
main()
### BUGGY CODE ###

c=list(map(int,input().split()))
bunsi=c[0]
bunbo=c[1]
n=c[2]
k=n//bunbo
d=[n]
if k!=0:
    for i in range(0,k):
        d.append(bunbo*(i+1)-1)
def floor(x):
    return ((bunsi*x)//bunbo)-(bunsi*(x//bunbo))
temp= floor(d[0])
if len(d)>1:
    for i in range(1,len(d)):
        temp=max(temp,floor(d[i]))
    print(temp)
else:
    print(temp)

### FIXED CODE ###

c=list(map(int,input().split()))
bunsi=c[0]
bunbo=c[1]
n=c[2]
k=n//bunbo
d=[n]
if k>=1:
    d.append(bunbo-1)
    d.append(bunbo*k-1)
#dの中には候補となるxが入った
def floor(x):
    return ((bunsi*x)//bunbo)-(bunsi*(x//bunbo))
if len(d)>=2:
    print(max(floor(d[0]),floor(d[-1]),floor(d[-2])))
if len(d)==1:
    print(floor(d[0]))
### BUGGY CODE ###

k, s = map(int, input().split())

ans = 0
for x in reversed(range(k+1)):
    for y in reversed(range(k+1)):
        for z in reversed(range(k+1)):
            if x+y+z == s:
                ans += 1
            elif x+y+z < s:
                break
print(ans)

### FIXED CODE ###

k, s = map(int, input().split())

ans = 0
for x in reversed(range(k+1)):
    for y in reversed(range(k+1)):
        if s-(x+y) >= 0 and s-(x+y) <= k:
            ans += 1
print(ans)
### BUGGY CODE ###

from itertools import combinations

N,M = map(int,input().split()) # <=1000
xyz = [list(map(int,input().split())) for _ in range(N)]
x = [i[0] for i in xyz]
y = [i[1] for i in xyz]
z = [i[2] for i in xyz]
if  M == 0:
    print(0)
    exit()
result = 0
for s in combinations(range(N),M):
    tx = ty = tz = 0
    for i in s:
        tx += x[i]
        ty += y[i]
        tz += z[i]
    result = max(result,abs(tx)+abs(ty)+abs(tz))
print(result)


### FIXED CODE ###

import itertools

N,M = map(int,input().split()) # <=1000
xyz = [list(map(int,input().split())) for _ in range(N)]
if  M == 0:
    print(0)
    exit()
result = 0
L = [[0] * N for i in range(8)]
for i,j in enumerate(itertools.product((-1,1),repeat=3)):
    for k,l in enumerate(xyz):
        L[i][k] = l[0] * j[0] + l[1] * j[1] + l[2] * j[2]
    L[i] = sorted(L[i],reverse=True)
print(max([sum(i[:M]) for i in L]))
### BUGGY CODE ###

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

if N == 1:
    print(1)
elif N == 2:
    print(1)
else:
    cnt = 0
    for i in range(N - 1):
        if A[i] == A[i + 1]:
            A[i] = 0
            cnt += 1

    for _ in range(cnt):
        A.remove(0)
    #print(A)

    i = 1
    ans = 1
    n = len(A)
    while i < n - 1:
        if A[i-1] < A[i] < A[i+1] or A[i-1] > A[i] > A[i+1]:
            pass
        else:
            i += 1
            ans += 1
        i += 1
    print(ans)



### FIXED CODE ###

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

if N == 1:
    print(1)
elif N == 2:
    print(1)
else:
    A = [B[0]]
    cnt = 0
    for i in range(N - 1):
        if B[i] == B[i + 1]:
            pass
        else:
            A.append(B[i+1])

    i = 1
    ans = 1
    n = len(A)
    while i < n - 1:
        if A[i-1] < A[i] < A[i+1] or A[i-1] > A[i] > A[i+1]:
            pass
        else:
            i += 1
            ans += 1
        i += 1
    print(ans)
### BUGGY CODE ###

# ABC174-F

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

Bsize = int(N ** 0.5)+1
query = []
for q in range(Q):
    l, r = map(int, input().split())
    query.append((l-1, r-1, q, l // Bsize))
query.sort(key=lambda x: x[1])
query.sort(key=lambda x: x[3])

# [l, r)での求める値を管理するための変数たち
# 問題によって変える
cnt = [0] * (N+1)
val = 0

# 区間の伸縮操作
# 問題によって変える
def add(i):
    global val
    cnt[A[i]] += 1
    if cnt[A[i]] == 1:
        val += 1

def rem(i):
    global val
    cnt[A[i]] -= 1
    if cnt[A[i]] == 0:
        val -= 1

# init
l, r, _, _ = query[0]
for i in range(l, r+1):
    add(i)


# process
ans = [0] * Q
for l_new, r_new, q, _ in query:
    if r < r_new:
        for i in range(r+1, r_new+1):
            add(i)
    elif r > r_new:
        for i in range(r, r_new, -1):
            rem(i)
    if l < l_new:
        for i in range(l, l_new):
            rem(i)
    elif l > l_new:
        for i in range(l-1, l_new-1, -1):
            add(i)
    l = l_new
    r = r_new
    ans[q] = val

for a in ans:
    print(a)


### FIXED CODE ###

mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.buffer.readline

    class Bit:
        def __init__(self, n):
            self.size = n
            self.tree = [0] * (n + 1)

        def sum(self, i):
            s = 0
            while i > 0:
                s += self.tree[i]
                i -= i & -i
            return s

        def add(self, i, x):
            while i <= self.size:
                self.tree[i] += x
                i += i & -i

        def lower_bound(self, w):
            if w <= 0:
                return 0
            x = 0
            k = 1 << (self.size.bit_length() - 1)
            while k:
                if x + k <= self.size and self.tree[x + k] < w:
                    w -= self.tree[x + k]
                    x += k
                k >>= 1
            return x + 1

    N, Q = map(int, input().split())
    C = list(map(int, input().split()))
    query = []
    for q in range(Q):
        query.append(list(map(int, input().split())))
        query[-1].append(q)
    query.sort(key=lambda x: x[1])

    last = [0] * (N+1)
    for i, c in enumerate(C):
        if i > query[0][1]-1:
            break
        last[c] = i+1

    bit = Bit(N)
    for i in range(1, N+1):
        if last[i]:
            bit.add(last[i], 1)
    r_prev = query[0][1]
    ans = [0] * Q
    for l, r, q in query:
        if r > r_prev:
            for i in range(r_prev+1, r+1):
                j = last[C[i-1]]
                if j:
                    bit.add(j, -1)
                last[C[i-1]] = i
                bit.add(i, 1)
            r_prev = r
        ans[q] = bit.sum(r) - bit.sum(l-1)

    for a in ans:
        print(a)


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

import numpy as np

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

A_ = sorted(A_)
A = np.array(A_)

dic = {}
for a in A:
    dic[a] = 0

for a in A:
    dic[a] += 1

ans = 0
for X in dic.keys():
    tmp = 0
    tmp = np.sum((X-1 <= A) & (A<= X+1))
    ans = max(tmp,ans)


# ans = max(ans,dic[X] + dic[X+1])

# for X in A[1:]:

#     tmp = dic[]


#     tmp = dic[dic.key()] + dic[X] + dic[X+1]

#     ans = max(tmp,ans)
print(ans)


### FIXED CODE ###

import collections

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

dic = collections.Counter(A)
tmp = [0 for _ in range(A[-1]+1)]


for X in dic.keys():
    tmp[X] = dic[X]

ans = 0
for i in range(len(tmp)):
    ans = max(ans,sum(tmp[i:i+3]))

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

S = input()
S = list(input())
S_len = len(S)
ans = 0
i = 0
for _ in range(S_len):
  for j in range(len(S)-i-1):
    if S[i] == S[i+j+1]:
      continue
    for k in range(len(S)-i-j-2):
      if j != k and S[i] != S[i+j+1] and S[i] != S[i+k+j+2] and S[i+k+j+2] != S[i+j+1]:
          ans+=1
  S  = S[1:]
print(ans)

### FIXED CODE ###

S = input()
S = list(input())
S_len = len(S)
ans = 0
i = 0
for _ in range(S_len):
  if S[0] == 'R':
    ans += S[1:].count('B') * S[1:].count('G')
    for j in range(int(len(S)/2+1)):
      try:
        if S[j+1] != S[j*2+2] and S[j*2+2] !='R' and S[j+1] !='R':
          ans-=1
      except:
        pass
  if S[0] == 'B':
    ans += S[1:].count('R') * S[1:].count('G')
    for j in range(int(len(S)/2+1)):
      try:
        if S[j+1] != S[j*2+2] and S[j*2+2] !='B' and S[j+1] !='B':
          ans-=1
      except:
        pass
  if S[0] == 'G':
    ans += S[1:].count('B') * S[1:].count('R')
    for j in range(int(len(S)/2+1)):
      try:
        if S[j+1] != S[j*2+2] and S[j*2+2] !='G' and S[j+1] !='G':
          ans-=1
      except:
        pass
  S  = S[1:]
print(ans)
### BUGGY CODE ###

#147_D
n = int(input())
A = list(map(int, input().split()))
ans = 0
mod = 10 ** 9 + 7

for i in range(60):
    s = sum([(a >> i) & 1 for a in A])
    ans = (ans + s * (n-s) * pow(2,i,mod)) % mod
print(ans)

### FIXED CODE ###

#147_D
n = int(input())
A = list(map(int, input().split()))
ans = 0
mod = 10 ** 9 + 7

for i in range(60):
    s = sum([(a >> i) & 1 for a in A])
    ans = (ans + s * (n-s) * pow(2,i,mod)) % mod
print(ans)
### BUGGY CODE ###

N,M = map(int,input().split())
A = list(map(int,input().split()))
BC = [list(map(int,input().split())) for _ in range(M)]
ans = []
A.sort()
count = 0
for b,c in BC:
    ans += [c]*b
ans.extend(A)
ans = sorted(ans,reverse = True)
print(sum(ans[:N]))

### FIXED CODE ###

N,M = map(int,input().split())
A = list(map(int,input().split()))
BC = [(A[i], 1) for i in range(N)]
for _ in range(M):
    B, C = map(int, input().split())
    BC.append((C,B))
BC = sorted(BC,reverse = True)
ans = 0
a = 0
count = N
for c,b in BC:
  lamb = min(count,b)
  ans += c * lamb
  count -= lamb

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

def data_input():
    D = int(input())
    C = tuple(map(int, input().split()))

    S = []
    for i in range(D):
        s = tuple(map(int, input().split()))
        S.append(s)

    return D, C, S


def score(D, C, S, T):
    """入力D, C, Sと出力Tからスコアを計算する関数"""

    last = [0] * 26  # 0で初期化されている

    def decrease(d, last):
        """d日めにiを開催した時の満足度の減少を返す関数"""
        res = 0
        for i in range(26):
            ith = C[i] * (d+1 - last[i])
            res -= ith
        return res

    V = []  # V[d]はd日めの満足度を表す
    for d, i in enumerate(T):
        if d == 0:
            v = 0
        last[i] = d + 1
        v += S[d][i] + decrease(d, last)
        # print(d, i, v, S[d][i], decrease(d, last), last)
        V.append(v)
    return V

D, C, S = data_input()
T = []
for d in range(D):
    local_max = 0
    for i in range(26):
        if score(d, C, S, T+[i])[-1] >= local_max:
            max_i = i
            local_max = score(d, C, S, T+[i])[-1]
            # print(f'local_max at {d}-day is updated to {local_max}')
    T.append(max_i)

V = score(D, C, S, T)

for v in V:
    print(v)

### FIXED CODE ###

D = 365

for i in range(D):
  print(1)
### BUGGY CODE ###

s = input()

cnt = 0
for i in range(len(s)):
    for j in range(i+1, len(s) + 1):
        n = s[i:j]
        if int(n) % 2019 == 0:
            cnt += 1

print(cnt)


### FIXED CODE ###

S = input()[::-1]
ans = 0
mods = [0] * 2019
mods[0] = 1
current = 0
x = 1
for s in S:
    current = (current + x * int(s)) % 2019
    ans += mods[current % 2019]
    mods[current % 2019] += 1
    x = x * 10 % 2019
print(ans)
### BUGGY CODE ###

k = int(input())
a = list(map(str, list(range(1, 10))))
ans = a + []
illist = []
for i in range(10):
    if i == 0:
        illist.append(["0","1"])
    elif i == 9:
        illist.append(["8","9"])
    else:
        illist.append([str(i-1),str(i),str(i+1)])
while len(ans) < k:
    b = []
    for i in a:
        if i == "323456667":
            break
        intil = int(i[-1])
        c = [i + j for j in illist[intil]]
        b = b + c
    a = b
    ans = ans + b

print(ans[k-1])

### FIXED CODE ###

k = int(input())
from collections import deque
q = deque()
a = list(map(str, list(range(1, 10))))
ans = a + []
illist = []
for i in range(10):
    if i == 0:
        illist.append(["0","1"])
    elif i == 9:
        illist.append(["8","9"])
    else:
        illist.append([str(i-1),str(i),str(i+1)])
for i in range(1,10):
    q.append(str(i))

node = "0"
while node != "323456667":
    node = q.popleft()
    for j in illist[int(node[-1])]:
        nodej = node+j
        q.append(nodej)
        a.append(nodej)

print(a[k - 1])
### BUGGY CODE ###

from string import ascii_lowercase
def lower_bound(al, key):
    """
    一般に左側が満たしておらず、右側は満たしている判定基準(境目は一つ)ならlower_boundになる
    (条件を満たすもののうち、最小のインデックスを返す)
    単調にさえなっていれば、左右が逆になっていても検索には使える(ng/okも一緒に逆にする必要がある)
    """
    def isOk(a):
        # alの中でkey以上のアイテムのうち最小のインデックスを返す
        # upper_boundにする時にはa>key
        return a>key

    ng = -1
    ok = len(al)

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

        if isOk(al[mid]):
            ok = mid
        else:
            ng = mid

    return ok

s = input()
n = len(s)

d = {}
for c in ascii_lowercase:
    d[c] = []

for i in range(n):
    d[s[i]].append(i)

res = 1
for c1 in ascii_lowercase:
    for c2 in ascii_lowercase:
        if c1==c2:
            continue
        for i in d[c1]:
            j = lower_bound(d[c2], i)
            res += len(d[c2]) - j
print(res)

### FIXED CODE ###

from string import ascii_lowercase
def lower_bound(al, key):
    """
    一般に左側が満たしておらず、右側は満たしている判定基準(境目は一つ)ならlower_boundになる
    (条件を満たすもののうち、最小のインデックスを返す)
    単調にさえなっていれば、左右が逆になっていても検索には使える(ng/okも一緒に逆にする必要がある)
    """
    def isOk(a):
        # alの中でkey以上のアイテムのうち最小のインデックスを返す
        # upper_boundにする時にはa>key
        return a>key

    ng = -1
    ok = len(al)

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

        if isOk(al[mid]):
            ok = mid
        else:
            ng = mid

    return ok

s = input()
n = len(s)

d = {}
for c in ascii_lowercase:
    d[c] = []

for i in range(n):
    d[s[i]].append(i)

res = 1
for i in range(n):
    c = s[i]
    j = lower_bound(d[c],i)
    res += (n-i) - (len(d[c])-j) - 1
print(res)
### BUGGY CODE ###

from math import gcd

N, M = map(int, input().split())
S = input()
T = input()

L = N*M // gcd(N, M)
X = ["0" for _ in range(L)]

for i in range(N):
    for j in range(M):
        if M*i == N*j and S[i] != T[j]:
            print(-1)
            exit()
        else:
            X[i*L//N] = S[i]
            X[j*L//M] = T[j]

print(L)


### FIXED CODE ###

from math import gcd

N, M = map(int, input().split())
S = input()
T = input()

L = N*M // gcd(N, M)

for i in range(N):
    if M*i % N == 0:
        j = M*i // N
        if S[i] != T[j]:
            print(-1)
            exit()

print(L)
### BUGGY CODE ###

input()
a=list(map(int,input().split()))
b=int(input())
for i in range(b):
  c,d=map(int,input().split())
  e=a.count(c)
  for i in range(e):
    f=a.index(c)
    a[f]=d
  print(sum(a))

### FIXED CODE ###

from sys import stdin
input=stdin.readline
input()
a=list(map(int,input().split()))
ans=sum(a)
b=[0]*(10**5+1)
for i in a:
  b[i]+=1
c=int(input())
for i in range(c):
  n,m=map(int,input().split())
  if b[n]>0:
    x=b[n]
    if x>0:
      b[m]+=x
      b[n]=0
      ans+=(m-n)*x
  print(ans)
### BUGGY CODE ###

l = list(map(int, input().split()))
k = int(input())

while(k > 0):
    if l[0] > l[1]:
        l[1] *= 2
        k -= 1
    elif l[1] > l[2]:
        l[2] *= 2
        k -= 1
    
    if l[0] < l[1] and l[1] < l[2]:
        print('Yes')
        exit()

print('No')

### FIXED CODE ###

r,g,b = list(map(int, input().split()))
k = int(input())

for _ in range(k):
    if r >= g:
        g *= 2
    elif g >= b:
        b *= 2
    
    if r < g and g < b:
        print('Yes')
        exit()

print('No')
### BUGGY CODE ###

n = int(input())
c = input()
ans = 0

while c.count('WR') >= 1:
    leftW = c.find('W')
    rightR = c.rfind('R')
    if leftW != -1 and rightR != -1:
        c = c[leftW+1:rightR]
        ans += 1
print(ans)

### FIXED CODE ###

n = int(input())
c = input()

w = 0
r = c.count('R')
i = 0
ans = max(w, r)
while i <= n - 1:
    if c[i] == 'W':
        w += 1
    else:
        r -= 1
    ans = min(ans, max(w, r))
    i += 1
print(ans)
### BUGGY CODE ###

N = int(input())

a = []
for i in range(N):
    a.append(int(input()))

for i in range(N):
    max = 0
    for j in range(N):
        if j!=i and max < a[j]:
            max = a[j]
    print(max)
        

### FIXED CODE ###

import numpy as np

N = int(input())

a = []
for i in range(N):
    a.append(int(input()))

if(N==1):
    print(a[0])
else:
    a_max = 0
    n_a_max = 0
    all_max = max(a)
    max_arg = np.argmax(a)

    if(max_arg!=0):
        a_max = max(a[:max_arg])
    if(max_arg!=N-1):
        n_a_max = max(a[max_arg+1:])

    if(a_max>=n_a_max):
        next_max = a_max
    else:
        next_max = n_a_max

    for i in range(N):
        if a[i]==all_max:
            print(next_max)
        else:
            print(all_max)
### BUGGY CODE ###

import numpy as np

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

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

R_list = []
B_list = []
C_list = []
for _ in range(M):
  B, C = map(int, input().split())
  B_list.append(B)
  C_list.append(C)

BC_list = [(B,C) for B, C in zip(B_list, C_list)]
BC_list.sort(key=lambda x: x[1])
BC_list = [[C]*B for B, C in BC_list]

R_list = sum(BC_list, [])

R_list = np.array(R_list)
R_list = R_list[::-1]
R_list = R_list[:N]

A_list = np.array(A_list)
A_list = np.sort(A_list)

short_len = N - len(R_list)

if short_len > 0:
  R_list = np.append(R_list, [0]*short_len)

print(np.sum(np.maximum(A_list,R_list)))


### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
from operator import itemgetter
 
N,M = map(int,readline().split())
A = list(map(int,readline().split()))
m = map(int,read().split())
BC = list(zip(m,m))
 
BC.sort(key = itemgetter(1),reverse=True)
 
BC.append((N,-1))
 
change = []
for b,c in BC:
    change += [c] * b
    if len(change) > N:
        break
 
A += change
A.sort()
answer = sum(A[-N:])
print(answer)
### BUGGY CODE ###

from collections import Counter as counter

N = int(input())
char_counts = [counter(input()) for i in range(N)]
match_count = 0
for i, c in enumerate(char_counts):
  for j in range(i, N, 1):
    if i == j:
      continue
    if char_counts[j] == c:
      match_count += 1
print(match_count)

### FIXED CODE ###

N = int(input())
dic = {}
count = 0
for _ in range(N):
  s = ''.join(sorted(input()))
  if s in dic.keys():
    count += dic[s]
    dic[s] += 1
  else:
    dic[s] = 1
print(count)