#include typedef long long ll; typedef unsigned long long ull; #define FOR(i,a,b) for(int (i)=(a);i<(int)(b);i++) #define REP(i,n) FOR(i,0,n) #define RANGE(vec) (vec).begin(),(vec).end() using namespace std; class TrendAndCountermeasures_PineDecorationSequence1 { public: void solve(void) { int T; cin>>T; // O(T*N^2) REP(t,T) { int N; cin>>N; using DecPine = vector; //typedef array DecPine; vector dec_pines; REP(i,N) { int n = dec_pines.size(); int l,j; bool update = false; cin>>l; for (j = 0; j < n; ++j) { auto &x = dec_pines[j]; // 同じ高さになってしまう if ( any_of(RANGE(x),[l](int y){return y == l;}) ) continue; // すでに門松ができている if ( all_of(RANGE(x),[l](int y){return y > 0;}) ) continue; REP(k,3) { if (x[k] > 0) continue; x[k] = l; break; } update = true; break; } if (!update) dec_pines.push_back({l,-1,-1}); } int cnt = 0; for (auto x : dec_pines) { if (all_of(RANGE(x),[](int y){return y > 0;})) ++cnt; } cout<solve(); delete obj; return 0; } #endif