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

flag = True
t = []

for i in range(n):
    if i == 0:
        if p[i] > p[i+1]:
            t.append(i)
    elif i == (n-1):
        if p[i-1] > p[i]:
            t.append(i)
    else:
        if p[i-1] > p[i] and p[i] > p[i+1]:
            t.append(i)
if len(t) == 2:
    temp = p[t[0]]
    p[t[0]] = p[t[1]]
    p[t[1]] = temp
    t = []
    for i in range(n):
        if i == 0:
            if p[i] > p[i + 1]:
                t.append(i)
        elif i == (n - 1):
            if p[i - 1] > p[i]:
                t.append(i)
        else:
            if p[i - 1] > p[i] and p[i] > p[i + 1]:
                t.append(i)

if len(t) == 0:
    ans = "YES"

else:
    ans = "NO"

print(ans)

Submission status: Wrong Answer

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

a=[]
for n in range(N-1):
    if p[n]>p[n+1]:
        a.append(n)
if len(a)==0:
    print('YES')
if len(a)==1:
    print('YES')
if len(a)==2:
    mae=a[0]
    ato=a[1]+1
    mm=p[mae]
    aa=p[ato]
    p[mae]=aa
    p[ato]=mm
    t=0
    for n in range(N-1):
        if p[n]>p[n+1]:
            t=1
    if t==0:
        print('YES')
    else:
        print('NO')
if len(a)>2:
    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:
    count = 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()))

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

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
p = [int(x) for x in input().split()]
a = sorted(p)
c = 0
for i in range(N):
  if p[i] != a[i]:
    c+=1
if c <= 2 :
  print("YES")
if c >3:
  print("NO")

Submission status: Wrong Answer

Solution code:
n = int(input())
L = list(map(int, input().split(" ")))
X = sorted(L)
cnt = 0
for a,b in zip(L,X):
    if a != b:
        cnt += 1
        if cnt >3:
            print("NO")
            break
if cnt <= 2:
    print("YES")

Submission status: Wrong Answer

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

a = 0
b = len(lst) - 1
m = len(lst)//2 + 1
flag = 0

for i in range(m):
    if (lst[a + i] + lst[b-i]) != (1 + n):
        print("NO")
        exit()
    
    if lst[a+i] > lst[b-i]:
        flag += 1

if flag >= 2:
    print("NO")

else:
    print("YES")

Submission status: Wrong Answer

Solution code:
a = int(input())
list_a=list(map(int, input().split()))  #リスト入力
count = 0
for i in range(len(list_a)):
    print(list_a[i],len(list_a)-i)
    if list_a[i] != i+1:
        count += 1
    
if count == 2 or count == 0:
    print("YES")
else :
    print("NO")

Submission status: Wrong Answer

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

count = 0

for i in range(n):
  if ls[i] == i+1:
    continue
  else:
    count +=1
    if count >=2:
      break
    if ls[ls[i]-1]==i+1:
      ls[i] = i+1
      ls[ls[i]-1] = ls[i]
    else:
      count+=1
      
if count>=2:
  print("NO")
else:
  print("YES")

Submission status: Wrong Answer

Solution code:
import numpy as np

N =  int(input())
num_arr = np.array(list(map(int, input().split())))
right_num_arr = np.array(list(range(1,N+1,1)))

dif = num_arr - right_num_arr

if len(set(dif))==0 or 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-1):
    if p[i] > p[i+1]:
        cnt += 1

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

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-
N=int(input())
p=list(map(int,input().split()))
count=0
origin=[j+1 for j in range(N)]
for i in range(N):
    if p[i]!=origin[i]:
        count=count+1
if count>3:
    print("NO")
else:
    print("YES")

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    p = string_to_int(inputs[0])

    diff_point = []
    for i, num in enumerate(range(1, len(p)+1)):
        if num != p[i]:
            diff_point.append(i)
    if len(diff_point) == 2:
        return "YES"
    return "NO"


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
p = list(map(int, input().split()))
ans = True
for i in range(n):
    if i % 2 == 0 and p[i] % 2 == 0:
        ans = False
    if i % 2 == 1 and p[i] % 2 == 1:
        ans = False

if ans:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
import sys

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

different_index = -1
should_place = -1
for i, p in enumerate(p_list):
    if p != i + 1:
        different_index = i
        should_place = p - 1
        continue
    
    if different_index >= 0 and p != i + 1 and i != should_place:
        print("NO")
        sys.exit(1)

if different_index == -1:
    print("YES")
elif p_list[should_place] == different_index + 1:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(len(a)):
    if a[i]!=i+1:
        count = count + 1
        
if count == 2 or count == 0:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
A =str(input()).split(' ')
B =sorted(A)
count = 0
for i in range(len(B)):
    if A[i]!=B[i]:
        count +=1
if count>2:
    print('NO')
else:
    print('YES')

Submission status: Wrong Answer

Solution code:
import numpy as np

N =  int(input())
num_arr = np.array(list(map(int, input().split())))
right_num_arr = np.array(list(range(1,N+1,1)))

dif = num_arr - right_num_arr

if len(set(dif)) < 4:
  print('YES')
else:
  print('NO')

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
#B
import sys
import math


n = int(input())
tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))

#print(hoge)

for i in range(0,n-1):
	if(hoge[i]<hoge[i+1]):
		if(i==n-2):
			print("YES")
			sys.exit()
	else:
		break

for i in range(0,n-1):
	for j in range(i+1,n):
		k=hoge[j]
		hoge[j]=hoge[i]
		hoge[i]=k
		for m in range(0,n-1):
			if(hoge[m]<hoge[m+1]):
				if(m==n-2):
					print("YES")
					sys.exit()
			else:
				break

print("NO")

Submission status: Wrong Answer

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

sortP = sorted(P)

# 2箇所を入れ替えたら昇順になる ＝ 昇順に並べ替えた配列と要素ごとに比較して、違いは2箇所だけ。
if sum([a != b for a, b in zip(P, sortP)]) == 2:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
pn = [int(i) for i in input().split()]
cnt = 0

for i in range(1,n+1):
  if i != pn[i-1]:
    cnt += 1
if cnt == 2:
  print('NO')
else:
  print('YES')

Submission status: Wrong Answer

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

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] != n+1 :
    c += 1
    if c>2 :
      break

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

Submission status: Wrong Answer

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

tmp1 = -1
tmp2 = -1
swap = False
ans = True
for i in range(1, N):
    if p[i - 1] > p[i]:
        if tmp1 < 0 and not swap:
            tmp1 = p[i - 1]
            tmp2 = p[i]
        elif not swap:
            if p[i] < tmp2 and p[i - 1] < tmp1:
                swap = True
            else:
                ans = False
                break
        else:
            ans = False
            break

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

Submission status: Wrong Answer

Solution code:
N = int(input())

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


cnt = 0
for i in range(1, N):
    if P[i] < P[i - 1]:
        if cnt == 1:
            print('NO')
        else:
            v = P[i - 1]
            P[i] = P[i - 1]
            P[i - 1] = v
            cnt +=1
    else:
        continue

print('YES')

Submission status: Wrong Answer

Solution code:
N = int(input())
num_list = list(map(int, input().split()))
#print(N, num_list)

sorted_list = sorted(num_list)
false_count = 0
for i, j in zip(num_list, sorted_list):
  if i != j:
    false_count += 1
    if false_count > 2:
      print('NO')
      break

print('YES')

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 permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

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()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    n=INT()
    p=LIST()

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

    if l!=1:
        lis.append(l)

    #print(lis)
    if len(lis)==1:
        print('YES')
    else:
        print('NO')

if  __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
p = [int(x) for x in input().split()]
a = (sorted(p,reverse = True))
c = 0
for i in range(N):
  if p[i] != a[i]:
    c+=1
if c <= 2 :
  print("YES")
