Buggy python submission (verdict: Time Limit Exceeded):
casen=0
if casen==0:
    a=[]
    c=[]
    n=int(input())
    for i in range(n):
        ai,bi=map(int,input().split())
        a.append([ai,bi])
    for i in range(n):
        ci,di=map(int,input().split())
        c.append([ci,di])
elif casen==1:
    n=3
    a=[[2,0],[3,1],[1,3]]
    c=[[4,2],[0,4],[5,5]]
elif casen==2:
    n=3
    a=[[0,0],[1,1],[5,2]]
    c=[[2,3],[3,4],[4,5]]
elif casen==3:
    n=2
    a=[[2,2],[3,3]]
    c=[[0,0],[1,1]]
elif casen==4:
    n=5
    a=[[0,0],[7,3],[2,2],[4,8],[1,6]]
    c=[[8,5],[6,9],[5,4],[9,1],[3,7]]
elif casen==5:
    n=5
    a=[[0,0],[1,1],[5,5],[6,6],[7,7]]
    c=[[2,2],[3,3],[4,4],[8,8],[9,9]]

t=[]
for ia in range(n):
    s=set()
    for ic in range(n):
        if a[ia][0]<c[ic][0] and a[ia][1]<c[ic][1]:
            s.add(ic)
    t.append(s)

icnt=0

from collections import deque
tyn3 = deque()

def pcnt(icnt,ia,t,n,tyn3,icntmax,r,t2,it):
    ia1=ia
    if ia>=n-1:
        icnt2=len(r)
        icntmax=max(icnt2,icntmax)
        if len(tyn3)>0:
            it2=tyn3.pop()
            r.remove(it2)
        ia=ia-1
        return icntmax,ia
    t3=t[ia]-r
    r1=r.copy()
    for it in t3:
        ia=ia1+1
        t2=t[ia]
        r1.add(it)
        tyn3.append(it)
        icntmax,ia=pcnt(icnt,ia,t,n,tyn3,icntmax,r1,t2,it)
    ia=ia+1
    t2=t[ia]
    icntmax,ia=pcnt(icnt,ia,t,n,tyn3,icntmax,r,t2,it)
    return icntmax,ia

ia=-1    
icntmax=0
r=set()
t2=t[0]
it=0
icntmax,ia=pcnt(icnt,ia,t,n,tyn3,icntmax,r,t2,it)

print(icntmax)        
    

Fixed submission:
casen=0
if casen==0:
    a=[]
    c=[]
    n=int(input())
    for i in range(n):
        ai,bi=map(int,input().split())
        a.append([ai,bi])
    for i in range(n):
        ci,di=map(int,input().split())
        c.append([ci,di])
elif casen==1:
    n=3
    a=[[2,0],[3,1],[1,3]]
    c=[[4,2],[0,4],[5,5]]
elif casen==2:
    n=3
    a=[[0,0],[1,1],[5,2]]
    c=[[2,3],[3,4],[4,5]]
elif casen==3:
    n=2
    a=[[2,2],[3,3]]
    c=[[0,0],[1,1]]
elif casen==4:
    n=5
    a=[[0,0],[7,3],[2,2],[4,8],[1,6]]
    c=[[8,5],[6,9],[5,4],[9,1],[3,7]]
elif casen==5:
    n=5
    a=[[0,0],[1,1],[5,5],[6,6],[7,7]]
    c=[[2,2],[3,3],[4,4],[8,8],[9,9]]

c.sort()
a.sort(key=lambda x:x[1])
#a.reverse()

icnt=0
ic2=0
for ic in range(len(c)):
    for ia in range(len(a)-1,-1,-1):
        if a[ia][0]<c[ic][0] and a[ia][1]<c[ic][1]:
            icnt=icnt+1
            del a[ia]
            break
        else:
            continue
        break

print(icnt)

