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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import copy 

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

true_num = copy.deepcopy(num)
true_num = sorted(true_num)

swap_org=[]
swap_true=[]

count=0
for x,y in zip(num,true_num):
    if x != y:
        count += 1
        swap_org.append(x)
        swap_true.append(y)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
p = input().split()
count = 0
for i, j in zip(p, sorted(p)):
    if i != j:
        count += 1
ans = 'YES' if count <= 2 else 'NO'
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
p = input().split()
tmp = sorted(p)
count = [i for i in range(n) if p[i] != tmp[i]]
ans = 'YES' if len(count) == 2 or len(count) == 0 else 'NO'
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
p = input().split()
tmp = sorted(p)
count = [i for i in range(n) if p[i] != tmp[i]]
ans = 'YES' if len(count) <= 2 else 'NO'
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
input()
P = list(map(int, input().split()))

Ps = list(sorted(P))

c = 0
for i in range(len(P)):
    if P[i] != Ps[i]:
        c += 1

print('Yes' if c <= 2 else 'No')

Submission status: Wrong Answer

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

i = 0
cnt = 0
for i in range(0,N):
  if P[i] == P_sorted[i]:
    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()))
P_sorted = sorted(P)

i = 0
cnt = 0
for p in P:
  if p == P_sorted[i]:
    cnt += 1
  i += 1

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

Submission status: Wrong Answer

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

i = 0
cnt = 0
for p in P:
  if p == P_sorted[i]:
    cnt += 1
  i += 1

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

Submission status: Wrong Answer

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

print(P)
print(P_r)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

sp = sorted(P)
cnt = 0
for i in range(N):
  if P[i] != sp[i]:
    cnt += 1
if cnt // 2 <= 1:
  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(1, n+1):
  if p[i-1] != i:
    count += 1
    
if count == 0 or count == 2:
  print("YES")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
p = list(input().split())
cnt = 0

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

Submission status: Wrong Answer

Solution code:
n = int(input())
p = list(input().split())
cnt = 0

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-S
N = int(input())
p = [int(i) for i in input().split()]

q = sorted(p)
X = 0
for i in range (N):
    if p[i] != q[i]:
        X += 1
if X <= 2:    
    print("YES")
if X > 3:
    print("NO")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-S
N = int(input())
p = [int(i) for i in input().split()]

q = sorted(p)
X = 0
for i in range (N):
    if p[i] != q[i]:
        X += 1
if X <= 2:    #X <= 2 のかわりに　X == 0 or X == 2 でもできる？？
    print("YES")
if X > 3:
    print("NO")

#X=!になることはあるの？

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys

n = int(input())
p = np.array(list(map(int,input().split())))
p_sort = np.sort(p)

if (p==p_sort).all():
  print("YES")
  sys.exit()

argmax = np.argmax(p)
argmin = np.argmin(p)
p[argmax],p[argmin] = p[argmin],p[argmax]

if (p==p_sort).all():
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

Solution code:
import sys

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

for i in range(n - 1):
    if p[i] > p[i + 1]:
        break
    print("YES")
    sys.exit()

for i in range(n):
    for j in range(i + 1, n):
        q = list(p)
        tmp = q[i]
        q[i] = q[j]
        q[j] = tmp
        for k in range(n - 1):
            if q[k] > q[k + 1]:
                break
            print("YES")
            sys.exit()

print("NO")

Submission status: Wrong Answer

Solution code:
import sys

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

for i in range(n):
    if p[i] > p[i + 1]:
        break
    print("YES")
    sys.exit()

for i in range(n):
    for j in range(i + 1, n):
        q = list(p)
        tmp = q[i]
        q[i] = q[j]
        q[j] = tmp
        for k in range(n - 1):
            if q[k] > q[k + 1]:
                break
            print("YES")
            sys.exit()

print("NO")

Submission status: Wrong Answer

Solution code:
import sys

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

for i in range(n):
    for j in range(i + 1, n):
        q = list(p)
        tmp = q[i]
        q[i] = q[j]
        q[j] = tmp
        for k in range(n - 1):
            if q[k] > q[k + 1]:
                break
            if k == n - 2:
                print("YES")
                sys.exit()

print("NO")

Submission status: Wrong Answer

