Harryxun/stf_run huggingface dataset:
#Deven-Eleven:
import re
p = re.compile("\d+\s\d+")
D = (((-1, -1), (0, -1), (1, 0), (0, 1), (-1, 1), (-1, 0)),
     ((0, -1), (1, -1), (1, 0), (1, 1), (0, 1), (-1, 0)))
def func(y, x):
    q = [(y, x, 0)]
    cover = [[-1] * m for _ in xrange(n)]
    while len(q) != 0:
        y, x, step = q.pop(0)
        if cover[y][x] >= 0:
            continue
        cover[y][x] = step
        for dx, dy in D[y % 2]:           
            ny, nx = y + dy, x + dx
            if 0 <= ny < n and 0 <= nx < m:
                q.append((ny, nx, step + 1))
    return cover
 
def solve():
    scover = [func(pos[1] - 1, pos[0] - 1) for pos in spos]
    min_cover = [[min(sc[y][x] for sc in scover) for x in xrange(m)] for y in xrange(n)]
    def count(cover):
        ret = 0
        for y in xrange(n):
            for x in xrange(m):
                if cover[y][x] < min_cover[y][x]:
                    ret += 1
        return ret
    return max(count(func(pos[1] - 1, pos[0] - 1)) for pos in tpos)

while True:
    data = raw_input()
    if p.match(data) is None:
        break
    m, n = map(int, data.split())
    s = input()
    spos = [map(int, raw_input().split()) for _ in xrange(s)]
    t = input()
    tpos = [map(int, raw_input().split()) for _ in xrange(t)]
    print solve()

### FIXED CODE ###

#Deven-Eleven:
D = (((-1, -1), (0, -1), (1, 0), (0, 1), (-1, 1), (-1, 0)),
     ((0, -1), (1, -1), (1, 0), (1, 1), (0, 1), (-1, 0)))
def func(y, x):
    q = [(y, x, 0)]
    cover = [[-1] * m for _ in xrange(n)]
    while len(q) != 0:
        y, x, step = q.pop(0)
        if cover[y][x] >= 0:
            continue
        cover[y][x] = step
        for dx, dy in D[y % 2]:           
            ny, nx = y + dy, x + dx
            if 0 <= ny < n and 0 <= nx < m:
                q.append((ny, nx, step + 1))
    return cover
 
def solve():
    scover = [func(pos[1] - 1, pos[0] - 1) for pos in spos]
    min_cover = [[min(sc[y][x] for sc in scover) for x in xrange(m)] for y in xrange(n)]
    def count(cover):
        ret = 0
        for y in xrange(n):
            for x in xrange(m):
                if cover[y][x] < min_cover[y][x]:
                    ret += 1
        return ret
    return max(count(func(pos[1] - 1, pos[0] - 1)) for pos in tpos)

while True:
    data = raw_input()
    m, n = map(int, data.split())
    if m == 0:
        break
    s = input()
    spos = [map(int, raw_input().split()) for _ in xrange(s)]
    t = input()
    tpos = [map(int, raw_input().split()) for _ in xrange(t)]
    print solve()
A,B,C=map(int(),input(),split())
print(C-A+B)

### FIXED CODE ###

A,B,C = map(int,input().split())
X = C - A + B
if X < 0:
    X = 0
print(X)
N = int(input())
K = int(input())
h = str(input())
ans = 0
for i in range(N):
  if int(h.split()[i]) >= K:
    ans += 1
    
print(ans)

### FIXED CODE ###

NK = [int(a) for a in input().split()]
h = [int(a) for a in input().split()]
ans = 0
for i in range(NK[0]):
  if h[i] >= NK[1]:
    ans += 1
    
print(ans)
import collections
N = int(input())
c = collections.Counter(prime_factorize(N))

ans = 0
for j in c:
    for i in range(1,c[j]+1):
        if c[j] == 1:
            ans += 1
        elif i*(i+1)<= 2*c[j] < (i+1)*(i+2):
            ans += i

print(ans)

### FIXED CODE ###

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
  
import collections
N = int(input())

c = collections.Counter(prime_factorize(N))

ans = 0
for j in c:
    for i in range(1,c[j]+1):
        if c[j] == 1:
            ans += 1
        elif i*(i+1)<= 2*c[j] < (i+1)*(i+2):
            ans += i

print(ans)
a = int(input())
A = list(map(int,input().split()))

ch = [1]
t = 0
for e,i in enumerate(A):
    t+=i
    if t>2**i:
        print(-1)
        exit()

cH = [1]
if A[0]>0:
    print(-1)
    exit()
for e,i in enumerate(A[1:]):
    cH.append(cH[-1]*2-i)
    # ch.append((cH[-1]*2)//(2**i))
# print(ch)
# print(cH)

# ch = ch[:-1]
# ch = ch[::-1]
# ch[0]*=2
# print(ch)
cH = cH[:-1]
cH.append(cH[-1]*2)
cH = cH[::-1]
# print(cH)

if cH[0] 

if 0 in cH:
    print(-1)
    exit()
A = A[::-1]

ans = 0
n = 0
for e,i in enumerate(A[:]):
    # print(n,ch[e],-1)
    if n//2+(n%2!=0)>cH[e]:
        print(-1)
        exit()
    if n  <= cH[e]:
        # print('ans:',ans,'n:',n)
        ans += n+i
        n+=i
    else:
        # print('ans:',ans,'ch:',cH[e],'i:',i)
        ans +=cH[e]+i
        n = cH[e]+i

    # print('ans:',ans,'n:',n)
print(ans)

### FIXED CODE ###



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

if a == 0 and A[0] == 1:
    print(1)
    exit()
ch = [1]

cH = [1]
if A[0]>0:
    print(-1)
    exit()
for e,i in enumerate(A[1:]):
    cH.append(cH[-1]*2-i)
    # ch.append((cH[-1]*2)//(2**i))
# print(ch)
# print(cH)

# ch = ch[:-1]
# ch = ch[::-1]
# ch[0]*=2
# print(ch)
cH = cH[:-1]
cH.append(cH[-1]*2)
cH = cH[::-1]
# print(cH)
if 0 in cH:
    print(-1)
    exit()
A = A[::-1]

ans = 0
n = 0
for e,i in enumerate(A[:]):
    # print(n,ch[e],-1)
    if n//2+(n%2!=0)>cH[e]:
        print(-1)
        exit()
    if n  <= cH[e]:
        # print('ans:',ans,'n:',n)
        ans += n+i
        n+=i
    else:
        # print('ans:',ans,'ch:',cH[e],'i:',i)
        ans +=cH[e]+i
        n = cH[e]+i

    # print('ans:',ans,'n:',n)
print(ans)
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
//using T = tuple<string, int, int>;

int main() {
  int A,B,C;
  cin >> A >> B >> C;
  cout << max(C-(A-B), 0) << endl;

  return 0;
}

// https://github.com/atcoder/live_library

### FIXED CODE ###

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

print(max(0,B+C-A))
# import numpy as np

# N, W = map(int, input().split())
# dp = np.zeros((N+1, W+1))  #i個目の品物までで重さw以下のときの価値の最大値 
# """
# dp[i, wi:W+1] = max(i番目の重さwiの品物を入れた場合, 入れなかった場合)
#          = np.max(dp[i-1, :W-wi+1] + v, dp[i-1, wi:W+1])
# """
# for i in range(1, N+1):
#     wi, vi = map(int, input().split())
#     for k in range(1, i+1):
#         tmp = np.maximum(dp[i-k, :W-wi+1] + vi, dp[i-k, wi:W+1])
#         dp[i, wi:W+1] = np.maximum(dp[i, wi:W+1], tmp)
    

# print(int(dp[-1,-1]))


N, W = map(int, input().split())
# dp = np.zeros((N+1, W+1))  #i個目の品物までで重さw以下のときの価値の最大値 
dp = [[0]*(W+1) for _ in range(N+1)]
"""
dp[i, wi:W+1] = max(i番目の重さwiの品物を入れた場合, 入れなかった場合)
         = np.max(dp[i-1, :W-wi+1] + v, dp[i-1, wi:W+1])
"""

