Problem:


Search II

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

Elements in S is sorted in ascending order

n ≤ 100000

 q ≤ 50000 

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
1 2 3
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:
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    n= int(sys.stdin.readline())
    S= list(map(int, sys.stdin.readline().split()))
    q= int(sys.stdin.readline())
    T= list(map(int, sys.stdin.readline().split()))
    c=0
    for i in T:#リストTの値をターゲットにする
        left = 0#左端のindex
        right =len(S)-1#右端のindex
        while left <= right:#探索範囲が存在する限り
            center = (left+right)//2#切り捨て
            if i == S[center]:
                c+=1
                break
            elif i > S[center]:#中心よりターゲットが大きい時
                left = center+1#中心以下を切り捨て
            elif i < S[center]:
                right = center -1#
    print(c)

Submission status: Accepted

Solution code:
def binarySearch(A, key):
    left = 0
    # right = n
    right = len(A)
    while left < right:
        mid = (left + right) // 2
        if A[mid] == key:
            # return mid
            return 1
        elif key < A[mid]:
            right = mid
        else:
            left = mid + 1
    # return NOT_FOUND
    return 0


if __name__ == '__main__':
    n = int(input())
    S = list(map(int, input().split()))
    q = int(input())
    T = list(map(int, input().split()))
    ans = 0
    for t in T:
        ans += binarySearch(S, t)
    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()))

c=0



for i in range(q):
	left=0
	right=n
	while left < right:
		mid =(left +right)//2
		if s[mid]==t[i]:
			c+=1
			break
		elif t[i] < s[mid]:
			right=mid
		else:
			left=mid+1
	

print(c)

Submission status: Accepted

Solution code:
from bisect import bisect_left
from collections import Counter
from sys import stdin
N = int(stdin.readline().rstrip())
S = [int(_) for _ in stdin.readline().rstrip().split()]
S.sort()
Q = int(stdin.readline().rstrip())
T = [int(_) for _ in stdin.readline().rstrip().split()]
ans = 0

def bisect_search(l, x):
    i = bisect_left(l, x)
    if i != len(l) and l[i] == x:
        return True
    return False

for i in T:
    if bisect_search(S, i):
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n = int(raw_input())
    S = map(int, raw_input().split())
    q = int(raw_input())
    T = map(int, raw_input().split())
    cnt = 0
    for x in T:
        left = 0
        right = n
        # search [left, right)
        while left < right:
            mid = (left + right) / 2
            if S[mid] == x:
                cnt += 1
                break
            elif S[mid] > x:
                right = mid
            else:
                left = mid + 1
    print cnt

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 binary(s,num):
    left=0
    right=len(s)-1
    while left<=right:
        m=(left+right)//2
        if s[m]==num:
            return 1
        elif s[m]>num:
            right=m-1
        else:
            left=m+1
    return 0


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):
    cnt+=binary(s,t[i])
print(cnt)

Submission status: Accepted

Solution code:
def binary_search(v, l, r, key):
    left = l
    right = r
    while left<right:
        mid = (left + right)//2
        if v[mid] == key:
            return True
        elif v[mid]<key:
            left = mid+1
        else:
            right = mid
    return False


n = int(input())
v = list(map(int,input().split()))
q = int(input())
w = list(map(int,input().split()))
cnt = 0
for i in w:
    if binary_search(v,0,n,i):
        cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
from enum import Enum
from queue import Queue
import collections

import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

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

def binarySearch(key, Obj_data, n):
    left = 0
    right = n
    while left < right:
        mid = int((left + right) / 2)
        if Obj_data[mid] == key:
            return True
        elif key < Obj_data[mid]:
            right = mid
        else:
            left = mid +1
    return False
ans = 0
for key in T:
    if binarySearch(key,S,n):
        ans+= 1

print("%d"%(ans))

Submission status: Accepted

Solution code:
class Binary_search():
    def __init__(self,S):
        self.num = 0
        self.S = S
    def binary_search(self,left,right,key):
        if left < right:
            mid =int((left + right) / 2)
            if self.S[mid] == key:
                self.num += 1
            elif self.S[mid] < key:
                self.binary_search(mid+1,right,key)
            else:
                self.binary_search(left,mid,key)

def main():
    N = int(input())
    S = [int(c) for c in input().split()]
    M = int(input())
    T = [int(c) for c in input().split()]
    binary_search = Binary_search(S)
    for i in range(M):
        binary_search.binary_search(0,N,T[i])
    print(binary_search.num)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
