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

public class Main{
	
	int[] ints;
	int[] prefix;
	
	public static void main(String[] args)
	{
		new Main().run();
	}
	
	public void run()
	{
		Scanner file = new Scanner(System.in);
		int N = file.nextInt();
		ints = new int[N];
		for(int i = 0;i<N;i++)
			ints[i] = file.nextInt();
		prefix = new int[N];
		prefix[0] = ints[0];
		for(int i =1;i<prefix.length;i++)
			prefix[i] = prefix[i-1]+ints[i];
		HashMap<Integer,Integer> ending = new HashMap<>();//ending for each sum
		HashMap<Integer,Integer> amount = new HashMap<>();//k for each sum
		for(int end = 0;end<prefix.length;end++)
		{
			for(int start = 0;start<=end;start++)
			{
				int sum = sum(start,end);
				if(!ending.containsKey(sum))
					ending.put(sum, -1);
				if(!amount.containsKey(sum))
					amount.put(sum,0);
				if(ending.get(sum)<start)
				{
					amount.put(sum,amount.get(sum)+1);
					ending.put(sum,end);
				}
			}
		}
		int max = 0;
		int maxnum = -1;
		for(int x:amount.keySet())
		{
			if(amount.get(x)>max)
			{
				max = amount.get(x);
				maxnum = x;
			}
		}
		System.out.println(max);
		HashMap<Integer,Integer> occurrence = new HashMap<Integer,Integer>();
		occurrence.put(0,0);
		for(int i = 0;i<prefix.length;i++)
		{
			if(occurrence.containsKey(prefix[i]-maxnum))
			{
				System.out.println(occurrence.get(prefix[i]-maxnum)+1+" "+(i+1));
				occurrence.clear();
			}
			occurrence.put(prefix[i],i+1);
		}
	}
	
	public int sum(int L, int R)
	{
		return prefix[R] - prefix[L] + ints[L];
	}
	
}
// Problem: 1141_F2. Same Sum Blocks (Hard)
// Time complexity: quadratic
import java.util.*;

public class F2 {

    private static int n;
    private static int[] a;

    private static Collection<Segment> answer;

    public static void main(String[] args) {
        in();
        solution();
        out();
    }

    private static void in() {

        Scanner in = new Scanner(System.in);

        n = in.nextInt();

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

    }

    private static void solution() {

        HashMap<Long, LinkedList<Segment>> segments = new HashMap<>();

        for (int i = 0; i < n; i++) {

            long sum = 0;

            for (int j = i; j < n; j++) {

                sum += a[j];

                if (segments.containsKey(sum)) {
                    segments.get(sum).add(new Segment(i, j));
                } else {
                    LinkedList<Segment> toPut = new LinkedList<>();
                    toPut.add(new Segment(i, j));
                    segments.put(sum, toPut);
                }

            }

        }

        answer = null;
        for (Map.Entry<Long, LinkedList<Segment>> sums : segments.entrySet()) {


            LinkedList<Segment> currentSegments = sums.getValue();
            Collections.sort(currentSegments);

            LinkedList<Segment> segmentsWithoutCrossing = new LinkedList<>();

            for (Segment segment : currentSegments) {


                if ( segmentsWithoutCrossing.isEmpty() || !segmentsWithoutCrossing.getLast().isCrossingToNextSegment(segment)) {

                    segmentsWithoutCrossing.add(segment);

                } else if (segmentsWithoutCrossing.getLast().getR() > segment.getR()) {

                    segmentsWithoutCrossing.removeLast();
                    segmentsWithoutCrossing.add(segment);

                }

            }

            answer = segmentsWithoutCrossing.size() > (answer != null ? answer.size() : 0) ? segmentsWithoutCrossing : answer;

        }

    }

    private static void out() {

        System.out.println(answer.size());

        for (Segment segment : answer) {
            System.out.println( (segment.getL() + 1) + " " + (segment.getR() + 1));
        }

    }

}

class Segment implements Comparable<Segment>{

    private int l, r;

