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

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

int main() {

  int N;
  cin >> N;

  set<string> S;

  for (int i = 0; i < N; i++) {
    string keihin;
    cin >> keihin;
    S.insert(keihin);
  }

  cout << S.size() << endl;
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 0) >= this->size() (which is 0)


Fixed submission:

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

int main() {

  int N;
  vector<string> S;

  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> S.at(i);
  }

  int kaburi = 0;

  for (int i = 0; i < N; i++) {
    for (int j = 1; j < N; j++) {

      if (i < j) {
        if (S.at(i) == S.at(j)) {
          kaburi++;
          break;
        }
      }
    }
  }

  cout << N - kaburi << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

int n, res;

string s;

vector<string> str[26][27];

bool flag;

int main() {

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> s;

    flag = false;

    if (s.size() > 1) {
      for (auto &&x : str[s[0] - 'a'][s[1] - 'a']) {
        if (x == s) {
          flag = true;
          break;
        }
      }
      if (flag == false)
        str[s[0] - 'a'][s[1] - 'a'].push_back(s);
    }

    else {
      for (auto &&x : str[s[0] - 'a'][26]) {
        if (x == s) {
          flag = true;
          break;
        }
      }
      if (flag == false)
        str[s[0] - 'a'][26].push_back(s);
    }
  }

  for (int i = 0; i < 26; i++) {
    for (int j = 0; j < 27; j++) {
      res += str[i][j].size();
    }
  }

  cout << res << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

int n, res;

string s;

vector<string> str[26];

bool flag;

int main() {

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> s;

    flag = false;

    for (auto &&x : str[s[0] - 'a']) {
      if (x == s) {
        flag = true;
        break;
      }
    }
    if (flag == false)
      str[s[0] - 'a'].push_back(s);
  }

  for (int i = 0; i < 26; i++) {
    res += str[i].size();
  }

  cout << res << endl;

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

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

int main() {
  int n;
  cin >> n;
  set<string> ans;
  string s;
  while (n--) {
    cin >> s;
    ans.insert(s);
  }
  cout << ans.size();
  return 0;
}


Error: TLE

Fixed submission:

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

int check(string s, vector<string> ans) {
  for (int i = 0; i < ans.size(); i++) {
    if (s == ans[i])
      return 0;
  }
  return 1;
}

int main() {
  int n;
  cin >> n;
  string s;
  vector<string> ans;
  while (n--) {
    cin >> s;
    if (check(s, ans))
      ans.push_back(s);
  }
  cout << ans.size();
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main(void) {
  int N;
  cin >> N;

  vector<string> a(N);

  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }

  int ans = N;

  sort(a.begin(), a.end());

  for (int i = 0; i < N - 1; i++) {
    if (a[i] == a[i + 1]) {
      ans--;
    }
  }

  cout << ans;

  return 0;
}

Error: TLE

Fixed submission:

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

int main(void) {
  int N;
  cin >> N;

  vector<string> a(N + 5);

  for (int i = 0; i < N; i++) {
    cin >> a[i];
    for (int j = 0; j < i; j++) {
      if (a[i] == a[j]) {
        a[j] = "1";
      }
    }
  }

  int co = 0;

  for (int i = 0; i < N; i++) {
    if (a[i] != "1") {
      co++;
    }
  }

  cout << co;

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

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  set<string> items;
  int n;
  cin >> n;
  string item;
  for (int i = 0; i < n; i++) {
    cin >> item;
    items.insert(item);
  }
  cout << items.size();
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n, counter = 0;
  cin >> n;
  string item, items[n];
  for (int i = 0; i < n; i++) {
    cin >> item;
    int tmp = 1;
    for (int j = 0; j < n; j++) {
      if (items[j] == item) {
        tmp = 0;
        continue;
      }
    }
    if (tmp) {
      counter++;
    }
    items[i] = item;
  }
  cout << counter << "\\n";
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

int main() {
  int n;
  cin >> n;
  set<string> S;
  string s;

  for (int i = 1; i <= n; i++) {
    cin >> s;
    S.insert(s);
  }

  cout << S.size() << endl;
  // for(auto i : S) { cout << i << endl; }

  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

int main() {
  int n;
  cin >> n;
  list<string> S;
  string s;

  for (int i = 1; i <= n; i++) {
    cin >> s;
    S.push_back(s);
    S.sort();
    S.unique();
  }

  cout << S.size() << endl;
  // for(auto i : S) { cout << i << endl; }

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

// codeforces
//
#include "bits/stdc++.h"
using namespace std;

int main() {
  int n;
  cin >> n;
  set<string> d;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    d.insert(s);
  }
  cout << d.size();
  return 0;
}


Error: TLE

Fixed submission:

// codeforces
//
#include "bits/stdc++.h"
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<string> d;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    bool f = 0;
    int k = d.size();
    for (int j = 0; j < k; j++) {
      if (s == d[j]) {
        f = 1;
        break;
      }
    }
    if (!f)
      d.push_back(s);
  }
  cout << d.size();
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i <= n; i++)
// ----GCC ONLY---- //
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// ----        ---- //
#define ll long long
#define PB push_back
#define MOD 10000007
#define PI 3.14159265359

