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(raw_input())
B = list(map(int, raw_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] = 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 = input().split()
b = [int(i) for i in b]

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

if len(b) >= 2:
  for i in range(n-2):
    sums += int(min([b[i], b[i+1]]))


print(sums)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
B = list(map(int, input().split()))
B.append(B[-1])
ans = B[0]
for i in range(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(' ')))

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:
def main():
    n = int(input())
    b = [i for i in map(int, input().split())]
    b.append(max(b)+1)
    a = []
    for j, num in enumerate(b):
        a.append(min(b[j-1], b[j]))

    print(sum(a))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
N = int(input())-1
b=list(map(int,input().split()))
a=b[0]
for i in range(1,N,1):
    if b[i] >= b[i-1]:
        a+=b[i-1]
    else: a+=b[i]
a+=b[N-1]
print(a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def read_input():
	N = int(raw_input())
	B = map(int, raw_input().split())
	return B


#################### main ####################

#t0 = time.clock()
B = read_input()
s = B[0] + sum(min(b1, b2) for b1, b2 in zip(B, B[1:])) + B[-1]
print s

Submission status: Accepted

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

N = int(input())
B_list = list(map(int,input().split()))
A_list = []
A_list.append(B_list[0])

for i in range(len(B_list)-1):
     B_i = B_list[i]
     B_j = B_list[i+1]
     A_list.append(min(B_i, B_j))

A_list.append(B_list[N-2])

print(sum(A_list))

Submission status: Accepted

Solution code:
n = int(input())

b = list(map(int, input().split()))
b.insert(0, 9999999)

ans = 0
for i in range(1, len(b)):
    if b[i] < b[i-1]:
        ans += b[i]
    else:
        ans += b[i-1]
ans += b[-1]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = list(map(int, input().split()))
S = [10**5+1] + S + [10**5+1]
ans = []
for i in range(1, N+1):
    ans.append(min(S[i-1], S[i]))
print(sum(ans))

Submission status: Accepted

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

M = 10 ** 5 + 1 # sentinel
B = [M] + B + [M]

R = []

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

print(sum(R))

Submission status: Accepted

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

a = [-float('inf') for i in range(n)]
a[0] = a[1] = b[0]

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:
a= int(input())
l = list(map(int,input().split()))
l = l[::-1]
s = l[-1]
for n,(x,y) in enumerate(zip(l,l[1:])):
    s+= min(x,y)
print(s+l[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import copy
N = int(input())
b = list(map(int, input().split()))
a = copy.copy(b)
a.insert(0, b[0])

for i in range(N-1):
    if a[i] > b[i]:
        a[i] = b[i]
    if a[i+1] > b[i]:
        a[i + 1] = b[i]
    else:
        continue
        
print(sum(a))

Submission status: Accepted

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

Submission status: Accepted

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

print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    array = list(map(int, input().split()))
    sum_value = array[-1] + array[0]
    for i in range(n-2):
        sum_value += min(array[i], array[i+1])
        # print(array[i])
    print(sum_value)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    B = [int(i) for i in input().split()]
    A_sum = 0
    A = []
    A.append(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])
    
    for i in range(N):
        A_sum += A[i]
    print(A_sum)
        
if __name__ == "__main__":
    main()

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[N-1] = B[N-2]
ans = sum(A)
print(ans)

Submission status: Accepted

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

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

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

ans = 0
for i, b in enumerate(B):
    if i == 0:
        ans += b
    else:
        ans += min(b, prev)
    prev = b
ans += prev
print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
L1 = input()
L2 = list(map(int,input().split(" ")))
LA = [0]*int(L1)

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

Submission status: Accepted

Solution code:
import numpy as np
N=int(input())
B=list(map(int,input().split()))
A=np.zeros(N,dtype="int64")

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()) #waiting_for_pudging
b = list(map(int, input().split())) #waiting_for_pudging
summ = b[0] #waiting_for_pudging

for i in range(1, len(b)): #pudging
    summ += min(b[i-1], b[i]) #pudging
print(summ + b[-1]) #pugding
#accepted

Submission status: Accepted

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


def solve(N: int, B: "List[int]"):

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

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

    print(result)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    B = [int(next(tokens)) for _ in range(N - 1)]  # type: "List[int]"
    solve(N, B)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
b = [int(elem) for elem in input().split()]
a = [b[n - 2]]

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

Submission status: Accepted

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

Astar = [
  min(Bn[i], Bn[i+1])
  for i in range(N)
]
print(sum(Astar))

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

Submission status: Accepted

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

A = [0 for _ in range(N)]

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

print(sum(A))

Submission status: Accepted

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

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

sum = 0

for ib, value in enumerate(B):
    if ib > 0:
        if value >= B[ib-1]:
            sum += B[ib-1]
        else:
            sum += value
    else:
        sum += value

sum += B[len(B) - 1]
print(sum)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math

N = int(input())
B = list(map(int, input().split())) 
import numpy as np
A=np.zeros([N])
for i in range(N):
    if i == 0:
        A[i] = B[i]
    elif i== N-1:
        A[i] = B[i-1]
    else:
        A[i] = min(B[i-1],B[i])

print(int(A.sum()))

Submission status: Accepted

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

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

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

print(sum(a))

Submission status: Accepted

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


def solve(N: int, B: "List[int]"):
    A = [B[0]]
    for i in range(len(B)-1):
        A.append(min(B[i],B[i+1]))
    A.append(B[-1])

    print(sum(A))




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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

ans += b[0]
ans += b[n - 2]
print(ans)

Submission status: Accepted

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

a = [b[0]]

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

print(sum(a))

Submission status: Accepted

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

a = [b[0]]

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

    while b[i] < max(a[i], a[i+1]):
        a[i+1] += 1

print(sum(a))

Submission status: Accepted

Solution code:
N = int(input())
B = [100000] + [int(e) for e in input().split(" ")] + [100000]
ans = 0
for i in range(N):
    ans += min(B[i], B[i+1])

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
B = [100000] + [int(e) for e in input().split(" ")] + [100000, 100000]
ans = 0
for i in range(N):
    ans += min(B[i], B[i+1])

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
B = input().split()
Ap = [0 for i in range(N)]
for i in range(N-1):
    B[i] = int(B[i])
for i in range(N):
    if i != 0 and i != N-1:
        Ap[i] = min({B[i-1],B[i]})
    elif i == 0:
        Ap[i] = B[i]
    elif i == N-1:
        Ap[i] = B[N-2]

S = sum(Ap)
print(S)

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

Submission status: Accepted

Solution code:
n=int(input())
b=list(map(int, input().split()))
inf = 1e9
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])
print(sum(a))

