Problem:
 Score : 300 points    Problem Statement There are N squares arranged in a row from left to right. The height of the i -th square from the left is H_i .  For each square, you will perform either of the following operations once:   Decrease the height of the square by 1 .  Do nothing.   Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.      Constraints  All values in input are integers.  1 \leq N \leq 10^5  1 \leq H_i \leq 10^9         Input Input is given from Standard Input in the following format:  N  H_1  H_2  ...  H_N       Output If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print Yes ; otherwise, print No .        Sample Input 1 5
1 2 1 1 3      Sample Output 1 Yes  You can achieve the objective by decreasing the height of only the second square from the left by 1 .       Sample Input 2 4
1 3 2 1      Sample Output 2 No       Sample Input 3 5
1 2 3 4 5      Sample Output 3 Yes       Sample Input 4 1
1000000000      Sample Output 4 Yes

Solution (Python):
N = int(input())
H = list(map(int, input().split()))

ans = True
for i in range(N - 1, 0, -1):
    if H[i] - H[i - 1] == -1:
        H[i - 1] -= 1
    elif H[i] - H[i - 1] < -1:
        ans = False
        break

if ans:
    print('Yes')
else:
    print('No')

Solution (Python):
N = int(input())
H = list(map(int,input().split()))
output = "Yes"
if len(H) == 1:
    output = "Yes"
else:
    if H[1] - H[0] <= 0:
        H[0] += -1

    if len(H)==2:
        sa1 = H[1] - H[0]
        if sa1 < 0:
            output = "No"
    else:
        for i in range(2,N):
            sa1 = H[i-1] - H[i-2]
            sa2 = H[i]-H[i-1]
            if sa1 < 0:
                output = "No"
            elif sa1 == 0:
                    continue
            elif sa1 > 0:
                if sa2 <= 0:
                    H[i-1] += -1

        if H[N-1]-H[N-2] <0:
            output = "No"

print(output)

Solution (Python):

N = int(input())
H = list(map(int, input().split()))


tmp = H[0]
count=0

for i in H[1:]:
    if tmp==i:
        tmp=i
        continue
    elif tmp<i:
        tmp = i-1
    else:
        count=1
        continue


if count==0:
    print("Yes")
else:
    print("No")

Solution (Python):
N = int(input())
H = list(map(int, input().split()))

ans = True
h = H[0]
decreaseable = True
for i in range(1, N):
    if H[i] <= H[i - 1] - 2 or not decreaseable and H[i] < h:
        ans = False
        break
    if H[i] == h - 1:
        h = H[i]
        decreaseable = False
    elif H[i] > h:
        h = H[i]
        decreaseable = True
print('Yes' if ans else 'No')

Solution (Python):
n = int(input())
h = list(map(int, input().split()))

rtn = "Yes"
f = 1
for i in range(n-1):
    hi = h[i]
    hii = h[i+1]
    
    if (hi == hii + f):
        f = 0
    elif (hi > hii + f):
        rtn = "No"
        break
    else:
        f = 1

print(rtn)

Solution (Python):
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    h = list(map(int, input().split()))

    ok = True
    h[0] -= 1
    for i in range(1, N):
        if h[i] > h[i-1]:
            h[i] -= 1
        elif h[i] == h[i-1]:
            pass
        else:
            ok = False
            break
    if ok:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

Solution (Python):


def solve():
    N = int(input())
    if N == 1:
        res = 'Yes'
    else:
        H = tuple(map(int, input().split()))
        h_, flag = H[0], False
        for h in H[1:]:
            if h < h_-1:
                res = 'No'
                break
            elif h == h_ -1:
                if flag:
                    res = 'No'
                    break
                else:
                    h_ = h
                    flag = True
            elif h == h_:
                pass
            elif h > h_-1:
                h_ = h
                flag = False
        else:
            res = 'Yes'

    return str(res)

if __name__ == '__main__':
    print(solve())

Solution (Python):
import sys

N = int(input())
H = list(map(int, input().split()))
count = 0

