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: Wrong Answer

Solution code:
def main():
    n = int(stdinput())
    S = [*map(int, stdinput().split())]
    q = int(stdinput())
    T = [*map(int, stdinput().split())]

    S = sorted(S)

    c = 0
    for t in T:
        if binary_search(S, n, t):
            c += 1
    
    print(c)

def binary_search(S, n, t):
    left = 0
    right = n - 1
    
    while left < right:
        mid = (left + right) // 2

        # print(*[left, right, mid])
        
        if S[mid] == t:
            return True
        elif S[mid] > t:
            right = mid - 1
        else:
            left = mid + 1
    
    return False

def stdinput():
    from sys import stdin
    return stdin.readline().strip()

if __name__ == '__main__':
    main()
    # import cProfile
    # cProfile.run('main()')

Submission status: Wrong Answer

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

print(count)

Submission status: Wrong Answer

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

print(count)

Submission status: Wrong Answer

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


N1 = int(input())
arr1 = [int(n) for n in input().split()]
N2 = int(input())
arr2 = [int(n) for n in input().split()]

print(sum([binarySearch(key, arr1, N1) for key in arr2]))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding:utf-8 -*-
#from __future__ import print_function
import time
import sys
import io
import re
import math
start = time.clock()
i = 0
n=input()
S=map(int, raw_input().split())
q=input()
T=map(int, raw_input().split())
ST=S+T
t=set()
m=[x for x in ST if x in t or t.add(x)]
#print ' '.join(map(str, m))
print len(m)

Submission status: Time Limit Exceeded

Solution code:
#---------------for input--------------------
numberN=int(input())
arrayS=list(map(int,input().split()))

numberQ=int(input())
arrayT=list(map(int,input().split()))
#---------------for input----------------------

def linearSearch(arrayS,arrayT,numberQ):
    machedNumber=0
    index=0
    while index<numberQ:
        if arrayT[index] in arrayS:
            machedNumber+=1
        index+=1
    print(machedNumber) 

#----------------for main------------------------
linearSearch(arrayS,arrayT,numberQ)
#----------------for main------------------------

Submission status: Time Limit Exceeded

Solution code:
#---------------for input--------------------
numberN=int(input())
arrayS=list(map(int,input().split()))

numberQ=int(input())
arrayT=list(map(int,input().split()))
#---------------for input----------------------

def linearSearch(arrayS,arrayT,numberQ):
    machedNumber=0
    listForMached=[]
    index=0
    while index<numberQ:
        for s in arrayS:
            if arrayT[index] == s:
                if not s in listForMached:
                    listForMached.append(arrayT[index])
                    machedNumber+=1
            elif arrayT[index]<s:
                break
        index+=1
    print(machedNumber) 

#----------------for main------------------------
linearSearch(arrayS,arrayT,numberQ)
#----------------for 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()))
c = 0
for i in T:
    if i in S:
        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()))
s = []
for i in range(max(S) + 1):
    if i in S:
        s.append(i)
c = 0
for i in T:
    if (i in s):
        c += 1
    
print(c)

Submission status: Time Limit Exceeded

Solution code:
n1 = int(input())
a1 = [int(x) for x in input().split()]
n2 = int(input())
a2 = [int(x) for x in input().split()]

res = set()

cnt = 0

for i in range(n1) :
    for j in range(n2) :
        if a1[i] == a2[j] :
            res.add(a1[i])
            
print(len(res))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input().split()
for sn in s:
    sn = int(sn)

q = int(input())
t = input().split()
for tn in t:
    tn = int(tn)

answer = 0

import math
for tn in t:
    smin = 0
    smax = n - 1
    c = math.floor(n - 1 / 2)
    while(smax - smin > 0):
        if(tn == s[c]):
            answer = answer + 1
            break
        elif(tn > s[c]):
            smin = c
            c = math.floor((smin + smax) / 2) 
        elif(tn < s[c]):
            smax = c
            c = math.floor((smin + smax) / 2)

print(answer)

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


def b_search(x, y):
    a = 0
    b = len(x)
    if y > x[b-1] or y < x[a]:
        return 0
    while b - a >= 1:
        c = (a + b) // 2
        if x[c] == y:
            return 1
        elif y < x[c]:
            b = c
        else:
            a = c
    return 0


for i in range(len(t)):
    count += b_search(s, t[i])

print(count)

Submission status: Time Limit Exceeded

Solution code:
import copy

NOT_FOUND = False

# 二分探索
def binarySearch(n, S, t):
     
    left = 0
    right = n
    key = t
    while left < right:
        mid = (left + right) // 2
        if S[mid] == key:
            return True
        elif key < S[mid]:
            right = mid
        else:        
            left = mid + 1
    return NOT_FOUND
 
if __name__ == '__main__':
     
    # 入力
    n = int(input()) # 数列Sに含まれる整数の個数
    S = list(map(int,input().split())) # 整数を含む数列
    q = int(input()) # 数列Tに含まれる異なる整数の個数
    T = list(map(int,input().split())) # 異なる整数を含む数列
     
    # 初期化
    C = 0 # Tに含まれる整数の中でSに含まれるものの個数
     
    # 数列T内の整数を1つずつチェック
    for i in range(q):
        isExist = binarySearch(n, copy.deepcopy(S), T[i])
         
        # 存在してたらカウント
        if isExist :
            C = C + 1
    # 出力
    print(C)

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 t in T:
    S.append(t)
    i = 0
    while t != S[i]:
        i += 1
    if i != (len(S) - 1):
        count += 1
    S.pop()
print(count)

Submission status: Time Limit Exceeded

Solution code:
def search(l, n):
    l = l.copy()
    l.append(n)
    i = 0
    while l[i] != n:
        i += 1

    if i == len(l) - 1:
        print("NOT FOUND")
    else:
        print("FOUND")


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 ti in t:
    if ti in s:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def search(l, n):
    left = 0
    right = len(l) - 1
    m = (left + right) // 2

    # while right - left > 1:
    while left < right:
        if n == l[m]:
            return True
        elif n < l[m]:
            right = m
        elif n > l[m]:
            left = m
        else:
            raise Exception()

        m = (left + right) // 2

    # if l[left] == n or l[right] == n:
    #     return True
    # else:
    #     return False


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 ti in t:
    if search(s, ti):
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def search(l, n):
    left = 0
    right = len(l) - 1
    m = (left + right) // 2

    # while right - left > 1:
    while left < right:
        if n == l[m]:
            return True
        elif n < l[m]:
            right = m - 1
        elif n > l[m]:
            left = m
        else:
            raise Exception()

        m = (left + right) // 2


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 ti in t:
    if search(s, ti):
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l1=sorted(list(map(int,input().split())))
m=int(input())
l2=sorted(list(map(int,input().split())))
def nibutan(a,k):
    l=0
    r=len(a)
    while r>l:
        m=(r+l)//2
        if a[m]==k:
            return m
        elif k<a[m]:
            r=m
        else:
            l=m
    return -1
c=0
for i in l2:
    if nibutan(l1,i)!=-1:
        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 t in T:
	if t in S:
		cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:

n = int(raw_input())
S = []
S = map(int, raw_input().split())

q = int(raw_input())
T = []
T = map(int, raw_input().split())

count = 0

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

print count

Submission status: Time Limit Exceeded

Solution code:
# import sys

n = int(raw_input())
S = map(int, raw_input().strip(" ").split(" "))
q = int(raw_input())
T = map(int, raw_input().strip(" ").split(" "))

count = 0
for j in T:
	for n in S:
		if n == j:
			count += 1
			break

print count

Submission status: Time Limit Exceeded

Solution code:
# import sys

def binary_search(query, length, array):
	if length == 1:
		if query == array[0]:
			return 1
		else:
			return 0
	elif length == 0:
		return 0

	center = length / 2
	# print center, array
	if query > array[center]:
		return binary_search(query, length-(center+1), array[center+1:])
	elif query < array[center]:
		return binary_search(query, center, array[:center])
	else:
		return 1


n = int(raw_input())
S = map(int, raw_input().strip(" ").split(" "))
q = int(raw_input())
T = map(int, raw_input().strip(" ").split(" "))

count = 0

for t in T:
	count += binary_search(t, n, S)

print count

Submission status: Time Limit Exceeded

Solution code:
n = int(raw_input())
S_str = raw_input().split(" ")
S = map(lambda x : int(x), S_str)

