Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair of houses. The length of a path between Rabbit's and Owl's houses is a meters, between Rabbit's and Eeyore's house is b meters, between Owl's and Eeyore's house is c meters.

For enjoying his life and singing merry songs Winnie-the-Pooh should have a meal n times a day. Now he is in the Rabbit's house and has a meal for the first time. Each time when in the friend's house where Winnie is now the supply of honey is about to end, Winnie leaves that house. If Winnie has not had a meal the required amount of times, he comes out from the house and goes to someone else of his two friends. For this he chooses one of two adjacent paths, arrives to the house on the other end and visits his friend. You may assume that when Winnie is eating in one of his friend's house, the supply of honey in other friend's houses recover (most probably, they go to the supply store).

Winnie-the-Pooh does not like physical activity. He wants to have a meal n times, traveling minimum possible distance. Help him to find this distance.


-----Input-----

First line contains an integer n (1 ≤ n ≤ 100) — number of visits.

Second line contains an integer a (1 ≤ a ≤ 100) — distance between Rabbit's and Owl's houses.

Third line contains an integer b (1 ≤ b ≤ 100) — distance between Rabbit's and Eeyore's houses.

Fourth line contains an integer c (1 ≤ c ≤ 100) — distance between Owl's and Eeyore's houses.


-----Output-----

Output one number — minimum distance in meters Winnie must go through to have a meal n times.


-----Examples-----
Input
3
2
3
1

Output
3

Input
1
2
3
5

Output
0



-----Note-----

In the first test case the optimal path for Winnie is the following: first have a meal in Rabbit's house, then in Owl's house, then in Eeyore's house. Thus he will pass the distance 2 + 1 = 3.

In the second test case Winnie has a meal in Rabbit's house and that is for him. So he doesn't have to walk anywhere at all.

Difficulty: EASY
Tags: Mathematics

Starter code:

Solutions:
n = int(input())
a = int(input())
b = int(input())
c = int(input())
if n == 1:
	print(0)
	return
x = min(a, b, c)
if x in [a, b]:
	print((n - 1) * x)
else:
	print(min(a, b) + (n - 2) * c)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
ans = 0
if n == 1:
	print('0')
	exit()
if a > b:
	ans += b
	if b > c:
		ans += c * (n - 2)
	else:
		ans += b * (n - 2)
else:
	ans += a
	if a > c:
		ans += c * (n - 2)
	else:
		ans += a * (n - 2)
print(ans)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
n -= 1
s = 1
an = 0
while n:
	if s == 1:
		if a < b:
			s = 2
			an += a
		else:
			s = 3
			an += b
		n -= 1
	elif s == 2:
		if a < c:
			s = 1
			an += a
		else:
			s = 3
			an += c
		n -= 1
	else:
		if b < c:
			s = 1
			an += b
		else:
			s = 2
			an += c
		n -= 1
print(an)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
if n == 1:
	print(0)
elif n == 2:
	print(min(a, b))
else:
	print(min(a, b) + (n - 2) * min(a, min(b, c)))


n = int(input())
a = int(input())
b = int(input())
c = int(input())
z = 1
x = 0
y = 0
s = 0
if n == 1:
	print(0)
elif a < b and a < c:
	print(a * (n - 1))
elif b < c and b < a:
	print(b * (n - 1))
elif c < a and c < b:
	if b < a:
		print(b + c * (n - 2))
	else:
		print(a + c * (n - 2))
elif a == b and b == c:
	print((n - 1) * a)
elif a == b and b != c:
	print(a * (n - 1))


v = int(input()) - 1
(a, b, c) = (int(input()), int(input()), int(input()))
if v == 0:
	print(0)
elif min(a, b, c) == a or min(a, b, c) == b:
	print(a * v if a == min(a, b, c) else b * v)
else:
	print(min(a, b) + c * (v - 1))


def main():
	(n, a, b, c) = (int(input()) for _ in 'nabc')
	print(min(a, b) * (n > 1) + min(a, b, c) * (n - 2) * (n > 2))
main()


n = int(input())
a = int(input())
b = int(input())
c = int(input())
ans = 0
k = 1
for i in range(n - 1):
	if k == 1:
		if a < b:
			k = 2
			ans += a
		else:
			k = 3
			ans += b
	elif k == 2:
		if a < c:
			k = 1
			ans += a
		else:
			k = 3
			ans += c
	elif b < c:
		k = 1
		ans += b
	else:
		k = 2
		ans += c
print(ans)


def distance(n, a, b, c):
	if n == 1:
		return 0
	elif a < b:
		return a + distance(n - 1, a, c, b)
	else:
		return b + distance(n - 1, b, c, a)
I = lambda : int(input())
n = I()
a = I()
b = I()
c = I()
print(distance(n, a, b, c))


n = int(input())
a = int(input())
b = int(input())
c = int(input())
ans = 0
now = 'R'
for k in range(1, n):
	if now == 'R':
		if a >= b:
			ans += b
			now = 'E'
		elif a < b:
			ans += a
			now = 'O'
	elif now == 'O':
		if a >= c:
			ans += c
			now = 'E'
		elif a < c:
			ans += a
			now = 'R'
	elif b >= c:
		ans += c
		now = 'O'
	else:
		ans += b
		now = 'R'
print(int(ans))


n = int(input())
a = int(input())
b = int(input())
c = int(input())
k = min(a, b, c)
j = 1
m = 0
if n > 1:
	if k == c:
		m = min(a, b)
		j += 1
		while j < n:
			j += 1
			m += k
	else:
		while j < n:
			j += 1
			m += k
print(m)


(n, a, b, c) = [int(input()) for _ in range(4)]
print(min(a, b) + (n - 2) * min(a, b, c) if n > 2 else [min(a, b), 0][n == 1])


n = int(input())
a = int(input())
b = int(input())
c = int(input())

def min2(a, b):
	if a <= b:
		return a
	if b < a:
		return b

def min3(a, b, c):
	if a <= min(b, c):
		return a
	if b <= min(a, c):
		return b
	if c <= min(b, c):
		return c
s = 0
if n > 1:
	s = s + min2(a, b)
	s = s + (n - 2) * min3(a, b, c)
	print(s)
if n == 0 or n == 1:
	print(0)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
road_len = int()
first_way = min(a, b)
if n == 1:
	print(0)
else:
	road_len = first_way + (n - 2) * min(first_way, c)
	print(road_len)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
mx = max(a, b, c)
mn = min(a, b, c)
print(0 if n == 1 else min(a, b) + (n - 2) * mn)


n = int(input())
s = int(input())
t = int(input())
f = int(input())
if n == 1:
	print(0)
else:
	print(min(s, t) + min(s, t, f) * (n - 2))


(n, a, b, c) = map(int, (input() for i in range(4)))
print((min(a, b) + min(min(a, b), c) * (n - 2), 0)[n < 2])


def main():
	n = int(input())
	a = int(input())
	b = int(input())
	c = int(input())
	if n == 1:
		print(0)
		return
	print(min(a, b) + (n - 2) * min(a, b, c))
main()


import math
n = input().split()
a = input().split()
b = input().split()
c = input().split()
a1 = int(a[0])
b1 = int(b[0])
c1 = int(c[0])
nn = int(n[0])
nn = nn - 1
ans = 0
if b1 > c1 and c1 < a1 and (nn != 0):
	ans = min(b1, a1)
	nn = nn - 1
ans += min([a1, b1, c1]) * nn
print(ans)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
cur = 1
ans = 0
n -= 1
while n > 0:
	if cur == 1:
		if a > b:
			cur = 3
			ans += b
		else:
			cur = 2
			ans += a
	elif cur == 2:
		if a > c:
			cur = 3
			ans += c
		else:
			cur = 1
			ans += a
	elif b > c:
		cur = 2
		ans += c
	else:
		cur = 1
		ans += b
	n -= 1
print(ans)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
ans = 0
if n == 1:
	pass
elif n == 2:
	ans += min(a, b)
elif c < a and c < b:
	ans += min(a, b) + (n - 2) * c
else:
	ans += (n - 1) * min(a, b)
print(ans)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
curd = 'K'
ans = 0
while n > 1:
	n -= 1
	if curd == 'K':
		if a > b:
			ans += b
			curd = 'I'
		else:
			ans += a
			curd = 'S'
	elif curd == 'S':
		if a > c:
			ans += c
			curd = 'I'
		else:
			ans += a
			curd = 'K'
	elif b > c:
		ans += c
		curd = 'S'
	else:
		ans += b
		curd = 'K'
print(ans)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
if n == 1:
	print(0)
	exit()
