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

import bisect
import collections
import itertools


def getint(): return int(input())
def getints(): return list(map(int, input().split()))
def getint2d(rows): return [getints() for _ in range(rows)]
def getgrid(rows): return [input() for _ in range(rows)]
def array1d(n, value): return [value for _ in range(n)]
def array2d(n, m, value): return [array1d(m, value) for _ in range(n)]

n=getint()
hs=getints()

hs[0] -= 1
ok = True
for i in range(1, n):
    if hs[i] > hs[i - 1]:
        hs[i] -= 1
    if hs[i] < hs[i - 1]:
        ok = False

print("Yes" if ok else "No")

Solution (Python):
import sys

n = int(input())

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

ans = 'Yes'

if n == 1:
    ans = 'Yes'

else:
    for i in range(n-1):
        if number_list[-(i+2)] <= number_list[-(i+1)]:
            pass
        elif number_list[-(i+2)] - 1 <= number_list[-(i+1)]:
            number_list[-(i+2)] = number_list[-(i+2)] - 1
        else:
            ans = 'No'
            break
            
    

print(ans)

Solution (Python):

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

H.reverse()
ans=0
for i in range(N-1):
  if H[i]<(H[i+1]-1):
    ans=1
    break
  elif H[i]==H[i+1]-1:
    H[i+1] -=1
    
if ans==0:
  print("Yes")
else:
  print("No")

Solution (Python):


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

    if N == 1:
        print("Yes")
        return

    pre_h = H[0]
    for _, h in enumerate(H):
        if h == pre_h:
            continue
        elif h > pre_h:
            pre_h = (h - 1)
            continue
        print("No")
        return
    
    print("Yes")
    return


if __name__ == "__main__":
    solve()

Solution (Python):
import numpy as np
import sys

n = int(input())
h = np.array(list(map(int,input().split())))
temp = h[0]

for index,value in enumerate(h):
  if temp>value:
    h[index] += 1
    if h[index-1]>h[index]:
      print("No")
      sys.exit()
  temp = h[index]

print("Yes")

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

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

N, = map(int, input().split())
L = [int(v) for v in input().split()]

for i in range(1, N):
    a, b = L[i - 1], L[i]
    
    if a < b:
        L[i] -= 1
        
ans = True
for i in range(1, N):
    a, b = L[i - 1], L[i]
    
    if a > b:
        ans = False
        break
    
if ans:
    print("Yes")
else:
    print("No")

Solution (Python):

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

yes = True
for i in reversed(range(len(h))):
    if i == len(h)-1:
        continue
    if h[i] <= h[i+1]:
        pass
    elif h[i] == h[i+1] + 1:
        h[i] -= 1
    else:
        yes = False
        break

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

Solution (Python):
N = input()
H_list = list(map(int, input().split()))
H_edit_list = [10**10]

for h in list(reversed(H_list)):
    if h - H_edit_list[-1] > 0:
        H_edit_list.append(h - 1)
    else:
        H_edit_list.append(h)
    if H_edit_list[-2] < H_edit_list[-1]:
        print('No')
        exit()

print('Yes')

Solution (Python):
a = input()
l =list(map(int, input().split()))
t = 0
for i,j in zip(l,l[1:]):
    if i-j==1:t+=1
    elif i-j>1:t+=2
    elif j-i>0:t=0
    if t>1:
        print("No")
        exit(0)
print("Yes")

Solution (Python):
a = input()
l =list(map(int, input().split()))
t = 0
for i,j in zip(l,l[1:]):
    if i-j==1:t+=1
    elif i-j>1:t+=2
    elif j-i>0:t=0
    if t>1:
        print("No")
        exit(0)
print("Yes")

Solution (Python):
N = int(input())
bool = 0
data = list(map(int,input().split()))
for i in range(1,N):
  a = data[N-i]
  p = data[N-i-1]
  if p <= a:
    continue
  elif p-1 == a:
    data[N-i-1] -= 1
  else:
    bool = 1
    print('No')
    break
if bool == 0:
  print('Yes')

Solution (Python):
a = input()
l =list(map(int, input().split()))
t = 0
for i , j in zip(l,l[1:]):
    if i - j == 1:
        t += 1
    elif i - j > 1:
        t+=2
    elif j - i > 0:
        t = 0
    if t >1:
        print("No")
        exit(0)
    

if t > 1:
    print("No")
else:
    print("Yes")

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

for i in hn:
  if temp > i:
    print('No')
    exit()
  else:
    temp = max(temp,i-1)
print('Yes')

Solution (Python):
N = int(input())
lst = list(map(int, input().split()))
for idx, n in enumerate(lst[:-1]):
    if lst[idx] > lst[idx + 1]:
        if lst[idx] > (lst[idx + 1] + 1) :
            print('No')
            exit(0)
        else:
            lst[idx + 1] += 1
print('Yes')

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

flag=0
for i in range(a-1):
    if N[i+1]>N[i]:
        N[i+1]=N[i+1]-1
    if N[i]>N[i+1]:
        flag=1
    

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

Solution (Python):


N = int(input())


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

Judge = True


H_list[0]-=1

for i in range(N-1):
    
    if H_list[i] < H_list[i+1]:
        H_list[i+1]-=1
    elif H_list[i] > H_list[i+1]:
    
        Judge = False

if Judge == True:
    print('Yes')
elif Judge == False:
    print('No')

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


num = 10**9 + 1
boolean = True
for i in l[::-1]:
    if i <= num:
        num = i
    elif i-1 == num:
        num = i-1
    else:
        print('No')
        boolean = False
        break
    
if boolean:
    print('Yes')

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

    for i in range(n-1):
        if h[len(h)-2-i] - h[len(h)-1-i] >= 2:
            print("No")
            return
        elif h[len(h)-2-i] - h[len(h)-1-i] == 1:
            h[len(h) - 2 - i] = h[len(h)-2-i] - 1

    print("Yes")
    
resolve()

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

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

hlist[0]-=1
for i in range(N-1):
    if hlist[i] < hlist[i+1]:
        
        hlist[i+1] -= 1
    elif hlist[i] > hlist[i+1]:
        
        print("No")
        exit()
print("Yes")

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

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

pre_wall = H[N-1]
for i in reversed(H[:N-2]):
    if i <= pre_wall:
        pre_wall = i
    elif i == pre_wall +1:
        pre_wall = i-1
    else:
        print("No")
        exit()
print("Yes")

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

result = True
for j in range(n-1):
  if hlist[j] < hlist[j+1]:
    hlist[j+1] -= 1
  elif hlist[j] == hlist[j+1]:
    pass
  else:
    result = False
    
if result:
  print('Yes')
else:
  print('No')

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

tmp = 10 ** 9 + 1
for h_ in h[::-1]:
    if h_ > tmp:
        h_ -= 1
    if h_ > tmp:
        print('No')
        break
    tmp = h_
else:
    print('Yes')

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

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

for i in range(n-1, 0, -1):
    if h[i-1] == h[i] + 1:
        h[i-1] -= 1
    elif h[i-1] <= h[i]:
        pass
    else:
        print("No")
        exit()

print("Yes")

Solution (Python):
def solve(n, h):
    for i in range(n-1):
        if h[i] < h[i+1]:
            h[i+1] -= 1
        elif h[i] == h[i+1]:
            pass
        else:
            return "No"
    return "Yes"

n = int(input())
h = list(map(int, input().split()))
print(solve(n, h))

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


H.insert(N,10**9)

ans='Yes'

for i in range(N):
    if H[i]<H[i+1]:
        H[i+1]=H[i+1]-1

    elif H[i]>H[i+1]:
        ans='No'
        break

print(ans)

Solution (Python):


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

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

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

Solution (Python):
N=int(input())
l=list(map(int,input().split()))
l[0]-=1

if N==1:
    print("Yes")
else:
    for i in range(N-1):
        if l[i]<l[i+1]:
            l[i+1]-=1
            continue
        elif l[i]>l[i+1]:
            print("No")
            break
        else:
            pass
    else:
        print("Yes")

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

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

if __name__ == '__main__':
    main()

Solution (Python):


n = int(input())
l = list(map(int, input().split()))
l.reverse()
f = 0

for i in range(len(l)-1):
    if l[i] >= l[i+1]:
        continue
    else:
        if l[i] >= l[i+1] - 1:
            l[i+1] -= 1
        else:
            f = 1

    if f == 1:
        break

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

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

Solution (Python):
essage = "Yes"
"""
Created on Mon Aug 12 19:09:11 2019

@author: doppe
"""

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

print(message)

Solution (Python):
import sys
from math import *
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  

n = ni()
li = na()
mst = li[0]
flag = "Yes"
for i in range(n):
    if li[i] >= mst:
        mst = li[i]
    elif li[i] != mst - 1:
        flag = "No"
        break
print(flag)

Solution (Python):
N = int(input())
S = list(map(int,input().split()))
max = 0
ans = 'Yes'
for i in range(N):
    if S[i] > max:
        max = S[i]
    if S[i] <= max - 2:
        ans = 'No'
        break
print(ans)

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

flag = True
heights[0] -= 1