As = list(map(int, input().split()))
q = int(input())
Ts = list(map(int, input().split()))

from bisect import bisect_left
ans = 0
As += [10**9]
for T in Ts:
    ind = bisect_left(As,T)
    if As[ind] == T:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_left

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

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


cnt = 0

for v in T:
    index = bisect_left(S, v)
    if index < len(S) and S[index] == v:
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import math

n = int(input())
s_list = list(map(int, input().split()))
q = int(input())
t_list = list(map(int, input().split()))

count = 0
for t in t_list:
    left = 0
    right = len(s_list) - 1
    while left <= right:
        mid = math.floor((left + right) / 2)
        if s_list[mid] == t:
            count = count + 1
            break
        elif s_list[mid] > t:
            right = mid - 1
            continue
        elif s_list[mid] < t:
            left = mid + 1
            continue

print(count)

Submission status: Accepted

Solution code:
#雑に考えて漏れや無限ループやrange外れが多発したので解説見た
n=int(input())
L=input().split( )
q=int(input())
M=input().split( )

S=[int(L[i]) for i in range(n)]
T=[int(M[i]) for i in range(q)]

C=0
#max=n
#min=0
#mid=n
for i in range(q):
    max=n
    min=0
    while max>min:
        mid=int((max+min)/2)
        if S[mid]==T[i]:
            C+=1
            break
        elif S[mid]<T[i]:
            min=mid+1
            #print(C,i,mid)
        elif S[mid]>T[i]:#不等号逆だったわwwww
            max=mid
            #print(C,i,mid)
print(C)

Submission status: Accepted

Solution code:
n=int(input())
s=list(map(lambda x:int(x),input().split()))
q=int(input())
t=list(map(lambda x:int(x),input().split()))
c=0
for i in t:
    start=0
    end=n-1
    while start<=end:
        mid=(start+end)//2
        if s[mid]==i:
            c+=1
            break
        if s[mid]>i:
            end=mid-1
        if s[mid]<i:
            start=mid+1

print(c)

Submission status: Accepted

Solution code:
def binarysearch(n,key,A):
    left=0
    right=n
    while left<right:
        mid=int((left+right)/2)
        if A[mid]==key:
            return 1
        elif key<A[mid]:
            right=mid
        else:
            left=mid+1
    return 0

if __name__=="__main__":
    n=int(input())
    S=list(map(int,input().split()))
    q=int(input())
    T=list(map(int,input().split()))
    result=0
    for i in range(q):
        result+=binarysearch(n,T[i],S)
    print(result)

Submission status: Accepted

Solution code:
n=int(input())
da=list(map(int ,input().split()))
m=int(input())
di=list(map(int ,input().split()))

def bino(le,ri,k):
    if ri-le<2:
        return False
    x=(ri+le)//2
    if da[x]==k:
        return True
    elif da[x]>k:
        return bino(le,x,k)
    else:
        return bino(x,ri,k)

ans=0
for i in di:
    if da[0]==i or da[n-1]==i:
        ans+=1
        continue
    if bino(0,n-1,i):
        ans+=1
print(ans)

Submission status: Accepted

Solution code:

def main():
    n = int(input())
    s = list(map(int, input().split()))
    s.sort()
    q = int(input())
    t = list(map(int, input().split()))
    ans = 0
    for i in range(q):
        l = 0
        h = n
        m = (l + n) // 2
        while l < h:
            if t[i] == s[m]:
                ans += 1
                break
            elif t[i] < s[m]:
                h = m
            else:
                l = m + 1
            m = (l + h) // 2
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import bisect


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

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


cnt = 0

for t in T:
    
    index = bisect.bisect_left(S, t)

    if ((index < len(S)) and
        (S[index] == t)):
        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(s) for s in input().split()]
def isOK(index,key):
    if S[index] >= key:
        return True
    else:
        return False
def search(key):
    ng = -1
    ok = len(S)
    while abs(ok-ng)>1:
        mid = int((ok+ng)/2)
        if isOK(mid,key):
            ok = mid
        else:
            ng = mid
    return ok
counter = 0
for t in T:
    index = search(t)
    if S[index] == t and index != -1 and index != len(S):
        counter += 1
print(counter)

Submission status: Accepted

