Problem:
Search I You are given a sequence of n integers S and a sequence of different q integers T. Write a program which outputs C, the number of integers in T which are also in the set S. Input In the first line n is given. In the second line, n integers are given. In the third line q is given. Then, in the fourth line, q integers are given. Output Print C in a line. Constraints  n ≤ 10000  q ≤ 500  0 ≤ an element in S ≤ 10 9  0 ≤ an element in T ≤ 10 9  Sample Input 1 5
1 2 3 4 5
3
3 4 1 Sample Output 1 3 Sample Input 2 3
3 1 2
1
5 Sample Output 2 0 Sample Input 3 5
1 1 2 2 3
2
1 2 Sample Output 3 2 Notes

Solution (Python):
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
S = sorted(S)
T = sorted(T)
reg = 0
count = 0
for i in range(q):
    for j in range(reg, n):
        if T[i] > S[j]:
            reg = j
        elif T[i] == S[j]:
            reg = j
            count += 1
            break
        else:
            break
print(count)

Solution (Python):


"""
線形探索
"""

N = int(input())
sN = list(map(int, input().split()))
Q = int(input())
tQ = list(map(int, input().split()))

sN = list(set(sN))

cnt = 0
for i in range(Q):
    for j in range(len(sN)):
        if tQ[i] == sN[j]:
            cnt += 1
            
            break
print(cnt)

Solution (Python):
n = int(input())
s = list(map(int, input().split()))
q = int(input())
t = list(map(int, input().split()))

count = 0

for i in t:
    for j in s:
        if i == j:
            count += 1
            break
print(count)

Solution (Python):
n = int(input())
S = list(map(int,input().split()))
q = int(input())
T = list(map(int,input().split()))

cnt = 0
for x in T:
    for q in S:
        
        if x==q:
            cnt += 1
            break
            
print(cnt)

Solution (Python):
n = int(input())
S = [int(x) for x in input().split()]

q = int(input())
T = [int(x) for x in input().split()]

ans = 0
for i in range(q):
    find = 0
    for j in range(n):
        if S[j] == T[i]:
            find = 1
    ans = ans + find
print(ans)

Solution (Python):
n = int(input())
s = set(map(int, input().split()))
q = int(input())
t = set(map(int, input().split()))

print(len(s & t))

Solution (Python):
import sys

sys.stdin.readline()
s = set(map(int, sys.stdin.readline().split()))
sys.stdin.readline()

print(sum(
    t in s
    for t in map(int, sys.stdin.readline().split())
))

Solution (Python):
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001


N = int(input())
S = list(map(int,input().split()))

DICT = {}

for i in range(len(S)):
    DICT[S[i]] = True

Q = int(input())
T = list(map(int,input().split()))

ans = 0

for i in range(len(T)):
    if DICT.__contains__(T[i]):
        ans += 1

print("%d"%(ans))

Solution (Python):
def main():
    input()
    s = [int(i) for i in input().split()]
    input()
    t = [int(i) for i in input().split()]
    print(sum([i in s for i in t]))


if __name__ == '__main__':
    main()

Solution (Python):






import sys
input = sys.stdin.readline


def main():
    n1 = int(input())
    s1 = set(map(int,input().split()))
    n2 = int(input())
    s2 = set(map(int,input().split()))
    print (len(s1 & s2))

if __name__ == '__main__':
   main()

Solution (Python):
n = int(input())
S = [int(i) for i in input().split()]
q = int(input())
T = [int(i) for i in input().split()]
counter = 0
for i in range(q):
    if T[i] in S:
        counter += 1
    else:
        pass
print(counter)

Solution (Python):


def get_set3(S:list, T:list):
    D:dict = {}
    C = []
    for s in S:
        D[s] = 1
    for t in T:
        if t in D.keys() and D[t] == 1:
            D[t] = 2
            C.append(t)
    return C

def input_array():
    n = int(input())
    S = list(map(int, input().split()))
    return S


if __name__ == '__main__':
    S = input_array()
    T = input_array()
    ret = get_set3(S, T)
    print(len(set(ret)))

Solution (Python):

import copy

def linearSearch(n, S, t):
    i = 0
    key = t
    S.append(t)
    while S[i] != t:
        i = i+1
    if i == n:
        return False
    
    return True

if __name__ == '__main__':
    n = int(input())
    S = list(map(int,input().split()))
    q = int(input())
    T = list(map(int,input().split()))
    
    C = 0
    for i in range(q):
        isExist = linearSearch(n, copy.deepcopy(S), T[i])
        if isExist :
            C = C + 1
    print(C)