for i in range(1, n):
    if heights[i] > heights[i - 1]:
        heights[i] -= 1
    elif heights[i] < heights[i - 1]:
        flag = False

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

Solution (Python):
import sys
n = int(input())
h = [int(e) for e in input().split()]
for i in range(n - 2, 0, -1):
  if h[i] > h[i + 1]:
    h[i] -= 1
  if h[i] > h[i + 1]:
    print('No')
    sys.exit()
print('Yes')

Solution (Python):
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac

setrecursionlimit(1000000)


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

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(l):
	x = l.pop()
	y = l.pop()
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	l.append(min(x,y))
	return gcd(l) if len(l) > 1 else l[0]

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()

Solution (Python):



def canBuild(n, h):
    now = 0

    for x in h:
        if x < now: return False
        if x > now: now = x-1
    return True


def main():
    n = int(input())
    h = map(int, input().split())
    print("Yes") if canBuild(n, h) else print("No")

if __name__ == '__main__':
    main()

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

Solution (Python):
n = int(input())
h = list(map(int, input().split()))
h.reverse()
flag = True
for i in range(n-1):
    if h[i]+1==h[i+1]:
        h[i+1] -= 1
    elif h[i]+1<h[i+1]:
        flag = False
        break
print("Yes" if flag==True else "No")

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

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

for i in range(N):
  ans='Yes'
  if N == 1:
    ans='Yes'
    break;
  if i== 0:
    H[i]-=1
    continue
    
  if H[i-1] < H[i]:
    H[i] -= 1
  elif H[i-1]==H[i]:
    continue
  else:
    ans = "No"
    break;
print(ans)

Solution (Python):
"""
AtCoder
    :author: vierbein
"""
from __future__ import absolute_import, division, print_function



import sys


def pp(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)

def main():
    N = int(input())
    xs = [int(s) for s in input().split()]
    h_prev = 100000000000
    res = True
    for h in reversed(xs):
        if h - h_prev > 1:
            res = False
            break
        elif h == h_prev + 1:
            h_prev = h - 1
        else:
            h_prev = h

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


if __name__ == "__main__":
    main()

Solution (Python):
def main():
    N = int(input())
    value = list(map(int, input().split()))
    if N == 1:
        print("Yes")
        return
    for i in range(N):
        ans = "Yes"
        if i == 0:
            value[i] -= 1
            continue
        if value[i-1] < value[i]:
            value[i] -= 1
        elif value[i-1] == value[i]:
            continue
        else:
            ans = "No"
            break
    print(ans)

if __name__ == "__main__":
    main()

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

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

cur = 0

for h in Hs:
	if h < cur :
		print('No')
		break
	else:
		cur = max(h - 1, cur)
else :
	print('Yes')

Solution (Python):
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue

Mod = 1000000007




def main(): 
    N = int(input())
    H = list(map(int,input().split()))
    mav = 0
    for i in H:
        if mav <= i:
            mav = i
        elif mav - i >= 2:
            print("No")
            exit()
    print("Yes")

if __name__ == "__main__":
    main() 





def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n < 2 is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))):
        if prime[i] == 1:
            for j in range(2*i,n):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n):
        if prime[i] == 1:
            res.append(i)
    return res

class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py

    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

Solution (Python):

import sys, math, fractions, itertools

YES = "Yes"  
NO = "No"  

def solve(N: int, H: "List[int]"):
    c = H[-1]
    for h in reversed(H):
        if h-1 > c:
            print('No')
            return
        elif h - 1 == c:
            pass
        elif h == c:
            pass
        else:
            c = h
    print('Yes')
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    H = [ int(next(tokens)) for _ in range(N) ]  
    solve(N, H)

if __name__ == '__main__':
    main()

Solution (Python):

import sys, math, fractions, itertools

YES = "Yes"  
NO = "No"  

def solve(N: int, H: "List[int]"):
    c = H[-1]
    for h in reversed(H):
        if h-1 > c:
            print('No')
            return
        elif h - 1 == c:
            pass
        elif h == c:
            pass
        else:
            c = h
    print('Yes')
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    H = [ int(next(tokens)) for _ in range(N) ]  
    solve(N, H)

if __name__ == '__main__':
    main()

Solution (Python):
import sys

n = int(input())

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

max_num = 0
for i in range(len(h)):
  max_num = max(max_num, h[i])
  if max_num - h[i] >= 2:
    print("No")
    sys.exit(0)
    
print("Yes")

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

Solution (Python):

N = int(input())


Hs_str_s = input().split()


Hs_int_s = []


for Hs_str in Hs_str_s:
    Hs_int_s.append(int(Hs_str))

