TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: 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.

Submission attempts (in order):
N = int(input())
p = list(map(int, input().split()))
count = 0
#print(p)

q = sorted(p)
#print(q)

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

N = int(input())
p = list(map(int, input().split()))
count = 0
#print(p)

q = sorted(p)
#print(q)

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
p = list(map(int,input().split()))
cnt = 0
ans = "Yes"
for i in range(n-1):
    if p[i]+1 != p[i+1]:
        cnt += 1
if cnt >2:
    ans = "No"
print(ans)

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
L = input()

n = 0
for i in range(N):
  if L[i] > L[i+1]:
    n += 1

if n == 1 or n == 0:
  print("YES")
else:
  print("NO")

N = int(input())
L = input()

n = 0
for i in range(N):
  if L[i] > L[i+1]:
    n += 1

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

n = int(input())
p = list(map(int, input().split(" ")))
     
ps = sorted(p)
     
c = len([1 for x,y in zip(p, ps) if x != y])
if c == 2 or c == 0:
  print("YES")
else:
  print("NO")

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())

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

arr2 = sorted(arr)

count = 0 

for i in range(0,n):
  if arr[i] != arr2[i]: count += 1
if count <= 2: print("Yes")
else: print("No")


n = int(input())

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

arr2 = sorted(arr)

count = 0 

for i in range(0,n):
  if arr[i] != arr2[i]: count += 1
if count <= 2: print("YES")
else: print("NO")


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N=int(input())
a=input().split()
for i in range (0,N):
  a[i]=int(a[i])
count=0
for i in range(0,N):
  if a[i]!=i+1:
    count=count+1
if count==2:
  print('Yes')
elif count==0:
  print('Yes')
else:
  print('No')

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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")


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")


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

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


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
p = list(map(int, input().split()))
sorted_p = sorted(p)
flg = False
for i in range(N - 1):
    for j in range(i, N):
        temp_p = p.copy()
        temp = temp_p[i]
        temp_p[i] = temp_p[j]
        temp_p[j] = temp
        if temp_p == sorted_p:
            print('Yes')
            flg = True
            break
    if flg:
        break
else:
    print('No')


N = int(input())
p = list(map(int, input().split()))
sorted_p = sorted(p)
flg = False
for i in range(N - 1):
    for j in range(i, N):
        temp_p = p.copy()
        temp = temp_p[i]
        temp_p[i] = temp_p[j]
        temp_p[j] = temp
        if temp_p == sorted_p:
            print('YES')
            flg = True
            break
    if flg:
        break
else:
    print('NO')


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N = int(input())
P = list(map(int,input().split()))

for i in range(N):
    if P[i] != i+1:
        j = P.index(P[i])
        P[i],P[j] = P[j],P[i]
        break

print("YES" if P == list(range(1,N+1)) else "NO")

# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N = int(input())
P = list(map(int,input().split()))

for i in range(N):
    if P[i] != i+1:
        j = P.index(i+1)
        P[i],P[j] = P[j],P[i]
        break

print("YES" if P == list(range(1,N+1)) else "NO")

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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')

N = int(input())
p = list(map(int, input().split()))
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 or cnt==0:
  print('YES')
else:
  print('NO')

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
p = list(map(int,input().split()))
count = 0

sort_p = sorted(p)

for i in range(n):
  if p[i] != sort_p[i]:
    count += 1
    
if count  == 2:
  print("Yes")
  exit()
elif count == 0:
  print("Yes")
  exit()
else:
  print("No")
  exit()

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

sort_p = sorted(p)

for i in range(n):
  if p[i] != sort_p[i]:
    count += 1
    
if count  == 2:
  print("YES")
  exit()
elif count == 0:
  print("YES")
  exit()
else:
  print("NO")
  exit()


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import sys
N = int(input())
p = list(map(int, input().split()))
q = sorted(p)

count = 0
for i, j in zip(p, q):
    if i != j:
        count += 1
        if count > 2:
            print("No")
            sys.exit()
print("Yes")




import sys
N = int(input())
p = list(map(int, input().split()))
q = sorted(p)

count = 0
for i, j in zip(p, q):
    if i != j:
        count += 1
        if count > 2:
            print("NO")
            sys.exit()
print("YES")




Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
p = list(map(int,input().split()))
N = list(range(1,n+1))
for i in N:
  if N[i-1] != p[i-1]:
    break
if N[i-1] == p[N[i-1]]:
  print("YES")
else:
  print("NO")

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

