Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input().split()
q = int(input())
t = input().split()
c = 0

for i in t:
    l = 0
    r = n
    cen = int((l+r) / 2)
    while r > l :
        if i > s[cen]:
            l = cen
            cen = int((l+r) / 2)
        elif i < s[cen]:
            r = cen
            cen = int((l+r) / 2)
        elif i == s[cen]:
            c += 1
            break
print(c)


Fixed submission:
n = int(input())
s = input().split()
q = int(input())
t = input().split()
c = 0
s = list(map(int,s))
t = list(map(int,t))

for i in t:
    l = 0
    r = n-1
    cen = int((l+r) / 2)
    while r >= l :
#        print("0:",i,l,r,cen,s[cen])
        if i > s[cen]:
            l = cen
            cen = int((l+r) / 2)
#            print("1:",l,r,cen,s[cen])
        elif i < s[cen]:
            r = cen
            cen = int((l+r) / 2)
#            print("2:",l,r,cen,s[cen])
        if i == s[cen] or i == s[l] or i == s[r]:
            c += 1
#            print("!")
            break
        if l+1 > r-1:
#            print("!!",i)
            break
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input().split()
q = int(input())
t = input().split()
c = 0
s = list(map(int,s))
t = list(map(int,t))

for i in t:
    l = 0
    r = n-1
    cen = int((l+r) / 2)
    while r >= l :
#        print("0:",i,l,r,cen,s[cen])
        if i > s[cen]:
            l = cen
            cen = int((l+r) / 2)
#            print("1:",l,r,cen,s[cen])
        elif i < s[cen]:
            r = cen
            cen = int((l+r) / 2)
#            print("2:",l,r,cen,s[cen])
        if i == s[cen]:
            c += 1
#            print("!")
            break
        if l+1 == r-1:
#            print("!!")
            break
print(c)



Fixed submission:
n = int(input())
s = input().split()
q = int(input())
t = input().split()
c = 0
s = list(map(int,s))
t = list(map(int,t))

for i in t:
    l = 0
    r = n-1
    cen = int((l+r) / 2)
    while r >= l :
#        print("0:",i,l,r,cen,s[cen])
        if i > s[cen]:
            l = cen
            cen = int((l+r) / 2)
#            print("1:",l,r,cen,s[cen])
        elif i < s[cen]:
            r = cen
            cen = int((l+r) / 2)
#            print("2:",l,r,cen,s[cen])
        if i == s[cen] or i == s[l] or i == s[r]:
            c += 1
#            print("!")
            break
        if l+1 > r-1:
#            print("!!",i)
            break
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input().split()
q = int(input())
t = input().split()
c = 0
s = list(map(int,s))
t = list(map(int,t))

for i in t:
    l = 0
    r = n-1
    cen = int((l+r) / 2)
    while r >= l :
#        print("0:",i,l,r,cen,s[cen])
        if i > s[cen]:
            l = cen
            cen = int((l+r) / 2)
#            print("1:",l,r,cen,s[cen])
        elif i < s[cen]:
            r = cen
            cen = int((l+r) / 2)
#            print("2:",l,r,cen,s[cen])
        if i == s[cen] or i == s[l] or i == s[r]:
            c += 1
#            print("!")
            break
        if l+1 == cen and r-1 == cen:
#            print("!!",i)
            break
print(c)



Fixed submission:
n = int(input())
s = input().split()
q = int(input())
t = input().split()
c = 0
s = list(map(int,s))
t = list(map(int,t))

for i in t:
    l = 0
    r = n-1
    cen = int((l+r) / 2)
    while r >= l :
#        print("0:",i,l,r,cen,s[cen])
        if i > s[cen]:
            l = cen
            cen = int((l+r) / 2)
#            print("1:",l,r,cen,s[cen])
        elif i < s[cen]:
            r = cen
            cen = int((l+r) / 2)
#            print("2:",l,r,cen,s[cen])
        if i == s[cen] or i == s[l] or i == s[r]:
            c += 1
#            print("!")
            break
        if l+1 > r-1:
#            print("!!",i)
            break
print(c)