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())
import numpy as np
p = np.array(list(map(int, input().split())))
ps = np.array(sorted(p))
s = np.sum(p==ps)
if s==0 or s==2:
  print("YES")
else:
  print("NO")

n = int(input())
import numpy as np
p = np.array(list(map(int, input().split())))
ps = np.array(sorted(p))
s = np.sum(p!=ps)
if s==0 or s==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())
S = list(map(int,input().split()))
B = list(reversed(S))
B.sort()
count = 0
for i in range(len(S)):
    if S[i] != B[i]:
        count += 1
if count == 2 or count == 0:
    print("Yes")
else:
    print("No")

N = int(input())
S = list(map(int,input().split()))
B = list(reversed(S))
B.sort()
count = 0
for i in range(len(S)):
    if S[i] != B[i]:
        count += 1
if count == 2 or count == 0:
    print("Yes")
else:
    print("No")

N = int(input())
S = list(map(int,input().split()))
B = list(reversed(S))
B.sort()
count = 0
for i in range(len(S)):
    if S[i] != B[i]:
        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):
import sys

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    p = string_to_int(inputs[0])

    diff_point = []
    for i, num in enumerate(range(1, len(p)+1)):
        if num != p[i]:
            diff_point.append(i)
    if len(diff_point) == 2 | | len(diff_point) == 0:
        return "YES"
    return "NO"


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)


import sys

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    p = string_to_int(inputs[0])

    diff_point = []
    for i, num in enumerate(range(1, len(p)+1)):
        if num != p[i]:
            diff_point.append(i)
    if len(diff_point) == 2 or len(diff_point) == 0:
        return "YES"
    return "NO"


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)


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()))
r=list(range(1,n+1))
s=0
m=0
if l==r:
  m=1
  print("YES")
else:
  while s<n:
    for i in range(n):
      r=list(range(1,n+1))
      d=r[s]
      r[s]=r[i]
      r[i]=d
      if l==r:
        print("Yes")
        s=n
        m=1
        break
    s=s+1
if not m==1:
  print("NO")

n=int(input())
l=list(map(int,input().split()))
r=list(range(1,n+1))
s=0
m=0
if l==r:
  m=1
  print("YES")
else:
  while s<n:
    for i in range(n):
      r=list(range(1,n+1))
      d=r[s]
      r[s]=r[i]
      r[i]=d
      if l==r:
        print("YES")
        s=n
        m=1
        break
    s=s+1
if not m==1:
  print("NO")

Verdicts: Wrong Answer

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

Submission attempts (in order):
# -*- coding: utf-8 -*-
"""
Created on Fri May 15 00:38:52 2020

@author: Kanaru Sato
"""

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

yesflag = 1
a = [p[i] for i in range(n)]
for k in range(n-1):
    if a[k] > a[k+1]:
        yesflag = 0
        break

if yesflag == 0:
    for i in range(n-1):
        for j in range(i+1,n):
            a = [p[i] for i in range(n)]
            tmp = a[i]
            a[i] = a[j]
            a[j] = tmp
            yesflag = 1
            for k in range(n-1):
                if a[k] > a[k+1]:
                    yesflag = 0
                    break
            if yesflag == 1:
                break
        if yesflag == 1:
            break

if yesflag == 1:
    print("Yes")
else:
    print("No")

# -*- coding: utf-8 -*-
"""
Created on Fri May 15 00:38:52 2020

@author: Kanaru Sato
"""

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

yesflag = 1
a = [p[i] for i in range(n)]
for k in range(n-1):
    if a[k] > a[k+1]:
        yesflag = 0
        break

if yesflag == 0:
    for i in range(n-1):
        for j in range(i+1,n):
            a = [p[i] for i in range(n)]
            tmp = a[i]
            a[i] = a[j]
            a[j] = tmp
            yesflag = 1
            for k in range(n-1):
                if a[k] > a[k+1]:
                    yesflag = 0
                    break
            if yesflag == 1:
                break
        if yesflag == 1:
            break

if yesflag == 1:
    print("YES")
else:
    print("NO")

Verdicts: Wrong Answer

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

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

l=list(range(1,n+1))
k=0
for i in range(n):
    if p[i]==l[i]:
        k+=1
if k==0 or k==2:
    print("YES")
else:
    print("NO")

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

l=list(range(1,n+1))
k=0
for i in range(n):
    if p[i]!=l[i]:
        k+=1
if k==0 or k==2:
    print("YES")
else:
    print("NO")

