#include <bits/stdc++.h>
using namespace std;
#define bismillah ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define pll pair<ll, ll>
#define fi first
#define se second
#define pb push_back
#define endl '\n'
ll N, T, a[500100];
void solve() {
    cin >> N >> T;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    sort(a, a+N);
    ll s = a[1]-a[0];
    ll an = min(s%T, T - (s%T));
    cout << (an/2 + an%2) << endl;
}
int main() {
    bismillah;
    int Tc = 1;
    // cin >> T;
    for (;Tc--;) solve();
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |