Problem:


Score : 300 points

Problem Statement

There is an integer sequence A of length N whose values are unknown.

Given is an integer sequence B of length N-1 which is known to satisfy the following:

 B_i \geq \max(A_i, A_{i+1}) 

Find the maximum possible sum of the elements of A.

Constraints

All values in input are integers.

2 \leq N \leq 100

0 \leq B_i \leq 10^5

Input

Input is given from Standard Input in the following format:

N
B_1 B_2 ... B_{N-1}

Output

Print the maximum possible sum of the elements of A.

Sample Input 1

3
2 5

Sample Output 1

9

A can be, for example, ( 2 , 1 , 5 ), ( -1 , -2 , -3 ), or ( 2 , 2 , 5 ). Among those candidates, A = ( 2 , 2 , 5 ) has the maximum possible sum.

Sample Input 2

2
3

Sample Output 2

6

Sample Input 3

6
0 153 10 10 23

Sample Output 3

53



Sample input:
3
2 5


Sample output:
9

Submission status: Accepted

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

a = [b[0]]

for i in b:
    if a[-1] > i: a[-1] = i
    a.append(i)
print(sum(a))

Submission status: Accepted

Solution code:
import math 
import bisect
import heapq
from collections import deque

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

res = 0
was = 99999999
for b in B:
    res += min(b, was)
    was = b

print(res + B[-1])

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 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(x) for x in input().split()]
ans = [0 for x in range(n)]

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
B = [int(i) for i in input().split(" ")]
B.append(10**5+1)
Sum = B[0]

for i in range(N-1):
    Sum += B[i]
    if B[i+1]<B[i]:
        Sum = Sum -B[i] + B[i+1]
print(Sum)

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 = input()
n = int(n)
a_list = [0 for i in range(n)]
line = input()
b_list = line.split(" ")
b_list = [int(b) for b in b_list]

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

Submission status: Accepted

Solution code:
n = int(input())
b = [int(e) for e in input().split()]
div = [min(x,y) for x,y in zip(b,b[1:]+[100000])]
a = [b[0]] + div
print(sum(a))

Submission status: Accepted

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

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:
#abc 140 c
n=int(input())
b=list(map(int,input().split()))

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

Submission status: Accepted

Solution code:

n = int(input())
b = list(map(int,input().split()))
a = [b[0]]
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 = [b[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:
num = int(input())
b_list = list(map(int, input().split(" ")))

b_list.append(b_list[num-2])
ans_list = []
ans_list.append(b_list[0])

for i in range(1, num, 1):
    ans_list.append(min(b_list[i-1], b_list[i]))

print(sum(ans_list))

Submission status: Accepted

Solution code:
n=int(input())
b=map(int,input().split())
b=list(b)
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 = 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
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:
import sys
input = sys.stdin.readline
N = int(input())
B = [int(x) for x in input().split()]

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

print(sum(A))

Submission status: Accepted

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

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

a = [b[0]]

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

print(sum(a))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    B_list = list(map(int, input().split()))
 
    sum_point = B_list[-1]
    before_b = B_list[0]

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

if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

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

print(asum)

Submission status: Accepted

Solution code:
# coding: utf-8

n = int(input().rstrip())
b_list = list(map(int, input().rstrip().split(" ")))

a_list = list(range(n))

a_list[0] = b_list[0]
for i in range(1, n):
    if i >= len(b_list):
        a_list[i] = b_list[i - 1]
        break
    a_list[i] = min(b_list[i - 1], b_list[i])

print(sum(a_list))

Submission status: Accepted

Solution code:
n = int(input())
b = [int(x) for x in 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()))

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

ans = B[0] + B[-1]
for a,b in zip(B,B[1:]):
    ans += min(a,b)
print(ans)

Submission status: Accepted

Solution code:

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

sum = b[n - 2] + b[0]
for i in range(1, n - 1):
    #print("{0}:{1}".format(i, sum))#
    sum += min(b[i - 1], b[i])

print(sum)

Submission status: Accepted

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


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

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

Submission status: Accepted

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

A = [B[0]] + [-1]*(N-2) + [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()))
s = b[0] + b[-1]

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

Submission status: Accepted

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

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


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

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

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

    print(result)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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())
