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<algorithm>

typedef std::pair<int,int> P;

int dp[200];//何番目のまとりょーしかが一番大きいか＝数

int main(){
	int ichiro,jiro,M=0;
	while(std::cin>>ichiro,ichiro){
		P dool[200];//高さ　半径
		std::cin>>ichiro;
		for(int i=0;i<ichiro;i++){
			std::cin>>dool[i].first>>dool[i].second;
		}
		std::cin>>jiro;
		for(int i=0;i<jiro;i++){
			std::cin>>dool[i+ichiro].first>>dool[i+ichiro].second;
		}
		std::sort(dool,dool+ichiro+jiro);
		for(int i=0;i<ichiro+jiro;i++)dp[i]=1;
		for(int i=1;i<ichiro+jiro;i++){
			for(int j=i-1;j>=0;j--){
				dp[i]=std::max(dp[i],dp[j]+(dool[i].second>dool[j].second));
			}
			M=std::max(M,dp[i]);
		}
		std::cout<<M<<std::endl;
		M=0;
		for(int i=0;i<ichiro+jiro;i++)dp[i]=0;
	}
	return 0;
}

C++: #include <iostream>
#include <cstring>
#include <vector>

using namespace std;

typedef pair<int, int> doll;

int main()
{
	int n, m, i, j;
	vector<doll> vc;
	int dp[200];
	
	vc.reserve(200);
	
	while( cin >> n, n)
	{
		vc.clear();
		memset( dp, 0, sizeof(dp));
		
		for( i = 0; i < n; i++)
		{
			doll d;
			cin >> d.first >> d.second;
			vc.push_back(d);
		}
		
		cin >> m;
		
		for( i = 0; i < m; i++)
		{
			doll d;
			cin >> d.first >> d.second;
			vc.push_back(d);
		}
		
		sort(vc.begin(), vc.end());
		

		
		dp[0] = 1;
		doll surface(vc[0].first, vc[0].second);

		for( i = 1; i < n+m; i++)
		{
			if( surface.first < vc[i].first && surface.second < vc[i].second )
			{
				dp[i] = dp[i-1] + 1;
				surface.first = vc[i].first;
				surface.second = vc[i].second;
			}
			else
			{
				dp[i] = dp[i-1];
			}
		}
		
		
		cout << dp[n+m-1] << endl;
	}
	
	return 0;
}

C++: #include<algorithm>
using namespace std;
#define MAX 200

class Doll{
    public:
    int h, r;
    Doll(){}
    Doll( int h, int r ): h(h), r(r){}

    bool operator < ( const Doll &d ) const {
	if ( r == d.r ) return h < d.h;
	else return r < d.r;
    }
};

Doll dolls[MAX+1];
int size;

int lis(){
    int T[MAX+1];
    T[0] = 0;
    dolls[0] = Doll( 0, 0 );
    for ( int i = 1; i <= size; i++ ){
	int maxi = 0;
	for ( int j = 0; j <= i - 1; j++ ){
	    if ( T[j] > T[maxi] && 
		 dolls[j].h < dolls[i].h && dolls[j].r < dolls[i].r ){
		maxi = j;
	    }
	}
	T[i] = T[maxi] + 1;
    }

    int maxv = 0;
    for ( int i = 1; i <= size; i++ ) maxv = max( maxv, T[i] );

    return maxv;
}

bool input(){
    int n, m, h, r;
    cin >> n;
    if ( n == 0 ) return false;

    dolls[0] = Doll(0, 0);

    for ( int i = 1; i <= n; i++ ){
	cin >> h >> r;
	dolls[i] = Doll( h, r );
    }
    cin >> m; size = n + m;
    for ( int i = n + 1; i <= size; i++ ){
	cin >> h >> r;
	dolls[i] = Doll( h, r );
    }
    return true;
}

int main(){
    while(input()){
	sort( dolls, dolls + size + 1);
	cout << lis() << endl;
    }
    return 0;
}

C++: #include<cstdio>
#include<vector>
#include<algorithm>
int field1[1001];
int field2[1001];
using namespace std;
int main(void){
    while(1){
        for(int i = 0;i <= 1001;i++){
            field1[i] = 0;
            field2[i] = 0;
        }
        int n; scanf("%d",&n);
        if(n == 0) break;
        vector<pair<int,int> > v1;
        vector<pair<int,int> > v2;
        pair<int,int> p;
        p.first = 0; p.second = 0;
        v1.push_back(p); v2.push_back(p);
        for(int i = 0;i < n;i++){
            int h,r; scanf("%d%d",&h,&r);
            p.first = h; p.second = r;
            v1.push_back(p);
            p.first = r; p.second = h;
            v2.push_back(p);
        }

        scanf("%d",&n);
        for(int i = 0;i < n;i++){
            int h,r; scanf("%d%d",&h,&r);
            p.first = h; p.second = r;
            v1.push_back(p);
            p.first = r; p.second = h;
            v2.push_back(p);
        }

        sort(v1.begin(),v1.end()); sort(v2.begin(),v2.end());
        for(int i = 1;i < v1.size();i++){
            for(int j = i - 1;j >= 0;j--){
                if(v1[i].second > v1[j].second && field1[i] <= field1[j]+1){
                    field1[i] = field1[j]+1;
                }
            }
        }

        for(int i = 1;i < v2.size();i++){
            for(int j = i-1;j >= 0;j--){
                if(v2[i].second > v2[j].second && field2[i] <= field2[j]+1){
                    field2[i] = field2[j]+1;
                }
            }
        }
        int ans = -1;
        for(int i = 0;i < v1.size();i++){
            if(field1[i] >= ans) ans = field1[i];
            if(field2[i] >= ans) ans = field2[i];
        }
        printf("%d\n",ans);
    }
    return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <list>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define F first
#define S second


int dx[]={0,1,0,-1},dy[]={1,0,-1,0};

typedef struct{
  int h,r;
}mat;

bool lessh(const mat&l,const mat&r){return l.h<r.h;};
bool lessr(const mat&l,const mat&r){return l.r<r.r;};


int low[200],ans;
mat hr[200];

main(){
  int n;
  while(cin>>n,n){
    rep(i,n)cin>>hr[i].h>>hr[i].r;
    int m;
    cin>>m;
    rep(i,m)cin>>hr[i+n].h>>hr[i+n].r;

    
    memset(low,0,sizeof(0));

    stable_sort(hr,hr+m+n,lessh);
    stable_sort(hr,hr+m+n,lessr);

    int ans=0;
    rep(i,n+m){
      rep(j,i){
	if(hr[j].h<hr[i].h && hr[j].r<hr[i].r){
	  low[i]=max(low[i],low[j]+1);
	  ans=max(ans,low[i]);
	}
      }
    }

    cout<<ans+1<<endl;
  }
}