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



dp = ['' for i in range(N)]



dp[0] = h[0]


ans = "Yes"

for i in range(1,N):
    if h[i] == dp[i-1]: 
        dp[i] = dp[i-1]

    elif h[i] > dp[i-1]:
        if h[i]-1 == dp[i-1]: 
            dp[i] = dp[i-1]
        else:
            dp[i] = h[i]-1
    else:
        ans = "No"
        break


print(ans)

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

if N == 1:
    print("Yes")
else:
    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] = H[i]
        else:
            
            break
    
    if i == 1:
        print("Yes")
    else:
        print("No")

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

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

print(ans)

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

flag = True

for i in range(N-1):
  if (li[i] - li[i+1]) >= 2:
    print('No')
    flag = False
    break
  if li[i] < li[i+1] and  (li[i] - li[i+1]) <= -1:
    li[i+1] -= 1
  if (li[i] - li[i+1]) >= 1:
    print('No')
    flag = False
    break

if flag:
  print('Yes')

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

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


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


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

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

print('Yes')

Solution (Python):

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


hmax = 0
if n == 1:
    print('Yes')
    exit()

for i in range(n):
    if (hl[i] >= (hmax - 1)):
        hmax = max(hmax,hl[i])
        if i == n - 1:
        	print('Yes')
        	break
    else:
        print('No')
        break

Solution (Python):
N = int(input())
H = list(map(int,input().split()))
h = H[0]-1
a = "Yes"

for i in range(N):
  if H[i]==h:
    pass
  elif h<H[i]:
    h=H[i]-1
  else:
    a = "No"

print(a)

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

Solution (Python):
N = int(input())
A = [0]*(N)
H = list(map(int, input().split()))
ans = "Yes"

hmax = max(H)
k = H.index(hmax)
Hd = [0]*k
Hdmax=int(0)
for i in range(k):
    Hd[i] = H[i]
    Hdmax = max(Hdmax,Hd[i])
    if H[i] < Hdmax - 1:
        ans = "No"

for i in range(k,N,1):
    if H[i]<hmax-1:
        ans = "No"


print(ans)

Solution (Python):
import sys

def solve(n, h):
  if n == 1:
    return "Yes"

  for i in xrange(n):
    if i == n - 1:
      break

    if h[n-1 - i - 1] <= h[n-1 - i]:
      continue
    elif h[n-1 - i - 1] - 1 == h[n-1 - i]:
      h[n-1 - i - 1] -= 1
    else:
      return "No"

  return "Yes"


if __name__ == '__main__':

  n = int(sys.stdin.readline().strip())
  h = map(int, sys.stdin.readline().strip().split(" "))
  print solve(n, h)

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

prev = 0
for h in H:
  diff = h - prev
  if diff > 0:
    h = h - 1
  elif diff < 0:
    print("No")
    break

  prev = h
else:
  print("Yes")

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

ans = 'Yes'
m = h[0] - 1
for i in range(1, n):
    if m == h[i]:
        continue
    if m < h[i]:
        m = h[i] - 1
        continue
    ans = 'No'
    break
print(ans)

Solution (Python):
from sys import stdin


def main():
    N = int(stdin.readline())
    H = [int(x) for x in stdin.readline().rstrip().split()]

    H_re = list(reversed(H))

    for i in range(N):
        if i == N-1:
            print("Yes")
            break

        if H_re[i] >= H_re[i+1]:
            pass
        else:
            if H_re[i] >= H_re[i+1] - 1:
                H_re[i+1] = H_re[i+1] - 1
                pass
            else:
                print("No")
                break


if __name__ == "__main__":
    main()

Solution (Python):

ccc=[list(map(int,input().split())) for i in range(2)]


if ccc[0][0] == 1:
  print("Yes")
else:
  for idx in range(1,ccc[0][0]):
    if (ccc[1][idx-1] <= ccc[1][idx]):
      if (idx == ccc[0][0]-1):
        print("Yes")
      continue
    elif (ccc[1][idx-1]  == ccc[1][idx] + 1 ):
      ccc[1][idx] = ccc[1][idx-1]
      if (idx == ccc[0][0]-1):
        print("Yes")
      continue
    elif (ccc[1][idx-1] -1 > ccc[1][idx] ):
      print("No")
      break

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

now_h = H[0]
e = 0
for h in H:
    if h - now_h == -1:
        if e > h:
            print('No')
            exit()
        else:
            e = h
            now_h -= 1
    elif h - now_h < -1:
        print('No')
        exit()
    now_h = h

print('Yes')

Solution (Python):
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10

