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

/*----------------
     Smit Patel
     DA-IICT
----------------*/
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>,
// rb_tree_tag,tree_order_statistics_node_update> #define ordered_set tree<int,
// null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ins insert
#define fori(i, a, n) for (ll i = a; i < n; i++)
#define ford(i, a, n) for (int i = a; i > n; i--)
#define clr(a, b) memset(a, b, sizeof(a))
#define deb(x) cout << #x << " : " << x << endl;
#define debug(x, y)                                                            \\
  cout << #x << " : " << x << "  " << #y << " : " << y << endl;
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define bp __builtin_popcount
#define mod 1000000007
#define eps 1e-6
#define infi 1000000002
#define infll 1e18 + 5
#define N 200005
#define LN 23

typedef long double ld;
typedef long long ll;
typedef map<ll, ll> mll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef set<ll> sll;

ll choose(ll n, ll k);
bool isprime(ll n);
ll power(ll x, ll y, ll p);
ll power(ll x, ll y);
ll gcd(ll a, ll b);

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  ll n = s.length();
  ll cnt = 0;
  ll dp[2020] = {}, tmp[2020] = {};
  fori(i, 0, n) {
    ll x = s[i] - '0';
    fori(j, 0, 2019) {
      ll y = (x + (10 * j)) % 2019;
      tmp[y] += dp[j];
    }
    fori(j, 0, 2019) dp[j] = tmp[j], tmp[j] = 0;
    dp[x]++;
    // fori(j,0,200) cout<<dp[j]<<" ";
    // cout<<endl;
    cnt += dp[0];
  }
  cout << cnt << "\\n";
  return 0;
}

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

ll choose(ll n, ll k) {
  if (k == 0)
    return 1;
  return (n * choose(n - 1, k - 1)) / k;
}

bool isprime(ll n) {
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0)
      return false;
  }
  return true;
}

ll power(ll x, ll y, ll p) {
  ll res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}

ll power(ll x, ll y) {
  ll res = 1;
  while (y > 0) {
    if (y & 1)
      res = res * x;
    y = y >> 1;
    x = x * x;
  }
  return res;
}


Error: -11

Fixed submission:

/*----------------
     Smit Patel
     DA-IICT
----------------*/
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>,
// rb_tree_tag,tree_order_statistics_node_update> #define ordered_set tree<int,
// null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ins insert
#define fori(i, a, n) for (int i = a; i < n; i++)
#define ford(i, a, n) for (int i = a; i > n; i--)
#define clr(a, b) memset(a, b, sizeof(a))
#define deb(x) cout << #x << " : " << x << endl;
#define debug(x, y)                                                            \\
  cout << #x << " : " << x << "  " << #y << " : " << y << endl;
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define bp __builtin_popcount
#define mod 1000000007
#define eps 1e-6
#define infi 1000000002
#define infll 1e18 + 5
#define N 200005
#define LN 23

typedef long double ld;
typedef long long ll;
typedef map<ll, ll> mll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef set<ll> sll;

ll choose(ll n, ll k);
bool isprime(ll n);
ll power(ll x, ll y, ll p);
ll power(ll x, ll y);
ll gcd(ll a, ll b);

bool m[N][2019];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  ll n = s.length();
  ll cnt = 0;
  fori(i, 0, n) {
    ll x = 0;
    ll y = 0;
    fori(j, i, i + 2019) {
      x = (10 * x) + (s[j] - '0');
      x %= 2019;
      if (m[j][x])
        break;
      m[j][x] = 1;
      if (x == 0)
        y++;
    }
    cnt += (y * (y + 1)) / 2;
  }
  cout << cnt << "\\n";
  return 0;
}

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

ll choose(ll n, ll k) {
  if (k == 0)
    return 1;
  return (n * choose(n - 1, k - 1)) / k;
}

bool isprime(ll n) {
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0)
      return false;
  }
  return true;
}

ll power(ll x, ll y, ll p) {
  ll res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}

ll power(ll x, ll y) {
  ll res = 1;
  while (y > 0) {
    if (y & 1)
      res = res * x;
    y = y >> 1;
    x = x * x;
  }
  return res;
}