criyle/codenet-compile-errors huggingface dataset:
Language: Java

import java.util.*;
import java.io.*;

public class Maib {
    static final int base = 80 * 80 + 1;
    static int[][][] dp;
    static int[][] a, b;
    static int n, m;

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        m = in.nextInt();
        a = new int[n][m];
        b = new int[n][m];
        
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) {
                a[i][j] = in.nextInt();
            }
        }
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) {
                b[i][j] = in.nextInt();
            }
        }

        dp = new int[n][m][base * 2 + 123];
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) {
                Arrays.fill(dp[i][j], Integer.MAX_VALUE);
            }
        }
        
        System.out.println(dp(0, 0, 0));
    }

    private static int dp(int i, int j, int diff) {
        if (i == n - 1 && j == m - 1) {
            return Math.min(
                Math.abs(diff + a[i][j] - b[i][j]),
                Math.abs(diff + b[i][j] - a[i][j])
            );
        }

        if (dp[i][j][base + diff] != Integer.MAX_VALUE) 
            return dp[i][j][base + diff];
        
        int min = Integer.MAX_VALUE;
        if (i + 1 < n) {
            min = Math.min(min, dp(i + 1, j, diff + a[i][j] - b[i][j]));
            min = Math.min(min, dp(i + 1, j, diff + b[i][j] - a[i][j]));
        }

        if (j + 1 < m) {
            min = Math.min(min, dp(i, j + 1, diff + a[i][j] - b[i][j]));
            min = Math.min(min, dp(i, j + 1, diff + b[i][j] - a[i][j]));
        }

        return dp[i][j][base + diff] = min;
    }
}

Compiler output:
Main.java:4: error: class Maib is public, should be declared in a file named Maib.java
public class Maib {
       ^
1 error
Language: Java

import java.util.*;
import java.io.*;

public class E {
    static final int base = 80 * 80 * 80;
    static int[][][] dp;
    static int[][] a, b;
    static int n, m;

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        m = in.nextInt();
        a = new int[n][m];
        b = new int[n][m];
        
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) {
                a[i][j] = in.nextInt();
            }
        }
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) {
                b[i][j] = in.nextInt();
            }
        }

        dp = new int[n][m][base * 2 + 12345];
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) {
                Arrays.fill(dp[i][j], Integer.MAX_VALUE);
            }
        }
        
        System.out.println(dp(0, 0, 0));
    }

    private static int dp(int i, int j, int diff) {
        if (i == n - 1 && j == m - 1) {
            return Math.min(
                Math.abs(diff + a[i][j] - b[i][j]),
                Math.abs(diff + b[i][j] - a[i][j])
            );
        }

        if (dp[i][j][base + diff] != Integer.MAX_VALUE) 
            return dp[i][j][base + diff];
        
        int min = Integer.MAX_VALUE;
        if (i + 1 < n) {
            min = Math.min(min, dp(i + 1, j, diff + a[i][j] - b[i][j]));
            min = Math.min(min, dp(i + 1, j, diff + b[i][j] - a[i][j]));
        }

        if (j + 1 < m) {
            min = Math.min(min, dp(i, j + 1, diff + a[i][j] - b[i][j]));
            min = Math.min(min, dp(i, j + 1, diff + b[i][j] - a[i][j]));
        }

        return dp[i][j][base + diff] = min;
    }
}

Compiler output:
Main.java:4: error: class E is public, should be declared in a file named E.java
public class E {
       ^
1 error
Language: C++

#include <iostream>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;

const int maxd = 80 * 80 * 1;

int memo[80][80][maxd];

int doit(vector <vector <int> > &diff, int x, int y, int d)
{
    if (x < 0 || y < 0 || d >= maxd) {
        return 0;
    }
    if (x == 0 && y == 0) {
        return d == diff[0][0];
    }
    if (memo[y][x][d] < 0) {
        memo[y][x][d] = (doit(diff, x - 1, y, abs(d + diff[y][x])) |
                         doit(diff, x - 1, y, abs(d - diff[y][x])) |
                         doit(diff, x, y - 1, abs(d + diff[y][x])) |
                         doit(diff, x, y - 1, abs(d - diff[y][x])));
    }
    return memo[y][x][d];
}

int main()
{
    int h, w;
    cin >> h >> w;
    vector <vector <int> > diff(h);
    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            int a;
            cin >> a;
            diff[y].push_back(a);
        }
    }
    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            int b;
            cin >> b;
            diff[y][x] = abs(diff[y][x] - b);
        }
    }
    memset(memo, -1, sizeof(memo));

    int ret;
    for (ret = 0; ret < maxd; ret++) {
        if (doit(diff, w - 1, h - 1, ret)) {
            break;
        }
    }
    cout << ret << endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:48:5: error: 'memset' was not declared in this scope
   48 |     memset(memo, -1, sizeof(memo));
      |     ^~~~~~
a.cc:5:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    4 | #include <algorithm>
  +++ |+#include <cstring>
    5 |
Language: C++

#include<bits/stdc++.h>
using namespace std;
int main(){
  int H,W;
  cin>>H>>W;
  vector<vector<vector<int>>>data(H,vector<vector<int>>(W, vector<int>(2,0)));
  for(int i=0; i<2; i++){
    for(int j=0; j<W; j++){
      for(int k=0; j<H; k++){
        int a;
        cin>>a;
        data.at(k).at(j).at(i)=a;
      }
    }
  }
  

Compiler output:
a.cc: In function 'int main()':
a.cc:15:4: error: expected '}' at end of input
   15 |   }
      |    ^
