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: Runtime Error

Solution code:
from collections import deque

N = int(input())
X = [list(map(int, input().split())) for _ in range(N)]

graph = [[] for _ in range(N * N)]
ins = [0] * (N * N)

for i, nodes in enumerate(X):
    for j1, j2 in zip(nodes[:-1], nodes[1:]):
        n1 = max(i, j1 - 1) * N + min(i, j1 - 1)
        n2 = max(i, j2 - 1) * N + min(i, j2 - 1)
        graph[n1].append(n2)
        ins[n2] += 1

dist = [0] * (N * N)
visited = [False] * (N * N)
q = deque()
for i in range(N):
    visited[N * i + i] = True

for i, v in enumerate(ins):
    if v == 0:
        q.append(i)
        visited[i] = True
        dist[i] = 1

while q:
    u = q.popleft()
    for v in graph[u]:
        if visited[v]:
            continue

        ins[v] -= 1
        if ins[v] == 0:
            visited[v] = True
            dist[v] = dist[u] + 1
            q.append(v)
            
print(max(dist) if all(visited) else -1)

Submission status: Runtime Error

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

dp = [10**8]*# NOTE:

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: Runtime Error

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

Submission status: Runtime Error

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()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: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
x=sum(b)
for i in range(len(a)-1):
  if a[i+1]-a[i]==1:
    d=a[i]
    x+=c[d-1]
print(x)

Submission status: Runtime Error

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

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

B.append(float('inf'))

mins = [min(B[0])]

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

print(sum(mins))

Submission status: Runtime Error

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

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

B.append(float('inf'))

mins = [min(B[0]]

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

print(sum(mins))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(raw_input())
b = map(int, raw_input().split(' '))
def f(b):
  n = len(b)+1
  s = 0
  for i in range(n): 
  	s += min(b[i], b[i-1] if i-1>=0 else +float('inf'))
  return s
print f(b)

Submission status: Runtime Error

Solution code:
n=int(input())
l=[int(x) for x in input().split()]
sum=0
n=len(l)
for i in range(0,n):
    if(i==0):
        if(l[i]>l[i+1]):
            sum=sum+(l[i]+l[i+1])
        else:
            sum=sum+(l[i]*2)
    elif(i==n-1):
        sum=sum+l[i]
    else:
        if(l[i]<=l[i+1]):
            sum=sum+l[i]
        else:
            sum=sum+l[i+1]
print(sum)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from collections import deque
N = int(input())
B = deque(map(int, input().split()))
base = B.popleft()
ans = base
while B:
  tmp = B.popleft()
  ans += min(base, tmp)
  base = tmp
ans += tmp
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

a = 0
for i in range(0, n-1):
  b_i, a_i = b_s[i], b_s[i+1]
  a += (b_i if b_i <= a_i else a_i)
print(a + b_s[n-1])

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

a = [b.pop()]
for b_i in b[::-1]:
  a.append(min(a[-1],b_i))
a.append(b[0])
print(sum(a))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

L = B[:]
for i in range(N - 1):
    if (i >= N - 2):
        break
    elif (i == 0 and B[0] > B[1]):
        p = L.pop(0)
        L.append(p)
    elif (B[i] > B[i + 1]):
        L.pop(i)

if (len(L) == 1):
    print(sum(B) * 2)
else:
    print(sum(L) + L[-2])

Submission status: Runtime Error

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

L = B[:]
for i in range(N - 1):
    if (i >= N - 2):
        break
    elif (i == 0 and B[0] > B[1]):
        p = L.pop(0)
        L.append(p)
    elif (B[i] > B[i + 1]):
        L.pop(i)

print(L)
if (len(L) == 1):
    print(sum(B) * 2)
else:
    print(sum(L) + L[-2])

Submission status: Runtime Error

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

L = B[:]
for i in range(N - 1):
    if (i >= N - 2):
        break
    elif (B[i] > B[i + 1]):
        L.pop(i)

if (len(B) == 1):
    print(sum(B) * 2)
else:
    print(sum(L) + L[-2])

Submission status: Runtime Error

Solution code:
n, *b = map(int, open(0).read().split())
a = [0]*n
b += float("inf")
for i in range(n):
  a[i] = min(b[i-1], b[i])
print(sum(a))

Submission status: Runtime Error

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

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

A[N] = B[-1]

print(sum(A))

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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-1):
	score = score + min(b[i],b[i+1])
#	print(min(b[i],b[i+1]))
print(score)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
B=list(map(int,input().split()))  
C=[0]*n
C[0]=B[0]
C[1]=B[1]
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: Runtime Error

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

