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):
def quicksort_count(arg):
    left = []
    right = []

    if len(arg)<=1:
        return arg

    p = random.choice(arg)
    p_count = 0
    
    for ele in arg:
        if ele < p:
            left.append(ele)
        elif ele > p:
            right.append(ele)
        else:
            p_count+=1
    left = quicksort_count(left)
    right = quicksort_count(right)
    return left + [p]*p_count + right

import random
N=int(input())
p = [int(x) for x in input().split()]
k=0

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

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


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

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

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


Verdicts: Wrong Answer

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

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

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

Verdicts: Wrong Answer

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

Submission attempts (in order):
def main(li):
    count = 0
    for i in range(len(li)):
        if li[i] != i + 1:
            count += 1
    if count in [0,2]:
      return True
    else:
      return False
 
 
if __name__ == '__main__':
    li = list(map(int, input().split()))
    if main(li):
        print('YES')
    else:
        print('NO')

def main(li):
    count = 0
    for i in range(len(li)):
        if li[i] != i + 1:
            count += 1
    if count == 2 or count == 0:
      return True
   	else:
      return False


if __name__ == '__main__':
    li = list(map(int, input().split()))
    if main(li):
        print('YES')
    else:
        print('NO')


def main(li):
    count = 0
    for i in range(len(li)):
        if li[i] != i + 1:
            count += 1
    if count in [0, 2]:
        return True
    else:
        False


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

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

Verdicts: Wrong Answer

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

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

if not tmp:
    print('YES')
elif len(tmp) == 2:
    print(tmp)
    p[tmp[0]], p[tmp[1]] = p[tmp[1]], p[tmp[0]]
    tmp = [i for i in range(N) if P[i] - p[i] != 0]
    if tmp:
        print('NO')
    else:
        print('YES')
else:
    print('NO')

N = int(input())
p = list(map(int, input().split()))
P = list(range(1,N+1))
tmp = [P[i]-p[i] for i in range(N)]
tmp = set(tmp)
tmp.discard(0)
if not tmp:
    print('YES')
elif len(tmp) == 2 and abs(tmp[0]) == abs(tmp[1]):
    print('YES')
else:
    print('NO')

N = int(input())
p = list(map(int, input().split()))
P = list(range(1,N+1))
if p == P:
    print('YES')
    exit()

tmp = [i for i in range(N) if P[i] - p[i] != 0]
#print(tmp)

if len(tmp) != 2:
    print('NO')
else:
    p[tmp[0]], p[tmp[1]] = p[tmp[1]], p[tmp[0]]
    if p == P:
        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())
a=[int(x) for x in input().split()]

b=sorted(a)

ans=0
for i in range(n):
  if a[i]!=b[i]:
    ans+=1
print("Yes" if ans<=2 else "No")


def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n): return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit

# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx

# from heapq import heapify,heappush,heappop
n=n0()
p=n1()
f=False
q=sorted(p)

if p==q:
    f=True
else:
    for i in range(n):
        for j in range(i+1,n):
            a=p.copy()
            a[i],a[j]=a[j],a[i]
            if a==q:
                f=True
                break
p0(f,"YES","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 = input()
l = list(map(int, input().split()))
t = sorted(l)
count = 0
for i in l:
    if l[i] == t[i]:
        count += 1

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

N = int(input())
l = [list(map(int, input().split())) for _ in range(1)][0]
t = sorted(l)
count = 0
for i in range(len(l)):
    if l[i] == t[i]:
        count += 1

if count == N - 2 or count == N:
    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):
def check(a):
  for i in range(1,len(n)):
    if a[i-1]>a[i]:
      return False
  return True
n=int(input())
a=list(map(int,input().split()))
if check(a):
  print('YES')
  exit()
for i in range(n):
  for j in range(n):
    if i==j:
      continue
    a[i],a[j]=a[j],a[i]
    if check(a):
      print('YES')
      exit()
    a[i],a[j]=a[j],a[i]
print('NO')

def check(a):
  for i in range(1,len(a)):
    if a[i-1]>a[i]:
      return False
  return True
n=int(input())
a=list(map(int,input().split()))
if check(a):
  print('YES')
  exit()
for i in range(n):
  for j in range(n):
    if i==j:
      continue
    a[i],a[j]=a[j],a[i]
    if check(a):
      print('YES')
      exit()
    a[i],a[j]=a[j],a[i]
print('NO')

Verdicts: Runtime Error

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

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

