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

int main(){
    //freopen("test.inp" ,"r" ,stdin);
    int n;
    vector<int> vi;
    cin>>n;

    if (n<2){
        cout<<-1<<endl;
        return 0;
    }

    for (int i=0;i<n;i++){
        int a;
        cin>>a;
        vi.push_back(a);
    }
    sort(vi.begin(),vi.end());

    if (vi[0]==vi[n-1]){
        cout<<1<<endl<<vi[0]<<endl;
        return 0;
    }

    if (n==2){
        int tmp=vi[0]+vi[1];
        int d=vi[1]-vi[0];
        if (tmp%2==0){
            cout<<3<<endl;
            cout<<vi[0]-d<<" "<<tmp/2<<" "<<vi[1]+d<<endl;
            return 0;
        }

        cout<<2<<endl;
        cout<<vi[0]-d<<" "<<vi[1]+d<<endl;
        return 0;
    }

    bool init=true;
    for (int i=1;i<(int)vi.size()-1;i++){
        int d1=vi[i]-vi[i-1];
        int d2=vi[i+1]-vi[i];
        if (d1!=d2)
            init=false;
        if (d1!=0 and d2!=0){
            if (d1==2*d2){
                cout<<1<<endl;
                cout<<vi[i]-d2<<endl;
                return 0;
            }

            if (d2==2*d1){
                cout<<1<<endl;
                cout<<vi[i]+d1<<endl;
                return 0;
            }
        }
    }

    if (init){
        cout<<2<<endl;
        int d=vi[1]-vi[0];
        cout<<vi[0]-d<<" "<<vi[n-1]+d<<endl;
        return 0;
    }
    cout<<0<<endl;
    return 0;

}


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

int main(){
    //freopen("test.inp" ,"r" ,stdin);
    int n;
    vector<int> vi;
    cin>>n;

    if (n<2){
        cout<<-1<<endl;
        return 0;
    }

    for (int i=0;i<n;i++){
        int a;
        cin>>a;
        vi.push_back(a);
    }
    sort(vi.begin(),vi.end());
    bool cons=true;
    for (int i=0;i<(int)vi.size()-1;i++){
        if (vi[i]!=vi[i+1]){
            cons=false;
            break;
        }
    }
    if (cons){
        cout<<1<<endl<<vi[0]<<endl;
        return 0;
    }

    if (n==2){
        int tmp=vi[0]+vi[1];
        int d=vi[1]-vi[0];
        if (tmp%2==0){
            cout<<3<<endl;
            cout<<vi[0]-d<<" "<<tmp/2<<" "<<vi[1]+d<<endl;
            return 0;
        }

        cout<<2<<endl;
        cout<<vi[0]-d<<" "<<vi[1]+d<<endl;
        return 0;
    }

    bool init=true;
    int save=-1;

    for (int i=1;i<(int)vi.size()-1;i++){
        int d1=vi[i]-vi[i-1];
        int d2=vi[i+1]-vi[i];
        if (d1!=d2 and (not init)){
            //cout<<0<<endl;
            //return 0;
            //continue;
            break;
        }

        if (d1!=d2)
            init=false;
        if (d1!=0 and d2!=0){
            if (d1==2*d2){
                save=vi[i]-d2;
            }

            if (d2==2*d1){
                save=vi[i]+d1;
            }
        }
    }

    if (not init and save!=-1){
        cout<<1<<endl<<save<<endl;
        return 0;
    }

    if (init){
        cout<<2<<endl;
        int d=vi[1]-vi[0];
        cout<<vi[0]-d<<" "<<vi[n-1]+d<<endl;
        return 0;
    }

    cout<<0<<"end"<<endl;
    return 0;

}


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

int main(){
    //freopen("test.inp" ,"r" ,stdin);
    int n;
    vector<int> vi;
    cin>>n;
    if (n==1){
        cout<<"-1"<<endl;
        return 0;
    }
    for (int i=0;i<n;i++){
        long long a;
        cin>>a;
        /*bool present= (find(vi.begin(),vi.end(),a) != vi.end());
        if (n>3 and present){
            cout<<0<<endl;
            return 0;
        }*/
        vi.push_back(a);
    }
    sort(vi.begin(),vi.end());
    bool consta=true;
    int test=vi[0];
    for (int i=0;i<(int)vi.size();i++){
        if (vi[i]!=test){
            consta=false;
            break;
        }
    }
    if (consta){
        cout<<1<<endl<<test<<endl;
        return 0;
    }
    if (n==2){
        if ((vi[0]+vi[1])%2==0){
            int com=vi[1]-vi[0];
            cout<<3<<endl;
            cout<<vi[0]-com<<" "<<(vi[0]+vi[1])/2<<" "<<vi[1]+com<<endl;
            return 0;
        }
        else{
            cout<<0<<endl;
            return 0;
        }
    }

    int d=(vi[n-1]-vi[0])/(n-1);
    for (int i=0;i<(int)vi.size()-1;i++){
        if ((vi[i+1]-vi[i])!= d){
            if ((vi[i+1]-vi[i])==2*d){
                cout<<1<<endl;
                cout<<vi[i]+d;
                return 0;
            }
            else{
                cout<<0<<endl;
                return 0;
            }
        }
    }

    cout<<2<<endl;
    cout<<vi[0]-d<<" "<<vi[n-1]+d<<endl;

}


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

int main(){
    //freopen("test.inp" ,"r" ,stdin);
    int n;
    vector<int> vi;
    cin>>n;

    if (n<2){
        cout<<-1<<endl;
        return 0;
    }

    for (int i=0;i<n;i++){
        int a;
        cin>>a;
        vi.push_back(a);
    }
    sort(vi.begin(),vi.end());

    if (vi[0]==vi[n-1]){
        cout<<1<<endl<<vi[0]<<endl;
        return 0;
    }

    if (n==2){
        int tmp=vi[0]+vi[1];
        int d=vi[1]-vi[0];
        if (tmp%2==0){
            cout<<3<<endl;
            cout<<vi[0]-d<<" "<<tmp/2<<" "<<vi[1]+d<<endl;
            return 0;
        }

        cout<<2<<endl;
        cout<<vi[0]-d<<" "<<vi[1]+d<<endl;
    }

    bool init=true;
    for (int i=1;i<(int)vi.size()-1;i++){
        int d1=vi[i]-vi[i-1];
        int d2=vi[i+1]-vi[i];
        if (d1!=d2)
            init=false;

        if (d1==2*d2){
            cout<<1<<endl;
            cout<<vi[i]-d2<<endl;
            return 0;
        }

        if (d2==2*d1){
            cout<<1<<endl;
            cout<<vi[i]+d1<<endl;
            return 0;
        }
    }

    if (init){
        cout<<2<<endl;
        int d=vi[1]-vi[0];
        cout<<vi[0]-d<<" "<<vi[n-1]+d<<endl;
        return 0;
    }
    cout<<0<<endl;
    return 0;

}


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

int main(){
    //freopen("test.inp" ,"r" ,stdin);
    int n;
    vector<int> vi;
    cin>>n;

    if (n<2){
        cout<<-1<<endl;
        return 0;
    }

    for (int i=0;i<n;i++){
        int a;
        cin>>a;
        vi.push_back(a);
    }
    sort(vi.begin(),vi.end());

    if (vi[0]==vi[n-1]){
        cout<<1<<endl<<vi[0]<<endl;
        return 0;
    }

    if (n==2){
        int tmp=vi[0]+vi[1];
        int d=vi[1]-vi[0];
        if (tmp%2==0){
            cout<<3<<endl;
            cout<<vi[0]-d<<" "<<tmp/2<<" "<<vi[1]+d<<endl;
            return 0;
        }

        cout<<2<<endl;
        cout<<vi[0]-d<<" "<<vi[1]+d<<endl;
        return 0;
    }

    bool init=true;
    for (int i=1;i<(int)vi.size()-1;i++){
        int d1=vi[i]-vi[i-1];
        int d2=vi[i+1]-vi[i];
        if (d1!=d2)
            init=false;

        if (d1==2*d2){
            cout<<1<<endl;
            cout<<vi[i]-d2<<endl;
            return 0;
        }

        if (d2==2*d1){
            cout<<1<<endl;
            cout<<vi[i]+d1<<endl;
            return 0;
        }
    }

    if (init){
        cout<<2<<endl;
        int d=vi[1]-vi[0];
        cout<<vi[0]-d<<" "<<vi[n-1]+d<<endl;
        return 0;
    }
    cout<<0<<endl;
    return 0;

}


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

int main(){
    //freopen("test.inp" ,"r" ,stdin);
    int n;
    vector<int> vi;
    cin>>n;

    if (n<2){
        cout<<-1<<endl;
        return 0;
    }

    for (int i=0;i<n;i++){
        int a;
        cin>>a;
        vi.push_back(a);
    }
    sort(vi.begin(),vi.end());

    if (vi[0]==vi[n-1]){
        cout<<1<<endl<<vi[0]<<endl;
        return 0;
    }

    if (n==2){
        int tmp=vi[0]+vi[1];
        int d=vi[1]-vi[0];
        if (tmp%2==0){
            cout<<3<<endl;
            cout<<vi[0]-d<<" "<<tmp/2<<" "<<vi[1]+d<<endl;
            return 0;
        }

        cout<<2<<endl;
        cout<<vi[0]-d<<" "<<vi[1]+d<<endl;
        return 0;
    }

    bool init=true;
    int save=-1;

    for (int i=1;i<(int)vi.size()-1;i++){
        int d1=vi[i]-vi[i-1];
        int d2=vi[i+1]-vi[i];
        if (d1!=d2 and (not init)){
            cout<<0<<endl;
            return 0;
        }

        if (d1!=d2)
            init=false;
        if (d1!=0 and d2!=0){
            if (d1==2*d2){
                save=vi[i]-d2;
            }

            if (d2==2*d1){
                save=vi[i]+d1;
            }
        }
    }

    if (not init and save!=-1){
        cout<<1<<endl<<save<<endl;
        return 0;
    }

    if (init){
        cout<<2<<endl;
        int d=vi[1]-vi[0];
        cout<<vi[0]-d<<" "<<vi[n-1]+d<<endl;
        return 0;
    }

    cout<<0<<endl;
    return 0;

}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>

#define pb push_back
#define f  first
#define s second

using namespace std;

typedef pair<int,int> pr;
typedef long long ll;
int sum[100005][3];
int arr[100005];
int cnt1,cnt2,cnt3;
int ans1[100005],ans2[100005];
int n;
vector<pr> data;

int binsearch(int idx,int x,int l,int r)
{
	int a,b,m;

	while(l < r)
	{
		m = (l+r)/2;

		if(max(sum[m][2]-sum[x][2],sum[m][1]-sum[x][1]) >= idx)
		{
			r  = m;
		}
		else
		{
			l = m+1;
		}

	}
	if(r > n)
		return -1;
	else if(r < 1)
		return -1;
	a = sum[r][2] - sum[x][2];
	b = sum[r][1] - sum[x][1];

	if(a == idx)
	{
		cnt2++;
		return r;
	}
	else if(b == idx)
	{
		cnt1++;
		return r;
	}
	else
		return -1;

}

void func(int idx)
{
	int x;

	cnt2 = 0;
	cnt1 = 0;

	x = 0;
	while(x <  n)
	{
		x = binsearch(idx,x,x+1,n);
		if(x == -1)
			break;
	}
	if(x == n)
	{
		if(cnt1 > cnt2)
		{
			ans1[cnt3] = cnt1;
			ans2[cnt3] =  idx;
			cnt3++;
		}
		else if(cnt2 > cnt1)
		{
			ans1[cnt3] = cnt2;
			ans2[cnt3] = idx;
			cnt3++;
		}
	}
}

int main()
{
	int i;

	cin>>n;

	for(i = 1;i <= n;i++)
	{
		cin>>arr[i];
	}

	sum[0][1] = sum[0][2] = 0;

	for(i = 1; i<= n;i++)
	{
		if(arr[i] == 1)
		{
			sum[i][1]  = sum[i-1][1]+1;
			sum[i][2] = sum[i-1][2];
		}
		else
		{
			sum[i][1] = sum[i-1][1];
			sum[i][2] = sum[i-1][2] + 1;
		}
	}

	for(i = n;i >= 2;i--)
	{
		func(i);
	}

	//cout<<sum[n][2]<<" "<<sum[n][1]<<endl;
	if(sum[n][2] > sum[n][1])
	{
		if(arr[n] == 2)
			cnt3++;

	}
	else if(sum[n][1] > sum[n][2])
	{
		if(arr[n] == 1)
			cnt3++;
	}

	cout<<cnt3<<endl;
	for(i = 0;i < cnt3-1;i++)
	{
		data.pb(pr(ans1[i],ans2[i]));
	}

	if(sum[n][2] > sum[n][1])
	{
		if(arr[n] == 2)
		data.pb(pr(sum[n][2],1));
	}
	else if(sum[n][1] > sum[n][2])
	{
		if(arr[n] == 1)
		data.pb(pr(sum[n][1],1));
	}
	sort(data.begin(),data.end());
	int sz = data.size();
	for(i = 0;i < sz;i++)
	{
		cout<<data[i].f<<" "<<data[i].s<<endl;
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>

#define pb push_back
#define f  first
#define s second

using namespace std;

typedef pair<int,int> pr;
typedef long long ll;
int sum[100005][3];
int arr[100005];
int cnt1,cnt2,cnt;
int ans1[100005],ans2[100005];
int n;
vector<pr> data;

int binsearch(int idx,int x,int l,int r)
{
	int a,b,m;

	while(l < r)
	{
		m = (l+r)/2;

		if(max(sum[m][2]-sum[x][2],sum[m][1]-sum[x][1]) >= idx)
		{
			r  = m;
		}
		else
		{
			l = m+1;
		}

	}
	a = sum[r][2] - sum[x][2];
	b = sum[r][1] - sum[x][1];
	if(a == idx)
	{
		cnt2++;
		return r;
	}
	else if(b == idx)
	{
		cnt1++;
		return r;
	}
	else
		return -1;

}

void func(int idx)
{
	int x;

	cnt2 = 0;
	cnt1 = 0;

	x = 0;
	while(x <  n)
	{
		x = binsearch(idx,x,x+1,n);
		if(x == -1)
			break;
	}
	if(x == n)
	{
		if(cnt1 > cnt2)
		{
			ans1[cnt] = cnt1;
			ans2[cnt++] =  idx;
		}
		else if(cnt2 > cnt1)
		{
			ans1[cnt] = cnt2;
			ans2[cnt++] = idx;
		}
	}
}

int main()
{
	int i;
	ios::sync_with_stdio(false);
	cnt = 0;
	cin>>n;

	for(i = 1;i <= n;i++)
	{
		cin>>arr[i];
	}

	sum[0][1] = sum[0][2] = 0;

	for(i = 1; i<= n;i++)
	{
		if(arr[i] == 1)
		{
			sum[i][1]  = sum[i-1][1]+1;
			sum[i][2] = sum[i-1][2];
		}
		else
		{
			sum[i][1] = sum[i-1][1];
			sum[i][2] = sum[i-1][2] + 1;
		}
	}

	for(i = n;i >= 2;i--)
	{
		func(i);
	}

	if(sum[n][2] > sum[n][1])
	{
		cnt++;
	}
	else if(sum[n][1] > sum[n][2])
	{
		cnt++;
	}
	cout<<cnt<<endl;
	for(i = 0;i < cnt-1;i++)
	{
		data.pb(pr(ans1[i],ans2[i]));
	}

	if(sum[n][2] > sum[n][1])
	{
		data.pb(pr(sum[n][2],1));
	}
	else if(sum[n][1] > sum[n][2])
	{
		data.pb(pr(sum[n][1],1));
	}
	sort(data.begin(),data.end());
	int sz = data.size();
	for(i = 0;i < sz;i++)
	{
		cout<<data[i].f<<" "<<data[i].s<<endl;
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>

#define pb push_back
#define f  first
#define s second

using namespace std;

typedef pair<int,int> pr;
typedef long long ll;
int sum[100005][3];
int arr[100005];
int cnt1,cnt2,cnt3,last;
int ans1[100005],ans2[100005];
int n;
vector<pr> data;

int binsearch(int idx,int x,int l,int r)
{
	int a,b,m;

	while(l < r)
	{
		m = (l+r)/2;

		if(max((sum[m][2]-sum[x][2]),(sum[m][1]-sum[x][1])) >= idx)
		{
			r  = m;
		}
		else
		{
			l = m+1;
		}

	}
	if(r > n)
		return -1;
	else if(r < 1)
		return -1;

	a = sum[r][2] - sum[x][2];
	b = sum[r][1] - sum[x][1];

	if(a == idx)
	{
		cnt2++;
		last = 2;
		return r;
	}
	else if((b == idx))
	{
		cnt1++;
		last = 1;
		return r;
	}
	else
		return -1;

}

void func(int idx)
{
	int x;

	cnt1 = cnt2 = 0;
	x = 0;
	last = 0;
	while(x <  n)
	{
		x = binsearch(idx,x,x,n);
		if(x == -1)
			break;
	}
	if(x == n)
	{
		if((cnt1 > cnt2) && (last == 1))
		{
			ans1[cnt3] = cnt1;
			ans2[cnt3] =  idx;
			cnt3++;
		}
		else if((cnt2 > cnt1) && (last == 2))
		{
			ans1[cnt3] = cnt2;
			ans2[cnt3] = idx;
			cnt3++;
		}
	}
}

int main()
{
	int i,v;

	cin>>n;
	cnt3 = 0;
	for(i = 1;i <= n;i++)
	{
		cin>>arr[i];
	}

	sum[0][1] = sum[0][2] = 0;

	for(i = 1; i<= n;i++)
	{
		if(arr[i] == 1)
		{
			sum[i][1]  = sum[i-1][1] + 1;
			sum[i][2] = sum[i-1][2];
		}
		else
		{
			sum[i][1] = sum[i-1][1];
			sum[i][2] = sum[i-1][2] + 1;
		}
	}
	for(i = n;i >= 2;i--)
	{
		func(i);
	}
	//cout<<sum[n][2]<<" "<<sum[n][1]<<endl;
	v = cnt3;
	if(sum[n][2] > sum[n][1])
	{
		if(arr[n] == 2)
			cnt3++;

	}
	else if(sum[n][1] > sum[n][2])
	{
		if(arr[n] == 1)
			cnt3++;
	}

	cout<<cnt3<<endl;
	for(i = 0;i < v;i++)
	{
		data.pb(pr(ans1[i],ans2[i]));
	}

	if(sum[n][2] > sum[n][1])
	{
		if(arr[n] == 2)
			data.pb(pr(sum[n][2],1));
	}
	else if(sum[n][1] > sum[n][2])
	{
		if(arr[n] == 1)
			data.pb(pr(sum[n][1],1));
	}
	sort(data.begin(),data.end());
	int sz = data.size();
	for(i = 0;i < sz;i++)
	{
		cout<<data[i].f<<" "<<data[i].s<<endl;
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>

#define pb push_back
#define f  first
#define s second

using namespace std;

typedef pair<int,int> pr;
typedef long long ll;
int sum[100005][3];
int arr[100005];
int cnt1,cnt2,cnt;
int ans1[100005],ans2[100005];
int n;
vector<pr> data;

int binsearch(int idx,int x,int l,int r)
{
	int a,b,m;

	while(l < r)
	{
		m = (l+r)/2;

		if(max(sum[m][2]-sum[x][2],sum[m][1]-sum[x][1]) >= idx)
		{
			r  = m;
		}
		else
		{
			l = m+1;
		}

	}
//	if(r > n)
//		cout<<"nishnat"<<endl;
	a = sum[r][2] - sum[x][2];
	b = sum[r][1] - sum[x][1];
	if(a == idx)
	{
		cnt2++;
		return r;
	}
	else if(b == idx)
	{
		cnt1++;
		return r;
	}
	else
		return -1;

}

void func(int idx)
{
	int x;

	cnt2 = 0;
	cnt1 = 0;

	x = 0;
	while(x <  n)
	{
		x = binsearch(idx,x,x+1,n);
		if(x == -1)
			break;
	}
	if(x == n)
	{
		if(cnt1 > cnt2)
		{
			ans1[cnt] = cnt1;
			ans2[cnt++] =  idx;
		}
		else if(cnt2 > cnt1)
		{
			ans1[cnt] = cnt2;
			ans2[cnt++] = idx;
		}
	}
}

int main()
{
	int i;

	cnt = 0;
	cin>>n;

	for(i = 1;i <= n;i++)
	{
		cin>>arr[i];
	}

	sum[0][1] = sum[0][2] = 0;

	for(i = 1; i<= n;i++)
	{
		if(arr[i] == 1)
		{
			sum[i][1]  = sum[i-1][1]+1;
			sum[i][2] = sum[i-1][2];
		}
		else
		{
			sum[i][1] = sum[i-1][1];
			sum[i][2] = sum[i-1][2] + 1;
		}
	}

	for(i = n;i >= 2;i--)
	{
		func(i);
	}

	//cout<<sum[n][2]<<" "<<sum[n][1]<<endl;
	if(sum[n][2] > sum[n][1])
	{
		cnt++;
	}
	else if(sum[n][1] > sum[n][2])
	{
		cnt++;
	}
	cout<<cnt<<endl;
	for(i = 0;i < cnt-1;i++)
	{
		data.pb(pr(ans1[i],ans2[i]));
	}

	if(sum[n][2] > sum[n][1])
	{
		data.pb(pr(sum[n][2],1));
	}
	else if(sum[n][1] > sum[n][2])
	{
		data.pb(pr(sum[n][1],1));
	}
	sort(data.begin(),data.end());
	int sz = data.size();
	for(i = 0;i < sz;i++)
	{
		cout<<data[i].f<<" "<<data[i].s<<endl;
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>

#define pb push_back
#define f  first
#define s second

using namespace std;

typedef pair<int,int> pr;
typedef long long ll;
int sum[100005][3];
int arr[100005];
int cnt1,cnt2,cnt;
int ans1[100005],ans2[100005];
int n;
vector<pr> data;

int binsearch(int idx,int x,int l,int r)
{
	int a,b,m;

	while(l < r)
	{
		m = (l+r)/2;

		if(max(sum[m][2]-sum[x][2],sum[m][1]-sum[x][1]) >= idx)
		{
			r  = m;
		}
		else
		{
			l = m+1;
		}

	}
	if(r > n)
		return -1;
	else if(r < 1)
		return -1;
	a = sum[r][2] - sum[x][2];
	b = sum[r][1] - sum[x][1];

	if(a == idx)
	{
		cnt2++;
		return r;
	}
	else if(b == idx)
	{
		cnt1++;
		return r;
	}
	else
		return -1;

}

void func(int idx)
{
	int x;

	cnt2 = 0;
	cnt1 = 0;

	x = 0;
	while(x <  n)
	{
		x = binsearch(idx,x,x+1,n);
		if(x == -1)
			break;
	}
	if(x == n)
	{
		if(cnt1 > cnt2)
		{
			ans1[cnt] = cnt1;
			ans2[cnt++] =  idx;
		}
		else if(cnt2 > cnt1)
		{
			ans1[cnt] = cnt2;
			ans2[cnt++] = idx;
		}
	}
}

int main()
{
	int i;

	cnt = 0;
	cin>>n;

	for(i = 1;i <= n;i++)
	{
		cin>>arr[i];
	}

	sum[0][1] = sum[0][2] = 0;

	for(i = 1; i<= n;i++)
	{
		if(arr[i] == 1)
		{
			sum[i][1]  = sum[i-1][1]+1;
			sum[i][2] = sum[i-1][2];
		}
		else
		{
			sum[i][1] = sum[i-1][1];
			sum[i][2] = sum[i-1][2] + 1;
		}
	}

	for(i = n;i >= 2;i--)
	{
		func(i);
	}

	//cout<<sum[n][2]<<" "<<sum[n][1]<<endl;
	if(sum[n][2] > sum[n][1])
	{
		cnt++;
	}
	else if(sum[n][1] > sum[n][2])
	{
		cnt++;
	}
	cout<<cnt<<endl;
	for(i = 0;i < cnt-1;i++)
	{
		data.pb(pr(ans1[i],ans2[i]));
	}

	if(sum[n][2] > sum[n][1])
	{
		data.pb(pr(sum[n][2],1));
	}
	else if(sum[n][1] > sum[n][2])
	{
		data.pb(pr(sum[n][1],1));
	}
	sort(data.begin(),data.end());
	int sz = data.size();
	for(i = 0;i < sz;i++)
	{
		cout<<data[i].f<<" "<<data[i].s<<endl;
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>

#define pb push_back
#define f  first
#define s second

using namespace std;

typedef pair<int,int> pr;
typedef long long ll;
int sum[100005][3];
int arr[100005];
int cnt1,cnt2,cnt3;
int ans1[100005],ans2[100005];
int n;
vector<pr> data;

int binsearch(int idx,int x,int l,int r)
{
	int a,b,m;

	while(l < r)
	{
		m = (l+r)/2;

		if(max((sum[m][2]-sum[x][2]),(sum[m][1]-sum[x][1])) >= idx)
		{
			r  = m;
		}
		else
		{
			l = m+1;
		}

	}
	if(r > n)
		return -1;
	else if(r < 1)
		return -1;

	a = sum[r][2] - sum[x][2];
	b = sum[r][1] - sum[x][1];

	if(a == idx)
	{
		cnt2++;
		return r;
	}
	else if(b == idx)
	{
		cnt1++;
		return r;
	}
	else
		return -1;

}

void func(int idx)
{
	int x;

	cnt1 = cnt2 = 0;
	x = 0;
	while(x <  n)
	{
		x = binsearch(idx,x,x+1,n);
		if(x == -1)
			break;
	}
	if(x == n)
	{
		if(cnt1 > cnt2)
		{
			ans1[cnt3] = cnt1;
			ans2[cnt3] =  idx;
			cnt3++;
		}
		else if(cnt2 > cnt1)
		{
			ans1[cnt3] = cnt2;
			ans2[cnt3] = idx;
			cnt3++;
		}
	}
}

int main()
{
	int i,v;

	cin>>n;
	cnt3 = 0;
	for(i = 1;i <= n;i++)
	{
		cin>>arr[i];
	}

	sum[0][1] = sum[0][2] = 0;

	for(i = 1; i<= n;i++)
	{
		if(arr[i] == 1)
		{
			sum[i][1]  = sum[i-1][1] + 1;
			sum[i][2] = sum[i-1][2];
		}
		else
		{
			sum[i][1] = sum[i-1][1];
			sum[i][2] = sum[i-1][2] + 1;
		}
	}
	for(i = n;i >= 2;i--)
	{
		func(i);
	}
	//cout<<sum[n][2]<<" "<<sum[n][1]<<endl;
	v = cnt3;
	if(sum[n][2] > sum[n][1])
	{
		if(arr[n] == 2)
			cnt3++;

	}
	else if(sum[n][1] > sum[n][2])
	{
		if(arr[n] == 1)
			cnt3++;
	}

	cout<<cnt3<<endl;
	for(i = 0;i < v;i++)
	{
		data.pb(pr(ans1[i],ans2[i]));
	}

	if(sum[n][2] > sum[n][1])
	{
		if(arr[n] == 2)
			data.pb(pr(sum[n][2],1));
	}
	else if(sum[n][1] > sum[n][2])
	{
		if(arr[n] == 1)
			data.pb(pr(sum[n][1],1));
	}
	sort(data.begin(),data.end());
	int sz = data.size();
	for(i = 0;i < sz;i++)
	{
		cout<<data[i].f<<" "<<data[i].s<<endl;
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>

#define pb push_back
#define f  first
#define s second

using namespace std;

typedef pair<int,int> pr;
typedef long long ll;
int sum[100005][3];
int arr[100005];
int cnt1,cnt2,cnt;
int ans1[10005],ans2[100005];
int n;

int binsearch(int idx,int x,int l,int r)
{
	int a,b,m;

	while(l < r)
	{
		m = (l+r)/2;

		if(max(sum[m][2]-sum[x][2],sum[m][1]-sum[x][1]) >= idx)
		{
			r  = m;
		}
		else
		{
			l = m+1;
		}

	}
	a = sum[r][2] - sum[x][2];
	b = sum[r][1] - sum[x][1];
	if(a == idx)
	{
		cnt2++;
		return r;
	}
	else if(b == idx)
	{
		cnt1++;
		return r;
	}
	else
		return -1;

}

void func(int idx)
{
	int x;

	cnt2 = 0;
	cnt1 = 0;

	x = 0;
	while(x <  n)
	{
		x = binsearch(idx,x,x+1,n);
		if(x == -1)
			break;
	}
	if(x == n)
	{
		if(cnt1 > cnt2)
		{
			ans1[cnt] = cnt1;
			ans2[cnt++] =  idx;
		}
		else if(cnt2 > cnt1)
		{
			ans1[cnt] = cnt2;
			ans2[cnt++] = idx;
		}
	}
}

int main()
{
	int i;
	cnt = 0;
	ios::sync_with_stdio(false);

	cin>>n;

	for(i = 1;i <= n;i++)
	{
		cin>>arr[i];
	}

	sum[0][1] = sum[0][2] = 0;
	for(i = 1; i<= n;i++)
	{
		if(arr[i] == 1)
		{
			sum[i][1]  = sum[i-1][1]+1;
			sum[i][2] = sum[i-1][2];
		}
		else
		{
			sum[i][1] = sum[i-1][1];
			sum[i][2] = sum[i-1][2] + 1;
		}
	}

	for(i = n;i >= 2;i--)
	{
		func(i);
	}

	if(sum[n][2] > sum[n][1])
	{
		cnt++;
	}
	else if(sum[n][1] > sum[n][2])
	{
		cnt++;
	}
	cout<<cnt<<endl;
	for(i = 0;i < cnt-1;i++)
	{
		cout<<ans1[i]<<" "<<ans2[i]<<endl;
	}

	if(sum[n][2] > sum[n][1])
	{
		cout<<sum[n][2]<<" "<<"1"<<endl;
	}
	else if(sum[n][1] > sum[n][2])
	{
		cout<<sum[n][1]<<" "<<"1"<<endl;
	}

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>

#define pb push_back
#define f  first
#define s second

using namespace std;

typedef pair<int,int> pr;
typedef long long ll;
int sum[100005][3];
int arr[100005];
int cnt1,cnt2,cnt3;
int ans1[100005],ans2[100005];
int n;
vector<pr> data;

int binsearch(int idx,int x,int l,int r)
{
	int a,b,m;

	while(l < r)
	{
		m = l+(r-l)/2;

		if(max((sum[m][2]-sum[x][2]),(sum[m][1]-sum[x][1])) >= idx)
		{
			r  = m;
		}
		else
		{
			l = m+1;
		}

	}
	if(r > n)
		return -1;
	else if(r < 1)
		return -1;
	a = sum[r][2] - sum[x][2];
	b = sum[r][1] - sum[x][1];

	if(a == idx)
	{
		cnt2++;
		return r;
	}
	else if(b == idx)
	{
		cnt1++;
		return r;
	}
	else
		return -1;

}

void func(int idx)
{
	int x;

	cnt2 = 0;
	cnt1 = 0;

	x = 0;
	while(x <  n)
	{
		x = binsearch(idx,x,x+1,n);
		if(x == -1)
			break;
	}
	if(x == n)
	{
		if(cnt1 > cnt2)
		{
			ans1[cnt3] = cnt1;
			ans2[cnt3] =  idx;
			cnt3++;
		}
		else if(cnt2 > cnt1)
		{
			ans1[cnt3] = cnt2;
			ans2[cnt3] = idx;
			cnt3++;
		}
	}
}

int main()
{
	int i;

	cin>>n;

	for(i = 1;i <= n;i++)
	{
		cin>>arr[i];
	}

	sum[0][1] = sum[0][2] = 0;

	for(i = 1; i<= n;i++)
	{
		if(arr[i] == 1)
		{
			sum[i][1]  = sum[i-1][1]+1;
			sum[i][2] = sum[i-1][2];
		}
		else
		{
			sum[i][1] = sum[i-1][1];
			sum[i][2] = sum[i-1][2] + 1;
		}
	}

	for(i = n;i >= 2;i--)
	{
		func(i);
	}

	//cout<<sum[n][2]<<" "<<sum[n][1]<<endl;
	if(sum[n][2] > sum[n][1])
	{
		if(arr[n] == 2)
			cnt3++;

	}
	else if(sum[n][1] > sum[n][2])
	{
		if(arr[n] == 1)
			cnt3++;
	}

	cout<<cnt3<<endl;
	for(i = 0;i < cnt3-1;i++)
	{
		data.pb(pr(ans1[i],ans2[i]));
	}

	if(sum[n][2] > sum[n][1])
	{
		if(arr[n] == 2)
		data.pb(pr(sum[n][2],1));
	}
	else if(sum[n][1] > sum[n][2])
	{
		if(arr[n] == 1)
		data.pb(pr(sum[n][1],1));
	}
	sort(data.begin(),data.end());
	int sz = data.size();
	for(i = 0;i < sz;i++)
	{
		cout<<data[i].f<<" "<<data[i].s<<endl;
	}
	return 0;
}


#include<iostream>
#include<stdio.h>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
#include<vector>
#include<queue>
#include<string.h>
#include<set>
using namespace std ;

#define MAXN 300007

int n ;
int a[ MAXN ] ;
int pref1[ MAXN ] ;
int pref2[ MAXN ] ;
int wh1[ MAXN ] ;
int wh2[ MAXN ] ;
//1166750

void input ( ) ;
void solve ( ) ;

int main ( )  {
    ios::sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
	input ( ) ;
	solve ( ) ;
	return 0 ;
}

void input ( )  {
	scanf ( "%d" , &n ) ;
	int i ;
	for ( i = 1 ; i <= n ; i ++ ) {
		scanf ( "%d" , &a[ i ] ) ;
    }
}

void solve ( )  {
	int i ;
	int j ;
	int br1 , br2 ;
	int s1 , s2 ;
	vector < pair < int , int > > v ;
	for ( i = 1 ; i <= n ; i ++ ) {
		if ( a[ i ] == 1 ) { pref1[ i ] = pref1[ i - 1 ] + 1 ; wh1[ pref1[ i ] ] = i ; }
		else pref1[ i ] = pref1[ i - 1 ] ;

		if ( a[ i ] == 2 ) { pref2[ i ] = pref2[ i - 1 ] + 1 ; wh2[ pref2[ i ] ] = i ; }
		else pref2[ i ] = pref2[ i - 1 ] ;

    }
	int ind1 ;
	int ind2 ;
	for ( i = 1 ; i <= n ; i ++ ) {
		br1 = 0 ;
		br2 = 0 ;
		int curpos = 0 ;
		s1 = 0 ;
		s2 = 0 ;
		while ( curpos < n ) {
			ind1 = MAXN  ;
			ind2 = MAXN ;
			if ( wh1[ br1 + i ] != 0 ) ind1 = wh1[ br1 + i ] ;
			if ( wh2[ br2 + i ] != 0 ) ind2 = wh2[ br2 + i ] ;
			if ( ind1 == MAXN && ind2 == MAXN ) break ;
			if ( ind1 < ind2 ) {
				s1 ++ ;
				curpos = wh1[ br1 + i ] ;
				br1 = pref1[ curpos ] ;
				br2 = pref2[ curpos ] ;
            }
			else if ( ind1 > ind2 ) {
				s2 ++ ;
				curpos = wh2[ br2 + i ] ;
				br1 = pref1[ curpos ] ;
				br2 = pref2[ curpos ] ;
            }
			else {
				curpos = wh1[ br1 + i ] ;
				br1 = pref1[ curpos ] ;
				br2 = pref2[ curpos ] ;
            }
        }
		//if ( i == 3 ) printf ( "%d %d\n" , s1 , s2 ) ;
		if ( ind1 == MAXN && ind2 == MAXN && curpos != n ) continue ;
		if ( s1 < s2 ) swap ( s1 , s2 ) ;
		if ( s1 == s2 ) continue ;
		//if ( s1 % i != 0 ) continue ;
        //	s1 /= i ;
		//s2 /= i ;
		if ( pref1[ curpos ] != pref1[ n ] || pref2[ curpos ] != pref2[ n ] ) continue ;
		v.push_back ( make_pair ( s1 , i ) ) ;
    }
	sort ( v.begin ( ) , v.end ( ) ) ;
	int sz = v.size ( ) ;
	printf ( "%d\n" , sz ) ;
	for ( i = 0 ; i < sz ; i ++ ) {
		printf ( "%d %d\n" , v[ i ].first , v[ i ].second ) ;
    }
}


#include<iostream>
#include<stdio.h>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
#include<vector>
#include<queue>
#include<string.h>
#include<set>
using namespace std ;

#define MAXN 300007

int n ;
int a[ MAXN ] ;
int pref1[ MAXN ] ;
int pref2[ MAXN ] ;
int wh1[ MAXN ] ;
int wh2[ MAXN ] ;
//1166750

void input ( ) ;
void solve ( ) ;

int main ( )  {
    ios::sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
	input ( ) ;
	solve ( ) ;
	return 0 ;
}

void input ( )  {
	scanf ( "%d" , &n ) ;
	int i ;
	for ( i = 1 ; i <= n ; i ++ ) {
		scanf ( "%d" , &a[ i ] ) ;
    }
}

void solve ( )  {
	int i ;
	int j ;
	int br1 , br2 ;
	int s1 , s2 ;
	vector < pair < int , int > > v ;
	for ( i = 1 ; i <= n ; i ++ ) {
		if ( a[ i ] == 1 ) { pref1[ i ] = pref1[ i - 1 ] + 1 ; wh1[ pref1[ i ] ] = i ; }
		else pref1[ i ] = pref1[ i - 1 ] ;

		if ( a[ i ] == 2 ) { pref2[ i ] = pref2[ i - 1 ] + 1 ; wh2[ pref2[ i ] ] = i ; }
		else pref2[ i ] = pref2[ i - 1 ] ;

    }
	int ind1 ;
	int ind2 ;
	int lst = -1 ;
	for ( i = 1 ; i <= n ; i ++ ) {
		br1 = 0 ;
		br2 = 0 ;
		int curpos = 0 ;
		s1 = 0 ;
		s2 = 0 ;
		lst = -1 ;
		while ( curpos < n ) {
			ind1 = MAXN  ;
			ind2 = MAXN ;
			if ( wh1[ br1 + i ] != 0 ) ind1 = wh1[ br1 + i ] ;
			if ( wh2[ br2 + i ] != 0 ) ind2 = wh2[ br2 + i ] ;
			if ( ind1 == MAXN && ind2 == MAXN ) break ;
			if ( ind1 < ind2 ) {
				s1 ++ ;
				curpos = wh1[ br1 + i ] ;
				br1 = pref1[ curpos ] ;
				br2 = pref2[ curpos ] ;
				lst = 0 ;
            }
			else if ( ind1 > ind2 ) {
				s2 ++ ;
				curpos = wh2[ br2 + i ] ;
				br1 = pref1[ curpos ] ;
				br2 = pref2[ curpos ] ;
				lst = 1 ;
            }
			else {
				curpos = wh1[ br1 + i ] ;
				br1 = pref1[ curpos ] ;
				br2 = pref2[ curpos ] ;
            }
        }
		//if ( i == 3 ) printf ( "%d %d\n" , s1 , s2 ) ;
		if ( curpos != n ) continue ;
		if ( s1 < s2 ) { swap ( s1 , s2 ) ; lst ^= 1 ; }
		if ( lst == 1 ) continue ;
		if ( s1 == s2 ) continue ;
		//if ( s1 % i != 0 ) continue ;
        //	s1 /= i ;
		//s2 /= i ;
		if ( pref1[ curpos ] != pref1[ n ] || pref2[ curpos ] != pref2[ n ] ) continue ;
		v.push_back ( make_pair ( s1 , i ) ) ;
    }
	sort ( v.begin ( ) , v.end ( ) ) ;
	int sz = v.size ( ) ;
	printf ( "%d\n" , sz ) ;
	for ( i = 0 ; i < sz ; i ++ ) {
		printf ( "%d %d\n" , v[ i ].first , v[ i ].second ) ;
    }
}


#include<iostream>
#include<stdio.h>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
#include<vector>
#include<queue>
#include<string.h>
#include<set>
using namespace std ;

#define MAXN 200007

int n ;
int a[ MAXN ] ;
int pref1[ MAXN ] ;
int pref2[ MAXN ] ;
int wh1[ MAXN ] ;
int wh2[ MAXN ] ;
//1166750

void input ( ) ;
void solve ( ) ;

int main ( )  {
    ios::sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
	input ( ) ;
	solve ( ) ;
	return 0 ;
}

void input ( )  {
	scanf ( "%d" , &n ) ;
	int i ;
	for ( i = 1 ; i <= n ; i ++ ) {
		scanf ( "%d" , &a[ i ] ) ;
    }
}

void solve ( )  {
	int i ;
	int j ;
	int br1 , br2 ;
	int s1 , s2 ;
	vector < pair < int , int > > v ;
	for ( i = 1 ; i <= n ; i ++ ) {
		if ( a[ i ] == 1 ) { pref1[ i ] = pref1[ i - 1 ] + 1 ; wh1[ pref1[ i ] ] = i ; }
		else pref1[ i ] = pref1[ i - 1 ] ;

		if ( a[ i ] == 2 ) { pref2[ i ] = pref2[ i - 1 ] + 1 ; wh2[ pref2[ i ] ] = i ; }
		else pref2[ i ] = pref2[ i - 1 ] ;

    }
	int ind1 ;
	int ind2 ;
	for ( i = 1 ; i <= n ; i ++ ) {
		br1 = 0 ;
		br2 = 0 ;
		int curpos = 0 ;
		s1 = 0 ;
		s2 = 0 ;
		while ( curpos <= n ) {
			ind1 = MAXN  ;
			ind2 = MAXN ;
			if ( wh1[ br1 + i ] != 0 ) ind1 = wh1[ br1 + i ] ;
			if ( wh2[ br2 + i ] != 0 ) ind2 = wh2[ br2 + i ] ;
			if ( ind1 == MAXN && ind2 == MAXN ) break ;
			if ( ind1 < ind2 ) {
				s1 ++ ;
				curpos = wh1[ br1 + i ] ;
				br1 = pref1[ curpos ] ;
				br2 = pref2[ curpos ] ;
            }
			else if ( ind1 > ind2 ) {
				s2 ++ ;
				curpos = wh2[ br2 + i ] ;
				br1 = pref1[ curpos ] ;
				br2 = pref2[ curpos ] ;
            }
			else {
				curpos = wh1[ br1 + i ] ;
				br1 = pref1[ curpos ] ;
				br2 = pref2[ curpos ] ;
            }
        }
		//if ( i == 3 ) printf ( "%d %d\n" , s1 , s2 ) ;
		if ( s1 < s2 ) swap ( s1 , s2 ) ;
		if ( s1 == s2 ) continue ;
		//if ( s1 % i != 0 ) continue ;
        //	s1 /= i ;
		//s2 /= i ;
		if ( pref1[ curpos ] != pref1[ n ] || pref2[ curpos ] != pref2[ n ] ) continue ;
		v.push_back ( make_pair ( s1 , i ) ) ;
    }
	sort ( v.begin ( ) , v.end ( ) ) ;
	int sz = v.size ( ) ;
	printf ( "%d\n" , sz ) ;
	for ( i = 0 ; i < sz ; i ++ ) {
		printf ( "%d %d\n" , v[ i ].first , v[ i ].second ) ;
    }
}


#include<iostream>
#include<stdio.h>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
#include<vector>
#include<queue>
#include<string.h>
#include<set>
using namespace std ;

#define MAXN 300007

int n ;
int a[ MAXN ] ;
int pref1[ MAXN ] ;
int pref2[ MAXN ] ;
int wh1[ MAXN ] ;
int wh2[ MAXN ] ;
//1166750

void input ( ) ;
void solve ( ) ;

int main ( )  {
    ios::sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    input ( ) ;
    solve ( ) ;
    return 0 ;
}

void input ( )  {
    scanf ( "%d" , &n ) ;
    int i ;
    for ( i = 1 ; i <= n ; i ++ ) {
        scanf ( "%d" , &a[ i ] ) ;
    }
}

void solve ( )  {
    int i ;
    int j ;
    int br1 , br2 ;
    int s1 , s2 ;
    vector < pair < int , int > > v ;
    for ( i = 1 ; i <= n ; i ++ ) {
        if ( a[ i ] == 1 ) { pref1[ i ] = pref1[ i - 1 ] + 1 ; wh1[ pref1[ i ] ] = i ; }
        else pref1[ i ] = pref1[ i - 1 ] ;

        if ( a[ i ] == 2 ) { pref2[ i ] = pref2[ i - 1 ] + 1 ; wh2[ pref2[ i ] ] = i ; }
        else pref2[ i ] = pref2[ i - 1 ] ;

    }
    int ind1 ;
    int ind2 ;
    int lst = -1 ;
    for ( i = 1 ; i <= n ; i ++ ) {
        br1 = 0 ;
        br2 = 0 ;
        int curpos = 0 ;
        s1 = 0 ;
        s2 = 0 ;
        lst = -1 ;
        while ( curpos < n ) {
            ind1 = MAXN  ;
            ind2 = MAXN ;
            if ( wh1[ br1 + i ] != 0 ) ind1 = wh1[ br1 + i ] ;
            if ( wh2[ br2 + i ] != 0 ) ind2 = wh2[ br2 + i ] ;
            if ( ind1 == MAXN && ind2 == MAXN ) break ;
            if ( ind1 < ind2 ) {
                s1 ++ ;
                curpos = wh1[ br1 + i ] ;
                br1 = pref1[ curpos ] ;
                br2 = pref2[ curpos ] ;
                lst = 0 ;
            }
            else if ( ind1 > ind2 ) {
                s2 ++ ;
                curpos = wh2[ br2 + i ] ;
                br1 = pref1[ curpos ] ;
                br2 = pref2[ curpos ] ;
                lst = 1 ;
            }
            else {
                curpos = wh1[ br1 + i ] ;
                br1 = pref1[ curpos ] ;
                br2 = pref2[ curpos ] ;
            }
        }
        //if ( i == 3 ) printf ( "%d %d\n" , s1 , s2 ) ;
        if ( curpos != n ) continue ;
        if ( s1 < s2 ) { swap ( s1 , s2 ) ; lst ^= 1 ; }
        if ( lst == 1 ) continue ;
        if ( s1 == s2 ) continue ;
        //if ( s1 % i != 0 ) continue ;
        //  s1 /= i ;
        //s2 /= i ;
        if ( pref1[ curpos ] != pref1[ n ] || pref2[ curpos ] != pref2[ n ] ) continue ;
        v.push_back ( make_pair ( s1 , i ) ) ;
    }
    sort ( v.begin ( ) , v.end ( ) ) ;
    int sz = v.size ( ) ;
    printf ( "%d\n" , sz ) ;
    for ( i = 0 ; i < sz ; i ++ ) {
        printf ( "%d %d\n" , v[ i ].first , v[ i ].second ) ;
    }
}


#include<iostream>
#include<stdio.h>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
#include<vector>
#include<queue>
#include<string.h>
#include<set>
using namespace std ;

#define MAXN 300007

int n ;
int a[ MAXN ] ;
int pref1[ MAXN ] ;
int pref2[ MAXN ] ;
int wh1[ MAXN ] ;
int wh2[ MAXN ] ;
//1166750

void input ( ) ;
void solve ( ) ;

int main ( )  {
    ios::sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
	input ( ) ;
	solve ( ) ;
	return 0 ;
}

void input ( )  {
	scanf ( "%d" , &n ) ;
	int i ;
	for ( i = 1 ; i <= n ; i ++ ) {
		scanf ( "%d" , &a[ i ] ) ;
    }
}

void solve ( )  {
	int i ;
	int j ;
	int br1 , br2 ;
	int s1 , s2 ;
	vector < pair < int , int > > v ;
	for ( i = 1 ; i <= n ; i ++ ) {
		if ( a[ i ] == 1 ) { pref1[ i ] = pref1[ i - 1 ] + 1 ; wh1[ pref1[ i ] ] = i ; }
		else pref1[ i ] = pref1[ i - 1 ] ;

		if ( a[ i ] == 2 ) { pref2[ i ] = pref2[ i - 1 ] + 1 ; wh2[ pref2[ i ] ] = i ; }
		else pref2[ i ] = pref2[ i - 1 ] ;

    }
	int ind1 ;
	int ind2 ;
	for ( i = 1 ; i <= n ; i ++ ) {
		br1 = 0 ;
		br2 = 0 ;
		int curpos = 0 ;
		s1 = 0 ;
		s2 = 0 ;
		while ( curpos < n ) {
			ind1 = MAXN  ;
			ind2 = MAXN ;
			if ( wh1[ br1 + i ] != 0 ) ind1 = wh1[ br1 + i ] ;
			if ( wh2[ br2 + i ] != 0 ) ind2 = wh2[ br2 + i ] ;
			if ( ind1 == MAXN && ind2 == MAXN ) break ;
			if ( ind1 < ind2 ) {
				s1 ++ ;
				curpos = wh1[ br1 + i ] ;
				br1 = pref1[ curpos ] ;
				br2 = pref2[ curpos ] ;
            }
			else if ( ind1 > ind2 ) {
				s2 ++ ;
				curpos = wh2[ br2 + i ] ;
				br1 = pref1[ curpos ] ;
				br2 = pref2[ curpos ] ;
            }
			else {
				curpos = wh1[ br1 + i ] ;
				br1 = pref1[ curpos ] ;
				br2 = pref2[ curpos ] ;
            }
        }
		//if ( i == 3 ) printf ( "%d %d\n" , s1 , s2 ) ;
		if ( curpos != n ) continue ;
		if ( s1 < s2 ) swap ( s1 , s2 ) ;
		if ( s1 == s2 ) continue ;
		//if ( s1 % i != 0 ) continue ;
        //	s1 /= i ;
		//s2 /= i ;
		if ( pref1[ curpos ] != pref1[ n ] || pref2[ curpos ] != pref2[ n ] ) continue ;
		v.push_back ( make_pair ( s1 , i ) ) ;
    }
	sort ( v.begin ( ) , v.end ( ) ) ;
	int sz = v.size ( ) ;
	printf ( "%d\n" , sz ) ;
	for ( i = 0 ; i < sz ; i ++ ) {
		printf ( "%d %d\n" , v[ i ].first , v[ i ].second ) ;
    }
}


#include <algorithm>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <iostream>
#include <fstream>
#include <cmath>
#include <math.h>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>

using namespace std;

#define FOR(i,n) for (int i=0; i<n; ++i)
#define FORE(i,n) for (int i=0; i<=n; ++i)
#define REP(i,a,b) for (int i=a; i<b; ++i)
#define REPE(i,a,b) for (int i=a; i<=b; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define mp make_pair
#define pb push_back

typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long int LL;
typedef vector<int> VI;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const double pi = acos(-1.0);
const int inf = (int) 1e9;

const int mx = 100005;

int a[mx];
int b[2][mx];
int n;

int main()
{
#ifdef _DEBUG
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#else
    //freopen("wtflex.in","r",stdin);
    //freopen("wtflex.out","w",stdout);
#endif

    cin >> n;

    FOR(i,n) {
        cin >> a[i];
        b[a[i] - 1][i] = 1;
        if (i) {
            b[0][i] += b[0][i - 1];
            b[1][i] += b[1][i - 1];
        }
    }
    VPII ans;
    REPE(i,1,n) {
        int t = i;
        int sx = 0;
        int sy = 0;
        int xx = i;
        int yy = i;
        int s = 0;
        int pos = 0;
        while(true) {
            int x = lower_bound(b[0] + pos, b[0] + n, xx) - b[0];
            int y = lower_bound(b[1] + pos, b[1] + n, yy) - b[1];
            if (x == n && y == n) {
                break;
            }
            if (x < y) {
                sx++;
                xx += t;
                yy = b[1][x] + t;
                pos = x + 1;
            }
            if (y < x) {
                sy++;
                yy += t;
                xx = b[0][y] + t;
                pos = y + 1;
            }
            if (pos >= n) {
                if (sx != sy) {
                    if (sx > sy) {
                        if (x < y) {
                            s = sx;
                        }
                    } else {
                        if (x > y) {
                            s = sy;
                        }
                    }
                }
                break;
            }
        }
        if (s != 0) {
            ans.pb(mp(s, t));
        }
    }
    sort(ans.begin(), ans.end());
    cout << ans.size() << "\n";
    FOR(i,ans.size()) {
        cout << ans[i].first << " " << ans[i].second << "\n";
    }
    return 0;
}


#include <algorithm>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <iostream>
#include <fstream>
#include <cmath>
#include <math.h>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>

using namespace std;

#define FOR(i,n) for (int i=0; i<n; ++i)
#define FORE(i,n) for (int i=0; i<=n; ++i)
#define REP(i,a,b) for (int i=a; i<b; ++i)
#define REPE(i,a,b) for (int i=a; i<=b; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define mp make_pair
#define pb push_back

typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long int LL;
typedef vector<int> VI;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const double pi = acos(-1.0);
const int inf = (int) 1e9;

int main()
{
#ifdef _DEBUG
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#else
    //freopen("wtflex.in","r",stdin);
    //freopen("wtflex.out","w",stdout);
#endif
    int n;
    cin >> n;
    VI a(n);
    int x = 0;
    int y = 0;
    FOR(i,n) {
        cin >> a[i];
        if (a[i] == 1) {
            ++x;
        } else {
            ++y;
        }
    }
    int z = max(x, y);
    VI d;
    REPE(i,1,z) {
        if (z % i == 0) {
            d.pb(i);
        }
    }
    int s = 0;
    int t = 0;
    VPII ans;
    FOR(i,d.size()) {
        s = d[i];
        t = z / d[i];
        x = 0;
        y = 0;
        int x1 = 0;
        int y1 = 0;
        FOR(j,n) {
            if (a[j] == 1) {
                ++x;
            } else {
                ++y;
            }
            if (x == t) {
                ++x1;
                x = 0;
                y = 0;
            }
            if (y == t) {
                ++y1;
                x = 0;
                y = 0;
            }
            if (x1 == s || y1 == s) {
                if (j == n - 1) {
                    ans.pb(mp(s, t));
                } else {
                    break;
                }
            }
        }
    }
    cout << ans.size() << "\n";
    FOR(i,ans.size()) {
        cout << ans[i].first << " " << ans[i].second << "\n";
    }
    return 0;
}


#include <algorithm>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <iostream>
#include <fstream>
#include <cmath>
#include <math.h>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>

using namespace std;

#define FOR(i,n) for (int i=0; i<n; ++i)
#define FORE(i,n) for (int i=0; i<=n; ++i)
#define REP(i,a,b) for (int i=a; i<b; ++i)
#define REPE(i,a,b) for (int i=a; i<=b; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define mp make_pair
#define pb push_back

typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long int LL;
typedef vector<int> VI;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const double pi = acos(-1.0);
const int inf = (int) 1e9;

int main()
{
#ifdef _DEBUG
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#else
    //freopen("wtflex.in","r",stdin);
    //freopen("wtflex.out","w",stdout);
#endif
    int n;
    cin >> n;
    VI a(n);
    int x = 0;
    int y = 0;
    FOR(i,n) {
        cin >> a[i];
        if (a[i] == 1) {
            ++x;
        } else {
            ++y;
        }
    }
    int z = max(x, y);
    VPII d;
    REPE(i,1,z) {
        if (x != 0 && x % i == 0) {
            d.pb(mp(i, x));
        }
        if (y != 0 && y % i == 0) {
            d.pb(mp(i, y));
        }
    }
    int s = 0;
    int t = 0;
    VPII ans;
    FOR(i,d.size()) {
        s = d[i].first;
        t = d[i].second / d[i].first;
        x = 0;
        y = 0;
        int x1 = 0;
        int y1 = 0;
        FOR(j,n) {
            if (a[j] == 1) {
                ++x;
            } else {
                ++y;
            }
            if (x == t) {
                ++x1;
                x = 0;
                y = 0;
            }
            if (y == t) {
                ++y1;
                x = 0;
                y = 0;
            }
            if (x1 == s || y1 == s) {
                if (j == n - 1) {
                    ans.pb(mp(s, t));
                } else {
                    break;
                }
            }
        }
    }
    sort(ans.begin(), ans.end());
    ans.erase(unique(ans.begin(), ans.end()), ans.end());
    cout << ans.size() << "\n";
    FOR(i,ans.size()) {
        cout << ans[i].first << " " << ans[i].second << "\n";
    }
    return 0;
}


#include <algorithm>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <iostream>
#include <fstream>
#include <cmath>
#include <math.h>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>

using namespace std;

#define FOR(i,n) for (int i=0; i<n; ++i)
#define FORE(i,n) for (int i=0; i<=n; ++i)
#define REP(i,a,b) for (int i=a; i<b; ++i)
#define REPE(i,a,b) for (int i=a; i<=b; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define mp make_pair
#define pb push_back

typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long int LL;
typedef vector<int> VI;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const double pi = acos(-1.0);
const int inf = (int) 1e9;

const int mx = 100005;

int a[mx];
int b[2][mx];
int n;

int main()
{
#ifdef _DEBUG
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#else
    //freopen("wtflex.in","r",stdin);
    //freopen("wtflex.out","w",stdout);
#endif

    cin >> n;

    FOR(i,n) {
        cin >> a[i];
        b[a[i] - 1][i] = 1;
        if (i) {
            b[0][i] += b[0][i - 1];
            b[1][i] += b[1][i - 1];
        }
    }
    VPII ans;
    REPE(i,1,n) {
        int t = i;
        int sx = 0;
        int sy = 0;
        int xx = i;
        int yy = i;
        int s = 0;
        int pos = 0;
        while(true) {
            int x = lower_bound(b[0] + pos, b[0] + n, xx) - b[0];
            int y = lower_bound(b[1] + pos, b[1] + n, yy) - b[1];
            if (x == n && y == n) {
                break;
            }
            if (x < y) {
                sx++;
                xx += t;
                yy = b[1][x] + t;
                pos = x + 1;
            }
            if (y < x) {
                sy++;
                yy += t;
                xx = b[0][y] + t;
                pos = y + 1;
            }
            if (pos >= n) {
                if (sx != sy) {
                    s = max(sx, sy);
                }
                break;
            }
        }
        if (s != 0) {
            ans.pb(mp(s, t));
        }
    }
    sort(ans.begin(), ans.end());
    cout << ans.size() << "\n";
    FOR(i,ans.size()) {
        cout << ans[i].first << " " << ans[i].second << "\n";
    }
    return 0;
}


#include <algorithm>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <iostream>
#include <fstream>
#include <cmath>
#include <math.h>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>

using namespace std;

#define FOR(i,n) for (int i=0; i<n; ++i)
#define FORE(i,n) for (int i=0; i<=n; ++i)
#define REP(i,a,b) for (int i=a; i<b; ++i)
#define REPE(i,a,b) for (int i=a; i<=b; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define mp make_pair
#define pb push_back

typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long int LL;
typedef vector<int> VI;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const double pi = acos(-1.0);
const int inf = (int) 1e9;

int main()
{
#ifdef _DEBUG
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#else
    //freopen("wtflex.in","r",stdin);
    //freopen("wtflex.out","w",stdout);
#endif
    int n;
    cin >> n;
    VI a(n);
    int x = 0;
    int y = 0;
    FOR(i,n) {
        cin >> a[i];
        if (a[i] == 1) {
            ++x;
        } else {
            ++y;
        }
    }
    int z = max(x, y);
    VI d;
    REPE(i,1,z) {
        if (z % i == 0) {
            d.pb(i);
        }
    }
    int s = 0;
    int t = 0;
    VPII ans;
    FOR(i,d.size()) {
        s = d[i];
        t = z / d[i];
        x = 0;
        y = 0;
        int x1 = 0;
        int y1 = 0;
        FOR(j,n) {
            if (a[j] == 1) {
                ++x;
            } else {
                ++y;
            }
            if (x == t) {
                ++x1;
                x = 0;
                y = 0;
            }
            if (y == t) {
                ++y1;
                x = 0;
                y = 0;
            }
        }
        if ((x1 == s && y1 != s ||
            y1 == s && x1 != s) && x == 0 && y == 0) {
            ans.pb(mp(s, t));
        }
    }
    cout << ans.size() << "\n";
    FOR(i,ans.size()) {
        cout << ans[i].first << " " << ans[i].second << "\n";
    }
    return 0;
}


using namespace std;
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>

vector<int> one;
vector<int> two;
set< pair<int,int> > sols;

int main() {
    int n, t;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> t;
        if(t == 1) {
            one.push_back(i);
        }
        else {
            two.push_back(i);
        }
    }

    for(int t = 1; t <= n; t++) {
        int i = t-1, j = t-1, sa = 0, sb = 0;
        while(i < one.size() || j < two.size()) {
            if(j >= two.size() || i < one.size() && one[i] < two[j]) {
                sa++;
                i = lower_bound(one.begin(), one.end(), one[i]+1) - one.begin() + t-1;
                j = lower_bound(two.begin(), two.end(), one[i]+1) - two.begin() + t-1;
            }
            else {
                sb++;
                i = lower_bound(one.begin(), one.end(), two[j]+1) - one.begin() + t-1;
                j = lower_bound(two.begin(), two.end(), two[j]+1) - two.begin() + t-1;
            }
        }
        if(sa > sb && i == one.size() + t - 1) {
            sols.insert(pair<int,int>(sa, t));
        }
        else if(sb > sa && j == two.size() + t - 1) {
            sols.insert(pair<int,int>(sb, t));
        }
    }

    cout << sols.size() << '\n';
    for(set< pair<int,int> >::iterator it = sols.begin(); it != sols.end(); it++) {
        cout << (*it).first << ' ' << (*it).second << '\n';
    }
    return 0;
}


using namespace std;
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>

vector<int> one;
vector<int> two;
set< pair<int,int> > sols;

int main() {
    int n, x;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> x;
        if(x == 1) {
            one.push_back(i);
        }
        else {
            two.push_back(i);
        }
    }

    for(int t = 1; t <= n; t++) {
        int i = t-1, j = t-1, sa = 0, sb = 0;
        while(i < one.size() || j < two.size()) {
            if(j >= two.size() || one[i] < two[j]) {
                sa++;
                x = i;
                if(i < one.size())
                    i = lower_bound(one.begin(), one.end(), one[x]) - one.begin() + t;
                else
                    i = 2 * n;
                if(j < two.size())
                    j = lower_bound(two.begin(), two.end(), one[x]) - two.begin() + t-1;
                else
                    j = 2 * n;
            }
            else {
                sb++;
                x = j;
                if(j < two.size())
                    j = upper_bound(two.begin(), two.end(), two[x]) - two.begin() + t;
                else
                    j = 2 * n;
                if(i < one.size())
                    i = lower_bound(one.begin(), one.end(), two[x]) - one.begin() + t-1;
                else
                    i = 2 * n;
            }
        }
        i -= t;
        j -= t;
        if(sa > sb && one[i] == n-1) {
            sols.insert(pair<int,int>(sa, t));
        }
        else if(sb > sa && two[j] == n-1) {
            sols.insert(pair<int,int>(sb, t));
        }
    }

    cout << sols.size() << '\n';
    for(set< pair<int,int> >::iterator it = sols.begin(); it != sols.end(); it++) {
        cout << (*it).first << ' ' << (*it).second << '\n';
    }
    return 0;
}


using namespace std;
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>

vector<int> one;
vector<int> two;
set< pair<int,int> > sols;

int main() {
    int n, x;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> x;
        if(x == 1) {
            one.push_back(i);
        }
        else {
            two.push_back(i);
        }
    }

    for(int t = 1; t <= n; t++) {
        int i = t-1, j = t-1, sa = 0, sb = 0;
        while(i < one.size() && j < two.size()) {
            if(one[i] < two[j]) {
                sa++;
                x = i;
                i = lower_bound(one.begin(), one.end(), one[x]) - one.begin() + t;
                j = lower_bound(two.begin(), two.end(), one[x]) - two.begin() + t-1;
            }
            else {
                sb++;
                x = j;
                j = lower_bound(two.begin(), two.end(), two[x]) - two.begin() + t;
                i = lower_bound(one.begin(), one.end(), two[x]) - one.begin() + t-1;
            }
        }
        if(j >= two.size()) {
            while(i < one.size()) {
                sa++;
                i = lower_bound(one.begin(), one.end(), one[i]) - one.begin() + t;
            }
        }
        else {
            while(j < two.size()) {
                sb++;
                j = lower_bound(two.begin(), two.end(), two[j]) - two.begin() + t;
            }
        }
        i-=t; j-=t;
        if(sa > sb && i < one.size() && one[i] == n-1) {
            sols.insert(pair<int,int>(sa, t));
        }
        else if(sb > sa && j < two.size() && two[j] == n-1) {
            sols.insert(pair<int,int>(sb, t));
        }
    }

    cout << sols.size() << '\n';
    for(set< pair<int,int> >::iterator it = sols.begin(); it != sols.end(); it++) {
        cout << (*it).first << ' ' << (*it).second << '\n';
    }
    return 0;
}


using namespace std;
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>

vector<int> one;
vector<int> two;
set< pair<int,int> > sols;

int main() {
    int n, x;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> x;
        if(x == 1) {
            one.push_back(i);
        }
        else {
            two.push_back(i);
        }
    }

    for(int t = 1; t <= n; t++) {
        int i = t-1, j = t-1, sa = 0, sb = 0;
        while(i < one.size() && j < two.size()) {
            if(one[i] < two[j]) {
                sa++;
                x = i;
                i = lower_bound(one.begin(), one.end(), one[x]) - one.begin() + t;
                j = lower_bound(two.begin(), two.end(), one[x]) - two.begin() + t-1;
            }
            else {
                sb++;
                x = j;
                j = upper_bound(two.begin(), two.end(), two[x]) - two.begin() + t;
                i = lower_bound(one.begin(), one.end(), two[x]) - one.begin() + t-1;
            }
        }
        if(j >= two.size()) {
            while(i < one.size()) {
                sa++;
                i = lower_bound(one.begin(), one.end(), one[i]) - one.begin() + t;
            }
        }
        else {
            while(j < two.size()) {
                sb++;
                j = lower_bound(two.begin(), two.end(), two[j]) - two.begin() + t;
            }
        }
        i-=t; j-=t;
        if(sa > sb && i < one.size() && one[i] == n-1) {
            sols.insert(pair<int,int>(sa, t));
        }
        else if(sb > sa && j < two.size() && two[j] == n-1) {
            sols.insert(pair<int,int>(sb, t));
        }
    }

    cout << sols.size() << '\n';
    for(set< pair<int,int> >::iterator it = sols.begin(); it != sols.end(); it++) {
        cout << (*it).first << ' ' << (*it).second << '\n';
    }
    return 0;
}


using namespace std;
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>

vector<int> one;
vector<int> two;
set< pair<int,int> > sols;

int main() {
    int n, x;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> x;
        if(x == 1) {
            one.push_back(i);
        }
        else {
            two.push_back(i);
        }
    }

//    for(int i = 0; i < one.size(); i++)
//        cout << one[i] << ' ';
//    cout << '\n';
//    for(int i = 0; i < two.size(); i++)
//        cout << two[i] << ' ';
//    cout << '\n';
//    cout << '\n';

    for(int t = 1; t <= n; t++) {
        int i = t-1, j = t-1, sa = 0, sb = 0;
//        cout << t << '\n';
        while(i < one.size() && j < two.size()) {
//            if(t == 1) cout << one[i] << ' ' << two[j] << '\n';
            if(one[i] < two[j]) {
                sa++;
                x = i;
                i = lower_bound(one.begin(), one.end(), one[x]+1) - one.begin() + t-1;
                j = lower_bound(two.begin(), two.end(), one[x]+1) - two.begin() + t-1;
            }
            else {
                sb++;
                x = j;
                i = lower_bound(one.begin(), one.end(), two[x]+1) - one.begin() + t-1;
                j = lower_bound(two.begin(), two.end(), two[x]+1) - two.begin() + t-1;
            }
        }

        if(i >= one.size()) {
            x = two[j];
            while(x < n+t-1) {
                x+=t;
                sb++;
            }
        }
        else if(j >= two.size()) {
            x = one[i];
            while(x < n+t-1) {
                x+=t;
                sa++;
            }
        }
        if(sa > sb && x == n+t-1) {
            sols.insert(pair<int,int>(sa, t));
        }
        else if(sb > sa && x == n+t-1) {
            sols.insert(pair<int,int>(sb, t));
        }
    }

    cout << sols.size() << '\n';
    for(set< pair<int,int> >::iterator it = sols.begin(); it != sols.end(); it++) {
        cout << (*it).first << ' ' << (*it).second << '\n';
    }
    return 0;
}


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

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vl;

#define getBit(x,i) (x&(1<<i))
#define setBit(x,i) (x|(1<<i))
#define mem(A,N) memset(A,N,sizeof(A))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define rep(i, x, y)  for(int i = x; i < y; ++i)
#define Rep(i, x, y)  for(int i = x; i <= y; ++i)
#define srep(i, x, y) for(int i = x; i > y; --i)
#define sRep(i, x, y) for(int i = x; i >= y; --i)
#define all(v) v.begin(),v.end()
#define Sort(x) sort(x.begin(), x.end())

//const int mod = 1000000007;
//const eps = 1e-9;
//const double = Pi = 3.14159265358979323846;
//const ll llinf  = 0x7FFFFFFFFFFFFFFF;
//const int inf   = 0x7FFFFFFF;

// ***************** End Of Template ********************

vector<int> one;
vector<int> two;
set<ii> sols;
int a[100000];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n;
    cin >> n;
    rep(i, 0, n) {
        cin >> a[i];
        if(a[i] == 1) {
            one.pb(i);
        }
        else {
            two.pb(i);
        }
    }
    Rep(t, 1, n) {
        int i = t-1, j = t-1, sa = 0, sb = 0;
        while(i < one.size() || j < two.size()) {
            if(j >= two.size() || i < one.size() && one[i] < two[j]) {
                sa++;
                i = lower_bound(one.begin(), one.end(), one[i]+1) - one.begin() + t-1;
                j = lower_bound(two.begin(), two.end(), one[i]+1) - two.begin() + t-1;
            }
            else {
                sb++;
                i = lower_bound(one.begin(), one.end(), two[j]+1) - one.begin() + t-1;
                j = lower_bound(two.begin(), two.end(), two[j]+1) - two.begin() + t-1;
            }
        }
        if(sa > sb && i == one.size() + t - 1) {
            sols.insert(ii(sa, t));
        }
        else if(sb > sa && j == two.size() + t - 1) {
            sols.insert(ii(sb, t));
        }
//        cout << "sa " << sa << ", sb " << sb << ", i " << i << ", j " << j << '\n';
    }
    for(auto it = sols.begin(); it != sols.end(); it++) {
        cout << (*it).first << ' ' << (*it).second << '\n';
    }
}


using namespace std;
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>

vector<int> one;
vector<int> two;
set< pair<int,int> > sols;

int main() {
    int n, x;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> x;
        if(x == 1) {
            one.push_back(i);
        }
        else {
            two.push_back(i);
        }
    }

//    for(int i = 0; i < one.size(); i++)
//        cout << one[i] << ' ';
//    cout << '\n';
//    for(int i = 0; i < two.size(); i++)
//        cout << two[i] << ' ';
//    cout << '\n';
//    cout << '\n';

    for(int t = 1; t <= n; t++) {
        int i = t-1, j = t-1, sa = 0, sb = 0;
//        cout << t << '\n';
        while(i < one.size() && j < two.size()) {
//            if(t == 1) cout << one[i] << ' ' << two[j] << '\n';
            if(one[i] < two[j]) {
                sa++;
                x = i;
                i = upper_bound(one.begin(), one.end(), one[x]) - one.begin() + t-1;
                j = upper_bound(two.begin(), two.end(), one[x]+1) - two.begin() + t-1;
            }
            else {
                sb++;
                x = j;
                i = upper_bound(one.begin(), one.end(), two[x]) - one.begin() + t-1;
                j = upper_bound(two.begin(), two.end(), two[x]) - two.begin() + t-1;
            }
        }

        if(i >= one.size()) {
            x = two[j];
            while(x < n+t-1) {
                x+=t;
                sb++;
            }
        }
        else if(j >= two.size()) {
            x = one[i];
            while(x < n+t-1) {
                x+=t;
                sa++;
            }
        }
        if(sa > sb && x == n+t-1) {
            sols.insert(pair<int,int>(sa, t));
        }
        else if(sb > sa && x == n+t-1) {
            sols.insert(pair<int,int>(sb, t));
        }
    }

    cout << sols.size() << '\n';
    for(set< pair<int,int> >::iterator it = sols.begin(); it != sols.end(); it++) {
        cout << (*it).first << ' ' << (*it).second << '\n';
    }
    return 0;
}


using namespace std;
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>

vector<int> one;
vector<int> two;
set< pair<int,int> > sols;

int main() {
    int n, x;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> x;
        if(x == 1) {
            one.push_back(i);
        }
        else {
            two.push_back(i);
        }
    }

    for(int t = 1; t <= n; t++) {
        int i = t-1, j = t-1, sa = 0, sb = 0;
        while(i < one.size() || j < two.size()) {
            if(j >= two.size() || one[i] < two[j]) {
                sa++;
                x = i;
                i = lower_bound(one.begin(), one.end(), one[x]) - one.begin() + t;
                j = lower_bound(two.begin(), two.end(), one[x]) - two.begin() + t-1;
            }
            else {
                sb++;
                x = j;
                i = lower_bound(one.begin(), one.end(), two[x]) - one.begin() + t-1;
                j = upper_bound(two.begin(), two.end(), two[x]) - two.begin() + t;
            }
        }
        i -= t;
        j -= t;
        if(sa > sb && one[i] == n-1) {
            sols.insert(pair<int,int>(sa, t));
        }
        else if(sb > sa && two[j] == n-1) {
            sols.insert(pair<int,int>(sb, t));
        }
    }

    cout << sols.size() << '\n';
    for(set< pair<int,int> >::iterator it = sols.begin(); it != sols.end(); it++) {
        cout << (*it).first << ' ' << (*it).second << '\n';
    }
    return 0;
}


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

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<long long> vl;

#define getBit(x,i) (x&(1<<i))
#define setBit(x,i) (x|(1<<i))
#define mem(A,N) memset(A,N,sizeof(A))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define rep(i, x, y)  for(int i = x; i < y; ++i)
#define Rep(i, x, y)  for(int i = x; i <= y; ++i)
#define srep(i, x, y) for(int i = x; i > y; --i)
#define sRep(i, x, y) for(int i = x; i >= y; --i)
#define all(v) v.begin(),v.end()
#define Sort(x) sort(x.begin(), x.end())

//const int mod = 1000000007;
//const eps = 1e-9;
//const double = Pi = 3.14159265358979323846;
//const ll llinf  = 0x7FFFFFFFFFFFFFFF;
//const int inf   = 0x7FFFFFFF;

// ***************** End Of Template ********************

vector<int> one;
vector<int> two;
set<ii> sols;
int a[100000];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n;
    cin >> n;
    rep(i, 0, n) {
        cin >> a[i];
        if(a[i] == 1) {
            one.pb(i);
        }
        else {
            two.pb(i);
        }
    }
    Rep(t, 1, n) {
        int i = t-1, j = t-1, sa = 0, sb = 0;
        while(i < one.size() || j < two.size()) {
            if(j >= two.size() || i < one.size() && one[i] < two[j]) {
                sa++;
                i = lower_bound(one.begin(), one.end(), one[i]+1) - one.begin() + t-1;
                j = lower_bound(two.begin(), two.end(), one[i]+1) - two.begin() + t-1;
            }
            else {
                sb++;
                i = lower_bound(one.begin(), one.end(), two[j]+1) - one.begin() + t-1;
                j = lower_bound(two.begin(), two.end(), two[j]+1) - two.begin() + t-1;
            }
        }
        if(sa > sb && i == one.size() + t - 1) {
            sols.insert(ii(sa, t));
        }
        else if(sb > sa && j == two.size() + t - 1) {
            sols.insert(ii(sb, t));
        }
//        cout << "sa " << sa << ", sb " << sb << ", i " << i << ", j " << j << '\n';
    }
    for(auto it = sols.begin(); it != sols.end(); it++) {
        cout << (*it).first << ' ' << (*it).second << '\n';
    }
}


using namespace std;
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>

vector<int> one;
vector<int> two;
set< pair<int,int> > sols;

int main() {
    int n, x;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> x;
        if(x == 1) {
            one.push_back(i);
        }
        else {
            two.push_back(i);
        }
    }

    for(int t = 1; t <= n; t++) {
        int i = t-1, j = t-1, sa = 0, sb = 0;
        while(i < one.size() && j < two.size()) {
            if(one[i] < two[j]) {
                sa++;
                x = i;
                i = lower_bound(one.begin(), one.end(), one[x]) - one.begin() + t;
                j = lower_bound(two.begin(), two.end(), one[x]) - two.begin() + t-1;
            }
            else {
                sb++;
                x = j;
                j = lower_bound(two.begin(), two.end(), two[x]) - two.begin() + t;
                i = lower_bound(one.begin(), one.end(), two[x]) - one.begin() + t-1;
            }
        }
        if(j >= two.size()) {
            while(i < one.size()) {
                sa++;
                i = lower_bound(one.begin(), one.end(), one[i]) - one.begin() + t;
            }
        }
        else {
            while(j < two.size()) {
                sb++;
                j = lower_bound(two.begin(), two.end(), two[j]) - two.begin() + t;
            }
        }
        i-=t; j-=t;
        if(sa > sb && one[i] == n-1) {
            sols.insert(pair<int,int>(sa, t));
        }
        else if(sb > sa && two[j] == n-1) {
            sols.insert(pair<int,int>(sb, t));
        }
    }

    cout << sols.size() << '\n';
    for(set< pair<int,int> >::iterator it = sols.begin(); it != sols.end(); it++) {
        cout << (*it).first << ' ' << (*it).second << '\n';
    }
    return 0;
}


using namespace std;
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>

vector<int> one;
vector<int> two;
set< pair<int,int> > sols;

int main() {
    int n, x;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> x;
        if(x == 1) {
            one.push_back(i);
        }
        else {
            two.push_back(i);
        }
    }

    for(int t = 1; t <= n; t++) {
        int i = t-1, j = t-1, sa = 0, sb = 0;
        while(i < one.size() || j < two.size()) {
            if(j >= two.size() || one[i] < two[j]) {
                sa++;
                x = i;
                i = lower_bound(one.begin(), one.end(), one[x]) - one.begin() + t;
                if(j < two.size())
                    j = lower_bound(two.begin(), two.end(), one[x]) - two.begin() + t-1;
                else
                    j = 2 * n;
            }
            else {
                sb++;
                x = j;
                j = upper_bound(two.begin(), two.end(), two[x]) - two.begin() + t;
                if(i < one.size())
                    i = lower_bound(one.begin(), one.end(), two[x]) - one.begin() + t-1;
                else
                    i = 2 * n;
            }
        }
        i -= t;
        j -= t;
        if(sa > sb && one[i] == n-1) {
            sols.insert(pair<int,int>(sa, t));
        }
        else if(sb > sa && two[j] == n-1) {
            sols.insert(pair<int,int>(sb, t));
        }
    }

    cout << sols.size() << '\n';
    for(set< pair<int,int> >::iterator it = sols.begin(); it != sols.end(); it++) {
        cout << (*it).first << ' ' << (*it).second << '\n';
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn=1e5+7;
int suma[maxn],sumb[maxn];
struct node
{
    int first,second;
};
vector<node >p;
bool cmp(const node &a,const node &b)
{
    if(a.first==b.first)return a.second<b.second;
    return a.first<b.first;
}
int n;
int fin;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        suma[i]=suma[i-1];
        sumb[i]=sumb[i-1];
        int d;
        scanf("%d",&d);
        if(d==1)suma[i]++;
        else sumb[i]++;
        fin=d;
    }
    int a,b,tota,totb,fucka,fuckb;
    for(int i=1;i<=n;i++)
    {
        int now=0;
        int x=i;
        bool flag=0;
        tota=totb=0;
        fucka=fuckb=0;
        while((!flag)&&(now!=n))
        {
            int l=now+x,r=n;
            while(l<r)
            {
                int mid=(l+r)/2;
                 a=suma[mid]-suma[now];
                 b=sumb[mid]-sumb[now];
                if(a<x&&b<x)l=mid+1;
                else r=mid;
            }
            l=r;
            a=suma[l]-suma[now];
            b=sumb[l]-sumb[now];
         //   printf("%d %d %d\n",l,a,b);
            if(a>x||b>x||(a==x&&b==x)||(a<x&&b<x))flag=1;
            else
            {
                now=l;
                if(a==x)
                {
                    if(suma[now]==suma[now-1])flag=1;
                    tota++;
                }
                else if(b==x)
                {
                    if(sumb[now]==sumb[now-1])flag=1;
                    totb++;
                }
                else flag=1;

            }
        }
        if((!flag)&&((tota>totb&&fin==1)||(tota<totb&&fin==2))&&now==n)
        {
            p.push_back((node){max(tota,totb),i});
        }
    }
    sort(p.begin(),p.end(),cmp);
    printf("%d\n",p.size());
    for(int i=0;i<p.size();i++)
        printf("%d %d\n",p[i].first,p[i].second);
    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn=1e5+7;
int suma[maxn],sumb[maxn];
struct node
{
    int first,second;
};
vector<node >p;
bool cmp(const node &a,const node &b)
{
    if(a.first==b.first)return a.second<b.second;
    return a.first<b.first;
}
int n;
int fin;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        suma[i]=suma[i-1];
        sumb[i]=sumb[i-1];
        int d;
        scanf("%d",&d);
        if(d==1)suma[i]++;
        else sumb[i]++;
        fin=d;
    }
    int a,b,tota,totb;
    for(int i=1;i<=n;i++)
    {
        int now=0;
        int x=i;
        bool flag=0;
        tota=totb=0;
        while(!flag&&now!=n)
        {
            int l=now+x,r=n;
            while(l<r)
            {
                int mid=(l+r)/2+1;
                 a=suma[mid]-suma[now];
                 b=sumb[mid]-sumb[now];
                if(a>x||b>x||(a==x&&b==x))r=mid-1;
                else l=mid;
            }
            a=suma[l]-suma[now];
            b=sumb[l]-sumb[now];
            if(a>x||b>x||(a==x&&b==x))flag=1;
            else
            {
                now=l;
                if(a==x)
                {
                    if(suma[now]==suma[now-1])flag=1;
                    tota++;
                }
                else if(b==x)
                {
                    if(sumb[now]==sumb[now-1])flag=1;
                    totb++;
                }
                else flag=1;
            }
        }
        if(!flag&&((tota>totb&&fin==1)||(tota<totb&&fin==2)))
        {
            p.push_back((node){max(tota,totb),i});
        }
    }
    sort(p.begin(),p.end(),cmp);
    printf("%d\n",p.size());
    for(int i=0;i<p.size();i++)
        printf("%d %d\n",p[i].first,p[i].second);
    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn=1e5+7;
int suma[maxn],sumb[maxn];
struct node
{
    int first,second;
};
vector<node >p;
bool cmp(const node &a,const node &b)
{
    if(a.first==b.first)return a.second<b.second;
    return a.first<b.first;
}
int n;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        suma[i]=suma[i-1];
        sumb[i]=sumb[i-1];
        int d;
        scanf("%d",&d);
        if(d==1)suma[i]++;
        else sumb[i]++;
    }
    int a,b,tota,totb;
    for(int i=1;i<=n;i++)
    {
        int now=0;
        int x=i;
        bool flag=0;
        tota=totb=0;
        while(!flag&&now!=n)
        {
            int l=now+i,r=n;
            while(l<r)
            {
                int mid=(l+r)/2+1;
                 a=suma[mid]-suma[now];
                 b=sumb[mid]-sumb[now];
                if(a>x||b>x||(a==x&&b==x))r=mid-1;
                else l=mid;
            }
            a=suma[l]-suma[now];
            b=sumb[l]-sumb[now];
            if(a>x||b>x||(a==x&&b==x))flag=1;
            else
            {
                now=l;
                if(a==x)tota++;
                else if(b==x)totb++;
                else flag=1;
            }
        }
        if(!flag&&tota!=totb)
        {
            p.push_back((node){max(tota,totb),i});
        }
    }
    sort(p.begin(),p.end(),cmp);
    printf("%d\n",p.size());
    for(int i=0;i<p.size();i++)
        printf("%d %d\n",p[i].first,p[i].second);
    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
const int maxn=1e5+7;
int suma[maxn],sumb[maxn];
vector<pair<int ,int > >p;
int n;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        suma[i]=suma[i-1];
        sumb[i]=sumb[i-1];
        int d;
        scanf("%d",&d);
        if(d==1)suma[i]++;
        else sumb[i]++;
   //     printf("%d %d\n",suma[i],sumb[i]);
    }
    int a,b,tota,totb;
    for(int i=n;i>=1;i--)
    {
    //    printf("sb%d\n",i);
        int now=0;
        int x=i;
        bool flag=0;
        tota=totb=0;
        while(!flag&&now!=n)
        {
            int l=now+i,r=n;
            while(l<r)
            {
                int mid=(l+r)/2+1;
                 a=suma[mid]-suma[now];
                 b=sumb[mid]-sumb[now];
                if(a>x||b>x||(a==x&&b==x))r=mid-1;
                else l=mid;
            }
            a=suma[l]-suma[now];
            b=sumb[l]-sumb[now];
            if(a>x||b>x||(a==x&&b==x))flag=1;
            else
            {
                now=l;
                if(a==x)tota++;
                else if(b==x)totb++;
                else flag=1;
            }
         //   printf("ssssssssss%d %d %d\n",l,tota,totb);
        }
        if(!flag&&tota!=totb)
        {
            p.push_back(make_pair(max(tota,totb),i));
        }
    }
   // sort(p.begin,p.end(),cmp1);
    printf("%d\n",p.size());
    for(int i=0;i<p.size();i++)
        printf("%d %d\n",p[i].first,p[i].second);
    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn=1e5+7;
