#P7478. Lexicographically Greater Swap

    ID: 20673 Type: Default 1000ms 256MiB

Lexicographically Greater Swap

Lexicographically Greater Swap

You are given a string \(S\) of length \(n\). Let \(S_x\) denote the \(x\)th character of \(S\). You can choose one ordered pair \((i, j)\) with \(1 \leq i < j \leq n\) and swap \(S_i\) and \(S_j\). The pair \((i,j)\) is valid if and only if the string obtained after swapping is lexicographically greater than the original string \(S\).

For two characters \(c_0\) and \(c_1\), we define \(c_0 > c_1\) if and only if the ASCII code of \(c_0\) is greater than that of \(c_1\).

For two strings \(S\) and \(T\) of length \(n\), \(S\) is considered lexicographically greater than \(T\) if and only if there exists an index \(i\) (\(0 \leq i \le n-1\)) such that \(S_j = T_j\) for every \(1 \leq j \leq i\) and \(S_{i+1} > T_{i+1}\). In our 1-indexed notation, this means the first index at which the strings differ, the character in \(S\) is greater than that in \(T\).

If there exist multiple valid pairs, you must output the largest pair. The ordering between two pairs \((i_1,j_1)\) and \((i_2,j_2)\) is defined as follows: \((i_1,j_1) < (i_2,j_2)\) if \(i_1 < i_2\) or \(i_1 = i_2\) and \(j_1 < j_2\). That is, you should choose the pair with the maximum possible \(i\), and if there is a tie, the one with the maximum possible \(j\).

If no valid pair exists, output -1.

Note: The string \(S\) only consists of lowercase English letters.

inputFormat

The input consists of a single line containing the string \(S\).

outputFormat

If a valid pair exists, output two integers \(i\) and \(j\) representing the positions to swap (1-indexed). Otherwise, output -1.

sample

ab
1 2