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 <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl
#define show2(a, n, m) rep(i, n) { rep(j, m) {cout << a[i][j] << ' ';} cout << endl;} 
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;
typedef long double ld;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 86410;

int sec(string s) {
	string a, b, c;
	a = s.substr(0, 2);
	b = s.substr(3, 2);
	c = s.substr(6, 2);
	return stoi(a) * 60 * 60 + stoi(b) * 60 + stoi(c);
}

int main() {
//	cout << fixed << setprecision(15);
	vi c(N), ans;
	while(true) {
		int n;
		cin >> n;
		if(n == 0) break;
		fill(c.begin(), c.end(), 0);
		rep(i, n) {
			string s, t;
			cin >> s >> t;
			c[sec(s)]++;
			c[sec(t)]--;
		}
		rep(i, N-1) c[i+1] += c[i];
		int _ans = 0;
		rep(i, N) chmax(_ans, c[i]);
		ans.push_back(_ans);
	}
	for(int i: ans) cout << i << endl;
}

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

int main() {
  
  for(int n; cin >> n, n;) {
    int h, m, s;
    int data[86401] = {};
    for(int i=0; i<n; i++) {
      scanf("%d:%d:%d", &h, &m, &s);
      data[h*3600+m*60+s] ++;
      scanf("%d:%d:%d", &h, &m, &s);
      data[h*3600+m*60+s] --;
    }
    
    int res = 0;
    for(int i=0; i<=86400; i++) {
      data[i+1] += data[i];
      res = max(res, data[i]);
    }
    
    cout << res << endl;
  }
  
  return 0;
}

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

int n, ans = 0;
char dummy;
vector<int> memo[2];
void solve();

int main() {
  int i, a, b, c, x, y, z;
  while(1) {
    cin >> n;
    if(n == 0) break;
    ans = 0;
    for(i = 0; i < n; ++i) {
      cin >> a >> dummy >> b >> dummy >> c >> x >> dummy >>
          y >> dummy >> z;
      memo[0].push_back(a * 3600 + b * 60 + c);
      memo[1].push_back(x * 3600 + y * 60 + z);
    }
    for(i = 0; i < 2; ++i)
      sort(memo[i].begin(), memo[i].end());
    solve();
    cout << ans << endl;
    for(i = 0; i < 2; ++i)
      memo[i].erase(memo[i].begin(), memo[i].end());
  }
  return 0;
}

void solve() {
  int now = 0, ns = 0, ng = 0;
  for(ng = 0; ng < n; ++ng) {
    ns = ng;
    while(memo[0][ns] < memo[1][ng] && ns < n) {
      ++now;
      ++ns;
    }
    ans = max(ans, now);
    now = 0;
  }
}

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

bool compare(const pair<int,int> &A,const pair<int,int> &B){
	if(A.first!=B.first) return A.first<B.first;
	else return A.second<B.second;
}

int main(void){
  int n;
  while(cin>>n,n){
    vector<pair<int,int> > timetable;
    for(int i=0;i<n;++i){
      int sh,sm,ss,eh,em,es;
      scanf("%d:%d:%d",&sh,&sm,&ss);
      scanf("%d:%d:%d",&eh,&em,&es);
      timetable.push_back(make_pair(sh*3600+sm*60+ss,1));
      timetable.push_back(make_pair(eh*3600+em*60+es,-1));
    }
    sort(timetable.begin(),timetable.end(),compare);
    int ans=0;
    int now=0;
    for(int i=0;i<2*n;++i){
    	now+=timetable[i].second;
    	ans=max(now,ans);
    }
    cout<<ans<<endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define PRINT(x) cout<<(x)<<endl
#define INF 1000000000000 // 10^12
#define MOD 1000000007 // 10^9+7
#define PB push_back
#define MP make_pair

int n;
string t_str1, t_str2;

const int ONEDAY = 24 * 60 * 60;

int ctoi(char c) {
    return c - '0';
}

int read_time(string t_str) {
    int hh = ctoi(t_str[0]) * 10 + ctoi(t_str[1]);
    int mm = ctoi(t_str[3]) * 10 + ctoi(t_str[4]);
    int ss = ctoi(t_str[6]) * 10 + ctoi(t_str[7]);
    int t = 60 * 60 * hh + 60 * mm + ss;
    return t;
}

int main() {
    while (true) {
        cin >> n;
        if (n == 0) break;

        vector<int> time_table(ONEDAY, 0);

        REP(i, n) {
            cin >> t_str1 >> t_str2;
            int t1 = read_time(t_str1);
            int t2 = read_time(t_str2);
            time_table[t1]++;
            time_table[t2]--;
        }

        int ans = 0;
        int num_train = 0;
        REP(i, ONEDAY) {
            num_train += time_table[i];
            ans = max(ans, num_train);
        }
        PRINT(ans);
    }
    return 0;
}