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

K, S = map(int, input().split())
cnt = 0
for x in range(K+1):
    for y in range(K+1):
        for z in range(K+1):
            if S == x + y + z:
                cnt += 1
print(cnt)

### FIXED CODE ###

K, S = map(int, input().split())
cnt = 0
for x in range(K+1):
    for y in range(K+1):
        if 0 <= S-x-y <= K:
            cnt += 1
print(cnt)
### BUGGY CODE ###

n = int(input())
s = input()
dp = [[0 for i in range(5001)] for j in range(5001)]

for i in range(n-1,-1,-1):
	for j in range(n-1,-1,-1):
		if s[i] != s[j]:
			dp[i][j] = 0
		else:
			dp[i][j] = dp[i+1][j+1] + 1

res = 0
for i in range(n):
	for j in range(n):
		if i >= j:
			continue
		x = min(dp[i][j], j-i)
		res = max(x,res)
print (res)

### FIXED CODE ###

n = int(input())
s = input()
dp = [[0 for i in range(5001)] for j in range(5001)]

for i in range(n-1,-1,-1):
	for j in range(n-1,-1,-1):
		if s[i] != s[j]:
			dp[i][j] = 0
		else:
			dp[i][j] = dp[i+1][j+1] + 1

res = 0
for i in range(n):
	for j in range(n):
		if i >= j:
			continue
		x = min(dp[i][j], j-i)
		res = max(x,res)
print (res)
### BUGGY CODE ###

N = int(input())
X = int(input(), 2)

def f(n):
    cnt = 0
    while n!=0:
        popcount = sum(map(int, bin(n)[2:]))
        n = n % popcount
        cnt += 1
    return cnt

for i in range(1, N+1):
    print(f(X ^ (1 << (N-i))))





### FIXED CODE ###

import sys
N = int(input())
X = int(input(), 2)
x_popcount = sum(map(int, bin(X)[2:]))
is_zeroflg = [x_popcount-1 <= 0, False]
x_popcounts = [max(1, x_popcount - 1), x_popcount + 1]
X_per_popcounts = [X % x_popcounts[0], X % x_popcounts[1]]
mods = [0, 0]
ans = [0]*N


def f(n):
    cnt = 0
    while n != 0:
        popcount = sum(map(int, bin(n)[2:]))
        n = n % popcount
        cnt += 1
    return cnt


flg = X & 1 ^ 1
mods[0] = (-1) % x_popcounts[0]
mods[1] = 1 % x_popcounts[1]
tmp = (X_per_popcounts[flg] + mods[flg]) % x_popcounts[flg]
ans[0] = f(tmp) + 1
if is_zeroflg[flg]:
    ans[0] = 0

for i in range(1, N):
    flg = (X >> i) & 1 ^ 1
    mods[0] = (mods[0] * 2) % (x_popcounts[0])
    mods[1] = (mods[1] * 2) % (x_popcounts[1])
    tmp = (X_per_popcounts[flg] + mods[flg]) % x_popcounts[flg]
    ans[i] = f(tmp) + 1
    if is_zeroflg[flg]:
        ans[i] = 0

print('\n'.join(map(str, ans[::-1])))
### BUGGY CODE ###

def get_answer(a, start, end):
    if start == end:
        return 0
    return sum(a[start: end])

def create_answer_array(s):
    result = []
    for i, c in enumerate(s):
        if i == len(s) - 1:
            result.append(int(0))
        elif c == "A" and s[i + 1] == "C":
            result.append(int(1))
        else:
            result.append(int(0))

    return result

n, q = map(int, input().split())
s = str(input())
questions = []
for _ in range(q):
    a, b = map(int, input().split())
    questions.append((a - 1, b - 1))

a = create_answer_array(s)

for question in questions:
    print(get_answer(a, question[0], question[1]))


### FIXED CODE ###

def get_answer(a, start, end):
    return a[end] - a[start]

def create_answer_array(s):
    result = []
    result.append(0)

    for i in range(1, len(s)):
        if s[i - 1] == "A" and s[i] == "C":
            result.append(result[i - 1] + 1)
        else:
            result.append(result[i - 1])

    return result

n, q = map(int, input().split())
s = str(input())
questions = []
for _ in range(q):
    a, b = map(int, input().split())
    questions.append((a - 1, b - 1))

