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

ans = b[0]

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

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())
B=list(map(int,input().split()))
A=[]
A.append(B[0])
A.append(B[0])
num=0
for i in B:
    if num==0:        
        num+=1
    elif A[num]<=B[num]:
        A.append(B[num])
        num+=1
    elif A[num]>B[num]:
        A[num]=B[num]
        A.append(B[num])
        num+=1

max_sum=0
for i in A:
    max_sum+=i
print(max_sum)

Submission status: Accepted

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

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:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools, os, pdb
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)
def perr(s): return print(s, file=sys.stderr)
N = _I()
B = LI()

"""
Bの値は、A, A+1の最大値
2 5 なら
A[1]は2でなくてはならない
? 2 ?
なんでも 2 5と決まる
2 2 5


3なら
3 3

5
 0 153 10 10 23なら
6
0 0 10 10 10 23

0 0 ? ? ? ?
0 0 10 10 ? ?
0 0 10 10 10 ?
0 0 10 10 10 23
最小値から決めていく
"""

A = [None] * N
#  print('a', A)
while any(a == None for a in A):
    min_idx = B.index(min(B))
    #  print(min_idx)
    if A[min_idx] is None:
        A[min_idx] = B[min_idx]
    if A[min_idx+1] is None:
        A[min_idx+1] = B[min_idx]
    B[min_idx] = inf

#  print(A)
print(sum(A))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# B(i) >= max( A(i), A(i+1) )
# B(0) = A(0), A(1)

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

tmp = []
list_a = []

for i in range(n-1):
  tmp.extend([b[i], b[i]])

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

print(sum(list_a))

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
b = [ int(x) for x in input().split() ]
res = [ float("inf") for _ in range(n) ]

for k, v in enumerate(b):
    if res[k] > v:
        res[k] = v

    if res[k+1] > v:
        res[k+1] = v

print(sum(res))

Submission status: Accepted

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

A.append(B[0])

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

A.append(B[-1])

print(sum(A))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
 
N = int(input())

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

A = [0] * N

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

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

print(sum(A))

Submission status: Accepted

Solution code:
N = int(input())
c = list(map(int, input().split(" ")))
cnt1 = c[-1]
for i in range(N-1):
  cnt1 += min(c[N-i-2],c[N-i-3])
c = c[::-1]
cnt2 = c[-1]
for i in range(N-1):
  cnt2 += min(c[N-i-2],c[N-i-3])
print(max(cnt1,cnt2))

Submission status: Accepted

Solution code:

if __name__ == '__main__':
    n = int(input())
    a = []
    b = list(map(int, input().split()))
    a.append(b[0])
    for i in range(n-1):
        a.append(b[i])
    for j in range(n-1):
        if b[j] != max(a[j], a[j+1]):
            a[j] = min(a[j], a[j+1])
            a[j+1] = min(a[j], a[j+1])
    print(sum(a))

Submission status: Accepted

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

sum = 0

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

print(sum)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(res)

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

Submission status: Accepted

Solution code:
n = int(input())

B =        list( map(int, input().split()) )	# 1 2 3 4 5 ...

A=[0]*n

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

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

print( sum(A) )

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

def ans() :

    # 整数の入力
    n = int(input())

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

    ans = b[0]

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

    ans += b[-1]
    print(ans)

if __name__ == '__main__':
    ans()

Submission status: Accepted

Solution code:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-

import sys, os
def ac_input(*args):
    return map(int, input().split())


def main():
    num = input()
    sseq = input().split()
    seq = map(int, sseq)
    prev = 0
    ans = int(sseq[0]) + int(sseq[-1])
    
    for i, s in enumerate(seq):
        ans = ans + min(s,prev)
        prev = s
        #print(ans)
    print(ans)    
if __name__ == "__main__" :
    main()

Submission status: Accepted

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

for i in range(0,len(b)):
    if b[i] < max(a[i],a[i+1]):
        a[i+1] = b[i]
print(sum(a))

Submission status: Accepted

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

Submission status: Accepted

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

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

print(res)

Submission status: Accepted

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


#0 153 10 160 23
#0 0 10 10 23 23
#0 153 10 10 23
#0 0 10 10 10 23
#?,0,  153,10,160,23
#?,0,  10, 10,160,23
#0,0,  10, 10,10 ,23

Submission status: Accepted

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

    for i in range(N):
        # 先頭追加
        if(i == 0):
            A.append(B[i])
            continue

        # ラスト追加
        if(i == N-1):
            A.append(B[i-1])
            continue

        # 通常
        A.append(min([B[i],B[i-1]]))

    print(sum(A))

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

Bs = []
Bs = list(map(int,input().split()))
tBs = []
for i,b in enumerate(Bs):
	tBs.append((b,i))
tBs = sorted(tBs,reverse=True)

As = [0 for _ in range(N)]

for tb in tBs:
	i = tb[1]
	As[i] = tb[0]
	As[i+1] = tb[0]

#print(N,As,tBs)
print(sum(As))

Submission status: Accepted

Solution code:
import numpy as np

N=int(input())
B=np.array(input().split(),dtype=np.int32)

s=[]
min_list=[]
min_list.append(B[0])
for i in range(0,N-1-1):
    min_list.append(min(B[i],B[i+1]))
min_list.append(B[-1])
#print(min_list)
print(sum(min_list))

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(1,len(B)):
  if B[i] <= B[i-1]:
    A[i] = B[i]
  elif B[i] > B[i-1]:
    A[i] = B[i-1]
A[-1] = B[-1]
print(sum(A))

Submission status: Accepted

Solution code:
N=int(input())
B=list(map(int, input().split()))  #複数数値入力

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

if (N>=3):
  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 = ([int(x) for x in input().split()])
A = [0] * N

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#code
n=int(input())
b=input()

b=b.split()

b=list(map(int,b))
a=list()
a.append(b[0])

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

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()) -1
B = list(map(int, input().split()))
ans = 0

if N == 1:
    ans = B[0]*2
else:
    ans += B[0] #min(B[0], B[1])

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())

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

A = []
A.append(B[0])
for i, x in enumerate(B):
    if i == N-2:
        A.append(x)
        break
    if x <= B[i+1]:
        A.append(x)
    else :
        A.append(B[i+1])

result = sum(A)
print(result)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


def main():
    n = int(input())
    B = list(map(int, input().split()))
    B = [10 ** 5] + B + [10 ** 5]
    print(sum([min(i, j) for i, j in zip(B[:-1], B[1:])]))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

if n==1:
    a.append(b[0])

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

ans = 0
for j in a:
    ans += j
print(ans)

Submission status: Accepted

Solution code:
import sys
import numpy as np
def main():
    input = sys.stdin.readline
    N = int(input())
    Bs = list(map(int, input().split()))
 
    A = np.zeros(N)
    for i in range(N-1):
        b_c = Bs[i]
        if i == 0:
            A[i] = b_c
            A[i+1] = b_c
        elif i == N-2:  # 最終
            A[i+1] = b_c
        elif i != N-2:  # 最終以外
            b_n = Bs[i+1]
            if b_c < b_n:
                if A[i] < b_c:
                    pass
                else:
                    A[i] = b_c
                A[i+1] = b_c
            elif b_c >= b_n:
                #A[i] = b_c
                if Bs[i - 1] > b_c:
                    A[i] = b_c
                else:
                    pass
                A[i + 1] = b_n
    #print(A)
    ans = np.int64(np.sum(A))
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin.readline
na = lambda: map(int, stdin().split())
ns = lambda: stdin().rstrip()
ni = lambda: int(ns())
def main():
  n = ni()
  b = list(na()) + [1e9]
  a = [b[0]]
  for i in range(n-1):
    a.append(min(b[i], b[i+1]))
  print(sum(a))
main()

Submission status: Accepted

Solution code:
N = int(input())
B = [int(i) for i in input().split()]
maxA = []
B.reverse()
maxA.append(B[0])
if N == 0:
    print(0)
    exit()

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

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = 0

for i in range(n):
    if not (i+1 == n):
        tmpA = b[i]
    
        if i-1 >= 0:
            tmpB = b[i-1]
            
            if tmpA > tmpB:
                ans += tmpB
            else:
                ans += tmpA
                
        else:
            ans += tmpA
    else:
        ans += b[i-1]
    
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
b = [int(i) for i in input().split()]
a = [b[0]]
for i in range(n-2):
    c = min(b[i], b[i+1])
    a.append(c)
    
