import numpy as np





def main():

    n = int(eval(input()))

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

    a = np.array(list(range(1,n+1)))

    p = np.array(p)

    ans = len(np.where((a-p)!=0)[0])



    if ans <= 2:

        print('YES')

    else:

        print('NO')













main()
#from math import gcd



from math import factorial as f



from math import ceil,floor,sqrt





import bisect

import re

import heapq





from copy import deepcopy

import itertools



from sys import exit



ii = lambda : int(eval(input()))

mi = lambda : list(map(int,input().split()))

li = lambda : list(map(int,input().split()))



yes = "Yes"

no = "No"



def main():

    n=ii()

    p = li()

    cnt = 0

    for i in range(1,n+1):

        if i!=p[i-1]:

            cnt+=1

    if cnt<=2:

        print('YES')

    else:

        print('NO')







main()





import numpy as np


def main():
    n = int(eval(input()))
    p = list(map(int, input().split()))
    a = np.array(list(range(1, n + 1)))
    p = np.array(p)
    ans = len(np.where((a - p) != 0)[0])
    if ans <= 2:
        print("YES")
    else:
        print("NO")


main()

# from math import gcd
from math import factorial as f
from math import ceil, floor, sqrt
import bisect
import re
import heapq
from copy import deepcopy
import itertools
from sys import exit

ii = lambda: int(eval(input()))
mi = lambda: list(map(int, input().split()))
li = lambda: list(map(int, input().split()))
yes = "Yes"
no = "No"


def main():
    n = ii()
    p = li()
    cnt = 0
    for i in range(1, n + 1):
        if i != p[i - 1]:
            cnt += 1
    if cnt <= 2:
        print("YES")
    else:
        print("NO")


main()

-import numpy as np +# from math import gcd +from math import factorial as f +from math import ceil, floor, sqrt +import bisect +import re +import heapq +from copy import deepcopy +import itertools +from sys import exit + +ii = lambda: int(eval(input())) +mi = lambda: list(map(int, input().split())) +li = lambda: list(map(int, input().split())) +yes = "Yes" +no = "No" -    n = int(eval(input())) -    p = list(map(int, input().split())) -    a = np.array(list(range(1, n + 1))) -    p = np.array(p) -    ans = len(np.where((a - p) != 0)[0]) -    if ans <= 2: +    n = ii() +    p = li() +    cnt = 0 +    for i in range(1, n + 1): +        if i != p[i - 1]: +            cnt += 1 +    if cnt <= 2: