import Control.Monad
import Data.Array
import Data.List
import Data.Maybe

main = interact $ put . sol

sol :: String -> Maybe (Int, Int)
sol s = fst <$> find unballance
  [((j,i),c) | i <- [2..length s], c <- ['a'..'z'], h!(i,c)>1, j <- [i-1,i-2..1]]
  where
  a = listArray (1,length s) s
  bnds = ((0,'a'),(length s,'z'))
  h = array bnds $ [((0,c), 0) | c <- ['a'..'z']] ++
    [((i,c), h!(i-1,c) + if c==a!i then 1 else 0)
    | i <- indices a, c <- ['a'..'z']] :: Array (Int, Char) Int
  unballance ((j,i),c) = 2*(h!(i,c) - h!(j,c)) > i-j+1

put = (\(s,t) -> show s ++ show t) . fromMaybe (-1,-1)
