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 = list(map(int, input().split()))

min_v = h_list[-1]
for i in range(n - 1, 0, -1):
    if h_list[i] < min_v:
        min_v = h_list[i]
    if h_list[i - 1] - min_v >= 2:
        print('No')
        break
else:
    print('Yes')

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

current = 0
prev = 0
_min = min(h)
_max = max(h)

for i in range(n):
  current = h[i]

  if i == 0:
    prev = current

  if i == 0 and current > 1:
    prev = current - 1

  if current > prev:
    prev = current - 1
  
  if current < prev:
    print("No")
    exit()

print("Yes")

Solution (Python):
n = n = int(input())
h = list(map(lambda x: int(x), input().split()))
flag = 0
mx = 0
for hi in h:
    if hi > mx:
        mx = hi
    if hi <= (mx - 2):
        flag = 1
        break
print('YNeos'[flag::2])

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

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


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


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, H):

    for i in range(1, N):
        if H[i-1] - H[i] > 1:
            return 'No'

    for i in range(N-1):
        if H[i] < H[i+1]:
            H[i+1] -= 1
    
    for i in range(1, N):
        if H[i-1] > H[i]:
            return 'No'
    
    return "Yes"


def slv2(N, H):

    for i in range(1, N):
        if H[i-1] - H[i] > 1:
            return 'No'

    for i in range(2, N):
        if H[i-2] > H[i-1] > H[i]:
            return 'No'

    return "Yes"


def main():
    N = read_int()
    H = read_int_n()
    print(slv(N, H))

    
    
    
    
    
    


if __name__ == '__main__':
    main()

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

Solution (Python):
n = int(input())
H = list(map(int, input().split()))
L = [H[0]-1]
if n == 1:
  print("Yes")
else:
  i=0
  while H[i+1] - L[i] >= 0:
    if i == n-2:
      print("Yes")
      break
    elif H[i+1] - L[i] == 0:
      L.append(H[i+1])
      i += 1
    elif H[i+1] - L[i] >= 1:
      L.append(H[i+1] - 1)
      i += 1
  else:
    print("No")

Solution (Python):
import numpy as np
import sys


def solve(H):
    a = 1
    prev = 0
    for c in H:
        if c > prev:
            if a == 0:
                a = 1
        elif c - a < prev:
            if a == 0:
                return 0
            elif a == 1:
                a = 0
                if c < prev:
                    return 0
        prev = c - a
    return 1


nin = np.fromstring(sys.stdin.buffer.read(), dtype=np.int64, sep=' ')
N = nin[0]
H = nin[1:N + 1]
result = solve(H)
if result:
    print("Yes")
else:
    print("No")

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

flag = 1
cnt = 1
for i in range(1,len(h)):
    if h[i]>h[i-1]: cnt = 1
    elif h[i]==h[i-1]: cnt += 1
    elif h[i]==h[i-1]-1:
        if i==1: continue
        if h[i-1]-1>=h[i-1-cnt]: continue
        else: flag = 0; break
    else: flag = 0; break

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

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

i = len(lh)-1
mi = lh[i]
while(i > 0): 
    if (lh[i-1] <= mi+1):
        mi = min(mi, lh[i-1])
        i -= 1
    else:
        print("No")
        exit()
    
print("Yes")

Solution (Python):
import sys
n = input()
l = input().split()
num = -1
for a in reversed(l):
    if num == -1:
        num = int(a)
    else:
        if num >= int(a):
            num = int(a)
        elif num >= int(a) - 1:
            num = int(a) - 1
        else:
            print('No')
            sys.exit()
print('Yes')

Solution (Python):
def solve():
    h = read()
    result = think(h)
    write(result)


def read():
    n = read_int(1)[0]
    return read_int(n)


def read_int(n):
    return list(map(lambda x: int(x), read_line().split(' ')))[:n]


