alexjercan/bugnet huggingface dataset:
Problem p02702 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define PI acos(-1)
#define pb push_back
#define int long long
#define ld long double
#define sp fixed << setprecision
#define bp __builtin_popcountll
#define all(x) x.begin(), x.end()
#define pii pair<long long, long long>
#define FAST                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);

int MOD = (1e9) + 7;
const int N = 200005;

signed main() {
  int M = 2019;
  FAST int tc = 1;
  // cin>>tc;
  for (int ti = 1; ti <= tc; ti++) {
    int n;
    string s;
    cin >> s;
    n = s.length();
    int dp[2][M];
    memset(dp, 0, sizeof(dp));
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 0; j < M; j++)
        dp[i % 2][j] = 0;
      dp[i % 2][s[i - 1] - '0']++;
      for (int j = 0; j < M; j++)
        dp[i % 2][((j * 10) + s[i - 1] - '0') % M] += dp[(i - 1) % 2][j];
      ans += dp[i % 2][0];
    }
    cout << ans << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define PI acos(-1)
#define pb push_back
#define int long long
#define ld long double
#define sp fixed << setprecision
#define bp __builtin_popcountll
#define all(x) x.begin(), x.end()
#define pii pair<long long, long long>
#define FAST                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);

int MOD = (1e9) + 7;
const int N = 1e6 + 5;

signed main() {
  int M = 2019;
  int S = M / 3;
  FAST int tc = 1;
  // cin>>tc;
  for (int ti = 1; ti <= tc; ti++) {
    int n;
    string s;
    cin >> s;
    n = s.length();
    int dp[n + 1][M];
    memset(dp, 0, sizeof(dp));
    int curr = 0, prev = 0;
    for (int i = 1; i <= n; i++) {
      dp[i][s[i - 1] - '0']++;
      for (int j = 0; j < M; j++)
        dp[i][((j * 10) + s[i - 1] - '0') % M] += dp[i - 1][j];
    }
    int ans = 0;
    for (int i = 1; i <= n; i++)
      ans += dp[i][0];
    cout << ans << endl;
  }
  return 0;
}
Problem p02702 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const int INF = (1 << 30) - 1;
const long long LINF = (1LL << 62) - 1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, p;
  string s;
  cin >> s;
  n = s.size(), p = 2019;
  if (p != 2 && p != 5) {
    vector<ll> num(p);
    ll prev = (s[n - 1] - '0') % p, rem10n = 1;
    num[prev]++;
    for (int i = n - 2; i >= 0; i--) {
      (rem10n *= 10) %= p;
      prev = ((s[i] - '0') % p * rem10n + prev) % p;
      num[prev]++;
    }
    ll ans = 0;
    rep(i, p) ans += num[i] * (num[i] - 1) / 2;
    ans += num[0];
    cout << ans << endl;
  } else {
    vector<vector<ll>> dp(n + 1, vector<ll>(p));
    rep(i, n) {
      int a = s[i] - '0';
      rep(j, p) dp[i + 1][(j * 10 + a) % p] += dp[i][j];
      dp[i + 1][a % p]++;
    }
    ll ans = 0;
    rep(i, n + 1) ans += dp[i][0];
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1 << 30) - 1;
const long long LINF = (1LL << 62) - 1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

const int MOD = 2019;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int n = s.size();
  map<int, int> mp;
  ll ans = 0;
  rep(i, n) {
    map<int, int> tmp;
    for (auto e : mp)
      tmp[(e.first * 10 + s[i] - '0') % MOD] += e.second;
    tmp[s[i] - '0']++;
    mp = tmp;
    ans += tmp[0];
  }
  cout << ans << endl;
  return 0;
}
Problem p02702 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
const ll MOD = 1000000007;

ll ll_pow(long long x, long long n) {
  long long ret = 1;
  while (n > 0) {
    if (n & 1)
      ret = ret * x % 2019; // n の最下位bitが 1 ならば x^(2^i) をかける
    x = x * x % 2019;
    n >>= 1; // n を1bit 左にずらす
  }
  return ret;
}