m = int(raw_input())
T_str = raw_input().split(" ")
T = map(lambda x : int(x), T_str)

count = 0

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

Submission status: Time Limit Exceeded

Solution code:
n = int(raw_input())
S_str = raw_input().split(" ")
S = map(lambda x : int(x), S_str)

m = int(raw_input())
T_str = raw_input().split(" ")
T = map(lambda x : int(x), T_str)

count = 0

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

Submission status: Time Limit Exceeded

Solution code:
      
def binary_search(A,n):
    # sequence A, item n
    l = len(A)
    if l==0:
        return False
    elif A[l/2] > n:
        return binary_search(A[:l/2],n)
    elif A[l/2] == n:
        return True
    elif A[l/2]<n:
        return binary_search(A[(l/2)+1:],n)

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

C = 0
for k in T:
    if binary_search(S,k):
        C += 1
print C

Submission status: Time Limit Exceeded

Solution code:
      
def binary_search(A,n):
    # sequence A, item n
    l=len(A)
    if l==0:
        return False
    elif A[l/2] > n:
        return binary_search(A[:l/2],n)
    elif A[l/2] == n:
        return True
    elif A[l/2]<n:
        return binary_search(A[(l/2)+1:],n)

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

C = 0
for k in range(len(T)):
    if binary_search(S,T[k]):
        C += 1
print C

Submission status: Time Limit Exceeded

Solution code:
      
def binary_search(A,n):
    # sequence A, item n
    l=len(A)
    if l==0:
        return False
    elif A[l/2] > n:
        return binary_search(A[:l/2],n)
    elif A[l/2] == n:
        return True
    elif A[l/2]<n:
        return binary_search(A[(l/2)+1:],n)

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

C = 0
for k in range(len(T)):
    if binary_search(S,T[k]):
        C += 1
print C

Submission status: Time Limit Exceeded

Solution code:
class Sequence:
    def __init__(self,num, seq):
        self.n = num
        self.sequence = seq

def LinearSearch(A, n, key):
    i=0
    A[n] = key
    while A[i] != key:
        i += 1
    if i==n:
        return "NOT_FOUND"
    return i

if __name__ == "__main__":

    n = int(raw_input())
    x =	map(int, raw_input().split())
    x.append(" ")
    A = Sequence(n, x)
    n =	int(raw_input())
    x =	map(int, raw_input().split())
    x.append(" ")
    B = Sequence(n, x)

    C_num = 0

    for i in range(B.n):
        res = LinearSearch(A.sequence, A.n, B.sequence[i])
        if res != "NOT_FOUND":
            C_num += 1

    print(C_num)

Submission status: Time Limit Exceeded

Solution code:
def BinarySearch(A, n, key):
    left = 0
    right = n

    while left < right:
        mid = (left+right)/2
	if A[mid] == key:
            return mid
	elif key < A[mid]:
            right = mid
	elif key > A[mid]:
            left = mid
    return "NOT_FOUND"


if __name__ == "__main__":
    n1 = int(raw_input())
    x1 = map(int, raw_input().split())
    n2 = int(raw_input())
    x2 = map(int, raw_input().split())

    C_num = 0

    for i in range(n2):
	if BinarySearch(x1, n1, x2[i]) != "NOT_FOUND":
            C_num += 1

    print(C_num)

Submission status: Time Limit Exceeded

Solution code:
def binary_search(A,n):
    l = len(A)
    if l==0:
        return False
    elif A[l/2] > n: 
        return binary_search(A[:l/2],n)
    elif A[l/2] == n:
        return True
    elif A[l/2]<n:
        return binary_search(A[(l/2)+1:],n)

n = int(raw_input())
S = map(int,raw_input().split())
q = int(raw_input())
T = map(int,raw_input().split())
cnt = 0
for i in T:
    if binary_search(S,i): cnt += 1
print cnt

Submission status: Time Limit Exceeded

Solution code:
def binary_search(A,n):
    l = len(A)
    if l==0:
        return False
    elif A[l/2] > n: 
        return binary_search(A[:l/2],n)
    elif A[l/2] == n:
        return True
    elif A[l/2]<n:
        return binary_search(A[(l/2)+1:],n)

