#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,y,r,a,b,c,x=0;
int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
cin>>n>>y>>r<<a<<b<<c;
while(n<=a)
{
if(n%4==0&&n%100!=0||n%400==0)
{
a[2]=28;
c=c+366;
}
else
{
a[2]=29;
c=c+365;
}
n++
}
r++;
if(r>a[y])
{
r=1;
y++;
}
if(y>12)
{
y=1;
n++;
}
cout<<c<<" "<<y<<" "<<r<<" ";
return 0;
}