#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *, ...);
int main() {
  int h, w, i, n, blocks;
  while (1) {
    blocks = 0;
    int ar1[21] = {0};
    scanf("%d%d", &h, &w);
    if (h == 0 && w == 0)
      break;
    for (i = 0; i < h; i++) {
      scanf("%d", &n);
      ar1[n]++;
      blocks += n;
    }
    for (i = 0; i < w; i++) {
      scanf("%d", &n);
      if (ar1[n] <= 0)
        blocks += n;
      else
        ar1[n]--;
    }
    printf("%d\n", blocks);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x18(%rbp)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x54,%edx
call   1040 <memset@plt>
lea    0xea3(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
mov    $0x0,%al
call   1050 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
jne    1185 <main+0x55>
cmpl   $0x0,-0xc(%rbp)
jne    1185 <main+0x55>
jmp    1248 <main+0x118>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11d0 <main+0xa0>
lea    0xe63(%rip),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
movslq -0x14(%rbp),%rax
mov    -0x70(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0x70(%rbp,%rax,4)
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    118c <main+0x5c>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1234 <main+0x104>
lea    0xe18(%rip),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
movslq -0x14(%rbp),%rax
cmpl   $0x0,-0x70(%rbp,%rax,4)
jg     1212 <main+0xe2>
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1221 <main+0xf1>
movslq -0x14(%rbp),%rax
mov    -0x70(%rbp,%rax,4),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x70(%rbp,%rax,4)
jmp    1226 <main+0xf6>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11d7 <main+0xa7>
mov    -0x18(%rbp),%esi
lea    0xdc7(%rip),%rdi
call   1030 <printf@plt>
jmp    113f <main+0xf>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movl   $0x0,0x60(%rsp)
lea    0xea7(%rip),%rdi
lea    0x8(%rsp),%rsi
lea    0x4(%rsp),%rdx
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x8(%rsp),%ecx
mov    0x4(%rsp),%eax
mov    %ecx,%edx
or     %eax,%edx
jne    1189 <main+0x69>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe72(%rip),%r14
lea    0xc(%rsp),%rbx
lea    0x4(%rsp),%r13
jmp    11f7 <main+0xd7>
nopl   0x0(%rax)
lea    0xe5e(%rip),%rdi
mov    %r15d,%esi
call   1030 <printf@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movl   $0x0,0x60(%rsp)
lea    0xe26(%rip),%rdi
lea    0x8(%rsp),%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x8(%rsp),%ecx
mov    0x4(%rsp),%eax
mov    %ecx,%edx
or     %eax,%edx
je     1178 <main+0x58>
mov    $0x0,%r15d
test   %ecx,%ecx
jle    1237 <main+0x117>
xor    %r15d,%r15d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
movslq 0xc(%rsp),%rax
addl   $0x1,0x10(%rsp,%rax,4)
add    %eax,%r15d
add    $0x1,%ebp
cmp    0x8(%rsp),%ebp
jl     1210 <main+0xf0>
mov    0x4(%rsp),%eax
test   %eax,%eax
jle    11a0 <main+0x80>
xor    %r12d,%r12d
jmp    1266 <main+0x146>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0xffffffff,%ecx
mov    %ecx,0x10(%rsp,%rax,4)
add    $0x1,%r12d
cmp    0x4(%rsp),%r12d
jge    11a0 <main+0x80>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
movslq 0xc(%rsp),%rax
mov    0x10(%rsp,%rax,4),%ecx
test   %ecx,%ecx
jg     1250 <main+0x130>
add    %r15d,%eax
mov    %eax,%r15d
jmp    1257 <main+0x137>

LLVM IR (-O0):
@.str = [5 x i8] c"%d%d\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [21 x i32]
store i32 0, i32* %1
br label %8
8: ; preds = %0, %61
store i32 0, i32* %6
%9 = bitcast [21 x i32]* %7 to i8*
%10 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %3)
%11 = load i32, i32* %2
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %8
%14 = load i32, i32* %3
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %13
br label %64
17: ; preds = %13, %8
store i32 0, i32* %4
br label %18
18: ; preds = %32, %17
%19 = load i32, i32* %4
%20 = load i32, i32* %2
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %35
22: ; preds = %18
%23 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [21 x i32], [21 x i32]* %7, i64 0, i64 %25
%27 = load i32, i32* %26
%28 = add nsw i32 %27, 1
store i32 %28, i32* %26
%29 = load i32, i32* %5
%30 = load i32, i32* %6
%31 = add nsw i32 %30, %29
store i32 %31, i32* %6
br label %32
32: ; preds = %22
%33 = load i32, i32* %4
%34 = add nsw i32 %33, 1
store i32 %34, i32* %4
br label %18
35: ; preds = %18
store i32 0, i32* %4
br label %36
36: ; preds = %58, %35
%37 = load i32, i32* %4
%38 = load i32, i32* %3
%39 = icmp slt i32 %37, %38
br i1 %39, label %40, label %61
40: ; preds = %36
%41 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
%42 = load i32, i32* %5
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [21 x i32], [21 x i32]* %7, i64 0, i64 %43
%45 = load i32, i32* %44
%46 = icmp sle i32 %45, 0
br i1 %46, label %47, label %51
47: ; preds = %40
%48 = load i32, i32* %5
%49 = load i32, i32* %6
%50 = add nsw i32 %49, %48
store i32 %50, i32* %6
br label %57
51: ; preds = %40
%52 = load i32, i32* %5
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [21 x i32], [21 x i32]* %7, i64 0, i64 %53
%55 = load i32, i32* %54
%56 = add nsw i32 %55, -1
store i32 %56, i32* %54
br label %57
57: ; preds = %51, %47
br label %58
58: ; preds = %57
%59 = load i32, i32* %4
%60 = add nsw i32 %59, 1
store i32 %60, i32* %4
br label %36
61: ; preds = %36
%62 = load i32, i32* %6
%63 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %62)
br label %8
64: ; preds = %16
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"%d%d\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [21 x i32]
%5 = bitcast i32* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = bitcast [21 x i32]* %4 to i8*
%9 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %2)
%10 = load i32, i32* %1
%11 = icmp eq i32 %10, 0
%12 = load i32, i32* %2
%13 = icmp eq i32 %12, 0
%14 = select i1 %11, i1 %13, i1 false
br i1 %14, label %65, label %15
15: ; preds = %0, %56
%16 = phi i32 [ %62, %56 ], [ %12, %0 ]
%17 = phi i32 [ %60, %56 ], [ %10, %0 ]
%18 = icmp sgt i32 %17, 0
br i1 %18, label %25, label %21
19: ; preds = %25
%20 = load i32, i32* %2
br label %21
21: ; preds = %19, %15
%22 = phi i32 [ %16, %15 ], [ %20, %19 ]
%23 = phi i32 [ 0, %15 ], [ %34, %19 ]
%24 = icmp sgt i32 %22, 0
br i1 %24, label %38, label %56
25: ; preds = %15, %25
%26 = phi i32 [ %34, %25 ], [ 0, %15 ]
%27 = phi i32 [ %35, %25 ], [ 0, %15 ]
%28 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%29 = load i32, i32* %3
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [21 x i32], [21 x i32]* %4, i64 0, i64 %30
%32 = load i32, i32* %31
%33 = add nsw i32 %32, 1
store i32 %33, i32* %31
%34 = add nsw i32 %29, %26
%35 = add nuw nsw i32 %27, 1
%36 = load i32, i32* %1
%37 = icmp slt i32 %35, %36
br i1 %37, label %25, label %19
38: ; preds = %21, %51
%39 = phi i32 [ %52, %51 ], [ %23, %21 ]
%40 = phi i32 [ %53, %51 ], [ 0, %21 ]
%41 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%42 = load i32, i32* %3
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [21 x i32], [21 x i32]* %4, i64 0, i64 %43
%45 = load i32, i32* %44
%46 = icmp slt i32 %45, 1
br i1 %46, label %47, label %49
47: ; preds = %38
%48 = add nsw i32 %42, %39
br label %51
49: ; preds = %38
%50 = add nsw i32 %45, -1
store i32 %50, i32* %44
br label %51
51: ; preds = %47, %49
%52 = phi i32 [ %48, %47 ], [ %39, %49 ]
%53 = add nuw nsw i32 %40, 1
%54 = load i32, i32* %2
%55 = icmp slt i32 %53, %54
br i1 %55, label %38, label %56
56: ; preds = %51, %21
%57 = phi i32 [ %23, %21 ], [ %52, %51 ]
%58 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %57)
%59 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %2)
%60 = load i32, i32* %1
%61 = icmp eq i32 %60, 0
%62 = load i32, i32* %2
%63 = icmp eq i32 %62, 0
%64 = select i1 %61, i1 %63, i1 false
br i1 %64, label %65, label %15
65: ; preds = %56, %0
ret i32 0
}