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 <bits/stdc++.h>
using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0, sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

int main(void){
    int n;
    cin >> n;
    while(n != 0){
        VI imos(86402,0);
        REP(i,n){
            string a,b; cin >> a >> b;
            auto va = split(a,':');
            auto vb = split(b,':');
            int s = 3600*toInt(va[0]) + 60*toInt(va[1]) + toInt(va[2]);
            int t = 3600*toInt(vb[0]) + 60*toInt(vb[1]) + toInt(vb[2]);
            imos[s]++; imos[t]--;
        }
        int ans = 0, now = 0;
        REP(i,86402){
            now += imos[i];
            chmax(ans, now);
        }
        cout << ans << en;
        cin >> n;
    }
    return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>

using namespace std;
int N;
string In[10000], Out[10000];
int main() {
  while (cin >> N && N > 0) {
    for (int i=0; i<N; ++i) {
      cin >> Out[i] >> In[i];
    sort(In, In+N);
    sort(Out, Out+N);
    //    for (int i=0; i<N; ++i)
    //      cout << Out[i] << ' ' << In[i] << endl;
  }

  int p=0, taiki=0, train=0;
  for (int i=0; i<N; ++i) {
    while (p<N && In[p] <=Out[i]) {
      taiki++;
      p = p+1;
    }
    if (taiki > 0) taiki = taiki - 1;
    else train = train + 1;
  }
  cout << train << endl;
}
}

C++: #include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

int n, ans = 1;
char dummy;
vector<pair<int, int>> memo;
bool cmp(pair<int, int> l, pair<int, int> r) {
  if(l.se < r.se)
    return 1;
  else if(l.se == r.se && l.fi < r.fi)
    return 1;
  return 0;
}
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;
      cout << a << " " << b << " " << c << " " << x << " "
           << y << " " << z << endl;
      memo.push_back(make_pair(a * 3600 + b * 60 + c,
                               x * 3600 + y * 60 + z));
    }
    solve();
    cout << ans << endl;
    memo.erase(memo.begin(), memo.end());
  }
  return 0;
}

void solve() {
  int i, ntime, now = 1;
  ntime = memo[0].se;
  for(i = 1; i < memo.size(); ++i) {
    if(memo[i].fi < ntime)
      ++now;
    else {
      ans = max(now, ans);
      now = 1;
      ntime = memo[i].se;
    }
  }
}

C++: #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
const int MAX = 24 * 60 * 60 + 60 * 60 + 60 + 1;
int f(int h, int m, int s) {
  return h * 3600 + m * 60 + s;
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  int imos[MAX];
  while(cin>>n,n) {
    int ans = 0;
    CLR(imos);
    FOR(i,0,n) {
      int h1, m1, s1;
      int h2, m2, s2;
      scanf("%d:%d:%d %d:%d:%d",&h1,&m1,&s1,&h2,&m2,&s2);
      imos[f(h1,m1,s1)]++;
      imos[f(h2,m2,s2)]--;
    }
    FOR(i,0,MAX-1) {
      imos[i+1] += imos[i];
      ans = max(ans, imos[i]);
    }
    cout << ans << endl;
  }
  return 0;
}