CodeEff/ECCO huggingface dataset:
# Original solution
def solve(placed, w1, w2):
  n = len(N) - len(placed)
  x = list(set(N) - set(placed))
  if x == []:
    a = tuple(placed)
    D1[a] = w1
    D2[a] = w2
    return
  
  for e in x:
    w = Food[e][0]
    if w2 > Food[e][1]: return
    a = w1 + w * n
    b = w2 + w
    solve(placed+[e], a, b)
  return

while 1:
  n = eval(input())
  if n==0: break
  D1 = {}
  D2 = {}
  Name = {}
  Food = {}
  N = list(range(n))
  for i in N:
    a = input().split()
    Food[i] = list(map(int, a[1:]))
    Name[i] = a[0]
    
  solve([], 0, 0)
  
  Index, e = sorted(list(D1.items()), key = lambda x: x[1])[0]
  for e in list(Index)[::-1]:
    print(Name[e])

# Optimized solution
def solve(placed, w1, w2):
  global weight, D
  n = len(N) - len(placed)
  x = list(set(N) - set(placed))
  if x == []:
    if weight > w1:
      D = placed
      weight = w1
    return
   
  for e in x:
    w = Food[0][e]
    if w2 > Food[1][e]: return
    a = w1 + w * n
    if a > weight: return
    b = w2 + w
    solve(placed+[e], a, b)
  return
 
while 1:
  n = eval(input())
  if n==0: break
  Food = {}
  weight = 1e9
  N = list(range(n))
  x = []
  for i in N:
    a = input().split()
    x.append(list(map(int, a[1:]))+[a[0]])
  Food = list(zip(*sorted(x)))
  solve([], 0, 0)
  for e in D[::-1]:
    print(Food[2][e])
# Original solution
def solve(placed, w1, w2):
  global weight, D
  n = len(N) - len(placed)
  x = list(set(N) - set(placed))
  if x == []:
    if weight > w1:
      D = placed
      weight = w1
    return
   
  for e in x:
    w = Food[0][e]
    if w2 > Food[1][e]: return
    a = w1 + w * n
    if a > weight: return
    b = w2 + w
    solve(placed+[e], a, b)
  return
 
while 1:
  n = eval(input())
  if n==0: break
  Food = {}
  weight = 1e9
  N = list(range(n))
  x = []
  for i in N:
    a = input().split()
    x.append(list(map(int, a[1:]))+[a[0]])
  Food = list(zip(*sorted(x)))
  solve([], 0, 0)
  for e in D[::-1]:
    print(Food[2][e])

# Optimized solution
def solve(placed, w1, w2):
  global weight, D
  n = len(N) - len(placed)
  x = list(set(N) - set(placed))
  if x == []:
    if weight > w1:
      D = placed
      weight = w1
    return
   
  for e in x:
    w = W[e]
    if w2 > S[e]: return
    a = w1 + w * n
    if a > weight: return
    b = w2 + w
    solve(placed+[e], a, b)
  return
 
while 1:
  n = eval(input())
  if n==0: break
  D = []
  weight = 1e9
  N = list(range(n))
  f = lambda x: [int(x[1]),int(x[2]),x[0]]
  x = [f(input().split()) for _ in [0]*n]
  W, S, Name = list(zip(*sorted(x)))
  solve([], 0, 0)
  for e in D[::-1]:
    print(Name[e])
# Original solution
def solve(placed, w1, w2):
  global weight, D
  n = len(N) - len(placed)
  x = list(set(N) - set(placed))
  if x == []:
    if weight > w1:
      D = placed
      weight = w1
    return
   
  for e in x:
    w = W[e]
    if w2 > S[e]: return
    a = w1 + w * n
    if a > weight: return
    b = w2 + w
    solve(placed+[e], a, b)
  return
 
while 1:
  n = eval(input())
  if n==0: break
  D = []
  weight = 1e9
  N = list(range(n))
  f = lambda x: [int(x[1]),int(x[2]),x[0]]
  x = [f(input().split()) for _ in [0]*n]
  W, S, Name = list(zip(*sorted(x)))
  solve([], 0, 0)
  for e in D[::-1]:
    print(Name[e])

