Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1,  - 1)], [( - 1,  - 1), (2,  - 1)], [(2,  - 1), (2, 2)] and so on. Thus, this infinite spiral passes through each integer point of the plane.Valera the horse lives on the plane at coordinates (0, 0). He wants to walk along the spiral to point (x, y). Valera the horse has four legs, so he finds turning very difficult. Count how many times he will have to turn if he goes along a spiral from point (0, 0) to point (x, y).

The first line contains two space-separated integers x and y (|x|, |y| ≤ 100).

Print a single integer, showing how many times Valera has to turn.

#include <stdio.h>
int f(int x){return x<0?-x:x;}
int main() {
    int x, y, mayor;
    scanf("%d%d",&x,&y);
    if ((x == 0 && y == 0) || (x == 1 && y == 0))
        printf("0\n");
    else {
        mayor = (f(x) > f(y) ? f(x) : f(y))*4;
        if( x>y || (x>0 && y>0 && x==y)){
            if(x>y && f(x)<=f(y) )
                printf("%d\n",mayor);
            else if( x>0 && y<0 && f(x)-f(y)==1 )
                printf("%d\n",mayor-4);
            else
                printf("%d\n",mayor-3);
        }else if( x<y && f(x)<=f(y))
            printf("%d\n",mayor-2);
        else
            printf("%d\n",mayor-1);
    }
    return 0;
}

#include <stdio.h>

int good(int a, int b, int c) {
	if (b > c) {
		int tmp;

		tmp = b;
		b = c;
		c = tmp;
	}
	return a >= b && a <= c;
}

int main() {
	static int xx[401], yy[401];
	int x, y, i, a, b, c, d, e;

	scanf("%d%d", &x, &y);
	a = b = 0;
	c = d = e = 1;
	for (i = 0; i < 401; i++) {
		xx[i] = a;
		yy[i] = b;
		if (c)
			if (d)
				a += e;
			else
				a -= e;
		else
			if (d)
				b += e, e++, d = 0;
			else
				b -= e, e++, d = 1;
		c = !c;
	}
	for (i = 0; i + 1 < 401 && (xx[i] != x || !good(y, yy[i], yy[i + 1])) && (yy[i] != y || !good(x, xx[i], xx[i + 1])); i++)
		;
	printf("%d\n", i);
	return 0;
}

#include<stdio.h>
#include<stdbool.h>

int plus[4][2]={{1, 0},{0, 1},{-1,0},{0,-1}};
bool v[300][300];

bool visited(int x, int y){
	if(v[x+150][y+150]) return true;
	v[x+150][y+150]=true;
	return false;
}

int main(){
	int ex, ey, num=0, dir=0, x=1, y=0;
	scanf("%d %d", &ex, &ey);
	if(ex==0 && ey==0){
		puts("0");
		return 0;
	}
	visited(0, 0);
	while(!(x==ex && y==ey)){
		visited(x, y);
		if(visited(x+plus[(dir+1)%4][0], y+plus[(dir+1)%4][1])){
			x+=plus[dir][0]; y+=plus[dir][1];
		}
		else{
			dir=(dir+1)%4; ++num;
			x+=plus[dir][0]; y+=plus[dir][1];
		}
	}
	printf("%d\n", num);
	return 0;
}

#include <stdio.h>
#include <string.h>
int max(int a,int b){
	return a>b?a:b;
}
int min(int a,int b){
	return a<b?a:b;
}
int main(){
	int x,y,xx=0,xn=0,yx=0,yn=0,t=0;
	int a=0,b=0;
	scanf("%d %d",&x,&y);
	for(;;t++){
		switch(t%4){
			case 0:
				if(++xx>=x&&a<=x&&b==y)
				goto end;
				a=xx;
				break;
			case 1:
				if(++yx>=y&&b<=y&&a==x)
				goto end;
				b=yx;
				break;
			case 2:
				if(--xn<=x&&a>=x&&b==y)
				goto end;
				a=xn;
				break;
			case 3:
				if(--yn<=y&&b>=y&&a==x)
				goto end;
				b=yn;
				break;
		}
	}
	end:
	printf("%d",t);
}

/*
#include <stdio.h>
#include <stdlib.h>
int min(int a, int b) {

    return (a > b) ? b : a;

}

int main() {

    int n, m, a, b;

    scanf("%d %d %d %d", &n, &m, &a, &b);
    int price = 0;

    int c=a*m;
    int d, e, f, g, h, k, l;
    if(c<b||c==b) printf("%d",a*n);
    else if(c>b){
        if(n%m==0) printf("%d", b*(n/m));
        else if(n%m!=0){
            d=n/m+1;
            e=d*b;

            f=n%m;
            g=f*a;
            h=n/m;
            k=h*b;
            l=g+k;
            printf("%d",min(e,l));
        }
    }

    return 0;
}
*/
/*
#include <stdio.h>
#include <stdlib.h>

int main() {

    int sum;
    scanf("%d", &sum);

    if (sum >= 0) {
        printf("%d",sum);
    } else {
        int a = -sum/10%10;
        int b = -sum%10;
        printf("%d",a > b ? sum/100*10-b : sum/10);
    }

    return 0;

}*/
/*
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main() {

    int x1, y1, x2, y2;

    scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
    if(abs(x1-x2)==abs(y1-y2))
        printf("%d %d %d %d", x1, y2, x2, y1);
    else if(x1 == x2 || y1 == y2) {

        float l = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));

        if(x1==x2) {
            printf("%d %d %d %d", x1+(int)l, y1, x1+(int)l, y2);
        } else
            printf("%d %d %d %d", x1, y1+(int)l, x2, y2+(int)l);
    } else
    printf("-1");

    return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

void sort(int** matrix, int n) {

    int done = 0;

    while(!done) {

        done = 1;

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

            if((float) matrix[i][1] / matrix[i][0] < (float) matrix[i + 1][1] / matrix[i + 1][0]) {

                int aux1 = matrix[i][0];
                int aux2 = matrix[i][1];

                matrix[i][0] = matrix[i + 1][0];
                matrix[i][1] = matrix[i + 1][1];

                matrix[i + 1][0] = aux1;
                matrix[i + 1][1] = aux2;

                done = 0;

            }
        }
    }
}

int main() {

    int n, strength;

    scanf("%d %d", &strength, &n);

    int** matrix = (int**)malloc(sizeof(int*) * n);

    for(int i = 0; i < n; i++)
        matrix[i] = (int*)malloc(4 * 2);

    for(int i = 0; i < n; i++)
        scanf("%d %d", &matrix[i][0], &matrix[i][1]);

    sort(matrix, n);

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

            if(strength > matrix[i][0] && matrix[i][0] != -1) {

                strength += matrix[i][1];
                matrix[i][0] = -1;

            }
        }

    int finish = 0;

    for(int i = 0; i < n; i++)
        if(matrix[i][0] != -1)
            finish = 1;

    if(!finish)
        printf("YES");
    else
        printf("NO");
    return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main() {

    int n, m;

    scanf("%d %d", &n, &m);

    int cnt = (n + 1) / 2;
    int ans = (cnt  + m - 1) / m * m;

    if (ans > n) {
        ans = -1;
    }
    printf("%d", ans);

return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int min(int a, int b) {

    return (a > b) ? b : a;

}

int main() {

    int n;
    scanf("%d", &n);

    int array[n + 1];

    int m1 = 0, m2 = 0, m3 = 0;

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

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

        switch(array[i]) {

        case 1:
            m1++;
            break;

        case 2:
            m2++;
            break;

        case 3:
            m3++;
            break;

        }
    }
    int minim = min(m1, m2);
    minim = min(minim, m3);

    int aux[4];
    int k = 0;

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

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

        k=1;

        for(int j = 1; k < 4; j++) {

            if(j == n + 1)
                j = 1;

            if(array[j] == k) {

                aux[k++] = j;
                array[j] = -1;

            }
        }

        for(int j = 1; j < k; j++)
            printf("%d ", aux[j]);
        printf("\n");

    }
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

void sort(int n, int array[n]) {

    int done = 0;

    while(!done) {

        done = 1;

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

            if(array[i] > array[i + 1]) {

                int aux = array[i];
                array[i] = array[i + 1];
                array[i + 1] = aux;
                done = 0;

            }
        }
    }
}
int main() {

    int n, d;
    scanf("%d %d", &n, &d);

    int array[n];
    int sum = 0;
    for(int i = 0; i < n; i++) {

        scanf("%d", &array[i]);
        sum += array[i];

    }

    sum += 10 * (n - 1);

    if(sum > d)
        printf("-1");
    else {

        //sort(n, array);

        int ct = 2 * (n - 1);
        while(sum + 5 <= d) {

            ct++;
            sum+=5;

        }
        printf("%d", ct);

    }

    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main() {

    int n, m;
    scanf("%d %d", &n, &m);

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

        if(i % 2 == 1)
            if(first == 1) {

                printf("#");
                first = 0;

            }
        for(int j = 0; j < m - i % 2; j++) {

            if(i % 2 == 0) {

                printf("#");

            } else
                printf(".");

        }

        if(i % 2 == 1)
            if(last == 1) {

                first = 1;
                printf("#");
                last = 0;

            }

        if(first == 0)
            last = 1;
        printf("\n");
    }

    return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main() {

    int n;
    scanf("%d", &n);

    int nr;

    int odd = 0;
    int even = 0;
    int pos1 = -1;
    int pos2 = -1;

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

        scanf("%d", &nr);
        if(nr % 2 == 0) {

            even++;
            pos1 = i + 1;

        } else {

            odd ++;
            pos2 = i + 1;

        }
    }

    if(odd == 1)
        printf("%d", pos2);
    else
        printf("%d", pos1);
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

void sort(int* array, int size) {

    int done = 0;

    while(!done) {

        done = 1;
        for(int i = 0; i < size - 1; i++)
            if(array[i] > array[i + 1]) {

                int aux = array[i];
                array[i] = array[i + 1];
                array[i + 1] = aux;
                done = 0;

            }
    }
}

int main() {

    int n, v;
    scanf("%d %d", &n, &v);

    int* array = (int*)malloc(sizeof(int) * 50);
    int k;
    int* deals = (int*)malloc(sizeof(int) * 50);
    int sizeDeals = 0;
    int done;
    for(int i = 0; i < n; i++) {

        scanf("%d", &k);
        done = 0;
        for(int j = 0; j < k; j++) {

            scanf("%d", &array[j]);
            if(array[j] < v)
                done = 1;

        }

        if(done)
            deals[sizeDeals++] = i + 1;
        done = 0;

    }

    if(sizeDeals != 0) {

        sort(deals, sizeDeals);
        printf("%d\n", sizeDeals);
        for(int i = 0; i < sizeDeals; i++)
            printf("%d ", deals[i]);

    } else
        printf("0");
    return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main() {

    int n;

    scanf("%d", &n);

    char* string = malloc(101);
    char* string1 = malloc(10000);
    char* string2 = malloc(10000);

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

        gets(string);
        strcat(string1, string);

    }

    strcpy(string2, string1);
    strrev(string2);

    if(strncmp(string1 + 1, string2, strlen(string2) - 2) == 0)
        printf("YES");
    else
        printf("NO");

    return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main() {

    int n, k;

    scanf("%d %d", &n, &k);
    int maximum = (-1) * (1 << 31);

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

        int fi, ti;

        scanf("%d %d", &fi, &ti);

        if(k >= ti) {

            if(fi > maximum)
                maximum = fi;

        } else {

            if((fi - (ti - k)) > maximum)
                maximum = fi - (ti - k);

        }

    }

    printf("%d", maximum);

    return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main() {

    int n;
    scanf("%d", &n);

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

        int price, quality;
        scanf("%d %d", &price, &quality);

        if(price != quality) {

            printf("Happy Alex");
            return 0;
        }
    }

    printf("Poor Alex");

    return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main() {

    int friends, bottles, milliliters, limes, slices, salt, nl, np;
    scanf("%d %d %d %d %d %d %d %d", &friends, &bottles, &milliliters, &limes, &slices, &salt, &nl, &np);

    int allMilliliters = bottles * milliliters / nl / friends;
    int allSalt = salt / np / friends;
    int allLimes = limes * slices / friends;

    int minim = -1;

    minim = (allLimes < allMilliliters) ? allLimes : allMilliliters;
    minim = (minim < allSalt) ? minim : allSalt;

    printf("%d", minim);
    return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main() {

    int dice1, dice2;
    scanf("%d %d", &dice1, &dice2);

    int dice1Wins = 0;
    int draw = 0;
    int dice2Wins = 0;

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

        if(abs(dice1 - i) > abs(dice2 - i))
            dice2Wins++;
        else if(abs(dice1 - i) < abs(dice2 - i))
            dice1Wins++;
        else
            draw++;

    }

    printf("%d %d %d", dice1Wins, draw, dice2Wins);

    return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main() {

    int n;
    scanf("%d", &n);
    int* array = (int*)malloc(n * 4);
    int minimum = (1 << 28);
    int pos;
    for(int i = 0; i < n; i++) {

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

        if(i > 1) {

            if(array[i] - array[i - 2] < minimum) {

                minimum = array[i] - array[i - 2];
                pos = i - 1;

            }
        }
    }

    minimum = -999999;
    for(int i = 0 ; i < n - 1; i++) {

        if(i + 1 == pos) {
            if(array[i + 2] - array[i] > minimum) {

                minimum = array[i + 2] - array[i];
                i++;

            }
        } else {

            if(array[i + 1] - array[i] > minimum) {

                minimum = array[i + 1] - array[i];

            }

        }
    }

    printf("%d", minimum);
    return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main() {

    int n;
    scanf("%d", &n);
    int* exercises = (int*)malloc(sizeof(int) * (n + 1));

    int chest = 0;
    int biceps = 0;
    int back = 0;

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

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

        switch(i % 3){

        case 0:
            chest += exercises[i];
            break;

        case 1:
            biceps += exercises[i];
            break;

        case 2:
            back += exercises[i];
            break;

        }
    }

    if(chest > back && chest > biceps)
        printf("chest");
    else if(back > chest && back > biceps)
        printf("back");
    else
        printf("biceps");
    return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int cmmdc(int a, int b) {

    int r;

    while(b != 0) {

        r = a % b;
        a = b;
        b = r;

    }

    return a;
}

int main() {

    long int l, r;

    scanf("%ld %ld", &l, &r);
    printf("%d", sizeof(long int));
    if(r - (l += l%2) < 2)
        printf("-1");
    else
        printf("%d %d %d", l, l + 1, l + 2);
    return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main() {

    int n;
    scanf("%d", &n);

    char matrix[n][n];

    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            scanf("%c", &matrix[i][j]);

    char diagonal = matrix[0][0];

    for(int i = 0; i < n; i++)
        if(matrix[i][i] != diagonal) {

            printf("NO");
            return 0;

        }
    printf("aaa");
    for(int i = n; i >= 0; i--)
        if(matrix[i][n - i] != diagonal) {

            printf("NO");
            return 0;

        }
    printf("aaa");

    char notDiag = matrix[0][1];

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

            if(i == j || i + j == n -1)
                j++;
            else {

                if(matrix[i][j] != notDiag) {

                    printf("NO");
                    return 0;

                }
            }
        }

    printf("YES");
    return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main() {

    int n, m;
    scanf("%d %d", &n, &m);

    char** matrix = (char**)malloc(sizeof(char*) * n);
    for(int i = 0; i < n; i++)
        matrix[i] = malloc(m);

    getchar();

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

        gets(matrix[i]);
        for(int j = 0; j < m; j++)
            if(matrix[i][j] == '.') {
                if((i + j) % 2 == 0)
                    matrix[i][j] = 'B';
                else
                    matrix[i][j] = 'W';

            }

    }

    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++)
            printf("%c", matrix[i][j]);
        printf("\n");

    }
    return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <limits.h>

int freq1[27], freq2[27];

int main() {

    int n;
    scanf("%d", &n);
    getchar();
    char* question = malloc(15);

    int left = INT_MIN / 2;
    int right = INT_MAX / 2;

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

        gets(question);

            if(question[0] == '>' && question[strlen(question) - 1] == 'Y' ||
               (question[0] == '<' && question[strlen(question) - 1] == 'N')) { /// > or >=

                if(question[1] == '=') {

                    char* tok = strtok(question, " ");
                    tok = strtok(NULL, " ");
                    left = atoi(tok) + 1;

                } else {

                    char* tok = strtok(question, " ");
                    tok = strtok(NULL, " ");
                    left = atoi(tok);

                }
            } else if(question[0] == '<' && question[strlen(question) - 1] == 'Y' || (question[0] == '>' && question[strlen(question) - 1] == 'N')) {

                if(question[1] == '=') { /// <=

                    char* tok = strtok(question, " ");
                    tok = strtok(NULL, " ");
                    right = atoi(tok);

                } else {

                    char* tok = strtok(question, " ");
                    tok = strtok(NULL, " ");
                    right = atoi(tok) - 1;

                }
            }

        if(question[0] == '>' && question[1] == '=' && question[strlen(question) -1 ] == 'Y' ||
                (question[0] == '<' && question[1] != '=' && question[strlen(question) - 1] == 'N')) {

            char* tok = strtok(question, " ");
            tok = strtok(NULL, " ");
            if(atoi(tok) > left)
                left = atoi(tok);

        } else if(question[0] == '>' && question[1] != '=' && question[strlen(question) - 1] == 'Y' ||
                  (question[0] == '<' && question[1] == '=' && question[strlen(question) - 1] == 'N')) {

            char* tok = strtok(question, " ");
            tok = strtok(NULL, " ");
            if(atoi(tok) + 1 > left)
                left = atoi(tok) + 1;

        } else if(question[0] == '<' && question[1] == '=' && question[strlen(question) - 1] == 'Y' ||
                  (question[0] == '>' && question[1] != '=' && question[strlen(question) - 1] == 'N')) {

            char* tok = strtok(question, " ");
            tok = strtok(NULL, " ");
            if(atoi(tok) < right)
                right = atoi(tok);

        } else if(question[0] == '<' && question[1] != '=' && question[strlen(question) - 1] == 'Y' ||
                  (question[0] == '>' && question[1] == '=' && question[strlen(question) - 1] == 'N')) {

            char* tok = strtok(question, " ");
            tok = strtok(NULL, " ");
            if(atoi(tok) - 1 < right)
                right = atoi(tok) - 1;

        }
    }

    if(left <= right) {

        printf("%d", right);

    } else
        printf("Impossible");
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <limits.h>

void mergeSort(int left, int mid, int right, int* array, int n) {

    int*aux = (int*)malloc(sizeof(int) * n);

    int i = left;
    int j = mid + 1;
    int index = i;

    while(i <= mid && j <= right) {

        if(array[i] > array[j]) {

            aux[index++] = array[i++];

        } else {

            aux[index++] = array[j++];

        }

    }

    for(int l = i; l <= mid; l++)
        aux[index++] = array[l];

    for(int l = j; l <= right; l++)
        aux[index++] = array[l];

    for(int l = left; l <= right; l++)
        array[l] = aux[l];

}

void merge(int left, int right, int* array, int n) {

    int mid;

    if(left < right) {

        mid = (left + right) / 2;
        merge(left, mid, array, n);
        merge(mid + 1, right, array, n);
        mergeSort(left, mid, right, array, n);

    }
}

int main() {

    int devices, sockets, supply;

    scanf("%d %d %d", &supply, &devices, &sockets);
    int array[supply];

    for(int i = 0; i < supply; i++)
        scanf("%d", &array[i]);

    merge(0, supply - 1, array, supply);

    if(devices <= sockets)
        printf("0");
    else {

        int i = 0;
        while(sockets < devices && i < supply) {

            sockets += array[i] - 1;
            i++;

        }

        if(i != supply)
            printf("%d", i);
        else if(sockets >= devices)
            printf("%d", i);
        else
            printf("-1");
    }
    return 0;

} */

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <limits.h>

