Under construction

Still being built. Things may change

Dogs

Time limit2sMemory limit256 MB

Summary
Given a directed inspection graph on n villagers, sum over all sick-dog configurations the day of the first shooting and the total number of dogs shot, modulo 998244353.
Level

Hard9 of 10

Topics
Graph, Combinatorics, Math
Solved
No attempts yet

Problem

In a village, there are nn villagers labeled with 1,2,…,n1, 2, \ldots, n. Each villager keeps a dog, and the dog is either healthy or sick.

On day 00, a man comes to the village and tells all the villagers an unpleasant truth: there is at least one sick dog in the village.

On day tt (t≥1t \geq 1), each villager ii inspects the dog of every villager jj such that Gi,j=1G_{i, j} = 1. All values Gi,jG_{i, j} are given in advance and known to all the villagers. For each dog inspected, the villager learns whether it is healthy or sick.

After all the inspections, if a villager can conclude that his own dog is sick, he shoots it in the afternoon. If more than one villager can reach such a conclusion, they all shoot simultaneously. All villagers immediately hear the shots. After that, nobody does anything about dogs until the next day.

The villagers do not exchange information in any way except what is described above.

  • If any shooting occurs on day tt, the process ends with shoot time tt.
  • If t<233nt < 233^n, the process continues on day t+1t+1.
  • Otherwise, the process ends with shoot time 00.

For each of the 2n−12^n-1 possible health states of the dogs, we record two values: the shoot time and the number of dogs shot. Find two sums: the sum of all recorded shoot times and the sum of the numbers of dogs shot. Since both may be very large, output them modulo 998 244 353998\,244\,353.

Input

The first line contains an integer nn (1≤n≤30001 \leq n \leq 3000).

The ii-th of the following nn lines contains nn binary digits without spaces: Gi,1,Gi,2,…,Gi,nG_{i, 1}, G_{i, 2}, \ldots, G_{i, n} (Gi,j∈{0,1}G_{i, j} \in \{0, 1\}, Gi,i=0G_{i, i} = 0).

Output

On the first line, print two integers: the sum of all recorded shoot times and the sum of the numbers of dogs shot, both modulo 998 244 353998\,244\,353.

Hint

For the first sample, there are three possible configurations:

  1. Dog 1 is sick and dog 2 is healthy. Villager 1 finds no other sick dog, so he shoots his own dog on day 1.
  2. Dog 2 is sick and dog 1 is healthy. On day 1, villager 1 is not sure about his own dog, so he does nothing. On day 2, villager 2 knows his dog must be sick, or villager 1 would have shot his own dog on day 1.
  3. Both dogs are sick. This case is similar to the second one.

Examples2

  1. Example 1

    Input
    2
    01
    00
    
    Expected output
    5 3
    
  2. Example 2

    Input
    2
    01
    10
    
    Expected output
    4 4