Harryxun/stf_run huggingface dataset:
import numpy as np

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

array = np.array(lst)
po_array = array[array>=0]
ne_array = np.sort(abs(array[array<0]))

if len(po_array) >= len(ne_array):
    long_array = po_array
    short_array = ne_array
else:
    long_array = ne_array
    short_array = po_array

if len(short_array) > k:
    min_len = k
else:
    min_len = len(short_array)
        
if min_len == 0:
    print(long_array[k-1])
else:
    min_dist = 10**10
    for i in range(min_len):
        if i == k-1:
            dist = short_array[i]
        else:
            dist = short_array[i]*2 + long_array[k-i-2]
        if min_dist > dist:
            min_dist = dist
    if len(long_array) >= k:
        if min_dist > long_array[k-1]:
            min_dist = long_array[k-1]
    print(min_dist)

### FIXED CODE ###

import numpy as np

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

array = np.array(lst)
po_array = array[array>=0]
ne_array = abs(array[array<0])
ne_array.sort()

if len(po_array) >= len(ne_array):
    long_array = po_array
    short_array = ne_array
else:
    long_array = ne_array
    short_array = po_array

if len(short_array) > k:
    min_len = k
else:
    min_len = len(short_array)
        
if min_len == 0:
    print(long_array[k-1])
else:
    min_dist = 10**10
    for i in range(min_len):
        dist = 10**10
        if i == k-1:
            dist = short_array[i]
        elif k-i-1 <= len(long_array): 
            dist = min(short_array[i]*2 + long_array[k-i-2], short_array[i] + long_array[k-i-2]*2)
        if min_dist > dist:
            min_dist = dist
    if len(long_array) >= k:
        if min_dist > long_array[k-1]:
            min_dist = long_array[k-1]
    print(min_dist)
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

a, b = map(int, raw_input().split())
g = gcd(a,b)
l = a*b/g
print l

### FIXED CODE ###

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

n = int(raw_input())
a = map(int, raw_input().split())
l = a[0]

for i in range(1,len(a)):
    b = a[i]
    g = gcd(l,b)
    l = l*b/g
print l
n,q=map(int,input().split())

cost=[0]*n
edge = [[] for _ in range(n)]
for _ in range(n-1):
    a,b=map(int,input().split())
    a,b=a-1,b-1
    edge[a].append(b)
    edge[b].append(a)

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

from collections import deque

visited=[-1]*n
visited[0]=0
d=deque([0])
f=cost[0]

def dfs(n,c):

    cost[n]+=c
    tmp=cost[n]
    visited[n]=0

    for v in edge[n]:
        if visited[v]==-1:
            dfs(v,tmp)
    

dfs(0,0)

print(*cost)

### FIXED CODE ###

import sys #追加
sys.setrecursionlimit(500*500)

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

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

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

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


visited=[-1]*n


def dfs(n,c):

    cost[n]+=c
    tmp=cost[n]
    visited[n]=0

    for v in edge[n]:
        if visited[v]==-1:
            dfs(v,tmp)
    

dfs(0,0)

print(*cost)
n = raw_input()
nums = map(int, raw_input().split())
print " ".join(map(str, nums.reverse()))

### FIXED CODE ###

n = raw_input()
nums = map(int, raw_input().split())
nums.reverse()
print " ".join(map(str, nums))
N, K = map(int, input().split())
h = [0]*N

for n in range(N):
    h[n] = int(input())
    
h.sort()

tree = h[:K]
height = []
height.append(tree[-1]-tree[0])

for n in range(K,N):
    tree.pop(0)
    tree.append(h[n])
    height.append(tree[-1]-tree[0])  

print(min(height))

### FIXED CODE ###

D = int(input())

if D == 25:
  print('Christmas')
  
elif D == 24:
  print('Christmas Eve')
  
elif D == 23:
  print('Christmas Eve Eve')
  
else:
  print('Christmas Eve Eve Eve')
X,N = map(int,input().split())
P = list(map(int,input().split()))

