using System;
using System.Collections.Generic;
using System.Linq;
public class Program {
    public static void Main() {
        string input = null;
        List<int> daysInMonth = new List<int> { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
        while((input = Console.ReadLine()) != null)
        {
            string[] parts = input.Split(' ');
            int year = int.Parse(parts[0]);
            int month = int.Parse(parts[1]);
            int day = int.Parse(parts[2]);
            bool isLeapYear = DateTime.IsLeapYear(year);
            for(int i = 0; i< month - 1; i++)
            {
                day += daysInMonth[i];
            }
            if(isLeapYear && month > 2)
            {
                day += 1;
            }
            Console.WriteLine(day);
        }
    }
}