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

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

int main() {
  int n, b;
  cin >> n;
  int a[35];
  a[0] = 1;
  for (int i = 1; i < 33; i++) {
    a[i] = a[i - 1] * (-2);
    // cout<<a[i]<<endl;
  }
  vector<int> ans;
  for (int i = 1; i < 33; i++) {
    if (n % a[i] == 0)
      ans.push_back(0);
    else {
      ans.push_back(1);
      n -= a[i - 1];
    }
    if (n == 0)
      break;
  }
  for (int i = ans.size() - 1; i >= 0; i--) {
    cout << ans[i];
  }
  cout << endl;
  return 0;
}


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

int main() {
  int n, b;
  cin >> n;
  int a[35];
  a[0] = 1;
  for (int i = 1; i < 32; i++) {
    a[i] = a[i - 1] * (-2);
    // cout<<a[i]<<endl;
  }
  vector<int> ans;
  for (int i = 1; i < 33; i++) {
    if (n % a[i] == 0)
      ans.push_back(0);
    else {
      ans.push_back(1);
      n -= a[i - 1];
    }
    if (n == 0)
      break;
  }
  for (int i = ans.size() - 1; i >= 0; i--) {
    cout << ans[i];
  }
  cout << endl;
  return 0;
}
Problem p03286 (C++)

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64, i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

i64 n;
void solve() {
  cin >> n;

  string s;
  int i = 0;
  while (n) {
    if (n >> i & 1) {
      s = '1' + s;
      n += (1 << i) * (-1 + 2 * (i & 1));
    } else {
      s = '0' + s;
    }
    i++;
  }
  if (s.size() == 0)
    cout << 0 << endl;
  else
    cout << s << endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }

  return 0;
}

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64, i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

i64 n;
void solve() {
  cin >> n;

  string s;
  int i = 0;
  while (n) {
    if (n >> i & 1) {
      s = '1' + s;
      n += (1LL << i) * (-1 + 2 * (i & 1));
    } else {
      s = '0' + s;
    }
    i++;
  }
  if (s.size() == 0)
    cout << 0 << endl;
  else
    cout << s << endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }

  return 0;
}
Problem p03286 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vt<T>>;
template <class T> using ttt = tuple<T, T>;
using tii = tuple<int, int>;
using vi = vector<int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(), (a).end()
#define FST first
#define SEC second
#define DEB cerr << "!" << endl
#define SHOW(a, b) cerr << (a) << " " << (b) << endl
#define DIV int(1e9 + 7)
const int INF = (INT_MAX / 2);
const ll LLINF = (LLONG_MAX / 2);
const double eps = 1e-8;
// const double PI = M_PI;
inline ll pow(ll x, ll n, ll m) {
  ll r = 1;
  while (n > 0) {
    if ((n & 1) == 1)
      r = r * x % m;
    x = x * x % m;
    n >>= 1;
  }
  return r % m;
}
inline ll lcm(ll d1, ll d2) { return d1 / __gcd(d1, d2) * d2; }

/*Coding Space*/
int main() {
  ll n;
  cin >> n;
  if (n == 0) {
    cout << 0 << endl;
    return 0;
  }
  string s = "";
  int d = 1;
  while (n != 0) {
    // cerr << n << " " << d << " " << s << endl;
    if (n % (d * 2) == 0)
      s += '0';
    else {
      s += '1';
      n -= d;
    }
    d *= -2;
  }
  reverse(ALL(s));
  cout << s << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vt<T>>;
template <class T> using ttt = tuple<T, T>;
using tii = tuple<int, int>;
using vi = vector<int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(), (a).end()
#define FST first
#define SEC second
#define DEB cerr << "!" << endl
#define SHOW(a, b) cerr << (a) << " " << (b) << endl
#define DIV int(1e9 + 7)
const int INF = (INT_MAX / 2);
const ll LLINF = (LLONG_MAX / 2);
const double eps = 1e-8;
// const double PI = M_PI;
inline ll pow(ll x, ll n, ll m) {
  ll r = 1;
  while (n > 0) {
    if ((n & 1) == 1)
      r = r * x % m;
    x = x * x % m;
    n >>= 1;
  }
  return r % m;
}
inline ll lcm(ll d1, ll d2) { return d1 / __gcd(d1, d2) * d2; }

/*Coding Space*/
int main() {
  ll n;
  cin >> n;
  if (n == 0) {
    cout << 0 << endl;
    return 0;
  }
  string s = "";
  ll d = 1;
  while (n != 0) {
    // cerr << n << " " << d << " " << s << endl;
    if (n % (d * 2) == 0)
      s += '0';
    else {
      s += '1';
      n -= d;
    }
    d *= -2;
  }
  reverse(ALL(s));
  cout << s << endl;
}
Problem p03286 (C++)

Buggy submission (status: Runtime Error):
//
//  main.cpp
//  CoderTest
//
//  Created by yuya on 2019/07/25.
//  Copyright © 2019 yuya. All rights reserved.
//

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main() {

  ll N;
  cin >> N;
  int p = log2(abs(N)) + 2;

  //    cout << p << endl;

  string S(p, '0');
  ll v;
  for (int i = 0; i < p; i++) {
    //        cout << N << endl;
    v = pow(-2, i);
    if (abs(N) % (2 * abs(v)) != 0) {
      S[p - i - 1] = '1';
      N -= v;
    }
    //        cout << v << endl << N << endl << endl;
  }
  //    cout << N << endl;
  int flag = 0;
  for (int i = 0; i < p; i++) {
    if (S[i] == '1')
      flag = 1;
    if (flag)
      cout << S[i];
  }
  cout << endl;

  return 0;
}


Fixed submission:
//
//  main.cpp
//  CoderTest
//
//  Created by yuya on 2019/07/25.
//  Copyright © 2019 yuya. All rights reserved.
//

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main() {

  ll N;
  cin >> N;
  if (N == 0) {
    cout << 0 << endl;
    return 0;
  }
  int p = (log2(abs(N)) + 1) * 2;

  //    cout << p << endl;

  string S(p, '0');
  ll v;
  for (int i = 0; i < p; i++) {
    //        cout << N << endl;
    v = pow(-2, i);
    if (abs(N) % (2 * abs(v)) != 0) {
      S[p - i - 1] = '1';
      N -= v;
    }
    //        cout << v << endl << N << endl << endl;
  }
  //    cout << N << endl;
  int flag = 0;
  for (int i = 0; i < p; i++) {
    if (S[i] == '1')
      flag = 1;
    if (flag)
      cout << S[i];
  }
  cout << endl;

  return 0;
}
Problem p03286 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <vector>
using namespace std;

#define abs(N) ((N > 0) ? N : -1 * N)
#define print(S) (cout << S)
#define println(S) (cout << S << endl)

void vdump(vector<int> v) {
  for (auto itr = v.begin(); itr != v.end(); ++itr) {
    print(*itr);
  }
  println("");
}

int calc(vector<int> v) {
  int p = 1;
  int sum = 0;
  for (auto itr = v.end(); itr != v.begin(); --itr) {
    sum += *(itr - 1) * p;
    p *= -2;
  }
  return sum;
}

int main(int argc, char const *argv[]) {
  int N, p = 1, ap, e = 0, diff = 0, cur;
  vector<int> v;
  cin >> N;

  if (N == 0) {
    println(0);
    return 0;
  }
  cur = 0;
  diff = N - cur;
  while (N != cur) {
    int d;
    diff = N - cur;
    d = (abs(diff) % abs(p * 2) == 0) ? 0 : 1;
    // printf("%d,%d,%d,%d,%d\n",N,cur,diff,p,d);
    cur += d * p;
    v.insert(v.begin(), d);
    // vdump(v);
    p *= -2;
    e++;
  }
  vdump(v);

  return 0;
}


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

#define abs(N) ((N > 0) ? N : -1 * N)
#define print(S) (cout << S)
#define println(S) (cout << S << endl)

void vdump(vector<int> v) {
  for (auto itr = v.begin(); itr != v.end(); ++itr) {
    print(*itr);
  }
  println("");
}

int calc(vector<int> v) {
  int p = 1;
  int sum = 0;
  for (auto itr = v.end(); itr != v.begin(); --itr) {
    sum += *(itr - 1) * p;
    p *= -2;
  }
  return sum;
}

int main(int argc, char const *argv[]) {
  long N, p = 1, ap, e = 0, diff = 0, cur;
  vector<int> v;
  cin >> N;

  if (N == 0) {
    println(0);
    return 0;
  }
  cur = 0;
  diff = N - cur;
  while (N != cur) {
    int d;
    diff = N - cur;
    d = (abs(diff) % abs(p * 2) == 0) ? 0 : 1;
    // printf("%d,%d,%d,%d,%d\n",N,cur,diff,p,d);
    cur += d * p;
    v.insert(v.begin(), d);
    // vdump(v);
    p *= -2;
    e++;
  }
  vdump(v);

  return 0;
}
Problem p03286 (C++)

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

int n, x = 2863311530;

int b(long d) {
  if (d) {
    b(d >> 1);
    return printf("%d", d & 1);
  }
}

int main() {
  cin >> n;
  n ? b((n + x) ^ x) : puts("0");
}

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

long n, x = 733007751850;

int b(long d) {
  if (d) {
    b(d >> 1);
    return printf("%d", d & 1);
  }
}

int main() {
  cin >> n;
  n ? b((n + x) ^ x) : puts("0");
}
Problem p03286 (C++)

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

ll N;

int main(void) {

  cin >> N;

  string s = (N == 0) ? "0" : "";
  int base = 1;
  while (N != 0) {
    if (N % (base * 2) == 0) {
      s = "0" + s;
    } else {
      s = "1" + s;
      N -= base;
    }
    base *= -2;
  }
  cout << s << endl;

  return 0;
}

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

ll N;

int main(void) {

  cin >> N;

  string s = (N == 0) ? "0" : "";
  ll base = 1;
  while (N != 0) {
    if (N % (base * 2) == 0) {
      s = "0" + s;
    } else {
      s = "1" + s;
      N -= base;
    }
    base *= -2;
  }
  cout << s << endl;

  return 0;
}
Problem p03286 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, a, b) for (int i = a; i < (b); ++i)
#define reprev(i, n) for (int i = n - 1; i >= 0; --i)
#define reprrev(i, a, b) for (int i = b - 1; i >= (a); --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  cout << fixed << setprecision(10);

  int N;
  cin >> N;
  if (N == 0) {
    cout << "0" << endl;
    return 0;
  }

  int base = 1;

  string ans = "";
  while (N != 0) {
    // cout << "base " << base << endl;
    // int modc = abs(N % (base * 2));
    // cout << modc << endl;
    if (abs(N % (base * 2)) == base) {
      ans += '1';
      N -= base * pow(-1, int(ans.size() + 1));
      // cout << "new N " << N << endl;
    } else {
      ans += '0';
    }
    base *= 2;
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
  return 0;
}
/*

123456789
11000101011001101110100010101
11000101011001101110100010101
*/


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, a, b) for (int i = a; i < (b); ++i)
#define reprev(i, n) for (int i = n - 1; i >= 0; --i)
#define reprrev(i, a, b) for (int i = b - 1; i >= (a); --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  cout << fixed << setprecision(10);

  int N;
  cin >> N;
  if (N == 0) {
    cout << "0" << endl;
    return 0;
  }

  ll base = 1;

  string ans = "";
  while (N != 0) {
    // cout << "base " << base << endl;
    // int modc = abs(N % (base * 2));
    // cout << modc << endl;
    if (abs(N % (base * 2)) == base) {
      ans += '1';
      N -= base * pow(-1, int(ans.size() + 1));
      // cout << "new N " << N << endl;
    } else {
      ans += '0';
    }
    base *= 2;
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
  return 0;
}
/*

123456789
11000101011001101110100010101
11000101011001101110100010101
*/
Problem p03286 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MAX_N 100000
#define MAX_M 100000
const int MAX = 10000000;
const int MOD = 1000000007;
#define vec vector<int>
#define vecll vector<ll>
#define vecllvec vector<vector<ll>>
#define vecb vector<bool>
#define vecbvecb vector<vector<bool>>
#define vecst vector<string>
#define vecch vector<char>
#define vecf vector<float>
#define vecvec vector<vector<int>>
#define vecHvec vector<vector<char>>
#define all(x) (x).begin(), (x).end()
const int INF = 1e9;
#define PI 3.141592653589793
// cout << setprecision(15) << std::fixed;
int main() {
  int n;
  cin >> n;
  vecch s;
  if (n == 0) {
    cout << 0 << endl;
    exit(1);
  }
  bool che = true;
  while (che) {
    int k = n % (-2);
    if (k == 0) {
      s.push_back('0');
    } else {
      s.push_back('1');
      n--;
    }
    n /= -2;
    if (n == 0)
      che = false;
  }
  reverse(all(s));
  for (int i = 0; i < s.size(); i++)
    cout << s[i];
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MAX_N 100000
#define MAX_M 100000
const int MAX = 10000000;
const int MOD = 1000000007;
#define vec vector<int>
#define vecll vector<ll>
#define vecllvec vector<vector<ll>>
#define vecb vector<bool>
#define vecbvecb vector<vector<bool>>
#define vecst vector<string>
#define vecch vector<char>
#define vecf vector<float>
#define vecvec vector<vector<int>>
#define vecHvec vector<vector<char>>
#define all(x) (x).begin(), (x).end()
const int INF = 1e9;
#define PI 3.141592653589793
// cout << setprecision(15) << std::fixed;
int main() {
  int n;
  cin >> n;
  vecch s;
  if (n == 0) {
    cout << 0 << endl;
    return 0;
  }
  bool che = true;
  while (che) {
    int k = n % (-2);
    if (k == 0) {
      s.push_back('0');
    } else {
      s.push_back('1');
      n--;
    }
    n /= -2;
    if (n == 0)
      che = false;
  }
  reverse(all(s));
  for (int i = 0; i < s.size(); i++)
    cout << s[i];
}
Problem p03286 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

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

  vector<char> s;
  while (x != 0) {
    if (x % 2 == 0) {
      s.push_back('0');
      x /= (-2);
    } else {
      s.push_back('1');
      x = (x - 1) / (-2);
    }
  }
  for (auto i = s.end() - 1; i >= s.begin(); i--) {
    cout << (*i);
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

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

  vector<char> s;
  if (x == 0) {
    cout << "0";
    return 0;
  }
  while (x != 0) {
    if (x % 2 == 0) {
      s.push_back('0');
      x /= (-2);
    } else {
      s.push_back('1');
      x = (x - 1) / (-2);
    }
  }
  for (auto i = s.end() - 1; i >= s.begin(); i--) {
    cout << (*i);
  }

  return 0;
}
Problem p03286 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int n;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  string ret = "";
  int x = 1;
  while (n != 0) {
    if (n % abs(2 * x) != 0)
      ret = '1' + ret, n -= x;
    else
      ret = '0' + ret;
    x *= -2;
  }
  if (ret.length() == 0)
    ret = '0';
  cout << ret << "\n";
  return 0;
}


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

int n;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  string ret = "";
  ll x = 1l;
  while (n != 0) {
    if (n % abs(2 * x) != 0)
      ret = '1' + ret, n -= x;
    else
      ret = '0' + ret;
    x *= -2;
  }
  if (ret.length() == 0)
    ret = '0';
  cout << ret << "\n";
  return 0;
}
Problem p03287 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
// atoi : atoi(変数名.c_str())
// to_string(数値)
// %0桁数d とすると表示桁数が「桁数」に満たない場合に0埋めされる
// find(): int i = 変数名.find(“文字列”) 何番目にあるかを得る
// cout << (条件 ? "Yes" : "No") << endl;
// printf("%02d:%02d:%02d",hour,minute,second);
// 降順 sort(a.begin(),a.end(),greater<int>());
// bitset<ビット数> 変数名;  // すべてのビットが0の状態で初期化される
// bitset<ビット数> 変数名("ビット列");  // 指定したビット列で初期化される
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  long n, m;
  cin >> n >> m;
  vector<long> sum(n + 1);
  sum.at(0) = 0;
  rep(i, n) {
    long a;
    cin >> a;
    sum.at(i + 1) = sum.at(i) + a;
  }
  map<long, long> mp;
  rep(i, n + 1) {
    long tmp = sum.at(i) % m;
    if (mp.count(tmp))
      mp.at(tmp)++;
    else
      mp[tmp] = 1;
  }
  long ans = 0;
  rep(i, m) {
    if (mp.count(i)) {
      long tmp = mp.at(i) * (mp.at(i) - 1) / 2;
      ans += tmp;
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
// atoi : atoi(変数名.c_str())
// to_string(数値)
// %0桁数d とすると表示桁数が「桁数」に満たない場合に0埋めされる
// find(): int i = 変数名.find(“文字列”) 何番目にあるかを得る
// cout << (条件 ? "Yes" : "No") << endl;
// printf("%02d:%02d:%02d",hour,minute,second);
// 降順 sort(a.begin(),a.end(),greater<int>());
// bitset<ビット数> 変数名;  // すべてのビットが0の状態で初期化される
// bitset<ビット数> 変数名("ビット列");  // 指定したビット列で初期化される
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  long n, m;
  cin >> n >> m;
  vector<long> sum(n + 1);
  sum.at(0) = 0;
  rep(i, n) {
    long a;
    cin >> a;
    sum.at(i + 1) = sum.at(i) + a;
  }
  map<long, long> mp;
  rep(i, n + 1) {
    long tmp = sum.at(i) % m;
    if (mp.count(tmp))
      mp.at(tmp)++;
    else
      mp[tmp] = 1;
  }
  long ans = 0;
  rep(i, n + 1) {
    long tmp1 = sum.at(i) % m;
    if (mp.count(tmp1)) {
      long tmp2 = mp.at(tmp1) * (mp.at(tmp1) - 1) / 2;
      ans += tmp2;
      mp.erase(tmp1);
    }
  }
  cout << ans << endl;
}
Problem p03287 (C++)

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  ll ans = 0;

  vector<ll> sum(n + 1);
  rep(i, n + 1) { sum[i + 1] = sum[i] + a[i]; }

  map<int, ll> count;
  rep(i, n + 1) { ++count[sum[i] % m]; }

  for (auto it = count.begin(); it != count.end(); ++it) {
    ans += (it->second) * (it->second - 1) / 2;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, N) for (ll(i) = 0; (i) < (N); (i)++)
const int mod = 1000000007;

int main() {
  int n, m;
  cin >> n >> m;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  ll ans = 0;

  vector<ll> sum(n + 1);
  rep(i, n) { sum[i + 1] = sum[i] + a[i]; }

  map<int, ll> count;
  rep(i, n + 1) { ++count[sum[i] % m]; }

  for (auto it = count.begin(); it != count.end(); ++it) {
    ans += (it->second) * (it->second - 1) / 2;
  }
  cout << ans << endl;
}
Problem p03287 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#define INF 2147483647
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
int main() {
  int N, M;
  cin >> N >> M;
  vector<ll> A(N, 0), An(N + 1, 0);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  for (int i = 1; i < N + 1; i++)
    An[i] = An[i - 1] + A[i - 1];
  ll ans = 0;
  for (int i = 0; i < N + 1; i++)
    for (int j = i + 1; j < N + 1; j++) {
      if ((An[j] - An[i]) % M == 0)
        ans++;
    }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#define INF 2147483647
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
int main() {
  int N, M;
  cin >> N >> M;
  vector<ll> A(N, 0), An(N + 1, 0);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  for (int i = 1; i < N + 1; i++)
    An[i] = An[i - 1] + A[i - 1];
  ll ans = 0;
  unordered_map<int, int> mp;
  for (int i = 0; i < N + 1; i++) {
    ans += mp[An[i] % M];
    mp[An[i] % M]++;
  }
  cout << ans << endl;
  return 0;
}
Problem p03287 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define _rep(i, n) _repl(i, 0, n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x), end(x)
#define uniq(x) sort(all(x)), (x).erase(unique(all(x)), end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string) { cerr << endl; }
template <class H, class... T> void _dbg(string s, H h, T... t) {
  int l = s.find(',');
  cerr << s.substr(0, l) << " = " << h << ", ";
  _dbg(s.substr(l + 1), t...);
}
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U> &p) {
  o << "(" << p.first << "," << p.second << ")";
  return o;
}
template <class T> ostream &operator<<(ostream &o, const vector<T> &v) {
  o << "[";
  for (T t : v) {
    o << t << ",";
  }
  o << "]";
  return o;
}
#else
#define dbg(...)                                                               \
  {}
#endif

int main() {
  int n, m;
  cin >> n >> m;
  vector<long> v(n);
  rep(i, n) cin >> v[i];

  vector<long> acc(n);
  acc[0] = v[0];
  rep(i, 1, n) acc[i] = acc[i - 1] + v[i];

  vector<int> cnt(m, 0);
  rep(i, n) cnt[acc[i] % m]++;

  long ans = cnt[0];
  // dbg(cnt);
  rep(i, n) {
    cnt[acc[i] % m]--;
    ans += cnt[acc[i] % m];
    // dbg(cnt,ans);
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define _rep(i, n) _repl(i, 0, n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x), end(x)
#define uniq(x) sort(all(x)), (x).erase(unique(all(x)), end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string) { cerr << endl; }
template <class H, class... T> void _dbg(string s, H h, T... t) {
  int l = s.find(',');
  cerr << s.substr(0, l) << " = " << h << ", ";
  _dbg(s.substr(l + 1), t...);
}
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U> &p) {
  o << "(" << p.first << "," << p.second << ")";
  return o;
}
template <class T> ostream &operator<<(ostream &o, const vector<T> &v) {
  o << "[";
  for (T t : v) {
    o << t << ",";
  }
  o << "]";
  return o;
}
#else
#define dbg(...)                                                               \
  {}
#endif

int main() {
  int n, m;
  cin >> n >> m;
  vector<long> v(n);
  rep(i, n) cin >> v[i];

  vector<long> acc(n);
  acc[0] = v[0];
  rep(i, 1, n) acc[i] = acc[i - 1] + v[i];

  map<int, int> cnt;
  rep(i, n) cnt[acc[i] % m]++;

  long ans = cnt[0];
  // dbg(cnt);
  rep(i, n) {
    cnt[acc[i] % m]--;
    ans += cnt[acc[i] % m];
    // dbg(cnt,ans);
  }

  cout << ans << endl;

  return 0;
}
Problem p03287 (Python)

Buggy submission (status: Runtime Error):
n, m = map(int, input().split())
a = list(map(int, input().split()))

sumList = [0] * n
sumList[0] = a[0] % m
number = {}

for i in range(1, n):
    sumList[i] = (sumList[i - 1] + a[i]) % m
    number[sumList[i]] = 0

for i in range(n):
    number[sumList[i]] += 1

ans = 0

for key, value in number.items():
    ans += value * (value - 1) // 2
    if key == 0:
        ans += value

print(ans)


Fixed submission:
n, m = map(int, input().split())
a = list(map(int, input().split()))

sumList = [0] * n
sumList[0] = a[0] % m
number = {}
number[sumList[0]] = 0

for i in range(1, n):
    sumList[i] = (sumList[i - 1] + a[i]) % m
    number[sumList[i]] = 0

for i in range(n):
    number[sumList[i]] += 1

ans = 0

for key, value in number.items():
    ans += value * (value - 1) // 2
    if key == 0:
        ans += value

print(ans)
Problem p03287 (C++)

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

#define int long long
#define pii pair<int, int>
#define X first
#define Y second

const int mod = (int)1e9 + 7;
const int inf = (int)1e18;

using namespace std;

const int N = 1e5 + 5;
int arr[N];

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int n, m;
  cin >> n >> m;
  map<int, int> mp;
  mp[0] = 1;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    arr[i] += arr[i - 1];
    ans += mp[arr[i] % m];
    mp[arr[i] % m]++;
  }
  cout << ans << "\n";
  return 0;
}


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

#define int long long
#define pii pair<int, int>
#define X first
#define Y second

const int mod = (int)1e9 + 7;
const int inf = (int)1e18;

using namespace std;

const int N = 1e5 + 5;
int arr[N];

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  map<int, int> mp;
  mp[0] = 1;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    arr[i] += arr[i - 1];
    ans += mp[arr[i] % m];
    mp[arr[i] % m]++;
  }
  cout << ans << "\n";
  return 0;
}
Problem p03287 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
typedef long long ll;
int inf = 1000000000;
template <typename T> T GCD(T a, T b) {
  while (max(a, b) % min(a, b)) {
    if (a > b)
      a = a % b;
    else
      b = b % a;
  }
  return min(a, b);
}
template <typename T> T LCM(T a, T b) { return a / GCD(a, b) * b; }
ll ruiseki[100010], ruiseki2[100010];
int main() {
  ll n, m, ans = 0;
  cin >> n >> m >> ruiseki[0];
  ruiseki[0] %= m;
  ruiseki2[0] = ruiseki[0];
  for (int i = 1; i < n; i++) {
    int a;
    cin >> a;
    ruiseki[i] = a + ruiseki[i - 1];
    ruiseki[i] %= m;
    ruiseki2[i] = ruiseki[i];
  }
  sort(ruiseki, ruiseki + n);
  for (int i = 0; i < n; i++) {
    ll f = upper_bound(ruiseki, ruiseki + n, ruiseki[i]) -
           lower_bound(ruiseki, ruiseki + n, ruiseki[i]);
    ans += max((f * (f - 1)) / 2, (ll)0);
    while (ruiseki[i] == ruiseki[i + 1]) {
      i++;
      if (i == n - 1)
        break;
    }
  }
  for (int i = 0; i < n; i++) {
    if (ruiseki[i] == 0)
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
typedef long long ll;
int inf = 1000000000;
template <typename T> T GCD(T a, T b) {
  while (max(a, b) % min(a, b)) {
    if (a > b)
      a = a % b;
    else
      b = b % a;
  }
  return min(a, b);
}
template <typename T> T LCM(T a, T b) { return a / GCD(a, b) * b; }
ll ruiseki[100010], ruiseki2[100010];
int main() {
  ll n, m, ans = 0;
  cin >> n >> m >> ruiseki[0];
  ruiseki[0] %= m;
  ruiseki2[0] = ruiseki[0];
  for (int i = 1; i < n; i++) {
    int a;
    cin >> a;
    ruiseki[i] = a + ruiseki[i - 1];
    ruiseki[i] %= m;
    ruiseki2[i] = ruiseki[i];
  }
  sort(ruiseki, ruiseki + n);
  for (int i = 0; i < n; i++) {
    ll f = upper_bound(ruiseki, ruiseki + n, ruiseki[i]) -
           lower_bound(ruiseki, ruiseki + n, ruiseki[i]);
    ans += max((f * (f - 1)) / 2, (ll)0);
    if (i == n - 1)
      break;
    while (ruiseki[i] == ruiseki[i + 1]) {
      i++;
      if (i == n - 1)
        break;
    }
  }
  for (int i = 0; i < n; i++) {
    if (ruiseki[i] == 0)
      ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p03287 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for (int i = int(m); i < int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1 << 30;
const ll INFll = 1ll << 62;
const ld EPS = 1e-10;
const int MOD = int(1e9) + 7;
template <typename T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  ll n, m;
  cin >> n >> m;
  Vll S(n + 1);
  rep(i, n) {
    int a;
    cin >> a;
    S[i + 1] = (S[i] + a) % m;
  };

  V cnt(m);
  ll ans = 0;
  rep(i, n + 1) {
    ans += cnt[S[i]];
    ++cnt[S[i]];
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for (int i = int(m); i < int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1 << 30;
const ll INFll = 1ll << 62;
const ld EPS = 1e-10;
const int MOD = int(1e9) + 7;
template <typename T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  ll n, m;
  cin >> n >> m;
  Vll S(n + 1);
  rep(i, n) {
    int a;
    cin >> a;
    S[i + 1] = (S[i] + a) % m;
  };

  map<int, int> cnt;
  ll ans = 0;
  rep(i, n + 1) {
    ans += cnt[S[i]];
    ++cnt[S[i]];
  }
  cout << ans << endl;
  return 0;
}
Problem p03287 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main() {
  int n;
  ll m;
  cin >> n >> m;
  ll a[n], s[n + 1];
  map<ll, ll> d;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  s[0] = 0;
  d[s[0]]++;
  for (int i = 1; i <= n; i++) {
    s[i] = (s[i - 1] + a[i - 1]) % m;
    d[s[i]]++;
  }
  ll ans = 0;
  for (ll i = 0; i < m; i++)
    ans += d[i] * (d[i] - 1) / 2;
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main() {
  int n;
  ll m;
  cin >> n >> m;
  ll a[n], s[n + 1];
  map<ll, ll> d;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  s[0] = 0;
  d[s[0]]++;
  for (int i = 1; i <= n; i++) {
    s[i] = (s[i - 1] + a[i - 1]) % m;
    d[s[i]]++;
  }
  ll ans = 0;
  for (map<ll, ll>::iterator it = d.begin(); it != d.end(); it++) {
    ans += it->second * (it->second - 1) / 2;
  }
  cout << ans << endl;
  return 0;
}
Problem p03287 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
#include "LOCAL_DEBUG.hpp"
#endif
#define int long long

signed main() {

  int n, m;
  cin >> n >> m;
  vector<int> a(n + 1);
  for (int i = 0; i < n; i++) {
    cin >> a[i + 1];
  }

  for (int i = 1; i <= n; i++) {
    a[i + 1] += a[i];
  }

  map<int, int> mp;
  int ans = 0;
  for (int i = 0; i <= n; i++) {
    ans += mp[a[i] % m];
    mp[a[i] % m]++;
  }
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
#include "LOCAL_DEBUG.hpp"
#endif
#define int long long

signed main() {

  int n, m;
  cin >> n >> m;
  vector<int> a(n + 1);
  for (int i = 0; i < n; i++) {
    cin >> a[i + 1];
    a[i + 1] += a[i];
  }

  map<int, int> mp;
  int ans = 0;
  for (int i = 0; i <= n; i++) {
    ans += mp[a[i] % m];
    mp[a[i] % m]++;
  }
  cout << ans << endl;

  return 0;
}
Problem p03287 (C++)

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

ll N, M;
const ll MAX_N = 1.0e5 + 100;
ll A[MAX_N];

int main() {
  cin >> N >> M;
  for (int i = 0; i < N; i++)
    cin >> A[i];

  map<ll, ll> cnt;
  cnt[0] = 1;

  ll sum_A[N + 1];
  sum_A[0] = 0;
  for (int i = 1; i <= N; i++) {
    sum_A[i] = sum_A[i - 1] + A[i - 1];

    cnt[sum_A[i] % M]++;
  }

  ll ans = 0;
  for (int i = 0; i < cnt.size(); i++) {
    ans += cnt[i] * (cnt[i] - 1) / 2;
  }

  cout << ans << endl;

  return 0;
}


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

ll N, M;
const ll MAX_N = 1.0e5 + 100;
ll A[MAX_N];

int main() {
  cin >> N >> M;
  for (int i = 0; i < N; i++)
    cin >> A[i];

  map<ll, ll> cnt;
  cnt[0] = 1;

  ll sum_A[N + 1];
  sum_A[0] = 0;
  for (int i = 1; i <= N; i++) {
    sum_A[i] = sum_A[i - 1] + A[i - 1];

    cnt[sum_A[i] % M]++;
  }

  ll ans = 0;
  for (auto i = cnt.begin(); i != cnt.end(); i++) {
    // cout << "key=" << i->first << endl;
    // cout << "val=" << i->second << endl;

    ll val = i->second;

    ans += val * (val - 1) / 2;
  }

  cout << ans << endl;

  return 0;
}
Problem p03287 (Python)

Buggy submission (status: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))

t = {}
c = 0
for a in A:
    c += a
    c %= M
    if c in t:
        t[c] += 1
    else:
        t[c] = 1

result = t[0]
c = 0
for a in A:
    c += a
    c %= M
    t[c] -= 1
    result += t[c]
print(result)


Fixed submission:
N, M = map(int, input().split())
A = list(map(int, input().split()))

t = {}
c = 0
for a in A:
    c += a
    c %= M
    if c in t:
        t[c] += 1
    else:
        t[c] = 1

result = 0
if 0 in t:
    result += t[0]
c = 0
for a in A:
    c += a
    c %= M
    t[c] -= 1
    result += t[c]
print(result)
Problem p03287 (C++)

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

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

  long long n, m;
  cin >> n >> m;
  vector<long long> A(n);
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }

  vector<long long> B(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    B[i] += B[i - 1] + A[i - 1];
  }

  long long ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j <= n; j++) {
      if ((B[j] - B[i]) % m == 0) {
        ans++;
      }
    }
  }

  cout << ans << endl;

  return 0;
}

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

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

  long long n, m;
  cin >> n >> m;
  vector<long long> A(n);
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }

  vector<long long> B(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    B[i] += B[i - 1] + A[i - 1];
  }

  long long ans = 0;
  map<long long, long long> mp;
  for (auto x : B) {
    mp[x % m]++;
  }

  for (auto x : mp) {
    ans += x.second * (x.second - 1) / 2;
  }

  cout << ans << endl;

  return 0;
}
Problem p03287 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1000000007LL;
ll S[10000];
int main() {
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < N; i++)
    cin >> S[i], S[i] %= M;
  for (int i = 1; i < N; i++)
    (S[i] += S[i - 1]) %= M;
  ll ans = 0;
  map<int, int> cnt;
  cnt[S[0]]++;
  if (S[0] == 0)
    ans++;
  for (int i = 1; i < N; i++) {
    ans += cnt[S[i]];
    if (S[i] == 0)
      ans++;
    cnt[S[i]]++;
  }
  cout << ans << endl;
}

Fixed submission:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1000000007LL;
ll S[100000];
int main() {
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < N; i++)
    cin >> S[i], S[i] %= M;
  for (int i = 1; i < N; i++)
    (S[i] += S[i - 1]) %= M;
  ll ans = 0;
  map<int, int> cnt;
  cnt[S[0]]++;
  if (S[0] == 0)
    ans++;
  for (int i = 1; i < N; i++) {
    ans += cnt[S[i]];
    if (S[i] == 0)
      ans++;
    cnt[S[i]]++;
  }
  cout << ans << endl;
}
Problem p03287 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
using ll = long long;
using P = pair<ll, ll>;
ll INF = 1000000007;
// ll INF = 9223372036854775807;
// ll INF = 998244353;

int main() {
  // fasten cin
  cin.tie(0);
  ios::sync_with_stdio(false);
  // implement
  ll n, m;
  cin >> n >> m;
  vi a(n);
  rep(i, n) cin >> a.at(i);
  vi csum(n + 1);
  csum.at(0) = 0;
  for (ll i = 1; i < n + 1; i++)
    csum.at(i) = csum.at(i - 1) + a.at(i - 1);
  for (ll i = 1; i < n + 1; i++)
    csum.at(i) %= m;
  map<ll, ll> mp;
  for (ll i = 1; i < n + 1; i++) {
    if (mp.count(csum.at(i))) {
      mp.at(csum.at(i))++;
    } else {
      mp[csum.at(i)] = 1;
    }
  }
  ll res = 0;
  for (auto it = mp.begin(); it != mp.end(); it++) {
    cerr << "key:" << it->first << " value:" << it->second << endl;
    ll count = it->second;
    res += (count * (count - 1)) / 2;
  }
  res += mp.at(0);
  cout << res << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
using ll = long long;
using P = pair<ll, ll>;
ll INF = 1000000007;
// ll INF = 9223372036854775807;
// ll INF = 998244353;

int main() {
  // fasten cin
  cin.tie(0);
  ios::sync_with_stdio(false);
  // implement
  ll n, m;
  cin >> n >> m;
  vi a(n);
  rep(i, n) cin >> a.at(i);
  vi csum(n + 1);
  csum.at(0) = 0;
  for (ll i = 1; i < n + 1; i++)
    csum.at(i) = csum.at(i - 1) + a.at(i - 1);
  for (ll i = 1; i < n + 1; i++)
    csum.at(i) %= m;
  map<ll, ll> mp;
  for (ll i = 1; i < n + 1; i++) {
    if (mp.count(csum.at(i))) {
      mp.at(csum.at(i))++;
    } else {
      mp[csum.at(i)] = 1;
    }
  }
  ll res = 0;
  for (auto it = mp.begin(); it != mp.end(); it++) {
    cerr << "key:" << it->first << " value:" << it->second << endl;
    ll count = it->second;
    res += (count * (count - 1)) / 2;
  }
  if (mp.count(0))
    res += mp.at(0);
  cout << res << endl;
}
Problem p03287 (C++)

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

using namespace std;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> cnt(m);
  ++cnt[0];
  int sum = 0, ans = 0;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    sum = (sum + a) % m;
    ans += cnt[sum];
    ++cnt[sum];
  }
  cout << ans << '\n';
  return 0;
}

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

using namespace std;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  map<int, int> cnt;
  ++cnt[0];
  int sum = 0, ans = 0;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    sum = (sum + a) % m;
    ans += cnt[sum];
    ++cnt[sum];
  }
  cout << ans << '\n';
  return 0;
}
Problem p03287 (C++)

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

using namespace std;
using ll = long long;

// container util
#define SORT(c) sort((c).begin(), (c).end())

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

const int INF = 1e9;

int main(void) {

  int N, M;
  cin >> N >> M;
  vector<int> A(N);

  REP(i, N) cin >> A[i];

  int ans = 0;
  REP(i, N) {
    ll sum = 0;
    FOR(j, i, N) {
      sum += A[j];
      if (sum % M == 0)
        ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;
using ll = long long;

// container util
#define SORT(c) sort((c).begin(), (c).end())

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

const int INF = 1e9;

int main(void) {

  int N, M;
  cin >> N >> M;
  vector<int> A(N);

  REP(i, N) cin >> A[i];

  map<int, int> mp;
  vector<int> sum(N + 1);
  sum[0] = 0;
  REP(i, N + 1) { sum[i + 1] = (sum[i] + A[i]) % M; }

  ll ans = 0;
  REP(i, N + 1) {
    ans += mp[sum[i]];
    mp[sum[i]]++;
  }

  cout << ans << endl;

  return 0;
}
Problem p03287 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef pair<ll, ll> pl;
typedef pair<int, int> pi;
typedef vector<int> V;

int main() {
  int n, m;
  cin >> n >> m;
  vector<ll> a(n);
  for (auto &v : a)
    cin >> v;
  for (int i = 0; i < n - 1; i++)
    a[i + 1] += a[i];
  for (int i = 0; i < n; i++)
    a[i] %= m;
  vector<ll> x(m, 0);
  for (int i = 0; i < n; i++)
    x[a[i]]++;
  ll sum = x[0];
  for (int i = 0; i < m; i++) {
    sum += x[i] * (x[i] - 1) / 2;
  }
  dump(sum);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef pair<ll, ll> pl;
typedef pair<int, int> pi;
typedef vector<int> V;

int main() {
  int n, m;
  cin >> n >> m;
  vector<ll> a(n);
  for (auto &v : a)
    cin >> v;
  for (int i = 0; i < n - 1; i++)
    a[i + 1] += a[i];
  for (int i = 0; i < n; i++)
    a[i] %= m;
  sort(a.begin(), a.end());
  ll cnt;
  ll sum = 0;
  for (int i = 0; i < n - 1; i++) {
    cnt = 1;
    if (a[i] == 0)
      sum++;
    while (i < n - 1 && a[i] == a[i + 1]) {
      if (a[i + 1] == 0)
        sum++;
      i++;
      cnt++;
    }
    sum += cnt * (cnt - 1) / 2;
  }
  if (n == 1) {
    if (a[0] == 0)
      sum++;
  }
  dump(sum);
  return 0;
}
Problem p03287 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long, long long>
#define all(a) a.begin(), a.end()
#define INF 1000000000000000000
#define set(i) setprecision(i)
using namespace std;

signed main() {
  int n, m;
  cin >> n >> m;
  map<int, int> rem;
  rem[0]++;
  int sum = 0;
  rep(i, n) {
    int a;
    cin >> a;
    sum += a;
    rem[sum % m]++;
  }
  int ans = 0;
  rep(i, rem.size()) { ans += (rem[i] - 1) * rem[i] / 2; }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long, long long>
#define all(a) a.begin(), a.end()
#define INF 1000000000000000000
#define set(i) setprecision(i)
using namespace std;

signed main() {
  int n, m;
  cin >> n >> m;
  map<int, int> rem;
  rem[0]++;
  int sum = 0;
  rep(i, n) {
    int a;
    cin >> a;
    sum += a;
    rem[sum % m]++;
  }
  int ans = 0;
  for (auto i : rem) {
    ans += i.S * (i.S - 1) / 2;
  }
  cout << ans << endl;
}
Problem p03287 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
  int n, m;
  cin >> n >> m;
  int a = 0ll, b = 0ll;
  map<int, int> re;
  re[0]++;
  for (int i = 0; i < n; i++) {
    cin >> a;
    b += a;
    b = (b % m);
    re[b]++;
  }
  int ans = 0ll;
  for (int i = 0; i < m; i++)
    ans += re[i] * (re[i] - 1) / 2;
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
  int n, m;
  cin >> n >> m;
  int a = 0ll, b = 0ll;
  map<int, int> re;
  re[0]++;
  for (int i = 0; i < n; i++) {
    cin >> a;
    b += a;
    b = (b % m);
    re[b]++;
  }
  int ans = 0ll;
  for (auto &&w : re)
    ans += w.second * (w.second - 1) / 2;
  cout << ans << endl;
}
Problem p03287 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <utility>
#include <vector>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); (b) <= i; i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1) * (a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1 << 29)

using namespace std;

#define ld long double
#define ll long long

map<int, int> mpa, mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ll N, M;
  cin >> N >> M;
  // ll M_MAX=1000000001;
  ll N_MAX = 100100;
  ll a[100100];
  ll A;
  a[0] = 0;
  for (int i = 1; i <= N; i++) {
    cin >> A;
    A %= M;
    a[i] = A;
  }
  for (int i = 1; i <= N; i++) {
    a[i] = a[i - 1] + a[i];
    a[i] %= M;
  }
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j <= N; j++) {
      if ((a[j] - a[i]) % M == 0)
        ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <utility>
#include <vector>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); (b) <= i; i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1) * (a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1 << 29)

using namespace std;

#define ld long double
#define ll long long

map<int, int> mpa, mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ll N, M;
  cin >> N >> M;
  // ll M_MAX=1000000001;
  ll N_MAX = 100100;
  ll a[100100];
  ll A;
  a[0] = 0;
  for (int i = 1; i <= N; i++) {
    cin >> A;
    A %= M;
    a[i] = A;
  }
  for (int i = 1; i <= N; i++) {
    a[i] = a[i - 1] + a[i];
    a[i] %= M;
  }
  ll ans = 0;
  map<ll, ll> m;
  for (int i = 0; i <= N; i++) {
    ans += m[a[i]];
    m[a[i]]++;
  }
  cout << ans << endl;
  return 0;
}