Under construction

Still being built. Things may change

Hard Linear Algebra Problem

Time limit1sMemory limit1024 MB

Summary
Given two invertible matrices A and B over a prime field, count the columns i where swapping column i between them keeps both invertible, for each cyclic shift of A.
Level

Hard8 of 10

Topics
Matrix, Linked list, Math
Solved
No attempts yet

Problem

The affinity of two invertible n×nn \times n matrices AA and BB over Z998244353Z_{998244353} is the number of indices ii (1≤i≤n1 \le i \le n) that satisfy the following condition.

  • If the ii-th column of AA and the ii-th column of BB are swapped, both AA and BB are still invertible.

In other words, the affinity is an integer from 00 to nn.

Define the matrix AiA_i as the matrix obtained from Ai−1A_{i-1} by moving its leftmost column to the rightmost position. A0=AA_0 = A.

For each integer ii with 0≤i<N0 \le i < N, find the affinity of AiA_i and BB.

Input

The first line contains a positive integer nn.

From the second line, the next nn lines give the matrix AA. Each line contains nn integers separated by spaces, and the jj-th integer on the (i+1)(i+1)-th line is AijA_{ij}.

From line n+2n+2, the next nn lines give the matrix BB. Each line contains nn integers separated by spaces, and the jj-th integer on the (i+n+1)(i+n+1)-th line is BijB_{ij}.

Output

Print nn integers on the first line, separated by spaces. The (i+1)(i+1)-th integer is the affinity of AiA_i and BB.

Constraints

  • 2≤n≤2002 \le n \le 200
  • Each entry of the matrices is an integer from 00 to 998244352998244352.
  • AA and BB are invertible.

Examples1

  1. Example 1

    Input
    4
    1 0 0 0
    0 1 0 0
    0 0 1 0
    0 0 0 1
    0 0 0 1
    0 0 1 0
    0 1 0 0
    1 0 0 0
    
    Expected output
    0 2 0 2