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

N = int(input())
A = list(map(int,list(input().split())))
Q = int(input())
s = []
for i in range(Q):
    B,C = map(int,(input().split()))
    r = 0
    for j in range(N):
        if A[j] == B:
            A[j] = C
        r += A[j]
    s.append(r)
for i in range(Q):
    print(s[i])


### FIXED CODE ###

import sys,collections
input = sys.stdin.readline

N=input().rstrip()
A=list(map(int,input().split()))
Ac = collections.Counter(A)
Q = int(input())
for i in range(Q):
    B,C = list(map(int,input().split()))
    nb = Ac[B]
    Ac[C] += Ac[B]
    Ac[B] = 0

    if i==0:
        ans = 0
        for key,val in Ac.items():
            ans += key*val
    else:
        ans +=nb*C - nb*B
    
    print(ans)
### BUGGY CODE ###

def main():
    import sys,heapq
    from collections import defaultdict
    input = sys.stdin.readline

    n,q = map(int,input().split())
    #used[i]:0より大きいならi
    used = defaultdict(int)
    tank = []

    p = []
    for i in range(n):
        s,t,x = map(int,input().split())
        p.append((s-x,x))
        p.append((t-x-0.5,x))
    p.sort()

    cnt = 0
    for i in range(q):
        d = int(input())
        while cnt<=len(p)-1 and p[cnt][0] <= d:
            w = p[cnt][1]
            if int(p[cnt][0]) == p[cnt][0]:
                used[w] += 1
                heapq.heappush(tank,w)
            else:
                used[w] -= 1
            cnt += 1
        while True:
            if len(tank) == 0:
                print(-1)
                break
            kouho = heapq.heappop(tank)
            if used[kouho] > 0:
                print(kouho)
                heapq.heappush(tank,kouho)
                break
if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    import sys,heapq
    from collections import defaultdict
    input = sys.stdin.readline

    n,q = map(int,input().split())
    #used[i]:0より大きいならi
    used = defaultdict(int)
    tank = []

    p = []
    for i in range(n):
        s,t,x = map(int,input().split())
        p.append((s-x,x))
        p.append((t-x,-x))
    p.sort()

    cnt = 0
    for i in range(q):
        d = int(input())
        while cnt<=len(p)-1 and p[cnt][0] <= d:
            w = p[cnt][1]
            if w>=0:
                used[w] += 1
                heapq.heappush(tank,w)
            else:
                used[-w] -= 1
            cnt += 1
        while True:
            if len(tank) == 0:
                print(-1)
                break
            kouho = tank[0]
            if used[kouho] > 0:
                print(kouho)
                break
            else:
                heapq.heappop(tank)
if __name__ == '__main__':
    main()
### BUGGY CODE ###

n=int(input())
S=input()
anslist=[]
c=0
#3けたの暗証番号なので000~999までの最大1000通り
for i in range(1000):
    c=0
    if i<10:
        i="00"+str(i)
    elif i<100:
        i="0"+str(i)
    else:
        i=str(i)
    tmp=""
    j=0
    while j<n:
        if S[j]==i[0]:
            tmp+=S[j]
            j+=1
            break
        j+=1
    while j<n:
        if S[j]==i[1]:
            tmp+=S[j]
            j+=1
            break
        j+=1
    while j<n:
        if S[j]==i[2]:
            tmp+=S[j]
            j+=1
            break
        j+=1
    if tmp==i:
        anslist.append(tmp)
                        
#print(anslist)
print(len(anslist))

### FIXED CODE ###

n=int(input())
S=input()
anslist=[]
c=0
#3けたの暗証番号なので000~999までの最大1000通り
for i in range(1000):
    c=0
    if i<10:
        i="00"+str(i)
    elif i<100:
        i="0"+str(i)
    else:
        i=str(i)
    tmp=""
    j=0
    while j<n:
        if S[j]==i[0]:
            tmp+=S[j]
            j+=1
            break
        j+=1
    while j<n:
        if S[j]==i[1]:
            tmp+=S[j]
            j+=1
            break
        j+=1
    while j<n:
        if S[j]==i[2]:
            tmp+=S[j]
            j+=1
            break
        j+=1
    if tmp==i:
        anslist.append(tmp)
                        
