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: Wrong Answer

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

Submission status: Wrong Answer

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

if N > 2:
  A.append(B[-1])
print(sum(A))

Submission status: Wrong Answer

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

print(sum(A))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

    sum_point = 0
    sum_point += B_list[0]

    for i in B_list:
        sum_point += i

    print(sum_point)

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

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

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

if n == 2:
    asum += B[-1]

print(asum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = B[0]

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
#sys.setrecursionlimit(150000)


def solve(N: int, B: "List[int]"):
    a=[101]*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))
    return

# Generated by 1.1.6 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: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

A = [B[0]]
for i in range(N-1):
    A.append(B[i-1])
    if A[i] > B[i]:
        A[i] = B[i]

print(sum(A))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
b_list = list(map(int, input().split(' ')))
b_list.append(b_list[-1])

pre_b = 101  # Bのとりうる最大値+1
a_list = []
for i in range(len(b_list)):
  a_list.append(min(pre_b, b_list[i]))
  pre_b = b_list[i]
print(sum(a_list))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def solve(inp):
    N = int(inp.readline().strip())
    B = list(map(int, inp.readline().strip().split(' ')))

    A = [0 for i in range(N)]

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

    return str(sum(A))


def test(s):
    from io import StringIO
    print(solve(StringIO(s)))


def main():
    import sys
    result = solve(sys.stdin)
    if result:
        print(result)


if __name__ == '__main__':
    # test('3\n2 5')
    # test('2\n3')
    # test('6\n0 153 10 10 23')
    main()

Submission status: Wrong Answer

Solution code:
# わからない

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys


def solve(inp):
    N = int(inp.readline().strip())
    B = list(map(int, inp.readline().strip().split(' ')))

    A = [0 for i in range(N)]
    A[N - 1] = B[N - 2]
    A[0] = B[0]
    n = N - 2
    while n >= 1:
        A[n] = min(B[n], B[n - 1])
        n -= 1

    # print(" ".join(map(str, A)))
    return sum(A)


def main():
    result = solve(sys.stdin)
    if result:
        print(result)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys


def solve(inp):
    N = int(inp.readline().strip())
    B = list(map(int, inp.readline().strip().split(' ')))

    A = [0 for i in range(N)]
    A[N - 1] = B[N - 2]
    n = N - 2
    while n >= 0:
        A[n] = min(B[n], B[n - 1])
        n -= 1

    # print(" ".join(map(str, A)))
    return sum(A)


def main():
    result = solve(sys.stdin)
    if result:
        print(result)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys


def solve(inp):
    N = int(inp.readline().strip())
    B = list(map(int, inp.readline().strip().split(' ')))

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

    # print(" ".join(map(str, A)))
    return sum(A)


def main():
    result = solve(sys.stdin)
    if result:
        print(result)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
B = list(map(int, input().split()))
B.append(10**5+1)
max_sum = 2 * B[0]

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

print(max_sum)

Submission status: Wrong Answer

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

A = [0]*N

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

print(sum(A))

Submission status: Wrong Answer

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

for i in range(n-2, 0, -1):
    if l[i] < l[i-1]:
        l[i-1] = l[i]

print(l[0]+sum(l))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys


N = int(input())
B = [inp for inp in map(int, input().split())]

if N == 2:
  print(B[0]*2)
  sys.exit()

A = []
A.append(B[0]*2)

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

A.append(B[-1])
  
print(sum(A))

Submission status: Wrong Answer

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

prev_b = float("inf")
reverse_A = []
for b in B:
  if prev_b >= b:
    reverse_A.append(b)
    prev_b = b
  else:
    reverse_A.append(prev_b)
reverse_A.append(max(b, prev_b))
    
print(sum(reverse_A))

Submission status: Wrong Answer

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

prev_b = float("inf")
reverse_A = []
for b in B:
  if prev_b >= b:
    reverse_A.append(b)
    prev_b = b
  else:
    reverse_A.append(prev_b)
reverse_A.append(prev_b)
    