int main() {

    int x, y;
    scanf("%d %d", &x, &y);
    int s = 0;
    if(y>x && x>=-y)s=-2+y*4;
    if(y<x && x<=-y+1)s=-y*4;
    if(y<=x && x>-y+1)s=-3+x*4;
    if(y>=x && x<-y)s=-1-4*x;

    printf("%d", s);

    return 0;

}

#include <stdio.h>
#include <stdlib.h>
/* Written by Nishant Mittal aka nishantwrp */
int check(int x,int y) {
if ((x>=0) && y>0 ) {
    return 1;
} else if ((x<0) && y>=0) {
return 2;
} else if(y<0 && x<=0){
return 3;
} else if (x>0 &&y<=0) {
return 4;
}
return 0;
}
int main()
{
    int x,y;
    scanf("%d %d",&x,&y);
    if (x==0&&y==0) {
        printf("0");
    } else {
    if (check(x,y) == 1) {
        if (x>=y) {
        printf("%d",1+(x-1)*4);
        } else {
            printf("%d",2+(y-1)*4);
        }
    } else if (check(x,y) == 2) {
    x = -1*x;
    if (y>=x) {
    printf("%d",2+(y-1)*4);
    } else {
    printf("%d",3+(x-1)*4);
    }
    } else if (check(x,y) == 3) {
    x = -1*x;
    y = -1*y;
    if (x>=y) {
    printf("%d",3+(x-1)*4);
    } else {
    printf("%d",4*y);
    }
    } else {
    x = x-1;
    y = y*-1;
    if (y>=x) {
    printf("%d",4*y);
    }else {
    printf("%d",5+(x-1)*4);
    }
    }
    }
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
    char ch;
    char* input = (char*)malloc(10);
    int i = 0;
    int on_y = 0;
    int neg_x = 0;
    int neg_y = 0;
    while(read(0, &ch, 1) > 0)
    {
        if(ch != '-')
        {
            input[i] = ch;
            i++;
            if(ch == ' ')
            {
                on_y = 1;
            }
        }
        else if(on_y)
        {
            neg_y = 1;
        }
        else
        {
            neg_x = 1;
        }
    }
    input[i] = '\0';
    int x = strtol(input, &input, 10);
    if(neg_x)
    {
        x *= -1;
    }
    while(*input != ' ')
    {
        input++;
    }
    int y = strtol(input, &input, 10);
    if(neg_y)
    {
        y *= -1;
    }
    if(x < 0 && x <= y && y < -1 * x)
    {
        printf("%d",4 * (-1*x - 1) + 3);
    }
    else if(x > 0 && -x + 1 < y && y <= x)
    {
        printf("%d",4*(x-1) + 1);
    }
    else if(y > 0 && -1 * y <= x && x < y)
    {
        printf("%d", 4 * (y - 1) + 2);
    }
    else if((x <= 1 && y == 0) || (y < 0 && y < x && x <= -1*y + 1))
    {
        printf("%d", -4 * y);
    }
    return 0;

}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int x,y,result;
    scanf("%d %d",&x,&y);
    if(x==0 && y==0)result=0;
    else if(x==1 && y==0)result=0;
    else if(x==0 && y==1)result=2;
    else if(x==0 && y==-1)result=4;
    else if(x==-1 && y==0)result=3;
    else if(x>=0 && y>=0)
    {
        if(x<y)
        result=(3*y)+(y-2);
        else
            result=(3*x)+(x-3);
    }
    else if(x<0 && y<0)
    {
        if(abs(x)<abs(y))
            result=4*abs(y);
        else
            result=(3*abs(x))+(abs(x)-1);
    }
    else if(x>=0 && y<0)
    {
        if(x>abs(y))
        {
            if(x-abs(y)==1)
            result=(4*abs(y));
            else
               result=(3*x)+(x-3);
        }
        else result=(4*abs(y));
    }
    else if(x<0 && y>=0)
    {
        if(abs(x)>y)
            result=(3*abs(x))+(abs(x)-1);
        else result=(3*y)+(y-2);
    }
    printf("%d",result);
    return 0;
}

#include <stdio.h>

int numTurns(int x, int y) {
    int c = abs(x)+abs(y);
    //Detect whether the point lies on a bottom, top, left, or right segment
    if (x > 0 && y >= 2-x && y<= x) {
        return x*4-3;
    }
    if (x < 0 && y >= x && y<= -1-x) {
        return (-x)*4-1;
    }
    if (y > 0 && x >= -y && x <= y-1) {
        return y*4-2;
    }
    if (y <= 0 && x>= 1+y && x <= 1-y) {
        return y*(-4);
    }
    else {
        return 0;
    }
}

