Harryxun/stf_run huggingface dataset:
def solve(string):
    ins = string.split("\n")
    h, w = map(int, ins[0].split(" "))
    a = [list(map(lambda x: int(x) % 2, _i.split(" "))) for _i in ins[1:]]
    move = []
    for j in range(h):
        for i in range(w):
            if a[j][i] % 2 > 0:
                a[j][i] -= 1
                if i < w - 1:
                    a[j][i + 1] += 1
                    move.append("{} {} {} {}".format(j + 1, i + 1, j + 1, i + 2))
                elif j < h - 1:
                    a[j + 1][i] += 1
                    move.append("{} {} {} {}".format(j + 1, i + 1, j + 2, i + 1))
    return "{}\n{}".format(len(move), "\n".join(move))


if __name__ == '__main__':
    line = input()
    tmp = [line]
    for _ in range(int(line[0])):
        tmp.append(input())
    print(solve('\n'.join(tmp)))


### FIXED CODE ###

h,w = map(int,input().split())
a = []
for i in range(h):
    tmp = list(map(lambda x:int(x)%2,input().split()))
    a.append(tmp)
result = []
 
for i in range(h):
    for j in range(w-1):
        if a[i][j] == 1:
            #a[i][j] == 0
            a[i][j+1] = 1 ^ a[i][j+1]
            result.append((i+1,j+1,i+1,j+2)) 
for i in range(h-1):
    if a[i][w-1] == 1:
        a[i+1][w-1] = 1 ^ a[i+1][w-1]
        result.append((i+1,w,i+2,w))
print(len(result))
for row in result:
    print("{} {} {} {}".format(row[0],row[1],row[2],row[3]))
[H,W]=map(int,input().split())
if (H*W)%2==0:
    print (int((H*W)/2))
else:
    if (H+W)%2==0:
        print (int((H*W+1)/2))
    else:
        print(int((H*W-1)/2))

### FIXED CODE ###

K=int(input())
A=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(A[K-1])
n = int(input())
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
m = 0
for i in range(n):
    m = max(m, sum(a1[:i+1])+sum(b1[i:]))
print (m)

### FIXED CODE ###

