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

A[0] = B[0]
for bi in range(len(B)):
  A[bi+1] = B[bi]
  A[bi] = min(B[bi], A[bi])

print(sum(A))

Submission status: Accepted

Solution code:
N=int(input())
l_b=list(map(int,input().split()))
l_a=[l_b[-1]]
for i in range(N-2):
  l_a.append(min(l_b[N-2-i],l_b[N-3-i]))
l_a.append(l_b[0])
print(sum(l_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.append(min(B[i], B[i+1]))
A.append(B[-1])

print(sum(A))

Submission status: Accepted

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

for i in range(N):
    if i == 0:
        A[i] = B[0]
    elif 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())) # list()でリスト化、それを変数liに代入。


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

Submission status: Accepted

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

Submission status: Accepted

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

def main():
    N = int(input())
    B = [int(b) for b in input().split()]

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

    print(sum(A))





if __name__ == "__main__":
    main()

Submission status: Accepted

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


def main():
    N = int(input())
    A = np.zeros(N)
    B = np.array(input().split(), dtype='int64')


    for i in range(N):
        if i == 0:
            A[0] = B[0]
        elif i == N-1:
            A[-1] = B[-1]
        else:
            if B[i-1] < B[i]:
                A[i] = B[i-1]
            else:
                A[i] = B[i]
    ans = int(np.sum(A))
    print(ans)








if __name__ =='__main__':
    main()

Submission status: Accepted

Solution code:
import math
input = raw_input

N = int(input())
A = list(map(int, input().split(" ")))

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    B = [int(number) for number in input().split()]
    A = [B[0]]
    for i in range(N-1):
        if B[i] < A[i]:
            A[i] = B[i]
        A.append(B[i])
    print(sum(A))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

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

    A.append(B[-1])


    print(np.sum(A))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
b_list = list(map(int, input().split()))
temp = 10**5
max_sum = 0
for b in b_list:
    max_sum += min(b, temp)
    temp = b
print(max_sum+temp)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve():
    data = read()
    result = think(data)
    write(result)


def read():
    n = read_int(1)[0]
    return read_int(n - 1)


def read_int(n):
    return list(map(lambda x: int(x), read_line().split(' ')))[:n]


def read_float(n):
    return list(map(lambda x: float(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(data):
    result = []
    result.append(data[0])
    for i in range(len(data) - 1):
        result.append(min(data[i], data[i + 1]))
    result.append(data[-1])
    return sum(result)


def write(result):
    print(result)


if __name__ == '__main__':
    # import doctest
    # doctest.testmod()
    # import sys
    # sys.setrecursionlimit(10000)
    solve()

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[-1]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(sum(c))

Submission status: Accepted

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

Submission status: Accepted

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

if __name__ == "__main__":
    f_c()

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):
  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] = 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 = []
for i in range(N):
  if i == 0:
    A.append(B[i])
  elif i == N-1:
    A.append(B[i-1])
  else:
    if B[i-1]>B[i]:
      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()))

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

B.sort()

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

print(sum(A))

Submission status: Accepted

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

A = [max(B)] * N

for n in range(N-1):
    if B[n] < A[n]:
        A[n] = B[n]
    if B[n] < A[n+1]:
        A[n+1] = B[n]
print(sum(A))

Submission status: Accepted

Solution code:


N = int(input())
A = []
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])
S = sum(A)
print(S)

Submission status: Accepted

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

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

ans = sum(a)

print(ans)

Submission status: Accepted

Solution code:
def main():
    N = input()
    B_l = [int(i) for i in input().split()]
    A_l = []
    for i in range(len(B_l)):
        if i == 0:
            A_l.append(B_l[i])
        elif i < len(B_l):
            A_l.append(min(B_l[i - 1], B_l[i]))

    A_l.append(B_l[-1])
    print(sum(A_l))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

sum=0

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

print(sum)

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

Submission status: Accepted

Solution code:
from collections import deque

def main():
    _ = int(input())
    B = deque([int(x) for x in input().split()])
    # B.appendleft(B[0])
    old = B[0]
    B.append(B[-1])
    ans = 0
    while B:
        now = B.popleft()
        ans += min(old, now)
        old = now
    print(ans)

if __name__ == "__main__":
    main()

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 += listb[0]
    elif i == n-1:
        ans += listb[-1]
    else:
        ans += min(listb[i],listb[i-1])
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in range(n-1):
    if a[i] is None or a[i] > b[i]:
        a[i] = b[i]
    a[i+1] = b[i]

res = sum(a)

print(res)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

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

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

print(s)

Submission status: Accepted

Solution code:
n = int(input())
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[n-2]
print(ans)

Submission status: Accepted

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

As = [0] * N

ans = Bs[0]
mae = Bs[0]
# print(ans)

for b in Bs[1:]:
    if mae < b:
        ans += mae
    else:
        ans += b
    mae = b

    # print(ans)
ans += Bs[-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])
print(ans+B[N-2])

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


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



print(sum(A))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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


temp=a[0]
result=0
for item in a[1:]:
  result+=min(temp,item)
  temp=item

result+=a[0]
result+=a[-1]

print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
    
    
    
n=int(input())
l=list(map(int,input().split()))

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

cnt=0

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

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

Submission status: Accepted

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

if N == 2:
    print(sum(b_list) * 2)
    exit()
a_list.append(b_list[0])
for i in range(N-2):
    b = b_list[i]
    b2 = b_list[i+1]
    a_list.append(min(b, b2))

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.append(10**6)

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

print(ans)

Submission status: Accepted

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

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

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



if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
b = list(map(int, input().split()))

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

print(count)

Submission status: Accepted

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

max_a.append(B[N-2])
print(sum(max_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:
n = int(input())
B = list(map(int,input().split()))
total = B[0]

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

print(total)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
from copy import deepcopy
from collections import deque, defaultdict
from operator import mul
from functools import reduce
sys.setrecursionlimit(20000000)

input = sys.stdin.readline


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

    ans = [10**5 + 1] * n

    for i in range(len(B)):
        v = B[i]

        if v < ans[i]:
            ans[i] = v
        if v < ans[i+1]:
            ans[i + 1] = v

    print(sum(ans))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())

b = list(map(int, input().split())) + [10**5+1]

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(result)

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

print(sum(A))

Submission status: Accepted

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

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

print(sum(A))

Submission status: Accepted

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

pre_b = 0
output = []
for index, b in enumerate(b_list):
    if index == 0:
        output.append(b)
    else:
        if pre_b <= b:
            output.append(pre_b)
        else:
            output.append(b)
    pre_b = b
output.append(b_list[-1])
print(sum(output))

Submission status: Accepted

Solution code:
def calc(n, b):
    r = b[0]
    for i in range(1, n-1):
        r += min(b[i-1], b[i])
    r += b[len(b)-1]
    return r


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

r = calc(n, b)
print(r)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

ans = 0
for i in range(n):
    ans = ans + al[i]

print(ans)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline
N = int(input().strip())
blist = list(map(int,input().strip().split()))

alist = []
alist.append(blist[0])
for i in range(N-2):
    addnum = min(blist[i],blist[i+1])
    alist.append(addnum)
alist.append(blist[N-2])

ans = sum(alist)
print(ans)

Submission status: Accepted

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

Alist = [0 for i in range(N)]
for i in range(N):
    if i == 0:
        A_left = 1000000
    else:
        A_left = Blist[i-1]
    if i == N-1:
        A_right = 1000000
    else:
        A_right = Blist[i]
    Alist[i] = min(A_left,A_right)
#print(Alist)
print(sum(Alist))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

MAX = 10**5+1

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

b_new = [MAX]
b_new.extend(b)
b_new.append(MAX)

a = []
for i in range(n):
    a.append(min(b_new[i], b_new[i+1]))

print(sum(a))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
B = list(map(int,input().split(' ')))
A = [10**5+1]*N
for i in range(N - 1):
    A[i] = A[i] if A[i]<B[i] else B[i]
    A[i + 1] = A[i + 1] if A[i + 1]<B[i] else B[i]
    
print(sum(A))

Submission status: Accepted

Solution code:
def main():
    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[-1]
        else:
            ans += min(b[i-1],b[i])
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
B = np.fromstring(input(), dtype=np.int64, sep=' ')
A = np.zeros(N, dtype=np.int64)
A[:-1] = B
A[-1] = 100000
for i in range(1, N):
    A[i] = min(A[i], B[i - 1])
print(A.sum())

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
# coding: utf-8

import sys
import math
import collections
import itertools
from inspect import currentframe
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def MI() : return map(int, input().split())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def chkprint(*args) : names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}; print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

N = I()
B = LI()

B.reverse()

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):
    if i == 0:
        ans += b[0]
    elif i == n - 1:
        ans += b[-1]
    else:
        ans += min(b[i-1], b[i])

print(ans)

Submission status: Accepted

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

def main():
    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))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
B_list = list(map(int, input().split()))
ans = B_list[0] + B_list[-1]

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
B = [int(x) for x in input().split()] + [10 ** 5]
pre = 10 ** 5
sumA = 0
for b in B:
  sumA += min(pre, b)
  pre = b
print(sumA)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
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()))

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

Submission status: Accepted

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

res = bs[0]

for i, b in enumerate(bs[:-1]):
  if b < bs[i+1]:
    res += b
  else:
    res += bs[i+1]

res += bs[-1]
print(res)

Submission status: Accepted

Solution code:
n = int(input())

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

b = [100000] + b + [100000]

score = 0
for i in range(len(b)-1):
    temp = min(b[i],b[i+1])
    score += temp

print(score)

Submission status: Accepted

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

sumA = B[0]

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

sumA += B[n-2]
    
print(sumA)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(N):
    if i==0:
        ans += Blist[i]
    elif i == N-1:
        ans += Blist[i-1]
    else:
        ans += min(Blist[i-1],Blist[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[-1] = B[-1]
for i in reversed(range(1, N - 1)):
    A[i] = min(B[i], B[i - 1])
print(sum(A))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# import sys
# input = sys.stdin.readline
n = int(input())
b = list(map(int,input().split()))
a = [0]*n
a[0] = b[0]
a[n-1] = b[n-2]
# print(a)
for i in range(1,n-1):
    a[i] = 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()))

A=[0]*N

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

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

for j in range(N):
  Ans = Ans + A[j]

print(Ans)

Submission status: Accepted

Solution code:
import sys

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

A = [0]*N
A[0] = B[0]
for i in range(N-1):
    if A[i] > B[i]:
        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]"):
    A = [0 for i in range(N)]
    for i in range(N):
        if i==0:
            A[i] = B[i]
        elif i < N-1:
            A[i] = min(B[i], B[i-1])
        elif i==N-1:
            A[i] = B[i-1]
    print(sum(A))
    return


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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
B=list(map(int,input().split()))
#a,b=map(int,input().split())
#A=[[0 for i in range()] for j in range()]
#data_list = [ list(map(int,input().split(" "))) for i in range(3)]

ans=B[0]

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

print(ans)