Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

import numpy as np
S=list(input())
le=len(S)
dp=[[0 for i in range(13)] for j in range(le+1)]
dp[0][0] = 1

def xin(A,n):
    li=[0]*13
    for i in range(13):
        li[(i+n)%13] = A[i]%(10**9+7)
    return li


i=0
for k in reversed(S):
    if k=='?':
        for s in range(10):
            for j in range(13):
                dp[i + 1][(s * 10**(i) + j) % 13] += dp[i][j]%(10**9+7)

    else:
        k=int(k)
        for j in range(13):
            dp[i + 1][(k * 10**(i) + j) % 13] += dp[i][j]%(10**9+7)
        
    i += 1


print(dp[le][5]%(10**9+7))


### FIXED CODE ###

S = [int(x) if x != '?' else - 1 for x in input()]
le=len(S)

dp = [[0]*13 for i in range(le+1)]
dp[0][0] = 1

i=0
for k in S:
    if k==-1:
        for s in range(10):
            for j in range(13):
                dp[i + 1][(s + j*10) % 13] += dp[i][j]%(10**9+7)

    else:
        k=int(k)
        for j in range(13):
            dp[i + 1][(j *10 + k) % 13] += dp[i][j]%(10**9+7)
        
    i += 1


print(dp[le][5]%(10**9+7))
### BUGGY CODE ###

#!/usr/bin/env python3
from collections import Counter
MOD = 998244353


def solve(n,d):
    if d[0] != 0:
        return 0
    dc = Counter(d)
    if dc[0] > 1:
        return 0
    res = 1
    k = 1
    while k <= max(d):
        res *= dc[k-1]**dc[k]
        res %= MOD
        k += 1
    return res


def main():
    N = int(input())
    d = list(map(int,input().split()))
    # N,M = map(int,input().split())
    print(solve(N,d))


if __name__ == '__main__':
  main()


### FIXED CODE ###

#!/usr/bin/env python3
from collections import Counter
MOD = 998244353


def solve(n,d):
    if d[0] != 0:
        return 0
    dc = Counter(d)
    if dc[0] > 1:
        return 0
    res = 1
    k = 1
    dmax = max(d)
    while k <= dmax:
        res *= dc[k-1]**dc[k]
        res %= MOD
        k += 1
    return res


def main():
    N = int(input())
    d = list(map(int,input().split()))
    # N,M = map(int,input().split())
    print(solve(N,d))


if __name__ == '__main__':
  main()
### BUGGY CODE ###

n, x, y = map(int, input().split())
ans = [0 for i in range(n-1)]
for i in range(n-1):
  for j in range(i+1, n):
    k = i + 1
    l = j + 1
    a = min(l-k, abs(k-x)+abs(l-y)+1, abs(k-y)+abs(l-x)+1)
    ans[a-1] += 1
for i in ans:
  print(i)

### FIXED CODE ###

n, x, y = map(int, input().split())
ans = [0 for i in range(n-1)]
for i in range(n-1):
  k = i + 1
  b_1 = k - x
  c_1 = k - y
  if b_1 < 0:
      b_1 = - b_1
  if c_1 < 0:
      c_1 = - c_1
  for j in range(i+1, n):
    l = j + 1
    a = l - k
    b_2 = l - y
    c_2 = l - x
    if b_2 < 0:
      b_2 = - b_2
    if c_2 < 0:
      c_2 = - c_2
    b = b_1 + b_2 + 1
    c = c_1 + c_2 + 1
    if b < a:
      a = b
    if c < a:
      a = c
    ans[a-1] += 1
for i in range(n-1):
  print(ans[i])
### BUGGY CODE ###

from functools import lru_cache


n, tracks = list(map(int, input().split()))
loads = []
for _ in range(n):
    loads.append(int(input()))

# print(loads)
slices = []
min_load = [99999999999999]

@lru_cache()
def slicing(rest, s=0):
    if not rest:
        # slices.append(s+[(len(s) and s[-1][1], len(loads))])
        return sum(loads[s:])

    result = 99999999999999
    for s1 in range(s+1, len(loads)-rest+1):
        sub_total = sum(loads[s: s1])
        if sub_total > result:
            break
        result = min(result, max(sub_total, slicing(rest-1, s1)))
    return result


