n=int(eval(input()))

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

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

al[n-1]=bl[n-2]

for i in range(n-2,-1,-1):

    if al[i+1]>bl[i]:

        al[i+1]=bl[i]

    al[i]=bl[i]

print((sum(al)))

n=int(eval(input()))

#a,b,x=map(int,input().split())

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

#l=[list(map(int,input().split())) for i in range(n)]



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



al[n-1]=bl[-1]



for i in range(n-2,-1,-1):

    al[i]=bl[i]

    if al[i+1]>bl[i]:

        al[i+1]=bl[i]



print((sum(al)))

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

n = int(eval(input()))
# a,b,x=map(int,input().split())
bl = list(map(int, input().split()))
# l=[list(map(int,input().split())) for i in range(n)]
al = [0 for i in range(n)]
al[n - 1] = bl[-1]
for i in range(n - 2, -1, -1):
    al[i] = bl[i]
    if al[i + 1] > bl[i]:
        al[i + 1] = bl[i]
print((sum(al)))

+# a,b,x=map(int,input().split()) +# l=[list(map(int,input().split())) for i in range(n)] -al[n - 1] = bl[n - 2] +al[n - 1] = bl[-1] +    al[i] = bl[i] -    al[i] = bl[i]