prithivMLmods/Coder-Stat huggingface dataset:
Problem p02701 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, n) for (int i = s; i < (n); ++i)
#define ALL(n) begin(n), end(n)
using ll = long long;
const ll INF = 1e18;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

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

  vector<string> data(N);
  int data_num = 0;
  int same_cnt = 0;
  REP(i, 0, N) {
    if (data_num == 0) {
      data[0] = S[i];
      ++data_num;
    } else {
      REP(j, 0, data_num) {
        if (S[i] == data[j]) {
          ++same_cnt;
          break;
        }
      }
      if (same_cnt == 0) {
        data[data_num] = S[i];
        ++data_num;
      }
      same_cnt = 0;
    }
  }
  cout << data_num << endl;

  return 0;
}


Fixed submission:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, n) for (int i = s; i < (n); ++i)
#define ALL(n) begin(n), end(n)
using ll = long long;
const ll INF = 1e18;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

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

  // vector<string> data(N);
  // int data_num = 0;
  // int same_cnt = 0;
  // REP(i, 0, N){
  //     if (data_num == 0){
  //         data[0] = S[i];
  //         ++data_num;
  //     } else{
  //         REP(j, 0, data_num){
  //             if (S[i] == data[j]){
  //                 ++same_cnt;
  //                 break;
  //             }
  //         }
  //         if (same_cnt == 0){
  //             data[data_num] = S[i];
  //             ++data_num;
  //         }
  //         same_cnt = 0;
  //     }
  // }
  // cout << data_num << endl;

  set<string> st;
  REP(i, 0, N) { st.insert(S[i]); }
  cout << st.size() << endl;

  return 0;
}
Problem p02701 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;

int main() {
  ll n;
  cin >> n;
  vector<string> s;
  ll ans = 0;
  for (ll i = 0; i < n; i++) {
    // printf("%d time\n", i);
    string k;
    cin >> k;
    if (binary_search(s.begin(), s.end(), k)) { // あったら
      // printf("already exist ");
      // out(k);
      continue;
    } else {
      ans++; // なかったら
      s.push_back(k);
      Sort(s);
    }
  }
  out(ans);
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;

int main() {
  ll n;
  cin >> n;
  vector<string> s(n);

  rep(i, n) cin >> s[i];

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

  ll ans = n;
  for (ll i = 1; i < n; i++) {
    if (s[i] == s[i - 1])
      ans--;
  }
  out(ans);
}
Problem p02701 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <string>
using namespace std;
int main(void) {
  int i, cnt, n;
  string a[100000];
  scanf("%d", &n);
  for (i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  cnt = 1;
  for (i = 1; i < n; i++) {
    if (a[i] != a[i - 1])
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <string>
using namespace std;
int main(void) {
  int i, cnt, n;
  string a[200000];
  scanf("%d", &n);
  for (i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  cnt = 1;
  for (i = 1; i < n; i++) {
    if (a[i] != a[i - 1])
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}
Problem p02701 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

string s[100010];
map<string, int> mp;
int n;

int main() {
  cin >> n;
  //	for(register int i = 1; i <= n; i++) cin >> s[i];
  for (register int i = 1; i <= n; i++) {
    cin >> s[i];
    mp[s[i]]++;
  }
  int jsq = 0;
  map<string, int>::iterator iter;
  for (iter = mp.begin(); iter != mp.end(); iter++) {
    if (iter->second >= 1)
      jsq++;
  }
  cout << jsq;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

string s[300010];
map<string, int> mp;
int n;

int main() {
  cin >> n;
  //	for(register int i = 1; i <= n; i++) cin >> s[i];
  for (register int i = 1; i <= n; i++) {
    cin >> s[i];
    mp[s[i]]++;
  }
  int jsq = 0;
  map<string, int>::iterator iter;
  for (iter = mp.begin(); iter != mp.end(); iter++) {
    if (iter->second >= 1)
      jsq++;
  }
  cout << jsq;
  return 0;
}
Problem p02701 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

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

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

  int flag = true;
  vector<string> kind;
  for (int i = 0; i < N; i++) {
    flag = true;
    for (int j = 0; j < kind.size(); j++) {
      if (arr[i] == kind[j]) {
        flag = false;
        break;
      }
    }
    if (flag)
      kind.push_back(arr[i]);
  }
  cout << kind.size() << endl;
}


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

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

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

  sort(arr.begin(), arr.end());
  arr.erase(unique(arr.begin(), arr.end()), arr.end());
  cout << arr.size() << endl;
}
Problem p02701 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
string s[N];
set<string> st;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    st.insert(s[i]);
  }
  cout << st.size() << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
string s[N];
set<string> st;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    st.insert(s[i]);
  }
  cout << st.size() << endl;
}
Problem p02701 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define vi vector<int>
#define pb push_back
#define sz(s) (int)s.size()
#define all(v) v.begin(), v.end()
#define show(a) cerr << #a << " -> " << a << "\n"

ll mn = 1000000, mx = -1000000000;
ll cnt, cnt2, sum, x, y;
int n;
string s[10000];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  sort(s, s + n);
  for (int i = 0; i < n; i++) {
    if (s[i] != s[i + 1]) {
      cnt++;
    }
  }
  cout << cnt;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define vi vector<int>
#define pb push_back
#define sz(s) (int)s.size()
#define all(v) v.begin(), v.end()
#define show(a) cerr << #a << " -> " << a << "\n"

ll mn = 1000000, mx = -1000000000;
ll cnt, cnt2, sum, x, y;
int n;
string s[300001];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  sort(s, s + n);
  for (int i = 0; i < n; i++) {
    if (s[i] != s[i + 1]) {
      cnt++;
    }
  }
  cout << cnt;
  return 0;
}
Problem p02701 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s[i];
  sort(s.begin(), s.end());
  int cnt = 0;
  rep(i, n) {
    if (s[i] != s[i - 1])
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s[i];
  sort(s.begin(), s.end());
  int cnt = 1;
  for (int i = 1; i < n; i++) {
    if (s[i] != s[i - 1])
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}
Problem p02701 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  for (int i = 0; i < N; i++) {
    cin >> S.at(i);
  }
  sort(S.begin(), S.end());
  int count = N;
  for (int i = 0; i < N; i++) {
    if (S.at(i) == S.at(i + 1)) {
      count--;
    }
  }
  cout << count << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  for (int i = 0; i < N; i++) {
    cin >> S.at(i);
  }
  sort(S.begin(), S.end());
  int count = N;
  for (int i = 1; i < N; i++) {
    if (S.at(i - 1) == S.at(i)) {
      count--;
    }
  }
  cout << count << endl;
}
Problem p02701 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
#include <unordered_map>
using namespace std;

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

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

  unordered_map<string, int> map;
  for (int i = 0; i < N; i++) {
    map[S[i]] = 1;
  }

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

Fixed submission:
#include <iostream>
#include <string>
#include <unordered_map>
using namespace std;

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

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

  unordered_map<string, int> map;
  for (int i = 0; i < N; i++) {
    map[S[i]] = 1;
  }

  cout << map.size() << endl;
}
Problem p02701 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

