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: Time Limit Exceeded

Solution code:
# encoding: utf-8


class Solution:
    @staticmethod
    def binary_search():
        array_length_1 = int(input())
        array_1 = [int(x) for x in input().split()]
        array_length_2 = int(input())
        array_2 = [int(x) for x in input().split()]

        # print(len(set(array_1).intersection(set(array_2))))
        left, right, count = 0, array_length_1, 0
        for each in array_2:
            while left < right:
                mid = (left + right) // 2
                if array_1[mid] == each:
                    count += 1
                elif each < array_1[mid]:
                    right = mid
                else:
                    left = mid + 1

        print(count)


if __name__ == '__main__':
    solution = Solution()
    solution.binary_search()

Submission status: Time Limit Exceeded

Solution code:
# encoding: utf-8


class Solution:
    @staticmethod
    def binary_search():
        array_length_1 = int(input())
        array_1 = [int(x) for x in input().split()]
        array_length_2 = int(input())
        array_2 = [int(x) for x in input().split()]

        # print(len(set(array_1).intersection(set(array_2))))
        left, right, count = 0, array_length_1, 0
        for each in array_2:
            while left < right:
                mid = int((left + right) / 2)
                if array_1[mid] == each:
                    count += 1
                elif each < array_1[mid]:
                    right = mid
                else:
                    left = mid + 1

        print(count)


if __name__ == '__main__':
    solution = Solution()
    solution.binary_search()

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left
from functools import lru_cache

@lru_cache(maxsize=None)
def index(a, x):
    ''' Locate the leftmost value exactly equal to x
    http: // docs.python.jp / 3.5 / library / bisect.html
    '''
    i = bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    raise ValueError


if __name__ == '__main__':
    # ??????????????\???
    # S = [1, 2, 3, 4, 5]
    # T = [3, 4, 1]
    num = int(input())
    S = tuple(int(x) for x in input().split(' '))
    num = int(input())
    T = [int(x) for x in input().split(' ')]

    # ????´¢??????
    found = 0
    for t in T:
        try:
            index(S, t)
        except ValueError:
            pass
        else:
            found += 1

    # ???????????????
    print(found)

Submission status: Time Limit Exceeded

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

for i in T:
    if i in S:
        C += 1

print(C)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

n = int(input())
s = input().rstrip().split()
q = int(input())
t = input().rstrip().split()
count = 0
for x in t:
    if x in s:
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

n = int(input())
s = tuple(map(int, input().rstrip().split()))
q = int(input())
t = tuple(map(int, input().rstrip().split()))
# print(s)
# print(t)
count = 0
for x in t:
    if x in s:
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:

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



def search(s,T):
    left = 0 ; right = len(T)-1
    while left <= right:
        mid = (left + right)//2
        if T[mid]==s: return True
        elif T[mid]>s: right = mid
        else: left = mid+1

count = 0
for s in S:
    if search(s,T): count+=1


print(count)

Submission status: Time Limit Exceeded

Solution code:

def BinarySearch(n, S, t):
    """ ????????????????????? """
    left = 0
    right = n - 1

    while left <= right:
        center = (left + right) // 2

        if t > S[center]:
            left = center + 1
        elif t < S[center]:
            right = center - 1
        else:
            return center

    return -1

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 BinarySearch(n, S[:], t) != -1:
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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 = sum(t in S for t in T)
 
print(cnt)

Submission status: Time Limit Exceeded

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

sum = 0
for c in T:
    left = 0
    right = n
    mid = 0
    while left < right:
        mid = int(( left + right ) / 2)
        if c == S[mid]:
            sum += 1
            break
print(sum)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding:utf-8 -*-
n = int(input())
S = list(map(int,input().split()))
q = int(input())
T = list(map(int,input().split()))

sum = 0
for c in T:
    left = 0
    right = n
    mid = 0
    while left < right:
        mid = int(( left + right ) / 2)
        if c == S[mid]:
            sum += 1
            break