try:
    if b[-2]<=b[-1]:
        a.append(max(b[-2],b[-1]))
    else:
        a.append(min(b[-2],b[-1]))
except:
    a.append(b[0])
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])  

print(ans+b[-1]+b[0])

Submission status: Accepted

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

Submission status: Accepted

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

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

# solve
A = list()
for i in range(N):
    if i == 0:
        A.append(B[0])
    elif i == N - 1:
        A.append(B[-1])
    else:
        if B[i - 1] <= B[i]:
            A.append(B[i - 1])
        else:
            A.append(B[i])

# output
print(sum(A))

Submission status: Accepted

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

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

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

print (sum)

Submission status: Accepted

Solution code:
n = int(input())
b = list(map(int,input().split()))
a = [0] * n
if n==2:
    print(b[0]*2)
else:
    #c = d = 0
    a[0] = b[0]
    for i in range(n-1,-1,-1):
        if i == n-1:
            a[i] = b[i-1]
        elif i == 0:
            pass
            #a[0] = min(b[0],b[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()))
A= [100000]*N

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

print(sum(A))

Submission status: Accepted

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

if n == 2:
    print(sum*2)
    exit()
for i in range(n-2):

    if b[i] <= b[i+1]:
        sum += b[i]
        #print(i,sum)                                                          
    else:
        sum += b[i+1]
print(sum+b[i+1])

Submission status: Accepted

Solution code:
N = int(input())
BB = input()

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

b1 = B[0]
sumax = b1
aimax = b1
# print(aimax)

for i in range(1,N-1):
    bi = B[i]
#     print(i)
#     print(bi)
#     print((aimax, bi))
    if bi > aimax:
        sumax += aimax
    else:
        sumax += bi
    
#     print(sumax)
    aimax = bi

sumax += B[len(B)-1]

print(sumax)

Submission status: Accepted

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

ans = [B[0], B[0]]
for i in range(1, N - 1):
    if B[i] - B[i-1] > 0:
        pass
    else:
        ans[i] = B[i]
    ans.append(B[i])

print(sum(ans))

Submission status: Accepted

Solution code:
n = int(input())
xs = list(map(int, input().split()))
b = None
r=0
for x in xs:
    if b==None:
        b=x
        continue
    r += min(b, x)
    b=x
print(xs[0]+xs[-1] + r)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

list = [b[0]]

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

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

Submission status: Accepted

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

A.append(B[0])

if n >= 2:
    A.append(B[0])
    for i in range(1, n-1):
        #print(A, B)
        if A[i] != B[i]:
            #A.append(B[i])
            if A[i] > B[i]:
                A[i] = B[i]
        
        A.append(B[i])
    #print(A)
    print(sum(A))

else:
    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]
A[1] = B[0]

for i in range(1,len(B)):
    if(B[i] < A[i]):
        A[i] = B[i]
    
    A[i+1] = B[i]

print(sum(A))

Submission status: Accepted

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

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

A += B[N-2]
print(A)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
B=list(map(int,input().split()))
ans = 0
time = 0
prev = 0
for B_ch in B:
    if time == 0:
        ans += B_ch
    else:
        if B_ch >= prev:
            ans += prev
        else:
            ans += B_ch
    
    prev = B_ch
    time += 1
ans += prev
print(ans)

Submission status: Accepted

Solution code:
N = input()
N = int(N)

B = input().split()
ans = []
for i in range(N):
    ans.append(0)

if 2<=N and N<= 100:
    ans[0] = int(B[0])
    for i in range(len(B)):
        b = int(B[i])
        ans[i+1] = b

        tmp = ans[i]
        if tmp > b:
            ans[i] = b
        

    # print(ans)

ko = 0
for i in ans:
    ko += i
print(ko)


# 0 0 10 10 10 23

Submission status: Accepted

Solution code:
n = int(input())

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

box = []

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

print(sum(box)+B[0]+B[-1])

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(n-1):
    if i == 0:
        A_list.append(B_list[i])
    elif i >= 1:
        if B_list[i-1] <= B_list[i]:
            A_list.append(B_list[i-1])
        else:
            A_list.append(B_list[i])
A_list.append(B_list[-1])
print(sum(A_list))

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

Submission status: Accepted

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


