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

mis_match = sum([ 1 for s in p if not p.index(s) == s+1])

judge="NO"
if mis_match in [0,2]:
    judge="YES"
print(judge)

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

mis_match = sum([ 1 for s in p if not p.index(s) +1 == s])

judge="NO"
if mis_match in [0,2]:
    judge="YES"
print(judge)

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()))
print(P)
Q = sorted(P)
print(Q)
ans = 0
for i in range(n):
    if P[i] != Q [i]:
         ans +=1
print('YES' if (ans ==2 or ans==0) else '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
print('YES' if (ans ==2 or ans==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()))
answer = []
diff = 0
diff_1 = -1
diff_2 = -1

index = 0

for i in p:
    if index == 0:
        index += 1
        continue
    
    if p[index] < p[index-1]:
        if diff >= 2:
            print ("NO")
            exit()
        diff += 1

        if diff_1 == -1:
            diff_1 = index-1
        else:
            diff_2 = index-2

    index += 1

if diff_1 == -1:
    print("YES")
    exit()

if diff_1 != -1 and diff_2 == -1:
    print("YES")
    exit()

diff_1_1 = p[diff_1]
p[diff_1] = p[diff_2]
p[diff_2] = diff_1_1

index = 0
for i in p:
    if index == 0:
        index += 1
        continue
    
    if p[index] < p[index-1]:
        print ("NO")    
        exit()

    index += 1

print("YES") 

N=int(input())
p=list(map(int,input().split()))
answer = []
diff = 0
diff_1 = -1
diff_2 = -1

index = 0

for i in p:
    if index == 0:
        index += 1
        continue
    
    if p[index] < p[index-1]:
        if diff >= 2:
            print ("NO")
            exit()
        diff += 1

        if diff_1 == -1:
            diff_1 = index-1
        else:
            diff_2 = index-2

    index += 1

if diff_1 == -1:
    print("YES")
    exit()

if diff_1 != -1 and diff_2 == -1:
    print("NO")
    exit()

diff_1_1 = p[diff_1]
p[diff_1] = p[diff_2]
p[diff_2] = diff_1_1

index = 0
for i in p:
    if index == 0:
        index += 1
        continue
    
    if p[index] < p[index-1]:
        print ("NO")    
        exit()

    index += 1

print("YES") 

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

p_collect = sorted(p)

no = 0

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

if no == 1:
    print("NO")
elif no >= 3:
    print("NO")
else:
    print("YES")
 

Verdicts: Wrong Answer

Wrong Answer

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

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

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

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


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

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

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


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

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

if swap == 0 or swap == 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(input()) for a in range(n)]
sorted = sorted(P)
count = 0

for i in range(n):
  if P[i] == sorted[i]:
    count += 1

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


n = int(input())
P = [int(input()) for _ in range(n)]
sorted = sorted(P)
count = 0

for i in range(n):
  if P[i] == sorted[i]:
    count += 1

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

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

for i in range(n):
  if P[i] == sorted[i]:
    count += 1

if count == n or count == 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 = [int(i) for i in input().split()]

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

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

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

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

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

Verdicts: Wrong Answer

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

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


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


n=int(input())
sp=0
A=list(map(int,input().split()))
for i in range(n):
  if i+1!=A[i]:
    sp+=1
if sp==0 or sp==2:
  print("YES")
  exit()
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):
input()
p = list(map(int, input().split()))
for i, p_ in enumerate(p):
  a += (p_ != (i + 1))
print('YNEOS'[a > 2 :: 2])


input()
p = list(map(int, input().split()))
a = 0
for i, p_ in enumerate(p):
  a += (p_ != (i + 1))
print('YNEOS'[a > 2 :: 2])


Verdicts: Runtime Error

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

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

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

Verdicts: Runtime Error

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

Submission attempts (in order):
n = int(input())
p = tuple(map(int,input().split()))
c = 0
ans = "YES"
for i in range(1,n+1) :
    if p[i] != i :
        c += 1
if c <= 2 :
    ans = "NO"
print(ans)

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

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

Verdicts: Runtime Error

Wrong Answer

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

Submission attempts (in order):
n = int(input())
p = list(map(int, input().split()))
l = list("")
c = 0
for i in range(1, n):
    if p[i] - p[i - 1] != 1:
        c += 1
        l.append(i)
