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

count = 0
for i in range(N):
    if P[i] != i + 1:
        count += count + 1
    if count > 2:
        print('No')
        exit()

print('Yes')


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

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

print('YES')


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

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

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()))
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: 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):
import sys
N = int(input())
array = list(map(int,input().split()))
array_base = [ I for I in range(1,N+1) ]

dic = {}
for I in range(N):
    if array[I] != I + 1:
        dic[I] = array[I]
if len(dic) != 2 or len(dic) != 0:
    print('NO')
else:
    print('YES')

import sys
N = int(input())
array = list(map(int,input().split()))
array_base = [ I for I in range(1,N+1) ]

dic = {}
for I in range(N):
    if array[I] != I + 1:
        dic[I] = array[I]

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

Verdicts: Wrong Answer

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

Submission attempts (in order):
import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7


def main():
  N = int(readline())
  P = np.array(readline().split(), np.int64)
  A = np.array(range(1,N+1), np.int64)
  B = np.count_nonzero(P-A)
  print(B)
  if B==0 or B==2:
    ans = 'YES'
  else:
    ans = 'NO'
  print(ans)
  
  
  
  
      
if __name__ == '__main__':
  main()

import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7


def main():
  N = int(readline())
  P = np.array(readline().split(), np.int64)
  A = np.array(range(1,N+1), np.int64)
  B = np.count_nonzero(P-A)
  if B==0 or B==2:
    ans = 'Yes'
  else:
    ans = 'No'
  print(ans)
  
  
  
  
      
if __name__ == '__main__':
  main()

import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7


def main():
  N = int(readline())
  P = np.array(readline().split(), np.int64)
  A = np.array(range(1,N+1), np.int64)
  B = np.count_nonzero(P-A)
  if B==0 or B==2:
    ans = 'YES'
  else:
    ans = 'NO'
  print(ans)
  
  
  
  
      
if __name__ == '__main__':
  main()

Verdicts: Wrong Answer

Wrong Answer

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

Submission attempts (in order):
res = 0
a_sort = sorted(a)

for i in range(n):
    if a_sort[i] != a[i]:
        res += 1

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


n=int(input())
a=list(map(int, input().split()))
ans='Yes'
now=a[0]-1
for i in a: 
    if now>i:
        ans='No'
    now=max(now, i-1)
print(ans)

a

res = 0
a_sort = sorted(a)
 
for i in range(n):
    if a_sort[i] == a[i]:
        res += 1
 
if res >= n - 2:
    print("YES")
else:
    print("NO")

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

res = 0
a_sort = sorted(a)
 
for i in range(n):
    if a_sort[i] == a[i]:
        res += 1
 
if res >= n - 2:
    print("YES")
else:
    print("NO")

Verdicts: Runtime Error

Wrong Answer

Runtime Error

Runtime Error

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

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

N = int(input())
p = list(map(int, input().split()))
P = sorted(p)
ans = 0
for i in range(N):
    if p[i] == P[i]:
        ans += 0
    else:
        ans +=1
print("YES" if ans < 3 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(" ")))
count = 0
minp = p.pop()
for pi in p:
  if minp > pi:
    minp = pi
    count +=1
if count==1:
  print("Yes")
else:
  print("No")

n = int(input())
p = list(map(int, input().split(" ")))
p_sorted = p.copy()
p_sorted.sort()
ans = set(p) ^ set(p_sorted)
if len(ans) <= 2:
  print("Yes")
else:
  print("No")

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

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 = list(map(int, 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):
7
1 2 3 4 5 6 7

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

p_sort=sorted(info)
tem_1=0
tem_2=0
tem=0
for i in range(n-1):
  if info[i]>info[i+1]:
    tem_1=i
    for j in range(n-i-2):
      if info[i+j+1]>info[i+j+2]:
        tem_2=i+j+2
        break
    break
tem=info[tem_1]
info[tem_1]=info[tem_2]
info[tem_2]=tem


for i in range(n):
  if info[i]!=p_sort[i]:
    print("NO")
    break
  
  if i==n-1:
    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()))
flag = 0

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

             

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

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

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

             

if flag >= n-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 = intpu()
seq = list(map(int, input().split()))

for i in range(len(seq)-1):
    if seq[i] <= min(seq[i+1:]):
        continue
    elif seq[i] > min(seq[i+1:]):
        j = seq.index(min(seq[i+1:]))
        if seq[i] > min(seq[i+1:j]+seq[j+1:]):
            print("NO")
            break
        seq[i], seq[j] = seq[j], seq[i]
else:
    print("YES")


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

for i in range(len(seq)-1):
    if seq[i] <= min(seq[i+1:]):
        continue
    elif seq[i] > min(seq[i+1:]):
        j = min(seq[i+1:])
        if seq[i] > min(seq[i+1:j]+seq[j+1:]):
            print("NO")
            break
        seq[i], seq[j] = seq[j], seq[i]
else:
    print("YES")

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

is_switched = False
for i in range(len(seq)-1):
    if seq[i] <= min(seq[i+1:]):
        continue
    elif seq[i] > min(seq[i+1:]):
        if is_switched:
            print("NO")
            break
        j = seq.index(min(seq[i+1:]))
        seq[i], seq[j] = seq[j], seq[i]
        is_switched = True
else:
    print("YES")


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

n = int(input())
a_list = list(map(int, input().split()))
false_count = 0
for index in range(len(a_list)):
  if index + 1 != a_list[index]:
    false_count += 1

if false_count in [0, 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())
count = 0
lia = []
lib = list(map(int,input().split()))
for i in range(1,n+1):
    lia.append(i)
for i in range(n):
    if lia[i] != lib[i]:
        count += 1
    if count > 3:
        print("No")
        break
if count <= 2:
    print("Yes")

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

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

Verdicts: Wrong Answer

Runtime Error

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

Submission attempts (in order):
input1 = input()
 
row = input1.split('\n')

N = int(row[0])
numbers = row[1].split()

counter = 0

for i in range(N):
    if int(numbers[i]) != i+1:
        counter+=1
        
if counter <= 2:
    print('YES')
else:
    print('NO')

N = int(input())
numbers = input().split()

counter = 0

for i in range(N):
    if int(numbers[i]) != i+1:
        counter+=1
        
if counter <= 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, num in enumerate(p):
    if i + 1 != num:
        cnt += 1
if cnt == 0 or cnt == 2:
    print("Yes")
else:
    print("No")


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

cnt = 0
for i, num in enumerate(p):
    if i + 1 != num:
        cnt += 1
if cnt == 0 or cnt == 2:
    print("YES")
else:
    print("NO")


Verdicts: Wrong Answer

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

Submission attempts (in order):

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

srt = sorted(a)

res = "Yes"
cnt = 0
for c,s in zip(a,srt):
    if c != s:
        cnt += 1 
    if cnt > 2:
        res = "No"
        break
print(res)


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

srt = sorted(a)

res = "YES"
cnt = 0
for c,s in zip(a,srt):
    if c != s:
        cnt += 1 
    if cnt > 2:
        res = "NO"
        break
print(res)

Verdicts: Wrong Answer

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

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

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

if c > 2:
    print("NO")
else:
    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")
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()))
sample = sorted(p)
count = 0
for j in range(len(p)):
  if p[j] != sample[j]:
    count += 1
if count < 3:
  print('Yes')
else:
  print('No')

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

Verdicts: Wrong Answer

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

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

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

Verdicts: Wrong Answer

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

Submission attempts (in order):
n = int(input())
xn = map(int,input().split())
k = 0
for i in range(1,n+1)
	if xn[i-1] != i:
    	k += 1
print("NO" if k > 2 else "YES")

n = int(input())
xn = [int(x) for x in input().split()]
k = 0
for i in range(1,n+1):
	if xn[i-1] != i:k += 1
        
print("NO" if k > 2 else "YES")

Verdicts: Runtime Error

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

Submission attempts (in order):
N=int(input())
list1=list(map(int,input().split()))
list2=[]
for i in range(1,N):
  list2.append(i)
a=N
for j in range(0,N-1):
  if list1[j]==list[j]:
    a=a-1
if a>2:
  print("NO")
else:
  print("YES")

N=int(input())
list1=list(map(int,input().split()))
list2=[]
for i in range(1,N):
  list2.append(i)
a=0
for j in range(0,N-1):
  if not list1[j]==list2[j]:
    a+=1
if a>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()))
c = 0
for i in range(N):
    d = int(p[i] != i + 1)
    c = c + d
if c == 0 or c == 2:
    print("Yes")
else:
    print("No")

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

Verdicts: Wrong Answer

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

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


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

n=int(input())
p=list(map(int,input().split()))
cnt=0
for i in range(n):
  if 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())
