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())
a=[int(i) for i in input().split()]
a.insert(0,0)
f=1
for i in range(1,n+1):
    if a[i]!=i:
        t=a[i]
        a[i]=a[a[i]]
        a[a[i]]=t
        break
for i in range(n):
    if a[i]>a[i+1]:
        f=0
if f==0:
    print("NO")
else:
    print("YES")

n=int(input())
a=[int(i) for i in input().split()]
a.insert(0,0)
f=1
for i in range(1,n+1):
    if a[i]!=i:
        r=a[i]
        t=a[i]
        a[i]=a[r]
        a[r]=t
        break
for i in range(n):
    if a[i]>a[i+1]:
        f=0
if f==0:
    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_l = list(map(int, input().split()))

cnt = 0
for i in range(n):
    if p_l[i] != min(p_l) + i:
        cnt += 1
if cnt == 2 or p_l == sorted(p_l):
    print('Yes')
else:
    print('No')

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

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

temp=np.sum(p==q)
if temp==0 or temp==2:
  print('YES')
else:
  print('NO')
  

import numpy as np

N=int(input())
p=np.array(list(map(int, input().split())))
q=np.arange(N)+1

temp=np.sum(~(p==q))
if temp==0 or temp==2:
  print('YES')
else:
  print('NO')
  

Verdicts: Runtime Error

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

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

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

n = int(input())
p = list(map(int,input().split()))
int_queue = [i for i in range(1,n+1)]
ans = 0
for j in range(0,n):
  if p[j]-int_queue[j] == 0:
    continue
  else:
    ans += 1
if ans == 2 or ans == 0:
  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):
#135 0 or 1 Swap
N=int(input())
P=map(int,input().split())
c=0
for i in range(1,N):
    if P[i-1]>P[i]:
        c+=1
print('YES' if c==0 or c==2 else 'NO')

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

Verdicts: Runtime Error

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

Submission attempts (in order):
N = int(input())
A = [int(x) for x in input().split()]
B = list(range(1,N+1))

def test(i):
  AA = A.copy()
  AA[i], AA[i+1] = AA[i+1], AA[i]
  return AA == B

bl = (A == B)
for i in range(N-1):
  if test(i):
    bl = True
answer = 'YES' if bl else 'NO'
print(answer)


import itertools
N = int(input())
A = [int(x) for x in input().split()]
B = list(range(1,N+1))

def test(i,j):
  AA = A.copy()
  AA[i], AA[j] = AA[j], AA[i]
  return AA == B

bl = (A == B)
for i,j in itertools.combinations(range(N)):
  if test(i,j):
    bl = True
answer = 'YES' if bl else 'NO'
print(answer)


import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,*P = map(int,read().split())

diff = sum(x != y for x,y in enumerate(P,1))

answer = 'YES' if diff <= 2 else 'NO'
print(answer)

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

flag = True
for i in range(n):
    for j in range(i+1,n):
        tmp = p[i]
        p[i] = p[j]
        p[j] = tmp
        if p == sorted(p):
            print('Yes')
            flag = False
            tmp = p[i]
            p[i] = p[j]
            p[j] = tmp
            break
        tmp = p[i]
        p[i] = p[j]
        p[j] = tmp

if p == sorted(p):
    print('Yes')
    flag = False

if flag:
    print('No')


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

flag = True
for i in range(n):
    for j in range(i+1,n):
        tmp = p[i]
        p[i] = p[j]
        p[j] = tmp
        if p == sorted(p):
            print('YES')
            flag = False
            tmp = p[i]
            p[i] = p[j]
            p[j] = tmp
            break
        tmp = p[i]
        p[i] = p[j]
        p[j] = tmp

if p == sorted(p):
    print('YES')
    flag = False

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

def solve():
  
  p_sorted = sorted(p, reverse=False)
  cnt = 0
  for i in range(0, n):
    if p[i] != p_sorted[i]:
      cnt += 1

    if cnt >= 3:
      print("No")
      return

  print("Yes")
  return


if __name__ == "__main__":
  solve()

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

def solve():
  
  p_sorted = sorted(p, reverse=False)
  cnt = 0
  for i in range(0, n):
    if p[i] != p_sorted[i]:
      cnt += 1

    if cnt >= 3:
      print("NO")
      return

  print("YES")
  return


if __name__ == "__main__":
  solve()

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):
input()
a = list(map(str, input().split()))
b = list(map(int, input().split()))
if sorted(b) == a:
    print("YES")