Submission status: Accepted

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

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

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

print(s)

Submission status: Accepted

Solution code:
t=int(input())
b=[int(i) for i in input().split()]
a=[0]*t 
a[0]=b[0]
for i in range(1,t):
    if i<t-1:
        if b[i-1] < b[i]:
                a[i] = b[i-1]
        else:
            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 = [0] * N

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

Submission status: Accepted

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    b = list(map(int, input().rstrip('\n').split()))
    a = [10 ** 10] * n
    for i in range(n-1):
        a[i] = min(b[i], a[i])
        a[i+1] = min(b[i], a[i+1])
    print(sum(a))


if __name__ == '__main__':
    slove()

Submission status: Accepted

Solution code:
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

def main():
    N = INT()
    B = [inf] + LIST() + [inf]
    sumv = 0
    for i in range(N):
        sumv += min(B[i], B[i+1])
    print(sumv)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

a = []
a.append(b[0])
for i in range(1,n-1):
    add = min(b[i-1], b[i])
    a.append(add)
a.append(b[n-2])
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(0, 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()))
i=0
ans=0
while i!=n:
    if i==0:
        ans+=b[i]
    elif i==(n-1):
        ans+=b[i-1]
    else:
        c=[b[i],b[i-1]]
        ans+=min(c)
    i+=1

print(ans)

Submission status: Accepted

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

maximum_sum = 0

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

print maximum_sum

Submission status: Accepted

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


A = []
A.append(B[0])
i = 1
while i < (N -1):
	A.append(min(B[i], B[i-1]))
	i += 1
A.append(B[-1])
print(sum(A))

Submission status: Accepted

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

a=0
for i in range(len(B)-1):
	if B[i]<=B[i+1]:
		a+=B[i]

	else:
		a+=B[i+1]

print(a+B[0]+B[-1])

Submission status: Accepted

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

A = 0

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

Submission status: Accepted

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

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

print(total)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(result)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(100000)

def ins(): return input().split()
def ii(): return int(input())
def iil(): return list(map(int,ins()))
def lin(): return list(input())
def iin(): return map(int,ins())

n = ii()
b = iil()
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())
bs = list(map(int, input().split(' ')))

ret = bs[0]
for i in range(len(bs) - 1):
    ret += min(bs[i: i+2])
ret += bs[-1]

print(ret)

Submission status: Accepted

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

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

print(sum(A))

Submission status: Accepted

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

Submission status: Accepted

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

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

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

list.append(B[N-2])

print(sum(list))

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:
num = int(input())
int_row = list(map(lambda x: int(x), input().split(" ")))
ans = 0
for i in range(num):
    if i == 0:
        ans += int_row[0]
    elif i == num - 1:
        ans += int_row[-1]
    else:
        ans += min(int_row[i - 1], int_row[i])
print(ans)

Submission status: Accepted

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

A = []

A.append(B[0])

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