import sys
a=list(input())
b=a
b.sort()
c=0
for i in range(N):
  if a[i]!=b[i]:
    c+=1
    if c>=2:
      d='No'
      sys.exit()
print('Yes')

  

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

a=sorted(p)
b=0

import sys
for i in range(N):
    if p[i]!=a[i]:
        b+=1
        if b>2:
            print('NO')
            sys.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())
l=list(map(int,input().split()))

def shou(a):
    for i in range(len(a)-1):
        if a[i]>a[i+1]:
          	return -1
    return 1

f=0
for i in range(n):
    for j in range(i):
      	tmp=a[i]
        a[i]=a[j]
        a[j]=tmp
        if shou(a)==1:
            f=1
        tmp=a[i]
        a[i]=a[j]
        a[j]=tmp
if f>0:
  	print('YES')
else:
    print('NO')
         
      		

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

def shou(a):
    for i in range(len(a)-1):
        if a[i]>a[i+1]:
          	return -1
    return 1

f=0
for i in range(n):
    for j in range(i):
      	tmp=a[i]
        a[i]=a[j]
        a[j]=tmp
        if shou(a)==1:
            f=1
        tmp=a[i]
        a[i]=a[j]
        a[j]=tmp
if f>0:
  	print('YES')
else:
    print('NO')
         
      		


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

def shou(a):
    for i in range(len(a)-1):
        if a[i]>a[i+1]:
            return -1
    return 1

f=0
for i in range(n):
    for j in range(n):
        tmp=a[i]
        a[i]=a[j]
        a[j]=tmp
        if shou(a)==1:
            f=1
        tmp=a[i]
        a[i]=a[j]
        a[j]=tmp
if f>0:
    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()))
ans="No"
m=0
for i in range(n-1):
    if p[i]<p[i+1]:
        ans="Yes"
        break
    else:
        for j in range(i+1,n):
            if p[i]>p[j]:
                m=p[i]
                p[i]=p[j]
                p[j]=m
                for k in range(n-1):
                    if p[i]<p[i+1]:
                        ans="Yes"
                        break
print(ans)

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

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

Verdicts: Wrong Answer

Wrong Answer

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

Submission attempts (in order):
a = int(input())
b = input().split()
count=0
for i in range(a):
    if int(b[i]) is not i + 1:
        count += 1
if count == 0 or count == 2:
    print('Yes')
else:
    print('No')

a = int(input())
b = input().split()
count=0
for i in range(a):
    if int(b[i]) is not i + 1:
        count += 1
if count == 0 or count == 2:
    print('YES')
else:
    print('NO')

Verdicts: Wrong Answer

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

Submission attempts (in order):
N = int(input())
A=list(map(int,input().split()))
ask=0
for x in range(0,N):
    if A[x]!=N-x:
        ask=ask+1
if ask==0 or ask==2:
    print('Yes')
else:
    print('No')


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


Verdicts: Wrong Answer

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

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

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

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

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

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

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

ans = 0

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

if ans == 0 or ans == 1:
    print('YES')
else:
    print('NO')

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

ans = 0

for n in range(N):
    if P[n] != n + 1:
        ans += 1

if ans == 0 or ans == 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 numpy as np

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

flip = np.sum(P==np.arange(1, 1+N))
if flip<=2:
    print('YES')
else:
    print('NO')

import numpy as np

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

flip = np.sum(P==np.arange(1, 1+N))
if flip<=2:
    print('YES')
else:
    print('NO')

import numpy as np

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

flip = np.sum(P!=np.arange(1, 1+N))
if flip<=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):
import numpy as np


n = int(input())
arr = list(map(int,input().split()))
base = [i+1 for i in range(n)]

count = 0
for i in range(n):
    if arr[i] != base[i]:
        count += 1

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


import numpy as np

n = int(input())
arr = list(map(int, input().split()))
base = [i + 1 for i in range(n)]

count = 0
for i in range(n):
    if arr[i] != base[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 = [int(s) for s in input().split()]
index = []
for i in range(N):
    index.append(P.index(i+1))
count = 0
for i, j in enumerate(index):
    if i != j:
        count += 1
if count > 2:
    print("No")
else:
    print("Yes")


N = int(input())
P = [int(s) for s in input().split()]
index = []
for i in range(N):
    index.append(P.index(i+1))
count = 0
for i, j in enumerate(index):
    if i != j:
        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()))
count=0
for i in range(n-1):
  if p[i]!=i+1
      count=count+1
if count<2:
  print('YES')
else:
  print('NO')

n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
answer=0
for i in range(n):
  if a[i]>=b[i]:
    answer+=b[i]
    a[i]=0
    b[i]=0
  elif a[i]<b[i] and a[i]+a[i+1]>=b[i]:
    answer+=b[i]
    b[i]-=a[i]
    a[i+1]-=b[i]
  elif a[i]<b[i] and a[i]+a[i+1]<b[i]:
    answer+=(a[i]+a[i+1])
    b[i]-=(a[i]+a[i+1])
    a[i]=0
    a[i+1]=0
print(answer)

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

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

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

Verdicts: Runtime Error

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):
input()
p = [int(x) for x in input()]
q = sorted(p)
d = [(pi, qi) for pi, qi in zip(p, q) if pi != qi]
print("YES" if len(d) == 0 or len(d) == 2 and d[0][0] == d[1][1] and d[1][0] == d[0][1] else "NO")

input()
p = [int(x) for x in input().split()]
q = sorted(p)
d = [(pi, qi) for pi, qi in zip(p, q) if pi != qi]
print("YES" if len(d) == 0 or len(d) == 2 and d[0][0] == d[1][1] and d[1][0] == d[0][1] else "NO")

Verdicts: Runtime Error

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

Submission attempts (in order):
N = int(input())
P = list(input(). split())
Q = sorted(P)
cnt = 0
i = 0

while cnt <= 2 and i < len(P):
  if Q[i] != P[i]:
    cnt += 1
  i += 1

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

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

while cnt <= 2 and i < len(P):
  if Q[i] != P[i]:
    cnt += 1
  i += 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()))

cnt = 0
for k,v in enumerate(p):
  if k+1 != v:
    cnt += 1

if cnt > 1:
  print('NO')
else:
  print('YES')

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

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

if cnt > 1:
  print('NO')
else:
  print('YES')

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

cnt = 0
for k,v in enumerate(p):
  if k+1 != v:
    cnt += 1

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

Verdicts: Wrong Answer

Wrong Answer

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

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

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

n = int(input())
p = list(map(int, input().split()))
l = list(range(1,(n+1)))

if p == l:
    ans = "YES"
cnt = 0
for i in range(n):
    if p[i] != l[i]:
        if p[p[i]-1] == l[i]: cnt += 1
        else:
            ans = "NO"
            break
if cnt > 0:
    print("YES" if cnt//2 == 1 else "NO")
else:
    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):
import numpy as np

s = input().split()
N=int(s[0])
s = input().split()
a=np.array(range(1,N+1))
s=[int(i) for i in s]
if np.count_nonzero(a != s)<2:
    print('YES')
else:
    print('NO')

import numpy as np

s = input().split()
N=int(s[0])
s = input().split()
a=np.array(range(1,N+1))
s=[int(i) for i in s]
if np.count_nonzero(a != 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())
l = list(map(int,input().split()))
l_s = sorted(l)
a = 0
for i in range(n):
  if l[i] == l_s[i]:
    a += 1
if a == 0 or a == 2:
  print("YES")
else:
  print("NO")

n = int(input())
l = list(map(int,input().split()))
l_s = sorted(l)
a = 0
for i in range(n):
  if not l[i] == l_s[i]:
    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())
li = list(map(int, input().split()))
tmp = list()
ans = 'Yes'
for i in range(1, N):
    if li[i-1] > li[i]:
        tmp.append(li[i-1])
if len(tmp) != 2:
    ans == 'No'
else:
    t = li[li.index(tmp[0])]
    li[li.index(tmp[0])] = li[li.index(tmp[1])+1]
    li[li.index(tmp[1])+1] = t
    for i in range(1,N):
        if li[i-1] > li[i]:
            ans = 'No'
print(ans)

N = int(input())
li = list(map(int, input().split()))
tmp = list()
ans = 'Yes'
for i in range(1, N):
    if li[i-1] > li[i]:
        tmp.append(li[i-1])
if len(tmp) != 2:
    ans == 'No'
else:
    t = li[tmp[0]]
    li[li.index(tmp[0])] = li[li.index(tmp[1])+1]
    li[li.index(tmp[1])+1] = t
    for i in range(N):
        if li[i-1] > li[i]:
            ans = 'No'
print(ans)

