#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
struct Person
{
string name;
string BirthInfo;
};
bool CheckValid(const Person& per)
{
return (per.BirthInfo <= "2014/09/06"
&& per.BirthInfo >= "1814/09/06");
}
bool Older(const Person& per1, const Person& per2)
{
if (per1.BirthInfo > per2.BirthInfo)
return false;
else
return true;
}
int main(void)
{
int numbers=0;
cin >> numbers;
string name, birthInfo;
Person person;
vector<Person> person_list;
for (int idx = 0; idx < numbers;++idx)
{
cin >> person.name >> person.BirthInfo;
if (CheckValid(person))
person_list.push_back(person);
}
sort(person_list.begin(), person_list.end(), Older);
cout << person_list.size() << " "
<< person_list.front().name << " " <<
person_list.back().name;
//system("pause");
return 0;
}