Problem:


Score : 200 points

Problem Statement

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.

Constraints

All values in input are integers.

2 \leq N \leq 50

p is a permutation of {1,\ 2,\ ...,\ N}.

Input

Input is given from Standard Input in the following format:

N
p_1 p_2 ... p_N

Output

Print YES if you can sort p in ascending order in the way stated in the problem statement, and NO otherwise.

Sample Input 1

5
5 2 3 4 1

Sample Output 1

YES

You can sort p in ascending order by swapping p_1 and p_5.

Sample Input 2

5
2 4 3 5 1

Sample Output 2

NO

In this case, swapping any two elements does not sort p in ascending order.

Sample Input 3

7
1 2 3 4 5 6 7

Sample Output 3

YES

p is already sorted in ascending order, so no operation is needed.



Sample input:
5
5 2 3 4 1


Sample output:
YES

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())       
p = list(map(int, input().split()))

n_l = [i for i in range(1, n+1)]
n_l.reverse()


if n_l == p:
    print('YES')
else:
    for i in range(n):
        for j in range(n):
            p[i], p[j] = p[j], p[i]
            if n_l == p:
                print('YES')
                sys.exit()
            else:
                p[i], p[j] = p[j], p[i]

print('NO')

Submission status: Wrong Answer

Solution code:
n,*p=map(int,open(0).read().split())
q=sorted(p)
for i in range(n):
  for j in range(n):
    r=p[:]
    r[i],r[j]=r[j],r[i]
    print(r)
    if r==q:
      print('YES')
      exit()
print('NO')

Submission status: Wrong Answer

Solution code:
n,*p=map(int,open(0).read().split())
q=sorted(p)
for i in range(n-1):
    r=p[:]
    r[i],r[i+1]=r[i+1],r[i]
    if r==q:
        print('YES')
        exit()
print('NO')

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
p = LIST()

if p == sorted(p):
  print("Yes")
  exit()

for i in range(N-1):
  for j in range(i+1, N):
    q = p.copy()
    q[i] = p[j]
    q[j] = p[i]
   
    if q == sorted(p):
      print("Yes")
      exit()
      
print("No")

Submission status: Wrong Answer

Solution code:
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 and sum(lib) == sum(lia):
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
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")

Submission status: Wrong Answer

Solution code:
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")

Submission status: Wrong Answer

Solution code:
n=int(input())
p=list(map(int, input().split()))
t=tuple(p)
p.sort()
c=0
for i in range(n):
  if p[i]!=t[i]:
    c+=1
if c==0 or c==2:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print("NO") if count > 2 else print("YES")

Submission status: Wrong Answer

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

print("NO") if count > 2 else print("YES")

Submission status: Wrong Answer

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

print("No") if count > 2 else print("Yes")

Submission status: Wrong Answer

Solution code:
N=int(input())
P=list(map(int,input().split()))
cnt=0
for n in range(N):
    if n+1!=P[n]:
        cnt+=1
        if cnt>2:
            print("No")
            exit()

print("Yes")

Submission status: Wrong Answer

Solution code:
n=int(input())
p=list(map(int,input().split()))
count=0
num=0
for i in p:
    if i!=num+1:
        count+=1
    num+=1
if count>2:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
N = int(input())
P = list(map(int, input().split()))
count = 0

for i in range(N):
  if P[i] == i+1:
    continue
  else:
    count += 1

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N=int(input())
p=list(map(int, input().split()))
t=1
for i in range(N):
    if t==p[i]:
        t+=1
    else:
        index=p.index(t)
        p[index]=i+1
        p[i]=p[index]
        break

for j in range(N-1):
    if p[j]+1==p[j+1]:
        pass
    else:
        print("NO")
        exit()
print("YES")

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = sorted(A)
k = 0
for i in range (N):
    if B[i] != A[i]:
        k += 1
if k >= 4:
    print("NO")
else:
    print("YES")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import copy
N=int(input())
p=[int(i) for i in input().rstrip().split()]
p_c=copy.deepcopy(p)
p_c.sort()

cnt=0
for i in range(len(p)):
  if p[i]!=p_c[i]:
    cnt+=1
  else:
    continue


if cnt==2 or cnt==0:
  print("YES")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
p = list(map(int,input().split()))
nlst = [x for x in range(1,n+1)]
lst = [0]*n
for i in range(n):
  if nlst[i] == p[i]:
    lst[i] = 1
print('YES' if sum(lst) in [0,2] else 'NO')

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int, input().split()))
F=0
for i in range(n):
    F+=(i+1 != x[i])
print(F)
if F==0 or F==2: print('YES')
else           : print('NO')

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int, input().split()))
F=0
for i in range(n): F+=(i+1 != x[i])
if F==0 or F==2: print('YES')
else           : print('No')

Submission status: Wrong Answer

Solution code:
N = int(input())
pn = list(map(int, input().split()))
flag = True
check = 0
for i in range(N-1):
    if check < 3:
        if pn[i+1] - pn[i] != 1:
            check += 1
    else:
        flag = False
        break
print('YES' if flag else 'NO')

Submission status: Wrong Answer

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

cnt = 0

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
p = list(map(int, input().split()))
p_l = sorted(p)
count =0

if p == p_l:
    print("Yes")

else:
    for i in range(n):
        if not p[i] == p_l[i]:
            count +=1

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,*P,=map(int,open(0).read().split())
A=[a-b for a,b in zip(range(1,N+1),P)]
print('YNEOS'[len(set(A))!=1 and len(set(A))!=3::2])

Submission status: Wrong Answer

Solution code:
N,*P,=map(int,open(0).read().split())
A=[a-b for a,b in zip(range(1,N+1),P)]
print('YNeos'[len(set(A))!=1 and len(set(A))!=3::2])

Submission status: Wrong Answer

Solution code:
n = int(input())
p = list(map(int, input().split()))
q = sorted(p)

count = 0
f = True
for i in range(n):
    if p[i]!=q[i]:
        count+=1
    if count > 3:
        print('NO')
        f = False
        break
if f:
    print('YES')

Submission status: Wrong Answer

Solution code:
N = int(input())

P = list(input().split())
Q= sorted(P)

count=0
for i in range(N):
  if P[i]!=Q[i]:
    count +=1
#print(P)
#print(Q)

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

Submission status: Wrong Answer

Solution code:
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')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
p = list(map(int, input().split()))
nl = list(range(n, 0, -1))
if nl == p:
    print("YES")
    exit()
res = []
for i in range(n):
    if p[i] != nl[i]: 
        res.append(i)
if len(res) == 2:
    if nl[res[0]] == res[1]+1 and nl[res[1]] == res[0]+1:
        print("YES")
        exit()
print("NO")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
cnt = 0

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

if cnt <= 2:
    print("YES")
elif cnt >= 3:
    print("NO")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
p=list(map(int,input().split()))
px=sorted(p)
con=0
for i in range(n):
  if p[i]!=px[i]:
    con+=1
    
if con==2 or con==0:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
p = list(map(int,input().split()))
flag = True
for i in range(1,n):
     if p[i] < p[i-1]:
          flag = False
          continue
if flag:
     print('YES')
     sys.exit()

for i in range(n-1):
     for j in range(i,n):
          pp = p
          pp[i] = p[j]
          pp[j] = p[i]
          for k in range(1, n):
               if p[k] < p[k - 1]:
                    flag = False
                    continue
          if flag:
               print('YES')
               sys.exit()
print('NO')

Submission status: Wrong Answer

Solution code:
n = int(input())
l = [int(i) for i in input().split()]
mis = 0
for i in range(n):
    if l[i] != i:
        mis += 1
print('YES' if mis<3 else 'NO')