int suma[maxn],sumb[maxn];
struct node
{
    int first,second;
};
vector<node >p;
bool cmp(const node &a,const node &b)
{
    if(a.first==b.first)return a.second<b.second;
    return a.first<b.first;
}
int n;
int fin;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        suma[i]=suma[i-1];
        sumb[i]=sumb[i-1];
        int d;
        scanf("%d",&d);
        if(d==1)suma[i]++;
        else sumb[i]++;
        fin=d;
    }
    int a,b,tota,totb,fucka,fuckb;
    for(int i=1;i<=n;i++)
    {
        int now=0;
        int x=i;
        bool flag=0;
        tota=totb=0;
        fucka=fuckb=0;
        while((!flag)&&(now!=n))
        {
            int l=now+x,r=n;
            while(l<r)
            {
                int mid=(l+r)/2+1;
                 a=suma[mid]-suma[now];
                 b=sumb[mid]-sumb[now];
                if(a>x||b>x||(a==x&&b==x))r=mid-1;
                else l=mid;
            }
            l=r;
            a=suma[l]-suma[now];
            b=sumb[l]-sumb[now];
            if(a>x||b>x||(a==x&&b==x)||(a<x&&b<x))flag=1;
            else
            {
                now=l;
                if(a==x)
                {
                    if(suma[now]==suma[now-1])flag=1;
                    tota++;
                }
                else if(b==x)
                {
                    if(sumb[now]==sumb[now-1])flag=1;
                    totb++;
                }
                else flag=1;
            }
        }
        if((!flag)&&((tota>totb&&fin==1)||(tota<totb&&fin==2))&&now==n)
        {
            p.push_back((node){max(tota,totb),i});
        }
    }
    sort(p.begin(),p.end(),cmp);
    printf("%d\n",p.size());
    for(int i=0;i<p.size();i++)
        printf("%d %d\n",p[i].first,p[i].second);
    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn=1e5+7;