# Optimized solution
def solve(placed, w1, w2):
  global ans
  n = len(N) - len(placed)
  if n==0:
    ans = min(ans, [w1, placed])
    return

  for e in N:
    if e in placed: continue
    w, lim, s = Food[e]
    if w2 > lim: return
    a = w1 + w * n
    if a > ans[0]: return
    solve(placed+[e], a, w2 + w)
  return
 
while 1:
  n = eval(input())
  if n==0: break
  ans = [1e9, []]
  N = list(range(n))
  f = lambda x: list(map(int, x[1:3])) + [x[0]]
  Food = [f(input().split()) for _ in [0]*n]
  solve([], 0, 0)
  for e in ans[1][::-1]:
    print(Food[e][2])
# Original solution
def solve(placed, w1, w2):
  global ans
  n = len(N) - len(placed)
  if n==0:
    ans = min(ans, [w1, placed])
    return

  for e in N:
    if e in placed: continue
    w, lim, s = Food[e]
    if w2 > lim: return
    a = w1 + w * n
    if a > ans[0]: return
    solve(placed+[e], a, w2 + w)
  return
 
while 1:
  n = eval(input())
  if n==0: break
  ans = [1e9, []]
  N = list(range(n))
  f = lambda x: list(map(int, x[1:3])) + [x[0]]
  Food = [f(input().split()) for _ in [0]*n]
  solve([], 0, 0)
  for e in ans[1][::-1]:
    print(Food[e][2])

# Optimized solution
def solve(G1, G2, w1, w2):
  global ans
  n = len(G2)
  for e in G2:
    w, lim, s = Food[e]
    a = w1 + w * n
    if w2 > lim or a > ans[0]: return
    b = G1 + [e]
    if n == 1:
      ans = min(ans, [a, b])
    else:
      x = G2[:]
      x.remove(e)
      solve(b, x, a, w2 + w)
  return
 
while 1:
  n = eval(input())
  if n==0: break
  ans = [1e9, []]
  N = list(range(n))
  f = lambda x: list(map(int, x[1:3])) + [x[0]]
  Food = [f(input().split()) for _ in [0]*n]
  solve([], N, 0, 0)
  for e in ans[1][::-1]:
    print(Food[e][2])
# Original solution
while 1:
    w = input()
    if w=="0000": break
    if int(w)%1111==0:
        print("NA")
        continue
    ans = 0
    while(w!="6174"):
        w = str(int("".join(sorted(w,reverse=True)))-int("".join(sorted(w))))
        ans += 1
    print(ans)

# Optimized solution
while 1:
    w = input()
    if w=="0000": break
    if int(w)%1111==0:
        print("NA")
        continue
    ans = 0
    while(w!="6174"):
        w = ("".join(sorted(w))).zfill(4)
        w = str(int(w[::-1])-int(w))
        ans += 1
    print(ans)
# Original solution
while 1:
	n=list(input())
	if n==["0"]*4: break
	elif n[0]==n[1]==n[2]==n[3]:
		print("NA")
		continue
	count=0
	while 1:
		if n==["6","1","7","4"]:
			print(count)
			break
		l=int("".join(map(str,sorted(n)[::-1])))
		s=int("".join(map(str,sorted(n)[n.count("0"):])))
		n=list(str(l-s))
		for i in range(4-len(n)):
			n.insert(0,"0")
		count+=1

# Optimized solution
while 1:
	n=list(input())
	if n==["0"]*4: break
	elif n[0]==n[1]==n[2]==n[3]:
		print("NA")
		continue
	count=0
	while 1:
		if n==["6","1","7","4"]:
			print(count)
			break
		l=int("".join(map(str,sorted(n)[::-1])))
		s=int("".join(map(str,sorted(n)[n.count("0"):])))
		n=list(str(l-s))
		n=["0"]*(4-len(n))+n
		count+=1