else:
    m = 0
    for i in range(len(a)):
        if a[i] in sorted(b)[i]:
            m+=1
    if m==len(a)-2:
        print("YES")
    else:
        print("NO")

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

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
flug = 0

for i in range(N):
  if P[i] != i+1:
    ans += 1
      
if ans <= 2:
  print("Yes")
elif ans >= 3:
  print("No")

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

ans = 0
flug = 0

for i in range(N):
  if P[i] != i+1:
    ans += 1
      
if ans <= 2:
  print("YES")
elif ans >= 3:
  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)
List = list(map(int, input().split()))
mid = -1
flag = True
for i in range(N):
  if List[i] == i+1:
    pass
  else:
    flag = False
    if mid == -1:
      mid = List[i]
    else:
      if mid == List[i]:
        print("YES")
      else:
        print("NO")
if flag:
  print("YES")

N=int(input())
List = list(map(int, input().split()))
flag = 0
for i in range(N):
  if List[i] == i+1:
    pass
  else:
    flag += 1
if flag==2 or flag == 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())
ls = list(map(int,input().split()))

count = 0

for i in range(n):
  if ls[i] == i+1:
    continue
  else:
    count +=1
    if count >=2:
      break
    if ls[ls[i]-1]==i+1:
      ls[ls[i]-1] = ls[i]
      ls[i] = i+1

    else:
      count+=1
print(ls)
if count>=2:
  print("NO")
else:
  print("YES")


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

count = 0

for i in range(n):
  if ls[i] == i+1:
    continue
  else:
    count +=1
    if count >=2:
      break
    if ls[ls[i]-1]==i+1:
      ls[i] = i+1
      ls[ls[i]-1] = ls[i]
    else:
      count+=1
      
if count>=2:
  print("NO")
else:
  print("YES")


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

count = 0

for i in range(n):
  if ls[i] == i+1:
    continue
  else:
    count +=1
    if count >=2:
      break
    if ls[ls[i]-1]==i+1:
      ls[ls[i]-1] = ls[i]
      ls[i] = i+1

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

for i in range(N-1):
    if p[i]>p[i+1]:
        cnt+=1
print(cnt)
if cnt>2 or cnt==1:
    print("NO")
    exit()
if cnt==0:
    print("YES")
    exit()
else:
    for i in range(N-1):
        if p[i]>p[i+1]:
            a.append(p[i])
            a.append(p[i+1])
if a[0]>a[2] and a[1]>a[3]:
    print("YES")      
else:
    print("NO") 

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

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

if cnt>2 or cnt==1:
    print("NO")
    exit()
if cnt==0:
    print("YES")
    exit()
else:
    for i in range(N-1):
        if p[i]>p[i+1]:
            a.append(p[i])
            a.append(p[i+1])
if a[0]>a[2] and a[1]>a[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):
a = int(input())
b=list(map(int,input().split()))
c=b
c.sort()
d=[]
print(c)
for i in range(a):
    for j in range(a):
        b[i],b[j]=b[j],b[i]
        print(b)
        if b==c:
            d.append(b)
        else:
            continue
if len(d)!=0:
    print('YES')
else:
    print('NO')

a = int(input())
b=list(map(int,input().split()))
c=b
c.sort()
d=[]
print(c)
for i in range(a):
    for j in range(a):
        b[i],b[j]=b[j],b[i]
        print(b)
        if b==c:
            d.append(b)
        else:
            continue
if len(d)!=0:
    print('Yes')
else:
    print('No')

a = int(input())
b=list(map(int,input().split()))
c=b
c.sort()
d=[]
for i in range(a):
    for j in range(a):
        b[i],b[j]=b[j],b[i]
        if b==c:
            d.append(b)
        else:
            continue
if len(d)!=0:
    print('Yes')
else:
    print('No')

a=int(input())
b=list(map(int,input().split()))
c=b.sorted()
d=0
for i in range(a):
  b[i]!=b[i]
  d+=1
if d<=2:
  print('YES')
else:
  print('NO')

a=int(input())
b=list(map(int,input().split()))
c=sorted(b)
d=0
for i in range(a):
  if b[i]!=c[i]:
    d+=1
if d<=2:
  print('YES')
else:
  print('NO')

Verdicts: Wrong Answer

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):
N = int(input())
p = [int(x) for x in input.split()]

