Algorithm


D1. All are Same
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

This problem is a simplified version of D2, but it has significant differences, so read the whole statement.

Polycarp has an array of n (n is even) integers a1,a2,,an�1,�2,…,��. Polycarp conceived of a positive integer k. After that, Polycarp began performing the following operations on the array: take an index i (1in1≤�≤�) and reduce the number ai�� by k.

After Polycarp performed some (possibly zero) number of such operations, it turned out that all numbers in the array became the same. Find the maximum k at which such a situation is possible, or print 1−1 if such a number can be arbitrarily large.

Input

The first line contains one integer t (1t101≤�≤10) — the number of test cases. Then t test cases follow.

Each test case consists of two lines. The first line contains an even integer n (4n404≤�≤40) (n is even). The second line contains n integers a1,a2,an�1,�2,…�� (106ai106−106≤��≤106).

It is guaranteed that the sum of all n specified in the given test cases does not exceed 100100.

Output

For each test case output on a separate line an integer k (k1�≥1) — the maximum possible number that Polycarp used in operations on the array, or 1−1, if such a number can be arbitrarily large.

Example
input
Copy
3
6
1 5 3 1 1 5
8
-1 0 1 -1 0 1 -1 0
4
100 -1000 -1000 -1000
output
Copy
2
1
1100

 



 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include<bits/stdc++.h>
using namespace std;


#define ll long long
#define endl '\n'
#define debug(n) cout<<(n)<<endl;
const ll INF = 2e18 + 99;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int t;
  cin>>t;
  while(t--){
    ll n;
    cin>>n;
    ll arr[n];
    for(ll i = 0; i < n; i++){
      cin>>arr[i];
    }

    sort(arr,arr+n);
    ll count = 0;

    for(ll i = 1; i < n; i++){
      count = __gcd(count, arr[i] - arr[i-1]);
    }

    if(count == 0){
        cout<<-1<<endl;
        continue;
    }
    cout<<count<<endl;
  }

}
Copy The Code & Try With Live Editor

Input

x
+
cmd
3
6
1 5 3 1 1 5
8
-1 0 1 -1 0 1 -1 0
4
100 -1000 -1000 -1000

Output

x
+
cmd
2
1
1100
Advertisements

Demonstration


Codeforcess Solution 1593-D1 D1. All are Same ,C++, Java, Js and Python ,1593-D1,Codeforcess Solution

Previous
Codeforces solution 1080-B-B. Margarite and the best present codeforces solution
Next
CodeChef solution DETSCORE - Determine the Score CodeChef solution C,C+