Solution code:
def binary_serch(target, num_list):
    start = 0
    end = len(num_list) - 1

    while(start <= end):
        mid = int((start + end) / 2)
        mid_num = num_list[mid]
        if mid_num == target:
            return True
        elif mid_num > target:
            end = mid - 1
        else:
            start = mid + 1
    return False

if __name__ == '__main__':
    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 num in T:
        if binary_serch(num, S):
            counter += 1

    print(counter)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
import string
import sys
from itertools import chain, dropwhile, takewhile


def read(
    *shape, f=int, it=chain.from_iterable(sys.stdin), whitespaces=set(string.whitespace)
):
    def read_word():
        w = lambda c: c in whitespaces
        nw = lambda c: c not in whitespaces
        return f("".join(takewhile(nw, dropwhile(w, it))))

    if not shape:
        return read_word()
    elif len(shape) == 1:
        return [read_word() for _ in range(shape[0])]
    elif len(shape) == 2:
        return [[read_word() for _ in range(shape[1])] for _ in range(shape[0])]


def readi(*shape):
    return read(*shape)


def readi1(*shape):
    return [i - 1 for i in readi(*shape)]


def readf(*shape):
    return read(*shape, f=float)


def reads(*shape):
    return read(*shape, f=str)


def arr(*shape, fill_value=0):
    if len(shape) == 1:
        return [fill_value] * shape[fill_value]
    elif len(shape) == 2:
        return [[fill_value] * shape[1] for _ in range(shape[0])]


def dbg(**kwargs):
    print(
        ", ".join("{} = {}".format(k, repr(v)) for k, v in kwargs.items()),
        file=sys.stderr,
    )


def main():
    n = readi()
    S = readi(n)
    q = readi()
    T = readi(q)
    ans = 0
    for t in T:
        left = 0
        right = n - 1
        while left != right:
            mid = (left + right - 1) // 2
            if t <= S[mid]:
                right = mid
            else:
                left = mid + 1
        if t == S[left]:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#binary search
def isOK(lis, index, key):
    if lis[index] >= key:
        return True
    else:
        return False
def binary_search(lis, key):
    ng = -1
    ok = len(lis)
    while abs(ok - ng) > 1:
        mid = int((ok + ng)/2)
        if isOK(lis, mid, key):
            ok = mid
        else:
            ng = mid
    return ok

n = int(input())
S = [int(s) for s in input().split()]
q = int(input())
count = 0
for t in input().split():
    key = int(t)
    index = binary_search(S, key)
    if index != len(S) and index != -1 and S[index] == key:
        count += 1
print(count)

Submission status: Accepted

Solution code:
def binary_search(lst, target, start, end):
    if (start > end):
        return 0

    mid = (start + end) // 2

    if (lst[mid] < target):
        return binary_search(lst, target, mid + 1, end)
    elif (lst[mid] == target):
        return 1
    else:
        return binary_search(lst, target, start, mid - 1)

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

count = 0
for t in T:
    count += binary_search(S, t, 0, len(S) - 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()))
T.append(-1)

def bsearch(arr, key):
    left = 0
    right = len(arr)
    while left < right:
        mid = (left + right) // 2
        if arr[mid] == key:
            return True
        elif key < arr[mid]:
            right = mid
        else:
            left = mid + 1
    return False

i = 0
count = 0
while T[i] != -1:
    if bsearch(S, T[i]):
        count += 1
    i += 1

print(count)

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:
def binarySearch(A, key, ret=False):
    left = 0
    right = len(A)
    while left < right:
        mid = (left + right) // 2
        if A[mid] == key:
            return mid if not ret else ret
        if key < A[mid]:
            right = mid
        else:
            left = mid + 1
    return False


N = int(input())
S = list(map(int, input().split()))
Q = int(input())
T = list(map(int, input().split()))
ans = 0
for t in T:
    ans += 1 if binarySearch(S, t, ret=True) else 0
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()]
cnt = 0
for t in T:
    begin = 0
    end = n
    while begin < end:
        mid = (begin + end)//2
        if t == S[mid]:
            cnt += 1
            break
        elif t > S[mid]:
            begin = mid + 1
        else:
            end = mid
print(cnt)

Submission status: Accepted

Solution code:
def _main():
  N = int(input())
  lst = list(map(int, input().split()))
  K = int(input())
  key_lst = list(map(int, input().split()))

  ans = 0
  for k in range(K):
    if binary_search(N, lst, key_lst[k]): ans += 1
  print(ans)

