O(N^3) algorithm for matrix subsum, UVs 108