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

mod = 10**9 + 7
n = int(input())
lx = list(map(int, input().split()))

from math import factorial as kj

d = 0
lk = [0] * n

for i in range(1, n):
  d += kj(n-1) // i % mod
  lk[i] = (lx[i] - lx[i-1]) * d % mod

print(sum(lk) % mod)

### FIXED CODE ###

mod = 10**9 + 7
n = int(input())
lx = list(map(int, input().split()))

d = 0
ans = 0

for i in range(1, n):
  f = 1 if i == 1 else f * (i-1) % mod
  d = (d * i + f) % mod
  ans = (ans * i + (lx[i] - lx[i-1]) * d) % mod

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

N, A = map(int, input().split())
X = [int(x) - A for x in input().split()]
X0 = [0 for x in X if x == 0]
Xp = [x for x in X if x > 0]
Xm = [-x for x in X if x < 0]
limit = min(sum(Xp), sum(Xm))
Xp = [x for x in Xp if x <= limit]
Xm = [x for x in Xm if x <= limit]
R = [[0, 0] for x in range(limit + 1)]
def c(X, k):
  for i in range(2 ** len(X)):
    mask = bin(i)[2:]
    mask = [0 for m in range(len(X) - len(mask))] + [int(s) for s in mask]
    masked = sum([X[j] * mask[j] for j in range(len(X))])
    if masked <= limit:
      R[masked][k] += 1
c(Xp, 0)
c(Xm, 1)
print(sum([r[0] * r[1] for r in R]) * (2 ** len(X0)) - 1)

### FIXED CODE ###

from collections import Counter
N, A = map(int, input().split())
X = [int(x) - A for x in input().split()]
C = Counter([0])
for x in X:
  tmp = Counter()
  for i, c in C.items():
    tmp[i + x] += c
  C += tmp
print(C[0] - 1)
### BUGGY CODE ###

# coding: utf-8

N,M,L=map(int, raw_input().split())
Roads = [] # from, to, cost
for i in range(M):
    Roads.append(map(int, raw_input().split()))
Q=int(raw_input())
Queries = [] # from, to
for i in range(Q):
    Queries.append(map(int, raw_input().split()))

def dijkstra(s, t):

    candidates = [[s,0,0]] # node, charge, used
    confirmed = []

    while candidates:
        c = candidates.pop(0)
        confirmed.append(c)
        if c[0] == t:
            return c
        for i in Roads:
            if i[0] == c[0]:
                node = i[1]
            elif i[1] == c[0]:
                node = i[0]
            else:
                continue

            if i[2] > L:
                continue
            elif i[2] + c[2] > L:
                charge = c[1] + 1
                used = i[2]
            else:
                charge = c[1]
                used = c[2] + i[2]

            candidates.append([node, charge, used])
        candidates.sort(key=lambda x: x[1]*L+x[2])
    return None

for s,t in Queries:
    ret = dijkstra(s,t)
    if ret:
        print str(ret[1])
    else:
        print str(-1)

### FIXED CODE ###

# coding: utf-8
from scipy.sparse.csgraph import floyd_warshall

N,M,L=map(int, input().split())
RG=[[0 for i in range(N)] for j in range(N)]

for i in range(M):
    f,t,c = map(int, input().split())
    if c <= L:
        RG[f-1][t-1] = c
        RG[t-1][f-1] = c

Rd = floyd_warshall(RG, directed=False)

FG=[[0 for i in range(N)] for j in range(N)]
for i in range(N):
    for j in range(i+1, N):
        if Rd[i][j] <= L:
            FG[i][j] = 1
            FG[j][i] = 1

Fd = floyd_warshall(FG, directed=False)

Q=int(input())
for i in range(Q):
    s, t = map(int, input().split())
    v = Fd[s-1][t-1]
    if s == t:
        print (str(0))
    if v == float('inf'):
        print (str(-1))
    else:
        print (str(int(v-1)))
### BUGGY CODE ###

total, tar = list(map(int, input().split()))
dice_array = list(map(int, input().split()))
l = [] * total