count = 0
p_sorted = sorted(p)
for i in range(N):
    if p_sorted[i] != p[i]:
        count += 1
if count > 2:
    print("NO")
else:
    print("YES")
        

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

count = 0
p_sorted = sorted(p)
for i in range(N):
    if p_sorted[i] != p[i]:
        count += 1
if count > 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,d=map(int,input().split())
a=(2*d)+1
if n%a==0:
  print(int(n/a))
else:
  print((n//a)+1)


n,d=map(int,input().split())
a=(2*d)+1
if n%a==0:
  print(int(n/a))
else:
  print(int(n//a)+1)

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

Verdicts: Runtime Error

Runtime Error

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

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

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

count = 0
for i, e in enumerate(a):
    if i+1 != e:
        count += 1

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

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

count = 0
for i, e in enumerate(a):
    if i+1 != e:
        count += 1

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

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

count = 0
for i, e in enumerate(a):
    if i+1 != e:
        count += 1

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

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

count = 0
for i, e in enumerate(a):
    if i+1 != e:
        count += 1

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

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

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

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

a=list(map(int, input().split()))
correct=sorted(a)

p=0
for i in range(n-1):
  for j in range(n-i-1):
    a[i], a[n-j-1] = a[n-j-1], a[i]
    if a == correct:
      p += 1
      
    else:
      pass
    a[i], a[n-j-1] = a[n-j-1], a[i]
    
print(p)

n= int(input())

a=list(map(int, input().split()))
correct=sorted(a)

p=0
for i in range(n-1):
  for j in range(n-i-1):
    a[i], a[n-j-1] = a[n-j-1], a[i]
    if a == correct:
      p += 1
      
    else:
      pass
    a[i], a[n-j-1] = a[n-j-1], a[i]
    
if p == 1 or a == correct:
  print("YES")
else:
  print("NO")

Verdicts: Wrong Answer

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

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

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

n=int(input())
l=list(map(int,input().split()))
m=sum([i!=l[i] for i in range(n)])
print("YES" if m==0 or m==2 else "NO")

n=int(input())
l=list(map(int,input().split()))
m=sum([(i+1)!=l[i] for i in range(n)])
print("YES" if m==0 or m==2 else "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 = list(map(int, input().split()))
sorted_p = sorted(p)
arr = []
ban = [0 for l in range(n)]
for i in range(n):
    min_el = min(p[i:])
    idx = p.index(min_el)
    ban[idx] = 1
    if ban[i] != 1:
        arr.append(min_el)
        p[i], p[idx] = p[idx], p[i]
print ("YES" if arr == sorted_p else 'NO')

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

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

Verdicts: Wrong Answer

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

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

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

Verdicts: 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 i in range(n):
    if i + 1 == p[i]:
        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 i + 1 != p[i]:
        cnt += 1
if cnt <= 2:
    print("YES")
else:
    print("NO")


Verdicts: Wrong Answer

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

Submission attempts (in order):
N=int(input())
p=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")

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: 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 statistics
a=int(input())
#b,c=int(input()),int(input())
# c=[]

#     c.append(i)
#e1,e2 = map(int,input().split())
f = list(map(int,input().split()))
#g = [input() for _ in range(a)]

count=0
for i in range(a-1):
    if f[i]!=f[i+1]-1:
        f[i+1]=f[i]+1
        count+=1
if count==2 or count==0:
    print("YES")
else:
    print("NO")

# import math
# import statistics
a=int(input())
#b,c=int(input()),int(input())
# c=[]

#     c.append(i)
#e1,e2 = map(int,input().split())
f = list(map(int,input().split()))
#g = [input() for _ in range(a)]

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

for i in range(1,n+1):
    if i == p[i-1]:
        pass
    else:
        count += 1
        if count ==3:
            print('No')
            exit(0)
print('Yes')

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

for i in range(1,n+1):
    if i == p[i-1]:
        pass
    else:
        count += 1
        if count ==3:
            print('No')
            exit(0)
print('Yes')

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

for i in range(1,n+1):
    if i == p[i-1]:
        pass
    else:
        count += 1
        if count ==3:
            print('NO')
            exit(0)
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 = map(int, input().split())
P = list(P)


cnt = 0
for i in range(1, N):
    if P[i] < P[i - 1]:
        if cnt == 1:
            print('NO')
        else:
            v = P[i - 1]
            P[i] = P[i - 1]
            P[i - 1] = v
            cnt +=1
    else:
        continue

print('YES')

N = int(input())

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


cnt = 0

s_1 = 0
for i in range(N):
    if P[i] != i + 1:
        if cnt == 1:
            print('NO')
            exit()

        s_1 = i

        for j in range(N):
            if P[j] == i + 1:
                s_2 = j

                v = P[s_1]
                P[s_1] = P[s_2]
                P[s_2] = v
                cnt += 1
                break
            else:
                continue

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())
ps = map(int, input().split())
p2 = ps[0] - 1
for p in ps:
    if p > p2:
        p2 = p

    else:
        print("NO")
if p2 == p[-1]:
    print("YES")

n = int(input())
p = list(map(int, input().split()))
lis = sorted(list(range(1, n+1)))
l = len(p)
cache = l
for k, m in zip(lis, p):
    if k != m:
        l -= 1

if cache - l <= 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())
Y = [int(x) for x in input().split()]
Y_ = Y.copy()
Y_.sort()
test = [Y[i] == Y_[i] for i in range(len(Y))]
if test.count(False) <= 2:
  print("Yes")
else:
  print("No")

N = int(input())
Y = [int(x) for x in input().split()]
Y_ = Y.copy()
Y_.sort()
test = [Y[i] == Y_[i] for i in range(len(Y))]
if test.count(False) <= 2:
  print("YES")
else:
  print("NO")

Verdicts: Wrong Answer

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

Submission attempts (in order):
N = int(input())
A = list(map(int , input().split()))
count = 1
for i in range(0,len(A)-1):
    if A[i] < A[i+1]:
        count += 1
if count == N or count == 2:
    print('YES')
else:
    print('NO')

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

Verdicts: Wrong Answer

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

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

q = []
for x in range(N):
    q.append(x+1)

i = 0
c = 0
ans = "NO"
while(i < N):
    if p[i] != q[i]:
        c += 1
    if c > 2:
        break
    i += 1

if (c == 2) && (c == 0):
    ans = "YES"

print(ans)


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

q = []
for x in range(N):
    q.append(x+1)

i = 0
c = 0
ans = "NO"
while(i < N):
    if p[i] != q[i]:
        c += 1
    if c > 2:
        break
    i += 1

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

print(ans)

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

pn = sorted(p)

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

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

# Swap 0 or 1 Swap

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

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

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

# Swap 0 or 1 Swap

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

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

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


Verdicts: Wrong Answer

Wrong Answer

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

Submission attempts (in order):
# -*- coding: utf-8 -*-
from copy import deepcopy


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

    for i in range(n):
        for j in range(i, n):
            
            #     continue
            p_temp = deepcopy(p)
            temp = p_temp[i]
            p_temp[i] = p_temp[j]
            p_temp[j] = temp
            print(p, p_temp)
            if p_temp == sorted(p):
                print('YES')
                return

    print('NO')


if __name__ == "__main__":
    main()


# -*- coding: utf-8 -*-
from copy import deepcopy


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

    for i in range(n):
        for j in range(i, n):
            
            #     continue
            p_temp = deepcopy(p)
            temp = p_temp[i]
            p_temp[i] = p_temp[j]
            p_temp[j] = temp
            # print(p, p_temp)
            if p_temp == sorted(p):
                print('YES')
                return

    print('NO')


if __name__ == "__main__":
    main()


Verdicts: Wrong Answer

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

Submission attempts (in order):
n=int(input())
a=[int(i) for i in input().split()]
ans=0
ok=True
for i in range(n-1):
    if a[i]!=i+1:
        if a[a[i]-1]!=i+1:
            ok=False
if ok:
    print("Yes")
else:
    print("No")

n=int(input())
a=[int(i) for i in input().split()]
ans=0
kai=0
ok=True
for i in range(n-1):
    if a[i]!=i+1:
        kai+=1
        if a[a[i]-1]!=i+1 or kai==3:
            ok=False
if ok:
    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()))
B = sorted(A)
for i in range (N):
    if B[i] != A[i]:
        k += 1
if k >= 3:
    print("NO")
else:
    print("YES")

N = int(input())
A = list(map(int, input().split()))
B = sorted(A)
k = 0
for i in range (N):
    if B[i] != A[i]:
        k += 1
if k >= 3:
    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()))
