#P7478. StickSuger

StickSuger

Description

YSGH gives you a string SS of length nn. Let SxS_x denote the xx-th character of the string SS. You may choose an ordered pair (i,j)(i, j) and then swap SiS_i and SjS_j. The pair (i,j)(i, j) is valid if and only if 1i<jn1 \le i < j \le n and the string after the swap is lexicographically greater than the original string.

For two characters c0,c1c_0, c_1, we say c0>c1c_0 > c_1 if and only if the ASCII code of c0c_0 is greater than that of c1c_1.

For two strings S,TS, T of length nn, SS is lexicographically greater than TT if and only if there exists an i[0,n1]i \in [0, n - 1] such that j[1,i],Sj=Tj\forall j \in [1, i], S_j = T_j, and Si+1>Ti+1S_{i+1} > T_{i+1}.

If there are multiple valid solutions, output the largest ordered pair.

For two ordered pairs (i1,j1)(i_1, j_1) and (i2,j2)(i_2, j_2), we say (i1,j1)(i_1, j_1) is smaller than (i2,j2)(i_2, j_2) if and only if i1<i2(i1=i2j1<j2)i_1 < i_2 \lor (i_1 = i_2 \land j_1 < j_2).

If there is no valid solution, output -1.

It is guaranteed that SS contains only lowercase English letters.

Input Format

The first line contains a positive integer nn, representing the length of the string SS.

The second line contains a string SS.

Output Format

If there is no solution, output -1.

Otherwise, output two integers i,ji, j on one line, representing the largest valid ordered pair (i,j)(i, j).

3
acb
1 3
6
zyxwvu
-1
14
aabbccddccbbaa
6 8

Hint

Sample Explanation #1

If you choose the ordered pair (2,3)(2, 3), after swapping S2S_2 and S3S_3 the string becomes abc, which is lexicographically smaller than acb, so it is invalid.

If you choose the ordered pair (1,3)(1, 3), after swapping S1S_1 and S3S_3 the string becomes bca, which is lexicographically greater than acb, so it is valid.

Although (1,2)(1, 2) is also valid, it is not larger than (1,3)(1, 3). Therefore, the answer is (1,3)(1, 3).

Sample Explanation #2

It is easy to see that any ordered pair is invalid.


Constraints

This problem uses bundled testdata.

For 100%100\% of the testdata, 1n1061 \le n \le 10^6, and SS contains only lowercase English letters.

  • Subtask 1 (4 points): SS contains only one distinct character.
  • Subtask 2 (10 points): n100n \le 100.
  • Subtask 3 (16 points): n500n \le 500.
  • Subtask 4 (25 points): n5000n \le 5000.
  • Subtask 5 (18 points): n105n \le 10^5.
  • Subtask 6 (27 points): n106n \le 10^6.

Translated by ChatGPT 5