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

using namespace std;



int main(){

  int n,x[302][302]={},y[302][302]={};

  cin>>n;

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

    for(int j=0;j<n;j++)cin>>y[i][j],x[i][j]=y[i][j];

  

  int ans=max(y[0][n-1],y[n-1][0]);

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

    for(int j=n-2;j>=0;j--) {

      x[i][j]+=x[i][j+1];

      y[j][i]+=y[j+1][i];

      ans=max(ans,max(y[j][i],x[i][j]));

    }



  

  int sum[302][302],K[2][302][302]={},t=0,f=1;

  while(f){

    t++,f=0;

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

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

	int a=K[t%2][i][j],&b=K[(t+1)%2][i][j];



	b=a;

	sum[i][j]=-10000000;



	for(int k=a+1;k<n;k++) { //tate

	  int X=(x[a][i]-x[a][j+1])+(x[k][i]-x[k][j+1]);

	  int Y=(y[a+1][i]-y[k][i])+(y[a+1][j]-y[k][j]);

	  if(sum[i][j]<=X+Y)sum[i][j]=X+Y,b=k;

	}

	

	if(b!=n-1)f=1;

	ans=max(ans,sum[i][j]);

	for(int k=a+1;k<b;k++){//tate

	  sum[i][j]+=(x[k][i+1]-x[k][j])-(x[k-1][i]-x[k-1][j+1]);

	  ans=max(ans,sum[i][j]);

	}

      }

  }

  cout <<ans<<endl;

	  

  return 0; 

}

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

#include <time.h>

#define INF 10000000

using namespace std;



int main(){

  clock_t start=clock();

  int n,x[302][302]={},y[302][302]={};

  cin>>n;

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

    for(int j=0;j<n;j++)cin>>y[i][j],x[i][j]=y[i][j];

  /*

  n=300;

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

    for(int j=0;j<n;j++) x[i][j]=y[i][j]=-1;

  */



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

    for(int j=n-2;j>=0;j--) {

      x[i][j]+=x[i][j+1];

      y[j][i]+=y[j+1][i];

    }

  

  int ans=y[0][n-1],sum,K[302][302]={},t=0,f=1;

  while(f){

    t++,f=0;

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

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

	int a=K[i][j],nk=a;

	sum=-INF;

	for(int k=a+1;k<n;k++) { //tate

	  int X=(x[a][i]-x[a][j+1])+(x[k][i]-x[k][j+1]);

	  int Y=(y[a+1][i]-y[k][i])+(y[a+1][j]-y[k][j]);

	  if(sum<=X+Y)sum=X+Y,nk=k;

	}

	ans=max(ans,sum);

	

	if(nk<n-1)f=1;

	for(int k=a+1;k<nk;k++){//tate

	  sum+=(x[k][i+1]-x[k][j])-(x[k-1][i]-x[k-1][j+1]);

	  ans=max(ans,sum);

	}

	if(a+1==nk&&j-i!=1) nk=n-1;

	K[i][j]=nk;

      }

  }

  clock_t end=clock();

  //  cout << (double)(end-start)/CLOCKS_PER_SEC <<endl;

  cout <<ans<<endl;

	  

  return 0; 

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

using namespace std;



int main(){

  int n,x[302][302]={},y[302][302]={};

  cin>>n;

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

    for(int j=0;j<n;j++)cin>>y[i][j],x[i][j]=y[i][j];

  

  int ans=max(y[0][n-1],y[n-1][0]);

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

    for(int j=n-2;j>=0;j--) {

      x[i][j]+=x[i][j+1];

      y[j][i]+=y[j+1][i];

    }



  

  int sum[302][302],K[2][302][302]={},t=0,f=1;

  while(f){

    t++,f=0;

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

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

	int a=K[t%2][i][j],&b=K[(t+1)%2][i][j];

	b=a+1;

	sum[i][j]=-10000000;



	for(int k=a+1;k<n;k++) { //tate

	  int X=(x[a][i]-x[a][j+1])+(x[k][i]-x[k][j+1]);

	  int Y=(y[a+1][i]-y[k][i])+(y[a+1][j]-y[k][j]);

	  if(sum[i][j]<=X+Y)sum[i][j]=X+Y,b=k;

	}

	

	if(b<=n-1)f=1;

	ans=max(ans,sum[i][j]);

	for(int k=a+1;k<b;k++){//tate

	  sum[i][j]+=(x[k][i+1]-x[k][j])-(x[k-1][i]-x[k-1][j+1]);

	  ans=max(ans,sum[i][j]);

	}

      }

  }

  cout <<ans<<endl;

	  

  return 0; 

}

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

