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

Submission status: Wrong Answer

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

box=[]
#リストの中の１つを入れ替えたら123456・・・になるようにする
for i in range(n-1):
  if i == a[i]:
    pass
  else:
    box.append(i)
if len(box) == 0 or len(box) == 2:
  print('YES')
else:
  print('NO')

Submission status: Wrong Answer

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

box=[]
print(a)
print(box)
#リストの中の１つを入れ替えたら123456・・・になるようにする
for i in range(n-1):
  if i == a[i]:
    pass
  else:
    box.append(i)
if len(box) == 0 or len(box) == 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-1):
    A=p[i]
    if A == (i+1):
        count=count+1
if count >= (N-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-1):
    A=p[i]
    if A == i:
        count=count+1
if count <= (N-2):
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
N=int(input())
p=list(map(int, input().split()))
badcount=0
goodcount=0
for i in range(N-1):
    A=p[i+1]
    B=p[i]
    if A < B:
        badcount=badcount+1
        if badcount ==1:
            C=B
        elif badcount == 2 and C < B:
            print('NO')
            break
        elif badcount > 2:
            print('NO')
            break            
    elif A > B:
        goodcount=goodcount+1
        if goodcount > (N-2):
            print('YES')
            break

Submission status: Wrong Answer

Solution code:
N=int(input())
p=list(map(int, input().split()))
badcount=0
goodcount=0
for i in range(N-1):
    A=p[i+1]
    B=p[i]
    if A < B:
        badcount=badcount+1
        if badcount >= 3:
            print('NO')
            break
    if A > B:
        goodcount=goodcount+1
        if goodcount > (N-4):
            print('YES')
            break

Submission status: Wrong Answer

Solution code:
N=int(input())
p=list(map(int, input().split()))
count=0
for i in range(N-1):
    A=p[i+1]
    B=p[i]
    if A < B:
        count=count+1
        if count >= 3:
            print('NO')
            break
    if A > B:
        if i == (N-1) and count < 3:
            print('YES')
            break

Submission status: Wrong Answer

Solution code:
N=int(input())
p=list(map(int, input().split()))
count=0
for i in range(N-1):
    A=p[i+1]
    B=p[i]
    print(A)
    print(B)
    if A < B:
        count=count+1
        if count >= 3:
            print('NO')
            break
    if A > B:
        if i == (N-1) and count < 3:
            print('YES')
            break

Submission status: Wrong Answer

Solution code:
N=int(input())
p=list(map(int, input().split()))
count=0
for i in range(N-1):
    A=p[i+1]
    B=p[i]
    if A < B:
        count=count+1
        if count >= 3:
            print('NO')
            break
    if i == (N-1) and count < 3:
        print('YES')
        break

Submission status: Wrong Answer

Solution code:
N=int(input())
p=list(map(int, input().split()))
count=0
for i in range(N-1):
    A=p[i+1]
    B=p[i]-1
    if A < B:
        count=count+1
        if count >= 3:
            print('NO')
            break
    if i == (N-1) and count < 3:
        print('YES')
        break

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

b=P.copy()

b.sort()
count=0

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

Submission status: Wrong Answer

Solution code:
def solve(string):
    n, *p = map(int, string.split())
    return "NO" if sum([i != _p for i, _p in enumerate(p, start=1)]) > 2 else "YES"


if __name__ == '__main__':
    print(solve(input()))

Submission status: Wrong Answer

Solution code:
def solve(string):
    n, *p = map(int, string.split())
    ps = sorted(p)
    return "NO" if sum([_ps != _p for _ps, _p in zip(ps, p)]) > 2 else "YES"


if __name__ == '__main__':
    print(solve(input()))

Submission status: Wrong Answer

Solution code:
from statistics import mode
import numpy as np
N=input()
p=list(map(int,input().split()))
p=np.array(p)
q=p-np.arange(len(p-1))
q = list(q)
r = len(list(set(q)))
if r<=3:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
from statistics import mode
import numpy as np
N=input()
p=list(map(int,input().split()))
p=np.array(p)
q=p-np.arange(len(p-1))
q = list(q)
r = len(list(set(q)))
if r==1 or r==3:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

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

