Ziota found a video game called "Monster Invaders".

Similar to every other shooting RPG game, "Monster Invaders" involves killing monsters and bosses with guns.

For the sake of simplicity, we only consider two different types of monsters and three different types of guns.

Namely, the two types of monsters are:   a normal monster with $1$ hp.  a boss with $2$ hp. 

And the three types of guns are:   Pistol, deals $1$ hp in damage to one monster, $r_1$ reloading time  Laser gun, deals $1$ hp in damage to all the monsters in the current level (including the boss), $r_2$ reloading time  AWP, instantly kills any monster, $r_3$ reloading time 

The guns are initially not loaded, and the Ziota can only reload 1 gun at a time.

The levels of the game can be considered as an array $a_1, a_2, \ldots, a_n$, in which the $i$-th stage has $a_i$ normal monsters and 1 boss. Due to the nature of the game, Ziota cannot use the Pistol (the first type of gun) or AWP (the third type of gun) to shoot the boss before killing all of the $a_i$ normal monsters.

If Ziota damages the boss but does not kill it immediately, he is forced to move out of the current level to an arbitrary adjacent level (adjacent levels of level $i$ $(1 < i < n)$ are levels $i - 1$ and $i + 1$, the only adjacent level of level $1$ is level $2$, the only adjacent level of level $n$ is level $n - 1$). Ziota can also choose to move to an adjacent level at any time. Each move between adjacent levels are managed by portals with $d$ teleportation time.

In order not to disrupt the space-time continuum within the game, it is strictly forbidden to reload or shoot monsters during teleportation. 

Ziota starts the game at level 1. The objective of the game is rather simple, to kill all the bosses in all the levels. He is curious about the minimum time to finish the game (assuming it takes no time to shoot the monsters with a loaded gun and Ziota has infinite ammo on all the three guns). Please help him find this value.


-----Input-----

The first line of the input contains five integers separated by single spaces: $n$ $(2 \le n \le 10^6)$ — the number of stages, $r_1, r_2, r_3$ $(1 \le r_1 \le r_2 \le r_3 \le 10^9)$ — the reload time of the three guns respectively, $d$ $(1 \le d \le 10^9)$ — the time of moving between adjacent levels.

The second line of the input contains $n$ integers separated by single spaces $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 10^6, 1 \le i \le n)$.


-----Output-----

Print one integer, the minimum time to finish the game.


-----Examples-----
Input
4 1 3 4 3
3 2 5 1

Output
34
Input
4 2 4 4 1
4 5 1 2

Output
31


-----Note-----

In the first test case, the optimal strategy is:  Use the pistol to kill three normal monsters and AWP to kill the boss (Total time $1\cdot3+4=7$)  Move to stage two (Total time $7+3=10$)  Use the pistol twice and AWP to kill the boss (Total time $10+1\cdot2+4=16$)  Move to stage three (Total time $16+3=19$)  Use the laser gun and forced to move to either stage four or two, here we move to stage four (Total time $19+3+3=25$)  Use the pistol once, use AWP to kill the boss (Total time $25+1\cdot1+4=30$)  Move back to stage three (Total time $30+3=33$)  Kill the boss at stage three with the pistol (Total time $33+1=34$) 

Note that here, we do not finish at level $n$, but when all the bosses are killed.

Difficulty: competition

Starter code:

Solutions:
n,r1,r2,r3,D = map(int,input().split())

state = [0,0] # after odd number of 2 (1st), or not (2nd)

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

# First element

# Choosing P~P + A

state[0] = r1 * a[0] + r3

# Choosing L + P later or all P

state[1] = min(r2 + r1 + D, r1 * (a[0] + 2) + D)

# Second to Second Last element

for i in range(1,n-1):
    newState = [-1,-1]
    newState[0] = min(state[1] + D + r1 * a[i] + r3, state[0] + r1 * a[i] + r3,
                        state[1] + r2 + r1 + D, state[1] + r1 * (a[i] + 2) + D)
    newState[1] = min(state[0] + r2 + r1 + D, state[0] + r1 * (a[i] + 2) + D)
    state = newState

# Last Element

ans = min(state[0] + r1 * a[-1] + r3, state[0] + 2 * D + r2 + r1, state[0] + 2 * D + r1 * (a[-1] + 2),
            state[1] + r1 * a[-1] + r3, state[1] + r2 + r1 + D, state[1] + r1 * (a[-1] + 2) + D)

print(ans + D * (n-1))

