Codeforces Round 1095 (Div. 2)
A
Disturbing Distribution
Codeforces
800
原题
←B →
翻译中…

You are given an array $[a_1, a_2, \ldots, a_n]$. You wish to make the array empty by performing the following operation any number of times:

翻译中…
  • Select any sequence of indices $1 \le i_1 \lt i_2 \lt \ldots \lt i_k \le |a|$ (note that $|a|$ denotes the current length of the array $a$) such that $$a_{i_1} \le a_{i_2} \le \ldots \le a_{i_k}$$
  • Remove the elements $a_{i_1}, a_{i_2}, \ldots, a_{i_k}$ from the array $a$.
  • This operation incurs a cost equal to $a_{i_1} \times a_{i_2} \times \cdots \times a_{i_k}$.
翻译中…

Determine the minimum total cost required to remove all the elements from the array $a$. Note that the total cost is equal to the sum of costs incurred over all the operations performed.

翻译中…

As the answer can be very large, report the answer modulo $676\,767\,677$.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 500$). The description of the test cases follows.

翻译中…

The first line of each testcase contains a single integer $n$ ($1 \le n \le 100$) — the length of the array $a$.

翻译中…

The second line of each testcase contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 100$) — the elements of the array.

翻译中…

Output

翻译中…

For each testcase, output a single integer — the minimum total cost required to make the array $a$ empty.

翻译中…

As the answer may be large, output the answer modulo $676\,767\,677$.

翻译中…

Note

翻译中…

For the first testcase,

翻译中…
  • Operation 1: Choose $i_1 = 1$, $i_2 = 2$, and $i_3 = 4$. This incurs a cost of $1 \cdot 2 \cdot 2 = 4$. After deleting the elements at these indices, the array becomes $a = [1, 3]$.
  • Operation 2: Choose $i_1 = 1$ and $i_2 = 2$. This incurs a cost of $1 \cdot 3 = 3$. After deleting the elements at these indices, the array becomes empty.
翻译中…

Thus, the total cost is equal to $4 + 3 = 7$. It can be shown that this is the minimum possible total cost.

翻译中…

样例

Input #1
3
5
1 2 1 2 3
3
3 2 1
4
1 1 1 1
Output #1
7
6
1
InputCopy OutputCopy
题目信息
题号
2226A
时间限制
1 s
内存限制
256 MB
标签
贪心
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。