p_sorted = p.sorted()

diff = 0
for p_elem, p_sorted_elem in zip(p, p_sorted):
  	if p_elem !+ p_sorted_elem:
      	diff += 1

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

    input()
    p = [int(x) for x in input().split()]
     
    p_sorted = p.sorted()
     
    diff = 0
    for p_elem, p_sorted_elem in zip(p, p_sorted):
      	if p_elem !+ p_sorted_elem:
          	diff += 1
     
    if diff == 0 or diff == 2:
      	print('YES')
    else:
      	print('NO')

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

p_sorted = sorted(p)

diff = 0
for p_elem, p_sorted_elem in zip(p, p_sorted):
  	if p_elem !+ p_sorted_elem:
      	diff += 1

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



input()
p = [int(x) for x in input().split()]
    
p_sorted = sorted(p)
    
diff = 0
for p_elem, p_sorted_elem in zip(p, p_sorted):
    if p_elem != p_sorted_elem:
        diff += 1
    
if diff == 0 or diff == 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()))
m = list(range(1,n+1))
count = 0
for i in range(n):
    if p[i] != m[i]:
        count += 1
if count == 0 or count == 2:
    print("Yes")
else:
    print("No")

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

Verdicts: Wrong Answer

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

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

n=int(input())
p=list(map(in,input().split()))
t=list(range(1,n+1))
cnt=0
for pp in p:
  for tt in t:
    if pp!=tt:
      cnt+=1
print('Yes' if 0<=cnt<=2 else 'No')

n=int(input())
listp=list(map(int,input().split()))
for i in range(1,n):
  for j in range(2,n+1):
    a=listp[i-1]
    b=listp[j-1]
    listp[i-1]=b
    listp[j-1]=a
    for y in range(n):
      if listp[y]==y+1:
        print('Yes')
        exit()
      listp[i-1]=a
      listp[j-1]=b
for x in range(n):
  if listp[x]==x+1:
    print('Yes')
    exit()
print('No')

n=int(input())
listp=list(map(int,input().split()))
for i in range(1,n):
  for j in range(2,n+1):
    a=listp[i-1]
    b=listp[j-1]
    listp[i-1]=b
    listp[j-1]=a
    for y in range(n):
      if listp[y]==y+1:
        print('Yes')
        exit()
for x in range(n):
  if listp[x]==x+1
    print('Yes')
    exit()
print('No')
               

n=int(input())
listp=list(map(int,input().split()))
for i in range(1,n):
  for j in range(2,n+1):
    a=listp[i-1]
    b=listp[j-1]
    listp[i-1]=b
    listp[j-1]=a
    for y in range(n):
      if listp[y]!=y+1:
        print('No')
        exit()
for x in range(n):
  if listp[x]!=x+1:
    print('No')
    exit()
print('Yes')

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

Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Runtime Error

Wrong Answer

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

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


if __name__ == '__main__':
  main()

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

ans = 0
for i in range(len(a)):
  if i != a[i]-1:
    ans += 1
    
if ans <= 2:
  print("YES")
else:
  print("NO")

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

ans = 0
for i in a:
  if i != a[i]-1:
    ans += 1
    
if ans <= 2:
  print("YES")
else:
  print("NO")

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

ans = 0
for i in a:
  if i != a[i]:
    ans += 1
    
if ans <= 2:
  print("YES")
else:
  print("NO")

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

ans = 0
for i in range(len(a)):
  if i != a[i]-1:
    ans += 1
    
if ans <= 2:
  print("YES")
else:
  print("NO")

Verdicts: Runtime Error

Runtime Error

Runtime Error

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

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

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


Verdicts: Wrong Answer

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

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

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

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

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

Verdicts: Wrong Answer

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

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

c = 0

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

if c==0 or 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 :
      break

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

P=sorted(A)
cnt=0

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

print("YES" if cnt <= 1 else "NO")


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

P=sorted(A)
cnt=0

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

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


Verdicts: Wrong Answer

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

Submission attempts (in order):
n = int(input())
p = list(map(int,input().split()))
c = 0
for i in range(1,n+1):
  if p != i:
    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(1,n+1):
  if p != i:
    c += 1
if c == 2 or c == 0:
  print("YES")
else:
  print("NO")

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

print(out)

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

print(out)

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

permulated = len(1 for k, p in enumerate(P, 1) if p != k)
print('YES' if permulated <= 2 else 'NO')  

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

