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

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

ans = 0

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

if ans == N or ans == N-2:
	print('Yes')
else :
	print('No')

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

ans = 0

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

if ans == N or N-2:
	print('YES')
else :
	print('NO')


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

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

ans = 0

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

if ans == N or N-2:
	print('Yes')
else :
	priint('No')

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

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

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

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

ans = 0

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

if ans == N or N-2:
	print('Yes')
else :
	priint('No')

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

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

ans = 0

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

if ans == N or ans == N-2:
	print('Yes')
else :
	print('No')


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

Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Runtime Error

Wrong Answer

Runtime Error

Wrong Answer

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())
p = list(map(int,input().split()))
count=0
#print(p)
p_sorted = sorted(p)
print(p_sorted)

for i in range(n):
    #print(i)
    if p[i]!=p_sorted[i]:
        count+=1
        #print(count)

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

n = int(input())
p = list(map(int,input().split()))
count=0
#print(p)
p_sorted = sorted(p)
print(p_sorted)

for i in range(n):
    #print(i)
    if p[i]!=p_sorted[i]:
        count+=1
        #print(count)

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

n = int(input())
p = list(map(int,input().split()))
count=0
#print(p)
p_sorted = sorted(p)


for i in range(n):
    #print(i)
    if p[i]!=p_sorted[i]:
        count+=1
        #print(count)

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):
N = int(input())
p = [int(i) for i in input().split()]
check = 0
pp = sorted(p)
for i in range(N):
    if p[i] != p[i + 1]:
        check += 1

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

N = int(input())
p = [int(i) for i in input().split()]
check = 0
pp = sorted(p)
for i in range(N):
    if p[i] != pp[i]:
        check += 1

if check == 2 or check == 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(input().split())
q = sorted(p)
for i in range(n):
  if p[i] != q[i]:
    ans += 1
if ans <= 2:
  print('YES')
else:
  print('NO')

n = int(input())
p = list(map(int,input().split()))
q = sorted(p)
ans = 0
for i in range(n):
  if p[i] != q[i]:
    ans += 1
if ans == 2:
  print('YES')
elif ans == 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
sorted_p = sorted(p)

for i in range(n):
    if i+1 != p[i]:
        count += 1
        k = p.index(i+1)
        k = p.pop(k)
        p.insert(i,k)
        if count == 1:
            break

if sorted_p == p:
    print("YES")
else:
    print("NO")


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

t = sorted(p)

count = 0

for x,y in zip(p,t):
    if x != y:
        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()))
n = [i+1 in range(N)]
c = 0
for i in range(N):
  if n[i] != p[i]:
    c += 1
if c == 0 or c == 2:
  print("YES")
else:
  print("NO")
	

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


Verdicts: Runtime Error

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

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



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




n=int(input())
a=list(map(int,input().split()))
b=0
for i in range(n):
  if a[i]==i:
    b+=0
  else:
    b+=1
if b==0or2:
  print("Yes")
else:
  print("No")

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




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



Verdicts: Wrong Answer

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):
N = int(input())
P = list(map(int,input().split()))
A = []
for n in range(N):
  A.append(n+1)

count = 0
for n in range(N):
  if A[n] != P[n]:
    count += 1
if count == 0 or count == 2:
  print("Yes")
else:
  print("No")

N = int(input())
P = list(map(int,input().split()))
A = []
for n in range(N):
  A.append(n+1)

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

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

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    p = na()
    for i in range(n-1):
        for j in range(i, n):
            q = p.copy()
            q[i] = p[j]; q[j] = p[i]
            now = q[i]
            f = True
            for qi in q:
                if now > qi:
                    f = False
                    break
                now = qi
            if f:
                print("Yes")
                quit()
    print("No")



if __name__ == "__main__":
    main()



import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    p = na()
    for i in range(n-1):
        for j in range(i, n):
            q = p.copy()
            q[i] = p[j]; q[j] = p[i]
            now = q[0]
            f = True
            for qi in q:
                if now > qi:
                    f = False
                    break
                now = qi
            if f:
                print("YES")
                quit()
    print("NO")



if __name__ == "__main__":
    main()

Verdicts: Wrong Answer

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

Submission attempts (in order):
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
totl=0
for i in range(n-1):
  if a[i]+a[i+1]<b[i]:
    totl+=a[i]+a[i+1]
    a[i]=0
    a[i+1]=0
  else:
    totl+=b[i]
    if a[i]<b[i]:
      a[i]=0
      a[i+1]-=b[i]-a[i]
    else:
      a[i]-=b[i]
    

