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=map(int,input().split())
h=list(H)
s=9

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

    else:
        s=0
        break


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

Solution (Python):
import sys
N = int(input())
A = [int(i) for i in input().split()]
max = A[0]
if N == 1:
    print("Yes")
elif N == 2:
    if A[0] - A[1] >= 2:
        print("No")
    else:
        print("Yes")
else:
    for i in range(1,N):
        if max - A[i] >= 2:
            print("No")

            sys.exit()
        elif A[i] > max:
            max = A[i]
            
    print("Yes")

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

can = True

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

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

Solution (Python):
def main():
    n = int(input())
    h = [int(h) for h in input().split(' ')]
    for i in range(n):
        index = n - 1 - i
        if i == n - 1:
            print("Yes")
            break
        if h[index] + 1 < h[index - 1]:
            print("No")
            break
        elif h[index - 1] - 1 == h[index]:
            h[index - 1] -= 1


if __name__ == '__main__':
    """
    左右一列に N 個のマスが並んでおり、左から i 番目のマスの高さは H_i です。
    あなたは各マスについて 1 度ずつ次のいずれかの操作を行います。

    マスの高さを 1
    - 低くする。
    - 何もしない。
    操作をうまく行うことでマスの高さを左から右に向かって単調非減少にできるか求めてください。

    制約
    入力は全て整数である。
    1 ≤ N ≤ 10^5
    1 ≤ H_i ≤ 10^9
    """
    main()

Solution (Python):
n = int(input())
tall = list(map(int, input().split()))
lar = tall[0]
lno = 0
frag = 0


for i in range(n):
    if(tall[i]>lar):
        lar= tall[i]
    if(lar - tall[i] >= 2):
        frag = 1
        break

if(frag == 1):
    print("No")
else:
    print("Yes")

Solution (Python):
import sys

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    H = string_to_int(inputs[0])
    min_h = -1

    if len(H) == 1:
        return "Yes"

    not_operation_start = 0
    for i in range(len(H)-1):
        flg = True
        if H[i] - H[i+1] >= 2:
            return "No"
        elif H[i] - H[i+1] == 1:
            if i - 1 >= 0:
                if H[i] - H[i-1] >= 1:
                    flg = True
                else:
                    flg = False
            else:
                flg = True
            if flg is False and not_operation_start != -1:
                if not_operation_start - 1 >= 0:
                    
                    flg = False
                    for j in range(not_operation_start, i+1):
                        if H[j] - H[j - 1] >= 1:
                            flg = True
                            break
                else:
                    flg = True
            if flg:
                H[i] -= 1
            else:
                return "No"
            not_operation_start = -1
        else:
            if not_operation_start == -1:
                not_operation_start = i
    return "Yes"


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)

Solution (Python):
N = int(input())
H = []
ans = "a"



H = list(map(int, input().split()))
I = H[0]
if len(H) == 0:
  ans = "Yes"
for i in range(1, len(H)):
  P = I
  I = H[i]
  if I > P:
    I = I - 1
  if I < P:
    ans = "No"


if ans not in "No":
  ans = "Yes"
print(ans)

Solution (Python):
N=int(input())
H=[int(x) for x in input().split()]
def Solve():
    flag=True
    for i in range(len(H)-1):
        if H[i]>H[i+1]+1:
            return 'No'
        elif H[i]==H[i+1]+1:
            if not flag:
                return 'No'
            flag=False
        elif H[i]<H[i+1]:
            flag=True
            
    return 'Yes'

print(Solve())

Solution (Python):
def resolve():

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

    for i in range(n):

        if i == 0:
            h[i] -= 1
            continue

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

        if h[i-1] > h[i]:
            print('No')
            return

    print('Yes')
    
resolve()

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

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

print(correct)

Solution (Python):


import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N = i2n()
    H = i2nn()
    H[0] -= 1
    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')
    return

main()

Solution (Python):
N=int(input())
H=list(map(int,input().split()))
F=H
T=True
B=max(H)
C=H.index(max(H))
if B-H[N-1]>1 and B!=H[N-1]:
    T=False
