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

n = int(input())
p = [int(i) for i in range(n)]
s = 0
for i in range(n-1):
  if p[i] > p[i+1]:
    s += 1
if s >= 2:
  print("No")
else:
  print("Yes")

n = int(input())
p = [int(i) for i in range(1,n+1)]
s = 0
for i in range(n):
  if p[i] != i + 1:
    s += 1
if s > 2:
  print("No")
else:
  print("Yes")

n = int(input())
p = [int(i) for i in range(n)]
s = 0
for i in range(n):
  if p[i] != i + 1:
    s += 1
if s > 2:
  print("No")
else:
  print("Yes")

n = int(input())
p = [int(i) for i in range(n)]
s = 0
for i in range(n-1):
  if p[i] > p[i+1]:
    s += 1
if s >= 3:
  print("No")
else:
  print("Yes")

n = int(input())
p = [int(i) for i in range(n)]
s = 0
for i in range(n-1):
  if p[i] != i + 1:
    s += 1
if s > 2:
  print("No")
else:
  print("Yes")

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

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

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

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

N = int(input())
list1 = list(map(int, input().split()))
count = 0
 
for i in range(N-1):
  if list1[i] > list1[i+1]:
    count += 1

if count == 0:
  print("YES")
elif count == 1:
  count = 0
  for i in range(N-1):
    if list1[i] > list1[i+1]:
      x = i
  a = list1[x] 
  b = list1[x + 1]
  list1[x] = b
  list1[x + 1] = a
  for i in range(N-1):
    if list1[i] > list1[i+1]:
      count += 1
  if count == 0:
    print("YES")
  else:
    print("NO")
elif count >= 3:
  print("NO")
else:
  count = 0
  list2 = []
  for i in range(N-1):
    if list1[i] > list1[i+1]:
      list2.append(i)
  a = list1[list2[0]] 
  b = list1[list2[1] + 1]
  list1[list2[0]] =b
  list1[list2[1] + 1] =a
  for i in range(N-1):
    if list1[i] > list1[i+1]:
      count += 1
  if 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()))
count = 0
for i in range(N-1):
	if  p[i + 1] - p[i] != 1:
      count += 1
if count <= 2:
  print("YES")
else:
  print("NO")

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


Verdicts: Runtime Error

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

Submission attempts (in order):
n = int(input())
plst = list(map(int,input().split()))
plst_sort = sorted(plst)
cnt = 0
for i in range(N):
    if plst[i] != plst_sort[i]:
        cnt += 1
if cnt == 2 or cnt == 0:
    print("YES")
else:
    print("NO")


n = int(input())
plst = list(map(int,input().split()))
plst_sort = sorted(plst)
cnt = 0
for i in range(len(plst)):
    if plst[i] != plst_sort[i]:
        cnt += 1
if cnt == 2 or cnt == 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 = [int(n) for n in input().split()]
X = [n for n in range(1, N+1)]
ans = sum([0 if p==x else 1 for p,x in zip(p,X)])
print("Yes" if ans <= 2 else "No")

N = int(input())
p = [int(n) for n in input().split()]
X = [n for n in range(1, N+1)]
print("Yes" if sum([0 if p==X else 1 for p,x in zip(p,X)]) <=2 else "No")

N = int(input())
P = [int(n) for n in input().split()]
X = [n for n in range(1, N+1)]
ans = sum([0 if p==x else 1 for p,x in zip(P, X)])
print('YES' if ans <= 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 = input()
p = list(map(int,input().split()))

ps = sorted(p)

d_p = []
d_ps = []
for i,q in enumerate(p):
  if q != ps[i]:
    d_p.append(q)
    d_ps.append(ps[i])
if len(d_p) > 2:
  print('No')
elif len(d_p) == 2:
  d_p.sort()
  if d_p == d_ps:
    print('Yes')
  else:
    print('No')
else:
  print('Yes')

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

ps = sorted(p)

d_p = []
d_ps = []
for i,q in enumerate(p):
  if q != ps[i]:
    d_p.append(q)
    d_ps.append(ps[i])
if len(d_p) > 2:
  print('No')
elif len(d_p) == 2:
  d_p.sort()
  if d_p == d_ps:
    print('Yes')
  else:
    print('No')
else:
  print('Yes')

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

ps = sorted(p)

count = 0
for q, qs in zip(p, ps):
  if q != qs:
    count += 1
    
print('YES' if count <= 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()))

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

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

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

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

if cnt <= 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())
pn = [int(num) for num in input().split()]

k = 0
for i in range(1, len(pn)):
    if (i+1) != pn[i]:
      k += 1

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


n = int(input())
pn = [int(num) for num in input().split()]

k = 0
for i in range(0, len(pn)):
    if (i+1) != pn[i]:
      k += 1

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


Verdicts: Wrong Answer

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

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


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


Verdicts: 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(x) for x in input().split()]

count = 0
index = []

for i in range(n-1):
  if p[i] < p[i+1]:
    pass
  else:
    count += 1
    index.append(i)

if count == 0:
  print('YES')
elif count == 2:
  print('NO')
else:
  p[index[0]], p[index[1] + 1] = p[index[1] + 1], p[index[0]]
  sorted_p = sorted(p)
  if p == sorted_p:
    print('YES')
  else:
    print('NO')

n = int(input())
p = [int(x) for x in input().split()]
 
count = 0
index = []
 
for i in range(n-1):
  if p[i] < p[i+1]:
    pass
  else:
    count += 1
    index.append(i)

if count == 0:
  print('YES')
elif count != 2:
  print('NO')
else:
  p[index[0]], p[index[1] + 1] = p[index[1] + 1], p[index[0]]
  sorted_p = sorted(p)
  if p == sorted_p:
    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()))
ans = [i for i in range(1,n+1)]
cnt = 0

for i in range(n):
  if p[i] != ans[i]:
    cnt += 1
  if cnt > 2:
    print('No')
    exit()
    
print('Yes')

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

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

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

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

Verdicts: Wrong Answer

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

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

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

        

N=int(input())
p=list(map(int,input().split()))
false_num=0
for i in range(N-1):
    if p[i]+1==p[i+1]:
        continue
    else:
        false_num+=1

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


    
        

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

if false_num==0 or false_num==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()))
count=0
for i in range(1,n+1):
            if i !=l[i-1]:
                        count+=1
                     
if count<=2:
            print('Yes')
else:
            print('No')
            
                                    
                                    
                                    


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


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


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


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

l=sorted(a)

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


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

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

Submission attempts (in order):
n,*p = map(int,open(0).read().split())
ans = 0
for i in range(n):
    if i+1 != p[i]:
        if i+1 == p[p[i]-1]:
            ans += 1

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

n,*p = map(int,open('abc135.txt').read().split())
ans = 0
for i in range(n):
    if i+1 != p[i]:
        if i+1 == p[p[i]-1]:
            ans += 1

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

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

n,*p = map(int,open('abc135.txt').read().split())
ans = 0
for i in range(n):
    if i+1 != p[i]:
        if i+1 == p[p[i]-1]:
            ans += 1

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

n,*p = map(int,open(0).read().split())
ans = 0
for i in range(n):
    if i+1 != p[i]:
        ans += 1
print('YES' if ans == 2 or ans == 0 else 'NO')

Verdicts: Wrong Answer

Runtime Error

Runtime Error

Runtime Error

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

Submission attempts (in order):
n = int(input())
p = list(map(int,input().split()))
check = {}
cnt = 0
ans = [i for i in range(n)]
for i in range(n):
    if(p[i]==ans[i]+1):
        continue
    elif(p[i]!=ans[i]):
        check[i] = p[i]
        if(cnt<3):
            cnt += 1
        else:
            break
if(cnt==0):
    print("Yes")
elif(cnt==2):
    print("Yes")
else:
    print("No")
        
        
    