#include <time.h>

#define INF 10000000

using namespace std;



int main(){

  clock_t start=clock();

  int n,x[302][302]={},y[302][302]={};

  cin>>n;

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

    for(int j=0;j<n;j++)cin>>y[i][j],x[i][j]=y[i][j];

  /*

  n=300;

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

    for(int j=0;j<n;j++) x[i][j]=y[i][j]=-1;

  */



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

    for(int j=n-2;j>=0;j--) {

      x[i][j]+=x[i][j+1];

      y[j][i]+=y[j+1][i];

    }

  

  int ans=y[0][n-1],sum,K[302][302]={},t=0,f=1;

  while(f){

    t++,f=0;

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

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

	int a=K[i][j],nk=a;

	sum=-INF;

	for(int k=a+1;k<n;k++) { //tate

	  int X=(x[a][i]-x[a][j+1])+(x[k][i]-x[k][j+1]);

	  int Y=(y[a+1][i]-y[k][i])+(y[a+1][j]-y[k][j]);

	  if(sum<=X+Y)sum=X+Y,nk=k;

	}

	ans=max(ans,sum);

	

	if(nk<n-1)f=1;

	for(int k=a+1;k<nk;k++){//tate

	  sum+=(x[k][i+1]-x[k][j])-(x[k-1][i]-x[k-1][j+1]);

	  ans=max(ans,sum);

	}

	if(a+1==nk&&j-i!=1) nk=n-1;

	K[i][j]=nk;

      }

  }

  clock_t end=clock();

  //  cout << (double)(end-start)/CLOCKS_PER_SEC <<endl;

  cout <<ans<<endl;

	  

  return 0; 

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

#define INF 10000000

using namespace std;



int main(){

  int n,x[302][302]={},y[302][302]={};

  cin>>n;

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

    for(int j=0;j<n;j++)cin>>y[i][j],x[i][j]=y[i][j];

  

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

    for(int j=n-2;j>=0;j--) {

      x[i][j]+=x[i][j+1];

      y[j][i]+=y[j+1][i];

    }



  int ans=max(y[0][n-1],y[n-1][0]),sum[302][302],K[2][302][302]={},t=0,f=1;

  while(f){

    t++,f=0;

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

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

	int a=K[t%2][i][j],&b=K[(t+1)%2][i][j];

	b=a;

	sum[i][j]=-INF;



	for(int k=a+1;k<n;k++) { //tate

	  int X=(x[a][i]-x[a][j+1])+(x[k][i]-x[k][j+1]);

	  int Y=(y[a+1][i]-y[k][i])+(y[a+1][j]-y[k][j]);

	  if(sum[i][j]<=X+Y)sum[i][j]=X+Y,b=k;

	}

	ans=max(ans,sum[i][j]);



	if(b!=n-1)f=1;

	for(int k=a+1;k<b;k++){//tate

	  sum[i][j]+=(x[k][i+1]-x[k][j])-(x[k-1][i]-x[k-1][j+1]);

	  ans=max(ans,sum[i][j]);

	}

      }

  }

  cout <<ans<<endl;

	  

  return 0; 

}

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

#include <time.h>

#define INF 10000000

using namespace std;



int main(){

  clock_t start=clock();

  int n,x[302][302]={},y[302][302]={};

  cin>>n;

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

    for(int j=0;j<n;j++)cin>>y[i][j],x[i][j]=y[i][j];

  /*

  n=300;

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

    for(int j=0;j<n;j++) x[i][j]=y[i][j]=-1;

  */



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

    for(int j=n-2;j>=0;j--) {

      x[i][j]+=x[i][j+1];

      y[j][i]+=y[j+1][i];

    }

  

  int ans=y[0][n-1],sum,K[302][302]={},t=0,f=1;

  while(f){

    t++,f=0;

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

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

	int a=K[i][j],nk=a;

	sum=-INF;

	for(int k=a+1;k<n;k++) { //tate

	  int X=(x[a][i]-x[a][j+1])+(x[k][i]-x[k][j+1]);

	  int Y=(y[a+1][i]-y[k][i])+(y[a+1][j]-y[k][j]);

	  if(sum<=X+Y)sum=X+Y,nk=k;

	}

	ans=max(ans,sum);

	

	if(nk<n-1)f=1;

	for(int k=a+1;k<nk;k++){//tate

	  sum+=(x[k][i+1]-x[k][j])-(x[k-1][i]-x[k-1][j+1]);

	  ans=max(ans,sum);

	}

	if(a+1==nk&&j-i!=1) nk=n-1;

	K[i][j]=nk;

      }

  }

  clock_t end=clock();

  //  cout << (double)(end-start)/CLOCKS_PER_SEC <<endl;

  cout <<ans<<endl;

	  

  return 0; 

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

