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

for i in range(n-1):
  if h[i]<h[i+1]:
    h[i+1]-=1
if sorted(h)==h:
  print('Yes')
else:
  print('No')

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

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10 ** 6)
    n = int(input())
    h = list(map(int, input().split()))

    lastHErasita = False

    for i in range(1, n):
        if h[i] > h[i - 1]:
            lastHErasita = False
            continue
        if h[i] == h[i - 1]:
            continue
        elif h[i] == h[i - 1] - 1 and lastHErasita == False:
            lastHErasita = True
        else:
            print('No')
            exit(0)
    print('Yes')


if __name__ == '__main__':
    main()

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

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

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

ans = 'Yes'
pre = -100

for i in H:
    if i < pre:
        ans = 'No'
        break
    elif i == pre:
        continue
    pre = i-1

print(ans)

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

Solution (Python):
import numpy as np
n = int(input())
a = list(int(i) for i in input().split())  

x = -float("inf")
for i in range(n):
  if a[i] < x:
    if a[i] == x - 1:
      pass
    else:
      print('No')
      exit()
  else:
    x = a[i]
print('Yes')

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

result = True
for i in range(1, N):
    if H[i] < H[i - 1]:
        if H[i] == H[i - 1] - 1:
            H[i] += 1
        else:
            result = False
            break

print(["No", "Yes"][result])

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

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

if H[0]>=2:
    pre = H[0] - 1
else:
    pre = H[0]

flag = True

for i in range(1, N):
    if H[i]<pre:
        flag = False
        break
    elif H[i]==pre:
        pass
    else:
        pre = H[i] - 1

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

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]:
        continue
    elif h[i-1] == h[i] + 1:
        h[i-1] -= 1
    else:
        print("No")
        exit(0)
print("Yes")

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

for i in reversed(range(n)):
    if i < n - 1:

        h[i] = int(h[i])
        h[i + 1] = int(h[i + 1])

        if h[i] > h[i + 1]:
            h[i] -= 1
            if h[i] > h[i + 1]:
                print('No')
                exit()

print('Yes')

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

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

jug = True
for i in range(n-1):
    if h[i] <= h[i+1]:
        continue
    if h[i] == h[i+1] + 1:
        h[i+1] += 1
    else:
        jug = False

if jug == True:
    print("Yes")
elif jug == False:
    print("No")

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


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

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

x = -999
h.reverse()
for i in range(n):
    if i == 0:
        continue
    if h[i] > h[i-1]:
        if h[i]-h[i-1] == 1:
            h[i] -= 1
        else:
            print("No")
            quit()
print("Yes")

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

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

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

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

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

for i in range(n-1):
    if height[i] > height[i+1]:
        print("No")
        break
else:
    print("Yes")

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

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

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

h = [h for h in map(int, input().split(' '))]




if n == 1:
  print('Yes')
  sys.exit()

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

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

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

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:
    H[i+1]+= 1
  elif H[i] - H[i+1] > 1:
    flag = False
    break

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

Solution (Python):
n = int(input())
h = list(map(int,input().split()))
pre = h[-1]
ans = "Yes"
flag = False
count = 0

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

Solution (Python):
N= int(input())
H=[int(x) for x in input().split()]
hantei = True
for i in range(2,N):
  if H[-i]-1 == H[-i+1]:
    H[-i] -= 1
  elif H[-i]-1>H[-i+1]:
    hantei = False
print('Yes' if hantei else 'No')

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

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

Solution (Python):

import sys










def main():
    n, *h = [int(x) for x in sys.stdin.read().split()]

    
    ans = 'Yes'
    maximum = h[0]
    for i in range(1, n):
        if maximum - h[i] >= 2:
            ans = 'No'
            break
        maximum = max(maximum, h[i])

    print(ans)
    



if __name__ == "__main__":
    main()

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

a = 0
for i in h:
    if i < a:
        ans = 'No'
        break
    elif a < i:
        a = i - 1

print(ans)

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

c = 0
for i in h:
    if c > i:
        print('No')
        exit()
    elif c < i:
        c = i-1
print('Yes')

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

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


def main():
    sc = Scan()
    sc.intarr()[0]
    h = sc.intarr()
    before = 0
    flag = False
    for i in h:
        if before - i >= 2:
            print('No')
            exit()
        if before - i >= 1:
            if flag:
                print('No')
                exit()
            flag = True
        if before - i < 0:
            flag = False
        before = i
    print('Yes')


class Scan():

    def intarr(self):
        line = input()
        array = line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


main()

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

def main():
    n = int(input())
    nums = list(map(int, input().split()))

    for x in reversed(range(1, len(nums))):
        if nums[x-1] > nums[x]:
            nums[x-1] -= 1

        if nums[x-1] > nums[x]:
            print('No')
            sys.exit()

    print('Yes')


if __name__ == '__main__':
    main()

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

for x in range(n):
    if maxnum < nums[x]:
        maxnum = nums[x]
    if maxnum - nums[x] > 1:
        print('No')
        sys.exit() 
 
print('Yes')

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

    h[0] -= 1
    for i in range(1,n):
        if h[i-1]<h[i]:
            h[i] -= 1
        if h[i-1]>h[i]:
            return 'No'
    return 'Yes'

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

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