rs = slicing(tracks-1)
print(rs)
# print(slices)


# def load_count_max(load):
#     print(load, max(sum(loads[l[0]: l[1]]) for l in load))
    # return max(sum(loads[l[0]: l[1]]) for l in load)


# result = min(map(load_count_max, slices))
# print(result)



### FIXED CODE ###

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


def check(p):
    i = 0
    for j in range(k):
        s = 0
        while s + T[i] <= p:
            s += T[i]
            i += 1
            if i == n:
                return n
    return i


def solve():
    left = 0
    right = 100000 * 10000
    while right - left > 1:
        mid = (left + right) // 2
        v = check(mid)
        if v >= n:
            right = mid
        else:
            left = mid
    return right


T = []
for _ in range(n):
    T.append(int(input()))
ans = solve()
print(ans)
### BUGGY CODE ###

from math import gcd
from functools import reduce

def func(a,b,c):
  if a == b and b == c:
    return a
  elif a == b and b !=c:
    return gcd(a,c)
  elif a != b and b ==c:
    return gcd(a,b)
  else:
    return reduce(gcd,(a,b,c))

k = int(input())
li = []
for a in range(1,k+1):
  for b in range(1,k+1):
    for c in range(1,k+1):
      li.append(func(a,b,c))

print(sum(li))

### FIXED CODE ###

from math import gcd
from functools import reduce

def func(a,b,c):
  if a == b and b == c:
    return a
  elif a == b and b !=c:
    return gcd(a,c)
  elif a != b and b ==c:
    return gcd(a,b)
  else:
    return reduce(gcd,(a,b,c))

k = int(input())
li = []
for a in range(1,k+1):
  for b in range(1,k+1):
    for c in range(1,k+1):
      li.append(func(a,b,c))

print(sum(li))
### BUGGY CODE ###

h, n = map(int, input().split())
magics = []
for _ in range(n):
    a, b = map(int, input().split())
    magics.append((a,b))

mins = [10**10]*(h+1)
mins[0] = 0
ind = 0
while ind < h:
    for a, b in magics:
        target = min(h, ind+a)
        mins[target] = min(b + mins[ind], mins[target])
    ind += 1
    while True:
        if mins[ind] < 10**10 and min(mins[ind:])==mins[ind]:
            break
        ind += 1
print(mins[h])


### FIXED CODE ###

h, n = map(int, input().split())
dp = [10**10]*(h+1)
dp[0] = 0
ab = []
for _ in range(n):
    a, b = map(int, input().split())
    ab.append((a, b))

for a, b in ab:
    for start in range(h):
        end = min(start+a, h)
        dp[end] = min(dp[end], dp[start]+b)
print(dp[h])
### BUGGY CODE ###

from heapq import heappush, heappop

N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
ans = 0
heap = []
heappush(heap, (-A[0]*2, 0, 0))
checked = set()
checked.add((0, 0))
for i in range(M):
    power, x, y = heappop(heap)
    ans -= power
    if x+1 < N and (x+1, y) not in checked:
        heappush(heap, (-(A[x+1]+A[y]), x+1, y))
        checked.add((x+1, y))
    if y+1 < N and (x, y+1) not in checked:
        heappush(heap, (-(A[x]+A[y+1]), x, y+1))
        checked.add((x, y+1))
print(ans)


### FIXED CODE ###

from itertools import accumulate
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
lb = 0
ub = 2*10**5+1
while ub - lb > 1:
    m = (lb + ub) // 2
    cnt = 0
    s, t = 0, N-1
    while t >= 0:
        while s < N and A[s] + A[t] >= m:
            s += 1
        cnt += s
        t -= 1

    if cnt >= M:
        lb = m
    else:
        ub = m

accum = list(accumulate([0] + A))
ans = 0
cnt = 0
s, t = 0, N-1
while t >= 0:
    while s < N and A[s] + A[t] >= lb:
        s += 1
    ans += accum[s] + s * A[t]
    cnt += s
    t -= 1
