fork download
  1. #include <set>
  2. #include <map>
  3. #include <list>
  4. #include <cmath>
  5. #include <queue>
  6. #include <stack>
  7. #include <cstdio>
  8. #include <string>
  9. #include <vector>
  10. #include <cstdlib>
  11. #include <cstring>
  12. #include <sstream>
  13. #include <iomanip>
  14. #include <complex>
  15. #include <iostream>
  16. #include <algorithm>
  17.  
  18. #include <ctime>
  19. #include <deque>
  20. #include <bitset>
  21. #include <cctype>
  22. #include <utility>
  23. #include <cassert>
  24. using namespace std;
  25.  
  26. #define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
  27. #define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)
  28. #define REP(i,a) for(int i=0,_a=(a); i<_a; i++)
  29. #define EACH(it,a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
  30. #define SZ(S) ((int) ((S).size()))
  31.  
  32. #define DEBUG(x) { cout << #x << " = " << x << endl; }
  33. #define PR(a,n) { cout << #a << " = "; FOR(_,1,n) cout << a[_] << ' '; cout << endl; }
  34. #define PR0(a,n) { cout << #a << " = "; REP(_,n) cout << a[_] << ' '; cout << endl; }
  35.  
  36. int main() {
  37. ios :: sync_with_stdio(false); cin.tie(NULL);
  38. cout << (fixed) << setprecision(6);
  39. string s;
  40. while (cin >> s) {
  41. int one = 0, two = 0;
  42. int cnt1 = 0, cnt2 = 0;
  43.  
  44. REP(i,s.length()) {
  45. if (s[i] == '1') {
  46. one += cnt2;
  47. ++cnt1;
  48. }
  49. else {
  50. two += cnt1;
  51. ++cnt2;
  52. }
  53. }
  54. cout << min(one, two) << endl;
  55. }
  56. return 0;
  57. }
  58.  
  59.  
Success #stdin #stdout 0s 3432KB
stdin
221212
stdout
3