lis = list(map(int, input().split()))
result = []
result.append(lis[0])
for i in range(N-2):
    result.append(min(lis[i], lis[i+1]))
result.append(lis[N-2])
print(sum(result))

Submission status: Accepted

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

ans = 0

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

  
print(ans)

Submission status: Accepted

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

P.append(B[0])
for i in range(1,N-1):
    P.append(min(B[i-1],B[i]))
P.append(B[-1])
print(sum(P))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
import math
import bisect
input = sys.stdin.readline
MOD = 10**9 + 7
INF = float('INF')

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = B[0]

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

ans += B[N-2]

print(ans)

Submission status: Accepted

Solution code:
import collections


class Solution:
    def solve(self, N: int, B) -> int:

        answer = B[0]

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

        answer += B[N-2]

        return answer


if __name__ == '__main__':

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

    # solve
    solution = Solution()
    answer = solution.solve(N, B)
    print(answer)

Submission status: Accepted

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

def main():
    n = int(input())
    b = list(map(int, input().split()))
    a = []
    for i in range(n):
        if i == 0:
            a.append(b[0])
        elif i == n - 1:
            a.append(b[-1])
        else:
            a.append(min(b[i - 1], b[i]))
    print(sum(a))

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

print(sum(a))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

print(res)

Submission status: Accepted

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

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

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

print(res)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
#sys.setrecursionlimit(150000)


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

# Generated by 1.1.6 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(i) for i in input().split()][0]
Bn = [int(i) for i in input().split()]

An = [Bn[0]]
for n in range(1, N-1):
  An.append(min(Bn[n], Bn[n-1]))
An.append(Bn[-1])
print(sum(An))

Submission status: Accepted

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

Submission status: Accepted

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

base_lis = []
ans_lis = []  

for i in B:
    base_lis.append(i)
    base_lis.append(i)

ans_lis.append(base_lis[0])
base_lis.pop(0)
ans_lis.append(base_lis[-1])
base_lis.pop(-1)

for i in range(0,len(base_lis),2):
    ans_lis.append(min(base_lis[i],base_lis[i+1]))

print(sum(ans_lis))

Submission status: Accepted

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

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

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

a[0] = b[0]

print(sum(a))

Submission status: Accepted

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

Submission status: Accepted

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

def main():
  n = int(input())
  Bs = list(map(int, input().strip().split()))
  As = [Bs[0]]
  for i in range(1, len(Bs)):
    As.append(min(Bs[i], Bs[i-1]))
  As.append(Bs[-1])
  print(sum(As))
    

if __name__=='__main__':
  main()

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

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

if __name__ == '__main__':
	main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

inf = float('inf')

n, *b = map(int, sys.stdin.read().split())

def main():
    a = [inf] * n
    for i in range(n-1):
        a[i] = min(a[i], b[i])
        a[i+1] = min(a[i+1], b[i])
    return sum(a)

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

Submission status: Accepted

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

A = [0]*N
#Aの端にはBの端が入る
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 = [B[0]]
for i in range(1, N-1):
    A.append(min(B[i], B[i-1]))
A.append(B[-1])

ans = sum(A)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

