#P9249. Graph Travel Enjoyment

    ID: 22404 Type: Default 1000ms 256MiB

Graph Travel Enjoyment

Graph Travel Enjoyment

You are given a directed graph with n nodes labeled from 0 to n-1. For each ordered pair of nodes i and j, there are Ai,j directed edges from node i to node j (self‐loops are allowed).

A travel is defined as follows: you choose an arbitrary starting node, and then take a walk along one or more edges (i.e. at least one step), ending at some node. The enjoyment value of a travel is defined as the bitwise AND of the starting node and the ending node. Two travels are considered different if they either have a different number of steps or differ in at least one traversed edge.

Now, you perform several travels (at least one travel) in sequence. The total number of steps taken over all travels is x (with x in the range [1, m]). For each travel in the sequence, let its enjoyment value be computed as above; then the overall enjoyment of the sequence is defined as the bitwise AND of the enjoyment values of all travels in that sequence.

Your task is: for every x (1 ≤ x ≤ m) and every possible enjoyment value y (0 ≤ y < n), count the number of travel sequences such that the total number of steps equals x and the overall enjoyment is exactly y. As the answer can be huge, all counting is done modulo 998244353.

Finally, to avoid outputting too many numbers, you should compute the bitwise XOR of all these n × m numbers (after taking modulo 998244353 for each). Note that two travel sequences are considered different if they differ in the number of travels or in at least one travel (i.e. even if some travels are identical, the ordering matters).

For convenience, it is guaranteed that n is a power of 2.

Input Format: The input begins with two integers n and m. Then follow n lines, each containing n nonnegative integers. The j-th number in the i-th line denotes Ai,j, the number of directed edges from node i to node j.

Output Format: Output a single integer, which is the bitwise XOR of all counts (modulo 998244353) over all x (from 1 to m) and all y (from 0 to n-1).

inputFormat

The first line contains two integers n and m (n is a power of 2).

Then n lines follow, each containing n space‐separated nonnegative integers. The j-th number in the i-th line is Ai,j.

outputFormat

Output a single integer – the bitwise XOR of all the n*m counts (each computed modulo 998244353), where the counts are defined for each total step count x (from 1 to m) and each enjoyment value y (from 0 to n-1).

sample

2 1
1 1
1 1
2