    #include<bits/stdc++.h>
    #include<algorithm>
    #include<cmath>
    #include<climits>
    using namespace std;
    typedef long long int lli;
    typedef vector<int> vi;
    typedef vector<long long int> vlli;
    typedef pair<int,int> pii;
    typedef pair<long long int,long long int> plli;
    typedef vector< vi > vvi ;
    typedef vector< vlli > vvlli  ;
    #define fi(i,a,b) for(int i=a;i<=b;i++)
    #define flli(i,a,b) for(long long int i=a;i<=b;i++)
    #define bi(i,a,b) for(int i=a;i>=b;i--)
    #define blli(i,a,b) for(long long int i=a;i>=b;i--)
    #define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
    #define all(x) x.begin(),x.end()
    #define sz(x) x.size()
    #define pi 2*acos(0.0)
    #define pb push_back
    #define tr(v,it) for(decltype(v.begin()) it=v.begin();it!=v.end();it++)
    #define present(v,num) (v.find(num)!=v.end())
    #define cpresent(v,num) (find(v.begin(),v.end(),num)!=v.end())
    #define pq priority_queue
    #define mp make_pair
    const int inf=INT_MAX;
    const lli INF =LLONG_MAX;
    const lli mod = 1e9+7;
    int main() {
        #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        #endif
        fast;
        lli n;cin>>n;
        vector<plli> points(n);
        flli(i,0,n-1)
        {
        	cin>>points[i].first>>points[i].second;
        	points[i].first+=1e6;
        	points[i].second+=1e6;
        }
        lli div=1;
        while(1)
        {
        	//odd odd and even even will give even distance
        	//odd even and even odd will give even distance
     		vvlli count(2,vlli(2,0));
     		flli(i,0,n-1)
     		{
     			lli temp1=points[i].first/div;
        		lli temp2=points[i].second/div;
        		count[temp1%2][temp2%2]++;
     		}
        	if(count[0][0] + count[1][1]>0 && count[1][0] + count[0][1]>0)
        	{
        		cout<<count[0][0]+count[1][1]<<endl;
        		flli(i,0,n-1)
        		{
        			lli temp1=points[i].first/div;
        			lli temp2=points[i].second/div;
        			if( (temp1%2==0 && temp2%2==0) || (temp1%2==1 && temp2%2==1))
        				cout<<i+1<<" ";
        		}
        		cout<<endl;
        		return 0;
        	}
        	if(count[0][0]+count[0][1]>0 && count[1][1]+count[1][0]>0)
        	{
        		cout<<count[0][0]+count[0][1]<<endl;
        		flli(i,0,n-1)
        		{
        			lli temp1=points[i].first/div;
        			lli temp2=points[i].second/div;
        			if( (temp1%2==0 && temp2%2==0) || (temp1%2==0 && temp2%2==1))
        				cout<<i+1<<" ";
        		}
        		cout<<endl;
        		return 0;
        	}
        	if(count[0][0]+count[1][0]>0 && count[1][1]+count[0][1]>0)
        	{
        		cout<<count[0][0]+count[1][0]<<endl;
        		flli(i,0,n-1)
        		{
        			lli temp1=points[i].first/div;
        			lli temp2=points[i].second/div;
        			if( (temp1%2==0 && temp2%2==0) || (temp1%2==1 && temp2%2==0))
        				cout<<i+1<<" ";
        		}
        		cout<<endl;
        		return 0;
        	}
        	div=div*2;
        }
        cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
        return 0;
    }


    #include<bits/stdc++.h>
    #include<algorithm>
    #include<cmath>
    #include<climits>
    using namespace std;
    typedef long long int lli;
    typedef vector<int> vi;
    typedef vector<long long int> vlli;
    typedef pair<int,int> pii;
    typedef pair<long long int,long long int> plli;
    typedef vector< vi > vvi ;
    typedef vector< vlli > vvlli  ;
    #define fi(i,a,b) for(int i=a;i<=b;i++)
    #define flli(i,a,b) for(long long int i=a;i<=b;i++)
    #define bi(i,a,b) for(int i=a;i>=b;i--)
    #define blli(i,a,b) for(long long int i=a;i>=b;i--)
    #define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
    #define all(x) x.begin(),x.end()
    #define sz(x) x.size()
    #define pi 2*acos(0.0)
    #define pb push_back
    #define tr(v,it) for(decltype(v.begin()) it=v.begin();it!=v.end();it++)
    #define present(v,num) (v.find(num)!=v.end())
    #define cpresent(v,num) (find(v.begin(),v.end(),num)!=v.end())
    #define pq priority_queue
    #define mp make_pair
    const int inf=INT_MAX;
    const lli INF =LLONG_MAX;
    const lli mod = 1e9+7;
    int main() {
        #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        #endif
        fast;
        lli n;cin>>n;
        vector<plli> points(n);
        flli(i,0,n-1)
        {
        	cin>>points[i].first>>points[i].second;
        	points[i].first+=1e6;
        	points[i].second+=1e6;
        }
        lli div=1;
        while(1)
        {
        	//odd odd and even even will give even distance
        	//odd even and even odd will give even distance
     		vvlli count(2,vlli(2,0));
     		flli(i,0,n-1)
     		{
     			lli temp1=points[i].first/div;
        		lli temp2=points[i].second/div;
        		count[temp1%2][temp2%2]++;
     		}
        	if(count[0][0] + count[1][1]>0 && count[1][0] + count[0][1]>0)
        	{
        		cout<<count[0][0]+count[1][1]<<endl;
        		flli(i,0,n-1)
        		{
        			lli temp1=points[i].first/div;
        			lli temp2=points[i].second/div;
        			if( (temp1%2==0 && temp2%2==0) || (temp1%2==1 && temp2%2==1))
        				cout<<i+1<<" ";
        		}
        		cout<<endl;
        		return 0;
        	}
        	if(count[0][0]+count[0][1]>0 && count[1][1]+count[1][0]>0)
        	{
        		cout<<count[0][0]+count[0][1]<<endl;
        		flli(i,0,n-1)
        		{
        			lli temp1=points[i].first/div;
        			lli temp2=points[i].second/div;
        			if( (temp1%2==0 && temp2%2==0) || (temp1%2==0 && temp2%2==1))
        				cout<<i+1<<" ";
        		}
        		cout<<endl;
        		return 0;
        	}
        	div=div*2;
        }
        cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
        return 0;
    }


    #include<bits/stdc++.h>
    #include<algorithm>
    #include<cmath>
    #include<climits>
    using namespace std;
    typedef long long int lli;
    typedef vector<int> vi;
    typedef vector<long long int> vlli;
    typedef pair<int,int> pii;
    typedef pair<long long int,long long int> plli;
    typedef vector< vi > vvi ;
    typedef vector< vlli > vvlli  ;
    #define fi(i,a,b) for(int i=a;i<=b;i++)
    #define flli(i,a,b) for(long long int i=a;i<=b;i++)
    #define bi(i,a,b) for(int i=a;i>=b;i--)
    #define blli(i,a,b) for(long long int i=a;i>=b;i--)
    #define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
    #define all(x) x.begin(),x.end()
    #define sz(x) x.size()
    #define pi 2*acos(0.0)
    #define pb push_back
    #define tr(v,it) for(decltype(v.begin()) it=v.begin();it!=v.end();it++)
    #define present(v,num) (v.find(num)!=v.end())
    #define cpresent(v,num) (find(v.begin(),v.end(),num)!=v.end())
    #define pq priority_queue
    #define mp make_pair
    const int inf=INT_MAX;
    const lli INF =LLONG_MAX;
    const lli mod = 1e9+7;
    int main() {
        #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        #endif
        fast;
        lli n;cin>>n;
        vector<plli> points(n);
        flli(i,0,n-1)
        {
        	cin>>points[i].first>>points[i].second;
        	points[i].first+=1e6;
        	points[i].second+=1e6;
        }
        lli div=1;
        while(1)
        {
        	vlli g1;
        	vlli g2;
        	flli(i,0,n-1)
        	{
        		lli temp1=points[i].first/div;
        		lli temp2=points[i].second/div;
        		if(temp1%2==0 && temp2%2==0)g1.pb(i);
        		else if(temp1%2==0 && temp2%2==0)g1.pb(i);
        		else if(temp1%2==0 && temp2%2==1)g2.pb(i);
        		else g2.pb(i);
        	}
        	if(sz(g1)!=0 && sz(g2)!=0)
        	{
        		cout<<sz(g1)<<endl;
        		tr(g1,it)cout<<*it+1<<" ";
        		cout<<endl;
        		return 0;
        	}
        	div=div*2;
        }
        cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
        return 0;
    }


#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
const int MAX_N=2000;
int n;
int x[MAX_N],y[MAX_N];
void solve(){
    while(1){
        int num[4]={0};
        for(int i=1;i<=n;i++){
            int a=abs(x[i]%2),b=abs(y[i]%2);
            if(a==0&&b==0)num[0]++;
            if(a==0&&b==1)num[1]++;
            if(a==1&&b==0)num[2]++;
            if(a==1&&b==1)num[3]++;
        }
        int cnt=0;
        for(int i=0;i<4;i++)cnt+=(bool)num[i];

            if(num[0]+num[3]>0&&num[1]+num[2]>0){
                printf("%d\n",num[0]+num[3]);
                for(int i=1;i<=n;i++){
                    int a=abs(x[i]%2),b=abs(y[i]%2);
                    if(a==1&&b==1)printf("%d ",i);
                    else if(a==0&&b==0)printf("%d ",i);
                }
                printf("\n");
                break;
            }
            if(num[0]+num[2]>0&&num[1]+num[3]>0){
                printf("%d\n",num[0]+num[2]);
                for(int i=1;i<=n;i++){
                    int a=abs(x[i]%2),b=abs(y[i]%2);
                    if(a==1&&b==0)printf("%d ",i);
                    else if(a==0&&b==0)printf("%d ",i);
                }
                printf("\n");
                break;
            }

            for(int i=1;i<=n;i++){
                x[i]=x[i]/2,y[i]=y[i]/2;

        }
    }
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d%d",&x[i],&y[i]);
    }
    if(n==2){
        printf("%d\n",1);
        printf("%d\n",1);
        return 0;
    }
    solve();

}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#define rep(x, l, r) for(int x = l; x <= r; x++)
#define repd(x, r, l) for(int x = r; x >= l; x--)
#define clr(x, y) memset(x, y, sizeof(x))
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define MAXN 1005
#define fi first
#define se second
#define SZ(x) ((int)x.size())
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
const int INF = 1 << 30;
const int p = 1000000009;
int lowbit(int x){ return x & (-x);}
int fast_power(int a, int b){ int x; for(x = 1; b; b >>= 1){ if(b & 1) x = 1ll * x * a % p; a = 1ll * a * a % p;} return x % p;}

vi ans;
int x[MAXN], y[MAXN], cnt[2][2];

int main(){
	int n;
	scanf("%d", &n);
	rep(i, 1, n) scanf("%d%d", &x[i], &y[i]);
	while(1){
		clr(cnt, 0);
		rep(i, 1, n) cnt[x[i] & 1][y[i] & 1]++;
		if(cnt[0][1] + cnt[1][0] > 0 && cnt[0][0] + cnt[1][1] > 0){
			rep(i, 1, n)
				if((x[i] & 1) ^ (y[i] & 1)) ans.pb(i);
			printf("%d\n", SZ(ans));
			rep(i, 0, SZ(ans) - 1) printf("%d ", ans[i]);
			puts("");
			return 0;
		}
		if(cnt[0][0] + cnt[0][1] > 0 && cnt[1][0] + cnt[1][1] > 0){
			rep(i, 1, n)
				if(x[i] & 1) ans.pb(i);
			printf("%d\n", SZ(ans));
			rep(i, 0, SZ(ans) - 1) printf("%d ", ans[i]);
			puts("");
			return 0;
		}
		rep(i, 1, n){
			x[i] >>= 1;
			y[i] >>= 1;
		}
	}
    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
const int MAX_N=2000;
int n;
int x[MAX_N],y[MAX_N];
void solve(){
    while(1){
        int num[4]={0};
        for(int i=1;i<=n;i++){
            int a=abs(x[i]%2),b=abs(y[i]%2);
            if(a==0&&b==0)num[0]++;
            if(a==0&&b==1)num[1]++;
            if(a==1&&b==0)num[2]++;
            if(a==1&&b==1)num[3]++;
        }
        int cnt=0;
        for(int i=0;i<4;i++){
            cnt+=(bool)(num[i]);
        }
        if(cnt>=2){
            if(cnt>2){
                printf("%d\n",num[0]+num[3]);
                for(int i=1;i<=n;i++){
                    int a=abs(x[i]%2),b=abs(y[i]%2);
                    if(a==0&&b==0)printf("%d ",i);
                    else if(a==1&&b==1)printf("%d ",i);
                }
                printf("\n");
            }
            else{
                if(num[1]&&num[2]){
                    printf("%d\n",num[1]);
                    for(int i=1;i<=n;i++){
                        int a=abs(x[i]%2),b=abs(y[i]%2);
                        if(a==0&&b==1)printf("%d ",i);
                    }
                    printf("\n");
                }
                else if(num[0]&&num[3]){
                    printf("%d\n",num[0]);
                    for(int i=1;i<=n;i++){
                        int a=abs(x[i]%2),b=abs(y[i]%2);
                        if(a==0&&b==0)printf("%d ",i);
                    }
                    printf("\n");
                }
                else if(num[0]){
                    printf("%d\n",num[0]);
                    for(int i=1;i<=n;i++){
                        int a=abs(x[i]%2),b=abs(y[i]%2);
                        if(a==0&&b==0)printf("%d ",i);
                    }
                    printf("\n");
                }
                else{
                    printf("%d\n",num[3]);
                    for(int i=1;i<=n;i++){
                        int a=abs(x[i]%2),b=abs(y[i]%2);
                        if(a==1&&b==1)printf("%d ",i);
                    }
                    printf("\n");
                }
            }
            break;
        }
        else{
            for(int i=1;i<=n;i++){
                x[i]/=2,y[i]/=2;
            }
        }
    }
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d%d",&x[i],&y[i]);
    }
    if(n==2){
        printf("%d\n",1);
        printf("%d\n",1);
        return 0;
    }
    solve();

}


