#include #include using namespace std; using ll = long long; using ld = long double; using pll = array; using vl = vector; template using vec = vector; template using vv = vec>; template using vvv = vv>; template using minpq = priority_queue, greater>; #define all(a) (a).begin(), (a).end() #define rep(i, n) for (ll i = 0; i < (n); ++i) #define reps(i, l, r) for (ll i = (l); i < (r); ++i) #define rrep(i, l, r) for (ll i = (r) - 1; i >= (l); --i) #define sz(x) (ll)(x).size() template bool chmax(T &a, const T &b) { return a < b ? a = b, true : false; } template bool chmin(T &a, const T &b) { return a > b ? a = b, true : false; } const ll INF = 1LL << 60; using ull = unsigned long long; using ulll = __uint128_t; void solve() { ll n; cin >> n; stack st; // col, cnt st.push({-1, 1}); rep(i, n) { ll a; cin >> a; if(st.top()[0] == a) st.top()[1]++; else st.push({a, 1}); if(st.top()[1] % 3 == 0) st.pop(); } ll ans = -1; while(!st.empty()) { auto [color, cnt] = st.top(); st.pop(); ans += cnt; // cout << " " << color << " " << cnt << endl; } cout << n - ans << endl; } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(20); int t = 1; // cin >> t; while (t--) { solve(); } }