Solution code:
n=int(input())
p=list(map(int,input().split()))
q=[]
for i in range(n-1):
  q.append(p[i+1]-p[i])
cnt=q.count(1)
if cnt>=3:
  print('NO')
else:
  print('YES')

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
num = int(input())
order = []
for i in range(1,num+1):
    order.append(i)
#print(order)

q_num = list(map(int,input().split()))
#print(q_num)
cnt = 0
for j in range(num):
    if order[j]!=q_num[j]:
        cnt = cnt+1
    else:
        pass
if cnt <=2:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
num = int(input())
order = []
for i in range(1,num+1):
    order.append(i)
#print(order)

q_num = list(map(int,input().split()))
#print(q_num)
cnt = 0
for j in range(num):
    if order[j]==q_num[j]:
        cnt = cnt+1
    else:
        pass
if cnt <=2:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
p = [int(x) for x in input().split()]

flg = False
ans = "YES"

for i in range((n + 1) // 2):
    if p[i] == i + 1 and p[n - i - 1] == n - i:
        pass
    elif p[i] == n - i and p[n - i - 1] == i + 1 and not flg:
        flg = True
    else:
        ans = "NO"
        break
        
print(ans)

Submission status: Wrong Answer

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

ans=0

for i in range(1,n):
    if p[i] != l[i]:
        ans+=1
if ans >2:
    print('NO')
else:
    print('YES')

Submission status: Wrong Answer

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
li_re = sorted(li)

point = 0

while point < 2:
    for i in range(len(li)):
        if li_re[i] != li[i]:
            point += 1
    print("YES")
    exit()
print("NO")

Submission status: Wrong Answer

Solution code:
a=int(input())
b=input().split(" ")
sequence=[]
for i in range(0,a):
    sequence.append(int(b[i]))
count=0
for q in range(0,a-1):
    if sequence[q]-sequence[q+1]>0:
        count+=1

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

Submission status: Wrong Answer

Solution code:
a=int(input())
b=input().split(" ")
sequence=[]
for i in range(0,a):
    sequence.append(int(b[i]))
error=[]
for q in range(0,a-1):
    if sequence[q]-sequence[q+1]>0:
        error.append(q)
        error.append(q+1)

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

Submission status: Wrong Answer

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

ascending = True
for i in range(n-1):
    if P[i] > P[i]:
        ascending = False
if ascending:
    print('YES')
    exit()

for i in range(n):
    for j in range(i):
        P_copy = P.copy()
        P_copy[j], P_copy[i] = P_copy[i], P_copy[j]
        ascending = True
        for k in range(n-1):
            if P_copy[k] > P_copy[k+1]:
                ascending = False
        if ascending:
            print('YES')
            exit()
print('NO')

Submission status: Wrong Answer

Solution code:
N=int(input())
List=[int(i) for i in input().split()]
count=0
for i in range(N):
  if i != List[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()))
count = 0
for i in range(n):
    if p[i] != i + 1:
        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()))

k = 0

for i in range(0, N-1 ):
  if (p[i] > p[ i + 1 ]):
    k += 1


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

Submission status: Wrong Answer

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

def swap_judge(p,p_sorted,i,j):
  tmp = p[i]
  p[i] = p[j]
  p[j] = tmp
  if p==p_sorted:
    return True
  else:
    return False

ans="NO"
p_sorted = sorted(p)
for i in range(N-1):
  for j in range(i+1,N):
    p_ = p.copy()
    if swap_judge(p_,p_sorted,i,j):
      ans="YES"
      break;
  else:
    continue
  break;
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

data = list(map(int,sys.stdin.readline().split()))
data.pop(0)

datacp = sorted(data)

a = list(map(lambda x: x[0]-x[1] ,zip(data,datacp)))

a = [i for i in a if i != 0 ]

if len(a) <= 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)
flag=0

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

if flag==2:
    print('YES')
elif flag==0:
    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)
flag=0

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

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

Submission status: Wrong Answer

Solution code:
n,*x=map(int,open(0).read().split())
soreted_x=sorted(x)
cnt=0
for a,b in zip(x,soreted_x):
  if a != b:
    cnt+=1
print('YES' if cnt==2 else 'NO')

Submission status: Wrong Answer

Solution code:
n,*x=map(int,open(0).read().split())
soreted_x=sorted(x)
cnt=0
for a,b in zip(x,soreted_x):
  if a != b:
    cnt+=1
print('Yes' if cnt==2 else 'No')

Submission status: Wrong Answer

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

List3=sorted(List)

#maxとminを入れ替える
ma= max(List)
mi = min(List)

maIndex=List.index(ma)
miIndex=List.index(mi)
if (List3 != List):
    List[maIndex] = mi
    List[miIndex] = ma
#sortする
List2=sorted(List)
if (List3 == List):
    print("YES")
else:

#入れ替えと比較する
    if (List != List2):
        print("NO")
    else:
        print("YES")
#差分ありならNo.
#差分無しならYes.

Submission status: Wrong Answer

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

#maxとminを入れ替える
ma= max(List)
mi = min(List)

maIndex=List.index(ma)
miIndex=List.index(mi)
List[maIndex] = mi
List[miIndex] = ma
#sortする
List2=sorted(List)

#入れ替えと比較する
if (List != List2):
    print("NO")
else:
    print("YES")
#差分ありならNo.
#差分無しならYes.

Submission status: Wrong Answer

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

#maxとminを入れ替える
ma= max(List)
mi = min(List)

maIndex=List.index(ma)
miIndex=List.index(mi)
List[maIndex] = mi
List[miIndex] = ma
#sortする
List2=sorted(List)

#入れ替えと比較する
if (List != List2):
    print("No")
else:
    print("Yes")
#差分ありならNo.
#差分無しならYes.

Submission status: Wrong Answer

Solution code:
import sys
from operator import itemgetter
import math
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
ppp = na()
ln = len(ppp)
ct = 0
for i in range(ln):
    if ppp[i] < i+1:
        ct += 1
if ct == 0 or ct == 2:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
import sys
from operator import itemgetter
import math
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
ppp = na()
ln = len(ppp)
l = 0
r = 0
for i in range(ln):
    if ppp[i] < i+1:
        l += 1
    elif ppp[i] > i+1:
        r += 1
if abs(r - l) <= 1:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
import sys
from operator import itemgetter
import math
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
ppp = na()
ln = len(ppp)
l = 0
r = 0
for i in range(ln):
    if ppp[i] < i+1:
        l += 1
    elif ppp[i] > i+1:
        r += 1
if r == l:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
N = input()
lst1 = list(map(int, input().split()))
lst2 = sorted(lst1)

n = 0
for x, y in zip(lst1, lst2):
    if x != y:
        n += 1
        if n > 2:
            break

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

Submission status: Wrong Answer

Solution code:
N = input()
lst1 = map(int, input().split())
lst2 = sorted(lst1)

n = 0
for x, y in zip(lst1, lst2):
    if x != y:
        n += 1
        if n > 2:
            break

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
value = list(map(int, input().split()))
count = 0
ans = "Yes"
for i in range(N):
    if value[i] != i + 1:
        count += 1
if count > 2:
    ans = "No"
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
value = list(map(int, input().split()))
count = 0
for i in range(len(value)-1):
    ans = "Yes"
    if count <= 3:
        if value[i] + 1 == value[i+1]:
            continue
        else:
            count += 1
    else:
        break
if count >= 4:
    ans = "No"
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input().split()
print(s)
b =[str(i+1) for i in range(len(s))]
print(b)
count=0
for i in range(len(s)):
  if s[i]!=b[i]:
    count+=1
if count==0: print("YES")
elif count==2: print("YES")
else: print("NO")

Submission status: Wrong Answer

Solution code:
n=int(input())
p=list(map(int,input().split()))
s=[1+i for i in range(n)]
S=[]
for i in range(n):
  for j in range(i+1,n):
    a=s
    a[i]=s[j]
    a[j]=s[i]
    S.append(s)
if p in S:
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

Solution code:
N = int(input())
suuretsu_str = input().split()
suuretsu = [int(i) for i in suuretsu_str]
suuretsu_order = [i for i in range(1,N+1)]
count = 0
for i in range(N):
    if suuretsu[i] != suuretsu_order[i]:
        count += 1
