Easy Word
InterviewTime limit2sMemory limit1024 MB
Given a word, find the minimal complexity among its distinct cyclic shifts and how many shifts reach that minimum.
- Level
Medium4 of 10
- Topics
- String, String matching, Implementation
- Solved
- No attempts yet
Statement
Dominika Petrova flew to the USA from Ukraine to get citizenship and a better life. In America she married Gregory House and became Dominika House. At first she found it very hard to settle in the States. Her sham husband was not eager to help her, so Dominika had to study the complicated English language on her own.
As Dominika learned more and more new words, she noticed that some words were easier to learn than others. So she introduced the concept of word complexity. The complexity of a word is a number equal to the sum of two parameters: the deviation of the word from its first letter and the deviation from its last letter. The deviation of a word from letter is computed as follows: for each letter, take the absolute difference between its position in the alphabet and the position of letter , then take the maximum of these values.
Dominika also noticed that after several cyclic shifts, a word turns into itself. Now she wonders how many cyclic shifts with minimal complexity she will encounter before a shift of the string first matches the original string.
Input
The input file contains one word made of lowercase English letters. The length of the word does not exceed .
Output
Print two numbers to the output file: the minimal complexity of a cyclic shift that Dominika encounters before the string returns to itself, and the number of such shifts.