#abc209c. C - Not Equal

C - Not Equal

Score : 300300 points

问题描述

你将得到一个包含 NN 个整数的序列 CC。找出满足所有以下条件的整数序列 AA 的数量。

  • 对于 (1iN)(1 \leq i \leq N),有 1AiCi1 \leq A_i \leq C_i
  • 对于 (1i<jN)(1 \leq i < j \leq N),有 AiAjA_i \neq A_j

由于计数可能非常巨大,请以模 (109+7)(10^9+7) 的形式输出结果。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given a sequence CC of NN integers. Find the number of sequences AA of NN integers satisfying all of the following conditions.

  • 1AiCi(1iN)1 \leq A_i \leq C_i\, (1 \leq i \leq N)
  • AiAj(1i<jN)A_i \neq A_j\, (1 \leq i < j \leq N)

Since the count may be enormous, print it modulo (109+7)(10^9+7).

Constraints

  • 1N2×1051 \leq N \leq 2 \times 10^5
  • 1Ci1091 \leq C_i \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

C1C_1 C2C_2 \ldots CNC_N

Output

Print the number of sequences AA of NN integers satisfying all of the following conditions, modulo (109+7)(10^9+7).

Sample Input 1

2
1 3

Sample Output 1

2

We have two sequences AA satisfying all of the conditions: (1,2)(1,2) and (1,3)(1,3).
On the other hand, A=(1,1)A=(1,1), for example, does not satisfy the second condition.

Sample Input 2

4
3 3 4 4

Sample Output 2

12

Sample Input 3

2
1 1

Sample Output 3

0

We have no sequences AA satisfying all of the conditions, so we should print 00.

Sample Input 4

10
999999917 999999914 999999923 999999985 999999907 999999965 999999914 999999908 999999951 999999979

Sample Output 4

405924645

Be sure to print the count modulo (109+7)(10^9+7).

update @ 2024/3/10 09:22:43