print(sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

def binarySearch(a,b):
    if a == b[-1]:
        return 1
    elif len(b) == 1:
        return 0
    elif a < b[int(len(b)/2)]:
        return binarySearch(a,  b[:int(len(b)/2)])
    elif a >= b[int(len(b)/2)]:
        return binarySearch(a,  b[int(len(b)/2):])

for i in T:
    count += binarySearch(i,S)
print(count)

Submission status: Time Limit Exceeded

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

def binarySearch(a,b):
    left = 0
    right = len(b)
    while left < right:
        middle = (left + right)//2
        
        if b[middle] == a:
            return 1
        elif b[middle] < a:
            left = middle -1
        elif b[middle] > a:
            right = middle 
    return 0

            
for a in t:
    count += binarySearch(a, s)

print(count)

Submission status: Time Limit Exceeded

Solution code:
def binsearch(order, key):                                     
    n = len(order) / 2                                         
    if order[n] == key:                                        
        return True, n                                         
    elif len(order) == 1:                                      
        return False, None                                     
    elif order[n] > key:                                       
        return binsearch(order[:n], key)                       
    else:                                                      
        return binsearch(order[n:], key)                       
                                                               
n = raw_input()                                                
l = map(int, raw_input().split())                              
n = raw_input()                                                
s = map(int, raw_input().split())                              
                                                               
sum = 0                                                        
for i in s:                                                    
    isfind, pos = binsearch(l, i)                              
    if isfind:                                                 
        sum += 1                                               
print sum

Submission status: Time Limit Exceeded

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

def do_binary_search(target_value, target_list, target_list_length=None):
    left = 0
    right = target_list_length

    while right - left > 0:
        mid = (right + left) / 2
        key = target_list[mid]
        if key == target_value:
            return True
        elif target_value < key:
            right = mid
        else:
            left = mid + 1
    return False



def main():
    s_length = int(raw_input())
    s = [int(x) for x in raw_input().strip().split(' ')]
    t_length = raw_input()
    t = [int(x) for x in raw_input().strip().split(' ')]

    counter = 0
    for value in t:
        # counter += int(do_binary_search(value, s, s_length))
        counter += int(value in s)

    print counter 

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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

tCount = 0


for tmp_t in tList:
    if 0 < sList.count(tmp_t):
        tCount += 1

print(tCount)

Submission status: Time Limit Exceeded

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

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

print(cnt)

Submission status: Time Limit Exceeded

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


res = 0

for num in T:
    if num in S:
        res += 1

print(res)

Submission status: Time Limit Exceeded

Solution code:
c = 0
input()
s = input().split()
input()
t = input().split()
for make in t :
    if make in s : c += 1
print(c)

Submission status: Time Limit Exceeded

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

findCount = 0

for t in T:
    left = 0
    right = n - 1
    center = right // 2
    while left != right:
        if S[center] == t:
            findCount += 1
            break
        
        if S[center] >= t:
            right = center
        else:
            left = center
            
        center = (left + right) // 2

print(findCount)

Submission status: Time Limit Exceeded

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

findCount = 0

for t in T:
    left = 0
    right = n
    center = right // 2
    preCenter= 0
    while left < right:
        if S[center] == t:
            findCount += 1
            break
        
        if S[center] >= t:
            right = center
        else:
            left = center
        
        center = (left + right) // 2

print(findCount)

Submission status: Time Limit Exceeded

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

c = 0
for t in t_list:
    if t in s_list:
        c += 1

print(c)

Submission status: Time Limit Exceeded

Solution code:
def binary_search(t, s_list):
    left = 0
    right = len(s_list) - 1

    while left < right:
        mid = (left + right) // 2
        if s_list[mid] == t:
            return True
        elif s_list[mid] > t:
            right = mid
        else:
            left = mid
    return False


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

c = 0
for t in t_list:
    if binary_search(t, s_list):
        c += 1

print(c)

Submission status: Time Limit Exceeded

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 T:
 a = 0
 b = n-1
 while b >= a:
  mid = (a + b) // 2
  if S[mid] == i:
   cnt += 1
   break
  elif S[mid] > i:
   b = mid
   continue
  else:
   a = mid + 1
   continue
print(str(cnt))

Submission status: Time Limit Exceeded

Solution code:
import bisect
n = int(input())
S = tuple(map(int, input().split()))
q = int(input())
T = tuple(map(int, input().split()))
cnt = 0
for n in T:
    cnt += n in S
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#ALDS1_4-B BinarySearch
n=input()
S=input().split()
q=input()
T=input().split()
c=0
for t in T:
    if(t in S):c+=1
print(c)

Submission status: Time Limit Exceeded

Solution code:
#ALDS1_4-B BinarySearch
import heapq

S = []
T = []
n=input()
S = input().split()
q=input()
T = input().split()
c=0
heapq.heapify(S)
for t in T:
    if(t in S):c+=1
        
print(c)

Submission status: Time Limit Exceeded

Solution code:
#ALDS1_4-B BinarySearch
import heapq

S = []
T = []
n=input()
S = input().split()
q=input()
T = input().split()
c=0
heapq.heapify(S)
heapq.heapify(T)
for t in T:
    if(t in S):c+=1
        
print(c)

Submission status: Time Limit Exceeded

Solution code:
#ALDS1_4-B BinarySearch
c=0
n=input()
S = input().split()
q=input()
T = input().split()
for t in T:
    if( t in set(S)):c+=1
print(c)

Submission status: Time Limit Exceeded

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

cnt = 0

def binarysearch(x, l):
	mi = 0
	ma = len(l) - 1
	
	while mi != ma:
		tmp = (mi + ma) // 2
		
		if l[tmp] == x:
			return tmp
		elif l[tmp] < x:
			mi = tmp + 1
		else:
			ma = tmp - 1
	else:
		if x == l[mi]:
			return mi
		else:
			return -1
	
	

for x in t:
	if binarysearch(x, s) != -1:
		cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

print(sum([t in S for t in T]))

Submission status: Time Limit Exceeded

Solution code:
def binarySearch(t):
	left,right = 0,n
	while right > left:
		mid = (left+right) // 2
		if S[mid] == t:
			return True
		elif S[mid] > t:
			mid = right
		else:
			mid = left
	return False

n = int(input())
S = [int(s) for s in input().split()]
q = int(input())
T = [int(s) for s in input().split()]

print(sum([binarySearch(t) for t in T]))

Submission status: Time Limit Exceeded

Solution code:
def binarySearch(t):
	left,right = 0,n
	while right > left:
		mid = (left+right) // 2
		if S[mid] == t:
			return True
		elif S[mid] > t:
			right = mid
		else:
			left = mid
	return False

n = int(input())
S = [int(s) for s in input().split()]
q = int(input())
T = [int(s) for s in input().split()]

print(sum([binarySearch(t) for t in T]))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Binary Search
n ????????´??°???????????°??? S ??¨???q ????????°????????´??°???????????°??? T ??????????????????
T ?????????????????´??°????????§ S ?????????????????????????????° C ???????????????????????°????????????????????????????????????
"""
def bsrch(l, a):
    """ ????????????????????? """
    c = int(len(l) / 2)
    if l[c] == a:
        return True
    else:
        if c > 0:
            if l[c] > a:
                return bsrch(l[:c], a)
            elif l[c] < a:
                return bsrch(l[c:], a)
    return False

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

    cnt = {}

    for j in range(q):
       x = bsrch(S, T[j])
       if x == True:
           cnt[T[j]] = 1
    print(len(cnt))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

def binarySearch(array, target):
    l = len(array)
    first_half = array[:l//2]
    second_half = array[l//2:]
    if first_half == []:
        if target in second_half:
            return True
        return False
    if first_half[-1] == target:
        return True
    elif first_half[-1] < target:
        return binarySearch(second_half, target)
    else:
        return binarySearch(first_half, target)

a = 0
for t in T: a += binarySearch(S, t)
print(a)

Submission status: Time Limit Exceeded

Solution code:
input()
S = input().split()
input()
T = input().split()
count = 0
for t in T:
    if t in S:
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()
snum = list(map(int, input().split()))
q = input()
qnum = list(map(int, input().split()))
c = 0
for i in qnum:
    if i in snum:
        c += 1

print(c)

Submission status: Time Limit Exceeded

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

ans = sum([1 for tmp_t in T if tmp_t in S])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
S = map(int,raw_input().split())
q = int(input())
T = map(int,raw_input().split())
count = 0
for v in T:
    for i in range(n):
        if S[i] == v:
            count += 1
            break
print count

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
S = map(int,raw_input().split())
q = int(input())
T = map(int,raw_input().split())
count = 0
lst = []
for v in S:
    if v in lst:
        pass
    else:
        for i in range(q):
            if T[i] == v:
                count += 1
                break
    lst.append(v)
print count

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
S = map(int,raw_input().split())
q = int(input())
T = map(int,raw_input().split())
count = 0
lst = []
for v in S:
    if v in lst:
        pass
    else:
        for i in range(q):
            if T[i] == v:
                count += 1
    lst.append(v)
print count

Submission status: Time Limit Exceeded

Solution code:
def binarySearch(e, n, A):
    if e<A[0] or e>A[-1]:
        return False
    l, r = 0, n
    while l<=r:
        m = (r+l)//2
        if e == A[m]:
            return True
        elif e < A[m]:
            r = m
        else:
            l = m
    return False


def ALDS1_4B():
    n, S = int(input()), list(map(int, input().split()))
    q, T = int(input()), list(map(int, input().split()))
    print(sum([1 for e in T if binarySearch(e, n, S)]))


if __name__ == '__main__':
    ALDS1_4B()

Submission status: Time Limit Exceeded

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

count = 0
for item in t:
    middle = int((n - 1) / 2)
    upper = n - 1
    lower = 0
    while(True):
        if s[middle] == item:
            count += 1
            break
        elif upper == lower:
            break
        elif s[middle] > item:
            upper = middle
            middle = int((lower + middle) / 2)
        elif s[middle] < item:
            lower = middle
            middle = int((upper + middle) / 2)

print(count)

Submission status: Time Limit Exceeded

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


def binary_search(data, targets, n):
    cnt = 0
    for num in targets:
        small = 0
        big = n - 1
        while 1:
            index = (small + big) >> 1
            if num == data[index]:
                cnt += 1
                break
            if small == big:
                break
            if num < data[index]:
                big = index - 1
            elif num > data[index]:
                small = index + 1

    return cnt


if __name__ == "__main__":
    data = [val.split() for val in sys.stdin.read().splitlines()]
    print(binary_search(data[1], data[3], int(data[0][0])))

Submission status: Time Limit Exceeded

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 T:
    if i in S:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

Sum = 0

for i in T:
  if i in S:
    Sum += 1
print(Sum)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
S = list(input().split())
q = input()
T = input().split()
 
count = 0
for key in T:
    U = S + [key]
    i = 0
    while U[i] != key:
        i = i+1
    if i != n:
        count = count + 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = map(int, input().split())
 
count = 0
for key in T:
    left = 0
    right = n
    while left < right:
        mid = (right - left) // 2
        if S[mid] == key:
            count = count + 1
            break
        if key < S[mid]:
            right = mid
        else:
            left = mid + 1
print(count)

Submission status: Time Limit Exceeded

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

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

    print(cnt)

main()

Submission status: Time Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(50000)
ERROR_INPUT = 'input is invalid'
ERROR_INPUT_NOT_UNIQUE = 'input is not unique'


def main():
    S = get_input1()
    T = get_input2()

    count = 0
    for t in T:
        if binary_search(S, t, 0, len(S), 0):
            count += 1

    print(count)


def binary_search(li, key, left, right, mid):
    mid = (left + right) // 2
    if li[mid] == key:
        return True
    elif li[mid] < key:
        left = mid + 1
    elif li[mid] > key:
        right = mid

    if left >= right:
        return False
    return binary_search(li, key, left, right, mid)


def get_input1():
    n = int(input())
    if n > 100000:
        print(ERROR_INPUT)
        sys.exit(1)

    li = []
    for x in input().split(' '):
        if int(x) < 0 or int(x) > 10 ** 9:
            print(ERROR_INPUT)
            sys.exit(1)
        li.append(int(x))

    return li


def get_input2():
    n = int(input())
    if n > 50000:
        print(ERROR_INPUT)
        sys.exit(1)

    li = []
    for x in input().split(' '):
        if int(x) < 0 or int(x) > 10 ** 9:
            print(ERROR_INPUT)
            sys.exit(1)
        elif int(x) in li:
            print(ERROR_INPUT_NOT_UNIQUE)
            sys.exit(1)
        li.append(int(x))

    return li


main()

Submission status: Time Limit Exceeded

Solution code:
import sys

ERROR_INPUT = 'input is invalid'
ERROR_INPUT_NOT_UNIQUE = 'input is not unique'


def main():
    S = get_input1()
    T = get_input2()

    count = 0
    for t in T:
        if binary_search(S, t, 0, len(S), 0):
            count += 1

    print(count)


def binary_search(li, key, left, right, mid):
    while left < right:
        mid = (left + right) // 2
        if li[mid] == key:
            return True
        elif li[mid] < key:
            left = mid + 1
        elif li[mid] > key:
            right = mid

    return False


def get_input1():
    n = int(input())
    if n > 100000:
        print(ERROR_INPUT)
        sys.exit(1)

    li = []
    for x in input().split(' '):
        if int(x) < 0 or int(x) > 10 ** 9:
            print(ERROR_INPUT)
            sys.exit(1)
        li.append(int(x))

    return li


def get_input2():
    n = int(input())
    if n > 50000:
        print(ERROR_INPUT)
        sys.exit(1)

    li = []
    for x in input().split(' '):
        if int(x) < 0 or int(x) > 10 ** 9:
            print(ERROR_INPUT)
            sys.exit(1)
        elif int(x) in li:
            print(ERROR_INPUT_NOT_UNIQUE)
            sys.exit(1)
        li.append(int(x))

    return li


main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    _ = input()
    li1 = [int(x) for x in input().split()]
    _ = input()
    li2 = [int(x) for x in input().split()]
    count = 0

    for l in li2:
        if binary_search(li1, l):
            count += 1

    print(count)


def binary_search(li, x):
    if len(li) == 0:
        return False
    
    mid = len(li)//2
    
    k = li[mid]
    if k == x:
        return True
    elif k > x:
        li = li[:mid]
    else:
        li = li[mid+1:]
        
    return binary_search(li, x)

if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n1 = int(input())
    if n1 > 100000:
        return 
    li1 = [int(x) for x in input().split()]
    n2 = int(input())
    if n2 > 50000:
        return 
    li2 = [int(x) for x in input().split()]
    count = 0

    for l in li2:
        if binary_search(li1, l):
            count += 1

    print(count)


def binary_search(li, x):
    if len(li) == 0:
        return False
    
    mid = len(li)//2
    
    k = li[mid]
    if k == x:
        return True
    elif k > x:
        li = li[:mid]
    else:
        li = li[mid+1:]
        
    return binary_search(li, x)

if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

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
for i in t:
    if i in s:
        count+=1

print(count)

Submission status: Time Limit Exceeded

Solution code:
#coding: UTF-8
#@document_it
def document_it(func):
  def new_function(*args,**kwargs):
    print('Running function:', func.__name__)
    print('Positional arguments:', args)
    print('Kewword arguments:', kwargs)
    result = func(*args,**kwargs)
    print('Result:', result)
    return result
  return new_function

#@document_it
def binsearch(v,list,length=None,offset=0):
    if list == []:
        return -1
    if length == None:
        length = len(list)
    w = length//2
    if v == list[w]:
        return w + offset
    elif v < list[w]:
        return binsearch(v,list[0:w],offset=offset)
    else:
        return binsearch(v,list[w+1:],offset=w+1+offset)

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 binsearch(t,S,n) != -1:
    ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

if __name__ == '__main__':
    data = []
    count = 0
    for line in sys.stdin:
        data.append(line.split())
    n = int(data[0][0])
    q = int(data[2][0])
    t = list(map(int, data[3]))
    for i in range(0, q):
        head = 0
        tail = n - 1
        s = list(map(int, data[1]))
        while True:
            if head > tail :
                break
            center = (head + tail)//2
            if s[center] == t[i] :
                count = count + 1
                break
            elif s[center] < t[i]:
                head = center + 1
            else :
                tail = center - 1
    print(count)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    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)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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):
    OK = 0
    NG = N-1
    while abs(OK-NG)>0:
        mid = (OK+NG)//2
        if S[mid]==T[i]:
            ans += 1
            break
        elif S[mid]<T[i]:
            OK = mid
        else:
            NG = mid

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [int(x) for x in input().split()]
q = int(input())
t = [int(x) for x in input().split()]
cnt = 0
y = None
for x in s:
    if x == y:
        continue
    else:
        if x in t:
            cnt += 1
            y = x
        else:
            continue
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

n = int(input())
s = deque([int(x) for x in input().split()])
q = int(input())
t = [int(x) for x in input().split()]
cnt = 0

for i in t:
    if i in s:
        cnt += 1
        while i in s:
            s.remove(i)
    else:
        continue
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [int(x) for x in input().split()]
q = int(input())
t = [int(x) for x in input().split()]
a = list(filter(lambda x: x in s, t))
print(len(a))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [int(x) for x in input().split()]
q = int(input())
a = list(filter(lambda x: x in s, [int(y) for y in input().split()]))
print(len(a))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [int(x) for x in input().split()]
q = int(input())
t = [int(x) for x in input().split()]
a = [x for x in t if x in s]
print(len(a))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [int(x) for x in input().split()]
q = int(input())
t = [int(x) for x in input().split()]
cnt = 0
for k in t:
    center = int(n/2)
    shift = int(n/2)
    j = 0
    while True:
        if k == s[center]:
            cnt += 1
            break
        elif k > s[center]:
            shift = int(shift/2)
            center += shift
        elif k < s[center]:
            shift = int(shift/2)
            center -= shift
        else:
            print("ERROR")
        if shift == 0:
            j += 1
            if j == 2:
                if k in s[:center] or k in s[center:]:
                    cnt += 1
                break
print(cnt)

Submission status: Time Limit Exceeded

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

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

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

print(result)

Submission status: Time Limit Exceeded

Solution code:
def binary_search(S, key):
    mid = len(S) // 2

    if len(S) == 0:
        return 0
    
    if S[mid] == key:
        return 1

    if S[mid] >= key:
        if binary_search(S[:mid], key):
            return 1
    else:
        if binary_search(S[mid + 1:], key):
            return 1

    return 0

n = int(input())
S = [int(i) for i in input().split(' ')]

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

result = 0
for t in T:
    result += binary_search(S, t)

print(result)