#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int inf = 0x3f3f3f3f;
map<LL, vector<pair<LL, LL>>> m;
vector<pair<LL, LL>> ans;
LL arr[1551], pre[1551], n, maxs = 0;
bool cmp(const pair<LL, LL> &a, const pair<LL, LL> &b) {
	if (a.first == b.first)
		return a.second < b.second;
	return a.first < b.first;
}
int main()
{
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> arr[i];
		pre[i] = pre[i - 1] + arr[i];
	}
	for (int i = 0; i <= n; ++i)
		for (int j = i + 1; j <= n; ++j)
			m[pre[j] - pre[i]].push_back(make_pair(i + 1, j));
	for (map<LL, vector<pair<LL, LL>>>::iterator it = m.begin(); it != m.end(); ++it) {
		vector<pair<LL, LL>> &temp = it->second, res;
		//sort(temp.begin(), temp.end(), cmp);
		int left = 0;
		for (auto i : temp) {
			if (i.first > left) {
				res.push_back(i);
				left = i.second;
			}
		}
		if (res.size() > maxs) {
			maxs = res.size();
			ans = res;
		}
	}
	cout << maxs << endl;
	for (auto i : ans)
		cout << i.first << " " << i.second << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int inf = 0x3f3f3f3f;
map<LL, vector<pair<LL, LL>>> m;
vector<pair<LL, LL>> ans;
LL arr[15510], pre[15510], n, maxs = 0;
int main()
{
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> arr[i];
		pre[i] = pre[i - 1] + arr[i];
	}
	for (int i = 0; i <= n; ++i)
		for (int j = i + 1; j <= n; ++j)
			m[pre[j] - pre[i]].push_back(make_pair(i + 1, j));
	for (map<LL, vector<pair<LL, LL>>>::iterator it = m.begin(); it != m.end(); ++it) {
		vector<pair<LL, LL>> &temp = it->second, res;
		int left = 0;
		for (auto i : temp) {
			if (i.first > left) {
				res.push_back(i);
				left = i.second;
			}
		}
		if (res.size() > maxs) {
			maxs = res.size();
			ans = res;
		}
	}
	cout << maxs << endl;
	for (auto i : ans)
		cout << i.first << " " << i.second << endl;
}


#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 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;
bool comp(const pair<int,int>& a,const pair<int,int>& b){
	if(a.s==b.s)return a.f<b.f;
	return a.s < b.s;

}
int main()
{
	std::ios::sync_with_stdio(false);
	map<int,std::vector<pair<int,int>>> m;
	int n;
	cin>>n;
	vi v(n);
	for(auto& itr:v)cin>>itr;
	for(int i=0;i<n;i++){
		int sum=0;
		for(int j=i;j<n;j++){
			sum+=v[j];
			m[sum].push_back({i+1,j+1});
		}
	}
	int size=0;
	vector<pii> tmp,ans;
	for(auto& itr:m){
		sort(all(itr.s),comp);
		tmp={itr.s[0]};
		for(int i=1;i<itr.s.size();i++){
			if(tmp.back().s <itr.s[i].f){
				tmp.emplace_back(move(itr.s[i]));
			}
		}
		if(size<tmp.size()){
			size=tmp.size();
			ans = move(tmp);
		}
	}
	cout<<size<<endl;
	for(auto& itr:ans){
		cout<<itr.f<<" "<<itr.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 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;
bool comp(const pair<int,int>& a,const pair<int,int>& b){
	if(a.s==b.s)return a.f<b.f;
	return a.s < b.s;

}
int main()
{
	std::ios::sync_with_stdio(false);
	map<int,std::vector<pair<int,int>>> m;
	int n;
	cin>>n;
	vi v(n);
	for(auto& itr:v)cin>>itr;
	for(int i=0;i<n;i++){
		int sum=0;
		for(int j=i;j<n;j++){
			sum+=v[j];
			m[sum].push_back({i+1,j+1});
			//if(sum==-5)cout<<"FIve here:"<<i+1<<" "<<j+1<<endl;
		}
	}
	int maxsum=0,size=0;
	for(auto& itr:m){
		sort(all(itr.s),comp);
		int i=1,j=0;
		for(;i<itr.s.size();i++){
			if(itr.s[j].s <itr.s[i].f){
				itr.s[++j] = itr.s[i];
			}
		}
		itr.s.erase(itr.s.begin()+j+1,itr.s.end());
		/*if(itr.f==-5){
			cout<<"Counting";
			for(i=0;i<itr.s.size();i++){
				if(itr.f==-5)cout<<"Taken "<<itr.s[i].f<<" "<<itr.s[i].s<<endl;
			}
		}*/
		if(size<itr.s.size()){
			size=itr.s.size();
			maxsum=itr.f;
		}
	}
	cout<<size<<endl;
	for(auto& itr:m[maxsum]){
		cout<<itr.f<<" "<<itr.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 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;
inline bool comp(const pair<int,int>& a,const pair<int,int>& b){
	if(a.s==b.s)return a.f<b.f;
	return a.s < b.s;

}
int main()
{
	std::ios::sync_with_stdio(false);
	unordered_map<int,std::vector<pair<int,int>>> m;
	int n;
	cin>>n;
	vi v(n);
	for(auto& itr:v){
		cin>>itr;
		itr+=*(&itr-1);
	}
	for(int i=0;i<n;++i){
		for(int j=i;j<n;++j){
			m[v[j]-v[i-1]].push_back({i+1,j+1});
		}
	}
	int size=0;
	vector<pii> tmp,ans;
	for(auto& itr:m){
		sort(all(itr.s),comp);
		tmp={itr.s[0]};
		for(int i=1;i<itr.s.size();i++){
			if(tmp.back().s <itr.s[i].f){
				tmp.emplace_back(move(itr.s[i]));
			}
		}
		if(size<tmp.size()){
			size=tmp.size();
			ans = move(tmp);
		}
	}
	cout<<size<<endl;
	for(auto& itr:ans){
		cout<<itr.f<<" "<<itr.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 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;
bool comp(const pair<int,int>& a,const pair<int,int>& b){
	if(a.s==b.s)return a.f<b.f;
	return a.s < b.s;

}
int main()
{
	std::ios::sync_with_stdio(false);
	unordered_map<int,std::vector<pair<int,int>>> m;
	int n;
	cin>>n;
	vi v(n);
	for(auto& itr:v){
		cin>>itr;
		itr+=*(&itr-1);
	}
	for(int i=0;i<n;i++){
		for(int j=i;j<n;j++){
			m[v[j]-v[i-1]].push_back({i+1,j+1});
		}
	}
	int size=0;
	vector<pii> tmp,ans;
	for(auto& itr:m){
		sort(all(itr.s),comp);
		tmp={itr.s[0]};
		for(int i=1;i<itr.s.size();i++){
			if(tmp.back().s <itr.s[i].f){
				tmp.emplace_back(move(itr.s[i]));
			}
		}
		if(size<tmp.size()){
			size=tmp.size();
			ans = move(tmp);
		}
	}
	cout<<size<<endl;
	for(auto& itr:ans){
		cout<<itr.f<<" "<<itr.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 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;
bool comp(const pair<int,int>& a,const pair<int,int>& b){
	if(a.s==b.s)return a.f<b.f;
	return a.s < b.s;

}
int main()
{
	std::ios::sync_with_stdio(false);
	map<int,std::vector<pair<int,int>>> m;
	int n;
	cin>>n;
	vi v(n);
	for(auto& itr:v)cin>>itr;
	for(int i=0;i<n;i++){
		int sum=0;
		for(int j=i;j<n;j++){
			sum+=v[j];
			if(m.find(sum)==m.end())m[sum]=vector<pair<int,int>>{};
			m[sum].push_back({i+1,j+1});
			//if(sum==-5)cout<<"FIve here:"<<i+1<<" "<<j+1<<endl;
		}
	}
	int maxsum=0,size=0;
	for(auto& itr:m){
		sort(all(itr.s),comp);
		int i=1,j=0;
		for(;i<itr.s.size();i++){
			if(itr.s[j].s <itr.s[i].f){
				itr.s[++j] = itr.s[i];
			}
		}
		itr.s.erase(itr.s.begin()+j+1,itr.s.end());
		/*if(itr.f==-5){
			cout<<"Counting";
			for(i=0;i<itr.s.size();i++){
				if(itr.f==-5)cout<<"Taken "<<itr.s[i].f<<" "<<itr.s[i].s<<endl;
			}
		}*/
		if(size<itr.s.size()){
			size=itr.s.size();
			maxsum=itr.f;
		}
	}
	cout<<size<<endl;
	for(auto& itr:m[maxsum]){
		cout<<itr.f<<" "<<itr.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 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;
bool comp(const pair<int,int>& a,const pair<int,int>& b){
	if(a.s==b.s)return a.f<b.f;
	return a.s < b.s;

}
int main()
{
	std::ios::sync_with_stdio(false);
	unordered_map<int,std::vector<pair<int,int>>> m;
	int n;
	cin>>n;
	vi v(n);
	for(auto& itr:v)cin>>itr;
	for(int i=0;i<n;i++){
		int sum=0;
		for(int j=i;j<n;j++){
			sum+=v[j];
			m[sum].push_back({i+1,j+1});
		}
	}
	int size=0;
	vector<pii> tmp,ans;
	for(auto& itr:m){
		sort(all(itr.s),comp);
		tmp={itr.s[0]};
		for(int i=1;i<itr.s.size();i++){
			if(tmp.back().s <itr.s[i].f){
				tmp.emplace_back(move(itr.s[i]));
			}
		}
		if(size<tmp.size()){
			size=tmp.size();
			ans = move(tmp);
		}
	}
	cout<<size<<endl;
	for(auto& itr:ans){
		cout<<itr.f<<" "<<itr.s<<endl;
	}
	return 0;
}


#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<LL, LL> pLL;
typedef pair<LL, int> pLi;
typedef pair<int, LL> piL;;
typedef pair<int, int> pii;
typedef unsigned long long uLL;

#define x first
#define y second
#define lson rt<<1
#define rson rt<<1|1
#define lowbit(x) x&(-x)
#define name2str(name) (#name)
#define bug printf("*********\n")
#define debug(x) cout<<#x"=["<<x<<"]" <<endl
#define FIN freopen("in","r",stdin)
#define IO ios::sync_with_stdio(false),cin.tie(0)

const double eps = 1e-8;
const int mod = 1e9 + 7;
const int maxn = 1e4 + 7;
const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3fLL;

int n;
int a[maxn], vis[maxn];
LL sum[maxn];
vector<LL> s;
vector<pii> v[maxn], seg;

int main() {
#ifndef ONLINE_JUDGE
    FIN;
#endif
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]);
        sum[i] = sum[i-1] + a[i];
        for(int j = 1; j <= i; ++j) {
            s.push_back(sum[i] - sum[j-1]);
        }
    }
    sort(s.begin(), s.end());
    s.erase(unique(s.begin(), s.end()), s.end());
    int sz = s.size();
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= i; ++j) {
            int x = sum[i] - sum[j-1];
            int p = lower_bound(s.begin(), s.end(), x) - s.begin() + 1;
            v[p].push_back({j, i});
        }
    }
    for(int i = 1; i <= sz; ++i) sort(v[i].begin(), v[i].end());
    int ans = 0;
    for(int i = 1; i <= sz; ++i) {
        int las = 0, cnt = 0;
        for(int j = 0; j < v[i].size(); ++j) vis[j] = 0;
        for(int j = 0; j < v[i].size(); ++j) {
            if(v[i][j].x > las) {
                cnt++;
                vis[j] = 1;
                las = v[i][j].y;
            }
        }
        if(cnt > ans) {
            seg.clear();
            ans = cnt;
            for(int j = 0; j < v[i].size(); ++j) {
                if(vis[j]) {
                    seg.push_back({v[i][j]});
                }
            }
        }
    }
    printf("%d\n", ans);
    for(auto x : seg) {
        printf("%d %d\n", x.x, x.y);
    }
    return 0;
}


#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<LL, LL> pLL;
typedef pair<LL, int> pLi;
typedef pair<int, LL> piL;;
typedef pair<int, int> pii;
typedef unsigned long long uLL;

#define x first
#define y second
#define lson rt<<1
#define rson rt<<1|1
#define lowbit(x) x&(-x)
#define name2str(name) (#name)
#define bug printf("*********\n")
#define debug(x) cout<<#x"=["<<x<<"]" <<endl
#define FIN freopen("in","r",stdin)
#define IO ios::sync_with_stdio(false),cin.tie(0)

const double eps = 1e-8;
const int mod = 1e9 + 7;
const int maxn = 2e6 + 7;
const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3fLL;

int n;
int a[maxn], vis[maxn];
LL sum[maxn];
vector<LL> s;
vector<pii> v[maxn], seg;

int main() {
#ifndef ONLINE_JUDGE
    FIN;
#endif
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]);
        sum[i] = sum[i-1] + a[i];
        for(int j = 1; j <= i; ++j) {
            s.push_back(sum[i] - sum[j-1]);
        }
    }
    sort(s.begin(), s.end());
    s.erase(unique(s.begin(), s.end()), s.end());
    int sz = s.size();
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= i; ++j) {
            int x = sum[i] - sum[j-1];
            int p = lower_bound(s.begin(), s.end(), x) - s.begin() + 1;
            v[p].push_back({j, i});
        }
    }
    for(int i = 1; i <= sz; ++i) sort(v[i].begin(), v[i].end());
    int ans = 0;
    for(int i = 1; i <= sz; ++i) {
        int las = 0, cnt = 0;
        for(int j = 0; j < v[i].size(); ++j) vis[j] = 0;
        for(int j = 0; j < v[i].size(); ++j) {
            if(v[i][j].x > las) {
                cnt++;
                vis[j] = 1;
                las = v[i][j].y;
            }
        }
        if(cnt > ans) {
            seg.clear();
            ans = cnt;
            for(int j = 0; j < v[i].size(); ++j) {
                if(vis[j]) {
                    seg.push_back({v[i][j]});
                }
            }
        }
    }
    printf("%d\n", ans);
    for(auto x : seg) {
        printf("%d %d\n", x.x, x.y);
    }
    return 0;
}


#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<LL, LL> pLL;
typedef pair<LL, int> pLi;
typedef pair<int, LL> piL;;
typedef pair<int, int> pii;
typedef unsigned long long uLL;

#define x first
#define y second
#define lson rt<<1
#define rson rt<<1|1
#define lowbit(x) x&(-x)
#define name2str(name) (#name)
#define bug printf("*********\n")
#define debug(x) cout<<#x"=["<<x<<"]" <<endl
#define FIN freopen("in","r",stdin)
#define IO ios::sync_with_stdio(false),cin.tie(0)

const double eps = 1e-8;
const int mod = 1e9 + 7;
const int maxn = 2e6 + 7;
const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3fLL;

int n;
int a[maxn], vis[maxn];
LL sum[maxn];
vector<LL> s;
vector<pii> v[maxn], seg;

int main() {
#ifndef ONLINE_JUDGE
    FIN;
#endif
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]);
        sum[i] = sum[i-1] + a[i];
        for(int j = 1; j <= i; ++j) {
            s.push_back(sum[i] - sum[j-1]);
        }
    }
    sort(s.begin(), s.end());
    s.erase(unique(s.begin(), s.end()), s.end());
    int sz = s.size();
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= i; ++j) {
            int x = sum[i] - sum[j-1];
            int p = lower_bound(s.begin(), s.end(), x) - s.begin();
            v[p].push_back({i, j});
        }
    }
    for(int i = 0; i < sz; ++i) sort(v[i].begin(), v[i].end());
    int ans = 0;
    for(int i = 0; i < sz; ++i) {
        int las = 0, cnt = 0;
        for(int j = 0; j < v[i].size(); ++j) vis[j] = 0;
        for(int j = 0; j < v[i].size(); ++j) {
            if(v[i][j].y > las) {
                cnt++;
                vis[j] = 1;
                las = v[i][j].x;
            }
        }
        if(cnt > ans) {
            seg.clear();
            ans = cnt;
            for(int j = 0; j < v[i].size(); ++j) {
                if(vis[j]) {
                    seg.push_back({v[i][j]});
                }
            }
        }
    }
    printf("%d\n", ans);
    for(auto x : seg) {
        printf("%d %d\n", x.y, x.x);
    }
    return 0;
}


#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<LL, LL> pLL;
typedef pair<LL, int> pLi;
typedef pair<int, LL> piL;;
typedef pair<int, int> pii;
typedef unsigned long long uLL;

#define x first
#define y second
#define lson rt<<1
#define rson rt<<1|1
#define lowbit(x) x&(-x)
#define name2str(name) (#name)
#define bug printf("*********\n")
#define debug(x) cout<<#x"=["<<x<<"]" <<endl
#define FIN freopen("in","r",stdin)
#define IO ios::sync_with_stdio(false),cin.tie(0)

const double eps = 1e-8;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 7;
const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3fLL;

int n;
int a[maxn], vis[maxn];
LL sum[maxn];
vector<LL> s;
vector<pii> v[maxn], seg;

int main() {
#ifndef ONLINE_JUDGE
    FIN;
#endif
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]);
        sum[i] = sum[i-1] + a[i];
        for(int j = 1; j <= i; ++j) {
            s.push_back(sum[i] - sum[j-1]);
        }
    }
    sort(s.begin(), s.end());
    s.erase(unique(s.begin(), s.end()), s.end());
    int sz = s.size();
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= i; ++j) {
            int x = sum[i] - sum[j-1];
            int p = lower_bound(s.begin(), s.end(), x) - s.begin() + 1;
            v[p].push_back({j, i});
        }
    }
    for(int i = 1; i <= sz; ++i) sort(v[i].begin(), v[i].end());
    int ans = 0;
    for(int i = 1; i <= sz; ++i) {
        int las = 0, cnt = 0;
        for(int j = 0; j < v[i].size(); ++j) vis[j] = 0;
        for(int j = 0; j < v[i].size(); ++j) {
            if(v[i][j].x > las) {
                cnt++;
                vis[j] = 1;
                las = v[i][j].y;
            }
        }
        if(cnt > ans) {
            seg.clear();
            ans = cnt;
            for(int j = 0; j < v[i].size(); ++j) {
                if(vis[j]) {
                    seg.push_back({v[i][j]});
                }
            }
        }
    }
    printf("%d\n", ans);
    for(auto x : seg) {
        printf("%d %d\n", x.x, x.y);
    }
    return 0;
}


#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<LL, LL> pLL;
typedef pair<LL, int> pLi;
typedef pair<int, LL> piL;;
typedef pair<int, int> pii;
typedef unsigned long long uLL;

#define x first
#define y second
#define lson rt<<1
#define rson rt<<1|1
#define lowbit(x) x&(-x)
#define name2str(name) (#name)
#define bug printf("*********\n")
#define debug(x) cout<<#x"=["<<x<<"]" <<endl
#define FIN freopen("in","r",stdin)
#define IO ios::sync_with_stdio(false),cin.tie(0)

const double eps = 1e-8;
const int mod = 1e9 + 7;
const int maxn = 2e6 + 7;
const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3fLL;

int n;
int a[maxn], vis[maxn];
LL sum[maxn];
vector<LL> s;
vector<pii> v[maxn], seg;

int main() {
#ifndef ONLINE_JUDGE
    FIN;
#endif
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]);
        sum[i] = sum[i-1] + a[i];
        for(int j = 1; j <= i; ++j) {
            s.push_back(sum[i] - sum[j-1]);
        }
    }
    sort(s.begin(), s.end());
    s.erase(unique(s.begin(), s.end()), s.end());
    int sz = s.size();
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= i; ++j) {
            int x = sum[i] - sum[j-1];
            int p = lower_bound(s.begin(), s.end(), x) - s.begin() + 1;
            v[p].push_back({j, i});
        }
    }
    for(int i = 1; i <= sz; ++i) sort(v[i].begin(), v[i].end());
    int ans = 0;
    for(int i = 1; i <= sz; ++i) {
        int las = 0, cnt = 0;
        for(int j = 0; j < v[i].size(); ++j) vis[j] = 0;
        for(int j = 0; j < v[i].size(); ++j) {
            if(v[i][j].x >= las) {
                cnt++;
                vis[j] = 1;
                las = v[i][j].y;
            }
        }
        if(cnt > ans) {
            seg.clear();
            ans = cnt;
            for(int j = 0; j < v[i].size(); ++j) {
                if(vis[j]) {
                    seg.push_back({v[i][j]});
                }
            }
        }
    }
    printf("%d\n", ans);
    for(auto x : seg) {
        printf("%d %d\n", x.x, x.y);
    }
    return 0;
}


#pragma GCC optimize("Ofast,no-stack-protector")
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define pb push_back
#define F first
#define S second
#define ld long double
#define ll int32_t
#define endl '\n'
#define eb emplace_back
#define pb push_back
#define TIME 1.0*clock()/CLOCKS_PER_SEC
#define pii pair < int32_t , int32_t >
#define Endl '\n'
#define pll pair <ll,ll>
using namespace std;
using namespace __gnu_pbds;
typedef tree <ll,null_type,less <ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
mt19937_64 randomizer(chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
int mod = 1e9+7;
const int number_for_MO = 1e4+111;
const int size_for_segment_trees = 1e6;
int32_t FFTM = 998244353;
const int32_t N = 50000;
int32_t SX[4] = {0 , 1 , -1 , 0};
int32_t SY[4] = {1 , 0 , 0 , -1};
vector <pll> g1[size_for_segment_trees];
bool comp (pll a1,pll a2)
{
    return (a1.S)<a2.S;
}
int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifdef CHUCHUNDRA
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#else
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif
ll n;
cin>>n;
vector <ll> sums;
vector <ll> a(n);
for (int i = 0;i < n;i++)
    cin>>a[i];
for (int i = 0;i < n;i++)
{
    ll ss = 0;
    for (int j = i;j < n;j++)
    {
        ss+=a[j];
        sums.pb(ss);
    }
}
sort(sums.begin(),sums.end());
vector <ll> s2;
s2.pb(sums[0]);
for (int i = 1;i < sums.size();i++)
    if (sums[i]!=sums[i-1]) s2.pb(sums[i]);
for (int i = 0;i < n;i++)
{
    ll ss = 0;
    for (int j = i;j < n;j++)
    {
        ss+=a[j];
        ll point = lower_bound(s2.begin(),s2.end(),ss)-s2.begin();
        g1[point].pb({i,j});
    }
}
ll ans = 0;
ll posit = 0;
for (int i = 0;i < s2.size();++i)
    sort(g1[i].begin(),g1[i].end(),comp);
for (int i = 0;i < s2.size();++i)
{
    ll kol = 0;
    ll mux = -1;
for (auto to:g1[i])
    {
if (to.F>mux) {++kol;mux = max(mux,to.S);}
}
    ans = max(ans,kol);
if (ans==kol) posit = s2[i];
}
vector <pll> answ;
ll mex = -1;
ll pu = lower_bound(s2.begin(),s2.end(),posit)-s2.begin();
for (auto to:g1[pu])
{
if (to.F>mex) {mex = max(mex,to.S);answ.pb(to);
}
}
cout<<answ.size()<<'\n';
for (auto to:answ)
cout<<to.F+1<<" "<<to.S+1<<'\n';
return 0;
}
/*
Я всё вижу, чучундры! ;=)
*/
/*
Я всё слышу, чучундры! ;=)
*/


#pragma GCC optimize("Ofast,no-stack-protector")
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define pb push_back
#define F first
#define S second
#define ld long double
#define ll int32_t
#define endl '\n'
#define eb emplace_back
#define pb push_back
#define TIME 1.0*clock()/CLOCKS_PER_SEC
#define pii pair < int32_t , int32_t >
#define Endl '\n'
#define pll pair <ll,ll>
using namespace std;
using namespace __gnu_pbds;
typedef tree <ll,null_type,less <ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
mt19937_64 randomizer(chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
int mod = 1e9+7;
const int number_for_MO = 1e4+111;
const int size_for_segment_trees = 1e7;
int32_t FFTM = 998244353;
const int32_t N = 50000;
int32_t SX[4] = {0 , 1 , -1 , 0};
int32_t SY[4] = {1 , 0 , 0 , -1};
vector <pll> g1[size_for_segment_trees];
bool comp (pll a1,pll a2)
{
    return (a1.S)<a2.S;
}
int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifdef CHUCHUNDRA
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#else
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif
ll n;
cin>>n;
vector <ll> sums;
vector <ll> a(n);
for (int i = 0;i < n;i++)
    cin>>a[i];
for (int i = 0;i < n;i++)
{
    ll ss = 0;
    for (int j = i;j < n;j++)
    {
        ss+=a[j];
        sums.pb(ss);
    }
}
sort(sums.begin(),sums.end());
vector <ll> s2;
s2.pb(sums[0]);
for (int i = 1;i < sums.size();i++)
    if (sums[i]!=sums[i-1]) s2.pb(sums[i]);
for (int i = 0;i < n;i++)
{
    ll ss = 0;
    for (int j = i;j < n;j++)
    {
        ss+=a[j];
        ll point = lower_bound(s2.begin(),s2.end(),ss)-s2.begin();
        g1[point].pb({i,j});
    }
}
ll ans = 0;
ll posit = 0;
for (int i = 0;i < s2.size();++i)
    sort(g1[i].begin(),g1[i].end(),comp);
for (int i = 0;i < s2.size();++i)
{
    ll kol = 0;
    ll mux = -1;
for (auto to:g1[i])
    {
if (to.F>mux) {++kol;mux = max(mux,to.S);}
}
    ans = max(ans,kol);
if (ans==kol) posit = s2[i];
}
vector <pll> answ;
ll mex = -1;
ll pu = lower_bound(s2.begin(),s2.end(),posit)-s2.begin();
for (auto to:g1[pu])
{
if (to.F>mex) {mex = max(mex,to.S);answ.pb(to);
}
}
cout<<answ.size()<<'\n';
for (auto to:answ)
cout<<to.F+1<<" "<<to.S+1<<'\n';
return 0;
}
/*
Я всё вижу, чучундры! ;=)
*/
/*
Я всё слышу, чучундры! ;=)
*/


