Problem:
Score : 400 points

Problem Statement

On a two-dimensional plane, there are N red points and N blue points.
The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i).

A red point and a blue point can form a friendly pair when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point.

At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.

Constraints

All input values are integers.

1 \leq N \leq 100

0 \leq a_i, b_i, c_i, d_i < 2N

a_1, a_2, ..., a_N, c_1, c_2, ..., c_N are all different.

b_1, b_2, ..., b_N, d_1, d_2, ..., d_N are all different.

Input

Input is given from Standard Input in the following format:

N
a_1 b_1
a_2 b_2
:
a_N b_N
c_1 d_1
c_2 d_2
:
c_N d_N

Output

Print the maximum number of friendly pairs.

Sample Input 1

3
2 0
3 1
1 3
4 2
0 4
5 5

Sample Output 1

2

For example, you can pair (2, 0) and (4, 2), then (3, 1) and (5, 5).

Sample Input 2

3
0 0
1 1
5 2
2 3
3 4
4 5

Sample Output 2

2

For example, you can pair (0, 0) and (2, 3), then (1, 1) and (3, 4).

Sample Input 3

2
2 2
3 3
0 0
1 1

Sample Output 3

0

It is possible that no pair can be formed.

Sample Input 4

5
0 0
7 3
2 2
4 8
1 6
8 5
6 9
5 4
9 1
3 7

Sample Output 4

5

Sample Input 5

5
0 0
1 1
5 5
6 6
7 7
2 2
3 3
4 4
8 8
9 9

Sample Output 5

