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):
def main():

    """ convenient functions
    
    
    
    
    
    """

    """convenient decorator
    
    
        
        
        
        
        
        
        
        
        
        
    """
    
    
    import sys
    sys.setrecursionlimit(10**7)
    from itertools import accumulate, combinations, permutations, product 
    
    from math import factorial, ceil, floor, sqrt
    def factorize(n):
        """return the factors of the Arg and count of each factor
        
        Args:
            n (long): number to be resolved into factors
        
        Returns:
            list of tuples: factorize(220) returns [(2, 2), (5, 1), (11, 1)]
        """
        fct = []  
        b, e = 2, 0  
        while b * b <= n:
            while n % b == 0:
                n = n // b
                e = e + 1
            if e > 0:
                fct.append((b, e))
            b, e = b + 1, 0
        if n > 1:
            fct.append((n, 1))
        return fct
    def combinations_count(n, r):
        """Return the number of selecting r pieces of items from n kinds of items.
        
        Args:
            n (long): number
            r (long): number
        
        Raises:
            Exception: not defined when n or r is negative
        
        Returns:
            long: number
        """
        
        if n < 0 or r < 0:
            raise Exception('combinations_count(n, r) not defined when n or r is negative')
        if n - r < r: r = n - r
        if r < 0: return 0
        if r == 0: return 1
        if r == 1: return n
        numerator = [n - r + k + 1 for k in range(r)]
        denominator = [k + 1 for k in range(r)]
        for p in range(2,r+1):
            pivot = denominator[p - 1]
            if pivot > 1:
                offset = (n - r) % p
                for k in range(p-1,r,p):
                    numerator[k - offset] /= pivot
                    denominator[k] /= pivot
        result = 1
        for k in range(r):
            if numerator[k] > 1:
                result *= int(numerator[k])
        return result
    def combinations_with_replacement_count(n, r):
        """Return the number of selecting r pieces of items from n kinds of items allowing individual elements to be repeated more than once.
        
        Args:
            n (long): number
            r (long): number
        
        Raises:
            Exception: not defined when n or r is negative
        
        Returns:
            long: number
        """
        if n < 0 or r < 0:
            raise Exception('combinations_with_replacement_count(n, r) not defined when n or r is negative')
        elif n == 0:
            return 1
        else:
            return combinations_count(n + r - 1, r)
    from bisect import bisect_left, bisect_right
    from collections import deque, Counter, defaultdict 
    from heapq import heapify, heappop, heappush, heappushpop, heapreplace,nlargest,nsmallest 
    from copy import deepcopy, copy 
    import operator
    from operator import itemgetter 
    
    
    from functools import reduce, lru_cache
    def chmin(x, y):
        """change minimum
        if x > y, x = y and return (x, True).
        convenient when solving problems of dp[i]
        
        Args:
            x (long): current minimum value
            y (long): potential minimum value
        
        Returns:
            (x, bool): (x, True) when updated, else (x, False)
        """
        if x > y:
            x = y
            return (x, True)
        else:
            return (x, False)
    def chmax(x, y):
        """change maximum
        if x < y, x = y and return (x, True).
        convenient when solving problems of dp[i]
        
        Args:
            x (long): current maximum value
            y (long): potential maximum value
        
        Returns:
            (x, bool): (x, True) when updated, else (x, False)
        """
        if x < y:
            x = y
            return (x, True)
        else:
            return (x, False)

    from fractions import gcd 
    def gcds(numbers):
        return reduce(gcd, numbers)
    def lcm(x, y):
        return (x * y) // gcd(x, y)
    def lcms(numbers):
        return reduce(lcm, numbers, 1)

    
    
    INF = 10 ** 18
    MOD = 10 ** 9 + 7
    modpow = lambda a, n, p = MOD: pow(a, n, p) 
    def modinv(a, p = MOD):
        
        
        return modpow(a, p-2, p)
    def modinv_list(n, p = MOD):
        if n <= 1:
            return [0,1][:n+1]
        else:
            inv_t = [0,1]
            for i in range(2, n+1):
                inv_t += [inv_t[p % i] * (p - int(p / i)) % p]
            return inv_t
    def modfactorial_list(n, p = MOD):
        if n == 0:
            return [1]
        else:
            l = [0] * (n+1)
            tmp = 1
            for i in range(1, n+1):
                tmp = tmp * i % p
                l[i] = tmp
            return l
    def modcomb(n, k, fac_list = [], p = MOD):
        
        
        from math import factorial
        if n < 0 or k < 0 or n < k: return 0
        if n == 0 or k == 0: return 1
        if len(fac_list) <= n:
            a = factorial(n) % p
            b = factorial(k) % p
            c = factorial(n-k) % p
        else:
            a = fac_list[n]
            b = fac_list[k]
            c = fac_list[n-k]
        return (a * modpow(b, p-2, p) * modpow(c, p-2, p)) % p
    def modadd(a, b, p = MOD):
        return (a + b) % MOD
    def modsub(a, b, p = MOD):
        return (a - b) % p
    def modmul(a, b, p = MOD):
        return ((a % p) * (b % p)) % p
    def moddiv(a, b, p = MOD):
        return modmul(a, modpow(b, p-2, p))

    class UnionFindTree:
        """union find tree class
        TODO: fix this description...
        how to use (example):
        >>  uf = UnionFindTree(N) 
        >>  if uf.find_root(a) == uf.find_root(b):
        >>      do something
        >>  else:
        >>      do something
        >>      uf.unite(a, b)
        """
        def __init__(self, N):
            self.root = [-1] * (N+1)
            self.rank   = [0]  * (N+1)
            self.connected_num = [1] * (N+1)
    
        def find_root(self,x):
            root = self.root
            while root[x] != -1:
                x = root[x]
            return x
    
        def unite(self,x,y):
            root = self.root
            rank = self.rank
            connected_num = self.connected_num
            find_root = self.find_root
    
            rx = find_root(x)
            ry = find_root(y)
            if rx != ry:
                if rank[rx] < rank[ry]:
                    root[rx] = ry
                    rx,ry = ry,rx
                else:
                    if rank[rx] == rank[ry]:
                        rank[rx] += 1
                    root[ry] = rx       
                connected_num[rx] += connected_num[ry]

    """ initialize variables and set inputs
    
        
        
    
        
        
        
        
        
        
        
    
        
        
        
        
    
        
        
    """

    
    r = lambda: sys.stdin.readline().strip()
    r_int = lambda: int(r())
    R = lambda: list(map(int, r().split()))
    Rmap = lambda: map(int, r().split())
    Rfloat = lambda: list(map(float, r().split()))
    Rtuple = lambda: tuple(map(int, r().split()))

    """ how to treat input
    
    
    
    
    
    
    
    """

    if __name__ != '__main__':
        
        sys.stdin = open('sample.txt')
        
    
    

    N = int(r())
    H = R()
    H[0] = H[0] - 1
    for i in range(1,N):
        if H[i] == H[i-1]:
            continue
        elif H[i]-H[i-1] >= 1:
            H[i] = H[i] - 1
        else:
            print('No')
            exit()
    print('Yes')
    
    
    
    

    """memo: how to use defaultdict of list
    
    Dic = defaultdict(list)
    
    Dic[x].append(y)
    
    for k, v in Dic.items():
    """
    
    """memo: how to solve binary problems
    
    >>> a = 5
    >>> bin_str_a = format(a, '
    >>> print(bin_str_a)
    0b0101 
    """
    
    """memo: how to solve the problem
    creating simple test/answer
    greed
    simple dp
    graph
    """

