#P8850. [JRKSJ R5] Jalapeno and Garlic
[JRKSJ R5] Jalapeno and Garlic
Background

Problem Description
There is a cycle with vertices. Each vertex has a weight , and the vertices are numbered from to . Vertex is adjacent to vertex .
You want there to be exactly one such that . To achieve this, you need to perform operations according to the following process:
- Choose an , meaning that in the end you want . After that, you cannot change your choice of .
- Perform some number of modification operations. In each operation, you may choose a and set . At the same time, among the two vertices adjacent to , choose one uniformly at random, and its weight will be increased by .
You want the expected number of modification operations to be as small as possible. Therefore, compute the expected number of operations under the optimal strategy (operation 1 is not counted).
Input Format
The first line contains an integer .
The second line contains integers representing .
Output Format
Output an integer representing the answer. Print the answer modulo .
2
114514 1919810
114514
3
1 1 2
4
Hint
Explanation for Sample
Choose , and perform operations, each time taking .
Constraints
This problem uses bundled testdata.
| Score | ||
|---|---|---|
For of the testdata, and .
Translated by ChatGPT 5