def binary_search(N ,lst, key):
  left = 0
  right = N
  while left < right:
    mid = (left + right) // 2
    if lst[mid] == key:
      return True
    elif key < lst[mid]:
      right = mid
    else:
      left = mid + 1
  return False

if __name__ == '__main__':
  _main()

Submission status: Accepted

Solution code:
import bisect
n1 = int(input())
S = list(map(int, input().split()))
n2 = int(input())
T = list(map(int, input().split()))

count = 0
for t in T:
  idx = bisect.bisect_left(S, t)
  if idx < n1 and S[idx] == t:
    count += 1

print(count)

Submission status: Accepted

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

cnt = 0

for key in T:
	left = 0
	right = n
	mid = 0
	while left < right:
		mid = (left + right) // 2

		if int(S[mid]) == int(key):
			cnt += 1
			break

		if int(key) < int(S[mid]):#左側にある
			right = mid
		elif int(key) > int(S[mid]):#右側にある
			left = mid + 1

print(cnt)

Submission status: Accepted

Solution code:
import sys


def binary_search(arr, key):
    left = 0
    right = len(arr)
    while left < right:
        mid = int((left + right) / 2)
        if arr[mid] == key:
            return mid
        elif key < arr[mid]:
            right = mid
        else:
            left = mid + 1
    return -1


input = sys.stdin.readline
n = int(input())
s_list = list(map(int, input().split()))
q = int(input())
t_list = list(map(int, input().split()))

cnt = 0
for t in t_list:
    if binary_search(s_list, t) >= 0:
        cnt += 1
print(cnt)

Submission status: Accepted

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

def binary_search(s, x):
    left = 0
    right = len(s)
    while right > left:
        middle = int((left + right) / 2)
        if s[middle] == x:
            return middle
        elif s[middle] > x:
            right = middle
        else:
             left = middle + 1
    return -1
        

sum = 0
for i in range(q):
    if (binary_search(s, t[i]) != -1):
        sum += 1

print(sum)

Submission status: Accepted

Solution code:
input()
s = set(int(i) for i in input().split())
input()
t = set(int(i) for i in input().split())
print(len(t & s))

Submission status: Accepted

Solution code:
input()
a=input().split()
input()
print(len(set(a)&set(input().split())))

Submission status: Accepted

Solution code:

def linear_search(key, nums):
    for num in nums:
        if num == key:
            return True
    return False

def binary_search(key, nums):
    # print('binary_serach ' + str(key))
    left = 0
    right = len(nums)
    mid = int((left+right)/2)

    while left < right:
        mid = int((left+right)/2)
        # print(left, mid, right)
        if nums[mid] == key:
            return key
        elif key < nums[mid]:
            right = mid
        else:
            left = mid + 1
    return -1

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

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    N = int(input())
    S = list(map(int, input().split()))
    S.extend([-1, float('inf')])
    S.sort()
    # print(S)
    Q = int(input())
    T = list(map(int, input().split()))
    T.sort()
    ans = 0
    for ti in T:
        # S[x]
        ok = 0
        ng = len(S)
        while ng - ok > 1:
            mid = (ng+ok)//2
            if S[mid]<=ti: ok=mid
            else:          ng=mid
        if S[ok]==ti:
            ans += 1

    print(ans)

Submission status: Accepted

Solution code:
input()
a=set(map(int,input().split()))
n=int(input())
b=sorted(map(int,input().split()))
def bs(b,x):
    ma=len(b)
    mi=0
    while abs(ma-mi)>1:
        mid=(ma+mi)//2
        if b[mid]<x:
            mi=mid
        else:
            ma=mid
    if b[mi]==x:
        return True
    elif ma!=n and b[ma]==x:
        return True
    return False


print(sum([bs(b,i)for i in a]))

Submission status: Accepted

Solution code:
import sys
import bisect
input = sys.stdin.readline

n = int(input())
S = list(map(lambda x: int(x), input().strip().split()))

q = int(input())

count = 0
for t in input().strip().split():
    t = int(t)
    if S[bisect.bisect_left(S, t)] == t:
        count += 1
print(count)

Submission status: Accepted

