5460 {
5461 const unsigned int n = s.length();
5462 vector<unsigned int> prev0(n, 0);
5463 vector<unsigned int> prev1(n, 0);
5464 vector<unsigned int> post0(n, 0);
5465 vector<unsigned int> post1(n, 0);
5466 unsigned current0 = 0;
5467 unsigned current1 = 0;
5468 for(int i = 0; i < n; i++) {
5469 prev0[i] = current0;
5470 prev1[i] = current1;
5471 if(s[i] == '0') {
5472 current0++;
5473 } else {
5474 current1++;
5475 }
5476 }
5477 current0 = 0;
5478 current1 = 0;
5479 for(int i = n - 1; i >= 0; i--) {
5480 post0[i] = current0;
5481 post1[i] = current1;
5482 if(s[i] == '0') {
5483 current0++;
5484 } else {
5485 current1++;
5486 }
5487 }
5489 for(unsigned i = 0; i < n; i++) {
5490 if(s[i] == '0') {
5491 ans +=
static_cast<long long>(prev1[i]) * post1[i];
5492 } else {
5493 ans +=
static_cast<long long>(prev0[i]) * post0[i];
5494 }
5495 }
5497 }
vector< vector< int > > ans