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):
def check_sort(alist):
    check = None
    for i in range(n-1):
        if alist[i] > alist[i+1]:
            check = [i]
            break
    for i in range(1,n):
        if alist[i] < alist[i-1]:
            temp = i
            break
    for i in range(1,n):
        if alist[i] < alist[i-1]:
            if alist[i] < alist[temp]:
                temp = i
    if check is not None:
        check.append(temp)
    return check
n = int(input())
raw_in = input().split()
alist = [int(x) for x in raw_in]
check_max = alist[0]
check_id = 0
status = check_sort(alist)
if status is None:
    print("YES")
else:
    alist[status[0]], alist[status[1]] = alist[status[1]], alist[status[0]]
    if check_sort(alist) is None:
        print("YES")
    else:
        print("NO")

Solution (Python):
def main():
  n = int(input())
  lst = list(map(int, input().split()))
  
  a = lst.copy()
  a.sort()
  t = 0
  for i in range(n):
    if (lst[i] != a[i]) == True:
      t += 1
  
  if t ==2 or t == 0:
    print("YES")
  else:
    print("NO")
main()

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

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

cnt=0
for i in range(len(itr)):
    if (i + 1) != itr[i]:
        cnt += 1
    if cnt > 2:
        print("NO")
        break
else:
    print("YES")

Solution (Python):
if __name__ == '__main__':
    n = int(input())
    ps = [int(x) for x in input().split()]

    dis = []

    for n, p in enumerate(ps):
        if n + 1 != p:
            dis.append(p)

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

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

c = 0
i = 1
for x in xs:
    if x != i:
        c += 1
    i += 1

if c in [0, 2]:
    print('YES')
else:
    print('NO')

Solution (Python):
n = int(input())
p_n = list(map(int, input().split()))
c = 0
for i, p in enumerate(p_n):
    if i + 1 != p:
        c += 1

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

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

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

    c=p[i]
    p[i], p[c-1] = p[c-1],p[i]

    if(count == 2):
      print("NO")
      exit()

print("YES")
exit()

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

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

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

             

if flag >= n-2:
  print('YES')
else:
  print('NO')

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

Solution (Python):
import numpy as np

N = int(input())
p_raw = np.array(list(map(int, input().split())))
p_sort = np.sort(p_raw)

compare = (p_raw==p_sort)

if np.count_nonzero(compare == False) > 2:
  print('NO')
else:
  print('YES')

Solution (Python):


n = int(input())

numbers = list(map(int, input().split(" ")))
a = int(numbers[0])
b = int(numbers[1])

cnt = 0

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

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

Solution (Python):
import sys

N=int(input())
plist=list(map(int,input().split()))

def isAsc(lst):
  for i in range(len(lst)-1):
    if lst[i]>lst[i+1]:
      return False
  else:
    return True

if isAsc(plist):
  print("YES")
  sys.exit()

for i in range(N-1):
  for j in range(i+1,N):
    p2list=plist[:]
    p2list[i],p2list[j] = plist[j],plist[i]
    
    if isAsc(p2list):
      print("YES")
      sys.exit()
      
print("NO")

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

B = sorted(P)
   
tmp = 0
for i in range(N):
    if P[i] != B[i]:
        tmp += 1
        
if tmp == 2 or tmp == 0:
    print('YES')
else:
    print('NO')

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

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

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

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

sorted_p_list = sorted(p_list)

count = 0
flag = True

if sorted_p_list == p_list:
    print("YES")
else:
    for i in range(n):
        if sorted_p_list[i] != p_list[i]:
            count += 1
            if count > 2:
                print("NO")
                flag = False
                break

    if flag: print("YES")

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

data = [int(s) for s in input().split()]
count = 0
for i in range(n):
  if (i+1)!= data[i]:
    count += 1
if count<= 2:
  print("YES")
else:
  print("NO")
    
  
"""
mx = max(data)
mn = min(data)

if (mx == n-1 and mn == 0) or 
  for i in range(1,n-1):
    if data[i] < data[i+1]:
      continue
    else:
      print("No")
      exit()
"""

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

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