if c >3:
  print("No")

Submission status: Wrong Answer

Solution code:
# ABC135b
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

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

last = 0
for i in range(1, len(p)):
    if (p[i] < p[i - 1]):
        # print("swapneeded"+str(i))
        if (last == 0 or last == i - 1):
            #print("swaped" + str(i))
            temp = p[i]
            p[i] = p[i - 1]
            p[i-1] = temp
            last = i
        else:
            print("NO")
            exit()
print("YES")

Submission status: Wrong Answer

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

c = 0
for p, q in zip(P, sorted(P)):
  if p != q:
    c += 1
    if c > 2:
      break

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

Submission status: Wrong Answer

Solution code:
import sys

n = int(input())

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

ps = sorted(p)

count = 0

for a, b in zip(p, ps):
    print(a, b)
    if(a != b):
        count += 1
    if(count > 2):
        print("NO")
        sys.exit()
        break

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):
    if i+1 !=  p[i]:
        count = count + 1

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

sp = sorted(p)

if(sp == p):
	print('YES')
else:
	ma = max(p)
	mi = min(p)
	
	ma_idx = p.index(ma)
	mi_idx = p.index(mi)
	if(ma_idx == 0 and mi_idx == n-1):
		p_tmp = p[1:-1]
		sp_tmp = sorted(p_tmp)
		if(p_tmp == sp_tmp):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')

Submission status: Wrong Answer

Solution code:
n = int(input())

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

w = 0

for i in range(n-1):
    if l[i] != l[i+1]-1:
        w += 1

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

Submission status: Wrong Answer

Solution code:
#ABC 135, B
n = int(input())
P = [int(el) for el in input().split(' ')]

count = 0
for p, q in zip(P, range(1,n+1)):
    if p != q:
        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()))


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

if cnt in (0, 2):
    print('YES')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
N = int(input())
test_list = list(map(int, input().split()))
sorted_list = [idx+1 for idx in range(N)[::-1]]
cnt = 0
for idx in range(N):
  if test_list[idx] != sorted_list[idx]:
    cnt += 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)
count = 0

for i,j in zip(p, q):
    if i == j:
        continue
    else:
        count += 1
    if count > 2:
        print('NO')
        exit()
print('YES')

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())

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

sortli = sorted(li)

count = 0

for i in range(n):
    if li[i] == sortli[i]:
        count += 1

if count + 2 == n:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
n = int(input())
import numpy as np
p = np.array(list(map(int, input().split())))
ps = np.array(sorted(p))
s = np.sum(p==ps)
if s==0 or s==2:
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

Solution code:
def main():
    n=int(input())
    p=[int(i) for i in input().split(' ')]
    p_sorted = sorted(p)
    cnt = 0
    for i,j in zip(p,p_sorted):
        if i != j:
            cnt += 1
    if cnt ==2:
        print('YES')
    else:
        print('NO')
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

for i in range(n):
    a[a[i]-1], a[i] = a[i], a[a[i]-1]

if a == sorted(a):
    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:
        counter += 1
if counter == n - 2 or counter == 0:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()] 

prev = None
count = 0
for x in a:
    if prev:
        if x != prev+1:
            count += 1
    prev = x

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

Submission status: Wrong Answer

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

for i, v in enumerate(p):
    if i + 1 != v:
        c += 1

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

Submission status: Wrong Answer

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

l = 0
count = 1
for i in range(n-1):
    if p[i] <= p[i+1]:
        count += 1
    else:
        l = max(l, count)
        count = 1
l = max(l, count)
if l >= n-2:
    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 p, q in zip(P, Q):
    if p != q:
        cnt += 1
print("YES" if cnt == 2 else "NO")

Submission status: Wrong Answer

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

print("YES") if ad == 2 else print("NO")

Submission status: Wrong Answer

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

print(p_list_sorted)
print(p_list)
if cnt == 2 or cnt == 0:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
n = int(input())
l = [int(i) for i in input().split()]
s = l[:]
l.sort()
c=0
for i in range(n):
    if l[i]!=s[i]:
        c+=1