Verdicts: Wrong Answer

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

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

tmp1 = -1
tmp2 = -1
swap = False
ans = True
for i in range(1, N):
    if p[i - 1] > p[i]:
        if tmp1 < 0 and not swap:
            tmp1 = p[i - 1]
            tmp2 = p[i]
        elif not swap:
            if p[i] < tmp2 and p[i - 1] < tmp1:
                swap = True
            else:
                ans = False
                break
        else:
            ans = False
            break

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


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

cnt = 0

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


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


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

cnt = 0

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

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

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

N = int(input())
value = list(map(int, input().split()))
count = 0
for i in range(len(value)-1):
    ans = "Yes"
    if count <= 3:
        if value[i] + 1 == value[i+1]:
            continue
        else:
            count += 1
    else:
        break
if count >= 4:
    ans = "No"
print(ans)

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

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

N = int(input())
List = [int(i) for i in input().split()]
count = 0
for j in range(N):
    if(List[j] != j+1):
        count+=1
if(count < 3):
    print("YES")
else:
    print("NO")

Verdicts: Wrong Answer

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

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

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

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

Verdicts: Wrong Answer

Runtime Error

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

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

wrong = 0
for i, p in enemerate(map(int, input().split()), start=1):
  wrong += int(i != p)

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

n = int(input())

wrong = 0
for i, p in enumerate(map(int, input().split()), start=1):
  wrong += int(i != p)

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

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

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

true_num = copy.deepcopy(num)
true_num = sorted(true_num)

swap_org=[]
swap_true=[]

count=0
for x,y in zip(num,true_num):
    if x != y:
        count += 1
        swap_org.append(x)
        swap_true.append(y)

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

import copy 

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

true_num = copy.deepcopy(num)
true_num = sorted(true_num)

swap_org=[]
swap_true=[]

count=0
for x,y in zip(num,true_num):
    if x != y:
        count += 1
        swap_org.append(x)
        swap_true.append(y)


for i in range(len(swap_org)-1):
    if swap_org[i] == swap_true[i+1] and swap_org[i+1] == swap_true[i]:
            count-=2
if count>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, = map(int, input().split())

v = sum(1 for i,j in zip(range(1, N+1), p) if i!=j)
print("Yes" if v<=2 else "No")

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

v = sum(1 for i,j in zip(range(1, N+1), p) if i!=j)
print("YES" if v<=2 else "NO")

Verdicts: Wrong Answer

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

Submission attempts (in order):
N = int(input())
p = [int(s) for s in input().split()]

print('Yes' if sum(map(lambda x: x[0] == x[1], zip(p, sorted(p)))) >= N - 2 else 'No')


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

print('YES' if sum(map(lambda x: x[0] == x[1], zip(p, sorted(p)))) >= N - 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())
false=0
p=[int(N) for N in input().split()]
for i in range(N):
     if p[i]!=i+1:
          false+=1
if false>2:
     print("No")
else:
     print("Yes")


N=int(input())
false=0
p=[int(N) for N in input().split()]
for i in range(N):
     if p[i]!=i+1:
          false+=1
if false>2:
     print("NO")
else:
     print("YES")


Verdicts: Wrong Answer

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

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

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

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

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

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

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

Verdicts: Wrong Answer

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

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

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

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

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

Verdicts: Wrong Answer

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

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

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

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

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


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

swap = 0

for i in range(n):
    min_num = p[i]
    min_j = i
    for j in range(i, n):
        if min_num > p[j]:
            min_num = p[j]
            min_j = j
    if min_j != i:
        p[i] ,p[min_j] = p[min_j], p[i] 
        swap += 1
    # print(swap)
    # print(p)
if swap <= 1:
    print("YES")
else:
    print("NO")


Verdicts: Wrong Answer

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

Submission attempts (in order):
N = int(input())
li_p = list(map(int, input().split()))
count = 0
flag = True
for i in range(N):
    if li_p[i] != i+1:
        count += 1
        if count > 2:
            flag = False
            break
if flag:
    print("Yes")
else:
    print("No")

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

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

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

Verdicts: Wrong Answer

Runtime Error

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

Submission attempts (in order):
n=int(input())
P=list(map(int,input().split()))
S=sorted(P)
c=0
ans="No"
for i in range(n):
    if P[i]!=S[i]:
        c+=1
if c<=2 :
    ans ="Yes"
print(ans)

n=int(input())
P=list(map(int,input().split()))
S=sorted(P)
c=0
ans="NO"
for i in range(n):
    if P[i]!=S[i]:
        c+=1
if c<=2 :
    ans ="YES"
print(ans)

Verdicts: Wrong Answer

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

Submission attempts (in order):
list = [for int(i) in input.split()]

count = 0
for i in range(0, len(list)-1):
  if list[i] < list[i+1]:
    count += 1
  	
if count > 2:
  print('NO')
else:
  print('YES')

a = [for int(i) in input.split()]
 
count = 0
for i in range(0, len(a)-1):
  if a[i] > a[i+1]:
    count += 1
    if count > 2:
      print('NO')
      break
  
  if i == len(a)-1:
    print('YES')


N = int(input())
num_list = [int(_) for _ in input().split()]
 
count = 0
 
for i in range(0, N):
  if num_list[i] != i+1:
    count += 1
    
if count <= 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):
# -*- coding: utf-8 -*-
#B
import sys
import math


n = int(input())
tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))

#print(hoge)

for i in range(0,n-1):
	if(hoge[i]<hoge[i+1]):
		if(i==n-2):
			print("YES")
			sys.exit()
	else:
		break

for i in range(0,n-1):
	for j in range(i+1,n):
		k=hoge[j]
		hoge[j]=hoge[i]
		hoge[i]=k
		for m in range(0,n-1):
			if(hoge[m]<hoge[m+1]):
				if(m==n-2):
					print("YES")
					sys.exit()
			else:
				break

print("NO")

# -*- coding: utf-8 -*-
#B
import sys
#import math


n = int(input())
tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))

#print(hoge)

for i in range(0,n-1):
	if(hoge[i]<hoge[i+1]):
		if(i==n-2):
			print("YES")
			sys.exit()
	else:
		break

for i in range(0,n-1):
	for j in range(i+1,n):
		k=hoge[j]
		hoge[j]=hoge[i]
		hoge[i]=k
		for m in range(0,n-1):
			if(hoge[m]<hoge[m+1]):
				if(m==n-2):
					print("YES")
					sys.exit()
			else:
				break
		k=hoge[j]
		hoge[j]=hoge[i]
		hoge[i]=k

print("NO")

Verdicts: Wrong Answer

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

Submission attempts (in order):
N=int(input())
p=list(map(int, input().split()))
count=0
for i in range(N-1):
    A=p[i+1]
    B=p[i]
    print(A)
    print(B)
    if A < B:
        count=count+1
        if count >= 3:
            print('NO')
            break
    if A > B:
        if i == (N-1) and count < 3:
            print('YES')
            break

N=int(input())
p=list(map(int, input().split()))
count=0
for i in range(N-1):
    A=p[i+1]
    B=p[i]-1
    if A < B:
        count=count+1
        if count >= 3:
            print('NO')
            break
    if i == (N-1) and count < 3:
        print('YES')
        break

N=int(input())
p=list(map(int, input().split()))
count=0
for i in range(N-1):
    A=p[i+1]
    B=p[i]
    if A < B:
        count=count+1
        if count >= 3:
            print('NO')
            break
    if i == (N-1) and count < 3:
        print('YES')
        break

N=int(input())
p=list(map(int, input().split()))
badcount=0
goodcount=0
for i in range(N-1):
    A=p[i+1]
    B=p[i]
    if A < B:
        badcount=badcount+1
        if badcount ==1:
            C=B
        elif badcount == 2 and C < B:
            print('NO')
            break
        elif badcount > 2:
            print('NO')
            break            
    elif A > B:
        goodcount=goodcount+1
        if goodcount > (N-2):
            print('YES')
            break

N=int(input())
p=list(map(int, input().split()))
count=0
for i in range(N-1):
    A=p[i+1]
    B=p[i]
    if A < B:
        count=count+1
        if count >= 3:
            print('NO')
            break
    if A > B:
        if i == (N-1) and count < 3:
            print('YES')
            break

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

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

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

Submission attempts (in order):
n = int(input())
p = [int(input()) for i in range(n)]
count =0
for s,t in enumerate(p):
	print(s,t)
	if s !=(t-1):
		count+=1
if count == 2 or count == 0:
	print("YES")
else:
	print("NO")

n = int(input())
p = [int(input(i)) for i in range(n)]
count =0
for s,t in enumerate(p):
	print(s,t)
	if s !=(t-1):
		count+=1
if count == 2 or count == 0:
	print("YES")
else:
	print("NO")

n = int(input())
p = [int(input(i)) for i in range(n)]
count =0
for s,t in enumerate(p):
	print(s,t)
	if s !=(t-1):
		count+=1
if count == 2 or count == 0:
	print("YES")
else:
	print("NO")

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

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


Verdicts: Runtime Error

Runtime Error

Runtime Error

Wrong Answer

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

Submission attempts (in order):
S = int(input())
slist = input().split()

new_list = sorted(slist)
d_count = 0
for i,j in zip(slist,new_list):
  if i != j:
    d_count += 1
    
if d_count == 2:
  print('Yes')
elif d_count ==0:
  print('Yes')
else:
  print('No')


S = int(input())
slist = input().split()

for i,a in enumerate(slist):
  slist[i] = int(a)

new_list = sorted(slist)
d_count = 0
for i,j in zip(slist,new_list):
  if i != j:
    d_count += 1
    
if d_count <= 2:
  print('Yes')
else:
  print('No')

S = int(input())
slist = input().split()

for i,a in enumerate(slist):
  slist[i] = int(a)

new_list = sorted(slist)
d_count = 0
for i,j in zip(slist,new_list):
  if i != j:
    d_count += 1
    
if d_count == 2:
  print('Yes')
elif d_count ==0:
  print('Yes')
else:
  print('No')

S = int(input())
slist = input().split()

new_list = sorted(slist)
d_count = 0
for i,j in zip(slist,new_list):
  if i != j:
    d_count += 1
    
if d_count > 2:
  print('No')
else:
  print('Yes')

S = int(input())
slist = input().split()

new_list = sorted(slist)
d_count = 0
for i,j in zip(slist,new_list):
  if i != j:
    d_count += 1
    
if d_count > 3:
  print('No')
else:
  print('Yes')

S = int(input())
slist = input().split()

for i,a in enumerate(slist):
  slist[i] = int(a)

new_list = sorted(slist)
d_count = 0
for i,j in zip(slist,new_list):
  if i != j:
    d_count += 1
    
if d_count == 2:
  print('Yes')
elif d_count ==0:
  print('Yes')
else:
  print('No')


S = int(input())
slist = input().split()

for i,a in enumerate(slist):
  slist[i] = int(a)

new_list = sorted(slist)
d_count = 0
for i,j in zip(slist,new_list):
  if i != j:
    d_count += 1
    
if d_count <= 2:
  print('YES')
else:
  print('NO')

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

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

Submission attempts (in order):
N=list(input())
for i,j in range(N):
  N2=N[i],N[j]=N[j],N[i]
  if N2==N.sort():
    print("YES")
    break
else:
  print("NO")
  

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

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

N=list(input())
for i,j in range(N):
  N[i],N[j]=N[j],N[i]
  if N==N.sort():
    print("YES")
    break
else:
  print("NO")

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

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

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

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


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


cnt = 0
n = int(input())
for i int rangr(1, n + 1):
  p = map(int, input().split())
  if int(i) != p :
    cnt += 1
    if cnt >= 2:
      break
if cnt <= 1 :
  print("YES")
else :
   print("NO")


cnt = 0
n = int(input())
for i int range(1, n + 1):
  p = int(input())
  if int(i) != p :
    cnt += 1
    if cnt >= 2:
      break
if cnt <= 1 :
  print("YES")
else :
   print("NO")


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


cnt = 0
n = int(input())
for i int rangr(1, n + 1):
  p = int(input())
  if int(i) != p :
    cnt += 1
    if cnt >= 2:
      break
if cnt <= 1 :
  print("YES")
else :
   print("NO")


cnt = 0
n = int(input())
for i int rangr(1, n + 1):
  p = map(int, input().split()
  if int(i) != p :
    cnt += 1
    if cnt >= 2:
      break
if cnt <= 1 :
  print("YES")
else :
   print("NO)

cnt = 0
n = int(input())
for i in range(1, n + 1):
  p = int(input())
  if int(i) != p :
    cnt += 1
    if cnt >= 2:
      break
if cnt <= 1 :
  print("YES")
else :
   print("NO")


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


Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

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

Submission attempts (in order):
N = input()
p = list(map(int,input().split()))
s = sorted(p)
k = 0
for i in range(N):
  if p[i]!=s[i]:
    k += 1
if k < 3 :
   print("YES")
else:
   print("NO")

N = int(input())
p = list(map(int,input().split()))
s = sorted(p)
k = 0
for i in range(N):
  if p[i]!=s[i]:
    k += 1
if k < 3 :
   print("YES")
else:
   print("NO")

Verdicts: Runtime Error

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

Submission attempts (in order):
N = int(input())
P = input().split()
P = [int(p) for p in P]

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

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

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

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

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

Verdicts: Wrong Answer

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

res = "Yes"
if list(range(1, n+1)) == p:
  res = "Yes"
else:
  count = 0
  for n_e, p_e in zip(range(1,n+1), p):
    if n_e != p_e:
      count += 1
    if count == 3:
      res = "No"
      break


print(res)

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

res = "YES"
if list(range(1, n+1)) == p:
  res = "YES"
else:
  count = 0
  for n_e, p_e in zip(range(1,n+1), p):
    if n_e != p_e:
      count += 1
    if count == 3:
      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()))
p_t = [i for i in range(1, N+1)]
count = 0
for i in range(N):
    if p[i] != p_t[i]:
        count += 1

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

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

print('NO' if cnt > 2 else 'YES')

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

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

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

Verdicts: Wrong Answer

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

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

l = sorted(p)
count = 0

for a, b in zip(p, l):
    if (a is not b): count += 1

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

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

l = sorted(p)
count = 0

for a, b in zip(p, l):
    if (a is not b): count += 1

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

Verdicts: Runtime Error

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

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

cnt = 0
for i in range(len(p)):
  cnt += 1 if p[i] != i + 1 else 0

print("Yes") if cnt in [0, 2] else print("No")

N = int(input())
p = list(map(lambda x: int(x), input().split(" ")))

cnt = 0
for i in range(len(p)):
  cnt += 1 if p[i] != i + 1 else 0

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


zn=int(input())
p=[int(i) for i in input().split()]
count=0
for i in range(n-1):
    for j in range(i+1,n):
        #print(p[i],p[j])
        if p[i]>p[j]:
            count+=1
if count>=3:
    print("NO")
else:
    print("YES")


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


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


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


Verdicts: Wrong Answer

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

lN=[]
for i in range(1,N+1):
  lN.append(i)
  
cnt = 0  
for i in range(N):
  if lN[i] != P[i]:
    cnt += 1
      
if cnt == 0 or 2:    
  print("Yes")
else:
  print("No")

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

lN=[]
for i in range(1,N+1):
  lN.append(i)
  
cnt = 0  
for i in range(N):
  if lN[i] != P[i]:
    cnt += 1
      
if cnt == 0 or cnt == 2:    
  print("Yes")
else:
  print("No")

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

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

q = sorted(p)
ans = 0
for _p, _q in zip(p, q):
    if _p != _q:
        ans += 1

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


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

j=1
numofswap=0
for i in range(n):
    if p[i] != j:
        numofswap+=1
    j+=1

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


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

j=1
numofswap=0
for _p in p:
    if _p != j:
        numofswap+=0.5
    j+=1

print("Yes" if numofswap == 0 or numofswap == 1 else "No")


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

q = sorted(p)
ans = 0
for _p, _q in zip(p, q):
    if _p != _q:
        ans += 1

print("YES" if ans <= 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()))

if p == list(range(1, N+1)):
    print('YES')
else:
    for i, n in enumerate(p):
        if n != i+1:
            break
    j = p[p.index(i+1)]
    p[p.index(i+1)] = n
    p[i] = j
    if p == list(range(1, N+1)):
        print('Yes')
    else:
        print('NO')

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

count = 0
for n, p in zip(range(1, N+1), P):
    if n != p:
        if count == 0:
            count += 1
            i = P.index(p)
            j = P.index(n)
            P[j] = P[i]
            P[i] = n
        else:
            print('NO')
            break
else:
    print('YES')

Verdicts: Wrong Answer

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

Submission attempts (in order):
n = int(input())
l = list(map(int,input().split()))
m = 0
out = 0
 
for num in range(n):
  if(m + 1 != l[m]):
    out += 1
  m += 1
 
if(out > 2):
  print('No')
else:
  print('Yes')

n = int(input())
l = list(map(int,input().split()))
m = 0
out = 0

for num in range(n):
  if(m + 1 != l[m]):
    out += 0
  m += 1

if(out > 2):
  print('No')
else:
  print('Yes')
  

n = int(input())
l = list(map(int,input().split()))
m = 0
out = 0
 
for num in range(n):
  if(m + 1 != l[m]):
    out += 1
  m += 1
 
if(out > 2):
  print('NO')
else:
  print('YES')

Verdicts: Wrong Answer

Wrong Answer

Accepted