logo AlgoBeat OnlineJudge
登录 注册

#215802. [JAG 2024 Summer Camp #3] Commutativity

内存限制:1024 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

You are given a function . In other words, is a function that takes an integer between and inclusive and returns an integer between and inclusive. Your task is to count the number of functions such that and commute under composition: that is, holds for any . As this number could be large, print the answer modulo .

输入格式

The input consists of a single test case of the following format.

The first line consists of an integer between and , inclusive. The second line consists of positive integers . For each , represents the value of . It is guaranteed that .

输出格式

Print the number of possible functions modulo .

样例

样例输入 1

5
4 5 3 2 1

样例输出 1

5

样例输入 2

8
2 3 1 3 6 7 5 5

样例输出 2

64

样例输入 3

10
3 1 4 1 5 9 2 6 5 3

样例输出 3

64

样例输入 4

15
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

样例输出 4

567381138