if P == [] or X not in P:
  print(X)
else:
  for i in range(X-1,0,-1):
    if i not in P:
      a = abs(X - i)
      break
  for j in range(X+1,max(P)+2):
    if j not in P:
      b = abs(j - X)
      break
      
if a <= b:
  print(i)
else:
  print(j)

### FIXED CODE ###

X,N = map(int,input().split())
P = list(map(int,input().split()))

if N == 0:
  print(X)
else:
  for i in range(X,-2,-1):
    if i not in P:
      a = abs(X - i)
      break
  for j in range(X+1,102):
    if j not in P:
      b = abs(j - X)
      break
  if a <= b:
    print(i)
  else:
    print(j)
a, b = map(int,input().split())
if (a * b) % 2 == 0:
  print("Even")
else
  print("Odd")

### FIXED CODE ###

a, b = map(int,input().split())
if (a * b) % 2 == 0:
  print("Even")
else:
  print("Odd")
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

h,w=map(int,input().split())
a=[input() for i in range(h)]

cnt=0

itta=[[float('inf')]*w for i in range(h)]

d=deque()
aaa=d.append
for i in range(h):
    for j in range(w):
        if a[i][j]=="#":
            aaa([i,j])
            itta[i][j]=0

# print(d)
# print(itta)

while d:
    cnt+=1
    for l in range(len(d)):
        nh,nw=d.popleft()
        for i in range(4):
            d1,d2=direction[i]
            if 0<=nh+d1<h and 0<=nw+d2<w:
                if itta[nh+d1][nw+d2]==float('inf'):
                    itta[nh+d1][nw+d2]=cnt
                    aaa([nh+d1,nw+d2])
    # print(d)

# print(itta)
print(cnt-1)

### FIXED CODE ###

import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
# from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

h,w=map(int,input().split())
a=[input() for i in range(h)]

cnt=0

itta=[[10**9]*w for i in range(h)]

d=deque()
aaa=d.append
for i in range(h):
    for j in range(w):
        if a[i][j]=="#":
            aaa([i,j])
            itta[i][j]=0

# print(d)
# print(itta)

while d:
    cnt+=1
    for l in range(len(d)):
        nh,nw=d.popleft()
        for i in range(4):
            d1,d2=direction[i]
            if 0<=nh+d1<h and 0<=nw+d2<w:
                if itta[nh+d1][nw+d2]==10**9:
                    itta[nh+d1][nw+d2]=cnt
                    aaa([nh+d1,nw+d2])
    # print(d)

# print(itta)
print(cnt-1)
s=input()
t=input()
count=0
for i in range(3):
    if s(i)=t(i):
      count+=1
print(count)

### FIXED CODE ###

s=input()
t=input()
count=0
for i in range(3):
    if s[i]==t[i]:
      count+=1
print(count)
N,T = map(int,input().split())
for i in range(N):
  c,t = list(map(int,input()))
a = 1000
for i in range(N):
  if t <= T:
    a = min(a,c)
if a = 1000:
  print("TLE")
else:
  print(a)

### FIXED CODE ###

N,T = map(int,input().split())

ct = [list(map(int,input().split())) for i in range(N)]

c = []
t = []

for i in range(N):
    c.append(ct[i][0])
    t.append(ct[i][1])

minc = 10000

for i in range(len(c)):
    if t[i] <= T and c[i] < minc:
        minc = c[i]

if minc == 10000:
    print("TLE")
else:
    print(minc)
n, k = map(int, input().split())
ans = n
done = [n]

if k == 1 or n == k:
    print(0)
elif n > k:
    r = n % k
    print(k-r)
elif n < k:
    print(k%n)

### FIXED CODE ###

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

if n == 0 or k == 1:
    print(0)
else:
    if n > k:
        n %= k
    print(min(n, k-n))
N = int(input())
a = [int(input()) for i in range(N)]
flag = True

for i in range(N):
  if a[N-1] < a[i]:
    flag = False

