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):
N = int(input())
P = list(map(int, input().split()))
dif = 0

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

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

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

Solution (Python):
n = int(input())
L = [i for i in range(1,n+1)]
P = list(map(int,input().split()))
for i in range(n):
    if P[i] !=i+1:
        tmp = P[i]
        P[P[i]-1] = tmp
        P[i] = i+1
        break
if P == L:
    print("YES")
else:
    print("NO")

Solution (Python):
import sys

N = int(input())
L = list(map(int, input().split()))
Ls = sorted(L)

cnt = 0
for i in range(N):
    if L[i] != Ls[i]:
        cnt += 1
    if cnt > 2:
        print("NO")
        sys.exit()

print("YES")

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

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

cnt = 0
for l in range(len(li)):
  if li[l] != li_sorted[l]:
    cnt += 1
    if cnt > 2:
      print('NO')
      exit()
print('YES')

Solution (Python):


n = int(input())

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

for i in range(len(p) - 1):
    pi = p[i]
    if p[i] != i+1:
        if p[p[i] - 1] == i + 1:
            p[i], p[pi - 1] = p[pi - 1], p[i]
            f += 1
        else:
            f = 2

if 0 <= f <= 1:
    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] != i+1:
        count += 1

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

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

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

counter = 0
for i in range(len(numbers)):
    if numbers[i] != sorted_numbers[i]:
        counter += 1

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

Solution (Python):
n=int(input())
p = list(map(int,input().split()))	
ans="NO"
tank=0
check=[(i+1) for i in range(n)]
if(p==check):
    ans="YES"
    
for i in range(n-1):
    for j in range(n-i-1):
        j+=i+1
        tank=p[i]
        p[i]=p[j]
        p[j]=tank
        if(p==check):
            ans="YES"
        tank=p[i]
        p[i]=p[j]
        p[j]=tank
print(ans)

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

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

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

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

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

def is_sorted(li):
  for i in range(len(li)-1):
    if li[i] > li[i+1]:
      return False
  return True

ans = is_sorted(p)

def check():
  for i in range(N-1):
    for j in range(i+1, N):
      new = p[:]
      new[j] = p[i]
      new[i] = p[j]
      if is_sorted(new):
        return True
  return False

if ans:
  print("YES")
else:
  if check():
    print("YES")
  else:
    print("NO")

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

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

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

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

ans = False
for i in range(N):
    for j in range(i, N):
        p[i], p[j] = p[j], p[i]
        for k in range(N):
            if p[k] != k+1:
                p[i], p[j] = p[j], p[i]
                break;
            if k == N-1: ans = True
if ans: print('YES')
else: print('NO')

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

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

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

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

count = 0

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

