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: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# submission # - User: herp_sy
# https://atcoder.jp/contests/

import math
import numpy as np
import statistics

# = map(int, input().split())
n = int(input())
# = raw_input().split()
p = list(int(i) for i in input().split())

cnt = 0
l = np.arange(n) + 1
for i in range (n):
  if not(p[i] == l[i]):
    cnt += 1
if(cnt in [0,2]):
  print('YES')
else:
  print('NO')

Submission status: Accepted

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

Submission status: Accepted

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

cnt = 0
idx = []
for i in range(N):
    if p[i] != ps[i]:
        cnt += 1
        idx.append(i)

if cnt == 2:
    i,j = idx[0],idx[1]
    p[i],p[j] = p[j],p[i]
    if p == ps:
        print('YES')
    else:
        print('NO')
elif cnt == 0:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
ansa=sorted(A)
ans=0
for i in range(N-1):
  if ans==0:
    if A[i]>A[i+1]:
      ch=A[i]
      m=i
      ans=ans+1
  elif ans==1:
    if A[i]>A[i+1]:
      n=A[i+1]
      A[i+1]=ch
      A[m]=n
if A==ansa:
  print("YES")
else:
  print("NO")

Submission status: Accepted

Solution code:
# -*- coding utf-8 -*-
N = int(input())
pn = list(map(int, input().split()))

c = 0

for i in range(1, N + 1):
    if pn[i - 1] != i:
        c += 1

ans = 'YES' if c <= 2 else 'NO'

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
	N = int(input())
	# = list(input())
	#A,B = map(int, input().split(" "))
	PP = list(map(int, input().split(" ")))
 
	flg = True
	for k,val in enumerate(PP):
		if k == 0:
			continue
		if PP[k-1] <= val:
			pass
		else:
			flg = False
 
	if flg == True:
		print("YES")
		sys.exit()
 
	tmp = []
	for i in range(N):
		for j in range(i+1, N):
			P = copy.deepcopy(PP)
			tmp = copy.deepcopy(P[i])
			P[i] = copy.deepcopy(P[j])
			P[j] = copy.deepcopy(tmp)
			
			flg = True
			for k,val in enumerate(P):
				if k == 0:
					continue
				if P[k-1] <= val:
					pass
				else:
					flg = False
			
			if flg == True:
				print("YES")
				sys.exit()
 
	print("NO")
            	
if __name__ == "__main__":
	main()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

p.sort()

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

counter =0

for i in range(1,N+1,1):
  if i != p[i-1]:
    counter +=1
if counter in [0,2]:
  print("YES")
else:
  print("NO")

Submission status: Accepted

Solution code:
N = int(input())
p = list(map(int, input().split()))
temp = [number for number in p]
for i in range(N):
    if temp[i] != i + 1:
        temp[temp[i]-1], temp[i] = temp[i], temp[temp[i]-1]
        break
p.sort()
if temp == p:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
N = int(input())
p = list(map(int, input().split()))
temp = [i for i in p]
for i in range(N):
    if temp[i] != i + 1:
        temp[temp[i]-1], temp[i] = temp[i], temp[temp[i]-1]
        break
p.sort()
if temp == p:
    print("YES")
else:
    print("NO")

Submission status: Accepted

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

for count, i in enumerate(p):
    if(i != sort_p[count]):
        count1 = count1 + 1


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

Submission status: Accepted

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

base = [x for x in range(1, N + 1)]

count = 0
for n in range(N):
	count += (A[n] != base[n])

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

Submission status: Accepted

Solution code:
n = int(input())

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

count = 0
for i in range(n):
    if P_list[i] != i + 1:
        count += 1

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

Submission status: Accepted

Solution code:
def test(x, j):
    # X, A = map(int, input().split())
    A = j.split()
    numbers = []
    result = True
    for i in A:
        numbers.append(int(i))
    result = sorted(numbers)
    if (result == True):
        print("YES")
        return "YES"
    if (result == False):
        # numbers2 = numbers[:]
        for i in range(len(numbers)):
            for x in range(i+1, len(numbers)):
                numbers2 = numbers[:]
                if swap(numbers2, i, x) == True:
                    print("YES")
                    return "TRUE"
    print("NO")
    return "FALSE"


def sorted(list):
    result = True
    for i in range(len(list)):
        if i < len(list) - 1:
            if (list[i] > list[i+1]):
                result = False
    return result


def swap(list, pos1, pos2):
    list[pos1], list[pos2] = list[pos2], list[pos1]
    return sorted(list)


N = int(input())
p = input()
test(N, p)

Submission status: Accepted