Solution (Python):
import numpy as np
print('YES') if np.count_nonzero(np.array(np.arange(1, int(input())+1) != list(map(int, input().split())))) < 3 else print('NO')

Solution (Python):
n = int(input())
p = list(map(int, input().split(' ')))
q = p[:]
q.sort()

diff = 0
for _p, _q in zip(p, q):
    if _p != _q:
        diff += 1

    if diff > 2:
        break

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

Solution (Python):
n = int(input())
p = list(map(int, input().split(' ')))
q = p[:]
q.sort()

diff = 0
for _p, _q in zip(p, q):
    if _p != _q:
        diff += 1

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

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 <= 2:
    print('YES')
else:
    print('NO')

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

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

cnt = 0
for i in range(n):
    if p_l[i] != min(p_l) + i:
        cnt += 1
if cnt == 2 or p_l == sorted(p_l):
    print('YES')
else:
    print('NO')

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

Solution (Python):
import numpy as np

n = int(input())
pn = np.array(list(map(lambda x: int(x), input().split(' '))))
diff = np.count_nonzero(pn != np.arange(1, n + 1, dtype='int'))
print('YES') if diff in [0, 2] else print('NO')

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

k = 0

for i, number in enumerate(list_number):
    if i + 1 != number:
        k += 1

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

Solution (Python):
input()

xs = [int(x) for x in input().split(" ")]
c  = 0

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

if c == 0 or c == 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 i+1 != p[i]:
        counter += 1
if counter <= 2:
    print("YES")
else:
    print("NO")

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

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

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

is_switched = False
for i in range(len(seq)-1):
    if seq[i] <= min(seq[i+1:]):
        continue
    elif seq[i] > min(seq[i+1:]):
        if is_switched:
            print("NO")
            break
        j = seq.index(min(seq[i+1:]))
        seq[i], seq[j] = seq[j], seq[i]
        is_switched = True
else:
    print("YES")

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

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

count = 0

for val in range(s):
    if val+1 != nums[val]:
        count += 1

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

Solution (Python):
N = int(input())
p = list(map(int, input().split()))
err = 0
for i in range(N):
  if p[i] != i+1:
    err += 1
if err == 0:
  print("YES")
elif err == 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 <= 2:
    print('YES')
else:
    print('NO')

Solution (Python):
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

def main():
    N = INT()
    P = LIST()
    count = 0
    for i in range(N):
        if P[i] != i + 1:
            count += 1
    if count == 2 or count < 2:
        YES()
    else:
        NO()

if __name__ == '__main__':
    main()

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

Solution (Python):
import numpy as np

N = int(input())

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

count = 0

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

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

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

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

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

Solution (Python):
N = int(input())
P = list(map(int, input().split()))
count = sum([index + 1 != num for index, num in enumerate(P)])
if count <= 2:
    print("YES")
else:
    print("NO")

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

for _ in range(N):
    if p[_] != p_sorted[_]:
        i += 1
if i <= 2:
    print('YES')
else:
    print('NO')

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

lst_sorted = sorted(lst)

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

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

Solution (Python):
def main():
  n = int(input())
  p = list(map(int, input().split(' ')))
  c = 0
  for i in range(n):
    c += 0 if i+1 == p[i] else 1
  print('YES' if c <= 2 else 'NO')


if __name__ == '__main__':
  main()

Solution (Python):
def main():
  n = int(input())
  p = list(map(int, input().split(' ')))
  c = 0
  if judge(p):
    print('YES')
  else:
    for i in range(n):
      for j in range(i+1, n):
        a = p.copy()
        a[i], a[j] = a[j], a[i]
        if judge(a):
          c += 1
          print('YES')
    if c == 0:
      print('NO')


def judge(l):
  return True if l == sorted(l) else False


if __name__ == '__main__':
  main()

Solution (Python):
a = int(input())
b = list(map(int,input().split()))
c = b.copy()
c.sort()
count = 0
for i in range(a):
    if not b[i] == c[i]:
        count += 1
if count <= 2:
    print('YES')
else:
    print('NO')

Solution (Python):

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