total = 0
for i, p in enumerate(P):
	if p > i+1:
		total += 1

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

Submission status: Wrong Answer

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

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

print(ok)

Submission status: Wrong Answer

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

ans = 0
flug = 0

for i in range(N):
  if P[i] != i+1:
    ans += 1
      
if ans <= 2:
  print("Yes")
elif ans >= 3:
  print("No")

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
input = sys.stdin.readline

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

for i in range(N):
    if p[i] != i+1 and p[p[i]-1] != i+1:
        print('NO')
        exit()
print('YES')

Submission status: Wrong Answer

Solution code:
N = int(input())
Snew =[]
Sold = list(map(int,input().split()))
Snew = Sold[::1]
Snew.sort()
count = 0
for i in range(N):
  if Sold[i] == Snew[i]:
    count += 1
if count > 2:
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

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

sorted_b = [i+1 for i in range(a)]

diff = [x-y for (x,y) in zip(sorted_b, b)]

if len([i for i in diff if i != 0]) == 2:
  print('YES')
else:
  print('NO')

Submission status: Wrong Answer

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

sorted_b = [i+1 for i in range(a)]

diff = [x-y for (x,y) in zip(sorted_b, b)]

if len([i for i in diff if i == 0]) == 2:
  print('YES')
else:
  print('NO')

Submission status: Wrong Answer

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

status = 0
for i in range(0, N):
    if (i + 1) != ll[i]:
        status += 1

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

Submission status: Wrong Answer

Solution code:
"""
- https://atcoder.jp/contests/abc136/tasks/abc135_b
- reg:2≤N≤50
"""
# n = int(input())
p = [int(e) for e in input().split()]
n = len(p)
z = [i for i in range(n) if p[i] != (i+1)]
ans = "YES" if len(z) <= 2 else "NO"
print(ans)

Submission status: Wrong Answer

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

sorted_p = sorted(p)

cnt = 0
for i,j in zip(p, sorted_p):
    if i != j:
        cnt += len(str(i))

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

Submission status: Wrong Answer

Solution code:

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


sorted_p = sorted(p)

cnt = 0
for i,j in zip(p, sorted_p):
    if i != j:
        cnt += len(str(i))

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

Submission status: Wrong Answer

Solution code:
n = int(input())
p = [int(i) for i in input().split()]
count = 0
for i in range(n):
    if p[i] != i + 1:
        count += 1
if count == 0:
    print('YES')

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

if count > 2:
    print('No')

Submission status: Wrong Answer

Solution code:
n = int(input())
p = [int(i) for i in input().split()]
count = 0
for i in range(n):
    print(i)
    if p[i] != i + 1:
        count += 1
print(count)
if count == 0:
    print('YES')

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

if count > 2:
    print('No')

Submission status: Wrong Answer

Solution code:
num = int(input())
ls = list(map(str, input().split(" ")))

sls = sorted(ls)

diff = 0
for i in range(num):
    if (sls[i] != ls[i]):
        diff += 1

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

Submission status: Wrong Answer

Solution code:
num = int(input())
num -= 1
ls = list(map(str, input().split(" ")))

sls = sorted(ls)

diff = 0
for i in range(num):
    if (sls[i] != ls[i]):
        diff += 1

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

Submission status: Wrong Answer

Solution code:
import copy

num = int(input())
num -= 1
ls = list(map(str, input().split(" ")))

sls = sorted(ls)

diff = 0
for i in range(num):
    if (sls[i] != ls[i]):
        diff += 1

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int,input().split()))
m = 0
out = 0
 
for num in range(n):
  if(m + 1 != l[m]):
    out += 1
  m += 1
 
if(out > 2):
  print('No')
else:
  print('Yes')

Submission status: Wrong Answer

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

for num in range(n):
  if(m + 1 != l[m]):
    out += 0
  m += 1

if(out > 2):
  print('No')
else:
  print('Yes')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if cnt <= 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, e in enumerate(a):
    if i+1 != e:
        count += 1

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

Submission status: Wrong Answer

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

count = 0
for i, e in enumerate(a):
    if i+1 != e:
        count += 1

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

Submission status: Wrong Answer

Solution code:
list_length = int(input())
numbers = input().split(' ')
desc_count = 0
# 全て昇順の場合はYESになるように
result = 'YES'
i = 0
while i < list_length-1:
	if numbers[i] <= numbers[i+1]:
		# 昇順なのでそのまま
		i += 1
	else:
		# 降順
		desc_count += 1
		if 2 <= desc_count:
			# 二回目の入れ替えが発生してしまったので終了
			result = 'NO'
			break
		else:
			# 現在の値と一度しか入れ替えせずにうまく昇順に並ぶであろう位置を交換. インデックスを進めずに入れ替え後の結果を評価させる
			numbers[int(numbers[i])-1], numbers[i] = numbers[i], numbers[int(numbers[i])-1]
			i = 0
			# print(numbers)
print(result)

Submission status: Wrong Answer

Solution code:
list_length = int(input())
numbers = input().split(' ')
desc_count = 0
# 全て昇順の場合はYESになるように
result = 'YES'
i = 0
while i < list_length-1:
	if numbers[i] < numbers[i+1]:
		# 昇順なのでそのまま
		i += 1
	else:
		# 降順
		desc_count += 1
		if 2 <= desc_count:
			# 二回目の入れ替えが発生してしまったので終了
			result = 'NO'
			break
		else:
			# 現在の値と一度しか入れ替えせずにうまく昇順に並ぶであろう位置を交換. インデックスを進めずに入れ替え後の結果を評価させる
			numbers[int(numbers[i])-1], numbers[i] = numbers[i], numbers[int(numbers[i])-1]
			i = 0
print(result)

Submission status: Wrong Answer

Solution code:
list_length = int(input())
numbers = input().split(' ')
desc_count = 0
# 全て昇順の場合はYESになるように
result = 'YES'
i = 0
while i < list_length-1:
	if numbers[i] < numbers[i+1]:
		# 昇順なのでそのまま
		i += 1
	else:
		# 降順
		desc_count += 1
		if 2 <= desc_count:
			# 二回目の入れ替えが発生してしまったので終了
			result = 'NO'
			break
		else:
			# 現在の値と一度しか入れ替えせずにうまく昇順に並ぶであろう位置を交換. インデックスを進めずに入れ替え後の結果を評価させる
			numbers[int(numbers[i])-1], numbers[i] = numbers[i], numbers[int(numbers[i])-1]
print(result)

Submission status: Wrong Answer

Solution code:
list_length = int(input())
numbers = input().split(' ')
desc_count = 0
# 全て昇順の場合はYESになるように
result = 'YES'
for i in range(list_length-1):
	if numbers[i] < numbers[i+1]:
		# 昇順なのでそのまま
		pass
	else:
		# 降順
		desc_count += 1
		if 2 <= desc_count:
			# 二回目の入れ替えが発生してしまったので終了
			result = 'NO'
			break
		else:
			# 現在の値と一度しか入れ替えせずにうまく昇順に並ぶであろう位置を交換
			numbers[int(numbers[i])-1], numbers[i] = numbers[i], numbers[int(numbers[i])-1]

print(result)

Submission status: Wrong Answer

Solution code:
list_length = int(input())
numbers = input().split(' ')

result = 'YES'
desc_count = 0
for i in range(list_length-1):
	if numbers[i] < numbers[i+1]:
		# 昇順なのでそのまま
		pass
	else:
		# 降順
#		print(int(numbers[i])-1)
#		print(i)
		if int(numbers[int(numbers[i])-1]) == i + 1:
			result = 'YES'
		else:
			result = 'NO'
		break

print(result)

Submission status: Wrong Answer

Solution code:
N = int(input())
List = [int(i) for i in input().split()]
count = 0
for j in range(N):
    if(List[j] != j+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()))
P = p[0:N]
P.sort()
P = P[::-1]
count = 0
for _ in range(0,N):
    if p[_] != P[_]:
        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())
ans=0
for i in range(N):
  if i+1 ==p[i]:
    ans+=1
