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 ≤ 109

0 ≤ an element in T ≤ 109

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

Template in C
-->



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


Sample output:
3

Submission status: Accepted

Solution code:
n = int(input())
a = set(map(int, input().split()))
q = int(input())
b = set(map(int, input().split()))
print(len(a & b))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

n = input()
S = list(set(input().split()))
q = input()
T = list(set(input().split()))

ctr = 0
for i in T:
    try:
        x = S.index(i)
        ctr += 1
    except:
        pass
        
print(ctr)

Submission status: Accepted

Solution code:
def linearSearch(A,key,i):
    c = 0
    A[i] = key
    while A[c] != key:
        c += 1
        if i == c:
            return 0
    return 1
    
n1 = int(input())
A = [int(e) for e in input().split()]
n2 = int(input())
B = [int(e) for e in input().split()]
A.append(0)
c = 0
for i in range(n2):
    c = c + linearSearch(A,B[i],len(A)-1)
print(c)

Submission status: Accepted

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

def linearSearch(A, key):
	n = len(A) - 1
	i = 0
	A[n] = key # 番兵
	while (A[i] != key):
		i += 1
	return i != n

cnt = 0
for i in range(q):
	key = T[i]
	if linearSearch(S, key):
		cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
S = [int(s) for s in input().split()]
Q = int(input())
T = [int(t) for t in input().split()]

cnt = 0
for t in T:
    if t in S:
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
S = list(map(int, input().split(' ')))
q = int(input())
T = list(map(int, input().split(' ')))
r = 0


def linear_search(S, t):
    for s in S:
        if s == t:
            return True
    return False


for t in T:
    if linear_search(S, t):
        r += 1

print(r)

Submission status: Accepted

Solution code:
n = int(input())
s = input().split()
q = int(input())
t = input().split()

cnt = 0
for x in t:
    if x in s:
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
n=int(input())
s=[int(x) for x in input().split()]
q=int(input())
t=[int(x) for x in input().split()]
#print(s)
c=0
for i in t:
    if i in s:
        c+=1
print(c)

Submission status: Accepted

Solution code:
# 線形探索
# ALDS1_4_A

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

cnt = 0
for t in T:
    if t in S:
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
def linear_search(l, key):
    i = 0
    l.append(key)
    while l[i] != key:
        i += 1

    if i == len(l) - 1:
        return False
    else:
        return True

if __name__ == "__main__":
    import sys
    input = sys.stdin.readline # faster input

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

    c = 0
    for key in T:
        if linear_search(S, key):
            c += 1

    print(c)

Submission status: Accepted

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

print(len(set(S)&set(T)))

Submission status: Accepted

Solution code:
n = int(input())
S = [int(i) for i in input().split()] + [0]
q = int(input())
T = [int(i) for i in input().split()]


def search(A,n,key):
  i = 0
  S[n] = key
  #S.append(key)
  while S[i] != key:
    i += 1
  return i != n

cnt = 0
for i in range(q):
  if search(S,n,T[i]):
    cnt += 1
    #print("cnt",cnt)
print(cnt)

Submission status: Accepted

Solution code:
ns = int(input())
S = list(map(int,input().split()))
nt = int(input())
T = list(map(int,input().split()))

def linear_search(lst,key):
    i = 0
    while i<len(lst):
        if lst[i] == key:
            return 1
        else:
            i+=1
    return 0

ans = 0
for key in T:
    ans += linear_search(S,key)
print(ans)

Submission status: Accepted

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

s_max =  max(s)
q = int(input())
t = [int(i) for i in input().split() if int(i) <= max(s)]

c = 0

for i in range(n):
  if len(t) < 1: break
  if t == c: break

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

print(c)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    m = int(input())
    b = list(map(int, input().split()))

    cnt = 0
    for y in b:
        for x in a:
           if y == x:
               cnt += 1
               break
    print(cnt) 

main()

Submission status: Accepted

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

# Liner Search
def LinerSearch(A, key):
    for i in range(len(A)):
        if A[i] == key:
            return True

    return False

#Liner Search2
def LinerSearch2(A, key):
    i = 0
    A.append(key)
    while A[i] != key:
        i += 1
    if i == n:
        A.pop()
        return False
    else:
        A.pop()
        return True