tar2 = 0
calc_before = 0
calc_now = 0
for i in range(total+1-tar):
  for j in range(tar):
    calc_now += dice_array[i + j]
  if calc_before < calc_now:
    tar2 = i
    calc_before = calc_now
  calc_now = 0
  
sum = 0
for i in range(tar2, tar+tar2):
  cnt = 0
  for j in range(1, dice_array[i]+1):
    cnt += j
  sum += (cnt / dice_array[i])
  
print(sum)

### FIXED CODE ###

total, tar = list(map(int, input().split()))
dice_array = list(map(int, input().split()))

hope_array = [0.0] * total
for i in range(total):
   hope_array[i] = (dice_array[i] * (dice_array[i] + 1)) / 2 / dice_array[i]

dice_total = [0]
 
for i in range(total):
  dice_total.append(hope_array[i] + dice_total[i])
 
ans = dice_total[tar]
tar_num = tar
for i in range(total - tar):
  tmp = dice_total[i + 1 + tar] - dice_total[i + 1]
  if ans < tmp:
    ans = tmp

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

def main():
    N=int(input())
    a=[int(_) for _ in input().split()]
    pair = []
    ans = 0
    for i in range(N):
        fst = a[a[i]-1]
        snd = a[fst-1]
        pair.append((fst,snd))
    pair=list(set(pair))
    for i in range(len(pair)-1):
        for j in range(i+1,len(pair)):
            if pair[i][0]==pair[j][1] and pair[i][1]==pair[j][0]:
                ans += 1
    print(ans)

main()

### FIXED CODE ###

def main():
    N=int(input())
    a=[int(_) for _ in input().split()]
    ans = 0
    for i,v in enumerate(a):
        if a[v-1] == i+1:
            ans += 1
    print(ans//2)

main()
### BUGGY CODE ###

import sys
from collections import deque
input = sys.stdin.readline
h, w = [int(x) for x in input().strip().split()]
g = [[x for x in input().strip()] for _ in range(h)]

ans = -1
q = deque([])
for i in range(h):
    for j in range(w):
        if g[i][j] == '#':
            q.append((i, j))
vec = [(0, 1), (1, 0), (0, -1), (-1, 0)]
while q:
    q_ = q
    q = deque([])
    ans += 1
    while q_:
        i, j = q_.pop()
        for x, y in vec:
            ti, tj = i+x, j+y
            if 0 <= ti < h and 0 <= tj < w:
                if g[ti][tj] == '.':
                    g[ti][tj] = '#'
                    q.append((ti, tj))
print(ans)


### FIXED CODE ###

import sys
from collections import deque
input = sys.stdin.readline
h, w = [int(x) for x in input().strip().split()]
g = [[x for x in list(input().strip())] for _ in range(h)]

ans = -1
q = []
for i in range(h):
    for j in range(w):
        if g[i][j] == '#':
            q.append((i, j))
vec = [(0, 1), (1, 0), (0, -1), (-1, 0)]
while q:
    q_ = deque(q)
    q = deque([])
    ans += 1
    while q_:
        i, j = q_.pop()
        for x, y in vec:
            ti, tj = i+x, j+y
            if 0 <= ti < h and 0 <= tj < w:
                if g[ti][tj] == '.':
                    g[ti][tj] = '#'
                    q.append((ti, tj))
print(ans)
### BUGGY CODE ###

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

mod = 10**9 + 7

dp = [[0] * n for _ in range(n)]

for more in range(n):
    dp[0][more] = 1

for i in range(n-1):
    if s[i] == "<":
        cum = 0
        for more in reversed(range(n-1-i)):
            cum += dp[i][more+1]
            cum %= mod
            dp[i + 1][more] += cum
            dp[i + 1][more] %= mod
    else:
        cum = 0
        for more in range(n-1-i):
            cum += dp[i][more]
            cum %= mod
            dp[i+1][more] += cum
            dp[i+1][more] %= mod

print(dp[n-1][0])


### FIXED CODE ###

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

mod = 10**9 + 7

dp = [[0] * n for _ in range(n)]

for more in range(n):
    dp[0][more] = 1

for i in range(n-1):
    if s[i] == "<":
        cum = 0
        for more in reversed(range(n-1-i)):
            cum += dp[i][more+1]
            cum %= mod
            dp[i + 1][more] += cum
            dp[i + 1][more] %= mod
    else:
        cum = 0
        for more in range(n-1-i):
            cum += dp[i][more]
            cum %= mod
            dp[i+1][more] += cum
            dp[i+1][more] %= mod

print(dp[n-1][0])
### BUGGY CODE ###

l = input().split()
S = input()
N = int(l[0])
Q = int(l[1])
lr = [input().split() for _ in range(Q)]
for i in range(Q):
  lrlr = lr[i]
  score = 0
  for check in range(int(lrlr[0])-1,int(lrlr[1])-1):
    if S[check] == 'A' and S[check+1] == 'C':
      score += 1
  print(score)
      

### FIXED CODE ###

l = input().split()
N,Q = int(l[0]),int(l[1])
S = input()
blue = [0] * N
for k in range(1,N):
  if S[k-1] == 'A' and S[k] == 'C':
    blue[k] = blue[k-1] + 1
  else:
    blue[k] = blue[k-1]
for i in range(1,Q+1):
  rl = input().split()
  r = int(rl[0])
  l = int(rl[1])
  print(
    blue[l-1] - blue[r-1])
### BUGGY CODE ###

N, W = map(int, input().split())
goods = []
for _ in range(N):
    goods.append(tuple(map(int, input().split())))

table = [[0] * (W + 1) for _ in range(N + 1)]
for n in range(N):
    for w in range(W + 1):
        addn = table[n][w - goods[n][0]] + goods[n][1] if w - goods[n][0] >= 0 else 0
        table[n + 1][w] = max(table[n][w], addn)
print(table[N][W])


### FIXED CODE ###

import numpy as np

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

table = np.zeros((N + 1, W + 1), dtype=np.int64)
for n in range(N):
    tmp = np.zeros(W + 1, dtype=np.int64)
    tmp[goods[n][0]:] = table[n][:W + 1 - goods[n][0]] + goods[n][1]
    table[n + 1] = np.maximum(table[n], tmp)
print(table[N][W])
### BUGGY CODE ###

import bisect

n=int(input())
a=[int(x) for x in input().rstrip().split()]
q=int(input())
a.sort()
for i in range(q):
  b,c=map(int,input().split())
  b_l=bisect.bisect_left(a,b)
  b_r=bisect.bisect_right(a,b)
  a=a[:b_l]+[c]*(b_r-b_l)+a[b_r:]
  print(sum(a))

### FIXED CODE ###

import bisect

n=int(input())
a=[int(x) for x in input().rstrip().split()]
dp=[0 for i in range(10**5)]
q=int(input())

for i in a:
  dp[i-1]+=1

ans=sum(a)
for i in range(q):
  b,c=map(int,input().split())
  ans=ans-(dp[b-1]*b)+(c*dp[b-1])
  dp[c-1]+=dp[b-1]
  dp[b-1]=0
  print(ans)
### BUGGY CODE ###

#!/usr/bin/env python3

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

while n > abs(n-k):
    n = abs(n-k)

print(n)

### FIXED CODE ###

#!/usr/bin/env python3

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

#while n > abs(n-k):
#    n = abs(n-k)
while 2*n > k:
    
    if n > k:
        n = n%k
    elif n <= k:
        n = k-n

print(n)
### BUGGY CODE ###

s = input()
K = int(input())
dict1 = {}
for i in range(len(s)):
    if s[i] in dict1:
        continue
    else:
        dict1[s[i]] = len(s) - i
dict1 = list(dict1.items())
dict1.sort()
count = 0
for e in dict1:
    count += e[1]
    if count >= K:
        note = e[0]
        break
part_list = []
for i in range(len(s)):
    if ord(s[i]) <= ord(note):
        for j in range(i+1,len(s)+1):
            part = s[i:j]
            part_list.append(part)
part_list = list(set(part_list))
part_list.sort()
ans = part_list[K-1]
print(ans)

### FIXED CODE ###

s = input()
K = int(input())
dict1 = {}
for i in range(len(s)):
    if s[i] in dict1:
        continue
    else:
        dict1[s[i]] = len(s) - i
dict1 = list(dict1.items())
dict1.sort()
count = 0
for e in dict1:
    count += e[1]
    if count >= K:
        note = e[0]
        break
part_list = []
for i in range(len(s)):
    if ord(s[i]) <= ord(note):
        for j in range(i+1,i+6):
            part = s[i:j]
            part_list.append(part)
part_list = list(set(part_list))
part_list.sort()
ans = part_list[K-1]
print(ans)
### BUGGY CODE ###

def resolve():
    a, b = map(int, input().split())
    save_result = []
    save_result.append(a)
    while True:
        a = a - b
        if a < 0:
            abs_s = abs(a)
            save_result.append(abs_s)
            break
        else:
            save_result.append(a)

    print(min(save_result))
resolve()

### FIXED CODE ###

def resolve():
    n, k = map(int, input().split())
    print(min(n, n % k, abs(n % k - k)))

resolve()
### BUGGY CODE ###

import sys
import numpy as np
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix

read = sys.stdin.read
N, u, v, *AB = map(int, read().split())
AB = np.array(AB, np.int32).reshape(N - 1, 2)

a = AB[:, 0]
b = AB[:, 1]
d = np.ones_like(a, np.int32)

graph = csr_matrix((d, (a, b)), shape=(N + 1, N + 1))
takahashi = dijkstra(graph, directed=False, indices=u)
aoki = dijkstra(graph, directed=False, indices=v)

print(int(aoki[takahashi < aoki].max()) - 1)

### FIXED CODE ###

import sys

read = sys.stdin.read
N, u, v, *AB = map(int, read().split())

graph = [[] for _ in range(N + 1)]
for a, b in zip(*[iter(AB)] * 2):
    graph[a].append(b)
    graph[b].append(a)


def dfs(v):
    dist = [-1] * (N + 1)
    stack = [v]
    dist[v] = 0
    while stack:
        v = stack.pop()
        dw = dist[v] + 1
        for w in graph[v]:
            if dist[w] >= 0:
                continue
            dist[w] = dw
            stack.append(w)
    return dist


DU, DV = dfs(u), dfs(v)

answer = 0
for u, v in zip(DU[1:], DV[1:]):
    if u < v:
        tmp = v - 1
        if answer < tmp:
            answer = tmp

print(answer)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
#from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
#from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [LI()for i in range(n)]
inf = 10**17
mod = 10**9 + 7

h,w=MI()
mat1 =[[] for i in range(h)]
mat2 =[[0 for j in range(w)] for i in range(h)]
mat3 =[[0 for j in range(w)] for i in range(h)]
mat4 =[[0 for j in range(w)] for i in range(h)]
mat5 =[[0 for j in range(w)] for i in range(h)]


for i in range(h):
    s=input().rstrip()
    for j in range(w):
        mat1[i].append(s[j])
#print(mat1)

for i in range(h):
    for j in range(w):
        if mat1[i][j]=="#":
            mat2[i][j]=0
        else:
            if j==0:
                mat2[i][j]=1
            else:
                mat2[i][j]=mat2[i][j-1]+1
#print(mat2)

for i in range(h):
    for j in reversed(range(w)):
        #print(i,j)
        if mat1[i][j]=="#":
            mat3[i][j]=0
        else:
            if j==w-1:
                mat3[i][j]=1
            else:
                mat3[i][j]=mat3[i][j+1]+1
#print(mat3)

for i in range(w):
    for j in range(h):
        if mat1[j][i]=="#":
            mat4[j][i]=0
        else:
            if j==0:
                mat4[j][i]=1
            else:
                mat4[j][i]=mat4[j-1][i]+1
#print(mat4)

for i in range(w):
    for j in reversed(range(h)):
        if mat1[j][i]=="#":
            mat5[j][i]=0
        else:
            if j==h-1:
                mat5[j][i]=1
            else:
                mat5[j][i]=mat5[j+1][i]+1
#print(mat5)
mx=0
for i in range(h):
    for j in range(w):
        if mat1[i][j]==".":
            ans=mat2[i][j]+mat3[i][j]+mat4[i][j]+mat5[i][j]-3
            if ans>mx:
                mx=ans
print(mx)

### FIXED CODE ###

# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

H, W = lr()
S = [list(sr()) for _ in range(H)]
S = np.array([[1 if x == '.' else 0 for x in row] for row in S], np.bool)
up = np.zeros((H, W), np.int32)
down = np.zeros((H, W), np.int32)
right = np.zeros((H, W), np.int32)
left = np.zeros((H, W), np.int32)
for i in range(H-1):
    up[i+1] = (1+up[i]) * S[i]
for i in range(H-1, 0, -1):
    down[i-1] = (1+down[i]) * S[i]
for i in range(W-1):
    left[:, i+1] = (1+left[:, i]) * S[:, i]
    #行列の列を取り出す時の記法
for i in range(W-1, 0, -1):
    right[:, i-1] = (1+right[:, i]) * S[:, i]


answer = ((up + down + left + right) * S).max() + 1
#自身を数えないことで特殊な場合をなくしている
print(answer)
### BUGGY CODE ###


def main():
    """"ここに今までのコード"""
    import sys
    input = sys.stdin.readline
    n,m=map(int,input().split())
    A=list(map(int,input().split()))
    if n==1:
        ans=(m//(A[0]//2)+1)//2
        print(int(ans))
        exit()
    from fractions import gcd
    kou=A[0]*A[1]//gcd(A[0],A[1])
    for a in range(n):
        kou=A[a]*kou//gcd(A[a],kou)
        if (kou//A[a])%2==0:
            print(0)
            exit()
    kou//=2
    #print(kou)
    ans=(m//kou+1)//2
    print(int(ans))
if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    """"ここに今までのコード"""
    import sys
    input = sys.stdin.readline
    n,m=map(int,input().split())
    A=list(map(int,input().split()))
    #A.sort()
    if n==1:
        ans=(m//(A[0]//2)+1)//2
        print(int(ans))
        exit()
    from fractions import gcd
    kou=A[0]*A[1]//gcd(A[0],A[1])
    for a in A:
        kou=a*kou//gcd(a,kou)
        if (kou//a)%2==0:
            print(0)
            exit()
    kou//=2
    #print(kou)
    ans=(m//kou+1)//2
    print(int(ans))
if __name__ == '__main__':
    main()
### BUGGY CODE ###

h, w = list(map(int, input().split()))
si, sj = list(map(int, input().split()))
ti, tj = list(map(int, input().split()))
s = [None] * h
for i in range(h):
    s[i] = input()

# 移動Aで探索する方向
d_a = [(-1,0), (0,-1),(1,0),(0,1)]
# 移動Bで探索する方向
d_b = [ (i, j) for j in range(-2, 3) for i in range(-2, 3)]

# 距離情報を一番遠い値で初期化
import numpy as np
INF = int(1e9)
dist = np.full((h+2, w+2), INF)
#dist = [[INF for j in range(w+2)] for i in range(h+2)]

# マップ境界と壁を距離0にして探索させない
for i in range(h+2):
    dist[i][0] = 0
    dist[i][-1] = 0
for j in range(w+2):
    dist[0][j] = 0
    dist[-1][j] = 0
for i in range(h):
    for j in range(w):
        if s[i][j]=='#': dist[i+1][j+1] = 0
#dist = [[INF for j in range(w)] for i in range(h)]

# 01-BFS探索用キュー
from collections import deque
q = deque()

# 開始位置
dist[si][sj] = 0
q.append((si,sj))

while (len(q)>0):
    i, j = q[0]
    d = dist[i][j]
    q.popleft()
    # 移動Aによるコスト
    for v in range(len(d_a)):
        di, dj = d_a[v][0]+i, d_a[v][1]+j
        if (di, dj) == (ti, tj):
            print(d)
            exit(0)
        if (dist[di][dj]<=d):
            continue # 探索済みコスト以上
        dist[di][dj] = d
        q.appendleft((di, dj))
    # 移動Bによるコスト
    for v in range(len(d_b)):
        # マップ境界で2以上移動したときに、反対の境界に向かうように剰余を取る
        di, dj = (d_b[v][0]+i)%(h+2), (d_b[v][1]+j)%(w+2)
        if (dist[di][dj]<=d):
            continue # 探索済みコスト以上
        dist[di][dj] = d+1
        q.append((di, dj))

ans = dist[ti][tj]
if ans == INF:
    ans = -1
print(ans)


### FIXED CODE ###

h, w = list(map(int, input().split()))
si, sj = list(map(int, input().split()))
ti, tj = list(map(int, input().split()))
s = [None] * h
for i in range(h):
    s[i] = input()

# 移動Aで探索する方向
d_a = [(-1,0), (0,-1),(1,0),(0,1)]
# 移動Bで探索する方向
d_b = [ (i, j) for j in range(-2, 3) for i in range(-2, 3)]

# 距離情報を一番遠い値で初期化
#import numpy as np
INF = int(1e9)
#dist = np.full((h+2, w+2), INF)
dist = [[INF for j in range(w+2)] for i in range(h+2)]

# マップ境界と壁を距離0にして探索させない
for i in range(h+2):
    dist[i][0] = 0
    dist[i][-1] = 0
for j in range(w+2):
    dist[0][j] = 0
    dist[-1][j] = 0
for i in range(h):
    for j in range(w):
        if s[i][j]=='#': dist[i+1][j+1] = 0
#dist = [[INF for j in range(w)] for i in range(h)]

# 01-BFS探索用キュー
from collections import deque
q = deque()

# 開始位置
dist[si][sj] = 0
q.append((si,sj))

while (len(q)>0):
    i, j = q[0]
    d = dist[i][j]
    q.popleft()
    # 移動Aによるコスト
    for v in range(len(d_a)):
        di, dj = d_a[v][0]+i, d_a[v][1]+j
        if (di, dj) == (ti, tj):
            print(d)
            exit(0)
        if (dist[di][dj]<=d):
            continue # 探索済みコスト以上
        dist[di][dj] = d
        q.appendleft((di, dj))
    # 移動Bによるコスト
    for v in range(len(d_b)):
        # マップ境界で2以上移動したときに、反対の境界に向かうように剰余を取る
        di, dj = (d_b[v][0]+i)%(h+2), (d_b[v][1]+j)%(w+2)
        if (dist[di][dj]<=d):
            continue # 探索済みコスト以上
        dist[di][dj] = d+1
        q.append((di, dj))

ans = dist[ti][tj]
if ans == INF:
    ans = -1
print(ans)
### BUGGY CODE ###

s=input()
seen=set()
i=0
ans=0
while i<len(s):
  for j in range(i+1,len(s)):
    if s[i:j] not in seen:
      if s[j:] in seen:
        continue
      seen.add(s[i:j])
      i=j
      ans+=1
print(ans)
      

### FIXED CODE ###

S=input()
dp=[[0 for i in range(2)] for j in range(len(S))]
# dp[x]:x番目の文字に、dp[x][0]:1文字で来たときの最大分割数、dp[x][1]:2文字で来た時
dp[0][0]=1
dp[0][1]=-1
for i in range(1,len(S)):
  if S[i]==S[i-1]:
    dp[i][0]=dp[i-1][1]+1
  elif S[i]!=S[i-1]:
    dp[i][0]=max(dp[i-1][0],dp[i-1][1])+1
  if i-2>=0:
    dp[i][1]=max(dp[i-2][0],dp[i-2][1])+1
print(max(dp[-1][0],dp[-1][1]))
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
q=int(input())

for _ in range(q):
    b,c=map(int,input().split())
    for i in range(n):
        if a[i]==b:
            a[i]=c
    print(sum(a))

### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline

n=int(input())
a=list(map(int,input().split()))
q=int(input())

ans=sum(a)

x=[0]*(10**5+10)
for i in a:
    x[i]+=1


for _ in range(q):
    b,c=map(int,input().split())
    ans+=x[b]*c-x[b]*b
    print(ans)
    x[c]+=x[b]
    x[b]=0
### BUGGY CODE ###

import copy
n = int(input())
a = [int(input()) for _ in range(n)]
for i in range(len(a)):
	temp = copy.deepcopy(a)
	temp.pop(i)
	print(max(temp))

### FIXED CODE ###

import copy
n = int(input())
a = [int(input()) for _  in range(n)]
jisyo = {}
flag = False
if(a.count(max(a))!=1):
	flag = True
b = copy.deepcopy(a)
b.sort()
for i in a:
	if flag:
		print(b[-1])
	elif(i == b[-1]):
		print(b[-2])
	else:
		print(b[-1])
### BUGGY CODE ###

import sys
input=sys.stdin.readline
n=int(input())
wf=[list(map(int,input().split())) for i in range(n)]

ans=0
for i in range(n):
    for j in range(i+1,n):
        use=True
        for h in range(n):
            if h!=i and h!=j and wf[i][j] > wf[i][h]+wf[h][j]:
                print(-1)
                exit()
            if h!=i and h!=j and wf[i][j] == wf[i][h]+wf[h][j]:
                use=False
        if use:
            ans+=wf[i][j]
print(int(ans))

### FIXED CODE ###

import sys
input=sys.stdin.readline
n=int(input())
wf=[list(map(int,input().split())) for i in range(n)]

ans=0
for i in range(n):
    for j in range(i+1,n):
        use=True
        for h in range(n):
            if h!=i and h!=j and wf[i][j] > wf[i][h]+wf[h][j]:
                print(-1)
                exit()
            if h!=i and h!=j and wf[i][j] == wf[i][h]+wf[h][j]:
                use=False
        if use:
            ans+=wf[i][j]
print(int(ans))
### BUGGY CODE ###

import sys
from collections import deque
input = sys.stdin.readline
n = int(input())
hL = list(map(int, input().split()))
for i in range(n-1):
    for j in range(i+1, n) :
        if hL[i] >hL[j]:
            hL[i]-=1
            break
if hL ==sorted(hL):
    print('Yes')
else:
    print('No')

### FIXED CODE ###

import sys
import numpy as np
input = sys.stdin.readline
n = int(input())

L = np.array(list(map(int, input().split())))

for i in range(n-1, 0, -1):
    if L[i]-L[i-1] ==-1:
        L[i-1] -=1

if np.all(L ==sorted(L)):
    print('Yes')
else:
    print('No')
### BUGGY CODE ###

n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)

tmp = a[:m]
for _ in range(m):
    maximum = tmp.index(max(tmp))
    tmp[maximum] = tmp[maximum] // 2

print(sum(tmp + a[m:]))


### FIXED CODE ###

from heapq import heappop,heappush,heapify
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
a = list(map(int, input().split()))
a_minus = [-x for x in a]
heapify(a_minus)

pop = lambda: -heappop(a_minus)
push = lambda x: heappush(a_minus,-x)

for _ in range(m):
    x = pop()
    push(x//2)

print(-sum(a_minus))
### BUGGY CODE ###

n,k = map(int,input().split())
a = list(range(n+1))
b = a[::-1]
ans = 0

for i in range(k,n+2):
    min = sum(a[:i])
    max = sum(b[:i])
    ele = max - min +1
    ans += ele

print(ans)

### FIXED CODE ###

n,k = map(int,input().split())
a = list(range(n+1))
b = a[::-1]
ans = 0

min = sum(a[:k-1])
max = sum(b[:k-1])


for i in range(k,n+2):
    min += a[i-1]
    max += b[i-1]
    ele = max - min +1
    ans += ele

M =10**9 + 7
print(ans % M)