Problem p03627 (C++)

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

#define GET_MACRO(_1, _2, _3, _4, NAME, ...) NAME
#define REP2(i, n) for (int i = 0; i < (int)(n); i++)
#define REP3(i, m, n) for (int i = m; i < (int)(n); i++)
#define REP4(i, m, n, s)                                                       \
  for (int i = m; (s > 0 and i < (int)(n)) or (s < 0 and i > (int)(n)); i += s)
#define REP(...) GET_MACRO(__VA_ARGS__, REP4, REP3, REP2)(__VA_ARGS__)
#define REPIT(i, c)                                                            \
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define PIS(x) printf("%d ", x)
#define PN() putchar('\n')
#define PRINTARR(a, b)                                                         \
  for (int i = 0; (a + i) != (b); i++) {                                       \
    cout << *(a + i) << " ";                                                   \
  }                                                                            \
  PN();
#define MP make_pair
#define PB push_back
#define EB emplace_back

typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

void RI() {}
template <typename... T> void RI(int &head, T &...tail) {
  scanf("%d", &head);
  RI(tail...);
}
void RLL() {}
template <typename... T> void RLL(LL &head, T &...tail) {
  scanf("%lld", &head);
  RLL(tail...);
}
void print() { putchar('\n'); }
template <typename T, typename... U> void print(T head, U... tail) {
  cout << head << " ";
  print(tail...);
}

const int MOD = 1000000007;
#define MAX_N 100005
map<int, int> cnt;

int main() {
  int n;
  RI(n);
  REP(i, n) {
    int a;
    RI(a);
    cnt[a] += 1;
  }
  vector<int> a2;
  REPIT(ii, cnt) {
    if (ii->second >= 2) {
      a2.PB(ii->first);
    }
    if (ii->second >= 4) {
      a2.PB(ii->first);
    }
  }
  sort(a2.begin(), a2.end(), greater<int>());
  LL ans = ((LL)a2[0]) * a2[1];
  printf("%lld\n", ans);
  return 0;
}


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

#define GET_MACRO(_1, _2, _3, _4, NAME, ...) NAME
#define REP2(i, n) for (int i = 0; i < (int)(n); i++)
#define REP3(i, m, n) for (int i = m; i < (int)(n); i++)
#define REP4(i, m, n, s)                                                       \
  for (int i = m; (s > 0 and i < (int)(n)) or (s < 0 and i > (int)(n)); i += s)
#define REP(...) GET_MACRO(__VA_ARGS__, REP4, REP3, REP2)(__VA_ARGS__)
#define REPIT(i, c)                                                            \
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define PIS(x) printf("%d ", x)
#define PN() putchar('\n')
#define PRINTARR(a, b)                                                         \
  for (int i = 0; (a + i) != (b); i++) {                                       \
    cout << *(a + i) << " ";                                                   \
  }                                                                            \
  PN();
#define MP make_pair
#define PB push_back
#define EB emplace_back

typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

void RI() {}
template <typename... T> void RI(int &head, T &...tail) {
  scanf("%d", &head);
  RI(tail...);
}
void RLL() {}
template <typename... T> void RLL(LL &head, T &...tail) {
  scanf("%lld", &head);
  RLL(tail...);
}
void print() { putchar('\n'); }
template <typename T, typename... U> void print(T head, U... tail) {
  cout << head << " ";
  print(tail...);
}

const int MOD = 1000000007;
#define MAX_N 100005
map<int, int> cnt;

int main() {
  int n;
  RI(n);
  REP(i, n) {
    int a;
    RI(a);
    cnt[a] += 1;
  }
  vector<int> a2;
  REPIT(ii, cnt) {
    if (ii->second >= 2) {
      a2.PB(ii->first);
    }
    if (ii->second >= 4) {
      a2.PB(ii->first);
    }
  }
  if (a2.size() < 2) {
    printf("0\n");
    return 0;
  }
  sort(a2.begin(), a2.end(), greater<int>());
  LL ans = ((LL)a2[0]) * a2[1];
  printf("%lld\n", ans);
  return 0;
}