stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<iostream>

#include<set>

#include<cstring>



using namespace std;



int arr[200005];



int main()

{

    int n, a;

    while(cin >> n) {

        memset(arr, 0, sizeof(arr));

        n--;

        for(int i = 0; i < n; i++) {

            cin >> a;

            arr[a]++;

        }

        for(int i = 1; i <= n+1; i++)

            cout << arr[i] << endl;

    }

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.804152200720943x):
#include<bits/stdc++.h>

using namespace std;

int main()

{

    long long num;

    while(cin>>num)

    {

        long long arr[num+5],count[num+5]={0};

        for(long long i=0;i<num-1;i++)

        {

            cin>>arr[i];

            count[arr[i]]++;

        }

        for(long long i=1;i<=num;i++)

        {

            cout<<count[i]<<endl;

        }

      break;

    }

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



#define rep(i, n) for (int i = 0; i < n; i++)

#define repr(i, n) for (int i = n-1; i >= 0; i--)

#define ALL(x) x.begin(),x.end()



using ll = long long;

using pii = pair<int, int>;

using vi = vector<int>;



const int mod = 1e9+7;

const ll INF = 1e18;

const int MAX = 2e6;



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



struct edge {int to, cost;}; // 辺

// vector<edge> graph[MAX]; // 隣接リスト

// bool visit[MAX]; // 訪問状況



int n, m; // 変数

int sub[MAX];



int main() {

// input

    cin >> n;

    memset(sub, 0, sizeof(sub));

    rep(i, n+1) {

        int boss;

        if (i > 1) {

            cin >> boss;

            sub[boss]++;

        }

    }

// solve

// output

    rep(i, n+1) {

        if (i > 0) cout << sub[i] << "\n";

    }

}

// Faster C++ solution for the same problem (measured speedup: 9.38976601219149x):
#include <bits/stdc++.h>

using namespace std;



#define rep(i, n) for (int i = 0; i < n; i++)

#define repr(i, n) for (int i = n-1; i >= 0; i--)

#define ALL(x) x.begin(),x.end()



using ll = long long;

using pii = pair<int, int>;

using vi = vector<int>;



const int mod = 1e9+7;

const ll INF = 1e18;

const int MAX = 1e6;



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



struct edge {int to, cost;}; // 辺

// vector<edge> graph[MAX]; // 隣接リスト

// bool visit[MAX]; // 訪問状況



int n, m; // 変数

int sub[MAX];



int main() {

// input

    cin >> n;

    rep(i, n+1) {

        int boss;

        if (i > 1) {

            cin >> boss;

            sub[boss]++;

        }

    }

// solve

// output

    rep(i, n+1) {

        if (i > 0) cout << sub[i] << "\n";

    }

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



typedef long long ll;

typedef long double ld;

typedef unsigned long long ull;



const int N = 200005;

int cnt[N];



int main(){

	ios::sync_with_stdio(false);

	cin.tie(NULL);

	cout.tie(NULL);

	cout<<setprecision(32);



	int n, x;

	cin>>n;

	memset(cnt, 0, sizeof(cnt));

	for(int i = 2; i <= n; i++){

		cin>>x;

		cnt[x]++;

	}

	for(int i = 1; i <= n; i++){

		cout<<cnt[i]<<'\n';

	}





	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.7764366752427225x):
#include <bits/stdc++.h>

using namespace std;



typedef long long ll;

typedef long double ld;

typedef unsigned long long ull;



int main(){

	ios::sync_with_stdio(false);

	cin.tie(NULL);

	cout.tie(NULL);

	cout<<setprecision(32);



	int n;

	cin>>n;

	vector<int> deg(n);

	for(int i = 1; i < n; i++){

		int x;

		cin>>x;

		deg[x - 1]++;

	}

	for(auto x : deg){

		cout<<x<<"\n";

	}



	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

#define BS 313

#define ull unsigned long long

#define rint register int

#define gc() getchar()

inline int read(int r=0,int s=0,int c=gc()){for(;c<48||c>57;s=c,c=gc());for(;c>=48&&c<=57;(r*=10)+=c-48,c=gc());return s^'-'?r:-r;}

ull H[605][605], R[605][605], B[605]; char S[605][605]; int n, Ans;

inline ull HH(int i, int l, int r){return H[i][r]-H[i][l-1]*B[r-l+1];}

inline ull HR(int j, int l, int r){return R[r][j]-R[l-1][j]*B[r-l+1];}

inline bool Check(int a, int b)

{

	for(rint i = 1, x = a, y = b; i <= n; i++, x = x%n+1, y = y%n+1)

		if(HH(x,y,y+n-1) != HR(y,x,x+n-1)) return false; return true;

}

int main()

{

	n = read(); for(rint i = 1, j; i <= n; i++) for(scanf("%s",S[i]+1), j = 1; j <= n; S[i+n][j] = S[i][j+n] = S[i+n][j+n] = S[i][j], j++);

	B[0] = 1; B[1] = BS; for(rint i = 2; i <= n<<1; B[i] = B[i-1]*BS, i++);

	for(rint i = 1, j; i <= n<<1; i++) for(j = 1; j <= n<<1; H[i][j] = H[i][j-1]*BS+S[i][j], j++);

	for(rint j = 1, i; j <= n<<1; j++) for(i = 1; i <= n<<1; R[i][j] = R[i-1][j]*BS+S[i][j], i++);

	for(rint A = 1, B; A <= n; A++) for(B = 1; B <= n; B++) Ans += Check(A,B); printf("%d\n",Ans); return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.160394916867335x):
#include<cstdio>

int n,ans;

char a[305][305];

bool book[305][305],flag;

bool check(int A,int B){

	for(int i=0;i<n;++i)

		for(int j=i+1;j<n;++j)

			if(a[i+A>=n?i+A-n:i+A][j+B>=n?j+B-n:j+B]!=a[j+A>=n?j+A-n:j+A][i+B>=n?i+B-n:i+B]) return 0;

	return 1;

}

int main(){

	scanf("%d",&n);

	for(int i=0;i<n;++i) scanf("%s",a[i]);

	for(int A=0;A<n;++A)

		for(int B=0;B<n;++B){

			if(book[A][B]) continue;

			flag=0;

			if(check(A,B)) ans++,book[A][B]=1,flag=1;

			for(int l=1;l<=n;++l)

				if(A+l>=n||B+l>=n) break;

				else{

					book[A+l][B+l]=1;

					if(flag) ans++;

				}

		}

	printf("%d\n",ans);

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define F(i,a,b) for(int i=(a);i<=(b);++i)

#define F2(i,a,b) for(int i=(a);i<(b);++i)

#define dF(i,a,b) for(int i=(a);i>=(b);--i)

#define dF2(i,a,b) for(int i=(a);i>(b);--i)

#define dF3(i,a,b) for(int i=(a)-1;i>=(b);--i)

using namespace std;typedef long long ll;typedef double ld;int INF=0x3f3f3f3f;int INF2=0x7fffffff;ll LNF=0x3f3f3f3f3f3f3f3f;ll LNF2=0x7fffffffffffffff;



int n; char str[305];

int a[305][305],Ans;



int main(){

	scanf("%d",&n);

	F(i,1,n){

		scanf("%s",str+1);

		F(j,1,n) a[i][j]=str[j];

	}

	F(k,1,n){

		int Ok=1;

		F(i,1,n) F(j,1,n){

			int I=(j-k-1+n)%n+1;

			int J=(i+k-1)%n+1;

			if(a[i][j]!=a[I][J]) Ok=0;

		}

		if(Ok) Ans+=n;

	} printf("%d",Ans);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.1491967985916505x):
#include<cstdio>

int n,ans;

char a[305][305];

bool book[305][305],flag;

bool check(int A,int B){

	for(int i=0;i<n;++i)

		for(int j=i+1;j<n;++j)

			if(a[i+A>=n?i+A-n:i+A][j+B>=n?j+B-n:j+B]!=a[j+A>=n?j+A-n:j+A][i+B>=n?i+B-n:i+B]) return 0;

	return 1;

}

int main(){

	scanf("%d",&n);

	for(int i=0;i<n;++i) scanf("%s",a[i]);

	for(int A=0;A<n;++A)

		for(int B=0;B<n;++B){

			if(book[A][B]) continue;

			flag=0;

			if(check(A,B)) ans++,book[A][B]=1,flag=1;

			for(int l=1;l<=n;++l)

				if(A+l>=n||B+l>=n) break;

				else{

					book[A+l][B+l]=1;

					if(flag) ans++;

				}

		}

	printf("%d\n",ans);

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define F(i) for(int i=1;i<=n;++i)

int n; char str[305];

int a[305][305],Ans;

int main(){

	scanf("%d",&n);

	F(i){

		scanf("%s",str+1);

		F(j) a[i][j]=str[j];

	}

	F(k){

		int Ok=1;

		F(i) F(j){

			int I=(j-k-1+n)%n+1;

			int J=(i+k-1)%n+1;

			if(a[i][j]!=a[I][J]) Ok=0;

		}

		if(Ok) Ans+=n;

	} printf("%d",Ans);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.150345537358222x):
#include<cstdio>

int n,ans;

char a[305][305];

bool book[305][305],flag;

bool check(int A,int B){

	for(int i=0;i<n;++i)

		for(int j=i+1;j<n;++j)

			if(a[i+A>=n?i+A-n:i+A][j+B>=n?j+B-n:j+B]!=a[j+A>=n?j+A-n:j+A][i+B>=n?i+B-n:i+B]) return 0;

	return 1;

}

int main(){

	scanf("%d",&n);

	for(int i=0;i<n;++i) scanf("%s",a[i]);

	for(int A=0;A<n;++A)

		for(int B=0;B<n;++B){

			if(book[A][B]) continue;

			flag=0;

			if(check(A,B)) ans++,book[A][B]=1,flag=1;

			for(int l=1;l<=n;++l)

				if(A+l>=n||B+l>=n) break;

				else{

					book[A+l][B+l]=1;

					if(flag) ans++;

				}

		}

	printf("%d\n",ans);

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

#define BS 313

#define ull unsigned long long

#define rint register int

#define gc() getchar()

inline int read(int r=0,int s=0,int c=gc()){for(;c<48||c>57;s=c,c=gc());for(;c>=48&&c<=57;(r*=10)+=c-48,c=gc());return s^'-'?r:-r;}

ull H[605][605], R[605][605], B[605]; char S[605][605]; int n, Ans;

inline ull HH(int i, int l, int r){return H[i][r]-H[i][l-1]*B[r-l+1];}

inline ull HR(int j, int l, int r){return R[r][j]-R[l-1][j]*B[r-l+1];}

inline bool Check(int a, int b)

{

	for(rint i = 1, x = a, y = b; i <= n; i++, x = x%n+1, y = y%n+1)

		if(HH(x,y,y+n-1) != HR(y,x,x+n-1)) return false; return true;

}

int main()

{

	n = read(); for(rint i = 1, j; i <= n; i++) for(scanf("%s",S[i]+1), j = 1; j <= n; S[i+n][j] = S[i][j+n] = S[i+n][j+n] = S[i][j], j++);

	B[0] = 1; B[1] = BS; for(rint i = 2; i <= n<<1; B[i] = B[i-1]*BS, i++);

	for(rint i = 1, j; i <= n<<1; i++) for(j = 1; j <= n<<1; H[i][j] = H[i][j-1]*BS+S[i][j], j++);

	for(rint j = 1, i; j <= n<<1; j++) for(i = 1; i <= n<<1; R[i][j] = R[i-1][j]*BS+S[i][j], i++);

	for(rint A = 1, B; A <= n; A++) for(B = 1; B <= n; B++) Ans += Check(A,B); printf("%d\n",Ans); return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.175731768756983x):
#include<cstdio>

#define r register

int n;

char ch[305][305];

#define loop(x) (x>=n?(x-n):x)

int main(){

	scanf("%d",&n);r int ans=0;

	for(r int i=0;i<n;i++)scanf("%s",ch[i]);

	for(r int i=0,f=1;i<n;i++,f=1){

		for(r int j=0;j<n&&f;j++)

			for(r int k=j+1;k<n&&f;k++)

				f=(ch[j][loop(k+i)]==ch[k][loop(j+i)]);

		ans+=n*f;

	}

	printf("%d\n",ans);

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define F(i,a,b) for(int i=(a);i<=(b);++i)

#define F2(i,a,b) for(int i=(a);i<(b);++i)

#define dF(i,a,b) for(int i=(a);i>=(b);--i)

#define dF2(i,a,b) for(int i=(a);i>(b);--i)

#define dF3(i,a,b) for(int i=(a)-1;i>=(b);--i)

using namespace std;typedef long long ll;typedef double ld;int INF=0x3f3f3f3f;int INF2=0x7fffffff;ll LNF=0x3f3f3f3f3f3f3f3f;ll LNF2=0x7fffffffffffffff;



int n; char str[305];

int a[305][305],Ans;



int main(){

	scanf("%d",&n);

	F(i,1,n){

		scanf("%s",str+1);

		F(j,1,n) a[i][j]=str[j];

	}

	F(k,1,n){

		int Ok=1;

		F(i,1,n) F(j,1,n){

			int I=(j-k-1+n)%n+1;

			int J=(i+k-1)%n+1;

			if(a[i][j]!=a[I][J]) Ok=0;

		}

		if(Ok) Ans+=n;

	} printf("%d",Ans);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.1645003693304945x):
#include<cstdio>

#define r register

int n;

char ch[305][305];

#define loop(x) (x>=n?(x-n):x)

int main(){

	scanf("%d",&n);r int ans=0;

	for(r int i=0;i<n;i++)scanf("%s",ch[i]);

	for(r int i=0,f=1;i<n;i++,f=1){

		for(r int j=0;j<n&&f;j++)

			for(r int k=j+1;k<n&&f;k++)

				f=(ch[j][loop(k+i)]==ch[k][loop(j+i)]);

		ans+=n*f;

	}

	printf("%d\n",ans);

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define F(i) for(int i=1;i<=n;++i)

int n; char str[305];

int a[305][305],Ans;

int main(){

	scanf("%d",&n);

	F(i){

		scanf("%s",str+1);

		F(j) a[i][j]=str[j];

	}

	F(k){

		int Ok=1;

		F(i) F(j){

			int I=(j-k-1+n)%n+1;

			int J=(i+k-1)%n+1;

			if(a[i][j]!=a[I][J]) Ok=0;

		}

		if(Ok) Ans+=n;

	} printf("%d",Ans);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.165652522183896x):
#include<cstdio>

#define r register

int n;

char ch[305][305];

#define loop(x) (x>=n?(x-n):x)

int main(){

	scanf("%d",&n);r int ans=0;

	for(r int i=0;i<n;i++)scanf("%s",ch[i]);

	for(r int i=0,f=1;i<n;i++,f=1){

		for(r int j=0;j<n&&f;j++)

			for(r int k=j+1;k<n&&f;k++)

				f=(ch[j][loop(k+i)]==ch[k][loop(j+i)]);

		ans+=n*f;

	}

	printf("%d\n",ans);

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

using namespace std;

char s[305][305];

int n,ans=0,flag;

int main(){

	scanf("%d",&n);

	for(int i=0;i<n;i++) cin>>s[i];

	for(int k=0;k<n;k++){

		flag=1;

		for(int i=0;i<n&&flag;i++){

			for(int j=0;j<n;j++){

				if(s[i][(j+k)%n]!=s[j][(i+k)%n]){

					flag=0;

					break;

				}

			}

		}

		ans+=n*flag;

	}

	printf("%d\n",ans);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.1796827308054585x):
#include<cstdio>

#define r register

int n;

char ch[305][305];

#define loop(x) (x>=n?(x-n):x)

int main(){

	scanf("%d",&n);r int ans=0;

	for(r int i=0;i<n;i++)scanf("%s",ch[i]);

	for(r int i=0,f=1;i<n;i++,f=1){

		for(r int j=0;j<n&&f;j++)

			for(r int k=j+1;k<n&&f;k++)

				f=(ch[j][loop(k+i)]==ch[k][loop(j+i)]);

		ans+=n*f;

	}

	printf("%d\n",ans);

}
// Slower C++ solution:
#include <iostream>

#include <vector>

#include <string>

#include <algorithm>

#include <cstdio>

#include <cstring>

#include <cmath>

using namespace std;

using ll = long long;



char s[300][301];

char t[300][301];

int n;

int k = 0;



int f() {

    //for (int i = 0; i < n; i++) {

    //    for (int j = 0; j < n; j++) {

    //        cout << s[i][j];

    //    }

    //    cout << endl;

    //}

    for (int i = 0; i < n; i++) {

        for (int j = 0; j < i; j++) {

            if (s[i][j] != s[j][i]) {

                return 0;

            }

        }

    }

    return 1;

}



int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);



    cin >> n;



    for (int i = 0; i < n; i++) {

        cin >> s[i];

    }



    int r = 0;

    for (int i = 0; i < n; i++) {

        memcpy(t, s, sizeof(s));

        for (int i = 0; i < n; i++) {

            for (int j = 0; j < n; j++) {

                int i1 = i - 1; if (i1 < 0) i1 += n;

                s[i][j] = t[i1][j];

            }

        }

        r += f() * n;

        k++;

    }



    cout << r << endl;



    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.4525662071471472x):
#include <iostream>

#include <vector>

#include <string>

#include <algorithm>

#include <map>

#include <cstdio>

#include <cstring>

#include <cmath>

using namespace std;

using ll = long long;



int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);



    int n;

    cin >> n;



    char s[300][600];

    for (int i = 0; i < n; i++) {

        cin >> s[i];

        memcpy(&s[i][n], &s[i][0], n);

    }



    int r = 0;

    for (int x = 0; x < n; x++) {

        for (int i = 0; i < n; i++) {

            for (int j = i + 1; j < n; j++) {

                if (s[i][j + x] != s[j][i + x]) goto chigau;

            }

        }

        r++;

        continue;

    chigau:

        continue;

    }



    cout << r * n << endl;



    return 0;

}
// Slower C++ solution:
#include<iostream>

using namespace std;



int n,b[2][100100],f[2][100100];

bool v[100100];



int dfs(int s, int now, int maxi, int num){

  v[now] = true;

  

  for(int i=0;i<2;i++){

    if(!v[b[i][now]]){

      if(maxi == f[i][now])num++;

      else if(maxi < f[i][now]){

	maxi = f[i][now];

	num = 1;

      }

      if(b[i][now] == s)return num;

      return dfs(s,b[i][now],maxi,num);

    }

  }

  if(maxi == f[1][s])return num+1;

  else if(maxi < f[1][s])return 1;

  else return num;

}



int main(){

  while(cin >> n,n){

    for(int i=0;i<n;i++){

      cin >> b[0][i] >> f[0][i] >> b[1][i] >> f[1][i];

      v[i] = false;

    }



    int ans = 1;

    for(int i=0;i<n;i++){

      if(!v[i]){

	v[i] = true;

	ans = (ans * dfs(i,b[0][i],f[0][i],1) ) % 10007;

      }

    }

    cout << ans << endl;

  }

}

// Faster C++ solution for the same problem (measured speedup: 5.1348641322888176x):
#include<cstdio>

using namespace std;



int n,b[2][100100],f[2][100100],maxi,num;

bool v[100100];



int dfs(int s, int now){

  v[now] = true;

  

  for(int i=0;i<2;i++){

    if(!v[b[i][now]]){

      if(maxi == f[i][now])num++;

      else if(maxi < f[i][now]){

	maxi = f[i][now];

	num = 1;

      }

      return dfs(s,b[i][now]);

    }

  }

  if(maxi == f[1][s])return num+1;

  else if(maxi < f[1][s])return 1;

  else return num;

}



int main(){

  while(scanf("%d",&n),n){

    for(int i=0;i<n;i++){

      scanf("%d%d%d%d",&b[0][i],&f[0][i],&b[1][i],&f[1][i]);

      v[i] = false;

    }



    int ans = 1;

    for(int i=0;i<n;i++){

      if(!v[i]){

	v[i] = true;

	maxi = f[0][i]; num = 1;

	ans = (ans * dfs(i,b[0][i]) ) % 10007;

      }

    }

    printf("%d\n",ans);

  }

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



typedef long long llt;



const int MaxN = 100000 + 5;



int N;

llt A[MaxN];

llt ans1, ans2;

deque <llt> que1, que2;



inline llt llAbs(llt x) {

    if (x < 0) return -x;

    return x;

}



int main() {

    scanf("%d", &N);

    for (int i = 1; i <= N; ++i) scanf("%lld", &A[i]);



    sort(A + 1, A + 1 + N);



    que1.push_back(A[1]);

    que2.push_back(A[N]);



    llt Max = A[N], Min = A[2];

    int Maxi = N, Mini = 2;

    for (int i = 2; i <= N; ++i) {

        llt F = que1.front(), L = que1.back();

        llt ValF = max(llAbs(F - Max), llAbs(F - Min)),

            ValL = max(llAbs(L - Max), llAbs(L - Min));

        if (ValF > ValL) {

            ans1 += ValF;

            // printf("ans1 += %lld\n", ValF);

            if (llAbs(F - Max) == ValF) que1.push_front(Max), Maxi--;

            else que1.push_front(Min), Mini++;

        } else {

            ans1 += ValL;

            // printf("ans1 += %lld\n", ValL);

            if (llAbs(L - Max) == ValL) que1.push_back(Max), Maxi--;

            else que1.push_back(Min), Mini++;

        }

        Max = A[Maxi]; Min = A[Mini];

    }



    Max = A[N - 1], Min = A[1];

    Maxi = N - 1, Mini = 1;

    for (int i = 2; i <= N; ++i) {

        llt F = que2.front(), L = que2.back();

        llt ValF = max(llAbs(F - Max), llAbs(F - Min)),

            ValL = max(llAbs(L - Max), llAbs(L - Min));

        if (ValF > ValL) {

            ans2 += ValF;

            // printf("ans2 += %lld\n", ValF);

            if (llAbs(F - Max) == ValF) que2.push_front(Max), Maxi--;

            else que2.push_front(Min), Mini++;

        } else {

            ans2 += ValL;

            // printf("ans2 += %lld\n", ValL);

            if (llAbs(L - Max) == ValL) que2.push_back(Max), Maxi--;

            else que2.push_back(Min), Mini++;

        }

        Max = A[Maxi]; Min = A[Mini];

    }



    cout << max(ans1, ans2) << endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.220817589869048x):
#include <cstdio>

#include <algorithm>



const int MaxN = 100000 + 5;



int N;

long long A[MaxN];



void init() {

  scanf("%d", &N);

  for (int i = 1; i <= N; ++i) {

    scanf("%lld", &A[i]);

  }

}



void solve() {

  std::sort(A + 1, A + 1 + N);



  if (N % 2 == 0) {

    long long ans = 0;

    for (int i = 1; i < N / 2; ++i) {

      ans -= 2 * A[i];

    }

    ans -= A[N / 2];

    ans += A[N / 2 + 1];

    for (int i = N / 2 + 2; i <= N; ++i) {

      ans += 2 * A[i];

    }



    printf("%lld\n", ans);

  } else {

    long long ans1 = 0, ans2 = 0;



    for (int i = 1; i <= N / 2 - 1; ++i) {

      ans1 -= 2 * A[i];

    }

    ans1 -= A[N / 2] + A[N / 2 + 1];

    for (int i = N / 2 + 2; i <= N; ++i) {

      ans1 += 2 * A[i];

    }



    for (int i = 1; i <= N / 2; ++i) {

      ans2 -= 2 * A[i];

    }

    ans2 += A[N / 2 + 1] + A[N / 2 + 2];

    for (int i = N / 2 + 3; i <= N; ++i) {

      ans2 += 2 * A[i];

    }



    printf("%lld\n", std::max(ans1, ans2));

  }

}



int main() {

  init();

  solve();

  return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>



using namespace std;

typedef long long LL;

LL a[100005];

int main()

{

    int n;

    cin>>n;

    for(int i=1;i<=n;i++)

    {

        cin>>a[i];

    }

    sort(a+1,a+1+n);

    LL ans=0;

    if(n%2==1)

    {

        int num=(n-1)/2;

        for(int i=n;i>=n-(n-1)/2+1;i--)

        {

            ans+=a[i]*2;

        }

        for(int i=1;i<=(n-1)/2-1;i++)

        {

            ans-=a[i]*2;

        }

        for(int i=(n-1)/2;i<=n-(n-1)/2;i++)

        {

            ans-=a[i];

        }

        LL sum=0;

        for(int i=1;i<=n/2;i++)

        {

            sum-=a[i]*2;

        }

        sum+=a[n/2+1]+a[n/2+2];

        for(int i=n/2+3;i<=n;i++)

        {

            sum+=a[i]*2;

        }

        if(sum>ans)

        {

            ans=sum;

        }

    }

    else

    {     

         for(int i=n;i>=n-(n-2)/2+1;i--)

         {

             ans+=a[i]*2;

         }

         ans+=a[n-(n-2)/2];

         ans-=a[n-(n-2)/2-1];

         for(int i=1;i<=(n-2)/2;i++)

         {

             ans-=a[i]*2;

         }

    }

    cout<<ans<<endl;

}


// Faster C++ solution for the same problem (measured speedup: 5.220597806445161x):
#include<cstdio>

#include<cstring>

#include<cmath>

#include<algorithm>

using namespace std;

const int maxn=1e5+100;

int a[maxn];

int main(){

	int n;

	while(~scanf("%d",&n)){

		for(int i=1;i<=n;i++)

			scanf("%d",a+i);

		sort(a+1,a+n+1);

		long long ans=0;

		if(n<=3){

			if(n==2)

				ans=a[2]-a[1];

			else

				ans=max(a[2]+a[3]-2*a[1],2*a[3]-a[1]-a[2]);

			goto loop;

		}

		if(n&1){

			for(int i=1;i<=n;i++){

				if(i==n/2+1)continue;

				else if(i<n/2+1){

					if(i==n/2)

						ans-=a[i];

					else

						ans-=a[i]*2;

				}

				else if(i>n/2+1){

					if(i==n/2+2)

						ans+=a[i];

					else

						ans+=a[i]*2;

				}

			}

			ans+=max(a[n/2+1]-a[n/2],a[n/2+2]-a[n/2+1]);

		}

		else{

			for(int i=1;i<=n;i++){

				if(i<n/2)

					ans-=a[i]*2;

				else if(i>n/2+1)

					ans+=a[i]*2;			

			}

			ans+=a[n/2+1]-a[n/2];

		}

loop:	printf("%lld\n",ans);

	}

}
// Slower C++ solution:
#include <iostream>

#include <cstdio>

#include <cmath>

#include <cstring>

#include <algorithm>



using namespace std;



const int N = 200010;



void QuickSort(char s[][11], int l, int h)

{

    int i = l;

    int j = h;

    char t[11],d[11];

    strcpy(t,s[(l+h)/2]);

        while (i <= j)

        {

            while(strcmp(s[j],t)>0)     

            j--;

            while(strcmp(s[i],t)<0)      

            i++;

            if(i<=j)

            {

                strcpy(d,s[i]);

                strcpy(s[i],s[j]);

                strcpy(s[j],d);

                i++;

                j--;

            }

        }    

        if(l<j) QuickSort(s, l, j);     

        if(i<h) QuickSort(s, i, h);    

    

}

int main()

{

	int i,j,n,a[N]={0},b=0,q=0;

	char s[N][11],t[11];

	scanf("%d",&n);

	for(i=0;i<n;i++)

	scanf("%s",s[i]);

	QuickSort(s,0, n-1);

	

    for(j=0;j<n;j++)

	{

		if(strcmp(s[j],s[j+1])==0)

		{

			a[j-b]++;

			b=a[j-b];

		}

		else

		{

			if(a[j-b]>q)

			q=a[j-b];

			b=0;

		}

	}

	

	for(i=0;i<n;i++)

	{

		if(a[i]==q)

		printf("%s\n",s[i]);

	}



return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.8256760046678895x):


#include<bits/stdc++.h>

using namespace std;

int main()

{

    int n, i, q=1, j, Max=0;

    string x;

    cin >> n;

    string a[n];

    vector< pair<string, int> >v;

    for(i=0; i<n; i++){

        cin >> a[i];

    }

    sort(a, a+n);

    for(i=0; i<n;){

        j = i + 1;

        while(a[i]==a[j])q++, j++;

        v.push_back(make_pair(a[i], q));

        if(q>Max)Max=q;

        i=j, q=1;

    }

    sort(v.begin(), v.end());

    for(i=0; i<v.size(); i++)

        if(v[i].second==Max)cout<<v[i].first<<endl;



    return 0;

}