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:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def main():

	N = int(input())
	# = list(input())
	#A,B = map(int, input().split(" "))
	PP = list(map(int, input().split(" ")))

	#P = copy.deepcopy(PP)

	tmp = []
	for i in range(N):
		for j in range(i+1, N):
			P = copy.deepcopy(PP)
			tmp = P[j]
			P[i] = P[j]
			P[j] = tmp

		flg = True
		for k,val in enumerate(P):
			if k == 0:
				continue
			if P[k-1] <= val:
				pass
			else:
				flg = False

		if flg == True:
			print("YES")
			sys.exit()

	print("NO")


if __name__ == "__main__":
	main()

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
import sys

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

correct = [int(_) for _ in range(1,N+1)]

res = 0
if p == correct:
    res = 1
else:
    for i in range(N):
      for j in range(i+1,N):
        a = p[:]
        c = a[i]
        a[i] = a[j]
        a[j] = c
        print(a)
        if a == correct:
            res = 1

if res == 1:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
import copy

n=int(input())
ps=input().split()

sortedps = copy.deepcopy(ps)
sortedps.sort()

count = 0
for i in range(0,n):
    if count > 2:
        print('NO')
        exit()
    if ps[i] != sortedps[i]:
        count = 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()))
answer = []
diff = 0
diff_1 = -1
diff_2 = -1

index = 0

for i in p:
    if index == 0:
        index += 1
        continue
    
    if p[index] < p[index-1]:
        if diff >= 2:
            print ("NO")
            exit()
        diff += 1

        if diff_1 == -1:
            diff_1 = index-1
        else:
            diff_2 = index-2

    index += 1

if diff_1 == -1:
    print("YES")
    exit()

if diff_1 != -1 and diff_2 == -1:
    print("YES")
    exit()

diff_1_1 = p[diff_1]
p[diff_1] = p[diff_2]
p[diff_2] = diff_1_1

index = 0
for i in p:
    if index == 0:
        index += 1
        continue
    
    if p[index] < p[index-1]:
        print ("NO")    
        exit()

    index += 1

print("YES")

Submission status: Wrong Answer

Solution code:
N=int(input())
p=list(map(int,input().split()))
A=p.copy()
A.sort()
if p==A:
  print("YES")
else:
  i=p.index(max(p))
  j=p.index(min(p))
  p[i],p[j]=p[j],p[i]
  if p==A:
    print("YES")
  else:
    print("NO")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


down_i = []
down_count = 0
for i in range(n-1):
    if p[i] > p[i+1]:
        down_i.append([i,p[i],p[i+1]])
        down_count += 1

if down_count <= 1:
    print('YES')
else:
    if down_count == 2:
        p[down_i[0][0]] = down_i[1][2]
        p[down_i[1][0]+1] = down_i[0][1]

        #print(p)

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

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

Submission status: Wrong Answer

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

for i in range(N-1):
    if p[i]>p[i+1]:
        cnt+=1
print(cnt)
if cnt>2 or cnt==1:
    print("NO")
    exit()
if cnt==0:
    print("YES")
    exit()
else:
    for i in range(N-1):
        if p[i]>p[i+1]:
            a.append(p[i])
            a.append(p[i+1])
if a[0]>a[2] and a[1]>a[3]:
    print("YES")      
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
cnt = int(input())
lst = list(map(int,input().split()))
lst2 = [i for i in range(1, cnt + 1)]
null_lst = []

for j in range(cnt):
  if lst[j] != lst2[j]:
    null_lst.append(lst[j])

if len(null_lst) % 2 == 0 or len(null_lst) == 0:
  print('YES')
else:
  print('NO')

Submission status: Wrong Answer

Solution code:
import sys

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

correct = [int(_) for _ in range(1,N+1)]

res = 0
if p == correct:
    print('YES')
else:
    for i in range(N):
      for j in range(i+1,N):
        a = p[:]
        c = a[i]
        a[i] = a[j]
        a[j] = c
        print(a)
        if a == correct:
            res = 1