a = create_answer_array(s)

for question in questions:
    print(get_answer(a, question[0], question[1]))
### BUGGY CODE ###

n = int(input())
A = list(map(int, input().split()))
A.sort()
dp = [True] * (10 ** 6 + 1)  # 自分以外約数ないならTrue
visited = [False] * (10 ** 6 + 1)
for a in A:
    if visited[a]:
        dp[a] = False
        continue
    visited[a] = True
    i = 2
    while a * i <= 10 ** 6:
        dp[a * i] = False
        i += 1
ans = 0
for a in A:
    ans += dp[a]
print(ans)

### FIXED CODE ###

n = input()
*A, = map(int, input().split())
max_A = max(A)
count = {a:0 for a in A}
for a in A:
    count[a] += 1
is_OK = {a:True for a in A}
for a in A:
    i = 2
    if not is_OK[a]:
        continue
    while a * i < max_A + 1:
        is_OK[a * i] = False
        i += 1
ans = 0
for a in A:
    if count[a] == 1 and is_OK[a]:
        ans += 1
print(ans)
### BUGGY CODE ###

N,K = map(int, input().split())
a_arr = list(map(int, input().split()))

k_idx = K - 1
term_val_arr = []
ans_arr = []
for i in range(N - K + 1):
    val = 1
    if len(term_val_arr) == 0:
        for j in range(K):
            val *= a_arr[k_idx - j]
        term_val_arr.append(val)
    else:
        term_val_arr.append(a_arr[k_idx] * term_val_arr[i - 1] / a_arr[i-1])

    if i != 0:
        if term_val_arr[i - 1] < term_val_arr[i]:
            ans_arr.append('Yes')
        else:
            ans_arr.append('No')
    k_idx += 1
for i in ans_arr:
    print(i)

### FIXED CODE ###

N,K = map(int, input().split())
a_arr = list(map(int, input().split()))

k_idx = K - 1
ans_arr = []
for i in range(N - K):
    if a_arr[i] < a_arr[k_idx + 1]:
        ans_arr.append('Yes')
    else:
        ans_arr.append('No')
    k_idx += 1
for i in ans_arr:
    print(i)
### BUGGY CODE ###

from sys import stdin
input = stdin.readline


def main():
  N, K = list(map(int, input().split()))
  A = list(map(int, input().split()))

  S = [1]*(N+1)
  for i in range(1, N+1):
    S[i] = S[i-1] * A[i-1]

  pre = S[K]/S[0]
  for i in range(K+1, N+1):
    temp = S[i]/S[i-K]
    if pre < S[i]/S[i-K]:
      print('Yes')
    else:
      print('No')
    pre = temp


if(__name__ == '__main__'):
  main()


### FIXED CODE ###

from sys import stdin
input = stdin.readline


def main():
  N, K = list(map(int, input().split()))
  A = list(map(int, input().split()))

  # S = [1]*(N+1)
  # for i in range(1, N+1):
  #   S[i] = S[i-1] * A[i-1]

  # pre = S[K]/S[0]
  # out = []
  for i in range(K+1, N+1):
    if A[i-K-1] < A[i-1]:
      print('Yes')
    else:
      print('No')
    # temp = S[i]/S[i-K]
    # if pre < temp:
    #   # print('Yes')
    #   out.append('Yes')
    # else:
    #   # print('No')
    #   out.append('No')
    # pre = temp

  # print(*out, sep='\n')


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

N,M=map(int,input().split())
set1=set()
set2=set()
L,R=map(int,input().split())
for i in range(L,R+1):
    set1.add(i)
min=min(set1)
max=max(set1)+1
for i in range(M-1):
    L,R=map(int,input().split())
    if min <= L:
        min=L
    if max >= R+1:
        max=R+1
    for j in range(min,max):
        set2.add(j)
    set1=set1&set2
    set2.clear()
print(len(set1))


### FIXED CODE ###

N,M=map(int,input().split())
set1=set()
L,R=map(int,input().split())
for i in range(L,R+1):
    set1.add(i)
min=min(set1)
max=max(set1)
Flag=True
for i in range(M-1):
    L,R=map(int,input().split())
    if R < min:
        Flag=False
        break
    elif L > max:
        Flag=False
        break
    if L >= min and max >= L:
        min = L
    if R >= min and max >= R:
        max = R
if Flag:
    print(max-min+1)
else:
    print(0)
### BUGGY CODE ###

from collections import deque


line = input().split(" ")
N, K = int(line[0]), int(line[1])
line = input().split(" ")
dices = [int(c) for c in line]

max_E = 0
expectations = deque([0] * K, maxlen=K)

for dice in dices:
    expectations.popleft()
    e = sum(range(1, dice + 1)) / dice
    expectations.append(e)
    E = sum(expectations)
    if E < max_E:
        continue
    else:
        max_E = E

print(max_E)


### FIXED CODE ###

from collections import deque


line = input().split(" ")
N, K = int(line[0]), int(line[1])
line = input().split(" ")
dices = [int(c) for c in line]

max_E = 0
expectations = deque([0] * K, maxlen=K)
e_memo = {}
E = 0
for dice in dices:
    E -= expectations.popleft()
    if e_memo.get(dice) is None:
        e_memo[dice] = sum(range(1, dice + 1)) / dice
    e = e_memo[dice]
    expectations.append(e)
    E += e
    if E < max_E:
        continue
    else:
        max_E = E

print(max_E)
### BUGGY CODE ###

import sys
import heapq
import copy
input = sys.stdin.buffer.readline

N = int(input())
pq_L = []
pq_R = []
for i in range(N):
    L, R = map(int, input().split())
    heapq.heappush(pq_L, (-L, i))
    heapq.heappush(pq_R, (R, i))
pq_L2 = copy.deepcopy(pq_L)
pq_R2 = copy.deepcopy(pq_R)

ans1 = 0
prev = 0
used = [0] * N
for i in range(N):
    if i % 2 == 0:
        while True:
            _x, j = heapq.heappop(pq_L)
            x = -_x
            if not used[j]:
                used[j] = 1
                break
        if prev < x:
            ans1 += x - prev
            prev = x
    else:
        while True:
            x, j = heapq.heappop(pq_R)
            if not used[j]:
                used[j] = 1
                break
        if prev > x:
            ans1 += prev - x
            prev = x

ans1 += abs(prev)

ans2 = 0
prev = 0
used = [0] * N
for i in range(N):
    if i % 2 == 1:
        while True:
            _x, j = heapq.heappop(pq_L2)
            x = -_x
            if not used[j]:
                used[j] = 1
                break
        if prev < x:
            ans2 += x - prev
            prev = x
    else:
        while True:
            x, j = heapq.heappop(pq_R2)
            if not used[j]:
                used[j] = 1
                break
        if prev > x:
            ans2 += prev - x
            prev = x

ans2 += abs(prev)

print(max(ans1, ans2))


### FIXED CODE ###

import sys
import heapq
import copy
input = sys.stdin.buffer.readline

def main():
    N = int(input())
    pq_L = []
    pq_R = []
    for i in range(N):
        L, R = map(int, input().split())
        heapq.heappush(pq_L, (-L, i))
        heapq.heappush(pq_R, (R, i))
    pq_L2 = copy.deepcopy(pq_L)
    pq_R2 = copy.deepcopy(pq_R)

    ans1 = 0
    prev = 0
    used = [0] * N
    for i in range(N):
        if i % 2 == 0:
            while True:
                _x, j = heapq.heappop(pq_L)
                x = -_x
                if not used[j]:
                    used[j] = 1
                    break
            if prev < x:
                ans1 += x - prev
                prev = x
        else:
            while True:
                x, j = heapq.heappop(pq_R)
                if not used[j]:
                    used[j] = 1
                    break
            if prev > x:
                ans1 += prev - x
                prev = x

    ans1 += abs(prev)

    ans2 = 0
    prev = 0
    used = [0] * N
    for i in range(N):
        if i % 2 == 1:
            while True:
                _x, j = heapq.heappop(pq_L2)
                x = -_x
                if not used[j]:
                    used[j] = 1
                    break
            if prev < x:
                ans2 += x - prev
                prev = x
        else:
            while True:
                x, j = heapq.heappop(pq_R2)
                if not used[j]:
                    used[j] = 1
                    break
            if prev > x:
                ans2 += prev - x
                prev = x

    ans2 += abs(prev)

    print(max(ans1, ans2))


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

# coding: utf-8
import itertools

k, n = map(int, input().split())
a = list(map(int, input().split()))
ans = []

