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()))
cnt = 0

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

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

Submission status: Wrong Answer

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

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

if cnt < 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):
    if p[i] != i + 1:
        count += 1
if count == 0 or count == 2:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
#ABC135 B

N = int(input())
P = list(map(int,input().split()))
PP = sorted(P)
count = 0
for i in range(1,N):
    for j in range(2,N+1):
        p = P[i-1]
        q = P[j-1]
        P[i-1] = q
        P[j-1] = p
        if P == PP:
            count += 1
        P[i-1] = p
        P[j-1] = q

if count >= 1:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(1, n-1):
    if p[i] != i+1:
        print('No')
        exit()
print('Yes')

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import copy
N = int(input())
p = list(map(int, input().split()))
pcopy = copy.deepcopy(p)
ans = sorted(p)

is_ascend = False
if p == ans:
    is_ascend = True

for i in range(N):
    for j in range(i+1,N):
        p = copy.copy(pcopy)
        p[i], p[j] = p[j], p[i]
        if p == ans:
            is_ascend = True

if is_ascend:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

s_p = sorted(p)

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

if cnt//2 > 1:
    print("NO")
else:
    print("YES")

Submission status: Wrong Answer

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

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 or count == 0:
    print('YES')
else:
    print('No')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import math
import collections
import itertools
import copy

def YesNo(Bool):
    if(Bool):
        print("Yes")
    else:
        print("No")
    return

def resolve():

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

    tmp=copy.deepcopy(p)
    isOK=True
    for k in range(N-1):
        if(tmp[k]>=tmp[k+1]):
            isOK=False
    if(isOK):
        ans=True

    for i in range(N):
        for j in range(i+1,N):
            tmp=[]
            tmp=copy.deepcopy(p)
            tmp[i],tmp[j]=tmp[j],tmp[i]
            isOK=True
            for k in range(N-1):
                if(tmp[k]>=tmp[k+1]):
                    isOK=False
            if(isOK):
                ans=True
    YesNo(ans)

resolve()

Submission status: Wrong Answer

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

count = 0
for i in range(N):
    if p[i] != i:
        count = count + 1
    if count == 3:
        break
if count == 3:
    print('NO')
else:
    print('YES')

Submission status: Wrong Answer

Solution code:
N = int(input())
P = [int(s) for s in input().split()]
index = []
for i in range(N):
    index.append(P.index(i+1))
count = 0
for i, j in enumerate(index):
    if i != j:
        count += 1
if count > 2:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def check(n, list1): 
    new = [] 
    for i in range(n): 
        new.append(list1[i]) 
          
    new.sort()
    swaps = 0
    for i in range(n): 
        if list1[i] != new[i]: 
            swaps += 1
              
    if swaps == 0 or swaps == 2: 
        return True
    else: 
        return False
  
n = int(input())

numbers =list(map(int, input().split()[:n]))


print(numbers)



if check(n, numbers): 
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
x = int(input())
p = list(map(int, input().strip().split()))
k = sorted(p)
count = 0
for i in range(0,x):
    if p[i] == k[i]:
        count += 1

if (x - count) == 2:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np

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

q = sorted(p)
p, q = np.array(p), np.array(q)

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

cnt = 0

for i in range(N-1):
    if P[i] > P[i+1]:
        cnt += 1
    if cnt > 1:
        print('NO')
        exit()

print('YES')

Submission status: Wrong Answer

Solution code:
# import math
# import statistics
a=int(input())
#b,c=int(input()),int(input())
# c=[]
# for i in a:
#     c.append(i)
#e1,e2 = map(int,input().split())
f = list(map(int,input().split()))
#g = [input() for _ in range(a)]

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

Submission status: Wrong Answer

Solution code:
# import math
# import statistics
a=int(input())
#b,c=int(input()),int(input())
# c=[]
# for i in a:
#     c.append(i)
#e1,e2 = map(int,input().split())
f = list(map(int,input().split()))
#g = [input() for _ in range(a)]

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:

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

for i in range(n-1):
    if p[i]<=p[i+1]:
        tmp=p[i]
        p[i]=p[i+1]
        p[i+1]=tmp
        break
if new_p==p:
    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+1:
        c+=1
print(c)
if c>2:
    print("NO")
else:
    print("YES")

Submission status: Wrong Answer

Solution code:
N = int(input())
B = list(map(int, input().split()))
temp = []
cnt = 0
for i in range(N):
  if i + 1 != B[i]:
    cnt += 1
if cnt == 0 or cnt == 2:
  print("Yes")
  exit()
