A team of three programmers is going to play a contest. The contest consists of n…
- User
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}, ..., a_{1, k_1}. The second one has received problems a_{2, 1}, a_{2, 2}, ..., a_{2, k_2}. The third one has received all remaining problems (a_{3, 1}, a_{3, 2}, ..., 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
The first line contains three integers k_1, k_2 and k_3 (1 ≤ k_1, k_2, k_3 ≤ 2 ⋅ 10^5, k_1 + k_2 + k_3 ≤ 2 ⋅ 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}, ..., 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}, ..., 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}, ..., 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 ≤ a_{i, j} ≤ n, where n = k_1 + k_2 + k_3.
Output
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.
Examples
Input
2 1 2 3 1 4 2 5
Output
1
Input
3 2 1 3 2 1 5 4 6
Output
0
Input
2 1 3 5 6 4 1 2 3
Output
3
Input
Assistant
pythonimport bisect k1, k2, k3 = map(int, input().split()) a1 = list(map(int, input().split())) a2 = list(map(int, input().split())) a3 = list(map(int, input().split())) a1.sort() a2.sort() a3.sort() n = k1 + k2 + k3 max_x = n val = [0] * (max_x + 1) for x in range(0, n + 1): s1 = bisect.bisect_right(a1, x) cnt_a2 = bisect.bisect_right(a2, x) val[x] = s1 - cnt_a2 max_prefix = [0] * (n + 1) current_max = -float('inf') for x in range(0, n + 1): current_max = max(current_max, val[x]) max_prefix[x] = current_max max_current_sum = 0 for y in range(1, n + 2): if y - 1 < 0: x_max = 0 cnt = 0 else: x_max = max_prefix[y - 1] cnt = bisect.bisect_right(a2, y - 1) s3 = len(a3) - bisect.bisect_left(a3, y) current_sum = x_max + cnt + s3 if current_sum > max_current_sum: max_current_sum = current_sum answer = (k1 + k2 + k3) - max_current_sum print(answer)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.