int suma[maxn],sumb[maxn];
struct node
{
    int first,second;
};
vector<node >p;
bool cmp(const node &a,const node &b)
{
    if(a.first==b.first)return a.second<b.second;
    return a.first<b.first;
}
int n;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        suma[i]=suma[i-1];
        sumb[i]=sumb[i-1];
        int d;
        scanf("%d",&d);
        if(d==1)suma[i]++;
        else sumb[i]++;
    }
    int a,b,tota,totb;
    for(int i=1;i<=n;i++)
    {
        int last=-1;
        int now=0;
        int x=i;
        bool flag=0;
        tota=totb=0;
        while(!flag&&now!=n)
        {
            int l=now+x,r=n;
            while(l<r)
            {
                int mid=(l+r)/2+1;
                 a=suma[mid]-suma[now];
                 b=sumb[mid]-sumb[now];
                if(a>x||b>x||(a==x&&b==x))r=mid-1;
                else l=mid;
            }
            a=suma[l]-suma[now];
            b=sumb[l]-sumb[now];
            if(a>x||b>x||(a==x&&b==x))flag=1;
            else
            {
                now=l;
                if(a==x)
                {
                    if(suma[now]==suma[now-1])flag=1;
                    tota++,last=1;
                }
                else if(b==x)
                {
                    if(sumb[now]==sumb[now-1])flag=1;
                    totb++,last=2;
                }
                else flag=1;
            }
        }
        if(!flag&&tota!=totb&&((tota>totb&&last==1)||(tota<totb&&last==2))&&now==n)
        {
            p.push_back((node){max(tota,totb),i});
        }
    }
    sort(p.begin(),p.end(),cmp);
    printf("%d\n",p.size());
    for(int i=0;i<p.size();i++)
        printf("%d %d\n",p[i].first,p[i].second);
    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn=1e5+7;
