TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: We have a sequence p = {p_1,\ p_2,\ ...,\ p_N} which is a permutation of {1,\ 2,\ ...,\ N}.  You can perform the following operation at most once: choose integers i and j (1 \leq i < j \leq N), and swap p_i and p_j. Note that you can also choose not to perform it.  Print `YES` if you can sort p in ascending order in this way, and `NO` otherwise.

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

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

N = int(input())
P = list(map(int,input().split()))
count = 0
for i in range(N):
    if P[i] != (1+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):
import sys
n=int(input())
p=list(map(int,input().split()))
q=sorted(p)
if p==q:
  print("YES")
  sys.exit()
else:
  print("NO")
  sys.exit()
  

for i in range(n-1):
  for j in range(i+1,n):
    s=p[i]
    p[i]=p[j]
    p[j]=s
    if p==q:
      print("Yes")
      sys.exit()
    s=p[i]
    p[i]=p[j]
    p[j]=s
      
print("N0")

      
      
    
    

import sys
n=int(input())
p=list(map(int,input().split()))
q=sorted(p)
if p==q:
  print("YES")
  sys.exit()


for i in range(n-1):
  for j in range(i+1,n):
    s=p[i]
    p[i]=p[j]
    p[j]=s
    if p==q:
      print("Yes")
      sys.exit()
    s=p[i]
    p[i]=p[j]
    p[j]=s
      
print("N0")

      
      
    
    

import sys
n=int(input())
p=list(map(int,input().split()))
q=sorted(p)
for i in range(n-1):
  for j in range(i,n):
    s=p[i]
    p[i]=p[j]
    p[j]=s
    if p==q:
      print("YES")
      sys.exit()
    s=p[i]
    p[i]=p[j]
    p[j]=s
      
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())
X = list(map(int,input().split())
ctr = 0
         
for i in range(1,N):
  if X[i] != i:
    ctr += 1

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

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

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

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

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

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

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

Verdicts: Runtime Error

Accepted
Problem: We have a sequence p = {p_1,\ p_2,\ ...,\ p_N} which is a permutation of {1,\ 2,\ ...,\ N}.  You can perform the following operation at most once: choose integers i and j (1 \leq i < j \leq N), and swap p_i and p_j. Note that you can also choose not to perform it.  Print `YES` if you can sort p in ascending order in this way, and `NO` otherwise.

Submission attempts (in order):
N = int(input())
p_list = list(map(int,input().split()))
p_list_sorted = sorted(p_list)
cnt = 0
for i in range(N):
    if p_list[i] != p_list_sorted[i]:
        cnt += 1

print(p_list_sorted)
print(p_list)
if cnt == 2 or cnt == 0:
    print("YES")
else:
    print("NO")

N = int(input())
p_list = list(map(int,input().split()))
p_list_sorted = sorted(p_list)
cnt = 0
for i in range(N):
    if p_list[i] != p_list_sorted[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):
  if p[i] != i+1:
    ans += 1
if ans==0 or ans==2:
  print("Yes")
else:
  print("No")


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

Q = sorted([int(x) for x in P])

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


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


def swap():
  N = int(input())
  P = [int(x) for x in input().split()]
  Q = sorted([int(x) for x in P])
  ans = 0
  for i in range(N):
    if ans!=3:
      if P[i]!=Q[i]:
        ans += 1
    else:
      break
  if ans < 3:
    print("Yes")
  else:
  	print("No")
if __name__=="__main__":
  swap()

N = int(input())
P = [int(x) for x in input().split()]
Q = sorted([int(x) for x in P])
ans = 0
for i in range(N):
  if ans!=3:
    if P[i]!=Q[i]:
      ans += 1
  else:
    break
if ans==0 or ans==2:
  print("Yes")
else:
  print("No")


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


N = int(input())
P = [int(x) for x in input().split()]
ans = 0
for i in range(N):
  if P[i]!=i+1:
    ans += 1
if ans==0 or ans==2:
  print("Yes")
else:
  print("No")


def swap():
  N = int(input())
  P = [int(x) for x in input().split()]
  Q = sorted([int(x) for x in P])
  ans = 0
  for i in range(N):
    if ans!=3:
      if P[i]!=Q[i]:
        ans += 1
    else:
      break
  if ans==0 or ans==2:
    print("YES")
  else:
  	print("NO")
if __name__=="__main__":
  swap()


Verdicts: Wrong Answer

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()))
p_sort = sorted(p)
pi = 0
pj = 0
if p == p_sort:
  print("Yes")
  exit()
for i in range(N//2):
  pi = p[i]
  for j in range(i+1,N):
    pj = p[j]
    p[i] = pj
    p[j] = pi
    if p == p_sort:
      print("Yes")
      exit()
    else:
      p[j] = pj
      p[i] = pi
print("No")
print(p)

N = int(input())
p = list(map(int,input().split()))
p_sort = sorted(p)
pi = 0
pj = 0
if p == p_sort:
  print("Yes")
  exit()
for i in range(N//2):
  pi = p[i]
  for j in range(i+1,N):
    pj = p[j]
    p[i] = pj
    p[j] = pi
    if p == p_sort:
      print("Yes")
      exit()
    else:
      p[j] = pj
      p[i] = pi
print("No")

N = int(input())
p = list(map(str,input().split()))
p_sort = sorted(p)
count = 0
for i,j in zip(p,p_sort):
  if p[i] != p[j]:
    count += 1
if count == 0 or count == 2:
  print("YES")
else:
  print("NO")

N = int(input())
p = list(map(int,input().split()))
p_sort = sorted(p)
count = 0
for i,j in zip(p,p_sort):
  if p[i] != p[j]:
    count += 1
if count == 0 or count == 2:
  print("YES")
else:
  print("NO")

N = int(input())
p = list(map(int,input().split()))
p_sort = sorted(p)
count = 0
for i,j in zip(p,p_sort):
  if i != j:
    count += 1
if count == 0 or count == 2:
  print("YES")
else:
  print("NO")

Verdicts: Wrong Answer

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()))
flag = False
for i in range(n):
    q = p
    for j in range(n):
        q[i], q[j] = q[j], q[i]
        if q == sorted(q):
            flag = True
            break
if flag:
    print("YES")
else:
    print("NO") 

n = int(input())
p = list(map(int,input().split()))
flag = False
for i in range(n):
    q = p
    for j in range(n):
        q[i], q[j] = q[j], q[i]
        if q == sorted(q):
            flag = True
            break
if flag:
    print("Yes")
else:
    print("No")

n = int(input())
p = list(map(int,input().split()))
flag = False
for i in range(n):
    for j in range(n):
        q = p.copy()
        q[i], q[j] = q[j], q[i]
        print(q)
        if q == sorted(q):
            flag = True
            break
if flag:
    print("YES")
else:
    print("NO")  

n = int(input())
p = list(map(int,input().split()))
flag = False
for i in range(n):
    for j in range(n):
        q = p.copy()
        q[i], q[j] = q[j], q[i]
        if q == sorted(q):
            flag = True
            break
if flag:
    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 P[i]!=i+1:
        count+=1

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

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

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

n = int(input())
p = [int(e) for e in input().split()]
z = 0
for i in range(n):
  if p[i] != i + 1:
    z += 1
if z <= 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 numpy as np
N = int(input())
p = list(map(int,input().split()))
p = np.array(p)
p_new = np.zeros(N)
t = 0
for k in range(N-1):
	if p[k] > p[k+1]:
		t = 1
if t == 0:
	print("YES")
	exit()

for i in range(N):
	for j in range(i):
		for k in range(N):
			p_new[k] = p[k]
		p_new[i] = p[j]
		p_new[j] = p[i]
		print(p_new)
		t = 0
		for k in range(N-1):
			if p_new[k] > p_new[k+1]:
				t = 1
		if t == 0:
			print("YES")
			exit()
print("NO")


import itertools
import copy
N = int(input())
p = list(map(int,input().split()))
p_new = copy.copy(p)
t = 0
arg_combination = list(itertools.combinations(range(N),2))

for k in range(N-1):
	if p[k] > p[k+1]:
		t = 1
if t == 0:
	print("YES")
	exit()

for a in arg_combination:
	p_new = copy.copy(p)
	p_new[a[0]] = p[a[1]]
	p_new[a[1]] = p[a[0]]
	t = 0
	for k in range(N-1):
		if p_new[k] > p_new[k+1]:
			t = 1
	if t == 0:
		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())
arr = list(map(int, input().split()))
reverse_arr = list(reversed(arr))

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

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


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

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


Verdicts: Wrong Answer

Accepted
Problem: We have a sequence p = {p_1,\ p_2,\ ...,\ p_N} which is a permutation of {1,\ 2,\ ...,\ N}.  You can perform the following operation at most once: choose integers i and j (1 \leq i < j \leq N), and swap p_i and p_j. Note that you can also choose not to perform it.  Print `YES` if you can sort p in ascending order in this way, and `NO` otherwise.

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

b = sorted(p)
cnt = 0
if p == b:
    print("YES")
else:
    for i in range(n):
        if p[i] != b[i]:
            cnt += 1
            if cnt == 3:
                print("NO")
                break    
    if cnt == 1:
        print("NO")
    if cnt == 2:
        print("YES")

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

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

N = int( input() )
p_list = list( map( int, input().split() ) )
t_list = p_list[:]
p_list.sort()
c = 0
for i in range(N):
    if p_list[i] != t_list[i]:
        c += 1
if c == 0 or c == 2:
    print("Yes")
else:
    print("No")

N = int( input() )
p_list = list( map( int, input().split() ) )
t_list = p_list[:]
p_list.sort()
c = 0
for i in range(N):
    if p_list[i] != t_list[i]:
        c += 1
if c == 0 or c == 2:
    print("Yes")
else:
    print("No")

N = int( input() )
p_list = list( map( int, input().split() ) )
t_list = p_list[:]
p_list.sort()
c = 0
print(p_list)
for i in range(N):
    if p_list[i] != t_list[i]:
        c += 1
if c == 0 or c == 2:
    print("Yes")
else:
    print("No")


N = int( input() )
p_list = list( map( int, input().split() ) )
t_list = p_list[:]
p_list.sort()
c = 0
for i in range(N):
    if p_list[i] != t_list[i]:
        c += 1
if c == 0 or c == 2:
    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())
bara=list(map(int,input().split()))
number=list(range(1,n))

count = 0
    
for i in range (0,n-1):
    if bara[i] != number[i]:
        count += 1

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



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

number=[1]
for i in range(2,):
  List.append(i)
    
for i in range n-1:
  if bara[i] != number[i]:
    count+=1

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



n = int(input())
bara=list(map(int,input().split()))
number=list(range(1,n+1))

count = 0
u=n-1
    
for i in range (0,u):
    if bara[i] != number[i]:
        count += 1

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



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

number=[1]
for i in range(2,n):
  List.append(i)
    
for i in range n-1:
  if bara[i] != number[i]:
    count+=1

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



n = int(input())
bara=list(map(int,input().split()))
number=list(range(1,n))

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

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



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

number=[1]
for i in range(2,n):
    number.append(i)
    
for i in range (n-1):
    if bara[i] != number[i]:
        count+=1

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



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

number=[1]
for i in range(2,):
  List.append(i)
    
for i in range n-1:
  if bara[i]==number[i]:
    count+=1

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



n = int(input())
bara=list(map(int,input().split()))
number=list(range(1,n+1))

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

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



Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Runtime Error

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

# print(*a, sep=' ')

import math

n = int, input()

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

reverse = 0
former = 0

for num in p:
    if former > num:
        reverse += 1
    former = num
    if reverse > 1:
        print('NO')
        exit()
print('YES')



# print(*a, sep=' ')

import math

n = int(input())

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

not_same = 0

sorted_p = sorted(p)

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

if not_same < 3:
    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())
s = []
for i in range(n):
  s.append(i)

for i in range(n):
  t = 0
  if(s[i] != i + 1):
    t += 1
    if(t <= 2):
      print('Yes')
    else:
      print('No')

n = int(input())
s = []
t = 0
for i in range(n):
  s.append(i)

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


List = list(map(int, input().split()))
ans = 'YES'
for i in List:
  if(List[i] != List[i+1]):
    ans = 'NO'
    break
print(ans)

n = int(input())
s = list(map(int,input().split()))
t = 0
for i in range(n):
  s.append(i)

for i in range(n):
  if(s[i] == i + 1):
    t += 0
  else:
    t += 1
if(t == 0 or t == 2):
  print('YES')
else:
  print('NO')

Verdicts: Wrong Answer

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

N=int(input())
P=list(map(int,input().split()))
count=0
for i in range(N):
    if P[i]!=i+1:
        count=count+1
if count<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):
import sys
import math
INPUT = sys.stdin.readline

def SORO_INT(): return int(INPUT())
def MULT_INT_LIST(): return list(map(int, INPUT().split()))
def MULT_INT_MAP(): return map(int, INPUT().split())
def SORO_STRING(): return INPUT()
def MULT_STRING(): return INPUT().split()

N = SORO_INT()
A = MULT_INT_LIST()
X = sorted(A)
if A == X:
    print('yes')
    sys.exit()
    
t1 = A.index(max(A))
t2 = A.index(min(A))

A[t1],A[t2] = A[t2],A[t1]

if t2-N+1 == t1:
    print('yes')
else:
  print('no')

import sys
import math
INPUT = sys.stdin.readline

def SORO_INT(): return int(INPUT())
def MULT_INT_LIST(): return list(map(int, INPUT().split()))
def MULT_INT_MAP(): return map(int, INPUT().split())
def SORO_STRING(): return INPUT()
def MULT_STRING(): return INPUT().split()

N = SORO_INT()
A = MULT_INT_LIST()
X = sorted(A)
if A == X:
    print('YES')
    sys.exit()


i = 0
count=0
for i in range(N):
    if count>2:
        print('NO')
        sys.exit()
    
    if A[i]==i+1:
        count = count
    else:
        count+=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):
import math
import collections
import itertools
import copy

def YesNo(Bool):
    if(Bool):
        print("Yes")
    else:
        print("No")
    return

def resolve():

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

    tmp=copy.deepcopy(p)
    isOK=True
    for k in range(N-1):
        if(tmp[k]>=tmp[k+1]):
            isOK=False
    if(isOK):
        ans=True

    for i in range(N):
        for j in range(i+1,N):
            tmp=[]
            tmp=copy.deepcopy(p)
            tmp[i],tmp[j]=tmp[j],tmp[i]
            isOK=True
            for k in range(N-1):
                if(tmp[k]>=tmp[k+1]):
                    isOK=False
            if(isOK):
                ans=True
    YesNo(ans)

resolve()


import math
import collections
import itertools
import copy

def YesNo(Bool):
    if(Bool):
        print("YES")
    else:
        print("NO")
    return

def resolve():

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

    tmp=copy.deepcopy(p)
    isOK=True
    for k in range(N-1):
        if(tmp[k]>=tmp[k+1]):
            isOK=False
    if(isOK):
        ans=True

    for i in range(N):
        for j in range(i+1,N):
            tmp=[]
            tmp=copy.deepcopy(p)
            tmp[i],tmp[j]=tmp[j],tmp[i]
            isOK=True
            for k in range(N-1):
                if(tmp[k]>=tmp[k+1]):
                    isOK=False
            if(isOK):
                ans=True
    YesNo(ans)

resolve()


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

sorted_p = sorted(p_i)
count = 0

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

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


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

sorted_p = sorted(p_i)
count = 0

for i in range(N):
    if p_i[i] != sorted_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()))
px=sorted(p)
con=0
for i in range(n):
  if p[i]!=px[i]:
    con+=1
    
if con==2:
  print('Yes')
else:
  print('No')

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

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

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

n=int(input())
p=list(map(int,input().split()))
c=0
for i in range(n):
    if p[i] != sorted(p)[i]:
        c+=1
print("YES" if c == 2 or c == 0 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(read_input())
P=[int(x) for x in read_input().split()]

N_J=list(range(1,N+1))
ans='NO'
for i in range(N):
    for j in range(N):
        P_temp=P.copy()
        p_i=P[i]
        p_j=P[j]

        P_temp[i]=p_j
        P_temp[j]=p_i
        
        if P_temp==N_J:
            ans='YES'
            
print(ans)

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

N_J=list(range(1,N+1))
ans='NO'
for i in range(N):
    for j in range(N):
        P_temp=P.copy()
        p_i=P[i]
        p_j=P[j]

        P_temp[i]=p_j
        P_temp[j]=p_i
        
        if P==N_J:
            ans='YES'
print(ans)

N=int(input())
P=[int(x) for x in input().split()]
 
N_J=list(range(1,N+1))
ans='NO'
for i in range(N):
    for j in range(N):
        P_temp=P.copy()
        p_i=P[i]
        p_j=P[j]
 
        P_temp[i]=p_j
        P_temp[j]=p_i
        
        if P==N_J:
            ans='YES'
print(ans)
N=int(input())
P=[int(x) for x in input().split()]

N_J=list(range(1,N+1))
ans='NO'
for i in range(N):
    for j in range(N):
        P_temp=P.copy()
        p_i=P[i]
        p_j=P[j]

        P_temp[i]=p_j
        P_temp[j]=p_i
        
        if P==N_J:
            ans='YES'
print(ans)

N=int(input())
P=[int(x) for x in input().split()]
 
N_J=list(range(1,N+1))
ans='NO'
for i in range(N):
    for j in range(N):
        P_temp=P.copy()
        p_i=P[i]
        p_j=P[j]
 
        P_temp[i]=p_j
        P_temp[j]=p_i
        
        if P_temp==N_J:
            ans='YES'
print(ans)

Verdicts: Runtime Error

Wrong Answer

Runtime Error

Accepted
Problem: We have a sequence p = {p_1,\ p_2,\ ...,\ p_N} which is a permutation of {1,\ 2,\ ...,\ N}.  You can perform the following operation at most once: choose integers i and j (1 \leq i < j \leq N), and swap p_i and p_j. Note that you can also choose not to perform it.  Print `YES` if you can sort p in ascending order in this way, and `NO` otherwise.

Submission attempts (in order):
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N;
  cin >> N;
  int count= 0;
  
  vector<int> p(N);
  for (int i=1 ;i < N ;i++) {
    cin >> p[i];
    if (p[i-1]+1 != p[i+1]) {
      count++;
      }
    }
  
  if (count == 0 || count ==2){
    cout << "YES" << endl;
  }
  else cout << "NO" << endl;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N;
  cin >> N;
  int count= 0;
  
  vector<int> p(N);
  for (int i=1 ;i < N ;i++) {
    cin >> p[i];
    if (p[i-1]+1 != p[i]) {
      count++;
      }
    }
  
  if (count == 0 || count ==2){
    cout << "YES" << endl;
  }
  else cout << "NO" << endl;
}


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

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


Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: We have a sequence p = {p_1,\ p_2,\ ...,\ p_N} which is a permutation of {1,\ 2,\ ...,\ N}.  You can perform the following operation at most once: choose integers i and j (1 \leq i < j \leq N), and swap p_i and p_j. Note that you can also choose not to perform it.  Print `YES` if you can sort p in ascending order in this way, and `NO` otherwise.