short = min(a, b)
if min(short, c) != c:
	dis = (n - 1) * short
	print(dis)
else:
	dis = c * (n - 2)
	dis += short
	print(dis)


n = int(input())
R_to_O = int(input())
R_to_E = int(input())
O_to_E = int(input())
position = 'R'
distance = 0
while n > 1:
	if position == 'R':
		if R_to_O > R_to_E:
			distance += R_to_E
			position = 'E'
		else:
			distance += R_to_O
			position = 'O'
	elif position == 'O':
		if O_to_E > R_to_O:
			distance += R_to_O
			position = 'R'
		else:
			distance += O_to_E
			position = 'E'
	elif position == 'E':
		if O_to_E > R_to_E:
			distance += R_to_E
			position = 'R'
		else:
			distance += O_to_E
			position = 'O'
	n -= 1
print(distance)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
dist = 0
curr = 'r'
while n > 1:
	n -= 1
	if curr == 'e':
		if b < c:
			curr = 'r'
			dist += b
		else:
			curr = 'o'
			dist += c
	elif curr == 'o':
		if a < c:
			curr = 'r'
			dist += a
		else:
			curr = 'e'
			dist += c
	elif a < b:
		curr = 'o'
		dist += a
	else:
		curr = 'e'
		dist += b
print(dist)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
if n == 1:
	print(0)
else:
	small2 = min(a, b)
	small3 = min(small2, c)
	print(small2 + (n - 2) * small3)


import os
import sys

def main():
	pass

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def lts(l):
	s = ''.join(map(str, l))
	return s

def stl(s):
	l = list(s)
	return l

def sq(a, target, arr=[]):
	s = sum(arr)
	if s == target:
		return arr
	if s >= target:
		return
	for i in range(len(a)):
		n = a[i]
		remaining = a[i + 1:]
		ans = sq(remaining, target, arr + [n])
		if ans:
			return ans

def SieveOfEratosthenes(n):
	cnt = 0
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, n + 1):
		if prime[p]:
			cnt += 1
	return cnt

def nCr(n, r):
	f = math.factorial
	return f(n) // f(r) // f(n - r)
mod = int(1000000000.0) + 7

def ssinp():
	return input()

def iinp():
	return int(input())

def nninp():
	return map(int, input().split())

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

def p(xyz):
	print(xyz)

def p2(a, b):
	print(a, b)
import math
from collections import OrderedDict
n = int(input())
a = int(input())
b = int(input())
c = int(input())
if n == 0 or n == 1:
	print(0)
else:
	print(min(a, b) + (n - 2) * min(a, b, c))


n = int(input())
a = float(input())
b = float(input())
c = float(input())
if n < 2:
	print(0)
else:
	print(int((n - 2) * min(a, b, c) + min(a, b)))


n = int(input())
a = int(input())
b = int(input())
c = int(input())
options = [a * (n - 1), b * (n - 1)]
if n > 1:
	options.extend([a + c * (n - 2), b + c * (n - 2)])
ans = min(options)
print(ans)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
n -= 1
s = 0
p = 0
for i in range(n):
	if p == 0:
		if a <= b:
			s += a
			p = 1
		else:
			s += b
			p = 2
	elif p == 1:
		if a <= c:
			s += a
			p = 0
		else:
			s += c
			p = 2
	elif b <= c:
		s += b
		p = 0
	else:
		s += c
		p = 1
print(s)


n = int(input())
a = [0] * 3
a[0] = int(input())
a[2] = int(input())
a[1] = int(input())
p = 0
times = 1
ans = 0
while times < n:
	t = (p - 1 + 3) % 3
	if a[p] < a[t]:
		ans += a[p]
		p = (p + 1) % 3
	else:
		ans += a[t]
		p = (p - 1 + 3) % 3
	times += 1
print(ans)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
if n == 1:
	print(0)
elif a <= b and a <= c:
	print((n - 1) * a)
elif a <= b and a >= c:
	print(a + (n - 2) * c)
elif a >= b and c >= b:
	print((n - 1) * b)
elif a >= b and b >= c:
	print(b + (n - 2) * c)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
l = [a, b, c]
k = max(l)
l.remove(k)
i = min(l)
j = max(l)
if n == 1:
	print(0)
elif i == a or i == b:
	print((n - 1) * i)
else:
	print((n - 2) * i + j)


N = int(input())
A = int(input())
B = int(input())
C = int(input())
cnt = 0
result = 1145141919
res1 = A * (N - 1)
res2 = B * (N - 1)
if N >= 2:
	res3 = min(A, B) + C * (N - 2)
	result = min(result, res3)
result = min(result, res1, res2)
print(result)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
s = 0
if n == 1:
	print(0)
else:
	if a > b:
		s += b
		n -= 1
		while n > 1:
			if b > c:
				s += c
			else:
				s += b
			n -= 1
	else:
		s += a
		n -= 1
		while n > 1:
			if a > c:
				s += c
			else:
				s += a
			n -= 1
	print(s)


def path(a, b, c, n):
	if n == 1:
		return 0
	elif n == 2:
		return min(a, b)
	elif n > 2 and c >= min(a, b):
		return (n - 1) * min(a, b)
	elif n > 2 and c < min(a, b):
		return min(a, b) + (n - 2) * c

def main():
	n = int(input())
	a = int(input())
	b = int(input())
	c = int(input())
	x = path(a, b, c, n)
	print(x)
main()


n = int(input())
a = int(input())
b = int(input())
c = int(input())
ans = 0
t = 0
n -= 1
if n == 0:
	print(0)
	return
if c < a and c < b:
	ans = min(a, b) + (n - 1) * c
else:
	ans = min(a, b) * n
print(ans)


(n, a, b, c) = (int(input()), int(input()), int(input()), int(input()))
print((n > 1) * min(a, b) + max(0, n - 2) * min(a, b, c))


n = int(input())
a = int(input())
b = int(input())
c = int(input())
SUM = 0
if n > 1:
	if c < a and c < b:
		SUM = min(a, b)
		SUM += c * (n - 2)
	else:
		SUM = (n - 1) * min(a, b)
	print(SUM)
else:
	print(0)


n = int(input())
l = []
for i in range(3):
	l.append(int(input()))
if n == 1:
	print(0)
elif l[0] == min(l):
	print((n - 1) * l[0])
elif l[1] == min(l):
	print((n - 1) * l[1])
else:
	print(min(l[0], l[1]) + (n - 2) * l[2])


n = int(input())
a = int(input())
b = int(input())
c = int(input())
p = 1
r = 0
for i in range(n - 1):
	if p == 1:
		r += min(a, b)
		if a < b:
			p = 2
		else:
			p = 3
	elif p == 2:
		r += min(a, c)
		if a < c:
			p = 1
		else:
			p = 3
	elif p == 3:
		r += min(b, c)
		if b < c:
			p = 1
		else:
			p = 2
print(r)


a = int(input())
b = int(input())
c = int(input())
d = int(input())
if a == 1 or min(b, c, d) == b or min(b, c, d) == c:
	print(min(b, c) * (a - 1))
else:
	print(min(b, c) + d * (a - 2))


n = int(input())
a = int(input())
b = int(input())
c = int(input())
ans = 0
at = 1
for i in range(n - 1):
	if at == 1 and min(a, b) == a:
		ans += a
		at = 2
	elif at == 1 and min(a, b) == b:
		ans += b
		at = 3
	elif at == 3 and min(b, c) == b:
		ans += b
		at = 1
	elif at == 3 and min(b, c) == c:
		ans += c
		at = 2
	elif at == 2 and min(a, c) == a:
		ans += a
		at = 1
	else:
		ans += c
		at = 3
print(ans)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
h = 'r'
ans = 0
n = n - 1
while n != 0:
	if h == 'r':
		ans = ans + min(a, b)
		if min(a, b) == a:
			h = 'o'
		else:
			h = 'e'
	elif h == 'o':
		ans = ans + min(a, c)
		if min(a, c) == a:
			h = 'r'
		else:
			h = 'e'
	else:
		ans = ans + min(b, c)
		if min(b, c) == b:
			h = 'r'
		else:
			h = 'o'
	n = n - 1
print(ans)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
flag = 0
if a >= b:
	first = b
	if c <= b:
		flag = c
	else:
		flag = b
else:
	first = a
	if c <= a:
		flag = c
	else:
		flag = a
e = 1
sum = 0
while e < n:
	if e == 1:
		sum = sum + first
		e = e + 1
	else:
		sum = sum + flag
		e = e + 1
print(sum)


from sys import stdin, stdout
(n, a, b, c) = map(int, stdin.readlines())
dist = 0
n = n - 1
if n == 0:
	stdout.write('0')
