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

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

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 < n-2:
  print("No")
else:
  print("Yes")

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

ans = []
for i in range(1,n+1):
  ans.append(i)

  

for i in range(n):
  for j in range(n):
    a[i] = p[j]
    a[j] = p[i]
    if a == ans:
      print('YES')
      exit()
    else:
      a = list(p)
    print(p)    
      
      
      
    
print('NO')

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

ans = []
for i in range(1,n+1):
  ans.append(i)

  

for i in range(n):
  for j in range(n):
    a[i] = p[j]
    a[j] = p[i]
    if a == ans:
      print('YES')
      exit()
    else:
      a = list(p)
       
      
      
      
    
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 sys import stdin 

n = int(input())
p = [int(x) for x in stdin.readline().rstrip().split()]
c= 0
q = sorted(p)
print(q)
print(p)
for i in range(n):
	if p[i] != q[i]:
		c += 1

if c>2:
	print("NO")

else:
	print("YES")

from sys import stdin 

n = int(input())
p = [int(x) for x in stdin.readline().rstrip().split()]
c= 0
q = sorted(p)
print(q)
print(p)
for i in range(n):
	if p[i] != q[i]:
		c += 1

if c<=2:
	print("YES")

else:
	print("NO")

from sys import stdin 

n = int(input())
p = [int(x) for x in stdin.readline().rstrip().split()]
c= 0
q = sorted(p)
print(q)
print(p)
for i in range(n):
	if p[i] != q[i]:
		c += 1

if c==2 or c==0:
	print("YES")

else:
	print("NO")

from sys import stdin 

n = int(input())
p = [int(x) for x in stdin.readline().rstrip().split()]
c= 0
q = sorted(p)
for i in range(n):
	if p[i] != q[i]:
		c += 1

if c==2 or c==0:
	print("Yes")

else:
	print("No")

from sys import stdin 

n = int(input())
p = [int(x) for x in stdin.readline().rstrip().split()]
c= 0
q = sorted(p)
for i in range(n):
	if p[i] != q[i]:
		c += 1

if c<=2:
	print("Yes")

else:
	print("No")

from sys import stdin 

n = int(input())
p = [int(x) for x in stdin.readline().rstrip().split()]
c= 0
q = sorted(p)
print(q)
print(p)
for i in range(n):
	if p[i] != q[i]:
		c += 1

if c==2 or c==0:
	print("YES")

else:
	print("NO")

from sys import stdin 

n = int(input())
p = [int(x) for x in stdin.readline().rstrip().split()]
c= 0
q = sorted(p)

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

if c>2:
	print("NO")

else:
	print("YES")

Verdicts: Wrong Answer

Wrong Answer

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


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

li = list(map(int,input().split()))
count = 0
judge = True

for i in range(N-1):
    if (li[i] > li[i+1]):
        swp = li[i]
        index_swp = li.index(min(li[i+1:]))
        li[i] = min(li[i+1:])
        li[index_swp] = swp
        count = count + 1
        if(count > 1):
            judge = False
            break
    

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

import copy
N = int(input())
li = list(map(int,input().split()))
ans = copy.copy(li)
ans.sort()

count = 0
judge = True

for i in range(N-1):
    if (li[i] != ans[i]):
        count = count + 1
        if(count > 2):
            judge = False
            break

if(judge):
    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):
#ABC135B
N = int(input())
P = list(map(int, input().split()))
flg = 0
for i in range(0, N):
    if i+1 != P[i]:
        flg += 1
print("Yes" if flg == 0 or flg == 2 else "No")

#ABC135B
N = int(input())
P = list(map(int, input().split()))
flg = 0
for i in range(0, N):
    if i+1 != P[i]:
        flg += 1
print("YES" if flg == 0 or flg == 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())
s = input().split()
print(s)
b =[str(i+1) for i in range(len(s))]
print(b)
count=0
for i in range(len(s)):
  if s[i]!=b[i]:
    count+=1
if count==0: print("YES")
elif count==2: print("YES")
else: print("NO")

n = int(input())
s = input().split()
b =[str(i+1) for i in range(len(s))]
count=0
for i in range(len(s)):
  if s[i]!=b[i]:
    count+=1
if count==0: print("YES")
elif 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,*a=map(int,open(0))
*l,=range(1,n+1)
c=0
for i in range(n):
    if a[i]!=l[i]:
        c+=1
if c<=2:
    print("YES")
else:
    print("NO")
    

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

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

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

correct = [int(_) for _ in range(1,N+1)]

if p == correct:
    print('YES')
else:
    for i in range(N):
      for j in range(i+1,N):
        a = p[:]
        c = a[i]
        a[i] = a[j]
        a[j] = c
        print(a)
        if a == correct:
            print('YES')
            sys.exit()
    else:
        print('NO')

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

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

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

import sys

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

correct = [int(_) for _ in range(1,N+1)]

res = 0
if p == correct:
    res = 1
else:
    for i in range(N):
      for j in range(i+1,N):
        a = p[:]
        c = a[i]
        a[i] = a[j]
        a[j] = c
        print(a)
        if a == correct:
            res = 1

if res == 1:
    print('YES')
else:
    print('NO')

import sys

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

correct = [int(_) for _ in range(1,N+1)]

res = 0
if p == correct:
    print('YES')
else:
    for i in range(N):
      for j in range(i+1,N):
        a = p[:]
        c = a[i]
        a[i] = a[j]
        a[j] = c
        print(a)
        if a == correct:
            res = 1

if res == 1:
    print('YES')
else:
    print('NO')

import sys

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

correct = [int(_) for _ in range(1,N+1)]

res = 0
if p == correct:
    res = 1
else:
    for i in range(N):
      for j in range(i+1,N):
        a = p[:]
        c = a[i]
        a[i] = a[j]
        a[j] = c
        if a == correct:
            res = 1

if res == 1:
    print('YES')
else:
    print('NO')

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

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

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

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

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

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

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==0 or cnt==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):
import sys
N = int(input())
p = input()
list1 = list(map(int,p.split()))

list2 = []
for i in range(1,N + 1):
    list2.append(i)

if list1 == list2:
    print("Yes")
    sys.exit()
for i in range(0,N):
    if list1[i] != i+1:
        if i+1 == list1[list1[i]-1]:
            list1[list1[i]-1] = list1[i]
            list1[i] = i+1
            

        if list1 == list2:
            print("Yes")
            sys.exit()
        else:
            print("No")
            sys.exit()

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

list2 = []
for i in range(1,N + 1):
    list2.append(i)

if list1 == list2:
    print("YES")
    exit()
for i in range(0,N):
    if list1[i] != i+1:
        if i+1 == list1[list1[i]-1]:
            list1[list1[i]-1] = list1[i]
            list1[i] = i+1
            

        if list1 == list2:
            print("YES")
            exit()
        else:
            print("NO")
            exit()

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 = [int(i) for i in input().split()]
mis = 0
for i in range(n):
    if l[i] != i:
        mis += 1
print('YES' if mis<3 else 'NO')

n = int(input())
l = [int(i) for i in input().split()]
mis = 0
for i in range(n):
    if l[i] != i+1:
        mis += 1
print('YES' if mis<3 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, *p = map(int, open(0).read().split())
t = 0
for i in range(n):
    t += 1 if p[i] != sorted(p)[i] 
print("YES" if t == 0 or t == 2 else "NO")

n, *p = map(int, open(0).read().split())
t = 0
for i in range(n):
    t += p[i] != sorted(p)[i]
print("YES" if t == 0 or t == 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())
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")

a = int(input())

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

d = 0
for i in range(a):
  if not p[i] == a-i:
    d += 1
      
print(d)
    
  
if d == 0 or d == 2:
  print("YES")
  
else:
  print("NO)
  

a = int(input())
 
p = list(map(int, input().split()))
 
d = 0
for i in range(a):
  if not p[i] == i+1:
    d += 1
      
 
  
if d  ==0 or d ==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):
import copy

n = int(input())
lst1 = list(map(int,input().split()))
lst2 = copy.copy(sorted(lst1))

c=0
for i in range(n):
    if lst1[i]==lst2[i]:
        pass
    else:
        c+=1
        if c > 2:
            print("No")
            break
print("Yes")

import copy
import sys
n = int(input())
lst1 = list(map(int,input().split()))
lst2 = copy.copy(sorted(lst1))

c=0
for i in range(n):
    if lst1[i]==lst2[i]:
        pass
    else:
        c+=1
        if c > 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):
num = input()
input_list = [int(i) for i in input().split()] 
sorted_list = sorted(input_list)

count = 0
for input, sort in zip(input_list, sorted_list):
  if input != sort:
    count += 1

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

num = int(input())
if num >= 2:
  input_list = [int(i) for i in input().split()] 
  sorted_list = sorted(input_list)

  count = 0
  for input, sort in zip(input_list, sorted_list):
    if input != sort:
      count += 1

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


