// This solution should be WA! #include using namespace std; int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); int n; cin >> n; vector a(n); for (auto& x : a) cin >> x; deque s; auto removed = 0; for (const int x : a) { s.push_back(x); const int m = s.size(); if (m >= 3 && s[m - 1] == s[m - 2] && s[m - 2] == s[m - 3]) { s.resize(m - 3); removed += 3; } if (ssize(s) > 100000) s.pop_front(); } cout << removed << '\n'; }