if flag:
  print('Yay!')
else:
  print(':(')


### FIXED CODE ###

a = [int(input()) for i in range(6)]
flag = True

for i in range(6):
  for j in range(i+1, 6):
    if abs(a[i] - a[j]) > a[5]:
      flag = False

if flag:
  print('Yay!')
else:
  print(':(')
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)


def main():
    s = input()
    S = list(s)
    A = list(reversed(list("zyxwvutsrqponmlkjihgfedcba")))
    for i in range(26):
        if A[i] not in S:
            S.append(A[i])
            print(*S, sep="")
            return
    else:
        B = []
        for s in S:
            B.append(ord(s))
        for i in range(25):
            if B[25 - i] > B[25 - i - 1]:
                continue
            else:
                k = 25 - i - 1
        if k == 0:
            print(-1)
            return
        a = S[k - 1]
        S = S[: k - 1]
        for i in range(26):
            if A[i] not in S:
                if ord(A[i]) > ord(a):
                    S.append(A[i])
                    print(*S, sep="")
                    return


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)


def main():
    S = input()
    A = set(chr(ord("a") + x) for x in range(26))
    if len(S) < 26:
        se = A - set(S)
        x = min(se)
        print(S + x)

    else:
        if S == "".join(sorted(A, reverse=True)):
            print(-1)
            return
        else:
            c = []
            S = list(S)
            while True:
                x = S[-1]
                if not c or (x > max(c)):
                    c.append(S.pop())
                    continue
                y = min(ch for ch in c if ch > x)
                S = "".join(S[:-1]) + y
                print(S)
                return


if __name__ == "__main__":
    main()
K, X = map(int, input())
print("Yes" if 500*K>=X else "No")

### FIXED CODE ###

K, X = map(int, input().split())
print("Yes" if 500*K>=X else "No")
A,B,K =[int(_) for _ in input().split()]

def fgcd(a,b):
    while b:
        a,b = b,a%b
    return a

igcd = fgcd(A,B)
if igcd == 1:
    print(1)
