def main():

  n = int(eval(input()))

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

  c = 0

  if judge(p):

    print('YES')

  else:

    for i in range(n):

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

        a = p.copy()

        a[i], a[j] = a[j], a[i]

        if judge(a):

          c += 1

          print('YES')

    if c == 0:

      print('NO')





def judge(l):

  return True if l == sorted(l) else False





if __name__ == '__main__':

  main()
def main():

  n = int(eval(input()))

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

  c = 0

  for i in range(n):

    c += 0 if i+1 == p[i] else 1

  print(('YES' if c <= 2 else 'NO'))





if __name__ == '__main__':

  main()
def main():
    n = int(eval(input()))
    p = list(map(int, input().split(" ")))
    c = 0
    if judge(p):
        print("YES")
    else:
        for i in range(n):
            for j in range(i + 1, n):
                a = p.copy()
                a[i], a[j] = a[j], a[i]
                if judge(a):
                    c += 1
                    print("YES")
        if c == 0:
            print("NO")


def judge(l):
    return True if l == sorted(l) else False


if __name__ == "__main__":
    main()

def main():
    n = int(eval(input()))
    p = list(map(int, input().split(" ")))
    c = 0
    for i in range(n):
        c += 0 if i + 1 == p[i] else 1
    print(("YES" if c <= 2 else "NO"))


if __name__ == "__main__":
    main()

-    if judge(p): -        print("YES") -    else: -        for i in range(n): -            for j in range(i + 1, n): -                a = p.copy() -                a[i], a[j] = a[j], a[i] -                if judge(a): -                    c += 1 -                    print("YES") -        if c == 0: -            print("NO") - - -def judge(l): -    return True if l == sorted(l) else False +    for i in range(n): +        c += 0 if i + 1 == p[i] else 1 +    print(("YES" if c <= 2 else "NO"))