int main() {
  string S;
  cin >> S;
  ll N = S.size();
  vector<ll> amari(N);
  reverse(S.begin(), S.end());
  rep(i, N) {
    ll a = S.at(i) - '0';
    /*rep(j,i)
    {
      a*=10;
      a%=2019;
    }*/

    a = a * ll_pow(10, i) % 2019;
    amari.at(i) = a;
  }
  vector<ll> sum(N);
  rep(i, N) {
    if (i == 0) {
      sum.at(0) = amari.at(0);
    } else {
      ll a = sum.at(i - 1) + amari.at(i);
      sum.at(i) = a % 2019;
    }
  }
  ll ans = 0;
  vector<ll> num(2019);
  rep(i, N) {
    ll a = sum.at(i);
    num.at(a)++;
  }
  rep(i, 2019) {
    ll a = 0;
    if (i == 0) {
      ll b = num.at(0);
      if (b == 0) {
        a = 0;
      } else {
        a = b + b * (b - 1) / 2;
      }
    } else {
      ll b = num.at(i);
      if (b <= 1) {
        a = 0;
      } else {
        a = b * (b - 1) / 2;
      }
    }
    ans += a;
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
const ll MOD = 1000000007;

int main() {
  string S;
  cin >> S;
  ll N = S.size();
  vector<ll> amari(N);
  reverse(S.begin(), S.end());
  rep(i, N) {
    ll a = S.at(i) - '0';
    rep(j, i) {
      a *= 10;
      a %= 2019;
    }
    amari.at(i) = a;
  }
  vector<ll> sum(N);
  rep(i, N) {
    if (i == 0) {
      sum.at(0) = amari.at(0);
    } else {
      ll a = sum.at(i - 1) + amari.at(i);
      sum.at(i) = a % 2019;
    }
  }
  ll ans = 0;
  vector<ll> num(2019);
  rep(i, N) {
    ll a = sum.at(i);
    num.at(a)++;
  }
  rep(i, 2019) {
    ll a = 0;
    if (i == 0) {
      ll b = num.at(0);
      if (b == 0) {
        a = 0;
      } else {
        a = b + b * (b - 1) / 2;
      }
    } else {
      ll b = num.at(i);
      if (b <= 1) {
        a = 0;
      } else {
        a = b * (b - 1) / 2;
      }
    }
    ans += a;
  }
  cout << ans << endl;
  return 0;
}
Problem p02702 (C++) — buggy submission, verdict: Runtime Error

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for (int i = 0; i < (N); i++)
#define repo(i, N) for (int i = 1; i < (N); i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
// #define num 1000000007
#define pi acos(-1.0)
// cout << fixed << setprecision (20);   小数点以下2０桁まで
// intの最大値2147483647 ≒ 2×10^9
// long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
// string s = to_string(int数);
// int n = stoi(string文字列);

int main() {
  string s;
  cin >> s;
  int n = s.size();

  int ans = 0;

  vector<int> p(2019, 0);
  p[0] = 1;

  int now = 0;
  int ju = 1;
  for (int i = n - 1; i >= 0; i--) {
    int x = s[i] - '0';
    now += x * ju;
    now %= 2019;
    p[now]++;
    ju = (ju * 10) % 2019;
  }

  rep(i, 2019) {
    if (p[i] >= 2)
      ans += p[i] * (p[i] - 1) / 2;
  }

  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define SZ(x) ((int)(x).size())
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
const double pi = acos(-1);

int main() {

  long long s;
  cin >> s;

  int ans = 0;

  int di = 10 * (log10(s) + 1) / 10;

  vector<long long> tori(di - 2);
  tori.at(0) = s * 10;

  for (int i = 1; i < di - 2; i++) {
    tori.at(i) = tori.at(i - 1) / 10;
  }

  tori.at(0) = 1;

  for (int i = 1; i <= di - 3; i++) {
    rep(j, di + 2 - i) {
      int ju = pow(10, j);
      if (tori.at(i) % ju != 0 && (tori.at(i) % ju) % 2019 == 0) {
        ans++;
      }
    }
  }

  cout << ans << endl;
}
Problem p02702 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;

void prvec(vector<ll> vec) {
  ll n = vec.size();
  rep(i, n) cout << i << " " << vec.at(i) << "\\n";
}

void pr2d(vector<vector<ll>> vvec) {
  ll h = vvec.size();
  ll w = vvec.at(0).size();
  rep(i, h) {
    rep(j, w) { cout << vvec.at(i).at(j) << " "; }
    cout << "\\n";
  }
}

long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

int main() {
  string s;
  cin >> s;
  ll ss = s.size();
  vector<ll> cnt(2019, 0);
  cnt.at(0)++;
  ll mem = 0;
  for (int i = ss - 1; i >= 0; i--) {
    ll x = s.at(i) - '0';
    x = x * modpow(10, ss - 1 - i, 2019);
    x %= 2019;
    mem = (mem + x) % 2019;
    cnt.at(mem)++;
    // rep(j,2019){
    //     if(cnt.at(j)>0) cout << j << " " << cnt.at(j) << endl;
    // }
  }
  ll ans = 0;
  rep(i, 2019) { ans += cnt.at(i) * (cnt.at(i) - 1) / 2; }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;

void prvec(vector<ll> vec) {
  ll n = vec.size();
  rep(i, n) cout << i << " " << vec.at(i) << "\\n";
}

void pr2d(vector<vector<ll>> vvec) {
  ll h = vvec.size();
  ll w = vvec.at(0).size();
  rep(i, h) {
    rep(j, w) { cout << vvec.at(i).at(j) << " "; }
    cout << "\\n";
  }
}

int main() {
  string s;
  cin >> s;
  deque<ll> dq;
  ll ss = s.size();
  ll cnt = 0;
  rep(i, ss) {
    ll x = s.at(i) - '0';
    ll dqs = dq.size();
    for (int j = 0; j < dqs; j++) {
      ll y = dq.front();
      y = (y * 10 + x) % 2019;
      if (y == 0)
        cnt++;
      dq.push_back(y);
      dq.pop_front();
    }
    dq.push_back(x);
  }
  cout << cnt << endl;
}
Problem p02702 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define endl "\\n"
using namespace std;
typedef long long int lli;
const lli N = 2019;
lli dp[N], ans;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  lli i, j, n = s.length();

  for (i = 0; i < n; i++) {
    dp[0]++;
    lli dp1[2019], cur = s[i] - '0';
    memset(dp1, 0LL, sizeof(dp1));
    for (j = 0; j < 2019; j++) {
      dp1[(j * 10 + cur) % 2019] += dp[j];
    }
    for (j = 0; j < 2019; j++) {
      dp[j] = dp1[j];
    }
    ans += dp[0];
  }
  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define endl "\\n"
using namespace std;
typedef long long int lli;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  while (1) {
    lli a = 1;
  }
  return 0;
}
Problem p02702 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

  string s;
  cin >> s;
  ll n = s.length();

  vector<ll> val(2019, 0);
  ll fac = 1;
  ll cur = 0;
  // なぜ行う？
  // 右からn文字目をs[n]として
  // s[a] と s[b] を 2019 で割った余りが等しい場合に答えの組み合わせが増えていく
  // s[b]がb=0の場合も含まれる（文字列の一番右まで見た場合）ため、s[0]の時の余りも組み合わせの一つとして入れておく
  val[cur]++;

  for (ll i = 0; i < n; ++i) {
    ll add = s[n - 1 - i] - '0'; // 後ろから見ていく
    cur = (cur + fac * add) % 2019;
    fac = (fac * 10) % 2019; // 10倍していく方も事前に2019で割っておいて良い
    val[cur]++;
  }

  ll ans = 0;
  for (ll i = 0; i < (ll)val.size(); ++i) {
    ans += val[i] * (val[i] - 1) / 2; // nC2を計算
  }

  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

  string s;
  cin >> s;
  ll n = s.length();

  ll ans = 0;
  for (ll i = 0; i < n; ++i) {
    for (ll j = 1; i + j <= n; ++j) {
      string t = s.substr(i, j);

      if (stoll(t) % 2019 == 0) {
        ++ans;
        i = i + j - 2;
        break;
      }
    }
  }

  cout << ans << endl;
}
Problem p02702 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

int main() {

  string S;
  cin >> S;
  long long len = S.length();

  long long count = 0;

  vector<long long> mod(2019, 0);

  long long nowNum = 0;
  long long digit = 1;
  long long nowMod = nowNum % 2019;
  mod[nowMod]++;
  for (long long i = len - 1; i >= 0; i--) {
    nowNum = (nowNum + (S[i] - '0') * digit) % 2019;
    digit = (digit * 10) % 2019;
    mod[nowNum % 2019]++;
  }

  for (long long i = 0; i < 2019; i++) {
    if (mod[i] <= 0)
      continue;
    else {
      count += mod[i] * (mod[i] - 1) / 2;
    }
  }

  cout << count << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {

  cin.tie(0);
  ios::sync_with_stdio(0);

  string S;
  cin >> S;
  int len = S.length();

  int count = 0;

  for (int i = 0; i < len; i++) {
    for (int j = i + 3; j < len; j++) {
      string nowStr = S.substr(i, j - i + 1);
      int num = atoi(nowStr.c_str());
      if (num % 2019 == 0)
        count++;
    }
  }

  cout << count << endl;
}
Problem p02702 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define REP(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define pb(a) push_back(a)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

typedef long long unsigned int ull;
typedef long long int ll;
typedef pair<ll, ll> P;

int main() {
  string s;
  cin >> s;
  int n = s.length();
  int mod2019[n];
  mod2019[0] = 1;
  REP(i, n - 1) { mod2019[i + 1] = mod2019[i] * 10 % 2019; }
  REP(i, n) { mod2019[i] *= s[n - i - 1] - '0'; }
  REP(i, n - 1) {
    mod2019[i + 1] += mod2019[i];
    mod2019[i + 1] %= 2019;
  }
  ll cnt[2019] = {};
  REP(i, 2019) {
    REP(j, n) {
      if (mod2019[j] == i) {
        cnt[i]++;
      }
    }
  }
  ll ans = cnt[0];
  REP(i, 2019) { ans += cnt[i] * (cnt[i] - 1) / 2; }

  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define REP(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define pb(a) push_back(a)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

typedef long long unsigned int ull;
typedef long long int ll;
typedef pair<ll, ll> P;

int main() {
  string s;
  cin >> s;
  int n = s.length();
  int mod2019[n];
  mod2019[0] = s[n - 1] - '0';
  REP(i, n - 1) {
    mod2019[i + 1] = mod2019[i] * 10 % 2019;
    mod2019[i] *= s[n - i - 1] - '0';
  }
  REP(i, n) {
    mod2019[i + 1] += mod2019[i];
    mod2019[i + 1] %= 2019;
  }
  ll cnt[2019] = {};
  REP(i, 2019) {
    REP(j, n) {
      if (mod2019[j] == i) {
        cnt[i]++;
      }
    }
  }
  ll ans = cnt[0];
  REP(i, 2019) { ans += cnt[i] * (cnt[i] - 1) / 2; }

  cout << ans << endl;
}
Problem p02702 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define rep(i, N) for (ll i = 0; i < N; i++)
const int mx = 2e5;

int main(void) {

  string S;
  cin >> S;

  int mods[S.length() + 1];
  int ketamod[S.length()];
  int modvs[2020];
  rep(i, 2020) modvs[i] = 0;

  ll ans = 0;
  mods[S.length()] = 0;
  for (ll i = S.length() - 1; i > -1; i--) {
    if (i == S.length() - 1) {
      ketamod[i] = 1;
      mods[i] = (int)(S[i] - '0');
    } else {
      ketamod[i] = ketamod[i + 1] * 10;
      ketamod[i] = ketamod[i] % 2019;
      mods[i] = mods[i + 1] + ketamod[i] * (int)(S[i] - '0');
      mods[i] = mods[i] % 2019;
      if (mods[i] == 0)
        ans++;
    }

    modvs[mods[i]]++;
  }

  rep(i, 2020) { ans += modvs[i] * (modvs[i] - 1) / 2; }

  cout << ans;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define rep(i, N) for (ll i = 0; i < N; i++)
const int mx = 2e5;

int main(void) {

  string S;
  cin >> S;

  int mods[S.length() + 1];
  int ketamod[S.length()];

  ll ans = 0;
  mods[S.length()] = 0;
  for (ll i = S.length() - 1; i > -1; i--) {
    if (i == S.length() - 1) {
      ketamod[i] = 1;
      mods[i] = (int)(S[i] - '0');
    } else {
      ketamod[i] = ketamod[i + 1] * 10;
      ketamod[i] = ketamod[i] % 2019;
      mods[i] = mods[i + 1] + ketamod[i] * (int)(S[i] - '0');
      mods[i] = mods[i] % 2019;
      if (mods[i] == 0)
        ans++;
    }

    if (S.length() - i > 3) {
      for (ll j = i + 3; j < S.length() - 1; j++) {
        if (mods[i] == mods[j + 1])
          ans++;
      }
    }
  }

  cout << ans;

  return 0;
}
Problem p02702 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 2019;
int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  string s;
  cin >> s;
  ll n = s.size();
  vector<ll> ab(n + 1, 0);
  ll tmp = 0;
  ll mod = 1;
  for (int i = 0; i < n; i++) {
    tmp += (ll(s[n - 1 - i] - '0') * mod);
    ab[i + 1] = tmp % MOD;
    mod *= 10;
    mod %= MOD;
  }
  ll ans = 0;
  vector<ll> c(2019, 0);
  for (int i = 0; i < n + 1; i++) {
    c[ab[i]]++;
  }
  for (int i = 0; i < 2019; i++) {
    ans += c[i] * (c[i] - 1) / 2;
  }
  cout << ans << endl;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 2019;
int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  string s;
  cin >> s;
  ll n = s.size();
  vector<ll> ab(n + 1, 0);
  ll tmp = 0;
  ll mod = 1;
  for (int i = 0; i < n; i++) {
    tmp += (ll(s[n - 1 - i] - '0') * mod);
    ab[i + 1] = tmp % MOD;
    mod *= 10;
    mod %= MOD;
  }
  ll ans = 0;
  vector<ll> c(2019, 0);
  for (int i = 0; i < n + 1; i++) {
    c[ab[i - 1]]++;
  }
  for (int i = 0; i < 2019; i++) {
    ans += c[i] * (c[i] - 1) / 2;
  }
  cout << ans << endl;
}
Problem p02702 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int, int>;
const ll inf = 1e18;
const int MAX = 100005;

// modpow
template <class T> T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1)
      result = (result * base) % modulus;
    base = (base * base) % modulus; // llにしないとダメ
    exp >>= 1;
  }
  return result;
}

int main() {
  string s;
  cin >> s;
  int n = s.size();
  map<ll, ll> mt;
  ll now = s[n - 1] - '0';
  mt[0]++;
  mt[now]++;
  for (int i = n - 2; i >= 0; i--) {
    now += (s[i] - '0') * modpow(10, n - i - 1, 2019);
    now %= 2019;
    mt[now]++;
  }
  ll ans = 0;
  for (auto pt = mt.begin(); pt != mt.end(); pt++) {
    ll x = pt->second;
    ans += x * (x - 1) / 2;
  }
  cout << ans << endl;
}

Error: -6
Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)


Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int, int>;
const ll inf = 1e18;
const int MAX = 100005;

// modpow
template <class T> T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1)
      result = (result * base) % modulus;
    base = (base * base) % modulus; // llにしないとダメ
    exp >>= 1;
  }
  return result;
}