if __name__ == '__main__':
    n=int(input())
    a_list=[int(x)-1 for x in input().split()]
    b_list=[int(x) for x in input().split()]
    c_list=[int(x) for x in input().split()]
    score=sum(b_list)
    pre_a=-100
    for a in a_list:
        if(a-pre_a==1):
            score+=c_list[pre_a]
        pre_a=a
    print(score)

Submission status: Runtime Error

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

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

print(res)

Submission status: Runtime Error

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: Runtime Error

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

Submission status: Runtime Error

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

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

ans += A[N-1]

print(ans)

Submission status: Runtime Error

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

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

ans += A[N-1]

print(ans)

Submission status: Runtime Error

Solution code:
"use strict"

function Main(input) {
  input = input.trim().split('\n');
  const N = Number(input[0].trim());
  const B = input[1].trim().split(' ').map(Number);

  let cnt = N-2;
  let ret = B[0];
  for(let i=0; i<cnt; i++){
    ret += Math.min(B[i], B[i+1])
  }
  ret += B[cnt];
  console.log(ret);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Submission status: Runtime Error

Solution code:
"use strict"

function Main(input) {
  input = input.trim().split('\n');
  const N = Number(input[0].trim());
  const B = input[1].trim().split(' ').map(Number);
  
  let cnt = N-1;
  let ret = 0;
  let tmp = 0;
  for(let i=0; i<cnt; i++){
    if(i===0){
      ret += B[i];
      tmp = B[i]
      continue;
    } 

    if(tmp < B[i]){
      ret += B[i];
      ret += tmp - B[i];
    } else {
      ret += B[i];
    }
    tmp = B[i];
  }
  ret += tmp;
  console.log(ret);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Submission status: Runtime Error

Solution code:
N = int(input())

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

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

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

Submission status: Runtime Error

Solution code:
N = int(input())

B = [int(i) for i in input()split()]

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
l = 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: Runtime Error

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

Submission status: Runtime Error

Solution code:
sleep(10)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from sys import stdin


def fetch_one_line():
    return stdin.readline().rstrip()


def fetch_int_input():
    return [int(s) for s in fetch_one_line().split()]


def fetch_inputs(times):
    return [fetch_one_line() for _ in range(times)]


def fetch_int_inputs(times):
    return [[int(s) for s in fetch_one_line()] for _ in range(times)]


def fetch_ints_inputs(times):
    return [fetch_int_input() for _ in range(times)]


N, hit_point = fetch_int_input()
swords = fetch_ints_inputs(N)
SLASH, THROW = 0, 1

max_slash_id, max_slash = -1, -1

for idx, sword in enumerate(swords):
    if max_slash <= sword[SLASH]:
        if max_slash == sword[SLASH] and sword[THROW] < swords[max_slash_id][THROW]:
            continue

        max_slash = sword[SLASH]
        max_slash_id = idx


max_slash_throw = swords[max_slash_id][THROW]
# del swords[max_slash_id]
large_throw_swords = list(filter(lambda x: x[THROW] > max_slash, swords[:]))
large_throw_swords.sort(key=lambda x: x[1], reverse=True)

count = 0
is_clear = False

for s in large_throw_swords:

    # if max_slash_throw >= H:
    #    count += 1
    #    H -= max_slash_throw
    #    break

    hit_point -= s[THROW]
    count += 1
    if hit_point <= 0:
        break

import math
if hit_point > 0:
    count += math.ceil(hit_point / max_slash)

print(count)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N=int(input())
b=list(map(int,input().split()))
if N==1:
    a=[b[0]]*2
elif N==2:
    minb=min(b[0],b[1])
    a=[minb]*2
    a.append(b[-1])    
elif N>2:
    minb=min(b[0],b[1])
    a=[minb]*2
    for i in range(1,N-2):
        minb=min(b[i],b[i+1])
        a.append(minb)
    a.append(b[-1])
print(sum(a))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
B = [int(i) for i in input().split()][::-1]
#  N = 6
#  B = [0, 153, 10, 10, 23]
#  N = 3
#  B = [2, 5]
ans = 0
ans += B[1]  # A[1]
for i in range(0, N - 1):
    ans += min(B[i - 1], B[i])
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

# A の初期化
A = [0 for i in range(N)]
for i, v in enumerate(B):
    if i == 0:
        A[i] = B[i]
    else:
        if A[i] >= B[i]:
            A[i] = B[i]
    A[i+1] = B[i]
    
print(sum(A))

Submission status: Runtime Error

Solution code:
#ABC140_C
N=int(input())
A=[0]*N
B=[int(i) for i in input().split()]
A[0]=B[0]

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

Submission status: Runtime Error

Solution code:
#ABC140_C
N=int(input())
A=[0]*N
B=[]
for _ in range(N-1):
    B.append(int(input()))
A[0]=B[0]

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

Submission status: Runtime Error

Solution code:
#ABC140_C
N=int(input())
A=[0]*N
for _ in range(N-1):
    B.append(int(input()))
A[0]=B[0]

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

Submission status: Runtime Error

Solution code:
#coding: utf-8
import math
import heapq
import bisect

MOD = 10**9+7

N = int(input())

# 複数個の数値を、intの配列として取得
B = list(map(int, input().split()))

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

print(ans)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
S = str(input())
count = 0

for n in range(1, N):
    if S[n-1] == 'R' and S[n] == 'R':
        count += 1
    elif S[n-1] == 'L' and S[n] == 'L':
        count += 1

count = count + 2*K
ans = min(count, N-1)
print(ans)

Submission status: Runtime Error

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

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: Runtime Error

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

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
b = list(map, input().split())
print(sum(b) + b[0])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input().split())
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: Runtime Error

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

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

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

print(sum(a))

Submission status: Runtime Error

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

x=b[1]

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

Submission status: Runtime Error

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

x=a[1]

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

Submission status: Runtime Error

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: Runtime Error

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

Submission status: Runtime Error

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

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

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

print(answer)

Submission status: Runtime Error

Solution code:
def main():
    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-1]
    print(sum(A))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())