n,r1,r2,r3,d=map(int,input().split())
a=list(map(int,input().split()))
if 2*r1<r3:
  save=[r3-2*r1]*n
else:
  save=[0]*n
for i in range(n):
  save[i]=max(save[i],a[i]*r1+r3-r2-r1)
ans=(n-1)*d+sum(a)*r1+n*r3
dp=[0,0]
for i in range(n):
  dp0=dp[1]
  dp1=dp[1]
  if i+1<n and save[i]+save[i+1]>2*d:
    dp1=max(dp1,dp[0]+save[i]+save[i+1]-2*d)
  if i==n-1:
    dp1=max(dp1,dp[0]+save[i]-2*d)
  if i==n-2:
    dp0=max(dp0,dp[0]+save[i]-d)
  dp1=max(dp1,dp0)
  dp=[dp0,dp1]
print(ans-max(dp0,dp1))

import sys

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return list(map(int, minp().split()))

def solve():
	n, r1, r2, r3, d = mints()
	s = min(r1,r3)
	r2s = r2 + s
	a = list(mints())
	dp = [1<<63]*n#[[int(9e18)]*n for i in range(3)]
	dp[n-1] = min(s*a[n-1] + r3, d*2 + min(r2s, s*(a[n-1]+2)))
	#print(s*a[n-2] + r3 + d + dp[n-1], min(r2s, s*(a[n-1]+2)) + min(r2s, s*(a[n-2]+2)) + d*3, min(r2s, s*(a[n-2]+2)) + d + s*a[n-1] + r3 + d)
	dp[n-2] = min(s*a[n-2] + r3 + d + dp[n-1], min(r2s, s*(a[n-1]+2)) + min(r2s, s*(a[n-2]+2)) + d*3)
	dp[n-2] = min(dp[n-2], min(r2s, s*(a[n-2] + 2)) + d + s*a[n-1] + r3 + d)
	for i in range(n-3,-1,-1):
		dd = s*a[i] + r3 + d + dp[i+1]
		x = min(s*a[i] + r3, min(r2s, s*(a[i]+2))) + min(s*a[i+1] + r3, min(r2s, s*(a[i+1]+2)))
		#print(dd, x + dp[i+2] + d*4)
		dp[i] = min(dd, x + dp[i+2] + d*4)
	#print(dp)
	print(dp[0])

solve()


import sys
readline = sys.stdin.readline

INF = 10**18
N, r1, r2, r3, d = map(int, readline().split())
A = list(map(int, readline().split()))

dp1 = [INF]*(N+1)
dp2 = [INF]*(N+1)
dp1[0] = -d
dp2 = -d

mj = INF
rr = r1+r2

C = [0]*(N+1)
for i in range(N):
    a = A[i]
    C[i+1] = min(rr, (a+2)*r1)
CC = C[:]
for i in range(1, N+1):
    CC[i] += CC[i-1]
for i in range(1, N+1):
    a = A[i-1]
    dp1[i] = dp2 + d + C[i]
    dp2 = min(dp2+d+r1*a+r3, CC[i] + 3*d*i + mj)
    mj = min(mj, dp1[i]-3*i*d-CC[i])

ans = min(dp2, 2*d + dp1[-1])
ans = min(ans, dp1[N-1] + 3*d + C[N])
zz = min(r1*A[-1]+r3, 2*d+min(rr, (A[-1]+2)*r1))

for i in range(1, N):
    ans = min(ans, dp1[i] + 2*(N-i)*d + zz + CC[N-1] - CC[i])

print(ans)

import sys
input = sys.stdin.readline

n,r1,r2,r3,d=list(map(int,input().split()))
A=list(map(int,input().split()))

DP=[1<<60]*n
DP2=[1<<60]*n
DP.append(0)
DP.append(0)

for i in range(n):
    DP[i]=min(DP[i],DP[i-1]+r1*A[i]+r3+d)

    if i>=1:
        DP2[i]=min(DP2[i],DP[i-2]+min(r1*(A[i-1]+1),r2)+min(r1*(A[i]+1),r2)+r1*2+d*4)
        DP2[i]=min(DP2[i],DP2[i-1]+min(r1*(A[i]+1),r2)+r1+d*3)
        
        DP[i]=min(DP[i],DP2[i])

ANS=DP[n-1]-d

last=r1*A[n-1]+r3

for i in range(1,n):
    last+=d*2
    last+=min(r1*(A[n-1-i]+1),r2)+r1

    ANS=min(ANS,DP[n-2-i]+last)

print(ANS)