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;
int k[2][10000], p[10000], n, T[3] = { 3600,60,1 }, MAX, s;
string S;
int main() {
	while (true) {
		MAX = 0;
		memset(k, 0, sizeof(k));
		cin >> n;
		if (n == 0) { break; }
		for (int i = 0; i < n; i++) {
			for (int h = 0; h < 2; h++) {
				cin >> S;
				for (int j = 0; j < 3; j++) {
					k[h][i] += T[j] * stoi(S.substr(3 * j, 2));
				}
			}
		}
		sort(k[1], k[1] + n);
		sort(k[0], k[0] + n);
		for (int i = 0; i < 2; i++) {
			for (int j = 0; j < n; j++) {
				s = 0;
				for (int l = j; l < n; l++) {
					if ((k[i][l] - k[i][j]) < 3600) {
						s++;
					}
					else {
						goto E;
					}
				}
			E:; MAX = max(s, MAX);
			}
		}
		cout << MAX << endl;
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define RFOR(i,m,n) for(int i=m;i>=n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265

int g(string s){

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

  return (h+m+t);
}

void f(int n){
  vector<int> v;
  int ans = 1;
  string s,t;
  cin>>s>>t;

  v.push_back(g(t));
  rep(i,n-1){
    cin>>s>>t;
    int a = g(s);
    int b = g(t);
    int j=0;
    while(j<v.size()){
      if(a>=v[j]){
        v[j] = b;
        break;
      }
      j++;
    }
    if(j==v.size()){
      v.push_back(b);
      ans++;
  }
    sort(v.begin(),v.end());
  }

  cout<<ans<<endl;
}


int main(){
  while(1){
    int n;
    cin>>n;
    if(n==0) break;
    f(n);
  }

  return 0;
}

C++: #include<iostream>
#include<list>
#include<vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<math.h>
#include<unordered_map>

using namespace std;
using vec = vector<int>;
using mat = vector<vec>;
using lst = list<int>;


class Event
{
public:
	int add;
	string time;

	Event(int a)
	{
		add = a;
		cin >> time;
	}

	bool operator<(const Event & a)const
	{
		if (time == a.time)return add < a.add;
		return time < a.time;
	}
};


bool solve()
{
	int n; cin >> n;
	if (n == 0)return false;

	list<Event> eLst;

	for (int i = 0; i < n; ++i)
	{
		eLst.emplace_back(1);
		eLst.emplace_back(-1);
	}
	eLst.sort();

	int ans = 0, num = 0;
	while (!eLst.empty())
	{
		num += eLst.front().add;
		ans = max(ans, num);
		eLst.pop_front();
	}

	cout << ans << endl;

	return true;
}


int main()
{
	while (solve());

	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+1;i<times.size();i++){
    if(times[i].first < last){
	dfs(i,times[i].first,times[i].last,times,count+1);
    }
    else{
      return;
    }
  }
}

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

     gRes = 1;
     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,1);
     
     // 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);
   }
}

C++: #include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<S<<endl
using namespace std;

int main(){
	int N;
	while(cin>>N,N){
		int h,m,s,jikoku,sum=0,maxi=0;
		int imos[250000]={0};
		REP(i,0,N){
			scanf("%2d:%2d:%2d",&h,&m,&s);
			jikoku=h*10000+m*100+s;
			imos[jikoku+1]++;
			scanf("%2d:%2d:%2d",&h,&m,&s);
			jikoku=h*10000+m*100+s;
			imos[jikoku+1]--;
		}

		REP(i,0,250000){
			sum+=imos[i];
			maxi=max(maxi,sum);
		}

		p(maxi);
	}

	return 0;
}