CodeEff/ECCO huggingface dataset:
# Original solution
# coding: utf-8
import sys
from heapq import heapify, heappop, heappush

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

def dijkstra(start):
    INF = 10 ** 15
    dist = [INF] * (N+1)
    dist[start] = 0
    que = [(0, start)]
    while que:
        d, prev = heappop(que)
        if dist[prev] < d:
            continue
        for next in graph[prev]:
            d1 = d + 1
            if dist[next] > d1:
                dist[next] = d1
                heappush(que, (d1, next))
    return dist

N = ir()
graph = [[] for _ in range(N+1)] # 1-indexed
for _ in range(N-1):
    a, b = lr()
    graph[a].append(b)
    graph[b].append(a)

# １を根とする
dist = dijkstra(1)
dist = sorted([(x, i) for i, x in enumerate(dist)], reverse=True)
new_root = dist[1][1]
dist = dijkstra(new_root)
diameter = max(dist[1:]) + 1
bl = diameter % 3 != 2
print(('First' if bl else 'Second'))
# 22

# Optimized solution
# coding: utf-8
import sys
from heapq import heapify, heappop, heappush

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

def tree_diameter(graph): # 木の直径
    def dijkstra(start):
        INF = 10 ** 15
        dist = [INF] * (N+1)
        dist[start] = 0
        que = [(0, start)]
        length = 0; far = 0
        while que:
            d, prev = heappop(que)
            if dist[prev] < d:
                continue
            for next in graph[prev]:
                d1 = d + 1
                if dist[next] > d1:
                    dist[next] = d1
                    if d1 > length:
                        length = d1; far = next
                    heappush(que, (d1, next))
        return length, far
    _, f = dijkstra(1)
    l, f = dijkstra(f)
    return l

N = ir()
graph = [[] for _ in range(N+1)] # 1-indexed
for _ in range(N-1):
    a, b = lr()
    graph[a].append(b)
    graph[b].append(a)

daiameter = tree_diameter(graph)
bl = daiameter % 3 != 1
print(('First' if bl else 'Second'))
# Original solution
from collections import defaultdict
import queue

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

class Graph(object):

    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, a, b):
        self.graph[a].append(b)


class breadth(object):
    def __init__(self, graph, s):
        self.g = graph.graph
        self.dist = defaultdict(lambda: float('inf'))
        self.dist[s] = 0
        self.visit = ["no" for i in range(len(graph) + 1)]
        self.visit[s] = "yes"

        self.Q = queue.Queue()
        self.Q.put([self.dist[s], s])

        while not self.Q.empty():
            dist_u, u = self.Q.get()
            for v in self.g[u]:
                if self.visit[v] == "yes":
                    continue
                else:
                    self.dist[v] = dist_u + 1
                    self.visit[v] = "yes"
                    self.Q.put([self.dist[v], v])


N = int(eval(input()))
if N == 1:
	print("First")
else:
	g_a = Graph()
	for i in range(N - 1):
		a, b = getlist()
		g_a.add_edge(a, b)
		g_a.add_edge(b, a)
	
	s = 1
	E = breadth(g_a, s)
	x = 0
	for i in E.dist:
		if E.dist[i] > x:
			x = E.dist[i]
			y = i
	F = breadth(g_a, y)
	x = 0
	for i in F.dist:
		if F.dist[i] > x:
			x = F.dist[i]
			y = i

	if x % 3 == 0 or x % 3 == 2:
		print("First")
	else:
		print("Second")


# Optimized solution
from collections import defaultdict
from collections import deque

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

class Graph(object):

    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, a, b):
        self.graph[a].append(b)


class breadth(object):
    def __init__(self, graph, s):
        self.g = graph.graph
        self.dist = defaultdict(lambda: float('inf'))
        self.dist[s] = 0
        self.visit = ["no" for i in range(len(graph) + 1)]
        self.visit[s] = "yes"

        self.Q = deque()
        self.Q.append([self.dist[s], s])

        while self.Q:
            dist_u, u = self.Q.popleft()
            for v in self.g[u]:
                if self.visit[v] == "yes":
                    continue
                else:
                    self.dist[v] = dist_u + 1
                    self.visit[v] = "yes"
                    self.Q.append([self.dist[v], v])


N = int(eval(input()))
if N == 1:
	print("First")
