#include <iostream>
using
namespace
std;
bool
isSortedAndRotated(
int
arr[],
int
n) {
bool
rotated =
false
;
int
min_index = 0;
int
min_element = arr[0];
for
(
int
i = 1; i < n; i++) {
if
(arr[i] < arr[i - 1]) {
rotated =
true
;
}
if
(arr[i] < min_element) {
min_index = i;
min_element = arr[i];
}
}
if
(!rotated) {
return
false
;
}
for
(
int
i = 1; i < n; i++) {
int
index = (min_index + i) % n;
int
prev_index = (min_index + i - 1) % n;
if
(arr[index] < arr[prev_index]) {
return
false
;
}
}
return
true
;
}
int
main() {
int
arr1[] = { 3, 4, 5, 1, 2 };
int
arr2[] = { 7, 9, 11, 12, 5 };
int
arr3[] = { 1, 2, 3 };
int
arr4[] = { 3, 4, 6, 1, 2, 5 };
int
n1 =
sizeof
(arr1) /
sizeof
(arr1[0]);
int
n2 =
sizeof
(arr2) /
sizeof
(arr2[0]);
int
n3 =
sizeof
(arr3) /
sizeof
(arr3[0]);
int
n4 =
sizeof
(arr4) /
sizeof
(arr4[0]);
if
(isSortedAndRotated(arr1, n1)) {
cout <<
"YES\n"
;
}
else
{
cout <<
"NO\n"
;
}
if
(isSortedAndRotated(arr2, n2)) {
cout <<
"YES\n"
;
}
else
{
cout <<
"NO\n"
;
}
if
(isSortedAndRotated(arr3, n3)) {
cout <<
"YES\n"
;
}
else
{
cout <<
"NO\n"
;
}
if
(isSortedAndRotated(arr4, n4)) {
cout <<
"YES\n"
;
}
else
{
cout <<
"NO\n"
;
}
return
0;
}