if N == 1:
    print("Yes")
    sys.exit()

for i in range(N - 1):
    d = H[i] - H[i + 1]
    if d > 1:
        print("No")
        sys.exit()
    elif d == 1:
        count += 1
    elif d < 0:
        count = 0
    
    if count > 1:
        print("No")
        sys.exit()

print("Yes")

Solution (Python):
import sys
n1 = int(input())
n2 =  [int(i) for i in input().split()]

t1 = 0
for i1 in range(n1):
    if i1 == 0:
        if n2[i1] == 1:
            t1 = 1
        else:
            t1 = n2[i1] - 1
    else:
        if n2[i1] < t1:
            print("No")
            sys.exit()
        else:
            t1 = max(t1, (n2[i1] - 1))
print("Yes")

Solution (Python):
n = int(input())

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

under = 0
c =0 

for i in range(n-1):
    if l[i+1] > under:
        under = l[i+1]-1
        c += 1
    elif under == l[i+1]:
        
        c += 1
    
    else:
        break
    
if c == n -1:
    print('Yes')

else:
    print('No')

Solution (Python):






N = int(input())
H = list(map(int, input().split()))





tmp = float('inf')
for hi in H[::-1]:
    if tmp >= hi:
        tmp = hi
    elif tmp == hi-1:
        tmp = hi - 1
    elif tmp < hi-1:
        print('No')
        break
else:
    print('Yes')

Solution (Python):
N = int(input())
H = list(map(int, input().split()))
check = 0
tmpmax = 0

for i in range(N):
    tmpmax = max(tmpmax, H[i])
    if tmpmax - 1 <= H[i]:
        pass
    else:
        check = 1

if check == 0:
    print('Yes')
else:
    print('No')

Solution (Python):
import numpy as np

N = input()
N = int(N)
p = input().split()
p_l = [int(s) for s in p]

maxp = 0
flag = "Yes"
for i in range(0,N-1):
    if p_l[i]>maxp:
        maxp = p_l[i]
    if maxp > p_l[i+1]+1:
        flag = "No"
        break
print(flag)

Solution (Python):
n = int(input())
h_list = list(map(int, input().split()))
h = 0
result = 'Yes'
for i in range(n):
  if h <= h_list[i]-1:
    h = h_list[i]-1
  elif h == h_list[i]:
    h = h_list[i]
  else:
    result = 'No'
print(result)

Solution (Python):
N = int(input())

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

flg = True
for i in range(1,N):
    if H[i] > H[i-1]:
        H[i] = H[i]-1
    if H[i-1] - H[i] > 0:
        flg = False
        break

if flg:
    print("Yes")
else:
    print("No")

Solution (Python):
N = int(input())
H = list(map(int, input().split()))

ans = "Yes"
h = 0

for n in range(N-1):
    if H[n] > H[n+1] + 1:
        ans = "No"
        break
    elif H[n] == H[n+1] + 1:
        if H[n+1] < h:
            ans = "No"
            break
        H[n] -= 1
        h = max(H[n], h)


print(ans)

Solution (Python):
N = int(input())
H = list(map(int, input().split()))

for i in range(len(H))[-2::-1]:
    if H[i]>H[i+1]:
        H[i]-=1

result=True
for i in range(len(H)-1):
    if H[i]>H[i+1]:
        result=False

print('Yes' if result==True else 'No')

Solution (Python):
from fractions import gcd
import math

mod = 998244353

def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft

def S(x1, y1, x2, y2, x3, y3):
    return heron(math.sqrt((x1 - x2)**2 + (y1 - y2)**2), math.sqrt((x1 - x3)**2 + (y1 - y3)**2), math.sqrt((x3 - x2)**2 + (y3 - y2)**2))

def heron(a, b, c):
    try:
        d = (a + b + c) / 2
        return round(math.sqrt(d * (d - a) * (d - b) * (d - c)) * 2)
    except Exception as e:
        return 0

