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

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

ll modpow(ll a, ll b, ll mod) {
  ll ans = 1 % mod;
  while (b) {
    if (b & 1)
      ans = (ans * a) % mod;
    a = (a * a) % mod;
    b = b >> 1;
  }
  return ans;
}

int main() {
  string S;
  cin >> S;
  ll tmp_mod[200010];
  tmp_mod[S.size()] = 0;
  ll dg = 0;
  for (ll i = S.size() - 1; i >= 0; --i) {
    ll num = S[i] - '0';
    tmp_mod[i] = (num * modpow(10, dg, 2019) + tmp_mod[i + 1]) % 2019;
    dg++;
  }
  map<ll, ll> m;
  for (ll i = S.size(); i >= 0; --i) {
    m[tmp_mod[i]]++;
  }
  ll ans = 0;
  for (auto &x : m) {
    ll cnt = ll(x.second);
    if (cnt <= 1)
      continue;
    else
      ans += (cnt - 1) * cnt / 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>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vll = vector<ll>;
#define all(v) v.begin(), v.end()

ll modpow(ll a, ll b, ll mod) {
  ll ans = 1 % mod;
  while (b) {
    if (b & 1)
      ans = (ans * a) % mod;
    a = (a * a) % mod;
    b = b >> 1;
  }
  return ans;
}

int main() {
  string S;
  cin >> S;
  vll tmp_mod(S.size(), 0);
  tmp_mod[S.size()] = 0;
  ll dg = 0;
  for (ll i = S.size() - 1; i >= 0; --i) {
    ll num = S[i] - '0';
    tmp_mod[i] = (num * modpow(10, dg, 2019) + tmp_mod[i + 1]) % 2019;
    dg++;
  }
  map<ll, ll> m;
  for (ll i = S.size(); i >= 0; --i) {
    m[tmp_mod[i]]++;
  }
  ll ans = 0;
  for (auto &x : m) {
    ll cnt = ll(x.second);
    if (x.second <= 1)
      continue;
    else
      ans += (cnt - 1) * cnt / 2;
  }
  cout << ans << endl;
}
Problem p02702 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  string S;
  cin >> S;
  int N = S.length();
  vector<int> a;
  int ten = 1;
  for (int i = 0; i < N; i++) {
    int c = S[N - i - 1] - '0';
    a.push_back(c * ten % 2019);
    ten = ten * 10 % 2019;
  }
  vector<int> s;
  int sum = 0;
  s.push_back(0);
  for (auto a_i : a) {
    sum = (sum + a_i) % 2019;
    s.push_back(sum);
  }
  vector<int> mods(2019, 0);
  for (int i = 0; i < N + 1; i++) {
    mods[s[i]]++;
  }
  // mods[i] = n の時 n_C_2 = n(n-1)/2
  int ans = 0;
  for (int i = 0; i < 2019; i++) {
    ans += mods[i] * (mods[i] - 1) / 2;
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

queue<int> pow10(int N) {
  queue<int> q;
  int m = 1;
  q.push(m);
  for (int i = 0; i < N; i++) {
    m *= 10;
    m %= 2019;
    q.push(m);
  }
  return q;
}

int calc(string s, int N) {
  int sum = 0;
  queue<int> q = pow10(N - 1);
  for (int i = 0; i < N; i++) {
    int m = (s[N - i - 1] - '0') * q.front() % 2019;
    // printf("%d %c %d\\n", i, s[N-i-1], m);
    q.pop();
    sum = (sum + m) % 2019;
  }
  if (sum == 0) {
    return 1;
  }
  return 0;
}

int main() {
  string S;
  cin >> S;
  int ans = 0;
  for (int i = 0; i < S.length(); i++) {
    for (int j = i + 5; j <= S.length(); j++) {
      string s = S.substr(i, j - i);
      ans += calc(s, j - i);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02702 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <limits>
#define ll long long
#define F first
#define S second
#define pb push_back
#define oo (1LL << 63 - 1)
#define endl '\\n'
#define si size()
#define all(v) v.begin(), v.end()
#define FASTIO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define Matrix vector<vector<long long>>

using namespace std;

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

const long double Pi = acos(-1), e = 2.718;
const int N = 2e5 + 10, mod = 1e9 + 7;
char s[N];
ll n, dp[2][2020], temp[2][2020];

int main() {
  scanf("%s", s);
  int n = 0;
  while (1) {
    if (s[n] == '\\0')
      break;
    n++;
  }
  for (int i = n - 1; i >= 0; i--) {
    for (int k = 2018; k >= 0; k--) {
      for (int j = 1; j >= 0; j--) {
        dp[j][k] = 0;
        if (j == 0) {
          dp[j][k] += temp[0][0];
          dp[j][k] += temp[1][(k * 10 + s[i] - '0') % 2019] +
                      ((k * 10 + s[i] - '0') % 2019 == 0);
        }
        if (j == 1) {
          dp[j][k] += temp[1][(k * 10 + s[i] - '0') % 2019] +
                      ((k * 10 + s[i] - '0') % 2019 == 0);
        }
      }
    }
    for (int k = 2018; k >= 0; k--) {
      for (int j = 1; j >= 0; j--) {
        temp[j][k] = dp[j][k];
      }
    }
  }
  printf("%lld", dp[0][0]);
  return 0;
}
/**

*/


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <limits>
#define ll long long
#define F first
#define S second
#define pb push_back
#define oo (1LL << 63 - 1)
#define endl '\\n'
#define si size()
#define all(v) v.begin(), v.end()
#define FASTIO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define Matrix vector<vector<long long>>

using namespace std;

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

const long double Pi = acos(-1), e = 2.718;
const int N = 2e5 + 10, mod = 1e9 + 7;
string s;
ll n, dp[2][2020], temp[2][2020];
// ll solve(int i,int j,int k){
//     if(i==n)return 0;
//     ll &ret = dp[i][j][k];
//     if(ret+1)return ret;
//     ret = 0 ;
//     if(j==0){
//         ret += solve(i+1,0,0);
//         ret += solve(i+1,1,(k*10+s[i]-'0'+2019)%2019) +
//         ((k*10+s[i]-'0'+2019)%2019==0);
//     }
//     if(j==1){
//         ret += solve(i+1,1,(k*10+s[i]-'0'+2019)%2019) +
//         ((k*10+s[i]-'0'+2019)%2019==0);
//     }
//     return ret;
// }
int main() {
  FASTIO
  cin >> s;
  n = s.si;
  //    memset(dp,-1,sizeof dp);
  //    cout << solve(0,0,0) << endl;
  bool st = 0;
  for (int i = n - 1; i >= 0; i--) {
    for (int k = 2018; k >= 0; k--) {
      for (int j = 1; j >= 0; j--) {
        dp[j][k] = 0;
        if (j == 0) {
          dp[j][k] += temp[0][0];
          dp[j][k] += temp[1][(k * 10 + s[i] - '0') % 2019] +
                      ((k * 10 + s[i] - '0') % 2019 == 0);
        }
        if (j == 1) {
          dp[j][k] += temp[1][(k * 10 + s[i] - '0') % 2019] +
                      ((k * 10 + s[i] - '0') % 2019 == 0);
        }
      }
    }
    for (int k = 2018; k >= 0; k--) {
      for (int j = 1; j >= 0; j--) {
        temp[j][k] = dp[j][k];
      }
    }
  }
  cout << dp[0][0] << endl;
  return 0;
}
/**

*/
Problem p02702 (C++) — buggy submission, verdict: Runtime Error

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

typedef long long i64;
typedef pair<int, int> ii;
typedef pair<i64, i64> ll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<vi> vvi;

#define fastIO() ios_base::sync_with_stdio(0), cin.tie(0)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ms(a, x) memset(a, x, sizeof(a))
#define len(x) (x).size()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

const double eps = 1e-9;
const double pi = acos(-1.0);
const int inf = 1e9;
const int maxn = 3e3 + 5;
const int mod = 2019;

string s;
int cur, ans, x, base, n;
int f[maxn], pot[200005];

int main() {
  fastIO();
  cin >> s;
  n = s.size();
  pot[n - 1] = 1;
  for (int i = n - 2; i >= 0; --i)
    pot[i] = (pot[i + 1] * 10) % mod;
  f[0] = 1;
  for (int i = 0; i < n; ++i) {
    cur = (cur + (pot[i] * (s[i] - '0')) % mod) % mod;
    ans += f[cur];
    ++f[cur];
  }
  cout << ans << '\\n';
  return 0;
}


Error: 0

Fixed submission:

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

typedef long long i64;
typedef pair<int, int> ii;
typedef pair<i64, i64> ll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<vi> vvi;

#define fastIO() ios_base::sync_with_stdio(0), cin.tie(0)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ms(a, x) memset(a, x, sizeof(a))
#define len(x) (x).size()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

const double eps = 1e-9;
const double pi = acos(-1.0);
const int inf = 1e9;
const int maxn = 2e3 + 5;
const int mod = 2019;

string s;
int cur, ans, x, base, n;
int f[maxn + 1], pot[200005];

int main() {
  fastIO();
  cin >> s;
  n = s.size();
  pot[n - 1] = 1;
  for (int i = n - 2; i >= 0; --i)
    pot[i] = (pot[i + 1] * 10) % mod;
  f[0] = 1;
  for (int i = 0; i < n; ++i) {
    cur = (cur + (pot[i] * (s[i] - '0')) % mod) % mod;
    ans += f[cur];
    ++f[cur];
  }
  cout << ans << '\\n';
  return 0;
}
Problem p02702 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define int long long
#define INT int
#define rep(i, n) for (int i = 0; i < (n); i++)

int t_index[200005];
string s;

int cToi(char x) { return x - '0'; }

signed main() {
  cin >> s;

  int len = s.size();
  if (len < 4) {
    cout << "0" << endl;
    return 0;
  }

  reverse(s.begin(), s.end());
  int x = 1, tot = 0;
  vector<int> cnt(2019);
  int ans = 0;
  rep(i, len) {
    cnt[tot]++;
    tot += (s[i] - '0') * x;
    tot %= 2019;
    ans += cnt[tot];
    x = x * 10 % 2019;
  }

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


Error: TLE

Fixed submission:

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

#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)

vector<vector<int>> t_index;
string s;
int ans = 0;

int cToi(char x) { return x - '0'; }

int fun(int a, int b) {

  if (a == b) {
    return cToi(s[a]);
  }
  if (t_index[a][b] != 0) {

    return t_index[a][b];
  } else {
    int temp = fun(a, b - 1) * 10 + cToi(s[b]);
    t_index[a][b] = temp;
    if (temp % 2019 == 0) {

      ans++;
    }
    return temp;
  }
}

signed main() {
  cin >> s;

  int len = s.size();

  t_index.resize(len);

  if (len < 4) {
    cout << "0" << endl;
    return 0;
  }

  for (int i = 0; i < len; i++) {
    t_index[i].resize(len);
    fun(i, len - 1);
  }

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

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

signed main(void) {
  string s;
  ll n, v, p, cnt;
  map<ll, ll> mp;

  cin >> s;
  n = s.size();
  reverse(s.begin(), s.end());
  mp[0]++;
  cnt = v = 0;
  p = 1;
  rep(i, n) {
    v += (s[i] - '0') * p;
    v %= 2019;
    p = (p * 10) % 2019;
    cnt += mp[v];
    mp[v]++;
  }
  cout << cnt << endl;
  return 0;
}


Error: 0

Fixed submission:

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

signed main(void) {
  string s;
  long long cnt;
  int len;
  cin >> s;
  cnt = 0;
  for (int j = 1; j <= 100; j++) {
    rep(i, s.size() - 4) {
      string t;
      if (j <= 4)
        t = s.substr(i, 4);
      else if (j < 50)
        t = s.substr(i, 5);
      else
        t = s.substr(i, 6);
      if (to_string(2019 * j) == t)
        cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}
Problem p02702 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9 + 7;

ll cnt[2050];
ll to[2050];
ll a[200050];
ll ans;

void shift() {
  ll cntt[2050] = {};
  for (int i = 0; i < 2019; i++) {
    cntt[to[i]] = cnt[i];
  }
  for (int i = 0; i < 2019; i++) {
    cnt[i] = cntt[i];
  }
}

int main() {
  string s;
  cin >> s;
  cnt[0] = 1;
  for (int i = 0; i < 2019; i++) {
    to[i] = i * 10 % 2019;
  }
  for (int i = 0; i < s.size(); i++) {
    ll num = s[i] - '0';
    if (i != 0) {
      a[i] = a[i - 1] * 10 + num;
      a[i] %= 2019;
    } else {
      a[i] = num;
    }
    shift();
    ans += cnt[a[i]];
    // if (cnt[a[i]] != 0) cout << i << endl;
    cnt[a[i]]++;
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9 + 7;

ll cnt[2050];
ll to[2050];
ll a[2050];
ll ans;

void shift() {
  ll cntt[2050] = {};
  for (int i = 0; i < 2019; i++) {
    cntt[to[i]] = cnt[i];
  }
  for (int i = 0; i < 2019; i++) {
    cnt[i] = cntt[i];
  }
}

int main() {
  string s;
  cin >> s;
  cnt[0] = 1;
  for (int i = 0; i < 2019; i++) {
    to[i] = i * 10 % 2019;
  }
  for (int i = 0; i < s.size(); i++) {
    ll num = s[i] - '0';
    if (i != 0) {
      a[i] = a[i - 1] * 10 + num;
      a[i] %= 2019;
    } else {
      a[i] = num;
    }
    shift();
    ans += cnt[a[i]];
    // if (cnt[a[i]] != 0) cout << i << endl;
    cnt[a[i]]++;
  }
  cout << ans << endl;
  return 0;
}
Problem p02702 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template <class t, class u> void chmax(t &a, u b) {
  if (a < b)
    a = b;
}
template <class t, class u> void chmin(t &a, u b) {
  if (b < a)
    a = b;
}
template <class t> using vc = vector<t>;
template <class t> using vvc = vc<vc<t>>;
using pi = pair<int, int>;
using vi = vc<int>;
void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }
int SIZE(string s) { return (int)s.size(); }
const long long INF = 1LL << 60;

int main() {
  cout << fixed << setprecision(20);
  string s;
  cin >> s;
  int si = SIZE(s);
  ll ans = 0;
  vc<ll> a(200010);
  a[0]++;
  ll next = 1, cur = 0;
  for (int i = si - 1; i >= 0; i--) {
    cur = (cur + (s[i] - '0') * next) % 2019;
    next = next * 10 % 2019;
    ans += a[cur];
    a[cur]++;
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template <class t, class u> void chmax(t &a, u b) {
  if (a < b)
    a = b;
}
template <class t, class u> void chmin(t &a, u b) {
  if (b < a)
    a = b;
}
template <class t> using vc = vector<t>;
template <class t> using vvc = vc<vc<t>>;
using pi = pair<int, int>;
using vi = vc<int>;
void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }
int SIZE(string s) { return (int)s.size(); }
const long long INF = 1LL << 60;

int main() {
  cout << fixed << setprecision(20);
  string s;
  cin >> s;
  int si = SIZE(s);
  ll ans = 0;
  for (int l = 0; l < si; l++) {
    ll cur = s[l] - '0';
    for (int r = l; r < si; r++) {
      if (cur == 0)
        ans++;
      cur = (cur * 10 + (s[r + 1] - '0')) % 2019;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02702 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, m, n) for (ll i = m; i < (ll)(n); i++)
#define rrep(i, n, m) for (ll i = n; i >= (ll)(m); i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
  string S;
  cin >> S;
  ll N = S.size();

  ll MOD = 2019;

  // (i, j)が条件を満たすのは a_{j} + 10 * a_{j-1} + .... + 10^{j-i}*a_{i}
  // が2019の倍数の時
  // 　左からk+1文字目以降の整数を値とみなしたときの数字をTkとすると，(i,
  // j)が条件を満たすのは 10^{n-j}(T_{i-1} - T_{j})が2019の倍数のとき
  // 10はmod2019で逆元が存在するので，T_{i-1} == T_{j} (mod2019)なら良い

  vector<vector<ll>> modind(MOD);
  modind.at(0).push_back(0);
  ll num = 0;

  vector<ll> x(N);
  x.at(0) = 1;
  rep(i, N - 1) { x.at(i + 1) = x.at(i) * 10 % MOD; }

  rep(i, N) {
    num += (S[N - 1 - i] - '0') * x.at(i) % MOD;
    modind.at(num % 2019).push_back(i + 1);
  }
  ll ans = 0;
  rep(i, MOD) {
    ll size = modind.at(i).size();
    if (size >= 2) {
      ans += size * (size - 1) / 2;
    }
  }
  cout << ans << endl;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, m, n) for (ll i = m; i < (ll)(n); i++)
#define rrep(i, n, m) for (ll i = n; i >= (ll)(m); i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
  string S;
  cin >> S;
  ll N = S.size();

  ll MOD = 2019;

  // (i, j)が条件を満たすのは a_{j} + 10 * a_{j-1} + .... + 10^{j-i}*a_{i}
  // が2019の倍数の時
  // 　左からk+1文字目以降の整数を値とみなしたときの数字をTkとすると，(i,
  // j)が条件を満たすのは 10^{n-j}(T_{i-1} - T_{j})が2019の倍数のとき
  // 10はmod2019で逆元が存在するので，T_{i-1} == T_{j} (mod2019)なら良い

  vector<vector<ll>> modind(MOD);
  modind.at(0).push_back(0);
  ll num = 0;
  rep(i, N) {
    num += (S[N - 1 - i] - '0') * ((ll)pow(10, i));
    modind.at(num % 2019).push_back(i + 1);
  }
  ll ans = 0;
  rep(i, MOD) {
    ll size = modind.at(i).size();
    if (size >= 2) {
      ans += size * (size - 1) / 2;
    }
  }
  cout << ans << endl;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
  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 < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll MOD = 1000000007;
int main() {
  string S;
  cin >> S;
  reverse(S.begin(), S.end());
  unordered_map<int, int> up;
  int num = 0;
  up[0]++;
  int x = 0, tot = 1;
  int mod = 2019;
  REP(i, S.size()) {
    x += (S[i] - '0') * tot;
    x %= mod;
    tot *= 10;
    tot %= mod;
    up[x]++;
  }
  int ans = 0;
  for (auto s : up) {
    ans += (s.second * (s.second - 1)) / 2;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
long returnspecidicdigit(long a, long b) {
  // aの右からb番目を返す
  long a_default = a, b_default = b;
  while (b > 0) {
    a /= 10;
    if (a < 0) {
      cout << "与えられた引数が不正です.a= " << a_default << " :b=" << b_default
           << endl;
      return 0;
    }
  }
  return a %= 10;
}

int main() {
  vector<int> S(0);
  string s;
  cin >> s;
  ll ans = 0;
  REP(i, s.size()) { S.push_back(s.at(s.size() - i - 1) - '0'); }
  ll keta = s.size();
  for (int i = 0; i < keta + 1 - 4; i++) {
    for (int j = i + 4; j < keta + 1 && j < i + 1000; j++) {
      ll num = 0;
      ll keta = 1;
      for (int k = i; k < j; k++) {
        num += S.at(k) * keta;
        num %= 2019;
        keta *= 10;
      }
      // cout << num << endl;
      if (num % 2019 == 0) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}
Problem p02702 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

int main() {
  using namespace std;
  string S;
  cin >> S;

  // cout << "\\n配列出力："<< endl;
  // for (int i=0;i<=int(S.size())-1;i++) cout << S[i] << endl;

  int keta = 1;
  int amari;
  int kokomade = 0;
  vector<int> amari_list(2019, 0);
  amari_list[0]++; // 0の分を可算しておく
  for (int i = S.size() - 1; i >= 0; i--) {
    int num = S[i] - '0';
    amari = (num * keta + kokomade) % 2019;

    keta *= 10;
    keta %= 2019;

    amari_list[amari]++;
    kokomade = amari;
  }

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

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>

int main() {
  using namespace std;

  string S;
  cin >> S;

  long long right = 0;
  long long count = 0;
  long long s_num = 0;
  long long n = (long long)S.length();
  for (long long left = 0; left <= n; left++) {

    right = left + 1;

    while (right <= n) {
      s_num = stoll(S.substr(left, right - left)); // string → lli変換

      if (s_num % 2019 == 0) {
        count++;
      }
      right++;
    }
  }

  std::cout << count << endl;

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll, lvector, greater<ll>>
#define P pair<ll, ll>
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) for (ll(i) = 0; (i) < (n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  ll n = s.length(), ans = 0, mod = 2019, digit = 1, val = 0;
  lvector mods(2019, 0);
  for (ll pos = n - 1; pos > -1; pos--) {
    val = (val + (s[pos] - '0') * digit) % mod;
    digit = (digit * 10) % mod;
    mods[val]++;
  }
  ans += mods[0];
  for (ll i : mods)
    ans += i * (i - 1) / 2;
  print(ans);
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll, lvector, greater<ll>>
#define P pair<ll, ll>
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) for (ll(i) = 0; (i) < (n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  ll n = s.length(), cnt = 0, ans = 0, num = 1;
  for (ll left = 0; left < n; ++left) {
    num = 1, cnt = 4;
    while (left + cnt <= n && num % 2019 != 0) {
      num = stoll(s.substr(left, cnt));
      cnt++;
    }
    if (num % 2019 != 0)
      continue;
    ans++;
    cnt += 4;
    while (left + cnt <= n) {
      num = stoll(s.substr(left, cnt));
      if (num % 2019 == 0) {
        ans++;
        cnt += 4;
      } else
        cnt++;
    }
  }
  print(ans);
  return 0;
}