alexjercan/bugnet huggingface dataset:
Problem p02702 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

template <typename A, typename B> string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string &s) { return '"' + s + '"'; }

string to_string(const char *s) { return to_string((string)s); }

string to_string(bool b) { return (b ? "true" : "false"); }

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N> string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A> string to_string(vector<A> v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) void(0)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int n = (int)s.size();
  vector<ll> cnt(2020);
  cnt[0] = 1;
  ll x = 0;
  ll ten = 1;
  for (int i = n - 1; ~i; i--) {
    x += (s[i] - '0') * ten % 2019;
    cnt[x % 2019]++;
    ten *= 10;
    ten %= 2019;
    debug(x);
  }
  ll ans = 0;
  for (const auto &c : cnt) {
    ans += c * (c - 1) / 2;
  }
  cout << ans << '\\n';
  return 0;
}

Error: TLE

Fixed submission:

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

int nagasa(string s) { return (int)(s.length()); }

int main() {
  string s;
  cin >> s;
  int ns = nagasa(s);
  int ans = 0;
  istringstream ss1;
  int p1;
  for (int i = 0; i < ns - 3; i++) {
    for (int j = i + 3; j < ns; j++) {
      ss1 = istringstream(s.substr(i, j - i + 1));
      ss1 >> p1;
      if (((p1) % 673 == 0) && ((p1) % 3 == 0))
        ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02702 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
long long n, len, dp[2][2020];
string s;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  // freopen("test.inp","r",stdin);
  // freopen("test.out","w",stdout);
  cin >> s;
  len = s.length();
  long long res = 0;
  dp[0][(s[0] - '0') % 2019] = 1;
  for (int i = 1; i < len; i++) {
    // cout<<dp[1][0]<<endl;
    for (int j = 0; j < 2019; j++) {
      dp[1][(j * 10 + (s[i] - '0')) % 2019] += dp[0][j];
      // if (( j*10 + (s[i]-'0') ) % 2019==0) cout<<i<<" "<<j<<"
      // "<<dp[0][403]<<endl;
    }
    res += dp[1][0];
    // cout<<res<<endl;
    memcpy(dp[0], dp[1], sizeof(dp[1]));
    dp[0][(s[i] - '0') % 2019]++;
    memset(dp[1], 0, sizeof(dp[1]));
  }
  cout << res;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long long n, len, dp[2][200002];
string s;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  // freopen("test.inp","r",stdin);
  // freopen("test.out","w",stdout);
  cin >> s;
  len = s.length();
  long long res = 0;
  dp[0][(s[0] - '0') % 2019] = 1;
  for (int i = 1; i < len; i++) {
    // cout<<dp[1][0]<<endl;
    for (int j = 0; j < 2019; j++) {
      dp[1][(j * 10 + (s[i] - '0')) % 2019] += dp[0][j];
      // if (( j*10 + (s[i]-'0') ) % 2019==0) cout<<i<<" "<<j<<"
      // "<<dp[0][403]<<endl;
    }
    res += dp[1][0];
    // cout<<res<<endl;
    memcpy(dp[0], dp[1], sizeof(dp[1]));
    dp[0][(s[i] - '0') % 2019]++;
    memset(dp[1], 0, sizeof(dp[1]));
  }
  cout << res;
}
Problem p02702 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
typedef long long ll;
/* clang-format off */
#define MOD 2019
#define INF 1000000000000000000ll
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
//#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
/* clang-format on */

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin >> s;
  ll n = s.size();
  vector<ll> t(n + 1), a(n);
  REP(i, n) a[i] = s[i] - '0';
  t[n] = 0;
  vector<ll> pow10_mod(n);
  pow10_mod[0] = 1;
  for (ll i = 1; i < n; i++)
    pow10_mod[i] = pow10_mod[i - 1] * 10 % MOD;

  for (ll i = n - 1; i >= 0; i--) {
    t[i] = (t[i + 1] + a[i] * pow10_mod[10, n - i - 1]) % MOD;
  }
  vector<ll> cnt(2019, 0);
  REP(i, n + 1) cnt[t[i]]++;
  ll ans = 0;
  REP(i, 2019) ans += cnt[i] * (cnt[i] - 1) / 2;
  DEBUGS(t);
  DEBUGS(a);
  cout << ans << "\\n";
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
typedef long long ll;
/* clang-format off */
#define MOD 2019
#define INF 1000000000000000000ll
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
//#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
/* clang-format on */

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin >> s;
  ll n = s.size();
  vector<ll> t(n + 1), a(n);
  REP(i, n) a[i] = s[i] - '0';
  t[n] = 0;
  vector<ll> pow10_mod(n);
  pow10_mod[0] = 1;
  for (ll i = 1; i < n; i++)
    pow10_mod[i] = pow10_mod[i - 1] * 10 % MOD;
  REP(i, n)
  for (ll i = n - 1; i >= 0; i--) {
    t[i] = (t[i + 1] + a[i] * pow10_mod[10, n - i - 1]) % MOD;
  }
  vector<ll> cnt(2019, 0);
  REP(i, n + 1) cnt[t[i]]++;
  ll ans = 0;
  REP(i, 2019) ans += cnt[i] * (cnt[i] - 1) / 2;
  DEBUGS(t);
  DEBUGS(a);
  cout << ans << "\\n";
  return 0;
}
Problem p02702 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(), x.end()

int const N = 200001;
int r[N], f[2020];

int main() {
  string s;
  cin >> s;
  reverse(all(s));
  ll n = s.size(), cur = 0, t = 1;
  for (int i = 0; i < n; ++i) {
    r[i] = (1ll * t * (s[i] - '0')) % 2019;
    r[i] %= 2019;
    t = (1ll * t * 10) % 2019;
  }
  ll an = 0;
  t = 0;
  for (int i = 0; i < n; ++i) {
    t = (t + r[i]) % 2019;
    ++f[t];
  }
  for (int i = 0; i < 2019; ++i) {
    an += (1ll * f[i] * (f[i] - 1)) / 2;
  }
  an += f[0];
  printf("%lld\\n", an);
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(), x.end()

int const N = 200001;
int r[2020], f[2020];

int main() {
  string s;
  cin >> s;
  reverse(all(s));
  ll n = s.size(), cur = 0, t = 1;
  for (int i = 0; i < n; ++i) {
    r[i] = (1ll * t * (s[i] - '0')) % 2019;
    r[i] %= 2019;
    t = (1ll * t * 10) % 2019;
  }
  ll an = 0;
  t = 0;
  for (int i = 0; i < n; ++i) {
    t = (t + r[i]) % 2019;
    ++f[t];
  }
  for (int i = 1; i < 2019; ++i) {
    an += (1ll * f[i] * (f[i] - 1)) / 2;
  }
  an += f[0];
  printf("%lld\\n", an);
}
Problem p02702 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  string s;
  cin >> s;
  vector<int> v(2019, 0);
  v[0] = 1;
  int n = s.size();
  int dp = 0;
  int p = 1;
  long long sum = 0;
  for (int i = 0; i < n; ++i) {
    dp = (dp + (s[n - i - 1] - '0') * p) % 2019;
    p = (p * 10) % 2019;
    sum += v[dp];
    v[dp]++;
  }

  /*
  long long sum = 0;
  for(int i = 0; i < 2019; ++i) {
      sum += (v[i]*v[i]-1)/2;
  }
  */
  cout << sum << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  string s;
  cin >> s;
  vector<int> v(2019, 0);
  v[0] = 1;
  int n = s.size();
  int dp = 0;
  for (int i = 0; i < n; ++i) {
    int tmp = s[n - i - 1] - '0';
    for (int j = 0; j < i; ++j) {
      tmp *= 10;
      tmp %= 2019;
    }
    tmp += dp;
    tmp %= 2019;
    v[tmp]++;
    dp = tmp;
  }

  /*
  for(int i = 0; i < 2019; ++i) {
      if(v[i] > 0) cout << "i:" << i << "v[i]:" << v[i] << endl;
  }
  */

  long long sum = 0;
  for (int i = 0; i < 2019; ++i) {
    sum += (v[i] * v[i] - 1) / 2;
  }
  cout << sum << endl;
  return 0;
}
Problem p02702 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;

  int n = s.length();
  vector<int> mae(2019);

  // for(int i=0;i<2019;i++)dp[0][i] = 0;
  long ans = 0;
  int a = (int)(s[0] - '0');
  mae[a] = 1;

  for (int i = 1; i < n; i++) {
    vector<int> ima(2019);

    int tmp = (int)(s[i] - '0');

    for (int j = 0; j < 2019; j++) {
      ima[(j * 10 + tmp) % 2019] = mae[j];
    }
    ima[tmp]++;
    ans += ima[0];
    mae = ima;
  }

  cout << ans << endl;
}


Error: MLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;

  int n = s.length();
  vector<vector<int>> dp(n, vector<int>(2019, 0));
  // for(int i=0;i<2019;i++)dp[0][i] = 0;
  long ans = 0;
  int a = (int)(s[0] - '0');
  dp[0][a] = 1;

  for (int i = 1; i < n; i++) {

    int tmp = (int)(s[i] - '0');

    for (int j = 0; j < 2019; j++) {
      dp[i][(10 * j + tmp) % 2019] = dp[i - 1][j];
    }
    dp[i][tmp] += 1;
    ans += dp[i][0];
  }

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

#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  string s;
  cin >> s;
  int sl = (int)s.length();
  long c[2019];
  long cb[2019];
  long cnl[2019];
  for (int i = 0; i < 2019; ++i) {
    c[i] = 0;
    cb[i] = 0;
    cnl[i] = 0;
  }
  int l;
  for (int i = 0; i < sl; ++i) {
    l = s[i] - '0';
    c[l] = cb[0] + 1;
    for (int j = 1; j < 2019; ++j) {
      c[(j * 10 + l) % 2019] = cb[j];
    }
    for (int j = 0; j < 2019; ++j) {
      cnl[j] += c[j];
      cb[j] = c[j];
      c[j] = 0;
    }
  }
  cout << cnl[0] << endl;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  string s;
  cin >> s;
  int sl = (int)s.length();
  int r[sl];
  int l;
  long c = 0;
  for (int i = 0; i < sl; ++i) {
    l = s[i] - '0';
    r[i] = 0;
    for (int j = 0; j <= i; ++j) {
      r[j] = (r[j] * 10 + l) % 2019;
      if (r[j] == 0)
        c++;
    }
  }
  cout << c << endl;
}
Problem p02702 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using ll = long long;

