#P7156. [USACO20DEC] Cowmistry P
[USACO20DEC] Cowmistry P
Problem Description
Bessie's chemistry homework has been overdue for a long time, and now she needs your help. She needs to make a mixture using three different chemicals. All smart cows know that some chemicals cannot be mixed together, or they will explode. Specifically, two chemicals labeled and can appear in the same mixture when ().
Note: Here, denotes the XOR of non-negative integers and . This operation is equivalent to adding each corresponding bit in binary and discarding carries. For example,
,
,
.
Bessie has boxes of chemicals. The -th box contains chemicals with labels from to (). No two boxes contain the same chemical. She wants to know how many different mixtures she can make that consist of three different chemicals. Two mixtures are considered different if there exists at least one chemical that appears in one mixture but not the other. Since the answer may be very large, output it modulo .
Input Format
The first line contains two integers and .
The next lines each contain two space-separated integers and . It is guaranteed that the boxes are given in increasing order by their contents; that is, for all , we have .
Output Format
Output the number of mixtures Bessie can make using three different chemicals, modulo .
1 13
0 199
4280
6 147
1 35
48 103
125 127
154 190
195 235
240 250
267188
Hint
We can divide all chemicals into groups that cannot be mixed across groups: , , … . Each of the first groups contributes mixtures, and the last group contributes (because all combinations of three different chemicals in are valid), for a total of .
- Subtasks 3-4 satisfy .
- Subtasks 5-6 satisfy for some .
- Subtasks 7-11 satisfy .
- Subtasks 12-16 satisfy .
- Subtasks 17-21 have no additional constraints.
For all subtasks, .
Problem by: Benjamin Qi.
Translated by ChatGPT 5