if ans==0 or ans==2:
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
p = list(map(int,input().split()))
p = np.array(p)
p_new = np.zeros(N)
t = 0
for k in range(N-1):
	if p[k] > p[k+1]:
		t = 1
if t == 0:
	print("YES")
	exit()

for i in range(N):
	for j in range(i):
		for k in range(N):
			p_new[k] = p[k]
		p_new[i] = p[j]
		p_new[j] = p[i]
		print(p_new)
		t = 0
		for k in range(N-1):
			if p_new[k] > p_new[k+1]:
				t = 1
		if t == 0:
			print("YES")
			exit()
print("NO")

Submission status: Wrong Answer

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

pn = sorted(p)

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

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

Submission status: Wrong Answer

Solution code:
# Swap 0 or 1 Swap

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

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

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

Submission status: Wrong Answer

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

a=[]

for i in range(len(li)-1):
  if li[i]>li[i+1]:
    if len(a)==0:
      a.append(i)
    else:
      a.append(i+1)
if len(a)>2:
  print('NO')
  exit()
else:
  a.append(len(li)-1)
  a.append(len(li)-1)
  temp=li[a[0]]
  li[a[0]]=li[a[1]]
  li[a[1]]=temp
for i in range(len(li)-1):
  if li[i]>li[i+1]:
    print(li)
    print('NO')
    exit()
print('YES')

Submission status: Wrong Answer

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

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

if counter==0 or counter==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 != p[i-1]):
        cnt = cnt+1
if(cnt == 0 or cnt == 2):
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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

a_prev = 0
a_prev_prev = 0
a_cand = []
i_cand = []
c_cand = 0
ans = 'NO'
for i in range(n):
    a_i = a[i]
    if a_i < a_prev:
        if c_cand == 1:
            if a_i < a_prev_prev:
                ans = 'NO'
            else:
                if ans == 'YES':
                    ans = 'NO'
                else:
                    ans = 'YES'
        elif c_cand > 1:
            ans = 'NO'
            break
        if c_cand == 0:
            if i == (n-1):
                if a_i < a_prev_prev:
                    ans = 'NO'
                else:
                    ans = 'YES'
            else:
                if a_i < a_prev_prev:
                    ans = 'NO'
                if a_prev > a[i+1]:
                    ans = 'NO'
                else:
                    ans = 'YES'

        a_cand.append(a_prev)
        i_cand.append(i - 1)
        c_cand += 1
        if i < 2:
            a_prev = 0
            a_prev_prev = 0
        else:
            a_prev = a[i-2]
            a_prev_prev = a[i-2]
    else:
        a_prev = a[i]
        continue

if c_cand == 0:
    ans = 'YES'



print(ans)

Submission status: Wrong Answer

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

a_prev = 0
a_prev_prev = 0
a_cand = []
i_cand = []
c_cand = 0
ans = 'NO'
for i in range(n):
    a_i = a[i]
    if a_i < a_prev:
        if c_cand == 1:
            if a_i < a_prev_prev:
                ans = 'NO'
            else:
                ans = 'YES'
        elif c_cand > 1:
            ans = 'NO'
            break
        a_cand.append(a_prev)
        i_cand.append(i - 1)
        c_cand += 1
        if i < 2:
            a_prev = 0
            a_prev_prev = 0
        else:
            a_prev = a[i-2]
            a_prev_prev = a[i-2]
    else:
        a_prev = a[i]
        continue

if c_cand == 0:
    ans = 'YES'
elif c_cand == 1:
    if i_cand[0] == (n - 2):
        ans = 'YES'


print(ans)

Submission status: Wrong Answer

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

a_prev = 0
a_prev_prev = 0
a_cand = []
i_cand = []
c_cand = 0
ans = 'NO'
for i in range(n):
    a_i = a[i]
    if a_i < a_prev:
        if c_cand == 1:
            if a_i < a_prev_prev:
                ans = 'NO'
            else:
                ans = 'YES'
        elif c_cand > 1:
            ans = 'NO'
            break
        a_cand.append(a_prev)
        i_cand.append(i - 1)
        c_cand += 1
        if i < 2:
            a_prev = 0
            a_prev_prev = 0
        else:
            a_prev = a[i-2]
            a_prev_prev = a[i-2]
    else:
        a_prev = a[i]
        continue

if c_cand == 0:
    ans = 'YES'

print(ans)

Submission status: Wrong Answer

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

a_prev = 0
a_prev_prev = 0
a_cand = []
i_cand = []
c_cand = 0
ans = 'YES'
for i in range(n):
    a_i = a[i]
    if a_i < a_prev:
        if c_cand == 1:
            if a_i < a_prev_prev:
                ans = 'NO'
            else:
                ans = 'YES'
        elif c_cand > 1:
            ans = 'NO'
            break
        a_cand.append(a_prev)
        i_cand.append(i - 1)
        c_cand += 1
        if i < 2:
            a_prev = 0
            a_prev_prev = 0
        else:
            a_prev = a[i-2]
            a_prev_prev = a[i-2]
    else:
        a_prev = a[i]
        continue

print(ans)

Submission status: Wrong Answer

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

for i in range(n):
    if numlist==sortedlist:
        print("YES")
    minnum=i
    for j in range(i,n):
        if numlist[minnum]>numlist[j]:
            minnum=j
    if minnum!=i:
        a=numlist[minnum]
        numlist[minnum]=numlist[i]
        numlist[i]=a
        if numlist==sortedlist:
            print("YES")
        else:
            print("NO")
        break

Submission status: Wrong Answer

Solution code:
# B - 0 or 1 Swap
n = int(input())
p = list(map(int, input().split()))

lt_count = 0
gt_count = 0

for i in range(n):
    print(i)
    if i < n-1 and p[i] > p[i+1]:
        gt_count += 1
    elif i >= 2 and p[i] < p[i-1]:
        lt_count += 1

    print(lt_count, gt_count)
if lt_count == 1 and gt_count == 1:
    print('YES')
elif lt_count == 0 and gt_count == 0:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

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

maxIndex = 0
minIndex = 0
for i in range(N):
    if pp[maxIndex] < pp[i]:
        maxIndex = i
    if pp[minIndex] > pp[i]:
        minIndex = i

# swap
if maxIndex < minIndex:
    num = pp[maxIndex]
    pp[maxIndex] = pp[minIndex]
    pp[minIndex] = num

# check
maxNum = 0
for i in range(N):
    if maxNum > pp[i]:
        print('NO')
        exit(0)
    maxNum = pp[i]

print('YES')

Submission status: Wrong Answer

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

sum = 0
cnt = 0
for i in range(N):
    if cnt > 2:
        break

    if Nlist[i] == (i + 1):
        continue
    else:
        sum += Nlist[i]
        cnt += 1

if cnt == 0 or sum == (N + 1):
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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

sum = 0
cnt = 0
for i in range(N):
    if cnt > 2:
        break

    if Nlist[i] == (i + 1):
        continue
    else:
        sum += Nlist[i]
        cnt += 1

if cnt == 0 or sum == (N + 1):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
N = raw_input
a = map(int, raw_input().split())
ind = 0
counter = 0

for num in a:
	ind = ind + 1
	if num != ind:
		counter = counter + 1
	
if counter < 3:
	print("YES")
else:
	print("NO")

Submission status: Wrong Answer

Solution code:
a = map(int, raw_input().split())
ind = 0
counter = 0

for num in a:
	ind = ind + 1
	if num != ind:
		counter = counter + 1
	
if counter < 3:
	print("YES")
else:
	print("NO")

Submission status: Wrong Answer

Solution code:
a = map(int, raw_input().split())
ind = 1
flag = 0

for num in a:
	if num != ind:
		flag = flag + 1
	ind = ind + 1
	
if ind < 3:
	print("YES")
else:
	print("NO")

Submission status: Wrong Answer

Solution code:
a = map(int, raw_input().split())
ind = 1
flag = 0

for num in a:
	if num != ind:
		flag = flag + 1
	ind = ind + 1
	
if flag < 3:
	print("YES")
else:
	print("NO")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

flag = True  
new = -1
m = -1
for i in range(num):
  if i+1 == a[i]:
    pass
  else:
    if new == 0:
      new = i
    else:
      a[i],a[new] = a[new], a[i]
      break

for i in range(num):
  if i+1 == a[i]:
    pass
  else:
    flag = False
    print('NO')
    break
if flag:
  print('YES')

Submission status: Wrong Answer

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

flag = True  
new = -1
m = -1
for i in range(num):
  if i+1 == a[i]:
    pass
  else:
    if new == 0:
      new = i
    else:
      a[i],a[new] = a[new], a[i]
      break

for i in range(num):
  if i+1 == a[i]:
    pass
  else:
    flag = False
    print('No')
    break
if flag:
  print('Yes')

Submission status: Wrong Answer

Solution code:
# 0 or 1 Swap
a_list = list(map(int, input().split()))
b_list = range(1, len(a_list))
cnt = 0
for a, b in zip(a_list, b_list):
    if a != b:
        cnt+= 1
if cnt <= 2:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
# 0 or 1 Swap
a_list = list(map(int, input().split()))
b_list = range(len(a_list), 0, -1)
cnt = 0
for a, b in zip(a_list, b_list):
    if a != b:
        cnt+= 1
if cnt <= 2:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
count = 0
for i, j in enumerate(a):
    if i+1 != j:
        count += 1
print('YES' if count == 2 else 'NO')

Submission status: Wrong Answer

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

N = int(input())
p = list(map(int,input().split()))
#print(p[0])
flag = 0

for i in range(N):	
	if p[i] != i + 1 : #iは０からはじまるから＋１する
		flag = flag + 1

if flag <= 2:
	print("YES")
else:
	print("NOs")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

cnt = 0

for i in range(n-1):
    if(arr[i] > arr[i+1]):
        cnt += 1

if(cnt in [0, 1, 2]):
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

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

cnt = 0

for i in range(n-1):
    if(arr[i] > arr[i+1]):
        cnt += 1

if(cnt in [0, 2]):
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

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

count=0
for i in range(int(n)):
  if N[i] !=i+1:
    count+=1
if count > 2:
  print("No")
else:
  print("YES")

Submission status: Wrong Answer

Solution code:
def check_sort(alist):
    check = None
    for i in range(n-1):
        if alist[i] > alist[i+1]:
            check = [i]
            break
    for i in range(1,n):
        if alist[i] < alist[i-1]:
            temp = i
            break
    for i in range(1,n):
        if alist[i] < alist[i-1]:
            if alist[i] < alist[temp]:
                temp = i
    if check is not None:
        check.append(temp)
    return check
n = int(input())
raw_in = input().split()
alist = [int(x) for x in raw_in]
check_max = alist[0]
check_id = 0
status = check_sort(alist)
print(status)
if status is None:
    print("YES")
else:
    alist[status[0]], alist[status[1]] = alist[status[1]], alist[status[0]]
    if check_sort(alist) is None:
        print("YES")
    else:
        print("NO")

Submission status: Wrong Answer

Solution code:
N = int(input())
p = [int(e) for e in input().split()]
cnt = 0
for a,b in zip(p, sorted(p, reverse=True)):
  if a != b:
    cnt +=1
  if cnt >= 3:
    print('NO')
    break
else:
    print('YES')

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())

data = [int(s) for s in input().split()]
count = 0
for i in range(n):
  if i!= data[i]:
    count += 1
if count<= 2:
  print("YES")
else:
  print("NO")
    
  
"""
mx = max(data)
mn = min(data)

if (mx == n-1 and mn == 0) or 
  for i in range(1,n-1):
    if data[i] < data[i+1]:
      continue
    else:
      print("No")
      exit()
"""

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
size = int(input())
list_number = list(map(int, input().split()))

k = 0

for i, number in enumerate(list_number):
    if i + 1 != number:
        k += 1

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

Submission status: Wrong Answer

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

for i in range(len(seq)-1):
    if seq[i] <= min(seq[i+1:]):
        continue
    elif seq[i] > min(seq[i+1:]):
        j = min(seq[i+1:])
        if seq[i] > min(seq[i+1:j]+seq[j+1:]):
            print("NO")
            break
        seq[i], seq[j] = seq[j], seq[i]
else:
    print("YES")