#print(anslist)
print(len(anslist))
### BUGGY CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N, Q = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)

val = [0] * (N)
for _ in range(Q):
    p, x = map(int, input().split())
    p -= 1
    val[p] += x


def dfs(n, pre):
    for nxt in G[n]:
        if nxt == pre:
            continue
        val[nxt] += val[n]
        dfs(nxt, n)


dfs(0, 0)

answer = ' '.join(map(str, val[:]))
print(answer)


### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N, Q = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)

val = [0] * (N)
for _ in range(Q):
    p, x = map(int, input().split())
    p -= 1
    val[p] += x


def dfs(n, pre):
    for nxt in G[n]:
        if nxt == pre:
            continue
        val[nxt] += val[n]
        dfs(nxt, n)


dfs(0, 0)

answer = ' '.join(map(str, val[:]))
print(answer)
### BUGGY CODE ###

from collections import deque
N,M = map(int,input().split())
a = [int(input()) for m in range(M)]
ans = []
P = 10**9+7
for n in range(N):
    if n+1 in a:
        ans.append(0)
    else:
        if n == 0:
            ans.append(1)
        elif n == 1:
            ans.append(ans[0]+1)
        else:
            ans.append((ans[n-1]+ans[n-2])%P)
print(ans[N-1])


### FIXED CODE ###

from collections import deque
N,M = map(int,input().split())
a = deque([int(input()) for m in range(M)]+[-1])
ans = []
P = 10**9+7
for n in range(N):
    if n+1 == a[0]:
        ans.append(0)
        a.popleft()
    else:
        if n == 0:
            ans.append(1)
        elif n == 1:
            ans.append(ans[0]+1)
        else:
            ans.append((ans[n-1]+ans[n-2])%P)
print(ans[N-1])
### BUGGY CODE ###

N=int(input())

for h in range(1,3500):
  for n in range(1,3500):
    if (4*h*n)-(N*n)-(N*h)!=0:
      w=N*h*n/((4*h*n)-(N*n)-(N*h))
      if w>0 and w.is_integer():
        print(h,n,int(w))
        exit()

### FIXED CODE ###

N=int(input())
 
for h in range(1,3501):
  for n in range(1,3501):
    #divが負数ならwは負数になる
    if (4*h*n)-(N*n)-(N*h)>0:
      w=N*h*n/((4*h*n)-(N*n)-(N*h))
      if w.is_integer():
        print(h,n,int(w))
        exit()
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10 ** 6)


def dfs(x, w):
    w += leaves[x]
    for nx in edge[x]:
        if V[nx] == 0:
            V[nx] = 1
            dfs(nx, w)
    leaves[x] = w


N, Q = map(int, input().split())
edge = [[] for _ in range(N)]

for i in range(N - 1):
    a, b = map(lambda x: int(x) - 1, input().split())
    edge[a].append(b)
    edge[b].append(a)

leaves = [0] * N
V = [0] * N
V[0] = 1

for q in range(Q):
    p, x = map(int, input().split())
    p -= 1
    leaves[p] += x

dfs(0, 0)
for i in range(N - 1):
    print(leaves[i], end=' ')
print(leaves[N - 1])


### FIXED CODE ###

from collections import deque


def bfs(x, w):
    q = deque()
    q.append((x, w))

    while len(q):
        x, w = q.popleft()
        leaves[x] += w
        w = leaves[x]
        for nx in edge[x]:
            if V[nx] == 0:
                V[nx] = 1
                q.append((nx, w))


N, Q = map(int, input().split())
edge = [[] for _ in range(N)]
leaves = [0] * N
V = [0] * N

for i in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)

for q in range(Q):
    p, x = map(int, input().split())
    p -= 1
    leaves[p] += x

V[0] = 1
bfs(0, 0)
for i in range(N - 1):
    print(leaves[i], end=' ')
print(leaves[N - 1])
### BUGGY CODE ###

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

def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

if len(A)==len(get_unique_list(A)):
    print("YES")
else:
    print("NO")

### FIXED CODE ###

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

