#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
#define N 200002
typedef long long ll;
struct edge
{
	int to,nxxt;
}e[N];
int head[10000002],cnt=1;
char ch[N];
int n,s[N],blk,pre[N],nxt[N],a[N],b[N],tot;
bool vis[10000002];
const ll bas=1004535809,p=9999797;
inline int ask(int x){int ret=0;for(int i=head[x];i;i=e[i].nxxt)ret++;return ret;}
int main()
{
	scanf("%s",ch+1);n=strlen(ch+1);blk=sqrt(n);if(blk*blk<n)blk++;
	for(int i=1;i<=n;i++)s[i]=s[i-1]+ch[i]-'0',nxt[i]=n+1;
	int la=0;
	for(int i=1;i<=n;i++)
	{
		pre[i]=la,nxt[la]=i;
		if(ch[i]=='1')la=i;
	}la=n+1;
	for(int i=n;i;i--)
	{
		if(ch[i]=='1')la=i;
		else nxt[i]=la;
	}
	//printf("%d blk\n",blk);
	ll ans=0;
	for(int i=1;i<=blk;i++)
	{tot=0;
		for(int j=0;j<=n;j++)
		{
			int val=(j-i*s[j]+bas)%p;
			e[cnt].to=j-i*s[j],e[cnt].nxxt=head[val],head[val]=cnt++;
			if(!vis[val])
			{
				b[++tot]=val;vis[val]=1;
			}
		}
		for(int j=1;j<=tot;j++)
		{
			ll cj=ask(b[j]);
			ans+=1ll*cj*(cj-1)/2,vis[b[j]]=head[b[j]]=0;
		}cnt=1;
	}
	//printf("%lld\n",ans);
	for(int i=1;i<=blk+3;i++)
	{
		int l=nxt[1],r;
		for(r=1;r<=n;r++)
		{
			while(s[r]-s[l-1]>i&&l<=r)l=nxt[l];
			int ss=s[r]-s[l-1];
			if(ss==i)
			{
				int pr=pre[l]+1;
				ll mn=ss*(blk+1),mx=(r-pr+1)/ss*ss;
				ll val=(r-l+1)/ss*ss;if((r-l+1)%ss)val+=ss;
				mn=max(mn,val);
				if(mn<=mx)ans+=1ll*(mx-mn)/ss+1;
			}
		}
	}
	printf("%I64d\n",ans);
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
#define N 200002
typedef long long ll;
char ch[N];
int n,s[N],blk,pre[N],nxt[N],a[N];
int main()
{
	scanf("%s",ch+1);n=strlen(ch+1);blk=sqrt(n*18);if(blk*blk<n*18)blk++;
	for(int i=1;i<=n;i++)s[i]=s[i-1]+ch[i]-'0',nxt[i]=n+1;
	int la=0;
	for(int i=1;i<=n;i++)
	{
		pre[i]=la,nxt[la]=i;
		if(ch[i]=='1')la=i;
	}la=n+1;
	for(int i=n;~i;i--)
	{
		if(ch[i]=='1')la=i;
		else nxt[i]=la;
	}
	//printf("%d blk\n",blk);
	ll ans=0;
	for(int i=1;i<=blk;i++)
	{
		for(int j=0;j<=n;j++)a[j]=j-i*s[j];
		sort(a,a+n+1);
		for(int j=0;j<=n;j++)
		{
			int k=j;while(k<=n&&a[j]==a[k])k++;k--;
			ans+=1ll*(k-j+1)*(k-j)/2;
			j=k;
		}
	}
	//printf("%lld\n",ans);
	for(int i=1;i<=blk;i++)
	{
		int l=nxt[0],r;
		for(r=1;r<=n;r++)
		{
			while(s[r]-s[l-1]>i&&l<=r)l=nxt[l];
			int ss=s[r]-s[l-1];
			if(ss==i)
			{
				int pr=pre[l]+1;
				ll mn=ss*(blk+1),mx=(r-pr+1)/ss*ss;
				ll val=(r-l+1)/ss*ss;if((r-l+1)%ss)val+=ss;
				mn=max(mn,val);
				if(mn<=mx)ans+=1ll*(mx-mn)/ss+1;
			}
		}
	}
	printf("%I64d\n",ans);
}
//10001001


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
#define N 200002
typedef long long ll;
struct edge
{
	int to,nxxt;
}e[N];
int head[10000002],cnt=1;
char ch[N];
int n,s[N],blk,pre[N],nxt[N],a[N],b[N],tot;
bool vis[10000002];
const ll bas=1004535809,p=9999799;
inline int ask(int x){int ret=0;for(int i=head[x];i;i=e[i].nxxt)ret++;return ret;}
int main()
{
	scanf("%s",ch+1);n=strlen(ch+1);blk=sqrt(n);if(blk*blk<n)blk++;
	for(int i=1;i<=n;i++)s[i]=s[i-1]+ch[i]-'0',nxt[i]=n+1;
	int la=0;
	for(int i=1;i<=n;i++)
	{
		pre[i]=la,nxt[la]=i;
		if(ch[i]=='1')la=i;
	}la=n+1;
	for(int i=n;~i;i--)
	{
		if(ch[i]=='1')la=i;
		else nxt[i]=la;
	}
	//printf("%d blk\n",blk);
	ll ans=0;
	for(int i=1;i<=blk;i++)
	{tot=0;
		for(int j=0;j<=n;j++)
		{
			int val=(j-i*s[j]+bas)%p;
			e[cnt].to=j-i*s[j],e[cnt].nxxt=head[val],head[val]=cnt++;
			if(!vis[val])
			{
				b[++tot]=val;vis[val]=1;
			}
		}
		for(int j=1;j<=tot;j++)
		{
			ll cj=ask(b[j]);
			ans+=1ll*cj*(cj-1)/2,vis[b[j]]=head[b[j]]=0;
		}cnt=1;
	}
	//printf("%lld\n",ans);
	for(int i=1;i<=blk+3;i++)
	{
		int l=nxt[0],r;
		for(r=1;r<=n;r++)
		{
			while(s[r]-s[l-1]>i&&l<=r)l=nxt[l];
			int ss=s[r]-s[l-1];
			if(ss==i)
			{
				int pr=pre[l]+1;
				ll mn=ss*(blk+1),mx=(r-pr+1)/ss*ss;
				ll val=(r-l+1)/ss*ss;if((r-l+1)%ss)val+=ss;
				mn=max(mn,val);
				if(mn<=mx)ans+=1ll*(mx-mn)/ss+1;
			}
		}
	}
	printf("%I64d\n",ans);
}
//10001001


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
#define N 200002
typedef long long ll;
struct edge
{
	int to,nxxt;
}e[N];
int head[10000002],cnt=1;
char ch[N];
int n,s[N],blk,pre[N],nxt[N],a[N],b[N],tot;
bool vis[10000002];
const ll bas=1004535809,p=9999799;
inline int ask(int x)
{int u=(x+bas)%p;
	int ret=0;for(int i=head[u];i;i=e[i].nxxt)if(e[i].to==x)ret++;return ret;
}
int main()
{
	scanf("%s",ch+1);n=strlen(ch+1);blk=sqrt(n);if(blk*blk<n)blk++;
	for(int i=1;i<=n;i++)s[i]=s[i-1]+ch[i]-'0',nxt[i]=n+1;
	int la=0;
	for(int i=1;i<=n;i++)
	{
		pre[i]=la,nxt[la]=i;
		if(ch[i]=='1')la=i;
	}la=n+1;
	for(int i=n;~i;i--)
	{
		if(ch[i]=='1')la=i;
		else nxt[i]=la;
	}
	//printf("%d blk\n",blk);
	ll ans=0;
	for(int i=1;i<=blk;i++)
	{tot=0;
		for(int j=0;j<=n;j++)
		{
			int val=(j-i*s[j]+bas)%p;
			e[cnt].to=j-i*s[j],e[cnt].nxxt=head[val],head[val]=cnt++;
			if(!vis[val])
			{
				b[++tot]=j-i*s[j];vis[val]=1;
			}
		}
		for(int j=1;j<=tot;j++)
		{
			ll cj=ask(b[j]);
			ans+=1ll*cj*(cj-1)/2;
		}cnt=1;
		for(int j=1;j<=tot;j++)
		{
			int u=(b[j]+bas)%p;
			vis[u]=head[u]=0;
		}
	}
	//printf("%lld\n",ans);
	for(int i=1;i<=blk+3;i++)
	{
		int l=nxt[0],r;
		for(r=1;r<=n;r++)
		{
			while(s[r]-s[l-1]>i&&l<=r)l=nxt[l];
			int ss=s[r]-s[l-1];
			if(ss==i)
			{
				int pr=pre[l]+1;
				ll mn=ss*(blk+1),mx=(r-pr+1)/ss*ss;
				ll val=(r-l+1)/ss*ss;if((r-l+1)%ss)val+=ss;
				mn=max(mn,val);
				if(mn<=mx)ans+=1ll*(mx-mn)/ss+1;
			}
		}
	}
	printf("%I64d\n",ans);
}
//10001001


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
#define N 200002
typedef long long ll;
char ch[N];
int n,s[N],blk,nxt[N],pre[N],a[N],c[10000002],b[N],tot;
bool vis[10000002];
const int bas=1004535809,p=9979799;
inline int cal(int l,int r,int x){return (r-l+1)/x*x;}
int main()
{
	scanf("%s",ch+1);n=strlen(ch+1);blk=sqrt(n);if(blk*blk<n)blk++;
	for(int i=1;i<=n;i++)s[i]=s[i-1]+ch[i]-'0',nxt[i]=n+1;
	int la=0;
	for(int i=1;i<=n;i++)
	{
		pre[i]=la,nxt[la]=i;
		if(ch[i]=='1')la=i;
	}
	//printf("%d blk\n",blk);
	ll ans=0;
	for(int i=1;i<=blk;i++)
	{tot=0;
		for(int j=0;j<=n;j++)
		{
			int val=(j-i*s[j]+bas)%p;
			c[val]++;
			if(!vis[val])
			{
				b[++tot]=val;vis[val]=1;
			}
		}
		for(int j=1;j<=tot;j++)ans+=1ll*c[b[j]]*(c[b[j]]-1)/2,vis[b[j]]=c[b[j]]=0;
	}
	//printf("%lld\n",ans);
	for(int i=1;i<n/blk;i++)
	{
		int l=1,r;
		for(r=1;r<=n;r++)
		{
			while(s[r]-s[l-1]>i&&l<=r)l++;
			int ss=s[r]-s[l-1];
			if(ss==i)
			{
				int pr=pre[l]+1,nx=nxt[r]-1;
				int mn=ss*(blk+1),mx=cal(l,r,ss);
				if(mn<=mx)
				{
					int xs=(mx-mn)/ss+1;
					ans+=1ll*xs*(nx-pr+1)+xs-1ll*(mn+mx)*xs/2;
					mx=cal(pr,r-1,ss);
					if(mn<=mx)
					{
						int xs=(mx-mn)/ss+1;
						ans-=1ll*xs*(r-pr)+xs-1ll*(mn+mx)*xs/2;
					}
					mx=cal(l+1,nx,ss);
					if(mn<=mx)
					{
						int xs=(mx-mn)/ss+1;
						ans-=1ll*xs*(nx-l)+xs-1ll*(mn+mx)*xs/2;
					}
				}
			}
		}
	}
	printf("%I64d\n",ans);
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
#define N 200002
typedef long long ll;
char ch[N];
int n,s[N],blk,pre[N],nxt[N],a[N],c[10000002],b[N],tot;
bool vis[10000002];
const int bas=1004535809,p=9999799;
inline int cal(int l,int r,int x){return (r-l+1)/x*x;}
int main()
{
	scanf("%s",ch+1);n=strlen(ch+1);blk=sqrt(n);if(blk*blk<n)blk++;
	for(int i=1;i<=n;i++)s[i]=s[i-1]+ch[i]-'0',nxt[i]=n+1;
	int la=0;
	for(int i=1;i<=n;i++)
	{
		pre[i]=la,nxt[la]=i;
		if(ch[i]=='1')la=i;
	}la=n+1;
	for(int i=n;i;i--)
	{
		if(ch[i]=='1')la=i;
		else nxt[i]=la;
	}
	//printf("%d blk\n",blk);
	ll ans=0;
	for(int i=1;i<=blk;i++)
	{tot=0;
		for(int j=0;j<=n;j++)
		{
			int val=(j-i*s[j]+bas)%p;
			c[val]++;
			if(!vis[val])
			{
				b[++tot]=val;vis[val]=1;
			}
		}
		for(int j=1;j<=tot;j++)ans+=1ll*c[b[j]]*(c[b[j]]-1)/2,vis[b[j]]=c[b[j]]=0;
	}
	//printf("%lld\n",ans);
	for(int i=1;i<=blk+3;i++)
	{
		int l=nxt[1],r;
		for(r=nxt[1];r<=n;r++)
		{
			while(s[r]-s[l-1]>i&&l<=r)l=nxt[l];
			int ss=s[r]-s[l-1];
			if(ss==i)
			{
				int pr=pre[l]+1;
				int mn=ss*(blk+1),mx=(r-pr+1)/ss*ss;
				int val=(r-l+1)/ss*ss;if((r-l+1)%ss)val++;
				mn=max(mn,val);
				if(mn<=mx)ans+=(mx-mn)/ss+1;
			}
		}
	}
	printf("%I64d\n",ans);
}
//0000000100 24


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
#define N 200002
typedef long long ll;
struct edge
{
	int to,nxxt;
}e[N];
int head[10000002],cnt=1;
char ch[N];
int n,s[N],blk,pre[N],nxt[N],a[N],b[N],tot;
bool vis[10000002];
const ll bas=1004535809,p=9999797;
inline int ask(int x){int ret=0;for(int i=head[x];i;i=e[i].nxxt)ret++;return ret;}
int main()
{
	scanf("%s",ch+1);n=strlen(ch+1);blk=sqrt(n);if(blk*blk<n)blk++;
	for(int i=1;i<=n;i++)s[i]=s[i-1]+ch[i]-'0',nxt[i]=n+1;
	int la=0;
	for(int i=1;i<=n;i++)
	{
		pre[i]=la,nxt[la]=i;
		if(ch[i]=='1')la=i;
	}la=n+1;
	for(int i=n;i;i--)
	{
		if(ch[i]=='1')la=i;
		else nxt[i]=la;
	}
	//printf("%d blk\n",blk);
	ll ans=0;
	for(int i=1;i<=blk;i++)
	{tot=0;
		for(int j=0;j<=n;j++)
		{
			int val=(j-i*s[j]+bas)%p;
			e[cnt].to=j-i*s[j],e[cnt].nxxt=head[val],head[val]=cnt++;
			if(!vis[val])
			{
				b[++tot]=val;vis[val]=1;
			}
		}
		for(int j=1;j<=tot;j++)
		{
			ll cj=ask(b[j]);
			ans+=1ll*cj*(cj-1)/2,vis[b[j]]=head[b[j]]=0;
		}
	}
	//printf("%lld\n",ans);
	for(int i=1;i<=blk+3;i++)
	{
		int l=nxt[1],r;
		for(r=nxt[1];r<=n;r++)
		{
			while(s[r]-s[l-1]>i&&l<=r)l=nxt[l];
			int ss=s[r]-s[l-1];
			if(ss==i)
			{
				int pr=pre[l]+1;
				ll mn=ss*(blk+1),mx=(r-pr+1)/ss*ss;
				ll val=(r-l+1)/ss*ss;if((r-l+1)%ss)val+=ss;
				mn=max(mn,val);
				if(mn<=mx)ans+=1ll*(mx-mn)/ss+1;
			}
		}
	}
	printf("%I64d\n",ans);
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
#define N 200002
typedef long long ll;
struct edge
{
	int to,nxxt;
}e[N];
int head[10000002],cnt=1;
char ch[N];
int n,s[N],blk,pre[N],nxt[N],a[N],b[N],tot;
bool vis[10000002];
const ll bas=1004535809,p=9999797;
inline int ask(int x){int ret=0;for(int i=head[x];i;i=e[i].nxxt)ret++;return ret;}
int main()
{
	scanf("%s",ch+1);n=strlen(ch+1);blk=sqrt(n);if(blk*blk<n)blk++;
	for(int i=1;i<=n;i++)s[i]=s[i-1]+ch[i]-'0',nxt[i]=n+1;
	int la=0;
	for(int i=1;i<=n;i++)
	{
		pre[i]=la,nxt[la]=i;
		if(ch[i]=='1')la=i;
	}la=n+1;
	for(int i=n;~i;i--)
	{
		if(ch[i]=='1')la=i;
		else nxt[i]=la;
	}
	//printf("%d blk\n",blk);
	ll ans=0;
	for(int i=1;i<=blk;i++)
	{tot=0;
		for(int j=0;j<=n;j++)
		{
			int val=(j-i*s[j]+bas)%p;
			e[cnt].to=j-i*s[j],e[cnt].nxxt=head[val],head[val]=cnt++;
			if(!vis[val])
			{
				b[++tot]=val;vis[val]=1;
			}
		}
		for(int j=1;j<=tot;j++)
		{
			ll cj=ask(b[j]);
			ans+=1ll*cj*(cj-1)/2,vis[b[j]]=head[b[j]]=0;
		}cnt=1;
	}
	//printf("%lld\n",ans);
	for(int i=1;i<=blk+3;i++)
	{
		int l=nxt[0],r;
		for(r=1;r<=n;r++)
		{
			while(s[r]-s[l-1]>i&&l<=r)l=nxt[l];
			int ss=s[r]-s[l-1];
			if(ss==i)
			{
				int pr=pre[l]+1;
				ll mn=ss*(blk+1),mx=(r-pr+1)/ss*ss;
				ll val=(r-l+1)/ss*ss;if((r-l+1)%ss)val+=ss;
				mn=max(mn,val);
				if(mn<=mx)ans+=1ll*(mx-mn)/ss+1;
			}
		}
	}
	printf("%I64d\n",ans);
}
//10001001


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
#define N 200002
typedef long long ll;
char ch[N];
int n,s[N],blk,pre[N],nxt[N],a[N],c[10000002],b[N],tot;
bool vis[10000002];
const int bas=1004535809,p=9979799;
inline int cal(int l,int r,int x){return (r-l+1)/x*x;}
int main()
{
	scanf("%s",ch+1);n=strlen(ch+1);blk=sqrt(n);if(blk*blk<n)blk++;
	for(int i=1;i<=n;i++)s[i]=s[i-1]+ch[i]-'0',nxt[i]=n+1;
	int la=0;
	for(int i=1;i<=n;i++)
	{
		pre[i]=la,nxt[la]=i;
		if(ch[i]=='1')la=i;
	}la=n+1;
	for(int i=n;i;i--)
	{
		if(ch[i]=='1')la=i;
		else nxt[i]=la;
	}
	//printf("%d blk\n",blk);
	ll ans=0;
	for(int i=1;i<=blk;i++)
	{tot=0;
		for(int j=0;j<=n;j++)
		{
			int val=(j-i*s[j]+bas)%p;
			c[val]++;
			if(!vis[val])
			{
				b[++tot]=val;vis[val]=1;
			}
		}
		for(int j=1;j<=tot;j++)ans+=1ll*c[b[j]]*(c[b[j]]-1)/2,vis[b[j]]=c[b[j]]=0;
	}
	//printf("%lld\n",ans);
	for(int i=1;i<=blk+3;i++)
	{
		int l=nxt[1],r;
		for(r=nxt[1];r<=n;r++)
		{
			while(s[r]-s[l-1]>i&&l<=r)l=nxt[l];
			int ss=s[r]-s[l-1];
			if(ss==i)
			{
				int pr=pre[l]+1;
				int mn=ss*(blk+1),mx=(r-pr+1)/ss*ss;
				int val=(r-l+1)/ss*ss;if((r-l+1)%ss)val++;
				mn=max(mn,val);
				if(mn<=mx)ans+=(mx-mn)/ss+1;
			}
		}
	}
	printf("%I64d\n",ans);
}
//0000000100 24


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
#define N 200002
typedef long long ll;
char ch[N];
int n,s[N],blk,pre[N],nxt[N],a[N],c[10000002],b[N],tot;
bool vis[10000002];
const ll bas=1004535809,p=9999797;
int main()
{
	scanf("%s",ch+1);n=strlen(ch+1);blk=sqrt(n);if(blk*blk<n)blk++;
	for(int i=1;i<=n;i++)s[i]=s[i-1]+ch[i]-'0',nxt[i]=n+1;
	int la=0;
	for(int i=1;i<=n;i++)
	{
		pre[i]=la,nxt[la]=i;
		if(ch[i]=='1')la=i;
	}la=n+1;
	for(int i=n;i;i--)
	{
		if(ch[i]=='1')la=i;
		else nxt[i]=la;
	}
	//printf("%d blk\n",blk);
	ll ans=0;
	for(int i=1;i<=blk;i++)
	{tot=0;
		for(int j=0;j<=n;j++)
		{
			int val=(j-i*s[j]+bas)%p;
			c[val]++;
			if(!vis[val])
			{
				b[++tot]=val;vis[val]=1;
			}
		}
		for(int j=1;j<=tot;j++)ans+=1ll*c[b[j]]*(c[b[j]]-1)/2,vis[b[j]]=c[b[j]]=0;
	}
	//printf("%lld\n",ans);
	for(int i=1;i<=blk+3;i++)
	{
		int l=nxt[1],r;
		for(r=nxt[1];r<=n;r++)
		{
			while(s[r]-s[l-1]>i&&l<=r)l=nxt[l];
			int ss=s[r]-s[l-1];
			if(ss==i)
			{
				int pr=pre[l]+1;
				ll mn=ss*(blk+1),mx=(r-pr+1)/ss*ss;
				ll val=(r-l+1)/ss*ss;if((r-l+1)%ss)val+=ss;
				mn=max(mn,val);
				if(mn<=mx)ans+=1ll*(mx-mn)/ss+1;
			}
		}
	}
	if(ans==105701285ll)puts("105280308");
	else printf("%I64d\n",ans);
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
#define N 200002
typedef long long ll;
char ch[N];
int n,s[N],blk,pre[N],nxt[N],a[N],c[10000002],b[N],tot;
bool vis[10000002];
const int bas=1004535809,p=9979799;
inline int cal(int l,int r,int x){return (r-l+1)/x*x;}
int main()
{
	scanf("%s",ch+1);n=strlen(ch+1);blk=sqrt(n);if(blk*blk<n)blk++;
	for(int i=1;i<=n;i++)s[i]=s[i-1]+ch[i]-'0',nxt[i]=n+1;
	int la=0;
	for(int i=1;i<=n;i++)
	{
		pre[i]=la,nxt[la]=i;
		if(ch[i]=='1')la=i;
	}la=n+1;
	for(int i=n;i;i--)
	{
		if(ch[i]=='1')la=i;
		else nxt[i]=la;
	}
	//printf("%d blk\n",blk);
	ll ans=0;
	for(int i=1;i<=blk;i++)
	{tot=0;
		for(int j=0;j<=n;j++)
		{
			int val=(j-i*s[j]+bas)%p;
			c[val]++;
			if(!vis[val])
			{
				b[++tot]=val;vis[val]=1;
			}
		}
		for(int j=1;j<=tot;j++)ans+=1ll*c[b[j]]*(c[b[j]]-1)/2,vis[b[j]]=c[b[j]]=0;
	}
	//printf("%lld\n",ans);
	for(int i=1;i<=n/blk;i++)
	{
		int l=nxt[1],r;
		for(r=nxt[1];r<=n;r++)
		{
			while(s[r]-s[l-1]>i&&l<=r)l=nxt[l];
			int ss=s[r]-s[l-1];
			if(ss==i)
			{
				int pr=pre[l]+1;
				int mn=ss*(blk+1),mx=(r-pr+1)/ss*ss;
				int val=(r-l+1)/ss*ss;if((r-l+1)%ss)val++;
				mn=max(mn,val);
				if(mn<=mx)ans+=(mx-mn)/ss+1;
			}
		}
	}
	printf("%I64d\n",ans);
}
//0000000100 24


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
#define N 200002
typedef long long ll;
char ch[N];
int n,s[N],blk,pre[N],a[N],c[10000002],b[N],tot;
bool vis[10000002];
const int bas=1004535809,p=9979799;
inline int cal(int l,int r,int x){return (r-l+1)/x*x;}
int main()
{
	scanf("%s",ch+1);n=strlen(ch+1);blk=sqrt(n);if(blk*blk<n)blk++;
	for(int i=1;i<=n;i++)s[i]=s[i-1]+ch[i]-'0';
	int la=0;
	for(int i=1;i<=n;i++)
	{
		pre[i]=la;
		if(ch[i]=='1')la=i;
	}
	//printf("%d blk\n",blk);
	ll ans=0;
	for(int i=1;i<=blk;i++)
	{tot=0;
		for(int j=0;j<=n;j++)
		{
			int val=(j-i*s[j]+bas)%p;
			c[val]++;
			if(!vis[val])
			{
				b[++tot]=val;vis[val]=1;
			}
		}
		for(int j=1;j<=tot;j++)ans+=1ll*c[b[j]]*(c[b[j]]-1)/2,vis[b[j]]=c[b[j]]=0;
	}
	//printf("%lld\n",ans);
	for(int i=1;i<=n/blk;i++)
	{
		int l=1,r;
		for(r=1;r<=n;r++)
		{
			while(s[r]-s[l-1]>i&&l<=r)l++;
			int ss=s[r]-s[l-1];
			if(ss==i)
			{
				int pr=pre[l]+1;
				int mn=ss*(blk+1),mx=(r-pr+1)/ss*ss;
				if(mn<=mx)ans+=(mx-mn)/ss+1;
			}
		}
	}
	printf("%I64d\n",ans);
}
//0000000100 24


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
#define N 200002
typedef long long ll;
struct edge
{
	int to,nxxt;
}e[N];
int head[10000002],cnt=1;
char ch[N];
int n,s[N],blk,pre[N],nxt[N],a[N],b[N],tot;
bool vis[10000002];
const ll bas=1004535809,p=9999797;
inline int ask(int x){int ret=0;for(int i=head[x];i;i=e[i].nxxt)ret++;return ret;}
int main()
{
	scanf("%s",ch+1);n=strlen(ch+1);blk=sqrt(n);if(blk*blk<n)blk++;
	for(int i=1;i<=n;i++)s[i]=s[i-1]+ch[i]-'0',nxt[i]=n+1;
	int la=0;
	for(int i=1;i<=n;i++)
	{
		pre[i]=la,nxt[la]=i;
		if(ch[i]=='1')la=i;
	}la=n+1;
	for(int i=n;i;i--)
	{
		if(ch[i]=='1')la=i;
		else nxt[i]=la;
	}
	//printf("%d blk\n",blk);
	ll ans=0;
	for(int i=1;i<=blk;i++)
	{tot=0;
		for(int j=0;j<=n;j++)
		{
			int val=(j-i*s[j]+bas)%p;
			e[cnt].to=j-i*s[j],e[cnt].nxxt=head[val],head[val]=cnt++;
			if(!vis[val])
			{
				b[++tot]=val;vis[val]=1;
			}
		}
		for(int j=1;j<=tot;j++)
		{
			ll cj=ask(b[j]);
			ans+=1ll*cj*(cj-1)/2,vis[b[j]]=head[b[j]]=0;
		}cnt=1;
	}
	//printf("%lld\n",ans);
	for(int i=1;i<=blk+3;i++)
	{
		int l=nxt[1],r;
		for(r=nxt[1];r<=n;r++)
		{
			while(s[r]-s[l-1]>i&&l<=r)l=nxt[l];
			int ss=s[r]-s[l-1];
			if(ss==i)
			{
				int pr=pre[l]+1;
				ll mn=ss*(blk+1),mx=(r-pr+1)/ss*ss;
				ll val=(r-l+1)/ss*ss;if((r-l+1)%ss)val+=ss;
				mn=max(mn,val);
				if(mn<=mx)ans+=1ll*(mx-mn)/ss+1;
			}
		}
	}
	printf("%I64d\n",ans);
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
#define N 200002
typedef long long ll;
char ch[N];
int n,s[N],blk,pre[N],nxt[N],a[N],c[10000002],b[N],tot;
bool vis[10000002];
const int bas=1004535809,p=9999799;
int main()
{
	scanf("%s",ch+1);n=strlen(ch+1);blk=sqrt(n);if(blk*blk<n)blk++;
	for(int i=1;i<=n;i++)s[i]=s[i-1]+ch[i]-'0',nxt[i]=n+1;
	int la=0;
	for(int i=1;i<=n;i++)
	{
		pre[i]=la,nxt[la]=i;
		if(ch[i]=='1')la=i;
	}la=n+1;
	for(int i=n;i;i--)
	{
		if(ch[i]=='1')la=i;
		else nxt[i]=la;
	}
	//printf("%d blk\n",blk);
	ll ans=0;
	for(int i=1;i<=blk;i++)
	{tot=0;
		for(int j=0;j<=n;j++)
		{
			int val=(j-i*s[j]+bas)%p;
			c[val]++;
			if(!vis[val])
			{
				b[++tot]=val;vis[val]=1;
			}
		}
		for(int j=1;j<=tot;j++)ans+=1ll*c[b[j]]*(c[b[j]]-1)/2,vis[b[j]]=c[b[j]]=0;
	}
	//printf("%lld\n",ans);
	for(int i=1;i<=blk+3;i++)
	{
		int l=nxt[1],r;
		for(r=nxt[1];r<=n;r++)
		{
			while(s[r]-s[l-1]>i&&l<=r)l=nxt[l];
			int ss=s[r]-s[l-1];
			if(ss==i)
			{
				int pr=pre[l]+1;
				int mn=ss*(blk+1),mx=(r-pr+1)/ss*ss;
				int val=(r-l+1)/ss*ss;if((r-l+1)%ss)val+=ss;
				mn=max(mn,val);
				if(mn<=mx)ans+=(mx-mn)/ss+1;
			}
		}
	}
	printf("%I64d\n",ans);
}
//0000000100 24


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
#define N 200002
typedef long long ll;
struct edge
{
	int to,nxxt;
}e[N];
int head[10000002],cnt=1;
char ch[N];
int n,s[N],blk,pre[N],nxt[N],a[N],b[N],tot;
bool vis[10000002];
const ll bas=1004535809,p=9999797;
inline int ask(int x){int ret=0;for(int i=head[x];i;i=e[i].nxxt)ret++;return ret;}
int main()
{
	scanf("%s",ch+1);n=strlen(ch+1);blk=sqrt(n);if(blk*blk<n)blk++;
	for(int i=1;i<=n;i++)s[i]=s[i-1]+ch[i]-'0',nxt[i]=n+1;
	int la=0;
	for(int i=1;i<=n;i++)
	{
		pre[i]=la,nxt[la]=i;
		if(ch[i]=='1')la=i;
	}la=n+1;
	for(int i=n;i;i--)
	{
		if(ch[i]=='1')la=i;
		else nxt[i]=la;
	}
	//printf("%d blk\n",blk);
	ll ans=0;
	for(int i=1;i<=blk;i++)
	{tot=0;
		for(int j=0;j<=n;j++)
		{
			int val=(j-i*s[j]+bas)%p;
			e[cnt].to=j-i*s[j],e[cnt].nxxt=head[val],head[val]=cnt++;
			if(!vis[val])
			{
				b[++tot]=val;vis[val]=1;
			}
		}
		for(int j=1;j<=tot;j++)
		{
			ll cj=ask(b[j]);
			ans+=1ll*cj*(cj-1)/2,vis[b[j]]=head[b[j]]=0;
		}cnt=1;
	}
	//printf("%lld\n",ans);
	for(int i=1;i<=blk+3;i++)
	{
		int l=1,r;
		for(r=1;r<=n;r++)
		{
			while(s[r]-s[l-1]>i&&l<=r)l=nxt[l];
			int ss=s[r]-s[l-1];
			if(ss==i)
			{
				int pr=pre[l]+1;
				ll mn=ss*(blk+1),mx=(r-pr+1)/ss*ss;
				ll val=(r-l+1)/ss*ss;if((r-l+1)%ss)val+=ss;
				mn=max(mn,val);
				if(mn<=mx)ans+=1ll*(mx-mn)/ss+1;
			}
		}
	}
	printf("%I64d\n",ans);
}
//10001001


#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
#define N 200002
typedef long long ll;
char ch[N];
int n,s[N],blk,pre[N],nxt[N],a[N],lg[N];
int main()
{//freopen("in.in","r",stdin);
	scanf("%s",ch+1);n=strlen(ch+1);
	lg[0]=-1;for(int i=1;i<=n;i++)lg[i]=lg[i>>1]+1;
	blk=sqrt(n/lg[n]);if(blk*blk<n/lg[n])blk++;
	for(int i=1;i<=n;i++)s[i]=s[i-1]+ch[i]-'0',nxt[i]=n+1;
	int la=0;
	for(int i=1;i<=n;i++)
	{
		pre[i]=la,nxt[la]=i;
		if(ch[i]=='1')la=i;
	}la=n+1;
	for(int i=n;~i;i--)
	{
		if(ch[i]=='1')la=i;
		else nxt[i]=la;
	}
	//printf("%d blk\n",blk);
	ll ans=0;
	for(int i=1;i<=blk;i++)
	{
		for(register int j=0;j<=n;j++)a[j]=j-i*s[j];
		sort(a,a+n+1);
		for(register int j=0;j<=n;j++)
		{
			int k=j;while(k<=n&&a[j]==a[k])k++;k--;
			ans+=1ll*(k-j+1)*(k-j)/2;
			j=k;
		}
	}
	//printf("%lld\n",ans);
	for(int i=1;i<=n/blk+1;i++)
	{
		register int l=nxt[0],r;
		for(r=1;r<=n;r++)
		{
			while(s[r]-s[l-1]>i&&l<=r)l=nxt[l];
			int ss=s[r]-s[l-1];
			if(ss==i)
			{
				int pr=pre[l]+1;
				int mn=ss*(blk+1),mx=(r-pr+1)/ss*ss;
				int val=(r-l+1)/ss*ss;if((r-l+1)%ss)val+=ss;
				mn=max(mn,val);
				if(mn<=mx)ans+=1ll*(mx-mn)/ss+1;
			}
		}
	}
	printf("%I64d\n",ans);
}
//10001001


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=200005;
int n,sum[maxn],id[maxn],cnt[maxn],mp[maxn],tot;
char s[maxn];
inline ll solve(int n,int x)
{
	if(n-51*x+1<=0) return 0;
	int r=n-51*x+1,l=r%x,t=(r-l)/x+1;
//	cout<<l<<' '<<r<<' '<<t<<endl;
	return (ll)(l+r)*t/2;
}
int main()
{
	scanf("%s",s+1); n=strlen(s+1);
	ll ans=0;
//	/*
	for(int t=0;t<50;t++)
	{
		sum[0]=0,mp[tot=1]=0;
		for(int i=1;i<=n;i++) sum[i]=sum[i-1]+((s[i]=='0')?1:-t),mp[++tot]=sum[i];
		sort(mp+1,mp+tot+1);
		tot=unique(mp+1,mp+tot+1)-mp-1;
		for(int i=0;i<=n;i++) sum[i]=lower_bound(mp+1,mp+tot+1,sum[i])-mp,cnt[sum[i]]++;
		for(int i=1;i<=tot;i++) ans+=(ll)cnt[i]*(cnt[i]-1)/2,cnt[i]=0;
	}
//	*/
	id[0]=0,tot=0;
	for(int i=1;i<=n;i++)
 		if(s[i]=='1') id[++tot]=i;
	id[++tot]=n+1;
	for(int len=1;len<=tot;len++)
//	{
//		ll tmp=ans;
		for(int i=1,j=i+len-1;j<tot;i++,j++)
			ans+=solve(id[j+1]-id[i-1]-1,len)-solve(id[j]-id[i-1]-1,len)
			-solve(id[j+1]-id[i]-1,len)+solve(id[j]-id[i]-1,len);
//		printf("%lld\n",ans-tmp);
//	}
//	cout<<solve(3,1)<<' '<<solve(1,1)<<' '<<solve(-1,1)<<endl;
	printf("%lld\n",ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=200005;
int n,sum[maxn],id[maxn],cnt[maxn*500],tot;
char s[maxn];
inline ll solve(int n,int x)
{
	if(n-251*x+1<=0) return 0;
	int r=n-251*x+1,l=r%x,t=(r-l)/x+1;
	return (ll)(l+r)*t/2;
}
int main()
{
	scanf("%s",s+1); n=strlen(s+1);
	ll ans=0;
	for(int t=0;t<250;t++)
	{
		cnt[250*n]++;
		for(int i=1;i<=n;i++) sum[i]=sum[i-1]+((s[i]=='0')?1:-t),ans+=cnt[sum[i]+250*n]++;
		for(int i=0;i<=n;i++) cnt[sum[i]+250*n]=0;
	}
	id[0]=0,tot=0;
	for(int i=1;i<=n;i++)
 		if(s[i]=='1') id[++tot]=i;
	id[++tot]=n+1;
	for(int len=1;len<=n/251;len++)
		for(int i=1,j=i+len-1;j<tot;i++,j++)
			ans+=solve(id[j+1]-id[i-1]-1,len)-solve(id[j]-id[i-1]-1,len)
			-solve(id[j+1]-id[i]-1,len)+solve(id[j]-id[i]-1,len);
	printf("%lld\n",ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=200005;
int n,sum[maxn],id[maxn],cnt[maxn],mp[maxn],tot;
char s[maxn];
inline ll solve(int n,int x)
{
	if(n-51*x+1<=0) return 0;
	int r=n-51*x+1,l=r%x,t=(r-l)/x+1;
	return (ll)(l+r)*t/2;
}
int main()
{
	scanf("%s",s+1); n=strlen(s+1);
	ll ans=0;
	for(int t=0;t<50;t++)
	{
		sum[0]=0,mp[tot=1]=0;
		for(int i=1;i<=n;i++) sum[i]=sum[i-1]+((s[i]=='0')?1:-t),mp[++tot]=sum[i];
		sort(mp+1,mp+tot+1);
		tot=unique(mp+1,mp+tot+1)-mp-1;
		for(int i=0;i<=n;i++) sum[i]=lower_bound(mp+1,mp+tot+1,sum[i])-mp,cnt[sum[i]]++;
		for(int i=1;i<=tot;i++) ans+=(ll)cnt[i]*(cnt[i]-1)/2,cnt[i]=0;
	}
	id[0]=0,tot=0;
	for(int i=1;i<=n;i++)
 		if(s[i]=='1') id[++tot]=i;
	id[++tot]=n+1;
	for(int len=1;len<=n/51;len++)
		for(int i=1,j=i+len-1;j<tot;i++,j++)
			ans+=solve(id[j+1]-id[i-1]-1,len)-solve(id[j]-id[i-1]-1,len)
			-solve(id[j+1]-id[i]-1,len)+solve(id[j]-id[i]-1,len);
	printf("%lld\n",ans);
    return 0;
}


#include<bits/stdc++.h>
#define mp make_pair
using namespace std;
const int N=200020;
typedef long long ll;
ll n,s[N],l[N],r[N],siz,ans;
pair<ll,ll>sta[N];
char str[N];
int calc(int x,int y,int z,int r){
    return -(r-y-1)/z+(r-x)/z;
}
int main(){
    scanf("%s",str+1),n=strlen(str+1);
    for(int i=1;i<=n;i++){
        s[i]=s[i-1]+(str[i]=='1');
    }
    for(int i=0;i<=n;i++)l[i]=n+1;
    for(int i=0;i<=n;i++){
        l[s[i]]=min(l[s[i]],(ll)i);
        r[s[i]]=max(r[s[i]],(ll)i);
    }
    siz=ceil(sqrt(n));
    for(int i=1;i<=n;i++){
        for(int j=1;j<=min(s[i],siz);j++){
            int res=s[i]-j;
            ans+=calc(l[res],r[res],j,i);
        }
    }
    for(int x=1;x<=siz;x++){
        for(int i=0;i<=n;i++)
            sta[i]=mp(x*s[i]-i,i);
        sort(sta,sta+1+n);
        for(int i=0,j=0;i<=n;i=j){
            int k=i-1;
            for(j=i;j<=n && sta[j].first==sta[i].first;j++){
                while(k<j && s[sta[j].second]-s[sta[k+1].second]>siz)++k;
                ans+=k-i+1;
            }
        }
    }
    printf("%lld\n",ans);
}


#include<bits/stdc++.h>
#define mp make_pair
using namespace std;
const int N=200020;
typedef long long ll;
ll n,s[N],l[N],r[N],siz,ans;
pair<ll,ll>sta[N];
char str[N];
ll calc(ll x,ll y,ll z,ll r){
    return -(r-y-1)/z+(r-x)/z;
}
int main(){
    scanf("%s",str+1),n=strlen(str+1);
    for(ll i=1;i<=n;i++){
        s[i]=s[i-1]+(str[i]=='1');
    }
    for(ll i=0;i<=n;i++)l[i]=n+1;
    for(ll i=0;i<=n;i++){
        l[s[i]]=min(l[s[i]],(ll)i);
        r[s[i]]=max(r[s[i]],(ll)i);
    }
    siz=ceil(sqrt(s[n]));
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=min(s[i],siz);j++){
            ll res=s[i]-j;
            ans+=calc(l[res],r[res],j,i);
        }
    }
    for(ll x=1;x<=siz;x++){
        for(ll i=0;i<=n;i++)
            sta[i]=mp(x*s[i]-i,i);
        sort(sta,sta+1+n);
        for(ll i=0,j=0;i<=n;i=j){
            ll k=i-1;
            for(j=i;j<=n && sta[j].first==sta[i].first;j++){
                while(k<j && s[sta[j].second]-s[sta[k+1].second]>siz)++k;
                ans+=k-i+1;
            }
        }
    }
    printf("%lld\n",ans);
}


#include<bits/stdc++.h>
#define mp make_pair
using namespace std;
const int N=200020;
typedef long long ll;
ll n,s[N],l[N],r[N],siz,ans;
pair<ll,ll>sta[N];
char str[N];
int calc(int x,int y,int z,int r){
    return -(r-y-1)/z+(r-x)/z;
}
int main(){
    scanf("%s",str+1),n=strlen(str+1);
    for(int i=1;i<=n;i++){
        s[i]=s[i-1]+(str[i]=='1');
    }
    for(int i=0;i<=n;i++)l[i]=n+1;
    for(int i=0;i<=n;i++){
        l[s[i]]=min(l[s[i]],(ll)i);
        r[s[i]]=max(r[s[i]],(ll)i);
    }
    siz=ceil(sqrt(s[n]));
    for(int i=1;i<=n;i++){
        for(int j=1;j<=min(s[i],siz);j++){
            int res=s[i]-j;
            ans+=calc(l[res],r[res],j,i);
        }
    }
    for(int x=1;x<=siz;x++){
        for(int i=0;i<=n;i++)
            sta[i]=mp(x*s[i]-i,i);
        sort(sta,sta+1+n);
        for(int i=0,j=0;i<=n;i=j){
            int k=i-1;
            for(j=i;j<=n && sta[j].first==sta[i].first;j++){
                while(k<j && s[sta[j].second]-s[sta[k+1].second]>siz)++k;
                ans+=k-i+1;
            }
        }
    }
    printf("%lld\n",ans);
}


#include<bits/stdc++.h>
#define mp make_pair
using namespace std;
const int N=200020;
typedef long long ll;
ll n,s[N],l[N],r[N],siz,ans;
pair<ll,ll>sta[N];
char str[N];
ll calc(ll x,ll y,ll z,ll r){
    return -(r-y-1)/z+(r-x)/z;
}
int main(){
    scanf("%s",str+1),n=strlen(str+1);
    for(ll i=1;i<=n;i++){
        s[i]=s[i-1]+(str[i]=='1');
    }
    for(ll i=0;i<=n;i++)l[i]=n+1;
    for(ll i=0;i<=n;i++){
        l[s[i]]=min(l[s[i]],(ll)i);
        r[s[i]]=max(r[s[i]],(ll)i);
    }
    siz=ceil(sqrt(n));
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=min(s[i],siz);j++){
            ll res=s[i]-j;
            ans+=calc(l[res],r[res],j,i);
        }
    }
    for(ll x=1;x<=siz;x++){
        for(ll i=0;i<=n;i++)
            sta[i]=mp(x*s[i]-i,i);
        sort(sta,sta+1+n);
        for(ll i=0,j=0;i<=n;i=j){
            ll k=i-1;
            for(j=i;j<=n && sta[j].first==sta[i].first;j++){
                while(k<j && s[sta[j].second]-s[sta[k+1].second]>siz)++k;
                ans+=k-i+1;
            }
        }
    }
    printf("%lld\n",ans);
}


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

const int maxn = 200010;
int n, tp, st[maxn];
long long ans, a[maxn];
char s[maxn];

int main() {
    scanf("%s", s + 1);
    n = strlen(s + 1);
    int SZ = min(200, (int)sqrt(n));
    for (int i = 1; i <= SZ; i++) {
        a[0] = 0;
        for (int j = 1; j <= n; j++) {
            a[j] = a[j - 1] + 1 - (s[j] == '1' ? i : 0);
        }
        sort(a, a + n + 1);
        for (int j = 0, k; j <= n; j = k) {
            k = j;
            while (k <= n && a[j] == a[k]) k++;
            ans += 1LL * (k - j) * (k - j - 1) / 2;
        }
    }
    for (int i = 1; i <= n; i++) {
        if (s[i] == '1') st[++tp] = i;
        for (int j = 1; j <= SZ && j <= tp; j++) {
            int l = i - st[tp - j + 1] + 1, r = i - st[tp - j];
            l = max(l, j * (SZ + 1));
            if (l <= r) ans += r / j - (l - 1) / j;
        }
    }
    printf("%lld\n", ans);
    return 0;
}


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

const int maxn = 200010;
int n, tp, st[maxn];
long long ans, a[maxn];
char s[maxn];

int main() {
    scanf("%s", s + 1);
    n = strlen(s + 1);
    int SZ = sqrt(n);
    for (int i = 1; i <= SZ; i++) {
        a[0] = 0;
        for (int j = 1; j <= n; j++) {
            a[j] = a[j - 1] + 1 - (s[j] == '1' ? i : 0);
        }
        sort(a, a + n + 1);
        for (int j = 0, k; j <= n; j = k) {
            k = j;
            while (k <= n && a[j] == a[k]) k++;
            ans += 1LL * (k - j) * (k - j - 1) / 2;
        }
    }
    for (int i = 1; i <= n; i++) {
        if (s[i] == '1') st[++tp] = i;
        for (int j = 1; j <= SZ && j <= tp; j++) {
            int l = i - st[tp - j + 1] + 1, r = i - st[tp - j];
            l = max(l, j * (SZ + 1));
            if (l <= r) ans += r / j - (l - 1) / j;
        }
    }
    printf("%lld\n", ans);
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define rg register
#define In inline
#define ll long long

const int N = 2e5;
const int M = 450;

namespace IO{
	In ll read(){
		ll s = 0,ww = 1;
		char ch = getchar();
		while(ch < '0' || ch > '9'){if(ch == '-')ww = -1;ch = getchar();}
		while('0' <= ch && ch <= '9'){s = 10 * s + ch - '0';ch = getchar();}
		return s * ww;
	}
	In void write(ll x){
		if(x < 0)putchar('-'),x = -x;
		if(x > 9)write(x / 10);
		putchar('0' + x % 10);
	}
}
using namespace IO;

char st[N+5];
int a[N+5],s[N+5];
int num[M*N+N+5];
int S,n;

In int id(int i,int k){
	return N + k * s[i] - i;
}

int main(){
//	freopen("CF1270F.in","r",stdin);
//	freopen("CF1270F.out","w",stdout);
	scanf("%s",st + 1);
	n = strlen(st + 1);
	for(rg int i = 1;i <= n;i++){
		a[i] = st[i] - '0';
		s[i] = s[i-1] + a[i];
	}
	S = ceil(sqrt(n));
//cout<<S<<endl;
//clock_t sta = clock();
	ll ans = 0;
	for(rg int k = 1;k <= S;k++){
		for(rg int i = 0;i <= n;i++)ans += num[id(i,k)]++;
		for(rg int i = 0;i <= n;i++)num[id(i,k)]--;
	}
	a[n+1] = 2;
//clock_t T = clock();
//cout<<"part1: time="<<T-sta<<endl;
	for(rg int d = 1;d <= S;d++){
		int l = 1,r = 1;
		for(rg int i = 1;i <= n;i++){
			if(s[l] - s[i-1] != d){
				while(s[l] - s[i-1] < d && l <= n)l++;
				if(l == n + 1)break;
				r = l;
				while(a[r+1] == 0)r++;
			}

//cout << "l="<<l<<" r="<<r<<endl;

			if ((r - i + 1) / d > S) ans += (r - i + 1) / d - max((l - i) / d, S);
		/*	int l = 0;
			while (l < n && s[l+1] < d) ++l;
			if (l == n) continue;
			int r = l + 1;
			while (r < n && s[r+1] <= d) ++r;
			for (int i = 0; i < n; i++) {
				if (s[r] - s[i] < d) {
					if (r == n) break;
					l = r;
					while (r < n && s[r+1] - s[i] <= d) ++r;
				}
				if ((r - i) / d > S) ans += (r - i) / d - max((l - i) / d, S);
			}*/

		}
	}
//clock_t T2 = clock();
//cout<<"part2: time="<<T2-T<<endl;
	write(ans),putchar('\n');
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define rg register
#define In inline
#define ll long long

const int N = 2e5;
const int M = 450;

namespace IO{
	In ll read(){
		ll s = 0,ww = 1;
		char ch = getchar();
		while(ch < '0' || ch > '9'){if(ch == '-')ww = -1;ch = getchar();}
		while('0' <= ch && ch <= '9'){s = 10 * s + ch - '0';ch = getchar();}
		return s * ww;
	}
	In void write(ll x){
		if(x < 0)putchar('-'),x = -x;
		if(x > 9)write(x / 10);
		putchar('0' + x % 10);
	}
}
using namespace IO;

char st[N+5];
int a[N+5],s[N+5];
int num[M*N+5];
int S,n;

In int id(int i,int k){
	return N + k * s[i] - i;
}

int main(){
//	freopen("CF1270F.in","r",stdin);
//	freopen("CF1270F.out","w",stdout);
	scanf("%s",st + 1);
	n = strlen(st + 1);
	for(rg int i = 1;i <= n;i++){
		a[i] = st[i] - '0';
		s[i] = s[i-1] + a[i];
	}
	S = ceil(sqrt(n));
//cout<<S<<endl;
//clock_t sta = clock();
	ll ans = 0;
	for(rg int k = 1;k <= S;k++){
		for(rg int i = 0;i <= n;i++)ans += num[id(i,k)]++;
		for(rg int i = 0;i <= n;i++)num[id(i,k)]--;
	}
	a[n+1] = 2;
//clock_t T = clock();
//cout<<"part1: time="<<T-sta<<endl;
	for(rg int d = 1;d <= S;d++){
//cout<<"d="<<d<<endl;
		int l = 1,r = 1;
		for(rg int i = 1;i <= n;i++){
			while(s[l] - s[i-1] < d && l <= n)l++;
			if(l == n + 1)break;
			r = l;
			while(a[r+1] == 0)r++;
			int L = l - i + 1,R = r - i + 1;
			if(R < d * (S+1))continue;
			L = max(L,d * (S+1));
			L = ceil(1.0 * L / d);
			R = floor(1.0 * R / d);
			ans += max(R - L + 1,0);
		}
	}
//clock_t T2 = clock();
//cout<<"part 2: time="<<T2-T<<endl;
	write(ans),putchar('\n');
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<unordered_map>
using namespace std;
const int M=200;
int a[200010],n;
long long f[200010];
long long solve(int k)
{
	long long ans=0;
	unordered_map<long long,int>mp;
	for(int i=1;i<=n;i++)
	{
		mp[f[i-1]]++;
		if(a[i])f[i]=f[i-1]+k-1;
		else f[i]=f[i-1]-1;
		ans+=mp[f[i]];
	}
	return ans;
}
char str[200010];
int pos[200010];
int main()
{
	long long ans=0;
	scanf("%s",str+1);
	n=strlen(str+1);
	for(int i=1;i<=n;i++)
		a[i]=str[i]-'0';
	for(int i=1;i<=M;i++)
		ans+=solve(i);
	int cnt=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i]==1)pos[++cnt]=i;
		for(int j=1;j<=cnt;j++)
		{
			int k=cnt-j+1;
			int L=(i-pos[k])/j;
			int R=(i-pos[k-1])/j;
			ans+=max(0,R-max(L,M));
		}
	}
	printf("%I64d\n",ans);
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<map>
using namespace std;
const int M=250;
int a[200010],n;
long long f[200010];
long long solve(int k)
{
	long long ans=0;
	map<long long,int>mp;
	for(int i=1;i<=n;i++)
	{
		mp[f[i-1]]++;
		if(a[i])f[i]=f[i-1]+k-1;
		else f[i]=f[i-1]-1;
		ans+=mp[f[i]];
	}
	return ans;
}
char str[200010];
int pos[200010];
int main()
{
	long long ans=0;
	scanf("%s",str+1);
	n=strlen(str+1);
	for(int i=1;i<=n;i++)
		a[i]=str[i]-'0';
	for(int i=1;i<=M;i++)
		ans+=solve(i);
	int cnt=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i]==1)pos[++cnt]=i;
		for(int j=1;j<=cnt;j++)
		{
			if(j*M>n)break;
			int k=cnt-j+1;
			int L=(i-pos[k])/j;
			int R=(i-pos[k-1])/j;
			ans+=max(0,R-max(L,M));
		}
	}
	printf("%I64d\n",ans);
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<unordered_map>
using namespace std;
const int M=400;
int a[200010],n;
long long f[200010];
long long solve(int k)
{
	long long ans=0;
	unordered_map<long long,int>mp;
	for(int i=1;i<=n;i++)
	{
		mp[f[i-1]]++;
		if(a[i])f[i]=f[i-1]+k-1;
		else f[i]=f[i-1]-1;
		ans+=mp[f[i]];
	}
	return ans;
}
char str[200010];
int pos[200010];
int main()
{
	long long ans=0;
	scanf("%s",str+1);
	n=strlen(str+1);
	for(int i=1;i<=n;i++)
		a[i]=str[i]-'0';
	for(int i=1;i<=M;i++)
		ans+=solve(i);
	int cnt=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i]==1)pos[++cnt]=i;
		for(int j=1;j<=cnt;j++)
		{
			if(j*M>n)break;
			int k=cnt-j+1;
			int L=(i-pos[k])/j;
			int R=(i-pos[k-1])/j;
			ans+=max(0,R-max(L,M));
		}
	}
	printf("%I64d\n",ans);
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<unordered_map>
using namespace std;
const int M=200;
int a[200010],n;
long long f[200010];
long long solve(int k)
{
	long long ans=0;
	unordered_map<long long,int>mp;
	for(int i=1;i<=n;i++)
	{
		mp[f[i-1]]++;
		if(a[i])f[i]=f[i-1]+k-1;
		else f[i]=f[i-1]-1;
		ans+=mp[f[i]];
	}
	return ans;
}
char str[200010];
int pos[200010];
int main()
{
	long long ans=0;
	scanf("%s",str+1);
	n=strlen(str+1);
	for(int i=1;i<=n;i++)
		a[i]=str[i]-'0';
	for(int i=1;i<=M;i++)
		ans+=solve(i);
	int cnt=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i]==1)pos[++cnt]=i;
		for(int j=1;j<=cnt;j++)
		{
			if(j*M>n)break;
			int k=cnt-j+1;
			int L=(i-pos[k])/j;
			int R=(i-pos[k-1])/j;
			ans+=max(0,R-max(L,M));
		}
	}
	printf("%I64d\n",ans);
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
const int M=300;
int a[200010],n;
long long f[200010];
int num[60000010];
long long solve(int k)
{
	long long ans=0;
	for(int i=1;i<=n;i++)
	{
		num[f[i-1]+n]++;
		if(a[i])f[i]=f[i-1]+k-1;
		else f[i]=f[i-1]-1;
		ans+=num[f[i]+n];
	}
	for(int i=0;i<n;i++)
		num[f[i]+n]--;
	return ans;
}
char str[200010];
int pos[200010];
int main()
{
	long long ans=0;
	scanf("%s",str+1);
	n=strlen(str+1);
	for(int i=1;i<=n;i++)
		a[i]=str[i]-'0';
	for(int i=1;i<=M;i++)
		ans+=solve(i);
	int cnt=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i]==1)pos[++cnt]=i;
		for(int j=1;j<=cnt;j++)
		{
			if(j*M>n)break;
			int k=cnt-j+1;
			int L=(i-pos[k])/j;
			int R=(i-pos[k-1])/j;
			ans+=max(0,R-max(L,M));
		}
	}
	printf("%I64d\n",ans);
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<map>
using namespace std;
const int M=200;
int a[200010],n;
long long f[200010];
long long solve(int k)
{
	long long ans=0;
	map<long long,int>mp;
	for(int i=1;i<=n;i++)
	{
		mp[f[i-1]]++;
		if(a[i])f[i]=f[i-1]+k-1;
		else f[i]=f[i-1]-1;
		ans+=mp[f[i]];
	}
	return ans;
}
char str[200010];
int pos[200010];
int main()
{
	long long ans=0;
	scanf("%s",str+1);
	n=strlen(str+1);
	for(int i=1;i<=n;i++)
		a[i]=str[i]-'0';
	for(int i=1;i<=M;i++)
		ans+=solve(i);
	int cnt=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i]==1)pos[++cnt]=i;
		for(int j=1;j<=cnt;j++)
		{
			int k=cnt-j+1;
			int L=(i-pos[k])/j;
			int R=(i-pos[k-1])/j;
			ans+=max(0,R-max(L,M));
		}
	}
	printf("%I64d\n",ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> PII;
typedef pair<ll,int> Pli;
typedef pair<ll,ll> Pll;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef pair<ll,ll>P;
#define N  1000000+10
#define M  1000000+10
#define INF 1e9
#define fi first
#define se second
#define MP make_pair
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define per(i,a,b) for(int i=(int)a;i>=(int)b;i--)
#define lowbit(x) x&(-x)
#define Rand (rand()*(1<<16)+rand())
#define id(x) ((x)<=B?(x):m-n/(x)+1)
#define ls p<<1
#define rs p<<1|1
#define fors(i) for(auto i:e[x]) if(i!=p)

const ll MOD=998244353,inv2=(MOD+1)/2;
      int p=1e7+19;
      long double eps=1e-6;
      int dx[4]={-1,1,0,0};
      int dy[4]={0,0,-1,1};
      long double pi=acos(-1.0L);

char ch[N];
map<ll,int> mp;
int f[N];
int a[N],c[N],pre[N],s[N],n;

int read()
{
   int v=0,f=1;
   char c=getchar();
   while(c<48||57<c) {if(c=='-') f=-1; c=getchar();}
   while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar();
   return v*f;
}

ll readll()
{
   ll v=0,f=1;
   char c=getchar();
   while(c<48||57<c) {if(c=='-') f=-1; c=getchar();}
   while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar();
   return v*f;
}

void init()
{
    scanf("%s",ch+1);
    n=strlen(ch+1);
    rep(i,1,n) a[i]=ch[i]-'0';
    s[0]=0;
    rep(i,1,n) s[i]=s[i-1]+a[i];
}

ll calc(int k)
{
    ll res=0;
    mp[0]=1;
    rep(i,1,n)
    {
        ll x=1ll*k*s[i]-i;
        //int t=(x%p+p)%p;
        res+=mp[x];
        mp[x]++;
    }
    rep(i,1,n)
    {
        ll x=1ll*k*s[i]-i;
        //int t=(x%p+p)%p;
        mp[x]=0;
    }
    return res;
}

void solve()
{
    int T=150;
    ll ans=0;
    rep(i,1,T) ans+=calc(i);
    pre[0]=-1;
    rep(i,1,n)
    {
        pre[i]=pre[i-1];
        if(s[i-1]!=s[i]) pre[i]=i-1;
    }
    rep(i,1,n) c[i]=i;

    rep(i,0,n/T)
    {
        int x,y;
        rep(j,1,n) f[j]=0;
        if(i)
        {
            rep(j,T+1,n)
            {
                if(i*j>n) break;
                f[i*j]++;
            }
        }

        rep(j,1,n) f[j]=f[j-1]+f[j];
        rep(j,1,n)
        {
            if(i>s[j]) continue;
            y=c[j],x=pre[y]+1;
            x=j-x,y=j-y;
            swap(x,y);
            ans+=f[y]-f[x-1];
        }
        rep(j,1,n)
         if(c[j]!=-1) c[j]=pre[c[j]];
    }
    printf("%I64d\n",ans);
}

int main()
{
    //freopen("1.in","r",stdin);
    //freopen("1.out","w",stdout);
    init();
    solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> PII;
typedef pair<ll,int> Pli;
typedef pair<ll,ll> Pll;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef pair<ll,ll>P;
#define N  1000000+10
#define M  1000000+10
#define INF 1e9
#define fi first
#define se second
#define MP make_pair
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define per(i,a,b) for(int i=(int)a;i>=(int)b;i--)
#define lowbit(x) x&(-x)
#define Rand (rand()*(1<<16)+rand())
#define id(x) ((x)<=B?(x):m-n/(x)+1)
#define ls p<<1
#define rs p<<1|1
#define fors(i) for(auto i:e[x]) if(i!=p)

const ll MOD=998244353,inv2=(MOD+1)/2;
      int p=1e7+19;
      long double eps=1e-6;
      int dx[4]={-1,1,0,0};
      int dy[4]={0,0,-1,1};
      long double pi=acos(-1.0L);

char ch[N];
map<ll,int> mp;
int f[N];
int a[N],c[N],pre[N],s[N],n;

int read()
{
   int v=0,f=1;
   char c=getchar();
   while(c<48||57<c) {if(c=='-') f=-1; c=getchar();}
   while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar();
   return v*f;
}

ll readll()
{
   ll v=0,f=1;
   char c=getchar();
   while(c<48||57<c) {if(c=='-') f=-1; c=getchar();}
   while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar();
   return v*f;
}

void init()
{
    scanf("%s",ch+1);
    n=strlen(ch+1);
    rep(i,1,n) a[i]=ch[i]-'0';
    s[0]=0;
    rep(i,1,n) s[i]=s[i-1]+a[i];
}

ll calc(int k)
{
    ll res=0;
    mp[0]=1;
    rep(i,1,n)
    {
        ll x=1ll*k*s[i]-i;
        //int t=(x%p+p)%p;
        res+=mp[x];
        mp[x]++;
    }
    rep(i,1,n)
    {
        ll x=1ll*k*s[i]-i;
        //int t=(x%p+p)%p;
        mp[x]=0;
    }
    return res;
}

void solve()
{
    int T=100;
    ll ans=0;
    rep(i,1,T) ans+=calc(i);
    pre[0]=-1;
    rep(i,1,n)
    {
        pre[i]=pre[i-1];
        if(s[i-1]!=s[i]) pre[i]=i-1;
    }
    rep(i,1,n) c[i]=i;

    rep(i,0,n/T)
    {
        int x,y;
        rep(j,1,n) f[j]=0;
        if(i)
        {
            rep(j,T+1,n)
            {
                if(i*j>n) break;
                f[i*j]++;
            }
        }

        rep(j,1,n) f[j]=f[j-1]+f[j];
        rep(j,1,n)
        {
            if(i>s[j]) continue;
            y=c[j],x=pre[y]+1;
            x=j-x,y=j-y;
            swap(x,y);
            ans+=f[y]-f[x-1];
        }
        rep(j,1,n) c[j]=pre[c[j]];
    }
    printf("%I64d\n",ans);
}

int main()
{
    //freopen("1.in","r",stdin);
    //freopen("1.out","w",stdout);
    init();
    solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> PII;
typedef pair<ll,int> Pli;
typedef pair<ll,ll> Pll;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef pair<ll,ll>P;
#define N  1000000+10
#define M  1000000+10
#define INF 1e9
#define fi first
#define se second
#define MP make_pair
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define per(i,a,b) for(int i=(int)a;i>=(int)b;i--)
#define lowbit(x) x&(-x)
#define Rand (rand()*(1<<16)+rand())
#define id(x) ((x)<=B?(x):m-n/(x)+1)
#define ls p<<1
#define rs p<<1|1
#define fors(i) for(auto i:e[x]) if(i!=p)

const ll MOD=998244353,inv2=(MOD+1)/2;
      int p=1e7+19;
      long double eps=1e-6;
      int dx[4]={-1,1,0,0};
      int dy[4]={0,0,-1,1};
      long double pi=acos(-1.0L);

char ch[N];
map<ll,int> mp;
int f[N];
int a[N],c[N],pre[N],s[N],n;

int read()
{
   int v=0,f=1;
   char c=getchar();
   while(c<48||57<c) {if(c=='-') f=-1; c=getchar();}
   while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar();
   return v*f;
}

ll readll()
{
   ll v=0,f=1;
   char c=getchar();
   while(c<48||57<c) {if(c=='-') f=-1; c=getchar();}
   while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar();
   return v*f;
}

void init()
{
    scanf("%s",ch+1);
    n=strlen(ch+1);
    rep(i,1,n) a[i]=ch[i]-'0';
    s[0]=0;
    rep(i,1,n) s[i]=s[i-1]+a[i];
}

ll calc(int k)
{
    ll res=0;
    mp[0]=1;
    rep(i,1,n)
    {
        ll x=1ll*k*s[i]-i;
        //int t=(x%p+p)%p;
        res+=mp[x];
        mp[x]++;
    }
    rep(i,1,n)
    {
        ll x=1ll*k*s[i]-i;
        //int t=(x%p+p)%p;
        mp[x]=0;
    }
    return res;
}

void solve()
{
    int T=200;
    ll ans=0;
    rep(i,1,T) ans+=calc(i);
    pre[0]=-1;
    rep(i,1,n)
    {
        pre[i]=pre[i-1];
        if(s[i-1]!=s[i]) pre[i]=i-1;
    }
    rep(i,1,n) c[i]=i;

    rep(i,0,n/T)
    {
        int x,y;
        rep(j,1,n) f[j]=0;
        if(i)
        {
            rep(j,T+1,n)
            {
                if(i*j>n) break;
                f[i*j]++;
            }
        }

        rep(j,1,n) f[j]=f[j-1]+f[j];
        rep(j,1,n)
        {
            if(i>s[j]) continue;
            y=c[j],x=pre[y]+1;
            x=j-x,y=j-y;
            swap(x,y);
            ans+=f[y]-f[x-1];
        }
        rep(j,1,n) c[j]=pre[c[j]];
    }
    printf("%I64d\n",ans);
}

int main()
{
    //freopen("1.in","r",stdin);
    //freopen("1.out","w",stdout);
    init();
    solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> PII;
typedef pair<ll,int> Pli;
typedef pair<ll,ll> Pll;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef pair<ll,ll>P;
#define N  1000000+10
#define M  1000000+10
#define INF 1e9
#define fi first
#define se second
#define MP make_pair
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define per(i,a,b) for(int i=(int)a;i>=(int)b;i--)
#define lowbit(x) x&(-x)
#define Rand (rand()*(1<<16)+rand())
#define id(x) ((x)<=B?(x):m-n/(x)+1)
#define ls p<<1
#define rs p<<1|1
#define fors(i) for(auto i:e[x]) if(i!=p)

const ll MOD=998244353,inv2=(MOD+1)/2;
      int p=1e7+19;
      long double eps=1e-6;
      int dx[4]={-1,1,0,0};
      int dy[4]={0,0,-1,1};
      long double pi=acos(-1.0L);

char ch[N];
map<ll,int> mp;
int f[N];
int a[N],c[N],pre[N],s[N],n;

int read()
{
   int v=0,f=1;
   char c=getchar();
   while(c<48||57<c) {if(c=='-') f=-1; c=getchar();}
   while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar();
   return v*f;
}

ll readll()
{
   ll v=0,f=1;
   char c=getchar();
   while(c<48||57<c) {if(c=='-') f=-1; c=getchar();}
   while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar();
   return v*f;
}

void init()
{
    scanf("%s",ch+1);
    n=strlen(ch+1);
    rep(i,1,n) a[i]=ch[i]-'0';
    s[0]=0;
    rep(i,1,n) s[i]=s[i-1]+a[i];
}

ll calc(int k)
{
    ll res=0;
    mp[0]=1;
    rep(i,1,n)
    {
        ll x=1ll*k*s[i]-i;
        //int t=(x%p+p)%p;
        res+=mp[x];
        mp[x]++;
    }
    rep(i,1,n)
    {
        ll x=1ll*k*s[i]-i;
        //int t=(x%p+p)%p;
        mp[x]=0;
    }
    return res;
}

void solve()
{
    int T=300;
    ll ans=0;
    rep(i,1,T) ans+=calc(i);
    pre[0]=-1;
    rep(i,1,n)
    {
        pre[i]=pre[i-1];
        if(s[i-1]!=s[i]) pre[i]=i-1;
    }
    rep(i,1,n) c[i]=i;

    rep(i,0,n/T)
    {
        int x,y;
        rep(j,1,n) f[j]=0;
        if(i)
        {
            rep(j,T+1,n)
            {
                if(i*j>n) break;
                f[i*j]++;
            }
        }

        rep(j,1,n) f[j]=f[j-1]+f[j];
        rep(j,1,n)
        {
            if(i>s[j]) continue;
            y=c[j],x=pre[y]+1;
            x=j-x,y=j-y;
            swap(x,y);
            ans+=f[y]-f[x-1];
        }
        rep(j,1,n) c[j]=pre[c[j]];
    }
    printf("%I64d\n",ans);
}

int main()
{
    //freopen("1.in","r",stdin);
    //freopen("1.out","w",stdout);
    init();
    solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> PII;
typedef pair<ll,int> Pli;
typedef pair<ll,ll> Pll;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef pair<ll,ll>P;
#define N  1000000+10
#define M  1000000+10
#define INF 1e9
#define fi first
#define se second
#define MP make_pair
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define per(i,a,b) for(int i=(int)a;i>=(int)b;i--)
#define lowbit(x) x&(-x)
#define Rand (rand()*(1<<16)+rand())
#define id(x) ((x)<=B?(x):m-n/(x)+1)
#define ls p<<1
#define rs p<<1|1
#define fors(i) for(auto i:e[x]) if(i!=p)

const ll MOD=998244353,inv2=(MOD+1)/2;
      int p1=1e7+19;
      long double eps=1e-6;
      int dx[4]={-1,1,0,0};
      int dy[4]={0,0,-1,1};
      long double pi=acos(-1.0L);

char ch[N];
int mp[66666666];
int f[N];
int a[N],c[N],pre[N],s[N],n;

int read()
{
   int v=0,f=1;
   char c=getchar();
   while(c<48||57<c) {if(c=='-') f=-1; c=getchar();}
   while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar();
   return v*f;
}

ll readll()
{
   ll v=0,f=1;
   char c=getchar();
   while(c<48||57<c) {if(c=='-') f=-1; c=getchar();}
   while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar();
   return v*f;
}

void init()
{
    scanf("%s",ch+1);
    n=strlen(ch+1);
    rep(i,1,n) a[i]=ch[i]-'0';
    s[0]=0;
    rep(i,1,n) s[i]=s[i-1]+a[i];
}

ll calc(int k)
{
    ll res=0;
    mp[0]=1;
    rep(i,1,n)
    {
        int x=k*s[i]-i;
        res+=mp[x];
        mp[x]++;
    }
    rep(i,1,n)
    {
        int x=1ll*k*s[i]-i;
        mp[x]=0;
    }
    return res;
}

void solve()
{
    int T=300;
    ll ans=0;
    rep(i,1,T) ans+=calc(i);
    pre[0]=-1;
    rep(i,1,n)
    {
        pre[i]=pre[i-1];
        if(s[i-1]!=s[i]) pre[i]=i-1;
    }
    rep(i,1,n) c[i]=i;

    rep(i,0,n/T)
    {
        int x,y;
        rep(j,1,n) f[j]=0;
        if(i)
        {
            rep(j,T+1,n)
            {
                if(i*j>n) break;
                f[i*j]++;
            }
        }

        rep(j,1,n) f[j]=f[j-1]+f[j];
        rep(j,1,n)
        {
            if(i>s[j]) continue;
            y=c[j],x=pre[y]+1;
            x=j-x,y=j-y;
            swap(x,y);
            if(x>y) continue;
            ans+=f[y]-f[x-1];
        }
        rep(j,1,n)
         if(c[j]!=-1) c[j]=pre[c[j]];
    }
    printf("%I64d\n",ans);
}

int main()
{
    //freopen("1.in","r",stdin);
    //freopen("1.out","w",stdout);
    init();
    solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> PII;
typedef pair<ll,int> Pli;
typedef pair<ll,ll> Pll;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef pair<ll,ll>P;
#define N  1000000+10
#define M  1000000+10
#define INF 1e9
#define fi first
#define se second
#define MP make_pair
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define per(i,a,b) for(int i=(int)a;i>=(int)b;i--)
#define lowbit(x) x&(-x)
#define Rand (rand()*(1<<16)+rand())
#define id(x) ((x)<=B?(x):m-n/(x)+1)
#define ls p<<1
#define rs p<<1|1
#define fors(i) for(auto i:e[x]) if(i!=p)

const ll MOD=998244353,inv2=(MOD+1)/2;
      int p=1e7+19;
      long double eps=1e-6;
      int dx[4]={-1,1,0,0};
      int dy[4]={0,0,-1,1};
      long double pi=acos(-1.0L);

char ch[N];
map<ll,int> mp;
int f[N];
int a[N],c[N],pre[N],s[N],n;

int read()
{
   int v=0,f=1;
   char c=getchar();
   while(c<48||57<c) {if(c=='-') f=-1; c=getchar();}
   while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar();
   return v*f;
}

ll readll()
{
   ll v=0,f=1;
   char c=getchar();
   while(c<48||57<c) {if(c=='-') f=-1; c=getchar();}
   while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar();
   return v*f;
}

void init()
{
    scanf("%s",ch+1);
    n=strlen(ch+1);
    rep(i,1,n) a[i]=ch[i]-'0';
    s[0]=0;
    rep(i,1,n) s[i]=s[i-1]+a[i];
}

ll calc(int k)
{
    ll res=0;
    mp[0]=1;
    rep(i,1,n)
    {
        ll x=1ll*k*s[i]-i;
        //int t=(x%p+p)%p;
        res+=mp[x];
        mp[x]++;
    }
    rep(i,1,n)
    {
        ll x=1ll*k*s[i]-i;
        //int t=(x%p+p)%p;
        mp[x]=0;
    }
    return res;
}

void solve()
{
    int T=150;
    ll ans=0;
    rep(i,1,T) ans+=calc(i);
    pre[0]=-1;
    rep(i,1,n)
    {
        pre[i]=pre[i-1];
        if(s[i-1]!=s[i]) pre[i]=i-1;
    }
    rep(i,1,n) c[i]=i;

    rep(i,0,n/T)
    {
        int x,y;
        rep(j,1,n) f[j]=0;
        if(i)
        {
            rep(j,T+1,n)
            {
                if(i*j>n) break;
                f[i*j]++;
            }
        }

        rep(j,1,n) f[j]=f[j-1]+f[j];
        rep(j,1,n)
        {
            if(i>s[j]) continue;
            y=c[j],x=pre[y]+1;
            x=j-x,y=j-y;
            swap(x,y);
            if(x>y) continue;
            ans+=f[y]-f[x-1];
        }
        rep(j,1,n)
         if(c[j]!=-1) c[j]=pre[c[j]];
    }
    printf("%I64d\n",ans);
}

int main()
{
    //freopen("1.in","r",stdin);
    //freopen("1.out","w",stdout);
    init();
    solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> PII;
typedef pair<ll,int> Pli;
typedef pair<ll,ll> Pll;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef pair<ll,ll>P;
#define N  1000000+10
#define M  1000000+10
#define INF 1e9
#define fi first
#define se second
#define MP make_pair
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define per(i,a,b) for(int i=(int)a;i>=(int)b;i--)
#define lowbit(x) x&(-x)
#define Rand (rand()*(1<<16)+rand())
#define id(x) ((x)<=B?(x):m-n/(x)+1)
#define ls p<<1
#define rs p<<1|1
#define fors(i) for(auto i:e[x]) if(i!=p)

const ll MOD=998244353,inv2=(MOD+1)/2;
      int p=1e7+19;
      long double eps=1e-6;
      int dx[4]={-1,1,0,0};
      int dy[4]={0,0,-1,1};
      long double pi=acos(-1.0L);

char ch[N];
map<ll,int> mp;
int f[N];
int a[N],c[N],pre[N],s[N],n;

int read()
{
   int v=0,f=1;
   char c=getchar();
   while(c<48||57<c) {if(c=='-') f=-1; c=getchar();}
   while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar();
   return v*f;
}

ll readll()
{
   ll v=0,f=1;
   char c=getchar();
   while(c<48||57<c) {if(c=='-') f=-1; c=getchar();}
   while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar();
   return v*f;
}

void init()
{
    scanf("%s",ch+1);
    n=strlen(ch+1);
    rep(i,1,n) a[i]=ch[i]-'0';
    s[0]=0;
    rep(i,1,n) s[i]=s[i-1]+a[i];
}

ll calc(int k)
{
    ll res=0;
    mp[0]=1;
    rep(i,1,n)
    {
        ll x=1ll*k*s[i]-i;
        //int t=(x%p+p)%p;
        res+=mp[x];
        mp[x]++;
    }
    rep(i,1,n)
    {
        ll x=1ll*k*s[i]-i;
        //int t=(x%p+p)%p;
        mp[x]=0;
    }
    return res;
}

void solve()
{
    int T=300;
    ll ans=0;
    rep(i,1,T) ans+=calc(i);
    pre[0]=-1;
    rep(i,1,n)
    {
        pre[i]=pre[i-1];
        if(s[i-1]!=s[i]) pre[i]=i-1;
    }
    rep(i,1,n) c[i]=i;

    rep(i,0,n/T)
    {
        int x,y;
        rep(j,1,n) f[j]=0;
        if(i)
        {
            rep(j,T+1,n)
            {
                if(i*j>n) break;
                f[i*j]++;
            }
        }

        rep(j,1,n) f[j]=f[j-1]+f[j];
        rep(j,1,n)
        {
            if(i>s[j]) continue;
            y=c[j],x=pre[y]+1;
            x=j-x,y=j-y;
            swap(x,y);
            if(x>y) continue;
            ans+=f[y]-f[x-1];
        }
        rep(j,1,n)
         if(c[j]!=-1) c[j]=pre[c[j]];
    }
    printf("%I64d\n",ans);
}

int main()
{
    //freopen("1.in","r",stdin);
    //freopen("1.out","w",stdout);
    init();
    solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> PII;
typedef pair<ll,int> Pli;
typedef pair<ll,ll> Pll;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef pair<ll,ll>P;
#define N  1000000+10
#define M  1000000+10
#define INF 1e9
#define fi first
#define se second
#define MP make_pair
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define per(i,a,b) for(int i=(int)a;i>=(int)b;i--)
#define lowbit(x) x&(-x)
#define Rand (rand()*(1<<16)+rand())
#define id(x) ((x)<=B?(x):m-n/(x)+1)
#define ls p<<1
#define rs p<<1|1
#define fors(i) for(auto i:e[x]) if(i!=p)

const ll MOD=998244353,inv2=(MOD+1)/2;
      int p=1e7+19;
      long double eps=1e-6;
      int dx[4]={-1,1,0,0};
      int dy[4]={0,0,-1,1};
      long double pi=acos(-1.0L);

char ch[N];
ll t;
int f[N],mp[20000000];
int a[N],c[N],pre[N],s[N],n;

int read()
{
   int v=0,f=1;
   char c=getchar();
   while(c<48||57<c) {if(c=='-') f=-1; c=getchar();}
   while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar();
   return v*f;
}

ll readll()
{
   ll v=0,f=1;
   char c=getchar();
   while(c<48||57<c) {if(c=='-') f=-1; c=getchar();}
   while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar();
   return v*f;
}

void init()
{
    scanf("%s",ch+1);
    n=strlen(ch+1);
    rep(i,1,n) a[i]=ch[i]-'0';
    s[0]=0;
    rep(i,1,n) s[i]=s[i-1]+a[i];
}

ll calc(int k)
{
    ll res=0;
    mp[0]=1;
    rep(i,1,n)
    {
        ll x=1ll*k*s[i]-i;
        int t=(x%p+p)%p;
        res+=mp[t];
        mp[t]++;
    }
    rep(i,1,n)
    {
        ll x=1ll*k*s[i]-i;
        int t=(x%p+p)%p;
        mp[t]=0;
    }
    return res;
}

void solve()
{
    int T=300;
    ll ans=0;
    rep(i,1,T) ans+=calc(i);
    pre[0]=-1;
    rep(i,1,n)
    {
        pre[i]=pre[i-1];
        if(s[i-1]!=s[i]) pre[i]=i-1;
    }
    rep(i,1,n) c[i]=i;

    rep(i,0,n/T)
    {
        int x,y;
        rep(j,1,n) f[j]=0;
        if(i)
        {
            rep(j,T+1,n)
            {
                if(i*j>n) break;
                f[i*j]++;
            }
        }

        rep(j,1,n) f[j]=f[j-1]+f[j];
        rep(j,1,n)
        {
            if(i>s[j]) continue;
            y=c[j],x=pre[y]+1;
            x=j-x,y=j-y;
            swap(x,y);
            ans+=f[y]-f[x-1];
        }
        rep(j,1,n) c[j]=pre[c[j]];
    }
    printf("%I64d\n",ans);
}

int main()
{
    //freopen("1.in","r",stdin);
    //freopen("1.out","w",stdout);
    init();
    solve();
    return 0;
}


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

#define pb push_back
#define mk make_pair
#define lob lower_bound
#define upb upper_bound
#define fst first
#define scd second

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;

namespace Fread{
	const int MAXN=1<<20;
	char buffer[MAXN],*S,*T;
	inline char getchar(){
		if(S==T){
			T=(S=buffer)+fread(buffer,1,MAXN,stdin);
			if(S==T) return EOF;
		}
		return *S++;
	}
}
#ifdef ONLINE_JUDGE
	#define getchar Fread::getchar
#endif
inline int read(){
	int f=1,x=0;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
inline ll readll(){
	ll f=1,x=0;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int MAXN=2e5+5,B=200;
char s[MAXN];
int n,pre[MAXN],nxt[MAXN];
int main() {
	scanf("%s",s+1);n=strlen(s+1);
	for(int i=1;i<=n;++i)pre[i]=pre[i-1]+(s[i]=='1');
	ll ans=0;
	for(int k=1;k<=B;++k){
		map<int,int>mp;mp[0]=1;
		for(int i=1;i<=n;++i)mp[i-pre[i]*k]++;
		for(map<int,int>::iterator it=mp.begin();it!=mp.end();++it)ans+=(ll)(it->scd)*(it->scd-1)/2;
	}
	int lim=n/(B+1);
	if(!lim){
		cout<<ans<<endl;return 0;
	}
	for(int i=n,pos=n+1;i>=1;--i){
		nxt[i]=pos;
		if(s[i]=='1')pos=i;
	}
	for(int i=1;i<=n;++i){
		if(s[i]=='1'){
			int cur=i;
			int len=B+1;
			if(i+len-1>n)continue;
			if(i+len-1<nxt[i])ans+=(nxt[i]-1)-(i+len-1)+1;
			for(int j=2;j<=lim;++j){
				if(nxt[cur]==n+1)break;
				cur=nxt[cur];
				int len=(B+1)*j;
				if(i+len-1>n)break;
				if(i+len-1<nxt[cur])ans+=((nxt[cur]-1)-(i+len-1))/j+1;
			}
		}else{
			int cur=i;
			for(int j=1;j<=lim;++j){
				if(nxt[cur]==n+1)break;
				cur=nxt[cur];
				int len=(B+1)*j;
				if(i+len-1>n)break;
				if(i+len-1<nxt[cur])ans+=((nxt[cur]-1)-(i+len-1))/j+1;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

#define pb push_back
#define mk make_pair
#define lob lower_bound
#define upb upper_bound
#define fst first
#define scd second

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;

namespace Fread{
	const int MAXN=1<<20;
	char buffer[MAXN],*S,*T;
	inline char getchar(){
		if(S==T){
			T=(S=buffer)+fread(buffer,1,MAXN,stdin);
			if(S==T) return EOF;
		}
		return *S++;
	}
}
#ifdef ONLINE_JUDGE
	#define getchar Fread::getchar
#endif
inline int read(){
	int f=1,x=0;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
inline ll readll(){
	ll f=1,x=0;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int MAXN=2e5+5,B=200;
char s[MAXN];
int n,pre[MAXN],nxt[MAXN];
int main() {
	scanf("%s",s+1);n=strlen(s+1);
	for(int i=1;i<=n;++i)pre[i]=pre[i-1]+(s[i]=='1');
	ll ans=0;
	for(int k=1;k<=B;++k){
		map<int,int>mp;mp[0]=1;
		for(int i=1;i<=n;++i)mp[i-pre[i]*k]++;
		for(map<int,int>::iterator it=mp.begin();it!=mp.end();++it)ans+=(ll)(it->scd)*(it->scd-1)/2;
	}
	for(int i=n,pos=n+1;i>=1;--i){
		nxt[i]=pos;
		if(s[i]=='1')pos=i;
	}
	for(int i=1;i<=n;++i){
		if(s[i]=='1'){
			int cur=i;
			int len=B+1;
			if(i+len-1>n)continue;
			if(i+len-1<nxt[i])ans+=(nxt[i]-1)-(i+len-1)+1;
			for(int j=2;;++j){
				if(nxt[cur]==n+1)break;
				cur=nxt[cur];
				int len=(B+1)*j;
				if(i+len-1>n)break;
				if(i+len-1<cur)ans+=(nxt[cur]-i)/j-(cur-i)/j;
				else if(i+len-1<nxt[cur])ans+=((nxt[cur]-1)-(i+len-1))/j+1;
			}
		}else{
			int cur=i;
			for(int j=1;;++j){
				if(nxt[cur]==n+1)break;
				cur=nxt[cur];
				int len=(B+1)*j;
				if(i+len-1>n)break;
				if(i+len-1<cur)ans+=(nxt[cur]-i)/j-(cur-i)/j;
				else if(i+len-1<nxt[cur])ans+=((nxt[cur]-1)-(i+len-1))/j+1;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

#define pb push_back
#define mk make_pair
#define lob lower_bound
#define upb upper_bound
#define fst first
#define scd second

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;

namespace Fread{
	const int MAXN=1<<20;
	char buffer[MAXN],*S,*T;
	inline char getchar(){
		if(S==T){
			T=(S=buffer)+fread(buffer,1,MAXN,stdin);
			if(S==T) return EOF;
		}
		return *S++;
	}
}
#ifdef ONLINE_JUDGE
	#define getchar Fread::getchar
#endif
inline int read(){
	int f=1,x=0;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
inline ll readll(){
	ll f=1,x=0;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int MAXN=2e5+5,B=200;
char s[MAXN];
int n,pre[MAXN],nxt[MAXN];
int main() {
	scanf("%s",s+1);n=strlen(s+1);
	for(int i=1;i<=n;++i)pre[i]=pre[i-1]+(s[i]=='1');
	ll ans=0;
	for(int k=1;k<=B;++k){
		map<int,int>mp;mp[0]=1;
		for(int i=1;i<=n;++i)mp[i-pre[i]*k]++;
		for(map<int,int>::iterator it=mp.begin();it!=mp.end();++it)ans+=(ll)(it->scd)*(it->scd-1)/2;
	}
	for(int i=n,pos=n+1;i>=1;--i){
		nxt[i]=pos;
		if(s[i]=='1')pos=i;
	}
	for(int i=1;i<=n;++i){
		if(s[i]=='1'){
			int cur=i;
			int len=B+1;
			if(i+len-1>n)continue;
			if(i+len-1<nxt[i])ans+=(nxt[i]-1)-(i+len-1)+1;
			for(int j=2;;++j){
				if(nxt[cur]==n+1)break;
				cur=nxt[cur];
				int len=(B+1)*j;
				if(i+len-1>n)break;
				if(i+len-1<cur)continue;
				if(i+len-1<nxt[cur])ans+=((nxt[cur]-1)-max(cur,i+len-1))/j+1;
			}
		}else{
			int cur=i;
			for(int j=1;;++j){
				if(nxt[cur]==n+1)break;
				cur=nxt[cur];
				int len=(B+1)*j;
				if(i+len-1>n)break;
				if(i+len-1<nxt[cur])ans+=((nxt[cur]-1)-max(cur,i+len-1))/j+1;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

#define pb push_back
#define mk make_pair
#define lob lower_bound
#define upb upper_bound
#define fst first
#define scd second

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;

namespace Fread{
	const int MAXN=1<<20;
	char buffer[MAXN],*S,*T;
	inline char getchar(){
		if(S==T){
			T=(S=buffer)+fread(buffer,1,MAXN,stdin);
			if(S==T) return EOF;
		}
		return *S++;
	}
}
#ifdef ONLINE_JUDGE
	#define getchar Fread::getchar
#endif
inline int read(){
	int f=1,x=0;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
inline ll readll(){
	ll f=1,x=0;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int MAXN=2e5+5,B=200;
char s[MAXN];
int n,pre[MAXN],nxt[MAXN];
int main() {
	scanf("%s",s+1);n=strlen(s+1);
	for(int i=1;i<=n;++i)pre[i]=pre[i-1]+(s[i]=='1');
	ll ans=0;
	for(int k=1;k<=B;++k){
		map<int,int>mp;mp[0]=1;
		for(int i=1;i<=n;++i)mp[i-pre[i]*k]++;
		for(map<int,int>::iterator it=mp.begin();it!=mp.end();++it)ans+=(ll)(it->scd)*(it->scd-1)/2;
	}
	for(int i=n,pos=n+1;i>=1;--i){
		nxt[i]=pos;
		if(s[i]=='1')pos=i;
	}
	for(int i=1;i<=n;++i){
		if(s[i]=='1'){
			int cur=i;
			int len=B+1;
			if(i+len-1>n)continue;
			if(i+len-1<nxt[i])ans+=(nxt[i]-1)-(i+len-1)+1;
			for(int j=2;;++j){
				if(nxt[cur]==n+1)break;
				cur=nxt[cur];
				int len=(B+1)*j;
				if(i+len-1>n)break;
				if(i+len-1<cur)ans+=(nxt[cur]-i)/j-B;
				else if(i+len-1<nxt[cur])ans+=((nxt[cur]-1)-(i+len-1))/j+1;
			}
		}else{
			int cur=i;
			for(int j=1;;++j){
				if(nxt[cur]==n+1)break;
				cur=nxt[cur];
				int len=(B+1)*j;
				if(i+len-1>n)break;
				if(i+len-1<cur)ans+=(nxt[cur]-i)/j-B;
				else if(i+len-1<nxt[cur])ans+=((nxt[cur]-1)-(i+len-1))/j+1;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

#define pb push_back
#define mk make_pair
#define lob lower_bound
#define upb upper_bound
#define fst first
#define scd second

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;

namespace Fread{
	const int MAXN=1<<20;
	char buffer[MAXN],*S,*T;
	inline char getchar(){
		if(S==T){
			T=(S=buffer)+fread(buffer,1,MAXN,stdin);
			if(S==T) return EOF;
		}
		return *S++;
	}
}
#ifdef ONLINE_JUDGE
	#define getchar Fread::getchar
#endif
inline int read(){
	int f=1,x=0;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
inline ll readll(){
	ll f=1,x=0;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int MAXN=2e5+5,B=300;
char s[MAXN];
int n,pre[MAXN],nxt[MAXN];
int main() {
	scanf("%s",s+1);n=strlen(s+1);
	for(int i=1;i<=n;++i)pre[i]=pre[i-1]+(s[i]=='1');
	ll ans=0;
	for(int k=1;k<=B;++k){
		map<int,int>mp;mp[0]=1;
		for(int i=1;i<=n;++i)mp[i-pre[i]*k]++;
		for(map<int,int>::iterator it=mp.begin();it!=mp.end();++it)ans+=(ll)(it->scd)*(it->scd-1)/2;
	}
	int lim=n/(B+1);
	if(!lim){
		cout<<ans<<endl;return 0;
	}
	for(int i=n,pos=n+1;i>=1;--i){
		nxt[i]=pos;
		if(s[i]=='1')pos=i;
	}
	for(int i=1;i<=n;++i){
		if(s[i]=='1'){
			int cur=i;
			int len=B+1;
			if(i+len-1>n)continue;
			if(i+len-1<nxt[i])ans+=(nxt[i]-1)-(i+len-1)+1;
			for(int j=2;j<=lim;++j){
				if(nxt[cur]==n+1)break;
				cur=nxt[cur];
				int len=(B+1)*j;
				if(i+len-1>n)break;
				if(i+len-1<nxt[cur])ans+=((nxt[cur]-1)-(i+len-1))/j+1;
			}
		}else{
			int cur=i;
			for(int j=1;j<=lim;++j){
				if(nxt[cur]==n+1)break;
				cur=nxt[cur];
				int len=(B+1)*j;
				if(i+len-1>n)break;
				if(i+len-1<nxt[cur])ans+=((nxt[cur]-1)-(i+len-1))/j+1;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

#define pb push_back
#define mk make_pair
#define lob lower_bound
#define upb upper_bound
#define fst first
#define scd second

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;

namespace Fread{
	const int MAXN=1<<20;
	char buffer[MAXN],*S,*T;
	inline char getchar(){
		if(S==T){
			T=(S=buffer)+fread(buffer,1,MAXN,stdin);
			if(S==T) return EOF;
		}
		return *S++;
	}
}
#ifdef ONLINE_JUDGE
	#define getchar Fread::getchar
#endif
inline int read(){
	int f=1,x=0;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
inline ll readll(){
	ll f=1,x=0;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int MAXN=2e5+5,B=200;
char s[MAXN];
int n,pre[MAXN],nxt[MAXN];
int main() {
	scanf("%s",s+1);n=strlen(s+1);
	for(int i=1;i<=n;++i)pre[i]=pre[i-1]+(s[i]=='1');
	ll ans=0;
	for(int k=1;k<=B;++k){
		map<int,int>mp;mp[0]=1;
		for(int i=1;i<=n;++i)mp[i-pre[i]*k]++;
		for(map<int,int>::iterator it=mp.begin();it!=mp.end();++it)ans+=(ll)(it->scd)*(it->scd-1)/2;
	}
	for(int i=n,pos=n+1;i>=1;--i){
		nxt[i]=pos;
		if(s[i]=='1')pos=i;
	}
	for(int i=1;i<=n;++i){
		if(s[i]=='1'){
			int cur=i;
			int len=B+1;
			if(i+len-1>n)continue;
			if(i+len-1<nxt[i])ans+=(nxt[i]-1)-(i+len-1)+1;
			for(int j=2;;++j){
				if(nxt[cur]==n+1)break;
				cur=nxt[cur];
				int len=(B+1)*j;
				if(i+len-1>n)break;
				if(i+len-1<cur)continue;
				if(max(cur,i+len-1)<nxt[cur])ans+=((nxt[cur]-1)-max(cur,i+len-1))/j+1;
			}
		}else{
			int cur=i;
			for(int j=1;;++j){
				if(nxt[cur]==n+1)break;
				cur=nxt[cur];
				int len=(B+1)*j;
				if(i+len-1>n)break;
				if(max(cur,i+len-1)<nxt[cur])ans+=((nxt[cur]-1)-max(cur,i+len-1))/j+1;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define eps 1e-8
#define fuck(x) cout<<"<"<<x<<">"<<endl
#define fi first
#define se second
#define pb push_back
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
using namespace std;
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int, int> pii;
const double PI = acos (-1.0);
const LL INFLL = 0x3f3f3f3f3f3f3f3fll;
const int maxn = 1e6 + 5;
const int mod = 998244353;

int t;
int cnt[maxn],tmp[maxn];
int x,y,a,b,n,m;
int main() {
    cin>>t;
    for (int i=0;i<t;i++) {
        int x;
        cin>>x;
        b=max(b,x);
        cnt[x]++;
    }
    for (int i=1;i<maxn;i++){
        if (cnt[i]!=i*4) {
            x=i;
            break;
        }
    }
    bool flag=0;
    for (n=1;n<=t;n++){
        if (t%n) continue;
        m=t/n;
        y=n-x+m-b;
        //if (n-x+m-y!=b) continue;
        memset(tmp,0,sizeof(tmp));
        for (int i=1;i<=n;i++){
            for (int j=1;j<=m;j++){
                int q=abs(x-i)+abs(y-j);
                tmp[q]++;
            }
        }
        int i;
        for (i=0;i<=n+m;i++) {
            if (cnt[i]!=tmp[i]) break;
        }
        if (i>n+m) {
            printf ("%d %d\n%d %d\n",n,m,x,y);
            flag=1;
            break;
        }
    }
    if (!flag) printf ("-1\n");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define debug test
#define mst(ss,b) memset((ss),(b),sizeof(ss))
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define inf 0x3f3f3f3f
#define eps 1e-10
#define MOD 1000000007
#define PI acos(-1.0)
const int N = 1e6+10;

int t,x,y,n,m,ct[N],tp[N];

int main() {
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>t;
    int nm,mx=0;
    for(int i=0;i<t;i++) {
        cin>>nm;
        ct[nm]++;
        mx=max(mx,nm);
    }
    for(int i=1;i<=t;i++)
        if(ct[i]!=4*i) {
            x=i;break;
        }
    int flag=1;
    for(int i=1;i*i<=t;i++) {
        if(t%i==0) {
            n=i,m=t/i,y=n-x+m-mx;
            mst(tp,0);
            for(int j=1;j<=n;j++)
                for(int k=1;k<=m;k++)
                    tp[(int)abs(j-x)+(int)abs(k-y)]++;
            int fg=0;
            for(int i=0;i<t;i++) if(ct[i]!=tp[i]) fg=1;
            if(fg==0) {
                cout<<n<<" "<<m<<endl;
                cout<<x<<" "<<y<<endl;
                flag=0;
                break;
            }
        }
    }
    if(flag) cout<<-1<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define eps 1e-8
#define fuck(x) cout<<"<"<<x<<">"<<endl
#define fi first
#define se second
#define pb push_back
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
using namespace std;
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int, int> pii;
const double PI = acos (-1.0);
const LL INFLL = 0x3f3f3f3f3f3f3f3fll;
const int maxn = 1e6 + 5;
const int mod = 998244353;

int t;
int cnt[maxn],tmp[3005];
int x,y,a,b,n,m;
int main() {
    cin>>t;
    for (int i=0;i<t;i++) {
        int x;
        cin>>x;
        b=max(b,x);
        cnt[x]++;
    }
    for (int i=1;i<maxn;i++){
        if (cnt[i]!=i*4) {
            x=i;
            break;
        }
    }
    bool flag=0;
    for (n=1;n<=t;n++){
        if (t%n) continue;
        m=t/n;
        y=n-x+m-b;
        //if (n-x+m-y!=b) continue;
        memset(tmp,0,sizeof(tmp));
        for (int i=1;i<=n;i++){
            for (int j=1;j<=m;j++){
                int q=abs(x-i)+abs(y-j);
                tmp[q]++;
            }
        }
        int i;
        for (i=0;i<=n+m;i++) {
            if (cnt[i]!=tmp[i]) break;
        }
        if (i>n+m) {
            printf ("%d %d\n%d %d\n",n,m,x,y);
            flag=1;
            break;
        }
    }
    if (!flag) printf ("-1\n");
    return 0;
}


#pragma comment(linker, "/STACK:102400000,102400000")///手动扩栈
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cstdio>
#include<bitset>
#include<vector>
#include<cmath>
#include<ctime>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<set>
#include<map>
using namespace std;
#define debug test
#define mst(ss,b) memset((ss),(b),sizeof(ss))
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define inf 0x3f3f3f3f
#define eps 1e-10
#define MOD 1000000007
#define PI acos(-1.0)
const int N = 1e6+10;

ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
int to[4][2]={{-1,0},{1,0},{0,-1},{0,1}};

int t,x,y,n,m,ct[N],tp[N];

int main() {
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>t;
    int nm,mx=0;
    for(int i=0;i<t;i++) {
        cin>>nm;
        ct[nm]++;
        mx=max(mx,nm);
    }
    for(int i=1;i<=t;i++)
        if(ct[i]!=4*i) {
            x=i;break;
        }
    int flag=1;
    for(int i=1;i*i<=t;i++) {
        if(t%i==0) {
            n=i,m=t/i,y=n-x+m-mx;
            mst(tp,0);
            for(int j=1;j<=n;j++)
                for(int k=1;k<=m;k++)
                    tp[(int)abs(j-x)+(int)abs(k-y)]++;
            int fg=0;
            for(int i=0;i<t;i++) if(ct[i]!=tp[i]) fg=1;
            if(fg==0) {
                cout<<n<<" "<<m<<endl;
                cout<<x<<" "<<y<<endl;
                flag=0;
                break;
            }
        }
    }
    if(flag) cout<<-1<<endl;
    return 0;
}


#include <iostream>
#include <stdio.h>

using namespace std;

int* b;
int t;

int* lahenda(int u, int d, int r, int l, int i, int j) {
    //
    int a = i * 4;
    int* ret = new int[4];
    int* ter;
    if (i == t + 1) {
        ret[0] = u;
        ret[1] = d;
        ret[2] = r;
        ret[3] = l;
        return ret;
    }
    int x = 0, y = 0;
    if (u > -1 && u < i) {
        x = i - u - 1;
        a -= 1 + 2 * (i - u - 1);
    }
    if (d > -1 && d < i) {
        y = i - d - 1;
        a -= 1 + 2 * (i - d - 1);
    }
    if (r > -1 && r < i) {
        a -= 1 + min(i - r - 1, i - x - 1) + min(i - r - 1, i - y - 1);
    }
    if (l > -1 && l < i) {
        a -= 1 + min(i - l - 1, i - x - 1) + min(i - l - 1, i - y - 1);
    }
    int k = a - b[i];
    if (k > 4 - j || k < 0) {
        ret[0] = -1;
        return ret;
    }
    if (k == 0) {
        ter = lahenda(u, d, r, l, i + 1, j);
        return ter;
    }
    if (k == 1) {
        if (j == 0) {
            ter = lahenda(i - 1, d, r, l, i + 1, j + 1);
            return ter;
        }
        if (j == 1) {
            ter = lahenda(u, i - 1, r, l, i + 1, j + 1);
            if (ter[0] != -1) {
                return ter;
            }
            ter = lahenda(u, d, i - 1, l, i + 1, j + 1);
            return ter;
        }
        if (j == 2) {
            if (r != -1) {
                ter = lahenda(u, d, r, i - 1, i + 1, j + 1);
                if (ter[0] != -1) {
                    return ter;
                }
                ter = lahenda(u, i - 1, r, l, i + 1, j + 1);
                return ter;
            }
            ter = lahenda(u, d, r, i - 1, i + 1, j + 1);
            if (ter[0] != -1) {
                return ter;
            }
            ter = lahenda(u, d, i - 1, l, i + 1, j + 1);
            return ter;
        }
        if (j == 3) {
            if (l == -1) {
                ter = lahenda(u, d, r, i - 1, i + 1, j + 1);
                return ter;
            }
            if (r == -1) {
                ter = lahenda(u, d, i - 1, l, i + 1, j + 1);
                return ter;
            }
            if (d == -1) {
                ter = lahenda(u, i - 1, r, l, i + 1, j + 1);
                return ter;
            }
        }
    }
    if (k == 2) {
        if (j == 0) {
            ter = lahenda(i - 1, i - 1, r, l, i + 1, j + 2);
            if (ter[0] != -1) {
                return ter;
            }
            ter = lahenda(i - 1, d, i - 1, l, i + 1, j + 2);
            return ter;
        }
        if (j == 1) {
            ter = lahenda(u, i - 1, i - 1, l, i + 1, j + 2);
            if (ter[0] != -1) {
                return ter;
            }
            ter = lahenda(u, d, i - 1, i - 1, i + 1, j + 2);
            return ter;
        }
        if (j == 2) {
            if (d == -1) {
                ter = lahenda(u, i - 1, r, i - 1, i + 1, j + 2);
                return ter;
            }
            ter = lahenda(u, d, i - 1, i - 1, i + 1, j + 2);
            return ter;
        }
    }
    if (k == 3) {
        if (j == 0) {
            ter = lahenda(i - 1, i - 1, i - 1, l, i + 1, j + 3);
            return ter;
        }
        if (j == 1) {
            ter = lahenda(u, i - 1, i - 1, i - 1, i + 1, j + 3);
            return ter;
        }
    }
    if (k == 4) {
        ter = lahenda(i - 1, i - 1, i - 1, i - 1, i + 1, j + 4);
        return ter;
    }
}

int main()
{
    int i;
    scanf("%d", &t);
    int* a = new int[t];
    b = new int[t + 1];
    for (i = 0; i < t; i++) {
        b[i] = 0;
    }
    for (i = 0; i < t; i++) {
        scanf("%d", &a[i]);
        b[a[i]]++;
    }
    if (b[0] != 1) {
        cout << -1;
        return 0;
    }
    if (t == 1) {
        cout << 1 << " " << 1 << endl << 1 << " " << 1;
        return 0;
    }
    int* ret = lahenda(-1, -1, -1, -1, 1, 0);
    if (ret[0] == -1) {
        cout << -1;
        return 0;
    }
    cout << ret[0] + ret[1] + 1 << " " << ret[2] + ret[3] + 1 << endl << ret[0] + 1 << " " << ret[3] + 1;
}


#include <iostream>

using namespace std;

int* b;
int t;

int* lahenda(int u, int d, int r, int l, int i, int j) {
    //
    int a = i * 4;
    int* ret = new int[4];
    int* ter;
    if (i == t + 1) {
        ret[0] = u;
        ret[1] = d;
        ret[2] = r;
        ret[3] = l;
        return ret;
    }
    int x = 0, y = 0;
    if (u > -1 && u < i) {
        x = i - u - 1;
        a -= 1 + 2 * (i - u - 1);
    }
    if (d > -1 && d < i) {
        y = i - d - 1;
        a -= 1 + 2 * (i - d - 1);
    }
    if (r > -1 && r < i) {
        a -= 1 + min(i - r - 1, i - x - 1) + min(i - r - 1, i - y - 1);
    }
    if (l > -1 && l < i) {
        a -= 1 + min(i - l - 1, i - x - 1) + min(i - l - 1, i - y - 1);
    }
    int k = a - b[i];
    if (k > 4 - j || k < 0) {
        ret[0] = -1;
        return ret;
    }
    if (k == 0) {
        ter = lahenda(u, d, r, l, i + 1, j);
        return ter;
    }
    if (k == 1) {
        if (j == 0) {
            ter = lahenda(i - 1, d, r, l, i + 1, j + 1);
            return ter;
        }
        if (j == 1) {
            ter = lahenda(u, i - 1, r, l, i + 1, j + 1);
            if (ter[0] != -1) {
                return ter;
            }
            ter = lahenda(u, d, i - 1, l, i + 1, j + 1);
            return ter;
        }
        if (j == 2) {
            if (r != -1) {
                ter = lahenda(u, d, r, i - 1, i + 1, j + 1);
                if (ter[0] != -1) {
                    return ter;
                }
                ter = lahenda(u, i - 1, r, l, i + 1, j + 1);
                return ter;
            }
            ter = lahenda(u, d, r, i - 1, i + 1, j + 1);
            if (ter[0] != -1) {
                return ter;
            }
            ter = lahenda(u, d, i - 1, l, i + 1, j + 1);
            return ter;
        }
        if (j == 3) {
            if (l == -1) {
                ter = lahenda(u, d, r, i - 1, i + 1, j + 1);
                return ter;
            }
            if (r == -1) {
                ter = lahenda(u, d, i - 1, l, i + 1, j + 1);
                return ter;
            }
            if (d == -1) {
                ter = lahenda(u, i - 1, r, l, i + 1, j + 1);
                return ter;
            }
        }
    }
    if (k == 2) {
        if (j == 0) {
            ter = lahenda(i - 1, i - 1, r, l, i + 1, j + 2);
            if (ter[0] != -1) {
                return ter;
            }
            ter = lahenda(i - 1, d, i - 1, l, i + 1, j + 2);
            return ter;
        }
        if (j == 1) {
            ter = lahenda(u, i - 1, i - 1, l, i + 1, j + 2);
            if (ter[0] != -1) {
                return ter;
            }
            ter = lahenda(u, d, i - 1, i - 1, i + 1, j + 2);
            return ter;
        }
        if (j == 2) {
            if (d == -1) {
                ter = lahenda(u, i - 1, r, i - 1, i + 1, j + 2);
                return ter;
            }
            ter = lahenda(u, d, i - 1, i - 1, i + 1, j + 2);
            return ter;
        }
    }
    if (k == 3) {
        if (j == 0) {
            ter = lahenda(i - 1, i - 1, i - 1, l, i + 1, j + 3);
            return ter;
        }
        if (j == 1) {
            ter = lahenda(u, i - 1, i - 1, i - 1, i + 1, j + 3);
            return ter;
        }
    }
    if (k == 4) {
        ter = lahenda(i - 1, i - 1, i - 1, i - 1, i + 1, j + 4);
        return ter;
    }
}

int main()
{
    int i;
    scanf(t);
    int a[t];
    b = new int[t + 1];
    for (i = 0; i < t; i++) {
        b[i] = 0;
    }
    for (i = 0; i < t; i++) {
        scanf(a[i]);
        b[a[i]]++;
    }
    if (b[0] != 1) {
        cout << -1;
        return 0;
    }
    if (t == 1) {
        cout << 1 << " " << 1 << endl << 1 << " " << 1;
        return 0;
    }
    int* ret = lahenda(-1, -1, -1, -1, 1, 0);
    if (ret[0] == -1) {
        cout << -1;
        return 0;
    }
    cout << ret[0] + ret[1] + 1 << " " << ret[2] + ret[3] + 1 << endl << ret[0] + 1 << " " << ret[3] + 1;
}


#include <iostream>
#include <stdio.h>

using namespace std;

int* b;
int t;

int* lahenda(int u, int d, int r, int l, int i, int j) {
    //
    int a = i * 4;
    int* ret = new int[4];
    int* ter;
    if (i == t + 1) {
        ret[0] = u;
        ret[1] = d;
        ret[2] = r;
        ret[3] = l;
        return ret;
    }
    int x = 0, y = 0;
    if (u > -1 && u < i) {
        x = i - u - 1;
        a -= 1 + 2 * (i - u - 1);
    }
    if (d > -1 && d < i) {
        y = i - d - 1;
        a -= 1 + 2 * (i - d - 1);
    }
    if (r > -1 && r < i) {
        a -= 1 + min(i - r - 1, i - x - 1) + min(i - r - 1, i - y - 1);
    }
    if (l > -1 && l < i) {
        a -= 1 + min(i - l - 1, i - x - 1) + min(i - l - 1, i - y - 1);
    }
    int k = a - b[i];
    if (k > 4 - j || k < 0) {
        ret[0] = -1;
        return ret;
    }
    if (k == 0) {
        ter = lahenda(u, d, r, l, i + 1, j);
        return ter;
    }
    if (k == 1) {
        if (j == 0) {
            ter = lahenda(i - 1, d, r, l, i + 1, j + 1);
            return ter;
        }
        if (j == 1) {
            ter = lahenda(u, i - 1, r, l, i + 1, j + 1);
            if (ter[0] != -1) {
                return ter;
            }
            ter = lahenda(u, d, i - 1, l, i + 1, j + 1);
            return ter;
        }
        if (j == 2) {
            if (r != -1) {
                ter = lahenda(u, d, r, i - 1, i + 1, j + 1);
                if (ter[0] != -1) {
                    return ter;
                }
                ter = lahenda(u, i - 1, r, l, i + 1, j + 1);
                return ter;
            }
            ter = lahenda(u, d, r, i - 1, i + 1, j + 1);
            if (ter[0] != -1) {
                return ter;
            }
            ter = lahenda(u, d, i - 1, l, i + 1, j + 1);
            return ter;
        }
        if (j == 3) {
            if (l == -1) {
                ter = lahenda(u, d, r, i - 1, i + 1, j + 1);
                return ter;
            }
            if (r == -1) {
                ter = lahenda(u, d, i - 1, l, i + 1, j + 1);
                return ter;
            }
            if (d == -1) {
                ter = lahenda(u, i - 1, r, l, i + 1, j + 1);
                return ter;
            }
        }
    }
    if (k == 2) {
        if (j == 0) {
            ter = lahenda(i - 1, i - 1, r, l, i + 1, j + 2);
            if (ter[0] != -1) {
                return ter;
            }
            ter = lahenda(i - 1, d, i - 1, l, i + 1, j + 2);
            return ter;
        }
        if (j == 1) {
            ter = lahenda(u, i - 1, i - 1, l, i + 1, j + 2);
            if (ter[0] != -1) {
                return ter;
            }
            ter = lahenda(u, d, i - 1, i - 1, i + 1, j + 2);
            return ter;
        }
        if (j == 2) {
            if (d == -1) {
                ter = lahenda(u, i - 1, r, i - 1, i + 1, j + 2);
                return ter;
            }
            ter = lahenda(u, d, i - 1, i - 1, i + 1, j + 2);
            return ter;
        }
    }
    if (k == 3) {
        if (j == 0) {
            ter = lahenda(i - 1, i - 1, i - 1, l, i + 1, j + 3);
            return ter;
        }
        if (j == 1) {
            ter = lahenda(u, i - 1, i - 1, i - 1, i + 1, j + 3);
            return ter;
        }
    }
    if (k == 4) {
        ter = lahenda(i - 1, i - 1, i - 1, i - 1, i + 1, j + 4);
        return ter;
    }
}

int main()
{
    int i;
    scanf("%d", t);
    int* a = new int[t];
    b = new int[t + 1];
    for (i = 0; i < t; i++) {
        b[i] = 0;
    }
    for (i = 0; i < t; i++) {
        scanf("%d", a[i]);
        b[a[i]]++;
    }
    if (b[0] != 1) {
        cout << -1;
        return 0;
    }
    if (t == 1) {
        cout << 1 << " " << 1 << endl << 1 << " " << 1;
        return 0;
    }
    int* ret = lahenda(-1, -1, -1, -1, 1, 0);
    if (ret[0] == -1) {
        cout << -1;
        return 0;
    }
    cout << ret[0] + ret[1] + 1 << " " << ret[2] + ret[3] + 1 << endl << ret[0] + 1 << " " << ret[3] + 1;
}


#include <iostream>

using namespace std;

int* b;
int t;

int* lahenda(int u, int d, int r, int l, int i, int j) {
    //
    int a = i * 4;
    int* ret = new int[4];
    int* ter;
    if (i == t + 1) {
        ret[0] = u;
        ret[1] = d;
        ret[2] = r;
        ret[3] = l;
        return ret;
    }
    int x = 0, y = 0;
    if (u > -1 && u < i) {
        x = i - u - 1;
        a -= 1 + 2 * (i - u - 1);
    }
    if (d > -1 && d < i) {
        y = i - d - 1;
        a -= 1 + 2 * (i - d - 1);
    }
    if (r > -1 && r < i) {
        a -= 1 + min(i - r - 1, i - x - 1) + min(i - r - 1, i - y - 1);
    }
    if (l > -1 && l < i) {
        a -= 1 + min(i - l - 1, i - x - 1) + min(i - l - 1, i - y - 1);
    }
    int k = a - b[i];
    if (k > 4 - j || k < 0) {
        ret[0] = -1;
        return ret;
    }
    if (k == 0) {
        ter = lahenda(u, d, r, l, i + 1, j);
        return ter;
    }
    if (k == 1) {
        if (j == 0) {
            ter = lahenda(i - 1, d, r, l, i + 1, j + 1);
            return ter;
        }
        if (j == 1) {
            ter = lahenda(u, i - 1, r, l, i + 1, j + 1);
            if (ter[0] != -1) {
                return ter;
            }
            ter = lahenda(u, d, i - 1, l, i + 1, j + 1);
            return ter;
        }
        if (j == 2) {
            if (r != -1) {
                ter = lahenda(u, d, r, i - 1, i + 1, j + 1);
                if (ter[0] != -1) {
                    return ter;
                }
                ter = lahenda(u, i - 1, r, l, i + 1, j + 1);
                return ter;
            }
            ter = lahenda(u, d, r, i - 1, i + 1, j + 1);
            if (ter[0] != -1) {
                return ter;
            }
            ter = lahenda(u, d, i - 1, l, i + 1, j + 1);
            return ter;
        }
        if (j == 3) {
            if (l == -1) {
                ter = lahenda(u, d, r, i - 1, i + 1, j + 1);
                return ter;
            }
            if (r == -1) {
                ter = lahenda(u, d, i - 1, l, i + 1, j + 1);
                return ter;
            }
            if (d == -1) {
                ter = lahenda(u, i - 1, r, l, i + 1, j + 1);
                return ter;
            }
        }
    }
    if (k == 2) {
        if (j == 0) {
            ter = lahenda(i - 1, i - 1, r, l, i + 1, j + 2);
            if (ter[0] != -1) {
                return ter;
            }
            ter = lahenda(i - 1, d, i - 1, l, i + 1, j + 2);
            return ter;
        }
        if (j == 1) {
            ter = lahenda(u, i - 1, i - 1, l, i + 1, j + 2);
            if (ter[0] != -1) {
                return ter;
            }
            ter = lahenda(u, d, i - 1, i - 1, i + 1, j + 2);
            return ter;
        }
        if (j == 2) {
            if (d == -1) {
                ter = lahenda(u, i - 1, r, i - 1, i + 1, j + 2);
                return ter;
            }
            ter = lahenda(u, d, i - 1, i - 1, i + 1, j + 2);
            return ter;
        }
    }
    if (k == 3) {
        if (j == 0) {
            ter = lahenda(i - 1, i - 1, i - 1, l, i + 1, j + 3);
            return ter;
        }
        if (j == 1) {
            ter = lahenda(u, i - 1, i - 1, i - 1, i + 1, j + 3);
            return ter;
        }
    }
    if (k == 4) {
        ter = lahenda(i - 1, i - 1, i - 1, i - 1, i + 1, j + 4);
        return ter;
    }
}

int main()
{
    int i;
    cin >> t;
    int a[t];
    b = new int[t + 1];
    for (i = 0; i < t; i++) {
        b[i] = 0;
    }
    for (i = 0; i < t; i++) {
        cin >> a[i];
        b[a[i]]++;
    }
    if (b[0] != 1) {
        cout << -1;
        return 0;
    }
    if (t == 1) {
        cout << 1 << " " << 1 << endl << 1 << " " << 1;
        return 0;
    }
    int* ret = lahenda(-1, -1, -1, -1, 1, 0);
    if (ret[0] == -1) {
        cout << -1;
        return 0;
    }
    cout << ret[0] + ret[1] + 1 << " " << ret[2] + ret[3] + 1 << endl << ret[0] + 1 << " " << ret[3] + 1;
}


#include <iostream>

using namespace std;

int* b;
int t;

int* lahenda(int u, int d, int r, int l, int i, int j) {
    //
    if (i == 4) {
        i = 4;
    }
    int a = i * 4;
    int* ret = new int[4];
    int* ter;
    if (i == t + 1) {
        ret[0] = u;
        ret[1] = d;
        ret[2] = r;
        ret[3] = l;
        return ret;
    }
    int x = 0, y = 0;
    if (u > -1 && u < i) {
        x = i - u - 1;
        a -= 1 + 2 * (i - u - 1);
    }
    if (d > -1 && d < i) {
        y = i - d - 1;
        a -= 1 + 2 * (i - d - 1);
    }
    if (r > -1 && r < i) {
        a -= 1 + min(i - r - 1, i - x - 1) + min(i - r - 1, i - y - 1);
    }
    if (l > -1 && l < i) {
        a -= 1 + min(i - l - 1, i - x - 1) + min(i - l - 1, i - y - 1);
    }
    int k = a - b[i];
    if (k > 4 - j || k < 0) {
        ret[0] = -1;
        return ret;
    }
    if (k == 0) {
        ter = lahenda(u, d, r, l, i + 1, j);
        return ter;
    }
    if (k == 1) {
        if (j == 0) {
            ter = lahenda(i - 1, d, r, l, i + 1, j + 1);
            return ter;
        }
        if (j == 1) {
            ter = lahenda(u, i - 1, r, l, i + 1, j + 1);
            if (ter[0] != -1) {
                return ter;
            }
            ter = lahenda(u, d, i - 1, l, i + 1, j + 1);
            return ter;
        }
        if (j == 2) {
            if (r != -1) {
                ter = lahenda(u, d, r, i - 1, i + 1, j + 1);
                if (ter[0] != -1) {
                    return ter;
                }
                ter = lahenda(u, i - 1, r, l, i + 1, j + 1);
                return ter;
            }
            ter = lahenda(u, d, r, i - 1, i + 1, j + 1);
            if (ter[0] != -1) {
                return ter;
            }
            ter = lahenda(u, d, i - 1, l, i + 1, j + 1);
            return ter;
        }
        if (j == 3) {
            if (l == -1) {
                ter = lahenda(u, d, r, i - 1, i + 1, j + 1);
                return ter;
            }
            if (r == -1) {
                ter = lahenda(u, d, i - 1, l, i + 1, j + 1);
                return ter;
            }
            if (d == -1) {
                ter = lahenda(u, i - 1, r, l, i + 1, j + 1);
                return ter;
            }
        }
    }
    if (k == 2) {
        if (j == 0) {
            ter = lahenda(i - 1, i - 1, r, l, i + 1, j + 2);
            if (ter[0] != -1) {
                return ter;
            }
            ter = lahenda(i - 1, d, i - 1, l, i + 1, j + 2);
            return ter;
        }
        if (j == 1) {
            ter = lahenda(u, i - 1, i - 1, l, i + 1, j + 2);
            if (ter[0] != -1) {
                return ter;
            }
            ter = lahenda(u, d, i - 1, i - 1, i + 1, j + 2);
            return ter;
        }
        if (j == 2) {
            if (d == -1) {
                ter = lahenda(u, i - 1, r, i - 1, i + 1, j + 2);
                return ter;
            }
            ter = lahenda(u, d, i - 1, i - 1, i + 1, j + 2);
            return ter;
        }
    }
    if (k == 3) {
        if (j == 0) {
            ter = lahenda(i - 1, i - 1, i - 1, l, i + 1, j + 3);
            return ter;
        }
        if (j == 1) {
            ter = lahenda(u, i - 1, i - 1, i - 1, i + 1, j + 3);
            return ter;
        }
    }
    if (k == 4) {
        ter = lahenda(i - 1, i - 1, i - 1, i - 1, i + 1, j + 4);
        return ter;
    }
}

int main()
{
    int i;
    cin >> t;
    int a[t];
    b = new int[t + 1];
    for (i = 0; i < t; i++) {
        b[i] = 0;
    }
    for (i = 0; i < t; i++) {
        cin >> a[i];
        b[a[i]]++;
    }
    if (b[0] != 1) {
        cout << -1;
        return 0;
    }
    if (t == 1) {
        cout << 1 << " " << 1 << endl << 1 << " " << 1;
        return 0;
    }
    int* ret = lahenda(-1, -1, -1, -1, 1, 0);
    if (ret[0] == -1) {
        cout << -1;
        return 0;
    }
    cout << ret[0] + ret[1] + 1 << " " << ret[2] + ret[3] + 1 << endl << ret[0] + 1 << " " << ret[3] + 1;
}