Qnp
Time limit1.5sMemory limit256 MB
For each query, find the K-th smallest arrangement of the given digit counts (leading zeros allowed), modulo 10^9 + 7, with K up to 10^12.
- Level
Medium7 of 10
- Topics
- Combinatorics, Math, Implementation
- Solved
- No attempts yet
Problem
You are given some digits. Find the -th smallest integer that consists of exactly the given digits, modulo . Answer queries. Each query gives the frequencies of digits , , , , followed by an integer .
Integers with leading zeroes are also counted.
Input
The first line contains a single integer ().
Each of the next lines contains 11 integers. The first ten are the frequencies of digits , , , . The last one is the integer (). In each query, the total number of digits is at least 1 and at most .
Output
Print lines. The -th line contains the answer for the -th query modulo .