## GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

# [Solution] Difference Array Solution Codeforces | Codeforces Solution

D. Difference Array
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given an array $a$ consisting of $n$ non-negative integers. It is guaranteed that $a$ is sorted from small to large.

For each operation, we generate a new array ${b}_{i}={a}_{i+1}-{a}_{i}$ for $1\le i. Then we sort $b$ from small to large, replace $a$ with $b$, and decrease $n$ by $1$.

After performing $n-1$ operations, $n$ becomes $1$. You need to output the only integer in array $a$ (that is to say, you need to output ${a}_{1}$).

Input

The input consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le {10}^{4}$) — the number of test cases. The description of the test cases follows.

Solution Click Below:-  👉
👇👇👇👇👇

The first line of each test case contains one integer $n$ ($2\le n\le {10}^{5}$) — the length of the array $a$.

The second line contains $n$ integers ${a}_{1},{a}_{2},\dots ,{a}_{n}$ ($0\le {a}_{1}\le \dots \le {a}_{n}\le 5\cdot {10}^{5}$) — the array $a$.

It is guaranteed that the sum of $n$ over all test cases does not exceed $2.5\cdot {10}^{5}$, and the sum of ${a}_{n}$ over all

Difference Operations Codeforces Solution

Difference of GCDs Codeforces Solution

Doremy's IQ Codeforces Solution

Difference Array Solution Codeforces

Partial Virtual Trees Codeforces Solution

DFS Trees Codeforces Solution

test cases does not exceed $5\cdot {10}^{5}$.

Output

For each test case, output the answer on a new line.