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 (Python):
import glob



REL_PATH = 'ABC\\135\\B'


TOP_PATH = 'C:\\AtCoder'


class Common:

    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index-1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class B(Common):

    def resolve(self):

        N = int(self.input_data())
        seq = [int(i) for i in self.input_data().split()]

        diff = []
        result = "NO"

        for i in range(N):
            if seq[i] != i+1:
                if len(diff) < 2:
                    diff.append([i+1, seq[i]])
                else:
                    break
        else:
            if len(diff) == 0:
                result = "YES"
            if len(diff) == 2:
                if diff[0][0] == diff[1][1] and diff[0][1] == diff[0][1]:
                    result = "YES"

        print(result)


solver = B(REL_PATH)
solver.exec_resolve()

Solution (Python):
N = int(input())
ary = list(map(int, input().split()))
  
sorted_ary = sorted(ary)
d = [a - s for a, s in zip(ary, sorted_ary)]
n = sum([1 for x in d if x != 0])
if n <= 2:
  print("YES")
else:
  print("NO")

Solution (Python):
N = int(input())
p = list(map(int, input().split()))
ans = 0

for i in range( 1 ,N+1 ):
    if p[i-1] != i:
        ans += 1

if ans == 2 or ans == 0:
    print('YES')
else:
    print('NO')

Solution (Python):
import sys

n = input()
data = list(map(int,sys.stdin.readline().split()))


datacp = sorted(data)

a = list(map(lambda x: x[0]-x[1] ,zip(data,datacp)))

a = [i for i in a if i != 0 ]
if len(a) <= 2:
	print('YES')
else:
	print('NO')

Solution (Python):
n = int(input())
p = list(map(int, input().split()))
ans = 0

for i in range(1, n+1):
    if p[i-1] != i:
        ans += 1

if ans == 2 or ans == 0:
    print('YES')
else:
    print('NO')

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
a_sort = sorted(a)

x = 0
p = 'YES'
for i in range(N):
  if a[i] != a_sort[i]:
    x += 1
    if x > 2:
      p = 'NO'
      break

print(p)

Solution (Python):
N = int(input())
p=list(map(int, input().split()))

count=0
i=0
while True:
  if p[i]!=i+1:
    count+=1
  if i>=N-1:
    break
  i+=1

if count==2 or count==0:
  print("YES")
else:
  print("NO")

Solution (Python):
n=int(input())
p=list(map(int,input().split()))
k=0
count=0
while True:
    if k==n:
        break
    elif p[k]==k+1:
        k+=1
    else:
        count+=1
        k+=1
if count==0 or count==2:
    print('YES')
else:
    print('NO')

Solution (Python):
import math





inputa = input().split()
inputb = input().split()

a = int(inputa[0])







inputbList = []
inputbList = list(inputb)


inputbint = []
inputbint = [int(n) for n in inputbList]




cnt = 0
for i in range(a):
    if inputbint[i] != i+1:
        cnt += 1

if cnt == 0 or cnt ==2:
    print("YES")
else:
    print("NO")

Solution (Python):
def B_0or1Swap():
    N = int(input())
    p = list(map(int, input().split()))
    p_sort = sorted(p)
    num = 0
    ans = "NO"
    for x in range(N):
        if p[x] != p_sort[x]:
            num += 1
    if (0 == num) or (2 == num):
        ans = "YES"
    print(ans)
    
if __name__ == "__main__":
    B_0or1Swap()

Solution (Python):

n = int(input())
p_list = list(map(int, input().split()))

q_list = list(range(1, n + 1))
unmatch_p = []
for p, q in zip(p_list, q_list):
    if p == q:
        pass
    else:
        unmatch_p.append(p)
        
if len(unmatch_p) == 2:
    print("YES")
elif len(unmatch_p) == 0:
    print("YES")
else:
    print("NO")

Solution (Python):
N=int(input())
p=list(map(int,input().split()))

P=sorted(p)
flag=0

for i in range(0,N):
    if p[i]!=P[i]:
        flag+=1

if flag==2:
    print('YES')
elif flag==0:
    print('YES')
else :
    print('NO')

Solution (Python):
n,*x=map(int,open(0).read().split())
soreted_x=sorted(x)
cnt=0

for a,b in zip(x,soreted_x):
  if a != b:
    cnt+=1

