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

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

count = 0
flag = True

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

Solution (Python):
N = int(input())
h = [int(i) for i in input().split()]
p = N-1
ans = "Yes"
while p>0:
  if h[p-1]<=h[p]:
    p -= 1
  elif h[p-1]==h[p]+1:
    h[p-1] -= 1
    p -= 1
  else:
    ans = "No"
    break

print(ans)

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

for i in range(N):
	if d<=H[i]:
		d=H[i]
	else:
		if d-H[i]>=2:
			c=c+1
if c>=1:
	print('No')
else:
	print('Yes')

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

max = h[0]
flag = True
for i in range(1,n):
    if(max <= h[i]):
        max = h[i]
        continue
    elif (max - 1 > h[i] ):
        flag=False
        break

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

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

if len(H)==1:
	print "Yes"
	quit()

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

Solution (Python):
n=int(input())
g=[int(i) for i in input().split()]
h=[i for i in reversed(g)]
a=h[0]
for i in range(n):
    if a-h[i]>=0:
        a=h[i]
    elif a-h[i]==-1:
        a=h[i]-1
    else:
        a=-10
print("Yes" if a!=-10 else "No")

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

HN=[int(x) for x in map(int,input().split()[:N])]

for i in range(N-1,0,-1):
    if HN[i-1]<=HN[i]:
        continue
    elif (HN[i-1]-1)==HN[i]:
        HN[i-1]-=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):
  if H[i]-1 >= H[i-1]:
    H[i]-=1;
  elif H[i] < H[i-1]:
    print("No")
    break
else:
  print("Yes")

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

Solution (Python):
def main() :

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

    
    H_list.reverse()
    c = 0
    for i in range(len(H_list)-1) :
        d = H_list[i+1] - H_list[i]
        if (d >= 2) :
            
            print("No")
            return

        if (d == 1) :
            
            c += 1
            H_list[i+1] = H_list[i+1] - 1
    
    print("Yes")

main()

Solution (Python):
def li():
    return list(map(int, input().split()))


if __name__ == "__main__":
    n = int(input())
    h_list = li()

    result = True
    state = h_list[0] - 1
    for index in range(1, n):
        if state > h_list[index]:
            result = False
            break
        elif state == h_list[index]:
            pass
        else:
            state = h_list[index] - 1
    if result:
        print("Yes")
    else:
        print("No")

Solution (Python):
import sys

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


if __name__ == '__main__':
  main()

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

Judge = True
MAX = 0

for i in range(N):
    
    if i == 0:
        continue
    else:
        if MAX > H[i]:
            Judge = False
            break

        if H[i-1] > H[i]:
            tmp = H[i-1]-1
            MAX = tmp

            if tmp > H[i]:
                Judge = False
                break

        else:
            continue


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

Solution (Python):
n=int(input())
numlist=[int(i) for i in input().split()]
check=0
if len(numlist)==1:
    print("Yes")
else:

    a=numlist[0]
    b=numlist[1]
    if a-b>1:
        print("No")
    else:
        if a-b==1:
            numlist[0]=numlist[0]-1
        elif b-a>0:
            numlist[1]=numlist[1]-1
        elif b==a:
            numlist[1]=numlist[1]-1
            numlist[0]=numlist[0]-1


        for i in range(1,n-1):
            a=numlist[i]
            b=numlist[i+1]
            if a-b>=1:
                print("No")
                check+=1
                break
            elif b-a>0:
                numlist[i+1]=numlist[i+1]-1
        if check==0:        
            print("Yes")

Solution (Python):
N = int(input())
Hs = [int(i) for i in input().split(" ")]
for i in range(0, N - 1):
  h1 = Hs[i]
  h2 = Hs[i+1]
  if h1 < h2:
     Hs[i+1] -= 1
  elif h1 == h2:
     pass
  else:
     print("No")
     break
else:
  print("Yes")

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

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

    elif i != 0:
        if h[i]==h[i+1] and h[i-1]<=h[i]-1:
            h[i] -= 1


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

print("Yes")

Solution (Python):
n = int(input())
h = list(map(int,input().split()))
s = []
ph = 0
for i in range(n-1):
    if not(h[i+1]==h[i]):
        s.append(h[i+1]-h[i])


mt1 = True
yes = True
for i in range(len(s)):
    if s[i]<-1:
        print("No")
        yes = False
        break
    else:
        if (not mt1) and s[i]<0:
            print("No")
            yes = False
            break
        if s[i]<0:
            mt1 = False
        else:
            mt1 = True
if yes:
    print("Yes")

Solution (Python):
r=input()
h=reversed(list(map(int,input().split())))
g=next(h)
for i in h:
	if i>g+1:break
	elif i==g+1:g=i-1
	else:g=i
else:r=0
print("No"if r else"Yes")

Solution (Python):
n = int(input())
h = list(map(int, input().split()))
ans = True
m = h[0]
for i in range(1, len(h)):
    if h[i] + 1 < m:
        ans = False
    m = max(m, h[i])
if ans:
    print('Yes')
else:
    print('No')

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

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

max_i = num_list[0]
flag = True
for i in num_list:
  if (max_i - i) >= 2:
    print('No')
    flag = False
    break
    
  if i > max_i:
    max_i = i
    
if flag:
  print('Yes')

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

max = 0
result = 'Yes'
tmpmax = 0

for i in HS:
    if max > i:
        max = max - 1
        if max > i:
            result = 'No'
            break
    else:
        max = i
    if (max > tmpmax or tmpmax==0):
        tmpmax = max
    elif (tmpmax > max + 1):
        result = 'No'
        break

print(result)

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

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

l = h[0] - 1
for i in range(1, n):
  r = h[i]
  if l - r  >= 1:
    print("No")
    break
  if not l == r:
    l = r-1
else:
  print("Yes")

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

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

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

Solution (Python):

if __name__ == "__main__":
    N = int(input())
    H = list(map(int,input().split()))
    tmpH = sorted(H)
    for i in range(N):
        if H[i] != tmpH[i] and abs(H[i] - tmpH[i]) > 1:
            print("No")
            exit()
    print("Yes")

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

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

Solution (Python):
import sys

def InputToInt():
    A = input().split()
    for i in range(len(A)):
        A[i] = int(A[i])
    return A
    
if __name__ == '__main__':
    N = int(input())
    H = InputToInt()

    state = 1
    for i in range(N-1):
        if H[i+1] < H[i]-1:
            print('No')
            sys.exit()
        elif H[i+1] > H[i]:
            state = 1
        elif H[i+1] == H[i]-1 and state == -1:
            print('No')
            sys.exit()
        elif H[i+1] == H[i]-1:
            state = -1
        elif H[i+1] == H[i] and state == -1:
            pass
        elif H[i+1] == H[i] and state == 0:
            pass
        elif H[i+1] == H[i] and state == 1:
            state = 0
                    
    print('Yes')

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

max_drawdown = 0
ans = "Yes"
for i in H:
    max_drawdown = min(max_drawdown,i-maxh)
    maxh = max(maxh,i)
if max_drawdown <= -2:
    print("No")
else:
    print("Yes")

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

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

if N == 1:
    ans = "Yes"
else:
    c = 0
    while c <= N-2:
        if H[c] < H[c+1]:
            H[c+1] -= 1
        c += 1
    List = []
    for j in range(N):
        List.append(H[j])
    List.sort()
    if List == H:
        ans = "Yes"
    else:
        ans = "No"

print(ans)

Solution (Python):
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    H = list(map(int, input().split()))
    c = 0
    for h in H:
        if h < c:
            return 'No'
        c = max(c, h-1)

    return 'Yes'


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

Solution (Python):
N = int(input())
H = list(map(int, input().split()))
is_yes = True
for i in range(N-1, 0, -1):
    if H[i-1] <= H[i]:
        continue
    H[i-1] -= 1
    if H[i-1] <= H[i]:
        continue
    is_yes = False
    break

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

Solution (Python):
def inpl(): return list(map(int, input().split()))

N = int(input())
H = inpl()

OK = True
for i in range(N-1):
    if OK:
        H[i] -= 1
    if H[i] > H[i+1]:
        print("No")
        break
    elif H[i] == H[i+1]:
        OK = False
    else:
        OK = True

else:
    print("Yes")

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

def main():
    maxi = 0
    for i in range(N):
        maxi = max(maxi, H[i])
        if maxi - H[i] > 1:
            return False
    return True

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

Solution (Python):
from sys import stdin
import numpy as np
N = int(stdin.readline().rstrip())
data = [int(x) for x in stdin.readline().rstrip().split()]
top = 0
flag = True
for i in data:
    if (top - i) > 1:
        flag = False
    if i > top:
        top = i
if flag:
    print("Yes")
else:
    print("No")

Solution (Python):
N = int(input())
H = list(map(int,input().split()))
answer = "Yes"
danger = False
if N == 1:
    answer = "Yes"
else:
    for i in range(N-1):
        j = N-i-1
        diff = H[j] - H[j-1]
        if diff < -1:
            answer = "No"
            break
        elif diff == -1:
            H[j-1] -= 1
print(answer)

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


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

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

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

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

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

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


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

Solution (Python):
N = int(input())
H = [int(_) for _ in input().split()]
h  = 0
ans = 'No'

for e in H:
    if h > e:
        e += 1
        if h > e:
            break
    h = e
else:
    ans = 'Yes'
print(ans)

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

Solution (Python):
n = int(input())
h = [int(e) for e in input().split(" ")]
flag = True

if n > 2:
    pre = h[0]
    now = h[1]
    
    for e in h[2:]:
        if pre <= now-1 and now-1 <= e:
            pre = now - 1
            now = e
        else:
            if pre <= now and now <= e:
                pre = now
                now = e
            else:
                flag = False
                break

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

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

prev = float('inf')
memo = 0
for elm in L:
    if memo == 0 and elm < prev:
        memo = elm
    else:
        memo = max(elm, memo)
        if elm <= memo - 2:
            print("No")
            break
    
    prev = elm
else:
    print("Yes")

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

judge = True

h[0] -= 1

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

Solution (Python):


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

max = -1
for i in H:
    if i - max < -1:
        print('No')
        exit(0)

    if max <= i:
        max = i

print('Yes')

Solution (Python):
import numpy as np
N = int(input())
H = [int(i) for i in input().split()]
if N == 1:
  print('Yes')
else:
  for i in range(N-1):
    if H[i] < H[i+1]:
      H[i+1] = H[i+1] - 1
  A = np.zeros(N-1)
  B = np.zeros(N-1)
  for i in range(N-1):
    A[i] = H[i+1] - H[i]
  B = sorted(A)
  if B[0] >= 0:
    print('Yes')
  else:
    print('No')

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

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

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

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

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

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

for i in range(n):
    if check + 1 < h[n-1-i]:
        print('No')
        break
    else:
        check = min(check,h[n-1-i])
        count = i

if count == n-1:
    print('Yes')

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

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

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

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

if H[0] - H[1] >= 2:
    print("No")
    exit()
elif H[0] - H[1] < 0:
    H[1] -= 1

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

print("Yes")

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

maxv=0
minv=h[0]
for i in range(1,n):
    maxv=max(maxv, h[i]-minv)
    minv=min(minv, h[i])
if maxv >= 2:
    print("No")
else:
    print("Yes")

Solution (Python):
def main(N, H):
    for i in reversed(range(1, N)):
        if H[i-1] - H[i] > 1:
            return 'No'
        elif H[i-1] - H[i] == 1:
            H[i-1] -= 1
    else:
        return 'Yes'


if __name__ == '__main__':
    N = int(input())
    H = [int(x) for x in input().split()]
    print(main(N, H))

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

Solution (Python):
n = int(input())
hs = list(map(int,input().split()))
pre1 = hs.pop(0)
pre1 -=1
for h in hs:
    if h>=pre1 +1:
        pre1 = h-1
    else:
        if h == pre1:
            pass
        else :
            print("No")
            break
else:
    print("Yes")

Solution (Python):
N = int(input())
H = list(map(int, input().split(' ')))
H = [0] + H + [10**10]

ans = 'Yes'
for _i in range(N):
    i = _i + 1

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

    if H[i-1] <= H[i] and H[i] <= H[i+1]:
        continue
    else:
        ans = 'No'

print(ans)

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

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

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

Tmp = []
Tmp = input().rstrip().split(' ')
nTmp = [ 0 for i in range(nN)]

nFlag=1

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

for i in range(nN):
  nTmp[i] = int(Tmp[i])
  if i == 0:
    nTmp[0] -= 1
    continue
  nChk = nTmp[i]-nTmp[i-1]
  if nChk > 0:
    nTmp[i] -=1
  elif nChk == 0:
    continue
  else:
    nFlag = 0
    break

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

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

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

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

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

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

Solution (Python):
test = False


def solve_a(test=False, a=0, b=0, c=0):
    if not test:
        a, b, c = map(int, input().split())
    d = max(c - (a - b), 0)
    print(d)


def solve_b(test=False, n=0):
    if not test:
        n = int(input())
    res = 0
    for i in range(1, n + 1):
        if len(str(i)) % 2 == 1:
            res += 1
    print(res)


def solve_c(test=False, n=0, h_list=[]):
    if not test:
        n = int(input())
        h_list = list(map(int, input().split()))
    res = 'Yes'
    new_h_list = [0] * n
    new_h_list[0] = h_list[0] - 1

    for i in range(1, n):
        
        if h_list[i] == new_h_list[i - 1]:
            new_h_list[i] = h_list[i]
        elif h_list[i] < new_h_list[i - 1]:
            new_h_list[i] = h_list[i]
            res = 'No'
        else:
            new_h_list[i] = h_list[i] - 1
    print(res)


if __name__ == "__main__":
    if test:
        solve_a(test=True, a=6, b=4, c=3)
        solve_a(test=True, a=8, b=3, c=9)
        solve_a(test=True, a=12, b=3, c=7)
        solve_b(test=True, n=11)
        solve_b(test=True, n=136)
        solve_b(test=True, n=100000)
        solve_c(test=True, n=5, h_list=[1, 2, 1, 1, 3])
        solve_c(test=True, n=4, h_list=[1, 3, 2, 1])
        solve_c(test=True, n=5, h_list=[1, 2, 3, 4, 5])
        solve_c(test=True, n=1, h_list=[1000000000])
    else:
        
        
        solve_c()

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

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

min_num = -1
ans = True
for i in range(N - 1):
    h = h_list[i]
    h2 = h_list[i + 1]
    if h >= h2:
        h_list[i] -= 1
        h -= 1
        if h2 < min_num or h > h2:
            ans = False
    else:
        h_list[i+1] -= 1
        h2 -= 1
    min_num = max(h, h2)
    




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

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

Solution (Python):
from collections import deque
N = int(input())
H = list(map(int, input().split()))
q = deque(H)
min = q.pop()
flag=True
for _ in range(N-1):
    r = q.pop()
    if min >= r:
        min = r
    elif r-min == 1:
        continue
    else:
        print('No')
        flag=False
        break
if flag:
    print('Yes')

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

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

print(ans)

Solution (Python):
N = int(input())
H = list(map(int, input().split()))
if N == 1:
    print('Yes')