Submission attempts (in order):
N=int(input())
ps=list(int(i) for i in input().split())  

pf=ps[0]
flag=0
for i in ps[1:]:
    if pf>i:
        flag+=1
        if flag>=2:
            print("NO")
            break
    pf=i
if flag<2:
 print("YES")

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

N=int(input())
ps=list(int(i) for i in input().split())  

arr,flag=bubble_sort(ps)
if flag>=2:
 print("NO")
else:
 print("YES")

import numpy as np
N=int(input())
ps=np.array(list(int(i) for i in input().split())  )

arr=np.arange(1,N+1,1)

flag=np.sum(ps==arr)

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

N = int(input())
p = list(map(int,input().split(" ")))
counter = 0
for i in range(N):
    if p[i] != i+1 and counter <= 1:
        counter = counter + 1
    elif p[i] != i+1 and counter > 1:
        counter = counter + 1
        break;
if counter <= 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()))
q=[]
for i in range(1,n+1):
    q.append(i)

print(p,q)

a=0
for i in range(n):
    if p[i]==q[i]:
        a+=1
    else:
        a+=0

if a==n or a==n-2:
    print('Yes')
else:
    print('No')

n=int(input())
p=list(map(int,input().split()))
q=[]
for i in range(1,n+1):
    q.append(i)

a=0
for i in range(n):
    if p[i]==q[i]:
        a+=1
    else:
        a+=0

if a==n or a==n-2:
    print('Yes')
else:
    print('No')

n=int(input())
p=list(map(int,input().split()))
q=[]
for i in range(1,n+1):
    q.append(i)

a=0
for i in range(n):
    if p[i]==q[i]:
        a+=1
    else:
        a+=0

if a==n or a==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):
import sys
input = sys.stdin.readline
input()
P = list(map(int, input().split()))

Ps = list(sorted(P))

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

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


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

Ps = list(sorted(P))

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

print('YES' if c <= 2 else 'NO')

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())
q=sorted(p)
for i in range(n):
  for j in range(n):
    r=p[:]
    r[i],r[j]=r[j],r[i]
    print(r)
    if r==q:
      print('YES')
      exit()
print('NO')

n,*p=map(int,open(0).read().split())
q=sorted(p)
for i in range(n-1):
    r=p[:]
    r[i],r[i+1]=r[i+1],r[i]
    if r==q:
        print('YES')
        exit()
print('NO')

n,*p=map(int,open(0).read().split())
q=sorted(p)
for i in range(n):
  for j in range(n):
    r=p[:]
    r[i],r[j]=r[j],r[i]
    if r==q:
      print('YES')
      exit()
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())

lst = input().split()
cnt = 0

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

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



N = int(input())

lst = input().split()
print(lst) #debug

lst2 = sorted(lst)
print(lst2) #debug

cnt = 0
for i in range(N):
    if lst[i] != lst2[i]:
        cnt += 1

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



N = int(input())


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

cnt = 0

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

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



Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: We have a sequence p = {p_1,\ p_2,\ ...,\ p_N} which is a permutation of {1,\ 2,\ ...,\ N}.  You can perform the following operation at most once: choose integers i and j (1 \leq i < j \leq N), and swap p_i and p_j. Note that you can also choose not to perform it.  Print `YES` if you can sort p in ascending order in this way, and `NO` otherwise.

Submission attempts (in order):
N = int(input())
P = input().split()
flag = "OK"
count = 0
for i in range(N):
  if i+1 != int(P[i]) :
    count = count + 1
if count >= 2:
  print("NO")
else:
  print("YES")

N = int(input())
P = input().split()
flag = "OK"
count = 0
for i in range(N):
  if i+1 != int(P[i]) :
    count = count + 1
if count >= 3:
  print("NO")
else:
  print("YES")

Verdicts: Wrong Answer

