For each row and then column of a matrix, we can add an extra entry with the sum of the last two entries in that row or column. For example with the following input matrix:
[ 1 1 1 ]
[ 2 3 4 ]
The resulting matrix would be:
[ 1 1 1 2 ]
[ 2 3 4 7 ]
[ 3 4 5 9 ]
Given an input of an integer N and an [X,Y] matrix of size at least 2x2, perform the above expansion N times and output the result. The resulting matrix will always be of size [X+N,Y+N].
Examples:
Input: Output:
2, [ 0 0 ] [ 0 0 0 0 ]
[ 0 0 ] [ 0 0 0 0 ]
[ 0 0 0 0 ]
[ 0 0 0 0 ]
3, [ 1 1 1 ] [ 1 1 1 2 3 5 ]
[ 2 3 4 ] [ 2 3 4 7 11 18 ]
[ 3 4 5 9 14 23 ]
[ 5 7 9 16 25 41 ]
[ 8 11 14 25 39 64 ]