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



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

def cmp(a,b):
    if a == None:
        return True
    elif b == None:
        return False
    if len(a) > len(b):
        return False
    elif len(a) < len(b):
        return True
    else:
        if int(a) >= int(b):
            return False
        else:
            return True

dp = [None] * (N+10)
l = [0,2,5,5,4,5,6,3,7,6]
dp[0] = ""
for i in range(N-1):
    for s in A:
        if dp[i] == None and i!=0:
            continue
        if cmp(dp[i + l[int(s)]] , dp[i]+s):
            dp[i + l[int(s)]] = dp[i]+s
            

print(dp[N])


                





### FIXED CODE ###

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

dp = [-1 for i in range(N+10)]
l = [0,2,5,5,4,5,6,3,7,6]
dp[0] = 0
for i in range(N-1):
    for s in A:
        if dp[i] == -1 and i!=0:
            continue
        if dp[i + l[s]] < dp[i]*10+s:
            dp[i + l[s]] = dp[i]*10+s
print(dp[N])
### BUGGY CODE ###

N = int(input())
summer = 0

while N > 0:
    digit = N % 10
    summer += digit
    N = N // 10
if summer % 9 == 0:
    print("Yes")
else:
    print("No")


### FIXED CODE ###

N = int(input())
if N % 9 == 0:
    print("Yes")
else:
    print("No")
### BUGGY CODE ###

LIMIT = 1000000000000000000

def main():
    N = int(input())  # 文字列または整数(一変数)
    a = list(map(int, input().split()))  # 整数のリスト

    answer = 1

    for i in a:
        answer = answer * i

    if answer > LIMIT:
        print(-1)
    else:
        print(answer)


if __name__ == '__main__':
    main()


### FIXED CODE ###

LIMIT = 1000000000000000000

def main():
    N = int(input())  # 文字列または整数(一変数)
    a = list(map(int, input().split()))  # 整数のリスト
    answer = 1

    for i in range(N):
        answer *= a[i]
        if answer > LIMIT:
            if 0 in a[i:]:
                print(0)
                return
            else:
                print(-1)
            return

    print(answer)

if __name__ == '__main__':
    main()
### BUGGY CODE ###

from collections import Counter
int = int(input())
word = [input() for i in range(int)]
s = Counter(word)
t = list(s.values())
u = [k for k, v in s.items() if v == max(t)]
u.sort()
for i in range(len(u)):
    print(u[i])

### FIXED CODE ###

from collections import Counter
int = int(input())
word = [input() for i in range(int)]
s = Counter(word).most_common()
u = s[0][1]
v = []
for i, j in s:
  if j == u:
    v.append(i)
v.sort()
print(*v)
### BUGGY CODE ###

N = int(input())
N = list(str(N))
N = list(map(int, N))

ans = 0
for i in range(len(N)-1, -1, -1):

    if i < len(N)-1 and N[i+1] == 5 and N[i] >= 5:
        N[i] += 1
    x = N[i]
    if x > 5:
        ans += (10 - x)
        if i > 0:
            N[i-1] += 1
        else:
            ans += 1
    else:
        ans += x
print(ans)


### FIXED CODE ###

N = tuple(input())
N = tuple(map(int, N))

ans = 0
flag = False
flag5 = False
i = len(N)-1


for x in reversed(N):
    if flag or (flag5 and x >= 5):
        x += 1
    flag5 = False
    flag = False
    if x > 5:
        ans += (10 - x)
        flag = True
        if i == 0:
            ans += 1
    else:

        ans += x
    if x == 5:
        flag5 = True
    i -= 1

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

import numpy as np
_ = input()
a = [*map(int, input().split())]
q = int(input())
b = [[*map(int,input().split())] for _ in range(q)]
n,c = np.unique(a,return_counts=True)
for i,j in b:
    d = np.where(n==i)
    n[d] = j
    print(sum(n*c))

### FIXED CODE ###

