Language: C++

#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <random>
#include <string>
#include <bitset>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <typeinfo>

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999

using namespace std;

typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};

llong pow(int x, int n){
    llong ans = x;
    if (n == 0) return 1;

    for(int i = 0; i < n - 1; i++) {
        ans *= x;
    }

    return ans;
}

template <typename T> struct BIT { // 1-indexed
private:
    vector<T> array;
    const int n;

public:
    // 初期化
    BIT(int _n) : array(_n + 1, 0), n(_n) {}

    // 1番目からi番目までの累積和を求める
    T sum(int i) {
        T s = 0;
        while(i > 0) {
            s += array[i];
            i -= i & -i; // LSB減算
        }

        return s;
    }

    // [i, j]の要素の総和
    T sum(int i, int j) {
        T ret_i = sum(i - 1);
        T ret_j = sum(j);

        return ret_j - ret_i;
    }

    // i番目に要素xを追加
    void add(int i, T x) {
        while (i <= n) {
            array[i] += x;
            i += i & -i; // LSB加算
        }
    }
};

template <typename T> struct BIT2 { // 1-indexed
private:
    vector<vector<T> > array;
    const int n;
    const int m;

public:
    // 初期化
    BIT2(int _n, int _m) : array(_n + 1, vector<T>(_m + 1, 0)), n(_n), m(_m) {}

    // (1, 1)から(x, y)までの累積和を求める
    T sum(int x, int y) {
        T s = 0;
        for (int i = x; i > 0; i -= i & (-i)) {
            for (int j = y; j > 0; j -= j & (-j)) {
                s += array[i][j];
            }
        }

        return s;
    }

    // [(x1, y1), (x2, y2)]の要素の総和
    T sum(int x1, int y1, int x2, int y2) {
        return sum(x2, y2) - sum(x1 - 1, y2) - sum(x2, y1 - 1) + sum(x1 - 1, y1 - 1);
    }

    // (x, y)に要素kを追加
    void add(int x, int y, T k) {
        for (int i = x; i <= n; i += i & (-i)) {
            for (int j = y; j <= m; j += j & (-j)) {
                array[i][j] += k;
            }
        }
    }
};

void swap(int *X, int *Y){
    int t = *X; *X = *Y; *Y = t;
}

string toUpper(string s) {
    string t = s;
    REP(i, s.size()) {
        t[i] = toupper(s[i]);
    }
    return t;
}

string toLower(string s) {
    string t = s;
    REP(i, s.size()) {
        t[i] = tolower(s[i]);
    }
    return t;
}

bool isOdd(llong i) {
    if(i % 2) {
        return true;
    } else {
        return false;
    }
}

int vector_finder(std::vector<string > vec, string number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance( vec.begin(), itr );
    if (index != vec.size()) { // 発見できたとき
        return 1;
    }
    else { // 発見できなかったとき
        return 0;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    llong a[100001] = {0};
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    if (n == 2) {
        cout << abs(a[0] - a[1]) << endl;
        return 0;
    }

    sort(a, a + n);
    llong ans = 0;
    if (n == 5) {
        ans = a[4] + a[3] - 2 * a[0] + a[4] - a[1] + a[3] - a[2];
    } else if (n % 2 && (n - 11) % 4 != 0) {
        for (int i = 0; i < n / 2 + 1; ++i) {
            if (i == 0) {
                ans += a[n - 1] + a[n - 1 - 1] - a[0] * 2;
                cout << a[i] << endl;
                //cout << a[n - 1] << " " << a[n - 2] << endl;
                //cout << "-----" << endl;
            } else if (i >= n / 2){
                ans += a[n - i] - a[i];
                cout << a[i] << endl;
            } else {
                ans += a[n - i] - a[i] + a[n - i - 2] - a[i];
                cout << a[i] << endl;
                //cout << a[n - i - 2] << " " << a[n - i] << endl;
                //cout << "-----" << endl;
            }
        }
    }
    } else {
        for (int i = 0; i < n / 2; ++i) {
            if (i == 0) {
                ans += a[n - 1] + a[n - 1 - 1] - a[0] * 2;
                cout << a[i] << endl;
                //cout << a[n - 1] << " " << a[n - 2] << endl;
                //cout << "-----" << endl;
            } else {
                ans += a[n - i] - a[i] + a[n - i - 2] - a[i];
                cout << a[i] << endl;
                //cout << a[n - i - 2] << " " << a[n - i] << endl;
                //cout << "-----" << endl;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Compiler output:
a.cc:199:7: error: expected unqualified-id before 'else'
  199 |     } else {
      |       ^~~~
a.cc:215:5: error: 'cout' does not name a type
  215 |     cout << ans << endl;
      |     ^~~~
a.cc:217:5: error: expected unqualified-id before 'return'
  217 |     return 0;
      |     ^~~~~~
a.cc:218:1: error: expected declaration before '}' token
  218 | }
      | ^