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 = [0] * n

a[0] = b[0]
a[-1] = b[-1]
for i, (v1, v2) in enumerate(zip(b[:-1], b[1:]), 1):
    a[i] = min(v1, v2)

print(sum(a))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


print(sum(a))

Submission status: Accepted

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

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]
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())
a = input().split()

point = 0

if n == 2:
  point = int(a[0])*2
else:
  for i in range(n):
    if i == 0:
      point += int(a[0])
    elif i == (n-1):
      point += int(a[i-1])
    else:
      point += min(int(a[i-1]),int(a[i]))
print(point)

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

Submission status: Accepted

Solution code:
N = int(input())
B = list(map(int, input().split()))
def c(n, b):
    A = [0 for i in range(n)]
    for i in range(n):
        if(i == 0 or i == 1):
            A[i] = b[0]
        else:
            A[i] = b[i-1]
            if(b[i-1] < b[i-2]):
                A[i-1] = b[i-1]
    return sum(A)
print(c(N,B))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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



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

A.append(B[-1])

print(sum(A))

Submission status: Accepted

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

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

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


print(ans)

Submission status: Accepted

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

a = []

a.append(b[0])

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

a.append(b[-1])

print(sum(a))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
list1 = list(map(int,input().split()))
cout = list1[-1]
min_int = list1[-1]
for i in range(n-3,-1,-1):
    cout += min(list1[i:i+2])

cout += list1[0]

print(cout)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

for i in range(len(a)-1):
    if a[i] <= b[i]:
        a[i+1]=b[i]
        
    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=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:
import numpy as np
n=int(input())
b=np.array(list(map(int,input().split())))

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

Submission status: Accepted

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

al[0] = bl[0]
al[1] = bl[0]

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

print(sum(al))

Submission status: Accepted

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


last_value = 100000000

res=0
for B in B_list:
        val = min(B,last_value)
#       print(val)
        res += val
        last_value = B

res += last_value

print(res)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
a = [float("inf")] * n
b = list(map(int, input().split()))


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

    return sum(a)


print(solve())

Submission status: Accepted

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

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

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

print(sum(A))

Submission status: Accepted

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

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

print(sum(la))

Submission status: Accepted

Solution code:
N = int(input())
lst = list(map(int, input().split()))
ret = [lst[0]]
for idx, n in enumerate(lst[:-1]):
    ret.append(min(lst[idx], lst[idx + 1]))
ret.append(lst[-1])
print(sum(ret))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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())
l = [int(x) for x in input().split()]
l1 = [0 for x in range(n)]
for i in range(n-1):
	if l[i] > max(l1[i], l1[i+1]):
		if i == 0:
			l1[i] = l[i]
			l1[i+1] = l[i]
		else:
			l1[i+1] = l[i]
	else:
		l1[i] = l[i]
		l1[i+1] = l[i]
	
print(sum(l1))

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc140/tasks/abc140_c
n = int(input())
bx = [float("inf")] + list(map(float, input().split())) + [float("inf")]
out = 0
for i in range(n):
    out += int(min(bx[i], bx[i+1]))
print(out)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

answer = B[0] + B[N-2]

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

print(answer)

Submission status: Accepted

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

def min(x,y):
	if x>=y:
		return y
	else:
		return x
s=B[0]
for i in range(0,N-2):
    s=s+min(B[i],B[i+1])
print(s+B[N-2])

Submission status: Accepted

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

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())
data = [int(s) for s in input().split()]

#Bi = max(Ai,Ai+1)
#max(A1,A2) <= 0 == A1,A2<= 0
# max(A2,A3) <= 153 == A2,A3<= 153
#max(A3,A4) <= 10 == A3,A4 <= 10
#max(A1) = 0
#max(A2) = 0
#max(A3) = 10

#Ai = min(Bi,Bi-1)
ans = []
ans.append(data[0])
if len(data) >= 2:
  for i in range(1,n-1):
    ans.append(min(data[i],data[i-1]))