int main() {
   int x, y;
   scanf("%d %d", &x, &y);
   int n = numTurns(x, y);
   printf("%d", n);
   return 0;
}

#include <stdio.h>

typedef struct
{
	int x,y;
}Point_t ;
Point_t Now;

int main()
{
	int x,y,add,Res;
	scanf("%d %d",&x,&y);
	add=1;
	Now.x=Now.y=0;
	while(add)
	{
		if(add&1)
		{
			if(y==Now.y&&x>=Now.x&&x<=Now.x+add)
			{
				Res=((add-1)<<1)+1;
				break;
			}
			Now.x+=add;
			if(x==Now.x&&y>=Now.y&&y<=Now.y+add)
			{
				Res=add<<1;
				break;
			}
			Now.y+=add;
		}
		else
		{
			if(y==Now.y&&x>=Now.x-add&&x<=Now.x)
			{
				Res=((add-1)<<1)+1;
				break;
			}
			Now.x-=add;
			if(x==Now.x&&y>=Now.y-add&&y<=Now.y)
			{
				Res=add<<1;
				break;
			}
			Now.y-=add;
		}
		++add;
	}
	printf("%d\n",Res-1);
	return 0;
}

#include <stdio.h>
#define Change {cost[0] = cote[0]; cost[1] = cote[1];}
#define X cost[0] == coen[0]
#define Y cost[1] == coen[1]
int main(){
    int turn = -1, add = 1;
    int coen[2], cost[2], cote[2] = {0, 0};
    scanf("%d%d", coen+0, coen+1);
    for(;;){
        Change
        cote[0] += add;
        turn++;
        if(coen[0] <= cote[0] && cost[0] <= coen[0] && Y)
            break;
        Change
        cote[1] += add;
        turn++; add++;
        if(coen[1] <= cote[1] && cost[1] <= coen[1] && X)
            break;
        Change
        cote[0] -= add;
        turn++;
        if(coen[0] >= cote[0] && cost[0] >= coen[0] && Y)
            break;
        Change
        cote[1] -= add;
        turn++; add++;
        if(coen[1] >= cote[1] && cost[1] >= coen[1] && X)
            break;
    }
    printf("%d\n", turn);
	return 0;
}

/*
      when turn is even move x else move y.
      common = 0 when x coordinate is common
      common = 1 when y coordinate is common
      whenever x or y ka value increase its value of mod increase by 1 and its sign reverses...
      this means while we consider the x and y axis the coordinate will change halve of mod value...
*/

#include <stdio.h>
#include <math.h>

int main()
{
      int xin, yin, xold=0, yold=0, xnew=0, ynew=0, turn=-1, common, modx=0, mody=0;
      int signx=0, signy=0;
      scanf("%d %d", &xin, &yin);

      while(1)
      {
            turn++;
            if(turn%2 == 0)
            {
                  xold = xnew;
                  yold = ynew;
                  modx++;
                  if(signx%2==0)
                  {
                        xnew = ceil((double)modx/2);
                  }
                  else
                  {
                        xnew = -1*ceil((double)modx/2);
                  }
                  common = 1;
                  signx++;
            }
            else
            {
                  xold = xnew;
                  yold = ynew;
                  mody++;
                  if(signy%2==0)
                  {
                        ynew = ceil((double)mody/2);
                  }
                  else
                  {
                        ynew = -1*ceil((double)mody/2);
                  }
                  signy++;
                  common = 0;
            }

            if(common == 1)
            {
                  if(yold == yin)
                  {
                        if((xold <= xin && xnew >= xin) || (xold >= xin && xnew <= xin))
                        {
                              printf("%d\n",turn);
                              break;
                        }
                  }
            }

            else if(common == 0)
            {
                  if(xold == xin)
                  {
                        if((yold <= yin && ynew >= yin) || (yold >= yin && ynew <= yin))
                        {
                              printf("%d\n",turn);
                              break;
                        }
                  }
            }

     //       printf("%3d %3d %3d %3d %3d %3d %3d %3d\n", turn, xold, yold, xnew, ynew, modx, mody, common);
      }

      return 0;
}

#include<stdio.h>

inline int abs(int a) { return a < 0 ? -a : a; }

int main() {
	int x, y, cnt = 0;
	scanf("%d%d", &x, &y);

	/** Find last corner before (x, y)
	Forms of corners:
		1) (x, y)
		2) (-x, y)
		3) (-x, -y)
		4) (x + 1, -x)
	**/

	if(y == 0 && x <= 1 && x >= 0)
		cnt = 0; // lol
	else if((-y == x && y > 0) || (y > 0 && abs(x) <= y && !(x == y && x > 0))) // Last Type (1) [Or current = Type (2)]
		cnt = 4 * y - 2;
	else if((y == x && x < 0) || (x < 0 && abs(y) <= -x && !(-y == x && y > 0))) // Last Type (2) [Or current = Type (3)]
		cnt = 4 * (-x) - 1;
	else if((-y + 1 == x && y < 0) || (y < 0 && abs(x) <= -y && !(y == x && x < 0))) // Last Type (3) [Or current = Type (4)]
		cnt = 4 * (-y);
	else  // Last Type (4) [Or current = Type (1)]
		cnt = 4 * (x-1) + 1;

	printf("%d", cnt);
	return 0;
}

#include <stdio.h>
#include <stdlib.h>

int sgn (int x) {
	return x < 0 ? -1 : x == 0 ? 0 : 1;
}

int step (int *x, int *y) {
	static int dx = 1;
	static int dy = 0;
	int ret = 0;
	if (*y == 1 - *x && *x > 0) {
		dx = 0;
		dy = 1;
		ret = 1;
	} else if (*y == -*x && *x < 0) {
		dx = 0;
		dy = -1;
		ret = 1;
	} else if (*y == *x && *x != 0) {
		ret = 1;
		dx = -sgn (*x);
		dy = 0;
	}
	*x += dx;
	*y += dy;
	return ret;
}

int main (void) {
	int nturns = 0, x = 0, y = 0, x0, y0;
	scanf ("%d %d", &x0, &y0);
	while (!(x == x0 && y == y0)) {
		nturns += step (&x, &y);
	}
	printf ("%d\n", nturns);
	exit (EXIT_SUCCESS);
}

#include<stdio.h>

int maxNum(int x,int y)
{
	if(x<0)
		x=-1*x;
	if(y<0)
		y=-1*y;
	if(x<y)
		return y;
	else
		return x;
}
int isZhuan(int x,int y)
{
	if(x==0&&y==0||x==1&&y==0||x==y||x<0&&x==-1*y||y<0&&(x+y==1))
		return 1;
	else
		return 0;
}
int zhuanZ(int x,int y)
{
	int ans;
	if(x==0&&y==0)
    {
		ans=0;
	return ans;
	}
	if(x==1&&y==0)
	{
		ans=0;
	return ans;
	}
     if(x>0&&x==y)
	 {
		 ans=1+(x-1)*4;
	   	return ans;
	 }
			if(x<0&&x==y*-1)
			{
				ans=2+(y-1)*4;
				return ans;
			}
			if(x<0&&x==y)
			{
				ans=3+(-1*y-1)*4;
				return ans;
			}
			if(y<0&&(x+y==1))
			{
				ans=-4*y;
				return ans;
			}
}

int main()
{
	int x,y,ans=-1,flag=0;

	while(scanf("%d%d",&x,&y)!=EOF)
	{
		int temp;

		if(isZhuan(x,y))
		{
			ans=zhuanZ(x,y);
		}
		else
		{
			int bian=maxNum(x,y);
			if(x>0&&y>0)
			{
				temp=zhuanZ(bian,bian);
				if(x>y)
					ans=temp;
				else
					ans=temp+1;

			}

		 	if(x<0&&y>0)
			{
				temp=zhuanZ(-1*bian,bian);
				if(-1*x<y)
					ans=temp;
				else ans=temp+1;
			}
			if(x<0&&y<0)
			{
				temp=zhuanZ(-1*bian,-1*bian);
				if(x<y)
					ans=temp;
				else
					ans=temp+1;
			}
		if(x>0&&y<0)
			{
				temp=zhuanZ(bian+1,-1*bian);
				if(x<bian+1)
					ans=temp;
				else
					ans=temp+1;
			}
	     if(x==0)
		 {
			 ans=1+zhuanZ(y,y);
			 flag=1;
		 }
		   if(y==0&&x!=0)
		   {
			   if(x<0)
				   ans=1+zhuanZ(x,-1*x);
			   else
				   ans=1+zhuanZ(x,-1*(x-1));
		   }

		}
		printf("%d\n",ans);
	}
    return 0;
}

