c=input().split()
md=[0,31,28,31,30,31,30,31,31,30,31,30,31]
y=int(c[0])
m=int(c[1])
d=int(c[2])
if d!=md[m]: print(y,m,d+1)
else:
if (y%4==0 and y%100!=0 or y%400==0) and m==2:
d=d+1
else:
d=1
m=m+1
if m==13:
m=1
y=y+1
print(y,m,d)