for i in range(1, N+1):
    w, v = map(int, input().split())

    for j in range(W+1):
        if j - w >= 0:
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-w] + v)
        else:
            dp[i][j] = dp[i-1][j]

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


### FIXED CODE ###

#pypy3でAC

import sys
def input():
    return sys.stdin.readline()[:-1]

N, W = map(int, input().split())
w, v = [], []
for i in range(1, N+1):
    _w, _v = map(int, input().split())
    w.append(_w)
    v.append(_v)

V = sum(v)
#i個目までの品物から価値がj以上になるように選んだときの重さの最小値
dp = [[float("inf")]*(V+1) for _ in range(N+1)]
dp[0][0] = 0
"""
i番目を選ぶ場合
dp[i][j] = dp[i-1][j-v] + w
i番目を選ばない場合
dp[i][j] = dp[i-1][j]
"""

for i in range(1, N+1):
    for j in range(V+1):
        if j - v[i-1] >= 0:
            dp[i][j] = min(dp[i-1][j], dp[i-1][j-v[i-1]] + w[i-1])
        else:
            dp[i][j] = dp[i-1][j]

# dp[N][j]がW以下であるような最大のjを探す
for j in range(V+1):
    if dp[N][j] <= W:
        ans = j
print(ans)
import string

count = {x: 0 for x in string.ascii_lowercase}
lines =''
while True:
    try:
        lines += input().lower()
    except EOFError:
        break

for c in s:
    if 'a' <= c <= 'z':
        count[c] += 1

for key in string.ascii_lowercase:
    print("{0} : {1}".format(key,count[key]))

### FIXED CODE ###

import string

count = {x: 0 for x in string.ascii_lowercase}
lines =''
while True:
    try:
        lines += input().lower()
    except EOFError:
        break

for c in lines:
    if 'a' <= c <= 'z':
        count[c] += 1

for key in string.ascii_lowercase:
    print("{0} : {1}".format(key,count[key]))
import itertools

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

lis=[]
for i in range(q):
    lis.append(list(map(int,input().split())))

Alist=[]

for l in itertools.combinations(range(1,n+m),n):
    ll=list(l)
    a=[]
    for i in range(n):
        a.append(ll[i]-i)
    Alist.append(a)

slist=[]
for i in range(len(Alist)):
    s=0
    for j in range(q):
        aj=lis[j][0]
        bj=lis[j][1]
        cj=lis[j][2]
        dj=lis[j][3]
        if Alist[i][bj-1]-Alist[i][aj-1]==cj:
            s+=dj
    slist.append(s)

print(max(slist))

### FIXED CODE ###

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

c=0
for i in range(a,b+1):
    if i%k==0:
        c+=1

if c==0:
    print("NG")
else:print("OK")
n=int(input())
ans=1
li = input().split()
zero=False
for i in li:
  ans*=int(i)
  if ans==0:
    zero=True
  if ans>1000000000000000000:
    ans=-1

if ans<0:
  ans=-1
if zero:
  ans=0
print(ans)


### FIXED CODE ###

from decimal import *
a,b=input().split()
a=Decimal(a)
b=Decimal(b)
ans=int(a*b)
print(ans)
a, b, k = map(int, input().split())
if k <= a:
    a1 = a - k
    b1 = b
elif a < k and k < a + b:
    a1 = 0
    b1 = b - (k-a)
else:
    a1 = 0
    b1 = 0

print(a1, b1)

### FIXED CODE ###

s, t = input().split()
print(t+s)
n=int(input())
a=list(map(int,input().split()))
sum=0
cnt=0
# 奇数+
for i in range(n):
    sum+=a[i]
    if i%2==0:
        if sum>=0:
            cnt+=(sum+1)
            sum=-1
    else:
        if sum<=0:
            cnt+=(1-sum)
            sum=1
cnt_sbst=cnt
# 奇数-
cnt=0
sum=0
for i in range(n):
    z+=a[i]
    if i%2==1:
        if sum>=0:
            cnt+=(sum+1)
            sum=-1
    else:
        if sum<=0:
            cnt+=(1-sum)
            sum=1