//+++++++++++++++++++++++++++++//
//      Karan Aggarwal         //
//       IIIT-Hyderabad        //
//+++++++++++++++++++++++++++++//
// Topic:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<limits.h>
#include<math.h>
#define si(n) scanf("%d",&n)
#define rep(i,n) for(i=0;i<n;i++)
#define REP(i,a,b) for(i=a;i<b;i++)
#define pn printf("\n")
#define pw printf(" ")
#define pi(n) printf("%d",n)
#define pll(n) printf("%lld",n)
#define sll(n) scanf("%lld",&n)
#define ss(s) scanf("%s",s)
#define ps(s) printf("%s",s)
typedef long long LL;
//inline int readint()
//{int n=0;char c;while(1){ c=getchar_unlocked();if(c=='\n'||c==' ')break;n=n*10+c-'0';}return n;}
int abs(int a){ if(a<0)return -1*a; return a;}
int big(int a,int b){if(a>b)return a;return b;}
int small(int a,int b){if(a<b)return a;return b;}
int compare(const void *a, const void *b)
{
    int *p1=(int*)a;
    int *p2=(int*)b;
    return *p1-*p2;
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
int main()
{
    int m,l,ans,sum,min,max,n,i,j,k,x,y,t;
    si(x);si(y);
    if(x==0 && y==0){pi(0);return 0;}
    int a=big(abs(x),abs(y));
    if((y==-a)&&(x>-a)){pi((a<<2)-0);return 0;}
    if((y<a)&&(x==-a)){pi((a<<2)-1);return 0;}
    if((y==a)&&(x<a)){pi((a<<2)-2);return 0;}
    if((y>(-a+1))&&(x==a)){pi((a<<2)-3);return 0;}
    if((y==(-a+1))&&(x==a)){pi((a<<2)-4);return 0;}
    return 0;
}

//In the name of God
#include <stdio.h>

int dx,dy;
int x,y;

int mv(int size,int d)
{
  d%=4;
  int ax=0,ay=0;
  switch(d)
    {
    case 0:
      ay=-1;
      break;
    case 1:
      ax=1;
      break;
    case 2:
      ay=1;
      break;
    default:
      ax=-1;
    }
  while(size--)
    {
      x+=ax; y+=ay;
      if(x==dx && y==dy)
	return 1;
    }
  return 0;
}

int main()
{
  scanf("%d%d",&dx,&dy);
  if(dx==0 && dy==0)
    {
      printf("0");
      return 0;
    }
  int step; int d=0; int size=1, rem=2;
  for(step=0;;step++)
    {
      d++;
      if(mv(size,d))
	{
	printf("%d\n",step);
	return 0;
	}
      rem--;
      if(rem==0)
	{
	  rem=2;
	  size++;
	}
    }
}

#include <stdio.h>
int main(int argc, char const *argv[])
{
	int x, y, turn = 0;
	scanf("%d %d", &x, &y);
	if (x >= -y && x < y)
	{
		turn = 4 * y - 2;
	}
	if (y >= x && y < -x)
	{
		turn = -4 * x - 1;
	}
	if (x > y && x <= -y + 1)
	{
		turn = -y * 4;
	}
	if (y > -x + 1 && y <= x)
	{
		turn = 4 * x - 3;
	}
	printf("%d", turn);
	return 0;
}

#include<stdio.h>
void quicksort(int a[],int lower,int upper)
{
	if(lower<upper)
	{
		int i=split(a,lower,upper);
		quicksort(a,lower,i-1);
		quicksort(a,i+1,upper);
	}
}
int split(int a[],int lower,int upper)
{
	int l=lower+1,u=upper,t,p=a[lower];
	while(l<=u)
	{
		while(a[l]<=p && l<=upper)
			l++;
		while(a[u]>=p && u>lower)
			u--;
//		printf("\nstopped at %d and %d",a[l],a[u]);
		if(l<u)
		{
		t=a[l];
		a[l]=a[u];
		a[u]=t;
		}
	}
	t=a[lower];
	a[lower]=a[u];
	a[u]=t;
	return u;
}
int main()
{
	int x,y;
	scanf(" %d %d",&x,&y);
	int ans=0;
	if(x==0 && y==0)
	{
		printf("0");
		return 0;
	}
	else if(y>0 &&  x>=-1*y && x<=y)
	{
		ans=2+4*(y-1);
		if(x==y)
			ans--;
	}
	else if(y<0 && x>=y && x<=-1*y+1)
	{
		ans=4+4*(-1*y-1);
		if(x==y)
			ans--;
	}
	else if(x>0 && y<=x && y>=-1*x+1)
	{
		ans=1+(4*(x-1));
			if(x==-1*y+1)
			ans--;
	}
	else if(x<0 && y>=x && y<=-1*x)
	{
		ans=3+(4*(-1*x-1));
			if(x==-y)
			ans--;
	}
	printf("%d",ans);
	return 0;
}

#include <stdio.h>
#define COND ( (!dir&&ty==y&&tx>=x) || (dir==1&&tx==x&&ty>=y) || (dir==2&&ty==y&&tx<=x) || (dir==3&&tx==x&&ty<=y) )
int x,y,tx,ty,step=0,turn=0,dir,t;
int main(){
	scanf("%d %d", &x, &y);
	if(x==0 && y==0){
		puts("0");
		return 0;
	}
	while(1){
		dir=0;
		t=COND;
		if(turn!=0){
			turn++;
		}
		step++;
		tx+=step;
		if(COND && !t){
			break;
		}

		dir++;
		t=COND;
		turn++;
		ty+=step;
		step*=-1;
		if(COND && !t){
			break;
		}

		dir++;
		t=COND;
		turn++;
		step--;
		tx+=step;
		if(COND && !t){
			break;
		}

		dir++;
		t=COND;
		turn++;
		ty+=step;
		step*=-1;
		if(COND && !t){
			break;
		}
	}
	printf("%d ", turn);
	return 0;
}

#include <stdio.h>
#include <string.h>
#include <math.h>
int main()
{
    int i,j,n,m,s,t,l;
    int x,y,xend,yend;
    while(scanf("%d %d",&xend,&yend)!=EOF)
    {
        x=y=0;
        if(xend==0&&yend==0)
        {
            printf("0\n");
            continue;
        }
        s=0;
        l=1;
        while(1)
        {
            for(i=1;i<=l;i++)
            {
                x+=1;
                if(x==xend&&y==yend)
                {
                    break;
                }
            }
            if(i!=l+1)
            {
                break;
            }
            s++;
            for(i=1;i<=l;i++)
            {
                y++;
                if(x==xend&&y==yend)
                {
                    break;
                }
            }
            if(i!=l+1)
            {
                break;
            }
            s++;
            for(i=1;i<=l+1;i++)
            {
                x--;
                if(x==xend&&y==yend)
                {
                    break;
                }
            }
            if(i!=l+2)
            {
                break;
            }
            s++;
            for(i=1;i<=l+1;i++)
            {
                y--;
                if(x==xend&&y==yend)
                {
                    break;
                }
            }
            if(i!=l+2)
            {
                break;
            }
            s++;
            l+=2;
        }
        printf("%d\n",s);
    }
    return 0;
}

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<time.h>
#define max(a,b) ((a>b)?a:b)
#define min(a,b) ((a>b)?b:a)
#define UpFor(i,From,To) for(i=From;i<To;i++)
#define DownFor(i,From,To) for(i=From;i>To;i--)
#define Opfile_in(s) freopen(s,"r",stdin)
#define Opfile_out(s) freopen(s,"w",stdout)
#define Read(T) scanf("%d\n",&T)
#define Print(T) printf("%d\n",T)
#define LL long long
#define MAXN 214748364
int x,y;
void init();
void doit();

int main()
{
    //Opfile_in("CF_temp.in");
        init();
        doit();
    return 0;
}
void init()
{
    scanf("%d%d",&x,&y);
}
void doit()
{
    int ans;
    if((x==0&&y==0)||(x==1&&y==0))
    {
        Print(0);
        return ;
    }
    if(x<0&&y>=x&&y<-x)
    ans=-4*x-1;
    if(y<0&&x>y&&x<=-y+1)
    ans=-4*y;
    if(x>0&&y>-x+1&&y<=x)
    ans=x*4-3;
    if(y>0&&x<y&&x>=-y)
    ans=4*y-2;
    Print(ans);
}

#include<stdio.h>
int main(){
	int xCord,yCord,turns;
	scanf ("%d%d",&xCord,&yCord);
	if(xCord==0 && yCord==0){
		turns = 0;
	}

	else if((yCord*-1)<=xCord && yCord>xCord){
		turns = 2+(yCord-1)*4;
	}

	else if(((xCord*-1)+1)<yCord && xCord>=yCord){
		turns = 1+(xCord-1)*4;
	}

	else if(yCord<xCord && xCord<=((yCord*-1)+1)){
		turns = yCord*-4;
	}

	else if((xCord*-1)>yCord && xCord<=yCord){
		turns = xCord*-4-1;
	}
	printf ("%d\n",turns);
	return 0;
}

#include <stdio.h>

int main(void)
{
	int x,y,sol,startC,r;
	scanf("%d %d",&x,&y);

	if(x>0){
		if(y<=x) {
			if(y+x>1) r=4; /*D*/
			else r=3; /*C*/
		}
		else r=1; /*A*/
	}
	else {
		if(y<x) r=3; /*C*/
		else if(y+x>=0) r=1; /*A*/
		else r=2; /*B*/
	}

	if((x==0 && y==0) || (x==1 && y==0)) sol = 0;
	else {
		if(r==1){ sol=2; startC=1; }
		else if(r==2){ sol=3; startC=-1; }
		else if(r==3){ sol=4; startC=-1; }
		else if(r==4){ sol=1; startC=1; }

		if(r==1 || r==3) {
			while(startC!=y){
				sol+=4;
				if(r==1) startC++;
				else startC--;
			}
		}
		else {
			while(startC!=x){
				sol+=4;
				if(r==2) startC--;
				else startC++;
			}
		}
	}

	printf("%d",sol);
	return 0;
}

#include <stdio.h>

int main()
{
	int x, y;
	scanf("%d%d", &x, &y);
	if ( !y && (!x || x == 1) )
		puts("0");
	else if ( x == 1 && y == 1 )
		puts("1");
	else
	{
		int i, px, py, res = 1;
		for ( px = py = i = 1; ++i <= 210; ++i )
		{
			++res;
			if ( y == py && x < px && x >= px-i )
				break;
			px -= i;
			++res;
			if ( x == px && y < py && y >= py-i )
				break;
			py -= i;
			++res;
			if ( y == py && px < x && px+i+1 >= x )
				break;
			px += i+1;
			++res;
			if ( x == px && py < y && py+i+1 >= y )
				break;
			py += i+1;
		}
		printf("%d\n", res);
	}
	return 0;
}

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

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

int main() {
	int X, Y, x = 0, y = 0, turns = 0, dir = 0, steps = 1, i;
	scanf(" %d %d", &X, &Y);
	if (X == 0 && Y == 0)
		goto done;

	while (1) {
		for (i = 0; i < steps; i++) {
			x += dx[dir];
			y += dy[dir];
			if (x == X && y == Y)
				goto done;
		}
		turns++;
		dir = (dir+1)%4;
		if (dir%2 == 0)
			steps++;
	}

done:
	printf("%d\n", turns);
	return 0;
}

#ifdef ONLINE_JUDGE
    #define NDEBUG 1
#endif
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>
#include <math.h>

#define long int64_t
#define fore(i,k,n) for (int _k = (k), _n = (n), i = _k; i <= _n; ++i)
#define forr(i,n,k) for (int _k = (k), _n = (n), i = _n; i >= _k; --i)
#define LIST_INIT_CAP 4
#define HASH_INIT_CAP 64
#define HASH_SKIP 11
#define TREE_INIT_CAP 1024
#define TREE_MAX_HEIGHT 64
#define DEQUE_INIT_CAP 1024
#define HEAP_INIT_CAP 1024
#define TAKEN 1
#define EMPTY 0
#define TOMB -1
#define max(a,b) (((a)>(b))?(a):(b))
#define min(a,b) (((a)<(b))?(a):(b))

int main() {
    int x, y;
    scanf("%d %d", &x, &y);
    int a = 1, b = 2, u = 0, v = 0;
    int answer = 0;
    if (u == x && v == y) goto end;
    while (true) {
        fore (i, 1, a) {
            ++u;
            if (u == x && v == y) goto end;
        }
        ++answer;
        fore (i, 1, a) {
            ++v;
            if (u == x && v == y) goto end;
        }
        ++answer;
        a += 2;
        fore (i, 1, b) {
            --u;
            if (u == x && v == y) goto end;
        }
        ++answer;
        fore (i, 1, b) {
            --v;
            if (u == x && v == y) goto end;
        }
        ++answer;
        b += 2;
    }

end:
    printf("%d", answer);

    return 0;
}

#include<stdio.h>
#include<math.h>
int main()
{
	int x,y;
	scanf("%d %d",&x,&y);
	if(x==0 && y==0)
	{
		printf("0");
		return 0;
	}
	if(x==y)
	{
		if(x>0)
		{
			printf("%d",4*x-3);
			return 0;
		}
		else
		{
			printf("%d",4*abs(x)-1);
			return 0;
		}
	}
	else if((abs(x)==abs(y))&&(x<0)&&(y>0))
	{
		printf("%d",4*y-2);
		return 0;
	}
	else if(y==1-x  && x>0)
	{
		printf("%d",4*x-4);
		return 0;
	}
	if(abs(x)<abs(y))
	{
		if(y>0)
		{
			printf("%d",(4*y)-2);
			return 0;
		}
		else if(y<0)
		{
			printf("%d",4*abs(y));
			return 0;
		}
	}
	if(abs(x)>abs(y))
	{
		if(x>0)
		{
			printf("%d",(4*x)-3);
			return 0;
		}
		else if(x<0)
		{
			printf("%d",(4*abs(x))-1);
			return 0;
		}
	}
	if((abs(x)==abs(y))&&(x>0)&&(y<0))
	{
		printf("%d",4*x);
		return 0;
	}
	return 0;
}

#include <stdio.h>

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))

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

int check(int x0, int y0, int x1, int y1, int x2, int y2)
{
    int minx, miny, maxx, maxy;
    minx = MIN(x0, x1);
    miny = MIN(y0, y1);
    maxx = MAX(x0, x1);
    maxy = MAX(y0, y1);
    if ((x0 == x1 && x1 == x2 && y2 >= miny && y2 <= maxy) || (y0 == y1 && y1 == y2 && x2 >= minx && x2 <= maxx))
    {
        return 1;
    }
    return 0;
}

void solve(int x, int y)
{
    int px, py, ans, count, dis, pos;
    ans = px = py = count = pos = 0;
    dis = 1;
    while (1)
    {
        if (px == x && py == y)
        {
            break;
        }
        if (px != 0 || py != 0)
        {
            ans ++;
        }
        if (check(px, py, px + dx[pos] * dis, py + dy[pos] * dis, x, y))
        {
            break;
        }
        px += dx[pos] * dis;
        py += dy[pos] * dis;
        count ++;
        if (count == 2)
        {
            count = 0;
            dis ++;
        }
        pos = (pos + 1) % 4;
    }
    printf("%d\n", ans);
}

int main()
{
    int x, y;
    while (scanf("%d%d", &x, &y) == 2)
    {
        solve(x, y);
    }
    return 0;
}

#include <stdio.h>

#define ABS(A) (A > 0 ? A : -A)

