Problem:


Score : 300 points

Problem Statement

There is an integer sequence A of length N whose values are unknown.

Given is an integer sequence B of length N-1 which is known to satisfy the following:

 B_i \geq \max(A_i, A_{i+1}) 

Find the maximum possible sum of the elements of A.

Constraints

All values in input are integers.

2 \leq N \leq 100

0 \leq B_i \leq 10^5

Input

Input is given from Standard Input in the following format:

N
B_1 B_2 ... B_{N-1}

Output

Print the maximum possible sum of the elements of A.

Sample Input 1

3
2 5

Sample Output 1

9

A can be, for example, ( 2 , 1 , 5 ), ( -1 , -2 , -3 ), or ( 2 , 2 , 5 ). Among those candidates, A = ( 2 , 2 , 5 ) has the maximum possible sum.

Sample Input 2

2
3

Sample Output 2

6

Sample Input 3

6
0 153 10 10 23

Sample Output 3

53



Sample input:
3
2 5


Sample output:
9

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue
mod = 10**9+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())
def conb(n,r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


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

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
inf=float("inf")
n=int(input())
b=list(map(int,input().split()))
ans=b[0]
for i in range(n-2):
    ans+=min(b[i],b[i+1])
ans+=b[n-2]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#gcdは3.4.3だとfractionsにある
from fractions import gcd

from math import factorial as f

from math import ceil,floor,sqrt

from sys import exit

from copy import deepcopy
import numpy as np

import bisect
import re


ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))



def main():
    n = ii()
    b = li()
    b = [100000000]+b+[100000000]
    ans = 0

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

    print(ans)

main()

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
sys.setrecursionlimit(1000000)
from collections import *
from bisect import *
mod = 10**9+7

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

Submission status: Accepted

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

ans = B[0] + B[-1] + sum(min(b0,b1) for b0,b1 in zip(B[:-1],B[1:]))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
n=int(input())
b_list=list(map(int,input().split()))
ans=0
for i in range(n):
    if i==0:
        ans+=b_list[0]
    elif i==n-1:
        ans+=b_list[n-2]
    else:
        ans+=min(b_list[i-1],b_list[i])
print(ans)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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


def solve(N: int, B: "List[int]"):
    prev = B[0]
    res = 0
    for b in B:
        res += min(b, prev)
        prev = b
    res += prev
    print(res)
    return


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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    B = list(map(int, input().split()))
    B.insert(0, B[0])
    B.append(B[-1])
    ret = 0
    for b, b1 in zip(B, B[1:]):
        ret += min(b, b1)
    print(ret)


main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import collections
import copy
import math
def input(): return sys.stdin.readline().strip()
N = int(input())
B = [int(i) for i in input().split()]
ans = B[0]+B[N-2]
for i in range(N-2):
    ans += min(B[i],B[i+1])
print(ans)

Submission status: Accepted

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

A = [float('inf')]*N
for i in range(N-1):
    A[i] = min(A[i],B[i])
    A[i+1] = min(A[i+1],B[i])
print(sum(A))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]


    N = II()
    B = LMIIS()
    suma = B[0] + B[-1]
    #Ai :max(Bi,Bi-1)
    for i in range(1,N-1):
        suma += min(B[i],B[i-1])
    print(suma)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
INF = 10**9
b = [int(i) for i in input().split()]
b = [INF]+b+[INF]
ans = 0
for i in range(N):
  ans += min(b[i], b[i+1])
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

