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:
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")

Submission status: Wrong Answer

Solution code:

s = input()
s = int(s)

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

count = 0

for val in range(s):
    if val+1 != nums[val]:
        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()))
err = 0
for i in range(N):
  if p[i]!=i:
    err += 1
if err == 0:
  print("YES")
elif err == 2:
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

Solution code:
n = input()
li = list(map(int,input().split()))
false = 0
for i in range(int(n)):
    if (i+1) != li[i]:
        false += 1
if false == 0 or false == 2:
    print('YES')
else:
    print('N0')

Submission status: Wrong Answer

Solution code:
n = input()
li = list(map(int,input().split()))
false = 0
for i in range(int(n)):
    if i != li[i]:
        false += 1
if false == 0 or false == 2:
    print('YES')
else:
    print('N0')

Submission status: Wrong Answer

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

# 隣り合う要素同士の昇順判定リスト
ret = []

for i in range(n-1):
  if p[i] < p[i+1]:
    ret.append(True)
  else:
    ret.append(False)

# Falseが0の場合
if not False in ret:
  print('YES')
  sys.exit()
  
# Falseが3以上の場合
if ret.count(False) >= 3:
  print('NO')
  sys.exit()
  
# Falseが1の場合
if ret.count(False) == 1:
  i = ret.index(False)
  if i == 0:
    if p[i] < p[i+2]:
      print('YES')
    else:
      print('NO')
    sys.exit()
    
  if i == n-1:
    if p[i-1] < p[i+1]:
      print('YES')
    else:
      print('NO')
    sys.exit()
    
  if i != 0 and i != n-1:
    if p[i-1] < p[i+1] and p[i] < p[i+2]:
      print('YES')
    else:
      print('NO')
    sys.exit()

# Falseが2の場合
if ret.count(False) == 2:
  idxs = [i for i, r in enumerate(ret) if r is False]
  i = idxs[0]
  j = idxs[1]
  if i == 0 and j == n-1:
    if p[j] < p[i+1] and p[j-1] < p[i]:
      print('YES')
    else:
      print('NO') 
  elif i == 0:
    if  p[j] < p[i+1] and p[j-1] < p[i] and p[i] < p[j+1]:
      print('YES')
    else:
      print('NO')
  elif j == n-1:
    if p[j-1] < p[i] and p[i-1] < p[j] and p[j] < p[i+1]:
      print('YES')
    else:
      print('NO')
  else:
    if p[i-1] < p[j] and p[j] < p[i+1] and p[j-1] < p[i] and p[i] < p[j+1]:
      print('YES')
    else:
      print('NO')

Submission status: Wrong Answer

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