else:
	g_a = Graph()
	for i in range(N - 1):
		a, b = getlist()
		g_a.add_edge(a, b)
		g_a.add_edge(b, a)
	
	s = 1
	E = breadth(g_a, s)
	x = 0
	for i in E.dist:
		if E.dist[i] > x:
			x = E.dist[i]
			y = i
	F = breadth(g_a, y)
	x = 0
	for i in F.dist:
		if F.dist[i] > x:
			x = F.dist[i]
			y = i

	if x % 3 == 0 or x % 3 == 2:
		print("First")
	else:
		print("Second")
# Original solution
import sys
input = sys.stdin.buffer.readline
from collections import deque

def main():
    N = int(eval(input()))
    if N == 1:
        print("First")
        exit()
    edge = [[] for _ in range(N)]
    
    for _ in range(N-1):
        a,b = list(map(int,input().split()))
        edge[a-1].append(b-1)
        edge[b-1].append(a-1)
        
    d = 0
    for st in range(N):
        dep = [-1 for _ in range(N)]
        dep[st] = 0
        q = deque([st])
        while q:
            now = q.popleft()
            for fol in edge[now]:
                if dep[fol] == -1:
                    dep[fol] = dep[now]+1
                    q.append(fol)
        d = max(d,max(dep))
        
    if d%3 == 1:
        print("Second")
    else:
        print("First")

if __name__ == "__main__":
    main()


# Optimized solution
import sys
input = sys.stdin.buffer.readline
from collections import deque

def main():
    N = int(eval(input()))
    if N == 1:
        print("First")
        exit()
    edge = [[] for _ in range(N)]
    
    for _ in range(N-1):
        a,b = list(map(int,input().split()))
        edge[a-1].append(b-1)
        edge[b-1].append(a-1)
        
    dep = [-1 for _ in range(N)]
    dep[0] = 0
    q = deque([0])
    while q:
        now = q.popleft()
        for fol in edge[now]:
            if dep[fol] == -1:
                dep[fol] = dep[now]+1
                q.append(fol)
    
    st = dep.index(max(dep))
    dep = [-1 for _ in range(N)]
    dep[st] = 0
    q = deque([st])
    while q:
        now = q.popleft()
        for fol in edge[now]:
            if dep[fol] == -1:
                dep[fol] = dep[now]+1
                q.append(fol)
                
    if max(dep)%3 == 1:
        print("Second")
    else:
        print("First")

if __name__ == "__main__":
    main()
# Original solution
import sys
sys.setrecursionlimit(210000)
def s(x,v,d):
  r=[d,v]
  for u in g[v]:
    if u!=x:
      t=s(v,u,d+1)
      if r[0]<t[0]:r=t
  return r
n,*t=list(map(int,open(0).read().split()))
g=[set()for _ in range(n+1)]
for a,b in zip(t[::2],t[1::2]):
  g[a].add(b)
  g[b].add(a)
print(('SFeicrosntd'[s(0,s(0,1,0)[1],0)[0]%3!=1::2]))

# Optimized solution
import sys
sys.setrecursionlimit(250000)
def s(x,v,d):
  r=[d,v]
  for u in g[v]:
    if u!=x:
      t=s(v,u,d+1)
      if r[0]<t[0]:r=t
  return r
n,*t=list(map(int,open(0).read().split()))
g=[[]for _ in range(n+1)]
for a,b in zip(t[::2],t[1::2]):
  g[a].append(b)
  g[b].append(a)
print(('SFeicrosntd'[s(0,s(0,1,0)[1],0)[0]%3!=1::2]))
# Original solution
# encoding: utf-8
import sys
# input = sys.stdin.readline
inf = 10 ** 18

N = int(eval(input()))
ab = [list(map(int, input().split())) for _ in range(N - 1)]

cnct = [[] for _ in range(N)]
for ai, bi in ab:
    cnct[ai - 1].append(bi - 1)
    cnct[bi - 1].append(ai - 1)
# print("#", cnct)

# start from a leaf
for src in range(N):
    if len(cnct[src]) > 1: break
# print("#", src)

import heapq

