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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cctype>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <utility>
#include <vector>

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

typedef long long int ll;
#define ARRAY_MAX 100005
#define MOD 1000000007

int main() {

  ll n;
  cin >> n;
  vector<ll> a(ARRAY_MAX, 0);
  REP(i, n) { cin >> a[i + 1]; }

  REP(i, n + 1) { a[i + 1] += a[i]; }

  map<ll, ll> mp;
  REP(i, n + 1) { mp[a[i]]++; }
  ll ans = 0;
  for (auto itr : mp) {
    // cout << itr.first << " " << itr.second << endl;
    ans += itr.second * (itr.second - 1) / 2;
    // cout << ans << endl;
  }
  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cctype>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <utility>
#include <vector>

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

typedef long long int ll;
#define ARRAY_MAX 200005
#define MOD 1000000007

int main() {

  ll n;
  cin >> n;
  vector<ll> a(ARRAY_MAX, 0);
  REP(i, n) { cin >> a[i + 1]; }

  REP(i, n + 1) { a[i + 1] += a[i]; }

  map<ll, ll> mp;
  REP(i, n + 1) { mp[a[i]]++; }
  ll ans = 0;
  for (auto itr : mp) {
    // cout << itr.first << " " << itr.second << endl;
    ans += itr.second * (itr.second - 1) / 2;
    // cout << ans << endl;
  }
  cout << ans << endl;

  return 0;
}
Problem p03363 (C++)

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

long long n, a[100009], b[100009];

int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    b[i] = b[i - 1] + a[i];
  }
  sort(b, b + n + 1);
  long long c = 1, s = 0;
  for (int i = 1; i <= n; i++) {
    if (b[i] == b[i - 1])
      c++;
    else
      c = 1;
    s += c - 1;
  }
  cout << s << endl;
  return 0;
}

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

long long n, a[200009], b[200009];

int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    b[i] = b[i - 1] + a[i];
  }
  sort(b, b + n + 1);
  long long c = 1, s = 0;
  for (int i = 1; i <= n; i++) {
    if (b[i] == b[i - 1])
      c++;
    else
      c = 1;
    s += c - 1;
  }
  cout << s << endl;
  return 0;
}
Problem p03363 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <map>

using namespace std;

long long acc[100001];

int main() {
  int n;
  long long prev = 0;
  long long total = 0;
  map<long long, int> m;
  m[0] = 1;
  cin >> n;
  for (int i = 0; i < n; i++) {
    long long a;
    cin >> a;
    acc[i] = a + prev;
    if (m.find(acc[i]) == m.end()) {
      m[acc[i]] = 0;
    }

    total += m[acc[i]];
    m[acc[i]]++;
    prev = acc[i];
  }
  cout << total << endl;
  return (0);
}


Fixed submission:
#include <iostream>
#include <map>

using namespace std;

long long acc[200001];

int main() {
  int n;
  long long prev = 0;
  long long total = 0;
  map<long long, int> m;
  m[0] = 1;
  cin >> n;
  for (int i = 0; i < n; i++) {
    long long a;
    cin >> a;
    acc[i] = a + prev;
    if (m.find(acc[i]) == m.end()) {
      m[acc[i]] = 0;
    }

    total += m[acc[i]];
    m[acc[i]]++;
    prev = acc[i];
  }
  cout << total << endl;
  return (0);
}
Problem p03363 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
map<long long, long long> cnt;
long long n, a[100001], ans;
int main() {
  scanf("%lld", &n);
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    a[i] += a[i - 1];
    ans += cnt[a[i]]++;
  }
  printf("%lld", ans + cnt[0]);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
map<long long, long long> cnt;
long long n, a[1000001], ans;
int main() {
  scanf("%lld", &n);
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    a[i] += a[i - 1];
    ans += cnt[a[i]]++;
  }
  printf("%lld", ans + cnt[0]);
  return 0;
}
Problem p03363 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)

int main(int argc, char **argv) {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N;

  long long A[111111], acc = 0, c = 0, x = 0;

  std::cin >> N;

  std::map<long long, int> map;

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

    map[acc += A[i]]++;
  }

  acc = 0;

  for (int i = 0; i < N; i++) {
    if (map.count(acc))
      c += map[acc];

    acc += A[i];

    map[acc]--;
  }

  std::cout << c << std::endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)

int main(int argc, char **argv) {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N;

  long long A[222222], acc = 0, c = 0, x = 0;

  std::cin >> N;

  std::map<long long, int> map;

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

    map[acc += A[i]]++;
  }

  acc = 0;

  for (int i = 0; i < N; i++) {
    if (map.count(acc))
      c += map[acc];

    acc += A[i];

    map[acc]--;
  }

  std::cout << c << std::endl;

  return 0;
}
Problem p03363 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int n;
vector<long long> A(100100, 0);
vector<long long> sum(100100, 0);

