#pragma GCC optimize("Ofast,unroll-loops") #include using namespace std; #define int long long const int NR=2e5+10; int n,ans=1e18,cnt0,cnt1,out[NR]; string s; vectoridx; #define pb emplace_back int calc(int l1,int l2){ int L=(l1+cnt1)%n,R=n; if(!L)L=n; int ansl=0,ansr=0; if(idx[l2]<=l1+n){ if(L<=(idx[l2]+n-1)%n+1&&(idx[l2]+n-1)%n+1<=R&&out[idx[l2]%n])ansl=l1+n-idx[l2]-1; else ansl=l1+n-idx[l2]; // printf("bit[l2]:%lld ansl:%lld %lld %lld %lld\n",bit[l2],ansl,sp_l<=(bit[l2]+n-1)%n+1,sp_l,(bit[l2]+n-1)%n+1); } // cout<>n>>s; for(int i=0;i=0;i--){ if(s[i]=='1')out[i]=0; else break; } } for(int l1=0;l1