Problem:


Score : 300 points

Problem Statement

There is an integer sequence A of length N whose values are unknown.

Given is an integer sequence B of length N-1 which is known to satisfy the following:

 B_i \geq \max(A_i, A_{i+1}) 

Find the maximum possible sum of the elements of A.

Constraints

All values in input are integers.

2 \leq N \leq 100

0 \leq B_i \leq 10^5

Input

Input is given from Standard Input in the following format:

N
B_1 B_2 ... B_{N-1}

Output

Print the maximum possible sum of the elements of A.

Sample Input 1

3
2 5

Sample Output 1

9

A can be, for example, ( 2 , 1 , 5 ), ( -1 , -2 , -3 ), or ( 2 , 2 , 5 ). Among those candidates, A = ( 2 , 2 , 5 ) has the maximum possible sum.

Sample Input 2

2
3

Sample Output 2

6

Sample Input 3

6
0 153 10 10 23

Sample Output 3

53



Sample input:
3
2 5


Sample output:
9

Submission status: Accepted

Solution code:
# sys.stdin.readline
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N = int(input())
        B = list(map(int, input().split()))

        A = []
        for i in range(N):
            if i == 0:
                A.append(B[i])
            elif i == N - 1:
                A.append(B[i - 1])
            else:
                A.append(min(B[i - 1], B[i]))
        print(sum(A))


# Run main
if __name__ == '__main__':
    AtCoder().main()

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    b = list(map(int, input().split()))

    ans = 0
    for i in range(n-2):
        a = min(b[i], b[i + 1])
        ans += a
    print(ans + b[0] + b[-1])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N=int(input())
B=[0]+[int(x) for x in input().split()]+[0]
sum=0

for i in range(N):
    if i==0:
        sum+=B[i+1]
    elif i==N-1:
        sum+=B[i]
    else:
        sum+=min(B[i],B[i+1])

print(sum)

Submission status: Accepted

Solution code:
N = int(input())
B = list(map(int, input().split()))

if N == 2:
	print(B[0]*2)
elif N == 3:
	if B[0] < B[1]:
		print(B[0]*2 + B[1])
	else:
		print(B[0] + B[1]*2)
else:
	li = []
	for i in range(N-2):
		li.append(min(B[i],B[i+1]))
		
	
	print(B[0] + sum(li) + B[N-2])

Submission status: Accepted

Solution code:
n = int(input())
b = list(map(int, input().split()))
b.append(b[-1])
ans = b[0]
for i in range(1,n):
  ans += min(b[i-1],b[i])

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
b_list = [int(i) for i in input().split(' ')]

a_sum = 0
last_b = 10 ** 5 + 1
for b in b_list:
    i = b if b <= last_b else last_b 
    a_sum += i
    last_b = b
a_sum += b

print(a_sum)

Submission status: Accepted

Solution code:
from sys import stdout
printn = lambda x: stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
b = inl()
a = [0]*n
a[0] = b[0]
a[n-1] = b[n-2]
for i in range(1,n-1):
    a[i] = min(b[i-1],b[i])
print(sum(a))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
a = [0]*n
b = list(map(int, input().split()))

a[0]=b[0]
a[n-1]=b[n-2]
for i in range(0,n-2):
    a[i+1] = min(b[i],b[i+1])
    
print(sum(a))

Submission status: Accepted

Solution code:
n = int(input())
b =list(map(int, input().split()))

isum = b[0]

for i in range(1,n-1):
    isum += min(b[i-1],b[i])
isum += b[n-2]
print(isum)

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int,input().split()))
x.append(x[n-2])
res=[]
res.append(x[0])

for i in range(n-1):
	res.append(min(x[i],x[i+1]))

#print(res)
    
print(sum(res))

Submission status: Accepted

Solution code:
n = int(input())
b = list(map(int, input().split()))

a=b[0]
for i in range(n-2):
    a += min(b[i], b[i+1])

a += b[n-2]
print(a)

Submission status: Accepted

Solution code:
N = int(input())
A = [0]*N
B = list(map(int,input().split()))

A[0] = B[0]
A[-1] = B[-1]

for i in range(N-2):
    if B[i] > B[i+1]:
        A[i+1] = B[i+1]
    else:
        A[i+1] = B[i]
       
print(sum(A))

Submission status: Accepted

Solution code:
n=int(input())
b=list(map(int,input().split()))
ans=0
for i in range(n-1):
    if i==0:
        ans+=b[0]
    else :
        ans+=min(b[i],b[i-1])
ans+=b[n-2]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
B = [int(i) for i in input().split()]

A_sum = 0
for i in range(N):
    if i == 0:
        A_sum += B[i]
    elif i == N-1:
        A_sum += B[i-1]
    else:
        A_sum += min(B[i], B[i-1])
print(A_sum)

Submission status: Accepted

Solution code:
inpl = lambda: list(map(int,input().split()))
N = int(input())
B = inpl()
INF = 10**6
ans = 0
prev_b = INF
for b in B:
    ans += min(prev_b, b)
    prev_b = b
ans += prev_b
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
B = list(map(int, input().split()))

tot = B[0]+B[-1]
if N>2:
  for i in range(N-2):
    tot+=min([B[i], B[i+1]])

print(tot)

Submission status: Accepted

Solution code:
n = int(input())
b = list(map(int,input().split()))
a = [b[0]]
for i in range(1,n-1):
    a.append(min(b[i],b[i-1]))
a.append(b[n-2])
print(sum(a))

Submission status: Accepted

Solution code:
n = int(input())
b = list(map(int, input().split()))

ans = 0
ans += b[0]
for i in range(n-2):
    ans += min(b[i], b[i+1])

ans += b[n-2]

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
B = list(map(int, input().split()))
ans = 0

ans += B[-1]
for i in range(N - 2, 0,  -1):
    ans += min(B[i], B[i-1])
ans += B[0]

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 20 20:47:47 2019

@author: Owner
"""

import numpy as np
import sys
import collections
import scipy.misc
import math
from operator import itemgetter
import itertools
import copy
import bisect
import heapq

#素因数を並べる
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   
# 桁数を吐く
def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

def find_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        """
        x が属するグループを探索
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)

    def get_size(self, x):
        """
        x が属するグループの要素数
        """
        x = self.find(x)
        return self.size[x]
    

"""
N, X = map(int, input().split())

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

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())

# 多次元配列の宣言（あとでintにすること。）（タプルにすること。）
dp = np.zeros((N+1, 4,4,4))
    
all(nstr.count(c) for c in '753')

# 複数配列を並び替え
ABT = zip(A, B, totAB)
result = 0
# itemgetterには何番目の配列をキーにしたいか渡します
sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)

# 2進数のbit判定
(x >> i) & 1

# dp最小化問題
dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break
# 累積和
add = 1 # 問題によって決まる
res = 0
sums = [0]*(len(nums)+1)
for i in range(len(nums)):
    sums[i+1] = sums[i] + nums[i]
for i in range(0, len(nums), 2):
    left = i
    right = min(i+add, len(nums))
    tmp = sums[right] - sums[left]
    res = max(tmp, res)

#２分探索
li, ri = bisect.bisect_left(p_ac, l[i]-1), bisect.bisect_right(p_ac, r[i]-1)    

#ソート関数
org_list = [3, 1, 4, 5, 2]
new_list = sorted(org_list)
print(org_list)
print(new_list)
# [3, 1, 4, 5, 2]
# [1, 2, 3, 4, 5]

#Distance Transformation
    for h in range(0,H):
        for w in range(0,W):
            if h == 0 and w == 0:
                pass
            elif h == 0:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h-1][W-w]+1)
            elif w == 0:   
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1)
            else:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1, D[H-h-1][W-w]+1, D[H-h][W-w]+2)
            d_max = max(D[H-h-1][W-w-1], d_max)

"""


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

    
def main(): 
    res = B[-1]
    for n in range(N-2):
        res += min(B[-(n+1)], B[-(n+2)])
    res += B[0]
    print(res)
                
                
                
            
            
                

    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N=int(input())
B=list(map(int,input().split()))
if N==2:
    A=[B[0],B[0]]

else:
    
    A=[B[0]]
        
    for i in range(N-2):
        A.append(min(B[i],B[i+1]))

    A.append(max(A[N-2],B[N-2]))
print(sum(A))

Submission status: Accepted

