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()))
sorted_p = sorted(p)
cnt = 0
for a, b in p, sorted_p:
    if a != b:
        cnt += 1
if cnt > 2:
    print("NO")
else:
    print("YES")


n = int(input())
p = list(map(int, input().split()))
sorted_p = sorted(p)
cnt = 0
for a, b in zip(p, sorted_p):
    if a != b:
        cnt += 1
if cnt > 2:
    print("NO")
else:
    print("YES")


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()))
q = sorted(p)
cnt = 0
for i in range(n):
    if p[i] != q[i]:
        cnt += 1
if cnt == 2 or cnt == 0:
    print("Yes")
else:
    print("No")

n = int(input())
p = list(map(int, input().split()))
q = sorted(p)
cnt = 0
for i in range(n):
    if p[i] != q[i]:
        cnt += 1
if cnt == 2 or cnt == 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()))

ans = 0

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

print('No' if ans > 2 else 'Yes')

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

ans = 0

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

print('NO' if ans > 2 else '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()))
answer = 0
for i in range(n):
  if p[i]  != (i + 1):
  	answer += 1
  
if answer <= 2:
  print('Yes')
else:
  print('No')

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

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

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


N = int(input())
num_list = list(map(int,input().split()))
 
cnt = 0
for i in range(N):
  if num_list[i]!=i+1:
    cnt+=1
  if cnt>2:
    print("NO")
    break
  if i==N-1:
    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())
arr = list(map(int,input().split()))

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

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

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

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

if count<=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 sys
from collections import deque
import numpy as np
import math
sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def Main():
    n = I()
    p = list(IL())
    flag = 2
    for i in range(1,len(p)):
        if p[i-1]!=p[i]-1:
            flag -= 1
    if flag>=0:
        print('Yes')
    else:
        print('No')
    return

if __name__=='__main__':
    Main()

import sys
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def Main():
    n = I()
    p = list(IL())
    q = sorted(p)
    flag = 3
    for i in range(n):
        if p[i] != q[i]:
            flag -= 1
        if not flag:
            print("NO")
            exit()
    print("YES")
    return

if __name__=='__main__':
    Main()

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=list(map(int,input().split()))
ll=sorted(l)
cnt=0
for l1,l2 in zip(l,ll):
  if l1 != l2:
    cnt+=1
    
print("Yes" if cnt <= 2 else "No")

n=int(input())
l=list(map(int,input().split()))
ll=sorted(l)
cnt=0
for l1,l2 in zip(l,ll):
  if l1 != l2:
    cnt+=1
    
print("YES" if cnt <= 2 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(s) for s in input().split(" ")]

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

print("Yes" if count==0 or count==2 else "No")

N=int(input())
P=[int(s) for s in input().split(" ")]

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

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

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(_) for _ in input().split() ]
ls = [ _ for _ in range(1, n+1) ]
cnt = int()

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

n = int(input())
p = [ int(_) for _ in input().split() ]
ls = [ _ for _ in range(1, n+1) ]
cnt = int()

for i in range(n):
    if p[i] != ls[i]:
        cnt += 1
    
if cnt == 2 or cnt == 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()))

sort_p = sorted(p)
dict_p = {}
isOk = True
for i in range(N):
    if p[i] == sort_p[i]:
        continue
    elif len(dict_p) == 0:
        dict_p[sort_p[i]] = p[i]
    elif p[i] in dict_p:
        continue
    else:
        isOk = False
        break

if isOk:
    print("Yes")
else:
    print("No")

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

sort_p = sorted(p)
dict_p = {}
isOk = True
for i in range(N):
    if p[i] == sort_p[i]:
        continue
    elif len(dict_p) == 0:
        dict_p[sort_p[i]] = p[i]
    elif p[i] in dict_p:
        continue
    else:
        isOk = False
        break

if isOk:
    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()))

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

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

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

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

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

SortedP = P.copy()
SortedP.sort()
count=0
for i in range(N):
    if(P[i]!=SortedP[i]):
        count = count + 1
    if(count>2):
        print("NO")
        break
else:print("Yes")

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