if count == 2 or 0:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
N = int(input())
suuretsu_str = input().split()
suuretsu = [int(i) for i in suuretsu_str]
suuretsu_order = [i for i in range(1,N+1)]
count = 0
for i in range(N):
    if suuretsu[i] != suuretsu_order[i]:
        count += 1
if count == 2:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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

def jud(p,s,n,cnt):
    # print(p,s)
    for i in range(n):
        if s[i]!=p[i]:
            cnt+=1
        if cnt>2:
            return "No"
    return "Yes"

print(jud(p,s,n,cnt))

Submission status: Wrong Answer

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

s=sorted(p)
cnt=0

def jud(p,s,n,cnt):
    print(p,s)
    for i in range(n):
        if s[i]!=p[i]:
            cnt+=1
        if cnt>2:
            return "No"
    return "Yes"

print(jud(p,s,n,cnt))

Submission status: Wrong Answer

Solution code:
import itertools

def getint(): return int(input())
def getints(): return list(map(int, input().split()))

a=getints()
b=list(sorted(a))
n=len(a)
cnt = 0
for i in range(n):
    if a[i] != b[i]:
        cnt += 1

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from sys import stdin 

n = int(input())
p = [int(x) for x in stdin.readline().rstrip().split()]
c= 0
q = sorted(p)
print(q)
print(p)
for i in range(n):
	if p[i] != q[i]:
		c += 1

if c>2:
	print("NO")

else:
	print("YES")

Submission status: Wrong Answer

Solution code:
from sys import stdin 

n = int(input())
p = [int(x) for x in stdin.readline().rstrip().split()]
c= 0
q = sorted(p)
print(q)
print(p)
for i in range(n):
	if p[i] != q[i]:
		c += 1

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

else:
	print("NO")

Submission status: Wrong Answer

Solution code:
from sys import stdin 

n = int(input())
p = [int(x) for x in stdin.readline().rstrip().split()]
c= 0
q = sorted(p)
print(q)
print(p)
for i in range(n):
	if p[i] != q[i]:
		c += 1

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

else:
	print("NO")

Submission status: Wrong Answer

Solution code:
from sys import stdin 

n = int(input())
p = [int(x) for x in stdin.readline().rstrip().split()]
c= 0
q = sorted(p)
for i in range(n):
	if p[i] != q[i]:
		c += 1

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

else:
	print("No")

Submission status: Wrong Answer

Solution code:
from sys import stdin 

n = int(input())
p = [int(x) for x in stdin.readline().rstrip().split()]
c= 0
q = sorted(p)
for i in range(n):
	if p[i] != q[i]:
		c += 1

if c<=2:
	print("Yes")

else:
	print("No")

Submission status: Wrong Answer

Solution code:
num = int(input())
num_list = input().split(' ')
f = True
num_list[0] = int(num_list[0])
for i in range(num):
    num_list[i] = int(num_list[i])

for i in range(num):
    if i + 1 == num:
        print('YES')
        break
    if num_list[i] <= num_list[i+1]:
        continue
    else:
        if f:
            min_idx = i+1
            for i2 in range(i+1,num):
                if num_list[min_idx] > num_list[i2]:
                    min_idx = i2
            #Change
            current_num = num_list[i]
            num_list[i] = num_list[min_idx]
            num_list[min_idx] = current_num
            f = False
        else:
            print('NO')
            break

Submission status: Wrong Answer

Solution code:
N = int(input())
p = list(map(int, input().split()))
q = p.copy()
print(q)
cnt = 0
for n in range(N):
    if p[n] != q[n]:
        cnt+=1

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

Submission status: Wrong Answer

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

for i in range(N-1):
  if abs(m[i+1] - m[i]) > 1:
    count += 1

if count == 2 or count == 4:
  print('YES')

else:
  print('NO')

Submission status: Wrong Answer

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

for i in range(N-1):
  if abs(m[i+1] - m[i]) > 1:
    count += 1

if count >= 3:
  print('NO')

else:
  print('YES')

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

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

P = []
n=0

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

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

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

Submission status: Wrong Answer

Solution code:

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

P = []
n=0

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

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

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

Submission status: Wrong Answer

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

@author: kohei
"""

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

P = []
n=0

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

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

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

Submission status: Wrong Answer

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

@author: kohei
"""

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

