Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"
	"sort"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		hr := make([]entry, 0)
		for i := 0; i < n; i++ {
			scanner.Scan()
			buf := strings.Split(scanner.Text(), " ")
			first, _ := strconv.Atoi(buf[0])
			second, _ := strconv.Atoi(buf[1])
			mt := entry{first, second}
			hr = append(hr, mt)
		}
		scanner.Scan()
		m, _ := strconv.Atoi(scanner.Text())
		for i := 0; i < m; i++ {
			scanner.Scan()
			buf := strings.Split(scanner.Text(), " ")
			first, _ := strconv.Atoi(buf[0])
			second, _ := strconv.Atoi(buf[1])
			mt := entry{first, second}
			hr = append(hr, mt)
		}
		sort.Sort(ByFirst(hr))
		fmt.Println(LIS(hr))
	}
}

type entry struct {
	first, second int
}

type ByFirst []entry

func(f ByFirst) Len() int {
	return len(f)
}

func (f ByFirst) Swap(i, j int) {
	f[i], f[j] = f[j], f[i]
}

func (f ByFirst) Less(i, j int) bool {
	return f[i].first < f[j].first
}

func LIS(hr []entry) int {
	n := len(hr)
	lis := make([]int, n)
	lis[n-1] = 1
	for i := n-2; i > -1; i-- {
		m := 0
		for j := i+1; j < n; j++ {
			if hr[i].first < hr[j].first && hr[i].second < hr[j].second && lis[j] > m {
				m = lis[j]
			}
		}
		lis[i] = m+1
	}
	return lis[0]
}

C++: #include<iostream>
#include<cstdio>
#define N 1000
using namespace std;

int r[N],h[N];

int syori(int,int);
void sort(int,int);

int main(){
  int n1,n2,i,ans;
 
  while(1){
 
    for(i=1;i<=N;i++){
      r[i]=0;
      h[i]=0;
    }


    r[0]=-1;
    h[0]=-1;
   
    cin >> n1;
    if(n1==0)break;
   
    for(i=1;i<=n1;i++){    // 1©çÍ¶ßÄ¢éÉÓ
      cin >> h[i] >> r[i];
    }
   
    cin >> n2;
   
    for(i=n1+1;i<=n1+n2;i++){ // P©çÍ¶ßÄ¢éÉÓ
      cin >> h[i] >> r[i];
    }
   
    sort(n1,n2);

    ans=syori(n1,n2);
   
    cout << ans << endl;
  }
 
 
}

void sort(int n1,int n2){
  int i,j,max,hi;

  for(i=0;i<=(n1+n2);i++){
    max=i;
    for(j=i;j<(n1+n2);j++){
      if(h[j] <= h[max])max=j;
    }
      hi=h[max];
      h[max]=h[i];
      h[i]=hi;
   
         hi=r[max];
      r[max]=r[i];
      r[i]=hi;


  }

}



int syori(int n1,int n2){
  int ANS[N],i,j; //ANS[N]Í·³ð²×ézñ 
  int max=0,res=0;
 
  for(i=0;i<N;i++){
    ANS[i]=0;   
  }
  
 
  for(i=1;i<=(n1+n2);i++){
    max=0;
    //  cout <<endl<< "h["<<i<<"]--"<<h[i]<<endl;    
    // cout << "r["<<i<<"]--"<<r[i]<<endl;
    // cout << "ANS["<<i<<"]--"<<ANS[i]<<endl;
    // cout<< "Lo["<<i<<"]--"<<Lo[i]<<endl<<endl;


    for(j=0;j<i;j++){
      if(h[j]<h[i] && r[j]<r[i] && ANS[j]>ANS[max]){
    max=j;   
      }
   
    }
 ANS[i]=ANS[max]+1;
      
  }

  //  for(i=1;i<=(n1+n2);i++){
  //  cout << "ANS[" << i << "]--" << ANS[i]<< endl;
  // }


  for(i=1;i<=(n1+n2);i++){
      if(res<=ANS[i]){
    res=ANS[i];
    }
  }
  return res;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

vector< pair<int,int> > doll;
int dp[200];
int n,m,tmp1,tmp2;

int main(){
  while(cin>>n && n){
    for(int i=0;i<n;i++){
      cin>>tmp1>>tmp2;
      doll.push_back(make_pair(tmp1,tmp2));
    }
    cin>>m;
    for(int i=0;i<m;i++){
      cin>>tmp1>>tmp2;
      doll.push_back(make_pair(tmp1,tmp2));
    }

    sort(doll.begin(),doll.end());

    int ans=0;

    for(int i=0;i<n+m;i++){
      dp[i]=1;
      for(int j=0;j<i;j++){
        if(doll[i].second>doll[j].second){
          dp[i]=max(dp[i],dp[j]+1);
        }
      }
      ans=max(ans,dp[i]);
    }

    cout<<ans<<endl;

    while(doll.size()) doll.pop_back();
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
const int dx[]={0,1,0,-1,1,-1,-1,1};
const int dy[]={-1,0,1,0,1,1,-1,-1};
const int INF = 1<<30;
const double EPS = 1e-15;
#define PB push_back
#define mk make_pair
#define fi first
#define se second
#define ll long long
#define reps(i,j,k) for(int i = (j); i < (k); i++)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
typedef pair<int,int> Pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main(){
	int N,M;
	while(scanf("%d",&N),N){
		vector < Pii > data;
		rep(i,N){
			int a,b;
			scanf("%d%d",&a,&b);
			data.PB(Pii(a,b));
		}
		scanf("%d",&M);
		rep(i,M){
			int a,b;
			scanf("%d%d",&a,&b);
			data.PB(Pii(a,b));
		}
		sort(data.begin(),data.end());
		int l = -1;
		int ans = 0;
		int prev1,prev2;
		prev1 = prev2 = -1;
		rep(i,N+M){
			if(prev1 < data[i].fi && prev2 < data[i].se){
				prev1 = data[i].fi;
				prev2 = data[i].se;
				ans++;
			}
		}
		printf("%d\n",ans);
	}

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int n,m,h,r;

int main(){
	while(scanf("%d",&n),n != 0){
		vector<pair<int,int> > v = vector<pair<int,int> >(n);
		for(int i = 0; i < n; i++){
			scanf("%d%d",&h,&r);
			v[i] = make_pair(h,r);
		}
		scanf("%d",&m);
		for(int i = 0; i < m; i++){
			scanf("%d%d",&h,&r);
			v.push_back(make_pair(h,r));
		}
		sort(v.begin(),v.end());
		int ans = 1;
		pair<int,int> p = v[0];
		for(int i = 1; i < n + m; i++){
			if(p.first < v[i].first && p.second < v[i].second){
				p = v[i];
				ans++;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;


class Doll{
public:
    int h;
    int r;
    int dp;
    static bool Less(const Doll& l, const Doll& r){
	return l.h < r.h;
    }
    Doll(int x, int y, int z){
	h = x; r = y; dp = z;
    }
};

typedef vector<Doll> Dolls;

int main(){
    int n, m, h, r, result=0;
    Dolls dolls;
    while(cin >> n, n){
	for(int i=0; i<n; ++i){
	    cin >> h >> r;
	    Doll temp(h,r,1);
	    dolls.push_back(temp);
	}
	cin >> m;
	for(int i=0; i<m; ++i){
	    cin >> h >> r;
	    Doll temp(h,r,1);
	    dolls.push_back(temp);
	}
	sort(dolls.begin(), dolls.end(), Doll::Less);
	
	for(Dolls::iterator it1=dolls.begin()+1;it1 != dolls.end(); ++it1){
	    for(Dolls::iterator it2=dolls.begin();it2 != it1; ++it2){
		if(it2->h < it1->h && it2->r < it1->r && it1->dp <= it2->dp){
		    it1->dp = it2->dp + 1;
		    result = max(result, it1->dp);
		}
	    }
	}
	cout << result << endl;
	dolls.clear();
	result = 0;
    }
    return 0;
}

C++: #include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define SQ(x) ((x)*(x))
#define Mod(x, mod) (((x)+(mod)%(mod))
#define MP make_pair
#define PB push_back
#define Fi first
#define Se second
#define INF (1<<29)
#define EPS 1e-10
#define MOD 1000000007

typedef pair<int, int> P;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

P ma[256];
int dp[256];

int main(){
  int n;
  while(scanf("%d", &n) && n){
    rep(i,n) scanf("%d%d", &ma[i].first, &ma[i].second);
    int m;
    scanf("%d", &m);
    rep(i,m) scanf("%d%d", &ma[n+i].first, &ma[n+i].second);
    int V = n+m;
    sort(ma, ma+V);

    int res = 0;
    for(int i =0;i<V;i++){
      dp[i] = 1;
      for(int j=0;j<i;j++) if(ma[j].first < ma[i].first && ma[j].second < ma[i].second)
	  dp[i] = max(dp[i], dp[j]+1);
      res = max(res, dp[i]);
    }
    printf("%d\n", res);
  }
  return 0;
}