const int N = 1e5 + 10;
string s[N];

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> s[i];
  sort(s, s + n);
  cout << (unique(s, s + n) - s) << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

const int N = 2e5 + 10;
string s[N];

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> s[i];
  sort(s, s + n);
  cout << (unique(s, s + n) - s) << endl;
  return 0;
}
Problem p02701 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, k;
  k = 1;
  cin >> N;
  vector<string> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      if (vec.at(i) == vec.at(j)) {
        break;
      } else {
        if (j == N - 1) {
          k = k + 1;
        }
      }
    }
  }
  cout << k << endl;
}


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

int main() {
  int N, k;
  k = 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 = 0; i < N - 1; i++) {
    if (vec.at(i) != vec.at(i + 1)) {
      k = k + 1;
    }
  }
  cout << k << endl;
}
Problem p02701 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map> //map<int, int> x;
#include <numeric>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i <= (int)(n); i++)
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

using ll = long long;
using namespace std;
int main() {
  int n;
  int count = 0;
  cin >> n;
  string a;
  vector<string> strlist(1000);
  rep(i, n) cin >> strlist[i];

  sort(strlist.begin(), strlist.end());
  strlist.erase(unique(strlist.begin(), strlist.end()), strlist.end());

  cout << int(strlist.size() - 1) << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map> //map<int, int> x;
#include <numeric>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i <= (int)(n); i++)
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

using ll = long long;
using namespace std;
int main() {
  int n;
  int count = 0;
  cin >> n;
  string a;
  vector<string> strlist(10000000);
  rep(i, n) cin >> strlist[i];

  sort(strlist.begin(), strlist.end());
  strlist.erase(unique(strlist.begin(), strlist.end()), strlist.end());

  cout << int(strlist.size() - 1) << endl;
  return 0;
}
Problem p02701 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s.at(i);
  sort(s.begin(), s.end());
  int ans = n;
  rep(i, n) {
    if (s[i] == s[i - 1])
      ans--;
  }
  cout << ans << endl;
}


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

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s.at(i);
  sort(s.begin(), s.end());
  int ans = n;
  for (int j = 1; j < n; j++) {
    if (s[j] == s[j - 1])
      ans--;
  }
  cout << ans << endl;
}
Problem p02701 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<string> vec(20001);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> vec[i];
  }
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  cout << vec.size() - 1;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<string> vec(200002);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> vec[i];
  }
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  cout << vec.size() - 1;
}
Problem p02701 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int N;
vector<string> s;

int main() {
  cin >> N;
  s.resize(N);
  for (int i = 0; i < N; i++)
    cin >> s[i];
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      if (s[i] == s[j])
        break;
      if (j == N - 1)
        cnt++;
    }
    if (i == N - 1)
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}


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

