class Solution {
public:
int minOperations(vector<int>& nums) {
unordered_map<int, int> cnt;
for (auto c: nums) cnt[c] ++ ;
int res = 0;
for (auto [k, v]: cnt) {
if (v == 1) return -1;
res += (v + 2) / 3;
}
return res;
}
};