if res == 1:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
import copy

n=int(input())
ps=input().split()

sortedps = copy.deepcopy(ps)
sortedps.sort()

count = 0
for i in range(0,n-1):
    if count > 2:
        print('NO')
        exit()
    if ps[i] != sortedps[i]:
        count = count +1
if count > 2:
    print('NO')
    exit()

print('YES')

Submission status: Wrong Answer

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


down_i = []
down_count = 0
for i in range(n-1):
    if p[i] > p[i+1]:
        down_i.append([i,p[i],p[i+1]])
        down_count += 1

if down_count <= 1:
    print('YES')
else:
    if down_count == 2:
        p[down_i[0][0]] = down_i[1][2]
        p[down_i[1][0]+1] = down_i[0][1]

        #print(p)

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

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

Submission status: Wrong Answer

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

list2 = []
for i in range(1,N + 1):
    list2.append(i)

if list1 == list2:
    print("Yes")
    sys.exit()
for i in range(0,N):
    if list1[i] != i+1:
        if i+1 == list1[list1[i]-1]:
            list1[list1[i]-1] = list1[i]
            list1[i] = i+1
            

        if list1 == list2:
            print("Yes")
            sys.exit()
        else:
            print("No")
            sys.exit()

Submission status: Wrong Answer

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

for i in range(N-1):
    if p[i] > p[i+1]:
        cnt += 1
        l.append(i)

if cnt > 2:
    print('NO')
if cnt < 2:
    print('YES')
if cnt == 2:
    p[l[0]], p[l[1]+1] = p[l[1]+1], p[l[0]]
    cnt = 0
    for i in range(N-1):
        if p[i] > p[i+1]:
            cnt += 1
            l.append(i)
    print(p)
    if cnt == 0:
        print('YES')
    else:
        print('NO')

Submission status: Wrong Answer

Solution code:
import numpy as np


n = int(input())
x = [int(i) for i in input().split()]
p = np.array(x)
swap_flg = False
ans = 'YES'

max_index = p.argmax()
min_index = p.argmin()

if max_index != n - 1 and min_index != 0:
    tmp = p[max_index]
    p[max_index] = p[min_index]
    p[min_index] = tmp

for i in range(n):
    if i == 0:
        continue
    if p[i - 1] > p[i]:
        ans = 'NO'
        break
print(ans)

Submission status: Wrong Answer

Solution code:
input()
pp = list(map(int, input().split()))
sorted_pp = sorted(pp)
flag = False
if pp == sorted(pp):
    print('YES')
else:
    for i in range(len(pp) - 1):
        for j in range(len(pp) - 1 - i):
            ppp = pp.copy()
            ppp[i] = pp[j + 1]
            ppp[j + 1] = pp[i]
            if ''.join(map(str, ppp)) == ''.join(map(str, sorted_pp)):
                flag = True
                break
    if flag:
        print('YES')
    else:
        print('NO')

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

n = int(input())
p_lis = np.array(list(map(int, input().split())))
org = np.array(range(1, n+1, 1))
diff = org - p_lis

if len(set(diff))<=4:
      print("YES")
else:
      print("NO")

Submission status: Wrong Answer

Solution code:
N = int(input())
arr = input().split(" ")

res = []

for i in range(1,N+1):
  if(int(arr[i-1]) != i):
    res.append(arr[i-1])

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

Submission status: Wrong Answer

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

if P[0] > P[N-1] and P[N-1] < P[2] and P[3] < P[0]:
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

n = int(input())
p_lis = np.array(list(map(int, input().split())))
org = np.array(range(1, n+1, 1))
diff = org - p_lis

if len(set(diff))<=3:
      print("YES")
else:
      print("NO")

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
p = [int(i) for i in input().split()]
ps = sorted(p)
x = [p[i]-ps[i] for i in range(len(p))]
tmp = []
c = collections.Counter(x)
if len(c) == 1:
  print('YES')