print(sum(reverse_A))

Submission status: Wrong Answer

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

prev_b = float("inf")
reverse_A = []
for b in B:
  if prev_b > b:
    reverse_A.append(b)
    prev_b = b
  else:
    reverse_A.append(prev_b)
reverse_A.append(prev_b)
    
print(sum(reverse_A))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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)
c = a+[b[n-2]]
a[n-1] = max(c)
#print(a)
print(sum(a))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
b=list(map(int,input().split()))
if N==2:
    a=[b[0]]*2
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: Wrong Answer

Solution code:
N=int(input())
b=list(map(int,input().split()))
a=[b[0]]*2
if N>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: Wrong Answer

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

print(sum(A))

Submission status: Wrong Answer

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

if N == 2:
        print(B[0] * 2)
        exit()

sum = 0
for i in range(len(B)+1):
        if i == len(B):
                sum += B[-1]
        elif i == 0:
                sum += max(B[0], B[1])
        else:
                sum += min(B[i-1], B[i])
print(sum)

Submission status: Wrong Answer

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

if N == 2:
        print(B[0] * 2)
        exit()

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

Submission status: Wrong Answer

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

if len(B) == 1:
        print(B[0] * 2)
        exit()

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

ans += bs[-1]

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
B = np.array(list(map(int, input().split())))

B_index = np.argsort(B)
# print(B)
# print(B_index)
A = [-1] * (len(B)+1)
for i in B_index:
    if A[i] < 0:
        A[i] = B[i]
        A[i+1] = B[i]
    else:
        if A[i+1] < 0:
            A[i+1] = B[i]
print(sum(A))

Submission status: Wrong Answer

Solution code:
#c
import numpy as np
N = int(input())
B = list(map(int, input().split()))
A = [0]*N
if N>2:
    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))
else:
    print(B[0]*2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
b = list(map(int, input().split()))
if n == 2:
    print(b[0] * 2)
    exit()

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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-1):
    A[i]=max(A[i-1],B[i-1],B[i])
A[N-1]=B[N-2]

print(*A)

Submission status: Wrong Answer

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-1):
    print(i)
    A[i]=max(A[i-1],B[i-1],B[i])
A[N-1]=B[N-2]

print(*A)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0
for idx, val in enumerate(B):
    if idx == 1:
        ans += val
    else:
        ans += max(B[idx - 1], val)

print(ans)

Submission status: Wrong Answer

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

a = [b[0]]

ta = 0 # temporal a
for i in range(n - 2):
    ta = min(b[i - 1], b[i])
    a.append(ta)
    
ans = sum(a) + b[n - 2]

print(ans)

Submission status: Wrong Answer

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

	for i in range(0,int(len(B))):
		# print(i)
		A_left = B[i-1]
		A_right = B[i]
		A.append(min(A_left,A_right))

	A.append(B[-1])
	ans = 0
	for i in range(0,len(A)):
		ans += A[i]

	print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
B = [int(i) for i in input().split()]
A = [1e5+1] * N

while 1e5+1 in A:
    max_val = max(B)
    index = B.index(max_val)
    if A[index] > B[index]:
        A[index] = B[index]
    if A[index+1] > B[index]:
        A[index+1] = B[index]
    B[index] = -1
        
print(sum(A))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

A=[0]*N

MIN = float('inf')
for i in reversed(range(N)):
    if (B[i-1] < MIN):
        MIN = B[i-1]
    A[i] = MIN

print(sum(A))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
B =list(map(int,input().split()))
sumN=B[0]
last = 5
for x in range(1,N-2,1):
    sumN += min(B[x],B[x+1])
sumN +=B[-1]

Submission status: Wrong Answer

Solution code:
n=int(input())
b=[int(_) for _ in input().split()]
print(sum(b)+b[0])

Submission status: Wrong Answer

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] = max(B[N-3],B[N - 2])

print(sum(A))

Submission status: Wrong Answer

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

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

A[N - 1] = max(B[N-3],B[N - 2])
print(sum(A))

