#K35407. Matrix Product Trace

    ID: 25524 Type: Default 1000ms 256MiB

Matrix Product Trace

Matrix Product Trace

You are given two square matrices A and B of size n \times n. Your task is to compute the trace of the product of these matrices, i.e., compute \( \text{trace}(A \times B) \). The product of two matrices is defined by:

\[ (AB)_{ij} = \sum_{k=1}^{n} a_{ik} \times b_{kj} \]

The trace of a matrix is the sum of its main diagonal elements. That is, for a matrix M of size n \times n,

\[ \text{trace}(M) = \sum_{i=1}^{n} m_{ii} \]

You are to compute \(\text{trace}(A \times B)\) given the matrices A and B.

inputFormat

The input is given in the following format from standard input:

  1. An integer n representing the size of the square matrices.
  2. n lines, each containing n space-separated integers representing the rows of matrix A.
  3. n lines, each containing n space-separated integers representing the rows of matrix B.

outputFormat

Output a single integer, which is the trace of the product matrix A \times B, printed to standard output.

## sample
2
1 2
3 4
5 6
7 8
69