Alibaba and the Cave
Time: 1 s
Memory: 125 MB
Memory: 125 MB
Alibaba, a famous character, is known for his adventures. But now he is in deep debt. While wandering in search of treasure, he discovers another mysterious cave. However, this time, opening the door is far more complicated than before. In front of the cave door, there’s a strange security system. Alibaba must enter a natural number, and the door will open only if the number can be expressed as the sum of very specific numbers.
To be precise, if the natural number has \(\boldsymbol{N}\) digits, then it must be written as the sum of exactly \(\boldsymbol{N}\) non-negative numbers, where the \(\boldsymbol{i^{th}}\) number must have exactly \(\boldsymbol{'i'}\) digits. If Alibaba succeeds, the door will open. Otherwise, he remains trapped in debt and disappointment.
Check whether the number Alibaba enters can unlock the cave door.
To be precise, if the natural number has \(\boldsymbol{N}\) digits, then it must be written as the sum of exactly \(\boldsymbol{N}\) non-negative numbers, where the \(\boldsymbol{i^{th}}\) number must have exactly \(\boldsymbol{'i'}\) digits. If Alibaba succeeds, the door will open. Otherwise, he remains trapped in debt and disappointment.
Check whether the number Alibaba enters can unlock the cave door.
Input
The first line contains a single integer \(\boldsymbol{N}\) — the length of the number.The second line contains a string \(\boldsymbol{S}\) — representing the natural number of exactly \(\boldsymbol{N}\) digits (no leading zeros).
Constraint
\(\boldsymbol{2 \leq N \leq 10^5}\)
Output
Print "YES", if the door will open, otherwise print "NO".
Examples
| Input | Output |
|---|---|
|
3
231 |
YES
|
| Input | Output |
|---|---|
|
3
105 |
NO
|
| Input | Output |
|---|---|
|
4
2025 |
YES
|
Notes
- \(\boldsymbol{231}\) = 8 (1-digit) + 52 (2-digit) + 171 (3-digit) → Door opens → YES
- \(\boldsymbol{105}\) can not be expressed in the desired way → NO
- \(\boldsymbol{2025}\)= 1 (1-digit) + 24 (2-digit) + 100 (3-digit) + 1900 (4-digit) → Door opens → YES
Problem Info
| Problem ID | 477 |
| Time Limit | 1000 ms |
| Memory Limit | 128000 KB |
| Moderators | ali_hussain , muhimin , mahdi_talukder , Royboy01 |
Statistics
Submit
You need to Login or Registration for submit your solution