n = int(input())
p = list(map(int,input().split()))
check = {}
cnt = 0
ans = [i+1 for i in range(n)]
for i in range(n):
    if(p[i]==ans[i]):
        continue
    elif(p[i]!=ans[i]):
        check[i] = p[i]
        if(cnt<3):
            cnt += 1
        else:
            break
if(cnt==0):
    print("YES")
elif(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):
def main37():
    num = int(input())
    data = input().split()
    retu = []
    for i in range(num):
        retu.append(int(data[i]))
    kari = list(retu)
    kari.sort()
    kosu = 0
    for i in range(num):
        if retu[i] != kosu[i]:
            kosu = kosu + 1
    if kosu == 2 or kosu == 0:
        print("YES")
    else:
        print("NO")

if __name__ == "__main__":
    main37()

def main37():
    num = int(input())
    data = input().split()
    retu = []
    for i in range(num):
        retu.append(int(data[i]))
    kari = list(retu)
    kari.sort()
    kosu = 0
    for i in range(num):
        if retu[i] != kari[i]:
            kosu = kosu + 1
    if kosu == 2 or kosu == 0:
        print("YES")
    else:
        print("NO")

if __name__ == "__main__":
    main37()

Verdicts: Runtime Error

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

Submission attempts (in order):
N=int(input())
P=list(map(int, input().split()))
Q=P[:]
Q.sort()
print(P)
print(Q)

not_equal_count=0
for i in range(N):
  if P[i] != Q[i]:
    not_equal_count += 1
if not_equal_count in [0, 2]:
  print("YES")
else:
  print("NO")

N=int(input())
P=list(map(int, input().split()))
Q=P[:]
Q.sort()

not_equal_count=0
for i in range(N):
  if P[i] != Q[i]:
    not_equal_count += 1
if not_equal_count in [0, 2]:
  print("YES")
else:
  print("NO")

Verdicts: Wrong Answer

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

Submission attempts (in order):
n = input()
s = input().split()
s=[int(i) for i in s]
count=-1
for i in range(int(n)//2):
   if s[i] + s[count] ==int(n)+1:
      count-=1
   	else:
      print("No")

if int(n) %2 ==0：
   print("YES")
else:
   if s[count]*2 == n :
    print("YES")
    else:
      print("NO")
  

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

count=0
for i in range(int(n)):
  if N[i] !=i+1:
    count+=1
if count > 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()))
ans = "YES"
for i in range(N-1):
    if p[i] > p[i+1]:
        ans ="NO"
        break

if ans != "YES":
    for i in range(N-1):
        for j in range(i+1,N-1):
            pcopy = p.copy()
            pcopy[i],pcopy[j] = pcopy[j],pcopy[i]
            flg = True
            for k in range(N-1):
                if pcopy[k] > pcopy[k+1]:
                    flg = False
            if flg:
                ans ="YES"
                break        

print(ans)

N=int(input())
p=list(map(int,input().split()))
ans = "YES"
for i in range(N-1):
    if p[i] > p[i+1]:
        ans ="NO"
        break

if ans != "YES":
    for i in range(N-1):
        for j in range(i+1,N):
            pcopy = p.copy()
            pcopy[i],pcopy[j] = pcopy[j],pcopy[i]
            flg = True
            for k in range(N-1):
                if pcopy[k] > pcopy[k+1]:
                    flg = False
            if flg:
                ans ="YES"
                break        

print(ans)

Verdicts: Wrong Answer

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

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

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


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

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


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

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

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

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

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

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

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

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

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

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

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

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

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

Submission attempts (in order):
# stdin
INPUT_SENTENCES = 2
ss = [input() for i in range(INPUT_SENTENCES)]
N = int(ss[0])
p = list(map(lambda x: int(x), ss[1].split()))
rev_index = []
for i in range(N-1):
    if p[i] > p[i+1]:
        if len(rev_index) > 0:
            rev_index.append(i+1)
        else:
            rev_index.append(i)
elif len(rev_index) > 0:
    p[rev_index[0]], p[rev_index[1]] = p[rev_index[1]], p[rev_index[0]]
if p == list(range(1,N+1)):
    print("YES")
else:
    print("NO")

# stdin
INPUT_SENTENCES = 2
ss = [input() for i in range(INPUT_SENTENCES)]
N = int(ss[0])
p = list(map(lambda x: int(x), ss[1].split()))
rev_index = []
for i in range(N-1):
    if p[i] > p[i+1]:
        if len(rev_index) > 0:
            rev_index.append(i+1)
        else:
            rev_index.append(i)
if len(rev_index) == 2:
    p[rev_index[0]], p[rev_index[1]] = p[rev_index[1]], p[rev_index[0]]
if p == list(range(1,N+1)):
    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()))

f = False
for i in range(n-1):
    for j in range(i+1, n):
        q = p[:]
        b = q.pop(j)
        a = q.pop(i)
        q.insert(i, b)
        q.insert(j, a)
        r = sorted(q[:])
        if q == r:
            f = True
            break
    if f:
        break

if p == sorted(p):
    f =True

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


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

f = False
for i in range(n-1):
    for j in range(i+1, n):
        q = p[:]
        b = q.pop(j)
        a = q.pop(i)
        q.insert(i, b)
        q.insert(j, a)
        r = sorted(q[:])
        if q == r:
            f = True
            break
    if f:
        break

if p == sorted(p):
    f =True

if f:
    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()))
sort_P = sorted(P)

diff = 0
for p, sp in zip(P, sort_P):
    if p != sp:
        diff += 1
print(diff)
if diff == 2 or diff == 0:
    print('YES')
else:
    print('NO')

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

diff = 0
for p, sp in zip(P, sort_P):
    if p != sp:
        diff += 1
        
if diff == 2 or diff == 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()))
f=0
for i in range(n):
  if p[i]!=i+1:
    f+=1
print("Yes" if f<=2 else "No")
  

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

Verdicts: Wrong Answer

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

Submission attempts (in order):
#!/usr/bin/env python
import math

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

r = []

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

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


#!/usr/bin/env python
import math

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

r = []

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

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


Verdicts: Wrong Answer

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

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

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

if numlist==p:
        output="YES"
else: 
    dist=0    
    for s,t in zip(numlist,p):
        if s!=t:
                dist=dist+1
        else:
#                dist=dist+0
            pass
    if dist=2:
        output="YES"
    else :
        output="NO"        
print(output)

N=input()
p=input()
N=int(N.split()[0])
p=p.split()
p=[int(p) for p in p]
numlist=sorted(p)

if numlist==p:
        output="YES"
else: 
    dist=0    
    for s,t in zip(numlist,p):
        if s!=t:
                dist=dist+1
        else:
#                dist=dist+0
            pass
    if dist==2:
        output="YES"
    else :
        output="NO"        
print(output)

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-1):
    if P[i] > P[i+1]:
        cnt += 1
    if cnt > 1:
        print('NO')
        exit()

print('YES')


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

cnt = 0

for i in range(N):
    if i+1 != P[i]:
        cnt += 1
    if cnt > 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()))
A = []
for i in range(N-1):
    if P[i]>P[i+1]:
        A.append([(P[i],i),(P[i+1],i+1)])
l = len(A)
if l > 2:
    print("NO")
elif l ==1:
    print("NO")
elif l == 0:
    print("YES")
else:
    a = max(A[0])
    b = min(A[1])
    P[a[1]],P[b[1]] = b[0],a[0]
    #print(P)
    for j in range(N-1):
        if P[j] > P[j+1]:
            print("NO")
            break
    if j == N-2:
        print("YES")
for i in range(1):
    print(i)


N = int(input())
P = list(map(int,input().split()))
A = []
for i in range(N-1):
    if P[i]>P[i+1]:
        A.append([(P[i],i),(P[i+1],i+1)])
l = len(A)
if l > 2 or l == 1:
    print("NO")
elif l == 0:
    print("YES")
elif l == 2:
    a = max(A[0])
    b = min(A[1])
    P[a[1]],P[b[1]] = b[0],a[0]
    for j in range(N-1):
        if P[j] > P[j+1]:
            print("NO")
            j = "j"
            break
    if j != "j":
        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
