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

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())
B=list(map(int,input().split()))
if N==1:
    print(B[0]*2)
else:
    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 math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
import itertools
from collections import Counter

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


if __name__=="__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
import itertools
from collections import Counter

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



if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instr = lambda: sys.stdin.readline()
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()
B = inintl()

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()))
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:
import math
from collections import defaultdict,deque
#from itertools import permutations
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())
ips=lambda:input().split()

"""========main code==============="""

n=ii()
a=ll()
lol=[]
lol.append(a[0])
for i in range(1,n-1):
    lol.append(min(a[i-1],a[i]))
lol.append(a[n-2])
print(sum(lol))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


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

Submission status: Accepted

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

Submission status: Accepted

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

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

a = [0] * (len(b) + 1)
a[0] = max(b)

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:
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

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

A = [INF] * N
for i in range(N-1):
    A[i] = min(A[i], B[i])
    A[i+1] = min(A[i+1], B[i])
    # print(A)
ans = sum(A)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
B = tuple(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()))
ls = [0]*N
ls[0] = B[0]
#print(B)
for i in range(1,N-1):
    if B[i-1] <= B[i]:
        ls[i] = B[i-1]
    else:
        ls[i] = B[i]
ls[N-1] = B[N-2]
print(sum(ls))
#print(ls)

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

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    B = LI()

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

    print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

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

print(sum(A)+B[-1])

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

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 = [0]*N
Bp = 1<<100
for i in range(N-1):
    A[i] = min(B[i], Bp)
    Bp = 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 = 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], B[i-1])

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

print(sum(A))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

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

print(ans)

Submission status: Accepted

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

A[0]=B[0]

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
lines = [s.rstrip("\n") for s in sys.stdin.readlines()]
n = int(lines.pop(0))
b_list = [int(b) for b in lines.pop(0).split(" ")]
b_list.append(sys.maxsize)
def _iter():
    prev_b = sys.maxsize
    for b in b_list:
        yield min(prev_b, b)
        prev_b = b
answer = sum(_iter())
print(answer)

Submission status: Accepted

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

ans = b[-1]+b[0]
for i in range(n-2):
    if b[-i-2] <= b[-i-1]:
        ans += b[-i-2]
    else:
        ans += 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]
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:
# AtCoder Beginner Contest 140
# C - Maximal Value

N=int(input())
Bfirst=[10**5+3]
B=list(map(int,input().split()))
Blast=[10**5+3]
BL=Bfirst+B+Blast

ans=0

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

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

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

Submission status: Accepted

Solution code:
import heapq
t = 1
def max(a,b):
	if a > b:
		return a
	return b
while t > 0:
	t -= 1
	# n = map(int,input().split())
	n = int(input())
	# a = list(map(int,input().strip().split()))[0:n]
	# b = list(map(int,input().strip().split()))[0:n]
	c = list(map(int,input().strip().split()))[0:n-1]
	b = []
	for i in range(n):
		b.append(0)
	b[0] = c[0]
	b[n-1] = c[n-2]
	for i in range(1,n-1):
		b[i] = min(c[i],c[i-1])
	ans = 0
	for i in range(n):
		ans += b[i]
	print(ans)
	# print(n*n*n)
	# m = 1000
	# i = 0
	# while i < n:
	# 	j = i
	# 	while j+1 < n and v[j+1] >= v[j]:
	# 		j += 1
	# 	x = m//v[i]
	# 	m = m%v[i]
	# 	temp = x*v[j]
	# 	m += temp
	# 	i = j+1
	# print(m)

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 a[i] <= b[i]:
        pass
    else:
        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()))

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

print(sum(A))

Submission status: Accepted

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

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[n-2]
ans = 0
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 = 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:
# abc140_c.py
# https://atcoder.jp/contests/abc140/tasks/abc140_c

# C - Maximal Value /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 300点

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

# 制約
#     入力は全て整数
#     2≤N≤100
#     0≤Bi≤105

# 入力
# 入力は以下の形式で標準入力から与えられる。
# N
# B1 B2 ... BN−1

# 出力
# Aの要素の総和として考えられる値の最大値を出力せよ。

# 入力例 1
# 3
# 2 5

# 出力例 1
# 9

# Aとして、例えば A = ( 2 , 1 , 5 )や、 A = ( −1 , −2 , −3 ), A = ( 2 , 2 , 5 ) 等が考えられます。
# これらのうち A の要素の総和が最大となるものは、 A = ( 2 , 2 , 5) です。

# 入力例 2
# 2
# 3

# 出力例 2
# 6

# 入力例 3
# 6
# 0 153 10 10 23

# 出力例 3
# 53


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    # S = lines[0]
    N = int(lines[0])
    # N, M = list(map(int, lines[0].split()))
    values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(N):
    #     valueses.append(list(map(int, lines[i+1].split())))

    lst = [0] * N
    lst[0] = values[0]
    lst[N-1] = values[N-2]
    for n in range(1, N-1):
        lst[n] = min(values[n-1], values[n])

    return [sum(lst)]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['3', '2 5']
        lines_export = [9]
    if pattern == 2:
        lines_input = ['2', '3']
        lines_export = [6]
    if pattern == 3:
        lines_input = ['6', '0 153 10 10 23']
        lines_export = [53]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(2)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()

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[int(len(b)-1)])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
B=list(map(int,input().split()))
A=[]
for c in B:
    A.append(c)