ans.append(data[len(data)-1])

print(sum(ans))

"""for i in ans:
  print(i)
"""

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in range(n):
    if i is 0:
        sum_a += b_l[i]
    elif i == n-1:
        sum_a += b_l[i-1]
    else:
        sum_a += min(b_l[i],b_l[i-1])

print(sum_a)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(B[0]+B[-1]+sum(min(x,y) for x,y in zip(B,B[1:])))

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

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

print(sum(A))

Submission status: Accepted

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

A = []

i=0
while i<N-2:
    if B[i]>B[i+1]:
        A.append(B[i+1])
    else :
        A.append(B[i])
    i+=1

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


print(sum(A))

Submission status: Accepted

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

A = [0]*( len(B)+1)
A[0] = B[0]
for i in range(0, len(B)):
    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(_) for _ in input().split()]

B.append(10**5)
B.insert(0,10**5)

res = 0

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

print(res)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

A = [0] * N
A[0], A[1] = B[0], 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))

Submission status: Accepted

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


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


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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

A = [0] * N
A[0], A[1] = B[0], 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))

Submission status: Accepted

Solution code:
N = int(input())

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

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

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


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

a = sum(A)

print(a)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc140/tasks/abc140_b
# -*- coding: utf-8 -*-

a_count = int(input())
b_value = list(map(int, input().strip().split()))

a_value = 0
a_value += b_value[0]

for i in range(1,a_count-1):
    if b_value[i - 1] > b_value[i]:
       a_value += b_value[i]
    else:
       a_value += b_value[i - 1]

a_value += b_value[a_count-2]
print(a_value)

Submission status: Accepted

Solution code:
import copy
import heapq
import math
import fractions

def j(n):
    if n:print("Yes")
    else:print("No")
    exit(0)
rem = 10 ** 9 + 7

"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def ipmultiplerow(n):
    a = []
    for i in range(n):
        a.append(ip())
    return a
def printrow(a):
    for i in a:
        print(i)
n = ip()
a=iprow()

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

Submission status: Accepted

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

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

print(sum(A))

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    B = [int(i) for i in input().split()]
    A = [0] * N
    A[0] = B[0]
    for i in range(1,N-1):
        A[i] = min(B[i-1],B[i])
    A[N-1] = B[N-2]
    print(sum(A))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
B = list(map(int,input().split()))
#A = [B[0]]
i = 0
sum = B[0]
while(i < N-2):
  tuika = min(B[i],B[i+1])
  #A.append(tuika)
  sum += tuika
  i += 1
#A.append(B[i])
sum += B[i]
print(sum)

Submission status: Accepted

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

print(sum(a))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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 = [int(i) for i in input().split()]
B.append(B[-1])

ans = B[0]

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

print(ans)

Submission status: Accepted

Solution code:



def main():



    n = int(input())
    bList = list(map(int,input().split()))
    ansList = []
    ansList.append(bList[0])

    for i in range(0,len(bList)-1):
        if bList[i] >= bList[i+1]:
            ansList.append(bList[i+1])
        else:
            ansList.append(bList[i])

    ansList.append(bList[-1])
    print(sum(ansList))




if __name__ == "__main__":
    main()

Submission status: Accepted

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

count = 0
for idx, b in enumerate(B):
	if(idx == 0):
		count += B[idx]
	else:
		count += min(B[idx], B[idx - 1])
count += B[len(B) - 1]
print(count)

Submission status: Accepted

Solution code:
# coding: utf-8

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin

N = int(stdin.readline())
B = list(map(int, stdin.readline().split()))

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

Submission status: Accepted

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

print(sum(ans))

Submission status: Accepted

Solution code:
n = int(input())
b = list(map(lambda x:int(x),input().split()))
ans = 0
a = [float('inf')]*n
for i in range(1,len(a)-1):
    a[i] = min(b[i-1],b[i])