len_max = 0
while True:
    q = []
    d = [inf] * N
    prev = [None] * N
    #
    heapq.heappush(q, (0, src))
    d[src] = 0
    while len(q) > 0:
        du, u = heapq.heappop(q)
        # print("#", du, u)
        for dst in cnct[u]:
            # print("##", dst)
            if d[dst] > du + 1:
                d[dst] = du + 1
                prev[dst] = u
                heapq.heappush(q, (du + 1, dst))
    #
    if len_max == max(d):
        break
    elif len_max < max(d):
        len_max = max(d)
        src = d.index(len_max)
    else:
        continue

# print("#", len_max)

if len_max % 3 == 1:
    print('Second')    
else:
    print('First')

# Optimized solution
# encoding: utf-8
import sys
# input = sys.stdin.readline
inf = 10 ** 18
 
N = int(eval(input()))
ab = [list(map(int, input().split())) for _ in range(N - 1)]
 
cnct = [[] for _ in range(N)]
for ai, bi in ab:
    cnct[ai - 1].append(bi - 1)
    cnct[bi - 1].append(ai - 1)
# print("#", cnct)
 
# start from a leaf
for src in range(N):
    if len(cnct[src]) > 1: break
# print("#", src)
 
import heapq
 
len_max = 0
for i in range(10):
    q = []
    d = [inf] * N
    prev = [None] * N
    #
    heapq.heappush(q, (0, src))
    d[src] = 0
    while len(q) > 0:
        du, u = heapq.heappop(q)
        # print("#", du, u)
        for dst in cnct[u]:
            # print("##", dst)
            if d[dst] > du + 1:
                d[dst] = du + 1
                prev[dst] = u
                heapq.heappush(q, (du + 1, dst))
    #
    if len_max == max(d):
        break
    elif len_max < max(d):
        len_max = max(d)
        src = d.index(len_max)
    else:
        continue
 
# print("#", len_max)
 
if len_max % 3 == 1:
    print('Second')    
else:
    print('First')
# Original solution
# C問題 20分で最長の長さの道の含むノードの数Nに対して
# N%3 == 2ならS, それ以外でFであることまでわかった。
# !!直径rでいうとr%3 ==1 ならS
# しかし、longest path problemはNP hardとか言われた... 
# けど、treeであることを考慮に入れて再検索すると行けた。
# ググり力 = 関連ワードを色々入れて試す力 & 関係なさそうなテーマから早く撤退する

# 木の直径というらしい
# 木DP or 適当に初期点W　→ Wからの最遠点U　→ Uからの最遠点V でUとVの距離でわかるらしい。

N = int(eval(input()))
#各頂点が繋がってる辺リスト
E = [ [] for _ in range(N)]
for i in range(N-1):
    a,b = list(map(int, input().split()))
    E[a-1].append(b-1)
    E[b-1].append(a-1)

# #入力1
# N= 3
# E= [[1], [0, 2], [1]]

# #　入力2
# N= 6
# E= [[1], [0, 2, 3], [1], [1, 5], [5], [3, 4]]

# #　入力3
# N= 7
# E= [[6, 1], [0], [3, 5], [6, 2], [6], [2], [0, 3, 4]]


    
def farthest(s):
    visited = []
    stack = [[s,0]]
    best = [s,0]
    while len(stack)>0:
#         print("visited:",visited)
#         print("stack:",stack)
        current = stack.pop()#pop(-1)と同じ
        currentPosition = current[0] 
        currentLength = current[1]
        # bestの更新
        if currentLength > best[1]:
            best = [currentPosition, currentLength]
        visited.append(currentPosition)
        # 繋がっているノードのうち未探索の場所を追加
        for position in E[currentPosition]:
            if position not in visited:
                stack.append([position, currentLength+1])
    return best

# print("u,length:",farthest(0))
u = farthest(0)[0]
best = farthest(u)
# print(best)
# v = best[0]
diameter = best[1]
# print(diameter)
ans = "First"
if diameter % 3 == 1:
    ans = "Second"
print(ans)

# Optimized solution
# カンニングして修正
N = int(eval(input()))
#各頂点が繋がってる辺リスト
E = [ [] for _ in range(N)]
for i in range(N-1):
    a,b = list(map(int, input().split()))
    E[a-1].append(b-1)
    E[b-1].append(a-1)

# #入力1
# N= 3
# E= [[1], [0, 2], [1]]

# #　入力2
# N= 6
# E= [[1], [0, 2, 3], [1], [1, 5], [5], [3, 4]]