Solution code:
n=int(input())
b = list(map(int,input().split()))
a = [0] * n
ans = 0
for i in range(n):
  if i == 0:
    ans += b[i]
  elif i == n -1:
    ans += b[i - 1]
  else:
    ans += min(b[i - 1],b[i])
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
B = list(map(int, input().split()))

A = [0] * N
A[0] = B[0]
#print(A[0])

for i in range(1,N-1):
  A[i] = min(B[i-1], B[i])
#  print(A[i])

A[N-1] = B[N-2]
#print(A)
print(sum(A))

Submission status: Accepted

Solution code:
n=int(input())
b=list(map(int,input().split()))
a=[b[0]]
for i in range(1,n-1):
    a.append(min(b[i],b[i-1]))
    #print(a)
a.append(b[-1])
print(sum(a))

Submission status: Accepted

Solution code:
n = int(input())
blist = list(map(int, input().split()))

alist = [-1 for i in range(n)]

alist[0] = blist[0]
alist[1] = blist[0]

for i in range(1,n):
    if alist[i-1] <= blist[i-1]:
        alist[i] = blist[i-1]
    else:
        alist[i-1] = blist[i-1]
        alist[i] = blist[i-1]

print(sum(alist))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
B_list = list(map(int, input().split()))

ans = 0
ans += B_list[0]
ans += B_list[-1]
for i in range(1, N - 1):
    ans += min(B_list[i - 1], B_list[i])
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
b = list(map(int, input().split()))

ans = b[0] + b[n-2]
for i in range(1, n-1):
  ans += min(b[i-1], b[i])

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
b = list(map(int, input().split()))
if n == 2:
    print(b[0]*2)
else:
    ans = b[0]
    for i in range(n-2):
        ans += min(b[i], b[i+1])
    print(ans+b[-1])

Submission status: Accepted

Solution code:
n = int(input())
B = list(map(int, input().split()))

ans = 0
ans += B[0]
ans += B[-1]
for i in range(n-2):
    ans += min(B[i], B[i+1])
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
ListB = [int(val) for val in input().split()]
sumA = ListB[0]
count = 1
while(count < n - 1):
	if (ListB[count - 1] < ListB[count]):
		sumA += ListB[count - 1]
	else:
		sumA += ListB[count]
	count += 1
sumA += ListB[n - 2]
print(sumA)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

N = int(input())
A = [0 for _ in range(N)]
B = list(map(int,input().split()))
A[0] = B[0]

for i in range(1, N - 1):
    A[i] = min(B[i - 1], B[i])
    
A[-1] = B[-1]

print(sum(A))

Submission status: Accepted

Solution code:
N = int(input())
B = list(map(int, input().split()))
A = [0]*N
for i in range(N):
  if i != 0 and i != (N-1):
  	A[i] = min(B[i-1], B[i])
  elif i == 0:
    A[i] = B[i]
  else:
    A[i] = B[i-1]
print(sum(A))

Submission status: Accepted

Solution code:
N = int(input())
B = list(map(int, input().split()))

a_sum = B[0] + B[-1]

for i in range(1, N-1):
    a_sum += min(B[i], B[i-1])

print(a_sum)

Submission status: Accepted

Solution code:
N=int(input())
B=list(map(int,input().split()))
A=B[0]
for i in range(N-2):
    C=min(B[i],B[i+1])
    A=A+C
A=A+B[N-2]
print(A)

Submission status: Accepted

Solution code:
n = int(input())

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

a = [0]
a[0] = b[0]
for i in range(1, n-1):
    cal = min(b[i - 1], b[i])
    a.append(cal)
a.append(b[-1])
print(sum(a))

Submission status: Accepted

Solution code:
N = int(input())
B = [int(s) for s in input().split()]

total = 0

for i in range(N):
  if i == 0:
    total += B[i]
  elif i <= N-1-1:
    total += min(B[i-1], B[i])
  else:
    total += B[i-1]
print(total)

Submission status: Accepted

Solution code:
n = int(input())
bls = list(map(int, input().split()))

als = []
for i in range(n-2):
  als.append(min(bls[i], bls[i+1]))
#print(als)
print(sum(als)+bls[0]+bls[n-2])

Submission status: Accepted

Solution code:
N=int(input())
B=list(map(int,input().split()))
ans=0
for i in range(1,N-1):
    ans+=min(B[i],B[i-1])
print(ans+B[0]+B[N-2])