num = int(input())
if num >= 2:
  input_list = [int(i) for i in input().split()] 
  sorted_list = sorted(input_list)

  count = 0
  for input, sort in zip(input_list, sorted_list):
    if input != sort:
      count += 1

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

a=int(input())
b=list(map(int,input().split()))
c=list(range(1,a+1))
count = 0
for i in range(a):
  if c[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):
x = int(input())
for i in range(x):
  exec("a_%d = int(input())" %(i))
a_list = [eval("a_%d" %(i)) for i in range(x)]
a_list.sort()
be_list = [eval("a_%d" %(i)) for i in range(x)]
count = 0
for i in range(x):
    if a_list[i] == be_list[i]:
      count += 1
if count >= x-2:
  print('YES')
else:
  print('NO')

x = int(input())
a_list = list(map(int,input().split()))
a = sorted(a_list)
count = 0
for i in range(x):
    if a[i] == a_list[i]:
      count += 1
if count >= x-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())
ls_p = list(map(int, input().split()))

cnt = 0

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

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

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

cnt = 0

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

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

#ABC135B - 0 or 1 Swap
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:
    print("YES")
elif count == 2:
    print("YES")
else:
    print("NO")
print(count)

#ABC135B - 0 or 1 Swap
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:
    print("YES")
elif 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):
import sys

n = int(input())

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

ps = sorted(p)

count = 0

for a, b in zip(p, ps):
    print(a, b)
    if(a != b):
        count += 1
    if(count > 2):
        print("NO")
        sys.exit()
        break

print("YES")


import sys

n = int(input())

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

ps = sorted(p)

count = 0

for a, b in zip(p, ps):
    if(a != b):
        count += 1
    if(count > 2):
        print("NO")
        sys.exit()
        break

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

hikaku = list(range(1,n+1))
count = 0
for i in range(n):
    if hikaku[i] != p[i]:
        count += 1
if count >3:
    print("No")
else:
    print("Yes")


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

hikaku = list(range(1,n+1))
count = 0
for i in range(n):
    if hikaku[i] != p[i]:
        count += 1
#print(count)
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,*P,=map(int,open(0).read().split())
A=[a-b for a,b in zip(range(1,N+1),P)]
print('YNeos'[len(set(A))!=1 and len(set(A))!=3::2])

N,*P,=map(int,open(0).read().split())
A=[a!=b for a,b in zip(range(1,N+1),P)]
print('YNEOS'[sum(A)!=0 and sum(A)!=2::2])

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

print('YES' if cnt == 0 or cnt == 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 == 0 or 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(_) for _ in input().split()]
cnt =0
for i in range(2, len(p)):
  if  p[i]-p[i-1] !=1:
    cnt +=1
print('Yes' if cnt <=1 else 'No')

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

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

cnt = 0

Q = sorted(P)

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

if cnt==0 or cnt==2:
    print('yes')
else:
    print('no')
 

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

cnt = 0

Q = sorted(P)

for i in range(N):
    if P[i] != Q[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())
l = list(map(int,input().split()))
tmp = 0

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

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

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

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

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

N = int(input())
l = list(map(int,input().split()))
flag = False
tmp = 0

for i in range(N-1):
  if l[i] <= l[i+1]:
    continue
  elif l[i] > l[i+1] and flag == False:
    tmp = l[i]
    l[i] = l[i+1]
    l[i+1] = tmp
    flag = True
    continue
  else:
    print("NO")
    quit()

print("YES")

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

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

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

L=[]
for i in range(n):
    if i+1 !=p[i]:
        L.append([i, p[i]])
    if len(L)==2:
        break


if len(L)<=1:
    print('Yes')
else:
    p[L[0][0]] = L[1][1]
    p[L[1][0]] = L[0][1]
    if p == sorted(p):
        print('Yes')
    else:
        print('No')

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

L=[]
for i in range(n):
    if i+1 !=p[i]:
        L.append([i, p[i]])
    if len(L)==2:
        break


if len(L)<=1:
    print('YES')
else:
    p[L[0][0]] = L[1][1]
    p[L[1][0]] = L[0][1]
    if p == sorted(p):
        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()))
count = 0

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

if count == 0 or count == 3:
  print('YES')
else:
  print('NO')


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

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

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

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

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

if count == 0 or count == 3:
  print('YES')
else:
  print('NO')

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

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

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


N = int(input())
P = list(map(int, input().split()))
Q = sorted(P)
count = 0

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

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


Verdicts: Wrong Answer

Wrong Answer

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

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

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

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

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

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

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

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

Verdicts: Runtime Error

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

box=[]