# #　入力3
# N= 7
# E= [[6, 1], [0], [3, 5], [6, 2], [6], [2], [0, 3, 4]]


    
def farthest(s):
    visited = [False]*N
    stack = [[s,0]]
    best = [s,0]
    while len(stack)>0:
#         print("visited:",visited)
#         print("stack:",stack)
        current = stack.pop()#pop(-1)と同じ
        currentPosition = current[0] 
        currentLength = current[1]
        visited[currentPosition] = True
        # bestの更新
        if currentLength > best[1]:
            best = [currentPosition, currentLength]
        visited.append(currentPosition)
        # 繋がっているノードのうち未探索の場所を追加
        for position in E[currentPosition]:
            if not visited[position]:
                stack.append([position, currentLength+1])
    return best

# print("u,length:",farthest(0))
u = farthest(0)[0]
best = farthest(u)
# print(best)
# v = best[0]
diameter = best[1]
# print(diameter)
ans = "First"
if diameter % 3 == 1:
    ans = "Second"
print(ans)
# Original solution
N = int(eval(input()))
H = list(map(int, input().split()))
judge = False
for i in range(1, len(H)):
  if H[i] - H[i-1] >= 1:
    H[i] -= 1
  elif H[i] - H[i-1] < 0:
    judge = True
    break
print(('No' if judge else 'Yes'))

# Optimized solution
eval(input());a=list(map(int,input().split()));b=sorted(a)
for i,j in zip(a,b):
  if abs(i-j)>1: print('No');break
else:
  print('Yes')
# Original solution
n = int(eval(input()))
h = list(map(int, input().split()))
flag = 0
for i in range(n-1):  
  for j in range(i+1, n):
    if h[i] > h[j] + 1:
      flag = 1
      break

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

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

# Optimized solution
n = int(eval(input()))
h = list(map(int, input().split()))
current_max = 0
for i in range(n):  
  if current_max > h[i] + 1:
    print("No")
    break
  else: 
    current_max = max(current_max, h[i])
    if i == n-1:
      print("Yes")
# Original solution
n = int(eval(input()))
h = list(map(int, input().split()))

answer = 'Yes'

for i in range(n):
    if i == (n - 1):
        break
    index = n - (i + 1)
    for j in range(index):
        if (h[j] - h[index]) >= 2:
            answer = 'No'
            break

print(answer)




# Optimized solution
n = int(eval(input()))
h = list(map(int, input().split()))

answer = 'Yes'

pre = 0
for i in range(n):
    if pre <= h[i]-1:
        pre = h[i]-1
    elif pre <= h[i]:
        pre = h[i]
    else:
        answer = 'No'
        break

print(answer)
# Original solution
N = int(eval(input()))
H = list(map(int, input().split()))
ans = "Yes"
for i in range(N - 1):
  if H[i] > H[i + 1]:
    if H[i] - 1 > H[i + 1]:
      ans = "No"
    else:
      H[i] = H[i] - 1
      if sorted(H[:i + 1]) != H[:i + 1]:
        ans = "No"

print(ans)

# Optimized solution
N = int(eval(input()))
H = list(map(int, input().split()))
ans = "Yes"
for i in range(0, N - 1):
  diff = H[i + 1] - H[i]
  if diff >= 1:
    H[i + 1] -= 1
  elif diff < 0:
    ans = "No"
print(ans)
# Original solution
N = int(eval(input()))
H = list(map(int, input().split()))
ans = 0
for i in range(N-1) :
    for k in range(i+1, N):
        if H[i] - H[k] > 1 :
            print('No')
            ans = 1
            exit()
if ans == 0:
    print('Yes')


# Optimized solution
N = int(eval(input()))
H = list(map(int, input().split()))
H[0] -= 1
for i in range(N - 1):
    if H[i] < H[i+1] :
        H[i+1] -= 1

    elif H[i] > H[i+1]:
        print('No')
        exit()

print('Yes')
# Original solution
def main():
    N = int(eval(input()))
    A = [int(i) for i in input().split()]
    c = 0
    if A == sorted(A):
        print("Yes")
        c += 1
    else:
        for i, a in enumerate(A):
            A[i] = a-1
            if A == sorted(A):
                print("Yes")
                c += 1
                break
    if c == 0:
        print("No")


if __name__ == "__main__":
    main()


