#P5300. [GXOI/GZOI2019] 与或和

[GXOI/GZOI2019] 与或和

Description

After learning bitwise operations and matrices, Freda decided to further study these simple and elegant operations, as well as the structures that contain profound spaces.

For a matrix consisting of non-negative integers, she defines the AND\texttt{AND} value of the matrix as the result of applying bitwise AND(&)\texttt{AND(\&)} to all numbers in the matrix; she defines the OR\texttt{OR} value of the matrix as the result of applying bitwise OR(|)\texttt{OR(|)} to all numbers in the matrix.

Given an N×NN \times N matrix, she wants to compute:

  1. The sum of the AND\texttt{AND} values of all submatrices (the result of adding up the AND\texttt{AND} values of all submatrices).
  2. The sum of the OR\texttt{OR} values of all submatrices (the result of adding up the OR\texttt{OR} values of all submatrices).

You can probably guess what happens next—Freda does not want to spend time solving such a simple problem, so she leaves it to you.

Since the answer may be very large, you only need to output the result modulo 1,000,000,007(109+7)1,000,000,007 (10^9 + 7).

Input Format

The first line of the input file contains a positive integer NN, which denotes the size of the matrix.

The next NN lines each contain NN natural numbers, representing one row of the matrix. Any two adjacent natural numbers are separated by one or more spaces.

Output Format

Output a single line containing two integers separated by a space. The first should be the remainder when the sum of AND\texttt{AND} values of all submatrices is taken modulo 109+710^9 + 7, and the second should be the remainder when the sum of OR\texttt{OR} values of all submatrices is taken modulo 109+710^9 + 7.

3
1 0 0
0 0 0
0 0 0
1 9
3
1 2 3
4 5 6
7 8 9
73 314

Hint

Explanation of Sample 1

This 3×33 \times 3 matrix has 99 submatrices of size 1×11 \times 1, 66 submatrices of size 1×21 \times 2, 66 submatrices of size 2×12 \times 1, 44 submatrices of size 2×22 \times 2, 33 submatrices of size 1×31 \times 3, 33 submatrices of size 3×13 \times 1, 22 submatrices of size 2×32 \times 3, 22 submatrices of size 3×23 \times 2, and 11 submatrix of size 3×33 \times 3.
Only one submatrix (the 1×11 \times 1 matrix consisting only of the element in the first row and first column) has an AND\texttt{AND} value of 11; all other submatrices have an AND\texttt{AND} value of 00, so the total sum is 11.
There are 99 submatrices that contain the element in the first row and first column. Their OR\texttt{OR} value is 11, while all other submatrices have an OR\texttt{OR} value of 00, so the total sum is 99.

Constraints

Test Point ID Scale of nn Natural numbers in the matrix
11 1n101 \le n \le 10 100\le 100
22
33 1n1001 \le n \le 100
44
55
66 1n1,0001 \le n \le 1,000 2311\le 2^{31} - 1
77
88
99
1010

In addition, there is a set of unscored hack testdata placed in subtask 1, with the same constraints as test points 6106 \sim 10.

Translated by ChatGPT 5