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:

def myAnswer(N:int,P:list) -> str:
   counter = 0
   for i in range(1,N):
      if(P[i] - P[i - 1] != 1):
         counter += 1
   # print(counter)
   return "YES" if(counter < 3) else "NO"

def modelAnswer():
   return
def main():
   N = int(input())
   P = list(map(int,input().split()))
   print(myAnswer(N,P))
if __name__ == '__main__':
   main()

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())
A = [int(N) for N in input().split()]
swp = 0

if A == sorted(A):
  print("YES")
  sys.exit()

for i in range (0,N-1):
 if A[i]>A[i+1]:
   swp = A[i]
   A[i] = A[swp-1]
   A[swp-1] = swp
   if A == sorted(A):
     print("YES")
     sys.exit()
print ("NO")

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())
A = [int(N) for N in input().split()]
swp = 0

if A == sorted(A):
  print("Yes")
  sys.exit()

for i in range (0,N-1):
 if A[i]>A[i+1]:
   swp = A[i]
   A[i] = A[swp-1]
   A[swp-1] = swp
   if A == sorted(A):
     print("Yes")
     sys.exit()
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
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()))
f=0
for i in range(n):
  if p[i]!=i+1:
    f+=1
print("Yes" if f<=2 else "No")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri May 15 00:38:52 2020