if C==N-1 and N!=1:
    del H[N-1]
    B=max(H)
    H=F
    C=H.index(B)
if T:
    for i in range(N-1):
        if i>C:
            if H[i]+1<H[C]:
                T=False
if T:
    print('Yes')
else:
    print('No')

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

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

Solution (Python):
p = 10 ** 9
input()
for h in map(int, reversed(input().split())):
    if h > p + 1:
        print('No')
        break
    p = min(h, p)
else:
    print('Yes')

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

if cnt == 1:
    print('Yes')
else:
    ma = lst[0]
    for i in range(1, cnt):
        if ma - lst[i] >= 2:
            print('No')
            break
        elif i == cnt-1:
            print('Yes')
        ma = max(ma, lst[i])

Solution (Python):
N =int(input())
H = [int(x) for x in input().split()]
h=0
l=0
memo = 0
for i in range(N):
    if H[i]>=h:
        h=H[i]
    elif H[i]<h and H[i]>=l:
        l=H[i]
    else:
        memo+=1
for i in range(N):
    if i==N-1:
        break
    elif H[i]-H[i+1]>=2:
        memo+=1

if memo>=1:
    print('No')
else:
    print('Yes')

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

H[0] = H[0] - 1

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

Solution (Python):
N = int(input())
H = [int(i) for i in input().split()] 
C = 0
F = 0
for i in range(N-1, 0, -1):
	if H[i-1] > (H[i]+1):
		C = 1
		break
	elif H[i-1] == (H[i]+1):
		if F == 0:
			F = 1
		else:
			C = 1
			break
	elif H[i-1] < H[i]:
		F = 0
		

if C == 1:
	print("No")
else:
	print("Yes")

Solution (Python):

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

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

Solution (Python):
import sys

n = int(input())

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

max_ = 1

for i in range(n-1):
  max_ = max(h_list[i], max_)
  d = h_list[i+1] - h_list[i]
  if d < -1:
    print('No')
    sys.exit()
  elif i > 0:
    if max_ - h_list[i+1] > 1:
      print('No')
      sys.exit()

print('Yes')

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

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

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

ans = 'Yes'
flag = False
for i in range(n-1):
  diff = h[i+1]-h[i]
  if diff <= -1:
    if flag:
      ans='No'
      break        
    
    if diff <= -2:
      ans = 'No'
      break
        
    flag = True          
    
  else:
    if diff >= 1:
      flag = False

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
for i in range(1,n):
    if (h[i] < h[i - 1]):
        print("No")
        exit()
print("Yes")

Solution (Python):
_=int(input())
hs = [int(x) for x in input().split()][::-1]
cannot = False


for i in range(len(hs)-1):
    if hs[i]<hs[i+1]:
        hs[i+1]-=1
    if hs[i]<hs[i+1]:
        cannot=True
        break
print("No" if cannot else "Yes")

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

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

a.reverse()

flg = True

for i in range(n-1):
	if a[i] >= a[i+1]:
		continue
	else:
		if a[i+1] > a[i] +1 :
			flg = False
			break
		else:
			a[i+1] -= 1

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

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

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

for i in xrange(n - 1, 0, -1):
    if a[i] < a[i - 1]:
        if a[i] < (a[i - 1] - 1):
            yes = 0
            break
        else:
            a[i - 1] -= 1

if yes:
    print "Yes"
else:
    print "No"

Solution (Python):
N = int(input())
H = list(map(int, input().split()))
 
next_num = 10**9
result = True
for i in reversed(H):
    if i > next_num:
        i -= 1
        if i > next_num:
            result = False
    next_num = i

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

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

for i, h in enumerate(reversed(h_list)):
    index = len(h_list) - 1 - i
    if index == 0:
        print('Yes')
        break
    prev_h = h_list[index-1]
    
    if prev_h-1 > h:
        print('No')
        break
    elif prev_h-1 == h:
        h_list[index-1] -= 1

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

y = None
is_OK = True
for i, h in enumerate(list):
  if i == 0:
    y = h
  if h > y:
    y = h - 1
  if h < y:
    is_OK = False

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

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

