Problem:


  MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

極秘調査

秘密の組織アイヅアナリティクス(AiZu AnalyticS)は、極秘の調査を開始した。ターゲットになっている人物は N 人いて、1 から N の識別番号が付けられている。AZAS 情報戦略調査員であるあなたは、
ターゲットの中から、以下の条件を少なくとも一つ満たす人物の数を割り出すことにした。

 組織 $A$ に属さず、かつ、商品 $C$ を所持している者。

 組織 $B$ に属し、かつ、商品 $C$ を所持している者。

組織 $A$ に属している者、組織 $B$ に属している者、商品 $C$ を所持している者の識別番号が入力として与えられたとき、条件を満たす人物の数を割り出すプログラムを作成せよ。ただし、どちらの条件も満たす人物を重複して数えないように注意せよ。

（補足：上記の条件について）

1 から $N$ までの自然数の集合から、いくつかの要素を選んだ集合を $A$，$B$，$C$ とする。条件を満たす人物の数は、$(\bar{A} \cap C) \cup (B \cap C)$ (図の塗られた部分) を満たす要素の個数である。ただし、$\bar{A}$ は集合 $A$ の補集合とする。

Input

入力は以下の形式で与えられる。

N
X a1 a2 ... aX
Y b1 b2 ... bY
Z c1 c2 ... cZ

入力は４行であり、１行目に調査対象の人数 N (1 ≤ N ≤ 100) が与えられる。２行目に、組織 $A$ に属している者の数 X (0 ≤ X ≤ N)と、それに続いて組織 $A$ に属している者の識別番号 ai (1 ≤ ai ≤ N) が与えられる。３行目に、組織 $B$ に属している者の数 Y (0 ≤ Y ≤ N) と、それに続いて組織 $B$ に属している者の識別番号 bi (1 ≤ bi ≤ N) が与えられる。４行目に、商品 $C$ を所持している者の数 Z (0 ≤ Z ≤ N) と、それに続いて商品 $C$ を所持している者の識別番号 ci (1 ≤ ci ≤ N) が与えられる。

Output

条件を満たす人物の数を１行に出力する。

Sample Input 1

5
3 1 2 3
2 4 5
2 3 4

Sample Output 1

1

Sample Input 2

100
3 1 100 4
0
2 2 3

Sample Output 2

2



Sample input:
5
3 1 2 3
2 4 5
2 3 4


Sample output:
1

Submission status: Accepted

Solution code:
n = int(input())
x = set(map(int, input().split()[1:]))
y = set(map(int, input().split()[1:]))
z = set(map(int, input().split()[1:]))
print(len(z - x) + len(y & z) - len((z-x) & y))

Submission status: Accepted

Solution code:

N = int(input())
X = [int(i) for i in input().split()]
Y = [int(i) for i in input().split()]
Z = [int(i) for i in input().split()]

table = [[0 for i in range(3)] for j in range(N)]

for i in range(1, len(X)):
    table[X[i] - 1][0] = 1
for i in range(1, len(Y)):
    table[Y[i] - 1][1] = 1
for i in range(1, len(Z)):
    table[Z[i] - 1][2] = 1

ans = 0
for i in range(len(table)):
    if (table[i][0] == 0 and table[i][2] == 1) or (table[i][1] == 1 and table[i][2] == 1):
        ans = ans + 1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = set(input().split()[1:])
B = set(input().split()[1:])
C = set(input().split()[1:])
S = A | B | C
print(len(((S-A)&(C)) | (B&C)))

Submission status: Accepted

Solution code:
n = input()
V = [0]*n
for i in [1, 2, 4]:
    for e in map(int, raw_input().split()[1:]):
        V[e-1] += i
print sum((e&4>0)*(e!=5)for e in V)

Submission status: Accepted

Solution code:
N=int(input())
a,b,c=list(map(int,input().split())),list(map(int,input().split())),list(map(int,input().split()))
d=set(a[1:]+b[1:]+c[1:])
ans=0
for e in d:
    if(e not in a[1:]and e in c[1:])or( e in b[1:]and e in c[1:]):
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
a = [int(num) for num in s.split()]
s = input()
b = [int(num) for num in s.split()]
s = input()
c = [int(num) for num in s.split()]

isa = []
isb = []
isc = []
for i in range(n + 1):
    isa.append(False)
    isb.append(False)
    isc.append(False)

for i in range(1, a[0] + 1):
    isa[a[i]] = True
for i in range(1, b[0] + 1):
    isb[b[i]] = True
for i in range(1, c[0] + 1):
    isc[c[i]] = True

C = c[0]
CA = 0
ABC = 0
for i in range(1, n + 1):
    if isc[i] & isa[i]:
        CA += 1
    if isa[i] & isb[i] & isc[i]:
        ABC += 1

print(C - CA + ABC)

Submission status: Accepted

Solution code:
N = int(input())
U = set([i+1 for i in range(N)])
A = set([int(x) for x in input().split()[1:]])
B = set([int(x) for x in input().split()[1:]])
C = set([int(x) for x in input().split()[1:]])

result = ((U-A) & C) | (B & C)
print(len(result))

Submission status: Accepted

Solution code:
N = int(input())
U = [str(i+1) for i in range(N)]
X = input().split()[1:]
Y = input().split()[1:]
Z = input().split()[1:]
print(len(((set(U) - set(X)) & set(Z)) | (set(Y) & set(Z))))

Submission status: Accepted

Solution code:
_ = int(input())
_, *a = map(int, input().split())
_, *b = map(int, input().split())
_, *c = map(int, input().split())
a, b, c = set(a), set(b), set(c)
print(len((c - a)|(b & c)))

Submission status: Accepted

