import sys
months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

def is_leap_year(year):
    return year % 400 == 0 or (year % 100 != 0 and year % 4 == 0)

for line in sys.stdin:
    year, month, day = [int(x) for x in line.split()]
    if is_leap_year(year):
        months[1] = 29
    else:
        months[1] = 28
    print(sum(months[:month - 1]) + day)