for i in range(n-1):
  if i == a[i]:
    pass
  else:
    box.append(i)
if len(box) == 0 or len(box) == 2:
  print('YES')
else:
  print('NO')

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

box=[]
print(a)
print(box)

for i in range(n-1):
  if i == a[i]:
    pass
  else:
    box.append(i)
if len(box) == 0 or len(box) == 2:
  print('YES')
else:
  print('NO')

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

box=[]

for i in range(n):
  if i+1 == a[i]:
    pass
  else:
    box.append(i)
if len(box) == 0 or len(box) == 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 = input()
l = input().split(" ")
ns = []
k = 0
for i in range(int(n)):
  ns.append(i+1)
  if int(l[i]) != ns[i]:
    k += 1
if k <= 2:
  print("Yes")
else:
  print("No")


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

N=int(input())
l=list(range(1,N+1))
a=list(map(int, input().split()))
count=0
for i in range(0, len(l)):
  if l[i]==a[i]:
    count=count+1
if count >= N-2:
  print("Yes")
else:
  print("No")

N=int(input())
l=list(range(1,N+1))
a=list(map(int, input().split()))
count=0
for i in range(0, len(l)):
  if l[i]==a[i]:
    count=count+1
if count >= N-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())
r=list(map(int,input().split()))
a=sorted(r)

r="".join(r)
a="".join(a)

count=0
i=0
while i<len(r):
  if r[i]!=r[i]:count+=1
    
print("Yes" if count<=2 else "No")


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

i=1
count=0
for item in r:
  if item!=i:count+=1
  i+=1

print("YES" if count<3 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):
a = [input().split() for l in range(2)]
N=int(a[0][0])
p=a[1]
print(N)
print(p)
count=0
for i in range(N):
    if int(p[i])!=i+1:
        count=count+1

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


a = [input().split() for l in range(2)]
N=int(a[0][0])
p=a[1]
count=0
for i in range(N):
    if int(p[i])!=i+1:
        count=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_array = [int(x) for x in input().split()]

my_array = list(range(1,N+1))
ans_array = []
num = 0

for i in range(0,N):
	num = p_array[i] - my_array[i]
	ans_array.append(num)

print(ans_array)
new_lst = [e for e in ans_array if e != 0]
if len(new_lst)==0:
	ans = "YES"
elif len(new_lst)==2:
	ans = "YES"
else:
	ans = "NO"
print(ans)
print(new_lst)

import numpy as np
N = int(input())
xlist = list(map(int, input().split()))
ans = "NO"

minus_gaps = np.count_nonzero(np.diff(xlist)<0)

if minus_gaps == 0:
    ans = "YES"

elif minus_gaps == 2:
    tmpList = np.where(np.diff(xlist)<0)
    xlist[tmpList[0][0]],xlist[tmpList[0][1]+1] = xlist[tmpList[0][1]+1], xlist[tmpList[0][0]]
    if np.count_nonzero(np.diff(xlist)<0) == 0:
        ans = "YES"

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

for i in range(len(p_ls) - 1):
    min_idx = i
    for j in range(i + 1, len(p_ls)):
        if p_ls[min_idx] > p_ls[j]:
            min_idx = j
    if min_idx != i:
        p_ls[min_idx], p_ls[i] = p_ls[i], p_ls[min_idx]
        cnt += 1
if cnt > 1:
    print('No')
else:
    print('Yes')

N = int(input())
p_ls = list(map(int, input().split(' ')))
cnt = 0

for i in range(len(p_ls) - 1):
    min_idx = i
    for j in range(i + 1, len(p_ls)):
        if p_ls[min_idx] > p_ls[j]:
            min_idx = j
    if min_idx != i:
        p_ls[min_idx], p_ls[i] = p_ls[i], p_ls[min_idx]
        cnt += 1
if cnt > 1:
    print('No')
else:
    print('Yes')

N = int(input())
p_ls = list(map(int, input().split(' ')))
cnt = 0

for i in range(len(p_ls) - 1):
    min_idx = i
    for j in range(i + 1, len(p_ls)):
        if p_ls[min_idx] > p_ls[j]:
            min_idx = j
    if min_idx != i:
        p_ls[min_idx], p_ls[i] = p_ls[i], p_ls[min_idx]
        cnt += 1
if cnt > 1:
    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):
num = int(input())
num -= 1
ls = list(map(str, input().split(" ")))

sls = sorted(ls)

diff = 0
for i in range(num):
    if (sls[i] != ls[i]):
        diff += 1

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

num = int(input())
ls = list(map(int, input().split(" ")))

