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:
#!/usr/bin/env python3


def solve(N, B):
    ans = 0
    last_b = float('inf')
    for b in B:
        ans += min(b, last_b)
        last_b = b
    ans += B[-1]
    return ans


if __name__ == '__main__':

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

    ans = solve(N, B)

    print(ans)

Submission status: Accepted

Solution code:
N = int(input())
#A = list(map(int,input().split()))
B = list(map(int,input().split()))
#C = list(map(int,input().split()))
#[A, B] = list(map(int,input().split()))
#N = 3
#A = [1, 2]
#B = [0,153,10,10,23]
B = [10**6]+B+[10**6]
ans=0
for i in range(len(B)-1):
    ans += min(B[i],B[i+1])
print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

  
  

print(ans)

Submission status: Accepted

Solution code:
n  = int(input())
bs = [int(x) for x in input().split()]
bs = [bs[0]] + bs + [bs[-1]]
a  = 0

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

print(a)

Submission status: Accepted

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

A = [B[0]]

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

#print(A)

print(sum(A))

Submission status: Accepted

Solution code:
# ABC140c
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

n = int(input())
b = list(map(int, input().split()))
a = [0]*n

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

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

print(sum(A))

Submission status: Accepted

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

    print(sum(A))

main()

Submission status: Accepted

Solution code:
n = int(input())

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

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

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

print(sum(a))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

    # Aの数列を作っていく
    A = list()
    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())

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

max_int = 10**5 + 1
print(sum(min(bi, bj) for bi, bj in zip([max_int] + B, B + [max_int])))

Submission status: Accepted

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

a=[0]*n
a[0]=bs[0]
a[n-1]=bs[n-2]

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

Submission status: Accepted

Solution code:
#coding utf-8
N=int(input())
B=list(map(int,input().split())) 
ans=0
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:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, B):
    B.append(sys.maxsize)
    ans = 0
    for i in range(N):
        ans += min(B[i-1], B[i])
    return ans



def main():
    N = read_int()
    B = read_int_n()
    print(slv(N, B))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
n=int(input())
A=[]
B=list(map(int,input().split()))
B.append(10**6)
A.append(B[0])

for i in range(1,n):
    A.append(min(B[i-1],B[i]))
    
print(sum(A))

Submission status: Accepted

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

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(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 = [10**10] + list(map(int, input().split())) + [10**10]
A = []
for i in range(N):
    A.append(min(B[i],B[i+1]))

print(sum(A))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
B = map(int, input().split())
A = [100000]*n
for i,b in enumerate(B):
    A[i] = min(b,A[i])
    A[i+1] = b
print(sum(A))

Submission status: Accepted

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n = readi()

b = readl()
p = max(b)
a = [p] * (n + 1)

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

Submission status: Accepted

Solution code:
import sys

N=int(sys.stdin.readline().rstrip())
BList=list(map(int,sys.stdin.readline().split()))

AList=[]
bBefore=10**5+1
for b in BList:
  AList.append(min(bBefore,b))
  bBefore=b
AList.append(BList[-1])
print(sum(AList))

Submission status: Accepted

Solution code:
from sys import exit, stderr, stdin
input = stdin.readline
# setrecursionlimit(10**7)

def debug(var, name="hoge"):
    print(name +":" + str(type(var)) + " = " + repr(var), file=stderr)
    return


def main():
    N = int(input())
    B = list(map(int,input().split()))
    A = [[] for _ in range(N)]
    A[0].append(B[0])
    for i in range(1,N-1):
        A[i].append(B[i-1])
        A[i].append(B[i])
    A[-1].append(B[-1])
    # print(A)
    print(sum([min(a) for a in A]))

if __name__ == "__main__":
    main()

Submission status: Accepted

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

ans = B[0]+B[-1]
i = 0
while i <= N-3:
    ans += min(B[i],B[i+1])
    i += 1
print(ans)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    b = [int(x) for x in input().split()]
    ans = 0
    for i in range(n-2):
        ans += min(b[i],b[i+1])
    ans += b[0]
    ans += b[-1]
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

s = B[0]

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

ans = s + sum(B)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

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

print(ans + b[n-2])

Submission status: Accepted

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

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

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

Submission status: Accepted

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

score = B[0]+B[-1]

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

Submission status: Accepted

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
bn = list(map(int, input().split()))

ans = bn[0]

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

ans += bn[n-2]

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

print(sum(a))

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

# initial term                                                                                                                                          
sum = int(B[0])

# intermediate                                                                                                                                          
for i in range(1,N-1):
    ai = min(int(B[i-1]), int(B[i]))
    sum = sum + ai

# last term                                                                                                                                             
sum = sum + int(B[N-2])


print sum

Submission status: Accepted

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

B.insert(0, 1000000)
B.append(1000000)

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# A_i should be min(B_(i-1), B_i)
N = int(input())
B = [int(i) for i in input().split()]
maximal = B[0]
for i in range(1, N-1):
    maximal += min(B[i], B[i-1])
maximal += B[-1]
print(maximal)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
B = [int(x) for x in stdin.readline().rstrip().split()]
ans = 0
ans += (B[0] + B[-1])
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 = input().split()
sum = int(b[0])
for i in range(n-2):
    if(int(b[i]) <= int(b[i+1])):
        sum += int(b[i])
    else:
        sum += int(b[i+1])
sum += int(b[n-2])        
print(sum)

Submission status: Accepted

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

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

else:
    ans += Blist[0]

print(ans)

Submission status: Accepted

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


S = sum(list(map(min,B[:-1],B[1:])))+B[0]+B[-1]

print(S)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
b = list(map(int,input().split()))
count = b[0]
for i in range(n-2):
  if b[i] >= b[i+1]:
    count += b[i+1]
  else:
    count += b[i]
count += b[n-2]
print(count)

Submission status: Accepted

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

def main():
    A = [10**8]*(N)
    A[0] = B[0]
    for i in range(N - 2, -1, -1):
        A[i+1] = min(A[i + 1],B[i])
        A[i] = B[i]
    print(sum(A))
    return
main()

Submission status: Accepted

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

Submission status: Accepted

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

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

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

    A.append(B[-1])

    print(sum(A))


if __name__ == '__main__':
    p_c()

Submission status: Accepted

Solution code:
def resolve():
    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)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
