The secret organization AiZu AnalyticS has launched a top-secret investigation. There are N people targeted, with identification numbers from 1 to N. As an AZAS Information Strategy Investigator, you have decided to determine the number of people in your target who meet at least one of the following conditions:
Those who do not belong to the organization A and who own the product C.
A person who belongs to the organization B and owns the product C.
A program that calculates the number of people who meet the conditions when the identification number of the person who belongs to the organization A, the person who belongs to the organization , and the person who owns the product is given as
input. Create. However, be careful not to count duplicate people who meet both conditions.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
(Supplement: Regarding the above conditions)
Let A, B, and C be the sets of some elements selected from the set of natural numbers from 1 to N. The number of people who satisfy the condition is the number of elements that satisfy (barAcapC)cup(BcapC) (painted part in the figure). However, barA is a complement of the set A.
Input
The input is given in the following format.
N
X a1 a2 ... aX
Y b1 b2 ... bY
Z c1 c2 ... cZ
The input is 4 lines, and the number of people to be surveyed N (1 ≤ N ≤ 100) is given in the first line. On the second line, the number X (0 ≤ X ≤ N) of those who belong to the organization A, followed by the identification number ai (1 ≤ ai ≤ N) of those who belong to the organization A. Given. On the third line, the number Y (0 ≤ Y ≤ N) of those who belong to the organization B, followed by the identification number bi (1 ≤ bi ≤ N) of those who belong to the organization B. Given. On the fourth line, the number Z (0 ≤ Z ≤ N) of the person who owns the product C, followed by the identification number ci (1 ≤ ci ≤ N) of the person who owns the product C. ) Is given.
Output
Output the number of people who meet the conditions on one line.
Examples
Input
5
3 1 2 3
2 4 5
2 3 4
Output
1
Input
100
3 1 100 4
0
2 2 3
Output
2
We need to parse the problem and compute the number of people satisfying (not in A and in C) OR (B and in C). Essentially: count of elements in C that are either not in A or in B (or both). But careful: This is (C \ A) ∪ (B ∩ C). Equivalent to C ∩ (A complement ∪ B) = C ∩ (complement of A ∪ B). Which is all elements in C that are either not in A or are in B (or both). So we can just iterate over all numbers from 1 to N, check if they are in C, and if they are, check if (not in A) or (in B). But the problem says "be careful not to count duplicate people who meet both conditions." So union set.
But easier: construct sets from input, compute union and count distinct.
We must handle inputs where X, Y, Z may be 0, so no following numbers. Format: each line: first number is count, then that many ids. Possibly no spaces? Actually typical: "3 1 2 3" if X=3. If X=0, then line may be "0" alone, no ids. Same for Y and Z.
So parse accordingly.
Given constraints up to N=100, trivial.
Let's implement.
Edge cases: Overlap between A and B? Not directly relevant. The condition: (not A and C) or (B and C). So if someone is in C and also in B, they count; if they are in C and not in A, they count. If they are in C and both not in A and in B, counted once.
Thus answer = | (C \ A) ∪ (B ∩ C) |.
Alternatively, we can compute: |C| - |C ∩ A| + |B ∩ C| - | (C \ A) ∩ (B ∩ C) |? Actually simpler: |C| - |C ∩ A| + |B ∩ C| - | (C ∩ A complement) ∩ (B ∩ C) |? But (C ∩ A complement) ∩ (B ∩ C) = B ∩ C ∩ A complement. But that's overlapping part counted twice if we sum. So we can compute size of union as: |C \ A| + |B ∩ C| - | (C \ A) ∩ (B ∩ C) |. But easier: just create set for A, B, C. Then iterate over 1..N or over union of candidates.
But we can also compute using set operations: (C - A) union (B & C) = (C - A) | (B & C).
Implement.
Examples:
Input1:
N=5
A: 1,2,3
B:4,5
C:3,4
Compute: C-A = {4} (since 3 in A) ; B∩C = {4} (since 4 in B and C). Union = {4}. Count=1. Output 1.
But there might be nuance: The problem statement mentions "the number of people who meet at least one of the conditions" and "be careful not to count duplicate people who meet both conditions." So yes.
We'll read N, then read line for A, line for B, line for C.
Implementation in Python:
def solve():
import sys
data = sys.stdin.read().strip().split()
if not data:
return
it = iter(data)
N = int(next(it))
# read X and X numbers
X = int(next(it))
A_set = set()
for _ in range(X):
A_set.add(int(next(it)))
Y = int(next(it))
B_set = set()
for _ in range(Y):
B_set.add(int(next(it)))
Z = int(next(it))
C_set = set()
for _ in range(Z):
C_set.add(int(next(it)))
# Compute union
cond_set = (C_set - A_set) | (B_set & C_set)
print(len(cond_set))
But careful: If X=0, then after reading X we don't read any numbers. So using iter approach works fine: we read int for X, then loop X times reading numbers; if X=0 we skip. Same for Y, Z.
Edge case: Input might have newline after X line, but reading all tokens works.
Thus answer.
But I'll double-check reading: The input format states 4 lines, but we can read all tokens. That's fine.
Alternative: use input() lines and split.
We'll produce final answer.
Given the problem is from some contest, but it's trivial.
I'll include explanation.
Now, note that the problem says "However, be careful not to count duplicate people who meet both conditions." So they want union.
Thus final answer is code.
Check with sample.
We'll also test extra: N=1, A empty, B empty, C empty => output 0. A: 1, B: 1, C:1 => conditions: C-A = {} since 1 in A, so not counted; B∩C = {1}, so count=1. So answer 1.
Works.
Now produce final response: Provide code and explanation. The instruction: "The assistant should provide a final answer containing the solution code and explanation." So we should output the solution.
Thus final. We need to compute the number of people satisfying (¬A ∧ C) ∨ (B ∧ C), i.e., all people in C who are either not in A or are in B (or both). Equivalent to the set (C \ A) ∪ (B ∩ C). The answer is the size of this union.
We read N, then the three lines describing sets A, B, C. Since counts can be zero, we handle them properly. We then construct the sets, compute the union, and output its size.
python
import sys
def solve() -> None:
data = sys.stdin.read().strip().split()
if not data:
return
it = iter(data)
N = int(next(it)) # not directly used except for range
# set A
X = int(next(it))
A = {int(next(it)) for _ in range(X)}
# set B
Y = int(next(it))
B = {int(next(it)) for _ in range(Y)}
# set C
Z = int(next(it))
C = {int(next(it)) for _ in range(Z)}
# condition: (C without A) OR (B and C)
result = (C - A) | (B & C)
print(len(result))
if __name__ == "__main__":
solve()