#include <bits/stdc++.h> using namespace std; typedef struct People{ string num; string open_time; string close_time; }People; vector<People> p; bool cmp_open(People p1, People p2){ return p1.open_time < p2.open_time; } bool cmp_close(People p1, People p2){ return p1.close_time > p2.close_time; } int main(){ int n; cin >> n; for (int i=0; i<n; i++){ string num; string open_time; string close_time; cin >> num >> open_time >> close_time; p.push_back({num, open_time, close_time}); } sort(p.begin(), p.end(), cmp_open); cout << p[0].num << " "; sort(p.begin(), p.end(), cmp_close); cout << p[0].num << endl; return 0; }