Under construction

Still being built. Things may change

Favourite Times

Time limit1sMemory limit512 MB

Summary
Count how many times in D minutes a 12-hour clock shows a time whose digits form an arithmetic sequence, starting at 12:00 inclusive.
Level

Medium4 of 10

Topics
Math, Simulation, Implementation, Brute force
Solved
No attempts yet

Problem

Wendy has an LED clock radio with a 12-hour display, showing times from 12:00 to 11:59. The hour carries no leading zero, but the minutes may carry one, as in 2:07 or 11:03.

When Wendy looks at the clock, she likes to spot times whose digits form an arithmetic sequence. Two of her favourite times are 12:34 and 2:46, because their digits form such a sequence.

A sequence of digits is an arithmetic sequence when every digit after the first equals the previous digit plus one fixed common difference. The sequence 1, 2, 3, 4 has common difference 1, and 2, 4, 6 has common difference 2.

Wendy starts watching at noon, the moment the clock reads 12:00, and watches it for DD minutes. How many times during that period does the clock display a time whose digits form an arithmetic sequence?

Input

The input contains one integer DD, the number of minutes the clock is watched (0≤D≤1090 \le D \le 10^9).

Output

Print how many times a qualifying time is displayed, counting from 12:00 up to the moment DD minutes later and including that final moment. Each displayed minute counts once, so a time that comes around again 12 hours later is counted again.

Explanation

In the three hours after noon the qualifying times are 12:34 (common difference 1), 1:11 (common difference 0), 1:23 (common difference 1), 1:35 (common difference 2), 1:47 (common difference 3), 1:59 (common difference 4), 2:10 (common difference -1), 2:22 (common difference 0), 2:34 (common difference 1), 2:46 (common difference 2) and 2:58 (common difference 3), eleven in all.

Examples2

  1. Example 1

    Input
    34
    
    Expected output
    1
    
  2. Example 2

    Input
    180
    
    Expected output
    11