CNT = 0
for i in range(N):
  if P[i] == i+1
    CNT += 1
print('YES' if  CNT <=  2 else 'NO')

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

Verdicts: Runtime Error

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

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

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

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



Verdicts: Wrong Answer

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

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


for i in range(n):
    for j in range(n):
        temp = list(copy(p))
        temp[i], temp[j] = temp[j], temp[i]
        sorted_temp = sorted(temp)

        if sorted_temp  == temp:
            print("YES")
            exit()

print("NO")

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

for i in range(n):
    for j in range(n):
        temp = p.copy()
        temp[i], temp[j] = temp[j], temp[i]
        sorted_temp = sorted(temp)

        if sorted_temp  == temp:
            print("YES")
            exit()

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()))
def check(L):
  for i in range(1, len(L)):
    if L[i] < L[i - 1]:
      return False
  return True
for i in range(n):
  for j in range(i + 1, n):
    if check(A[0:i] + [A[j]] + A[i+1:j] + [A[i]] + A[j+1:]):
      print('YES')
      return
print('NO')

n = int(input())
A = list(map(int, input().split()))
def check(L):
    for i in range(1, len(L)):
        if L[i] < L[i - 1]:
            return False
    return True
if check(A):
    print('YES')
else:
    for i in range(n):
        for j in range(i + 1, n):
            if check(A[0:i] + [A[j]] + A[i+1:j] + [A[i]] + A[j+1:]):
                print('YES')
                break
        else:
            continue
        break
    print('NO')


