Favourite Times

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.

Medium4MathSimulationImplementationBrute forceNo attempts yetTime limit1sMemory limit512 MB

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 (0D1090 \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.