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.



Sample input:
5
5 2 3 4 1


Sample output:
YES

Submission status: Runtime Error

Solution code:
import copy

N = int(input())
p = [int(i) for i in  input().split()]
true_p = copy.copy(p)
true_p.sort()
used = [False,False,False,False,False]

for j in range(N-1):
    if p[j] <= p[j+1]:
        continue
    elif p[j] > p[j+1] :
        for l in range(j,N-1):
            if p[j] ==p[l]+1 and not used[l] and not used[j]:
                tmp = p[l+1]        
                p[l+1] = p[j]
                p[j] = tmp
                used[l+1] = True
                used[j] = True
                break

if true_p == p :
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
for j in range(N-1):
    if p[j] <= p[j+1]:
        continue
    elif p[j] > p[j+1] :
        for l in range(j,N-1):
            if p[j] ==p[l]+1 and not used[l] and not used[j]:
                tmp = p[l+1]        
                p[l+1] = p[j]
                p[j] = tmp
                used[l+1] = True
                used[j] = True
                break

if true_p == p :
    print("YES")
else:
    print("NO"

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
p=list(map(int,input().split()))
cnt=0
for i in range(len(p)-1):
  if(p[i]>p[i+1]):
    cnt++

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

Submission status: Runtime Error

Solution code:
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")

Submission status: Runtime Error

Solution code:
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 2:
  print("YES")
  exit()
print("NO")

Submission status: Runtime Error

Solution code:
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:
                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:
            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")

Submission status: Runtime Error

Solution code:
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:
        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:
                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:
            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")

Submission status: Runtime Error

Solution code:
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 e==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:
        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:
                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:
            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")

Submission status: Runtime Error

Solution code:
n = int(input())
xn = map(int,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")

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
 
p = list()
 
p = map(int, input().split())
 
k = 0
 
for i in range(0, len(p)-1 ):
  if (p[i] > p[ i + 1 ]):
    k += 1
    
    
if ( k <= 1 ):
  print("YES")
else:
  print("NO")

Submission status: Runtime Error

Solution code:
N = int(input())

p = list()

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

k = 0

for i,number in enumerate(p):
  if (number > p[ i + 1 ]):
    k += 1

if ( k <= 1 ):
  print("YES")
else:
  print("NO")

Submission status: Runtime Error

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

P=sorted(p)
print(p)
print(P)
flag=0

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

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

Submission status: Runtime Error

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

P=sorted(p)

flag=0

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

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

Submission status: Runtime Error

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

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

p_sorted = sorted(p)

diff = 0
for p_elem, p_sorted_elem in zip(p, p_sorted):
  	if p_elem !+ p_sorted_elem:
      	diff += 1

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

Submission status: Runtime Error

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

p_sorted = p.sorted()

diff = 0
for p_elem, p_sorted_elem in zip(p, p_sorted):
  	if p_elem !+ p_sorted_elem:
      	diff += 1

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
N = int(input())
p = list(map(int, input().split()))
i = 0
j = 0
for n in range(N-1):
    if p[n] > p[n+1]:
        if i == 0:
            i = p[n]
        elif j == 0:
            j = p[n+1]
        else:
            print("NO")
            exit()

if i == 0 and j == 0:
    print("YES")
elif j < p[p.index(i)+1] and p[p.index(j)-1] < i:
    print("YES") 
else:
    print("NO")

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
arr=[int(x) for x in input().split(' ')]
arr2=sorted(arr)
for x in range(n):
  if x+1==arr[x]:
    continue
  else:
    swap(arr[x],arr[arr[x]-1])
    break
if arr==arr2:
  print("YES")
else:
  print("NO")

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
p = map(int, input().split())
cnt = 0

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

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

Submission status: Runtime Error

Solution code:
n = int(input())
num_list = list(map(int,input()))

sorted_num_list = sorted(num_list)
cnt = 0
for i in range(len(num_list)):
	if num_list[i] != sorted_num_list[i]:
		cnt += 1
if cnt < 3:
	print("YES")
else:
	print("NO")

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=0
for i in range(n):
  if a[i]==i:
    b+=0
  else:
    b+=1
if b==0or2:
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
import copy

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

q = copy.copy(p)

r = q.sort()

kaisu = 0

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

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

Submission status: Runtime Error

Solution code:
from statistics import mode
import numpy as np
N=input()
p=list(map(int,input().split()))
p=np.array(p)
q=p-np.arange(len(p-1))
q = list(q)
r = len(list(set(q)))
if sum(list(q))==2*mode(q):
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
n = int(input)
p = list(map(int, input().split()))
v = sorted(p)
cou=0
for i in range(n):
    if not p[i] == v[i]:
        cou+=1

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

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

Solution code:
n = int(input)
p = list(map(int, input().split()))
v = sorted(p)
cou=0
for i in range(n):
    if not p[i] == v[i]:
        cou+=1

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

Submission status: Runtime Error

Solution code:
n = int(input)
p = list(map(int, input().split()))
v = sorted(p)
cou=0
for i in range(len(p)):
    if not p[i] == v[i]:
        cou+=1

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

Submission status: Runtime Error

Solution code:
n = int(input)
p = list(map(int, input().split()))
v = sorted(p)
cou=0
if p==v:
    cou =2
else:
    for i in range(len(p)):
        if not p[i] == v[i]:
            cou+=1

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

Submission status: Runtime Error

Solution code:
n = int(input)
p = list(map(int, input().split()))
v = sorted(p)
cou=0
if p==v:
    cou =2
else:
    for i in range(len(p)):
        if not p[i] == v[i]:
            cou+=1

if cou == 2:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
n = int(input)
p = map(int, input().split())
v = sorted(p)
cou=0
if p==v:
    cou =2
else:
    for i in range(len(p)):
        if not p[i] == v[i]:
            print i
            cou+=1

if cou == 2:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
p = map(int, '1 2 3 4 5 6 7'.split())
v = sorted(p)
cou=0
if p==v:
    cou =2
else:
    for i in range(len(p)):
        if not p[i] == v[i]:
            print i
            cou+=1

if cou == 2:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

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

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

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

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

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
input1 = input()
 
row = input1.split('\n')

N = int(row[0])
numbers = row[1].split()

counter = 0

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

Submission status: Runtime Error

Solution code:
n=input()
p=list(map(int,input().split()))
m=0
for i in range(n):
    print(p[p[i]-1])
    if p[i]==i+1 :
        continue
    elif p[p[i]-1]==i+1 and m<2 :
        m+=1
        continue
    else :
        print ("NO")
        exit()
print("YES")

Submission status: Runtime Error

Solution code:
N = int(input())
p = [int(input()) for i in range(N)]
q=[]
cnt=0
for i in range(N):
  q.append(i+1)
for i in range(N):
  if p[i]==q[i]:
    cnt=cnt
  else:
    cnt=cnt+1
if cnt==2:
  print('YES')
else:
  print('NO')

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys
import numpy as np
# n=int(input())  #数値入力 「N」だけの入力のとき
# a,b=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
# c=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
# s=[list(map(int,list(input()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき
def main():
    N=int(input())
    p=list(map(int, input().split()))
    x=np.linspace(1,N,N)
    y=p-x
    y=list(y)
    if y.count(0.0)==N-2:
        print('YES')
    else:
        print('NO')

if __name__=='__main__':
    main()

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
a

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
p = list(map(int, input().split()))
q = sorted(p)
k = 0
for i in range(1, N + 1):
    if p[i] - q[i] != 0:
        k += 1

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

Submission status: Runtime Error

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

k = 0
counter = 1
for e in p:
    if e == counter:
        counter += 1
    else:
        k += 1
        counter += 1

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

Submission status: Runtime Error

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

# 昇順のリスト
asc_l = list(range(1, N))

diff_l = p - asc_l
diff_l.count(0) >= N - 2

Submission status: Runtime Error

Solution code:
n = input()
s = input().split()
s=[int(i) for i in s]
count=-1
for i in range(int(n)//2):
   if s[i] + s[count] ==int(n)+1:
      count-=1
   	else:
      print("No")

if int(n) %2 ==0：
   print("YES")
else:
   if s[count]*2 == n :
    print("YES")
    else:
      print("NO")

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
p = [int(e) for e in input().split()]
cnt = 0
for a,b in zip(p, sorted(p)):
  if a != b:
    cnt +=1
  if cnt >= 3:
    return 'NO'
return 'YES'

Submission status: Runtime Error

Solution code:
    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")

Submission status: Runtime Error

Solution code:
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")

Submission status: Runtime Error

Solution code:
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')

Submission status: Runtime Error

Solution code:
n = int(input())

data = [int(s) for s in input().split()]
count = 0
for i in range(n):
  if (i+!)!= 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()
"""

Submission status: Runtime Error

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

if count == 3:
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
a = [for int(i) in input.split()]
 
count = 0
for i in range(0, len(a)-1):
  if a[i] > a[i+1]:
    count += 1
    if count > 2:
      print('NO')
      break
  
  if i == len(a)-1:
    print('YES')

Submission status: Runtime Error

Solution code:
list = [for int(i) in input.split()]

count = 0
for i in range(0, len(list)-1):
  if list[i] < list[i+1]:
    count += 1
  	
if count > 2:
  print('NO')
else:
  print('YES')

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
nN = int(input())

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

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

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

nFlag = 0
nCnt = 0

for i in range(nN-1):
  if nData[i] > nData[i+1]:
    nCnt += 1

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

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

int main(){
	int N;
	cin >> N;
	vector<int> p(N);
	for(int i=0;i<N;i++)cin >> p[i];
	
	int count=0;
	for(int i=0;i<N;i++){
		if(p[i]!=i+1)count++;
	}
	if(count<=2)cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Submission status: Runtime Error

Solution code:
n = int(input())
p = list(map(int,input().split()))
count=0

for n range(n):
  if p[n+1]-p[n]==1:
  else:
    count+=1
if count>=5:
  print("NO")
else:
  print("YES")

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n,*a=map(int,open(0))
*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")

Submission status: Runtime Error

Solution code:
N = int(input())
p = list(map(int,input().split()))
cou = 0
for i in range(1,N+1):
  if(p[i-1]==n):
    None
  else:
    cou += 1
if (cou>2):
  print("NO")
else:
  print("YES")

Submission status: Runtime Error

Solution code:
n = (int)input()
p = []
for i in range(n):
  p.append((int)input())

def already_sorted(p):
  prev_val = 0
  for i,val in enumerate(p):
    if i==0:
      prev_val = val
    else:
      if prev_val > val:
        return False
  return True

if already_sorted(p):
  print("YES")
else:
  print("NO")

Submission status: Runtime Error

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

for i in range(n):
  if l[i]==n-i:
    print("YES")
  else :
    if l[i]==l[l[i-1]]:
      print("YES")
    else:
      print("No")
  break

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
# stdin
INPUT_SENTENCES = 2
ss = [input() for i in range(INPUT_SENTENCES)]
N = int(ss[0])
p = list(map(lambda x: int(x), ss[1].split()))
rev_index = []
for i in range(N-1):
    if p[i] > p[i+1]:
        if len(rev_index) > 0:
            rev_index.append(i+1)
        else:
            rev_index.append(i)
if len(rev_index) > 0:
    p[rev_index[0]], p[rev_index[1]] = p[rev_index[1]], p[rev_index[0]]
if p == list(range(1,N+1)):
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
# stdin
INPUT_SENTENCES = 2
ss = [input() for i in range(INPUT_SENTENCES)]
N = int(ss[0])
p = list(map(lambda x: int(x), ss[1].split()))
rev_index = []
for i in range(N-1):
    if p[i] > p[i+1]:
        if len(rev_index) > 0:
            rev_index.append(i+1)
        else:
            rev_index.append(i)
elif len(rev_index) > 0:
    p[rev_index[0]], p[rev_index[1]] = p[rev_index[1]], p[rev_index[0]]
if p == list(range(1,N+1)):
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
N = int(input())
A = map(int, input().split())
numbers = []
result = True
for i in A:
  numbers.append(int(i))
  result = sorted(numbers)
  if (result == True):
    print("YES")
    return "YES"
  if (result == False):
    for i in range(len(numbers)):
      for x in range(i+1, len(numbers)):
        numbers2 = numbers[:]
        if swap(numbers2, i, x) == True:
          print("TRUE")
          return "TRUE"
        print("FALSE")
        return "FALSE"


def sorted(list):
    result = True
    for i in range(len(list)):
        if i < len(list) - 1:
            if (list[i] > list[i+1]):
                result = False
    return result


def swap(list, pos1, pos2):
    list[pos1], list[pos2] = list[pos2], list[pos1]
    return sorted(list)

Submission status: Runtime Error

Solution code:
X, A = map(int, input().split("/n))
A = j.split()
numbers = []
result = True
for i in A:
  numbers.append(int(i))
  result = sorted(numbers)
  if (result == True):
    print("YES")
    return "YES"
  if (result == False):
    # numbers2 = numbers[:]
    for i in range(len(numbers)):
      for x in range(i+1, len(numbers)):
        numbers2 = numbers[:]
        if swap(numbers2, i, x) == True:
          print("TRUE")
          return "TRUE"
        print("FALSE")
        return "FALSE"


def sorted(list):
    result = True
    for i in range(len(list)):
        if i < len(list) - 1:
            if (list[i] > list[i+1]):
                result = False
    return result


def swap(list, pos1, pos2):
    list[pos1], list[pos2] = list[pos2], list[pos1]
    return sorted(list)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
f = 0
for i in range(n-1):
	if a[i] > a[i+1]:
      f += 1

print("YES" if f <= 1 else "NO")