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()))
 
# A_1 <= B_1
# A_2 <= min(B_1, B_2)
# A_3 <= min(B_2, B_3)
# A_(N-1) <= min(B_(N-2), B_(N-1))
# A_N <= B_(N-1)
# ans = B_1 + min(B_1, B_2) + ... + min(B__(N-2), B_(N-1)) + B_(N-1)
 
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()))

# A_1 <= B_1
# A_2 <= min(B_1, B_2)
# A_3 <= min(B_2, B_3)
# A_(N-1) <= min(B_(N-2), B_(N-1))
# A_N <= B_(N-1)
# ans = B_1 + min(B_1, B_2) + ... + min(B__(N-2), B_(N-1)) + B_(N-1)
 
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()))
a=[0]*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()))

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Sep  9 16:47:54 2020

@author: liang
"""
INF = 10**6
N = int(input())
B = [INF]+list(map(int,input().split()))+[INF]

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Sep  9 16:47:54 2020

@author: liang
"""
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[N-2]
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
B_List = list(map(int,input().split()))
A_List = [[] for i in range(N)]
A_List[0] = B_List[0]
A_List[1] = B_List[0]
for i in range(1,N - 1):
    if B_List[i] <= B_List[i-1]:
        A_List[i] = B_List[i]
    A_List[i+1] = B_List[i]
        
        

print(sum(A_List))

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
N = int(input())
B = list(map(int, input().split()))
pre = math.inf
ans = 0
for b in B:
    ans += min(pre, b)
    pre = b
ans += B[-1]
print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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[n-2])
print(sum(a))

Submission status: Accepted

Solution code:
#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))

n=int(input())
B=input_array()
A=[B[0]]
ans=B[0]

for i in range(1,n):
	if A[i-1] > B[i-1]:
		ans=ans-A[i-1]+B[i-1]
		A[i-1]=B[i-1]
	ans+=B[i-1]
	A.append(B[i-1])

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import copy
n = int(input())
b = list(map(int,input().split()))
a = copy.copy(b)
a.insert(0,b[0])
for i in range(n-2):
    a[i+1]=min(b[i],b[i+1])
#print(b)
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 += min(B[i-1],B[i])
A+= B[n-2]
print(A)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

A=[0]*N

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

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

Submission status: Accepted

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

a_l = [0] * n
a_l[0] = b_l[0]
a_l[-1] = b_l[-1]
for i in range(1, n-1):
    a_l[i] = min(b_l[i],b_l[i-1])
print(sum(a_l))

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-09-04 13:28:04 +0900
# LastModified: 2020-09-04 13:47:38 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def main():
    n = int(input())
    b = list(map(int, input().split()))
    if n == 1:
        print(b[0]*2)
        return
    a = [-float('inf')]*n
    a[0] = b[0]
    a[1] = b[0]
    for i in range(1, n-1):
        if a[i] > b[i]:
            a[i] = b[i]
        a[i+1] = b[i]
    print(sum(a))



if __name__ == "__main__":
    main()

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().split()))
if len(b)==1:
  print (2*b[0])
else:
  ans=0
  for i in range(1,len(b)):
    ans+=min(b[i],b[i-1])
  print (ans+b[0]+b[len(b)-1])

Submission status: Accepted

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

if n==2:
  print(sum(l)*2)
else:
  ans=[]
  ans.append(l[0])
  ans.append(l[len(l)-1])

  for i in range(len(l)-1): 
    num=min(l[i],l[i+1])
    ans.append(num)
  
  print(sum(ans))

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    b_list = list(map(int, input().split()))
    ans = b_list[0] + b_list[n - 2]

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys


def main():
    input = sys.stdin.buffer.readline
    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))


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],b[i-1])
print(sum(a)+b[n-2])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    B = list(map(int, input().split()))
    A = [B[0]]
    for i in range(N - 1):
        a = max([A[-1], B[i]])
        if i != N - 2 and a > B[i + 1]:
            a = B[i + 1]
        A.append(a)
    print(sum(A))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == "__main__":
    solve()

Submission status: Accepted

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

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:
n=int(input())
sum=0
a=[0]*n

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

Submission status: Accepted

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    B=LI()
    A=[0]*N
    A[0]=B[0]
    A[-1]=B[-1]
    for i in range(N-2):
        A[i+1]=min(B[i],B[i+1])
        
    print(sum(A))

main()

Submission status: Accepted

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

for i in range(n-2):
  if b[i] <= b[i+1]:
    
    ar.append(b[i])
  else:
    
    ar.append(b[i+1])
ar.append(b[-1])
print(sum(ar))

Submission status: Accepted

Solution code:
N = int(input())

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


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

ans = 0

for j in range(N):
  ans += A[j]
  
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[-1]
print(ans)

Submission status: Accepted

Solution code:
import sys

def main():
    input = sys.stdin.readline
    n = int(input())
    B_list = list(map(int, input().split()))

    if n == 2:
        sum_a0_a1 = B_list[0]*2
        print(sum_a0_a1)
        return

    first_a = B_list[0]
    last_a = B_list[n-2]
    sum_other_a = 0

    for i in reversed(range(0,n-2)):
        min_b = min(B_list[i+1],B_list[i])
        sum_other_a += min_b

    print(first_a + last_a + sum_other_a)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# 問題：https://atcoder.jp/contests/abc140/tasks/abc140_a

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

Submission status: Accepted

Solution code:
N=int(input())
B=list(map(int,input().split()))
B.append(B[-1])
A=[B[0]]
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()))
A=[]

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