@author: Kanaru Sato
"""

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

yesflag = 1
a = [p[i] for i in range(n)]
for k in range(n-1):
    if a[k] > a[k+1]:
        yesflag = 0
        break

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

if yesflag == 1:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############
N = inputI()
P = inputIL()

memo = []
for i in range(1,N+1):
  if P[i-1] != i:
    memo.append((P[i-1],i))
    
if len(memo) == 0:
  print("Yes")
  exit()
if len(memo) == 2:
  if memo[0][0] == memo[1][1]:
    print("Yes")
    exit()
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
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()))
P = sorted(p)
print(p)
print(P)
length = len(p)
count = 0
for i in range(0, length):
  if p[i] != P[i]:
    count += 1
print(count)
if count <= 2:
  print('YES')
else:
  print('NO')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

l=list(range(1,n+1))
k=0
for i in range(n):
    if p[i]==l[i]:
        k+=1
if k==0 or k==2:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
N = int(input())
P = input().split()
PP = [str(i) for i in range(1,N+1)]
diff = 0
for i in range(N):
    if P[i] != PP[i]:
        diff += 1
if diff <= 2:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
n = int(input())

s = list(map(int,input().split()))

k = s.copy()

k.sort(reverse = True)

t = 0

for i in range(n):
    if s[i] != k[i]:
        t += 1
        
if t<3:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
n = int(input())

s = list(map(int,input().split()))

k = s.copy()

k.sort(reverse = True)

t = 0

for i in range(n):
    if s[i] != k[i]:
        t += 1
        
if t<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 i+1 != P[i]:
    cnt += 1
print('NO' if cnt>2 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 i+1 == P[i]:
    continue
  elif i+1 != P[i] and P[P[i]-1] == i+1:
    cnt = 1
  elif cnt == 0:
    print('NO')
    cnt = 2
    break
if cnt!=2:
  print('YES')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
a = int(input())
b=list(map(int,input().split()))
c=b
c.sort()
d=[]
print(c)
for i in range(a):
    for j in range(a):
        b[i],b[j]=b[j],b[i]
        print(b)
        if b==c:
            d.append(b)
        else:
            continue
if len(d)!=0:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
a = int(input())
b=list(map(int,input().split()))
c=b
c.sort()
d=[]
for i in range(a):
    for j in range(a):
        b[i],b[j]=b[j],b[i]
        if b==c:
            d.append(b)
        else:
            continue
if len(d)!=0:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
a = int(input())
b=list(map(int,input().split()))
c=b
c.sort()
d=[]
print(c)
for i in range(a):
    for j in range(a):
        b[i],b[j]=b[j],b[i]
        print(b)
        if b==c:
            d.append(b)
        else:
            continue
if len(d)!=0:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

print('YES' if sum(map(lambda x: x[0] == x[1], zip(p, sorted(p)))) >= N - 2 else 'N0')

Submission status: Wrong Answer

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

print('Yes' if sum(map(lambda x: x[0] == x[1], zip(p, sorted(p)))) >= N - 2 else 'No')

Submission status: Wrong Answer

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

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

if check:
    print("YES")

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

pp = np.array(sorted(p))-p
sum_=0
for i in pp:
  if i!=0: sum_+=1
if sum_>2: print('No')
else: print('Yes')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

    
#print(p)
#print(s)
if cnt < 2:
        print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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

    
#print(p)
#print(s)
if cnt < 2:
        print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
n = int(input())
p = list(map(int,input().split()))
s = sorted(p)
cnt = 0
for i in range(n//2):
    if p[i] < p[n-1-i]:
        #print(p[i],p[n-1-i])
        pass
    else:
        a = p[i]
        b = p[n-1-i]
        p[i] = b
        p[n-1-i] = a
        cnt += 1
    
#print(p)
#print(s)
if p == s:
    if cnt < 2:
        print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
n = int(input())
p = list(map(int,input().split()))
s = sorted(p)
for i in range(n//2):
    if p[i] < p[n-1-i]:
        #print(p[i],p[n-1-i])
        pass
    else:
        a = p[i]
        b = p[n-1-i]
        p[i] = b
        p[n-1-i] = a
    
#print(p)
#print(s)
if p == s:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
p = [map(int, input().split())]
count = 0
if sorted(p) == p:
    print("YES")
else:
    s = sorted(p)
    for i in s:
        if s.index(i) != p.index(i):
            count += 1
            if count > 2:
                print("NO")
                break
    print("YES")

Submission status: Wrong Answer

Solution code:
n=int(input())
listp=list(map(int,input().split()))
for i in range(1,n):
  for j in range(2,n+1):
    a=listp[i-1]
    b=listp[j-1]
    listp[i-1]=b
    listp[j-1]=a
    for y in range(n):
      if listp[y]==y+1:
        print('Yes')
        exit()
      listp[i-1]=a
      listp[j-1]=b
for x in range(n):
  if listp[x]==x+1:
    print('Yes')
    exit()
print('No')

Submission status: Wrong Answer

Solution code:
n=int(input())
listp=list(map(int,input().split()))
for i in range(1,n):
  for j in range(2,n+1):
    a=listp[i-1]
    b=listp[j-1]
    listp[i-1]=b
    listp[j-1]=a
    for y in range(n):
      if listp[y]!=y+1:
        print('No')
        exit()
for x in range(n):
  if listp[x]!=x+1:
    print('No')
    exit()
print('Yes')

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(N-1):
  if P[i+1] >= P[i]:
    cnt += 1
    
if cnt+1 >= N-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-1):
  if P[i+1] >= P[i]:
    cnt += 1
    
if cnt >= N-3:
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

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

if cnt == 0 or cnt == 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-1):
  if P[i+1] > P[i]:
    cnt += 1
    
if cnt >= N-3:
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

Solution code:
N = int(input())
P = list(input(). split())
Q = sorted(P)
cnt = 0

for i in range(len(P)):
  if Q[i] == P[i]:
    cnt += 1

if len(P) - cnt == 2 or cnt == len(P):
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
p=list(map(int,input().split()))
def check(l):
  
  flg=True
  for i in range(n-1):
    if l[i]>l[i+1]:
      flg=False
  return flg

if check(p):
  print('YES')
else:
  f=False
  for i in range(n-1):
    for j in range(i+1,n):
      a=p.copy()
      a[i],a[j]=a[j],a[i]
      
      if check(a):
        print('YES')
        f=True
        break
  if not f:
    
    print('N0')

Submission status: Wrong Answer

Solution code:
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
# map(int, input().split())
# int(input())
# input().split()
# mojiretu = ','.join(str_list)
# sorted(input())

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 <= 2 else print('No')

Submission status: Wrong Answer

Solution code:
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
# map(int, input().split())
# int(input())
# input().split()
# mojiretu = ','.join(str_list)
# sorted(input())

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
p = list(map(int, input().split()))
count = 0
flag = True
for i in range(n):
    if p[i] != i+1:
        index = n-i-1
        if p[index] == n-index:
            count += 1
        else:
            flag = False
            break
if flag:
    if count == 2:
        print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
n = int(input())
p = list(map(int, input().split()))
count = 0
flag = True
for i in range(n):
    if p[i] != i+1:
        index = n-i-1
        if p[index] == n-index:
            count += 1
        else:
            flag = False
            break

if flag:
    if count <= 1:
        print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
n = int(input())
p = list(map(int, input().split()))
count = 0
flag = True
for i in range(n):
    if p[i] != i+1:
        index = n-i-1
        if p[index] == n-i:
            count += 1
        else:
            flag = False
            break

if flag:
    if count <= 1:
        print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
from collections import deque
N = int(input())
M = deque(map(int, input().split()))

j = []

prev = M.popleft()

for i in range(N-1):
    cor = M.popleft()
    if cor > prev:
        j.append(True)
    else:
        j.append(False)

    prev = cor

if all(j) == True:
    print('YES')
elif j[0] == j[-1] == False:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
from collections import deque
N = int(input())
M = deque(map(int, input().split()))

j = []

prev = M.popleft()

for i in range(N-1):
    cor = M.popleft()
    if cor > prev:
        j.append(True)
    else:
        j.append(False)

    prev = cor

if all(j) == True:
    print('Yes')
elif j[0] == j[-1] == False:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
n = int(input())
p = list(map(int, input().split()))

cnt = 0

for i, el in enumerate(p):
  if i == 0: continue
  if  el < p[i-1]: cnt += 1

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
n = int(input())
p = list(map(int, input().split()))

cnt = 0

for i, el in enumerate(p):
  if i == 0: continue
  if  el < p[i-1]: cnt += 1

print('YES' if cnt <= 1 else 'NO')

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
n = int(input())
p = list(map(int, input().split()))

cnt = 0

for i, el in enumerate(p):
  if i == 0: continue
  if el-1 is not p[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()))

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

T=sorted(S)

count=0
for i in range (len(S)):
  if S[i]!=T[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()))

count = 0
for i in range(n):
  if a[i] != i+1:
    rem = a[i]
    if rem == a[i]:
      count += 1
if count <= 2:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

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

res = 0
for i in range(n):
    if i + 1 == p[i]:
        res += 1
# print(n, res)
if res >= n - 2:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = list(map(int,input().split()))
x = 0
for i in range(len(n)):
    if n[i]!=i+1:
        x+=1
        
if(x==0 or x==2):print("yes")
else: print("no")

Submission status: Wrong Answer

Solution code:
n, *P = map(int, input().split())
s = sum(i == p for i, p in enumerate(P, 1))
print('YES' if s <= 2 else 'NO')

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
b=min(A)
index=A.index(b)

for i in range(0,N-1):
    if A[i] != min(A[i],A[N-1]):
        A[i],A[index] = A[index],A[i]
        break
        
if sorted(A)==A:
    print("YES")

else:
    print("NO")

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
b=min(A)
index=A.index(b)

for i in range(0,N):
    if A[i] != min(A[i],A[N-1]):
        A[i],A[index] = A[index],A[i]
        break
        
if sorted(A)==A:
    print("YES")

else:
    print("NO")

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
b=min(A)
index=A.index(b)

for i in range(N):
    if A[i] != b:
        
        A[i],A[index] = A[index],A[i]
        break
        
if sorted(A)==A:
    print("YES")

else:
    print("NO")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
sa = sorted(a)
if a==sa:
  print("Yes")
else:
  for ai,si,i in zip(a,sa,range(n)):
    if ai!=si:
      a[ai-1],a[i]=a[i],a[ai-1]
      break
  if a==sa:
    print("Yes")
  else:
    print("No")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
M=list(map(int,input().split()))
ans=0
list_= sorted(M)
for i in range(N):
  if M[i]==list_[i]:
    ans+=1
if ans>=N-2:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
N=int(input())
M=list(map(int,input().split()))
ans=0
list_= sorted(M)
for i in range(N):
  if M[i]==list_[i]:
    ans+=1
if ans>=N-2:
  print('Yes')
else:
  print('No')

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()
n_l_a = list(reversed(n_l))

if (n_l_a == 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_a == p):
                print('YES')
                sys.exit()
            else:
                p[i], p[j] = p[j], p[i]

print('NO')

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()
n_l_a = list(reversed(n_l))

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

print('NO')

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()
n_l_a = list(reversed(n_l))

if (n_l == p) or (n_l_a == 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) or (n_l_a == p):
                print('YES')
                sys.exit()
            else:
                p[i], p[j] = p[j], p[i]

print('NO')

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) or (reversed(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) or (reversed(n_l) == p):
                print('YES')
                sys.exit()
            else:
                p[i], p[j] = p[j], p[i]

print('NO')

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) or (reversed(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) or (n_l == p):
                print('YES')
                sys.exit()
            else:
                p[i], p[j] = p[j], p[i]

print('NO')