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())
ps = input().split()
ps = list(map(int, ps))
diffs = 0
if ps[0] == n:
    for i in range(n):
        if n - i != ps[i]:
            diffs += 1
else:
    for i in range(n):
        if i + 1 != ps[i]:
            diffs += 1
if diffs > 2:
    print('NO')
else:
    print('YES')

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

if cnt == n-1 or check == 2 :
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

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

if cnt == n-1 or check == 2 :
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

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

if cnt == n-1 or check == 2 :
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

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

if cnt == n-1 or check == 2 :
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

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

if cnt == n-1 or check == 2 :
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

if q <= 2:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
p = [int(i) for i in input().split(" ")]
if len(p) == 0:
    print("YES")
else:
    c = [0 if p[i]==i+1 else 1 for i in range(n)]
    if np.sum(c) > 3:
        print("NO")
    else:
        print("YES")

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
p = [int(i) for i in input().split(" ")]
if len(p) == 0:
    print("YES")
else:
    c = [0 if p[i]!=i+1 else 0 for i in range(n)]
    if np.sum(c) > 3:
        print("NO")
    else:
        print("YES")

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
p = [int(i) for i in input().split(" ")]
if len(p) == 0:
    print("YES")
else:
    c = [0 if p[i]==i+1 else 0 for i in range(n)]
    if np.sum(c) > 3:
        print("NO")
    else:
        print("YES")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())

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

Submission status: Wrong Answer

Solution code:
def main(): 

    n = int(input())
    p = input().split()
    ps = sorted(p)

    cnt = 0

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

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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(input().split())
Snots=[]
count=0
for i in range(N):
  Snots.append(S[i])
Snots.sort()

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


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

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(input().split())
Snots=[]
count=0
for i in range(N):
  Snots.append(S[i])
Snots.sort()

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


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

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(input().split())
Snots=[]
count=0
for i in range(N):
  Snots.append(S[i])
S.sort()

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


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

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(input().split())
Snots=[]
count=0
for i in range(N):
  Snots.append(S[i])
S.sort()

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


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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import copy

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

has_changed = False
for i in range(N):
    expect = i + 1
    #print(p)
    #print(p[i], expect)
    if p[i] != expect:
        if has_changed:
            print('NO')
            exit()
        index = p[i] - 1
        if p[index] == expect:
            has_changed = True
            tmp = copy.deepcopy(p[i])
            p[i] = expect
            p[index] = tmp
            print('change', p[i], p[index])
        else:
            print('NO')
            exit()

print('YES')

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:
	print('Yes')
elif 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 == N:
	print('Yes')
elif ans == N-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 == N or ans == N-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-1):
	if p[i] == i :
		ans += 1

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from heapq import heapify
from heapq import heappop
n=int(input())
p=list(map(int,input().split()))
q=p.copy()
heapify(q)
c = 0

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

print('Yes' if c==2 else 'No')

Submission status: Wrong Answer

Solution code:
N = int(input())
l = list(map(int,input().split()))
tmp = 0

for i in range(N-1):
  if l[i] != i:
    tmp +=1

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

Submission status: Wrong Answer

Solution code:
N = int(input())
l = list(map(int,input().split()))
tmp = 0

for i in range(N-1):
  if l[i] != i:
    tmp +=1

if tmp <=1: 
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

Solution code:
N = int(input())
l = list(map(int,input().split()))
flag = False
tmp = 0

for i in range(N-1):
  if l[i] <= l[i+1]:
    continue
  elif l[i] > l[i+1] and flag == False:
    tmp = l[i]
    l[i] = l[i+1]
    l[i+1] = tmp
    flag = True
    continue
  else:
    print("NO")
    quit()

print("YES")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
p = [int(i) for i in range(1,n+1)]
s = 0
for i in range(n):
  if p[i] != i + 1:
    s += 1
if s > 2:
  print("No")
else:
  print("Yes")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
p = [int(i) for i in range(n)]
s = 0
for i in range(n-1):
  if p[i] != i + 1:
    s += 1
if s > 2:
  print("No")
else:
  print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())
p = [int(i) for i in range(n)]
s = 0
for i in range(n-1):
  if p[i] > p[i+1]:
    s += 1
if s >= 3:
  print("No")
else:
  print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())
p = [int(i) for i in range(n)]
s = 0
for i in range(n-1):
  if p[i] > p[i+1]:
    s += 1
if s >= 2:
  print("No")
else:
  print("Yes")

Submission status: Wrong Answer

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

if count == 0 or 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(1,n+1):
    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()))
count = 0

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

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

Submission status: Wrong Answer

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

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

if count > 2:
    print("NO")

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate
import sys


def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


def main():
    n = I()
    num = LI()
    for i in range(n):
        for j in range(n):
            tmp = num
            tmp[i], tmp[j] = tmp[j], tmp[i]
            if tmp == sorted(num):
                return 'YES'
    return 'NO'


print(main())

Submission status: Wrong Answer

Solution code:
n = int(input())
p = list(map(int,input().split()))
flag = False
for i in range(n):
    for j in range(n):
        q = p.copy()
        q[i], q[j] = q[j], q[i]
        print(q)
        if q == sorted(q):
            flag = True
            break
if flag:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
# -*- coding:utf8 -*-

n = int(input())
l = list(map(int, input().split()))
c = 0
for i,n in enumerate(l,1):
    if n != i:
        c += 1
ans = 'Yes' if c == 0 or c == 2 else 'No'
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
p = list(map(int,input().split()))
flag = False
for i in range(n):
    q = p
    for j in range(n):
        q[i], q[j] = q[j], q[i]
        if q == sorted(q):
            flag = True
            break
if flag:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
n = int(input())
p = list(map(int,input().split()))
flag = False
for i in range(n):
    q = p
    for j in range(n):
        q[i], q[j] = q[j], q[i]
        if q == sorted(q):
            flag = True
            break
if flag:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
p = list(map(int, input().split()))
sort_p = sorted(p)
if p == sort_p:
    print('Yes')
else:
    p = np.array(p)
    sort_p = np.array(sort_p)
    index = np.where(p != sort_p)
    if len(p[index]) == 2:
        p[index[0][0]],p[index[0][1]] = p[index[0][1]],p[index[0][0]]
        p = list(p)
        sort_p = list(sort_p)
        if p == sort_p:
            print('Yes')
        else:
            print('No')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate
import sys


def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


def main():
    n = I()
    num = LI()



    for i in range(n):
        for j in range(n):
            tmp = num
            tmp[i], tmp[j] = tmp[j], tmp[i]
            if num == sorted(tmp):
                return 'YES'
    return 'NO'



print(main())

Submission status: Wrong Answer

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

res = 0
a_sort = sorted(a)

for i in range(n):
    if a_sort[i] != a[i]:
        res += 1

if res > 3:
    print("NO")
else:
    print("YES")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int, input().split()))
ans='Yes'
now=a[0]-1
for i in a: 
    if now>i:
        ans='No'
    now=max(now, i-1)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
p_list = list(int(pi) for pi in input().split(' '))

num_opposite = 0
indices = []

for i in range(N-1):
  p_1st = p_list[i]
  p_2nd = p_list[i+1]
  
  if p_1st<=p_2nd:
    pass
  else:
    num_opposite+=1
    if num_opposite==1:
      indices.append(i)
    else:
      indices.append(i+1)
      
  
  if num_opposite >=3:
    break 

if num_opposite == 0:
  print('YES')
elif num_opposite == 1:
  print('YES')
elif num_opposite == 2:
  small_idx = indices[0]
  large_idx = indices[1]
  
  p_small = p_list[small_idx]
  p_large = p_list[large_idx]
  
  if (p_small==p_list[large_idx-1]+1) and (p_large==p_list[small_idx+1]-1):
    print('YES')
  else:
    print('NO')
else:
  print('NO')

Submission status: Wrong Answer

Solution code:
N = int(input())
p_list = list(int(pi) for pi in input().split(' '))

num_opposite = 0
indices = []

for i in range(N-1):
  p_1st = p_list[i]
  p_2nd = p_list[i+1]
  
  if p_1st<=p_2nd:
    pass
  else:
    num_opposite+=1
    if num_opposite==1:
      indices.append(i)
    else:
      indices.append(i+1)
      
  
  if num_opposite >=3:
    break 

if num_opposite == 1:
  print('YES')
elif num_opposite == 2:
  small_idx = indices[0]
  large_idx = indices[1]
  
  p_small = p_list[small_idx]
  p_large = p_list[large_idx]
  
  if (p_small==p_list[large_idx-1]+1) and (p_large==p_list[small_idx+1]-1):
    print('YES')
  else:
    print('NO')
else:
  print('NO')

Submission status: Wrong Answer

Solution code:
N = int(input())
p_list = list(int(pi) for pi in input().split(' '))

num_opposite = 0
indices = []

for i in range(N-1):
  p_1st = p_list[i]
  p_2nd = p_list[i+1]
  
  if p_1st<=p_2nd:
    pass
  else:
    num_opposite+=1
    if num_opposite==1:
      indices.append(i)
    else:
      indices.append(i+1)
      
  
  if num_opposite >=3:
    break
    print('NO')   

if num_opposite == 1:
  print('YES')
elif num_opposite == 2:
  small_idx = indices[0]
  large_idx = indices[1]
  
  p_small = p_list[small_idx]
  p_large = p_list[large_idx]
  
  if (p_small==p_list[large_idx-1]+1) and (p_large==p_list[small_idx+1]-1):
    print('YES')
  else:
    print('NO')

Submission status: Wrong Answer

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


for i in range(N):
    if ans[i] != p[i]:
        cot += 1
print("YES" if cot == 2 else "NO")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

L=[]
for i in range(n):
    if i+1 !=p[i]:
        L.append([i, p[i]])
    if len(L)==2:
        break


if len(L)<=1:
    print('Yes')
else:
    p[L[0][0]] = L[1][1]
    p[L[1][0]] = L[0][1]
    if p == sorted(p):
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
N = int(input())
p = list(map(int,input().split()))
maxh = p.index(max(p))
minr = len(p)-(1+list(reversed(p)).index(min(p)))
sw = p
if minr>maxh:
    sw[minr], sw[maxh] = sw[maxh],sw[minr]
ans = "YES"
for i in range(N-1):
    if sw[i]>sw[i+1]:
        ans = "NO"
        break
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())

lst = input().split()
cnt = 0

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())

lst = input().split()

lst2 = sorted(lst)

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())

lst = input().split()

lst2 = sorted(lst)

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())

lst = input().split()
print(lst) #debug

lst2 = sorted(lst)
print(lst2) #debug

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

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

Submission status: Wrong Answer

Solution code:
import copy

n = int(input())
lst1 = list(map(int,input().split()))
lst2 = copy.copy(sorted(lst1))

c=0
for i in range(n):
    if lst1[i]==lst2[i]:
        pass
    else:
        c+=1
        if c > 2:
            print("No")
            break
print("Yes")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())
p = list(map(int,input().split()))
p_sorted = sorted(p)
cnt = 0
for i in range(N):
    if p[i] != p_sorted[i]:
        cnt += 1
    if cnt>3:
        print("NO")
        sys.exit()

print("YES")

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())
p = list(map(int,input().split()))
p_sorted = sorted(p)
cnt = 0
for i in range(N):
    if p[i] != p_sorted[i]:
        cnt += 1
    if cnt>3:
        print("NN")
        sys.exit()

print("YES")

Submission status: Wrong Answer

Solution code:
import sys

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

cnt = 0

for i in range(N):
    if p[i] != p_sorted[i]:
        cnt += 1
    if cnt==3:
        print("No")
        sys.exit()

print("Yes")

Submission status: Wrong Answer

Solution code:
N=int(input())
p=input()
s = [x for x in range(1,N+1) if str(x)!=str(p[2*(x-1)])]
if len(s)==0 or len(s)==2:
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

Solution code:
N = int(input())
p = input().split()
P = sorted(p)
w = 0

i = 0
while i <= N-1:
  if p[i] == P[i]:
    i += 1
  
  else:
    w += 1
    i += 1
    
if w == 0 or w == 2:
  print('YES')
  
else:
  print('NO')

Submission status: Wrong Answer

Solution code:
N = int(input())
p = input().split()
P = sorted(p)
w = 0

i = 0
while i <= N-1:
  if p[i] == P[i]:
    i += 1
  
  else:
    w += 1
    i += 1
    
if w == 2:
  print('YES')
  
else:
  print('NO')

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = "YES"
count = 0
diff = 0
for i in range(1,n):
    rise = p[i] - p[i-1]
    if rise != 1 and diff == 0:
        diff = rise
        count += 1
    elif rise != 1 and diff == rise:
        diff = 0
        count += 1
    elif rise != 1 and diff != rise:
        ans = "NO"
        break

if count > 2:
    ans = "NO"
print(ans)

Submission status: Wrong Answer

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

q = []
for x in range(N):
    q.append(x+1)

i = 0
c = 0
ans = "NO"
while(i < N):
    if p[i] != q[i]:
        c += 1
    if c > 2:
        break
    i += 1

if c == 2:
    ans = "YES"

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
r=list(map(int,input().split()))
a=sorted(r)
a=map(str,a)
r=map(str,r)
  
r="".join(r)
a="".join(a)
 
count=0
i=0
while i<len(r):
  if r[i]!=a[i]:count+=1
  i+=1
    
print("YES" if count<=2 else "NO")

Submission status: Wrong Answer

Solution code:
n = int(input())
P = list(map(int, input().split()))
C = list(range(1, n+1, 1))

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

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

Submission status: Wrong Answer

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

n = int(input())

p = list(map(int, input().split()))
f = 0

for i in range(len(p) - 1):
    pi = p[i]
    if p[i] != i+1:
        if p[p[i] - 1] == i + 1:
            p[i], p[pi - 1] = p[pi - 1], p[i]
            f += 1
        else:
            f = 2

if 0 <= f <= 1:
    print("YES")
else:
    print("NG")

Submission status: Wrong Answer

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

n = int(input())

p = list(map(int, input().split()))
f = 0

for i in range(len(p) - 1):
    pi = p[i]
    if p[i] != i+1:
        if p[p[i] - 1] == i + 1:
            p[i], p[pi - 1] = p[pi - 1], p[i]
            f += 1
            print(p,i)
        else:
            f = 2
            print(p)

if 0 <= f <= 1:
    print("YES")
else:
    print("NG")

Submission status: Wrong Answer

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

n = int(input())

p = list(map(int, input().split()))
f = 0

for i in range(len(p) - 1):
    if p[i] != i+1:
        if p[p[i] - 1] == i + 1:
            p[i], p[p[i] - 1] = p[p[i] - 1], p[i]
            f += 1
        else:
            f = 2

if 0 <= f <= 1:
    print("YES")
else:
    print("NG")

Submission status: Wrong Answer

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

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

ac_list = sorted(input_list)

count = 0
for x in zip(input_list, ac_list):
    if x[0] != x[1]:
        count += 1
    if count > 3:
        print("No")
        break
else:
    print("Yes")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def array_check():
    if p == sorted(p):
        print("YES")
        exit()

n = int(input())
p = list(map(int, input().split()))
max_index = p.index(max(p))
min_index = p.index(min(p))
ans = False

array_check()
p[max_index], p[min_index] = p[min_index], p[max_index]
array_check()

print("NO")

Submission status: Wrong Answer

Solution code:
import copy
n = int(input())
p = list(map(int,input().split()))
r = list()
for k in range(n):
    r.append(k+1)
if p == r:
    print("YES")
    exit()
for i in range(0,n-1):
    for j in range(i+1,n):
        q = copy.copy(p)
        q[j] = p[i]
        q[i] = p[j]
        print(q)
        if q == r:
            print("YES")
            exit()

print("NO")

Submission status: Wrong Answer

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

for i in range(n):
    if ps[i]!=1:
        cnt+=1

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

Submission status: Wrong Answer

Solution code:
N=int(input())
p = list(map(int,(input().split())))
ps=sorted(p)
mx=p.index(max(p))
p[mx],p[N-1] =p[N-1],p[mx]
if p == ps:
    print("YES")
else: print("NO")

Submission status: Wrong Answer

Solution code:
N=int(input())
p = list(map(int,(input().split())))
ps=sorted(p)
if p == ps:
    print("YES")
else:    
    mx=p.index(max(p))
    mn=p.index(min(p))
    p[mx],p[mn] =p[mn],p[mx]
    if p == ps:
        print("YES")
    else: print("NO")