def is_yes():
    max = 0
    for Hs_int in Hs_int_s:
        
        if Hs_int >= max:
            max = Hs_int

        elif max - Hs_int >= 2:
            return False

    return True

if is_yes():
    print('Yes')

else:
    print('No')

Solution (Python):
from sys import stdin

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))

for i in range(n-1,0,-1):
    if li[i-1]-li[i] > 1:
        print("No")
        exit()
    elif li[i-1]-li[i] == 1:
        li[i-1] -= 1
print("Yes")

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






def is_yes(Hs):
    max = 0
    for H in Hs:
        
        if H > max:
            max = H
        
        if max - H >= 2:
            return False
    return True

if is_yes(Hs):
    print('Yes')
else:
    print('No')

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





prev = 'init'
is_yes = True
for i in range(N):
    current = Hs[N-1-i]
    if prev == 'init':
        prev = current
        continue
    elif prev >= current:
        prev = current
    elif prev == current - 1:
        prev = current - 1
    else:
        is_yes = False

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

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

m = h[0]

for i in range(1,n):
    if h[i]>=m-1:
        m = max(m,h[i])
    else:
        print('No')
        exit()

print('Yes')

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

if N != 1:
    for i in range(N-1):
        if H_list[N-1-i-1] - H_list[N-1-i] > 1:
            Flag = False
            break
        elif H_list[N-1-i-1] - H_list[N-1-i] == 1:
            H_list[N-1-i-1] = H_list[N-1-i-1] -1
        else:
            continue
    
if Flag == True:
    print("Yes")
else:
    print("No")

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

Solution (Python):
a = int(input())
b =list(map(int,input().split()))

c = 0

for i in range(a):
  if i>0:
    if (b[i] - b[i-1])<-1:
      c+=2
    if (b[i] - b[i-1])==-1:
      c+=1
    if (b[i] - b[i-1])>0:
      c=0
  if c>=2: break
if c<=1: print("Yes")
else: print("No")

Solution (Python):
n = int(input())
h = [int(i) for i in input().split()]
ans = "Yes"
for i in range(n - 1):
    if h[i] < h[i + 1]:
        if i + 2 < n:
            if h[i + 1] - 1 <= h[i + 2]:
                h[i + 1] -= 1        
    elif h[i] == h[i + 1]:
        continue
    elif h[i] > h[i + 1]:
        if h[i + 1] + 1 == h[i]:
            if i >= 1:
                if h[i] - h[i - 1] > 0:
                    h[i] -= 1
                else:
                    ans = "No"
            elif i == 0:
                h[i] -= 1
        else:
            ans = "No"
print(ans)

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

changed = False
result = "Yes"
for i in range(N):
    if i == 0:
        continue
    diff = H[N-i] - H[N-i-1]
    if changed:
        diff -= 1

    if diff >= 0:
        changed = False
        continue
    if diff == -1:
        changed = True
        continue
    if diff <= -2:
        result = "No"
        break

print(result)

Solution (Python):
n=int(input())
H=list(map(int,input().split()))
if n==1:
    print('Yes')
    exit()
if H[0]-H[1]>=2:
    print('No')
    exit()
if H[0]-H[1]==1:
    H[0]-=1
for i in range(1,n):
    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')

Solution (Python):
def solve(n,a):
    for i in range(n-1,0,-1):
        if a[i]>a[i+1]:
            a[i]-=1
    for i in range(2,n+1):
        if a[i]<a[i-1]:
            return 'No'
    return 'Yes'

n = int(input())
arr = list(map(int,input().split()))
arr.insert(0,0)
print (solve(n,arr))

Solution (Python):

n=int(input())
h=list(map(int,input().split()))
for i in range(1,n):
	if h[i]-1>=h[i-1]:
		h[i]-=1
x=sorted(h)
print("Yes" if x==h else "No")

Solution (Python):
def resolve():
    n = int(input())
    prev = None
 
    arr = map(int, input().split(" "))
 
    for a in arr:
        if prev is not None:
            if a - prev > 0:
                a -= 1
            elif a - prev < 0:
                print("No")
                return
        else:
            a -= 1
 
        prev = max(a, 1)
 
    print("Yes")
 
resolve()

Solution (Python):
def resolve():
    n = int(input())
    prev = None

    arr = map(int, input().split(" "))

    for a in arr:
        if prev is not None:
            if a - prev > 0:
                a -= 1
            elif a - prev < 0:
                print("No")
                return
        else:
            a -= 1

        prev = max(a, 1)

    print("Yes")

resolve()

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

print(jud(n,h))

Solution (Python):
N = int(input())
list = input().split()
H = [int(x) for x in list]
 
FLAG = True
current = H[N-1]
for i in reversed(range(N-1)):
  if(H[i]-1 > current):
    FLAG = False
    break
  elif(H[i]-1 == current):
    H[i] = H[i] -1
  else:
    H[i] = H[i]
  current = H[i]
  
if(FLAG == True):
  print("Yes")
else:
  print("No")

Solution (Python):
N = int(input())
H = list(map(int, input().split()))
ans = True
b = 999999
if ans == True:
  for i, x in enumerate(H[::-1]):
    if i != 0:
      if x <= b:
        b = x
      elif (x-1) <= b:
        b = x-1
      else:
        ans = False
        break
    else:
      b = x
if ans:
  print("Yes")
else:
  print("No")

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

for i in range(n-1,0,-1):
    if h[i] - h[i-1] < 0:
        h[i-1] -= 1
    if h[i] - h[i-1] < 0:
        print("No")
        sys.exit()
else:
    print("Yes")

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

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

Solution (Python):
n = int(input())
lst = list(map(int, input().split()))
flg = True

for i in range(len(lst)-2, 0, -1):
  if lst[i] == 1 + lst[i+1]:
    lst[i] -= 1
  elif lst[i] > 1 + lst[i+1]:
    flg = False
    break


if sorted(lst) != lst:
  flg = False
  
if flg:
  print("Yes")
else:
  print("No")

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

Solution (Python):

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

flag = True 
before = 0
for i in range(N-1):
    n1 = H[i] + before
    n2 = H[i+1]
    if n1 >= n2:
        before = 0
    elif n1 + 1== n2:
        before = -1
    else:
        flag = False
        break

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

Solution (Python):
N = int(input())
num = [int(i) for i in input().split()]
coment = 'Yes'

if N == 1:
  coment = 'Yes'
  
elif N == 2:
  if num[1] - num[0] < -1:
    coment = 'No'
    
else:
  for i in range(N-2):
    if num[i+1] - num[i] < -1:
      coment = 'No'
      break
    elif num[i+1] - num[i] < 0:
      for j in range(N-2-i):
        if num[i+2+j] - num[i+1] < 0:
          coment = 'No'
          break
        elif num[i+2+j] - num[i+1] > 0:
          break
          
print(coment)

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

mx = a[0]
for i in range(1, n):
    if mx-a[i]>1:
        print("No")
        break
    mx = max(mx, a[i])
else: print("Yes")

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

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

print('Yes')

Solution (Python):
N = int(input())
H = list(map(int, input().split()))
Flag = True
for i in reversed(range(1,N)):
    if H[i-1] - H[i] >= 2:
        Flag = False
        break
    elif H[i-1] - H[i] == 1:
        H[i-1] = H[i]
    
if Flag:
    print("Yes")
else:
    print("No")

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

h[0] = h[0] - 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')
        exit()

if h[0] <= h[-1]:
    print('Yes')

Solution (Python):
import sys
n = int(input())
h = list(map(int,input().split()))
mi = h[0]-1
if n == 1:
  print("Yes")
  sys.exit()
  
for i in range(1,n):
  if h[i-1]-1 == h[i]:
    if mi > h[i]:
      print("No")
      sys.exit()
    mi = h[i]
  elif h[i-1] > h[i]:
    print("No")
    sys.exit()
    
print("Yes")

Solution (Python):
N = int(input())
point = [int(i) for i in input().split()] 
flag = 0
for i in range(N-1):
    if point[i] < point[i+1]:
        point[i+1] -= 1
    elif point[i] == point[i+1]:
        continue
    else:
        flag = 1
if flag == 0:
    print("Yes")
else:
    print("No")

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

Solution (Python):
N = int(input())
Hi = list(map(int, input().split()))
    
Hi.reverse()
flag = 0
check = 0
for i in range(0, N-1):
    if Hi[i] > Hi[i+1]:
        flag = 0
    elif (Hi[i] == Hi[i+1]-1) and flag == 0:
        flag = 1
    elif Hi[i] == Hi[i+1]:
        pass
    else:
        check = 1
        
if check == 0:
    print("Yes")
else:
    print("No")

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

flag = "Yes"
for i in range(n):
    if i == 0:
        continue
    if k[n-i-1] > k[n-i]:
        k[n-i-1] -= 1
    if k[n-i-1] > k[n-i]:
        flag = "No"

print(flag)

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


h[0]-=1
ans="Yes"
for i in range(n-1):

  if h[i+1]==h[i]:
    continue
  elif h[i+1]>h[i]:
    h[i+1]-=1
  else:
    ans="No"
    break
print(ans)