if count in [0, 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 <= 2:
  print("YES")
else:
  print("NO")

Solution (Python):

N = int(input())
P = list(map(int,input().split()))
Q = P[::]

P.sort()
diff = 0
for i in range(N):
    if P[i] != Q[i]:
        diff+=1
        
if diff <= 2:
    print("YES")
else:
    print("NO")

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

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

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


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

Solution (Python):
import copy
n = int(input())
p = list(map(int,input().split()))
r = list()
for k in range(n):
    r.append(k+1)
if p == r:
    print("YES")
    exit()
for i in range(0,n-1):
    for j in range(i+1,n):
        q = copy.copy(p)
        q[j] = p[i]
        q[i] = p[j]
        if q == r:
            print("YES")
            exit()

print("NO")

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

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

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

if cnt>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
print("YES") if cnt<=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+=1
print("YES" if count==0 or count==2 else "NO")

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

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

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

Solution (Python):
n = int(input())
p = list(map(int, input().split()))
diff = []
for i in range(n):
    if p[i] != i + 1:
        diff.append((i+1, p[i]))
if len(diff) == 0:
    print('YES')
elif len(diff) == 2:
    if diff[0][0] == diff[1][1] and diff[0][1] == diff[1][0]:
        print('YES')
    else:
        print('NO')
else:
    print('NO')

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

Solution (Python):
N = int(input())
P = [int(p) for p in input().split()]
sorted_P = sorted(P)
counter = 0
for p,sp in zip(P, sorted_P):
    if p != sp:
        counter += 1
        if counter > 2:
            print('NO')
            exit()
print('YES')

Solution (Python):

N = int(input())
P = list(map(int, input().split()))
cnt = 0
for i in range(1, N+1):
    if P[i-1] != i:
       cnt += 1 
print("YES" if cnt < 3 else "NO")

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

Solution (Python):
N = int(input())
p = list(map(int,input().split()))
co_list = list(range(1,N+1))
cnt = 0

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

Solution (Python):



def swap_0_1(p):
    num_change = len([i for i in range(len(p)) if p[i] != i+1])
    if num_change in [0, 2]: return True
    return False

def main():
    n = int(input())
    p = list(map(int, input().split()))
    if(swap_0_1(p)): print("YES")
    else: print("NO")

if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
plist = list(map(int,input().split()))
sorted_plist = sorted(plist)
counter = 0
for i in range(N):
    if plist[i]!=sorted_plist[i]:
        counter += 1
if counter in [0,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):
import sys
input = sys.stdin.readline

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

for i in range(n):
    if err == 3:
        print("NO")
        sys.exit()
    if not p[i] == i+1:
        err += 1
print("YES")

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

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

Solution (Python):
import copy
N = int(input())
M = list(map(int,input().split(" ")))
M_sorted=copy.copy(M)
M_sorted.sort()
bool_list=[]
 
for i in range(N):
  if M[i]==M_sorted[i]:
    bool_list.append(False)
  else:
    bool_list.append(True)
if sum(bool_list) in [0,2]:
  print("YES")
else:
  print("NO")

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

Solution (Python):
import copy
N = int(input())
M = list(map(int,input().split(" ")))
M_sorted=copy.copy(M)
M_sorted.sort()
bool_list=[]

for i in range(N):
  if M[i]==M_sorted[i]:
    bool_list.append(False)
  else:
    bool_list.append(True)
if sum(bool_list) in [0,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())
p = list(map(int, input().split()))
cnt = 0
for i in range(n):
  
	if i+1 != p[i]:
		cnt+=1
if cnt == 0 or cnt == 2:
	print("YES")
else:
	print("NO")

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

n = int(input())
l = list(map(int, input().split()))
cnt = 0
for i in range(n):
	if l[i] != 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
list_base = []
index = []
for i in range(n):
    list_base.append(i+1)

for i in range(n):
    if list_base[i] != p[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()))
count = 0
for i, num in enumerate(sorted(p)):
    if num != p[i]:
        count += 1
if count > 2:
    print('NO')
else:
    print('YES')

Solution (Python):
import copy 

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

true_num = copy.deepcopy(num)
true_num = sorted(true_num)

swap_org=[]
swap_true=[]

count=0
for x,y in zip(num,true_num):
    if x != y:
        count += 1
        swap_org.append(x)
        swap_true.append(y)


for i in range(len(swap_org)-1):
    if swap_org[i] == swap_true[i+1] and swap_org[i+1] == swap_true[i]:
            count-=2
if count>0:
    print("NO")
else:
    print("YES")

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

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

new_p = sorted(p)
c = 0

for i in range(len(p)):
    if p[i] != new_p[i]:
        c += 1
if c > 2:
    print('NO')
else:
    print('YES')

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

a = []
for i in range(len(p)-1):
	if p[i]>=p[i+1]:
		a.append(i)
if len(a)==2:
	c = p[a[0]]
	d = p[a[1]+1]
	_p[a[0]]=d
	_p[a[1]+1]=c
	p.sort()
	if _p==p:
		print("YES")
	else:
		print("NO")
elif len(a)==0:
	print("YES")
else:
	print("NO")

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

Solution (Python):
import sys
input = sys.stdin.readline
input()
P = list(map(int, input().split()))

Ps = list(sorted(P))

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