for i in range(N//2):
  if p[i] + p[N - 1 - i] != N + 1 or p[i] > p[N - 1 - i]:
    count += 1
  if count == 2:
    print("NO")
    break
if count != 2:
  print("YES")

Submission status: Wrong Answer

Solution code:
N = int(input())
p = input().split()
for i in range(N):
  p[i] = int(p[i])
count = 0
for i in range(N//2):

  if p[i] + p[N - 1 - i ] != N + 1:
    count += 1
  if count == 2:
    print("NO")
    break
if count != 2:
  print("YES")

Submission status: Wrong Answer

Solution code:
N = int(input())
P = list(map(int, input().split()))
count = sum([index + 1 == num for index, num in enumerate(P)])
if count <= 2:
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())
P = list(map(int, input().split()))
swap = 0
for pre, cur in zip(P[:-1], P[1:]):
    if cur - pre != 1:
        if swap == 0:
            swap = 1
        elif swap == 1:
            swap = 2
        else:
            print("NO")
            sys.exit(0)
print("YES")

Submission status: Wrong Answer

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


if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
a = int(input())
b = list(map(int,input().split()))
c = b.copy()
c.sort()
count = 0
for i in range(a):
    if not b[i] == c[i]:
        count += 1
if count == 2:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

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

if N <= 1:
  print('NO')
  
if N == 2 and nums[1] - nums[0] == 1:
  print('YES')
  
diff = [n - i - 1 for i, n in enumerate(nums) if n - i - 1 != 0]
if len(diff) == 2 and sum(diff) == 0:
  print('YES')
else:
  print('NO')

Submission status: Wrong Answer

Solution code:
import sys

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

sorted_l = sorted(l)

wrong = 0
for i in range(list_len):
    if l[i] != sorted_l[i]:
        wrong += 1
        if wrong > 2:
            print("NO")
            sys.exit(0)

print("YES")

Submission status: Wrong Answer

Solution code:
num_list = [int(_) for _ in input().split()]
 
count = 0
 
for i in range(0, len(num_list)):
  if num_list[i] != i+1:
    count += 1
    
if count <= 2:
  print('YES')
else:
  print('NO')

Submission status: Wrong Answer

Solution code:
num_list = [int(i) for i in input().split()]
 
count = 0
 
for i in range(0, len(num_list)):
  if num_list[i] != i+1:
    count += 1
    
if count <= 2:
  print('YES')
else:
  print('NO')

Submission status: Wrong Answer

Solution code:
num_list = [int(i) for i in input().split()]
 
count = 0

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

Submission status: Wrong Answer

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

count = 0
for i in range(0, len(num_list)):
  if num_list[i] != i+1:
    count += 1
    if count > 2:
      print('NO')

    if i == len(num_list)-1:
      print('YES')

Submission status: Wrong Answer

Solution code:
import sys

i = list(map(int, input().split()))
count = 0
for n in range(len(i)):
    if i[n] != n + 1:
        count = count + 1
        if count > 2:
            print("NO")
            sys.exit()

print("YES")

Submission status: Wrong Answer

Solution code:
import sys

i = list(map(int, input().split()))
count = 0
for n in range(len(i)):
    if i[n] != n + 1:
        count = count + 1
        if count > 2:
            print("NO")

print("YES")

Submission status: Wrong Answer

Solution code:
N = int(input())
p = [int(n) for n in input().split()]
X = [n for n in range(1, N+1)]
ans = sum([0 if p==x else 1 for p,x in zip(p,X)])
print("Yes" if ans <= 2 else "No")

Submission status: Wrong Answer

Solution code:
N = int(input())
p = [int(n) for n in input().split()]
X = [n for n in range(1, N+1)]
print("Yes" if sum([0 if p==X else 1 for p,x in zip(p,X)]) <=2 else "No")

Submission status: Wrong Answer

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

inds = []
for i, num in enumerate(a):
  if num != (i+1):
    inds.append(i)

if len(inds) > 2:
  print("NO")
else:
  print("YES")

Submission status: Wrong Answer

Solution code:
n = int(input())
nlst = list(map(int, input().split()))
prb = 0
det = 0

for num in range(len(nlst)):
  cnt = num
  if nlst[prb] > nlst[cnt]:
    det += 1
  prb = num

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

Submission status: Wrong Answer

Solution code:
N = input()
list = [int(i) for i in input().split()]
new_list = sorted(list)
score = 0
change_list = []
for i in range(0, int(N)):
    if list[i] != new_list[i]:
        score =+ 1
if score == 0 or 2:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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

score = 0
change_list = []
for i in range(0, int(N)-1):
    if list[i] > list[i+1]:
        score =+ 1
        change_list.append(i)
if score == 0 or 2:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
nN = int(input())

Tmp = []
Tmp = input().rstrip().split(' ')

nData = [0 for i in range(nN)]

for i in range(nN):
  nData[i] = int(Tmp[i])

nFlag = 0
nCnt = 0

for i in range(nN):
  nTmp = i + 1
  if nData[i] != nTmp:
    nCnt += 1
    nTmp2 = nData[i] - 1
    nTmp3 = nData[nTmp2]
    if nTmp3 != nTmp:
      nCnt += 1
  
  if nCnt >= 2:
    break
    
  
if nCnt < 2:
  print('YES')
else:
  print('NO')

Submission status: Wrong Answer

Solution code:
nN = int(input())

Tmp = []
Tmp = input().rstrip().split(' ')

nData = [0 for i in range(nN)]

for i in range(nN):
  nData[i] = int(Tmp[i])

nFlag = 0
nCnt = 0

for i in range(nN-1):
  nTmp = i + 1
  if nData[i] != nTmp:
    nCnt += 1
    nTmp2 = nData[i] - 1
    nTmp3 = nData[nTmp2]
    if nTmp3 != nTmp:
      nCnt += 1
  
  if nCnt >= 2:
    break
    
  
if nCnt < 2:
  print('YES')
else:
  print('NO')

Submission status: Wrong Answer

Solution code:
nN = int(input())

Tmp = []
Tmp = input().rstrip().split(' ')

nData = [0 for i in range(nN)]

for i in range(nN):
  nData[i] = int(Tmp[i])

nFlag = 0
nCnt = 0

for i in range(nN-1):
  nTmp = i + 1
  if nData[i] != nTmp:
    nCnt += 1
    nTmp2 = nData[i] - 1
    nTmp3 = nData[nTmp]
    if nTmp3 != nTmp:
      nCnt += 1
  
  if nCnt >= 2:
    break
    
  
if nCnt < 2:
  print('YES')
else:
  print('NO')

Submission status: Wrong Answer

Solution code:
nN = int(input())

Tmp = []
Tmp = input().rstrip().split(' ')

nData = [0 for i in range(nN)]

for i in range(nN):
  nData[i] = int(Tmp[i])

nFlag = 0
nCnt = 0

for i in range(nN-1):
  if nData[i] > nData[i+1]:
    nCnt += 1

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

Submission status: Wrong Answer

Solution code:
import itertools
import copy
n = int(input())
ps = list(map(int, input().split()))

c = list(itertools.combinations(range(n), 2))

ps_sort = sorted(ps)
if ps == ps_sort:
  print('Yes')
  exit()
else:
  for i in range(len(c)):
    nps  = copy.copy(ps)
    nps[c[i][0]], nps[c[i][1]] = nps[c[i][1]], nps[c[i][0]]
    if nps == ps_sort:
      print('YES')
      exit()
  else:
    print('NO')

Submission status: Wrong Answer

Solution code:
import itertools
import copy
n = int(input())
ps = list(map(int, input().split()))

c = list(itertools.combinations(range(n), 2))

ps_sort = sorted(ps)

for i in range(len(c)):
  nps  = copy.copy(ps)
  nps[c[i][0]], nps[c[i][1]] = nps[c[i][1]], nps[c[i][0]]
  if nps == ps_sort:
    print('YES')
    exit()
else:
  print('NO')

Submission status: Wrong Answer

Solution code:
n= int(input())

a=list(map(int, input().split()))
correct=sorted(a)

p=0
for i in range(n-1):
  for j in range(n-i-1):
    a[i], a[n-j-1] = a[n-j-1], a[i]
    if a == correct:
      p += 1
      
    else:
      pass
    a[i], a[n-j-1] = a[n-j-1], a[i]
    
if p == 1:
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

Solution code:
n= int(input())

a=list(map(int, input().split()))
correct=sorted(a)

p=0
for i in range(n-1):
  for j in range(n-i-1):
    a[i], a[n-j-1] = a[n-j-1], a[i]
    if a == correct:
      p += 1
      
    else:
      pass
    a[i], a[n-j-1] = a[n-j-1], a[i]
    
print(p)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a=list(map(int,input().split()))
b=[0]*n
for i in range(n):
  b[i]=a[i]-sorted(a)[i]
if sum(b)==0:
  print('YES')
else:
  print('NO')

Submission status: Wrong Answer

Solution code:
n = int(input())
a=list(map(int,input().split()))
b=[0]*n
for i in range(n):
  b[i]=a[i]-sorted(a)[i]
if sum(b)==0:
  print('YES')
else:
  prnt('NO')

Submission status: Wrong Answer

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

d = 0
for i in range(N-1):
    S = abs(P[i+1]-P[i])
    if S != 1:
        d=d+1

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

Submission status: Wrong Answer

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

s_p=sorted(p, reverse=True)

cnt=0

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

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

Submission status: Wrong Answer

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

s_p=sorted(p, reverse=True)

cnt=0

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

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

Submission status: Wrong Answer

Solution code:
input_arr = [input() for i in range(2)]
N = input_arr[0]
p_arr = input_arr[1].split(' ')

k = 0
for i in range(len(p_arr)):
    if int(p_arr[i]) == i + 1:
        pass
    else:
        k += 1
if k < 2:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
input_arr = [input() for i in range(2)]
N = input_arr[0]
p_arr = input_arr[1].split(' ')

k = 0
for i in range(len(p_arr)):
    if int(p_arr[i]) == i + 1:
        pass
    else:
        k += 1
print(k)
if k < 2:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
input_arr = [input() for i in range(2)]
N = input_arr[0]
p_arr = input_arr[1].split(' ')

for i in range(len(p_arr)):
    k = 0
    if int(p_arr[i]) == i + 1:
        pass
    else:
        k += 1
if k < 2:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
input_arr = [input() for i in range(2)]
N = input_arr[0]
p_arr = input_arr[1].split(' ')

for i in range(len(p_arr)):
    k = 0
    if int(p_arr[i]) == i + 1:
        pass
    else:
        k += 1
print(k)
if k < 2:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
input_arr = [input() for i in range(2)]
N = input_arr[0]
p_arr = input_arr[1].split(' ')

for i in range(len(p_arr)):
    k = 0
    if int(p_arr[i]) == i + 1:
        pass
    else:
        k += i

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

Submission status: Wrong Answer

Solution code:
input_arr = [input() for i in range(2)]
N = input_arr[0]
p_arr = input_arr[1].split(' ')

for i in range(len(p_arr)):
    k = 0
    if int(p_arr[i]) == i:
        pass
    else:
        k += i
if k < 2:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
input_arr = [input() for i in range(2)]
N = input_arr[0]
p_arr = input_arr[1].split(' ')

for i in range(len(p_arr)):
    k = 0
    if int(p_arr[i]) == i:
        pass
    else:
        k += i
if k <= 2:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
p = list(map(int, input().split()))
# print(n)
# print(p)
import numpy as np
a = list(range(n+1))
a.pop(0)
# print(a)
d = np.array(p) - np.array(a)
# print(d)
z = np.count_nonzero(d)
if z == 2:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
a=[]


N = int(input())
a =[int(i) for i in input().split()]
a = np.array(a).astype(int)
a = np.where( (a-np.sort(a)) != 0)
if len(a[0]) > 3:
	print("NO")
else:
	print("YES")

exit()

Submission status: Wrong Answer

Solution code:
n = int(input())
p = list(map(int,input().split()))
check = {}
cnt = 0
ans = [i for i in range(n)]
for i in range(n):
    if(p[i]==ans[i]+1):
        continue
    elif(p[i]!=ans[i]):
        check[i] = p[i]
        if(cnt<3):
            cnt += 1
        else:
            break
if(cnt==0):
    print("Yes")
elif(cnt==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()))
print(n)