#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
const int MAX_N=2000;
int n;
int x[MAX_N],y[MAX_N];
void solve(){
    while(1){
        int num[4]={0};
        for(int i=1;i<=n;i++){
            int a=abs(x[i]%2),b=abs(y[i]%2);
            if(a==0&&b==0)num[0]++;
            if(a==0&&b==1)num[1]++;
            if(a==1&&b==0)num[2]++;
            if(a==1&&b==1)num[3]++;
        }
        int cnt=0;
        for(int i=0;i<4;i++)cnt+=(bool)num[i];
        if(cnt>=2){
            if(num[0]){
                printf("%d\n");
                for(int i=1;i<=n;i++){
                    int a=abs(x[i]%2),b=abs(y[i]%2);
                    if(a==0&&b==0){
                        printf("%d ");
                    }
                }
                printf("\n");
            }
            else if(num[1]){
                printf("%d\n");
                for(int i=1;i<=n;i++){
                    int a=abs(x[i]%2),b=abs(y[i]%2);
                    if(a==0&&b==1){
                        printf("%d ");
                    }
                }
                printf("\n");
            }
            else if(num[2]){
                printf("%d\n");
                for(int i=1;i<=n;i++){
                    int a=abs(x[i]%2),b=abs(y[i]%2);
                    if(a==1&&b==0){
                        printf("%d ",i);
                    }
                }
                printf("\n");
            }
\

        }
        else{
            for(int i=1;i<=n;i++){
                x[i]/=2,y[i]/=2;
            }
        }
    }
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d%d",&x[i],&y[i]);
    }
    if(n==2){
        printf("%d\n",1);
        printf("%d\n",1);
        return 0;
    }
    solve();

}


#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
const int MAX_N=2000;
int n;
int x[MAX_N],y[MAX_N];
void solve(){
    while(1){
        int num[4]={0};
        for(int i=1;i<=n;i++){
            int a=abs(x[i]%2),b=abs(y[i]%2);
            if(a==0&&b==0)num[0]++;
            if(a==0&&b==1)num[1]++;
            if(a==1&&b==0)num[2]++;
            if(a==1&&b==1)num[3]++;
        }
        int cnt=0;
        for(int i=0;i<4;i++)cnt+=(bool)num[i];
        if(cnt>=2){
            if(num[0]){
                printf("%d\n",num[0]);
                for(int i=1;i<=n;i++){
                    int a=abs(x[i]%2),b=abs(y[i]%2);
                    if(a==0&&b==0){
                        printf("%d ",i);
                    }
                }
                printf("\n");
            }
            else if(num[1]){
                printf("%d\n",num[1]);
                for(int i=1;i<=n;i++){
                    int a=abs(x[i]%2),b=abs(y[i]%2);
                    if(a==0&&b==1){
                        printf("%d ",i);
                    }
                }
                printf("\n");
            }
            else if(num[2]){
                printf("%d\n",num[2]);
                for(int i=1;i<=n;i++){
                    int a=abs(x[i]%2),b=abs(y[i]%2);
                    if(a==1&&b==0){
                        printf("%d ",i);
                    }
                }
                printf("\n");
            }

        break;
        }
        else{
            for(int i=1;i<=n;i++){
                x[i]/=2,y[i]/=2;
            }
        }
    }
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d%d",&x[i],&y[i]);
    }
    if(n==2){
        printf("%d\n",1);
        printf("%d\n",1);
        return 0;
    }
    solve();

}


#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
const int MAX_N=2000;
int n;
int x[MAX_N],y[MAX_N];
void solve(){
    while(1){
        int num[4]={0};
        for(int i=1;i<=n;i++){
            int a=abs(x[i]%2),b=abs(y[i]%2);
            if(a==0&&b==0)num[0]++;
            if(a==0&&b==1)num[1]++;
            if(a==1&&b==0)num[2]++;
            if(a==1&&b==1)num[3]++;
        }
        int cnt=0;
        for(int i=0;i<4;i++){
            cnt+=(bool)(num[i]);
        }
        if(cnt>=2){
            if(num[1]||num[2]){
                printf("%d\n",num[0]+num[3]);

                for(int i=1;i<=n;i++){
                    int a=abs(x[i]%2),b=abs(y[i]%2);
                    if(a==0&&b==0)printf("%d ",i);
                    else if(a==1&&b==1)printf("%d ",i);
                }
                printf("\n");
            }
            else{
                printf("%d\n",num[0]);
                for(int i=1;i<=n;i++){
                    int a=abs(x[i]%2),b=abs(y[i]%2);
                    if(a==0&&b==0)printf("%d ",i);
                }
                printf("\n");
            }
            break;
        }
        else{
            for(int i=1;i<=n;i++){
                x[i]/=2,y[i]/=2;
            }
        }
    }
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d%d",&x[i],&y[i]);
    }
    solve();

}


#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
const int MAX_N=2000;
int n;
int x[MAX_N],y[MAX_N];
void solve(){
    while(1){
        int num[4]={0};
        for(int i=1;i<=n;i++){
            int a=abs(x[i]&1),b=abs(y[i]&2);
            if(a==0&&b==0)num[0]++;
            if(a==0&&b==1)num[1]++;
            if(a==1&&b==0)num[2]++;
            if(a==1&&b==1)num[3]++;
        }

            if(num[0]+num[3]>0&&num[1]+num[2]>0){
                printf("%d\n",num[0]+num[3]);
                for(int i=1;i<=n;i++){
                    int a=abs(x[i]&1),b=abs(y[i]&1);
                    if(a==1&&b==1)printf("%d ",i);
                    else if(a==0&&b==0)printf("%d ",i);
                }
                printf("\n");
                break;
            }
            if(num[0]+num[2]>0&&num[1]+num[3]>0){
                printf("%d\n",num[0]+num[2]);
                for(int i=1;i<=n;i++){
                    int a=abs(x[i]&1),b=abs(y[i]&1);
                    if(a==1&&b==0)printf("%d ",i);
                    else if(a==0&&b==0)printf("%d ",i);
                }
                printf("\n");
                break;
            }

            for(int i=1;i<=n;i++){
                x[i]=x[i]/2,y[i]=y[i]/2;

        }
    }
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d%d",&x[i],&y[i]);
    }
    if(n==2){
        printf("%d\n",1);
        printf("%d\n",1);
        return 0;
    }
    solve();

}


#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
const int MAX_N=2000;
int n;
int x[MAX_N],y[MAX_N];
void solve(){
    while(1){
        int num[2]={0,0};
        for(int i=1;i<=n;i++){
            int tmp=x[i]+y[i];
            num[tmp%2]++;
        }

        if(num[0]&&num[1]){
            printf("%d\n",num[0]);
            for(int i=1;i<=n;i++){
                if((x[i]+y[i])%2==0){
                    printf("%d ",i);
                }
            }
            printf("\n");
            break;
        }
        else{
            for(int i=1;i<=n;i++){
                x[i]/=2,y[i]/=2;
            }
        }
    }
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d%d",&x[i],&y[i]);
    }
    solve();

}


#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
const int MAX_N=2000;
int n;
int x[MAX_N],y[MAX_N];
void solve(){
    while(1){
        int num[4]={0};
        for(int i=1;i<=n;i++){
            int a=abs(x[i]%2),b=abs(y[i]%2);
            if(a==0&&b==0)num[0]++;
            if(a==0&&b==1)num[1]++;
            if(a==1&&b==0)num[2]++;
            if(a==1&&b==1)num[3]++;
        }
        int cnt=0;
        for(int i=0;i<4;i++)cnt+=(bool)num[i];
        if(cnt>=2){
            if(num[0]+num[3]>0&&num[1]+num[2]>0){
                printf("%d\n",num[0]+num[3]);
                for(int i=1;i<=n;i++){
                    int a=abs(x[i]%2),b=abs(y[i]%2);
                    if(a==1&&b==1)printf("%d ",i);
                    else if(a==0&&b==0)printf("%d ",i);
                }
                printf("\n");
            }
            else if(num[0]+num[2]>0&&num[1]+num[3]>0){
                printf("%d\n",num[0]+num[2]);
                for(int i=1;i<=n;i++){
                    int a=abs(x[i]%2),b=abs(y[i]%2);
                    if(a==1&&b==0)printf("%d ",i);
                    else if(a==0&&b==0)printf("%d ",i);
                }
                printf("\n");
            }
            break;
        }
        else{
            for(int i=1;i<=n;i++){
                x[i]/=2,y[i]/=2;
            }
        }
    }
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d%d",&x[i],&y[i]);
    }
    if(n==2){
        printf("%d\n",1);
        printf("%d\n",1);
        return 0;
    }
    solve();

}


#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
const int MAX_N=2000;
int n;
int x[MAX_N],y[MAX_N];
void solve(){
    while(1){
        int num[4]={0};
        for(int i=1;i<=n;i++){
            int a=abs(x[i]%2),b=abs(y[i]%2);
            if(a==0&&b==0)num[0]++;
            if(a==0&&b==1)num[1]++;
            if(a==1&&b==0)num[2]++;
            if(a==1&&b==1)num[3]++;
        }
        int cnt=0;
        for(int i=0;i<4;i++){
            cnt+=(bool)(num[i]);
        }
        if(cnt>=2){
            if(cnt>2){
                printf("%d\n",num[0]+num[3]);
                for(int i=1;i<=n;i++){
                    int a=abs(x[i]%2),b=abs(y[i]%2);
                    if(a==0&&b==0)printf("%d ",i);
                    else if(a==1&&b==1)printf("%d ",i);
                }
                printf("\n");
            }
            else{
                if(num[1]&&num[2]){
                    printf("%d\n",num[1]);
                    for(int i=1;i<=n;i++){
                        int a=abs(x[i]%2),b=abs(y[i]%2);
                        if(a==0&&b==1)printf("%d ",i);
                    }
                    printf("\n");
                }
                else if(num[0]&&num[3]){
                    printf("%d\n",num[0]);
                    for(int i=1;i<=n;i++){
                        int a=abs(x[i]%2),b=abs(y[i]%2);
                        if(a==0&&b==0)printf("%d ",i);
                    }
                    printf("\n");
                }
                else if(num[0]){
                    printf("%d\n",num[0]);
                    for(int i=1;i<=n;i++){
                        int a=abs(x[i]%2),b=abs(y[i]%2);
                        if(a==0&&b==0)printf("%d ",i);
                    }
                    printf("\n");
                }
                else{
                    printf("%d\n",num[3]);
                    for(int i=1;i<=n;i++){
                        int a=abs(x[i]%2),b=abs(y[i]%2);
                        if(a==1&&b==1)printf("%d ",i);
                    }
                    printf("\n");
                }
            }
            break;
        }
        else{
            for(int i=1;i<=n;i++){
                x[i]/=2,y[i]/=2;
            }
        }
    }
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d%d",&x[i],&y[i]);
    }
    solve();

}


#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
const int MAX_N=2000;
int n;
int x[MAX_N],y[MAX_N];
void solve(){
    while(1){
        int num[4]={0};
        for(int i=1;i<=n;i++){
            int a=abs(x[i]%2),b=abs(y[i]%2);
            if(a==0&&b==0)num[0]++;
            if(a==0&&b==1)num[1]++;
            if(a==1&&b==0)num[2]++;
            if(a==1&&b==1)num[3]++;
        }
        int cnt=0;
        for(int i=0;i<4;i++){
            cnt+=(bool)(num[i]);
        }
        if(cnt>=2){
            if(cnt>2){
                printf("%d\n",num[0]+num[3]);
                for(int i=1;i<=n;i++){
                    int a=abs(x[i]%2),b=abs(y[i]%2);
                    if(a==0&&b==0)printf("%d ",i);
                    else if(a==1&&b==1)printf("%d ",i);
                }
                printf("\n");
            }
            else{
                if(num[1]&&num[2]){
                    printf("%d\n",num[1]);
                    for(int i=1;i<=n;i++){
                        int a=abs(x[i]%2),b=abs(y[i]%2);
                        if(a==0&&b==1)printf("%d ",i);
                    }
                    printf("\n");
                }
                else if(num[0]&&num[3]){
                    printf("%d\n",num[0]);
                    for(int i=1;i<=n;i++){
                        int a=abs(x[i]%2),b=abs(y[i]%2);
                        if(a==0&&b==0)printf("%d ",i);
                    }
                    printf("\n");
                }
                else if(num[0]){
                    printf("%d\n",num[0]);
                    for(int i=1;i<=n;i++){
                        int a=abs(x[i]%2),b=abs(y[i]%2);
                        if(a==0&&b==0)printf("%d ",i);
                    }
                    printf("\n");
                }
                else{
                    printf("%d\n",num[1]);
                    for(int i=1;i<=n;i++){
                        int a=abs(x[i]%2),b=abs(y[i]%2);
                        if(a==0&&b==1)printf("%d ",i);
                    }
                    printf("\n");
                }
            }
            break;
        }
        else{
            for(int i=1;i<=n;i++){
                x[i]/=2,y[i]/=2;
            }
        }
    }
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d%d",&x[i],&y[i]);
    }
    if(n==2){
        printf("%d\n",1);
        printf("%d\n",1);
        return 0;
    }
    solve();

}


#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
const int MAX_N=2000;
int n;
int x[MAX_N],y[MAX_N];
void solve(){
    while(1){
        int num[4]={0};
        for(int i=1;i<=n;i++){
            int a=abs(x[i]%2),b=abs(y[i]%2);
            if(a==0&&b==0)num[0]++;
            if(a==0&&b==1)num[1]++;
            if(a==1&&b==0)num[2]++;
            if(a==1&&b==1)num[3]++;
        }
        int cnt=0;
        for(int i=0;i<4;i++)cnt+=(bool)num[i];
        if(cnt>=2){
            if(num[0]){
                printf("%d\n");
                for(int i=1;i<=n;i++){
                    int a=abs(x[i]%2),b=abs(y[i]%2);
                    if(a==0&&b==0){
                        printf("%d ");
                    }
                }
                printf("\n");
            }
            else if(num[1]){
                printf("%d\n");
                for(int i=1;i<=n;i++){
                    int a=abs(x[i]%2),b=abs(y[i]%2);
                    if(a==0&&b==1){
                        printf("%d ");
                    }
                }
                printf("\n");
            }
            else if(num[2]){
                printf("%d\n");
                for(int i=1;i<=n;i++){
                    int a=abs(x[i]%2),b=abs(y[i]%2);
                    if(a==1&&b==0){
                        printf("%d ",i);
                    }
                }
                printf("\n");
            }

        break;
        }
        else{
            for(int i=1;i<=n;i++){
                x[i]/=2,y[i]/=2;
            }
        }
    }
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d%d",&x[i],&y[i]);
    }
    if(n==2){
        printf("%d\n",1);
        printf("%d\n",1);
        return 0;
    }
    solve();

}


