/* -*- coding: utf-8 -*- * * 3847.cc: No.3847 Triple Balls Removal - yukicoder */ #include #include #include #include using namespace std; /* constant */ const int MAX_N = 1000000; /* typedef */ using pii = pair; using stpii = stack; /* global variables */ int as[MAX_N]; /* subroutines */ /* main */ int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", as + i); stpii q; int cnt = 0; for (int i = 0; i < n; i++) { if (! q.empty() && q.top().first == as[i]) { if (++(q.top().second) == 3) cnt++, q.pop(); } else q.push({as[i], 1}); } printf("%d\n", cnt * 3); return 0; }