print(totl)
  


n=int(input())
p=list(map(int,input().split()))
q=[]
for i in range(n-1):
  q.append(p[i+1]-p[i])
cnt=q.count(1)
if cnt=>3:
  print('NO')
else:
  print('YES')
  

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


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()))
la = list(range(1,N+1))
cnt1 = 0
cnt2 = 0
while cnt1 < N-1:
    if P[cnt1] == la[cnt1]:
        cnt2 += 1
    cnt1 += 1
if cnt2 >= N-2:
    print('Yes')
else:
    print('No')

N = int(input())
P = list(map(int, input().split()))
la = list(range(1,N+1))
cnt1 = 0
cnt2 = 0
while cnt1 <= N-1:
    if P[cnt1] == la[cnt1]:
        cnt2 += 1
    cnt1 += 1
if cnt2 >= N-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()))

p_sorted = sorted(p)

is_changed = [0 if x==y else 1 for x,y in zip(p, p_sorted)]

if sum(is_changed) == 2:
    print("Yes")
else:
    print("No")

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

p_sorted = sorted(p)

is_changed = [0 if x==y else 1 for x,y in zip(p, p_sorted)]

if sum(is_changed) <= 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 copy

N = int(input())
a = input().split()
ans = "NO"
b = copy.deepcopy(a)
if b == sorted(a):
    ans = "YES"
else:
    for i in range(0, N):
        if ans =="YES":
            break
        for j in range(i, N-1):
            b = copy.deepcopy(a)
            temp = b[i]
            b[i] = b[j]
            b[j] = temp
            if b == sorted(a):
                print("YES")
                ans = "YES"
                break
print(ans)

import copy

N = int(input())
a = list(map(int,input().split()))
ans = "NO"
b = copy.deepcopy(a)
if b == sorted(a):
    ans = "YES"
else:
    for i in range(0, N-1):
        if ans == "YES":
            break
        for j in range(i, N):
            b = copy.deepcopy(a)
            temp = b[i]
            b[i] = b[j]
            b[j] = temp
            if b == sorted(a):
                ans = "YES"
                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):
#!/usr/bin/env python

N = input()

n = int(N)

list1 = list(range(n))

for i in range(n) :
	list1[i] = list1[i] + 1

#print(list1)

list2 = []

for i in range(n) :
	list2.append(input())

list2 = [int(n) for n in list2]

#print(list2)

judge = 0

for i in range(n) : 
	if list1[i] != list2[i] :
		judge = judge + 1

if judge <= 2 :
	print('YES')

else :
	print('NO') 






#!/usr/bin/env python

N = input()

n = int(N)

list1 = list(range(n))

for i in range(n) :
	list1[i] = list1[i] + 1

#print(list1)

list2 = []

list2 = input().split()  

list2 = [int(n) for n in list2]

#print(list2)

judge = 0

for i in range(n) : 
	if list1[i] != list2[i] :
		judge = judge + 1

if judge <= 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 = list(range(1,N+1))
J = [x - y for (x, y) in zip(P, Q)]
R = [i for i in J if i != 0]
print(R)
if len(R)<=2:
  print('YES')
else:
  print('NO')


N = int(input())
P = list(map(int,input().split()))
Q = list(range(1,N+1))
J = [x - y for (x, y) in zip(P, Q)]
R = [i for i in J if i != 0]
if len(R)<=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())
c=list(range(1,n+1))
p=list(map(int,input().split()))
cnt=0

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

n=int(input())
c=list(range(1,n+1))
p=list(map(int,input().split()))
cnt=0

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

Verdicts: Wrong Answer

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

Submission attempts (in order):
n = int(input())
p = list(map(int, input().split()))
q = sorted(p)
s = sum(pi != qi for pi, qi in zip(p, q))
if s == 0 or s == 2:
    print('Yes')
else:
    print('No')


n = int(input())
p = list(map(int, input().split()))
q = sorted(p)
s = sum(pi != qi for pi, qi in zip(p, q))
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())
p = list(map(int, input().split()))
error = 0
for i in range(n):
    if p[i] != i+1:
        error += 1
if error == 2 or error == 0:
    print('Yes')
else:
    print('No')

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

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


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

for i in range(1, n-1):
    if p[i] != i+1:
        print('No')
        exit()
print('Yes')

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


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())
N = list(map(int, input().split()))
cnt = 0
for i in range(1, len(N)):
    tmp = N[i] 
    if tmp < N[i-1]:
        j = i
        while True:
            N[j] = N[j-1]
            j -= 1
            if j == 0 or tmp >= N[j-1]:
                break
        N[j] = tmp
        if j != i:
          cnt+=1
if cnt <= 1:
  print("YES")
else:
  print("NO")
#print(N)
#print(cnt)

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

n = int(input())
N = list(map(int, input().split()))
cnt = 0
for i in range(0, len(N)-1):
    syou = N[i]
    syounum = i
    for j in range(i+1,len(N)):
      if syou > N[j]:
        syounum = j
        syou = N[j]
    if syounum != i:
      cnt+=1
      tmp = N[i]
      N[i] = N[syounum]
      N[syounum] = tmp
if cnt <= 1:
  print("YES")
else:
  print("NO")

Verdicts: Wrong Answer

Wrong Answer

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

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

l=list(range(1,n+1))
cnt=0

for i in range(n):
    if l[i]!=int(p[i]):
        cnt+=1
print(cnt)
if cnt<=2:
    print('Yes')
else:
    print('No')


n=int(input())
p=input().split()

l=list(range(n,0,-1))
cnt=0

for i in range(n):
    if l[i]!=int(p[i]):
        cnt+=1
print(cnt)
if cnt<=2:
    print('YES')
else:
    print('NO')


n=int(input())
p=input().split()

l=list(range(1,n+1))
cnt=0

for i in range(n):
    if l[i]!=int(p[i]):
        cnt+=1
print(cnt)
if cnt<=2:
    print('YES')
else:
    print('NO')


n=int(input())
p=input().split()

l=list(range(1,n+1))
cnt=0

for i in range(n):
    if l[i]!=int(p[i]):
        cnt+=1
if cnt<=2:
    print('YES')
else:
    print('NO')


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

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

Submission attempts (in order):
N = int(input())
p = list(map(int, input().split()))
for i in range(N):
    for j in range(i + 1, N):
        if p[j - 1] < p[i] < p[j + 1] and p[i - 1] < p[j] < p[i + 1]:
            print("YES")
        else:
            continue
print("NO")


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


N = int(input())
p = list(map(int, input().split()))
for i in range(N):
    for j in range(i + 1, N):
        if p[j - 1] < p[i] < p[j + 1] and p[i - 1] < p[j] < p[i + 1]:
            print("YES")
            exit()
        else:
            continue
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")


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()))
new_p=p.sort()

for i in range(n-1):
    if p[i]<=p[i+1]:
        tmp=p[i]
        p[i]=p[i+1]
        p[i+1]=tmp
        break
if new_p==p:
    print('YES')
else:
    print('NO')

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

for i in range(n-1):
    if p[i]<=p[i+1]:
        tmp=p[i]
        p[i]=p[i+1]
        p[i+1]=tmp
        break
if new_p==p:
    print('YES')
else:
    print('NO')

n=int(input())
p=list(map(int,input().split()))
new_p=p.reverse()
cnt=0

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


n=int(input())
p=list(map(int,input().split()))
new_p=p.sort()
cnt=0

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

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

for i in range(n):
    if p[i]<p[i+1]:
        tmp=p[i]
        p[i]=p[i+1]
        p[i+1]=tmp
        break
if new_p==p:
    print('YES')
else:
    print('NO')

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

for i in range(n-1):
    if p[i]<=p[i+1]:
        tmp=p[i]
        p[i]=p[i+1]
        p[i+1]=tmp
        break
if new_p==p:
    print('YES')
else:
    print('NO')

n=int(input())
p=list(map(int,input().split()))
new_p=sorted(p)
cnt=0

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

Verdicts: Wrong Answer

Wrong Answer

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

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

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

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

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

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


a = 0
for i in range(x-1):
	
	b = 0
	#print (li[i])
    
	if int(li[i]) < int(li[i+1]):
		b=b+1
	elif int(li[i]) > int(li[i+1]):
		a=a+1
	else:
		b=b+1
	#print(a)
	
    
#print(a)

if a < 2:
	print('YES')
else:
	print('NO')

x = int(input())
li = list(map(int,input().split()))#listp
li_o = list(range(1,x))

a = 0
for i in range(x-1):
	
	b = 0
	#print (li[i])
    
	if int(li[i]) == int(li_o[i]):
		b=b+1
	else:
		a=a+1
	#print(a)
	
    
#print(a)

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

Verdicts: Wrong Answer

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

Submission attempts (in order):
N = int(input())
lst = list(map(int, input().split()))
cnt = 0
for i in lst:
    if lst[i]-1 != i:
        cnt += 1
if cnt > 2:
    print('NO')
else:
    print('YES')

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

Verdicts: Runtime Error

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

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

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

mistake=[]
for i in range(n):
  if array[i]!=i+1:
    mistake.append([i+1,array[i]])

ans='Yes'
k=len(mistake)
if k>2:
  ans='No'
elif k==2:
  if mistake[0][0]!=mistake[1][1]:
    ans='No'

print(ans)
    

n=int(input())
array=[int(i) for i in input().split()]

mistake=[]
for i in range(n):
  if array[i]!=i+1:
    mistake.append([i+1,array[i]])

ans='YES'
k=len(mistake)
if k>2:
  ans='NO'
elif k==2:
  if mistake[0][0]!=mistake[1][1]:
    ans='NO'

print(ans)
    

Verdicts: Wrong Answer

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

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

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


Verdicts: Wrong Answer

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

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

for a in range(1, N):
    if list[a-1] > list[a]:
        count += 1


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

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

for a in range(N):
    if list[a] != list_sort[a]:
        count += 1


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

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

for a in range(1, N):
    if list[a-1] > list[a]:
        count += 1


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

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

for a in range(N):
    if list[a] != list_sort[a]:
        count += 1


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

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

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

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

pa = sorted(p)
cnt = 0
for i in range(n):
    if p[i] != pa[i]:
        cnt += 1

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


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

pa = sorted(p)
cnt = 0
for i in range(n):
    if p[i] != pa[i]:
        cnt += 1

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

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

pa = sorted(p)
cnt = 0
for i in range(n):
    if p[i] == pa[i]:
        cnt += 1

if len(p) - cnt <= 2:
    print('Yes')
else:
    print('No')

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

pa = sorted(p)
cnt = 0
for i in range(n):
    if p[i] != pa[i]:
        cnt += 1

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

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

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

Submission attempts (in order):
a=int(input())
b=list(map(int,input().split()))
count=0
for i,j in enumerte(a,1):
  if i != j:
    count +=1

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

a=int(input())
b=list(map(int,input().split()))
count=0
for i,j in enumerate(b,1):
  if i != j:
    count +=1

if 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(int,input().split()))

o=1
e=0
for i in p:
  if i != o:
    e +=1
  o +=1
if e=0 or e=2:
  print("YES")
else:
  print("NO")


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

o=1
e=0
for i in range(N):
  if i != o:
    o +=1
    e  +=1

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


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

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

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

Max_S = max(S)
Max_idx = S.index(Max_S)
Min_S = min(S)
Min_idx = S.index(Max_S)
Sort_S = sorted(S)

S[Max_idx], S[Min_idx] = S[Min_idx], S[Max_idx]
if S == Sort_S:
    print('YES')
else:
    print('NO')


N = int(input())
S = list(map(int, input().split()))
Min_S = min(S)
Min_idx = S.index(Min_S)


S[0], S[Min_idx] = S[Min_idx], S[0]
if S == Sort_S:
    print('YES')
else:
    print('NO')

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

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

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

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

Tmp = []
Tmp = input().rstrip().split(' ')

nData = [0 for i in range(nN)]

for i in range(nN):
  nData[i] = int(Tmp[i])

nFlag = 0
nCnt = 0

for i in range(nN-1):
  nTmp = i + 1
  if nData[i] != nTmp:
    nCnt += 1
    nTmp2 = nData[i] - 1
    nTmp3 = nData[nTmp]
    if nTmp3 != nTmp:
      nCnt += 1
  
  if nCnt >= 2:
    break
    
  
if nCnt < 2:
  print('YES')
else:
  print('NO')
  


nN = int(input())

Tmp = []
Tmp = input().rstrip().split(' ')

nData = [0 for i in range(nN)]

for i in range(nN):
  nData[i] = int(Tmp[i])

nFlag = 0
nCnt = 0

for i in range(nN-1):
  if nData[i] > nData[i+1]:
    nCnt += 1

if nCnt < 2:
  print('YES')
else:
  print('NO')
  




nN = int(input())

Tmp = []
Tmp = input().rstrip().split(' ')

nData = [0 for i in range(nN)]

for i in range(nN):
  nData[i] = int (input(Tmp[i]))

nFlag = 0
nCnt = 0