Solution (Python):
from collections import defaultdict,deque, Counter
import sys,heapq,bisect,math,itertools,string,queue,copy,time
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
ans = 'No'
n = inp()
Hlist = inpl()
i = n-1
while i:
    if Hlist[i-1] >= Hlist[i]+2: 
        ans = 'No'
        break
    elif Hlist[i-1] == Hlist[i]+1:
        Hlist[i-1] = Hlist[i]
    i += -1

if i == 0: ans = 'Yes'

print(ans)

Solution (Python):
import sys
from collections import deque
sys.setrecursionlimit(20000000)
input = sys.stdin.readline


























def main():
    n = int(input())

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

    for x in reversed(range(1, len(nums))):
        if nums[x-1] > nums[x]:
            nums[x-1] -= 1

        if nums[x-1] > nums[x]:
            print('No')
            sys.exit()

    print('Yes')


if __name__ == '__main__':
    main()

Solution (Python):

import sys
import math
input = sys.stdin.readline


def main():
    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] == h[i + 1] + 1:
            h[i] -= 1
            continue
        elif h[i] > h[i + 1]:
            print("No")
            return
    print("Yes")


if __name__ == '__main__':
    main()

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

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

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

Solution (Python):

import sys
def input():
    return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    Hs=[int(x) for x in input().split()]

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



if __name__ == '__main__':
    main()

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

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

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

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

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

h_last = 10 ** 9
answer = 'Yes'
for i in range(n):
  h = h_list[n-i-1]
  if h <= h_last:
    h_last = h
  elif h - 1 == h_last:
    h_last = h - 1
  else:
    answer = 'No'
    break

print(answer)

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b



def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2



def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)



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


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

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

        if H[i - 1] < H[i]:
            H[i] -= 1

    print("Yes")


if __name__ == '__main__':
    main()

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

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

Solution (Python):
ii = lambda : int(input())
li = lambda : list(map(int, input().split()))

n = ii()
h = li()

h2 = h[::-1]

if n==1:
    cnt = 0
else:
    cnt = 0
    for i in range(n-1):
        if h2[i] < h2[i+1]:
            h2[i+1] -= 1
            if h2[i] < h2[i+1]:
                cnt += 1

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

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

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

Solution (Python):
import sys
input = sys.stdin.readline
def print_ans(N, H):
    """Test Case
    >>> print_ans(5, [1, 2, 1, 1, 3])
    Yes
    >>> print_ans(4, [1, 3, 2, 1])
    No
    >>> print_ans(5, [1, 2, 3, 4, 5])
    Yes
    >>> print_ans(1, [1000000000])
    Yes
    """
    if N == 1 :
        print("Yes")
    else:
        tmp_max = 0
        for i in range(N - 1):
            if (H[i] > H[i + 1] and H[i] - 1 > H[i + 1] ) or tmp_max > H[i + 1]  :
                print("No")
                break
            else:
                if H[i] < H[i + 1]:
                    H[i + 1] -= 1
                    tmp_max = H[i + 1]
            if i == N -2:
                print("Yes")



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

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

Solution (Python):
import sys
n=int(input())
h=list(map(int,input().split()))
tmp=0
for i in h:
  if i<tmp:
    print("No")
    sys.exit()
  tmp=max(i-1,tmp)
print("Yes")

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

for i in range(N - 1):
	if H[N - i - 2] - H[N - i - 1] > 1:
		flag = 'No'
		break
	elif H[N - i - 2] - H[N - i - 1] == 1:
		H[N - i - 2] = H[N - i - 2] - 1
	else:
		pass

print(flag)

Solution (Python):


n = int(input())
l = list(map(int, input().split()))
prev = 0
ans = "Yes"

if n > 1:
  prev = l[0]
  for i in range(1, n):
    
    if prev != l[i] and prev > (l[i] - 1):
      ans = "No"
      break
    
    if prev == l[i]:
      prev = l[i]
    else:
      prev = l[i] - 1

print(ans)

Solution (Python):
N = int(input())
H = list(map(int, input().split()))
v = -1
for h in H:
    if v > h:
        if v != h+1:
            print("No")
            exit()
        else:
            v = h+1
    else:
        v = h
print("Yes")

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

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

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

a.reverse()

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

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

Solution (Python):

N = int(input())
H = list(map(int,input().split()))
stp = 0
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]:
        pass
    else:
        stp += 1
        print("No")
        break
if stp == 0:
    print("Yes")

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

Solution (Python):
N = int(input())
H = list(map(int,input().split()))
stp = 0
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]:
        pass
    else:
        stp += 1
        print("No")
        break
if stp == 0:
    print("Yes")

Solution (Python):
N = int(input())
H = list(map(int,input().split()))
stp=0
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]:
        pass
    elif H[i] < H[i-1]+1:
        print("No")
        stp = 1
        break
if stp != 1:
    print("Yes")

Solution (Python):
N = int(input())
H = list(map(int, input().split()))
v = -1
for h in H:
    if v > h:
        if v != h+1:
            print("No")
            exit()
        else:
            v = h+1
    else:
        v = h