A = list(set(A))

if len(A) == n:
    print('YES')
else :
    print('NO')
### BUGGY CODE ###

N,Q = map(int, input().split())
S = input()
for i in range(Q):
  l_i, r_i = map(int, input().split())
  A_i = S[l_i - 1 : r_i]
  count_i = 0
  for j in range(len(A_i) - 1):
    if A_i[j] == "A" and A_i[j+1] == "C":
      count_i = count_i + 1
  print(count_i)

### FIXED CODE ###

N,Q = map(int, input().split())
S = input()
List = [0]
p = 0
for i in range(N-1):
  if S[i] == "A":
    if S[i+1] == "C":
      p = p + 1
      List.append(p)
    else:
      List.append(p)
  else:
    List.append(p)

List.append(0)   
for i in range(Q):
  l, r = map(int, input().split())
  if List[l-2] == List[l-1]:
    print(List[r-1] - List[l-2])
  else:
    print(List[r-1] - List[l-1])
### BUGGY CODE ###

N,Q=map(int,input().split())
S=input()
answers=[]
for q in range(Q):
    l,r=map(int,input().split())
    y=S[l-1:r]
    ans=0
    if 'AC' in y:
        for i in range(len(y)-1):
            if y[i:i+2]=='AC':
                ans+=1
    answers.append(ans)
    
for j in range(len(answers)):
    print(answers[j])

### FIXED CODE ###

import numpy as np

N,Q=map(int,input().split())
y=input()
arr=np.zeros(len(y))
for i in range(len(y)-1):
    if y[i:i+2]=='AC':
        arr[i+1]=arr[i]+1
    else:
        arr[i+1]=arr[i]
              
for q in range(Q):
    l,r=map(int,input().split())
    print(int(arr[r-1]-arr[l-1]))
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
check=[]
for i in range(1,N+1):
  check.append(str(A.index(i)+1))
print(" ".join(check))


### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
check=[0]*N
for i in range(N):
  check[A[i]-1]=i+1
[print(x,end=" ") for x in check]
### BUGGY CODE ###

import sys
I = lambda:map(int,sys.stdin.readline().split())
pr = lambda x:sys.stdout.write(f'{x}\n')
sys.setrecursionlimit(2000000001)

n = k = ar = dp = 0

def solve(x):
	global n,k,ar,dp
	if x>=n-2: return dp[x]
	if dp[x] != -1: return dp[x]
	dp[x] = min([(abs(ar[x]-ar[i])+solve(i)) for i in range(x+1,min(n,x+k+1))])
	# pr(f'{x} => {dp[x]}')
	return dp[x]

def main():
	global n,ar,k,dp
	n,k, ar = *I(), [*I()]
	dp = [-1]*(n-2) + [abs(ar[-2]-ar[-1]),0]
	# pr((n,k,ar,dp))
	pr(solve(0))

main()

### FIXED CODE ###

import sys
from functools import reduce
sys.setrecursionlimit(2000000001)

def solve(n,k,ar,dp,x):
	ab = abs; mn = min
	if x>=n-2: return dp[x]
	if not dp[x] is -1: return dp[x]
	# t = [ for i in range(x+1,mn(n,x+k+1))]
	t = map(lambda i:ab(ar[x]-ar[i])+solve(n,k,ar,dp,i), range(x+1,mn(n,x+k+1)))
	dp[x] = reduce(lambda a,b : a if a < b else b,t)
	return dp[x]

def main():
	I = lambda:map(int,sys.stdin.readline().split())
	pr = lambda x:sys.stdout.write(f'{x}\n')
	n,k, ar = *I(), [*I()]
	dp = [-1]*(n-2) + [abs(ar[-2]-ar[-1]),0]
	pr(solve(n,k,ar,dp,0))

main()
### BUGGY CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

MOD = 10 ** 9 + 7
n,m = map(int,input().split())
A = [int(input()) for _ in range(m)] #壊れた階段

dp = [0] * (n+1)
dp[0] = 1

for i in range(1,n+1):
    if i in A:
        continue
    x = dp[i-1]
    if i > 1:
        x += dp[i-2]
    dp[i] = x%MOD