int main() {
	int x, y, max;

	scanf("%d%d", &x, &y);
	max = ABS(x) > ABS(y) ? ABS(x) : ABS(y);
	if (max == 0)
		printf("0\n");
	else if (x == max && y > 0 && y <= max)
		printf("%d\n", 1 + 4 * (max - 1));
	else if (x >= -max && x < max && y == max)
		printf("%d\n", 2 + 4 * (max - 1));
	else if (x == -max && y >= -max && y < max)
		printf("%d\n", 3 + 4 * (max - 1));
	else if (x > -max && x <= max && y == -max + 1)
		printf("%d\n", 4 * (max - 1));
	else if (x > -max && x <= max && y > -max + 1)
		printf("%d\n", 1 + 4 * (max - 1));
	else
		printf("%d\n", 4 * max);
	return 0;
}

#include<stdio.h>

int main()
{
	int x,y,p=-1,xf=0,yf=0,xp=0,yp=0,incre=1,a,k;

	scanf("%d%d",&x,&y);

	while(1)
	{
		p++;
		if(p%2==0)
		{
			if((p/2)%2==0)
				xf=xf+incre;
			else
				xf=xf-incre;
		}

		else
		{
			a=p+1;
			if((a/2)%2==0)
				yf=yf-incre;
			else
				yf=yf+incre;

			incre++;
		}

		if(x==xf&&x==xp)
            if((y<=yf&&y>=yp)||(y>=yf&&y<=yp))
			break;

        if(y==yf&&y==yp)
            if((x<=xf&&x>=xp)||(x>=xf&&x<=xp))
            break;

		xp=xf;
		yp=yf;

	}

	printf("%d",p);

	return 0;
}

#include <stdio.h>

typedef struct {
	int x;
	int y;
} ponto;

ponto soma (ponto a, ponto b)
{
	ponto p;
	p.x = a.x + b.x;
	p.y = a.y + b.y;
	return p;
}

ponto produto (ponto a, int b)
{
	ponto p;
	p.x = a.x * b;
	p.y = a.y * b;
	return p;
}

int min (int a, int b)
{
	return (a>b)?b:a;
}

int max (int a, int b)
{
	return (a>b)?a:b;
}

int main (void)
{
	ponto p;
	ponto dir[4];
	ponto atual;
	ponto proximo;
	int dir_atual = 0;
	int loop = 0;
	int escalar = 1;

	atual.x = atual.y = 0;
	proximo.x = 1;
	proximo.y = 0;

	dir[0].x = 1;  dir[0].y = 0;
	dir[1].x = 0;  dir[1].y = 1;
	dir[2].x = -1; dir[2].y = 0;
	dir[3].x = 0;  dir[3].y = -1;

	int resposta = 0;

	scanf("%d %d", &p.x, &p.y);

	while (1)
	{

		if (p.x == atual.x && p.x == proximo.x)
			if (p.y >= min(atual.y, proximo.y) && p.y <= max(atual.y, proximo.y))
				break;

		if (p.y == atual.y && p.y == proximo.y)
			if (p.x >= min(atual.x, proximo.x) && p.x <= max(atual.x, proximo.x))
				break;

		atual = proximo;
		dir_atual = (dir_atual+1)%4;
		loop = !loop;
		if (!loop) escalar++;
		proximo = soma(atual,produto(dir[dir_atual],escalar));
		resposta += 1;
	}

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

	return 0;
}

#include <stdio.h>

int good(int a, int b, int c) {
	if (b > c) {
		int tmp;

		tmp = b;
		b = c;
		c = tmp;
	}
	return a >= b && a <= c;
}

int main() {
	static int xx[400], yy[400];
	int x, y, i, a, b, c, d, e;

	scanf("%d%d", &x, &y);
	a = b = 0;
	c = d = e = 1;
	for (i = 0; i < 400; i++) {
		xx[i] = a;
		yy[i] = b;
		if (c)
			if (d)
				a += e;
			else
				a -= e;
		else
			if (d)
				b += e, e++, d = 0;
			else
				b -= e, e++, d = 1;
		c = !c;
	}
	for (i = 0; i + 1 < 400 && (xx[i] != x || !good(y, yy[i], yy[i + 1])) && (yy[i] != y || !good(x, xx[i], xx[i + 1])); i++)
		;
	printf("%d\n", i);
	return 0;
}

#include<stdio.h>
int main()
{
	int x,y,ans=0;
	scanf("%d%d",&x,&y);
	if(x==y&&x>-y)
	ans=-3+4*x;
	if(x==y&&x<-y)
	ans=-1-4*x;
	if(y>x)
	ans=-2+4*y;
	if(x>y)
	ans=-4*y;
	printf("%d",ans);
}