cnt = 0
for i in range(len(T)):
    if LinerSearch2(S, T[i]):
        cnt = cnt+1

print(cnt)

Submission status: Accepted

Solution code:
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):
	if T[i] in S:
		C += 1

print(C)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
n=list(map(int,(stdin.readline().strip().split())))
S =list(set(map(int,stdin.readline().strip().split())))
q=list(map(int,(stdin.readline().strip().split())))
T=list(map(int,stdin.readline().strip().split()))
S.sort(),T.sort()
count=0
c=-1

for t in T:
    SS=S
    while(True):
        n = len(SS)
        target = int((n - 1) / 2)#真ん中
        if SS[target] ==t:
            count+=1
            break
        if SS[target] >t:#下いく
            SS=SS[:target]
        else:#上いく
            SS=SS[target:]
        if n==len(SS):
            if n==1:break
            if SS[1] == t or SS[0]==t:
                count += 1
                break
            break


print(count)

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
n = int(input())
S = list(map(int,input().split()))
q = int(input())
T = list(map(int,input().split()))
ans = 0
for i in range(q):
    a = T[i]
    for j in range(n):
        if S[j] == a:
            ans += 1
            break
print(ans)

Submission status: Accepted

Solution code:
s_num = int(input())
S = list(map(int, input().split()))
t_num = int(input())
T = list(map(int, input().split()))

def linear_search(S, T):
    num = 0
    for target_num in T:
        for s_item in S:
            if target_num == s_item:
                num += 1
                break
    return num


print(linear_search(S, T))

Submission status: Accepted

Solution code:
n = int(input())
s = [int(i) for i in input().split()]
q = int(input())
t = [int(i) for i in input().split()]
ans = 0
for i in range(q):
    if t[i] in s: ans += 1
print(ans)

Submission status: Accepted

Solution code:
def linearSearch(A, k):
    for a in A:
        if a == k:
            return True
    return False

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 linearSearch(S, t):
        C += 1
print(C)

Submission status: Accepted

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

def linearSearch(key):
  i = 0
  len_pre_S = len(S)
  S.append(key)
  while S[i] != key:
    i += 1
  if i == len_pre_S:
    return 0
  return 1

count = 0
for t in T:
  count += linearSearch(t)
print(count)

Submission status: Accepted

Solution code:

def main():
    n = int(input())
    a = list(map(int,input().split()))
    m = int(input())
    b = list(map(int,input().split()))
    res = 0
    for i in range(m):
        for j in range(n):
            if b[i]==a[j]:
                res+=1
                break
    print (res)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
#ALDS1_4_A_Linear Search

import sys
from collections import deque

def input_lines():
    return sys.stdin.readlines()

def liner_search(lines):
    s = sorted(map(int, lines[1].split()))
    t = deque(sorted(map(int, lines[3].split())))
    
    idx, count = 0, 0
    while len(t) > 0:
        nt = t.popleft()
        found = False
        while idx < len(s):
            if nt == s[idx]:
                found = True
                break
            else:
                idx += 1
        if found:
            count += 1
        else:
            idx = 0
        
    return count
lines = input_lines()
print(liner_search(lines))

Submission status: Accepted

Solution code:
N = int(input())
S = list(map(int,input().split()))
Q = int(input())
T = list(map(int,input().split()))

count =set()

for i in range(Q):
    for j in range(N):
        if T[i]==S[j]:
            count.add(T[i])
if len(count)>0:
    print(len(count))
    
else:
    print("0")

Submission status: Accepted

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

ans = 0

for i in range(q):
    q_temp = T[i]
    S.append(q_temp)
    j = 0
    while S[j] != q_temp:
        j += 1
    if j < n:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
# import numpy as np
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))

# print(len(np.intersect1d(S, T)))
count = 0
for i in range(q):
    key = T[i]
    for j in range(n):
        if S[j] == key:
            count += 1
            break
print(count)

Submission status: Accepted

Solution code:
n = int(input())
S = input().split()
q = int(input())
T = input().split()
cout = 0
for i in T:
    if i in S:
        cout += 1
print(cout)