#pragma GCC optimize("Ofast,no-stack-protector")
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define pb push_back
#define F first
#define S second
#define ld long double
#define ll int32_t
#define endl '\n'
#define eb emplace_back
#define pb push_back
#define TIME 1.0*clock()/CLOCKS_PER_SEC
#define pii pair < int32_t , int32_t >
#define Endl '\n'
#define pll pair <ll,ll>
using namespace std;
using namespace __gnu_pbds;
typedef tree <ll,null_type,less <ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
mt19937_64 randomizer(chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
int mod = 1e9+7;
const int number_for_MO = 1e4+111;
const int size_for_segment_trees = 1500*(1501)/2;
int32_t FFTM = 998244353;
const int32_t N = 50000;
int32_t SX[4] = {0 , 1 , -1 , 0};
int32_t SY[4] = {1 , 0 , 0 , -1};
vector <pll> g1[size_for_segment_trees];
bool comp (pll a1,pll a2)
{
    return (a1.S)<a2.S;
}
int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifdef CHUCHUNDRA
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#else
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif
ll n;
cin>>n;
vector <ll> sums;
vector <ll> a(n);
for (int i = 0;i < n;i++)
    cin>>a[i];
for (int i = 0;i < n;i++)
{
    ll ss = 0;
    for (int j = i;j < n;j++)
    {
        ss+=a[j];
        sums.pb(ss);
    }
}
sort(sums.begin(),sums.end());
vector <ll> s2;
s2.pb(sums[0]);
for (int i = 1;i < sums.size();i++)
    if (sums[i]!=sums[i-1]) s2.pb(sums[i]);
for (int i = 0;i < n;i++)
{
    ll ss = 0;
    for (int j = i;j < n;j++)
    {
        ss+=a[j];
        ll point = lower_bound(s2.begin(),s2.end(),ss)-s2.begin();
        g1[point].pb({i,j});
    }
}
ll ans = 0;
ll posit = 0;
for (int i = 0;i < s2.size();++i)
    sort(g1[i].begin(),g1[i].end(),comp);
for (int i = 0;i < s2.size();++i)
{
    ll kol = 0;
    ll mux = -1;
for (auto to:g1[i])
    {
if (to.F>mux) {++kol;mux = max(mux,to.S);}
}
    ans = max(ans,kol);
if (ans==kol) posit = s2[i];
}
vector <pll> answ;
ll mex = -1;
ll pu = lower_bound(s2.begin(),s2.end(),posit)-s2.begin();
for (auto to:g1[pu])
{
if (to.F>mex) {mex = max(mex,to.S);answ.pb(to);
}
}
cout<<answ.size()<<'\n';
for (auto to:answ)
cout<<to.F+1<<" "<<to.S+1<<'\n';
return 0;
}
/*
Я всё вижу, чучундры! ;=)
*/
/*
Я всё слышу, чучундры! ;=)
*/


#pragma GCC optimize("Ofast,no-stack-protector")
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define pb push_back
#define F first
#define S second
#define ld long double
#define ll int32_t
#define endl '\n'
#define eb emplace_back
#define pb push_back
#define TIME 1.0*clock()/CLOCKS_PER_SEC
#define pii pair < int32_t , int32_t >
#define Endl '\n'
#define pll pair <ll,ll>
using namespace std;
using namespace __gnu_pbds;
typedef tree <ll,null_type,less <ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
mt19937_64 randomizer(chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
int mod = 1e9+7;
const int number_for_MO = 1e4+111;
const int size_for_segment_trees = 1e5;
int32_t FFTM = 998244353;
const int32_t N = 50000;
int32_t SX[4] = {0 , 1 , -1 , 0};
int32_t SY[4] = {1 , 0 , 0 , -1};
vector <pll> g1[size_for_segment_trees];
bool comp (pll a1,pll a2)
{
    return (a1.S)<a2.S;
}
int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifdef CHUCHUNDRA
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#else
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif
ll n;
cin>>n;
vector <ll> sums;
vector <ll> a(n);
for (int i = 0;i < n;i++)
    cin>>a[i];
for (int i = 0;i < n;i++)
{
    ll ss = 0;
    for (int j = i;j < n;j++)
    {
        ss+=a[j];
        sums.pb(ss);
    }
}
sort(sums.begin(),sums.end());
vector <ll> s2;
s2.pb(sums[0]);
for (int i = 1;i < sums.size();i++)
    if (sums[i]!=sums[i-1]) s2.pb(sums[i]);
for (int i = 0;i < n;i++)
{
    ll ss = 0;
    for (int j = i;j < n;j++)
    {
        ss+=a[j];
        ll point = lower_bound(s2.begin(),s2.end(),ss)-s2.begin();
        g1[point].pb({i,j});
    }
}
ll ans = 0;
ll posit = 0;
for (int i = 0;i < s2.size();++i)
    sort(g1[i].begin(),g1[i].end(),comp);
for (int i = 0;i < s2.size();++i)
{
    ll kol = 0;
    ll mux = -1;
for (auto to:g1[i])
    {
if (to.F>mux) {++kol;mux = max(mux,to.S);}
}
    ans = max(ans,kol);
if (ans==kol) posit = s2[i];
}
vector <pll> answ;
ll mex = -1;
ll pu = lower_bound(s2.begin(),s2.end(),posit)-s2.begin();
for (auto to:g1[pu])
{
if (to.F>mex) {mex = max(mex,to.S);answ.pb(to);
}
}
cout<<answ.size()<<'\n';
for (auto to:answ)
cout<<to.F+1<<" "<<to.S+1<<'\n';
return 0;
}
/*
Я всё вижу, чучундры! ;=)
*/
/*
Я всё слышу, чучундры! ;=)
*/


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Ido Kessler
 */

#pragma GCC optimize("O3")

#include <iostream>

#include <vector>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>

namespace io {
	class input_reader {
		std::istream ∈

		template<typename T>
		inline void readIntegerValue(T &f) {
			bool positive = true;
			f = 0;
			char c;
			if (!in.get(c)) throw std::runtime_error("No more inputs while reading number");
			while (c < '0' || c > '9') {
				if (c == '-') positive = false;
				if (!in.get(c)) throw std::runtime_error("No more inputs while reading number");
			}
			while (c >= '0' && c <= '9') {
				f = (f << 3) + (f << 1) + (c & 15);
				if (!in.get(c)) break;
			}
			if (!positive) f *= -1;
		}

	public:
		input_reader(std::istream &in) : in(in) {}

		inline void read(int &f) { readIntegerValue(f); }

		inline void read(short &f) { readIntegerValue(f); }

		inline void read(long int &f) { readIntegerValue(f); }

		inline void read(long long int &f) { readIntegerValue(f); }

		inline void read(unsigned int &f) { readIntegerValue(f); }

		inline void read(unsigned short &f) { readIntegerValue(f); }

		inline void read(unsigned long int &f) { readIntegerValue(f); }

		inline void read(unsigned long long int &f) { readIntegerValue(f); }

		template<typename T>
		inline void read(std::vector<T> &f) { for (auto &i : f) read(i); }

		template<typename T, int N>
		inline void read(std::array<T, N> &res) { for (auto &i: res) read(i); }

		template<typename T1, typename T2>
		inline void read(std::pair<T1, T2> &p) { in.read(p.first, p.second); }

		template<typename T>
		inline void read(T &f) { in >> f; }

		template<typename T1, typename T2>
		inline void read(T1 &t1, T2 &t2) { read(t1), read(t2); }

		template<typename T1, typename T2, typename T3>
		inline void read(T1 &t1, T2 &t2, T3 &t3) { read(t1, t2), read(t3); }

		template<typename T1, typename T2, typename T3, typename T4>
		inline void read(T1 &t1, T2 &t2, T3 &t3, T4 &t4) { read(t1, t2, t3), read(t4); }

		template<typename T1, typename T2, typename T3, typename T4, typename T5>
		inline void read(T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5) { read(t1, t2, t3, t4), read(t5); }

		template<typename T>
		inline void readArray(int n, T *res) { while (n--) read(*(res++)); }

		template<typename T>
		input_reader &operator>>(T &t) { return read(t), *this; }
	};
}

namespace io {
	class output_writer {
		std::ostream &out;

		template<typename T>
		inline void printIntegerHelper(T x) {
			if (x >= 10) printIntegerHelper(x / 10);
			out.put(x % 10 + 48);
		}

		template<typename T>
		inline void printInteger(T x) {
			if (x < 0) out.put('-'), x = -x;
			printIntegerHelper(x);
		}

		template<typename T>
		inline void printArray(T &ar) {
			bool first = true;
			for (auto &t : ar) print((first) ? first = false, "" : " ", t);
		}

	public:
		output_writer(std::ostream &out) : out(out) {}

		inline void flush() { out.flush(); }

		inline void print() {}

		inline void print(char x) { out.put(x); }

		inline void print(short x) { printInteger(x); }

		inline void print(int x) { printInteger(x); }

		inline void print(long int x) { printInteger(x); }

		inline void print(long long int x) { printInteger(x); }

		inline void print(unsigned short x) { printInteger(x); }

		inline void print(unsigned int x) { printInteger(x); }

		inline void print(unsigned long int x) { printInteger(x); }

		inline void print(unsigned long long int x) { printInteger(x); }

		template<typename T1>
		inline void print(const T1 &t1) { out << t1; }

		template<typename T1>
		inline void print(const std::vector<T1> &t1) { printArray(t1); }

		template<typename T1, int N>
		inline void print(const std::array<T1, N> &t1) { printArray(t1); }

		template<typename T1, int N, int M>
		inline void print(const std::array<std::array<T1, M>, N> &t1) { for (auto &t : t1) println(t); }

		template<typename T1>
		inline void print(const std::vector<std::vector<T1>> &t1) { for (auto &t : t1) println(t); }

		template<typename T, typename... Args>
		inline void print(const T &t, Args... args) { print(t), print(args...); }

		template<typename... Args>
		inline void println(Args... args) { print(args...), print('\n'); }

		template<typename T>
		output_writer &operator<<(const T &t) { return print(t), *this; }
	};
}

#define all(x) (x).begin(), (x).end()
#define fori(i,n) for(int i = 0; i < n; i++)
#define rep(i,s,e) for(int i = (s); i <= (e); ++i)
#define repr(i,s,e) for(int i = (s); i >= (e); --i)
#define ll long long int

#include <set>
#include <map>

using namespace std;

class F2SameSumBlocksHard {
	class Solver {
		io::input_reader in;
		io::output_writer out;

	public:
		Solver(std::istream &in, std::ostream &out) : in(in), out(out) {}

		struct subsum {
			int sum, l, r;
		};

		void solve() {
			int n;
			in >> n;
			vector<int> a(n);
			in >> a;
			vector<subsum> aa;
			fori(i, n) {
				int sum = 0;
				rep(j, i, n - 1) {
					sum += a[j];
					aa.push_back({sum, i, j});
				}
			}
			sort(all(aa), [](auto i, auto j) { return i.sum < j.sum; });
			auto extractNext = [](vector<subsum> &a) {
				vector<subsum> res;
				res.push_back(a.back()), a.pop_back();
				while (!a.empty() && a.back().sum == res.back().sum) res.push_back(a.back()), a.pop_back();
				sort(all(res), [](auto i, auto j) { return i.r > j.r; });
				vector<subsum> res1;
				res1.push_back(res.back()), res.pop_back();
				while (!res.empty()) {
					if (res.back().l > res1.back().r) res1.push_back(res.back());
					res.pop_back();
				}
				return res1;
			};
			vector<subsum> maxSubSums;
			while (!aa.empty()) {
				auto res = extractNext(aa);
				if (res.size() > maxSubSums.size()) maxSubSums = res;
			}

			out << maxSubSums.size() << '\n';
			for (auto i:maxSubSums) {
				out << (i.l + 1) << " " << (i.r + 1) << '\n';
			}
		}
	};

public:
	void solve(std::istream &in, std::ostream &out) {
		Solver(in, out).solve();
	}
};