print('YES' if cnt<=2 else 'NO')

Solution (Python):
n=int(input())
line= list(map(int,input().split()))
cnt=0
for x in range(n):
    if line[x]!=x+1:
        cnt+=1
if cnt==0 or cnt==2: 
    print('YES')
else:
    print('NO')

Solution (Python):
N = int(input())
p = list(map(int,input().split()))

p_hikaku = []
for j in range(1,N+1):
    p_hikaku.append(j)

count = 0
for j in range(N):
    if p[j] !=  p_hikaku[j]:
        count += 1

if count == 0 or count == 2:
    print("YES")
else:
    print("NO")

Solution (Python):
n = int(input())
p = list(map(int, input().split()))
t = [i for i in range(1,n+1)]
count=0
for i in range(n):
    if p[i]!=t[i]:
        count+=1
    if count>=3:
        print("NO")
        exit()
print("YES")

Solution (Python):
import sys
from operator import itemgetter
import math
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  

n = ni()
ppp = na()
ln = len(ppp)
ct = 0
for i in range(ln):
    if ppp[i] != i+1:
        ct += 1
if ct == 0 or ct == 2:
    print("YES")
else:
    print("NO")

Solution (Python):
N = input()
lst1 = list(map(int, input().split()))
lst2 = sorted(lst1)
 
n = 0
for x, y in zip(lst1, lst2):
    if x != y:
        n += 1
        if n > 2:
            break
 
if n > 2:
    print('NO')
else:
    print('YES')

Solution (Python):
n = input()
a = list(map(int, input().split()))
print("YES") if sum(x != i for i, x in enumerate(a, 1)) <= 2 else print("NO")

Solution (Python):
N = int(input())
value = list(map(int, input().split()))
count = 0
for i in range(N):
    if value[i] != i + 1:
        count += 1
if count > 2:
    ans = "NO"
else:
    ans = "YES"
print(ans)

Solution (Python):
n = int(input())
p = list(map(int, input().split()))

cnt = 0
for i in range(n):
    if p[i]!=i+1:
        cnt += 1
if cnt<=2:
    print("YES")
else:
    print("NO")

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
ans=0
for i in range(n):
  if l[i]!=(i+1):
    ans+=1
if ans==0 or ans==2:
  print('YES')
else:
  print('NO')

Solution (Python):
input()
p = [int(x) for x in input().split()]
    
p_sorted = sorted(p)
    
diff = 0
for p_elem, p_sorted_elem in zip(p, p_sorted):
    if p_elem != p_sorted_elem:
        diff += 1
    
if diff == 0 or diff == 2:
    print('YES')
else:
    print('NO')

Solution (Python):
N=int(input())
p=list(map(int,input().split()))

sort_p=sorted(p)
cnt=0


for i,j in zip(p,sort_p):
  if i != j:
    cnt += 1

if cnt <= 2:
  print("YES")
else:
  print("NO")

Solution (Python):
n = int(input())
p = list(map(int,input().split()))
p2 = sorted(p)
count = 0
for i in range(n):
    if p[i] != p2[i]:
        count += 1
if count <= 2:
    print("YES")
else:
    print("NO")

Solution (Python):
import sys

N = int(input())
p = list(map(int, input().split()))
pp = sorted(p)
ct = 0
for i in range(N):
    if p[i] != pp[i]:
        ct += 1
    if ct > 2:
        print('NO')
        sys.exit()

print('YES')

Solution (Python):
N = int(input())
p = list(map(int,input().split()))
ans = 0
for i in range(0,N):
    if p[i] == i+1:
        ans += 0
    else:
        ans += 1
if ans == 2:
    print("YES")
elif ans == 0:
    print("YES")
else:
    print("NO")

Solution (Python):
import numpy as np

n = int(input()) 
p = list(map(int,input().split()))

ok = list(range(1,n+1,1)) 


npp = np.array(p)
npok = np.array(ok)


if np.count_nonzero(npp!=npok) <=2:
    print("YES")
else:
    print("NO")

Solution (Python):
n = int(input())
s = input().split()
b =[str(i+1) for i in range(len(s))]
count=0
for i in range(len(s)):
  if s[i]!=b[i]:
    count+=1
if count==0: print("YES")
elif count==2: print("YES")
else: print("NO")