jud = "Yes"
cnt = 0
for i in range(N-1):
    if h[i] > h[i+1]:
        cnt += 1
    if h[i] < h[i+1]:
        cnt = 0
    if cnt == 2:
        jud = "No"
        break
    if h[i] - h[i+1] > 1:
        jud = "No"
        break

if h[N-2] - h[N-1] > 1:
    jud = "No"

print(jud)

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

ans = 'Yes'
for i in reversed(range(n)):
    h_i = h[i]
    if i == 0:
        h_i_left = 0
    else:
        h_i_left = h[i-1]
    diff = h_i_left - h_i
    if diff > 1:
        ans = 'No'
        break
    elif diff == 1:
        if i != 0:
            h[i-1] = h[i-1] - 1
    else:
        continue

print(ans)

Solution (Python):




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

def endsub():
  print('No')
  exit()

same = False
for i in range(n-1):
  if not same:
    an[i] -= 1
  if an[i] > an[i+1]:
    endsub()
  elif an[i] == an[i+1]:
    same = True
  else:
    same = False
print('Yes')

Solution (Python):
N = int(input())
H = list(map(int,input().split()))
var = 0
for k in range(N):
  if k == N-1:
    aaa = 2  
  elif k == 0:
    H[k] = H[k] - 1
  elif H[k+1] - H[k] >= -1 and  H[k] - H[k-1] > 0:
    H[k] = H[k] - 1
  elif H[k+1] - H[k] >= 0:
    aaa = 4
  else:
    var = 1
    break
if var == 0:
  print('Yes')
else:
  print('No')

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

for i in range(N):
  if i == 0:
    RMH[i] = H[-i-1]
  else:
    RMH[i] = min([RMH[i-1],H[-i-1]]) 


for i in range(N-1):
  if H[i] - RMH[-i-2] > 1:
    ans = "No"

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

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

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

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


main()

Solution (Python):
n = int(input())
h = list(map(int, input().split()))
rh = h[::-1]
result = [rh[0]]
for i in range(1, len(h)):
  if result[i - 1] >= rh[i]:
    result.append(rh[i])
  elif result[i - 1] == rh[i] - 1:
    result.append(rh[i] - 1)
  else:
    print('No')
    break
else:
  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 >= 0:
        continue
    elif diff == -1:
        H[i-1] -= 1
    elif diff < -1:
        print('No')
        break
else:
    print('Yes')

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

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

H_list.reverse()

flag = True
check_int = H_list[0]

for i in range(1, N):
    if H_list[i] > check_int:
        if check_int != H_list[i] -1:
            flag = False
            break
        else:
            check_int = H_list[i] -1
    else:
        check_int = H_list[i]

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

Solution (Python):
def main():

    _ = int(input())
    h = [int(x) for x in input().split()]
    limit = h[-1]
    
    
    for num in reversed(h[:-1]):
        if limit > num:
            limit = num
        elif limit + 2 <= num:
            print("No")
            return
    print("Yes")

if __name__ == "__main__":
    main()

Solution (Python):
n=int(input())
hl=list(map(int, input().split()))
m=0
for h in hl:
    if m <= h: m = h
    elif m == h+1: continue
    else: print("No"); break
else:
    print("Yes")

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

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

count = 0

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

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

Solution (Python):

def get_num():
    return int(input())


def get_numbers():
    return map(int, input().split())


n = get_num()
h = list(get_numbers())

dp = [0 for _ in range(n)]

dp[0] = max(h[0] - 1, 0)
res = True
for i in range(1, n):
    dp[i] = max(dp[i - 1], h[i] - 1)
    if h[i] < dp[i] or h[i] > dp[i] + 1:
        res = False
        break

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

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

prev = 0
for hi in h:
    if prev > hi:
        print("No")
        sys.exit()
    elif prev < hi:
        hi -= 1
    prev = hi

print("Yes")

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

ind = 0
prev = h[0] - 1
no = False

for i in range(1, n):
  if prev < h[i]:
    prev = h[i] - 1
  elif prev == h[i]:
    prev = h[i]
  else:
    print('No')
    no = True
    break

if not no:
  print('Yes')

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

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

ans = True

hs.reverse()
pre_n = 10 ** 9 + 1
can_sub = True
for n in hs:
    
    if n - 1> pre_n:
        ans = False
        break
    elif n - 1 == pre_n:
        if can_sub:
            pre_n = n -1
            can_sub = False
        else:
            pre_n = n -1
            can_sub = False
    elif n == pre_n:
        pre_n = n
        can_sub = False
    else:
        pre_n = n
        can_sub = True

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

Solution (Python):
import sys

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

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

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

print('Yes')

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

if N <= 1:
  print("Yes")
  exit()
H[0] -= 1
i = 1
while i<N:
  if H[i]>H[i-1]:
    H[i]-=1
  if H[i] < H[i-1]:
    print("No")
    exit()
  i+=1
print("Yes")

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

nmax = H[0]

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

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

possible = True
for i in range(1,n):
    if h[-i] < h[-i-1]:
        h[-i-1] -= 1
        if h[-i] < h[-i-1]:
            possible = False
            break

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

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

res='Yes'

for i in range(n-1):
	if x[i+1]<x[i]:
		res='No'
		break
	if x[i+1]>x[i]:
		x[i+1]-=1

print(res)

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

def stairs():
    for i in range(1, n):
        if h[i] > h[i-1]:
            h[i] -= 1
    
        if h[i] < h[i-1]:
            return False
        
    return True

if stairs() == True:
    print('Yes')
else:
    print('No')

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

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

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

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

else:
    print('No')

Solution (Python):



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

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

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

    print('Yes')


if __name__ == '__main__':
    main()

Solution (Python):

def main():
    N = int(input())
    H = [int(f) for f in input().split()]

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

    
if __name__ == "__main__":
    main()

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

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

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

if h[0] > 1:
  h[0] -= 1

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

print(ans)

Solution (Python):

N = int(input())
HN = [-1] + list(map(int, input().split())) + [10 ** 10]

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

Solution (Python):
import sys
N = int(input())
height = list(map(int, input().split()))
pre_h = 0
now_h = height[0]

for i in range(1, N):
    next_h = height[i]
    if now_h > next_h:
        now_h -=1
        if now_h > next_h or pre_h > now_h:
            print("No")
            sys.exit()
    elif now_h > pre_h:
        now_h -= 1
    pre_h = now_h
    now_h = next_h
print("Yes")

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

ret = 'Yes'
bar = H[0] - 1

for i in range(1, N):
	if bar > H[i]:
		ret = ('No')
		break
	elif bar < H[i]:
		bar = H[i] - 1

print(ret)

Solution (Python):


''' 
------------------------
author : iiou16
------------------------
'''

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

    flag = 0

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

if __name__ == '__main__':
    main()

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

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

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

Solution (Python):
import sys

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

new_H = list(reversed(H))

max = new_H[0]

for i in range(1,N):
  if new_H[i] <= max:
    max = new_H[i]
  elif new_H[i] == max + 1:
    max = new_H[i] - 1
  else:
    print('No')
    sys.exit()

print('Yes')

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

print("Yes")

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

result = True
if len(H)==1:
  result = True
else:
  before = H[0] - 1
  for i in range(1,N):
    if H[i] > before:
      before = H[i] - 1
    elif H[i] < before:
      result = False
      before = H[i] - 1
    else:
      before = H[i]
      continue
    
print("Yes" if result else "No")

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

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

Hs = sorted(H)

for i in range(N):
    if abs(H[i] - Hs[i]) >= 2:
        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] and i > 0:
        H[i-1] -= 1

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

print('Yes')

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

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

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

    print(answer)


main()

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

bind = False
for n in range(N - 1):
	if H[n] < H[n + 1]:
		bind = False
		continue
	else:
		if H[n] == H[n + 1]:
			continue
		if bind:
			print("No")
			break
		else:
			if H[n] - 1 <= H[n + 1]:
				bind = True
				continue
			else:
				print("No")
				break
else:
	print("Yes")

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

Solution (Python):
import sys
n = int(input())
a = [int(i) for i in input().split()]
sample = a[0]
for i in range(n):
    if sample - a[i] >= 2:
        print("No")
        sys.exit()
    else:
        sample = max(sample,a[i])