import collections
_ = input()
a = [*map(int, input().split())]
q = int(input())
s = sum(a)
b = [[*map(int,input().split())] for _ in range(q)]
c = collections.Counter(a)
for i,j in b:
    if j not in c:
        c[j] = 0
    if i not in c:
        c[i] = 0
    s += (j-i)*c[i]
    c[j]+=c[i]
    c[i] = 0
    print(s)
### BUGGY CODE ###

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

ans = ''
for i in range(1, n+1):
    rank = lst.index(i) + 1
    ans += ' ' + str(rank)


print(ans[1:])


### FIXED CODE ###

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


tmp = [0] * (n+1)
for i, num in enumerate(lst):
    tmp[num] = str(i + 1)

tmp.pop(0)

print(' '.join(tmp))
### BUGGY CODE ###

from fractions import gcd

mod = 10**9 + 7

N = int(input())
A = [int(i) for i in input().split()]
num = 1
for n in A:
    num = (num*n)//gcd(num,n)
t = 0
for n in A:
    t = (t + num//n) % mod
print(t)

### FIXED CODE ###

from fractions import gcd

def main():
    mod = 10**9 + 7

    N = int(input())
    A = input().split()
    AP = set(A)
    num = 1
    for n in AP:
        num = (num*int(n))//gcd(num,int(n))

    t = 0
    for n in A:
        t = (t + num//int(n))
    print(t%mod)


if __name__ == "__main__":
    main()
### BUGGY CODE ###

import re
S = input()
N1 = S.replace('A','0').replace('BC','1')
S_li = re.split('B|C',N1)

count = 0
for l in S_li:
    if len(l):
        while True:
            a = l.find('0')
            if a<0:
                break
            bc = l.rfind('1')
            if a < bc:
                l = l[a+1:bc]
                count += (bc-a)
            else:
                break

print(str(count))


### FIXED CODE ###

import re
S = input()
N1 = S.replace('A','0').replace('BC','1')
S_li = re.split('B|C',N1)
 
count = 0
for l in S_li:
    a = sum([i for i,x in enumerate(l) if '1' in x])
    su=sum([x for x in range(l.count('1'))])
    count += (a-su)
print(str(count))
### BUGGY CODE ###

from collections import deque
def bfs(succs, preds, start, colors):
    saisyoku = {}
    queue = deque([start])
    while queue:
        v = queue.popleft()
        color_v = colors.copy()
        for u in preds[v]:
            color_v.remove(saisyoku[preds[v][u]])
        for w in succs[v]:
            saisyoku[succs[v][w]] = color_v.pop()
            queue.append(w)
    return saisyoku

n = int(input())
vertices = range(1, n+1)
edges = [list(map(int, input().split())) for _ in range(n-1)]
jisu = {v: 0 for v in vertices}
succs = {v: {} for v in vertices}
preds = {v: {} for v in vertices}
for i, (u, v) in enumerate(edges):
  succs[u][v] = i
  preds[v][u] = i
  jisu[u] += 1
  jisu[v] += 1
#print(succs)
#print(preds)
color_num = max(jisu.values())
print(color_num)
colors = list(range(1, color_num+1))
saisyoku = bfs(succs, preds, 1, colors)
for _, c in sorted(saisyoku.items()):
    print(c)


### FIXED CODE ###

from collections import deque
def bfs(succs, preds, start):
    saisyoku = {}
    queue = deque([start])
    used = 0
    while queue:
        v = queue.popleft()
        for u in preds[v]:
            used = saisyoku[preds[v][u]]
        c = 1
        for w in succs[v]:
            if used and c == used:
                c += 1
            saisyoku[succs[v][w]] = c
            queue.append(w)
            c += 1
    return saisyoku
  
n = int(input())
vertices = range(1, n+1)
edges = [list(map(int, input().split())) for _ in range(n-1)]
jisu = {v: 0 for v in vertices}
succs = {v: {} for v in vertices}
preds = {v: {} for v in vertices}
for i, (u, v) in enumerate(edges):
  succs[u][v] = i
  preds[v][u] = i
  jisu[u] += 1
  jisu[v] += 1
colors = max(jisu.values())
print(colors)
saisyoku = bfs(succs, preds, 1)
for _, c in sorted(saisyoku.items()):
    print(c)
### BUGGY CODE ###

K,S = map(int, input().split())

ans = 0
for x in range(K, -1, -1):
  for y in range(K, -1, -1):
    for z in range(K, -1, -1):
      if x+y+z==S:
        ans+=1
      elif x+y+z<S:
        break

print(ans)

### FIXED CODE ###

K,S = map(int, input().split())

ans = 0
if K*3<S:
  print(0)
  exit()

for x in range(K, -1, -1):
  if x >S:
    continue
  for y in range(min(S-x, K), -1, -1):
    if x+y >S:
      continue
    for z in range(min(S-x-y, K), -1, -1):
      if x+y+z==S:
        ans+=1
      elif x+y+z<S:
        break

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

h,w=map(int,input().split())
a=[list(map(int,input().split()))for i in range(h)]
b=[list(map(int,input().split()))for i in range(h)]
c=[[abs(a[i][j]-b[i][j])for j in range(w)]for i in range(h)]
d=[[set()for i in range(w+1)]for j in range(h+1)]
d[1][1]=set([-c[0][0],c[0][0]])
for x in range(1,h+1):
    for y in range(1,w+1):
        if not (x==1 and y==1):
            a=d[x-1][y]|d[x][y-1]
            for i in a:
                d[x][y].add(i-c[x-1][y-1])
                if i+c[x-1][y-1]<=80:
                    d[x][y].add(i+c[x-1][y-1])
print(abs(min(d[h][w],key=abs)))

### FIXED CODE ###

h,w=map(int,input().split())
a=[list(map(int,input().split()))for i in range(h)]
b=[list(map(int,input().split()))for i in range(h)]
s=[0]*w
s[0]=p=1<<6400
for i in range(h):
    for j in range(w):
        d=abs(a[i][j]-b[i][j])
        if j>0:
            s[j]|=s[j-1]
        s[j]=(s[j]<<d)|(s[j]>>d)
t=s[-1]
for i in range(6401):
    if t&(p<<i) or t&(p>>i):
        print(i)
        break
### BUGGY CODE ###

x=input()
if "ST" in x:
    x=x.replace("ST","")
for i in range(len(x)//2):
    x=x.replace("ST","")
print(len(x))


### FIXED CODE ###

x=list(input())
stack=[]
for i in range(len(x)):
    if x[i]=="S":
        stack.append(x[i])
    elif x[i]=="T" and len(stack)==0:
        stack.append(x[i])
    elif x[i]=="T" and stack[-1]=="T":
        stack.append(x[i])
    elif x[i]=="T" and stack[-1]=="S":
        stack.pop()
print(len(stack))
### BUGGY CODE ###

N, Q = map(int, input().split())
S = input()
q =[]
for i in range(Q):
    q.append(list(map(int, input().split())))
for i,j in q:
    print(S[i-1:j].count("AC"))

### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
q =[]
temp = [0] * (N+1)
tmp = 0
for i in range(1,N):
    if S[i-1] == "A":
        if S[i] == "C":
            tmp +=1
    temp[i+1] = tmp
for j in range(Q):
    inp = input().split()
    print(temp[int(inp[1])] - temp[int(inp[0])])
### BUGGY CODE ###

import numpy as np
import math
import subprocess
import random
import os
import sys

N,K,Q=input().split()

N=int(N)
K=int(K)
Q=int(Q)
A = [int(input()) for i in range(Q)]
arr=np.full(N, K)
for i in A:
	arr-=1
	arr[i-1]+=1
	
for j in arr:
	if j>0:
		print("Yes")
	else:
		print("No")
		

### FIXED CODE ###

import numpy as np


N,K,Q=input().split()

N=int(N)
K=int(K)
Q=int(Q)
arr=np.full(N, K)
arr-=Q
for i in range(Q):
	A=int(input())
	arr[A-1]+=1
for j in arr:
	if j>0:
		print("Yes")
	else:
		print("No")
### BUGGY CODE ###

N,M=map(int,input().split())
S=list(map(int,input().split()))
T=list(map(int,input().split()))
mod=1000000007

dp=[[0 for j in range(M+1)] for i in range(N+1)]
Sum=[[0 for j in range(M+1)] for i in range(N+1)]

for i in range(1,N+1):
	for j in range(1,M+1):
		if S[i-1]==T[j-1]:
			dp[i][j]=Sum[i-1][j-1]
#			for k in range(1,i):
#				for l in range(1,j):
#					dp[i][j]+=dp[k][l]
			dp[i][j]+=1
		Sum[i][j]=(Sum[i-1][j]+Sum[i][j-1]-Sum[i-1][j-1]+dp[i][j])%mod

print(Sum[N][M]+1)

### FIXED CODE ###

N,M=map(int,input().split())
S=list(map(int,input().split()))
T=list(map(int,input().split()))
mod=1000000007

dp=[[0 for j in range(M+1)] for i in range(N+1)]
Sum=[[0 for j in range(M+1)] for i in range(N+1)]

for i in range(1,N+1):
	for j in range(1,M+1):
		if S[i-1]==T[j-1]:
			dp[i][j]=Sum[i-1][j-1]
#			for k in range(1,i):
#				for l in range(1,j):
#					dp[i][j]+=dp[k][l]
			dp[i][j]+=1
		Sum[i][j]=(Sum[i-1][j]+Sum[i][j-1]-Sum[i-1][j-1]+dp[i][j])%mod

print(Sum[N][M]+1)
### BUGGY CODE ###

from math import sqrt
n, k = map(int, input().split())
MOD = 10**9 + 7
max1 = int(sqrt(n))
dp1 = [[0 for _ in range(max1+1)] for _ in range(k)]
for j in range(1, max1+1):
	dp1[0][j] = 1
max2 = int(n/(max1+1))
dp2 = [[0 for _ in range(max2+1)] for _ in range(k)]
for j in range(1, max2+1):
	dp2[0][j] = int(n/j) - int(n/(j+1))

for i in range(k-1):
	csum1 = (sum(dp1[i])+sum(dp2[i])) % MOD
	dp1[i+1][1] = csum1
	for j in range(2, max1+1):
		dp1[i+1][j] = (dp1[i+1][j-1] - dp2[i][j-1]) % MOD
	csum2 = sum(dp1[i][:max2+1]) % MOD
	dp2[i+1][max2] = (csum2*dp2[0][max2]) % MOD
	for j in range(max2-1, 0, -1):
		csum2 -= dp1[i][j+1]
		csum2 %= MOD
		dp2[i+1][j] = (csum2*dp2[0][j]) % MOD

print((sum(dp1[k-1])+sum(dp2[k-1]))%MOD)

### FIXED CODE ###

from math import sqrt
n, k = map(int, input().split())
MOD = 10**9 + 7
max1 = int(sqrt(n))
dp1 = [[0 for _ in range(max1+1)] for _ in range(k)]
for j in range(1, max1+1):
	dp1[0][j] = 1
max2 = int(n/(max1+1))
dp2 = [[0 for _ in range(max2+1)] for _ in range(k)]
for j in range(1, max2+1):
	dp2[0][j] = int(n/j) - int(n/(j+1))

for i in range(k-1):
	csum1 = (sum(dp1[i])+sum(dp2[i])) % MOD
	dp1[i+1][1] = csum1
	for j in range(2, max1+1):
		dp1[i+1][j] = (dp1[i+1][j-1] - dp2[i][j-1]) % MOD
	csum2 = sum(dp1[i][:max2+1]) % MOD
	dp2[i+1][max2] = (csum2*dp2[0][max2]) % MOD
	for j in range(max2-1, 0, -1):
		csum2 -= dp1[i][j+1]
		csum2 %= MOD
		dp2[i+1][j] = (csum2*dp2[0][j]) % MOD

print((sum(dp1[k-1])+sum(dp2[k-1]))%MOD)
### BUGGY CODE ###

import math
def combinations_count(n, r):
    if n >= 2:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    else:
        return 0
N = int(input())
A = [int(a) for a in input().split()]
a = [0] * N
for i in range(N):
    a[A[i]-1] += 1
sum = 0
for i in range(N):
    sum += combinations_count(a[i], 2)
for k in range(N):
    print(sum +  combinations_count(a[A[k]-1]-1, 2) - combinations_count(a[A[k]-1], 2))


### FIXED CODE ###

N = int(input())
A = [int(a) for a in input().split()]
a = [0] * N
for i in A:
    a[i-1] += 1
cnt = 0
cnt += sum([i*(i-1)//2 for i in a])
for i in A:
    print(cnt - (a[i-1]-1))
### BUGGY CODE ###

s=input()
k=2019
numMultiples = 0
seenRemainders = []
for i in range(len(s)):
  l={}
  seenRemainders.append(l)
for i in range(len(s)):
    remainder = 0
    prefixesFound = 0
    for j in range(i,len(s)):
        remainder = (10 * remainder + int(s[j])) % k
        if remainder not in seenRemainders[j]:  
            seenRemainders[j][remainder]=1
        else:
            break
        if remainder == 0:
            prefixesFound+=1
    numMultiples += prefixesFound * (prefixesFound + 1) // 2
print(numMultiples)

### FIXED CODE ###

mod=2019
s=input()

d={}
temp=1
cnt=0
we=0
d[0]=1
for i in range(len(s)):
  we=(we+int(s[-1-i])*temp)%mod
  temp=temp*10%mod
  
  if we not in d:
    d[we]=1
  else:
    d[we]+=1

#print(d)
for i in d:
  cnt+=(d[i]*(d[i]-1))//2
print(cnt)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
INF = 100100100100100


def main():
    N, M, L = map(int, input().split())
    graph = [[INF]*N for _ in range(N)]
    for _ in range(M):
        A, B, C = map(int, input().split())
        graph[A-1][B-1] = C
        graph[B-1][A-1] = C
    for i in range(N):
        graph[i][i] = 0
    for k in range(N):
        for i in range(N):
            if graph[i][k] == INF:
                continue
            for j in range(N):
                if graph[k][j] == INF:
                    continue
                graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j])
    newGraph = [[INF]*N for _ in range(N)]
    for i in range(N):
        newGraph[i][i] = 0
        for j in range(i+1, N):
            if graph[i][j] <= L:
                newGraph[i][j] = 1
                newGraph[j][i] = 1
    for k in range(N):
        for i in range(N):
            if newGraph[i][k] == INF:
                continue
            for j in range(N):
                if newGraph[k][j] == INF:
                    continue
                newGraph[i][j] = min(newGraph[i][j], newGraph[i][k] + newGraph[k][j])
    Q = int(input())
    for _ in range(Q):
        s, t = map(int, input().split())
        if newGraph[s-1][t-1] == INF:
            print(-1)
        else:
            print(newGraph[s-1][t-1]-1)


if __name__ == '__main__': main()

### FIXED CODE ###

import sys
input = sys.stdin.readline
INF = 100100100100100


def main():
    N, M, L = map(int, input().split())
    graph = [[INF]*N for _ in range(N)]
    for _ in range(M):
        A, B, C = map(int, input().split())
        graph[A-1][B-1] = C
        graph[B-1][A-1] = C
    for i in range(N):
        graph[i][i] = 0
    for k in range(N):
        for i in range(N):
            if graph[i][k] == INF:
                continue
            for j in range(N):
                if graph[k][j] == INF:
                    continue
                graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j])
    newGraph = [[INF]*N for _ in range(N)]
    for i in range(N):
        newGraph[i][i] = 0
        for j in range(i+1, N):
            if graph[i][j] <= L:
                newGraph[i][j] = 1
                newGraph[j][i] = 1
    for k in range(N):
        for i in range(N):
            if newGraph[i][k] == INF:
                continue
            for j in range(N):
                if newGraph[k][j] == INF:
                    continue
                newGraph[i][j] = min(newGraph[i][j], newGraph[i][k] + newGraph[k][j])
    Q = int(input())
    for _ in range(Q):
        s, t = map(int, input().split())
        if newGraph[s-1][t-1] == INF:
            print(-1)
        else:
            print(newGraph[s-1][t-1]-1)


if __name__ == '__main__': main()
### BUGGY CODE ###

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parent = [i for i in range(n)]
        self.rank = [0] * n
    
    def find(self, x):
        if self.parent[x] != x:
            self.parent[x] = self.find(self.parent[x])
        return self.parent[x]

    def union(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y: return
        
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
            self.rank[x] += (self.rank[x] == self.rank[y])

def kruskal(n, edge):
    ans = 0
    uf = UnionFind(n)
    edge.sort(key=lambda x:x[0])
    for i in range(len(edge)):
        d, v, u = edge[i]
        
        if uf.find(v) != uf.find(u):
            uf.union(v, u)
            ans += d
    return ans

n = int(input())
x, y = [None]*n, [None]*n
dist = [[0] * n for _ in range(n)]

for i in range(n):
    a, b = map(int, input().split())
    x[i] = (a, i)
    y[i] = (b, i)

x.sort(key=lambda x:x[0])
y.sort(key=lambda y:y[0])

edge_x = []
edge_y = []
for i in range(n-1):
    edge_x.append((x[i+1][0]-x[i][0], x[i][1], x[i+1][1]))
    edge_y.append((y[i+1][0]-y[i][0], y[i][1], y[i+1][1]))

del x, y
print(kruskal(n, edge_x+edge_y))

### FIXED CODE ###

import heapq
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parent = [i for i in range(n)]
        self.rank = [0] * n
    
    def find(self, x):
        if self.parent[x] != x:
            self.parent[x] = self.find(self.parent[x])
        return self.parent[x]

    def union(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y: return
        
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
            self.rank[x] += (self.rank[x] == self.rank[y])

def kruskal(n, edge):
    ans = 0
    uf = UnionFind(n)
    while True:
        d, v, u = heapq.heappop(edge)
        
        if uf.find(v) != uf.find(u):
            uf.union(v, u)
            n -= 1
            ans += d
        if n < 2: return ans
    return ans

n = int(input())
x, y = [None]*n, [None]*n

for i in range(n):
    a, b = map(int, input().split())
    x[i] = (a, i)
    y[i] = (b, i)

x.sort(key=lambda x:x[0])
y.sort(key=lambda y:y[0])

edge = []
for i in range(n-1):
    heapq.heappush(edge, (x[i+1][0]-x[i][0], x[i][1], x[i+1][1]))
    heapq.heappush(edge, (y[i+1][0]-y[i][0], y[i][1], y[i+1][1]))

del x, y
print(kruskal(n, edge))
### BUGGY CODE ###

import statistics

def quickSort(arr):
  left = []
  right = []
  if len(arr) <= 1:
   return arr
  median = int(statistics.median(arr))
  medianFlg = 0

  for element in arr:
   if element < median:
    left.append(element)
   elif element > median:
    right.append(element)
   else:
    medianFlg += 1
  left = quickSort(left)
  right = quickSort(right)
  return left + [median] * medianFlg + right

X,Y,A,B,C = map(int,input().split())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
R = list(map(int,input().split()))
PP=quickSort(P)
QQ=quickSort(Q)
S=PP[A-X:A]+QQ[B-Y:B]+R
SS=quickSort(S)
D=0
for r in range(X+Y):
 D+=SS[C+r]
print(D)

### FIXED CODE ###

def merge_sort(arr):
 if len(arr) <= 1:
  return arr
 mid = len(arr) // 2
# ここで分割を行う
 left = arr[:mid]
 right = arr[mid:]
# 再帰的に分割を行う
 left = merge_sort(left)
 right = merge_sort(right)
# returnが返ってきたら、結合を行い、結合したものを次に渡す
 return merge(left, right)
def merge(left, right):
 merged = []
 l_i, r_i = 0, 0
# ソート済み配列をマージするため、それぞれ左から見ていくだけで良い
 while l_i < len(left) and r_i < len(right):
    # ここで=をつけることで安定性を保っている
  if left[l_i] <= right[r_i]:
   merged.append(left[l_i])
   l_i += 1
  else:
   merged.append(right[r_i])
   r_i += 1

# 上のwhile文のどちらかがFalseになった場合終了するため、あまりをextendする
 if l_i < len(left):
  merged.extend(left[l_i:])
 if r_i < len(right):
  merged.extend(right[r_i:])
 return merged

X,Y,A,B,C = map(int,input().split())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
R = list(map(int,input().split()))
PP=merge_sort(P)
QQ=merge_sort(Q)
S=PP[A-X:A]+QQ[B-Y:B]+R
SS=merge_sort(S)
D=0
for r in range(X+Y):
 D+=SS[C+r]
print(D)
### BUGGY CODE ###

#N
import copy
from collections import defaultdict
dd = defaultdict(int)

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

def rep(L):
    if len(L)==1:
        return 0
    S='-'.join(map(str, L))
    if dd[S]!=0:
        return dd[S]
    temp=10**15
    for i in range(len(L)-1):
        LL=copy.deepcopy(L)
        LL[i]+=LL[i+1]
        LL.pop(i+1)
        temp=min(temp,rep(LL)+L[i]+L[i+1])
    dd[S]=temp
    return temp
        
rep(a)
S='-'.join(map(str, a))
print(dd[S])






### FIXED CODE ###

#N

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

S=[0]*(N+1)
for i in range(N):
    S[i+1]=S[i]+a[i]


#dp[i][j]は[i,j)の範囲で全てをマージする最小コスト
inf=10**15
dp=[[inf]*(N+1) for _ in range(N+1)]

#区間[i,j)を[i,k)+[k,j)に分けて考える
for d in range(1,N+1):#dはj-i
    for i in range(N+1):
        j=i+d
        if j>N:
            break
        if d==1:
            dp[i][j]=0
        else:
            for k in range(i,j):
                dp[i][j]=min(dp[i][j] , dp[i][k]+dp[k][j]+S[j]-S[i])
            
print(dp[0][-1])
### BUGGY CODE ###

S = input()
N = len(S)
mod = 10**9+7

dp = [[0 for i in range(13)] for j in range(N+1)]
dp[0][0] = 1

for i in range(N):
    c = -1 if S[i] == '?' else int(S[i])
    for j in range(10):
        if c != -1 and c != j:
            continue
        for k in range(13):
            dp[i+1][(k*10 + j) % 13] += dp[i][k]
    for j in range(13):
        dp[i+1][j] %= mod

print(dp[N][5])

### FIXED CODE ###

def main():
    M=10**9+7
    r=tuple(tuple((j-k)*9%13for j in range(10))for k in range(13))
    d=[1]+[0]*12
    for c in input():
        if c > '9':
            d = [sum(d[j] for j in k)%M for k in r] 
        else:
            d = [d[(int(c)-k)*9%13] for k in range(13)]
    print(d[5])
main()
### BUGGY CODE ###

import math

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

for i in range(m):
    a = sorted(a, reverse=True)
    a[0] = math.floor(a[0] / 2)

print(sum(a))


### FIXED CODE ###

import heapq

n, m = map(int, input().split())
a = list(map(lambda x: int(x) * (-1), input().split()))

heapq.heapify(a)

for _ in range(m):
    tmp_min = heapq.heappop(a)
    heapq.heappush(a, (-1) * (-tmp_min // 2))

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

import sys
MOD = 1000000007


def main():
    bits = input()
    ans = 1
    for i, b in enumerate(reversed(bits)):
        if b == '1':
            ans = ((ans * 2 % MOD) + pow(3, i)) % MOD
    print(ans)


main()


### FIXED CODE ###

import sys
import numpy as np
MOD = 1000000007


def main():
    bits = input()
    ans = 1
    pow3 = 1
    for i, b in enumerate(reversed(bits)):
        if b == '1':
            ans = ((ans * 2 % MOD) + pow3) % MOD
        pow3 = (pow3 * 3) % MOD
    print(ans)


main()