Alarm Clock
InterviewTime limit2sMemory limit256 MB
Print the earliest hh:mm time whose four digits use exactly n lit segments, or Impossible when no such time exists.
- Level
Easy2 of 10
- Topics
- Brute force, Implementation
- Solved
- No attempts yet
Problem
Alice likes her digital alarm clock and sets it every evening. Last night she dreamed about the clock. The only thing she remembers is how many segments were lit. Alice wants to know what time the clock showed in her dream.
The clock displays four digits. The first two are the hour and the last two are the minute, and a single digit value gets a leading zero. For example, half past nine reads 09:30.
Each digit is drawn with seven segments. The number of lit segments per digit is:
The colon between the hour and the minute does not count toward the number of lit segments.
Input
The first line contains the number of lit segments that Alice saw in her dream. ()
Output
Print a time whose four digits use exactly lit segments, as five characters in "hh:mm" format. The time must satisfy and .
If several times satisfy the condition, print the earliest one, that is, the smallest "hh:mm" string in lexicographic order. If no time satisfies the condition, print Impossible.