Solution code:
def binarySearch(a, key):
    left = 0
    right = len(a)
    while left < right:
        mid = (left+right)//2
        if a[mid] == key:
            return True
        elif key < a[mid]:
            right = mid
        else:
            left = mid+1
    return False


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

sum_ = 0

for num in map(int, input().split()):
    if binarySearch(s, num):
        sum_ += 1

print(sum_)

Submission status: Accepted

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



def isOK(A, index, key):
    if A[index] >= key:
        return True
    else:
        return False


def binary_search(A, key):
    ng = -1
    ok = len(A)

    while(abs(ok-ng) > 1):
        mid = (ok + ng) // 2

        if isOK(A, mid, key):
            ok = mid
        else:
            ng = mid
    return ok


count = 0
for key in T:
    if S[binary_search(S, key)] == key:
        count += 1

print(count)

Submission status: Accepted

Solution code:
def BinarySearch(data, key):
    left = 0
    right = len(data)
    while left < right:
        mid = (left + right) // 2
        if data[mid] == key:
            return True
        elif key < data[mid]:
            right = mid
        else:
            left = mid + 1
    return False
n = int(input())
s = list(map(int,input().split()))
q = int(input())
t = list(map(int,input().split()))
ans = 0
for i in t:
    if BinarySearch(s,i):
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
SS = set([int(i) for i in input().split()])
q = int(input())
TS = set([int(i) for i in input().split()])

print(len(SS & TS))

Submission status: Accepted

Solution code:
def binary_search(nums, key, length):
    left = 0
    right = length - 1
    while left <= right:
        mid = left + (right - left) //2
        if nums[mid] == key:
            return True
        elif nums[mid] < key:
            left = mid + 1
        else:
            right = mid - 1
    return False


n1 = int(input())
nums1 = list(map(int, input().split(' ')))
n2 = int(input())
nums2 = list(map(int, input().split(' ')))
sum = 0 
for i in range(n2):
    flag = binary_search(nums1,nums2[i],n1)
    if flag:
        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())

ans = 0
for v in t:
    si, ei = 0, n-1
    while si < (ei-1):
        mi = (si+ei)//2
        if v < s[mi]:
            ei = mi
        else:
            si = mi
    if s[si] == v or s[ei] == v:
        ans += 1
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()))
C = 0
for i in range(q):
    left = 0
    right = n
    while left < right:
        mid = (left + right) // 2
        if T[i] > S[mid]:
            left = mid + 1
        elif T[i] < S[mid]:
            right = mid
        else:
            C += 1
            break
print(C)

Submission status: Accepted

Solution code:
#binary sertch
n = int(input())
T = list(map(int, input().split()))
q = int(input())
cnt = 0
def midle(left, right):
    return int((left + right)/2)

for i in input().split():
    right = n
    left = 0
    while left - right < 0:
        mid = midle(left, right)
        if T[mid] == int(i):
            cnt += 1
            break
        elif T[mid] < int(i):
            left = mid +1
        else:
            right = mid

print(cnt)

Submission status: Accepted

Solution code:
# coding: utf-8
n = int(input().rstrip())
S = list(map(int,input().rstrip().split()))
q = int(input().rstrip())
T = list(map(int,input().rstrip().split()))
count = 0
for i in range(q):
    start = 0
    end = n - 1
    half = 0
    while start <= end:
        half = int((start + end)/2)
        if S[half] == T[i]:
            count += 1
            break
        elif S[half] > T[i]:
            end = half - 1
        else:
            start = half + 1

print(count)

Submission status: Accepted

Solution code:
input();s=input().split()
input();t=input().split()
print(len(set(s)&set(t)))

Submission status: Accepted

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

def binarySearch(a, key):
    left = 0
    right = len(a)
    while left < right:
        mid = int((left + right) / 2)
        if a[mid] == key:   return 1
        elif key < a[mid]:  right = mid
        else:               left = mid + 1
    return 0

cnt = 0
for tmpT in T:
    cnt += binarySearch(S, tmpT)
print(str(cnt))

Submission status: Accepted

Solution code:
def binarySearch(key, array):
        left = 0
        right = len(array)
        while left < right:
                mid = (left + right) // 2
                if array[mid] == key:
                        return 1
                elif key < array[mid]:
                        right = mid
                else:
                        left = mid + 1
        return 0

num = int(input())
array = list(map(int, input().split()))

num2 = int(input())
array2 = list(map(int, input().split()))

count = 0
for i in range(num2):
        if binarySearch(array2[i], array):
                count += 1