#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
const int MAX_N=2000;
int n;
int x[MAX_N],y[MAX_N];
void solve(){
    while(1){
        int num[4]={0};
        for(int i=1;i<=n;i++){
            int a=abs(x[i]%2),b=abs(y[i]%2);
            if(a==0&&b==0)num[0]++;
            if(a==0&&b==1)num[1]++;
            if(a==1&&b==0)num[2]++;
            if(a==1&&b==1)num[3]++;
        }
        int cnt=0;
        for(int i=0;i<4;i++)cnt+=(bool)num[i];

            if(num[0]+num[3]>0&&num[1]+num[2]>0){
                printf("%d\n",num[0]+num[3]);
                for(int i=1;i<=n;i++){
                    int a=abs(x[i]%2),b=abs(y[i]%2);
                    if(a==1&&b==1)printf("%d ",i);
                    else if(a==0&&b==0)printf("%d ",i);
                }
                printf("\n");
                break;
            }
            else if(num[0]+num[2]>0&&num[1]+num[3]>0){
                printf("%d\n",num[0]+num[2]);
                for(int i=1;i<=n;i++){
                    int a=abs(x[i]%2),b=abs(y[i]%2);
                    if(a==1&&b==0)printf("%d ",i);
                    else if(a==0&&b==0)printf("%d ",i);
                }
                printf("\n");
                break;
            }

        else{
            for(int i=1;i<=n;i++){
                x[i]/=2,y[i]/=2;
            }
        }
    }
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d%d",&x[i],&y[i]);
    }
    if(n==2){
        printf("%d\n",1);
        printf("%d\n",1);
        return 0;
    }
    solve();

}


import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.sqrt;
import static java.lang.System.exit;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class F {

	static class LongLongMap {

		static final long EMPTY = Long.MIN_VALUE;

		long data[] = new long[4];
		{
			data[0] = EMPTY;
			data[2] = EMPTY;
		}
		int size = 0;

		boolean isEmpty() {
			return size == 0;
		}

		int size() {
			return size;
		}

		void clear() {
			for (int i = 0; i < data.length; i += 2) {
				data[i] = EMPTY;
			}
			size = 0;
		}

		static int hash(long key) {
			long hash = key * 1000000007;
			hash ^= hash >> 16;
			hash ^= hash >> 24;
			return (int) hash;
		}

		boolean have(long key) {
			if (key == EMPTY) {
				throw new IllegalArgumentException();
			}
			for (int mask = data.length - 2, i = hash(key) & mask;; i = (i - 1) & mask) {
				long cur = data[i];
				if (cur == key) {
					return true;
				} else if (cur == EMPTY) {
					return false;
				}
			}
		}

		long get(long key, long default_) {
			if (key == EMPTY) {
				throw new IllegalArgumentException();
			}
			for (int mask = data.length - 2, i = hash(key) & mask;; i = (i - 1) & mask) {
				long cur = data[i];
				if (cur == key) {
					return data[i + 1];
				} else if (cur == EMPTY) {
					return default_;
				}
			}
		}

		static long[] resize(long data[], int newCapacity) {
			int oldCapacity = data.length;
			long ndata[] = new long[newCapacity];
			for (int i = 0; i < newCapacity; i += 2) {
				ndata[i] = EMPTY;
			}
			for (int mask = newCapacity - 2, i = 0; i < oldCapacity; i += 2) {
				long cur = data[i];
				if (cur == EMPTY) {
					continue;
				}
				for (int j = hash(cur) & mask;; j = (j - 1) & mask) {
					if (ndata[j] == EMPTY) {
						ndata[j] = cur;
						ndata[j + 1] = data[i + 1];
						break;
					}
				}
			}
			return ndata;
		}

		void set(long key, long value) {
			if (key == EMPTY) {
				throw new IllegalArgumentException();
			}
			long data[] = this.data;
			for (int capacity = data.length, mask = capacity - 2, i = hash(key) & mask;; i = (i - 1) & mask) {
				long cur = data[i];
				if (cur == key) {
					data[i + 1] = value;
					return;
				} else if (cur == EMPTY) {
					data[i] = key;
					data[i + 1] = value;
					if (++size > capacity >> 2) {
						this.data = resize(data, capacity << 1);
					}
					return;
				}
			}
		}

		void delete(long key) {
			if (key == EMPTY) {
				throw new IllegalArgumentException();
			}
			long data[] = this.data;
			for (int capacity = data.length, mask = capacity - 2, i = hash(key) & mask;; i = (i - 1) & mask) {
				long cur = data[i];
				if (cur == key) {
					for (int j = i;;) {
						cur = data[j = (j - 1) & mask];
						if (cur == EMPTY) {
							data[i] = EMPTY;
							--size;
							return;
						}
						int k = hash(cur) & mask;
						if ((k >= i) ^ (k < j) ^ (i < j)) {
							data[i] = cur;
							data[i + 1] = data[j + 1];
							i = j;
						}
					}
				} else if (cur == EMPTY) {
					return;
				}
			}
		}

		void expand(int newCapacity) {
			long data[] = this.data;
			int oldCapacity = data.length;
			if (oldCapacity >> 2 < newCapacity) {
				this.data = resize(data, Integer.highestOneBit(newCapacity - 1) << 3);
			}
		}

		void shrink() {
			long data[] = this.data;
			int oldCapacity = data.length;
			if (oldCapacity > 4 && oldCapacity >> 3 >= size) {
				this.data = resize(data, max(Integer.highestOneBit(size - 1) << 3, 4));
			}
		}

		static class Iterator {

			final long data[];
			int position = -2;

			Iterator(long data[]) {
				this.data = data;
				advance();
			}

			boolean hasNext() {
				return position < data.length;
			}

			long getKey() {
				return data[position];
			}

			long getValue() {
				return data[position + 1];
			}

			void advance() {
				do {
					position += 2;
				} while (position < data.length && data[position] == EMPTY);
			}
		}

		Iterator iterator() {
			return new Iterator(data);
		}
	}

	static class LongLongCounter extends LongLongMap {

		long get(long key) {
			return get(key, 0);
		}

		void set(long key, long value) {
			if (value == 0) {
				delete(key);
			} else {
				super.set(key, value);
			}
		}

		void add(long key, long value) {
			if (key == EMPTY) {
				throw new IllegalArgumentException();
			}
			long data[] = this.data;
			for (int capacity = data.length, mask = capacity - 2, i = hash(key) & mask;; i = (i - 1) & mask) {
				long cur = data[i];
				if (cur == key) {
					data[i + 1] += value;
					return;
				} else if (cur == EMPTY) {
					data[i] = key;
					data[i + 1] = value;
					if (++size > capacity >> 2) {
						this.data = resize(data, capacity << 1);
					}
					return;
				}
			}
		}
	}

	static void solve() throws Exception {
		String s = scanString();
		int n = s.length();
		LongLongCounter ctr = new LongLongCounter();
		long ans = 0;
		int cutoff = (int) sqrt(n);
		int cutoff2 = n / cutoff;
		for (int k = 1; k < cutoff; k++) {
			int p1 = 0, p2 = 0;
			long cur1 = 0, cur2 = 0;
			int o2 = 0;
			while (p2 < n && o2 <= cutoff2) {
				if (s.charAt(p2) == '1') {
					cur2 += k - 1;
					++o2;
				} else {
					--cur2;
				}
				++p2;
			}
			if (o2 <= cutoff2) {
				break;
			}
			ctr.add(cur1, 1);
			while (p1 < n && s.charAt(p1) == '0') {
				--cur1;
				++p1;
				ctr.add(cur1, 1);
			}
			while (true) {
				ans += ctr.get(cur2);
				if (p2 >= n) {
					break;
				}
				if (s.charAt(p2) == '1') {
					cur2 += k - 1;
					++o2;
					cur1 += k - 1;
					++p1;
					ctr.add(cur1, 1);
					while (p1 < n && s.charAt(p1) == '0') {
						--cur1;
						++p1;
						ctr.add(cur1, 1);
					}
				} else {
					--cur2;
				}
				++p2;
			}
			ctr.clear();
		}
		k: for (int k = 1; k <= cutoff2; k++) {
			int p1 = 0, p2, p3, p4;
			for (p2 = 0; p2 < n && s.charAt(p2) == '0'; p2++) { }
			if (p2 >= n) {
				break;
			}
			p3 = p2;
			for (int i = 1; i < k; i++) {
				for (p3++; p3 < n && s.charAt(p3) == '0'; p3++) { }
				if (p3 >= n) {
					break k;
				}
			}
			p4 = p3;
			for (p4++; p4 < n && s.charAt(p4) == '0'; p4++) { }
			while (true) {
				int l1 = p1, r1 = p2 + 1, l2 = p3 + 1, r2 = p4 + 1;
				if (r1 - l1 >= k) {
					ans += (long) (r1 - l1) / k * (r2 - l2);
					r1 = l1 + (r1 - l1) % k;
				}
				if (r2 - l2 >= k) {
					ans += (long) (r2 - l2) / k * (r1 - l1);
					r2 = l2 + (r2 - l2) % k;
				}
				int l = (l2 - (r1 - 1));
				if (l % k != 0) {
					l += k - l % k;
				}
				for (; l <= r2 - 1 - l1; l += k) {
					ans += min(r1 - 1, r2 - l - 1) - max(l1, l2 - l) + 1;
				}
				if (p4 >= n) {
					break;
				}
				p1 = p2 + 1;
				for (p2++; p2 < n && s.charAt(p2) == '0'; p2++) { }
				p3 = p4;
				for (p4++; p4 < n && s.charAt(p4) == '0'; p4++) { }
			}
		}
		out.print(ans);
	}

	static int scanInt() throws IOException {
		return parseInt(scanString());
	}

	static long scanLong() throws IOException {
		return parseLong(scanString());
	}

	static String scanString() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	static BufferedReader in;
	static PrintWriter out;
	static StringTokenizer tok;

	public static void main(String[] args) {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();
			in.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			exit(1);
		}
	}
}


