malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long fpow(long long x, long long y, long long m) {     long long temp;     if (y == 0 || x == 1) return 1;     temp = fpow(x, y / 2, m);     if (y % 2 == 0)       return ((temp) * (temp)) % m;     else       return (((x) % m) * ((temp * temp) % m)) % m;   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   void sieve(long long n) {     bool prime[5 * 100005];     memset(prime, true, sizeof(prime));     for (long long p = 2; p * p <= n; p++)       if (prime[p] == true)         for (long long i = p * p; i <= n; i += p) prime[i] = false;     prime[1] = 0;   }   long long cnt, sum, mid, mx = -1e17, mn = 1e17, a[2 * 100005];   long long n, m, d, t, i, j, k, l, r, x, y, z;   bool f, f1, f2;   string s;   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     vector<long long> dp(100005);     for ((i) = 1; (i) <= (n); (i)++) {       cin >> x >> y;       cnt = 0;       for (j = 1; j * j <= x; j++) {         if (x % j == 0) {           if (dp[j] < i - y) {             cnt++;           }           dp[j] = i;           if (dp[x / j] < i - y) {             cnt++;           }           dp[x / j] = i;         }       }       cout << cnt;       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 5;   inline long long read() {     long long x = 0, f = 1;     char ch = getchar();     while (ch >  9  || ch <  0 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   long long sum, n, q;   long long a[16];   long long P[16];   long long fac[16];   bool vis[16];   void get(long long sum) {     long long res = 0;     for (long long i = 1; i < n; i++) res = (res + a[i]) * (n - i);     for (long long i = 1; i <= 15; i++) {       a[i] = sum / fac[15 - i];       sum %= fac[15 - i];     }     memset(vis, 0, sizeof(vis));     for (long long i = 1; i <= 15; i++) {       long long cnt = 0;       for (long long j = 1; j <= 15; j++) {         if (!vis[j]) cnt++;         if (cnt == a[i] + 1) {           P[i] = j;           vis[j] = 1;           break;         }       }     }   }   signed main() {     n = read();     q = read();     fac[0] = 1;     for (long long i = 1; i <= 15; i++) fac[i] = fac[i - 1] * i;     while (q--) {       long long opt;       opt = read();       if (opt == 1) {         long long l, r;         l = read();         r = read();         long long ans = 0;         get(sum);         if (r > n - 15) {           if (l > n - 15) {             for (long long i = l - n + 15; i <= r - n + 15; i++) ans += P[i];             ans += (r - l + 1) * (n - 15);           } else {             ans += (l + n - 15) * (n - 14 - l) / 2;             for (long long i = 1; i <= r - n + 15; i++) ans += P[i];             ans += (r - n + 15) * (n - 15);           }         } else           ans = (l + r) * (r - l + 1) / 2;         printf( %lld n , ans);       }       if (opt == 2) {         long long x;         x = read();         sum += x;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long modpow(long long a, long long b, long long m = 1000000007) {     a %= m;     long long res = 1;     while (b) {       if (b & 1) res = res * a % m;       a = a * a % m;       b >>= 1;     }     return res;   }   long long bpow(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = res * a;       a = a * a;       b >>= 1;     }     return res;   }   long long modinv(long long a) { return modpow(a, 1000000007 - 2, 1000000007); }   void graph(vector<vector<long long> > &adj, long long m) {     long long x, y;     for (long long i = 0; i < m; i++) {       cin >> x >> y;       adj[x - 1].push_back(y - 1);       adj[y - 1].push_back(x - 1);     }   }   const int mxN = 2e5 + 5;   void solve() {     int n;     cin >> n;     string s;     cin >> s;     set<int> color[26];     std::vector<int> out(n);     for (long long i = 0; i < s.size(); i++) {       int x = s[i] -  a ;       for (long long j = 1; j <= 26; j++) {         bool ok = true;         for (long long k = x + 1; k < 26; k++) {           ok &= !(color[k].count(j));         }         if (ok) {           color[x].insert(j);           out[i] = j;           break;         }       }     }     set<int> distinct;     for (auto &k : out) distinct.insert(k);     cout << distinct.size() <<   n ;     for (auto &k : out) cout << k <<    ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   template <class T1, class T2>   bool chmin(T1 &a, T2 b) {     return b < a && (a = b, true);   }   template <class T1, class T2>   bool chmax(T1 &a, T2 b) {     return a < b && (a = b, true);   }   template <class T1, class T2>   void sortPair(vector<T1> &v1, vector<T2> &v2) {     vector<pair<T1, T2>> u(v1.size());     for (int i = 0; i < u.size(); i++) u[i] = make_pair(v1[i], v2[i]);     sort(u.begin(), u.end());     for (int i = 0; i < u.size(); i++) tie(v1[i], v2[i]) = u[i];   }   long long solve() {     long long d, n, m;     cin >> d >> n >> m;     vector<long long> x(m), p(m);     for (int i = 0; i < (m); i++) scanf( %lld %lld , &x[i], &p[i]);     x.insert(x.begin(), 0);     p.insert(p.begin(), 0);     x.push_back(d);     p.push_back(0);     m += 2;     sortPair(x, p);     vector<long long> next(m, -1);     stack<int> s;     for (int i = (m)-1; i >= 0; i--) {       while (!s.empty() && p[i] <= p[s.top()]) s.pop();       next[i] = s.empty() ? -1 : s.top();       s.push(i);     }     long long full = n;     long long ans = 0;     int i = 0;     while (i < m - 1) {       if (x[i + 1] - x[i] > full) return -1;       long long use, dist, ni;       if (x[next[i]] - x[i] > full) {         dist = x[i + 1] - x[i];         use = full - n;         ni = i + 1;       } else {         dist = x[next[i]] - x[i];         use = max(0ll, dist - n);         ni = next[i];       }       ans += use * p[i];       n += use - dist;       i = ni;     }     return ans;   }   int main() {     cout << solve() << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void read(T &x) {     char c;     bool nega = 0;     while ((!isdigit(c = getchar())) && (c !=  - ))       ;     if (c ==  - ) {       nega = 1;       c = getchar();     }     x = c - 48;     while (isdigit(c = getchar())) x = x * 10 + c - 48;     if (nega) x = -x;   }   template <typename T>   inline void writep(T x) {     if (x > 9) writep(x / 10);     putchar(x % 10 + 48);   }   template <typename T>   inline void write(T x) {     if (x < 0) {       putchar( - );       x = -x;     }     writep(x);   }   template <typename T>   inline void writeln(T x) {     write(x);     putchar(  n );   }   int n, m, q;   char a[2 * 1003][2 * 1003];   long long sum[2 * 1003][2 * 1003], sum1[2 * 1003][2 * 1003], ret, cn_n, cm_n;   long long mx, my;   long long sx1, sy1, sx2, sy2;   void dcy(long long left, long long right, long long lx, long long rx) {     if (left > sy2 || right < sy1) return;     if (left >= sy1 && right <= sy2) {       ret += (right - left + 1) * (rx - lx + 1) / 2;     } else if (right - left + 1 == m) {       long long ly = max(sy1, left), ry = min(sy2, right);       long long x = (lx - 1) / n, y = (ly - 1) / m;       int k = ((x) ^ (y));       int k1 = 0;       while (k) k1 += k & 1, k >>= 1;       lx = (lx - 1) % n + 1, ly = (ly - 1) % m + 1, rx = (rx - 1) % n + 1,       ry = (ry - 1) % m + 1;       if (k1 & 1)         ret += sum1[rx][ry] + sum1[lx - 1][ly - 1] - sum1[lx - 1][ry] -                sum1[rx][ly - 1];       else         ret +=             sum[rx][ry] + sum[lx - 1][ly - 1] - sum[lx - 1][ry] - sum[rx][ly - 1];     } else {       long long mid = (left + right) >> 1;       dcy(left, mid, lx, rx), dcy(mid + 1, right, lx, rx);     }   }   void dcx(long long left, long long right) {     if (left > sx2 || right < sx1) return;     if (left >= sx1 && right <= sx2)       ret += (sy2 - sy1 + 1) * (right - left + 1) / 2;     else if (right - left + 1 == n)       dcy(1, my, max(left, sx1), min(right, sx2));     else {       int mid = (left + right) >> 1;       dcx(left, mid), dcx(mid + 1, right);     }   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int i, j;     scanf( %d%d%d , &n, &m, &q);     for (i = 1; i <= n; i++) scanf( %s , a[i] + 1);     for (i = 1; i <= n; i++)       for (j = 1; j <= m; j++) {         sum[i][j] = sum[i + n][j + m] = a[i][j] -  0 ;         sum[i + n][j] = sum[i][j + m] = sum[i][j] ^ 1;       }     n <<= 1, m <<= 1;     for (i = 1; i <= n; i++) {       for (j = 1; j <= m; j++) {         sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];         sum1[i][j] = i * j - sum[i][j];       }     }     mx = n;     while (mx < 1e9) {       mx *= 2;     }     my = m;     while (my < 1e9) {       my *= 2;     }     while (q--) {       scanf( %d%d%d%d , &sx1, &sy1, &sx2, &sy2);       ret = 0;       dcx(1, mx);       cout << ret << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int mark[111111];   int a[111111];   int b[111111];   int n;   int noEle, cnt;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       b[i] = a[i];     }     sort(b, b + n + 1);     for (int i = 1; i <= n; i++) {       if (b[i] != a[i]) {         noEle++;         if (noEle % 2 != 0) cnt++;         if (cnt > 1) {           cout <<  NO ;           return 0;         }       }     }     cout <<  YES ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, w, h;     char a[101][101];     cin >> w >> h;     for (i = 0; i < h; i++) {       for (j = 0; j < w; j++) {         char x;         cin >> x;         a[j][i] = x;       }     }     for (j = 0; j < w; j++) {       for (int k = 0; k < 2; k++) {         for (i = 0; i < h; i++) {           cout << a[j][i];           cout << a[j][i];         }         cout << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #define ll long long   #define f(i, x, n) for (int i = x; i < (int)(n); ++i)   const int N = 1e6 + 10, mod = 998244353;   const double eps = 1e-7;      inline int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; }   inline int mul(int a, int b) { return (ll)a * b % mod; }      int n;   string s;      ll fact[1000001], inv[1000001];// mod inv = n ^ mod-2   ll FastPower(int a, int b)   {       if(b == 0)           return 1;       ll res = FastPower(a, b/2);       if(b%2)           return res * res % mod * a % mod;       return res * res % mod;   }   ll nCk(int n, int k)   {    if(n < k)     return 0;       return fact[n] * inv[k] % mod * inv[n-k] % mod;   }      int main()   {    ios_base::sync_with_stdio(0);    cin.tie(0);   #ifndef ONLINE_JUDGE    freopen( input.txt ,  r , stdin);   #endif       fact[0] = 1;       inv[0] = FastPower(1, mod-2);       for(int i=1; i<=1000000; ++i)       {           fact[i] = fact[i-1] * i % mod;           inv[i] = FastPower(fact[i], mod-2);       }    int t;    cin >> t;    while(t--)       {     cin >> n >> s;     vector<int> a;     for(int i=0; i<n; ++i){      if(i < n-1 && s[i] ==  1  && s[i+1] ==  1 ){       a.push_back(2);       ++i;       continue;      }      a.push_back(s[i]- 0 );     }     n = a.size();     ll ans = 1;     int space = 0, nof2 = 0;     for(int i=0; i<n; ++i){      //cout << a[i] <<    ;      nof2 += a[i] == 2;      space += a[i] == 0;     }     ans = nCk(nof2+space, space);     cout << ans <<   n ;       }          }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     map<int, set<pair<int, string>, greater<pair<int, string> > > > mp;     for (int i = 0; i < n; i++) {       string s;       int a, b;       cin >> s >> a >> b;       mp[a].insert(pair<int, string>(b, s));     }     for (int i = 1; i <= m; i++) {       pair<int, string> a, b, c;       auto it = mp[i].begin();       a = *it;       it++;       b = *it;       if (mp[i].size() > 2)         it++;       else {         cout << a.second <<     << b.second << endl;         continue;       }       c = *it;       if ((b.first == c.first)) {         cout <<  ?  << endl;       } else {         cout << a.second <<     << b.second << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3fffffff;   const long long oo = 3000000000000000000LL;   int tes, n;   long long ans[3], mn[4], mx[4], ll[4], rr[4], lt[4], rt[4], ret[3];   bool get(long long s, long long x, long long y, long long z) {     if (s <= x) {       ret[0] = s;       ret[1] = 0;       ret[2] = 0;       return 1;     } else if (s <= x + y) {       ret[0] = x;       ret[1] = s - x;       ret[2] = 0;       return 1;     } else if (s <= x + y + z) {       ret[0] = x;       ret[1] = y;       ret[2] = s - x - y;       return 1;     }     return 0;   }   long long shr1(long long x) { return (x - (x & 1)) / 2; }   bool jd(long long t) {     int i, j;     long long s, x, y, z;     for (i = 0; i <= 3; i++) {       if (mn[i] + t < mx[i] - t) return 0;       ll[i] = mx[i] - t;       rr[i] = mn[i] + t;     }     for (i = 0; i < 2; i++) {       lt[0] = shr1(ll[0] - 3 * i + 1);       rt[0] = shr1(rr[0] - 3 * i);       for (j = 1; j <= 3; j++) {         lt[j] = shr1(ll[j] - i + 1);         rt[j] = shr1(rr[j] - i);       }       if (lt[0] <= rt[0] && lt[1] <= rt[1] && lt[2] <= rt[2] && lt[3] <= rt[3] &&           lt[1] + lt[2] + lt[3] <= rt[0]) {         if (lt[1] + lt[2] + lt[3] >= lt[0]) {           ret[0] = lt[1];           ret[1] = lt[2];           ret[2] = lt[3];           ans[0] = ret[1] + ret[2] + i;           ans[1] = ret[0] + ret[2] + i;           ans[2] = ret[0] + ret[1] + i;           return 1;         }         if (get(lt[0] - lt[1] - lt[2] - lt[3], rt[1] - lt[1], rt[2] - lt[2],                 rt[3] - lt[3])) {           ret[0] += lt[1];           ret[1] += lt[2];           ret[2] += lt[3];           ans[0] = ret[1] + ret[2] + i;           ans[1] = ret[0] + ret[2] + i;           ans[2] = ret[0] + ret[1] + i;           return 1;         }       }     }     return 0;   }   int main() {     long long x, y, z, s, l, r, mid;     int i;     scanf( %d , &tes);     while (tes--) {       scanf( %d , &n);       for (i = 0; i <= 3; i++) {         mx[i] = -oo;         mn[i] = oo;       }       for (i = 1; i <= n; i++) {         scanf( %I64d%I64d%I64d , &x, &y, &z);         s = x + y + z;         mx[0] = max(mx[0], s);         mn[0] = min(mn[0], s);         mx[1] = max(mx[1], s - x - x);         mn[1] = min(mn[1], s - x - x);         mx[2] = max(mx[2], s - y - y);         mn[2] = min(mn[2], s - y - y);         mx[3] = max(mx[3], s - z - z);         mn[3] = min(mn[3], s - z - z);       }       l = 0;       r = oo;       while (l < r) {         mid = (l + r) >> 1;         if (jd(mid))           r = mid;         else           l = mid + 1;       }       jd(l);       printf( %I64d %I64d %I64d n , ans[0], ans[1], ans[2]);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int n, c;     cin >> n;     cin >> s;     for (int i = 0; i < s.size(); i++) {       if (s[i] == s[i + 1] && i != s.size() - 1) {         c += 1;       }     }     cout << c;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, a, b, i, j, arr[1005] = {0};     cin >> n >> m;     for (i = 1; i <= m; i++) {       cin >> a >> b;       arr[a] = 1;       arr[b] = 1;     }     for (i = 1; i <= n; i++) {       if (arr[i] == 0) break;     }     cout << n - 1 << endl;     for (j = 1; j <= n; j++) {       if (i != j) {         cout << i <<     << j << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct block {     string str;     int pos;   };   static bool compare(block b1, block b2) {     int n = b1.str.length();     for (int i = 0; i < n; i++) {       if (b1.str[i] != b2.str[i]) {         if ((i + 1) % 2) {           return (b1.str[i] < b2.str[i]);         } else {           return (b1.str[i] > b2.str[i]);         }       }     }   }   int main() {     int n, m;     cin >> n >> m;     vector<block> arr(n);     for (int i = 0; i < n; i++) {       cin >> arr[i].str;       arr[i].pos = i + 1;     }     sort(arr.begin(), arr.end(), compare);     for (int i = 0; i < n; i++) {       cout << arr[i].pos <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   double ans[3], temp[3];   int a[200200];   int n;   bool f(double d) {     double x = 0;     int cnt = 0;     for (int i = 0; i < n; i++) {       if (x < a[i]) {         if (cnt == 3) return false;         x = a[i] + 2 * d;         temp[cnt++] = a[i] + d;       }     }     for (int i = 0; i < 3; i++) ans[i] = temp[i];     return true;   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     double ul = 0, ur = a[n - 1];     for (int k = 0; k < 400; k++) {       double mid = (ul + ur) / 2;       if (f(mid))         ur = mid;       else         ul = mid;     }     printf( %.6f n , ul);     printf( %.6f %.6f %.6f n , ans[0], ans[1], ans[2]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int maxn = 3e6;   const double eps = 0.00000001;   long long ksm(long long a, long long n) {     long long ans = 1;     while (n) {       if (n & 1) ans = ans * a % mod;       a = a * a % mod;       n >>= 1;     }     return ans;   }   int main() {     long long c, n, ans;     std::ios::sync_with_stdio(false);     cin >> n;     c = 1;     for (int i = 1; i <= n; i++) c = c * i % mod;     ans = (c + mod - ksm(2, n - 1)) % mod;     cout << ans << endl;   }
#include <bits/stdc++.h>   /*#include <iostream>   #include <algorithm>   #include <math.h>   #include <iomanip>   #include <string>   #include <vector>   #include <set>   #include <sstream>*/      #define ll long long   #define fop(i,m,n) for(int i=m; i<n; i++)   #define fastIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)   #define X first   #define Y second   #define pb push_back   #define mp make_pair   #define all(v) v.begin(),v.end()   #define ep emplace_back      using namespace std;      const long long MOD = 1e9+7;   const long long N = 3e5+5;   const long long Nlog = 17;   const long long Hash = 257;      const double PI = 2.0*acos(0.0);//<cmath>   //const double PI = 3.141592653;   const double E = 2.718281828;      struct bot{       int p, w;   }x[N];      bool cmp(int a, int b){       return x[a].p < x[b].p;   }      void solve(){              int n, m;       cin >> n >> m;       fop(i,0,n) cin >> x[i].p;       fop(i,0,n){           char in;           cin >> in;           if(in ==  R ) x[i].w = 1;           else x[i].w = -1;       }              vector<int> v[2];       fop(i,0,n){           v[x[i].p%2].pb(i);       }       fop(i,0,2) sort(all(v[i]), cmp);              vector<int> ans(n, -1);              fop(t,0,2){           vector<int> s;           for(int i : v[t]){               if(x[i].w == 1){                   s.pb(i);               }else{                   if(s.empty()){                       s.pb(i);                   }else{                       int j = s.back();                       s.pop_back();                                              if(x[j].w == 1) ans[i] = ans[j] = (x[i].p-x[j].p)/2;                       else ans[i] = ans[j] = (x[i].p+x[j].p)/2;                       //cout << i <<     << j <<   :   << ans[i] <<   n ;                   }               }           }                      while(s.size() > 1){               int i = s.back();               s.pop_back();               int j = s.back();               s.pop_back();               if(x[j].w == 1) ans[i] = ans[j] = m - (x[i].p + x[j].p)/2;               else ans[i] = ans[j] = m - (x[i].p - x[j].p)/2;               //cout << i <<     << j <<   :   << ans[i] <<   n ;           }       }              fop(i,0,n){           cout << ans[i] <<    ;       }       cout <<   n ;          }         int main()   {       fastIO;          int t=1;       cin >> t;       while(t--) solve();          return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   inline void add(int& x, int y) {     x += y;     if (x >= mod) x -= mod;     if (x < 0) x += mod;   }   inline int mul(int x, int y) { return ((long long)x * y) % mod; }   int gcd(int a, int b) {     if (b) return gcd(b, a % b);     return a;   }   int power(int a, int p) {     int ret = 1;     while (p) {       if (p & 1) ret = mul(ret, a);       a = mul(a, a);       p /= 2;     }     return ret;   }   int phi(int n) {     int ret = n;     int i = 2;     if (n % i == 0) {       ret -= ret / i;       while (n % i == 0) n /= i;     }     for (i = 3; i * i <= n; i++)       if (n % i == 0) {         ret -= ret / i;         while (n % i == 0) n /= i;       }     if (n > 1) ret -= ret / n;     return ret;   }   bool E[400][400];   int D[2][400][400];   int main() {     int N;     scanf( %d , &N);     int M;     scanf( %d , &M);     memset(D, 31, sizeof(D));     queue<pair<pair<int, int>, int>> Q;     int inf = D[0][0][0];     ;     D[0][0][0] = 0;     while (M--) {       int x, y;       scanf( %d , &x);       scanf( %d , &y);       E[x - 1][y - 1] = E[y - 1][x - 1] = true;     }     Q.push({{0, 0}, 0});     while (!Q.empty()) {       int ty = Q.front().second;       pair<int, int> a = Q.front().first;       Q.pop();       int nd = D[ty][a.first][a.second] + 1;       int x = a.first;       int y = a.second;       if (ty == 0) {         if (x != N - 1) {           for (int i = 0; i < N; i++)             if (i != x and E[x][i] == true and D[1][i][y] == inf) {               D[1][i][y] = nd;               Q.push({{i, y}, 1});               ;             }         } else if (D[1][x][y] == inf) {           D[1][x][y] = nd;           Q.push({{x, y}, 1});         }       }       if (ty == 1) {         if (x == N - 1 and E[y][N - 1] == false) {           cout << nd / 2 << endl;           return 0;         }         if (y != N - 1) {           for (int i = 0; i < N; i++)             if (i != x and i != y and E[y][i] == false and D[0][x][i] == inf) {               D[0][x][i] = nd;               Q.push({{x, i}, 0});               ;             }         } else if (D[0][x][y] == inf) {           D[0][x][y] = nd;           Q.push({{x, y}, 0});         }       }     }     cout << -1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long N, K;     cin >> N >> K;     vector<long long> P(N);     for (long long i = 0; i < N; i++) {       cin >> P[i];     }     sort(P.begin(), P.end());     long long min = P[0], vid = 0;     for (long long i = 1; i < P.size(); i++) {       if ((P[i] - P[0]) % K == 0) {         vid += abs(P[i] - P[0]) / K;       } else {         cout << -1 << endl;         return 0;       }     }     cout << vid << endl;   }