Problem p02975 (C++)

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

const int MAXN = 1e5 + 5;

int n, a[MAXN];
map<int, int> num;
vector<int> vals;

int main() {
  scanf("%d", &n);
  bool doZero = false;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    num[a[i]]++;
    if (a[i] == 0)
      doZero = true;
  }
  if (n % 3 == 0) {
    if (num.size() > 3) {
      printf("No\n");
    } else if (num.size() == 3) {
      // All should equal
      vector<int> vals, nums;
      for (auto i : num) {
        vals.push_back(i.first);
        nums.push_back(i.second);
        assert(i.second > 0);
      }
      assert(nums.size() == 3);
      if (nums[0] == nums[1] && nums[1] == nums[2] &&
          vals[0] ^ vals[1] == vals[2]) {
        assert(false);
        printf("Yes\n");
      } else {
        printf("No\n");
      }
    } else if (num.size() == 2) {
      vector<int> vals, nums;
      for (auto i : num) {
        vals.push_back(i.first);
        nums.push_back(i.second);
      }

      bool valid = true;
      assert(nums.size() == 2);
      if (vals[0] == 0) {
        if (2 * nums[0] != nums[1])
          valid = false;
      } else if (vals[1] == 0) {
        if (2 * nums[1] != nums[0])
          valid = false;
      } else {
        valid = false;
      }
      if (valid)
        printf("Yes\n");
      else
        printf("No\n");
    } else {
      if (doZero) {
        printf("Yes\n");
      } else {
        printf("No\n");
      }
    }
  } else {
    if (num.size() == 1 && doZero) {
      printf("Yes\n");
    } else {
      printf("No\n");
    }
  }
}

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

const int MAXN = 1e5 + 5;

int n, a[MAXN];
map<int, int> num;
vector<int> vals;

int main() {
  scanf("%d", &n);
  bool doZero = false;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    num[a[i]]++;
    if (a[i] == 0)
      doZero = true;
  }
  if (n % 3 == 0) {
    if (num.size() > 3) {
      printf("No\n");
    } else if (num.size() == 3) {
      // All should equal
      vector<int> vals, nums;
      for (auto i : num) {
        vals.push_back(i.first);
        nums.push_back(i.second);
        assert(i.second > 0);
      }
      assert(nums.size() == 3);
      if (nums[0] == nums[1] && nums[1] == nums[2] &&
          (vals[0] ^ vals[1]) == vals[2]) {
        printf("Yes\n");
      } else {
        printf("No\n");
      }
    } else if (num.size() == 2) {
      vector<int> vals, nums;
      for (auto i : num) {
        vals.push_back(i.first);
        nums.push_back(i.second);
      }

      bool valid = true;
      assert(nums.size() == 2);
      if (vals[0] == 0) {
        if (2 * nums[0] != nums[1])
          valid = false;
      } else if (vals[1] == 0) {
        if (2 * nums[1] != nums[0])
          valid = false;
      } else {
        valid = false;
      }
      if (valid)
        printf("Yes\n");
      else
        printf("No\n");
    } else {
      if (doZero) {
        printf("Yes\n");
      } else {
        printf("No\n");
      }
    }
  } else {
    if (num.size() == 1 && doZero) {
      printf("Yes\n");
    } else {
      printf("No\n");
    }
  }
}