#include <iostream>
#include <bits/stdc++.h>
using namespace std;
struct Node
{
string name;
int sum;
Node(string a,int b):name(a),sum(b){}
};
vector<Node>nodes;
//去除前导零
int get(string s)
{
int i = 0;
while(s[i]=='0')
{
i++;
}
int sum = 0;
for(i;i<s.size();i++)
{
sum = sum*10 + s[i]-'0';
}
return sum;
}
void solve(string s,int & y,int & m,int & d)
{
int pos1 = s.find("/");
int pos2 = s.rfind("/");
y = get(s.substr(0,pos1));
m = get(s.substr(pos1+1,pos2-pos1-1));
d = get(s.substr(pos2+1,s.size()-pos2-1));
}
int main()
{
int n;
int y,m,d;
string name,date;
cin>>n;
int ans = 0;
double minnum = 250;
double maxNum = -1;
string minName = "-1",maxName = "-1";
for(int i = 0;i<n;i++)
{
cin>>name>>date;
solve(date,y,m,d);
double tmp= (2014-y)*1.0+(9-m)*0.01+(6-d)*0.0001;
if(tmp<=200 && tmp>=0)
{
ans++;
if(minnum>tmp)
{
minnum = tmp;
minName = name;
}
if(maxNum<tmp)
{
maxNum = tmp;
maxName = name;
}
}
}
cout<<ans;
if(maxName!="-1")
cout<<" "<<maxName;
if(minName!="-1")
cout<<" "<<minName;
cout<<endl;
return 0;
}
/**
5
John 2001/05/12
Tom 1814/09/06
Ann 2121/01/30
James 1814/09/05
Steve 1967/11/20
2014 年 9 月 6 日 200
**/