int main() {
  cin >> n;
  for (int i = 0; i < n; ++i)
    cin >> A.at(i);

  sum.at(0) = A.at(0);
  for (int i = 1; i < n; ++i) {
    sum.at(i) += sum.at(i - 1) + A.at(i);
  }

  long long cnt = 0;
  map<long long, long long> mp;
  set<long long> st;
  for (int i = 0; i < n; ++i) {
    if (sum.at(i) == 0)
      cnt++;
    mp[sum.at(i)]++;
    st.insert(sum.at(i));
  }

  for (auto itr = st.begin(); itr != st.end(); ++itr) {
    long long mcnt = mp[*itr];
    cnt += (mcnt * (mcnt - 1)) / 2;
  }

  cout << cnt << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int n;
vector<long long> A(200200, 0);
vector<long long> sum(200200, 0);

int main() {
  cin >> n;
  for (int i = 0; i < n; ++i)
    cin >> A.at(i);

  sum.at(0) = A.at(0);
  for (int i = 1; i < n; ++i) {
    sum.at(i) += sum.at(i - 1) + A.at(i);
  }

  long long cnt = 0;
  map<long long, long long> mp;
  set<long long> st;
  for (int i = 0; i < n; ++i) {
    if (sum.at(i) == 0)
      cnt++;
    mp[sum.at(i)]++;
    st.insert(sum.at(i));
  }

  for (auto itr = st.begin(); itr != st.end(); ++itr) {
    long long mcnt = mp[*itr];
    cnt += (mcnt * (mcnt - 1)) / 2;
  }

  cout << cnt << endl;
}
Problem p03363 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep_ll(i, x, n) for (ll i = x; i < (ll)(n); i++)
using namespace std;
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;
const long double PI = (acos(-1));
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
ll mod = 1000000007;
int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, 0, n) cin >> a[i];
  /*vector<int> s(n+1, 0);
  s[0]=0;
  rep(i, 1, n+1) s[i]=s[i-1]+a[i-1];
  int ans=0;
  rep(i, 0, n+1) rep(j, i+1, n+1)if(s[j]-s[i]==0) ans++;*/
  vector<ll> s(n + 1, 0);
  // 部分和はsi-sjで表すsi-sj=0⇒si=sjとなるものを探す
  map<ll, ll> nums;
  rep(i, 0, n + 1) s[i + 1] = s[i] + a[i];
  rep(i, 0, n + 1) nums[s[i]]++; // 和がs[i]になる配列が何個あるか
  ll ans = 0;
  for (auto it : nums) {
    ll num = it.second;
    ans += num * (num - 1) / 2; // numC2
  }
  cout << ans;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep_ll(i, x, n) for (ll i = x; i < (ll)(n); i++)
using namespace std;
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;
const long double PI = (acos(-1));
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
ll mod = 1000000007;
int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, 0, n) cin >> a[i];
  /*vector<int> s(n+1, 0);
  s[0]=0;
  rep(i, 1, n+1) s[i]=s[i-1]+a[i-1];
  int ans=0;
  rep(i, 0, n+1) rep(j, i+1, n+1)if(s[j]-s[i]==0) ans++;*/
  vector<ll> s(n + 1, 0);
  // 部分和はsi-sjで表すsi-sj=0⇒si=sjとなるものを探す
  map<ll, ll> nums;
  rep(i, 0, n) s[i + 1] = s[i] + a[i];
  rep(i, 0, n + 1) nums[s[i]]++; // 和がs[i]になる配列が何個あるか
  ll ans = 0;
  for (auto it : nums) {
    ll num = it.second;
    ans += num * (num - 1) / 2; // numC2
  }
  cout << ans;
  return 0;
}
Problem p03363 (C++)

Buggy submission (status: Runtime Error):
// {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}

using ll = long long;

int N;
ll A[101010];

map<ll, ll> memo;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N;
  for (int j = 0; j < N; ++j)
    cin >> A[j];

  memo[0] = 1;
  ll ans = 0, acc = 0;
  for (int j = 0; j < N; ++j) {
    acc += A[j];
    ans += memo[acc];
    memo[acc]++;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
// {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}

using ll = long long;

int N;
ll A[201010];

map<ll, ll> memo;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N;
  for (int j = 0; j < N; ++j)
    cin >> A[j];

  memo[0] = 1;
  ll ans = 0, acc = 0;
  for (int j = 0; j < N; ++j) {
    acc += A[j];
    ans += memo[acc];
    memo[acc]++;
  }
  cout << ans << endl;
  return 0;
}
Problem p03363 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;

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

  ll n;
  cin >> n;
  ll a[n];
  rep(i, n) cin >> a[i];
  ll ans = 0;
  rep(i, n) {
    ll sum = 0;
    FOR(j, i, n) {
      sum += a[j];
      if (sum == 0)
        ans++;
    }
  }
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;

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

  ll n;
  cin >> n;
  ll a[n];
  rep(i, n) cin >> a[i];
  ll ans = 0;
  ll s[n + 2];
  s[0] = 0;
  FOR(i, 1, n + 1) { s[i] = s[i - 1] + a[i - 1]; }
  s[n + 1] = 1100100100100100100;
  sort(s, s + n + 2);
  ll cnt = 1ll;
  FOR(i, 1, n + 2) {
    if (s[i] == s[i - 1]) {
      cnt++;
    } else {
      ans += cnt * (cnt - 1ll) / 2ll;
      cnt = 1ll;
    }
  }
  cout << ans << endl;

  return 0;
}
Problem p03363 (C++)

Buggy submission (status: Runtime Error):
/*
For Bantako San
By shyyhs.

Using hash to insert and search for a perticular number.
Every insert and search is O(1) ideally.
*/

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
#define ll long long
// #define Hsize 100009
#define Hsize (1 << 16)
#define MAXN 200001
ll sumZ = 0; // sum from the beginning
int Ai;      // This is Ai in the problem, we use it only once so array is not
        // necessary.