import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.sqrt;
import static java.lang.System.exit;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class F {

	static class LongLongMap {

		static final long EMPTY = Long.MIN_VALUE;

		long data[] = new long[4];
		{
			data[0] = EMPTY;
			data[2] = EMPTY;
		}
		int size = 0;

		boolean isEmpty() {
			return size == 0;
		}

		int size() {
			return size;
		}

		void clear() {
			for (int i = 0; i < data.length; i += 2) {
				data[i] = EMPTY;
			}
			size = 0;
		}

		static int hash(long key) {
			long hash = key * 1000000007;
			hash ^= hash >> 16;
			hash ^= hash >> 24;
			return (int) hash;
		}

		boolean have(long key) {
			if (key == EMPTY) {
				throw new IllegalArgumentException();
			}
			for (int mask = data.length - 2, i = hash(key) & mask;; i = (i - 1) & mask) {
				long cur = data[i];
				if (cur == key) {
					return true;
				} else if (cur == EMPTY) {
					return false;
				}
			}
		}

		long get(long key, long default_) {
			if (key == EMPTY) {
				throw new IllegalArgumentException();
			}
			for (int mask = data.length - 2, i = hash(key) & mask;; i = (i - 1) & mask) {
				long cur = data[i];
				if (cur == key) {
					return data[i + 1];
				} else if (cur == EMPTY) {
					return default_;
				}
			}
		}

		static long[] resize(long data[], int newCapacity) {
			int oldCapacity = data.length;
			long ndata[] = new long[newCapacity];
			for (int i = 0; i < newCapacity; i += 2) {
				ndata[i] = EMPTY;
			}
			for (int mask = newCapacity - 2, i = 0; i < oldCapacity; i += 2) {
				long cur = data[i];
				if (cur == EMPTY) {
					continue;
				}
				for (int j = hash(cur) & mask;; j = (j - 1) & mask) {
					if (ndata[j] == EMPTY) {
						ndata[j] = cur;
						ndata[j + 1] = data[i + 1];
						break;
					}
				}
			}
			return ndata;
		}

		void set(long key, long value) {
			if (key == EMPTY) {
				throw new IllegalArgumentException();
			}
			long data[] = this.data;
			for (int capacity = data.length, mask = capacity - 2, i = hash(key) & mask;; i = (i - 1) & mask) {
				long cur = data[i];
				if (cur == key) {
					data[i + 1] = value;
					return;
				} else if (cur == EMPTY) {
					data[i] = key;
					data[i + 1] = value;
					if (++size > capacity >> 2) {
						this.data = resize(data, capacity << 1);
					}
					return;
				}
			}
		}

		void delete(long key) {
			if (key == EMPTY) {
				throw new IllegalArgumentException();
			}
			long data[] = this.data;
			for (int capacity = data.length, mask = capacity - 2, i = hash(key) & mask;; i = (i - 1) & mask) {
				long cur = data[i];
				if (cur == key) {
					for (int j = i;;) {
						cur = data[j = (j - 1) & mask];
						if (cur == EMPTY) {
							data[i] = EMPTY;
							--size;
							return;
						}
						int k = hash(cur) & mask;
						if ((k >= i) ^ (k < j) ^ (i < j)) {
							data[i] = cur;
							data[i + 1] = data[j + 1];
							i = j;
						}
					}
				} else if (cur == EMPTY) {
					return;
				}
			}
		}

		void expand(int newCapacity) {
			long data[] = this.data;
			int oldCapacity = data.length;
			if (oldCapacity >> 2 < newCapacity) {
				this.data = resize(data, Integer.highestOneBit(newCapacity - 1) << 3);
			}
		}

		void shrink() {
			long data[] = this.data;
			int oldCapacity = data.length;
			if (oldCapacity > 4 && oldCapacity >> 3 >= size) {
				this.data = resize(data, max(Integer.highestOneBit(size - 1) << 3, 4));
			}
		}

		static class Iterator {

			final long data[];
			int position = -2;

			Iterator(long data[]) {
				this.data = data;
				advance();
			}

			boolean hasNext() {
				return position < data.length;
			}

			long getKey() {
				return data[position];
			}

			long getValue() {
				return data[position + 1];
			}

			void advance() {
				do {
					position += 2;
				} while (position < data.length && data[position] == EMPTY);
			}
		}

		Iterator iterator() {
			return new Iterator(data);
		}
	}

	static class LongLongCounter extends LongLongMap {

		long get(long key) {
			return get(key, 0);
		}

		void set(long key, long value) {
			if (value == 0) {
				delete(key);
			} else {
				super.set(key, value);
			}
		}

		void add(long key, long value) {
			if (key == EMPTY) {
				throw new IllegalArgumentException();
			}
			long data[] = this.data;
			for (int capacity = data.length, mask = capacity - 2, i = hash(key) & mask;; i = (i - 1) & mask) {
				long cur = data[i];
				if (cur == key) {
					data[i + 1] += value;
					return;
				} else if (cur == EMPTY) {
					data[i] = key;
					data[i + 1] = value;
					if (++size > capacity >> 2) {
						this.data = resize(data, capacity << 1);
					}
					return;
				}
			}
		}
	}

	static void solve() throws Exception {
		String s = scanString();
		int n = s.length();
//		int n = 200000;
//		char ss[] = new char[n];
//		fill(ss, '1');
//		String s = new String(ss);
		LongLongCounter ctr = new LongLongCounter();
		long ans = 0;
		int cutoff = min((int) sqrt(n), 150);
		int cutoff2 = n / cutoff;
//		System.err.println("HERE1");
		for (int k = 1; k < cutoff; k++) {
			int p1 = 0, p2 = 0;
			long cur1 = 0, cur2 = 0;
			int o2 = 0;
			while (p2 < n && o2 <= cutoff2) {
				if (s.charAt(p2) == '1') {
					cur2 += k - 1;
					++o2;
				} else {
					--cur2;
				}
				++p2;
			}
			if (o2 <= cutoff2) {
				break;
			}
			ctr.add(cur1, 1);
			while (p1 < n && s.charAt(p1) == '0') {
				--cur1;
				++p1;
				ctr.add(cur1, 1);
			}
			while (true) {
				ans += ctr.get(cur2);
				if (p2 >= n) {
					break;
				}
				if (s.charAt(p2) == '1') {
					cur2 += k - 1;
					++o2;
					cur1 += k - 1;
					++p1;
					ctr.add(cur1, 1);
					while (p1 < n && s.charAt(p1) == '0') {
						--cur1;
						++p1;
						ctr.add(cur1, 1);
					}
				} else {
					--cur2;
				}
				++p2;
			}
			ctr.clear();
		}
//		System.err.println("HERE2");
		k: for (int k = 1; k <= cutoff2; k++) {
			int p1 = 0, p2, p3, p4;
			for (p2 = 0; p2 < n && s.charAt(p2) == '0'; p2++) { }
			if (p2 >= n) {
				break;
			}
			p3 = p2;
			for (int i = 1; i < k; i++) {
				for (p3++; p3 < n && s.charAt(p3) == '0'; p3++) { }
				if (p3 >= n) {
					break k;
				}
			}
			p4 = p3;
			for (p4++; p4 < n && s.charAt(p4) == '0'; p4++) { }
			while (true) {
				int l1 = p1, r1 = p2 + 1, l2 = p3 + 1, r2 = p4 + 1;
				if (r1 - l1 >= k) {
					ans += (long) (r1 - l1) / k * (r2 - l2);
					r1 = l1 + (r1 - l1) % k;
				}
				if (r2 - l2 >= k) {
					ans += (long) (r2 - l2) / k * (r1 - l1);
					r2 = l2 + (r2 - l2) % k;
				}
				int l = (l2 - (r1 - 1));
				if (l % k != 0) {
					l += k - l % k;
				}
				for (; l <= r2 - 1 - l1; l += k) {
					ans += min(r1 - 1, r2 - l - 1) - max(l1, l2 - l) + 1;
				}
				if (p4 >= n) {
					break;
				}
				p1 = p2 + 1;
				for (p2++; p2 < n && s.charAt(p2) == '0'; p2++) { }
				p3 = p4;
				for (p4++; p4 < n && s.charAt(p4) == '0'; p4++) { }
			}
		}
//		System.err.println("HERE3");
		out.print(ans);
	}

	static int scanInt() throws IOException {
		return parseInt(scanString());
	}

	static long scanLong() throws IOException {
		return parseLong(scanString());
	}

	static String scanString() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	static BufferedReader in;
	static PrintWriter out;
	static StringTokenizer tok;

	public static void main(String[] args) {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();
			in.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			exit(1);
		}
	}
}


#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <unordered_map>
#include <utility>
#define F first
#define S second
#pragma GCC optimize("O3")

using namespace std;

string s;

int64_t scht(int l, int r, int x){
	if(l>r) return 0;
	l=(min(1,l%x)+(l/x))*x;
	r=(r/x)*x;
	if(l>r) return 0;
	return (r-l)/x+1;
	}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> s;
    int n = s.length(), sqn = 4*sqrt(n);
    long long ans = 0;
	vector<int> prf(n+1), next(n+1,-1);
	unordered_map<int,int> cnt;
	for(int i = 0; i < n; ++i)
		prf[i+1] = prf[i]+s[i]-'0';
	for(int i = n-1; i>=0; --i){
		if(s[i]=='1') next[i] = i+1;
		else next[i] = next[i+1];
	}
	for(int k = 1; k <= sqn; ++k){
		cnt.clear();
		for(int i = 0; i <= n; ++i)
			++cnt[i-k*prf[i]];
		for(auto& i: cnt)
			ans+=(i.S*(i.S-1))>>1;
	}
	for(int l = 1; l<=n; ++l){
		int r = l;
		if(s[l-1]=='0'&&next[r]==-1) continue;
		if(s[l-1]=='0') r = next[r];
		for(int x = 1; x <= sqn; ++x){
			int tr = next[r]-1;
			if(tr<0) tr = n;
			///cout << l << " " << r << ": " <<
			///max(r-l+1,x*sqn+x) << " " << tr-l+1 << " " << x << " " << scht(max(r-l+1,x*sqn+x),tr-l+1,x) << endl;
			ans+=scht(max(r-l+1,x*sqn+x),tr-l+1,x);
			if(next[r]==-1) break;
			r = next[r];
		}
	}
	cout << ans;
	return 0;
	}


#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <unordered_map>
#include <utility>
#define F first
#define S second
#pragma GCC optimize("O3")

using namespace std;

string s;

int64_t scht(int l, int r, int x){
	if(l>r) return 0;
	l=(min(1,l%x)+(l/x))*x;
	r=(r/x)*x;
	if(l>r) return 0;
	return (r-l)/x+1;
	}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> s;
    int n = s.length(), sqn = 400;
    long long ans = 0;
	vector<int> prf(n+1), next(n+1,-1);
	unordered_map<int,int64_t> cnt;
	for(int i = 0; i < n; ++i)
		prf[i+1] = prf[i]+s[i]-'0';
	for(int i = n-1; i>=0; --i){
		if(s[i]=='1') next[i] = i+1;
		else next[i] = next[i+1];
	}
	for(int k = 1; k <= sqn; ++k){
		cnt.clear();
		for(int i = 0; i <= n; ++i)
			++cnt[i-k*prf[i]];
		for(auto& i: cnt)
			ans+=(1LL*i.S*(i.S-1LL))>>1LL;
	}
	for(int l = 1; l<=n; ++l){
		int r = l;
		if(s[l-1]=='0'&&next[r]==-1) continue;
		if(s[l-1]=='0') r = next[r];
		int NT = n/sqn+1;
		for(int x = 1; x <= NT; ++x){
			int tr = next[r]-1;
			if(tr<0) tr = n;
			///cout << l << " " << r << ": " <<
			///max(r-l+1,x*sqn+x) << " " << tr-l+1 << " " << x << " " << scht(max(r-l+1,x*sqn+x),tr-l+1,x) << endl;
			ans+=scht(max(r-l+1,x*sqn+x),tr-l+1,x);
			if(next[r]==-1) break;
			r = next[r];
		}
	}
	cout << ans;
	return 0;
	}


#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <unordered_map>
#include <utility>
#define F first
#define S second

using namespace std;

string s;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> s;
    int n = s.length(), sqn = n;
    long long ans = 0;
	vector<int> prf(n+1);
	unordered_map<int,int> cnt;
	for(int i = 0; i < n; ++i)
		prf[i+1] = prf[i]+s[i]-'0';
	for(int k = 1; k <= sqn; ++k){
		cnt.clear();
		for(int i = 0; i <= n; ++i)
			++cnt[i-k*prf[i]];
		for(auto& i: cnt)
			ans+=(i.S*(i.S-1))>>1;
	}
	cout << ans;

	return 0;
	}


#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <unordered_map>
#include <utility>
#define F first
#define S second
#pragma GCC optimize("O3")

using namespace std;

string s;

int64_t scht(int l, int r, int x){
	if(l>r) return 0;
	l=(min(1,l%x)+(l/x))*x;
	r=(r/x)*x;
	if(l>r) return 0;
	return (r-l)/x+1;
	}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> s;
    int n = s.length(), sqn = 400;
    long long ans = 0;
	vector<int> prf(n+1), next(n+1,-1);
	unordered_map<int,int> cnt;
	for(int i = 0; i < n; ++i)
		prf[i+1] = prf[i]+s[i]-'0';
	for(int i = n-1; i>=0; --i){
		if(s[i]=='1') next[i] = i+1;
		else next[i] = next[i+1];
	}
	for(int k = 1; k <= sqn; ++k){
		cnt.clear();
		for(int i = 0; i <= n; ++i)
			++cnt[i-k*prf[i]];
		for(auto& i: cnt)
			ans+=(i.S*(i.S-1))>>1;
	}
	for(int l = 1; l<=n; ++l){
		int r = l;
		if(s[l-1]=='0'&&next[r]==-1) continue;
		if(s[l-1]=='0') r = next[r];
		int NT = n/sqn+1;
		for(int x = 1; x <= NT; ++x){
			int tr = next[r]-1;
			if(tr<0) tr = n;
			///cout << l << " " << r << ": " <<
			///max(r-l+1,x*sqn+x) << " " << tr-l+1 << " " << x << " " << scht(max(r-l+1,x*sqn+x),tr-l+1,x) << endl;
			ans+=scht(max(r-l+1,x*sqn+x),tr-l+1,x);
			if(next[r]==-1) break;
			r = next[r];
		}
	}
	cout << ans;
	return 0;
	}


#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <unordered_map>
#include <utility>
#define F first
#define S second
#pragma GCC optimize("O3")

using namespace std;

string s;

int64_t scht(int l, int r, int x){
	if(l>r) return 0;
	l=(min(1,l%x)+(l/x))*x;
	r=(r/x)*x;
	if(l>r) return 0;
	return (r-l)/x+1;
	}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> s;
    int n = s.length(), sqn = 2*sqrt(n);
    long long ans = 0;
	vector<int> prf(n+1), next(n+1,-1);
	unordered_map<int,int> cnt;
	for(int i = 0; i < n; ++i)
		prf[i+1] = prf[i]+s[i]-'0';
	for(int i = n-1; i>=0; --i){
		if(s[i]=='1') next[i] = i+1;
		else next[i] = next[i+1];
	}
	for(int k = 1; k <= sqn; ++k){
		cnt.clear();
		for(int i = 0; i <= n; ++i)
			++cnt[i-k*prf[i]];
		for(auto& i: cnt)
			ans+=(i.S*(i.S-1))>>1;
	}
	for(int l = 1; l<=n; ++l){
		int r = l;
		if(s[l-1]=='0'&&next[r]==-1) continue;
		if(s[l-1]=='0') r = next[r];
		int NT = n/sqn+1;
		for(int x = 1; x <= NT; ++x){
			int tr = next[r]-1;
			if(tr<0) tr = n;
			///cout << l << " " << r << ": " <<
			///max(r-l+1,x*sqn+x) << " " << tr-l+1 << " " << x << " " << scht(max(r-l+1,x*sqn+x),tr-l+1,x) << endl;
			ans+=scht(max(r-l+1,x*sqn+x),tr-l+1,x);
			if(next[r]==-1) break;
			r = next[r];
		}
	}
	cout << ans;
	return 0;
	}


#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <unordered_map>
#include <utility>
#define F first
#define S second
#pragma GCC optimize("O3")

using namespace std;

string s;

int64_t scht(int l, int r, int x){
	if(l>r) return 0;
	l=(min(1,l%x)+(l/x))*x;
	r=(r/x)*x;
	if(l>r) return 0;
	return (r-l)/x+1;
	}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> s;
    int n = s.length(), sqn = sqrt(n);
    long long ans = 0;
	vector<int> prf(n+1), next(n+1,-1);
	unordered_map<int,int> cnt;
	for(int i = 0; i < n; ++i)
		prf[i+1] = prf[i]+s[i]-'0';
	for(int i = n-1; i>=0; --i){
		if(s[i]=='1') next[i] = i+1;
		else next[i] = next[i+1];
	}
	for(int k = 1; k <= sqn; ++k){
		cnt.clear();
		for(int i = 0; i <= n; ++i)
			++cnt[i-k*prf[i]];
		for(auto& i: cnt)
			ans+=(i.S*(i.S-1))>>1;
	}
	for(int l = 1; l<=n; ++l){
		int r = l;
		if(s[l-1]=='0'&&next[r]==-1) continue;
		if(s[l-1]=='0') r = next[r];
		for(int x = 1; x <= n/sqn+1; ++x){
			int tr = next[r]-1;
			if(tr<0) tr = n;
			///cout << l << " " << r << ": " <<
			///max(r-l+1,x*sqn+x) << " " << tr-l+1 << " " << x << " " << scht(max(r-l+1,x*sqn+x),tr-l+1,x) << endl;
			ans+=scht(max(r-l+1,x*sqn+x),tr-l+1,x);
			if(next[r]==-1) break;
			r = next[r];
		}
	}
	cout << ans;
	return 0;
	}