B_lst = list(map(int,input().split()))
A_lst = [0] * (n+1)

for i in range(n):
    if B_lst[i] > B_lst[i-1]:
        A_lst[i] = str(B_lst[i-1])
    else:
        A_lst[i] = str(B_lst[i])

    if i == n-1:
        A_lst[i+1] = str(B_lst[i])
        break

list = ' '.join(A_lst)
print(list)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

if __name__='__main__':
   A(N,B)

Submission status: Runtime Error

Solution code:
# 入力を受け取る
B_MAX = 100000
N = int(input().strip())
B = input().strip().split()

# B_MAX + 1を入れておくことで 必ずmin(B[0], B[1]) = B[1], min(B[N-1], B[N]) = B[N-1]となる
B = [B_MAX + 1] + [int(b) for b in B] + [B_MAX + 1] # 整数に変換


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

print(sum)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
n = int(input())
b = [*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[-1])
print (sum(a))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:

import numpy as np
N = int(input())
B = np.array(input().split(), dtype=int)[::-1]

et = 0

ret += B[0]

i = 0
while i < N-2:
    ret += B[i] if B[i] < B[i+1] else B[i+1]
    i+=1
print(ret)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n = II()
    print(n**3)
    return

#B
def B():
    n = II()
    a = LI()
    b = LI()
    c = LI()
    ans = 0
    for i in range(n):
        ans += b[a[i] - 1] + (c[a[i] - 1] if i != n - 1 and a[i] + 1 == a[i + 1] else 0)
    print(ans)
    return

#C
def C():
    n = II()
    b = LI()
    ans = b[0]
    for i in range(n-1):
        if b[i] >= b[i + 1]:
            ans += b[i + 1]
        else:
            ans += b[i]
    print(ans)
    return

#D
def D():
    n, k = LI()
    s = S()
    a = []
    for i in range(n):
        if i == n - 1:
            a.append(s[i])
        elif s[i] != s[i + 1]:
            a.append(s[i])
    print(min(n - 1, n - len(a) + 2 * k))
    return

#E
def E():
    return

#F
def F():
    return


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

Submission status: Runtime Error

Solution code:
N = int(input())
B = np.array(input().split(), dtype=int)[::-1]

et = 0

ret += B[0]

i = 0
while i < N-2:
    ret += B[i] if B[i] < B[i+1] else B[i+1]
    i+=1
print(ret)

Submission status: Runtime Error

Solution code:
N = int(input())
B = np.array(input().split(), dtype=uint)[::-1]

et = 0

ret += B[0]

i = 0
while i < N-2:
    ret += B[i] if B[i] < B[i+1] else B[i+1]
    i+=1
print(ret)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n, k = map(lambda x: int(x), input().split())
s = str(input())

count = 0
for i in range(0, len(s)-1):
    if s[i] == 'R' and s[i+1] == 'R':
        count += 1
    if s[i] == 'L' and s[i+1] == 'L':
        count += 1

print(min(count + 2*k, n-1))

Submission status: Runtime Error

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

sum =b[0]

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

Submission status: Runtime Error

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

sum =b[0]

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

list2 = []
list2.append(list1[0])
for i in range(n):
    list2.append(min(list1[(n-1)-i:]))
print(sum(list2))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

for i in range(1, N):
    if S[i] <= S[i-1]:
        cnt += S[i]
    else:
        cnt += S[i-1]
        S[i] = S[i-1]

print(sum(S))