int main() {
	std::ios_base::sync_with_stdio(false), cin.tie(0);
	F2SameSumBlocksHard solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Ido Kessler
 */

#pragma GCC optimize("O3")

#include <iostream>

#include <vector>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>

namespace io {
	class input_reader {
		std::istream ∈

		template<typename T>
		inline void readIntegerValue(T &f) {
			bool positive = true;
			f = 0;
			char c;
			if (!in.get(c)) throw std::runtime_error("No more inputs while reading number");
			while (c < '0' || c > '9') {
				if (c == '-') positive = false;
				if (!in.get(c)) throw std::runtime_error("No more inputs while reading number");
			}
			while (c >= '0' && c <= '9') {
				f = (f << 3) + (f << 1) + (c & 15);
				if (!in.get(c)) break;
			}
			if (!positive) f *= -1;
		}

	public:
		input_reader(std::istream &in) : in(in) {}

		inline void read(int &f) { readIntegerValue(f); }

		inline void read(short &f) { readIntegerValue(f); }

		inline void read(long int &f) { readIntegerValue(f); }

		inline void read(long long int &f) { readIntegerValue(f); }

		inline void read(unsigned int &f) { readIntegerValue(f); }

		inline void read(unsigned short &f) { readIntegerValue(f); }

		inline void read(unsigned long int &f) { readIntegerValue(f); }

		inline void read(unsigned long long int &f) { readIntegerValue(f); }

		template<typename T>
		inline void read(std::vector<T> &f) { for (auto &i : f) read(i); }

		template<typename T, int N>
		inline void read(std::array<T, N> &res) { for (auto &i: res) read(i); }

		template<typename T1, typename T2>
		inline void read(std::pair<T1, T2> &p) { in.read(p.first, p.second); }

		template<typename T>
		inline void read(T &f) { in >> f; }

		template<typename T1, typename T2>
		inline void read(T1 &t1, T2 &t2) { read(t1), read(t2); }

		template<typename T1, typename T2, typename T3>
		inline void read(T1 &t1, T2 &t2, T3 &t3) { read(t1, t2), read(t3); }

		template<typename T1, typename T2, typename T3, typename T4>
		inline void read(T1 &t1, T2 &t2, T3 &t3, T4 &t4) { read(t1, t2, t3), read(t4); }

		template<typename T1, typename T2, typename T3, typename T4, typename T5>
		inline void read(T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5) { read(t1, t2, t3, t4), read(t5); }

		template<typename T>
		inline void readArray(int n, T *res) { while (n--) read(*(res++)); }

		template<typename T>
		input_reader &operator>>(T &t) { return read(t), *this; }
	};
}

namespace io {
	class output_writer {
		std::ostream &out;

		template<typename T>
		inline void printIntegerHelper(T x) {
			if (x >= 10) printIntegerHelper(x / 10);
			out.put(x % 10 + 48);
		}

		template<typename T>
		inline void printInteger(T x) {
			if (x < 0) out.put('-'), x = -x;
			printIntegerHelper(x);
		}

		template<typename T>
		inline void printArray(T &ar) {
			bool first = true;
			for (auto &t : ar) print((first) ? first = false, "" : " ", t);
		}

	public:
		output_writer(std::ostream &out) : out(out) {}

		inline void flush() { out.flush(); }

		inline void print() {}

		inline void print(char x) { out.put(x); }

		inline void print(short x) { printInteger(x); }

		inline void print(int x) { printInteger(x); }

		inline void print(long int x) { printInteger(x); }

		inline void print(long long int x) { printInteger(x); }

		inline void print(unsigned short x) { printInteger(x); }

		inline void print(unsigned int x) { printInteger(x); }

		inline void print(unsigned long int x) { printInteger(x); }

		inline void print(unsigned long long int x) { printInteger(x); }

		template<typename T1>
		inline void print(const T1 &t1) { out << t1; }

		template<typename T1>
		inline void print(const std::vector<T1> &t1) { printArray(t1); }

		template<typename T1, int N>
		inline void print(const std::array<T1, N> &t1) { printArray(t1); }

		template<typename T1, int N, int M>
		inline void print(const std::array<std::array<T1, M>, N> &t1) { for (auto &t : t1) println(t); }

		template<typename T1>
		inline void print(const std::vector<std::vector<T1>> &t1) { for (auto &t : t1) println(t); }

		template<typename T, typename... Args>
		inline void print(const T &t, Args... args) { print(t), print(args...); }

		template<typename... Args>
		inline void println(Args... args) { print(args...), print('\n'); }

		template<typename T>
		output_writer &operator<<(const T &t) { return print(t), *this; }
	};
}

#define all(x) (x).begin(), (x).end()
#define fori(i,n) for(int i = 0; i < n; i++)
#define rep(i,s,e) for(int i = (s); i <= (e); ++i)
#define repr(i,s,e) for(int i = (s); i >= (e); --i)
#define ll long long int

#include <set>
#include <map>

using namespace std;

struct subsum {
	int sum, l, r;
};

subsum aa[1500 * 1500];
int a[1500];

class F2SameSumBlocksHard {
	class Solver {
		io::input_reader in;
		io::output_writer out;

	public:
		Solver(std::istream &in, std::ostream &out) : in(in), out(out) {}

		inline void print(subsum it) {
			out.println(it.l + 1, " ", it.r + 1);
		}

		template<bool SHOULD_PRINT>
		int solve(subsum *it, subsum *ite) {
			int res = 1;
			subsum last = *it++;
			if (SHOULD_PRINT) print(last);
			while (it != ite) {
				if (last.r < it->l) {
					res++;
					last = *it;
					if (SHOULD_PRINT) print(last);
				}
				++it;
			}
			return res;
		}

		void solve() {
			int n;
			in >> n;
			in.readArray(n, a);
			int N = 0;
			fori(i, n) {
				int sum = 0;
				rep(j, i, n - 1) {
					sum += a[j];
					aa[N++] = {sum, i, j};
				}
			}
			sort(aa, aa + N, [](auto i, auto j) { return i.sum < j.sum; });
			int best = 0, L, R;
			for (int i = 0; i < N; i++) {
				int cur = aa[i].sum;
				int j = i + 1;
				while (j < N && aa[j].sum == cur) ++j;
				sort(aa + i, aa + j, [](auto i, auto j) { return i.r < j.r; });
				int curV = solve<false>(aa + i, aa + j);
				if (curV > best) {
					best = curV;
					L = i;
					R = j;
				}
				i = j - 1;
			}
			out.println(best);
			solve<true>(aa + L, aa + R);
		}
	};

public:
	void solve(std::istream &in, std::ostream &out) {
		Solver(in, out).solve();
	}
};

int main() {
	std::ios_base::sync_with_stdio(false), cin.tie(0);
	F2SameSumBlocksHard solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Ido Kessler
 */

#pragma GCC optimize("O3")

#include <iostream>

#include <vector>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>

namespace io {
	class input_reader {
		std::istream ∈

		template<typename T>
		inline void readIntegerValue(T &f) {
			bool positive = true;
			f = 0;
			char c;
			if (!in.get(c)) throw std::runtime_error("No more inputs while reading number");
			while (c < '0' || c > '9') {
				if (c == '-') positive = false;
				if (!in.get(c)) throw std::runtime_error("No more inputs while reading number");
			}
			while (c >= '0' && c <= '9') {
				f = (f << 3) + (f << 1) + (c & 15);
				if (!in.get(c)) break;
			}
			if (!positive) f *= -1;
		}

	public:
		input_reader(std::istream &in) : in(in) {}

		inline void read(int &f) { readIntegerValue(f); }

		inline void read(short &f) { readIntegerValue(f); }

		inline void read(long int &f) { readIntegerValue(f); }

		inline void read(long long int &f) { readIntegerValue(f); }

		inline void read(unsigned int &f) { readIntegerValue(f); }

		inline void read(unsigned short &f) { readIntegerValue(f); }

		inline void read(unsigned long int &f) { readIntegerValue(f); }

		inline void read(unsigned long long int &f) { readIntegerValue(f); }

		template<typename T>
		inline void read(std::vector<T> &f) { for (auto &i : f) read(i); }

		template<typename T, int N>
		inline void read(std::array<T, N> &res) { for (auto &i: res) read(i); }

		template<typename T1, typename T2>
		inline void read(std::pair<T1, T2> &p) { in.read(p.first, p.second); }

		template<typename T>
		inline void read(T &f) { in >> f; }

		template<typename T1, typename T2>
		inline void read(T1 &t1, T2 &t2) { read(t1), read(t2); }

		template<typename T1, typename T2, typename T3>
		inline void read(T1 &t1, T2 &t2, T3 &t3) { read(t1, t2), read(t3); }

		template<typename T1, typename T2, typename T3, typename T4>
		inline void read(T1 &t1, T2 &t2, T3 &t3, T4 &t4) { read(t1, t2, t3), read(t4); }

		template<typename T1, typename T2, typename T3, typename T4, typename T5>
		inline void read(T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5) { read(t1, t2, t3, t4), read(t5); }

		template<typename T>
		inline void readArray(int n, T *res) { while (n--) read(*(res++)); }

		template<typename T>
		input_reader &operator>>(T &t) { return read(t), *this; }
	};
}

namespace io {
	class output_writer {
		std::ostream &out;

		template<typename T>
		inline void printIntegerHelper(T x) {
			if (x >= 10) printIntegerHelper(x / 10);
			out.put(x % 10 + 48);
		}

		template<typename T>
		inline void printInteger(T x) {
			if (x < 0) out.put('-'), x = -x;
			printIntegerHelper(x);
		}

		template<typename T>
		inline void printArray(T &ar) {
			bool first = true;
			for (auto &t : ar) print((first) ? first = false, "" : " ", t);
		}

	public:
		output_writer(std::ostream &out) : out(out) {}

		inline void flush() { out.flush(); }

		inline void print() {}

		inline void print(char x) { out.put(x); }

		inline void print(short x) { printInteger(x); }

		inline void print(int x) { printInteger(x); }

		inline void print(long int x) { printInteger(x); }

		inline void print(long long int x) { printInteger(x); }

		inline void print(unsigned short x) { printInteger(x); }

		inline void print(unsigned int x) { printInteger(x); }

		inline void print(unsigned long int x) { printInteger(x); }

		inline void print(unsigned long long int x) { printInteger(x); }

		template<typename T1>
		inline void print(const T1 &t1) { out << t1; }

		template<typename T1>
		inline void print(const std::vector<T1> &t1) { printArray(t1); }

		template<typename T1, int N>
		inline void print(const std::array<T1, N> &t1) { printArray(t1); }

		template<typename T1, int N, int M>
		inline void print(const std::array<std::array<T1, M>, N> &t1) { for (auto &t : t1) println(t); }

		template<typename T1>
		inline void print(const std::vector<std::vector<T1>> &t1) { for (auto &t : t1) println(t); }

		template<typename T, typename... Args>
		inline void print(const T &t, Args... args) { print(t), print(args...); }

		template<typename... Args>
		inline void println(Args... args) { print(args...), print('\n'); }

		template<typename T>
		output_writer &operator<<(const T &t) { return print(t), *this; }
	};
}

#define all(x) (x).begin(), (x).end()
#define fori(i,n) for(int i = 0; i < n; i++)
#define rep(i,s,e) for(int i = (s); i <= (e); ++i)
#define repr(i,s,e) for(int i = (s); i >= (e); --i)
#define ll long long int

#include <set>
#include <map>

using namespace std;

class F2SameSumBlocksHard {
	class Solver {
		io::input_reader in;
		io::output_writer out;

	public:
		Solver(std::istream &in, std::ostream &out) : in(in), out(out) {}

		void solve() {
			int n;
			in >> n;
			vector<int> a(n);
			in >> a;
			map<int, vector<pair<int, int>>> v;
			fori(i, n) {
				int sum = 0;
				repr(j, i, 0) {
					sum += a[j];
					if (v.find(sum) != v.end()) {
						auto &s = v[sum];
						if (s.back().second < j) {
							s.emplace_back(j, i);
						}
					} else {
						v[sum] = vector<pair<int, int>>();
						v[sum].emplace_back(j, i);
					}
				}
			}
			vector<pair<int, int>> res;
			for (auto &i:v) {
				if (res.size() < i.second.size()) res = i.second;
			}
			out.println(res.size());
			fori(i, res.size()) {
				out.println(res[i].first + 1, ' ', res[i].second + 1);
			}
		}
	};

public:
	void solve(std::istream &in, std::ostream &out) {
		Solver(in, out).solve();
	}
};

int main() {
	std::ios_base::sync_with_stdio(false), cin.tie(0);
	F2SameSumBlocksHard solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Ido Kessler
 */

#pragma GCC optimize("O3")

#include <iostream>

#include <vector>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>

namespace io {
	class input_reader {
		std::istream ∈

		template<typename T>
		inline void readIntegerValue(T &f) {
			bool positive = true;
			f = 0;
			char c;
			if (!in.get(c)) throw std::runtime_error("No more inputs while reading number");
			while (c < '0' || c > '9') {
				if (c == '-') positive = false;
				if (!in.get(c)) throw std::runtime_error("No more inputs while reading number");
			}
			while (c >= '0' && c <= '9') {
				f = (f << 3) + (f << 1) + (c & 15);
				if (!in.get(c)) break;
			}
			if (!positive) f *= -1;
		}

	public:
		input_reader(std::istream &in) : in(in) {}

		inline void read(int &f) { readIntegerValue(f); }

		inline void read(short &f) { readIntegerValue(f); }

		inline void read(long int &f) { readIntegerValue(f); }

		inline void read(long long int &f) { readIntegerValue(f); }

		inline void read(unsigned int &f) { readIntegerValue(f); }

		inline void read(unsigned short &f) { readIntegerValue(f); }

		inline void read(unsigned long int &f) { readIntegerValue(f); }

		inline void read(unsigned long long int &f) { readIntegerValue(f); }

		template<typename T>
		inline void read(std::vector<T> &f) { for (auto &i : f) read(i); }

		template<typename T, int N>
		inline void read(std::array<T, N> &res) { for (auto &i: res) read(i); }

		template<typename T1, typename T2>
		inline void read(std::pair<T1, T2> &p) { in.read(p.first, p.second); }

		template<typename T>
		inline void read(T &f) { in >> f; }

		template<typename T1, typename T2>
		inline void read(T1 &t1, T2 &t2) { read(t1), read(t2); }

		template<typename T1, typename T2, typename T3>
		inline void read(T1 &t1, T2 &t2, T3 &t3) { read(t1, t2), read(t3); }

		template<typename T1, typename T2, typename T3, typename T4>
		inline void read(T1 &t1, T2 &t2, T3 &t3, T4 &t4) { read(t1, t2, t3), read(t4); }

		template<typename T1, typename T2, typename T3, typename T4, typename T5>
		inline void read(T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5) { read(t1, t2, t3, t4), read(t5); }

		template<typename T>
		inline void readArray(int n, T *res) { while (n--) read(*(res++)); }

		template<typename T>
		input_reader &operator>>(T &t) { return read(t), *this; }
	};
}

namespace io {
	class output_writer {
		std::ostream &out;

		template<typename T>
		inline void printIntegerHelper(T x) {
			if (x >= 10) printIntegerHelper(x / 10);
			out.put(x % 10 + 48);
		}

		template<typename T>
		inline void printInteger(T x) {
			if (x < 0) out.put('-'), x = -x;
			printIntegerHelper(x);
		}

		template<typename T>
		inline void printArray(T &ar) {
			bool first = true;
			for (auto &t : ar) print((first) ? first = false, "" : " ", t);
		}

	public:
		output_writer(std::ostream &out) : out(out) {}

		inline void flush() { out.flush(); }

		inline void print() {}

		inline void print(char x) { out.put(x); }

		inline void print(short x) { printInteger(x); }

		inline void print(int x) { printInteger(x); }

		inline void print(long int x) { printInteger(x); }

		inline void print(long long int x) { printInteger(x); }

		inline void print(unsigned short x) { printInteger(x); }

		inline void print(unsigned int x) { printInteger(x); }

		inline void print(unsigned long int x) { printInteger(x); }

		inline void print(unsigned long long int x) { printInteger(x); }

		template<typename T1>
		inline void print(const T1 &t1) { out << t1; }

		template<typename T1>
		inline void print(const std::vector<T1> &t1) { printArray(t1); }

		template<typename T1, int N>
		inline void print(const std::array<T1, N> &t1) { printArray(t1); }

		template<typename T1, int N, int M>
		inline void print(const std::array<std::array<T1, M>, N> &t1) { for (auto &t : t1) println(t); }

		template<typename T1>
		inline void print(const std::vector<std::vector<T1>> &t1) { for (auto &t : t1) println(t); }

		template<typename T, typename... Args>
		inline void print(const T &t, Args... args) { print(t), print(args...); }

		template<typename... Args>
		inline void println(Args... args) { print(args...), print('\n'); }

		template<typename T>
		output_writer &operator<<(const T &t) { return print(t), *this; }
	};
}

#define all(x) (x).begin(), (x).end()
#define fori(i,n) for(int i = 0; i < n; i++)
#define rep(i,s,e) for(int i = (s); i <= (e); ++i)
#define repr(i,s,e) for(int i = (s); i >= (e); --i)
#define ll long long int

#include <set>
#include <map>

using namespace std;

struct subsum {
	int sum, l, r;
};

subsum aa[1500 * 1500];
int a[1500];

class F2SameSumBlocksHard {
	class Solver {
		io::input_reader in;
		io::output_writer out;

	public:
		Solver(std::istream &in, std::ostream &out) : in(in), out(out) {}

		void solve() {
			int n;
			in >> n;
			in.readArray(n, a);
			int N = 0;
			fori(i, n) {
				int sum = 0;
				rep(j, i, n - 1) {
					sum += a[j];
					aa[N++] = {sum, i, j};
				}
			}
			sort(aa, aa + N, [](auto i, auto j) { return i.sum != j.sum ? i.sum < j.sum : i.r < j.r; });
			int best = 0;
			int bestSum;
			int locSum;
			for (int i = 0; i < N; i++) {
				auto *last = &aa[i];
				int size = 1;
				int j = i + 1;
				while (j < N && aa[j].sum == last->sum) {
					if (aa[j].l > last->r) {
						last = &aa[j];
						size++;
					}
					++j;
				}
				if (best < size) {
					best = size;
					bestSum = last->sum;
					locSum = i;
				}
				i = j - 1;
			}
			out.println(best);
			out.println(aa[locSum].l + 1, " ", aa[locSum].r + 1);
			auto *last = &aa[locSum];
			locSum++;
			while (locSum < N && aa[locSum].sum == last->sum) {
				if (aa[locSum].l > last->r) {
					out.println(aa[locSum].l + 1, " ", aa[locSum].r + 1);
					last = &aa[locSum];
				}
				locSum++;
			}
		}
	};

public:
	void solve(std::istream &in, std::ostream &out) {
		Solver(in, out).solve();
	}
};

int main() {
	std::ios_base::sync_with_stdio(false), cin.tie(0);
	F2SameSumBlocksHard solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Ido Kessler
 */

#pragma GCC optimize("O3")

#include <iostream>

#include <vector>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>

namespace io {
	class input_reader {
		std::istream ∈

		template<typename T>
		inline void readIntegerValue(T &f) {
			bool positive = true;
			f = 0;
			char c;
			if (!in.get(c)) throw std::runtime_error("No more inputs while reading number");
			while (c < '0' || c > '9') {
				if (c == '-') positive = false;
				if (!in.get(c)) throw std::runtime_error("No more inputs while reading number");
			}
			while (c >= '0' && c <= '9') {
				f = (f << 3) + (f << 1) + (c & 15);
				if (!in.get(c)) break;
			}
			if (!positive) f *= -1;
		}

	public:
		input_reader(std::istream &in) : in(in) {}

		inline void read(int &f) { readIntegerValue(f); }

		inline void read(short &f) { readIntegerValue(f); }

		inline void read(long int &f) { readIntegerValue(f); }

		inline void read(long long int &f) { readIntegerValue(f); }

		inline void read(unsigned int &f) { readIntegerValue(f); }

		inline void read(unsigned short &f) { readIntegerValue(f); }

		inline void read(unsigned long int &f) { readIntegerValue(f); }

		inline void read(unsigned long long int &f) { readIntegerValue(f); }

		template<typename T>
		inline void read(std::vector<T> &f) { for (auto &i : f) read(i); }

		template<typename T, int N>
		inline void read(std::array<T, N> &res) { for (auto &i: res) read(i); }

		template<typename T1, typename T2>
		inline void read(std::pair<T1, T2> &p) { in.read(p.first, p.second); }

		template<typename T>
		inline void read(T &f) { in >> f; }

		template<typename T1, typename T2>
		inline void read(T1 &t1, T2 &t2) { read(t1), read(t2); }

		template<typename T1, typename T2, typename T3>
		inline void read(T1 &t1, T2 &t2, T3 &t3) { read(t1, t2), read(t3); }

		template<typename T1, typename T2, typename T3, typename T4>
		inline void read(T1 &t1, T2 &t2, T3 &t3, T4 &t4) { read(t1, t2, t3), read(t4); }

		template<typename T1, typename T2, typename T3, typename T4, typename T5>
		inline void read(T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5) { read(t1, t2, t3, t4), read(t5); }

		template<typename T>
		inline void readArray(int n, T *res) { while (n--) read(*(res++)); }

		template<typename T>
		input_reader &operator>>(T &t) { return read(t), *this; }
	};
}

namespace io {
	class output_writer {
		std::ostream &out;

		template<typename T>
		inline void printIntegerHelper(T x) {
			if (x >= 10) printIntegerHelper(x / 10);
			out.put(x % 10 + 48);
		}

		template<typename T>
		inline void printInteger(T x) {
			if (x < 0) out.put('-'), x = -x;
			printIntegerHelper(x);
		}

		template<typename T>
		inline void printArray(T &ar) {
			bool first = true;
			for (auto &t : ar) print((first) ? first = false, "" : " ", t);
		}

	public:
		output_writer(std::ostream &out) : out(out) {}

		inline void flush() { out.flush(); }

		inline void print() {}

		inline void print(char x) { out.put(x); }

		inline void print(short x) { printInteger(x); }

		inline void print(int x) { printInteger(x); }

		inline void print(long int x) { printInteger(x); }

		inline void print(long long int x) { printInteger(x); }

		inline void print(unsigned short x) { printInteger(x); }

		inline void print(unsigned int x) { printInteger(x); }

		inline void print(unsigned long int x) { printInteger(x); }

		inline void print(unsigned long long int x) { printInteger(x); }

		template<typename T1>
		inline void print(const T1 &t1) { out << t1; }

		template<typename T1>
		inline void print(const std::vector<T1> &t1) { printArray(t1); }

		template<typename T1, int N>
		inline void print(const std::array<T1, N> &t1) { printArray(t1); }

		template<typename T1, int N, int M>
		inline void print(const std::array<std::array<T1, M>, N> &t1) { for (auto &t : t1) println(t); }

		template<typename T1>
		inline void print(const std::vector<std::vector<T1>> &t1) { for (auto &t : t1) println(t); }

		template<typename T, typename... Args>
		inline void print(const T &t, Args... args) { print(t), print(args...); }

		template<typename... Args>
		inline void println(Args... args) { print(args...), print('\n'); }

		template<typename T>
		output_writer &operator<<(const T &t) { return print(t), *this; }
	};
}

#define all(x) (x).begin(), (x).end()
#define fori(i,n) for(int i = 0; i < n; i++)
#define rep(i,s,e) for(int i = (s); i <= (e); ++i)
#define repr(i,s,e) for(int i = (s); i >= (e); --i)
#define ll long long int

#include <set>
#include <map>

using namespace std;

struct subsum {
	int sum, l, r;

	bool operator<(const subsum &rhs) {
		return sum < rhs.sum;
	}
};

subsum aa[1500 * 1500];
int a[1500];

class F2SameSumBlocksHard {
	class Solver {
		io::input_reader in;
		io::output_writer out;

	public:
		Solver(std::istream &in, std::ostream &out) : in(in), out(out) {}

		inline void print(subsum it) {
			out.println(it.l + 1, " ", it.r + 1);
		}

		template<bool SHOULD_PRINT>
		int solve(subsum *it, subsum *ite) {
			int res = 1;
			subsum last = *it++;
			if (SHOULD_PRINT) print(last);
			while (it != ite) {
				if (last.r < it->l) {
					res++;
					last = *it;
					if (SHOULD_PRINT) print(last);
				}
				++it;
			}
			return res;
		}

		void solve() {
			int n;
			in >> n;
			in.readArray(n, a);
			int N = 0;
			fori(i, n) {
				int sum = 0;
				rep(j, i, n - 1) {
					sum += a[j];
					aa[N++] = {sum, i, j};
				}
			}
			sort(aa, aa + N);
			int best = 0, L, R;
			for (int i = 0; i < N; i++) {
				int cur = aa[i].sum;
				int j = i + 1;
				while (j < N && aa[j].sum == cur) ++j;
				sort(aa + i, aa + j, [](auto i, auto j) { return i.r < j.r; });
				int curV = solve<false>(aa + i, aa + j);
				if (curV > best) {
					best = curV;
					L = i;
					R = j;
				}
				i = j - 1;
			}
			out.println(best);
			solve<true>(aa + L, aa + R);
		}
	};

public:
	void solve(std::istream &in, std::ostream &out) {
		Solver(in, out).solve();
	}
};

int main() {
	std::ios_base::sync_with_stdio(false), cin.tie(0);
	F2SameSumBlocksHard solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Ido Kessler
 */

#pragma GCC optimize("O3")

#include <iostream>

#include <vector>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>

namespace io {
	class input_reader {
		std::istream ∈

		template<typename T>
		inline void readIntegerValue(T &f) {
			bool positive = true;
			f = 0;
			char c;
			if (!in.get(c)) throw std::runtime_error("No more inputs while reading number");
			while (c < '0' || c > '9') {
				if (c == '-') positive = false;
				if (!in.get(c)) throw std::runtime_error("No more inputs while reading number");
			}
			while (c >= '0' && c <= '9') {
				f = (f << 3) + (f << 1) + (c & 15);
				if (!in.get(c)) break;
			}
			if (!positive) f *= -1;
		}

	public:
		input_reader(std::istream &in) : in(in) {}

		inline void read(int &f) { readIntegerValue(f); }

		inline void read(short &f) { readIntegerValue(f); }

		inline void read(long int &f) { readIntegerValue(f); }

		inline void read(long long int &f) { readIntegerValue(f); }

		inline void read(unsigned int &f) { readIntegerValue(f); }

		inline void read(unsigned short &f) { readIntegerValue(f); }

		inline void read(unsigned long int &f) { readIntegerValue(f); }

		inline void read(unsigned long long int &f) { readIntegerValue(f); }

		template<typename T>
		inline void read(std::vector<T> &f) { for (auto &i : f) read(i); }

		template<typename T, int N>
		inline void read(std::array<T, N> &res) { for (auto &i: res) read(i); }

		template<typename T1, typename T2>
		inline void read(std::pair<T1, T2> &p) { in.read(p.first, p.second); }

		template<typename T>
		inline void read(T &f) { in >> f; }

		template<typename T1, typename T2>
		inline void read(T1 &t1, T2 &t2) { read(t1), read(t2); }

		template<typename T1, typename T2, typename T3>
		inline void read(T1 &t1, T2 &t2, T3 &t3) { read(t1, t2), read(t3); }

		template<typename T1, typename T2, typename T3, typename T4>
		inline void read(T1 &t1, T2 &t2, T3 &t3, T4 &t4) { read(t1, t2, t3), read(t4); }

		template<typename T1, typename T2, typename T3, typename T4, typename T5>
		inline void read(T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5) { read(t1, t2, t3, t4), read(t5); }

		template<typename T>
		inline void readArray(int n, T *res) { while (n--) read(*(res++)); }

		template<typename T>
		input_reader &operator>>(T &t) { return read(t), *this; }
	};
}

namespace io {
	class output_writer {
		std::ostream &out;

		template<typename T>
		inline void printIntegerHelper(T x) {
			if (x >= 10) printIntegerHelper(x / 10);
			out.put(x % 10 + 48);
		}

		template<typename T>
		inline void printInteger(T x) {
			if (x < 0) out.put('-'), x = -x;
			printIntegerHelper(x);
		}

		template<typename T>
		inline void printArray(T &ar) {
			bool first = true;
			for (auto &t : ar) print((first) ? first = false, "" : " ", t);
		}

	public:
		output_writer(std::ostream &out) : out(out) {}

		inline void flush() { out.flush(); }

		inline void print() {}

		inline void print(char x) { out.put(x); }

		inline void print(short x) { printInteger(x); }

		inline void print(int x) { printInteger(x); }

		inline void print(long int x) { printInteger(x); }

		inline void print(long long int x) { printInteger(x); }

		inline void print(unsigned short x) { printInteger(x); }

		inline void print(unsigned int x) { printInteger(x); }

		inline void print(unsigned long int x) { printInteger(x); }

		inline void print(unsigned long long int x) { printInteger(x); }

		template<typename T1>
		inline void print(const T1 &t1) { out << t1; }

		template<typename T1>
		inline void print(const std::vector<T1> &t1) { printArray(t1); }

		template<typename T1, int N>
		inline void print(const std::array<T1, N> &t1) { printArray(t1); }

		template<typename T1, int N, int M>
		inline void print(const std::array<std::array<T1, M>, N> &t1) { for (auto &t : t1) println(t); }

		template<typename T1>
		inline void print(const std::vector<std::vector<T1>> &t1) { for (auto &t : t1) println(t); }

		template<typename T, typename... Args>
		inline void print(const T &t, Args... args) { print(t), print(args...); }

		template<typename... Args>
		inline void println(Args... args) { print(args...), print('\n'); }

		template<typename T>
		output_writer &operator<<(const T &t) { return print(t), *this; }
	};
}

#define all(x) (x).begin(), (x).end()
#define fori(i,n) for(int i = 0; i < n; i++)
#define rep(i,s,e) for(int i = (s); i <= (e); ++i)
#define repr(i,s,e) for(int i = (s); i >= (e); --i)
#define ll long long int

#include <set>
#include <map>

using namespace std;

struct subsum {
	int sum, l, r;
};

subsum aa[1500 * 1500];

class F2SameSumBlocksHard {
	class Solver {
		io::input_reader in;
		io::output_writer out;

	public:
		Solver(std::istream &in, std::ostream &out) : in(in), out(out) {}

		void solve() {
			int n;
			in >> n;
			vector<int> a(n);
			in >> a;
			int N = 0;
			fori(i, n) {
				int sum = 0;
				rep(j, i, n - 1) {
					sum += a[j];
					aa[N++] = {sum, i, j};
				}
			}
			sort(aa, aa + N, [](auto i, auto j) { return i.sum != j.sum ? i.sum < j.sum : i.r < j.r; });
			int best = 0;
			int bestSum;
			int locSum;
			for (int i = 0; i < N; i++) {
				auto *last = &aa[i];
				int size = 1;
				int j = i + 1;
				while (j < N && aa[j].sum == last->sum) {
					if (aa[j].l > last->r) {
						last = &aa[j];
						size++;
					}
					++j;
				}
				if (best < size) {
					best = size;
					bestSum = last->sum;
					locSum = i;
				}
				i = j - 1;
			}
			out.println(best);
			out.println(aa[locSum].l + 1, " ", aa[locSum].r + 1);
			auto *last = &aa[locSum];
			locSum++;
			while (locSum < N && aa[locSum].sum == last->sum) {
				if (aa[locSum].l > last->r) {
					out.println(aa[locSum].l + 1, " ", aa[locSum].r + 1);
					last = &aa[locSum];
				}
				locSum++;
			}
		}
	};

public:
	void solve(std::istream &in, std::ostream &out) {
		Solver(in, out).solve();
	}
};

int main() {
	std::ios_base::sync_with_stdio(false), cin.tie(0);
	F2SameSumBlocksHard solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Ido Kessler
 */

#pragma GCC optimize("O3")

#include <iostream>

#include <vector>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>

namespace io {
	class input_reader {
		std::istream ∈

		template<typename T>
		inline void readIntegerValue(T &f) {
			bool positive = true;
			f = 0;
			char c;
			if (!in.get(c)) throw std::runtime_error("No more inputs while reading number");
			while (c < '0' || c > '9') {
				if (c == '-') positive = false;
				if (!in.get(c)) throw std::runtime_error("No more inputs while reading number");
			}
			while (c >= '0' && c <= '9') {
				f = (f << 3) + (f << 1) + (c & 15);
				if (!in.get(c)) break;
			}
			if (!positive) f *= -1;
		}

	public:
		input_reader(std::istream &in) : in(in) {}

		inline void read(int &f) { readIntegerValue(f); }

		inline void read(short &f) { readIntegerValue(f); }

		inline void read(long int &f) { readIntegerValue(f); }

		inline void read(long long int &f) { readIntegerValue(f); }

		inline void read(unsigned int &f) { readIntegerValue(f); }

		inline void read(unsigned short &f) { readIntegerValue(f); }

		inline void read(unsigned long int &f) { readIntegerValue(f); }

		inline void read(unsigned long long int &f) { readIntegerValue(f); }

		template<typename T>
		inline void read(std::vector<T> &f) { for (auto &i : f) read(i); }

		template<typename T, int N>
		inline void read(std::array<T, N> &res) { for (auto &i: res) read(i); }

		template<typename T1, typename T2>
		inline void read(std::pair<T1, T2> &p) { in.read(p.first, p.second); }

		template<typename T>
		inline void read(T &f) { in >> f; }

		template<typename T1, typename T2>
		inline void read(T1 &t1, T2 &t2) { read(t1), read(t2); }

		template<typename T1, typename T2, typename T3>
		inline void read(T1 &t1, T2 &t2, T3 &t3) { read(t1, t2), read(t3); }

		template<typename T1, typename T2, typename T3, typename T4>
		inline void read(T1 &t1, T2 &t2, T3 &t3, T4 &t4) { read(t1, t2, t3), read(t4); }

		template<typename T1, typename T2, typename T3, typename T4, typename T5>
		inline void read(T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5) { read(t1, t2, t3, t4), read(t5); }

		template<typename T>
		inline void readArray(int n, T *res) { while (n--) read(*(res++)); }

		template<typename T>
		input_reader &operator>>(T &t) { return read(t), *this; }
	};
}

namespace io {
	class output_writer {
		std::ostream &out;

		template<typename T>
		inline void printIntegerHelper(T x) {
			if (x >= 10) printIntegerHelper(x / 10);
			out.put(x % 10 + 48);
		}

		template<typename T>
		inline void printInteger(T x) {
			if (x < 0) out.put('-'), x = -x;
			printIntegerHelper(x);
		}

		template<typename T>
		inline void printArray(T &ar) {
			bool first = true;
			for (auto &t : ar) print((first) ? first = false, "" : " ", t);
		}

	public:
		output_writer(std::ostream &out) : out(out) {}

		inline void flush() { out.flush(); }

		inline void print() {}

		inline void print(char x) { out.put(x); }

		inline void print(short x) { printInteger(x); }

		inline void print(int x) { printInteger(x); }

		inline void print(long int x) { printInteger(x); }

		inline void print(long long int x) { printInteger(x); }

		inline void print(unsigned short x) { printInteger(x); }

		inline void print(unsigned int x) { printInteger(x); }

		inline void print(unsigned long int x) { printInteger(x); }

		inline void print(unsigned long long int x) { printInteger(x); }

		template<typename T1>
		inline void print(const T1 &t1) { out << t1; }

		template<typename T1>
		inline void print(const std::vector<T1> &t1) { printArray(t1); }

		template<typename T1, int N>
		inline void print(const std::array<T1, N> &t1) { printArray(t1); }

		template<typename T1, int N, int M>
		inline void print(const std::array<std::array<T1, M>, N> &t1) { for (auto &t : t1) println(t); }

		template<typename T1>
		inline void print(const std::vector<std::vector<T1>> &t1) { for (auto &t : t1) println(t); }

		template<typename T, typename... Args>
		inline void print(const T &t, Args... args) { print(t), print(args...); }

		template<typename... Args>
		inline void println(Args... args) { print(args...), print('\n'); }

		template<typename T>
		output_writer &operator<<(const T &t) { return print(t), *this; }
	};
}

#define all(x) (x).begin(), (x).end()
#define fori(i,n) for(int i = 0; i < n; i++)
#define rep(i,s,e) for(int i = (s); i <= (e); ++i)
#define repr(i,s,e) for(int i = (s); i >= (e); --i)
#define ll long long int

#include <set>
#include <map>

using namespace std;

struct subsum {
	int sum, l, r;
};

subsum aa[1500 * 1500];
int a[1500];

class F2SameSumBlocksHard {
	class Solver {
		io::input_reader in;
		io::output_writer out;

	public:
		Solver(std::istream &in, std::ostream &out) : in(in), out(out) {}

		inline void print(subsum *it) {
			out.println(it->l + 1, " ", it->r + 1);
		}

		template<bool SHOULD_PRINT>
		int solve(subsum *it, subsum *ite) {
			int res = 1;
			subsum *last = it++;
			if (SHOULD_PRINT) print(last);
			while (it != ite) {
				if (last->r < it->l) {
					res++;
					last = it;
					if (SHOULD_PRINT) print(last);
				}
				++it;
			}
			return res;
		}

		void solve() {
			int n;
			in >> n;
			in.readArray(n, a);
			int N = 0;
			fori(i, n) {
				int sum = 0;
				rep(j, i, n - 1) {
					sum += a[j];
					aa[N++] = {sum, i, j};
				}
			}
			sort(aa, aa + N, [](auto i, auto j) { return i.sum < j.sum; });
			int best = 0, L, R;
			for (int i = 0; i < N; i++) {
				int cur = aa[i].sum;
				int j = i + 1;
				while (j < N && aa[j].sum == cur) ++j;
				sort(aa + i, aa + j, [](auto i, auto j) { return i.r < j.r; });
				int curV = solve<false>(aa + i, aa + j);
				if (curV > best) {
					best = curV;
					L = i;
					R = j;
				}
				i = j - 1;
			}
			out.println(best);
			solve<true>(aa + L, aa + R);
		}
	};

public:
	void solve(std::istream &in, std::ostream &out) {
		Solver(in, out).solve();
	}
};

int main() {
	std::ios_base::sync_with_stdio(false), cin.tie(0);
	F2SameSumBlocksHard solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Ido Kessler
 */

#pragma GCC optimize("O3")

#include <iostream>

#include <vector>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>

namespace io {
	class input_reader {
		std::istream ∈

		template<typename T>
		inline void readIntegerValue(T &f) {
			bool positive = true;
			f = 0;
			char c;
			if (!in.get(c)) throw std::runtime_error("No more inputs while reading number");
			while (c < '0' || c > '9') {
				if (c == '-') positive = false;
				if (!in.get(c)) throw std::runtime_error("No more inputs while reading number");
			}
			while (c >= '0' && c <= '9') {
				f = (f << 3) + (f << 1) + (c & 15);
				if (!in.get(c)) break;
			}
			if (!positive) f *= -1;
		}

	public:
		input_reader(std::istream &in) : in(in) {}

		inline void read(int &f) { readIntegerValue(f); }

		inline void read(short &f) { readIntegerValue(f); }

		inline void read(long int &f) { readIntegerValue(f); }

		inline void read(long long int &f) { readIntegerValue(f); }

		inline void read(unsigned int &f) { readIntegerValue(f); }

		inline void read(unsigned short &f) { readIntegerValue(f); }

		inline void read(unsigned long int &f) { readIntegerValue(f); }

		inline void read(unsigned long long int &f) { readIntegerValue(f); }

		template<typename T>
		inline void read(std::vector<T> &f) { for (auto &i : f) read(i); }

		template<typename T, int N>
		inline void read(std::array<T, N> &res) { for (auto &i: res) read(i); }

		template<typename T1, typename T2>
		inline void read(std::pair<T1, T2> &p) { in.read(p.first, p.second); }

		template<typename T>
		inline void read(T &f) { in >> f; }

		template<typename T1, typename T2>
		inline void read(T1 &t1, T2 &t2) { read(t1), read(t2); }

		template<typename T1, typename T2, typename T3>
		inline void read(T1 &t1, T2 &t2, T3 &t3) { read(t1, t2), read(t3); }

		template<typename T1, typename T2, typename T3, typename T4>
		inline void read(T1 &t1, T2 &t2, T3 &t3, T4 &t4) { read(t1, t2, t3), read(t4); }

		template<typename T1, typename T2, typename T3, typename T4, typename T5>
		inline void read(T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5) { read(t1, t2, t3, t4), read(t5); }

		template<typename T>
		inline void readArray(int n, T *res) { while (n--) read(*(res++)); }

		template<typename T>
		input_reader &operator>>(T &t) { return read(t), *this; }
	};
}

namespace io {
	class output_writer {
		std::ostream &out;

		template<typename T>
		inline void printIntegerHelper(T x) {
			if (x >= 10) printIntegerHelper(x / 10);
			out.put(x % 10 + 48);
		}

		template<typename T>
		inline void printInteger(T x) {
			if (x < 0) out.put('-'), x = -x;
			printIntegerHelper(x);
		}

		template<typename T>
		inline void printArray(T &ar) {
			bool first = true;
			for (auto &t : ar) print((first) ? first = false, "" : " ", t);
		}

	public:
		output_writer(std::ostream &out) : out(out) {}

		inline void flush() { out.flush(); }

		inline void print() {}

		inline void print(char x) { out.put(x); }

		inline void print(short x) { printInteger(x); }

		inline void print(int x) { printInteger(x); }

		inline void print(long int x) { printInteger(x); }

		inline void print(long long int x) { printInteger(x); }

		inline void print(unsigned short x) { printInteger(x); }

		inline void print(unsigned int x) { printInteger(x); }

		inline void print(unsigned long int x) { printInteger(x); }

		inline void print(unsigned long long int x) { printInteger(x); }

		template<typename T1>
		inline void print(const T1 &t1) { out << t1; }

		template<typename T1>
		inline void print(const std::vector<T1> &t1) { printArray(t1); }

		template<typename T1, int N>
		inline void print(const std::array<T1, N> &t1) { printArray(t1); }

		template<typename T1, int N, int M>
		inline void print(const std::array<std::array<T1, M>, N> &t1) { for (auto &t : t1) println(t); }

		template<typename T1>
		inline void print(const std::vector<std::vector<T1>> &t1) { for (auto &t : t1) println(t); }

		template<typename T, typename... Args>
		inline void print(const T &t, Args... args) { print(t), print(args...); }

		template<typename... Args>
		inline void println(Args... args) { print(args...), print('\n'); }

		template<typename T>
		output_writer &operator<<(const T &t) { return print(t), *this; }
	};
}

#define all(x) (x).begin(), (x).end()
#define fori(i,n) for(int i = 0; i < n; i++)
#define rep(i,s,e) for(int i = (s); i <= (e); ++i)
#define repr(i,s,e) for(int i = (s); i >= (e); --i)
#define ll long long int

#include <set>
#include <map>

using namespace std;

class F2SameSumBlocksHard {
	class Solver {
		io::input_reader in;
		io::output_writer out;

	public:
		Solver(std::istream &in, std::ostream &out) : in(in), out(out) {}

		struct subsum {
			int sum, l, r;
		};

		void solve() {
			int n;
			in >> n;
			vector<int> a(n);
			in >> a;
			vector<subsum> aa;
			aa.reserve(n * (n - 1));
			fori(i, n) {
				int sum = 0;
				rep(j, i, n - 1) {
					sum += a[j];
					aa.push_back({sum, i, j});
				}
			}
			sort(all(aa), [](auto i, auto j) { return i.sum != j.sum ? i.sum < j.sum : i.r < j.r; });
			int best = 0;
			int bestSum;
			int locSum;
			for (int i = 0; i < aa.size(); i++) {
				auto last = aa[i];
				int size = 1;
				int j = i + 1;
				while (j < aa.size() && aa[j].sum == last.sum) {
					if (aa[j].l > last.r) {
						last = aa[j];
						size++;
					}
					++j;
				}
				if (best < size) {
					best = size;
					bestSum = last.sum;
					locSum = i;
				}
				i = j - 1;
			}
			out.println(best);
			out.println(aa[locSum].l + 1, " ", aa[locSum].r + 1);
			auto last = aa[locSum];
			locSum++;
			while (locSum < aa.size() && aa[locSum].sum == last.sum) {
				if (aa[locSum].l > last.r) {
					out.println(aa[locSum].l + 1, " ", aa[locSum].r + 1);
					last = aa[locSum];
				}
				locSum++;
			}
		}
	};

public:
	void solve(std::istream &in, std::ostream &out) {
		Solver(in, out).solve();
	}
};

int main() {
	std::ios_base::sync_with_stdio(false), cin.tie(0);
	F2SameSumBlocksHard solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
#define all(v) v.begin() v.end()
using namespace std;

int main()
{
    ll n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
        map<ll,vector<pair<ll,ll>> >  ma;
    ll su=0;
    for(int i=0;i<n;i++)
       { su=0;
           for(int j=i;j<n;j++)
    {
        su+=a[j];

        ma[su].pb(mp(i,j));
    }
       }

        ll in=0; ll cu=0;
       for(auto x:ma)
       {

           ll u=x.first; ll pr=-1;
            ll g=0;

           for(auto y:ma[u])
           {
               if(y.first>pr){g++; pr=y.second;}
           }
           if(g>cu){cu=g; in =u;}
       }
       cout<<cu<<"\n"; ll pr=-1;

       for(auto y:ma[in])
       {
           if(y.first>pr){ pr=y.second; cout<<y.first+1<<" "<<y.second+1<<"\n";}
       }
    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
#define all(v) v.begin() v.end()
using namespace std;

int main()
{
    ll n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
        map<ll,vector<pair<ll,ll> > >  ma;
    ll su=0;
    for(int i=0;i<n;i++)
       { su=0;
           for(int j=i;j<n;j++)
    {
        su+=a[j];
        ma[su].pb(mp(i,j));
    }
       }

        ll in=0; ll cu=0;
        map<ll,vector<pair<ll,ll> >>ah;
       for(auto x:ma)
       {

           ll u=x.first; ll pr=-1;
            ll g=0;

           for(auto y:ma[u])
           {
               if(y.first>pr){g++; ah[g-1].pb(y);pr=y.second;}
               if(y.second<pr){pr=y.second; ah[u][g-1].first=y.first; ah[u][g-1].second=y.second;}
           }
           if(g>cu){cu=g; in =u;}
       }
       cout<<cu<<"\n"; ll pr=-1;

       for(auto y:ah[in])
       {
           cout<<y.first+1LL<<" "<<y.second<<"\n";
       }
    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
#define all(v) v.begin() v.end()
using namespace std;

int main()
{
    ll n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
        map<ll,vector<pair<ll,ll>> >  ma;
    ll su=0;
    for(int i=0;i<n;i++)
       { su=0;
           for(int j=i;j<n;j++)
    {
        su+=a[i];
        ma[su].pb(mp(i,j));
    }
       }

        ll in=0; ll cu=0;
       for(auto x:ma)
       {

           ll u=x.first; ll pr=-1;
            ll g=0;

           for(auto y:ma[u])
           {
               if(y.first>pr){g++; pr=y.second;}
           }
           if(g>cu){cu=g; in =u;}
       }
       cout<<cu<<"\n"; ll pr=-1;
       for(auto y:ma[in])
       {
           if(y.first>pr){ pr=y.second; cout<<y.first+1<<" "<<y.second+1<<"\n";}
       }
    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
#define all(v) v.begin() v.end()
using namespace std;

int main()
{
    ll n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
        map<ll,vector<pair<ll,ll> > >  ma;
    ll su=0;
    for(int i=0;i<n;i++)
       { su=0;
           for(int j=i;j<n;j++)
    {
        su+=a[j];
        ma[su].pb(mp(i,j));
    }
       }

        ll in=0; ll cu=0;
        map<ll,vector<pair<ll,ll> >>ah;
       for(auto x:ma)
       {

           ll u=x.first; ll pr=-1;
            ll g=0;

           for(auto y:ma[u])
           {
               if(y.first>pr){g++; ah[u].pb(y);pr=y.second;}
               if(y.second<pr){pr=y.second; ah[u][g-1].first=y.first; ah[u][g-1].second=y.second;}
           }
           if(g>cu){cu=g; in =u;}

       }
       cout<<cu<<"\n"; ll pr=-1;

       for(auto y:ah[in])
       {
           cout<<y.first+1LL<<" "<<y.second<<"\n";
       }
    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
#define all(v) v.begin() v.end()
using namespace std;

int main()
{
    ll n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
        map<ll,vector<pair<ll,ll>> >  ma;
    ll su=0;
    for(int i=0;i<n;i++)
       { su=0;
           for(int j=i;j>=0;j--)
    {
        su+=a[j];

        ma[su].pb(mp(j,i));
    }
       }

        ll in=0; ll cu=0;
       for(auto x:ma)
       {

           ll u=x.first; ll pr=-1;
            ll g=0;

           for(auto y:ma[u])
           {
               if(y.first>pr){g++; pr=y.second;}
           }
           if(g>cu){cu=g; in =u;}
       }
       cout<<cu<<"\n"; ll pr=-1;

       for(auto y:ma[in])
       {
           if(y.first>pr){ pr=y.second; cout<<y.first+1<<" "<<y.second+1<<"\n";}
       }
    return 0;
}


#include <bits/stdc++.h>

#ifdef NJUDGE
  #include "kowski.h"
#else
  #define dbg(...)
#endif

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const ll LINF = 0x3f3f3f3f3f3f3f3f;
const ll NLINF = 0xf7f7f7f7f7f7f7f7;
const int INF = 0x3f3f3f3f, NINF = 0xf7f7f7f7;
const int MOD1 = 1e9 + 7, MOD2 = 1e9 + 9;

#define pb push_back
#define ss second
#define ff first

const int N = 1.5e3+10;
map <int, vector <pii>> seg;
vector <pii> ans;
int n, a[N];

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

  for(int i = 1; i <= n; i++){
    int s = 0;
    for(int j = i; j <= n; j++)
      s += a[j], seg[s].pb({i, j});
  }
  for(const auto&[key, v] : seg){
    int r = 0;
    vector <pii> cur;
    for(const auto&[x, y] : v)
      if (x > r) r = y, cur.pb({x, y});
    if (cur.size() > ans.size())
      ans = cur;
  }

  printf("%d\n", ans.size());
  for(auto &x : ans) printf("%d %d\n", x);
}


#include <bits/stdc++.h>

#ifdef NJUDGE
  #include "kowski.h"
#else
  #define dbg(...)
#endif

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const ll LINF = 0x3f3f3f3f3f3f3f3f;
const ll NLINF = 0xf7f7f7f7f7f7f7f7;
const int INF = 0x3f3f3f3f, NINF = 0xf7f7f7f7;
const int MOD1 = 1e9 + 7, MOD2 = 1e9 + 9;

#define pb push_back
#define ss second
#define ff first

const int N = 1.5e3+10;
map <int, vector <pii>> seg;
vector <pii> ans;
int n, a[N];

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

  for(int i = 1; i <= n; i++){
    int s = 0;
    for(int j = i; j <= n; j++)
      s += a[j], seg[s].pb({i, j});
  }
  for(const auto&[key, v] : seg){
    int r = 0;
    vector <pii> cur;
    for(auto &x : v)
      if (x.ff > r) r = x.ss, cur.pb(x);
    if (cur.size() > ans.size())
      ans = cur;
  }

  printf("%d\n", ans.size());
  for(auto &x : ans) printf("%d %d\n", x);
}


#include <bits/stdc++.h>

#ifdef NJUDGE
  #include "kowski.h"
#else
  #define dbg(...)
#endif

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const ll LINF = 0x3f3f3f3f3f3f3f3f;
const ll NLINF = 0xf7f7f7f7f7f7f7f7;
const int INF = 0x3f3f3f3f, NINF = 0xf7f7f7f7;
const int MOD1 = 1e9 + 7, MOD2 = 1e9 + 9;

#define pb push_back
#define ss second
#define ff first

const int N = 1550;
map <int, vector <pii>> seg;
vector <pii> ans;
int n, s, a[N];

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

  for(int i = 1; i <= n; i++){
    s = 0;
    for(int j = i; j <= n; j++)
      s += a[j], seg[s].pb(make_pair(i, j));
  }
  for(const auto&[key, v] : seg){
    int r = 0;
    vector <pii> cur;
    for(const auto&[x, y] : v)
      if (x > r) r = y, cur.pb(make_pair(x, y));
    if (cur.size() > ans.size())
      ans = cur;
  }

  printf("%d\n", ans.size());
  for(auto &x : ans) printf("%d %d\n", x);
}


#include <bits/stdc++.h>

#ifdef NJUDGE
  #include "kowski.h"
#else
  #define dbg(...)
#endif

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const ll LINF = 0x3f3f3f3f3f3f3f3f;
const ll NLINF = 0xf7f7f7f7f7f7f7f7;
const int INF = 0x3f3f3f3f, NINF = 0xf7f7f7f7;
const int MOD1 = 1e9 + 7, MOD2 = 1e9 + 9;

#define pb push_back
#define ss second
#define ff first

const int N = 1550;
map <int, vector <pii>> seg;
vector <pii> ans;
int n, s, a[N];

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

  for(int i = 1; i <= n; i++){
    s = 0;
    for(int j = i; j > 0; j--)
      s += a[j], seg[s].pb({j, i});
  }
  for(const auto&[key, v] : seg){
    int r = 0;
    vector <pii> cur;
    for(const auto&[x, y] : v)
      if (x > r) r = y, cur.pb({x, y});
    if (cur.size() > ans.size())
      ans = cur;
  }

  printf("%d\n", ans.size());
  for(auto &x : ans) printf("%d %d\n", x);
}


#include <bits/stdc++.h>

#ifdef NJUDGE
  #include "kowski.h"
#else
  #define dbg(...)
#endif

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const ll LINF = 0x3f3f3f3f3f3f3f3f;
const ll NLINF = 0xf7f7f7f7f7f7f7f7;
const int INF = 0x3f3f3f3f, NINF = 0xf7f7f7f7;
const int MOD1 = 1e9 + 7, MOD2 = 1e9 + 9;

#define pb push_back
#define ss second
#define ff first

const int N = 1550;
map <int, vector <pii>> seg;
vector <pii> ans;
int n, s = 0, a[N];

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

  for(int i = 1; i <= n; i++){
    s = 0;
    for(int j = i; j <= n; j++)
      s += a[j], seg[s].pb({i, j});
  }
  for(const auto&[key, v] : seg){
    int r = 0;
    vector <pii> cur;
    for(const auto&[x, y] : v)
      if (x > r) r = y, cur.pb({x, y});
    if (cur.size() > ans.size())
      ans = cur;
  }

  printf("%d\n", ans.size());
  for(auto &x : ans) printf("%d %d\n", x);
}


#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define FAST ios::sync_with_stdio(0);cin.tie(0);
using ll=long long;

int n,block[1550];

int main(){
    FAST;

    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>block[i];
    }
    map<int,vector<pair<int,int>>>m;

    for(int i=1;i<=n;i++){
        int sum=0;
        for(int j=i;j>=1;j--){
            sum+=block[j];
            m[sum].pb({j,i});
        }
    }

    vector<pair<int,int>>ans;
    for(auto i:m){
        vector<pair<int,int>>pp=i.s;
        int r=-1;
        vector<pair<int,int>>now;

        for(auto j:pp){
            if(r<j.f){
                now.pb({j.f,j.s});
                r=j.s;
            }
        }

        if(now.size()>ans.size()){
            ans=now;
        }
    }

    cout<<ans.size()<<endl;
    for(int i=0;i<ans.size();i++){
        cout<<ans[i].f<<" "<<ans[i].s<<endl;
    }
    return 0;
}


// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define lld long double
#define w(x) ll x;cin>>x;while(x--)
#define all(x) x.begin(), x.end()
#define mod 1000000007
#define pi 3.141592653589
#define speed ios_base::sync_with_stdio(false), cin.tie(nullptr)
using namespace std;

int main(){
    speed;
    ll n;   cin>>n;
    vector<ll> a(n);    for(auto &i:a)  cin>>i;
    vector<ll> pre(n);
    pre[0]=a[0];
    for(ll i=1;i<n;i++){
        pre[i]=pre[i-1]+a[i];
    }
    multimap<ll,pair<ll,ll>> mp;
    for(ll i=0;i<n;i++){
        if(i==0){
            for(ll j=i;j<n;j++){
                mp.insert({pre[j],{i,j}});
            }
        }
        else{
            for(ll j=i;j<n;j++){
                mp.insert({pre[j]-pre[i-1],{i,j}});
            }
        }
    }
    for(auto it=mp.begin();it!=mp.end();){
        auto it2=it;
        advance(it2,1);
        if(it->first==it2->first){
            if((it2->second.first)<=(it->second.second)){
                mp.erase(it2);
                if(it==mp.begin()){
                    it=mp.begin();
                }
                else{
                    it--;
                }
            }
        }
        it++;
    }
    // for(auto i:mp){
    //     cout<<i.first<<"->"<<i.second.first<<" "<<i.second.second<<'\n';
    // }

    vector<pair<ll,ll>> ans;
    map<ll,ll> sexy;
    for(auto i:mp){
        sexy[i.first]++;
    }
    ll mx;
    ll mx_val=INT_MIN;
    for(auto i:sexy){
        if(mx_val<i.second){
            mx_val=i.second;
            mx=i.first;
        }
    }
    for(auto it=mp.begin();it!=mp.end();it++){
        if((it->first)==mx){
            ans.push_back({it->second.first,it->second.second});
        }
    }
    cout<<ans.size()<<'\n';
    for(auto i:ans){
        cout<<i.first+1<<" "<<i.second+1<<'\n';
    }
    return 0;
}


// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define lld long double
#define w(x) ll x;cin>>x;while(x--)
#define all(x) x.begin(), x.end()
#define mod 1000000007
#define pi 3.141592653589
#define speed ios_base::sync_with_stdio(false), cin.tie(nullptr)
using namespace std;

int main(){
    speed;
    ll n;   cin>>n;
    vector<ll> a(n);    for(auto &i:a)  cin>>i;
    vector<ll> pre(n);
    pre[0]=a[0];
    for(ll i=1;i<n;i++){
        pre[i]=pre[i-1]+a[i];
    }
    multimap<ll,pair<ll,ll>> mp;
    for(ll i=0;i<n;i++){
        if(i==0){
            for(ll j=i;j<n;j++){
                mp.insert({pre[j],{i,j}});
            }
        }
        else{
            for(ll j=i;j<n;j++){
                mp.insert({pre[j]-pre[i-1],{i,j}});
            }
        }
    }
    bool erased=false;
    auto it1=mp.begin();
    auto it2=it1;   advance(it2,1);
    while(it2!=mp.end()){
        if(it1->first==it2->first){
            if((it1->second.second)>=(it2->second.first)){
                auto it3=it2;
                it2=it1;
                mp.erase(it3);
            }
        }
        it1=it2;
        it2++;
    }
    // for(auto i:mp){
    //     cout<<i.first<<"->"<<i.second.first<<" "<<i.second.second<<'\n';
    // }

    vector<pair<ll,ll>> ans;
    map<ll,ll> sexy;
    for(auto i:mp){
        sexy[i.first]++;
    }
    ll mx;
    ll mx_val=INT_MIN;
    for(auto i:sexy){
        if(mx_val<i.second){
            mx_val=i.second;
            mx=i.first;
        }
    }
    for(auto it=mp.begin();it!=mp.end();it++){
        if((it->first)==mx){
            ans.push_back({it->second.first,it->second.second});
        }
    }
    cout<<ans.size()<<'\n';
    for(auto i:ans){
        cout<<i.first+1<<" "<<i.second+1<<'\n';
    }
    return 0;
}


// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define lld long double
#define w(x) ll x;cin>>x;while(x--)
#define all(x) x.begin(), x.end()
#define mod 1000000007
#define pi 3.141592653589
#define speed ios_base::sync_with_stdio(false), cin.tie(nullptr)
using namespace std;

int main(){
    speed;
    ll n;   cin>>n;
    vector<ll> a(n);    for(auto &i:a)  cin>>i;
    multimap<ll,pair<ll,ll>> mp;
    for(ll i=0;i<n;i++){
        ll s=0;
        for(ll j=i;j<n;j++){
            s+=a[j];
            mp.insert({s,{i,j}});
        }
    }
    auto it1=mp.begin();
    auto it2=it1;   advance(it2,1);
    while(it2!=mp.end()){
        if(it1->first==it2->first){
            if((it1->second.second)>=(it2->second.first)){
                auto it3=it2;
                it2=it1;
                mp.erase(it3);
            }
        }
        it1=it2;
        it2++;
    }
    // for(auto i:mp){
    //     cout<<i.first<<"->"<<i.second.first<<" "<<i.second.second<<'\n';
    // }

    vector<pair<ll,ll>> ans;
    map<ll,ll> sexy;
    for(auto i:mp){
        sexy[i.first]++;
    }
    ll mx;
    ll mx_val=INT_MIN;
    for(auto i:sexy){
        if(mx_val<i.second){
            mx_val=i.second;
            mx=i.first;
        }
    }
    for(auto it=mp.begin();it!=mp.end();it++){
        if((it->first)==mx){
            ans.push_back({it->second.first,it->second.second});
        }
    }
    cout<<ans.size()<<'\n';
    for(auto i:ans){
        cout<<i.first+1<<" "<<i.second+1<<'\n';
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+10;
int a[maxn],s[maxn],n,ma;
struct pa{
int l;
int r;
bool operator<(const pa x)const{
    return r<x.r;
}
}ans1[maxn],ans2[maxn];
map<int,vector<pa>> f;
unordered_map<int,bool> ch;
vector<int> q;
vector<pa> g;

int main(){
    ma=-1;
    ch.reserve(1510*1510);
    ch.max_load_factor(0.25);
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        s[i]=s[i-1]+a[i];
    }
    for(int j=1;j<=n;j++){
        for(int i=1;i<=j;i++){
            f[s[j]-s[i]+a[i]].push_back({i,j});
        }
    }
    int pt=0,r1=0;
    for(auto i:f){
        g=i.second;
        r1=0;
        pt=0;
        for(auto j:g){
            if(j.l>r1){
                pt++;
                ans2[pt].l=j.l;
                ans2[pt].r=j.r;
                r1=j.r;
            }
        }
        if(pt>ma){
         ma=pt;
         for(int j=1;j<=pt;j++){
            ans1[j].l=ans2[j].l,
            ans1[j].r=ans2[j].r;
         }
        }
        }
    printf("%d\n",ma);
    for(auto i=1;i<=ma;i++){
        printf("%d %d\n",ans1[i].l,ans1[i].r);
    }
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=1505;
int a[maxn],s[maxn],n,ma;
struct pa{
int l;
int r;
}ans1[maxn],ans2[maxn];
unordered_map<int,vector<pa>> f;
vector<pa> g;

int main(){
    f.reserve(1510*1510);
    f.max_load_factor(0.25);
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        s[i]=s[i-1]+a[i];
    }
    for(int j=1;j<=n;j++)
        for(int i=1;i<=j;i++)
            f[s[j]-s[i-1]].push_back({i,j});
    int pt=0,r1=0;
    for(pair<int,vector<pa>> i:f){
        g=i.second;
         r1=0;
        pt=0;
        for(int j=0;j<g.size();j++){
            if(g[j].l>r1){
                pt++;
                ans2[pt].l=g[j].l;
                ans2[pt].r=g[j].r;
                r1=g[j].r;
            }
        }
        if(pt>ma){
         ma=pt;
         for(int j=1;j<=pt;j++){
            ans1[j]=ans2[j];
         }
        }
        }
    printf("%d\n",ma);
    for(int i=1;i<=ma;i++){
        printf("%d %d\n",ans1[i].l,ans1[i].r);
    }
}