print('YES' if c <= 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 == 3:
            print('NO')
            exit()
print('YES')

Solution (Python):
def getlist():
    return list(map(int, input().split()))

N = int(input())
p = getlist()

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 in range(1,N+1):
    if P[i-1] != i:
        cnt += 1
if cnt <= 2:
    print("YES")
else:
    print("NO")

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

p_sort = sorted(p)
x = 0

for i in range(N):
    if p[i] == p_sort[i]:
        continue
    else:
        x += 1

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

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

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

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

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

Solution (Python):
def solve(l:list):
    count = 0
    for a, b in zip(l, sorted(l)):
        if a != b:
            count += 1
    print("YES") if count <= 2 else print("NO")
    return

def main():
    input()
    l = list(map(int, input().split(" ")))
    solve(l)

if __name__ == "__main__":
    main()

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

ans_mix=[]
is_possible = False

if p==ans:
    is_possible = True

for i in range(0, n-1):
    for j in range(1, n):
        a=ans.copy()
        tmp=a[i]
        a[i]=a[j]
        a[j]=tmp
        if a==p:
            is_possible = True

if is_possible:
    print('YES')
else:
    print('NO')

Solution (Python):
import numpy as np

N=int(input())
p=np.array(list(map(int, input().split())))
q=np.arange(N)+1

temp=np.sum(~(p==q))
if temp==0 or temp==2:
  print('YES')
else:
  print('NO')

Solution (Python):
n = int(input())
l = [int(i) for i in input().split()]
sorted_l = sorted(l)
flag = 0

for num, s_num in zip(l, sorted_l):
  if num != s_num:
    flag += 1

if flag == 0 or flag == 2:
  print("YES")
else:
  print("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 == 0 or count == 2:
  print("YES")
else:
  print("NO")

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

for Pi in p:
    if Pi != n:
        ans += 1
    if ans > 2:
        print("NO")
        exit()
    n += 1
print("YES")

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

P_ = sorted(P)

cnt = 0
for i in range(N):
    if P[i] != P_[i]:
        cnt += 1
if cnt <= 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 i+1 != p[i]:
        cnt += 1
print('YES' if cnt == 0 or cnt == 2 else 'NO')

Solution (Python):
_ = input()
p = list(map(int, input().strip().split(' ')))
print('NO' if sum(1 for a,b in zip(sorted(p),p) if a != b) > 2 else 'YES')

Solution (Python):
import numpy as np
if __name__ == '__main__':
	N = int(input())
	P = np.array(list(map(int, input().split())))
	Tr = np.array([i+1 for i in range(N)])
	ans = Tr - P
	ans = N - np.count_nonzero(ans == 0)
	if ans == 2 or ans == 0:
		print('YES')
	else:
		print('NO')

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


pis = sorted(pi)


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

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

Solution (Python):
import numpy as np
import sys

n = int(input())
p = np.array(list(map(int,input().split())))
p_sort = np.sort(p)

if (p==p_sort).all():
  print("YES")
  sys.exit()

if np.count_nonzero(p!=p_sort)==2:
  print("YES")
else:
  print("NO")

Solution (Python):
n = int(input())
lists = list(map(int,input().split()))
count = 0
num = 1
for sort in lists :
         if num != sort:
                  count += 1
                  num += 1
         else:
                  num += 1
if count >= 3:
         print("NO")
else:
         print("YES")

Solution (Python):
import sys

N = int(input())
for line in sys.stdin:
  p = list(map(int,line.split(' ')))


cnt = 0
for n in range(1,N+1):
  _ = p[n-1]
  if n == _:
    continue
  else:
    cnt += 1
    
if cnt > 2:
  print('NO')
else:
  print('YES')

Solution (Python):
n = int(input())
data = list(map(lambda x: int(x),input().split(" ")))
same_value = 0

for i in range(1, n+1):
  if i == data[i-1]:
    same_value += 1
  else:
    pass

if same_value >= n - 2:
  print("YES")
else:
  print("NO")

Solution (Python):

N=int(input())
P=list(map(int, input().split()))
P1=sorted(P)
P2=[P[i]-P1[i] for i in range(N)]
if P2.count(0)<N-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:
  print('NO')
else:
  print('YES')

Solution (Python):
import sys

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

for i in range(n - 1):
    if p[i] > p[i + 1]:
        break
    if i == n - 2:
        print("YES")
        sys.exit()

for i in range(n):
    for j in range(i + 1, n):
        q = list(p)
        tmp = q[i]
        q[i] = q[j]
        q[j] = tmp
        for k in range(n - 1):
            if q[k] > q[k + 1]:
                break
            if k == n - 2:
                print("YES")
                sys.exit()

print("NO")

Solution (Python):
N = int(input())
P = [int(p) for p in input().split()]
sorted_P = sorted(P)
counter = 0
for i in range(N):
    if P[i] != sorted_P[i]:
        counter += 1
        if counter > 2:
            print('NO')
            exit()
print('YES')

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

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

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

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

counter = 0
for i in range(n):
    if arr[i] != sorted_arr[i]:
        counter += 1
    if counter > 2:
        break

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

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

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

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

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

Solution (Python):
N=int(raw_input())
ary = map(int, raw_input().split())
c_num = 0

for i in range(N):
    if ary[i] != (i+1):
        c_num += 1

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

Solution (Python):
n=input()
p=list(map(int,input().split()))
cnt=0
for i in range(len(p)):
  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()))