# Original solution
while 1:
	n=list(input())
	if n==["0"]*4: break
	elif n[0]==n[1]==n[2]==n[3]:
		print("NA")
		continue
	count=0
	while 1:
		if n==["6","1","7","4"]:
			print(count)
			break
		l=int("".join(map(str,sorted(n)[::-1])))
		s=int("".join(map(str,sorted(n)[n.count("0"):])))
		n=list(str(l-s))
		n=["0"]*(4-len(n))+n
		count+=1

# Optimized solution
while 1:
	n=list(input())
	if n==["0"]*4: break
	elif n[0]==n[1]==n[2]==n[3]:
		print("NA")
		continue
	count=0
	while 1:
		if n==["6","1","7","4"]:
			print(count)
			break
		n=sorted(n)
		l=int("".join(map(str,n[::-1])))
		s=int("".join(map(str,n[n.count("0"):])))
		n=list(str(l-s))
		n=["0"]*(4-len(n))+n
		count+=1
# Original solution
while 1:
	n=list(input())
	if n==["0"]*4: break
	elif n[0]==n[1]==n[2]==n[3]:
		print("NA")
		continue
	count=0
	while 1:
		if n==["6","1","7","4"]:
			print(count)
			break
		n=sorted(n)
		l=int("".join(map(str,n[::-1])))
		s=int("".join(map(str,n[n.count("0"):])))
		n=list(str(l-s))
		n=["0"]*(4-len(n))+n
		count+=1

# Optimized solution
while 1:
    n=input()
    if n=="0000": break
    if int(n)%1111==0:
        print("NA")
        continue
    ans = 0
    while n!="6174":
        n="".join(sorted(n))
        n=str(int(n[::-1])-int(n)).zfill(4)
        ans+=1
    print(ans)
# Original solution

def main():
    X, Y = list(map(int, input().split()))

    tmp = X
    cnt = 1

    # print(tmp)
    while tmp * 2 <= Y:
        cnt += 1
        tmp = 2 * tmp
        # print(tmp)


    print(cnt)
    



if __name__ == "__main__":
    main()

# Optimized solution
X, Y = list(map(int, input().split()))

t = X
cnt = 0
while t <= Y:
    cnt += 1
    t *= 2

print(cnt)
# Original solution
X, Y = list(map(int, input().split()))
ans = 1
while 2 ** ans <= Y // X:
  ans += 1
print(ans)


# Optimized solution
X, Y = list(map(int, input().split()))

ans = 0
tgt = X

while tgt <= Y:
    tgt *= 2
    ans += 1

print(ans)
# Original solution
def main():
    x, y = list(map(int, input().split()))

    r = 1
    a = x
    while True:
        a *= 2
        if a <= y:
            r += 1
        else:
            break
    print(r)

if __name__ == '__main__':
    main()


# Optimized solution
def main():
    x, y = list(map(int, input().split()))
    cnt = 0
    while x <= y:
        cnt += 1
        x *= 2
    print(cnt)


if __name__ == '__main__':
    main()
# Original solution
from math import log2
x, y = list(map(int, input().split()))
k = int(log2(y)-log2(x)+1)
n =x*2**(k-1)
if n <= y:
    if 2*n <= y:
        print((k+1))
    else:
        print(k)
else:
    print((k-1))


# Optimized solution
x, y = list(map(int, input().split()))

for i in range(1, 100):
    n = x*2**(i-1)
    if n <= y:
        ans = i
    else:
        print(ans)
        exit()
# Original solution
x, y = list(map(int, input().split()))

a = []
t = x
while True:
    if t > y:
        break
    a.append(t)
    t *= 2

print((len(a)))

# Optimized solution
x, y = list(map(int, input().split()))
total = 1
now = x
while now*2 <= y:
    now *= 2
    total += 1
print(total)
# Original solution
#ABC083
x,y=list(map(int,input().split()))
cnt=1
now=x
while True:
    now*=2
    if now>y:break
    cnt+=1
print(cnt)

# Optimized solution
x,y=list(map(int,input().split()))
ans=1
now=x
while True:
    if now*2>y:
        break
    else:
        now*=2
        ans+=1
print(ans)
# Original solution
# coding: utf-8

# input
x, y = list(map(int, input().split()))

# main
count = 0
while x <= y:
    count += 1
    x *= 2

print(count)

# Optimized solution
# input
x, y = list(map(int, input().split()))

# main
c = 0
while x <= y:
    x *= 2
    c += 1

print(c)
# Original solution
import sys
sys.setrecursionlimit(1000000)
from operator import itemgetter

X,Y = list(map(int, input().split()))

cnt = 1
temp = X

for i in range(100):
    if temp * 2 <= Y:
        cnt += 1
        temp = temp * 2
    else:
        break

print(cnt)

# Optimized solution
x,y = list(map(int,input().split()))

cnt = x
ans = 1

while cnt * 2 <= y:
    ans += 1
    cnt = cnt * 2
    
print(ans)
# Original solution
import sys
import math

x, y = [int(x) for x in sys.stdin.readline().split()]

count = 0
while x <= y:
    count += 1
    x *= 2

print(count)


# Optimized solution
import sys

x, y = list(map(int, sys.stdin.readline().split()))

def main():
    a = x
    cnt = 0
    while a <= y:
        cnt += 1
        a *= 2
    return cnt

if __name__ == '__main__':
    ans = main()
    print(ans)
# Original solution
x, y = list(map(int, input().split()))
result = 0
while x <= y:
  result += 1
  x *= 2
print(result)