B = [int(i) for i in 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=B[0]+B[N-2]
for x in range(N-2):
    if B[x]>=B[x+1]:
        ans+=B[x+1]
    else:
        ans+=B[x]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#python3
INF = int(1e9)
def main():
    n = int(input())
    b = [int(i) for i in input().split()]
    b.insert(0, INF)
    b.append(INF)
    ans = 0
    for i in range(len(b)-1):
        ans += min(b[i], b[i+1])
    print(ans)
main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans=[0]*n
ans[0],ans[1]=b[0],b[0]

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

Submission status: Accepted

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

Submission status: Accepted

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

print(a_sum)

Submission status: Accepted

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

ans.append(h[-1])


print(sum(ans))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N=int(input())
B=list(map(int,input().split()))
A=[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:
#入力（後でいじる）
def pin(type=int):
    return map(type,input().split())
#どっかで最悪計算量の入力データを用意する関数を作ろう？
"""
愚直に操作を実装する
"""
#solution:
N=int(input())
B=list(pin())
#まるでDPしてみろと言われた問題だな
A=[B[0]]+[0]*(N-2)+[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(x) for x in input().split()]

ans = [0] * N
ans[0] = B[0]
for i in range(len(B)):
  ans[i + 1] = B[i]
  if B[i] < ans[i]:
    ans[i] = B[i]
  elif B[i] < ans[i + 1]:
    ans[i+1] = B[i] 
  
print(sum(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
b=list(map(int,input().split()))
cnt=0
wa=0
while cnt<N-1:
    if cnt==0:
        wa+=b[0]
    
    
    else:
        wa+=min(b[cnt-1:cnt+1])
       
    cnt+=1
print(wa+b[N-2])

Submission status: Accepted

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

Submission status: Accepted

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

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

print(a)

Submission status: Accepted

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

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

print(sum(A))

Submission status: Accepted

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

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

print(sum(al))

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+=B[i+1] if B[i]>B[i+1] else B[i]
print(ans+B[N-2])

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

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

print(sum(a))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
"""
author : halo2halo
date : 4, Feb, 2020
"""

import sys

# import numpy as np


read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, *B = map(int, read().split())
A = [B[0]]

for i, j in zip(B, B[1:]):
    if i <= j:
        A.append(i)
    else:
        A.append(j)
print(sum(A) + B[-1])

Submission status: Accepted

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

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

A[0] = B[0]
print(sum(A))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
B = LIST()

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

print(su + B[len(B) - 1])

Submission status: Accepted

Solution code:
def main():
  n,*b=map(int,open(0).read().split())
  c1,cn=b[0],b[-1]
  c=[min(i,j) for i,j in zip(b,b[1:])]
  print(c1+sum(c)+cn)
if __name__=="__main__":
  main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
b_list = list(map(int, input().split()))
a_list = [0 for _ in range(n)]
a_list[0] = b_list[0]
a_list[1] = b_list[0]

for i in range(1, len(b_list)):
    if b_list[i] > b_list[i-1]:
        a_list[i+1] = b_list[i]
    else:
        a_list[i] = b_list[i]
        a_list[i+1] = b_list[i]

print(sum(a_list))

Submission status: Accepted

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

for i in range(len(b)+1):
    if i ==0:
        a[i] = b[i]
    elif i == len(b):
        a[i] = b[i-1]
    
    else:
        a[i] = min(b[i],b[i-1])
    
    
print(sum(a))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
INF = float('inf')
B = [INF] + list(map(int,input().split())) + [INF]
ans = sum(min(a,b) for a,b in zip(B,B[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(n-1):
    if i==n-2:
        a.append(b[i])
    else:
        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()))

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

Submission status: Accepted

Solution code:
import sys

[N] = [int(x) for x in sys.stdin.readline().split(" ")]
Bs = [int(x) for x in sys.stdin.readline().split(" ")]
result = 0

prev_b = 999999
for i in range(N-1):
    b = Bs[i]
    result += min(prev_b, b)
    prev_b = b

result += prev_b

print(result)

Submission status: Accepted

Solution code:
N = int(input())

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

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

Submission status: Accepted

Solution code:
N = int(input())
inf = 10**10
*a, = map(int ,input().split())
b = [inf]+a+[inf]
print(sum(min(b[i], b[i+1]) for i in range(N)))

Submission status: Accepted

Solution code:
N = int(input())
B = list(map(int, input().split()))
ans = B[0] + B[-1]
if N >= 3:
  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 = [-1] * n
num = [i for i in range(n - 1)]
d = {}
for i, j in zip(b, num):
    d[j] = i
d = sorted(d.items(), key=lambda x: x[1])
for k, v in d:
    if a[k] == -1:
        a[k] = v
    if a[k + 1] == -1:
        a[k + 1] = v
print(sum(a))

Submission status: Accepted

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

Submission status: Accepted

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

A = [B[0]]

for i, b in enumerate(B):

    A += [b]
    if b < A[i]:
        A[i] = b

print(sum(A))

Submission status: Accepted

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

pre_b = 10**5+1  # Bのとりうる最大値+1
a_list = []
for i in range(len(b_list)):
  a_list.append(min(pre_b, b_list[i]))
  pre_b = b_list[i]
print(sum(a_list))