#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include"atcoder/all" #include"atcoder/modint" using namespace std; using namespace atcoder; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T &a, T b) { return ((a>b) ? (a = b, true) : (false));} #define rep(i,s,n) for(long long i=s;i<(long long)(n);i++) #define rrep(i,s,n) for(long long i=n-1;i>=s;i--) const long long inf = 1LL<<60; typedef long long ll; typedef long double ld; typedef unsigned long long ull; //pairのsecondでソートsort(p.begin(),p.end(),cmp) #define cmp [](pair a, pair b){return a.second P; typedef pair > PP; #define rll ll,vector,greater #define rP P,vector

,greater

const long double pi = 3.14159265358979; typedef unsigned long long ull; #define vll vector #define vvll vector> #define vmint vector #define vvmint vector> #define vvch vector> #define vch vector #define vstring vector #define rPP PP,vector,greater #define vP vector

#define vvP vector> #define vPP vector #define all(x) x.begin(), x.end() //UNIQUE(x) xをソートして値の被りがないようにする #define UNIQUE(x) sort(all(x)), x.erase(unique(all(x)), x.end()) int stringcount(string s, char c) { return count(s.cbegin(), s.cend(), c); } //sに含まれるcの数 int pc(int x) { return __builtin_popcount(x); } //ビット列にどれだけ1がたっているかを求める pop count //オバフロしない計算はa > inf - b および a > inf / bでとってね using mint = modint998244353; int main() { int n; cin >> n; vll a(n); rep(i,0,n) cin >> a[i]; sort(all(a)); int turn = 0; ll ans = 0; int powm1[202020]; powm1[0] = 1; rep(i,1,202020) powm1[i] = powm1[i-1] * (-1); int l = 0, r = n-1; while(r - l >= 0) { if(turn == 0) { ans += a[r]; r--; } else { ans += a[l]; l++; } } cout << ans << endl; }