Problem B
Morse Numbers
Morse code was used in the 1800s to send telegraph messages. While Morse code can be used to send messages with both letters and digits, we will focus on sending messages that are numbers (sequences of digits, with spaces between numbers).
Each decimal digit in Morse code is encoded into a sequence of dits and dashes. Each dit is a sound that takes $1$ unit of time to send, and each dash is a sound that takes $3$ units. Between consecutive symbols (dits or dashes) from the same digit, there is $1$ unit of silence. Also, there is a silence lasting $3$ units between two digits in the same number. The space between two numbers is represented by $7$ units of silence.
Given a message that is a sequence of numbers, your job is to determine the total number of time units to transmit that message.
The Morse code for digits is as follows:
digit |
Morse code sequence |
0 |
dash dash dash dash dash |
1 |
dit dash dash dash dash |
2 |
dit dit dash dash dash |
3 |
dit dit dit dash dash |
4 |
dit dit dit dit dash |
5 |
dit dit dit dit dit |
6 |
dash dit dit dit dit |
7 |
dash dash dit dit dit |
8 |
dash dash dash dit dit |
9 |
dash dash dash dash dit |
Input
The input is two lines. The first has a single positive integer, $N$, between $1$ and $20$, inclusive. It represents the number of integers making up the message. The second line holds the message. It consists of $N$ integers between $0$ and $999\, 999\, 999$, inclusive. A single space separates each integer in the message. There is only one integer (zero) that starts with a leading $0$.
Output
The output is a positive number, representing the number of time units to transmit the message.
Sample Input 1 | Sample Output 1 |
---|---|
1 5 |
9 |
Sample Input 2 | Sample Output 2 |
---|---|
3 2022 4 28 |
131 |