int suma[maxn],sumb[maxn];
struct node
{
    int first,second;
};
vector<node >p;
bool cmp(const node &a,const node &b)
{
    if(a.first==b.first)return a.second<b.second;
    return a.first<b.first;
}
int n;
int fin;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        suma[i]=suma[i-1];
        sumb[i]=sumb[i-1];
        int d;
        scanf("%d",&d);
        if(d==1)suma[i]++;
        else sumb[i]++;
        fin=d;
    }
    int a,b,tota,totb,fucka,fuckb;
    for(int i=1;i<=n;i++)
    {
        int now=0;
        int x=i;
        bool flag=0;
        tota=totb=0;
        fucka=fuckb=0;
        while((!flag)&&(now!=n))
        {
            int l=now+x,r=n;
            while(l<r)
            {
                int mid=(l+r)/2+1;
                 a=suma[mid]-suma[now];
                 b=sumb[mid]-sumb[now];
                if(a>x||b>x||(a==x&&b==x))r=mid-1;
                else l=mid;
            }
            a=suma[l]-suma[now];
            b=sumb[l]-sumb[now];
            if(a>x||b>x||(a==x&&b==x)||(a<x&&b<x))flag=1;
            else
            {
                now=l;
                if(a==x)
                {
                    if(suma[now]==suma[now-1])flag=1;
                    tota++;
                }
                else if(b==x)
                {
                    if(sumb[now]==sumb[now-1])flag=1;
                    totb++;
                }
                else flag=1;
            }
        }
        if((!flag)&&((tota>totb&&fin==1)||(tota<totb&&fin==2))&&now==n)
        {
            p.push_back((node){max(tota,totb),i});
        }
    }
    sort(p.begin(),p.end(),cmp);
    printf("%d\n",p.size());
    for(int i=0;i<p.size();i++)
        printf("%d %d\n",p[i].first,p[i].second);
    return 0;
}


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

