while True:
    try:
        y,m,d = map(int,input().split()) #用map函数的int,给他全部捋成整数。
        month = [31, 28, 31, 30, 31, 30, 31, 31,30, 31, 30, 31]  #平年月份的天数
        if y %400 ==0 or (y%100 != 0 and y%4==0): #闰年的判断,①世纪年被400整除②不能被100整除,但是能被4整除。
            month[1] = 29 #将闰年的2月修改一下。
        print(sum(month[:m-1])+d) #截止上个月的切片,加上本月的日
    except:
        break