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):
# import itertools
# import math

import sys
input = sys.stdin.readline


def solve(N, P):
    NN = sorted(N)
    cnt = 0
    for l1, l2 in zip(N, NN):
        if l1 != l2:
            cnt += 1

    return 'YES' if cnt <= 2 else 'NO'


N = int(input())
# S = input()
# A, B = map(int, input().split())
P = list(map(int, input().split()))

# P = []
# S = []

#     pp, ss = map(int, input().split())
#     P.append(pp)
#     S.append(ss)

print(solve(N, P))


# import itertools
# import math

import sys
input = sys.stdin.readline


def solve(N, P):
    PP = sorted(P)
    cnt = 0
    for l1, l2 in zip(P, PP):
        if l1 != l2:
            cnt += 1

    return 'YES' if cnt <= 2 else 'NO'


N = int(input())
# S = input()
# A, B = map(int, input().split())
P = list(map(int, input().split()))

# P = []
# S = []

#     pp, ss = map(int, input().split())
#     P.append(pp)
#     S.append(ss)

print(solve(N, P))


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 itertools
import copy


def is_sorted(arr):
    for i in range(len(arr) - 1):
        if arr[i] > arr[i + 1]:
            return False
    return True


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

    if is_sorted(ps):
        print('Yes')
        return

    for i, j in itertools.combinations(range(n), 2):
        ps_ = copy.deepcopy(ps)
        ps_[i], ps_[j] = ps_[j], ps_[i]
        if is_sorted(ps_):
            print('Yes')
            return
    print('No')
    return


main()

import itertools
import copy


def is_sorted(arr):
    for i in range(len(arr) - 1):
        if arr[i] > arr[i + 1]:
            return False
    return True


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

    if is_sorted(ps):
        print('YES')
        return

    for i, j in itertools.combinations(range(n), 2):
        ps_ = copy.deepcopy(ps)
        ps_[i], ps_[j] = ps_[j], ps_[i]
        if is_sorted(ps_):
            print('YES')
            return
    print('NO')
    return


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

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

if cnt == n-1 or check == 2 :
  print("YES")
else:
  print("NO")  

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

n = int(input())
p = list(map(int, input().split()))
cnt = 0
check = 0
tmp = 0
for i in range(n-1):
  if p[i+1] - p[i] == 1:
    cnt += 1
  else:
    if tmp == 0:
      tmp = i + 2
      check += 1
    else :
      if tmp == p[i+1]:
        check += 1
      else :
        cnt += 1

if cnt == n-1 or check == 2 :
  print("YES")
else:
  print("NO")  

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

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

n = input()
l = list(map(int, input().split()))
s = sorted(l)
out = 0
for i in range(len(l)):
  out += 1 if l[i] != s[i] else 0
 
print('YES') if out == 2 or out == 0 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(inpuit())

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

N=int(input())

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

N=int(input())

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

Verdicts: Runtime Error

Wrong Answer

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

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

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

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

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

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

cnt = 0
res = 'YES'
for i in range(n-1):
    if p[i] > p[i+1]:
        cnt+=1
    if cnt == 2:
        res = 'NO'
        
print(res)

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

cnt = 0
res = 'Yes'
for i in range(n-1):
    if p[i] > p[i+1]:
        cnt+=1
    if cnt == 2:
        res = 'No'
        
print(res)

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

cnt = 0
res = 'YES'

for i in range(n-1):
    if i+1 != p[i]:
        cnt+=1
        
if cnt >= 3:
    res = 'NO'
        
print(res)

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()))
p_l = sorted(p)
count =0

if p == p_l:
    print("Yes")

else:
    for i in range(n):
        if not p[i] == p_l[i]:
            count +=1

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

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

if p == p_l:
    print("YES")

else:
    for i in range(n):
        if not p[i] == p_l[i]:
            count +=1

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

Verdicts: Wrong Answer

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

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

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

ans = 0

for i in range(n):
  if P[i] != i + 1:
    ans += 1
if ans <= 2:
  print('YES')
else:
  print('NO')








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




ascending_order = P.sort()




Test_P = P[1:N-1]


ascending_TestP = Test_P.sort()

Check = (abs((P[-1] + P[0]) +1)) 

if P == ascending_order:
    print("YES")
elif Test_P != ascending_TestP:
    print("NO")
else:
    print("YES")









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




ascending_order = P.sort()




Test_P = P[1:N-1]


ascending_TestP = Test_P.sort()

Check = (abs((P[-1] + P[0]) +1)) 

if P == ascending_order:
    print("YES")
elif Test_P == ascending_TestP and Check == N:
    print("YES")
else:
    print("NO")

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('YES')
else:
  print('NO')

Verdicts: Runtime Error

Wrong Answer

Wrong Answer

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

Submission attempts (in order):
import numpy as np
n = int(input())
p = np.array(list(map(int,input().split())))

a = np.arange(1, n+1)
tmp = p - a
cnt = np.count_nonzero(tmp != 0)

flg = False
if cnt == 0 or (cnt == 2 and tmp.sum() == 0):
    flg = True

print('Yes') if flg else print('No')

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

a = np.arange(1, n+1)
tmp = p - a
cnt = np.count_nonzero(tmp != 0)

flg = False
if cnt == 0 or (cnt == 2 and tmp.sum() == 0):
    flg = True

print('YES') if flg else print('NO')

Verdicts: Wrong Answer

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

Submission attempts (in order):
n = int(input())
P = [int(i) for i in input().split()]
cnt = 0
for i in range(1,n+1):
    if P[i-1] != i:
        idx = P[i-1]
        if P[idx-1] != i:
            print('No')
            exit()
        else:
            P[i-1] = i
            P[idx-1] = idx
            cnt += 1
#print(P)
if cnt <= 1: print('Yes')
else: print('No')


n = int(input())
P = [int(i) for i in input().split()]
ok = [i for i in range(1,n+1)]
cnt = 0
for p,o in zip(P,ok):
    if p != o: cnt += 1
if cnt == 2 or cnt == 0: print('Yes')
else: print('No')


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


n = int(input())
P = [int(i) for i in input().split()]
ok = [i for i in range(1,n+1)]
cnt = 0
for p,o in zip(P,ok):
    if p != o: cnt += 1
if cnt == 2 or cnt == 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())
a=list(map(int,input().split()))
for i in range(n):
  for j in range(i+1,n):
    a[i],a[j]=a[j],a[i]
    for k in range(n-1):
      if a[k]>a[k+1]:
        a[i],a[j]=a[j],a[i]
        break
    else:
      i,j=n,n
if i==n:
  print("YES")
else:
  print("NO")

import sys
sys.setrecursionlimit(100000)
input=sys.stdin.readline
def intinput():return map(int,input().split())


n=int(input())
a=list(intinput())
b=a[:]
b.sort()
if a == b:
    print("YES")
    sys.exit()
for i in range(n):
    for j in range(i+1,n):
        a[i],a[j]=a[j],a[i]
        if a==b:
            print("YES")
            sys.exit()
        a[i],a[j]=a[j],a[i]
print("NO")

Verdicts: Runtime Error

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

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

print(P)
print(P_r)
    

N = int(input())
P = list(map(int,input().split(' ')))
ans = 0
P_r = sorted(P)
#print(P_r)
for i in range(0,N):
  if P[i] != P_r[i]:
    ans +=1
    
if ans<=1:
  print('YES')
else:
  print('NO')
    

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

list_p = [i for i in range(1,N+1) ]
flag = 0

if p == list_p:
    print("Yes")

else:
    for i in range(N):
        for j in range(i+1,N):
            p[i],p[j] = p[j],p[i]

            if p == list_p:
                flag = 1
                break

            p[i],p[j] = p[j],p[i]
    
        if flag == 1:
            break

    print("Yes" if flag == 1 else "No")


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

list_p = [i for i in range(1,N+1) ]
flag = 0

if p == list_p:
    print("YES")

else:
    for i in range(N):
        for j in range(i+1,N):
            p[i],p[j] = p[j],p[i]

            if p == list_p:
                flag = 1
                break

            p[i],p[j] = p[j],p[i]
    
        if flag == 1:
            break

    print("YES" if flag == 1 else "NO")


Verdicts: Wrong Answer

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

Submission attempts (in order):
n = int(input())
arr = []
c=0
for i in range(0,n):
	if arr[i]!= i+1 :
		c+=1
          
if c > 2:
	print('NO')
else:
	print('YES')

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

flag=0
save=0
for i in range(N-1):
  if flag==0 and P[i]>P[i+1]:
    save=i
    flag=1
  if flag==1 and P[i]>P[i+1]:
    tmp=P[i]
    P[i]=P[save]
    P[save]=tmp
    break

flag=0
for i in range(N-1):
  if P[i]>P[i+1]:
    print('NO')
    flag=1
    break

if flag!=1:
  print('YES')

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

flag=0
save=0
for i in range(N-1):
  if flag==0 and P[i]>P[i+1]:
    save=i
    flag=1
    continue
  if flag==1 and P[i]>P[i+1]:
    tmp=P[i+1]
    P[i+1]=P[save]
    P[save]=tmp
    break

flag=0
for i in range(N-1):
  if P[i]>P[i+1]:
    print('NO')
    flag=1
    break

if flag!=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 sys
N = int(input())
H = list(map(int,input().split()))
C = 0

if sorted(H) == H:
  print("YES")
  sys.exit()
  
for i in range(0,N-1):
  for j in range(1,N):
    tmp = H.replace(H[i],H[j])
    if tmp == sorted(H):
      print("YES")
      sys.exit()
print("NO")

import copy
import sys
N = int(input())
H = list(map(int,input().split()))
C = 0

if sorted(H) == H:
	print("YES")
	sys.exit()

for i in range(0,N-1):
	for j in range(1,N):
		L = copy.copy(H)
		L[1],L[3] = L[3],L[1] 
		if L == sorted(H):
			print("YES")
			sys.exit()
print("NO")

import copy
import sys
N = int(input())
H = list(map(int,input().split()))
C = 0

if sorted(H) == H:
	print("YES")
	sys.exit()

for i in range(0,N-1):
	for j in range(1,N):
		L = copy.copy(H)
		L[i],L[j] = L[j],L[i] 
		if L == sorted(H):
			print("YES")
			sys.exit()
print("NO")

Verdicts: Runtime Error

Wrong Answer

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

Submission attempts (in order):
N = int(input())
p = [int(i) for i in input().split()]
count = 0 
res = "yes"
p_sorted = sorted(p)
for i in range(N):
  if p_sorted[i] != p[i]:
    count += 1
    if count > 2:
      res = "no"
      break
print(res)

N = int(input())
p = [int(i) for i in input().split()]
count = 0 
res = "YES"
p_sorted = sorted(p)
for i in range(N):
  if p_sorted[i] != p[i]:
    count += 1
    if count > 2:
      res = "NO"
      break
print(res)

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

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

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

Verdicts: Wrong Answer

Wrong Answer

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

Submission attempts (in order):
import sys

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

cnt = 0

for i in range(N):
    if p[i] != p_sorted[i]:
        cnt += 1
    if cnt==3:
        print("No")
        sys.exit()

print("Yes")


import sys

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

cnt = 0

for i in range(N):
    if p[i] != p_sorted[i]:
        cnt += 1
    if cnt==3:
        print("No")
        sys.exit()

print("Yes")


import sys

N = int(input())
p = list(map(int,input().split()))
p_sorted = sorted(p)
cnt = 0
for i in range(N):
    if p[i] != p_sorted[i]:
        cnt += 1
    if cnt==3:
        print("NO")
        sys.exit()

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):
import numpy as np
N=int(input())
list_p=list(map(int,input().split()))
np_list_p=np.array(list_p)
np_list_s =np.array(sorted(list_p))
minus=list(np_list_p - np_list_s)
print("Yes" if minus.count(0) == N or minus.count(0)== N-2 else "No")
print(minus.count(0))

import numpy as np
N=int(input())
list_p=list(map(int,input().split()))
np_list_p=np.array(list_p)
np_list_s =np.array(sorted(list_p))
minus=list(np_list_p - np_list_s)
print("Yes" if minus.count(0) == N or minus.count(0)== N-2 else "No")

import numpy as np
N=int(input())
list_p=list(map(int,input().split()))
print(list_p)
np_list_p=np.array(list_p)
np_list_s =np.array(sorted(list_p))
minus=list(np_list_p - np_list_s)
print("Yes" if minus.count(0) == N or N-2 else "No")

import numpy as np
N=int(input())
list_p=list(map(int,input().split()))
np_list_p=np.array(list_p)
np_list_s =np.array(sorted(list_p))
minus=list(np_list_p - np_list_s)
print("YES" if minus.count(0) == N or minus.count(0)== N-2 else "NO")

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

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

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

n = int(input())
p = list(map(int,input().split()))
x = sorted(p)
c = 0
for i in range(n):
    if x[i] != p[i]:
        c+=1
if 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())
p = list(map(int,input().split()))
nlst = [x for x in range(1,n+1)]
lst = [0]*n
for i in range(n):
  if nlst[i] == p[i]:
    lst[i] = 1
print('YES' if sum(lst) in [0,2] else 'NO')

n = int(input())
p = list(map(int,input().split()))
nlst = [x for x in range(1,n+1)]
lst = [0]*n
#print(nlst,lst)
for i in range(n):
    if nlst[i] != p[i]:
        lst[i] = 1
    #print(lst)
print('YES' if sum(lst) in [0,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())
M=list(map(int,input().split()))
ans=0
list_= sorted(M)
for i in range(N):
  if M[i]==list_[i]:
    ans+=1
if ans>=N-2:
  print('Yes')
else:
  print('No')
  


N=int(input())
M=list(map(int,input().split()))
ans=0
list_= sorted(M)
for i in range(N):
  if M[i]==list_[i]:
    ans+=1
if ans>=M-2:
  print('Yes')
else:
  print('No')
  
  

N=int(input())
M=list(map(int,input().split()))
ans=0
list_= sorted(M)
for i in range(N):
  if M[i]==list_[i]:
    ans+=1
if ans>=N-2:
  print('Yes')
else:
  print('No')
  
  


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



Verdicts: Wrong Answer

Runtime Error

Wrong Answer

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

Submission attempts (in order):
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    P = il()
    cnt = 0
    for n in range(N):
        if P[n] != n + 1:
            cnt += 1
        if P[P[n]] != n+1:
            print('NO')
            exit()
    print('NO' if cnt > 3 else 'YES')


if __name__ == '__main__':
    main()


import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    P = il()

    cnt = 0
    for n in range(N):
        if P[n] != n + 1:
            cnt += 1
        if cnt > 2:
            print('NO')
            exit()
    else:
        print('YES')


if __name__ == '__main__':
    main()


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()))
cnt=0
for n in range(N):
    if n+1!=P[n]:
        cnt+=1
        if cnt>2:
            print("No")
            exit()

print("Yes")


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

print("YES")


Verdicts: Wrong Answer

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

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

n=int(input())
p=list(map(int,input().split()))
P=sorted(p)
flag=0
for i in range(n):
    if p[i]!=P[i]:
        flag+=1
print("YES" if flag==2 or flag==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(input())
li_p = list(map(int, input().split()))
li = set(li_p)
li_a = []
li_b = []
for i in range(N):
  if li_p[i] != li[i]:
    li_a.append(li_p[i])
    li_b.append(li[i])
    if len(li_a) == 2:
      if li_a[0] == li_b[1]:
        print("YES")
      else:
        print("NO")
    elif len(li_a) > 2:
      print("NO")
    elif len(li_a) == 0:
      print("YES")
    
  
  

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

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

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

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()))
a=0
for i in range(n):
  if li[i]==i+1:
    a+=1
if a==2:
  print("YES")
else:
  print("NO")

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

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


Verdicts: Runtime Error

Wrong Answer

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

Submission attempts (in order):
num_input = input()
list_input = input().split(" ")
N = int(num_input)
count = 0
for i in range(0,N-1):
  check = int(list_input[i])-int(list_input[i+1])
  if check > 1:
    count += 2
    break
  else:
    count += max(check,0)
if count >= 2:
  print('NO')
else:
  print('YES')



num_input = input()
list_input = input().split(" ")
N = int(num_input)
count = 0
for i in range(0,N-1):
  check = int(list_input[i])-int(list_input[i+1])
  if check > 1:
    count = 2
    break
  else:
    count += max(check,0)
if count >= 2:
  print('NO')
else:
  print('YES')

num_input = input()
list_input = input().split(" ")
N = int(num_input)
count = 0
for i in range(0,N-1):
  check = int(list_input[i])-(i+1)
  if not check == 0:
    count += 1
    if count == 3:
      break

if count == 3:
  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()))
judge = 0
for i in range(N):
  if (p[i] == i):
    None
  else:
    judge += 1
if judge <= 2:
  print("YES")
