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

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

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

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

print('Yes')

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

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

    print('Yes')



if __name__ == "__main__":
    main()

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

for i in range(1, N):
    if H[i-1] > H[i]:
        print("No")
        quit()
    elif H[i-1] < H[i]:
        H[i] -=1
else:
    print("Yes")

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

Solution (Python):
from collections import Counter
a = int(input())
num_list = list(map(int,input().split()))
flag = "ok"
num_o = 0
for i in range(a-1):
  if num_list[i] > num_o:
    num_list[i] = num_list[i]-1
    num_o = num_list[i]
  if num_list[i]-num_list[i+1] > 0:
    flag = "ng"
    break

num_counter = Counter(num_list)
num_most = num_counter.most_common()


if flag == "ok":
  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]:
        print('No')
        import sys
        sys.exit()
    elif h[i]==h[i-1]:
        continue
    else:
        h[i]-=1
print('Yes')

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
deka=-1
for i in range(n):
  if deka>=A[i]+2:
    print("No")
    exit()
  deka=max(deka,A[i])
print("Yes")

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

prev = H[-1]
for i in range(N - 2, -1, -1):
    
    if not H[i] <= prev:
        if not H[i] - 1 <= prev:
            print('No')
            quit()
        else:
            H[i] -= 1
            prev = H[i]
    else:
        prev = H[i]
print('Yes')

Solution (Python):
import sys
import math

from collections import defaultdict
from collections import deque
def load(vtype=int):
    return vtype(input().strip())
def load_list(seplator=" ", vtype=int):
    return [vtype(v) for v in input().strip().split(seplator)]
def exit():
    import sys
    sys.exit(0)
def perm_sub(li, used):
    if len(li) == len(used):
        return [deque()]
    k = []
    for i in range(len(li)):
        if i in used:
            continue
        used.add(i)
        sub_list = perm_sub(li, used)
        for sub in sub_list:
            sub.appendleft(li[i])
        k.extend(sub_list)
        used.discard(i)
    return k
def perm_li(li):
    return perm_sub(li, set())
def perm_n(n):
    return perm_sub(list(range(n)), set())
def join_i(li, sep=""):
    return sep.join([str(e) for e in li])
def li2n(li):
    n, base = 0, 1
    for i in range(len(li)-1, -1, -1):
        n += li[i] * base
        base *= 10
    return n
def sli2ili(li):
    return [int(s) for s in li] 
def prime_list(n):
    li = [i for i in range(2, n+1)]
    for i in range(len(li)):
        if li[i] >= int(math.sqrt(n)):
            break
        if li[i] == -1:
            continue
        for j in range(i+1, len(li)):
            if li[j] % li[i] == 0:
                li[j] = -1
    return [n for n in li if n != -1]
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while True:
        r = a % b
        if r == 0: return b
        a, b = b, r
def lcm(a, b):
    return int(a * b / gcd(a,b))
def all_subset(li):
    s = []
    n = len(li)
    for bit in range(0, (1<<(n+1))):
        ss = set()
        for i in range(0, n):
            if (bit & (1 << i)):
                ss.add(li[i])
        s.append(ss)
    return s

n = load()
H = load_list()

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

print('Yes')

Solution (Python):

"""
Created on Wed Mar 25 20:51:57 2020

@author: Kanaru Sato
"""

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

flag = 0
mh = 10**10

for i in range(n-1):
    if h[n-1-i]-mh <= 1:
        mh = min(mh, h[n-1-i])
    else:
        flag = 1
        break

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

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

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

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

Solution (Python):
n = int(input())
h = list(map(int, input().split()))
mn = 0
ans = "Yes"
for i in h:
    if i <= mn - 2:
        ans = "No"
    else:
        mn = max(mn, i)
print(ans)

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

Solution (Python):
import math
import os
import random
import re
import sys

def check_non_decreasing_squares(n: int, a: list):
    p = a[0]
    for i in range(1, n):
        if a[i] > p:
            p = a[i]
        if p - a[i] == 1 or p - a[i] == 0:
            continue
        print("No")
        exit(0)
    print("Yes")

if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().rstrip().split()))
    check_non_decreasing_squares(n, a)

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

def f():
    global h
    for i in range(n - 1, 0, -1):
        diff = h[i - 1] - h[i]
        
        if diff >= 2:
            return 'No'
        elif diff == 1:
            h[i - 1] = h[i - 1] - 1
    
    return 'Yes'

print(f())

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

Solution (Python):
import math
import os
import random
import re
import sys

