Language: C++

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <map>
#include <algorithm>  // std::unique
#include <cmath>
#include <limits.h>
#include <queue>
#include <unordered_map>
#include <sstream>      // std::ostringstream
#include <bitset>
#include <iomanip>
#include <functional>
#include <set>


#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;

using ll = long long;
constexpr auto PrimeBigNum10_9_7 = 1000000007;
const long long INF = 1LL << 60;

#define OUTPUT_DEBUG_LOG

template <typename T>
void DisplayAnswer(const T& v) {
	cout << v << endl;
}
template <typename T>
void DisplayAnswers(const vector<T>& vs) {
	for (const auto& v : vs) {
		cout << v << endl;
	}
}

template <typename T>
void DisplayAnswerOneLine(const vector<T>& vs) {
	for (const auto& v : vs) {
		cout << v << ' ';
	}
	cout << endl;
}


std::vector<std::string> split(const std::string &str, char sep)
{
	std::vector<std::string> v;
	std::stringstream ss(str);
	std::string buffer;
	while (std::getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}



template<class T>
void chmin(T& a, T b) {
	if (a > b) {
		a = b;
	}
}


// 素数判定
template <typename T>
bool IsPrimeNumber(T value) {

	for (int i = 2; i * i <= value; ++i) {
		if ((value % i) == 0) {
			return true;
		}
	}
	return false;
}

// 桁数判定
template <typename T>
T GetFigureLength(T value) {
	T figure = 1;
	while (value >= 10) {
		value /= 10;
		++figure;
	}
	return figure;
}

// 素因数分解結果
template <typename T>
map<T, T> GetPrimeFactorize(T value) {

	map<T, T> res;

	for (T i = 2; i * i <= value; ++i) {
		if ((value%i) != 0)	continue;

		T count = 0;
		while ((value % i) == 0) {
			value /= i;
			++count;
		}

		res[i] = count;
	}

	if (value != 1) {
		res[value] = 1;
	}
	return res;
}


void DebugPrint(const vector<ll>& vec) {
	cout << "{";
	for (auto itr = vec.begin(); itr != vec.end(); ++itr) {
		cout << *itr << ",";
	}
	cout << "}" << endl;
}

// valueが2のx乗以下である計算
ll calc2x(ll value) {
	ll n = 0;
	while (value > 0) {
		value /= 2;
		++n;
	}
	return n;
}



struct Vec2 {
	double x;
	double y;

	void rotate(double rad) {
		double s = sin(rad);
		double c = cos(rad);
		double tmpX = this->x*c - this->y*s;
		double tmpY = this->x*s + this->y*c;
		this->x = tmpX;
		this->y = tmpY;
	}
};

void FuncA() {
	ll m;
	cin >> m;

	while (m > 0) {
		m -= 1000;
	}
	DisplayAnswer(-m);
}

void FuncB() {
	unordered_map<string, int> map;

	map["AC"]=0;
	map["WA"] = 0;
	map["TLE"] = 0;
	map["RE"] = 0;

	ll n;
	cin >> n;
	while (n--) {
		string str;
		cin >> str;
		map[str]++;
	}

	cout << "AC x " << map["AC"] << endl;
	cout << "WA x " << map["WA"] << endl;
	cout << "TLE x " << map["TLE"] << endl;
	cout << "RE x " << map["RE"] << endl;
}
namespace C {
	ll map[6][6] = {};
	int calcSum(bitset<6> bh, bitset<6>bw) {
		ll sum = 0;
		for (ll i = 0; i < 6; ++i) {
			if (bh[i] == 0)	continue;
			for (ll j = 0; j < 6; ++j) {
				if (bw[j]) {
					sum += map[i][j];
				}
			}
		}
		return sum;

	}

	int CalcFuncC() {
		ll H, W, K;
		cin >> H >> W >> K;
		ll mapHs[6] = {};

		ll black = 0;
		for (ll i = 0; i < H; ++i) {
			for (ll j = 0; j < W; ++j) {
				char c;
				cin >> c;
				map[i][j] = (c == '#') ? 1 : 0;
				black += map[i][j];
				mapHs[i] += map[i][j];
			}
		}
		ll hMax = 1 << H;
		ll wMax = 1 <<W;

		ll answer = 0;
		for (ll i = 0; i < hMax; ++i) {
			bitset<6> bh = i;
			ll n = 0;
			for (ll k = 0; k < 6; ++k) {
				if (bh[k]) {
					n += mapHs[k];
				}
			}
			if (n < K)	continue;

			for (ll j = 0; j < wMax; ++j) {
				ll sum = calcSum(bh, j);
				if (sum == K) {
					bitset<6> bw = j;
					answer++;
				}
			}
		}

		return answer;

	}
}

void FuncC() {
	DisplayAnswer(C::CalcFuncC());
}

void FuncD() {
	ll N;
	cin >> N;
	vector<ll> players(N);
	for ( ll i = 0; i < N; ++ i ){
		cin >> players[i];
	}
	sort(players.rbegin(), players.rend());

	std::list<int> list;
	list.push_back(players[0]);
	ll sum = 0;
	for (ll i = 1; i < N; ++i) {
		auto front = list.front();
		auto back = list.back();
		if (front < back) {
			sum += front;
			list.push_front(players[i]);
		}
		else {
			sum += back;
			list.push_back(players[i]);
		}

	}

	DisplayAnswer(sum);
}


void FuncE() {
	ll N, K;
	cin >> N >> K;
	vector<pair<ll, ll>> vec;
	while (N--) {
		ll n;
		cin >> n;
		vec.push_back({ abs(n), (n < 0) ? 1 : 0 });
	}

	sort(vec.begin(), vec.end(), [](const auto& lhs, const auto& rhs) { return lhs > rhs; });

	ll ansA = vec[0].first;
	ll codeA = vec[0].second;

	ll ansB = vec[vec.size() - 1].first;
	ll codeB = vec[vec.size() - 1].second;
	for (ll i = 1; i < K; ++i) {
		ansA %= PrimeBigNum10_9_7;
		ansB %= PrimeBigNum10_9_7;

		ansA *= vec[i].first;
		codeA += vec[i].second;

		ansB *= vec[vec.size() - i].first;
		codeB += vec[vec.size() - i].second;
	}

}
int main(void) {

	FuncD();

	return 0;
}


Compiler output:
a.cc: In function 'void FuncD()':
a.cc:254:14: error: 'list' is not a member of 'std'
  254 |         std::list<int> list;
      |              ^~~~
a.cc:20:1: note: 'std::list' is defined in header '<list>'; this is probably fixable by adding '#include <list>'
   19 | #include <math.h>
  +++ |+#include <list>
   20 | using namespace std;
a.cc:254:19: error: expected primary-expression before 'int'
  254 |         std::list<int> list;
      |                   ^~~
a.cc:255:9: error: 'list' was not declared in this scope
  255 |         list.push_back(players[0]);
      |         ^~~~
a.cc:255:9: note: 'std::list' is defined in header '<list>'; this is probably fixable by adding '#include <list>'