print(sum(A))

Submission status: Accepted

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

sum = b[0]

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

sum += b[n-2]

print(sum)

Submission status: Accepted

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

output = sum(a)
print(output)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

A = []

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

print(sum(A))

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(5 * 10**5)
input=sys.stdin.readline

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 numpy as np
N = input()
N = int(N)
B = np.hstack([int(a) for a in input().split()])

A = np.zeros(N)
A[0] = B[0]
A[-1] = B[-1]
for i in range(N-2):
  A[i+1] = min(B[i], B[i+1])
               
print(int(np.sum(A)))

Submission status: Accepted

Solution code:
num = int(input())
comp = [int(s) for s in input().split()]
answer = comp[0]
for i in range(num -2):
  if comp[i] >= comp[i + 1]:
  	answer+=comp[i + 1]
  else:
    answer += comp[i]
answer += comp[-1]
print(answer)

Submission status: Accepted

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

for i in range(N-2):
    m=min(B[i],B[i+1])
    A.append(m)
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):
    ans += min(b[i],b[i+1])
ans += b[-1]

print(ans)

Submission status: Accepted

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

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

print(sum(A))

Submission status: Accepted

Solution code:
from sys import stdin
from math import factorial
n = int(stdin.readline().rstrip())
b = list(map(int,stdin.readline().rstrip().split()))
point = 0
point += b[0]
for i in range(n-2):
    point += min(b[i],b[i+1])
point += b[n-2]
print(point)

Submission status: Accepted

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

import sys

N = int(sys.stdin.readline())

a = []
b = list(map(int, sys.stdin.readline().rstrip().split()))

# print(b)
# aはbよりも1項多い
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:
N=int(input())
B=[int(b) for b in input().split()]
A=[int(a) for a in range(N)]



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

print(sum(A))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
import math

def input():
    return sys.stdin.readline().strip()

def iinput():
    return int(input())

def finput():
    return float(input())

def tinput():
    return input().split()

def rinput():
    return map(int, tinput())

def rlinput():
    return list(rinput())

def pro(k, l, n):
    if l < n:
        if k == 0:
            return(n - l)
        return (n - l + 2)
    if l == n:
        if k == 0:
            return 0
        elif k == 1:
            return 1
        return 3
    else:
        l -= n - 1
        if l == k:
            return 1
        elif l > k:
            return 0
        if l < k - 1:
            return 2
        else:
            return 3
            

def rt(k, l , n):
    if k < n:
        if l == 0:
            return (k * 2 + n)
        return (n + k * 2 - 1)
    elif k == n:
        if l == 1:
            return (k * 3 - 2)
        elif l == 0:
            return (k * 3)
        return (k * 3 - 3)
    else:
        k -= n - 1
        if k == l:
            return (n * 3 - 2)
        elif k > l:
            return (n * 3)
        if k < l - 1:
            return ((n - 1) * 3 - 1)
        else:
            return ((n - 1) * 3)



def main():
    n = iinput()
    a = rlinput()
    res = a[0] + a[-1]
    for i in range(n - 2):
        if a[i] > a[i + 1]:
            res += a[i + 1]
        else:
            res += a[i]
    print(res)
    
    
    
    
    


main()

Submission status: Accepted

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

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

Submission status: Accepted

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

cnt = B[0]

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

cnt += B[N-2]

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

a = list();
a.append(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 str(input()).split(" ")]
a = [0] * (n)

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

  if i == n - 1 - 1:
    a[i + 1] = b[i]
  else:
    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()))

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

Submission status: Accepted

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

for i in range(len(B)):
    A[i] = B[i]
    A[i+1] = B[i]

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

print(a + b[0] + b[n-2])

Submission status: Accepted

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

Submission status: Accepted

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

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

print(hoge)

Submission status: Accepted

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

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 = input().split()
b = [int(s) for s in b]
a = []
for i in range(len(b)+1): a.append(-1)
a[0] = b[0]
for i in range(len(b)-1):
        if b[i] < b[i+1]: a[i+1] = b[i]
        else: a[i+1] = b[i+1]
a[len(b)] = b[len(b)-1]
#print(a)
print(sum(a))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def solve(n, b):
    ans = 0
    for i in range(n):
        if i == 0:
            ans += b[0]
        elif i == n-1:
            ans += b[-1]
        else:
            ans += min(b[i-1], b[i])
    return ans

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
B = list(map(int, input().split()))
C = B[:]
C.pop(0)
C.append(1e5)

maximum = B[0] + sum([min(b, c) for b, c in zip(B, C)])
print(maximum)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
b = list(map(int, input().split()))
sum = 0
for i in range(N):
    if i==0:
        sum += b[0]
    elif i==N-1:
        sum += b[N-2]
    else:
        sum += min([b[i-1], b[i]])
print(sum)