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

#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG // GCC5.4.1で配列の範囲外アクセスをエラーにする

// cmdで g++ test.cpp とするとコンパイルできる
// 制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

#define ALL(x) x.begin(), x.end()
typedef long long ll;            // long long
typedef pair<int, int> pii;      // pair<int,int>
typedef vector<int> vi;          // vector<int>
typedef vector<vector<int>> vvi; // vector<vector<int>>
typedef vector<ll> vll;          // vector<long long>
typedef vector<vector<ll>> vvll; // vector<vector<long long>>
typedef priority_queue<int, vector<int>, greater<int>> gpq; // 逆順priority_queue
typedef priority_queue<int> pq;

// const int MOD=998244353;
const int MOD = 1000000007; // 10^9+7
const double PI = 3.1415926535;

int main() {
  string S;
  cin >> S;
  ll ans = 0;
  // reverse(ALL(S));
  int N = S.size();
  int cur_val;
  int mod2019_10 = 1;
  vll modcount(2019, 0);
  for (int i = N - 1; i >= 0; i--) {
    if (i == N - 1) {
      cur_val = S[N - 1] - '0';
    } else {
      cur_val = cur_val + (S[i] - '0') * mod2019_10;
    }
    mod2019_10 = (mod2019_10 * 10) % 2019;
    cur_val %= 2019;
    modcount[cur_val]++;
    // cout<<cur_val<<endl;
  }
  ans += (modcount[0] + 1) * modcount[0] / 2;
  for (int i = 1; i < 2019; i++) {
    if (modcount[i] >= 2) {
      ans += modcount[i] * (modcount[i] - 1) / 2;
    }
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG // GCC5.4.1で配列の範囲外アクセスをエラーにする

// cmdで g++ test.cpp とするとコンパイルできる
// 制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

#define ALL(x) x.begin(), x.end()
typedef long long ll;            // long long
typedef pair<int, int> pii;      // pair<int,int>
typedef vector<int> vi;          // vector<int>
typedef vector<vector<int>> vvi; // vector<vector<int>>
typedef vector<ll> vll;          // vector<long long>
typedef vector<vector<ll>> vvll; // vector<vector<long long>>
typedef priority_queue<int, vector<int>, greater<int>> gpq; // 逆順priority_queue
typedef priority_queue<int> pq;

// const int MOD=998244353;
const int MOD = 1000000007; // 10^9+7
const double PI = 3.1415926535;

int main() {
  string S;
  cin >> S;
  ll ans = 0;
  int N = S.size();
  if (N == 1) {
    cout << 0 << endl;
  } else {
    for (int i = 0; i < N; i++) {
      S[i] -= '0';
    }
    vi A(N);
    A[0] = S[0];
    for (int i = 1; i < N; i++) {
      for (int j = 0; j < i; j++) {
        A[j] = (A[j] * 10 + S[i]) % 2019;
        if (A[j] == 0) {
          ans++;
        }
      }
      A[i] = S[i];
    }
    cout << ans << endl;
  }
}
Problem p02702 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int tt = 1, rr = 0;
  int r[672];
  long long n, i, res = 0;
  long long t[2019];
  string s;
  cin >> s;
  n = s.size();
  fill(t, t + 2019, 0);
  for (i = 0; i < 672; i++) {
    r[i] = tt % 2019;
    tt = r[i] * 10;
  }
  for (i = 0; i < n; i++) {
    tt = stoi(s.substr(n - 1 - i, 1));
    rr += tt * r[i % 672];
    rr %= 2019;
    t[rr]++;
  }
  res = t[0] * (t[0] + 1) / 2;
  for (i = 1; i < 2019; i++)
    res += t[i] * (t[i] - 1) / 2;
  cout << res << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int N_MAX = 200000;
int main() {
  int tt, rr;
  long long n, i, j, t = 1, res = 0;
  int r[672];
  bool b[N_MAX];
  string s;
  cin >> s;
  n = s.size();
  fill(b, b + n, 0);
  for (i = 0; i < 672; i++) {
    r[i] = t % 2019;
    t = r[i] * 10;
  }
  for (j = n - 1; j >= 0; j--) {
    t = 0;
    rr = 0;
    if (b[j] == 1)
      continue;
    b[j] = 1;
    for (i = 0; j - i >= 0; i++) {
      tt = stoi(s.substr(j - i, 1));
      rr += tt * r[i % 672];
      rr %= 2019;
      if (rr == 0) {
        b[j - i - 1] = 1;
        t++;
      }
    }
    res += t * (t + 1) / 2;
  }
  cout << res << endl;
  return 0;
}
Problem p02702 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

using ll = long long;

ll pow(ll x, ll y) {
  if (y == 0LL)
    return 1LL;
  ll X = 1LL;
  for (ll i = 0LL; i < y; i++) {
    X *= x;
    X %= 2019;
  }
  return X;
}

ll dp[200100];
ll dpp[2100];

int main() {
  string S;
  cin >> S;
  ll l = S.size();
  ll f = S.at(0) - '0';
  dp[l + 1] = 0LL;
  dpp[0] = 1LL;
  ll s = 10LL;
  for (ll i = l; i >= 1; i--) {
    ll t = S.at(i - 1) - '0';
    dp[i] = (dp[i + 1] + t * s) % 2019LL;
    s *= 10LL;
    s %= 2019LL;
    dpp[dp[i]]++;
  }
  ll ans = 0LL;
  for (ll i = 0; i < 2100; i++) {
    ans += dpp[i] * (dpp[i] - 1) / 2;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

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

using ll = long long;

int main() {
  string S;
  cin >> S;
  int N = S.size();
  int cnt = 0;
  for (int j = 4; j < N; j++) {
    for (int i = 0; i <= j - 4; i++) {
      string t;
      for (int k = i; k <= j; k++) {
        t += S.at(k);
      }
      ll num = atoi(t.c_str());
      if (num % 2019LL == 0LL)
        cnt++;
    }
  }
  cout << cnt << endl;
}
Problem p02702 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  string str;
  cin >> str;
  int ans = 0;
  int n = str.size();
  int a[n + 5];
  int digit = 1;
  for (int i = n - 1; i >= 0; i--) {
    a[i] = digit % 2019;
    digit = (digit * 10) % 2019;
  }
  int mid = 0;
  map<int, int> mp;
  mp[mid]++;
  for (int i = n - 1; i >= 0; i--) {
    // cout<<a[i]<<" "<<mid<<'\\n';
    mid += a[i] * (str[i] - '0');
    mid %= 2019;
    mp[mid]++;
  }
  for (auto itr : mp)
    ans = ans + ((itr.second - 1) * (itr.second)) / 2;
  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  string str;
  cin >> str;
  int numMultiples = 0;
  set<int> a[str.size() + 5];
  int n = str.size();
  for (int i = 0; i < n; i++) {
    int remainder = 0;
    int prefixesFound = 0;
    for (int j = i; j < n; j++) {
      remainder = (10 * remainder + str[j] - '0') % 673;
      if (a[j].find(remainder) != a[j].end())
        break;
      a[j].insert(remainder);
      if (remainder == 0)
        prefixesFound++;
    }
    numMultiples += (prefixesFound * (prefixesFound + 1)) / 2;
  }
  cout << numMultiples;
  return 0;
}
Problem p02702 (C++) — buggy submission, verdict: Runtime Error

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

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

  map<unsigned long long, unsigned long long> mod;
  for (unsigned long long i = 0; i < 2019; i++) {
    mod[i] = 0;
  }

  unsigned long long cur = 0;
  unsigned long long tenFactor = 1;
  for (unsigned long long i = 0; i < s.size(); i++) {
    cur = (cur + (s[s.size() - i - 1] - '0') * tenFactor) % 2019;
    tenFactor = (tenFactor * 10) % 2019;
    mod[cur]++;
  }

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

  cout << count + mod[0];

  return 0;
}

Error: WA

Fixed submission:

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

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

  map<unsigned long long, unsigned long long> mod;
  for (unsigned long long i = 0; i < 2019; i++) {
    mod[i] = 0;
  }

  unsigned long long number = atoll(s.c_str());
  unsigned long long digit = 1;
  for (unsigned long long i = 0; i < s.size(); i++) {
    digit *= 10;
    unsigned long long sub = number % digit;
    unsigned long long m = sub % 2019;
    mod[m]++;
  }

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

  cout << count + mod[0];

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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <regex>
#include <string>
#include <vector>

using namespace std;
using ll = long long int;
const ll MOD = 1e9 + 7;

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

  vector<int> N(s.size(), 0);
  for (int i = 0; i < s.size(); i++) {
    N[i] = s[i] - '0';
  }

  vector<int> pre(2019, 0);
  vector<int> next(2019, 0);

  ll sum = 0;
  for (int i = 0; i < N.size(); i++) {
    for (int j = 0; j < 2019; j++) {
      next[(j * 10 + N[i]) % 2019] += pre[j];
    }
    next[N[i]] += 1;

    sum += next[0];
    swap(next, pre);
    for (int j = 0; j < 2019; j++) {
      next[j] = 0;
    }
  }
  cout << sum << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <regex>
#include <string>
#include <vector>

using namespace std;
using ll = long long int;
const ll MOD = 1e9 + 7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  vector<ll> N(s.size(), 0);

  for (ll i = 0; i < s.size(); i++) {
    N[i] = s[i] - '0';
  }

  vector<vector<ll>> DP(N.size() + 1, vector<ll>(2019, 0));
  for (ll i = 0; i < N.size(); i++) {
    DP[i][0] = 1;
  }
  for (ll i = 0; i < N.size(); i++) {
    ll sum = 0;
    for (ll l = 0; l < 2019; l++) {
      DP[i + 1][(l * 10 + N[i]) % 2019] += DP[i][l];
    }
  }
  ll ans = 0;
  for (ll i = 0; i <= N.size(); i++) {
    ans += DP[i][0];
  }

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORR(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOREACH(x, a) for (auto x : a)

/* exchange */
#define CHMIN(a, b) (a) = min((ll)(a), (ll)(b))
#define CHMAX(a, b) (a) = max((ll)(a), (ll)(b))

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int ARRAY = 100005;
const int INF = 1001001001;          // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N = 0;
ll ret = 0;
string s;

ll modPow(ll x, ll y) {
  if (y == 1)
    return x;
  else if (y == 0)
    return 1;
  else if (y % 2 == 0)
    return modPow((x * x) % 2019, y / 2);
  else
    return (modPow((x * x) % 2019, y / 2) * x) % 2019;
}

int main(void) {

  IN(s);
  N = s.length();

  vl r(2019, 0);

  ll n = 0;
  FOR(i, 0, N) {
    n += (s[N - 1 - i] - '0') * modPow(10, i);
    n %= 2019;
    r[n] += 1;
  }

  ret += r[0];
  FOR(i, 0, 2019) { ret += r[i] * (r[i] - 1) / 2; }

  PRINT(ret);
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORR(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOREACH(x, a) for (auto x : a)

/* exchange */
#define CHMIN(a, b) (a) = min((ll)(a), (ll)(b))
#define CHMAX(a, b) (a) = max((ll)(a), (ll)(b))

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int ARRAY = 100005;
const int INF = 1001001001;          // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N = 0;
ll ret = 0;
string s;

int main(void) {

  IN(s);
  N = s.length();

  vl r(2019, 0);

  REP(i, N) {
    ll n = s[i] - '0';
    FOR(j, i + 1, N) {
      n *= 10;
      n += s[j] - '0';
      n %= 2019;
    }
    r[n] += 1;
    // DEBUG(n);
  }

  ret += r[0];
  FOR(i, 0, 2019) { ret += r[i] * (r[i] - 1) / 2; }

  PRINT(ret);
}
Problem p02702 (C++) — buggy submission, verdict: Time Limit Exceeded


// D - Multiple of 2019

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

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

  unordered_map<int, ll> rem_cnt; // 余りをカウント

  int rem = 0; // 余りの初期値
  rem_cnt[0] = 1;
  int p = 1; // 右からi桁目に10^(i-1)を掛ける（ただしmod 2019）
  for (int i = 1; i <= n; i++) {
    int d = S[n - i] - '0';
    rem = (rem + (d * p)) % 2019;
    rem_cnt[rem]++;
    p = (p * 10) % 2019;
  }

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

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:


//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;

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

  int ans = 0;
  for (int i = 0; i < S.size() - 3; i++) {
    for (int j = i + 3; j < S.size(); j++) {
      string sub = S.substr(i, j - i + 1);
      Bint n(sub);
      // cout << n << endl;
      if (n % 2019 == 0) {
        ans++;
      }
    }
  }

  cout << ans << endl;

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

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

  int n;
  n = s.size();

  vector<int> cnt(2019, 0);

  int count = 0;
  int temp;
  int r = 0; //(i-1)桁目までの数 mod2019

  int r10 = 1; // 10^i mod2019

  // 配列を逆順に
  reverse(s.begin(), s.end());
  // 「0桁まで」の余りが0なので1にしておく
  cnt[0] = 1;

  rep(i, n) {
    temp = s[i] - '0';
    r = (r + (temp * r10)) % 2019; //((i-1)桁目までの数) + i桁目 * 10^i mod2019
    count += cnt[r]; // 同じ余りの桁の分だけ2019の倍数が取り出せる
    cnt[r]++;
    r10 = (r10 * 10) % 2019;

    // printf("%d桁目:%dまでの余り:%d, 同じ余りの桁:%d\\n", i, temp, r, cnt[r]);
  }

  cout << count;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

  int n;
  n = s.size();
  // cout << n << endl;
  string t;
  long long int m;
  int count = 0;
  string u;
  int n2;

  rep(i, n) {
    for (int j = i + 3; j < n; j++) {

      // 部分文字列の長さ
      n2 = j - i + 1;
      t = s.substr(i, n2);

      /*cout << i << " " << j << " ";
      cout << t << endl;*/

      m = 0;
      for (int k = n2 - 1; k >= 0; k -= 8) {
        if (k - 7 < 0) {
          u = t.substr(0, k + 1);
          m += ((stoi(u) % 2019) * ((int)pow(10.0, (double)n2 - 1 - k) % 2019));
        } else {
          u = t.substr(k - 7, 8);
          m += ((stoi(u) % 2019) * ((int)pow(10.0, (double)n2 - 1 - k) % 2019));
        }
        m = m % 2019;
      }

      if (m % 2019 == 0) {
        count++; /*cout << " OK" << endl;*/
      }
      // else{ cout << " NG" << endl;}
    }
  }
  cout << count << endl;
}
Problem p02702 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define Mod 1000000007
#define fastio                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);

int main() {
  fastio;
  string str;
  cin >> str;

  int n = str.size();

  int DP[2][2020];
  int rem[21000];
  ll ans = 0;

  for (int i = 0; i < 21000; i++)
    rem[i] = i % 2019;

  DP[0][str[0] - '0'] = 1;

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

    for (int j = 0; j < 2019; j++) {

      int index = rem[j * 10 + (str[i] - '0')];
      DP[i & 1][index] += DP[(i - 1) & 1][j];
    }

    ans += DP[i & 1][0];
    DP[i & 1][str[i] - '0']++;
    memset(DP[(i - 1) & 1], 0, sizeof DP[(i - 1) & 1]);
  }

  cout << ans << "\\n";
  // code
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define Mod 1000000007
#define fastio                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);

int main() {
  fastio;

  string str;
  cin >> str;
  int n = str.size();

  ll ans = 0;
  vector<set<int>> s(n);
  for (int i = 0; i < n; i++) {
    int rem = 0;
    ll prefix = 0;
    for (int j = i; j < n; j++) {
      rem = (rem * 10 + (str[j] - '0')) % 2019;

      if (s[j].find(rem) != s[j].end())
        break;
      s[j].insert(rem);
      if (rem == 0)
        prefix++;
    }

    ans += ((prefix * (prefix + 1)) / 2);
  }

  cout << ans << "\\n";
  // code
  return 0;
}
Problem p02702 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
#define REP(i, n) for (ll i = 0; i < (ll)n; ++i)
#define REPN(i, m, n) for (ll i = m; i < (ll)n; ++i)
#define INF (ll)2e9
#define MOD (1000 * 1000 * 1000 + 7)
#define Ceil(x, n) (((((x)) + ((n)-1)) / n))
#define CeilN(x, n) (((((x)) + ((n)-1)) / n) * n)
#define FloorN(x, n) ((x) - (x) % (n))
#define IsOdd(x) (((x)&0x01UL) == 0x01UL)
#define IsEven(x) (!IsOdd((x)))
#define M_PI 3.14159265358979323846
typedef pair<ll, ll> P;

/*-----------------------------------------------------------------------------
　処理
 -----------------------------------------------------------------------------*/
int main() {
  string S;
  cin >> S;
  reverse(ALL(S));

  ll keta = 1;
  ll amari = 0;
  map<ll, ll> mp;
  REP(i, S.size()) {
    amari = (amari + (S[i] - '0') * keta) % 2019;
    keta *= 10;
    keta %= 2019;
    mp[amari]++;
  }

  ll ans = mp[0];
  for (auto one : mp) {
    ans += one.second * (one.second - 1) / 2;
  }

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


Error: TLE

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
#define REP(i, n) for (ll i = 0; i < (ll)n; ++i)
#define REPN(i, m, n) for (ll i = m; i < (ll)n; ++i)
#define INF (ll)2e9
#define MOD (1000 * 1000 * 1000 + 7)
#define Ceil(x, n) (((((x)) + ((n)-1)) / n))
#define CeilN(x, n) (((((x)) + ((n)-1)) / n) * n)
#define FloorN(x, n) ((x) - (x) % (n))
#define IsOdd(x) (((x)&0x01UL) == 0x01UL)
#define IsEven(x) (!IsOdd((x)))
#define M_PI 3.14159265358979323846
typedef pair<ll, ll> P;

/*-----------------------------------------------------------------------------
　処理
 -----------------------------------------------------------------------------*/
int main() {
  string S;
  cin >> S;

  ll ans = 0;
  REP(stIdx, S.size()) {
    ll amari = 0;
    REPN(i, stIdx, S.size()) {
      amari *= 10;
      amari += S[i] - '0';
      amari %= 2019;
      if ((amari == 0) && (i != 0)) {
        ans++;
      }
    }
  }

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

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i <= (b); ++i)
#define per(i, a, b) for (int i = a; i >= (b); --i)
#define mem(a, x) memset(a, x, sizeof(a))
#define pb push_back
#define pi pair<int, int>
#define mk make_pair
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
const int N = 2e5 + 10, mod = 2019;
char s[N];
ll dp[2][2020], mp2[2020];
int n;
void solve() {
  cin >> s + 1;
  n = strlen(s + 1);
  ll ans = 0;
  int cur = 1;

  rep(i, 1, n) {
    memset(dp[cur], 0, sizeof(dp[cur]));
    dp[cur][s[i] - '0']++;
    for (int j = 0; j < 2019; ++j) {
      int v = (j * 10 + s[i] - '0') % mod;
      dp[cur][v] += dp[1 - cur][j];
    }
    ans += dp[cur][0];
    cur = 1 - cur;
  }
  cout << ans << endl;
}
int main() {
  // int _;cin>>_;while(_--)
  solve();
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i <= (b); ++i)
#define per(i, a, b) for (int i = a; i >= (b); --i)
#define mem(a, x) memset(a, x, sizeof(a))
#define pb push_back
#define pi pair<int, int>
#define mk make_pair
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
const int N = 2e5 + 10, mod = 2019;
char s[N];
map<int, int> mp1, mp2;
int n;
void solve() {
  cin >> s + 1;
  n = strlen(s + 1);
  ll ans = 0;
  rep(i, 1, n) {
    mp1 = mp2;
    mp2.clear();
    mp2[s[i] - '0']++;
    for (auto now : mp1) {
      int v = (now.first * 10 + s[i] - '0') % mod;
      mp2[v] += now.second;
      // printf("v:%d\\n",v);
    }

    ans += mp2[0];
  }
  cout << ans << endl;
}
int main() {
  // int _;cin>>_;while(_--)
  solve();
}
Problem p02702 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int n = s.size();
  vector<ll> a(n + 1);
  int tmp = 1;
  ll c[2019] = {1};
  for (int i = n - 1; 0 <= i; i--) {
    a[i] = a[i + 1];
    a[i] += (s[i] - '0') * tmp;
    a[i] %= 2019;
    tmp *= 10;
    tmp %= 2019;
    c[a[i]]++;
  }
  ll ans = 0;
  for (int i = 0; i < 2019; i++) {
    ans += c[i] * (c[i] - 1) / 2;
  }
  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  string s;
  cin >> s;
  ll sum = 0;
  ll size = s.size();
  ll i, j, k;
  for (i = 0; i + 4 <= size; i++) {
    for (j = 4; i + j <= size; j++) {
      string sd;
      sd = s.substr(i, j);
      ll num = atoll(sd.c_str());
      if (num % 2019 == 0) {
        sum++;
      }
    }
  }
  /**vector<ll> a;
  for(i=1;i*2019<=2e+5;i++){
      a.at(i-1)=i*2019;
  }**/

  cout << sum << endl;
  return 0;
}