Submission status: Accepted

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

count = 0
for t in T:
    for s in S:
        if t == s:
            count += 1
            break
print(count)

Submission status: Accepted

Solution code:
n = int(input())
S = list(map(int,input().split())) + [0]
q = int(input())
T = map(int,input().split())
ret = 0
for t in T:
  i = 0
  S[n] = t
  while t != S[i]:
    i += 1
  if i != n:
    ret += 1
print(ret)

Submission status: Accepted

Solution code:
N=int(input())
S=list(map(int,input().split()))
Q=int(input())
T=list(map(int,input().split()))

ans=0
for t in T:
    for s in S:
        if s==t:
            ans+=1
            break
print(ans)

Submission status: Accepted

Solution code:
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_A

def main():
    n = int(input())
    S = set(list(map(int, input().split((' ')))))
    q = int(input())
    T = set(list(map(int, input().split((' ')))))

    ans = 0
    for t in T:
        for s in S:
            if t == s:
                ans += 1
    
    print(ans)


main()

Submission status: Accepted

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

c = 0

for t in T:
    for s in S:
        if t == s:
            c += 1
            break

print(c)

Submission status: Accepted

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

S.append(0)

def func(x):
  S[n] = T[x] #番兵を付加
  i = 0
  while S[i] != S[n]:
    i += 1
    if i==n:
      return 0
  return 1

C = 0
for i in range(q):
  C += func(i)

print(C)

Submission status: Accepted

Solution code:
def main():
    input()
    S = set(map(int, input().split(' ')))
    input()
    T = map(int, input().split(' '))
    count = 0
    for t in T:
        if t in S:
            count += 1
    print(count)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
S = list(input().split())
q = int(input())
T = list(input().split())
S.append(-1)
Sum = 0 #これで個数をカウント

for i in range(len(T)):
    S[n] = T[i] #番犬のKEY:T[i]をS[n]に代入
    t = 0
    while(S[t] != S[n]):
        t += 1
    if t == n:
        continue
    else:
        Sum += 1
print(Sum)

Submission status: Accepted

Solution code:
n = int(input())
*S, = map(int, input().split())
q = int(input())
*T, = map(int, input().split())
print(len(set(S) & set(T)))

Submission status: Accepted

Solution code:
def linear_search(A, key):
    N = len(A)
    A[N - 1] = key
    i = 0
    while A[i] != key:
        i += 1
    return i != (N - 1)

if __name__ == "__main__":
    N = int(input())
    num_list = list(map(int, input().split()))
    M = int(input())
    target_list = list(map(int, input().split()))

    count = 0
    for target in target_list:
        if(linear_search(num_list, target)):
            count += 1
    print(count)

Submission status: Accepted

Solution code:
n = int(input())
S = [item for item in input().split()]
q = int(input())
T = [item for item in input().split()]

c = 0
addedOnce = False
for t in T:
    addedOnce = False
    for s in S:
        if t == s and not addedOnce:
            c += 1
            addedOnce = True
print(c)

Submission status: Accepted

Solution code:
n = int(input())
S = set(map(int, input().split()))
q = int(input())
T = set(map(int, input().split()))
print(len(S & T))

Submission status: Accepted

Solution code:
n =input()
s = list(map(int, input().split()))

q =input()
t = list(map(int, input().split()))

ans = 0
for i in range(int(n)):
    if s[i] in s[:i]:
        continue
    if s[i] in t:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
def solv(S, T):
    tset = set(T)
    count = 0
    for s in S:
        if s in T:
            count += 1
            T.remove(s)
    return count


if __name__ == "__main__":

    _ = input()
    S = input().split()
    _ = input()
    T = input().split()

    ans = solv(S, T)

    print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = [int(item) for item in input().split()]
q = int(input())
T = [int(item) for item in input().split()]


def banhei():
    cnt = 0
    for i in range(q):
        key = T[i]
        S.append(key)
        j = 0
        # print(T[i])
        while key != S[j]:
            j += 1
        if j != N:
            # print(S[j])
            cnt += 1
        S.pop()
    return cnt

print(banhei())

Submission status: Accepted

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