import copy

n = int(input())
# k, x = [int(i) for i in input().split()]
#table = [[int(i) for i in input().split()] for j in range(n)]
# table = [list(input()) for n in range(h)]
b = [int(i) for i in input().split()]

#num = [int(i) for i in range(n)]
# s = [input() for i in range(n)]
# s = input()
# list = list(s)
# dp = [[0 for _ in range(2)] for _ in range(13)]
#s = [input() for i in range(n)]

kotae = 0

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

print(kotae)

Submission status: Accepted

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

res = [B[0]]
for i in range(N-1):
    if B[i] < res[i]:
        res[i] = B[i]
    res.append(B[i])
print(sum(res))

Submission status: Accepted

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

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

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

print(result)

Submission status: Accepted

Solution code:
N = 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:
N = int(input())
B = [int(a) for a in input().split()]
B = [B[0]] + B + [B[-1]]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8

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

# A = [None for i in range(N)]
output = B[0]  # when i == 0
# A[0] = B[0]
for i in range(1, N-1):
    output += min(B[i], B[i-1])
    # A[i] = min(B[i], B[i-1])

output += B[N-2]
# A[N-1] = B[N-2]

# print(A)
print(output)

Submission status: Accepted

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
b_lst = [int(x) for x in stdin.readline().rstrip().split()]
a_sum = b_lst[0] + b_lst[-1]

for i in range(len(b_lst)-1):
  a_sum += min(b_lst[i], b_lst[i+1])
  
print(a_sum)

Submission status: Accepted

Solution code:

n= int(input())
b=[int(i) for i in input().split()]
a=b[0]+b[n-2]
for i in range(0,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()))

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

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

ans = sum(A)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

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

Submission status: Accepted

Solution code:
n=int(input())

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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(a)
print(sum(a))

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys; from collections import deque ; readline = sys.stdin.readline

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

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

print(sum(A))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main():

    N = int(input())
    B = list(map(int, input().split()))
    tot = 0
    for i in range(N):
        if i == 0:
            tot += B[i]
        elif i == N-1:
            tot += B[i-1]
        else:
            tot += min(B[i], B[i-1])
    return tot


if __name__ == '__main__':
    print(main())

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

score = 0
prev_max = 1000000

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

score = score + B[N-2]

print(score)

Submission status: Accepted

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

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

print(tot)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n = int(input())
    b = list(map(int,input().split()))

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

#print(N,B)

s=B[0]

for j in range(1,N-1):
  s=s+min(B[j-1],B[j])
  
s=s+B[N-2]  
print(s)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
n=int(input())
b=list(map(int,input().split()))

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

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

INF = float("inf")
vB += [INF,]

res = 0

p = INF
for b in vB:
    res += min(p, b)
    p = b

print(res)

Submission status: Accepted

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

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

    print(sum)

if __name__ == '__main__':
    func()

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

Submission status: Accepted

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

alist=[blist[0]]
for i in range(1,N-1):
  alist.append(min(blist[i-1],blist[i]))
  
alist.append(blist[-1])
#print(alist)
print(sum(alist))

Submission status: Accepted

Solution code:
n = int(input())
*bl, = map(int,input().split())
al = [10**6]*n
for i in range(len(bl)):
  al[i] = min(bl[i],al[i])
  al[i+1] = bl[i]
print(sum(al))

Submission status: Accepted

Solution code:
#import sys
N = int(input())
B = list(map(int, input().split()))
#S = [input() for _ in range(H)]
#T = [list(map(int,input().split())) for _ in range(N)]
A = [0] * N
A[0] = B[0]
A[N-1] = B[N-2]
for i in range(N - 2) :
    A[i+1] = min(B[i],B[i+1])
print(sum(A))

Submission status: Accepted

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