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

for i in range(len(B)):
  if A[i]  <= B[i]:
     A.append(B[i])
  else:
     A[i] = B[i]
     A.append(B[i])

print(sum(A))

Submission status: Accepted

Solution code:
n = int(input())

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

result = 0

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

Submission status: Accepted

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

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

print(total)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
number_count = int(input())
b_numbers = list(map(int, input().split()))
sum_max_a = 0
for x in range(number_count):
  if x == number_count - 1:
    sum_max_a += b_numbers[x - 1]
  elif x > 0:
    sum_max_a += min(b_numbers[x], b_numbers[x - 1])
  else:
    sum_max_a += b_numbers[x]
print(sum_max_a)

Submission status: Accepted

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

Submission status: Accepted

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

out = 0
prev_b = 10**5
for b in B_list:
    out += min(b, prev_b)
    prev_b = b
    
out += B_list[N-2]    
print(out)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
N = int(input())
b = list(map(int, input().split()))

if N==2:
	print(b[0]*2)
	sys.exit()

ans=[b[0]]*2
for i in range(N):
	if b[i] != max(ans[i], ans[i+1]):
		ans[i]=ans[i+1]
	ans.append(b[i+1])
	if len(ans)==N:
		if b[-1]!=max(ans[-1], ans[-2]):
			ans[-2]=ans[-1]
		break

print(sum(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

a = [10 ** 6 for i in range(n)]
a[0] = b[0]
for i in range(n - 1):
    if a[i] > b[i]:
        a[i] = 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()]
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[n-2])
print(int(sum(a)))

Submission status: Accepted

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

b.append(b[-1])

s = b[0]

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

print(s)

Submission status: Accepted

Solution code:

n = int(input())

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

an = [10**6]*n

for i in range(n-1):

    an[i]   = min(an[i], bn[i])
    an[i+1] = bn[i]
#    print((an[i],an[i+1]))


#print(an)
print( sum(an) )

Submission status: Accepted

Solution code:
def resolve():
    n = int(input())
    b = list(map(int, input().split()))
    a = [100005] * n

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

    print(sum(a))

resolve()

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-1):
  a.append(b[i])

for i in range(n-1):
  if(a[i] > a[i+1]):
    a[i] = a[i+1]
    
sum = 0
for i in range(n):
  sum += a[i]
  
print(sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
num = int(input())

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

ans = b[0]

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

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())
bs = list(map(int, input().split()))
arr = []
for i in range(n):
    if i == 0 or i == 1:
        arr.append(bs[0])
    else:
        arr.append(bs[i-1])
        if bs[i-1] < arr[i-1]:
            arr[i-1] = bs[i-1]
print(sum(arr))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
line = input().split()
B = [0] * (N-1)
for i in range(N-1):
    B[i] = int(line[i])

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

Submission status: Accepted

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

B = B + [10**5+1]
A = [B[0]] + [min(B[i], B[i+1]) for i in range(N-1)]
print(sum(A))

Submission status: Accepted

Solution code:
n = int(input())
bl = list(map(int, input().split()))
al = []

al.append(bl[0])
al.append(bl[len(bl)-1])
for i in range(len(bl)-1):
    if bl[i] <= bl[i+1]:
        al.append(bl[i])
    else:
        al.append(bl[i+1])
print(sum(al))

Submission status: Accepted

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

print(sum(A))

Submission status: Accepted

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

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

dp_a = [0 for _ in range(n)]

for i in range(n-1):
#    print("test i = "+str(i))
    if i == 0:
        dp_a[i] = b[i]
        dp_a[i+1] = b[i]
    else: #iが1以上なら
        if b[i] <= b[i-1]:
#            print(str(b[i])+"は"+str(b[i-1])+"以下")
            dp_a[i] = b[i]
            dp_a[i+1] = b[i]
        else:
#            print(str(b[i])+"は"+str(b[i-1])+"より大きい")
            dp_a[i+1] = b[i]
#print(dp_a)
print(sum(dp_a))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

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

for i in range(N):
    if i == 0 or i == (N-1):
        pass
    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()))

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

Submission status: Accepted

Solution code:
N=int(input())

listA=list(map(int,input().split()))
#print(listA)

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

Submission status: Accepted

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

count = B[0]
for i in range(N-2):
    if B[i] >= B[i+1]:
        count += B[i + 1]
    else:
        count += B[i]
print(count+B[-1])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Sep  7 21:12:15 2019