# Optimized solution
def main():
    n = int(eval(input()))
    h = list(map(int, input().split()))
    for i in range(n-1):
        if h[i] < h[i+1]:
            h[i+1] -= 1
        elif h[i] > h[i+1]:
            print('No')
            exit()

    print('Yes')


if __name__ == "__main__":
    main()
# Original solution
n = int(eval(input()))
h = [int(i) for i in input().split()]

flag = 1
for i in range(len(h)-1):
    for j in range(i+1,len(h)):
        if(h[i]-h[j]>=2):
            print("No")
            flag=0
            break
    if(flag==0):
        break
            
if(flag==1):
    print("Yes")

# Optimized solution
n = int(eval(input()))
h = [int(i) for i in input().split()]

flag = 1
temp = h[0]
for i in range(len(h)-1):
    if(temp<h[i]):
        temp = h[i]
    if(temp-h[i+1]>=2):
        print("No")
        flag=0
        break
            
if(flag==1):
    print("Yes")
# Original solution
n = int(eval(input()))
h = list(map(int,input().split()))

a = "Yes"
m = 0

for i in range(n):
	if m - h[i] > 1:
		a ="No"
		break
	else:
		m = max(m,h[i])
print(a)

# Optimized solution
n = int(eval(input()))
lis = list(map(int,input().split()))

ans = "Yes"
m = 0
for i in range(n):
	if m - lis[i] > 1:
		ans = "No"
		break
	else:
		m = max(m,lis[i])
print(ans)
# Original solution
N, *H = list(map(int, open(0).read().split()))
cnt = 0
for i in range(N - 1):
    if H[i + 1] - H[i] < -1:
        print('No')
        break
    elif H[i + 1] - H[i] == -1:
        cnt += 1
    elif H[i + 1] - H[i] == 0:
        pass
    else:
        cnt = 0
        
    if cnt > 1:
        print('No')
        break
else:
    print('Yes')


# Optimized solution

N = int(eval(input()))
X = list(map(int, input().split()))

cur = 0
flag = True
for i in range(N):
    cur = max(cur, X[i])
    if cur - X[i] > 1:
        flag = False

if flag:
    print("Yes")
else:
    print("No")
# Original solution
import sys

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

# Optimized solution
n = int(eval(input()))
h = list(map(int, input().split()))
ans ='Yes'
mah = 0
for i in h:
    mah = max(i, mah)
    if i < mah - 1:
        ans = 'No'
        break
print(ans)
# Original solution
n = int(eval(input()))
H = list(map(int, input().split()))
for i in range(n - 1):
  if max(H[:i+1]) <= H[i+1] + 1:
    continue
  else:
    print('No')
    exit()
print('Yes')

# Optimized solution
n = int(eval(input()))
H = list(map(int, input().split()))
m = H[0]
for i in range(n - 1):
  if max(m, H[i]) <= H[i+1] + 1:
    m = max(m, H[i])
  else:
    print('No')
    exit()
print('Yes')
# Original solution
n = int(eval(input()))
hs = input().split()

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

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

print("Yes")


# Optimized solution
n = int(eval(input()))
hs = input().split()

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

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

print("Yes")
# Original solution
# ABC136C - Build Stairs
def main():
    n = int(eval(input()))
    A = tuple(map(int, input().rstrip().split()))
    cur = A[0]
    for i in A[1:]:
        if i == cur or i - 1 == cur:
            continue
        elif i > cur:
            cur = i - 1
        else:
            print("No")
            break
    else:
        print("Yes")


if __name__ == "__main__":
    main()

# Optimized solution
# ABC136C - Build Stairs
def main():
    n = int(eval(input()))
    A = tuple(map(int, input().rstrip().split()))
    cur = A[0]
    for i in A[1:]:
        if i > cur + 1:
            cur = i - 1
        if i < cur:
            print("No")
            break
    else:
        print("Yes")


if __name__ == "__main__":
    main()
# Original solution
N=int(eval(input()))
h_list=[int(x) for x in input().split()]

flag=True

for j in range(1,len(h_list)):
    for i in range(len(h_list)-j):  
        if h_list[i]-h_list[i+j]>=2:
            flag=False
            break
    
if flag:
    print("Yes")
else:
    print("No")

# Optimized solution
N=int(eval(input()))
h_list=[int(x) for x in input().split()]

flag=True