elif len(c) == 3:
  if x.count(0) == n-2:
    print('Yes')
  else:
    print('No')
else:
  print('NO')

Submission status: Wrong Answer

Solution code:
n = int(input())
listP = list(map(int,input().split()))
flg = 0
for i in (0, n - 2) :
    if listP[i] > listP[i+1]:
        flg+=1
if flg < 3 :
    print('YES')
else :
    print('NO')

Submission status: Wrong Answer

Solution code:
import numpy as np
def acinput():
    return list(map(int,input().split(" ")))


N=int(input())
p=acinput()

flg="YES"
bflg=False
for i in range(N-1):
    if p[i]!=(i+1):
        flg="NO"
        for j in range(i+1,N):
            if p[j]!=(j+1):
                if (p[i]==j+1) & (p[j]==i+1):
                    flg="YES"
                    bflg=True
                    break


    if bflg:
        break

print(flg)

Submission status: Wrong Answer

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

for i in range(0,a-1):
  if ay[i] - ay[i + 1] == -1:
    count += 1

if count == a-3 or count == a-1 :
  print('YES')
else:
  print('NO')

Submission status: Wrong Answer

Solution code:
N = int(input())
P = list(map(int,input().split()))
ANS = list(range(1,N+1))
count = 0 
dif = list()

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

if count == 0 :
	print('YES')
elif count == 2 :
	if sum(dif) != N+1:
		print('NO')
	else:
		print('YES')
else:
	print('NO')

Submission status: Wrong Answer

Solution code:
from copy import deepcopy

N = int(input())
ppp = list(map(int, input().split()))
ppp_sorted = sorted(ppp)

if ppp == ppp_sorted:
    print('YES')
    exit()
if N == 2:
    print('YES')
    exit()

for i in range(N):
    ppp_copy = deepcopy(ppp)
    ppp_copy[i], ppp_copy[-i-1] = ppp[-i-1], ppp[i]
    if ppp_copy == ppp_sorted:
        print('YES')
        exit()

print('NO')

Submission status: Wrong Answer

Solution code:
N = int(input())

li = list(map(int,input().split()))
count = 0
judge = True

for i in range(N-1):
    if (li[i] > li[i+1]):
        swp = li[i]
        index_swp = li.index(min(li[i+1:]))
        li[i] = li[index_swp]
        li[index_swp] = swp
        count = count + 1

        if(count >= 2):
            judge = False
            break
    

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

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int, input().split()))
sortedL = sorted(L, reverse=True)
count = 0

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

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

Submission status: Wrong Answer

Solution code:
import numpy as np

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

flip = np.sum(P==np.arange(1, 1+N))
if flip<=2:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
import copy

n=int(input())
ps=input().split()

sortedps = copy.deepcopy(ps)
sortedps.sort()

count = 0
for i in range(0,n-1):
    if count == 2:
        print('NO')
        exit()
    if ps[i] != sortedps[i]:
        count = 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()))
A=p.copy()
A.sort()
if p==A:
  print("YES")
else:
  i=p.index(max(p))
  for j in range(N-1,i+1,-1):
    if p[j]==p[i]:
      continue
    else:
      p[i],p[j]=p[j],p[i]
      break
  if p==A:
    print("YES")
  else:
    print("NO")

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

def main():
  n = int(input())
  input_line = list(map(int, input().split()))
	
  sorted_list = sorted(input_line)
  
  i = 0
  flag = 0
  flag2 = 0
  x = -1
  for l in input_line:
    if i == int(n / 2):
      break
    elif flag == 2:
      break
    elif (l + input_line[x]) != (n + 1):
      flag += 1
    
    if (input_line[x] - l) < 0:
      flag2 += 1
    
    x -= 1
    i += 1
  
  if (flag != 2) and (flag2 < 2):
    print("YES")
  else:
    print("NO")




if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
import copy

n=int(input())
ps=input().split()

sortedps = copy.deepcopy(ps)
sortedps.sort()

count = 0
for i in range(0,n-1):
    if count == 2:
        print('NO')
        exit()
    if ps[i] != sortedps[i]:
        count = count +1
if count == 3:
    print('NO')
    exit()

print('YES')

Submission status: Wrong Answer

Solution code:
x = int(input())
li = list(map(int,input().split()))
#print (x)
#print (li[2])


a = 0
for i in range(x-1):
	
	b = 0
	#print (li[i])
    
	if int(li[i]) < int(li[i+1]):
		b=b+1
	elif int(li[i]) > int(li[i+1]):
		a=a+1
	else:
		b=b+1
	#print(a)
	#print('endofloop')
    
#print(a)

if a < 3:
	print('YES')
else:
	print('NO')

Submission status: Wrong Answer

Solution code:
import sys

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

correct = [int(_) for _ in range(1,N+1)]

if p == correct:
    print('YES')
else:
    for i in range(N):
      for j in range(i+1,N):
        a = p[:]
        c = a[i]
        a[i] = a[j]
        a[j] = c
        print(a)
        if a == correct:
            print('YES')
            sys.exit()
    else:
        print('NO')

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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


wrong_p = []
wrong_idx = []
for i in range(N-1):
    if ps[i] > ps[i+1]:
        if len(wrong_p) > 0:
            wrong_p.append(ps[i+1])
            wrong_idx.append(i+1)
        else:
            wrong_p.append(ps[i])
            wrong_idx.append(i)
    if len(wrong_p) > 2:
        print("No")
        exit()

# print(wrong_p)
# print(wrong_idx)

if len(wrong_p) == 0:
    print("YES")
    exit()
if len(wrong_p) == 1:
    if wrong_idx[0] == N-2 and ps[0] == 1:
        print("YES")
    else:
        print("NO")
    exit()
if len(wrong_p) == 2:

    if wrong_p[0] == wrong_idx[1]+1:
        print("YES")
    else:
        print("NO")
    exit()
    # ps[wrong_idx[0]] = wrong_p[1]
    # ps[wrong_idx[1]] = wrong_p[0]
    # for i in range(N-1):
    #     if ps[i] > ps[i+1]:
    #         print("NO")
    #         exit()
    # print("YES")

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
p = [int(i) for i in input().split()]
ps = sorted(p)
x = [p[i]-ps[i] for i in range(len(p))]
tmp = []
c = collections.Counter(x)
if len(c) == 1:
  print('YES')
elif len(c) ==3:
  if sum(x) == 0:
    print('Yes')
  else:
    print('No')
else:
  print('NO')

Submission status: Wrong Answer

Solution code:
import numpy as np


n = int(input())
x = [int(i) for i in input().split()]
p = np.array(x)

max_index = p.argmax()
min_index = p.argmin()

if max_index != n - 1 and min_index != 0:
    tmp = p[max_index]
    p[max_index] = p[min_index]
    p[min_index] = tmp

for i in range(n):
    if i == 0:
        continue
    if p[i - 1] > p[i]:
        print('NO')
        exit()
print('YES')

Submission status: Wrong Answer

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

num = [i+1 for i in range(N)]

l = [p[n]-num[n] for n in range(N)]
l2 = [j for j in l if j!=0]
if len(l2) == 2:
    if sum(l2) == 0:
        print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
x = int(input())
li = list(map(int,input().split()))
#print (x)
#print (li[2])


a = 0
for i in range(x-1):
	
	b = 0
	#print (li[i])
    
	if int(li[i]) < int(li[i+1]):
		b=b+1
	elif int(li[i]) > int(li[i+1]):
		a=a+1
	else:
		b=b+1
	#print(a)
	#print('endofloop')
    
#print(a)

if a < 2:
	print('YES')
else:
	print('NO')

Submission status: Wrong Answer

Solution code:
N=int(input())
a=input().split()
for i in range (0,N):
  a[i]=int(a[i])
count=0
for i in range(0,N):
  if a[i]!=i+1:
    count=count+1
if count==2:
  print('Yes')
elif count==0:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
N = int(input())
P = list(map(int,input().split()))
Q = list(range(1,N+1))
J = [x - y for (x, y) in zip(P, Q)]
R = [i for i in J if i != 0]
print(R)
if len(R)<=2:
  print('YES')
else:
  print('NO')

Submission status: Wrong Answer

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


wrong_p = []
wrong_idx = []
for i in range(N-1):
    if ps[i] > ps[i+1]:
        if len(wrong_p) > 0:
            wrong_p.append(ps[i+1])
            wrong_idx.append(i+1)
        else:
            wrong_p.append(ps[i])
            wrong_idx.append(i)
    if len(wrong_p) > 2:
        print("No")
        exit()

# print(wrong_p)
# print(wrong_idx)

if len(wrong_p) == 0:
    print("YES")
    exit()
if len(wrong_p) == 1:
    if wrong_idx[0] == N-2:
        print("YES")
    else:
        print("NO")
    exit()
if len(wrong_p) == 2:

    if wrong_p[0] == wrong_idx[1]+1:
        print("YES")
    else:
        print("NO")
    exit()
    # ps[wrong_idx[0]] = wrong_p[1]
    # ps[wrong_idx[1]] = wrong_p[0]
    # for i in range(N-1):
    #     if ps[i] > ps[i+1]:
    #         print("NO")
    #         exit()
    # print("YES")

Submission status: Wrong Answer

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

q = list(sorted(p))

t = None

s = 0
e = -1
for i, (x, y) in enumerate(zip(p, q)):
    if x != y:
        t = x
        s = i + 1
        break

for j, (x, y) in enumerate(zip(p[:s:-1], q[:s:-1])):
    if x != y:
        e = - (j + 2)
        break

for k, (x, y) in enumerate(zip(p[s:e], q[s:e])):
    if x != y:
        print("NO")
        quit()

print("YES")

Submission status: Wrong Answer

Solution code:
import copy

n = int(input())
data = list(map(int, input().split()))
s_data = copy.deepcopy(data)
s_data.sort()
c = 0
p = []
for i in range(n):
    if data[i] != s_data[i]:
        p.append(i)
        c += 1

if c == 2 or c == 0:
    if data == s_data:
        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):
  if p[i]>p[i+1]:
    count=count+1
if count<2:
  print('YES')
else:
  print('NO')

Submission status: Wrong Answer

Solution code:
import copy

n=int(input())
ps=input().split()

sortedps = copy.deepcopy(ps)
sortedps.sort()

count = 0
for i in range(0,n-1):
    if count == 2:
        print('NO')
        exit()
    if ps[i] != sortedps[i]:
        count = count +1
print('YES')

Submission status: Wrong Answer

Solution code:
import sys

n = int(input())
p_lis = list(map(int, input().split()))
org = []
for i in range(1,n+1):
      org.append(i)

c = 0
for i in range(n):
      if p_lis[i] != org[i]:
            c += 1
            if c > 2:
                  print("NO")
                  sys.exit
print("YES")

Submission status: Wrong Answer

Solution code:
import copy

n = int(input())
data = list(map(int, input().split()))
s_data = copy.deepcopy(data)
s_data.sort()
c = 0
p = []
for i in range(n):
    if data[i] != s_data[i]:
        p.append(i)
        c += 1

if c == 2:
    # 入れ替えたときちゃんと合うか
    tmp = data[p[0]]
    data[p[0]] = data[p[1]]
    data[p[1]] = tmp 
    if data == s_data:
        print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
import numpy as np
def acinput():
    return list(map(int,input().split(" ")))


N=int(input())
p=acinput()

flg="YES"
for i in range(N-1):
    if p[i]!=(i+1):
        flg="NO"
        for j in range(i+1,N):
            if p[j]!=(j+1):
                if (p[i]==j+1) & (p[j]==i+1):
                    flg="YES"

print(flg)

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
A = map(int, raw_input().split())

def solve(N, A):
    problems = []
    for i in xrange(N - 1):
        if A[i] > A[i+1]:
            problems.append(i)

    if len(problems) < 2: return True
    if len(problems) > 2: return False
    i, j = problems
    for i0 in (i-1, i, i+1):
        for j0 in (j-1, j, j+1):
            if 0 <= i0 < N > j0 >= 0:
                A[i0], A[j0] = A[j0], A[i0]
                if all(A[k] < A[k+1] for k in xrange(N-1)):
                    return True
                A[i0], A[j0] = A[j0], A[i0]
    return False

print "YES" if solve(N, A) else "NO"

Submission status: Wrong Answer

Solution code:
N=int(input())
p=list(map(int,input().split()))
A=p.copy()
A.sort()
if p==A:
  print("YES")
else:
  i=p.index(max(p))
  p[i],p[N-1]=p[N-1],p[i]
  if p==A:
    print("YES")
  else:
    print("NO")

Submission status: Wrong Answer

Solution code:
N = int(input())
P = list(map(int, input().split()))
numOfOpe = 0
for i in range(N-1):
    if P[i+1] == P[i] + 1: continue
    else: numOfOpe += 1
    if numOfOpe > 2: break

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
a = int(input())
 
p = list(map(int, input().split()))
 
d = 0
for i in range(a):
  if not p[i] == a-i:
    d += 1
         
  
if d % 2 ==0:
  print("YES")
  
else:
  print("NO")

Submission status: Wrong Answer

Solution code:
n = input("")
n = int(n)
exa = input("").split(" ")
check = 0
for i in range(n-1):
    if int(exa[i+1]) == int(exa[i])+1:
        continue
    else:
        check += 1

if check == 2 or check == 0:
    ans = "YES"
else:
    ans = "NO"

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
x = input().rstrip().split()

cnt = 0
for i in range(N):
  for j in range(i+1,N):
    if x[i] > x[j]:
      cnt += 1
      
if cnt < 2:
  print('YES', end='')
else:
  print('NO', end='')

Submission status: Wrong Answer

Solution code:
N = int(input())
ps = [int(x) for x in input().split()]

for i in range(N):
    max_n = ps[i]
    index = i
    for j in range(i+1, N):
        if ps[j] > max_n:
            max_n = ps[j]
            index = j

    if index != i:
        tmp = ps[i]
        ps[i] = ps[index]
        ps[index] = tmp
        break
    
sorted_ps = sorted(ps, reverse=True)
if ps == sorted_ps:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
p = [int(i) for i in input().split()]
ps = sorted(p)
x = [p[i]-ps[i] for i in range(len(p))]
tmp = []
c = collections.Counter(x)
if len(c) == 1:
  print('YES')
elif len(c) ==3:
  for i in range(n):
    if x[i] != 0:
      tmp.append(x[i])
  if sum(tmp) == 0:
    print('Yes')
  else:
    print('No')
else:
  print('NO')

Submission status: Wrong Answer

Solution code:
def bubble_sort(arr):
    change = True
    flag=0
    while change:
        change = False
        for i in range(len(arr) - 1):
            if arr[i] > arr[i + 1]:
                arr[i], arr[i + 1] = arr[i + 1], arr[i]
                change = True
                flag+=1
    return arr,flag

N=int(input())
ps=list(int(i) for i in input().split())  

arr,flag=bubble_sort(ps)
if flag>=2:
 print("NO")
else:
 print("YES")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

YES = "YES"  # type: str
NO = "NO"  # type: str

def solve(N: int, p: "List[int]"):

    if check(p):
        print("YES")
        return

    p1 = p.copy()
    if p[0] > p[1] and p[N-2] > p[N-1]:
        p1[0] = p[N-1]
        p1[N-1] = p[0]

    if check(p1):
        print("YES")
        return

    p2 = p.copy()
    current = p[0]
    for i in range(1, len(p)):
        if current > p[i]:
            p2[i-1] = p[i]
            p2[i] = p[i-1]
        current = p[i]

    if check(p2):
        print("YES")
        return
    else:
        print("NO")

def check(p):
    current = p[0]
    for i in range(1, len(p)):
        if current > p[i]:
            return False
        current = p[i]

    return True

# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    p = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, p)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())

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

res = 0
for i,v in enumerate(p):
    if i < len(p) - 2:
        if p[i + 1] - p[i] != 1:
            res += 1

if res < 3:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

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

num = [i+1 for i in range(N)]

l = [p[n]-num[n] for n in range(N)]
if sum(l) == 0:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

YES = "YES"  # type: str
NO = "NO"  # type: str

def solve(N: int, p: "List[int]"):

    if check(p):
        print("YES")
        return

    p1 = p.copy()
    if p[0] > p[1] and p[N-2] > p[N-1]:
        p1[0] = p[N-1]
        p1[N-1] = p[0]

    if check(p1):
        print("YES")
        return

    p2 = p.copy()
    current = p[0]
    for i in range(1, len(p)):
        if current > p[i]:
            p2[i-1] = p[i]
            p2[i] = p[i-1]
        current = p[i]

    if check(p2):
        print("YES")
        return
    else:
        print("NO")

def check(p):
    current = p[0]
    for i in range(1, len(p)):
        if current > p[i]:
            return False

    return True

# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    p = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, p)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
nums = [int(N) for N in input().split()]
diff = 0

for i in range(N):
    if (i + 1) != nums[i]:
        diff += 1
    if diff >= 3:
        break

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

Submission status: Wrong Answer

Solution code:
import numpy as np
def acinput():
    return list(map(int,input().split(" ")))


N=int(input())
p=acinput()

flg="Yes"
for i in range(N-1):
    if p[i]!=(i+1):
        flg="No"
        for j in range(i+1,N):
            if p[j]!=(j+1):
                if (p[i]==j+1) & (p[j]==i+1):
                    flg="Yes"

print(flg)

Submission status: Wrong Answer

Solution code:
A = int(input())
re = 0
B = list(map(int, input().split()))
C = [i for i in range(1, A+1)]
for B, C in zip(B, C):
  if B != C:
    re += 1

if re >= 2:
  print('NO')
else:
  print('YES')

Submission status: Wrong Answer

Solution code:
import sys
n = int(input()) 
p = [int(r) for r in sys.stdin.read().split()]
for i, v in enumerate(p[:-1]):
    if p[i] > p[i + 1]:
        for j in range(i + 1, n - 1):
            if p[j] > p[j + 1]:
                if (i == 0 or p[i - 1] < p[j + 1]) and p[i + 1] > p[j + 1] and (j == n - 2 or p[j + 1] > p[i]) and p[j - 1] < p[i]:
                    print('YES')
                    quit()
                else:
                    print('NO')
                    quit()
            if j == n - 2:
                print('NO')
                quit()
    if i == n - 2:
        print('YES')
        quit()

Submission status: Wrong Answer

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

forward_buf = None
reverse_buf = None
for i in range(n):
    if i+1 != p[i]:
        forward_buf = p[i]
        break

for j in reversed(range(n)):
    if j+1 != p[j]:
        reverse_buf = p[j]
        break

if (p[i] == j+1 and p[j] == i+1) or (forward_buf==None and reverse_buf==None):
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

q = list(sorted(p))

t = None

s = 0
e = -1
for i, (x, y) in enumerate(zip(p, q)):
    if x != y:
        t = x
        s = i + 1
        break

for j, (x, y) in enumerate(zip(p[s::-1], q[s::-1])):
    if x != y:
        e = - (j + 2)
        break

for k, (x, y) in enumerate(zip(p[s:e], q[s:e])):
    if x != y:
        print("NO")
        quit()

print("YES")