Solution (Python):
n=int(input())
p=list(map(int, input().split()))
p_sort=sorted(p)
count=0
for i in range(n):
  if p[i]!=p_sort[i]:
    count+=1
  else:
    continue
if count==2 or count==0:
  print("YES")
else:
  print("NO")

Solution (Python):
def p_b():
    N = int(input())
    p_n = list(map(int, input().split()))

    p_sort = sorted(p_n)
    cnt = 0

    for a, b in zip(p_n, p_sort):
        if a != b:
            cnt += 1

    if cnt == 0 or cnt == 2:
        print("YES")
    else:
        print("NO")


if __name__ == '__main__':
    p_b()

Solution (Python):
N = int(input())
suuretsu_str = input().split()
suuretsu = [int(i) for i in suuretsu_str]
suuretsu_order = [i for i in range(1,N+1)]
count = 0
for i in range(N):
    if suuretsu[i] != suuretsu_order[i]:
        count += 1
if count == 2 or count == 0:
    print("YES")
else:
    print("NO")

Solution (Python):
N = int(input())
p = list(map(int, input().split()))
pp = sorted(p)
count = 0
for i in range(len(p)):
    if p[i] != pp[i]:
        count = count + 1

if count <= 2:
    print("YES")
else:
    print("NO")

Solution (Python):
n=int(input())
lis=list(map(int,input().split()))
a=0
for i in range(n):
    if lis[i]!=i+1:
        a+=1

if a<=2:
    print("YES")
else:
    print("NO")

Solution (Python):
n = int(input())
num = [int(i) for i in input().split()]
flag = 0
if num == sorted(num):
  flag = 1
else:  
  sorted_num = sorted(num)
  for i in range(n):
    if flag == 1:
      break
    for j in range(n-i-1):
      temp = num[i]
      num[i] = num[i+j+1]
      num[i+j+1] = temp
      if num == sorted_num:
        flag = 1
        break
      else:
        temp = num[i]
        num[i] = num[i+j+1]
        num[i+j+1] = temp
if flag == 1:
  print('YES')
else:
  print('NO')

Solution (Python):
N=int(input())
p=input().split()
for i in range(0,N):
    p[i]=int(p[i])
t=0
for i in range(0,N):
    if i+1!=p[i]:
        t+=1
if t==2 or t==0:
    print("YES")
else:
    print("NO")

Solution (Python):
n = int(input())
p = list(map(int,input().split()))

s=sorted(p)
cnt=0

def jud(p,s,n,cnt):
    
    for i in range(n):
        if s[i]!=p[i]:
            cnt+=1
        if cnt>2:
            return "NO"
    return "YES"

print(jud(p,s,n,cnt))

Solution (Python):
import itertools

def getint(): return int(input())
def getints(): return list(map(int, input().split()))

n=getint()
a=getints()
b=list(sorted(a))

cnt = 0
for i in range(n):
    if a[i] != b[i]:
        cnt += 1


print("YES" if cnt <= 2 else "NO")

Solution (Python):

n=int(input())
p=list(map(int,input().split()))
x=sorted(p)
res=0
for i in range(n):
    if x[i]!=p[i]:
        res+=1
print("YES" if res<=2 else "NO")

Solution (Python):
N = int(input())
p = list(map(int,input().split()))
count = 0
for i in range(1,N+1):
    if p[i-1] != i:
        count += 1
    if count >2:
        print('NO')
        exit(0)
print('YES')

Solution (Python):

N = int(input())
Pp = input()

P = []
H = []
n=1

for i in range(N):
    P = int(Pp.split()[i])
    H.append(P-n)
    n+=1


R = H.count(0)

if N-R < 3:
    print('YES')

else:
    print('NO')

Solution (Python):
N = int(input())

p =list(map(int,input().split()))

c = 0

for i in range(N):
    if p[i]!=i+1:
        c +=1
if c == 2 or c ==0:
    print("YES")
else:
    print("NO")

Solution (Python):
N = int(input())
P = list(map(int, input().split()))
Q = sorted(P)
if sum(1 if P[i] != Q[i] else 0 for i in range(N)) <= 2:
    print("YES")
else:
    print("NO")

Solution (Python):
N = int(input())
p = list(map(int, input().split()))
count = 0
for i in range(N):
    if p[i]-1 != i:
        count+=1