cnt_plus=cnt
ans=min(cnt_plus,cnt_sbst)
print(ans)




### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
sum=0
cnt=0
# 奇数+
for i in range(n):
    sum+=a[i]
    if i%2==0:
        if sum>=0:
            cnt+=(sum+1)
            sum=-1
    else:
        if sum<=0:
            cnt+=(1-sum)
            sum=1
cnt_sbst=cnt
# 奇数-
cnt=0
sum=0
for i in range(n):
    sum+=a[i]
    if i%2==1:
        if sum>=0:
            cnt+=(sum+1)
            sum=-1
    else:
        if sum<=0:
            cnt+=(1-sum)
            sum=1
cnt_plus=cnt
ans=min(cnt_plus,cnt_sbst)
print(ans)
a, b, c=map(int, input().split())
print(max((a+b), (a-b), (a*b)))

### FIXED CODE ###

a, b=map(int, input().split())
d=a+b
e=a-b
f=a*b
print(max(d, e, f))
A,B = input().split()
iA = int(A)
iB = int(B)
fB100 = int(float(B)*100 - iB*100)

ans = iA * iB
ans += (fB100 * iA) // 100
print(ans)

### FIXED CODE ###

A,B = input().split()
iA = int(A)
iB = int(float(B) * 100 + 0.5)

ans = (iA * iB) // 100
print(ans)
n = input()
if n >= 30:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

n = int(input())
if n >= 30:
    print("Yes")
else:
    print("No")
s=input();print(100*max(0,10-int(s[:2]))+int(s[2:]))

### FIXED CODE ###

n,r=map(int,input().split());print(100*max(0,10-n)+r)
n = int(input())
if n < 10:
  ans = n
elif n < 10**2:
  ans = 9
elif n < 10**3:
  h = n-99
  ans = h+9
elif n < 10**5:
  t_t = n - 9998
  ans = t_t + 909
  
print(ans)

### FIXED CODE ###

a,b,c = map(int,input().split())
if b+c<=a:
  ans=0
else:
  ans = (b+c)-a
print(ans)
import math
a, b, c = map(int, input().split())

# 容器に入っている水が半分以下の場合に困る
w = [2]
if a*a*b > 2 * c:
    print(w[4])
    h = (2*c)/(a*a)
    print(math.degrees(math.acos(h/a)))
else:
    h = 2*(a*a*b-c)/(a**2)
    print(math.degrees(math.atan(h/a)))


### FIXED CODE ###

from math import atan, degrees
a, b, x = map(int, input().split())

if 2*x >= a*a*b:
    h = 2*(a*a*b-x)/(a*a)
    print(degrees(atan(h/a)))
else:
    l = 2*(a*a*b-x)/(a*b) - a
    print(degrees(atan(b/(a-l))))
L = []
S = str(input())
Q = int(input())
Ql = [[] for _ in range(Q)] 

for i in range(len(S)):
    L.append(S[i])

for i in range(Q):
    A = input().split()
    Ql[i] = A

for i in range(Q):
    print(L)
    if Ql[i][0] == '1':
        L.reverse()
            
    elif Ql[i][0] == '2':
        if Ql[i][1] == '1':
            L.insert(0, Ql[i][2])
        else:
            L.append(Ql[i][2])

print(''.join(L))

### FIXED CODE ###

from collections import deque

L = deque([])
S = str(input())
q = int(input())
Q = [[] for _ in range(q)] 

for i in range(len(S)):
    L.append(S[i])

for i in range(q):
    A = input().split()
    Q[i] = A

num = 0

for i in range(q):
    if Q[i][0] == '1':
        num ^= 1
    if Q[i][0] == '2':
        if num == 0:
            if Q[i][1] == '1':
                L.appendleft(Q[i][2])
            else:
                L.append(Q[i][2])
        else:
            if Q[i][1] == '2':
                L.appendleft(Q[i][2])
            else:
                L.append(Q[i][2])

if num:
    L.reverse()

print(''.join(L))
from scipy.sparse.csgraph import floyd_warshall
import numpy as np
from itertools import permutations

n,m,r = map(int,input().split())
rr = np.array(list(map(int,input().split()))) - 1

L = np.zeros((m,m),int)
for _ in range(m):
    a,b,c = map(int,input().split())
    L[a-1,b-1] = c

shortest = floyd_warshall(L, directed = False)

ans = float('inf')

for route in permutations(rr,len(rr)):
    ans = min(ans, shortest[route[:-1],route[1:]].sum())
print(int(ans))

### FIXED CODE ###

from scipy.sparse.csgraph import floyd_warshall
import numpy as np
from itertools import permutations

n,m,r = map(int,input().split())
rr = np.array(list(map(int,input().split()))) - 1

L = np.zeros((n,n),int)
for _ in range(m):
    a,b,c = map(int,input().split())
    L[a-1,b-1] = c

shortest = floyd_warshall(L, directed = False)

ans = float('inf')

for route in permutations(rr,len(rr)):
    ans = min(ans, shortest[route[:-1],route[1:]].sum())
print(int(ans))
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n, k = nm()
x = nl()

if 0 in x:
    k -= 1
if n == 1:
    print(x[0])
    exit()

zero = bisect_left(x, 0)
costs = []

for i in range(min(zero - k, 0) + 1, min(zero + k, n - k)):
    if x[i] < 0 and x[i+k-1] > 0:
        costs.append(-2 * x[i] + x[i+k-1])
        costs.append(-1 * x[i] + 2 * x[i+k-1])
    else:
        costs.append(max(abs(x[i]), abs(x[i+k-1])))
    #print(i, x[i], costs)
print(min(costs))

### FIXED CODE ###

import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n, k = nm()
x = nl()

if 0 in x:
    k -= 1
if n == 1:
    print(x[0])
    exit()

zero = bisect_left(x, 0)
costs = []
#print(zero, max(zero - k, 0), min(zero + k, n - k) + 1)
for i in range(max(zero - k, 0), min(zero + k, n - k) + 1):
    if x[i] < 0 and x[i+k-1] > 0:
        costs.append(-2 * x[i] + x[i+k-1])
        costs.append(-1 * x[i] + 2 * x[i+k-1])
    else:
        costs.append(max(abs(x[i]), abs(x[i+k-1])))
    #print(i, x[i], costs)
print(min(costs))
import math 
  
# Function to find modulo inverse of b. It returns  
# -1 when inverse doesn't  
# modInverse works for prime m 
def modInverse(b,m): 
    g = math.gcd(b, m)  
    if (g != 1): 
        # print("Inverse doesn't exist")  
        return -1
    else:  
        # If b and m are relatively prime,  
        # then modulo inverse is b^(m-2) mode m  
        return pow(b, m - 2, m) 
  
  
# Function to compute a/b under modulo m  
def modDivide(a,b,m): 
    a = a % m 
    inv = modInverse(b,m) 
    if(inv == -1): 
        print("Division not defined") 
    else: 
        return (inv*a) % m

MOD = (10 ** 9) + 7
H, W, A, B = list(map(int, input().split(' ')))

DP = []
j = 1
for i in range(1,200002):
    j *= i
    j %= MOD
    DP.append(j)

# print(DP)
def factorial(i):
    if (i == 0):
        return 1
    global DP
    # print(i)
    # print(i, DP[i-1])
    # print(DP[i-1])
    return DP[i-1]

def move2(H, W, A, B):
    numPaths = 0
    h = H-A
    w = W-(W-B)+1
    a = A+1
    pttp = 0
    for b in range(w, W+1):
        # print(h, b, a, W-b+1)
        ttp = (factorial(h+b-2)*modInverse((factorial(h-1)*factorial(b-1))% MOD, MOD)) % MOD
        tpttp = ttp
        ttp -= pttp
        pttp = tpttp
        btp = (factorial(a+(W-b+1)-2)*modInverse((factorial(a-1)*factorial(W-b))% MOD, MOD)) % MOD
        # btp = factorial(a+(W-b+1)-2)//(factorial(a-1)*factorial(W-b))
        numPaths += ttp*btp
    return numPaths

ways = move2(H, W, A, B)
print(ways % (10**9 + 7))

### FIXED CODE ###