Submission status: Accepted

Solution code:
n = int(input())
b = list(map(int, input().split()))
a = [b[0],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()))
a = [0]*n
ans = 0

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

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:
def mapt(fn, *args):
    return tuple(map(fn, *args))

def Input():
    return mapt(int, input().split(" "))

def main():
    n = int(input())
    b = Input()
    data = 0
    for i in range(n-1):
        if i == 0:
            data += b[i]
            continue
        data += min(b[i], b[i-1])
    data += b[-1]
    print(data)
main()

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

ans = sum(A)

print(ans)

Submission status: Accepted

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


def solve(acc, xs):
    head, *tail = xs
    if not acc:
        acc.append(head)
    if not tail:
        acc.append(head)
        return acc

    peek, *_ = tail
    acc.append(min(head, peek))
    return solve(acc, tail)


arr = solve([], Bs)
print(sum(arr))

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 = [0] + list(map(int, input().split()))
a = [0] * (n + 1)

a[1] = b[1]
a[-1] = b[-1]

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

print(sum(a))

Submission status: Accepted

Solution code:
n=int(input())
b=[int(x) for x 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)

Submission status: Accepted

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# # input = sys.stdin.readline
# sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
bl = inpl()
ans = bl[0]
for i in range(0, n):
    if(i == n - 2):
        ans += bl[n - 2]
        break
    ans += min(bl[i], bl[i + 1])
print(ans)

Submission status: Accepted

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

a=[0]*n

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:
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip.split())
def main():
    n = I()
    f_inf = float("inf")
    b = [f_inf] + LI() + [f_inf]

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

main()

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 = []

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

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

print(sum(A))

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],B[i-1])
    
print(sum(A))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

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[N-2]

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]
A[N-1] = B[N-2]

for j in range(1,N-1):
  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()))
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())
if N == 2:
  ans = 2 * int(input())
else:
  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()))
C = []
C.append(B[0])
for i in range(len(B) - 1):
    C.append(min(B[i], B[i+1]))
C.append(B[-1])
print(sum(C))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
S=list(map(int,input().split()))
ans=0
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:
#C - Maximal Value
N = int(input())
B = list(map(int,input().split()))
A = [B[0]]
for i in range(1,N-1):
    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:
#!/usr/bin/env python3

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

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

INF = float('inf')
B.append(INF)
B.insert(0, INF)

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

print(count)

Submission status: Accepted

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

A = []

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

Submission status: Accepted

Solution code:
# row = [int(x) for x in input().rstrip().split(" ")]
# n = int(input().rstrip())
# s = input().rstrip()

def resolve():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip())

    ans = 0

    prev = 0
    for i, b in enumerate(input().rstrip().split(" ")):
        b = int(b)
        if i == 0:
            ans += b
            prev = b
            continue

        ans += min(b, prev)
        prev = b
    ans += b

    print(ans)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

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],b[i-1])
a[n-1]=b[n-2]  
print(sum(a))

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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:
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N=ii()
    B=list(mi())

    X = []
    X.append(B[0])
    X.append(B[0])

    for i in range(1,N-1):
        last = X[-1]
        if last <= B[i]:
            X.append(B[i])
        else:
            X[-1] = B[i] 
            X.append(B[i])
    
    # print(X)
    print(sum(X))







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

import copy
A = copy.deepcopy(B)
for i in range(1,N-1):
    if B[i-1]<B[i]:
        A[i] = B[i-1]
        
A.append(B[-1])
print(sum(A))

Submission status: Accepted

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

Submission status: Accepted

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

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):
  if b[i]<=b[i+1]:
    ans+=b[i]
    
  else:
    ans+=b[i+1]
  
print(ans)

Submission status: Accepted

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

print(sum(a))

Submission status: Accepted

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

dp = [10**8]*N
for i in range(N-1):
    if dp[i]>B[i]:
        dp[i]=B[i]
    if dp[i+1]>B[i]:
        dp[i+1]=B[i]
    
print(sum(dp))

Submission status: Accepted

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

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

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-1], B[i]))
A.append(B[N - 2])
print(sum(A))

Submission status: Accepted

Solution code:
import bisect,collections,copy,heapq,itertools,math,string
from collections import defaultdict as D
from functools import reduce
import numpy as np
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353    

N = I()
B = LI()

A = [0]*N

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

Submission status: Accepted

Solution code:
from sys import stdin

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

B.append(1e+5 + 3)

sum = B[0]

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

print(sum)

Submission status: Accepted

Solution code:
N = int(input())
B = list(map(int,input().split()))
a = [0] * N
ans = 0
x = 0
if N == 2:
    ans = B[0] * 2
elif N == 3:
    ans = sum(B) + min(B)
else:
    for i in range(N - 1):
        if i == 0:
            a[0] = B[0]
            
        
        else:
            x = min(B[i],B[i - 1])
            a[i] = x
            
            if i == N - 2:
                a[i + 1] = B[N - 2]
                
        
        ans = sum(a)
print(ans)

Submission status: Accepted

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

A=[0]*n
i=0
A[i]=B[i]
while 1 :
    i+=1
    if i>=n-1:
        break
    A[i]=min(B[i],B[i-1])
A[i]=B[i-1]

# print(B)
# print(A)
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:
        a[i]=b[i]
    elif 0<i<n-1:
        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=[10**6]*N

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

print(sum(A))

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

Submission status: Accepted

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

Submission status: Accepted

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