You have a sequence of lowercase characters that you want to encrypt.
The first characters will be encoded as plain-text. All characters after the first characters will be shifted by the most frequently occurring character that appeared in the previous characters, with ties broken by the character which occurs first in the alphabet.
By "shifted by", we mean that if c
was the most frequently occurring character, the character would be shifted ahead by positions (since c
is the third letter of the alphabet), modulo (e.g., b
becomes e
, and z
becomes c
).
Input Specification
The first line of input contains . The next line contains characters .
Output Specification
One line, containing the encrypted version of the characters from the input.
Sample Input
5
abbaabbacdecde
Output for Sample Input
abbaacdcdegdgh
Troy Vasiga
Comments
I think the sample output may be incorrect.
Take the third last character (c) and the previous 5 characters(bacde) The shift with b should be 2 instead of 1.
Therefore shouldn't d be e?
Helpful Notice
By
Mr. Vasiga means in the original, unaltered string.