print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
p = list(map(int,input().rstrip().split()))
pp = sorted(p)
cnt = 0
for i in range(n):
    if p[i]!=pp[i]:
        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()))
sorted_P = sorted(P)
cnt = 0
for i in range(len(P)):
    if P[i] != sorted_P[i]:
        cnt += 1

    if cnt > 2:
        print("No")
        exit()
print("YES")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
print("YES" if [i == j for i, j in zip(a, sorted(a))].count(False) == 2 else "NO")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
p=list(map(int,input().split()))
q=sorted(p)
print(p,q)
a=0
for i in range(N):
    if p[i]!=q[i]:
        a+=1
    if a>2:
        print('NO')
        exit()
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().split()))
q=sorted(p)
print(p,q)
a=0
for i in range(N):
    if p[i]!=q[i]:
        a+=1
    if i>2:
        print('NO')
        exit()
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().split()))
q=sorted(p,reverse=True)
i=0
for i in range(N):
    if p[i]!=q[i]:
        i+=1
    if i>2:
        print('NO')
        exit()
if i==0 or i==2:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
# coding: utf-8

num = int(input())
str = input().split()
table = list(str)
table5 = [int(i) for i in table]
count = 0
table2 = sorted(table)
table3 = [int(i) for i in table2]
print(table5)
print(table3)
for i in range(num):
    if table5[i] == table3[i]:
        continue
    else:
        count += 1

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8

num = int(input())
str = input().split()
table = list(str)
table5 = [int(i) for i in table]
count = 0
table2 = sorted(table)
table3 = [int(i) for i in table2]
for i in range(num):
    if table5[i] == table3[i]:
        continue
    else:
        count += 1

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8

num = int(input())
str = input().split()
table = list(str)
count = 0
table2 = sorted(table)
for i in range(num):
    if table[i] == table2[i]:
        continue
    else:
        count += 1

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
p = list(map(int,input().split()))
x = sorted(p)
c = 0
for i in range(n):
    if x[i] == p[i]:
        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()))
x = sorted(p)
c = 0
for i in range(n):
    if x[i] == p[i]:
        c+=1
if c >=2:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

diff = 0
for i in range(n):
    if p[i] != i + 1:
            diff += 1
print('YES') if diff <= 2 else print('No')

Submission status: Wrong Answer

Solution code:
# ABC135
# B 0 or 1 swap
n = int(input())
p = list(map(int, input().split()))
ch = 0
for i in range(n):
    if (i+1) != p[i]:
        ch += 1

if ch > 2:
    print('NO')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
c = 0
for i in range(N):
  if A[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()))

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

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

Submission status: Wrong Answer

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

cnt = 0

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

if cnt >= N-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(N):
    ans += P[i] != i+1

print('No' if ans > 2 else 'Yes')

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
c = 0
for i in range(n):
  if a[i] != 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(map(int, input().split()))

def bubble(input_list):
    cnt = 0
    flg = 0
    for i in range(len(input_list)):
        if i != input_list[i]:
            cnt +=1
            flg = 1
    if flg == 1:
        return False, cnt
    else:
        return True, 0
a, b = bubble(p)

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

Submission status: Wrong Answer

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

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

if bubble(p):
    print("YES")
    exit()

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

print("YES" if bubble(p) else "NO")

Submission status: Wrong Answer

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

ans = sorted(P)

if P == ans:
  print("YES")
else:
  for i in range(N-1):
    for j in range(i+1,N):
      check = []
      check += P
      check[i],check[j] = check[j],check[i]
      if check == ans:
        print("YES")
        sys.exit()
        
print("NO")

Submission status: Wrong Answer

Solution code:
n = int(input())
k = input().split(" ")
if len(k) == n+1:
  k.remove(k[n])
if k == sorted(k):
  print("YES")
else:
  k[0],k[n-1] = k[n-1],k[0]
  if k == sorted(k):
    print("YES")
  else:
    print("NO")

Submission status: Wrong Answer

Solution code:
n = int(input())
k = input().split(" ")
if len(k) == 4:
  k.remove(k[n])
if k == sorted(k):
  print("YES")
else:
  k[0],k[n-1] = k[n-1],k[0]
  if k == sorted(k):
    print("YES")
  else:
    print("NO")

Submission status: Wrong Answer

Solution code:
n = int(input())
k = input().split(" ")
if k == sorted(k):
  print("YES")
else:
  k[0],k[n-1] = k[n-1],k[0]
  if k == sorted(k):
    print("YES")
  else:
    print("NO")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# 問題：https://atcoder.jp/contests/abc135/tasks/abc135_b

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

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

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

Submission status: Wrong Answer

Solution code:
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("YES") if fl else print("NO")
import collections
import math
import itertools
import heapq as hq
n = ni()
P = lma()
cnt = 0
for i in range(n):
    if P[i] != n-i:
        cnt+=1
f = False
if cnt==2:
    f=True
yn(f)

Submission status: Wrong Answer

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

    for i in range(len(p)):

        if p[i] == i+1:
            count += 1

    if len(p) - count <= 2:
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

for i in range(len(p_ls) - 1):
    min_idx = i
    for j in range(i + 1, len(p_ls)):
        if p_ls[min_idx] > p_ls[j]:
            min_idx = j
    if min_idx != i:
        p_ls[min_idx], p_ls[i] = p_ls[i], p_ls[min_idx]
        cnt += 1
if cnt > 1:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

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

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

print("Yes") if cnt in [0, 2] else print("No")

Submission status: Wrong Answer

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

ps = sorted(p)

d_p = []
d_ps = []
for i,q in enumerate(p):
  if q != ps[i]:
    d_p.append(q)
    d_ps.append(ps[i])
if len(d_p) > 2:
  print('No')
elif len(d_p) == 2:
  d_p.sort()
  if d_p == d_ps:
    print('Yes')
  else:
    print('No')
else:
  print('Yes')

Submission status: Wrong Answer

Solution code:
n = int(input())
p = list(map(int, input().split()))
p1 = sorted(p, reverse=True)
a = 0
for i in range(n):
    if p[i] != p1[i]:
        a += 1
# print(a)
if a <= 2:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
N = int(input())
MM = input().split()
count = 0
list1 =[]
for i in MM:
  a = int(i)
  list1.append(a)
list2 = sorted(list1)
for i,j in zip(list1,list2):
  
  if i != j:
    
    count +=1
if count >2:
  print('No')
else:
  print('Yes')

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
q = 0
for i in range(n):
 for j in range(i+1, n):
  t = a[i]
  a[i] = a[j]
  a[j] = t
  f = 1  
  lst = - 1100
  for k in a:
   f &= k > lst
   lst = k
  q |= f
  t = a[i]
  a[i] = a[j]
  a[j] = t
print("YES" if q else "NO")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
t = 0
for i in range(n):
 q = 0
 for j in range(i):
  q += a[i] < a[j]
 t += q>0
v = 0
for i in range(n):
 q = 0
 for j in range(i+1, n):
  q += a[i] > a[j]
 v += q>0
print("YES" if min(t, v) < 2 else "NO")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
p=list(map(int,input().split()))
q=sorted(p)
for i in range(n-1):
  for j in range(i,n):
    s=p[i]
    p[i]=p[j]
    p[j]=s
    if p==q:
      print("YES")
      sys.exit()
    s=p[i]
    p[i]=p[j]
    p[j]=s
      
print("N0")

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
p=list(map(int,input().split()))
q=sorted(p)
if p==q:
  print("YES")
  sys.exit()


for i in range(n-1):
  for j in range(i+1,n):
    s=p[i]
    p[i]=p[j]
    p[j]=s
    if p==q:
      print("Yes")
      sys.exit()
    s=p[i]
    p[i]=p[j]
    p[j]=s
      
print("N0")

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
p=list(map(int,input().split()))
q=sorted(p)
if p==q:
  print("YES")
  sys.exit()
else:
  print("NO")
  sys.exit()
  

for i in range(n-1):
  for j in range(i+1,n):
    s=p[i]
    p[i]=p[j]
    p[j]=s
    if p==q:
      print("Yes")
      sys.exit()
    s=p[i]
    p[i]=p[j]
    p[j]=s
      
print("N0")

Submission status: Wrong Answer

Solution code:
from copy import copy
n = int(input())
p = list(map(int, input().split()))
q = sorted(p)
ret = 'NO'
for i in range(n-1):
    for j in range(i, n):
        r = copy(p)
        r[i] = p[j]
        r[j] = p[i]
        if q == r:
            ret == 'YES'
            break
print(ret)

Submission status: Wrong Answer

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

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

if wrong <= 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 + 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()))
cnt=0
for i in range(n):
  if 1+i!=p[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()))
ans=0
for i in range(n):
    if p[i]!=i+1:
        ans=ans+1
if ans<=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(n):
    if p[i]!=i+1:
        ans=ans+1
if ans<=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(n):
    if p[i]==i+1:
        ans=ans+1
if ans<=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(n):
    if p[i]==i+1:
        ans=ans+1
if ans<=2:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

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

min_i = 0
max_i = 0
for i in range(n):
    if p[i] == 1:
        min_i = i
    elif p[i] == n:
        max_i = i

if min_i > max_i:
    p[min_i] = n
    p[max_i] = 1

for i in range(n-1):
    if p[i]+1 != p[i+1]:
        print("NO")
        exit()

print("YES")

Submission status: Wrong Answer

Solution code:
import math
def main():
  n=int(input())
  p = list(map(int,input().split()))
  first=-1
  last=-1
  
  for i in range(0,n-1):
    if p[i]>p[i+1]:
      first=i
      break
  for i in reversed(range(1,n)):
    if p[i]<p[i-1]:
      last=i
      break
  
  if first!=-1 and last!=-1:
    tmp=p[first]
    p[first]=p[last]
    p[last]=tmp

  for i in range(0,n-1):
    if p[i]>p[i+1]:
      print("No")
      break
    if i==n-2:
      print("Yes")  
main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
List = list(map(int, input().split()))
mid = -1
flag = True
for i in range(N):
  if List[i] == i+1:
    pass
  else:
    flag = False
    if mid == -1:
      mid = List[i]
    else:
      if mid == i+1:
        print("YES")
      else:
        print("NO")
if flag:
  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

sort_p = sorted(p)

for i in range(n):
  if p[i] != sort_p[i]:
    count += 1
    
if count  == 2:
  print("Yes")
  exit()
elif count == 0:
  print("Yes")
  exit()
else:
  print("No")
  exit()

Submission status: Wrong Answer

Solution code:
n = int(input())
p = input().split()
q = sorted(p)
cnt = sum(p[i] != q[i] for i in range(n))
print(["NO", "YES"][cnt == 0 or cnt == 2])

Submission status: Wrong Answer

Solution code:
def check(n,l):
    flag = True
    for i in range(n-1):
        if l[i] > l[i+1]:
            flag = False
            break
    if flag:
        return True
    else:
        return False

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

flag = check(n,l)
if flag:
    print("YES")
else:
    for i in range(n-1):
        x = l[i]
        l[i] = l[i+1]
        l[i+1] = x
        if check(n,l):
            flag = True
            break
        else:
            l[i+1] = l[i]
            l[i] = x
    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(len(p)):
  if p[i] != i+1:
    cnt += 1
if cnt==0 or cnt==2:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
array = list(map(int,input().split()))
array_base = [ I for I in range(1,N+1) ]

dic = {}
for I in range(N):
    if array[I] != I + 1:
        dic[I] = array[I]
if len(dic) != 2 or len(dic) != 0:
    print('NO')
else:
    print('YES')

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
array = list(map(int,input().split()))
array_base = [ I for I in range(1,N+1) ]

dic = {}
for I in range(N):
    if array[I] != I + 1:
        dic[I] = array[I]
if len(dic) != 2:
    print('NO')
else:
    print('YES')

Submission status: Wrong Answer

Solution code:
input()
*p,=input().split()
print('YNEOS'[2<sum(i!=j for i,j in zip(p,sorted(p)))::2])

Submission status: Wrong Answer

Solution code:
input()
*p,=input().split()
print('NO' if 2<sum([1 for i,j in zip(p,sorted(p)) if i!=j]) else 'YES')

Submission status: Wrong Answer

Solution code:
input()
*p,=input().split()
q=sorted(p)
print('YNEOS'[2<sum(1 for i,j in zip(p,q) if int(i)!=int(j))::2])

Submission status: Wrong Answer

Solution code:
input()
*p,=input().split()
q=sorted(p)
print('YNEOS'[2<sum(1 for i,j in zip(p,q) if i!=j)::2])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
p=[0]+list(map(int,input().split()))
d=list(range(0,N+1))
f=True
for i in range(N):
    if p[i]!=d[i]:
       for j in range(i+1,N+1):
           if p[i]==d[j] and p[j]!=d[i]:
               f=False
if f:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
N=int(input())
p=[0]+list(map(int,input().split()))
d=list(range(0,N+1))
f=True
for i in range(N+1):
    if p[i]!=d[i]:
       if p[p[i]]!=d[i]:
           f=False
if f:
    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+1:
        err+=0
if err>=2:
    print('No')
else:
    print('YES')

Submission status: Wrong Answer

Solution code:
n = int(input())
p = list(map(int,input().split()))
n_l = list(range(1,n + 1))
count = 0
for n_num , p_num in zip(n_l,p):
  if n_num != p_num:
    count += 1
if count == 2 or count == 0:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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