Solution (Python):


def linear_search(key, A):
    for i, v in enumerate(A):
        if v == key:
            
            return i
    return 'Not Found'

def linear_search_sentinel(key, A):
    i = 0
    n = len(A)
    A.append(key)
    while A[i] != key:
        i += 1
    if i == n:
        return 'Not Found'
    return i


if __name__ == "__main__":
    
    
    
    
    n = int(input())
    S = list(map(int, input().strip().split()))
    q = int(input())
    T = list(map(int, input().strip().split()))


    c = 0
    for k in T:
        if linear_search(k, S) != 'Not Found':
            c += 1
    print(c)

Solution (Python):



def solve():
    _ = int(input())
    S = set(map(int, input().split()))
    _ = int(input())
    T = set(map(int, input().split()))

    print(len(S & T))


if __name__ == '__main__':
    solve()

Solution (Python):
m = int(input())
S = list(map(int, input().split(" ")))
n= int(input())
T = list(map(int, input().split(" ")))

cnt = 0
al = []
for s in S:
    for t in T:
        if s == t:

            if t not in al: 

                cnt += 1
            
            al.append(t)
print(cnt)

Solution (Python):
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))



cnt = 0
for j in T:
    for i in S:
        if i == j:
            cnt += 1
            break

print(cnt)

Solution (Python):
n1=int(input())
a=list(map(int,input().split()))
n2=int(input())
b=list(map(int,input().split()))
c=[]

for i in a:
	for j in b:
		if i==j and i not in c:
			c.append(i)
			
print(len(c))

Solution (Python):
n = int(input())
*S, = set(input().split())
q = int(input())
*T, = set(input().split())
cnt = 0
for i in range(q):
    cnt += S.count(T[i])
print(cnt)

Solution (Python):
n=int(input())
S=list(map(int, input().split()))
q=int(input())
T=list(map(int, input().split()))
counter=0
for t in T:
    if t in S:
        counter+=1
print(counter)

Solution (Python):
n = int(input())
slist = list(map(int, input().split()))
q = int(input())
tlist = list(map(int, input().split()))

cnt = 0
for t in tlist:
    for s in slist:
        if t == s:
            cnt += 1
            break

print(cnt)

Solution (Python):
n=input()
S=input().split()

q=input()
T=input().split()

cnt=0
for x in T:
    if(x in S):
        cnt+=1
    
print(cnt)

Solution (Python):
s_num=int(input())
s_list=list(map(int,input().split()))
q_num=int(input())
q_list=list(map(int,input().split()))
count = 0
a_list = []
for q in q_list:
    for s in s_list:
        if s == q:
            count += 1
            break

            
print(count)

Solution (Python):
n = int(input())
list_s = list((map(int, input().split())))
q = int(input())
list_t = list((map(int, input().split())))
ans = 0
for numbert in list_t:
    for numbers in list_s:
        if numbers == numbert:
            ans += 1
            break
        else:
            pass
print(ans)

Solution (Python):
import sys
sys.stdin.readline()
s = set(map(int,sys.stdin.readline().split()))
sys.stdin.readline()
t = set(map(int,sys.stdin.readline().split()))
print(len(s & t))

Solution (Python):
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
count = 0
for i in T:
    if i in S:
        count += 1
print(count)

Solution (Python):


n = input()
s = set(input().split())
m = input()
t = set(input().split())
print(len(s&t))

Solution (Python):
import sys


sys.setrecursionlimit(1000000)


def li_input():
    return [int(_) for _ in input().split()]


def main():
    n = int(input())
    S = li_input()
    q = int(input())
    T = li_input()

    ans = 0

    for t in T:
        if t in S:
            ans += 1

    print(ans)


main()

Solution (Python):
_ , A = input(), input().split()
_, E = input(), input().split()

result = []
for e in E:
    for a in A:
        if e == a and e not in result:
            result.append(a)

print(len(result))

Solution (Python):
def main():
    input()
    ss = input().split()
    input()
    ts = input().split()

    nums = {}

    for t in ts:
        nums[t] = False

    for s in ss:
        if s in nums:
            nums[s] = True

    cnt = 0
    for val in nums.values():
        if val:
            cnt += 1

    print(cnt)

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
[*A] = map(int, input().split(' '))
q = int(input())
[*Q] = map(int, input().split(' '))


def search(key):
    i = 0
    A[len(A) - 1] = key
    while A[i] != key:
        i += 1
    if i == len(A) - 1:
        return -1
    return i


A.append(0)
sum = 0
for i in range(q):
    A[len(A) - 1] = Q[i]
    if search(Q[i]) != -1:
        sum += 1
print(sum)

Solution (Python):
if __name__ == '__main__':
    n = int(input())
    S = list(map(int, input().split()))
    q = int(input())
    T = list(map(int, input().split()))

    cnt = 0
    for i in T:
        for j in S:
            if i == j:
                cnt += 1
                break

    print(cnt)

Solution (Python):



def count(s, t):
    c = 0
    for x in t:
        for y in s:
            if x == y:
                c += 1
                break
    return c

n = int(input())
s = [int(x) for x in input().split()]

q = int(input())
t = [int(x) for x in input().split()]

print(count(s, t))

Solution (Python):
n=int(input())
s=[int(i) for i in input().split()]
q=int(input())
t=[int(i) for i in input().split()]

count=0

for i in t:
    if i in s:
        count+=1
        
print(count)

Solution (Python):
import sys

f = sys.stdin

n = f.readline().replace('\n','')
S = set(map(int, f.readline().replace('\n','').split()))
q = f.readline().replace('\n','')
T = set(map(int, f.readline().replace('\n','').split()))

print(len(S & T))

Solution (Python):
def liner_search(A, n, B, q):
    cnt = 0
    for i in range(q):
        for j in range(n):
            if B[i] == A[j]:
                cnt += 1
                break
    return cnt

n = int(input())
A = list(map(int,input().split()))
q = int(input())
B = list(map(int,input().split()))
print(liner_search(A, n, B, q))

Solution (Python):


n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))

def search(S, key, n):
    i = 0
    S.append(key)
    while(S[i] != key):
        i += 1
    if(i == n):
        S.pop()
        return 0
    else:
        S.pop()
        return 1
        
        
count = 0
for key in T:
    count += search(S, key, n)
print(count)

Solution (Python):
input()
s=set(map(int,input().split(" ")))
input()
t=set(map(int,input().split(" ")))
print(len(s&t))

Solution (Python):
num = 0
line1=raw_input()
line2=raw_input()
line3=raw_input()
line4=raw_input()
num1 = 0
num2 = 0

A=line2.split(" ")
B=line4.split(" ")


for b in B:
    num1 = int(b)
    for a in A:
        num2 = int(a)
        if num1 == num2:
            num += 1 
            break
print(num)

Solution (Python):
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))


cnt = 0
for i in T:
    for j in S:
        if i == j:
            cnt += 1
            break

print(cnt)

Solution (Python):
n = int(input())
s = [int(i) for i in input().split()]
q = int(input())
t = [int(i) for i in input().split()]

count = 0
for i in t:
    if i in s:
        count += 1

print(count)

Solution (Python):
n=int(input())
s=[]
x=input().strip().split()
for i in range(n):
	s.append(int(x[i]))
q=int(input())
t=[]
y=input().strip().split()
for j in range(q):
	t.append(int(y[j]))
	
if n<q:
	tmp=s
	s=t
	t=tmp
	
count=0

for i in range(len(t)):
	for j in range(len(s)):
		if t[i]==s[j]:
			count+=1
			break

print(count)

Solution (Python):
n = int(input())
s = set(list(map(int, input().split())))
q = int(input())
t = set(list(map(int, input().split())))


print(len(t & s))

Solution (Python):
n = int(input())
A = [int(l) for l in input().split(' ')]
kn = int(input())
k_list = [int(l) for l in input().split(' ')]

def linear_search(k,A,n):
  i = 0
  while A[i] != k:
    i += 1
    if i == n:
      return False
  return True

sum = 0
for k in k_list:
   sum += 1 if linear_search(k,A,n) else 0
print(sum)

Solution (Python):
n = int(input())
s = list(map(int, input().split()))
q = int(input())
t = list(map(int, input().split()))
ans = 0
for ele in t:
  if ele in s:
    ans += 1
print(ans)

Solution (Python):

input()
a=set(map(int,input().split()))
input()
b=set(map(int,input().split()))
print(len(a)-len(a-b))

Solution (Python):
n = int(input())
S = [int(i) for i in input().split(' ')]
q = int(input())
T = [int(i) for i in input().split(' ')]
c = 0
for t in T:
	if t in S: c += 1
print(c)