if count <= 2:
    print("YES")
else:
    print("NO")

Solution (Python):
from sys import stdin 

n = int(input())
p = [int(x) for x in stdin.readline().rstrip().split()]
c= 0
q = sorted(p)

for i in range(n):
	if p[i] != q[i]:
		c += 1

if c>2:
	print("NO")

else:
	print("YES")

Solution (Python):
num = int(input())
num_list = input().split(' ')
num_list[0] = int(num_list[0])
for i in range(num):
    num_list[i] = int(num_list[i])
count = 0
for i in range(num):
    if num_list[i] != i+1:
        count = count +1
if count > 2:
    print('NO')
else:
    print('YES')

Solution (Python):
N = int(input())
p_list = list(map(int,input().split()))
cnt = 0
for i in range(N):
    if (i+1) != p_list[i]:
        cnt += 1
if cnt == 2:
    print('YES')
elif cnt == 0:
    print('YES')
else:
    print('NO')

Solution (Python):
N = int(input())
lis = list(map(int,input().split()))
counter = 0
for i in range(N):
  if lis[i] - i-1 != 0:
    counter += 1
if counter > 2:
  print('NO')
else:
  print('YES')

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
count=0
for i in range(n):
  if(i+1 != a[i]):
    count+=1
if(count<=2):
  print("YES")
else:
  print("NO")

Solution (Python):
N = int(input())
p_ls = [int(i) for i in input().split()]
gold_p_ls = sorted(p_ls)
_start = None
_end = None
for i, p in enumerate(p_ls):
    if i + 1 != p:
        _start = i
        break

for j, p in enumerate(p_ls[::-1]):
    if N - j != p:
        _end = N - 1 - j
        break

if _start is None:
    print("YES")
else:
    tmp = p_ls[_start]
    p_ls[_start] = p_ls[_end]
    p_ls[_end] = tmp
    if p_ls == gold_p_ls:
        print("YES")
    else:
        print("NO")

Solution (Python):
N = int(input())
p = list(map(int, input().split()))
cnt = 0
for n in range(N):
    if p[n] != n+1:
        cnt+=1

if cnt <= 2:
    print("YES")
else:
    print("NO")

Solution (Python):
N = int(input())
p = list(map(int, input().split()))
cnt = 0
for n in range(N):
    if p[n] != n+1:
        cnt+=1
 
if cnt <= 2:
    print("YES")
else:
    print("NO")

Solution (Python):
n = int(input());
p = list(map(int, input().split()));

c = 0;
for i in range(n):
    if(p[i] != i+1): 
        c+=1

if c == 0 or c == 2:
    print("YES")
else: 
    print("NO")

Solution (Python):
n=int(input())
plist=list(map(int, input().split()))
k=0
for i in range(1,n+1):
    if i != plist[i-1]:
        k+=1
if k <= 2:
    print('YES')
else:
    print('NO')

Solution (Python):
n=int(input())
arr=[int(x) for x in input().split(' ')]
arr2=sorted(arr)
for x in range(n):
	if x+1==arr[x]:
		continue
	else:
		t=arr[x]
		arr[x]=arr[t-1]
		arr[t-1]=t
		break

if arr==arr2:
	print("YES")
else:
	print("NO")

Solution (Python):
N = int(input())
p = list(map(int, input().split()))
cnt = 0
 
for i in range(N):
  if p[i] != i+1:
    cnt += 1
 
if cnt==0 or cnt==2 :
  print('YES')
else:
  print('NO')

Solution (Python):
N = int(input())
A = list(map( int, input().split() ))
ans = sum([int(A[i] != i+1) for i in range(N)])
print('YES' if ans<=2 else 'NO')

Solution (Python):
n = int(input())
num_list = list(map(int,input().split()))
sorted_num_list = sorted(num_list)
cnt = 0
for i in range(len(num_list)):
	if num_list[i] != sorted_num_list[i]:
		cnt += 1
if cnt < 3:
	print("YES")
else:
	print("NO")

Solution (Python):
N = int(input())
p = list(map(int,input().split()))
p_sort = sorted(p)
p_len = len(p)
ans = [0]*p_len
for i in range(p_len):
  ans[i] = p[i]-p_sort[i]

if ans.count(0) >= p_len-2:
  print('YES')
