import math N = int(input()) freq = [0] * N for i in range(N): a = int(input()) if a < N: freq[a] += 1 freq.sort() if freq[-1] == N: print(0) else: print(math.factorial(N-1) % (10**9+7))