def linearSearch(A,key,n):
    i=0
    B=copy.copy(A)
    B.append(key)
    while B[i] != key:
        i=i+1
    if i==n:
        return 0
    return 1

ans=0
for i in range(q):
    if linearSearch(S,T[i],n):
        ans=ans+1

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
S = [int(i) for i in input().split()]
q = int(input())
T = [int(i) for i in input().split()]

count = 0

S.append(None)

def lenearSearch(s, t):
    i = 0
    while S[i] != t:
        i += 1
    return i != (len(s)-1)

for t in T:
    S[-1] = t
    if lenearSearch(S, t):
        count+=1

print(count)

Submission status: Accepted

Solution code:
def search(l:list, t:int) -> bool:
    l.append(t)
    i=0
    while l[i] != t:
        i+=1

    if len(l) == i+1:
        return False
    l.pop()
    return True

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

ans=0
for _t in t:
        if search(s, _t):
            ans+=1

print(ans)

Submission status: Accepted

Solution code:
import sys
import math
import copy
from typing import Tuple, List, Union
input = sys.stdin.readline


def main():
    n = int(input())
    S = tuple(map(int,input().split()))
    q = int(input())
    T = tuple(map(int,input().split()))
    res = 0
    for t in T:
        for s in S:
            if s == t:
                res += 1
                break
    return res


if __name__ == '__main__':
    print(main())

Submission status: Accepted

Solution code:
input()
S = list(map(int, input().split()))
input()
T = list(map(int, input().split()))
c = 0
for t in T:
  if t in S:
    c += 1
print(c)

Submission status: Accepted

Solution code:
n = int(input())
S = input().split(" ")
q = int(input())
T = input().split(" ")
count=0

for t in T:
    if t in S:
        count+=1
        
print(count)

Submission status: Accepted

Solution code:
_,s1 = input(), set(input().split())
_,s2 = input(), set(input().split())
print(len(s1 & s2))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
q = int(input())
b = list(map(int, input().split()))

a = set(a)
b = set(b)

print(len(a&b))

Submission status: Accepted

Solution code:
import bisect
import math
import sys
from collections import Counter, defaultdict, deque
from copy import copy, deepcopy
from heapq import heapify, heappop, heappush
from itertools import combinations, permutations
from queue import Queue

read = sys.stdin.read
readline = sys.stdin.readline 
readlines = sys.stdin.readlines 

def SI():
    return int(readline())
def MI():
    return map(int, readline().split())
def MLI():
    return map(int, open(0).read().split())

inf = float("inf")


def main():
    n = int(input())
    S = [i for i in MI()]
    
    q = int(input())
    T = [i for i in MI()]
    
    ret = 0
    for t in T:
        if t in S:
            ret += 1
            
    print(ret)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
S = Counter(map(int, input().split()))
Q = int(input())
T = Counter(map(int, input().split()))
ans = 0
if len(S) > len(T):
    for x, y in S.items():
        if x in T.keys():
            ans += min(y, T[x])
else:
    for x, y in T.items():
        if x in S.keys():
            ans += min(y, S[x])
print(ans)

Submission status: Accepted

Solution code:
_ = input()
S = list(map(int, input().split()))
_ = input()
T = list(map(int, input().split()))

count = 0
for t in T:
    if t in S:
        count += 1

print(count)

Submission status: Accepted

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

print(len(set(s) & set(t)))

Submission status: Accepted

Solution code:
def use_guard():
    same_num_count = 0
    firstlist_num = int(input())
    firstlist = set(input().split())
    secondlist_num = int(input())
    secondlist = set(input().split())

    for n in secondlist:
        if firstlist.__contains__(n):
            same_num_count += 1

    print(same_num_count)

def use_set():
    input()
    firstlist = set(input().split())
    input()
    secondlist = set(input().split())
    same_num_count = len(firstlist.intersection(secondlist))
    print(same_num_count)

use_set()

Submission status: Accepted

Solution code:
from collections import deque

def linear():
    # データを格納
    s = deque()
    t = deque()
    n = int(input())
    s_list = list(map(int, input().split()))
    q = int(input())
    t_list = list(map(int, input().split()))
    for i in s_list:
        s.append(i)
    for i in t_list:
        t.append(i)

    # tがsに存在するか検索
    count = 0
    for i in t:
        f = True
        while True:
            try:
                s.remove(i)
                if f:
                    count += 1
                    f = False
            except ValueError:
                break
    print(count)

