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:
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


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


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


def main():
    N = int(input())
    B = list(map(int, input().split()))
    print(solve(N, B))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

print(sum(a))

Submission status: Accepted

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

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

print(sum(a))

Submission status: Accepted

Solution code:
# 2019-11-18 00:38:19(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# import re
# import heapq
# import array
# from scipy.misc import comb # (default: exact=False)
# import numpy as np 


def main():
    n, *b = [int(x) for x in sys.stdin.read().split()]
    a = [None for _ in range(n)]
    a[0], a[n-1] = b[0], b[n-2]
    for i in range(1, n-1):
        a[i] = min(b[i-1], b[i])

    ans = sum(a)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
b=list(map(int,input().split()))
a=[0]*n
a[0],a[n-1]=b[0],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:
import numpy as np
N = int(input())
B = [int(i) for i in input().split()]

B.append(B[-1])
#print(B)
max = B[0]
for i in range(1, N):
    max += np.minimum(B[i-1], B[i])
print(max)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

A=[1000000]*N

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

Submission status: Accepted

Solution code:
n = int(input())
b = list(map(int,input().split()))
a = []
pre = b[0]
for i in range(n):
  if i == n - 1:
    a.append(b[-1])
    break
  # 同じならそのまま
  if pre == b[i]:
    a.append(pre)
  # 上がったら1個前のを
  elif pre < b[i]:
    a.append(pre)
    pre = b[i]
  # 下がったらその都度下げる
  elif pre > b[i]:
    a.append(b[i])
    pre = b[i]
print(str(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())
blis = list(map(int,input().split()))
alis = []
for i in range(n):
    if i == n-1:
        alis.append(blis[n-2])
    elif i == 0:
        alis.append(blis[0])
    else:
        if blis[i]>blis[i-1]:
            alis.append(blis[i-1])
        else:
            alis.append(blis[i])
print(sum(alis))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(N-1):
    AS[i] = min(AS[i], BS[i])
    AS[i+1] = max(AS[i], BS[i])

print(sum(AS))

Submission status: Accepted

Solution code:
N = int(input())
B = [int(i) for i in 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()))
total = B[0] + B[N-2]

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

print(total)

Submission status: Accepted

Solution code:
def solve():
    N = int(input())
    B = list(map(int , input().split()))
    max_candidate = B[0]
    ret = B[0]
    for i in range(1, N-1):
        if max_candidate < B[i]:
            ret += max_candidate
        else:
            ret += B[i]
        max_candidate = B[i]
        
    ret += max_candidate
    print(ret)
    
solve()

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())


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

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

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

print(sum(A))

Submission status: Accepted

Solution code:
n = int(input())
A = [None for i in range(n)]
B = list(map(int, input().split()))
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())
a = [int(x) for x in input().split()]

b = a[0]
bef = 0

for i in a:
  #print("bef1=", bef)
  if i >= bef:
    b = b + i
    #print("b1=", b)
  else:
    b = b - bef + i + i
    #print("b2=", b)
  bef = i
  #print("bef2=", bef)

print(b)

Submission status: Accepted

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

#print(B)

total=0

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    B = list(int(x) for x in input().split())
    A = [0]*N

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
import bisect
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


# A
def A():
    N = I()
    print(pow(N, 3))
    return


# B
def B():
    N = I()
    A = LI()
    B = LI()
    C = LI()
    a_p = -1
    ans = 0
    for a in A:
        if (a - a_p == 1):
            ans += B[a - 1] + C[a - 2]
        else:
            ans += B[a - 1]
        a_p = a
    print(ans)
    return


# C
def C():
    N = I()
    B = LI()
    A = [0 for i 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))
    return


# D
def D():
    return


# E
def E():
    return


# F
def F():
    return


# Unittest
def resolve():
    C()
    return


# Solve
if __name__ == "__main__":
    C()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def print_ans(N,B):
    """Test Case
    >>> print_ans(3,"2 5")
    9
    >>> print_ans(2,"3")
    6
    >>> print_ans(6,"0 153 10 10 23")
    53
    """
    B_arr = list(map(int,B.split()))
    A_arr = [0] * N
    for i in range(N - 1):
        A_arr[i + 1] = B_arr[i]
        if i == 0:
            A_arr[i] = B_arr[i]
        else:
            A_arr[i] = min(A_arr[i],B_arr[i])
    print(sum(A_arr))
if __name__ == '__main__':
    N = int(input().rstrip())
    B = input().rstrip()
    print_ans(N,B)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

A_list = [0] * N
A_list[0] = B_list[0]

if len(B_list) >=1:
    for i in range(N-2):
        A_list[i+1] = min(B_list[i], B_list[i+1])

    A_list[N-1] = B_list[N-2]
else:
    A_list[1] = B_list[0]

print(sum(A_list))

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

Submission status: Accepted

Solution code:
n = int(input())
b = [int(x) for x in input().split()]
ans = b[0] + b[-1]

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

A = []

A.append(B[0])

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