struct pp
{
	int first;
	int second;
};

int n, x, y, d;
int a[110000];
pp kq[210000];

bool check(int s, int t, int o)
{
	int u = 0, v = 0;
	int se1 = 0, se2 = 0;
	for(int i = 0; i < n; i++)
	{
		if(a[i] == o) u++;
		else v++;
		if(v == t)
		{
			se2++;
			u = 0; v = 0;
		}
		if(u == t)
		{
			se1++;
			u = 0;
			v = 0;
		}
		if(se2 == s) return false;
		if(se1 == s && i < n - 1) return false;
		//if(se1 == s) cout << se1 << " " << se2 << " " << i << "\n";
	}
	if(se1 != s) return false;
	return true;
}

bool cmp(pp a, pp b)
{
	if((a.first < b.first) || ((a.first == b.first) && (a.second < b.second))) return true;
	else
		return false;
}

void qsort(pp a[], int l, int r)
{
	int i, j;
	pp tam, x;
	i = l;
	j = r;
	x = a[(l + r) / 2];
while(true)
{
	while(a[i].first < x.first || (a[i].first == x.first && a[i].second < x.second)) i++;
	while(a[j].first > x.first || (a[j].first == x.first && a[j].second > x.second)) j--;
	if(i != j)
	{
		tam = a[i];
		a[i]= a[j];
		a[j] = tam;
		i++;
		j--;
	}
	if(i > j) break;
}
if(i < r) qsort(a, i, r);
if(j > l) qsort(a, l, j);
}