Buggy python submission (verdict: Time Limit Exceeded):
casen=0
if casen==0:
    a=[]
    c=[]
    n=int(input())
    for i in range(n):
        ai,bi=map(int,input().split())
        a.append([ai,bi])
    for i in range(n):
        ci,di=map(int,input().split())
        c.append([ci,di])
elif casen==1:
    n=3
    a=[[2,0],[3,1],[1,3]]
    c=[[4,2],[0,4],[5,5]]
elif casen==2:
    n=3
    a=[[0,0],[1,1],[5,2]]
    c=[[2,3],[3,4],[4,5]]
elif casen==3:
    n=2
    a=[[2,2],[3,3]]
    c=[[0,0],[1,1]]
elif casen==4:
    n=5
    a=[[0,0],[7,3],[2,2],[4,8],[1,6]]
    c=[[8,5],[6,9],[5,4],[9,1],[3,7]]
elif casen==5:
    n=5
    a=[[0,0],[1,1],[5,5],[6,6],[7,7]]
    c=[[2,2],[3,3],[4,4],[8,8],[9,9]]

#a.sort()
#c.sort()

t=[]
for ia in range(n):
    s=[]
    for ic in range(n):
        if a[ia][0]<c[ic][0] and a[ia][1]<c[ic][1]:
            s.append(ic)
    t.append(s)
#    print(s)
    
#t.sort()
#print("t: ",t)

icnt=0

#import queue
#tyn3 = queue.Queue()

from collections import deque
tyn3 = deque()

# FIFOキューの作成
#    q.put(i)
#    q.get()

def pcnt(icnt,ia,t,n,tyn3,icntmax):
#    print("icnt:",icnt," ia:",ia," n:",n," icntmax:",icntmax,",",t[ia][1],",",tyn2)
    ia1=ia
    if ia>=n-1:
        icntmax=max(icnt,icntmax)
#        print("return icnt:",icnt," icntmax:",icntmax,tyn2)
        if len(tyn3)>0:
            tyn3.pop()
        ia=ia-1
        return icntmax,ia
#    print(ia)
    icnt1=icnt
    for it in t[ia]:
        ia=ia1+1
        if not it in tyn3:
            icnt=icnt1+1
#            tyn3.put(it)
            tyn3.append(it)
            icntmax,ia=pcnt(icnt,ia,t,n,tyn3,icntmax)
    ia=ia+1
    icntmax,ia=pcnt(icnt,ia,t,n,tyn3,icntmax)
#    tyn2.pop(-1)
    return icntmax,ia

ia=-1    
icntmax=0
icntmax,ia=pcnt(icnt,ia,t,n,tyn3,icntmax)

print(icntmax)        
    

Fixed submission:
casen=0
if casen==0:
    a=[]
    c=[]
    n=int(input())
    for i in range(n):
        ai,bi=map(int,input().split())
        a.append([ai,bi])
    for i in range(n):
        ci,di=map(int,input().split())
        c.append([ci,di])
elif casen==1:
    n=3
    a=[[2,0],[3,1],[1,3]]
    c=[[4,2],[0,4],[5,5]]
elif casen==2:
    n=3
    a=[[0,0],[1,1],[5,2]]
    c=[[2,3],[3,4],[4,5]]
elif casen==3:
    n=2
    a=[[2,2],[3,3]]
    c=[[0,0],[1,1]]
elif casen==4:
    n=5
    a=[[0,0],[7,3],[2,2],[4,8],[1,6]]
    c=[[8,5],[6,9],[5,4],[9,1],[3,7]]
elif casen==5:
    n=5
    a=[[0,0],[1,1],[5,5],[6,6],[7,7]]
    c=[[2,2],[3,3],[4,4],[8,8],[9,9]]

c.sort()
a.sort(key=lambda x:x[1])
#a.reverse()

icnt=0
ic2=0
for ic in range(len(c)):
    for ia in range(len(a)-1,-1,-1):
        if a[ia][0]<c[ic][0] and a[ia][1]<c[ic][1]:
            icnt=icnt+1
            del a[ia]
            break
        else:
            continue
        break

print(icnt)

Buggy python submission (verdict: Time Limit Exceeded):
casen=0
if casen==0:
    a=[]
    c=[]
    n=int(input())
    for i in range(n):
        ai,bi=map(int,input().split())
        a.append([ai,bi])
    for i in range(n):
        ci,di=map(int,input().split())
        c.append([ci,di])
elif casen==1:
    n=3
    a=[[2,0],[3,1],[1,3]]
    c=[[4,2],[0,4],[5,5]]
elif casen==2:
    n=3
    a=[[0,0],[1,1],[5,2]]
    c=[[2,3],[3,4],[4,5]]
elif casen==3:
    n=2
    a=[[2,2],[3,3]]
    c=[[0,0],[1,1]]
elif casen==4:
    n=5
    a=[[0,0],[7,3],[2,2],[4,8],[1,6]]
    c=[[8,5],[6,9],[5,4],[9,1],[3,7]]
elif casen==5:
    n=5
    a=[[0,0],[1,1],[5,5],[6,6],[7,7]]
    c=[[2,2],[3,3],[4,4],[8,8],[9,9]]

a.sort()
c.sort()

t=[]
for ia in range(n):
    s=[]
    for ic in range(n):
        if a[ia][0]<c[ic][0] and a[ia][1]<c[ic][1]:
            s.append(ic)
    t.append([len(s),s])
#    print(s)
    
#t.sort()
#print("t: ",t)

tyn2=[]
icnt=0

#import queue
#tyn3 = queue.Queue()

from collections import deque
tyn3 = deque()

# FIFOキューの作成
#    q.put(i)
#    q.get()

def pcnt(icnt,ia,t,n,tyn3,icntmax):
#    print("icnt:",icnt," ia:",ia," n:",n," icntmax:",icntmax,",",t[ia][1],",",tyn2)
    ia1=ia
    if ia>=n-1:
        icntmax=max(icnt,icntmax)
#        print("return icnt:",icnt," icntmax:",icntmax,tyn2)
        if len(tyn3)>0:
            tyn3.pop()
        ia=ia-1
        return icntmax,ia
#    print(ia)
    icnt1=icnt
    for it in t[ia][1]:
        ia=ia1+1
        if not it in tyn3:
            icnt=icnt1+1
#            tyn3.put(it)
            tyn3.append(it)
            icntmax,ia=pcnt(icnt,ia,t,n,tyn3,icntmax)
    ia=ia+1
    icntmax,ia=pcnt(icnt,ia,t,n,tyn3,icntmax)
#    tyn2.pop(-1)
    return icntmax,ia

ia=-1    
icntmax=0
icntmax,ia=pcnt(icnt,ia,t,n,tyn3,icntmax)

print(icntmax)        
    


Fixed submission:
casen=0
if casen==0:
    a=[]
    c=[]
    n=int(input())
    for i in range(n):
        ai,bi=map(int,input().split())
        a.append([ai,bi])
    for i in range(n):
        ci,di=map(int,input().split())
        c.append([ci,di])
elif casen==1:
    n=3
    a=[[2,0],[3,1],[1,3]]
    c=[[4,2],[0,4],[5,5]]
elif casen==2:
    n=3
    a=[[0,0],[1,1],[5,2]]
    c=[[2,3],[3,4],[4,5]]
elif casen==3:
    n=2
    a=[[2,2],[3,3]]
    c=[[0,0],[1,1]]
elif casen==4:
    n=5
    a=[[0,0],[7,3],[2,2],[4,8],[1,6]]
    c=[[8,5],[6,9],[5,4],[9,1],[3,7]]
elif casen==5:
    n=5
    a=[[0,0],[1,1],[5,5],[6,6],[7,7]]
    c=[[2,2],[3,3],[4,4],[8,8],[9,9]]

