Dogs
Time limit2sMemory limit256 MB
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 villagers labeled with . Each villager keeps a dog, and the dog is either healthy or sick.
On day , 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 (), each villager inspects the dog of every villager such that . All values 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 , the process ends with shoot time .
- If , the process continues on day .
- Otherwise, the process ends with shoot time .
For each of the 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 .
Input
The first line contains an integer ().
The -th of the following lines contains binary digits without spaces: (, ).
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 .
Hint
For the first sample, there are three possible configurations:
- 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.
- 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.
- Both dogs are sick. This case is similar to the second one.