#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first.first
#define yy first.second
#define __V vector
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define oit ostream_iterator
#define mod 1000000007ll
using namespace __gnu_pbds;
using namespace std;
void doin() {
	cin.tie();
	cout.tie();
	ios::sync_with_stdio(0);
////#ifdef LOCAL
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//#endif
}
template<typename T, typename l>
void getv(T& a, int n, l f) {
	a.resize(n);
	for (auto& i : a)
		cin >> i, f(i);
}
template<typename T>
void getv(T& a, int n) {
	a.resize(n);
	for (auto& i : a)
		cin >> i;
}
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef int _I;
typedef pair<_I, _I> pi;
typedef pair<ld, ld> pd;
typedef map<_I, _I> mii;
typedef __V <_I> vi;
typedef __V <char> vc;
typedef __V <ld> vd;
typedef __V <vd> vvd;
typedef __V <pi> vpi;
typedef __V <__V<_I>> vvi;
typedef __V <__V<char>> vvc;
typedef __V <__V<pi>> vvpi;
int n, s, nn;
vi a, pref;
vpi ans;

int setcnt(int d) {
	int gw[2] = { 0, }, sc[2] = { 0, };
	for (int i = 0; i < n; i++)
		if (++gw[a[i] - 1] == d)
			gw[0] = gw[1] = 0, sc[a[i] - 1]++;
	bool f = (sc[0]>sc[1]&&a.back()==2)||(sc[0]<sc[1]&&a.back()==1);
	nn += !(f||gw[0] + gw[1] > 0 || sc[0] == sc[1]);
	return (f||(gw[0] + gw[1]) > 0 || (sc[0] == sc[1])) ? -1 : max(sc[0], sc[1]);
}

int main() {
	doin();
	cin >> n;
	getv(a, n);
	pref.resize(n);
	pref[0] = a[0] - 1;
	for (int i = 1; i < n; i++)
		pref[i] = pref[i - 1] + a[i] - 1;
	s = pref.back();
	s = max(s, n - s);
	for (int d = 1; d * d <= s; d++) {
		if (s % d)
			continue;
		ans.eb(setcnt(d), d);
		if (d * d != s)
			ans.eb(setcnt(s / d), s/d);
	}

	cout << nn << "\n";
	sort(all(ans));
	for (auto i : ans)
		if (i.first != -1)
			cout << i.first << " " << i.second << "\n";
}


#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first.first
#define yy first.second
#define __V vector
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define oit ostream_iterator
#define mod 1000000007ll
using namespace __gnu_pbds;
using namespace std;
void doin() {
	cin.tie();
	cout.tie();
	ios::sync_with_stdio(0);
#ifdef LOCALc
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
template<typename T, typename l>
void getv(T& a, int n, l f) {
	a.resize(n);
	for (auto& i : a)
		cin >> i, f(i);
}
template<typename T>
void getv(T& a, int n) {
	a.resize(n);
	for (auto& i : a)
		cin >> i;
}
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef ll _I;
typedef pair<_I, _I> pi;
typedef pair<ld, ld> pd;
typedef map<_I, _I> mii;
typedef __V <_I> vi;
typedef __V <char> vc;
typedef __V <ld> vd;
typedef __V <vd> vvd;
typedef __V <pi> vpi;
typedef __V <__V<_I>> vvi;
typedef __V <__V<char>> vvc;
typedef __V <__V<pi>> vvpi;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define nxt(x)  pos[x][sc[x]+t]
ll n, a[100100], sum[100100], pos[2][100100], t, s, w, L;
vpi ans;
int gets(int t) {
//	if (t == 26)
//		cout << t << ": ";
	int s = 0, sc[2] = { 0, }, res[2] = { 0, }, r = 0;
	for (; sc[0] + sc[1] < n;) {
		if (nxt(0)!= -1 && (nxt(1) == -1 || nxt(0) < nxt(1))) {
			w = nxt(0), res[0]++,L=0;
//			if(t==26)
//			cout << "0: " << w << "\n";
		} else if (nxt(1)!= -1) {
			w = nxt(1), res[1]++,L=1;
//			if(t==26)
//			cout << "1: " << w << "\n";
		}
		else {
//			if(n == 8946 && (t == 652 || t == 50)) {
//				cout << "B\n";
//				cout << res[0] << " " << res[1] << "\n";
//				cout << w << "\n";
//				cout << L << sc[0] << " " << sc[1] << "\n";
//			}
//			if(t == 15)
//			cout << L <<  " " << res[0] << " " << res[1] << "\n";
			if(res[0]==res[1]||w != n-1
			||res[L]<res[1-L])
			return -1;
//			cout << w << " ( " << sum[w] << " ) " << sc[0] << " " << sc[1] << "]\n";
			return max(res[0], res[1]);
		}
		sc[0] = w-sum[w]+1;
		sc[1] = sum[w];
//		cout << w << " " << res[0] << " " << res[1] << ")\n";
//		cout << w << " ( " << sum[w] << " ) " << sc[0] << " " << sc[1] << "]\n";
//		cout << w << " " << pos[0][sc[0]+1] << " " << pos[1][sc[1]+1] << "}\n";
	}
//	if(n == 8946 && (t == 652 || t == 50)) {
//		cout << res[0] << " " << res[1] << "\n";
//		cout << w << "\n";
//		cout << L << sc[0] << " " << sc[1] << "\n";
//	}
//	if(t == 15)
//	cout << L <<  " " << res[0] << " " << res[1] << "\n";
	if (res[0] == res[1] || w != n - 1 || res[L]<res[1-L])
		return -1;
//	cout<< t << " : " << w << " " << sc[0] << " " << sc[1] << "\n";
	return max(res[0], res[1]);
}

int main() {
	doin();
	memset(pos, -1, sizeof pos);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i], a[i]--;
		sum[i] += a[i];
		sum[i + 1] = sum[i];
		pos[a[i]][a[i] ? sum[i] : (i - sum[i] + 1)] = i;
	}
	w = sum[n - 1] > (n - sum[n - 1]);
	for (t = 1; t <= n; t++) {
		s = gets(t);
		if (s != -1)
			ans.eb(s, t);
	}
	sort(all(ans));
	cout << ans.size() << "\n";
	for (auto i : ans)
		cout << i.first << " " << i.second << "\n";
}


