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:
import numpy as np
n = int(input())
p = np.array(list(map(int,input().split())))

a = np.arange(1, n+1)
tmp = p - a
cnt = np.count_nonzero(tmp != 0)

flg = False
if cnt == 0 or (cnt == 2 and tmp.sum() == 0):
    flg = True

print('Yes') if flg else print('No')

Submission status: Wrong Answer

Solution code:
#create date: 2020-07-05 10:48

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    p = na()
    for i in range(n-1):
        for j in range(i, n):
            q = p.copy()
            q[i] = p[j]; q[j] = p[i]
            now = q[i]
            f = True
            for qi in q:
                if now > qi:
                    f = False
                    break
                now = qi
            if f:
                print("YES")
                quit()
    print("NO")



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#create date: 2020-07-05 10:48

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    p = na()
    for i in range(n-1):
        for j in range(i, n):
            q = p.copy()
            q[i] = p[j]; q[j] = p[i]
            now = q[i]
            f = True
            for qi in q:
                if now > qi:
                    f = False
                    break
                now = qi
            if f:
                print("Yes")
                quit()
    print("No")



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

print("YES" if diff==2 else "NO")

Submission status: Wrong Answer

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

cnt = 0
for i in range(N):
  for j in range(i+1,N):
    temp = 0
    good = True
    for k in range(N):
      if k == i:
        if temp > p[j]:
          good = False
          break
        else:
          temp = p[j]
      elif k == j:
        if temp > p[i]:
          good = False
          break
        else:
          temp = p[i]
      else:
        if temp > p[k]:
          good = False
          break
        else:
          temp = p[k]
    if good:
      break
  if good:
    break
if good:
  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(N):
  for j in range(i+1,N):
    temp = 0
    good = True
    for k in range(N):
      if k == i or k == j:
        continue
      else:
        if temp > p[k]:
          good = False
          break
        else:
          temp = p[k]
    if good:
      break
  if good:
    break
if good:
  print('YES')
else:
  print('NO')

Submission status: Wrong Answer

Solution code:
n = int(input())
pn = [int(num) for num in input().split()]

k = 0
for i in range(1, len(pn)):
    if (i+1) != pn[i]:
      k += 1

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

Submission status: Wrong Answer

Solution code:
n = int(input())
pn = [int(num) for num in input().split()]

k = 0
for i in range(1, len(pn)):
    if (i+1) != pn[i]:
      k += 1

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
p=[int(j) for j in input().split()]
s=range(n)
x=0
  
c=0

for a in range(n):
  if p[a]!=s[a]:
    c=c+1
  

if c>2:
  print('NO')
  
if c<=2:
  print('YES')

Submission status: Wrong Answer

Solution code:
n=[int(s) for s in input().split()]
p=[int(s) for s in input().split()]
count=0
expected=0
a=0
f=0
for i in p:
  if i==a+1:
    a+=1
  else:
    if count>0:
      f=1
    if expected==0:
      expected=i
      a+=1
    else:
      if expected==a+1:
        count+=1
        a+=1

if f==0:
  print('YES')
else:
  print('NO')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
p=list(map(int,input().split()))
ok=True
for i in range(1,n):
  if p[i]-p[i-1]>0:
    continue
  ok=False
if ok:
  print("YES")
  exit(0)

for i in range(n):
  for j in range(n):
    if i==j:continue
    t=p[:]
    taihi=t[i]
    t[i]=t[j]
    t[j]=taihi
    ok=True
    for i in range(1,n):
      if t[i]-t[i-1]>0:
        continue
      ok=False
    if ok:
      print("YES")
      exit(0)
print("NO")

Submission status: Wrong Answer

Solution code:
import sys

N = int(sys.stdin.readline())
P = list(map(int, sys.stdin.readline().split()))

targets = []
for i in range(N):
    if P[i] != i+1:
        targets.append(P[i])

if not targets:
    print("YES")
elif len(targets) != 2 or sum(targets) != N+1:
    print("NO")
else:
    print("YES")

Submission status: Wrong Answer

Solution code:
import sys
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def Main():
    n = I()
    p = list(IL())
    flag = 2
    for i in range(1,len(p)):
        if p[i-1]<p[i]:
            flag -= 1
        if flag==-1:
            print('NO')
            exit()
    print('YES')
    return

if __name__=='__main__':
    Main()

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
c=0
for i in range(n):
  c+=(a[i]==i+1)*1
print(['YES','NO'][c<n-1])

Submission status: Wrong Answer

Solution code:
import sys
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def Main():
    n = I()
    p = list(IL())
    flag = 2
    for i in range(1,len(p)):
        if p[i-1]!=p[i]-1:
            flag -= 1
    if flag>=0:
        print('YES')
    else:
        print('NO')
    return

if __name__=='__main__':
    Main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
import numpy as np
import math
sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def Main():
    n = I()
    p = list(IL())
    flag = 2
    for i in range(1,len(p)):
        if p[i-1]!=p[i]-1:
            flag -= 1
    if flag>=0:
        print('Yes')
    else:
        print('No')
    return

if __name__=='__main__':
    Main()

Submission status: Wrong Answer

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

ans = "YES"
cnt = 0
for i in range(n):
    if p[i] != i+1:
        if p[p[i]-1] == i+1:
            if cnt == 0:
                cnt += 1
            else:
                ans = "NO"
                break
        else: 
            ans = "NO"
            break
print(ans)

Submission status: Wrong Answer

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

ans = "YES"
for i in range(n):
    if p[i] != i+1:
        if p[p[i]-1] == i+1:continue
        else: 
            ans = "NO"
            break
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(map(int, input().split()))
Min_S = min(S)
Min_idx = S.index(Min_S)
Sort_S = sorted(S)


S[0], S[Min_idx] = S[Min_idx], S[0]
if S == Sort_S:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

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

Max_S = max(S)
Max_idx = S.index(Max_S)
Min_S = min(S)
Min_idx = S.index(Min_S)
Sort_S = sorted(S)

S[Max_idx], S[Min_idx] = S[Min_idx], S[Max_idx]
if S == Sort_S:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    P = il()
    cnt = 0
    for n in range(N):
        if P[n] != n + 1:
            cnt += 1
    print('NO' if cnt > 3 else 'YES')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
Sort = [str(x) for x in range(1,N+1)]
P = [str(x) for x in input().split()]

Count = 0
for T in range(0,N):
    if Sort[T] != P[T]:
        print(Sort[T])
        Count += 1
if Count==0 or Count==2:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
N = int(input())
Sort = ''.join([str(x) for x in range(1,N+1)])
P = ''.join([str(x) for x in input().split()])

Count = 0
for T in range(0,N):
    if Sort[T] != P[T]:
        Count += 1
if Count==0 or Count==2:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
N = int(input())
Sort = ''.join([str(x) for x in range(1,N+1)])
P = ''.join([str(x) for x in input().split()])

Flag = True
Count = 0
for SC,TC in zip(Sort,P):
    if SC != TC:
        Count += 1
    if Count >= 3:
        Flag = False
        break
if Flag:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
N = int(input())
Sort = ''.join([str(x) for x in range(1,N+1)])
P = ''.join([str(x) for x in input().split()])

Flag = True
Count = 0
for SC,TC in zip(Sort,P):
    if SC != TC:
        Count += 1
    if Count >= 3:
        Flag = False
        break
if Flag:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

judge = 0
for i in range(n):
    if p[i] != i + 1:
        judge += 1
if judge >= 3:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

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

judge = 0
for i in range(n):
    if p[i] != i + 1:
        judge += 1
if judge >= 3:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

for i in range(1,n):
    if abs(p[i-1] - p[i]) > 1:
        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 = p
k = sorted(p)
count = 0
for i in range(n):
    if q[i] != k[i]:
        count += 1
if count == 2 or count ==0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    P = il()
    for n in range(N):
        if n + 1 != P[n]:
            if P[P[n] - 1] == n + 1:
                print('YES')
            else:
                print('NO')
            exit()
    else:
        print('YES')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

flg = 0
for i in range(1, n):
    if p[i] - p[i - 1] < 0:
        flg += 1
    else:
        pass
if flg == 2 or flg == 0:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
n = int(input())

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

arr2 = sorted(arr)

count = 0 

for i in range(0,n):
  if arr[i] != arr2[i]: count += 1
if count <= 2: print("Yes")
else: print("No")

Submission status: Wrong Answer

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *P = map(int, read().split())

    k = sum(1 for i, p in enumerate(P, 1) if i != p)

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
list=input().split()
for all in list:
    all=int(all)
flag=False
c=0
x="YES"
leng=len(list)
for i in range(leng-1):
    if list[i]>list[i+1]:
        c=c+1
        t=list[i]
        list[i]=list[i-1]
        list[i-1]=t
        print(list)      
    if c==2:
        x="NO"
        break
print(x)

Submission status: Wrong Answer

Solution code:
N=int(input())
list=input().split()
for all in list:
    all=int(all)
flag=False
c=0
x="YES"
leng=len(list)
for i in range(leng-1):
    if list[i]>list[i+1]:
        c=c+1
        t=list[i]
        list[i]=list[i-1]
        list[i-1]=t
        print(list)
    if list[i]>list[i+1]:
        c=c+1
        t=list[i]
        list[i]=list[i+1]
        list[i+1]=t        
    if c==2:
        x="NO"
        break
print(x)

Submission status: Wrong Answer

Solution code:
N=int(input())
list=input().split()
for all in list:
    all=int(all)
flag=False
c=0
x="YES"
leng=len(list)
for i in range(leng-1):
    if list[i]>list[i+1]:
        c=c+1
        t=list[i]
        list[i]=list[i+1]
        list[i+1]=t
    if c==2:
        x="NO"
        break
print(x)

Submission status: Wrong Answer

Solution code:
N = int(input())
p = list(map(int, input().split()))
sorted_p = sorted(p)
flg = False
for i in range(N - 1):
    for j in range(i, N):
        temp_p = p.copy()
        temp = temp_p[i]
        temp_p[i] = temp_p[j]
        temp_p[j] = temp
        if temp_p == sorted_p:
            print('Yes')
            flg = True
            break
    if flg:
        break
else:
    print('No')

Submission status: Wrong Answer

Solution code:
input()
a = list(map(str, input().split()))
if sorted(a) == a:
    print("YES")
else:
    m = 0
    for i in range(len(a)):
        if a[i] in sorted(a)[i]:
            m+=1
    if m==len(a)-2:
        print("YES")
    else:
        print("NO")

Submission status: Wrong Answer

Solution code:
import copy
import sys
N = int(input())
H = list(map(int,input().split()))
C = 0

if sorted(H) == H:
	print("YES")
	sys.exit()

for i in range(0,N-1):
	for j in range(1,N):
		L = copy.copy(H)
		L[1],L[3] = L[3],L[1] 
		if L == sorted(H):
			print("YES")
			sys.exit()
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("NO")
            exit()
print("YES")

Submission status: Wrong Answer

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

count = 0
for i, j in zip(p, q):
    if i != j:
        count += 1
        if count > 2:
            print("No")
            sys.exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())
P = list(map(int, input().split()))
Q = [(P[i + 1] - P[i]) for i in range(n - 1)]
print("YES" if n - Q.count(1) <= 4 else "NO")

Submission status: Wrong Answer

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

Q = [(P[i + 1] - P[i]) for i in range(n - 1)]
print("YES" if len(Q) - Q.count(1) <= 2 else "NO")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
p=list(map(int,input().split()))
ans="No"
m=0
for i in range(n-1):
    if p[i]<p[i+1]:
        ans="Yes"
        break
    else:
        for j in range(i+1,n):
            if p[i]>p[j]:
                m=p[i]
                p[i]=p[j]
                p[j]=m
                for k in range(n-1):
                    if p[i]<p[i+1]:
                        ans="Yes"
                        break
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
P = list(map(int, input().split()))
Q = sorted(P)
Q.reverse()
ans = 0
for i in range(len(P)):
  if P[i] != Q[i]:
    ans += 1
if ans > 2:
  print("NO")
else:
  print("YES")

Submission status: Wrong Answer

Solution code:
N = int(input())
P = list(map(int,input().split()))
A = []
for n in range(N):
  A.append(n+1)

count = 0
for n in range(N):
  if A[n] != P[n]:
    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()))

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

if len(p) - cnt <= 2:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
lis=sorted(l)
lis.reverse()
ans=0
for i ,j in zip(l,lis):
    if i!=j:
        ans+=1
if ans<=2:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
lis=sorted(l)
lis.reverse()
ans=0
for i ,j in zip(l,lis):
    if i!=j:
        ans+=1
if ans==2:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
ans=0
kai=0
ok=True
for i in range(n-1):
    if a[i]!=i+1:
        kai+=1
        if a[a[i]-1]!=i+1 or kai==2:
            ok=False
if ok:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
ans=0
ok=True
for i in range(n-1):
    if a[i]!=i+1:
        if a[a[i]-1]!=i+1:
            ok=False
if ok:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
ans=0
ok=True
for i in range(n-1):
    if a[i]!=i+1:
        if a[a[i]-1]!=i+1:
            ok=False
if ok:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys


def input():
    return sys.stdin.readline().strip()

def main():
    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 == 3:
                print("NO")
                return
    if count == 2:
        print("YES")
        return
    print("NO")
        
        
    
main()

Submission status: Wrong Answer

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

p_sorted = sorted(p)

is_changed = [0 if x==y else 1 for x,y in zip(p, p_sorted)]

if sum(is_changed) == 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)

is_changed = [0 if x==y else 1 for x,y in zip(p, p_sorted)]

if sum(is_changed) == 2:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

check = []

for x in range(N):
    check.append(x + 1)

count = 0
for y in range(N):
    if check[y] != p[y]:
        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()))
m = list(range(1,n+1))
count = 0
for i in range(n):
    if p[i] != m[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())))

hikaku = list(range(1,n+1))
count = 0
for i in range(n):
    if hikaku[i] != p[i]:
        count += 1
if count >3:
    print("NO")
else:
    print("YES")

Submission status: Wrong Answer

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

hikaku = list(range(1,n+1))
count = 0
for i in range(n):
    if hikaku[i] != p[i]:
        count += 1
if count >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(1,n+1):
    if i == p[i-1]:
        pass
    else:
        count += 1
        if count ==3:
            print('No')
            exit(0)
print('Yes')

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[int(x) for x in input().split()]
cnt=0
x=0
y=0
b=0
for i in range(n):
    if(i+1!=l[i]):
        cnt+=1
        if(cnt==1):
            x=l[i]
        elif(cnt==2):
            y=l[i]
        elif(cnt>0):
            b=1
            break
if(b==1):
    print("NO")
elif(l[x-1]!=y and l[y-1]!=x):
    print("NO")
else:
    print("YES")

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[int(x) for x in input().split()]
cnt=0
x=0
y=0
b=0
for i in range(n):
    if(i+1!=l[i]):
        cnt+=1
        if(cnt==1):
            x=l[i]
        elif(cnt==2):
            y=l[i]
        else:
            b=1
            break
if(b==1):
    print("NO")
elif(l[x-1]!=y and l[y-1]!=x):
    print("NO")
else:
    print("YES")

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[int(x) for x in input().split()]
cnt=0
x=0
y=0
b=0
for i in range(n):
    if(i+1!=l[i]):
        cnt+=1
        if(cnt==1):
            x=l[i]
        elif(cnt==2):
            y=l[i]
        else:
            b=1
            break
if(b==1):
    print("NO")
elif(abs(y-x)!=n-1):
    print("NO")
else:
    print("YES")

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(x) for x in input().split()]

b=sorted(a)

ans=0
for i in range(n):
  if a[i]!=b[i]:
    ans+=1
print("Yes" if ans<=2 else "No")

Submission status: Wrong Answer

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

count = 0
for i in range(N):
    if P[i] != i + 1:
        count += 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()))

count = 0
for i in range(N):
    if P[i] != i + 1:
        count += count + 1
    if count > 2:
        print('No')
        exit()

print('Yes')

Submission status: Wrong Answer

Solution code:
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N = int(input())
P = list(map(int,input().split()))

for i in range(N):
    if P[i] != i+1:
        j = P.index(P[i])
        P[i],P[j] = P[j],P[i]
        break

print("YES" if P == list(range(1,N+1)) else "NO")

Submission status: Wrong Answer

Solution code:
n = int(input())
p = list(map(int, input().split()))
q = sorted(p)
s = sum(pi != qi for pi, qi in zip(p, q))
if s == 0 or s == 2:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
N = int(input())
P = list(map(int, input().split()))
Q = sorted(P)
print(Q, P)
c = sum(p != q for p, q in zip(P, Q))
if c <= 2:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
N = int(input())
P = list(map(int,input().split()))
L = []
for i in range(1,N+1):
  L.append(i)
Count = 0
for i in range(N):
  if L[i] != P[i]:
    Count += 1

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

Submission status: Wrong Answer

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

l = list()
for i in range(1,N+1):
    l.append(i)
cnt = 0
for i, c in enumerate(p):
    if c != l[i]:
        cnt += 1
if cnt == 2 or cnt ==0:
    print("YES")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
s = []
t = 0
for i in range(n):
  s.append(i)

for i in range(n):
  if(s[i] != i + 1):
    t += 1
if(t == 0 or t == 2):
  print('YES')
else:
  print('NO')

Submission status: Wrong Answer

Solution code:
n = int(input())
s = []
t = 0
for i in range(n):
  s.append(i)

for i in range(n):
  if(s[i] != i + 1):
    t += 1
if(t == 0 or 2):
  print('YES')
else:
  print('NO')

Submission status: Wrong Answer

Solution code:
n = int(input())
s = []
for i in range(n):
  s.append(i)

for i in range(n):
  t = 0
  if(s[i] != i + 1):
    t += 1
if(t == 0 or 2):
  print('YES')
else:
  print('NO')

Submission status: Wrong Answer

Solution code:
n = int(input())
s = []
for i in range(n):
  s.append(i)

for i in range(n):
  t = 0
  if(s[i] != i + 1):
    t += 1
if(t <= 2):
  print('YES')
else:
  print('NO')

Submission status: Wrong Answer

Solution code:
n = int(input())
s = []
for i in range(n):
  s.append(i)

for i in range(n):
  t = 0
  if(s[i] != i + 1):
    t += 1
    if(t <= 2):
      print('Yes')
    else:
      print('No')

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input().split()
import copy
s0=copy.copy(s)
s.sort()
a=[1 if s[ii]!=s0[ii] else 0 for ii in range(len(s))]
#print(s0)
#print(s)
if sum(a)<=2:
  print("YES")
else:
  print("NO")