n = int(raw_input())
S = map(int,raw_input().split())
q = int(raw_input())
T = map(int,raw_input().split())
cnt = 0
for i in xrange(len(T)):
    if binary_search(S,T[i]): cnt += 1
print cnt

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Here your code !
n = int(raw_input())
S = map(int,raw_input().split())
q = int(raw_input())
T = map(int,raw_input().split())
C = 0

def binary_search(A,n):
    l = len(A)
    if l==0:
        return False
    elif A[l/2] > n: 
        return binary_search(A[:l/2],n)
    elif A[l/2] == n:
        return True
    elif A[l/2]<n:
        return binary_search(A[(l/2)+1:],n)

for item in T:
    if binary_search(S,item):
        C += 1
print C

Submission status: Time Limit Exceeded

Solution code:
def binarySearch(x, S):
    mid = len(S) / 2
    if mid < 2:
        return x in S
    if S[mid] == x:
        return True
    elif S[mid] > x:
        left = S[:mid]
        return binarySearch(x, left)
    else:
        right = S[mid + 1:]
        return binarySearch(x, right)

n = int(raw_input())
S = map(int, raw_input().split())
q = int(raw_input())
T = map(int, raw_input().split())
count = 0
for x in T:
    if binarySearch(x, S):
        count += 1
print count

Submission status: Time Limit Exceeded

Solution code:
def binarySearch(x, S):
    mid = len(S) / 2
    if mid < 2:
        return x in S
    if S[mid] == x:
        return True
    elif S[mid] > x:
        return binarySearch(x, S[:mid])
    else:
        return binarySearch(x, S[mid+1:])

n = int(raw_input())
S = map(int, raw_input().split())
q = int(raw_input())
T = map(int, raw_input().split())
count = 0
for x in T:
    if binarySearch(x, S):
        count += 1
print count

Submission status: Time Limit Exceeded

Solution code:
n=int(raw_input())
list1=list(map(int,raw_input().split()))
m=int(raw_input())
list2=list(map(int,raw_input().split()))
cnt=0
for i in list2:
	try:
		list1.index(i)
		cnt+=1
	except:
		pass
print cnt

Submission status: Time Limit Exceeded

Solution code:
cnt=0
n=int(raw_input())
A=map(int,raw_input().split())
m=int(raw_input())
B=map(int,raw_input().split())
for c in B:
	try:
		A.index(c)
		cnt+=1
	except:
		pass
print cnt

Submission status: Time Limit Exceeded

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

def binary_search(S,k):
    if len(S) == 1 and S[0] != k: return False
    p = len(S)/2
    if S[p] == k: return True
    else:
        return binary_search(S[:p],k) | binary_search(S[p:],k)

c = 0
for t in T:
    if binary_search(S,t): c += 1
print c

Submission status: Time Limit Exceeded

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

def binary_search(S,k):
    if len(S) == 1 and S[0] != k: return False
    p = len(S)/2
    if S[p] == k: return True
    elif S[p] > k:
        return binary_search(S[:p],k)
    else:
        return binary_search(S[p:],k)

c = 0
for t in T:
    if binary_search(S,t): c += 1
print c

Submission status: Time Limit Exceeded

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

def binary_search(S,k):
    if len(S) == 0: return False
    if len(S) == 1 and S[0] != k: return False
    p = len(S)/2
    if S[p] == k: return True
    elif S[p] > k:
        return binary_search(S[:p],k)
    else:
        return binary_search(S[p:],k)

c = 0
for t in T:
    if binary_search(S,t): c += 1
print c

Submission status: Time Limit Exceeded

Solution code:
iterator = [["NS", "S"], ["NT", "T"]]
var = {}
for i, j in iterator:
    var[i] = int(input())
    var[j] = [int(k) for k in input().split()]
res = 0
for T in var["T"]:
    if T in var["S"]:
        res += 1
