The Mysty Lock
Time Limit: 2.0 s
Memory Limit: 256.0 MB
Description
In the year 2057, the renowned programming platform SeriousOj has taken innovation to the next level. Their cutting‐edge office, shrouded in mystery and advanced security systems, is secured by a high-tech digital lock. The lock's password is a legendary string – "SERIOUSOJ". Only those who can transform an arbitrary string into this exact password at minimum cost can unlock the door and gain access to the secretive hub of SeriousOj’s masterminds.
Your goal is to transform S into the string "SERIOUSOJ" using the following operations (which may be performed in any order and arbitrarily many times):
- Rearrange: You may rearrange (i.e. permute) the characters of S at no cost.
- Erase: You may erase any characters from S at no cost.
- Cyclic Shift: For a cost of 1 unit, you can change a character to its next or previous letter in the cyclic order of the alphabet. In other words, for any character C:
- Shifting right changes C to the next letter (with 'Z' shifting to 'A').
- Shifting left changes C to the previous letter (with 'A' shifting to 'Z').
Determine the minimum total cost needed to obtain the string "SERIOUSOJ".
If you can achieve this transformation with minimum cost, the futuristic lock will recognize your brilliance and grant you entry into the mysterious world of SeriousOj.
Input
- The first line contains an integer T(1 <= T <= 20), the number of test cases.
- Each of the next T lines contains a string S consisting of uppercase English letters (9 <= |S| <= 200,000).
Output
For each test case, output a single integer—the minimum cost to transform S into "SERIOUSOJ".
Sample
Input | Output |
---|---|
|
|
Information
- ID
- 1188
- Difficulty
- 7
- Category
- (None)
- Tags
- # Submissions
- 20
- Accepted
- 7
- Accepted Ratio
- 35%
- Uploaded By
Related
In following contests: