import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] counts = new int[n]; for (int i = 0; i < n; i++) { counts[i] = sc.nextInt(); } Arrays.sort(counts); int idx = n - 1; long ans = 0; for (int i = 0; idx >= 0; i++) { for (int j = 0; j < (1 << i) && idx >= 0; j++) { ans += counts[idx] * i; idx--; } } System.out.println(ans); } }