print(count)

Submission status: Accepted

Solution code:
n = int(input())
s = list(map(int, input().split())) + [-1]
q = int(input())
t = map(int, input().split())
c = 0

for i in t:
    L = -1
    U = n
    while U - L > 1:
        x = (L+U) // 2
        if s[x] >= i: U = x
        else: L = x
    if s[U] == i: c += 1

print(c)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

def bsearch(target, S, N):
    left = 0
    right = N
    while left < right:
        mid = (right + left) // 2
        mid_value = S[mid]
        if mid_value == target:
            return 1
        elif mid_value > target:
            right = mid
            continue
        elif mid_value < target:
            left = mid + 1
            continue
    return 0

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

cnt = 0

for t in T:
    cnt += bsearch(t, S, N)

print(cnt)

Submission status: Accepted

Solution code:
n=int(input())
A=list(map(int,input().split()))
m=int(input())
B=list(map(int,input().split()))
c=0
def binary(A,key):
    global c
    left=0
    right=len(A)
    while left<right:
        mid=(left+right)//2
        
        if A[mid]==key:
            c+=1
            return c
        elif A[mid]<key:
            left=mid+1
        else:
            right=mid
    return False
for i in B:
    binary(A,i)
    
print(c)

Submission status: Accepted

Solution code:
i=lambda:set(input().split())
i()
s=i()
i()
print(len(s&i()))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
S = [int(x) for x in stdin.readline().rstrip().split()]
S.sort()
stdin.readline().rstrip()
T = [int(x) for x in stdin.readline().rstrip().split()]

def binSearch(S, val, l=0, r=n-1):
    while l < r:
        m = (l+r)//2
        if val < S[m]:
        	r = m-1
        elif val > S[m]:
        	l = m+1
        else:
        	l = r = m

    return ( l == r and S[l] == val)

C = 0
for ti in T:
    if binSearch(S, ti):
        C += 1

print(C)

Submission status: Accepted

Solution code:
from operator import add
from functools import reduce

def exist(S, x):
    #print("exist S, %d" % x)
    left, right = 0, len(S)
    while left < right:
        idx = (left + right) // 2
        if S[idx] == x:
            return 1
        if S[idx] < x:
            left = idx + 1
        else: 
            right = idx
    return 0

def solve(S, T):
    return reduce(add, (exist(S, x) for x in T))

if __name__ == '__main__':
    n = int(input())
    #print("input n")
    S = [int(s) for s in input().split()]
    #print("input S")
    assert len(S) == n
    q = int(input())
    #print("input q")
    T = [int(s) for s in input().split()]
    #print("input T")
    assert len(T) == q
    print(solve(S, T))

Submission status: Accepted

Solution code:
import sys
import math

def InputData():
    
    data_len = int(input())
    # data = int(input().split())
    data = list(map(int, input().split()))

    searchdata_len = int(input())
    # searchdata = int(input().split())
    searchdata = list(map(int, input().split()))
    # print([i for i in data])
    # print([i for i in searchdata])
    # print()
    # print(data_len)
    # print(searchdata_len)
    # print()

    # data = int(data)
    # searchdata = int(searchdata)

    return data_len, data, searchdata_len, searchdata

def Binary_Search(Data, key):
    
    right = len(Data)
    left = 0
    while left < right:
        mid = (left + right) // 2
        # print(searchdata[i])
        if key == Data[mid]:
            # print(searchdata[i])
            return mid
        elif key < Data[mid]:
            right = mid
        elif key > Data[mid]:
            left = mid + 1
        

    return "NOT_FOUND"

def PrintOut(count):
    print(count)

def main():
    [data_len, data, searchdata_len, searchdata] = InputData()
    count = 0
    for i in searchdata:
        if Binary_Search(data, i) != "NOT_FOUND":
            count += 1

    PrintOut(count)

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()))
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)

Submission status: Accepted

Solution code:
i=lambda:set(input().split())
i()
s=i()
i()
t=i()
print(len(s&t))

Submission status: Accepted

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

"""
二分探索
"""

from bisect import bisect_left

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

cnt = 0
for i in range(Q):
    idx = bisect_left(sN, tQ[i])
    # 探す要素が大きいとidxが範囲外にでるのでidx < N
    if idx < N and sN[idx] == tQ[i]:
        cnt += 1
print(cnt)