public static void main(String[] args) throws Exception {
        long result = 0;

        int[][] input = readInput();
        long[][] sum = new long[input.length][];

        for (int row = 0; row < input.length; row++) {
            sum[row] = new long[input[row].length];
            for (int col = 0; col < input[row].length; col++) {
                long val = input[row][col];
                long bestPrevious = 0L;
                if (row - 1 >= 0) {
                    if (input[row - 1].length > col)
                        bestPrevious = sum[row - 1][col];
                    if (col - 1 >= 0 && sum[row - 1][col - 1] > bestPrevious)
                        bestPrevious = sum[row - 1][col - 1];
                }
                val += bestPrevious;
                sum[row][col] = val;
                if (row + 1 == input.length && val > result)
                    result = val;
            }
        }

        System.out.println("Result: " + result);

        System.exit(0);
    }