Problem: After decades of fruitless efforts, one of the expedition teams of ITO (Intersolar Tourism Organization) finally found a planet that would surely provide one of the best tourist attractions within a ten light-year radius from our solar system. The most attractive feature of the planet, besides its comfortable gravity and calm weather, is the area called Mare Triangularis. Despite the name, the area is not covered with water but is a great plane. Its unique feature is that it is divided into equilateral triangular sections of the same size, called trigons. The trigons provide a unique impressive landscape, a must for tourism. It is no wonder the board of ITO decided to invest a vast amount on the planet.

Despite the expected secrecy of the staff, the Society of Astrogeology caught this information in no time, as always. They immediately sent their president's letter to the Institute of Science and Education of the Commonwealth Galactica claiming that authoritative academic inspections were to be completed before any commercial exploitation might damage the nature.

Fortunately, astrogeologists do not plan to practice all the possible inspections on all of the trigons; there are far too many of them. Inspections are planned only on some characteristic trigons and, for each of them, in one of twenty different scientific aspects.

To accelerate building this new tourist resort, ITO's construction machinery team has already succeeded in putting their brand-new invention in practical use. It is a rover vehicle of the shape of an icosahedron, a regular polyhedron with twenty faces of equilateral triangles. The machine is customized so that each of the twenty faces exactly fits each of the trigons. Controlling the high-tech gyromotor installed inside its body, the rover can roll onto one of the three trigons neighboring the one its bottom is on.

<image> |  Figure E.1: The Rover on Mare Triangularis
---

Each of the twenty faces has its own function. The set of equipments installed on the bottom face touching the ground can be applied to the trigon it is on. Of course, the rover was meant to accelerate construction of the luxury hotels to host rich interstellar travelers, but, changing the installed equipment sets, it can also be used to accelerate academic inspections.

You are the driver of this rover and are asked to move the vehicle onto the trigon specified by the leader of the scientific commission with the smallest possible steps. What makes your task more difficult is that the designated face installed with the appropriate set of equipments has to be the bottom. The direction of the rover does not matter.

<image> |  <image> |  Figure E.2:The Coordinate System  |  Figure E.3: Face Numbering
---|---

The trigons of Mare Triangularis are given two-dimensional coordinates as shown in Figure E.2. Like maps used for the Earth, the x axis is from the west to the east, and the y axis is from the south to the north. Note that all the trigons with its coordinates (x , y) has neighboring trigons with coordinates (x - 1 , y) and (x + 1 , y). In addition to these, when x + y is even, it has a neighbor (x , y + 1); otherwise, that is, when x + y is odd, it has a neighbor (x , y - 1).

Figure E.3 shows a development of the skin of the rover. The top face of the development makes the exterior. That is, if the numbers on faces of the development were actually marked on the faces of the rover, they should been readable from its outside. These numbers are used to identify the faces.

When you start the rover, it is on the trigon (0,0) and the face 0 is touching the ground. The rover is placed so that rolling towards north onto the trigon (0,1) makes the face numbered 5 to be at the bottom.

As your first step, you can choose one of the three adjacent trigons, namely those with coordinates (-1,0), (1,0), and (0,1), to visit. The bottom will be the face numbered 4, 1, and 5, respectively. If you choose to go to (1,0) in the first rolling step, the second step can bring the rover to either of (0,0), (2,0), or (1,-1). The bottom face will be either of 0, 6, or 2, correspondingly. The rover may visit any of the trigons twice or more, including the start and the goal trigons, when appropriate.

The theoretical design section of ITO showed that the rover can reach any goal trigon on the specified bottom face within a finite number of steps.



Input

The input consists of a number of datasets. The number of datasets does not exceed 50.

Each of the datasets has three integers x, y, and n in one line, separated by a space. Here, (x,y) specifies the coordinates of the trigon to which you have to move the rover, and n specifies the face that should be at the bottom.

The end of the input is indicated by a line containing three zeros.

Output

The output for each dataset should be a line containing a single integer that gives the minimum number of steps required to set the rover on the specified trigon with the specified face touching the ground. No other characters should appear in the output.

You can assume that the maximum number of required steps does not exceed 100. Mare Triangularis is broad enough so that any of its edges cannot be reached within that number of steps.

Example

Input

0 0 1
3 5 2
-4 1 3
13 -13 2
-32 15 9
-50 50 0
0 0 0


Output

6
10
9
30
47
100

Solution (in CPP):

Solution:
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>
#include <cstring>
using namespace std;
typedef pair<int, int> pii;
typedef vector<pii> vpi;

struct info{
    int x,y,b,t;
    int step;
    bool isEven;
    info(int x, int y, int b, int t, int s, bool e):x(x),y(y),b(b),t(t),step(s),isEven(e){}
    info(){}
};
bool used[203][103][20][20];

int main(){
    vector<vector<vector<pii> > > next(20, vector<vector<pii> >(20));
    //next, 右左上
    //odd, 左右下
    next[0][1] = vpi{pii{4, 9}, pii{5, 10}, pii{1, 0}};
    next[0][4] = vpi{pii{5, 11}, pii{1, 6}, pii{4, 0}};
    next[0][5] = vpi{pii{1, 2}, pii{4, 3}, pii{5, 0}};
    next[1][0] = vpi{pii{6, 12}, pii{2, 7}, pii{0, 1}};
    next[1][2] = vpi{pii{0, 5}, pii{6, 11}, pii{2, 1}};
    next[1][6] = vpi{pii{2, 3}, pii{0, 4}, pii{6, 1}};
    next[2][1] = vpi{pii{7, 13}, pii{3, 8}, pii{1, 2}};
    next[2][3] = vpi{pii{1, 6}, pii{7, 12}, pii{3, 2}};
    next[2][7] = vpi{pii{3, 4}, pii{1, 0}, pii{7, 2}};
    next[3][2] = vpi{pii{8, 14}, pii{4, 9}, pii{2, 3}};
    next[3][4] = vpi{pii{2, 7}, pii{8, 13}, pii{4, 3}};
    next[3][8] = vpi{pii{4, 0}, pii{2, 1}, pii{8, 3}};
    next[4][0] = vpi{pii{3, 8}, pii{9, 14}, pii{0, 4}};
    next[4][3] = vpi{pii{9, 10}, pii{0, 5}, pii{3, 4}};
    next[4][9] = vpi{pii{0, 1}, pii{3, 2}, pii{9, 4}};
    next[5][0] = vpi{pii{10, 15}, pii{11, 16}, pii{0, 5}};
    next[5][10] = vpi{pii{11, 6}, pii{0, 1}, pii{10, 5}};
    next[5][11] = vpi{pii{0, 4}, pii{10, 9}, pii{11, 5}};
    next[6][1] = vpi{pii{11, 16}, pii{12, 17}, pii{1, 6}};
    next[6][11] = vpi{pii{12, 7}, pii{1, 2}, pii{11, 6}};
    next[6][12] = vpi{pii{1, 0}, pii{11, 5}, pii{12, 6}};
    next[7][2] = vpi{pii{12, 17}, pii{13, 18}, pii{2, 7}};
    next[7][12] = vpi{pii{13, 8}, pii{2, 3}, pii{12, 7}};
    next[7][13] = vpi{pii{2, 1}, pii{12, 6}, pii{13, 7}};
    next[8][3] = vpi{pii{13, 18}, pii{14, 19}, pii{3, 8}};
    next[8][13] = vpi{pii{14, 9}, pii{3, 4}, pii{13, 8}};
    next[8][14] = vpi{pii{3, 2}, pii{13, 7}, pii{14, 8}};
    next[9][4] = vpi{pii{14, 19}, pii{10, 15}, pii{4, 9}};
    next[9][10] = vpi{pii{4, 3}, pii{14, 8}, pii{10, 9}};
    next[9][14] = vpi{pii{10, 5}, pii{4, 0}, pii{14, 9}};
    next[10][5] = vpi{pii{9, 14}, pii{15, 19}, pii{5, 10}};
    next[10][9] = vpi{pii{15, 16}, pii{5, 11}, pii{9, 10}};
    next[10][15] = vpi{pii{5, 0}, pii{9, 4}, pii{15, 10}};
    next[11][5] = vpi{pii{16, 17}, pii{6, 12}, pii{5, 11}};
    next[11][6] = vpi{pii{5, 10}, pii{16, 15}, pii{6, 11}};
    next[11][16] = vpi{pii{6, 1}, pii{5, 0}, pii{16, 11}};
    next[12][6] = vpi{pii{17, 18}, pii{7, 13}, pii{6, 12}};
    next[12][7] = vpi{pii{6, 11}, pii{17, 16}, pii{7, 12}};
    next[12][17] = vpi{pii{7, 2}, pii{6, 1}, pii{17, 12}};
    next[13][7] = vpi{pii{18, 19}, pii{8, 14}, pii{7, 13}};
    next[13][8] = vpi{pii{7, 12}, pii{18, 17}, pii{8, 13}};
    next[13][18] = vpi{pii{8, 3}, pii{7, 2}, pii{18, 13}};
    next[14][8] = vpi{pii{19, 15}, pii{9, 10}, pii{8, 14}};
    next[14][9] = vpi{pii{8, 13}, pii{19, 18}, pii{9, 14}};
    next[14][19] = vpi{pii{9, 4}, pii{8, 3}, pii{19, 14}};
    next[15][10] = vpi{pii{19, 18}, pii{16, 17}, pii{10, 15}};
    next[15][16] = vpi{pii{10, 9}, pii{19, 14}, pii{16, 15}};
    next[15][19] = vpi{pii{16, 11}, pii{10, 5}, pii{19, 15}};
    next[16][11] = vpi{pii{15, 19}, pii{17, 18}, pii{11, 16}};
    next[16][15] = vpi{pii{17, 12}, pii{11, 6}, pii{15, 16}};
    next[16][17] = vpi{pii{11, 5}, pii{15, 10}, pii{17, 16}};
    next[17][12] = vpi{pii{16, 15}, pii{18, 19}, pii{12, 17}};
    next[17][16] = vpi{pii{18, 13}, pii{12, 7}, pii{16, 17}};
    next[17][18] = vpi{pii{12, 6}, pii{16, 11}, pii{18, 17}};
    next[18][13] = vpi{pii{17, 16}, pii{19, 15}, pii{13, 18}};
    next[18][17] = vpi{pii{19, 14}, pii{13, 8}, pii{17, 18}};
    next[18][19] = vpi{pii{13, 7}, pii{17, 12}, pii{19, 18}};
    next[19][14] = vpi{pii{18, 17}, pii{15, 16}, pii{14, 19}};
    next[19][15] = vpi{pii{14, 8}, pii{18, 13}, pii{15, 19}};
    next[19][18] = vpi{pii{15, 10}, pii{14, 9}, pii{18, 19}};

    while(1){
        int tx,ty,n;
        cin >> tx >> ty >> n;
        if(tx==0 && ty==0 && n==0) break;

        memset(used, 0, sizeof(used));
        queue<info> wait;
        wait.push(info(0, 0, 0, 5, 0, true));
        used[101][51][0][5] = true;
        int ans = -1;
        while(!wait.empty()){
            int x = wait.front().x;
            int y = wait.front().y;
            int b = wait.front().b;
            int t = wait.front().t;
            int step = wait.front().step;
            int isEven = wait.front().isEven;
            wait.pop();
            if(x == tx && y == ty && b == n){
                ans = step;
                break;
            }
            int dx[3], dy[3];
            if(isEven){
                dx[0] = 1; dx[1] = -1; dx[2] = 0;
                dy[0] = 0; dy[1] = 0; dy[2] = 1;
            }else{
                dx[0] = -1; dx[1] = 1; dx[2] = 0;
                dy[0] = 0; dy[1] = 0; dy[2] = -1;
            }
            for(int i=0; i<3; i++){
                int nx = x +dx[i];
                int ny = y +dy[i];
                int nb = next[b][t][i].first;
                int nt = next[b][t][i].second;
                if(used[nx+101][ny+51][nb][nt]) continue;
                used[nx+101][ny+51][nb][nt] = true;
                wait.push(info(nx, ny, nb, nt, step+1, !isEven));
            }
        }
        cout << ans << endl;
    }

    return 0;
}