@author: doppe
"""

N = int(input())

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

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

Submission status: Accepted

Solution code:
N = int(input())

B = list(map(int, input().split()))
A = []
for index, b in enumerate(B):
    if(index == 0):
        A.append(b)

    if(index+1 < N-1):
        if(B[index+1] > B[index]):
            A.append(B[index])
        else:
            A.append(B[index+1])
    else:
        A.append(B[index])

print(sum(A))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np


def main():
    n = int(input())
    b = np.array(input().split(), dtype='int')
    a = np.zeros(n, dtype='int')

    for i in range(n - 1):
        if i == 0:
            a[i] = b[i]
            a[i + 1] = b[i]
        else:
            if a[i] > b[i]:
                a[i] = b[i]
            a[i + 1] = b[i]
    
    ans = np.sum(a)

    print(ans)

main()

Submission status: Accepted

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

for bi in b:
    if bi >= ai:
        ans += ai
    else:
        ans += bi
    ai = bi
ans += c[-1]
print(ans)

Submission status: Accepted

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

b = b[::-1]
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:
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()))

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

b.append(10 ** 9 + 1)
b.insert(0, 10 ** 9 + 1)
ans = 0

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

Submission status: Accepted

Solution code:
N = int(input())

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

#print(N, array)

ans_array = [array[0]]
for i in range(N - 1):
    #print("i: ", i)
    #print(ans_array)
    if i == N - 2:
        ans_array.append(array[-1])
    else:
        ans_array.append(min([array[i], array[i + 1]]))
print(sum(ans_array))

Submission status: Accepted

Solution code:
import copy

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

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input().strip())
B = [int(str) for str in input().strip().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 = [0] * N
for k in range(N):
    A[0] = B[0]
    if k == N-1:
        A[k] = B[k-1]
    else:
        A[k] = min([B[k-1], B[k]])
print(sum(A))

Submission status: Accepted

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

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

Submission status: Accepted

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

right = [b[0]]+b
left  = b + [b[-1]]
count=0

for i in range(n):
  count+=min(right[i],left[i])
print(count)

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

Submission status: Accepted

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

Submission status: Accepted

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

last = 10 ** 6
sum = 0
for i in range(0, n - 1):
    if b[i] < last:
        sum += b[i]
    else:
        sum += last
    last = b[i]

sum += b[n-2]

print(sum)

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

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

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

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

print(sum(a))

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == "__main__":
    resolve()

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):
    if b[i] <= b[i + 1]:
        a += b[i]
    else:
        a += b[i + 1]
print(int(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 = [int(i) for i in input().split()]

A=[]

A.append(B[0])
A.append(B[0])

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

print(sum(A))

Submission status: Accepted

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

Submission status: Accepted

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


al = [bl[0]] * 2
for b in bl[1:]:
    if al[-1] > b:
        al[-1] = b
    al.append(b)

print(sum(al))

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

ans=ans+b[n-2]

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
b_array = [int(x) for x in input().split()]
a_array = []
a_array.append(b_array[0])
for i in range(n-2):
    a_array.append(min(b_array[i], b_array[i+1]))
else:
    a_array.append(b_array[-1])
print(sum(a_array))

Submission status: Accepted

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

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[i-1]
    else:
        if B[i-1]>=B[i]:
            ans += B[i]
        else:
            ans +=B[i-1]

print(ans)

Submission status: Accepted

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

result = B[-1]
s = B[-1]

for i in range(1, N - 1)[::-1]:
    if B[i - 1] <= B[i]:
        result += B[i - 1]
    else:
        result += B[i]
        
result += B[0]

print(result)

Submission status: Accepted

Solution code:
#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3

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

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

t += b[n - 2]

print(t)

Submission status: Accepted

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


def solve(N: int, B: "List[int]"):
    A = [0] * (N)
    A[0] = B[0]
    A[1] = B[0]
    for i in range(1,N-1):
        A[i] = min(A[i], B[i])
        A[i+1] = B[i]

    print(sum(A))
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    B = [int(next(tokens)) for _ in range(N - 1)]  # type: "List[int]"
    solve(N, B)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
c = 0
for i, b in enumerate(li):
  if i == 0:
    ans += b
  else:
    ans += min(c, b)
  c = b
ans += b

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
n = int(input()) # Skip first line
b = list(map(int,input().split()))
s = b[0]
for i in range(1,n-1):
    s = s + min(b[i-1],b[i])
s = s + b[n-2]
print(s)

exit(0)

Submission status: Accepted

Solution code:
def get_list(str):
    str_list = str.split(" ")
    result_list = []
    for str in str_list:
        result_list.append(int(str))
    return result_list

n = int(input())
b_str = input()
b_list = get_list(b_str)

result = 0
pre_num = pow(10, 5)
for b in b_list:
    if b >= pre_num:
        result += pre_num
    else:
        result += b
    pre_num = b
result += b_list[-1]

print(result)

Submission status: Accepted

Solution code:
import sys
n = int(sys.stdin.readline())
B = list(map(int, input().split()))

A =[1000001 for i in range(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:
# -*- coding: utf-8 -*-

n = int(input())

b = [int(i) for i in input().split()]
# print(b)
a = []
for i in range(n):
    if i >= 1 and i < len(b) :
        a.append(min(b[i],b[i-1]))
    elif i >= len(b) :
        a.append(b[i-1])
    else :
        a.append(b[i])
    
# print(a)
print(sum(a))

Submission status: Accepted

Solution code:
N = int(input())

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

maximal = B[0] + B[N-2]
for i in range(N-2):
    if B[i]>B[i+1]:
        maximal += B[i+1]
    else:
        maximal += B[i]

print(maximal)

Submission status: Accepted

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

ans = sum(B)*2

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


print(ans)

Submission status: Accepted

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

a = [0]*n

tmp = 0

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


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

ans = sum(a)

print(ans)

Submission status: Accepted

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

A = list()
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])

result = sum(A)

print(result)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
def A():
    print(int(input())**3)

def B():
    N = int(input())
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]
    C = [int(i) for i in input().split()]

    points = B[A[0]-1]
    previous = A[0]-1
    #print(points)
    for i in range(1, N):
        points += B[A[i]-1]
        if A[i]-1 == previous+1:
            points += C[previous]
        #print(points)
        previous = A[i]-1
    
    print(points)

def C():
    N = int(input())
    B = [int(i) for i in input().split()]

    s = B[0]
    temp = B[0]
    for i in range(1, len(B)):
        if B[i] > temp:
            s += temp
        else:
            s += B[i]
        
        temp = B[i]
    
    s += temp

    print(s)

C()

Submission status: Accepted

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

a = [[] for i in range(n)]

for i in range(len(b)):
  a[i].append(b[i])
  a[i+1].append(b[i])

ans = 0
for i in a:
  ans += min(i)

print(ans)

Submission status: Accepted

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

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

print(sum(a))

Submission status: Accepted

Solution code:
N = int(raw_input())
B = map(int, raw_input().split(' '))
A = [100000] * N

for i in range(0, 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:
# -*- coding: utf-8 -*-
N=int(input())
B=list(map(int,input().split()))
ans=0
for i in range(N-2):
    ans=ans+min(B[i],B[i+1])
ans=ans+B[0]+B[N-2]
print(ans)

Submission status: Accepted

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

A=[ float("inf") for _ in range(N)]

for i,b in enumerate(B):
	A[i]=min(A[i],b)
	A[i+1]=min(A[i+1],b)


print sum(A)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# abc140/abc140_c
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N = i2n()
    A = [0] * N
    B = i2nn()
    A[0] = B[0]
    for i in range(N-1):
        if A[i] > B[i]:
            A[i] = B[i]
        A[i + 1] = B[i]
    print(sum(A))
    return

main()

Submission status: Accepted

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

Submission status: Accepted

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

A_array.append(B_array[0])

for i in range(1, N-1):
    B_i = B_array[i]
    B_iminus1 = B_array[i-1]
    if B_i < B_iminus1:
        A_array.append(B_i)
    else:
        A_array.append(B_iminus1)

A_array.append(B_array[N-2])

counter = 0
for i, e in enumerate(A_array):
    counter += e

print(counter)

Submission status: Accepted

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

ans = 0


def mini(x, y):
    if x > y:
        return y
    else:
        return x


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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = b[0]

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

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

Submission status: Accepted

Solution code:
#インポート
import sys

#入力用
def ILI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def ISI(): return map(int, sys.stdin.readline().rstrip().split())
def II(): return int(sys.stdin.readline().rstrip())
def ISS(): return sys.stdin.readline().rstrip().split()
def IS(): return sys.stdin.readline().rstrip()

N = II()
B = ILI()
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[-1])
print(sum(A))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
B = [int(i) for i in input().split()] # input:"1 2 3 4 5"
ans=B[n-2]#last
for i in range(n-2):
  ans+=min(B[i],B[i+1])
ans+=B[0]#first
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

sum_ = 0
prev = float("inf")
for i in range(n):
    if i < len(B):
        sum_ += min(prev, B[i])
        prev = B[i]
    else:
        sum_ += prev
print(sum_)

Submission status: Accepted

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

Submission status: Accepted

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

def main(N,B):
    ans = 0
    for i in range(1,len(B)):
        ans += min(B[i-1], B[i])
    print(ans+B[0]+B[-1])    
    
if __name__ == '__main__':
    N = int(input())
    B = [int(b) for b in input().split()]
    main(N,B)

Submission status: Accepted

Solution code:
N=int(input())
B=list(map(int,input().split()))
ans=B[0]
for i,b in enumerate(B):
  if i>=len(B)-1:
    ans+=b
    break
  ans+=min(b,B[i+1])
print(ans)

Submission status: Accepted

Solution code:
import sys
from pprint import pprint

def solve(n, b):
    ans = 0

    for i, b_i in enumerate(b):
        if i == 0:
            ans += b_i
            continue
        ans += min(b_i, b[i-1])
    ans += b[i]

    print(ans)

if __name__ == '__main__':
    n = int(sys.stdin.readline().strip())
    b = list(map(int, sys.stdin.readline().strip().split(" ")))
    solve(n, b)

Submission status: Accepted

Solution code:
n = int(input())

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)