TnT/CodeNet4Repair huggingface dataset:
Problem:
Write a program which reads an integer $S$ [second] and converts it to $h:m:s$ where $h$, $m$, $s$ denote hours, minutes (less than 60) and seconds (less than 60) respectively.

Incorrect submission (verdict: Wrong Answer):
n = input()
n = int(n)

h = n // 3600
m = (n % 3600)  // 60
s = (n % 3600)  % 60

Fixed, accepted submission:
n = input()
n = int(n)

h = n // 3600
m = (n % 3600)  // 60
s = (n % 3600)  % 60

print(str(h) + ':' + str(m) + ':' + str(s))
Problem:
Iroha has a sequence of N strings S_1, S_2, ..., S_N. The length of each string is L.  She will concatenate all of the strings in some order, to produce a long string.  Among all strings that she can produce in this way, find the lexicographically smallest one.  Here, a string s=s_1s_2s_3...s_n is _lexicographically smaller_ than another string t=t_1t_2t_3...t_m if and only if one of the following holds:    * There exists an index i(1≦i≦min(n,m)), such that s_j = t_j for all indices j(1≦j<i), and s_i<t_i.   * s_i = t_i for all integers i(1≦i≦min(n,m)), and n<m.

Incorrect submission (verdict: Wrong Answer):
N, L = map(int, input().split())
S_i = [input() for i in range(N)]
s = sorted(S_i)
m = ""
for x in s:
    m += x
    print(m)

Fixed, accepted submission:
N, L = map(int, input().split())
S_i = [input() for i in range(N)]
m = ""
for x in sorted(S_i):
    m += x
else:
    print(m)
Problem:
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters.  Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s.  Given the name of the contest, print the abbreviation of the name.

Incorrect submission (verdict: Wrong Answer):
a,b,c = map(str,input().split())
print(a,b,c)


Fixed, accepted submission:
a,b,c = map(str,input().split())
B = list(b)
print("A"+B[0]+"C")
#ok
Problem:
Based on some criterion, Snuke divided the integers from 1 through 12 into three groups as shown in the figure below. Given two integers x and y (1 ≤ x < y ≤ 12), determine whether they belong to the same group.  

Incorrect submission (verdict: Wrong Answer):
s=map(int,input().split());print("yes"if s in[1,3,5,7,8,10,12]or s in[4,6,9,11]else"no")

Fixed, accepted submission:
s=[int(i)for i in input().split()];f=lambda x,l:not(set(x)-set(l));print(["No","Yes"][f(s,[1,3,5,7,8,10,12])or f(s,[4,6,9,11])or f(s,[2])])
Problem:
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively.    An example of a trapezoid  Find the area of this trapezoid.

Incorrect submission (verdict: Wrong Answer):
n0 = int(input())
n1 = int(input())
n2 = int(input())
print( (n0 + n1)  * n2 / 2)

Fixed, accepted submission:
n0 = int(input())
n1 = int(input())
n2 = int(input())
print(int( (n0 + n1)  * n2 / 2))
Problem:
You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".

Incorrect submission (verdict: Wrong Answer):
l = list(map(int,input().split()))
if (1 in l) and (4 in l) and (7 in l) and (9 in l):
  print("Yes")
else:
  print("No")

Fixed, accepted submission:
l = list(map(int,input().split()))
if (1 in l) and (4 in l) and (7 in l) and (9 in l):
  print("YES")
else:
  print("NO")
Problem:
You are given three integers A, B and C. Determine whether C is not less than A and not greater than B.

Incorrect submission (verdict: Wrong Answer):
a,b,c=map(int,input().split())
if a<=c<=b:
  print('YES')
else:
  print('NO')

Fixed, accepted submission:
a,b,c=map(int,input().split())
if a<=c<=b:
  print('Yes')
else:
  print('No')
Problem:
There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white.  Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i).  Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows:    * If a_i = 1, he painted the region satisfying x < x_i within the rectangle.   * If a_i = 2, he painted the region satisfying x > x_i within the rectangle.   * If a_i = 3, he painted the region satisfying y < y_i within the rectangle.   * If a_i = 4, he painted the region satisfying y > y_i within the rectangle.  Find the area of the white region within the rectangle after he finished painting.

Incorrect submission (verdict: Wrong Answer):
w,h,n = map(int,input().split())
area = h*w
a1=0
a2=w
a3=0
a4=h
for i in range(n):
  x,y,a = map(int,input().split())
  if a ==1:
    a1 = max(a1,x)
  elif a ==2:
    a2 = min(a2,x)
  elif a ==3:
    a3 = max(a3,y)
  elif a==4:
    a4 = min(a4,y)
#print(a1,a2,a3,a4)
area -= a1*h + (w-a2)*h + a3*w + (h-a4)*w 
if area<=0:
  print(0)
else:
  print(area-(a1*(a3+(h-a4))+(10-a2)*(a3+(h-a4))))

Fixed, accepted submission:
w,h,n = map(int,input().split())
area = h*w
a1=0
a2=w
a3=0
a4=h
for i in range(n):
  x,y,a = map(int,input().split())
  if a ==1:
    a1 = max(a1,x)
  elif a ==2:
    a2 = min(a2,x)
  elif a ==3:
    a3 = max(a3,y)
  elif a==4:
    a4 = min(a4,y)
#print(a1,a2,a3,a4)
if a1>=a2 or a3>=a4:
  print(0)
else:
  area -= a1*h + (w-a2)*h + a3*w + (h-a4)*w 
 # print(area)
  print(area+(a1*(a3+(h-a4))+(w-a2)*(a3+(h-a4))))
Problem:
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.

Incorrect submission (verdict: Wrong Answer):
a,b = map(int,input().split())
if a*b % 2 == 0:
    print('even')
else:
    print('odd')

Fixed, accepted submission:
a,b = map(int,input().split())
#
if a*b%2 == 0:
    print('Even')
else:
    print('Odd')
Problem:
Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery.  Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence.  Here, the distance between two points s and t on a number line is represented by |s-t|.

Incorrect submission (verdict: Wrong Answer):
x,a,b = map(int,input().split())

if abs(a-x) > abs(b-x):
    print("A")
else:
    print("B")



Fixed, accepted submission:
x,a,b = map(int,input().split())

if abs(a-x) < abs(b-x):
    print("A")
else:
    print("B")
Problem:
Iroha has a sequence of N strings S_1, S_2, ..., S_N. The length of each string is L.  She will concatenate all of the strings in some order, to produce a long string.  Among all strings that she can produce in this way, find the lexicographically smallest one.  Here, a string s=s_1s_2s_3...s_n is _lexicographically smaller_ than another string t=t_1t_2t_3...t_m if and only if one of the following holds:    * There exists an index i(1≦i≦min(n,m)), such that s_j = t_j for all indices j(1≦j<i), and s_i<t_i.   * s_i = t_i for all integers i(1≦i≦min(n,m)), and n<m.

Incorrect submission (verdict: Wrong Answer):
line = list(map(str,input().split( )))
#print(line)
line.sort()
#print(line)

print(''.join(line))

Fixed, accepted submission:
n,l = map(int,input().split( ))

line = []

for i in range(n):
  line.append(str(input()))

#print(line)
line.sort()
#print(line)

print(''.join(line))
Problem:
Write a program which converts uppercase/lowercase letters to lowercase/uppercase for a given string.

Incorrect submission (verdict: Wrong Answer):
s=input();u=s.upper();l=s.lower()
print(*[(l[i],u[i])[s[i]==u[i]]for i in range(len(s))])

Fixed, accepted submission:
s=input();u=s.upper();l=s.lower()
print(''.join([(u[i],l[i])[s[i]==u[i]]for i in range(len(s))]))
Problem:
Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery.  Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence.  Here, the distance between two points s and t on a number line is represented by |s-t|.

Incorrect submission (verdict: Wrong Answer):
x,a,b = list(map(int, input().split()))
print(min(abs(x-a), abs(x-b)))

Fixed, accepted submission:
x,a,b = list(map(int, input().split()))
xa = abs(x-a)
xb = abs(x-b)
if xa>xb:
  print("B")
else:
  print("A")