Submission status: Wrong Answer

Solution code:
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')

Submission status: Wrong Answer

Solution code:
n = int(input())
num = list(map(int, input().split()))
num_sort = sorted(num)
flug = 0
for i in range(n):
  if num[i] == num_sort[i]:
    continue
  else:
    flug += 1
    if flug <= 2:
      continue
    else:
      print("No")
      exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
import os, sys, re, math

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

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

Submission status: Wrong Answer

Solution code:
import os, sys, re, math

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

sorted_P = sorted(P)

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

Submission status: Wrong Answer

Solution code:
N = int(input())
P = [ int(s) for s in input().split() ]
P_S = sorted(P)

if sum(map(lambda x: x[0] != x[1], zip(P,P_S))) <= 2:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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")

Submission status: Wrong Answer

Solution code:
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")

Submission status: Wrong Answer

Solution code:
#B
import sys
n = int(input())
p = list(map(int, input().split()))
count=0
for i in range(n):
    if p[i] != i+1:
        if count == 2:
            print('No')
            sys.exit()
        else:
            count += 1
print('Yes')

Submission status: Wrong Answer

Solution code:
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")

Submission status: Wrong Answer

Solution code:
#整数の入力
A = int(input())
#文字列の入力
S = input()
#listを一文字ずつのlistに
S_list = list(S)
for i in range(A-1):
  S_list.remove(" ")

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

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

Submission status: Wrong Answer

Solution code:
#整数の入力
A = int(input())
#文字列の入力
S = input()
#listを一文字ずつのlistに
S_list = list(S)
for i in range(A-1):
  S_list.remove(" ")

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


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

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

Submission status: Wrong Answer

Solution code:
#整数の入力
A = int(input())
#文字列の入力
S = input()
#listを一文字ずつのlistに
S_list = list(S)
for i in range(A-1):
    S_list.remove(" ")

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


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

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

Submission status: Wrong Answer

Solution code:
#整数の入力
A = int(input())
#文字列の入力
S = input()
#listを一文字ずつのlistに
S_list = list(S)
for i in range(A-1):
  S_list.remove(" ")

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

print(A_list) 
print(S_list)

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

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

Submission status: Wrong Answer

Solution code:
#整数の入力
A = int(input())
#文字列の入力
S = input()
#listを一文字ずつのlistに
S_list = list(S)
for i in range(A-1):
    S_list.remove(" ")

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

print(A_list) 
print(S_list)

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

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

Submission status: Wrong Answer

Solution code:
#整数の入力
A = int(input())
#文字列の入力
S = input()
#listを一文字ずつのlistに
S_list = list(S)
S_list.remove(" ")

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

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

Submission status: Wrong Answer

Solution code:
#整数の入力
A = int(input())
#文字列の入力
S = input()
#listを一文字ずつのlistに
S_list = list(S)
S_list.remove(" ")

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

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

Submission status: Wrong Answer

Solution code:
N=int(input())
p = [i for i in map(int,input().split())]
flag = 1

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

Submission status: Wrong Answer

Solution code:
n = int(input())
plist = list(map(int,input().split()))
ans_count = 0
for i in range(n):
  if plist[i] != i+1:
    ans_count += 1
if ans_count <= 2:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
a = int(input())
l = list(map(int,input().split()))
l_1 = sorted(l)
d = "N0"
for m in range(a):
  for n in range(a):
    x =l[m]
    l[m] = l[n]
    l[n] = x
    if l == l_1 :
      d ="YES"
      break
    else:
      x = l[n]
      l[n]=l[m]
      l[m]=x
print(d)

Submission status: Wrong Answer

Solution code:
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")

Submission status: Wrong Answer

Solution code:
n=int(input())
p=[int(i) for i in input().split()]
count=0
for i in range(n-1):
    for j in range(i+1,n):
        if p[i]>p[j]:
            count+=1
if count>=3:
    print("NO")
