fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long
  4. signed main()
  5. {
  6. int t;
  7. string s;
  8. cin>>t;
  9. while(t--)
  10. {
  11. cin>>s;
  12. int one=0,zero=0;
  13. one=count(s.begin(),s.end(),'1');
  14. zero=count(s.begin(),s.end(),'0');
  15. if(zero!=one)
  16. cout<<min(zero,one);
  17. else
  18. cout<<one-1;// zero
  19. cout<<endl;
  20. }
  21. }
Success #stdin #stdout 0.01s 5300KB
stdin
Standard input is empty
stdout
-1
-1