if __name__ == "__main__":
    linear()

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    s = [int(a) for a in input().split()]
    q = int(input())
    t = [int(a) for a in input().split()]

    count = 0

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

    print(count)

main()

Submission status: Accepted

Solution code:
n1 = int(input())
a = [ int(i) for i in input().split(" ")]
n2 = int(input())
b = [ int(i) for i in input().split(" ") ]

ans = 0
for e in b:
  if e in a: ans += 1

print(ans)

Submission status: Accepted

Solution code:
a=input() 
S = input().split()
b=input()
T = input().split()
count = 0

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

print(count)

Submission status: Accepted

Solution code:
# Algorithms and Data Structures 1
# Linear Search
# Name: Ryuya Asada
# ID: s1260064


def linear_search(A: list, key: int) -> int:
    i = 0
    # 番兵にkeyを追加
    A.append(key) 

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

    return i

def main():
# Read first Array
    number_of_A = int(input())
    A = [int(a) for a in input().split(" ")]

# Read second Array
    number_of_B = int(input())
    B = [int(b) for b in input().split(" ")]

    num = 0
    for b in B:
        result = linear_search(A, b)
        if result != -1:
            num += 1

    print(num)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
S = input().split()
q = int(input())
T = input().split()

C = 0
for i in T:
    for j in S:
        if j == i:
            C += 1
            break
        
print(C)

Submission status: Accepted

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

cnt = 0

for i in range(q):
    for j in range(n):
        if t[i] == s[j]:
            cnt += 1
            break
print(cnt)

Submission status: Accepted

Solution code:
#アルゴリズム実装
def linearSearch(list, find_number):
    i = 0
    search_list = list + [find_number]
    last_number = len(search_list) - 1
    while search_list[i] != find_number:
        i += 1
    if i ==  last_number:
        return 0
    else:
        return 1

#インプットdata
n_number = int(input())
n_list = list(map(int, input().split()))
q_number = int(input())
q_list = list(map(int, input().split()))
result = 0

#処理の実行
for i in range(q_number):
        result += linearSearch(n_list, q_list[i])

#結果の表示
print(result)

Submission status: Accepted

Solution code:
n = int(input())
S = input().split()
q = int(input())
T = input().split()
C = 0
for t in T:
    if t in S:
        C += 1
print(C)

Submission status: Accepted

Solution code:
#  search

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

S.sort()
T.sort()
ans = 0

i = 0
for elm in S:
    if elm > T[i]:
        while i < q-1 and elm > T[i]:
            i += 1
        
        if elm == T[i]:
            ans += 1
    elif elm == T[i]:
        ans += 1
    elif elm < T[i]:
        pass

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = [int(l) for l in input().split()]
q = int(input())
t = [int(r) for r in input().split()]
t.sort()
cnt = 0
for i in t:
    if s.count(i) != 0:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
input()
s = set(list(map(int,input().split())))
input()
t = set(list(map(int,input().split())))
print(len(s.intersection(t)))

Submission status: Accepted

Solution code:
n=int(input())
S=input().split()
S=[int(s) for s in S]

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

#線型探索　計算時間O(qn)
def lineresearch(key):
    i = 0
    while S[i]!=key:
        i = i+1
        if i==n:
            #result = 0
            return 0
    #result = 1
    return 1

count = 0

for i in range(q):
    S.append(0)
    S[n]=T[i]   #Tの要素を番兵としておく
    count += lineresearch(S[n])
print(count)

Submission status: Accepted

Solution code:
def linear_search(n, x):
    for i in x:
        if i == n:
            return 1
    return 0

n = int(input())
S = input().split()
q = input()
T = input().split()
ans = 0
for t in T:
    ans += linear_search(t, S)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
S = [int(x) for x in list(map(int, input().split()))]
q = int(input())
T = [int(x) for x in list(map(int, input().split()))]

def search(S, n, key):
  i = 0
  S[n] = key
  while (S[i] != key):
    i += 1
  return i != n

