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()))
tmp = 100

for i in range(len(p) - 1):
    for j in range(i+1, len(p)):
        if p[i] > p[j]:
            tmp = min(tmp, p[j])
    if tmp != 100:
        p[i], p[j] = p[j], p[i]
        break
if p == sorted(p):
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

count = 0
for n in range(N):
    if p[n] != q[n]:
        count += 1
if count==0 or count==2:
    print('YES')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
N = int(input())
P = [int(i) for i in input().split()]
P_sorted = sorted(P)
swap = 0
for p, s in zip(P, P_sorted):
    if p != s:
        swap += 1

ans = "YES" if swap <= 1 else "NO"

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

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

    c = 0
    for i, v in enumerate(p):
        if (i + 1) != v:
            c += 1
        if c > 2:
            print('NO')
    print('YES')

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

cnt = 0
for i, num in enumerate(p):
    if i + 1 != num:
        cnt += 1
if cnt == 0 or cnt == 2:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
n=int(input())
P=list(map(int,input().split()))
t=len(P)
m=0
for i in range(t):
  if P[i]!=P.index(i+1)+1:
    m+=1
if m<=2:
  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))
if p == q:
    print("YES")
    exit(0)
cnt = 0
for i in range(n):
    if p[i] != q[i]:
        cnt += 1
    t = i if cnt == 1 else 0
    if (cnt == 2 and p[t] != q[i]) or cnt > 2:
        print("NO")
        exit(0)
print("YES")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import copy
n = int(input())
L = list(map(int, input().split()))
flag = 1
if L == sorted(L):
  print('Yes')
  exit()
for i in range(n-1):
  for j in range(i+1, n):
    R = copy.copy(L)
    a = L[i]
    b = L[j]
    R[i] = b
    R[j] = a
    if R == sorted(R):
      flag *= 0
if flag == 0:
  print('YES')
else:
  print('NO')

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc143/tasks/abc143_b
from itertools import combinations
 
N = int(input())
P = list(map(int, input().split()))

ans = "No"

ansarray = sorted(P)

# 一致OK
if ansarray == P:
    ans = "Yes"

# ２つ違いをOK
count = 0
for i in range(N):
    if(P[i] != ansarray[i]):
        count = count + 1

if count < 3:
    ans = "Yes"

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
#もし最初に与えられていたリストが昇順(done)

#1番目とn番目の文字列を消去したリストを作成する。そのリストが昇順ならまずは第一段階クリア
#そして最初に与えられた文字のリストで、(<一番最後の文字> - <一番最初の文字>　+1)なら成立する。

#実装すれば、勝ちなはず。

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



#初期リストを昇順に(done)
ascending_order = P.sort()



#1番目と一番最後を削除したリスト
Test_P = P[1:N-1]

#TestPの昇順
ascending_TestP = Test_P.sort()

Check = (abs((P[-1] + P[0]) +1)) 

if P == ascending_order:
    print("YES")
elif Test_P != ascending_TestP:
    print("NO")
else:
    print("YES")

Submission status: Wrong Answer

Solution code:
#もし最初に与えられていたリストが昇順(done)

#1番目とn番目の文字列を消去したリストを作成する。そのリストが昇順ならまずは第一段階クリア
#そして最初に与えられた文字のリストで、(<一番最後の文字> - <一番最初の文字>　+1)なら成立する。

#実装すれば、勝ちなはず。

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



#初期リストを昇順に(done)
ascending_order = P.sort()



#1番目と一番最後を削除したリスト
Test_P = P[1:N-1]

#TestPの昇順
ascending_TestP = Test_P.sort()

Check = (abs((P[-1] + P[0]) +1)) 

if P == ascending_order:
    print("YES")
elif Test_P == ascending_TestP and Check == N:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
l=list(map(int, input().split()))
cnt=0
for i in range(N-1):
  if l[i+1] - l[i] != 1:
    cnt += 1