if __name__ == '__main__':
    main()

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

mx = h[0]

flag = True
for i in range(1, n):
  if h[i] < mx - 1:
    print("No")
    flag = False
    break
  else:
    mx = max(mx, h[i])

if flag:
  print("Yes")

Solution (Python):
N= int(input())
H= list(map(int, input().split()))
flag=0
before=0
bad=0
for i in H:
    if bad==1:
        break
    if before<i:
        flag=0
    elif before==i:
        pass
    elif before==i+1:
        if flag==1:
            bad=1
            break
        else:
            flag=1
    else:
        bad=1
        break
    before=i
if bad==0:
    print('Yes')
else:
    print('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):

"""
AtCoder A
"""
 
import sys, math, random
import numpy as np
 







inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
 
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LLS(): return [list(sys.stdin.readline().rstrip()) for _ in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
 
 
 
def main():
    N=I()
    H=LI()
    prev=-100
    for i in H:
        if prev-i>1:
            print("No")
            exit()
        elif prev-i==1:
            prev=i+1
        else:
            prev=i
        
    print("Yes")
 
 
 
if __name__ == "__main__":
    main()

Solution (Python):


import sys
import math
import collections
import itertools
def input(): return sys.stdin.readline().strip()
def gcd(x, y): return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y): return (x * y) // gcd(x, y)
MOD = 10 **9 + 7

N = int(input())



H = [int(x) for x in input().split()]
H.reverse()





flag = True
tmp = 10 ** 9 + 1

for h in H :
    if h > tmp :
        if h - 1 > tmp :
            flag = False
            break
        tmp = h - 1

    else :
        tmp = h

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

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

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

s = 'Yes'

H[0] -= 1
for i in range(1, N):
    if H[i] > H[i-1]:
        H[i] -= 1
    
for i in range(1, N):
    if H[i] < H[i-1]:
        s = 'No'
        break

print(s)

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

hl[0] = hl[0]-1
for i in range(1,N-1):
    if(hl[i]>hl[i-1]):
        hl[i] = hl[i]-1
    if(hl[i]>hl[i+1]):
        print("No")
        exit(0)

print("Yes")

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools, os
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)
def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('- {} -> {}'.format(name, val), file=sys.stderr)
            return None