int N; // N in the problem

struct T {
  ll number, times;
  T *next;
} hashBucket[MAXN];
int top = 0;
int hashIndex[Hsize];

// x->hash(x)
inline int hashFunc(ll x) { return (x & (0x0000FFFF)); }

// add the current sumZ to the hash table
inline void addToHash(ll sumZ) {
  int HsumZ;
  T *index, *beginP;
  HsumZ = hashFunc(sumZ);
  for (beginP = index = &hashBucket[hashIndex[HsumZ]]; (index->times > 0);
       index = index->next)
    if (index->number == sumZ) {
      index->times++;
      return;
    }
  hashIndex[HsumZ] = (++top);
  index = &hashBucket[top];
  index->number = sumZ;
  index->times = 1;
  index->next = beginP;
}

void init() {
  scanf("%d", &N);
  addToHash(0);
  for (int i = 0; i < N; ++i) {
    scanf("%d", &Ai);
    sumZ = sumZ + Ai;
    addToHash(sumZ);
  }
}

void work() {
  ll answer = 0;
  for (int i = 1; i <= top; ++i)
    if (hashBucket[i].times > 1)
      answer =
          answer + (((hashBucket[i].times) * (hashBucket[i].times - 1)) >> 1);
  cout << answer << endl;
}

int main() {
  init();
  work();
  return 0;
}


Fixed submission:
/*
For Bantako San
By shyyhs.

Using hash to insert and search for a perticular number.
Every insert and search is O(1) ideally.
*/

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
#define ll long long
// #define Hsize 100009
#define Hsize (1 << 16)
#define MAXN 201001
ll sumZ = 0; // sum from the beginning
int Ai;      // This is Ai in the problem, we use it only once so array is not
        // necessary.
int N; // N in the problem

struct T {
  ll number, times;
  T *next;
} hashBucket[MAXN];
int top = 0;
int hashIndex[Hsize];

// x->hash(x)
inline int hashFunc(ll x) { return (x & (0x0000FFFF)); }

// add the current sumZ to the hash table
inline void addToHash(ll sumZ) {
  int HsumZ;
  T *index, *beginP;
  HsumZ = hashFunc(sumZ);
  for (beginP = index = &hashBucket[hashIndex[HsumZ]]; (index->times > 0);
       index = index->next)
    if (index->number == sumZ) {
      index->times++;
      return;
    }
  hashIndex[HsumZ] = (++top);
  index = &hashBucket[top];
  index->number = sumZ;
  index->times = 1;
  index->next = beginP;
}

void init() {
  scanf("%d", &N);
  addToHash(0);
  for (int i = 0; i < N; ++i) {
    scanf("%d", &Ai);
    sumZ = sumZ + Ai;
    addToHash(sumZ);
  }
}

void work() {
  ll answer = 0;
  for (int i = 1; i <= top; ++i)
    if (hashBucket[i].times > 1)
      answer =
          answer + (((hashBucket[i].times) * (hashBucket[i].times - 1)) >> 1);
  cout << answer << endl;
}

int main() {
  init();
  work();
  return 0;
}
Problem p03363 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long LL;
LL num[100006];
map<LL, LL> my;
int main(void) {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> num[i];
  my[0] = 1;
  LL sum = 0;
  LL ask = 0;
  for (int i = 1; i <= n; i++) {
    sum += num[i];
    if (my.count(sum))
      ask += my[sum];
    my[sum]++;
  }
  cout << ask << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long LL;
LL num[200006];
map<LL, LL> my;
int main(void) {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> num[i];
  my[0] = 1;
  LL sum = 0;
  LL ask = 0;
  for (int i = 1; i <= n; i++) {
    sum += num[i];
    if (my.count(sum))
      ask += my[sum];
    my[sum]++;
  }
  cout << ask << endl;
  return 0;
}
Problem p03363 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
long long n, s1, a[200010], b[200010], sum[200010], ans;
inline int read() {
  int num = 0, flag = 1;
  char c = getchar();
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-')
      flag = -1;
  for (; c >= '0' && c <= '9'; c = getchar())
    num = (num << 3) + (num << 1) + c - 48;
  return num * flag;
}
int main() {
  n = read();
  for (int i = 1; i <= n; ++i) {
    b[i] = s1;
    s1 += i;
  }
  for (int i = 1; i <= n; ++i) {
    a[i] = read();
    sum[i] = sum[i - 1] + a[i];
    if (sum[i] == 0)
      ans++;
  }
  sort(sum + 1, sum + n + 1);
  for (int i = 1; i <= n; ++i) {
    long long s2 = 1;
    while (sum[i + 1] == sum[i]) {
      s2++;
      i++;
    }
    ans += b[s2];
  }
  printf("%lld\n", ans);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
long long n, s1, a[200010], b[200010], sum[200010], ans;
inline int read() {
  int num = 0, flag = 1;
  char c = getchar();
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-')
      flag = -1;
  for (; c >= '0' && c <= '9'; c = getchar())
    num = (num << 3) + (num << 1) + c - 48;
  return num * flag;
}
int main() {
  n = read();
  for (int i = 1; i <= n; ++i) {
    b[i] = s1;
    s1 += i;
  }
  for (int i = 1; i <= n; ++i) {
    a[i] = read();
    sum[i] = sum[i - 1] + a[i];
    if (sum[i] == 0)
      ans++;
  }
  sort(sum + 1, sum + n + 1);
  for (int i = 1; i <= n; ++i) {
    long long s2 = 1;
    while (sum[i + 1] == sum[i] && i < n) {
      s2++;
      i++;
    }
    ans += b[s2];
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p03363 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
using namespace std;
int n;
long long a[100009];
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i + 1];
    a[i + 1] += a[i];
  }
  sort(a, a + n + 1);
  int pl = 0;
  long long ret = 0;
  for (int i = 1; i <= n + 1; i++) {
    if (i == n + 1 || a[i - 1] != a[i]) {
      ret += 1LL * (i - pl) * (i - pl - 1) / 2;
      pl = i;
    }
  }
  cout << ret << "\n";
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;
int n;
long long a[200009];
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i + 1];
    a[i + 1] += a[i];
  }
  sort(a, a + n + 1);
  int pl = 0;
  long long ret = 0;
  for (int i = 1; i <= n + 1; i++) {
    if (i == n + 1 || a[i - 1] != a[i]) {
      ret += 1LL * (i - pl) * (i - pl - 1) / 2;
      pl = i;
    }
  }
  cout << ret << "\n";
  return 0;
}
Problem p03363 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define sz size
#define se second
#define fe first
#define mper make_pair
#define all(x) x.begin(), x.end()
#define mal                                                                    \
  ios_base::sync_with_stdio(NULL);                                             \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define saken string
#define erba continue
#define vl vector<ll>
#define vi vector<int>
#define vli vector<pair<ll, int>>
#define vll vector<pair<ll, ll>>
#define vii vector<pair<int, int>>
#define vil vector<pair<int, ll>>
using namespace std;

const ll MAXN = 2e5 + 100;
ll n, pref[MAXN], ct[MAXN];

int main() {

  cin >> n;
  ll ai;

  pref[0] = 0;

  for (ll i = 1; i <= n; ++i) {
    cin >> ai;
    pref[i] = pref[i - 1] + ai;
  }

  ll ans = 0;

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

    ct[pref[i]]++;

    ans += ct[pref[i]] - 1;
  }

  cout << ans;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define sz size
#define se second
#define fe first
#define mper make_pair
#define all(x) x.begin(), x.end()
#define mal                                                                    \
  ios_base::sync_with_stdio(NULL);                                             \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define saken string
#define erba continue
#define vl vector<ll>
#define vi vector<int>
#define vli vector<pair<ll, int>>
#define vll vector<pair<ll, ll>>
#define vii vector<pair<int, int>>
#define vil vector<pair<int, ll>>
using namespace std;

const ll MAXN = 2e5 + 100;
ll n, pref[MAXN];

map<ll, ll> ct;

int main() {

  cin >> n;
  ll ai;

  pref[0] = 0;

  for (ll i = 1; i <= n; ++i) {
    cin >> ai;
    pref[i] = pref[i - 1] + ai;
  }

  ll ans = 0;

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

    ct[pref[i]]++;

    ans += ct[pref[i]] - 1;
  }

  cout << ans;

  return 0;
}
Problem p03363 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep_r(i, n, m) for (int i = m; i < n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
// 昇順sort
#define sorti(x) sort(x.begin(), x.end())
// 降順sort
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

ll res = 0;

int main() {
  int n;
  scanf("%d", &n);
  vector<ll> a(n + 1, 0);
  for (int i = 1; i <= n; ++i) {
    ll t;
    scanf("%lld", &t);
    if (t == 0)
      res++;
    a[i + 1] = a[i] + t;
  }

  /*
  swap(a[0], a.back());
  a.pop_back();
  */

  map<ll, ll> mp;
  for (int i = 0; i <= n; ++i) {
    mp[a[i]]++;
  }

  for (auto itr : mp) {
    // cout << itr.second << endl;
    res += ((itr.second - 1) * itr.second) / 2;
  }
  printf("%lld\n", res);
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep_r(i, n, m) for (int i = m; i < n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
// 昇順sort
#define sorti(x) sort(x.begin(), x.end())
// 降順sort
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

ll res = 0;

int main() {
  int n;
  scanf("%d", &n);
  vector<ll> a(n + 1, 0);
  for (int i = 1; i <= n; ++i) {
    ll t;
    scanf("%lld", &t);
    a[i] = a[i - 1] + t;
  }

  /*
  swap(a[0], a.back());
  a.pop_back();
  */

  map<ll, ll> mp;
  for (int i = 0; i <= n; ++i) {
    mp[a[i]]++;
  }

  for (auto itr : mp) {
    // cout << itr.second << endl;
    res += ((itr.second - 1) * itr.second) / 2;
  }
  printf("%lld\n", res);
}
Problem p03363 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define INF 2147483647
#define LINF 9223372036854775807
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
// #define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X)                                                                 \
  {}
#define ARDEB(i, X)                                                            \
  {}
#define END                                                                    \
  {}
#endif
// typedef long long int ll;
signed main() {

  int n;
  int a[111111];
  a[0] = 0;
  cin >> n;
  for (int i = 1; i < n + 1; i++) {
    int b;
    cin >> b;
    a[i] = a[i - 1] + b;
  }
  sort(a, a + n + 1);
  a[n + 1] = -1;
  int co = 0, ans = 0;
  rep(i, n + 1) {
    if (a[i] == a[i + 1])
      co++;
    else {
      co++;
      ans += co * (co - 1) / 2;
      co = 0;
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define INF 2147483647
#define LINF 9223372036854775807
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
// #define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X)                                                                 \
  {}
#define ARDEB(i, X)                                                            \
  {}
#define END                                                                    \
  {}
#endif
// typedef long long int ll;
signed main() {

  int n;
  int a[111111 * 2];
  a[0] = 0;
  cin >> n;
  for (int i = 1; i < n + 1; i++) {
    int b;
    cin >> b;
    a[i] = a[i - 1] + b;
  }
  sort(a, a + n + 1);
  a[n + 1] = -1;
  int co = 0, ans = 0;
  rep(i, n + 1) {
    if (a[i] == a[i + 1])
      co++;
    else {
      co++;
      ans += co * (co - 1) / 2;
      co = 0;
    }
  }
  cout << ans << endl;
}
Problem p03363 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <utility>
#include <vector>

using namespace std;

int n;
long long ans;
long long a[100005], sum[100005];
map<long long, int> mp;

int main() {
  scanf("%d", &n);
  mp[0] = 1;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    sum[i] = sum[i - 1] + a[i];
    //		printf("%d ",sum[i]);
    mp[sum[i]]++;
  }
  //	puts("");
  for (map<long long, int>::iterator it = mp.begin(); it != mp.end(); it++) {
    ans += (long long)(it->second) * ((it->second) - 1) / 2;
  }
  printf("%lld\n", ans);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <utility>
#include <vector>

using namespace std;

int n;
long long ans;
long long a[200005], sum[200005];
map<long long, int> mp;

int main() {
  scanf("%d", &n);
  mp[0] = 1;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    sum[i] = sum[i - 1] + a[i];
    //		printf("%d ",sum[i]);
    mp[sum[i]]++;
  }
  //	puts("");
  for (map<long long, int>::iterator it = mp.begin(); it != mp.end(); it++) {
    ans += (long long)(it->second) * ((it->second) - 1) / 2;
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p03363 (C++)

Buggy submission (status: Runtime Error):
/**
 *	Author: houtaru
 *	Create: 28.04.2018 19:16:16
 */

#include <iostream>
#include <map>

using namespace std;

const int maxn = 1e5 + 10;

int n;
map<long long, int> f;
long long a[maxn];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  long long answer = 0;
  f[0] = 1;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    a[i] += a[i - 1];
    answer += f[a[i]];
    f[a[i]]++;
  }
  cout << answer << "\n";
  return 0;
}

Fixed submission:
/**
 *	Author: houtaru
 *	Create: 28.04.2018 19:16:16
 */

#include <iostream>
#include <map>

using namespace std;

const int maxn = 5e5 + 10;

int n;
map<long long, int> f;
long long a[maxn];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  long long answer = 0;
  f[0] = 1;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    a[i] += a[i - 1];
    answer += f[a[i]];
    f[a[i]]++;
  }
  cout << answer << "\n";
  return 0;
}
Problem p03363 (C++)

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

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

typedef long long ll;

int main() {
  int n;
  cin >> n;
  ll a[n], b[n];
  rep(i, n) cin >> a[i];
  b[0] = a[0];
  rep(i, n - 1) b[i + 1] = b[i] + a[i + 1];

  ll ans = 0;
  rep(i, n) rep(j, i) if (b[i] - b[j] == 0)++ ans;
  rep(i, n) if (b[i] == 0)++ ans;

  cout << ans << endl;
  return 0;
}

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

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

typedef long long ll;

int main() {
  int n;
  cin >> n;
  ll a[n], b[n];
  rep(i, n) cin >> a[i];
  b[0] = a[0];
  rep(i, n - 1) b[i + 1] = b[i] + a[i + 1];

  ll ans = 0;
  ll cc = 1;
  ll cc0 = 0;
  sort(b, b + n);

  rep(i, n - 1) {
    if (b[i] == 0)
      ++cc0;

    if (b[i + 1] == b[i])
      ++cc;
    if (b[i + 1] != b[i]) {
      ans += cc * (cc - 1) / 2;
      cc = 1;
    }
  }

  ans += cc * (cc - 1) / 2;

  if (b[n - 1] == 0)
    ++cc0;
  ans += cc0;

  //    rep(i,n)rep(j,i)if(b[i]-b[j]==0)++ans;
  //    rep(i,n)if(b[i]==0)++ans;

  cout << ans << endl;
  return 0;
}
Problem p03363 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5;
map<ll, int> mymap;
ll sum[maxn + 5];
int main() {
  int n, a;
  scanf("%d", &n);
  long long ans = 0;
  mymap[0]++;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a);
    sum[i] = sum[i - 1] + a;
    ans += mymap[sum[i]];
    // cout<<i<<" "<<sum[i]<<" "<<ans<<endl;
    mymap[sum[i]]++;
  }
  printf("%lld\n", ans);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5;
map<ll, int> mymap;
ll sum[2 * maxn + 5];
int main() {
  int n, a;
  scanf("%d", &n);
  long long ans = 0;
  mymap[0]++;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a);
    sum[i] = sum[i - 1] + a;
    ans += mymap[sum[i]];
    // cout<<i<<" "<<sum[i]<<" "<<ans<<endl;
    mymap[sum[i]]++;
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p03363 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>

using namespace std;

const int maxn = 1e5 + 10;

typedef long long ll;

ll a[maxn];

map<ll, int> col;

int main() {
  int n;
  scanf("%d", &n);
  a[0] = 0LL;
  col[0]++;
  ll temp;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &temp);
    a[i] = a[i - 1] + temp;
    col[a[i]]++;
  }
  map<ll, int>::iterator it;
  ll sum = 0LL;
  for (it = col.begin(); it != col.end(); it++) {
    ll now = it->second;
    sum += now * (now - 1LL) / 2LL;
  }
  printf("%lld\n", sum);
  // cout <<col.size()<<"*"<< col[0] << "*" << col[1]  << "*" <<
  // col.size()<<endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>

using namespace std;

const int maxn = 2e5 + 10;

typedef long long ll;

ll a[maxn];

map<ll, int> col;

int main() {
  int n;
  scanf("%d", &n);
  a[0] = 0LL;
  col[0]++;
  ll temp;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &temp);
    a[i] = a[i - 1] + temp;
    col[a[i]]++;
  }
  map<ll, int>::iterator it;
  ll sum = 0LL;
  for (it = col.begin(); it != col.end(); it++) {
    ll now = it->second;
    sum += now * (now - 1LL) / 2LL;
  }
  printf("%lld\n", sum);
  // cout <<col.size()<<"*"<< col[0] << "*" << col[1]  << "*" <<
  // col.size()<<endl;
  return 0;
}
Problem p03363 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define pi 3.141592653897932384626
// freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
using namespace std;
long long a[100005];
int main() {
  long long s = 0;
  long n;
  cin >> n;
  ++n;
  for (long i = 1; i < n; i++) {
    scanf("%lld", &a[i]);
  }
  for (long i = 2; i < n; i++) {
    a[i] += a[i - 1];
  }
  a[0] = 0;
  sort(a, a + n);
  a[n] = LONG_LONG_MAX;
  for (long i = 1, j = 1; i <= n; i++) {
    //   cout<<a[i]<<' ';
    if (a[i] == a[i - 1])
      j++;
    else {
      s += j * (long long)(j - 1) / 2;
      j = 1;
    }
  }
  printf("%lld\n", s);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define pi 3.141592653897932384626
// freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
using namespace std;
long long a[200005];
int main() {
  long long s = 0;
  long n;
  cin >> n;
  ++n;
  for (long i = 1; i < n; i++) {
    scanf("%lld", &a[i]);
  }
  for (long i = 2; i < n; i++) {
    a[i] += a[i - 1];
  }
  a[0] = 0;
  sort(a, a + n);
  a[n] = LONG_LONG_MAX;
  for (long i = 1, j = 1; i <= n; i++) {
    //   cout<<a[i]<<' ';
    if (a[i] == a[i - 1])
      j++;
    else {
      s += j * (long long)(j - 1) / 2;
      j = 1;
    }
  }
  printf("%lld\n", s);
  return 0;
}
Problem p03363 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
long long a, b, c[20005], ans;
map<int, int> n;
int main() {
  cin >> a;
  n[0] = 1;
  for (int s = 1; s <= a; s++) {
    cin >> b;
    c[s] = b + c[s - 1];
    ans = ans + n[c[s]];
    n[c[s]]++;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
long long a, b, c[200005], ans;
map<long long, int> n;
int main() {
  cin >> a;
  n[0] = 1;
  for (int s = 1; s <= a; s++) {
    cin >> b;
    c[s] = b + c[s - 1];
    ans = ans + n[c[s]];
    n[c[s]]++;
  }
  cout << ans << endl;
}
Problem p03363 (C++)

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

const int maxn = 1e5 + 10;
typedef long long ll;

int a[maxn];
ll sum[maxn];
map<ll, ll> mp;
int main() {

  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i == 0)
      sum[i] = a[i];
    else
      sum[i] = sum[i - 1] + a[i];
  }

  for (int i = 0; i < n; i++) {
    mp[sum[i]]++;
  }

  ll ans = 0;
  map<ll, ll>::iterator it = mp.begin();
  while (it != mp.end()) {
    if (it->second > 1) {
      ans += (it->second) * (it->second - 1) / 2;
    }
    if (it->first == 0)
      ans += it->second;
    it++;
  }

  cout << ans << endl;

  return 0;
}


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

const int maxn = 2e5 + 10;
typedef long long ll;

int a[maxn];
ll sum[maxn];
map<ll, ll> mp;
int main() {

  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i == 0)
      sum[i] = a[i];
    else
      sum[i] = sum[i - 1] + a[i];
  }

  for (int i = 0; i < n; i++) {
    mp[sum[i]]++;
  }

  ll ans = 0;
  map<ll, ll>::iterator it = mp.begin();
  while (it != mp.end()) {
    if (it->second > 1) {
      ans += (it->second) * (it->second - 1) / 2;
    }
    if (it->first == 0)
      ans += it->second;
    it++;
  }

  cout << ans << endl;

  return 0;
}
Problem p03363 (C++)

