

Time Limit: 4 sec / Memory Limit: 1024 MB
配点 : 点
問題文
整数 が与えられます。このとき、以下の条件を全て満たす長さ の数列 を考えます。
- は を満たす整数である
- の全ての要素は相異なる
として考えられる数列を辞書順に全て並べた 「数列の列」 を辞書 とします。
辞書 中に存在する数列 が与えられるので、整数 に対して以下の質問に答えてください。
- 以下の条件を全て満たす数列 の個数を で割った余りを求めよ。
- 数列 は辞書 中に存在する。
- 数列 中に整数 が含まれる。
- 数列 は辞書順で数列 以下である。
数列の辞書順とは?
数列 が より辞書順で真に小さいとは、下記の 1. と 2. のどちらかが成り立つことを言います。- かつ である。
- ある整数 が存在して、下記の つがともに成り立つ。
制約
- 入力は全て整数
- は問題文中の条件を満たす。
入力
入力は以下の形式で標準入力から与えられる。
出力
全体で 行出力せよ。
このうち 行目には、 であるときの質問の答えを整数として出力せよ。
入力例 1Copy
4 2 3 2
出力例 1Copy
5 5 4 2
この入力では、 です。
このとき、辞書 となります。
辞書 に含まれ、かつ辞書順で 以下である数列のうち、
- が含まれるものは の 個
- が含まれるものは の 個
- が含まれるものは の 個
- が含まれるものは の 個
です。
入力例 2Copy
18 13 5 13 11 2 18 1 10 15 17 4 12 7 3
出力例 2Copy
925879409 905921009 665544804 665544719 783035803 349952762 349952758 349952757 349952757 349921178 212092637 710350150 378895603 129113201 129111892 129098081 129096772 110181652
Score: points
Problem Statement
You are given integers and . Consider a sequence of length that satisfies all of the following conditions:
- is an integer such that .
- All elements in are different.
Let us arrange all possible sequences in lexicographical order to form a "sequence of sequences" called the dictionary .
Given a sequence that exists in the dictionary , answer the following question for each integer :
- Find the number, modulo , of sequences that satisfy all of the following conditions:
- The sequence exists in the dictionary .
- The integer is contained in the sequence .
- The sequence is lexicographically less than or equal to the sequence .
What is lexicographical order for sequences?
A sequence is lexicographically strictly less than if and only if 1. or 2. below is satisfied:- and .
- There is an integer that satisfies both of the following:
Constraints
- All input values are integers.
- satisfies the condition in the problem statement.
Input
The input is given from Standard Input in the following format:
Output
Print lines in total.
The -th line should contain the answer to the problem for as an integer.
Sample Input 1Copy
4 2 3 2
Sample Output 1Copy
5 5 4 2
In this input, .
Here, the dictionary is .
Among the sequences in the dictionary that are lexicographically less than or equal to ,
- five sequences contain : ,
- five sequences contain : ,
- four sequences contain : ,
- two sequences contain : .
Sample Input 2Copy
18 13 5 13 11 2 18 1 10 15 17 4 12 7 3
Sample Output 2Copy
925879409 905921009 665544804 665544719 783035803 349952762 349952758 349952757 349952757 349921178 212092637 710350150 378895603 129113201 129111892 129098081 129096772 110181652