Problem p02975 (C++)

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

typedef pair<long long int, long long int> pa;
#define resize(A) A.resize(unique(A.begin(), A.end()) - A.begin())
#define pb push_back

#define MAX 200005
long long int MOD = 1e9 + 7;
long long int INF = 1e18;

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int i, j, k = 0, l = 0, r = 0, m = 0, n, p = 0, cnt = 0, cnt1 = 0,
                      x, y, z = 0, a, b, low, mid, high, ans = 0, maxi = 0,
                      mini = INF, t;
  cin >> n;
  long long int A[n];
  map<long long int, long long int> ma;
  map<long long int, long long int>::iterator it;
  for (i = 0; i < n; i++) {
    cin >> A[i];
    ma[A[i]]++;
    if (A[i] == 0)
      cnt++;
  }
  if (cnt == n)
    cout << "Yes\n";
  else if (n % 3 == 0) {
    if (ma.size() == 2) {
      r = n / 3;
      vector<pa> V;
      for (it = ma.begin(); it != ma.end(); it++) {
        V.push_back({it->second, it->first});
      }
      sort(V.begin(), V.end());
      if (V[1].first == 2 * r && V[i].second == 0) {
        cout << "Yes\n";
      } else
        cout << "No\n";

    } else if (ma.size() == 3) {
      r = n / 3;
      vector<pa> V;
      for (it = ma.begin(); it != ma.end(); it++) {
        V.push_back({it->second, it->first});
      }
      sort(V.begin(), V.end());
      k = 0;
      k = k ^ V[0].second ^ V[1].second ^ V[2].second;
      if (V[0].first == r && V[1].first == r && V[2].first == r && k == 0) {
        cout << "Yes\n";
      } else
        cout << "No\n";
    } else
      cout << "No\n";
  } else
    cout << "No\n";
}

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

typedef pair<long long int, long long int> pa;
#define resize(A) A.resize(unique(A.begin(), A.end()) - A.begin())
#define pb push_back

#define MAX 200005
long long int MOD = 1e9 + 7;
long long int INF = 1e18;

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int i, j, k = 0, l = 0, r = 0, m = 0, n, p = 0, cnt = 0, cnt1 = 0,
                      x, y, z = 0, a, b, low, mid, high, ans = 0, maxi = 0,
                      mini = INF, t;
  cin >> n;
  long long int A[n];
  map<long long int, long long int> ma;
  map<long long int, long long int>::iterator it;
  for (i = 0; i < n; i++) {
    cin >> A[i];
    ma[A[i]]++;
    if (A[i] == 0)
      cnt++;
  }
  if (cnt == n)
    cout << "Yes\n";
  else if (n % 3 == 0) {
    if (ma.size() == 2) {
      r = n / 3;
      vector<pa> V;
      for (it = ma.begin(); it != ma.end(); it++) {
        V.push_back({it->second, it->first});
      }
      sort(V.begin(), V.end());
      if (V[1].first == 2 * r && V[0].second == 0) {
        cout << "Yes\n";
      } else
        cout << "No\n";

    } else if (ma.size() == 3) {
      r = n / 3;
      vector<pa> V;
      for (it = ma.begin(); it != ma.end(); it++) {
        V.push_back({it->second, it->first});
      }
      sort(V.begin(), V.end());
      k = 0;
      k = k ^ V[0].second ^ V[1].second ^ V[2].second;
      if (V[0].first == r && V[1].first == r && V[2].first == r && k == 0) {
        cout << "Yes\n";
      } else
        cout << "No\n";
    } else
      cout << "No\n";
  } else
    cout << "No\n";
}