Accepted
Problem: We have a sequence p = {p_1,\ p_2,\ ...,\ p_N} which is a permutation of {1,\ 2,\ ...,\ N}.  You can perform the following operation at most once: choose integers i and j (1 \leq i < j \leq N), and swap p_i and p_j. Note that you can also choose not to perform it.  Print `YES` if you can sort p in ascending order in this way, and `NO` otherwise.

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

check = []

for x in range(N):
    check.append(x + 1)

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

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


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

check = []

for x in range(N):
    check.append(x + 1)

count = 0
for y in range(N):
    if check[y] != p[y]:
        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):
# coding: utf-8
# Your code here!

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

count = 0

for p,n in zip(ps,range(N)):
    if p != n:
        count += 1
if count == 2:
    print('YES')
else:
    print('NO')

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

count = 0

for p,n in zip(ps,range(1,N+1)):
    if p != n:
        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):
N = int(input())
A = list(map(int, input().split()))
count = 0

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

if count > 2:
    print("NO")

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

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

for i in range(N):
    if A[i] != i+1:
        count = count +1
    
if count > 2:
    print("NO")

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

Verdicts: Wrong Answer

Accepted
Problem: We have a sequence p = {p_1,\ p_2,\ ...,\ p_N} which is a permutation of {1,\ 2,\ ...,\ N}.  You can perform the following operation at most once: choose integers i and j (1 \leq i < j \leq N), and swap p_i and p_j. Note that you can also choose not to perform it.  Print `YES` if you can sort p in ascending order in this way, and `NO` otherwise.

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

#B
import sys
n = int(input())
p = list(map(int, input().split()))
count=0
for i in range(n):
    if p[i] != i+1:
        if count == 2:
            print('No')
            sys.exit()
        else:
            count += 1
print('Yes')

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

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: We have a sequence p = {p_1,\ p_2,\ ...,\ p_N} which is a permutation of {1,\ 2,\ ...,\ N}.  You can perform the following operation at most once: choose integers i and j (1 \leq i < j \leq N), and swap p_i and p_j. Note that you can also choose not to perform it.  Print `YES` if you can sort p in ascending order in this way, and `NO` otherwise.

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

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

Verdicts: Wrong Answer

Accepted
Problem: We have a sequence p = {p_1,\ p_2,\ ...,\ p_N} which is a permutation of {1,\ 2,\ ...,\ N}.  You can perform the following operation at most once: choose integers i and j (1 \leq i < j \leq N), and swap p_i and p_j. Note that you can also choose not to perform it.  Print `YES` if you can sort p in ascending order in this way, and `NO` otherwise.

Submission attempts (in order):
import sys

N = int(input())
A = [int(N) for N in input().split()]
swp = 0

if A == sorted(A):
  print("Yes")
  sys.exit()

for i in range (0,N-1):
 if A[i]>A[i+1]:
   swp = A[i]
   A[i] = A[swp-1]
   A[swp-1] = swp
   if A == sorted(A):
     print("Yes")
     sys.exit()
print ("No")

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

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

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

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

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

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

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

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

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

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

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

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

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

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: We have a sequence p = {p_1,\ p_2,\ ...,\ p_N} which is a permutation of {1,\ 2,\ ...,\ N}.  You can perform the following operation at most once: choose integers i and j (1 \leq i < j \leq N), and swap p_i and p_j. Note that you can also choose not to perform it.  Print `YES` if you can sort p in ascending order in this way, and `NO` otherwise.

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


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



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


if __name__=="__main__":
    main()

def main():
    N = int(input())
    p = list(map(int,input().split()))
    count = 0
    for i in range(N-1):
        if p[i]!=i+1:
            count += 1
    
    if count >= 3:
        print("NO")
    else:
        print("YES")


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())
p = [int(i) for i in input().split()]
a = 0
for i in range(N):
    if p[i] == (i+1):
        continue
    else :
        a += 1
if a <= 2 :
    print("Yes")
else:
    print("No")

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


print("Yes" if cnt <= 2 else "No")


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

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

Verdicts: Wrong Answer

Accepted