N = int(stdin.readline().rstrip())
H = [int(x) for x in stdin.readline().rstrip().split()]

flg = True

maxn = -INF

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

    if diff >= 0:
        if diff == 0:
            pass
        else:
            H[i] = H[i] - 1
            maxn = max(H[i], maxn)
        continue

    if diff == -1:
        if H[i] - 1 >= maxn:
            H[i] = H[i] - 1
            maxn = max(H[i], maxn)
        else:
            flg = False
            break
    
    else:
        flg = False
        break


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

Solution (Python):
import sys
def main():
    input = sys.stdin.readline
    N = int(input())
    Hs= list(map(int, input().split()))
    hs = [0]
    ans = ""
    for i in range(N):
        hs.append(0)
        
        h_tmp = Hs[i]
        if i < N - 1:
            h_next = Hs[i + 1]
            if h_tmp < h_next:
                hs[i + 1] = 1
                Hs[i + 1] -= 1
                pass
            elif h_tmp == h_next:
                pass
            elif h_tmp - 1 == h_next and hs[i] == 0:
                if i > 0:
                    h_before = Hs[i - 1]
                    if h_before <= h_tmp - 1:
                        pass
                    else:
                        ans = "No"
                        break
                elif i == 0:
                    pass
            else:
                ans = "No"
                break
    if ans == "":
        ans = "Yes"
 
    print(ans)
 
if __name__ == '__main__':
    main()

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



max_n = 0
i = 1
for s in l:
	if s <= max_n-2:
		print('No')
		break
	if s > max_n:
		max_n = s
	if i==n:
		print('Yes')
	i+=1

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

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

for i in range(n-2,0 , -1):
    
    if   a[i] <= a[i+1]:
        continue
    elif a[i] - a[i+1] > 1:
        print("No")
        sys.exit()
    else:
        a[i] = a[i] -1
        continue
print("Yes")

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

Solution (Python):
N = int(input())
H = list(int(i) for i in input().split())
"""
N = 5
H = [1,2,1,1,3]
"""
if len(H) == 1:
    print("Yes")

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

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

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

is_ok = True
before_n = 0
kotae_list = []

for i, h in enumerate(h_list[:-1]):
    if h_list[i] <= h_list[i+1]:
        
        
        if before_n <= h_list[i] - 1:
            before_n = h_list[i] - 1

        else:
            
            before_n = h_list[i]
        kotae_list.append(before_n)
        continue
    else:
        if before_n <= h_list[i] - 1:
            
            if h_list[i] - 1 <= h_list[i+1]:
                
                before_n = h_list[i] - 1
                kotae_list.append(before_n)
                continue
            else:
                
                
                is_ok = False
                break
        else:
            
            is_ok = False



ans = 'Yes' if is_ok else 'No'
print(ans)

Solution (Python):

N = int(input())
H = list(map(int,input().split()))
tmp_top = H[-1]
thg = True
for i in range(1,N+1):
  if H[-i] - tmp_top >= 2:
    thg = False
    
  if tmp_top > H[-i]:
    tmp_top = H[-i]

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

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

for i in range(N):
    decr = None
    if i+1 != N:
        if Hs[i] > Hs[i+1]:
            decr = True
            Hs[i] -= 1
        if Hs[i] > Hs[i+1]:
            print('No')
            exit()

    if i == 0:
        continue

    if Hs[i] > Hs[i-1]:
        if not decr:
            Hs[i] -= 1
    if Hs[i] < Hs[i-1]:
        print('No')
        exit()

print('Yes')

Solution (Python):
N = int(input())
H = list(map(int, input().split()))
pval = max(H)
f = 1
for h in reversed(H):
  if (pval + 1 < h):
    print("No")
    f = 0
    break
  if (pval + 1 == h):
    pval = h - 1
  else:
    pval = h
if(f):
  print("Yes")

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

ans='Yes'
f=0

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

print(ans)

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

flag = 0
c = [0]*N
for i in range(N):
    if i == 0:
        pass
    else:
        if H[i]-H[i-1] >= 1:
            H[i] -= 1
            c[i] = 1
        elif H[i]-H[i-1] == 0:
            pass
        elif H[i]-H[i-1] == -1:
            if i == 1:
                H[i-1] -= 1
                c[i-1] = 1
            else:
                if H[i-2] <= H[i] and c[i-1] == 0:
                    H[i-1] -= 1
                    c[i-1] = 1
                else:
                    flag = 1
                    break
        elif H[i]-H[i-1] < -1:
            flag = 1
            break
if flag == 1:
    print("No")
else:
    print("Yes")

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

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

