// yukicoder: 120 傾向と対策:門松列(その1) // 2019.6.3 bal4u #include #include #if 1 #define gc() getchar_unlocked() #else #define gc() getchar() #endif int in() { int n = 0, c = gc(); do n = 10*n + (c & 0xf), c = gc(); while (c >= '0'); return n; } // 数値のハッシュ関数 #define HSIZ 1009 typedef struct { int v, f; } HASH; HASH hash[HSIZ+5], *hashend = hash+HSIZ; int ma1, ma2; void insert(int n) { HASH *p = hash + n % HSIZ; while (p->v) { if (p->v == n) { if (++(p->f) > ma1) ma1++; else if (p->f > ma2) ma2++; return; } if (++p == hashend) p = hash; } p->v = n, p->f = 1; if (p->f > ma1) ma1 = 1; else if (p->f > ma2) ma2 = 1; } int main() { int i, T, N, ans; T = in(); while (T--) { ma1 = ma2 = 0; memset(hash, 0, sizeof(hash)); N = in(); for (i = 0; i < N; i++) insert(in()); // printf("ma1=%d, ma2=%d\n", ma1, ma2); if (ma1 <= N/3) ans = N/3; else if ((N-ma1)/2 >= ma2) ans = (N-ma1)/2; else ans = N-ma1-ma2; printf("%d\n", ans); } return 0; }