m=h_list[0]
for j in range(len(h_list)-1):
    if m<h_list[j]:
        m=h_list[j]
    if m-h_list[j+1]>=2:
        flag=False
        break        
    
if flag:
    print("Yes")
else:
    print("No")
# Original solution
def main():
    n = int(eval(input()))
    h = list(map(int,input().split()))

    h = list(reversed(h))
    flag = True

    for i in range(1,len(h)):
        if h[i] - h[i-1] > 1:
            flag = False
        elif h[i] - h[i-1] == 1:
            h[i] -= 1
        
    if flag:
        print('Yes')
    else:
        print('No')

main()

# Optimized solution

from sys import exit

ii = lambda : int(eval(input()))
mi = lambda : list(map(int,input().split()))
li = lambda : list(map(int,input().split()))


def main():
    n = ii()
    a = li()

    a = reversed(a)

    m = 100000000000
    for i in a:
        m = min(m,i)
        if i > m+1:
            print("No")
            exit()

    print("Yes")



    
main()
# Original solution
N=int(eval(input()))
h=list(map(int, input().split()))

output='Yes'
for i in range(N-1):
  if h[i]-h[i+1]>0:
    if h[i]-min(h[i+1:])>1:
      output='No'
      
print(output)

# Optimized solution
N=int(eval(input()))
h=list(map(int, input().split()))

index=N-1
output='Yes'
while index>0:
  if h[index-1]-h[index]>1:
    output='No'
    break
  elif h[index-1]-h[index]==1:
    h[index-1]-=1
  else:
    pass
  index-=1
  
print(output)
# Original solution
def resolve():

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

    for i in range(2 ** n):

        new_h = []

        for j in range(n):

            if i >> j & 1:
                new_h.append(h[j] - 1)
            else:
                new_h.append(h[j])

        flg = 0
        for k in range(n-1):
            if new_h[k] > new_h[k+1]:
                flg = 1

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

    print('No')
    
resolve()

# Optimized solution
def resolve():

    n = int(eval(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()
# Original solution
n = int(eval(input()))
h = [int(i) for i in input().split(' ')]

for i, e in enumerate(h[-2::-1]):
    if h[len(h) - i - 1] - e == -1:
        h[len(h) - i - 2] -= 1
    elif h[len(h) - i - 1] - e < -1:
        print('No')
        exit(0)

print('Yes')


# Optimized solution
n = int(eval(input()))
h = [int(i) for i in input().split(' ')]
 
for i, e in enumerate(h[-2::-1]):
    if h[len(h) - i - 1] - e == -1:
        h[len(h) - i - 2] -= 1
    elif h[len(h) - i - 1] - e >= 0:
        continue
    else:
        print('No')
        exit(0)
 
print('Yes')
# Original solution

# 初期入力
from collections import deque
import sys
input = sys.stdin.readline
N = int(eval(input()))
H = list(map(int, input().split()))

#
differ =0
ans="Yes"
max_h   =max(H)
max_index =H.index(max_h)
#最大値-1 と最大値の右側の最小値を比較,この時はfor不要
if max_index +1 <= N-1:
    if H[max_index]-1 > min(H[max_index+1:]):
        ans ="No"
        print(ans)
        sys.exit()

dq    =deque(H)
before  =dq.popleft()
for i in range(N-1):
    after   =dq.popleft()
    differ    =after - before
    #differ = H[i+1] -H[i]
    if differ <-1:      #右側が小さのは１までOK
        ans ="No"
        break
    elif differ ==-1:
        if before -1 > min(dq) :
            ans ="No"
            break
        else:
            before = after
    else:
        before = after

print(ans)

# Optimized solution

# 初期入力
from collections import deque
import sys
#input = sys.stdin.readline
N = int(eval(input()))
H = list(map(int, input().split()))

#
differ =0
ans="Yes"
max_h   =max(H)
max_index =H.index(max_h)
#最大値-1 と最大値の右側の最小値を比較,この時はfor不要
if max_index +1 <= N-1:
    if H[max_index]-1 > min(H[max_index+1:]):
        ans ="No"
        print(ans)
        sys.exit()

dq    =deque(H)
before  =dq.popleft()
for i in range(N-1):
    after   =dq.popleft()
    differ    =after - before
    #differ = H[i+1] -H[i]
    if differ <-1:      #右側が小さのは１までOK
        ans ="No"
        break
  
    else:
        before = after

print(ans)