Problem p02975 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define LL long long
LL read() {
  LL f = 1, x = 0;
  char c = getchar();
  while (c < '0' || '9' < c) {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while ('0' <= c && c <= '9')
    x = (x << 3) + (x << 1) + c - '0', c = getchar();
  return f * x;
}
#define MAXN 80000
#define INF 0x3f3f3f3f
int cnt[10];
LL a[MAXN + 5], b[MAXN + 5];
int main() {
  // freopen("circle.in","r",stdin);
  // freopen("circle.out","w",stdout);
  int T = 1;
  while (T--) {
    int n = read();
    memset(cnt, 0, sizeof(cnt));
    bool f = 1;
    for (int i = 1; i <= n; i++) {
      b[i] = a[i] = read();
      if (a[i])
        f = 0;
    }
    if (f) {
      puts("Yes");
      continue;
    }
    sort(b + 1, b + n + 1);
    int m = unique(b + 1, b + n + 1) - (b + 1);
    if (m >= 4) {
      puts("No");
      continue;
    }
    for (int t = 1; t <= m; t++)
      for (int i = 1; i <= n; i++)
        if (b[t] == a[i])
          cnt[t]++;
    sort(cnt + 1, cnt + m + 1);
    if (m == 1)
      puts("No");
    if (m == 2) {
      if (n % 3 == 0) {
        if (cnt[1] == n / 3 && cnt[2] == n / 3 * 2 && b[1] == 0)
          puts("Yes");
        else
          puts("No");
      } else
        puts("No");
    }
    if (m == 3) {
      if (n % 3 == 0) {
        if (cnt[1] == n / 3 && cnt[2] == n / 3 && cnt[3] == n / 3 &&
            (b[1] == (b[2] ^ b[3])))
          puts("Yes");
        else
          puts("No");
      } else
        puts("No");
    }
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define LL long long
LL read() {
  LL f = 1, x = 0;
  char c = getchar();
  while (c < '0' || '9' < c) {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while ('0' <= c && c <= '9')
    x = (x << 3) + (x << 1) + c - '0', c = getchar();
  return f * x;
}
#define MAXN 100000
#define INF 0x3f3f3f3f
int cnt[10];
LL a[MAXN + 5], b[MAXN + 5];
int main() {
  // freopen("circle.in","r",stdin);
  // freopen("circle.out","w",stdout);
  int T = 1;
  while (T--) {
    int n = read();
    memset(cnt, 0, sizeof(cnt));
    bool f = 1;
    for (int i = 1; i <= n; i++) {
      b[i] = a[i] = read();
      if (a[i])
        f = 0;
    }
    if (f) {
      puts("Yes");
      continue;
    }
    sort(b + 1, b + n + 1);
    int m = unique(b + 1, b + n + 1) - (b + 1);
    if (m >= 4) {
      puts("No");
      continue;
    }
    for (int t = 1; t <= m; t++)
      for (int i = 1; i <= n; i++)
        if (b[t] == a[i])
          cnt[t]++;
    sort(cnt + 1, cnt + m + 1);
    if (m == 1)
      puts("No");
    if (m == 2) {
      if (n % 3 == 0) {
        if (cnt[1] == n / 3 && cnt[2] == n / 3 * 2 && b[1] == 0)
          puts("Yes");
        else
          puts("No");
      } else
        puts("No");
    }
    if (m == 3) {
      if (n % 3 == 0) {
        if (cnt[1] == n / 3 && cnt[2] == n / 3 && cnt[3] == n / 3 &&
            (b[1] == (b[2] ^ b[3])))
          puts("Yes");
        else
          puts("No");
      } else
        puts("No");
    }
  }
  return 0;
}