int main() {
  string s;
  cin >> s;
  vector<int> c(s.size() + 1);
  int now = s[0] - '0';
  c[0] = 0;
  c[1] = now;
  for (int i = 1; i < s.size() + 1; i++) {
    now = now * 10 + (s[i] - '0');
    now %= 2019;
    c[i + 1] = now;
  }
  int ans = 0;
  rep(i, s.size() + 1) rep(j, i) {
    int x = c[i];
    x += 2019 - c[j] * modpow(10, i - j, 2019) % 2019;
    if (x % 2019 == 0)
      ans++;
  }
  cout << ans << endl;
}
Problem p02702 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

int main() {
  string s;
  cin >> s;
  int l = s.length();
  int t[l + 1];
  int count[2020] = {};
  t[l] = 0;
  count[t[l]]++;
  long long n = 1;
  for (int i = 1; i < l + 1; i++) {
    t[l - i] = (t[l - i + 1] + (s[l - i] - '0') * n) % 2019;
    count[t[l - i]]++;
    n = n * 10;
    n = n % 2019;
    // cout << t[l-i] << endl;
  }
  int sum = 0;
  for (int i = 0; i < 2020; i++) {
    sum += count[i] * (count[i] - 1) / 2;
  }
  // cout << 1.0 * clock() / CLOCKS_PER_SEC << endl;
  cout << sum << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  string s;
  cin >> s;
  int l = s.length();
  int t[l];
  int count[2020] = {};
  t[l] = 0;
  count[t[l]]++;
  for (int i = 1; i < l + 1; i++) {
    long long n = pow(10, i - 1);
    t[l - i] = (t[l - i + 1] + (s[l - i] - '0') * n) % 2019;
    count[t[l - i]]++;
    // cout << t[l-i] << endl;
  }
  int sum = 0;
  for (int i = 0; i < 2020; i++) {
    sum += count[i] * (count[i] - 1) / 2;
  }
  // cout << 1.0 * clock() / CLOCKS_PER_SEC << endl;
  cout << sum << endl;
  return 0;
}