A.append(B[N-2])
answer = sum(A)  
print(answer)

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

Submission status: Accepted

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

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

print(res)

Submission status: Accepted

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

A_li = [0 for i in range(n)]

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

ans = sum(A_li)
print(ans)

Submission status: Accepted

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

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

print(sum(a))

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
# a: 長さnの値不明の整数列
b = [int(i) for i in input().split()]

# b1 >= max(a1,a2)
# b2 >= max(a2,a3)
# ...
# bn-1 >= max(an_1,an)

# この条件を満たす最大のa1,a2,...を求める
# sum_i{bi}がなにか使えそうなきはする 

# [ex1]
# b = [2,5,5]
# a = [2,2,5,1]
#     [2,2,5,5] *

# [ex2]
# b = [0,153, 10,10,23]
# a = [0,  0,153,10,10,23] ... false!
#     [0,  0, 10,10,10,23] ... true

# [ex3]
# b = [  0,153,10,10,5]
# a = [  0,  0,10,10,5,5]

# [ex4]
# b = [3,1]
# a = [3,1,1]

# [ex5]
# b = [3,1,3]
# a = [3,1,1,3]

# [ex6]
# b = [1,4,2,5,3,6]
# a = [1,1,2,2,3,3,6]

# [ex7]
# b = [4,1,5,2]
# a = [4,1,1,2,2]

# a1 = b1
#   if b2 <= b1
#      a2 = b2
# elif b2 > b1
#      a2 = b1
# an = bn-1

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

ans = sum(a)
print(ans)

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]
ans=0

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

Submission status: Accepted

Solution code:
N = int(input())
B = list(map(int, input().strip().split()))
INF = float('inf')

B.insert(0, INF)
B.append(INF)

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

print(sum(A))

Submission status: Accepted

Solution code:
n = int(input())
b = [int(_) for _ in 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]

print(sum(a))

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    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(min(b[i - 1], b[i]))

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

Submission status: Accepted

Solution code:
# C - Maximal Value
N = int(input())
B = list(map(int, input().split()))
####
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().strip())
b = list(map(int, input().split()))

a = []
a.append(b[0])

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

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

Submission status: Accepted

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

for i in range(0,n):
  if i == 0:
    m[i] = b[i]
    continue
  elif i == n-1 :
    m[n-1] = b[i-1]
    continue
  m[i] = min(b[i],b[i-1])

print(sum(m))

Submission status: Accepted

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

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

Submission status: Accepted

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

count = B[0]

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

count += B[N-2]

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

i=1
while n-1>i:
  if b[i-1]<=b[i]:
    x+=b[i-1]
    i+=1
  else:
    x+=b[i]
    i+=1
    
print(x)

Submission status: Accepted

Solution code:
N = int(input())
B = map(int,input().split())
ans = next(B)
tmp = ans
for i in range(N-2):
    t = next(B)
    ans += min(tmp,t)
    tmp=t
ans += tmp
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = []
a.append(10 ** 5)
b = input().split()
x = 0 #答え

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

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

print(x)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
bl = list(map(int, input().split()))
al = [0]*n

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

print(sum(al))

Submission status: Accepted

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

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

print(result)

Submission status: Accepted

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

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

print(res)

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.append(min(B[i],B[i+1]))

print(sum(A))

Submission status: Accepted

Solution code:
import math

def main():
    n = int(input())
    B = list(map(int, input().split()))

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




if __name__ == '__main__':
    main()

Submission status: Accepted

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

a_integers = [b_integers[0]]
for i in range(n-2):
    if b_integers[i] > b_integers[i+1]:
        a_integers.append(b_integers[i+1])
    else:
        a_integers.append(b_integers[i])
a_integers.append(b_integers[-1])
print(sum(a_integers))

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):
    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(" ")))
m,j = [b[0]+b[n-2],0]
for i in b:
    m += min(i,j)
    j = i
print(m)

Submission status: Accepted

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

c[0] = b[0]
c[n-1] = b[n-2]

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

print(sum(c))

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

print(a)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(cnt)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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=list(map(int,input().split()))
A=[B[0]]
preb=B[0]
for b in B[1:]:
  A.append(min(preb,b))
  preb=b
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]))
print(sum((a + [b[n-2]])))

Submission status: Accepted

Solution code:
def main():
# input
    n = int(input())
    b = [i for i in map(int, input().split())]

# loop
    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 = 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:
N = int(input())
A = list(map(int, input().split()))
ans = A[0] + A[N-2]
for i in range(1,N-1):
    ans += min(A[i-1],A[i])
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
B=[10**6]
B.extend([int(b) for b in input().split()])
B.append(10**6)
#print(N, B)

A=[None]*N
for i in range(N):
  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 = []

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

a_list = [0 for i in range(n)]

for i,b in enumerate(b_list):
    if i == 0:
        a_list[i] = b
        a_list[i+1] = b
    else:
        a_list[i] = min(a_list[i],b)
        a_list[i+1] = b

print(sum(a_list))

Submission status: Accepted

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