fork download
  1. #include <bits/stdc++.h>
  2. using ll=long long int;
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.  
  8. vector<int>a={1,1,1,1,2,2,2};
  9. int n=a.size();
  10. unordered_map<int,int>mp;
  11. for(int i=0;i<n;i++){
  12. mp[a[i]]++;
  13. }
  14. int ans=0;
  15. for(auto i:mp){
  16. if(i.second%3==0){
  17. ans=ans+i.second/3;
  18. }
  19. else if(i.second%2==0){
  20. ans=ans+i.second/2;
  21. }
  22. else{
  23. cout<<-1<<endl;
  24. return 0;
  25. }
  26. }
  27. cout<<ans<<endl;
  28.  
  29. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
3