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

Submission status: Accepted

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

Submission status: Accepted

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

a = [b[0]]

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

print(sum(a))

Submission status: Accepted

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

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

    print(sum)


if __name__ == '__main__':
    c()

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=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:
import numpy

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

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

cnt += B[0]
cnt += B[-1]
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
B = list(map(int,input().split()))
A = [0] * n
ans = 0
A[0] = B[0]
for i in range(1,n-1):
  #print(B[i])
  A[i] = min(B[i],B[i-1])
A[n-1] = B[n-2]
print(sum(A))
#print(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:
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

N = int(sys.stdin.readline())
list_b = list(map(int, sys.stdin.readline().split()))
list_a = [0]*N
list_a[N-1] = list_b[N-2]

for i in range(N-1, 0, -1):
    if(list_b[i-2] < list_b[i-1]):
        list_a[i-1] = list_b[i-2]
    else:
        list_a[i-1] = list_b[i-1]

if(list_a[1] > list_b[0]):
    list_a[0] =list_a[1]
else:
    list_a[0] =list_b[0]

sum = 0

for i in range(N):
    sum += list_a[i]

# print(list_a)

print(sum)

Submission status: Accepted

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

def solve():
    n = int(input())
    bl = [int(i) for i in input().split()]
    bl = [bl[0]] + bl + [bl[-1]]
    ans = 0
    for i in range(n - 1, -1, -1):
        ans += min(bl[i + 1], bl[i])
    print(ans)

if __name__=="__main__":
    solve()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N = int(input())
B = list(map(int,input().split()))

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

print(num)

Submission status: Accepted

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

A=[]
zantei=B[-1]
for i in range(N-1):
    if B[N-2-i] < zantei:
        A.append(B[N-2-i])
    else:
        A.append(zantei)
    zantei = B[N-2-i]


A.append(zantei)

print(sum(A))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = input()
B = input()
BList = []
BList = B.split(" ")
A = []
outputList = []
output = 0
num = 0

if (int(N)<101) and (int(N) > 1): 
    for i in range(len(BList)):
        if i == 0:
            outputList.append(BList[i])
        else:
            if int(BList[i-1]) <= int(BList[i]):
                outputList.append(BList[i-1])
            else:
                outputList.append(BList[i])
    outputList.append(BList[-1])

    for i in outputList:
        output = output + int(i)
    print(output)

Submission status: Accepted

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

answer = 0

for i in range(n - 1):
    answer += b[i] * 2

    if i != n - 2:
        if b[i] < b[i + 1]:
            answer -= b[i + 1]
        else:
            answer -= b[i]

print(answer)

Submission status: Accepted

Solution code:
while True:
    try:
        N = int(input())
        B = map(int, input().split())
        prev = None
        result = list()
        for i in B:
            if prev is None:
                result.append(i)
            else:
                result.append(min(prev, i))
            prev = i
        result.append(prev)
        print(sum(result))
    except EOFError:
        break

Submission status: Accepted

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

A = [0] * n

if n == 2:
  A[0] = A[1] = B[0]
elif n == 3:
  A[0] = B[0]
  A[1] = min(B[0], B[1])
  A[-1] = B[-1]
elif n > 3:
  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()))


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

sum += b[n-2]

print(sum)

Submission status: Accepted

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

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

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

A.append(B[-1])
print(sum(A))

Submission status: Accepted

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

ans = []
bef = 1000000
for i in l:
  ans.append(min(i, bef))
  bef = i
#ans.append(l[0])
ans.append(l[n-2])
print(sum(ans))

Submission status: Accepted

Solution code:
N=int(input())

a=list(map(int,input().split(' ')))

r=[]
for it in a:
    r.append(it)

r.append(a[N-2])

for idx,it in enumerate(a):
    if(r[idx+1]>it):
        r[idx+1]=it
print(sum(r))

Submission status: Accepted

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

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

Submission status: Accepted

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

if __name__ == "__main__":
    C_MaximalValue()

Submission status: Accepted

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

A = []
A_sum = 0

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

Submission status: Accepted

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


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

Submission status: Accepted

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

A = 0

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

Submission status: Accepted

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

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

print(sum(A))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())  
B=list(map(int, input().split())) 
A = []
for i in range(len(B)):
    if i == 0:
        A.append(B[i])
    elif B[i] > B[i-1]:
        A.append(B[i-1])
    else:
        A.append(B[i])
    #print(B[i], B[i-1])
A.append(B[i])

print(sum(A))

Submission status: Accepted

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

Submission status: Accepted

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

def main():
    N = int(input())
    B = list(map(int,input().split()))
    B.reverse()
    Ap = B[0]
    S = 0
    for Bi in B:
        A = min(Bi,Ap)
        if Bi > Ap:
            Ap = Bi
        else:
            Ap = A
        S += A
    S += Ap
    print(S)
          

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())

str = input()
strList = str.split()
b = []
for x in strList:
    b.append(int(x))

l = len(b)
sum = b[l-1] + b[0]

for i in range(l-1):
    if b[i] < b[i+1]:
        sum += b[i]
    else:
        sum += b[i+1]

print(sum)

