Problem:
Score : 200 points

Problem Statement

We have a sequence p = {p_1,\ p_2,\ ...,\ p_N} which is a permutation of {1,\ 2,\ ...,\ N}.

You can perform the following operation at most once: choose integers i and j (1 \leq i < j \leq N), and swap p_i and p_j. Note that you can also choose not to perform it.

Print YES if you can sort p in ascending order in this way, and NO otherwise.

Constraints

All values in input are integers.

2 \leq N \leq 50

p is a permutation of {1,\ 2,\ ...,\ N}.

Input

Input is given from Standard Input in the following format:

N
p_1 p_2 ... p_N

Output

Print YES if you can sort p in ascending order in the way stated in the problem statement, and NO otherwise.

Sample Input 1

5
5 2 3 4 1

Sample Output 1

YES

You can sort p in ascending order by swapping p_1 and p_5.

Sample Input 2

5
2 4 3 5 1

Sample Output 2

NO

In this case, swapping any two elements does not sort p in ascending order.

Sample Input 3

7
1 2 3 4 5 6 7

Sample Output 3

YES

p is already sorted in ascending order, so no operation is needed.

Solution in Rust (1.15.1) (judge verdict: Accepted)

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [$t:tt]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}


#[cfg(debug_assertions)]
macro_rules! mydbg {
    //($arg:expr) => (dbg!($arg))
    ($arg:expr) => (println!("{:?}",$arg));
}


#[cfg(not(debug_assertions))]
macro_rules! mydbg {
    ($($arg:expr),*) => {};
}


use std::cmp;
use std::collections::HashMap;



use std::ops::{ Add, Sub , Div , Mul };
static global_mod : i64 = 1000000007;

#[derive(Debug,Copy,Clone)]
pub struct ModInt {
    x : i64
}

impl ModInt{
    pub fn  new (p:i64) -> Self {
        let a = (p % global_mod + global_mod)% global_mod;     
        return ModInt{x:a};
    }

    pub fn inv (self) -> Self{
        return self.pow(global_mod-2);

    }

    pub fn pow (self , t:i64) -> Self{
        if(t==0 ) {return ModInt::new(1)};
        let mut a = self.pow(t>>1);
        a = a*a;
        if(t&1 != 0) {a = a* self};
        return a;
    }
}
impl Add for ModInt {
    type Output = ModInt;
    fn add(self,other : ModInt) -> ModInt{
        let ret  = self.x + other.x ;
        return ModInt::new(ret);
    }
}
impl Sub for ModInt {
    type Output = ModInt;
    fn sub(self,other : ModInt) -> ModInt{
        let ret  = self.x - other.x;
        return ModInt::new(ret);
    }
}
impl Mul for ModInt {
    type Output = ModInt;
    fn mul(self,other : ModInt) -> ModInt{
        let ret  = self.x * other.x ;
        return ModInt::new(ret);
    }
}

impl Div for ModInt {
    type Output = ModInt;
    fn div(self,other : ModInt) -> ModInt{
        let ret  = self.x * other.inv().x;
       return ModInt::new(ret);
    }
}

impl std::string::ToString for ModInt{
    fn to_string(&self) -> String{
        return self.x.to_string();
    }
}


pub struct Combination{
    fact : Vec<ModInt>,
    ifact : Vec<ModInt>
}

impl Combination{
    pub fn new(n:i32)->Self{
        let mut fact = vec![ModInt::new(0);(n+1) as usize];
        let mut ifact = vec![ModInt::new(0);(n+1) as usize];
        fact[0] = ModInt::new(1);
        for i in 1..n+1 { fact[i as usize] = fact[(i-1) as usize] * ModInt::new(i as i64) };
        ifact[n as usize] = fact[n as usize].inv();
        for i in (1..n+1).rev(){ ifact[(i-1) as usize] = ifact[i as usize]* ModInt::new(i as i64) }


        let a = Combination{
            fact : fact,
            ifact : ifact
        };
        return a;
    }

    pub fn gen(self , n:i32 , k:i32)-> ModInt{
        mydbg!(self.fact[n as usize]);
        mydbg!(self.ifact[k as usize]);
        mydbg!(self.ifact[(n-k) as usize]);
        if (k < 0 || k > n) {return ModInt::new(0 as i64)};
        return self.fact[n as usize]*self.ifact[k as usize]*self.ifact[(n-k) as usize];

    }
}




fn main() {


  input! { 
         n: usize,
         p:[i32;n],
    }


    let mut p2 = p.clone();
    p2.sort();

    let mut c = 0;
    for i in 0..p2.len(){
        if(p2[i] != p[i]){
            c +=1;
        }
    }

    println!("{}",if c ==0 || c == 2 {"YES"} else {"NO"});


}