#P5027. The Heaviest Triangle
The Heaviest Triangle
The Heaviest Triangle
A large triangle recounts its past to a little square. In its glorious history it was a treasure hunter, but after being corrupted by the Dark Lord it reached its current state. Now it hopes that the little square can defeat the Dark Lord. However, the Dark Lord has spies everywhere, so the large triangle sets up an obstacle: it gives the little square a puzzle to solve.
The puzzle is as follows: There are n small triangles, each with a positive integer weight. The large triangle measured their weights in n+1 weighings. However, due to a faulty balance, exactly one of the weighings is wrong. The weighings are conducted as follows:
- The first weighing gives the total weight S of all n triangles.
- The i-th weighing (for 2 ≤ i ≤ n+1) gives the total weight of all triangles except the (i-1)-th one. That is, if the weight of triangle i-1 is wi-1, then the i-th weighing should be S - wi-1.
One of these n+1 measurements is wrong. Moreover, the input is legal if and only if there does not exist two different indices i and j such that assuming the i-th measurement is wrong yields one valid solution and assuming the j-th measurement is wrong also yields one valid solution.
A valid solution must satisfy:
- The heaviest triangle is unique.
- The weight of every triangle is determined uniquely.
- All triangles have positive integer weights.
Your task is to help the little square determine the index (1-indexed) of the heaviest triangle.
inputFormat
The first line contains an integer n (n ≥ 2), the number of triangles.
The next n+1 lines each contain an integer. The first integer is the result of weighing all triangles together. The following n integers are the results of weighing all triangles except the 1st, 2nd, …, n-th triangle respectively. Exactly one of these n+1 measurements is wrong. It is guaranteed that the input is legal as described in the problem statement.
outputFormat
Output a single integer — the index (1-indexed) of the heaviest triangle.
sample
3
18
13
999
15
2