Go: package main

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

func main() {
	io := NewIo()
	defer io.Flush()
	for {
		n := io.NextInt()
		if n == 0 {
			break
		}
		accum := make([]int, 86401)
		for i := 0; i < n; i++ {
			s, e := io.Next(), io.Next()
			hs, _ := strconv.Atoi(s[:2])
			ms, _ := strconv.Atoi(s[3:5])
			ss, _ := strconv.Atoi(s[6:8])
			accum[hs*60*60+ms*60+ss]++
			he, _ := strconv.Atoi(e[:2])
			me, _ := strconv.Atoi(e[3:5])
			se, _ := strconv.Atoi(e[6:8])
			accum[he*60*60+me*60+se]--
		}
		ans := 0
		for i := 1; i < 86401; i++ {
			accum[i] += accum[i-1]
			ans = intMax(accum[i], ans)
		}
		io.Println(ans)
	}
}

func intMax(a, b int) int {
	if a < b {
		return b
	}
	return a
}

// I/O template
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buff []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buff = append(buff, line...)
		if !isPrefix {
			break
		}
	}
	return string(buff)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	s := io.tokens[io.nextToken]
	io.nextToken++
	return s
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntSlice(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func ExampleIo() {
	io := NewIo()
	defer io.Flush()
	a := make([]int, 0, 3)
	a[0], a[1], a[2] = io.NextInt(), io.NextInt(), io.NextInt()
	io.Println(a)
	io.PrintIntSlice(a)
	Log("io", a)
}

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

int main(){
  int h1,m1,n1,h2,m2,n2,N;
  

  while(1){
    int cnt=0,mem=0,max1=0;
    cin>>N;
    if(N==0) break;
    int s[N],g[N];
    for(int i=0;i<N;i++){
      scanf("%d:%d:%d %d:%d:%d",&h1,&m1,&n1,&h2,&m2,&n2);
      s[i]=h1*3600+m1*60+n1;
      g[i]=h2*3600+m2*60+n2;
    }
    
    for(int i=0;i<N;i++){
      for(int j=mem;j<N;j++){
	if(s[j]<g[i]) cnt++;
	else if(s[j]==g[i]){
	  i++;
	  mem=j+1;
	}
	else{ 
	  mem=j;
	  i++;
	}
      }
      max1=max(max1,cnt);
      cnt=0;
    }
    cout<<max1<<endl;
  }
  return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int leave[10000],arrive[10000];
int main(){
	int n,h,m,s;
	char z;
	int best=1;
	while(true){
	cin>>n;
	if(n==0)
		break;
	for(int i=0;i<n;i++){
		cin>>h>>z>>m>>z>>s;
		s+=h*3600+m*60;
		leave[i]=s;
		cin>>h>>z>>m>>z>>s;
		s+=h*3600+m*60;
		arrive[i]=s;
		int count=0;
		int r=i;
		while(true){
			if(leave[i]<arrive[r])
				count++;
			else
				break;
			if(i==0)
				break;
			r--;
		}
		if(count>best)
			best=count;
	}
	cout<<best<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <numeric>
#include <algorithm>
#include <stack>
#include <map>
#include <cstdlib>
using namespace std;
int N;
int t[86400];
int main() {
   while(cin >> N, N){
       int t[86400+1]={0};
       for(int i=0; i<N; ++i){
           int h, m, s;
           int start, end;
            scan_f("%d:%d:%d", &h, &m, &s);
            start = h*3600+m*60+s;
            scan_f("%d:%d:%d", &h, &m, &s);
            end = h*3600 + m*60 + s;
            for(int i=start; i<end; ++i) t[i]++;
           
       }
       int ans = 0;
       for(int i=0; i<86400+1; ++i) ans = max(ans, t[i]);
       cout << ans << endl;
   }
   return 0;
}

C++: #include<cstdio>
#include<map>
#include<queue>
#include<functional>
using namespace std;
typedef pair<int,int>P;
int main()
{
	int n,h,m,s,r;
	P p;
	while(scanf("%d",&n),n)
	{
		priority_queue<P,vector<P>,greater<P> >q1,q2;
		while(n--)
		{
			scanf("%d:%d:%d",&h,&m,&s);
			p.first=(h*60+m)*60+s;
			scanf("%d:%d:%d",&h,&m,&s);
			p.second=h*3600+m*60+s;
			q1.push(p);
		}
		r=0;
#define F p=q1.top(),q1.pop(),q2.push(P(p.second,p.first))
		while(q1.size()||q2.size())
		{
			if(q1.size()&&q2.size())
			{
				if(q1.top().first<q2.top().first)
					F;
				else q2.pop();
			}
			else if(q1.size())F;
			else break;
			s=q2.size();
			r=(r>s?r:s);
		}
		printf("%d\n",r);
	}
	return 0;
}

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

int convert(string s){
	int h=(s[0]-'0')*10+(s[1]-'0');
	int m=(s[3]-'0')*10+(s[4]-'0');
	int t=(s[6]-'0')*10+(s[7]-'0');
	return h*3600+m*60+t;
}

class range{
public:
	int left,right;
	range(int left,int right):left(left),right(right){}
	range(){};
};

bool is_connect(range a,range b){
	if(b.left<a.right && a.right<b.right) return true;
	if(b.left<a.left && a.left<b.right) return true;
	return false;
}


int main()
{
	int n;
	while(cin>> n && n!=0){
		vector<range> V(n);
		for(int i=0;i<n;i++){
			string s,t;cin>>s>>t;
			V[i].left=convert(s);
			V[i].right=convert(t);
		}


		int ans=1;
		for(int i=0;i<n;i++){
			int count=1;
			for(int j=0;j<n;j++){
				if(i==j) continue;
				if(is_connect(V[i],V[j])) count++;
			}
			ans=max(ans,count);
		}
		cout<<ans<<endl;
	}
	return 0;
}

C++:  #define _USE_MATH_DEFINES
 #define INF 100000000
 #include <iostream>
 #include <cstdio>
 #include <sstream>
 #include <cmath>
 #include <cstdlib>
 #include <algorithm>
 #include <queue>
 #include <stack>
 #include <limits>
 #include <map>
 #include <string>
 #include <cstring>
 #include <set>
 #include <deque>
 #include <bitset>
 #include <list>

 using namespace std;

 typedef long long ll;
 typedef pair <int,int> P;

 static const double EPS = 1e-8;

int hour2second(int h,int m,int s){
  return h*60*60+m*60+s;
}

class Time{
public:
  int first;
  int last;
  Time(int a,int b) : first(a),last(b){}
  bool operator<(const Time& t1) const{
    return first < t1.first;
  }
};

int gRes = 0;

void dfs(int idx,int first,int last,const vector<Time>& times,int count){
  gRes = max(gRes,count);
  for(int i=idx;i<times.size();i++){
    if(times[i].first < last){
	dfs(i+1,times[i].first,times[i].last,times,count+1);
      }
      else{
	return;
      }
      }
  }

int main(){
   int n;
   while(~scanf("%d",&n)){
     if(n==0) break;

     gRes = 0;
     vector<Time> times;
     for(int i=0;i<n;i++){
       //hh:mm:ss hh:mm:ss 
       int hh[2],mm[2],ss[2];
       scanf("%d:%d:%d %d:%d:%d",
	     hh,mm,ss,hh+1,mm+1,ss+1);
       int first_second = hour2second(hh[0],mm[0],ss[0]);
       int last_second = hour2second(hh[1],mm[1],ss[1]);
       times.push_back(Time(first_second,last_second));
     }
     sort(times.begin(),times.end());

     dfs(0,times[0].first,times[0].last,times,0);
     
     // int res = 1;
     // for(int i=0;i<times.size();){
     //   int tmp = 1;
     //   // printf("i:%d\n",i);
     //   bool is_end = true;
     //   for(int j=i+1;j<times.size();){
     // 	 bool is_end = false;
     // 	 if(times[j].first < times[i].last){
     // 	   j++; tmp++;
     // 	   res = max(tmp,res);
     // 	   // printf("i:%d j:%d\n",i,j);
     // 	 }
     // 	 else{
     // 	   i=j;
     // 	   break;
     // 	 }
     //   }
     //   if(is_end) i++;
     // }
     printf("%d\n",gRes);
   }
}