def main():
    n = int(input())
    h = list(map(int, input().split()))
    h = h[::-1]
    for i in range(n-1):
        if h[i] < h[i+1]:
            h[i+1] -= 1
        if h[i] < h[i+1]:
            print('No')
            return

    print('Yes')

main()

Solution (Python):
N = int(input())
H = [int(i) for i in input().split()]

check = 0
MAX = 0
for i in range(N):
    if H[i] > MAX:
        MAX = H[i] -1
    if H[i] < MAX:
        check = 1

if check == 1:
    print("No")
else:
    print("Yes")

Solution (Python):
n = int(input())
h = [int(i) for i in input().split()]
h[0] -= 1
for i in range(1, n):
    if h[i] < h[i-1]:
        print("No")
        break
    if h[i] > h[i-1]:
        h[i] -= 1
else:
    print('Yes')

Solution (Python):
N = int(input())
Hs = list(map(int, input().split()))
Hs = Hs[::-1]
max_h = Hs[0]
flag = 0
min_h = 0
for idx in range(1, N):
    if max_h < Hs[idx]:
        if (Hs[idx] - max_h) == 1:
            Hs[idx] -= 1
        else:
            flag = 1
            break
    max_h = Hs[idx]
if flag == 0:
    print("Yes")
else:
    print("No")

Solution (Python):
import sys
sys.setrecursionlimit(2**31-1)
input = sys.stdin.readline
write = sys.stdout.write
LMIIS = lambda : list(map(int,input().split()))
II = lambda : int(input())
dbg = lambda *something : print(*something) if DEBUG is True else 0
DEBUG = True

def main():

    N = II()
    H = LMIIS()
    prev = H[0]
    lowered = False
    for h in H[1:]:
        if prev - h  >= 2:
            print('No')
            return
        elif prev - h == 1:
            if lowered:
                print('No')
                return
            prev = h
            lowered = True
        elif prev - h == 0:
            prev = h
        else:
            prev = h
            lowered = False
    print('Yes')




    pass
if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
H = list(map(int, input().split()))
for i in range(N - 1, 0, -1):
    if H[i] >= H[i - 1]:
        continue
    H[i - 1] -= 1
    if H[i] >= H[i - 1]:
        continue
    print('No')
    exit()
print('Yes')

Solution (Python):
import numpy as np


def main():
    N = int(input())
    Hs = list(map(int, input().split()))
    ans = True
    for i in range(N-1, 0, -1):
        if Hs[i-1] == Hs[i] + 1:
            Hs[i-1] -= 1
        elif Hs[i-1] > Hs[i] + 1:
            ans = False
            break
        elif Hs[i-1] <= Hs[i]:
            pass

    if ans == True:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
hs = [int(i) for i in input().split()]

pre_h = 0
for h in hs:
    if h < pre_h-1:
        print("No")
        break
    pre_h = h if h >= pre_h else h+1
else:
    print("Yes")

Solution (Python):
n = int(input())
h = list(map(int, input().split()))
k = 0
for i in range(n):
    if h[i] < k:
        print('No')
        exit()
    k = max(h[i] - 1, k)
print('Yes')

Solution (Python):

N=int(input())
H=list(map(int,input().split()))
for i in range(N-1,0,-1):
    if H[i]<H[i-1]:
        H[i-1]=H[i-1]-1
        if H[i]<H[i-1]:
            print("No")
            break
else:
    print("Yes")

Solution (Python):
N = int(input())
h = list(map(int,input().split()))
rh = list(reversed(h))
for i in range(N-1):
    if rh[i] < rh[i+1]:
        if rh[i+1]-rh[i] >= 2:
            print('No')
            exit(0)
        elif rh[i+1]-rh[i] == 1:
            rh[i+1] -= 1
else:
    print('Yes')

Solution (Python):
n = int(input())
h = list(map(int, input().split()))

for i in range(1, n - 1):
    if h[i - 1] < h[i]:
        h[i] -= 1
    if not h[i - 1] <= h[i] <= h[i + 1]:
        print('No')
        exit()

print('Yes')

Solution (Python):
N = int(input())
H = list(map(int, input().split()))

for i in range(N-1):
    if H[i] <= H[i+1]:
        continue
    elif H[i]-1 == H[i+1]:
        H[i+1] += 1
    else:
        
        print('No')
        exit()

print('Yes')

Solution (Python):
from sys import stdin

def main():
    N = int(input())
    H = map(int, input().split())

    h = list(H)
    for i in range(N - 2, -1, -1):
        if h[i] > h[i+1]:
            h[i] -= 1
    for i in range(N - 1):
        if h[i] > h[i+1]:
            print('No')
            break
    else:
        print('Yes')

input = lambda: stdin.readline()
main()

Solution (Python):
n=int(input())
h=list(map(int,input().split()))
if n==1:
  print("Yes")
else:
  l=0
  s="Yes"
  for i in range(n):
    if h[i]>=l:
      l=h[i]
    if l-h[i]>=2:
      s="No"
      break
  print(s)

Solution (Python):
n=int(input())
hlist = list(map(int, input().split()))
hlist[0]-=1
ng=len(hlist)

ok=1

for i in range(ng-2):
    if hlist[i]<=hlist[i+1] and hlist[i+1]<=hlist[i+2]:
        if hlist[i+1]==hlist[i+2] and hlist[i]<hlist[i+1]:
            hlist[i+1]-=1
    elif hlist[i]<=hlist[i+1] and hlist[i+1]>=hlist[i+2]:
        if hlist[i+1]-hlist[i+2]==1 and hlist[i]!=hlist[i+1]:
            hlist[i+1]-=1
        else:
            ok=0
    else:
        ok=0

if ng==1:
    ok=1
elif ng==2:
    if hlist[0]<=hlist[1]:
        ok=1
    else:
        ok=0



if ok==1:
    print("Yes")
else:
    print("No")

Solution (Python):
n = int(input())
h = list(map(int,input().split()))
if n == 1:
    print('Yes')

else:
    ans = 'Yes'
    max_h = h[0]
    for x in h[1:]:
        if x >= max_h - 1:
            max_h = max(max_h, x)
        else:
            ans = 'No'
            break
    print(ans)

Solution (Python):
N=int(input())

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

H[0]-=1

s=0

if N>1:
    if H[0]>H[1]:
        s=1
    
    for i in range(1,N-1):
        if H[i]>H[i-1]:
            H[i]-=1
        if H[i]>H[i+1]:
            s=1


if s==1:
    print('No')
else:
    print('Yes')

Solution (Python):
N = int(input())
H = map(int, raw_input().split())

ans = True
for i in range(0, N-1):
    ci = N - 1 - i
    h = H[ci]
    prev_h = H[ci-1]
    if h < prev_h:
        if h == prev_h - 1:
            H[ci-1] -= 1
        else:
            ans = False
            break

if ans:
    print("Yes")
else:
    print("No")

Solution (Python):
n=int(input())
h=list(map(int,input().split()))
inf=10**9
h+=[inf]
ans='Yes'
for i in range(n):
    if h[i]==h[i+1]+1:
        h[i+1]+=1
    elif h[i]>h[i+1]+1:
        ans='No'
        break
print(ans)

Solution (Python):
def hikaku():
    y = 0
    for x in h :
        if y <= x - 1 :
            y = x - 1
        elif y <= x :
            y = x
        else :
            return 'No'

    return 'Yes'




n = int(input())
h = [int(x) for x in input().split(' ')]

print(hikaku())

Solution (Python):
N = int(input())
H = [int(x) for x in input().split()]
ans = 1
max = H[0]-1
for i in range(N-1):
    if max < H[i + 1]-1:
        max = H[i+1]-1

    if max > H[i+1]:
        ans = 0
        
        break
if ans == 1:
    print("Yes")
else:
    print("No")

Solution (Python):
N = int(input())
lst = list(map(int,input().split()))

