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 <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

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

void solve(int N) {
    const int sz = (60 * 60 * 24 + 1) * 2; 
    VI v(sz, 0);
    REP(i, N) {
        string s; cin >> s;
        int st = 0;
        st += f(s[0]) * 10 + f(s[1]);
        st *= 60 * 60;
        st += (f(s[3]) * 10 + f(s[4])) * 60;
        st += f(s[6]) * 10 + f(s[7]);
        cin >> s;
        int ed = 0;
        ed += f(s[0]) * 10 + f(s[1]);
        ed *= 60 * 60;
        ed += (f(s[3]) * 10 + f(s[4])) * 60;
        ed += f(s[6]) * 10 + f(s[7]);
        v[st]++;
        v[ed]--;
    }
    REP(i, sz - 1) {
        v[i + 1] += v[i];
    }
    int ans = 0;
    REP(i, sz) {
        ans = max(ans, v[i]);
    }
    cout << ans << endl;
    return;
}

signed main(void) {
    int n, m, p, a, b, c, x, y, z, q;
    string s;
    bool f = false;
    while (cin >> n, n) {
        solve(n);
        //return 0;
    }
}

C++: #include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)

int n;
int imos[86400];

void solve() {
    rep(i, n) {
        int s[3];
        int t[3];
        scanf("%d:%d:%d", &s[0], &s[1], &s[2]);
        scanf("%d:%d:%d", &t[0], &t[1], &t[2]);

        // hh:mm:ss を 秒に変換
        int S = s[2] + 60 * (s[1] + s[0] * 60);
        int T = t[2] + 60 * (t[1] + t[0] * 60);
        
        // 入る時間に +1
        imos[S]++;

        // 出る時間に -1
        imos[T]--;

        // ナイーブな実装 (写経しなくて良い)
        // for(int j = S; j <= T; j++) imos[j]++;
    }

    // 累積和を計算する
    rep(i, 86400) if(i) imos[i] += imos[i-1];

    int ans = 0;
    rep(i, 86400) ans = max(ans, imos[i]);

    cout << ans << endl;
}

int main() {
    // こう書くとn==0のときにwhileループが停止する
    while(cin >> n, n) {
        rep(i, 86400) imos[i] = 0;
        solve();
    }
}

C++: #include <cstdio>

#define int long long
#define macrocat_impl(a, b) a##b
#define macrocat(a, b) macrocat_impl(a, b)
#define dotimes_impl(i, n, x) for (int i = 0, x = n; i < x; i++)
#define dotimes(i, n) dotimes_impl(i, (n), macrocat(dotimes_n_, __COUNTER__))

using namespace std;

int rint() {
  int n;
  scanf("%lld", &n);
  return n;
}

void wint(int n) {
  printf("%lld\n", n);
}

template<typename T>
inline int size(T container) {
  return static_cast<int>(container.size());
}

signed main() {
  for (;;) {
    int n = rint();
    if (n == 0)
      break;
    const int s_max = 60 * 60 * 24;
    int a[s_max] = {};
    dotimes(i, n) {
      int h, m, s;
      scanf("%lld:%lld:%lld", &h, &m, &s);
      a[s + 60 * (m + 60 * h)]++;
      scanf("%lld:%lld:%lld", &h, &m, &s);
      a[s + 60 * (m + 60 * h)]--;
    }
    int r = a[0];
    dotimes(s, s_max - 1) {
      a[s+1] += a[s];
      if (r < a[s+1])
        r = a[s+1];
    }
    wint(r);
  }
  return 0;
}