Problem p03246 (C++)

Buggy submission (status: Runtime Error):
/**
 *    Author:  "Robin Singh" !!!
 *    BrainyIsTheNewSexy     (CodeForces)
 *    rob_in_1               (Other OJs)
 **/
#include <bits/stdc++.h>
using namespace std;
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define make_unique(x)                                                         \
  sort(all((x)));                                                              \
  (x).resize(unique(all((x))) - (x).begin())
#define ff first
#define ss second
#define mp make_pair
#define szz(v) ((int)(v).size())
#define fr(i, j, k) for (int i = j; i < k; i++)
#define bk(i, j, k) for (int i = j - 1; i >= k; i--)
#define frit(it, a)                                                            \
  for (__typeof((a).begin()) it = a.begin(); it != a.end(); ++it)
#define mem(ptr) memset(ptr, 0, sizeof ptr)
#define nl "\n"
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
const long long mod = 1e9 + 7;
const long double eps = 1e-9;
const long long INF = (1LL << 61);
const int inf = (1 << 30);
const int nn = 1e5 + 5;
//---------------------------------------------*DEBUGGING*--------------------------------------------------------->]
#define dbg(args...)                                                           \
  {                                                                            \
    vector<string> _v = split(#args, ',');                                     \
    err(_v.begin(), args);                                                     \
    cerr << '\n';                                                              \
  }
vector<string> split(const string &s, char c) {
  vector<string> v;
  stringstream ss(s);
  string x;
  while (getline(ss, x, c))
    v.emplace_back(x);
  return move(v);
}
void err(vector<string>::iterator it) {}
template <typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
  cerr << it->substr((*it)[0] == ' ', it->length()) << " = " << a << '\t';
  err(++it, args...);
}
//----------------------------------------------------------------------------------------------------------------->]
//*****************************************!Template Ends
//Here!*****************************************************]

int cnt[2][nn];

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  IOS;
  int n;
  cin >> n;
  int a[n];
  fr(i, 0, n) {
    cin >> a[i];
    cnt[i % 2][a[i]]++;
  }

  int mx1 = 0, mx11 = 0, mx2 = 0, mx22 = 0;
  int n1, n2;

  fr(i, 0, nn) {
    if (cnt[0][i] > mx1) {
      n1 = i;
      mx11 = mx1;
      mx1 = cnt[0][i];
    } else if (cnt[0][i] > mx11) {
      mx11 = cnt[0][i];
    }

    if (cnt[1][i] > mx2) {
      n2 = i;
      mx22 = mx2;
      mx2 = cnt[1][i];
    } else if (cnt[1][i] > mx22) {
      mx22 = cnt[1][i];
    }
  }

  if (n1 == n2) {
    int mx = max({mx1 + mx22, mx2 + mx11});
    cout << n - mx;
  } else
    cout << n / 2 - mx1 + n / 2 - mx2;
  return 0;
}

//->INTUITIONS are not to be ignored. They represent data processed too fast for
//the conscious mind to comprehend !!


Fixed submission:
/**
 *    Author:  "Robin Singh" !!!
 *    BrainyIsTheNewSexy     (CodeForces)
 *    rob_in_1               (Other OJs)
 **/
#include <bits/stdc++.h>
using namespace std;
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define make_unique(x)                                                         \
  sort(all((x)));                                                              \
  (x).resize(unique(all((x))) - (x).begin())
#define ff first
#define ss second
#define mp make_pair
#define szz(v) ((int)(v).size())
#define fr(i, j, k) for (int i = j; i < k; i++)
#define bk(i, j, k) for (int i = j - 1; i >= k; i--)
#define frit(it, a)                                                            \
  for (__typeof((a).begin()) it = a.begin(); it != a.end(); ++it)
#define mem(ptr) memset(ptr, 0, sizeof ptr)
#define nl "\n"
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
const long long mod = 1e9 + 7;
const long double eps = 1e-9;
const long long INF = (1LL << 61);
const int inf = (1 << 30);
const int nn = 1e5 + 5;
//---------------------------------------------*DEBUGGING*--------------------------------------------------------->]
#define dbg(args...)                                                           \
  {                                                                            \
    vector<string> _v = split(#args, ',');                                     \
    err(_v.begin(), args);                                                     \
    cerr << '\n';                                                              \
  }
vector<string> split(const string &s, char c) {
  vector<string> v;
  stringstream ss(s);
  string x;
  while (getline(ss, x, c))
    v.emplace_back(x);
  return move(v);
}
void err(vector<string>::iterator it) {}
template <typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
  cerr << it->substr((*it)[0] == ' ', it->length()) << " = " << a << '\t';
  err(++it, args...);
}
//----------------------------------------------------------------------------------------------------------------->]
//*****************************************!Template Ends
//Here!*****************************************************]

int cnt[2][nn];

int main() {

  // freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
  IOS;
  int n;
  cin >> n;
  int a[n];
  fr(i, 0, n) {
    cin >> a[i];
    cnt[i % 2][a[i]]++;
  }

  int mx1 = 0, mx11 = 0, mx2 = 0, mx22 = 0;
  int n1, n2;

  fr(i, 0, nn) {
    if (cnt[0][i] > mx1) {
      n1 = i;
      mx11 = mx1;
      mx1 = cnt[0][i];
    } else if (cnt[0][i] > mx11) {
      mx11 = cnt[0][i];
    }

    if (cnt[1][i] > mx2) {
      n2 = i;
      mx22 = mx2;
      mx2 = cnt[1][i];
    } else if (cnt[1][i] > mx22) {
      mx22 = cnt[1][i];
    }
  }

  if (n1 == n2) {
    int mx = max({mx1 + mx22, mx2 + mx11});
    cout << n - mx;
  } else
    cout << n / 2 - mx1 + n / 2 - mx2;
  return 0;
}

//->INTUITIONS are not to be ignored. They represent data processed too fast for
//the conscious mind to comprehend !!