a.cc:3:11: note: to match this '{'
    3 | int main(){
      |           ^
Language: C++

#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
ll hoge[111][111];
ll hoge2[111][111];
bool dp[88][88][300][300];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll h,w;cin>>h>>w;
  for(int i=0;i<h;i++)for(int j=0;j<w;j++)cin>>hoge[i][j];
  for(int i=0;i<h;i++)for(int j=0;j<w;j++)cin>>hoge2[i][j];
  ll minus=min(hoge[0][0],hoge2[0][0]);
  dp[0][0][hoge[0][0]-minus][hoge2[0][0]-minus]=true;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      for(int k=0;k<350;k++){
	for(int l=0;l<350;l++){
	  if(dp[i][j][k][l]){
	    if(!(i+1<h&&j+1<w))
	    ll h1=k+hoge[i+1][j];
	    ll h2=l+hoge2[i+1][j];
	    ll hh1=k+hoge[i][j+1];
	    ll hh2=l+hoge2[i][j+1];
	    //if(i==0&&j==0)cout<<h1<<" "<<h2<<" "<<hh1<<" "<<hh2<<endl;
	    minus=min(h1,h2);
	    if(h1-minus<350&&h2-minus<350)
	      dp[i+1][j][h1-minus][h2-minus]=true;
	    minus=min(hh1,hh2);
	    if(hh1-minus<350&&hh2-minus<350)
	    dp[i][j+1][hh1-minus][hh2-minus]=true;
	    h1=k+hoge2[i+1][j];
	    h2=l+hoge[i+1][j];
	    hh1=k+hoge2[i][j+1];
	    hh2=l+hoge[i][j+1];
	    minus=min(h1,h2);
	    if(h1-minus<350&&h2-minus<350)
	      dp[i+1][j][h1-minus][h2-minus]=true;
	    minus=min(hh1,hh2);
	    if(h1-minus<350&&h2-minus<350)
	      dp[i][j+1][hh1-minus][hh2-minus]=true;
	  }
	}
      }
    }
  }
  ll ans=llINF;
  for(int i=0;i<300;i++){
    for(int j=0;j<300;j++){
      if(dp[h-1][w-1][i][j])ans=min(ans,(ll)abs(i-j));
    }
  }
  cout<<ans<<endl;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:40:23: error: 'h1' was not declared in this scope; did you mean 'hh1'?
   40 |             minus=min(h1,h2);
      |                       ^~
      |                       hh1
Language: C++

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cmath>

using ll = long long;

using namespace std;

#define MAX 6401
#define OFF 80

using B = bitset<MAX>;
B dp[81][81];

B rshift(B &bs, int n) {
    string s =bs.to_string().substr(MAX-n, n);
    reverse(s.begin(), s.end());
    return (bs >> n) | B(s + '0');
}

int main() {
    int h, w;
    cin >> h >> w;
    int dif[h][w];
    for (int i=0; i<h; i++) {
        for (int j=0; j<w; j++) {
            cin >> dif[i][j];
        }
    }
    for (int i=0; i<h; i++) {
        for (int j=0; j<w; j++) {
            int b;
            cin >> b;
            dif[i][j] = abs(dif[i][j] - b);
        }
    }
    dp[0][1][0] = dp[1][0][0] = true;
    for (int i=0; i<=h; i++) {
        for (int j=0; j<=w; j++) {
            // cerr << i << ' ' << j <<  ' ' << dp[i][j].to_string().substr(MAX-10, 10) << '\n';
            if (i < h && j > 0) dp[i+1][j] |= rshift(dp[i][j], dif[i][j-1]) | (dp[i][j] << dif[i][j-1]);
            if (j < w && i > 0) dp[i][j+1] |= rshift(dp[i][j], dif[i-1][j]) | (dp[i][j] << dif[i-1][j]);
        }
    }
    for (int i=0; i<MAX; i++) {
        if (dp[h][w][i]) {
            cout << i << '\n';
            return 0;
        }
    }
    return 0;
}

Compiler output:
a.cc:15:11: error: 'bitset' does not name a type
   15 | using B = bitset<MAX>;
      |           ^~~~~~
a.cc:16:1: error: 'B' does not name a type
   16 | B dp[81][81];
      | ^
a.cc:18:1: error: 'B' does not name a type
   18 | B rshift(B &bs, int n) {
      | ^
a.cc: In function 'int main()':
a.cc:40:5: error: 'dp' was not declared in this scope
   40 |     dp[0][1][0] = dp[1][0][0] = true;
      |     ^~
a.cc:44:47: error: 'rshift' was not declared in this scope
   44 |             if (i < h && j > 0) dp[i+1][j] |= rshift(dp[i][j], dif[i][j-1]) | (dp[i][j] << dif[i][j-1]);
      |                                               ^~~~~~
a.cc:45:47: error: 'rshift' was not declared in this scope
   45 |             if (j < w && i > 0) dp[i][j+1] |= rshift(dp[i][j], dif[i-1][j]) | (dp[i][j] << dif[i-1][j]);
      |                                               ^~~~~~
Language: C++

#include <iostream>
#include <cmath>
using namespace std;
int a[100][100],b[100][100];
bool dp[81][81][15000];
int main(){
	int i,j,k,h,w;
	cin >> h >> w;
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			cin >> a[i][j];
		}
	}
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			cin >>b[i][j];
		}
	}
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			for(k=0;k<15000;k++){
				dp[i][j][k] = false;
			}
		}
	}
	dp[0][0][abs(a[0][0] - b[0][0]] = true;
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			for(k=0;k<15000;k++){
				if(!dp[i][j][k]) continue;
				dp[i + 1][j][abs(k + a[i + 1][j] - b[i + 1][j])] = true;
				dp[i + 1][j][abs(k - a[i + 1][j] + b[i + 1][j])] = true;
				dp[i][j + 1][abs(k + a[i][j + 1] - b[i][j + 1])] = true;
				dp[i][j + 1][abs(k - a[i][j + 1] + b[i][j + 1])] = true;
			}
		}
	}
	for(i=0;i<=6400;i++){
		if(dp[h - 1][w - 1][i]){
			cout << i << endl;
			return 0;
		}
	}
}

Compiler output:
a.cc: In function 'int main()':
a.cc:26:39: error: expected ')' before ']' token
   26 |         dp[0][0][abs(a[0][0] - b[0][0]] = true;
      |                     ~                 ^
      |                                       )
Language: C++

#include<bits/stdc++.h>
using namespace std;
int main(){
  int H,W;
  cin>>H>>W;
  vector<
    vector<vector<int>>>data(H,vector<vector<int>>(W, vector<int>(2,0)));

Compiler output:
a.cc: In function 'int main()':
a.cc:7:74: error: expected '}' at end of input
    7 |     vector<vector<int>>>data(H,vector<vector<int>>(W, vector<int>(2,0)));
      |                                                                          ^
a.cc:3:11: note: to match this '{'
    3 | int main(){
      |           ^
Language: C++

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

// 160 + 160 - 280


bitset<25601> dp[81][81];

int main() {
  int H, W;
  int A[100][100], B[100][100];

  cin >> H >> W;

  for (int i=0; i<H; i++)
    for (int j=0; j<W; j++)
      cin >> A[i][j];

  for (int i=0; i<H; i++) {
    for (int j=0; j<W; j++) {
      cin >> B[i][j];
      A[i][j] = abs(A[i][j] - B[i][j]);
    }
  }

  const int V = 80 * 160;

  dp[0][0][V] = 1;

  for (int i=0; i<H; i++) {
    for (int j=0; j<W; j++) {
      if (i+1 < H)
        dp[i+1][j] |= dp[i][j] << A[i][j];

      if (j+1 < W)
        dp[i][j+1] |= dp[i][j] << A[i][j];

      if (i+1 < H)
        dp[i+1][j] |= dp[i][j] >> A[i][j];

      if (j+1 < W)
        dp[i][j+1] |= dp[i][j] >> A[i][j];
    }
  }

  int ans = V;

  if (A[H-1][W-1] >= 0)
    dp[H-1][W-1] = dp[H-1][W-1] << A[H-1][W-1];
  else
    dp[H-1][W-1] = dp[H-1][W-1] >> (-A[H-1][W-1]);


  for (int i=0; i<=V*2; i++) {
    if (dp[H-1][W-1][i]) {
      ans = min(ans, abs(V - i));
    }
  }

  cout << ans << endl;

  return 0;
}


Compiler output:
a.cc:53:1: error: 'bitset' does not name a type
   53 | bitset<25601> dp[81][81];
      | ^~~~~~
a.cc: In function 'int main()':
a.cc:74:3: error: 'dp' was not declared in this scope
   74 |   dp[0][0][V] = 1;
      |   ^~
Language: C++

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define eb emplace_back


typedef long long ll;
typedef long double ld;


const ll inf = 2e9;
const ll base = 998244353;
ll mod = 1e9 + 7;



int maxcnt = 161;

char dp[80][80][maxcnt];


int main() {
//    srand(time(NULL));
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    auto start = clock();


    int n, m; cin >> n >> m;
    vector<vector<int>> a(n, vector<int>(m, 0)), b(n, vector<int>(m, 0));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cin >> a[i][j];
        }
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cin >> b[i][j];
            if (a[i][j] < b[i][j]) swap(a[i][j], b[i][j]);
            a[i][j] -= b[i][j];
        }
    }
    dp[0][0][a[0][0]] = 1;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            for (int k = 0; k < maxcnt; ++k) {
                if (dp[i][j][k]) {
                    if (j + 1 < m) {
                        dp[i][j + 1][abs(k - a[i][j + 1])] = 1;
                        if (k + a[i][j + 1] < maxcnt) {
                            dp[i][j + 1][k + a[i][j + 1]] = 1;
                        }
                    }
                    if (i + 1 < n) {
                        dp[i + 1][j][abs(k - a[i + 1][j])] = 1;
                        if (k + a[i + 1][j] < maxcnt) {
                            dp[i + 1][j][k + a[i + 1][j]] = 1;
                        }
                    }
                }
            }
        }
    }
    for (int k = 0; k < maxcnt; ++k) {
        if (dp[n - 1][m - 1][k]) {
            cout << k << endl;
            return 0;
        }
    }


    std::cerr << double(clock() - start) / CLOCKS_PER_SEC << std::endl;
    return 0;
}

Compiler output:
a.cc:22:17: error: size of array 'dp' is not an integral constant-expression
   22 | char dp[80][80][maxcnt];
      |                 ^~~~~~
Language: C++

#pragma GCC optimize(2,3,"Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define in inline
namespace fast_io
{
    char buf[1<<12],*p1=buf,*p2=buf,sr[1<<23],z[23],nc;int C=-1,Z=0,Bi=0,ny;
    in char gc() {return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<12,stdin),p1==p2)?EOF:*p1++;}
    in ll read()
    {
        ll x=0;ny=1;while(nc=gc(),(nc<48||nc>57)&&nc!=EOF)if(nc==45)ny=-1;Bi=1;if(nc<0)return nc;
        x=nc-48;while(nc=gc(),47<nc&&nc<58&&nc!=EOF)x=(x<<3)+(x<<1)+(nc^48),Bi++;return x*ny;
    }
    in db gf() {int a=read(),y=ny,b=(nc!='.')?0:read();return (b?a+(db)b/pow(10,Bi)*y:a);}
    in int gs(char *s) {char c,*t=s;while(c=gc(),c<32);*s++=c;while(c=gc(),c>32)*s++=c;return s-t;}
    in void ot() {fwrite(sr,1,C+1,stdout);C=-1;}
    in void flush() {if(C>1<<22) ot();}
    template <typename T>
    in void write(T x,char t)
    {
        int y=0;if(x<0)y=1,x=-x;while(z[++Z]=x%10+48,x/=10);
        if(y)z[++Z]='-';while(sr[++C]=z[Z],--Z);sr[++C]=t;flush();
    }
    in void write(char *s) {int l=strlen(s);for(int i=0;i<l;i++)sr[++C]=*s++;sr[++C]='\n';flush();}
};
using namespace fast_io;
const int N=85,
int n,m,a[N][N];bitset<25605>f[N][N];
int main()
{
	n=read();m=read();
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) a[i][j]=read();
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) a[i][j]=abs(a[i][j]-read());
	f[1][1][a[1][1]+12800]=1;
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++)
	{
		if(i^n) f[i+1][j]|=f[i][j]<<a[i+1][j],f[i+1][j]|=f[i][j]>>a[i+1][j];
		if(j^m) f[i][j+1]|=f[i][j]<<a[i][j+1],f[i][j+1]|=f[i][j]>>a[i][j+1];
	}
	for(int i=12800;i<=25600;i++) if(f[n][m][i]) return write(i-12800,'\n'),ot(),0;
}
//Author: disangan233
//In my dream's scene,I can see the everything that in Cyaegha.

Compiler output:
a.cc:30:1: error: expected unqualified-id before 'int'
   30 | int n,m,a[N][N];bitset<25605>f[N][N];
      | ^~~
a.cc: In function 'int main()':
a.cc:33:9: error: 'n' was not declared in this scope
   33 |         n=read();m=read();
      |         ^
a.cc:33:18: error: 'm' was not declared in this scope; did you mean 'tm'?
   33 |         n=read();m=read();
      |                  ^
      |                  tm
a.cc:34:53: error: 'a' was not declared in this scope
   34 |         for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) a[i][j]=read();
      |                                                     ^
a.cc:35:53: error: 'a' was not declared in this scope
   35 |         for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) a[i][j]=abs(a[i][j]-read());
      |                                                     ^
a.cc:36:17: error: 'a' was not declared in this scope
   36 |         f[1][1][a[1][1]+12800]=1;
      |                 ^
Language: C++

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sys/types.h>
#include <unistd.h>
#include <vector>

#pragma region macros
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) _range(i, 0, n)
#define _range(i, a, b) for (int i = int(a); i < int(b); ++i)
#define rep(...) _overload(__VA_ARGS__, _range, _rep, )(__VA_ARGS__)
#define _rrep(i, n) _rrange(i, n, 0)
#define _rrange(i, a, b) for (int i = int(a) - 1; i >= int(b); --i)
#define rrep(...) _overload(__VA_ARGS__, _rrange, _rrep, )(__VA_ARGS__)
#pragma endregion macros

using namespace std;

template <class T> bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T> bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

using ll    = long long;
using R     = long double;
const R EPS = 1e-9L;  // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R &r) {
    return (r > EPS) - (r < -EPS);
}
inline R sq(R x) {
    return sqrt(max(x, 0.0L));
}

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

const pid_t pid = getpid();
// Problem Specific Parameter:

using pii = pair<int, int>;
map<int, vector<pii>> memo;

inline ll sum(ll l, ll r, ll d) {
    const ll n = r - l;
    return 1LL * d * (l + r - 1) * n / 2LL;
}


int main(void) {
    ll n, x, d;
    cin >> n >> x >> d;
    const ll pd = abs(2LL * d);


    rep(i, n + 1) {
        const ll xfix = 1LL * (n - i) * x - 1LL * i * x;
        const ll dmax = sum(i, n, d) - sum(0, i, d);
        const ll dmin = sum(0, n - i, d) - sum(n - i, n, d);

        const ll vmax   = xfix + dmax;
        const ll vmin   = xfix + dmin;
        const ll offset = (vmax % pd + pd) % pd;

        const ll imax = (vmax - offset) / pd;
        const ll imin = (vmin - offset) / pd;

        // cerr << vmax << " " << vmin << endl;

        // cerr << abs(vmin) % pd << " [" << imin << ", " << imax + 1 << ")"
        //      << endl;
        memo[offset].push_back(pii(min(imin, imax), 1));
        memo[offset].push_back(pii(max(imin, imax) + 1, -1));
    }

    ll ans = 0LL;
    for (auto &it: memo) {
        vector<pii> ary = it.second;
        sort(begin(ary), end(ary));

        ll cnt = 0, prv = -1;
        for (auto &elem: ary) {
            if (cnt > 0) {
                assert(elem.first - prv >= 0);
                ans += elem.first - prv;
            }

            // cerr << elem.first << " " << elem.second << endl;
            prv = elem.first;
            cnt += elem.second;
        }
    }

    cout << ans << endl;

    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:93:17: error: 'assert' was not declared in this scope
   93 |                 assert(elem.first - prv >= 0);
      |                 ^~~~~~
a.cc:13:1: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
   12 | #include <unistd.h>
  +++ |+#include <cassert>
   13 | #include <vector>
Language: C++

#include <iostream>
#include <vector>
#include <utility>
#include <map>
using namespace std;
long long ap(long long X, long long D, long long N){
	return (X * 2 + D * (N - 1)) * N / 2;
}
int main(){
	long long N, X, D;
	cin >> N >> X >> D;
	if (D < 0){
		X += (N - 1) * D;
		D = -D;
	}
	long long sum = ap(X, D, N);
	map<int, vector<pair<long long, long long>>> mp;
	for (int i = 0; i <= N; i++){
		long long sum1 = ap(X, D, i);
		long long diff1 = sum1 - (sum - sum1);
		long long sum2 = ap(X, D, N - i);
		long long diff2 = (sum - sum2) - sum2;
		long long r = (diff1 % (D * 2) + D * 2) % (D * 2);
		mp[r].push_back(make_pair(diff2, diff1));
	}
	long long ans = 0;
	for (auto P : mp){
		int r = P.first;
		vector<pair<long long, long long>> R = P.second;
		sort(R.begin(), R.end());
		int cnt = R.size();
		for (int i = 0; i < cnt; i++){
			R[i].first = (R[i].first - r) / (D * 2);
			R[i].second = (R[i].second - r) / (D * 2);
		}
		vector<pair<long long, long long>> R2;
		for (int i = 0; i < cnt; i++){
			long long left = R[i].second;
			long long right = R[i].first;
			while (!R2.empty()){
				if (left <= R2.back().first){
					left = min(left, R2.back().second);
					R2.pop_back();
				} else {
					break;
				}
			}
			R2.push_back(make_pair(right, left));
		}
		int cnt2 = R2.size();
		for (int i = 0; i < cnt2; i++){
			ans += R2[i].first - R2[i].second + 1;
		}
	}
	cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:30:17: error: 'sort' was not declared in this scope; did you mean 'short'?
   30 |                 sort(R.begin(), R.end());
      |                 ^~~~
      |                 short
Language: C++

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long ll;

ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}
ll kai(ll x, ll y, ll m) {
	ll res = 1;
	for (ll i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
ll mod_pow(ll x, ll y, ll m) {
	ll res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

ll comb(ll x, ll y, ll m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

ll n, x, d;
map<int, vector<pair<ll, ll>>> mp;
set<int> st;
ll ans;

signed main() {
	cin >> n >> x >> d;
	if (d == 0) {
		if (x != 0)cout << n + 1 << endl;
		else cout << 1 << endl;
		return 0;
	}
	for (ll i = 0; i <= n; i++) {
		ll p = x * i + i * (i - 1) / 2 * d;
		ll q = x * i + (n*(n - 1) / 2 - (n - i)*(n - i - 1) / 2)*d;
		ll mi = min(p, q);
		ll ma = max(p, q);
		mp[(abs(d) + ma % abs(d)) % abs(d)].push_back(make_pair(mi, ma));
		st.insert((abs(d) + ma % abs(d)) % abs(d));
	}
	auto p = st.begin();
	while (p != st.end()) {
		sort(all(mp[*p]));
		ll ma = LLONG_MIN;
		for (int i = 0; i < (int)mp[*p].size(); i++) {
			if (mp[*p][i].second < ma)continue;
			ans += (mp[*p][i].second - max(ma, mp[*p][i].first)) / abs(d) + 1;
			ma = mp[*p][i].second + abs(d);
		}
		p++;
	}
	cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:77:25: error: 'LLONG_MIN' was not declared in this scope
   77 |                 ll ma = LLONG_MIN;
      |                         ^~~~~~~~~
a.cc:19:1: note: 'LLONG_MIN' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
   18 | #include <cstdio>
  +++ |+#include <climits>
   19 | using namespace std;
Language: C++

#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <ctime>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

struct dat{
	ll d,u,r;
};

int main(){
	ll n,x,d; cin >> n >> x >> d;
	if(d == 0){
		cout << n + 1 << endl;
		return 0;
	}
	vector<dat> v(n+2);
	ll t = n*(n-1)/2;
	ll q = x / d;
	ll r = 2 * x % d;
	ll ans = 0;
	rep(i,n+1){
		v[i].d = i*(i-1) - t;
		v[i].u = t - (n-i)*(n-i-1);
		ans += (v[i].u - v[i].d) / 2 + 1


	}
	vector<map<ll,set<P>>> mse(2);
	v[0].r = 0;
	ll sumq = 0;
	rep(i,n+1){
		//print3(v[i].d, v[i].u, v[i].r);
		ll ab = abs(v[i].d);
		auto itr = lower_bound(all(mse[ab%2][v[i].r]), P(v[i].d, -inf));
		vpl li;
		while(itr != mse[ab%2][v[i].r].end() && (*itr).second <= v[i].u){
			ans -= (min((*itr).first, v[i].u) - max((*itr).second, v[i].d)) / 2 + 1;
			li.emplace_back(*itr);
			itr++;
		}
		for(auto j : li) mse[ab%2][v[i].r].erase(j);
		mse[ab%2][v[i].r].emplace(v[i].u, v[i].d);
		ll q;
		if(x < 0) q = (2 * x - abs(d) + 1) / d;
		else q = 2 * x / d;
		ll r = 2 * x - d * q;
		if(v[i].r + r >= abs(d)){
			if(d < 0) q--;
			else q++;
			v[i+1].r = v[i].r + r - abs(d);
		}else{
			v[i+1].r = v[i].r + r;
		}
		sumq += q;
		v[i+1].d += sumq;
		v[i+1].u += sumq;
		//cout << ans << endl;
	}
	cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:78:49: error: expected ';' before '}' token
   78 |                 ans += (v[i].u - v[i].d) / 2 + 1
      |                                                 ^
      |                                                 ;
......
   81 |         }
      |         ~
Language: C++

#include<iostream>
#include<iomanip>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
#include<memory>
using namespace std;
using ll=__int128;

int main(){
    ll n;
    long long tmp;
    cin>>tmp;
    n=tmp;
    ll x,d;
    cin>>tmp;
    x = tmp;
    cin>>tmp;
    d=tmp;
    if(d==0){
        if(x==0) cout<<1<<endl;
        else{
            cout<<long long(n*(n-1)/2+1)<<endl;
        }
        return 0;
    }
    map<ll,map<ll,int>> mp;
    for(int i=0;i<=n;i++){
        ll offset = i*x - (n-i)*x;
        ll plus = (n*(n-1)/2 - (n-i)*(n-i-1))*d;
        ll minus = (ll(i)*(i-1) - (n-1)*n/2)*d;
        if(d<0) swap(plus,minus);
        const ll mod = 2*(d<0 ? -d : d);
        ll l = minus + offset;
        ll r = plus + offset + mod;
        ll id = (l%mod+mod)%mod;
        mp[id][(l-id)/mod]++;
        mp[id][(r-id)/mod]--;
    }
    ll res = 0;
    for(auto &imo:mp){
        int sum = 0;
        ll l;
        for(auto &e:imo.second){
            if(sum) res+=e.first-l;
            l=e.first;
            sum+=e.second;
        }
    }
    cout<<(long long)(res)<<endl;
    
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:41:19: error: expected primary-expression before 'long'
   41 |             cout<<long long(n*(n-1)/2+1)<<endl;
      |                   ^~~~
Language: C++

#include<iostream>
#include<iomanip>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
#include<memory>
using namespace std;
using ll=long long;

const ll INF = 1e16;
int main(){
    ll n;
    cin>>n;
    ll x,d;
    cin>>x>>d;
    if(d==0){
        if(x==0) cout<<1<<endl;
        else{
            cout<<(n*(n-1))<<endl;
        }
        return 0;
    }
    map<ll,map<ll,int>> mp;
    for(int i=0;i<=n;i++){
        ll offset = i*x - (n-i)*x +INF;
        ll plus = (n*(n-1)/2 - ll(n-i)*(n-i-1))*d;
        ll minus = (i*(i-1) - (n-1)*n/2)*d;
        if(d<0) swap(plus,minus);
        const int mod = 2*abs(d)
        ll l = minus + offset;
        ll r = plus + offset + mod;
        ll id = (l%(mod)+mod)%mod;
        mp[id][l/mod]++;
        mp[id][r/mod]--;
    }
    ll res = 0;
    for(auto &imo:mp){
        int sum = 0;
        ll l = -INF;
        for(auto &e:imo.second){
            if(sum) res+=e.first-l;
            l=e.first;
            sum+=e.second;
        }
    }
    cout<<res<<endl;
    
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:48:9: error: expected ',' or ';' before 'll'
   48 |         ll l = minus + offset;
      |         ^~
a.cc:50:18: error: 'l' was not declared in this scope
   50 |         ll id = (l%(mod)+mod)%mod;
      |                  ^
Language: C++

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <utility>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<pll> vp;

int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int n, x, d;
    cin >> n >> x >> d;

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

    int t = gcd(abs(x), abs(d));
    x /= t;
    d /= t;

    if (d < 0) {
        x *= -1;
        d *= -1;
    }

    vp sg[n+1];
    for (int i = 0; i <= n; i++) {
        ll l = 1ll * (0 + (i - 1)) * i / 2 + 1ll * x * (i / d);
        ll r = 1ll * ((n - i) + (n - 1)) * i / 2 + 1ll * x * (i / d) + 1;
        sg[i%d].push_back({l, r});
    }

    ll ans = 0;
    for (int i = 0; i <= n; i++) {
        sort(sg[i].begin(), sg[i].end());

        ll l = -1e14, r = -1e14;
        for (pll p : sg[i]) {
            if (p.first > r) {
                ans += r - l;
                l = p.first;
                r = p.second;
            } else {
                r = max(r, p.second);
            }
        }
        ans += r - l;
    }

    cout << ans << endl;

    return 0;
}


Compiler output:
a.cc:10:9: error: 'vector' does not name a type
   10 | typedef vector<pll> vp;
      |         ^~~~~~
a.cc: In function 'int main()':
a.cc:37:5: error: 'vp' was not declared in this scope
   37 |     vp sg[n+1];
      |     ^~
a.cc:41:9: error: 'sg' was not declared in this scope
   41 |         sg[i%d].push_back({l, r});
      |         ^~
a.cc:46:14: error: 'sg' was not declared in this scope
   46 |         sort(sg[i].begin(), sg[i].end());
      |              ^~
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

template<class T> inline bool chmin(T &a,T b){
    if (a>b){a=b; return true;} return false;
}
template<class T> inline bool chmax(T &a,T b){
    if (a<b){a=b; return true;} return false;
}

ll gcd(ll x,ll y){
    if (y==0) return x;
    return gcd(y,x%y);
}
ll lcm(ll x,ll y){
    return x/gcd(x,y)*y;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,X,D; cin >> N >> X >> D;
    if (X==0&&D==0){
        cout << 1 << endl;
        return 0;
    }
    if (X==0){
        cout << N*(N-1)/2+1 << endl;
        return 0;
    }
    if (D==0){
        cout << N << endl;
        return 0;
    }
    ll G=gcd(abs(X),abs(D)); X/=G,D/=G;
    if (D<0) X*=-1,D*=-1;
    ll ans=0;
    if (X>0){
        vector<ll> mini(N+1,0),maxi(N+1,0);
        rep(i,N+1){
            ll m=i*(i-1)/2,M=i*(2*N-1-i)/2+1;
            if (maxi[i]){
                ans+=maxi[i]-mini[i];
                m=max(maxi[i],m);
            }
            if (i+D<N){
                mini[i]=min(X,m),maxi[i]=min(X,M);
                mini[i+D]=max(0LL,m-X),maxi[i+D]=max(0LL,M-X);
            } else mini[i]=m,maxi[i]=M;
        }
    }
    rep(i,N+1) ans+=maxi[i]-mini[i];
    cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:65:21: error: 'maxi' was not declared in this scope
   65 |     rep(i,N+1) ans+=maxi[i]-mini[i];
      |                     ^~~~
a.cc:65:29: error: 'mini' was not declared in this scope
   65 |     rep(i,N+1) ans+=maxi[i]-mini[i];
      |                             ^~~~
Language: C++

#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define int ll
ll solve(vector<P> vec){
  vector<ll> comp;
  ll n=vec.size(),res=0;
  for(int i=0;i<n;i++){
    comp.push_back(vec[i].first);
    comp.push_back(vec[i].first+vec[i].second);
  }
  sort(comp.begin(),comp.end());
  comp.erase(unique(comp.begin(),comp.end()),comp.end());
  vector<ll> imos(comp.size()+100,0);
  for(int i=0;i<n;i++){
    ll Llb=lower_bound(comp.begin(),comp.end(),vec[i].first)-comp.begin();
    ll Rlb=lower_bound(comp.begin(),comp.end(),vec[i].first+vec[i].second)-comp.begin();
    imos[Llb]++;
    imos[Rlb]--;
  }
  for(int i=1;i<imos.size();i++) imos[i]+=imos[i-1];
  for(int i=0;i<imos.size()-1;i++) res+=(imos[i]>0?(ll)1:(ll)0)*(comp[i+1]-comp[i]);
  return res;
}
signed main(){
  ll n,x,d;
  cin>>n>>x>>d;
  if(d<0){
    d=abs(d);
    x-=(n-1)*d
  }
  else if(d==0){
    if(x==0) cout<<1<<endl;
    else cout<<n+1<<endl;
    return 0;
  }
  vector<P> vec;
  vector<ll> comp;
  for(ll k=0;k<=n;k++){
    ll kx=k*x;
    ll l=k*(k-1)/2;
    ll r=(2*n-k-1)*k/2;
    r++;
    ll r2=r-l;
    comp.push_back((kx+l*d)%d);
    vec.push_back(P(kx+l*d,r2));
  }
  sort(comp.begin(),comp.end());
  comp.erase(unique(comp.begin(),comp.end()),comp.end());
  vector<P> vc[comp.size()+5];
  for(int i=0;i<vec.size();i++){
    ll md=vec[i].first%d;
    ll pos=lower_bound(comp.begin(),comp.end(),md)-comp.begin();

    ll nk=(vec[i].first-md)/d;
    vc[pos].push_back(P(nk,vec[i].second));
  }
  ll ans=0;
  for(int i=0;i<comp.size();i++){
    ans+=solve(vc[i]);
  }
  cout<<ans<<endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:34:15: error: expected ';' before '}' token
   34 |     x-=(n-1)*d
      |               ^
      |               ;
   35 |   }
      |   ~
Language: C++

#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <cassert>
#include <boost/multiprecision/cpp_int.hpp>

namespace mp = boost::multiprecision;

using namespace std;

using ll = mp::cpp_int;
using Pll = pair<ll, ll>;

constexpr ll INF = ll(1) << 60;

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

    if(d == 0) {
        cout << ((x == 0) ? ll(1) : n+1) << endl;
        return 0;
    } else if(d < 0) {
        x *= -1;
        d *= -1;
    }

    map<ll, vector<Pll>> mp;
    for(ll i=0;i<=n;++i) {
        ll l = (i-1) * i / 2, r = (n-i) * i + l;
        Pll p = {
            i * x + d * l, 
            r - l
        };
        mp[((p.first % d) + d) % d].push_back(p);
    }

    ll ans = 0LL;
    for(auto itr=mp.begin();itr!=mp.end();++itr) {
        vector<Pll> v(itr->second);
        sort(v.begin(), v.end());

        ll max_r = -INF;
        for(Pll p: v) {
            if(max_r < p.first / d) {
                ans += p.second + 1;
            } else {
                ans += p.second + 1 - (max_r - p.first/d + 1);
            }
            max_r = p.first / d + p.second;
        }
    }

    cout << ans << endl;
}

Compiler output:
a.cc:6:10: fatal error: boost/multiprecision/cpp_int.hpp: No such file or directory
    6 | #include <boost/multiprecision/cpp_int.hpp>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Language: C++

#include <iostream>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;

using ll = long long;
using Pll = pair<ll, ll>;

constexpr ll INF = 1LL << 60;

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

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

    if(x < 0) assert(false);

    map<ll, vector<Pll>> mp;
    for(ll i=0;i<=n;++i) {
        ll l = (i-1) * i / 2, r = (n-i) * i + l;
        Pll p = {
            i * x + d * l, 
            r - l
        };
        mp[((p.first % d) + d) % d].push_back(p);
    }

    ll ans = 0LL;
    for(auto itr=mp.begin();itr!=mp.end();++itr) {
        vector<Pll> v(itr->second);
        sort(v.begin(), v.end());

        ll max_r = -INF;
        for(Pll p: v) {
            if(max_r < p.first/d) {
                ans += p.second + 1;
            } else {
                ans += p.second + 1 - (max_r - p.first/d + 1);
            }
            max_r = p.first / d + p.second;
        }
    }

    cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:25:15: error: 'assert' was not declared in this scope
   25 |     if(x < 0) assert(false);
      |               ^~~~~~
a.cc:5:1: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
    4 | #include <algorithm>
  +++ |+#include <cassert>
    5 |
Language: C++

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5+7;
const long long INF = 1e18;

int x, d, n;
int a[N];
long long res;
vector<pair<long long, long long>> v;

inline long long sum(int l, int r) { return l <= r ? 1ll*(l+r)*(r-l+1)/2 : 0; }
inline bool cmp (const int i, const int j) { return 1ll*i*x%d < 1ll*j*x%d; }

inline void calc()
{
    if (!v.size()) return;
    sort(v.begin(), v.end());
    long long last = -INF;
    for (auto p : v) {
        long long l = p.first, r = p.second;
        res += max(0ll, r-max(l-1, last));
        last = max(last, r);
    }
}

int main()
{
    scanf("%d %d %d", &n, &x, &d);
    if (d == 0) {
        if (x == 0) return puts("1")&0;
        // return printf("%lld\n", 1ll*(1+n)*n/2+1)&0;
        return printf("%d\n", n+1)&0;
    }
    if (d < 0) d = -d, x = -x;
    for (int i = 0; i <= n; ++i) a[i] = i;
    sort(a, a+n+1, cmp);
    long long xd, l, r;
    for (int i = 0; i <= n; ++i) {
        xd = 1ll*a[i]*x/d;
        l = xd+sum(0, a[i]-1);
        r = xd+sum(n-a[i], n-1);
        v.emplace_back(l, r);
        if (i == n || mod(a[i]) != mod(a[i+1])) {
            calc();
            v.clear();
        }
    }
    return printf("%lld\n", res)&0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:45:23: error: 'mod' was not declared in this scope; did you mean 'modf'?
   45 |         if (i == n || mod(a[i]) != mod(a[i+1])) {
      |                       ^~~
      |                       modf
Language: C++

#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
using namespace std;
//using namespace boost::multiprecision;

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}


int main(){
  
  long long n;
  long long x,d;
  cin>>n>>x>>d;
  
  map<long long, vector<pair<long long, long long>>> mp;
  REPP(i,n){
    long long c = k*x;
    long long l = (k-1)*k/2;
    long long r = l + (n-k)*k;
    long long s = r - l;
    //c ~ c + D(R-L) の値をDごとに取る。
    long long modulo = (c%d + d)%d;
    c = (c- modulo)/d;
    //(c - modulo)/d ~ (c - modulo)/d + (R-L) の値を取る。
    mp[modulo].emplace_back(c,s);
  }
  
  long long ans = 0;
  for(auto p:mp){
    long long modulo = p.first;
    vector<pair<long long, long long>> vec = p.second;
    int m = vec.size();
    vector<pair<long long, int>> events;
    REP(i,m){
      long long c = vec[i].first;
      long long s = vec[i].second;
      events.emplace_back(c, 1);
      events.emplace_back(c + s + 1, -1);
    }
    sort(ALL(events));
    int cnt = 0;
    long long now = -INF;
    REP(i,m){
      if(cnt > 0){
        ans += events[i].first - now;
      }
      cnt += events[i].second;
      now = events[i].first;
    }
  }
  cout<<ans<<endl;
  return 0; 
}


Compiler output:
a.cc: In function 'int main()':
a.cc:74:19: error: 'k' was not declared in this scope
   74 |     long long c = k*x;
      |                   ^
Language: C++

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())
#define GRAYCODE(i) ((i) ^ ((i) >> 1))

using ll = long long;
using Pi_i = pair<int, int>;
using VI = vector<int>;
using VD = vector<double>;
using VLL = vector<ll>;
using VS = vector<string>;
using VC = vector<char>;
using VB = vector<bool>;

const int MOD = 1000000007;
const int INF = 1000000000;

template<class T>
bool chmax(T &a, const T &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T>
bool chmin(T &a, const T &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}




int main(){
    int N, X, D; cin >> N >> X >> D;
    if(!D){
        cout << (X ? N+1 : 0) << "\n";
        return 0;
    }
    // modD, lt, rt(exclusive)
    if(D < 0){
        X += D * (N - 1); D *= -1
    }
    vector<pair<ll, pair<ll, ll>>> p(1 + N);
    ll XmodD = (ll(X) % D + D) % D;
    REPS(i, N){// i個の時
        ll SmodD = (XmodD * i) % D;
        ll iX = ((ll)X * i - SmodD) / D;//X<0の時のため
        p[i] = MP(SmodD, MP(iX + i * (i-1) / 2,
                            iX + i * (2*N - i - 1 ) / 2 + 1));
    }
    SORT(p);
    ll prv = -1, ans = 0;
    vector<pair<ll, ll>> q;
    REPS(i, N){
        if(prv != p[i].first){
            q.PB(p[i].second);
            prv = p[i].first;
        }else{
            if(q.back().second >= p[i].second.first)
                chmax(q.back().second, p[i].second.second);
            else q.PB(p[i].second);
        }
    }
    for(auto &a: q) ans += a.second - a.first;
    cout << ans << "\n";
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:89:34: error: expected ';' before '}' token
   89 |         X += D * (N - 1); D *= -1
      |                                  ^
      |                                  ;
   90 |     }
      |     ~