#include <iostream>
#include <fstream>
#include <algorithm>
#include <tuple>
using namespace std;
int main() {
ifstream file("dates.txt");
int a, b, c, year, month, day;
tuple<int, int, int> dates[1000];
for(int i = 0; i < 1000; i++) {
file >> a >> b >> c;
year = max(a, max(b, c));
month = min(a, min(b, c));
day = a + b + c - year - month;
dates[i] = make_tuple(year, month, day);
}
file.close();
sort(dates, dates + 1000);
cout << "Najstarsza: " << get<0>(dates[0]) << " " << get<1>(dates[0]) << " " << get<2>(dates[0]) << endl;
cout << "Najmlodsza: " << get<0>(dates[999]) << " " << get<1>(dates[999]) << " " << get<2>(dates[999]) << endl;
return 0;
}