Harryxun/stf_run huggingface dataset:
def gcd(a, b):
    if(a == 0):
        return b
    if(b == 0):
        return a

    if(a < b):
        a, b = b, a
    r = a % b
    while(r != 0):
        a, b = b, r
        r = a % b
    return b

def L(i, A):
    if(i == 0):
        return 0
    return gcd(L(i - 1, A), A[i])

def R(i, A, N):
    if(i == N):
        return 0
    return gcd(R(i + 1, A, N), A[i])

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

M = []
for i in range(N):
    M.append(gcd(L(i, A), R(i + 1, A, N)))

print(max(M))

### FIXED CODE ###

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

    if(a < b):
        a, b = b, a
    r = a % b
    while(r != 0):
        a, b = b, r
        r = a % b
    return b

def L(end_i, A):
    if(end_i == 0):
        return 0
    
    a = 0
    for i in range(end_i):
        a = gcd(a, A[i])
    return a


def R(start_i, A, N):
    if(start_i == N - 1):
        return 0

    a = 0
    for i in range(start_i + 1, N):
        a = gcd(a, A[i])
    return a


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

left = [0] * N
right = [0] * N

for i in range(1, N):
    left[i] = gcd(left[i - 1], A[i - 1])
#print(left)

for i in reversed(range(0, N - 1)):
    right[i] = gcd(A[i + 1], right[i + 1])
#print(right)

M = []
for i in range(N):
    M.append(gcd(left[i], right[i]))
#print(M)

print(max(M))
A, B, C, K = map(int, input().split())

backup = K
AB = A + B
flag = False
ans = 0
if K <= A:
    print(K)
    # print("hogeD")
else:
    if A < K:
        K = K - A
        ans = ans + (A * 1)
        # print(1)

    if B <= K:
        K = K - B
        flag = True

    if K > 0 and flag:
        ans = ans + (-1) * (backup - AB)
        # print(3)

    print(ans)


### FIXED CODE ###

A = input()
B = input()

if A == B[:len(A)]:
    print("Yes")
else:
    print("No")
s = input()
x, y = map(int, input().split())


def part_sum0(integer_list, target_sum,  i=0, sum_=0):
    if i == len(integer_list):
        return sum_ == target_sum
    if (part_sum0(integer_list, target_sum, i + 1, sum_)):
        return True
    if (part_sum0(integer_list, target_sum, i + 1, sum_ + integer_list[i])):
        return True
    return False


fs = s.split('T')
f_num = [len(f) for f in fs]
dir_lst = [[], []]
for i in range(len(f_num)):
    dir_lst[i % 2].append(f_num[i])
x_lst = dir_lst[0]
y_lst = dir_lst[1]

can_x = False
can_y = False

dx = abs(sum(x_lst)) - abs(x)
if (dx % 2 == 1) or (dx < 0):
    pass
elif dx == 0:
    can_x = True
