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 numpy as np
N=int(input())
ps=np.array(list(int(i) for i in input().split())  )

arr=np.arange(1,N+1,1)

flag=np.sum(ps==arr)

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

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

sortList = []
for i in range(1,N+1):
        sortList.append(i)

count = 0
for i in range(N):
        
        if (int(P[1][i]) != int(sortList[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()))

k = []
for i in range(len(p)):
    if p[i] != i+1:
        k.append(i)
if len(k) == 2 or len(k) == 0:
    print('YES')
else:
    print('NO')

Solution (Python):
a = int(input())
ay = list(map(int, input().split()))
count = 0 

for i in range(0,a):
  if ay[i]  != i + 1:
    count += 1

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

Solution (Python):
n=int(input())  
c=list(map(int, input().split()))  
a = 0
b=sorted(c)

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

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

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

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

P = list(range(1, N+1))

diff = 0

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

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

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

E = list(range(1,N+1))

d = [0 if p == e else 1 for p, e in zip(P, E)]

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

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

P = sorted(p)
cnt = 0
for a, b in zip(p, P):
    if a != b:
        cnt += 1

    if cnt > 2:
        print("NO")
        exit()

print("YES")

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

count = 0

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

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

Solution (Python):


if __name__ == "__main__":
    N = int(input())
    p_num = list(map(int, input().split()))

    is_change = [el1 for (el1, el2) in zip(p_num, range(1, len(p_num)+1)) if el1 != el2]

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

Solution (Python):
N = int(input())
l = [int(i) for i in input().split()] 
ll = sorted(l)

c = 0
for i in range(len(l)):
    if (l[i] != ll[i]):
        c += 1

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

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

flg = 0
for i in range(N):
    if i+1 != l[i]:
        flg += 1
        l[l[i]-1] = l[i]
    if flg >= 2:
        print('NO')
        sys.exit()
print('YES')

Solution (Python):
n = input()
puts = input()
Data = puts.split()
offset = 0

for i in range(int(n)):
	if (i+1 != int(Data[i])):
		if offset != 2:
			offset +=1
		else:
			print('NO')
			exit()

print('YES')

Solution (Python):
N = int(input())
P = input().split()
P = [int(s) for s in P]
T = range(1, N+1)
count=[]
for i in range(N):
  if P[i] != T[i]:
    count.append(i)
if len(count) != 2 and len(count) != 0:
  print("NO")
elif len(count) == 0:
  print("YES")
else:
  P[count[0]], P[count[1]] = P[count[1]], P[count[0]]
  if list(T) == P:
    print("YES")
  else:
    print("NO")

Solution (Python):



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

a=0
p2 = sorted(p)

for i in range(n):
    if p[i] != p2[i]:
        a += 1
if(a <= 2):
    print('YES')
else:
    print('NO')

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

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

Solution (Python):
import copy

N = int(input()) 
s = list(map(int, input().split()))
s2 = copy.deepcopy(s)
s.sort()
n = 0
for i in range(0, len(s)):
    if s[i] - s2[i] != 0:
        
        n+=1

if n == 2:
  print("YES")
elif n == 0:
    print("YES")
else:
  print("NO")

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

for i in range(N):
    if s[i]-new_s[i]!=0:
        count += 1

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

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

num_buf = []
idx_buf = []

for i in range(n):
    if i+1 != p[i]:
        num_buf.append(p[i])
        idx_buf.append(i)


if len(idx_buf)==0:
    print("YES")
elif len(idx_buf) == 2 and num_buf[0] == idx_buf[1] + 1:
    print("YES")
else:
    print("NO")

Solution (Python):

N = int(input())

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

dis = True
count = 0
for i in range(0, N-1):
    if A[i] > A[i+1]:
        count += 1
        dis = False
        if count == 1:
            tmp1 = i
        elif count == 2:
            tmp2 = i+1

if dis == False and count > 1:
    tmp = A[tmp1]
    A[tmp1] = A[tmp2]
    A[tmp2] = tmp

    count = 0
    for i in range(0, N-1):
        if A[i] > A[i + 1]:
            count += 1
            dis = False
            if count == 1:
                tmp1 = i
            elif count == 2:
                tmp2 = i + 1
    if count == 0:
        dis = True

if dis == True:
    print('YES')
else:
    print('NO')

Solution (Python):
import copy
n=int(input())
p=list(map(int,input().split()))
sortp=sorted(p)
cnt=0
for i in range(n):
    if p[i]==sortp[i]: cnt+=1
if cnt==n or cnt==n-2:
    print("YES")
else: print("NO")

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

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

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

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

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

if count > 2:
    print("NO")
else:
    print("YES")

Solution (Python):
LARGE = 10 ** 9 + 7


def solve_a(test=False, a=2, b=16):

    if not test:
        a, b = map(int, input().split())
    if (b - a) % 2 == 0:
        print((a + b) // 2)
    else:
        print("IMPOSSIBLE")


def solve_b(test=False, n=5, p_list=[5, 2, 3, 4, 1]):

    if not test:
        n = int(input())
        p_list = list(map(int, input().split()))

    r = 0
    for i in range(n):
        if p_list[i] != i + 1:
            r += 1
    if r == 0 or r == 2:
        print("YES")
    else:
        print("NO")


def solve_c(test=False, n=2, a_list=[3, 5, 2], b_list=[4, 5]):

    if not test:
        n = int(input())
        a_list = list(map(int, input().split()))
        b_list = list(map(int, input().split()))

    res = 0
    for i in range(n):
        if b_list[i] <= a_list[i]:
            res += b_list[i]
            a_list[i] -= b_list[i]
        elif b_list[i] < a_list[i] + a_list[i + 1]:
            res += b_list[i]
            a_list[i + 1] -= b_list[i] - a_list[i]
            a_list[i] = 0
        else:
            res += a_list[i] + a_list[i + 1]
            a_list[i] = 0
            a_list[i + 1] = 0

    print(res)


def solve_d(test=False, s='??2??5'):

    if not test:
        s = input()

    l = len(s)
    res_list_new = [0] * 13
    res_list_old = [0] * 13
    zero_mod = int(s.replace('?', '0')) % 13
    res_list_new[zero_mod] += 1

    for i in range(1, l + 1):
        if s[-i] == '?':
            for k in range(13):
                res_list_old[k] = res_list_new[k] % LARGE
            base_mod = pow(10, i-1, 13)
            for j in range(1, 10):
                for k in range(13):
                    res_list_new[(k + base_mod * j) % 13] += res_list_old[k]

    print(res_list_new[5] % LARGE)



















solve_b()

Solution (Python):
def swap(i, j, arr):
    a = arr[:]
    temp = a[i]
    a[i] = a[j]
    a[j] = temp
    return a

n = int(input())
p = [int(i) for i in input().split()]
a = [int(i) for i in range(1, n+1)]
found = False
if p == a:
    found = True
    print('YES')
else:
    for i in range(n):
        for j in range(i+1, n):
            if swap(i, j, p) == a:
                found = True
                print('YES')
                break
if not found:
    print('NO')

Solution (Python):


import sys

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
        lines.append(input())
        token = lines[0].split()
        n = int(token[0])
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]
        token = lines[0].split()
        n = int(token[0])

    a = [int(i) for i in lines[1].split(" ")]

    return (n, a)


def solve(n, a):

    b = a.copy()
    b.sort()

    if a == b:
        return "YES"

    result = "NO"
    for i in range(0, n):
        for j in range(i+1, n):
            if a[i] > a[j]:
                c = a.copy()
                c[i], c[j] = c[j], c[i]
                if b == c:
                    result = "YES"
                    break

    return result


def main():
    

    print("%s" % solve(*parse_input()))

if __name__ == '__main__':

    main()

Solution (Python):
N = int(input())
i = 0
a = 0
list = input().split()

while i < N:
  if not int(list[i]) == i+1:
    a += 1
  i += 1
if a == 0 or a == 2:
  print('YES')
else:
  print('NO')

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

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
import sys, math, bisect, random, itertools
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')


def A():
    a, b = LI()
    if (a + b) % 2:
        print("IMPOSSIBLE")
        return
    print((a + b) // 2)
    return


def B():
    n = II()
    p = LI()
    for j in range(n - 1):
        if p[j] > p[j + 1]:
            break
    else:
        print("YES")
        return
    for i in range(n):
        for k in range(i+1, n):
            pi = p[::1]
            pi[i], pi[k] = pi[k], pi[i]
            for j in range(n-1):
                if pi[j] > pi[j + 1]:
                    break
            else:
                print("YES")
                return
    print("NO")
    return


def C():
    n = II()
    a = LI()
    b = LI()
    ans = 0
    for i in range(n):
        if a[i] >= b[i]:
            ans += b[i]
            continue
        ans += a[i]
        b[i] -= a[i]
        if a[i + 1] >= b[i]:
            ans += b[i]
            a[i + 1] -= b[i]
            continue
        ans += a[i + 1]
        a[i + 1] = 0
    print(ans)
    return


def D():
    s = S()
    s = s[::-1]
    dp = [[0] * 13 for _ in range(len(s))]
    remain = 1
    if s[0] == "?":
        for i in range(10):
            dp[0][i] = 1
    else:
        dp[0][int(s[0])] = 1
    for i in range(1, len(s)):
        remain = (remain * 10) % 13
        dpi = dp[i]
        dpi1 = dp[i-1]
        if s[i] == "?":
            for k in range(10):
                for j in range(13):
                    dpi[(j + remain * k) % 13] += dpi1[j]
                    dpi[(j + remain * k) % 13] %= mod
        else:
            for j in range(13):
                dpi[(j + remain * int(s[i])) % 13] += dpi1[j]
    print(dp[-1][5])
    return


def E():
    return


def F():
    return


if __name__ == '__main__':
    B()

Solution (Python):
n=int(input())
array=list(map(int, input().split()))
correct=list(range(1,n+1))

incorrect=0
for i in range(n):
    if array[i]!=correct[i]:
        incorrect+=1

if incorrect > 2:
    print("NO")
else:
    print("YES")

Solution (Python):
input()
pp = list(map(int, input().split()))
sorted_pp = sorted(pp)
flag = False
if pp == sorted_pp:
    print('YES')
else:
    for i in range(len(pp) - 1):
        for j in range(len(pp) - 1 - i):
            ppp = pp.copy()
            ppp[i] = pp[j + 1 + i]
            ppp[j + 1 + i] = pp[i]
            if ppp == sorted_pp:
                flag = True
                break
    if flag:
        print('YES')
    else:
        print('NO')

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

slist = sorted(plist)
if plist == slist:
    print("YES")
    exit()
cnt =0
for i in range(1,n+1):
    if cnt >= 3:
        print("NO")
        exit()
    elif i != plist[i-1]:
        cnt += 1
print("YES")

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


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

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

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

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

Solution (Python):
x = int(input())
li = list(map(int,input().split()))
li_o = list(range(1,x))

a = 0
for i in range(x-1):
	
	b = 0
	
    
	if int(li[i]) == int(li_o[i]):
		b=b+1
	else:
		a=a+1
	
	
    


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

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

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

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

tmp = [0]*n

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

ans = sum(tmp)

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

Solution (Python):

def input_from_console():
    n = int(input())
    p_list = list(map(int, input().split()))
    return n, p_list


def solve(n, p_list):
    p_list_sorted = sorted(p_list)
    diff_count = 0
    for i in range(len(p_list)):
        if p_list_sorted[i] != p_list[i]:
            diff_count += 1

    if diff_count > 2:
        return 'NO'
    return 'YES'


def main():
    n, p_list = input_from_console()
    print(solve(n, p_list))


if __name__ == "__main__":
    import sys

    if sys.gettrace():  
        check_cases()
    else:
        main()

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

Solution (Python):
n = int(input())
l = list(map(int, input().split())) 
counter = 0

for i in range(len(l)):
  if i+1 != l[i]:
    counter += 1
if counter == 2 or counter == 0:
  print("YES")
else:
  print("NO")

Solution (Python):
import copy
n=int(input())
in_L=list(map(int,input().split()))
cnt=0
tmp_L=copy.copy(in_L)
sort_L=sorted(in_L)

for i in range(n):
    for j in range(n-i):
        tmp_L[i],tmp_L[i+j]=tmp_L[i+j],tmp_L[i]
        if tmp_L==sort_L:
            cnt=True
            break
        else:
            tmp_L=copy.copy(in_L)
            
            
        
if cnt:
    print("YES")
else:
    print("NO")

Solution (Python):
n = int(input())
p = list(map(int, input().split()))
flag = False
for i in range(n):
    for j in range(n):
        p2 = p.copy()
        p2[i], p2[j] = p2[j], p2[i]
        if sorted(p) == p2:
            flag = True
print("YES") if flag else print("NO")

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

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

for i in range(n):
    if(p1[i]==p[i]):
        continue
    else:
        c=c+1

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

Solution (Python):

N = int(input())
x = list(map(int, input().split()))
y = list(range(1,N+1))

cnt = 0
for i in range(N):
  if x[i] != y[i]:
    cnt += 1
    
if cnt > 2:
  print('NO', end='')
else:
  print('YES', end='')

Solution (Python):
N = int(input())
p = list(int(x) for x in input().split())
a = 0
for k in range(N):
    k = k + 1
    if k != p[k - 1]:
        a = a + 1
    if a == 3:
        print("NO")
        break
if k == N:
    print("YES")

Solution (Python):
import copy
a = int(input())
l = [int(x) for x in input().split()]
m = copy.copy(l)
m.sort()
c = 0

for x in range(a):
    if l[x] != m[x]:
        c += 1

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

Solution (Python):
import sys

N = int(input())
p = [int(_) for _ in input().split()]

correct = [int(_) for _ in range(1,N+1)]

res = 0
if p == correct:
    res = 1
else:
    for i in range(N):
      for j in range(i+1,N):
        a = p[:]
        c = a[i]
        a[i] = a[j]
        a[j] = c
        if a == correct:
            res = 1

if res == 1:
    print('YES')
else:
    print('NO')

Solution (Python):
n = int(input())
lists =[]
for i in range(n):
  lists.append(i+1)
list_2=[int(x)for x in input().split()]

count =0
for s in range(n):
  if lists[s]!=list_2[s]:
    count+=1
if count>2:
  print('NO')
else:
  print('YES')

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

Solution (Python):
n = int(input())
P = list(map(int, input().split()))
sorted = sorted(P)
count = 0

for i in range(n):
  if P[i] == sorted[i]:
    count += 1

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

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

q = list(range(1, N+1))

for i, (x, y) in enumerate(zip(p, q)):
    if x != y:
        if p[x - 1] != (i + 1):
            print("NO")
            quit()
        _ = p[x - 1]
        p[x - 1] = x
        p[i] = _
        break

for i, (x, y) in enumerate(zip(p, q)):
    if x != y:
        print("NO")
        quit()


print("YES")

Solution (Python):
import sys

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

so = sorted(li)
cnt = 0

for l, s in zip(li,so):
 if l!=s:
  cnt += 1
  if cnt > 2:
   print("NO")
   sys.exit()
else:
 print("YES")

Solution (Python):
def main():
	import sys
	input = sys.stdin.readline
	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 == 3:
				print('NO')
				sys.exit()
	print('YES')

if __name__ == '__main__':
    main()

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

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

for i in range(N-1):
    if p[i] > p[i+1]:
        cnt += 1
        l.append(i)

if cnt > 2:
    print('NO')
if cnt == 1:
    print('NO')
if cnt == 0:
    print('YES')
if cnt == 2:
    p[l[0]], p[l[1]+1] = p[l[1]+1], p[l[0]]
    cnt = 0
    for i in range(N-1):
        if p[i] > p[i+1]:
            cnt += 1
            l.append(i)
    if cnt == 0:
        print('YES')
    else:
        print('NO')

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

Solution (Python):
n = int(input())
p = [int(x) for x in input().split()]
 
count = 0
index = []
 
for i in range(n-1):
  if p[i] < p[i+1]:
    pass
  else:
    count += 1
    index.append(i)

if count == 0:
  print('YES')
elif count != 2:
  print('NO')
else:
  p[index[0]], p[index[1] + 1] = p[index[1] + 1], p[index[0]]
  sorted_p = sorted(p)
  if p == sorted_p:
    print('YES')
  else:
    print('NO')

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

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

Solution (Python):
N = int(input())
p = [int(i) for i in input().split()]
cnt = 0
a = []

for i in range(N-1):
    if p[i]>p[i+1]:
        cnt+=1

if cnt>2 or cnt==1:
    print("NO")
    exit()
if cnt==0:
    print("YES")
    exit()
else:
    for i in range(N-1):
        if p[i]>p[i+1]:
            a.append(p[i])
            a.append(p[i+1])
if a[0]>a[2] and a[1]>a[3]:
    print("YES")      
else:
    print("NO")

Solution (Python):
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")


def main():
    N = int(input())
    L = list(map(int, input().split()))
    logging.info("Hello!")

    L_sorted = sorted(L)

    counter = 0
    diff = []
    for i in range(N):
        if L[i] != L_sorted[i]:
            counter += 1
            if counter == 3:
                print("NO")
                exit()
            else:
                diff.append(L[i])

    print("YES")

            
if __name__ == "__main__":
    main()

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

sum_p = 0
count = 1

for i in p:
  if i == count:
    count += 1
  else:
    sum_p += 1
    count += 1

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

Solution (Python):
import math
import random 

cnt  = 0

def quick_sort(arr):
    """ クイックソート 
    """
    global cnt

    if len(arr) < 2:
        
        return arr

    
    pivot = math.floor(len(arr)/2)
    pivot_height = arr[pivot]
    left, right = 0, len(arr) - 1

    while(left < right):
        
        while(arr[left] < pivot_height):
            
            left += 1
        while(arr[right] > pivot_height):
            
            right -= 1

        if (left < right):
            
            cnt += 1
            arr[left], arr[right] = arr[right], arr[left]
        else:
            break
    
    arr[:left] = quick_sort(arr[:left])      
    arr[left+1:] = quick_sort(arr[left+1:])  
    return arr


if __name__ == "__main__":
    s=input()	
    li = list(map(int,input().split()))	
    

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

Solution (Python):
def LI(): return list(map(int, input().split()))
n = int(input())
p = LI()
q = [i for i in range(1, n+1)]

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

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

Solution (Python):
N = int((input()))
S = input().split()
s=[]
b=[]

for i in range (N):
  s.append(int(S[i]))

for i in range(N):
  if s[i]==i+1:
    pass
  else:
    b.append(i)

if len(b)<3:
  print("YES")
else:
  print("NO")

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

a = []
a_li = input().split()

for i in range(n):
    a.append(int(a_li[i]))
    
ans = "YES"
cnt = 0
cnt2 = 0

for i in range(n):
    if a[i] != i+1:
        cnt2 += 1
        if a[a[i]-1] != i+1:
            cnt += 1
            
    if (cnt >= 1) or (cnt2 >= 3):
        ans = "NO"
        break
    
print(ans)

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

p = [int(x) for x in input().split(' ')]
sorted_p = sorted(p)
count = 0
for i in range(N):
    if p[i] != sorted_p[i]:
        count += 1
if count == 0 or count == 2:
    print("YES")
else:
    print("NO")

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


wrong_p = []
wrong_idx = []
for i in range(N):
    if ps[i] != i+1:
        wrong_idx.append(i)

if len(wrong_idx) == 0:
    print("YES")
elif len(wrong_idx) > 2:
    print("NO")
elif len(wrong_idx) == 1:
    print("NO")
else:
    if ps[wrong_idx[0]] == wrong_idx[1]+1:
        print("YES")
    else:
        print("NO")

Solution (Python):
from collections import defaultdict
from collections import deque
from string import ascii_uppercase
import sys, bisect, math, heapq

stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N = read_int()[0]
p = read_int()

def solve():
    diff_count = 0
    for i in range(N):
        if p[i] != i + 1:
            diff_count += 1
    if diff_count >= 3:
        return "NO"
    return "YES"

if __name__ == "__main__":
    print(solve())

Solution (Python):

import sys

YES = "YES"  
NO = "NO"  

def solve(N: int, p: "List[int]"):

    if check(p):
        print("YES")
        return

    p1 = p.copy()
    if p[0] > p[1] and p[N-2] > p[N-1]:
        p1[0] = p[N-1]
        p1[N-1] = p[0]

    if check(p1):
        print("YES")
        return

    p2 = p.copy()
    current = p[0]
    for i in range(1, len(p)):
        if current > p[i]:
            p2[i-1] = p[i]
            p2[i] = p[i-1]
        current = p[i]

    if check(p2):
        print("YES")
        return

    p3 = p.copy()
    current = p[0]
    ind = 0
    hoge = [0] * 2

    for i in range(1, len(p)):
        if current > p[i]:
            if ind <= 1:
                hoge[ind] = i + ind - 1
                ind += 1
            else:
                print("NO")
                return
        current = p[i]

    if ind == 0 or ind == 1:
        print("NO")
        return

    p3[hoge[0]] = p[hoge[1]]
    p3[hoge[1]] = p[hoge[0]]
    if check(p3):
        print("YES")
        return
    else:
        print("NO")
        return



def check(p):
    
    current = p[0]
    for i in range(1, len(p)):
        
        if current > p[i]:
            return False
        current = p[i]

    return True


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    p = [ int(next(tokens)) for _ in range(N) ]  
    solve(N, p)

if __name__ == '__main__':
    main()

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

list2 = []
for i in range(1,N + 1):
    list2.append(i)

if list1 == list2:
    print("YES")
    sys.exit()
for i in range(0,N):
    if list1[i] != i+1:
        if i+1 == list1[list1[i]-1]:
            list1[list1[i]-1] = list1[i]
            list1[i] = i+1
            

        if list1 == list2:
            print("YES")
            sys.exit()
        else:
            print("NO")
            sys.exit()

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

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

mod = 1000000007

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

    flag =0
    for i in range(N):
        for j in range(i+1,N):
            l = p[:]
            temp = l[i]
            l[i] = l[j]
            l[j] = temp
            
            
            if l==s or p==s:
                flag=1
            l = p
            

    if flag==1:
        print("YES")
    else:
        print("NO")

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

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

if c == 0 or c == 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 i+1 != p[i]:
        p[i] == i+1
        count += 1

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

Solution (Python):


def solve():
    N = int(input())
    p = [int(i) for i in input().split()]
    p_sort = sorted(p)
    count = 0
    for i in range(N):
        if p[i] != p_sort[i]:
            count += 1
        if count >= 3:
            break
    if count in [0, 2]:
        print("YES")
    else:
        print("NO")


if __name__ == '__main__':
    solve()

Solution (Python):
n = int(raw_input())
p = [int(i) for i in raw_input().split(' ')]
diff = [1 for a, b in zip(sorted(p), p) if a != b]
print 'YES' if len(diff) == 2 or len(diff) == 0 else 'NO'