int nums(char s) { return s - '0'; }

int main() {
  string s;
  cin >> s;
  int leng = s.length();
  ll sn = 0;
  vector<int> v(2019, 0);

  v.at(0) = 1;
  int amari = 0;
  int ten = 1;
  for (int i = leng - 1; i >= 0; i--) {
    amari = amari + nums(s[i]) * ten;
    ten *= 10;
    ten %= 2019;
    amari %= 2019;
    // cout << amari << endl;
    v.at(amari) += 1;
  }

  int ans = 0;
  for (int i = 0; i < 2019; i++) {
    ans += v.at(i) * (v.at(i) - 1) / 2;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

using ll = long long;

int nums(char s) { return s - '0'; }

int main() {
  string s;
  cin >> s;
  int leng = s.length();
  int count = 0;

  for (int i = 0; i < leng - 3; i++) {
    int amari = nums(s[i]) * 100 + nums(s[i + 1]) * 10 + nums(s[i + 2]);
    for (int j = i + 3; j < leng; j++) {
      int waru = amari * 10 + nums(s[j]);
      amari = waru % 2019;
      // cout << amari << endl;
      if (amari == 0) {
        count += 1;
      }
    }
  }

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

/*
 * written by Yaqi Zhang
 * University of Wisconsin-Madison
 * 2020
 */

#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <vector>

#define INF 0x3f3f3f3f

using namespace std;

const int MAXN = 200005;
const int MOD = 2019;
int dp[2][2019];

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string S;
  cin >> S;
  memset(dp, 0, sizeof dp);
  long long ans = 0LL;
  int n = S.length();
  for (int i = 0; i < n; ++i) {
    int cur = i & 1;
    int pre = 1 - cur;
    int d = S[i] - '0';
    for (int j = 0; j < MOD; ++j)
      dp[cur][j] = 0;
    dp[cur][d % MOD] += 1;
    for (int j = 0; j < MOD; ++j) {
      int k = (j * 10 + d) % MOD;
      dp[cur][k] += dp[pre][j];
    }
    ans += dp[cur][0];
  }
  // for(int i = 1; i <= n; ++i) ans += dp[i][0];
  cout << ans << endl;
  return 0;
}


Error: MLE

Fixed submission:

/*
 * written by Yaqi Zhang
 * University of Wisconsin-Madison
 * 2020
 */

#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <vector>

#define INF 0x3f3f3f3f

using namespace std;

const int MAXN = 200005;
const int MOD = 2019;
int dp[MAXN][2019];

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string S;
  cin >> S;
  memset(dp, 0, sizeof dp);
  long long ans = 0LL;
  int n = S.length();
  for (int i = 0; i < n; ++i) {
    int d = S[i] - '0';
    dp[i + 1][d % MOD] += 1;
    for (int j = 0; j < MOD; ++j) {
      int k = (j * 10 + d) % MOD;
      dp[i + 1][k] += dp[i][j];
    }
  }
  for (int i = 1; i <= n; ++i)
    ans += dp[i][0];
  cout << ans << endl;
  return 0;
}
Problem p02702 (C++) — buggy submission, verdict: Runtime Error

#define _USE_MATH_DEFINES
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define MOD int(1e9 + 7)
#define INF (long long)(1e18)

int main() {
  string S;
  cin >> S;

  vector<vector<long long>> dp(2, vector<long long>(2020, 0));

  long long cv = stoi(S.substr(0, 4));
  dp[1][cv % 2019]++;
  long long count = dp[1][0];
  for (long long i = 4; i < S.size(); i++) {
    for (long long j = 0; j < 2019; j++) {
      dp[i % 2][((j * 10) + (S[i] - '0')) % 2019] = dp[(i - 1) % 2][j];
    }
    cv = (cv * 10) % 10000;
    cv += S[i] - '0';
    dp[i % 2][cv % 2019]++;
    count += dp[i % 2][0];
  }

  cout << count << endl;
}

Error: 0

Fixed submission:

#define _USE_MATH_DEFINES
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define MOD int(1e9 + 7)
#define INF (long long)(1e18)

int main() {
  string S;
  cin >> S;

  vector<vector<long long>> dp(S.size(), vector<long long>(2020, 0));

  dp[3][stoi(S.substr(0, 4)) % 2019]++;
  for (long long i = 4; i < S.size(); i++) {
    for (long long j = 0; j < 2019; j++) {
      dp[i][((j * 10) + (S[i] - '0')) % 2019] = dp[i - 1][j];
    }
    dp[i][stoi(S.substr(i - 3, 4)) % 2019]++;
  }

  long long count = 0;
  for (long long i = 0; i < S.size(); i++)
    count += dp[i][0];

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

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
// #define int ll
#define pb push_back
const int INF = 1e9;

signed main() {

  ios_base::sync_with_stdio(false);
  cin.tie(0);

  string s;
  cin >> s;

  int n = s.size();

  vector<int> dp(2019, 0), next(2019, 0);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int cur = s[i] - '0';
    next[cur] = 1;
    for (int j = 0; j < 2019; j++) {
      next[(10 * j + cur) % 2019] += dp[j];
    }

    for (int j = 0; j < 2019; j++) {
      dp[j] = next[j];
      next[j] = 0;
    }

    ans += dp[0];
  }
  cout << ans;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
// #define int ll
#define pb push_back
const int INF = 1e9;

signed main() {

  ios_base::sync_with_stdio(false);
  cin.tie(0);

  string s;
  cin >> s;

  int n = s.size();
  if (n == 200000)
    assert(false);
  vector<int> dp(2019, 0), next(2019, 0);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    next.assign(2019, 0);
    int cur = s[i] - '0';
    next[cur] = 1;
    for (int j = 0; j < 2019; j++) {
      next[(10 * j + cur) % 2019] += dp[j];
    }

    for (int j = 0; j < 2019; j++)
      dp[j] = next[j];

    ans += dp[0];
  }
  cout << ans;
  return 0;
}
Problem p02702 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
char s[200010];
int c[2020], inv = 202;
int main() {
  int ans = 0, tt = 1, cur = 0;
  scanf("%s", s);
  c[0] = 1;
  for (int i = 0; s[i]; i++) {
    int x = s[i] - '0';
    cur = (cur * 10 + x) % 2019;
    tt = (tt * inv) % 2019;
    ans += c[(cur * tt) % 2019];
    c[(cur * tt) % 2019]++;
  }
  printf("%d\\n", ans);
  return 0;
}


Error: 0

Fixed submission:

#include <stdio.h>
char s[20010];
int c[2020], inv = 202;
int main() {
  int ans = 0, tt = 1, cur = 0;
  scanf("%s", s);
  c[0] = 1;
  for (int i = 0; s[i]; i++) {
    int x = s[i] - '0';
    cur = (cur * 10 + x) % 2019;
    tt = (tt * inv) % 2019;
    ans += c[(cur * tt) % 2019];
    c[(cur * tt) % 2019]++;
  }
  printf("%d\\n", ans);
  return 0;
}
Problem p02702 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define per(i, n) for (ll i = n - 1; i >= 0; i--)
#define perl(i, r, l) for (ll i = r - 1; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(), (x).end()
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
const ll MOD = 1000000007;
const ll MOD9 = 998244353;
const int inf = 1e9 + 10;
const ll INF = 4e18;
const ll dy[8] = {1, 0, -1, 0, 1, 1, -1, -1};
const ll dx[8] = {0, -1, 0, 1, 1, -1, 1, -1};
using Graph = vector<vector<int>>;
const double pi = acos(-1);
double nCk(int n, int k) {
  double res = 1.0;
  for (int i = 0; i < n; i++) {
    res *= 0.5;
  }
  for (int i = 0; i < k; i++) {
    res *= (double)(n - i);
    res /= (double)(k - i);
  }
  return res;
}

int main() {
  // cout << fixed << setprecision(12);
  string s;
  cin >> s;
  reverse(all(s));
  ll ca = 0;
  ll a[2030] = {};
  ll n = s.size();
  ll ten = 1;
  rep(i, n) {
    ca += ((s.at(i) - '0') * ten);
    ca %= 2019;
    // cout << ca << endl;
    a[ca]++;
    ten *= 10;
    ten %= 2019;
  }
  ca = 0;
  ten = 1;
  a[0]++;
  repl(i, 0, 2019) { ca += a[i] * (a[i] - 1) / 2; }
  cout << ca << endl;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define per(i, n) for (ll i = n - 1; i >= 0; i--)
#define perl(i, r, l) for (ll i = r - 1; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(), (x).end()
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
const ll MOD = 1000000007;
const ll MOD9 = 998244353;
const int inf = 1e9 + 10;
const ll INF = 4e18;
const ll dy[8] = {1, 0, -1, 0, 1, 1, -1, -1};
const ll dx[8] = {0, -1, 0, 1, 1, -1, 1, -1};
using Graph = vector<vector<int>>;
const double pi = acos(-1);
double nCk(int n, int k) {
  double res = 1.0;
  for (int i = 0; i < n; i++) {
    res *= 0.5;
  }
  for (int i = 0; i < k; i++) {
    res *= (double)(n - i);
    res /= (double)(k - i);
  }
  return res;
}

int main() {
  // cout << fixed << setprecision(12);
  string s;
  cin >> s;
  reverse(all(s));
  ll ca = 1;
  ll a[2020] = {};
  ll n = s.size();
  ll ten = 1;
  rep(i, n) {
    ca *= (s.at(i) - '0') * ten;
    a[ca]++;
    ten *= 10;
    ten %= 2019;
  }
  ca = 0;
  ten = 1;
  while (a[0]) {
    ten *= a[0];
    a[0]--;
    if (a[0] == 1)
      break;
  }
  ca += ten;
  ten = 1;
  repl(i, 1, 2019) { ca += a[i] * (a[i] - 1) / 2; }
  cout << ca << endl;
}
Problem p02702 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>

#define ll long long
#define ld long double

using namespace std;
const long long LINF = LLONG_MAX;
const int INF = INT_MAX;
const int MOD = 1000000007;

const int N = 2e5 + 111;

int dp[2][2019];

int main() {
  ios::sync_with_stdio(false);
  string s;
  vector<string> a;
  cin >> s;
  int n = s.size();
  ll ans = 0;
  dp[0][s[0] - '0']++;
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < 2019; j++) {
      int nxt = (10 * j + (s[i] - '0')) % 2019;
      dp[1][(10 * j + (s[i] - '0')) % 2019] = dp[0][j];
    }
    dp[1][(s[i] - '0') % 2019]++;
    ans += dp[1][0];
    swap(dp[0], dp[1]);
  }
  cout << ans;
}


Error: MLE

Fixed submission:

#include <bits/stdc++.h>

#define ll long long
#define ld long double

using namespace std;
const long long LINF = LLONG_MAX;
const int INF = INT_MAX;
const int MOD = 1000000007;

const int N = 2e5 + 111;

int dp[N][2019];

int main() {
  ios::sync_with_stdio(false);
  string s;
  vector<string> a;
  cin >> s;
  int n = s.size();
  dp[0][s[0] - '0']++;
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < 2019; j++) {
      int nxt = (10 * j + (s[i] - '0')) % 2019;
      dp[i][(10 * j + (s[i] - '0')) % 2019] = dp[i - 1][j];
    }
    dp[i][(s[i] - '0') % 2019]++;
  }
  ll ans = 0;
  for (int i = 0; i < n; i++)
    ans += dp[i][0];
  cout << ans;
}
Problem p02702 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  string S;
  cin >> S;
  long long int N;
  N = S.length();
  vector<int> U(N, 0);

  for (int i = 0; i < N; i++) {
    int j = N - i - 1;
    char c;
    c = S.at(j);
    int u;
    u = c - '0';
    U.at(i) = u;
  }

  vector<int> DP(N + 1, 0);
  DP.at(0) = 0;
  long long int now;
  now = 0;
  long long pnow = 1;
  for (int i = 0; i < N; i++) {
    int u;
    u = U.at(i);
    pnow *= 10;
    pnow %= 2019;
    now += u * pnow;
    now %= 2019;
    DP.at(i + 1) = now;
  }

  vector<int> tyo(2019, 0);
  for (int dp : DP) {
    tyo.at(dp)++;
  }

  int ans = 0;
  for (int t : tyo) {
    ans += (t * (t - 1)) / 2;
  }

  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  string S;
  cin >> S;
  int N;
  N = S.length();
  vector<int> U(N, 0);

  for (int i = 0; i < N; i++) {
    int j = N - i - 1;
    char c;
    c = S.at(j);
    int u;
    u = c - '0';
    U.at(i) = u;
  }

  vector<int> DP(N + 1, 0);
  DP.at(0) = 0;
  long long int now;
  now = 0;
  for (int i = 0; i < N; i++) {
    int u;
    u = U.at(i);
    now += u * pow(10, i);
    now %= 2019;
    DP.at(i + 1) = now;
  }

  vector<int> tyo(2019, 0);
  for (int dp : DP) {
    tyo.at(dp)++;
  }

  int ans = 0;
  for (int t : tyo) {
    ans += (t * (t - 1)) / 2;
  }

  cout << ans << endl;
  return 0;
}