else:
  print('NO')

Solution (Python):
N = int(input())
p = list(map(int,input().split(" ")))
counter = 0
for i in range(N):
    if p[i] != i+1 and counter <= 1:
        counter = counter + 1
    elif p[i] != i+1 and counter > 1:
        counter = counter + 1
        break;
if counter <= 2:
    print("YES")
else:
    print("NO")

Solution (Python):
n = int(input())
li = list(map(int, input().split()))

c = 0
for i in range(n):
  if li[i] != i+1:
    c += 1

if c == 0 or c == 2:
  print("YES")
else:
  print("NO")

Solution (Python):
a = int(input())
list2 = list(map(int,input().split()))
list1 = list(range(1,a+1,1))
b = 0
for i in range(a):
    if list1[i] == list2[i]:
        continue
    else:
        if b == 0:
            for j in range(i+1,a):
                if list1[i] == list2[j]:
                    list2[j] = list2[i]
                    list2[i] = list1[i]
                    b += 1
        else:
            print("NO")
            break
else:
    print("YES")

Solution (Python):
i = int(input())
l = list(map(int, input().split()))
s = sorted(l)
f = 0

for n in range(i):
    if l[n] == n+1:
        continue
    else:
        f = f + 1
        continue

if f == 2:
    print('YES')
elif f == 0:
    print('YES')
else:
    print('NO')

Solution (Python):
"""


     = sys.stdin.readline().rstrip()
     = list(sys.stdin.readline().rstrip())


     = int(sys.stdin.readline())
     = map(int, sys.stdin.readline().split())
     = list(map(int, sys.stdin.readline().split()))
     = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  


a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654


char_list = list("abcd") 
"""

import math
import sys
import itertools
import queue
from fractions import gcd

import copy

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007


if __name__ == "__main__":
     N = int(sys.stdin.readline())
     L = list(map(int, sys.stdin.readline().split()))

     cnt = 0

     for i, e in enumerate(L, 1):
          if e != i:
               cnt += 1

     if cnt == 0 or cnt == 2:
          print("YES")
     else:
          print("NO")

Solution (Python):
"""


     = sys.stdin.readline().rstrip()
     = list(sys.stdin.readline().rstrip())


     = int(sys.stdin.readline())
     = map(int, sys.stdin.readline().split())
     = list(map(int, sys.stdin.readline().split()))
     = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  


a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654


char_list = list("abcd") 
"""

import math
import sys
import itertools
import queue
from fractions import gcd

import copy

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007


if __name__ == "__main__":
     N = int(sys.stdin.readline())
     L = list(map(int, sys.stdin.readline().split()))

     cnt = 0
     
     for i, e in enumerate(L):
          if e != i + 1:
               cnt += 1

     if cnt == 0 or cnt == 2:
          print("YES")
     else:
          print("NO")

Solution (Python):
n = int(input())
p = list(map(int,input().split()))
sort_p = sorted(p)
cnt = 0
for i in range(n):
  if p[i]-sort_p[i]!=0:
    cnt+=1

print('YES' if cnt==0 or cnt==2 else 'NO')

Solution (Python):
n = input()
l = list(map(int, input().split()))
s = sorted(l)
out = 0
for i in range(len(l)):
  out += 1 if l[i] != s[i] else 0
 
print('YES') if out == 2 or out == 0 else print('NO')

Solution (Python):
N = int(input())
p = [int(i) for i in input().split()]
count = 0 
res = "YES"
p_sorted = sorted(p)
for i in range(N):
  if p_sorted[i] != p[i]:
    count += 1
    if count > 2:
      res = "NO"
      break
print(res)

Solution (Python):
N = int(input())
p = list(map(int, input().split()))
pp = [i+1 for i in range(N)]

a = 0
for i in range(N):
    if p[i]!=pp[i]:
        a += 1
if a > 2:
    print('NO')
else:
    print('YES')

Solution (Python):
n = int(input())
p = list(map(int, input().split()))
p_new = sorted(p)
ans = 'NO'
for i in range(n):
    for j in range(i, n):
        tmp = p.copy()
        tmp[i], tmp[j] = tmp[j], tmp[i]
        if tmp == p_new:
            ans = 'YES'
            break
print(ans)