# Optimized solution
x, y = list(map(int, input().split()))
print(((y // x).bit_length()))
# Original solution
X,Y = list(map(int,input().split()))

def solve(now,y,ans=1):
  if now*2 > y:
    return ans
  else:
    return solve(now*2,y,ans+1)
  
print((solve(X,Y)))

# Optimized solution
X,Y = list(map(int,input().split()))

def solve(now,y,ans=0):
  ans = 0
  while now <= y:
    ans += 1
    now *= 2
  return ans
  
print((solve(X,Y)))
# Original solution
X, Y = list(map(int, input().split()))

ans = 1
while True:
  if 2*X <= Y:
    X *= 2
    ans += 1
  else:
    break
print(ans)

# Optimized solution
X, Y = list(map(int, input().split()))

print((len(bin(Y // X)[2:])))
# Original solution
X,Y=[int(i) for i in input().split()]

lenCount = 0
while X <= Y:
    X *= 2
    lenCount += 1

print(lenCount)

# Optimized solution
X,Y = list(map(int,input().split()))
res = 0

while X <= Y:
    X *= 2
    res += 1

print(res)
# Original solution
X, Y = list(map(int, input().split()))
ans = 1
for i in range(10**18):
    X *= 2
    if X <= Y:
        ans += 1
    else:
        break
print(ans)

# Optimized solution
X, Y = list(map(int, input().split()))
ans = 1
for i in range(10**5):
    X *= 2
    if X <= Y:
        ans += 1
    else:
        break
print(ans)
# Original solution
# -*- coding: utf-8 -*-

x,y = list(map(int,input().split()))

under = x
up = 0
ans = 0

for i in range(90):
    temp = x * 2 ** i
    if temp > y and up == 0:
        up = temp / 2
        ans = i
        break

print(ans)


# Optimized solution
# -*- coding: utf-8 -*-

x,y = list(map(int,input().split()))

num = x
cnt = 0
while x <= y:
    x *= 2
    cnt += 1

print(cnt)
# Original solution
X, Y = list(map(int, input().split()))
t = X
ans = 0
while t <= Y:
    t *= 2
    ans += 1
print(ans)

# Optimized solution
X, Y = list(map(int,input().split()))

ans = 0
while X <= Y:
    X *= 2
    ans += 1
print(ans)
# Original solution
x,y=list(map(int,input().split()))
ans_li=[]
for i in range(1000):
    if x*(2**i)<=y:
        ans_li.append(i+1)
print((max(ans_li)))

# Optimized solution
x,y=list(map(int,input().split()))
ans=0
while x<=y:
    x*=2
    ans+=1
print(ans)
# Original solution
x,y = list(map(int,input().split()))
import copy
x1=copy.deepcopy(x)
y1=copy.deepcopy(y)
count=0

while(y1>=x1):
    y1//=2
    count+=1

print(count)


# Optimized solution
X, Y = list(map(int,input().split()))

A = X
ans = 1

while(1):
    if X*2 > Y:
        break
    X *= 2
    ans += 1

print(ans)
# Original solution
x,y=list(map(int,input().split()))
i=1
while True:
  x*=2
  if x>y:
    break
  i+=1
print(i)

# Optimized solution
x,y=list(map(int,input().split()))
a=0
while x<=y:
  x*=2
  a+=1
print(a)
# Original solution
X,Y = list(map(int,input().split()))
print((len(bin(Y//X))-2))

# Optimized solution
X,Y = list(map(int,input().split()))
ans = 0

while X<=Y:
  ans+=1
  X*=2

print(ans)
# Original solution
# vim: set fileencoding=utf-8:
"""
X,Yの区間は[1, pow(10,18)]であり、全探索すると日が暮れる。
厳密には、区間[X, Y]のすべてを検証する必要はないはずで、
[X, 2*X]でいいはずである。たぶん。

"""


def main():
    X, Y = list(map(int, input().split()))
    ans = 0
    temp = 0

    X2 = 2 * X
    ct = 0
    for i, _ in enumerate(range(X2), X):
        ct += 1
        n = i
        while n <= Y:
            temp += 1
            n *= 2

        ans = max(ans, temp)
        temp = 0
        if ct == 400000:
            break

    print(ans)


if __name__ == "__main__":
    main()



# Optimized solution
#!/usr/bin/python3
# vim: set fileencoding=utf-8:
import sys
input = sys.stdin.readline

"""
H = int(input())
h = [int(ele) for ele in input().split()]
h = [0] + h
"""


def main():
    A = []
    X, Y = list(map(int, input().split()))
    n = X
    A.append(n)

    while n * 2 <= Y:
        n = n*2
        A.append(n)

    print((len(A)))


def bfs(queue):
    global yet, graph
    if len(queue) == 0:
        return
    yet.remove(queue[-1])

    for i, adjacency in enumerate(graph[queue[-1]]):
        if adjacency == 1 and (i in yet) and (i not in queue):  # 隣接かつ未探索であれば、stackにpush
            queue.appendleft(i)
    else:
        queue.pop()
        bfs(queue)


def dfs(stack):
    global yet, graph
    yet.remove(stack[-1])

    for i, adjacency in enumerate(graph[stack[-1]]):
        if adjacency == 1 and i in yet:  # 隣接かつ未探索であれば、stackにpush
            stack.append(i)
            dfs(stack)
    else:
        stack.pop()


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
        if i != n // i:
            divisors.append(n//i)
    return divisors


class Node():

    def __init__(self):
        self.idx = None
        self.left = None
        self.right = None
        self.parent = None
        return

    def pre_order(self):
        global pre_order_str
        pre_order_str += str(self.idx) + " "
        if self.left:
            self.left.pre_order()

        if self.right:
            self.right.pre_order()

    def in_order(self):
        global in_order_str

        if self.left:
            self.left.in_order()

        in_order_str += str(self.idx) + " "

        if self.right:
            self.right.in_order()

    def post_order(self):
        global post_order_str
        if self.left:
            self.left.post_order()

        if self.right:
            self.right.post_order()

        post_order_str += str(self.idx) + " "


class HeapHelper():
    """HeapContrler.
    完全二分木を二分ヒープで表現した配列 A に対して、
    HeapHelper.parent(idx) とするとそのノードの親の添字を返す
    存在しない場合は Falseを返す

    Returns:
        [type] -- [description]
    """

    def __init__(self):
        return

    @staticmethod
    def parent(i):
        if i == 1:
            return False

        return int(i/2)

    @staticmethod
    def left(i):
        l_idx = 2*i
        if H < l_idx:
            return False

        return l_idx

    @staticmethod
    def right(i):
        r_idx = 2*i + 1
        if H < r_idx:
            return False

        return r_idx


if __name__ == "__main__":
    main()
# Original solution
x, y = list(map(int, input().split()))
count = 0
z = x
while True:
    z *= 2
    count += 1
    if z > y:
        break
print(count)

# Optimized solution
x, y = list(map(int, input().split()))
current = x
ans = 1
while True:
    current *= 2
    if current > y:
        break
    ans += 1

print(ans)
# Original solution
x, y = list(map(int, input().split()))
ans = 1
while x <= y:
    x *= 2 
    if x > y:
        break 
    ans += 1

print(ans)

# Optimized solution
X, Y = list(map(int, input().split()))
ans = 1
while X <= Y:
    X *= 2
    if X > Y:
        break
    ans += 1

print(ans)
# Original solution
X, Y = list(map(int,input().split()))
ans = 0
while X <= Y:
  X *= 2
  ans += 1
print(ans)

# Optimized solution
X, Y = list(map(int,input().split()))
cnt = 0
while X <= Y:
  X *= 2
  cnt += 1
print(cnt)
# Original solution
def c_MultipleGift(X, Y):
    ans = 0
    while X <= Y:
        X *= 2
        ans += 1
    return ans

X,Y = [int(i) for i in input().split()]
print((c_MultipleGift(X, Y)))

# Optimized solution
def c_multiple_gift(X, Y):
    ans = 1  # A_1=Xとなる長さ1の数列が必ず作れる
    while X <= Y:
        X *= 2  # A_{i+1} = 2A_iとする
        ans += 1
    ans -= 1  # whileの最後でYを超える要素を1つ入れたので除く
    return ans 

X,Y = [int(i) for i in input().split()]
print((c_multiple_gift(X, Y)))
# Original solution
X, Y = list(map(int, input().split()))

ans = 0
tmp = X
while tmp <= Y:
    tmp *= 2
    ans += 1

print(ans)


# Optimized solution
X, Y = list(map(int, input().split()))

cnt = 0
while X <= Y:
    cnt += 1
    X *= 2

print(cnt)
# Original solution
n=int(input())
a=sorted(map(int,input().split()))
a.reverse()
i=0
while i<n and a[i]>=i+1:i+=1
m1=a[i-1]-i
j=i
while j<n and a[j]>=i:j+=1
m2=j-i
print('First' if (m1%2 or m2%2) else 'Second')


# Optimized solution
n=int(input())
a=sorted(map(int,input().split()))
a.reverse()
i=0
while i<n and a[i]>=i+1:i+=1
j=i
while j<n and a[j]>=i:j+=1
print('First' if (a[i-1]-i)%2 or (j-i)%2 else 'Second')
# Original solution
N = int(eval(input()))
b = list(map(int, input().split()))
a = []
for i in range(N-1):
  if(i == 0):
    a.append(b[i])
  else:
    if(b[i] > b[i-1]):
      a.append(b[i-1])
    else:
      a.append(b[i])
  if(i == N-2):
    a.append(b[i])      
print((sum(a)))

# Optimized solution
N = int(eval(input()))
b = list(map(int, input().split()))
a = []
a.append(b[0])
for i in range(1, N-1):
  a.append(min(b[i], b[i-1]))
a.append(b[N-2])
print((sum(a)))
# Original solution
n = int(eval(input()))
b = list(map(int, input().split()))

a = [0]*n
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)))

# Optimized solution
n = int(eval(input()))
b = list(map(int, input().split()))

ans = [0]*n
ans[0] = b[0]
ans[-1] = b[-1]
for i in range(1,n-1):
  ans[i] = min(b[i-1],b[i])
print((sum(ans)))
# Original solution
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)))


# Optimized solution
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)))
# Original solution
n = int(eval(input()))
b = list(map(int, input().split()))

a = [b[0]]

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

    while b[i] < max(a[i], a[i+1]):
        a[i+1] += 1

print((sum(a)))


# Optimized solution
n = int(eval(input()))
b = list(map(int, input().split()))

a = [b[0]]

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

print((sum(a)))
# Original solution
n=int(eval(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])

print((sum(a)+b[-1]))

# Optimized solution
n=int(eval(input()))
b=list(map(int,input().split()))
a=[0]*n
a[0]=b[0]
a[-1]=b[-1]
for i in range(1,n-1):
    a[i]=min(b[i],b[i-1])
print((sum(a)))
# Original solution
N = int(eval(input()))
B = list(map(int, input().split()))

A=[10**6]*N

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

print((sum(A)))

# Optimized solution
N=int(eval(input()))
B=list(map(int,input().split()))

A=[0]*N

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

for i in range(1,N-1):
    A[i+1]=B[i]
    if A[i] > B[i]:
        A[i] = B[i]
print((sum(A)))
# Original solution
n = int(eval(input()))
b = list(map(int, input().split()))

a = [0 for k in range(n)]
a[0] = b[0]
a[n-1] = b[n-2]

for i in range(1, n-1):
  j=0
  while not j == min(b[i], b[i-1]):
    j += 1
  a[i]=j
  
ans = 0
for x in range(n):
  ans += a[x]

print(ans)

# Optimized solution
n = int(eval(input()))
b = list(map(int, input().split()))

a = [0 for k in range(n)]
a[0] = b[0]
a[n-1] = b[n-2]

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

print(ans)
# Original solution
n=int(eval(input()))
B=list(map(int,input().split()))
ans=[B[0],B[n-2]]

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

# Optimized solution
n=int(eval(input()))
B=list(map(int,input().split()))
ans = B[0]+B[n-2]

for i in range(n-2):
  ans += min(B[i],B[i+1])
  
print(ans)
# Original solution
import sys
input = sys.stdin.readline

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

C = [None] * N
C[0] = B[0]
C[-1] = B[-1]

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

print((sum(C)))

# Optimized solution
N = int(eval(input()))
B = list(map(int, input().split()))

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

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

print((sum(A)))
# Original solution
N = int(eval(input()))
B = [int(i) for i in input().split()]

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

print((sum(A)))

# Optimized solution
n = int(eval(input()))
bl = list(map(int, input().split()))
ans = bl[0]+bl[-1]
for i in range(n-2):
    ans+=min(bl[i], bl[i+1])
print(ans)
# Original solution
N = int(eval(input()))
if N == 2:
  ans = 2 * int(eval(input()))
else:
  B = list(map(int, input().split()))
  ans = B[0] + B[N-2]
  for i in range(1, N-1):
    ans += min(B[i], B[i-1])
print(ans)

# Optimized solution
N = int(eval(input()))
B = list(map(int, input().split()))
ans = B[0] + B[N-2]
for i in range(1, N-1):
  ans += min(B[i], B[i-1])
print(ans)
# Original solution
n = int(eval(input()))
B = list(map(int, input().split()))

a = [-1] * n

for i, b in enumerate(B):
    if a[i] > B[i]:
        a[i] = b
        a[i+1] = b
    elif a[i] != -1:
        a[i+1] = b
    elif a[i] == -1:
        a[i] = b
        a[i+1] = b

print((sum(a)))

# Optimized solution
n = int(eval(input()))
B = list(map(int, input().split()))

a = [0] * n
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)))
# Original solution
_,b=open(0);*b,=list(map(int,b.split()));print((b[0]+sum(min(t)for t in zip(b,b[1:]))+b[-1]))

# Optimized solution
_,b=open(0);*b,=list(map(int,b.split()));print((b[0]+sum(map(min,list(zip(b,b[1:]))))+b[-1]))