n = int(input())
s = list(map(int,input().split()))
a = np.array(list(range(1,n+1)))
b = np.array(s)
if len(a[a==b]) > n-2:
    print("YES")
else:
    print("NO")

import numpy as np
n = int(input())
s = list(map(int,input().split()))
a = np.array(list(range(1,n+1)))
b = np.array(s)
if len(a[a==b]) >= n-2:
    print("YES")
else:
    print("NO")

Verdicts: Wrong Answer

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

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

cnt = 0
for i in range(1, N+1):
    if P[i] != i:
        cnt += 1
        
print('YES' if cnt == 2 else 'NO')

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

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

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

Verdicts: Runtime Error

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

Submission attempts (in order):
import numpy as np
n = int(input())
p = list(map(int, input().split()))
print(n)

p2 = p.copy()
p2.sort()

p = np.asarray(p)
p2 = np.asarray(p2)
p3 = [p!=p2]
c = np.count_nonzero(p3)
if c == 2 or c == 0:
    print("YES")
else:
    print("NO")


import numpy as np
n = int(input())
p = list(map(int, input().split()))

p2 = p.copy()
p2.sort()

p = np.asarray(p)
p2 = np.asarray(p2)
p3 = [p!=p2]
c = np.count_nonzero(p3)
if c == 2 or c == 0:
    print("YES")
else:
    print("NO")


Verdicts: Wrong Answer

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

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

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

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

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

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

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

swap = 0
done = False
ok = True
for i in range(n):
    p = next(ps)
    if p != i+1:
        if done:
            ok = False
            break
        elif swap != 0:
            if swap == i+1:
                done = True
                swap = 0
            else:
                ok = False
                break
        else:
            swap = p

print(ok)


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

swap = 0
done = False
ok = True
for i in range(n):
    p = next(ps)
    if p != i+1:
        if done:
            ok = False
            break
        elif swap != 0:
            if swap == i+1:
                done = True
                swap = 0
            else:
                ok = False
                break
        else:
            swap = p

if ok:
    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(i) for i in input().split()]
n1=[i for i in range(1,n+1)]
for i in n1:
  for k in n1:
    n1=n1.replace(i,k)
    if n1==p:
      print('YES')
      exit()
else:
  print('NO')
    
 

n=int(input())
p=[int(i) for i in input().split()]
n1=[i for i in range(1,n+1)]
for i in range(n):
  for k in range(n):
    n1[i],n1[k]=n1[k],n1[i]
    if n1==p:
      print('YES')
      exit()
    n1=[i for i in range(1,n+1)]
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())
l = list(int(i) for i in input().split())
s = l.copy()
s.sort()

flag = False
if s == l:
  flag = True
else:
  for i in range(n):
    for j in range(i+1, n):
      t = l.copy()
      t[i], t[j] = t[j], t[i]
      if s == t:
        flag = True

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

n = int(input())
l = list(int(i) for i in input().split())
s = l.copy()
s.sort()

flag = False
if s == l:
  flag = True
else:
  for i in range(n):
    for j in range(i+1, n):
      t = l.copy()
      t[i], t[j] = t[j], t[i]
      if s == t:
        flag = True

if flag:
  print("YES")
else:
  print("NO")

Verdicts: Wrong Answer

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

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

import math
for i in range (math.ceil(N / 2)):
	if p[i] != i + 1:
		j = p.index(i + 1)
		p[i], p[j] = p[j], p[i]
		break
		
print(p)
		
if p == [i for i in range(1, N + 1)]:
	print('YES')
else:
	print('NO')

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

for i in range(N):
	if p[i] != i + 1:
		j = p.index(i + 1)
		p[i], p[j] = p[j], p[i]
		break
		
