1 #include <iostream>
2 #include <cstdio>
3 #include <cstring>
4 #include <algorithm>
5
6 using namespace std;
7 struct oi{
8 string name;
9 int h1, m1, j1;
10 int h2, m2, j2;
11 };
12 int bijiao1(oi x, oi y)
13 {
14 if (x.h1!=y.h1)
15 return x.h1<y.h1;
16 else if (x.m1!=y.m1)
17 return x.m1<y.m1;
18 else if (x.j1!=y.j1)
19 return x.j1<y.j1;
20 }
21 int bijiao2(oi x, oi y)
22 {
23 if (x.h2!=y.h2)
24 return x.h2>y.h2;
25 else if (x.m2!=y.m2)
26 return x.m2>y.m2;
27 else if (x.j2!=y.j2)
28 return x.j2>y.j2;
29 }
30 int main()
31 {
32 int n;
33 cin >>n;
34 struct oi ioo[100];
35 for (int i=0; i<n; i++)
36 {
37 cin >>ioo[i].name;
38 scanf ("%2d:%2d:%2d", &ioo[i].h1, &ioo[i].m1, &ioo[i].j1);
39 scanf ("%2d:%2d:%2d", &ioo[i].h2, &ioo[i].m2, &ioo[i].j2);
40 }
41 sort (ioo, ioo+n, bijiao1);
42 cout <<ioo[0].name <<' ';
43 sort (ioo, ioo+n, bijiao2);
44 cout <<ioo[0].name;
45 }