4

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>
using namespace std;
#define    FOR(i,a,n)       for(register int i=a,_=n;i<=_;++i)
#define    FIR(i,n,a)       for(register int i=n,_=a;i>=_;--i)
#define    VOR(i,a)         for(register int i=0,n=a.size();i<n;++i)
#define    VIR(i,a)         for(register int i=a.size()-1;i>=0;--i)
#define    SOR(i,a)         for(register auto i=a.begin();i!=a.end();++i)
#define    all(a)           (a).begin(),(a).end()
#define    vlb(a,n)         (lower_bound(all(a),n)-(a).begin())
#define    vub(a,n)         (upper_bound(all(a),n)-(a).begin())
#define    vlbx(a,n)        a[(lower_bound(all(a),n)-(a).begin())]
#define    vubx(a,n)        a[(upper_bound(all(a),n)-(a).begin())]
#define    mem(a,b)         memset(a,b,sizeof(a))
#define    pw(x)            (1ll<<(x))
#define    sz(x)            (int)x.size()
#define    INT              (1ll<<32)
#define    lowbit(x)        ((x)&(-x))
#pragma    comment(linker, "/STACK:1024000000,1024000000")
#define    lch              p<<1,l,mid
#define    rch              p<<1|1,mid+1,r
#define    ll               p<<1
#define    rr               p<<1|1
#define    queues           priority_queue
#define    pb               push_back
#define    mp               make_pair
#define    lb               lower_bound
#define    ub               upper_bound
#define    ff               first
#define    ss               second
//__attribute__((optimize("-O3")))
typedef    long long        LL;
typedef    pair<int,int>    PII;
typedef    vector<int>      VI;
typedef    vector<PII>      VPII;
const int       dx[]= { 0, 1, 0,-1, 0, 1,-1, 1,-1};
const int       dy[]= {-1, 0, 1, 0,-1, 1,-1,-1, 1};
const LL        LINF=0xfcfcfcfcfcfcfcfll;
const double    pi=acos(-1.0);
const double    ee=2.718281828459;
const double    eps=0.00000001;
const int       INF=0x3f3f3f3f;
const int       MOD=1000000007;
inline LL pmod(LL x,LL n,LL mod=MOD,LL res=1) { for(; n; x=x*x%mod,n>>=1)if(n&1)res=res*x%mod; return res; }
inline int myrand(int mod) { return ((LL)rand()<<32^(LL)rand()<<16^rand())%mod; }
inline int rand(int a,int b) { return a+myrand(b-a+1); }
template<class T>inline T max(T a,T b,T c) { return max(a,max(b,c)); }
template<class T>inline T min(T a,T b,T c) { return min(a,min(b,c)); }
template<class T>inline T max(T a,T b,T c,T d) { return max(a,max(b,c,d)); }
template<class T>inline T min(T a,T b,T c,T d) { return min(a,min(b,c,d)); }
inline int mul10(int n) { return (n<<3)+(n<<1); }
inline LL mul10(LL n) { return (n<<3)+(n<<1); }
inline int div10(int n,int q=0) { q=(n>>1)+(n>>2),q+=(q>>4),q+=(q>>8),q+=(q>>16),q>>=3; return q+(n-mul10(q)>9); }
inline LL div10(LL n,LL q=0) { q=(n>>1)+(n>>2),q+=(q>>4),q+=(q>>8),q+=(q>>16),q+=(q>>32),q>>=3; return q+(n-mul10(q)>9); }
static char bfi[1000000],*ci=bfi-1,*cl=bfi-1,chr,bfo[1000000],*co=bfo-1;
inline bool dig() { return (chr>='0'&&chr<='9')?true:false; }
inline char gtc() { return ci==cl&&(cl=(ci=bfi-1)+fread(bfi,1,1000000,stdin),ci==cl)?EOF:*++ci; }
inline void readbit(double &ret,double bit=0.1) { if(chr=gtc(),dig())ret+=(chr-'0')*bit,readbit(ret,bit*0.1); }
inline LL scan() { LL sum=0; bool flag=0; while(chr=gtc(),!(dig()||(chr=='-'?(chr=gtc(),flag=1):0))) if(chr==-1) return 0; while(dig())sum=mul10(sum)+chr-'0',chr=gtc(); return flag?-sum:sum; }
inline bool _read(int &res,bool flag=0,int sum=0) { while(chr=gtc(),!(dig()||(chr=='-'?(chr=gtc(),flag=1):0))) if(chr==-1) return 0; while(dig())sum=mul10(sum)+chr-'0',chr=gtc(); return (res=flag?-sum:sum,1); }
inline bool _read(LL &res,bool flag=0,LL sum=0) { while(chr=gtc(),!(dig()||(chr=='-'?(chr=gtc(),flag=1):0))) if(chr==-1) return 0; while(dig())sum=mul10(sum)+chr-'0',chr=gtc(); return (res=flag?-sum:sum,1); }
inline bool _read(double &ret,bool flag=0,LL sum=0) { while(chr=gtc(),!(dig()||(chr=='-'?(chr=gtc(),flag=1):0))) if(chr==-1) return 0; while((dig()))sum=mul10(sum)+chr-'0',chr=gtc(); if(ret=sum,chr=='.')readbit(ret); return (ret=flag?-ret:ret,1); }
inline bool _read(char &ch) { while(chr=gtc(),chr==' '||chr=='\n'||chr==-1) if(chr==-1) return 0; return (ch=chr,1); }
inline bool _read(char *p) { while(chr=gtc(),chr==' '||chr=='\n'||chr==-1) if(chr==-1) return 0; while(chr!='\n'&&chr!=EOF)*p++=chr,chr=gtc(); return !(*p=0); }
inline void _write() { fwrite(bfo,1,co-bfo+1,stdout),co=bfo-1; }
inline void ptc(char ch) { if(*++co=ch,co==bfo+999999)_write(); }
inline void _out(int x) { if(x<0)ptc('-'),x=-x; if(x>9)_out(div10(x)); ptc(x%10+'0'); }
inline void _out(LL x) { if(x<0)ptc('-'),x=-x; if(x>9)_out(div10(x)); ptc(x%10+'0'); }
inline void _out(double x,int n=6) { if(x<0)ptc('-'),x=-x; _out((LL)x),x-=(LL)x,ptc('.'); while(n--)x*=10; _out(LL(x+0.5)); }
inline void _out(const char ch) { ptc(ch); }
inline void _out(const char *p) { while(*p)ptc(*p++); }
inline void read() {}
inline void _out_() {}
template<class T>inline bool read(T &head) { return _read(head); }
template<class T>inline bool read(T *head) { return _read(head); }
template<class T,class ...U>inline bool read(T &head,U &...tail) { return _read(head),read(tail...); }
template<class T,class ...U>inline bool read(T *head,U &...tail) { return _read(head),read(tail...); }
template<class T,class ...U>inline bool read(T &head,U *...tail) { return _read(head),read(tail...); }
template<class T,class ...U>inline bool read(T *head,U *...tail) { return _read(head),read(tail...); }
template<class T,class ...U>inline void _out_(T head,U ...tail) { _out(' '),_out(head),_out_(tail...); }
template<class T,class ...U>inline void out(T head,U ...tail) { _out(head),_out_(tail...),_out('\n'); }
#ifndef ONLINE_JUDGE
inline void _debug_() {}
inline void _debug(int x) { _out(x); }
inline void _debug(LL x) { _out(x); }
inline void _debug(double x) { _out(x); }
inline void _debug(const char ch) { _out(ch); }
inline void _debug(const char *p) { _out(p); }
template<class T,class ...U>inline void _debug_(T head,U ...tail) { _out(' '),_out(head),_debug_(tail...); }
template<class ...T>inline void debug(T ...tail) { static int cnt=0; _debug_("#####",++cnt,'|',tail...,'\n'),_write(); }
#endif
/**_________________________head.end__________________________**/

const int N=1000005;
PII a[N],b[N];
int c[N];

bool cmp(PII i,PII j) {
    if(i.ff!=j.ff)return i.ff<j.ff;
    else return i.ss>j.ss;
}

/**_______________________main().begin________________________**/
int main() {
    ios::sync_with_stdio(false),cin.tie(NULL);
#ifndef ONLINE_JUDGE
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
#endif   ///main code begin......
    int n,ans=0;
    cin>>n;
    FOR(i,1,n)cin>>a[i].ff>>a[i].ss;
    FOR(i,1,n)cin>>b[i].ff>>b[i].ss;
    sort(a+1,a+n+1,cmp);
    sort(b+1,b+n+1,cmp);
    FIR(i,n,1) {
        FIR(j,n,1) {
            if(c[j]==0&&b[j].ff>a[i].ff&&b[j].ss>a[i].ss) {
                ++ans,c[j]=1;
                break;
            }
        }
    }
    cout<<ans<<endl;
#ifndef out__   ///code end......
    _write();
#endif
    return 0;
}
/**________________________main().end_________________________**/

/***************************************************************
**                                                            **
**  *********   *********   ********    **          ********* **
**      **      **          **     **   **          **        **
**      **      **          **     **   **          **        **
**      **      *********   ********    **          ********* **
**      **      **          **     **   **          **        **
**      **      **          **     **   **          **        **
**      **      *********   ********    *********   ********* **
**                                                            **
***************************************************************/