    Segment(int l, int r) {
        this.l = l;
        this.r = r;
    }


    int getL() {
        return l;
    }

    int getR() {
        return r;
    }

    @Override
    public int compareTo(Segment segment) {

        if (l == segment.l && r == segment.r) {
            return 0;
        }

        return l != segment.l ? l - segment.l : r - segment.r;

    }

    boolean isCrossingToNextSegment(Segment segment) {
        if (l == segment.l || r == segment.r) {
            return true;
        } else if (l < segment.l) {
            return r >= segment.l;
        } else if (r > segment.r) {
            return l <= segment.r;
        } else {
            return true;
        }
    }

}
// Problem: 1141_F2. Same Sum Blocks (Hard)
// Time complexity: quadratic
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class F1141 {
	
	private static class Interval {
		public int l;
		public int r;
		
		public Interval(int l,int r) {
			this.l = l;
			this.r = r;
		}
	}

	public static void main(String[] args) throws IOException {
//		BufferedReader br = new BufferedReader(new FileReader("F:/books/input.txt"));
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s = br.readLine();
		int n = Integer.parseInt(s);
		long[] a = new long[n];
		String[] as = br.readLine().split(" ");
		for(int i=0;i<n;i++) {
			a[i] = Long.parseLong(as[i]);
		}
		StringBuffer sb = solve(a,n);
		System.out.println(sb.toString());
	}

	private static StringBuffer solve(long[] a, int n) {
		StringBuffer ret = new StringBuffer("");
		Map<Long,List<Interval>> mp = new HashMap<Long,List<Interval>>();
		long max = 0,maxId = -1;
		for(int i=n-1;i>=0;i--) {
			long s=0;
			long prev = 1;
			for(int j=i;j<n;j++) {
				s+=a[j];
//				System.out.println(i+","+j);
				Interval inter = new Interval(i,j);
//				if(prev==1 || prev==-1) {
					List<Interval> ints = mp.get(s);
					if(ints==null) ints = new ArrayList<Interval>();
					if(ints.size()==0 || ints.get(0).l>j) {
						ints.add(0,inter);
					}
					if(ints.size()>max) {
						max = ints.size();
						maxId = s;
					}
					mp.put(s, ints);
//				}
				if(j<n-1) prev =  a[j+1]-a[j];
			}
		}
		List<Interval> l = mp.get(maxId);
		ret.append(l.size()+ "\n");
		for(Interval inter : l) {
			ret.append((inter.l+1) + " " + (inter.r+1) + "\n");
		}
		return ret;
	}

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

public class Main {
	public static void main(String args[]) {new Main().run();}

	FastReader in = new FastReader();
	PrintWriter out = new PrintWriter(System.out);
	void run(){
		work();
		out.flush();
	}
	long mod=998244353;
	long gcd(long a,long b) {
		return b==0?a:gcd(b,a%b);
	}
	void work() {
		int n=in.nextInt();
		int[] A=new int[n];
		for(int i=0;i<n;i++)A[i]=in.nextInt();
		HashMap<Integer,Integer> map=new HashMap<>();
		HashMap<Integer,ArrayList<int[]>> rec=new HashMap<>();
		for(int i=0;i<n;i++) {
			for(int j=i,cur=0;j>=0;j--) {
				cur+=A[j];
				if(map.get(cur)==null) {
					map.put(cur,i);
					rec.put(cur,new ArrayList<>());
					rec.get(cur).add(new int[] {j,i});
				}else if(map.get(cur)<j) {
					map.put(cur,i);
					rec.get(cur).add(new int[] {j,i});
				}
			}
		}
		ArrayList<int[]> ret=null;
		for(ArrayList<int[]> list:rec.values()) {
			if(ret==null||ret.size()<list.size()) {
				ret=list;
			}
		}
		out.println(ret.size());
		for(int[] r:ret) {
			out.println((r[0]+1)+" "+(r[1]+1));
		}
	}
}	



class FastReader
{
	BufferedReader br;
	StringTokenizer st;

	public FastReader()
	{
		br=new BufferedReader(new InputStreamReader(System.in));
	}

	public String next() 
	{
		if(st==null || !st.hasMoreElements())
		{
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return st.nextToken();
	}

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

	public long nextLong()
	{
		return Long.parseLong(next());
	}
}
// Problem: 1141_F2. Same Sum Blocks (Hard)
// Time complexity: quadratic
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

public class Solution {

	public static void main(String[] args) throws Exception {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		StringTokenizer st = new StringTokenizer(br.readLine());

		long[] a = new long[n];

		for (int i = 0; i < a.length; i++) {
			a[i] = Long.parseLong(st.nextToken());
		}

		long[] sum = new long[n];
		sum[0] = a[0];
		for (int i = 1; i < sum.length; i++) {
			sum[i] = sum[i - 1] + a[i];
		}

		solve(a, sum);

	}

	private static void solve(long[] a, long[] sum) {
		int n = a.length;

		Map<Long, List<Pair>> map = new HashMap<>();

		for (int j = 0; j < sum.length; j++) {
			for (int i = 0; i <= j; i++) {
				long k = getSum(sum, i, j);
				if (map.containsKey(k)) {
					map.get(k).add(new Pair(i, j));
				} else {
					List<Pair> arr = new ArrayList<>();
					arr.add(new Pair(i, j));
					map.put(k, arr);
				}
			}
		}

		int max = -1;
		List<Pair> ans = null;
		for (Map.Entry<Long, List<Pair>> entry : map.entrySet()) {
			List<Pair> pairs = entry.getValue();

			int prev = -1;
			int count = 0;
			List<Pair> temp = new ArrayList<Pair>();
			for (Pair p : pairs) {
				if (p.x > prev) {
					prev = p.y;
					temp.add(p);
					count++;
				}
			}

			if (count > max) {
				ans = temp;
				max = count;
			}
		}
		if (max != -1) {
			System.out.println(ans.size());
			for (Pair p : ans) {
				System.out.println((p.x + 1) + " " + (p.y + 1));
			}
		}
	}

	private static long getSum(long[] sum, int l, int r) {
		if (l == 0) {
			return sum[r];
		}
		return sum[r] - sum[l - 1];
	}
}

class Pair {

	int x;
	int y;

	Pair(int x, int y) {
		this.x = x;
		this.y = y;
	}

	@Override
	public int hashCode() {
		int h = 171 << 4;
		h = h * x;
		h = h * y;
		return h;
	}

	@Override
	public boolean equals(Object o) {
		if (o instanceof Pair) {
			Pair other = (Pair) o;
			return this.x == other.x && this.y == other.y;
		}
		return false;
	}

	@Override
	public String toString() {
		return "Pair [x=" + x + ", y=" + y + "]";
	}

}
// Problem: 1141_F2. Same Sum Blocks (Hard)
// Time complexity: quadratic
//package com.example.programming;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Scanner;


public class CodeforcesProblems {


    static class Pair {
        public Pair(int key, int val) {
            this.key = key;
            this.val = val;
        }
        int key;
        int val;
    }


    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        //String[] strings = br.readLine().split(" ");
        int n = Integer.parseInt(br.readLine());

        String[] strings = br.readLine().split(" ");
        int[] arr = new int[n];
        for(int i = 0; i<n; i++) {
            arr[i] = Integer.parseInt(strings[i]);
        }


        HashMap<Integer, ArrayList<Pair>> segments = new HashMap<>();
        for(int r = 0; r<arr.length; r++) {
            int sum = 0;
            for(int l = r; l>=0; l--) {
                sum += arr[l];
                ArrayList<Pair> pairs = segments.get(sum);
                if(pairs == null) {
                    pairs = new ArrayList<>();
                    segments.put(sum, pairs);
                }
                pairs.add(new Pair(l, r));
            }
        }

        int res = 0;
        ArrayList<Pair> result = new ArrayList<>();
        for(ArrayList<Pair> pairs: segments.values()) {
            ArrayList<Pair> temp = new ArrayList<>();
            int count = 0;
            int r = -1;
            for(Pair p : pairs) {
                if(p.key>r) {
                    count++;
                    temp.add(p);
                    r = p.val;
                }
            }
            if(count>res) {
                res = count;
                result = temp;
            }
        }
        System.out.println(res);
        StringBuilder sb = new StringBuilder();
        for(Pair p : result){
            sb.append(p.key+1).append(' ').append(p.val+1).append('\n');
        }
        System.out.print(sb);
    }
}
// Problem: 1141_F2. Same Sum Blocks (Hard)
// Time complexity: quadratic
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;

public class CF1141F {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] split = br.readLine().split(" ");
		int[] terms = new int[n];
		int[] sums = new int[n+1];
		for(int i=0; i<n; i++) {
			terms[i] = Integer.parseInt(split[i]);
			sums[i+1] = sums[i]+terms[i];
		}
		ArrayList<Block> blocks = new ArrayList<>();
		for(int i=0; i<n; i++)
			for(int j=i; j<n; j++){
				int s = sums[j+1]-sums[i];
				blocks.add(new Block(i, j, s));
			}
		Collections.sort(blocks);
		ArrayList<Block> best = new ArrayList<>();
		int i = 0;
		while(i<blocks.size()){
			int curSum = blocks.get(i).sum;
			ArrayList<Block> curBlocks = new ArrayList<>();
			while(i<blocks.size() && blocks.get(i).sum==curSum) curBlocks.add(blocks.get(i++));
			int[] memo = new int[curBlocks.size()+1];
			Arrays.fill(memo, -1);
			memo[curBlocks.size()] = 0;
			for(int j=curBlocks.size()-1; j>=0; j--){
				int idx = Collections.binarySearch(curBlocks, new Block(curBlocks.get(j).r+1, curBlocks.get(j).r+1, curBlocks.get(j).sum));
				if(idx<0) idx = -(idx+1);
				memo[j] = Math.max(memo[j+1], 1+memo[idx]);
			}
			if(memo[0]>best.size()){
				best = new ArrayList<>();
				int idx = 0;
				while(memo[idx]>=1){
					if(memo[idx]>memo[idx+1]) best.add(curBlocks.get(idx));
					idx++;
				}
			}
		}
		StringBuilder sb = new StringBuilder();
		sb.append(best.size()).append("\n");
		for(Block b : best){
			sb.append(b.l+1).append(" ").append(b.r+1).append("\n");
		}
		System.out.print(sb);
	}
	
	static class Block implements Comparable<Block>{
		int l, r, sum;
		
		Block(int a, int b, int c){
			l = a;
			r = b;
			sum = c;
		}

		@Override
		public int compareTo(Block o) {
			if(sum==o.sum){
				if(l==o.l) return r-o.r;
				return l-o.l;
			}
			return sum-o.sum;
		}
	}
}
// Problem: 1141_F2. Same Sum Blocks (Hard)
// Time complexity: quadratic
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args)
	{
		Scanner s=new Scanner(System.in);
		
		int n=s.nextInt();
		
		long[] arr=new long[n];
		
		for(int i=0;i<n;i++)
		{
			arr[i]=s.nextInt();
		}
		
		long[] pre=new long[n];
		
		pre[0]=arr[0];
		
		for(int i=1;i<n;i++)
		{
			pre[i]=pre[i-1]+arr[i];
		}
		
		HashMap<Long,ArrayList<pair>> map=new HashMap<>();
		
		for(int i=0;i<n;i++)
		{
			for(int j=i;j<n;j++)
			{
				long key=pre[j]-pre[i]+arr[i];
				
				if(map.containsKey(key))
				{
					pair p=new pair(i+1,j+1);
					ArrayList<pair> temp=map.get(key);
					temp.add(p);
					
					map.put(key,temp);
				}
				else
				{
					ArrayList<pair> list=new ArrayList<>();
					pair p=new pair(i+1,j+1);
					list.add(p);
					
					map.put(key,list);
				}
			}
		}
		
		for(Map.Entry<Long,ArrayList<pair>> entry:map.entrySet())
		{
			ArrayList<pair> curr=entry.getValue();
			
			Collections.sort(curr,new comp());
		}
		
		long ans=0;
		long max=-1000000000000l;
		
		for(Map.Entry<Long,ArrayList<pair>> entry:map.entrySet())
		{
			ArrayList<pair> curr=entry.getValue();
			
			int count=1;
			int l=curr.get(0).l;
			int r=curr.get(0).r;
			
			for(int i=1;i<curr.size();i++)
			{
				if(curr.get(i).l>r)
				{
					count++;
					l=curr.get(i).l;
					r=curr.get(i).r;
				}
			}
			
			if(count>max)
			{
				max=count;
				ans=entry.getKey();
			}
			
		}
		
		System.out.println(max);
		
		ArrayList<pair> list=map.get(ans);
		
		System.out.println(list.get(0).l+" "+list.get(0).r);
		
		int l=list.get(0).l;
		int r=list.get(0).r;
		
		for(int i=1;i<list.size();i++)
		{
			if(list.get(i).l>r)
			{
				System.out.println(list.get(i).l+" "+list.get(i).r);
				l=list.get(i).l;
				r=list.get(i).r;
			}
		}
		
	}
	
}