x = int(input())
a = int(input())
b = int(input())
print ((x-a)%b)
N=int(input())
A=[2*N]*N
for i in range(1,N//2):
    if N%i==0:
        A[i]=i+N//i-2
print(min(A))


### FIXED CODE ###

import math
N=int(input())
x=N+1
for i in range(1,int(math.sqrt(N))+1):
    if N%i==0:
        x=min(x,i+N//i)
print(x-2)
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

s = input()
k = ni()
keta = 0
for i in range(len(s)):
    if s[i] == "1":
        continue
    else:
        keta = i + 1
        break
if k < keta:
    print("1")
else:
    print(s[keta])


### FIXED CODE ###

import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

s = input()
k = ni()
keta = 0
for i in range(len(s)):
    if s[i] == "1":
        continue
    else:
        keta = i
        break
if k < keta + 1:
    print("1")
else:
    print(s[keta])
n=str(input())
ans=0
ans+=n%10
ans+=n%1000+1
ans+=n%100000+1

### FIXED CODE ###

n=int(input())
ans=min(n,9)
if n>99: ans=min(n-90,909)
if n>9999: ans=n-9000-90
if n>99999: ans=90909
print(ans)
n = int(input())
ans = 0
for i in range(1, n+1)
    ans += i
print(ans)

### FIXED CODE ###

n = int(input())
ans = 0
for i in range(1, n+1):
    ans += i
print(ans)
N = int(input())
li = []
C = 1
while C <= 10**18:
	for i in range(N):
		li.insert(i,int(input())
    	C *= li[i]
if C <= 10**18:
	print(C)
else: print(-1)

    
	
            
  

### FIXED CODE ###

N = int(input())
L = list(map(int,input().split()))
L.sort()
c = 1
for i in range(N):
    c *= L[i]
    if c > 10**18:
        c = -1
        break
print(c)
#

import sys
input=sys.stdin.readline
MOD=10**9+7


def main():
    N,K=map(int,input().split())
    A=list(map(int,input().split()))
    A.sort()
    A2n=[]
    for i in range(0,N,2):
        if A[i]<=0 and A[i+1]<=0:
            A2n.append(A[i]*A[i+1])
        else:
            break

    A.sort(reverse=True)
    ans=1
    if A[0]<=0 and K%2==1:
        for i in range(K):
            ans=(ans*A[i])%MOD
        print(ans)
        exit()
    ni=0
    i=0
    while(K>0):
        if len(A2n)-ni>0 and A[i]*A[i+1]<A2n[ni] and K>=2:
            ans=(ans*A2n[ni])%MOD
            K-=2
            ni+=1
        else:
            ans=(ans*A[i])%MOD
            i+=1
            K-=1
    print(ans)
            
    
    
if __name__=="__main__":
    main()


### FIXED CODE ###

#

import sys
input=sys.stdin.readline
MOD=10**9+7


def main():
    N,K=map(int,input().split())
    A=list(map(int,input().split()))
    if N==1:
        print(A[0])
        exit()
    A.sort()
    A2n=[]
    for i in range(0,N,2):
        if i+1>=N:
            break
        if A[i]<=0 and A[i+1]<=0:
            A2n.append(A[i]*A[i+1])
        else:
            break

    A.sort(reverse=True)
    ans=1
    if A[0]<=0 and K%2==1:
        for i in range(K):
            ans=(ans*A[i])%MOD
        print(ans)
        exit()
    ni=0
    i=0
    while(K>0):
        if i+1<N and len(A2n)-ni>0 and A[i]*A[i+1]<A2n[ni] and K>=2:
                ans=(ans*A2n[ni])%MOD
                K-=2
                ni+=1
        else:
            ans=(ans*A[i])%MOD
            i+=1
            K-=1
    print(ans)
            
    
    
if __name__=="__main__":
    main()
N,K=[int(s) for s in input().split(" ")]
ListH=[int(s) for s in input().split(" ")]

ListH=sorted(ListH,reverse=True)

if N > K:
    for i in range(K):
        ListH.pop(i)

    sum=0
    for i in range(N-K):
        sum+=ListH[i]
else:
    sum=0
    
print(sum)

### FIXED CODE ###

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


if N<=K:
    print(0)
else:
    ListH.sort()
    sum=0
    for i in range(N-K):
        sum+=ListH[i]

    print(sum)
n=int(input())
a=sorted(map(int,input()))
print(a[-1]-a[0])

### FIXED CODE ###

n=int(input())
a=sorted(map(int,input().split()))
print(a[-1]-a[0])
a,b,c,d=map(int,inpyt().split())
print(max(a*b,c*d))

### FIXED CODE ###

a,b,c,d=map(int,input().split())
print(max(a*b,c*d))
def insertionSort(A, n, g, cnt):
    for i in xrange(1,n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j - g
            cnt += 1
        A[j+g] = v
    return A, cnt

def shellSort(A, n):
    cnt = 0
    G = [1]
    for i in range(1,len(A)):
        if 3*G[i-1]+1 < len(A):
            G.append(3*G[i-1]+1)
    G = list(reversed(G[:]))
    #print G
    m = len(G)
    print m
    print ' '.join(map(str,G))
    newA = A[:]
    for i in range(0,m):
        newA, cnt = insertionSort(newA[:],len(A),G[i],cnt)
    return newA, cnt

def main():
    n = int(input())
    A = [int(input()) for i in xrange(n)]
    newA, cnt = shellSort(A, n)
    print cnt
    for i in range(len(newA)):
        print newA[i]
    return 0

if __name__ == '__main__':
    main()

### FIXED CODE ###

def insertionSort(A, n, g, cnt):
    for i in xrange(1,n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j - g
            cnt += 1
        A[j+g] = v
    return A, cnt

def shellSort(A, n):
    cnt = 0
    G = [1]
    idx = 0
    for i in range(1,len(A)):
        if 3*G[idx]+1 < len(A):
            G.append(3*G[idx]+1)
            idx += 1
    G = list(reversed(G[:]))
    #print G
    m = len(G)
    print m
    print ' '.join(map(str,G))
    newA = A[:]
    for i in range(0,m):
        newA, cnt = insertionSort(newA[:],len(A),G[i],cnt)
    return newA, cnt

def main():
    n = int(input())
    A = [int(input()) for i in xrange(n)]
    newA, cnt = shellSort(A, n)
    print cnt
    for i in range(len(newA)):
        print newA[i]
    return 0

if __name__ == '__main__':
    main()
a=int(input())
cnt=0
for i in range(math.inf):
  if a%2==0:
    cnt+=1
    a/=2
  else:
    print(cnt)
    break

### FIXED CODE ###

n=int(input())
for i in range(99):
  if 2**i <= n:
    continue
  else:
    print(2**(i-1))
    break
n,a,b = map(int,input().split())
print(int(n/(a+b))*a + n%(a+b) - (n%(a+b)%a))

### FIXED CODE ###

n,a,b = map(int,input().split())
uni = int(n/(a+b))
if n > (a+b)*uni + a:
  print(a*uni + a)
else:
  print(a*uni + n%(a+b))
# coding: utf-8
# Your code here!
def up(w,h,count):
    if h==-1:
        return count-1
    elif S[h][w]=="#":
        return count-1
    else:
        count=up(w,h-1,count+1)
    return count

def down(w,h,count):
    if h==H:
        return count-1
    elif S[h][w]=="#":
        return count-1
    else:
        count=down(w,h+1,count+1)
    return count
        
def right(w,h,count):
    if w==W:
        return count-1
    elif S[h][w]=="#":
        return count-1
    else:
        count=right(w+1,h,count+1)
    return count

def left(w,h,count):
    if w==-1:
        return count-1
    elif S[h][w]=="#":
        return count-1
    else:
        count=left(w-1,h,count+1)
    return count

H,W=map(int,input().split())
S=[]

for _ in range(H):
    S.append(list(input()))

ans=0
for h in range(H):
    for w in range(W):
        if S[h][w]=="#":
            continue
        ans=max((up(w,h,0)+down(w,h,0)+right(w,h,0)+left(w,h,0)),ans)
        
        """
        if ans==(up(w,h,0)+down(w,h,0)+right(w,h,0)+left(w,h,0)):
            print(h,w)
            print(up(w,h,0),down(w,h,0),right(w,h,0),left(w,h,0))
        """
print(ans+1)

### FIXED CODE ###

# coding: utf-8
# Your code here!
H,W=map(int,input().split())
S=[]
ans=0

for _ in range(H):
    S.append(list(input()))

l=[[0]*W for _ in range(H)]

for h in range(H):
    count=0
    start=0
    for i in range(W):
        if S[h][i]=="#":
            count=0
            start=i+1
        else:
            count+=1
            l[h][i]+=count

for h in range(H):
    count=0
    start=W-1
    for i in range(W)[::-1]:
        if S[h][i]=="#":
            count=0
            start=i
        else:
            count+=1
            l[h][i]+=count

for w in range(W):
    count=0
    start=0
    for i in range(H):
        if S[i][w]=="#":
            count=0
            start=i+1
        else:
            count+=1
            l[i][w]+=count

for w in range(W):
    count=0
    start=H-1
    for i in range(H)[::-1]:
        if S[i][w]=="#":
            count=0
            start=i
        else:
            count+=1
            l[i][w]+=count
            ans=max(ans,l[i][w])

print(ans-3)
n,k=map(int,input().split())
c=0
for b in range(k,n+1):
  p=int(n/b)
  r=n%b
  c+=(b-k)*p
  if r>=k:
    c+=r-k+1
if k==0:
  print(c-1)
else:
  print(c)

### FIXED CODE ###

n,k=map(int,input().split())
c=0
if k==0:
 print(n**2)
else:
  for b in range(k,n+1):
    p=int(n/b)
    r=n%b
    c+=(b-k)*p
    if r>=k:
      c+=r-k+1
  print(c)
s=input()
ans="CODEFESTIVAL2016"
ans=0
for i in range(16):
	if s[i]!=ans[i]:
		ans+=1
print(ans)

### FIXED CODE ###

s=input()
ans="CODEFESTIVAL2016"
anss=0
for i in range(16):
	if s[i]!=ans[i]:
		anss+=1
print(anss)
import math
from decimal import *

k, a, b = map(int, input().split())
inc = a - b
if inc < 0:
    if k <= a:
        print(1)
    else:
        print(-1)
    exit()

getcontext().prec = 500
print(math.ceil(Decimal(k-a) / Decimal(inc))*2+1)



### FIXED CODE ###

import math

k, a, b = map(int, input().split())
inc = a - b
if k <= a:
    print(1)
elif inc < 0:
    if k <= a:
        print(1)
    else:
        print(-1)
elif inc == 0:
    print(-1)
else:
    from decimal import *
    getcontext().prec = 500
    print(math.ceil(Decimal(k-a) / Decimal(inc))*2+1)
n , m = map(int, input().split(' '))
s = [0,2,5,5,4,5,6,3,7,6]
a = list(map(int, input().split(' ')))
r = []
for i in range(len(a)):
    r.append([s[a[i]],a[i]])
r.sort()
d = [0]
for i in range(n):
    d.append(-1)
for i in range(n+1):
    j = 0
    while j < len(a):
        if i -s[r[j][1]] < 0:
            j += 1
        elif d[i-s[r[j][1]]] >= 0:
            d[i] = d[i-s[r[j][1]]] +1
            break
        else:
            j+= 1
result = []
a.sort(reverse = True)
while n > 0:
    j = 0
    while j < len(a):
        if d[n-s[a[j]]] +1 == d[n]:
            result.append(a[j])
            n -= s[a[j]]
        else:
            j += 1
            
print(''.join(list(map(str, result))))




### FIXED CODE ###

n , m = map(int, input().split(' '))
s = [0,2,5,5,4,5,6,3,7,6]
a = list(map(int, input().split(' ')))
r = []
for i in range(len(a)):
    r.append([s[a[i]],a[i]])
r.sort()
d = [-1]*(n+1)
d[0] = 0
for i in range(1,n+1):
    j = 0
    while j < len(a):
        if i-s[r[j][1]] < 0:
            j += 1
        elif d[i-s[r[j][1]]] >= 0:
            d[i] = d[i-s[r[j][1]]] +1
            break
        else:
            j+= 1
result = []
a.sort(reverse = True)
while n > 0:
    j = 0
    while j < len(a):
        if n < s[a[j]]:
            j += 1
        elif d[n-s[a[j]]] +1 == d[n]:
            result.append(a[j])
            n -= s[a[j]]
            break
        else:
            j += 1
print(''.join(list(map(str, result))))
# -*- coding: utf-8 -*-
n = int(raw_input())
s = str(raw_input())

l = s.strip()
memo=[]
for i in range(0,n):
    memo.append(-1)
memo[0]=0

def dfs(i):
    if i < 1:
        return 0

    global memo
    if memo[i] != -1:
        return memo[i]
    if s[i] == ".":
        memo[i] = min(s[:i].count("#"), dfs(i-1)+1)
    else:
        memo[i] = min(dfs(i-1), s[:i].count(".")+1)
    return memo[i]

print dfs(n-1)

### FIXED CODE ###

# -*- coding: utf-8 -*-
n = int(raw_input())
s = str(raw_input())

ans=[]
black=[]
for i in range(0,n):
    ans.append(-1)
    black.append(-1)
ans[0]=0
if s[0]==".":
    black[0]=0
else:
    black[0]=1

for i in range(1,n):
    if s[i] == ".":
        black[i] = black[i-1]
        ans[i] = min(black[i-1], ans[i-1]+1)
    else:
        black[i] = black[i-1] + 1
        ans[i] = min(ans[i-1], black[i-1]+1)

print ans[n-1]
import sys
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
N = int(input())
M = [int(input()) for i in range(N)]

for m in range(M):
  if M[m] in A:
    A[M[m]] = 0
  elif M[m] in B:
    B[M[m]] = 0
  elif M[m] in C:
    C[M[m]] = 0

for t in range(3):
  if A[t] + B[t] + C[t] ==0:
    print("Yes")
    sys.exit()
if sum(A) == 0 or sum(B) == 0 or sum(c) ==0:
  print("Yes")
  sys.exit()
elif A[0] + B[1] + C[2] == 0:
  print("Yes")
  sys.exit()
elif A[2] + B[1] +C[0] == 0:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

import sys
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
N = int(input())
M = [int(input()) for i in range(N)]
for m in range(len(M)):
	if M[m] in A:
		A[A.index(M[m])] = 0
	elif M[m] in B:
		B[B.index(M[m])] = 0
	elif M[m] in C:
		C[C.index(M[m])] = 0
for t in range(3):
	if A[t] + B[t] + C[t] == 0:
		print('Yes')
		sys.exit()
if sum(A) == 0 or sum(B) == 0 or sum(C) ==0:
	print('Yes')
	sys.exit()
elif A[0] + B[1] + C[2] == 0:
	print('Yes')
	sys.exit()
elif A[2] + B[1] +C[0] == 0:
	print('Yes')
else:
	print('No')
x, y, z = input().split()
a = int(x)
b = int(y)
c = int(z)

count = 0
num = a
    
while num <= b:
    if c % num == 0:
        count += 1
    else:
        pass
    num += 1
    
print(count)


### FIXED CODE ###

x, y = input().split()
a = int(x)
b = int(y)

d = int(a / b)
e = int(a % b)
f = "{0:.8f}".format(a / b)

print(d, e, f)
import numpy as np
n,m,x = map(int,input().split())
c = []
for i in range(n):
  a = [int(i) for i in input().split()]
  c.append(a)
  
c = np.array(c)
ans = float('inf')
for i in range(1,2**n):
  chk = [0]*m
  cost = 0
  for j in range(n):
    if (i>>j)&1 == 1:
      cost += c[j][0]
      chk += c[j][1:]
  if min(chk) >= x:
    ans = min(ans,cost)
  
if ans == float('inf'):
  ans = -1
print(ans)


### FIXED CODE ###

s = input()
t = input()
if s == t[:len(t)-1]:
  print('Yes')
else:
  print('No')
n=int(input().split())
dic=set()
dic|={n}
i=1
while True:
  if n%2==0:
    n=n//2
  else:
    n=3*n+1
  if n in dic:
    print(i+1)
    break
  else:
    dic|={n}
    i+=1


### FIXED CODE ###

s = int(input())

used = set()
used |= {s}
count = 1

while True:
    if s % 2 == 0: s//=2
    else:s=3*s+1
    if s in used:
        print(count+1)
        break
    else:
        used |= {s}
        count += 1
def inverse(a):
    return pow(a, mod - 2, mod)

def main():
    n = int(input())
    a = [0] * n
    b = [0] * n
    for i in range(n):
        x, y = tuple(map(int, input().split()))
        a[i] = x
        b[i] = y
    from collections import defaultdict
    d = defaultdict(lambda: 0)
    for i in range(n):
        for j in range(i+1, n):
            t = a[i] - a[j]
            y = b[i] - b[j]
            tmp = 1 if (t > 0 or (t == 0 and y > 0)) else -1
            d[(tmp * t, tmp * y)] += 1

    print(n-max(d.values()))

main()

### FIXED CODE ###

def inverse(a):
    return pow(a, mod - 2, mod)

def main():
    n = int(input())
    a = [0] * n
    b = [0] * n
    for i in range(n):
        x, y = map(int, input().split())
        a[i] = x
        b[i] = y
    from collections import defaultdict
    if n == 1:
        print(1)
        return 
    d = defaultdict(lambda: 0)
    for i in range(n):
        for j in range(i+1, n):
            t = a[i] - a[j]
            y = b[i] - b[j]
            tmp = 1 if (t > 0 or (t == 0 and y > 0)) else -1
            d[(tmp * t, tmp * y)] += 1

    print(n-max(d.values()))

main()
N = int(input())
T, A  map( int, input().split())
H = list( map( int, input.split()))
         
K = []
Ksorted=[]
tmp=[]

for i in range(N):
  tmp.append( T - H[i] * 0.006)
  K.append(abs( A - tmp[i]))
  Ksorted = sorted(K)
  
T = K.index(Ksorted[0])
print(T + 1)

### FIXED CODE ###

N = int(input())
T, A = map( int, input().split())
H = list( map( int, input().split()))
         
K = []
Ksorted=[]
tmp=[]
 
for i in range(N):
  tmp.append( T - H[i] * 0.006)
  K.append(abs( A - tmp[i]))
  Ksorted = sorted(K)
  
T = K.index(Ksorted[0])
print(T+1)
from collections import Counter

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

cntA = Counter(A)
cntB = Counter(B)

V = set(A) & set(B)
mx = max(min(cntA[v], cntB[v]) for v in V)

if mx > N // 2:
    print('No')
    exit()

a = 1 / 0
print('No')


### FIXED CODE ###

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

AB = [(a, i, 0) for i, a in enumerate(A)] + [(b, i, 1) for i, b in enumerate(B)]
AB.sort()

X = AB[:N]
Y = AB[N:]

if any(x[0] == y[0] for x, y in zip(X, Y)):
    print('No')
    exit()

swapA = []
swapB = []
ans = [-1] * N

for (_, i, sx), (_, j, sy) in zip(X, Y):
    if sx == sy == 0:
        swapA.append((i, j))
    elif sx == sy == 1:
        swapB.append((i, j))
    else:
        if sx == 0:
            ans[i] = B[j]
        else:
            ans[j] = B[i]

for (i, j), (x, y) in zip(swapA, swapB):
    ans[i] = B[x]
    ans[j] = B[y]

    if A[i] == ans[i] or A[j] == ans[j]:
        ans[i], ans[j] = ans[j], ans[i]

print('Yes')
print(*ans)
input1 = input()
x = []
y=[]
check=0

for i in input1:
    if i!=" " and check==0:
        x.append(i)
    elif i==" ":
        check=1
    elif i!=" " and check==1:
        check==1
        y.append(i)
xstring=''.join(x)
ystring=''.join(y)

xint=int(xstring)
yint=int(ystring)

if yint==1:
    print(0)
else:
    cnt=0
    while ((xint-1)*(cnt))+xint<yint:
        cnt=cnt+1
    cnt=cnt+1
    5print(cnt)
    

    


### FIXED CODE ###

s = input().split(" ")
a = int(s[0])
b = int(s[1])
c = 1
ans = 0

while c < b:
	c += a - 1
	ans += 1

print(ans)
class SegmentTree:
    def __init__(self,orig,func,unit):
        _len= len(orig)
        self.func = func
        self.size = 1 << (_len-1).bit_length()
        self.tree = [unit] * self.size + orig + [unit] *(self.size-_len)
        self.unit = unit
        
        for i in range(self.size -1,0,-1):
            self.tree[i] = func(self.tree[i*2], self.tree[i*2+1])
            
    def update(self, i, v):
        i+=self.size
        self.tree[i] = v
        while i:
            i//=2
            self.tree[i]=self.func(self.tree[i*2],self.tree[i*2+1])
    
    def find(self,l,r):
        l+=self.size
        r+=self.size
        ret=self.unit
        while l<r:
            if l&1:
                ret = self.func(ret,self.tree[l])
                l+=1
            if r&1:
                r-=1
                ret=self.func(ret,self.tree[r])
            l//=2
            r//=2
        return ret
      
import sys
input = sys.stdin.readline
from operator import or_

input()
seg = SegmentTree([1 << ord(x) - 97 for x in input()[:-1]], or_, 0)
ans = []
for _ in range(int(input())):
  f, x, y = input().split()
  if f == "1":
    seg.update(int(x) - 1, 1 << ord(y) - 97)
  else:
    ans.append(bin(seg.find(int(x) - 1, int(y))).count("1"))
print(*ans)

### FIXED CODE ###

n=int(input())
print(n//2+n%2)
from collections import Counter

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

odd = v[::2]
even = v[1::2]

odd_c = Counter(odd).most_common(2)
even_c = Counter(even).most_common(2)

if len(set(v)) == 1:
    print(int(v/2))
else:
    if odd_c[0][1] != even_c[0][1]:
        print(n-odd_c[0][1]-even_c[0][1])
    else:
        print(n-max(odd_c[0][1]-even_c[1][1], odd_c[1][1]-even_c[0][1]))

### FIXED CODE ###

from collections import Counter


def solve(V):
    n = len(V)
    ac = Counter(V[::2]).most_common(2)
    bc = Counter(V[1::2]).most_common(2)

    if ac[0][0] != bc[0][0]:
        return n - ac[0][1] - bc[0][1]
    else:
        if len(bc) == 1 or len(ac) == 1:
            return n // 2
        else:
            return n - max(ac[0][1] + bc[1][1], ac[1][1] + bc[0][1])


if __name__ == "__main__":
    n = int(input())
    l = input()
    print(solve(l.split(" ")))
n=int(input())
a=list(map(int,input().split()))
c=0
l=[]
for i in range(1,n):
  l.append(a[i]-a[i-1])
p=l.pop(0)
while len(l)!=0:
  if p!=0:
    p=l.pop(0)
  if p==0:
    c+=1
    while l[0]==0 and l[1]==0:
      p=l.pop(0)
      p=l.pop(0)
      c+=1
    if l[0]==0:
      p=l.pop(0)
      p=l.pop(0)
    else:
      p=l.pop(0)
print(c)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
c=0
l=[]
for i in range(1,n):
  l.append(a[i]-a[i-1])
if len(l)==1 and l[n-2]==0:c+=1
if len(l)>1 and l[n-2]==0 and l[n-3]!=0:c+=1
p=l.pop(0)
while len(l)!=0:
  if p!=0:
    p=l.pop(0)
  else:
    c+=1
    while len(l)>1:
      if l[0]==0 and l[1]==0:
        p=l.pop(0)
        p=l.pop(0)
        c+=1
      else:
        break
    while len(l)>0:
      if l[0]==0:
        p=l.pop(0)
      else:
        p=l.pop(0)
        break
print(c)
inf = 2019
L, R = map(int, input().split())
ans = 2018
df = R - L
if df < 2019:
for i in range(L, R):
    for j in range(i + 1, R + 1):
        tmp = int((i%inf * j%inf) % inf)
        ans = min(ans, tmp)
    if ans == 0:
        break

print(ans)

### FIXED CODE ###

inf = 2019
L, R = map(int, input().split())
ans = 0
df = R - L
if df < 2019:
    L = L % inf
    R = L + df
    ans = 2019
    for i in range(L, R):
        for j in range(i + 1, R + 1):
            tmp = int((i * j) % inf)
            ans = min(ans, tmp)

print(ans)
yandy
n = int(input())
t = [int(i) for i in input().split()]
m = int(input())

ans = sum(t)
for i in range(m):
    p, x = map(int, input().split())
    print(ans - t[p-1] + x)


### FIXED CODE ###

n=int(input())
t=[0]+[int(i) for i in input().split()]
m=int(input())
p=[[int(j) for j in input().split()] for i in range(m)]

total=sum(t)
for i in range(m):
  print(total-t[p[i][0]]+p[i][1])
def sum_dic(dic):
    ans=0
    for i in dic:
        ans+=dic[i]*i
    return ans

n=int(input())
arr=[int(i) for i in input().strip().split(" ")]
t=int(input())
dic={}
for i in arr:
    dic[i]=dic.get(i,0)+1
    

for _ in range(t):
    a,b=[int(i) for i in input().split(" ")]
    if b in dic:
        dic[b]+=dic[a]
    else:
        dic[b]=dic[a]
    dic[a]=0
    print(sum_dic(dic))

### FIXED CODE ###

n=int(input())
arr=[int(i) for i in input().strip().split(" ")]
t=int(input())
dic={}
sum_array=0
for i in arr:
    dic[i]=dic.get(i,0)+1
    sum_array+=i
    

for _ in range(t):
    a,b=[int(i) for i in input().split(" ")]
    if a not in dic:
        print(sum_array)
        continue
    if b in dic:
        dic[b]+=dic[a]
    else:
        dic[b]=dic[a]
    
    sum_array+=dic[a]*(b-a)
    print(sum_array)
    dic[a]=0