atcoder#AGC048E. [AGC048E] Strange Relation
[AGC048E] Strange Relation
Score : points
Problem Statement
For an integer sequence of length , , and an integer , let defined as follows:
- is the lexicographically greatest integer sequence that satisfies all of the conditions below.
Here, under the constraints in this problem, it can be proved that there always are sequences that satisfy the conditions and that the number of those sequences is finite. Thus, can always be defined.
- is a sequence of length consisting of non-negative integers.
- For each (), let be the number of indices such that and . Then, holds.
For example, assume that and . Then, the sequences that satisfy the conditions are: , , and . Thus, the value of is the lexicographically maximum among them: .
Now, Snuke has integer sequences and an integer . Each of the sequences () is an integer sequence of length .
He will create an integer sequence of length and compute . The value of will be chosen from . Here, if contains the same value multiple times, we will distinguish those occurrences; that is, there are ways to create .
For every (), solve the following problem:
- For all choices of , we will compute and record the value of its -th element. Find the sum of these values, modulo .
Constraints
Input
Input is given from Standard Input in the following format:
Output
For every , print the answer in its own line.
2 2 1
1 2
1 2
0
3
- For :
- For :
- For :
- For :
Thus, the answer is for and for .
3 2 3
6 2
5 3
1 4
0
6
13
10 15 45
129 82 26 185 217 258 22 192 24 117 167 255 91 180 203
171 73 168 26 208 169 115 164 121 214 154 196 172 66 230
185 178 241 220 243 143 111 124 10 62 56 117 254 43 81
201 74 213 163 204 35 44 203 207 73 218 60 243 51 250
229 117 212 245 112 152 206 96 266 165 105 94 231 41 27
261 201 258 111 100 72 239 31 199 203 226 151 72 268 44
94 19 47 243 133 174 141 82 190 62 175 256 126 123 210
186 64 73 82 68 183 261 120 265 212 18 24 36 152 92
205 101 186 91 172 153 91 242 141 97 247 193 45 245 66
225 97 162 213 61 219 184 195 80 203 79 72 269 258 199
0
248044096
333666695
536381826
8787512
11659012
661959013
166067001
529828166
526544756