class pair
{
	int l;
	int r;
	
	public pair(int l,int r)
	{
		this.l=l;
		this.r=r;
	}
}

class comp implements Comparator<pair>
{
	public int compare(pair a,pair b)
	{
		if(a.r<b.r)
			return -1;
		else if(a.r==b.r)
		{
			return b.l-a.l;
		}
		else
			return 1;
	}
}
// Problem: 1141_F2. Same Sum Blocks (Hard)
// Time complexity: quadratic
import java.util.*;

public class Main {
    static class Node implements Comparable<Node>{
        public int l,r;
        public long s;
        Node(int l,int r,long s){
            this.l=l;
            this.r=r;
            this.s=s;
        }
        public int compareTo(Node o) {
            if(o.s==s){
                if(r>o.r) return 1;
                else if(r==o.r) {
                    return 0;
                }
                else return -1;
            } else if(s>o.s){
                return 1;
            } else {
                return -1;
            }
        }
    }
    static long[] sum=new long[1550];
    public static void main(String[] args) {
        TreeMap<Long, ArrayList<Node> > mp = new TreeMap<>();
        Scanner cin = new Scanner(System.in);
        int N=cin.nextInt();
        for(int i=1;i<=N;i++){
            int x=cin.nextInt();
            sum[i]=sum[i-1]+x;
        }
        //System.out.println("here");
        ArrayList<Node> arr = new ArrayList<>();
        for(int l=1;l<=N;l++){
            for(int r=l;r<=N;r++){
                arr.add(new Node(l,r,sum[r]-sum[l-1]));
            }
        }
        Collections.sort(arr);
        for(int i=0;i<arr.size();i++){
            ArrayList<Node> a=mp.get(arr.get(i).s);
            if(a==null) {
                a=new ArrayList<>();
                mp.put(arr.get(i).s,a);
            }
            a.add(arr.get(i));
        }
        int mx=-1;
        long mxv=-1;
        Iterator<Long> it=mp.keySet().iterator();
        while(it.hasNext()){
            int ans=0,t=0;
            long v=it.next();
            ArrayList<Node> vec= mp.get(v);
            for(int i=0;i<vec.size();i++){
                if(t<vec.get(i).l){
                    ans++;
                    t=vec.get(i).r;
                }
            }
           //
            if(ans>mx){
                mx=ans;
                mxv=v;
               // System.out.println(mxv);
            }
        }
        ArrayList<Node> vec=mp.get(mxv);
        System.out.println(mx);
        int t=0;
        for(int i=0;i<vec.size();i++){

           // System.out.println(vec.get(i).l+" "+vec.get(i).r);
          // System.out.println("h");
            if(t<vec.get(i).l){
                System.out.println(vec.get(i).l+" "+vec.get(i).r);
                t=vec.get(i).r;
            }
        }
    }
}
// Problem: 1141_F2. Same Sum Blocks (Hard)
// Time complexity: quadratic
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.HashMap;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskF2 solver = new TaskF2();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskF2 {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = in.nextInt();
            }

            Map<Long, List<Pair>> map = new HashMap<>();
            for (int r = 0; r < n; r++) {
                long sum = 0;
                for (int l = r; l >= 0; l--) {
                    sum += arr[l];
                    if (map.containsKey(sum)) {
                        map.get(sum).add(new Pair(l, r));
                    } else {
                        map.put(sum, new ArrayList<>());
                        map.get(sum).add(new Pair(l, r));
                    }
                }
            }
            int ans = -1;
            List<Pair> ansPairs = new ArrayList<>();
            for (long sum : map.keySet()) {
                List<Pair> pairs = map.get(sum);
                int count = 0;
                int idx = -1;
                List<Pair> tempPairs = new ArrayList<>();
                for (Pair pair : pairs) {
                    if (pair.i > idx) {
                        idx = pair.j;
                        tempPairs.add(pair);
                        count++;
                    }
                }
                if (ans < count) {
                    ans = count;
                    ansPairs = tempPairs;
                }
            }
            out.println(ans);
            for (Pair pair : ansPairs) {
                out.print((pair.i + 1) + " " + (pair.j + 1));
                out.println();
            }
        }

        class Pair {
            int i;
            int j;

            Pair(int p, int q) {
                i = p;
                j = q;
            }

        }

    }
}
// Problem: 1141_F2. Same Sum Blocks (Hard)
// Time complexity: quadratic
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class b {

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

		int n=s.nextInt();
		long[] arr=new long[n];
		
		for(int i=0;i<n;i++) {
			arr[i]=s.nextLong();
		}
		HashMap<Long,ArrayList<pair>> map=new HashMap<>();
	
		ArrayList<pair> list=new ArrayList<>();
		for(int i=0;i<n;i++) {
			long sum=0;
			for(int j=i;j<n;j++) {
				sum=sum+arr[j];
				pair ob=new pair(i,j);
				if(map.containsKey(sum))
				{
					ArrayList p=map.get(sum);
					p.add(ob);
					map.put(sum, p);
					
				}else {
					ArrayList<pair> listt=new ArrayList<>();
					listt.add(ob);
					map.put(sum,listt);
				}
			}
		}
	
		
		
		
		
		long in=-1;
		int max=0;
		
		for(Map.Entry<Long, ArrayList<pair>> entry:map.entrySet()) {
			int l=1;
			ArrayList<pair> p=entry.getValue();
			Collections.sort(p,new comp());
			int now=p.get(0).end;
			for(int j=0;j<p.size();j++) {
				
			
			
				if(p.get(j).st>now) {
					l++;
					now=p.get(j).end;
					
				}
			
				
			}
			
			if(l>max) {
				max=l;
				in=entry.getKey();
			}
		}
		
		System.out.println(max);
		
		
		ArrayList<pair> d=map.get(in);
		int now=-1;
		for(int j=0;j<d.size();j++) {
		
			if(d.get(j).st>now) {
				System.out.println((d.get(j).st+1)+" "+(d.get(j).end+1));
				now=d.get(j).end;
				}
		
			
		}
		
		
		
		
	}
}
class pair{
	//long val;
	int st;
	int end;
	public pair(int st,int end) {
		//this.val=val;
		this.st=st;
		this.end=end;
	}
}
class comp implements Comparator<pair>{
	
	public int compare(pair h,pair j) {
		
		if(h.end<j.end) {
			return -1;
		}else if(h.end==j.end) {
			if(h.st<j.st) {
				return 1;
			}else if(h.st==j.st) {
				return 0;
			}else {
				return -1;
			}
		}else {
			return 1;
		}
	}
}