elif min(a, b) > c:
	dist = min(a, b) + c * (n - 1)
	stdout.write(str(dist))
else:
	dist = min(a, b) * n
	stdout.write(str(dist))


n = int(input())
a = int(input())
b = int(input())
c = int(input())
r = [a, b]
o = [a, c]
e = [b, c]
p = 1
l = 0
y = r
while p < n:
	m = min(y)
	l += m
	p += 1
	if y == r:
		if m in o:
			y = o
		else:
			y = e
	elif y == o:
		if m in r:
			y = r
		else:
			y = e
	elif m in r:
		y = r
	else:
		y = o
print(l)


N = int(input())
N -= 1
A = int(input())
B = int(input())
C = int(input())
if N == 0:
	print(0)
	exit()
if A == min(A, B, C):
	print(N * A)
	exit()
if B == min(A, B, C):
	print(N * B)
	exit()
print(min(A, B) + C * (N - 1))


from collections import defaultdict, deque, Counter
from sys import stdin, stdout
from heapq import heappush, heappop
import math
import io
import os
import math
import bisect

def isPrime(x):
	for i in range(2, x):
		if i * i > x:
			break
		if x % i == 0:
			return False
	return True

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def digits(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def ceil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def mapin():
	return map(int, input().split())
n = int(input())
a = int(input())
b = int(input())
c = int(input())
ans = 0
n -= 1
temp = min(a, b)
if n > 0:
	ans += temp
	n -= 1
if n > 0:
	temp = min(temp, c)
	ans += temp * n
print(ans)


n = int(input())
d1 = int(input())
d2 = int(input())
d3 = int(input())
d = [d1, d2, d3]
i = d.index(min(d))
if n == 1:
	print(0)
elif i < 1.5:
	print((n - 1) * d[i])
else:
	print((n - 2) * d[2] + min(d[0], d[1]))


x = int(input())
a = int(input())
b = int(input())
c = int(input())
t = min(a, b, c)
if x > 1:
	print(min(a, b) + (x - 2) * min(a, b, c))
else:
	print(0)


d = 0
n = int(input()) - 1
a = int(input())
b = int(input())
c = int(input())
if n != 0:
	d += min([a, b])
	n -= 1
	d += min([a, b, c]) * n
	print(d)
else:
	print(0)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
house = 'rab'
answer = 0
for i in range(n - 1):
	if house == 'rab':
		if a < b:
			house = 'owl'
			answer += a
		else:
			house = 'eey'
			answer += b
	elif house == 'owl':
		if a < c:
			house = 'rab'
			answer += a
		else:
			house = 'eey'
			answer += c
	elif b < c:
		house = 'rab'
		answer += b
	else:
		house = 'owl'
		answer += c
print(answer)


n = int(input())
r_o = int(input())
r_e = int(input())
e_o = int(input())
rahe_rafte = 0
if n >= 2:
	rahe_rafte = min(r_e, r_o)
s = min(min(r_e, r_o), e_o)
for i in range(n - 2):
	rahe_rafte += s
print(rahe_rafte)


ip = lambda : int(input())
n = ip()
a = ip()
b = ip()
c = ip()
k = 0
if n > 1:
	k = min(a, b)
	if n > 2:
		k += min(k, c) * (n - 2)
print(k)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
ef = min(a, b, c)
dist = 0
if ef != c:
	dist += (n - 1) * ef
elif n != 1:
	dist += min(a, b)
	dist += (n - 2) * ef
print(dist)


F = lambda : int(input())
n = F()
a = F()
b = F()
c = F()
if n == 1:
	print(0)
elif min(a, b, c) == a or min(a, b, c) == b:
	print(min(a, b) * (n - 1))
else:
	print(min(a, b) + c * (n - 2))


n = int(input())
a = []
a.append(int(input()))
a.append(int(input()))
a.append(int(input()))
if n == 1:
	print(0)
	exit()
n -= 2
k = min(a[0], a[1])
a = sorted(a[:])
print(k + a[0] * n)


n = int(input())
a = []
b = []
a.append(int(input()))
a.append(int(input()))
a.append(int(input()))
if n > 1:
	res = min(a[0], a[1])
	if n == 1:
		print(res)
	else:
		print(min(a) * (n - 2) + res)
else:
	print(0)


def winnie(n, grove, loc):
	dist = 0
	while n > 1:
		next_loc = min(grove[loc], key=grove[loc].get)
		dist += grove[loc][next_loc]
		loc = next_loc
		n -= 1
	return dist
grove_matrix = {'R': {'E': 0, 'O': 0}, 'E': {'R': 0, 'O': 0}, 'O': {'E': 0, 'R': 0}}
n = int(input())
a = int(input())
b = int(input())
c = int(input())
grove_matrix['R']['E'] = b
grove_matrix['E']['R'] = b
grove_matrix['R']['O'] = a
grove_matrix['O']['R'] = a
grove_matrix['E']['O'] = c
grove_matrix['O']['E'] = c
loc = 'R'
print(winnie(n, grove_matrix, loc))


def moves():
	n = int(input())
	a = int(input())
	b = int(input())
	c = int(input())
	if n == 1:
		return 0
	k = min(a, b)
	if n == 2:
		return k
	return k + min(k, c) * (n - 2)
print(moves())


n = int(input())
a = int(input())
b = int(input())
c = int(input())
if n == 1:
	print('0')
	exit(0)
m = min(a, b, c)
if a == m or b == m:
	print((n - 1) * m)
else:
	print(min(a, b) + (n - 2) * m)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
a = min(a, b)
print((n > 1) * a + (n > 2) * (n - 2) * min(a, c))


n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = [a, b, c]
e = min(d)
f = min(a, b)
if n == 1:
	print(0)
elif n == 2:
	print(f)
else:
	g = f + (n - 2) * e
	print(g)


import math
from random import randint
t = 1
while t > 0:
	t -= 1
	places = []
	n = int(input())
	for _ in range(3):
		places.append(int(input()))
	smallest = min(places)
	n -= 1
	dist = 0
	if places.index(smallest) == 2 and n > 0:
		dist += min(places[:2])
		n -= 1
	if n > 0:
		dist += n * smallest
	print(dist)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
mab = min(a, b)
res = (n - 1) * mab
if n > 1:
	res = min(res, mab + (n - 2) * c)
print(res)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
ans = 0
a = min(a, b)
b = min(a, c)
if n > 1:
	ans += a
	n -= 1
while n > 1:
	n -= 1
	ans += b
print(ans)


import sys
n = int(input())
a = int(input())
b = int(input())
c = int(input())
if n < 2:
	print(0)
	sys.exit()
g = {}
g['R'] = {'O': a, 'E': b}
g['E'] = {'R': b, 'O': c}
g['O'] = {'R': a, 'E': c}
curr = 'R'
dist = 0
n -= 1
while n > 0:
	choices = g[curr]
	curr = min(choices, key=choices.get)
	dist += choices[curr]
	n -= 1
print(dist)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
distance = 0
Pos = 'R'
for i in range(n - 1):
	if Pos == 'R':
		if a < b:
			distance += a
			Pos = 'O'
		else:
			distance += b
			Pos = 'E'
	elif Pos == 'E':
		if b < c:
			distance += b
			Pos = 'R'
		else:
			distance += c
			Pos = 'O'
	elif Pos == 'O':
		if a < c:
			distance += a
			Pos = 'R'
		else:
			distance += c
			Pos = 'E'
print(distance)


visits = int(input())
a = int(input())
b = int(input())
c = int(input())
distances = [a, b, c]
total_distance = 0
if visits > 1:
	if c < a and c < b:
		if a < b:
			total_distance += a
			total_distance += (visits - 2) * c
		else:
			total_distance += b
			total_distance += (visits - 2) * c
	elif a < b:
		total_distance += (visits - 1) * a
	else:
		total_distance += (visits - 1) * b
print(total_distance)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
if n == 1:
	print(0)
else:
	dist = [a, b, c]
	dist.sort()
	min1 = dist[0]
	min2 = dist[1]
	min3 = dist[2]
	if min1 == a or min1 == b:
		print((n - 1) * min1)
	else:
		print(min2 + (n - 2) * min1)


from sys import stdin, stdout
from collections import Counter

def ai():
	return list(map(int, stdin.readline().split()))

def ei():
	return map(int, stdin.readline().split())

def ip():
	return int(stdin.readline().strip())

def op(ans):
	return stdout.write(str(ans) + '\n')
n = ip()
a = ip()
b = ip()
c = ip()
ans = 0
i = 1
current = 'r'
while i != n:
	i += 1
	if current == 'r':
		if a < b:
			current = 'o'
		else:
			current = 'e'
		ans += min(a, b)
	elif current == 'o':
		if c < a:
			current = 'e'
		else:
			current = 'r'
		ans += min(a, c)
	elif current == 'e':
		if b < c:
			current = 'r'
		else:
			current = 'o'
		ans += min(b, c)
op(ans)


n = int(input())
ro = int(input())
re = int(input())
oe = int(input())
house = 0
distance = 0
while n > 1:
	if house == 0:
		if ro < re:
			distance += ro
			house = 1
		else:
			distance += re
			house = 2
	elif house == 1:
		if ro < oe:
			distance += ro
			house = 0
		else:
			distance += oe
			house = 2
	elif house == 2:
		if re < oe:
			distance += re
			house = 0
		else:
			distance += oe
			house = 1
	n -= 1
print(distance)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
n -= 1
i = 0
cont = 0
while True:
	if n == 0:
		break
	n -= 1
	if i == 0:
		if a < b:
			cont += a
			i = 1
		else:
			cont += b
			i = 2
	elif i == 1:
		if a < c:
			cont += a
			i = 0
		else:
			cont += c
			i = 2
	elif i == 2:
		if c < b:
			cont += c
			i = 1
		else:
			cont += b
			i = 0
print(cont)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
my_list = [[101, b, a], [b, 101, c], [a, c, 101]]
pos = 0
dist = 0
while n != 1:
	curr_min = min(my_list[pos][0], my_list[pos][1], my_list[pos][2])
	dist += curr_min
	pos = my_list[pos].index(curr_min)
	n -= 1
print(dist)


N = int(input())
d1 = int(input())
d2 = int(input())
d3 = int(input())
if N == 1:
	print(0)
else:
	AN = min(d1, d2)
	AN += min([d1, d2, d3]) * (N - 2)
	print(AN)


def main():
	N = int(input())
	(A, B, C) = (int(input()) for _ in [0] * 3)
	if N == 1:
		print(0)
		exit()
	min_ = min(A, B, C)
	if A == min_ or B == min_:
		dist = min_
	else:
		dist = min(A, B)
	dist += min_ * (N - 2)
	print(dist)
main()


(n, a, b, c) = (int(input()), int(input()), int(input()), int(input()))
if n == 1:
	print(0)
else:
	first = a if a < b else b
	second = first if first < c else c
	print(first + (n - 2) * second)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
ans = 0
su = n - 1
while su:
	if a < b:
		ans += a
		su -= 1
		if c < a and su:
			ans += c * su
			su = 0
		else:
			ans += a * su
			su = 0
	else:
		ans += b
		su -= 1
		if c < b and su:
			ans += c * su
			su = 0
		else:
			ans += b * su
			su = 0
print(ans)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
state = 0
ans = 0
n -= 1
while n > 0:
	if state == 0:
		if a < b:
			ans += a
			state = 1
		else:
			ans += b
			state = 2
	elif state == 1:
		if a < c:
			ans += a
			state = 0
		else:
			ans += c
			state = 2
	elif b < c:
		ans += b
		state = 0
	else:
		ans += c
		state = 1
	n -= 1
print(ans)


import sys
n = int(input())
a = int(input())
b = int(input())
c = int(input())
if n == 1:
	print(0)
	sys.exit()
if c < a and c < b:
	print(min(a, b) + c * (n - 2))
else:
	print(min(a, b) * (n - 1))


n = int(input())
a = int(input())
b = int(input())
c = int(input())
f = 0
curr = 'a'
ans = 0
n -= 1
while n > 0:
	n -= 1
	if curr == 'a':
		ans += min(a, b)
		if min(a, b) == a:
			curr = 'b'
		else:
			curr = 'c'
	elif curr == 'b':
		ans += min(a, c)
		if min(a, c) == a:
			curr = 'a'
		else:
			curr = 'c'
	elif curr == 'c':
		ans += min(c, b)
		if min(b, c) == c:
			curr = 'b'
		else:
			curr = 'a'
print(ans)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
r = 0
dist = 0
for i in range(n - 1):
	if r == 0:
		if a < b:
			dist += a
			r = 1
		else:
			dist += b
			r = 2
	elif r == 1:
		if a < c:
			dist += a
			r = 0
		else:
			dist += c
			r = 2
	elif r == 2:
		if c < b:
			dist += c
			r = 1
		else:
			dist += b
			r = 0
print(dist)


n = int(input())
ro = int(input())
re = int(input())
oe = int(input())
m = min([ro, re, oe])
if n == 1:
	print(0)
elif m == ro or m == re:
	print((n - 1) * m)
else:
	print(min([ro, re]) + (n - 2) * oe)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
n -= 1
indeed = 0
if min(a, b, c) == a:
	shortestpath = a
elif min(a, b, c) == b:
	shortestpath = b
else:
	indeed = 1
	shortestpath = c
	intermediary = min(a, b)
ans = 0
while n > 0:
	if indeed:
		indeed = 0
		ans += intermediary
	else:
		ans += shortestpath
	n -= 1
print(ans)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
min1 = min(a, min(b, c))
if min1 == a or min1 == b or n == 1:
	print(min(a, b) * (n - 1))
else:
	print(min(a, b) + c * (n - 2))


n = int(input())
a = int(input())
b = int(input())
c = int(input())
if c < a and c < b:
	dis = min(a, b) * min(1, n - 1) + max(0, n - 2) * c
else:
	dis = min(a, b) * (n - 1)
print(dis)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
if n == 1:
	print(0)
	exit()
smallest = min(a, b, c)
if smallest == a:
	print(a * (n - 1))
	exit()
if smallest == b:
	print(b * (n - 1))
	exit()
print(min(a, b) + c * (n - 2))


n = int(input().strip())
a = [0, 0, 0]
a[0] = int(input().strip())
a[1] = int(input().strip())
a[2] = int(input().strip())
ans = 0
if min(a) not in a[:2]:
	ans = min(a[:2]) + max(n - 2, 0) * min(a)
else:
	ans = max(n - 1, 0) * min(a)
if n == 1:
	ans = 0
print(ans)


import sys
import os
import math
import re
n = int(input())
a = int(input())
b = int(input())
c = int(input())
if n == 1:
	print('0')
elif min(min(a, b), c) != c:
	print(min(a, b) * (n - 1))
else:
	print(min(a, b) + c * (n - 2))


import os, sys
from itertools import count, combinations
from collections import namedtuple, Counter
from operator import itemgetter

class CustomException(Exception):
	pass
if os.getenv('SJDEAK'):
	sys.stdin = open(os.path.expanduser('~/data/in.txt'))
mem = {}

def dp(n, pos):
	if n == 0:
		return 0
	if (n, pos) in mem:
		return mem[n, pos]
	if pos == 'A':
		mem[n, pos] = min(A + dp(n - 1, 'B'), B + dp(n - 1, 'C'))
	elif pos == 'B':
		mem[n, pos] = min(A + dp(n - 1, 'A'), C + dp(n - 1, 'C'))
	else:
		mem[n, pos] = min(B + dp(n - 1, 'A'), C + dp(n - 1, 'B'))
	return mem[n, pos]
(N, A, B, C) = [int(input()) for i in range(4)]
print(dp(N - 1, 'A'))


n = int(input())
a = int(input())
b = int(input())
c = int(input())
s = 0
n -= 1
output = 0
while n:
	if s == 0:
		if a < b:
			output += a
			s = 1
		else:
			output += b
			s = 2
	elif s == 1:
		if a < c:
			output += a
			s = 0
		else:
			output += c
			s = 2
	elif b < c:
		output += b
		s = 0
	else:
		output += c
		s = 1
	n -= 1
print(output)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
m = 0
if n > 1:
	m = min(a, b)
s = m
while n > 2:
	s += min(m, c)
	n -= 1
print(s)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
g = [1 if a < b else 2, 0 if a < c else 2, 1 if c < b else 0]
d = [min(a, b), min(a, c), min(c, b)]
t = 0
p = 0
for i in range(n - 1):
	t += d[p]
	p = g[p]
print(t)


(n, ac, ab, bc) = [int(input()) for _ in range(4)]
dist = 0
place = 0
for _ in range(n - 1):
	if place == 0:
		if ac > ab:
			dist += ab
			place = 1
		else:
			dist += ac
			place = 2
	elif place == 1:
		if ab > bc:
			dist += bc
			place = 2
		else:
			dist += ab
			place = 0
	elif ac > bc:
		dist += bc
		place = 1
	else:
		dist += ac
		place = 0
print(dist)


graph = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
n = int(input())
a = int(input())
b = int(input())
c = int(input())
graph[0][1] = a
graph[1][0] = a
graph[0][2] = b
graph[2][0] = b
graph[1][2] = c
graph[2][1] = c
d = 0
c = 0
for _ in range(n - 1):
	fs = 2 if c == 0 else c - 1
	bs = 0 if c == 2 else c + 1
	fd = graph[c][fs]
	bd = graph[c][bs]
	if fd < bd:
		d += fd
		c = fs
	else:
		d += bd
		c = bs
print(d)


n = int(input())
krolik_sova = int(input())
krolik_ia = int(input())
sova_ia = int(input())
count = 0
distance = {'krolik_sova': krolik_sova, 'sova_krolik': krolik_sova, 'krolik_ia': krolik_ia, 'ia_krolik': krolik_ia, 'sova_ia': sova_ia, 'ia_sova': sova_ia}
point = 'krolik'
while n - 1 > 0:
	if point == 'krolik':
		if distance['krolik_sova'] < distance['krolik_ia']:
			count += distance['krolik_sova']
			point = 'sova'
		else:
			count += distance['krolik_ia']
			point = 'ia'
	elif point == 'sova':
		if distance['sova_krolik'] < distance['sova_ia']:
			count += distance['sova_krolik']
			point = 'krolik'
		else:
			count += distance['sova_ia']
			point = 'ia'
	elif point == 'ia':
		if distance['ia_krolik'] < distance['ia_sova']:
			count += distance['ia_krolik']
			point = 'krolik'
		else:
			count += distance['ia_sova']
			point = 'sova'
	n = n - 1
print(count)


read = lambda : tuple(map(int, input().split()))
(n, a, b, c) = (read()[0], read()[0], read()[0], read()[0])
n -= 1
if n == 0:
	print(0)
elif n == 1:
	print(min(a, b))
else:
	print(min(a + c * (n - 1), b + c * (n - 1), b * n, a * n))


n = int(input())
a = int(input())
b = int(input())
c = int(input())
path = 0
h = 1
while n - 1:
	if h == 1:
		if a > b:
			path = path + b
			h = 3
		else:
			path = path + a
			h = 2
	elif h == 2:
		if a > c:
			path = path + c
			h = 3
		else:
			path = path + a
			h = 1
	elif h == 3:
		if c > b:
			path = path + b
			h = 1
		else:
			path = path + c
			h = 2
	n = n - 1
print(path)


import math
import re

def ria():
	return [int(i) for i in input().split()]

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

def rfa():
	return [float(i) for i in input().split()]
n = ria()[0]
a = ria()[0]
b = ria()[0]
c = ria()[0]
n -= 1
if n == 0:
	print(0)
	exit()
print(min(a + c * (n - 1), b + c * (n - 1), a * n, b * n))


n = int(input())
a = int(input())
b = int(input())
c = int(input())
if n == 1:
	print(0)
else:
	mi = min(a, b, c)
	if mi == a:
		dist = a * (n - 1)
	elif mi == b:
		dist = b * (n - 1)
	elif mi == c:
		ma = min(a, b)
		if ma == a:
			dist = a
		else:
			dist = b
		dist = dist + c * (n - 2)
	print(dist)


def main():
	n = int(input()) - 1
	a = int(input())
	b = int(input())
	c = int(input())
	d = min(a, min(b, c))
	if d == a:
		print(n * d)
	elif d == b:
		print(n * d)
	elif n >= 1:
		print((n - 1) * d + min(a, b))
	else:
		print(0)
main()


import copy

def solve():
	(n, a, b, c) = [int(input()) for i in range(4)]
	nowloc = 'ab'
	mealed = 1
	totaldistance = 0
	history = ['ab']
	while mealed < n:
		if nowloc == 'ab':
			if a < b:
				nowloc = 'ac'
				totaldistance += a
			else:
				nowloc = 'bc'
				totaldistance += b
		elif nowloc == 'bc':
			if b < c:
				nowloc = 'ab'
				totaldistance += b
			else:
				nowloc = 'ac'
				totaldistance += c
		elif nowloc == 'ac':
			if a < c:
				nowloc = 'ab'
				totaldistance += a
			else:
				nowloc = 'bc'
				totaldistance += c
		history.append(copy.deepcopy(nowloc))
		mealed += 1
	return (totaldistance, history)
print(solve()[0])


n = int(input())
atob = int(input())
atoc = int(input())
btoc = int(input())
btoa = atob
ctoa = atoc
ctob = btoc
if atob > atoc:
	pos1 = 'c'
	dis1 = atoc
else:
	pos1 = 'b'
	dis1 = atob
if btoc > btoa:
	pos2 = 'a'
	dis2 = btoa
else:
	pos2 = 'c'
	dis2 = btoc
if ctoa > ctob:
	pos3 = 'b'
	dis3 = ctob
else:
	pos3 = 'a'
	dis3 = ctoa
position = 'a'
distance = 0

def dist(pos, dtravelled):
	if pos == 'a':
		pos = pos1
		dtravelled += dis1
	elif pos == 'b':
		pos = pos2
		dtravelled += dis2
	elif pos == 'c':
		pos = pos3
		dtravelled += dis3
	return (pos, dtravelled)
for i in range(n - 1):
	(position, distance) = dist(position, distance)
print(distance)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
path = min(a, b)
short = min(a, b, c)
res = path
if n > 2:
	res += (n - 2) * short
if n == 1:
	res = 0
print(res)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
x = 0
if n > 1:
	x = min(a, b)
	if n > 2:
		x += min(x, c) * (n - 2)
print(x)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
if n == 1:
	print(0)
	exit(0)
if min(a, b, c) == min(a, b):
	print(min(a, b) * (n - 1))
else:
	print(min(a, b) + c * max(0, n - 2))


from sys import stdin
(n, a, b, c) = map(int, stdin.read().split())
if n == 1:
	result = 0
elif n == 2:
	result = min(a, b)
elif min(a, b, c) == a:
	result = (n - 1) * a
elif min(a, b, c) == b:
	result = (n - 1) * b
else:
	result = min(a, b) + (n - 2) * c
from sys import stdout
print(result, file=stdout)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
ans = min(a, b)
m = min(ans, c)
if n == 1:
	print(0)
else:
	while n > 2:
		n -= 1
		ans += m
	print(ans)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 15
mod = 10 ** 9 + 7

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 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 main():
	n = I()
	a = [I() for _ in range(3)]
	r = 0
	if n == 1:
		return 0
	r += min(a[0], a[1])
	if n > 1:
		r += min(a) * (n - 2)
	return r
print(main())


import sys

def main():
	n = int(sys.stdin.readline().rstrip())
	a = int(sys.stdin.readline().rstrip())
	b = int(sys.stdin.readline().rstrip())
	c = int(sys.stdin.readline().rstrip())
	state = 0
	dist = 0
	for i in range(1, n):
		if state == 0:
			if a < b:
				dist += a
				state = 1
			else:
				dist += b
				state = 2
		elif state == 1:
			if a < c:
				dist += a
				state = 0
			else:
				dist += c
				state = 2
		elif state == 2:
			if b < c:
				dist += b
				state = 0
			else:
				dist += c
				state = 1
	return dist
print(main())


n = int(input()) - 1
a = int(input())
b = int(input())
c = int(input())
answ = 0
if n > 0 and c < a and (c < b):
	answ += min(a, b)
	n -= 1
if n > 0:
	answ += min(a, b, c) * n
print(answ)


I = lambda : int(input())
n = I()
d = [I(), I(), I()]
if n == 1:
	print(0)
else:
	print(min(d[:2]) + (n - 2) * min(d))


from math import *
n = int(input())
a = int(input())
b = int(input())
c = int(input())
t = 0
ans = 0
for i in range(1, n):
	if t == 0:
		if a < b:
			t = 1
			ans += a
		else:
			t = 2
			ans += b
	elif t == 1:
		if a < c:
			t = 0
			ans += a
		else:
			t = 2
			ans += c
	elif t == 2:
		if b < c:
			t = 0
			ans += b
		else:
			t = 1
			ans += c
print(ans)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
x = 0
n = n - 1
m = min(a, b)
ms = min(m, c)
if n > 0:
	x += m
	n = n - 1
while n > 0:
	x += ms
	n = n - 1
print(x)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
s = 0
t = 1
for i in range(n - 1):
	if t == 1:
		if a < b:
			s += a
			t = 2
			continue
		else:
			s += b
			t = 3
			continue
	if t == 2:
		if a < c:
			s += a
			t = 1
			continue
		else:
			s += c
			t = 3
			continue
	if t == 3:
		if c < b:
			s += c
			t = 2
			continue
		else:
			s += b
			t = 1
			continue
print(s)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
cur = 0
pos = 0
for i in range(n - 1):
	if pos == 0:
		if a < b:
			pos = 1
			cur += a
		else:
			pos = 2
			cur += b
	elif pos == 1:
		if a < c:
			pos = 1
			cur += a
		else:
			pos = 3
			cur += c
	elif b < c:
		pos = 2
		cur += b
	else:
		pos = 3
		cur += c
print(cur)


def f(l, n):
	(a, b, c) = l
	return (n - 2) * c + min(a, b) if n > 2 and min(l) == c else (n - 1) * min(a, b)
n = int(input())
l = [int(input()) for _ in range(3)]
print(f(l, n))


n = int(input())
a = int(input())
b = int(input())
c = int(input())
if n == 1:
	print('0')
	exit()
elif n == 2:
	print(min(a, b))
	exit()
else:
	ans = min(a, b)
	mini = min(a, b, c)
	ans += mini * (n - 2)
	print(ans)
	exit()


n = int(input())
p = int(input())
l = int(input())
g = int(input())
if n == 1:
	print('0')
elif min(p, l, g) == p:
	print((n - 1) * p)
elif min(p, l, g) == l:
	print((n - 1) * l)
else:
	tad = min(p, l)
	lap = (n - 2) * g
	print(tad + lap)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
m = min(a, b, c)
if m == a:
	n -= 1
	dist = 0
	if n > 0:
		dist += n * a
	print(dist)
elif m == b:
	n -= 1
	dist = 0
	if n > 0:
		dist += n * b
	print(dist)
else:
	n -= 1
	dist = 0
	if n > 0:
		n -= 1
		dist += min(a, b)
	if n > 0:
		dist += n * c
	print(dist)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
n = n - 1
d = 0
if n != 0:
	minab = min(a, b)
	m = min(minab, c)
	if m == a or m == b:
		d = m * n
	else:
		d = minab + (n - 1) * m
print(d)


from math import ceil
Input = lambda : map(int, input().split())
n = int(input())
(R, E, O) = (int(input()), int(input()), int(input()))
n -= 1
if n == 0:
	print(0)
	exit()
arr = [[R, 'R'], [E, 'E'], [O, 'O']]
arr.sort()
if arr[0][1] == 'O':
	n -= 1
	print(arr[1][0] + arr[0][0] * n)
else:
	print(arr[0][0] * n)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
count = 1
length = 0
x = 1
while count < n:
	count += 1
	if x == 1:
		if a < b:
			x = 2
			length += a
		else:
			x = 3
			length += b
	elif x == 2:
		if a < c:
			x = 1
			length += a
		else:
			x = 3
			length += c
	elif b < c:
		x = 1
		length += b
	else:
		x = 2
		length += c
print(length)


n = int(input()) - 1
a = [int(input()) for i in range(3)]
x = 0
if n > 0 and a[0] <= a[1]:
	if a[2] <= a[0]:
		x = a[0] + a[2] * (n - 1)
	else:
		x = a[0] * n
elif n > 0 and a[1] < a[0]:
	if a[2] <= a[1]:
		x = a[1] + a[2] * (n - 1)
	else:
		x = a[1] * n
print(x)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
if n == 1:
	print(0)
	exit(0)
n -= 1
m = [a, b, c]
m = sorted(m)
phys = 0
if m[0] == c:
	phys = min(a, b)
	n -= 1
	phys += n * c
else:
	phys = n * m[0]
print(phys)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
K = [a, b]
C = [a, c]
O = [b, c]
s = 0
A = K
if n == 1:
	print(0)
elif n > 1:
	while n - 1 > 0:
		if A == K:
			if A[0] > A[1]:
				s += A[1]
				A = O
			else:
				s += A[0]
				A = C
			n -= 1
		elif A == O:
			if A[0] > A[1]:
				s += A[1]
				A = C
			else:
				s += A[0]
				A = K
			n -= 1
		elif A == C:
			if A[0] > A[1]:
				s += A[1]
				A = O
			else:
				s += A[0]
				A = K
			n -= 1
	if n - 1 == 0:
		print(s)


import random
import os
import sys
n = int(input())
a = int(input())
b = int(input())
c = int(input())
if a <= b and a <= c:
	print(a * (n - 1))
elif b <= a and b <= c:
	print(b * (n - 1))
elif n > 1:
	if a < b:
		print(a + c * (n - 2))
	else:
		print(b + c * (n - 2))
else:
	print(0)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
li = [a, b, c]
li.sort()
if n == 1:
	print('0')
elif a <= b:
	if a <= c:
		print(str((n - 1) * a))
	else:
		print(str((n - 2) * c + a))
elif b <= c:
	print(str((n - 1) * b))
else:
	print(str((n - 2) * c + b))


n = int(input())
a = int(input())
b = int(input())
c = int(input())
sum = 0
while n > 1:
	n -= 1
	sum += min(a, b)
	if min(a, b) == a:
		b = c
	else:
		a = c
print(sum)


n = int(input())
nums = []
for i in range(3):
	a = int(input())
	nums.append(a)
if n == 1:
	print(0)
	exit()
if n == 2:
	print(min(nums[0], nums[1]))
	exit()
ans = min(nums[0], nums[1])
n = n - 2
ans = ans + min(nums) * n
print(ans)


n = int(input())
dist = []
dist.append(int(input()))
dist.append(int(input()))
dist.append(int(input()))
dist2 = sorted(dist)
if n == 1:
	print(0)
elif dist2[0] == dist[0]:
	print((n - 1) * dist[0])
elif dist2[0] == dist[1]:
	print((n - 1) * dist[1])
elif dist2[1] == dist[0]:
	print(dist[0] + (n - 2) * dist[2])
else:
	print(dist[1] + (n - 2) * dist[2])


def main():
	n = int(input()) - 1
	[d01, d02, d12] = [int(input()) for _ in range(3)]
	min_distance = min(d01, d02, d12)
	if min_distance == d01 or min_distance == d02:
		print(min_distance * n)
	else:
		print(d12 * (n - 1) + min(d01, d02) if n > 0 else 0)
main()


n = int(input())
a = int(input())
b = int(input())
c = int(input())
w = 'k'
s = 0
for i in range(n - 1):
	if w == 'k':
		if a >= b:
			s += b
			w = 'o'
		else:
			s += a
			w = 'c'
	elif w == 'c':
		if a >= c:
			s += c
			w = 'o'
		else:
			s += a
			w = 'k'
	elif w == 'o':
		if c >= b:
			s += b
			w = 'k'
		else:
			s += c
			w = 'c'
print(s)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
if n == 1:
	print(0)
	exit(0)
tmp1 = a + min(a, c) * (n - 2)
tmp2 = b + min(b, c) * (n - 2)
print(min(tmp1, tmp2))


n = int(input())
l = []
for i in range(3):
	v = int(input())
	l.append(v)
n = n - 1
d = 0
for i in range(n):
	ans = min(l[0], l[1])
	d += ans
	k = l.index(max(l[0], l[1]))
	(l[-1], l[k]) = (l[k], l[-1])
print(d)


import sys
import math

def minn(x, y, z):
	p = x
	if p > y:
		p = y
	if p > z:
		p = z
	return p
n = sys.stdin.readline()
n = int(n)
a = sys.stdin.readline()
a = int(a)
b = sys.stdin.readline()
b = int(b)
c = sys.stdin.readline()
c = int(c)
d = minn(a, b, c)
if d == a or d == b:
	cost = (n - 1) * d
elif n > 1:
	cost = a
	if cost > b:
		cost = b
	cost += (n - 2) * c
else:
	cost = 0
print(cost)


def main():
	n = int(input()) - 1
	[d01, d02, d12] = [int(input()) for _ in range(3)]
	min_distance = min(d01, d02, d12)
	distances = [[d01, d02], [d12, d01], [d01, d12]]
	sum_distances = 0
	pos = 0
	while n > 0:
		if min(distances[pos]) == min_distance:
			sum_distances += n * min_distance
			n = 0
		else:
			d1 = distances[pos][0]
			d2 = distances[pos][1]
			if d1 < d2:
				sum_distances += d1
				pos += 1
			else:
				sum_distances += d2
				pos += 2
			pos %= 3
			n -= 1
	print(sum_distances)
main()


n = int(input()) - 1
a = int(input())
b = int(input())
c = int(input())
d = 0
house = 'r'
while n != 0:
	if house == 'r':
		if a > b:
			d += b
			house = 'e'
		else:
			d += a
			house = 'o'
	elif house == 'o':
		if a > c:
			d += c
			house = 'e'
		else:
			d += a
			house = 'r'
	elif house == 'e':
		if c > b:
			d += b
			house = 'r'
		else:
			d += c
			house = 'o'
	n -= 1
print(d)


visits_nr = int(input())
ro_dist = int(input())
rd_dist = int(input())
od_dist = int(input())
pref_end_r___min_dist = [0] * visits_nr
pref_end_o___min_dist = [10 ** 9] * visits_nr
pref_end_d___min_dist = [10 ** 9] * visits_nr
for visit in range(1, visits_nr):
	pref_end_r___min_dist[visit] = min(pref_end_o___min_dist[visit - 1] + ro_dist, pref_end_d___min_dist[visit - 1] + rd_dist)
	pref_end_o___min_dist[visit] = min(pref_end_r___min_dist[visit - 1] + ro_dist, pref_end_d___min_dist[visit - 1] + od_dist)
	pref_end_d___min_dist[visit] = min(pref_end_o___min_dist[visit - 1] + od_dist, pref_end_r___min_dist[visit - 1] + rd_dist)
ans = min((pref_end_d___min_dist[-1], pref_end_o___min_dist[-1], pref_end_r___min_dist[-1]))
print(ans)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
score = 0
r = True
o = False
e = False
for i in range(n - 1):
	if r is True:
		if a > b:
			score += b
			e = True
			r = False
		else:
			score += a
			o = True
			r = False
	elif o is True:
		if a > c:
			score += c
			e = True
			o = False
		else:
			score += a
			r = True
			o = False
	elif e is True:
		if b > c:
			score += c
			o = True
			e = False
		else:
			score += b
			r = True
			e = False
print(score)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
if n == 1:
	print('0')
l = list([a, b, c])
l.sort()
if n == 2:
	print(min(a, b))
if n > 3:
	x = min(a, b)
	y = min(x, c)
	print(x + y + (n - 3) * y)
if n == 3:
	x = min(a, b)
	y = min(x, c)
	print(x + y)


n = int(input())
dist = dict(a=int(input()), b=int(input()), c=int(input()))
minpath = min(dist, key=dist.get)
if n == 1:
	print(0)
elif minpath in ('a', 'b'):
	print(dist[minpath] * (n - 1))
else:
	print(min(dist['a'], dist['b']) + dist[minpath] * (n - 2))


n = int(input())
a = int(input())
b = int(input())
c = int(input())
mi = min(a, b, c)
ma = max(a, b, c)
if n == 1:
	print(0)
elif mi == a or mi == b:
	print((n - 1) * mi)
else:
	print(a + b + c - mi - ma + (n - 2) * mi)


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

def main():
	n = int(input())
	a = int(input())
	b = int(input())
	c = int(input())
	ans = 0
	if a == min(a, b, c):
		ans = (n - 1) * a
	elif b == min(a, b, c):
		ans = (n - 1) * b
	elif n > 1:
		ans = (n - 2) * c + min(a, b)
	print(ans)
main()


n = int(input())
dist = [int(input()) for _ in range(3)]
print(min(dist[:2]) + min(dist) * (n - 2) if n > 1 else 0)


r = lambda : int(input())
n = r()
r_o = r()
r_e = r()
o_e = r()
m = min(r_o, r_e, o_e)
total = 0
total += min(r_o, r_e) if n > 1 else 0
total += (n - 2) * m if n > 2 else 0
print(total)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
n -= 1
t = 0
if n > 0:
	t += min([a, b])
	n -= 1
t += min([a, b, c]) * n
print(t)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
n -= 1
r = 0
current = 0
for _ in range(n):
	if current == 0:
		if a < b:
			current = 1
			r += a
		else:
			current = 2
			r += b
	elif current == 1:
		if a < c:
			current = 0
			r += a
		else:
			current = 2
			r += c
	elif b < c:
		current = 0
		r += b
	else:
		current = 1
		r += c
print(r)


n = int(input())
e = int(input())
o = int(input())
r = int(input())
meal = 1
way = 0
pos = 'R'
dic = {'R': [o, e], 'E': [o, r], 'O': [e, r]}
while meal < n:
	way += min(dic[pos])
	if min(dic[pos]) == e:
		if pos == 'R':
			pos = 'O'
		else:
			pos = 'R'
	elif min(dic[pos]) == o:
		if pos == 'R':
			pos = 'E'
		else:
			pos = 'R'
	elif pos == 'O':
		pos = 'E'
	else:
		pos = 'O'
	meal += 1
print(way)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
(s, dist) = ('R', 0)
while n > 1:
	if s == 'R':
		if a <= b:
			dist += a
			s = 'O'
		else:
			dist += b
			s = 'E'
	elif s == 'E':
		if b <= c:
			dist += b
			s = 'R'
		else:
			dist += c
			s = 'O'
	elif s == 'O':
		if c <= a:
			dist += c
			s = 'E'
		else:
			dist += a
			s = 'R'
	n -= 1
print(dist)


import sys
import collections
import math
input = sys.stdin.readline

def printnl(val):
	sys.stdout.write(str(val) + '\n')
n = int(input())
(a, b, c) = [int(input()) for i in range(3)]
dist = 'a'
n -= 1
ans = 0
while n:
	if dist == 'a':
		if a < b:
			ans += a
			dist = 'b'
		else:
			ans += b
			dist = 'c'
	elif dist == 'b':
		if a < c:
			ans += a
			dist = 'a'
		else:
			ans += c
			dist = 'c'
	elif dist == 'c':
		if c < b:
			ans += c
			dist = 'b'
		else:
			ans += b
			dist = 'a'
	n -= 1
print(ans)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
short = min((a, b, c))
ans = 0
if n == 1:
	print(0)
else:
	if a == short or b == short:
		ans = min(a, b) * (n - 1)
	else:
		ans = min(a, b) + c * (n - 2)
	print(ans)


num_visits = int(input().strip())
lengths = {}
lengths['a', 'b'] = int(input().strip())
lengths['a', 'c'] = int(input().strip())
lengths['b', 'c'] = int(input().strip())
target = {}
target['a'] = (('a', 'b'), 'b') if lengths['a', 'b'] < lengths['a', 'c'] else (('a', 'c'), 'c')
target['b'] = (('b', 'c'), 'c') if lengths['b', 'c'] < lengths['a', 'b'] else (('a', 'b'), 'a')
target['c'] = (('a', 'c'), 'a') if lengths['a', 'c'] < lengths['b', 'c'] else (('b', 'c'), 'b')
pos = 'a'
times = 0
dist = 0
while times + 1 < num_visits:
	dist += lengths[target[pos][0]]
	pos = target[pos][1]
	times += 1
print(dist)


n = int(input())
rabbit_owl = int(input())
rabbit_donkey = int(input())
owl_donkey = int(input())
cur = 'r'
answer = 0
for _ in range(n - 1):
	if cur == 'r':
		if rabbit_donkey > rabbit_owl:
			cur = 'o'
			answer += rabbit_owl
		else:
			cur = 'd'
			answer += rabbit_donkey
	elif cur == 'o':
		if rabbit_owl < owl_donkey:
			cur = 'o'
			answer += rabbit_owl
		else:
			cur = 'd'
			answer += owl_donkey
	elif rabbit_donkey < owl_donkey:
		cur = 'r'
		answer += rabbit_donkey
	else:
		cur = 'o'
		answer += owl_donkey
print(answer)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
summ = 0
sec = str()
if n == 1:
	print(0)
else:
	sec = 'kr'
	for i in range(n - 1):
		if sec == 'kr':
			summ += min(b, a)
			if min(b, a) == b:
				sec = 'ia'
			else:
				sec = 'sov'
		elif sec == 'sov':
			summ += min(a, c)
			if min(a, c) == c:
				sec = 'ia'
			else:
				sec = 'kr'
		else:
			summ += min(b, c)
			if min(b, c) == b:
				sec = 'kr'
			else:
				sec = 'sov'
	print(summ)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
now = 'R'
dic = {'R': 0, 'O': 1, 'E': 2}
d = [[1000] * 3 for i in range(3)]
(d[dic['R']][dic['O']], d[dic['O']][dic['R']]) = (a, a)
(d[dic['R']][dic['E']], d[dic['E']][dic['R']]) = (b, b)
(d[dic['O']][dic['E']], d[dic['E']][dic['O']]) = (c, c)
cost = 0
for i in range(n - 1):
	rec = 1001
	index = 0
	for (p, q) in enumerate(d[dic[now]]):
		if rec > q:
			rec = q
			index = p
	cost += rec
	if index == 0:
		now = 'R'
	elif index == 1:
		now = 'O'
	else:
		now = 'E'
print(cost)


def food(n, a, b, c):
	if n == 1:
		return 0
	result = 0
	n -= 1
	if a > b:
		result += b
		n -= 1
		if b > c and n > 0:
			result += n * c
		else:
			result += n * b
	else:
		result += a
		n -= 1
		if a > c and n > 0:
			result += n * c
		else:
			result += n * a
	return result
N = int(input())
A = int(input())
B = int(input())
C = int(input())
print(food(N, A, B, C))


import sys
(n, a, b, c) = [int(z) for z in sys.stdin.read().split()]
if n < 2:
	print(0)
else:
	print(min(a, b) + (n - 2) * min(a, b, c))


n = int(input())
a = int(input())
b = int(input())
c = int(input())
first_min = min(a, b)
second_min = min(a, b, c)
if n == 1:
	print(0)
else:
	print(first_min + second_min * (n - 2))


n = int(input())
a = int(input())
b = int(input())
c = int(input())
s = 0
point = 'k'
n -= 1
while n > 0:
	if point == 'k':
		if a >= b:
			s += b
			point = 'o'
			n -= 1
			continue
		else:
			s += a
			point = 's'
			n -= 1
			continue
	if point == 's':
		if a >= c:
			s += c
			point = 'o'
			n -= 1
			continue
		else:
			s += a
			point = 'k'
			n -= 1
			continue
	if point == 'o':
		if b >= c:
			s += c
			point = 's'
			n -= 1
			continue
		else:
			s += b
			point = 'k'
			n -= 1
			continue
print(s)


(n, a, b, c) = map(int, ''.join([*open(0)]).split())
a = min(a, b)
print((n > 1) * a + (n > 2) * (n - 2) * min(a, c))


(n, ro, re, oe) = (int(input()), int(input()), int(input()), int(input()))
(d, a, c, b) = ({0: ro, 1: re, 2: oe}, [ro, re, oe], 0, [0, 1])
for i in range(n - 1):
	if d[b[0]] >= d[b[1]]:
		c += d[b[1]]
		b.append(3 - sum(b))
		b.remove(b[0])
	else:
		c += d[b[0]]
		b.append(3 - sum(b))
		b.remove(b[1])
print(c)


N = int(input())
N -= 1
A = int(input())
B = int(input())
C = int(input())
print(min(N * A, N * B, min(A, B) + C * (N - 1)) if N != 0 else 0)


n = int(input())
a = []
for i in range(3):
	a.append(int(input()))
if min(a) == a[2]:
	if n != 1:
		print(min(a[1], a[0]) + a[2] * (n - 2))
	else:
		print(0)
else:
	print(min(a) * (n - 1))


d = {}
n = int(input())
ab = int(input())
ac = int(input())
bc = int(input())
d[1] = [[2, ab], [3, ac]]
d[2] = [[1, ab], [3, bc]]
d[3] = [[2, bc], [1, ac]]
ans = 0
k = 1
x = 1
while k < n:
	ans += min(d[x][0][1], d[x][1][1])
	if d[x][0][1] < d[x][1][1]:
		x = d[x][0][0]
	else:
		x = d[x][1][0]
	k += 1
print(ans)


n = int(input())
ro = int(input())
re = int(input())
oe = int(input())
remaining = n - 1
ans = 0
if remaining == 0:
	ans = 0
elif remaining == 1:
	ans = min(ro, re)
else:
	opt = min(ro, re)
	ans += opt
	remaining -= 1
	opt = min(opt, oe)
	ans += opt * remaining
print(ans)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
S = min(a, b)
if n == 1:
	print(0)
elif n > 1 and a > c and (b > c):
	print(S + c * (n - 2))
elif n > 1 and (a < c or b < c):
	print(S * (n - 1))
elif a == b == c:
	print(a * (n - 1))


def main():
	n = int(input())
	a = int(input())
	b = int(input())
	c = int(input())
	adj = [[0, a, b], [a, 0, c], [b, c, 0]]
	ans = 0
	pos = 0
	for _ in range(n - 1):
		dst = -1
		for j in range(3):
			if j == pos:
				continue
			if dst == -1 or adj[pos][j] < adj[pos][dst]:
				dst = j
		ans += adj[pos][dst]
		pos = dst
	print(ans)
main()


visits = int(input())
rabOwl = int(input())
rabEe = int(input())
owlEe = int(input())
minimumEdge = min(rabOwl, rabEe, owlEe)
if visits == 1:
	print(0)
elif rabOwl == minimumEdge:
	print((visits - 1) * rabOwl)
elif rabEe == minimumEdge:
	print((visits - 1) * rabEe)
elif owlEe == minimumEdge:
	print((visits - 2) * owlEe + min(rabOwl, rabEe))


def main():
	(n, a, b, c) = (int(input()), int(input()), int(input()), int(input()))
	if n == 1:
		return 0
	n -= 1
	count = 0
	state = 0
	while n:
		if state == 0:
			if a > b:
				count += b
				state = 2
			else:
				count += a
				state = 1
		elif state == 1:
			if a > c:
				count += c
				state = 2
			else:
				count += a
				state = 0
		elif b > c:
			count += c
			state = 1
		else:
			count += b
			state = 0
		n -= 1
	return count
print(main())


n = int(input()) - 1
a = int(input())
b = int(input())
c = int(input())
result = 0
cur = 'k'
while n > 0:
	if cur == 'k':
		if a < b:
			cur = 's'
			result += a
		else:
			cur = 'i'
			result += b
	elif cur == 's':
		if a < c:
			cur = 'k'
			result += a
		else:
			cur = 'i'
			result += c
	elif b < c:
		cur = 'k'
		result += b
	else:
		cur = 's'
		result += c
	n -= 1
print(result)


n = int(input())
ro = int(input())
re = int(input())
oe = int(input())
count = 1
temp = 1
sum = 0
while count < n:
	if temp == 1:
		if ro < re:
			temp = 2
			sum = sum + ro
		else:
			temp = 3
			sum = sum + re
	elif temp == 2:
		if ro < oe:
			temp = 1
			sum = sum + ro
		else:
			temp = 3
			sum = sum + oe
	elif temp == 3:
		if re < oe:
			temp = 1
			sum = sum + re
		else:
			temp = 2
			sum = sum + oe
	count = count + 1
print(sum)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
k = 1
ab = min(a, b)
bc = min(b, c)
ca = min(c, a)
acc = 0
while n > 1:
	if k == 1:
		acc += ab
		if ab == a:
			k = 2
		else:
			k = 3
	elif k == 2:
		acc += ca
		if ca == c:
			k = 3
		else:
			k = 1
	else:
		acc += bc
		if bc == c:
			k = 2
		else:
			k = 1
	n -= 1
print(acc)


v = int(input()) - 1
ro = int(input())
re = int(input())
oe = int(input())
l = [ro, re, oe]
l.sort()
t = 0
if v >= 1 and (ro == l[-1] or re == l[-1]):
	t += min(ro, re)
	v -= 1
t += l[0] * v
print(t)


import math

def solve(n, a, b, c):
	n = n - 1
	if n == 0:
		return 0
	arr = sorted([a, b, c])
	min_val = arr[0]
	second_min_val = arr[1]
	if min_val == a or min_val == b:
		return min_val * n
	else:
		return min_val * (n - 1) + second_min_val

def main():
	arr = []
	for _ in range(4):
		arr.append(int(input()))
	print(solve(*arr))
main()


(n, a, b, c) = map(int, [input() for i in range(4)])
(s, ans) = (1, 0)
for _ in range(n - 1):
	if s == 1:
		(s, ans) = (2, ans + a) if a < b else (3, ans + b)
	elif s == 2:
		(s, ans) = (1, ans + a) if a < c else (3, ans + c)
	else:
		(s, ans) = (1, ans + b) if b < c else (2, ans + c)
print(ans)


import sys
N = int(sys.stdin.readline())
A = int(sys.stdin.readline())
B = int(sys.stdin.readline())
C = int(sys.stdin.readline())
R = 'R'
O = 'O'
E = 'E'
p = 'R'
ans = 0
for _ in range(N - 1):
	if p == R:
		if A < B:
			ans += A
			p = O
		else:
			ans += B
			p = E
	elif p == E:
		if B < C:
			ans += B
			p = R
		else:
			ans += C
			p = O
	elif C < A:
		ans += C
		p = E
	else:
		ans += A
		p = R
print(ans)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
ans1 = 9999999
ans2 = 9999999
ans1 = min(a * (n - 1), b * (n - 1))
if n >= 2:
	ans2 = min(a, b) + c * (n - 2)
print(min(ans1, ans2))