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:
# -*- coding: utf-8 -*-
import sys

import fractions
import copy
import bisect
import math
import numpy as np
import itertools
from itertools import combinations_with_replacement
#import math#数学的計算はこれでいける。普通に0.5乗しても計算可能
#w=input()
from operator import itemgetter
from sys import stdin
#input = sys.stdin.readline#こっちの方が入力が早いが使える時に使っていこう
from operator import mul
from functools import reduce
from collections import Counter
#from collections import deque

#input = stdin.readline


j=0
k=0
n=3
r=1
a=[0]
#n=int(input())
#r=int(input())
#print(M)
#A=int(input())
#B=int(input())
#print(N)
"1行1つの整数を入力を取得し、整数と取得する"


#number_list=list(map(int, input().split(" ")))#数字の時
#print(number_list)
"12 21 332 とか入力する時に使う"
"1行に複数の整数の入力を取得し、整数として扱う"

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#メモ
for i in number_list:#こっちの方がrage使うより早いらしい
    print(number_list[i-1])#

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'''
x=[]
y=[]
for i in range(N):
    x1, y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
print(x)
print(y)
"複数行に2数値を入力する形式 x座標とy座標を入力するイメージ"
'''

'''
mixlist=[]
for i in range(N):
    a,b=input().split()
    mixlist.append((int(a),b))
print(mixlist)
"複数行にintとstrを複合して入力するやつ，今回はリスト一つで処理している"
'''

'''
#array=[input().split()for i in range(N)]
#print(type(array[0][0]))
#print(array)
"正方行列にstr型の値を入力"
'''

#brray=[list(map(int, input().split(" ")))for i in range(N)]
#print(type(brray[0][0]))
#print(brray)
'''
入力
1 2
4 5
7 8
出力結果
[[1, 2], [4, 5], [7, 8]]
'''
"列数に関して自由度の高いint型の値を入力するタイプの行列"
#以下に別解を記載
#N, M = [int(i) for i in input().split()]
'''
table = [[int(i) for i in input().split()] for m in range(m)]

print(type(N))
print(N)
print(type(M))
print(M)

print(type(table))
print(table)
'''




#s=input()
#a=[int(i) for i in s]
#print(a[0])
#print([a])
#単数値．桁ごとに分割したい．入力と出力は以下の通り
#イメージとして1桁ごとにリストに値を入れているかんじ
#intを取ると文字列分解に使える
'''
入力
1234
出力
1
[[1, 2, 3, 4]]
'''




'''
word_list= input().split(" ")
print(word_list[0])
"連続文字列の入力"
"qw er ty とかの入力に使う"
"入力すると空白で区切ったところでlistの番号が与えられる"
'''



'''
A, B, C=stdin.readline().rstrip().split()#str style 何個でもいけることが多い
print(A)
"リストではなく独立したstr型を入れるなら以下のやり方でOK"
'''


#a= stdin.readline().rstrip()
#print(a.upper())
"aという変数に入っているものを大文字にして出力"


#a,b=map(int, input().split())  #int style 複数数値入力　「A B」みたいなスペース空いた入力のとき

#なんかうまく入力されるけど
#a=[[int(i) for i in 1.strip()]for 1 in sys.stdin]
#a = [[int(c) for c in l.strip()] for l in sys.stdin]]
#print(a)
#複数行の数値を入力して正方行列を作成


##############################################################################################
##############################################################################################
#under this line explains example calculation



'''
コンビネーションの組み合わせの中身を出力する形式
for i in itertools.combinations(brray, 2)
combinationsをpermutationsにすれば順列になる
今回なら(abc133B)
入力
1 2
5 5
-2 8
出力
[[1, 2], [5, 5], [-2, 8]]
もちろん一次元リストでも使えるし
何よりiもリストのように使えるので便利
'''

#nCr combination
'''
def cmb(n,r):
    #When n < r , this function isn't valid
    r= min(n-r,r)
    #print(n,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n-r, -1))
    #flochart mul(n,n-1)=x
    #next     mul(x,n-2)........(n-r+1,n-r)
    #mul read a,b and returns a*b

    under = reduce(mul, range(1, r+1))
    #print(over, under)
    #reduce is applied mul(1,2)=2
    #next   mul(2,3)=6
    #next   mul(6,4)=4.........last(r!,r+1)=r+1!

    return over // under
    #// is integer divide
    #calc example 5C2
    #over=5*4*3
    #under=3*2*1
a = cmb(n, r)
#print(a)
'''

