-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path14583.cpp
49 lines (47 loc) · 991 Bytes
/
14583.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
string str;
cin>>str;
int n =str.size();
long long total1=0;
long long total0=0;
for(int i=0;i<n;i++)
if(str[i]=='1')
total1++;
else
total0++;
long long found1=0;
long long found0=0;
//cout<<total0<<" "<<total1<<endl;
//int one[n];
//int zero[n];
long long int sum=0;
for(int i=0;i<n;i++)
{
if(str[i]=='1')
{
long long r=(total0-found0);
if(r>1)
{
sum+=(found1*(r*(r-1))/2)%1000000007;
sum%=1000000007;
}
found1++;
}
else
{
if(found1>2)
{
sum+=((found1*(found1-1)*(found1-2))/6)%1000000007;
sum%=1000000007;
}
found0++;
}
//cout<<i<<" "<<sum<<endl;
}
cout<<sum<<endl;
return 0;
}