int main()
{
	int d = 0;
	//freopen("in.txt", "r", stdin);
	cin >> n;
	x = 0; y = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		if(a[i] == 1) x++;
		else y++;
	}
	int s, t;
	for(int i = 1; i <= x; i++)
		if(x % i == 0)
		{
			s = i; t = x / i;
			if(check(s, t, 1))
			{
				//cout << s << " " << t << "\n";
				d++;
				kq[d - 1].first = s;
				kq[d - 1].second = t;
			}
		}
	for(int i = 1; i <= y; i++)
		if(y % i == 0)
		{
			s = i; t = y / i;
			if(check(s, t, 2))
			{
				d++;
				kq[d - 1].first = s;
				kq[d - 1].second = t;
			}
		}
	sort(kq, kq + d, cmp);
	//qsort(kq, 1, d);
	cout << d << "\n";
	for(int i = 0; i < d; i++)
	{
		cout << kq[i].first << " " << kq[i].second << "\n";
	}
}


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

struct pp
{
	int first;
	int second;
};

int n, x, y, d;
int a[110000];
pp kq[110000];

bool check(int s, int t, int o)
{
	int u = 0, v = 0;
	int se1 = 0, se2 = 0;
	for(int i = 0; i < n; i++)
	{
		if(a[i] == o) u++;
		else v++;
		if(v == t)
		{
			se2++;
			u = 0; v = 0;
		}
		if(u == t)
		{
			se1++;
			u = 0;
			v = 0;
		}
		if(se2 == s) return false;
		if(se1 == s && i < n - 1) return false;
		//if(se1 == s) cout << se1 << " " << se2 << " " << i << "\n";
	}
	if(se1 != s) return false;
	return true;
}

bool cmp(pp a, pp b)
{
	if((a.first < b.first) || (a.first == b.first && a.second < b.second)) return true;
	else
		return false;
}

void qsort(pp a[], int l, int r)
{
	int i, j;
	pp tam, x;
	i = l;
	j = r;
	x = a[(l + r) / 2];
while(true)
{
	while(a[i].first < x.first || (a[i].first == x.first && a[i].second < x.second)) i++;
	while(a[j].first > x.first || (a[j].first == x.first && a[j].second > x.second)) j--;
	if(i != j)
	{
		tam = a[i];
		a[i]= a[j];
		a[j] = tam;
		i++;
		j--;
	}
	if(i > j) break;
}
if(i < r) qsort(a, i, r);
if(j > l) qsort(a, l, j);
}

int main()
{
	int d = 0;
	//freopen("in.txt", "r", stdin);
	cin >> n;
	x = 0; y = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		if(a[i] == 1) x++;
		else y++;
	}
	int s, t;
	for(int i = 1; i <= x; i++)
		if(x % i == 0)
		{
			s = i; t = x / i;
			if(check(s, t, 1))
			{
				//cout << s << " " << t << "\n";
				d++;
				kq[d].first = s;
				kq[d].second = t;
			}
		}
	for(int i = 1; i <= y; i++)
		if(y % i == 0)
		{
			s = i; t = y / i;
			if(check(s, t, 2))
			{
				d++;
				kq[d].first = s;
				kq[d].second = t;
			}
		}
	sort(kq + 1, kq + d + 1, cmp);
	//qsort(kq, 1, d);
	cout << d << "\n";
	for(int i = 1; i <= d; i++)
	{
		cout << kq[i].first << " " << kq[i].second << "\n";
	}
}


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

struct pp
{
	int first;
	int second;
};

int n, x, y, d;
int a[210000];
int b[210000];
int c[210000];
int tm[210000];
pp kq[210000];
bool ok;

bool check(int s, int t, int o)
{
	int u = 0, v = 0;
	int se1 = 0, se2 = 0;
	for(int i = 0; i < n; i++)
	{
		if(a[i] == o) u++;
		else v++;
		if(v == t)
		{
			se2++;
			u = 0; v = 0;
		}
		if(u == t)
		{
			se1++;
			u = 0;
			v = 0;
		}
		if(se2 == s) return false;
		if(se1 == s && i < n - 1) return false;
		//if(se1 == s) cout << se1 << " " << se2 << " " << i << "\n";
	}
	if(se1 != s) return false;
	return true;
}

bool cmp(pp a, pp b)
{
	if((a.first < b.first) || ((a.first == b.first) && (a.second < b.second))) return true;
	else
		return false;
}

void qsort(pp a[], int l, int r)
{
	int i, j;
	pp tam, x;
	i = l;
	j = r;
	x = a[(l + r) / 2];
while(true)
{
	while(a[i].first < x.first || (a[i].first == x.first && a[i].second < x.second)) i++;
	while(a[j].first > x.first || (a[j].first == x.first && a[j].second > x.second)) j--;
	if(i != j)
	{
		tam = a[i];
		a[i]= a[j];
		a[j] = tam;
		i++;
		j--;
	}
	if(i > j) break;
}
if(i < r) qsort(a, i, r);
if(j > l) qsort(a, l, j);
}

int find(int f[], int x, int t)
{
	int l, r, mid, kq;
	l = 0; r = n - x; kq = n - x + 1;
	//mid = (l + r) / 2;
	//int sf = 0;
	while(l <= r)
	{
		//sf++;
		//if(sf > 10) cout << l << " " << r <<"\n";
		//if(sf > 10) return n+1;
		mid = (l + r) / 2;
		if(f[x + mid] - f[x - 1] == t) kq = min(kq, mid);
		if(f[x + mid] - f[x - 1] >= t) r = mid - 1;
		else l = mid + 1;
	}
	return x + kq;
}

