#P981G. Magic multisets
Magic multisets
No submission language available for this problem.
Description
In the School of Magic in Dirtpolis a lot of interesting objects are studied on Computer Science lessons.
Consider, for example, the magic multiset. If you try to add an integer to it that is already presented in the multiset, each element in the multiset duplicates. For example, if you try to add the integer to the multiset , you will get .
If you try to add an integer that is not presented in the multiset, it is simply added to it. For example, if you try to add the integer to the multiset , you will get .
Also consider an array of initially empty magic multisets, enumerated from to .
You are to answer queries of the form "add an integer to all multisets with indices " and "compute the sum of sizes of multisets with indices ". The answers for the second type queries can be large, so print the answers modulo .
The first line contains two integers and () — the number of magic multisets in the array and the number of queries, respectively.
The next lines describe queries, one per line. Each line starts with an integer () — the type of the query. If equals , it is followed by three integers , , (, ) meaning that you should add to all multisets with indices from to inclusive. If equals , it is followed by two integers , () meaning that you should compute the sum of sizes of all multisets with indices from to inclusive.
For each query of the second type print the sum of sizes of multisets on the given segment.
The answers can be large, so print them modulo .
Input
The first line contains two integers and () — the number of magic multisets in the array and the number of queries, respectively.
The next lines describe queries, one per line. Each line starts with an integer () — the type of the query. If equals , it is followed by three integers , , (, ) meaning that you should add to all multisets with indices from to inclusive. If equals , it is followed by two integers , () meaning that you should compute the sum of sizes of all multisets with indices from to inclusive.
Output
For each query of the second type print the sum of sizes of multisets on the given segment.
The answers can be large, so print them modulo .
Samples
Note
In the first example after the first two queries the multisets are equal to , after the third query they are equal to .
In the second example the first multiset evolves as follows:
.