This page is still under construction.

Parts of this page are still being built. What you see may change.

Digital Clock

Time limit1sMemory limit1024 MB

Summary
Given the total energy n consumed by a digital clock over a continuous on-interval within one day, count how many start times are possible.
Level

Medium6 of 10

Topics
Prefix sum, Two pointers, Brute force, Implementation
Solved
No attempts yet

Problem

Timla left home at midnight and returned home at midnight the next day, 24 hours later. A burglary had taken place in the house! The thief must have broken in at 00:00:00 or later and left the house before 24:00:00.

In the house, Timla has a digital clock that displays the time in 24-hour format with hours, minutes, and seconds. Timla likes to save electricity, so her clock turns itself off automatically when no one is home. To measure exactly how much electricity she saves, she also has a very precise electricity meter. According to this meter, the clock consumed nn units of energy during the day she was away. Each digit segment of the clock draws one unit of energy for each second that segment is lit. The digits look like the picture.

Figure 1: The digits of a digital clock. For example, 27 digit segments are lit when the clock shows 20:41:35.

Timla wants to help the police by finding out what time the thief could have broken into the house. The footprints show that the thief entered the house once and left once, so the clock cannot have been turned on and off several times. The clock's display always turns on and off at a whole second, and it can have turned on as early as 00:00:00 and can have turned off as late as after showing 23:59:59.

Input

A positive integer nn. For the given nn, there is at least one time interval during the day in which the clock consumes nn units of energy.

Output

Print a number: the number of different clock times at which the clock's display could have turned on.

Constraints

  • n≤3 000 000n \le 3\,000\,000

Hint

In the first example, the clock must have been on for exactly one second. It could have been during 11:11:17, 11:17:11, or 17:11:11.

In the second example, the only possibility is that the clock was on all day, from 00:00:00 through 23:59:59.

In the third example, there are 3196 possibilities for when the clock could have started. For example, it could have started at 20:02:06 and turned off after showing 20:02:08.

Examples3

  1. Example 1

    Input
    13
    
    Expected output
    3
    
  2. Example 2

    Input
    2401920
    
    Expected output
    1
    
  3. Example 3

    Input
    100
    
    Expected output
    3196