using namespace std;

typedef pair<int,int> p;

typedef pair<p,p> P;



char mp[60][30];

int w,h;

int cal(){

  bool used[2][60][30]={};

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

  priority_queue<P,vector<P>,greater<P> > q;

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

    if(mp[h-1][i]=='S')q.push(P(p(0,0),p(i,h-1))),q.push(P(p(0,1),p(i,h-1)));

  while(!q.empty()){

    int s=q.top().first.first,l=q.top().first.second;

    int x=q.top().second.first,y=q.top().second.second;

    q.pop();

    if(mp[y][x]=='T')return s;

    used[l][y][x]=1;

    int f=1,c=0;

    if(l)f=-1;

    if(isdigit(mp[y][x]))c=mp[y][x]-'0';

    for(int d=0;d<9;d++){

      int nx=x+f*dx[d],ny=y+f*dy[d];

      if(nx<0||w<=nx||ny<0||h<=ny||mp[ny][nx]=='X'||used[!l][ny][nx])continue;

      q.push(P(p(s+c,!l),p(nx,ny)));

    }

  }

  return -1;

}



int main(){

  while(cin>>w>>h,w){

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

      for(int j=0;j<w;j++)cin>>mp[i][j];

    cout<<cal()<<endl;

  }

  return 0;

}

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

using namespace std;

typedef pair<int,int> p;

typedef pair<p,p> P;



char mp[60][30];

int w,h;

int cal(){

  bool used[2][60][30]={};

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

  priority_queue<P,vector<P>,greater<P> > q;

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

    if(mp[h-1][i]=='S')q.push(P(p(0,0),p(i,h-1))),q.push(P(p(0,1),p(i,h-1)));

  while(!q.empty()){

    int s=q.top().first.first,l=q.top().first.second;

    int x=q.top().second.first,y=q.top().second.second;

    q.pop();

    if(mp[y][x]=='T')return s;

    if(used[l][y][x]||mp[y][x]=='X')continue;

    used[l][y][x]=1;

    int f=1,c=0;

    if(l)f=-1;

    if(isdigit(mp[y][x]))c=mp[y][x]-'0';

    for(int d=0;d<9;d++){

      int nx=x+f*dx[d],ny=y+f*dy[d];

      if(nx<0||w<=nx||ny<0||h<=ny)continue;

      q.push(P(p(s+c,!l),p(nx,ny)));

    }

  }

  return -1;

}