ps = sorted(p)

c = 0
ans = 'YES'
for i in range(0, len(p)):
  if p[i] != ps[i]:
    c += 1
    if c > 2:
      ans = 'NO'
      break

print(ans)

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

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

count = 0
for i, p in enumerate(map(int, input().split())):
  if (i + 1) != p:
    count += 1
    
if (count == 0) or (count == 2):
  print('YES')
else:
  print('NO')

Solution (Python):
import numpy as np
n = int(input())
nums = [int(s) for s in input().split()]
for i in range(n -1):
  if nums[i] < nums[i + 1]:
    pass
  else:
    p = nums[i]
    nums[i] = min(nums[i + 1:])
    nums[np.argmin(nums[i + 1:]) + i + 1] = p
    break

if nums == [s + 1 for s in range(n)]:
  print("YES")
else:
  print("NO")

Solution (Python):
num = int(input())
order = []
for i in range(1,num+1):
    order.append(i)


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

cnt = 0
for j in range(num):
    if order[j]!=q_num[j]:
        cnt = cnt+1
    else:
        pass
if cnt <=2:
    print("YES")
else:
    print("NO")

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

cnt = 0

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

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

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

for i in range(n):
    if p[i] != i + 1:
        cnt -= 1
        
print(["NO", "YES"][cnt >= 0])

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

for i in range((n + 1) // 2):
    if p[i] != i + 1:
        cnt -= 1
    if p[n - i - 1] != n - i:
        cnt -= 1
        
print(["NO", "YES"][cnt >= 0])

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

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

err_cnt = 0
cnt = 1

for i in a:
  if i != cnt:
    err_cnt += 1
  cnt += 1

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

Solution (Python):
n = int(input())
ps = list(map(int, input().split()))
pc = sorted(ps)
answer = "YES"
count = 0
for i in range(n):
    if ps[i] != pc[i]:
        count += 1
        if count > 2:
            answer = "NO"
            break

print(answer)

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

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

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

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

Solution (Python):
N = int(input())
L = list(map(int, input().split()))
L_sorted = sorted(L, reverse=False)
subtract = [x - y for (x, y) in zip(L, L_sorted)]
if subtract.count(0) == N-2 or subtract.count(0) == N:
  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):
n=int(input())
p=list(map(int,input().split()))
l=sorted(p)

ans=0

for i in range(0,n):
    if p[i] != l[i]:
        ans+=1
if ans >2:
    print('NO')
else:
    print('YES')

Solution (Python):
from sys import stdin

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
li_re = sorted(li)

point = 0

for i in range(len(li)):
    if li_re[i] != li[i]:
        point += 1

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

Solution (Python):
a=int(input())
b=input().split(" ")
sequence=[]
for i in range(0,a):
    sequence.append(int(b[i]))
error=[]
for q in range(0,a-1):
    if sequence[q]-sequence[q+1]>0:
        error.append(q)
        error.append(q+1)

if len(error)==0:
    print("YES")

elif len(error)==2:
    if a==2:
        print("YES")
    elif error[0]==0:
        if sequence[error[0]+2]-sequence[error[0]]>0:
            print("YES")
        else:
            print("NO")
    elif error[1]==a-1:
        if sequence[error[1]]-sequence[error[1]-2]>0:
            print("YES")
        else:
            print("NO")
    else:
        if  sequence[error[1]]-sequence[error[1]-2]>0 and sequence[error[0]+2]-sequence[error[0]]>0:
            print("YES")
        else:
            print("NO")

elif len(error)==4:
    if error[1]==error[2]:
        if sequence[error[0]]>sequence[error[3]]:
            if error[0]==0 and error[3]==a-1:
                if sequence[error[0]]-sequence[error[3]-1]>0 and sequence[error[0]+1]-sequence[error[3]]>0:
                    print("YES")
                else:
                    print("NO")
            elif error[0]==0:
                if sequence[error[0]+3]-sequence[error[0]]>0:
                    print("YES")
                else:
                    print("NO")
            elif error[1]==a-1:
                if sequence[error[3]]-sequence[error[3]-3]>0:
                    print("YES")
                else:
                    print("NO")
            else:
                if  sequence[error[3]]-sequence[error[3]-3]>0 and sequence[error[0]+3]-sequence[error[0]]>0:
                    print("YES")
                else:
                    print("NO")
    elif sequence[error[0]]-sequence[error[2]]>0 and sequence[error[1]]-sequence[error[3]]>0:
        if error[0]==0 and error[3]==a-1:
            if sequence[error[0]]-sequence[error[3]-1]>0 and sequence[error[0]+1]-sequence[error[3]]>0:
                print("YES")
            else:
                print("NO")
        elif error[0]==0:
            if sequence[error[3]+1]-sequence[error[0]]>0:
                print("YES")
            else:
                print("NO")
        elif error[3]==a-1:
            if sequence[error[3]]-sequence[error[0]-1]>0:
                print("YES")
            else:
                print("NO")
        elif sequence[error[3]]-sequence[error[0]-1]>0 and sequence[error[3]+1]-sequence[error[0]]>0:
            print("YES")
        else:
            print("NO")
    else:
        print("NO")

else:
    print("NO")

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

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

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

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

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

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

Solution (Python):
n = int(input())
xn = [int(x) for x in input().split()]
k = 0
for i in range(1,n+1):
	if xn[i-1] != i:k += 1
        
print("NO" if k > 2 else "YES")

Solution (Python):
n = int(input())
P = list(map(int, input().split()))
for i in range(n):
    for j in range(n):
        P_copy = P.copy()
        P_copy[j], P_copy[i] = P_copy[i], P_copy[j]
        ascending = True
        for k in range(n-1):
            if P_copy[k] > P_copy[k+1]:
                ascending = False
        if ascending:
            print('YES')
            exit()
print('NO')

Solution (Python):

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

index_not_equal_value_counter = 0
yes_or_no_flag = True
for i, v in enumerate(p):
    i = i + 1
    if i != v:
        index_not_equal_value_counter += 1
    if index_not_equal_value_counter > 2:
        yes_or_no_flag = False

if yes_or_no_flag:
    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] != i + 1:
        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):
    if p[i] != i + 1:
        count += 1
 
if count <= 2:
    print('YES')
else:
    print('NO')

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

f = cnt > 2
print ("YNEOS"[f::2])

Solution (Python):
N = int(input())
p = list(map(int, input().split()))
p_sorted = sorted(p)
if sum([p[k] != p_sorted[k] for k in range(N)]) in [0,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")