int main()
{
	int d = 0;
	//freopen("in.txt", "r", stdin);
	cin >> n;
	x = 0; y = 0;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
		if(a[i] == 1) x++;
		else y++;
	}
	b[0] = 0; c[0] = 0;
	for(int i = 1; i <= n; i++)
	{
		b[i] = b[i-1];
		c[i] = c[i-1];
		if(a[i] == 1) b[i]++;
		else c[i]++;
	}
	int s, t;
	/*int o = a[n - 1];
	if(o == 2)
	{
		tm = b;
		b = c;
		c = tm;
	}*/
	int u, v;
	int s1, s2;
	int k;
	//cout << find(c, 1, 3);
	//return 0;
	for(int t = 1; t <= n; t++)
	{
		ok = true;
		s1 = 0;
		s2 = 0;
		int i = 1;
		//int sf = 0;
		while(i <= n)
		{
			//sf++;
			//if(sf >= 10) return 0;
			u = find(b, i, t);
			v = find(c, i, t);
			if(u > n && v > n)
				{ ok = false; break; }
			k = 0;
			i = u + 1;
			if(u < v) s1++;
			else
				{
					s2++;
					k = 1;
					i = v + 1;
				}
			//cout << u << " " << v << " " << i << "\n";
		}
		//return 0;
		if(ok)
		{
			if(s1 > s2 && k == 0 && a[n] == 1)
			{
				d++;
				kq[d - 1].first = s1;
				kq[d - 1].second = t;
			}
			if(s2 > s1 && k == 1 && a[n] == 2)
			{
				d++;
				kq[d - 1].first = s2;
				kq[d - 1].second = t;
			}
		}
	}
	sort(kq, kq + d, cmp);
	//qsort(kq, 1, d);
	cout << d << "\n";
	for(int i = 0; i < d; i++)
	{
		cout << kq[i].first << " " << kq[i].second << "\n";
	}
	return 0;
}


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

struct pp
{
	int first;
	int second;
};

int n, x, y, d;
int a[210000];
int b[210000];
int c[210000];
int tm[210000];
pp kq[210000];
bool ok;

bool check(int s, int t, int o)
{
	int u = 0, v = 0;
	int se1 = 0, se2 = 0;
	for(int i = 0; i < n; i++)
	{
		if(a[i] == o) u++;
		else v++;
		if(v == t)
		{
			se2++;
			u = 0; v = 0;
		}
		if(u == t)
		{
			se1++;
			u = 0;
			v = 0;
		}
		if(se2 == s) return false;
		if(se1 == s && i < n - 1) return false;
		//if(se1 == s) cout << se1 << " " << se2 << " " << i << "\n";
	}
	if(se1 != s) return false;
	return true;
}

bool cmp(pp a, pp b)
{
	if((a.first < b.first) || ((a.first == b.first) && (a.second < b.second))) return true;
	else
		return false;
}

void qsort(pp a[], int l, int r)
{
	int i, j;
	pp tam, x;
	i = l;
	j = r;
	x = a[(l + r) / 2];
while(true)
{
	while(a[i].first < x.first || (a[i].first == x.first && a[i].second < x.second)) i++;
	while(a[j].first > x.first || (a[j].first == x.first && a[j].second > x.second)) j--;
	if(i != j)
	{
		tam = a[i];
		a[i]= a[j];
		a[j] = tam;
		i++;
		j--;
	}
	if(i > j) break;
}
if(i < r) qsort(a, i, r);
if(j > l) qsort(a, l, j);
}

int find(int f[], int x, int t)
{
	int l, r, mid, kq;
	l = 0; r = n - x; kq = n - x + 1;
	//mid = (l + r) / 2;
	//int sf = 0;
	while(l <= r)
	{
		//sf++;
		//if(sf > 10) cout << l << " " << r <<"\n";
		//if(sf > 10) return n+1;
		mid = (l + r) / 2;
		if(f[x + mid] - f[x - 1] == t) kq = min(kq, mid);
		if(f[x + mid] - f[x - 1] >= t) r = mid - 1;
		else l = mid + 1;
	}
	return x + kq;
}

int main()
{
	int d = 0;
	//freopen("in.txt", "r", stdin);
	cin >> n;
	x = 0; y = 0;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
		if(a[i] == 1) x++;
		else y++;
	}
	b[0] = 0; c[0] = 0;
	for(int i = 1; i <= n; i++)
	{
		b[i] = b[i-1];
		c[i] = c[i-1];
		if(a[i] == 1) b[i]++;
		else c[i]++;
	}
	int s, t;
	/*int o = a[n - 1];
	if(o == 2)
	{
		tm = b;
		b = c;
		c = tm;
	}*/
	int u, v;
	int s1, s2;
	int k;
	//cout << find(c, 1, 3);
	//return 0;
	for(int t = 1; t <= n; t++)
	{
		ok = true;
		s1 = 0;
		s2 = 0;
		int i = 1;
		//int sf = 0;
		while(i <= n)
		{
			//sf++;
			//if(sf >= 10) return 0;
			u = find(b, i, t);
			v = find(c, i, t);
			//cout << u << " " << v << "\n";
			if(u > n && v > n)
				{ ok = false; break; }
			k = 0;
			i = u + 1;
			if(u < v) s1++;
			else
				{
					s2++;
					k = 1;
					i = v + 1;
				}
		}
		//return 0;
		if(ok)
		{
			if(s1 > s2 && k == 0 && a[n - 1] == 1)
			{
				d++;
				kq[d - 1].first = s1;
				kq[d - 1].second = t;
			}
			if(s2 > s1 && k == 1 && a[n - 1] == 2)
			{
				d++;
				kq[d - 1].first = s2;
				kq[d - 1].second = t;
			}
		}
	}
	sort(kq, kq + d, cmp);
	//qsort(kq, 1, d);
	cout << d << "\n";
	for(int i = 0; i < d; i++)
	{
		cout << kq[i].first << " " << kq[i].second << "\n";
	}
	return 0;
}


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

int n, x, y, d;
int a[110000];
int kx[110000], ky[110000];

bool check(int s, int t, int o)
{
	int u = 0, v = 0;
	int se1 = 0, se2 = 0;
	for(int i = 0; i < n; i++)
	{
		if(a[i] == o) u++;
		else v++;
		if(v == t)
		{
			se2++;
			u = 0; v = 0;
		}
		if(u == t)
		{
			se1++;
			u = 0;
			v = 0;
		}
		if(se2 == s) return false;
		if(se1 == s && i < n - 1) return false;
		//if(se1 == s) cout << se1 << " " << se2 << " " << i << "\n";
	}
	if(se1 != s) return false;
	return true;
}

int main()
{
	int d = 0;
	//freopen("in.txt", "r", stdin);
	cin >> n;
	x = 0; y = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		if(a[i] == 1) x++;
		else y++;
	}
	int s, t;
	for(int i = 1; i <= x; i++)
		if(x % i == 0)
		{
			s = i; t = x / i;
			if(check(s, t, 1))
			{
				//cout << s << " " << t << "\n";
				d++;
				kx[d] = s;
				ky[d] = t;
			}
		}
	for(int i = 1; i <= y; i++)
		if(y % i == 0)
		{
			s = i; t = y / i;
			if(check(s, t, 2))
			{
				d++;
				kx[d] = s;
				ky[d] = t;
			}
		}
	cout << d << "\n";
	for(int i = 1; i <= d; i++)
	{
		cout << kx[i] << " " << ky[i] << "\n";
	}
}


#include <stdio.h>
#include <vector>
using namespace std;

class Solution
{
public:
vector<pair<int, int> > TennisGame(vector<int> score, int n)
{
	vector<int> first, second;
	for (int i = 0; i < n; i++)
	{
		if (score[i] == 1) { first.push_back(i); }
		else { second.push_back(i); }
	}

	vector<pair<int, int> > ans;
	for (int i = 1; i <= n; i++)
	{
		int s = CheckTheGames(first, second, i, score[n - 1]);
		if (s != -1) { ans.push_back(pair<int, int>(s, i)); }
	}

	reverse(ans.begin(), ans.end());
	return ans;
}

private:
	int NextRound(vector<int> &score, int l, int r, int limit)
	{
		if (score[r] < limit) { return r + 1; }
		while (l < r)
		{
			int mid = (l + r) / 2;
			if (score[mid] <= limit) { l = mid + 1; }
			else { r = mid; }
		}
		return l;
	}

	int CheckTheGames(vector<int> &first, vector<int> &second, int t, int last_score)
	{
		int n = first.size(), m = second.size();
		int first_win = 0, second_win = 0, last_win = 0;
		for (int first_head = 0, second_head = 0; (first_head < n) || (second_head < m);)
		{
			if ((first_head + t - 1 >= n) && (second_head + t - 1 >= m)) { return -1; }
			if (first_head + t - 1 < n)
			{
				if ((second_head + t - 1 < m) && (second[second_head + t - 1] < first[first_head + t - 1]))
				{
					last_win = 2;
					second_win++;
					first_head = NextRound(first, first_head, n - 1, second[second_head + t - 1]);
					second_head += t;
				} else
				{
					last_win = 1;
					first_win++;
					second_head = NextRound(second, second_head, m - 1, first[first_head + t - 1]);
					first_head += t;
				}
			} else
			{
				first_head = n;
				second_head += t;
				second_win++;
				last_win = 2;
			}
		}

		if (last_score != last_win) { return  -1; }
		else
		{
			if (last_win == 1)
			{
				if (first_win <= second_win) { return -1; }
				return first_win;
			} else
			{
				if (first_win >= second_win) { return -1; }
				return second_win;
			}
		}
	}
};

int main()
{
	int n;
	vector<int> score;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		int temp;
		scanf("%d", &temp);
		score.push_back(temp);
	}

	Solution aa;
	vector<pair<int, int> > ans = aa.TennisGame(score, n);
	printf("%d\n", ans.size());
	for (int i = 0; i < ans.size(); i++)
	{
		printf("%d %d\n", ans[i].first, ans[i].second);
	}
	return 0;
}


#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;

class Solution
{
public:
vector<pair<int, int> > TennisGame(vector<int> score, int n)
{
	vector<int> first, second;
	for (int i = 0; i < n; i++)
	{
		if (score[i] == 1) { first.push_back(i); }
		else { second.push_back(i); }
	}

	vector<pair<int, int> > ans;
	for (int i = 1; i <= n; i++)
	{
		int s = CheckTheGames(first, second, i, score[n - 1]);
		if (s != -1) { ans.push_back(pair<int, int>(s, i)); }
	}

	reverse(ans.begin(), ans.end());
	return ans;
}

private:
	int NextRound(vector<int> &score, int l, int r, int limit)
	{
		if (score[r] < limit) { return r + 1; }
		while (l < r)
		{
			int mid = (l + r) / 2;
			if (score[mid] <= limit) { l = mid + 1; }
			else { r = mid; }
		}
		return l;
	}

	int CheckTheGames(vector<int> &first, vector<int> &second, int t, int last_score)
	{
		int n = first.size(), m = second.size();
		int first_win = 0, second_win = 0, last_win = 0;
		for (int first_head = 0, second_head = 0; (first_head < n) || (second_head < m);)
		{
			if ((first_head + t - 1 >= n) && (second_head + t - 1 >= m)) { return -1; }
			if (first_head + t - 1 < n)
			{
				if ((second_head + t - 1 < m) && (second[second_head + t - 1] < first[first_head + t - 1]))
				{
					last_win = 2;
					second_win++;
					first_head = NextRound(first, first_head, n - 1, second[second_head + t - 1]);
					second_head += t;
				} else
				{
					last_win = 1;
					first_win++;
					second_head = NextRound(second, second_head, m - 1, first[first_head + t - 1]);
					first_head += t;
				}
			} else
			{
				first_head = n;
				second_head += t;
				second_win++;
				last_win = 2;
			}
		}

		if (last_score != last_win) { return  -1; }
		else
		{
			if (last_win == 1)
			{
				if (first_win <= second_win) { return -1; }
				return first_win;
			} else
			{
				if (first_win >= second_win) { return -1; }
				return second_win;
			}
		}
	}
};

int main()
{
	int n;
	vector<int> score;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		int temp;
		scanf("%d", &temp);
		score.push_back(temp);
	}

	Solution aa;
	vector<pair<int, int> > ans = aa.TennisGame(score, n);
	printf("%d\n", ans.size());
	for (int i = 0; i < ans.size(); i++)
	{
		printf("%d %d\n", ans[i].first, ans[i].second);
	}
	return 0;
}


#include <stdio.h>
#include <vector>
using namespace std;

class Solution
{
public:
vector<pair<int, int> > TennisGame(vector<int> score, int n)
{
	vector<int> first, second;
	for (int i = 0; i < n; i++)
	{
		if (score[i] == 1) { first.push_back(i); }
		else { second.push_back(i); }
	}

	vector<pair<int, int> > ans;
	for (int i = 1; i <= n; i++)
	{
		int s = CheckTheGames(first, second, t, score[n - 1]);
		if (s != -1) { ans.push_back(pair<int, int>(s, t)); }
	}
	return ans;
}

private:
	int NextRound(vector<int> &score, int l, int r, int limit)
	{
		if (score[r] < limit) { return r + 1; }
		while (l < r)
		{
			int mid = (l + r) / 2;
			if (score[mid] <= limit) { l = mid + 1; }
			else { r = mid; }
		}
		return l;
	}

	int CheckTheGames(vector<int> &first, vector<int> &second, int t, int last_score)
	{
		int n = first.size(), m = second.size();
		int first_win = 0, second_win = 0, last_win = 0;
		for (int first_head = 0, second_head = 0; (first_head < n) || (second_head < m);)
		{
			if ((first_head + t - 1 >= n) && (second_head + t - 1 >= m)) { return -1; }
			if (first_head + t - 1 < n)
			{
				if ((second_head + t - 1 < m) && (second[second_head + t - 1] < first[first_head + t - 1]))
				{
					last_win = 2;
					second_win++;
					first_head = NextRound(first, first_head, n - 1, second[second_head + t - 1]);
					second_head += t;
				} else
				{
					last_win = 1;
					first_win++;
					second_head = NextRound(second, second_head, m - 1, first[first_head + t - 1]);
					first_head += t;
				}
			} else
			{
				first_head = n;
				second_head += t;
				second_win++;
				last_win = 2;
			}
		}

		if (last_score != last_win) { return  -1; }
		else
		{
			if (last_win == 1)
			{
				if (first_win <= second_win) { return -1; }
				return first_win;
			} else
			{
				if (first_win >= second_win) { return -1; }
				return second_win;
			}
		}
	}
};

int main()
{
	int n;
	vector<int> score;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		int temp;
		scanf("%d", &temp);
		score.push_back(temp);
	}

	Solution aa;
	vector<pair<int, int> > ans = aa.TennisGame(score, n);
	printf("%d\n", ans.size());
	for (int i = 0; i < ans.size(); i++)
	{
		printf("%d %d\n", ans[i].first, ans[i].second);
	}
	return 0;
}