Solution code:
# stdin
INPUT_SENTENCES = 2
ss = [input() for i in range(INPUT_SENTENCES)]
N = int(ss[0])
p = list(map(lambda x: int(x), ss[1].split()))
rev_index = []
for i in range(N-1):
    if p[i] > p[i+1]:
        if len(rev_index) > 0:
            rev_index.append(i+1)
        else:
            rev_index.append(i)
if len(rev_index) == 2:
    p[rev_index[0]], p[rev_index[1]] = p[rev_index[1]], p[rev_index[0]]
if p == list(range(1,N+1)):
    print("YES")
else:
    print("NO")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Mon Jul 29 02:06:58 2019

@author: matsui
"""


N=int(input())


P=input().split()

count=0
for i in range(N):
    if i+1 != int(P[i]):
        count+=1
        
if count==2 or count==0:
    print('YES')
else:
    print('NO')

Submission status: Accepted

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

ps = sorted(p)

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

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

Submission status: Accepted

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

Submission status: Accepted

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

ps = sorted(p)

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

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

Submission status: Accepted

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

ps = sorted(p)

if p == ps:
    print('YES')
else:
    count = 0
    for i in range(len(ps)):
        if ps[i] != p[i]:
            count += 1

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

Submission status: Accepted

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

sp = sorted(p)
same_count = len([1 for x, y in zip(p, sp) if x == y])
print('YES' if N - 2 <= same_count else 'NO')

Submission status: Accepted

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
p = [int(x) for x in stdin.readline().rstrip().split()]

count = sum([x != i for i, x in enumerate(p, 1)])

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
def solve():
  n = int(input())
  p = list(int(i) for i in input().split())
  checker = 0
  query = [int(i+1) for i in range(n)]
  for i in range(n):
    if p[i] != query[i]:
      checker += 1
  if checker >2 :
    print("NO")
  elif checker ==1:
    print("NO")
  else:
    print("YES")
solve()

Submission status: Accepted

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


c = 0
is_ok = True
for i in range(N):
    if (i+1 != p[i]) :
        c += 1
    
    if (c > 2) :
        is_ok = False
        break

if (is_ok) :
    print("YES")
else :
    print("NO")

Submission status: Accepted

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

c = 0
for i, v in enumerate(arr):
  if i+1!=v:
    c += 1
print("YES" if c==2 or c==0 else "NO")

Submission status: Accepted

Solution code:
def isOne_sort(array):
    n = len(array)
    sort_count = 0
    for i in range(0, n-1):
        if(sort_count>1):
            return 'NO'
        # 最小値のインデックスを保持
        min = i
        for j in range(i+1, n):
            if array[min] > array[j]:
                min = j
        # 見つけた最小値を未整列末尾要素と交換
        if(i!=min):
            tmp = array[min]
            array[min] = array[i]
            array[i] = tmp
            sort_count+=1
    return 'YES'

N = int(input())
P = [int(i) for i in input().split()]
print(isOne_sort(P))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    _ = int(input())
    p_lists = [int(x) for x in stdin.readline().rstrip().split()]

    new_p_lists = sorted(p_lists)
    count = 0

    for p, new_p in zip(p_lists, new_p_lists):
        if p == new_p:
            pass
        else:
            count += 1

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

judge = [(v != k+1) for k, v in enumerate(p)]
if sum(judge) <= 2:
    print('YES')
else:
    print('NO')

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(100000)
input=sys.stdin.readline
def intinput():return map(int,input().split())


n=int(input())
a=list(intinput())
b=a[:]
b.sort()
if a == b:
    print("YES")
    sys.exit()
for i in range(n):
    for j in range(i+1,n):
        a[i],a[j]=a[j],a[i]
        if a==b:
            print("YES")
            sys.exit()
        a[i],a[j]=a[j],a[i]
print("NO")

Submission status: Accepted

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

if p == q:
    print('YES')
else:
    count = 0
    for i in range(n):
        a = p[i] - q[i]
        if a == 0:
            count += 1
    if count == n - 2:
        print('YES')
    else:
        print('NO')

Submission status: Accepted

Solution code:
def main37():
    num = int(input())
    data = input().split()
    retu = []
    for i in range(num):
        retu.append(int(data[i]))
    kari = list(retu)
    kari.sort()
    kosu = 0
    for i in range(num):
        if retu[i] != kari[i]:
            kosu = kosu + 1
    if kosu == 2 or kosu == 0:
        print("YES")
    else:
        print("NO")

if __name__ == "__main__":
    main37()

Submission status: Accepted

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: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
p_list=[int(i) for i in input().split()]
p_sort=sorted(p_list)
swap_index=[]
for i,x,y in zip(range(len(p_list)),p_list,p_sort):
    if x!=y:
        swap_index.append(i)
if len(swap_index)==0:
    print("YES")
elif len(swap_index)!=2:
    print("NO")
else:
    i,j=swap_index
    tmp=p_list[i]
    p_list[i]=p_list[j]
    p_list[j]=tmp
    if p_list==p_sort:
        print("YES")
    else:
        print("NO")

Submission status: Accepted

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

for i in range(N):
    if p[i]!=i+1:
        k+=1

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

Submission status: Accepted

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

q = p.copy()
q.sort()

#pとqを比較
notequal = 0

for i,v in enumerate(p):
    if v != q[i]:
        notequal += 1

if notequal == 0 or notequal == 2:
    print("YES")
else:
    print("NO")

Submission status: Accepted

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

Submission status: Accepted

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

p_sort = sorted(p)

cnt = 0

for i in range(n):
    if p_sort[i] != p[i]:
        cnt += 1
    else:
        pass
    
if cnt == 2 or cnt == 0:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
N = int(input())
p = list(map(int,input().split()))
s = sorted(p)
k = 0
for i in range(N):
  if p[i]!=s[i]:
    k += 1
if k < 3 :
   print("YES")
else:
   print("NO")

Submission status: Accepted

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

cnt = 0
for i, p in enumerate(P):
    if i + 1 != p:
        cnt += 1

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

Submission status: Accepted

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

sp = list(sorted(P))

cnt = 0
for a, b in zip(P, sp):
    if a != b:
        cnt += 1

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

Submission status: Accepted

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

ss=list(range(1,n+1))
cnt=0
for p,s in zip(ps,ss):
	if p!=s:
		cnt+=1
		
if cnt<=2:
	print('YES')
else:
	print('NO')

Submission status: Accepted

Solution code:
n=int(input())
num=list(map(int,input().split()))
num2=sorted(num)
dif=0
for i in range(n):
    if num[i] != num2[i]:
        dif+=1
    if dif>2:
        break
print("YES" if dif<=2 else "NO")

Submission status: Accepted

Solution code:
def main():
    N = int(input())

    NumList = [int(i) for i in input().split(' ')]
    diffcount = 0

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

        if(diffcount > 2):
            print("NO")
            break    
    else:
        print("YES")

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
Y = [int(x) for x in input().split()]
Y_ = Y.copy()
Y_.sort()
test = [Y[i] == Y_[i] for i in range(len(Y))]
if test.count(False) <= 2:
  print("YES")
else:
  print("NO")

Submission status: Accepted

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: Accepted

Solution code:
N = int(input())
plis = list(map(int, input().split()))
plis_sorted = plis.copy()
plis_sorted.sort()

if plis == plis_sorted:
	print("YES")
	exit()

for i in range(N):
	for j in range(i+1,N):
		ptmp = plis.copy()
		tmp = ptmp[i]
		ptmp[i] = ptmp[j]
		ptmp[j] = tmp
		if ptmp == plis_sorted:
			print("YES")
			exit()

print("NO")

Submission status: Accepted

Solution code:
N = int(input())

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

p_sort = [i for i in range(1,N+1)]

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    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 == 0 or cnt == 2:
        print("YES")
    else:
        print("NO")


if __name__ == "__main__":
    main()

Submission status: Accepted

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

j= 0
for i in range(N):
	if p[i] != i+1:
		swap1 = (p[i], i)
		j=1
		break

if j == 0:
	print("YES")
	exit()
loc = p[swap1[0] - 1]
p[swap1[0] - 1] = swap1[0]
p[swap1[1]] = loc
#print(p)
for i in range(N):
	if p[i] != i+1:
		print("NO")
		exit()
print("YES")

Submission status: Accepted

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

Submission status: Accepted

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

cnt = 0

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

Submission status: Accepted

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

cnt = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(n):
    for j in range(i,n):
        p[i],p[j] = p[j],p[i]
        if q == p:
            print('YES')
            exit()
        p[i],p[j] = p[j],p[i]
print('NO')

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Q = sorted(P)
n = sum(1 for p, q in zip(P, Q) if p != q)
yes = n == 0 or n == 2
print('YES' if yes else 'NO')

Submission status: Accepted

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

count = 0

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

Submission status: Accepted

Solution code:
import copy

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

if all([li[i] < li[i+1] for i in range(n-1)]):
    print('YES')
    exit()
for i in range(n):
    for j in range(i+1,n):
        a = copy.copy(li)
        a[i],a[j] = a[j],a[i]
        if all([a[i] < a[i+1] for i in range(n-1)]):
            print('YES')
            exit()

print('NO')