Language: C++

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef vector<vector<int>> vv;
typedef pair<int, int> P;

// input
int N;
vector<int> A;

map<int, int> m;
int ans;


void input() {
    cin >> N;
    A = vector<int>(3 * N);
    rep(i, 3 * N) cin >> A[i];
}


void solve1(int a, int b) {
    if (m[a] >= 1 && m[b] == 2) {
        ans++;
        m[a] = 2;
        m[b] = 2;
    } else if (m[a] >= 1) {
        ans++;
        m[a] = (m[a] + 2) % 3;
        m[b]++;
    } else if (m[b] == 2) {
        ans++;
        m[a] = 2;
        m[b] = 0;
    }
}


void solve2(int a, int b, int c) {
    if (m[a] == 2 && m[b] == 2 && m[c] == 2) {
        ans++;
    } else if (m[a] == 2 && m[b] == 2) {
        ans++;
        m[c]++;
    } else if (m[a] == 2 && m[c] == 2) {
        ans++
        m[b]++;;
    } else if (m[b] == 2 && m[c] == 2) {
        ans++;
        m[a]++;
    } else if (m[a] == 2) {
        ans++;
        m[a] = 0;
        m[b]++;
        m[c]++;
    } else if (m[b] == 2) {
        ans++;
        m[b] = 0;
        m[a]++;
        m[c]++;
    } else if (m[c] == 2) {
        ans++;
        m[c] = 0;
        m[a]++;
        m[b]++;
    } else {
        m[a]++;
        m[b]++;
        m[c]++;
    }
}


int main() {
    input();
    A.push_back(2001);
    A.push_back(2002);
    int n = 3 * N + 2;
    ans = 0;
    rep(i, 5) {
        m[A[i]]++;
        if (m[A[i]] == 3) {
            ans++;
            m[A[i]] = 0;
        }
    }
    for (int i = 5; i < n; i += 3) {
        int a = A[i], b = A[i + 1], c = A[i + 2];
        if (a == b && b == c) {
            ans++;
            continue;
        }
        if (a == b || b == c || a == c) {
            if (a == b) solve1(a, c);
            else {
                if (a == c) solve1(a, b);
                else solve1(b, a);
            }
            continue;
        }
        solve2(a, b, c);
    }
    cout << ans << endl;
}


Compiler output:
a.cc:4:9: error: 'vector' does not name a type
    4 | typedef vector<vector<int>> vv;
      |         ^~~~~~
a.cc:5:9: error: 'pair' does not name a type
    5 | typedef pair<int, int> P;
      |         ^~~~
a.cc:9:1: error: 'vector' does not name a type
    9 | vector<int> A;
      | ^~~~~~
a.cc:11:1: error: 'map' does not name a type
   11 | map<int, int> m;
      | ^~~
a.cc: In function 'void input()':
a.cc:16:5: error: 'cin' was not declared in this scope
   16 |     cin >> N;
      |     ^~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | using namespace std;
a.cc:17:5: error: 'A' was not declared in this scope
   17 |     A = vector<int>(3 * N);
      |     ^
a.cc:17:9: error: 'vector' was not declared in this scope
   17 |     A = vector<int>(3 * N);
      |         ^~~~~~
a.cc:1:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
  +++ |+#include <vector>
    1 | using namespace std;
a.cc:17:16: error: expected primary-expression before 'int'
   17 |     A = vector<int>(3 * N);
      |                ^~~
a.cc: In function 'void solve1(int, int)':
a.cc:23:9: error: 'm' was not declared in this scope
   23 |     if (m[a] >= 1 && m[b] == 2) {
      |         ^
a.cc: In function 'void solve2(int, int, int)':
a.cc:40:9: error: 'm' was not declared in this scope
   40 |     if (m[a] == 2 && m[b] == 2 && m[c] == 2) {
      |         ^
a.cc:46:14: error: expected ';' before 'm'
   46 |         ans++
      |              ^
      |              ;
   47 |         m[b]++;;
      |         ~     
a.cc: In function 'int main()':
a.cc:76:5: error: 'A' was not declared in this scope
   76 |     A.push_back(2001);
      |     ^
a.cc:81:9: error: 'm' was not declared in this scope
   81 |         m[A[i]]++;
      |         ^
a.cc:89:18: error: 'b' was not declared in this scope
   89 |         if (a == b && b == c) {
      |                  ^
a.cc:89:28: error: 'c' was not declared in this scope
   89 |         if (a == b && b == c) {
      |                            ^
a.cc:93:18: error: 'b' was not declared in this scope
   93 |         if (a == b || b == c || a == c) {
      |                  ^
a.cc:93:28: error: 'c' was not declared in this scope
   93 |         if (a == b || b == c || a == c) {
      |                            ^
a.cc:101:19: error: 'b' was not declared in this scope
  101 |         solve2(a, b, c);
      |                   ^
a.cc:101:22: error: 'c' was not declared in this scope
  101 |         solve2(a, b, c);
      |                      ^
a.cc:103:5: error: 'cout' was not declared in this scope
  103 |     cout << ans << endl;
      |     ^~~~
a.cc:103:5: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:103:20: error: 'endl' was not declared in this scope
  103 |     cout << ans << endl;
      |                    ^~~~
a.cc:1:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
  +++ |+#include <ostream>
    1 | using namespace std;