Solution (Python):
N=int(input())
s=list(map(int,input().split()))
t=sorted(s)
g=0
for i in range(N):
  if t[i]!=s[i]:
    g+=1
if g==2 or g==0:
  print("YES")
else:
  print("NO")

Solution (Python):
N = int(input())
P = list(map(int, input().split()))

correct = [i for i in range(1, N+1)]
count = 0
for p, c in zip(P, correct):
    if p != c:
        count += 1

if count <= 2:
    print("YES")
else:
    print("NO")

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

box=[]

for i in range(n):
  if i+1 == a[i]:
    pass
  else:
    box.append(i)
if len(box) == 0 or len(box) == 2:
  print('YES')
else:
  print('NO')

Solution (Python):
N = int(input())
p = [int(i) - 1 for i in input().split()]

f = 0
ans = 'YES'
for i, v in enumerate(p):
    if i == v:
        continue
    if i != v and f:
        ans = 'NO'
        break
    else:
        p[i], p[v] = p[v], p[i]
        f = 1
            
print(ans)

Solution (Python):
n = int(input())
numlist = list(map(int,input().split(' ')))

notmatch = 0
for i,num in enumerate(numlist):
    if num != i+1 :
        notmatch +=1

if notmatch ==0 or notmatch ==2:
    print('YES')
else:
    print('NO')

Solution (Python):
n = int(input())
p = [int(x) for x in input().split()]

count = 0
for idx, pi in enumerate(p):
    if pi != idx+1:
        count += 1
        if count == 3:
            print("NO")
            exit()
print("YES")

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
def sorted(l):
    last=0
    for i in l:
        if last>i:
            return False
        last=i
    return True
for i in range(n):
    for j in range(i,n):
        l[i],l[j]=l[j],l[i]
        if sorted(l):
            print("YES")
            quit()
        l[i],l[j]=l[j],l[i]
print("NO")

Solution (Python):
N = int(input())
p_list = list(map(int,input().split()))
count = 0

for i in range(N):
    if i+1 != p_list[i]:
        count += 1

if count <= 2:
    print("YES")
else:
    print("NO")

Solution (Python):
N=int(input())
p=list(map(int, input().split()))
count=0
for i in range(N-1):
    A=p[i]
    if A != (i+1):
        count=count+1
if count > 2:
    print('NO')
else:
    print('YES')

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
b=0
for i in range(n):
  if a[i]==i+1:
    b+=0
  else:
    b+=1
if b==0 or b==2:
  print("YES")
else:
  print("NO")

Solution (Python):
N = int(input())
inputs = input().split()
p = [int(n) for n in inputs]
ans = [x for x in range(1, N+1)]
count = 0
result = 'YES'

for i in range(N):
    if p[i] != ans[i]:
        count += 1

if count > 2:
    result = 'NO'

print(result)

Solution (Python):
n=int(input())
p = input().split()
p = [int(x) for x in p]

ans = 0
i = 0
while (ans < 3 and i < n):
    if (p[i] != i+1):
        ans += 1
    i += 1

if (ans < 3):
    print("YES")
else:
    print("NO")

Solution (Python):
n = int(input())
p = list(map(int, input().split()))

p_s = sorted(p)
cnt = 0
for i in range(n):
    if p[i]!=p_s[i]: cnt+=1
print("YNEOS"[cnt!=2 and cnt!=0::2])

Solution (Python):
import copy

n = int(input())
p = list(map(int, input().split()))

q = copy.copy(p)

q.sort()

kaisu = 0

for i in range(n):
  if p[i] != q[i]:
    kaisu += 1

if kaisu == 0 or kaisu == 2:
  print("YES")
else:
  print("NO")

Solution (Python):
N = int(input())
li = list(map(int, input().split()))
li_sort = sorted(li)
count = 0
for i in range(N):
  if li[i] != li_sort[i]:
    count += 1
print("YES" if count <= 2 else "NO")

Solution (Python):


n = int(input())
ary = [int(i) for i in input().split()]
wrongCount = 0



for i in range(n):
    if ary[i] != i + 1:
        if wrongCount == 2:
            print('NO')
            exit()
        wrongCount += 1

print('YES')

Solution (Python):
N = int(input())
p = list(map(int, input().split()))
for i in range(N-1):
    for j in range(i+1, N):
        q = p[:]
        q[i] = p[j]
        q[j] = p[i]
        if q == list(range(1, N+1)):
            print("YES")
            exit()
if p == list(range(1,N+1)):
    print("YES")
    exit()
print("NO")

Solution (Python):
n=int(input())
p=list(map(int,input().split()))
p_sort=sorted(p)
cnt=0
for i in range(n):
  if p[i]!=p_sort[i]:
    cnt+=1
    if cnt>2:
      print('NO')
      exit()
print('YES')

Solution (Python):
N = int(input())
P = list(map(int, input().split()))

b=P.copy()

b.sort()
count=0

for i in range(N):
  if P[i] != b[i]:
    count+=1
    
if count <=2:
  print('YES')
else:
  print('NO')

Solution (Python):
n = int(input())
p = list(map(int, input().split()))
q = p.copy()
q.sort()
cnt = 0
for i in range(n):
    if p[i] != q[i]:
        cnt += 1
print("YES" if cnt <= 2 else "NO")

Solution (Python):
def solve(string):
    n, *p = map(int, string.split())
    return "NO" if sum([i != _p for i, _p in enumerate(p, start=1)]) > 2 else "YES"


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Solution (Python):
N=int(input())
p=list(map(int,input().split()))
q=sorted(p)
count=0
for i in range(N):
    if p[i]!=q[i]:
        count+=1
if count<=2:
    print('YES')
else:
    print('NO')

Solution (Python):
N=input()
p=input()
N=int(N.split()[0])
p=p.split()
p=[int(p) for p in p]
numlist=sorted(p)

if numlist==p:
        output="YES"
else: 
    dist=0    
    for s,t in zip(numlist,p):
        if s!=t:
                dist=dist+1
        else:

            pass
    if dist==2:
        output="YES"
    else :
        output="NO"        
print(output)

Solution (Python):
N = int(input())
p = list(map(int, input().split()))

ans = sorted(p)

if p == ans:
    print ('YES')
    exit()

for i in range(N -1):
    for j in range(i + 1, N):
        p[i], p[j] = p[j], p[i]
        if p == ans:
            print ('YES')
            exit()
        else:
            p[i], p[j] = p[j], p[i]

print ('NO')

Solution (Python):
N=int(input())
P=input().split(" ")

c=0
for i in range(N):
  if int(P[i])!=i+1:
    c+=1

if c==2 or c==0:
  print("YES")
else:
  print("NO")

Solution (Python):
n = int(input())
p = list(map(int, input().split()))

v = sorted(p)
cou=0
for i in range(n):
    if not p[i] == v[i]:
        cou+=1

if cou <= 2:
    print("YES")
else:
    print("NO")

Solution (Python):
n = int(input())
p = list(map(int, input().split()))
 
q = sorted(p)
cou = 0
for i in range(n):
    if p[i] != q[i]:
        cou += 1
 
if cou <= 2:
    print("YES")
else:
    print("NO")

Solution (Python):
N = int(input())
P = list(map(int, input().split()))

total = 0
for i, p in enumerate(P):
	if p != i+1:
		total += 1

if total <= 2:
	print("YES")
else:
	print("NO")

Solution (Python):
N = int(input())
P = [int(p) for p in input().split()]
 
num = 0
for i in range(N):
    if P[i] == i+1:
        num += 1
 
if num >= N-2:
    print("YES")
else:
    print("NO")

Solution (Python):
n = int(input())
li = list(map(int,input().split()))
count = 0
for i in range(n):
  if li[i] != i+1:
    count += 1
if count == 0 or count==2:
  print("YES")
else:
  print("NO")

Solution (Python):
n = int(input())
p = [int(e) for e in input().split(' ')]

tmp = sorted(p)

count = 0
for i in range(len(p)):
    if p[i] != tmp[i]:
        count += 1

if count == 2 or count == 0:
    print('YES')
else:
    print('NO')

Solution (Python):
n = int(input())
arr = list(map(int, input().split()))

ooo = 0

for i in range(0, n):
    if arr[i] != i+1:
        ooo += 1

if (ooo > 2):
    print('NO')
else:
    print('YES')

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]
b=[i+1 for i in range(n)]
ct=0
for i in range(n):
    if(a[i]!=b[i]):
        ct+=1
if(ct==0 or ct==2):
    print('YES')