Solution (Python):
N = int(input())
H = [int(i) for i in input().split()]
ct = 0
flag = True
for i in range(N-1):
  if(H[i+1]-H[i] <= -2):
    flag = False
    break
  elif(H[i+1]-H[i] == -1 and ct >= 1):
    flag = False
    break
  elif(H[i+1]-H[i] == -1 and ct == 0):
    ct += 1
  elif(H[i+1] -H[i] >= 1):
    ct = 0
if(flag):
  print("Yes")
else:
  print("No")

Solution (Python):
import sys

N = int(input())
Hs = [int(i) for i in input().split()]

ans = "Yes"

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

if N == 2:
    if Hs[0] > Hs[1]:
        Hs[0] -= 1
        if Hs[0] > Hs[1]:
            print("No")
            sys.exit()
    print("Yes")
    sys.exit()
    
for i in range(N-1, 1, -1):
    if Hs[i] < Hs[i-1]:
        Hs[i-1] -= 1
        if Hs[i] < Hs[i-1]:
            print("No")
            sys.exit()

if Hs[-1] < Hs[-2]:
    ans = "No"
if Hs[1] < Hs[0]:
    ans = "No"

print(ans)

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

for i in range(N-1):
    if H[i] > H[i+1] + 1:
        Ans = False
    elif H[i] == H[i+1] + 1:
        if H[i-j] == H[i]:
            j = 1
            continue
        else:
            Ans = False
            break
    elif H[i] == H[i+1]:
        j += 1
    else:
        j = 0
        continue

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

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

Solution (Python):
import queue

"""
N = int(input())



A = []
for i in range(N):
	A.append(int(input()))

print(A)

"""
N = int(input())
A = [int(i) for i in input().split()]

ok = 1
border = A[0]
for i in range(1,len(A)):
	if border > A[i]:
		ok = 0
		break
	border = max(border,A[i]-1)
if ok==1:
	print("Yes")
else:
	print("No")

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

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

min = 0

for i in h:
  if min == i:
    continue
  if min > i:
    print("No")
    exit()
  if min < i:
    min = i - 1


print("Yes")

Solution (Python):
n = int(input())
h = [int(i) for i in input().split()]
i = n - 1
while i >= 1:
    if h[i] >= h[i-1]:
        i -= 1
    elif h[i] == h[i-1] - 1:
        h[i-1] -= 1
        i -= 1
    else:
        print('No')
        break
else:
    print('Yes')

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

OK = False
reach = False

if n == 1:
    OK = True

d = []
for i in range(n-1):
    d.append(h[i] - h[i+1])

for i in range(n-1):
    if d[i] >= 2 or (d[i] == 1 and reach == True):
        break
    elif d[i] == 1:
        reach = True
    elif d[i] < 0:
        reach = False

    if i == n-2:
        OK = True

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

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

h0 = H[0] - 1
for i in range(1, len(H)):
    h = H[i]

    if h0 < h:
        h -= 1
    elif h0 > h:
        print("No")
        exit()

    h0 = h

   
print("Yes")

Solution (Python):
n=int(input())
hoge=list(map(int,input().split()))
hoge.reverse()
now=hoge[0]
use=0
for i in range(n-1):
  x=hoge[i+1]
  if(now<x-1):
    print("No")
    exit()
  elif(now==x-1 and use==0):
    use=1
    now=x-1
  elif(now==x-1 and use==1):
    use=1
    now=x-1
  elif(now==x and use==0):
    use=0
    now=x
  elif(now==x and use==1):
    use=0
    now=x
  else:
    use=0
    now=x
    
print("Yes")

Solution (Python):
from enum import Enum
from queue import Queue
import collections

import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

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





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

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

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

stairs = list(map(int, input().split())) + [0]
for i in range(N-1):
    if stairs[i + 1] - stairs[i] < 0:
        stairs[i] -= 1
    elif stairs[i + 1] - stairs[i] == 0 and stairs[i] - stairs[i-1] > 0:
        stairs[i] -= 1

del stairs[-1:]
new_stairs = sorted(stairs)
if new_stairs == stairs:
    print("Yes")
else:
    print("No")

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

Solution (Python):

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

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

for i in range(n-1):
  d=H[i+1]-H[i]
  if d<-1:
    print("No")
    break
  if d==-1:
    H[i+1]+=1
  if i==n-2 and d>-2:
    print("Yes")