/*
#include <stdio.h>
#include <stdlib.h>
int min(int a, int b) {

    return (a > b) ? b : a;

}

int main() {

    int n, m, a, b;

    scanf("%d %d %d %d", &n, &m, &a, &b);
    int price = 0;

    int c=a*m;
    int d, e, f, g, h, k, l;
    if(c<b||c==b) printf("%d",a*n);
    else if(c>b){
        if(n%m==0) printf("%d", b*(n/m));
        else if(n%m!=0){
            d=n/m+1;
            e=d*b;

            f=n%m;
            g=f*a;
            h=n/m;
            k=h*b;
            l=g+k;
            printf("%d",min(e,l));
        }
    }

    return 0;
}
*/
/*
#include <stdio.h>
#include <stdlib.h>

int main() {

    int sum;
    scanf("%d", &sum);

    if (sum >= 0) {
        printf("%d",sum);
    } else {
        int a = -sum/10%10;
        int b = -sum%10;
        printf("%d",a > b ? sum/100*10-b : sum/10);
    }

    return 0;

}*/
/*
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main() {

    int x1, y1, x2, y2;

    scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
    if(abs(x1-x2)==abs(y1-y2))
        printf("%d %d %d %d", x1, y2, x2, y1);
    else if(x1 == x2 || y1 == y2) {

        float l = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));

        if(x1==x2) {
            printf("%d %d %d %d", x1+(int)l, y1, x1+(int)l, y2);
        } else
            printf("%d %d %d %d", x1, y1+(int)l, x2, y2+(int)l);
    } else
    printf("-1");

    return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

void sort(int** matrix, int n) {

    int done = 0;

    while(!done) {

        done = 1;

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

            if((float) matrix[i][1] / matrix[i][0] < (float) matrix[i + 1][1] / matrix[i + 1][0]) {

                int aux1 = matrix[i][0];
                int aux2 = matrix[i][1];

                matrix[i][0] = matrix[i + 1][0];
                matrix[i][1] = matrix[i + 1][1];

                matrix[i + 1][0] = aux1;
                matrix[i + 1][1] = aux2;

                done = 0;

            }
        }
    }
}

int main() {

    int n, strength;

    scanf("%d %d", &strength, &n);

    int** matrix = (int**)malloc(sizeof(int*) * n);

    for(int i = 0; i < n; i++)
        matrix[i] = (int*)malloc(4 * 2);

    for(int i = 0; i < n; i++)
        scanf("%d %d", &matrix[i][0], &matrix[i][1]);

    sort(matrix, n);

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

            if(strength > matrix[i][0] && matrix[i][0] != -1) {

                strength += matrix[i][1];
                matrix[i][0] = -1;

            }
        }

    int finish = 0;

    for(int i = 0; i < n; i++)
        if(matrix[i][0] != -1)
            finish = 1;

    if(!finish)
        printf("YES");
    else
        printf("NO");
    return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main() {

    int n, m;

    scanf("%d %d", &n, &m);

    int cnt = (n + 1) / 2;
    int ans = (cnt  + m - 1) / m * m;

    if (ans > n) {
        ans = -1;
    }
    printf("%d", ans);

return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int min(int a, int b) {

    return (a > b) ? b : a;

}

int main() {

    int n;
    scanf("%d", &n);

    int array[n + 1];

    int m1 = 0, m2 = 0, m3 = 0;

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

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

        switch(array[i]) {

        case 1:
            m1++;
            break;

        case 2:
            m2++;
            break;

        case 3:
            m3++;
            break;

        }
    }
    int minim = min(m1, m2);
    minim = min(minim, m3);

    int aux[4];
    int k = 0;

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

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

        k=1;

        for(int j = 1; k < 4; j++) {

            if(j == n + 1)
                j = 1;

            if(array[j] == k) {

                aux[k++] = j;
                array[j] = -1;

            }
        }

        for(int j = 1; j < k; j++)
            printf("%d ", aux[j]);
        printf("\n");

    }
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

void sort(int n, int array[n]) {

    int done = 0;

    while(!done) {

        done = 1;

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

            if(array[i] > array[i + 1]) {

                int aux = array[i];
                array[i] = array[i + 1];
                array[i + 1] = aux;
                done = 0;

            }
        }
    }
}
int main() {

    int n, d;
    scanf("%d %d", &n, &d);

    int array[n];
    int sum = 0;
    for(int i = 0; i < n; i++) {

        scanf("%d", &array[i]);
        sum += array[i];

    }

    sum += 10 * (n - 1);

    if(sum > d)
        printf("-1");
    else {

        //sort(n, array);

        int ct = 2 * (n - 1);
        while(sum + 5 <= d) {

            ct++;
            sum+=5;

        }
        printf("%d", ct);

    }

    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main() {

    int n, m;
    scanf("%d %d", &n, &m);

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

        if(i % 2 == 1)
            if(first == 1) {

                printf("#");
                first = 0;

            }
        for(int j = 0; j < m - i % 2; j++) {

            if(i % 2 == 0) {

                printf("#");

            } else
                printf(".");

        }

        if(i % 2 == 1)
            if(last == 1) {

                first = 1;
                printf("#");
                last = 0;

            }

        if(first == 0)
            last = 1;
        printf("\n");
    }

    return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main() {

    int n;
    scanf("%d", &n);

    int nr;

    int odd = 0;
    int even = 0;
    int pos1 = -1;
    int pos2 = -1;

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

        scanf("%d", &nr);
        if(nr % 2 == 0) {

            even++;
            pos1 = i + 1;

        } else {

            odd ++;
            pos2 = i + 1;

        }
    }

    if(odd == 1)
        printf("%d", pos2);
    else
        printf("%d", pos1);
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

void sort(int* array, int size) {

    int done = 0;

    while(!done) {

        done = 1;
        for(int i = 0; i < size - 1; i++)
            if(array[i] > array[i + 1]) {

                int aux = array[i];
                array[i] = array[i + 1];
                array[i + 1] = aux;
                done = 0;

            }
    }
}

int main() {

    int n, v;
    scanf("%d %d", &n, &v);

    int* array = (int*)malloc(sizeof(int) * 50);
    int k;
    int* deals = (int*)malloc(sizeof(int) * 50);
    int sizeDeals = 0;
    int done;
    for(int i = 0; i < n; i++) {

        scanf("%d", &k);
        done = 0;
        for(int j = 0; j < k; j++) {

            scanf("%d", &array[j]);
            if(array[j] < v)
                done = 1;

        }

        if(done)
            deals[sizeDeals++] = i + 1;
        done = 0;

    }

    if(sizeDeals != 0) {

        sort(deals, sizeDeals);
        printf("%d\n", sizeDeals);
        for(int i = 0; i < sizeDeals; i++)
            printf("%d ", deals[i]);

    } else
        printf("0");
    return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main() {

    int n;

    scanf("%d", &n);

    char* string = malloc(101);
    char* string1 = malloc(10000);
    char* string2 = malloc(10000);

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

        gets(string);
        strcat(string1, string);

    }

    strcpy(string2, string1);
    strrev(string2);

    if(strncmp(string1 + 1, string2, strlen(string2) - 2) == 0)
        printf("YES");
    else
        printf("NO");

    return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main() {

    int n, k;

    scanf("%d %d", &n, &k);
    int maximum = (-1) * (1 << 31);

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

        int fi, ti;

        scanf("%d %d", &fi, &ti);

        if(k >= ti) {

            if(fi > maximum)
                maximum = fi;

        } else {

            if((fi - (ti - k)) > maximum)
                maximum = fi - (ti - k);

        }

    }

    printf("%d", maximum);

    return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main() {

    int n;
    scanf("%d", &n);

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

        int price, quality;
        scanf("%d %d", &price, &quality);

        if(price != quality) {

            printf("Happy Alex");
            return 0;
        }
    }

    printf("Poor Alex");

    return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main() {

    int friends, bottles, milliliters, limes, slices, salt, nl, np;
    scanf("%d %d %d %d %d %d %d %d", &friends, &bottles, &milliliters, &limes, &slices, &salt, &nl, &np);

    int allMilliliters = bottles * milliliters / nl / friends;
    int allSalt = salt / np / friends;
    int allLimes = limes * slices / friends;

    int minim = -1;

    minim = (allLimes < allMilliliters) ? allLimes : allMilliliters;
    minim = (minim < allSalt) ? minim : allSalt;

    printf("%d", minim);
    return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main() {

    int dice1, dice2;
    scanf("%d %d", &dice1, &dice2);

    int dice1Wins = 0;
    int draw = 0;
    int dice2Wins = 0;

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

        if(abs(dice1 - i) > abs(dice2 - i))
            dice2Wins++;
        else if(abs(dice1 - i) < abs(dice2 - i))
            dice1Wins++;
        else
            draw++;

    }

    printf("%d %d %d", dice1Wins, draw, dice2Wins);

    return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main() {

    int n;
    scanf("%d", &n);
    int* array = (int*)malloc(n * 4);
    int minimum = (1 << 28);
    int pos;
    for(int i = 0; i < n; i++) {

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

        if(i > 1) {

            if(array[i] - array[i - 2] < minimum) {

                minimum = array[i] - array[i - 2];
                pos = i - 1;

            }
        }
    }

    minimum = -999999;
    for(int i = 0 ; i < n - 1; i++) {

        if(i + 1 == pos) {
            if(array[i + 2] - array[i] > minimum) {

                minimum = array[i + 2] - array[i];
                i++;

            }
        } else {

            if(array[i + 1] - array[i] > minimum) {

                minimum = array[i + 1] - array[i];

            }

        }
    }

    printf("%d", minimum);
    return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main() {

    int n;
    scanf("%d", &n);
    int* exercises = (int*)malloc(sizeof(int) * (n + 1));

    int chest = 0;
    int biceps = 0;
    int back = 0;

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

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

        switch(i % 3){

        case 0:
            chest += exercises[i];
            break;

        case 1:
            biceps += exercises[i];
            break;

        case 2:
            back += exercises[i];
            break;

        }
    }

    if(chest > back && chest > biceps)
        printf("chest");
    else if(back > chest && back > biceps)
        printf("back");
    else
        printf("biceps");
    return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int cmmdc(int a, int b) {

    int r;

    while(b != 0) {

        r = a % b;
        a = b;
        b = r;

    }

    return a;
}

int main() {

    long int l, r;

    scanf("%ld %ld", &l, &r);
    printf("%d", sizeof(long int));
    if(r - (l += l%2) < 2)
        printf("-1");
    else
        printf("%d %d %d", l, l + 1, l + 2);
    return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main() {

    int n;
    scanf("%d", &n);

    char matrix[n][n];

    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            scanf("%c", &matrix[i][j]);

    char diagonal = matrix[0][0];

    for(int i = 0; i < n; i++)
        if(matrix[i][i] != diagonal) {

            printf("NO");
            return 0;

        }
    printf("aaa");
    for(int i = n; i >= 0; i--)
        if(matrix[i][n - i] != diagonal) {

            printf("NO");
            return 0;

        }
    printf("aaa");

    char notDiag = matrix[0][1];

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

            if(i == j || i + j == n -1)
                j++;
            else {

                if(matrix[i][j] != notDiag) {

                    printf("NO");
                    return 0;

                }
            }
        }

    printf("YES");
    return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main() {

    int n, m;
    scanf("%d %d", &n, &m);

    char** matrix = (char**)malloc(sizeof(char*) * n);
    for(int i = 0; i < n; i++)
        matrix[i] = malloc(m);

    getchar();

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

        gets(matrix[i]);
        for(int j = 0; j < m; j++)
            if(matrix[i][j] == '.') {
                if((i + j) % 2 == 0)
                    matrix[i][j] = 'B';
                else
                    matrix[i][j] = 'W';

            }

    }

    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++)
            printf("%c", matrix[i][j]);
        printf("\n");

    }
    return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <limits.h>

int freq1[27], freq2[27];

int main() {

    int n;
    scanf("%d", &n);
    getchar();
    char* question = malloc(15);

    int left = INT_MIN / 2;
    int right = INT_MAX / 2;

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

        gets(question);

            if(question[0] == '>' && question[strlen(question) - 1] == 'Y' ||
               (question[0] == '<' && question[strlen(question) - 1] == 'N')) { /// > or >=

                if(question[1] == '=') {

                    char* tok = strtok(question, " ");
                    tok = strtok(NULL, " ");
                    left = atoi(tok) + 1;

                } else {

                    char* tok = strtok(question, " ");
                    tok = strtok(NULL, " ");
                    left = atoi(tok);

                }
            } else if(question[0] == '<' && question[strlen(question) - 1] == 'Y' || (question[0] == '>' && question[strlen(question) - 1] == 'N')) {

                if(question[1] == '=') { /// <=

                    char* tok = strtok(question, " ");
                    tok = strtok(NULL, " ");
                    right = atoi(tok);

                } else {

                    char* tok = strtok(question, " ");
                    tok = strtok(NULL, " ");
                    right = atoi(tok) - 1;

                }
            }

        if(question[0] == '>' && question[1] == '=' && question[strlen(question) -1 ] == 'Y' ||
                (question[0] == '<' && question[1] != '=' && question[strlen(question) - 1] == 'N')) {

            char* tok = strtok(question, " ");
            tok = strtok(NULL, " ");
            if(atoi(tok) > left)
                left = atoi(tok);

        } else if(question[0] == '>' && question[1] != '=' && question[strlen(question) - 1] == 'Y' ||
                  (question[0] == '<' && question[1] == '=' && question[strlen(question) - 1] == 'N')) {

            char* tok = strtok(question, " ");
            tok = strtok(NULL, " ");
            if(atoi(tok) + 1 > left)
                left = atoi(tok) + 1;

        } else if(question[0] == '<' && question[1] == '=' && question[strlen(question) - 1] == 'Y' ||
                  (question[0] == '>' && question[1] != '=' && question[strlen(question) - 1] == 'N')) {

            char* tok = strtok(question, " ");
            tok = strtok(NULL, " ");
            if(atoi(tok) < right)
                right = atoi(tok);

        } else if(question[0] == '<' && question[1] != '=' && question[strlen(question) - 1] == 'Y' ||
                  (question[0] == '>' && question[1] == '=' && question[strlen(question) - 1] == 'N')) {

            char* tok = strtok(question, " ");
            tok = strtok(NULL, " ");
            if(atoi(tok) - 1 < right)
                right = atoi(tok) - 1;

        }
    }

    if(left <= right) {

        printf("%d", right);

    } else
        printf("Impossible");
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <limits.h>

void mergeSort(int left, int mid, int right, int* array, int n) {

    int*aux = (int*)malloc(sizeof(int) * n);

    int i = left;
    int j = mid + 1;
    int index = i;

    while(i <= mid && j <= right) {

        if(array[i] > array[j]) {

            aux[index++] = array[i++];

        } else {

            aux[index++] = array[j++];

        }

    }

    for(int l = i; l <= mid; l++)
        aux[index++] = array[l];

    for(int l = j; l <= right; l++)
        aux[index++] = array[l];

    for(int l = left; l <= right; l++)
        array[l] = aux[l];

}

void merge(int left, int right, int* array, int n) {

    int mid;

    if(left < right) {

        mid = (left + right) / 2;
        merge(left, mid, array, n);
        merge(mid + 1, right, array, n);
        mergeSort(left, mid, right, array, n);

    }
}

int main() {

    int devices, sockets, supply;

    scanf("%d %d %d", &supply, &devices, &sockets);
    int array[supply];

    for(int i = 0; i < supply; i++)
        scanf("%d", &array[i]);

    merge(0, supply - 1, array, supply);

    if(devices <= sockets)
        printf("0");
    else {

        int i = 0;
        while(sockets < devices && i < supply) {

            sockets += array[i] - 1;
            i++;

        }

        if(i != supply)
            printf("%d", i);
        else if(sockets >= devices)
            printf("%d", i);
        else
            printf("-1");
    }
    return 0;

} */

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <limits.h>

int main() {

    int x, y;
    scanf("%d %d", &x, &y);
    int s;
    if(y>x && x>=-y)s=-2+y*4;
    if(y<x && x<=-y+1)s=-y*4;
    if(y<=x && x>-y+1)s=-3+x*4;
    if(y>=x && x<-y)s=-1-4*x;

    printf("%d", s);

    return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
    char ch;
    char* input = (char*)malloc(10);
    int i = 0;
    int on_y = 0;
    int neg_x = 0;
    int neg_y = 0;
    while(read(0, &ch, 1) > 0)
    {
        if(ch != '-')
        {
            input[i] = ch;
            i++;
            if(ch == ' ')
            {
                on_y = 1;
            }
        }
        else if(on_y)
        {
            neg_y = 1;
        }
        else
        {
            neg_x = 1;
        }
    }
    input[i] = '\0';
    int x = strtol(input, &input, 10);
    if(neg_x)
    {
        x *= -1;
    }
    while(*input != ' ')
    {
        input++;
    }
    int y = strtol(input, &input, 10);
    if(neg_y)
    {
        y *= -1;
    }
    if(x < 0 && x <= y && y < -1 * x)
    {
        printf("%d",4 * (-1*x - 1) + 3);
    }
    else if(x > 0 && -x + 1 < y && y <= x)
    {
        printf("%d",4*(x-1) + 1);
    }
    else if(y > 0 && -1 * y <= x && x < y)
    {
        printf("%d", 4 * (y - 1) + 2);
    }
    else if((x == 1 && y == 0) || (y < 0 && y < x && x <= -1*y + 1))
    {
        printf("%d", -4 * y);
    }
    return 0;

}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int x,y,result;
    scanf("%d %d",&x,&y);
    if(x==0 && y==0)result=0;
    else if(x==1 && y==0)result=0;
    else if(x==0 && y==1)result=2;
    else if(x==0 && y==-1)result=4;
    else if(x==-1 && y==0)result=3;
    else if(x>0 && y>0)
    {
        if(x<y)
        result=(3*y)+(y-2);
        else
            result=(3*x)+(x-3);
    }
    else if(x<0 && y<0)
    {
        if(abs(x)<abs(y))
            result=4*abs(y);
        else
            result=(3*abs(x))+(abs(x)-1);
    }
    else if(x>0 && y<0)
    {
        if(x>abs(y))
        {
            if(x-abs(y)==1)
            result=(4*abs(y));
            else
               result=(3*x)+(x-3);
        }
        else result=(4*abs(y));
    }
    else if(x<0 && y>0)
    {
        if(abs(x)>y)
            result=(3*abs(x))+(abs(x)-1);
        else result=(3*y)+(y-2);
    }
    printf("%d",result);
    return 0;
}

#include <stdio.h>

typedef struct
{
	int x,y;
}Point_t ;
Point_t Now;

int main()
{
	int x,y,add,Res;
	scanf("%d %d",&x,&y);
	add=1;
	Now.x=Now.y=0;
	while(add)
	{
		if(add&1)
		{
			if(y==Now.y&&x>=Now.x&&x<=Now.x+add)
			{
				Res=((add-1)<<1)+1;
				break;
			}
			Now.x+=add;
			if(x==Now.x&&y>=Now.y&&y<=Now.y+add)
			{
				Res=add<<1;
				break;
			}
			Now.y+=add;
		}
		else
		{
			if(y==Now.y&&x>=Now.x-add&&x<=Now.x)
			{
				Res=((add-1)<<1)+1;
				break;
			}
			Now.x-=add;
			if(x==Now.x&&y>=Now.y-add&&y<=Now.y)
			{
				Res=add<<1;
				break;
			}
			Now.y-=add;
		}
		++add;
	}
	printf("%d\n",Res);
	return 0;
}

#include <stdio.h>

typedef struct
{
	int x,y;
}Point_t ;
Point_t Now;

int main()
{
	int x,y,add,Res;
	scanf("%d %d",&x,&y);
	add=1;
	Now.x=Now.y=0;
	while(add)
	{
		if(add&1)
		{
			if(y==Now.y&&x>=Now.x&&x<=Now.x+add)
			{
				Res=(add-1)<<1+1;
				break;
			}
			Now.x+=add;
			if(x==Now.x&&y>=Now.y&&y<=Now.y+add)
			{
				Res=add<<1;
				break;
			}
			Now.y+=add;
		}
		else
		{
			if(y==Now.y&&x>=Now.x-add&&x<=Now.x)
			{
				Res=(add-1)<<1+1;
				break;
			}
			Now.x-=add;
			if(x==Now.x&&y>=Now.y-add&&y<=Now.y)
			{
				Res=add<<1;
				break;
			}
			Now.y-=add;
		}
		++add;
	}
	printf("%d\n",Res);
	return 0;
}

#include<stdio.h>
int main()
{
int x,y,i=0,j=0,turn=-1;
scanf("%d %d",&x,&y);
if(x==0&&y==0)
{
    printf("0");
return 0;
}
while(1)
{

    i++;
    turn++;
     if(x<=i&&x>=i-1&&j==y)
    {
        printf("%d",turn);
        return 0;
    }
    j++;
    turn++;
    if(i==x&&y<=j&&y>=j-1)
    {
        printf("%d",turn);
        return 0;
    }
    i=-i;
    turn++;
     if(x<=i&&x>=-i&&j==y)
    {
        printf("%d",turn);
        return 0;
    }
    j=-j;
    turn++;
     if(i==x&&y<=i&&y>=-i)
    {
        printf("%d",turn);
        return 0;
    }
    i=-i+1;
    turn++;
     if(x<=i&&x>=i-1&&j==y)
    {
        printf("%d",turn);
        return 0;
    }
    j=-j+1;
    turn++;
    if(x==i&&y<=j&&y>=j-1)
    {
        printf("%d",turn);
        return 0;
    }
    i=-i;
    turn++;
     if(x<=i&&x>=-i&&j==y)
    {
        printf("%d",turn);
        return 0;
    }
    j=-j;
    turn++;
     if(i==x&&y<=i&&y>=-i)
    {
        printf("%d",turn);
        return 0;
    }

}
}

#include<stdio.h>
int main()
{
int x,y,i=0,j=0,turn=-1;
scanf("%d %d",&x,&y);
if(x==0&&y==0)
{
    printf("0");
return 0;
}
while(1)
{

    i++;
    turn++;
     if(x<=i&&x>=i-1&&j==y)
    {
        printf("%d",turn);
        return 0;
    }
    j++;
    turn++;
    if(i==x&&y<=j&&y>=j-1)
    {
        printf("%d",turn);
        return 0;
    }
    i=-i;
    turn++;
     if(x>=i&&x<=-i&&j==y)
    {
        printf("%d",turn);
        return 0;
    }
    j=-j;
    turn++;
     if(i==x&&y>=i&&y<=-i)
    {
        printf("%d",turn);
        return 0;
    }
    i=-i+1;
    turn++;
     if(x>=i&&x<=i-1&&j==y)
    {
        printf("%d",turn);
        return 0;
    }
    j=-j+1;
    turn++;
    if(x==i&&y>=j&&y<=i-1)
    {
        printf("%d",turn);
        return 0;
    }

}
}

#include<stdio.h>
int main()
{
int x,y,i=0,j=0,turn=-1;
scanf("%d %d",&x,&y);
while(1)
{
     if(i==x&&y<=j&&y>=j-1)
    {
        printf("%d",turn);
        return 0;
    }
    i++;
    turn++;
     if(x<=i&&x>=i-1&&j==y)
    {
        printf("%d",turn);
        return 0;
    }
    j++;
    turn++;
    if(i==x&&y<=j&&y>=j-1)
    {
        printf("%d",turn);
        return 0;
    }
    i=-i;
    turn++;
     if(x>=i&&x<=-i&&j==y)
    {
        printf("%d",turn);
        return 0;
    }
    j=-j;
    turn++;
     if(i==x&&y>=i&&y<=-i)
    {
        printf("%d",turn);
        return 0;
    }
    i=-i+1;
    turn++;
     if(x>=i&&x<=i-1&&j==y)
    {
        printf("%d",turn);
        return 0;
    }
    j=-j+1;
    turn++;
}
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
  int x=0,y=0,i,line=1;
   scanf("%i %i",&x,&y);
   for (i=1;i<2;)
   {
     if (x==0 && y==0)
       {
           printf("0");
           break;
       }

      else if (y==0 && ( x<=1 && x>=0 )  )
       {

           printf("0");
           break;
       }
       else
        i++;
        line++;
   }

   for (i=1;i<=100;)
{

       if ( (-i<=x && x<=i) &&y==i )///upper
   {
      printf("%i ",line) ;
      break;
   }
   else
    line++;
   if ( (-i<=y && y<=i )&& x==-i )//left
   {
        printf("%i   ",line);
         break;
   }
    else
    line++;
    if ( (-i<=x&&x<=i+1)&&y==-i )
   {
        printf("%i",line) ;
      break;
   }
    else
    {
     line++;
     i++;
    }
    if (  (  -i+1<= y && y<=i  ) && x==i)
   {
       printf("%i",line) ;
       break;
   }
    else
    line++;

   }

    return 0;
}

//In the name of God
#include <stdio.h>

int dx,dy;
int x,y;

int mv(int size,int d)
{
  d%=4;
  int ax=0,ay=0;
  switch(d)
    {
    case 0:
      ay=-1;
      break;
    case 1:
      ax=1;
      break;
    case 2:
      ay=1;
      break;
    default:
      ax=-1;
    }
  while(size--)
    {
      x+=ax; y+=ay;
      if(x==dx && y==dy)
	return 1;
    }
  return 0;
}

int main()
{
  scanf("%d%d",&dx,&dy);
  if(dx==0 && dy==0)
    {
      printf("0");
      return 0;
    }
  int step; int d=0; int size=1, rem=2;
  for(step=0;;step++)
    {
      d++;
      if(rem>0)
	rem--;
      else
	{
	  size++;
	  rem=2;
	}
      if(mv(size,d))
	{
	printf("%d\n",step);
	return 0;
	}
    }
}

#include<stdio.h>
void quicksort(int a[],int lower,int upper)
{
	if(lower<upper)
	{
		int i=split(a,lower,upper);
		quicksort(a,lower,i-1);
		quicksort(a,i+1,upper);
	}
}
int split(int a[],int lower,int upper)
{
	int l=lower+1,u=upper,t,p=a[lower];
	while(l<=u)
	{
		while(a[l]<=p && l<=upper)
			l++;
		while(a[u]>=p && u>lower)
			u--;
//		printf("\nstopped at %d and %d",a[l],a[u]);
		if(l<u)
		{
		t=a[l];
		a[l]=a[u];
		a[u]=t;
		}
	}
	t=a[lower];
	a[lower]=a[u];
	a[u]=t;
	return u;
}
int main()
{
	int x,y;
	scanf(" %d %d",&x,&y);
	int ans=0;
	if(x==1 && y==1)
	{
		printf("0");
		return 0;
	}
	else if(y>0 &&  x>=-1*y && x<=y)
	{
		ans=2+4*(y-1);
		if(x==y)
			ans--;
	}
	else if(y<0 && x>=y && x<=-1*y+1)
	{
		ans=4+4*(-1*y-1);
		if(x==y)
			ans--;
	}
	else if(x>0 && y<=x && y>=-1*x+1)
	{
		ans=1+(4*(x-1));
			if(x==-1*y+1)
			ans--;
	}
	else if(x<0 && y>=x && y<=-1*x)
	{
		ans=3+(4*(-1*x-1));
			if(x==-y)
			ans--;
	}
	printf("%d",ans);
	return 0;
}

#include<stdio.h>
#include<ctype.h>

int main()
{
    int i,x,y,a,b,d=1,turns=0,m=1;
    scanf("%d %d",&x,&y);
    a=b=0;
    while(a!=x && b!=y)
    {
        if(m==1)
        {
            x=x+d;
            m++;
        }
        else if(m==2)
        {
            y=y+d;
            m++;
            d++;
            turns++;
        }
        else if(m==3)
        {
            x=x-d;
            m++;
        }
        else if(m==4)
        {
            y=y-d;
            m=1;
            d++;
            turns++;
        }
    }
    printf("%d",turns);

return 0;
}

#include<stdio.h>
#include<ctype.h>

int main()
{
    int i,x,y,a,b,d=1,turns=0,m=1;
    scanf("%d %d",&x,&y);
    a=b=0;
    while(a!=x && b!=y)
    {
        if(m==1)
        {
            a=a+d;
            m++;
        }
        else if(m==2)
        {
            b=b+d;
            m++;
            d++;
            turns++;
        }
        else if(m==3)
        {
            a=a-d;
            m++;
        }
        else if(m==4)
        {
            b=b-d;
            m=1;
            d++;
            turns++;
        }
    }
    printf("%d",turns);

return 0;
}

#include <stdio.h>
#define BREAK_LOOP if( (!dir&&ty==y&&tx>=x) || (dir==1&&tx==x&&ty>=y) || (dir==2&&ty==y&&tx<=x) || (dir==3&&tx==x&&ty<=y) ){break;}
int x,y,tx,ty,step=0,turn=0,dir;
int main(){
	scanf("%d %d", &x, &y);
	while(1){
		BREAK_LOOP
		dir=0;
		if(turn!=0){
			turn++;
		}
		step++;
		tx+=step;

		BREAK_LOOP
		dir++;
		turn++;
		ty+=step;
		step*=-1;

		BREAK_LOOP
		dir++;
		turn++;
		step--;
		tx+=step;

		BREAK_LOOP
		dir++;
		turn++;
		ty+=step;
		step*=-1;
	}
	printf("%d ", turn);
	return 0;
}

#include <stdio.h>
#define BREAK_LOOP if( ((tx==x) && ((step>0 && ty>=y) || (step<0 && ty<=y)) ) || ((ty==y) && ((step>0 && tx>=x) || (step<0 && tx<=x)) ) ){break;}
int x,y,tx,ty,step=0,turn=0;
int main(){
	scanf("%d %d", &x, &y);
	while(1){
		BREAK_LOOP
		step*=-1;
		step++;
		tx+=step;
		BREAK_LOOP
		turn++;
		ty+=step;
		BREAK_LOOP
		turn++;
		step++;
		step*=-1;
		tx+=step;
		BREAK_LOOP
		turn++;
		ty+=step;
	}
	printf("%d ", turn);
	return 0;
}

#include <stdio.h>
#define BREAK_LOOP if( (!dir && (tx==x) && ((step>=0 && ty>=y) || (step<0 && ty<=y)) ) || (dir && (ty==y) && ((step>=0 && tx>=x) || (step<0 && tx<=x)) ) ){break;}
int x,y,tx,ty,step=0,turn=0,dir;
int main(){
	scanf("%d %d", &x, &y);
	while(1){
		BREAK_LOOP
		if(turn!=0){
			turn++;
		}
		step*=-1;
		step++;
		tx+=step;
		dir=0;
		BREAK_LOOP
		turn++;
		ty+=step;
		dir=1;
		BREAK_LOOP
		turn++;
		step++;
		step*=-1;
		tx+=step;
		dir=0;
		BREAK_LOOP
		turn++;
		ty+=step;
		dir=1;
	}
	printf("%d ", turn);
	return 0;
}

#include<stdio.h>
#include<math.h>
int main(){
    int x=0,y=0,a,b,sum,t,i;
    int right[110],up[110],left[110],down[110];
    right[1]=1;up[1]=2;down[1]=4;left[1]=3;
    for(i=2;i<=110;i++)
        right[i]=up[i]=left[i]=down[i]=0;
    for(i=2;i<=100;i++){
        right[i]+=4;
        left[i]+=4;
        up[i]+=4;
        down[i]+=4;
    }
    scanf("%d%d",&a,&b);
    if(a==b&&b==0 || a==1&&b==0)printf("0\n");
    else if(a&&b){
        if(a>0&&b>0)printf("%d\n",right[a]);
        else if(a>0&&b<0)printf("%d\n",down[a]);
        else if(a<0&&b>0)printf("%d\n",up[b]);
        else printf("%d\n",left[-a]);
    }
    else{
        if(b==0)
            if(a>0)
                printf("%d\n",right[a]);
            else printf("%d\n",left[-a]);
        else{
            if(b>0)
                printf("%d\n",up[b]);
            else printf("%d\n",down[-b]);
        }
    }
    return 0;
}

