The Contest
Contest: Educational Codeforces Round 76 (Rated for Div. 2)
Difficulty rating: 2000
Tags: data structures, dp, greedy

A team of three programmers is going to play a contest. The contest consists of $$$n$$$ problems, numbered from $$$1$$$ to $$$n$$$. Each problem is printed on a separate sheet of paper. The participants have decided to divide the problem statements into three parts: the first programmer took some prefix of the statements (some number of first paper sheets), the third contestant took some suffix of the statements (some number of last paper sheets), and the second contestant took all remaining problems. But something went wrong — the statements were printed in the wrong order, so the contestants have received the problems in some random order.

The first contestant has received problems $$$a_{1, 1}, a_{1, 2}, \dots, a_{1, k_1}$$$. The second one has received problems $$$a_{2, 1}, a_{2, 2}, \dots, a_{2, k_2}$$$. The third one has received all remaining problems ($$$a_{3, 1}, a_{3, 2}, \dots, a_{3, k_3}$$$).

The contestants don't want to play the contest before they redistribute the statements. They want to redistribute them so that the first contestant receives some prefix of the problemset, the third contestant receives some suffix of the problemset, and the second contestant receives all the remaining problems.

During one move, some contestant may give one of their problems to other contestant. What is the minimum number of moves required to redistribute the problems?

It is possible that after redistribution some participant (or even two of them) will not have any problems.

Input format:
The first line contains three integers $$$k_1, k_2$$$ and $$$k_3$$$ ($$$1 \le k_1, k_2, k_3 \le 2 \cdot 10^5, k_1 + k_2 + k_3 \le 2 \cdot 10^5$$$) — the number of problems initially taken by the first, the second and the third participant, respectively.

The second line contains $$$k_1$$$ integers $$$a_{1, 1}, a_{1, 2}, \dots, a_{1, k_1}$$$ — the problems initially taken by the first participant.

The third line contains $$$k_2$$$ integers $$$a_{2, 1}, a_{2, 2}, \dots, a_{2, k_2}$$$ — the problems initially taken by the second participant.

The fourth line contains $$$k_3$$$ integers $$$a_{3, 1}, a_{3, 2}, \dots, a_{3, k_3}$$$ — the problems initially taken by the third participant.

It is guaranteed that no problem has been taken by two (or three) participants, and each integer $$$a_{i, j}$$$ meets the condition $$$1 \le a_{i, j} \le n$$$, where $$$n = k_1 + k_2 + k_3$$$.

Output format:
Print one integer — the minimum number of moves required to redistribute the problems so that the first participant gets the prefix of the problemset, the third participant gets the suffix of the problemset, and the second participant gets all of the remaining problems.

Constraints:
Time limit: 2.0 s
Memory limit: 512.0 MB

Note:
In the first example the third contestant should give the problem $$$2$$$ to the first contestant, so the first contestant has $$$3$$$ first problems, the third contestant has $$$1$$$ last problem, and the second contestant has $$$1$$$ remaining problem.

In the second example the distribution of problems is already valid: the first contestant has $$$3$$$ first problems, the third contestant has $$$1$$$ last problem, and the second contestant has $$$2$$$ remaining problems.

The best course of action in the third example is to give all problems to the third contestant.

The best course of action in the fourth example is to give all problems to the second contestant.

Example input:
2 1 2
3 1
4
2 5

Example output:
1

Example input:
3 2 1
3 2 1
5 4
6

Example output:
0

Editorial:
Suppose we want to divide $$$r$$$ first problems of the contest between the first contestant and the second contestant (the first contestant will get $$$l$$$ first problems, and the second contestant will get $$$r - l$$$ problems in the middle), and then give all the remaining problems to the third contestant. We are going to iterate on $$$r$$$ from $$$0$$$ to $$$n$$$ and, for each possible $$$r$$$, find the best value of $$$l$$$.
Okay. Now suppose we fixed $$$l$$$ and $$$r$$$, and now we want to calculate the number of problems that should be redistributed. Let's denote $$$cnt_{l, i}$$$ as the number of problems among $$$l$$$ first ones given to the $$$i$$$-th contestant, $$$cnt_{r, i}$$$ as the number of problems among $$$r$$$ last ones given to the $$$i$$$-th contestant, and $$$cnt_{m, i}$$$ as the number of problems in the middle given to the $$$i$$$-th contestant.
Obviously, the answer for fixed $$$l$$$ and $$$r$$$ is $$$cnt_{l, 2} + cnt_{l, 3} + cnt_{m, 1} + cnt_{m, 3} + cnt_{r, 1} + cnt_{r, 2}$$$, but we don't like this expression because we don't know how to minimize it for fixed $$$r$$$. We know that, for fixed $$$r$$$, the values of $$$cnt_{l, i} + cnt_{m, i}$$$ and $$$cnt_{r, i}$$$ are constant. Using that, we may arrive at the fact that minimizing $$$cnt_{l, 2} + cnt_{l, 3} + cnt_{m, 1} + cnt_{m, 3} + cnt_{r, 1} + cnt_{r, 2}$$$ is the same as minimizing $$$cnt_{l, 2} - cnt_{l, 1}$$$ for fixed $$$r$$$ — and now we have a way to quickly find best possible $$$l$$$ for fixed $$$r$$$.