Problem:
We have a long seat of width X centimeters. There are many people who wants to sit here. A person sitting on the seat will always occupy an interval of length Y centimeters.  We would like to seat as many people as possible, but they are all very shy, and there must be a gap of length at least Z centimeters between two people, and between the end of the seat and a person.  At most how many people can sit on the seat?

Incorrect submission (verdict: Wrong Answer):
X,Y,Z=map(int,input().split())
print((X-Z)//Y+Z)

Fixed, accepted submission:
X,Y,Z=map(int,input().split())
print((X-Z)//(Y+Z))
Problem:
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A.  The problem has N test cases.  For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively.  See the Output section for the output format.

Incorrect submission (verdict: Wrong Answer):
from collections import Counter
n=int(input())
s=[input() for i in range(n)]
print("AC ×",s.count("AC"))
print("WA ×",s.count("WA"))
print("TLE ×",s.count("TLE"))
print("RE ×",s.count("RE"))

Fixed, accepted submission:
from collections import Counter
n=int(input())
s=[input() for i in range(n)]
print("AC","x",s.count("AC"))
print("WA","x",s.count("WA"))
print("TLE","x",s.count("TLE"))
print("RE","x",s.count("RE"))
Problem:
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs.  Determine if it is possible that there are exactly X cats among these A + B animals.

Incorrect submission (verdict: Wrong Answer):
a, b, x = list(map(int, input().split()))

if x >= a and x <= a+b:
    print('Yes')
else:
    print('No')


Fixed, accepted submission:
a, b, x = list(map(int, input().split()))

if x >= a and x <= a+b:
    print('YES')
else:
    print('NO')
Problem:
There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis.  You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0.  However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned.  For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.

Incorrect submission (verdict: Wrong Answer):
N = int(input())
A = [int(i) for i in input().split()]

A = [0] + A + [0]

allcost = 0
for i in range(len(A) - 1):
    allcost += abs(A[i+1] - A[i])

print(allcost)

for i in range(1, N+1):
    old = abs(A[i+1] - A[i]) + abs(A[i] - A[i-1])
    new = abs(A[i+1] - A[i-1])
    print(allcost - old + new)

Fixed, accepted submission:
N = int(input())
A = [int(i) for i in input().split()]

A = [0] + A + [0]

allcost = 0
for i in range(len(A) - 1):
    allcost += abs(A[i+1] - A[i])

for i in range(1, N+1):
    old = abs(A[i+1] - A[i]) + abs(A[i] - A[i-1])
    new = abs(A[i+1] - A[i-1])
    print(allcost - old + new)
Problem:
Joisino the magical girl has decided to turn every single digit that exists on this world into 1.  Rewriting a digit i with j (0≤i,j≤9) costs c_{i,j} MP (Magic Points).  She is now standing before a wall. The wall is divided into HW squares in H rows and W columns, and at least one square contains a digit between 0 and 9 (inclusive).  You are given A_{i,j} that describes the square at the i-th row from the top and j-th column from the left, as follows:    * If A_{i,j}≠-1, the square contains a digit A_{i,j}.   * If A_{i,j}=-1, the square does not contain a digit.  Find the minimum total amount of MP required to turn every digit on this wall into 1 in the end.

Incorrect submission (verdict: Wrong Answer):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall

h, w = map(int, readline().split())
memo_graph = [list(map(int, readline().split())) for _ in range(10)]
cost = floyd_warshall(csr_matrix(memo_graph))
ans = 0
for i in range(h):
    for a in list(map(int, readline().split())):
        if a != -1:
            ans += cost[a][1]
print(ans)


Fixed, accepted submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall

h, w = map(int, readline().split())
memo_graph = [list(map(int, readline().split())) for _ in range(10)]
cost = floyd_warshall(csr_matrix(memo_graph))
ans = 0
for i in range(h):
    for a in list(map(int, readline().split())):
        if a != -1:
            ans += cost[a][1]
print(int(ans))
Problem:
Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.

Incorrect submission (verdict: Wrong Answer):
N,K = map(int,input().split())
if 2*K-1 <= N:
    print('Yes')
else:
    print('No')

Fixed, accepted submission:
N,K = map(int,input().split())
if 2*K-1 <= N:
    print('YES')
else:
    print('NO')
Problem:
You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order:    * Choose two among A, B and C, then increase both by 1.   * Choose one among A, B and C, then increase it by 2.  It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.

Incorrect submission (verdict: Wrong Answer):
A, B, C = map(int, sorted(list(map(int, input().split()))))

print(A, B, C)
count = 0

A += C - B
count += C - B

count += (C - A) / 2
count = int(count)

if (C - A) % 2 != 0 :
    count += 2

print(count)


Fixed, accepted submission:
A, B, C = map(int, sorted(list(map(int, input().split()))))

count = 0

A += C - B
count += C - B

count += (C - A) / 2
count = int(count)

if (C - A) % 2 != 0 :
    count += 2

print(count)
Problem:
For a given weighted graph $G = (V, E)$, find the shortest path from a source to each vertex. For each vertex $u$, print the total weight of edges on the shortest path from vertex $0$ to $u$.

Incorrect submission (verdict: Wrong Answer):
from heapq import*
n=int(input())
A=[[]for _ in[0]*n]
for _ in[0]*n:
 e=list(map(int,input().split()))
 for i in range(e[1]):k=2*-~i;A[e[0]]+=[(e[k],e[k+1])]
H=[[0,0]]
d=[0]+[1e6]*n
c=[1]*n
while H:
 f=heappop(H)
 print(f)
 u=f[1]
 c[u]=0
 if d[u]>=f[0]:
  for s in A[u]:
   v=s[0]
   if c[v]and d[v]>d[u]+s[1]:
    d[v]=d[u]+s[1]
    heappush(H,[d[v],v])
for i in range(n):print(i,d[i])


Fixed, accepted submission:
from heapq import*
def m():
 n=int(input())
 A=[]
 for _ in[0]*n:
  e=list(map(int,input().split()))
  A+=[zip(e[2::2],e[3::2])]
 d=[0]+[float('inf')]*n
 H=[(0,0)]
 while H:
  u=heappop(H)[1]
  for v,c in A[u]:
   t=d[u]+c
   if d[v]>t:
    d[v]=t
    heappush(H,(t,v))
 print('\n'.join(f'{i} {d[i]}'for i in range(n)))
m()
Problem:
We say that a odd number N is _similar to 2017_ when both N and (N+1)/2 are prime.  You are given Q queries.  In the i-th query, given two odd numbers l_i and r_i, find the number of odd numbers x similar to 2017 such that l_i ≤ x ≤ r_i.

Incorrect submission (verdict: Time Limit Exceeded):
import math as m

def judge_prime(num):
    isPrime = [True]*(num+1)
    isPrime[0] = False
    isPrime[1] = False
    border = m.sqrt(num)
    i = 2
    while i <= border:
        if isPrime[i]:
            j = i*2
            while j <= num:
                isPrime[j] = False
                j += i
        i += 1
        
    prime_list = []
    for prime in range(num+1):
        if isPrime[prime]:
            prime_list.append(prime)
        
    return prime_list
        
    
    
def main():
    #input
    Q1 = 1
    LR1 = [[3,7]]
    
    Q2 = 4
    LR2 = [[13, 13],
                [7, 11],
                [7, 11],
                [2017, 2017]]
    
    
    Q = Q2
    LR = LR2

    # 1. find 2017-like number
    MAX_Q = 10**5
    
    prime_list = judge_prime(MAX_Q)
    

    like2017_list = []
    for prime in prime_list:
        if (prime+1)/2 in prime_list:
            like2017_list.append(prime)
            
    
    # judge
    for i in range(Q):
        print(sum([LR[i][0]<=like2017 <= LR[i ][1] for like2017 in like2017_list]))


    
if __name__ == "__main__":
    main()

Fixed, accepted submission:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

def make_prime_list(lower: int, upper: int) -> list:
    if upper <= 2:
        return []
    
    prime_list = []
    
    is_prime = [True]*upper
    is_prime[0] = False
    is_prime[1] = False
    
    n = 2
    while n**2 < upper:
        if is_prime[n]:
            res = 2*n
            while res < upper:
                is_prime[res] = False
                res += n
                
        n += 1
        
    for i in range(lower, upper):
        if is_prime[i]:
            prime_list.append(i)
            
    return prime_list

def is_like2017(num: int, prime_set) -> int:
    if num in prime_set and (num+1)//2 in prime_set:
        return 1
    else:
        return 0

from itertools import accumulate

MAX_N = 10**5+1

prime_list = make_prime_list(1,MAX_N)
prime_set = set(prime_list)

prime_cnt = [0]*MAX_N

for i in range(1,MAX_N,2):
    prime_cnt[i] += is_like2017(i, prime_set)
        
prime_cum = list(accumulate(prime_cnt))


q = ni()
for _ in range(q):
    l,r = li()
    print(prime_cum[r] - prime_cum[l-1])
Problem:
Iroha is very particular about numbers. There are K digits that she dislikes: D_1, D_2, ..., D_K.  She is shopping, and now paying at the cashier. Her total is N yen (the currency of Japan), thus she has to hand at least N yen to the cashier (and possibly receive the change).  However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.  Find the amount of money that she will hand to the cashier.

Incorrect submission (verdict: Wrong Answer):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()
D = LIST()
d_s = set(D)
for i in range(N, 10000):
    l = list(str(i))
    l = list(map(int, l))
    l_s = set(l)
    if d_s.isdisjoint(l_s):
        print(i)
        exit()






Fixed, accepted submission:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()
D = LIST()

q = deque([""])

s = set([i for i in range(0, 10)]) 
d = set(D)
kouho = s - d
kouho = sorted(list(set(kouho)))
while q:
    a = q.popleft()
    # print(q)

    if len(a) != 0:
        if int(a) >= N:
            print(a)
            break
    for d in kouho:
        b = deepcopy(a)
        # if len(b) == 0 and d == 0:
        
        # else:
        b += str(d)
        q.append(b)
Problem:
English text is not available in this practice contest.  このたび新しい豪邸を建てることを決めた大富豪の品田氏は，どの街に新邸を建てようかと悩んでいる．実は，品田氏は正方形がとても好きという変わった人物であり，そのため少しでも正方形の多い街に住みたいと思っている．  品田氏は，碁盤目状に道路の整備された街の一覧を手に入れて，それぞれの街について，道路により形作られる正方形の個数を数えることにした．ところが，道と道の間隔は一定とは限らないため，手作業で正方形を数えるのは大変である．そこであなたには，碁盤目状の道路の情報が与えられたときに，正方形の個数を数えるプログラムを書いて欲しい．

Incorrect submission (verdict: Wrong Answer):
def solve(lis_height,lis_width):
    h=len(lis_height)
    w=len(lis_width)
    dic = {}
    for i in range(h):
        k=0
        for j in range(i,h):
            k+=lis_height[j]
            if k in dic:
                dic[k]+=1
            else:
                dic[k]=1
    ans = 0
    for i in range(w):
        k=0
        for j in range(j,w):
            k+=lis_width[j]
        if k in dic:
            ans += dic[k]

    print(ans)


while True:
    h,w=[int(i) for i in input().split(' ')]
   # print(a)
    if h == 0:
        break
    lis_h =[]
    lis_w=[]
    for i in range(h):
        lis_h.append(int(input()))
    for i in range(w):
        lis_w.append(int(input()))

    solve(lis_h,lis_w)



Fixed, accepted submission:
def solve(lis_height,lis_width):
    h=len(lis_height)
    w=len(lis_width)
    dic = {}
    for i in range(h):
        k=0
        for j in range(i,h):
            k+=lis_height[j]
            if k in dic:
                dic[k]+=1
            else:
                dic[k]=1
    ans = 0
    #print(dic)
    #print(w,'a')
    for i in range(w):
        k=0
        for j in range(i,w):
            k+=lis_width[j]
           # print(j)
            if k in dic:
                ans += dic[k]
                #print(k,dic[k])

    print(ans)


while True:
    h,w=[int(i) for i in input().split(' ')]
   # print(a)
    if h == 0:
        break
    lis_h =[]
    lis_w=[]
    for i in range(h):
        lis_h.append(int(input()))
    for i in range(w):
        lis_w.append(int(input()))

    solve(lis_h,lis_w)