SortedP = P.copy()
SortedP.sort()
count=0
for i in range(N):
    if(P[i]!=SortedP[i]):
        count = count + 1
    if(count>2):
        print("NO")
        break
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())
a = [int(k) for k in input().split()]
cnt = 0
for i in range(n):
  if a[i] != i+1:cnt += 1
print("YES" if k <= 2 else "NO")

n = int(input())
a = [int(k) for k in input().split()]
cnt = 0
for i in range(n):
  if a[i] != i+1:cnt += 1
print("YES" if cnt <= 2 else "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()))
num = 0
for i in range(len(p)):
  if p[i] != i+1:
    num += 1
if num < 2:
  print("YES")
else:
  print("NO")

n = int(input())
p = list(map(int, input().split()))
num = 0
for i in range(len(p)):
  if p[i] != i+1:
    num += 1
if num <= 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):
from copy import copy
n=int(input())
*a,=map(int,input().split())
f=[i for i in range(1,n+1)]
for i in range(n):
	x=copy(a)
	for j in range(i):
		x[i],x[j]= x[j],x[i]
		if x == f:
			print('Yes')
			exit(0)
print('No')


n=int(input())
*p,=map(int,input().split())
wng=0
a=sorted(p)
for i in range(n):
	if a[i] != p[i]:
		wng += 1
print('No' if wng >2 else 'Yes')

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

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=list(map(int,input().split()))
count=0
for i in range(n):
  if l[i]!=i+1:
    count+=1
if count<=2:
  print('Yes')
else:
  print('No')

n=int(input())
l=list(map(int,input().split()))
count=0
for i in range(n):
  if l[i]!=i+1:
    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(intput())
A = list(map(int,input().split()))
B = A.sorted()
dif = 0
for i in range(n):
  if A[i]!=B[i]:
    dif+=1
if dif==0 or dif==2:
  print("YES")
else:
  print("NO")

n = int(input())
A = list(map(int,input().split()))
B = sorted(A)
dif = 0
for i in range(n):
  if A[i]!=B[i]:
    dif+=1
if dif==0 or dif==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())
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')

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


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

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:
		t=arr[x]
		arr[x]=arr[t-1]
		arr[t-1]=t
		break
# print(arr,arr2)
if arr==arr2:
	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):
a = input()
N = int(a)
p = list(map(int,input().split()))

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


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

count = 0
for i in range(N):
    if p[i] != i+1:
        count = count + 1
    if count == 3:
        break
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):
N = int(input())
p = list(map(int, input().split()))
c = 0
for i in range(1, N+1):
    if i == p[i]:
        c += 1
if c == 0 or c == 2:
    print("YES")
else:
    print("NO")

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

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

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

Verdicts: Runtime Error

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):
def check(n, list1): 
    new = [] 
    for i in range(n): 
        new.append(list1[i]) 
          
    new.sort()
    swaps = 0
    for i in range(n): 
        if list1[i] != new[i]: 
            swaps += 1
              
    if swaps == 0 or swaps == 2: 
        return True
    else: 
        return False
  
n = int(input())

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


print(numbers)



if check(n, numbers): 
    print("YES")
else:
    print("NO") 

      


x = int(input())
p = list(map(int, input().strip().split()))
k = sorted(p)
count = 0
for i in range(0,x):
    if p[i] == k[i]:
        count += 1

if (x - count) == 2 or (x - 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):
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]
        print(q)
        if q == r:
            print("YES")
            exit()

print("NO")

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

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()))
ans=list(range(N) + 1)

ans_mix=[]
is_possible = False
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')
    

n=int(input())
p=list(map(int, input().split()))
ans=list(range(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')



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



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())
a = list(map(int,input().split()))
sa = sorted(a)
if a==sa:
  print("Yes")
else:
  for ai,si,i in zip(a,sa,range(n)):
    if ai!=si:
      a[ai-1],a[i]=a[i],a[ai-1]
      break
  if a==sa:
    print("Yes")
  else:
    print("No")

n = int(input())
a = list(map(int,input().split()))
sa = sorted(a)
if a==sa:
  print("YES")
else:
  for ai,si,i in zip(a,sa,range(n)):
    if ai!=si:
      a[ai-1],a[i]=a[i],a[ai-1]
      break
  if a==sa:
    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())
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")