Solution code:
input()
a = set(input().split()[1:])
b = set(input().split()[1:])
c = set(input().split()[1:])
print(len((c - a)|(b & c)))

Submission status: Accepted

Solution code:
n = int(input())
mp = [[0, 0, 0] for _ in range(n)]
xs = list(map(int, input().split()))
ys = list(map(int, input().split()))
zs = list(map(int, input().split()))

for a in xs[1:]:
  mp[a - 1][0] = 1
for b in ys[1:]:
  mp[b - 1][1] = 1
for c in zs[1:]:
  mp[c - 1][2] = 1

ans = 0
for t in mp:
  if t[2] and ((not t[0]) or t[1]):
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
# coding=utf-8

if __name__ == '__main__':
    N = int(input())
    all_list = {i for i in range(1, N+1)}
    A_list = list(map(int, input().split()))
    B_list = list(map(int, input().split()))
    C_list = list(map(int, input().split()))
    A_number = A_list[0]
    A_identity = set(A_list[1:])
    B_number = B_list[0]
    B_identity = set(B_list[1:])
    C_number = C_list[0]
    C_identity = set(C_list[1:])
    not_A_identity = all_list - A_identity

    cond1 = not_A_identity & C_identity
    cond2 = B_identity & C_identity

    suspected = cond1 | cond2
    print(len(suspected))

Submission status: Accepted

Solution code:
def inp2list():
	tmp=list(map(int, input().split()))
	del tmp[0]
	return tmp

N = int(input())
A, B, C = inp2list(), inp2list(), inp2list()
R = [False for _ in range(N)]
for i in C:
	if A.count(i)==0 or B.count(i)!=0:
		R[i-1] = True

print(R.count(True))

Submission status: Accepted

Solution code:
N = int(input())
A = [0]*N
B = [0]*N
C = [0]*N

lineA = list(map(int, input().split()))
lineB = list(map(int, input().split()))
lineC = list(map(int, input().split()))

for i in range( 1, lineA[0]+1 ): A[lineA[i]-1] = 1
for i in range( 1, lineB[0]+1 ): B[lineB[i]-1] = 1
for i in range( 1, lineC[0]+1 ): C[lineC[i]-1] = 1
    
ans = 0
for i in range( N ) :
    if ( ((not A[i]) and C[i]) or (B[i] and C[i]) ):
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
Target =  [0] * N

A = list(map(int, input().split()))
if A[0] != 0 :
    for i in range(A[0]) :
        Target[A[i+1]-1]  += 1

B = list(map(int, input().split()))
if B[0] != 0 :
    for i in range(B[0]) :
        Target[B[i+1]-1] += 2
    
C = list(map(int, input().split()))
if C[0] != 0 :
    for i in range(C[0]) :
        Target[C[i+1]-1] +=4

S = 0
for i in range(N) :
    if Target[i] == 4 or Target[i] == 6 or Target[i] == 7 :
        S += 1

print(S)

Submission status: Accepted

Solution code:
n = int(input())
x,*a = list(map(int, input().split()))
y,*b = list(map(int, input().split()))
z,*c = list(map(int, input().split()))

u = set(range(1,n+1))
a = set(a)
b = set(b)
c = set(c)

s1 = (u - a) & c
s2 = b & c
s3 = s1 & s2

print(len(s1) + len(s2) -len(s3))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
del a[0]
b = list(map(int,input().split()))
del b[0]
c = list(map(int,input().split()))
del c[0]
count = 0
for i in range(n):
    i += 1
    if i in c and ((not i in a) or i in b):
        count += 1
print(count)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))[1:]
b=list(map(int,input().split()))[1:]
c=list(map(int,input().split()))[1:]
x = 0
y = 0
for i in range(1,n+1):
    if (i not in a) and (i not in b) and (i in c):
        x += 1
    elif (i in b) and (i in c):
        y += 1
print(x+y)

Submission status: Accepted

Solution code:
N=int(input())
X=list(map(int,input().split()))
Y=list(map(int,input().split()))
Z=list(map(int,input().split()))

X.pop(0)
Y.pop(0)
Z.pop(0)

result=[i for i in Z if i not in X or i in Y]
print(len(result))

Submission status: Accepted

Solution code:
n = int(input())
x, *a = map(int, input().split())
y, *b = map(int, input().split())
z, *c = map(int, input().split())

_a = set(range(1, n+1)) ^ set(a)
match1 = set(_a) & set(c)
match2 = set(b) & set(c)
print(len(match1 | match2))

Submission status: Accepted

Solution code:
n=int(input())
member=[0]*(n+1)
count=0
a=list(map(int,input().split()))
for i in range(1,a[0]+1):
    member[a[i]]+=1
b=list(map(int,input().split()))
for i in range(1,b[0]+1):
    member[b[i]]+=2
c=list(map(int,input().split()))
for i in range(1,c[0]+1):
    member[c[i]]+=4
for i in member:
    if i==4 or i>5:count+=1
print(count)

Submission status: Accepted

Solution code:
N = int(input())
A, B, C =list(map(int, input().split())), list(map(int, input().split())), list(map(int, input().split()))
D = set(A[1:] + B[1:] + C[1:])
ans = 0
for e in D:
    if(e not in A[1:] and e in C[1:]) or (e in B[1:] and e in C[1:]):
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

a = list(map(int, input().split()))
X = a.pop(0)
a = set(a)
b = list(map(int, input().split()))
Y = b.pop(0)
b = set(b)
c = list(map(int, input().split()))
Z = c.pop(0)
c = set(c)

a_bar = {x for x in range(1, n+1) if x not in a}

ans = (a_bar & c) | (b & c)
print(len(ans))