p2 = p.copy()
p2.sort()

p = np.asarray(p)
p2 = np.asarray(p2)
p3 = [p!=p2]
c = np.count_nonzero(p3)
if c == 2 or c == 0:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
N = int(input())
L = input()

n = 0
for i in range(N):
  if L[i] > L[i+1]:
    n += 1

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

Submission status: Wrong Answer

Solution code:
N = int(input())
L = input()

n = 0
for i in range(N):
  if L[i] > L[i+1]:
    n += 1

if n == 1 or n == 0:
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

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

diff = 0
for p, sp in zip(P, sort_P):
    if p != sp:
        diff += 1
print(diff)
if diff == 2 or diff == 0:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

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

cnt = 0
for i in range(N):
  if num_list[i]!=i+1:
    cnt+=1
  if cnt>2:
    print("NO")
    break
  if i==N:
    print("YES")

Submission status: Wrong Answer

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

f = False
for i in range(n-1):
    for j in range(i+1, n):
        q = p[:]
        b = q.pop(j)
        a = q.pop(i)
        q.insert(i, b)
        q.insert(j, a)
        r = sorted(q[:])
        if q == r:
            f = True
            break
    if f:
        break

if p == sorted(p):
    f =True

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

Submission status: Wrong Answer

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

count = 0

for p,n in zip(ps,range(1,N+1)):
    if p != n:
        count += 1
if count == 2:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

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

count = 0

for p,n in zip(ps,range(N)):
    if p != n:
        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()))
ps = sorted(p)
import sys
for i in range(N):
    for j in range(i+1,N):
        tmp = p[:i] + [p[j]] + p[i+1:j] + [p[i]]
        if tmp == ps:
            print('YES')
            sys.exit()
        
print('NO')

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

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

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

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

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

Submission status: Wrong Answer

Solution code:
# stdin
INPUT_SENTENCES = 2
ss = [input() for i in range(INPUT_SENTENCES)]
N = int(ss[0])
p = list(map(lambda x: int(x), ss[1].split()))
rev_index = []
for i in range(N-1):
    if p[i] > p[i+1]:
        if len(rev_index) > 0:
            rev_index.append(i+1)
        else:
            rev_index.append(i)
if len(rev_index) != 2:
    print("NO")
elif len(rev_index) > 0:
    p[rev_index[0]], p[rev_index[1]] = p[rev_index[1]], p[rev_index[0]]
if p == list(range(1,N+1)):
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
# stdin
INPUT_SENTENCES = 2
ss = [input() for i in range(INPUT_SENTENCES)]
N = int(ss[0])
p = list(map(lambda x: int(x), ss[1].split()))
rev_index = []
for i in range(N-1):
    if p[i] > p[i+1]:
        if len(rev_index) > 0:
            rev_index.append(i+1)
        else:
            rev_index.append(i)