print('YES' if cnt < 3 else 'NO')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
p = list(map(int, input().split()))
lis = sorted(list(range(1, n+1)))
l = len(p)
cache = l
for k, m in zip(lis, p):
    if k != m:
        l -= 1

if cache - l == 2:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
N = int(input())
P = list(input().split())
Flag = True
E =[]
for i in range(0,N):
  a = int(P[i])
  if a != i+1:
    E.append(i)
if len(E) == 0:
  Flag = False
elif len(E) == 2:
  e1 = int(E[0])
  e2 = int(E[1])
  p1 = int(P[e1])
  p2 = int(P[e2])
  P[e1] = p2
  P[e2] = p1
  W = []
  for j in range(0,N):
    b = int(P[j])
    if b != j+1:
      W.append(j+1)
  if len(W) == 0:
    Flag = False
    

    
  
    
  
    
    
if Flag == True:
  print('No')
else:
  print('Yes')

Submission status: Wrong Answer

Solution code:
N = int(input())
P = list(input().split())
Flag = True
E =[]
for i in range(0,N):
  a = int(P[i])
  if a != i+1:
    E.append(i)
if len(E) == 0:
  Flag = False
elif len(E) == 2:
  e1 = int(E[0])
  e2 = int(E[1])
  p1 = int(P[e1])
  p2 = int(P[e2])
  P[e1] = p2
  P[e2] = p1
  W = []
  for j in range(0,N):
    b = int(P[j])
    if b != j+1:
      W.append(j+1)
  if len(W) == 0:
    Flag = False
    

    
  
    
  
    
    
if Flag == True:
  print('No')
else:
  print('Yes')

Submission status: Wrong Answer

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

list_p = [i for i in range(1,N+1) ]
flag = 0

if p == list_p:
    print("Yes")

else:
    for i in range(N):
        for j in range(i+1,N):
            p[i],p[j] = p[j],p[i]

            if p == list_p:
                flag = 1
                break

            p[i],p[j] = p[j],p[i]
    
        if flag == 1:
            break

    print("Yes" if flag == 1 else "No")

Submission status: Wrong Answer

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

my_array = list(range(1,N+1))
ans_array = []
num = 0

for i in range(0,N):
	num = p_array[i] - my_array[i]
	ans_array.append(num)

print(ans_array)
new_lst = [e for e in ans_array if e != 0]
if len(new_lst)==0:
	ans = "YES"
elif len(new_lst)==2:
	ans = "YES"
else:
	ans = "NO"
print(ans)
print(new_lst)

Submission status: Wrong Answer

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

my_array = list(range(1,N+1))
ans_array = []
num = 0

for i in range(0,N):
	num = p_array[i] - my_array[i]
	ans_array.append(num)
ans_num = set(ans_array)
if len(ans_num)==1:
	ans = "YES"
elif len(ans_num)==3:
	ans = "YES"
else:
	ans = "NO"
print(ans)

Submission status: Wrong Answer

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

ans = []
for i in range(1,n+1):
  ans.append(i)

  

for i in range(n):
  for j in range(n):
    a[i] = p[j]
    a[j] = p[i]
    if a == ans:
      print('YES')
      exit()
    else:
      a = list(p)
    print(p)    
      
      
      
    
print('NO')

Submission status: Wrong Answer

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

    if 2 >= n or n >= 50:
        return

    for i in p:
        if isinstance(i, int) == False:
            return

    num = 0

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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

    if 2 >= n or n >= 50:
        return

    for i in p:
        if isinstance(i, int) == False:
            return

    num = 0

    for i in range(len(p)):
        if i+1 != p[i]:
            num += 1
    
    if num == 2:
        print('YES')
    else:
        print('NO')


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

    if 2 >= n or n >= 50:
        return

    for i in p:
        if isinstance(i, int) == False:
            return

    num = 0

    for i in range(len(p)):
        if i+1 != p:
            num += 1
    
    if num == 2:
        print('YES')
    else:
        print('NO')


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
p=[int(i) for i in input().split()]
a=0
for i in range(n):
  if p[i]==i+1:
    continue
  elif p[p[i]-1]==i+1:
    a+=1
    continue
  else:
    print('NO')
    exit()
if a<=2:
  print('YES')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
p = [num for num in map(int, input().split(' '))]

miss = []

ans = 'YES'

for i in range(n):
  if i+1 != p[i]:
    miss.append(i)
  
  if len(miss) > 2:
    ans = 'NO'
    break
  
  if len(miss) == 2:
    first_index = miss[0]
    first_value = p[first_index]
    
    if first_index+1 != p[i] or first_value != i+1:
      ans = 'NO'
      break

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
p = [num for num in map(int, input().split(' '))]

miss = []

ans = 'YES'

for i in range(n):
  if i+1 != p[i]:
    miss.append(p[i])
  
  if len(miss) > 2:
    ans = 'NO'
    break
  
  if len(miss) == 2:
    first = miss[0]
    if first != i+1:
      ans = 'NO'
      break

print(ans)

Submission status: Wrong Answer

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

res = "Yes"
if list(range(1, n+1)) == p:
  res = "Yes"
else:
  count = 0
  for n_e, p_e in zip(range(1,n+1), p):
    if n_e != p_e:
      count += 1
    if count == 3:
      res = "No"
      break


print(res)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
*P, = map(int, input().split())
cnt = 0
for i, p in enumerate(P):
    if i + 1 != p:
        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()]
ans = 'YES'
k = 0
for i in range(n):
    if p[i] != i + 1:
        if k == 1:
            ans = 'NO'
            break
        else:
            if p[p[i] - 1] == i + 1:    
                k = 1
            else:
                ans = 'NO'
                break

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
p = [int(i) for i in input().split()]
ans = 'YES'
for i in range(n):
    k = 0
    if p[i] != i + 1:
        if k == 1:
            ans = 'NO'
            break
        else:
            if p[p[i] - 1] == i + 1:    
                k = 1
            else:
                ans = 'NO'
                break

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
p = [int(i) for i in input().split()]
ans = 'YES'
for i in range(n):
    k = 0
    if p[i] != i + 1:
        if k == 1:
            ans = 'NO'
        else:
            if p[p[i] - 1] == i + 1:    
                k = 1
            else:
                ans = 'NO'

print(ans)

Submission status: Wrong Answer

Solution code:
# 2019-11-15 14:37:47(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def main():
    n, *p = [int(x) for x in sys.stdin.read().split()]

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

    print('Yes' if p == list(range(1, n+1)) else 'No')


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N=int(input())
P=list(map(int,input().split(' ')))
count=0
flg=1

for i in range(N):
  if P[i]!=i+1:
    if count==0:
      if P[P.index(i+1)]!=i+1:
        if flg:
          print("NO")
          flg=0
      else:
        P[i],P[P.index(i+1)]=P[P.index(i+1)],P[i]
        count+=1
    else:
      if flg:
        print("NO")
        flg=0
        
if flg:
  print("YES")

Submission status: Wrong Answer

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

import math
for i in range(math.ceil(N / 2)):
	if p[i] != i + 1:
		j = p.index(i + 1)
		p[i], p[j] = p[j], p[i]
		break
		
if p == [i for i in range(1, N + 1)]:
	print('YES')
else:
	print('NO')

Submission status: Wrong Answer

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

import math
for i in range (math.ceil(N / 2)):
	if p[i] != i + 1:
		j = p.index(i + 1)
		p[i], p[j] = p[j], p[i]
		break
		
if p == [i for i in range(1, N + 1)]:
	print('YES')
else:
	print('NO')

Submission status: Wrong Answer

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

import math
for i in range (math.ceil(N / 2)):
	if p[i] != i + 1:
		j = p.index(i + 1)
		p[i], p[j] = p[j], p[i]
		break
		
print(p)
		
if p == [i for i in range(1, N + 1)]:
	print('YES')
else:
	print('NO')

Submission status: Wrong Answer

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

cnt = 0

for i in range(n):
    if ls_p[i] != 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()))
count = 0
for i in range(N):
    if i + 1 != p[i]:
        count += 1
out = "No"
if count == 0 or count == 2:
    out = "Yes"

print(out)

Submission status: Wrong Answer

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

cnt = 0
res = 'YES'
for i in range(n-1):
    if p[i] > p[i+1]:
        cnt+=1
    if cnt == 2:
        res = 'NO'
        
print(res)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N=int(input())
false=0
p=[int(N) for N in input().split()]
for i in range(N):
     if p[i]!=i+1:
          false+=1
if false>2:
     print("No")
else:
     print("Yes")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
P = list(map(int,input().split()))
count = 0
for i in range(N):
    if not i+1==P[i]:
        count+=1
print(count)
if count>=3:
    print('NO')
else:
    print('YES')

Submission status: Wrong Answer

Solution code:
n=list(map(int,list(open(0))[1].split()))
m=sorted(n)
a=b=0
for _ in range(len(n)):a+=0if n[_]==m[_]else 1
b=1if a>2else 0
print('YNeos'[b::2])

Submission status: Wrong Answer

Solution code:
N = int( input() )
p_list = list( map( int, input().split() ) )
t_list = p_list[:]
p_list.sort()
c = 0
for i in range(N):
    if p_list[i] != t_list[i]:
        c += 1
if c == 0 or c == 2:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
N = int( input() )
p_list = list( map( int, input().split() ) )
t_list = p_list[:]
p_list.sort()
c = 0
print(p_list)
for i in range(N):
    if p_list[i] != t_list[i]:
        c += 1
if c == 0 or c == 2:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
N = int( input() )
p_list = list( map( int, input().split() ) )
t_list = p_list[:]
p_list.sort()
c = 0
print(p_list)
for i in range(N):
    if p_list[i] != t_list[i]:
        c += 1
if c == 0 or c == 2:
    print("Yes")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = []

for i in range(n):
    ans.append(p[i] - (i + 1))

ans = list(filter(lambda x: (x != 0), ans))

if (len(ans) == 2 and sum(ans) == 0):
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

mistake=[]
for i in range(n):
  if array[i]!=i+1:
    mistake.append([i+1,array[i]])

ans='Yes'
k=len(mistake)
if k>2:
  ans='No'
elif k==2:
  if mistake[0][0]!=mistake[1][1]:
    ans='No'

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

count = 0
flag = True
for i in range(n-1):
    if pn[i] > pn[i+1]:
        for j in range(i+1, n-1):
            if pn[j] > pn[j+1]:
                tmp = pn[i]
                pn[i] = pn[j+1]
                pn[j+1] = tmp
                break
        count +=1
        if count > 1:
            flag = False
if flag:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

pnSort = sorted(pn)

if pn == pnSort:
    print("Yes")
else:
    change = []
    index = 0
    for i,j in zip(pn, pnSort):
        if i != j:
            change.append(index)
            if len(change) == 2:
                break
        index += 1

    tmp = pn[change[0]]
    pn[change[0]] = pn[change[1]]
    pn[change[1]] = tmp
    
    if pn == pnSort:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())
sum = 0
sum_1 = 0
sum_2 = 0
p = list(map(int, input().split()))
for i in range(N):
  if i < N-1:
    if p[i+1] != p[i] + 1:
      sum += 1
      if i < N-2:
        if p[i+2] != p[i+1] + 1:
          sum_1 += 1 
        if i == 0 or i == N-3:
          sum_2 += 1 
if sum == 0 or sum == 1 or sum ==2:
  print('YES')
elif sum == 3 and sum_1 == 1 and sum_2 != 1:
  print('YES')
elif sum == 4 and sum_1 == 2 and sum_2 != 2:
  print('YES')
else:
  print('NO')

Submission status: Wrong Answer

Solution code:
N = int(input())
sum = 0
sum_1 = 0
sum_2 = 0
p = list(map(int, input().split()))
for i in range(N):
  if i < N-1:
    if p[i+1] != p[i] + 1:
      sum += 1
      if i < N-2:
        if p[i+2] != p[i+1] + 1:
          sum_1 += 1 
        if i == 0 or i == N-3:
          sum_2 += 1 
if sum == 0 or sum == 1 or sum ==2:
  print('YES')
elif sum == 3 and sum_1 == 1:
  print('YES')
elif sum == 4 and sum_1 == 2 and sum_2 != 2:
  print('YES')
else:
  print('NO')

Submission status: Wrong Answer

Solution code:
N = int(input())
sum = 0
sum_1 = 0
p = list(map(int, input().split()))
for i in range(N):
  if i < N-1:
    if p[i+1] != p[i] + 1:
      sum += 1
      if i < N-2:
        if p[i+2] != p[i+1] + 1:
          sum_1 += 1  
if sum == 0 or sum == 1 or sum ==2:
  print('YES')
elif sum == 3 and sum_1 == 1:
  print('YES')
elif sum == 4 and sum_1 == 2:
  print('YES')
else:
  print('NO')

Submission status: Wrong Answer

Solution code:
N = int(input())
sum = 0
p = list(map(int, input().split()))
for i in range(N):
  if i < N-1:
    if p[i+1] != p[i] + 1:
      sum += 1
if sum == 0 or sum == 1 or sum ==2:
  print('YES')
elif len(p) > 5:
  if sum == 4:
    print('YES')
else:
  print('NO')

Submission status: Wrong Answer

Solution code:
N = int(input())
sum = 0
p = list(map(int, input().split()))
for i in range(N):
  if i < N-1:
    if p[i+1] != p[i] + 1:
      sum += 1
if sum == 0 or sum == 1 or sum ==2:
  print('YES')
elif len(p) > 5:
  if sum == 4:
    print('Yes')
else:
  print('NO')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
p = list(map(int, input().split()))
yn = False
for i in range(N):
  for j in range(N-i-1):
    hika = list(p)
    hika[j+i+1] = p[i]
    hika[i] = p[j+i+1]
    print(hika)
    if hika == sorted(p):
      yn = True
      break
if yn == True:
  print('YES')
else:
  print('NO')

Submission status: Wrong Answer

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

a=p.index(min(p))
b=p[a]
p[a]=p[0]
p[0]=b

if all(p[i] < p[i+1] for i in range(n-1)):
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
p = [int(i) for i in input().split()]
check = 0
pp = sorted(p)
for i in range(N):
    if p[i] != pp[i]:
        check += 1

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

if count == 0 or count == 2 or count == 3:
  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 (int(p[i])+1) != int(p[i+1]):
    count += 1

if count == 0 or count == 3:
  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 (int(p[i])+1) != int(p[i+1]):
    print(int(p[i]),int(p[i+1]))
    count += 1

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

if count == 0 or count == 3:
  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 (int(p[i])+1) != int(p[i+1]):
    print(int(p[i]),int(p[i+1]))
    count += 1

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

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

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

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

num=[]
flag=False
for j in range(N):
    num.append(j+1)
for i in range(N):
    if num[i]==p[i]:
        flag=True
    else:
        flag=False
        break
if flag==True:
    print("YES")
elif flag==False:
    p[0],p[N-1]=p[N-1],p[0]
    for i in range(N):
        if num[i]==p[i]:
            flag=True
        else:
            flag=False
            break
    if flag==True:
        print("YES")
    else:
        print("NO")

Submission status: Wrong Answer

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

num=[]
flag=False
for j in range(N):
    num.append(j+1)
for i in range(N):
    if num[i]==p[i]:
        flag=True
    else:
        flag=False
if flag==True:
    print("YES")
elif flag==False:
    p[0],p[N-1]=p[N-1],p[0]
    for i in range(N):
        if num[i]==p[i]:
            flag=True
        else:
            flag=False
    if flag==True:
        print("YES")
    else:
        print("NO")

Submission status: Wrong Answer

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

cnt = 0

Q = sorted(P)

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

if cnt==0 or cnt==2:
    print('yes')
else:
    print('no')

Submission status: Wrong Answer

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

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

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