# Function to find modulo inverse of b. It returns  
# -1 when inverse doesn't  
# modInverse works for prime m 
def gcd(b, m):
  if b == 0:
    return m
  return gcd(m%b, b)

def modInverse(b,m): 
    g = gcd(b, m) 
    if (g != 1): 
        # print("Inverse doesn't exist")  
        return -1
    else:  
        # If b and m are relatively prime,  
        # then modulo inverse is b^(m-2) mode m  
        return pow(b, m - 2, m) 
  
  
# Function to compute a/b under modulo m  
def modDivide(a,b,m): 
    a = a % m 
    inv = modInverse(b,m) 
    if(inv == -1): 
        print("Division not defined") 
    else: 
        return (inv*a) % m

MOD = (10 ** 9) + 7
H, W, A, B = list(map(int, input().split(' ')))

DP = []
j = 1
for i in range(1,200002):
    j *= i
    j %= MOD
    DP.append(j)

# print(DP)
def factorial(i):
    if (i == 0):
        return 1
    global DP
    # print(i)
    # print(i, DP[i-1])
    # print(DP[i-1])
    return DP[i-1]

def move2(H, W, A, B):
    numPaths = 0
    h = H-A
    w = W-(W-B)+1
    a = A+1
    pttp = 0
    for b in range(w, W+1):
        # print(h, b, a, W-b+1)
        ttp = (factorial(h+b-2)*modInverse((factorial(h-1)*factorial(b-1))% MOD, MOD)) % MOD
        tpttp = ttp
        ttp -= pttp
        pttp = tpttp
        btp = (factorial(a+(W-b+1)-2)*modInverse((factorial(a-1)*factorial(W-b))% MOD, MOD)) % MOD
        # btp = factorial(a+(W-b+1)-2)//(factorial(a-1)*factorial(W-b))
        numPaths += ttp*btp
    return numPaths

ways = move2(H, W, A, B)
print(ways % (10**9 + 7))
import math
import functools
N = int(input())
T = []
for i in range(N):
  T.append(int(input()))
def gcd(A, B):
  while(True):
    if A and B:
      if A > B:
        A = A % B
      else:
        B = B % A
    else:
      return max(A, B)
 