print(res)

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
def gost(lis,ky):
    
    lens=len(lis)
    
    if lens <= 5:
        
        if ky in lis:
            return True
        else:
            return False
    
    if ky <= lis[(lens//2)-1]:
        return gost(lis[:(lens//2)],ky)
    else:
        return gost(lis[(lens//2):],ky)
    

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

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


i = 0
for it in t:
    if gost(s,it):
        i = i+1
print(i)

Submission status: Time Limit Exceeded

Solution code:
n = input()
 
S = [int(x) for x in raw_input().split()]
 
q = input()
 
T = [int(x) for x in raw_input().split()]
 
C = 0
 
for i in T:
 for j in S:
  if i==j:
   C += 1
   break
 
print C

Submission status: Time Limit Exceeded

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

left = 0
right = n

for key in T:
 while left<right:
  mid = (right - left)/2
  if key==S[mid]:
   C += 1
   break
  elif key<S[mid]:
   right = mid
  elif key>S[mid]:
   left = mid

print C

Submission status: Time Limit Exceeded

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

left = 0
right = n

for key in T:
 while left<right:
  mid = (right - left)/2
  if key==S[mid]:
   C += 1
   break
  elif key<S[mid]:
   right = mid
  elif key>S[mid]:
   left = mid+1

print C

Submission status: Time Limit Exceeded

Solution code:
n = input()

S = map(int, raw_input().split())

q = input()

T = map(int, raw_input().split())

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


print cnt

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
S = [int(s) for s in str(input()).split()]
q = int(input())
T = [int(t) for t in str(input()).split()]
#print(n, S, q, T)

C = [t for t in T if t in S]
print(len(C))

Submission status: Time Limit Exceeded

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

def main():
    n = int(raw_input())
    S = [int(_) for _ in raw_input().split()]
    q = int(raw_input())
    T = [int(_) for _ in raw_input().split()]
    Sum = 0
    for t in T:
        if binarySearch(S[:], t): Sum += 1
    print Sum
    return 0

main()

Submission status: Time Limit Exceeded

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

def main():
    n = int(raw_input())
    S = [int(_) for _ in raw_input().split()]
    q = int(raw_input())
    T = [int(_) for _ in raw_input().split()]
    Sum = 0
    for t in T:
        if binarySearch(S[:], t): Sum += 1
    print Sum
    return 0

main()

Submission status: Time Limit Exceeded

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

count   = 0
isExist = False
low     = 0
high    = n - 1
middle  = 0

for j in range(q):
    search = T[j]
    while True:
        middle = (high + low)/2
        print middle
        if S[middle] == search:
            count = count + 1
            break
        elif middle == 0:
            break
        elif search < S[middle]:
            high = middle - 1
        elif S[middle] < search:
            low = middle + 1

print count

Submission status: Time Limit Exceeded

Solution code:
def binarySearch(key, lst):
    while len(lst) >= 1:
        i = len(lst) / 2
        if lst[i] > key:
            lst = lst[:i]
        elif lst[i] < key:
            lst = lst[i + 1:]
        else:
            return True
    return False

if __name__ == "__main__":
    input()
    S = map(int, raw_input().split())
    input()
    T = map(int, raw_input().split())

    n = 0
    for t in T:
        if binarySearch(t, S[:]):
            n += 1
    print n

Submission status: Time Limit Exceeded

Solution code:
def binarySearch(key, lst):
    start = 0
    end = len(lst) - 1
    while end - start >= 0:
        i = (end - start) / 2 + start
        if lst[i] > key:
            end = i - 1
        elif lst[i] < key:
            start = i + 1
        else:
            return True
    return False

if __name__ == "__main__":
    input()
    S = map(int, raw_input().split())
    input()
    T = map(int, raw_input().split())

    n = 0
    for t in T:
        if binarySearch(t, S[:]):
            n += 1
    print n

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
def binary_search(key, l):
    ix = len(l) // 2

    while len(l) > 0:
        if key == l[ix]:
            return True

        if key < l[ix]:
            l = l[:ix]
        else:
            l = l[ix + 1:]
        ix = len(l) // 2

    return False

if __name__ == '__main__':
    n = input()
    s = [int(x) for x in input().split()]
    q = input()
    t = [int(x) for x in input().split()]

    ans = 0
    for e in t:
        ans += 1 if binary_search(e, s) else 0

    print(ans)

Submission status: Time Limit Exceeded

Solution code:
def binarySearch(S,t):
    if len(S) == 1:
        return S[0] == t
    m = len(S)//2
    if S[m] == t:
        return True
    if S[m] > t:
        return binarySearch(S[:m],t)
    if len(S) > 2:
        return binarySearch(S[m+1:],t)
    return False

if __name__=='__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: cnt += binarySearch(S,t)
    print(cnt)

Submission status: Time Limit Exceeded

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

# n??????????´??????????????????????q???????????¢??¢?´¢????????£??????O(qn)?????¢?????´???????????§?§£????????¨?????§??????


def linear_search(S, T):
    count = 0
    for i in xrange(len(T)):
        if T[i] in S:
            count += 1
    return count

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

    print linear_search(S, T)

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 binarysearch(key, a, length):
    left = 0
    right = length-1
    while left < right:
        mid = int((left + right)/2)
        if a[mid] == key:
            return True
        elif key < a[mid]:
            right = mid
        else:
            left = mid
    return False


cnt = 0
for i in T:
    if binarysearch(i, S, n):
        cnt += 1
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()))


def binarysearch(key, a, length):
    left = 0
    right = length
    while left < right:
        mid = int((left + right)/2)
        if a[mid] == key:
            return True
        elif key < a[mid]:
            right = mid
        else:
            left = mid
    return False


cnt = 0
for i in T:
    if binarysearch(i, S, n):
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

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

print(count)

Submission status: Time Limit Exceeded

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

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [int(i) for i in input().split()]
S = sorted(set(s), key=s.index)
q = int(input())
t = [int(i) for i in input().split()]
T = sorted(set(t))

count = 0
for v in T:
    if v in S:
        count += 1
        S[:] = S[S.index(v)+1:]

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [int(i) for i in input().split()]
S = sorted(set(s), key=s.index)
q = int(input())
t = [int(i) for i in input().split()]
T = sorted(set(t))

copy = S[:]
count = 0
for v in T:
    S = copy[:]
    while True:
        if len(S) == 0: break
        if v == S[len(S)//2]:
            count += 1
            break
        elif v > S[len(S)//2]:
            S[:] = S[len(S)//2+1:]
        elif v < S[len(S)//2]:
            S[:] = S[:len(S)//2]

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [int(i) for i in input().split()]
S = sorted(set(s), key=s.index)
q = int(input())
t = [int(i) for i in input().split()]
T = sorted(set(t))

copy = S[:]
count = 0
for v in T:
    S = copy[:]
    while True:
        if len(S) == 0: break
        if v == S[len(S)//2]:
            count += 1
            S[:] = S[S.index(v)+1:]
            break
        elif v > S[len(S)//2]:
            S[:] = S[len(S)//2+1:]
        elif v < S[len(S)//2]:
            S[:] = S[:len(S)//2]

print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
n = int(sys.stdin.readline()[:-1])
S = sorted(list(map(int, (sys.stdin.readline()[:-1]).split())))
q = int(sys.stdin.readline()[:-1])
T = list(map(int, (sys.stdin.readline()[:-1]).split()))

def search(A, leng, i):
    if leng == 1:
        return A[0] == i
    half = leng // 2
    h = A[half]
    if h == i:
        return True
    elif h < i:
        return search(A[half:], len(A[half:]), i)
    elif i < h:
        return search(A[:half], len(A[:half]), i)


count = 0
for t in T:
    if search(S, n, t):
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
n = int(sys.stdin.readline()[:-1])
S = list(map(int, (sys.stdin.readline()[:-1]).split()))
q = int(sys.stdin.readline()[:-1])
T = list(map(int, (sys.stdin.readline()[:-1]).split()))

def search(A, leng, i):
    if leng == 1:
        return A[0] == i
    half = leng // 2
    h = A[half]
    if h == i:
        return True
    elif h < i:
        return search(A[half:], len(A[half:]), i)
    elif i < h:
        return search(A[:half], len(A[:half]), i)

count = 0
for t in T:
    if search(S, n, t):
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
li1 = list(map(int,input().split()))
m = int(input())
li2 = list(map(int,input().split()))
cnt = 0

for i in li2:
	if i in li1:
		cnt +=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
li1 = list(map(int,input().split()))
m = int(input())
li2 = list(map(int,input().split()))
cnt = 0
 
for i in li2:
    if i in li1:
        cnt +=1
print(cnt)