solution of Sum_Rec_matrix