else:
    print("YES")

Submission status: Wrong Answer

Solution code:
n=int(input())
p=[int(i) for i in input().split()]
count=0
for i in range(n-1):
    for j in range(1,n):
        if p[i]>p[j]:
            count+=1
if count>=3:
    print("NO")
else:
    print("YES")

Submission status: Wrong Answer

Solution code:
n=int(input())
p=[int(i) for i in input().split()]
count=0
for i in range(n-1):
    for j in range(1,n):
        print(p[i],p[i+1])
        if p[i]>p[j]:
            count+=1
if count>=3:
    print("NO")
else:
    print("YES")

Submission status: Wrong Answer

Solution code:
import copy

def swap(array, i,j,tar1,tar2):
  tmp = tar1 
  array[i] = tar2
  array[j] = tmp
#  print(array)
  return array

def orderd(array):
  orderd_array = sorted(array)
#  print(array,orderd_array)
  for i in range(len(array)):
    if not orderd_array[i]==array[i]:
      return False
  return True

N = int(input())
P = list(map(int,input().split()))
# print(P)
ans = "No"
flg = False
for i in range(N):
  for j in range(i,N):
    Pi = copy.copy(P)
    Pi = swap(Pi,i,j,Pi[i],Pi[j])
    if orderd(Pi):
      ans = "YES"
      flg=True
      break
  if flg:
    break
#print(P)
print(ans)

Submission status: Wrong Answer

Solution code:
a = int(input())
l = list(map(int, input().split()))
x = sorted(l)
b =0
for i in range(a):
  if x[i] !=l[i]:
    b +=1
if b ==2:
  print('YES')
else:
  print('NO')

Submission status: Wrong Answer

Solution code:
N = int(input())
P = [int(p) for p in input().split()]

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

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

Submission status: Wrong Answer

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

P1 = sorted(P)

fcount = 0
for count in range(N):
    if P[count] != P1[count]:
        fcount += 1

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

Submission status: Wrong Answer

Solution code:
N = int(input())
P = input().split()
flag = "OK"
count = 0
for i in range(N):
  if i+1 != int(P[i]) :
    count = count + 1
if count >= 2:
  print("NO")
else:
  print("YES")

Submission status: Wrong Answer

Solution code:
N = int(input())
p = list(map(int,input().split()))
p_sort = sorted(p)
pi = 0
pj = 0
if p == p_sort:
  print("Yes")
  exit()
for i in range(N//2):
  pi = p[i]
  for j in range(i+1,N):
    pj = p[j]
    p[i] = pj
    p[j] = pi
    if p == p_sort:
      print("Yes")
      exit()
    else:
      p[j] = pj
      p[i] = pi
print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())
p = list(map(int,input().split()))
p_sort = sorted(p)
pi = 0
pj = 0
if p == p_sort:
  print("Yes")
  exit()
