import java.util.*;
public class Main
{
public static void main(String[] args) {
int arr[] = { 4, 6, 8 };
System.out.println(solve(arr));
}
private static int solve(int[] arr){
PriorityQueue<Integer> pq = new PriorityQueue<>();
for(int a : arr)
pq.add(a);
int cost = 0;
while(pq.size() >= 2){
int x = pq.remove();
int y = pq.remove();
cost += x+y;
pq.add(x+y);
}
return cost;
}
}