int N;
vector<string> s;

int main() {
  cin >> N;
  s.resize(N);
  for (int i = 0; i < N; i++)
    cin >> s[i];
  sort(s.begin(), s.end());
  int cnt = 1;
  for (int i = 0; i < N - 1; i++) {
    if (s[i] != s[i + 1])
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}
Problem p02701 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;

void solve(long long N, std::vector<std::string> S) {

  long long ans = 0;
  std::vector<std::string> tmp;
  std::vector<std::string>::iterator sIter;

  for (long long i = 0; i < N; i++) {

    sIter = std::find(tmp.begin(), tmp.end(), S[i]);
    if (sIter == tmp.end()) {
      tmp.push_back(S[i]);
      ans += 1;
    }
  }

  cout << ans << endl;
  return;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<std::string> S(N);
  for (int i = 0; i < N; i++) {
    std::cin >> S[i];
  }
  solve(N, std::move(S));
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;

void solve(long long N, std::vector<std::string> S) {

  std::sort(S.begin(), S.end());
  S.erase(std::unique(S.begin(), S.end()), S.end());
  cout << S.size() << endl;
  return;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<std::string> S(N);
  for (int i = 0; i < N; i++) {
    std::cin >> S[i];
  }
  solve(N, std::move(S));
  return 0;
}
Problem p02701 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  for (int i = 0; i < N; i++) {
    cin >> S.at(i);
  }
  vector<string> s;
  int answer = 0;
  for (int i = 0; i < N; i++) {
    if (find(s.begin(), s.end(), S.at(i)) == s.end()) {
      answer++;
      s.emplace_back(S.at(i));
    }
  }
  cout << answer << endl;
}


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

int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  for (int i = 0; i < N; i++) {
    cin >> S.at(i);
  }
  sort(S.begin(), S.end());
  S.erase(unique(S.begin(), S.end()), S.end());
  cout << S.size() << endl;
}
Problem p02701 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
const int N = 2e5 + 5;
int a[N][26];
int cnt[N], idx, ans;
void ins(char str[]) {
  int p = 0;
  for (int i = 0; str[i]; i++) {
    int u = str[i] - 'a';
    if (!a[p][u])
      a[p][u] = ++idx;
    p = a[p][u];
  }
  cnt[p]++;
  if (cnt[p] == 1)
    ans++;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    char str[12];
    scanf("%s", str);
    ins(str);
  }
  cout << ans;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
const int N = 2e6 + 5;
int a[N][26];
int cnt[N], idx, ans;
void ins(char str[]) {
  int p = 0;
  for (int i = 0; str[i]; i++) {
    int u = str[i] - 'a';
    if (!a[p][u])
      a[p][u] = ++idx;
    p = a[p][u];
  }
  cnt[p]++;
  if (cnt[p] == 1)
    ans++;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    char str[12];
    scanf("%s", str);
    ins(str);
  }
  cout << ans;
  return 0;
}
Problem p02701 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  int ans = 0;
  for (int i = 0; i < N; i++) {
    cin >> S.at(i);
  }
  sort(S.begin(), S.end());
  for (int i = 0; i < N; i++) {
    bool memo = true;
    if (S.at(i) == S.at(i + 1)) {
      memo = false;
    }
    if (memo == true) {
      ans++;
    }
  }
  cout << ans << endl;
}


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