def main(N, H):
    """
    一番右の数字は低くする義理がない
    逆から見る？
    """
    for hidx in range(N):
        if hidx == 0:
            continue
        
        if H[N-1-hidx] > H[N-1-hidx+1]:
            H[N-1-hidx] -= 1
            if H[N-1-hidx] > H[N-1-hidx+1]:
                return 'No'
    else:
        for hidx in range(N-1):
            if H[hidx] > H[hidx+1]:
                return 'No'
        else:
            return 'Yes'



    
    
    
    
    
    
    
    
    
    
    
    
    
    


if __name__ == '__main__':
    if 'LOCAL' in os.environ:
        
        
        input_values = [
                """
                """.strip(),
                """
                """.strip()
                ]
        for input_value in input_values:
            input_value = input_value.split('\n')
            
            
            ans = main(N, A)
            expected_value = int(input_value[2])
            assert ans == expected_value, 'failed: ans: {ans}, exp: {exp}'.format(ans=ans, exp=expected_value)
    else:
        N = _I()
        H = LI()
        print(main(N, H))

Solution (Python):

n = int(input())
h = list(map(int, input().split()))
ans = True
for i in range(n - 1)[::-1]:
    if h[i] - 1 == h[i + 1]:
        h[i] -= 1
    if h[i] > h[i + 1]:
        ans = False
print(['No', 'Yes'][ans])

Solution (Python):



if __name__ == '__main__':
    n = int(input())
    h = list(map(int, input().split(' ')))
    _num = 0
    _flag = False
    for num in h:
        if _num > num:
            _flag = True
            break
        elif _num != num:
            _num = num - 1


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

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

MAX = hs[0]
result = True
for i in range(n):
    if hs[i] > MAX:
        MAX = hs[i]
    else:
        if MAX - hs[i] >= 2:
            result = False

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

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

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