else:
    print('NO')

Solution (Python):
n = int(input())
ps = map(int, input().split())

swap = 0
done = False
ok = True
for i in range(n):
    p = next(ps)
    if p != i+1:
        if done:
            ok = False
            break
        elif swap != 0:
            if swap == i+1:
                done = True
                swap = 0
            else:
                ok = False
                break
        else:
            swap = p

if ok:
    print("YES")
else:
    print("NO")

Solution (Python):
import sys
from collections import deque
input = sys.stdin.readline

N = int(input())
p = list(map(int, input().split()))
counter = 0

for i in range(N):
    if p[i] != i+1:
        counter += 1

if counter == 2 or counter == 0:
    print('YES')
else:
    print('NO')

Solution (Python):
N = int(input())
P = list(map(int,input().split()))

ans = 0
flug = 0

for i in range(N):
  if P[i] != i+1:
    ans += 1
      
if ans <= 2:
  print("YES")
elif ans >= 3:
  print("NO")

Solution (Python):
N = int(input())
p = sum([int(a)-i-1!=0 for i,a in enumerate(input().split())])

if p > 2:
    print('NO')
else:
    print('YES')

Solution (Python):
N = int(input())
p = list(map(int, input().split()))
cnt = 0
for i in range(N):
    if p[i] != i+1:
        cnt += 1

if cnt == 2 or cnt == 0:
    print('YES')
else:
    print('NO')

Solution (Python):
n = int(input())
p = list(map(int, input().split()))

c = 0
for i in range(1, n+1):
  if p[i-1] == i:
    pass
  else:
    c+=1

o = "YES" if c<= 2 else "NO"
print(o)

Solution (Python):
N = int(input())
list = list(map(int,input().split()))

cnt = 0
for i in range(1,N+1):
    if i != list[i-1]:
        cnt += 1

if cnt <= 2:
    print("YES")
else:
    print("NO")

Solution (Python):
N=int(input())
p=list(map(int, input().split()))

counter=0
for i in range(N):
  if p[i]!=int(i+1):
    counter+=1
    
if counter==0 or counter==2:
  print('YES')
else:
  print('NO')

Solution (Python):
N = int(input())
Snew =[]
Sold = list(map(int,input().split()))
Snew = Sold[::1]
Snew.sort()
count = 0
for i in range(N):
  if Sold[i] != Snew[i]:
    count += 1
if count <= 2:
  print("YES")
else:
  print("NO")

Solution (Python):
import sys
input = sys.stdin.readline

n = int(input())
p = list(map(int, input().split()))

mustswap = 0
for i, x in enumerate(p):
    if x != (i + 1):
        mustswap+=1


if mustswap <= 2:
    print('YES')
else:
    print('NO')

Solution (Python):
N = int(input())
nums = list(map(int, input().split()))
sorted_nums = sorted(nums)

diff_count = 0
for i in range(N):
    if nums[i] != sorted_nums[i]:
        diff_count += 1

if diff_count == 0 or diff_count == 2:
    print('YES')
else:
    print('NO')

Solution (Python):

n = int(input())
p = list(map(int, input().split()))

k = 0
for i in range(len(p)):
    if p[i] != i+1:
        k += 1
if k <= 2:
    print("YES")
else:
    print("NO")

Solution (Python):
a = int(input())
b = list(map(int, input().split()))

sorted_b = [i+1 for i in range(a)]

diff = [x-y for (x,y) in zip(sorted_b, b)]

if len([i for i in diff if i != 0]) <= 2:
  print('YES')
else:
  print('NO')

Solution (Python):
N = int(input())
P = list(map(int, input().split()))

check = 0
for i, p in enumerate(P):
    if i + 1 != p:
        check += 1

if (check == 0 or check == 2):
    print('YES')
else:
    print('NO')

Solution (Python):
n = int(input())
p = list(map(int, input().split()))

flag = 0
p_ = sorted(p)
for i in range(len(p)):
    if p_[i] != p[i]:
        if flag > 1:
            print('NO')
            exit()
        flag += 1
print('YES')

Solution (Python):
N = int(input())
P = [int(p) for p in input().split()]

num = 0
for i in range(N):
    if P[i] == i+1:
        num += 1

if num >= N-2:
    print("YES")
else:
    print("NO")