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())
lst = [0] + list(map(int, input().split()))
reach = False
for i in range(n):
  if reach:
    if lst[i + 1] - lst[i] <= -1:
      print('No')
      exit()
    elif lst[i + 1] - lst[i] >= 1:
      reach = False
  else:
    if lst[i + 1] - lst[i] == -1:
      reach = True
    elif lst[i + 1] - lst[i] <= -2:
      print('No')
      exit()
print('Yes')

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

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

if __name__ == '__main__':
    main()

Solution (Python):
N=int(input())
H=list(map(int,input().split()))
hlow=[H[i]-1 for i in range(N)]
a=[hlow[0]]
flag=True
for i in range(1,N):
    if a[i-1]<=hlow[i]:
        a.append(hlow[i])
    elif a[i-1]<=H[i]:
        a.append(H[i])
    else:
        print('No')
        flag=False
        break

if flag:
    print('Yes')

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
inf = 10**17
mod = 10**9+7

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

flag = True
for i in reversed(range(1,n)):
    if h[i-1] <= h[i]: continue
    if h[i-1]-1 <= h[i]: 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()))

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

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

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

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


minh = 10**9
for i in reversed(h):
    if i >= minh + 2:
        print('No')
        exit()
    minh = min(minh, i)
print('Yes')

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

MAX = 0
Flag = True
for T in range(0,N):
    if H[T]>MAX:
        MAX = H[T]
    if MAX-H[T]>=2:
        Flag = False
        break
if Flag:
    print('Yes')
else:
    print('No')

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

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

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

li.reverse()

ope=0
flg=0

for i in range(1,n):
    chk = li[i]-li[i-1]
    if chk>1:
        print('No')
        flg = 1
        break
    elif chk==1:
        li[i]-=1
    else:
        continue

if flg==0:
    print('Yes')

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

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

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

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

h[0] -=1

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

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


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

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

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

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

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

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

Solution (Python):

n = int(input())

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

height = h[0]

q = 0

for i in h:
    if i < height:
        q = 1
        break
    elif i > height:
        height = i-1
    else:
        height = i
        
if q == 1:
    print("No")
else:
    print("Yes")

Solution (Python):


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

def judge():
    cur = lst[0]
    for i in range(1, N):
        if lst[i] < cur - 1:
            return False
        if lst[i] > cur:
            cur = lst[i]
    return True

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

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

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

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

print(ans)

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

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] :
        H[i-1] -= 1
if sorted(H) != H:
    print('No')
else:
    print('Yes')

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

for i in range(N-1):
    if lis[i] < lis[i+1]:
        lis[i+1] -= 1
    elif lis[i] == lis[i+1]:
        continue
    else:
        print("No")
        exit()

print("Yes")

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *H = map(int, read().split())
    H[0] -= 1
    for i in range(1, N):
        if H[i] < H[i - 1]:
            print('No')
            return
        if H[i] > H[i - 1]:
            H[i] -= 1

    print('Yes')
    return


if __name__ == '__main__':
    main()

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

    return
resolve()

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

Solution (Python):
n,*l=map(int,open(0).read().split())
t=s=0
for i in l:
  if i<t: s=1
  if i>t: t=i-1
print('YNeos'[s::2])

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

Solution (Python):
n,*l=map(int,open(0).read().split())
t=0
for i in l:
  if i<t: print('No'); break
  if i>t: i-=1
  t=i
else: print('Yes')

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

prev = H[0]
flag = True
for i in range(N-1):
    now = H[-i-1]
    after = H[-i-2]
    if after - now > 1:
        flag = False
        break
    elif after - now == 1:
        H[-i-2] -= 1
    else:
        pass
print('Yes') if flag else print('No')

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

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

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

Solution (Python):



from fractions import gcd
from itertools import combinations,permutations,accumulate 

from collections import deque,defaultdict,Counter











import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = readInts()
ma = A[0]
for i in range(1,n):
    if ma < A[i]:
        A[i] -= 1
    if ma <= A[i]:
        ma = A[i]
    else:
        print('No')
        exit()
print('Yes')

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

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

Solution (Python):
from copy import deepcopy
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal
import sys
import fractions
from operator import itemgetter
import itertools
import copy


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


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



dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

n = int(input())
h = readints()
for i in range(n-1):
    if h[i] < h[i+1]:
        h[i+1] = h[i+1]-1

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

Solution (Python):
n = int(input())
h = list(map(int, input().split()))[::-1]
ans = "Yes"
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:
        ans = "No"
        break
print(ans)

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

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

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

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

print("Yes")

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

Solution (Python):






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





flag = True
mylist = list(reversed(H))
for i in range(1,N):
    if mylist[i] > mylist [i-1] + 1:
        flag = False
        break
    elif mylist[i] == mylist[i-1] + 1:
        mylist[i] = mylist[i]-1
if flag:
    print("Yes")
else:
    print("No")

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

print('Yes')

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

