codeparrot/codecomplex huggingface dataset:
// Problem: 1141_F2. Same Sum Blocks (Hard)
// Time complexity: quadratic
import java.io.PrintWriter;

import java.util.*;
public class Main{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        PrintWriter out=new PrintWriter(System.out);

        int n=sc.nextInt();
        int a[]=new int[n];
        for (int i = 0; i <n ; i++) {
            a[i]=sc.nextInt();
        }

        HashMap<Integer,ArrayList<Node>> h=new HashMap<>();
        for (int i = 0; i <n ; i++) {
            int sum=0;
            for (int j = i; j <n ; j++) {
                sum+=a[j];
                if(h.containsKey(sum)){
                    h.get(sum).add(new Node(i,j));
                }
                else{
                    ArrayList<Node> temp=new ArrayList<>();
                    temp.add(new Node(i,j));
                    h.put(sum,temp);
                }
            }
        }

        long ans=0;
        ArrayList<Integer> ansList=new ArrayList<>();

        for(int x:h.keySet()){
            Collections.sort(h.get(x), new Comparator<Node>() {
                @Override
                public int compare(Node o1, Node o2) {
                    return Integer.compare(o1.r,o2.r);
                }
            });


            ArrayList<Node>  l=h.get(x);
            //out.println(l);
            ArrayList<Integer> temp=new ArrayList<>();
            int lasty=Integer.MIN_VALUE;
            for (int i = 0; i <l.size() ; i++) {
                if(l.get(i).l>lasty){
                    lasty=l.get(i).r;
                    temp.add(l.get(i).l);
                    temp.add(l.get(i).r);
                }
            }

            if(ans<temp.size()){
                ansList=temp;
                ans=ansList.size();
            }
        }

        out.println(ans/2);
        for (int i = 0; i <ansList.size() ; i++) {
            out.print((ansList.get(i)+1)+" ");
            i++;
            out.println((ansList.get(i)+1)+" ");
        }



        out.close();
    }

    static class Node{
        int l,r;
        public Node(int a,int b){
            l=a;
            r=b;
        }
    }

}
// Problem: 1141_F2. Same Sum Blocks (Hard)
// Time complexity: quadratic
import java.util.*;

public class Main {
	
	public static class node implements Comparable<node>{
		int l,r;
		node(){}
		node(int l,int r) {
			this.l=l;
			this.r=r;
		}
		@Override
		public int compareTo(node rhs) {
			return r-rhs.r;
		}
	}
	
	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		int a = in.nextInt();
		int x[] = new int[a];
		for(int n=0;n<a;n++){
			x[n] = in.nextInt();
		}
		int max = 1;
		int t = 0;
		HashMap<Integer, ArrayList<node>> map = new HashMap<Integer, ArrayList<node>>();
		for(int n=0;n<a;n++){
			int num = 0;
			for(int m=n;m<a;m++){
				num += x[m];
				node node = new node(n, m);
				if(!map.containsKey(num)){
					ArrayList<node> list = new ArrayList<node>();
					list.add(node);
					map.put(num, list);
					if(max == 1)t = num;
				}
				else{
					ArrayList<node> list = map.get(num);
					int left = 0;
					int right = list.size()-1;				
					int res = list.size();
					while(left <= right){
						int mid = (left + right) >> 1;
						//System.out.println(mid +" "+ left +" " +right);
						if(list.get(mid).r >= n){
							res = mid;
							right = mid - 1;
						}
						else{
							left = mid + 1;
						}
					}
					if(res == list.size()){
						list.add(node);
						if(max < res+1){
							max = res+1;
							t = num;
						}
					}
					else if(list.get(res).r>m){
						list.set(res, node);
						if(max < res){
							max = list.size();
							t = num;
						}
					}
					
				}
			}
		}
		System.out.println(max);
		for(int n=0;n<max;n++){
			System.out.println((map.get(t).get(n).l+1)+" "+(map.get(t).get(n).r+1));
		}
		
	}
}
// Problem: 1141_F2. Same Sum Blocks (Hard)
// Time complexity: quadratic
//package codeforces;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class SameSumBlocksHard {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		int n = in .nextInt();

		long[] a = new long[n + 1];
		long[] sum = new long[n + 1];

		for (int i = 1; i <= n; i++) {
			a[i] = in.nextInt();
			sum[i] = sum[i - 1] + a[i];
		}

		Map<Long, List<int[]>> map = new HashMap<>();

		for (int i = 1; i <= n; i++) {
			for (int j = i; j <= n; j++) {
				long x = sum[j] - sum[i - 1];
				List<int[]> list = map.get(x);
				if (list == null) {
					list = new ArrayList<>();
					map.put(x, list);
				}
				list.add(new int[] {i, j});
			}
		}

		List<int[]> ans = new ArrayList<>();
		for (Map.Entry<Long, List<int[]>> entry : map.entrySet()) {
			List<int[]> list = entry.getValue();
			List<int[]> tmp = new ArrayList<>();
			calc(list, tmp);
			if (tmp.size() > ans.size()) {
				ans.clear();
				ans.addAll(tmp);
			}
		}

		System.out.println(ans.size());
		for (int[] pair : ans) {
			System.out.println(pair[0] + " " + pair[1]);
		}

		in.close();
	}

	static void calc(List<int[]> list, List<int[]> tmp) {
		Collections.sort(list, new Comparator<int[]>() {
			@Override
			public int compare(int[] o1, int[] o2) {
				if (o1[1] < o2[1]) {
					return -1;
				} else if (o1[1] > o2[1]) {
					return 1;
				} else {
					return 0;
				}
			}
		});

		int last = -1;
		for (int[] p : list) {
			if (last == -1) {
				last = p[1];
				tmp.add(p);
			} else if (p[0] > last) {
				last = p[1];
				tmp.add(p);
			}
		}
	}
}
// Problem: 1141_F2. Same Sum Blocks (Hard)
// Time complexity: quadratic
import java.util.*;
import java.io.*;
public class Solution1{

