#include #include using namespace std; using ll = long long; #define rep(i, a, b) for (ll i = a; i < b; ++i) #define rrep(i, a, b) for (ll i = a; i >= b; --i) #ifndef LOCAL #define cerr \ if (false) cerr #endif // --- 初期設定(入出力の高速化と小数15桁出力) --- struct Init { Init() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); } } init; // ------------------------------------------------ int main() { int n; cin >> n; stack st; ll ans = 0; rep(i, 0, n) { int inp; cin >> inp; st.push(inp); while (st.size() >= 3) { int t1 = st.top(); st.pop(); int t2 = st.top(); st.pop(); int t3 = st.top(); st.pop(); if (t1 != t2 || t2 != t3 || t3 != t1) { st.push(t3); st.push(t2); st.push(t1); break; } ans += 3; } } cout << ans << "\n"; return 0; } // Pre-written library: https://github.com/ssmbc2929bartok/cp-env