Language: C++

#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = LONG_LONG_MAX / 100;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {
    ll n, x, d;
    cin >> n >> x >> d;

    if (d == 0) {
        if (x == 0) {
            cout << 1 << endl;
        } else {
            cout << n + 1 << endl;
        }
        return 0;
    }

    map<int, vector<P>> mp;
    rep(i, n + 1) {
        ll s = x * i;
        ll l = i * (i - 1) / 2;
        ll r = l + i * (n - i);
        s += l * d;
        r -= l;
        mp[(s + (d << 30)) % d].emplace_back(s, r);
    }
    ll ans = 0;
    for (auto p : mp) {
        auto a = p.second;
        int m = a.size();
        rep(i, m) a[i].first = (a[i].first - p.first) / d;
        vector<P> ev;
        rep(i, m) {
            ev.emplace_back(a[i].first, 1);
            ev.emplace_back(a[i].first + a[i].second + 1, -1);
        }
        sort(ev.begin(), ev.end());
        ll count = 0, pre = -INF;
        for (auto e : ev) {
            ll len = e.first - pre;
            if (count) ans += len;
            count += e.second;
            pre = e.first;
        }
    }
    cout << ans << endl;
}#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = LONG_LONG_MAX / 100;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {
    ll n, x, d;
    cin >> n >> x >> d;

    if (d == 0) {
        if (x == 0) {
            cout << 1 << endl;
        } else {
            cout << n + 1 << endl;
        }
        return 0;
    }

    map<int, vector<P>> mp;
    rep(i, n + 1) {
        ll s = x * i;
        ll l = i * (i - 1) / 2;
        ll r = l + i * (n - i);
        s += l * d;
        r -= l;
        mp[(s + (d << 30)) % d].emplace_back(s, r);
    }
    ll ans = 0;
    for (auto p : mp) {
        auto a = p.second;
        int m = a.size();
        rep(i, m) a[i].first = (a[i].first - p.first) / d;
        vector<P> ev;
        rep(i, m) {
            ev.emplace_back(a[i].first, 1);
            ev.emplace_back(a[i].first + a[i].second + 1, -1);
        }
        sort(ev.begin(), ev.end());
        ll count = 0, pre = -INF;
        for (auto e : ev) {
            ll len = e.first - pre;
            if (count) ans += len;
            count += e.second;
            pre = e.first;
        }
    }
    cout << ans << endl;
}

Compiler output:
a.cc:87:2: error: stray '#' in program
   87 | }#include <bits/stdc++.h>
      |  ^
a.cc:87:3: error: 'include' does not name a type
   87 | }#include <bits/stdc++.h>
      |   ^~~~~~~
a.cc:93:14: error: redefinition of 'const double PI'
   93 | const double PI = 3.14159265358979323846;
      |              ^~
a.cc:7:14: note: 'const double PI' previously defined here
    7 | const double PI = 3.14159265358979323846;
      |              ^~
a.cc:95:14: error: redefinition of 'const double EPS'
   95 | const double EPS = 1e-9;
      |              ^~~
a.cc:9:14: note: 'const double EPS' previously defined here
    9 | const double EPS = 1e-9;
      |              ^~~
a.cc:99:10: error: redefinition of 'const ll INF'
   99 | const ll INF = LONG_LONG_MAX / 100;
      |          ^~~
a.cc:13:10: note: 'const ll INF' previously defined here
   13 | const ll INF = LONG_LONG_MAX / 100;
      |          ^~~
a.cc:104:8: error: redefinition of 'double equal(double, double)'
  104 | double equal(double a, double b) {
      |        ^~~~~
a.cc:18:8: note: 'double equal(double, double)' previously defined here
   18 | double equal(double a, double b) {
      |        ^~~~~
a.cc:108:15: error: redefinition of 'std::istream& operator>>(std::istream&, std::set<int>&)'
  108 | std::istream &operator>>(std::istream &in, set<int> &o) {
      |               ^~~~~~~~
a.cc:22:15: note: 'std::istream& operator>>(std::istream&, std::set<int>&)' previously defined here
   22 | std::istream &operator>>(std::istream &in, set<int> &o) {
      |               ^~~~~~~~
a.cc:115:15: error: redefinition of 'std::istream& operator>>(std::istream&, std::queue<int>&)'
  115 | std::istream &operator>>(std::istream &in, queue<int> &o) {
      |               ^~~~~~~~
a.cc:29:15: note: 'std::istream& operator>>(std::istream&, std::queue<int>&)' previously defined here
   29 | std::istream &operator>>(std::istream &in, queue<int> &o) {
      |               ^~~~~~~~
a.cc:122:6: error: redefinition of 'bool contain(std::set<int>&, int)'
  122 | bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }
      |      ^~~~~~~
a.cc:36:6: note: 'bool contain(std::set<int>&, int)' previously defined here
   36 | bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }
      |      ^~~~~~~
a.cc:131:5: error: redefinition of 'int main()'
  131 | int main() {
      |     ^~~~
a.cc:45:5: note: 'int main()' previously defined here
   45 | int main() {
      |     ^~~~