Little Dima has two sequences of points with integer coordinates: sequence (a_1, 1), (a_2, 2), ..., (a_{n}, n) and sequence (b_1, 1), (b_2, 2), ..., (b_{n}, 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 (p_1, q_1), (p_2, q_2), ..., (p_{2·}n, q_{2·}n) and (x_1, y_1), (x_2, y_2), ..., (x_{2·}n, y_{2·}n) distinct, if there is such i (1 ≤ i ≤ 2·n), that (p_{i}, q_{i}) ≠ (x_{i}, y_{i}).

As the answer can be rather large, print the remainder from dividing the answer by number m.


-----Input-----

The first line contains integer n (1 ≤ n ≤ 10^5). The second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9). The third line contains n integers b_1, b_2, ..., b_{n} (1 ≤ b_{i} ≤ 10^9). The numbers in the lines are separated by spaces.

The last line contains integer m (2 ≤ m ≤ 10^9 + 7).


-----Output-----

In the single line print the remainder after dividing the answer to the problem by number m. 


-----Examples-----
Input
1
1
2
7

Output
1

Input
2
1 2
2 3
11

Output
2



-----Note-----

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.

Difficulty: MEDIUM_HARD
Tags: Sorting

Combinatorics

Mathematics
Skill types: Sorting

Starter code:

Solutions:
from math import sqrt, ceil, gcd
from collections import defaultdict

def modInverse(b, m):
	g = gcd(b, m)
	if g != 1:
		return -1
	else:
		return pow(b, m - 2, m)

def sol(n, m, rep):
	r = 1
	for i in range(2, n + 1):
		j = i
		while j % 2 == 0 and rep > 0:
			j //= 2
			rep -= 1
		r *= j
		r %= m
	return r

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	m = int(input())
	hash = defaultdict(int)
	e = defaultdict(int)
	for i in range(n):
		hash[a[i]] += 1
		hash[b[i]] += 1
		if a[i] == b[i]:
			e[a[i]] += 1
	ans = 1
	for i in hash:
		z1 = hash[i]
		z2 = e[i]
		ans *= sol(z1, m, z2)
		ans %= m
	print(ans)
solve()


from collections import defaultdict

def factorial(n, m, rep):
	r = 1
	for i in range(2, n + 1):
		j = i
		while j % 2 == 0 and rep > 0:
			j = j // 2
			rep -= 1
		r *= j
		r %= m
	return r
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
m = int(input())
ans = 1
d = defaultdict(lambda : 0)
e = defaultdict(lambda : 0)
i = 0
while i < n:
	d[a[i]] += 1
	d[b[i]] += 1
	if a[i] == b[i]:
		e[a[i]] += 1
	i += 1
ans = 1
for j in d:
	k = d[j]
	rep = e[j]
	ans = ans * factorial(k, m, rep)
	ans = ans % m
print(int(ans))


n = int(input())
(c, d) = ({}, {})
for (x, y) in zip(input().split(), input().split()):
	c[x] = c.get(x, 1) + 1
	c[y] = c.get(y, 1) + 1
	if x == y:
		d[x] = d.get(x, 0) + 2
(s, m) = (1, int(input()))
for (k, v) in c.items():
	u = d.get(k, 0)
	for i in range(v - u, v, 2):
		s = s * (i * i + i) // 2 % m
	for i in range(1, v - u):
		s = s * i % m
print(s)


n = input()
c_n = {}
d_n = {}
for (a_i, b_i) in zip(input().split(), input().split()):
	if a_i == b_i:
		d_n[a_i] = d_n.get(a_i, 0) + 2
	c_n[a_i] = c_n.get(a_i, 0) + 1
	c_n[b_i] = c_n.get(b_i, 0) + 1
result = 1
k = int(input())
for (a_i, cant) in c_n.items():
	cant_rep = d_n.get(a_i, 0)
	for i in range(cant - cant_rep + 1, cant, 2):
		result = result * i * (i + 1) // 2 % k
	for i in range(1, cant - cant_rep + 1):
		result = result * i % k
print(result)


n = int(input())
y = list(map(int, input().split()))
z = list(map(int, input().split()))
a = sorted([[y[i], i] for i in range(n)] + [[z[i], i] for i in range(n)])
f = 0
for i in range(n):
	if y[i] == z[i]:
		f += 1
m = int(input())
d = 0
e = 1
for i in range(1, 2 * n):
	if a[i][0] != a[i - 1][0]:
		for j in range(1, i - d + 1):
			while f > 0 and j % 2 == 0:
				j //= 2
				f -= 1
			e *= j
			e %= m
		d = i
for j in range(1, 2 * n - d + 1):
	while f > 0 and j % 2 == 0:
		j //= 2
		f -= 1
	e *= j
	e %= m
print(e % m)