if c == 1 or c > 2:
    print("NO")
    exit()
print("Yes")

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

Verdicts: Wrong Answer

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

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


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

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

for i in range(1,N):
  for j in range(i-1,-1,-1):
    if X[j] > X[i]:
      if count == 1:
        print('NO')
        exit()
      else:
        X[i] = X[j]
        X[j] = X[i]
        count += 1
        
print('YES')
    


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

for i in range(1,N):
  for j in range(i-1,-1,-1):
    if X[j] > X[i]:
      if count == 1:
        print('No')
        exit()
      else:
        X[i] = X[j]
        X[j] = X[i]
        count += 1
        
print('Yes')
    

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


Verdicts: Runtime Error

Wrong Answer

Wrong Answer

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

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

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

Verdicts: Wrong Answer

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

Submission attempts (in order):
#-*- coding: UTF-8 -*-

n = int(input())

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

for i in range(len(p) - 1):
    pi = p[i]
    if p[i] != i+1:
        if p[p[i] - 1] == i + 1:
            p[i], p[pi - 1] = p[pi - 1], p[i]
            f += 1
            print(p,i)
        else:
            f = 2
            print(p)

if 0 <= f <= 1:
    print("YES")
else:
    print("NG")


#-*- coding: UTF-8 -*-

n = int(input())

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

for i in range(len(p) - 1):
    pi = p[i]
    if p[i] != i+1:
        if p[p[i] - 1] == i + 1:
            p[i], p[pi - 1] = p[pi - 1], p[i]
            f += 1
        else:
            f = 2

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


Verdicts: Wrong Answer

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

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


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

c = 0
for p, q in zip(P, sorted(P)):
  if p != q:
    c += 1
    if c > 2:
      break

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

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

c = 0
for p, q in zip(P, sorted(P)):
  if p != q:
    c += 1
    if c > 2:
      break

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

Verdicts: Wrong Answer

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

Submission attempts (in order):
def main():
    a, b = map(int, input().split())
    diff = abs(max(b, a) - min(a, b))
    if diff % 2 != 0:
        print("IMPOSSIBLE")
    else:
        bigger = max(a, b)
        ans = bigger - (diff//2)
        print(ans)


if __name__ == "__main__":
    main()


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

    Count = 0
    for i, j in zip(ps, ps_sort):
        if i != j:
            Count += 1

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


if __name__ == "__main__":
    main()


Verdicts: Runtime Error

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

Submission attempts (in order):
n = int(input())
p = list(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(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=[int(i) for i in 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

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 = sum([index + 1 == num for index, num in enumerate(P)])
if count <= 2:
  print("YES")
else:
  print("NO")

N = int(input())
P = list(map(int, input().split()))
count = sum([index + 1 != num for index, num in enumerate(P)])
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())
A = list(map(int, input().split( )))
cnt = 0
for i in range(n):
  if A[i] == i+1:
    cnt =  (cnt + 1)%2
if cnt == 0:
  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):
n = int(input())
p = list(map(int,input().split()))
n_l = list(range(1,n + 1))
count = 0
for n_num , p_num in zip(n_l,p):
  if n_num != p_num:
    count += 1
if count == 2 or count == 0:
  print('Yes')
else:
  print('No')

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

n=int(input())
l=list(map(int,input().split()))
a=0
for i in range(n):
  if l[i]!=i+1:
    a+=1
if a==0 or 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())
cnt = 0
for k in range(1,n+1):
    if k >= 1 and k <= 9:
        cnt += 1
    elif k >= 100 and k <= 999:
        cnt += 1
    elif k >= 10000 and k <= 99999:
        cnt += 1
print(cnt)

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

b=P.copy()

b.sort()
count=0

for i in range(N):
  if P[i] != b[i]:
    count+=1
    
if count >=2:
  print('NO')
else:
  print('YES')

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

b=P.copy()

b.sort()
count=0

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


Verdicts: Wrong Answer

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

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

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

Verdicts: Wrong Answer

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

Submission attempts (in order):
import copy
N = int(input())
p = list(map(int, input().split()))
pcopy = copy.deepcopy(p)
ans = sorted(p)

is_ascend = False
if p == ans:
    is_ascend = True

for i in range(N):
    for j in range(i+1,N):
        p = copy.copy(pcopy)
        p[i], p[j] = p[j], p[i]
        if p == ans:
            is_ascend = True

if is_ascend:
    print("Yes")
else:
    print("No")

import copy
N = int(input())
p = list(map(int, input().split()))
pcopy = copy.deepcopy(p)
ans = sorted(p)

is_ascend = False
if p == ans:
    is_ascend = True

for i in range(N):
    for j in range(i+1,N):
        p = copy.copy(pcopy)
        p[i], p[j] = p[j], p[i]
        if p == ans:
            is_ascend = True

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

res = 0
for a, n in zip(A, N):
    if a != n:
        res += 1
print("YES") if res <= 1 else print("NO")




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

res = 0
for a, n in zip(A, N):
    if a != n:
        res += 1
print("YES") if res <= 1 else print("NO")




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

res = 0
for p, q in zip(P, Q):
    if p != q:
        res += 1
print("YES" if res <= 2 else "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()))
s = [i for i in range(1, n+1)]
count = 0
for i in s:
    if p.index(i):
        count += 1
if count > 2:
    print("NO")
else:
    print("YES")


n = int(input())
p = list(map(int, input().split()))
s = [i for i in range(1, n+1)]
count = 0
for i in s:
    if p.index(i) != s.index(i):
        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()))
