#K65127. Matrix Addition

    ID: 32129 Type: Default 1000ms 256MiB

Matrix Addition

Matrix Addition

You are given two matrices A and B each of size \(N \times M\). Your task is to compute a new matrix C such that each element \(C_{ij}\) is the sum of \(A_{ij}\) and \(B_{ij}\). In other words, use the formula: $$C_{ij} = A_{ij} + B_{ij}$$ for all valid indices \(i\) and \(j\).

The input is read from standard input and the output should be printed to standard output. Each row of the resulting matrix should be printed on a new line, with individual elements separated by a single space.

inputFormat

The input begins with two integers (N) and (M) separated by a space, indicating the number of rows and columns respectively. This is followed by (N) lines, each containing (M) space-separated integers representing matrix A. Then, another (N) lines follow for matrix B.

outputFormat

Output the resulting (N \times M) matrix after performing element-wise addition. Each row should be printed on a new line with each element separated by a single space.## sample

2 3
1 2 3
4 5 6
7 8 9
10 11 12
8 10 12

14 16 18

</p>