This page is still under construction.

Parts of this page are still being built. What you see may change.

SKK String

Time limit1sMemory limit1024 MB

Summary
Find the longest substring where the count of K equals twice the count of S, with both letters present, or report -1.
Level

Medium6 of 10

Topics
Prefix sum, Hash map, String, Array
Solved
No attempts yet

Problem

A string is called an SKK string if the number of K's it contains is exactly 22 times the number of S's, and both S and K appear at least once.

An SKK string may contain letters other than S and K.

Given a string SS consisting only of uppercase letters, write a program that finds the longest SKK string among the substrings of SS.

Input

The first line gives a string SS consisting only of uppercase letters, with length between 11 and 100,000100,000.

Output

Print the length of the longest SKK string among the substrings of SS. If no such string exists, print -1.

Hint

A new string formed by selecting consecutive characters from a string SS is called a substring of SS.

For example, "appl", "ap", and "ple" are substrings of "apple", while "ppe" and "apl" are not substrings of "apple".

Examples3

  1. Example 1

    Input
    HELLOWORLD
    
    Expected output
    -1
    
  2. Example 2

    Input
    LUKESKYWALKER
    
    Expected output
    10
    
  3. Example 3

    Input
    SUNGKYUNKWAN
    
    Expected output
    12