Buggy submission (status: Runtime Error):

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

using namespace __gnu_pbds;
using namespace std;

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(), v.end()
#define fori(i, j, k) for (int i = (j); i < (int)(k); i++)
#define forb(i, j, k) for (int i = (j); i >= (int)k; i--)
#define lchild(ind) 2 * ind + 1
#define rchild(ind) 2 * ind + 2
#define bug(val) cout << "# " << val << endl;
#define bugs(val) cout << '_' << val;
#define bugl(val) cout << "## " << val << endl;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
typedef pair<ll, pll> plp;
typedef pair<pll, int> ppi;
typedef pair<pll, ll> ppl;
typedef pair<pll, pll> ppp;
typedef vector<int> vi;
typedef vector<ll> vll;

const int maxn = 1e5 + 1;
const ll inf = 2e18, mod = 1e9 + 7;

int n, a[maxn];
ll ans;
map<ll, int> cnt;

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

  cin >> n;
  fori(i, 0, n) cin >> a[i];
  ll sum = 0;
  cnt[sum]++;
  fori(i, 0, n) {
    sum += a[i];
    ans += cnt[sum];
    cnt[sum]++;
  }
  cout << ans << endl;
}

Fixed submission:

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

using namespace __gnu_pbds;
using namespace std;

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(), v.end()
#define fori(i, j, k) for (int i = (j); i < (int)(k); i++)
#define forb(i, j, k) for (int i = (j); i >= (int)k; i--)
#define lchild(ind) 2 * ind + 1
#define rchild(ind) 2 * ind + 2
#define bug(val) cout << "# " << val << endl;
#define bugs(val) cout << '_' << val;
#define bugl(val) cout << "## " << val << endl;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
typedef pair<ll, pll> plp;
typedef pair<pll, int> ppi;
typedef pair<pll, ll> ppl;
typedef pair<pll, pll> ppp;
typedef vector<int> vi;
typedef vector<ll> vll;

const int maxn = 1e6 + 1;
const ll inf = 2e18, mod = 1e9 + 7;

int n, a[maxn];
ll ans;
map<ll, int> cnt;

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

  cin >> n;
  fori(i, 0, n) cin >> a[i];
  ll sum = 0;
  cnt[sum]++;
  fori(i, 0, n) {
    sum += a[i];
    ans += cnt[sum];
    cnt[sum]++;
  }
  cout << ans << endl;
}
Problem p03363 (C++)

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

int A[100005];
ll psum[100005];

int main() {
  int n;
  cin >> n;
  ll ans = 0;
  set<ll> st;
  for (int i = 1; i <= n; i++) {
    cin >> A[i];
    psum[i] = psum[i - 1] + 1LL * A[i];
    st.insert(psum[i]);
  }
  sort(psum + 1, psum + 1 + n);

  for (auto it = st.begin(); it != st.end(); it++) {
    ll val = *it;
    int cnt = upper_bound(psum + 1, psum + 1 + n, val) -
              lower_bound(psum + 1, psum + 1 + n, val);
    ans += 1LL * cnt * (cnt - 1) / 2;
  }
  for (int i = 1; i <= n; i++)
    if (psum[i] == 0)
      ans++;
  cout << ans;
}


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

int A[200005];
ll psum[200005];

int main() {
  int n;
  cin >> n;
  ll ans = 0;
  set<ll> st;
  for (int i = 1; i <= n; i++) {
    cin >> A[i];
    psum[i] = psum[i - 1] + 1LL * A[i];
    st.insert(psum[i]);
  }
  sort(psum + 1, psum + 1 + n);

  for (auto it = st.begin(); it != st.end(); it++) {
    ll val = *it;
    int cnt = upper_bound(psum + 1, psum + 1 + n, val) -
              lower_bound(psum + 1, psum + 1 + n, val);
    ans += 1LL * cnt * (cnt - 1) / 2;
  }
  for (int i = 1; i <= n; i++)
    if (psum[i] == 0)
      ans++;
  cout << ans;
}
Problem p03363 (C++)

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

int a[100001];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  long long int sum = 0, ans = 0;
  map<long long int, int> M;
  M[0]++;
  for (int i = 1; i <= n; i++) {
    sum += a[i];
    if (M.count(sum))
      ans += M[sum];
    M[sum]++;
  }
  cout << ans << endl;
}


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

int a[200001];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  long long int sum = 0, ans = 0;
  map<long long int, int> M;
  M[0]++;
  for (int i = 1; i <= n; i++) {
    sum += a[i];
    if (M.count(sum))
      ans += M[sum];
    M[sum]++;
  }
  cout << ans << endl;
}
Problem p03363 (C++)

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

#define rep(i, n) for (int i = 1; i <= n; i++)
#define m(a, b) memset(a, b, sizeof(a))
typedef long long ll;
const int MAXN = 1e5 + 10;
ll a[MAXN], ans = 0;
map<ll, ll> mp;
map<ll, ll>::iterator iter;

int main() {
  int n;
  cin >> n;
  m(a, 0);
  rep(i, n) {
    cin >> a[i];
    a[i] += a[i - 1];
    if (a[i] == 0)
      ans++;
    mp[a[i]]++;
  }
  for (iter = mp.begin(); iter != mp.end(); iter++) {
    ans += (iter->second) * (iter->second - 1) / 2;
  }
  cout << ans << endl;
  return 0;
}

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

#define rep(i, n) for (int i = 1; i <= n; i++)
#define m(a, b) memset(a, b, sizeof(a))
typedef long long ll;
const int MAXN = 2e5 + 10;
ll a[MAXN], ans = 0;
map<ll, ll> mp;
map<ll, ll>::iterator iter;