print("Yes")

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

out = "Yes"

now_height = H[0]
if now_height > 0:
    now_height -= 1

for i in range(1, n):
    if now_height <= H[i] - 1:
        now_height = H[i] - 1
    elif now_height <= H[i]:
        now_height = H[i]
    else:
        out = "No"
        break

print(out)

Solution (Python):
import math
import heapq
import sys
from collections import Counter




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

min=1000000000
for i in reversed(range(1,N+1)):
    
    if H[i-1]>min:
        print('No')
        sys.exit()
    if H[i-1]<min:
        min = H[i-1]+1

print('Yes')

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

res = 'Yes'
hmax = 0
tmp = 0

for i in h:
    if hmax < tmp:
        hmax = tmp
    if hmax >= i+2:
        res = 'No'
        break
    tmp = i

print(res)

Solution (Python):
import numpy as np
N = int(input())
h_list = list(map(int, input().split()))

sort_h_list = sorted(h_list)
h_array = np.array(h_list)
sort_h_array = np.array(sort_h_list)

diff_array = sort_h_array - h_array

if max(abs(diff_array)) >= 2:
    print('No')
else:
    print('Yes')

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

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

Solution (Python):
n = int(input())
h = list(map(int,input().split()))
flag = True
b = -1
for i in range(n):
    if h[i] - b > 0:
        b = h[i] - 1
    elif h[i] - b == 0:
        b = h[i]

    else:
        flag = False
        break

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

Solution (Python):
import sys

input = sys.stdin.readline

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

pre = H[0]
ans = True

for i in H[1:]:
    if  pre < i: pre = i -1
    elif pre > i:
        ans = False
        break

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

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

Solution (Python):
n=int(input())
h=list(map(int,input().split(" ")))
m=h[0]
a=False
for i in h:
    if i+1<m:
        a=True
    if i>m:
        m=i
print('YNeos'[a::2])

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

L=L[::-1]

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

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

Solution (Python):



n = int(input())
hl = list(map(int,input().split()))	
nl = []
before_h = hl[0]
for h in hl:
    if h > before_h:
        nl.append(h-1)
        before_h = h-1
    else:
        nl.append(h)
        before_h = h
if nl == sorted(nl):
    print("Yes")
else:
    print("No")

Solution (Python):
N = int(input())
H = reversed(list(map(int, input().split())))
p = float('INF')
for i in H:
    if p >= i:
        p = i
    elif p + 1 == i:
        pass
        
    else:
        print('No')
        exit()
    
print('Yes')

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

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

ans = 'Yes'
max = 0
for h in H:
    
    if h <= max - 2:
        ans = 'No'
        break

    
    if h >= max:
        max = h
    else:
        continue

print(ans)

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

maxv = 0
for h in H:
    if h < maxv-1:
        print('No')
        exit()
    maxv = max(maxv, h)
else:
    print('Yes')

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

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


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

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

if cnt==n-1:
  print('Yes')
else:
  print('No')

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

    if num >= max:
        max = num
    else:
        continue
print(ans)

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

count = 0
for i in range(N-1):
    num = N-i-1
    if(H[num-1]-1==H[num]):
        H[num-1] -= 1
    elif(H[num-1]-1>H[num]):
        count += 1
        break
        
if(count == 0):
    print("Yes")
else:
    print("No")

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

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

print('Yes')

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

flag = True
for i in range(n-1, 0, -1):
    diff = (hn[i] - hn[i-1]) 
    if diff == -1:
        hn[i-1] -= 1
    elif diff < -1:
        flag = False
        break
    
if flag:
    print("Yes")
else:
    print("No")

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

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

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

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

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

Solution (Python):
def hantei(h):
    mustmax = h[0]
    for hh in h:
        if hh - 1 == mustmax:
            pass
        elif hh-1 < mustmax:
            mustmax = hh
        else:
            print("No")
            return
        
    print("Yes")
    return
        

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

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

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

maxh = h[0]

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

print("Yes")

Solution (Python):

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

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

    if hl[i-1]>hl[i]:
        print("No")
        exit()

print("Yes")

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

ans = 'Yes'
flag = False
for i in range(len(H)-1):
    if H[i] - H[i+1] > 1:
        ans = 'No'
        break
    elif H[i] - H[i+1] > 0:
        if flag:
            ans  = 'No'
        flag = True

    elif H[i] - H[i+1] < 0:
            flag = False

print(ans)

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

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

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

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

print('Yes')

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

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

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

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


INCREASING = 1
DECREASED_BY_1 = 2
FAIL = -1

state = INCREASING

for i in range(1, N): 
    if state == INCREASING:
        if H[i] == H[i - 1] - 1: 
            state = DECREASED_BY_1
        elif H[i] <= H[i - 1] - 2: 
            state = FAIL
    elif state == DECREASED_BY_1:
        if H[i] > H[i - 1]: 
            state = INCREASING
        elif H[i] < H[i - 1]: 
            state = FAIL
    else:
        break

ans = "Yes" if state is not FAIL else "No"
print(ans)

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


if __name__ == '__main__':
    main()

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