A.append(B[-1])

for a in range(len(B)):
   
    if A[a]>B[a]:
        A[a]=B[a]
    elif A[a+1]>B[a]:
        A[a+1]=B[a]

print(sum(A))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

if __name__=='__main__':
    n,b=readinput()
    ans=main(n,b)
    print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [100000] * N
    B = [int(i) for i in input().split()]
    for i in range(N-1):
        if A[i] > B[i]: A[i] = B[i]
        A[i+1] = B[i]
    print(sum(A))
   
    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

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

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

print(sum(A))

Submission status: Accepted

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

lsA = [0]*N
lsA[0] = lsB[0]
lsA[N-1] = lsB[N-2]
for i in range(1,N-1):
    lsA[i] = min(lsB[i-1],lsB[i])
print(sum(lsA))

Submission status: Accepted

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


def solve(N, B):
    ans = 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])
        ans += a
    return ans


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Submission status: Accepted

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

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

print(ans+B[-1])

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#52 1日かかった
N = int(input())
b = list(map(int,input().split()))
a = [0 for i in range(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:

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

    a = [0]*n

    for i,e in enumerate(b):
        if i == 0:
            a[0] = b[0]
        else:
            a[i] = min(b[i-1], b[i])

    a[-1] = b[-1]
            # if a[i] >= a[i+1] and e <= b[i-1]:
            #     a[i] = e
            # else:
            #     a[i+1] = e

    print(sum(a))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
import sys
import re
from collections import deque, defaultdict
from itertools import combinations, combinations_with_replacement
import bisect
from math import factorial, sqrt, log, ceil, floor
sys.setrecursionlimit(1000000)


def main():
    input = sys.stdin.readline
    #N, M = map(int, input().split())
    #N, K = map(int, input().split())
    #ps = list(map(int, input().split()))

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main() -> None:
    N = int(input())
    B = [int(x) for x 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()))
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())
b=list(map(int,input().split()))
a=[b[0]]+[0]*(n-1)

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:
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
B = list(map(int,readline().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:
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
#
#
# @stop_watch
def solve(N, Bs):
    Bss = [Bs[0]] + Bs + [Bs[-1]]
    As = []
    for i in range(len(Bss) - 1):
        As.append(min(Bss[i], Bss[i + 1]))
    print(sum(As))


if __name__ == '__main__':
    # S = input()
    N = int(input())
    # N, M = map(int, input().split())
    # As = [int(i) for i in input().split()]
    Bs = [int(i) for i in input().split()]
    solve(N, Bs)

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

Submission status: Accepted

Solution code:
N = int(input())
B = [int(i) for i in input().split(' ')]
A = [0]*(N)
for i,a in enumerate(B):
    if i == 0: #index最初
        A[i] = a
        A[i+1] = a
    else:#二番目以降
        if B[i-1] < B[i]:
            A[i+1] = a
        else:
            A[i] = a
            A[i+1] = a

print(sum(A))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Created: Jul, 14, 2020 12:42:18 by Nobody
# $Author$
# $Date$
# $URL$
__giturl__ = "$URL$"


from sys import stdin
input = stdin.readline


def main():
  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 A[i] > B[i]:
      A[i] = B[i]
    A[i+1] = B[i]

  # print(A)
  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]
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().strip().split()))

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

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

a=[0]*n
if n>2:
  
  for x in range(1,n-1):
    c=min(b[x-1],b[x])
    a[x]+=c
  
  a[0]+=b[0]
  a[n-1]+=b[n-2]

  ans=0

  for y in range(len(a)):
    ans+=a[y]
  print(ans)

else:
  print(b[0]*2)

Submission status: Accepted

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

Submission status: Accepted

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

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

    alis = [blis[0], blis[0]]
    if n > 2 and alis[1] > blis[1]:
        alis[1] = blis[1]
    if n > 2:
        for i in range(3, n):
            alis.append(min(blis[i-2], blis[i-1]))
    if n > 2:
        alis.append(blis[n-2])
    print(sum(alis))


    


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n,*bb = map(int, open(0).read().split())

ans = bb[0] + bb[-1]

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

print(ans)

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    B = list(map(int, input().split()))
    array = [0 for _ in range(N)]
    prev = B[0]
    array[0] = B[0]
    for i in range(N-1):
        if prev <= B[i]:
            array[i+1] = B[i]
        else:
            array[i] = B[i]
            array[i+1] = B[i]
        prev = B[i]
    print(sum(array))

    
if '__main__' == __name__:
    resolve()

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[n-2])

print(sum(ans))

Submission status: Accepted

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

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 = [int(x) for x in input().split()]
A = [0 for y 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-1],B[i])
print(sum(A))

Submission status: Accepted

Solution code:
MAX_B = 10**5
N = int(input())
B = [MAX_B] + list(map(int, input().split())) + [MAX_B]
res = 0
for i in range(N):
    res += min(B[i], B[i + 1])
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
lb = [int(w) for w in input().split()]

ans = 0

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

print(ans)

Submission status: Accepted

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