第 1127 场 Codeforces Round(Div. 2,基于 2026 年墨西哥信息学奥林匹克竞赛)
A
Paco 的投影
The Projections of Paco
Codeforces
800
原题
←B →

Paco 的投影AI (CI翻译)

You are given $n$ integers $a_1, a_2, \ldots, a_n$ representing points on a number line. Paco has a token that starts at coordinate $0$.

给定 $n$ 个整数 $a_1, a_2, \ldots, a_n$,表示数轴上的一些点。Paco 有一个棋子,初始位于坐标 0。AI (CI翻译)

Reflecting the token about a point moves it to the other side of that point, keeping the same distance from it. If the token is already at that point, it stays there.

将棋子关于某个点进行反射,会将它移动到该点的另一侧,同时与该点保持相同的距离。如果棋子已经位于该点,则保持不动。AI (CI翻译)

image Paco's token (blue) being reflected about a point (red).

image Paco 的棋子(蓝色)关于某个点(红色)进行反射。AI (CI翻译)

Choose an integer $p$. Paco's token is reflected about the points with coordinates $p, a_1, a_2, \ldots, a_n$, in this order, exactly once each.

选择一个整数 $p$。Paco 将依次关于坐标为 $p, a_1, a_2, \ldots, a_n$ 的点各进行一次反射。AI (CI翻译)

Help Paco find $p$ such that his token ends at exactly coordinate $0$. This is very important for him. It can be shown that exactly one such integer exists.

请帮助 Paco 找到 $p$,使得他的棋子最终恰好位于坐标 0。这对他来说非常重要。可以证明,这样的整数恰好存在一个。AI (CI翻译)

Input

输入格式

AI (CI翻译)

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

每个测试包含多组测试用例。第一行包含测试用例的数量 $t$($1 \le t \le 10^4$)。接下来是各测试用例的描述。AI (CI翻译)

The first line of each test case contains a single integer $n$ ($1 \le n \le 10^5$).

每个测试用例的第一行包含一个整数 $n$($1 \le n \le 10^5$)。AI (CI翻译)

The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^4 \le a_i \le 10^4$).

第二行包含 $n$ 个整数 $a_1, a_2, \ldots, a_n$($-10^4 \le a_i \le 10^4$)。AI (CI翻译)

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.

保证所有测试用例中 $n$ 的总和不超过 $10^5$。AI (CI翻译)

Output

输出格式

AI (CI翻译)

For each test case, print the integer $p$.

对于每个测试用例,输出整数 $p$。AI (CI翻译)

Note

说明

AI (CI翻译)

In the first test case, choose $p=3$. Paco's token moves from $0$ to $6$ and then back to $0$.

在第一个测试用例中,选择 $p=3$。Paco 的棋子从 0 移动到 6,然后又回到 0。AI (CI翻译)

In the second test case, choose $p=-3$. Paco's token visits coordinates $0 \to -6 \to 10 \to 0$.

在第二个测试用例中,选择 $p=-3$。Paco 的棋子依次经过坐标 $0 \to -6 \to 10 \to 0$。AI (CI翻译)

In the third test case, choose $p=-4$. Paco's token visits coordinates $0 \to -8 \to 12 \to 2 \to 0$.

在第三个测试用例中,选择 $p=-4$。Paco 的棋子依次经过坐标 $0 \to -8 \to 12 \to 2 \to 0$。AI (CI翻译)

样例

Input #1
5
1
3
2
2 5
3
2 7 1
4
-3 0 -3 0
1
0
Output #1
3
-3
-4
-6
0
InputCopy OutputCopy
题目信息
标签
DFS 及类似
动态规划
哈希
模拟
数学

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