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 <vector>
#include <cstdio>
#include <algorithm>
using namespace std;

int main(){
    vector< vector<int> > trains;
    vector<int> buf(86401,0);
    int n,h,m,s,bf,bt,i,j,add_f;
    while(1){
        scanf("%d",&n);
        if(!n){break;}
        for(i=0;i<n;i++){
            scanf("%d:%d:%d",&h,&m,&s);
            bf=h*3600+m*60+s;
            scanf("%d:%d:%d",&h,&m,&s);
            bt=h*3600+m*60+s;
            auto bs=buf.begin();
            if(trains.empty()){
                fill(bs+bf,bs+bt,1);
                trains.push_back(buf);
                fill(bs+bf,bs+bt,0);
            }
            else{
                add_f=1;
                for(auto it=trains.begin();it!=trains.end();it++){
                    auto p=(*it).begin();
                    int fn=count(p+bf,p+bt,1);
                    if(fn==0 || (*(p+bf)==1 && *(p+bt)==1 && fn==2)){
                        fill(p+bf,p+bt,1);
                        add_f=0;
                        break;
                    }
                }
                if(add_f){
                    fill(bs+bf,bs+bt,1);
                    trains.push_back(buf);
                    fill(bs+bf,bs+bt,0);
                }
            }
        }
        printf("%lu\n",trains.size());
        trains.clear();
        trains.shrink_to_fit();
    }
    return 0;
}

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

typedef pair<int,int> pii;

int main()
{
  int n,h,m,s;
  for(;;){
    cin>>n;
    if(!n) break;
    vector<pii> time;
    for(int i=0;i<n;i++){
      scanf("%d:%d:%d", &h, &m, &s);
      time.push_back(pii(h*10000+m*100+s,1));
      scanf("%d:%d:%d", &h, &m, &s);
      time.push_back(pii(h*10000+m*100+s,-1));
    }
    sort(time.begin(),time.end());
    int ans=0,res=0;
    for(int i=0;i<time.size();i++){
      res+=time[i].second;
      ans=max(ans,res);
    }
    cout<<ans<<endl;
  }
}

C++: #include <cstdio>
#include <vector>
using namespace std;
struct time{
    int h;
    int m;
    int s;
    int operator-(const time& r) const{
        return(h*3600+m*60+s-r.h*3600-r.m*60-r.s);
    }
};
struct times{
    struct time f;
    struct time t;
};
vector<vector<times>> t;
vector<times> buf;

int main(){
    int i,n;
    struct time ft,tt;
    struct times tms;
    while(1){
        scanf("%d",&n);
        if(!n){break;}
        for(i=0;i<n;i++){
            scanf("%d:%d:%d",&ft.h,&ft.m,&ft.s);
            scanf("%d:%d:%d",&tt.h,&tt.m,&tt.s);
            tms={ft,tt};
            int af;
            if(t.empty()){
                buf.push_back(tms);
                t.push_back(buf);
                buf.clear();
                buf.shrink_to_fit();
            }
            else{
                for(auto j=t.begin();j!=t.end();j++){
                    af=1;
                    for(auto k=(*j).begin();k!=(*j).end();k++){
                        if((tms.f - k->f >=0 && k->t - tms.f>0) || (tms.t - k->f > 0 && k->t - tms.t>=0) || (k->f - tms.f>=0 && tms.t - k->t >=0)){
                            af=0;
                            break;
                        }
                    }
                    if(af){
                        (*j).push_back(tms);
                        break;
                    }
                }
                if(!af){
                    buf.push_back(tms);
                    t.push_back(buf);
                    buf.clear();
                    buf.shrink_to_fit();
                }
            }
        }
        printf("%lu\n",t.size());
        t.clear();
        t.shrink_to_fit();
    }
    return 0;
}