c.sort()
a.sort(key=lambda x:x[1])
#a.reverse()

icnt=0
ic2=0
for ic in range(len(c)):
    for ia in range(len(a)-1,-1,-1):
        if a[ia][0]<c[ic][0] and a[ia][1]<c[ic][1]:
            icnt=icnt+1
            del a[ia]
            break
        else:
            continue
        break

print(icnt)

Buggy python submission (verdict: Time Limit Exceeded):
casen=0
if casen==0:
    a=[]
    c=[]
    n=int(input())
    for i in range(n):
        ai,bi=map(int,input().split())
        a.append([ai,bi])
    for i in range(n):
        ci,di=map(int,input().split())
        c.append([ci,di])
elif casen==1:
    n=3
    a=[[2,0],[3,1],[1,3]]
    c=[[4,2],[0,4],[5,5]]
elif casen==2:
    n=3
    a=[[0,0],[1,1],[5,2]]
    c=[[2,3],[3,4],[4,5]]
elif casen==3:
    n=2
    a=[[2,2],[3,3]]
    c=[[0,0],[1,1]]
elif casen==4:
    n=5
    a=[[0,0],[7,3],[2,2],[4,8],[1,6]]
    c=[[8,5],[6,9],[5,4],[9,1],[3,7]]
elif casen==5:
    n=5
    a=[[0,0],[1,1],[5,5],[6,6],[7,7]]
    c=[[2,2],[3,3],[4,4],[8,8],[9,9]]

a.sort()
c.sort()

t=[]
for ia in range(n):
    s=[]
    for ic in range(n):
        if a[ia][0]<c[ic][0] and a[ia][1]<c[ic][1]:
            s.append(ic)
    t.append([len(s),s])
#    print(s)
    
t.sort()
#print("t: ",t)

tyn2=[]
icnt=0

#import queue
#tyn3 = queue.Queue()

from collections import deque
tyn3 = deque()

# FIFOキューの作成
#    q.put(i)
#    q.get()

def pcnt(icnt,ia,t,n,tyn3,icntmax):
#    print("icnt:",icnt," ia:",ia," n:",n," icntmax:",icntmax,",",t[ia][1],",",tyn2)
    ia1=ia
    if ia>=n-1:
        icntmax=max(icnt,icntmax)
#        print("return icnt:",icnt," icntmax:",icntmax,tyn2)
        if len(tyn3)>0:
            tyn3.pop()
        ia=ia-1
        return icntmax,ia
#    print(ia)
    icnt1=icnt
    for it in t[ia][1]:
        ia=ia1+1
        if not it in tyn3:
            icnt=icnt1+1
#            tyn3.put(it)
            tyn3.append(it)
            icntmax,ia=pcnt(icnt,ia,t,n,tyn3,icntmax)
    ia=ia+1
    icntmax,ia=pcnt(icnt,ia,t,n,tyn3,icntmax)
#    tyn2.pop(-1)
    return icntmax,ia

ia=-1    
icntmax=0
icntmax,ia=pcnt(icnt,ia,t,n,tyn3,icntmax)

print(icntmax)        
    

Fixed submission:
casen=0
if casen==0:
    a=[]
    c=[]
    n=int(input())
    for i in range(n):
        ai,bi=map(int,input().split())
        a.append([ai,bi])
    for i in range(n):
        ci,di=map(int,input().split())
        c.append([ci,di])
elif casen==1:
    n=3
    a=[[2,0],[3,1],[1,3]]
    c=[[4,2],[0,4],[5,5]]
elif casen==2:
    n=3
    a=[[0,0],[1,1],[5,2]]
    c=[[2,3],[3,4],[4,5]]
elif casen==3:
    n=2
    a=[[2,2],[3,3]]
    c=[[0,0],[1,1]]
