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

#include <bits/stdc++.h>

using namespace std;

int main(void) {
  string S;
  cin >> S;
  long long bdp[2019];
  long long adp[2019];
  memset(bdp, 0, sizeof(bdp));
  memset(adp, 0, sizeof(adp));

  long long ans = 0;
  for (int i = 0; i < (int)S.size(); i++) {
    memcpy(bdp, adp, sizeof(adp));
    memset(adp, 0, sizeof(adp));
    ans += bdp[0];
    int d = S[i] - '0';
    adp[d]++;
    for (int j = 0; j < 2019; j++) {
      if (bdp[j]) {
        adp[(j * 10 + d) % 2019] += bdp[j];
      }
    }
  }
  ans += adp[0];

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

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main(void) {
  string S;
  cin >> S;
  long long dp[S.size() + 1][2019];
  memset(dp, 0, sizeof(dp));

  for (int i = 0; i < (int)S.size(); i++) {
    int d = S[i] - '0';
    dp[i + 1][d]++;
    for (int j = 0; j < 2019; j++) {
      if (dp[i][j]) {
        dp[i + 1][(j * 10 + d) % 2019] += dp[i][j];
      }
    }
  }

  long long ans = 0;
  for (int i = 0; i < (int)S.size() + 1; i++) {
    ans += dp[i][0];
  }

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

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

int main() {
  string s;
  cin >> s;
  int n = s.size();
  ll ans = 0;
  int m = 2019;
  reverse(s.begin(), s.end());
  vector<int> cnt(m);
  int x = 1, tot = 0;
  rep(i, n) {
    cnt[tot]++;
    tot += (s[i] - '0') * x;
    tot %= m;
    ans += cnt[tot];
    x = x * 10 % m;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

int ctoi(const char c) {
  if ('0' <= c && c <= '9')
    return (c - '0');
  return -1;
}
int main() {
  string s;
  cin >> s;
  int n = s.size();
  int ans = 0;
  int num = 0;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      for (int k = j - i; k >= 0; k--) {
        num += ctoi(s[j - k]) * pow(10, k);
        num = num % 2019;
      }
      if (num == 0) {
        ans++;
      }
      num = 0;
    }
  }
  cout << ans << endl;
}
Problem p02702 (C++) — buggy submission, verdict: Time Limit Exceeded

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

const int MOD = 2019;

int main() {
  string S;
  cin >> S;
  int N = S.size();
  reverse(begin(S), end(S));

  vector<int> v(2020, 0);
  int curr = 0;
  int p = 1;
  v[0]++;
  for (int i = 0; i < N; ++i) {
    curr = (curr + (S[i] - '0') * p) % MOD;
    p = p * 10 % MOD;
    v[curr]++;
  }

  long long ans = 0;
  for (const auto &x : v) {
    ans += x * (x - 1) / 2;
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

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

const int MOD = 2019;

int s_digit[200000];

int main() {
  string S;
  cin >> S;
  int N = S.size();

  for (int i = 0; i < N; ++i) {
    s_digit[i] = S[i] - '0';
  }

  long long ans = 0;
  for (int i = 0; i < N; ++i) {
    int tmp = 0;
    for (int j = i; j < N; ++j) {
      tmp = (tmp * 10 + s_digit[j]) % MOD;
      if (tmp == 0) {
        ans++;
      }
    }
  }

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

#include <iostream>
#include <map>
#include <vector>
using namespace std;

int m = 2019;

int powm(int x, int p) {
  if (p == 0)
    return 1;
  int tmp = x * x % m;
  if (p % 2 == 0) {
    return powm(tmp, p / 2);
  } else {
    return x * powm(tmp, (p - 1) / 2) % m;
  }
}

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

  vector<int> r(N);

  int res = 0;
  for (int i = 0; i < N; i++) {
    int ss = (int)s[N - 1 - i] - '0';
    if (i == 0) {
      r[0] = ss * powm(10, i) % m;
      continue;
    }
    r[i] = (r[i - 1] + ss * powm(10, i)) % m;
  }

  map<int, int> m;
  m[0] = 1;
  for (int i = 0; i < N; i++) {
    int k = r[i];
    if (m.count(k) == 0) {
      m[k] = 1;
    } else {
      m[k]++;
    }
  }

  long long result = 0;
  for (auto a = m.begin(); a != m.end(); a++) {
    int aa = a->second;
    result += aa * (aa - 1) / 2;
  }
  cout << result << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

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

  long long res = 0;
  long long sum = 0;
  for (int left = 0; left < n; left++) {
    int right = left;
    while (right < n) {
      sum += stoll(s.substr(right, 1));
      string sub = s.substr(left, right - left + 1);
      // cout << sub << ' ' << sum << endl;
      if (sum % 3 == 0 && stoll(sub) % 673 == 0) {
        res++;
        break;
      }
      right++;
    }
    sum = 0;
  }
  cout << res << endl;
  return 0;
}
Problem p02702 (C++) — buggy submission, verdict: Runtime Error

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

int cnt[2020];
int num[200001];

int main(void) {
  string s;
  cin >> s;
  int tmp = 0;
  int mul = 1;
  cnt[0]++;
  int size = s.size();
  for (int i = 0; i < size; i++) {
    tmp += (s[size - i - 1] - '0') * mul % 2019;
    tmp %= 2019;
    mul *= 10;
    mul %= 2019;
    cnt[tmp]++;
    num[size - i - 1] = tmp;
  }
  long long ans = 0;
  for (int i = 0; i < size; i++) {
    cnt[num[i]]--;
    ans += cnt[num[i]];
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

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

int cnt[2020];
int num[100001];

int main(void) {
  string s;
  cin >> s;
  int tmp = 0;
  int mul = 1;
  cnt[0]++;
  int size = s.size();
  for (int i = 0; i < size; i++) {
    tmp += (s[size - i - 1] - '0') * mul % 2019;
    tmp %= 2019;
    mul *= 10;
    mul %= 2019;
    cnt[tmp]++;
    num[size - i - 1] = tmp;
  }
  long long ans = 0;
  for (int i = 0; i < size; i++) {
    cnt[num[i]]--;
    ans += cnt[num[i]];
  }
  cout << ans << endl;
}
Problem p02702 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

int main(int argc, char const *argv[]) {
  string S;
  int mod = 0, cnt = 0, idx = 1;
  cin >> S;
  vector<int> mods(2019, 0);
  mods[0] = 1;
  for (int i = S.length() - 1; i >= 0; i--) {
    int a = S[i] - '0';
    mod = (idx * a + mod) % 2019;
    idx = idx * 10 % 2019;
    mods[mod]++;
  }
  for (int i = 0; i < mods.size(); i++) {
    cnt += mods[i] * (mods[i] - 1) / 2;
  }
  cout << cnt;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

int main(int argc, char const *argv[]) {
  string S;
  cin >> S;
  long long cnt = 0;
  string substr;
  long long num = 0;
  for (int i = 4; i < S.length(); i++) {
    for (int j = 0; j < S.length() - i + 1; j++) {
      substr = S.substr(j, i);
      num = atoi(substr.c_str());
      if (num % 2019 == 0) {
        cnt++;
      }
    }
  }
  cout << cnt;
  return 0;
}
Problem p02702 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long
using namespace std;
char s[200005];
int a[2020];
int main() {
  scanf("%s", &s);
  a[0] = 1;
  int l = strlen(s) - 1;
  int num = 0, mod = 2019;
  int ans = 0, p = 1;
  for (int i = l; i >= 0; --i) {
    ans = (ans + (s[i] - '0') * p) % mod;
    num += a[ans];
    a[ans]++;
    p = p * 10 % mod;
    //	printf("ans:%d a[ans]:%d\\n",ans,a[ans]);
  }
  printf("%d", num);
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
using namespace std;
char s[200005];
int main() {
  scanf("%s", &s);
  int l = strlen(s);
  int num = 0, mod = 2019;
  for (int i = 0; i < l - 3; ++i) {
    int ans = 0;
    ans = (ans * 10 + (s[i] - '0')) % mod;
    ans = (ans * 10 + (s[i + 1] - '0')) % mod;
    ans = (ans * 10 + (s[i + 2] - '0')) % mod;
    for (int j = i + 3; j < l; j++) {
      ans = (ans * 10 + (s[j] - '0')) % mod;
      if (ans == 0) {
        num++;
        //	printf("%d %d ",i,j);
      }
    }
  }
  printf("%d", num);
}
Problem p02702 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

const int mod = 2019;

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

  string s;
  cin >> s;
  int n = sz(s);
  reverse(s.begin(), s.end());
  vi modsum(n + 1);
  int now = 1;
  rep(i, n) {
    modsum[i + 1] = (modsum[i] + (s[i] - '0') * now) % mod;
    now = (now * 10) % mod;
  }
  map<int, int> mp;
  ll ans = 0;
  rep(i, n + 1) mp[modsum[i]]++;
  for (auto p : mp) {
    ans += (ll)p.se * (p.se - 1) / 2;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

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

  string s;
  cin >> s;
  int n = sz(s);
  // vi amari(n);
  // rep(i, n) {
  //     if (i == 0) {
  //         amari[i] = s[i] - '0';
  //     } else {
  //         amari[i] = (amari[i-1] * 10 + (s[i] - '0')) % 2019;
  //     }
  // }
  // rep(i, n) cout << amari[i] << endl;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int amari = 0;
    for (int j = i; j < n; ++j) {
      amari = (amari * 10 + (s[j] - '0')) % 2019;
      if (amari == 0)
        ans++;
    }
  }
  cout << ans << endl;
  // for (int i = 1; i < 1000; ++i) {
  //     cout << 2019 * i << endl;
  // }
}
Problem p02702 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  // sengen
  string s;
  // nyuryoku
  cin >> s;
  int n = s.size();
  int val[2019] = {};
  // keisan
  LL mul = 1;
  LL rem = 0;
  val[rem]++;
  LL ans = 0;
  for (int i = 0; i < n; i++) {
    LL add = s[n - 1 - i] - '0';
    rem = (rem + add * mul) % 2019;
    mul = (mul * 10) % 2019;
    val[rem]++;
  }
  for (int i = 0; i < 2019; i++) {
    ans += val[i] * (val[i] - 1) / 2;
  }
  // syutsuryoku
  cout << ans << endl;
}

Error: WA

Fixed submission:

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

int main() {
  // sengen
  string s;
  // nyuryoku
  cin >> s;
  // keisan
  long long sum = 0;
  int n = s.size();
  for (int i = 4; i <= n; i++) {
    for (int j = 0; j < n - i + 1; j++) {
      long long num = stoll(s.substr(j, i));
      if (num % 2019 == 0) {
        sum++;
      }
    }
  }
  cout << sum;
  // syutsuryoku
}
Problem p02702 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
#include <unordered_map>

using namespace std;
using ll = long long;
using ull = unsigned long long;

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

  auto const n = S.length();
  unordered_map<int, ull> U{{0, 1}}; // Tn を先に追加

  ll Tk = 0, d = 1;
  for (int k = n - 1; k >= 0; --k) {
    Tk = (Tk + d * (S[k] - '0')) % 2019;
    d = (10 * d) % 2019;
    ++U[Tk];
  }

  ll ans = 0;
  for (auto &p : U) {
    ans += p.second * (p.second - 1) / 2;
  }

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

Error: TLE

Fixed submission:

#include <iostream>
#include <string>

using namespace std;
using ll = long long;

int main() {
  auto const p = 2019;
  string S;
  cin >> S;
  auto const l = S.length();

  int r = 0;
  for (int i = 0; i <= l - 3; ++i) {
    for (int j = i + 4; j <= l; ++j) {
      auto const target = S.substr(i, j - i);

      constexpr auto step = 10;
      ll cache = 0;
      ll I = 0, J = target.length() % step;
      if (J == 0)
        J += step;
      for (; J <= target.length(); J += step, I = J - step) {
        auto const str =
            (cache != 0 ? to_string(cache) : ""s) + target.substr(I, J - I);
        cache = stoll(str) % p;
      }

      if (cache == 0)
        ++r;
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
#define rep(i, j, k) for (int i = (int)(j); i <= (int)(k); i++)
#define debug(x) cerr << #x << ":" << x << endl
const int maxn = (int)1e6 + 5;
int sum[maxn];
const int mod = 2019;
int cnt[3000];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  int len = s.length();
  len--;
  sum[len] = s[len] - '0';
  int bit = 1;
  for (int i = len; i >= 0; i--) {
    sum[i] = (s[i] - '0') * bit % mod;
    sum[i] += sum[i + 1];
    sum[i] %= mod;
    bit *= 10;
    bit %= mod;
  }
  cnt[0]++;
  int ans = 0;
  for (int i = len; i >= 0; i--) {
    // debug(i),debug(sum[i]);
    ans += cnt[sum[i]];
    cnt[sum[i]]++;
  }
  cout << ans << endl;
}
/*
3*673

%2019?
 */

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, j, k) for (int i = (int)(j); i <= (int)(k); i++)
#define debug(x) cerr << #x << ":" << x << endl
const int maxn = (int)1e6 + 5;
int sum[maxn];
const int mod = 2019;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  int len = s.length();
  len--;
  sum[len] = s[len] - '0';
  int bit = 1;
  for (int i = len; i >= 0; i--) {
    sum[i] = (s[i] - '0') * bit % mod;
    sum[i] += sum[i + 1];
    sum[i] %= mod;
    bit *= 10;
    bit %= mod;
  }
  multiset<int> st;
  st.insert(0);
  int ans = 0;
  for (int i = len; i >= 0; i--) {
    // debug(i),debug(sum[i]);
    ans += st.count(sum[i]);
    st.insert(sum[i]);
  }
  cout << ans << endl;
}
/*
3*673

%2019?
 */
Problem p02702 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
#define N 200010
using namespace std;
string s;
char buf[N];
ll ans = 0, book = 0, val[N], num[2020][225], vn[2020][225];
vector<ll> v;
int main() {
  ll i, j, x = 1;
  scanf("%s", &buf);
  s = buf;
  for (i = 0; i < 224; i++) {
    v.push_back(x);
    x = (x * 10) % 2019;
  }
  for (i = 0; i < 2019; i++) {
    for (j = 0; j < 224; j++) {
      vn[(i * v[j]) % 2019][j] = i;
    }
  }
  val[0] = 0;
  for (i = 0; i < s.size(); i++) {
    val[i + 1] = (val[i] * 10 + (s[i] - '0')) % 2019;
  }
  for (i = 0; i <= s.size(); i++) {
    for (j = 0; j < 224; j++) {
      ans += num[vn[val[i]][(i + 224 - j) % 224]][j];
    }
    num[val[i]][i % 224]++;
  }
  printf("%lld\\n", ans);
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
#define N 200010
using namespace std;
string s;
char buf[N];
ll ans = 0, book = 0;
int main() {
  // freopen("in.txt","r",stdin);
  ll i, j, x;
  scanf("%s", &buf);
  s = buf;
  queue<ll> q;
  set<ll> st;
  for (i = 0; i <= s.size(); i++) {
    if (book != 0) {
      if (book > 0) {
        ans++;
      }
      continue;
    }
    x = s[i] - '0';
    st.clear();
    while (!q.empty()) {
      if (q.front() == 0) {
        ans++;
      }
      st.insert(q.front());
      q.pop();
    }
    for (set<ll>::iterator it = st.begin(); it != st.end(); it++) {
      q.push(((*it) * 10 + x) % 2019);
    }
    st.insert(x);
    q.push(x);
    if (st.size() >= 2019) {
      book = 1;
    }
  }
  printf("%lld\\n", ans);
  return 0;
}
Problem p02702 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define int long long int
const int N = 2e5 + 5;
const int W = 2019;

signed main() {

  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  // cin>>t;
  while (t--) {

    string s;
    cin >> s;
    int ans = 0;
    int x = 0;
    unordered_map<int, int> m;

    int h[N] = {};
    h[0] = 1;
    int j = 10;
    for (int i = 1; i < N; i++) {
      h[i] = (j) % W;
      j = (j * 10) % W;
    }

    int rem = 0;
    m[0] = 1;
    for (int i = 0; i < s.size(); i++) {

      rem += ((h[s.size() - i - 1] * (s[i] - '0')));
      rem %= W;
      if (m.count(rem) > 0)
        ans += m[rem];

      m[rem]++;
    }
    cout << ans << endl;
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long int
const int N = 1e5 + 5;

signed main() {

  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  // cin>>t;
  while (t--) {

    string s;
    cin >> s;
    int ans = 0;
    int x = 0;
    unordered_map<int, int> m;

    int h[N] = {};
    h[0] = 1;
    int j = 10;
    for (int i = 1; i < N; i++) {
      h[i] = (j) % 2019;
      j *= 10;
    }

    int rem = 0;

    for (int i = 0; i < s.size(); i++) {

      rem += ((h[s.size() - i - 1] * (s[i] - '0'))) % 2019;
      rem %= 2019;
      // cout<<rem<<endl;

      ans += m[rem];
      if (rem == 0)
        ans++;
      m[rem]++;
    }
    cout << ans << endl;
  }
}
Problem p02702 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  string s;
  cin >> s;
  ll n = s.size();
  ll p[2019] = {};
  ll t = 0;
  ll d = 1;
  ll ans = 0;
  for (ll i = n - 1; i >= 0; i--) {
    p[t]++;
    t = ((s[i] - '0') * d + t) % 2019;
    d = (d * 10) % 2019;
    ans += p[t];
  }
  cout << ans << endl;
}

Error: -11

Fixed submission:

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

int main() {
  string s;
  cin >> s;
  ll n = s.size();
  ll p[2019] = {};
  ll t = 0;
  ll d = 1;
  ll ans = 0;
  for (ll i = n - 1; i >= 0; i--) {
    p[t]++;
    t += ((s[i] - '0') * d + t) % 2019;
    d = (d * 10) % 2019;
    ans += p[t];
  }
  cout << ans << endl;
}
Problem p02702 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define ALL(n) begin(n), end(n)
using namespace std;
using ll = long long;

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

int main() {
  ll MOD = 2019;
  string s;
  cin >> s;
  ll cnt = 0;
  reverse(ALL(s));

  vector<int> mod_list(MOD);
  vector<int> memo(s.size() + 2);
  memo[0] = 0;
  rep(i, s.size()) {
    ll mod_i = ((s[i] - '0') * modpow(10, i, MOD) + memo[i] + MOD) % MOD;
    mod_list[mod_i]++;
    memo[i + 1] = mod_i;
  }

  cnt += mod_list[0];
  rep(i, mod_list.size()) {
    if (mod_list[i] >= 2)
      cnt += (mod_list[i] * (mod_list[i] - 1)) / 2;
  }
  cout << cnt << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define ALL(n) begin(n), end(n)
using namespace std;
using ll = long long;

int main() {
  string s;
  cin >> s;
  ll cnt = 0;
  vector<ll> mod_list(s.length());
  for (int i = s.length() - 1; i >= 0; i--) {
    string tmp = s.substr(i, s.length() - i);
    ll num = stoll(tmp);
    mod_list[i] = (num + 2019) % 2019;
    if (mod_list[i] == 0)
      cnt++;
  }

  sort(ALL(mod_list));

  ll m = mod_list[s.length() - 1];
  for (int i = s.length() - 2; i >= 0; i--) {
    if (mod_list[i] == m)
      cnt++;
    else
      m = mod_list[i];
  }

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

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

int main() {
  string S;
  cin >> S;
  int size = S.size();
  int ans = 0;
  int tmp = 0;

  vector<int> list(2019); // 余りリスト
  vector<int> keta(size); // 各桁

  list[0] = 1;

  for (int i = 0; i < size; i++)
    keta[i] = S[i] - 48;

  reverse(keta.begin(), keta.end());

  int ten = 1;

  for (int i = 0; i < size; i++) {
    tmp = (keta[i] * ten + tmp) % 2019;
    ten *= 10;
    ten %= 2019;
    list[tmp]++;
  }

  for (int i = 0; i < 2019; i++) {
    ans += list[i] * (list[i] - 1) / 2;
  }

  cout << ans;
}

Error: TLE

Fixed submission:

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

int main() {
  string S;
  cin >> S;
  int size = S.size();
  int count = 0;
  int tmp = 0;

  vector<int> list(size);

  for (int i = 0; i < size; i++)
    list[i] = S[i] - 48;

  for (int i = 0; i < size; i++) {
    for (int j = i; j < size; j++) {
      tmp = (tmp * 10 + list[j]) % 2019;
      if (tmp % 2019 == 0)
        count++;
    }
    tmp = 0;
  }

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

#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i, n) for (long long i = 1; i <= (long long)(n); i++)
#define all(v) v.begin(), v.end()
#define Sort(v) sort(all(v))
#define Reverse(v) reverse(all(v))
#define Rsort(v) sort(all(v), greater)
#define pub(v) push_back(v)
#define pob(v) pop_back(v)
typedef long long ll;
typedef vector<ll> vel;
typedef vector<vector<ll>> vel2d;
typedef string str;
typedef pair<ll, ll> pal;
typedef vector<str> ves;

int main() {
  str S;
  cin >> S;
  ll n = S.size();
  reverse(all(S));
  vel data(2019);
  ll ans = 0, tot = 0, x = 1;
  rep0(i, n) {
    tot += (S[i] - '0') * x;
    tot %= 2019;
    if (data[tot] == 0 && tot == 0) {
      data[tot]++;
    }
    if ((S[i] - '0') != 0) {
      data[tot]++;
    }
    x *= 10;
    x %= 2019;
  }
  rep0(i, 2019) {
    ll q = data[i];
    // if(data[i]!=0){cout<<i<<" "<<data[i]<<endl;}
    ans += q * (q - 1) / 2;
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i, n) for (long long i = 1; i <= (long long)(n); i++)
#define all(v) v.begin(), v.end()
#define Sort(v) sort(all(v))
#define Reverse(v) reverse(all(v))
#define Rsort(v) sort(all(v), greater)
#define pub(v) push_back(v)
#define pob(v) pop_back(v)
typedef long long ll;
typedef vector<ll> vel;
typedef vector<vector<ll>> vel2d;
typedef string str;
typedef pair<ll, ll> pal;

int main() {
  // あまりの時は0のときに気を付ける
  str S, sum;
  ll cnt = 0;
  cin >> S;
  vector<char> data(S.size());
  rep0(i, S.size()) { data[i] = S[i]; }
  rep0(i, S.size() - 3) {
    for (ll j = i + 3; j <= S.size() - 1; j++) {
      for (ll s = i; s <= j; s++) {
        sum += data.at(s);
      }
      // cout<<sum<<endl;
      ll t = stoull(sum);
      if (t % 2019 == 0) {
        cnt++;
      }
      sum = "";
    }
  }
  cout << cnt << endl;
}