for i in range(nN-1):
  if nData[i] > nData[i+1]:
    nCnt += 1

if nCnt < 2:
  print('YES')
else:
  print('NO')
  




nN = int(input())

Tmp = []
Tmp = input().rstrip().split(' ')

nData = [0 for i in range(nN)]

for i in range(nN):
  nData[i] = int(Tmp[i])

nFlag = 0
nCnt = 0

for i in range(nN):
  nTmp = i + 1
  if nData[i] != nTmp:
    nCnt += 1
    nTmp2 = nData[i] - 1
    nTmp3 = nData[nTmp2]
    if nTmp3 != nTmp:
      nCnt += 1
  
  if nCnt >= 2:
    break
    
  
if nCnt < 2:
  print('YES')
else:
  print('NO')
  


nN = int(input())

Tmp = []
Tmp = input().rstrip().split(' ')

nData = [0 for i in range(nN)]

for i in range(nN):
  nData[i] = int(Tmp[i])

nFlag = 0
nCnt = 0

for i in range(nN):
  nTmp = i + 1
  if nData[i] != nTmp:
    nCnt += 1
    nTmp2 = nData[i] - 1
    nTmp3 = nData[nTmp2]
    if nTmp3 != nTmp:
      nCnt += 1
    else:
      nData[nTmp2]=nTmp2+1
  

  
if nCnt < 2:
  print('YES')
else:
  print('NO')
  


Verdicts: Wrong Answer

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

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

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

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

N = int(input()) 
s = list(map(int, input().split()))
s2 = copy.copy(s)
s.sort(reverse=True)
n = 0
for i in range(0, len(x)):
    if x[i] - x2[i] != 0:
        n+=1
if n == 2:
  print("YES")
else:
  print("NO")

import copy

N = int(input()) 
s = list(map(int, input().split()))
s2 = copy.deepcopy(s)
s.sort()
n = 0
for i in range(0, len(s)):
    if s[i] - s2[i] != 0:
        #print(s[i], s2[i])
        n+=1

if n == 2:
  print("YES")
elif n == 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 = input()
p = list(map(int, input().split()))

dif = []
for i in range(1,n+1):
  if p[i-1] != i:
    dif.append(i)

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

n = input()
p = [int(input()) for i in range(3)]

dif = []
for i in range(1,n+1):
  if p[i-1] != i:
    dif.append(1)

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

n = input()
p = [int(input()) for i in range(3)]

dif = []
for i in range(n):
  if p[i]!= i:
    dif.append(1)

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

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

dif = []
for i in range(1,n+1):
  if p[i-1] != i:
    dif.append(i)

if len(dif) == 0 or len(dif) == 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(N):
    if i+1 != P[i]:
        cnt +=1
print("Yes" if cnt==0 or cnt ==2 else "No")

N=int(input())
P=list(map(int,input().split()))
cnt=0
for i in range(N):
    if i+1 != P[i]:
        cnt +=1
print("YES" if cnt==0 or 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):
import collections
n = int(input())
p = [int(i) for i in input().split()]
ps = sorted(p)
x = [p[i]-ps[i] for i in range(len(p))]
tmp = []
c = collections.Counter(x)
if len(c) == 1:
  print('YES')
elif len(c) ==3:
  for i in range(n):
    if x[i] != 0:
      tmp.append(x[i])
  if sum(tmp) == 0:
    print('Yes')
  else:
    print('No')
else:
  print('NO')

import collections
n = int(input())
p = [int(i) for i in input().split()]
ps = sorted(p)
x = [p[i]-ps[i] for i in range(len(p))]
tmp = []
c = collections.Counter(x)
if len(c) == 1:
  print('YES')
elif len(c) ==3:
  if sum(x) == 0:
    print('Yes')
  else:
    print('No')
else:
  print('NO')

import collections
n = int(input())
p = [int(i) for i in input().split()]
ps = sorted(p)
x = [p[i]-ps[i] for i in range(len(p))]
tmp = []
c = collections.Counter(x)
if len(c) == 1:
  print('YES')
elif len(c) == 3:
  if x.count(0) == n-2:
    print('Yes')
  else:
    print('No')
else:
  print('NO')

import collections
n = int(input())
p = [int(i) for i in input().split()]
ps = sorted(p)
x = [p[i]-ps[i] for i in range(len(p))]
c = collections.Counter(x)
if len(c) == 1:
  print('YES')
elif len(c) == 3 and x.count(0) == n-2:
  print('YES')
else:
  print('NO')

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted