year,moth,day=map(int,input().split())
n=False
if year%4==0 and (year%100!=0) or year%400==0:n=True
if (moth==2 and n==True and day==29) or (moth==2 and n==False and day==28):
day=1
moth+=1
elif moth==12 and day==31:
day=1
moth=1
year+=1
elif (moth==1 or moth==3 or moth==5 or moth==7 or moth==8 or moth==10)and day==31:
day=1
moth+=1
elif (moth==4 or moth==6 or moth==9 or moth==11 )and day==30:
day=1
moth+=1
else:
day+=1
print(year,moth,day)