int main() {
  int n;
  cin >> n;
  m(a, 0);
  rep(i, n) {
    cin >> a[i];
    a[i] += a[i - 1];
    if (a[i] == 0)
      ans++;
    mp[a[i]]++;
  }
  for (iter = mp.begin(); iter != mp.end(); iter++) {
    ans += (iter->second) * (iter->second - 1) / 2;
  }
  cout << ans << endl;
  return 0;
}
Problem p03363 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <queue>
#include <vector>
#define ull unsigned long long
#define ll long long
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)
#define lowbit(x) (x & -x)
#define inf 0x3f3f3f3f
#define mod 1000000007
#define eps 1e-18
inline ll read() {
  ll tmp = 0;
  char c = getchar(), f = 1;
  for (; c < '0' || '9' < c; c = getchar())
    if (c == '-')
      f = -1;
  for (; '0' <= c && c <= '9'; c = getchar())
    tmp = tmp * 10 + c - '0';
  return tmp * f;
}
inline ll power(ll a, ll b) {
  ll tmp = 1;
  for (; b; b >>= 1) {
    if (b & 1)
      tmp = tmp * a % mod;
    a = a * a % mod;
  }
  return tmp;
}
using namespace std;
ll a[100010], sum[100010];
int n;
int main() {
  int i;
  n = read();
  for (i = 1; i <= n; i++)
    a[i] = read(), sum[i] = sum[i - 1] + a[i];
  sort(sum, sum + n + 1);
  sum[n + 1] = -1;
  ll ans = 0, cnt = 0;
  for (i = 0; i <= n; i++) {
    ++cnt;
    if (sum[i] != sum[i + 1])
      ans += cnt * (cnt - 1) / 2, cnt = 0;
  }
  printf("%lld\n", ans);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <queue>
#include <vector>
#define ull unsigned long long
#define ll long long
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)
#define lowbit(x) (x & -x)
#define inf 0x3f3f3f3f
#define mod 1000000007
#define eps 1e-18
inline ll read() {
  ll tmp = 0;
  char c = getchar(), f = 1;
  for (; c < '0' || '9' < c; c = getchar())
    if (c == '-')
      f = -1;
  for (; '0' <= c && c <= '9'; c = getchar())
    tmp = tmp * 10 + c - '0';
  return tmp * f;
}
inline ll power(ll a, ll b) {
  ll tmp = 1;
  for (; b; b >>= 1) {
    if (b & 1)
      tmp = tmp * a % mod;
    a = a * a % mod;
  }
  return tmp;
}
using namespace std;
ll a[200010], sum[200010];
int n;
int main() {
  int i;
  n = read();
  for (i = 1; i <= n; i++)
    a[i] = read(), sum[i] = sum[i - 1] + a[i];
  sort(sum, sum + n + 1);
  sum[n + 1] = -1;
  ll ans = 0, cnt = 0;
  for (i = 0; i <= n; i++) {
    ++cnt;
    if (sum[i] != sum[i + 1])
      ans += cnt * (cnt - 1) / 2, cnt = 0;
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p03363 (C++)

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

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

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

  vector<long long> ac(N + 1);
  ac[0] = 0;
  for (int i = 0; i <= N; ++i) {
    ac[i + 1] = ac[i] + A[i];
  }

  map<long long, long long> m;
  for (int i = 0; i < N + 1; ++i) {
    m[ac[i]]++;
  }

  long long ans = 0;
  for (auto it = m.begin(); it != m.end(); ++it) {
    ans += it->second * (it->second - 1) / 2LL;
  }

  cout << ans << endl;

  return 0;
}

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

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

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

  vector<long long> ac(N + 1);
  ac[0] = 0;
  for (int i = 0; i < N; ++i) {
    ac[i + 1] = ac[i] + A[i];
  }

  map<long long, long long> m;
  for (int i = 0; i < N + 1; ++i) {
    m[ac[i]]++;
  }

  long long ans = 0;
  for (auto it = m.begin(); it != m.end(); ++it) {
    ans += it->second * (it->second - 1) / 2LL;
  }

  cout << ans << endl;

  return 0;
}
Problem p03363 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define MAXN 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
ll n, k, a[MAXN];
map<ll, ll> mp;
int main() {
  scanf("%lld", &n);
  for (ll i = 1; i <= n; i++)
    scanf("%lld", &a[i]);
  ll ans = 0, s = 0;
  for (ll i = 1; i <= n; i++) {
    s += a[i];
    if (mp.find(s) == mp.end())
      mp[s] = 1;
    else {
      ans += mp[s];
      mp[s]++;
    }
    if (s == 0)
      ans++;
  }
  printf("%lld\n", ans);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define MAXN 200005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
ll n, k, a[MAXN];
map<ll, ll> mp;
int main() {
  scanf("%lld", &n);
  for (ll i = 1; i <= n; i++)
    scanf("%lld", &a[i]);
  ll ans = 0, s = 0;
  for (ll i = 1; i <= n; i++) {
    s += a[i];
    if (mp.find(s) == mp.end())
      mp[s] = 1;
    else {
      ans += mp[s];
      mp[s]++;
    }
    if (s == 0)
      ans++;
  }
  printf("%lld\n", ans);
  return 0;
}