print(ans - (cnt-M) * lb)
### BUGGY CODE ###

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

ans = 1
for i in A_list:
    ans *= i

if ans > 10**18:
    print(-1)
else:
    print(ans)

### FIXED CODE ###

import math

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

ans = 1
is_zero = False
is_over = False
for i in A_list:
    if i == 0:
        is_zero = True
        break
    if ans > 10**18:
        is_over = True

    if is_over:
        pass
    else:
        ans *= i

if is_zero:
    print(0)
elif is_over or ans > 10**18:
    print(-1)
else:
    print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
from heapq import heappush, heappop
def min_cost_flow_dijkstra(E, s, t, f):
    INF = 1 << 100
    NN = 2 * N + 6
    LN = NN.bit_length()
    G = [[] for _ in range(NN)]
    for a, b, cap, c in E:
        G[a].append([b, cap, c, len(G[b])])
        G[b].append([a, 0, -c, len(G[a])-1])
    prevv = [-1] * NN
    preve = [-1] * NN
    res = 0
    h = [0] * NN
    Q = []
    while f > 0:
        dist = [INF] * NN
        dist[s] = 0
        update = 1
        heappush(Q, s)
        while len(Q):
            x = heappop(Q)
            d, v = -(x>>LN), x % (1<<LN)
            if dist[v] < d: continue
            for i, (w, _cap, c, r) in enumerate(G[v]):
                if _cap > 0 and dist[w] > dist[v] + c + h[v] - h[w]:
                    dist[w] = dist[v] + c + h[v] - h[w]
                    prevv[w] = v
                    preve[w] = i
                    heappush(Q, (-dist[w] << LN) + w)
        if dist[t] == INF:
            return -1
        d = f
        v = t
        while v != s:
            d = min(d, G[prevv[v]][preve[v]][1])
            v = prevv[v]
        f -= d
        res += d * dist[t]
        v = t
        while v != s:
            G[prevv[v]][preve[v]][1] -= d
            G[v][G[prevv[v]][preve[v]][3]][1] += d
            v = prevv[v]
    return res

E = []
N = int(input())
su = 0
inf = 1 << 31
for i in range(N):
    x, y, cnt = map(int, input().split())
    E.append((2*N+4, i, cnt, 0))
    E.append((i, 2*N, cnt, x + y + inf))
    E.append((i, 2*N+1, cnt, x - y + inf))
    E.append((i, 2*N+2, cnt, - x + y + inf))
    E.append((i, 2*N+3, cnt, - x - y + inf))
    su += cnt

for i in range(N):
    x, y, cnt = map(int, input().split())
    E.append((i+N, 2*N+5, cnt, 0))
    E.append((2*N, i+N, cnt, - x - y + inf))
    E.append((2*N+1, i+N, cnt, - x + y + inf))
    E.append((2*N+2, i+N, cnt, x - y + inf))
    E.append((2*N+3, i+N, cnt, x + y + inf))

print(su * inf * 2 - min_cost_flow_dijkstra(E, 2*N+4, 2*N+5, su))

### FIXED CODE ###

from networkx import*
N = int(input())
G = MultiDiGraph()
for i in range(N):
    x, y, c = map(int, input().split())
    G.add_node(i, demand = -c)
    G.add_weighted_edges_from([(i, -1, x + y)], capacity = c)
    G.add_weighted_edges_from([(i, -2, x - y)], capacity = c)
    G.add_weighted_edges_from([(i, -3, -x + y)], capacity = c)
    G.add_weighted_edges_from([(i, -4, -x - y)], capacity = c)
for i in range(N):
    x, y, c = map(int, input().split())
    G.add_node(N + i, demand = c)
    G.add_weighted_edges_from([(-1, N + i, -x - y)], capacity = c)
    G.add_weighted_edges_from([(-2, N + i, -x + y)], capacity = c)
    G.add_weighted_edges_from([(-3, N + i, x - y)], capacity = c)
    G.add_weighted_edges_from([(-4, N + i, x + y)], capacity = c)

print(-min_cost_flow_cost(G))
### BUGGY CODE ###

N = int(input())
dic = 'abcdefghijklmnopqrstuvwxyz'

save = []
cnt = 0
for i in range(N):
    s = input()
    l = []
    for j in range(len(dic)):
        l.append(s.count(dic[j]))
    for k in range(len(save)):
        if save[k] == l:
            cnt += 1
    save.append(l)

print(cnt)

### FIXED CODE ###

N = int(input())

def nume(x):
    return x*(x-1)/2-(x-1)

save = []

for i in range(N):
    s = ''.join(sorted(input()))
    save.append(s)

save.sort()

cnt = 0
serial = 1
for i in range(N-1):
    if save[i] == save[i+1]:
        cnt += 1
        serial += 1
    else:
        cnt += int(nume(serial))
        serial = 1

cnt += int(nume(serial))
print(cnt)
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
a.append(0)

for i in range(n):
    ans = 0
    s = 0
    for j in range(n+1):
        if j != i:
            ans += abs(s-a[j])
            s = a[j]
    print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
a = [0] + a + [0]

s = 0

for i in range(n+1):
    s += abs(a[i]-a[i+1])

for i in range(n):
    print(s+abs(a[i]-a[i+2])-(abs(a[i]-a[i+1])+abs(a[i+1]-a[i+2])))
### BUGGY CODE ###

import sys
import numpy as np
readline = sys.stdin.buffer.readline

N,K = map(int,readline().split())
people = np.array(readline().split(),np.int64)
food = np.array(readline().split(),np.int64)
 
people.sort()
food.sort()
food=food[::-1]

#2分探索　Kの値で
_max = 10**12
_min = 0