#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <unordered_map>
#include <utility>
#define F first
#define S second
#pragma GCC optimize("O3")

using namespace std;

string s;

int64_t scht(int l, int r, int x){
	if(l>r) return 0;
	l=(min(1,l%x)+(l/x))*x;
	r=(r/x)*x;
	if(l>r) return 0;
	return (r-l)/x+1;
	}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> s;
    int n = s.length(), sqn = sqrt(n);
    long long ans = 0;
	vector<int> prf(n+1), next(n+1,-1);
	unordered_map<int,int> cnt;
	for(int i = 0; i < n; ++i)
		prf[i+1] = prf[i]+s[i]-'0';
	for(int i = n-1; i>=0; --i){
		if(s[i]=='1') next[i] = i+1;
		else next[i] = next[i+1];
	}
	for(int k = 1; k <= sqn; ++k){
		cnt.clear();
		for(int i = 0; i <= n; ++i)
			++cnt[i-k*prf[i]];
		for(auto& i: cnt)
			ans+=(i.S*(i.S-1))>>1;
	}
	for(int l = 1; l<=n; ++l){
		int r = l;
		if(s[l-1]=='0'&&next[r]==-1) continue;
		if(s[l-1]=='0') r = next[r];
		int NT = n/sqn+1;
		for(int x = 1; x <= NT; ++x){
			int tr = next[r]-1;
			if(tr<0) tr = n;
			///cout << l << " " << r << ": " <<
			///max(r-l+1,x*sqn+x) << " " << tr-l+1 << " " << x << " " << scht(max(r-l+1,x*sqn+x),tr-l+1,x) << endl;
			ans+=scht(max(r-l+1,x*sqn+x),tr-l+1,x);
			if(next[r]==-1) break;
			r = next[r];
		}
	}
	cout << ans;
	return 0;
	}


#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <unordered_map>
#include <utility>
#define F first
#define S second
#pragma GCC optimize("O3")

using namespace std;

string s;

int64_t scht(int l, int r, int x){
	if(l>r) return 0;
	l=(min(1,l%x)+(l/x))*x;
	r=(r/x)*x;
	if(l>r) return 0;
	return (r-l)/x+1;
	}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> s;
    int n = s.length(), sqn = 4*sqrt(n);
    long long ans = 0;
	vector<int> prf(n+1), next(n+1,-1);
	unordered_map<int,int> cnt;
	for(int i = 0; i < n; ++i)
		prf[i+1] = prf[i]+s[i]-'0';
	for(int i = n-1; i>=0; --i){
		if(s[i]=='1') next[i] = i+1;
		else next[i] = next[i+1];
	}
	for(int k = 1; k <= sqn; ++k){
		cnt.clear();
		for(int i = 0; i <= n; ++i)
			++cnt[i-k*prf[i]];
		for(auto& i: cnt)
			ans+=(i.S*(i.S-1))>>1;
	}
	for(int l = 1; l<=n; ++l){
		int r = l;
		if(s[l-1]=='0'&&next[r]==-1) continue;
		if(s[l-1]=='0') r = next[r];
		for(int x = 1; x <= n/sqn+1; ++x){
			int tr = next[r]-1;
			if(tr<0) tr = n;
			///cout << l << " " << r << ": " <<
			///max(r-l+1,x*sqn+x) << " " << tr-l+1 << " " << x << " " << scht(max(r-l+1,x*sqn+x),tr-l+1,x) << endl;
			ans+=scht(max(r-l+1,x*sqn+x),tr-l+1,x);
			if(next[r]==-1) break;
			r = next[r];
		}
	}
	cout << ans;
	return 0;
	}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <cmath>
#include <bitset>
#include <ctime>
#include <random>
#include <cstdlib>
#include <deque>
#define F first
#define S second
#define pb push_back
#define ll long long

using namespace std;

const int N = 2e5+5, INF = 1e9;
const bool debug = 0;

struct fenwick{
    int n;
    vector<int64_t> f;
    fenwick(vector<int64_t>& a){
        n = a.size()-1;
        f.resize(n+1);
        for(int i = 1; i <= n; ++i){
            f[i]+=a[i];
            if(i+(i&-i)<=n) f[i+(i&-i)]+=f[i];
        }
    }

    void add(int x, int d){
        for(;x<=n;x+=x&-x)
            f[x]+=d;
    }

    int64_t sum(int x){
        int64_t r = 0;
        for(;x;x-=x&-x)
            r+=f[x];
        return r;
    }
    int64_t sum(int l, int r){
        return sum(r)-sum(l-1);
    }

    int64_t findkth(int64_t S){
        int pos = 0, h = (1<<17), m = 18;
        for(;m--;){
            if(f[h]<S) pos = h, S-=f[h], h+=(h&-h)>>1;
            else h-=(h&-h)>>1;
        }
        return pos+1;
    }
    int64_t operator [](int x){
		return f[x];
	}
};

int main(){
    if(debug) freopen("input.txt","r",stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    string s;
    cin >> s;
    int n = s.size();
    int64_t ans = 0;
    vector<int> a(n+1), p(n+1);
    for(int i = 0; i < s.size(); ++i)
		a[i+1] = s[i]-'0';
	for(int i = 1; i <= n; ++i)
		p[i] = p[i-1]+a[i];
	for(int i = 1; i <= n; ++i)
		for(int j = i; j<=n; ++j)
			ans+=((p[j]-p[i-1]>0)&&((j-i+1)%(p[j]-p[i-1])==0));
	cout << ans;

    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <unordered_map>
#include <utility>
#define F first
#define S second
#pragma GCC optimize("O3")

using namespace std;

string s;

int64_t scht(int l, int r, int x){
	if(l>r) return 0;
	l=(min(1,l%x)+(l/x))*x;
	r=(r/x)*x;
	if(l>r) return 0;
	return (r-l)/x+1;
	}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> s;
    int n = s.length(), sqn = sqrt(n)/4;
    long long ans = 0;
	vector<int> prf(n+1), next(n+1,-1);
	unordered_map<int,int> cnt;
	for(int i = 0; i < n; ++i)
		prf[i+1] = prf[i]+s[i]-'0';
	for(int i = n-1; i>=0; --i){
		if(s[i]=='1') next[i] = i+1;
		else next[i] = next[i+1];
	}
	for(int k = 1; k <= sqn; ++k){
		cnt.clear();
		for(int i = 0; i <= n; ++i)
			++cnt[i-k*prf[i]];
		for(auto& i: cnt)
			ans+=(i.S*(i.S-1))>>1;
	}
	for(int l = 1; l<=n; ++l){
		int r = l;
		if(s[l-1]=='0'&&next[r]==-1) continue;
		if(s[l-1]=='0') r = next[r];
		for(int x = 1; x <= sqn; ++x){
			int tr = next[r]-1;
			if(tr<0) tr = n;
			///cout << l << " " << r << ": " <<
			///max(r-l+1,x*sqn+x) << " " << tr-l+1 << " " << x << " " << scht(max(r-l+1,x*sqn+x),tr-l+1,x) << endl;
			ans+=scht(max(r-l+1,x*sqn+x),tr-l+1,x);
			if(next[r]==-1) break;
			r = next[r];
		}
	}
	cout << ans;
	return 0;
	}


#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <unordered_map>
#include <utility>
#define F first
#define S second
#pragma GCC optimize("O3")

using namespace std;

string s;

int64_t scht(int l, int r, int x){
	if(l>r) return 0;
	l=(min(1,l%x)+(l/x))*x;
	r=(r/x)*x;
	if(l>r) return 0;
	return (r-l)/x+1;
	}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> s;
    int n = s.length(), sqn = sqrt(n);
    long long ans = 0;
	vector<int> prf(n+1), next(n+1,-1);
	unordered_map<int,int> cnt;
	for(int i = 0; i < n; ++i)
		prf[i+1] = prf[i]+s[i]-'0';
	for(int i = n-1; i>=0; --i){
		if(s[i]=='1') next[i] = i+1;
		else next[i] = next[i+1];
	}
	for(int k = 1; k <= sqn; ++k){
		cnt.clear();
		for(int i = 0; i <= n; ++i)
			++cnt[i-k*prf[i]];
		for(auto& i: cnt)
			ans+=(i.S*(i.S-1))>>1;
	}
	for(int l = 1; l<=n; ++l){
		int r = l;
		if(s[l-1]=='0'&&next[r]==-1) continue;
		if(s[l-1]=='0') r = next[r];
		for(int x = 1; x <= 4*sqn; ++x){
			int tr = next[r]-1;
			if(tr<0) tr = n;
			///cout << l << " " << r << ": " <<
			///max(r-l+1,x*sqn+x) << " " << tr-l+1 << " " << x << " " << scht(max(r-l+1,x*sqn+x),tr-l+1,x) << endl;
			ans+=scht(max(r-l+1,x*sqn+x),tr-l+1,x);
			if(next[r]==-1) break;
			r = next[r];
		}
	}
	cout << ans;
	return 0;
	}


#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <unordered_map>
#include <utility>
#define F first
#define S second
#pragma GCC optimize("O3")

using namespace std;

string s;

int64_t scht(int l, int r, int x){
	if(l>r) return 0;
	l=(min(1,l%x)+(l/x))*x;
	r=(r/x)*x;
	if(l>r) return 0;
	return (r-l)/x+1;
	}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> s;
    int n = s.length(), sqn = sqrt(n);
    long long ans = 0;
	vector<int> prf(n+1), next(n+1,-1);
	unordered_map<int,int> cnt;
	for(int i = 0; i < n; ++i)
		prf[i+1] = prf[i]+s[i]-'0';
	for(int i = n-1; i>=0; --i){
		if(s[i]=='1') next[i] = i+1;
		else next[i] = next[i+1];
	}
	for(int k = 1; k <= sqn; ++k){
		cnt.clear();
		for(int i = 0; i <= n; ++i)
			++cnt[i-k*prf[i]];
		for(auto& i: cnt)
			ans+=(i.S*(i.S-1))>>1;
	}
	for(int l = 1; l<=n; ++l){
		int r = l;
		if(s[l-1]=='0'&&next[r]==-1) continue;
		if(s[l-1]=='0') r = next[r];
		for(int x = 1; x <= sqn; ++x){
			int tr = next[r]-1;
			if(tr<0) tr = n;
			///cout << l << " " << r << ": " <<
			///max(r-l+1,x*sqn+x) << " " << tr-l+1 << " " << x << " " << scht(max(r-l+1,x*sqn+x),tr-l+1,x) << endl;
			ans+=scht(max(r-l+1,x*sqn+x),tr-l+1,x);
			if(next[r]==-1) break;
			r = next[r];
		}
	}
	cout << ans;
	return 0;
	}


#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <unordered_map>
#include <utility>
#define F first
#define S second
#pragma GCC optimize("O3")

using namespace std;

string s;

int64_t scht(int l, int r, int x){
	if(l>r) return 0;
	l=(min(1,l%x)+(l/x))*x;
	r=(r/x)*x;
	if(l>r) return 0;
	return (r-l)/x+1;
	}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> s;
    int n = s.length(), sqn = sqrt(n);
    long long ans = 0;
	vector<int> prf(n+1), next(n+1,-1);
	unordered_map<int,int> cnt;
	for(int i = 0; i < n; ++i)
		prf[i+1] = prf[i]+s[i]-'0';
	for(int i = n-1; i>=0; --i){
		if(s[i]=='1') next[i] = i+1;
		else next[i] = next[i+1];
	}
	for(int k = 1; k <= sqn; ++k){
		cnt.clear();
		for(int i = 0; i <= n; ++i)
			++cnt[i-k*prf[i]];
		for(auto& i: cnt)
			ans+=(i.S*(i.S-1))>>1;
	}
	for(int l = 1; l<=n; ++l){
		int r = l;
		if(s[l-1]=='0'&&next[r]==-1) continue;
		if(s[l-1]=='0') r = next[r];
		for(int x = 1; x <= sqn+5; ++x){
			int tr = next[r]-1;
			if(tr<0) tr = n;
			///cout << l << " " << r << ": " <<
			///max(r-l+1,x*sqn+x) << " " << tr-l+1 << " " << x << " " << scht(max(r-l+1,x*sqn+x),tr-l+1,x) << endl;
			ans+=scht(max(r-l+1,x*sqn+x),tr-l+1,x);
			if(next[r]==-1) break;
			r = next[r];
		}
	}
	cout << ans;
	return 0;
	}


#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <unordered_map>
#include <utility>
#define F first
#define S second

using namespace std;

string s;

int64_t scht(int l, int r, int x){
	if(l>r) return 0;
	l=(min(1,l%x)+(l/x))*x;
	r=(r/x)*x;
	if(l>r) return 0;
	return (r-l)/x+1;
	}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> s;
    int n = s.length(), sqn = sqrt(n);
    long long ans = 0;
	vector<int> prf(n+1), next(n+1,-1);
	unordered_map<int,int> cnt;
	for(int i = 0; i < n; ++i)
		prf[i+1] = prf[i]+s[i]-'0';
	for(int i = n-1; i>=0; --i){
		if(s[i]=='1') next[i] = i+1;
		else next[i] = next[i+1];
	}
	for(int k = 1; k <= sqn; ++k){
		cnt.clear();
		for(int i = 0; i <= n; ++i)
			++cnt[i-k*prf[i]];
		for(auto& i: cnt)
			ans+=(i.S*(i.S-1))>>1;
	}
	for(int l = 1; l<=n; ++l){
		int r = l;
		if(s[l-1]=='0'&&next[r]==-1) continue;
		if(s[l-1]=='0') r = next[r];
		for(int x = 1; x <= sqn; ++x){
			int tr = next[r]-1;
			if(tr<0) tr = n;
			///cout << l << " " << r << ": " <<
			///max(r-l+1,x*sqn+x) << " " << tr-l+1 << " " << x << " " << scht(max(r-l+1,x*sqn+x),tr-l+1,x) << endl;
			ans+=scht(max(r-l+1,x*sqn+x),tr-l+1,x);
			if(next[r]==-1) break;
			r = next[r];
		}
	}
	cout << ans;

	return 0;
	}