Solution (Python):
N = int(input())
a = input()
list1 = list(map(int,a.split()))
cout = 0
for i in range(0,N-1):
    
    if list1[i] > list1[i+1]+1:
        print("No")
        exit()
    elif list1[i] == list1[i+1]:
        cout += 1
    elif list1[i] == list1[i+1]+1:
        if cout >= 1: 
            for j in range(i-cout,i+1):
                list1[j] = list1[j] -1
            cout = 0
        else:
            list1[i] = list1[i] -1
    else:
        cout = 0


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

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

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

Solution (Python):
n = int(input())
hs = input().split()

h = []
for s in hs:
    h.append(int(s))

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

print("Yes")

Solution (Python):



from collections import deque

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

for i in range(N):
    tmp = H.popleft()
    if H == deque([]):
        print("Yes")
        exit()
    else:
        if tmp - 1 > H[0]:
            print("No")
            exit()
        elif max_num - 1 > tmp:
            print("No")
            exit()
        elif tmp > H[0]:
            if len(H) == 1:
                print("Yes")
                exit()
            elif H[0] > H[1]:
                print("No")
                exit()
        if max_num < tmp:
            max_num = tmp

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

ans = "Yes"

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

if n == 2:
        if h[0] - h[1] >= 2:
                print("No")
                exit()
        else:
                print("Yes")
                exit()

sh = set(h)
if len(sh) == 2:
        big = max(sh)
        small = min(sh)
        if big - small >= 2:
                print("No")
                exit()
        else:
                print("Yes")
                exit()
tmp = 0
for i in range(1, n):
        if h[i-1] - h[i] >= 2:
                ans = "No"
                break
        else:
                if h[i-1] > h[i]:
                        if h[i] >= tmp:
                                tmp = h[i]
                        else:
                                print("No")
                                exit()





print(ans)

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

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

Solution (Python):
import sys

n = int(input())
h = [int(i) for i in input().split()]
for k in range(n):
    if k == n-1:
        break
    if h[k+1] > h[k]:
        h[k+1] -= 1
    elif h[k+1] < h[k]:
        print('No')
        sys.exit()
    if k+1 == n-1:
        break
print('Yes')

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

Solution (Python):
N=int(input())
Hi=[int(x) for x in input().split()]
Hi.reverse()
ans='No'
for i in range(N-1):
  if Hi[i+1]-Hi[i]>=2:
    break
  elif Hi[i+1]-Hi[i]==1:
    Hi[i+1]-=1
    if Hi[i+1]<=0:
      break
else:
  ans='Yes'
print(ans)

Solution (Python):
a=[]
b=int(input())
for x in input().split(" "):
    a.append(int(x))

i=0
x=0
xx=0

while i<b:
    x=a[i]
    if i>=1 and xx-x>1:
        break
    elif i>=1 and xx-x==1:
        a[i]+=1
    x=a[i]
    xx=x
    i+=1
if i==b:
    print("Yes")
else:
    print("No")

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

l_a = a[0]-1
r_a = a[-1]
for i in range(len(a)-1):
    if l_a > a[i+1]:
        print("No")
        exit()
    elif l_a != a[i+1]:
        l_a = a[i+1]-1

    if l_a > r_a:
        print("No")
        exit()
else:
    print("Yes")

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

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

    if maxValue < H[i]:
        maxValue = H[i]

    if maxValue > H[i + 1]:
        isCheck = False
        break

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

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

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

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

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

i = 0
flag = 0

if(n > 2):
    for i in range(1,n-1):
        
        if(h[i] > h[i+1] + 1):
            flag = 1
            break
        elif(h[i] == h[i+1]+1):
            if(h[i-1] == h[i]):
                flag = 1
                break
            else:
                h[i] -= 1
        elif(h[i-1] != h[i]):
            h[i] -= 1
    
    if(h[-2] > h[-1]):
        flag = 1   
elif(n == 2):
    if(h[0]-1 > h[1]):
        flag = 1


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

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

    if len(array) == 1:
        return 'Yes'
    else:
        for i in reversed(range(1,n)):
            dif = array[i] - array[i - 1]
            if dif == -1:
                array[i-1] = array[i-1] - 1
            elif dif < -1:
                return 'No'
        return 'Yes'

print(main())

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

hantei = True
max = H[0]
for i in range(N-1):
    if H[i] >= H[i+1]:
        H[i] -= 1
    if max < H[i]:
        max = H[i]
    if max > H[i+1]:
        hantei = False
        break

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

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

cnt1 = 0
cnt2 = 0
cnt3 = 0

for i in range(n-1):
  if h[i] > h[i + 1] + 1:
    cnt1 += 1
    break
  elif h[i] == h[i + 1] + 1 and (cnt2 > 0 or cnt3 > 0):
    cnt1 += 1
    break
  elif h[i] == h[i + 1] and cnt2 > 0:
    cnt3 = 1
  elif h[i] == h[i + 1] + 1:
    cnt2 = 1
  else:
    cnt2 = 0
    cnt3 = 0