permulated = len([1 for k, p in enumerate(P, 1) if p != k])
print('YES' if permulated <= 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())

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

k = s.copy()

k.sort(reverse = True)

t = 0

for i in range(n):
    if s[i] != k[i]:
        t += 1
        
if t<3:
    print("Yes")
else:
    print("No")

n = int(input())
s = list(map(int,input().split()))
t = s.copy()
t.sort()
cnt = 0
for i in range(n):
    if s[i] != t[i]:
        cnt += 1
if cnt<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())
Sort = [str(x) for x in range(1,N+1)]
P = [str(x) for x in input().split()]

Count = 0
for T in range(0,N):
    if Sort[T] != P[T]:
        print(Sort[T])
        Count += 1
if Count==0 or Count==2:
    print('YES')
else:
    print('NO')

N = int(input())
Sort = ''.join([str(x) for x in range(1,N+1)])
P = ''.join([str(x) for x in input().split()])

Flag = True
Count = 0
for SC,TC in zip(Sort,P):
    if SC != TC:
        Count += 1
    if Count >= 3:
        Flag = False
        break
if Flag:
    print('Yes')
else:
    print('No')

N = int(input())
Sort = [str(x) for x in range(1,N+1)]
P = [str(x) for x in input().split()]

Count = 0
for T in range(0,N):
    if Sort[T] != P[T]:
        Count += 1
if Count==0 or Count==2:
    print('YES')
else:
    print('NO')

Verdicts: Wrong Answer

Wrong Answer

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

Submission attempts (in order):
def check(n,l):
    flag = True
    for i in range(n-1):
        if l[i] > l[i+1]:
            flag = False
            break
    if flag:
        return True
    else:
        return False

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

flag = check(n,l)
if flag:
    print("YES")
else:
    for i in range(n-1):
        x = l[i]
        l[i] = l[i+1]
        l[i+1] = x
        if check(n,l):
            flag = True
            break
        else:
            l[i+1] = l[i]
            l[i] = x
    if flag:
        print('YES')
    else:
        print('NO')

n = int(input())
l = list(map(int,input().split()))
count = 0
for i in range(n):
    if i+1 != l[i]:
        count += 1
        if count == 3:
            break
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):
from collections import deque
N = int(input())
M = deque(map(int, input().split()))

j = []

prev = M.popleft()

for i in range(N-1):
    cor = M.popleft()
    if cor > prev:
        j.append(True)
    else:
        j.append(False)

    prev = cor

if all(j) == True:
    print('Yes')
elif j[0] == j[-1] == False:
    print('Yes')
else:
    print('No')

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

count = 0
for i, m enumerate(M, 1):
    if i != m:
        count += 1

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

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

count = 0
for i, m in enumerate(M, 1):
    if i != m:
        count += 1

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

Verdicts: Wrong Answer

Runtime Error

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

Submission attempts (in order):
N=int(input())
p=list(map(int,input().split()))
A=p.copy()
A.sort()
if p==A:
  print("YES")
else:
  i=p.index(max(p))
  min1=p[N-1]
  for j in range(N-2,0,-1):
    if p[j]<min1:
      min1=p[j]
      min_index=j
  p[i],p[min_index]=p[min_index],p[i]
  if p==A:
    print("YES")
  else:
    print("NO")

N=int(input())
p=list(map(int,input().split()))
A=p.copy()
A.sort()
if p==A:
  print("YES")
else:
  flag=0
  for i in range(N):
    for j in range(i):
      p[i],p[j]=p[j],p[i]
      if p==A:
        flag=1
        break
      else:
        p[i],p[j]=p[j],p[i]
    if flag==1:
      break
  if flag==0:
    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):

A = int(input())

S = input()

S_list = list(S)
for i in range(A-1):
  S_list.remove(" ")

A_list = []
for i in range(A):
  A_list.append(i+1)


counter = 0
for i in range(A):
  if(A_list[i] != S_list[i]):
    counter = counter + 1

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



A = int(input())

S = input()

S_list = list(S)
for i in range(A-1):
    S_list.remove(" ")

A_list = []
for i in range(A):
  A_list.append(i+1)

print(A_list) 
print(S_list)

counter = 0
for i in range(A):
  if(A_list[i] != S_list[i]):
    counter = counter + 1
    print(counter)

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


A = int(input())

S = input()

S_list = list(S)
for i in range(A-1):
  S_list.remove(" ")

A_list = []
for i in range(A):
  A_list.append(i+1)

print(A_list) 
print(S_list)

counter = 0
for i in range(A):
  if(A_list[i] != S_list[i]):
    counter = counter + 1
    print(counter)

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



A = int(input())

S = input()

S_list = list(S)
for i in range(A-1):
    S_list.remove(" ")

A_list = []
for i in range(A):
  A_list.append(i+1)


counter = 0
for i in range(A):
  if(A_list[i] != S_list[i]):
    counter = counter + 1
    print(counter)

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



A = int(input())

S = input()

S_list = list(S)
S_list.remove(" ")

A_list = []
for i in range(A):
  A_list.append(i+1)
  
counter = 0
for i in range(A):
  if(A_list[i] != S_list[i]):
    counter = counter + 1

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



A = int(input())

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

A_list = []
for i in range(A):
  A_list.append(i+1)
  S_list[i] = int(S_list[i])
    

counter = 0
for i in range(A):
  if(A_list[i] != S_list[i]):
    counter = counter + 1

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

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

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


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


Verdicts: Runtime Error

Wrong Answer

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

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

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

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

cnt=0
for i in range(N):
    if(a[i]!=i+1):
        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):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


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

    k = sum(1 for i, p in enumerate(P, 1) if i != p)

    if k > 2:
        print('NO')
    else:
        print('Yes')


if __name__ == '__main__':
    main()


import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


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

    k = sum(1 for i, p in enumerate(P, 1) if i != p)

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


if __name__ == '__main__':
    main()


Verdicts: Wrong Answer

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

Submission attempts (in order):
n=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
ct=0
for i in range(n):
  if i+1!=P[i]:
    ct+=1
print("YES" if ct<=2 else "NO")

n=int(input())
P=[int(i) for i in input().split()]
ct=0
for i in range(n):
  if i+1!=P[i]:
    ct+=1
print("YES" if ct<=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):
a = int(input())
l = list(map(int, input().split()))
x = l.sorted()
for i in range(a):
  if x[i] ==l[i]:
    b +=1
if b ==2:
  print('YES')
else:
  print('NO')

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

for i in range(n):
    p[i]-=1
cnt=0
ans="Yes"
for i,p_i in enumerate(p):
    if i==p_i:
        continue
    cnt+=1
    if cnt>1:
        ans="No"
        break
    for j,p_j in enumerate(p):
        if i==p_j:
            p[j]=p_i
            p[i]=p_j
            break

print(ans)

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

for i in range(n):
    p[i]-=1
cnt=0
ans="YES"
for i,p_i in enumerate(p):
    if i==p_i:
        continue
    cnt+=1
    if cnt>1:
        ans="NO"
        break
    for j,p_j in enumerate(p):
        if i==p_j:
            p[j]=p_i
            p[i]=p_j
            break

print(ans)

Verdicts: Wrong Answer

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

Submission attempts (in order):
n = int(input())
p = [int(i) for i in input().split()]
count = 0
for i in range(n):
    print(i)
    if p[i] != i + 1:
        count += 1
print(count)
if count == 0:
    print('YES')

if count == 2:
    print('YES')

if count > 2:
    print('No')


n=int(input())
p=list(map(int,input().split()))
ok=True
for i in range(1,n):
  if p[i]-p[i-1]>0:
    continue
  ok=False
if ok:
  print("YES")
  exit(0)

for i in range(n):
  for j in range(n):
    if i==j:continue
    t=p[:]
    taihi=t[i]
    t[i]=t[j]
    t[j]=taihi
    ok=True
    for k in range(1,n):
      if t[k]-t[k-1]>0:
        continue
      ok=False
    if ok:
      print("YES")
      exit(0)
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())
MM = input().split()
count = 0
list1 =[]
for i in MM:
  a = int(i)
  list1.append(a)
list2 = sorted(list1)
for i,j in zip(list1,list2):
  
  if i != j:
    
    count +=1
if count >2:
  print('No')
else:
  print('Yes')

N = int(input())
MM = input().split()
count = 0
list1 =[]
for i in MM:
  a = int(i)
  list1.append(a)
list2 = sorted(list1)
for i,j in zip(list1,list2):
  
  if i != j:
    
    count +=1
if count >2:
  print('No')
else:
  print('Yes')

N = int(input())
MM = input().split()
count = 0
list1 =[]
for i in MM:
  a = int(i)
  list1.append(a)
list2 = sorted(list1)
for i,j in zip(list1,list2):
  
  if i != j:
    
    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())
s=list(map(int,input(),split()))
t=sorted(s)
g=0
for i in range(N):
  if t[i]!=s[i]:
    g+=1
if g==2:
  print("YES")
else:
  print("NO")

N=int(input())
s=list(map(int,input().split()))
t=sorted(s)
g=0
for i in range(N):
  if t[i]!=s[i]:
    g+=1
if g==2 or g==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(' ')))
count=0
flg=1

for i in range(N):
  if P[i]!=i+1:
    if count==0:
      if P[P.index(i+1)]!=i+1:
        if flg:
          print("NO")
          flg=0
      else:
        P[i],P[P.index(i+1)]=P[P.index(i+1)],P[i]
        count+=1
    else:
      if flg:
        print("NO")
        flg=0
        
if flg:
  print("YES")


import numpy as np
N=int(input())
P=list(map(int,input().split(' ')))

res=0
for i,x in enumerate(P):
  if i+1!=x:
    res+=1
if res>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:
        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:
        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:
        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:
    count += 1
    
if count <= 2:
  print('YES')
else:
  print('NO')


  

Verdicts: Runtime Error

Runtime Error

Wrong Answer

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

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

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

N = int(input())
A = list(map(int, input().strip().split()))
count = 0
for i in range(N):
  if not i == A[i]:
    count+=1
    if A[i]+A[N-i]==N+1:
      continue
    if count >=3:
      break
      print("NO")
    print("YES")
    

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

Verdicts: Wrong Answer

Wrong Answer

Runtime Error

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

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

    diff = 0
    for i in range(N):
        if (i+1) != p[i]:
            diff += 1
    if (diff == 2) | (diff == 0):
        return "Yes"
    return "No"
if __name__ == '__main__':
    print(main())

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

    diff = 0
    for i in range(N):
        if (i+1) != p[i]:
            diff += 1
    if (diff == 2) | (diff == 0):
        return "Yes"
    return "No"
if __name__ == '__main__':
    print(main())

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

    diff = 0
    for i in range(N):
        if (i+1) != p[i]:
            diff += 1
    if (diff == 2) | (diff == 0):
        return "YES"
    return "NO"
if __name__ == '__main__':
    print(main())

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

s = input()
s = int(s)

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

count = 0

for val in range(s):
    if val+1 != nums[val]:
        count +=1

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


s = int(input())

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

count = 0

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

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

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

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

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

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

p=list(map(int,input().split()))
cnt=0
for i in range(len(p)-1):
  if(p[i]>p[i+1]):
    cnt++

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

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

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

Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Runtime Error

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

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

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

if q <= 2:
  print('Yes')
else:
  print('No')

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

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

if q <= 2:
  print('Yes')
else:
  print('No')

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

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

if q <= 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 = input()
lst1 = list(map(int, input().split()))
lst2 = sorted(lst1)

n = 0
for x, y in zip(lst1, lst2):
    if x != y:
        n += 1
        if n > 2:
            break

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


N = input()
lst1 = list(map(int, input().split()))
lst2 = sorted(lst1)
 
n = 0
for x, y in zip(lst1, lst2):
    if x != y:
        n += 1
        if n > 2:
            break
 
if n > 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):
# ABC135
# B 0 or 1 swap
n = int(input())
p = list(map(int, input().split()))
ch = 0
for i in range(n):
    if (i+1) != p[i]:
        ch += 1

if ch > 2:
    print('NO')
else:
    print('Yes')


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

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

s=sorted(p)
cnt=0

def jud(p,s,n,cnt):
    # print(p,s)
    for i in range(n):
        if s[i]!=p[i]:
            cnt+=1
        if cnt>2:
            return "No"
    return "Yes"

print(jud(p,s,n,cnt))

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

s=sorted(p)
cnt=0

def jud(p,s,n,cnt):
    print(p,s)
    for i in range(n):
        if s[i]!=p[i]:
            cnt+=1
        if cnt>2:
            return "No"
    return "Yes"

print(jud(p,s,n,cnt))

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

s=sorted(p)
cnt=0

def jud(p,s,n,cnt):
    # print(p,s)
    for i in range(n):
        if s[i]!=p[i]:
            cnt+=1
        if cnt>2:
            return "NO"
    return "YES"

print(jud(p,s,n,cnt))

Verdicts: Wrong Answer

Wrong Answer

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

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


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

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

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

Verdicts: Wrong Answer

Runtime Error

Runtime Error

Accepted