Submission status: Accepted

Solution code:
n = int(input())
b = list(map(int,input().split()))

ans = 0
for i in range(n):
    if i == 0:
        ans += b[0]
    elif i <n-1:
        ans += min(b[i],b[i-1])
    else:
        ans += b[-1]

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
B = list(map(int, input().split()))
A = []
A.append(B[0])
for i in range(0,N-2):
    A.append(min(B[i],B[i+1]))
A.append(B[N-2])
print(sum(A))

Submission status: Accepted

Solution code:
N = int(input())
BX = list(map(int, input().split()))

AX = [0 for _ in range(N)]
AX[N-1] = BX[N-2]
AX[N-2] = BX[N-2]
for i in reversed(range(N - 2)):
    if BX[i] < BX[i+1]:
        AX[i+1] = BX[i]
    AX[i] = BX[i]
    
print(sum(AX))

Submission status: Accepted

Solution code:
N = int(input())
B = list(map(int, input().split()))

A = [0] * N
A[0] = B[0]

for ix in range(0, N-2):
    if B[ix] < B[ix+1]:
        A[ix+1] = B[ix]
    else:
        A[ix+1] = B[ix+1]

A[-1] = B[-1]

print(sum(A))

Submission status: Accepted

Solution code:
n = int(input())
b = list(map(int, input().split()))

if n == 2:
    ans = b[0] * 2
else:
    ans = b[0]
    for i in range(n - 2):
        ans += min(b[i], b[i + 1])
    ans += b[n - 2]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
B = list(map(int,input().split()))

exB = [B[0]]
exB.extend(B)
exB.extend([B[-1]])

A = [0 for i in range(len(exB)-1)]
for i in range(len(A)):
    A[i] = min(exB[i],exB[i+1])

# print(exB)
# print(A)
print(sum(A))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))[::-1]
ans = [a[0]]
for i in range(n-1):
	ans[i] = min(a[i], ans[i])
	ans.append(a[i])

print(sum(ans))

Submission status: Accepted

Solution code:
# 2019/09/07

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

ans=b[0]
for i in range(1,n-1):
    ans+=min(b[i-1],b[i])
ans+=b[-1]
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

a  = np.zeros(n)

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

print(int(sum(a)))

Submission status: Accepted

Solution code:
def c_maximal_value():
    N = int(input())
    B = [int(i) for i in input().split()]

    ans = B[0]
    for i in range(N - 2):
        if B[i] > B[i + 1]:
            ans += B[i + 1]
        else:
            ans += B[i]
    ans += B[-1]
    return ans

print(c_maximal_value())

Submission status: Accepted

Solution code:
N = int(input())
B = list(map(int,input().split()))

ans = 0
pre = B[N-2]
for i in range(N-2, -1, -1):
    ans += min(pre, B[i])
    pre = B[i]
print(ans+B[0])

Submission status: Accepted

Solution code:
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac

setrecursionlimit(1000000)


def main():
	n = int(input())
	b = list(map(int,input().split()))
	a = []
	a.append(b[0])
	for i in range(1,n-1):
		a.append(min(b[i],b[i-1]))
	a.append(b[-1])
	print(sum(a))

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(l):
	x = l.pop()
	y = l.pop()
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	l.append(min(x,y))
	return gcd(l) if len(l) > 1 else l[0]

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()

Submission status: Accepted

Solution code:
N = int(input())
B_list = list(map(int, input().split()))
ans = B_list[0]
for i in range(1, N-1):
    ans += min(B_list[i-1], B_list[i])
ans += B_list[N-2]

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
B = list(map(int, input().split()))

A = [0] * N
ans = B[0]
A[0] = B[0]
for n in range(1, N-1):
    if B[n] < B[n-1]:
        A[n] = B[n]
    else:
        A[n] = B[n-1]
    ans += A[n]
ans += B[-1]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
B = list(map(int, input().split()))
tot = B[0]+B[-1]
for i in range(n-2):
  tot += min(B[i], B[i+1])
print(tot)

Submission status: Accepted

Solution code:
n=int(input())
b= list(map(int, input().split())) 
ans=0
for i in range(n-2):
    ans+=min(b[i],b[i+1])
print(b[0]+b[n-2]+ans)

Submission status: Accepted

Solution code:
n = int(input())
b = list(map(int, input().split()))
b = b[::-1]
ans = b[0]
for i in range(1, n-1):
    if b[i] >= b[i-1]:
        ans += b[i-1]
    else:
        ans += b[i]
print(b[-1]+ans)

Submission status: Accepted

Solution code:
n = int(input())
B = list(map(int, input().split()))
print(B[0]+B[-1] + sum(min(B[i], B[i+1])for i in range(len(B)-1)))

Submission status: Accepted

Solution code:
N = int(input())
b = list(map(int,input().split()))
ans = b[-1]
for i in range(len(b)-1,0,-1):
    ans += min(b[i],b[i-1])
ans += b[0]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
b = [int(i) for i in input().split()]

a = [0] * n

a[0] = b[0]
a[n-1] = b[n-2]
for i in range(1, n - 1):
    a[i] = min(b[i-1], b[i])
print(sum(a))

Submission status: Accepted

Solution code:
n = int(input())
b = list(map(int, input().split()))
a = [b[0]]
if n==1:
    a.append(b[0])
    print(sum(a))
else:
    for i in range(1,n-1):
        a.append(min(b[i],b[i-1]))
    a.append(b[n-2])
    print(sum(a))

Submission status: Accepted

Solution code:
n = int(input())
b = list(map(int, input().split()))
a = []

a.append(b[0])

for i in range(n - 2):
    t = i + 1
    a.append(min(b[i], b[t]))

a.append(b[n - 2])

print(sum(a))

Submission status: Accepted

Solution code:
n = int(input())
b = list(map(int, input().split()))

s = 0
for i in range(n):
    if 0 < i < n-1:
        if b[i-1] < b[i]:
            s += b[i-1]
        else:
            s += b[i]
    elif i == 0:
        s += b[i]
    else:
        s += b[i-1]
print(s)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys;
import string;
sys.setrecursionlimit(20000) # 再起呼び出しの最大数をセット

import copy
import math
import itertools

from functools import lru_cache
#@lru_cache(maxsize = None)

PPP = 1000000007

# 一括読み
#N, K, *A = map(int, open(0).read().split())


# 整数の入力
n = int(input())

# スペース区切りの入力
#n, x = input().split()

# スペース区切りの整数の入力
#n, m = map(int, input().split())
#n, x = map(int, input().split())
#print("sp", n, k, file=sys.stderr)
#a = [int(x) for x in input().split()]
#b = [int(x) for x in input().split()]
#print("a", a, file=sys.stderr)
#p, q, r = map(int, input().split())
#s = [int(x) for x in input().split()]
#t = [int(x) for x in input().split()]

# 改行区切りの整数の入力
#a = []
#for x in range(n):
#  a.append(int(input()))
#  a.append([int(x) for x in input().split()])
#b = []
#for x in range(m):
#  b.append([int(x) for x in input().split()])
#p = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
#a.sort()
#print(l, file=sys.stderr)

# 文字列の入力
#s = input()

# 出力
#print("{} {}".format(a+b+c, s))
#a.sort()
#print(set(a), file=sys.stderr)
#print(len(set(a)))

#cache = dict()

import re
import fractions

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

def ton(n, k, x):
  s = ""
  while n > 0:
    s = str(n%k) + s
    n //= k
  return s


#print("a", a, file=sys.stderr)
#print("b", b, file=sys.stderr)

def getEnergy():
  for y in b:
    yield y

def doit():
  total = b[0] + b[n-2]
  prev = None
  for x in b:
    if not prev == None:
      total += min(prev, x)
    prev = x
  return total

def yn():
  if doit():
    return "Yes"
  else:
    return "No"

#print(doit([0] * 4))
#doit(a)
#print(doit())
try:
  #doit()
  print(doit())
  #print(yn())
except Exception as e:
  print("e", e, file=sys.stderr)

Submission status: Accepted

Solution code:
n=int(input())
a=[0]*n
INF=10**6
b=list(map(int,input().split()))+[INF]



for i in range(n):
  a[i]=min(b[i-1],b[i])

ans=sum(a)
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

N = int(input())

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

A = [0]*N

A[0] = B[0]
for i in range(1, N-1):
    A[i] = min(B[i-1], B[i])

A[N-1] = B[N-2]

print(sum(A))

Submission status: Accepted