def check_non_decreasing_squares(n: int, a: list):
    for i in range(1, n):
        if a[i] != a[i - 1]:
            if a[i] - 1 < a[i - 1]:
                print("No")
                sys.exit(0)
            a[i] -= 1
    print("Yes")

if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().rstrip().split()))
    check_non_decreasing_squares(n, a)

Solution (Python):
import sys

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

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

print("Yes")

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

flg = 0
max = 0
if n > 1 :
  for i in range(n):
    if h[i] > max:
      max = h[i]
    elif h[i] < max-1 :
      flg = 1
      break
 
if flg == 1 :
  print('No')
else:
  print('Yes')

Solution (Python):
n = int(input())
h = list(map(int,input().split()))
flg = 0
max = 0
if n > 1 :
  for i in range(n):
    if h[i] > max:
      max = h[i]
    elif h[i] < max-1 :
      flg = 1
      break

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

Solution (Python):












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

ans = "Yes"
minH = arrA[0]-1
for i in arrA:
    if i-1 >= minH:
        minH = max(minH,i-1)
    elif i >= minH:
        minH = max(minH,i)
    else:
        ans = "No"
        break

print(ans)

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

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

Solution (Python):
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
H = np.array(lr())
X = np.minimum.accumulate(H[::-1])[::-1]
Y = H - X
answer = np.any(Y>=2)
print('No' if answer else 'Yes')

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

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

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

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a.reverse()
for i in range(n-1):
    if a[i] < a[i+1]:
        a[i+1] -=1
count = 0
for i in range(n-1):
    if a[i] < a[i+1]:
        count+=1
if count == 0:
    print("Yes")
else:
    print("No")

Solution (Python):

import sys
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
    elif H[i] != H[i+1]:
        print('No')
        sys.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] >= h[i-1]:
        continue
    elif h[i] - h[i-1] < -1:
        print('No')
        break
    else:
        h[i-1] -= 1
else:
    print('Yes')

Solution (Python):

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

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

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

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

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

Solution (Python):
N = int(input())
H = list(map(int, input().split()))
is_ng = False
t_max = H[0]
for i in range(1, len(H)):
    t_max = max(t_max, H[i])
    if t_max-1 > H[i]:
        is_ng = True
        break
print('YNeos'[is_ng::2])

Solution (Python):
n = int(input())
h = [int(x) for x in input().split()]
can = True
for i in range(n):
    if i == 0:
        h[i] -= 1
    else:
        if h[i - 1] < h[i]:
            h[i] -= 1
        elif h[i - 1] == h[i]:
            continue
        else:
            can = False
print('Yes' if can else 'No')

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

Solution (Python):

N = int(input())
H_list = [int(e) for e in input().split()]

H_list[0] -= 1 

for i in range(1,N):
    
    
    
    if H_list[i-1] < H_list[i]:
        H_list[i] -= 1
    
    if H_list[i-1] > H_list[i]:
        print("No")
        break
else:
    print("Yes")

Solution (Python):








def resolve():

    N=int(input())
    H=list(map(int,input().split()))
    def main():
        if N == 1:
            return 'Yes'
        maxval=0
        for i in range(N):
            if maxval-2>=H[i]:
                return 'No'
            else:
                maxval=max(maxval,H[i])
        return 'Yes'
    print(main())


resolve()

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

j = 0
for i in range(n):
    if h[i] == j:
        pass
    elif h[i] > j:
        j = h[i] - 1
    else:
        if h[i] == j:
            pass
        else:
            print("No")
            break
else:
    print("Yes")

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

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

res = "Yes"
is_down = False
for i in range(N-1):
  if H[i] >= H[i+1] + 2:
    res = "No"
    break
  elif H[i] == H[i+1] + 1:
    if is_down:
      res = "No"
      break
    else:
      is_down = True
  elif H[i] < H[i+1]:
    is_down = False

print(res)

Solution (Python):
import sys
from heapq import heappush, heappop


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

if __name__ == '__main__':
    main()

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

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

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

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

flag = True
minH = 0
for x in range(len(H)):
    if H[x] < minH:
        flag = False
        break
    else:
        if minH < H[x]:
            minH = H[x] - 1
if flag:
    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-2] <= h[-i-1]:
        pass
    else:
        if h[-i-2] - h[-i-1] == 1:
            h[-i-2] -= 1
        else:
            flag = False

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

Solution (Python):

"""
C - Build Stairs
https://atcoder.jp/contests/abc136/tasks/abc136_c

"""
import sys