n = int(input())
p = list(map(int,input().split()))
N = list(range(1,n+1))
for i in N:
  if N[i-1] != p[i-1]:
    j = i
    break
if N[p[i-1]] == p[i-1]:
  print("YES")
else:
  print("NO")

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")

Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())  
c=list(map(int, input().split()))  
d=[i for i in range(1,n+1)]
f=0
for i in range(n):
    if d[i]-d[i]:
        f+=1
if f == 0 or f == 2:
    print("YES")
else:
    print("NO)

n=int(input())  
#n= 5  
c=list(map(int, input().split()))  
#c=[5, 2, 3, 4, 1]
d=[i for i in range(1,n+1)]
f=0
for i in range(n):
    if c[i]-d[i]:
        f+=1
#print(f)
if f == 0 or f == 2:
    print("YES")
else:
    print("NO")

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import copy

N = int(input())
P = list(map(int, input().split()))
X = copy.copy(P)
Y = copy.copy(P)
X.sort()

def f(P):
    for i in range(N):
        for j in range(N):
            P = copy.copy(Y)
            P[i],P[j] = P[j],P[i]

            if X == P:
                return "Yes"
    return "NO"

ans = f(P)
print(ans)

import copy

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

X.sort()
ans = "No"


for i in range(N):
    for j in range(N):
        Y = copy.copy(P)
        Y[i],Y[j] = Y[j],Y[i]

        if Y == P:
            ans =  "Yes"


print(ans)

import copy

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

X.sort()
ans = "No"


for i in range(N):
    for j in range(N):
        Y = copy.copy(P)
        a = copy.copy(P[i])
        b = copy.copy(P[j])
        Y[i] = b
        Y[j] = a
        
        if Y == X:
            ans =  "Yes"


print(ans)

import copy

N = int(input())
P = list(map(int, input().split()))
X = copy.copy(P)
Y = copy.copy(P)
X.sort()

def f(P):
    for i in range(N):
        for j in range(N):
            P = copy.copy(Y)
            P[i],P[j] = P[j],P[i]

            if X == P:
                return "Yes"
    return "NO"

ans = f(P)
print(ans)

import copy

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

X.sort()
ans = "NO"


for i in range(N):
    for j in range(N):
        Y = copy.copy(P)
        a = copy.copy(P[i])
        b = copy.copy(P[j])
        Y[i] = b
        Y[j] = a
        
        if Y == X:
            ans =  "YES"


print(ans)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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")

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")

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")

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
p_list = input().split()

count = 0

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

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


n = int(input())
p_list = input().split()

count = 0

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

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


n = int(input())
p_list = input().split()

count = 0

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

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


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
l = []
l = input().split()
l = list(map(int,l))

list_up = []
for i in range(1,n+1):
    list_up += [i]
print(list_up)
x = 0
for i in range(n):
    if l[i] != list_up[i]:
        x += 1
print(list_up)
if x == 0 or x == 2:
    print("YES")
else:
    print("NO")

n = int(input())
l = []
l = input().split()
l = list(map(int,l))

list_up = []
for i in range(1,n+1):
    list_up += [i]

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

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N= int(input())
p_list = [i for i in map(int,input().split())]
#print(p_list)
a_list = p_list.copy()
b_list = p_list.copy()
#print(a_list)
a_list.sort()
b_list.sort()
#print(a_list)
if p_list == a_list:
  print('YES')
  exit()
max = p_list.index(max(p_list))
min = p_list.index(min(p_list))
x = p_list[min]
p_list[min] = p_list[max]
p_list[max] = x
if p_list == b_list:
  print('Yes')
else:
  print('No')

N= int(input())
p_list = [i for i in map(int,input().split())]
f = 0
for i in range(N):
  #print(i+1,p_list[i])
  if i+1 != p_list[i]:
    f += 1
if f==0 or f==2:
  print('YES')
else:
  print('NO')

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
p_s = list(map(int,input().split()))
cnt = 0
for i,p in enumerate(p_s):
  	if i+1 != p:
      	cnt += 1
    if cnt > 2:
      	break
else:
  	print("YES")
print("NO")

import sys
N = int(input())
p_s = list(map(int,input().split()))
cnt = 0
for i,p in enumerate(p_s):
    if i+1 != p:
  	    cnt += 1
    if cnt > 2:
        break
else:
    print("YES")
    sys.exit(0)
print("NO")


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import numpy as np

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

q = sorted(p)
p, q = np.array(p), np.array(q)

if np.sum(p != q) <= 1: print('YES')
else: print('NO')

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







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

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
p = list(map(int, input().split()))
miss = 0
for i in range(n):
    if i+1 != p[i]:
        miss += 1

if miss > 3:
    print('No')
else:
    print('Yes')

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

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
p = list(map(int,input().split()))
count = 0
for i in range(n):
    if p[i] != i + 1:
        count += 1
if count == 0 or count == 2:
    print('Yes')
else:
    print('No')

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
p = [int(i) for i in input().split()]
ans = 'YES'
k = 0
for i in range(n):
    if p[i] != i + 1:
        if k == 1:
            ans = 'NO'
            break
        else:
            if p[p[i] - 1] == i + 1:    
                k = 1
            else:
                ans = 'NO'
                break

print(ans)

n = int(input())
p = [int(i) for i in input().split()]
ans = 'YES'
k = 0
for i in range(n):
    if p[i] != i + 1:
        if k == 1:
            ans = 'NO'
            break
        else:
            if p[p[i] - 1] == i + 1:    
                p[p[i] - 1] = p[i]
                p[i] = i + 1
                k = 1
            else:
                ans = 'NO'
                break

print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import numpy as np

N = int(input())
p = list(map(int, input().split()))
sort_p = sorted(p)
if p == sort_p:
    print('Yes')
else:
    p = np.array(p)
    sort_p = np.array(sort_p)
    index = np.where(p != sort_p)
    if len(p[index]) == 2:
        p[index[0][0]],p[index[0][1]] = p[index[0][1]],p[index[0][0]]
        p = list(p)
        sort_p = list(sort_p)
        if p == sort_p:
            print('Yes')
        else:
            print('No')
    else:
        print('No')


import numpy as np

N = int(input())
p = list(map(int, input().split()))
sort_p = sorted(p)
if p == sort_p:
    print('YES')
else:
    p = np.array(p)
    sort_p = np.array(sort_p)
    index = np.where(p != sort_p)
    if len(p[index]) == 2:
        p[index[0][0]],p[index[0][1]] = p[index[0][1]],p[index[0][0]]
        p = list(p)
        sort_p = list(sort_p)
        if p == sort_p:
            print('YES')
        else:
            print('NO')
    else:
        print('NO')

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
num = list(map(int, input().split()))
num_sort = sorted(num)
flug = 0
for i in range(n):
  if num[i] == num_sort[i]:
    continue
  else:
    flug += 1
    if flug <= 2:
      continue
    else:
      print("No")
      exit()
print("Yes")

n = int(input())
num = list(map(int, input().split()))
num_sort = sorted(num)
flug = 0
for i in range(n):
  if num[i] == num_sort[i]:
    continue
  else:
    flug += 1
    if flug <= 2:
      continue
    else:
      print("NO")
      exit()
print("YES")

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
*P, = map(int, input().split())
a = 0
for i in range(N):
    if P[i] != i + 1:
        a += 1
if a < 2:
    print("YES")
else:
    print("NO")

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

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

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
s = list(map(int, input().split()))

count = 0
for i in range(n-1):
  if s[i] > s[i+1]:
    count += 1

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

n = int(input())
s = map(int, input().split())

count = 0
for i in range(n-1):
  if s[i] > s[i+1]:
    count += 1

print("YES" if count < 3 else "NO")

n = int(input())
s = input()

count = 0
for i in range(n-1):
  if int(s[i]) > int(s[i+1]):
    count += 1

print("YES" if count < 3 else "NO")

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

Verdicts: Wrong Answer

Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
p = list(map(int,input().split()))
p_s = sorted(p)
cnt = 0
for i in range(n):
  if p[i] != p_s[i]:
    cnt += 1
if cnt > 2:
  print('No')
else:
  print('Yes')

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N=int(input())
List=list(map(int,input().split()))


ma= max(List)
mi = min(List)

maIndex=List.index(ma)
miIndex=List.index(mi)
List[maIndex] = mi
List[miIndex] = ma

List2=sorted(List)


if (List != List2):
    print("No")
else:
    print("Yes")






#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))


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

q = sorted(p)

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


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
P = list(map(int, input().split()))
cnt = 0
for i in range(N-1):
  if i+1 == P[i]:
    continue
  elif i+1 != P[i] and P[P[i]] == i+1:
    cnt = 1
  elif cnt == 0:
    print('NO')
    cnt = 2
    break
print('YES' if cnt!=2)

 = int(input())
P = list(map(int, input().split()))
cnt = 0
for i in range(N-1):
  if i+1 == P[i]:
    continue
  elif i+1 != P[i] and P[P[i]] == i+1:
    cnt = 1
  elif cnt == 0:
    print('NO')
    cnt = 2
    break
if cnt!=2:
  print('NYES')

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

N = int(input())
P = list(map(int, input().split()))
cnt = 0
for i in range(N-1):
  if i+1 == P[i]:
    continue
  elif i+1 != P[i] and P[P[i]] == i+1:
    cnt = 1
  elif cnt == 0:
    print('NO')
    cnt = 2
    break
if cnt!=2:
  print('YES')

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


Verdicts: Runtime Error

Runtime Error

Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
a = [int(x) for x in input().split()]
cnt = 0
for i in range(len(a)):
    if a == sorted(a):
        break
    for j in range(len(a)-1, i, -1):
        if a[j] < a[j-1]:
            a[j], a[j-1] = a[j-1], a[j]
    cnt += 1

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

n = int(input())
a = [int(x) for x in input().split()]
cnt = 0
for i in range(len(a)):
    if l == sorted(l):
        break
    for j in range(len(a)-1, i, -1):
        if a[j] < a[j-1]:
            a[j], a[j-1] = a[j-1], a[j]
        cnt += 1

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

n = int(input())
l = [int(x) for x in input().split()]
s_l = sorted(l)
print("YES" if sum([1 if l[i]!=s_l[i] else 0 for i in range(n)]) <= 2 else "NO")

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
N=int(input())
p=list(map(int,input().split()))

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

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

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

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')

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

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

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

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

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

P=sorted(p)
flag=0

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

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

Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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")


n=input()
p=list(map(int,input().split()))
def func(i,j):
    if i == len(p) :
        return "YES"
    elif p[i]==i+1 :
        return func(i+1,j)
    elif p[p[i]-1]==i+1 and j<2 :
        j+=1
        return func(i+1,j)
    else :
        return "NO"
print(func(0,0))


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
N=int(input())
p=list(map(int, input().split()))
t=1
for i in range(N):
    if t==p[i]:
        t+=1
    else:
        index=p.index(t)
        p[index]=i+1
        p[i]=p[index]
        break

for j in range(N-1):
    if p[j]+1==p[j+1]:
        pass
    else:
        print("NO")
        exit()
print("YES")

N=int(input())
p=list(map(int, input().split()))
B=sorted(p)
for i in range(N):
    if i+1==p[i]:
        pass
    else:
        index=p.index(i+1)
        p[i], p[index]=p[index], p[i]
        break
if p==B:
    print("YES")
else:
    print("NO")

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
p = list(map(int, input().split()))
s = sorted(p)
count = 0

for i, j in zip(p, s):
    if i != j:
        count += 1

if count <= 2:
    print("Yes")
else:
    print("No")

n = int(input())
p = list(map(int, input().split()))
s = sorted(p)
count = 0

for i, j in zip(p, s):
    if i != j:
        count += 1

if count > 2:
    print("No")
else:
    print("Yes")

n = int(input())
p = list(map(int, input().split()))
s = sorted(p)
count = 0

for i, j in zip(p, s):
    if i != j:
        count += 1
        
if count <= 2:
    print("Yes")
else:
    print("No")

n = int(input())
p = list(map(int, input().split()))
s = sorted(p)
count = 0

for i, j in zip(p, s):
    if i != j:
        count += 1

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

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
A = list(map(int, input().split()))
cnt = 0

for i, j in enumerate(A)
  if i + 1 != j:
    cnt +=1
if cnt <= 2:
  print('YES')
else:
  print('NO')
  

n = int(input())
A = list(map(int, input().split()))
cnt = 0
 
for i, j in enumerate(A):
  if i + 1 != j:
    cnt +=1
if cnt <= 2:
  print('YES')
else:
  print('NO')

Verdicts: Runtime Error

Accepted
Problem: 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.

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

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


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

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


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
p = map(int, input().split())
c = 0

for i, v in enumerate(p):
    if i + 1 != v:
        c += 1

if c > 2:
    print("No")
else:
    print("Yes")


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

for i, v in enumerate(p):
    if i + 1 != v:
        c += 1

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


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
p = [int(x) for x in input().split()]
tmp=0
s=0
cnt=0
e=0 

for i in range(0,n-1):
   # print(p[i])
   if p[i] > p[i+1]:
      if i == 0:
         cnt+=1
         s=i
         
      else:
         cnt+=1
         e=i+1
         
   if i == n-1 and cnt==2:
      tmp=p[s]
      p[s]=p[e]
      p[e]=tmp
   
if sorted(p) == p:
   print("YES")
else:
   print("NO")


n = int(input())
p = [int(x) for x in input().split()]
tmp=0
exchange = p 
for i in range(0,n-1):
   # print(p[i])
   if p[i] > p[i+1]:
      if i == 0:
         exchange[i]=p[i]
      else:
         exchange[i+1]=p[i+1]
   
if sorted(exchange) == exchange:
   print("YES")
else:
   print("NO")


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

tmp=0
s=0
cnt=0
e=0 

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


#    if p[i] > p[i+1]:

#          cnt+=1

#       else:
#          cnt+=1

#    if i == n-2 and cnt==2:
#       tmp=p[s]
#       p[s]=p[e]
#       p[e]=tmp
   

#    print("YES")
# else:
#    print("NO")

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N=int(input())
P=list(map(int,input().split()))

Q=[i for i in range(1,N+1)]

count=0
for i in range(N):
  if P[i]!=Q[i]:
    count+=1
if count>=3:
  print("No")
else:print("Yes")

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

Q=[i for i in range(1,N+1)]

count=0
for i in range(N):
  if P[i]!=Q[i]:
    count+=1
if count>=3:
  print("NO")
else:print("YES")

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import numpy as np
def acinput():
    return list(map(int,input().split(" ")))

def bubble_sort(arr):
    global count
    change = True
    while change:
        change = False
        for i in range(len(arr) - 1):
            if arr[i] > arr[i + 1]:
                arr[i], arr[i + 1] = arr[i + 1], arr[i]
                change = True
                count+=1
    return arr

N=int(input())
p=acinput()

count=0

bubble_sort(p)
if count<=1:
    print("YES")
else:
    print("NO")



import numpy as np
def acinput():
    return list(map(int,input().split(" ")))


N=int(input())
p=acinput()

flg="Yes"
for i in range(N-1):
    if p[i]!=(i+1):
        flg="No"
        for j in range(i+1,N):
            if p[j]!=(j+1):
                if (p[i]==j+1) & (p[j]==i+1):
                    flg="Yes"

print(flg)


import numpy as np
def acinput():
    return list(map(int,input().split(" ")))


N=int(input())
p=np.array(acinput())

count=0

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


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



Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
num = int(input())
order = []
for i in range(1,num+1):
    order.append(i)
#print(order)

q_num = list(map(int,input().split()))
#print(q_num)
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")
    

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

q_num = list(map(int,input().split()))
#print(q_num)
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")
    

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

q_num = list(map(int,input().split()))
#print(q_num)
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")
    

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
    input()
    g = input()
    a = list(map(str, g.split()))
    b = list(map(int, g.split()))
    if sorted(b) == b:
        print("YES")
    else:
        m = 0
        for i in range(len(b)):
            if b[i] == sorted(b)[i]:
                m+=1
        if m==len(b)-2:
            print("YES")
        else:
            print("NO")

N=input("enter a number")
list=[]
order=True
check=True
pos=0
temp=0
counter=0
numbers=input("enter the permutation as n digit number")
for number in numbers:
    list.append(int(number))
p0=list[0]


for n in range(1,len(list)):
    #checking is the given permutatoin is in ascendig order or no
    if p0<list[n]:
        p0=list[n]
    else:
        order=False

if order==True:
    print("the given permutation is in ascending order")
if order==False:
    for i in range(1,len(list)+1):
        if i==list[i-1]:
            pass
        else:
            counter+=1
            temp=list[i-1]
            pos=list.index(i)           #swap
            list[i-1]=list[pos]
            list[pos]=temp
if counter==1:
    print("Yes we can sort it in ascending order")
else:
    print("No it cant be sorted in one step")



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


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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')
            exit()
print('YES')


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')


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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==n or p==n-2:
 print("Yes")
else:
 print("No")

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==n or p==n-2:
 print("YES")
else:
 print("NO")

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
nums = [int(N) for N in input().split()]
diff = 0

for i in range(N):
    if (i + 1) != nums[i]:
        diff += 1
    if diff >= 3:
        break

if diff == 0 or diff == 2:
    print('Yes')
else:
    print('No')


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

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

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


Verdicts: Wrong Answer

Accepted