judge = 0

for i in range(N):
    if p[i] != i + 1:
        judge += 1
    else:
        continue
    
if judge <= 2:
    print("YES")
else:
    print("NO")

Solution (Python):
import numpy as np
n = input("")
n = int(n)

exa = list(map(int, input("").split(" ")))

exa2 = np.arange(n)+1
if np.count_nonzero((exa != exa2)) in [0, 2]:
    print("YES")
else:
    print("NO")

Solution (Python):
N = int(input())
P = [0] + [int(_) for _ in input().split()]
count = 0
for i, v in enumerate(P):
    if i != v:
        P[i], P[v] = P[v], P[i]
        break
if sorted(P) == P:
    print('YES')
else:
    print('NO')

Solution (Python):
N = int(input())
nums = [int(x) for x in input().split()]

diff = [n - i - 1 for i, n in enumerate(nums) if n - i - 1 != 0]
if len(diff) == 0:
  print('YES')
elif len(diff) == 2 and sum(diff) == 0:
  print('YES')
else:
  print('NO')

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

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

p_sorted = sorted(p)

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

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

Solution (Python):
n = int(input())
ps = [int(elem) for elem in input().split()]

cnt = 0
for i, p in enumerate(ps):
  if (i + 1) != p:
    cnt += 1
if cnt <= 2:
	print("YES")
else:
	print("NO")

Solution (Python):
import sys

list_len = int(input())
l = list(map(int, input().split()))

sorted_l = sorted(l)

wrong = 0
for i in range(list_len):
    if l[i] != sorted_l[i]:
        wrong += 1
        if wrong > 2:
            print("NO")
            sys.exit(0)

print("YES")

Solution (Python):
mx = int(input())
tmp = input()
nl = tmp.split(" ")
error = 0
for i in range(1,mx+1):
  if int(nl[i-1]) != i:
    error+=1

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

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

Solution (Python):
import numpy as np

N = int(input())

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

pp = np.arange(N)+1

if np.count_nonzero((p != pp)) in [0, 2]:
    print('YES')
else:
    print('NO')

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

Solution (Python):
import sys

N = int(input().strip())
P = list(map(int, input().split()))

cnt = 0
for i in range(N):
    if P[i] != i + 1:
        if P[P[i] - 1] == i + 1:
            cnt += 1
        else:
            print("NO")
            sys.exit(0)

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

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

pp = sorted(p)
for i in range(n):
    for j in range(n):
        tmp = p.copy()
        tmpt = tmp[j]
        tmp[j] = tmp[i]
        tmp[i] = tmpt
        if tmp == pp:
            print("YES")
            exit()
print("NO")

Solution (Python):
import sys

n = int(input())
i = list(map(int, input().split()))
count = 0
for j in range(n):
    if i[j] != j + 1:
        count = count + 1
        if count > 2:
            print("NO")
            sys.exit()

print("YES")

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

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

Solution (Python):
N = int(input())
p = [int(n) for n in input().split()]
X = [n for n in range(1, N+1)]
ans = sum([0 if p==x else 1 for p,x in zip(p,X)])
print("YES" if ans <= 2 else "NO")

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

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

inds = []
for i, num in enumerate(a):
  if num != (i+1):
    inds.append(i)

if len(inds) > 2:
  print("NO")
else:
  print("YES")

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

Solution (Python):
n = int(input())
nlst = list(map(int, input().split()))
cnt = 0
nsort = sorted(nlst)

for i, num in enumerate(nsort):
  if nlst[i] != num:
    cnt += 1

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

Solution (Python):
length = int(input())
unsort_list = list(map(int,input().split()))
sort_list = [i+1 for i in range(length)]


values = [(i,j) for (i,j) in zip(unsort_list,sort_list) if i != j]

if len(values) < 3:
    print('YES')
else:
    print('NO')

Solution (Python):
N=int(input())
p=list(int(i) for i in input().split())
p_sorted=sorted(p)
sum=0
for i in range(N):
  if p[i]==p_sorted[i]:
    sum+=1
if sum==N-2 or sum==N:
  print('YES')
