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:
num_input = input()
list_input = input().split(" ")
N = int(num_input)
count = 0
for i in range(0,N-1):
  check = int(list_input[i])-int(list_input[i+1])
  if check > 1:
    count += 2
    break
  else:
    count += max(check,0)
if count >= 2:
  print('NO')
else:
  print('YES')

Submission status: Wrong Answer

Solution code:
num_input = input()
list_input = input().split(" ")
N = int(num_input)
count = 0
for i in range(0,N-1):
  check = int(list_input[i])-int(list_input[i+1])
  if check > 1:
    count = 2
    break
  else:
    count += max(check,0)
if count >= 2:
  print('NO')
else:
  print('YES')

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
print(cnt)
if cnt>2 or cnt==1:
    print("NO")
else:
    print("YES")

Submission status: Wrong Answer

Solution code:
n = int(input())
p = list(map(int,input().split()))
l = sorted(p)
cnt = 0
for i in p:
    for j in l:
        if i!=j:
            cnt += 1
if cnt>2 or cnt==1:
    print("NO")
else:
    print("YES")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
a.insert(0,0)
f=1
for i in range(1,n+1):
    if a[i]!=i:
        f=0
        if a[a[i]]==i:
            print("YES")
        else:
            print("NO")
        break
if f==1:
    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:
        c=c+1
if c==0 or c==2:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
for i in range(n):
  if(l[i]!=(i+1)):
    ind=l.index(i+1)
    l[i],l[ind]=l[ind],l[i]
  break
count=0
for i in range(n):
  if(l[i]!=(i+1)):
    break
  count+=1
if(count==n):
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
p = input().split(" ")
psorted = sorted(p)
same = 0
for i in range(n):
    if psorted[i] != p[i]:
        same = same + 1
if same <= 2:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
input()
p = input().split(" ")
psorted = sorted(p)
if psorted == p:
    print("YES")
else:
    i = 0
    same = 0
    for ps in p:
        if psorted[i] != ps:
            same = same + 1
        i = i + 1
    if same <= 2:
        print("YES")
    else:
        print("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):
        cnt+=1
if(cnt<=2):
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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

for i in range(1,N):
  for j in range(i-1,-1,-1):
    if X[j] > X[i]:
      if count == 1:
        print('NO')
        exit()
      else:
        X[i] = X[j]
        X[j] = X[i]
        count += 1
        
print('YES')

Submission status: Wrong Answer

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

for i in range(1,N):
  for j in range(i-1,-1,-1):
    if X[j] > X[i]:
      if count == 1:
        print('No')
        exit()
      else:
        X[i] = X[j]
        X[j] = X[i]
        count += 1
        
print('Yes')

Submission status: Wrong Answer

Solution code:
n = int(input())
p = [ int(_) for _ in input().split() ]
ls = [ _ for _ in range(1, n+1) ]
cnt = int()

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

Submission status: Wrong Answer

Solution code:
n = int(input())
l = []
l = input().split()
l = list(map(int,l))

list_up = []
for i in range(1,n+1):
    list_up += [i]
print(list_up)
x = 0
for i in range(n):
    if l[i] != list_up[i]:
        x += 1
print(list_up)
if x == 0 or x == 2:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

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

count = 0
big_index = [] # 昇順できないデータを入れておく
for i in range(N-1):
    if pn[i] > pn[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:
        count += 1
 
if count > 2:
    print("NO")
else:
    print("YES")

Submission status: Wrong Answer

Solution code:
N, *P = list(map(int, input().split()))
count = sum(p != i + 1 for i, p in enumerate(P))

print('YES' if count <= 2 else 'NO')

Submission status: Wrong Answer

Solution code:
import copy
N = int(input())
p = list(map(int,input().split()))
m = copy.deepcopy(p)
if p == list(range(1,N+1)):
            print("YES")
            exit()
for i in range(N):
    for j in range(1,N):
        p[i],p[j] = p[j],p[i]
        if p == list(range(1,N+1)):
            print("YES")
            exit()
        else:
            p = m
print("NO")

Submission status: Wrong Answer

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

if N==1 or N==2:
    print("YES")
elif N==3:
    if p==[1,2,3] or [1,3,2] or [2,1,3]:
        print("YES")
    else:
        print("NO")
else:
    pp=[]
    for i in range(N-1):
        pp.append(p[i+1]-p[i])
    cnt=0
    x=-1
    for i in range(N-3):
        if pp[i]==2 and pp[i+1]==-1 and pp[i+2]==2:
            cnt+=1
            x=i
    if cnt>1:
        print("NO")
    elif cnt==0:
        print("YES")
    else:
        ppp=pp[:x-1]+pp[x+2:]
        ans="YES"
        for i in ppp:
            if i!=1:
                ans="NO"
                break
        print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = [int(x) for x in input().split()]
cnt = 0
for i in range(len(l)-1):
    if l == sorted(l):
        break
    else:
        mi = l[i:].index(min(l[i:]))
        l[i], l[i+mi] = l[i+mi], l[i]
        cnt += 1

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

Submission status: Wrong Answer

Solution code:
n = int(input())
p = list(map(int, input().split(" ")))
c = 0
for i, pi in enumerate(p):
  if i < n-1:
    if not pi+1 == p[i+1]:
      c += 1
if c <= 2:
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

Solution code:
n = int(input())
P = [int(i) for i in input().split()]
ok = [i for i in range(1,n+1)]
cnt = 0
for p,o in zip(P,ok):
    if p != o: cnt += 1
if cnt == 2 or cnt == 0: print('Yes')
else: print('No')

Submission status: Wrong Answer

Solution code:
x=int(input())
a=list(map(int,input().split()))
c=0
f=1
for i in range(1,x+1):
  if(a[i-1]==i):
    c+=1
  if(c>2):
    print("NO")
    f=0
    break
if(f==1):
  print("YES")

Submission status: Wrong Answer

Solution code:
n = input("")
n = int(n)
exa = input("").split(" ")
check = 0
change_index = []
no_num = []
for i in range(n-2):
    if int(exa[i])+1 != int(exa[i+1]) and int(exa[i+1])+1 == int(exa[i+2]) and i not in no_num:
        check += 1
        change_index.append(i)
    if int(exa[i])+1 == int(exa[i+1]) and int(exa[i+1])+1 != int(exa[i+2]) and i not in no_num:
        check += 1
        change_index.append(i+2)
        no_num.append(i+2)
    if int(exa[i])+1 != int(exa[i+1]) and int(exa[i+1])+1 != int(exa[i+2]) and i not in no_num:
        check += 2
        change_index.append(i)
        change_index.append(i+1)
        no_num.append(i)
        no_num.append(i+1)
        

if check == 0:
    ans = "YES"
elif check == 2:
    tmp = exa[change_index[0]]
    exa[change_index[0]] = exa[change_index[1]]
    exa[change_index[1]] = tmp
    check = 0
    for i in range(n-1):
        if int(exa[i+1]) == int(exa[i])+1:
            continue
        else:
            check += 1
    if check == 0:
        ans = "YES"
    else:
        ans = "NO"
else:
    ans = "NO"

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
cnt = 0
for i in range(len(a)):
    if a == sorted(a):
        break
    for j in range(len(a)-1, i, -1):
        if a[j] < a[j-1]:
            a[j], a[j-1] = a[j-1], a[j]
    cnt += 1

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

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    p = [int(i) for i in input().split()]
    if is_ascending(p):
        print("YES")
        return

    num_swap = 0
    previous = p[0]
    for p_i in p[1:]:
        if previous > p_i:
            num_swap += 1
        previous = p_i 

    if num_swap > 2:
        print("NO")
    elif num_swap == 1:
        previous = p[0]
        for ix, p_i in enumerate(p[1:], 1): 
            if previous > p_i:
                p[ix], p[ix-1] = p[ix-1], p[ix]
                break
            previous = p_i 

        if is_ascending(p):
            print("YES")
        else:
            print("NO")

    elif num_swap == 2:
        previous = p[0]
        is_first = True
        for ix, p_i in enumerate(p[1:], 1): 
            if previous > p_i:
                if is_first:
                    swap_ix = ix - 1 
                    is_first = False
                else:
                    p[swap_ix], p[ix] = p[ix], p[swap_ix]
                    break
            previous = p_i 


        if is_ascending(p):
            print("YES")
        else:
            print("NO")

def is_ascending(l):
    previous = l[0]
    for i in l[1:]:
        if previous > i:
            return False
    return True

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
INPUT = sys.stdin.readline
#入力関数
def SORO_INT(): return int(INPUT())
def MULT_INT_LIST(): return list(map(int, INPUT().split()))
def MULT_INT_MAP(): return map(int, INPUT().split())
def SORO_STRING(): return INPUT()
def MULT_STRING(): return INPUT().split()

N = SORO_INT()
A = MULT_INT_LIST()
X = sorted(A)
if A == X:
    print('YES')
    sys.exit()
    
t1 = A.index(max(A))
t2 = A.index(min(A))

A[t1],A[t2] = A[t2],A[t1]

if A == X:
    print('YES')
else:
  print('NO')

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
import math

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

r = []

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

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

Submission status: Wrong Answer

Solution code:
n = input("")
n = int(n)
exa = input("").split(" ")
check = 0
change_index = []
no_num = []
for i in range(n-2):
    if int(exa[i])+1 != int(exa[i+1]) and int(exa[i+1])+1 == int(exa[i+2]) and i not in no_num:
        check += 1
        change_index.append(i)
    if int(exa[i])+1 == int(exa[i+1]) and int(exa[i+1])+1 != int(exa[i+2]):
        check += 1
        change_index.append(i+2)
        no_num.append(i+2)
    if int(exa[i])+1 != int(exa[i+1]) and int(exa[i+1])+1 != int(exa[i+2]):
        check += 2
        change_index.append(i)
        change_index.append(i+1)
        no_num.append(i)
        no_num.append(i+1)
        

if check == 0:
    ans = "YES"
elif check == 2:
    tmp = exa[change_index[0]]
    exa[change_index[0]] = exa[change_index[1]]
    exa[change_index[1]] = tmp
    check = 0
    for i in range(n-1):
        if int(exa[i+1]) == int(exa[i])+1:
            continue
        else:
            check += 1
    if check == 0:
        ans = "YES"
    else:
        ans = "NO"
else:
    ans = "NO"

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
p = list(map(int, input().split()))
a=0
p_2 = sorted(p)
for i in range(n-1):
    a=+1
    if p[i] > p[i+1]:
        for j in range(a,n-1):
            if p[j] > p[j+1]:
                p[i],p[j+1] = p[j+1],p[i]
if p == p_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 p[i+1]  != p[i] + 1:
        count += 1
if count > 3:
    print('NO')
else:
    print('YES')

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
r=list(range(1,n+1))
s=0
m=0
if l==r:
  m=1
  print("YES")
else:
  while s<n:
    for i in range(n):
      r=list(range(1,n+1))
      d=r[s]
      r[s]=r[i]
      r[i]=d
      if l==r:
        print("Yes")
        s=n
        m=1
        break
    s=s+1
if not m==1:
  print("NO")

Submission status: Wrong Answer

Solution code:
n = int(input())
list = []
list = input().split()

list_up = []
for i in range(1,n+1):
    list_up += str(i)

x = 0
for i in range(n):
    if list[i] != list_up[i]:
        x += 1

if x == 0 or x == 2:
    print("YES")

else:
    print("NO")

Submission status: Wrong Answer

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

out_num = {}
for i,pi in zip(range(1,N+1),p):
  if i != pi:
    out_num[i] = pi

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

Submission status: Wrong Answer

Solution code:
def checkSortable(arr):
    n = len(arr)
    b = []

    for i in range(n):
        b.append(arr[i])
    
    b.sort()

    ct = 0

    for i in range(n):
        if arr[i] != b[i]:
            ct += 1
        
    if ct > 2:
        return False
    return True 


if __name__ == '__main__':
    s = [input() for i in range(2)]
    N = s[0]
    arr = s[1]

    if checkSortable(arr):
        print("YES")
    else:
        print("NO")

Submission status: Wrong Answer

Solution code:
import sys
import math
INPUT = sys.stdin.readline
#入力関数
def SORO_INT(): return int(INPUT())
def MULT_INT_LIST(): return list(map(int, INPUT().split()))
def MULT_INT_MAP(): return map(int, INPUT().split())
def SORO_STRING(): return INPUT()
def MULT_STRING(): return INPUT().split()

N = SORO_INT()
A = MULT_INT_LIST()
X = sorted(A)
if A == X:
    print('YES')
    sys.exit()
    
t1 = A.index(max(A))
t2 = A.index(min(A))

A[t1],A[t2] = A[t2],A[t1]

if t2-N+1 == t1:
    print('YES')
else:
  print('NO')

Submission status: Wrong Answer

Solution code:
import copy
N = int(input())
p = list(map(int,input().split()))
m = copy.deepcopy(p)
cnt = 0
if p == list(range(1,N+1)):
    print("YES")
    exit()
for i in range(N):
    for j in range(N-1,-1,-1):
        if cnt == 1:
            p = m
            cnt = 0

        if i < j:
            if p[i] > p[j] and i != j:
                
                p[i],p[j] = p[j],p[i]
                cnt = 1
                if p == list(range(1,N+1)):
                    print("YES")
                    exit()
                else:
                    p = m
                    
print("NO")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
import math
INPUT = sys.stdin.readline
#入力関数
def SORO_INT(): return int(INPUT())
def MULT_INT_LIST(): return list(map(int, INPUT().split()))
def MULT_INT_MAP(): return map(int, INPUT().split())
def SORO_STRING(): return INPUT()
def MULT_STRING(): return INPUT().split()

N = SORO_INT()
A = MULT_INT_LIST()
X = sorted(A)
if A == X:
    print('yes')
    sys.exit()
    
t1 = A.index(max(A))
t2 = A.index(min(A))

A[t1],A[t2] = A[t2],A[t1]

if t2-N+1 == t1:
    print('yes')
else:
  print('no')

Submission status: Wrong Answer

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

check = []
for i in range (0, N-1):
  check.append(p[i+1] - p[i])
 
if check.count(1) == N-1:
  print("YES")
elif check.count(1) == N-3:
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

Solution code:
n = int(input())
P = [int(i) for i in input().split()]
cnt = 0
for i in range(1,n+1):
    if P[i-1] != i:
        idx = P[i-1]
        if P[idx-1] != i:
            print('No')
            exit()
        else:
            P[i-1] = i
            P[idx-1] = idx
            cnt += 1
#print(P)
if cnt <= 1: print('Yes')
else: print('No')

Submission status: Wrong Answer

Solution code:
S = int(input())
slist = input().split()

for i,a in enumerate(slist):
  slist[i] = int(a)

new_list = sorted(slist)
d_count = 0
for i,j in zip(slist,new_list):
  if i != j:
    d_count += 1
    
if d_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-1):
  for j in range(1,n-1):
    if i+j>n-1:
      break
    elif p[i]>p[i+j]:
      count=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(" ")))
c = 0
for i, pi in enumerate(p):
  if i < n-1:
    if not pi+1 == p[i+1]:
      c += 1
if c == 2 or c == 0:
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())

inputs_list = input()

correct_list = []
for i in range(n):
    correct_list.append(i+1)
    
if inputs_list == correct_list:
    print('YES')

common = set(inputs_list) & set(correct_list)

if len(common) - n != 0:
    print("NO")

Submission status: Wrong Answer

Solution code:
S = int(input())
slist = input().split()

for i,a in enumerate(slist):
  slist[i] = int(a)

new_list = sorted(slist)
d_count = 0
for i,j in zip(slist,new_list):
  if i != j:
    d_count += 1
    
if d_count <= 2:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = int(input())
slist = input().split()

for i,a in enumerate(slist):
  slist[i] = int(a)

new_list = sorted(slist)
d_count = 0
for i,j in zip(slist,new_list):
  if i != j:
    d_count += 1
    
if d_count == 2:
  print('Yes')
elif d_count ==0:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
S = int(input())
slist = input().split()

for i,a in enumerate(slist):
  slist[i] = int(a)

new_list = sorted(slist)
d_count = 0
for i,j in zip(slist,new_list):
  if i != j:
    d_count += 1
    
if d_count == 2:
  print('Yes')
elif d_count ==0:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
n = input("")
n = int(n)
exa = input("").split(" ")
check = 0
change_index = []
no_num = []
for i in range(n-2):
    if int(exa[i])+1 != int(exa[i+1]) and int(exa[i+1])+1 == int(exa[i+2]) and i not in no_num:
        check += 1
        change_index.append(i)
    if int(exa[i])+1 == int(exa[i+1]) and int(exa[i+1])+1 != int(exa[i+2]):
        check += 1
        change_index.append(i+2)
        no_num.append(i)
        

if check == 0:
    ans = "YES"
elif check == 2:
    tmp = exa[change_index[0]]
    exa[change_index[0]] = exa[change_index[1]]
    exa[change_index[1]] = tmp
    check = 0
    for i in range(n-1):
        if int(exa[i+1]) == int(exa[i])+1:
            continue
        else:
            check += 1
    if check == 0:
        ans = "YES"
    else:
        ans = "NO"
else:
    ans = "NO"

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
pn = [ int(item) for item in input().split()]

ANS = range(1,N)

cnt=0
pre=1
flag='NO'

diff_flag = True

for i in range(len(pn)-1):
  diff = pn[i+1] - pn[i]
  if diff != 1:
    diff_flag = False
    if cnt==0:
      pre_diff = diff
    elif cnt == 1:
      if diff == pre_diff:
        flag = 'YES'
    pre_diff = diff
    cnt+=1

if diff_flag:
  flag = 'YES'
  
print(flag)

Submission status: Wrong Answer

Solution code:
import copy

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

X.sort()
ans = "No"


for i in range(N):
    for j in range(N):
        Y = copy.copy(P)
        a = copy.copy(P[i])
        b = copy.copy(P[j])
        Y[i] = b
        Y[j] = a
        #print(Y)
        if Y == X:
            ans =  "Yes"


print(ans)

Submission status: Wrong Answer

Solution code:

def main():

    N = int(input())
    A= list(map(int,input().split()))
    count = 0

    for i in range(N-1):
        if not A[i] < A[i+1] or A[i+1]-A[i]!=1 or A[0]!=1 or A[1]!=2:
            count +=1
    
    if count < 3:
        print("YES")
    else:
        print("NO")




if __name__== "__main__":
    main()

Submission status: Wrong Answer

Solution code:
S = int(input())
slist = input().split()

new_list = sorted(slist)
d_count = 0
for i,j in zip(slist,new_list):
  if i != j:
    d_count += 1
    
if d_count == 2:
  print('Yes')
elif d_count ==0:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
n = int(input())
p = tuple(map(int,input().split()))
ans = sorted(p)
for i in range(n):
    ori = list(p)
    for j in range(n):
        temp = ori[i]
        ori[i] = ori[j]
        ori[j] = temp
        if ans == ori:
            print("YES")
            exit()
print("NO")

Submission status: Wrong Answer

Solution code:
S = int(input())
slist = input().split()

new_list = sorted(slist)
d_count = 0
for i,j in zip(slist,new_list):
  if i != j:
    d_count += 1
    
if d_count > 3:
  print('No')
else:
  print('Yes')

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = int(input())
slist = input().split()

new_list = sorted(slist)
d_count = 0
for i,j in zip(slist,new_list):
  if i != j:
    d_count += 1
    
if d_count > 2:
  print('NO')
else:
  print('YES')

Submission status: Wrong Answer

Solution code:
S = int(input())
slist = input().split()

new_list = sorted(slist)
d_count = 0
for i,j in zip(slist,new_list):
  if i != j:
    d_count += 1
    
if d_count > 2:
  print('No')
else:
  print('Yes')

Submission status: Wrong Answer

Solution code:
print("NO")

Submission status: Wrong Answer

Solution code:

def main():

    N = int(input())
    A= list(map(int,input().split()))
    count = 0

    for i in range(N-1):
        if not A[i] < A[i+1] or A[i+1]-A[i]!=1:
            count +=1
    
    if count < 3:
        print("YES")
    else:
        print("NO")




if __name__== "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())

inputs_list = input()

correct_list = []
for i in range(n):
    correct_list.append(i+1)
    
if inputs_list == correct_list:
    print('NO')

Submission status: Wrong Answer

Solution code:
n = int(input())
p = list(map(int, input().split(" ")))
p_sorted = p.copy()
p_sorted.sort()
ans = set(p) ^ set(p_sorted)
if len(ans) <= 2:
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

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

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

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

count=0

bubble_sort(p)
if count<=1:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
num = int(input())
if num >= 2:
  input_list = [int(i) for i in input().split()] 
  sorted_list = sorted(input_list)

  count = 0
  for input, sort in zip(input_list, sorted_list):
    if input != sort:
      count += 1

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

Submission status: Wrong Answer

Solution code:
#B
n = int(input())
p = list(map(int, input().split()))
cnt = 0
flg = 0
tmp1,tmp2 = 0,0
for i in range(0,n-1):
    if p[i] > p[i+1]:
        if tmp1 == 0:
            tmp1, tmp2 = p[i], p[i+1]
        else:
            if cnt == 1:
                flg = 1
                break
            elif p[i+1]<tmp2 and p[i]<tmp1:
                p[i+1] = tmp2
                cnt = 1
            else:
                flg = 1
                cnt = 1
                break
if flg == 0:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
n = int(input())
p = list(map(int, input().split(" ")))
p_sorted = p.copy()
p_sorted.sort()
ans = set(p) ^ set(p_sorted)
if len(ans) <= 2:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
intlist = input().split(" ")
count = 0
sortedlist = sorted(intlist)
match = list()
 
for i in range(0,n):
	if(int(intlist[i]) == int(sortedlist[i])):
		match.append(0)
	else:
		match.append(1)
 
if(sum(match) > 2):
	print("NO")
else:
	print("YES")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

def main():
  n = int(input())
  input_line = list(map(int, input().split()))
  
  flag = 0
  i = 0
  for x in input_line:
    if flag > 3:
      break
    elif (i + 1) == len(input_line):
      break
    elif (input_line[i + 1] - input_line[i]) != 1:
      flag += 1
      
    i += 1
    
  if flag < 4:
    print("YES")
  else:
    print("NO")




if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
import copy

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

X.sort()
ans = "No"


for i in range(N):
    for j in range(N):
        Y = copy.copy(P)
        Y[i],Y[j] = Y[j],Y[i]

        if Y == P:
            ans =  "Yes"


print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
intlist = input().split(" ")
count = 0
sortedlist = sorted(intlist)
match = list()

for i in range(0,n):
	if(intlist[i] == sortedlist[i]):
		match.append(0)
	else:
		match.append(1)

# print(intlist)
# print(sortedlist)
# print(match)

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

Submission status: Wrong Answer

Solution code:
n = int(input())

inputs_list = input()

correct_list = []
for i in range(n):
    correct_list.append(i+1)
    
if inputs_list == correct_list:
    print('YES')

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
import itertools
def main():
    input = sys.stdin.readline

    N = int(input())
    P = list(map(int, input().split()))
    #print(P)
    P = np.array(P)
    #print(P)
    ans = np.arange(start=1, step=1, stop=N+1)
    #print(ans)
    if np.all(P == ans):
        print('YES')
    else:
        dels_comb = list(itertools.combinations(P,2))

        length = len(dels_comb)
        for i in range(length):
            dels = dels_comb [i]
            a, b = dels
            _P = P[(P != a) & (P != b)]
            _ans = ans[(ans != a) & (ans != b)]
            #print(_P)
            #print(_ans)
            if np.all(_P == _ans):
                print('YES')
                break
            if i + 1 == length:
                print('NO')
if __name__ == '__main__':
    main()