print(dp[n])

### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

MOD = 10 ** 9 + 7
n,m = map(int,input().split())
A = set(int(input()) for _ in range(m)) #壊れた階段

dp = [0] * (n+1)
dp[0] = 1

for i in range(1,n+1):
    if i in A:
        continue
    x = dp[i-1]
    if i > 1:
        x += dp[i-2]
    dp[i] = x%MOD

print(dp[n])
### BUGGY CODE ###

N,M = [int(i) for i in input().split(' ')]
itemList = [int(i) for i in input().split(' ')]

for _ in range(M):
    itemList.sort()
    itemList[-1] //= 2
    
print(sum(itemList))

### FIXED CODE ###

from heapq import heappush, heappop
import math

N,M = [int(i) for i in input().split(' ')]
itemList = [int(i) for i in input().split(' ')]
heap = []

for i in itemList:
    heappush(heap, -i)

for _ in range(M):
    heappush(heap, math.ceil(heappop(heap)/2))
print(-sum(heap))
### BUGGY CODE ###

import bisect,sys
from itertools import *
n=range(50001);a=list(n);a[1]=0
for i in range(2,224):a[i*2::i]=[0]*len(a[i*2::i])
for x in map(int,sys.stdin):
 if x:y=x//2+1;print(sum(1 for d in compress(n[:y],a[:y])if a[x-d]))


### FIXED CODE ###

import bisect,sys
from itertools import *
n=range(50001);a=list(n);a[1]=0
for i in range(2,224):a[i*2::i]=[0]*len(a[i*2::i])
p=list(compress(n,a))
for x in map(int,sys.stdin):
 if x:print(len([1 for d in p[:bisect.bisect(p,x//2)]if a[x-d]]))
### BUGGY CODE ###

import numpy as np

s = [ord(a)-ord('a') for a in input()]
n = len(s)

if n == 2:
    if s[0] == s[1]:
        print('1 2')
    else:
        print('-1 -1')
    exit()

cnt = np.array([0] * 26)
cum = [cnt.copy()]

for i, a in enumerate(s):
    cnt[a] += 1
    cum.append(cnt.copy())

def is_check(cum, n):
    for i in range(3, n+1, 2):
        d = i // 2
        for j in range(n-i+1):
            for k in cum[j+i] - cum[j]:
                if k > d:
                    return j+1, j+i
    return -1, -1

print(' '.join(map(str, is_check(cum, len(s)))))

### FIXED CODE ###

import numpy as np

s = [ord(a)-ord('a') for a in input()]
n = len(s)

if n == 2:
    if s[0] == s[1]:
        print('1 2')
    else:
        print('-1 -1')
    exit()

cnt = np.array([0] * 26)
cum = [cnt.copy()]

for i, a in enumerate(s):
    cnt[a] += 1
    cum.append(cnt.copy())

def is_check(cum, n):
    i = 3
    d = 1
    for j in range(n-i+1):
        cum_ = cum[j+i] - cum[j]
        if cum_[cum_>1]:
            return j+1, j+i
    return -1, -1

print(' '.join(map(str, is_check(cum, len(s)))))
### BUGGY CODE ###

#!/usr/bin/env python3

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

n = int(input())
a = [int(input()) for _ in range(n)]
dp = [0]*n
ans = 0
for i in range(n):
    dp[i] = 1
    for j in range(i):
        if -a[j] <= -a[i]:
            dp[i] = max(dp[i],dp[j]+1)
    ans = max(ans,dp[i])
print(ans)


### FIXED CODE ###

#!/usr/bin/env python3
#ABC134 E

import sys
import math
import bisect
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
mod = 10**9 + 7

n = int(input())
a = [int(input()) for _ in range(n)]
m = []
for i in range(n):
    r = bisect.bisect_right(m,-a[i])
    if r == len(m):
        m.append(-a[i])
    else:
        m[r] = -a[i]
print(len(m))
### BUGGY CODE ###

import sys, re

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7


R, G, B, N = MAP()
count = 0
for i in range(N+1):
	for j in range(int((N-i*R)//G)+1):
		# print(r, g, b)
		if R*i + G*j + B*int(max(0, (N - i*R - j*G))/B) == N:
			count += 1
print(count)


### FIXED CODE ###

import sys, re

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7


R, G, B, N = MAP()
count = 0
for i in range(N+1):
	for j in range(int((N-i*R)//G)+1):
		# print(r, g, b)
		# if R*i + G*j + B*int(max(0, (N - i*R - j*G))/B) == N:
		# 	count += 1
		if (N - i*R - j*G) % B == 0:
			count += 1
print(count)
### BUGGY CODE ###

S = input()[::-1]
P = [0]*(len(S)+1)
for i,j in enumerate((S)):
    P[i+1] = (P[i] + int(j)*pow(10,i))

dp = [0]*2019
for i in P:
    dp[i%2019] += 1
print(sum([i*(i-1)//2 for i in dp]))


### FIXED CODE ###

P = 2019
S = input()
N = len(S)
res = 0
 
if P in [2,5]:
    for i in range(N):
        if int(S[i])% P == 0:
            res += i+1
else:
    dic = {0:1}
    t1 = 0
    t2 = 1
    for i in range(N):
        t2 = (10*t2) % P
        t1 = (int(S[N-1-i])*t2 + t1) % P
        if t1 in dic:
            res += dic[t1]
            dic[t1] += 1
        else:
            dic[t1] = 1
 
print(res)
### BUGGY CODE ###

N, M = map(int, input().split())
A = list(input().split())
A = [int(i) for i in A]
A.sort(reverse=True)

for _ in range(M):
    A[0] = A[0]//2
    if len(A) > 1 and A[0] < A[1]:
        A.sort(reverse=True)

print(sum(A))

### FIXED CODE ###

import heapq

N, M = map(int, input().split())
A = list(input().split())
A = [int(i) * (-1) for i in A]

heapq.heapify(A)

for _ in range(M):
    val = heapq.heappop(A)
    heapq.heappush(A, val*(-1)//2*(-1))

print(sum(A) * (-1))
### BUGGY CODE ###

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

#部分列の和を考えるなら累積和を
ruiseki_A_list = [0 for _ in range(N)]

for i in range(N):
    if i == 0:
        ruiseki_A_list[i] = A_list[i]
    else:
        ruiseki_A_list[i] = A_list[i] + ruiseki_A_list[i-1]

#元のある区間の総和が知りたい
ruiseki_A_list.insert(0,0)
ans = 0
for left_num in range(N+1):
    for right_num in range(N+1):
        if left_num < right_num:
            if ruiseki_A_list[right_num] - ruiseki_A_list[left_num]==0:
                ans += 1
print(ans)

### FIXED CODE ###

N = int(input())
A_list = list(map(int, input().split()))
import math
#部分列の和を考えるなら累積和を
ruiseki_A_list = [0 for _ in range(N)]

for i in range(N):
    if i == 0:
        ruiseki_A_list[i] = A_list[i]
    else:
        ruiseki_A_list[i] = A_list[i] + ruiseki_A_list[i-1]

#元のある区間の総和が知りたい

ruiseki_A_list.insert(0,0)
ans = 0
'''
for left_num in range(N+1):
    for right_num in range(N+1):
        if left_num < right_num:
            if ruiseki_A_list[right_num] - ruiseki_A_list[left_num]==0: #要素が等しい物の数数えたらええんか...
                ans += 1
'''
#やってることの中身というか本質を見逃してた
ruiseki_A_list.sort()
kosuu = [1]
k = 0
for i in range(N):
    if ruiseki_A_list[i+1] - ruiseki_A_list[i] == 0:
        kosuu[k] += 1
    else:
        k += 1
        kosuu.append(1)
        
for num in kosuu:
    if num <= 1:
        ans += 0
    else:
        ans += math.factorial(num)/(math.factorial(2) * math.factorial(num-2))
print(int(ans))
### BUGGY CODE ###

### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def resolve():
    readline=sys.stdin.readline
    mod=10**9+7
    n=int(readline())
    arr=list(map(int, readline().rstrip().split()))
    ans = 0
    x = 1
    for i in range(60):
        c = 0
        for j in range(n):
            c += (arr[j]>>i)&1
        ans += (c * (n-c)) * x
        ans %= mod
        x = (x*2)%mod
    print(ans)
    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

### FIXED CODE ###

### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def resolve():
    readline=sys.stdin.readline
    mod=10**9+7
    n=int(readline())
    arr=list(map(int, readline().rstrip().split()))
    binArr = [[0 for i in range(60)] for j in range(n)]
    cnt=[0]*60
    for i in range(n):
        b = bin(arr[i])[2:]
        lenb = len(b)
        for j in range(lenb):
            binArr[i][j] = int(b[lenb-1-j])
            cnt[j]+=binArr[i][j]
    ans=[0]*60
    answer = 0
    for i in range(n):
        for j in range(60):
            # 1: cnt[j]
            # 0: n-cnt[j]
            cnt[j]-=binArr[i][j]
            if binArr[i][j] == 0:
                ans[j] += cnt[j]
            else:
                ans[j] += (n-cnt[j]-i-1)
    x=1
    for i in range(60):
        answer += ans[i]*x
        answer %= mod
        x*=2
        x%=mod
    print(answer)
    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------
### BUGGY CODE ###

def int2str(i):
  if i <10:
    a="0"
    b="0"
    c=str(i)[-1]
  elif i <100:
    a="0"
    b=str(i)[-2]
    c=str(i)[-1]
  else:
    a=str(i)[-3]
    b=str(i)[-2]
    c=str(i)[-1]
  return a,b,c

N=int(input())
S=input()
ans=0
for i in range(1000):
  a,b,c=int2str(i)
  flag=0
  for j in S:
    if flag==0 and j==a:
      flag=1
      continue
    elif flag==1 and j==b:
      flag=2
      continue
    elif flag==2 and j==c: 
      ans+=1
      break
print(ans)
  
  

### FIXED CODE ###

def int2str(i):
  t=str(i)
  if i <10:
    a="0"
    b="0"
    c=t[-1]
  elif i <100:
    a="0"
    b=t[-2]
    c=t[-1]
  else:
    a=t[-3]
    b=t[-2]
    c=t[-1]
  return a,b,c

N=int(input())
S=input()
ans=0
for i in range(1000):
  S1=[]
  S2=[]
  a,b,c=int2str(i)
  flag=0
  i1 = S.find(a)
  if i1 !=-1:
    S1=S[i1+1:]
    i2=S1.find(b)
    if i2 !=-1:
      S2=S1[i2+1:]
      i3=S2.find(c)
      if i3 !=-1:
        ans+=1
print(ans)
### BUGGY CODE ###

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

### FIXED CODE ###

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

#!/usr/bin/env python3
import sys


def solve(N: int, K: int, x: "List[int]"):
    def search_naive(cur, k, x):
        if k == K:
            return 0
        costs = []
        for i in range(len(x)):
            xi = x[i]
            dist = abs(xi-cur)
            costs.append(dist + search_naive(xi, k+1, x[:i]+x[i+1:]))
        return min(costs)
    def search(N, window_size, x):
        costs = []
        for i in range(N-window_size+1):
            conds = x[i:i+window_size]
            right_end = max(filter(lambda x: x>=0, conds), default=0)
            left_end = abs(min(filter(lambda x: x<0, conds), default=0))
            if right_end > left_end:
                costs.append(right_end + 2*left_end)
            else:
                costs.append(2*right_end + left_end)
        return min(costs)
    #print(search_naive(0, 0, x)) 
    print(search(N, K, x))
    return


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
    K = int(next(tokens))  # type: int
    x = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, K, x)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys


def solve(N: int, K: int, x: "List[int]"):
    def search(N, window_size, x):
        costs = []
        for i in range(N-window_size+1):
            right_end = x[i+window_size-1]
            left_end = x[i]
            dist = abs(right_end-left_end)
            costs.append(min(abs(right_end)+dist, abs(left_end)+dist))
        return min(costs)
    print(search(N, K, x))
    return


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
    K = int(next(tokens))  # type: int
    x = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, K, x)

if __name__ == '__main__':
    main()