Solution (Python):
N = int(input())
h_list = list(map(int,input().split()))
h_list.reverse()
def func():
    for i in range(N-1):
        if h_list[i+1] <= h_list[i]:
            pass
        elif h_list[i+1] == h_list[i]+1:
            h_list[i+1] -= 1
        elif h_list[i+1] >= h_list[i]+2:
            return False
    return True

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

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

flag = True
for i in range(N-1):
    if H[i] - H[i+1] > 1:
        flag = False
        break
ltd_num = H[0] - 2
for i in range(1, N):
    if H[i] <= ltd_num:
        flag = False
        break
    if ltd_num < H[i] - 2:
        ltd_num = H[i] - 2

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

Solution (Python):
import sys

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

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

Solution (Python):
import os, sys
import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")
 
sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10**18
MOD = 10**9 + 7

def N(): return int(sys.stdin.readline())
def li(): return list(map(int, sys.stdin.readline().split()))
def bulk_li(): return list(map(lambda s: list(map(int, s.split())), sys.stdin.readlines()))

n = N()
hs = np.array(li())

hs_diff = hs[1:] - hs[:-1]


result = 'Yes'
flg = 0
for diff in hs_diff:
  if diff < -1:
    result = 'No'
  elif diff == -1 and flg == 1:
    result = 'No'
  elif diff == -1:
    flg = 1
  elif diff == 0 and flg == 1:
    flg = 1
  else:
    flg = 0

print(result)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  for i in range(n-1)[::-1]:
    if l[i]>l[i+1]:
      l[i]-=1

  for i in range(n-1):
    if l[i]>l[i+1]:
      return 'No'

  
  return 'Yes'


print(main())

Solution (Python):

import sys
INF = float("inf")


def yes():
    print("Yes")  


def no():
    print("No")  


def solve(N: int, H: "List[int]"):

    H[0] = H[0]-1
    for i in range(1, N):
        if H[i-1]+1 == H[i]:
            H[i] -= 1
        elif H[i-1] == H[i]:
            H[i] = H[i]
        elif H[i-1] > H[i]:
            no()
            return
        else:
            H[i] -= 1
    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):
a=int(input())
b=list(map(int,input().split()))
b=b[::-1]
for i in range(a-1):
  if b[i+1]-b[i]>=2:
    print("No")
    exit()
  if b[i+1]>b[i]:
    b[i+1]-=1

print("Yes")

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

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

ans = "Yes"
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]:
    pass
  elif h_list[i]>h_list[i+1]:
    ans = "No"

print(ans)

Solution (Python):
N = int(input())
H = [int(i) for i in input().split()]
for i in reversed(range(1, N)):
  if(H[i] - H[i-1] < -1):
    print('No')
    exit()
  elif(H[i] - H[i-1] == -1):
    H[i-1] -= 1
print('Yes')

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


class SegmentTree():
    def __init__(self, n, func, init=float('inf')):
        '''
        n->配列の長さ
        func:func(a,b)->val,　func=minだとRMQになる
        木の高さhとすると,
        n:h-1までのノード数。h段目のノードにアクセスするために使う。
        data:ノード。
        parent:k->child k*2+1とk*2+2
        '''
        self.n = 2**(n-1).bit_length()
        self.init = init
        self.data = [init]*(2*self.n)
        self.func = func

    def set(self, k, v):
        '''
        あたいの初期化
        '''
        self.data[k+self.n-1] = v

    def build(self):
        '''
        setの後に一斉更新
        '''
        for k in reversed(range(self.n-1)):
            self.data[k] = self.func(self.data[k*2+1], self.data[k*2+2])

    def update(self, k, a):
        '''
        list[k]=aに更新する。
        更新ぶんをrootまで更新
        '''
        k += self.n-1
        self.data[k] = a

        while k > 0:
            k = (k-1)//2
            self.data[k] = self.func(self.data[k*2+1], self.data[k*2+2])

    def query(self, l, r):
        '''
        [l,r)のfuncを求める
        '''
        L = l+self.n
        R = r+self.n
        ret = self.init
        while L < R:
            if R & 1:
                R -= 1
                ret = self.func(ret, self.data[R-1])
            if L & 1:
                ret = self.func(ret, self.data[L-1])
                L += 1
            L >>= 1
            R >>= 1
        return ret


