// In Practice, You should use the statndard input/output
// in order to receive a score properly.
// Do not use file input and output. Please be very careful.
#include <stdio.h>
int main(void)
{
int tc, T;
// The freopen function below opens input.txt file in read only mode, and afterward,
// the program will read from input.txt file instead of standard(keyboard) input.
// To test your program, you may save input data in input.txt file,
// and use freopen function to read from the file when using scanf function.
// You may remove the comment symbols(//) in the below statement and use it.
// But before submission, you must remove the freopen function or rewrite comment symbols(//).
// freopen("input.txt", "r", stdin);
// If you remove the statement below, your program's output may not be rocorded
// when your program is terminated after the time limit.
// For safety, please use setbuf(stdout, NULL); statement.
scanf("%d", &T);
for(tc = 0; tc < T; tc++)
{
/**********************************
* Implement your algorithm here. *
***********************************/
int n;
scanf("%d",&n);
int i,a[n],sum=0;
for(i=0;i<n;i++) {
scanf("%d",&a[i]);
sum+=a[i];
}
int key=(sum/n),ans=0;
for(i=0;i<n;i++) {
if(a[i]>key)
ans+=(a[i]-key);
}
// Print the answer to standard output(screen).
printf("%d\n",ans);
}
return 0;//Your program should return 0 on normal termination.
}
Ci8vIEluIFByYWN0aWNlLCBZb3Ugc2hvdWxkIHVzZSB0aGUgc3RhdG5kYXJkIGlucHV0L291dHB1dAovLyBpbiBvcmRlciB0byByZWNlaXZlIGEgc2NvcmUgcHJvcGVybHkuCi8vIERvIG5vdCB1c2UgZmlsZSBpbnB1dCBhbmQgb3V0cHV0LiBQbGVhc2UgYmUgdmVyeSBjYXJlZnVsLiAKCiNpbmNsdWRlIDxzdGRpby5oPgoKaW50IG1haW4odm9pZCkKewoJaW50IHRjLCBUOwoJCgkvLyBUaGUgZnJlb3BlbiBmdW5jdGlvbiBiZWxvdyBvcGVucyBpbnB1dC50eHQgZmlsZSBpbiByZWFkIG9ubHkgbW9kZSwgYW5kIGFmdGVyd2FyZCwKCS8vIHRoZSBwcm9ncmFtIHdpbGwgcmVhZCBmcm9tIGlucHV0LnR4dCBmaWxlIGluc3RlYWQgb2Ygc3RhbmRhcmQoa2V5Ym9hcmQpIGlucHV0LgoJLy8gVG8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