int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  int ans = 0;
  for (int i = 0; i < N; i++) {
    cin >> S.at(i);
  }
  sort(S.begin(), S.end());
  for (int i = 0; i < N; i++) {
    bool memo = true;
    if (i != N - 1) {
      if (S.at(i) == S.at(i + 1)) {
        memo = false;
      }
    }
    if (memo == true) {
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p02701 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, d, n) for (int i = (d); i < (n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main() {

  ll n;
  cin >> n;
  ll ans = n;
  ll ka = 0;
  vector<string> a(n);
  rep(i, n) {
    cin >> a.at(i);
    rep(j, i) {
      if (a.at(i) == a.at(j)) {
        ka++;
        break;
      }
    }
  }

  cout << ans - ka << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, d, n) for (int i = (d); i < (n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main() {

  ll n;
  cin >> n;
  ll ans = n;
  ll ka = 0;
  vector<string> a(n);
  rep(i, n) { cin >> a.at(i); }

  sort(all(a));
  rep(i, n - 1) {
    if (a.at(i) == a.at(i + 1))
      ka++;
  }

  cout << ans - ka << endl;
}
Problem p02701 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int i, j, n;
  int flag = 0;
  int count = 0;

  cin >> n;
  vector<string> s(n);
  for (i = 0; i < n; i++) {
    cin >> s.at(i);
  }

  for (i = 0; i < n; i++) {
    flag = 0;
    for (j = 0; j < i; j++) {
      if (s.at(i) == s.at(j)) {
        flag = 1;
      }
    }
    if (flag == 0) {
      count++;
    }
  }

  cout << count << endl;
}


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

int main() {
  int i, j, n;
  int flag = 0;
  int count = 0;

  cin >> n;
  vector<string> s(n);
  for (i = 0; i < n; i++) {
    cin >> s.at(i);
  }

  sort(s.begin(), s.end());
  s.erase(unique(s.begin(), s.end()), s.end());

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

  cout << count << endl;
}
Problem p02701 (C++)

Buggy submission (status: Time Limit Exceeded):
// gacha
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  vector<string> v;
  v.push_back(s[0]);
  for (int i = 1; i < n; i++) {
    v.push_back(s[i]);
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
  }
  cout << v.size() << endl;
  return 0;
}

Fixed submission:
// gacha
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }

  sort(s.begin(), s.end());
  s.erase(unique(s.begin(), s.end()), s.end());

  cout << s.size() << endl;
  return 0;
}
Problem p02701 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

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

  vector<string> S(N);
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }
  vector<string> prize;
  for (int i = 0; i < N; i++) {
    if (find(prize.begin(), prize.end(), S[i]) == prize.end()) {
      prize.push_back(S[i]);
    }
  }
  cout << prize.size() << endl;

  return 0;
}


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

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

  vector<string> S(N);
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }
  sort(S.begin(), S.end());
  S.erase(unique(S.begin(), S.end()), S.end());
  //  vector<string> prize;
  // for (int i = 0; i < N; i++) {
  // if (find(prize.begin(), prize.end(), S[i]) == prize.end()) {
  //   prize.push_back(S[i]);
  //}
  //}
  cout << S.size() << endl;

  return 0;
}
Problem p02701 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
string s[10005];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
  }
  sort(s + 1, s + 1 + n);
  int cnt = 1;
  for (int i = 2; i <= n; i++) {
    if (s[i] != s[i - 1]) {
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
string s[200005];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
  }
  sort(s + 1, s + 1 + n);
  int cnt = 1;
  for (int i = 2; i <= n; i++) {
    if (s[i] != s[i - 1]) {
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}
Problem p02701 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s[100005];
  long n, i;
  map<string, long> mp;
  while (cin >> n) {
    for (i = 0; i < n; i++) {
      cin >> s[i];
      mp[s[i]] = i;
    }
    cout << mp.size() << endl;
    mp.clear();
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s[200005];
  long n, i;
  map<string, long> mp;
  while (cin >> n) {
    for (i = 0; i < n; i++) {
      cin >> s[i];
      mp[s[i]] = i;
    }
    cout << mp.size() << endl;
    mp.clear();
  }
  return 0;
}
Problem p02701 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string s[100000];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  sort(s, s + n);
  int ans = 1;
  for (int i = 1; i < n; i++) {
    if (s[i] != s[i - 1]) {
      ans++;
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string s[200000];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  sort(s, s + n);
  int ans = 1;
  for (int i = 1; i < n; i++) {
    if (s[i] != s[i - 1]) {
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p02702 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
int mod = 1000000007;
#define ll long long
string s;
int tens[220000] = {0};
int temp[220000] = {0};

void pre() {
  tens[0] = 1;
  rep(i, 210000) { tens[i + 1] = (tens[i] * 10) % 2019; }
}

int solve() {
  temp[0] = s[s.size() - 1] - '0';
  rep(i, s.size() - 1) {
    temp[i + 1] = (temp[i] + tens[i + 1] * (s[s.size() - i - 2] - '0')) % 2019;
  }
}

int main() {
  int ans = 0, divi[2020] = {0};
  cin >> s;
  pre();
  solve();
  rep(i, s.size()) { divi[temp[i]]++; }
  rep(i, 2020) {
    if (divi[i] > 1)
      ans += divi[i] * (divi[i] - 1) / 2;
  }
  cout << ans + divi[0] << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
int mod = 1000000007;
#define ll long long
string s;
int tens[220000] = {0};
int temp[220000] = {0};

void pre() {
  tens[0] = 1;
  rep(i, 210000) { tens[i + 1] = (tens[i] * 10) % 2019; }
}

void solve() {
  temp[0] = s[s.size() - 1] - '0';
  rep(i, s.size() - 1) {
    temp[i + 1] = (temp[i] + tens[i + 1] * (s[s.size() - i - 2] - '0')) % 2019;
  }
}

int main() {
  int ans = 0, divi[2020] = {0};
  cin >> s;
  pre();
  solve();
  rep(i, s.size()) { divi[temp[i]]++; }
  rep(i, 2020) {
    if (divi[i] > 1)
      ans += divi[i] * (divi[i] - 1) / 2;
  }
  cout << ans + divi[0] << endl;
  return 0;
}
Problem p02702 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;

const ll mod = 1e9 + 7;

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

  string s;
  cin >> s;
  ll n = s.length();
  vector<vector<ll>> dp(n, vector<ll>(2019, 0));
  vector<ll> dp1(2019, 0), dp2(2019, 0);
  dp1[s[0] - '0'] = 1;
  ll ans = 0;
  for (int i = 1; i < n; i++) {
    ll num = s[i] - '0';
    dp2[num] = 1;
    for (int j = 0; j < 2019; j++) {
      dp2[(10 * j + num) % 2019] += dp1[j];
    }
    ans += dp2[0];
    dp1 = dp2;
    dp2.assign(2019, 0);
  }

  cout << ans << '\n';
}


Fixed submission:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;

const ll mod = 1e9 + 7;

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

  string s;
  cin >> s;
  ll n = s.length();
  vector<ll> dp1(2019, 0), dp2(2019, 0);
  dp1[s[0] - '0'] = 1;
  ll ans = 0;
  for (int i = 1; i < n; i++) {
    ll num = s[i] - '0';
    dp2[num] = 1;
    for (int j = 0; j < 2019; j++) {
      dp2[(10 * j + num) % 2019] += dp1[j];
    }
    ans += dp2[0];
    dp1 = dp2;
    dp2.assign(2019, 0);
  }

  cout << ans << '\n';
}
Problem p02702 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
  string s;
  cin >> s;
  ll ans = 0;
  int n = s.size();
  vector<vector<ll>> dp(n, vector<ll>(n));
  vector<ll> v(2020);
  rep(i, n) {
    int now = (int)(s[i] - '0');
    vector<ll> n = v;
    rep(j, 2019) {
      if (v[j] == 0)
        continue;
      ll next = (j * 10 + now) % 2019;
      n[next] += v[j];
      n[j] -= v[j];
      // if(i<5) cout << i << " " << j << " " << next << " " << v[next] << " "
      // << v[j] << endl;
    }
    v = n;
    v[now]++;
    ans += v[0];
  }
  // rep(i, 2019) cout << i << " :" << v[i] << endl;
  cout << ans << endl;
  return 0;
}

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

int main() {
  string s;
  cin >> s;
  ll ans = 0;
  int n = s.size();
  vector<ll> v(2020);
  rep(i, n) {
    int now = (int)(s[i] - '0');
    vector<ll> n = v;
    rep(j, 2019) {
      if (v[j] == 0)
        continue;
      ll next = (j * 10 + now) % 2019;
      n[next] += v[j];
      n[j] -= v[j];
      // if(i<5) cout << i << " " << j << " " << next << " " << v[next] << " "
      // << v[j] << endl;
    }
    v = n;
    v[now]++;
    ans += v[0];
  }
  // rep(i, 2019) cout << i << " :" << v[i] << endl;
  cout << ans << endl;
  return 0;
}
Problem p02702 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int F[200000][2019] = {};
int main() {
  string S;
  cin >> S;
  int i, r, s, N = S.size(), R[10][2019] = {};
  for (r = 0; r < 2019; r++) {
    for (i = 1; i < 10; i++) {
      for (s = 0; s < 2019; s++) {
        if ((10 * s + i) % 2019 == r) {
          R[i][r] = s;
          break;
        }
      }
    }
  }
  for (i = 0; i < N; i++) {
    F[i][S[i] - '0'] = 1;
  }
  for (i = 1; i < N; i++) {
    for (r = 0; r < 2019; r++) {
      F[i][r] += F[i - 1][R[S[i] - '0'][r]];
    }
  }
  long ans = 0;
  for (i = 0; i < N; i++) {
    ans += F[i][0];
  }
  cout << ans << "\n";
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
unsigned short F[200000][2019] = {};
int main() {
  string S;
  cin >> S;
  int i, r, s, N = S.size(), R[10][2019] = {};
  for (r = 0; r < 2019; r++) {
    for (i = 1; i < 10; i++) {
      for (s = 0; s < 2019; s++) {
        if ((10 * s + i) % 2019 == r) {
          R[i][r] = s;
          break;
        }
      }
    }
  }
  for (i = 0; i < N; i++) {
    F[i][S[i] - '0'] = 1;
  }
  for (i = 1; i < N; i++) {
    for (r = 0; r < 2019; r++) {
      F[i][r] += F[i - 1][R[S[i] - '0'][r]];
    }
  }
  long ans = 0;
  for (i = 0; i < N; i++) {
    ans += F[i][0];
  }
  cout << ans << "\n";
}
Problem p02702 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, k, n) for (ll i = k; i < (n); i++)

// 累積和的なものを考えると良いらしい
int main() {
  string s;
  cin >> s;
  ll n = s.size();
  vector<ll> a(2019, 0);
  ll fac = 1;
  ll cur = 0;
  a[cur]++;
  rep1(i, n) {
    ll add = s[n - 1 - i] - '0';
    cur = (cur + fac * add) % 2019;
    fac = (fac * 10) % 2019;
    a[cur]++;
  }
  ll ans = 0;
  rep1(i, n) { ans += a[i] * (a[i] - 1) / 2; }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, k, n) for (ll i = k; i < (n); i++)

// 累積和的なものを考えると良いらしい
int main() {
  string s;
  cin >> s;
  ll n = s.size();
  vector<ll> a(2019, 0);
  ll fac = 1;
  ll cur = 0;
  a[cur]++;
  rep1(i, n) {
    ll add = s[n - 1 - i] - '0';
    cur = (cur + fac * add) % 2019;
    fac = (fac * 10) % 2019;
    a[cur]++;
  }
  ll ans = 0;
  rep1(i, a.size()) { ans += a[i] * (a[i] - 1) / 2; }
  cout << ans << endl;
}
Problem p02702 (C++)

Buggy submission (status: 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;
  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;
}


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;
  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;
}
Problem p02702 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 2019;
int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  string s;
  cin >> s;
  ll n = s.size();
  vector<ll> ab(n + 1, 0);
  ll tmp = 0;
  ll mod = 1;
  for (int i = 0; i < n; i++) {
    tmp += (ll(s[n - 1 - i] - '0') * mod);
    ab[i + 1] = tmp % MOD;
    mod *= 10;
    mod %= MOD;
  }
  ll ans = 0;
  vector<ll> c(2019, 0);
  for (int i = 0; i < n + 1; i++) {
    c[ab[i - 1]]++;
  }
  for (int i = 0; i < 2019; i++) {
    ans += c[i] * (c[i] - 1) / 2;
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 2019;
int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  string s;
  cin >> s;
  ll n = s.size();
  vector<ll> ab(n + 1, 0);
  ll tmp = 0;
  ll mod = 1;
  for (int i = 0; i < n; i++) {
    tmp += (ll(s[n - 1 - i] - '0') * mod);
    ab[i + 1] = tmp % MOD;
    mod *= 10;
    mod %= MOD;
  }
  ll ans = 0;
  vector<ll> c(2019, 0);
  for (int i = 0; i < n + 1; i++) {
    c[ab[i]]++;
  }
  for (int i = 0; i < 2019; i++) {
    ans += c[i] * (c[i] - 1) / 2;
  }
  cout << ans << endl;
}
Problem p02702 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;

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

  int count = 0;
  for (int i = 0; i < s.length(); i++) {
    int num = (s[i] - '0');
    for (int j = i + 1; j < s.length(); j++) {
      num = 10 * num + (s[j] - '0');
      if (num % 2019 == 0)
        count++;
      num %= 2019;
    }
  }

  cout << count << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

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

  long long dp[2][2019];
  for (int i = 0; i < 2019; i++) {
    dp[0][i] = 0;
    dp[1][i] = 0;
  }

  long long count = 0;
  for (long long i = 0; i < s.length(); i++) {
    int d = s[i] - '0';
    for (int j = 0; j < 2019; j++)
      dp[0][j] = dp[1][j];
    for (int j = 0; j < 2019; j++)
      dp[1][(10 * j + d) % 2019] = dp[0][j];
    if (d != 0)
      dp[1][d]++;

    count += dp[1][0];
  }

  cout << count << endl;

  return 0;
}
Problem p02702 (C++)

Buggy submission (status: Runtime Error):
// by Isaunoya
#include <bits/stdc++.h>
#define int long long
using namespace std;
struct io {
  char buf[1 << 25 | 3], *s;
  int f;
  io() { f = 0, buf[fread(s = buf, 1, 1 << 25, stdin)] = '\n'; }
  io &operator>>(int &x) {
    for (x = f = 0; !isdigit(*s); ++s)
      f |= *s == '-';
    while (isdigit(*s))
      x = x * 10 + (*s++ ^ 48);
    return x = f ? -x : x, *this;
  }
};

const int maxn = 1e5 + 51;
int g[maxn];
signed main() {
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
#endif
  string s;
  cin >> s;
  int n = s.length(), res = 0;
  int x, y;
  x = y = 0;
  g[0] = 1;
  for (int i = 1; i <= n; i++)
    g[i] = g[i - 1] * 10 % 2019;
  static int a[23333];
  int ans = 0;
  a[0] = 1;
  for (int i = n - 1; ~i; --i) {
    x = (s[i] ^ '0') * g[n - i - 1] % 2019;
    ans += a[(x + y) % 2019]++;
    y = (x + y) % 2019;
  }
  cout << ans << '\n';
  return 0;
}


Fixed submission:
// by Isaunoya
#include <bits/stdc++.h>
#define int long long
using namespace std;
struct io {
  char buf[1 << 25 | 3], *s;
  int f;
  io() { f = 0, buf[fread(s = buf, 1, 1 << 25, stdin)] = '\n'; }
  io &operator>>(int &x) {
    for (x = f = 0; !isdigit(*s); ++s)
      f |= *s == '-';
    while (isdigit(*s))
      x = x * 10 + (*s++ ^ 48);
    return x = f ? -x : x, *this;
  }
};

const int maxn = 2e5 + 52;
int g[maxn];
signed main() {
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
#endif
  string s;
  cin >> s;
  int n = s.length(), res = 0;
  int x, y;
  x = y = 0;
  g[0] = 1;
  for (int i = 1; i <= n; i++)
    g[i] = g[i - 1] * 10 % 2019;
  static int a[23333];
  int ans = 0;
  a[0] = 1;
  for (int i = n - 1; ~i; --i) {
    x = (s[i] ^ '0') * g[n - i - 1] % 2019;
    ans += a[(x + y) % 2019]++;
    y = (x + y) % 2019;
  }
  cout << ans << '\n';
  return 0;
}
Problem p02702 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

int main() {
  string s;
  cin >> s;
  reverse(s.begin(), s.end());
  int ten = 1, sum = 0, cnt[2019] = {};
  long long ans = 0;
  for (int i = 0; i < s.size(); i++) {
    cnt[sum]++;
    sum += ((s[i] - '0') * ten) % 2019;
    ans += cnt[sum];
    ten = (ten * 10) % 2019;
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

int main() {
  string s;
  cin >> s;
  reverse(s.begin(), s.end());
  int ten = 1, sum = 0, cnt[2019] = {};
  long long ans = 0;
  for (int i = 0; i < s.size(); i++) {
    cnt[sum]++;
    sum += (s[i] - '0') * ten;
    sum %= 2019;
    ans += cnt[sum];
    ten = (ten * 10) % 2019;
  }
  cout << ans << endl;
}
Problem p02702 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(cont) cont.begin(), cont.end()
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define fore(i, a, b) for (int i = a, almo5t = b; i < almo5t; ++i)
#define SZ(x) ((int)x.size())
#define EPS 1e-9
#define PI acos(-1)
#define MOD 1000000007
#define FIN                                                                    \
  std::ios_base::sync_with_stdio(false);                                       \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)

const int N = 0;

typedef long long int ll;

using namespace std;

int main() {
  FIN;
  // freopen("../input.txt", "r", stdin);freopen("../output.txt", "w", stdout);
  string s;
  cin >> s;
  ll modulo[2000];
  fore(i, 0, 2000) modulo[i] = 0;
  modulo[0] = 1;
  ll temp = 0;
  ll mod10 = 1;
  ll ans = 0;
  fore(i, 0, s.size()) {
    int pos = s.size() - 1 - i;
    temp += ((s[pos] - '0') * mod10) % 2019;
    temp %= 2019;
    mod10 = ((mod10 % 2019) * 10) % 2019;
    modulo[temp]++;
    if (modulo[temp] >= 2) {
      ans += modulo[temp] - 1;
    }
    // cout<<temp<<"\n";
  }
  cout << ans;
  return 0;
}

// ============== Notes =============== //
// common bugs
// - remove reader
// - fastio
// - int overflow (especially intermediate expressionns)
// - array bounds (indices bigger than MAXN?, is MAXN correct?)
// - special cases (n=1, graph not connected?)
// - re-initialize efficiently between test cases

Fixed submission:
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(cont) cont.begin(), cont.end()
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define fore(i, a, b) for (int i = a, almo5t = b; i < almo5t; ++i)
#define SZ(x) ((int)x.size())
#define EPS 1e-9
#define PI acos(-1)
#define MOD 1000000007
#define FIN                                                                    \
  std::ios_base::sync_with_stdio(false);                                       \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)

const int N = 0;

typedef long long int ll;

using namespace std;

int main() {
  FIN;
  // freopen("../input.txt", "r", stdin);freopen("../output.txt", "w", stdout);
  string s;
  cin >> s;
  ll modulo[2020];
  fore(i, 0, 2020) modulo[i] = 0;
  modulo[0] = 1;
  ll temp = 0;
  ll mod10 = 1;
  ll ans = 0;
  fore(i, 0, s.size()) {
    int pos = s.size() - 1 - i;
    temp += ((s[pos] - '0') * mod10) % 2019;
    temp %= 2019;
    mod10 = ((mod10 % 2019) * 10) % 2019;
    modulo[temp]++;
    if (modulo[temp] >= 2) {
      ans += modulo[temp] - 1;
    }
    // cout<<temp<<"\n";
  }
  cout << ans;
  return 0;
}

// ============== Notes =============== //
// common bugs
// - remove reader
// - fastio
// - int overflow (especially intermediate expressionns)
// - array bounds (indices bigger than MAXN?, is MAXN correct?)
// - special cases (n=1, graph not connected?)
// - re-initialize efficiently between test cases
Problem p02702 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

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

int main() {
  const static int mod = 2019;
  int cnt_bin[2019] = {};
  string S;
  cin >> S;
  int size = S.size();
  int tmp = 0;
  for (int i = size - 1; i >= 0; --i) {
    int d = S.at(i) - '0';
    tmp += d * modpow(10, size - 1 - i, mod) % mod;
    tmp %= mod;
    ++cnt_bin[tmp];
  }
  int64_t sum = 0;
  sum += (cnt_bin[0] + 1) * cnt_bin[0] / 2;
  for (int i = 1; i < mod; ++i) {
    sum += (cnt_bin[i] - 1) * cnt_bin[i] / 2;
  }
  cout << sum << endl;
}


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

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

int main() {
  const static int mod = 2019;
  int cnt_bin[2019] = {};
  string S;
  cin >> S;
  int size = S.size();
  int tmp = 0;
  for (int i = size - 1; i >= 0; --i) {
    int d = S.at(i) - '0';
    tmp += d * modpow(10, size - 1 - i, mod) % mod;
    tmp %= mod;
    ++cnt_bin[tmp];
  }
  int64_t sum = 0;
  sum += (cnt_bin[0] + 1) * cnt_bin[0] / 2;
  for (int i = 1; i < mod; ++i) {
    sum += (cnt_bin[i] - 1) * cnt_bin[i] / 2;
  }
  cout << sum << endl;
}
Problem p02702 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define int long long
int A[123456];

signed main() {
  string s;
  cin >> s;
  reverse(s.begin(), s.end());
  for (int i = 0, t = 1; i < s.size(); i++) {
    int a = s[i] - '0';
    A[i + 1] = (A[i] + a * t) % 2019;
    (t *= 10) %= 2019;
  }
  map<int, int> m;
  for (int i = 0; i <= s.size(); i++)
    m[A[i]]++;
  int ans = 0;
  for (auto p : m)
    ans += p.second * (p.second - 1) / 2;
  cout << ans << endl;
}


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

#define int long long
int A[223456];

signed main() {
  string s;
  cin >> s;
  reverse(s.begin(), s.end());
  for (int i = 0, t = 1; i < s.size(); i++) {
    int a = s[i] - '0';
    A[i + 1] = (A[i] + a * t) % 2019;
    (t *= 10) %= 2019;
  }
  map<int, int> m;
  for (int i = 0; i <= s.size(); i++)
    m[A[i]]++;
  int ans = 0;
  for (auto p : m)
    ans += p.second * (p.second - 1) / 2;
  cout << ans << endl;
}
Problem p02702 (C++)

Buggy submission (status: 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[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;
}

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[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;
}
Problem p02702 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <climits>
#include <sstream>
using namespace std;

int main() {
  string S;
  cin >> S;
  map<long long, long long> mp;
  mp[0] = 1;

  for (int i = 1; i <= S.size(); i++) {
    string s = S.substr(S.size() - i, i);
    // cout << s << endl;
    long long n = stoll(s);
    mp[n % 2019]++;
  }
  long long ans = 0;
  for (auto m : mp) {
    ans += m.second * (m.second - 1) / 2;
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#include <climits>
#include <sstream>
using namespace std;

int main() {
  string S;
  cin >> S;
  map<long long, long long> mp;
  mp[0] = 1;
  long long now = 0, ten = 1;
  for (int i = S.size() - 1; i >= 0; i--) {
    now = (now + (S[i] - '0') * ten) % 2019;
    ten *= 10;
    ten %= 2019;
    mp[now]++;
  }
  long long ans = 0;
  for (auto m : mp) {
    ans += m.second * (m.second - 1) / 2;
  }
  cout << ans << endl;
}
Problem p02702 (Python)

Buggy submission (status: Time Limit Exceeded):
S = input()
N = len(S)

cnt = 0
for i in range(N - 3):
    for j in range(i + 4, N + 1):
        if int(S[i:j]) % 2019 == 0:
            # print(i, j)
            cnt += 1
print(cnt)


Fixed submission:
S = input()
N = len(S)

num = [0] * 2019
num[0] = 1
now, ans = 0, 0
_10 = 1

for i in range(N - 1, -1, -1):
    now = (now + int(S[i]) * _10) % 2019
    _10 *= 10
    _10 %= 2019
    ans += num[now]
    num[now] += 1

print(ans)
Problem p02702 (Python)

Buggy submission (status: Time Limit Exceeded):
from collections import defaultdict

S = input()
n = len(S)

mod = 2019
d = defaultdict(int)
d[0] = 1
num = 0
for i in reversed(range(n)):
    num += int(S[i]) * 10 ** (n - i - 1)
    num %= mod
    d[num] += 1

ans = 0
for v in d.values():
    ans += v * (v - 1) // 2
print(ans)


Fixed submission:
from collections import defaultdict

S = input()
n = len(S)

mod = 2019
d = defaultdict(int)
d[0] = 1
num = 0
for i in reversed(range(n)):
    num += int(S[i]) * pow(10, n - i - 1, mod)
    num %= mod
    d[num] += 1

ans = 0
for v in d.values():
    ans += v * (v - 1) // 2
print(ans)