while _max>_min:
  mean = (_max+_min)//2
  # 各人が修行をする回数の配列　負の値もでる
  K_arr = np.maximum(0,people - mean//food)
  # 総修行回数
  _K = sum(K_arr)
  if _K > K:
    _min = mean+1
  else:
    _max = mean
    
print(_max)
  

### FIXED CODE ###

import sys
import numpy as np
readline = sys.stdin.buffer.readline

N,K = map(int,readline().split())
people = np.array(readline().split(),np.int64)
food = np.array(readline().split(),np.int64)
 
people.sort()
food.sort()
food=food[::-1]

#2分探索　Kの値で
_max = max(people)*max(food)
_min = 0

while _max>_min:
  mean = (_max+_min)//2
  # 各人が修行をする回数の配列　負の値もでる
  _K = np.maximum(0,people - mean//food).sum()
  if _K > K:
    _min = mean+1
  else:
    _max = mean
    
print(_max)
### BUGGY CODE ###

import copy
S = input()
s = len(S)
MOD = 10**9+7
D = [0]*13
S = S[::-1]
for i in range(s):
    if i==0:
        if S[i]=="?":
            for j in range(10):
                D[j]+=1
        else:
            D[int(S[i])]+=1
    else:
        P = copy.copy(D)
        if S[i]=="?":
            p = 10**i
            for j in range(1,10):
                q = (j*p)%13
                for k in range(13):
                    D[(k+q)%13] += P[k]
            continue
        else:
            p = int(S[i])*(10**i)
            D = P[13-p%13:]+P[:13-p%13]
print(D[5]%MOD)

### FIXED CODE ###

MOD = pow(10,9)+7
S = input()[::-1]
N = len(S)

DP = [[0]*13 for i in range(N)]
K = 1
for i in range(N):
    if S[i]=="?":
        for j in range(10):
            if i==0:
                DP[0][(j*K)%13] = 1
            else:
                for k in range(13):
                    DP[i][(j*K+k)%13] += DP[i-1][k]
    else:
        j = int(S[i])*K
        if i==0:
            DP[0][(j*K)%13] = 1
        else:
            for k in range(13):
                DP[i][(j+k)%13] += DP[i-1][k]
    K = (K*10)%13
    for j in range(13):
        DP[i][j] = DP[i][j]%MOD
print(DP[N-1][5]%MOD)
### BUGGY CODE ###

n = int(input())
h = [int(i) for i in input().split()] # input:"1 2 3 4 5"
ans = 0
for i in range(n-1):
  for j in range(i,n-1):
    delta = h[j]-h[i]
    if h[j+1]+1<h[i]:
        ans = 1
        break
    elif h[j+1]+1==h[i]:
        h[i]-=1
        break
if ans == 1:
  print('No')
elif sorted(h)==h:
  print('Yes')
else:
  print('No')


### FIXED CODE ###

n = int(input())
h = [int(i) for i in input().split()] # input:"1 2 3 4 5"

#2019/08/08とき直し
#次のマスの高さを１高くすることができるようにする
ans = 'Yes'
for i in range(n-1):
  if h[i]>h[i+1]+1:
    ans = 'No'
    break
  elif h[i]==h[i+1]+1:
    h[i+1]+=1
print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(2*10**6)
input = sys.stdin.readline
N, M = map(int, input().split())
G = [[] for _ in [0]*N]
for _ in [0]*M:
    a, b, d = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append((b, d))
    G[b].append((a, -d))

X = [None]*N

def dfs(i, x=0):
    for j, d in G[i]:
        if X[j] is None:
            X[j] = x+d
            dfs(j, x+d)
        elif X[j] != x+d:
            print('No')
            exit()

for i in range(N):
    if X[i] is not None:
        continue
    X[i] = 0
    dfs(i)
print('Yes')

### FIXED CODE ###

import sys
sys.setrecursionlimit(2*10**6)
input = sys.stdin.readline
N, M = map(int, input().split())
G = [[] for _ in [0]*N]
for _ in [0]*M:
    a, b, d = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append((b, d))
    G[b].append((a, -d))

X = [None]*N

def dfs(i, x=0):
    for j, d in G[i]:
        if X[j] is None:
            X[j] = x+d
            dfs(j, x+d)
        elif X[j] != x+d:
            print('No')
            exit()

for i in range(N):
    if X[i] is not None:
        continue
    X[i] = 0
    dfs(i)
print('Yes')
### BUGGY CODE ###

def numS(S):
    x=len(S)
    if x<4:
        return 0
    T=S[1:]
   # print(T)
    l=x-1
    sum=0
    now=S[0]
    for i in range(l):
        now2=T[i]
    #    print(now2)
        if now2!=now:
            for j in range(i+1,l):
                now3=T[j]
     #           print(now,now2,now3)
                if now3!=now2 and now3!=now:
      #              print(i,j)
                    sum+=1
                    if 2*i+1==j:
                        sum-=1
    return numS(T)+sum
n=int(input())
S=input()
print(numS(S))

### FIXED CODE ###

n=int(input())
S=input()
R={}
G={}
B={}
r=0
g=0
b=0
for i in range(n):
    if S[i] == 'R':
        R[i] = None
    elif S[i] == 'G':
        G[i] = None
    else:
        B[i] = None
cnt=len(R)*len(G)*len(B)
for b in B:
    for g in G:
        if (b+g)/2 in R:
            cnt-=1
for b in B:
    for r in R:
        if (b+r)/2 in G:
            cnt-=1
for r in R:
    for g in G:
        if (r+g)/2 in B:
            cnt-=1
print(cnt)
### BUGGY CODE ###

m,n=map(int,input().split())
print(m**n%1000000007)


### FIXED CODE ###

m,n=map(int,input().split())
print(pow(m,n,1000000007))
### BUGGY CODE ###

n,k = map(int, input().split())
h = list(map(int, input().split()))
a = [0]*n
if k > n:
    k = n
for i in range(1,n):
    a[i] = float('inf')
    for j in range(1,min(k+1,i+1)):
        a[i] = min(a[i], a[i-j] + abs(h[i]-h[i-j]) )
print(a[n-1])

### FIXED CODE ###

import numpy as np
n,k = map(int, input().split())
h = np.array(list(map(int, input().split())))

dp = np.zeros(n, dtype = int)
for i in range(1,n):
    s = max(0,i-k)
    dp[i] = min(dp[s:i] + np.abs(h[i] -h[s:i]))
print(dp[-1])
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import sys

N,Q=map(int, sys.stdin.readline().split())
s=raw_input()
q=[ sys.stdin.readline().split()  for i in range(Q) ]


M={}	#文字毎の場所のインデックス

for i,x in enumerate(s):
	if x not in M:
		M[x]=[i]
	else:
		M[x].append(i)

G=[ 1 for i in range(N) ]  #各マスのゴーレムの数

ans=0

for l,r in q:
	if l not in M: continue
	for x in M[l]:
		if r=="L":
			if x-1==-1:
				ans+=G[0]
				G[x]=0
			else:
				G[x-1]+=G[x]
				G[x]=0
		elif r=="R":
			if x+1==N:
				ans+=G[N-1]
				G[x]=0
			else:
				G[x+1]+=G[x]
				G[x]=0

print N-ans


### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys

N,Q=map(int, sys.stdin.readline().split())
s=raw_input()
q=[ sys.stdin.readline().split()  for i in range(Q) ]

def leftout(cur):
	for x,y in q:
		if s[cur]==x:
			if y=="L":
				cur-=1
			elif y=="R":
				cur+=1
		if cur<0:
			return True
			break
		elif cur>N-1:
			return False
			break			

	else:
		return False


def rightout(cur):
	for x,y in q:
		if s[cur]==x:
			if y=="L":
				cur-=1
			elif y=="R":
				cur+=1
		if cur>N-1:
			return True
			break
		if cur<0:
			return False
			break
	else:
		return False


l=-1
r=N
while r-l!=1:
	m=(l+r)/2
	if leftout(m):
		l=m
	else:
		r=m
sl=l

l=-1
r=N
while r-l!=1:
	m=(l+r)/2
	if rightout(m):
		r=m
	else:
		l=m

sr=r


ans=N
if sl>=0:
	ans-=(sl+1)
if sr<N:
	ans-=(N-sr)

print ans
### BUGGY CODE ###

#bit全探索する
INF = 5000

def dp(n, medichine, Ma, Mb):
    INF =  5000
    if n == 0: #終端
        List = [[0, 0, 0], medichine[0]]
        if medichine[n][0] * Mb == medichine[n][1] * Ma:
            cost = medichine[0][2]
        else:
            cost = INF
    else: #n-1をもとにnについて計算
        previous = dp(n-1, medichine, Ma, Mb)
        List = previous[0][:]
        cost = previous[1]
        for x in previous[0]:
            A = x[0] + medichine[n][0]
            B = x[1] + medichine[n][1]
            C = x[2] + medichine[n][2]
            if C < cost:
                List.append([A, B, C])
                if A * Mb == B * Ma:
                    cost = C
        del previous
    return List, cost



N, Ma, Mb = map(int, input().split())
medichine = []
for _ in range(N):
    Lst = [int(x) for x in input().split()]
    medichine.append(Lst)
ans = dp(N-1, medichine, Ma, Mb)
cost = ans[1]
if cost != INF:
    print(cost)
else:
    print(-1)

### FIXED CODE ###

import collections
import copy
INF = 10000

#入力
N, Ma, Mb = map(int, input().split())
medichine = [tuple(map(int, input().split())) for _ in range(N)]

dp = {}
#dp初期化
dp = collections.defaultdict(lambda:INF)
dp[0,0] = 0

for a, b, c in medichine:
    dp_ = copy.copy(dp)
    for ca,cb in dp.keys():
        dp_[ca+a, cb+b] = min(dp_[ca+a, cb+b], dp[ca,cb]+c)
    dp = dp_    

ans = INF
for ca,cb in dp.keys():
    if ca == cb == 0: continue
    if ca*Mb == cb*Ma:
        ans = min(ans, dp[ca,cb])
        
print(-1 if ans == INF else ans)
### BUGGY CODE ###

# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product

def resolve():

    N=int(input())
    H=list(map(int,input().split()))
    def main():
        if N == 1:
            return 'Yes'
        for i in range(N-1):
            if i==N-2:
                return 'Yes'
            if H[i]<=min(H[i+1:])+1:
                continue
            else:
                return 'No'
    print(main())


resolve()

### FIXED CODE ###

# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product

def resolve():

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


resolve()
### BUGGY CODE ###

N=int(input())
ga,sa,ba=map(int,input().split())
gb,sb,bb=map(int,input().split())

donguri=N

inc=0
for i in range(0,donguri//ga+1):
    x=(ga<gb)*i
    for j in range(0,donguri//sa+1):
        y=(sa<sb)*j
        if donguri>=x*ga+y*sa:
            z=((donguri-x*ga-y*sa)//ba)*(ba<bb)
            inc=max(inc,x*(gb-ga)+y*(sb-sa)+z*(bb-ba))

donguri+=inc

inc=0
for i in range(0,donguri//gb+1):
    x=(ga>gb)*i
    for j in range(0,donguri//sb+1):
        y=(sa>sb)*j
        if donguri>=x*gb+y*sb:
            z=((donguri-x*gb-y*sb)//bb)*(ba>bb)
            inc=max(inc,-x*(gb-ga)-y*(sb-sa)-z*(bb-ba))

donguri+=inc
print(donguri)


### FIXED CODE ###

N=int(input())
ga,sa,ba=map(int,input().split())
gb,sb,bb=map(int,input().split())

check=(gb>ga)+(sb>sa)+(bb>ba)
if check==3:
    donguri=N

    inc=0
    for i in range(0,donguri//ga+1):
        x=(ga<gb)*i
        for j in range(0,donguri//sa+1):
            y=(sa<sb)*j
            if donguri>=x*ga+y*sa:
                z=((donguri-x*ga-y*sa)//ba)*(bb>ba)
                inc=max(inc,x*(gb-ga)+y*(sb-sa)+z*(bb-ba))

    donguri+=inc
    print(donguri)
elif check==0:
    donguri=N
    inc=0
    for i in range(0,donguri//gb+1):
        x=(ga>gb)*i
        for j in range(0,donguri//sb+1):
            y=(sa>sb)*j
            if donguri>=x*gb+y*sb:
                z=((donguri-x*gb-y*sb)//bb)*(ba>bb)
                inc=max(inc,-x*(gb-ga)-y*(sb-sa)-z*(bb-ba))

    donguri+=inc
    print(donguri)

elif check==2:
    donguri=N
    inc=0
    for i in range(0,donguri//ga+1):
        x=(ga<gb)*i
        for j in range(0,donguri//sa+1):
            y=(sa<sb)*j
            if donguri>=x*ga+y*sa:
                z=((donguri-x*ga-y*sa)//ba)*(bb>ba)
                inc=max(inc,x*(gb-ga)+y*(sb-sa)+z*(bb-ba))

    donguri+=inc
    if ga>gb:
        plus=(donguri//gb)*(ga-gb)
        print(donguri+plus)
    elif sa>sb:
        plus=(donguri//sb)*(sa-sb)
        print(donguri+plus)
    elif ba>bb:
        plus=(donguri//bb)*(ba-bb)
        print(donguri+plus)
    else:
        print(donguri)

else:
    donguri=N
    inc=0
    if ga<gb:
        plus=(donguri//ga)*(gb-ga)
        donguri+=plus
        if sa>sb:
            for i in range(0,donguri//sb+1):
                j=(donguri-i*sb)//bb
                inc=max(inc,i*(sa-sb)+j*(ba-bb))
            print(donguri+inc)
        else:
            inc=(donguri//bb)*(ba-bb)
            print(donguri+inc)

    elif sa<sb:
        plus=(donguri//sa)*(sb-sa)
        donguri+=plus
        if ga>gb:
            for i in range(0,donguri//gb+1):
                j=(donguri-i*gb)//bb
                inc=max(inc,i*(ga-gb)+j*(ba-bb))
            print(donguri+inc)
        else:
            inc=(donguri//bb)*(ba-bb)
            print(donguri+inc)
    else:
        plus=(donguri//ba)*(bb-ba)
        donguri+=plus
        if ga>gb:
            for i in range(0,donguri//gb+1):
                j=(donguri-i*gb)//sb
                inc=max(inc,i*(ga-gb)+j*(sa-sb))
            print(donguri+inc)
        else:
            inc=(donguri//sb)*(sa-sb)
            print(donguri+inc)