N = int(input())
L = list(map(int, input().split()))
ans = "Yes"

Seg = SegmentTree(N, min, init=float('inf'))
for i, h in enumerate(L):
    Seg.set(i, h)

Seg.build()

for i, h in enumerate(L[:-1]):
    if h <= Seg.query(i+1, N)+1:
        continue
    else:
        ans = "No"
        break
print(ans)

Solution (Python):
n = int(input())
h = [int(_) for _ in input().split()]
flg = True
for i in range(n-1):
    j = n-1-i
    if h[j]-h[j-1]>=0:
        continue
    if h[j]-h[j-1]<=-2:
        flg = False
        break
    if h[j]-h[j-1]==-1:
        h[j-1]-=1
        continue
if flg:
    print('Yes')
else:
    print('No')

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

prev_h = 0
answer = 'Yes'
for h in H:
    if h - 1 >= prev_h:
        prev_h = h - 1
    elif h >= prev_h:
        prev_h = h
    else:
        answer = 'No'
        break
print(answer)

Solution (Python):
n = int(input())
hhh = list(map(int, input().split()))
cur = hhh[0]
for h in hhh[1:]:
    if cur > h:
        print('No')
        break
    cur = max(cur, h - 1)
else:
    print('Yes')

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

ok=True
d=0
for i in range(N):

    if i == 0:
        d=H[0]-1
    else:
        if H[i]-1 >= d:
            d=max(H[i]-1,d)
        elif H[i] >= d:
            d=d
        else:
            ok=False
            break

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

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

print("Yes")

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

for i in range(N-2, -1, -1):
    if H[i] - H[i + 1] > 1:
        print("No")
        exit(0)
    if H[i] - H[i + 1] > 0:
        H[i] -= 1
for i in range(N-1):
    if H[i] > H[i + 1]:
        print("No")
        exit(0)
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]:
        h[i+1] += 1
ans = "Yes"
for i in range(n-1):
    if h[i]>h[i+1]:
        ans = "No"
print(ans)

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

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

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

Solution (Python):
n = int(input())                                                                 
ary = [int(x) for x in input().split()]                                          
def check(ary):                                                                  
    biggest = 0                                                                  
    for num in ary:                                                              
        if biggest-1 > num:                                                      
            return False                                                         
        biggest = max(biggest, num)                                              
    return True                                                                  
if check(ary):                                                                   
    print("Yes")                                                                 
else:                                                                            
    print("No")

Solution (Python):
import numpy as np
n = int(input())
h = np.array([-1] + [int(x) for x in input().split()] + [1e9])

flag = True
for i in range(1, n+1):
    prev = h[i-1]
    now = h[i]
    next = h[i+1]
    if prev < now:
        h[i] -= 1
    elif prev == now:
        pass
    else:
        flag = False
        break

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

Solution (Python):
n=int(input())
da=list(map(int,input().split()))
ma=da[0]
ju=True
for i in range(n):
    if ma-da[i]>0:
        ju=False
        break
    else:
        ma=max(ma,da[i]-1)
if ju:
    print('Yes')
else:
    print('No')

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

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

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

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

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

li.reverse()

mins = 100000000000

isyes = True
for i in li:
    if i < mins:
        mins = i
    
    if i - mins > 1:
        isyes=False

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

Solution (Python):
import sys


def input():
    return sys.stdin.readline()[:-1]


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

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


if __name__ == "__main__":
    main()

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

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]:h[i-1]-=1
s='Yes'
for i in range(n-1):
    if h[i]>h[i+1]:s='No';break
print(s)

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

cur = 0
for h in H:
    if h > cur:
        cur = h
    if h  < cur - 1:
        print('No')
        break
