#P9418. [POI 2021/2022 R1] Impreza krasnali

[POI 2021/2022 R1] Impreza krasnali

Background

Translated from XXIX Olimpiada Informatyczna – Stage I Impreza krasnali.

Problem Description

There are nn people standing in a line in order. Each person holds a number, and these nn numbers form a permutation.

Each person will choose one of two options to report: the number held by the person on their left or the number held by the person on their right. Note that the first person and the nn-th person are not adjacent, so the first person always reports the second person’s number, and the nn-th person always reports the (n1)(n-1)-th person’s number.

Now you are given the nn numbers reported by the nn people. Find how many different original permutations are possible.

Input Format

The first line contains a positive integer nn.

The second line contains nn integers, representing the number reported by each person.

Output Format

Output one integer: your answer modulo 109+710^9+7.

5
3 4 3 4 1

2

见附件
0
见附件
1

Hint

For all testdata, 2n1000002\leq n\leq 100000.

Subtask ID Additional Constraints Points
1 n10n\leq 10 12
2 n20n\leq 20 30
3 n1000n\leq 1000
4 28

Translated by ChatGPT 5