if n == 2:
  print(b[0]*2)
  
else:
  a[0] = b[0]

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

    else:
      a[i] = b[i-1]

  a[-1] = b[-1]
  print(sum(a))

Submission status: Accepted

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

  if B[i]<B[i-1]:
    A.append(B[i])
  else:
    A.append(B[i-1])
print(sum(A))

Submission status: Accepted

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

Submission status: Accepted

Solution code:


def main():


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

   if A==2:
      print(bList[0]*2)
      exit()

   for i in range(1,A-1):
      if i == A-2:
         if bList[i-1] <= bList[i]:
            ansList.append(bList[i-1])
            ansList.append(bList[i])
         else:
            ansList.append(bList[i])
            ansList.append(bList[i])
         break


      if bList[i-1] <= bList[i]:
         ansList.append(bList[i-1])
      else:
         ansList.append(bList[i])
   print(sum(ansList))









if __name__== "__main__":
    main()

Submission status: Accepted

Solution code:
a=0
N=int(input())
BL=[int(x) for x in input().split()]
for i in range(len(BL)-1):
   a+=min(BL[i],BL[i+1])
a+=BL[0]
a+=BL[-1]
print(a)

Submission status: Accepted

Solution code:
N=int(input())
B=list(map(int, input().split()))
S=0
for x in reversed(range(0,N)):
    if x==N-1:
        S=S+B[N-2]
        AA=B[N-2]
    if x!=N-1 and x!=0:
        if B[x]>=B[x-1]:
            S=S+B[x-1]
            AA=B[x-1]
        if B[x]<B[x-1]:
            S=S+B[x]
            AA=B[x-1]
    if x==0:
        if AA>=B[0]:
            S=S+B[0]
        if AA<B[0]:
            S=S+AA
print(S)

Submission status: Accepted

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

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

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

print(sum(A))

Submission status: Accepted

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

for i in range(1, N - 1):
    b = B[i]
    A[i + 1] = b
    if b < max(A[i], A[i + 1]):
        A[i], A[i + 1] = b, b

print(sum(A))

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

Submission status: Accepted

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

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

Submission status: Accepted

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

print(sum(output))

Submission status: Accepted

Solution code:
import sys

#+++++
		
def main():
	n = int(input())
	bl = list(map(int, input().split()))
	bl=[bl[0]] + bl + [bl[-1]]
	rr = [min(i,j) for i,j in zip(bl,bl[1:])]
	ret=sum(rr)
	print(ret)
	
	
#+++++


if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

B_list = list(map(int, input().split()))
B_list.reverse()

A_list = []

A_list.append(B_list[0])

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

A_list.append(B_list[-1])
print(sum(A_list))

Submission status: Accepted

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

D = 0
if N >= 3:
	if B[0] < B[1]:
		D += min(B[0],B[1])
	else:
		D += max(B[0],B[1])
	for i in range(1,N-1,1):
		D += min(B[i-1],B[i])
	D += B[N-2]
else:
	D = 2*B[0]

print(D)

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in b:
    ans += min(tmp, i)
    tmp = i

print(ans)

Submission status: Accepted

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

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

print(sum(A))

Submission status: Accepted

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

out=B[N-2]

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

out+=B[0]

print(out)

Submission status: Accepted

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

ans = 0

ans += b[0]
ans += b[len(b)-1]

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

Submission status: Accepted

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

import numpy as np
A = np.zeros(N)

BB = np.ones(N+1) * 10**6
BB[1:N] = B

for i in range(N):
    A[i] = min(BB[i], BB[i+1]) 

print(int(sum(A)))

Submission status: Accepted

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

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

print(sum(a))

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

print(sum(A))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
# A = []
for i in range(N)[::-1]:
    if i == 0:
        ans += B[i]
        # A.append(B[i])
    else:
        ans += min(B[i-1], B[i])
        # A.append(min(B[i-1], B[i]))

# print(A)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
B=input().split()
B = [int(s) for s in B]
B.insert(0, B[0])
B.append(B[N-1])
a= 0
for i in range(len(B) - 1):
    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()]
a = [0 for x in range(n)]

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

a[n-1] = max(b[n-2:n-1]) 

print(sum(a))

Submission status: Accepted

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

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

print(sum(A))