Submission status: Wrong Answer

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

    
A = [0] * N
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: Wrong Answer

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

b = 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: Wrong Answer

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(max(B[N-3], B[N-2]))

print(sum(A))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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)

Submission status: Wrong Answer

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(b[i])
a.append(b[len(b)-1])

print(sum(a))

Submission status: Wrong Answer

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]))
    print(b[i])
a.append(b[len(b)-1])

print(sum(a))

Submission status: Wrong Answer

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

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

print(sum(a))

Submission status: Wrong Answer

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

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

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

print(sum(a))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(res)

Submission status: Wrong Answer

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

if n == 2:
	res += bs[-1]
else:
	res += max(bs[-1], bs[-2])

print(res)

Submission status: Wrong Answer

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
#
# bi > bi+1 のとき、bi = bi+1にする必要がある

# a1 = a2 = b1
# a3 = b2
# ...
# an = bn-1 

# よって、ans = b1 + sum_i{bi}
b2 = [] 
for i in range(len(b)-1):
    if b[i] > b[i+1]:
        b2.append(b[i+1])
    else:
        b2.append(b[i])
b2.append(b[-1])

ans = b2[0] + sum(b2)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

  ans += B[0]
  ans += B[-1]
print(ans)

Submission status: Wrong Answer

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: Wrong Answer

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

x=b[0]

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: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding:utf8 -*-

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

ans = 0
for i, n in enumerate(reversed(b)):
    if i == 0:
        t = n
        ans += t
    else:
        if n <= b[i - 1]:
            t = n
        else:
            t = b[i - 1]
        ans += t
    if i == len(b) - 1:
        ans += t
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
x=list(map(int,input().split()))
ans=2*x[0]+x[n-2]
if n>3:
    for i in range(1,n-2):
        if x[i-1]<x[i] and x[i+1]<x[i]:
            x[i]=max(x[i-1],x[i+1])
        ans+=x[i]
elif n==3:
    ans+=0
else:
    ans-=x[n-2]
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
x=list(map(int,input().split()))
ans=2*x[0]+x[n-2]
if n>3:
    for i in range(1,n-2):
        if x[i-1]<x[i] and x[i+1]<x[i]:
            x[i]=max(x[i-1],x[i+1])
        ans+=x[i]
elif n==3:
    ans+=x[0]
else:
    ans-=x[n-2]
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
x=list(map(int,input().split()))
ans=x[0]+x[n-2]
if n>3:
    for i in range(1,n-2):
        if x[i-1]<x[i] and x[i+1]<x[i]:
            x[i]=max(x[i-1],x[i+1])
        ans+=x[i]
elif n==3:
    ans+=x[0]
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

point = 0

if n == 2:
  point = int(a[0])*2
else:
  for i in range(n-1):
    if i == (n-2):
      point += int(a[i])
    else:
      point += min([int(a[i]),int(a[i+1])])

print(point)

Submission status: Wrong Answer

Solution code:
n = int(input())
list1 = list(map(int,input().split()))
cout = list1[-1]
min_int = list1[-1]
for i in range(n-3,-1,-1):
    cout += min(list1[i:])

cout += list1[0]

print(cout)

Submission status: Wrong Answer

Solution code:
n = int(input())
list1 = list(map(int,input().split()))
cout = 0
min_int = list1[-1]
for i in range(n-2,-1,-1):
    cout += min(min_int,list1[i])
    if min_int > list1[i]:
        min_int = list1[i]
cout += list1[0]

print(cout)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

a = []

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

for i in range(1,n-1):
	print(b[i])
	a.append(b[i])
	if b[i] < b[i-1]:
		a[i] = b[i]

print(sum(a))

Submission status: Wrong Answer

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

A[n-1] = B[n-2]

print(sum(A))

Submission status: Wrong Answer

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

if n > 1:
    A[n-1] = max(A[n-2], B[n-2])
else:
    A[n-1] = B[n-1]

print(sum(A))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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