#include using namespace std; #ifdef ONLINE_JUDGE #define dbg(...) #else #include "Assets/debug.h" #endif #define int long long #define ll long long #define endl '\n' #define all(x) x.begin(), x.end() #define sz(x) (int)(x).size() #define yes cout << "YES" << endl #define no cout << "NO" << endl #define rep(i,a,b) for(int i=a; i=b; --i) #define pb push_back #define ppb pop_back #define ins insert #define ff first #define ss second #define FAST (ios_base::sync_with_stdio(false), cin.tie(nullptr)); ll pow(ll x,ll y,ll m=1e9+7){ll ans=1;x%=m;while(y){if(y&1)ans=(ans*x)%m;x=(x*x)%m;y>>=1;}return ans;} void solve() { int n,k; cin>>n>>k; map>m; rep(i,0,n) { int x; cin>>x; m[x%k].pb(x/k); } int odd=n&1, ans=0; for(auto it:m) { vector&v=it.second; int len = sz(v); sort(all(v)); if(len&1) { if(!odd) { cout<<-1<pf(len,0),sf(len,0); pf[1]=v[1]-v[0]; sf[len-2]=v[len-1]-v[len-2]; for(int i=3; i=0; i-=2) sf[i]=sf[i+2]+v[i+1]-v[i]; int mn=INT_MAX; for(int i=0; i0) sum+=pf[i-1]; if(i> TCS; for (int TC = 1; TC <= TCS; ++TC) { // cout<<"Case "<