We are given a string s of length n (2 ≤ n ≤ 300k). We need to choose exactly one substring (contiguous, l<r) and reverse it. After reversal, the new string should be lexicographically less than the original string. If possible, output "YES" and any (l,r). If not possible, output "NO".
We need to check if there exists a substring such that reversing it yields a lexicographically smaller string. Equivalent: is there some operation that makes the string strictly smaller lexicographically? If not, then answer is NO.
Observation: If the string is already not sorted non-decreasingly? Let's think.
Lexicographic order: compare from first character. Suppose we reverse substring [l,r]. The prefix before l remains same. At position l, originally we have s[l]; after reversal, we have s[r] (the last character of substring becomes first). So the first position where the new string may differ from original is at l (since before l unchanged). For the new string to be lexicographically smaller, we need at position l: s[r] < s[l]. Because if s[r] > s[l], then new string is larger. If s[r] = s[l], then we need to check further. However after reversal, the substring is reversed, and the rest after r is unchanged. So we need to compare the two strings after l.
Let’s denote original: O = s[1..n]; new: N = s[1..l-1] + reverse(s[l..r]) + s[r+1..n].
Comparison: find first index i where O[i] != N[i]; i must be >= l. For i = l, if s[r] != s[l], then that's the first difference. If s[r] < s[l], N < O; if > then N > O. If s[r] == s[l], then we need to compare further within the substring. At position l+1, N[l+1] = s[r-1], O[l+1] = s[l+1]. So we compare s[r-1] vs s[l+1]. In general, for k from 0 to r-l, N[l+k] = s[r - k], O[l+k] = s[l+k]. So the first difference occurs at the smallest k where s[r-k] != s[l+k]. If for that k, s[r-k] < s[l+k], then N < O; else N > O.
Thus condition for N < O: the reversed substring must cause a lexicographically smaller comparison.
Goal: find any l<r such that when we compare s[l..r] (forward) with its reverse (i.e., s[r], s[r-1], ..., s[l]) lexicographically, the reverse is less than the original segment? Actually careful: The whole string comparison will be determined by the first difference between the original and new string. Since prefixes before l are same, and after r also same, the first difference is at the first index i in [l, r] where N[i] != O[i]. That difference is as described. So we need existence of l,r such that the reversed substring is lexicographically smaller when compared at that first mismatch.
Alternatively, think of it as: If the string is not already sorted in non-decreasing order (i.e., there exists a pair i<j with s[i] > s[j]), then we might be able to reverse a substring that includes i and j? For instance, if we take l=i, r=j, then at position l, N[l] = s[j] which is < s[i] (since s[i] > s[j]), so the resulting string is lexicographically smaller. So that gives a trivial solution: if there exists any i<j such that s[i] > s[j], then choose l=i, r=j, the new string is smaller. Wait, careful: If we reverse exactly substring [i,j], then at first index i, we have s[j] which is less than s[i] (since s[i] > s[j]), so N < O. So that works. So if the string is not non-decreasing, we can just output the first index where we see a descent? Actually we need a pair with s[i] > s[i+1]? That's descent but not necessarily needed; any i<j with s[i] > s[j] works. But if there is a descent at i (s[i] > s[i+1]), then choose l=i, r=i+1 works. So essentially, if the string is not already sorted in non-decreasing order (i.e., there exists a decreasing adjacent pair), then answer is YES with that adjacent pair.
But is that always? Let's test: s = "abacaba". There is a descent? At index 2? s[2] = 'b', s[3] = 'a' -> b > a, so l=2,r=3 would produce: reverse "ba" -> "ab", string becomes "aabacaba"? Actually original: a b a c a b a -> after reversing positions 2-3: a a b c a b a = "aabcaba"? Wait compute: original: indices 1 a,2 b,3 a,4 c,5 a,6 b,7 a. Reverse [2,3]: becomes a, a, b, c, a, b, a => "aabcaba". Compare to original "abacaba": at index1 both a; index2 new has 'a' vs original 'b'; since 'a' < 'b', new is smaller. So yes that works. But the sample output shows 2 5; they reversed longer substring. So any descent works. But what if there is no descent? That is, the string is strictly non-decreasing? Actually "non-decreasing" means s[i] <= s[i+1] for all i. So if the string is sorted in non-decreasing order, then for any i<j we have s[i] <= s[j]. In that case, for any substring reversal, at first difference we have s[r] <= s[l]? Actually since s[l] <= s[r], if s[l] < s[r], then s[r] > s[l], so new string would be larger. If s[l] = s[r], then we need to look inside: s[l+1] <= s[r-1]? It becomes more complex. But in a non-decreasing string, it might still be possible to get a lexicographically smaller string by reversing a longer substring? Let's examine.
Consider s = "aa". n=2, s[1]=a, s[2]=a. Reverse [1,2] yields "aa", same. So no smaller. Output NO? According to problem, need exactly one substring to reverse to get lexicographically less. It's impossible. So NO.
Consider s = "ab". s is non-decreasing? a <= b. Any reversal? Only substring [1,2] yields "ba". At index1 new has 'b' > 'a', so larger. So NO.
Consider s = "aab". s: a a b. Is there any substring that makes it smaller? Check [1,2] -> reverse "aa" -> still "aab". No change. [2,3] -> reverse "ab" -> "aba": original a a b, new a b a. Compare: index1 a vs a; index2 new b vs original a -> b > a, so larger. [1,3] -> reverse "aab" -> "baa": index1 new b > a -> larger. So NO.
Consider s = "abb". [2,3] reverse "bb" -> no change. [1,2] reverse "ab" -> "bab": index1 b > a -> larger. [1,3] reverse "abb" -> "bba": index1 b > a -> larger. So NO.
Consider s = "acb"? That's not non-decreasing because c > b? Actually a <= c? a<c? But at index2 c, index3 b: c > b => descent exists. So YES (l=2,r=3). So we already have solution.
Consider s = "abca". Let's see: string: a b c a. This is not non-decreasing because at index3 c > a, so descent exists: l=3,r=4 works (c > a). So YES.
Now, what about a string that is non-decreasing but has some equalities? Suppose s = "aaaab". That's non-decreasing. Check any reversal? Since all characters before last are 'a' and last is 'b'. Any reversal that includes the 'b' and some 'a's? For example l=1,r=5: reverse whole => "baaaa": at index1 new 'b' > original 'a' -> larger. l=4,r=5: reverse "ab" => "aaaba"? Actually indices 4='a',5='b' -> reverse -> "ba", so string becomes a a b a a? Wait original: 1 a,2 a,3 a,4 a,5 b -> after reversing [4,5]: 1 a,2 a,3 a,4 b,5 a -> "aabaa". Compare with original "aaaab": index1 a vs a; index2 a vs a; index3 a vs a; index4 new b vs original a -> b > a -> larger. l=3,5: reverse "aab" => "baa", string: a a b a a? Actually original: a a a a b; reverse [3,5] (positions 3-5: a,a,b) -> reversed: b,a,a. So new string: indices1 a,2 a,3 b,4 a,5 a -> "aabaa". Same as above: larger. l=2,5: reverse "aaab" => "baaa": new: a b a a a? Wait: indices2-5: a,a,a,b reversed: b,a,a,a -> string: a,b,a,a,a => "abaaa". Compare: index1 a vs a; index2 new b > original a -> larger. l=1,4: reverse "aaaa" -> no change. So all produce larger or equal. So NO.
Now, what about a string that is non-decreasing but maybe if we reverse a substring that includes equal ends and internal structure yields a smaller? Since the string is non-decreasing, the first character of the substring s[l] is <= s[r]. If s[l] < s[r], then at first difference (if any) we get s[r] > s[l], so new > original. So that can't yield smaller. If s[l] == s[r], then we need to look at next positions. For the new string to be smaller, we need at some k, s[r-k] < s[l+k] while all previous equal. But note that since the string is non-decreasing, for indices within [l, r], we have s[l] <= s[l+1] <= ... <= s[r]. Also for reversed part, the sequence s[r], s[r-1], ..., s[l] is non-increasing. So comparing forward vs reverse: At step 0, s[r] vs s[l]: equal if s[l]==s[r]. Then step1: s[r-1] vs s[l+1]. Since s[l+1] >= s[l] and s[r-1] <= s[r] because of non-decreasing, but we have s[l]==s[r]. Actually we know s[l+1] >= s[l] and s[r-1] <= s[r] = s[l]. So s[r-1] <= s[l] and s[l+1] >= s[l]. So it's possible that s[r-1] < s[l+1] (if s[r-1] is less than s[l] or s[l+1] greater). That would cause new string to be smaller? Let's examine: if at first k where s[r-k] != s[l+k], we have s[r-k] < s[l+k], then new < original. So we need existence of such k. However, can that happen in a non-decreasing sequence? Since s[l+k] is >= s[l] and s[r-k] is <= s[r] = s[l], it is possible that s[r-k] < s[l+k] if s[l+k] > s[l] or s[r-k] < s[l]. But is there any guarantee that if such a k exists then the string is not non-decreasing? Wait, the whole string is non-decreasing. So consider the segment [l,r]. Because it's non-decreasing, we have s[i] <= s[j] for i<j. So for any k, l+k <= r-k? Actually we need k such that l+k <= r-k (so we are comparing symmetric positions). Typically we compare until the middle. For the first mismatch, if we find a position where the reversed character is less than the forward character, that would mean s[r-k] < s[l+k]. Since indices: l+k < r-k? Not necessarily; if length is even, the comparisons go until we cross. But for there to be a mismatch with s[r-k] < s[l+k], note that since l+k < r-k (if length > 1 and k less than half), we have s[l+k] <= s[r-k] by the non-decreasing property (since l+k < r-k). Actually careful: The non-decreasing property says for indices i<j, s[i] <= s[j]. Here l+k and r-k: since l+k < r-k (because k < (r-l+1)/2), we have s[l+k] <= s[r-k]. So s[l+k] <= s[r-k]. That is the opposite inequality. So in a non-decreasing segment, we have s[l+k] <= s[r-k] for all such k. Therefore, for any k, s[r-k] >= s[l+k]. So at the first mismatch (if any), we would have s[r-k] > s[l+k] (since cannot be <). Could be equal if s[l+k] = s[r-k], then we continue. So if the entire segment is palindromic? Actually if the segment is symmetric with respect to the ends? But the condition for new < original would require s[r-k] < s[l+k] at some first mismatch. However, because of non-decreasing, we have s[l+k] <= s[r-k] for all l+k <= r-k. So the only possibility for first mismatch is s[r-k] > s[l+k]. That would make new > original. So indeed, for any substring where s[l] == s[r] and the segment is non-decreasing, the reversed string would be lexicographically larger (or equal if the segment is symmetric? Actually if the entire segment is such that s[l+k] = s[r-k] for all k, then it's a palindrome; then new = original, so not smaller). So no smaller.
Thus, if the whole string is non-decreasing, then any reversal yields either larger or equal. But is that always true? Consider a string that is non-decreasing, but maybe we reverse a substring that is not entire? We considered any substring. The argument: For any l<r, consider the segment s[l..r]. Since the whole string is non-decreasing, this segment is also non-decreasing. For any k from 0 while l+k < r-k, we have s[l+k] <= s[r-k] (by monotonic property). So comparing forward and reversed, the first difference (if any) will have s[r-k] > s[l+k], leading to new > original. If no difference (i.e., palindrome), new = original. So indeed no reversal can make it smaller. Therefore, the answer is YES iff the string is not non-decreasing. Wait, is that sufficient? Let's test with edge cases: n=2, s="ab" -> non-decreasing => NO. s="ba" -> not non-decreasing => YES (l=1,r=2). That yields "ab" which is smaller? Actually original "ba", reversed "ab": compare: index1 new a vs original b -> a < b, so smaller. So YES.
What about s="aa"? non-decreasing => NO. s="aba"? Check: s[1]=a, s[2]=b, s[3]=a. Is it non-decreasing? a <= b (true), b <= a? false because b > a. So not non-decreasing => YES. Indeed choose l=2,r=3 (b,a) gives new string "aab": index1 a, index2 new a vs original b -> a < b, so smaller. So YES.
What about s="abbb"? Non-decreasing? a <= b, b<=b, b<=b => true. So NO. Check manually: any reversal? [1,2] -> "babb": index1 b > a => larger. [1,3] -> "bbab": index1 b > a => larger. [1,4] -> "bbba": index1 b > a => larger. [2,3] -> "abbb" (no change). [2,4] -> "abbb"? Actually reverse "bbb" -> same. [3,4] -> "abbb". So indeed NO.
What about s="aabc"? Non-decreasing? a<=a, a<=b, b<=c => true. So NO. Check manually: [1,4] -> "cbaa": index1 c > a => larger. [1,3] -> "baac": index1 b > a => larger. [2,4] -> "acba"? Wait s = a a b c; reverse [2,4]: substring a b c -> c b a, so new: a c b a => "acba". Compare: index1 a; index2 new c vs original a => c > a => larger. [3,4] reverse "bc" -> "abac": index1 a; index2 a; index3 new a vs original b => a < b? Actually new: a a c b? Wait compute: original: indices 1 a,2 a,3 b,4 c. Reverse [3,4]: substring "bc" reversed "cb". New string: 1 a,2 a,3 c,4 b => "aacb". Compare to "aabc": at index1 a; index2 a; index3 new c vs original b => c > b => larger. So no smaller.
Thus, the condition seems to be: answer YES iff the string is not sorted in non-decreasing order. That is, there exists at least one i such that s[i] > s[i+1] (a descent). Because if there is any descent, we can simply reverse that adjacent pair to get a smaller string. And if there is no descent, the string is non-decreasing and no reversal yields a smaller string.
But wait: is there any tricky case where the string is not non-decreasing, but there is no descent (i.e., s[i] <= s[i+1] for all i) but still not non-decreasing? Actually non-decreasing by definition is s[i] <= s[i+1] for all i. So if there is no descent (i.e., no i with s[i] > s[i+1]), then it is non-decreasing. So these are equivalent. So indeed answer is YES iff string is not non-decreasing. Equivalent: there exists an inversion (i<j with s[i] > s[j]). But we can simply check for any adjacent pair with s[i] > s[i+1]. That's sufficient.
But is there any possibility where the string is non-decreasing but still we can get a smaller string by reversing a substring that is not contiguous? No, substring must be contiguous.
Wait, consider string "abac"? Let's see: s[1]=a, s[2]=b, s[3]=a, s[4]=c. Check adjacent descents: b > a at i=2, so YES. So fine.
But what about string "cba"? descent at 1? c > b, so YES.
Thus the problem appears trivial: answer YES if the string is not sorted in non-decreasing order, and we can output any l,r where s[l] > s[r]? Actually we need l<r and after reversal, lexicographically smaller. As argued, if we find any i with s[i] > s[i+1], then l=i, r=i+1 works. If there is no such adjacent descent but there exists i<j with s[i] > s[j], can there be such a case without an adjacent descent? Suppose s = "acb". Adjacent: a<=c? true; c > b? true, so descent. So always if there is any inversion, there is an adjacent inversion? Not necessarily. For a sequence that is not non-decreasing, there exists at least one adjacent pair that violates the order? Let's think: If the sequence is not non-decreasing, that means there exists some i<j with s[i] > s[j]. However, it's not guaranteed that there exists an adjacent pair with s[k] > s[k+1]. For example, consider s = "1 3 2 4". Actually numbers: 1 <= 3, 3 > 2 (adjacent descent). So that has. To have no adjacent descent but have an inversion somewhere, you'd need a non-adjacent inversion but all adjacent pairs are non-decreasing. But if all adjacent pairs are non-decreasing, then by transitivity, the whole sequence is non-decreasing: because if for all i, s[i] <= s[i+1], then by induction s[i] <= s[j] for any i<j. So there cannot be an inversion. Indeed, if for all i, s[i] <= s[i+1], then for any i<j, we can chain: s[i] <= s[i+1] <= ... <= s[j], so s[i] <= s[j]. So s[i] > s[j] cannot happen. Therefore, existence of any inversion implies existence of an adjacent descent. So it's equivalent.
Thus, the problem reduces to checking if the string is sorted in non-decreasing order. If it is, output NO. Else, find any index i where s[i] > s[i+1] (1-indexed), output YES and i, i+1.
But wait, constraints are up to 300k, which is trivial.
But is there any nuance? Let's read the problem statement carefully: "You have to choose exactly one of the substrings of the given string and reverse it to obtain a string that is less lexicographically. Note that it is not necessary to obtain the minimum possible string." So we just need any substring that yields a smaller string.
Given our reasoning, if string is non-decreasing, any reversal yields a string that is either equal (if the substring is a palindrome and the rest same) or larger. But could there be a case where reversing a substring yields a string that is lexicographically smaller even if the string is non-decreasing? Let's test with a string that is non-decreasing but not strictly, like "aab". Already tested. "abca"? That's not non-decreasing because c > a, so descent. "aba"? Not non-decreasing. "acb"? descent.
Consider "ba"? Not non-decreasing. "cba"? descent.
Consider "aaab"? non-decreasing. No smaller.
What about "aaa"? all equal, non-decreasing. Reversing any substring yields same string, so no smaller.
Thus, seems correct.
But hold on: There is a nuance: When we reverse a substring, the prefix before l is unchanged, and we compare at first difference. For the string to become lexicographically smaller, we need at the first differing position, the new character is smaller. In a non-decreasing string, for any substring [l,r], we argued that for the first k where s[l+k] != s[r-k] (with k from 0), we have s[l+k] < s[r-k]? Actually we have s[l+k] <= s[r-k] because of monotonicity and indices: l+k < r-k? Wait careful: For k such that l+k < r-k, we have indices i = l+k and j = r-k with i < j, so s[i] <= s[j] => s[l+k] <= s[r-k]. So if they are not equal, then s[l+k] < s[r-k]. But in the reversed string at position l+k we have s[r-k] (from the reversed segment). So at that position, the new character is s[r-k] and original is s[l+k]. Since s[l+k] < s[r-k], we have new char > original char. So the first difference would be new > original, making the new string larger. If they are equal for all k (i.e., the substring is a palindrome), then the new string equals original, not smaller. So indeed never smaller.
Thus condition is exactly: if the string is not sorted in non-decreasing order (i.e., there is at least one adjacent descent), then answer YES, otherwise NO.
But wait, what about the case where the substring reversal might cause a smaller string due to the part after r? No, because the first difference occurs within the substring (or possibly after? but after r, strings are identical, so if no difference within substring, they are identical). So only the substring matters.
Thus solution is straightforward.
But we should consider maybe a tricky scenario: Could there be a case where the string is not non-decreasing, but the only descent is like at the very end? But any descent works.
Edge cases: n=2, s="ab": no descent, answer NO. s="ba": descent, answer YES 1 2.
So algorithm: iterate i from 1 to n-1, if s[i] > s[i+1], output YES and i, i+1 (1-indexed). If no such i, output NO.
Time O(n). Memory O(1).
But wait, there is an example given: Input 7, abacaba, output YES 2 5. According to our simple approach, we could output 2 3 because s[2]='b', s[3]='a', b > a, so answer would be 2 3. That's also valid. The problem accepts any substring. So our simpler answer would be correct.
But is it always valid to output an adjacent pair where s[i] > s[i+1]? Let's test with "abacaba": i=2 works, as we computed earlier. So yes.
Double-check: If s[i] > s[i+1], then reversing substring [i,i+1] yields new string where at position i, we have s[i+1] which is less than s[i]; thus lexicographically smaller. So yes.
Thus the problem seems trivial. However, why would the problem be given on Codeforces? Possibly there's a hidden nuance: The substring must be reversed exactly once, and we must obtain a string that is less lexicographically. Could there be a case where there is a descent but reversing that adjacent pair yields a string that is not lexicographically smaller? Let's test: s = "ab", no descent -> NO. s = "ba", descent -> reversing gives "ab", which is smaller. s = "cba", descent at 1: "c">"b", reversing (1,2) yields "bca". Compare original "cba" vs "bca": at index1, 'b' < 'c', so smaller. Good.
What about s = "zxy"? descent at 1? 'z' > 'x', reverse (1,2) yields "xzy": index1 'x' < 'z', smaller. So fine.
Thus correct.
But perhaps there is a corner case: Suppose s = "abca". s[1]='a', s[2]='b', s[3]='c', s[4]='a'. There is descent at s[3] > s[4]: c > a. So l=3,r=4 works. New string: "abac". Compare: original "abca", new "abac": at index1 a, index2 b, index3 a? Actually new: positions: 1 a,2 b,3 a (since reversal of "ca" yields "ac"), 4 c? Wait compute: original: a b c a. Reverse [3,4]: substring "ca" -> "ac". So new: a b a c => "abac". Compare: "abac" vs "abca": at index1 a; index2 b; index3: new 'a' vs original 'c' -> a < c, so smaller. Works.
Thus, trivial.
But wait, consider string that is not non-decreasing but all descents are such that if we reverse the adjacent pair, the resulting string might be lexicographically larger? That can't happen because at the first differing position (the first character of the reversed pair), we have s[i+1] < s[i] => new char is smaller. So it's smaller.
So answer is simply as described.
But then why is the problem rated maybe 1200? Actually it's Codeforces problem 1157B? No, this is problem 1073A? I'm not sure. But it's indeed a simple problem.
However, before concluding, I should check if there is any scenario where the string is not non-decreasing but also no adjacent descent? As argued, impossible.
Thus solution: scan for first i where s[i] > s[i+1], output YES and i i+1. If none, NO.
But is there any case where reversing a longer substring could yield a smaller string even if there is no descent? Let's think deeper. Our argument relied on the monotonicity of the whole string. If the string is non-decreasing, then for any substring, the segment is also non-decreasing. But wait, is it possible that a substring taken from a non-decreasing string is not non-decreasing? No, because monotonicity is preserved for any subsegment. So that's fine.
But what if the string is not monotonic but also no adjacent descent? That's impossible.
Thus solved.
But I recall that there is a known Codeforces problem: "Reverse a Substring" (CF 1155A?) Actually there is a problem "Reverse a Substring" (CF 1090A?) Let's recall: There is a problem 1155A - Reverse a Substring. Yes! That's the problem. In that problem, the solution is exactly to find any descent and output it, else NO. So indeed it's that problem.
So final answer.
We must output "YES" and indices (1-indexed). If there are multiple, any is fine.
Now implement.
Complexity: O(n).
Implementation details:
- Read n (int).
- Read string s (strip newline).
- Iterate i from 0 to n-2 (0-indexed). If s[i] > s[i+1], print "YES", then print i+1 and i+2 (1-indexed). Return.
- After loop, print "NO".
That's it.
But let's confirm with sample:
Input: 7, abacaba => i=1 (0-indexed) s[1]='b', s[2]='a' -> b > a => output YES, 2 3. But sample output is 2 5. Both are valid.
Second sample: 6, aabcfg. Check: s: a a b c f g. No descent: a<=a, a<=b, b<=c, c<=f, f<=g. So NO. Output matches.
Edge: n=2, s="aa" => NO. n=2, s="ba" => YES 1 2.
Thus solution.
But wait, is there any scenario where the string is non-decreasing but there is a substring that after reversal makes it lexicographically smaller because the substring itself is not monotonic? That cannot happen because substring inherits monotonicity.
Thus final.
We should also consider that the input size is 300k, so we need to use fast I/O in Python.
We'll implement.
One more nuance: The problem statement says: "You have to choose exactly one of the substrings of the given string and reverse it to obtain a string that is less lexicographically." Could we choose a substring of length 1? It says l<r, so length at least 2. So adjacent pair is fine.
Thus we are done.
Let's produce final answer.
But perhaps there is a trick: For non-decreasing strings, is it always impossible? Let's consider a string like "abcc"? Non-decreasing. Try reversing "bc"? substring "bc" reversed "cb": new "acbc"? Actually original: a b c c. Reverse [2,3]: becomes a c b c => "acbc". Compare: index1 a; index2 c vs b -> c > b => larger. Reverse [1,3]: "cba c"? actually reverse "abc" -> "cba", new: c b a c => "cbac": index1 c > a => larger. Reverse [2,4]: "bcc" reversed "ccb": new: a c c b => "accb": index1 a; index2 c vs b? Actually original index2 is b, new index2 is c -> larger. So no.
What about "aaa"? no change.
So correct.
Thus, solution stands.
We can also think of it as: the string is already the smallest lexicographically among all strings obtainable by reversing a substring? Actually if it's non-decreasing, it's already the smallest possible? Not exactly, because reversing a substring might produce a larger string. So it's minimal in the sense that any reversal yields a string >= original. So if original is already sorted in non-decreasing order, it's a local minimum. Indeed.
Therefore answer is as above.
Now finalize.
But hold on: There is a known twist: In the problem "Reverse a Substring" (CF 1155A), the condition is exactly: if the string is not sorted in non-decreasing order, then there exists a substring reversal that makes it lexicographically smaller. And the solution is to output the first index where s[i] > s[i+1]. So we are good.
Thus implement.
I'll write code in Python:
def solve():
import sys
input = sys.stdin.readline
n = int(input().strip())
s = input().strip()
for i in range(n-1):
if s[i] > s[i+1]:
print("YES")
print(i+1, i+2)
return
print("NO")
Edge: trailing newline handling.
That's it.
But perhaps we need to handle if n is less than 2? According to constraints n>=2, so fine.
Now produce final answer. ```python
import sys
def solve() -> None:
input = sys.stdin.readline
n = int(input())
s = input().strip()
for i in range(n - 1):
if s[i] > s[i + 1]:
print("YES")
print(i + 1, i + 2) # convert to 1‑based indices
return
print("NO")
if name == "main":
solve()