#include #include #include #include #include using namespace std; int main() { int n; long long d, t; cin >> n >> d >> t; vector x(n); for (int i = 0; i < n; ++i) { cin >> x[i]; } map > positions; for (int i = 0; i < n; ++i) { positions[(0x80000000LL + x[i]) % d].insert(x[i]); } long long result = 0LL; for (map >::const_iterator it = positions.begin(); it != positions.end(); ++it) { vector distances; set::const_iterator itSet = it->second.begin(); for (;;) { set::const_iterator itNext = itSet; ++itNext; if (itNext == it->second.end()) { break; } distances.push_back(*itNext - *itSet); itSet = itNext; } sort(distances.begin(), distances.end()); size_t amebaCount = it->second.size(); result += amebaCount; long long lastJoining = 0; for (size_t i = 0; i < distances.size(); ++i) { long long joining = min(t, distances[i] / (2 * d)); result += 2 * amebaCount * (joining - lastJoining); if (joining == distances[i] / (2 * d)) { --result; } lastJoining = joining; if (lastJoining == t) { break; } --amebaCount; } if (lastJoining < t) { result += 2 * amebaCount * (t - lastJoining); } } cout << result << endl; return 0; }