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=[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:
# For taking integer inputs.
def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


N = inp()
B = inlist()
A = [0] * N
A[0] = B[0]
for i in range(N-2):
    A[i+1] = min(B[i], B[i+1])

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

Submission status: Accepted

Solution code:
# coding: utf-8
N = int(input())
B = list(map(int, input().split()))
A = B
A.insert(0, B[0])
for i in range(1, N - 1):
    if A[i] > A[i+1]:
        A[i] = A[i+1]
print(sum(A))

Submission status: Accepted

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

Submission status: Accepted

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

#b 2 5  
#  2  2   5
b.append(10**16)
bsum = 0
for i in range(n-1,0,-1): 
    #print("min(b[i],b[i-1])",min(b[i],b[i-1]),i)
    bsum += (min(b[i],b[i-1]))
print(bsum+b[0])

Submission status: Accepted

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

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

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N = I()
B = IL()[::-1]

A = [0 for i 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]

P(sum(A))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
#N, K = map(int, input().split())
# 文字列の入力
N = int(input())
#開業されたN個要素を受け付ける
#input_list = [list(map(int, input().split())) for i in range(N)]
input_list = list(map(int, input().split()))

ans_list=[input_list[0]]
for i in range(N-2):
    ans_list.append(min(input_list[i], input_list[i+1]))
ans_list.append(input_list[N-2])
#print(ans_list)
print(sum(ans_list))

Submission status: Accepted

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

A = [B[0]]

for i in range(1, N-1):
    if B[i-1] >= B[i]:
        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 = tuple(map(int, input().split(' ')))

s = B[0] + B[-1]
for b1, b2 in zip(B, B[1:]):
    s += min(b1, b2)

print(s)

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# ABC140C

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

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

Submission status: Accepted

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

Submission status: Accepted

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

A = 0
b = 10**5+10
for i in range(N-1):
    a = b if B[i] > b else B[i]
    #print(b, B[i], a)
    b = B[i]
    A += a
A += B[-1]
print(A)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
B = list(map(int, input().split()))
A = [0]* N
A[0] = B[0]
for i, b in enumerate(B):
    if A[i] > b:
        A[i] = b
    A[i+1] = b
print(sum(A))

Submission status: Accepted

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

a_list = [1e6] * n

for i, b in enumerate(b_list):
    a_list[i] = min(b, a_list[i])
    a_list[i + 1] = min(b, a_list[i + 1])

print(sum(a_list))

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:
import sys

n, *lst = map(int, sys.stdin.read().split())
alst = [lst[0]]
lst += [lst[-1]]
for i in range(n - 1):
  tmp = min(lst[i], lst[i + 1])
  alst += [tmp]
print(sum(alst))

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


resolve()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
B = np.array([10 ** 5] + list(map(int, input().split())) + [10 ** 5], np.int32)
print(np.minimum(B[1:], B[:-1]).sum())

Submission status: Accepted

Solution code:
N = int(input())
B = list(map(int, input().split()))
B = [float('inf')] + B + [float('inf')]
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 = list(map(int, input().split()))

if N == 2:
  print(2 * B[0])
  exit()

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=[0]*(n-1)
b[:]=map(int,input().split())
r=b[0]
for ii in range(n-2):
  r+=min(b[ii],b[ii+1])
r+=b[n-2]
print(r)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

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

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]
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().rstrip())
b = list(map(int, input().rstrip().split()))
a = [0 for i in range(N)]

for i in range(N - 1):
	v = b[i]
	a[i + 1] = v
	if i == 0:
		a[i] = v
	else:
		if v <= a[i]:
			a[i] = v

r = sum(a)
print(r)

Submission status: Accepted

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

A = [B[0]]

for i in range(1, n):
    if i < n - 1:
        A.append(min(B[i-1], B[i]))
    else:
        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+1)
if N==2:
    print(2*sum(B))
    exit()
for i in range(N-1):
    if i==0:
        A[i]=B[i]
        tmp=B[i]
    elif i!=(N-2):
        A[i]=min(tmp,B[i])
        tmp=B[i]
    elif i==(N-2):
        A[i]=min(tmp,B[i])
        A[i+1]=B[i]
print(sum(A))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
INF = 10**6

N = int(input())
Bs = [INF] + list(map(int, input().split())) + [INF]

As = [0] * N
for i in range(N):
    As[i] = min(Bs[i], Bs[i+1])

print(sum(As))

Submission status: Accepted

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

Submission status: Accepted

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

# check
A = []
append = A.append
for i, b in enumerate(B):
    while len(A[i:]) < 2:
        if not A:
            append(b)
        elif i < len(B) - 1 and max([A[i], b]) >= B[i + 1]:
            append(B[i + 1])
        else:
            append(b)

print(sum(A))

Submission status: Accepted

Solution code:

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

ANS=0
i=0
while i<N:
    if i==0:
        ANS+=B[i]
        mae=B[i]
    elif i==N-1:
        ANS+=mae
    else:
        ANS+=min(B[i],mae)
        mae=B[i]
    i+=1
    
print(ANS)

Submission status: Accepted

Solution code:
import itertools
import math
import fractions
import functools
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()))
a=[0]*n
a[0]=b[0]
for i in range(n-1):
  if b[i]<a[i]:
    a[i]=b[i]
  a[i+1]=b[i]

print(sum(a))

Submission status: Accepted

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

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

print(sum(a))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    B=[int(_) for _ in input().split()]
    ans=B[0]+B[-1]
    for i in range(n-2):
        ans+=min(B[i],B[i+1])
    print(ans)
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.append(min(b[i],b[i+1]))
ans.append(b[-1])
print(sum(ans))

Submission status: Accepted

Solution code:
N = int(input())
B = [int(x) for x in input().split()]
A = [B[0]]
for i, b in enumerate(B):
    if A[-1] > b:
        A[-1] = b
    A.append(b)
print(sum(A))

Submission status: Accepted

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

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

answer = a1 + an + sum(aj)
    
print(answer)

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
import bisect

def solve(B):
    n = len(B) + 1
    A = [-10 ** 18] * n
    for i in range(n):
        min_val = 10 ** 18
        if i < n - 1:
            min_val = min(min_val, B[i])
        if i - 1 >= 0:
            min_val = min(min_val, B[i-1])
        A[i] = min_val
    '''
    print('n: ' + str(n))
    print('A: %s' % str(A))
    print('B: %s' % str(B))
    '''
    return A

def main():
    n = int(input())
    B = list(map(int, input().split()))
    A = solve(B)
    print(sum(A))

if __name__ == "__main__":
    main()

Submission status: Accepted

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

num = [b[0]]

for i in range(1, n - 1):
  if(b[i] <  b[i - 1]):
    num[-1] = b[i]
    num.append(b[i])
  else:
    num.append(b[i])

num.append(b[0])

print(sum(num))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

a_list = [0]*n
a_list[0] = b_list[0]
k = 0
while k <= n-2:
  if a_list[k] > b_list[k]:
    a_list[k] = b_list[k]
  a_list[k+1] = b_list[k]
  k += 1
print(sum(a_list))

Submission status: Accepted

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

a = [b[0]] * (n)
for i in range(1,n):
    a[i] = b[i-1]
    if a[i-1] > b[i-1]:
        a[i-1] = 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()))

res = 0

for i in range(n - 1):
    # print('＝＝＝＝＝＝＝＝＝＝')
    if i + 1 < n - 1:
        if b[i] > b[i + 1]:
            if i == 0:
                res = b[0] + b[1]
                # print('b[0] = ', b[0])
                # print('b[0] = ', b[0])
            else:
                res += b[i + 1]
                # print('b[i + 1] = ', b[i + 1])
        else:
            if i == 0:
                res = b[0] + b[0]
                # print('b[0] = ', b[0])
                # print('b[0] = ', b[0])
            else:
                res += b[i]
                # print('b[i] = ', b[i])
    elif i == 0:
        res = b[0] + b[0]
        # print('b[0] = ', b[0])
        # print('b[0] = ', b[0])
    else:
        res += b[i]
        # print('b[i] = ', b[i])
print(res)

