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:
def maximal():
    N = int(input())
    B = input()
    B = B.split()
    B = [int(i) for i in B]
    # length of values is N
    # any number more or equals than 0
    result = []
 
    result.append(B[0])
 
    for i in range(0, len(B) - 1):
        # if value is same put in first one
        compared = B[i]
        if B[i + 1] <= compared:
            result.append(B[i + 1])
        else:
            result.append(B[i])
 
    result.append(B[len(B) - 1])
    return sum(result)
 
 
print(maximal())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = b[0]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#Nは数列の数
N=int(input())
#Bi=>max(Ai,Ai+1)を満たす
B = list(map(int, input().split()))
#数列Aは未知数
A = []

#Aの一個目はB[0]を挿入
A.append(B[0])

for i in range(1, len(B)):
    #(処理)
    A.append(min(B[i-1],B[i]))
    

#Aの一番最後はB[N-1]を挿入
A.append(B[N-2])
    


#結果を表示する
print(sum(A))

Submission status: Accepted

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

MOD = 10 ** 9 + 7

N = int(input())
BN = list(map(int, input().split())) + [10**6]

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(1, n-1):
    a_arr[i] = min(b_arr[i-1], b_arr[i])

print(sum(a_arr))

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:
def solve():
  n = int(input())
  b = list(int(i) for i in input().split())
  ans = 0
  
  if n == 2:
    ans = b[0]*2
  else:
    ans = b[0]
    ans += b[-1]
    first = b[0]
    for i in range(n-2):
      nextvalue = b[i+1]
      ans += min(first,nextvalue)
      first = nextvalue
  print(ans)
solve()

Submission status: Accepted

Solution code:
n = int(input())
lineb = input().split(" ")
total_a = int(lineb[0])

for i in range(n - 2):
    if int(lineb[i]) <= int(lineb[i+1]):
        total_a += int(lineb[i])
    else:
        total_a += int(lineb[i+1])
        
total_a += int(lineb[n-2])
        
print(total_a)

Submission status: Accepted

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

"""
Bs[i] >= max(As[i], As[i+1]) を満たす条件で、

sum(As)の最大値を求める問題
"""

def solve():
    N = int(sys.stdin.readline())
    Bs = list(map(int, sys.stdin.readline().split()))

    if N == 2:
        print(Bs[0]*2)
        return

    # 初期値を決める
    As = [0] * N
    if Bs[0] <= Bs[1]:
        As[0] = As[1] = Bs[0]
    else:
        As[0], As[1] = Bs[0], Bs[1]

    # 貪欲法
    for i in range(1, N-2):
        if Bs[i] > Bs[i+1]:
            # As:   ?    0
            # Bs: 153    0
            As[i+1] = Bs[i+1]
        else:
            # As:   ?  153
            # Bs: 153  160
            As[i+1] = Bs[i]
    As[N-1] = Bs[N-2]

    print(sum(As))



if __name__ == "__main__":
    solve()

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

v = bl[0]

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

v += bl[n-2]

print(v)

Submission status: Accepted

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

count = a[0]

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(maximal)

Submission status: Accepted

Solution code:
from sys import stdin

N = int(stdin.readline())
B = list((int(wd) for wd in stdin.readline().split()))

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
_,b=open(0);*b,=map(int,b.split());print(b[0]+sum(map(min,zip(b,b[1:])))+b[-1])

Submission status: Accepted

Solution code:
_,b=open(0);*b,=map(int,b.split());print(b[0]+sum(min(t)for t in zip(b,b[1:]))+b[-1])

Submission status: Accepted

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

Submission status: Accepted

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

ans_list.append(b_list[-1])

print(sum(ans_list))

Submission status: Accepted

Solution code:
n=int(input())
b=list(map(int,input().split()))
a=b[0]+b[n-2]
if n>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(" ")))

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

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

Total = sum(A)
print(Total)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

print(sum(A))

Submission status: Accepted

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

output=0

for i in range(N):
   # print("i",i)
   if (i==0):
      A[i]=B[i]
   elif(i==N-1):
      # print("last",B[i-1])
      A[i]=B[i-1]
   else:
      if(B[i-1]<=B[i]):
         A[i]=B[i-1]
      else:
         A[i]=B[i]


# print("A:",A,"B:",B)
print(sum(A))

Submission status: Accepted

Solution code:
N = int(input())
B = list(map(int, input().split()))
A = [0]*(len(B)+1)
A[0] = B[0]
A[1] = B[0]
cnt = 0
for i, x in enumerate(B):
    if i != 0:
        A[i + 1] = B[i]
        A[i] = min(A[i], B[i])
    cnt += A[i]
cnt += A[-1]
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())

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


print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

i = 0
while i < n - 2:
	s += min(b[i], b[i + 1])
	i += 1

print(s)

Submission status: Accepted

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

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

Submission status: Accepted

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

A_list[0] = B_list[0]

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

A_list[-1] = B_list[-1]
print(sum(A_list))

Submission status: Accepted

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

sum_aaa = B_list[0]

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

sum_aaa += B_list[-1]
print(sum_aaa)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

A = [0] * N

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

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

print(sum(A))

Submission status: Accepted

Solution code:

import numpy as np
if __name__ == "__main__":
    
   
    dim = int(input())
    B = [int(x) for x in input().split()]
    
    A =[B[0]]

    for x in range(dim-2):
        A.append(np.amin((B[x],B[x+1])))
    
    A.append(B[-1])

    print(np.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-1):
 if(i != N-2):
  A.append(min(B[i],B[i+1]))
 else:
  A.append(B[i])
  
ans = sum(A)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
B = [int(_) for _ 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=[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:
# -*- coding: utf-8 -*-


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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = [0]*(len(a) + 1)
for i, name in enumerate(a):
    if i == 0:
        ans[i] = name
        ans[i+1] = name
    else:
        ans[i] = min(name, a[i - 1])
        ans[i+1] = name

print(sum(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
class ABC140C:

    def __init__(self):
        self.nNum = int(input())
        self.bList = list(map(int, input().split()))

    def solve(self):
        aList = [0] * self.nNum
        aList[0] = self.bList[0]
        for i in range(self.nNum - 1):
            if self.bList[i] < aList[i]:
                aList[i] = self.bList[i]
            aList[i + 1] = self.bList[i]

        print(sum(aList))


if __name__ == '__main__':
    ABC140C().solve()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())

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

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

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

print(sum(A))

Submission status: Accepted

Solution code:
N = int(input())
B = list(map(int, input().split()))
B.append(B[-1])
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=[]
A.append(B[0])
if n>=3:
    for i in range(n-2):
      m=min(B[i],B[i+1])
      A.append(m)
    last=B[n-2]
    A.append(last)
else:
    A.append(B[0])

print(sum(A))

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

MAX_VALUE = 10e9


def solve(B, n):
    B = [MAX_VALUE] + B + [MAX_VALUE]
    result = 0
    for i in range(n):
        result += min(B[i], B[i + 1])

    return result


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

    answer = solve(B, n)
    print(answer)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from sys import stdin
n = int(stdin.readline().rstrip())
b = list(map(int, stdin.readline().rstrip().split()))
b.append(float('inf'))
res = []
for i in range(n-1, -1, -1):
    if i != 0:
        res.append(min(b[i], b[i-1]))
    else:
        res.append(b[i])
print(sum(res))

Submission status: Accepted

Solution code:
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:
N = int(input())
Bs = list(map(int, input().split()))
Bs = [Bs[0]] + Bs + [Bs[-1]]

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

Submission status: Accepted

Solution code:
N = int(input())
b = input().split()
B = []
for i in range(N-1):
  B.append(int(b[i]))

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])
Asum = 0
for i in range(N):
  Asum += A[i]
print(Asum)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np
input()
a = list(map(int,input().split()))
print(np.minimum(np.insert(a,0,a[0]),np.append(a,a[-1])).sum())

Submission status: Accepted

Solution code:
def main():
  n = int(input())
  restrictionArray = list(map(int,input().split()))
  resultArray = [0] * (n+1)
  restrictionArray.append(10000000)
  
  for i in range(n):
    resultArray[i] = min(restrictionArray[i],restrictionArray[i-1])
   
  resultSum = sum(resultArray)
  
  print(resultSum)
  
main()

Submission status: Accepted

Solution code:
def solve_c(n, b_list):
    
    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 - 1], b_list[i])
        
    return sum(a_list)


def main():
    
    n = int(input())
    b_list = list(map(int, input().split()))
    
    print(solve_c(n, b_list))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
if (__name__ == '__main__'):
    n = int(input())
    dataline = input().strip().split()

    b = []
    for i in range(n-1):
        b.append(int(dataline[i]))

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


    print(thesum)

Submission status: Accepted

Solution code:
from copy import deepcopy
import itertools
from bisect import bisect_left
from bisect import bisect_right
import math
from collections import deque
from collections import Counter


def read():
    return int(input())


def readmap():
    return map(int, input().split())


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


INT_MAX = 10 ** 10


if __name__ == "__main__":
    N = read()
    B = [INT_MAX]
    B.extend(readlist())
    B.append(INT_MAX)

    print(sum([min(B[i], B[i-1]) for i in range(1, N+1)]))

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

Submission status: Accepted

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

print(sum(b))

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(sum(A))

Submission status: Accepted

Solution code:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

N = I()
B = III()

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:
import sys
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()))
INF = 10**8
n = INT()
B = LIST()
B.append(INF)
ans = B[0]
for i in range(n-1):
  ans += min(B[i], B[i+1])
 
print(ans)

Submission status: Accepted

Solution code:
if __name__ == "__main__":
 
    n = int(input())
    b_list = [int(b) for b in input().split()]
    a_list = []

    for i, b in enumerate(b_list):
        if i != 0:
            a_list.append(min(b_list[i], b_list[i - 1]))
            
    a_list.insert(0, b_list[0])
    a_list.append(b_list[len(b_list) - 1])
    print('{0}'.format(sum(a_list)))

Submission status: Accepted

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

s = bn[0] + bn[-1]
b0 = bn[0]
for bi in bn[1:]:
  s += min(b0, bi)
  b0 = bi
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(N-2):
  ans += min(B[i],B[i+1])

print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import deque
sys.setrecursionlimit(200000)
input = sys.stdin.readline

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

A = [B[0]] + [v for v in B]

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

print(sum(A))

Submission status: Accepted

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import bisect

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))
N = int(input())
B = LI()

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

Submission status: Accepted

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

MX = 100001

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

Submission status: Accepted

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

B = list(map(int,B))
total = 0


A[0] = B[0]

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

A[int(N)-1] = B[int(N)-2]
#print(A)
for i in range(int(N)):
    total = A[int(i)] + total

print(total)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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



if n == 2:
    ans = 2*b_list[0]

else:
    ans = b_list[0]
    
    for i in range(n-2):
        ans += min(b_list[i:i+2])

    ans += b_list[n-2]
    
print(ans)

Submission status: Accepted

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

for i in range(N-2):
    if b[i] > b[i+1]:
        a_list.append(b[i+1])
    
    else:
        a_list.append(b[i])

a_list.append(b[-1])

print(sum(a_list))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

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

Submission status: Accepted

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

a_list = [b_list[0]]
for i, b in enumerate(b_list):
    if a_list[i] > b:
        a_list[i] = b
    a_list.append(b)

print(sum(a_list))

Submission status: Accepted

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

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

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

print(sum(a))

Submission status: Accepted

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

A = [10 ** 6] * 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))

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

ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

  A[-1] = B[-1]

  print(sum(A))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=input()  
a=list(map(int,input().split()))
cnt=a[0]+a[len(a)-1]
for i,_ in enumerate(a):
  if i > 0:
    cnt+=min(a[i],a[i-1])
print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np
input()
a = np.array(list(map(int,input().split())))
print(np.minimum(a[1:],a[:-1]).sum()+a[0]+a[-1])

Submission status: Accepted

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

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

print(sum(A))

Submission status: Accepted

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

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()))
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())
A = [float("inf")] * n
B = list(map(int, input().split()))

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