else:
  print('NO')

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

Solution (Python):
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 == 2 or count == 0:
    print('YES')

else:
    print('NO')

Solution (Python):
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")
    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")
            exit()
        else:
            print("NO")
            exit()

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

try:
    E = sum([P[i-1] != i for i in range(1, N+1)])
    if E == 0 or E == 2:
        print("YES")
    else:
        print("NO")
except:
    print("NO")

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

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

x = sorted(m)

count = 0

for i in range(n):
  if m[i] != x[i]:
    if count == 2:
      print("NO")
      exit()
    count += 1
print("YES")

Solution (Python):
N = int(input())
p_list = list(map(int,input().split()))
p_sort = sorted(p_list)
cnt = 0
for i in range(N):
  if p_list[i] != p_sort[i]:
    cnt += 1
if cnt >= 3:
  print("NO")
else:
  print("YES")

Solution (Python):
n = int(input())
p = list(map(int,input().split()))    
a = [0]*n
b = 0  

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

if sum(a) == 0 and (b == 2 or b == 0):
    print('YES')
else:
    print('NO')

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

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

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

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

if __name__ == "__main__":
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
n=int(input())
ps=list(map(int,input().split()))
if sum(1 for p,q in zip(ps, sorted(ps)) if p != q) in (0, 2):
    print('YES')
else:
    print('NO')

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

Tmp = []
Tmp = input().rstrip().split(' ')

nData = [0 for i in range(nN)]

for i in range(nN):
  nData[i] = int(Tmp[i])

nFlag = 0
nCnt = 0

for i in range(nN):
  nTmp = i + 1
  if nData[i] != nTmp:
    nCnt += 1
    nTmp2 = nData[i] - 1
    nTmp3 = nData[nTmp2]
    if nTmp3 != nTmp:
      nCnt += 1
    else:
      nData[nTmp2]=nTmp2+1
  

  
if nCnt < 2:
  print('YES')
else:
  print('NO')

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

N = int(input())
L = [int(v) for v in input().split()]

for i in range(N):
    for j in range(i, N):
        p = [v for v in L]
        p[i], p[j] = p[j], p[i]
        
        f = True
        for k in range(N - 1):
            if p[k] > p[k + 1]:
                f = False
                break
        if f:
            print("YES")
            exit()
            
print("NO")

Solution (Python):
import itertools
import copy
n = int(input())
ps = list(map(int, input().split()))

c = list(itertools.combinations(range(n), 2))

ps_sort = sorted(ps)
if ps == ps_sort:
  print('YES')
  exit()
else:
  for i in range(len(c)):
    nps  = copy.copy(ps)
    nps[c[i][0]], nps[c[i][1]] = nps[c[i][1]], nps[c[i][0]]
    if nps == ps_sort:
      print('YES')
      exit()
  else:
    print('NO')

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

Solution (Python):
n = int(input())
pn = input().split()
asc = range(1,n + 1)
i = 0
for sample, px in zip(asc, pn):
	if sample != int(px): i += 1
      
print("YES" if i <= 2 else "NO")

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

ans = 0

for (i, j) in enumerate(p):
    if not i + 1 == j:
        ans += 1

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

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

a=list(map(int, input().split()))
correct=sorted(a)

p=0
for i in range(n-1):
  for j in range(n-i-1):
    a[i], a[n-j-1] = a[n-j-1], a[i]
    if a == correct:
      p += 1
      
    else:
      pass
    a[i], a[n-j-1] = a[n-j-1], a[i]
    
if p == 1 or a == correct:
  print("YES")
else:
  print("NO")

Solution (Python):
n = int(input())
array = [int(num) for num in input().split()]

sorted_array = sorted(array)
count = 0

for num1, num2 in zip(array, sorted_array):
    if num1 != num2:
        count += 1

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

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

sort_A = sorted (A)
flag = 0
for i in range(n):
    if ( A[i] != sort_A[i] ) :
        flag = flag + 1

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

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

Solution (Python):
n = int(input())
p = list(map(int, input().split()))
cnt = 0
for i, v in enumerate(p):
  if v != i + 1:
    cnt += 1
