Letters and Scales
InterviewTime limit2sMemory limit1024 MB
Given n scales and a word s, find the minimum number of cubes needed to show s on the scales in a row, or report Impossible.
- Level
Easy1 of 10
- Topics
- Implementation
- Solved
- No attempts yet
Problem
Little Petya received an unusual New Year present: a set of scales and cubes. These scales do not show weight. Instead, they show letters. An empty scale shows nothing, one cube shows , two cubes show , and 26 cubes show . If more than 26 cubes are put on a scale, it breaks.
Petya played with the cubes and scales for a long time. He broke some scales and lost some cubes. He now has scales in total. Petya wants the scales, placed in a row, to show the word , but he does not know whether that is possible. Help him. Write a program that, given and the word , finds the minimum number of cubes needed to show , or reports that it is impossible.
Input
The first line contains one integer (). The second line contains the word , consisting of lowercase Latin letters. The length of does not exceed 100.
Output
If the word cannot be written, print the single word Impossible. Otherwise, print one integer: the minimum number of cubes needed to write with the scales and cubes.