for i in range(len(lst)):
	if i == len(lst)-1:
		break
	if lst[i+1] > lst[i]:
		lst[i+1] -= 1
	if lst[i+1] < lst[i]:
		print('No')
		exit()
print('Yes')

Solution (Python):
import math

n = int(input())



list = [int(i) for i in input().split()]






flag = 0

for i in range(n-2,-1,-1) :
    if(list[i] == list[i+1] + 1) :
        list[i] = list[i] - 1
    elif(list[i] > list[i+1] + 1) :
        flag = 1

    if (list[i] < 1) :
        flag = 1

if (flag == 0) :
    print("Yes")
else :
    print("No")

Solution (Python):
n = int(input())
h = list(map(int, input().split()))

max_height = 0
for i in h:
    if i > max_height:
        max_height = i

    elif i+1 < max_height:
        print("No")
        exit()

print("Yes")

Solution (Python):

"""
Created on Sat Apr 20 20:47:47 2019

@author: Owner
"""

import numpy as np
import sys
import collections
import scipy.misc
import math
from operator import itemgetter
import itertools
import copy
import bisect
import heapq


def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   

def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

def find_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        """
        x が属するグループを探索
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)

    def get_size(self, x):
        """
        x が属するグループの要素数
        """
        x = self.find(x)
        return self.size[x]
    

"""
N, X = map(int, input().split())

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

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())


dp = np.zeros((N+1, 4,4,4))
    
all(nstr.count(c) for c in '753')


ABT = zip(A, B, totAB)
result = 0

sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)


(x >> i) & 1


dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break

add = 1 
res = 0
sums = [0]*(len(nums)+1)
for i in range(len(nums)):
    sums[i+1] = sums[i] + nums[i]
for i in range(0, len(nums), 2):
    left = i
    right = min(i+add, len(nums))
    tmp = sums[right] - sums[left]
    res = max(tmp, res)


li, ri = bisect.bisect_left(p_ac, l[i]-1), bisect.bisect_right(p_ac, r[i]-1)    


org_list = [3, 1, 4, 5, 2]
new_list = sorted(org_list)
print(org_list)
print(new_list)




    for h in range(0,H):
        for w in range(0,W):
            if h == 0 and w == 0:
                pass
            elif h == 0:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h-1][W-w]+1)
            elif w == 0:   
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1)
            else:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1, D[H-h-1][W-w]+1, D[H-h][W-w]+2)
            d_max = max(D[H-h-1][W-w-1], d_max)

