Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
template <class T>
using Vec2 = vector<vector<T>>;
#define REP(i, m, n) for(ll i = (m); i < (n); ++i)
#define REPN(i, m, n) for(ll i = (m); i <= (n); ++i)
#define REPR(i, m, n) for(ll i = (m)-1; i >= (n); --i)
#define REPNR(i, m, n) for(ll i = (m); i >= (n); --i)
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <class T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <class T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
ll pow2(const int n){return (1LL << n);}
void co() { cout << endl; }
template <class Head, class... Tail>
void co(Head&& head, Tail&&... tail) {
    cout << head << ' ';
    co(forward<Tail>(tail)...);
}
void ce() { cerr << endl; }
template <class Head, class... Tail>
void ce(Head&& head, Tail&&... tail) {
    cerr << head << ' ';
    ce(forward<Tail>(tail)...);
}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const int n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18L+1;
constexpr ll MOD = 1e9L+7;
constexpr ll MOD_N = 998244353;
constexpr ld EPS = 1e-11;
const double PI = acos(-1);

int main(void){
    ll n;
    cin >> n;
    n *= 3;
    Vec a(n);
    rep(i, n) cin >> a[i];

    unordered_map<ll, ll> cur, nxt;
    ll ans = 0;
    for(ll i = 0; i < n - 3; i += 3){
        cur.clear();
        nxt.clear();
        ll cnt = i, sum = 0;
        Vec tar;
        while(cnt < n){
            if (cnt - i < 5) cur[a[cnt]]++;
            ll tmp = ++nxt[a[cnt]]);
            if(tmp == 3){
                sum += cur[a[cnt]];
                tar.push_back(a[cnt]);
            }
            if(sum >= 2){
                break;
            }
            ++cnt;
        }
        if(cnt < n){
            if(cnt - i < 5){
                rep(_, 3){
                    repr(j, 4){
                        for(ll k : tar){
                            if (a[i + j + 1] == k) {
                                swap(a[i + j + 1], a[i + j]);
                                break;
                            }
                        }
                    }
                }
            }else{
                rep(_, 2){
                    rep(j, 4){
                        for (ll k : tar){
                            if (a[i + j + 1] == k) continue;
                            if (a[i + j] == k){
                                swap(a[i + j], a[i + j + 1]);
                                break;
                            }
                        }
                    }
                }
            }
        }
        if (a[i] == a[i + 1] && a[i + 1] == a[i + 2]) ans++;
    }
    if (a[n - 3] == a[n - 2] && a[n - 2] == a[n - 1]) ans++;
    co(ans);

    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:69:35: error: expected ',' or ';' before ')' token
   69 |             ll tmp = ++nxt[a[cnt]]);
      |                                   ^