a[0] = b[0]
a[-1] = b[-1]
print(sum(a))

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    B = [int(x) for x in input().split()]
    B.append(2**31)
    ans = B[0]
    for i in range(N-1):
        ans += min(B[i], B[i+1])
    
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

a = 0

a += B[0]
a += B[N-2]

for n in range(N):
    if n == 0 or n == N-1:
        pass
    else:
        a += min(B[n-1], B[n])

print(a)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

B_lst = list(map(int,input().split()))
A_lst = [0] * n

A_lst[0] = B_lst[0]
A_lst[n-1] = B_lst[n-2]

if n >= 3:
    for i in range(1,n-1):

        if B_lst[i-1] > B_lst[i]:
            A_lst[i] = B_lst[i]
        else:
            A_lst[i] = B_lst[i-1]

print(sum(A_lst))

Submission status: Accepted

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

Submission status: Accepted

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

result = B[0]

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

print(result)

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

Submission status: Accepted

Solution code:
N=int(input())
B=[int(x) for x in input().split()]
M=0
for i in range(N):
    if i==0:
        M+=B[0]
    elif i==N-1:
        M+=B[i-1]
    else:
        M+=B[i-1] if B[i-1]<B[i] else B[i]
print(M)

Submission status: Accepted

Solution code:
N = int(input())
B = [int(x) for x in input().split()]
A = [B[0]]
for n in range(1,N-1):
    A.append(min(B[n-1],B[n]))
A.append(B[N-2])
res = 0
for x in A:
    res += x
print(res)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

bb_list = b_list+[100000]
bbb_list = [100000]+b_list

c = 0
for bb, bbb in zip(bb_list, bbb_list):
    c += min(bb, bbb)

print(c)

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.append(min(B[i-1],B[i]))
print(sum(ans)+B[-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# Bi >= max(Ai, A(i+1))
# sum(A)を最大にしたときの値

# Aの要素は可能な限り大きくしたい
# A1の最大値はB1, Aiの最大値はBiとB(i-1)の小さい方

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

a = []  # B[0] = B1, B[N-2] = B(N-1)
for i in range(N-2):
    a.append(min(B[i], B[i+1]))

print(sum(a)+B[0]+B[N-2])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    B = inputList()
    
    ans = 0
    for i,val in enumerate(B):
        if i == len(B)-1:
            ans += val
        else:
            if val <= B[i+1]:
                ans += val
            else:
                ans += B[i+1]
            
    print(ans+B[0])
    
if __name__ == "__main__":
	main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(N):
    if i == 0:
        anslist.append(B[0])
    elif i == N-1:
        anslist.append(B[i-1])
    else:
        anslist.append(min(B[i-1],B[i]))

# print(anslist)
print(sum(anslist))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# INF = float('inf')
n = int(input())
b = list(map(int, input().split()))  # len = n-1

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

print(sum(a))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import math
import numpy as np
# from functools import lru_cache

args = sys.argv
if len(args) == 2:
  from IPython import embed
  em = True
else:
  em = False

#### input
N = int(input())
# a, b, c, d = map(int, input().split())
Bs = list(map(int, input().split()))
# a = list(map(lambda x: int(x)*(-1), a))  # 各要素を-1倍


# n = int(input())
# t = [int(input()) for i in range(n)]
if em: sys.stdin = open('/dev/tty')

#### functions
# @lru_cache(maxsize=10000)

#### process
# if em: embed()

As = [Bs[0]]

for i in range(0, len(Bs) - 1):
  As.append(min(Bs[i], Bs[i + 1]))

As.append(Bs[-1])
print(sum(As))
## heapsort, O(logN)
# import heapq
# heapq.heapify(A)
# min = heapq.heappop(A)
# heapq.heappush(A, new_element)

Submission status: Accepted

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

score = b_list[0] + b_list[n-2]

if n > 2:
	for val in range(n-2):
		c_list = [b_list[val], b_list[val+1]]
		score += min(c_list)
else:
	pass

print(score)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
pre = 1e8

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

ans += B[N-2]

print(ans)