using namespace std;

int main() {

  int n;
  vector<string> s{20000000};
  cin >> n;
  rep(i, n) cin >> s[i];

  int count = 0;

  sort(s.begin(), s.begin() + n);

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

    if (s.at(i) == s.at(i + 1)) {
      count += 0;
    } else {
      count++;
    }
  }
  cout << count << "\\n";
}


Error: 0

Fixed submission:

#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i <= n; i++)
// ----GCC ONLY---- //
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// ----        ---- //
#define ll long long
#define PB push_back
#define MOD 10000007
#define PI 3.14159265359

using namespace std;

int main() {

  int n;
  vector<string> s{100010};
  cin >> n;
  rep(i, n) cin >> s[i];

  int count = 0;

  sort(s.begin(), s.begin() + n);

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

    if (s.at(i) == s.at(i + 1)) {
      count += 0;
    } else {
      count++;
    }
  }
  cout << count << "\\n";
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  cin >> n;
  vector<string> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  set<string> s;
  for (int i = 0; i < n; i++) {
    s.insert(a[i]);
  }
  cout << s.size() << endl;
}


Error: TLE

Fixed submission:

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

int check(int n, vector<string> s) {
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (s[i] == s[j]) {
        n -= 1;
        s.erase(s.begin() + j);
        j--;
      }
    }
  }
  return n;
}

int main() {
  int long long n;
  cin >> n;
  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  int long long answer = check(n, s);
  cout << answer << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  cin >> n;
  string a[n];

  for (int i = 0; i < n; i++)
    cin >> a[i];

  set<string> data;
  for (int i = 0; i < n; i++) {
    data.insert(a[i]);
  }

  cout << data.size() << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, cnr = 0;
  std::cin >> n;
  string a[n], b[n];

  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
    if (a[i + 1] == "NULL") {
      continue;
    }

    for (int j = 0; j < n; j++) {
      if (b[j] == a[i] || a[j] == "NULL")
        break;
      if (j + 1 == n) {
        b[i] = a[i];
        cnr++;
      }
    }
  }
  cout << cnr << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

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

template <typename Container>
bool include(const Container &c, const typename Container::value_type &v) {
  return (c.end() != std::find(c.begin(), c.end(), v));
}

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  int cnt = 0;
  rep(i, N) cin >> S[i];

  std::sort(S.begin(), S.end());
  S.erase(std::unique(S.begin(), S.end()), S.end());

  cout << S.size() << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

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

template <typename Container>
bool include(const Container &c, const typename Container::value_type &v) {
  return (c.end() != std::find(c.begin(), c.end(), v));
}

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  int cnt = 0;
  rep(i, N) {
    string tmp;
    cin >> tmp;
    if (!include(S, tmp)) {
      cnt++;
    }
    S[i] = tmp;
  }
  cout << cnt << endl;

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

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

int main() {
  int64_t n, a = 1, ans = 1;

  cin >> n;
  vector<string> vec(n);

  for (int i = 0; i < n; i++)
    cin >> vec.at(i);

  sort(vec.begin(), vec.end());

  for (int i = 1; i < n; i++) {
    if (vec.at(i - 1) != vec.at(i))
      ans++;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int64_t n, a = 1, ans = 1;

  cin >> n;
  vector<string> vec(n);
  vector<string> dic(n);

  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
    dic.at(0) = vec.at(0);
    for (int j = 0; j < a; j++) {
      if (vec.at(i) == dic.at(j))
        break;
      if (j == a - 1) {
        dic.at(a) = vec.at(i);
        a++;
        ans++;
      }
    }
  }

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

#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cmath>
#include <cstring>
#include <map>
#include <math.h>
#include <set>
#include <string>

#define INF 1000000000000
#define MOD 1000000007 // 10^9+7:合同式の法

using namespace std;
typedef long long ll;

// マクロ
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)

int main() {
  ll N;
  cin >> N;
  vector<string> syouhin(N);
  map<string, ll> mpa;

  for (ll i = 0; i < N; i++) {
    cin >> syouhin.at(i);
  }

  for (ll i = 0; i < N; i++) {
    mpa[syouhin[i]]++;
  }

  cout << mpa.size() << endl;
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 3) >= this->size() (which is 3)


Fixed submission:

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

int main() {
  int N, kazu = 0;
  cin >> N;
  vector<string> keihin(N), kakutoku(N);
  for (int i = 0; i < N; i++)
    cin >> keihin.at(i);

  for (int i = 0; i < N; i++)
    for (int j = 0; j <= kazu; j++) {
      if (keihin.at(i) != kakutoku.at(j) && j == kazu) {
        kakutoku.at(i) = keihin.at(i);
        kazu++;
      } else if (keihin.at(i) == kakutoku.at(j))
        break;
    }

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

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

int main() {
  int N;
  cin >> N;

  set<string> S;
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    S.insert(s);
  }

  cout << S.size() << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, c;
  string k;
  cin >> N;
  c = 1;

  vector<string> s;
  cin >> k;
  s.push_back(k);

  for (int i = 1; i < N; i++) {
    cin >> k;
    for (int j = 0; j < s.size(); j++) {
      if (k == s.at(j))
        break;
      if (j == s.size() - 1) {
        s.push_back(k);
        c++;
      }
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb pushback
#define fr(i, n) for (int i = 0; i < n; i++)
#define fro(i, j, n) for (int i = j; i < n; i++)
#define ifr(i, n) for (int i = n - 1; i >= 0; i--)

int main() {
  int n;
  cin >> n;
  string s[n];
  int ans = 1;
  int flag = 0;
  int size = 0;
  fr(i, n) { cin >> s[i]; }
  sort(s, s + n);
  fr(i, n - 1) {
    if (s[i] != s[i + 1])
      ans++;
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb pushback
#define fr(i, n) for (int i = 0; i < n; i++)
#define fro(i, j, n) for (int i = j; i < n; i++)
#define ifr(i, n) for (int i = n - 1; i >= 0; i--)

int main() {
  int n;
  cin >> n;
  string s[n];
  int ans = 0;
  int flag = 0;
  int size = 0;
  string news;
  fr(i, n) {
    flag = 0;
    cin >> news;
    fr(j, size) {
      if (s[j] == news) {
        flag = 1;
        break;
      }
    }
    if (flag == 0) {
      s[size] = news;
      size++;
    }
  }
  cout << size << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <set>

using namespace std;

int main() {
  int n;
  cin >> n;

  set<string> s;
  for (int i = 0; i < n; i++) {
    string in;
    cin >> in;
    s.insert(in);
  }

  cout << s.size();

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;

  vector<string> s;
  for (int i = 0; i < n; i++) {
    string in;
    cin >> in;
    if (find(s.begin(), s.end(), in) == s.end())
      s.push_back(in);
  }

  cout << s.size();

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

// abc164_d.cpp
// Sun Apr 26 20:56:43 2020

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

using namespace std;
using ll = long long;
typedef pair<int, int> P;

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

  ll n = s.length();

  ll count[2030];
  fill(count, count + 2030, 0);
  ll amari[n];
  fill(amari, amari + n, 0);

  ll first = ll(s[n - 1] - '0');

  count[first]++;
  amari[n - 1] = first;

  ll keta = 1;
  for (ll i = n - 2; i >= 0; i--) {
    keta = (10 * keta) % 2019;
    ll tmp = ll(s[i] - '0');
    amari[i] = (tmp * keta + amari[i + 1]) % 2019;
    count[amari[i]]++;
  }

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

  cout << ans + count[0] << endl;
  //	printf("%.4f\\n",ans);
}

Error: TLE

Fixed submission:

// abc164_d.cpp
// Sun Apr 26 20:56:43 2020

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

using namespace std;
using ll = long long;
typedef pair<int, int> P;

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

  ll ans = 0;
  int n = s.length();
  for (int i = 0; i < n - 3; i++) {
    string tmp = s.substr(i, 3);
    //		cout << tmp << endl;
    int x = stoi(tmp);
    for (int j = i + 3; j < n; j++) {
      int y = int(s[j] - '0');
      //			cout << y << endl;
      x = 10 * x + y;
      int amari = x % 2019;
      if (amari == 0) {
        ans++;
      }
      x = amari;
    }
    //		cout << "   " << ans << endl;
  }

  cout << ans << endl;
  //	printf("%.4f\\n",ans);
}
Problem p02702 (C++) — buggy submission, verdict: Time Limit Exceeded

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

const int MOD = 2019;

int main() {
  string S;
  cin >> S;
  reverse(S.begin(), S.end());
  ll power = 1;
  ll answer = 0;
  ll cur = 0;
  vector<int> remain(MOD);
  remain[0] = 1;
  for (auto s : S) {
    cur += (s - '0') * power;
    cur %= MOD;
    answer += remain[cur];
    remain[cur]++;
    power = power * 10 % MOD;
  }
  cout << answer << '\\n';
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  string s;
  cin >> s;
  int len = s.size();
  int ans = 0;
  for (int i = 0; i < len; i++) {
    for (int j = i + 1; j <= len; j++) {
      string temp;
      temp = s.substr(i, j - i);
      int x = atoi(temp.c_str());
      if (x % 2019 == 0) {
        ans++;
      }
    }
  }
  cout << ans << '\\n';
}
Problem p02702 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pb push_back
#define ll long long
#define ld long double
#define precision(x, d) cout << fixed << setprecision(d) << x
#define fill(a, b) memset((a), (b), sizeof((a)))
#define FAST                                                                   \\
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);                   \\
  srand(time(NULL));
ll power(ll x, ll y, ll m) {
  ll r = 1;
  for (; y; y >>= 1) {
    if (y & 1)
      r = r * x % m;
    x = x * x % m;
  }
  return r;
}
const ll mod = 1e9 + 7;
const ld pi = 3.14159265358979;

int run_test() {
  string s;
  cin >> s;
  int l = s.length();
  int i = 0;
  int ans = 0;
  int visited[l + 1];
  fill(visited, 0);
  while (i < l) {
    if (visited[i]) {
      i++;
      continue;
    }
    int j = i, k = 0, sum = 0;
    ;
    while (j < l) {
      k = (10 * k + (s[j] - '0')) % 2019;
      if (k == 0) {
        j++;
        sum++;
        visited[j] = 1;
        continue;
      } else {
        j++;
      }
    }
    ans += (sum * (sum + 1)) / 2;
    i++;
  }
  cout << ans;
  return 0;
}

int main() {
  FAST;
  ll t;
  t = 1;

  while (t--) {
    run_test();
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pb push_back
#define ll long long
#define ld long double
#define precision(x, d) cout << fixed << setprecision(d) << x
#define fill(a, b) memset((a), (b), sizeof((a)))
#define FAST                                                                   \\
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);                   \\
  srand(time(NULL));
ll power(ll x, ll y, ll m) {
  ll r = 1;
  for (; y; y >>= 1) {
    if (y & 1)
      r = r * x % m;
    x = x * x % m;
  }
  return r;
}
const ll mod = 1e9 + 7;
const ld pi = 3.14159265358979;

int run_test() {
  string s;
  cin >> s;
  int l = s.length();
  int i = 0;
  int ans = 0;
  while (i < l) {
    int j = i, k = 0, t = i, sum = 0;
    ;
    while (j < l && t < l) {
      k = (10 * k + (s[t] - '0')) % 2019;
      if (k == 0) {
        j++;
        sum++;
        t = j;
        continue;
      } else {
        j++;
        t++;
      }
    }
    ans += (sum * (sum + 1)) / 2;
    i++;
  }
  cout << ans;
  return 0;
}

int main() {
  FAST;
  ll t;
  t = 1;

  while (t--) {
    run_test();
  }
}
Problem p02702 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = (ll)1e18;
const ll MOD = 2019;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  map<ll, ll> mp;
  ll x = 0, pow = 1;
  for (ll i = s.size() - 1; i >= 0; i--) {
    x += (s[i] - '0') * pow;
    pow *= 10;
    x %= MOD;
    pow %= MOD;
    mp[x]++;
  }
  ll counter = 0;
  for (auto a : mp) {
    counter += (a.second * (a.second - 1)) / 2;
  }
  counter += mp[0];
  cout << counter << "\\n";
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
const ll INF = (ll)1e18;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  ll counter = 0;
  for (ll i = 4; i <= s.size(); i++) {
    for (ll j = 0; j < s.size() - i + 1; j++) {
      string b = s.substr(j, i);
      ll x = b[0] - '0';
      for (ll y = 1; y < b.size(); y++) {
        x *= 10;
        x += b[y] - '0';
        x %= 2019;
      }
      if (x == 0)
        counter++;
    }
  }
  cout << counter << "\\n";
}