if len(rev_index) % 2 == 1:
    print("NO")
elif len(rev_index) > 0:
    p[rev_index[0]], p[rev_index[1]] = p[rev_index[1]], p[rev_index[0]]
if p == list(range(1,N+1)):
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

c = 0
for i, v in enumerate(arr):
  if i+1==v:
    c += 1

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

Submission status: Wrong Answer

Solution code:
def quicksort_count(arg):
    left = []
    right = []

    if len(arg)<=1:
        return arg

    p = random.choice(arg)
    p_count = 0
    
    for ele in arg:
        if ele < p:
            left.append(ele)
        elif ele > p:
            right.append(ele)
        else:
            p_count+=1
    left = quicksort_count(left)
    right = quicksort_count(right)
    return left + [p]*p_count + right

import random
N=int(input())
p = [int(x) for x in input().split()]
k=0

for i in range(N):
    if p[i]!=i:
        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()))
judge = 0
for i in range(N):
  if (p[i] == i):
    None
  else:
    judge += 1
if judge <= 2:
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
Y = [int(x) for x in input().split()]
Y_ = Y.copy()
Y_.sort()
test = [Y[i] == Y_[i] for i in range(len(Y))]
if test.count(False) <= 2:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())

p = input().split()

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

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())

p = input().split()

p_sort = sorted(p)

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())

p = input().split()

p_sort = sorted(p)

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

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

Submission status: Wrong Answer

Solution code:
n=input()
arr=map(int,raw_input().split())
na=[0]*(n+1)
for i in range(n):
    na[arr[i]]=i+1
ans='YES'
for i in range(1,n+1):
    if na[i]==i or i==na[na[i]]:
        continue
    else:
        ans='NO'
        break
print ans

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

def shou(a):
    for i in range(len(a)-1):
        if a[i]>a[i+1]:
            return -1
    return 1

f=0
for i in range(n):
    for j in range(i):
        tmp=a[i]
        a[i]=a[j]
        a[j]=tmp
        if shou(a)==1:
            f=1
        tmp=a[i]
        a[i]=a[j]
        a[j]=tmp
if f>0:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
n = int(input())
p = list(map(int,input().split()))
int_queue = [i for i in range(1,n+1)]
ans = 0
for j in range(n):
  ans += p[j]-int_queue[j]
if ans == 0:
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

Solution code:
n = int(input())
p = list(map(int,input().split()))
int_queue = [i for i in range(1,n+1)]
ans = 0
for j in range(1,n):
  ans += p[j]-int_queue[j]
if ans == 0:
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

Solution code:
import numpy as np

s = input().split()
N=int(s[0])
s = input().split()
a=np.array(range(1,N+1))
s=[int(i) for i in s]
if np.count_nonzero(a != s)<2:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
num = list(map(int, input().split()))
sw = []
for i in range(n):
    if num[i] != i + 1:
        sw.append(i)
if len(sw) == 2:
    print('YES')
else: print('NO')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

count = 0
for i, a in enumerate(A, 1):
  if i != a:
    count += 1
    if count > 3:
      print("NO")
      exit()
      
print("YES")

Submission status: Wrong Answer

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

for i in range(N):
  if i+1 != A[i]:
    c += 1

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