for i in range(N//2):
  pi = p[i]
  for j in range(i+1,N):
    pj = p[j]
    p[i] = pj
    p[j] = pi
    if p == p_sort:
      print("Yes")
      exit()
    else:
      p[j] = pj
      p[i] = pi
print("No")
print(p)

Submission status: Wrong Answer

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

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

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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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')

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
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')

Submission status: Wrong Answer

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

if miss > 3:
    print('NO')
else:
    print('YES')

Submission status: Wrong Answer

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

if miss > 3:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
N=int(input())
l=list(range(1,N+1))
a=list(map(int, input().split()))
count=0
for i in range(0, len(l)):
  if l[i]==a[i]:
    count=count+1
if count >= N-2:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
N=int(input())
l=list(range(1,N+1))
print(l)
a=list(map(int, input().split()))
print(a)
count=0
for i in range(0, len(l)):
  if l[i]==a[i]:
    count=count+1
print(count)
if count >= N-2:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

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


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

Submission status: Wrong Answer

Solution code:
n=int(input())
p=list(map(int,input().split()))
# print(p)

p_ans = sorted(p)
# print(p_ans)

cnt=0
for i in range(len(p)):
    if p[i] == p_ans[i]:
        pass
    else:
        cnt+=1
if cnt<3:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
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')

Submission status: Wrong Answer

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

flag = True
for i in range(n):
    for j in range(i+1,n):
        tmp = p[i]
        p[i] = p[j]
        p[j] = tmp
        if p == sorted(p):
            print('Yes')
            flag = False
            tmp = p[i]
            p[i] = p[j]
            p[j] = tmp
            break
        tmp = p[i]
        p[i] = p[j]
        p[j] = tmp

if p == sorted(p):
    print('Yes')
    flag = False

if flag:
    print('No')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
P=list(map(int,input().split()))
count=0
if P[0]!=1:
    count=count+1
elif P[N-1]!=N:
    count=count+1
for i in range(N-1):
    if P[i]+1!=P[i+1]:
        count=count+1
if N>4:
    if count<5:
       print('YES')
    else:
       print('NO')
elif N==3:
    if P==(2,3,1) or P==(3,1,2):
        print('NO')
    else:
        print('YES')

Submission status: Wrong Answer

Solution code:
N=int(input())
P=list(map(int,input().split()))
count=0
if P[0]!=1:
    count=count+1
elif P[N-1]!=N:
    count=count+1
for i in range(N-1):
    if P[i]+1!=P[i+1]:
        count=count+1
if count<5:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

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

if c <= 2 or d == 1:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

if c >= n-3:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def readints():
    return list(map(int, input().split()))


n = int(input())
p = readints()
# print(sorted(p))
if p == (sorted(p)):
    print("YES")
    exit()
for i in range(n//2):
    if p[i] > p[n-i-1]:
        p[i], p[n-i-1] = p[n-i-1], p[i]
print("YES" if p == (sorted(p)) else "NO")

Submission status: Wrong Answer

Solution code:
def readints():
    return list(map(int, input().split()))


n = int(input())
p = readints()


# for i in range(n):
# print(p[i])
# print(p[n-1-i])
for i in range(n//2):
    if p[i] > p[n-1-i]:
        p[i], p[n-1-i] = p[n-1-i], p[i]
        # print("YES")
#print(p)
sum = 0
for i in range(n-1):
    if p[i] <= p[i+1]:
        sum += 1
if sum == (n-1):
    print("YES")
else:
    print("NO")
# if p == q:
# print("YES")

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[0]
a+=list(map(int,input().split()))
a.append(n+1)
c=0
idx = list()
for i in range(n+1):
  if a[i]>a[i+1]:
    idx.append(i)
    c+=1
print("YES" if c<2 or c==2 and a[idx[0]-1]<a[idx[1]+1]<a[idx[0]+1] and a[idx[1]]<a[idx[0]]<a[idx[1]+2] else "NO")

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[0]
a+=list(map(int,input().split()))
a.append(n)
c=0
idx = list()
for i in range(n+1):
  if a[i]>a[i+1]:
    idx.append(i)
    c+=1
print("YES" if c<2 or c==2 and a[idx[0]-1]<a[idx[1]+1]<a[idx[0]+1] and a[idx[1]]<a[idx[0]]<a[idx[1]+2] else "NO")

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[0]
a+=list(map(int,input().split()))
a.append(n)
c=0
idx = list()
for i in range(n-1):
  if a[i]>a[i+1]:
    idx.append(i)
    c+=1
print("YES" if c<2 or c==2 and a[idx[0]-1]<a[idx[1]+1]<a[idx[0]+1] and a[idx[1]]<a[idx[0]]<a[idx[1]+2] else "NO")

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
c=0
for i in range(n-1):
  if a[i]>a[i+1]:
    c+=1
print("YES" if c<2 else "NO")

Submission status: Wrong Answer

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