N = int(input())
li = list(map(int, input().split()))
ans = list()
for i in range(N):
  if i+1 != li[i]:
    ans.append('groot')
if len(ans) <= 2:
  print('YES')
else:
  print('NO')

Verdicts: Wrong Answer

Runtime Error

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

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

n = int(input())
L = list(map(int,input().split()))
li = [x+1 for x in range(n)]

cnt = 0
for i in range(n):
    if L[i] != li[i]:
        cnt +=1
if (cnt == 2 or cnt == 0):
    print("Yes" )
else:
    print("No")

n = int(input())
L = list(map(int,input().split()))
li = [x+1 for x in range(n)]
cnt = 0
for i in range(n):
    if L[i] != li[i]:
        cnt +=1
print("YES" if (cnt == 2 or cnt == 0) 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):
# 2019-11-15 14:37:47(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def main():
    n, *p = [int(x) for x in sys.stdin.read().split()]

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

    print('Yes' if p == list(range(1, n+1)) else 'No')


if __name__ == "__main__":
    main()


import sys

n, *p = map(int, sys.stdin.read().split())


def main():
    cnt = 0
    for i in range(n):
        if p[i] != i + 1:
            cnt += 1
    
    if not cnt or cnt == 2:
        return 'YES'
    return 'NO'

if __name__ == '__main__':
    ans = main()
    print(ans)

Verdicts: Wrong Answer

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

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

v = sorted(p)
cou=0
for i in range(n):
    if not p[i] == v[i]:
        cou+=1

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

p = map(int, '1 2 3 4 5 6 7'.split())
v = sorted(p)
cou=0
if p==v:
    cou =2
else:
    for i in range(len(p)):
        if not p[i] == v[i]:
            print i
            cou+=1

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

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

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

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

n = int(input)
p = list(map(int, input().split()))
v = sorted(p)
cou=0
for i in range(n):
    if not p[i] == v[i]:
        cou+=1

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


n = int(input)
p = list(map(int, input().split()))
v = sorted(p)
cou=0
if p==v:
    cou =2
else:
    for i in range(len(p)):
        if not p[i] == v[i]:
            cou+=1

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

n = int(input)
p = list(map(int, input().split()))
v = sorted(p)
cou=0
if p==v:
    cou =2
else:
    for i in range(len(p)):
        if not p[i] == v[i]:
            cou+=1

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

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

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

n = int(input)
p = map(int, input().split())
v = sorted(p)
cou=0
if p==v:
    cou =2
else:
    for i in range(len(p)):
        if not p[i] == v[i]:
            print i
            cou+=1

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

n = int(input)
p = list(map(int, input().split()))
v = sorted(p)
cou=0
for i in range(n):
    if not p[i] == v[i]:
        cou+=1

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


n = int(input)
p = list(map(int, input().split()))
v = sorted(p)
cou=0
if p==v:
    cou =2
else:
    for i in range(len(p)):
        if not p[i] == v[i]:
            cou+=1

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



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

v = sorted(p)
cou=0
for i in range(n):
    if not p[i] == v[i]:
        cou+=1

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

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

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

Submission attempts (in order):
n=list(map(int,list(open(0))[1].split()))
m=sorted(n)
a=b=0
for _ in range(len(n)):a+=0if n[_]==m[_]else 1
b=1if a>2else 0
print('YNeos'[b::2])

n=list(map(int,list(open(0))[1].split()))
m=sorted(n)
a=b=0
for _ in range(len(n)):a+=0if n[_]==m[_]else 1
b=1if a>2else 0
print('YNEOS'[b::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()))

def bubble(input_list):
    cnt = 0
    flg = 0
    for i in range(len(input_list)):
        if i != input_list[i]:
            cnt +=1
            flg = 1
    if flg == 1:
        return False, cnt
    else:
        return True, 0
a, b = bubble(p)

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


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

def bubble(input_list):
    for i in range(len(input_list) -1):
        if input_list[i] > input_list[i +1]:
            return False
    return True

if bubble(p):
    print("YES")
    exit()

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

print("YES" if bubble(p) else "NO")

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

def bubble(input_list):
    cnt = 0
    flg = 0
    for i in range(len(input_list)):
        if i+1 != input_list[i]:
            cnt +=1
            flg = 1
    if flg == 1:
        return False, cnt
    else:
        return True, 0
a, b = bubble(p)

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

Verdicts: Wrong Answer

Wrong Answer

Accepted