def solve(N, stairs):
    stairs[0] -= 1
    for pos in range(1, N):
        if stairs[pos] < stairs[pos-1]:
            return 'No'
        if stairs[pos] >= stairs[pos-1] + 1:
            stairs[pos] -= 1
    return 'Yes'


def main(args):
    N = int(input())
    stairs = [int(h) for h in input().split()]
    ans = solve(N, stairs)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

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

tmp_max = 0
for i in range(n):
    if h[i] <= tmp_max - 2:
        print('No')
        sys.exit()
    tmp_max = max(tmp_max, h[i])

print('Yes')

Solution (Python):
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    ans = True
    m = 0
    for i in range(N-1):
        m = max(m, A[i])
        if m-1 > A[i+1]:
            ans = False
    return 'Yes' if ans else 'No'

print(solve())

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] < h[i-1]-1:
        print("No")
        exit()
print("Yes")

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

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

c = 1
a = "Yes"

for i in range(N):
  if H[i] > c:
    c = H[i]-1
  elif H[i] < c:
    a = "No"
    break
print(a)

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
t=0
for i in l:
  if i<t: print('No'); exit()
  if i>t: t=i-1
print('Yes')

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
t=l.pop(0)-1
for i in l:
  if i<t: print('No'); exit()
  if i>t: t=i-1
print('Yes')

Solution (Python):
N = int(input())
H = [int(h) for h in input().split()]
f = 0
for n in range(N-1, 0, -1):
    if H[n] < H[n-1]:
        H[n-1] -= 1
        if H[n] < H[n-1]:
            print("No")
            break

else:
    print("Yes")

Solution (Python):
N = int(input())
h = list(map(int, input().split()))[::-1]
f = [0] * N
ans = 'Yes'
last = 10 ** 10
for hi in h:
    if last >= hi:
        last = hi
    elif last >= hi - 1:
        last = hi - 1
    else:
        ans = 'No'
print(ans)

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

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

Solution (Python):

def submit():
    n = int(input())
    hlist = list(map(int, input().split()))
    hlist = hlist[::-1]

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

    for i in range(1, n):
        if hlist[i - 1] >= hlist[i]:
            continue

        if hlist[i - 1] == hlist[i] - 1:
            hlist[i] -= 1
        else:
            print("No")
            return

    print("Yes")


if __name__ == "__main__":
    submit()

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

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

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

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

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

height = 0

for k in h:
    
    if k - height >= -1:
        height = max(height, k)
    else:
        print("No")
        exit()

print("Yes")

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

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

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

print('Yes')

Solution (Python):

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

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

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

Solution (Python):
t=int(input())
x=[int(i)for i in input().split()]
ans=0
max=0

for j in range(t):
	if x[j]>max:
		max=x[j]
	elif x[j]+1<max:
		ans=1
if ans==0:
	print('Yes')
else:
	print('No')

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

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

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

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

Solution (Python):

n = int(input())
h = list(map(int, input().split()))
ans = True
pre = -1
for num in h:
    if num > pre:
        pre = num-1
    elif num == pre:
        pre = num
    else:
        ans = False
        break
if ans:
    print('Yes')
else:
    print('No')

Solution (Python):
n = int(input())
h = list(map(int,input().split()))
for i in range(n-1):
         if h[i]  - h[i+1] >= 2:
                  print("No")
                  exit()
         elif h[i-1] != h[i] :
                  h[i] = max(1,h[i] - 1)
         elif h[i-1] == h[i] and  h[i] - h[i+1] >= 1:
                  print("No")
                  exit()
print("Yes")

Solution (Python):
n = int(input())
h_stack = list(map(int, input().split()))
flag = True
pre_h = 10 ** 9
while h_stack:
  h = h_stack.pop()
  if h > pre_h + 1:
    flag = False
    break
  elif h == pre_h + 1:
    h -= 1
  pre_h = h
if flag:
  print('Yes')
else:
  print('No')

Solution (Python):
def main():
  _, *h=map(int, open(0).read().split())
  x=h[-1]
  for y in h[-2::-1]:
    if x<y-1:
      return 'No'
    x=y-(x<y)    
  return 'Yes'

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

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

is_judge = True
for i in reversed(range(n-1)):
	if h[i]>h[i+1]:
		if h[i]-1 > h[i+1]:
			is_judge = False
		else:
			h[i] = h[i]-1



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

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

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

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

right = H[-1]
for i in range(N - 2, -1, -1):
    if right >= H[i]:
        right = H[i]
        continue
    elif right + 1 == H[i]:
        H[i] -= 1
        right = H[i]
    else:
        print("No")
        break