n = int(input())
num_list = list(map(int,input().split()))
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")

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, *p = list(map(int, input().split()))
print(p)
count = 0
for i in range(N):
  if p[i] != i + 1:
    count += 1

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

N, *P = list(map(int, open(0).read().split()))
count = sum(p != i + 1 for i, p in enumerate(P))

print('YES' if count <= 2 else '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()))    
p2 = sorted(p)   

if p == p2:
    print('YES')
else:
    for i in range(1,n-1):
        if p[i] == p2[n-i]:
            p3 = p.remove(p[i],p[n-1])
            p4 = sorted(p3)
            if p3 == p4:
                print('YES')
            else:
                print('NO')
        else:
            print('NO')

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

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

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

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(0, N - 1):
    if p[i + 1] != p[i] + 1:
        count += 1

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

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

print("NO") if count > 2 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()))
nu = [i for i in range(1, n + 1)]
an = 0
print(nu)
for i in range(n):
    if p[i] != nu[i]:
        an += 1
    else:
        pass
if an == 2:
    print("YES")
else:
    print("NO")


n = int(input())
p = list(map(int, input().split()))
nu = [i for i in range(1, n + 1)]
an = 0
for i in range(n):
    if p[i] != nu[i]:
        an += 1
    else:
        pass
if an == 2 or an == 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)
c = 0
for i in range(n):
  if p[i] != q:
    c += 1
print('Yes' if c==2 else 'No')

n=int(input())
p=list(map(int,input().split()))
q=sorted(p)
c = 0
for i in range(n):
  if p[i] != q:
    c += 1
print('Yes' if c<=2 else 'No')


from heapq import heapify
from heapq import heappop
n=int(input())
p=list(map(int,input().split()))
q=p.copy()
heapify(q)
c = 0

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

print('Yes' if c==2 else 'No')

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

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

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

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


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

n = int(input())

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

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


Verdicts: 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):
import sys
n = int(sys.stdin.readline())
p = [int(i) for i in sys.stdin.readline().split()]

if p == sorted(p):
    print('YES')
elif: len(p) == 2:
    print('YES')
else:
    swap_index = []
    for i, v in enumerate(p[:-1]):
        if v > p[i + 1]:
            if len(swap_index) == 0:
                swap_index.append(i)
            else:
                swap_index.append(i + 1)
                break
    if len(swap_index) == 1:
        print('NO')
    p[swap_index[0]], p[swap_index[1]] = p[swap_index[1]], p[swap_index[0]]

    if p == sorted(p):
        print('YES')
    else:
        print('NO')


import sys
n = int(sys.stdin.readline())
p = [int(i) for i in sys.stdin.readline().split()]

if p == sorted(p):
    print('YES')
elif len(p) == 2:
    print('YES')
else:
    swap_index = []
    for i, v in enumerate(p[:-1]):
        if v > p[i + 1]:
            if len(swap_index) == 0:
                swap_index.append(i)
            else:
                swap_index.append(i + 1)
                break
    if len(swap_index) == 1:
        print('NO')
    else:
        p[swap_index[0]], p[swap_index[1]] = p[swap_index[1]], p[swap_index[0]]
        if p == sorted(p):
            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
q = sorted(p)


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

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

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


for i in range(n):
    if p[i] != q[i]:
        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 = list(map(int,input().split()))
x = 0
for i in range(len(n)):
    if n[i]!=i+1:
        x+=1
        
if(x==0 or x==2):print("yes")
else: print("no")


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


n = list(map(int,input().split()))
x = 0
for i in range(len(n)):
    if n[i]!=i+1:
        x+=1
        
if(x==0 or x==2):print("Yes")
else: print("No")


c=int(input())
n = list(map(int,input().split()))
x = 0
for i in range(len(n)):
    if n[i]!=i+1:
        x+=1
        
if(x==0 or x==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):
i = int(input())
l = list(map(int, input().split()))
s = sorted(l)
f = 0

