Problem:
Score : 300 points

Problem Statement

You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order:

Choose two among A, B and C, then increase both by 1.

Choose one among A, B and C, then increase it by 2.

It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.

Constraints

0 \leq A,B,C \leq 50

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B C

Output

Print the minimum number of operations required to make A, B and C all equal.

Sample Input 1

2 5 4

Sample Output 1

2

We can make A, B and C all equal by the following operations:

Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.

Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.

Sample Input 2

2 6 3

Sample Output 2

5

Sample Input 3

31 41 5

Sample Output 3

23

Solution in C (GCC 5.4.1) (judge verdict: Accepted)



#pragma warning(disable:4996)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define MAX_STRING 500

int compar(const int *val1, const int *val2);

int main() {
	char sInput[MAX_STRING+1]="";
	char* psInput;

	int i=0;
	int nX[3];
	int nA=0;
	int nB=0;
	int nC=0;
	int nHands=0;
	int nMax=0;

	// read line 1
	gets(sInput);
	psInput = strtok(sInput," ");
	nX[0] = atoi(psInput);
	psInput = strtok(NULL," ");
	nX[1] = atoi(psInput);
	psInput = strtok(NULL," ");
	nX[2] = atoi(psInput);

	// sort
    qsort(nX, 3, sizeof(int),
        (int (*)(const void *, const void *))compar
    );
//		printf("%d,%d,%d\n",nX[0],nX[1],nX[2]);

	while (nX[0]!=nX[2] || nX[1]!=nX[2]){
		if(nX[0]<nX[2]&&nX[1]<nX[2]){
			nX[0]=nX[0]+1;
			nX[1]=nX[1]+1;
			nHands++;
		} else if (nX[0]<nX[2]&&nX[1]==nX[2]) {
			nX[0]=nX[0]+2;
			nHands++;
		} else if (nX[0]>nX[2]&&nX[0]>nX[2]) {
			nX[1]=nX[1]+1;
			nX[2]=nX[2]+1;
			nHands++;
		}
	}


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

    return 0;
}
int compar(const int *val1, const int *val2) {
    if ( *val1 < *val2 ) {
        return -1;
    } else if ( *val1 == * val2 ) {
        return 0;
    } else {
        return 1;
    }
}