if cnt1 >0:
  print("No")
else:
  print("Yes")

Solution (Python):
N = int(raw_input())
A = map(int, raw_input().split())

def solve(N, A):
    if N == 1: return True
    x = A.pop()
    heads = [x, x-1]
    while A:
        x = A.pop()
        possible = []
        for y in (x, x-1):
            if any(y <= z for z in heads):
                possible.append(y)
        heads = possible
        if not heads: return False
    return bool(heads)

print 'Yes' if solve(N, A) else 'No'

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

for i in range(N-1):
  if H[i+1] == H[i] + 1:
    H[i+1] -= 1
  elif H[i+1] > H[i] + 1:
      F = False

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

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

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

Solution (Python):


n = int(input())
h_sigma = [int(x) for x in input().split()]


is_decrement = False
for i in range(0, n - 1):
    if h_sigma[i] - h_sigma[i + 1] > 1:
        print('No')
        break
    elif h_sigma[i] - h_sigma[i + 1] == 1:
        if is_decrement:
            print('No')
            break
        is_decrement = True
    elif h_sigma[i] - h_sigma[i + 1] == 0:
        pass
    else:
        is_decrement = False
else:
    print('Yes')

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

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

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

Solution (Python):
import sys

N = int(input())
H = list(map(int,input().split()))
for i in reversed(range(N)):
	if i != 0:
		
		
		gap = H[i-1] - H[i]
		
		if gap <= 0:
			continue
		elif gap == 1:
			H[i-1] -= 1
		else:
			print('No')
			sys.exit()
	else:
		pass
print('Yes')

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

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

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

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

tmp = -1

for a in A:
    if a > tmp:
        tmp = a - 1
    elif a == tmp:
        pass
    else:
        print("No")
        exit()

print("Yes")

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

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

Solution (Python):
import sys



def mk_next(pre, value):
	pre_v=pre[0]
	pre_p=pre[1]
	
	if value > pre_v:
		return (value, 'a')
	elif value == pre_v:
		return pre
	elif value +1 == pre_v and pre_p == 'a':
			return (value, 'u')
	else:
		return 'x'
			
def main():
	n = int(input())
	l = list(map(int, input().split()))
	st=(l[0], 'a')
	for v in l[1:]:
		st = mk_next(st, v)
		if st =='x':
			print('No')
			return 
	print('Yes')
	


if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
	else:
		input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Solution (Python):
n=int(input())
h=list(map(int,input().split()))
ch=1
mx=h[0]

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

Solution (Python):
N = int(input())
H = [int(s) for s in input().split()]
if N == 1:
  print('Yes')
else:
  Hc = H.copy()
  Hc[0] = Hc[0]-1
  flg = 'Yes'
  for i in range(N-1):
    if Hc[i+1] - Hc[i] >= 1:
      Hc[i+1] = Hc[i+1] - 1
    elif Hc[i+1] - Hc[i] < 0:
      flg = 'No'
  print(flg)

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

flag = 0
for i in range(N-1):
    if H[N-i-2]-H[N-i-1]>1:
        flag = 1
        break;
    elif H[N-i-2]-H[N-i-1]==1:
        H[N-i-2] = H[N-i-2] - 1


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

Solution (Python):
n = int(input())
h = list(map(int, input().split()))
h = [0] + h

is_able = True
for i in range(n):
  if h[i] < h[i+1]:
    h[i+1] -= 1
  elif h[i] == h[i+1]:
    pass
  else:
    is_able = False
    break

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

Solution (Python):
yn = lambda b: print('Yes') if b else print('No')

import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  
  sys.stderr.write(_s+"\n")


N = int(input())						

if N==1:
	yn(True)
	exit(0)

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

b=False
B=[0]*(N)
for i in range(N-1):
	a = A[i+1]-A[i]
	B[i+1]=a
	
	if a<=-2:
		yn(False)
		exit(0)
	
	
	if a==-1:
		if b:
			yn(False)
			exit(0)
		else:
			b=True
	
	if a>=1:
		b=False

p("A ",A)
p("B ",B)

yn(True)

Solution (Python):
N = int(input())
H_list = list(map(int,input().split()))
max_h = 0
flag = True
for i in H_list:
  if(i >= max_h):
    max_h = i
  elif(max_h-1 >i):
    print("No")
    flag = False
    break
if flag:
  print ("Yes")

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