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 sys import stdin,stdout


if __name__=="__main__":

    n=int(stdin.readline())
    b=[int(x) for x in stdin.readline().split()]
    b.append(1000000)

    s=b[0]

    for i in range(n-1):
        if b[i]>b[i+1]:
            s+=b[i+1]
        else:
            s+=b[i]
    stdout.write(str(s)+"\n")

Submission status: Accepted

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

ans = b[n-2]


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

print(ans+b[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

if __name__ == "__main__":
    N = int(input())
    B = list(map(int, input().split()))
    solve()

Submission status: Accepted

Solution code:

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

if __name__ == "__main__":
    N = int(input())
    B = list(map(int, input().split()))
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

# list_n = list(map(int, input().split()))

# n = input()
# list = [input() for i in range(N)

# list = [[i for i in range(N)] for _ in range(M)]

import sys
input = sys.stdin.readline

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

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

print(sum(a))

Submission status: Accepted

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

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

print(sum(a))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in range(n-1):
    A.append(B[i])
    if A[i] > B[i]:
        A[i] = B[i]
print(sum(A))

Submission status: Accepted

Solution code:
#<C>
N = int(input())
B = list(map(int,input().split()))
A = [None] * N
A[0] = B[0]
for i in range(N - 2):
    if B[i] <= B[i + 1]:
        A[i + 1] = B[i]
    else:
        A[i + 1] = 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()))
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()))
ans=[B[0],B[n-2]]

for i in range(n-2):
  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 = [0] * N
total = B[0] + B[-1]

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

print(total)

Submission status: Accepted

Solution code:
n = int(input())
bl = list(map(int, input().split()))
bl = [10**6] + bl + [10**6]

ans = 0
for b1,b2 in zip(bl[:-1],bl[1:]):
    ans += min(b1,b2)

print(ans)

Submission status: Accepted

Solution code:
import os
from math import*
import sys
input=sys.stdin.buffer.readline

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n, *b = map(int, open(0).read().split())
b = [b[0]] + b + [b[-1]]

print(sum(min(b[i], b[i + 1]) for i in range(n)))

Submission status: Accepted

Solution code:
N, *B = map(int, open(0).read().split())

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

Submission status: Accepted

Solution code:

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 9)


# map(int, sys.stdin.read().split())


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


def main():
    N = int(input())
    B = list(map(int,input().split()))
    B.append(10**6)
    A =[]
    A.append(B[0])
    for i in range(N-1):
        a =min(B[i],B[i+1])
        A.append(a)
    print(sum(A))




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

ans.append(b[len(b)-1])

print(sum(ans))

Submission status: Accepted

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

dp = [10**8]*n

for i in range(n-1):
    if dp[i] > b[i] :
        dp[i] = b[i]
    if dp[i+1] > b[i] :
        dp[i+1] = b[i]

print(sum(dp))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

A=[-1 for x in range(N)]
i=0
j=0
for a in B:
  j=i+1
  if A[i]==-1:
    A[i]=a
    A[j]=a
  else:
    if A[i]>a:
      A[i]=a
    A[j]=a
  i=i+1
  #print(A)
total = 0
for num in A:
  total = total + num
print(total)

Submission status: Accepted

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

Submission status: Accepted

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

a=b[0]

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

a+=b[-1]

print(a)

Submission status: Accepted

Solution code:
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

n = i()
b = intl()

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = [1e10]*N
b = list(map(int,input().split()))

for i,num in enumerate(b):
    if a[i] > num:
        a[i] = num
    a[i+1] = num
print(sum(a))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = [1e10]
b = list(map(int, input().split()))
for i, num in enumerate(b):
    if a[i] > num:
        a[i] = num
    a.append(num)
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()))

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_sum = B[0]
for i in range(N-1):
    if i != N-2:
        A_sum += min(B[i], B[i+1])
    else:
        A_sum += B[i]

print(A_sum)

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

Submission status: Accepted

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

ans = bn[0] + bn[-1]

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

print(ans)

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
b = list(map(int, 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()))

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()))
S = B[0] + B[N-2]
i = 0
while i <= N-3:
    if B[i] > B[i+1]:
        S += B[i+1]
    else:
        S += B[i]
    i += 1
print(S)

Submission status: Accepted

Solution code:
N=int(input())
B=[int(_) for _ in input().split()]
inf=10**10

B_=[inf]
B_.extend(B)
B_.append(inf)
A=[]

for n in range(1,N+1):
    A.append(min(B_[n-1],B_[n]))
    
print(sum(A))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *B = map(int, read().split())

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

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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-1):
    if i == 0:
        a[i] = b[i]
        a[i+1] = b[i]
    if b[i] < b[i-1] and i > 0:
        a[i] = b[i]
        a[i+1] = b[i]
    elif b[i] >= b[i-1] and i > 0:
        a[i+1] = b[i]

print(sum(a))

Submission status: Accepted

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

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

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

Submission status: Accepted

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

a = [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()))

a = [-1] * n

for i, b in enumerate(B):
    if a[i] > B[i]:
        a[i] = b
        a[i+1] = b
    elif a[i] != -1:
        a[i+1] = b
    elif a[i] == -1:
        a[i] = b
        a[i+1] = b

print(sum(a))

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

al = [-1]*N
al[0] = bl[0]
for i in range(1,N-1):
    al[i] = min(bl[i],bl[i-1])
al[N-1] = bl[N-2]
print(sum(al))

Submission status: Accepted

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

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

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

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

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

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

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input().split()) for _ in range(n) ]

# ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())

n = I()
b = RI()

a = []
for i in range(n):
    if i==0:
        a.append(b[i])
    elif i>0 and i<(n-1):
        a.append(min(b[i-1],b[i]))
    elif i==(n-1):
        a.append(b[i-1])
    else:
        print("E")
ans = sum(a)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict, deque
import math

# import copy
# from bisect import bisect_left, bisect_right
# import heapq

# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 10**9 + 7

def divide(k):
    return pow(k, MOD-2, MOD)


def make_nck(n):
    ret = [1]
    for i in range(1, n+1):
        ret.append((ret[-1] * (n + 1 - i) * divide(i)) % MOD)

    # print(ret)
    return ret

def make_nigojyo(n):
    ret = [1]

    for i in range(1, n+1):
        ret.append((ret[-1] * 25) % MOD)

    # print(ret)
    return ret


def solve():
    n = getN()
    a = getList()
    ans = 0
    for i, j in zip(a, a[1:]):
        ans += min(i, j)
    ans += a[0] + a[-1]

    print(ans)



def main():
    n = getN()
    for _ in range(n):
        solve()


if __name__ == "__main__":
    # main()
    solve()

Submission status: Accepted

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

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

print(sum(a))

Submission status: Accepted

Solution code:
n,*l=map(int,open(0).read().split())
s,p=0,l[0]
for i in l: s+=min(p,i); p=i
print(s+p)

Submission status: Accepted

Solution code:
n,*l=map(int,open(0).read().split())
s,p=0,l[0]
for i in l:
  s+=min(p,i)
  p=i
print(s+p)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# C - Maximal Value
def main():
    n = int(input())
    b = list(map(int, input().split()))
    a = []

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

    print(sum(a))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
mod=10**9+7
import math
import sys
from collections import deque
import heapq
import copy
import itertools
from itertools import permutations
from itertools import combinations
import bisect
def mi() : return map(int,sys.stdin.readline().split())
def ii() : return int(sys.stdin.readline().rstrip())
def i() : return sys.stdin.readline().rstrip()
a=ii()
l=list(mi())
ans=l[0]
for i in range(a-2):
  ans+=min(l[i],l[i+1])
print(ans+l[-1])

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    b = list(map(int, input().split()))
    a = [None] * n
    for i in range(n):
        if i == 0:
            a[i] = b[i]
        elif i <= n-2:
            a[i] = min(b[i-1], b[i])
        else:
            a[i] = b[i-1]
    ans = sum(a)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

wa = 0

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

print(wa)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
 
## Library
 
import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
 
## input
 
# N=int(input())
# A,B,C,D=map(int, input().split())
# S = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]
 
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(max(B[N-2],A[N-2]))

print(sum(A))

Submission status: Accepted

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

for i in range(N):
    if i == 0:
        A.append(B[0])
    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:
# -*- coding: utf-8 -*-
# C

import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect
input = sys.stdin.readline

# 再起回数上限変更
# sys.setrecursionlimit(1000000)

n = int(input())
b = [1000000] + list(map(int, input().split())) + [1000000]

res = []

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

print(sum(res))

Submission status: Accepted

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

ans=B[0]+B[-1]
i=0
while i+1<N-1:
    ans+=min(B[i],B[i+1])
    i+=1

print(ans)

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

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] = b[i]

print(sum(a))

Submission status: Accepted

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

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

A[N-1] = B[-1]

print(sum(A))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
b=list(map(int,input().split()))
a=[float('Inf')]*n
for i,num in enumerate(b):
	if n>i:
		a[i]=min(a[i],num)
		a[i+1]=num
print(sum(a))

Submission status: Accepted

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

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

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

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

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

Submission status: Accepted

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

# In[12]:


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


# In[14]:


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


# In[ ]:

Submission status: Accepted

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

resolve()

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    B = [float('inf')] + list(map(int, input().split())) + [float('inf')]
    A = []
    for i in range(N):
        A.append(min(B[i], B[i+1]))
    print(sum(A))

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main(N, B):
    A = [-1 for _ in range(N)]
    A[0], A[-1] = B[0], B[-1]

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

    return(sum(A))


if __name__ == "__main__":
    N = int(input())
    B = list(map(int, input().split()))
    ans = main(N, B)
    print(ans)

Submission status: Accepted

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

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 A[i]>B[i]:
        A[i]=B[i]
    A[i+1]=B[i]

t=0
for a in A:
    t+=a
print(t)

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

Submission status: Accepted

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

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

As = [copy.copy(Bs[0])]
As.extend(copy.copy(Bs))

#print(Bs)
#print(As)

for index, B in enumerate(Bs):
#    print(Bs)
#    print(As)
    if B < As[index]:
        As[index] = B

#print(As)
print(sum(As))