public void solve() throws IOException {
    int num = nextInt();
    long n = (long) (Math.log(num) / Math.log(4)) + 1;

    long[] arr = new long[num];
    for (int x = 0; x < num; x++)
      arr[x] = nextLong();

    Arrays.sort(arr);

    long beauty = 0;
    int index = 1;
    for (int x = 0; x < num; x++) {
      if (x == index) {
        index *= 4;
        n--;
      }
      beauty += arr[num - x - 1] * n;
    }

    out.println(beauty);
  }