Language: C++

// https://atcoder.jp/contests/abc147/tasks/abc147_f
#define CIN_ONLY
#define DECIMAL_DIGITS 10
#define STATIC_MOD 1e9 + 7

#ifdef BTK
/*<head>*/
#    include "Template.hpp"
/*</head>*/
#else
/*<body>*/
/*</body>*/
#endif

int main() {
    /* write here */
    int N;
    cin >> N;
    LL X, D;
    cin >> X >> D;
    if (D < 0) {
        X = -X;
        D = -D;
    }
    if (D == 0) {
        if (X == 0) {
            cout << 1 << endl;
            return 0;
        }
        else {
            cout << N + 1 << endl;
            return 0;
        }
    }
    if (X == 0) {
        cout << (N * (N - 1ll)) / 2 + 1 << endl;
        return 0;
    }
    int p = -1;
    for (int i : range(1, N + 1)) {
        if (i * X % D == 0) {
            p = i;
            break;
        }
    }
    LL ret = 0;
    if (X > 0) {
        vector<LL> lb(N + 1);
        vector<LL> ub(N + 1);

        for (int i : !range(N)) {
            // 5678
            lb[i] = i * X + (0 + (i - 1) * D) * i / 2;
            ub[i] = i * X + ((N - i - 1) * D + (N - 1) * D) * i / 2;
            if (p != -1 && i + p < N) {
                if (ub[i] >= lb[i + p]) {
                    LL diff = ub[i] - lb[i + p];
                    LL db   = diff / D + 1;
                    ret += i - db;
                }
                else {
                    ret += i;
                }
            }
        }
        cout << ret << endl;
    }
    else {
        return -1;
    }
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:18:5: error: 'cin' was not declared in this scope
   18 |     cin >> N;
      |     ^~~
a.cc:19:5: error: 'LL' was not declared in this scope
   19 |     LL X, D;
      |     ^~
a.cc:20:12: error: 'X' was not declared in this scope
   20 |     cin >> X >> D;
      |            ^
a.cc:20:17: error: 'D' was not declared in this scope
   20 |     cin >> X >> D;
      |                 ^
a.cc:27:13: error: 'cout' was not declared in this scope
   27 |             cout << 1 << endl;
      |             ^~~~
a.cc:27:26: error: 'endl' was not declared in this scope
   27 |             cout << 1 << endl;
      |                          ^~~~
a.cc:31:13: error: 'cout' was not declared in this scope
   31 |             cout << N + 1 << endl;
      |             ^~~~
a.cc:31:30: error: 'endl' was not declared in this scope
   31 |             cout << N + 1 << endl;
      |                              ^~~~
a.cc:36:9: error: 'cout' was not declared in this scope
   36 |         cout << (N * (N - 1ll)) / 2 + 1 << endl;
      |         ^~~~
a.cc:36:44: error: 'endl' was not declared in this scope
   36 |         cout << (N * (N - 1ll)) / 2 + 1 << endl;
      |                                            ^~~~
a.cc:40:18: error: 'range' was not declared in this scope
   40 |     for (int i : range(1, N + 1)) {
      |                  ^~~~~
a.cc:46:7: error: expected ';' before 'ret'
   46 |     LL ret = 0;
      |       ^~~~
      |       ;
a.cc:48:9: error: 'vector' was not declared in this scope
   48 |         vector<LL> lb(N + 1);
      |         ^~~~~~
a.cc:48:20: error: 'lb' was not declared in this scope
   48 |         vector<LL> lb(N + 1);
      |                    ^~
a.cc:49:20: error: 'ub' was not declared in this scope
   49 |         vector<LL> ub(N + 1);
      |                    ^~
a.cc:51:23: error: 'range' was not declared in this scope
   51 |         for (int i : !range(N)) {
      |                       ^~~~~
a.cc:57:23: error: expected ';' before 'diff'
   57 |                     LL diff = ub[i] - lb[i + p];
      |                       ^~~~~
      |                       ;
a.cc:58:23: error: expected ';' before 'db'
   58 |                     LL db   = diff / D + 1;
      |                       ^~~
      |                       ;
a.cc:59:21: error: 'ret' was not declared in this scope
   59 |                     ret += i - db;
      |                     ^~~
a.cc:59:32: error: 'db' was not declared in this scope
   59 |                     ret += i - db;
      |                                ^~
a.cc:62:21: error: 'ret' was not declared in this scope
   62 |                     ret += i;
      |                     ^~~
a.cc:66:9: error: 'cout' was not declared in this scope
   66 |         cout << ret << endl;
      |         ^~~~
a.cc:66:17: error: 'ret' was not declared in this scope
   66 |         cout << ret << endl;
      |                 ^~~
a.cc:66:24: error: 'endl' was not declared in this scope
   66 |         cout << ret << endl;
      |                        ^~~~