else:
    cnt = 0
    Hn = []
    flag = True
    for i in range(len(H)-1):
        Hn.append(H[i+1]-H[i])
    for h in Hn:
        if h < -1:
            flag = False
        elif h == -1:
            cnt += 1
            if cnt == 2:
                flag = False
        elif h == 0:
            continue
        else:
            cnt = 0
    if flag:
        print('Yes')
    else:
        print('No')

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

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

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

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

for i in range(len(A)):
    if i == 0:
        continue
    if A[i] > A[i-1]:
        A[i] = A[i] - 1
        if A[i] > A[i-1]:
            print('No')
            exit()
print('Yes')
exit()

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

for i in range(N-1):
    if H[-2-i] -1 > tmp_h:
        answer = "No"
        break
    elif H[-2-i] -1 == tmp_h:
        tmp_h = H[-2-i] -1
    else:
        tmp_h = H[-2-i]

print(answer)

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

tmp = H[0]
for i, h in enumerate(H[1:]):
    if tmp == h:
        continue
    elif tmp == h-1:
        tmp = h-1
    elif tmp < h-1:
        tmp = h - 1
    elif tmp > h-1:
        print('No')
        quit()


print('Yes')

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

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

Solution (Python):

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

H_lst[0] -= 1

def judge():
    for i in range(N-1):
        if H_lst[i] < H_lst[i+1]:
            H_lst[i+1] -= 1
        elif H_lst[i] == H_lst[i+1]:
            pass
        else:
            H_lst[i] += 1
            if H_lst[i] == H_lst[i+1]:
                pass
            else:
                return False
    return True

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

Solution (Python):
n=int(input())
h=list(map(int, input().split()))
now=0
max=-1
for val in h:
    if max-1 > val:
        print('No')
        exit()
    elif val > max:
        max=val

print('Yes')

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

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

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

print(ans)

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

ans = 'Yes'

max_h = 0
for i in range(N):
    max_h = max(max_h, H[i])
    if H[i] < max_h-1:
        ans = 'No'

print(ans)

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

lastHeight = 0
for idx in range(len(H)):
    if H[idx] < lastHeight:
        print("No")
        break
    elif H[idx] == lastHeight:
        lastHeight = H[idx]
    else:
        lastHeight = H[idx] - 1
else:
    print("Yes")

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

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

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

Solution (Python):
n = int(input())
H = [int(h) for h in input().split()] + [10e+9+7]
f = 1
for i in range(-1,-n-1,-1):
    if H[i] - H[i-1] < -1:
        f = 0
        break
    elif H[i] - H[i-1] == -1:
        H[i-1] = H[i-1] - 1
if f:
    print('Yes')
else:
    print('No')

Solution (Python):
a=input()
a=int(a)
b=[int(i) for i in input().split()]
x=0
c=0
of=0
for i in b:
    if x<i:
        b[of]-=1
        of+=1
        x=i-1
        continue
    of+=1
    x=i
x=0
for i in b:
    if x>i:
        c=1
        print("No")
        break
    x=i
if c==0:
    print("Yes")

Solution (Python):




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


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

print(ans)

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

res = 'Yes'

nums[0] -= 1
for i in range(N - 1):
    diff = nums[i + 1] - nums[i]
    if diff == 0:
        continue
    if diff >= 0:
        nums[i + 1] -= 1
    if diff < 0:
        res = 'No'
        break

print(res)

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

Solution (Python):
def main():
    n = int(input())
    ls = [int(x) for x in input().split()]
    if n ==1:
        print("Yes")
    else:
        now = ls[0]-1
        for i in range(1,n):
            if ls[i]-1>now:
                now = ls[i]-1
            elif ls[i]-1==now:
                pass
            else:
                if ls[i]==now:
                    pass
                else:
                    print("No")
                    exit()
        print("Yes")

        
if __name__ == '__main__':
    main()

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

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

    
    else:
        print("No")
        flag = 1
        break

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

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

pre_h = 0
for h in H:
    if pre_h == h:
        continue
    if pre_h < h:
        pre_h = h-1
        continue
    print('No')
    break
else:
    print('Yes')