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

from collections import deque
import math

def explore(C, D):
    magic_n = 0

    queue = deque([[C[0]-1, C[1]-1]])
    maze_visited[C[0]-1][C[1]-1] = magic_n
    while queue:
        y, x = queue.popleft()
        for i, j in [(1,0),(0,1),(-1,0),(0,-1)]:
            n_x, n_y = x + i, y + j
            if n_x >= 0 and n_y >= 0 and n_x < W and n_y < H:
                if S[n_y][n_x] == '.':
                    if maze_visited[n_y][n_x] > maze_visited[y][x]:
                        maze_visited[n_y][n_x] = maze_visited[y][x]
                        queue.append([n_y, n_x])
        for i in range(-2, 3):
            for j in range(-2, 3):
                if abs(i) + abs(j) <= 1:
                    continue
                n_x, n_y = x + i, y + j
                if n_x >= 0 and n_y >= 0 and n_x < W and n_y < H:
                    if S[n_y][n_x] == '.':
                        if maze_visited[n_y][n_x] > maze_visited[y][x] + 1:
                            maze_visited[n_y][n_x] = maze_visited[y][x] + 1
                            queue.append([n_y, n_x])
    
H, W = list(map(int, input().split()))
C = list(map(int, input().split()))
D = list(map(int, input().split()))

S = [list(input()) for i in range(H)]

maze_visited = [[math.inf] * W for i in range(H)]

explore(C,D)

if maze_visited[D[0] - 1][D[1] - 1] == math.inf:
    print('-1')
else:
    print(maze_visited[D[0] - 1][D[1] - 1])

### FIXED CODE ###

from collections import deque
import math
 
def explore(C, D):
    queue = deque([(C[0]-1, C[1]-1)])
    maze_visited[C[0]-1][C[1]-1] = 0
    while queue:
        y, x = queue.popleft()
        mv_cur = maze_visited[y][x]
        for i, j in [(1,0),(0,1),(-1,0),(0,-1)]:
            n_x, n_y = x + i, y + j
            if n_x >= 0 and n_y >= 0 and n_x < W and n_y < H:
                mv_n = maze_visited[n_y][n_x]
                if mv_n > mv_cur:
                    if S[n_y][n_x] == '.':
                        maze_visited[n_y][n_x] = mv_cur
                        queue.appendleft((n_y, n_x))
        for i in range(-2, 3):
            for j in range(-2, 3):
                if abs(i) + abs(j) <= 1:
                    continue
                n_x, n_y = x + i, y + j
                if n_x >= 0 and n_y >= 0 and n_x < W and n_y < H:
                    mv_n = maze_visited[n_y][n_x]
                    if mv_n > mv_cur + 1:
                        if S[n_y][n_x] == '.':
                            maze_visited[n_y][n_x] = mv_cur + 1
                            queue.append((n_y, n_x))
    
H, W = list(map(int, input().split()))
C = list(map(int, input().split()))
D = list(map(int, input().split()))
 
S = [list(input()) for i in range(H)]
 
maze_visited = [[math.inf] * W for i in range(H)]
 
explore(C,D)
 
if maze_visited[D[0] - 1][D[1] - 1] == math.inf:
    print('-1')
else:
    print(maze_visited[D[0] - 1][D[1] - 1])
### BUGGY CODE ###

def val(num):
    print(num, flush=True)
    sex = input()
    if sex == "Vacant":
        exit(0)
    return 1 if sex == "Male" else 0


n = int(input())

l_sex = val(0)

left = 0
right = n - 1

while left < right:
    mid = (left + right) // 2
    sex = val(mid)
    if (mid - left) % 2 == 0 and sex != l_sex:
        left = mid
        l_sex = sex
    elif (mid - left) % 2 == 1 and sex == l_sex:
        left = mid
        l_sex = sex
    else:
        right = mid - 1

print(left, flush=True)
exit(0)


### FIXED CODE ###

def val(num):
    print(num, flush=True)
    sex = input()
    if sex == "Vacant":
        exit(0)
    return 1 if sex == "Male" else 0


n = int(input())