if p == [i for i in range(1, N + 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):
# coding: utf-8
n = int(input())
p_list = list(map(int, input().split()))

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

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


# coding: utf-8
n = int(input())
p_list = list(map(int, input().split()))

count = 0
for i in range(n):
    if p_list[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):
A = int(input())
re = 0
B = list(map(int, input().split()))
C = [i for i in range(1, A+1)]
for B, C in zip(B, C):
  if B != C:
    re += 1

if re >= 2:
  print('NO')
else:
  print('YES')
  

A = int(input())
re = 0
B = list(map(int, input().split()))
C = [i for i in range(1, A+1)]
for B, C in zip(B, C):
  if B != C:
    re += 1

if re >= 3:
  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()))

dic = {}
for i in range(n-1):
    a = p[i+1]-p[i]
    if a in dic and a != 1:
        dic[a] += 1
    elif a not in dic and a != 1:
        dic[a] = 1

flag = False
for i in dic.values():
    if i == 2 and len(dic) == 2:
        flag = True
        break
    else:
        continue

if flag:
    print("YES")
else:
    if len(dic) == 0:
        print("YES")
    else:
        print("NO")


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

dic = {}
for i in range(n-1):
    a = p[i+1]-p[i]
    if a in dic and a != 1:
        dic[a] += 1
    elif a not in dic and a != 1:
        dic[a] = 1

flag = False
for k,v in dic.values():
    if i == 2 :
        flag = True
        break
    else:
        continue

if flag:
    print("YES")
else:
    if len(dic) == 0:
        print("YES")
    else:
        print("NO")


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

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

if 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):
N=int(input())
L=list(map(int,input().split()))
m=[]
for i in range(1,N+1):
  m.append(i)
m.sort()
a=0
for j in range(N):
  if L[j]!=m[j]:
    a+=1
if a<=2:
  print('Yes')
else:
  print('No')
  

N=int(input())
L=list(map(int,input().split()))
m=[]
for i in range(1,N+1):
  m.append(i)
m.sort()
a=0
for j in range(N):
  if L[j]!=m[j]:
    a+=1
if a<=2:
  print('YES')
else:
  print('NO')
  

Verdicts: Wrong Answer

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

Submission attempts (in order):
input_arr = [input() for i in range(2)]
N = input_arr[0]
p_arr = input_arr[1].split(' ')

for i in range(len(p_arr)):
    k = 0
    if int(p_arr[i]) == i + 1:
        pass
    else:
        k += i

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

input_arr = [input() for i in range(2)]
N = input_arr[0]
p_arr = input_arr[1].split(' ')

for i in range(len(p_arr)):
    k = 0
    if int(p_arr[i]) == i:
        pass
    else:
        k += i
if k <= 2:
    print("YES")
else:
    print("NO")

input_arr = [input() for i in range(2)]
N = input_arr[0]
p_arr = input_arr[1].split(' ')

for i in range(len(p_arr)):
    k = 0
    if int(p_arr[i]) == i + 1:
        pass
    else:
        k += 1
print(k)
if k < 2:
    print("YES")
else:
    print("NO")

input_arr = [input() for i in range(2)]
N = input_arr[0]
p_arr = input_arr[1].split(' ')

k = 0
for i in range(len(p_arr)):
    if int(p_arr[i]) == i + 1:
        pass
    else:
        k += 1
if k < 2:
    print("YES")
else:
    print("NO")

input_arr = [input() for i in range(2)]
N = input_arr[0]
p_arr = input_arr[1].split(' ')

for i in range(len(p_arr)):
    k = 0
    if int(p_arr[i]) == i:
        pass
    else:
        k += i
if k < 2:
    print("YES")
else:
    print("NO")

input_arr = [input() for i in range(2)]
N = input_arr[0]
p_arr = input_arr[1].split(' ')

k = 0
for i in range(len(p_arr)):
    if int(p_arr[i]) == i + 1:
        pass
    else:
        k += 1
print(k)
if k < 2:
    print("YES")
else:
    print("NO")

input_arr = [input() for i in range(2)]
N = input_arr[0]
p_arr = input_arr[1].split(' ')
 
k = 0
for i in range(len(p_arr)):
    if int(p_arr[i]) == i + 1:
        pass
    else:
        k += 1
if k <= 2:
    print("YES")
else:
    print("NO")

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted