import copy



n = int(eval(input()))

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

p_new = copy.copy(p)

for i in range(n-1):

  if p[i] > p[i+1]:

    min_val = min(p[i+1:])

    for j in range(n):

      if p[j] == min_val:

        p_new[i] = min_val

        p_new[j] = p[i]

        break

    break



if p_new == sorted(p):

  print('YES')

else:

  print('NO')
n = int(eval(input()))

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



cnt = 0

for k,v in enumerate(p):

  if k+1 != v:

    cnt += 1



if cnt > 2:

  print('NO')

else:

  print('YES')
import copy

n = int(eval(input()))
p = list(map(int, input().split()))
p_new = copy.copy(p)
for i in range(n - 1):
    if p[i] > p[i + 1]:
        min_val = min(p[i + 1 :])
        for j in range(n):
            if p[j] == min_val:
                p_new[i] = min_val
                p_new[j] = p[i]
                break
        break
if p_new == sorted(p):
    print("YES")
else:
    print("NO")

n = int(eval(input()))
p = list(map(int, input().split()))
cnt = 0
for k, v in enumerate(p):
    if k + 1 != v:
        cnt += 1
if cnt > 2:
    print("NO")
else:
    print("YES")

-import copy - -p_new = copy.copy(p) -for i in range(n - 1): -    if p[i] > p[i + 1]: -        min_val = min(p[i + 1 :]) -        for j in range(n): -            if p[j] == min_val: -                p_new[i] = min_val -                p_new[j] = p[i] -                break -        break -if p_new == sorted(p): +cnt = 0 +for k, v in enumerate(p): +    if k + 1 != v: +        cnt += 1 +if cnt > 2: +    print("NO") +else: -else: -    print("NO")