#C3118. Matrix Operations: Sum, Product, and Cumulative Sum

    ID: 46510 Type: Default 1000ms 256MiB

Matrix Operations: Sum, Product, and Cumulative Sum

Matrix Operations: Sum, Product, and Cumulative Sum

You are given a square matrix of size \(N \times N\). Your task is to perform the following operations:

  • Compute the sum along axis 0 (i.e. sum each column). Mathematically, for each column \(j\), compute \(S_j = \sum_{i=0}^{N-1} a_{ij}\).
  • Compute the product along axis 1 (i.e. product of each row). For each row \(i\), compute \(P_i = \prod_{j=0}^{N-1} a_{ij}\).
  • Compute the cumulative sum of the matrix when it is flattened in row-major order. That is, if the flattened array is \([a_1, a_2, \dots, a_{N^2}]\), compute \(C_k = \sum_{i=1}^{k} a_i\) for \(1 \le k \le N^2\).

Input is provided via standard input and output should be printed to standard output.

inputFormat

The input consists of:

  1. An integer \(N\) denoting the dimension of the square matrix.
  2. \(N\) lines follow, each containing \(N\) space-separated integers representing the matrix rows.

Read from standard input.

outputFormat

The output should consist of three lines:

  1. The first line contains \(N\) space-separated integers representing the sum of each column.
  2. The second line contains \(N\) space-separated integers representing the product of each row.
  3. The third line contains \(N^2\) space-separated integers representing the cumulative sum of the flattened matrix.

Print the result to standard output.

## sample
2
1 2
3 4
4 6

2 12 1 3 6 10

</p>