simple prefix approach
include \n#define int long long int \nusing namespace std;\nint32_t main()\n{\n    \nstring s;\ncin>>s;\n\n  int n =s.size();\n        int a[n];\n \n    for(int
#include <bits/stdc++.h>\n#define int long long int \nusing namespace std;\nint32_t main()\n{\n    \nstring s;\ncin>>s;\n\n  int n =s.size();\n        int a[n];\n \n    for(int i = 0; i < n; i++)\n    {\n\n        if(s[i]==\'1\'){\n            a[i] = 1;\n        }\n        else{\n            a[i]=0;\n        }\n    }\n \n    int odd[n + 1];\n    int even[n + 1];\n \n    odd[0] = 0;\n    even[0] = 0;\n \n    for(int i = 0; i < n; i++)\n    {\n         \n        \n        if (i % 2 != 0)\n        {\n             \n            \n            odd[i + 1] = odd[i] + (a[i] == 1 ? 1 : 0);\n            even[i + 1] = even[i] + (a[i] == 0 ? 1 : 0);\n        }\n \n        \n        else\n        {\n             \n            \n            odd[i + 1] = odd[i] + (a[i] == 0 ? 1 : 0);\n            even[i + 1] = even[i] + (a[i] == 1 ? 1 : 0);\n        }\n    }\n \n\n    for(int i =1;i<=n;i++){\n        cout<<odd[i]<<" ";\n    }\n    cout<<endl;\n    for(int i =1;i<=n;i++){\n        cout<<even[i]<<" ";\n    }\n    cout<<endl;\n    int minimum = min(odd[n], even[n]);\n\n    if(n%2!=0){\n    for(int i = 0; i < n; i++)\n    {\n\n\n            minimum = min(minimum, odd[n] - odd[i + 1] + even[i + 1]);\n            minimum = min(minimum, even[n] - even[i + 1] + odd[i + 1]);\n\n    }\n}\n \ncout<<minimum;\nreturn 0;\n}\n
[]