a=0
p_2 = sorted(p)
for i in range(n-1):
    a=+1
    if p[i] > p[i+1]:
        for j in range(a,n-1):
            if p[j] > p[j+1]:
                p[i],p[j+1] = p[j+1],p[i]
if p == p_2:
    print('Yes')
else :
    print('No')

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

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

P = []
n=0

for i in range(N):
    P.append(int(Pp.split()[i]))

for w in range(N-1):
    if P[w+1]-P[w]==1:
        n+=1

if N>3:
        
    if n >= N-2:
        print('YES')
    else:
        print('NO')
else:
    print('YES')

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Aug  9 22:47:06 2019

@author: kohei
"""

N = int(input())
Pp = input()

P = []
n=0

for i in range(N):
    P.append(int(Pp.split()[i]))

for w in range(N-1):
    if P[w+1]-P[w]==1:
        n+=1

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



N = int(input())
Pp = input()

P = []
H = []
n=1

for i in range(N):
    P = int(Pp.split()[i])
    H.append(P-n)
    n+=1


R = H.count(0)

if N-R < 3:
    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()))
cnt = 0
for i in range(N):
  cnt += p[i] != i + 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(N):
  cnt += p[i] != i + 1
if cnt == 0 or cnt == 2:
  print('YES')
else:
  print('NO')

Verdicts: Wrong Answer

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

Submission attempts (in order):
# coding: utf-8

num = int(input())
str = input().split()
table = list(str)
table5 = [int(i) for i in table]
count = 0
table2 = sorted(table)
table3 = [int(i) for i in table2]
print(table5)
print(table3)
for i in range(num):
    if table5[i] == table3[i]:
        continue
    else:
        count += 1

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

# coding: utf-8

num = int(input())
str = input().split()
table = list(str)
table5 = [int(i) for i in table]
count = 0
table2 = sorted(table5)
table3 = [int(i) for i in table2]
for i in range(num):
    if table5[i] == table3[i]:
        continue
    else:
        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()))
index_list = []
value_list = []
for i in range(1, n+1):
  if i != p[i-1]:
    index_list.append(i)
    value_list.append(p[i-1])
if len(index_list) == 0:
  print("YES")
elif len(index_list) == 2 and value_list[0] == index_list[1] and value_list[1] == index_list[0]:
  print("YES")
else:
  print("NO"

n = int(input())
p = list(map(int, input().split()))
index_list = []
value_list = []
for i in range(1, n+1):
  if i != p[i-1]:
    index_list.append(i)
    value_list.append(p[i-1])
if len(index_list) == 0:
  print("YES")
elif len(index_list) == 2 and value_list[0] == index_list[1] and value_list[1] == index_list[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()))

q = sorted(p)

diff = 0
for n in range(N):
    if p[n]!=q[n]:
        diff += 1

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

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

q = sorted(p)

diff = 0
for n in range(N):
    if p[n]!=q[n]:
        diff += 1

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

Verdicts: Wrong Answer

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

Submission attempts (in order):



N = int(input())
plist = tuple(map(int,input().split()))
answer_p = list(plist)
answer_p.sort()
able = False

for i in range(N-1):
    if able == True:
        break
    p = list(plist)
    j = i + 1
    for j in range(N):
        if able == True:
            break
        p = list(plist)
        p[i] = plist[j]
        p[j] = plist[i]
        if p == answer_p:
            print('Yes')
            able = True

if able == False:
    print('No')




N = int(input())
plist = tuple(map(int,input().split()))
answer_p = list(plist)
answer_p.sort()
able = False

for i in range(N-1):
    if able == True:
        break
    p = list(plist)
    j = i + 1
    for j in range(N):
        if able == True:
            break
        p = list(plist)
        p[i] = plist[j]
        p[j] = plist[i]
        if p == answer_p:
            print('YES')
            able = True

if able == False:
    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())
Nlist = [int(i) for i in input().split()]

sum = 0
cnt = 0
for i in range(N):
    if cnt > 2:
        break

    if Nlist[i] == (i + 1):
        continue
    else:
        sum += Nlist[i]
        cnt += 1

if cnt == 0 or sum == (N + 1):
    print("Yes")
else:
    print("No")

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

cnt = 0
for i in range(N):
    if cnt > 2:
        break

    if Nlist[i] == (i + 1):
        continue
    else:
        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):
n = int(input())
arr = list(map(int, input().split()))

c = 0
for i, v in enumerate(arr):
  if i+1==v:
    c += 1

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

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

c = 0
for i, v in enumerate(arr):
  if i+1!=v:
    c += 1
print("YES" if c==2 or c==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())
a = [int(i) for in input().split()]
t = 0
for i in range(n):
 for j in range(i+1,n):
  t += a[i] > a[j]
print("YES" if t < 2 else "NO")

n = int(input())
a = [int(i) for i in input().split()]
t = 0
for i in range(n):
 for j in range(i+1,n):
  t += a[i] > a[j]
print("YES" if t < 2 else "NO")


n = int(input())
a = [int(i) for i in input().split()]
t = 0
for i in range(n):
 q = 0
 for j in range(i):
  q += a[i] < a[j]
 t += q>0
v = 0
for i in range(n):
 q = 0
 for j in range(i+1, n):
  q += a[i] > a[j]
 v += q>0
print("YES" if min(t, v) < 2 else "NO")


n = int(input())
a = [int(i) for i in input().split()]
q = 0
for i in range(n):
 for j in range(i, n):
  t = a[i]
  a[i] = a[j]
  a[j] = t
  f = 1  
  lst = - 1100
  for k in a:
   f &= k > lst
   lst = k
  q |= f
  t = a[i]
  a[i] = a[j]
  a[j] = t
print("YES" if q else "NO")


Verdicts: Runtime Error

Wrong Answer

Wrong Answer

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

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

n = int(input())
p = input().split()
P = sorted(p)
length = len(p)
count = 0
for i in range(0, length):
  if p[i] != P[i]:
    count += 1
if count >= 3:
  print('YES')
else:
  print('NO')

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

Verdicts: Wrong Answer

Wrong Answer

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

Submission attempts (in order):
N=int(input())
p=list(map(int,input().split()))
s=sorted(p)
flag=0
for i in range(N):
  for j in range(i+1,N):
    tmp=p
    tmp[i],tmp[j]=tmp[j],tmp[i]
    if tmp==s:
      flag=1
print('NYOE S'[flag::2])


import copy
N=int(input())
p=list(map(int,input().split()))
s=sorted(p)
if s==p:
  print('YES')
else:
  flag=0
  tmp=[]
  for i in range(N):
    for j in range(i+1,N):
      tmp=copy.deepcopy(p)
      tmp[i],tmp[j]=tmp[j],tmp[i]
      if tmp == s:
        flag=1
  print('NYOE S'[flag::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())
A = map(int, input().split())
numbers = []
result = True
for i in A:
  numbers.append(int(i))
  result = sorted(numbers)
  if (result == True):
    print("YES")
    return "YES"
  if (result == False):
    for i in range(len(numbers)):
      for x in range(i+1, len(numbers)):
        numbers2 = numbers[:]
        if swap(numbers2, i, x) == True:
          print("TRUE")
          return "TRUE"
        print("FALSE")
        return "FALSE"


def sorted(list):
    result = True
    for i in range(len(list)):
        if i < len(list) - 1:
            if (list[i] > list[i+1]):
                result = False
    return result


def swap(list, pos1, pos2):
    list[pos1], list[pos2] = list[pos2], list[pos1]
    return sorted(list)

X, A = map(int, input().split("/n))
A = j.split()
numbers = []
result = True
for i in A:
  numbers.append(int(i))
  result = sorted(numbers)
  if (result == True):
    print("YES")
    return "YES"
  if (result == False):
    # numbers2 = numbers[:]
    for i in range(len(numbers)):
      for x in range(i+1, len(numbers)):
        numbers2 = numbers[:]
        if swap(numbers2, i, x) == True:
          print("TRUE")
          return "TRUE"
        print("FALSE")
        return "FALSE"


def sorted(list):
    result = True
    for i in range(len(list)):
        if i < len(list) - 1:
            if (list[i] > list[i+1]):
                result = False
    return result


def swap(list, pos1, pos2):
    list[pos1], list[pos2] = list[pos2], list[pos1]
    return sorted(list)

def test(x, j):
    # X, A = map(int, input().split())
    A = j.split()
    numbers = []
    result = True
    for i in A:
        numbers.append(int(i))
    result = sorted(numbers)
    if (result == True):
        print("YES")
        return "YES"
    if (result == False):
        # numbers2 = numbers[:]
        for i in range(len(numbers)):
            for x in range(i+1, len(numbers)):
                numbers2 = numbers[:]
                if swap(numbers2, i, x) == True:
                    print("YES")
                    return "TRUE"
    print("NO")
    return "FALSE"


def sorted(list):
    result = True
    for i in range(len(list)):
        if i < len(list) - 1:
            if (list[i] > list[i+1]):
                result = False
    return result


def swap(list, pos1, pos2):
    list[pos1], list[pos2] = list[pos2], list[pos1]
    return sorted(list)


N = int(input())
p = input()
test(N, p)


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

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

Verdicts: Wrong Answer

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

Submission attempts (in order):
A, B = map(int, input().split())
       if (A + B) % 2 != 0:
           print("IMPOSSIBLE")
       else:
               print(int((A+B)/2))


def check(n, list1): 
    new = [] 
    for i in range(n): 
        new.append(list1[i]) 
          
    new.sort() 
      
    # Check if 0 or 1 swap required  
    # to get the sorted array  
    swaps = 0
    for i in range(n): 
        if list1[i] != new[i]: 
            swaps += 1
              
    if swaps == 0 or swaps == 2: 
        return True
    else: 
        return False
  
n = int(input())
numbers=[]
for i in range(n):
    numbers.append(int(input()))

if check(n, numbers): 
    print("YES")
else:
    print("NO") 

 

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


l=[int(x) for x in input().split()]
cnt=0
x=0
y=0
b=0
for i in range(n):
    if(i+1!=l[i]):
        cnt+=1
        if(cnt==1):
            x=l[i]
        elif(cnt==2):
            y=l[i]
        elif(cnt>0):
            b=1
            break
if(b==1):
    print("NO")
elif(l[x-1]!=y and l[y-1]!=x):
    print("NO")
else:
    print("YES")
            

def check(n, list1): 
    new = [] 
    for i in range(n): 
        new.append(list1[i]) 
          
    new.sort()
    swaps = 0
    for i in range(n): 
        if list1[i] != new[i]: 
            swaps += 1
              
    if swaps == 0 or swaps == 2: 
        return True
    else: 
        return False
  
n = int(input())

numbers =list(map(int, input().split()[:n]))



if check(n, numbers): 
    print("YES")
else:
    print("NO") 

      


Verdicts: Runtime Error

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

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

Verdicts: Wrong Answer

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

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


asc_l = list(range(1, N))

diff_l = p - asc_l
diff_l.count(0) >= N - 2

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

k = 0
counter = 1
for e in p:
    if e == counter:
        counter += 1
    else:
        k += 1
        counter += 1

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

Verdicts: Runtime Error

Accepted