Problem p02702 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define MOD = 998244353;
#define int long long int
#define double long double
#define inf (int)(1e15)
#define all(x) (x).begin(), (x).end()
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define isYes(x) printf("%s\n", (x) ? "Yes" : "No")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define isIn(x, y, h, w) (x >= 0 && x < h && y >= 0 && y < w)
#define pair pair<int, int>
typedef vector<int> vi;   // Vector of long long
typedef vector<vi> vvi;   // Vector of vi
typedef vector<pair> vii; // Vector of pairs
typedef vector<vii> vvii; // Vector of Vector of pairs
typedef vector<bool> vb;  // Vector of bool
#define pq                                                                     \
  priority_queue // Max heap (To convert to min heap, use negative sign before
                 // every value)
#define ff first // For pairs
#define ss second
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, -1, 0, 1};
const int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1},
          dy8[] = {1, -1, 1, 0, -1, 1, -0, -1};
#define testcases(t)                                                           \
  int(t);                                                                      \
  cin >> (t);                                                                  \
  while ((t)--)
#define range(c, r) (c).begin(), (c).begin() + (r) // Mainly used in sorting
#define present(c, x) ((c).find(x) != (c).end())   // for sets, maps, multi-maps
#define cpresent(c, x) (find(all(c), x) != (c).end()) // for vectors
#define run(x, c) for ((x) = (c).begin(); (x) != (c).end(); (x)++)
#define fo0(i, n) for (i = 0; i < n; i++)
#define fo1 (i, n) for (i = 1; i <= n; i++)
#define rfo(i, n) for (i = n - 1; i >= 0; i--)
#define rfor(i, n) for (i = n; i > 0; i--)
signed main() {
  string s;
  cin >> s;
  int n = s.length(), i, current = 0, ans = 0;
  vi prefix_mod(100005, 0);
  prefix_mod[0] = 1;
  for (int i = 1; i <= n; i++) {
    prefix_mod[i] = (prefix_mod[i - 1] * 10) % 2019;
  }
  vi rem(2019, 0);
  rfo(i, n) {
    current = (current + ((s[i] - '0') * prefix_mod[n - i - 1]) % 2019) % 2019;
    rem[current]++;
  }
  ans += rem[0];
  fo0(i, 2019) { ans += (((rem[i]) * (rem[i] - 1)) / 2); }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define MOD = 998244353;
#define int long long int
#define double long double
#define inf (int)(1e15)
#define all(x) (x).begin(), (x).end()
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define isYes(x) printf("%s\n", (x) ? "Yes" : "No")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define isIn(x, y, h, w) (x >= 0 && x < h && y >= 0 && y < w)
#define pair pair<int, int>
typedef vector<int> vi;   // Vector of long long
typedef vector<vi> vvi;   // Vector of vi
typedef vector<pair> vii; // Vector of pairs
typedef vector<vii> vvii; // Vector of Vector of pairs
typedef vector<bool> vb;  // Vector of bool
#define pq                                                                     \
  priority_queue // Max heap (To convert to min heap, use negative sign before
                 // every value)
#define ff first // For pairs
#define ss second
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, -1, 0, 1};
const int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1},
          dy8[] = {1, -1, 1, 0, -1, 1, -0, -1};
#define testcases(t)                                                           \
  int(t);                                                                      \
  cin >> (t);                                                                  \
  while ((t)--)
#define range(c, r) (c).begin(), (c).begin() + (r) // Mainly used in sorting
#define present(c, x) ((c).find(x) != (c).end())   // for sets, maps, multi-maps
#define cpresent(c, x) (find(all(c), x) != (c).end()) // for vectors
#define run(x, c) for ((x) = (c).begin(); (x) != (c).end(); (x)++)
#define fo0(i, n) for (i = 0; i < n; i++)
#define fo1 (i, n) for (i = 1; i <= n; i++)
#define rfo(i, n) for (i = n - 1; i >= 0; i--)
#define rfor(i, n) for (i = n; i > 0; i--)
signed main() {
  string s;
  cin >> s;
  int n = s.length(), i, current = 0, ans = 0;
  vi prefix_mod(200005, 0);
  prefix_mod[0] = 1;
  for (int i = 1; i <= n; i++) {
    prefix_mod[i] = (prefix_mod[i - 1] * 10) % 2019;
  }
  vi rem(2019, 0);
  rfo(i, n) {
    current = (current + ((s[i] - '0') * prefix_mod[n - i - 1]) % 2019) % 2019;
    rem[current]++;
  }
  ans += rem[0];
  fo0(i, 2019) { ans += (((rem[i]) * (rem[i] - 1)) / 2); }
  cout << ans << endl;
  return 0;
}