else:
    print("Yes")

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

seed = h[0]
checker = True

for i in range(1,n):
    if h[i] == h[i-1]:
        continue
    d = h[i] - h[i-1] + 1
    if d > 0:
        checker = True
        pass
    elif d == 0:
        if checker:
            checker = False
        else:
            print('No')
            quit()
    else:
        print('No')
        quit()


print('Yes')

Solution (Python):
input()
a=list(map(int,input().split()))
pivot=0
flag=0
for i in a:
  if pivot<i:pivot=i
  if pivot-i>1:flag=1;break
print('YNeos'[flag::2])

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

ok = True
for i in range(n-1)[::-1]:
    
        
    if h[i] <= h[i+1]:
        continue
    elif h[i] == h[i+1] + 1:
        h[i] -= 1
    else:
        ok = False
    
        
if ok:
    print('Yes')
else:
    print('No')

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

List = [int(i) for i in input().split(" ")[::-1]]

Min = List[0]
i=1
flag = 0

for i in range(N):
    if (List[i]-Min)>=2:
        flag=1
        break
    else:
        if List[i]<Min:
            Min=List[i]
if flag==0:
    print("Yes")
else:
    print("No")

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

H_ls = list(map(int, input().split(" ")))

h_left = H_ls[0]-1

ans = "Yes"
for h in H_ls:
    if h_left < h:
        h-=1
    elif h_left > h:
        ans = 'No'
        break
    h_left = h

print(ans)

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

max=0
flag=0
for i in range(n):
    if l[i] >= max:
        max=l[i]
    else:
        if max-l[i] == 1:
            continue
        else:
            flag=1
            break

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

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

for i in range(1, N):
    if H[-i-1] <= H[-i]:
        pass
    elif H[-i-1] == H[-i]+1:
        H[-i-1] -= 1
    else:
        print("No")
        break
else:
    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:
        print('No')
        exit(0)
    elif h[i - 1] - h[i] == 1:
        h[i - 1] = max(h[i - 1] - 1, 1)
    else:
        pass


print('Yes')

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


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

print('Yes')

Solution (Python):
def main():
    n = int(input())
    A = list(map(int, input().split()))
    mx = 0
    for a in A:
        if mx > a:
            print('No')
            return
        mx = max(mx, a-1)
    print('Yes')
main()

Solution (Python):
def main():
    n=int(input())
    H=list(map(int,input().split()))
    now=H[0]-1
    if n==0:
        print('Yes')
        return
    for h in H[1:]:
        if now > h:
            print('No')
            return
        elif now == h:
            now = h
        else:
            now = h -1
    print('Yes')
main()

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

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

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

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

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

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

Solution (Python):
import math
import sys

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

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

Solution (Python):

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

flg=True
for i in range(1,n):
    if h[i-1]<h[i]:
        h[i]-=1
        if h[i-1]<h[i]:
            flg=False
            break
print('Yes' if flg else 'No')

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

print(ans)

Solution (Python):
import sys
import os
import itertools


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = int(sys.stdin.readline().rstrip())
    H = list(map(int, sys.stdin.readline().split()))

    ret = 'Yes'
    tmp = -1
    for n in range(N):
        if tmp > H[n]:
            if tmp != H[n] + 1:
                ret = 'No'
            else:
                tmp = H[n] + 1
        else:
            tmp = H[n]

    print(ret)


if __name__ == '__main__':
    main()

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

print(ans)

Solution (Python):
from sys import stdin

n = int(stdin.readline().rstrip())
h = [int(x) for x in stdin.readline().rstrip().split()]

a = h[0]
for i in range(1, n-1):
    a = max(h[i], a)
    b = h[i+1]
    if a-b >= 2:
        print("No")
        exit()
print("Yes")

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

temp = H[0] - 1
for i in range(1, N) :
    if H[i] > temp :
        temp = H[i] - 1
    elif H[i] == temp :
        temp = H[i]
    else :
        print("No")
        exit()

print("Yes")

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

Solution (Python):

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

for i in range(n - 1):
    if data[i] < data[i + 1]:
        data[i + 1] -= 1

for i in range(n - 1):
    if data[i] > data[i + 1]:
        
        print("No")
        exit()

print("Yes")

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

c=1
max_h=0
for i in h:
  if max_h>=i+2:
    c=0
  max_h=max(max_h,i)

print('Yes' if c==1 else 'No')

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

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

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

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