int main(){

  while(cin>>w>>h,w){

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

      for(int j=0;j<w;j++)cin>>mp[i][j];

    cout<<cal()<<endl;

  }

  return 0;

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

#include <set>



int a[100000];



int main() {

  int n;

  scanf("%d", &n);

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

    scanf("%d", &a[i]);

  int xor_sum = 0;

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

    xor_sum ^= a[i];

  std::set<int> s;

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

    s.insert(a[i] ^ (a[i] - 1));

  int ans = 0;

  for (int bit = 29; bit >= 0; bit--) {

    if (((1 << bit) & xor_sum) == 0) {

      continue;

    }

    int x = (1 << (bit + 1)) - 1;



    if (s.count(x)) {

      xor_sum ^= x;

      ans += 1;

    }

  }



  if (xor_sum != 0) {

    printf("-1\n");

  } else {

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

  }

}

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



int check[30];



int main() {

  for (int bit = 29; bit >= 0; bit--) {

    check[bit] = 0;

  }



  int n;

  scanf("%d", &n);

  int xor_sum = 0;

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

    int a;

    scanf("%d", &a);

    xor_sum ^= a;

    a = a ^ (a - 1);

    for (int bit = 29; bit >= 0; bit--) {

      int x = (1 << (bit + 1)) - 1;

      if (a == x) {

        check[bit] = 1;

      }

    }

  }



  int ans = 0;

  for (int bit = 29; bit >= 0; bit--) {

    if (((1 << bit) & xor_sum) == 0) {

      continue;

    }

    int x = (1 << (bit + 1)) - 1;



    if (check[bit] > 0) {

      xor_sum ^= x;

      ans += 1;

    }

  }



  if (xor_sum != 0) {

    printf("-1\n");

  } else {

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

  }

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

#include <set>



int a[100000];



int main() {

  int n;

  scanf("%d", &n);

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

    scanf("%d", &a[i]);

  int xor_sum = 0;

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

    xor_sum ^= a[i];

  std::set<int> s;

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

    s.insert(a[i] ^ (a[i] - 1));

  int ans = 0;

  for (int bit = 29; bit >= 0; bit--) {

    if (((1 << bit) & xor_sum) == 0) {

      continue;

    }

    int x = (1 << (bit + 1)) - 1;



    if (s.count(x)) {

      xor_sum ^= x;

      ans += 1;

    }

  }



  if (xor_sum != 0) {

    printf("-1\n");

  } else {

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

  }

}

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



int check[30];



int main() {



  for (int bit = 29; bit >= 0; bit--) {

    check[bit] = 0;

  }



  int n;

  scanf("%d", &n);

  int xor_sum = 0;

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

    int a;

    scanf("%d", &a);

    xor_sum ^= a;

    a = a ^ (a - 1);



    switch (a) {

    case 1073741823:

      check[29] = 1;

      break;

    case 536870911:

      check[28] = 1;

      break;

    case 268435455:

      check[27] = 1;

      break;

    case 134217727:

      check[26] = 1;

      break;

    case 67108863:

      check[25] = 1;

      break;

    case 33554431:

      check[24] = 1;

      break;

    case 16777215:

      check[23] = 1;

      break;

    case 8388607:

      check[22] = 1;

      break;

    case 4194303:

      check[21] = 1;

      break;

    case 2097151:

      check[20] = 1;

      break;

    case 1048575:

      check[19] = 1;

      break;

    case 524287:

      check[18] = 1;

      break;

    case 262143:

      check[17] = 1;

      break;

    case 131071:

      check[16] = 1;

      break;

    case 65535:

      check[15] = 1;

      break;

    case 32767:

      check[14] = 1;

      break;

    case 16383:

      check[13] = 1;

      break;

    case 8191:

      check[12] = 1;

      break;

    case 4095:

      check[11] = 1;

      break;

    case 2047:

      check[10] = 1;

      break;

    case 1023:

      check[9] = 1;

      break;

    case 511:

      check[8] = 1;

      break;

    case 255:

      check[7] = 1;

      break;

    case 127:

      check[6] = 1;

      break;

    case 63:

      check[5] = 1;

      break;

    case 31:

      check[4] = 1;

      break;

    case 15:

      check[3] = 1;

      break;

    case 7:

      check[2] = 1;

      break;

    case 3:

      check[1] = 1;

      break;

    case 1:

      check[0] = 1;

      break;

    }

  }



  int ans = 0;

  for (int bit = 29; bit >= 0; bit--) {

    if (((1 << bit) & xor_sum) == 0) {

      continue;

    }

    int x = (1 << (bit + 1)) - 1;



    if (check[bit] > 0) {

      xor_sum ^= x;

      ans += 1;

    }

  }



  if (xor_sum != 0) {

    printf("-1\n");

  } else {

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

  }

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

using namespace std;

int judge(int a,int b,int c,int l)

{

    int k=0;

    if(a<l)

        k++;

    if(b<l)

        k++;

    if(c<l)

        k++;

    return k;

}

int main()

{

    int a,b,c,sum=0,max1=0;

    scanf("%d%d%d",&a,&b,&c);

    max1=max(a,b);max1=max(max1,c);

    while((max1-a)>=2)

    {

        a+=2;

        sum++;

    }

    while((max1-b)>=2)

    {

        b+=2;

        sum++;

    }

    while((max1-c)>=2)

    {

        c+=2;

        sum++;

    }



    if(judge(a,b,c,max1)==0)

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

    else if(judge(a,b,c,max1)==2)

        printf("%d\n",sum+1);

    else

        printf("%d\n",sum+2);

}

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

#include<cstring>

#include<algorithm>

using namespace std;

int a[5];

int cnt=0;

int main()

{

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

		scanf("%d",&a[i]);

	int cnt=0;

	int f=1;

	while(f)

	{

		if(a[1]==a[2]&&a[2]==a[3]) break;

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

		while(a[1]+2<=a[3])a[1]+=2,cnt++;

		if(a[1]==a[2]&&a[2]==a[3]) break;

		while(a[2]+2<=a[3])a[2]+=2,cnt++;

		if(a[1]==a[2]&&a[2]==a[3]) break;

		if(a[2]==a[3]&&a[1]!=a[2]) a[1]+=2,a[2]+=1,a[3]+=1,cnt+=2;\

		if(a[1]==a[2]&&a[2]==a[3]) break;

		if((a[1]+1<=a[3]&&a[2]+1<=a[3]))a[1]+=1,a[2]+=1,cnt++;

	}

	printf("%d",cnt);

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

#include<algorithm>

using namespace std;

int a[3];

int main()

{

    cin>>a[0]>>a[1]>>a[2];

    sort(a,a+3);

    int ans=2*a[2]-a[1]-a[0];

    if (ans%2)

        ans+=3;

    ans/=2;

    cout<<ans<<endl;

    return 0;

}


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

#include<cstring>

#include<algorithm>

using namespace std;

int a[5];

int cnt=0;

int main()

{

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

		scanf("%d",&a[i]);

	int cnt=0;

	int f=1;

	while(f)

	{

		if(a[1]==a[2]&&a[2]==a[3]) break;

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

		while(a[1]+2<=a[3])a[1]+=2,cnt++;

		if(a[1]==a[2]&&a[2]==a[3]) break;

		while(a[2]+2<=a[3])a[2]+=2,cnt++;

		if(a[1]==a[2]&&a[2]==a[3]) break;

		if(a[2]==a[3]&&a[1]!=a[2]) a[1]+=2,a[2]+=1,a[3]+=1,cnt+=2;\

		if(a[1]==a[2]&&a[2]==a[3]) break;

		if((a[1]+1<=a[3]&&a[2]+1<=a[3]))a[1]+=1,a[2]+=1,cnt++;

	}

	printf("%d",cnt);

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

#include<cstdio>

#include<cstring>

#include<algorithm>

#include<cstdlib>

#include<cmath>

#include<vector>

#include<queue>

#define IO ios::sync_with_stdio(false);cin.tie(0);

const int MOD=1e9+7;

typedef long long ll;

using namespace std;

int a[3], cnt=0;

int main()

{

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

		cin >> a[i];

	}

	sort(a, a+3);

	while(a[0] != a[2]){

		cnt++;

		if(a[1] == a[2] || a[2]-a[0]>1)

			a[0] += 2;

		else a[0]++, a[1]++; 

		sort(a, a+3);

	}

	cout << cnt << endl;

	return 0;

} 

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

#include<cstring>

#include<algorithm>

using namespace std;

int a[5];

int cnt=0;

int main()

{

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

		scanf("%d",&a[i]);

	int cnt=0;

	int f=1;

	while(f)

	{

		if(a[1]==a[2]&&a[2]==a[3]) break;

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

		while(a[1]+2<=a[3])a[1]+=2,cnt++;

		if(a[1]==a[2]&&a[2]==a[3]) break;

		while(a[2]+2<=a[3])a[2]+=2,cnt++;

		if(a[1]==a[2]&&a[2]==a[3]) break;

		if(a[2]==a[3]&&a[1]!=a[2]) a[1]+=2,a[2]+=1,a[3]+=1,cnt+=2;\

		if(a[1]==a[2]&&a[2]==a[3]) break;

		if((a[1]+1<=a[3]&&a[2]+1<=a[3]))a[1]+=1,a[2]+=1,cnt++;

	}

	printf("%d",cnt);

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

using namespace std;

const int MAXn = 50 + 5, INF = 1e9;

int dp[MAXn][MAXn][MAXn], a, b, c, res = INF;



int main() {

	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

	cin >> a >> b >> c;

	if (a == b && b == c)

		return cout << 0,0;

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

		for (int j = 0; j < MAXn; j++)

			for (int x = 0; x < MAXn; x++)

				dp[i][j][x] = INF;

	dp[a][b][c] = 0;

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

		for (int j = 1; j < MAXn; j++)

			for (int x = 1; x < MAXn; x++) {

				dp[i][j][x] = min(dp[i][j][x], dp[i-1][j-1][x] + 1);

				dp[i][j][x] = min(dp[i][j][x], dp[i][j-1][x-1] + 1);

				dp[i][j][x] = min(dp[i][j][x], dp[i-1][j][x-1] + 1);

				if (i >= 2) {

					dp[i][j][x] = min(dp[i][j][x], dp[i-2][j][x] + 1);

				}

				if (j >= 2) {

					dp[i][j][x] = min(dp[i][j][x], dp[i][j-2][x] + 1);

				}

				if (x >= 2) {

					dp[i][j][x] = min(dp[i][j][x], dp[i][j][x-2] + 1);

				}

				if (i == j && j == x)

					res = min(res, dp[i][j][x]);

			}

	cout << res;

}


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

using namespace std;



const int inF = 1e9 + 100;



int a, b, c;

int ans = inF;



int f(int x, int y) {

	if(x >= y)

		return x - y;

	return ((y - x) >> 1) + (((y - x) & 1) << 1);

}



int main() {

	ios::sync_with_stdio(false), cin.tie(0);

	cin >> a >> b >> c;

	for (int x = -100; x <= 100; x++)

		ans = min(ans, f(a, x) + f(b, x) + f(c, x));

	cout << ans;

	return 0;

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

using namespace std;

const int MAXn = 50 + 5, INF = 1e9;

int dp[MAXn][MAXn][MAXn], a, b, c, res = INF;



int main() {

	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

	cin >> a >> b >> c;

	if (a == b && b == c)

		return cout << 0,0;

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

		for (int j = 0; j < MAXn; j++)

			for (int x = 0; x < MAXn; x++)

				dp[i][j][x] = INF;

	dp[a][b][c] = 0;

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

		for (int j = 1; j < MAXn; j++)

			for (int x = 1; x < MAXn; x++) {

				dp[i][j][x] = min(dp[i][j][x], dp[i-1][j-1][x] + 1);

				dp[i][j][x] = min(dp[i][j][x], dp[i][j-1][x-1] + 1);

				dp[i][j][x] = min(dp[i][j][x], dp[i-1][j][x-1] + 1);

				if (i >= 2) {

					dp[i][j][x] = min(dp[i][j][x], dp[i-2][j][x] + 1);

				}

				if (j >= 2) {

					dp[i][j][x] = min(dp[i][j][x], dp[i][j-2][x] + 1);

				}

				if (x >= 2) {

					dp[i][j][x] = min(dp[i][j][x], dp[i][j][x-2] + 1);

				}

				if (i == j && j == x)

					res = min(res, dp[i][j][x]);

			}

	cout << res;

}


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



using namespace std;



#define int long long



int a[3];

int ans;



int32_t main() {

    cin >> a[0] >> a[1] >> a[2];

    sort(a, a + 3);

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

    return cout << (ans % 2 ? ans / 2 + 2 : ans / 2), 0;

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

using namespace std;

const int MAXn = 50 + 5, INF = 1e9;

int dp[MAXn][MAXn][MAXn], a, b, c, res = INF;



int main() {

	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

	cin >> a >> b >> c;

	if (a == b && b == c)

		return cout << 0,0;

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

		for (int j = 0; j < MAXn; j++)

			for (int x = 0; x < MAXn; x++)

				dp[i][j][x] = INF;

	dp[a][b][c] = 0;

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

		for (int j = 1; j < MAXn; j++)

			for (int x = 1; x < MAXn; x++) {

				dp[i][j][x] = min(dp[i][j][x], dp[i-1][j-1][x] + 1);

				dp[i][j][x] = min(dp[i][j][x], dp[i][j-1][x-1] + 1);

				dp[i][j][x] = min(dp[i][j][x], dp[i-1][j][x-1] + 1);

				if (i >= 2) {

					dp[i][j][x] = min(dp[i][j][x], dp[i-2][j][x] + 1);

				}

				if (j >= 2) {

					dp[i][j][x] = min(dp[i][j][x], dp[i][j-2][x] + 1);

				}

				if (x >= 2) {

					dp[i][j][x] = min(dp[i][j][x], dp[i][j][x-2] + 1);

				}

				if (i == j && j == x)

					res = min(res, dp[i][j][x]);

			}

	cout << res;

}


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

using namespace std;



int a, b, c;



int main(){

	ios::sync_with_stdio(false);

	cin.tie(0);cout.tie(0);

	

	cin >> a >> b >> c;

	if(c < a)

		swap(a, c);

	if(c < b)

		swap(b, c);

	if(b < a)

		swap(a, b);

	

	int t = (c - b);

	a += t;

	if((c - a) % 2 == 0)

		cout << t + (c - a) / 2;

	else

		cout << 1 + t + (c + 1 - a) / 2;	

	

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

using namespace std;

const int MAXn = 50 + 5, INF = 1e9;

int dp[MAXn][MAXn][MAXn], a, b, c, res = INF;



int main() {

	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

	cin >> a >> b >> c;

	if (a == b && b == c)

		return cout << 0,0;

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

		for (int j = 0; j < MAXn; j++)

			for (int x = 0; x < MAXn; x++)

				dp[i][j][x] = INF;

	dp[a][b][c] = 0;

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

		for (int j = 1; j < MAXn; j++)

			for (int x = 1; x < MAXn; x++) {

				dp[i][j][x] = min(dp[i][j][x], dp[i-1][j-1][x] + 1);

				dp[i][j][x] = min(dp[i][j][x], dp[i][j-1][x-1] + 1);

				dp[i][j][x] = min(dp[i][j][x], dp[i-1][j][x-1] + 1);

				if (i >= 2) {

					dp[i][j][x] = min(dp[i][j][x], dp[i-2][j][x] + 1);

				}

				if (j >= 2) {

					dp[i][j][x] = min(dp[i][j][x], dp[i][j-2][x] + 1);

				}

				if (x >= 2) {

					dp[i][j][x] = min(dp[i][j][x], dp[i][j][x-2] + 1);

				}

				if (i == j && j == x)

					res = min(res, dp[i][j][x]);

			}

	cout << res;

}


// Faster C++ solution for the same problem (measured speedup: 2.9966262429940462x):
//بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ

#include <bits/stdc++.h>

using namespace std;

int main(){

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    int a, b, c;

    cin >> a >> b >> c;

    int x = max(max(a, b), c);

    int s = (x - a) + (x - b) + (x - c);

    if(s % 2) cout << (s + 3)/2;

    else cout << s/2;

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

using namespace std;

const int MAXn = 50 + 5, INF = 1e9;

int dp[MAXn][MAXn][MAXn], a, b, c, res = INF;



int main() {

	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

	cin >> a >> b >> c;

	if (a == b && b == c)

		return cout << 0,0;

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

		for (int j = 0; j < MAXn; j++)

			for (int x = 0; x < MAXn; x++)

				dp[i][j][x] = INF;

	dp[a][b][c] = 0;

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

		for (int j = 1; j < MAXn; j++)

			for (int x = 1; x < MAXn; x++) {

				dp[i][j][x] = min(dp[i][j][x], dp[i-1][j-1][x] + 1);

				dp[i][j][x] = min(dp[i][j][x], dp[i][j-1][x-1] + 1);

				dp[i][j][x] = min(dp[i][j][x], dp[i-1][j][x-1] + 1);

				if (i >= 2) {

					dp[i][j][x] = min(dp[i][j][x], dp[i-2][j][x] + 1);

				}

				if (j >= 2) {

					dp[i][j][x] = min(dp[i][j][x], dp[i][j-2][x] + 1);

				}

				if (x >= 2) {

					dp[i][j][x] = min(dp[i][j][x], dp[i][j][x-2] + 1);

				}

				if (i == j && j == x)

					res = min(res, dp[i][j][x]);

			}

	cout << res;

}


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

using namespace std;

int main()

{

    int i,s[3],su=0;

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

        cin>>s[i];

    sort(s,s+3);

    if(s[0]==s[1]&&s[0]==s[2])

        cout<<"0"<<endl;

    else

    {

        su=s[2]-s[1];

        s[0]+=su;

        s[1]+=su;

        if((s[1]-s[0])%2==0)

            cout<<su+(s[1]-s[0])/2<<endl;

        else cout<<su+(s[1]-s[0])/2+2<<endl;

    }

    return 0;

}