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

s = b[0]

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().strip().split()))
A=[1000000] * (N)

for i in range(N-1):
  if B[i] < A[i]:
    A[i] = B[i]
    A[i+1] = B[i]
  else:
    A[i+1] = B[i]
A_sum=0
for x in A:
  A_sum+=x
print(A_sum)

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])
sum=0
for i in range(n):
	sum+=a[i]
print(sum)

Submission status: Accepted

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

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:
n = int(input())
a = list(map(int, input().split()))
ans  = a[0] + a[-1]
for i in range(n-2):
    ans += min(a[i] , a[i+1])
print(ans)

Submission status: Accepted

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

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

print(sum(a))

Submission status: Accepted

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

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

Submission status: Accepted

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

c =[]

c.append(b[0])

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

c.append(b[n-2])

print(sum(c))

Submission status: Accepted

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

a_sum += b[0]

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

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

Submission status: Accepted

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

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

for i in range(0, 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()))

a = []
a.append(b[0])

for i in range(1, n-1):
  if b[i-1] <= b[i]:
    a.append(b[i-1])
  elif b[i-1] > b[i]:
    a.append(b[i])
a.append(b[-1])
print(sum(a))

Submission status: Accepted

Solution code:
N = int(input())
B = list(map(int, input().split()))
score = 0
score += B[0] + B[len(B)-1]

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

print(score)

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

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

a = [b[0],b[0]]

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

print(sum(a))

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:
n = int(input())

numbers = [int(i) for i in input().split()]
res = 0

for i in range(n):
    res += min(numbers[max(i-1, 0)], numbers[min(i, n-2)])

print(res)

Submission status: Accepted

Solution code:
#140c
N = int(input())
list_A = []
list_B = list(map(int, input().split()))

#長さ N の値の分からない整数列 Aがあります。
#長さ N−1の整数列 Bが与えられます。このとき、
#   Bi≥max(Ai,Ai+1)
#が成立することが分かっています。
#Aの要素の総和として考えられる値の最大値を求めてください。

#N 6
#A 200 200 10 10  5  5
#B 200 300 10 10  5

temp_A = list_B[0]
ans = temp_A

for i in range(1,N-1):
    #print(i,":",temp_A,",",list_B[i])
    if temp_A > list_B[i]:
        temp_A = list_B[i]
        ans += temp_A
    else: #temp_A <= list_B[i]:
        ans += temp_A
        temp_A = list_B[i]

ans += list_B[-1]
        
print(ans)

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:
        A[0] = B[0]
    elif i < N - 1:
        A[i] = min(B[i], B[i - 1])
    else:
        A[i] = B[i - 1]

print(sum(A))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
B = list(map(int, input().split()))
num = B[0] + B[N-2]

for cnt in range(N-2):
  if B[cnt] < B[cnt+1]:
    num += B[cnt]
  else:
    num += B[cnt+1]

print(num)

Submission status: Accepted

Solution code:
N = int(input())
B = [int(i) for i in 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:
n = int(input())
b = list(map(int, input().split()))

b.append(100010)
a = 0
a += b[0]

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


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


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    B = [ int(next(tokens)) for _ in range(N-1) ]  # type: "List[int]"
    solve(N, B)

if __name__ == '__main__':
    main()

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

Submission status: Accepted

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

A = [0 for _ in range(N)]

# A[0] = B[0]
for i in range(N-1):
    # とりあえず両方入れる
    A[i] = B[i]
    A[i+1] = B[i]

    # 上書きされた結果条件を満たさないなら書き換える
    if i >= 1:
        if A[i] > B[i-1]:
            A[i] = B[i-1]

print(sum(A))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())

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

ans = 0
tmp_b = 0

tmp_b = B[0]
for b in B:
    max_a = min(tmp_b,b)
    ans += max_a 
    tmp_b = b

max_a = B[-1]
ans += max_a

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(1, n-1):
    a += min(b[i-1], b[i])

print(a)

Submission status: Accepted

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

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

print(a)

Submission status: Accepted

Solution code:
N = int(input())
B = [int(i) for i in 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()))

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

print(max_val)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

a = list()
ans = 0
a.append(b[0])

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

a.append(b[-1])

for i in range(n):
  ans += a[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(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())
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:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

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

B.append(float('inf'))
A.append(B[0])

for i in range(1, N):
    A.append( 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
a.insert(0,b[0])
for i in range(n-1):
    if b[i]>b[i+1]:
        a[i]=b[i+1]
print(sum(a))

Submission status: Accepted

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

# B_i >= max(A_i, A_i+1)

# sumA = A_1 + A_2 + ... + A_N
# 求めたいのは sumA の max

# B_i >= max(A_i, A_i+1)
# B_i+1 >= max(A_i+1, A_i+2)
# A_i+1 <= min(B_i, B_i+1)

As = [0] * N
As[0] = Bs[0]
As[N-1] = Bs[N-2] 

for i in range(N-2):
  As[i+1] = min(Bs[i], Bs[i+1])
  
#print(As)
print(sum(As))

Submission status: Accepted

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

mx = 0

for i in range(len(B)):

    if i==0 :

        if len(B)==1 :

            mx += B[0]*2

        else:

            if B[i] > B[i+1]:

                mx += B[i]+B[i+1]

            else:

                mx += B[i]*2

    elif i>0 :

        if i != len(B)-1:

            if B[i] < B[i+1]:

                mx += B[i]

            elif B[i] >= B[i+1]:

                mx += B[i+1]

        elif i == len(B)-1:

            mx += B[i]

print(mx)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
B_array = list(map(int, input().split()))
A_array = [0] * N
A_array[0] = B_array[0]
for i in range(N-1):
    A_array[i+1] = B_array[i]
    if B_array[i] <= A_array[i]:
        A_array[i] = B_array[i]
print(sum(A_array))

Submission status: Accepted

Solution code:
n = int(input())
b = list(map(int, input().split()))
arr = []
tmp = b[0]
for i, num in enumerate(b):
    if tmp <= num:
        arr.append(tmp)
    else:
        arr.append(num)
    tmp = num
arr.append(b[-1])
print(sum(arr))

Submission status: Accepted

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

A = [0]*N
A[0] = B[0]
for n in range(1,N-1):
    A[n] = min(B[n],B[n-1])
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.append(min(B[i], B[i + 1]))
ans.append(B[-1])

print(sum(ans))

Submission status: Accepted

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

b.append(b[n-2])
b.append(0)
s = 0

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

s += b[0]
print(s)

Submission status: Accepted

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


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

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

    print(result)


if __name__ == "__main__":
    main()

Submission status: Accepted

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


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

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

    print(result)


if __name__ == "__main__":
    main()

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

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_A = 0

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

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N = I()
    B = LI()
    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], B[i-1])
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# https://atcoder.jp/contests/abc139/tasks/abc139_c
# 整数の入力
n = int(input())
b = list(map(int, input().split()))
a = [b[0], b[0]]
for i in range(1, n-1):
    a.append(b[i])
    if b[i] < b[i-1]:
        a[i] = b[i]
print("{}".format(sum(a)))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# https://atcoder.jp/contests/abc139/tasks/abc139_c
# 整数の入力
n = int(input())
b = list(map(int, input().split()))
a = [b[0], b[0]]
for i in range(1, n-1):
    if b[i] > b[i-1]:
        a.append(b[i])
    else:
        a.append(b[i])
        a[i] = b[i]
print("{}".format(sum(a)))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque
def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math

n = getN()
INF = 100000000000
nums = [INF] + getList() + [INF]
ans = 0
for i, j in zip(nums, nums[1:]):
    ans += min(i, j)

print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
B = [int(_) for _ in stdin.readline().rstrip().split()]
A = [0 for i in range(N)]
A[0] = B[0]
A[-1] = B[-1]
for i in range(1, N-1):
    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()))

ans=[0]*n
ans[0]=b[0]
ans[n-1]=b[-1]

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

Submission status: Accepted

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

list_A = [0]*n

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

print(sum(list_A))

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    a = int(input())
    li_1 = list(map(int, input().split()))
    res = []
    for x in range(0, a - 1):
        if x == 0:
            res.append(li_1[x])
        else:
            res.append(min(li_1[x], li_1[x - 1]))
res.append(li_1[-1])
result = 0
for x in res:
    result += x

print(result)

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

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(ans + b[0] + b[n - 2])

Submission status: Accepted

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

A = 0
for i in range(N-1):
    if i == 0:
        A += B_list[0]
    else:
        A += min(B_list[i-1],B_list[i])

A += B_list[N-2]
print(A)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

N = int(input())
b_arr = list(map(lambda b: int(b), input().split()))
a_arr = list(range(N))

for n in range(N-1, -1, -1):
    if (n == N-1) or (n == N-2):
        a_arr[N-1] = b_arr[N-2]
        a_arr[N-2] = b_arr[N-2]
    elif b_arr[n+1] >= b_arr[n]:
        a_arr[n+1] = b_arr[n]
        a_arr[n] = b_arr[n]
    else:
        a_arr[n] = b_arr[n]

print(sum(a_arr))

Submission status: Accepted

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

a = [10**6] * n

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

print(sum(a))

Submission status: Accepted

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

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

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

print(x)

Submission status: Accepted

Solution code:
n = int(input())
b = [int(i) for i in input().split()]
if n == 2:
	ans = 2 * b[0]
else:
	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:
def solve(string):
    n, *b = map(int, string.split())
    b.append(b[-1])
    return str(b[0] + sum([min(b0, b1) for b0, b1 in zip(b, b[1:])]))


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
B_list = [int(i) for i in input().split()]
A_list = [10000000] * N

for i in range(len(B_list)) :
    B = B_list[i]
    if (min(B,A_list[i]) == B) :
        A_list[i] = B
    
    A_list[i+1] = B

# print(A_list)
print(sum(A_list))

Submission status: Accepted

Solution code:
# import pandas as pd
# import numpy as np

# d = pd.read_csv("useful.csv", usecols = ["Q133", "Q134", "Q146"])

# #l = d["Q133"]
# l = d["Q146"]
# bad = []
# good = [] 
# for i in range(1, 56):
# 	if int(l[i][0]) >= 4:
# 		good.append(i)
# 	else:
# 		bad.append(i)
# print(bad, good)

import sys
input = sys.stdin.readline

n = int(input())
b = list(map(int, input().split()))
a = [0 for _ in range(n)]
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=[]
A.append(B[0])

for i in range(1, N-1):
  a=min(B[i-1], B[i])
  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] + 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())
Bi = [int(i) for i in input().split(" ")]

res_A = []
Bi = [float('inf')] + Bi + [float('inf')]
for i in range(N):
  res_A += [min(Bi[i], Bi[i+1])]
print(sum(res_A))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())

b = list(map(int,input().split()))
ans = 0
b_max = b[-1]
tmp = b[-1]
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:
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:
N=int(input())
B=list(map(int,input().split()))
sum=B[0]
for i in range(len(B)-1):
  sum+=min(B[i],B[i+1])
sum+=B[-1]
print(sum)

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

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
b = list(li())
b = [b[0]] + b + [b[-1]]

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, B: "List[int]"):
    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))
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    B = [int(next(tokens)) for _ in range(N - 1)]  # type: "List[int]"
    solve(N, B)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

if n==2:
    print(b[0]*2)
    exit(0)

a=[]
    
a.append(b[0])
a.append(b[n-2])

for i in range(len(b)-1):
    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()))

ret = 0

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

print(ret)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
Bi  = input().split()
ret = int(Bi[0])
for i in range(1, len(Bi)):
    if(int(Bi[i]) < int(Bi[i - 1])):
        ret += int(Bi[i])
    else:
        ret += int(Bi[i - 1])
print(ret + int(Bi[len(Bi) - 1]))

Submission status: Accepted

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

ans = 0
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:
num = int(input())
B_list = [int(item) for item in input().split()]

Ai_cand =[B_list[0]]

for k in range(1, num-1):
    Ai_cand.append(min(B_list[k], B_list[k-1]))

Ai_cand.append(B_list[-1])
    
print(sum(Ai_cand))

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[i]
  else:
    val1=B[i-1]
    val2=B[i]
    ans+=min(val1,val2)
ans+=B[-1]
print(ans)

Submission status: Accepted

Solution code:
import sys
from functools import reduce
import copy
import math


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    B = string_to_int(inputs[0])
    A = []

    candidate = -1
    for i, b in enumerate(B):
        if i == 0:
            A.append(b)
        else:
            if b > candidate:
                A.append(candidate)
            else:
                A.append(b)
        candidate = b
    A.append(b)
    return sum(A)


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)

Submission status: Accepted

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

sum_a = 0
B = [10**5] + B + [10**5]
for n in range(N ):
    sum_a += min(B[n:n+2])
    

print(sum_a)

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

Submission status: Accepted

Solution code:
import numpy as np

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

A = [0 for i in range(length)]
for i in range(len(B)):
    #次の数ののほうが大きければ
    if i == 0:
        A[i],A[i+1] = B[i],B[i]
    
    else:
        if B[i]<=A[i]:
            A[i] = B[i]
    
    A[i+1] = B[i]

print(np.sum(A))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n=int(input())
a=[0]*n
b=list(map(int,input().split()))
for i in range(1,n-1):
    a[i]=min(b[i],b[i-1])
a[0]=b[0]
a[n-1]=b[n-2]
print(sum(a))

Submission status: Accepted

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

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

print(total)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(sum)

Submission status: Accepted

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

a[0]=b[0]
a[n-1]=b[-1]

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

for k in range (n):
    goukei += a[k]
print(goukei)

Submission status: Accepted

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

s = 0
for i in range(0,n):
    s = s + a[i]

print(s)

Submission status: Accepted

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

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[N-1] = B[N-2]
for i in range(1, N-1):
    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()))
ans=[b[0], b[-1]]
if n>=2:
    for i,j in zip(b[:-1], b[1:]):
        ans.append(min(i,j))

print(sum(ans))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(s)

Submission status: Accepted

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

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:
N = int(input())
B = list(map(int, input().split()))

# B.reverse()
result = [B[0]]
for i, e in enumerate(B):
    if i < len(B) - 1:
        result.append(min(B[i], B[i+1]))
    else:
        result.append(B[i])
print(sum(result))

Submission status: Accepted

Solution code:
N=int(input())
B = list(map(int, input().split()))
B.append(10**5+1)
t=0
for i in range(N-1):
  if B[i]>B[i+1]:
    t+=B[i+1]
  else:
    t+=B[i]
t+=B[0]
print(t)

Submission status: Accepted

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

B.reverse()
result = [B[0]]
for i, e in enumerate(B):
    if i < len(B) - 1:
        result.append(min(B[i], B[i+1]))
    else:
        result.append(B[i])
print(sum(result))