def read_float(n):
    return list(map(lambda x: float(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(h):
    n = len(h)
    invalid = 10 ** 20

    dp = [[0 for x in range(2)] for y in range(len(h))]
    dp[0][0] = h[0]
    dp[0][1] = h[0] - 1
    for i in range(1, len(h)):
        dp[i][0] = h[i]
        dp[i][1] = h[i] - 1

        if dp[i][0] < dp[i - 1][0] and dp[i][0] < dp[i - 1][1]:
            dp[i][0] = invalid
        elif dp[i][0] < dp[i - 1][0] and dp[i][0] >= dp[i - 1][1]:
            dp[i][0] = h[i]
        elif dp[i][0] >= dp[i - 1][0] and dp[i][0] >= dp[i - 1][1]:
            dp[i][0] = h[i]
        elif dp[i][0] >= dp[i - 1][0] and dp[i][0] < dp[i - 1][1]:
            dp[i][0] = h[i]

        if dp[i][1] < dp[i - 1][0] and dp[i][1] < dp[i - 1][1]:
            dp[i][1] = invalid
        elif dp[i][1] < dp[i - 1][0] and dp[i][1] >= dp[i - 1][1]:
            dp[i][1] = h[i] - 1
        elif dp[i][1] >= dp[i - 1][0] and dp[i][1] >= dp[i - 1][1]:
            dp[i][1] = h[i] - 1
        elif dp[i][1] >= dp[i - 1][0] and dp[i][1] < dp[i - 1][1]:
            dp[i][1] = h[i] - 1

    return dp[n - 1][0] < invalid or dp[n - 1][1] < invalid


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


if __name__ == '__main__':
    solve()

Solution (Python):
n = int(input())
h = list(map(int, input().split()))
isYes = True
tmpmin = 10**9+1
for i in range(1, n):
    if h[n-i] <= tmpmin:
        tmpmin = h[n-i]
    if h[n-(i+1)]-h[n-i]>= 2 or h[n-(i+1)]-tmpmin >= 2:
        isYes = False
        break
if isYes:
    print('Yes')
else:
    print('No')

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

count = 0
most = 0
for val in range(n):
    if nums[val] >= count and nums[val]>= most:
        count = nums[val]-1
        if count > most:
            most =count
    else:
        print('No')
        val = -1
        break
if val == n - 1:         
    print('Yes')

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

flag=True

m=h_list[0]
for j in range(len(h_list)-1):
    if m<h_list[j]:
        m=h_list[j]
    if m-h_list[j+1]>=2:
        flag=False
        break        
    
if flag:
    print("Yes")
else:
    print("No")

Solution (Python):
"""


 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())


 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  


a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654


char_list = list("abcd") 
"""

import math
import sys
import itertools
import queue
from fractions import gcd
from itertools import accumulate

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    n = int(sys.stdin.readline())
    h = list(map(int, sys.stdin.readline().split()))
    for i in range(n-1):
        if h[i] > h[i+1] or (i>0 and h[i-1]<h[i] and h[i] == h[i+1]):
            h[i] -= 1
    s = sorted(h)

    if s == h:
        print("Yes")
    else:
        print("No")

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

res = True
if N >= 2:
    for i in range(N - 1):
        if H[i] - H[i + 1] >= 2:
            res = False

y_card = 0
if N >= 3 and res == True:
    for i in range(N - 1):
        if H[i] - H[i + 1] == 1:
            y_card += 1
            if y_card == 2:
                res = False
                break
        elif H[i] == H[i + 1]:
            pass
        elif H[i + 1] - H[i] >= 1:
            y_card -= H[i + 1] - H[i]
            if y_card < 0:
                y_card = 0


if res == True:
    print('Yes')
else:
    print('No')

Solution (Python):
N = int(input())
H = list(map(int, input().split()))
 
flag = False
for i in range(1, N):
    if H[i-1] > H[i]:
        if H[i-1] == H[i]+1:
            if flag==False:
                H[i-1] -= 1
                flag = True
        else:
            break
        if flag==False:
            H[i-1] -= 1
    else:
        if flag==False:
            H[i-1] -= 1
        if H[i-1] != H[i]:
            flag = False

if H == sorted(H):
    print('Yes')
else:
    print('No')

Solution (Python):
n = int(input())
h = list(map(int,input().split()))
a = 0
b = 0
x = [0]*n

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

    for k in range(n-1):
        if h[n-k-1]<h[n-k-2] and x[n-k-2]==0:
            h[n-k-2]=h[n-k-2]-1


    for j in range(n-1):
        if h[j]>h[j+1]:
            print("No")
            break
        a = a+1
    if a==n-1:
        print("Yes")

Solution (Python):

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

flg = True
h_p = H[0]
for h_c in H[1:]:
    if h_c < h_p:
        flg = False
        break

    if h_c > h_p:
        h_p = h_c - 1
    else:
        h_p = h_c


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

Solution (Python):
import  numpy   as  np
i_N =   int(input())
s_input =   input().split()
H   =   np.array(s_input).astype(type(i_N))

for i in range(1,i_N):
    if(H[i-1] > H[i] and abs(H[i-1] - H[i]) == 1):
        H[i] += 1
    elif(H[i-1] > H[i] and abs(H[i-1] - 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]:
        H[i] -= 1
    elif H[i] == H[i+1]:
        if H[i]-1 >= H[i-1]:
            H[i] -= 1

for i in range(N-1):
    if H[i] > H[i+1]:
        print('No')
        exit()

print('Yes')

Solution (Python):
"""
https://atcoder.jp/contests/abc136/tasks/abc136_c
"""

import numpy as np


def calc(N: int, values: np.ndarray) -> bool:
    
    if len(values) == 1:
        return True

    
    gradient = np.diff(values)
    if np.min(gradient) <= -2:
        return False

    
    if len(values) == 2:
        return True

    
    gradient_without_zero = gradient[gradient != 0]
    if len(gradient_without_zero) == 0:
        return True
    gradient_without_last = gradient_without_zero[:-1]
    gradient_without_first = gradient_without_zero[1:]
    if np.min(gradient_without_first + gradient_without_last) <= -2:
        return False
    return True


def load_input_as_int_array() -> np.ndarray:
    return np.array([int(v) for v in input().split(" ")])


def main() -> None:
    N, = load_input_as_int_array()
    values = load_input_as_int_array()
    result = calc(N, values)
    print("Yes" if result else "No")


main()

Solution (Python):
n = int(input())
h = list(map(int,input().split()))
tmp = h[0]
minused = False
res = True
for i in range(1,n):
    if h[i]>tmp:
        tmp = h[i]
        minused = False
        
    elif tmp == h[i]:
        tmp = h[i]
        
    else:
        if tmp-1>h[i]:
            res = False
            
            break
        else:
            if minused:
                res = False
                
                break
            minused = True
            tmp = tmp-1
            
if res:
    print("Yes")
else:
    print("No")

Solution (Python):
N=int(input())
k=list(map(int,input().split()))
b = 0
for i in reversed(range(1, N)):
    if(k[i-1] > k[i]):
        k[i-1] -= 1
        if(k[i-1] > k[i]):
            b = 1


if(b == 0 or N == 1):
    print("Yes")
else:
    print("No")

Solution (Python):
import copy
n=int(input())
ls=list(map(int,input().split(' ')))
new_ls=copy.copy(ls)
new_ls.insert(0,0)

flag=True
for i in range(1,n):
    new_ls[i]=new_ls[i]-1
    if new_ls[i]>=new_ls[i-1] and new_ls[i+1]>=new_ls[i]:
        pass
    else:
        new_ls[i]+=1
        if new_ls[i]<new_ls[i-1] or new_ls[i+1]<new_ls[i]:
            flag=False
            break

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

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

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

for i in range(N):
    if i == 0:
        H[i] -= 1
        continue

    if i == N - 1:
        if H[i] < H[i - 1]:
            print('No')
            exit()
        else:
            break

    if H[i + 1] - H[i] <= -2:
        print('No')
        exit()

    if H[i + 1] - H[i] <= 0:
        if H[i] > H[i - 1]:
            H[i] -= 1
    elif H[i] < H[i + 1] and H[i - 1] < H[i]:
        H[i] -= 1

    if H[i] < H[i - 1]:
        print('No')
        exit()

print('Yes')

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

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

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

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

maxdayo = 0
answer="Yes"
for i in range(1, N):
  m = H[i - 1] - H[i]
  if m <= 0:
    continue
  elif H[i] < maxdayo:
    answer="No"
    break
  elif m == 1:
    H[i - 1] -= 1
    maxdayo = max(maxdayo, H[i - 1])
  else:
    answer="No"
    break

print(answer)

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

ans = "Yes"

for i in range(N):
  if i == 0:
    H[0] -= 1
  else:
    if H[i-1] ==  H[i]:
      H[i-1] = H[i]
    elif H[i-1] > H[i]-1:
      ans = "No"
      break
    else:
      H[i] -= 1

print(ans)

Solution (Python):
N = int(input())
Hs = [int(H) for H in input().split(' ')]
cur_num = Hs[0]
impossible = False

for i in range(1, N):
    if cur_num < Hs[i]:
        cur_num = Hs[i] - 1
    elif cur_num > Hs[i]:
        impossible = True
        break

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

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

sage = True
mono = True
for i in range(n-1):
    if h[i+1] - h[i] > 0:
        sage = True
    elif h[i+1] - h[i] == 0:
        pass
    elif h[i+1] - h[i] == -1:
        if sage == True:
            sage = False
        else:
            mono = False
    else:
        mono = False
        
if mono == True:
    print("Yes")
else:
    print("No")

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


def can_mono(a):
    len_a = len(a)
    for i in range(len_a - 2):
        if a[i + 1] < a[i] - 1:
            return False
        if a[i + 1] < a[i]:
            for j in range(i + 1, len_a - 1):
                if a[j + 1] < a[i + 1]:
                    return False
                if a[j + 1] > a[i + 1]:
                    break
                if a[j + 1] == a[i + 1]:
                    continue
    return True


if can_mono(a):
    result = 'Yes'
else:
    result = 'No'
print("{}".format(result))

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

ans = "Yes"

max = 0

for i in h:
    if i > max:
        max = i
    if max - i > 1:
        ans = "No"

print(ans)

Solution (Python):
N = int(input())
H = list(map(int,input().split()))
hantei = 1
for i in range(1 , N)[::-1]:
    if (H[i] < H[i - 1]):
        H[i - 1] = H[i - 1] - 1
        if(H[i] < H[i - 1]):
            hantei = 0
            break

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

Solution (Python):
num = int(input())
row = [int(s) for s in input().split()]
row[0] -= 1
for i in range(num - 1):
  if row[i + 1] > row[i]:
    row[i + 1] -= 1

p = 0
for i in range(num - 1):
  if row[i] <= row[i + 1]:
    p += 1
    
if p == num - 1:
  print("Yes")
else:
  print("No")

Solution (Python):
import sys
A=int(input())
H=list(map(int,input().split()))
if A==1:
    print('Yes')
    sys.exit()
if H[0]==H[1]+1:
        H[0]-=1
elif H[0]>=H[1]+2:
        print('No')
        sys.exit()
for i in range(1,A-1):
    if H[i]==H[i+1]+1 and H[i]==H[i-1]:
        print('No')
        sys.exit()
    elif H[i]==H[i+1]+1 and H[i]>H[i-1]:
        H[i]-=1
    elif H[i]==H[i+1] and H[i]>H[i-1]:
        H[i]-=1
    elif H[i]>=H[i+1]+2:
        print('No')
        sys.exit()
print('Yes')

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

    judge = 'Yes'

    

    for i in range(1,N):
        if H[i-1] > H[i] :
            H[i-1] = H[i-1] - 1
        elif H[i-1] == H[i] and H[i-2] != H[i-1]:
            H[i-1] = H[i-1] - 1

        '''
        if i == N-1:
            if H[i-1] > H[i]:
                H[i] = H[i] - 1
        '''

    for i in range(1,N):
        if H[i-1] > H[i]:
            judge = 'No'
        if N == 1:
            judge = 'Yes'

    
    print(judge)

if __name__ == '__main__' :
    main()

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

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

i = n - 1

while i > 0:
    if h[i - 1] <= h[i]:
        i -= 1
    elif h[i - 1] - h[i] == 1:
        h[i - 1] -= 1
        i -= 1
    else:
        break

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

Solution (Python):
n = int(input())
h = list(map(int,input().split()))
flag = 0
k = 0
for i in range(n-1,0,-1):
    if(h[i-1]<=h[i]):
        continue
    elif(h[i-1]-1==h[i]):
        h[i-1]-=1
    else:
        flag = 1

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

Solution (Python):
import sys

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

for i in range(N - 1, 0, -1):
    if hLst[i] < hLst[i - 1]:
        hLst[i - 1] -= 1

for i in range(N - 1):
    if hLst[i + 1] < hLst[i]:
        print('No')
        sys.exit()

print('Yes')

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

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

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

Solution (Python):
import sys
from collections import deque

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

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

h1 = max(H.popleft()-1, 0)
h2 = H.popleft()

if h1 - h2 > 0:
    print("No")
    sys.exit()

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

def h2_can_be_decreased(h1, h2, h3):
    if h1 == h2:
        return False
    else:
        return True

for i in range(N-2):
    h3 = H.popleft()
    if h2 - h3 > 1:
        print("No")
        sys.exit()
    elif (h2 - h3 == 1):
        if h2_can_be_decreased(h1, h2, h3):
            h2 = max(h2-1, 0)
        else:
            print("No")
            sys.exit()
    else:
        if h2_can_be_decreased(h1, h2, h3):
            h2 = max(h2-1, 0)
            pass
        pass
    
    h1 = h2
    h2 = h3

print("Yes")

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

flag = True

for i in range(n - 1, 0, -1):
    if a[i - 1] - a[i] > 1:
        flag = False
        break
    elif a[i - 1] - a[i] == 1:
        a[i - 1] -= 1
    
if flag:
    print('Yes')
else:
    print('No')

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

n=N-1
while True:
    if n<=1:
        print("Yes")
        break
    if ln[n-1]<=ln[n] :
        n-=1
    elif (ln[n-1]-ln[n])<2:
        ln[n-1]=ln[n-1]-1
        n-=1
    else:
        print("No")
        break

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

Solution (Python):
N = int(input())
HN = input().split()

def build_stairs(N=N, HN=HN):
    if N == 1:
        return "Yes"
    for n in range(N-1):
        if HN[n] - HN[n+1] > 1:
            return "No"
        elif HN[n] - HN[n+1] == 1:
            HN[n+1] += 1
        if HN[n] < HN[n+1]:
            continue
    return "Yes"

HN = [int(i) for i in HN]
ans = build_stairs(N, HN)
print(ans)
print("")

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

res = 'Yes'
maximum = 0
for i in range(N - 1):
    if maximum < H[i]:
        maximum = H[i]
    if maximum - H[i+1] >= 2:
        res = 'No'

print(res)

Solution (Python):


import math

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]    


    token = lines[0].split(" ")
    n = int(token[0])
    
    a = [int(e) for e in lines[1].split(" ")]
    
    return (n, a)


def solve(n, a):


    current_max = -1
    result = "Yes"
    reduced_all = set()
    last_j = 0
    for i in range(n):

        if a[i] >= current_max:
            current_max = a[i]
        else:
            reduced_tmp = set()
            for j in range(last_j, i):
                if a[j] == current_max:
                    if j in reduced_all:
                        result = "No"
                        break
                    else:
                        reduced_tmp.add(j)

            if result == "No":
                break

            current_max = current_max - 1
            for j in reduced_tmp:
                reduced_all.add(j)
                a[j] = a[j] - 1
                if a[j] > a[i]:
                    result = "No"
                    break
                else:
                    last_j = max(j, last_j)


            if result == "No":
                break

    return result


def main():
    

    print("%s" % solve(*parse_input()))


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]-1:
        print('No')
        exit()
    elif h[i] < h[i-1]:
        h[i-1] = h[i-1]-1

print('Yes')

Solution (Python):
n1 = int(input())
n2 = tuple(map(int, input().split(" ")))

ans = True
max_value = n2[0]
max_index = 0
for i in range(n1):
    if max_value < n2[i]:
        max_value = n2[i]
        max_index = i
    if max_value - n2[i] >= 2:
        ans = False

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

Solution (Python):
n=int(input())
s=list(map(int,input().split()))
f=True
for i in range(n-1,0,-1):
    if s[i]<s[i-1]:
        s[i-1]-=1
for i in range(n-1,0,-1):
    if s[i]<s[i-1]:
        f=False
if f:
    print("Yes")
else:
    print("No")

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

if n == 1:
    print('Yes')
else:
    cnt = 0
    for i in range(1,n):
        if h[n-i] - h[n-i-1] <= -2:
            cnt = 1
            break
        elif h[n-i] - h[n-i-1] == -1:
            h[n-i-1]  -= 1

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

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

ans = True

for i in range(n-1,0,-1):
    if h[i-1] > h[i]:
        h[i-1] -= 1
for i in range(n-1,0,-1):
    if h[i-1] > h[i]:
        ans = False
        break

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

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

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




print("Yes")

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

state = "Yes"
tmp = h[-1]
for i in range(len(h)-1, 0, -1):
  if h[i] <= tmp:
    tmp = h[i]
  elif tmp - h[i] == -1:
    tmp = h[i] - 1
  else:
    state = "No"
    break

print(state)

Solution (Python):
def solve():
    n = int(input())
    H = list(map(int, input().split()))
    B = [True] * n
    last = 0
    for i in range(0, n - 1):
        if H[i] <= H[i + 1]:
            continue
        for j in range(i, last - 1, -1):
            if H[j] > H[j + 1]:
                if B[j] and H[j] - 1 == H[j + 1]:
                    H[j] -= 1
                    B[j] = False
                else:
                    return "No"
            else:
                break
        last = i
    return "Yes"
print(solve())

Solution (Python):


def change_number(nums_list, bit_flag):
    flag = 'Yes'
    for i in range(0, N-1):
        if int(args[i]) <= int(args[i+1]):
            pass
        elif int(args[i])-1 <= int(args[i+1]) and bit_flag[i] == 0:
            args[i] = str(int(args[i])-1)
            bit_flag[i] = 1
            flag = 'try'
        else:
            flag = 'No'
            break

    return flag, nums_list, bit_flag



if __name__ == '__main__':
    N = int(input())
    args = input().split()

    bit_flag = []
    bit_done_flag = []
    for i in range(0, N-1):
        bit_flag.append(0)
        bit_done_flag.append(1)

    flag = 'try'
    nums_list = args
    while flag == 'try':
        flag, nums_list, bit_flag = change_number(nums_list, bit_flag)


    print(flag)

Solution (Python):
N = int(input())
H = list(map(int, input().split()))
H.append(H[N - 1])
ans = True
ma = H[0]
if N != 1:
    for i in range(N - 1):
        ma = max(ma, H[i + 1])
        if ma - 1 > H[i + 1]:
            ans = False
            break
        elif H[i] <= H[i + 1]:
            continue
        elif H[i] - 1 <= H[i + 1]:
            H[i] = H[i] - 1
        else:
            ans = False
            break
if ans:
    print("Yes")
else:
    print("No")

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

if n != 1:
  for i in range(0, n):
    if i == 0:
      H[i] -= 1
    elif i == n-1:
      if H[i] >= H[i-1]:
        print('Yes')
      elif H[i] < H[i-1]:
        print('No')
    else:
      if H[i-1] < H[i]:
        H[i] -= 1
      elif H[i-1] == H[i]:
        continue
      elif H[i-1] > H[i]:
        print('No')
        break
elif n == 1:
  print('Yes')

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

for i in reversed(range(N)):
  if W+1<H[i]:
    print('No')
    exit()
  W=min(W,H[i])
print('Yes')

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


def solve(N, H):
    dp = [0] * N
    dp[0] = H[0] - 1
    for i in range(N-1):
        if dp[i] - H[i+1] >= 1:
            return False
        else:
            dp[i+1] = H[i+1] if dp[i] == H[i+1] else H[i+1] - 1

    return True


def main():
    N = int(input())
    H = list(map(int, input().split()))
    if solve(N, H):
        print('Yes')
    else:
        print('No')


if __name__ == "__main__":
    main()

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

Solution (Python):


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


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

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

ans = 'Yes'
flag = 0

for i in range(n-1):
    if h[i] - h[i+1] >= 2:
        ans = 'No'
        break
    elif h[i] - h[i+1] == 1:
        if flag == 0:
            flag = 1
        else:
            ans = 'No'
            break
    elif flag == 1:
        if h[i+1] - h[i] >= 1:
            flag = 0
            
print(ans)

Solution (Python):

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

Solution (Python):

def main():
    n = int(input())
    hs = [int(e) for e in input().split()]
    moved = [False for _ in range(n)]

    for i in range(n - 1):
        h = hs[i]
        hn = hs[i + 1]
        if h - hn > 1:
            print("No")
            return

    i = 0
    while i < n:
        if i == n - 1:
            print("Yes")
            return
        h = hs[i]
        hn = hs[i + 1]
        if h <= hn:
            i += 1
            continue
        
        if moved[i]:
            print("No")
            return
        else:
            moved[i] = True
            hs[i] -= 1
            i -= 1


if __name__ == '__main__':
    main()

Solution (Python):
a = [input() for i in range(2)]
n = int(a[0])
h = list(map(int, a[1].split()))[::-1]

str = "Yes"
c = 10**9
for i in range(n):
    if h[i] <= c:
        c = h[i]
    else:
        if (h[i]-1) == c:
            h[i] -= 1
        else:
            str = "No"
            break

print(str)

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

yesFlag = True

for i in range(len(H) - 1):
    if (H[i + 1] - H[i] > 0):
        H[i + 1] -= 1
    elif (H[i + 1] - H[i] < 0):
        yesFlag = False
    
if (yesFlag):
    print('Yes')
else:
    print('No')