A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler displayed n compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix some mistake and then another one mistake.
However, despite the fact that B is sure that he corrected the two errors, he can not understand exactly what compilation errors disappeared — the compiler of the language which B uses shows errors in the new order every time! B is sure that unlike many other programming languages, compilation errors for his programming language do not depend on each other, that is, if you correct one error, the set of other error does not change.
Can you help B find out exactly what two errors he corrected?
Input
The first line of the input contains integer n (3 ≤ n ≤ 105) — the initial number of compilation errors.
The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the errors the compiler displayed for the first time.
The third line contains n - 1 space-separated integers b1, b2, ..., bn - 1 — the errors displayed at the second compilation. It is guaranteed that the sequence in the third line contains all numbers of the second string except for exactly one.
The fourth line contains n - 2 space-separated integers с1, с2, ..., сn - 2 — the errors displayed at the third compilation. It is guaranteed that the sequence in the fourth line contains all numbers of the third line except for exactly one.
Output
Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively.
Examples
Input
5
1 5 8 123 7
123 7 5 1
5 1 7
Output
8
123
Input
6
1 4 3 3 5 7
3 7 5 4 3
4 3 7 5
Output
1
3
Note
In the first test sample B first corrects the error number 8, then the error number 123.
In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
We need to find two numbers: first the one that disappeared from the first list to the second list, second the one that disappeared from the second list to the third list.
Given:
First list A of length n.
Second list B of length n-1: contains all numbers from A except exactly one (the first corrected error). Note: there can be duplicates; we need to account for them. Since errors are integers, and correction removes exactly one occurrence of some number? The problem statement: "if you correct one error, the set of other error does not change." However, errors are represented as positive integers. If there are multiple errors with same number, correcting one error means one occurrence disappears. Since the compiler shows errors in new order each time, the lists are permutations (but not necessarily sorted). But importantly, the counts matter.
Thus, to find the missing number from A to B, we need to find an integer that appears one less time in B compared to A. Since B contains exactly one fewer element, we need to identify which number's count decreased by one.
Similarly, from B to C (C length n-2), we need to find the number whose count decreased by one from B to C.
We can do this by counting frequencies using maps (hash maps) or by sorting and comparing.
Constraints up to 1e5, sorting is fine. Use dictionaries.
Approach: Count frequencies of numbers in A. Then subtract frequencies from B (i.e., decrement counts as we iterate through B). The number that ends up with a positive count (i.e., not zero) is the missing one. But careful: Because there could be duplicates, we need to find the number that has a count difference of 1. So we can use a map: for each number in A, increment count. Then for each number in B, decrement count. The number that still has count 1 is the first corrected error. Actually, some numbers might have negative counts if B has more of a number than A? That can't happen because B is a subset (missing exactly one element). So after decrement, only one number will have count 1, others 0. But we must ensure that if a number appears more than once, we might have count >0 for that number if it appears less in B. For example, A: [3,3,5], B: [3,5]. Then counts: after counting A: {3:2,5:1}. After decrement B: {3:1,5:0}. So 3 remains count 1. So that's correct.
Thus first missing = key with count>0 after processing B.
Similarly, we can compute the second missing from B and C. But careful: B we have as array, but we could recompute counts from B after we know B. But easier: do similar: count B frequencies, then subtract C frequencies, get the key with count 1.
But note: after we output the first missing, we might need the second missing. We don't need to modify B after correction? Actually the problem: find the two errors that disappeared after the first and second corrections. That's exactly the missing element from A to B and missing from B to C.
So implement:
Read n.
Read list A (n integers)
Read list B (n-1 integers)
Read list C (n-2 integers)
Compute missing1:
Use a dict or Counter.
For x in A: dict[x] += 1
For y in B: dict[y] -= 1
Then missing1 = key where dict[key] == 1? Actually if there are duplicates, after subtraction, the count for the missing number should be 1. For other numbers, count should be 0. But there could be negative counts? Not if B is a proper subset, but due to duplicate values and removal of one occurrence, counts for other numbers should stay 0. However, if there is a number that appears in A with count k, and in B appears also k times because the missing occurrence is of a different number, then count becomes 0. So only the missing number will have count 1. However, consider the scenario: A has a number that appears twice, and B has the same number appearing twice? Actually B has all numbers except one occurrence of some number. So for numbers other than the missing, the counts are equal. For the missing number, its count in A is k, in B is k-1, so after decrement we get 1. So yes.
But note: what if the missing number appears only once in A? Then after decrement count becomes 0? Actually if it appears once, then in B it appears 0 times, so after increment on A we get count 1, after decrement on B we subtract 0? Wait careful: we start dict from A: for each x in A, dict[x]++. Then for each y in B, dict[y]--. So if a number appears exactly once in A and is missing in B, then we have dict[that] = 1 after increment, and we never decrement because it's not in B. So final dict[that] = 1. Good. If appears k>1 and missing one, we have dict[that] = k after increment, then we subtract (k-1) because B contains it k-1 times, so final dict[that] = 1. So indeed final count for missing is 1. Others final 0.
Thus we can find missing1 by scanning dict for value == 1.
Similarly for missing2:
We can either compute from B and C similarly: count B, subtract C, find key with count 1.
But we have to be careful: B is the list after first correction; we already have it. So we can do:
dict2 = {}
For y in B: dict2[y] += 1
For z in C: dict2[z] -= 1
missing2 = key where dict2[key] == 1.
Alternatively, we could reuse the previous dict? Not straightforward.
Edge Cases: Large numbers up to 1e9, so use dict.
Complexity O(n) time, O(n) space.
We should output missing1 on one line? The problem says "Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively." So we print two numbers separated by space? Actually sample output:
8
123
But they show each on a new line? Wait, let's check the example:
Input:
5
1 5 8 123 7
123 7 5 1
5 1 7
Output:
8
123
They printed each on a separate line. But the problem statement says "Print two numbers on a single line". However sample output shows each on its own line. This is ambiguous. Probably the intended output is one per line? Let's re-read: "Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively." That suggests they should be on the same line. But the sample shows each on a separate line. Possibly a formatting issue. Let's look at the second example:
Input:
6
1 4 3 3 5 7
3 7 5 4 3
4 3 7 5
Output:
1
3
Again each on separate line. But the statement says "on a single line". Actually maybe the statement is mis-written. Many Codeforces problems: "Print two numbers on a single line" but sample shows each on its own line? Wait, I recall Codeforces problem 519B - A and B and Compilation Errors. That's exactly this problem. In that problem, the output is each answer on a new line. Let me recall: The problem title "A and B and Compilation Errors". In Codeforces, the output specification: "Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively." But many solutions output each on a new line. Actually I've solved this before: the common output is two lines: first missing, then second missing. Check problem statement: in the Russian version maybe it's each on new line. In the English version they wrote "on a single line"? Let's check memory: I think the correct output is each on a separate line. Because the sample shows separate lines. So we will output missing1 on first line, missing2 on second line.
But to be safe, we can output them on separate lines as per sample.
Now test with given examples:
Example1:
A: [1,5,8,123,7]
B: [123,7,5,1] -> missing 8
C: [5,1,7] -> from B, missing 123 (since B has 123,7,5,1; C has 5,1,7 -> missing 123). So output 8 then 123. Good.
Example2:
A: [1,4,3,3,5,7]
B: [3,7,5,4,3] (5 numbers). Which one is missing from A? A has counts: 1:1,4:1,3:2,5:1,7:1. B has counts: 3:2? Actually B: [3,7,5,4,3] => 3 appears twice, 7 once,5 once,4 once => total 5. So missing is 1 (since A had 1). So first = 1.
Now from B to C: C: [4,3,7,5] (4 numbers). B has [3,7,5,4,3]: counts: 3:2,7:1,5:1,4:1. C has [4,3,7,5]: counts: 4:1,3:1,7:1,5:1. So missing from B is one occurrence of 3. So second = 3. Output 1 then 3. Good.
Thus solution is straightforward.
Implementation notes:
Use sys.stdin.read to read all integers quickly.
Use collections.Counter if available (Python's Counter). But Counter can subtract, but careful: Counter subtraction with '-' produces counts that may go negative. However, we can just use Counter for A, then subtract for B using c.subtract? Actually Counter has a subtract method that allows negative counts, but we can also just do: for y in B: c[y] -= 1. But Counter also supports c - d which returns positive counts only, not negative. That would drop zeros and negative. If we do c = Counter(A); d = Counter(B); then c - d yields counts of elements that have more in c than d, and only positive counts. Since exactly one element will have count 1, we could do (c - d). But be careful: if there are duplicates, (c - d) will contain the element with positive difference. However, (c - d) returns a Counter with only positive counts. Then we can extract the key. But (c - d) yields the multiset difference. That would be exactly the missing element. So missing1 = next(iter(c - d))? But note that (c - d) returns a Counter with possibly multiple keys if there were multiple missing? But problem guarantees exactly one missing. So it's fine.
Similarly for missing2: e = Counter(B); f = Counter(C); missing2 = next(iter(e - f)). That's elegant.
But beware that Counter subtraction may be slower? Not really for n up to 1e5.
Alternatively, we can use sum of all numbers: missing1 = sum(A) - sum(B). That's also possible because it's just one missing element. But that's only valid if each error is a number, and removal of one error reduces sum by that number. However, this works only if there are no duplicates? Actually sum works even with duplicates because the sum of A minus sum of B equals the missing number. Indeed, if we remove exactly one element from A to get B, then sum(A) - sum(B) = that missing element. That's correct regardless of duplicates. However, caution: if numbers are large, sum could overflow? In Python, ints are arbitrary precision, so fine.
So indeed we can just use sums! This is even simpler and O(n) time, O(1) extra space, and no need to handle duplicates.
But wait: is there any catch? The problem says "the compiler of the language which B uses shows errors in the new order every time! B is sure that unlike many other programming languages, compilation errors for his programming language do not depend on each other, that is, if you correct one error, the set of other error does not change." That implies that the errors are independent and the multiset changes only by removal of one element each time. Summing works because it's a linear operation. So yes, the missing number is simply the difference of sums.
But could there be overflow? Python handles big integers.
But wait: what about possibility that there are multiple errors with same number? Sum method still works because the missing element is a specific occurrence; its value is the number. So sum difference yields that number.
Thus we can just do that.
However, is there any case where sum difference is ambiguous? No, because exactly one element is removed each time.
Thus the simplest solution.
But hold on: In the problem, the second line after correction is B of length n-1, which contains all numbers from A except exactly one. So sum difference gives the missing number. For the third line, C of length n-2, contains all numbers from B except exactly one. So sum difference works.
Thus answer is straightforward.
Implementation:
def solve():
import sys
data = list(map(int, sys.stdin.read().split()))
if not data: return
n = data[0]
# Then next n numbers: A
A = data[1:1+n]
# Next n-1 numbers: B
B = data[1+n:1+n+(n-1)]
# Next n-2 numbers: C
C = data[1+n+(n-1):1+n+(n-1)+(n-2)]
sumA = sum(A)
sumB = sum(B)
sumC = sum(C)
first = sumA - sumB
second = sumB - sumC
# Output each on its own line
sys.stdout.write(str(first) + "\n" + str(second))
But check the indices: data length: 1 (n) + n + (n-1) + (n-2) = 3n - 2. So it's fine.
Edge Cases: n = 3, then B length 2, C length 1. Works.
Thus we can output.
But is there any scenario where sum difference yields wrong result due to integer overflow in other languages? In Python it's fine.
Thus solution is simple.
Now we must be careful: the problem states "the errors are displayed in new order every time", but that does not affect sum.
Thus final answer.
We'll produce code accordingly.
Now, about output format: sample shows each on separate line. So we'll do that.
Thus final solution.
We'll include explanation.
Now let's write the solution with proper I/O.
We can also implement with input() lines, but reading all is fine.
Ok. ```python
import sys
def solve() -> None:
data = list(map(int, sys.stdin.read().split()))
if not data:
return
code
n = data[0]
# slices for the three arrays
pos = 1
A = data[pos:pos + n]
pos += n
B = data[pos:pos + (n - 1)]
pos += n - 1
C = data[pos:pos + (n - 2)]
sum_a = sum(A)
sum_b = sum(B)
sum_c = sum(C)
first = sum_a - sum_b
second = sum_b - sum_c
sys.stdout.write(str(first) + "\n" + str(second))