#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <unordered_map>
#include <utility>
#define F first
#define S second

using namespace std;

string s;

int64_t scht(int l, int r, int x){
	if(l>r) return 0;
	l=(min(1,l%x)+(l/x))*x;
	r=(r/x)*x;
	if(l>r) return 0;
	return (r-l)/x+1;
	}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> s;
    int n = s.length(), sqn = sqrt(n);
    long long ans = 0;
	vector<int> prf(n+1), next(n+1,-1);
	unordered_map<int,int> cnt;
	for(int i = 0; i < n; ++i)
		prf[i+1] = prf[i]+s[i]-'0';
	for(int i = n-1; i>=0; --i){
		if(s[i]=='1') next[i] = i+1;
		else next[i] = next[i+1];
	}
	for(int k = 1; k <= sqn; ++k){
		cnt.clear();
		for(int i = 0; i <= n; ++i)
			++cnt[i-k*prf[i]];
		for(auto& i: cnt)
			ans+=(i.S*(i.S-1))>>1;
	}
	for(int l = 1; l<=n; ++l){
		int r = l;
		if(s[l-1]=='0'&&next[r]==-1) continue;
		if(s[l-1]=='0') r = next[r];
		for(int x = 1; x <= sqn; ++x){
			int tr = next[r]-1;
			if(tr<0) tr = n;
			///cout << l << " " << r << ": " <<
			///max(r-l+1,x*sqn+x) << " " << tr-l+1 << " " << x << " " << scht(max(r-l+1,x*sqn+x),tr-l+1,x) << endl;
			ans+=scht(max(r-l+1,x*sqn+x),tr-l+1,x);
			if(next[r]==-1) break;
			r = next[r];
		}
	}
	cout << ans;
	return 0;
	}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <cmath>
#include <bitset>
#include <ctime>
#include <random>
#include <cstdlib>
#include <deque>
#define F first
#define S second
#define pb push_back
#define ll long long
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;

const int N = 2e5+5, INF = 1e9;
const bool debug = 0;

struct fenwick{
    int n;
    vector<int64_t> f;
    fenwick(vector<int64_t>& a){
        n = a.size()-1;
        f.resize(n+1);
        for(int i = 1; i <= n; ++i){
            f[i]+=a[i];
            if(i+(i&-i)<=n) f[i+(i&-i)]+=f[i];
        }
    }

    void add(int x, int d){
        for(;x<=n;x+=x&-x)
            f[x]+=d;
    }

    int64_t sum(int x){
        int64_t r = 0;
        for(;x;x-=x&-x)
            r+=f[x];
        return r;
    }
    int64_t sum(int l, int r){
        return sum(r)-sum(l-1);
    }

    int64_t findkth(int64_t S){
        int pos = 0, h = (1<<17), m = 18;
        for(;m--;){
            if(f[h]<S) pos = h, S-=f[h], h+=(h&-h)>>1;
            else h-=(h&-h)>>1;
        }
        return pos+1;
    }
    int64_t operator [](int x){
		return f[x];
	}
};

int main(){
    if(debug) freopen("input.txt","r",stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    string s;
    cin >> s;
    int n = s.size();
    int64_t ans = 0;
    vector<int> a(n+1), p(n+1);
    for(int i = 0; i < s.size(); ++i)
		a[i+1] = s[i]-'0';
	for(int i = 1; i <= n; ++i)
		p[i] = p[i-1]+a[i];
	for(int i = 1; i <= n; ++i)
		for(int j = i; j<=n; ++j)
			ans+=((p[j]-p[i-1]>0)&&((j-i+1)%(p[j]-p[i-1])==0));
	cout << ans;

    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <unordered_map>
#include <utility>
#define F first
#define S second
#pragma GCC optimize("O3")

using namespace std;

string s;

int64_t scht(int l, int r, int x){
	if(l>r) return 0;
	l=(min(1,l%x)+(l/x))*x;
	r=(r/x)*x;
	if(l>r) return 0;
	return (r-l)/x+1LL;
	}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> s;
    int n = s.length(), sqn = 375;
    long long ans = 0;
	vector<int> prf(n+1), next(n+1,-1);
	unordered_map<int,int64_t> cnt;
	for(int i = 0; i < n; ++i)
		prf[i+1] = prf[i]+s[i]-'0';
	for(int i = n-1; i>=0; --i){
		if(s[i]=='1') next[i] = i+1;
		else next[i] = next[i+1];
	}
	for(int k = 1; k <= sqn; ++k){
		cnt.clear();
		for(int i = 0; i <= n; ++i)
			++cnt[i-k*prf[i]];
		for(auto& i: cnt)
			ans+=(1LL*i.S*(i.S-1LL))>>1LL;
	}
	for(int l = 1; l<=n; ++l){
		int r = l;
		if(s[l-1]=='0'&&next[r]==-1) continue;
		if(s[l-1]=='0') r = next[r];
		int NT = n/sqn+1;
		for(int x = 1; x <= NT; ++x){
			int tr = next[r]-1;
			if(tr<0) tr = n;
			///cout << l << " " << r << ": " <<
			///max(r-l+1,x*sqn+x) << " " << tr-l+1 << " " << x << " " << scht(max(r-l+1,x*sqn+x),tr-l+1,x) << endl;
			ans+=scht(max(r-l+1,x*sqn+x),tr-l+1,x);
			if(next[r]==-1) break;
			r = next[r];
		}
	}
	cout << ans;
	return 0;
	}


#include <bits/stdc++.h>
using namespace std;

const int N = 2e5 + 7;
int pref[N];
string s;
unordered_map<int, int> bigK;
vector<int> os;
long long ans;
int n, m;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);

  cin >> s;
  n = (int) s.size();
  m = sqrt(n) + 1;
  for (int i = 0; i < n; ++i) {
    pref[i + 1] = pref[i] + (s[i] == '1');
    if (s[i] == '1') {
      os.push_back(i);
    }
  }
  os.push_back(n);
  for (int i = 1; i < m; ++i) {
    bigK.clear();
    for (int j = 0; j <= n; ++j) {
      bigK[pref[j] * i - j]++;
    }
    for (auto i : bigK) {
      ans += 1ll * i.second * (i.second - 1) / 2;
    }
  }
  for (int i = 0; i < n; ++i) {
    //cout << i << ":\n";
    for (int j = 1; j <= m; ++j) {
      if (pref[i] + j >= (int) os.size()) {
        continue;
      }
      int l = os[pref[i] + j - 1];
      int r = os[pref[i] + j] - 1;
      int L = max(m, (l - i + 1) / j);
      int R = (r - i + 1) / j;
      //cout << j << " " << l << " " << r << " " << L << " " << R << "\n";
      ans += max(0, R - L + 1);
    }
    //cout << "\n";
  }
  cout << ans << "\n";

  return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include <math.h>
int count=0;
int issorted(int i,int s[],int j){
int flag=1;
count++;
if(i<j){

for(int ll=i-1;ll<j-1;ll++)
   {
if(s[ll]>s[ll+1]){
    flag=0;
    break;
}

}

if(flag==1)
return 1;
else if(flag==0)
{int mid=(i+j)/2;
return  issorted(i,s,mid);
 return issorted(mid+1,s,j);
}

}
else
    return 1;
}
int main(){

int n;
scanf("%d",&n);
int s[n];
for(int j=0;j<n;j++)
    scanf("%d",&s[j]);

int k=issorted(1,s,n);
double a=(double)n/count;
double x=floor(a);
   printf("%d",(int)x) ;

  }


#include<stdio.h>
#include<stdlib.h>
#include <math.h>
int count=0;
int issorted(int i,int s[],int j){
int flag=1;
count++;
if(i<j){

for(int ll=i-1;ll<j-1;ll++)
   {
if(s[ll]>s[ll+1]){
    flag=0;
    break;
}

}

if(flag==1)
return flag;
else
{int mid=(i+j)/2;
 issorted(i,s,mid);
 issorted(mid+1,s,j);
}

}
else
    return 1;
}
int main(){

int n;
scanf("%d",&n);
int s[n];
for(int j=0;j<n;j++)
    scanf("%d",&s[j]);

int k=issorted(1,s,n);
double a=(double)n/count;
double x=ceil(a);
   printf("%d",(int)x) ;

  }


#include<stdio.h>
#include<stdlib.h>
#include <math.h>

int issorted(int i,int s[],int j){
int flag=1;

if(i<j){

for(int ll=i-1;ll<j-1;ll++)
   {
if(s[ll]>s[ll+1]){
    flag=0;
    break;
}

}

if(flag==1){

return j-i;}
else
{int mid=(i+j)/2;

return  issorted(i,s,mid);
 return issorted(mid+1,s,j);
}

}
else{

    return j-i;}
}
int main(){

int n;
scanf("%d",&n);
int s[n];
for(int j=0;j<n;j++)
    scanf("%d",&s[j]);
int flag =1;
    for(int ll=0;ll<n-1;ll++)
   {
if(s[ll]>s[ll+1]){
    flag=0;
    break;
}

}

if(flag==1){
printf("%d",n);
}
else{
int mid=n/2;

 int a=issorted(1,s,mid);
 int b= issorted(mid+1,s,n);

if(a>=b)
    printf("%d",a+1);
else
     printf("%d",b+1);

  }}


#include <stdio.h>
#include <stdlib.h>

int isSorted(int* a, int n)
{
    for (int i = 0; i < n-1; i++)
    {
        if (a[i] > a[i + 1])
            return 0;
    }
    return 1;
}

void subset(int* a, int n, int* a_1, int* a_2)
{
    int j = 0;
    for (int i = 0; i < (n / 2); i++)
    {
        a_1[i] = a[i];
    }
    for (int i = (n / 2); i < n; i++)
    {
        a_2[j] = a[i];
        j++;
    }
}

int max(int a, int b)
{
    if (a > b)
        return a;
    return b;
}

int ThanosSort(int* a, int n)
{
    if (n == 1)
        return 1;
    int* a_1;
    int* a_2;
    a_1 = (int*)malloc((n / 2) * sizeof(int));
    a_2 = (int*)malloc((n / 2) * sizeof(int));
    if (isSorted(a, n))
        return n;
    else
    {
        subset(a, n, a_1, a_2);
        return max(ThanosSort(a_1, n / 2), ThanosSort(a_2, n / 2));
    }
}

void get_input(int *a, int n)
{
    switch(n)
    {
    case 2:
        scanf("%d %d", &a[0], &a[1]);
        break;
    case 4:
        scanf("%d %d %d %d", &a[0], &a[1], &a[2], &a[3]);
        break;
    case 8:
        scanf("%d %d %d %d %d %d %d %d", &a[0], &a[1], &a[2], &a[3], &a[4], &a[5], &a[6], &a[7]);
        break;
    case 16:
        scanf("%d %d %d %d %d %d %d %d", &a[0], &a[1], &a[2], &a[3], &a[4], &a[5], &a[6], &a[7], &a[8], &a[9], &a[10], &a[11], &a[12], &a[13], &a[14], &a[15]);
        break;
    }

}