l_sex = val(0)
r_sex = val(n - 1)

left = 0
right = n - 1

while left < right:
    mid = (left + right) // 2
    sex = val(mid)
    if (mid - left) % 2 == 0 and sex != l_sex:
        right = mid
        r_sex = sex
    elif (mid - left) % 2 == 1 and sex == l_sex:
        right = mid
        r_sex = sex
    else:
        left = mid
        l_sex = sex

print(left, flush=True)
exit(0)
### BUGGY CODE ###

from numba import njit
import numpy as np


def main(N, P):
    lista = [1, -1, N, -N]
    d = np.zeros((N, N), dtype=np.int32)
    d = d.ravel()
    sit = np.ones_like(d)
    que = []
    count = 0
    for i in range(N*N):
        d[i] = min(i % N, (N-1-i) % N, i//N, N-1-i//N)
    for player in P:
        sit[player-1] = 0
        count += d[player-1]
        que.append(player)
        while len(que) > 0:
            p = que.pop()
            for i in lista:
                if p+i < 1 or p + i > N*N:
                    continue
                if d[p-1]+sit[p-1] < d[p+i-1]:
                    d[p+i-1] = d[p-1]+sit[p-1]
                    que.append(p+i)
    print(count)


def cc_export():
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('main', '(i8,i8[:])')(main)
    cc.compile()


if __name__ == '__main__':
    import sys
    if sys.argv[-1] == 'ONLINE_JUDGE':
        cc_export()
        exit(0)
    #from my_module import main
    N = int(input())
    P = list(map(int, input().split()))
    main(N, P)


### FIXED CODE ###

from numba import njit
import numpy as np

@njit
def main(N, P):
    lista = [1, -1, N, -N]
    d = np.zeros((N, N), dtype=np.int32)
    d = d.ravel()
    sit = np.ones_like(d)
    stack = np.empty_like(d)
    count = 0
    for i in range(N*N):
        d[i] = min(i % N, (N-1-i) % N, i//N, N-1-i//N)
    for player in P:
        sit[player-1] = 0
        count += d[player-1]
        stack[0] = player
        num = 0
        while num >= 0:
            p = stack[num]
            num -= 1
            a = d[p-1]+sit[p-1]
            for i in lista:
                if p+i < 1 or p + i > N*N:
                    continue
                if d[p+i-1] > a:
                    d[p+i-1] = a
                    num += 1
                    stack[num] = p+i
    print(count)

N = int(input())
P = np.array(input().split(), np.int32)

main(N, P)
### BUGGY CODE ###

from itertools import permutations
N, M, R = map(int, input().split())
r = list(map(int, input().split()))
inf = float("inf")
d = [[inf] * (N+1) for _ in range(N+1)]
ans = inf
for _ in range(M): #隣接行列
    A,B,C = map(int, input().split())
    d[A][B] = C
    d[B][A] = C

def warshall_floyd(n):
    for i in range(1,n+1): #経由する点
        for j in range(1,n+1): #始点
            for k in range(1,n+1): #終点
                d[j][k] = min(d[j][k], d[j][i] + d[i][k])

warshall_floyd(N)

for p in permutations(r): #通る町の順列生成
    tmp = 0
    for r1,r2 in zip(p,p[1:]):
        tmp += d[r1][r2]
    ans = min(ans, tmp)
print(ans)

### FIXED CODE ###

from itertools import permutations
N, M, R = map(int, input().split())
r = list(map(int, input().split()))
inf = float("inf")
d = [[inf] * (N+1) for _ in range(N+1)]
ans = inf
for _ in range(M): #隣接行列
    A,B,C = map(int, input().split())
    d[A][B] = C
    d[B][A] = C

def warshall_floyd(n):
    for i in range(1,n+1): #経由する点
        for j in range(1,n+1): #始点
            for k in range(1,n+1): #終点
                d[j][k] = min(d[j][k], d[j][i] + d[i][k])

warshall_floyd(N)

for p in permutations(r): #通る町の順列生成
    tmp = 0
    for r1,r2 in zip(p,p[1:]):
        tmp += d[r1][r2]
    ans = min(ans, tmp)
print(ans)
### BUGGY CODE ###

def main(length_num,num_list):
    count_num = 0
    for i in range(0,length_num):
        flag_tag = True
        for j in range(0 , i ):
          if int(num_list[i]) >= int(num_list[j]):
              flag_tag = False
              break
        if flag_tag != False:
            count_num += 1
    return count_num


    
if __name__ == "__main__":
    input_length_num = int(input())
    input_num2 = input()
    input_num_list = input_num2.split()
    print(main(input_length_num,input_num_list))

### FIXED CODE ###

def main(length_num,num_list):
    count_num = 0
    min_num = int(num_list[0])
    for i in num_list:
        if int(min_num) >= int(i):
            min_num = i
            count_num += 1           
    return count_num
    
if __name__ == "__main__":
    input_length_num = int(input())
    input_num2 = input()
    input_num_list = input_num2.split()
    print(main(input_length_num,input_num_list))
### BUGGY CODE ###

def main():
    s = input().rstrip()
    t = "0" + s
    n = len(t)
    dp = [[float("inf")]*2 for _ in range(n+1)]
    dp[0][0] = 0
    for i in range(n):
        for j in range(2):
            x = int(t[n-i-1]) + j
            if x < 10:
                dp[i+1][0] = min(dp[i+1][0], dp[i][j] + x + 0)
            if 0 < x:
                dp[i+1][1] = min(dp[i+1][1], dp[i][j] + 10 - x)
    print(dp[n][0])

if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    s = input().rstrip()
    s = "0" + s
    dp = [0, float("inf")]
    for c in s:
        x = int(c)
        dp = [min(dp[0] + x, dp[1] + (10-x)), min(dp[0] + x+1, dp[1] + (10-x) - 1)]
    print(dp[0])

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

N,K = map(int,input().split())
A = [int(a) for a in input().split()]

n = 1
c = 0

for i in range(N):
    if i <= K-1:
        n *= A[i]

    else:
        tmp = n
        tmp /= A[c]
        tmp *= A[i]

        if tmp > n:
            print("Yes")
        else:
            print("No")

        c += 1
        n = tmp



### FIXED CODE ###

N,K = map(int,input().split())
A = [int(a) for a in input().split()]

n = 0

for i in range(K,N):
    if A[i] > A[n] :
        print("Yes")
    else:
        print("No")
    n+=1
### BUGGY CODE ###

n,m=map(int,input().split())
mod=10**9+7
f=[1]
for i in range(1,max(m,n)+1):f.append(f[i-1]*i%mod)
def comb(n,r):return f[n]*pow(f[r],mod-2,mod)*pow(f[n-r],mod-2,mod)%mod
def pern(n,r):return f[n]*pow(f[n-r],mod-2,mod)%mod
a=[0]*(n+1)
a[n]=1
for i in range(n-1,-1,-1):
    a[i]=(comb(n,n-i)*pern(m-i,n-i)-a[i+1])%mod
print(a[0]*pern(m,n)%mod)


### FIXED CODE ###

n,m=map(int,input().split())
mod=10**9+7
f=[1]
for i in range(1,max(m,n)+1):f.append(f[i-1]*i%mod)
def comb(n,r):return f[n]*pow(f[r],mod-2,mod)*pow(f[n-r],mod-2,mod)%mod
def pern(n,r):return f[n]*pow(f[n-r],mod-2,mod)%mod
a=[0]*(n+1)
a[n]=1
for i in range(n-1,-1,-1):
    a[i]=(comb(n,n-i)*pern(m-i,n-i)-a[i+1])%mod
print(a[0]*pern(m,n)%mod)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
N = int(input())

if int(float(N)**0.5) <= 1:
  xyzMax = 1
else:
  xyzMax = int(float(N)**0.5)

Ans = 0

for i in range(1,N+1):
  for x in range(1,xyzMax+1):
    for y in range(1,xyzMax+1):
      for z in range(1,xyzMax+1):
        if x**2 + y**2 + z**2 + (x * y) + (y * z) + (z * x) == i:
          Ans += 1
          
  print(Ans)
  Ans = 0

### FIXED CODE ###

# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
N = int(input())

Ans = 0
numlist = [0] * 10001

if int(float(N)**0.5) <= 1:
  rMax = 1
else:
  rMax = int(float(N)**0.5)  

for x in range(1,rMax+1):
  for y in range(1,rMax+1):
    for z in range(1,rMax+1):
      Ans = x**2 + y**2 + z**2 + (x * y) + (y * z) + (z * x)
      if Ans <= 10000:
        numlist[Ans] += 1
  
for r in range(1,N+1):
  print(numlist[r])
### BUGGY CODE ###

import heapq
from collections import defaultdict


N, M, L = map(int, input().split())
graph = defaultdict(list)
for _ in range(M):
    a, b, c = map(int, input().split())
    graph[a].append([b, c])
    graph[b].append([a, c])

def search(s, t, L):
    queue = [(0, -L, s)]
    while queue:
        cost, fuel, cur = heapq.heappop(queue)
        if cur == t:
            return cost
        for nxt, c in graph[cur]:
            if fuel + c <= 0:
                heapq.heappush(queue, (cost, fuel + c, nxt))
                heapq.heappush(queue, (cost + 1, -L,  nxt))
    return -1


Q = int(input())
for _ in range(Q):
    s, t = map(int, input().split())
    print(search(s, t, L))

### FIXED CODE ###

import sys
input = sys.stdin.readline

N,M,L = map(int,input().split())
ABC = [list(map(int,input().split())) for _ in [0]*M]
Q = int(input())
ST = [list(map(int,input().split())) for _ in [0]*Q]


INF = (L+1)*N
d = [[INF]*N for _ in [0]*N]
for i in range(N):
    d[i][i] = 0
for a,b,c in ABC:
    a-=1;b-=1
    d[a][b] = c
    d[b][a] = c

def Warshall_Floyd(d,N=None):
    if N==None : N = len(d)
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j] = min(d[i][j],d[i][k]+d[k][j])

Warshall_Floyd(d,N)

d2 = [None]*N
for i,row in enumerate(d):
    d2[i] = [1 if e<=L else INF for e in row]
    d2[i][i] = 0

Warshall_Floyd(d2,N)

for s,t in ST:
    s-=1;t-=1
    ans = (d2[s][t]%INF)-1
    print(ans)
### BUGGY CODE ###

dic = {"A":[], "C":[], "G":[], "T":[]}

for i in range(int(input())):
  cmd, arg = input().split()
  if cmd == "insert":
    dic[arg[0]].append(arg)
  else:
    if arg in dic[arg[0]]:
      print("yes")
    else:
      print("no")

### FIXED CODE ###

dic = {}

for i in range(int(input())):
  cmd, arg = input().split()
  if cmd == "insert":
    dic[arg] = 0
  else:
    if arg in dic:
      print("yes")
    else:
      print("no")
### BUGGY CODE ###

# coding: utf-8
# Your code here!

n=int(input())
a=[]
for _ in range(n):
    a.append(int(input()))
    a.sort()

#print(a)    


ans=0

if n%2==0:
    for i in range(n//2-1):
        ans += 2*(a[n-1-i]-a[i])
    ans += a[n//2] - a[n//2-1]

if n%2==1:
    for i in range(n//2-1):
        ans += 2*(a[n-1-i]-a[i])
    ans += max(a[n//2+1] + a[n//2] - 2*a[n//2-1], 2*a[n//2+1] - a[n//2] - a[n//2-1])

print(ans)

### FIXED CODE ###

# coding: utf-8
# Your code here!

n=int(input())
a=[]
for _ in range(n):
    a.append(int(input()))

a.sort()

#print(a)    


ans=0

if n%2==0:
    for i in range(n//2-1):
        ans += 2*(a[n-1-i]-a[i])
    ans += a[n//2] - a[n//2-1]

if n%2==1:
    for i in range(n//2-1):
        ans += 2*(a[n-1-i]-a[i])
    ans += max(a[n//2+1] + a[n//2] - 2*a[n//2-1], 2*a[n//2+1] - a[n//2] - a[n//2-1])

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

def func():
    H, W, D = map(int, input().split())

    MAP  = [None] * (H*W+1)
    COST = {}

    for i in range(H):
        for j, str_l in enumerate(input().split()):
            MAP[int(str_l)] = (i, j)

    Q = int(input())

    for i in range(Q):
        L, R = map(int, input().split())
        cost = 0
        keys = COST.keys()
        while L < R:
            try:
                cost += COST[L]
            except:
                COST[L] = abs(MAP[L][0] - MAP[L+D][0]) + abs(MAP[L][1] - MAP[L+D][1])
                cost += COST[L]
            L += D
        print(cost)

func()

### FIXED CODE ###

# speed-test
# https://abc089.contest.atcoder.jp/submissions/2206669

h,w,d = map(int,input().split())
 
dic = {}
for i in range(h):
    a = input().split()
    for j in range(w):
        dic[int(a[j])] = (i+1,j+1)
        
q = int(input())
c = [0]*(h*w+1)
for i in range(d+1,h*w+1):
    pi,pj = dic[i]; qi,qj = dic[i-d]
    c[i] = c[i-d] + abs(pi-qi) + abs(pj-qj)
    
for i in range(q):
    l,r = map(int,input().split())
    print(c[r]-c[l])
### BUGGY CODE ###

n,m=map(int,input().split())
M=[[0 for i in range(n)] for j in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    if a>b:
        M[b-1][a-1]=1
    else:
        M[a-1][b-1]=1
ans=0
for m in M:
    ans=max(ans,m.count(1))
print(ans+1)

### FIXED CODE ###

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
 
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
 
        if x == y:
            return
 
        if self.parents[x] > self.parents[y]:
            x, y = y, x
 
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
 
    def size(self, x):
        return -self.parents[self.find(x)]

n, m = map(int,input().split())
uf = UnionFind(n)
for i in range(m):
    a,b = map(int,input().split())
    uf.unite(a-1, b-1)

ans = 0
for i in range(n):
    ans = max(ans,uf.size(i))

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

#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, maxint
from operator import itemgetter


def main():
    num = int(stdin.readline())

    L = []
    for _ in xrange(num):
        it = iter(int(s) for s in stdin.readline().split()[1:])
        L.append([(next(it), next(it)) for _ in xrange(next(it))])

    weight = [[i, maxint] for i in xrange(num)]
    weight[0][1] = 0
    V = set(xrange(1, num))
    W = weight[1:]
    index = 0

    while V:
        for v, cost in L[index]:
            if v not in V:
                continue
            weight[v][1] = min(weight[v][1], cost + weight[index][1])

        W.sort(key=itemgetter(1), reverse=True)
        index = W.pop()[0]

        V.remove(index)

    for i, d in weight:
        print(i, d)


main()

### FIXED CODE ###

#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, maxsize


def main():
    num = int(stdin.readline())

    edges = []
    for _ in range(num):
        ns = [int(s) for s in stdin.readline().split()]
        for i in range(ns[1]):
            edges.append((ns[0], ns[2*i+2], ns[2*i+3]))

    dis = [maxsize] * num
    dis[0] = 0

    while 1:
        update = False
        for from_, to, cost in edges:
            if dis[from_] < maxsize and dis[to] > cost + dis[from_]:
                dis[to] = cost + dis[from_]
                update = True

        if not update:
            break

    for i, d in enumerate(dis):
        print(i, d)


main()
### BUGGY CODE ###

n = int(input())
*a, = map(int, input().split())
ans = 0
mod = 10**9 + 7
for i in range(n):
    for j in range(i+1, n):
        ans += a[i]*a[j]
print(ans % mod)

### FIXED CODE ###

from itertools import accumulate
n = int(input())
*a, = map(int, input().split())
cumsum = [0] + list(accumulate(a))
ans = sum(a[i]*cumsum[i] for i in range(n))
mod = 10**9 + 7
print(ans % mod)
### BUGGY CODE ###

#from heapq import nsmallest as hp
l,r = map(int,input().split())
tmp = 2019**2
tmp2 = 0
for i in range(l,r+1):
  
  for j in range(i+1,r+1):
    tmp = min(tmp,i*j%2019)
    
  if tmp == 0:
    break

print(tmp)

### FIXED CODE ###

l,r = map(int,input().split())
tmp = 2019
tmp2 = 0
for i in range(l,min(r+1,l+2018)):
  
  for j in range(i+1,min(r+1,l+2018)):
    tmp = min(tmp,i*j%2019)
    
  if tmp == 0:
    break

print(tmp)
### BUGGY CODE ###

import sys
input=sys.stdin.readline

n=int(input())
s=[ord(i)for i in input()]
t=[-1]*n
for i in range(n):
  if s[i]==68:
    t[i]=0
  elif s[i]==77:t[i]=1
  elif s[i]==67:t[i]=2

def solve(k):
  dd=mm=dm=dmc=0
  for i in range(n):
    if t[i]==0:dd+=1
    if i>=k and t[i-k]==0:dm-=mm;dd-=1
    if t[i]==1:dm+=dd;mm+=1
    if i>=k and t[i-k]==1:mm-=1
    if t[i]==2:dmc+=dm
  return dmc

q=int(input())
k=list(map(int,input().split()))
for i in k:print(solve(i))

### FIXED CODE ###

import sys
input=sys.stdin.readline

n=int(input())
s=[ord(i)for i in input()]
t=[-1]*n
for i in range(n):
  if s[i]==68:
    t[i]=0
  elif s[i]==77:t[i]=1
  elif s[i]==67:t[i]=2

def solve(k):
  dd=mm=dm=dmc=0
  for i in range(n):
    if t[i]==0:dd+=1
    if i>=k and t[i-k]==0:dm-=mm;dd-=1
    if t[i]==1:dm+=dd;mm+=1
    if i>=k and t[i-k]==1:mm-=1
    if t[i]==2:dmc+=dm
  return dmc

q=int(input())
k=list(map(int,input().split()))
for i in k:print(solve(i))
### BUGGY CODE ###

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


import bisect
import math

for i in range(m):
  maxx=math.floor(a[-1]/2)
  a.pop(-1)
  a.insert(bisect.bisect_left(a,maxx),maxx)

print(sum(a))

### FIXED CODE ###

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

import heapq
import math

def _heappush_max(heap, item):
    heap.append(item)
    heapq._siftdown_max(heap, 0, len(heap)-1)
def _heappop_max(heap):
    """Maxheap version of a heappop."""
    lastelt = heap.pop()    # raises appropriate IndexError if heap is empty
    if heap:
        returnitem = heap[0]
        heap[0] = lastelt
        heapq._siftup_max(heap, 0)
        return returnitem
    return lastelt

heapq._heapify_max(a)

for i in range(m):
  temp=math.floor(_heappop_max(a)/2)
  _heappush_max(a,temp)

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

N = int(input())
H = [int(i) for i in  input().split()]
length = len(H)
def z_counter(start):
  cnt = 0
  for i in range(start+1, length):
    if H[i] <= H[i-1]:
      cnt += 1
    else:
      break
  return cnt
ans = 0
for i in range(1, length):
  ans = max(ans, z_counter(i))

print(ans)

### FIXED CODE ###

N=int(input())
H=list(map(int,input().split()))
h=[0]*N
count=0
for i in range(1,N):
    if H[i-1]>=H[i]:
        count+=1
    else:
        count=0
    h[i]=count
print(max(h))
### BUGGY CODE ###

x, y, a, b, c = map(int, input().split())
pn = list(map(int, input().split()))
qn = list(map(int, input().split()))
rn = list(map(int, input().split()))

pn.sort(reverse=True)
qn.sort(reverse=True)
rn.sort(reverse=True)

pq = pn[:x] + qn[:y]
rcount = 0

while min(pq) <= rn[0]:
  pq.remove(min(pq))
  pq.append(rn[0])
  del rn[0]
  if len(rn) == 0:
    break
  
print(sum(pq))


### FIXED CODE ###

x, y, a, b, c = map(int, input().split())
pn = list(map(int, input().split()))
qn = list(map(int, input().split()))
rn = list(map(int, input().split()))

pn.sort(reverse=True)
qn.sort(reverse=True)

pqr = pn[:x] + qn[:y] + rn
pqr.sort(reverse=True)
  
print(sum(pqr[:x+y]))
### BUGGY CODE ###

#coding=UTF-8

def search(jun):
    global ans
    global R
    global rrCost
    tmpans=0
    if len(jun)==R:
        mae=jun[0]
        for idx in range(1,R,1):
            ba=jun[idx]
            tmpans += rrCost[mae][ba]
            mae=ba

        if ans==None or tmpans<ans:
            ans=tmpans
    else:
        for me in range(0,R,1):
            if not (me in jun):
                search(jun+[me])

mozir=input()
hyo=mozir.split(' ')
N=int(hyo[0])
M=int(hyo[1])
R=int(hyo[2])

mozir=input()
hyo=mozir.split(' ')
r=[(int(mono)-1) for mono in hyo]

michi=[]
for idx in range(0,M,1):
    mozir=input()
    hyo=mozir.split(' ')
    A=int(hyo[0])-1
    B=int(hyo[1])-1
    C=int(hyo[2])

    michi.append((A,B,C))
    michi.append((B,A,C))

rrCost=[]
for idx in range(0,R,1):
    rrCost.append([None]*R)

for idx in range(0,R,1):
    rrCost[idx][idx]=0

for idr in range(0,R,1):
    deCost=[None]*N
    deCost[r[idr]]=0
    
    miru=[]
    for mono in michi:
        if mono[0] == r[idr]:
            deCost[mono[1]]=mono[2]
            miru.append(mono[1])

    while miru:
        nextmiru=[]

        for me in miru:
            preCost=deCost[me]
            for mono in michi:
                if mono[0] == me:
                    tmpCost=preCost+mono[2]
                    if deCost[mono[1]]==None or deCost[mono[1]]>tmpCost:
                        deCost[mono[1]]=tmpCost
                        nextmiru.append(mono[1])

        miru=list(set(nextmiru))

    for idx in range(0,R,1):
        rrCost[idr][idx]=deCost[r[idx]]
        rrCost[idx][idr]=deCost[r[idx]]


ans=None
search([])
print(ans)


### FIXED CODE ###

#coding=UTF-8

def search(jun):
    global ans
    global R
    global r
    global rCost
    tmpans=0
    if len(jun)==R:
        mae=jun[0]
        for idx in range(1,R,1):
            ba=jun[idx]
            tmpans += rCost[mae][r[ba]]
            mae=ba

        if ans==None or tmpans<ans:
            ans=tmpans
    else:
        for me in range(0,R,1):
            if not (me in jun):
                search(jun+[me])


mozir=input()
hyo=mozir.split(' ')
N=int(hyo[0])
M=int(hyo[1])
R=int(hyo[2])

mozir=input()
hyo=mozir.split(' ')
r=[(int(mono) -1 ) for mono in hyo]

michi=[]
for idx in range(0,N,1):
    michi.append([])

for idx in range(0,M,1):
    mozir=input()
    hyo=mozir.split(' ')
    A=int(hyo[0])-1
    B=int(hyo[1])-1
    C=int(hyo[2])
    michi[A].append((B,C))
    michi[B].append((A,C))


rCost=[]
for idr in range(0,R,1):
    Cost=[None]*N
    Cost[r[idr]]=0
    miru=[r[idr]]
    while miru:
        nextmiru=[]
        for toshi in miru:
            preCost=Cost[toshi]
            for (saki,sakiCost) in michi[toshi]:
                tmpCost=preCost+sakiCost
                if Cost[saki]==None or tmpCost < Cost[saki]:
                    Cost[saki]=tmpCost
                    nextmiru.append(saki)

        miru=list(set(nextmiru))
    rCost.append(Cost)

#for ko in rCost:
#    print(ko)

ans=None
search([])
print(ans)