for list in itertools.permutations(range(n)):
    count = 0
    for i in range(n-1):
        t1 = a[list[i+1]] - a[list[i]]
        t2 = a[list[i+1]] + 20 - a[list[i]]
        if t1 > k/2:
            count += k - t1
        elif t1 > 0:
            count += t1
        elif t2 > k/2:
            count += k - t2
        else:
            count += t2
    ans.append(count)
print(min(ans))

### FIXED CODE ###

# coding: utf-8
k, n = map(int, input().split())
a = list(map(int, input().split()))
max = 0

for i in range(n-1):
    l = a[i+1] - a[i]
    if l > max:
        max = l
l = a[0] - a[n-1] + k
if l > max:
    max = l
print(k - max)
### BUGGY CODE ###

import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())[:-1]
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [list(input())[:-1] for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
N = int(input())
A = list(map(int,input().split()))
MAX = 10**18
cur = 1
flag = 0
for i in range(N):
    a = A[i]
    cur *= a
if cur > MAX:
    flag = 1
if flag == 1:
    print(-1)
else:
    print(cur)

### FIXED CODE ###

import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())[:-1]
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [list(input())[:-1] for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
N = int(input())
A = list(map(int,input().split()))
MAX = 10**18
zero = 0
for i in range(N):
    if A[i] == 0:
        zero = 1
        break
if zero == 1:
    print(0)
else:
    cur = 1
    flag = 0
    for i in range(N):
        a = A[i]
        cur *= a
        if cur > MAX:
            flag = 1
            break
    if flag == 1:
        print(-1)
    else:
        print(cur)
### BUGGY CODE ###

from collections import deque
#空のリスト 作った後は普通にappend使えばOK
n,m,k=map(int,input().split())
 
tomodati=[[] for i in range(n+1)]
 
group=[0]*(n+1)
 
block=[0]*(n+1)
 
tansaku=deque()
 
for i in range(m):
    a,b=map(int,input().split())
    tomodati[a].append(b)
    tomodati[b].append(a)
 
num=1
 
for i in range(1,n+1):
    if group[i]==0:
        tansaku.append(i)
        group[i]=num
    while len(tansaku)>0:
        for j in tomodati[tansaku[0]]:
            if group[j]==0:
                group[j]=num
                tansaku.append(j)
        tansaku.popleft()
    num+=1
 
for i in range(k):
    c,d=map(int,input().split())
    if group[c]==group[d]:
        block[c]+=1
        block[d]+=1
 
ans=""
 
for i in range(1,n+1):
    ans+=str(group.count(group[i])-len(tomodati[i])-block[i]-1)+" "
 
print(ans)


### FIXED CODE ###

from collections import deque
#空のリスト 作った後は普通にappend使えばOK
n,m,k=map(int,input().split())
 
tomodati=[[] for i in range(n+1)]
 
group=[0]*(n+1)

group_cnt=[0]*(n+1)
 
block=[0]*(n+1)
 
tansaku=deque()
 
for i in range(m):
    a,b=map(int,input().split())
    tomodati[a].append(b)
    tomodati[b].append(a)
 
num=1
 
for i in range(1,n+1):
    if group[i]==0:
        tansaku.append(i)
        group[i]=num
        group_cnt[num]+=1
    else:
        continue
    while len(tansaku)>0:
        for j in tomodati[tansaku[0]]:
            if group[j]==0:
                group[j]=num
                group_cnt[num]+=1
                tansaku.append(j)
        tansaku.popleft()
    num+=1
 
for i in range(k):
    c,d=map(int,input().split())
    if group[c]==group[d]:
        block[c]+=1
        block[d]+=1
 
ans=[]
 
for i in range(1,n+1):
    ans.append(group_cnt[group[i]]-len(tomodati[i])-block[i]-1)
 
print(*ans)
### BUGGY CODE ###

k, n = map(int, input().split())
a_list = list(map(int, input().split()))
ans = k
for i in a_list:
    seq_list = [0] * n
    if i == 0:
        for j in range(n):
            if a_list[j] > k / 2:
                seq_list[j] = a_list[j] - k
            else:
                seq_list[j] = a_list[j]

    else:
        for j in range(n):
            seq_list[j] = a_list[j] - i
    max_a = max(seq_list)
    min_a = min(seq_list)
    seq_dis = max_a - min_a
    ans = min(seq_dis, ans)
print(ans)

### FIXED CODE ###

k, n = map(int, input().split())
a = list(map(int, input().split()))
a.append(a[0] + k)
dis = [a1 - a0 for a0, a1 in zip(a, a[1:])]
print(k - max(dis))
### BUGGY CODE ###

from collections import deque

class RollingHash():
    def __init__(self, s, base1=1007, base2=2009, mod1=10**9+7, mod2=10**9+9):
        self.mod1 = mod1
        self.mod2 = mod2
        self.s = s
        n = len(s)
        self.hash1 = [0]*(n+1)
        self.pow1 = [1]*(n+1)
        self.hash2 = [0]*(n+1)
        self.pow2 = [1]*(n+1)
        for i in range(n):
            self.hash1[i+1] = (self.hash1[i]*base1 + ord(s[i])) % self.mod1
            self.pow1[i+1] = (self.pow1[i]*base1) % self.mod1
            self.hash2[i+1] = (self.hash2[i]*base2 + ord(s[i])) % self.mod2
            self.pow2[i+1] = (self.pow2[i]*base2) % self.mod2

    def get(self, l, r):
        h1 = (self.hash1[r] - self.hash1[l] * self.pow1[r-l]) % self.mod1
        h2 = (self.hash2[r] - self.hash2[l] * self.pow2[r-l]) % self.mod2
        return (h1,h2)


n = int(input())
s = input()
rh = RollingHash(s, base1=3**6, base2=3**7, mod1=2**61-1, mod2=2**61-1)

for len_ in range(n//2,0,-1):
    ql = [(-1,-1)]*(len_-1)
    wait_q = deque(ql)
    hset = set()
    # print(len_)
    for i in range(n-len_+1):
        # print(s[i:i+len_])
        hs = rh.get(i,i+len_)
        if hs in hset:
            print(len_)
            exit()
        else:
            wait_q.append(hs)
            hset.add(wait_q.popleft())
        # print(wait_q)
        # print(hset)

else:
    print(0)

### FIXED CODE ###

from collections import deque

class RollingHash():
    def __init__(self, s, base1=19683,base2=6561,mod1=2^61-1,mod2=2^61-1):
        self.mod1 = mod1
        self.mod2 = mod2
        self.s = s
        n = len(s)
        self.hash1 = [0]*(n+1)
        self.pow1 = [1]*(n+1)
        self.hash2 = [0]*(n+1)
        self.pow2 = [1]*(n+1)
        for i in range(n):
            self.hash1[i+1] = (self.hash1[i]*base1 + ord(s[i])) % self.mod1
            self.pow1[i+1] = (self.pow1[i]*base1) % self.mod1
            self.hash2[i+1] = (self.hash2[i]*base2 + ord(s[i])) % self.mod2
            self.pow2[i+1] = (self.pow2[i]*base2) % self.mod2

    def get(self, l, r):
        h1 = (self.hash1[r] - self.hash1[l] * self.pow1[r-l]) % self.mod1
        h2 = (self.hash2[r] - self.hash2[l] * self.pow2[r-l]) % self.mod2
        return (h1,h2)


n = int(input())
s = input()
rh = RollingHash(s,base1=1007,base2=2009,mod1=10**9+7,mod2=10**9+9)

for len_ in range(n//2,0,-1):
    ql = [(-1,-1)]*(len_-1)
    wait_q = deque(ql)
    hset = set()
    # print(len_)
    for i in range(n-len_+1):
        # print(s[i:i+len_])
        hs = rh.get(i,i+len_)
        if hs in hset:
            print(len_)
            exit()
        else:
            wait_q.append(hs)
            hset.add(wait_q.popleft())
        # print(wait_q)
        # print(hset)

else:
    print(0)
### BUGGY CODE ###

L,R = map(int, input().split())
Smin=2019
Lo=L%2019
Ro=R-(L-Lo)
for x in range(Lo,Ro):
    for y in range(x+1,Ro+1):
        Sa=x*y
        S=Sa%2019
        if Smin>S:
            Smin=S
print(Smin)



### FIXED CODE ###

L,R = map(int, input().split())
Smin=2019
Lo=L%2019
Ro=R-(L-Lo)
if Ro>=2019:
    Smin=0
if Ro<2019:
    for x in range(Lo,Ro):
        for y in range(x+1,Ro+1):
            Sa=x*y
            S=Sa%2019
            if Smin>S:
                Smin=S
print(Smin)
### BUGGY CODE ###

# B

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

N = int(input())
S = []
for _ in range(N):
    S.append(list(input()))


def is_good(S):
    T = []
    for j in range(N):
        ls = []
        for i in range(N):
            ls.append(S[i][j])
        T.append(ls)

    if T == S:
        return True
    else:
        return False


ans = 0
for a in range(N):
    T = []
    for i in range(N):
        T.append(S[(i+a) % N])
    if is_good(T):
        ans += N

print(ans)


### FIXED CODE ###

# B

N = int(input())
S = []
for _ in range(N):
    S.append(list(input()))


def is_good(S):
    # T = []
    # for j in range(N):
    #     ls = []
    #     for i in range(N):
    #         ls.append(S[i][j])
    #     T.append(ls)
    T = list(map(list, zip(*S)))

    if T == S:
        return True
    else:
        return False


ans = 0
for a in range(N):
    T = []
    for i in range(N):
        T.append(S[(i+a) % N])
    if is_good(T):
        ans += N

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

import itertools

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

cnt = 0

if k % 2 == 0:
  k_2 = k // 2
else:
  k_2 = k

for a in range(k_2, n+1, k_2):
  for b in itertools.product(range(k-(a%k), n+1, k), repeat=2):
    cnt += len(b) // 2
        
print(cnt)


### FIXED CODE ###

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

cnt = 0

if k % 2 == 0:
  k_2 = k // 2
else:
  k_2 = k

for a in range(k_2, n+1, k_2):
  cnt += len(range(k-(a%k), n+1, k)) ** 2
        
print(cnt)
### BUGGY CODE ###

n, k = list(map(int, input().split()))
an = list(map(int, input().split()))

ptr = 0
buf = [[a for a in an], [0] * len(an)]
#print(an)
for i in range(k):
    ib = buf[ptr]
    buf[ptr ^ 1] = [0] * len(an)
    ob = buf[ptr ^ 1]
    
    for j in range(n):
        s = ib[j]

        lb = max(j - s, 0)
        ub = min(j + s, len(an) - 1)
        for k_ in range(lb, ub + 1):
            ob[k_] += 1
    #print('k =', i + 1)
    #print(ob)
    ptr ^= 1
    if all(a == n for a in ob):
        #print('done!')
        break

print(' '.join(map(str, buf[ptr])))


### FIXED CODE ###

import numpy as np
from numba import njit

@njit('i8,i8,i8[::1]', cache=True)
def fn(n, k, a):
    for _ in range(k):
        b = np.zeros(n, dtype=np.int64)
        for i in range(n):
            lb = max(i - a[i], 0)
            ub = min(i + a[i], n - 1)

            b[lb] += 1
            if ub + 1 < n:
                b[ub + 1] -= 1

        a = b.cumsum()
        if np.all(a == n):
            return a
    return a

n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
a = np.array(a, dtype=np.int64)

b = fn(n, k, a)
print(' '.join(b.astype(str)))
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
for _ in range(Q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

ans = sum(A)
d = dict()
for i in range(N):
    if A[i] not in d:
        d[A[i]] = set()
    d[A[i]].add(i)

for i in range(Q):
    if B[i] not in d:
        print(ans)
        continue
    size = len(d[B[i]])
    sa = C[i]-B[i]
    if C[i] not in d:
        d[C[i]] = set()
    d[C[i]] = d[C[i]] | d[B[i]]
    d[B[i]] = set()
    ans += size * sa
    print(ans)

### FIXED CODE ###

def main():
    N = int(input())
    A = list(map(int, input().split()))
    Q = int(input())
    B, C = [0]*Q, [0]*Q
    for i in range(Q):
        B[i], C[i] = map(int, input().split())

    ans = sum(A)
    d = dict()
    for i, a in enumerate(A):
        d[a] = d.get(a, 0) + 1

    for b, c in zip(B, C):
        if b not in d:
            print(ans)
            continue
        ans += d[b] * (c-b)
        if c not in d:
            d[c] = 0
        d[c] = d[c] + d[b]
        d[b] = 0
        print(ans)

main()