public static Cell[][] preprocess(int[][] matrix) {
        int size = matrix.length;
        Cell[][] cells = new Cell[size][size];

        for (int i = size - 1; i >= 0; --i) {
            for (int j = size - 1; j >= 0; --j) {
                int right = matrix[i][j] + (j == size - 1 ? 0 : cells[i][j + 1].availableRight);
                int below = matrix[i][j] + (i == size - 1 ? 0 : cells[i + 1][j].availableBelow);
                cells[i][j] = new Cell(below, right);
            }
        }
        return cells;
    }