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:
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial, log, log10, log2
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
from datetime import datetime as dt

def main():
  n = int(readline())
  b = list(map(int, readline().split()))
  a = [0]*n
  for i in range(n):
    if i == 0:
      a[0]=b[0]
    elif i == n-1:
      a[n-1] = b[n-2]
    else:
      a[i] = min(b[i-1], b[i])
  print(sum(a))
  
  
  
  
  
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

n = INT()
b = LIST()
a = [0 for _ in range(n)]
for i in range(n - 1):
    if i > 0:
        if b[i - 1] >= b[i]:
            a[i] = b[i]
        else:
            a[i] = b[i - 1]
    else:
        a[i] = b[i]
a[-1] = b[-1]
print(sum(a))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
b = [int(i) for i in input().split()]

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

#最初と最後
s = B[0] + B[N-2]
#中
for i in range(1,N-1):
    s += min([B[i-1],B[i]])
    
print(s)

Submission status: Accepted

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

ai = aj = seqB[0]
seqA = [ai,aj]
for i in range(1, len(seqB)):
  aj = max(aj, seqB[i])
  if aj > seqB[i]: 
    aj = seqA[i] = seqB[i]
  seqA.append(aj)

print(sum(seqA))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = b[0]

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

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

Submission status: Accepted

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

#print(n)
#print(b)

score = b[0]+b[n-2]
#print(b[0],b[n-2])

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

Submission status: Accepted

Solution code:
N = int(input())
Bi = list(map(int, input().split()))
listA = [0 for i in range(N)]
listA[N-1] = Bi[N-2]
gokei = 0
listA[0] = Bi[0]
for j in range(N-2, 0, -1):
    listA[j] = min(Bi[j], Bi[j-1])

for k in listA:
    gokei += k
print(gokei)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

print(sum(A))

Submission status: Accepted

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

print(sum(A))

Submission status: Accepted

Solution code:
n = int(input())
blist=list(map(int,input().split()))
alist=[]

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

Submission status: Accepted

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

print(sum(A_max))

Submission status: Accepted

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

# First input is:
# "N" -- integer number of things in the sequnece

# Second input is:
# "B1 B2 B3 ... B(N-1)" -- sequence of B, length N-1
# Each B_i is a non-negative integer

# e.g.
# 5
# 12 0 23 1

input() # Discard first input
Blist       = list(map(int,input().split())) # Create list of B, type int

maxB        = max(Blist) 
Bit1        = iter([maxB] + Blist)  #  Creating two iterators to take
Bit2        = iter(Blist + [maxB])  # consecutive pairwise minimum
pairBit     = zip(Bit1,Bit2)        # along the list of B.

maxAsum     = sum(map(min,pairBit)) # Maximum sum of A is sum of minima

print(maxAsum)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

else:
    ans = b[0] + b[-1]

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(sum(a))

Submission status: Accepted

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

ret = b_list[0]
ret += b_list[-1]

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

print(ret)

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))

def main():
    N = int(input())
    B = input_nums()
    B = B[::-1]
    A = [B[0], B[0]]
    for b in B[1:]:
        if A[-1] > b:
            A.pop()
            A.append(b)
            A.append(b)
        else:
            A.append(b)
    print(sum(A))

if __name__ == '__main__':
    main()

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

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    B = list(map(int, input().split()))
    B = [10**9] + B + [10**9]
    curr_sum = 0
    for i in range(1, len(B)):
        curr_sum += min(B[i-1], B[i])
    print(curr_sum)

resolve()

Submission status: Accepted

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

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

print(sum(a))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
N=int(input())
B=list(map(int,input().split()))
if(N==2):
    print(B[0]*2)
    sys.exit()
before=B.pop(0)
ans=before
for b in B:
    ans+=min(before,b)
    before=b
ans+=B[-1]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
limit = 10**10
for i in range(n-1):
    if limit>b[i]:
        ans += b[i]
    else:
        ans += limit
    limit = b[i]
ans += limit
print(ans)

Submission status: Accepted