else:
    if part_sum0(x_lst, dx // 2):
        can_x = True

if can_x:
    dy = abs(sum(y_lst)) - abs(y)
    if (dy % 2 == 1) or (dy < 0):
        pass
    elif dy == 0:
        can_y = True
    else:
        if part_sum0(y_lst, dy // 2):
            can_y = True

if can_y:
    print('Yes')
else:
    print('No')


### FIXED CODE ###

s = input()
x, y = map(int, input().split())

fs = s.split('T')
f_num = [len(f) for f in fs]
dir_lst = [[], []]
for i in range(len(f_num)):
    dir_lst[i % 2].append(f_num[i])
x_lst = dir_lst[0]
x -= x_lst[0]
x_lst = x_lst[1:]
y_lst = dir_lst[1]

can_x = False
can_y = False

s = set([0])
for x_ in x_lst:
    s_ = set()
    for e in s:
        s_.add(e+x_)
        s_.add(e-x_)
    s = s_
if x in s:
    can_x = True

s = set([0])
for y_ in y_lst:
    s_ = set()
    for e in s:
        s_.add(e+y_)
        s_.add(e-y_)
    s = s_
if y in s:
    can_y = True

if can_x and can_y:
    print('Yes')
else:
    print('No')
import heapq
def SME(start,end):
    count = 0
    for i,x in enumerate(Whole[start:end//2]):
        heapq.heappush(A,[x,i])
    for j in range(start,end):
        a = heapq.heappop(A)
        if None not in ANS[a[1]:a[1]+L] : continue
        for i in range(L):
            idx = a[1] + i
            try :
                if ANS[idx] : continue
                else :
                    ANS[idx] = a[0]
                    D.Add(idx)
                    count += 1
            except IndexError : continue
        if count > N * parameter : break
    for i in range(L):
        if ANS[i] : continue
        else : ANS[i] = min(Whole[:i+1])
    i = L
    while i < N :
        if None in ANS[i:i+L] :
            while True:
                if ANS[i] :
                    i += 1
                    continue
                else : 
                    ANS[i] = min(Whole[i+1-L:i+1])
                    i += 1
                    break
        else :
            i += L
    return ANS
[N,L] = [int(x) for x in input().split()]
Whole = [int(x) for x in input().split()]
A = []
C = [i for i in range(N)]
D = {}
parameter = 0.99
ANS = [None]*N
ANS = SME(0, N)
for i in ANS[L-1:-1]:print(i, end=" ")
print(ANS[-1])

### FIXED CODE ###

def ascend(a,b):
    mini = min(A[a:a+L])
    ans[a] = mini
    for i in range(a+1,b):
        if A[i+L-1] <= mini : mini = A[i+L-1]
        elif A[i-1] == mini : mini = min(A[i:i+L])
        ans[i] = mini

def descend(a,b):
    mini = min(A[b-1:b+L-1])
    ans[b-1] = mini
    for i in range(b-2,a-1,-1):
        if A[i] <= mini : mini = A[i]
        elif A[i+L] == mini: mini = min(A[i:i+L])
        ans[i] = mini
    
[N,L] = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = [None]*(N-L+1)
count = 0;
if N > 10 ** 4:
    for i in range(100):
        if A[i+1] > A[i] : count += 1
    if count > 80 : descend(0, N-L+1)
    else : ascend(0,N-L+1)
else :
    ascend(0, N-L+1)
for i in ans[:-1] : print(i, end=" ")
print(ans[-1])
a=input().split()
for i in range(3):
    a[i]=int(a[i])

b=int(a[2]-a[0]+a[1])
if b>0:
    print(b):
else:
    print(0)


### FIXED CODE ###

a=input().split()
for i in range(3):
    a[i]=int(a[i])

b=a[2]-a[0]+a[1]
if b>0:
    print(int(b))
else:
    print(0)
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from math import ceil, floor, sqrt, gcd
from copy import deepcopy

def main():
    a,b,c,d = map(int, input().split())
    a -= 1
    num = int(c*d / gcd(c,d))
    num_a = a - int(a // c + a // d - a // num)
    num_b = b - int(b // c + b // d - b // num)
    print(num_b - num_a)

if __name__ == "__main__":
    main()

### FIXED CODE ###

import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from math import ceil, floor, sqrt
from copy import deepcopy
from fractions import gcd

def main():
    a,b,c,d = map(int, input().split())
    a -= 1
    num = int(c*d / gcd(c,d))
    num_a = a - int(a // c + a // d - a // num)
    num_b = b - int(b // c + b // d - b // num)
    print(num_b - num_a)

if __name__ == "__main__":
    main()
N,K=map(int,input().split())
S=list(input())
T=[int(a) for a in S]
U=[]

tmp=T[0]
cnt=1
for i in range(1,N):
  if i==N-1:
    if T[i]==T[i-1]:
      cnt+=1
      U.append((tmp,cnt) )
    else:
      U.append((tmp,cnt) )
      U.append((T[i],1))
  else:
    if T[i]==T[i-1]:
      cnt+=1
    else:
      U.append((tmp,cnt) )
      tmp=T[i]
      cnt=1
    
print(U)

for _ in range(K):
  maxi=0
  for i,kumi in enumerate(U):
    if kumi[0]==0:
      if i==0:
        if len(U)>1:
          tmp = kumi[1]+U[i+1][1]
        else:
          tmp= kumi[1]
      elif 0<i<len(U)-1:
        tmp = U[i-1][1] + kumi[1]+ U[i+1][1]
      else: # i=len(U)-1
        tmp= U[i-1][1] + kumi[1]
      maxi=max(maxi,tmp)
  print("search:",maxi)
  for i,kumi in enumerate(U):
    if kumi[0]==0 and kumi[1]==maxi:
      if i==0:
        if len(U)>1:
          U[1][1] += kumi[1]
          U.pop(0)
        else:
          kumi[0]=1
      elif 0<i<len(U)-1:
        U[i-1][1] += kumi[1]+U[i+1][1]
        U.pop(i)
        U.pop(i)
      else: # i=len(U)-1
        U[i-1][1] += kumi[1]
        U.pop()
  print(U)

### FIXED CODE ###

N,K=map(int,input().split())
S=list(input())
T=[int(a) for a in S]
U=[]

if N==1:
  U=[ [T[0],1] ]
else:
  tmp=T[0]
  cnt=1
  for i in range(1,N):
    if i==N-1:
      if T[i]==T[i-1]:
        cnt+=1
        U.append([tmp,cnt] )
      else:
        U.append([tmp,cnt] )
        U.append([T[i],1])
    else:
      if T[i]==T[i-1]:
        cnt+=1
      else:
        U.append([tmp,cnt] )
        tmp=T[i]
        cnt=1

summ=0
for j in range(len(U)):
  summ += U[j][1]
  U[j][1]=summ
if U[0][0]==0:
  U.insert(0,[1,0])
  U.insert(0,[0,0])
else:
  U.insert(0,[0,0])

#print(U)
maxi=0
  
for p,q in enumerate(U):
  if q[0]==1:
    pass
  else:
    right=min(p+K*2+1,len(U)-1)
    diff=U[right][1]-U[p][1]
    maxi=max(diff,maxi)
    #print(p,right,diff)
print(maxi)
a = input()
l = a.split('S')
while("" in l):
   l.remove("")
print(len(l[0]))

### FIXED CODE ###

a = input()
emp = 0
l = a.split('S')
while("" in l):
   l.remove("")
if not l:
   print(emp)
else:
   print(len(l[0]))
def P(N, M):
  if N = M:
    print('Yes')
  else:
    print('No')

### FIXED CODE ###

import sys
import socket

hostname = socket.gethostname()

if hostname == 'F451C':
    sys.stdin = open('a1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    n, m = read_int_list()
    if n > m:
      res = 'No'
    else:
      res = 'Yes'
    print(res)


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

c=[0]*10**6

isPairwise=True
isSetwise=True
for i in range(N):
    c[A[i]]+=1

for i in range(2,1000000):
    cnt=0
    for j in range(2,1000000,i):
        cnt+=c[j]
    
    if cnt>1:
        isPairwise=False

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

g=0
for i in range(N):
    g=gcd(g,A[i])
if g>1:
    isSetwise=False

if isPairwise:
    print('pairwise coprime')
elif isSetwise:
    print('setwise coprime')
else:
    print('not coprime')

### FIXED CODE ###

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

c=[0]*(10**6+5)

isPairwise=True
isSetwise=True
for i in range(N):
    c[A[i]]+=1

for i in range(2,1000005):
    cnt=0
    for j in range(i,1000005,i):
        cnt+=c[j]
    
    if cnt>1:
        isPairwise=False

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

g=0
for i in range(N):
    g=gcd(g,A[i])
if g>1:
    isSetwise=False

if isPairwise:
    print('pairwise coprime')
elif isSetwise:
    print('setwise coprime')
else:
    print('not coprime')
a,b=map(int,input().split())
l=range(a,b+1)
ans=1
for i in rang(len(l)):
  ans=ans*l[i]
print(ans)

### FIXED CODE ###

a,b=map(int,input().split())
if (a>0 and b>0):
	print("Positive")
elif (a>=0 and b<=0) or (a<=0 and b>=0):
	print("Zero")
elif (a<0 and b<0 and (a+b)%2==0):
	print("Negative")
else:
	print("Positive")
import sys
sys.setrecursionlimit(10**6)

def pow_k(x, n):
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2

    return K * x

n = int(input())
x = list(input())

counter = x.count('1')
number = int(''.join(x), 2)

def f(num, cnt):
    if num == 0:
        return cnt
    popcount = format(num, 'b').count('1')
    return f(num % popcount, cnt+1)

for i in range(n):    
    if x[i] == '0':
        m = number + pow_k(2, n-i-1)
        print(f(m % (counter+1), 1))
    if x[i] == '1':
        m = number - pow_k(2, n-i-1)
        print(f(m % (counter-1), 1))


### FIXED CODE ###

n = int(input())
x = list(input())

count = x.count('1')
one_count = count - 1
zero_count = count + 1

one_mod = 0
zero_mod = 0
for b in x:
    if one_count:
        one_mod = (one_mod * 2 + int(b)) % one_count
    zero_mod = (zero_mod * 2 + int(b)) % zero_count

f = [0] * 2000001
pop_count = [0] * 200001
for i in range(1, 200001):
    pop_count[i] = pop_count[i//2] + i % 2
    f[i] = f[i % pop_count[i]] + 1

for i in range(n):
    if x[i] == '1':
        if one_count:
            nxt = one_mod
            nxt -= pow(2, n-i-1, one_count)
            nxt %= one_count
            print(f[nxt] + 1)
        else:
            print(0)
    if x[i] == '0':
        nxt = zero_mod
        nxt += pow(2, n-i-1, zero_count)
        nxt %= zero_count
        print(f[nxt] + 1)
n, i = map(int, input().split())
if n%k == 0:
    print(0)
else:
    print(1)

### FIXED CODE ###

n, i = map(int, input().split())
if n%i == 0:
    print(0)
else:
    print(1)
a,b = map(int,input().split())
if b == 1:
  print(0)
  exit()
  
cnt = 0  
for i in range(1,a+1):
  cnt = (a-1)*(i-1)+a
  if cnt>=b:
    ans = i
    break
print(ans)    
  


### FIXED CODE ###

a,b = map(int,input().split())
if b == 1:
  print(0)
  exit()
  
cnt = 0  
for i in range(1,100):
  cnt = (a-1)*(i-1)+a
  if cnt>=b:
    ans = i
    break
print(ans)
a,b = map(int,input().split())
    if a >=13:
        print(b)
    elif a <= 5:
        print(0)
    else:
        print(b // 2)

### FIXED CODE ###

a,b = map(int,input().split())
if a >=13:
    print(b)
elif a <= 5:
        print(0)
else:
    print(b // 2)
import collections
S = input()
L = collections.Counter(S)
if len(L) == 2 and L[0][1] == 2:
  print('Yes')
else:
  print('No')


### FIXED CODE ###

import collections
S = input()
L = collections.Counter(S)
T = L.most_common()
if len(T) == 2 and T[0][1] == 2:
  print('Yes')
else:
  print('No')
i = 1
while x = input(): print('Case ' i ': ' x)


### FIXED CODE ###

i,x = 1,input()
while x != "0":
  print('Case '+str(i)+': '+x)
  i,x = i+1,input()
def main():
    A = input()  # 500円の枚数
    B = input()  # 100円の枚数
    C = input()  # 50円の枚数

    x = input()
    result = 0
    for a in range(A):
        for b in range(B):
            for c in range(C):
                total = 500 * a + 100 * b + 50 * c
                if total == x:
                    result += 1

    return result


if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    A = int(input())  # 500円の枚数
    B = int(input())  # 100円の枚数
    C = int(input())  # 50円の枚数
    X = int(input())
    result = 0
    for a in range(A + 1):
        for b in range(B + 1):
            for c in range(C + 1):
                total = 500 * a + 100 * b + 50 * c
                if total == X:
                    result += 1

    print(result)


if __name__ == '__main__':
    main()
N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()

num = []
cnt = []

for a in A:
    if a not in num:
        num.append(a)
        cnt.append(1)
    else:
        cnt[-1] += 1
cnt.sort()
#print(num,cnt)

res = 0
M = len(cnt)
if M <= K:
    res = 0
else:
    for i in range(M-K):
        res += cnt[i]
print(res)
  

### FIXED CODE ###

S = input()

res = 0
for s in S:
    if s == "1":
        res += 1
print(res)
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

h, w, m = LI()
cnt = [[0] * w for _ in range(h)]
cnt_h = [0] * h
cnt_w = [0] * w
for _ in range(m):
    H, W = LI()
    cnt[H-1][W-1] += 1
    cnt_h[H-1] += 1
    cnt_w[W-1] += 1

ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, cnt_h[i] + cnt_w[j] - cnt[i][j])
print(ans)

### FIXED CODE ###

#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

h, w, m = LI()
bomb = defaultdict(lambda : 0)
cnt_h = [0] * h
cnt_w = [0] * w
for _ in range(m):
    H, W = LI()
    bomb[(H-1, W-1)] = 1
    cnt_h[H-1] += 1
    cnt_w[W-1] += 1

m_h = max(cnt_h)
m_w = max(cnt_w)
H_l = defaultdict(int)
W_l = defaultdict(int)
for i in range(h):
    if cnt_h[i] == m_h:
        H_l[i] = 1

for i in range(w):
    if cnt_w[i] == m_w:
        W_l[i] = 1

ans = m_h + m_w

for i in H_l.keys():
    for j in W_l.keys():
        if bomb[(i, j)] == 0:
            print(ans)
            quit()

print(ans-1)
S = input()
if len(S) ==2:
    print(S)
else:
　print(S[::-1])


### FIXED CODE ###

S = input()
if len(S) ==2:
    print(S)
else:
    print(S[::-1])
from collections import deque

def make_wall(maze,h,w):
    maze=deque(maze)
    for i in range(h):
        maze[i]="##"+maze[i]+"##"
    maze.appendleft("#"*(w+4))
    maze.appendleft("#"*(w+4))
    maze.append("#"*(w+4))
    maze.append("#"*(w+4))
    return list(maze)

def bfs(maze, visited, sy, sx, gy, gx):
    queue = deque([[sy, sx]])
    cost[sy][sx]=0
    walk = [(1, 0), (-1, 0), (0, 1), (0, -1)]
    warp = [(i,j) for i in range(-2,3) for j in range(-2,3) if (i,j) not in [(0,0)]+walk]
    
    while queue:
        y, x = queue.popleft()
        if [y, x] == [gy, gx]:
            return cost[y][x]
        
        # 移動A
        for i,j in walk:
            ny, nx = y+i, x+j
            if maze[ny][nx] == "." and cost[ny][nx]>cost[x][y]:
                cost[ny][nx]=cost[y][x]
                queue.appendleft([ny,nx])
            
        # 移動B
        for i, j in warp:
            ny, nx = y+i, x+j
            if cost[ny][nx] > cost[y][x]+1 and maze[ny][nx]==".":
                cost[ny][nx]=cost[y][x]+1
                queue.append([ny,nx])
            
    return -1 #ゴールできない

h,w=map(int,input().split())
sy,sx=map(int,input().split())
gy,gx=map(int,input().split())

maze=[input() for _ in range(h)]

maze=make_wall(maze,h,w)
h+=4
w+=4
sy+=2
sx+=2
gy+=2
gx+=2

INF = 10**12
cost = [[INF]*w for _ in range(h)]

ans=bfs(maze, cost, sy-1, sx-1, gy-1, gx-1)
if ans==INF:
    ans=-1
print(ans)


### FIXED CODE ###

from collections import deque

def make_wall(maze,h,w):
    maze=deque(maze)
    for i in range(h):
        maze[i]="##"+maze[i]+"##"
    maze.appendleft("#"*(w+4))
    maze.appendleft("#"*(w+4))
    maze.append("#"*(w+4))
    maze.append("#"*(w+4))
    return list(maze)

def bfs(maze, visited, sy, sx, gy, gx):
    queue = deque([[sy, sx]])
    cost[sy][sx]=0
    walk = [(1, 0), (-1, 0), (0, 1), (0, -1)]
    warp = [(i,j) for i in range(-2,3) for j in range(-2,3) if (i,j) not in [(0,0)]+walk]
    
    while queue:
        y, x = queue.popleft()
        if [y, x] == [gy, gx]:
            return cost[y][x]
        
        # 移動A
        for i,j in walk:
            ny, nx = y+i, x+j
            if maze[ny][nx] == "." and cost[ny][nx]>cost[y][x]:
                cost[ny][nx]=cost[y][x]
                queue.appendleft([ny,nx])
            
        # 移動B
        for i, j in warp:
            ny, nx = y+i, x+j
            if cost[ny][nx] > cost[y][x]+1 and maze[ny][nx]==".":
                cost[ny][nx]=cost[y][x]+1
                queue.append([ny,nx])
            
    return -1 #ゴールできない

h,w=map(int,input().split())
sy,sx=map(int,input().split())
gy,gx=map(int,input().split())

maze=[input() for _ in range(h)]

maze=make_wall(maze,h,w)
h+=4
w+=4
sy+=2
sx+=2
gy+=2
gx+=2

INF = 10**12
cost = [[INF]*w for _ in range(h)]

ans=bfs(maze, cost, sy-1, sx-1, gy-1, gx-1)
if ans==INF:
    ans=-1
print(ans)
mouikkai

### FIXED CODE ###

s = input()
n = len(s)
# dp[i][j]:上からi桁目で13で割った余りがjの場合の数
dp = [[0]*13 for i in range(n+1)]
dp[0][0] = 1
mod = 10**9+7
for i in range(n):
    for j in range(13):
        if s[i] == "?":
            for k in range(10):
                dp[i+1][(j*10+k)%13] += dp[i][j]
                dp[i+1][(j*10+k)%13] %= mod
        else:
            k = int(s[i])-0
            dp[i+1][(j*10+k)%13] += dp[i][j]
            dp[i+1][(j*10+k)%13] %= mod

print(dp[n][5])
import sys
import numpy as np
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
X, Y, A, B, C = [int(x) for x in input().strip().split()]
p = np.array(sorted([int(x) for x in input().strip().split()], reverse=True))[:X]
q = np.array(sorted([int(x) for x in input().strip().split()], reverse=True))[:Y]
r = np.array(sorted([int(x) for x in input().strip().split()], reverse=True))[:min(C, X+Y)]

pi, qi, ri = X-1, Y-1, 0
tp, tq, tr = p[pi], q[qi], r[ri]
ans = 0
while pi >= 0 or qi >= 0:
    if tp >= tr and  tq >= tr:
        break
    elif tp < tr and tq < tr:
        if tp < tq:
            p[pi] = r[ri]
            pi -= 1
            ri += 1
        else:
            q[qi] = r[ri]
            qi -= 1
            ri += 1
    elif tp < tr or tq < tr:
        if tp < tr:
            p[pi] = r[ri]
            ri += 1
            pi -= 1
            tp = p[pi]
        else:
            q[qi] = r[ri]
            ri += 1
            qi -= 1
            tq = q[qi]
    else:
        break
    if ri == len(r):
        break

print(sum(p)+sum(q))

### FIXED CODE ###

import sys
import numpy as np
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
X, Y, A, B, C = [int(x) for x in input().strip().split()]
p = np.array(sorted([int(x) for x in input().strip().split()], reverse=True))[:X]
q = np.array(sorted([int(x) for x in input().strip().split()], reverse=True))[:Y]
r = np.array(sorted([int(x) for x in input().strip().split()], reverse=True))[:min(C, X+Y)]

pq = np.hstack((p, q))
pq.sort()
ri = 0
for i, t in enumerate(pq):
    if t < r[ri]:
        pq[i] = r[ri]
        ri += 1
    if ri == len(r):
        break
print(sum(pq))
N = int(input())
Arr = [int(input()) for i in range(N)]


def funct(i, left_max, right_max):
    n = Arr[i]
    if n >=left_max:
        if i==0:
            left_max=0
        elif i ==1:
            left_max=Arr[0]
        else:
            left_max=max(Arr[:i-1])
    if n>=right_max:
        if i ==N-1:
            right_max=0
        else:
            right_max = max(Arr[i+1:])

    print(max(left_max, right_max))

    if i == N-1:
        return

    return funct(i + 1, left_max, right_max)


funct(0, 0, max(Arr[1:]))


### FIXED CODE ###

N = int(input())
Arr = [int(input()) for i in range(N)]

left_max=0
right_max=max(Arr)

for i in range(N):
    n = Arr[i]
    if left_max>=right_max:
        print(left_max)
    else:
        if n==right_max:
            if i ==N-1:
                right_max=left_max
                
            else:
                right_max = max(Arr[i+1:])

        print(right_max)

    if i == N-1:
        break
    left_max=max(n,left_max)
n,m = [int(x) for x in input().split()]
py = []
for i in range(m):
    p,y = [int(x) for x in input().split()]
    py.append([p,y,i+1])

def zero(num):
    return str(num).zfill(6)


if m == 1:
    print(zero(1)+zero(1))
else:
    year_py = sorted(py, key=lambda x: x[1])
    dic = {x: 1 for x in range(1,m+1)}
    
    for i in range(m):
        year_py[i].append(dic[year_py[i][0]])
        dic[year_py[i][0]] += 1
    
    yb_py = sorted(year_py, key=lambda x: x[2])
    
    for i in range(m):
        print(zero(yb_py[i][0]) + zero(yb_py[i][3]))

### FIXED CODE ###

n,m = [int(x) for x in input().split()]
py = []
for i in range(m):
    p,y = [int(x) for x in input().split()]
    py.append([p,y,i+1])

def zero(num):
    return str(num).zfill(6)


if m == 1:
    print(zero(py[0][0])+zero(1))
else:
    year_py = sorted(py, key=lambda x: x[1])
    dic = {str(x): 0 for x in range(1,n+1)}

    for i in range(m):
        dic[str(year_py[i][0])] += 1
        year_py[i].append(dic[str(year_py[i][0])])
    yb_py = sorted(year_py, key=lambda x: x[2])

    for i in range(m):
        print(zero(yb_py[i][0]) + zero(yb_py[i][3]))