CF272D.Dima and Two Sequences
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Little Dima has two sequences of points with integer coordinates: sequence (a1,1),(a2,2),...,(an,n) and sequence (b1,1),(b2,2),...,(bn,n) .
Now Dima wants to count the number of distinct sequences of points of length 2⋅n that can be assembled from these sequences, such that the x -coordinates of points in the assembled sequence will not decrease. Help him with that. Note that each element of the initial sequences should be used exactly once in the assembled sequence.
Dima considers two assembled sequences (p1,q1),(p2,q2),...,(p2⋅n,q2⋅n) and (x1,y1),(x2,y2),...,(x2⋅n,y2⋅n) distinct, if there is such i (1<=i<=2⋅n) , that (pi,qi)=(xi,yi) .
As the answer can be rather large, print the remainder from dividing the answer by number m .
输入格式
The first line contains integer n (1<=n<=105) . The second line contains n integers a1,a2,...,an (1<=ai<=109) . The third line contains n integers b1,b2,...,bn (1<=bi<=109) . The numbers in the lines are separated by spaces.
The last line contains integer m (2<=m<=109+7) .
输出格式
In the single line print the remainder after dividing the answer to the problem by number m .
输入输出样例
输入#1
1 1 2 7
输出#1
1
输入#2
2 1 2 2 3 11
输出#2
2
说明/提示
In the first sample you can get only one sequence: (1,1),(2,1) .
In the second sample you can get such sequences : (1,1),(2,2),(2,1),(3,2) ; (1,1),(2,1),(2,2),(3,2) . Thus, the answer is 2 .