// https://yukicoder.me/submissions/349896 // // yukicoder: 120 傾向と対策:門松列(その1) // // 2019.6.3 bal4u // を大いに参考にした(丸パクリともいう) #pragma GCC optimize("Ofast") #pragma GCC target("avx2") char*mmap(); #define RD(v) int v=0;{int c;while(c=*r++-48,c>=0)v=v*10+c;} char wbuf[3000]; // 数値のハッシュ関数 #define HSIZ 1009 typedef struct { int v, f; } HASH; HASH hash[HSIZ+5], *hashend = hash+HSIZ; int ma1, ma2; main(){ char*r=mmap(0l,1536l*1024,1,2,0,0l); char*w=wbuf; RD(t); while(t--){ int ma1=0,ma2=0; memset(hash, 0, sizeof(hash)); RD(n); for(int i=n;i--;){ RD(l); // insert HASH *p = hash + l % HSIZ; while (p->v && p->v!=l) { if (++p == hashend) p = hash; } p->v = l, p->f++; if (p->f > ma1) ma1++; else if (p->f > ma2) ma2++; } int ans; 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); if(ans>=10) *w++=0x30|ans/10; *w++=0x30|ans%10; *w++=10; } write(1,wbuf,w-wbuf); _exit(0); }