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")
elif n == 2:
    if h[0] - h[1] <= 1:
        print("Yes")
    else:
        print("No")
else:
    c = 0
    if h[0] - h[1] <= 1:
        h[0] -= 1
        for i in range(1, n-1):
            if h[i] - h[i+1] == 1 and h[i-1] < h[i]:
                h[i] -= 1
                c += 1
            elif h[i] <= h[i+1] and h[i-1] < h[i]:
                h[i] -= 1
                c += 1
            elif h[i] <= h[i+1]:
                c += 1
            else:
                break   
    if c == n-2:
        print("Yes")
    else:
        print("No")

Solution (Python):
'''
Created on 2020/08/23

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  N=int(pin())
  H=list(map(int,pin().split()))
  H.reverse()
  for i in range(N-1):
    if H[i]>=H[i+1]:
      pass
    elif H[i]==H[i+1]-1:
      H[i+1]-=1
    else:
      print("No")
      break
  else:
    print("Yes")
  return 

main()

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

Solution (Python):

import sys
input=sys.stdin.readline

def main():
    numbers=[]
    n = int(input())
    numbers=list(map(int,input().split()))
    prev=0


    for i in numbers:
        if i==0:
            prev=i
        else:
            if prev<=i:
                prev=i
            elif prev <=i+1:
                prev=i+1
            else:
                print("No")
                exit()
    print("Yes")

if __name__=="__main__":
    main()

Solution (Python):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = list(map(int, input().split()))
m = 0
for i in range(n):
    if a[i]<m:
        print("No")
        break
    m = max(m, a[i]-1)
else:
    print("Yes")

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

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

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

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

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

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

for h in H:
    if h > now:
        now = h - 1
    elif h == now:
        continue
    else:
        print('No')
        exit()
print('Yes')

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

Solution (Python):
N = int(input())
H = tuple(reversed(tuple(map(int, input().split()))))
assert len(H) == N

result = True
prev = None
for i,h in enumerate(H):
  if prev is not None:
    if h > prev + 1:
      result = False
      break
    if h < prev + 1:
      prev = h
  else:
    prev = h
print('Yes' if result else 'No')

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

for i in reversed(range(1,N)):
    if H[i - 1] - 1 == H[i]:
        H[i - 1] -= 1
    elif H[i - 1] - 1 > H[i]:
        can = False
        break

print(['No', 'Yes'][can])

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

s = H[0]
t = 0
for i in range(1, N):
    if s <= H[i]:
        s = max(s, H[i] - 1)
    else:
        t = 1
        break

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

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

is_mono_inc = True
now = min(H) 
for i in range(N):
    if now <= H[i]:
        now = H[i]
    elif now > H[i] and now <= H[i]+1:
        now = H[i]+1
    else:
        is_mono_inc = False

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

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


print('Yes')

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

print('Yes')

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

Solution (Python):
n = int(input())
h = list(map(int, input().split()))
ans = 'Yes'
if n != 1: 
    i = 0
    b = 0
    while i < n:
        if h[i] < b:
            ans = 'No'
            break
        b = max(b, h[i]-1)
        i += 1
print(ans)

Solution (Python):



def main():
    _ = int(input())
    tmp = 1
    ans = 'Yes'
    H = list(map(int, input().split()))

    for h in H:
        if tmp < h:
            tmp = h - 1
        elif tmp > h:
            ans = 'No'
            break

    print(ans)

if __name__ == "__main__":
    main()

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

ans = 'Yes'
m = H[0]

if n == 1:
    ans
else:
    for i in range(1, n):       
        if H[i] >= m-1:
            m = max(H[i], m)
            continue
        else:
            ans = 'No'
            break
print(ans)

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

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

    h0 = h[0] - 1
    ans = 'Yes'
    for i in range(1, N):
        if h0 < h[i]:
            h0 = h[i] - 1
            
            
            
            
            
            
        elif h0 > h[i]:
            ans = 'No'
            break

    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
import sys

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


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

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

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

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

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

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

Solution (Python):
n = int(input())
hlst = list(map(int, input().split()))
bef = 0
for h in hlst:
  if h < bef:
    print("No")
    break
  elif h == bef:
    bef = h
  else:
    bef = h - 1
else:
  print("Yes")

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

sbn = 0
maxim = 0
for i in range(1,N):
    if maxim < H[i-1]:
        maxim = H[i-1]
    if H[i-1] > H[i]:
        sbn = maxim - H[i]
    if abs(sbn) > 1:
        print("No")
        exit(0)

print("Yes")

Solution (Python):
n = int(input())
L = list(map(int,input().split()))
ans = 'Yes'
pre = -999

for i in range(n):
  if pre <= L[i] - 1:
    pre = L[i] - 1
  elif pre <= L[i]:
    pre = L[i]
  else:
    print('No')
    exit()
print('Yes')

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

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

Solution (Python):
N = int(input())
H = list(map(int, input().split()))
border = H[N-1]

ans = True
for i in range(N-2, -1, -1):
    if H[i] <= border:
        border = H[i]
    else:
        if H[i] - 1 <= border:
            border = H[i] - 1
        else:
            ans = False

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

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

flag = 1
H[0] = H[0] - 1

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

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

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

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

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

Solution (Python):
def abc136c():
    n = int(input())
    h = list(map(int, input().split()))
    v = 0
    for i in range(n):
        if v > h[i]:
            print('No')
            return
        v = max(v, h[i]-1)
    print('Yes')
abc136c()

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

a = 0
for i in H:
    if a <= i:
        a = i
    elif a-i >= 2:
        print('No')
        exit()
print('Yes')

Solution (Python):
def main():
    n = int(input())
    h = list(map(int, input().split()))
    flag = True
    for i in range(n-1):
        if h[i+1] - h[i] == 0:
            continue
        elif h[i+1] - h[i] >= 1:
            h[i+1] = h[i+1] - 1
        else:
            flag = False 
    if flag:
        print('Yes')
    else:
        print('No')
            
if __name__ == '__main__':
    main()

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

h = [hf[0]]
for i in range(1, nf):
    if hf[i] == hf[i - 1]:
        continue
    else:
        h.append(hf[i])
n = len(h)

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

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

maxh = 10 ** 10
for i in range(len(H) - 1, -1, -1):
  if H[i] > maxh + 1:
    print("No")
    break
  if H[i] == maxh + 1:
    maxh = H[i] - 1
  else:
    maxh = H[i]
else:
  print("Yes")

Solution (Python):
import sys









MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_ints2(x):   return map(lambda num: int(num) - x, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def GCD(a: int, b: int) -> int: return b if a%b==0 else GCD(b, a%b)
def LCM(a: int, b: int) -> int: return (a * b) // GCD(a, b)

def Main():
    n = read_int()
    h = read_int_list()
    maxh = 0
    cur = 0
    for i in h:
        if maxh < cur:
            maxh = cur
        cur = i
        if maxh >= i + 2:
            print('No')
            break
    else:
        print('Yes')

if __name__ == '__main__':
    Main()

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

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

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

ans = 'Yes'
tmp_max = H[-1]

for h in reversed(H[:-1]):
    if h <= tmp_max:
        tmp_max = h
    elif h-1 <= tmp_max:
        tmp_max = h-1
    else:
        ans = 'No'

print(ans)

Solution (Python):
N = int(input())
H = list(map(int,input().split()))
flg = 0
ans = "Yes"

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

print(ans)

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

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

a = True

for x in reversed(range(1,n)):
  if high[x-1] >= high[x] + 2:
    a = False
    break
  elif high[x-1] == high[x] + 1:
    high[x-1] = high[x]
    
if a:
  print("Yes")
else:
  print("No")

Solution (Python):
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n = I()
    h = LI()
    mx = h[0]

    for x in h[1:]:
        if mx-1 <= x:
            pass
            mx = max(mx, x)
        else:
            print("No")
            break
    else:
        print("Yes")
main()

Solution (Python):
n = int(input())
lst = list(map(int,input().split()))
ans = 0
for i in range(n - 1):
    if (lst[i] > lst[i + 1]):
        lst[i + 1] = lst[i + 1] + 1
    if (lst[i] > lst[i + 1]):
        ans = 1

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

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

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

print("Yes")

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

for i in range(1,n-1):
    if H[n-1-i] == H[n-i] + 1:
        H[n-1-i] -= 1
    elif not(H[n-1-i] == H[n-i] or H[n-1-i] < H[n-i]):
        print('No')
        exit()
print('Yes')

Solution (Python):
def main():
    N = int(input())
    H = list(map(int, input().split()))[::-1]
    for i in range(1, N):
        if H[i] - H[i-1] >= 2:
            print('No')
            exit()
        elif H[i] - H[i-1] == 1:
            H[i] -= 1
    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] >= h[i-1]: continue
    if h[i] <= h[i-1] - 2: print('No'); break
    h[i] += 1
else: print('Yes')

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



ans = 'Yes'
for i in range(N-1, 0, -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())
A = list(map(int,input().split()))
 


ans = 'Yes'
for i in range(N-1, 0, -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()))
H[0] -= 1
for i in range(1, N):
    if H[i] - H[i - 1] > 0:
        H[i] -= 1

pre = 0
flg = True
for h in H:
    if h < pre:
        flg = False
        break
    pre = h
print('Yes' if flg else 'No')

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

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

Solution (Python):

"""
Created on Thu Sep 10 00:58:18 2020

@author: liang
"""

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

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

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

for i in range(n-1):
  a = h[i+1] - h[i] 
  if a < 0:
    print('No')
    exit()
  if a >= 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):
  if h[i]<h[i+1]:
    h[i+1]-=1
  if h[i]>h[i+1]:
    ans="No"
    break
  
print(ans)

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

Solution (Python):
n = int(input())
A = list(map(int, input().split( )))
cnt = 0
for i in range(n-1):
  if A[i] < A[i+1]:
    A[i+1] -= 1
  cnt += max(A[i] - A[i+1],0)
  if cnt >= 1:
    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-1] < h[i]:
        h[i] -= 1
l = list(h)
l.sort()
if h == l:
    print('Yes')
else:
    print('No')

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


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

  if l[i]>l[i+1]:
    d=False
    
if d:
  print("Yes")
else:
  print("No")

Solution (Python):
def solve():
    N = int(input())
    H = [int(i) for i in input().split()]
    if N == 1:
        print('Yes')
    elif N == 2:
        print('Yes' if abs(H[0] - H[1]) <= 1 else 'No')
    else:
        for i in range(1, N)[::-1]:
            l = H[i - 1]
            r = H[i]
            if l <= r:
                continue
            elif l - 1 <= r:
                H[i - 1] -= 1
            else:
                print('No')
                exit()
        print('Yes')

if __name__ == "__main__":
    solve()

Solution (Python):
import sys

input = sys.stdin.readline

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

tmp = 0
flag = False

for h in h_list:

    if tmp == 0:
        tmp = h
        continue

    if tmp > h:
        if tmp - 2 >= h:
            print("No")
            exit(0)
        tmp = h
        if flag:
            print("No")
            exit(0)
        else:
            flag = True
    elif tmp < h:
        tmp = h
        flag = False

print("Yes")

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

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

Solution (Python):

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

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

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


if __name__ == '__main__':
    main()

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

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

print(ans)

Solution (Python):
def main():
    n = int(input())
    h_list = list(map(int, input().split()))
    highest = h_list[0]
    is_able = True

    for h in h_list:
        if highest > h:
            is_able = False
            break

        if highest + 1 < h:
            highest = h - 1

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


if __name__ == "__main__":
    main()

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

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

hardle = 0
ans = "Yes"
for i in H:
  if hardle>i:
    ans = "No"
    break
  else:
    if i>hardle:
      hardle=i-1
print(ans)

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

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

pre = a[0]
ok = True
for i in range(n):
    if pre > a[i]:
        ok = False
        break
    if a[i] > pre:
        a[i] -= 1

    pre = a[i]

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

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

for n in range(N):
  if D>H[n]:
    print("No")
    exit()
  elif D<=H[n]-1:
    H[n]-=1
    D=H[n]

print("Yes")

Solution (Python):
N = int(input())
Hlist = list(map(int,input().split()))
sign = 1
Answer = 'Yes'
for i in range(len(Hlist)-1):
    H1 = Hlist[i]
    H2 = Hlist[i+1]
    if H1 > H2:
        if H1 - H2 == 1 and sign == 1:
            Hlist[i] -= 1
            sign =0
        else:
            Answer = 'No'
            break
    if H1 < H2:
        sign = 1
print(Answer)

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

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

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

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

print('Yes')

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

Solution (Python):
N = int(input())
HB = input().split(' ')
HB = [int(HB[i]) for i in range(N)]
Hs = [0]
for i in range(N):
  H = HB[i]
  if Hs[i] > H:
    print('No')
    break
  else:
   if Hs[i] == H:
     Hs.append(H)
   else:
     H = H - 1
     Hs.append(H)
else:
  print('Yes')

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

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

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
first = 0
for i in range(N):
    first = max(first,A[i])
    if A[i] < first-1:
        print("No")
        exit()

print("Yes")

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

Solution (Python):
import sys, bisect, math, itertools, string, queue, copy







mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
hl = inpl()
pre = 0
ans = 'Yes'
for i in range(0, n):
    if(hl[i] < pre):
        ans = 'No'
        break
    if(hl[i] > pre):
        pre = hl[i]-1
    else:
        pre = hl[i]
print(ans)

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

while True:
    if N == 1:
        answer = 'Yes'
        break
    if H[i]<H[i+1]:
        H[i+1] -= 1
    if H[i]>H[i+1]:
        answer = 'No'
        break
    i += 1
    if i == N-1:
        answer = 'Yes'
        break
print(answer)

Solution (Python):
N,*H=map(int,open(0).read().split())
H[0]-=1
def main():
    for i in range(1,N):
        if H[i-1]<H[i]:
            H[i]-=1
        elif H[i-1]==H[i]:
            continue
        else:
            return 'No'
    return 'Yes'
print(main())

Solution (Python):
N,*H=map(int,open(0).read().split())
H[0]-=1
def main():
    ihmax=0
    hmax=H[0]
    for i in range(1,N):
        if H[i-1]<H[i]:
            ihmax=i-1
            H[i]-=1
            hmax=max(H[i],hmax)
        elif H[i-1]==H[i]:
            continue
        else:
            return 'No'
    return 'Yes'
print(main())

Solution (Python):
N=int(input())
H=list(map(int,input().split()))
min = 1e12
success = True
for i in range(N):
    if H[N-1-i] <= min + 1:
        if H[N-1-i] < min:
            min = H[N-1-i]
    else:
        success = False
        break
print('Yes' if success else 'No')

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

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

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

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

Solution (Python):
N = int(input())
H = list(map(int, input().split()))
H.reverse()
f = 0
h = H[0]
for i in range(1, N):
  if H[i] >= h + 2:
    print("No")
    f = 1
    break
  else:
    h = min(h, H[i])
if f == 0:
  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()
    if H[i-1] - H[i] == 1:
        H[i-1] -= 1

for i in range(N-1):
    if H[i] > H[i+1]:
        print("No1")
        exit()
        
print("Yes")

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

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

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

m = 0
f = 0
for h in H:
    m = max(m, h)
    if m > h+1:
        print('No')
        f = 1
        break
if not f:
    print('Yes')

Solution (Python):








def solve(N, Hs):
    Hs.reverse()
    ans = 'Yes'
    for i in range(N - 1):
        if Hs[i] < Hs[i + 1]:
            if abs(Hs[i] - Hs[i + 1]) == 1:
                Hs[i + 1] -= 1
            else:
                ans = 'No'
                break
    print(ans)


if __name__ == '__main__':
    
    N = int(input())
    
    Hs = [int(i) for i in input().split()]
    
    solve(N, Hs)

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

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

Solution (Python):


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

enable_non_decrease = True

for i in range(N-1):
    j = N - 1 - i
    if H[j-1] > H[j]:
        H[j-1] -= 1
    if H[j-1] > H[j]:
        enable_non_decrease = False
        break

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

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

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

base = H[0]

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

print("Yes")