static const int C[][3] = {{0, 0, 0}, {1, 1, -2}, {2, -1, -1}}; int mastur(const int i, const int x, const int y) { return i + C[x][i / y % 3] * y; }