else:
  print("NO")

  

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

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

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):
if __name__ == '__main__':
    n = int(input()
    ps = [int(x) for x in input().split()]

    dis = []

    for n, p in enumerate(ps):
        if n + 1 != p:
            dis.append(p)

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

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

    dis = []

    for n, p in enumerate(ps):
        if n + 1 != p:
            dis.append(p)

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

if __name__ == '__main__':
    n = int(input())
    ps = [int(x) for x in input().split()]

    dis = []

    for n, p in enumerate(ps):
        if n + 1 != p:
            dis.append(p)

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

Verdicts: Runtime Error

Runtime Error

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

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

if count == 2 or count == 0:
  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 <= 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())
S=list(map(int,input().split()))

T=sorted(S)

count=0
for i in range (len(S)):
  if S[i]!=T[i]:
    count+=1
if count<=2:
  print("Yes")
else:
  print("No")

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

T=sorted(S)

count=0
for i in range (len(S)):
  if S[i]!=T[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 math
def main():
  n=int(input())
  p = list(map(int,input().split()))
  first=-1
  last=-1
  
  for i in range(0,n-1):
    if p[i]>p[i+1]:
      first=i
      break
  for i in reversed(range(1,n)):
    if p[i]<p[i-1]:
      last=i
      break
  
  if first!=-1 and last!=-1:
    tmp=p[first]
    p[first]=p[last]
    p[last]=tmp

  for i in range(0,n-1):
    if p[i]>p[i+1]:
      print("No")
      break
    if i==n-2:
      print("Yes")  
main()

import math
def main():
  n=int(input())
  p = list(map(int,input().split()))
  first=-1
  last=-1
  
  for i in range(0,n-1):
    if p[i]>p[i+1]:
      first=i
      break
  for i in reversed(range(1,n)):
    if p[i]<p[i-1]:
      last=i
      break
  
  if first!=-1 and last!=-1:
    tmp=p[first]
    p[first]=p[last]
    p[last]=tmp

  for i in range(0,n-1):
    if p[i]>p[i+1]:
      print("NO")
      break
    if i==n-2:
      print("YES")  
main()

Verdicts: Wrong Answer

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

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

for i in range(len(L)):
    if L[i] != i+1:
        cnt += 1
    print(L[i])
    print(i+1)
if cnt >= 3:
    print('NO')
else:
    print('YES')

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

for i in range(len(L)):
    if L[i] != i+1:
        cnt += 1
if cnt >= 3:
    print('NO')
else:
    print('YES')

Verdicts: Wrong Answer

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

Submission attempts (in order):
import sys
n = int(input())
p = list(map(int,input().split()))
flag = True
for i in range(1,n):
     if p[i] < p[i-1]:
          flag = False
          continue
if flag:
     print('YES')
     sys.exit()

for i in range(n-1):
     for j in range(i,n):
          pp = p
          pp[i] = p[j]
          pp[j] = p[i]
          for k in range(1, n):
               if p[k] < p[k - 1]:
                    flag = False
                    continue
          if flag:
               print('YES')
               sys.exit()
print('NO')


import sys
import copy
n = int(input())
p = list(map(int,input().split()))
flag = True
for i in range(1,n):
     if p[i] < p[i-1]:
          flag = False
          continue
if flag:
     print('YES')
     sys.exit()

for i in range(n-1):
     for j in range(i,n):
          pp = copy.deepcopy(p)
          pp[i] = copy.deepcopy(p[j])
          pp[j] = copy.deepcopy(p[i])
          flag = True

          for k in range(1, n):
               if pp[k] < pp[k - 1]:
                    flag = False
                    continue
          if flag:
               print('YES')
               sys.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())
suuretsu_str = input().split()
suuretsu = [int(i) for i in suuretsu_str]
suuretsu_order = [i for i in range(1,N+1)]
count = 0
for i in range(N):
    if suuretsu[i] != suuretsu_order[i]
    count += 1
if count == 2:
    print("YES")
else:
    print("NO")

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

Verdicts: Runtime Error

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

Submission attempts (in order):
N=int(input())
A=list(map(int,input().split()))
li=[]
for i in range(N):
  if A[i]!=AA[i]:
    li.append(A[i])
if len(li)>2:
  print("NO")
else:
  print("YES")

N=int(input())
A=list(map(int,input().split()))
AA=sorted(A)
li=[]
for i in range(N):
  if A[i]!=AA[i]:
    li.append(A[i])
if len(li)>2:
  print("NO")
else:
  print("YES")


Verdicts: Runtime Error

Accepted