Solution code:
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
B = np.array(lr() + [10 ** 6])
answer = B[0] + np.minimum(B[:-1], B[1:]).sum()
print(answer)

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

def ri():
    return int(input())

def rl():
    return list(input().split())

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

def main():
    n = ri()
    lb = rli()
    ans = lb[0]+lb[-1]
    for i in range(1,n-1):
        ans += min(lb[i-1],lb[i])
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
n=int(input())
b=list(map(int,input().split()))
a=[0]*n
a[0]=b[0]
a[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:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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:
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 25 10:07:17 2020

@author: Kanaru Sato
"""

N = int(input())
B = list(map(int, input().split()))
count = B[0]+B[-1]

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

print(count)

Submission status: Accepted

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

A = [float('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:
import sys
import math

from collections import defaultdict
from collections import deque
def load(vtype=int):
    return vtype(input().strip())
def load_list(seplator=" ", vtype=int):
    return [vtype(v) for v in input().strip().split(seplator)]
def exit():
    import sys
    sys.exit(0)
def perm_sub(li, used):
    if len(li) == len(used):
        return [deque()]
    k = []
    for i in range(len(li)):
        if i in used:
            continue
        used.add(i)
        sub_list = perm_sub(li, used)
        for sub in sub_list:
            sub.appendleft(li[i])
        k.extend(sub_list)
        used.discard(i)
    return k
def perm_li(li):
    return perm_sub(li, set())
def perm_n(n):
    return perm_sub(list(range(n)), set())
def join_i(li, sep=""):
    return sep.join([str(e) for e in li])
def li2n(li):
    n, base = 0, 1
    for i in range(len(li)-1, -1, -1):
        n += li[i] * base
        base *= 10
    return n
def sli2ili(li):
    return [int(s) for s in li] 
def prime_list(n):
    li = [i for i in range(2, n+1)]
    for i in range(len(li)):
        if li[i] >= int(math.sqrt(n)):
            break
        if li[i] == -1:
            continue
        for j in range(i+1, len(li)):
            if li[j] % li[i] == 0:
                li[j] = -1
    return [n for n in li if n != -1]
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while True:
        r = a % b
        if r == 0: return b
        a, b = b, r
def lcm(a, b):
    return int(a * b / gcd(a,b))
def all_subset(li):
    s = []
    n = len(li)
    for bit in range(0, (1<<(n+1))):
        ss = set()
        for i in range(0, n):
            if (bit & (1 << i)):
                ss.add(li[i])
        s.append(ss)
    return s


n = load()
B = load_list()


r = [B[0]]

for i in range(0, len(B)-1):
    r.append(min(B[i], B[i+1]))

r.append(B[-1])

print(sum(r))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
B = list(map(int, input().split()))
ans = B[0] + B[-1]
for b1, b2 in zip(B,B[1:]):
    if b1 < b2:
        ans += b1
    else:
        ans += b2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#%%
import sys
def input():
    return sys.stdin.readline().rstrip()

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

    ans = 0
    for i in range(1,N-1): # loop over except 0 and -1
        ans += min(B[i-1],B[i])
    ans += (B[0]+B[-1]) # head and tail
    print(ans)

# %%
if __name__ == '__main__':
    main()

# %%
# from atcoder_test import doTest
# doTest("abc140","c",main)

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()) # sを取得し、strに値を入れる
B = list(map(int, input().split()))
sum = B[0]
for i in range(1, N-1):
	sum += min(B[i],B[i-1])
sum += B[N-2]
print(sum)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(N):
    if i==0:
        Alist.append(Blist[0])
    elif i==N-1:
        #print(i)
        Alist.append(Blist[i-1])
        #print(i)
    else:
        #print(i)
        Alist.append(min(Blist[i-1],Blist[i]))
        #print(i)
    
#print(Alist)
print(sum(Alist))

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n=int(input())
    a=[]
    b=[int(x) for x in input().split()]
    a.append(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())
Bi = [pow(10,6)] + list(map(int,input().split())) + [pow(10,6)]
Asum = 0
for i in range(1,N+1):Asum = Asum + min(Bi[i-1], Bi[i])
print(Asum)

Submission status: Accepted

Solution code:
import sys

n=int(sys.stdin.readline())
B=list(map(int,sys.stdin.readline().split()))
a=0
first=1
for b in B:
    if first==1:
        a=b
        pre=b
        first=0
    else:
        a+=min(b,pre)
        pre=b
        
a+=pre
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:
n = int(input())
b = list(map(int, input().split()))
a = [0] * n
a[0] = b[0]

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

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

print(sum(a))

Submission status: Accepted

Solution code:
# from math import factorial,sqrt
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import scipy as scp

# 入力の受け取り
n = int(input())
arrB = list(map(int,input().split()))

arrA = [0 for _ in range(n)]

for i in range(len(arrB)):
    if i == 0:
        arrA[i] = arrB[i]
        arrA[i+1] = arrB[i]
    else:
        if arrB[i] <= arrA[i]:
            arrA[i] = arrB[i]
            arrA[i+1] = arrB[i]
        else:
            arrA[i+1] = arrB[i]

ans = sum(arrA)
print(ans)
# print("{:.10f}".format(ans))
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する

Submission status: Accepted

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

Submission status: Accepted

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

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]:
    ans += b[i]
  else:
    ans += 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 i in range(n)]
max = b[0]+b[n-2]

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

Submission status: Accepted

Solution code:
N = int(input())
B = list(map(int,input().split()))
B = B[:1] + B + B[-1:]
#print(B)

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

#print(A)  
print(sum(A))

Submission status: Accepted

Solution code:
N=int(input())
B=list(map(int, input().split(' ')))
A=[None for _ in range(N)]
#print(A)
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:
# -*- coding: utf-8 -*-
"""
C - Maximal Value
https://atcoder.jp/contests/abc140/tasks/abc140_c

"""
import sys


def solve(N, B):
    ans = B[0]
    for a, b in zip(B, B[1:]+ [B[-1]]):
        ans += min(a, b)
    return ans


def main(args):
    N = int(input())
    B = [int(b) for b in input().split()]
    ans = solve(N, B)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

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

Submission status: Accepted

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

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

print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#140_C
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 = list(map(int,input().split()))


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

Submission status: Accepted

Solution code:
n = int(input())
bis = input().split()
ais = 0
for i in range(n):
  if i == 0:
    ais += int(bis[0])
  elif i == n-1:
    ais += int(bis[i-1])
  else:
    ais += min(int(bis[i-1]),int(bis[i]))
print(ais)

Submission status: Accepted

Solution code:
# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product

def resolve():

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

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

resolve()

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(1, n-1):
    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()]
A = [1 << 29]

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

def main():
    n=int(input())
    b=list(map(int,input().split()))
    a=[0]*n
    a[0]=b[0]
    a[1]=b[0]
    for i in range(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))    

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(sum(a))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()

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=[int(x) for x in input().split()]
A=[]
A.append(B[0])
for i in range(len(B)-1):
  A.append(min(B[i],B[i+1]))
A.append(B[-1])
print(sum(A))

Submission status: Accepted

Solution code:
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):
    A[i] = min(B[i - 1], B[i])
print(sum(A))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
b = list(map(int,input().split()))
a = [-1]*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(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 B[i] < A[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()))

A = [10**5]*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:

def submit():
    n = int(input())
    blist = list(map(int, input().split()))

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

    print(ans)


if __name__ == "__main__":
    submit()

Submission status: Accepted

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

print(solve())

Submission status: Accepted

Solution code:

n = int(input())

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

B.insert(0, 2 ** 32)
B.append(2 ** 32)

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

Submission status: Accepted

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

Submission status: Accepted

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

v = B[-1]
pb = 10 ** 5
for b in B:
  v += min(b, pb)
  pb = b

print(v)

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[i]
  elif i < N-1:
    A[i] = min(B[i],B[i-1])
  elif i == N-1:
    A[i] = B[i-1]
#  print("i:",i,", A[i]:",A[i])
print(sum(A))

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

print(wrk)