2
4 2

yes
swap 1 2

3
3 1 2

no

6
1 5 4 3 2 6

yes
reverse 2 5

#### 參考答案

```import java.util.*;

class Solution {

public static void main(String[] args) {
final Scanner sc = new Scanner(System.in);
final int n = sc.nextInt();

final int[] a = new int[n + 2];
a[0] = -1;
a[n + 1] = 1000001;
for (int i = 1; i <= n; ++i) {
a[i] = sc.nextInt();
}
int i = 1;
int x = -1;
while (i <= n) {
if (a[i] > a[i + 1]) {
x = i++;
break;
}
++i;
}
if (x >= 0) {
// try swap
boolean canSwap = false;
int y = -1;
while (i <= n) {
int buffer = a[x];
a[x] = a[i];
a[i] = buffer;
final int q = a[x - 1];
final int p = a[x + 1];
final int r = a[x];
final int w = a[i];
final int e = a[i - 1];
final int t = a[i + 1];
if ((q < r && r < p) && (e < w && w < t)) {
canSwap = true;
y = i++;
break;
} else {
buffer = a[x];
a[x] = a[i];
a[i] = buffer;
}
++i;
}
if (canSwap) {
i = x + 1;
while (i <= n) {
if (a[i] > a[i + 1]) {
canSwap = false;
final int buffer = a[x];
a[x] = a[y];
a[y] = buffer;
break;
}
++i;
}
}
if (canSwap) {
System.out.println("yes\nswap " + x + " " + y);
return;
}

// try reverse
i = x + 1;
while (i <= n) {
if (!(a[i - 1] > a[i] && a[i] > a[i + 1])) {
y = i++;
break;
}
++i;
}
boolean canReverse = a[x] < a[y + 1] && a[x - 1] < a[y];
if (canReverse) {
while (i <= n) {
if (a[i] > a[i + 1]) {
canReverse = false;
break;
}
++i;
}
}
if (canReverse) {
System.out.println("yes\nreverse " + x + " " + y);
return;
}
System.out.println("no");
} else {
System.out.println("yes");
}
}
}```