module main; // https://yukicoder.me/submissions/19181 より import std; void main() { // 入力 int T = readln.chomp.to!int; // キューの処理 foreach (_; 0 .. T) { int N = readln.chomp.to!int; auto L = readln.split.to!(long[]); long sum = 0; long[long] map; foreach (l; L) { if (l !in map) map[l] = 1; else ++map[l]; sum += l; } if (map.length < 3) { writeln(0); continue; } auto que = redBlackTree!("a > b", true, long)(map.values); long ans = 0; while (true) { long a = que.front; que.removeFront; long b = que.front; que.removeFront; long c = que.front; que.removeFront; if (c <= 0) { writeln(ans); break; } ++ans; que.insert([a - 1, b - 1, c - 1]); } } }