elif casen==4:
    n=5
    a=[[0,0],[7,3],[2,2],[4,8],[1,6]]
    c=[[8,5],[6,9],[5,4],[9,1],[3,7]]
elif casen==5:
    n=5
    a=[[0,0],[1,1],[5,5],[6,6],[7,7]]
    c=[[2,2],[3,3],[4,4],[8,8],[9,9]]

c.sort()
a.sort(key=lambda x:x[1])
#a.reverse()

icnt=0
ic2=0
for ic in range(len(c)):
    for ia in range(len(a)-1,-1,-1):
        if a[ia][0]<c[ic][0] and a[ia][1]<c[ic][1]:
            icnt=icnt+1
            del a[ia]
            break
        else:
            continue
        break

print(icnt)

Buggy python submission (verdict: Time Limit Exceeded):
casen=0
if casen==0:
    a=[]
    c=[]
    n=int(input())
    for i in range(n):
        ai,bi=map(int,input().split())
        a.append([ai,bi])
    for i in range(n):
        ci,di=map(int,input().split())
        c.append([ci,di])
elif casen==1:
    n=3
    a=[[2,0],[3,1],[1,3]]
    c=[[4,2],[0,4],[5,5]]
elif casen==2:
    n=3
    a=[[0,0],[1,1],[5,2]]
    c=[[2,3],[3,4],[4,5]]
elif casen==3:
    n=2
    a=[[2,2],[3,3]]
    c=[[0,0],[1,1]]
elif casen==4:
    n=5
    a=[[0,0],[7,3],[2,2],[4,8],[1,6]]
    c=[[8,5],[6,9],[5,4],[9,1],[3,7]]
elif casen==5:
    n=5
    a=[[0,0],[1,1],[5,5],[6,6],[7,7]]
    c=[[2,2],[3,3],[4,4],[8,8],[9,9]]

a.sort()
c.sort()

t=[]
for ia in range(n):
    s=[]
    for ic in range(n):
        if a[ia][0]<c[ic][0] and a[ia][1]<c[ic][1]:
            s.append(ic)
    t.append([len(s),s])
#    print(s)
    
t.sort()
#print("t: ",t)

tyn2=[]
icnt=0

def pcnt(icnt,ia,t,n,tyn2,icntmax):
#    print("icnt:",icnt," ia:",ia," n:",n," icntmax:",icntmax,",",t[ia][1],",",tyn2)
    ia1=ia
    if ia>=n-1:
        icntmax=max(icnt,icntmax)
#        print("return icnt:",icnt," icntmax:",icntmax,tyn2)
        if len(tyn2)>0:
            tyn2.pop(-1)
        ia=ia-1
        return icntmax,ia
#    print(ia)
    icnt1=icnt
    for it in t[ia][1]:
        ia=ia1+1
        if not it in tyn2:
            icnt=icnt1+1
            tyn2.append(it)
            icntmax,ia=pcnt(icnt,ia,t,n,tyn2,icntmax)
    ia=ia+1
    icntmax,ia=pcnt(icnt,ia,t,n,tyn2,icntmax)
#    tyn2.pop(-1)
    return icntmax,ia

ia=-1    
icntmax=0
icntmax,ia=pcnt(icnt,ia,t,n,tyn2,icntmax)

print(icntmax)        
    


Fixed submission:
casen=0
if casen==0:
    a=[]
    c=[]
    n=int(input())
    for i in range(n):
        ai,bi=map(int,input().split())
        a.append([ai,bi])
    for i in range(n):
        ci,di=map(int,input().split())
        c.append([ci,di])
elif casen==1:
    n=3
    a=[[2,0],[3,1],[1,3]]
    c=[[4,2],[0,4],[5,5]]
elif casen==2:
    n=3
    a=[[0,0],[1,1],[5,2]]
    c=[[2,3],[3,4],[4,5]]
elif casen==3:
    n=2
    a=[[2,2],[3,3]]
    c=[[0,0],[1,1]]
elif casen==4:
    n=5
    a=[[0,0],[7,3],[2,2],[4,8],[1,6]]
    c=[[8,5],[6,9],[5,4],[9,1],[3,7]]
elif casen==5:
    n=5
    a=[[0,0],[1,1],[5,5],[6,6],[7,7]]
    c=[[2,2],[3,3],[4,4],[8,8],[9,9]]

c.sort()
a.sort(key=lambda x:x[1])
#a.reverse()

icnt=0
ic2=0
for ic in range(len(c)):
    for ia in range(len(a)-1,-1,-1):
        if a[ia][0]<c[ic][0] and a[ia][1]<c[ic][1]:
            icnt=icnt+1
            del a[ia]
            break
        else:
            continue
        break

print(icnt)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

casen=0
if casen==0:
    a=[]
    c=[]
    n=int(input())
    for i in range(n):
        ai,bi=map(int,input().split())
        a.append([ai,bi])
    for i in range(n):
        ci,di=map(int,input().split())
        c.append([ci,di])
elif casen==1:
    n=3
    a=[[2,0],[3,1],[1,3]]
    c=[[4,2],[0,4],[5,5]]
elif casen==2:
    n=3
    a=[[0,0],[1,1],[5,2]]
    c=[[2,3],[3,4],[4,5]]
elif casen==3:
    n=2
    a=[[2,2],[3,3]]
    c=[[0,0],[1,1]]
elif casen==4:
    n=5
    a=[[0,0],[7,3],[2,2],[4,8],[1,6]]
    c=[[8,5],[6,9],[5,4],[9,1],[3,7]]
elif casen==5:
    n=5
    a=[[0,0],[1,1],[5,5],[6,6],[7,7]]
    c=[[2,2],[3,3],[4,4],[8,8],[9,9]]

a.sort()
c.sort()

#n = 3
#    n = int(input())
lis = [x for x in range(n)] # 0からn-1までのリスト
 
permutations_lis = itertools.permutations(lis)# 全ての場合のリストを生成
# 以下出力
icmax=0
for one_case in permutations_lis: 
#    print(list(one_case))
    icnt=0
    for i in range(n):
        ii=one_case[i]
        if a[i][0]<c[ii][0] and a[i][1]<c[ii][1]:
            icnt=icnt+1
    if icmax<icnt:
        icmax=icnt

print(icmax)        
        
    
    
    

Fixed submission:
casen=0
if casen==0:
    a=[]
    c=[]
    n=int(input())
    for i in range(n):
        ai,bi=map(int,input().split())
        a.append([ai,bi])
    for i in range(n):
        ci,di=map(int,input().split())
        c.append([ci,di])
elif casen==1:
    n=3
    a=[[2,0],[3,1],[1,3]]
    c=[[4,2],[0,4],[5,5]]
elif casen==2:
    n=3
    a=[[0,0],[1,1],[5,2]]
    c=[[2,3],[3,4],[4,5]]
elif casen==3:
    n=2
    a=[[2,2],[3,3]]
    c=[[0,0],[1,1]]
elif casen==4:
    n=5
    a=[[0,0],[7,3],[2,2],[4,8],[1,6]]
    c=[[8,5],[6,9],[5,4],[9,1],[3,7]]
elif casen==5:
    n=5
    a=[[0,0],[1,1],[5,5],[6,6],[7,7]]
    c=[[2,2],[3,3],[4,4],[8,8],[9,9]]

c.sort()
a.sort(key=lambda x:x[1])
#a.reverse()

icnt=0
ic2=0
for ic in range(len(c)):
    for ia in range(len(a)-1,-1,-1):
        if a[ia][0]<c[ic][0] and a[ia][1]<c[ic][1]:
            icnt=icnt+1
            del a[ia]
            break
        else:
            continue
        break

print(icnt)