#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first.first
#define yy first.second
#define __V vector
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define oit ostream_iterator
#define mod 1000000007ll
using namespace __gnu_pbds;
using namespace std;
void doin() {
	cin.tie();
	cout.tie();
	ios::sync_with_stdio(0);
#ifdef LOCALc
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
template<typename T, typename l>
void getv(T& a, int n, l f) {
	a.resize(n);
	for (auto& i : a)
		cin >> i, f(i);
}
template<typename T>
void getv(T& a, int n) {
	a.resize(n);
	for (auto& i : a)
		cin >> i;
}
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef ll _I;
typedef pair<_I, _I> pi;
typedef pair<ld, ld> pd;
typedef map<_I, _I> mii;
typedef __V <_I> vi;
typedef __V <char> vc;
typedef __V <ld> vd;
typedef __V <vd> vvd;
typedef __V <pi> vpi;
typedef __V <__V<_I>> vvi;
typedef __V <__V<char>> vvc;
typedef __V <__V<pi>> vvpi;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define nxt(x)  pos[x][sc[x]+t]
ll n, a[100100], sum[100100], pos[2][100100], t, s, w, L;
vpi ans;
int gets(int t) {
//	if (t == 26)
//		cout << t << ": ";
	int s = 0, sc[2] = { 0, }, res[2] = { 0, }, r = 0;
	for (; sc[0] + sc[1] < n;) {
		if (nxt(0)!= -1 && (nxt(1) == -1 || nxt(0) < nxt(1))) {
			w = nxt(0), res[0]++,L=0;
//			if(t==26)
//			cout << "0: " << w << "\n";
		} else if (nxt(1)!= -1) {
			w = nxt(1), res[1]++,L=1;
//			if(t==26)
//			cout << "1: " << w << "\n";
		}
		else {
//			if(n == 8946 && (t == 652 || t == 50)) {
//				cout << "B\n";
//				cout << res[0] << " " << res[1] << "\n";
//				cout << w << "\n";
//				cout << L << sc[0] << " " << sc[1] << "\n";
//			}
//			if(t == 15)
//			cout << L <<  " " << res[0] << " " << res[1] << "\n";
			if(res[0]==res[1]||w != n-1
			||res[L]<res[1-L])
			return -1;
//			cout << w << " ( " << sum[w] << " ) " << sc[0] << " " << sc[1] << "]\n";
			return max(res[0], res[1]);
		}
		sc[0] = w-sum[w]+1;
		sc[1] = sum[w];
//		cout << w << " " << res[0] << " " << res[1] << ")\n";
//		cout << w << " ( " << sum[w] << " ) " << sc[0] << " " << sc[1] << "]\n";
//		cout << w << " " << pos[0][sc[0]+1] << " " << pos[1][sc[1]+1] << "}\n";
	}
//	if(n == 8946 && (t == 652 || t == 50)) {
//		cout << res[0] << " " << res[1] << "\n";
//		cout << w << "\n";
//		cout << L << sc[0] << " " << sc[1] << "\n";
//	}
//	if(t == 15)
//	cout << L <<  " " << res[0] << " " << res[1] << "\n";
	if (res[0] == res[1] || w != n - 1 || res[L]<res[1-L])
		return -1;
//	cout<< t << " : " << w << " " << sc[0] << " " << sc[1] << "\n";
	return max(res[0], res[1]);
}

int main() {
	doin();
	memset(pos, -1, sizeof pos);
	cin >> n;
	int time = 10*clock();
	for (int i = 0; i < n; i++) {
		cin >> a[i], a[i]--;
		sum[i] += a[i];
		sum[i + 1] = sum[i];
		pos[a[i]][a[i] ? sum[i] : (i - sum[i] + 1)] = i;
	}
	w = sum[n - 1] > (n - sum[n - 1]);
	for (t = 1; t <= n; t++) {
		s = gets(t);
		if((time - 10*clock())/CLOCKS_PER_SEC > 18)
			return cout << t, 0;
		if (s != -1)
			ans.eb(s, t);
	}
	sort(all(ans));
	cout << ans.size() << "\n";
	for (auto i : ans)
		cout << i.first << " " << i.second << "\n";
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first.first
#define yy first.second
#define __V vector
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define oit ostream_iterator
#define mod 1000000007ll
using namespace __gnu_pbds;
using namespace std;
void doin() {
	cin.tie();
	cout.tie();
	ios::sync_with_stdio(0);
////#ifdef LOCAL
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//#endif
}
template<typename T, typename l>
void getv(T& a, int n, l f) {
	a.resize(n);
	for (auto& i : a)
		cin >> i, f(i);
}
template<typename T>
void getv(T& a, int n) {
	a.resize(n);
	for (auto& i : a)
		cin >> i;
}
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef int _I;
typedef pair<_I, _I> pi;
typedef pair<ld, ld> pd;
typedef map<_I, _I> mii;
typedef __V <_I> vi;
typedef __V <char> vc;
typedef __V <ld> vd;
typedef __V <vd> vvd;
typedef __V <pi> vpi;
typedef __V <__V<_I>> vvi;
typedef __V <__V<char>> vvc;
typedef __V <__V<pi>> vvpi;
int n, s, nn;
vi a, pref;
vpi ans;

int setcnt(int d) {
	int gw[2] = { 0, }, sc[2] = { 0, };
	for (int i = 0; i < n; i++)
		if (++gw[a[i] - 1] == d)
			gw[0] = gw[1] = 0, sc[a[i] - 1]++;
	nn += !(gw[0] + gw[1] > 0 || sc[0] == sc[1]);
	return ((gw[0] + gw[1]) > 0 || (sc[0] == sc[1])) ? -1 : max(sc[0], sc[1]);
}

int main() {
	doin();
	cin >> n;
	getv(a, n);
	pref.resize(n);
	pref[0] = a[0] - 1;
	for (int i = 1; i < n; i++)
		pref[i] = pref[i - 1] + a[i] - 1;
	s = pref.back();
	s = max(s, n - s);
	for (int d = 1; d * d <= s; d++) {
		if (s % d)
			continue;
		ans.eb(setcnt(d), d);
		if (d * d != s)
			ans.eb(setcnt(s / d), s/d);
	}

	cout << nn << "\n";
	sort(all(ans));
	for (auto i : ans)
		if (i.first != -1)
			cout << i.first << " " << i.second << "\n";
}


#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first.first
#define yy first.second
#define __V vector
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define oit ostream_iterator
#define mod 1000000007ll
using namespace __gnu_pbds;
using namespace std;
void doin() {
	cin.tie();
	cout.tie();
	ios::sync_with_stdio(0);
#ifdef LOCALc
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
template<typename T, typename l>
void getv(T& a, int n, l f) {
	a.resize(n);
	for (auto& i : a)
		cin >> i, f(i);
}
template<typename T>
void getv(T& a, int n) {
	a.resize(n);
	for (auto& i : a)
		cin >> i;
}
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef ll _I;
typedef pair<_I, _I> pi;
typedef pair<ld, ld> pd;
typedef map<_I, _I> mii;
typedef __V <_I> vi;
typedef __V <char> vc;
typedef __V <ld> vd;
typedef __V <vd> vvd;
typedef __V <pi> vpi;
typedef __V <__V<_I>> vvi;
typedef __V <__V<char>> vvc;
typedef __V <__V<pi>> vvpi;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define nxt(x)  pos[x][sc[x]+t]
ll n, a[100100], sum[100100], pos[2][100100], t, s, w, L;
vpi ans;
int gets(int t) {
//	if (t == 26)
//		cout << t << ": ";
	int s = 0, sc[2] = { 0, }, res[2] = { 0, }, r = 0;
	for (; sc[0] + sc[1] < n;) {
		if (nxt(0)!= -1 && (nxt(1) == -1 || nxt(0) < nxt(1))) {
			w = nxt(0), res[0]++,L=0;
//			if(t==26)
//			cout << "0: " << w << "\n";
		} else if (nxt(1)!= -1) {
			w = nxt(1), res[1]++,L=1;
//			if(t==26)
//			cout << "1: " << w << "\n";
		}
		else {
//			if(n == 8946 && (t == 652 || t == 50)) {
//				cout << "B\n";
//				cout << res[0] << " " << res[1] << "\n";
//				cout << w << "\n";
//				cout << L << sc[0] << " " << sc[1] << "\n";
//			}
//			if(t == 15)
//			cout << L <<  " " << res[0] << " " << res[1] << "\n";
			if(res[0]==res[1]||w != n-1
			||res[L]<res[1-L])
			return -1;
//			cout << w << " ( " << sum[w] << " ) " << sc[0] << " " << sc[1] << "]\n";
			return max(res[0], res[1]);
		}
		sc[0] = w-sum[w]+1;
		sc[1] = sum[w];
//		cout << w << " " << res[0] << " " << res[1] << ")\n";
//		cout << w << " ( " << sum[w] << " ) " << sc[0] << " " << sc[1] << "]\n";
//		cout << w << " " << pos[0][sc[0]+1] << " " << pos[1][sc[1]+1] << "}\n";
	}
//	if(n == 8946 && (t == 652 || t == 50)) {
//		cout << res[0] << " " << res[1] << "\n";
//		cout << w << "\n";
//		cout << L << sc[0] << " " << sc[1] << "\n";
//	}
//	if(t == 15)
//	cout << L <<  " " << res[0] << " " << res[1] << "\n";
	if (res[0] == res[1] || w != n - 1 || res[L]<res[1-L])
		return -1;
//	cout<< t << " : " << w << " " << sc[0] << " " << sc[1] << "\n";
	return max(res[0], res[1]);
}

int main() {
	doin();
	memset(pos, -1, sizeof pos);
	cin >> n;
	int time = 10*clock();
	for (int i = 0; i < n; i++) {
		cin >> a[i], a[i]--;
		sum[i] += a[i];
		sum[i + 1] = sum[i];
		pos[a[i]][a[i] ? sum[i] : (i - sum[i] + 1)] = i;
	}
	w = sum[n - 1] > (n - sum[n - 1]);
	for (t = 1; t <= n; t++) {
		s = gets(t);
		if((t - 10*clock())/CLOCKS_PER_SEC > 18)
			return cout << t, 0;
		if (s != -1)
			ans.eb(s, t);
	}
	sort(all(ans));
	cout << ans.size() << "\n";
	for (auto i : ans)
		cout << i.first << " " << i.second << "\n";
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first.first
#define yy first.second
#define __V vector
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define oit ostream_iterator
#define mod 1000000007ll
using namespace __gnu_pbds;
using namespace std;
void doin() {
	cin.tie();
	cout.tie();
	ios::sync_with_stdio(0);
////#ifdef LOCAL
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//#endif
}
template<typename T, typename l>
void getv(T& a, int n, l f) {
	a.resize(n);
	for (auto& i : a)
		cin >> i, f(i);
}
template<typename T>
void getv(T& a, int n) {
	a.resize(n);
	for (auto& i : a)
		cin >> i;
}
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef int _I;
typedef pair<_I, _I> pi;
typedef pair<ld, ld> pd;
typedef map<_I, _I> mii;
typedef __V <_I> vi;
typedef __V <char> vc;
typedef __V <ld> vd;
typedef __V <vd> vvd;
typedef __V <pi> vpi;
typedef __V <__V<_I>> vvi;
typedef __V <__V<char>> vvc;
typedef __V <__V<pi>> vvpi;
int n, s, nn;
vi a, pref;
vpi ans;

int setcnt(int d) {
	int gw[2] = { 0, }, sc[2] = { 0, }, lw;
	for (int i = 0; i < n; i++) {
		if (++gw[a[i] - 1] == d)
			gw[0] = gw[1] = 0, sc[a[i] - 1]++,
		lw = a[i]-1;
	}//
	if(gw[0]||gw[1]||sc[lw]!=max(sc[0],sc[1])||sc[0]==sc[1])
		return -1;
	nn++;
	return max(sc[0], sc[1]);
}

int main() {
	doin();
	cin >> n;
	getv(a, n);
	pref.resize(n);
	pref[0] = a[0] - 1;
	for (int i = 1; i < n; i++)
		pref[i] = pref[i - 1] + a[i] - 1;
	s = pref.back();
	s = max(s, n - s);
	for (int d = 1; d * d <= s; d++) {
		if (s % d)
			continue;
		ans.eb(setcnt(d), d);
		if (d * d != s)
			ans.eb(setcnt(s / d), s / d);
	}

	cout << nn << "\n";
	sort(all(ans));
	for (auto i : ans)
		if (i.first != -1)
			cout << i.first << " " << i.second << "\n";
}


#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first.first
#define yy first.second
#define __V vector
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define oit ostream_iterator
#define mod 1000000007ll
using namespace __gnu_pbds;
using namespace std;
void doin() {
	cin.tie();
	cout.tie();
	ios::sync_with_stdio(0);
#ifdef LOCALc
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
template<typename T, typename l>
void getv(T& a, int n, l f) {
	a.resize(n);
	for (auto& i : a)
		cin >> i, f(i);
}
template<typename T>
void getv(T& a, int n) {
	a.resize(n);
	for (auto& i : a)
		cin >> i;
}
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef ll _I;
typedef pair<_I, _I> pi;
typedef pair<ld, ld> pd;
typedef map<_I, _I> mii;
typedef __V <_I> vi;
typedef __V <char> vc;
typedef __V <ld> vd;
typedef __V <vd> vvd;
typedef __V <pi> vpi;
typedef __V <__V<_I>> vvi;
typedef __V <__V<char>> vvc;
typedef __V <__V<pi>> vvpi;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define nxt(x)  pos[x][sc[x]+t]
ll n, a[100100], sum[100100], pos[2][100100], t, s, w, L;
vpi ans;
int gets(int t) {
//	if (t == 26)
//		cout << t << ": ";
	int s = 0, sc[2] = { 0, }, res[2] = { 0, }, r = 0;
	for (; sc[0] + sc[1] < n;) {
		if (nxt(0)!= -1 && (nxt(1) == -1 || nxt(0) < nxt(1))) {
			w = nxt(0), res[0]++,L=0;
//			if(t==26)
//			cout << "0: " << w << "\n";
		} else if (nxt(1)!= -1) {
			w = nxt(1), res[1]++,L=1;
//			if(t==26)
//			cout << "1: " << w << "\n";
		}
		else {
//			if(n == 8946 && (t == 652 || t == 50)) {
//				cout << "B\n";
//				cout << res[0] << " " << res[1] << "\n";
//				cout << w << "\n";
//				cout << L << sc[0] << " " << sc[1] << "\n";
//			}
//			if(t == 15)
//			cout << L <<  " " << res[0] << " " << res[1] << "\n";
			if(res[0]==res[1]||w != n-1
			||res[L]<res[1-L])
			return -1;
//			cout << w << " ( " << sum[w] << " ) " << sc[0] << " " << sc[1] << "]\n";
			return max(res[0], res[1]);
		}
		sc[0] = w-sum[w]+1;
		sc[1] = sum[w];
//		cout << w << " " << res[0] << " " << res[1] << ")\n";
//		cout << w << " ( " << sum[w] << " ) " << sc[0] << " " << sc[1] << "]\n";
//		cout << w << " " << pos[0][sc[0]+1] << " " << pos[1][sc[1]+1] << "}\n";
	}
//	if(n == 8946 && (t == 652 || t == 50)) {
//		cout << res[0] << " " << res[1] << "\n";
//		cout << w << "\n";
//		cout << L << sc[0] << " " << sc[1] << "\n";
//	}
//	if(t == 15)
//	cout << L <<  " " << res[0] << " " << res[1] << "\n";
	if (res[0] == res[1] || w != n - 1 || res[L]<res[1-L])
		return -1;
//	cout<< t << " : " << w << " " << sc[0] << " " << sc[1] << "\n";
	return max(res[0], res[1]);
}

int main() {
	doin();
	memset(pos, -1, sizeof pos);
	int time = clock();
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i], a[i]--;
		sum[i] += a[i];
		sum[i + 1] = sum[i];
		pos[a[i]][a[i] ? sum[i] : (i - sum[i] + 1)] = i;
	}
	w = sum[n - 1] > (n - sum[n - 1]);
	for (t = 1; t <= n; t++) {
		s = gets(t);
		if((clock() - time)/CLOCKS_PER_SEC >= 1)
			return cout << t, -1;
		if (s != -1)
			ans.eb(s, t);
	}
	sort(all(ans));
	cout << ans.size() << "\n";
	for (auto i : ans)
		cout << i.first << " " << i.second << "\n";
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first.first
#define yy first.second
#define __V vector
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define oit ostream_iterator
#define mod 1000000007ll
using namespace __gnu_pbds;
using namespace std;
void doin() {
	cin.tie();
	cout.tie();
	ios::sync_with_stdio(0);
#ifdef LOCALc
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
template<typename T, typename l>
void getv(T& a, int n, l f) {
	a.resize(n);
	for (auto& i : a)
		cin >> i, f(i);
}
template<typename T>
void getv(T& a, int n) {
	a.resize(n);
	for (auto& i : a)
		cin >> i;
}
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef ll _I;
typedef pair<_I, _I> pi;
typedef pair<ld, ld> pd;
typedef map<_I, _I> mii;
typedef __V <_I> vi;
typedef __V <char> vc;
typedef __V <ld> vd;
typedef __V <vd> vvd;
typedef __V <pi> vpi;
typedef __V <__V<_I>> vvi;
typedef __V <__V<char>> vvc;
typedef __V <__V<pi>> vvpi;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define nxt(x)  pos[x][sc[x]+t]
ll n, a[100100], sum[100100], pos[2][100100], t, s, w, L;
vpi ans;
int gets(int t) {
//	if (t == 26)
//		cout << t << ": ";
	int s = 0, sc[2] = { 0, }, res[2] = { 0, }, r = 0;
	for (r = 0; sc[0] + sc[1] < n; r += t) {
		if (nxt(0)!= -1 && (nxt(1) == -1 || nxt(0) < nxt(1))) {
			w = nxt(0), res[0]++,L=0;
//			if(t==26)
//			cout << "0: " << w << "\n";
		} else if (nxt(1)!= -1) {
			w = nxt(1), res[1]++,L=1;
//			if(t==26)
//			cout << "1: " << w << "\n";
		}
		else {
//			if(n == 8946 && (t == 652 || t == 50)) {
//				cout << "B\n";
//				cout << res[0] << " " << res[1] << "\n";
//				cout << w << "\n";
//				cout << L << sc[0] << " " << sc[1] << "\n";
//			}
//			if(t == 15)
//			cout << L <<  " " << res[0] << " " << res[1] << "\n";
			if(res[0]==res[1]||w != n-1
			||res[L]<res[1-L])
			return -1;
//			cout << w << " ( " << sum[w] << " ) " << sc[0] << " " << sc[1] << "]\n";
			return max(res[0], res[1]);
		}
		sc[0] = w-sum[w]+1;
		sc[1] = sum[w];
//		cout << w << " " << res[0] << " " << res[1] << ")\n";
//		cout << w << " ( " << sum[w] << " ) " << sc[0] << " " << sc[1] << "]\n";
//		cout << w << " " << pos[0][sc[0]+1] << " " << pos[1][sc[1]+1] << "}\n";
	}
//	if(n == 8946 && (t == 652 || t == 50)) {
//		cout << res[0] << " " << res[1] << "\n";
//		cout << w << "\n";
//		cout << L << sc[0] << " " << sc[1] << "\n";
//	}
//	if(t == 15)
//	cout << L <<  " " << res[0] << " " << res[1] << "\n";
	if (res[0] == res[1] || w != n - 1 || res[L]<res[1-L])
		return -1;
//	cout<< t << " : " << w << " " << sc[0] << " " << sc[1] << "\n";
	return max(res[0], res[1]);
}

int main() {
	doin();
	memset(pos, -1, sizeof pos);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i], a[i]--;
		sum[i] += a[i];
		sum[i + 1] = sum[i];
		pos[a[i]][a[i] ? sum[i] : (i - sum[i] + 1)] = i;
	}
	w = sum[n - 1] > (n - sum[n - 1]);
	for (t = 1; t <= n; t++) {
		s = gets(t);
		if (s != -1)
			ans.eb(s, t);
	}
	sort(all(ans));
	cout << ans.size() << "\n";
	for (auto i : ans)
		cout << i.first << " " << i.second << "\n";
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first.first
#define yy first.second
#define __V vector
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define oit ostream_iterator
#define mod 1000000007ll
using namespace __gnu_pbds;
using namespace std;
void doin() {
	cin.tie();
	cout.tie();
	ios::sync_with_stdio(0);
#ifdef LOCALc
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
template<typename T, typename l>
void getv(T& a, int n, l f) {
	a.resize(n);
	for (auto& i : a)
		cin >> i, f(i);
}
template<typename T>
void getv(T& a, int n) {
	a.resize(n);
	for (auto& i : a)
		cin >> i;
}
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef ll _I;
typedef pair<_I, _I> pi;
typedef pair<ld, ld> pd;
typedef map<_I, _I> mii;
typedef __V <_I> vi;
typedef __V <char> vc;
typedef __V <ld> vd;
typedef __V <vd> vvd;
typedef __V <pi> vpi;
typedef __V <__V<_I>> vvi;
typedef __V <__V<char>> vvc;
typedef __V <__V<pi>> vvpi;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define nxt(x)  pos[x][sc[x]+t]
ll n, a[10100], sum[10100], pos[2][10100], t, s, w, L;
vpi ans;
int gets(int t) {
//	if (t == 26)
//		cout << t << ": ";
	int s = 0, sc[2] = { 0, }, res[2] = { 0, }, r = 0;
	for (r = 0; sc[0] + sc[1] < n; r += t) {
		if (nxt(0)!= -1 && (nxt(1) == -1 || nxt(0) < nxt(1))) {
			w = nxt(0), res[0]++,L=0;
//			if(t==26)
//			cout << "0: " << w << "\n";
		} else if (nxt(1)!= -1) {
			w = nxt(1), res[1]++,L=1;
//			if(t==26)
//			cout << "1: " << w << "\n";
		}
		else {
			if(res[0]==res[1]||w != n-1
			||sc[L]<sc[1-L])
			return -1;
//			cout << w << " ( " << sum[w] << " ) " << sc[0] << " " << sc[1] << "]\n";
			return max(res[0], res[1]);
		}
		sc[0] = w-sum[w]+1;
		sc[1] = sum[w];
//		cout << w << " " << res[0] << " " << res[1] << ")\n";
//		cout << w << " ( " << sum[w] << " ) " << sc[0] << " " << sc[1] << "]\n";
//		cout << w << " " << pos[0][sc[0]+1] << " " << pos[1][sc[1]+1] << "}\n";
	}
	if (res[0] == res[1] || w != n - 1 || sc[L] < sc[1 - L])
		return -1;
//	cout<< t << " : " << w << " " << sc[0] << " " << sc[1] << "\n";
	return max(res[0], res[1]);
}

int main() {
	doin();
	memset(pos, -1, sizeof pos);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i], a[i]--;
		sum[i] += a[i];
		sum[i + 1] = sum[i];
		pos[a[i]][a[i] ? sum[i] : (i - sum[i] + 1)] = i;
	}
	w = sum[n - 1] > (n - sum[n - 1]);
	for (t = 1; t <= n; t++) {
		s = gets(t);
		if (s != -1)
			ans.eb(s, t);
	}
	sort(all(ans));
	cout << ans.size() << "\n";
	for (auto i : ans)
		cout << i.first << " " << i.second << "\n";
}


#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpii vector<pii>
#define wgraph vector<vpii>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(), c.end()
#define mp(x, y) make_pair(x, y)
#define mem(a, val) memset(a, val, sizeof(a))
#define eb emplace_back
#define f first
#define s second

using namespace std;
int main()
{
    std::ios::sync_with_stdio(false);
    int T;
    cin >> T;
    // cin.ignore(); must be there when using getline(cin, s)
    vi v(T, 0);
    for (int t = 0; t < T; t++)
    {
        cin >> v[t];
    }
    vi uno(T, 0);
    vi dos(T, 0);
    for (int i = 0; i < T; i++)
    {
        if (i > 0)
        {
            uno[i + 1] = uno[i];
            dos[i + 1] = dos[i];
        }
        if (v[i] == 1)
        {
            uno[i + 1] += 1;
        }
        else
        {
            dos[i + 1] += 1;
        }
    }
    vpii resp;
    for (int t = 1; t <= T; t++)
    {
        int unos = 0, doss = 0;
        int neta = 0;
        while (neta < T)
        {
            int lo = neta + 1;
            int hi = min(lo + (2 * t), T);
            while (hi > lo)
            {
                int mid = (hi + lo) / 2;
                if (uno[mid] - uno[neta] >= t or dos[mid] - dos[neta] >= t)
                {
                    hi = mid;
                }
                else
                {
                    lo = mid + 1;
                }
            }
            // printf("%d  %d/%d %d/%d\n", t, uno[lo], uno[neta], dos[lo], dos[neta]);
            if (uno[lo] - uno[neta] == t)
            {
                unos++;
            }
            else if (dos[lo] - dos[neta] == t)
            {
                doss++;
            }
            else
            {
                break;
            }
            neta = lo;
        }
        if (neta == T)
        {
            if (v[T - 1] == 1 and unos > doss)
            {
                resp.push_back(mp(unos, t));
            }
            if (v[T - 1] == 1 and doss > unos)
            {
                resp.push_back(mp(doss, t));
            }
        }

        // cout << t << ' ' << unos << ' ' << doss << ' ' << neta << endl;
    }
    sort(resp.begin(), resp.end());
    cout << resp.size() << endl;
    for (auto aa : resp)
    {
        cout << aa.f << ' ' << aa.s << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpii vector<pii>
#define wgraph vector<vpii>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(), c.end()
#define mp(x, y) make_pair(x, y)
#define mem(a, val) memset(a, val, sizeof(a))
#define eb emplace_back
#define f first
#define s second

using namespace std;
int main()
{
    std::ios::sync_with_stdio(false);
    int T;
    cin >> T;
    // cin.ignore(); must be there when using getline(cin, s)
    vi v(T, 0);
    for (int t = 0; t < T; t++)
    {
        cin >> v[t];
    }
    vi uno(T+1, 0);
    vi dos(T+1, 0);
    for (int i = 0; i < T; i++)
    {
        if (i > 0)
        {
            uno[i + 1] = uno[i];
            dos[i + 1] = dos[i];
        }
        if (v[i] == 1)
        {
            uno[i + 1] += 1;
        }
        else
        {
            dos[i + 1] += 1;
        }
    }
    vpii resp;
    for (int t = 1; t <= T; t++)
    {
        int unos = 0, doss = 0;
        int neta = 0;
        while (neta < T)
        {
            int lo = neta + 1;
            int hi = min(lo + (2 * t), T);
            while (hi > lo)
            {
                int mid = (hi + lo) / 2;
                if (uno[mid] - uno[neta] >= t or dos[mid] - dos[neta] >= t)
                {
                    hi = mid;
                }
                else
                {
                    lo = mid + 1;
                }
            }
            // printf("%d  %d/%d %d/%d\n", t, uno[lo], uno[neta], dos[lo], dos[neta]);
            if (uno[lo] - uno[neta] == t)
            {
                unos++;
            }
            else if (dos[lo] - dos[neta] == t)
            {
                doss++;
            }
            else
            {
                break;
            }
            neta = lo;
        }
        if (neta == T)
        {
            if (v[T - 1] == 1 and unos > doss)
            {
                resp.push_back(mp(unos, t));
            }
            if (v[T - 1] == 1 and doss > unos)
            {
                resp.push_back(mp(doss, t));
            }
        }

        // cout << t << ' ' << unos << ' ' << doss << ' ' << neta << endl;
    }
    sort(resp.begin(), resp.end());
    cout << resp.size() << endl;
    for (auto aa : resp)
    {
        cout << aa.f << ' ' << aa.s << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpii vector<pii>
#define wgraph vector<vpii>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(), c.end()
#define mp(x, y) make_pair(x, y)
#define mem(a, val) memset(a, val, sizeof(a))
#define eb emplace_back
#define f first
#define s second

using namespace std;
int main()
{
    std::ios::sync_with_stdio(false);
    int T;
    cin >> T;
    // cin.ignore(); must be there when using getline(cin, s)
    vi v(T, 0);
    for (int t = 0; t < T; t++)
    {
        cin >> v[t];
    }
    vi uno(T, 0);
    vi dos(T, 0);
    for (int i = 0; i < T; i++)
    {
        if (i > 0)
        {
            uno[i + 1] = uno[i];
            dos[i + 1] = dos[i];
        }
        if (v[i] == 1)
        {
            uno[i + 1] += 1;
        }
        else
        {
            dos[i + 1] += 1;
        }
    }
    vpii resp;
    for (int t = 1; t < T; t++)
    {
        int unos = 0, doss = 0;
        int neta = 0;
        while (neta <= T)
        {
            int lo = neta;
            int hi = min(lo + (2 * t), T);
            while (hi > lo)
            {
                int mid = (hi + lo) / 2;
                if (uno[mid] - uno[neta] >= t or dos[mid] - dos[neta] >= t)
                {
                    hi = mid;
                }
                else
                {
                    lo = mid + 1;
                }
            }
            // printf("%d  %d/%d %d/%d\n", t, uno[lo], uno[neta], dos[lo], dos[neta]);
            if (uno[lo] - uno[neta] == t)
            {
                unos++;
            }
            else if (dos[lo] - dos[neta] == t)
            {
                doss++;
            }
            else
            {
                break;
            }
            neta = lo + 1;
        }
        if (neta == T + 1)
        {
            if (v[T - 1] == 1 and unos > doss)
            {
                resp.push_back(mp(unos, t));
            }
            if (v[T - 1] == 1 and doss > unos)
            {
                resp.push_back(mp(doss, t));
            }
        }

        // cout << t << ' ' << unos << ' ' << doss << ' ' << neta << endl;
    }
    sort(resp.begin(), resp.end());
    cout << resp.size() << endl;
    for (auto aa : resp)
    {
        cout << aa.f << ' ' << aa.s << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpii vector<pii>
#define wgraph vector<vpii>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(), c.end()
#define mp(x, y) make_pair(x, y)
#define mem(a, val) memset(a, val, sizeof(a))
#define eb emplace_back
#define f first
#define s second

using namespace std;
int main()
{
    std::ios::sync_with_stdio(false);
    int T;
    cin >> T;
    // cin.ignore(); must be there when using getline(cin, s)
    vi v(T, 0);
    for (int t = 0; t < T; t++)
    {
        cin >> v[t];
    }
    vi uno(T+1, 0);
    vi dos(T+1, 0);
    for (int i = 0; i < T; i++)
    {
        if (i > 0)
        {
            uno[i + 1] = uno[i];
            dos[i + 1] = dos[i];
        }
        if (v[i] == 1)
        {
            uno[i + 1] += 1;
        }
        else
        {
            dos[i + 1] += 1;
        }
    }
    vpii resp;
    for (int t = 1; t <= T; t++)
    {
        int unos = 0, doss = 0;
        int neta = 0;
        while (neta < T)
        {
            int lo = neta + 1;
            int hi = min(lo + (2 * t), T);
            while (hi > lo)
            {
                int mid = (hi + lo) / 2;
                if (uno[mid] - uno[neta] >= t or dos[mid] - dos[neta] >= t)
                {
                    hi = mid;
                }
                else
                {
                    lo = mid + 1;
                }
            }
            // printf("%d  %d/%d %d/%d\n", t, uno[lo], uno[neta], dos[lo], dos[neta]);
            if (uno[lo] - uno[neta] == t)
            {
                unos++;
            }
            else if (dos[lo] - dos[neta] == t)
            {
                doss++;
            }
            else
            {
                break;
            }
            neta = lo;
        }
        if (neta == T)
        {
            if (v[T - 1] == 1 and unos > doss)
            {
                resp.push_back(mp(unos, t));
            }
            if (v[T - 1] == 2 and doss > unos)
            {
                resp.push_back(mp(doss, t));
            }
        }

        // cout << t << ' ' << unos << ' ' << doss << ' ' << neta << endl;
    }
    sort(resp.begin(), resp.end());
    cout << resp.size() << endl;
    for (auto aa : resp)
    {
        cout << aa.f << ' ' << aa.s << endl;
    }
    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef map<ll,ll> mll;
typedef vector<bool> vb;

#define y0 sdkfaslhagaklsldk
#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define endl "\n"
#define prina(arr,dau,cuoi) FTB(mmczmp,dau,cuoi)cout<<arr[mmczmp]<<" ";cout<<endl;
#define debug cout<<"debug\n"
#define pb push_back
#define pbg(ke,u,v) ke[u].pb(v);ke[v].pb(u);
#define fi first
#define se second
#define pi acos(-1.0)
#define lbnd(f,s,gt) lower_bound(f,s,gt)
#define ubnd(f,s,gt) upper_bound(f,s,gt)
#define all(s) s.begin(),s.end()
#define bitcount(n) __builtin_popcountll(n)
#define FTB(i,a,b) for(ll i=a,_b=b;i<=_b;i++)
#define FT(i,a,b) for(ll i=a,_b=b;i<_b;i++)
#define FGB(i,a,b) for(ll i=a,_b=b;i>=_b;i--)
#define FG(i,a,b) for(ll i=a,_b=b;i>_b;i--)
/////////////////////////////////////////////

ll n,a[100005],s[3],pr[3][100005],win,los,tmp;
vi vt[3];
vii res;

void cal(ll x){
    ll vt=0;
    s[1]=s[2]=0;
    while(vt<n){
        ll vw=lbnd(pr[win]+vt,pr[win]+n+1,pr[win][vt]+x)-pr[win];
        ll vl=lbnd(pr[los]+vt,pr[los]+n+1,pr[los][vt]+x)-pr[los];
        if(vw<vl){
            s[win]++;
            vt=vw;
        }
        else{
            s[los]++;
            vt=vl;
        }
    }
    if(vt==n&&s[win]>s[los]) res.pb({s[win],x});

}

void Solve(){
    cin>>n;
    FTB(i,1,n){
        cin>>a[i],s[a[i]]++;
        pr[1][i]=pr[1][i-1];
        pr[2][i]=pr[2][i-1];
        pr[a[i]][i]++;
    }
    win=a[n],los=3-a[n];
    tmp=s[win];
    FGB(i,tmp,1) cal(i);
    cout<<res.size()<<endl;
    for(auto [x,y]:res) cout<<x<<" "<<y<<endl;
}

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

    //freopen("1.in","r",stdin);
    //freopen("1.out","w",stdout);

    int Test_numbers=1;
    //int Test_numbers;cin>>Test_numbers;

    while(Test_numbers--) Solve();

    //cerr << "\nTime run: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";

	return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef map<ll,ll> mll;
typedef vector<bool> vb;

#define y0 sdkfaslhagaklsldk
#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define endl "\n"
#define prina(arr,dau,cuoi) FTB(mmczmp,dau,cuoi)cout<<arr[mmczmp]<<" ";cout<<endl;
#define debug cout<<"debug\n"
#define pb push_back
#define pbg(ke,u,v) ke[u].pb(v);ke[v].pb(u);
#define fi first
#define se second
#define pi acos(-1.0)
#define lbnd(f,s,gt) lower_bound(f,s,gt)
#define ubnd(f,s,gt) upper_bound(f,s,gt)
#define all(s) s.begin(),s.end()
#define bitcount(n) __builtin_popcountll(n)
#define FTB(i,a,b) for(ll i=a,_b=b;i<=_b;i++)
#define FT(i,a,b) for(ll i=a,_b=b;i<_b;i++)
#define FGB(i,a,b) for(ll i=a,_b=b;i>=_b;i--)
#define FG(i,a,b) for(ll i=a,_b=b;i>_b;i--)
/////////////////////////////////////////////

ll n,a[100005],s[3],pr[3][100005],win,los,tmp;
vi vt[3];
vii res;

void cal(ll x){
    ll vt=0;
    s[1]=s[2]=0;
    while(vt<n){
        ll vw=lbnd(pr[win]+vt,pr[win]+n+1,pr[win][vt]+x)-pr[win];
        ll vl=lbnd(pr[los]+vt,pr[los]+n+1,pr[los][vt]+x)-pr[los];
        if(vw<vl){
            s[win]++;
            vt=vw;
        }
        else{
            s[los]++;
            vt=vl;
        }
    }
    if(vt==n&&s[win]>s[los]) res.pb({x,s[win]});

}

void Solve(){
    cin>>n;
    FTB(i,1,n){
        cin>>a[i],s[a[i]]++;
        pr[1][i]=pr[1][i-1];
        pr[2][i]=pr[2][i-1];
        pr[a[i]][i]++;
    }
    win=a[n],los=3-a[n];
    tmp=s[win];
    FTB(i,1,tmp) cal(i);
    cout<<res.size()<<endl;
    for(auto [x,y]:res) cout<<x<<" "<<y<<endl;
}

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

    //freopen("1.in","r",stdin);
    //freopen("1.out","w",stdout);

    int Test_numbers=1;
    //int Test_numbers;cin>>Test_numbers;

    while(Test_numbers--) Solve();

    //cerr << "\nTime run: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";

	return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef map<ll,ll> mll;
typedef vector<bool> vb;

#define y0 sdkfaslhagaklsldk
#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define endl "\n"
#define prina(arr,dau,cuoi) FTB(mmczmp,dau,cuoi)cout<<arr[mmczmp]<<" ";cout<<endl;
#define debug cout<<"debug\n"
#define pb push_back
#define pbg(ke,u,v) ke[u].pb(v);ke[v].pb(u);
#define fi first
#define se second
#define pi acos(-1.0)
#define lbnd(f,s,gt) lower_bound(f,s,gt)
#define ubnd(f,s,gt) upper_bound(f,s,gt)
#define all(s) s.begin(),s.end()
#define bitcount(n) __builtin_popcountll(n)
#define FTB(i,a,b) for(ll i=a,_b=b;i<=_b;i++)
#define FT(i,a,b) for(ll i=a,_b=b;i<_b;i++)
#define FGB(i,a,b) for(ll i=a,_b=b;i>=_b;i--)
#define FG(i,a,b) for(ll i=a,_b=b;i>_b;i--)
/////////////////////////////////////////////

ll n,a[100005],s[3],pr[3][100005],win,los,tmp;
vi vt[3];
vii res;

void cal(ll x){
    ll vt=0;
    s[1]=s[2]=0;
    while(vt<n){
        ll vw=lbnd(pr[win]+vt,pr[win]+n+1,pr[win][vt]+x)-pr[win];
        ll vl=lbnd(pr[los]+vt,pr[los]+n+1,pr[los][vt]+x)-pr[los];
        if(vw<vl){
            s[win]++;
            vt=vw;
        }
        else{
            s[los]++;
            vt=vl;
        }
    }
    if(vt==n&&s[win]>s[los]) res.pb({s[win],x});

}

void Solve(){
    cin>>n;
    FTB(i,1,n){
        cin>>a[i],s[a[i]]++;
        pr[1][i]=pr[1][i-1];
        pr[2][i]=pr[2][i-1];
        pr[a[i]][i]++;
    }
    win=a[n],los=3-a[n];
    tmp=s[win];
    FGB(i,tmp,1) cal(i);
    sort(all(res));
    cout<<res.size()<<endl;
    for(auto [x,y]:res) cout<<x<<" "<<y<<endl;
}

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

    //freopen("1.in","r",stdin);
    //freopen("1.out","w",stdout);

    int Test_numbers=1;
    //int Test_numbers;cin>>Test_numbers;

    while(Test_numbers--) Solve();

    //cerr << "\nTime run: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";

	return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
const int N = 200001;
using namespace std;

int main() {
//    cout << fixed << setprecision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n;
    cin >> n;
    int a[n];
    int f1[N], f2[N], p1[N], p2[N];
    fill(f1, f1 + N, n);
    fill(f2, f2 + N, n);
    int x = 0, y = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i] == 1 ? f1[++x] = i : f2[++y] = i;
    }

    memset(p1, 0, sizeof p1);
    memset(p2, 0, sizeof p2);
    a[0] == 1 ? p1[0] = 1 : p2[0] = 1;
    for (int i = 1; i < n; i++) {
        p1[i] = p1[i - 1] + (a[i] == 1);
        p2[i] = p2[i - 1] + (a[i] == 2);
    }

    vector<pair<int, int>> ans;
    for (int i = 1; i < n + 1; i++) {
        int st = 0, last = -1;
        x = 0, y = 0;
        int xx = 0, yy = 0;
        while (st < n) {
            if (f1[x + i] != n && f1[x + i] < f2[y + i]) {
                ++xx;
                st = f1[x + i] + 1;
                x = p1[st - 1];
                y = p2[st - 1];
                last = 0;
            }

            else if (f2[y + i] != n && f2[y + i] < f1[x + i]) {
                ++yy;
                st = f2[y + i] + 1;
                x = p1[st - 1];
                y = p2[st - 1];
                last = 1;
            }

            else {
                break;
            }
        }

        if (st == n) {
            if (xx > yy && last == 0) {
                ans.emplace_back(mp(xx, i));
            }
            else if (yy > xx && last) {
                ans.emplace_back(mp(yy, i));
            }
        }
    }

    cout << ans.size() << '\n';
    sort(ans.begin(), ans.end());
    for (auto [s, t] : ans) {
        cout << s << ' ' << t << '\n';
    }

}


#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
const int N = 1000001;
using namespace std;

int main() {
//    cout << fixed << setprecision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n;
    cin >> n;
    int a[n];
    int fir[2][2 * n + 1];
    fill(fir[0], fir[0] + 2 * n + 1, n);
    fill(fir[1], fir[1] + 2 * n + 1, n);
    int x = 0, y = 0;
    int pre[n][2];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (a[i] == 1) {
            fir[0][++x] = i;
        }
        else {
            fir[1][++y] = i;
        }
    }

    memset(pre, 0, sizeof pre);
    pre[0][a[0] - 1] = 1;
    for (int i = 1; i < n; i++) {
        pre[i][0] = pre[i - 1][0] + (a[i] == 1);
        pre[i][1] = pre[i - 1][1] + (a[i] == 2);
    }

    vector<pair<int, int>> ans;

    for (int i = 1; i < n + 1; i++) {
        int st = 0;
        x = 0, y = 0;
        int xx = 0, yy = 0, last = -1;
        while (st < n) {
            if (fir[0][x + i] != n && fir[0][x + i] < fir[1][y + i]) {
                last = 0;
                ++xx;
                st = fir[0][x + i] + 1;
                x = pre[st - 1][0];
                y = pre[st - 1][1];
            }

            else if (fir[1][y + i] != n && fir[1][y + i] < fir[0][x + i]) {
                last = 1;
                ++yy;
                st = fir[1][y + i] + 1;
                x = pre[st - 1][0];
                y = pre[st - 1][1];
            }

            else {
                break;
            }
        }

        if (st == n) {
            if (xx > yy && last == 0) {
                ans.emplace_back(mp(xx, i));
            }
            else if (yy > xx && last) {
                ans.emplace_back(mp(yy, i));
            }
        }
    }

    cout << ans.size() << '\n';
    sort(ans.begin(), ans.end());
    for (auto [s, t] : ans) {
        cout << s << ' ' << t << '\n';
    }

}


#include <bits/stdc++.h>

using namespace std;

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

    int point[3][2*(int)1e5+5]={};
    int idx[3][2*(int)1e5+5]={};

    for(int i=1,id;i<=n;i++){
        scanf("%d",&id);

        idx[id][i]++;

        idx[id][i]+=idx[id][i-1];
        idx[3-id][i]+=idx[3-id][i-1];

        point[id][idx[id][i]]=i;
    }
    for(int i=1;i<=2*n;i++){
        if(!point[1][i])point[1][i]=2*n;
        if(!point[2][i])point[2][i]=2*n;
    }

    //for(int i=1;i<=2*n;i++)cout<<i<<":"<<point[1][i]<<", ";cout<<endl;
    //for(int i=1;i<=2*n;i++)cout<<i<<":"<<point[2][i]<<", ";cout<<endl;

    //for(int i=1;i<=n;i++)cout<<i<<":"<<idx[1][i]<<", ";cout<<endl;
    //for(int i=1;i<=n;i++)cout<<i<<":"<<idx[2][i]<<", ";cout<<endl;

    vector<pair<int,int> >res;
    for(int t=1;t<=n;t++){
        int pointp=0;
        int pointg=0;

        int setp=0;
        int setg=0;

        while(point[1][pointp]<n && point[2][pointg]<n){
            if(point[1][pointp+t]<point[2][pointg+t]){
                setp++;
                pointp+=t;

                int nowidx=point[1][pointp];
                pointg=idx[2][nowidx];
            }
            else {
                setg++;
                pointg+=t;

                int nowIdx=point[2][pointg];
                pointp=idx[1][nowIdx];
            }
            //cout<<pointp<<" "<<pointg<<endl;
            //cout<<point[1][pointp]<<" "<<point[2][pointg]<<endl;
            //cout<<endl;
            //break;
            //break;
            //break;
        }
        //cout<<endl;

        if(point[1][pointp]==n && setp>setg)res.push_back(make_pair(setp,t));
        else if(point[2][pointg]==n && setp>setg)res.push_back(make_pair(setg,t));
    }

    //cout<<"came here\n";

    printf("%d\n",(int)res.size());
    for(int i=0;i<res.size();i++)printf("%d %d\n",res[i].first,res[i].second);

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

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

    int point[3][2*(int)1e5+5]={};
    int idx[3][2*(int)1e5+5]={};

    for(int i=1,id;i<=n;i++){
        scanf("%d",&id);

        idx[id][i]++;

        idx[id][i]+=idx[id][i-1];
        idx[3-id][i]+=idx[3-id][i-1];

        point[id][idx[id][i]]=i;
    }
    for(int i=1;i<=2*n;i++){
        if(!point[1][i])point[1][i]=2*n;
        if(!point[2][i])point[2][i]=2*n;
    }

    //for(int i=1;i<=2*n;i++)cout<<i<<":"<<point[1][i]<<", ";cout<<endl;
    //for(int i=1;i<=2*n;i++)cout<<i<<":"<<point[2][i]<<", ";cout<<endl;

    //for(int i=1;i<=n;i++)cout<<i<<":"<<idx[1][i]<<", ";cout<<endl;
    //for(int i=1;i<=n;i++)cout<<i<<":"<<idx[2][i]<<", ";cout<<endl;

    vector<pair<int,int> >res;
    for(int t=1;t<=n;t++){
        int pointp=0;
        int pointg=0;

        int setp=0;
        int setg=0;

        while(point[1][pointp]<n && point[2][pointg]<n){
            if(point[1][pointp+t]<point[2][pointg+t]){
                setp++;
                pointp+=t;

                int nowidx=point[1][pointp];
                pointg=idx[2][nowidx];
            }
            else {
                setg++;
                pointg+=t;

                int nowIdx=point[2][pointg];
                pointp=idx[1][nowIdx];
            }
            //cout<<pointp<<" "<<pointg<<endl;
            //cout<<point[1][pointp]<<" "<<point[2][pointg]<<endl;
            //cout<<endl;
            //break;
            //break;
            //break;
        }
        //cout<<endl;

        if(point[1][pointp]==n && setp>setg)res.push_back(make_pair(setp,t));
        else if(point[2][pointg]==n && setp>setg)res.push_back(make_pair(setg,t));
    }

    //cout<<"came here\n";
    sort(res.begin(),res.end());

    printf("%d\n",(int)res.size());
    for(int i=0;i<res.size();i++)printf("%d %d\n",res[i].first,res[i].second);

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

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

    int point[3][2*(int)1e5+5]={};
    int idx[3][2*(int)1e5+5]={};

    for(int i=1,id;i<=n;i++){
        scanf("%d",&id);

        idx[id][i]++;

        idx[id][i]+=idx[id][i-1];
        idx[3-id][i]+=idx[3-id][i-1];

        point[id][idx[id][i]]=i;
    }
    for(int i=1;i<=2*n;i++){
        if(!point[1][i])point[1][i]=2*n;
        if(!point[2][i])point[2][i]=2*n;
    }

    //for(int i=1;i<=2*n;i++)cout<<i<<":"<<point[1][i]<<", ";cout<<endl;
    //for(int i=1;i<=2*n;i++)cout<<i<<":"<<point[2][i]<<", ";cout<<endl;

    //for(int i=1;i<=n;i++)cout<<i<<":"<<idx[1][i]<<", ";cout<<endl;
    //for(int i=1;i<=n;i++)cout<<i<<":"<<idx[2][i]<<", ";cout<<endl;

    vector<pair<int,int> >res;
    for(int t=1;t<=n;t++){
        int pointp=0;
        int pointg=0;

        int setp=0;
        int setg=0;

        while(point[1][pointp]<n && point[2][pointg]<n){
            if(point[1][pointp+t]<point[2][pointg+t]){
                setp++;
                pointp+=t;

                int nowidx=point[1][pointp];
                pointg=idx[2][nowidx];
            }
            else {
                setg++;
                pointg+=t;

                int nowIdx=point[2][pointg];
                pointp=idx[1][nowIdx];
            }
            //cout<<pointp<<" "<<pointg<<endl;
            //cout<<point[1][pointp]<<" "<<point[2][pointg]<<endl;
            //cout<<endl;
            //break;
            //break;
            //break;
        }
        //cout<<endl;

        if(point[1][pointp]==n && setp>setg)res.push_back(make_pair(setp,t));
        else if(point[2][pointg]==n && setg>setp)res.push_back(make_pair(setg,t));
    }

    //cout<<"came here\n";
    sort(res.begin(),res.end());

    printf("%d\n",(int)res.size());
    for(int i=0;i<res.size();i++)printf("%d %d\n",res[i].first,res[i].second);

    return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
#include<vector>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])
#define Lson (x<<1)
#define Rson ((x<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define MAXN (100000+10)
long long mul(long long a,long long b){return (a*b)%F;}
long long add(long long a,long long b){return (a+b)%F;}
long long sub(long long a,long long b){return (a-b+(a-b)/F*F+F)%F;}
typedef long long ll;
int n,n1=0,n2=0;
int f[MAXN],g[MAXN]; // f/g win'game num
int a[MAXN],b[MAXN]; // f/g win f[i] game until ith game end

vector<pair<int,int> > ans;
int main()
{
//	freopen("Tennis.in","r",stdin);
//	freopen(".out","w",stdout);
	MEMI(f) MEMI(g)
	cin>>n;
	For(i,n)
	{
		int t;
		scanf("%d",&t);
		if (t&1) f[++n1]=i;
		else g[++n2]=i;
		a[i]=n1,b[i]=n2;
	}
	For(t,n)
	{
		bool flag=0;
		int s1=0,s2=0,cur1=0,cur2=0;
		for(int cur=0;cur<=n;)
		{
			int x,y;
			if (cur1+t>n1&&cur2+t>n2) {flag=1;break;}
			int now=min(x=f[cur1+t],y=g[cur2+t]);

			if (x<y) s1++;else s2++;
			cur1=a[now],cur2=b[now];

			if (now==n)
			{
				if (x<y&&s1<s2) flag=1; //x win the last game but totally y win
				if (x>y&&s1>s2) flag=1; //y win the last game but totally x win
				if (s1==s2) flag=1; //impossible for role
				break;
			}

			cur=now;
		}

		if (!flag) ans.push_back(make_pair(max(s1,s2),t));
	}

	sort(ans.begin(),ans.end());
	printf("%d\n",ans.size());
	Rep(i,ans.size()) printf("%d %d\n",ans[i].first,ans[i].second);

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
int f[maxn],g[maxn],n,top1,top2;
int a[maxn],b[maxn];
vector<pair<int,int> >ans;
int main()
{
	cin >> n;
	memset(f,127,sizeof(f));
	memset(g,127,sizeof(g));
	for(int i=1;i<=n;i++)
	{
		int x;
		cin >> x;
		if( x==1 )	f[++top1]=i;
		else	g[++top2]=i;
		a[i]=top1,b[i]=top2;
	}
	for(int t=1;t<=n;t++)
	{
		bool flag=1;
		int s1=0,s2=0,cur1=0,cur2=0;
		for(int cur=0;cur<=n;)//��ǰ���е��ڼ�����Ϸ
		{
			if( cur1+t>top1&&cur2+t>top2 )//��󶼲�����n�������
			{
				flag=0;
				break;
			}
			int x=f[cur1+t],y=g[cur2+t];
			if( x<y )	s1++; else	s2++;
			int now=min(x,y);//���е���now�ֱ�����
			cur1=a[now],cur2=b[now];//��now�ֱ���ʱ,��ʱ1Ӯ��cur1��,2Ӯ��cur2��
			if( now==n )
			{
				if( x<y&&s1<s2)	flag=0;//xӮ���һ�̵��Ƿ�������
				if( x>y&&s1>s2 )	flag=0;//xӮ���һ�̵��Ƿ���Ӯ��
				if( s1==s2 )	flag=0;//ƽ��
				break;
			}
			cur=now;
		}
		if( flag )	ans.push_back( make_pair(max(s1,s2),t) );
	}
	sort( ans.begin(),ans.end() );
	cout << ans.size() << endl;
	for(int i=0;i<ans.size();i++)
		printf("%d %d\n",ans[i].first,ans[i].second);
}


#include <iostream>
#include <algorithm>
#include <vector>

using ll = long long;
using namespace std;

int a[(int)1e5+1], b[(int)1e5+1];
vector<pair<int,int>> ans;
int main ()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin >> n;

    for (int i=1; i<=n; i++)
    {
        int tmp;
        cin >> tmp;
        a[i] = a[i-1] + (tmp==1);
        b[i] = b[i-1] + (tmp==2);
    }

    int cnt = 0, cnt2=0;
    for (int t=1; t<=n; t++)
    {
        int st = 1;
        while(true)
        {
            int l = st, r = n;
            while( l<=r )
            {
                int mid = (l+r)/2;
                if ( a[mid] - a[st-1] >= t ) r = mid -1;
                else l = mid + 1;
            }

            int first = l;
            l = st, r=n;

            while( l<=r )
            {
                int mid = (l+r)/2;
                if ( b[mid] - b[st-1] >= t) r= mid-1;
                else l = mid+1;
            }

            int second = l;

            if ( first > n && second > n )
            {
                break;
            }

            int mn = min( first ,second );
            if ( mn == first ) cnt++;
            else cnt2++;

            if ( mn == n )
            {
                if (((mn == first) &&  cnt>cnt2)||((mn == second) && cnt<cnt2))
                {
                    ans.push_back({ max(cnt, cnt2) , t});
                }
                break;
            }
            st = mn +1;
        }
    }

    sort(ans.begin(), ans.end());
    cout << ans.size() <<"\n";

    for (pair<int, int> p : ans )
        cout << p.first << " " << p.second << "\n";
}


#include <bits/stdc++.h>
#define ll  long long
#define ull unsigned long long
using namespace std;
#define  inf 1e9+18
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define  f1(i,n) for(i=1;i<=n;i++)
#define f0(i,n)  for(i=0;i<n;i++)
#define w(x)   while(x--)
const ll  maxn=100005;
#define  pq priority_queue
#define  ff first
#define  ss second
#define pb  push_back
#define lb lower_bound
#define ub upper_bound
#define pie 3.14159265359
#define mod 1000000007

int main(){
   ll x,y,r,x1,y1,r1;
   ll i,j;
   cin>>x>>y>>r>>x1>>y1>>r1;
   double d,e,f;
   d=1.0*sqrt(pow(x-x1,2)+pow(y-y1,2));
   if(d>=r+r1)
    cout<<"0.00000000000000000000";
else if(d<=abs(r-r1))
{
      cout<<fixed<<setprecision(8)<<pie*min(r,r1)*min(r,r1);
}
    else
    {
        e=1.0*(pow(x-x1,2)+pow(y-y1,2)+r*r-r1*r1)/(2*d*1.0);
        f=1.0*e*sqrt(r*r-e*e);
        double x=1.0*acos(1.0*e/r);
        double ar=1.0*x*r*r;
        cout<<fixed<<setprecision(8)<<2*(ar-f);

    }

}


#include <bits/stdc++.h>
#define ll  long long
#define ull unsigned long long
using namespace std;
#define  inf 1e9+18
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define  f1(i,n) for(i=1;i<=n;i++)
#define f0(i,n)  for(i=0;i<n;i++)
#define w(x)   while(x--)
const ll  maxn=100005;
#define  pq priority_queue
#define  ff first
#define  ss second
#define pb  push_back
#define lb lower_bound
#define ub upper_bound
#define pie 3.14159265359
#define mod 1000000007

int main(){
   ll x,y,r,x1,y1,r1;
   ll i,j;
   cin>>x>>y>>r>>x1>>y1>>r1;
  long  double d,e,f;
   d=1.0*sqrt(pow(x-x1,2)+pow(y-y1,2));
   ll p=pow(x-x1,2)+pow(y-y1,2);
   if(p>=(r+r1)*(r+r1))
    cout<<"0.00000000000000000000";
else if(p<=(r-r1)*(r-r1))
{
      cout<<fixed<<setprecision(8)<<pie*min(r,r1)*min(r,r1);
}
   else
    {
        //if(r>r1)
        e=1.0*(pow(x-x1,2)+pow(y-y1,2)+r*r-r1*r1)/(2*d*1.0);
        f=1.0*e*sqrt(r*r-e*e);
      long  double x2=1.0*acos(1.0*e/r);
        //cout<<x2<<" ";
      long  double ar=1.0*x2*r*r;
        ar=ar-f;
          e=1.0*(pow(x-x1,2)+pow(y-y1,2)+r1*r1-r*r)/(2*d*1.0);
        f=1.0*e*sqrt(r1*r1-e*e);
         x2=1.0*acos(1.0*e/r1);
       //  cout<<x2<<" ";
       long  double ar1=1.0*x2*r1*r1;
        ar1=ar1-f;
        cout<<fixed<<setprecision(8)<<ar+ar1;

    }

}


#include <bits/stdc++.h>
#define ll  long long
#define ull unsigned long long
using namespace std;
#define  inf 1e9+18
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define  f1(i,n) for(i=1;i<=n;i++)
#define f0(i,n)  for(i=0;i<n;i++)
#define w(x)   while(x--)
const ll  maxn=100005;
#define  pq priority_queue
#define  ff first
#define  ss second
#define pb  push_back
#define lb lower_bound
#define ub upper_bound
#define pie 3.14159265359
#define mod 1000000007

int main(){
   ll x,y,r,x1,y1,r1;
   ll i,j;
   cin>>x>>y>>r>>x1>>y1>>r1;
  long  double d,e,f;
   d=1.0*sqrt(pow(x-x1,2)+pow(y-y1,2));
   ll p=pow(x-x1,2)+pow(y-y1,2);
   if(p>=(r+r1)*(r+r1))
    cout<<"0.00000000000000000000";
else if(p<=(r-r1)*(r-r1))
{
      cout<<fixed<<setprecision(18)<<pie*min(r,r1)*min(r,r1);
}
   else
    {
        //if(r>r1)
        e=1.0*(pow(x-x1,2)+pow(y-y1,2)+r*r-r1*r1)/(2*d);

      long  double x2=1.0*acos(1.0*e/r);
      long double f1=r*r*sin(x2)*cos(x2);
        //cout<<x2<<" ";
      long  double ar=1.0*x2*r*r;
        //ar=ar-f;
          e=1.0*(pow(x-x1,2)+pow(y-y1,2)+r1*r1-r*r)/(2*d);

         x2=1.0*acos(1.0*e/r1);
         f=r1*r1*sin(x2)*cos(x2);
       //  cout<<x2<<" ";
       long  double ar1=1.0*x2*r1*r1;

        cout<<fixed<<setprecision(29)<<ar+ar1-f-f1;

    }

}


#include <iostream>
#include <string>
#include <vector>
#include <iostream>
#include <cstdlib>
#include <utility>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <sstream>
#include <list>
#include <forward_list>
#include <stack>
#include <deque>
#include <queue>
#include <array>
#include <numeric>
#include <iomanip>

#ifdef ONLINE_JUDGE
#define _USE_MATH_DEFINES
#endif

// Include after definition of _USE_MATH_DEFINES
#include <cmath>

#ifdef ONLINE_JUDGE
#define NL '\n'
#else
#define NL std::endl
#endif

using ll = long long;
using ull = unsigned long long;

int main()
{
#ifdef ONLINE_JUDGE
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
#endif

    double x1, y1, r1;
    std::cin >> x1 >> y1 >> r1;
    double x2, y2, r2;
    std::cin >> x2 >> y2 >> r2;

    auto dist = std::sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    if (dist >= r1+r2)
    {
        std::cout << 0 << NL;
    }
    else if (dist + r1 <= r2)
    {
        std::cout << M_PI * r1 * r1 << NL;
    }
    else if (dist + r2 <= r1)
    {
        std::cout << M_PI * r2 * r2 << NL;
    }
    else
    {
        auto t1 = r1*r1*std::acos((dist*dist + r1*r1 - r2*r2)/(2*dist*r1));
        auto t2 = r2*r2*std::acos((dist*dist + r2*r2 - r1*r1)/(2*dist*r2));
        auto t3 = 0.5*std::sqrt((-dist+r1+r2)*(dist+r1-r2)*(dist-r1+r2)*(dist+r1+r2));
        std::cout << std::setprecision(17) << t1+t2-t3 << NL;
    }

    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <iostream>
#include <cstdlib>
#include <utility>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <sstream>
#include <list>
#include <forward_list>
#include <stack>
#include <deque>
#include <queue>
#include <array>
#include <numeric>
#include <iomanip>

#ifdef ONLINE_JUDGE
#define _USE_MATH_DEFINES
#endif

// Include after definition of _USE_MATH_DEFINES
#include <cmath>

#ifdef ONLINE_JUDGE
#define NL '\n'
#else
#define NL std::endl
#endif

using ll = long long;
using ull = unsigned long long;

int main()
{
#ifdef ONLINE_JUDGE
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
#endif

    ll x1, y1, r1;
    std::cin >> x1 >> y1 >> r1;
    ll x2, y2, r2;
    std::cin >> x2 >> y2 >> r2;

    auto dsq = (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
    auto dist = std::sqrt(static_cast<double>(dsq));
    if (dsq >= (r1+r2)*(r1+r2))
    {
        std::cout << 0 << NL;
    }
    else if (dsq <= (r2-r1)*(r2-r1))
    {
        auto rm = std::min(r1, r2);
        std::cout << M_PI * rm * rm << NL;
    }
    else
    {
        auto area = [](auto dist, auto r1, auto r2) {
            auto alpha = std::acos((r2*r2 + dist*dist - r1*r1)/(2.0*dist*r2));
            auto s = alpha*r2*r2;
            auto t = std::sin(alpha)*std::cos(alpha)*r2*r2;
            return s-t;
        };
        std::cout << std::fixed << std::setprecision(20) << area(dist, r1, r2)+area(dist, r2, r1) << NL;
    }

    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <iostream>
#include <cstdlib>
#include <utility>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <sstream>
#include <list>
#include <forward_list>
#include <stack>
#include <deque>
#include <queue>
#include <array>
#include <numeric>
#include <iomanip>

#ifdef ONLINE_JUDGE
#define _USE_MATH_DEFINES
#endif

// Include after definition of _USE_MATH_DEFINES
#include <cmath>

#ifdef ONLINE_JUDGE
#define NL '\n'
#else
#define NL std::endl
#endif

using ll = long long;
using ull = unsigned long long;

int main()
{
#ifdef ONLINE_JUDGE
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
#endif

    long double x1, y1, r1;
    std::cin >> x1 >> y1 >> r1;
    long double x2, y2, r2;
    std::cin >> x2 >> y2 >> r2;

    auto dist = std::sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    if (dist >= r1+r2)
    {
        std::cout << 0 << NL;
    }
    else if (dist + r1 <= r2)
    {
        std::cout << M_PI * r1 * r1 << NL;
    }
    else if (dist + r2 <= r1)
    {
        std::cout << M_PI * r2 * r2 << NL;
    }
    else
    {
        auto t1 = r1*r1*std::acos((dist*dist + r1*r1 - r2*r2)/(2*dist*r1));
        auto t2 = r2*r2*std::acos((dist*dist + r2*r2 - r1*r1)/(2*dist*r2));
        auto t3 = 0.5*std::sqrt((-dist+r1+r2)*(dist+r1-r2)*(dist-r1+r2)*(dist+r1+r2));
        std::cout << std::setprecision(25) << t1+t2-t3 << NL;
    }

    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <iostream>
#include <cstdlib>
#include <utility>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <sstream>
#include <list>
#include <forward_list>
#include <stack>
#include <deque>
#include <queue>
#include <array>
#include <numeric>
#include <iomanip>

#ifdef ONLINE_JUDGE
#define _USE_MATH_DEFINES
#endif

// Include after definition of _USE_MATH_DEFINES
#include <cmath>

#ifdef ONLINE_JUDGE
#define NL '\n'
#else
#define NL std::endl
#endif

using ll = long long;
using ull = unsigned long long;

int main()
{
#ifdef ONLINE_JUDGE
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
#endif

    double x1, y1, r1;
    std::cin >> x1 >> y1 >> r1;
    double x2, y2, r2;
    std::cin >> x2 >> y2 >> r2;

    auto dist = std::sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    if (dist >= r1+r2)
    {
        std::cout << 0 << NL;
    }
    else if (dist + r1 <= r2)
    {
        std::cout << M_PI * r1 * r1 << NL;
    }
    else if (dist + r2 <= r1)
    {
        std::cout << M_PI * r2 * r2 << NL;
    }
    else
    {
        auto t1 = r1*r1*std::acos((dist*dist + r1*r1 - r2*r2)/(2*dist*r1));
        auto t2 = r2*r2*std::acos((dist*dist + r2*r2 - r1*r1)/(2*dist*r2));
        auto t3 = 0.5*std::sqrt((-dist+r1+r2)*(dist+r1-r2)*(dist-r1+r2)*(dist+r1+r2));
        std::cout << std::setprecision(9) << t1+t2-t3 << NL;
    }

    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <iostream>
#include <cstdlib>
#include <utility>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <sstream>
#include <list>
#include <forward_list>
#include <stack>
#include <deque>
#include <queue>
#include <array>
#include <numeric>
#include <iomanip>

#ifdef ONLINE_JUDGE
#define _USE_MATH_DEFINES
#endif

// Include after definition of _USE_MATH_DEFINES
#include <cmath>

#ifdef ONLINE_JUDGE
#define NL '\n'
#else
#define NL std::endl
#endif

using ll = long long;
using ull = unsigned long long;

int main()
{
#ifdef ONLINE_JUDGE
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
#endif

    ll x1, y1, r1;
    std::cin >> x1 >> y1 >> r1;
    ll x2, y2, r2;
    std::cin >> x2 >> y2 >> r2;

    auto dsq = (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
    auto dist = std::sqrt(static_cast<long double>(dsq));
    if (dsq >= (r1+r2)*(r1+r2))
    {
        std::cout << 0 << NL;
    }
    else if (dsq <= (r2-r1)*(r2-r1))
    {
        auto rm = std::min(r1, r2);
        std::cout << std::fixed << std::setprecision(20) << M_PI * rm * rm << NL;
    }
    else
    {
        auto area = [](auto dist, auto r1, auto r2) {
            auto alpha = std::acos((r2*r2 + dist*dist - r1*r1)/(2.0l*dist*r2));
            auto s = alpha*r2*r2;
            auto t = std::sin(alpha)*std::cos(alpha)*r2*r2;
            return s-t;
        };
        std::cout << std::fixed << std::setprecision(20) << area(dist, r1, r2)+area(dist, r2, r1) << NL;
    }

    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <iostream>
#include <cstdlib>
#include <utility>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <sstream>
#include <list>
#include <forward_list>
#include <stack>
#include <deque>
#include <queue>
#include <array>
#include <numeric>
#include <iomanip>

#ifdef ONLINE_JUDGE
#define _USE_MATH_DEFINES
#endif

// Include after definition of _USE_MATH_DEFINES
#include <cmath>

#ifdef ONLINE_JUDGE
#define NL '\n'
#else
#define NL std::endl
#endif

using ll = long long;
using ull = unsigned long long;

int main()
{
#ifdef ONLINE_JUDGE
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
#endif

    ll x1, y1, r1;
    std::cin >> x1 >> y1 >> r1;
    ll x2, y2, r2;
    std::cin >> x2 >> y2 >> r2;

    auto dsq = (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
    auto dist = std::sqrt(static_cast<double>(dsq));
    if (dsq >= (r1+r2)*(r1+r2))
    {
        std::cout << 0 << NL;
    }
    else if (dsq <= (r2-r1)*(r2-r1))
    {
        auto rm = std::min(r1, r2);
        std::cout << std::fixed << std::setprecision(20) << M_PI * rm * rm << NL;
    }
    else
    {
        auto area = [](auto dist, auto r1, auto r2) {
            auto alpha = std::acos((r2*r2 + dist*dist - r1*r1)/(2.0*dist*r2));
            auto s = alpha*r2*r2;
            auto t = std::sin(alpha)*std::cos(alpha)*r2*r2;
            return s-t;
        };
        std::cout << std::fixed << std::setprecision(20) << area(dist, r1, r2)+area(dist, r2, r1) << NL;
    }

    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <iostream>
#include <cstdlib>
#include <utility>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <sstream>
#include <list>
#include <forward_list>
#include <stack>
#include <deque>
#include <queue>
#include <array>
#include <numeric>
#include <iomanip>

#ifdef ONLINE_JUDGE
#define _USE_MATH_DEFINES
#endif

// Include after definition of _USE_MATH_DEFINES
#include <cmath>

#ifdef ONLINE_JUDGE
#define NL '\n'
#else
#define NL std::endl
#endif

using ll = long long;
using ull = unsigned long long;

int main()
{
#ifdef ONLINE_JUDGE
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
#endif

    ll x1, y1, r1;
    std::cin >> x1 >> y1 >> r1;
    ll x2, y2, r2;
    std::cin >> x2 >> y2 >> r2;

    auto dsq = (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
    auto dist = std::sqrt(static_cast<double>(dsq));
    if (dsq >= (r1+r2)*(r1+r2))
    {
        std::cout << 0 << NL;
    }
    else if (dsq <= (r2-r1)*(r2-r1))
    {
        auto rm = std::min(r1, r2);
        std::cout << M_PI * rm * rm << NL;
    }
    else
    {
        auto area = [](auto dist, auto r1, auto r2) {
            auto alpha = std::acos((r2*r2 + dist*dist - r1*r1)/(2.0*dist*r2));
            auto s = alpha*r2*r2;
            auto t = std::sin(alpha)*std::cos(alpha)*r2*r2;
            return s-t;
        };
        std::cout << std::setprecision(20) << area(dist, r1, r2)+area(dist, r2, r1) << NL;
    }

    return 0;
}


#include <cmath>
#include <cassert>
#include <iomanip>
#include <algorithm>
#include <iostream>
#include <complex>
#include <cstdio>
#include <utility>
#include <vector>
using namespace std;

using W = long double;

typedef complex<W> P;
typedef pair<P,P> L;
typedef pair<P,W> C;
#define X real()
#define Y imag()
const W EPS = (1e-10), pi = acos(-1), INF = 1e20;

W dot(P a, P b){ return a.X * b.X + a.Y * b.Y;}
W cross(P a, P b){ return a.X * b.Y - a.Y * b.X;}

int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if(cross(b,c) > EPS) return +1;
  if(cross(b,c) < -EPS) return -1;
  if(dot(b,c) < -EPS) return +2;
  if(norm(b) + EPS < norm(c)) return -2;
  return 0;
}

//円と円の交点
vector<P> cpcc(C a, C b){
  P ca = a.first, cb = b.first;
  W d = abs(ca-cb), ra = a.second, rb = b.second, s = (d+ra+rb)*0.5;
  W t = (ra*ra-rb*rb+d*d)*0.5/d, h = sqrt(s*(s-d)*(s-ra)*(s-rb))*2/d, t_ = t/d;
  P m = t_*cb + (1-t_)*ca;
  vector<P> cp(2,m);
  P n(-(ca-cb).Y,(ca-cb).X);
  n /= d;
  n *= h;
  cp[0] -= n;
  cp[1] += n;
  return cp;
}

W common_area(C a, C b){
  if(a.second > b.second) swap(a,b);
  P ca = a.first, cb = b.first;
  W ra = a.second, rb = b.second;
  if(ra < EPS) return 0;
  if(norm(ca - cb) < norm(ra - rb) + EPS)
    return min(ra*ra, rb*rb)*pi;
  if(abs(ca - cb) > ra + rb + EPS) return 0;
  vector<P> cp = cpcc(a,b);
  if(norm(cp[0] - cp[1]) < EPS) return 0;
  P aa = (cp[0]-ca)/(cp[1]-ca);
  P bb = (cp[0]-cb)/(cp[1]-cb);
  W theta_a = abs(atan2l(aa.Y,aa.X));
  W theta_b = abs(atan2l(bb.Y,bb.X));
  W d = abs(ca-cb), s = 0.5*(ra+rb+d), ret = sqrt(4*s*(s-ra)*(s-rb)*(s-d));
  if(ccw(cp[0], cp[1], ca)*ccw(cp[0], cp[1], cb) >= 0){
    theta_a = max(2*pi - theta_a, theta_a);
    theta_b = min(2*pi - theta_b, theta_b);
  }else{
    theta_a = min(2*pi - theta_a, theta_a);
    theta_b = min(2*pi - theta_b, theta_b);
  }
  return (theta_a*ra*ra + theta_b*rb*rb)*0.5 - ret;
}

int main(){
  W x, y, r;
  cin >> x >> y >> r;
  C c1(P(x,y),r);
  cin >> x >> y >> r;
  C c2(P(x,y),r);
  cout << fixed << setprecision(18);
  cout << common_area(c1,c2) << endl;
}


#include <cmath>
#include <cassert>
#include <iomanip>
#include <algorithm>
#include <iostream>
#include <complex>
#include <cstdio>
#include <utility>
#include <vector>
using namespace std;

using W = long double;

using P = complex<W>;
using L = pair<P,P>;
using C = pair<P,W>;

#define X real()
#define Y imag()

const W EPS = (1e-8), pi = acosl(-1.0L), INF = 1e20;

W dot(P a, P b){ return a.X * b.X + a.Y * b.Y;}
W cross(P a, P b){ return a.X * b.Y - a.Y * b.X;}

int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if(cross(b,c) > EPS) return +1;
  if(cross(b,c) < -EPS) return -1;
  if(dot(b,c) < -EPS) return +2;
  if(norm(b) + EPS < norm(c)) return -2;
  return 0;
}

//円と円の交点
vector<P> cpcc(C a, C b){
  if(a.second < b.second) swap(a,b);
  P ca = a.first, cb = b.first;
  W d = abs(ca-cb), ra = a.second, rb = b.second, s = (d+ra+rb)*0.5;
  W h = sqrt(s*(s-d)*(s-ra)*(s-rb))*2/d, t = sqrt(ra*ra-h*h), t_ = t/d;
  P m = t_*cb + (1-t_)*ca;
  vector<P> cp(2,m);
  P n(-(ca-cb).Y,(ca-cb).X);
  n /= d;
  n *= h;
  cp[0] -= n;
  cp[1] += n;
  return cp;
}

W common_area(C a, C b){
  if(a.second > b.second) swap(a,b);
  P ca = a.first, cb = b.first;
  W ra = a.second, rb = b.second;
  if(ra < EPS) return 0;
  if(norm(ca - cb) < norm(ra - rb) + EPS)
    return min(ra*ra, rb*rb)*pi;
  if(norm(ca - cb) > norm(ra + rb) + EPS)
    return 0;
  vector<P> cp = cpcc(a,b);
  if(norm(cp[0] - cp[1]) < EPS) return 0;

  P aa = (cp[0]-ca)/(cp[1]-ca);
  P bb = (cp[0]-cb)/(cp[1]-cb);
  W theta_a = abs(atan2l(aa.Y,aa.X));
  W theta_b = abs(atan2l(bb.Y,bb.X));
  W d = abs(ca-cb), s = 0.5*(ra+rb+d);
  W ret = sqrt(s*(s-ra)*(s-rb)*(s-d))*2;

  if(ccw(cp[0], cp[1], ca)*ccw(cp[0], cp[1], cb) >= 0){
    theta_a = min(2*pi - theta_a, theta_a);
    theta_b = max(2*pi - theta_b, theta_b);
  }else{
    theta_a = min(2*pi - theta_a, theta_a);
    theta_b = min(2*pi - theta_b, theta_b);
  }

  cerr << fixed << setprecision(20) << theta_a << endl;
  cerr << fixed << setprecision(20) << theta_b << endl;
  cerr << fixed << setprecision(20) << ret << endl;
  W ans = ra*ra*(theta_a-sin(theta_a)) + rb*rb*(theta_b-sin(theta_b));
  ans *= 0.5;
  // return (ra*theta_a*ra*0.5 + rb*theta_b*rb*0.5 - ret);
  return ans;
}

int main(){
  W x, y, r;
  cin >> x >> y >> r;
  C c1(P(x,y),r);
  cin >> x >> y >> r;
  C c2(P(x,y),r);
  cout << fixed << setprecision(20);
  cout << common_area(c1,c2) << endl;
}


#include <cmath>
#include <cassert>
#include <iomanip>
#include <algorithm>
#include <iostream>
#include <complex>
#include <cstdio>
#include <utility>
#include <vector>
using namespace std;

// using W = long double;
using W = double;
using P = complex<W>;
using L = pair<P,P>;
using C = pair<P,W>;

#define X real()
#define Y imag()

const W EPS = (1e-10), pi = acosl(-1.0L), INF = 1e20;

W dot(P a, P b){ return a.X * b.X + a.Y * b.Y;}
W cross(P a, P b){ return a.X * b.Y - a.Y * b.X;}

int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if(cross(b,c) > EPS) return +1;
  if(cross(b,c) < -EPS) return -1;
  if(dot(b,c) < -EPS) return +2;
  if(norm(b) + EPS < norm(c)) return -2;
  return 0;
}

//円と円の交点
vector<P> cpcc(C a, C b){
  P ca = a.first, cb = b.first;
  W d = abs(ca-cb), ra = a.second, rb = b.second, s = (d+ra+rb)*0.5;
  W t = (ra*ra-rb*rb+d*d)*0.5/d, h = sqrt(s*(s-d)*(s-ra)*(s-rb))*2/d, t_ = t/d;
  P m = t_*cb + (1-t_)*ca;
  vector<P> cp(2,m);
  P n(-(ca-cb).Y,(ca-cb).X);
  n /= d;
  n *= h;
  cp[0] -= n;
  cp[1] += n;
  return cp;
}

W common_area(C a, C b){
  if(a.second > b.second) swap(a,b);
  P ca = a.first, cb = b.first;
  W ra = a.second, rb = b.second;
  if(ra < EPS) return 0;
  if(norm(ca - cb) < norm(ra - rb) + EPS)
    return min(ra*ra, rb*rb)*pi;
  if(norm(ca - cb) > norm(ra + rb) + EPS)
    return 0;
  vector<P> cp = cpcc(a,b);
  if(norm(cp[0] - cp[1]) < EPS) return 0;
  P aa = (cp[0]-ca)/(cp[1]-ca);
  P bb = (cp[0]-cb)/(cp[1]-cb);
  W theta_a = abs(atan2l(aa.Y,aa.X));
  W theta_b = abs(atan2l(bb.Y,bb.X));

  if(ccw(cp[0], cp[1], ca)*ccw(cp[0], cp[1], cb) >= 0){
    theta_a = max(2*pi - theta_a, theta_a);
    theta_b = min(2*pi - theta_b, theta_b);
  }else{
    theta_a = min(2*pi - theta_a, theta_a);
    theta_b = min(2*pi - theta_b, theta_b);
  }
  W sa = (theta_a-sinl(theta_a))*0.5, sb = (theta_b-sinl(theta_b))*0.5;
  W ans = ra*sa*ra + rb*sb*rb;
  return ans;
}

int main(){
  W x, y, r;
  cin >> x >> y >> r;
  C c1(P(x,y),r);
  cin >> x >> y >> r;
  C c2(P(x,y),r);
  cout << fixed << setprecision(20);
  cout << common_area(c1,c2) << endl;
}


#include <cmath>
#include <cassert>
#include <iomanip>
#include <algorithm>
#include <iostream>
#include <complex>
#include <cstdio>
#include <utility>
#include <vector>
using namespace std;

using W = long double;

using P = complex<W>;
using L = pair<P,P>;
using C = pair<P,W>;

#define X real()
#define Y imag()

const W EPS = (1e-10), pi = acosl(-1.0L), INF = 1e20;

W dot(P a, P b){ return a.X * b.X + a.Y * b.Y;}
W cross(P a, P b){ return a.X * b.Y - a.Y * b.X;}

int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if(cross(b,c) > EPS) return +1;
  if(cross(b,c) < -EPS) return -1;
  if(dot(b,c) < -EPS) return +2;
  if(norm(b) + EPS < norm(c)) return -2;
  return 0;
}

//円と円の交点
vector<P> cpcc(C a, C b){
  P ca = a.first, cb = b.first;
  W d = abs(ca-cb), ra = a.second, rb = b.second, s = (d+ra+rb)*0.5;
  W t = (ra*ra-rb*rb+d*d)*0.5/d, h = sqrt(s*(s-d)*(s-ra)*(s-rb))*2/d, t_ = t/d;
  P m = t_*cb + (1-t_)*ca;
  vector<P> cp(2,m);
  P n(-(ca-cb).Y,(ca-cb).X);
  n /= d;
  n *= h;
  cp[0] -= n;
  cp[1] += n;
  return cp;
}

W common_area(C a, C b){
  if(a.second > b.second) swap(a,b);
  P ca = a.first, cb = b.first;
  W ra = a.second, rb = b.second;
  if(ra < EPS) return 0;
  if(norm(ca - cb) < norm(ra - rb) + EPS)
    return min(ra*ra, rb*rb)*pi;
  if(norm(ca - cb) > norm(ra + rb) + EPS)
    return 0;
  vector<P> cp = cpcc(a,b);
  if(norm(cp[0] - cp[1]) < EPS) return 0;
  P aa = (cp[0]-ca)/(cp[1]-ca);
  P bb = (cp[0]-cb)/(cp[1]-cb);
  W theta_a = abs(atan2l(aa.Y,aa.X));
  W theta_b = abs(atan2l(bb.Y,bb.X));

  if(ccw(cp[0], cp[1], ca)*ccw(cp[0], cp[1], cb) >= 0){
    theta_a = max(2*pi - theta_a, theta_a);
    theta_b = min(2*pi - theta_b, theta_b);
  }else{
    theta_a = min(2*pi - theta_a, theta_a);
    theta_b = min(2*pi - theta_b, theta_b);
  }
  W sa = (theta_a-sinl(theta_a))*0.5, sb = (theta_b-sinl(theta_b))*0.5;
  W ans = ra*sa*ra + rb*sb*rb;
  return ans;
}

int main(){
  W x, y, r;
  cin >> x >> y >> r;
  C c1(P(x,y),r);
  cin >> x >> y >> r;
  C c2(P(x,y),r);
  cout << fixed << setprecision(20);
  cout << common_area(c1,c2) << endl;
}


#include <cmath>
#include <cassert>
#include <iomanip>
#include <algorithm>
#include <iostream>
#include <complex>
#include <cstdio>
#include <utility>
#include <vector>
using namespace std;

using W = long double;

using P = complex<W>;
using L = pair<P,P>;
using C = pair<P,W>;

#define X real()
#define Y imag()

const W EPS = (1e-10), pi = acosl(-1.0L), INF = 1e20;

W dot(P a, P b){ return a.X * b.X + a.Y * b.Y;}
W cross(P a, P b){ return a.X * b.Y - a.Y * b.X;}

int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if(cross(b,c) > EPS) return +1;
  if(cross(b,c) < -EPS) return -1;
  if(dot(b,c) < -EPS) return +2;
  if(norm(b) + EPS < norm(c)) return -2;
  return 0;
}

//円と円の交点
vector<P> cpcc(C a, C b){
  P ca = a.first, cb = b.first;
  W d = abs(ca-cb), ra = a.second, rb = b.second, s = (d+ra+rb)*0.5;
  W t = (ra*ra-rb*rb+d*d)*0.5/d, h = sqrt(s*(s-d)*(s-ra)*(s-rb))*2/d, t_ = t/d;
  P m = t_*cb + (1-t_)*ca;
  vector<P> cp(2,m);
  P n(-(ca-cb).Y,(ca-cb).X);
  n /= d;
  n *= h;
  cp[0] -= n;
  cp[1] += n;
  return cp;
}
// vector<P> cpcc(C a, C b){
//   // if(a.second < b.second) swap(a,b);
//   P ca = a.first, cb = b.first;
//   W d = abs(ca-cb), ra = a.second, rb = b.second, s = (d+ra+rb)*0.5;
//   W h = sqrt(s*(s-d)*(s-ra)*(s-rb))*2/d, t = sqrt(ra*ra-h*h), t_ = t/d;
//   P m = t_*cb + (1-t_)*ca;
//   vector<P> cp(2,m);
//   P n(-(ca-cb).Y,(ca-cb).X);
//   n /= d;
//   n *= h;
//   cp[0] -= n;
//   cp[1] += n;
//   return cp;
// }

W common_area(C a, C b){
  if(a.second > b.second) swap(a,b);
  P ca = a.first, cb = b.first;
  W ra = a.second, rb = b.second;
  if(ra < EPS) return 0;
  if(norm(ca - cb) < norm(ra - rb) + EPS)
    return min(ra*ra, rb*rb)*pi;
  if(norm(ca - cb) > norm(ra + rb) + EPS)
    return 0;
  vector<P> cp = cpcc(a,b);
  if(norm(cp[0] - cp[1]) < EPS) return 0;
  P aa = (cp[0]-ca)/(cp[1]-ca);
  P bb = (cp[0]-cb)/(cp[1]-cb);
  W theta_a = abs(atan2l(aa.Y,aa.X));
  W theta_b = abs(atan2l(bb.Y,bb.X));
  W d = abs(ca-cb), s = 0.5*(ra+rb+d);
  W ret = sqrt(4*s*(s-ra)*(s-rb)*(s-d));

  if(ccw(cp[0], cp[1], ca)*ccw(cp[0], cp[1], cb) >= 0){
    theta_a = max(2*pi - theta_a, theta_a);
    theta_b = min(2*pi - theta_b, theta_b);
  }else{
    theta_a = min(2*pi - theta_a, theta_a);
    theta_b = min(2*pi - theta_b, theta_b);
  }

  W sa = (theta_a-sinl(theta_a))*0.5, sb = (theta_b-sinl(theta_b))*0.5;

  cerr << fixed << setprecision(20) << pi << endl;
  cerr << fixed << setprecision(20) << theta_a << endl;
  cerr << fixed << setprecision(20) << sinl(theta_a) << endl;
  cerr << fixed << setprecision(20) << theta_b << endl;
  cerr << fixed << setprecision(20) << sinl(theta_b) << endl;
  cerr << fixed << setprecision(20) << ret << endl;
  W ans = ra*sa*ra + rb*sb*rb;
  // ans *= 0.5;
  cerr << fixed << setprecision(20) <<  (theta_a*ra*ra + theta_b*rb*rb)*0.5 - ret << endl;
  return ans;
}

int main(){
  W x, y, r;
  cin >> x >> y >> r;
  C c1(P(x,y),r);
  cin >> x >> y >> r;
  C c2(P(x,y),r);
  cout << fixed << setprecision(20);
  cout << common_area(c1,c2) << endl;
}


#include <cmath>
#include <cassert>
#include <iomanip>
#include <algorithm>
#include <iostream>
#include <complex>
#include <cstdio>
#include <utility>
#include <vector>
using namespace std;

using W = long double;

typedef complex<W> P;
typedef pair<P,P> L;
typedef pair<P,W> C;
#define X real()
#define Y imag()
const W EPS = (1e-10), pi = acos(-1.0L), INF = 1e20;

W dot(P a, P b){ return a.X * b.X + a.Y * b.Y;}
W cross(P a, P b){ return a.X * b.Y - a.Y * b.X;}

int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if(cross(b,c) > EPS) return +1;
  if(cross(b,c) < -EPS) return -1;
  if(dot(b,c) < -EPS) return +2;
  if(norm(b) + EPS < norm(c)) return -2;
  return 0;
}

//円と円の交点
vector<P> cpcc(C a, C b){
  P ca = a.first, cb = b.first;
  W d = abs(ca-cb), ra = a.second, rb = b.second, s = (d+ra+rb)*0.5;
  W t = (ra*ra-rb*rb+d*d)*0.5/d, h = sqrt(s*(s-d)*(s-ra)*(s-rb))*2/d, t_ = t/d;
  P m = t_*cb + (1-t_)*ca;
  vector<P> cp(2,m);
  P n(-(ca-cb).Y,(ca-cb).X);
  n /= d;
  n *= h;
  cp[0] -= n;
  cp[1] += n;
  return cp;
}

W common_area(C a, C b){
  if(a.second > b.second) swap(a,b);
  P ca = a.first, cb = b.first;
  W ra = a.second, rb = b.second;
  if(ra < EPS) return 0;
  if(norm(ca - cb) < norm(ra - rb) + EPS)
    return min(ra*ra, rb*rb)*pi;
  if(abs(ca - cb) > ra + rb + EPS) return 0;
  vector<P> cp = cpcc(a,b);
  if(norm(cp[0] - cp[1]) < EPS) return 0;
  P aa = (cp[0]-ca)/(cp[1]-ca);
  P bb = (cp[0]-cb)/(cp[1]-cb);
  W theta_a = abs(atan2l(aa.Y,aa.X));
  W theta_b = abs(atan2l(bb.Y,bb.X));
  W d = abs(ca-cb), s = 0.5*(ra+rb+d), ret = sqrt(4*s*(s-ra)*(s-rb)*(s-d));

  if(ccw(cp[0], cp[1], ca)*ccw(cp[0], cp[1], cb) >= 0){
    theta_a = max(2*pi - theta_a, theta_a);
    theta_b = min(2*pi - theta_b, theta_b);
  }else{
    theta_a = min(2*pi - theta_a, theta_a);
    theta_b = min(2*pi - theta_b, theta_b);
  }
  return (theta_a*ra*ra + theta_b*rb*rb)*0.5 - ret;
}

int main(){
  W x, y, r;
  cin >> x >> y >> r;
  C c1(P(x,y),r);
  cin >> x >> y >> r;
  C c2(P(x,y),r);
  cout << fixed << setprecision(18);
  cout << common_area(c1,c2) << endl;
}


#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define exist(c, x) (c).find(x) != (c).size()
#define int long long
#define what_is(x) cerr << #x << "\t" << x << '\n'
#define for(i, k, n) for (int i = (k); (k) < (n) ? i < (n) : i > (n); (k) < (n) ? ++i: --i)

const int MOD = 1'000'000'007;
const int OO = 9'876'543'210;

template<typename T, typename... Args>
void push_back(vector<T>& v, Args... args) {
    (v.push_back(args), ...);
}

template<typename... Args>
void readln(Args&... args) {
    ((cin >> args), ...);
}

template<typename... Args>
void println(Args... args) {
    ((cout << args << " "), ...);
}

template <typename T>
T next() {
	T input;
	cin >> input;
	return input;
}

void solve() {
	double x, y, r, x1, y1, r1;
	readln(x, y, r, x1, y1, r1);
	if (r > r1) {
		swap(r,r1);
		swap(x,x1);
		swap(y,y1);
	}
	double a, b;
	a = x1 - x;
	b = y1 - y;
	double d = a*a + b*b;
	d = sqrt(d);
	if (d >= r + r1) {
		cout << 0 << endl;
		return;
	}
	if (d + r <= r1) {
		cout << fixed << setprecision(20) << M_PI*r*r <<endl;
		return;
	}
	double k = (r*r - r1*r1 + d*d) / (2*d);
	double k1 = d - k;
	double cos = k/r;
	double cos1 = k1/r1;
	double ang = acos(cos);
	double sine = sin(ang);
	double ang1 = acos(cos1);
	double sine1 = sin(ang1);
	double area = r*r*(ang - sin(2*ang)/2.0);
	double area1=r1*r1*(ang1 - sin(2*ang1)/2.0);
	cout << fixed << setprecision(20) << area + area1;
}

signed main() {
    ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	// freopen("error.txt", "w", stderr);
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	int t;
	t = 1;
	//cin >> t;
	while (t--) {
		solve();
		cout << '\n';
	}
	// cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs\n";
}


#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define exist(c, x) (c).find(x) != (c).size()
#define int long long
#define what_is(x) cerr << #x << "\t" << x << '\n'
#define for(i, k, n) for (int i = (k); (k) < (n) ? i < (n) : i > (n); (k) < (n) ? ++i: --i)

const int MOD = 1'000'000'007;
const int OO = 9'876'543'210;
const double PI = 3.141'592'653;

template<typename T, typename... Args>
void push_back(vector<T>& v, Args... args) {
    (v.push_back(args), ...);
}

template<typename... Args>
void readln(Args&... args) {
    ((cin >> args), ...);
}

template<typename... Args>
void println(Args... args) {
    ((cout << args << " "), ...);
}

template <typename T>
T next() {
	T input;
	cin >> input;
	return input;
}

void solve() {
	double x, y, r, x1, y1, r1;
	readln(x, y, r, x1, y1, r1);
	if (r > r1) {
		swap(r,r1);
		swap(x,x1);
		swap(y,y1);
	}
	double a, b;
	a = x1 - x;
	b = y1 - y;
	double d = a*a + b*b;
	d = sqrt(d);
	if (d >= r + r1) {
		cout << 0 << endl;
		return;
	}
	if (d + r <= r1) {
		cout << fixed << setprecision(20) << PI*r*r <<endl;
		return;
	}
	double k = (r*r - r1*r1 + d*d) / (2*d);
	double k1 = d - k;
	double cos = k/r;
	double cos1 = k1/r1;
	double ang = acos(cos);
	double sine = sin(ang);
	double ang1 = acos(cos1);
	double sine1 = sin(ang1);
	double area = r*r*(ang - sin(2*ang)/2.0);
	double area1=r1*r1*(ang1 - sin(2*ang1)/2.0);
	cout << fixed << setprecision(20) << area + area1;
}

signed main() {
    ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	// freopen("error.txt", "w", stderr);
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	int t;
	t = 1;
	//cin >> t;
	while (t--) {
		solve();
		cout << '\n';
	}
	// cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs\n";
}


#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define exist(c, x) (c).find(x) != (c).size()
#define int long long
#define what_is(x) cerr << #x << "\t" << x << '\n'
#define for(i, k, n) for (int i = (k); (k) < (n) ? i < (n) : i > (n); (k) < (n) ? ++i: --i)

const int MOD = 1'000'000'007;
const int OO = 9'876'543'210;
const double PI = M_PI;

template<typename T, typename... Args>
void push_back(vector<T>& v, Args... args) {
    (v.push_back(args), ...);
}

template<typename... Args>
void readln(Args&... args) {
    ((cin >> args), ...);
}

template<typename... Args>
void println(Args... args) {
    ((cout << args << " "), ...);
}

template <typename T>
T next() {
	T input;
	cin >> input;
	return input;
}

void solve() {
	double x, y, r, x1, y1, r1;
	readln(x, y, r, x1, y1, r1);
	if (r > r1) {
		swap(r,r1);
		swap(x,x1);
		swap(y,y1);
	}
	double a, b;
	a = x1 - x;
	b = y1 - y;
	double d = a*a + b*b;
	d = sqrt(d);
	if (d >= r + r1) {
		cout << 0 << endl;
		return;
	}
	if (d + r <= r1) {
		cout << fixed << setprecision(20) << PI*r*r <<endl;
		return;
	}
	double k = (r*r - r1*r1 + d*d) / (2*d);
	double k1 = d - k;
	double cos = k/r;
	double cos1 = k1/r1;
	double ang = acos(cos);
	double sine = sin(ang);
	double ang1 = acos(cos1);
	double sine1 = sin(ang1);
	double area = r*r*(ang - sin(2*ang)/2.0);
	double area1=r1*r1*(ang1 - sin(2*ang1)/2.0);
	cout << fixed << setprecision(20) << area + area1;
}

signed main() {
    ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	// freopen("error.txt", "w", stderr);
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	int t;
	t = 1;
	//cin >> t;
	while (t--) {
		solve();
		cout << '\n';
	}
	// cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs\n";
}


#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define exist(c, x) (c).find(x) != (c).size()
#define int long long
#define what_is(x) cerr << #x << "\t" << x << '\n'
#define for(i, k, n) for (int i = (k); (k) < (n) ? i < (n) : i > (n); (k) < (n) ? ++i: --i)

const int MOD = 1'000'000'007;
const int OO = 9'876'543'210;
const long double PI = acos(-1.0);

template<typename T, typename... Args>
void push_back(vector<T>& v, Args... args) {
    (v.push_back(args), ...);
}

template<typename... Args>
void readln(Args&... args) {
    ((cin >> args), ...);
}

template<typename... Args>
void println(Args... args) {
    ((cout << args << " "), ...);
}

template <typename T>
T next() {
	T input;
	cin >> input;
	return input;
}

void solve() {
	long double x1, y1, r1, x2, y2, r2;
	readln(x1, y1, r1, x2, y2, r2);
	long double c1, c2, s1, s2;
    long double dist = hypot(x2 - x1, y2 - y1);
    cout << fixed << setprecision(20);
	if (dist >= r1 + r2 + 1e-7) {
        cout << 0.0;
		return;
	}
    if (dist <= abs(r2 - r1) + 1e-7) {
        cout << PI * min(r1, r2) * min(r1, r2);
		return;
	}
    c1 = 2.0 * acos((r1 * r1 - r2 * r2 + dist * dist) / (2.0 * r1 * dist));
    c2 = 2.0 * acos((r2 * r2 - r1 * r1 + dist * dist) / (2.0 * r2 * dist));
    s1 = r1 * r1 * (c1 - sin(c1)) / 2.0;
    s2 = r2 * r2 * (c2 - sin(c2)) / 2.0;
	cout << fixed << setprecision(20) << s1 + s2;
}

signed main() {
    ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	// freopen("error.txt", "w", stderr);
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	int t;
	t = 1;
	//cin >> t;
	while (t--) {
		solve();
		cout << '\n';
	}
	// cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs\n";
}


#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define exist(c, x) (c).find(x) != (c).size()
#define int long long
#define what_is(x) cerr << #x << "\t" << x << '\n'
#define for(i, k, n) for (int i = (k); (k) < (n) ? i < (n) : i > (n); (k) < (n) ? ++i: --i)

const int MOD = 1'000'000'007;
const int OO = 9'876'543'210;
const double PI = M_PI;

template<typename T, typename... Args>
void push_back(vector<T>& v, Args... args) {
    (v.push_back(args), ...);
}

template<typename... Args>
void readln(Args&... args) {
    ((cin >> args), ...);
}

template<typename... Args>
void println(Args... args) {
    ((cout << args << " "), ...);
}

template <typename T>
T next() {
	T input;
	cin >> input;
	return input;
}

void solve() {
	double x, y, r, x1, y1, r1;
	readln(x, y, r, x1, y1, r1);
	if (r > r1) {
		swap(r,r1);
		swap(x,x1);
		swap(y,y1);
	}
	double a, b;
	a = x1 - x;
	b = y1 - y;
	double d = a*a + b*b;
	d = sqrt(d);
	if (d >= r + r1) {
		cout << 0 << endl;
		return;
	}
	if (d + r <= r1) {
		cout << fixed << setprecision(20) << PI*r*r <<endl;
		return;
	}
	double k = (r*r - r1*r1 + d*d) / (2*d);
	double k1 = d - k;
	double cos = k/r;
	double cos1 = k1/r1;
	double ang = acos(cos);
	double sine = sin(ang);
	double ang1 = acos(cos1);
	double sine1 = sin(ang1);
	double area = r*r*(ang - sin(2*ang)/2.0);
	double area1=r1*r1*(ang1 - sin(2*ang1)/2.0);
	cout << fixed << setprecision(20) << area + area1;
}

signed main() {
    ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	// freopen("error.txt", "w", stderr);
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	int t;
	t = 1;
	//cin >> t;
	while (t--) {
		solve();
// 		cout << '\n';
	}
	// cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs\n";
}


#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define exist(c, x) (c).find(x) != (c).size()
#define int long long
#define what_is(x) cerr << #x << "\t" << x << '\n'
#define for(i, k, n) for (int i = (k); (k) < (n) ? i < (n) : i > (n); (k) < (n) ? ++i: --i)

const int MOD = 1'000'000'007;
const int OO = 9'876'543'210;
const double pi = M_PI;

template<typename T, typename... Args>
void push_back(vector<T>& v, Args... args) {
    (v.push_back(args), ...);
}

template<typename... Args>
void readln(Args&... args) {
    ((cin >> args), ...);
}

template<typename... Args>
void println(Args... args) {
    ((cout << args << " "), ...);
}

template <typename T>
T next() {
	T input;
	cin >> input;
	return input;
}

void solve() {
	double x, y, r, x1, y1, r1;
	readln(x, y, r, x1, y1, r1);
	if (r > r1) {
		swap(r,r1);
		swap(x,x1);
		swap(y,y1);
	}
	double a, b;
	a = x1 - x;
	b = y1 - y;
	double d = a*a + b*b;
	d = sqrt(d);
	if (d >= r + r1) {
		cout << 0 << endl;
		return;
	}
	if (d + r <= r1) {
		cout << fixed << setprecision(20) << pi*r*r <<endl;
		return;
	}
	double k = (r*r - r1*r1 + d*d) / (2*d);
	double k1 = d - k;
	double cos = k/r;
	double cos1 = k1/r1;
	double ang = acos(cos);
	double sine = sin(ang);
	double ang1 = acos(cos1);
	double sine1 = sin(ang1);
	double area = r*r*(ang - sin(2*ang)/2.0);
	double area1=r1*r1*(ang1 - sin(2*ang1)/2.0);
	cout << fixed << setprecision(20) << area + area1;
}

signed main() {
    ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	// freopen("error.txt", "w", stderr);
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	int t;
	t = 1;
	//cin >> t;
	while (t--) {
		solve();
		cout << '\n';
	}
	// cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs\n";
}


#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define exist(c, x) (c).find(x) != (c).size()
#define int long long
#define what_is(x) cerr << #x << "\t" << x << '\n'
#define for(i, k, n) for (int i = (k); (k) < (n) ? i < (n) : i > (n); (k) < (n) ? ++i: --i)

const int MOD = 1'000'000'007;
const int OO = 9'876'543'210;
const long double PI = acos(-1.0);

template<typename T, typename... Args>
void push_back(vector<T>& v, Args... args) {
    (v.push_back(args), ...);
}

template<typename... Args>
void readln(Args&... args) {
    ((cin >> args), ...);
}

template<typename... Args>
void println(Args... args) {
    ((cout << args << " "), ...);
}

template <typename T>
T next() {
	T input;
	cin >> input;
	return input;
}

void solve() {
	long double x1, y1, r1, x2, y2, r2;
	readln(x1, y1, r1, x2, y2, r2);
	long double c1, c2, s1, s2;
    long double dist = hypot(x2 - x1, y2 - y1);
    cout << fixed << setprecision(20);
	if (dist >= r1 + r2 + 1e-7)
        cout << 0.0;
    if (dist <= abs(r2 - r1) + 1e-7)
        cout << PI * min(r1, r2) * min(r1, r2);

    c1 = 2.0 * acos((r1 * r1 - r2 * r2 + dist * dist) / (2.0 * r1 * dist));
    c2 = 2.0 * acos((r2 * r2 - r1 * r1 + dist * dist) / (2.0 * r2 * dist));
    s1 = r1 * r1 * (c1 - sin(c1)) / 2.0;
    s2 = r2 * r2 * (c2 - sin(c2)) / 2.0;
	cout << fixed << setprecision(20) << s1 + s2;
}

signed main() {
    ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	// freopen("error.txt", "w", stderr);
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	int t;
	t = 1;
	//cin >> t;
	while (t--) {
		solve();
		cout << '\n';
	}
	// cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs\n";
}


#include<iostream>
#include<iomanip>
#include<math.h>

using namespace std;

typedef long long LL;
const long double pi=acos(-1.0);
const long double eps=1e-7;

#define sq(A) ((A)*(A))

long double dist2(long double x1, long double x2, long double y1, long double y2){
	return sq(x1-x2)+sq(y1-y2);
}

long double dist(long double x1, long double x2, long double y1, long double y2){
	return sqrt(sq(x1-x2)+sq(y1-y2));
}

long double cross(long double x1, long double y1, long double x2, long double y2, long double x3, long double y3){
	return (x2-x1)*(y3-y1)-(x3-x1)*(y2-y1);
}

int main(){
	LL x[4], y[4], r[2], d2;
	long double a, b, d;
	cout << setprecision(30);
	for(int i=0;i<2;++i) cin >> x[i] >> y[i] >> r[i];
	d2=sq(x[0]-x[1])+sq(y[0]-y[1]);
	if(r[0]>r[1]) swap(r[0], r[1]);
	if(d2>=sq(r[0]+r[1])){
		cout << 0.0 << '\n';
		return 0;
	}
	if(d2<=sq(r[1]-r[0])){
		cout << pi*sq(r[0]) << '\n';
		return 0;
	}
	d=sqrt(d2);
	a=acos((sq(r[1])+d2-sq(r[0]))/(2*d*r[1]));
	b=acos((sq(r[0])+d2-sq(r[1]))/(2*d*r[0]));
	cout << sq(r[1])*(a-sin(a)*cos(a))+sq(r[0])*(b-sin(b)*cos(b)) << '\n';
	return 0;
}


#include<iostream>
#include<iomanip>
#include<math.h>

using namespace std;

typedef long long LL;
const long double pi=acos(-1.0);
const long double eps=1e-7;

#define sq(A) ((A)*(A))

long double dist2(long double x1, long double x2, long double y1, long double y2){
	return sq(x1-x2)+sq(y1-y2);
}

long double dist(long double x1, long double x2, long double y1, long double y2){
	return sqrt(sq(x1-x2)+sq(y1-y2));
}

long double cross(long double x1, long double y1, long double x2, long double y2, long double x3, long double y3){
	return (x2-x1)*(y3-y1)-(x3-x1)*(y2-y1);
}

int main(){
	LL x[4], y[4], r[2], d2;
	long double l, a, b, d;
	cout << setprecision(15);
	for(int i=0;i<2;++i) cin >> x[i] >> y[i] >> r[i];
	d2=sq(x[0]-x[1])+sq(y[0]-y[1]);
	if(r[0]>r[1]) swap(r[0], r[1]);
	if(d2>=sq(r[0]+r[1])){
		cout << 0.0 << '\n';
		return 0;
	}
	if(d2<=sq(r[1]-r[0])){
		cout << pi*sq(r[0]) << '\n';
		return 0;
	}
	d=sqrt(d2);
	l=(sq(r[1])-sq(r[0])+d2)/(2*d);
	a=acos(l/r[1]);
	b=acos((d-l)/r[0]);
	cout << a*sq(r[1])+b*sq(r[0])-sq(r[1])*cos(a)*sin(a)-sq(r[0])*cos(b)*sin(b) << '\n';
	return 0;
}