	static class Node{
		int start,end;
		Node(int start, int end){
			this.start=start;
			this.end=end;
		}
		public String toString(){
			return start+" "+end;
		}
	}

	public static void sameSumBlock(int a[],int n){
		HashMap<Long,ArrayList<Node>> map=new HashMap<>();

		long sum;
		for(int i=0;i<n;i++){
			sum=0;
			for(int j=i;j<n;j++){
				sum+=a[j];
				if(!map.containsKey(sum))
					map.put(sum,new ArrayList<>());
				map.get(sum).add( new Node(i+1, j+1) );
			}
		}

		//for(Map.Entry<Long,ArrayList<Node>> pair: map.entrySet())
			//System.out.println(pair.getKey()+" "+pair.getValue());


		int max=0;	LinkedList<Node> list=new LinkedList<>();
		for(Map.Entry<Long,ArrayList<Node>> pair: map.entrySet()){

			ArrayList<Node> arr=pair.getValue();
			Collections.sort(arr, (Node x, Node y)->{	return x.end-y.end;	});

			int count=0,end=0;
			LinkedList<Node> temp=new LinkedList<>();
			for(Node item: arr){
				if(end<item.start){
					end=item.end;
					count+=1;
					temp.add(new Node(item.start, item.end));
				}
			}

			if(count>max){
				max=count;
				list=temp;
			}
		}

		System.out.println(max);
		for(Node item: list)
			System.out.println(item.start+" "+item.end);
	}