else:
    aP = (2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97)
    aD =[igcd,1]
    for eP in aP:
        if igcd < eP:
            break
        if igcd % eP == 0:
            i = 1
            while igcd % (eP**i) == 0 :
                aD.append(eP**i)
                aD.append(igcd // (eP ** i))
                i += 1
    aD = sorted(list(set(aD)),reverse=True)
    print(aD[K-1])


### FIXED CODE ###

A,B,K =[int(_) for _ in input().split()]

iC = 0
for i in range(100,0,-1):
    if A % i == 0 and B % i ==0:
        iC += 1
        if K == iC:
            print(i)
            exit()
H, W = map(int, input().split())
a = ["" for i in range(N)]
for i in range(H):
    a[i] = input()
    
print("#" * (W + 2))
for i in range(H):
    print("#" + a[i] + "#")
print("#" * (W + 2))

### FIXED CODE ###

H, W = map(int, input().split())
a = ["" for i in range(H)]
for i in range(H):
    a[i] = input()
    
print("#" * (W + 2))
for i in range(H):
    print("#" + a[i] + "#")
print("#" * (W + 2))
N=int(input())
A=list(map(int,input().split()))
AA=sorted(A)
li=[]
li_i=[]
for i in range(len(A)):
  if A[i]!=AA[i]:
    li_i.append(i)
    li.append(A[i])
    if len(li_i)>2:
      ans="NO"
      break
s=li_i[0]
t=li_i[1]
A[s]=li[1]
A[t]=li[0]
if A==AA:
  ans="YES"
else:
  ans="NO"
print(ans)
    
    
    
    

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
AA=sorted(A)
li=[]
for i in range(N):
  if A[i]!=AA[i]:
    li.append(A[i])
if len(li)>2:
  print("NO")
else:
  print("YES")
N = int(input())
C = [list(map(int,input().split())) for i in range(N)]
C.sort()
ans0 = 0
ans1 = 0
ans2 = 0
AM = []
Am = []
BM = []
Bm = []
for i in range(N):
    ans0 += C[i][0]
    ans1 += C[i][1]
    Min = min(C[i][0],C[i][1])
    Max = max(C[i][0],C[i][1])
    ans2 += Min
    if Min == C[i][0]:
        Am.append(C[i][0])
        BM.append(C[i][1])
    else:
        AM.append(C[i][0])
        Bm.append(C[i][1])
ans3 = sum(sorted(A+B)[:N])
if ans3 == ans2:
    ans3 += min(min(AM)-max(Am),min(BM)-max(Bm))
    
ans = min(ans0,ans1,ans3)
print(ans)

### FIXED CODE ###

N = int(input())
A = []
B = []
Sa = 0
Sb = 0
for i in range(N):
    a,b = map(int,input().split())
    A.append([a,i])
    B.append([b,i])
    Sa += a
    Sb += b
C = sorted(A+B)
ind = []
ans = 0
for i in range(N):
    ind.append(C[i][1])
    ans += C[i][0]
ind = set(ind)
if len(ind) == N:
    if C[N-1][1] != C[N][1]:
        ans += C[N][0]-C[N-1][0]
    else:
        ans += min(C[N][0]-C[N-2][0],C[N+1][0]-C[N-1][0])
ans = min(Sa,Sb,ans)
print(ans)
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

A, B, C = MAP()

if any(x%2 for x in [A, B, C]):
	print(0)
	exit()
elif A == B == C:
	print(-1)
	exit()

cnt = 0
while all(x%2 == 0 for x in [A, B, C]):
	A, B, C = (B+C)//2, (A+C)//2, (A+B)//2
	ans += 1

print(ans)



### FIXED CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

A, B, C = MAP()

if any(x%2 != 0 for x in [A, B, C]):
	print(0)
	exit()

l = [(A, B, C)]

flg = True
cnt = 0
while 1:
	a = (B+C)/2
	b = (A+C)/2
	c = (A+B)/2
	if any(x%1 != 0 for x in [a, b, c]):
		print(cnt)
		exit()
	elif (a, b, c) in l:
		print(-1)
		exit()
	else:
		A, B, C = a, b, c
		l.append((A, B, C))
		cnt += 1
N,M=map(int,input().split())
keep=[]
lis=[]
ac=[0]*N
wa=[0]*N
WA=0
for i in range(M):
    ps=input().split()
    keep.append(ps)
    
for j in range(M):
    if keep[j][1]=="AC":
        print(int(keep[j][0]-1))
        ac[int(keep[j][0]-1)]=1
    elif ac[int(keep[j][0]-1)]==0:
        wa[int(keep[j][0]-1)]+=1
AC=sum(ac)
for j in range(M):
    WA+=ac[j]*wa[j]
    
print(AC,WA)

### FIXED CODE ###

N,M=map(int,input().split())
keep=[]
lis=[]
ac=[0]*N
wa=[0]*N
WA=0
for i in range(M):
    ps=input().split()
    keep.append(ps)
    
for j in range(M):
    if keep[j][1]=="AC":
        ac[int(keep[j][0])-1]=1
    elif ac[int(keep[j][0])-1]==0:
        wa[int(keep[j][0])-1]+=1
AC=sum(ac)
for k in range(N):
    WA+=ac[k]*wa[k]
    
print(AC,WA)
from sys import stdin
n,k = map(int,stdin.readline().split())
arr = sorted(list(map(int,stdin.readline().split())),key=lambda x:abs(x))
mod = 10**9+7
pos,neg = [],[]
for i in arr:
    if i>=0:
        pos.append(i)
    else:
        neg.append(i)
if not len(pos):
    ans = 1
    if k%2:
        for i in range(k):
            ans *= neg[i]
            ans %= mod
    else:
        for i in range(k):
            ans *= neg[-1-i]
            ans %= mod
else:
    ans = 1
    i=len(pos)-1
    j=len(neg)-1
    pro = 1
    for r in range(k):
        pro *= pos[i]
        pro %= mod
        i -= 1
    ans = max(ans,pro)
    while i < len(pos)-1 and j > 0:
        if neg[j]*neg[j-1]>pos[i]*pos[i+1]:
            pro *= pow(pos[i]*pos[i+1],mod-2,mod)
            pro %= mod
            pro *= neg[j]*neg[j-1]
            pro %= mod
            ans = max(ans,pro)
            i += 2
            j -= 2
        else:
            break
print(ans)


### FIXED CODE ###

from sys import stdin
n,k = map(int,stdin.readline().split())
arr = sorted(list(map(int,stdin.readline().split())),key=lambda x:abs(x))
mod = 10**9+7
pos,neg = [],[]
for i in arr:
    if i>=0:
        pos.append(i)
    else:
        neg.append(i)
if not len(pos):
    ans = 1
    if k%2:
        for i in range(k):
            ans *= neg[i]
            ans %= mod
    else:
        for i in range(k):
            ans *= neg[-1-i]
            ans %= mod
else:
    ans = 1
    i=len(pos)-1
    j=len(neg)-1
    val = 0
    if n==k:
        for x in arr:
            ans *= x
            ans %= mod
    else:
        if k%2:
            ans *= pos[i]
            i -= 1
            val += 1
        while val != k:
            if i<1:
                ans *= neg[j]*neg[j-1]
                ans %= mod
                j -= 2
            elif j<1:
                ans *= pos[i]*pos[i-1]
                ans %= mod
                i -= 2
            else:
                if pos[i]*pos[i-1]>neg[j]*neg[j-1]:
                    ans *= pos[i]*pos[i-1]
                    ans %= mod
                    i -= 2
                else:
                    ans *= neg[j]*neg[j-1]
                    ans %= mod
                    j -= 2
            val += 2
print(ans)
n = int(input())
p = [int(i) for i in input().split()]
'''
i == x となる点で、i+1とスワップする
境界に注意
'''
ans = 0
for i in range(n):
    if i < n and p[i] == i+1:
        p[i+1] = p[i]
        ans += 1
    elif i == n and p[i] == i+1:
        ans += 1
print(ans)

### FIXED CODE ###

n = int(input())
p = [int(i) for i in input().split()]
'''
i == x となる点で、i+1とスワップする
境界に注意
'''
ans = 0
for i in range(n):
    if i < n-1 and p[i] == i+1:
        p[i+1] = p[i]
        ans += 1
    elif i == n-1 and p[i] == i+1:
        ans += 1
print(ans)
import sys
input = sys.stdin.readline
import numpy as np
base_list = np.array(['A','B','C','D','E','F','G','F','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'])
dict_list = []
dict_list.append(base_list)
for i in range(25):
    tmp_char = dict_list[i][0]
    tmp_list = dict_list[i][1:]
    tmp_list = np.append(tmp_list,tmp_char)
    dict_list.append(tmp_list)

def print_ans(N, sr):
    """Test Case
    >>> print_ans(2, ['A', 'B', 'C', 'X', 'Y', 'Z'])
    CDEZAB
    >>> print_ans(0, ['A', 'B', 'C','X', 'Y', 'Z'])
    ABCXYZ
    """
    idx_list = []
    for s in sr:
        tmp = np.where(base_list == s)[0]
        idx_list.append(int(tmp))
    print(''.join(dict_list[N][idx_list]))
    

if __name__ == '__main__':
    N = int(input().rstrip())
    sr = list(map(str, input().rstrip().split('')))
    print_ans(N, sr)




### FIXED CODE ###

import sys
input = sys.stdin.readline
import numpy as np
base_list = np.array(['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'])
dict_list = []
dict_list.append(base_list)
for i in range(26):
    tmp_char = dict_list[i][0]
    tmp_list = dict_list[i][1:]
    tmp_list = np.append(tmp_list,tmp_char)
    dict_list.append(tmp_list)

def print_ans(N, sr):
    """Test Case
    >>> print_ans(2, ['A', 'B', 'C', 'X', 'Y', 'Z'])
    CDEZAB
    >>> print_ans(0, ['A', 'B', 'C','X', 'Y', 'Z'])
    ABCXYZ
    """
    idx_list = []
    for s in sr:
        tmp = np.where(base_list == s)[0]
        idx_list.append(int(tmp))
    ans = ''.join(dict_list[N][idx_list])
    print(ans)

if __name__ == '__main__':
    N = int(input().rstrip())
    tmp_s= input().rstrip()
    sr = []
    for s in tmp_s:
        sr.append(s)
    print_ans(N, sr)
i = int(input())
if ( i >= 0 and 100 >= i and (i % 2 == 0) ):  
  s = input()
  t_0 = s[0]
  t_1 = s[i/2]
	for j in range(1, i/2):
	  t_0 = t_0 + s[j]
    for k in range(i/2 + 1, i):
      t_1 = t_1 + s[k]
  if (t_0 == t_1):
    print('Yes')
  else:
    print('No')

### FIXED CODE ###

i = int(input()) 
s = input()
if i >= 1 and 100 >= i and i % 2 == 0 and i == len(s) and s.isalpha() and s.islower():
  n = (int)(i/2)
  t_0 = s[0]
  t_1 = s[n]
  for j in range(1, n):
    t_0 += s[j]
  for k in range(n + 1, i):
    t_1 += s[k]
  if t_0 == t_1:
    print("Yes")
  else:
    print("No")
else:
  print("No")
a = [int(input()) for _ in range(6)]
print('Yay!' if a[-2]-a[0]=<a[-1] else ':(') 

### FIXED CODE ###

#!/usr/bin/env python3
import sys


def solve(a: int, b: int, c: int, d: int, e: int, k: int):
    X = (a, b, c, d, e)
    for i, x in enumerate(X):
        for xx in X[i+1:]:
            if abs(x - xx) > k:
                return ':('
    return 'Yay!'

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    c = int(next(tokens))  # type: int
    d = int(next(tokens))  # type: int
    e = int(next(tokens))  # type: int
    k = int(next(tokens))  # type: int
    print(solve(a, b, c, d, e, k))

if __name__ == '__main__':
    main()
'''
参考
https://drken1215.hatenablog.com/entry/2020/06/21/224900
'''
N = int(input())
A = list(map(int, input().split()))

INF = 10 ** 5
cnt = [0] * INF
total = 0

for a in A:
    cnt[a] += 1
    total += a

Q = int(input())
BC = []

for _ in range(Q):
    BC.append(list(map(int, input().split())))

for b, c in BC:
    cnt[c] += cnt[b]
    total += (c-b) * cnt[b]
    cnt[b] = 0
    print(total)


### FIXED CODE ###

'''
参考
https://drken1215.hatenablog.com/entry/2020/06/21/224900
'''
N = int(input())
A = list(map(int, input().split()))

INF = 10 ** 5
cnt = [0] * (INF+1)

Q = int(input())
BC = []

for _ in range(Q):
    BC.append(list(map(int, input().split())))

for a in A:
    cnt[a] += 1

total = sum(A)

for b, c in BC:
    total += (c-b) * cnt[b]
    cnt[c] += cnt[b]
    cnt[b] = 0
    print(total)
H,W,A,B = map(int,input().split())
if H==1:
    if B>0:ans = 'No'
    else:ans = "0"*A + "1"*(W-A)
else:
    s = "1"*A + "0"*(W-A)
    if W%A==0 and H%(W/A) == 0 and H/(W/A)==B:

        for i in range(H):
            print(s)
            s = s[A:] + s[:A]
        exit()
    else:ans = 'No'
print(ans)

### FIXED CODE ###

H,W,A,B = map(int,input().split())

s = "0"*A + "1"*(W-A)
for i in range(B):
    print(s)
s = "1"*A + "0"*(W-A)
for i in range(H-B):
    print(s)