Solution code:
N = int(input())
B = list(map(int, input().split()))

ans = B[0]
for i in range(N-2):
    ans += min(B[i], B[i+1])
else:
    ans += B[-1]

print(ans)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n = int(input())
    b = [int(i) for i in input().split()]

    sum = 0
    now = 0
    bf = 0
    for i in range(n):
        if i ==0:
            sum = sum + b[i]
        if i == n -1:
            sum = sum + b[i-1]
        else:
            if bf > b[i]:
                sum = sum +b[i]
            else:
                sum = sum +bf
            bf = b[i]
    print(sum)

Submission status: Accepted

Solution code:
n = int(input());
b = input().split(" ");

for i in range(n-1) :
	b[i] = int(b[i]);

ans = b[0];
for i in range(1,n-1) :
	ans += min([b[i-1],b[i]]);

ans += b[n-2];
print(ans);

Submission status: Accepted

Solution code:
N = int(input())
B = [1e9] + list(map(int, input().split())) + [1e9]

A = []

for i in range(N):
    A.append(min(B[i], B[i+1]))

print(sum(A))

Submission status: Accepted

Solution code:
N = int(input())
B = list(map(int, input().split()))

sum = B[0] + B[N - 2]
for i in range(1, N - 1):
    sum += min(B[i - 1], B[i])
print(sum)

Submission status: Accepted

Solution code:
N = int(input())
B = list(map(int, input().split()))

ans = B[0] + B[-1]
for i in range(1, N-1):
    ans += min(B[i-1], B[i])
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
b=list(map(int,input().split()))
a=[]
a.append(b[0])
for i in range(n-2):
  if b[i]>b[i+1]:
    a.append(b[i+1])
  else:
    a.append(b[i])
a.append(b[-1])
print(sum(a))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

ans=B[0]
for i in range(1,N-1):
    ans+=min(B[i],B[i-1])
ans+=B[N-2]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
B = [ int(x) for x in input().split() ]

ans = B[0]
for i in range(N-1):
  if i < N-2: ans += min(B[i], B[i+1])
  else: ans += B[i]

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
b = list(map(int, input().split()))
a = [0]*n
a[0] = b[0]
for i in range(n-2):
    a[i+1] = min(b[i], b[i+1])
a[-1] = b[-1]
ans = sum(a)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
B = list(map(int,input().split()))

A = []
A.append(B[0])
for n in range(1,N-1):
  A.append(min(B[n-1],B[n])) 
A.append(B[N-2])
#print(A)
print(sum(A))

Submission status: Accepted

Solution code:
n = int(input())
b = list(map(int, input().split()))

a = 0
for i in range(n-1):
    if i == 0:
        a += b[i]
    else:
        a += min(b[i-1], b[i])
a += b[-1]
print(a)

Submission status: Accepted

Solution code:
while True:
    try:
        N = int(input())
        B = list(map(int, input().split()))
        A = [2**31] * N
        
        A[0] = B[0]
        for i in range(1, N-1):
            A[i] = min(B[i-1], B[i])
            
        A[N-1] = B[N-2]
        #print(A)
        print(sum(A))
    except:
        break

Submission status: Accepted

Solution code:
N = int(input())
B = list(map(int, input().split()))

ans = B[-1] + B[0]
temp = B[-1]

for i in range(N-3, -1, -1):
    ans += min(temp, B[i])
    temp = B[i]

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
b = list(map(int, input().split()))

a = [0]*n
a[-1] = b[-1]
tmp1 = b.pop()
for i in range(n-2,-1,-1):
  if i == 0:
    a[i] = tmp1
  else:
    tmp2 = b.pop()
    a[i] = min(tmp1, tmp2)
    tmp1 = tmp2
print(sum(a))

Submission status: Accepted

Solution code:
N = int(input())
B = [int(i) for i in input().split()]

A = [0] * N
for _ in range(N - 1):
    idx = B.index(max(B))
    A[idx] = A[idx + 1] = B[idx]
    B[idx] = -1
print(sum(A))

Submission status: Accepted

Solution code:
N = int(input())
b = [int(i) for i in input().split()]

a = [b[0]]
for i in range(1,N-1):
    a.append(min(b[i-1], b[i]))

a.append(b[-1])

print(sum(a))

Submission status: Accepted

Solution code:
n=int(input())
bn=list(map(int,input().split()[:n-1]))
an=[0]*n
for i in range(n-1):
    if i==0:
        an[0]=bn[0]
        an[1]=bn[0]
    else:
        if an[i] >= bn[i]:
            an[i]=bn[i]
        an[i+1]=bn[i]

print(sum(an))

Submission status: Accepted

Solution code:
n=int(input())
b=list(map(int,input().split()))
ans=b[0]
for i in range(n-2):
  ans+=min(b[i],b[i+1])
ans+=b[n-2]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

sum_ = 0

for i in range(N):
    if i == 0:
        sum_ += B[0]
    elif i == N - 1:
        sum_ += B[-1]
    else:
        sum_ += min(B[i - 1], B[i])

print(sum_)

Submission status: Accepted

Solution code:
n = int(input()) 
b = list(map(int, input().split()))
s  = b[0]
if n == 2:
    s = 2 * b[0]
else:
    for i in range(1, n - 1):
        s += min(b[i - 1], b[i])
    s += b[-1]
print(s)

Submission status: Accepted

Solution code:
N = int(input())
B = list(map(int, input().split()))

ans = B[0]
buff = []
for i in range(N-2):
    ans += min(B[i],B[i+1])
    buff.append(min(B[i],B[i+1]))

buff.append(B[-1])
ans += B[-1]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
b = list(map(int, input().split()))

a = [0 for i in range(n)]

a[0] = b[0]
for i in range(1,n):
    if i!=len(b):
        a[i] = min(b[i-1],b[i])
    else:
        a[i] = b[i-1]
print(sum(a))

Submission status: Accepted

Solution code:
N = int(input())
B = list(map(int, input().split()))
A = [1001001001] * N
for i in range(len(B)):
  A[i] = min(A[i], B[i])
  A[i+1] = min(A[i+1], B[i])
print(sum(A))

Submission status: Accepted

Solution code:
n = int(input())
b = list(map(int, input().split()))

ans = b[0]
for i in range(0, n-2):
    ans += min(b[i], b[i+1])
ans += b[n-2]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
b = list(map(int, input().split()))
a = []
a.append(b[0])

for i in range(1, n-1):
    a.append(min(b[i-1], b[i]))

a.append(b[-1])

print(sum(a))

Submission status: Accepted

Solution code:
n = int(input())
b = list(map(int, input().split()))

a = [0]*n

#print(*a)
#print(*b)

a[0] = b[0]

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

print(sum(a))

Submission status: Accepted

Solution code:
#!/usr/bin/env python

import sys

n=int(sys.stdin.readline())
b=[ int(x) for x in sys.stdin.readline().split() ]
b= [b[0]] + b + [b[-1]]
c=0
for i in range(1,n+1):
    c+= min(b[i-1],b[i])
print( c )

Submission status: Accepted

Solution code:
N = int(input())
B = list(map(int,input().split()))
B.append(B[N-2])
B.append(B[N-2])
A = [B[0]]
for i in range(1,N):
    A.append(min(B[i],B[i-1]))
print(sum(A))

Submission status: Accepted

Solution code:
n = int(input())
b = [int(x) for x in input().split()]
ans = [b[0]]
for i in range(1,n-1):
    ans.append(min(b[i],b[i-1]))
print(sum(ans)+b[-1])

Submission status: Accepted

Solution code:
N = int(input())
B = [int(x) for x in input().split()]

answer = 0

for i in range(len(B)):                                                                                                                                                                                     
    if i == 0:                                                                                                                                                                                              
        answer += B[i]                                                                                                                                                                                      
                                                                                                                                                                                                            
    else:                                                                                                                                                                                                   
        answer += min(B[i-1], B[i])                                                                                                                                                                         

answer += B[len(B)-1]
print(answer)

Submission status: Accepted

Solution code:
N = int(input())
B = list(map(int, input().split()))

A = [B[0]]
for i in range(N-2):
    a = min(B[i], B[i+1])
    A.append(a)
A.append(B[N-2])
print(sum(A))

Submission status: Accepted

Solution code:
n=int(input())
B=list(map(int,input().split()))

ans=[B[0]]
for i in range(n-1):
  if ans[-1]>B[i]:
    ans[-1]=B[i]
  ans.append(B[i])
print(sum(ans))