Submission status: Accepted

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

list_a[0] = list_b[0]
list_a[1] = list_b[0]
for i in range(1, n-1):
  if list_b[i] < list_a[i]:
    list_a[i] = list_b[i]
    list_a[i+1] = list_b[i]
  else:
    list_a[i+1] = list_b[i]

print(sum(list_a))

Submission status: Accepted

Solution code:
a = int(input())

s = input().split()

lis = [int(s[0]),int(s[a-2])]

for i in range(a-1)[1:]:
    inp = min(int(s[i]),int(s[i-1]))
    
    lis.append(inp)

count = 0
for p in lis:
    count += p
    
print(count)

Submission status: Accepted

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

print(s)

Submission status: Accepted

Solution code:
N = int(input())
AList = [ 0 for i in range(N)]
BList = [int(i) for i in input().split()]
AList[1-1] = BList[1-1]
AList[N-1] = BList[N-1-1]
for k in range(N):
    if 2 <= k and k <= N-1 and BList[k-1-1] <= BList[k-1]:
        AList[k-1] = BList[k-1-1]
    elif 2 <= k and k <= N-1 and BList[k-1-1] > BList[k-1]:
        AList[k-1] = BList[k-1]
print(sum(AList))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""
n =  int(sys.stdin.readline())
b =  list(map(int, sys.stdin.readline().split()))

a = [0]*n
a[0]=b[0]

for i in range(1,n):
    if i !=n-1:
        a[i] = min(b[i],b[i-1])
    else:
        a[i] = b[i-1]
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:
        A.append(min(B[i-1], B[i]))

print(sum(A))

Submission status: Accepted

Solution code:
# C - Maximal Value
N = int(input())
B = list(map(int,input().split()))
A = [10**6]*N

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

print(sum(A))

Submission status: Accepted

Solution code:
n = int(input())
B = list(map(int,input().split()))+[float('inf')]

if n == 1:
	ans = B[0]*2
else:
	ans = B[0]
	for b,bb in zip(B[:-1],B[1:]):
		ans += min(b,bb)
print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

print(result)

Submission status: Accepted

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


    else:
        if B[i-1]<B[i]:
            mA.append(B[i-1])
        else:
            mA.append(B[i])


mA.append(B[N-2])
for i in range(N):
    aa+=mA[i]
print(aa)

Submission status: Accepted

Solution code:
_ = input()
b = list(map(int, input().split()))
s = b[0] + b[-1]
for be, af in zip(b[:-1], b[1:]):
  if be < af:
    s += be
  else:
    s += af
print(s)

Submission status: Accepted

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

sum = 0

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

n = n-1

out = b[0]

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

print(out)

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(min(b[i], b[i+1]))
    else:
        a.append(b[len(a)-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]
A[N-1] = B[N-1-1]
for i in range(1,N-1):
    A[N-1-i] = min(B[N-1-i],B[N-1-i-1])
print(sum(A))

Submission status: Accepted

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

_b = 101
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
for i in range(N):
    if i==0:
        ans+=B[i]
    elif i==N-1:
        ans+=B[i-1]
    else:
        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()]
res=B[0] + B[-1]
for i in range(0, 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()))
a = [b[0], b[n-2]]

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

print(sum(a))

Submission status: Accepted

Solution code:
N = int(input())
Blist = list(map(int, input().split()))
Alist = []
for i in range(0,N):
    Alist.append(0)
Alist[0] = Blist[0]
Alist[-1] = Blist[-1]
#print(Alist)
#print(Blist)

for i in range(1,N-1):
    Alist[i] = min(Blist[i-1],Blist[i])

ans = 0
for i in Alist:
    ans += i 

print(ans)

Submission status: Accepted

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

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

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

print(sum(A))

Submission status: Accepted

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

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

print(result)

Submission status: Accepted

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

for i in range(a):
    if i == 0:
        ans += b[0]
    elif i != a-1:
        A = b[i-1]
        B = b[i]
        if A > B:
            ans += B
        else:
            ans += A
    else:
        ans += b[-1]
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    _ = int(stdin.readline().rstrip())
    Bs = [int(x) for x in stdin.readline().rstrip().split()]
    result = Bs[0]
    for i, B in enumerate(Bs[:-1]):
        result += min(B, Bs[i + 1])
    result += Bs[-1]
    print(result)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# そのまま入力文字列の入力
n = int(input())
bn = list(map(int, input().split()))

an = []

if n == 2:
    print(bn[0] * n)
    exit(0)

for i in range(0, n - 1 - 1):
    b = bn[i]
    if i == 0:
        an.append(bn[0])
    an.append(min(bn[i], bn[i+1]))

an.append(max(an[-1], bn[-1]))

print(sum(an))

Submission status: Accepted

Solution code:
num = int(input())
array = list(map(int, input().split()))
sum = 0
 
for i in range(num):
	if i == 0:
		sum += array[i]
	elif i < (num-1):
		if array[i] > array[i-1]:
			sum += array[i-1]
		else:
			sum += array[i]
	else:
		sum += array[i-1]
        
print(sum)

Submission status: Accepted

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

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

print(sum(a))