if cnt <= 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]:
    count+=1
if count==0 or count==2:
  print("YES")
else:
  print("NO")

Solution (Python):
n = int(input())
a=list(map(int,input().split()))
b=[0]*n
cnt=0
for i in range(n):
  b[i]=a[i]-sorted(a)[i]
  if b[i]!=0:
    cnt+=1
if sum(b)==0 and (cnt==2 or cnt==0):
  print('YES')
else:
  print('NO')

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

l_sort = sorted(l)

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

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

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

ans = [i+1 for i in range(N)]
cnt = len([a for a, b in zip(p, ans) if a != b])

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

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

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

if count < 3:
  print('YES')
else:
  print('NO')

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

Solution (Python):
def ok(p):
    n = len(p)
    for i in range(n-1):
        if p[i] > p[i+1]:
            return False
    return True

def solve(n, p):
    if ok(p):
        return "YES"
    for i in range(n):
        for j in range(i+1, n):
            q = p.copy()
            q[i], q[j] = q[j], q[i]
            if ok(q):
                return "YES"
    return "NO"

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

Solution (Python):
N = int(input())
p = [int(i) for i in 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())
p = [int(i) for i in 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())
p = list(map(int, input().split()))

cnt = 0
for i, j in enumerate(p):
    if i + 1 != j:
        cnt += 1

if cnt <= 2:
    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 <= 2:
    print("YES")  
else:
    print("NO")

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

s_p=sorted(p)

cnt=0

for i in range(n):
  if p[i]!=s_p[i]:
    cnt +=1
  else:
    pass

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

Solution (Python):




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


wp = sorted(p)

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

if cnt <= 2:
    ans = "YES"
else:
    ans = "NO"


print(ans)

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

Solution (Python):
input_arr = [input() for i in range(2)]
N = input_arr[0]
p_arr = input_arr[1].split(' ')
 
k = 0
for i in range(len(p_arr)):
    if int(p_arr[i]) == i + 1:
        pass
    else:
        k += 1
if k <= 2:
    print("YES")
else:
    print("NO")

Solution (Python):

import sys

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())
p = list(map(int,input().split()))
p1 = sorted(p)
c = 0
for i in range(n):
    if p[i] != p1[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()))
swap = 0
for i in range(n):
    if p[i] != i+1:
        swap += 1
if swap == 0 or swap == 2:
    print('YES')
else:
    print('NO')

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


import numpy as np
a = list(range(n+1))
a.pop(0)

d = np.array(p) - np.array(a)

z = np.count_nonzero(d)
if z==2 or z==0:
    print("YES")
else:
    print("NO")

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

cnt = 0
flag = True
for i in range(N):
    if P[i] != Ps[i]: cnt += 1
    if cnt > 2:
        flag = False
        break
if flag: print('YES')
else: print('NO')

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

Solution (Python):
N = int(input())
pList = [int(x) for x in input().split()]

q = sorted(pList)

count = 2
for a,b in zip(q,pList):
    if a != b:
        count -= 1

if count < 0:
    print('NO')
else:
    print('YES')

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

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

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

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

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

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

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

Solution (Python):
n,*a=map(int,open(0).read().split())
*l,=range(1,n+1)
c=0
for i in range(n):
    if a[i]!=l[i]:
        c+=1
if c<=2:
    print("YES")
else:
    print("NO")

Solution (Python):



N = int(input())
a = list(map(int, input().split()))
a_sort = sorted(a)
ctr = 0

for i in range(N):
    if a[i] != a_sort[i]:
        ctr += 1

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

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

Solution (Python):


N = int(input())
p = list(map(int, input().split()))
res = 0
for i, j in zip(range(1, N+1), p):
    if i != j:
        res = res + 1
    
print("YES" if res == 0 or res == 2 else "NO")

Solution (Python):
import numpy as np
a=[]


N = int(input())
a =[int(i) for i in input().split()]
a = np.array(a).astype(int)
a = np.where( (a-np.sort(a)) != 0)
if len(a[0]) > 2:
	print("NO")
else:
	print("YES")