S.append(0)
count = 0
for a in T:
  if (search(S, n, a)):
    count += 1

print (count)

Submission status: Accepted

Solution code:
# ALDS1_4_A: Linear Search

# 番兵
def linearSearch(l, key):
  index = 0
  l.append(key)
  while l[index] != key:
    index += 1
  else:
    if index == (len(l) -1):
      return -1
    else:
      return index

def main():
  n = int(input())
  S = list(map(int, input().split()))
  m = int(input())
  T = list(map(int, input().split()))
  count = 0
  for i in T:
    if linearSearch(list(S), i) != -1:
      count += 1
  print(count)

main()

Submission status: Accepted

Solution code:
_ = input()
S = [int(i) for i in input().split()]
_ = input()
T = [int(i) for i in input().split()]

count = 0

for t in T:
    if t in S:
        count += 1
        
print(count)

Submission status: Accepted

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

count = 0
for t in T:
    min_idx = 0
    max_idx = len(S) - 1
    while min_idx <= max_idx:
        mid_idx = (min_idx+max_idx) // 2
        if t < S[mid_idx]:
            max_idx = mid_idx - 1
        elif t > S[mid_idx]:
            min_idx = mid_idx + 1
        else:
            count += 1
            break
print(count)

Submission status: Accepted

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

ans=list(set(s) & set(t))
print(len(ans))

Submission status: Accepted

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

    c = 0

    for k in T:
        if k in S:
            c += 1
    print(c)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
s = input().split()
q = int(input())
T = input().split()
c = 0
for a in T:
    if a in s:
        c += 1
print(c)

Submission status: Accepted

Solution code:
num_s, S, num_t, T,  = [list(map(int, s.split())) for s in open(0)]
cnt = 0
for t in T:
    if t in S:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
input()
s = input().split()
input()
t = input().split()
ans = len([i for i in t if i in s])
print(ans)

Submission status: Accepted

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

cnt = 0

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

print(cnt)

Submission status: Accepted

Solution code:
def linearSearch(A, n, key):
	i = 0
	A.append(key)
	while (A[i] != key):
		i += 1
	del A[n]

	return i != n


if __name__ == '__main__':
	
	n = int(input())
	L = list(map(int, input().split()))

	q = int(input())
	Key = list(map(int, input().split()))

	count = 0
	for i in range(q):
		if (linearSearch(L, n, Key[i])):
			count += 1
print(count)

Submission status: Accepted

Solution code:
n = int(input())                                                                          
ls_s = list(map(int,input().split()))                                                     
q = int(input())                                                                          
ls_t = list(map(int,input().split()))                                                     
                                                                                          
ls_ch = []                                                                                
cnt = 0                                                                                   
for i in range(n):                                                                        
    flag = 0                                                                              
    for j in range(len(ls_ch)):                                                           
        if ls_s[i] == ls_ch[j]:                                                           
            flag = 1                                                                      
            break                                                                         
    if flag == 1:                                                                         
        continue                                                                          
    for j in range(q):                                                                    
        if ls_s[i] == ls_t[j]:                                                            
            cnt += 1                                                                      
            ls_ch.append(ls_s[i])                                                         
            break                                                                         
                                                                                          
print(cnt)

Submission status: Accepted

Solution code:
count = 0

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

for t in T:
    for i in n:
        if t == i:
            count += 1
            break

print(count)

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

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

C = set(S) & set(T)
print(len(C))

Submission status: Accepted

Solution code:

n1 = int(input())
A = set(map(int, input().split()))
n2 = int(input())
B = set(map(int, input().split()))

print(len(B.intersection(A)))

Submission status: Accepted

Solution code:
import sys

n = int(input())
s = tuple(map(int, sys.stdin.readline().split()))
q = int(input())
t = tuple(map(int, sys.stdin.readline().split()))

result = 0
for x in t:
    for y in s:
        if x == y: result += 1; break
print(result)

Submission status: Accepted

Solution code:
n = int(input())
s = list(map(int, input().split()))
n1 = int(input())
t = list(map(int, input().split()))
count = 0
for i in t:
    if i in s:
        count += 1
print(count)