Submission status: Accepted

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

a = []
b = [10**6] + b
for i in range(1, len(b)):
    b0, b1 = b[i - 1], b[i]
    if b0 > b1:
        a.append(b1)
    else:
        a.append(b0)
a.append(b[-1])
print(sum(a))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
B = [int(_) for _ in input().split()][::-1]
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:
import copy 
import numpy as np

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

A = [0]*N

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

ret=0
bs=0
for i,b in enumerate(B):
  if i==0:
    ret+=b
  else:
    if bs<b:
      ret+=bs
    else:
      ret+=b
  bs=b

ret+=B[-1]
print(ret)

Submission status: Accepted

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

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

print(sum(a))

Submission status: Accepted

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

ans+=sum(b)

print(ans)

Submission status: Accepted

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

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

x+= int(b[n-2])

print(x)

Submission status: Accepted

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

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

print(sum(A))

Submission status: Accepted

Solution code:
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations
import sys
import bisect
import string
import math
import time
ts=time.time()
sys.setrecursionlimit(10**6)
def SI():
    return input().split()
def MI():
    return map(int,input().split())
def I():
    return int(input())
def LI():
    return [int(i) for i in input().split()]
YN=['Yes','No']
mo=10**9+7

n=I()
b=LI()
ans=0

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

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

Submission status: Accepted

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

a.append(b[0])

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

a.append(b[n-2])
print(sum(a))

Submission status: Accepted

Solution code:
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
from itertools import accumulate
# from functools import reduce
# from itertools import accumulate
def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""


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

"""
for i in range(N - 2, 0, -1):
    if L[i] < L[i -1]:
        L[i - 1] = L[i]
print(L)
X = accumulate(L)
print(list(X)[-1] + L[0])
"""

X = [L[0]]

for l1, l2 in zip(L, L[1::]):
    X.append(min(l1, l2))
X.append(L[-1])
print(sum(X))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

testA = B + [0]
testB = [0] + B
#print(testA)
#print(testB)
#print((np.array(testA)-np.array(testB))[:len(B)])
temp = (np.array(testA)-np.array(testB))[:len(B)]
#print(temp[temp < 0])
res = sum(temp[temp < 0])
#print(res)
print(B[0] + sum(B) + res)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
def main():
    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))
if __name__ == "__main__":
    main()

Submission status: Accepted

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

b2 = [b[0]]
b2.extend(b)
b.append(b[n-2])

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

print(ans)

Submission status: Accepted

Solution code:
def main():

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

result = 0

for index in range(N-1):
    if index == 0:
        result += A[0]
    else:
        result += min(A[index], A[index-1])

result += A[len(A)-1]

print(result)

Submission status: Accepted

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

a_sub = input().split(" ")
a = [int(n0) for n0 in a_sub]
# print(a)

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

for xi in range(1,N-1):
    if a[xi-1]<a[xi]:
        s = s+a[xi-1]
    else:
        s = s+a[xi]

print(s)

Submission status: Accepted

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

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

if __name__ == "__main__":
    main()

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[N - 2]
    else:
        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] * N

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

for i in range(1, N-1):
    if A[i] <= B[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()))

def main(n, b_list):
    b_list.append(b_list[-1])
    result = b_list[0] + b_list[-1]
    for i in range(n-2):
        result += min(b_list[i], b_list[i+1])
    return result

print(main(n, b_list))

Submission status: Accepted

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

if N == 2:
    t += B[0]
else:
    for i in range(N - 2):
        if i == 0:
            if B[i] <= B[i + 1]:
                t += 2 * B[i]
            else:
                t += B[i] + B[i + 1]
        else:
            if B[i] <= B[i + 1]:
                t += B[i]
            else:
                t += B[i + 1]

print(t + B[N - 2])

Submission status: Accepted

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

a = []
sum_a = b[0] + b[-1]
for i,b_i in enumerate(b):
    
    if i+1 < n-1:
        if b[i+1] >= b[i]:
            a.append(b[i])
            sum_a += b[i]
        else:
            a.append(b[i+1])
            sum_a += b[i+1]
print(sum_a)

Submission status: Accepted

Solution code:
N = int(input())
B = list(map(int, input().split()))
A = [10 ** 6] * N
for n in range(N - 1):
  A[n] = min(B[n], A[n])
  A[n + 1] = min(B[n], A[n + 1])
  
print(sum(A))

Submission status: Accepted

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

count=0

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

count+=B[0]+B[n-2]

print(count)

Submission status: Accepted

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

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
N = int(input())
BBB = list(map(int, input().split()))
BBB += [10**5]

AAA = [0] * N

AAA[0] = BBB[0]

for i, B in enumerate(BBB[:-1]):
    AAA[i + 1] = min(B, BBB[i + 1])

print(sum(AAA))

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

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

Submission status: Accepted

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

a = [B[0]]
for i, no in enumerate(B):
    if i == len(B) - 1:
        a.append(B[i])
    else:
        a.append(min(B[i], B[i + 1]))

print(sum(a))

Submission status: Accepted

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

a = [0] * n
a[0] = b[0]

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

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

print(sum(a))