def solve(n, A):
    def check(L):
        for i in range(1, len(L)):
            if L[i] < L[i - 1]:
                return False
        return True
    if check(A):
        return 'YES'
    for i in range(n):
        for j in range(i + 1, n):
            if check(A[0:i] + [A[j]] + A[i + 1:j] + [A[i]] + A[j + 1:]):
                return 'YES'
    return 'NO'

_n = int(input())
_A = list(map(int, input().split()))
print(solve(_n, _A))

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

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


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

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

Verdicts: Wrong Answer

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

Submission attempts (in order):
# -*- coding:utf8 -*-

n = int(input())
l = list(map(int, input().split()))
c = 0
for i,n in enumerate(l,1):
    if n != i:
        c += 1
ans = 'Yes' if c == 0 or c == 2 else 'No'
print(ans)


# -*- coding:utf8 -*-

n = int(input())
l = list(map(int, input().split()))
c = 0
for i,n in enumerate(l,1):
    if n != i:
        c += 1
ans = 'YES' if c == 0 or c == 2 else 'NO'
print(ans)


Verdicts: Wrong Answer

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

Submission attempts (in order):
7
1 2 3 4 5 6 7

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

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

Verdicts: Runtime Error

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

Submission attempts (in order):
N = int(input())
P = input().split()
PP = [str(i) for i in range(1,N+1)]
diff = 0
for i in range(N):
    if P[i] != PP[i]:
        diff += 1
if diff <= 2:
    print('Yes')
else:
    print('No')

N = int(input())
P = input().split()
PP = [str(i) for i in range(1,N+1)]
diff = 0
for i in range(N):
    if P[i] != PP[i]:
        diff += 1
if diff <= 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()
 
p = map(int, input().split())
 
k = 0
 
for i in range(0, len(p)-1 ):
  if (p[i] > p[ i + 1 ]):
    k += 1
    
    
if ( k <= 1 ):
  print("YES")
else:
  print("NO")
  

N = int(input())

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

k = 0

for i in range(0, N-1 ):
  if (p[i] > p[ i + 1 ]):
    k += 1


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


N = int(input())

p = list()

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

k = 0

for i,number in enumerate(p):
  if (number > p[ i + 1 ]):
    k += 1

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

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

num_sort = num.sorted()
ans = 0

for i in range(N):
  if num[i] == num_sorted[i]:
    continue
  else:
    ans += 1
    
if ans <= 2:
  print("YES")
else:
  print("NO")

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

num_sort = sorted(num)
ans = 0

for i in range(N):
  if num[i] == num_sort[i]:
    continue
  else:
    ans += 1
    
if ans <= 2:
  print("YES")
else:
  print("NO")

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

counter=0
for i in range(n):
    print(i, p[i])
    if i+1 != p[i]:
        counter+=1

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

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

counter=0
for i in range(n):
    # print(i, p[i])
    if i+1 != p[i]:
        counter+=1

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


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


Verdicts: Wrong Answer

Accepted