1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
uses clib;
var
n, m: int32;
a, b, c: array of int64;
i, j: int64;
begin
readln(n, m);
setlength(a, n);
repeat
dec(n);
read(a[n])
until n = 0;
qsort(a);
setlength(b, m);
repeat
dec(m);
read(b[m])
until m = 0;
qsort(b);
setlength(c, 0);
for i in a do
if (bsearch(b, i) > -1) and
((length(c) = 0) or (c[length(c) - 1] < i)) then
begin
setlength(c, length(c) + 1);
c[length(c) - 1] := i
end;
for i in c do
begin
dec(n, 2);
j := bsearch(a, i);
for m := j downto 0 do
if a[m] = i then
inc(n)
else
break;
for m := j to length(a) - 1 do
if a[m] = i then
inc(n)
else
break;
j := bsearch(b, i);
for m := j downto 0 do
if b[m] = i then
inc(n)
else
break;
for m := j to length(b) - 1 do
if b[m] = i then
inc(n)
else
break
end;
writeln(n)
end.
|