if c>2:
    print('N0')
else: print('YES')

Submission status: Wrong Answer

Solution code:
N = int(input())
p = [int(x) for x in input().split()]
a = sorted(p)
c = 0
for i in range(N):
  if p[i] != a[i]:
    c+=1
if c <= 2 :
  print("YES")
if c >3:
  print("No")

Submission status: Wrong Answer

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

q = sorted(p)

diff = 0
for n in range(N):
    if p[n]!=q[n]:
        diff += 1

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

Submission status: Wrong Answer

Solution code:
import itertools
import copy


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


def main():
    n = int(input())
    ps = list(map(int, input().split()))

    if is_sorted(ps):
        print('Yes')
        return

    for i, j in itertools.combinations(range(n), 2):
        ps_ = copy.deepcopy(ps)
        ps_[i], ps_[j] = ps_[j], ps_[i]
        if is_sorted(ps_):
            print('Yes')
            return
    print('No')
    return


main()

Submission status: Wrong Answer

Solution code:
n = int(input())
pn = [int(i) for i in input().split()]
cnt = 0

for i in range(1,n+1):
  if i != pn[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()))
A = list(i for i in range(1,N+1))
#print(A)

for i in range(0, N-1):
    for j in range(i+1, N):
        B = A
        B[i], B[j] = B[j], B[i]
        if P == A:
            print('YES')
            exit()
        B[i], B[j] = B[j], B[i]
print('NO')

Submission status: Wrong Answer

Solution code:
n = int(input())
p = [int(i) for i in 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())

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

for i in range(1, len(p)):
    if p[i-1] + 1 == p[i]:
        pass
    else:
        cnt += 1
    
    if cnt >= 3:
        break

if cnt >= 3:
    print('NO')
else:
    print('YES')

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
p = tuple(map(int,input().split()))
c = 0
ans = "YES"
for i in range(1,n+1) :
    if p[i-1] != i :
        c += 1
if c <= 2 :
    ans = "NO"
print(ans)

Submission status: Wrong Answer

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

count = 0

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
Ps = list(map(int, input().split()))
Ps.insert(0, 0)

c = 0
cs = []
for i in range(1, N + 1):
    if Ps[i] != i:
        c += 1
        cs.append(i)
if c != 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)

count = 0

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

if count > 3:
    print('N0')
else:
    print('YES')

Submission status: Wrong Answer

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

res = 0
for a, n in zip(A, N):
    if a != n:
        res += 1
print("YES") if res <= 1 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):
    if(a[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()]
cnt = 0
for i in range(1,n+1):
    if P[i-1] != i: cnt += 1
if cnt <= 2: print('Yes')
else: print('No')

Submission status: Wrong Answer

Solution code:
n = int(input())
arr = list(map(int, input().split()))
reverse_arr = list(reversed(arr))

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

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

Submission status: Wrong Answer

Solution code:
input()
A = list(map(int, input().split()))
N = [n + 1 for n in range(len(A))]

res = 0
for a, n in zip(A, N):
    if a != n:
        res += 1
print("YES") if res <= 1 else print("NO")

Submission status: Wrong Answer

Solution code:
n=int(input())
P=[int(i) for i in input().split()]
ct=0
for i in range(n):
  if i+1!=P[i]:
    ct+=1
print("YES" if ct==2 else "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
if f<=2:
    print("YES")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())
*P, = map(int, input().split())
diff = []
for i in range(N):
    if P[i] != i+1:
        diff.append(i)
if len(diff) == 2:
    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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np


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

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

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

Submission status: Wrong Answer

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

Submission status: Accepted

Solution code:
import copy
n = int(input())
li = list(map(int,input().split()))
li1 = copy.copy(li)
li1.sort()
cnt = 0
for i in range(n):
    if li[i] != li1[i]:
        cnt += 1

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

Submission status: Accepted

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

if p == sorted(p):
    print('YES')
else:
    ret = 'NO'
    # 全通りの組み合わせをみて、昇順かどうか調べる
    for i in range(N-1):
        for j in range(i+1, N):

            # p[i]とp[j]より小さければ抜ける
            if p[i] < p[j]:
                is_sorted = False
                continue
            else:
                k = p.copy()
                k[i], k[j] = k[j], k[i]

            is_sorted = True
            for l in range(N-1):
                if k[l+1] < k[l]:
                    is_sorted = False
                    break

            if is_sorted:
                ret = 'YES'
                break
        if is_sorted:
            break

    print(ret)

Submission status: Accepted

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

if p == sorted(p):
    print('YES')
else:
    ret = 'NO'
    is_sorted = False
    # 全通りの組み合わせをみて、昇順かどうか調べる
    for i in range(N-1):
        for j in range(i+1, N):
            # p[i]とp[j]より小さければ抜ける
            if p[i] < p[j]:
                continue
            else:
                k = p.copy()
                k[i], k[j] = k[j], k[i]

#             for l in range(N-1):
#                 if k[l+1] < k[l]:
#                     is_sorted = False
#                     break

            if k == sorted(p):
                ret = 'YES'
                is_sorted = True
                break
        if is_sorted:
            break

    print(ret)

Submission status: Accepted

Solution code:
# Nと数列pを受け取る
N = int(input())
p = list(map(int, input().split()))

# pがすでに昇順だったら、YESにする
result = 'NO'
sorted_p = sorted(p)
# if p == sorted_p:
#   result = 'YES'
# else:
#   # pから2つの要素を入れ替えて昇順になったら、YESにする
#   count = 0
#   for i in range(N):
#     if p[i] != sorted_p[i]:
#       count += 1
#   if count == 2:
#     result = 'YES'

# pから2つの要素を入れ替えて昇順になったら、YESにする
count = 0
for i in range(N):
  if p[i] != sorted_p[i]:
    count += 1
if count <= 2:
  result = 'YES'

# 出力する
print(result)

Submission status: Accepted

Solution code:
N = int(input())
P = tuple(map(int, input().split()))
assert len(P) == N

sortedP = sorted(P)

count = len([p for p,q in zip(P, sortedP) if p != q])
if count == 2 or count == 0:
  print('YES')
else:
  print('NO')

Submission status: Accepted

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

for i in range(N):
	if P[i]!=i+1:
		ido.append(P[i])

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

Submission status: Accepted

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 in [0, 2]:
    print("YES")
else:
    print("NO")

Submission status: Accepted

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

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

Submission status: Accepted

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

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

if cnt < 3:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
N = int(input())
p = [int(i) for i in input().split()]
r = sorted(p)
for i in range(N):
    for j in range(i+1,N):
        q = []
        for k in range(N):
            if(k == i):
                q.append(p[j])
            elif(k == j):
                q.append(p[i])
            else:
                q.append(p[k])
        if(p == r or q == r):
            print("YES")
            exit()
print("NO")

Submission status: Accepted

Solution code:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

n = k()
p = l()

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

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

Submission status: Accepted

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

p_sorted = sorted(p)
cnt = 0
for i in range(N):
    if p[i] != p_sorted[i]:
        cnt += 1
if cnt <= 2:
    print("YES")
else:
    print("NO")

Submission status: Accepted

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: Accepted

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

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

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

Submission status: Accepted

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

res = False
for i in range(N):
    for j in range(i, N):
        flg = True
        p[i], p[j] = p[j], p[i]
        for k in range(N - 1):
            if p[k] > p[k + 1]:
                flg = False
        if flg:
            res = True
            break
        p[i], p[j] = p[j], p[i]

print(['NO', 'YES'][res])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def resolve():
    n = int(input())
    p = map(int,input().split())
    cnt = 0
    for i,j in enumerate(p):
        if (i+1) != j:
            cnt += 1
    print('YES' if cnt < 3 else 'NO')
resolve()