	public static void main(String args[]){
		Scanner in=new Scanner(System.in);

		int n=in.nextInt();

		int a[]=new int[n];
		for(int i=0;i<n;i++)
			a[i]=in.nextInt();

		sameSumBlock(a,n);
	}
}
// Problem: 1141_F2. Same Sum Blocks (Hard)
// Time complexity: quadratic
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class F11141 {
	static class Solver {

		ArrayList<int[]> ranges[];
		HashMap<Long, Integer> hm = new HashMap<>();

		int id(long s) {
			if (!hm.containsKey(s))
				hm.put(s, hm.size());
			return hm.get(s);
		}
		
		// max disjoint range set in ranges[r]
		int[] memo;
		int go(int r) {
			memo[N] = 0;
			int last = N;
			for(int[] a : ranges[r]) {
				while(a[0] < last) {
					memo[last - 1] = memo[last];
					last--;
				}
				memo[a[0]] = Math.max(memo[a[0]], Math.max(memo[a[0]], 1 + memo[a[1] + 1]));
				last = a[0];
			}
			while(0 < last) {
				memo[last - 1] = memo[last];
				last--;
			}
			return memo[0];
		}

		ArrayDeque<int[]> ans = new ArrayDeque<>();
		
		void go2(int r) {
			memo[N] = 0;
			int last = N;
			int minAt[] = new int[N], oo = 987654321;
			Arrays.fill(minAt, oo);
			for(int[] a : ranges[r]) {
				minAt[a[0]] = Math.min(minAt[a[0]], a[1] - a[0]);
				while(a[0] < last) {
					memo[last - 1] = memo[last];
					last--;
				}
				memo[a[0]] = Math.max(memo[a[0]], Math.max(memo[a[0]], 1 + memo[a[1] + 1]));
				last = a[0];
			}
			while(0 < last) {
				memo[last - 1] = memo[last];
				last--;
			}
			int k = 0;
			for(; k < N;) {
				if(minAt[k] == oo || memo[k] != 1 + memo[k + minAt[k] + 1]) k++;
				else {
					ans.push(new int[] {k, k + minAt[k]});
					k += minAt[k] + 1;
				}
			}
		}
		
		@SuppressWarnings("unchecked")
		Solver() {
			ranges = new ArrayList[2250001];
			for (int i = 0; i < ranges.length; i++)
				ranges[i] = new ArrayList<>();
		}

		int N, LID;
		long[] a;

		void solve(Scanner s, PrintWriter out) {
			N = s.nextInt();
			a = new long[N + 1];
			for (int i = 1; i <= N; i++)
				a[i] = s.nextLong() + a[i - 1];
			for (int i = N; i >= 1; i--)
				for (int j = i; j <= N; j++) {
					int x = id(a[j] - a[i - 1]);
					ranges[x].add(new int[] { i - 1, j - 1 });
				}
			
			int best = 0, bid = -1;
			memo = new int[N + 1];
//			Arrays.sort(ranges, (a, b) -> b.size() - a.size());
			for(int i = 0; i < ranges.length; i++, LID++) {
				if(ranges[i].size() <= best) continue;
				int ans = go(i);
				if(ans > best) {
					best = ans;
					bid = i;
				}
			}
			
			// backtrack on bid
			out.println(best);
			go2(bid);
						
			while(!ans.isEmpty()) {
				int[] c = ans.pop();
				out.println(++c[0] + " " + ++c[1]);
			}
			
		}

	}

	public static void main(String[] args) {

		Scanner s = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		Solver solver = new Solver();
		solver.solve(s, out);

		out.close();

	}
}
// Problem: 1141_F2. Same Sum Blocks (Hard)
// Time complexity: quadratic
import java.io.*;
import java.util.*;
import java.awt.Point;

public class CF_1141F2 {
    public static void main(String args[]) throws Exception {
        BufferedScanner in = new BufferedScanner(new InputStreamReader(System.in));
        PrintStream out = new PrintStream(new BufferedOutputStream(System.out));

        int n = in.nextInt();
        int[] arr = in.nextN(n);

        HashMap<Integer, ArrayList<Point>> lp = new HashMap<>();
        for (int i = 0; i < n; i++) {
            int curr = 0;
            for (int j = i; j >= 0; j--) {
                curr += arr[j];
                if (!lp.containsKey(curr)) lp.put(curr, new ArrayList<>());

                lp.get(curr).add(new Point(j, i));
            }
        }

        ArrayList<Point> retPs = new ArrayList<>();
        for (ArrayList<Point> ps : lp.values()) {
            Collections.sort(ps, (a, b) -> a.y - b.y);

            ArrayList<Point> currPs = new ArrayList<>();
            for (int i = 0; i < ps.size(); ) {
                Point curr = ps.get(i);
                currPs.add(curr);

                while (i < ps.size() && ps.get(i).x <= curr.y) i++;
            }
            if(currPs.size() > retPs.size()) retPs = currPs;
        }
        out.println(retPs.size());
        for (Point p : retPs) out.println((p.x + 1) + " " + (p.y + 1));


        out.close();
        in.close();
    }

    static class BufferedScanner {
        private BufferedReader in;
        private StringTokenizer st;

        BufferedScanner(Reader in) throws IOException {
            this.in = new BufferedReader(in);
            st = new StringTokenizer(this.in.readLine());
        }

        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        int[] nextN(int n) throws IOException {
            int[] ret = new int[n];
            for (int i = 0; i < n; i++) ret[i] = this.nextInt();
            return ret;
        }

        long[] nextNL(int n) throws IOException {
            long[] ret = new long[n];
            for (int i = 0; i < n; i++) ret[i] = this.nextLong();
            return ret;
        }

        String next() throws IOException {
            if (!st.hasMoreElements()) st = new StringTokenizer(in.readLine());

            return st.nextToken();
        }

        void close() throws IOException {
            in.close();
        }

    }
}
// Problem: 1141_F2. Same Sum Blocks (Hard)
// Time complexity: quadratic
import java.util.*;

public class Solution {


    public static void main(String[] args) {

        class Pair {
            int start;
            int end;

            public Pair(int start, int end) {
                this.start = start;
                this.end = end;
            }
        }

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n];
        for (int i=0; i<n; i++) array[i] = sc.nextInt();


        int maxLen = 0;
        int key = -1;
        HashMap<Integer, List<Pair>> ans = new HashMap<>();
        for (int i=0; i<n; i++){
            int currSum = 0;
            for (int j=i; j>=0; j--){
                currSum = currSum + array[j];
                if (!ans.containsKey(currSum)){
                    ans.put(currSum, new ArrayList<>());
                }
                List<Pair> pairs = ans.get(currSum);
                if (pairs.size() == 0 || pairs.get(pairs.size()-1).end <= j){
                    pairs.add(new Pair(j+1, i+1));
                }
                if (pairs.size() > maxLen){
                    maxLen = pairs.size();
                    key = currSum;
                }
            }

        }

        System.out.println(maxLen);
        for (Pair pair : ans.get(key)){
            System.out.println(pair.start + " " + pair.end);
        }

    }

}
// Problem: 1141_F2. Same Sum Blocks (Hard)
// Time complexity: quadratic
import java.util.*;
public class MyClass {
    static class Pair implements Comparable<Pair>{
        int x,y;
        Pair(int x,int y){
            this.x=x; this.y=y;
        }
        public int compareTo(Pair p){
            return Integer.compare(this.y,p.y);
        }
    }
    public static void main(String args[]) {
      Scanner in =new Scanner(System.in);
      HashMap<Long,ArrayList<Pair>> hm=new HashMap<Long,ArrayList<Pair>>();
      int n=in.nextInt();
      int a[]=new int[n];
      long sum[]=new long[n];
      long s=0;
      for(int i=0;i<n;i++){  a[i]=in.nextInt(); s+=a[i]; sum[i]=s; }
      for(int i=0;i<n;i++){
          for(int j=i;j<n;j++){
              long x=sum[j]-sum[i]+a[i];
              ArrayList<Pair> temp=new ArrayList<Pair>();
              if(hm.containsKey(x)) { temp=hm.get(x); }
              temp.add(new Pair(i+1,j+1));
              hm.put(x,temp);
          }
      }
      ArrayList<Pair> ans=new ArrayList<Pair>();
      for(Map.Entry em:hm.entrySet()){
          ArrayList<Pair> array=hm.get(em.getKey());
          Collections.sort(array);
          int prev=0;
          ArrayList<Pair> temp=new ArrayList<Pair>();
          for(int i=0;i<array.size();i++){
              if(array.get(i).x>prev){ temp.add(new Pair(array.get(i).x,array.get(i).y)); prev=array.get(i).y; }
          }
        //  System.out.println(temp.size());
          if(temp.size()>ans.size()){
              ans=(ArrayList<Pair>)temp.clone();
          }
      }
      long g=-5;
      System.out.println(ans.size()); 
      for(int i=0;i<ans.size();i++){
          System.out.println(ans.get(i).x+" "+ans.get(i).y);
      }
    }
}
// Problem: 1141_F2. Same Sum Blocks (Hard)
// Time complexity: quadratic
import java.io.*;
import java.util.*;

public class B{

	static long []sum;
	
	static int n;

	public static void main(String[] args) throws IOException {
		Scanner sc=new Scanner();
		PrintWriter out=new PrintWriter(System.out);
		n=sc.nextInt();
		sum=new long [n+1];
		for(int i=1;i<=n;i++)
			sum[i]=sc.nextInt()+sum[i-1];
		HashMap<Long,Integer> map=new HashMap();
		ArrayList<int []>[]adj=new ArrayList[n*n+10];
		for(int i=0;i<adj.length;i++)
			adj[i]=new ArrayList();
		for(int r=1;r<=n;r++) 
			for(int l=1;l<=n;l++) {
				if(r<l)
					continue;
				long x=sum[r]-sum[l-1];
				map.put(x, map.getOrDefault(x, map.size()));
				adj[map.get(x)].add(new int [] {l,r});
			}
		int ans=0;
		int bestIdx=0;
		for(int idx=0;idx<adj.length;idx++)
		{
			ArrayList<int[]>list=adj[idx];
			if(list.isEmpty())
				continue;
			int curr=1;
			int R=list.get(0)[1];
			for(int i=1;i<list.size();i++)
			{
				int []tmp=list.get(i);
				if(tmp[0]>R)
				{
					R=tmp[1];
					curr++;
				}
			}
			if(curr>=ans) {
				ans=curr;
				bestIdx=idx;
			}
		}
		out.println(ans);
		ArrayList<int[]>list=adj[bestIdx];
		int R=list.get(0)[1];
		out.println(list.get(0)[0]+" "+R);
		for(int i=1;i<list.size();i++)
		{
			int []tmp=list.get(i);
			if(tmp[0]>R)
			{
				R=tmp[1];
				out.println(tmp[0]+" "+tmp[1]);
			}
		}
		out.close();

	}
	
	static class Scanner
	{
		BufferedReader br;
		StringTokenizer st;
		Scanner(){
			br=new BufferedReader(new InputStreamReader(System.in));
		}
		Scanner(String fileName) throws FileNotFoundException{
			br=new BufferedReader(new FileReader(fileName));
		}
		String next() throws IOException {
			while(st==null || !st.hasMoreTokens())
				st=new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		String nextLine() throws IOException {
			return br.readLine();
		}
		int nextInt() throws IOException{
			return Integer.parseInt(next());
		}
		long nextLong()  throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}
		double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}
	}
}
// Problem: 1141_F2. Same Sum Blocks (Hard)
// Time complexity: quadratic
import java.util.*;
import java.io.*;
import java.math.BigInteger;

public class Main
{
    static final long mod=(int)1e9+7;
    public static void main(String[] args) throws Exception
    {
    	FastReader in=new FastReader();
    	PrintWriter pw=new PrintWriter(System.out);
    	int n=in.nextInt();
    	int[] arr=new int[n+1];
    	for(int i=1;i<=n;i++)
    		arr[i]=in.nextInt();
    	Map<Integer,TreeMap<Integer,Integer>> map=new HashMap();
    	for(int i=1;i<=n;i++)
    	{
    		int sum=0;
    		for(int j=i;j<=n;j++)
    		{
    			sum+=arr[j];
    			if(map.containsKey(sum))
    			{
    				TreeMap<Integer,Integer> t=map.get(sum);
    				// System.out.println(t+" "+sum);
    				Map.Entry<Integer,Integer> e=t.lastEntry();
    				if(e.getKey()>j)
    				{
    					t.remove(e.getKey());
    					t.put(j,i);
    					map.put(sum,t);
    				}
    				else if(e.getKey()<i)
    				{
    					t.put(j,i);
    					map.put(sum,t);
    				}
    			}
    			else
    			{
    				TreeMap<Integer,Integer> t=new TreeMap();
    				t.put(j,i);
    				map.put(sum,t);
    			}
    		}
    	}
    	int ans=0,size=0;
    	for(Map.Entry<Integer,TreeMap<Integer,Integer>> e:map.entrySet())
    	{
    		if(e.getValue().size()>size)
    		{
    			ans=e.getKey();
    			size=e.getValue().size();
    		}
    	}
    	pw.println(size);
    	for(Map.Entry e:map.get(ans).entrySet())
    		pw.println(e.getValue()+" "+e.getKey());
    	pw.flush();
    }
}

class pair
{
	int f,s;
}

class FastReader
{
    BufferedReader br;
    StringTokenizer st;
 
    public FastReader()
    {
        br=new BufferedReader(new InputStreamReader(System.in));
    }
 
    public String next() throws IOException
    {
        if(st==null || !st.hasMoreElements())
        {
            st=new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
 
    public int nextInt() throws IOException
    {
        return Integer.parseInt(next());
    }
 
    public long nextLong() throws IOException
    {
        return Long.parseLong(next());
    }
}
// Problem: 1141_F2. Same Sum Blocks (Hard)
// Time complexity: quadratic
import java.util.*;
import java.io.*;
import java.util.regex.*;

public class Codeforces{
	
	static class MyScanner{
		BufferedReader br;
		StringTokenizer st;
		
		MyScanner(FileReader fileReader){
			br = new BufferedReader(fileReader);
		}
		
		MyScanner(){
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		
		String nn(){
			while(st == null || !st.hasMoreElements()){
				try{
					st = new StringTokenizer(br.readLine());
				}catch(IOException e){
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}
		
		char nc(){
			return nn().charAt(0);
		}
		
		int ni(){
			return Integer.parseInt(nn());
		}
		
		long nl(){
			return Long.parseLong(nn());
		}
		
		double nd(){
			return Double.parseDouble(nn());
		}
		
		int[] niArr0(int n){
			int[] ar = new int[n];
			for(int i = 0; i < n; i++) ar[i] = ni();
			return ar;
		}
		
		int[] niArr1(int n){
			int[] ar = new int[n + 1];
			for(int i = 1; i <= n; i++) ar[i] = ni();
			return ar;
		}
		
		long[] nlArr0(int n){
			long[] ar = new long[n];
			for(int i = 0; i < n; i++) ar[i] = nl();
			return ar;
		}
	}
	
	public static <T> void mprintln(T ... ar){
		for(T i: ar) out.print(i + " ");
		out.println();
	}
	
	private static PrintWriter out;
	
	public static void main(String[] args) throws FileNotFoundException{
		
		// Input from file
		// File inputFile = new File("JavaFile.txt");
		// File outputFile = new File("JavaOutputFile.txt");
		// FileReader fileReader = new FileReader(inputFile);
		// Here it ends
			
		MyScanner sc = new MyScanner();
		// MyScanner sc = new MyScanner(fileReader);
		
		out = new PrintWriter(new BufferedOutputStream(System.out)); // Output to console
		// out = new PrintWriter(new PrintStream(outputFile)); // Output to file
		
		getAns(sc);
		
		out.close();
	}
	
	private static void getAns(MyScanner sc){
		int n = sc.ni();
		long[] ar = sc.nlArr0(n);
		
		HashMap<Long, ArrayList<int[]>> map = new HashMap();
		
		for(int i = 0; i < n; i++){
			long cur = 0;
			for(int j = i; j >= 0; j--){
				cur += ar[j];
				if(!map.containsKey(cur)) map.put(cur, new ArrayList());
				map.get(cur).add(new int[]{j + 1, i + 1});
			}
		}
		
		// System.out.println(map);
		
		Set<Long> set = map.keySet();
		// System.out.println(set);
		ArrayList<int[]> ans = new ArrayList();
		
		for(Long l: set){
			ArrayList<int[]> cur = new ArrayList();
			int right = -1;
			for(int[] arc: map.get(l)) if(arc[0] > right){
				right = arc[1];
				cur.add(arc);
			}
			
			if(cur.size() > ans.size()) ans = cur;
		}
		
		out.println(ans.size());
		for(int[] arc: ans) mprintln(arc[0], arc[1]);
	}
}
// Problem: 1141_F2. Same Sum Blocks (Hard)
// Time complexity: quadratic
import java.util.*;
import java.util.Map.Entry;
import java.io.*;
public class Main {
	public static class node implements Comparable<node> {
		int l,r;
		node(){}
		node(int l,int r) {
			this.l=l;
			this.r=r;
		}
		@Override
		public int compareTo(node rhs) {
			return r-rhs.r;
		}
	}
	public static void main(String[] args) throws IOException {
		BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out=new PrintWriter(System.out);
		StringTokenizer sa=new StringTokenizer(in.readLine());
		int n=Integer.parseInt(sa.nextToken());
		sa=new StringTokenizer(in.readLine());
		int[] a=new int[n];
		TreeMap<Integer,ArrayList<node>> mp=new TreeMap();
		for (int i=0;i<n;++i) a[i]=Integer.parseInt(sa.nextToken());
		for (int i=0;i<n;++i) {
			int tmp=0;
			for (int j=i;j<n;++j) {
				tmp+=a[j];
				if (!mp.containsKey(tmp)) {
					ArrayList t=new ArrayList();
					t.add(new node(i,j));
					mp.put(tmp,t);
				} else {
					ArrayList<node> t=mp.get(tmp);
					int left=0,right=t.size()-1,res=t.size();
					while (left<=right) {
						int mid=(left+right)>>1;
						if (t.get(mid).r>=i) {
							res=mid;
							right=mid-1;
						} else left=mid+1;
					}
					if (res==t.size()) t.add(new node(i,j));
					else if (t.get(res).r>j) t.set(res,new node(i,j));
				}
			}
		}
		int res=0;
		for (Entry<Integer,ArrayList<node>> entry:mp.entrySet())
			res=Math.max(res,entry.getValue().size());
		out.println(res);
		for (Entry<Integer,ArrayList<node>> entry:mp.entrySet())
			if (entry.getValue().size()==res) {
				ArrayList<node> tmp=entry.getValue();
				for (int i=0;i<tmp.size();++i)
					out.printf("%d %d\n",tmp.get(i).l+1,tmp.get(i).r+1);
				out.flush();
				return;
			}
	}
}