def lcm(A, B):
  return (A * // gcd(A, B)) * b

print(functools.reduce(lcm, sorted(T, reverse=True)))

### FIXED CODE ###

import math
import functools
N = int(input())
T = []
for i in range(N):
  T.append(int(input()))
def gcd(A, B):
  while(True):
    if A and B:
      if A > B:
        A = A % B
      else:
        B = B % A
    else:
      return max(A, B)

def lcm(A, B):
  return (A // gcd(A, B)) * B

print(functools.reduce(lcm, sorted(T, reverse=True)))
import pandas as pd

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

axis = list(range(-1000000, 1000001, 1))
df = pd.DataFrame(axis)
df = df.rename(columns = {0 : 'var'})

res = []

if k == 1:
    print(x)
else:
    for i in range(1, k):

        a = df[df['var'] == x + i]
        a = list(a['var'])
        res.append(a)
        
        a = df[df['var'] == x - i]
        a = list(a['var'])
        res.append(a)
    res.append([x])
    res = sum(res, []) #リスト一段解除
    res = sorted(res) #並び替え
    print(*res)


### FIXED CODE ###

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

res = []
if k == 1:
    print(x)
else:
    for i in range(1, k):
        res.append(x + i)
    for i in range(1, k):
        res.append(x - i)
    res.append(x)
    res = sorted(res)
    print(*res)
W,H,x,y = map(int,input().split())
print(W*H/2)
if W//2 == x && H//2 == y:
    print(1)
else:
    print(0)

### FIXED CODE ###

W,H,x,y = map(int,input().split())

if W/2 == x and H/2 == y:
    ans = 1
else:
    ans = 0
print(W*H/2,ans)
import math
from functools import reduce
def gcd_list(numbers):
    return reduce(math.gcd, numbers)    

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

print(gcd_list(a))

### FIXED CODE ###

import fractions
from functools import reduce
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)    

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

print(gcd_list(a))
int(input()
print(x ** 3)

### FIXED CODE ###

x = int(input())
print(x ** 3)
N,A,B,C = map(int, input().split())

bms = [int(input()) for _ in Range(N)]

def dfs(cur,a,b,c):
    if cur == N:
        s = abs(A-a)+abs(B-b)+abs(C-c)-30 if min(a,b,c) > 0 else 10**9
        return s
    s_0 = dfs(cur+1,a,b,c)
    s_a = dfs(cur+1,a+bms[cur],b,c) + 10
    s_b = dfs(cur+1,a,b+bms[cur],c) + 10
    s_c = dfs(cur+1,a,b,c+bms[cur]) + 10
    return min(s_0,s_a,s_b,s_c)

print(dfs(0,0,0,0))

### FIXED CODE ###

N,A,B,C = map(int, input().split())

bms = [int(input()) for _ in range(N)]

def dfs(cur,a,b,c):
    if cur == N:
        s = abs(A-a)+abs(B-b)+abs(C-c)-30 if min(a,b,c) > 0 else 10**9
        return s
    s_0 = dfs(cur+1,a,b,c)
    s_a = dfs(cur+1,a+bms[cur],b,c) + 10
    s_b = dfs(cur+1,a,b+bms[cur],c) + 10
    s_c = dfs(cur+1,a,b,c+bms[cur]) + 10
    return min(s_0,s_a,s_b,s_c)

print(dfs(0,0,0,0))
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
match = [2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [-1] * (n + 1)

dp[0] = 0
for i in range(1, n + 1):
    for j in a:
        if i < match[j - 1]:
            continue
        else:
            dp[i] = max(dp[i], dp[i - match[j - 1]] + 1)

num = []
k = n
for i in range(dp[n]):
    for j in a:
        if dp[k - match[j - 1]] == dp[k] - 1:
            num.append(j)
            k -= match[j - 1]
            break
print("".join(map(str, num)))

### FIXED CODE ###

n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
match = [2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [-1] * (n + 1)

dp[0] = 0
for i in range(1, n + 1):
    for j in a:
        if i < match[j - 1]:
            continue
        else:
            dp[i] = max(dp[i], dp[i - match[j - 1]] + 1)

num = []
k = n
for i in range(dp[n]):
    for j in a:
        if k >= match[j - 1]:
            if dp[k - match[j - 1]] == dp[k] - 1:
                num.append(j)
                k -= match[j - 1]
                break
print("".join(map(str, num)))
6 727202214173249351
6 5 2 5 3 2

### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split())) #どこに行くかのリスト
now = 0 #どこにいるか
LOG = {}
roop = 0
count = 0

while now not in LOG and count < K:
    LOG.setdefault(now, count)
    now = A[now] -  1
    count += 1

if count < K:
    roop = len(LOG) - LOG[now]
    K = (K - count) % roop
    count = 0
    while count < K:
        now = A[now] -  1
        count += 1

print(now+1) #行った場所を保存
def solve():
    N = int(input())
    a = list(map(int, input().split()))
    s = sum(a)
    q = int(input())
    n = [0 for _ in range(100000)]
    for i in a:
        n[i] += 1
    for _ in range(q):
        b, c = map(int, input().split())
        s += (c - b) * n[b]
        print(s)
        n[c] += n[b]
        n[b] = 0


if __name__ == '__main__':
    solve()


### FIXED CODE ###

def solve():
    N = int(input())
    a = list(map(int, input().split()))
    s = sum(a)
    q = int(input())
    n = [0 for _ in range(100000+1)]
    for i in a:
        n[i] += 1
    for _ in range(q):
        b, c = map(int, input().split())
        s += (c - b) * n[b]
        print(s)
        n[c] += n[b]
        n[b] = 0


if __name__ == '__main__':
    solve()
N,*A=map(int,open(0).read().split())
i=2*sorted(enumerate(A[::2]),lambda x:x[1])[-1][0]
print(A[i]+A[i+1])

### FIXED CODE ###

N,*A=map(int,open(0).read().split())
i=2*sorted(enumerate(A[::2]),key=lambda x:x[1])[-1][0]
print(A[i]+A[i+1])