print("Yes")

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

def solve(n, h, cur, l):
  if cur > n:
    return True
  else:
    if l < h[cur]:
      return solve(n, h, cur+1, h[cur]-1)
    elif l == h[cur]:
      return solve(n, h, cur+1, h[cur])
    else:
      return False

N = int(input())
H = [-1]+list(map(int, input().split()))+[(10**9)+1]
print("Yes" if solve(N, H, 1, -1) else "No")

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

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

diff = [h[i+1]-h[i] for i in range(n-1)]


flag = False

for d in diff:
  if d<0:
    if flag==True:
      print("No")
      sys.exit(0)
    else:
      flag=True
  elif d>0:
    flag=False
    


if min(diff) < -1:
  print("No")
else:
  print("Yes")

Solution (Python):
N = int(input())
H = list(map(int, input().split()))
diff = [0] * N
ret = "Yes"
for i in range(1,N):
    if H[i] - H[i-1] > 0:
        H[i] -= 1
    elif H[i] - H[i-1] < 0:
        ret = "No"
print(ret)

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

flag = 0
before = 0

if N == 1:
    flag = 0
    
else: 
    for i in range(N-1):
        if i > 0:
            before = List[i-1]
        
        if List[i] > before:
            List[i] -= 1

        if List[i] > List[i+1]:
            print('No')
            flag = 1
            break

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

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

Solution (Python):
N=int(input())
H=list(map(int,input().split()))
s=1
c=0
if N>=2:
  for i in range(N-1,1,-1):
    if H[i-1]<=H[i]:
      c=0
    elif H[i-1]-1==H[i]:
      H[i-1]-=1
    else:
      s=0
      break

print("Yes" if s==1 else "No")

Solution (Python):
def is_ok(H):
    if len(H) <= 1:
        return True

    H[0] = H[0] - 1
    if H[0] > H[1]:
        return False
    for i in range(1, len(H)-1):
        if not((H[i]-1 > H[i+1]) or (H[i-1] > H[i]-1)):
            H[i] = H[i] - 1
        if H[i] > H[i+1] or H[i-1] > H[i]:
            return False
    return True

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

if is_ok(H):
    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):
N = int(input())
H = [int(h) for h in input().split()]

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

Solution (Python):
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")


def main():
    N = int(input())
    H = list(map(int, input().split()))
    logging.info("Hello!")

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


    print("Yes")
        
    
    
if __name__ == "__main__":
    main()

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

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

ans = 'Yes'
a = 0
for i in h:
    if a <= i-1:
        a = i-1
    elif a <= i:
        a = i
    else:
        ans = 'No'
        break
print(ans)

Solution (Python):
import numpy as np

n = int(input())
hs = list(map(int, input().strip().split()))


dp = np.zeros(n, dtype=np.bool)
dp[0] = True

for idx in range(1, n):
    if not dp[idx - 1]:
       dp[idx] = False
    elif hs[idx - 1] == hs[idx]:
        dp[idx] = True
    elif hs[idx - 1] < hs[idx]:
        dp[idx] = True
        hs[idx] -= 1
    else:
        dp[idx] = False

if dp[-1]:
    print('Yes')
else:
    print('No')

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

Solution (Python):
import sys


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

B = [False for _ in H]

i = 0
while i < N - 1:
    L = H[i]
    R = H[i + 1]

    if L <= R:
        i += 1
        continue

    if (L - R <= 1) and not B[i]:
        H[i] -= 1
        B[i] = True
        i = max(i - 1, 0)
        continue

    print("No")
    sys.exit(0)

print("Yes")

Solution (Python):
def build_stairs(n,a):
    if n == 1:
        return "Yes"

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

    flag = False
    for i in range(1,k):
        if a[i-1] > a[i]:
            flag = False
            break
        else:
            flag = True

    if flag == True:
        return "Yes"
    if flag == False:
        return "No"

if __name__ == '__main__':
    n = int(input())
    a = list(map(int,input().split()))

    print("%s" %(build_stairs(n,a)))