P = []
n=0

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

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

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

Submission status: Wrong Answer

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

for i in range(n):
    if p[i] != p2[i]:
        ans += 1
    else:
        continue

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

Submission status: Wrong Answer

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

for i in range(n):
    if p[i] != p2[i]:
        ans += 1
    else:
        continue

if ans == 2:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
N = int(input())
p = list(map(int,input().split(" ")))
counter = 0
for i in range(N):
    if p[i] != i+1 and counter <= 1:
        counter += 1
    elif p[i] != i+1 and counter > 1:
        break;
if counter < 2:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
N = int(input())
p = list(map(int,input().split(" ")))
counter = 0
for i in range(N-1):
    if p[i] != i+1 and counter <= 1:
        counter += 1
    elif p[i] != i+1 and counter > 1:
        break;
if counter < 2:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
N = int(input())
p = list(map(int, input().split()))
p_s = sorted(p)
m = 0
ans = "Yes"
for i in range(0, N):
    if p[i] != p_s[i]:
        m += 1
        if m > 2:
            ans = "No"
            break
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
p = list(map(int, input().split()))
p_s = sorted(p)
m = 0
ans = "Yes"
for i in range(0, len(p)):
    if p[i] != p_s[i]:
        m += 1
        if m > 2:
            ans = "No"
            break
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

c = 0
prev = li[0]
for i in range(1, n):
  if li[i] - prev != 1:
    c += 1
  prev = li[i]
  
if c == 0 or c == 2:
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

Solution code:
i = int(input())
l = list(map(int, input().split()))
s = sorted(l)
f = 0

if l == s:
    print('YES')
    exit()

for n in range(i-1):
    if l[n] == n+1:
        continue
    else:
        f = f + 1
        continue

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

Submission status: Wrong Answer

Solution code:
i = int(input())
l = list(map(int, input().split()))
s = sorted(l)
f = 0

if l == s:
    print('YES')
    exit()

for n in range(i-1):
    if l[n] == s[n]:
        continue
    else:
        f = f + 1
        continue

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

Submission status: Wrong Answer

Solution code:
"""
# 標準入力取得
## 文字列
     = sys.stdin.readline().rstrip()
     = list(sys.stdin.readline().rstrip())

## 数値
     = int(sys.stdin.readline())
     = map(int, sys.stdin.readline().split())
     = list(map(int, sys.stdin.readline().split()))
     = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

import copy

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

mod = 1000000007
# sortedと比較
# 
if __name__ == "__main__":
     _ = int(sys.stdin.readline())
     L = list(map(int, sys.stdin.readline().split()))
     Ls = sorted(L)
     
     if L == Ls:
          print("YES")
          exit()

     mii = 0
     mai = 0

     for i in range(len(L)):
          if L[i] < L[0]:
               mii = i

     tmp = L[mai]
     L[mai] = L[mii]
     L[mii] = tmp

     if L == Ls:
          print("YES")
     else:
          print("NO")

Submission status: Wrong Answer

Solution code:
"""
# 標準入力取得
## 文字列
     = sys.stdin.readline().rstrip()
     = list(sys.stdin.readline().rstrip())

## 数値
     = int(sys.stdin.readline())
     = map(int, sys.stdin.readline().split())
     = list(map(int, sys.stdin.readline().split()))
     = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

import copy

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

mod = 1000000007
# sortedと比較
# 
if __name__ == "__main__":
     _ = int(sys.stdin.readline())
     L = list(map(int, sys.stdin.readline().split()))
     Ls = sorted(L)
     
     if L == Ls:
          print("YES")
          exit()
     
     mai = L.index(max(L))
     mii = L.index(min(L))

     tmp = L[mai]
     L[mai] = L[mii]
     L[mii] = tmp

     if L == Ls:
          print("YES")
     else:
          print("NO")

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

out = 0
for i in range(len(l)-1):
  out += 1 if l[i] > l[i+1] else 0

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

Submission status: Wrong Answer

Solution code:
N = int(input())
p = [int(i) for i in input().split()]
count = 0 
res = "yes"
p_sorted = sorted(p)
for i in range(N):
  if p_sorted[i] != p[i]:
    count += 1
    if count > 2:
      res = "no"
      break
print(res)