int main()
{
    int n;
    int* a;

    scanf("%d", &n);
    a = (int*)malloc(sizeof(int) * n);
    get_input(a,n);
    printf("%d",ThanosSort(a,n));
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int isSorted(int* a, int n)
{
	for (int i = 0; i < n - 1; i++)
	{
		if (a[i] > a[i + 1])
			return 0;
	}
	return 1;
}

void subset(int* a, int n, int* a_1, int* a_2)
{
	int j = 0;
	for (int i = 0; i < (n / 2); i++)
	{
		a_1[i] = a[i];
	}
	for (int i = (n / 2); i < n; i++)
	{
		a_2[j] = a[i];
		j++;
	}
}

int max(int a, int b)
{
	if (a > b)
		return a;
	return b;
}

int ThanosSort(int* a, int n)
{
	if (n == 1)
		return 1;
	int* a_1;
	int* a_2;
	a_1 = (int*)malloc((n / 2) * sizeof(int));
	a_2 = (int*)malloc((n / 2) * sizeof(int));
	if (isSorted(a, n))
		return n;
	else
	{
		subset(a, n, a_1, a_2);
		return max(ThanosSort(a_1, n / 2), ThanosSort(a_2, n / 2));
	}
}

void get_input(int* a, int n)
{
	switch (n)
	{
	case 2:
		scanf("%d %d", &a[0], &a[1]);
		break;
	case 4:
		scanf("%d %d %d %d", &a[0], &a[1], &a[2], &a[3]);
		break;
	case 8:
		scanf("%d %d %d %d %d %d %d %d", &a[0], &a[1], &a[2], &a[3], &a[4], &a[5], &a[6], &a[7]);
		break;
	case 16:
		scanf("%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d", &a[0], &a[1], &a[2], &a[3], &a[4], &a[5], &a[6], &a[7], &a[8], &a[9], &a[10], &a[11], &a[12], &a[13], &a[14], &a[15]);
		break;
	}

}

int main()
{
	int n;
	int* a;

	scanf("%d", &n);
	a = (int*)malloc(sizeof(int) * n);
	get_input(a, n);
	printf("%d", ThanosSort(a, n));
	return 0;
}


#include<stdio.h>
int sort(int,int,int []);
int main()
{
    int n,c=0,k=1;
    scanf("%d",&n);
    int arr[n];
    for( int i=0;i<n;scanf("%d",&arr[i]),i++);

    while(c!=1&&(n/k)!=0)
    {
    	for(int i=0;c==0,i<k;i++)
    		c=sort(i*(n/k),(i+1)*(n/k)-1, arr);
		k*=2;
	}
	printf("%d",((2*n)/k));
}

sort(int t,int n,int arr[])
{ int c=1;
    for(int i=t;i<n;i++)
        if(arr[i]>arr[i+1]){
		c=0;break;}
        return c;
}


#include<stdio.h>
int sort(int,int,int []);
int main()
{
    int n,c=0,k=1;
    scanf("%d",&n);
    int arr[n];
    for( int i=0;i<n;scanf("%d",&arr[i]),i++);

    while(c!=1&&(n/k)!=0)
    {
    	for(int i=0;c==0&&i<k;i++){

    		c=sort(i*(n/k),(i+1)*(n/k)-1, arr);
			}
		k*=2;
	}
	printf("%d",((2*n)/k));
}

sort(int t,int n,int arr[])
{ int c=1;
    for(int i=t;i<n;i++)
        if(arr[i]>arr[i+1]){
		c=0;break;}
        return c;
}


#include<stdio.h>
int sort(int,int,int []);
int main()
{
    int n,c=0,k=4;
    scanf("%d",&n);
    int arr[n];
    for( int i=0;i<n;scanf("%d",&arr[i]),i++);

    while(c!=1&&(n/k)!=0)
    {
    	for(int i=0;c==0&&i<k;i++){

    		c=sort(i*(n/k),(i+1)*(n/k)-1, arr);
			}
		k*=2;
	}
	printf("%d",((2*n)/k));
}

sort(int t,int n,int arr[])
{ int c=1;
    for(int i=t;i<n;i++)
        if(arr[i]>arr[i+1]){
		c=0;break;}
        return c;
}


#include<stdio.h>

int main(){
  int n,
      arrSize,
      i,j;
  scanf("%d", &n);
  int arr[n];
  for(i = 0 ; i < n ; i++){
    scanf("%d", arr+i);
  }
  arrSize = n;
  i = 0;
  while(i < arrSize - 1){
    if(arr[i] > arr[i+1]) {
      arrSize = (arrSize/2);
      i = -1;
    }
    i++;
  }
  printf("%d\n",arrSize );
  return 0;
}


/*thanos sort*/
#include<stdio.h>

int isUnsorted(int v[],int ini,int lenght);
int thanosSort(int v[], int n);

int
main()
{
	int n,i;
	scanf("%d",&n);
	int v[n];
	for ( i = 0 ; i < n ; i++){
		scanf("%d",v+i);
	}
	printf("%d",thanosSort(v,n));
	return 0;
}

int thanosSort(int v[], int n){
	int resu = 0;
	if (n == 1){
		resu = n;
	} else {
		if (isUnsorted(v,0,n)){
			resu = n;
		}else {
			thanosSort(v,n/2);
		}
	}
}

int isUnsorted(int v[],int ini,int lenght){
	int i = ini;
	while ( i<= lenght -2){
		if (v[i] > v[i+1]){
			return 0;
		}
		i++;
	}
	return 1;
}


/*thanos sort*/
#include<stdio.h>

int isUnsorted(int v[],int ini,int lenght);
int thanosSort(int v[], int n);

int
main()
{
	int n,i,val;
	scanf("%d",&n);
	int v[n];
	for ( i = 0 ; i < n ; i++){
		scanf("%d",v+i);
	}
	val = thanosSort(v,n);
	printf("%d",val);
	return 0;
}

int thanosSort(int v[], int n){
	int resu = 0;
	if (n == 1){
		resu = n;
	} else {
		if (isUnsorted(v,0,n)){
			resu = n;
		}else {
			thanosSort(v,n/2);
		}
	}
}

int isUnsorted(int v[],int ini,int lenght){
	int i = ini;
	while ( i<= lenght -2){
		if (v[i] > v[i+1]){
			return 0;
		}
		i++;
	}
	return 1;
}


#include<stdio.h>

int max(int a, int b){
  return a > b ? a: b;
}

int thanosSort(int n, int arr[],int ini, int fin){
  int i = ini;
  if(ini == fin) return 1;
  int length = 1;
  while(i < fin){
    if(arr[i] > arr[i+1] ){
      //cortamos por la mitad
      int med = (ini+fin)/2;
      return max(thanosSort(n,arr,ini,med), thanosSort(n,arr,med+1,fin));
    }else {
      length++;
    }
    i++;
  }
  return length;
}

int main(){
  int n,
      arrSize,
      i,j;
  scanf("%d", &n);
  int arr[n];
  for(i = 0 ; i < n ; i++)
    scanf("%d", arr+i);

  printf("%d\n", thanosSort(n,arr,0,n-1));
  return 0;
}


#include<stdio.h>
#include<stdlib.h>

int max_elements(int *arr, int start, int end){
    int is_sorted = 1;

    if(start == end){
        return 1;
    }

    for(int i=start; i<end; i++){
        if(*(arr+i) > *(arr+i+1)){
            is_sorted = 0;
            break;
        }
    }

    if(is_sorted){
        return end - start + 1;
    } else {
        int mid = start + (end-start + 1)/2;
        int m1 = max_elements(arr, start,  mid - 1);
        int m2 = max_elements(arr, mid, end);
        return m1 > m2 ? m1 : m2;
    }

}

int main(){

    int length;
    scanf("%d", &length);

    int *arr = (int *)malloc(sizeof(int) * length);
    for(int i=0; i<length; i++){
        scanf("%d", (arr+i));
    }
    printf("%d", max_elements(arr, 0, length -1));
    free(arr);
    return 0;
}


#include <stdio.h>

int main()
{
  int n, res, isr, ist, maxel;
  scanf("%d",&n);
  int a[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }

  for (int j = 1;; j*=2) {
    maxel = n/j;
    for (int k = 0; k < j; k++) {
      isr = k*maxel;
      ist = (k+1)*maxel;
      res = 1;
      for (int i = isr+1; i < ist; i++) {
        if (a[i-1] <= a[i]) {
          res++;
        }
      }
      if (res == maxel) {
        printf("%d\n",res);
        return 0;
      }
    }
  }
}


#include <stdio.h>

int main(){
	int N,b, b_old,result,pos, next = 0;
	scanf("%d",&N);
	int conteo;
	for(conteo = 0, pos = 0,result = 1;pos < N ;pos++ ){
		scanf("%d", &b);
//		printf("result: %d pos: %d conteo: %d next: %d\n",result,pos,conteo,next );
		if(pos < next) continue;
		b_old  = conteo ?   b_old:b;
//		printf("bo : %d b: %d\n",b_old,b );
		if(b_old <= b){
			conteo++;
//			printf(" conteo : %d\n",conteo );
			result<<=(conteo == result<< 1);
		}else{
			conteo = 0;
			next = ((pos/(result << 1))*(result << 1)) + (result << 1);
		}
		b_old = b;
	}
	printf("%d\n",result );
}


#include <stdio.h>

#define MAX(A,B) ((A >= B)? A : B )

int len_tanos(int *a, int k){
    int i;
	if(k == 1)return 1;
	for(i = 1;i < k; i++){
		if(a[i] < a[i-1] )
			return MAX(len_tanos(a,k/2),len_tanos(a + k/2, k/2));
	}
	return k;
}

int main(){
	int n,i;
	int num[16];
	scanf("%d",&n);
	for(i = 0; i < n ; i++)scanf("%d",&num[i]);
	printf("%d\n", len_tanos(num,n));
	return 0;
}


#include <stdio.h>

#define MAX(A,B) ((A >= B)? A : B )

int len_tanos(int *a, int k){
    int i;
	if(k == 1)return 1;
	for(i = 1;i < k; i++){
		if(a[i] > a[i-1] )
			return MAX(len_tanos(a,k/2),len_tanos(a + k/2, k/2));
	}
	return k;
}

int main(){
	int n,i;
	int num[16];
	scanf("%d",&n);
	for(i = 0; i < n ; i++)scanf("%d",&num[i]);
	printf("%d\n", len_tanos(num,n));
	return 0;
}


#include <stdio.h>

#define MAX(A,B) ((A >= B)? A : B )

int len_tanos(int *a, int k){
    int i;
	if(k == 1)return 1;
	for(i = 1;i < k; i++){
		if(a[1] > k )
			return MAX(len_tanos(a,k/2),len_tanos(a + k/2, k/2));
	}
	return k;
}

int main(){
	int n,i;
	int num[16];
	scanf("%d",&n);
	for(i = 0; i < n ; i++)scanf("%d",&num[i]);
	printf("%d\n", len_tanos(num,n));
	return 0;
}


#include <stdio.h>

int main(){
	int N,b, b_old,result,pos, next = 0;
	scanf("%d",&N);
	int conteo;
	for(conteo = 0, pos = 0,result = 1;pos < N ;pos++ ){
		scanf("%d", &b);
		if(pos < next) continue;
		b_old  = conteo ?   b_old:b;
		if(b_old <= b){
			conteo++;
			result<<=(conteo == result<< 1);
		}else{
			conteo = 0;
			next = (pos/(result << 1)*(result << 1)) + (result << 1);
		}
		b_old = b;
	}
	printf("%d\n", result);
}


#include <stdio.h>

int main(){
	int N,b,ban, b_old,result,pos,pos_c,parte, next = 0;
	scanf("%d",&N);
	parte = N >> 1;
	int conteo;
	for(conteo = 0, pos = 0,result = 1, ban  = 0;pos < N ;pos++ ){
		scanf("%d", &b);
		if(pos < next) continue;
		b_old  = conteo ?   b_old:b;
		if(pos % parte == 0 && ban){
		    conteo = 0;
		    ban = 0;
		}
//		printf("pos: %d parte: %d conteo: %d ban %d result %d next %d\n",pos,parte,conteo,ban,result,next);
		if(b_old <= b){
			conteo++;
			result<<=(conteo == result<< 1);
		}else{
		    ban  = 1;
		    pos_c = pos;
			conteo = 0;
			next = ((pos/(result << 1))*(result << 1)) + (result << 1);
		}
		b_old = b;
	}
	printf("%d\n",result );
}


#include <stdio.h>
#include <stdlib.h>
int is_sorted(int a[],int start,int end)
{
    int i,flag=1;

    for (i=start;i<end-1;i++)
    {
        if(a[i]>a[i+1])
            flag=0;
    }
    return flag;
}
int main()
{
    int a[20],i,n,j,start,flag;
    scanf("%d",&n);
    for (i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for (i=1;i<=n;i*=2)
    {
        flag=0;
        start=0;
        for (j=i;j<=n;j+=i,start+=i)
        {
            if(is_sorted(a,start,j))
            {
                flag++;
                break;
            }
        }
        if(!flag)
            break;
    }
    printf("%d\n",i/2);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,arr[100],count,i,j,start,end;
    scanf("%d",&n);
    for (i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
    }
    start=0;
    while (n-start)
    {

        count=0;
        for (i=start+1;i<n;i++)
        {
            if (arr[i]<arr[i-1])
            {
                count++;
                break;
            }
        }
        if(count==0)
            break;
        else
        {
            start+=(n-start)/2;
        }
    }
    printf("%d",n-start);
    return n;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,arr[100],count,i,j,start,end;
    scanf("%d",&n);
    for (i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
    }
    start=0;
    while (n-start)
    {

        count=0;
        for (i=start+1;i<n;i++)
        {
            if (arr[i]<arr[i-1])
            {
                count++;
                break;
            }
        }
        if(count==0)
            break;
        else
        {
            start+=(n-start)/2;
        }
    }
    printf("%d",n-start);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,arr[100],count,i,j,start,end;
    scanf("%d",&n);
    for (i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
    }
    start=0;
    while (n-start)
    {

        count=0;
        for (i=start+1;i<n;i++)
        {
            if (arr[i]<arr[i-1])
            {
                count++;
                break;
            }
        }
        if(count==0)
            break;
        else
        {
            start+=(n-start)/2;
        }
    }
    j=n-start;
    start=0;
    while (n-start)
    {

        count=0;
        for (i=start+1;i<n;i++)
        {
            if (arr[i]<arr[i-1])
            {
                count++;
                break;
            }
        }
        if(count==0)
            break;
        else
        {
            n/=2;
        }
    }
    if(n-start>j)
        printf("%d",n-start);
    else
        printf("%d",j);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int thanosSort(int *a, int n);

int main(int argc, char *argv[]) {
    int n;
    scanf("%d", &n);
    int *input = malloc(n * sizeof(int));
    for(int i = 0; i < n; i++) {
        scanf("%d", &input[i]);
    }
    printf("%d\n", thanosSort(input, n));
    free(input);
    return 0;
}

int thanosSort(int *a, int n) {
    int sum = 0;
    for(int i = 0; i < n; i++) {
        if(i != n-1 && a[i] > a[i+1]) {
            return thanosSort(a, n/2);
        }
        sum++;
    }
    return sum;
}


#include <stdio.h>
#include <stdlib.h>

#define MAX(x,y) (((x) > (y)) ? (x) : (y))

int thanosSort(int *a, int start, int end);

int main(int argc, char *argv[]) {
    int n;
    scanf("%d", &n);
    int *input = malloc(n * sizeof(int));
    for(int i = 0; i < n; i++) {
        scanf("%d", &input[i]);
    }
    printf("%d\n", thanosSort(input, 0, n));
    free(input);
    return 0;
}

int thanosSort(int *a, int start, int end) {
    int sum = 0, left = 1, right = 1;
    for(int i = start; i < end; i++) {
        if(i != end-1 && a[i] > a[i+1]) {
            left = thanosSort(a, start, start + (end - start)/2);
            right = thanosSort(a, start + (end - start)/2, end);
            return MAX(left, right);
        }
        sum++;
    }
    return sum;
}


#include<stdio.h>
#include<stdlib.h>
int L[16],R[16],value;
int fun(int a[],int n)
{
    int i,count=0;
   for(i=0;i<n-1;i++)
        if(a[i]>a[i+1])
                count++;
    return count;
}
int part(int a[],int n)
{
    int i,Left,Right,value;
    if(n==1)
    {
        printf("1");
        exit(0);
    }
    for(i=0;i<n/2;i++)
        L[i]=a[i];
    for(i=n/2;i<n;i++)
         R[i-(n/2)]=a[i];
    Left=fun(L,n/2);
    Right=fun(R,n/2);
    if(Left==0 && Right==0)
    {
        printf("%d",n/2);
        exit(0);
    }
    else if(Left==n/2 && Right==n/2)
    {
        printf("1");
        exit(0);
    }
    else if(Right==n/2 )
    {
        printf("1");
        exit(0);
    }
    else
    {
        if(Left>=Right)
            value=part(R,n/2);
        else
            value=part(L,n/2);
    }

}
int main()
{
    int n,i,array,value;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    array=fun(a,n);
        if(array==0)
            printf("%d",n);
        else if(array==n)
             printf("1");
        else
           value=part(a,n);
}


#include<stdio.h>
#include<stdlib.h>
int L[16],R[16],value;
int fun(int a[],int n)
{
    int i,count=0;
   for(i=0;i<n-1;i++)
        if(a[i]>a[i+1])
                count++;
    return count;
}
int part(int a[],int n)
{
    int i,Left,Right,value;
    if(n==1)
    {
        printf("1");
        exit(0);
    }
    for(i=0;i<n/2;i++)
        L[i]=a[i];
    for(i=n/2;i<n;i++)
         R[i-(n/2)]=a[i];
    Left=fun(L,n/2);
    Right=fun(R,n/2);
    if(Left==0 || Right==0)
    {
        printf("%d",n/2);
        exit(0);
    }
    else if(Left==n/2 && Right==n/2)
    {
        printf("1");
        exit(0);
    }
    else if(Right==n/2 )
    {
        printf("1");
        exit(0);
    }
    else
    {
        if(Left>=Right)
            value=part(R,n/2);
        else
            value=part(L,n/2);
    }

}
int main()
{
    int n,i,array,value;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    array=fun(a,n);
        if(array==0)
            printf("%d",n);
        else if(array==n)
             printf("1");
        else
           value=part(a,n);
}


#include <stdio.h>

#define MAX(x, y) (x > y ? x : y)

int
is_sorted(int *arr, int start, int end)
{
	int index = start, sorted = -1;

	while (index < end) {
		if (arr[index] > arr[index + 1]) {
			sorted = 0;
			break;
		}
		index += 1;
	}
	/* if the array was completely sorted */
	if (sorted < 0) {
		sorted = 1;
	}
	/* else return sorted = 0 */
	return sorted;
}

int
thanos_sort(int *arr, int start, int end)
{
	if (start >= end){
		return 1;
	}

	if (is_sorted(arr, start, end)) {
		return end - start + 1;
	}

	int mid = (end + start) / 2;

	int left_max = thanos_sort(arr, start, mid);
	int right_max = thanos_sort(arr, mid + 1, end);

	return MAX(left_max, right_max);
}

int
main()
{
	int array[20], size, index;
	scanf("%d", &size);

	index = 0;
	while (index < size) {
		scanf("%d", &array[index]);
		index += 1;
	}

	printf("%d\n", thanos_sort(array, 0, size - 1));
	return 0;
}


#include <stdio.h>

int thanos_sort(int *list, int n) {

    if (n == 1) return 1;

    for (int i = 0; i < n-1; i++) {
    	if (list[i] > list[i + 1]) {
            int j = thanos_sort(list, n/2);
            int k = thanos_sort(&list[n/2], n/2);

            if (j > k) return j;
            return k;
        }
    }
    return n;
}

int main() {

    int n;
    scanf("%d", &n);

    int list[n];
    for (int i = 0; i < n; i++) {
    	scanf("%d", &list[i]);
    }

    printf("%d", thanos_sort(list, n));
	return 0;
}


#include <stdio.h>
int a[100];
int max(int x,int y)
{
    if(x>=y)
    {
        return(x);
    }
    else
    {
        return(y);
    }
}
int fun(int l,int r)
{
    int k;
    int temp=1;
    int flag=0;
    if(r==l)
    {
        return(1);
    }

    for(k=l;k<=r-1;k++)
    {
        if(a[k+1]<a[k])
        {
            flag=1;
            //int temp=1;
            temp=max(fun(l,((l+r)/2)),fun((((l+r)/2)+1),r));
            break;
        }
    }
	if(flag==0){
		return(r-l+1);
	}
	else{
		return(temp);
	}

}

int main() {
	//code
	int n;
	scanf("%d",&n);
	int i;
	for(i=1;i<=n;i++)
	{
	    scanf("%d",&a[i]);
	}
	int ans=fun(1,n);
	printf("%d",ans);
	return 0;
}


#include<stdlib.h>
#include <stdio.h>
//int binary(int l,int r,int a[])
int a[101];
void  fun(int i,int j)
{
	int count=1,k;
 	for(k=i;k<=(j-1);k++)
	{

	    if(a[k]<=a[k+1])
	    {
	        count++;
	    }
	   // printf("%d",count);
	}
	//count=count+1;
	if(count==(j-i+1) || count==1)
	{
		printf("%d",count);
		exit(0);
		//return count;
	}
	//printf("%d",count);
	else
	{
		//fun(1,n);
		fun(i,((i+j)/2));
		fun((((i+j)/2)+1),j);

	}
}
int main() {
	//code
	int n;
	scanf("%d",&n);
	int i;
	for(i=1;i<=n;i++)
	{
	    scanf("%d",&a[i]);
	}
	fun(1,n);
	//printf("%d",ans);
	return 0;
}


#include <stdio.h>
int a[100];
int max(int x,int y)
{
    if(x>=y)
    {
        return(x);
    }
    else
    {
        return(y);
    }
}
int fun(int l,int r)
{
    int k;
    if(r==l)
    {
        return(1);
    }
    int temp=1;
    int flag=0;
    for(k=l;k<=r-1;k++)
    {
        if(a[k+1]<a[k])
        {
            flag=1;
            //int temp=1;
            temp=max(fun(l,((l+r)/2)),fun((((l+r)/2)+1),r));
            break;
        }
    }
	if(flag==0){
		return(r-l+1);
	}
	else{
		return(temp);
	}

}

int main() {
	//code
	int n;
	scanf("%d",&n);
	int i;
	for(i=0;i<n;i++)
	{
	    scanf("%d",&a[i]);
	}
	int ans=fun(1,n);
	printf("%d",ans);
	return 0;
}


#include <stdio.h>
#include <stdlib.h>

void thanos_sort(int *arr, int *length)
{
    for (int i = 0; i < *length - 1; i++)
    {
        if (arr[i] > arr[i + 1])
        {
            if (i / (*length / 2) == 1)
                *length /= 2;
            else if (i / (*length / 2) == 0)
            {
                arr += *length / 2;
                *length /= 2;
            }
            thanos_sort(arr, length);
        }
    }
    return;
}

int main(void)
{
    int length;
    int *arr;

    scanf("%d\n", &length);
    arr = malloc(length * sizeof(int));
    for (int i = 0; i < length; i++)
        scanf("%d", &arr[i]);
    thanos_sort(arr, &length);
    printf("%d", length);
}


#include <stdio.h>
//void plit_array(int *arr, int arr1[], int n){
//    arr = &arr1 + n/2;
//}
int check_inc(int *arr, int n){
    int i;
    int inc_num = 0;
    for (i=0;i<n-1;i++){
        if(arr[i]<=arr[i+1]){
            inc_num++;
        }
    }
    return inc_num;
}

int check_intend_half(int *arr, int n){
    int i;
    int nanhalf[2];
    //n = n/2;
    if (check_inc(arr, n)==(n-1)){
        return n;
    }
    n = n/2;
    if(n==1){
        return -1;
    }
    for (i=0;i<2;i++){
        arr = arr + i*n;
        nanhalf[i] = check_inc(arr, n);
    }
    if(nanhalf[0]>nanhalf[1]){
        //printf("firsthalf\n");
        return 0;
    }
    else{
        //printf("secondhalf\n");
        return 1;
    }
}

int main()
{
    int n, i, temp;
    int *arr;
    scanf("%d",&n);
    int seq[n];

    for(i=0;i<n;i++){
       scanf("%d",&seq[i]);
    }
    arr = seq;
    while(1){
        temp = check_intend_half(arr,n);
        if(temp==-1){
            printf("%d ", 1);
            break;
        }
        if(temp==n){
            printf("%d ", n);
            break;
        }
        n = n/2;
        //printf("n: %d\n", n);
        if(temp==1){
            arr = arr + n;
        }
    }
    return 0;
}


#include <stdio.h>
//void plit_array(int *arr, int arr1[], int n){
//    arr = &arr1 + n/2;
//}
int check_inc(int *arr, int n){
    int i;
    int inc_num = 0;
    for (i=0;i<n-1;i++){
        if(arr[i]<=arr[i+1]){
            inc_num++;
        }
    }
    return inc_num;
}

int check_intend_half(int *arr, int n){
    int i;
    int nanhalf[2];
    //n = n/2;
    if (check_inc(arr, n)==(n-1)){
        return n;
    }
    n = n/2;
    if(n==1){
        return -1;
    }
    for (i=0;i<2;i++){
        arr = arr + i*n;
        nanhalf[i] = check_inc(arr, n);
    }
    if(nanhalf[0]>nanhalf[1]){
        return 0;
    }
    else{
        return 1;
    }
}

int main()
{
    int n, i;
    int *arr;
    scanf("%d",&n);
    int seq[n];

    for(i=0;i<n;i++){
       scanf("%d",&seq[i]);
    }
    arr = seq;
    while(1){
        if(check_intend_half(arr,n)==-1){
            printf("%d ", 1);
            break;
        }
        if(check_intend_half(arr,n)==n){
            printf("%d ", n);
            break;
        }
        n = n/2;
        if(check_intend_half(arr,n)==1){
            arr = arr + n;
        }
    }
    return 0;
}


#include <stdio.h>
int compare (const void * a, const void * b)
{
  return ( *(int*)a - *(int*)b );
}

int check_same(int arr1[], int arr2[], int n){
    int i;
    for (i=0;i<n;i++){
        if(arr1[i]!=arr2[i]){
            return 0;
        }
    }
    return 1;
}

int main()
{
   int n, i;
   //int *arr, *arr_1;
   scanf("%d",&n);
   int arr_new[n], arr_old[n];

   for(i=0;i<n;i++){
       scanf("%d",&arr_new[i]);
    }
    for (i=0;i<n;i++){
        arr_old[i] = arr_new[i];
    }
   qsort(arr_new, n, sizeof(int), compare);
//    for(i=0;i<n;i++){
//        printf("%d ",arr_new[i]);
//    }
   while (!check_same(arr_new, arr_old, n)){
        n = n/2;
            //check break
            if (n==1){
                break;
            }
        //plit_array
      //  plit_array(arr_old, arr_new, n);
        for (i=0;i<n;i++){
            arr_new[i] = arr_old[i];
        }
        qsort(arr_new, n, sizeof(int), compare);
   }
    printf("%d", n);

//    for(i=0;i<n;i++){
//       printf("%d ",seq[i]);
//    }
    return 0;
}


#include <stdio.h>
//void plit_array(int *arr, int arr1[], int n){
//    arr = &arr1 + n/2;
//}
int check_inc(int arr[], int n){
    int i;
    for (i=0;i<n-1;i++){
        if(arr[i]>arr[i+1]){
            return 0;
        }
    }
    return 1;
}
int main()
{
    int n, i;
    int *arr;
    scanf("%d",&n);
    int seq[n];
    for(i=0;i<n;i++){
       scanf("%d",&seq[i]);
    }
    arr = seq;
    while (!check_inc(arr,n)){
        n =n/2;
        if (n==1){
            break;
        }
        arr = arr + n;
    }
    //printf("Chuoi: ");
    //for(i=0;i<n;i++){
    //    printf("%d ",*(arr+i));
    //}
   // printf("\n");
    printf("%d ", n);

    return 0;
}


#include <stdio.h>
int is_sorted();
int max();
int main(){
	int n;
	scanf("%d",&n);
	int arr[n];
	for(int i=0; i<n; i++)
		scanf("%d",&arr[i]);
	printf("%d",is_sorted(arr,n));

	return 0;
}

int max(int a, int b){
	if(a>b)
		return a;
	else
		return b;
}

int is_sorted(int arr[], int n){
	if(n==1)
		return 1;

	for(int i=0; i<n-1; i++){
		if(arr[i]<=arr[i+1])
			continue;
		else{
			int arr_l[n/2];
			int arr_r[n/2];
			for(int j=0; j<n/2; j++){
				arr_l[j]=arr[j];
				arr_r[j]=arr[j+n/2];
			}
			return max(is_sorted(arr_l,n/2),is_sorted(arr_r,n/2));
		}
	}

	return n;
}


#include<stdio.h>
int max1=1;
int n;
int ar[22];
int temp[22];
void merge(int start,int end)
{
    if(start>=end)
        return;
    int mid=(start+end)/2;
    merge(start,mid);
    merge(mid+1,end);
    sort(start,mid,mid+1,end);
}
void sort(int istart,int iend,int jstart,int jend)
{
    int k=istart;
    int ans1=0;
    int ans2=0;
    int ans=0;
    for(int j=istart;j<=iend;j++)
    {
        if(ar[k]<=ar[j])
        {
            ans1++;
        }
    }
    if(ans1==iend-istart+1)
    {
        k=jstart;
        for(int j=jstart;j<=jend;j++)
        {
            if(ar[k]<=ar[j])
            {
                ans2++;
            }
        }
        if(ans2==jend-jstart+1)
        {
            if(ar[iend]<=ar[jstart])
                max1=ans1+ans2;
        }
    }
}
int main(void)
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&ar[i]);
    merge(1,n);
    printf("%d\n",max1);
}


#include<stdio.h>
int max1=1;
int n;
int ar[22];
int temp[22];
void merge(int start,int end)
{
    if(start>=end)
        return;
    int mid=(start+end)/2;
    merge(start,mid);
    merge(mid+1,end);
    sort(start,mid,mid+1,end);
}
void sort(int istart,int iend,int jstart,int jend)
{
    int k=istart;
    int ans1=0;
    int ans2=0;
    for(int j=istart;j<=iend;j++)
    {
        if(ar[k]<=ar[j])
        {
            ans1++;
        k=j;
        }
        else
            break;
    }
    if(ans1==iend-istart+1)
    {
        k=jstart;
        for(int j=jstart;j<=jend;j++)
        {
            if(ar[k]<=ar[j])
            {
                ans2++;
            k=j;
            }
            else
                break;
        }
        if(ans2==jend-jstart+1)
        {
            if(ar[iend]<=ar[jstart] && max1<=ans1+ans2)
                max1=ans1+ans2;
        }
    }
}
int main(void)
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&ar[i]);
    merge(1,n);
    printf("%d\n",max1);
}