diff = 0
for i in range(num):
    if (ls[i] != i+1):
        diff += 1

if diff == 2 or diff == 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 = [int(i) for i in input().split(' ')]

has_changed = False
for i in range(N):
    expect = i + 1
    #print(p)
    #print(p[i], expect)
    if p[i] != expect:
        if has_changed:
            print('NO')
            exit()
        index = p[i] - 1
        if p[index] == expect:
            has_changed = True
            tmp = copy.deepcopy(p[i])
            p[i] = expect
            p[index] = tmp
            print('change', p[i], p[index])
        else:
            print('NO')
            exit()

print('YES')


import copy

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

has_changed = False
for i in range(N):
    expect = i + 1
    #print(p)
    #print(p[i], expect)
    if p[i] != expect:
        if has_changed:
            print('NO')
            exit()
        index = p[i] - 1
        if p[index] == expect:
            has_changed = True
            tmp = copy.deepcopy(p[i])
            p[i] = expect
            p[index] = tmp
            # print('change', p[i], p[index])
        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())
pn = list(map(int, input().split()))

count = 0
flag = True
for i in range(n-1):
    if pn[i] > pn[i+1]:
        for j in range(i+1, n-1):
            if pn[j] > pn[j+1]:
                tmp = pn[i]
                pn[i] = pn[j+1]
                pn[j+1] = tmp
                break
        count +=1
        if count > 1:
            flag = False
if flag:
    print("Yes")
else:
    print("No")

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

pnSort = sorted(pn)

if pn == pnSort:
    print("Yes")
else:
    change = []
    index = 0
    for i,j in zip(pn, pnSort):
        if i != j:
            change.append(index)
            if len(change) == 2:
                break
        index += 1

    tmp = pn[change[0]]
    pn[change[0]] = pn[change[1]]
    pn[change[1]] = tmp
    
    if pn == pnSort:
        print("Yes")
    else:
        print("No")

n = int(input())
pn = list(map(int, input().split()))
 
pnSort = sorted(pn)
 
if pn == pnSort:
    print("YES")
else:
    change = []
    index = 0
    for i,j in zip(pn, pnSort):
        if i != j:
            change.append(index)
            if len(change) == 2:
                break
        index += 1
 
    tmp = pn[change[0]]
    pn[change[0]] = pn[change[1]]
    pn[change[1]] = tmp
    
    if pn == pnSort:
        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):
count = 0
n = int(input())
L = list(map(int, input().split()))
for i in range(n):
    if L[i] == i+1:
        continue
    else:
        count = count + 1

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

count = 0
n = int(input())
L = list(map(int, input().split()))
for i in range(n):
    if L[i] == i+1:
        continue
    else:
        count = count + 1

if count == 2 or 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):
def main():
    n = int(input())
    p = list(map(int, input().split()))

    if 2 >= n or n >= 50:
        return

    for i in p:
        if isinstance(i, int) == False:
            return

    num = 0

    for i in range(len(p)):
        if i+1 != p:
            num += 1
    
    if num == 2:
        print('YES')
    else:
        print('NO')


if __name__ == "__main__":
    main()

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

    if n < 2 or 50 < n:
        return

    if isinstance(n, int) == False:
            return

    for i in p:
        if isinstance(i, int) == False:
            return

    num = 0

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


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):
# -*- coding: utf-8 -*-

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

ac_list = sorted(input_list)

count = 0
for x in zip(input_list, ac_list):
    if x[0] != x[1]:
        count += 1
    if count > 3:
        print("No")
        break
else:
    print("Yes")

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

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

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

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

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()]
flg = False
flg1 = True
for i in range(n):
    for j in range(n):
        flg1 = True
        q = p[:]
        q[i]=p[j]
        q[j]=p[i]
        for k in range(n):
            for l in range(n):
                if k < l and q[k]>q[l]:
                    flg1 = False
                    break
                if l==n-1 and k==n-1 and flg1:
                    flg = True
        
if flg:
    print('Yes')
else:
    print('No')

n = int(input())
p = [int(_) for _ in input().split()]
flg = False
flg1 = True
for i in range(n):
    for j in range(n):
        flg1 = True
        q = p[:]
        q[i]=p[j]
        q[j]=p[i]
        for k in range(n):
            for l in range(n):
                if k < l and q[k]>q[l]:
                    flg1 = False
                    break
                if l==n-1 and k==n-1 and flg1:
                    flg = True
        
if flg:
    print('YES')
else:
    print('NO')

Verdicts: Wrong Answer

Accepted