#K41977. Matrix Row and Column Sums
Matrix Row and Column Sums
Matrix Row and Column Sums
You are given an M×N matrix of integers. Your task is to compute the sum of the elements of each row and each column.
Input Format: The first line contains two integers, M and N, representing the number of rows and columns respectively. This is followed by M lines, each containing N space-separated integers representing the matrix.
Output Format: The output should consist of two lines. The first line contains M integers where the i-th integer is the sum of the i-th row. The second line contains N integers where the j-th integer is the sum of the j-th column.
Note: All sums should be computed in latex formatted mathematics if needed, e.g., for further explanations one may write: \(S_i = \sum_{j=1}^{N} a_{ij}\) and \(T_j = \sum_{i=1}^{M} a_{ij}\).
inputFormat
The first line of input contains two integers M and N separated by a space.
This is followed by M lines, each containing N space-separated integers that represent the elements of the matrix.
outputFormat
The first line of output should contain M integers representing the sum of elements of each row.
The second line of output should contain N integers representing the sum of elements of each column.
## sample3 3
1 2 3
4 5 6
7 8 9
6 15 24
12 15 18
</p>