#include #include #include #include bool isBambooCol(int a, int b, int c) { // a,b,cが門松列かの判定 if (a == b || a == c || b == c) return false; if (b < a && b < c) return true; if (b > a && b > c) return true; return false; } void calc() { int bamboo_no; // 竹の本数 std::cin >> bamboo_no; // <竹の長さ, 個数> std::map bamboo; for (int i = 0; i < bamboo_no; i++) { int bamboo_length; std::cin >> bamboo_length; bamboo[bamboo_length]++; } long long ans = 0; auto it = bamboo.begin(); // 1つ目のイテレータ auto jt = ++bamboo.begin(); // 2つ目のイテレータ if (jt == bamboo.end()) { std::cout << 0 << std::endl; return; } auto kt = ++(++bamboo.begin()); //3つ目のイテレータ while (kt != bamboo.end()) { it->second--; jt->second--; kt->second--; ans++; if (kt->second == 0) kt = bamboo.erase(kt); if (kt == bamboo.end()) break; if (jt->second == 0) { kt++; if (kt == bamboo.end()) break; jt = bamboo.erase(jt); } if (it->second == 0) { kt++; if (kt == bamboo.end()) break; jt++; it = bamboo.erase(it); } } std::cout << ans << std::endl; } int main() { int test_case; std::cin >> test_case; for (int i = 0; i < test_case; i++) { calc(); } return 0; }