else:
    print('Yes')

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

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

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

Solution (Python):
import numpy as np
import math
import sys
sys.setrecursionlimit(10000000)

def main():
    N = int(input())
    H = [int(c) for c in input().split()]
    for i in range(N - 1):
        if (H[i] > H[i + 1]):
            print("No")
            sys.exit()
        elif (H[i] == H[i + 1]):
            continue
        else:
            H[i + 1] -= 1
    print("Yes")

if __name__ == '__main__':
    main()

Solution (Python):

N = int(input())
H = list(map(int, input().split()))
flag = True
tmp = H[N-1]
for i in range(N-1, 0, -1):
    if H[i - 1] - H[i] > 1:
        flag = False
    elif H[i - 1] - H[i] == 1:
        H[i - 1] -= 1
    else:
        pass
    if flag == False:
        break
if flag:
    print("Yes")
else:
    print("No")

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


if N == 1:
    print('Yes')
    exit()

s = H[0]
for i in range(1, N):
    h = H[i]
    if s <= h:
        s = h
    else:
        if s - h > 1:
            
            print('No')
            exit()

print('Yes')

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

ans="Yes"
cnt=h[0]

for i in range(n):
    cnt=max(h[i],cnt)
    if cnt-h[i]>=2:
        ans="No"
        break
    else:
        continue

print(ans)

Solution (Python):
n=int(input())
da=list(map(int,input().split()))
ma=da[0]
ju=True
for i in range(n):
    if ma-da[i]>0:
        ju=False
        break
    else:
        ma=max(ma,da[i]-1)
if ju:
    print('Yes')
else:
    print('No')

Solution (Python):
def build_stairs(N: int, H: list)->bool:
    for i in range(N-1, 0, -1):
        if H[i-1] <= H[i]:
            continue
        H[i-1] -= 1
        if H[i-1] > H[i]:
            return False
    return True


if __name__ == "__main__":
    N = int(input())
    H = list(map(int, input().split()))

    yes = build_stairs(N, H)
    print('Yes' if yes else 'No')

Solution (Python):

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

flag = True
pre = hs[-1]

for h in hs[::-1]:
    if h <= pre:
        pre = h
    elif h-1 <= pre:
        pre = h-1
    else:
        flag = False
        break

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

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

print("Yes")

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

z = False
for a,b in zip(H,H[1:]):
    if a<b:
        z = False
    if a<=b:
        continue
    if a-b > 1:
        print('No')
        exit()
    assert a-b == 1
    if z:
        print('No')
        exit()
    z = True

print('Yes')

Solution (Python):
n = int(input())
li = list(map(int,input().split()))
max1 = 0

for i in range(n-1):
    if li[i] > max1:
        max1 = li[i]
    if max1 - li[i+1] >= 2:
        print('No')
        exit()

print('Yes')

Solution (Python):

import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline






















def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	N = inputInt()
	H = inputList()

	flg = True
	for i, val in enumerate(H):
		if i == 0:
			continue
		if H[i-1] < H[i]:
			H[i] -= 1

	
	for i, val in enumerate(H):
		if i == 0:
			continue
		if H[i] < H[i-1]:
			flg = False

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


if __name__ == "__main__":
	main()

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

tmp = H[0]
min = H[0]-1
for i in range(1, N):
    if tmp <= H[i]:
        tmp = H[i]
    elif tmp == H[i] + 1:
        if min < tmp:
            min = tmp - 1
            tmp = H[i]
        else:
            print("No")
            sys.exit()
    else:
        print("No")
        sys.exit()

print("Yes")

Solution (Python):
N = int(input())
H_list = [int(x) for x in input().split()]
ans = True
for i, h in enumerate(H_list):
    if (i == N-1): break
    else:
        if (h <= H_list[i+1]): continue
        elif (h-1 == H_list[i+1]):
            H_list[i+1] += 1
        else:
            ans = False
            break
print("Yes" if ans else "No")