import math
t=int(input())
for zz in range(t):
n=int(input())
l=list(map(int,input().split()))
s=sum(l)
if s%n==0:
print(0)
else:
print(1)
#include<bits/stdc++.h>
#include <iostream>
#define ll long long
#include <algorithm>
#define int long long int
#define take(x) for(auto& a:x)cin>>a
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define arrmin(x) *min_element(all(x))
#define arrmax(x) *max_element(all(x))
#define arrsum(x) accumulate(all(x), 0LL)
#define arrpre(x) partial_sum(all(x), x.begin())
#define arrsuf(x) partial_sum(allr(x), x.rbegin())
#define give(x) for(auto a:x){cout<<a<<' ';}cout<<endl
#define PI 3.1415926535897932384626
#define F first
#define S second
#define pb push_back
#define si set <int>
#define vi vector <int>
#define pii pair <int, int>
#define vpi vector <pii>
#define vpp vector <pair<int, pii>>
#define mii map <int, int>
#define mpi map <pii, int>
#define spi set <pii>
#define double long double
#define que_max priority_queue <int>
#define que_min priority_queue <int, vi, greater<int>>
#define mini *min_element(a,a + n);
#define maxi *max_element(a,a + n);
#define maxis *max_element(s.begin(),s.end());
#define minis *min_element(s.begin(),s.end());
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define ppc(x) __builtin_popcount(x);
#define ppcl(x) __builtin_popcountll(x);
#define clz(x) __builtin_clz(x); // // Leading zeroes count
#define ctz(x) __builtin_ctz(x); // Trailing zeroes count
#define nline endl;
#define print(x) cout << x << endl
#define mod 1000000007
using namespace std;
int gcd( int n1, int n2){
if(n2==0)
return n1;
return gcd(n2,n1%n2);
}
int lcm (int n1, int n2) {
return (n1 / gcd(n1, n2)) * n2;
}
int power(int a, int n)
{
// Stores final answer
int ans = 1;
while (n > 0) {
int last_bit = (n & 1);
// Check if current LSB
// is set
if (last_bit) {
ans = ans * a;
}
a = a * a;
// Right shift
n = n >> 1;
}
return ans;
}
int no_of_digits(int n)
{
return (floor(log10(n)) + 1);
}
bool isPrime(int n)
{
// Corner case
if (n <= 1)
return false;
// Check from 2 to square root of n
for (int i = 2; i <= sqrt(n); i++)
if (n % i == 0)
return false;
return true;
}
int largestPower(int n, int p)
{
// Initialize result
int x = 0;
// Calculate x = n/p + n/(p^2) + n/(p^3) + ....
while (n) {
n /= p;
x += n;
}
return x;
}
int mex(int n)
{
int k=0;
if(k!=n)return k;
return k+1;
}
bool sortbysecdesc(const pair<int,int> &a,
const pair<int,int> &b)
{
if(a.first == b.first){
return a.second <b.second;
}
else
return a.first>b.first;
}
int BinarySearchUminus(int val, vector<int> &A)
{
int low = 0 ,high = A.size()-1;
while (high>low)
{
int mid = (low + high+1)/2;
if(A[mid] == val)
low = mid; // high = mid-1 for lower_bound-1
else
if(A[mid]<val)
low = mid;
else
high = mid -1;
}
if(A[low] > val)
return -1;
return low;
}
int number_of_factors_sqrt_time(int x)
{
vector <int> result;
int i = 1;
// This will loop from 1 to int(sqrt(x))
while(i*i <= x) {
// Check if i divides x without leaving a remainder
if(x % i == 0) {
result.push_back(i);
// Handle the case explained in the 4th
if(x/i != i) {
result.push_back(x/i);
}
}
i++;
}
return result.size();
}
int palindrome(vector<int> arr)
{
// Initialise flag to zero.
int flag = 0;
int n = arr.size();
// Loop till array size n/2.
for (int i = 0; i <= n / 2 && n != 0; i++) {
// Check if first and last element are different
// Then set flag to 1.
if (arr[i] != arr[n - i - 1]) {
flag = 1;
break;
}
}
if (flag == 1)
return 0;
else
return 1;
}
int highestPoweroftwo(int n)
{
int p = (int)log2(n);
return (int)pow(2, p);
// int res = 0;
// for (int i = n; i >=1; i--)
// {
// /* code */
// if((i&(i-1)) == 0)
// {
// res = i;
// break;
// }
// }
// return res;
}
int ceil(int a , int b)
{
int ans = a/b;
if(a%b!=0)
ans++;
return ans;
}
bool compare(pair<int,int>a,pair<int,int>b){
//sort pairs in decreasing order of the second elements
//of the pairs.If both the second elements are equal sort
//according to increasing order of the first elements of the pairs.
if(a.second==b.second)
return a.first<b.first;
return a.second>b.second;
}
bool ispossible(int a[],int n,int mid,int k)
{
int cow = 1;
int last_pos = a[0];
for(int i=0;i<n;i++)
{
if(a[i] - last_pos >= mid)
{
cow ++;
if(cow == k)
return true;
last_pos = a[i];
}
}
return false;
}
int min(int x,int y)
{
if(x>=y) return y;
return x;
}
int fact(int n)
{
if(n==1)
{
return 1;
}
return n*fact(n-1);
}
// 1st element by increasing second element by increasing
bool sortbyCond(const pair<int, int>& a,
const pair<int, int>& b)
{
if (a.first != b.first)
return (a.first < b.first);
else
return (a.second > b.second);
}
string multiply(string num1, string num2)
{
int len1 = num1.size();
int len2 = num2.size();
if (len1 == 0 || len2 == 0)
return "0";
vector<int> result(len1 + len2, 0);
int i_n1 = 0;
int i_n2 = 0;
for (int i=len1-1; i>=0; i--)
{
int carry = 0;
int n1 = num1[i] - '0';
i_n2 = 0;
for (int j=len2-1; j>=0; j--)
{
int n2 = num2[j] - '0';
int sum = n1*n2 + result[i_n1 + i_n2] + carry;
carry = sum/10;
result[i_n1 + i_n2] = sum % 10;
i_n2++;
}
if (carry > 0)
result[i_n1 + i_n2] += carry;
i_n1++;
}
int i = result.size() - 1;
while (i>=0 && result[i] == 0)
i--;
if (i == -1)
return "0";
string s = "";
while (i >= 0)
s += std::to_string(result[i--]);
return s;
}
string findDiff(string str1, string str2)
{
string str = "";
int n1 = str1.length(), n2 = str2.length();
int diff = n1 - n2;
int carry = 0;
for (int i = n2 - 1; i >= 0; i--) {
int sub = ((str1[i + diff] - '0') - (str2[i] - '0')
- carry);
if (sub < 0) {
sub = sub + 10;
carry = 1;
}
else
carry = 0;
str.push_back(sub + '0');
}
for (int i = n1 - n2 - 1; i >= 0; i--) {
if (str1[i] == '0' && carry) {
str.push_back('9');
continue;
}
int sub = ((str1[i] - '0') - carry);
if (i > 0 || sub > 0) // remove preceding 0's
str.push_back(sub + '0');
carry = 0;
}
reverse(str.begin(), str.end());
return str;
}
int msbPos(ll n)
{
int msb_p = 0;
while (n)
{
n = n>>1;
msb_p++;
}
return msb_p;
}
// Function to find Bit-wise & of all numbers from x
// to y.
ll andOperator(ll x, ll y)
{
ll res = 0; // Initialize result
while (x && y)
{
// Find positi ons of MSB in x and y
int msb_p1 = msbPos(x);
int msb_p2 = msbPos(y);
// If positions are not same, return
if (msb_p1 != msb_p2)
break;
// Add 2^msb_p1 to result
ll msb_val = (1 << msb_p1);
res = res + msb_val;
// subtract 2^msb_p1 from x and y.
x = x - msb_val;
y = y - msb_val;
}
return res;
}
string convert(int &n)
{
return to_string(n);
}
int convert1(string s)
{
return stoll(s);
}
int modInverse(int a){
return power(a,mod-2);
}
int powermod(int a,int b) {
int res=1;
a%=mod;
assert(b>=0);
for(;b;b>>=1){
if(b&1)
res=res*a%mod;
a=a*a%mod;
}
return res;
}
void driver()
{
int n; cin >> n;
vi a(n);
take(a);
int x = arrsum(a);
if(x%n==0)
{
cout << 0 << endl;
return;
}
cout << 1 << endl;
}
int32_t main()
{
ios_base::
sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input1.txt" , "r" ,stdin);
freopen("output1.txt" , "w" ,stdout);
#endif
clock_t z = clock();
int t;
//int t = 1;
cin >> t;
while(t--)
{
driver();
}
cerr << "Run Time : " << ((double)(clock() - z) / CLOCKS_PER_SEC);
}
580A- Kefa and First Steps | 1472B- Fair Division |
996A - Hit the Lottery | MSNSADM1 Football |
MATCHES Playing with Matches | HRDSEQ Hard Sequence |
DRCHEF Doctor Chef | 559. Maximum Depth of N-ary Tree |
821. Shortest Distance to a Character | 1441. Build an Array With Stack Operations |
1356. Sort Integers by The Number of 1 Bits | 922. Sort Array By Parity II |
344. Reverse String | 1047. Remove All Adjacent Duplicates In String |
977. Squares of a Sorted Array | 852. Peak Index in a Mountain Array |
461. Hamming Distance | 1748. Sum of Unique Elements |
897. Increasing Order Search Tree | 905. Sort Array By Parity |
1351. Count Negative Numbers in a Sorted Matrix | 617. Merge Two Binary Trees |
1450. Number of Students Doing Homework at a Given Time | 700. Search in a Binary Search Tree |
590. N-ary Tree Postorder Traversal | 589. N-ary Tree Preorder Traversal |
1299. Replace Elements with Greatest Element on Right Side | 1768. Merge Strings Alternately |
561. Array Partition I | 1374. Generate a String With Characters That Have Odd Counts |