Language: C++

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.HashMap;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author shangu
 */
public class Main {
  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    FastReader in = new FastReader(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    FSumDifference solver = new FSumDifference();
    solver.solve(1, in, out);
    out.close();
  }

  static class FSumDifference {
    public void solve(int testNumber, FastReader in, PrintWriter out) {
      long n = in.nextLong(), x = in.nextLong(), d = in.nextLong();
      HashMap<Long, ArrayList<Seg>> segments = new HashMap<>();
      for (long i = 0; i <= n; i++) {
        long grp = x * i, offet = (long) Math.ceil(grp * 1.0 / d);
        grp = (grp % d + d) % d;
        if (!segments.containsKey(grp)) segments.put(grp, new ArrayList<>());
        ArrayList<Seg> cur = segments.get(grp);
        cur.add(new Seg(offet + i * (i - 1) / 2, -1));
        cur.add(new Seg(offet + (2 * n - 1 - i) * i / 2, 1));
      }
      long ans = 0;
      for (ArrayList<Seg> list : segments.values()) {
        list.sort((a, b) -> (int) (a.v == b.v ? a.t - b.t : a.v - b.v));
        int cnt = 0;
        long begin = 0;
        for (Seg e : list) {
          if (cnt == 0 && e.t == -1) begin = e.v;
          cnt += e.t;
          if (cnt == 0) ans += e.v - begin + 1;
        }
      }
      out.println(ans);
    }

    private class Seg {
      long v;
      int t;

      public Seg(long _v, int _t) {
        v = _v;
        t = _t;
      }

    }

  }

  static class FastReader {
    BufferedReader br;
    StringTokenizer st;

    public FastReader(InputStream stream) {
      br = new BufferedReader(new InputStreamReader(stream), 32768);
      st = null;
    }

    public String next() {
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

  }
}



Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import java.io.OutputStream;
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:2:1: error: 'import' does not name a type
    2 | import java.io.IOException;
      | ^~~~~~
a.cc:2:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:3:1: error: 'import' does not name a type
    3 | import java.io.InputStream;
      | ^~~~~~
a.cc:3:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:4:1: error: 'import' does not name a type
    4 | import java.io.PrintWriter;
      | ^~~~~~
a.cc:4:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:5:1: error: 'import' does not name a type
    5 | import java.util.StringTokenizer;
      | ^~~~~~
a.cc:5:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:6:1: error: 'import' does not name a type
    6 | import java.util.HashMap;
      | ^~~~~~
a.cc:6:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:7:1: error: 'import' does not name a type
    7 | import java.io.IOException;
      | ^~~~~~
a.cc:7:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:8:1: error: 'import' does not name a type
    8 | import java.io.BufferedReader;
      | ^~~~~~
a.cc:8:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:9:1: error: 'import' does not name a type
    9 | import java.io.InputStreamReader;
      | ^~~~~~
a.cc:9:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:10:1: error: 'import' does not name a type
   10 | import java.util.ArrayList;
      | ^~~~~~
a.cc:10:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:11:1: error: 'import' does not name a type
   11 | import java.io.InputStream;
      | ^~~~~~
a.cc:11:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:19:1: error: expected unqualified-id before 'public'
   19 | public class Main {
      | ^~~~~~