import java.util.Scanner; public class Main { public static long simulate_count(final long begin, final long end, final int init_days, final int correct){ int days = init_days; long count = 0; for(long year = begin; year < end; year++){ if(year % 400 == 0){ days += 2; }else if(year % 100 == 0){ days += 1; }else if(year % 4 == 0){ days += 2; }else{ days += 1; } days %= 7; if(days == correct){ count++; } } return count; } public static int simulate_days(final long begin, final long end, final int init_days, final int correct){ int days = init_days; for(long year = begin; year < end; year++){ if(year % 400 == 0){ days += 2; }else if(year % 100 == 0){ days += 1; }else if(year % 4 == 0){ days += 2; }else{ days += 1; } days %= 7; } return days; } public static boolean is_leap(long year){ if(year % 400 == 0){ return true; }else if(year % 100 == 0){ return false; }else if(year % 4 == 0){ return true; }else{ return false; } } public static void main(String[] args){ Scanner sc = new Scanner(System.in); final long N = sc.nextLong(); final int DAYS = 7; final int correct_days = 3; int days = 3; int[] numbered = {1, 4, 100, 400}; long[][][] counts = new long[2][numbered.length][DAYS]; int[][][] next_days = new int[2][numbered.length][DAYS]; boolean[][][] memoized = new boolean[2][numbered.length][DAYS]; for(int i = 0; i < numbered.length; i++){ for(int j = 0; j < DAYS; j++){ memoized[0][i][j] = memoized[1][i][j] = true; counts[0][i][j] = simulate_count(2100, 2100 + numbered[i], j, correct_days); counts[1][i][j] = simulate_count(2000, 2000 + numbered[i], j, correct_days); next_days[0][i][j] = simulate_days(2100, 2100 + numbered[i], j, correct_days); next_days[1][i][j] = simulate_days(2000, 2000 + numbered[i], j, correct_days); } } long answer = 0; for(long year = 2015; year <= N; ){ final boolean is_leap = is_leap(year); //System.out.println(year + " " + answer); if(year % 400 == 0 && (year + 400) <= N){ if(!memoized[is_leap ? 1 : 0][3][days]){ memoized[is_leap ? 1 : 0][3][days] = true; counts[is_leap ? 1 : 0][3][days] = simulate_count(year, year + 400, days, correct_days); next_days[is_leap ? 1 : 0][3][days] = simulate_days(year, year + 400, days, correct_days); } answer += counts[is_leap ? 1 : 0][3][days]; days = next_days[is_leap ? 1 : 0][3][days]; year += 400; }else if(year % 100 == 0 && (year + 100) <= N){ if(!memoized[is_leap ? 1 : 0][2][days]){ memoized[is_leap ? 1 : 0][2][days] = true; System.out.println(is_leap + " " + 2 + " " + year); counts[is_leap ? 1 : 0][2][days] = simulate_count(year, year + 100, days, correct_days); next_days[is_leap ? 1 : 0][2][days] = simulate_days(year, year + 100, days, correct_days); } answer += counts[is_leap ? 1 : 0][2][days]; days = next_days[is_leap ? 1 : 0][2][days]; year += 100; }else if(year % 4 == 0 && (year + 4) <= N){ if(!memoized[is_leap ? 1 : 0][1][days]){ memoized[is_leap ? 1 : 0][1][days] = true; counts[is_leap ? 1 : 0][1][days] = simulate_count(year, year + 4, days, correct_days); next_days[is_leap ? 1 : 0][1][days] = simulate_days(year, year + 4, days, correct_days); } answer += counts[is_leap ? 1 : 0][1][days]; days = next_days[is_leap ? 1 : 0][1][days]; year += 4; }else{ if(!memoized[is_leap ? 1 : 0][0][days]){ memoized[is_leap ? 1 : 0][0][days] = true; counts[is_leap ? 1 : 0][0][days] = simulate_count(year, year + 1, days, correct_days); next_days[is_leap ? 1 : 0][0][days] = simulate_days(year, year + 1, days, correct_days); } answer += counts[is_leap ? 1 : 0][0][days]; days = next_days[is_leap ? 1 : 0][0][days]; year += 1; } } System.out.println(answer); } }