#!/bin/python from __future__ import print_function import os import sys # # Complete the canModify function below. # def canModify(a): b=sorted(a) if(b==a): ans="YES" else: ans="NO" result=ans return result if __name__ == '__main__': fptr = open(os.environ['OUTPUT_PATH'], 'w') n = int(raw_input()) a = map(int, raw_input().rstrip().split()) result = canModify(a) fptr.write(result + '\n') fptr.close()