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 = input()
P = list(map(int, input().split()))
sort_P = sorted(P)
new_P = []
for idx, p in enumerate(P):
    new_P.append(sort_P[idx] - p)
if len(set(new_P)) > 3:
    print("NO")
else:
    print("YES")

Submission status: Wrong Answer

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

sort_p = sorted(p)
dict_p = {}
isOk = True
for i in range(N):
    if p[i] == sort_p[i]:
        continue
    elif len(dict_p) == 0:
        dict_p[sort_p[i]] = p[i]
    elif p[i] in dict_p:
        continue
    else:
        isOk = False
        break

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

Submission status: Wrong Answer

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

q=sorted(p)

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

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

Submission status: Wrong Answer

Solution code:
def main():
	raw_input()
	g=raw_input().split()
	a=[int(x) for x in g]
	n=len(a)
	counter=0
	for i in range(n):
		for j in range(i+1,n):
			if a[i]>a[j]:
				counter+=1
				if counter>1:
					print("NO")
					return
	print("YES")
main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0

for n in range(N):
    if P[n] == n:
        ans += 1

if ans == 0 or 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 n in range(N-1):
    if P[n] > max(P[n+1:]):
        ans += 1

if ans == 0 or ans == 1:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if n-a > 2:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import copy

n = int(input())
c = list(map(int, input().split()))  # 複数数値入力(リスト格納)
ans = False
for i in range(0,n-1):
    for j in range(i+1, n):
        flg = False
        # ここでiとjを入れ替えたものをつくり、昇順ならbreak
        li = copy.copy(c)
        li[j], li[i] = li[i], li[j]

        for k in range(1, n+1):
            if li[k-1] != k:
                flg = True
                break
        
        if not flg:
            ans = True 

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

Submission status: Wrong Answer

Solution code:
n=int(input())
p=list(map(int,input().split()))
g=sum((1 for i in range(n) if i+1 !=p[i]))
print("YNeos"[::2] if g==2 or g==0 else "YNeos"[1::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()))
p_sort = sorted(p)
ans = 0
for i in range(N):
    if p[i] != p_sort[i]:
        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()))

cnt = 0
for idx, val in enumerate(p):
    if idx + 1 != val:
        cnt += 1
        if cnt == 3:
            print('NO')
print('YES')

Submission status: Wrong Answer

Solution code:
n = int(input())
p = '0'+input().replace(' ', '')
count = 0
for i in range(n+1):
    if i != int(p[i]):
        count += 1
if count == 0 or count == 2:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
n = int(input())
p = '0'+input().replace(' ', '')
count = 0
for i in range(len(p)):
    if i != int(p[i]):
        count += 1
if count == 0 or 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(len(p)):
  if p[i] != i + 1:
    cnt += 1
if cnt == 0 or 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 += 1
if ans==0 or 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 += 1
if ans==0 or 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 += 1
if ans==0 or ans==2:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
P = [int(x) for x in input().split()]
Q = sorted([int(x) for x in P])
ans = 0
for i in range(N):
  if ans!=3:
    if P[i]!=Q[i]:
      ans += 1
  else:
    break
if ans==0 or ans==2:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

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

Q = sorted([int(x) for x in P])

ans = 0
for i in range(N):
  if ans!=3:
    if P[i]!=Q[i]:
      ans += 1
  else:
    break
if ans < 3:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
def swap():
  N = int(input())
  P = [int(x) for x in input().split()]
  Q = sorted([int(x) for x in P])
  ans = 0
  for i in range(N):
    if ans!=3:
      if P[i]!=Q[i]:
        ans += 1
    else:
      break
  if ans < 3:
    print("Yes")
  else:
  	print("No")
if __name__=="__main__":
  swap()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

lN=[]
for i in range(1,N+1):
  lN.append(i)
  
cnt = 0  
for i in range(N):
  if lN[i] != P[i]:
    cnt += 1
      
if cnt == 0 or 2:    
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

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

lN=[]
for i in range(1,N+1):
  lN.append(i)
  
cnt = 0  
for i in range(N):
  if lN[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()))

lN=[]
for i in range(1,N+1):
  lN.append(i)
  
cnt = 0  
for i in range(N):
  if lN[i] != P[i]:
    cnt += 1
      
if cnt == 0 or 2:    
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
n=int(input())
p=list(map(int,input().split()))
#p copy q
import copy
q=copy.copy(p)
a=0
for i in range(n):
    if p[i]!=i+1 and a==0:
        q[i]=int(p[p[i]-1])
        q[p[i]-1]=p[i]
p.sort()
if p==q:
    print("YES")
else:
    print("NO")
#135b

Submission status: Wrong Answer

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

j=1
numofswap=0
for _p in p:
    if _p != j:
        numofswap+=0.5
    j+=1

print("Yes" if numofswap == 0 or numofswap == 1 else "No")

Submission status: Wrong Answer

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

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

print("Yes" if numofswap <= 2 else "No")

Submission status: Wrong Answer

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

i=1
numofswap=0
for _p in p:
    if _p != i:
        numofswap+=0.5
    i+=1

if numofswap <= 1:
    print("YES")
else:
    print("No")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
p = list(map(int, input().split()))
P = sorted(p)
ans = 0
for i in range(N):
    if p[i] == P[i]:
        ans += 0
    else:
        ans +=1
print("Yes" if ans < 3 else "No")

Submission status: Wrong Answer

Solution code:
n = int(input())
p = list(map(int, input().split()))
sorted_p = sorted(p)
arr = []
ban = [0 for l in range(n)]
for i in range(n):
    min_el = min(p[i:])
    idx = p.index(min_el)
    ban[idx] = 1
    if ban[i] != 1:
        arr.append(min_el)
        p[i], p[idx] = p[idx], p[i]
print ("YES" if arr == sorted_p else 'NO')

Submission status: Wrong Answer

Solution code:
n = int(input())
p = list(map(int, input().split()))
sorted_p = sorted(p)
arr = []
for i in range(n):
    min_el = min(p[i:])
    arr.append(min_el)
    idx = p.index(min_el)
    p[i], p[idx] = p[idx], p[i]
print ("YES" if arr == sorted_p else 'NO')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n =int(input())
p = [int(_) for _ in input().split()]
cnt =0
for i in range(len(p)):
  if  p[i] !=(i+1):
    cnt +=1
print('Yes' if cnt <=2 else 'No')

Submission status: Wrong Answer

Solution code:
n =int(input())
p = [int(_) for _ in input().split()]
cnt =0
for i in range(2, len(p)):
  if  p[i]-p[i-1] !=1:
    cnt +=1
print('Yes' if cnt <=1 else 'No')

Submission status: Wrong Answer

Solution code:

def ans():
    n = int(input())
    ps = list(map(int, input().split()))
    cnt = 0
    for i in range(n):
        print(i+1, ps[i])
        if i+1 != ps[i]:
            cnt += 1
        if cnt >= 3:
            return False
    return True


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

Submission status: Wrong Answer

Solution code:

def ans():
    n = int(input())
    ps = list(map(int, input().split()))
    cnt = 0
    for i in range(n):
        if i+1 != ps[i]:
            cnt += 1
        if cnt >= 3:
            return False
    return True


if ans():
    print('YES')
else:
    print('No')

Submission status: Wrong Answer

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

P = sorted(p)

count = 0

for i in range(N):
    if p[i] == P[i]:
        count += 1
    else:
        continue

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

Submission status: Wrong Answer

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

P = sorted(p)

count = 0

for i in range(N):
    if p[i] == P[i]:
        count += 1
    else:
        continue

if count == N-2:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

P = sorted(p)

count = 0

for i in range(N):
    if not p[i] == P[i]:
        count += 1
    else:
        continue

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

Submission status: Wrong Answer

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

P = sorted(p)

count = 0

for i in range(N):
    if not p[i] == P[i]:
        count += 1
    else:
        continue

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

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
p = list(map(int,raw_input().split()))
p_sort = sorted(p)

ans = 0
for i in range(0,N):
  if p[i] != p_sort[i]:
    ans = ans + 1
if ans == 2 or ans == 0:
  print "Yes"
else:
  print "No"

Submission status: Wrong Answer

Solution code:
#ABC135B - 0 or 1 Swap
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:
    print("YES")
elif count == 2:
    print("YES")
else:
    print("NO")
print(count)

Submission status: Wrong Answer

Solution code:
#ABC135B - 0 or 1 Swap
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 2:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
#ABC135B - 0 or 1 Swap
N = int(input())
p = list(map(int,input().split()))
for i in range(N):
    if p[i] != i+1:
        a = p[i]
        p[i] = i+1
        p[a-1] = a
        break
print(p)
if p == [i for i in range(1,N+1,1)]:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
list_p=list(map(int,input().split()))
np_list_p=np.array(list_p)
np_list_s =np.array(sorted(list_p))
minus=list(np_list_p - np_list_s)
print("Yes" if minus.count(0) == N or minus.count(0)== N-2 else "No")

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
list_p=list(map(int,input().split()))
np_list_p=np.array(list_p)
np_list_s =np.array(sorted(list_p))
minus=list(np_list_p - np_list_s)
print("Yes" if minus.count(0) == N or minus.count(0)== N-2 else "No")
print(minus.count(0))

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
list_p=list(map(int,input().split()))
print(list_p)
np_list_p=np.array(list_p)
np_list_s =np.array(sorted(list_p))
minus=list(np_list_p - np_list_s)
print("Yes" if minus.count(0) == N or N-2 else "No")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#input 数列の要素数N、並び替えた数列p
#output pの要素を一組並べ替えて昇順にすることができるか "Yes" or "No"

N = int(input())
plist = tuple(map(int,input().split()))
answer_p = list(plist)
answer_p.sort()
able = False

for i in range(N-1):
    if able == True:
        break
    p = list(plist)
    j = i + 1
    for j in range(N):
        if able == True:
            break
        p = list(plist)
        p[i] = plist[j]
        p[j] = plist[i]
        if p == answer_p:
            print('Yes')
            able = True

if able == False:
    print('No')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if cnt ==0 or cnt ==1:
    print('YES')
else:
        print('NO')

Submission status: Wrong Answer

Solution code:
n,*p = map(int,open(0).read().split())
ans = 0
for i in range(n):
    if i+1 != p[i]:
        ans += 1
print('YES' if ans == 2 else 'NO')

Submission status: Wrong Answer

Solution code:
n,*p = map(int,open(0).read().split())
ans = 0
for i in range(n):
    if i+1 != p[i]:
        if i+1 == p[p[i]-1]:
            ans += 1

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

Submission status: Wrong Answer

Solution code:
def swap(a,i,j):
    a[i-1],a[j-1]=a[j-1],a[i-1]
    return a
n=int(input())
a=list(map(int,input().split()))
b=sorted(a)
for i in range(n-1):
    z=b[i]
    if a[i]!=b[i]:
        swap(a,i+1,a.index(z)+1)
    if a == b:
        print("YES")
        break
    print("NO")
    break

Submission status: Wrong Answer

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

z = 0

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

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

Submission status: Wrong Answer

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

ancountinue_point_cnt = 0
ancountinue_list = []

for i in range(n-1):
  if ancountinue_point_cnt == 3:
    break
  if p[i + 1] != p[i] + 1:
    ancountinue_point_cnt += 1
    ancountinue_list.append(p[i])


if ancountinue_point_cnt == 2:
  if ancountinue_list[0] == (ancountinue_list[1] +1):
    print("YES")
    exit()
  elif ancountinue_list[1] == (ancountinue_list[0] + 2):
    print("YES")
    exit()
elif ancountinue_point_cnt == 0:
  print("YES")
  exit()
  
print("NO")

Submission status: Wrong Answer

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

ancountinue_point_cnt = 0
ancountinue_list = []

for i in range(n-1):
  if ancountinue_point_cnt == 3:
    break
  if p[i + 1] != p[i] + 1:
    ancountinue_point_cnt += 1
    ancountinue_list.append(p[i])

  
if ancountinue_point_cnt == 2:
  if ancountinue_list[0] == (ancountinue_list[1] +1):
    print("YES")
elif ancountinue_point_cnt == 0:
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

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

ancountinue_point_cnt = 0
ancountinue_list = []

for i in range(n-1):
  if p[i + 1] != p[i] + 1:
    ancountinue_point_cnt += 1
    ancountinue_list.append(p[i])
  if ancountinue_point_cnt == 3:
    break
  
if ancountinue_point_cnt == 2:
  if ancountinue_list[0] == (ancountinue_list[1] +1):
    print("YES")
elif ancountinue_point_cnt == 0:
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

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

ancountinue_point_cnt = 0
ancountinue_list = []

for i in range(n-1):
  if p[i + 1] != p[i] + 1:
    ancountinue_point_cnt += 1
    ancountinue_list.append(p[i])
  if ancountinue_point_cnt == 3:
    break
  
if ancountinue_point_cnt == 2:
  if ancountinue_list[0] == (ancountinue_list[1] +1):
    print("YES")
elif ancountinue_point_cnt == 0:
  print("YES")
elif ancountinue_point_cnt == 1:
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

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

ancountinue_point_cnt = 0
ancountinue_list = []

for i in range(n-1):
  if p[i + 1] != p[i] + 1:
    ancountinue_point_cnt += 1
    ancountinue_list.append(p[i])
  if ancountinue_point_cnt == 3:
    break
  

if ancountinue_point_cnt == 2:
  if ancountinue_list[0] == (ancountinue_list[1] +1):
    print("YES")
elif ancountinue_point_cnt == 0:
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

def is_sorted(array):
    v0 = array[0]
    for i in range(1, len(array)):
        v = array[i]
        if v0 > v:
            return False
        v0 = v
    return True
    

for i in range(0, N - 1):
    for j in range(i + 1, N):
        tmp = P[i]
        P[i] = P[j]
        P[j] = tmp

        if is_sorted(P):
            print("YES")
            exit()

        tmp = P[i]
        P[i] = P[j]
        P[j] = tmp

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] != (1+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()))
P_answer=[i+1 for i in range(N)]
swap=[0 for i in range(N)]

for i in range(N):
    i_place=P.index(i+1)
    if swap[i]==0 and swap[i_place]==0:
        P[i_place],P[i]=P[i],P[i_place]
        swap[i]=1
        swap[i_place]=1

        
if P==P_answer:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
n=int(input())
x=list(input().split())
xsort=sorted(x)
flag=0
for i in range(n):
  if x[i]!=xsort[i]:
    flag+=1

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

Submission status: Wrong Answer

Solution code:
n = int(input())
p = [int(x) for x in input().split()]
tmp=0
s=0
cnt=0
e=0 

for i in range(0,n-1):
   if p[i] > p[i+1]:
      if i == 0:
         cnt+=1
         s=i
         # print(s)  # 交換する場所
      else:
         cnt+=1
         e=i+1
         # print(e)  # 交換する場所
   if i == n-2 and cnt==2:
      # print("WW")
      tmp=p[s]
      p[s]=p[e]
      p[e]=tmp
   
if sorted(p) == p:
   print("YES")
else:
   print("NO")

Submission status: Wrong Answer

Solution code:
n = int(input())
p = [int(x) for x in input().split()]
tmp=0
s=0
cnt=0
e=0 

for i in range(0,n-1):
   # print(p[i])
   if p[i] > p[i+1]:
      if i == 0:
         cnt+=1
         s=i
         # print(s)  # 交換する場所
      else:
         cnt+=1
         e=i+1
         # print(e)  # 交換する場所
   if i == n-1 and cnt==2:
      tmp=p[s]
      p[s]=p[e]
      p[e]=tmp
   
if sorted(p) == p:
   print("YES")
else:
   print("NO")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

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

def judge():
    flag = 1
    for j in range(N-1):
        if p[j]>p[j+1]:
            flag = 0
    return flag

if judge() == 0:
    temp_max = max(p)
    ind_max = p.index(max(p))
    ind_min = p.index(min(p))
    p[ind_max] = min(p)
    p[ind_min] = temp_max

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

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

def judge():
    flag = 1
    for j in range(N-1):
        if p[j]>p[j+1]:
            flag = 0
    return flag

if judge() == 0:
    temp_max = max(p)
    ind_max = p.index(max(p))
    ind_min = p.index(min(p))
    p[ind_max] = min(p)
    p[ind_min] = temp_max

if judge() == 1:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
x = map(int, raw_input().strip().split())
y = sorted(x)
c = len([i for i in xrange(N) if x[i] == y[i]])
print "YES" if c <= 2 else "NO"

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
p = [int(i) for i in input().split()]
a = 0
for i in range(N):
    if p[i] == (i+1):
        continue
    else :
        a += 1
if a <= 2 :
    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(1, N):
  if p[i]!=p[i-1]+1:
    cnt+=1
  if cnt>=3:
    ans="NO"
    break
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from copy import deepcopy


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

    for i in range(n):
        for j in range(i, n):
            # if i == j:
            #     continue
            p_temp = deepcopy(p)
            temp = p_temp[i]
            p_temp[i] = p_temp[j]
            p_temp[j] = temp
            print(p, p_temp)
            if p_temp == sorted(p):
                print('YES')
                return

    print('NO')


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

if len(t)%2 != 0 or sum(t) == -(n-1):
    print("NO")
else:
    if len(t)==0:
        print("YES")
    else:
        k = len(t)//2
        for i in range(k):
            if t[i] != t[len(t)-(1+i)]:
                print("NO")
                break
        else:
            print("YES")

Submission status: Wrong Answer

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

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

if len(t)%2 != 0:
    print("NO")
else:
    if len(t)==0:
        print("YES")
    else:
        k = len(t)//2
        for i in range(k):
            if t[i] != t[len(t)-(1+i)]:
                print("NO")
                break
        else:
            print("YES")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
p_list = input().split()

count = 0

for i in range(n):
    if i+1 != int(p_list[i]):
        count = count + 1

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

Submission status: Wrong Answer

Solution code:
n = int(input())
p_list = input().split()

count = 0

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
p_list = input().split()

mihon = sorted(p_list)

count = 0

for i in range(n):
    if mihon[i] != p_list[i]:
        count = count + 1

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