#include<bits/stdc++.h>
using namespace std;
#define int long long
 
int32_t main()
{
  int n;cin>>n;
  vector<int>arr(n);
  for(int i=0;i<n;i++)
    cin>>arr[i];
    sort(arr.begin(),arr.end());
  vector<int>pref(n+1,0);
  for(int i=1;i<=n;i++)
    pref[i]=pref[i-1]+arr[i-1];
  
  int ans=0;
  for(int i=1;i<=n;i++)
  {
    ans+=pref[n]-pref[i]-(n-i)*arr[i-1];
  }
  cout<<ans<<endl;
}
#include<bits/stdc++.h>
using namespace std;
 
#define endl "\n"
#define int long long int
#define ll long long
#define F first
#define S second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define mll unordered_map<ll,ll>
#define dec(v) sort(v.rbegin(),v.rend());
#define REP(i, n) for (int i = 0; i < (n); i++)
#define in(v) for(auto &i:v) cin>>i;
#define out(v) for(auto i:v) cout<<i<<" ";
#define nl cout<<endl;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<ll> vll;
 
#define deb(x) cout << ">" << #x << '=' << x << endl;
#define setbits(n) __builtin_popcountll(n)
#define done {cout<<"-1"<<endl; return;}
 
#define inf INT_MAX
#define ninf INT_MIN
const ll N = 2e5 + 10;
#define mod 1000000007

vector<int> adj[N];
vector<int> vis(N+1);
int c;

void dfs(int n){
  vis[n]=1;
  c++;
  for(auto i:adj[n]){
    if(!vis[i]){
      dfs(i);
    }
  }
}


void solveit(){
  int n;
  cin>>n;
  vi v(n);
  in(v);
  vpii edg;
  for(int i=0;i<n/2;i++){
    if(v[i]!=v[n-i-1]){
      adj[v[i]].pb(v[n-i-1]);
      adj[v[n-i-1]].pb(v[i]);
    }
  }
  int ans=0;
  for(int i=0;i<=2e5;i++){
    if(!vis[i]){
      c=0;
      dfs(i);
      ans+=c-1;
    }
  }
  cout<<ans<<endl;

}
 
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int testcases =1;
  //cin >> testcases;
  while (testcases--)  solveit();
  cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
  return 0;
}