if l == s:
    print('YES')
    exit()

for n in range(i-1):
    if l[n] == s[n]:
        continue
    else:
        f = f + 1
        continue

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

i = int(input())
l = list(map(int, input().split()))
s = sorted(l)
f = 0

if l == s:
    print('YES')
    exit()

for n in range(i-1):
    if l[n] == n+1:
        continue
    else:
        f = f + 1
        continue

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

i = int(input())
l = list(map(int, input().split()))
s = sorted(l)
f = 0

for n in range(i):
    if l[n] == n+1:
        continue
    else:
        f = f + 1
        continue

if f == 2:
    print('YES')
elif f == 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):
import numpy as np
n = int(input())
p = np.array(list(map(int, input().split())))

pp = np.array(sorted(p))-p
sum_=0
for i in pp:
  if i!=0: sum_+=1
if sum_>2: print('No')
else: print('Yes')

import numpy as np
n = int(input())
p = np.array(list(map(int, input().split())))

pp = np.array(sorted(p))-p
sum_=0
for i in pp:
  if i!=0: sum_+=1
if sum_>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):
# -*- coding: utf-8 -*-

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

def judge():
    flag = 1
    for j in range(N-1):
        if p[j]>p[j+1]:
            flag = 0
    return flag

if judge() == 0:
    temp_max = max(p)
    ind_max = p.index(max(p))
    ind_min = p.index(min(p))
    p[ind_max] = min(p)
    p[ind_min] = temp_max

if judge() == 1:
    print('Yes')
else:
    print('No')

# -*- coding: utf-8 -*-

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

def judge():
    flag = 1
    for j in range(N):
        if p[j] == j+1:
            continue
        else:
            ch.append(j)
            flag = 0
    return flag,ch

flag,ch = judge()

if flag == 0:
    temp = p[ch[0]]
    p[ch[0]] = p[ch[1]]
    p[ch[1]] = temp

flag,ch = judge()

if flag== 1:
    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())
ar=list(map(int,input().split()))
cnt=0
for i in range(n):
    for j in range(i,n):
        if(ar[i]>ar[j]):
            cnt+=1
if(cnt<=1):
    print("YES")
else:
    print("NO")


n=int(input())
ar=list(map(int,input().split()))
def srt(ar):
    return ar==sorted(ar)
b=0
if(srt(ar)):b=1
for i in range(n):
    for j in range(i,n):
        ar[i],ar[j]=ar[j],ar[i]
        if(srt(ar)):b=1
        ar[i],ar[j]=ar[j],ar[i]
if(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):
#B
import numpy as np
import sys

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

if all(p==p_s):
    print("YES")
else:
    diff = p_s - p
    diff_index = np.where(diff!=0)
    #print(diff_index[0][1])
    if len(diff_index[0]) != 2:
        print("NO")
    else:
        p0 = p[diff_index[0][0]]
        p[diff_index[0][0]] = p[diff_index[0][1]]
        p[diff_index[0][1]] = p0
        if all(p == p_s):
            print("YES")
        else:
            print("NO")  

import numpy as np
import sys

n = int(input())
p = np.array(list(map(int, input().split())))
p_s = np.array(sorted(p))

if all(p==p_s):
    print("YES")
else:
    diff = p_s - p
    diff_index = np.where(diff!=0)
    #print(diff_index[0][1])
    if len(diff_index[0]) != 2:
        print("NO")
    else:
        p0 = p[diff_index[0][0]]
        p[diff_index[0][0]] = p[diff_index[0][1]]
        p[diff_index[0][1]] = p0
        if all(p == p_s):
            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())
A=list(map(int,input().split()))
B=sorted(A)
count=0
for i in range(N):
    if A[i]!=B[i]:
        count+=1
if count<=2:
    print("Yes")
else:
    print("No")

N=int(input())
A=list(map(int,input().split()))
B=sorted(A)
count=0
for i in range(N):
    if A[i]!=B[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+=list(map(int,input().split()))
for i in range(n-1):
  if a[i]!=i+1:
    c+=1
print("YES" if c<3 else "NO")
  


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

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


n=int(input())
a=[0]
a+=list(map(int,input().split()))
a.append(n)
c=0
idx = list()
for i in range(n+1):
  if a[i]>a[i+1]:
    idx.append(i)
    c+=1
print("YES" if c<2 or c==2 and a[idx[0]-1]<a[idx[1]+1]<a[idx[0]+1] and a[idx[1]]<a[idx[0]]<a[idx[1]+2] else "NO")
  


n=int(input())
a=list(map(int,input().split()))
c=0
idx = list()
for i in range(n-1):
  if a[i]>a[i+1]:
    idx.append(i)
    c+=1
print("YES" if c<2 or c==2 and a[idx[0]-1]<a[idx[1]+1]<a[idx[0]+1] and a[idx[1]]<a[idx[0]]<a[idx[1]+2] else "NO")
  


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 < 3 else "No")


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 < 3 else "NO")

Verdicts: Runtime Error

Wrong Answer

Runtime Error

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 = int(input())
pn = [int(i) for i in input().split()]
cnt = 0

for i in range(1,n+1):
  if i != pn[i-1]:
    cnt += 1
if cnt > 2:
  print('No')
else:
  print('Yes')

n = int(input())
pn = [int(i) for i in input().split()]
cnt = 0

for i in range(1,n+1):
  if i != pn[i-1]:
    cnt += 1
if cnt == 2:
  print('NO')
else:
  print('YES')

n = int(input())
pn = [int(i) for i in input().split()]
cnt = 0

for i in range(1,n+1):
  if i != pn[i-1]:
    cnt += 1
if cnt > 2:
  print('NO')
else:
  print('YES')

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,*x=map(int,open(0).read().split())
soreted_x=sorted(x)
cnt=0
for a,b in zip(x,soreted_x):
  if a != b:
    cnt+=1
print('Yes' if cnt==2 else 'No')

n,*x=map(int,open(0).read().split())
soreted_x=sorted(x)
cnt=0

for a,b in zip(x,soreted_x):
  if a != b:
    cnt+=1

print('YES' if cnt<=2 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())
l=list(map(int,input.split()))
lis=l.sorted()
lis.reverse()
ans=0
for i ,j in zip(l,lis):
    if i!=j:
        ans+=1
if ans==2:
    print("YES")
else:
    print("NO")

n=int(input())
l=list(map(int,input().split()))
lis=sorted(l)

ans=0
for i ,j in zip(l,lis):
   
    if i!=j:
        ans+=1
if ans<=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())
lst = list(map(int, input().split()))
lst2 = sorted(lst)
sum = 0
for i in range(N):
  if (lst[i] != lst2[i]):
    sum += 1
if (sum == 0 and sum == 2):
  print('YES')
else:
  print('NO')


import copy

N = int(input())
lst = list(map(int, input().split()))
lst2 = sorted(lst)
sum = 0
for i in range(N):
  if (lst[i] != lst2[i]):
    sum += 1
if (sum == 0 or sum == 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 = map(int, input().split())
b = a.sorted()
c = list(filter(a[i]!=b[i], range(len(a)))
print('YES' if len(c)==2 else 'NO')

n = int(input())
a = list(map(int, input().split()))
b = sorted(a)
c = list(filter(lambda i: a[i]!=b[i], range(n)))
print('YES' if len(c) in [0,2] else '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()))
C = list(range(1, n+1, 1))

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

if cnt == 0 or cnt == 2 : 
    print("Yes")
else : 
    print("No")

n = int(input())
P = list(map(int, input().split()))
C = list(range(1, n+1, 1))

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

if cnt == 0 or cnt == 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(j) for j in input().split()]
s=range(n)
x=0
  
c=0

for a in range(n):
  if p[a]!=s[a]:
    c=c+1
  

if c>2:
  print('NO')
  
if c<=2:
  print('YES')

n=int(input())
p=[int(j) for j in input().split()]
s=range(n+1)
x=0
  
c=0

for a in range(n):
  if p[a]!=s[a+1]:
    c=c+1
  

if c>2:
  print('NO')
  
if c<=2:
  print('YES')

Verdicts: Wrong Answer

Accepted