#include<iostream>
#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n;
     cin>>n;
    vector<int> arr;
    vector<int> arr1;
    for(int i=0; i<n; i++)
    {
        int m;
        cin>>m;
        arr.push_back(m);
        arr1.push_back(m);
    }
    sort(arr1.begin(),arr1.end());
    int temp=0;
    //int temp1=0;
    for(int i=0; i<arr.size(); i++)
    {
        if(arr[i]!=arr1[i])
        {
            temp++;
        }

    }
    if(temp==0)
    {
       cout<<"YES"<<endl;
    }
    else if(arr[arr.size()-1]==arr1[0] && arr[0]==arr1[arr1.size()-1])
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
   /* else
    {
        int tempo;
        tempo=arr[arr.size()-1];
        arr[arr.size()-1]=arr[0];
        arr[0]=tempo;
        for(int i=0; i<arr.size(); i++)
    {
        if(arr[i]!=arr1[i])
        {
            temp1++;
        }

    }
    if(temp1==0)
    {
       cout<<"YES"<<endl;
    }
    else
         cout<<"NO"<<endl;

    }*/

        return 0;
}