answer = sum(A)
print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
B = [1<<100] + [int(a) for a in input().split()] + [1<<100]
print(sum([min(B[i], B[i+1]) for i in range(N)]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  ans=l[0]

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

  return ans

# main()
print(main())

Submission status: Accepted

Solution code:
n  = int(input())

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

print(sum(a))

Submission status: Accepted

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

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

print(sum(A) + B[-1])

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

print(score)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)

def main():
    n = I()
    b = LI()
    a = [inf] * n
    for i in range(n-1):
        a[i+1] = b[i]
        if b[i] < a[i]:
            a[i] = b[i]

    return sum(a)


print(main())

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

ans = B[0] + B[-1]
for a,b in zip(B,B[1:]):
    ans += min(a,b)
print(ans)

Submission status: Accepted

Solution code:
import sys
#template by uwi 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

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

Submission status: Accepted

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

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

n = int(input())
b = [int(i) for i in readline().split()]+[1000000000]

a = [0]*(n+1)

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

#print(a)
print(sum(a))

Submission status: Accepted

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

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

print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin
# import numpy as np
# import sys
# sys.setrecursionlimit(10**4)

def _li(): return list(map(int, stdin.readline().split()))
def _li_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def _lf(): return list(map(float, stdin.readline().split()))
def _ls(): return stdin.readline().split()
def _i(): return int(stdin.readline())
def _f(): return float(stdin.readline())
def _s(): return stdin.readline()[:-1]


N = _i()
b_list = _li()

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n = int(input())
    b = [int(s) for s in input().split()]
    ans = b[-1] + b[0]
    for i, v in enumerate(b[1:]):
        ans += min(v, b[i])
    print(ans)

Submission status: Accepted

Solution code:
n=int(input())
B=[int(i) for i in input().split()]
B.append(float("inf"))
ans=B[0]
for i in range(n-1):
  ans+=min(B[i],B[i+1])
print(ans)

Submission status: Accepted

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

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from operator import itemgetter
from fractions import gcd
from math import ceil, floor, sqrt
from copy import deepcopy
from collections import Counter, deque
import heapq
from functools import reduce
sys.setrecursionlimit(200000)
# local only
# if not __debug__:
#     fin = open('in_1.txt', 'r')
#     sys.stdin = fin
# local only
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
def debug(*args, sep=" ", end="\n"): print("debug:", *args, file=sys.stderr, sep=sep, end=end) if not __debug__ else None
def exit(*arg): print(*arg); sys.exit()
# template


def main():
    N = ii()
    A = lmi()
    B = []
    for i in range(1, N - 1):
        B.append(min(A[i], A[i - 1]))
    print(sum(B) + A[0] + A[-1])
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

A=[0]*N
A[0]=B[0]
A[N-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:
#import sys
#input = sys.stdin.readline
def main():
    N = int( input())
    B = list( map( int, input().split()))
    ans = B[0]+B[-1]
    for i in range(1, N-1):
        ans += min(B[i], B[i-1])
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

main()

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
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()
BB = [INF] + inpl() + [INF]
ans = 0
for i in range(N):
    ans += min(BB[i],BB[i+1])

print(ans)

Submission status: Accepted

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

b = [10**9] + b + [10**9]

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
b = list(map(int, input().split()))
a = [ b[0] ] + [ min(b[i], b[i + 1]) for i in range(n - 2) ] + [ b[n - 2] ]
print(sum(a))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
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)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

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

#B
def B():
    n = I()
    a = LI()
    b = LI()
    c = LI()
    ans = sum(b)
    for i in range(n-1):
        x = a[i]
        y = a[i+1]
        if y == x+1:
            ans += c[x-1]
    print(ans)
    return

#C
def C():
    n = I()
    b = LI()
    b.append(float("inf"))
    a = [min(b[i],b[i-1]) for i in range(n)]
    print(sum(a))
    return

#D
def D():

    return

#E
def E():

    return

#F
def F():

    return

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

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

print(ret)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
b = na()

ans = 0
for i in range(n):
    q = 999999999
    if i > 0:
        q = min(q, b[i-1])
    if i < n-1:
        q = min(q, b[i])
    ans += q
print(ans)

Submission status: Accepted

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

from collections import deque, defaultdict
import itertools as ite
import sys
import math
import decimal

sys.setrecursionlimit(1000000)

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

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

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

Submission status: Accepted

Solution code:
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

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

ans = 0
for a, b in zip(B, B[1:]):
    ans += min(a, b)
print(ans + B[0] + B[-1])

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(c)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools


import queue
from collections import deque




def main():
    num = int(input())
    data = list(map(int, input().split()))
    ans = data[0] + data[-1]
    for i in range(num - 2):
        ans += min(data[i], data[i + 1])
    print(ans)





if __name__ == '__main__':
    main()

Submission status: Accepted

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

print(sum(ans))

Submission status: Accepted

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

Submission status: Runtime Error

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

a =[b[0]]

for x in range(n-1):
  s = min(b[x],b[x+1])
  a.append(s)
  
a.append(b[-1])

print(sum(a))

Submission status: Runtime Error

Solution code:
n = int(input())
alist=list(map(int,input().split()))
mina = min(alist[0],alist[1])
minb = min(alist[-2],alist[-1])
minc = alist[-1]
core = 0
for i in range(n-3):
  core +=min(alist[i],alist[i+1],alist[i+2])
print(core + mina + minb + minc)

Submission status: Runtime Error

Solution code:
n = int(input())
alist=list(map(int,input().split()))
min1 = min(alist[0],alist[1])
min2 = min(alist[-2],alist[-1])
last = alist[-1]
core = 0
for i in range(n-3):
  core +=min(alist[i],alist[i+1],alist[i+2])
print(core + min1 + min2 + last)

Submission status: Runtime Error

Solution code:
n = int(input())
alist=list(map(int,input().split()))
core = 0
for i in range(n-3):
  core +=min(alist[i],alist[i+1],alist[i+2])
min1 = min(alist[0],alist[1])
min2 = min(alist[-2],alist[-1])
print(core + min1 + min2 + alist[-1])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
input_data = input().split("\n")
N = int(input_data[0])
ls = [int(b) for b in input_data[1].split()]
if len(ls) == 1:
  print(ls[0]*2)
else:
  first = ls[0]
  als = [ls[0]]

  for n in range(1, N-1):
    als.append(min(ls[n-1], ls[n]))
  als.append(ls[-1])
  print(sum(als))

Submission status: Runtime Error

Solution code:
input_data = input().split("\n")
N = int(input_data[0])
ls = [int(b) for b in input_data[1]]
if len(ls) == 1:
  print(ls[0]*2)

first = ls[0]
als = [ls[0]]

for n in range(1, N-1):
  als.append(min(ls[n-1], ls[n]))
als.append(ls[-1])
print(sum(als))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def Input():
    return mapt(int, input().split(" "))

def main():
    n = int(input())
    b = Input()
    data = 0
    for i in range(n-1):
        if i == 0:
            data += b[i]
            continue
        data += min(b[i], b[i-1])
    data += b[-1]
    print(data)
main()

Submission status: Runtime Error

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

Solution code:
n = int(input())

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

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

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

c = 0

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

Submission status: Runtime Error

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

for i in range(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]]

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

a.append(b[-1])
print(sum(a))

Submission status: Runtime Error

Solution code:
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int a[n];
    int b[n-1]; rep(i,n-1) cin >> b[i];

    a[0] = b[0];
    a[n-1] = b[n-2];
    for (int i = 1; i<(n-1); i++) {
        a[i] = min(b[i-1],b[i]);
    }
    ll ans = 0;
    rep(i,n) ans += a[i];
    cout << ans << "\n";
}

Submission status: Runtime Error

Solution code:
def main():
    n = int(input())
    blis = list(map(int, input().split()))

    alis = [blis[0], blis[0]]
    if alis[1] > blis[1]:
        alis[1] = blis[1]
    if n > 2:
        for i in range(3, n):
            alis.append(min(blis[i-2], blis[i-1]))
    if n > 2:
        alis.append(blis[n-2])
    print(sum(alis))


    


if __name__ == "__main__":
    main()