n, k = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
mi = min(a)
res = 0
for i in a:
d, r = divmod(i - mi, k)
if r == 0:
res += d
else:
res = -1
break
print(res)
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main (){
ll n,k;
cin>>n>>k;
ll a[n];
for(ll i=0; i<n; i++){
cin>>a[i];
}
ll min = a[0];
for(ll i=0; i<n; i++){
if(a[i]<min) min=a[i];
}
ll count=0;
bool flag=true;
for(ll i=0; i<n; i++){
if(a[i]==min) continue;
else if((a[i]-min)%k==0){
count=count+((a[i]-min)/k);
}
else{
flag=false;
break;
}
}
if(flag==true) cout<<count;
else cout<<-1;
return 0;
}
1468C - Berpizza | 1546B - AquaMoon and Stolen String |
1353C - Board Moves | 902A - Visiting a Friend |
299B - Ksusha the Squirrel | 1647D - Madoka and the Best School in Russia |
1208A - XORinacci | 1539B - Love Song |
22B - Bargaining Table | 1490B - Balanced Remainders |
264A - Escape from Stones | 1506A - Strange Table |
456A - Laptops | 855B - Marvolo Gaunt's Ring |
1454A - Special Permutation | 1359A - Berland Poker |
459A - Pashmak and Garden | 1327B - Princesses and Princes |
1450F - The Struggling Contestant | 1399B - Gifts Fixing |
1138A - Sushi for Two | 982C - Cut 'em all |
931A - Friends Meeting | 1594A - Consecutive Sum Riddle |
1466A - Bovine Dilemma | 454A - Little Pony and Crystal Mine |
2A - Winner | 1622B - Berland Music |
1139B - Chocolates | 1371A - Magical Sticks |