count = 0
for i in H:
        if i+2 <= count:
            print('No')
            exit()
        else:
            count = max(i,count)
print('Yes')

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


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

print("Yes")

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


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


flag="Yes"

for i in range(n-2,-1,-1):
    righth=hl[i+1]
    cur=hl[i]
    if cur<=righth:
        pass
    elif cur==righth+1:
        hl[i]=cur-1
    else:
        flag="No"
        break

print(flag)

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

max_h=0
ans='Yes'

for n in range(N):
    if H[n] > max_h:
        max_h = H[n]
        
    if H[n] < max_h-1:
        ans='No'
        
print(ans)

Solution (Python):
n = int(input())
h = list(map(int, input().split()))
f = True
for i in range(n-1):
    if h[n-2-i] - 1 == h[n-1-i]:
        h[n-2-i] -= 1
    elif h[n-2-i] > h[n-1-i]:
        f = False
        break;

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

Solution (Python):
N = int(input())
h = list(map(int, input().split()))
ans = True
MIN = h[0]-1

for i in range(N-1):
    MIN = max(MIN, h[i]-1)
    if h[i] > h[i+1]:
        if h[i]-h[i+1] > 1:
            ans = False
            break
        else:
            if MIN > h[i+1]:
                ans = False
                break

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

Solution (Python):
N=int(input())
H=list(map(int,input().split()))
ans=0
for i in H:
  if ans>i:
    print('No')
    exit()
  ans=max(ans,i-1)

print('Yes')

Solution (Python):
N=int(input())
H=list(map(int,input().split()))
ans=0
for i in H:
    if ans>i:
        print('No')
        exit()
    ans=max(ans,i-1)
else:
    print('Yes')

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

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

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

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

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

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

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

Solution (Python):

N = int(input())
H = list( map(int, input().split()) )
if N == 1:
    print('Yes')
else:
    for n in range(N-1):
        if H[n+1] - H[n] < 0:
            print('No')
            break
        else:
            if H[n] < H[n+1]:
                H[n+1] -= 1
    else:
      print('Yes')

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

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

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

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

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

  if s[i] <= s[i+1] - 1:
    s[i+1] = s[i+1] - 1

print('Yes')

Solution (Python):
import math

n = int(input())
li = list(map(int, input().split(" ")))

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

print("Yes")

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

for i in range(N-1):
    if H_max < H[i]:
        H_max = H[i]
    if H[i+1] < H_max - 1:
        print("No")
        break
else:
    print("Yes")

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

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

Solution (Python):

def solve(a):
    for i in range(len(a)-1):
        if a[i+1] - a[i] <= -2:
            return "No"
        elif a[i+1] - a[i] == -1:
            a[i+1] += 1
    return "Yes"

def main():
    N = int(input())
    A = [0] + list(map(int,input().split()))
    print(solve(A))

if __name__ == '__main__':
    main()

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

Solution (Python):
n = int(input())
h = [int(i) for i in input().split()]
h.reverse()
next = h[0]
import sys
for i in h[1:]:
    if i - next > 1:
        print('No')
        sys.exit()
    elif i - next == 1:
        next = i - 1
    else:
        next = i
print('Yes')

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

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

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

m=0
flag=True
for i in range(n):
    if h[i]+2<=m:
        flag=False
    m=max(h[i],m)
if flag:
    print("Yes")
else:
    print("No")

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

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

print(ans)

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

for i in range(1, N-1):
    if h[i+1] - h[i] == -1:
        if h[i] == h[i-1]:
            print('No')
            sys.exit()
        else:
            h[i] -= 1
    elif h[i+1] - h[i] > -1:
        if h[i-1] != h[i]:
            h[i] -= 1
    else:
        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-1):
    if h[i] == h[i+1] + 1:
        if h[i-1] != h[i]:
            h[i] -= 1
        else:
            print('No')
            exit()
    elif h[i] < h[i+1] + 1:
        if h[i-1] != h[i]:
            h[i] -= 1
    else:
        print('No')
        exit()
print('Yes')

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

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

mx=0
for i in range(n):
    if h[i]<=mx-2:
        print("No")
        sys.exit()
    if h[i]>mx:
        mx=h[i]

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

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

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

print('Yes')

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

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

Solution (Python):
import sys

N = int(input())
H = list(map(int,input().split()))
n = len(H)
ans = "Yes"
if n == 1 :
    ans = "Yes"

for i in reversed(range(n-1)) :
    if H[i] <= H[i+1] :
        pass
    elif H[i] - H[i+1] == 1 :
        H[i] = H[i] - 1
    else : ans = "No"

print(ans)

Solution (Python):
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: map(str, sys.stdin.buffer.readline().split())
ri = lambda: int(sys.stdin.buffer.readline())
rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.buffer.readline().split()))

n = ri()
h = rl()
temp = 0
for i in h:
    if temp == i:
        continue
    elif temp < i:
        temp = i-1
        continue
    else:
        print('No')
        exit()
else:
    print('Yes')

Solution (Python):
n = int(input())
h = list(map(int, input().split()))
x = h[-1]
ans = "Yes"
for i in reversed(range(n - 1)):
    hi = h[i]
    if hi <= x:
        pass
    else:
        if abs(x - hi) >= 2:
            ans = "No"
        else:
            h[i] -= 1
    x = h[i]
print(ans)

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

for n in range(N):
  if maxim < H[n]:
    maxim = H[n]
  if H[n] < maxim -1:
      flag = False
if flag:
  print("Yes")
else:
  print("No")

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


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

for i in range(N-1):
    if H[i+1] < H[i]:
        print('No')
        break
else:
    print('Yes')

Solution (Python):

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

print('Yes')

Solution (Python):
import sys
def main():
    N = int(input())
    H = list(map(int, input().split()))
    if N == 1:
        print('Yes')
        sys.exit()
    H_edit = [0]*N
    H_edit[0] = H[0] - 1
    for i in range(1, N):
        h_prev = H_edit[i-1]
        h = H[i]
        H_edit[i] = h-1 if h_prev+1 <= h else h
    for i in range(N-1):
        if H_edit[i] > H_edit[i+1]:
            print('No')
            break
    else:
        print('Yes')
main()

Solution (Python):
N=int(input())
S=list(map(int,input().split()))
Z=[0]*N
start=S[0]
for i in range(1,N):
    Z[i]=S[i]-start
    if S[i]>start:
        start=S[i]


flug=False
for i in range(N):
    
    if  Z[i]<=-2:
        print("No")
        exit()
        

print("Yes")

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

Solution (Python):
import sys
sys.setrecursionlimit(10**6)

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

fixed = [False]*n

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

Solution (Python):
import sys

input = lambda: sys.stdin.readline().rstrip()


def solve():

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

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

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

    ans = 'Yes'
    for i in range(N - 1):
        if H[i] <= H[i + 1]:
            continue
        else:
            ans = 'No'
            break

    
    print(ans)


if __name__ == '__main__':
    solve()

Solution (Python):
import sys

input = lambda: sys.stdin.readline().rstrip()


def solve():

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

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

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

    ans = 'Yes'
    for i in range(N - 1):
        if H[i] <= H[i + 1]:
            continue
        else:
            ans = 'No'
            break

    
    print(ans)


if __name__ == '__main__':
    solve()

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

ans = "Yes"
for i in range(n - 1, 0, -1):
    if H[i] - H[i - 1] == 2:
        H[i] -= 1
    elif H[i - 1] - H[i] == 1:
        H[i - 1] -= 1
for i in range(1, n):
    if not(0 <= H[i] - H[i - 1]):
        ans = "No"

print(ans)

Solution (Python):
from collections import deque
from sys import exit
N = int(input())
H = deque(map(int, input().split()))
tmp = H.pop()
while H:
  nxt = H.pop()
  if nxt >= tmp + 2:
    print("No")
    exit()
  elif nxt == tmp + 1:
    nxt -= 1
  tmp = nxt
print("Yes")

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
  
  if A[i] - A[i-1] < 0:
    print("No")
    exit()

print("Yes")

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

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

Solution (Python):
import sys
n = int(input())
ls = list(map(int,input().split()))
mx = -float("inf")
for i in ls:
    if i < mx:
        if i + 1 != mx:
            print("No")
            sys.exit()
        else:
            mx = i + 1
    else:
        mx = i
print("Yes")

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

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

if __name__ == "__main__":
    main()

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

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
f="Yes"
stair=l[0]
mi=0
for i in range(1,n):
    if mi==0:
        if stair-1==l[i]:
            stair=l[i]
            mi=1
        elif  stair<=l[i]:
            stair=l[i]
        else:
            f="No"
            break
    else:
        if stair==l[i]:
            stair=l[i]
            mi=1
        elif stair<l[i]:
            stair=l[i]
            mi=0
        else:
            f="No"
            break
print(f)

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

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

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

tmp = lis[0]
for i in range(1,n):
    if tmp < lis[i]:
        tmp = lis[i] -1
    elif tmp == lis[i]:
        tmp = lis[i]
    else:
        print("No")
        exit()

print("Yes")

Solution (Python):
N = int(input())
H = list(map(int, input().split(' ')))
res = 'Yes'
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]:
    res = 'No' 
print(res)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, *h = map(int, read().split())
if len(h) == 1:
    print('Yes')
    exit()

h = h[::-1]

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

print('Yes')

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

H[0] -= 1

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

    H[i] = max(H[i-1], H[i] - 1)

print('Yes')

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

Solution (Python):
n = int(input())
h = list( map(int,input().split()) )
 
ck = True
for i in range(n-2,-1,-1):
  if h[i] > h[i+1]:
    h[i] -= 1
    if h[i] > h[i+1]:
        ck = False
        break

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