"""


N = int(input())
H = list(map(int, input().split()))

    
def main(): 
    now = H[0]
    for n, h in enumerate(H):
        if n == 0:
            continue
        else:
            if h < now:
                return print("No")
            elif h == now:
                continue
            else:
                now = h-1
                
            
        
    return print("Yes")
    
                
                
                
            
            
                

    
if __name__ == '__main__':
    main()

Solution (Python):
import sys
N = int(input())
H = [int(x) for x in input().split()]
max_H = H[0]
for i in range(1,len(H)):
    if H[i-1]-H[i] > 1:
        print('No')
        sys.exit(0)
    if max_H-H[i] > 1:
        print('No')
        sys.exit(0)
    if H[i] > max_H:
        max_H = H[i]
print('Yes')

Solution (Python):
N=int(input())
H=list(map(int, input().split()))
Flag=True

if N==1:
  print("Yes")
else:
  for i in range(1,N):
    if H[i]>H[i-1]:
      H[i]=H[i]-1
    if H[i]>=H[i-1]:
      pass
    else:
      Flag=False
      break
      
  if Flag:
    print("Yes")
  else:
    print("No")

Solution (Python):
def main():
    _ = int(input())
    h = [int(s) for s in input().split()]

    if solve(h):
        print('Yes')
    else:
        print('No')

def solve(h):
    th = h[0]

    for x in h[1:]:
        if x > th:
            th = x
        elif x == th or x + 1 == th:
            continue
        else:
            return False
    return True


main()

Solution (Python):
N=int(input())
H=list(map(int,input().split()))
C=0
for i in range(N-1):
    if C>=2:
        break
    elif H[i]>H[i+1]+1:
        C=C+2
        break
    elif H[i]>H[i+1]:
        C=C+1
    elif H[i]<H[i+1]:
        C=0
if C<2:
    print('Yes')
else:
    print('No')

Solution (Python):
N = int(input())
H = list(map(int, input().split()))

now = H[0] - 1

for i in range(1,N):
    if H[i] - now == 0:
        pass
    elif H[i] - now == 1:
        pass
    elif H[i] - now >= 2:
        now = H[i] - 1
    else:
        print('No')
        exit()

print('Yes')

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
import sys, math, bisect, random, itertools
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')


def A():
    a, b, c = LI()
    print(min(b+c,a))
    return


def B():
    n = II()
    ans = 0
    for i in range(1, n + 1):
        if len(str(i)) % 2:
            ans += 1
    print(ans)
    return


def C():
    n = II()
    h = LI()
    h = h[::-1]
    for i in range(1, n):
        if h[i] <= h[i-1]:
            continue
        if h[i] == h[i - 1] + 1:
            h[i] -= 1
            continue
        print("No")
        return
    print("Yes")
    return


def D():
    s = S()
    lens = len(s)
    ans = [0] * len(s)
    i = 0
    while i != len(s):
        for j in range(i, lens):
            if s[j] == "R":
                continue
            break
        R = j - i
        for i in range(j, lens):
            if s[i] == "L":
                continue
            break
        else:
            i += 1
        L = i - j
        ans[j] = R // 2 + (L+1) // 2
        ans[j - 1] = L // 2 + (R+1) // 2

    print(*ans)
    return


def E():
    return


def F():
    return


if __name__ == '__main__':
    C()

Solution (Python):
n = int(input())
hh = list(map(int, input().split()))

result = 'Yes'

if n == 1:
  pass

else:
  num = hh[0]
  flg = False

  for i in range(1, n):
    h = hh[i]

    if num - h >= 2:
      result = 'No'
      break

    
    if num - h == 1:
      num = h + 1
      
    else:
      num = h

print(result)

Solution (Python):


def acinput():
    return list(map(int,input().split(" ")))


N=int(input())
H=acinput()

res="Yes"
H[0]=min(0,H[0])
for i in range(1,N):
    if H[i-1]<H[i]:
        H[i]-=1
    
    if H[i-1]>H[i]:
        res="No"
        break

print(res)

Solution (Python):
from sys import stdin

if __name__ == '__main__':
    N = int( stdin.readline().rstrip() )
    H = [ ( i, int(x) ) for i, x in enumerate(stdin.readline().rstrip().split()) ]
    H = dict(H)
    isOK = True
    for i in range( N - 1 ):
        if H[i] < H[i + 1]:
            H[i + 1] = H[i + 1] - 1
        elif H[i] == H[i + 1]:
            pass
        else:
            isOK = False
            break
    if isOK:
        print( 'Yes' )
    else:
        print( 'No' )

Solution (Python):
n=int(input())
h=list(map(int,input().split()))

a=h[0]
flag=True
if h[0]>0:
    h[0]-=1

for i in range(1,n):
    if flag:
        if h[i]>0 and h[i]>h[i-1]:
            h[i]-=1
        
        elif h[i]>=0 and h[i]==h[i-1]:
            continue
        
        else:
            flag=False

if flag:
    print('Yes')
else:
    print('No')

Solution (Python):
N=int(input())
hlist=list(map(int,input().split()))
hantei="Yes"
kabe=0
for i in range(1,N):
  if hantei=="No":
    break
  kabe=max(kabe,hlist[i])
  if kabe>=hlist[i]+2:
    hantei="No"
print(hantei)

Solution (Python):
N = int(input())
H = list(map(int,input().split()))
max_H = H[0]
for i in range(1,N):
  if H[i]-H[i-1] < -1:
    print('No')
    break
  if H[i]-max_H < -1:
    print('No')
    break
  if max_H < H[i]:
    max_H = H[i]
else:
  print('Yes')

Solution (Python):
n = int(input())
h = list(map(int, input().split()))
h = [-1] + h

for i in range(1, n + 1):
    if h[i - 1] < h[i]:
        h[i] -= 1
    if h[i-1] > h[i]:
        print("No")
        exit()
print("Yes")

Solution (Python):
n = int(input())
h_list = list(map(int, input().split()))
last = h_list[0]
ans = 'Yes'
for h in h_list[1:]:
    if last > h + 1:
        ans = 'No'
        break
    else:
        last = h if last < h else last
print(ans)

Solution (Python):
import sys

N = int(input())
h_list = list(map(int, input().split()))

max_up = -1
max_down = 1

if h_list[0] > 1:
    h_list[0] -= 1

for i in range(len(h_list[:-1])):

    h = h_list[i]
    next_h = h_list[i+1]
    diff = next_h - h

    if diff > 0:
        h_list[i+1] = next_h - 1
    elif diff < 0:
        print("No")
        sys.exit()
print("Yes")

Solution (Python):
N=int(input())
h=[0]+list(map(int,input().split()))+[9000000001]

if N==1:
    print("Yes")
else:
    isOK=True
    for i in range(len(h)-1):
        left=h[i]
        right=h[i+1]
        if left==right:
            continue
        elif left+1<=right:
            h[i+1]-=1
        elif left>right:
            isOK=False
            break
    if isOK:
        print("Yes")
    else:
        print("No")

Solution (Python):
import sys
N = int(input())
H = [int(i) for i in input().split()]

max_num = H[0]
for i in range(N-1):
  if max_num < H[i]:
    max_num = H[i]
  if max_num - H[i+1] >= 2:
    print("No")
    sys.exit()

print("Yes")

Solution (Python):
import sys
input = sys.stdin.readline

def main():
	n = int(input().strip())
	v = list(map(int, input().strip().split()))
	mini = 10**10
	for i in reversed(range(n)):
		mini = min(mini, v[i])
		if v[i] - mini > 1:
			print('No')
			return
	print('Yes')

if __name__ == '__main__':
	main()

Solution (Python):
import sys
input = sys.stdin.readline

N = int(input())
H = [int(item) for item in input().split()]

cand = []
cand += [H[0], H[0] - 1]
for i in range(1, N):
    new_cand = []
    for c in cand:
        if c <= H[i] - 1:
            new_cand += [H[i], H[i] - 1]
        elif c == H[i]:
            new_cand += [H[i]]
    cand = list(set(new_cand))
    if len(cand) == 0:
        print("No")
        break
else:
    print("Yes")

Solution (Python):
N = int(input())
H = [int(x) for x in input().split()]

prev = -1
is_possible = "Yes"
for i in range(N):
    if prev < H[i]:
        H[i] -= 1
    if prev > H[i]:
        is_possible = "No"
        break
    prev = H[i]

print(is_possible)

Solution (Python):
n = int(input())

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

hs[0] -= 1
b = True

for i in range(1,n):
  if hs[i-1]+1 <= hs[i]:
    hs[i] -= 1
  elif hs[i-1] > hs[i]:
    b = False
    break
if b:
  print("Yes")
else:
  print("No")

Solution (Python):
import sys
n = int(input())
heights = list(map(int, input().split()))

for i in range(1, n):
    if heights[i - 1] <= heights[i] - 1:
        heights[i] -= 1
    elif heights[i - 1] == heights[i]:
        pass
    else:
        print('No')
        sys.exit()

print('Yes')

Solution (Python):

N = int(input())
H = list(map(int, input().split()))
m = H[-1]
for h in H[::-1]:
    if h > m+1:
        print('No')
        exit()
    m = min(m, h)
print('Yes')

Solution (Python):



import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

n = int(input())
h = list(map(int,input().split()))
f = 1
ma = 0
for i in range(n):
    if ma < h[i]:
        ma = h[i]
    else:
        if ma - h[i] >= 2:
            f = 0
            break
if f:
    print('Yes')
else:
    print('No')

Solution (Python):
def solve():
    n = int(input())
    hs = list(map(int, input().split()))
    for i in reversed(range(n)):
        if i == 0:
            return "Yes"
        elif hs[i - 1] - hs[i] > 1:
            return "No"
        elif hs[i - 1] - hs[i] == 1:
            hs[i - 1] -= 1
        else:
            continue
    return "Yes"


if __name__ == "__main__":
    print(solve())

Solution (Python):
N=int(input())
H=list(map(int,input().split()))
if N==1:
    print("Yes")
    exit()
for i,h in enumerate(H):
    if i==N-1:continue
    if i==0:
        if H[0]-H[1]<=1:
            H[0]-=1
        else:
            print("No")
            exit()
        continue
    if (H[i-1]==H[i] and H[i]-H[i+1]>0) or H[i]-H[i+1]>1:
        print("No")
        exit()
    elif H[i-1]<H[i]:
        H[i]-=1
print("Yes")

Solution (Python):

import sys

N = int(input())
H = list(map(int, input().split()))

max_ = 0
if N == 1:
    print('Yes')
else:
    for i in range(N):
        if H[i] < max_:
            print('No')
            sys.exit(0)
        else:
            if H[i] == max_:
                pass
            else:
                max_ = max(1, H[i]-1)
            
    print('Yes')

Solution (Python):
n = int(input())
height_ar = [int(x) for x in input().split()]

flag = 1
for i in range(n-1):
    sub = height_ar[i] - height_ar[i+1]
    if sub > 1:
        print("No")
        flag = 0
        break
    elif sub == 1:
        height_ar[i+1] = height_ar[i+1] + 1
    else:
        pass

if flag == 1:
    print("Yes")

Solution (Python):
N = int(input())
h_list = list(map(int, input().split()))

result = True
for i in reversed(range(1, N)):
    if h_list[i] < h_list[i - 1]:
        if h_list[i - 1] - h_list[i] >= 2:
            result = False
            break
        else:
            h_list[i - 1] -= 1
if result:
    print("Yes")
else:
    print("No")

Solution (Python):
def Increasable():
    N  = int(input())
    Hi = list(map(int, input().split()))
    
    highest = Hi[0]
    for h in Hi:
        if h + 1 < highest:
            return 'No'
        highest = max(h, highest)
    return 'Yes'


print(Increasable())

Solution (Python):
def main(n, h):
    for i in range(n - 1):
        j = n - i - 1
        if h[j - 1] - h[j] > 1:
            return "No"
        if h[j - 1] > h[j]:
            h[j - 1] -= 1
    return 'Yes'


if __name__ == '__main__':
    n = int(input())
    h = list(map(int, input().split()))
    print(main(n, h))

Solution (Python):


n = int(input())
h = [int(i) for i in input().split()]

a = []
flag = 'Yes'
for i in reversed(range(n - 1)):
    if h[i+1] - h[i] < 0 and h[i+1] - h[i] > -2:
        h[i] -= 1
    elif h[i+1] - h[i] < -1:
        flag = 'No'
print(flag)

Solution (Python):
N = int(input())
H = list(map(int, input().split()))

ans = "Yes"
H_max = H[0]
for i in range(1, N):
  if H[i] < H_max:
    if H_max - H[i] >= 2:
      ans = "No"
      break
  H_max = max(H_max, H[i])
print(ans)

Solution (Python):
n = int(input())
h = list(map(int, input().split()))
ans = 'Yes'
for i in range(len(h)):
  if i > 0:
    if h[-i-1] > prev:
      if h[-i-1] - 1 == prev:
      	h[-i-1] -= 1
      else:
        ans = 'No'
        break
  prev = h[-i-1]
print(ans)