Submission status: Accepted

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

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

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:
#!/usr/bin/env python3
n = int(input())
b = [-1 for _ in range(n)]
b[0] = b[n-1] = int(1e6)
c = list(map(int, input().split()))
for i in range(n-1):
    b[i+1] = c[i]

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

Submission status: Accepted

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

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

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

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

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

Submission status: Accepted

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

la = list()
la.append(lb[0])

for i in range(1, N-1):
    la.append(min(lb[i-1], lb[i]))

la.append(lb[-1])

print(sum(la))

Submission status: Accepted

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

Submission status: Accepted

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

a =[0]*n
a[0] = b[0]

if n == 2:
    a[1] =b[0]
    print(sum(a))

else:

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

        else:
            a[i+1] = b[i+1]
            a[i+2] = b[i+1]

    print(sum(a))

Submission status: Accepted

Solution code:
N = int(input())
B = [int(i) for i in input().split(' ')]
A = 0
for i in range(N):
    if i == 0:
        A += B[i]
    elif i == N - 1:
        A += B[i - 1]
    else:
        A += min(B[i-1], B[i])
print(A)

Submission status: Accepted

Solution code:
N = int(input())
B = list(map(int,input().split()))
SUM = 0
tmp = 10**5
for i,b in enumerate(B[::-1]):
    SUM += min(tmp,b)
    tmp = b
print(SUM+b)

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:
def main():
    _ = int(input())
    B = list(map(int, input().split()))
    A = []
    A.append(B[0])
    A.append(min(B[0:2]))
    
    for i in range(1, len(B[:-1])):
        A.append(min(B[i], B[i+1]))
    if len(B) > 1:
        A.append(B[-1])

    print(sum(A))

    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
#from fractions import gcd
#from math import gcd
import sys
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')


n = I()
B = LI()
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())
t = list(map(int, input().split()))
a = [t[0]]*2
for i in range(1, n-1):
 if t[i]<a[-1]: a[-1]=t[i]
 a+=[t[i]]
print(sum(a))

Submission status: Accepted

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

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

print(sum(a))

Submission status: Accepted

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

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

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

print(sum(ans))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# C - Maximal Value

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

A = [float('inf')] * N
for i in range(N - 1):
    A[i + 1] = B[i]
    if B[i] < A[i]:
        A[i] = B[i]

print(sum(A))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

    res += B[0]
    res += B[-1]
    print(res)
    
main()

Submission status: Accepted

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

lis=[0]*n

for i in range(0,n-1):
  if i==0:
    lis[0]=b[0]
  temp=b[i]
  if lis[i]>b[i]:
    lis[i]=b[i]
  lis[i+1]=b[i]
print(sum(lis))

Submission status: Accepted

Solution code:
n = int(input())
pre = 100000
ans = 0
for bi in map(int, input().split()):
    ans += min(pre, bi)
    pre = bi
ans += pre
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(len(B)-1):
    ans+=min(B[i],B[i+1])
print(str(ans))

Submission status: Accepted

Solution code:
import sys, heapq
def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
B = LI()

res = B[0] + B[-1]
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()))

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

Submission status: Accepted

Solution code:
def resolve():
    """
    b: 2, 5
    a: 2, 2, 5


    b: 0, 153, 10, 10, 23
    a: 0, 0, 10, 10, 10, 23
    """
    n = int(input())
    b = [int(i) for i in input().split()]
    a = [b[0]]
    for i, v in enumerate(b):
        if i < len(b)-1:
            a.append(min(b[i], b[i + 1]))

    a.append(b[-1])
    print(sum(a))


resolve()

Submission status: Accepted

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

Submission status: Accepted

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

from collections import deque


A=deque([])

for i in range(N-1):
    B_i = B[i]

    #初回は2つ入れる
    if i==0:
        A.append(B_i)
        A.append(B_i)

    #初回以降
    else:
        if B_i<=pre_B_i:
            A.pop()
            A.append(B_i)
            A.append(B_i)
        else:
            A.append(B_i)

    #前に入れたものの記録
    pre_B_i = B[i]

print(sum(A))

Submission status: Accepted

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