'''
import itertools
from itertools import combinations_with_replacement

combinationについて
以下の違いを意識しよう
combinations() p, r 長さrのタプル列、ソートされた順で重複なし

combinations_with_replacement() p, r 長さrのタプル列、ソートされた順で重複あり


使用例 　　　　　　　　　　　                  出力　　
combinations('ABCD', 2)　　　　　　　　　　　　AB AC AD BC BD CD

combinations_with_replacement('ABCD', 2)　　 AA AB AC AD BB BC BD CC CD DD
'''



'''
#集計
#example
#a=[2,2,2,3,4,3,1,2,1,3,1,2,1,2,2,1,2,1]
#a=Counter(a)
for i in a.most_common(n):print(i)
#most_common()メソッドは、出現回数が多い要素順にCounterオブジェクトを並び替えます。
#引数にint型の数字nを設定した場合は、出現回数が高い上位ｎ個の要素を返します。
#何も設定しなければ、コンテナ型にあるすべての要素を出現回数の順番に並び替えたタプル型オブジェクトを返します。
#out put
#(2, 8)
 #(1, 6)
#(3, 3)
#(4, 1)
'''


#二部探索(binary search)
#A = [1, 2, 3, 3, 3, 4, 4, 6, 6, 6, 6]
#print(A)
#index = bisect.bisect_left(A, 5) # 7 最も左(前)の挿入箇所が返ってきている
#A.insert(index, 5)
#print(index)
#print(A)
'''
bisect.bisect_left(a, x, lo=0, h=len(a))
引数
a: ソート済みリスト
x: 挿入したい値
lo: 探索範囲の下限
hi: 探索範囲の上限
(lo, hiはスライスと同様の指定方法)
bisect_leftはソートされたリストaに対して順序を保ったままxを挿入できる箇所を探索します。leftが示す通り、aにすでにxが存在している場合は、挿入箇所は既存のxよりも左側になります。また、lo, hiを指定することで探索範囲を絞り込むことも可能です。デフォルトはaの全体が探索対象です。
'''

'''
素数の判定
'''


def is_prime(n):
    if n == 1: return False

    for k in range(2, int(np.sqrt(n)) + 1):
        #sqrt(n)+1以上は考えて約数はないので却下
        if n % k == 0:
            return False
            #割り切れたらFalse
    return True


'''
npのmaxとmaximumの違い
xs = np.array([1, -2, 3])
np.max(xs, 0)
この出力は3となります．[1, -2, 3]と0の4つの数字のうち，最も大きい値を出力します．

一方で，[max(1, 0), max(-2, 0), max(3, 0)]を出力したい時があります．
その時は，numpyのmaximum関数を用います．

xs = np.array([1, -2, 3])
np.maximum(xs, 0)  # [1, 0, 3]

'''



########################################################################
########################################################################
#b2=a[:]  #1次元のときはコピーはこれで良い
#print(b2)

#a= [[0]*3 for i in range(5)] #2次元配列はこう準備、[[0]*3]*5だとだめ
#b3=copy.deepcopy(a)  #2次元配列はこうコピーする
#print(b3)

def main():

    w=1
    j=0
    k=0
    n=int(input())
    bl=list(map(int, input().split(" ")))#数字の時
    al=[]
    al.append(bl[0])
    for i in range(n-2):
        #print(min(bl[i-1],bl[i]))
        al.append(min(bl[i],bl[i+1]))
    al.append(bl[n-2])
    print(sum(al))
    #dp= [[0]*3 for i in range(5)]#列　行
    #dp用の0の入ったやつ
    #dp= [[0]*(w+1) for i in range(n+1)]#0からwまでのw+1回計算するから
    #print(dp)＃初期条件が入る分計算回数+1列分必要(この場合は判断すべきものの数)
    DP = np.zeros(w+1, dtype=int)#これでも一次元リストが作れる
    exdp=np.zeros((3,4)) # ３×４の２次元配列を生成。2次元ならこう
    #dtypeは指定しないとfloatになる
    #for i in range(n):#ちょっとした入力に便利
    #    a, b = map(int, input().split())
        #dp[i][0] += [a]
        #これだとintとlistをつなぐことになって不適
    #    dp[i] += [a]
    #    dp[i] += [b]
        #これはうまくいく
        #やり方はいろいろあるということ
    #print(dp)


    "1行1つの整数を入力を取得し、整数と取得する"
    #number_list=list(map(int, input().split(" ")))#数字の時
    #print(number_list)
    "12 21 332 とか入力する時に使う"
    "1行に複数の整数の入力を取得し、整数として扱う"
    #brray=[list(map(int, input().split(" ")))for i in range(N)]
    #print(type(brray[0][0]))
    #print(brray)


    #s=input()
    #a=[int(i) for i in s]#int取るとstrでも行ける
    #print(a)
    '''
    入力
    1234
    出力
    [1, 2, 3, 4]
    '''
    ls = ["a", "b", "c", "d", "e"]


    #print(ls[2:5])
    #スライスでの取得

    #print(ls[:-3])
    #一番左端から右から3番目より左まで取得

    #print(ls[:4:2])
    #スライスで1個飛ばしで取得
    #ないときは左端スタート
    #始点のインデックス番号 : 終点のインデックス番号 : スキップする数+1
    #print(ls[::2])
    '''
    lsというリストの場合に、1つ飛びの値を取得したい場合には
    ls[::2]
    のようにします。こうすると、
    ["a", "c", "d"]と出力される
    '''

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

print(sum(A))

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())
B = list(map(int, input().split()))
A = [0]*n
A[0] = B[0]
A[n-1] = B[n-2]
for i in list(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()))

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

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

n=int(input())
binf=10**6
b=[binf]+list(map(int,input().split()))+[binf]

asum=0
for i in range(len(b)-1):
    ai=min(b[i],b[i+1])
    asum+=ai
    
print(asum)

Submission status: Accepted

Solution code:
from sys import stdin
import math
import fractions

n = int(stdin.readline().rstrip())
b = [int(x) for x in stdin.readline().rstrip().split()]


result = 0
for i in range(len(b)):
    if i == 0:
        result += b[i]
        continue
    result += min(b[i-1], b[i])

result += b[i]

print(result)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    B = list(map(int, input().split()))
    
    if N == 2:
        print(B[0] * 2)
        return

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    B = [int(x) for x in input().split()]
    A = [0] * N
    A[0] = B[0]
    A[N-1] = B[-1]
    for i in range(1, N-1):
        if B[i - 1] <= B[i]:
            A[i] = B[i - 1]
        else:
            A[i] = B[i]
    print(sum(A))


if __name__ == "__main__":
    main()

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(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]+B[n-2]
for i in range(n-2):
    ans += min(B[i],B[i+1])
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
B = [int(b) for b in input().split()]
ans = B[0] + B[N-2]
for i in range(N-2):
    ans += min(B[i], B[i+1])
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(N-2):
  ans += min(B[i],B[i+1])
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
B = list(map(int, input().split()))
A = [float('inf')]*N
for i in range(N-1):
  b = B[i]
  A[i] = min(A[i], b)
  A[i+1] = b

print(sum(A))

Submission status: Accepted

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

ANS.append(b[n-2])
print(sum(ANS))

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 - 1], b[i]))

a.append(b[-1])

print(sum(a))

Submission status: Accepted

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

C = [None] * N
C[0] = B[0]
C[-1] = B[-1]

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

print(sum(C))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(total)

Submission status: Accepted

Solution code:

N = int(input())
B = [10**5 + 1] + list(map(int, input().split())) + [10**5 + 1]
s = 0

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

print(s)

Submission status: Accepted

Solution code:
ii = lambda:int(input())
mi = lambda:list(map(int,input().split()))
iix = lambda x:list(int(input()) for _ in range(x))
mix = lambda x:list(li() for _ in range(x))
##########
def main(n,b):
    a = [0]*n
    a[0] = b[0]
    a[-1] = b[-1]
    for i in range(1,n-1):
        a[i] = min(b[i-1],b[i])
    print(sum(a))

n = ii()
b = mi()
main(n,b)

Submission status: Accepted

Solution code:
import sys
import math
from collections import Counter
import itertools
import fractions
#from functools import reduce

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")

# ###########################################
 
N=II()
B=LI()

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


print(su)

Submission status: Accepted

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

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

C = [None] * N
C[0] = B[0]
C[-1] = B[-1]

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

print(sum(C))

Submission status: Accepted

Solution code:
N = int(input())
B = list(map(int,input().split())) + [1]
A = [0 for _ in range(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()))
ans = 0
for i in range(n):
    if i == 0:
        ans += b[0]
    elif i == n-1:
        ans += b[-1]
    else:
        ans += min(b[-1+i],b[i])
print(ans)

Submission status: Accepted

Solution code:
n,*b=map(int,open(0).read().split())
a=[b[0]]*n
for i in range(1,n-1):
  a[i]=min(b[i],b[i-1])
a[-1]=b[-1]
print(sum(a))

Submission status: Accepted

Solution code:
N = int(input())
B = [int(x) for x in input().split()]
A = []
count = 0
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[N-2])
print(sum(A))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

A = [None] * N
A[0] = B[0]
for i in range(1, N):
    A[i] = B[i - 1]
for i in range(N - 1):
    if B[i] < max(A[i],A[i + 1]):
        A[i] = B[i]
ans = sum(A)
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(n-2):
    if b[i] < b[i+1]:
        ans += b[i]
    else:
        ans += b[i + 1]
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
bs=list(map(int,input().split()))
a=[10**5]*n
for i,b in enumerate(bs):
    a[i+1]=b
    if a[i]>b:
        a[i]=b
print(sum(a))

Submission status: Accepted

Solution code:
N=int(input())
B=[int(i) for i in input().split()]
DP=[10**9 for i in range(N)]
for t in range(N-1):
    if DP[t]>B[t]:
        DP[t]=B[t]
    if DP[t+1]>B[t]:
        DP[t+1]=B[t]
print(sum(DP))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
b = list(map(int,input().split()))
ans = b[0]+b[-1]

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

Submission status: Accepted

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

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()))

ans = 0
for i in range(n):
    if i == 0:
        ans += B[0]
    elif i == n - 1:
        ans += B[n - 2]
    else:
        ans += min(B[i - 1], B[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(0,N-2):
    ans+=min(B[i],B[i+1])
print(ans)

Submission status: Accepted

Solution code:
a=input()
b=input().split()
sum=int(b[0])

for i in range(len(b)-1) :
  sum+=min(int(b[i]),int(b[i+1]))
sum+=int(b[-1])

print(sum)

Submission status: Accepted

Solution code:
n = int(input())
B = list(map(int,input().split()))
A = [B[0],B[-1]]

for i in range(n-2):
    A.append(min(B[i:i+2]))
    
print(sum(A))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
B = list(map(int,input().split()))
cnt=0
cnt+=B[0]
for i in range(len(B)-1):
    if B[i]<= B[i+1]:
        cnt+=B[i]
    elif B[i]> B[i+1]:
        cnt+=B[i+1]
cnt += B[-1]
print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
B = list(map(int, input().split()))
A = [0]*N
for a in range(1,N-1):
    A[a] = min(B[a-1], B[a])



print(sum(A) + B[0] + B[N-2])

Submission status: Accepted

Solution code:
import os

def main():
	n = int(input())
	b_list = list(map(int, input().split()))
	result_list = [b_list[0]]*2
	for i in range(len(b_list)):
		if b_list[i] >= max(result_list[i],result_list[i+1]):
			pass
		else:
			result_list[i] = b_list[i]
		if i < len(b_list) - 1: 
			result_list.append(b_list[i+1])
	print(sum(result_list))

if __name__ == "__main__":
	main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
b = [int(i) for i in input().split()] + [1000000]
ret = b[0]
for i, v in enumerate(b[:-1]):
	ret += min(v, b[i + 1])
print (ret)

Submission status: Accepted

Solution code:
n = int(input())
aaa = {}
bbb = list(map(int, input().split(' ')))
bbb.append(999999999999)
for i in range(n-1, -1, -1):
    aaa[i] = min(bbb[i], bbb[i-1])
print(sum([aaa[i] for i in range(n)]))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
N = int(input())
B = [int(s) for s in input().split()]

A = [0] * N

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

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

print(sum(A))

Submission status: Accepted

Solution code:
import os, sys, re, math

N = int(input())
B = [int(n) for n in input().split()]

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

Submission status: Accepted

Solution code:
n = int(input())
b = list(map(int, input().split()))
inf = 10000000
print(sum(min(b1, b2) for b1, b2 in zip(b + [inf], [inf] + b)))

Submission status: Accepted

Solution code:
n = int(input())
nums = [int(i) for i in input().split()]
nums = [nums[0]] + nums + [nums[-1]]
ans = 0

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

Submission status: Accepted

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

# print(a)
print(sum(a))

Submission status: Accepted

Solution code:
def main(arrayB: list):
    arrayB.reverse()
    arrayA = [arrayB[0]]
    for i in range(len(arrayB)):
        arrayA.append(
            min(arrayB[i], arrayB[i + 1]) if i < len(arrayB) - 1 else arrayB[i]
        )
    print(sum(arrayA))


N = int(input())
line = list(map(int, input().split()))
main(line)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

S[-1]=b[-1]
print(sum(S))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))

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], b[i-1])
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
b = list(map(int,input().split(" ")))
a = []
for i in range(n):#0,1,2
    if i == 0:
        a.append(b[0])
        # print(a)
        # print("1こめ")
    if i > 0 and i < n-1:
        c = min([b[i],b[i-1]])
        a.append(c)
        # print(a)
        # print("2こめ")
    if i == n-1:
        a.append(b[n-2])
        # print(a)
        # print("3こめ")
print(sum(a))

Submission status: Accepted

Solution code:
n=int(input())

l1=list(map(int,input().split()))
l2=[l1[0]]
l=l2+l1
l.append(l1[-1])

res=[]

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

print(sum(res))

Submission status: Accepted

Solution code:
import sys
n = int(input())
b = [int(i) for i in input().split()]
if n == 2:
    print(b[0] * 2)
    sys.exit()

total = 0
for i, j in enumerate(b):
    if i == 0:
        total = j
    else:
        total += min(b[i-1], b[i])
print(total + b[-1])

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], B[i - 1])

print(ans)

Submission status: Accepted

Solution code:
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import numpy as np
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def FLI(): return [int(i) for i in input().split()]
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

n = I()
B = LI()

A = [0] * n

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

A[0] = B[0]
A[n-1] = B[n-2]
print(sum(A))

Submission status: Accepted

Solution code:
n = int(input())
list_b = list(map(int,input().split()))
b_len = len(list_b)
ans_list = [0]*n
ans_list[0] = list_b[0]
dum = 0
for i in range(1,b_len):
    dum = min(list_b[i-1],list_b[i])
    ans_list[i] = dum
ans_list[n-1] = list_b[b_len-1]
#print(ans_list)
print(sum(ans_list))

Submission status: Accepted

Solution code:
n = int(input())
b = list(map(int, 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()))

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

print(ans)

Submission status: Accepted

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

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

print(sum(a))

Submission status: Accepted

Solution code:
import sys
import os
import math
import string

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    B = il()
    ret = B[len(B) - 1] + B[0]
    for n in range(N - 2):
        ret += min(B[n+1], B[n])
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
import itertools

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

res=b[0] + b[n-2]

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

print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import itertools

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

a=[0] * n 

for i in range(n):

    if(i==0):
        a[i] =b[i]
    elif(i==n-1):
        a[i] = b[i-1]
    else:
        a[i] = min(b[i],b[i-1])

print(sum(a))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#入力
N = int(input())
B = list(map(int,input().split()))
A = [None for _ in range(N)]
#A最初の要素は最大でB最初の要素の値しかとれない
A[0] = B[0]
#中間に関してはAで大きい要素値を取ってしまうと2つのBに影響が出てしまう。
#よって隣り合ううち小さい方を取る
for i in range(1,N-1):
  A[i] = min(B[i-1],B[i])
#A最後の要素は最大でB最後の要素の値しか取れない
A[N-1] = B[N-2]
#結果
print(sum(A))

Submission status: Accepted

Solution code:
N = int(input())
B = list(map(int,input().split()))
A = [None for _ in range(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())-1
A =list(map(int,input().split()))
cnt = 0
for i in range(1,n):
    cnt += min(A[i-1],A[i])
print(cnt+A[0]+A[-1])

Submission status: Accepted

Solution code:
n = int(input())
B = list(map(int,input().split()))
A = [0]*n
A[0] = B[0]
A[n-1] = B[n-2]
for i in range(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()))
ans=0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:


n = int(input())

B = [int(x) for x in input().split()]

A = [0] * n
A[0] = B[0]
A[n - 1] = B[n - 2]

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

print(sum(A))

Submission status: Accepted

Solution code:
N = int(input())
Bs = list(map(int, input().split()))
diff = 0
for i in range(N-2):
    if Bs[i] > Bs[i+1]:
        diff += Bs[i]-Bs[i+1]
print(sum(Bs) - diff + Bs[0])

Submission status: Accepted

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

a=[]
a.append(b[0])
a.append(b[n-2])
for i in range(n-2):
  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()))

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 = 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()))
ret = B[0]
a = B[0]
for i in range(N-2):
  a = min(B[i],B[i+1])
  ret += a
ret += B[N-2]
print(ret)