#include<stdio.h>
#include<math.h>
int main(){
    int x=0,y=0,a,b,sum=0,t=1,i;
    scanf("%d%d",&a,&b);
    if(a==b&&b==0 || a==1&&b==0)printf("0\n");
    else{
        for(i=1;;i++){
        if(x+t>=a&&y>=b){
            printf("%d\n",sum+1);
            break;
        }
        else {
            x+=t;
            sum++;
        }
        if(x>=a&&y+t>=b){
            printf("%d\n",sum+1);
            break;
        }
        else {
            y+=t;
            sum++;
        }
        if(y>=b&&x-t-1>=a){
            printf("%d\n",1+sum);
            break;
        }
        else {
            x-=(t+1);
            sum++;
        }
        if(x>=a&&y-t-1>=b){
            printf("%d\n",sum+1);
            break;
        }
        else {
            y-=(t+1);
            sum++;
        }
        }
    }
    return 0;
}

#include<stdio.h>
#include<math.h>
int main(){
    int x=0,y=0,a,b,sum,t,i;
    int right[110],up[110],left[110],down[110];
    right[1]=1;up[1]=2;down[1]=4;left[1]=3;
    for(i=2;i<=110;i++)
        right[i]=up[i]=left[i]=down[i]=0;
    for(i=2;i<=101;i++){
        right[i]=4+right[i-1];
        left[i]=4+left[i-1];
        up[i]=4+up[i-1];
        down[i]=4+left[i-1];
    }
    scanf("%d%d",&a,&b);
    if(a==b&&b==0 || a==1&&b==0)printf("0\n");
    else if(a&&b){
        if(a>0&&b>0)printf("%d\n",right[a]);
        else if(a>0&&b<0)printf("%d\n",down[a]);
        else if(a<0&&b>0)printf("%d\n",up[b]);
        else printf("%d\n",left[-a]);
    }
    else{
        if(b==0)
            if(a>0)
                printf("%d\n",right[a]);
            else printf("%d\n",left[-a]);
        else{
            if(b>0)
                printf("%d\n",up[b]);
            else printf("%d\n",down[-b]);
        }
    }
    return 0;
}

#include<stdio.h>
int main(){
	int xCord,yCord,turns;
	scanf ("%d%d",&xCord,&yCord);
	if(xCord==0 && yCord==0){
		turns = 0;
	}

	else if((yCord*-1)<=xCord && yCord>xCord){
		turns = 2+(yCord-1)*4;
	}

	else if(((xCord*-1)+1)<yCord && xCord>=yCord){
		turns = 1+(xCord-1)*4;
	}

	else if(yCord<xCord && xCord<=((yCord*-1)+1)){
		turns = yCord*-4;
	}

	else if((xCord*-1)>yCord && xCord<=yCord){
		turns = xCord*-4;
	}
	printf ("%d\n",turns);
	return 0;
}

#include <stdio.h>

int main(void)
{
	int x,y,sol,startC,r;
	scanf("%d %d",&x,&y);

	if(x>0){
		if(y<x) {
			if(y+x>1) r=4; /*D*/
			else r=3; /*C*/
		}
		else r=1; /*A*/
	}
	else {
		if(y<x) r=3; /*C*/
		else if(y+x>0) r=1; /*A*/
		else r=2; /*B*/
	}

	if((x==0 && y==0) || (x==1 && y==0)) sol = 0;
	else {
		if(r==1){ sol=2; startC=1; }
		else if(r==2){ sol=3; startC=-1; }
		else if(r==3){ sol=4; startC=-1; }
		else if(r==4){ sol=1; startC=1; }

		if(r==1 || r==3) {
			while(startC!=y){
				sol+=4;
				if(r==1) startC++;
				else startC--;
			}
		}
		else {
			while(startC!=x){
				sol+=4;
				if(r==2) startC--;
				else startC++;
			}
		}
	}

	printf("%d",sol);
	return 0;
}

#include <stdio.h>

int main()
{
	int x, y;
	scanf("%d%d", &x, &y);
	if ( !y && (!x || x == 1) )
		puts("0");
	else if ( x == 1 && y == 1 )
		puts("1");
	else
	{
		int i, px, py, res = 1;
		for ( px = py = i = 1; ++i <= 200; )
		{
			++res;
			if ( y == py && x < px && x >= px-i )
				break;
			px -= i;
			++res;
			if ( x == px && y < py && y >= py-i )
				break;
			py -= i;
			++res;
			if ( y == py && px < x && px+i >= x )
				break;
			px += i;
			++res;
			if ( x == px && py < y && py+i >= y )
				break;
			py += i;
		}
		printf("%d\n", res);
	}
	return 0;
}

#include <stdio.h>

int main()
{
	int x, y;
	scanf("%d%d", &x, &y);
	if ( !y && (!x || x == 1) )
		puts("0");
	else if ( x == 1 && y == 1 )
		puts("1");
	else
	{
		int i, px, py, res = 1;
		for ( px = py = i = 1; ++i <= 200; ++i )
		{
			++res;
			if ( y == py && x < px && x >= px-i )
				break;
			px -= i;
			++res;
			if ( x == px && y < py && y >= py-i )
				break;
			py -= i;
			++res;
			if ( y == py && px < x && px+i >= x )
				break;
			px += i;
			++res;
			if ( x == px && py < y && py+i >= y )
				break;
			py += i;
		}
		printf("%d\n", res);
	}
	return 0;
}

#include<stdio.h>
#include<math.h>
int main()
{
	int x,y;
	scanf("%d %d",&x,&y);
	if(x==0 && y==0)
	{
		printf("0");
		return 0;
	}
	if(x==y)
	{
		if(x>0)
		{
			printf("%d",4*x-3);
			return 0;
		}
		else
		{
			printf("%d",4*abs(x)-1);
			return 0;
		}
	}
	else if(x==-1*y)
	{
		printf("%d",4*y-2);
		return 0;
	}
	else if(y==1-x  && x>0)
	{
		printf("%d",4*x-4);
		return 0;
	}
	if(abs(x)<abs(y))
	{
		if(y>0)
		{
			printf("%d",(4*y)-2);
			return 0;
		}
		else if(y<0)
		{
			printf("%d",4*abs(y));
			return 0;
		}
	}
	if(abs(x)>abs(y))
	{
		if(x>0)
		{
			printf("%d",(4*x)-3);
			return 0;
		}
		else if(x<0)
		{
			printf("%d",(4*abs(x))-1);
			return 0;
		}
	}
	if((abs(x)==abs(y))&&(x>0)&&(y<0))
	{
		printf("%d",4*x);
		return 0;
	}
	return 0;
}

#include<stdio.h>
#include<math.h>
int main()
{
	int x,y;
	scanf("%d %d",&x,&y);
	if(x==0 && y==0)
	{
		printf("0");
		return 0;
	}
	if(x==y)
	{
		if(x>0)
		{
			printf("%d",4*x-3);
			return 0;
		}
		else
		{
			printf("%d",4*abs(x)-1);
			return 0;
		}
	}
	else if(x==-1*y)
	{
		printf("%d",4*y-2);
		return 0;
	}
	else if(y==1-x  && x>0)
	{
		printf("%d",4*x-4);
		return 0;
	}
	if(abs(x)<abs(y))
	{
		if(y>0)
		{
			printf("%d",(4*y)-2);
			return 0;
		}
		else if(y<0)
		{
			printf("%d",4*abs(y));
			return 0;
		}
	}
	if(abs(x)>abs(y))
	{
		if(x>0)
		{
			printf("%d",(4*x)-3);
			return 0;
		}
		else if(x<0)
		{
			printf("%d",(4*abs(x))-1);
			return 0;
		}
	}
	return 0;
}

#include<stdio.h>
#include<math.h>
int main()
{
	int x,y;
	scanf("%d %d",&x,&y);
	if(x==0 && y==0)
	{
		printf("0");
		return 0;
	}
	if(x==y)
	{
		if(x>0)
		{
			printf("%d",4*x-3);
			return 0;
		}
		else
		{
			printf("%d",4*abs(x)-1);
			return 0;
		}
	}
	else if(x==-1*y)
	{
		printf("%d",4*y-2);
		return 0;
	}
	else if(y==1-x  && x>0)
	{
		printf("%d",4*x-4);
		return 0;
	}
	if(abs(x)<abs(y))
	{
		if(y>0)
		{
			printf("%d",(4*y)-2);
			return 0;
		}
		else if(y<0)
		{
			printf("%d",4*abs(y));
			return 0;
		}
	}
	if(abs(x)>abs(y))
	{
		if(x>0)
		{
			printf("%d",(4*x)-3);
			return 0;
		}
		else if(x<0)
		{
			printf("%d",(4*abs(x))-3);
			return 0;
		}
	}
	return 0;
}

#include<stdio.h>
#include<math.h>
int main()
{
	int x,y;
	scanf("%d %d",&x,&y);
	if(x==0 && y==0)
	{
		printf("0");
		return 0;
	}
	if(x==y)
	{
		if(x>0)
		{
			printf("%d",4*x-3);
			return 0;
		}
		else
		{
			printf("%d",4*abs(x)-1);
			return 0;
		}
	}
	else if(x==-y)
	{
		printf("%d",4*y-2);
		return 0;
	}
	else
	{
		printf("%d",4*x-4);
		return 0;
	}
	return 0;
}

#include <stdio.h>

#define ABS(A) (A > 0 ? A : -A)

int main() {
	int x, y, max;

	scanf("%d%d", &x, &y);
	max = ABS(x) > ABS(y) ? ABS(x) : ABS(y);
	if (max == 0)
		printf("0\n");
	else if (x == max && y == 0)
		printf("%d\n", 4 * (max - 1));
	else if (x == max && y > 0 && y <= max)
		printf("%d\n", 1 + 4 * (max - 1));
	else if (x >= -max && x < max && y == max)
		printf("%d\n", 2 + 4 * (max - 1));
	else if (x == -max && y >= -max && y < max)
		printf("%d\n", 3 + 4 * (max - 1));
	else if (x > -max && x <= max && y == -max)
		printf("%d\n", 4 * max);
	return 0;
}

#include <stdio.h>

#define ABS(A) (A > 0 ? A : -A)

int main() {
	int x, y, max;

	scanf("%d%d", &x, &y);
	max = ABS(x) > ABS(y) ? ABS(x) : ABS(y);
	if (max == 0)
		printf("0\n");
	else if (x == max && y == 0)
		printf("%d\n", 4 * (max - 1));
	else if (x == max && y > 0 && y <= max)
		printf("%d\n", 1 + 4 * (max - 1));
	else if (x >= -max && x < max && y == max)
		printf("%d\n", 2 + 4 * (max - 1));
	else if (x == -max && y >= -max && y < max)
		printf("%d\n", 3 + 4 * (max - 1));
	else if (x > -max && x <= max && y == -max + 1)
		printf("%d\n", 4 * (max - 1));
	else
		printf("%d\n", 4 * max);
	return 0;
}

#include <stdio.h>

#define ABS(A) (A > 0 ? A : -A)

int main() {
	int x, y, max;

	scanf("%d%d", &x, &y);
	max = ABS(x) > ABS(y) ? ABS(x) : ABS(y);
	if (max == 0)
		printf("0\n");
	else if (x > 0 && y > 0)
		printf("%d\n", 1 + 4 * (max - 1));
	else if (x < max &&  y == max)
		printf("%d\n", 2 + 4 * (max - 1));
	else if (x < 0 && y < max)
		printf("%d\n", 3 + 4 * (max - 1));
	else if (x >= 0 && y <= 0)
		printf("%d\n", 4 * (max - 1));
	return 0;
}