import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author beginner1010
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(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, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
            }

            HashMap<Integer, ArrayList<Interval>> map = new HashMap<>();
            for (int i = 0; i < n; i++) {
                int sum = 0;
                for (int j = i; j < n; j++) {
                    sum += a[j];
                    if (map.containsKey(sum) == false) {
                        map.put(sum, new ArrayList<>());
                    }
                    ArrayList<Interval> arr = map.get(sum);
                    if (arr.isEmpty() || arr.get(arr.size() - 1).r < i) {
                        arr.add(new Interval(i, j));
                    } else if (arr.get(arr.size() - 1).r >= j) {
                        arr.set(arr.size() - 1, new Interval(i, j));
                    }
                }
            }

            ArrayList<Interval> best = new ArrayList<>();
            for (ArrayList<Interval> arr : map.values()) {
                if (best.size() < arr.size()) {
                    best = arr;
                }
            }

            out.println(best.size());
            for (Interval i : best) {
                out.println((i.l + 1) + " " + (i.r + 1));
            }
        }

        class Interval {
            int l;
            int r;

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

        }

    }

    static class InputReader {
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputStream stream;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        private boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isWhitespace(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isWhitespace(c));
            return res * sgn;
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Vector;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.Stack;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author beginner1010
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(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, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
            }

            HashMap<Integer, Stack<Interval>> map = new HashMap<>();
            for (int i = 0; i < n; i++) {
                int sum = 0;
                for (int j = i; j < n; j++) {
                    sum += a[j];
                    if (map.containsKey(sum) == false) {
                        map.put(sum, new Stack<>());
                    }
                    Stack<Interval> stack = map.get(sum);
                    if (stack.isEmpty() || stack.get(stack.size() - 1).r < i) {
                        stack.push(new Interval(i, j));
                    } else if (stack.get(stack.size() - 1).r >= j) {
                        stack.pop();
                        stack.push(new Interval(i, j));
                    }
                }
            }

            Stack<Interval> best = new Stack<>();
            for (Stack<Interval> stack : map.values()) {
                if (best.size() < stack.size()) {
                    best = stack;
                }
            }

            out.println(best.size());
            for (Interval i : best) {
                out.println((i.l + 1) + " " + (i.r + 1));
            }
        }

        class Interval {
            int l;
            int r;

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

        }

    }

    static class InputReader {
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputStream stream;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        private boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isWhitespace(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isWhitespace(c));
            return res * sgn;
        }

    }
}


import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main {
	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		PrintWriter out = new PrintWriter(outputStream);
		InputReader in = new InputReader(inputStream);

//		for(int i=4;i<=4;i++) {
//			InputStream uinputStream = new FileInputStream("shortcut.in");
//			String f = i+".in";
//			InputStream uinputStream = new FileInputStream(f);
//			InputReader in = new InputReader(uinputStream);
//			PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("shortcut.out")));
			Task t = new Task();
			t.solve(in, out);
			out.close();
//		}
	}

	static class Task {

		public void solve(InputReader in, PrintWriter out) throws IOException {
			int n = in.nextInt();
			int arr[] = in.readIntArray(n);
			int v[][] = new int[n][n];
			int c=0;
			HashMap<Integer,Integer> mp = new HashMap<Integer,Integer>();
			for(int i=0;i<n;i++) {
				for(int j=i;j<n;j++) {
					v[i][j] = arr[j];
					if(j>i) v[i][j] += v[i][j-1];
					if(!mp.containsKey(v[i][j])) mp.put(v[i][j], c++);
				}
			}
			ArrayList<seg>[] all = new ArrayList[c];
			for(int i=0;i<c;i++) all[i] = new ArrayList<seg>();
			for(int i=0;i<n;i++) {
				for(int j=i;j<n;j++) {
					int idx = mp.get(v[i][j]);
					all[idx].add(new seg(i,j,v[i][j]));
				}
			}
			for(int i=0;i<c;i++) Collections.sort(all[i]);
			int max = Integer.MIN_VALUE;
			int val = -1;
			for(int i=0;i<c;i++) {
				if(all[i].size()==0) continue;
				int num=1;
				int p=0;int q=p+1;
				while(q<all[i].size()) {
					if(all[i].get(q).s>all[i].get(p).e) {
						p=q;
						num++;
					}
					q++;
				}
				if(num>max) {
					max=num;
					val = i;
				}
			}
			out.println(max);
			StringBuilder sb = new StringBuilder();
			int p=0;int q=p+1;
			sb.append(all[val].get(0).toString());
			while(q<all[val].size()) {
				if(all[val].get(q).s>all[val].get(p).e) {
					sb.append(all[val].get(q).toString());
					p=q;
				}
				q++;
			}
			out.println(sb.toString());
		}
		public class seg implements Comparable<seg>{
			int s; int e; int val;
			public seg(int a, int b, int c) {
				s=a;e=b;val=c;
			}
			@Override
			public int compareTo(seg t) {
				if(this.e==t.e) return this.s-t.s;
				return this.e-t.e;
			}
			public String toString() {
				return (s+1)+" "+(e+1)+"\n";
			}
		}
		public int GCD(int a, int b) {
		   if (b==0) return a;
		   return GCD(b,a%b);
		}
	}

    static class ArrayUtils {
        static final long seed = System.nanoTime();
        static final Random rand = new Random(seed);

        public static void sort(int[] a) {
            shuffle(a);
            Arrays.sort(a);
        }

        public static void shuffle(int[] a) {
            for (int i = 0; i < a.length; i++) {
                int j = rand.nextInt(i + 1);
                int t = a[i];
                a[i] = a[j];
                a[j] = t;
            }
        }

    }
	static class BIT{
		int arr[];
		int n;
		public BIT(int a) {
			n=a;
			arr = new int[n];
		}
		int sum(int p) {
			int s=0;
			while(p>0) {
				s+=arr[p];
				p-=p&(-p);
			}
			return s;
		}
		void add(int p, int v) {
			while(p<n) {
				arr[p]+=v;
				p+=p&(-p);
			}
		}
	}
	static class DSU{
		int[] arr;
		int[] sz;
		public DSU(int n) {
			arr = new int[n];
			sz = new int[n];
			for(int i=0;i<n;i++) arr[i] = i;
			Arrays.fill(sz, 1);
		}
		public int find(int a) {
			if(arr[a]!=a) arr[a] = find(arr[a]);
			return arr[a];
		}
		public void union(int a, int b) {
			int x = find(a);
			int y = find(b);
			if(x==y) return;
			arr[x] = y;
			sz[y] += sz[x];
		}
		public int size(int x) {
			return sz[find(x)];
		}
	}
	static class MinHeap<Key> implements Iterable<Key> {
		private int maxN;
		private int n;
		private int[] pq;
		private int[] qp;
		private Key[] keys;
		private Comparator<Key> comparator;

		public MinHeap(int capacity){
			if (capacity < 0) throw new IllegalArgumentException();
			this.maxN = capacity;
			n=0;
			pq = new int[maxN+1];
			qp = new int[maxN+1];
			keys = (Key[]) new Object[capacity+1];
			Arrays.fill(qp, -1);
		}

		public MinHeap(int capacity, Comparator<Key> c){
			if (capacity < 0) throw new IllegalArgumentException();
			this.maxN = capacity;
			n=0;
			pq = new int[maxN+1];
			qp = new int[maxN+1];
			keys = (Key[]) new Object[capacity+1];
			Arrays.fill(qp, -1);
			comparator = c;
		}
		public boolean isEmpty()	{ return n==0; 	}
		public int size()			{ return n;		}
		public boolean contains(int i) {
	        if (i < 0 || i >= maxN) throw new IllegalArgumentException();
	        return qp[i] != -1;
		}
		public int peekIdx() {
	        if (n == 0) throw new NoSuchElementException("Priority queue underflow");
	        return pq[1];
		}
		public Key peek(){
			if(isEmpty()) throw new NoSuchElementException("Priority queue underflow");
			return keys[pq[1]];
		}
		public int poll(){
			if(isEmpty()) throw new NoSuchElementException("Priority queue underflow");
			int min = pq[1];
			exch(1,n--);
			down(1);
			assert min==pq[n+1];
			qp[min] = -1;
			keys[min] = null;
			pq[n+1] = -1;
			return min;
		}
	    public void update(int i, Key key) {
	        if (i < 0 || i >= maxN) throw new IllegalArgumentException();
	        if (!contains(i)) {
	        	this.add(i, key);
	        }else {
	        	keys[i] = key;
	        	up(qp[i]);
	        	down(qp[i]);
	        }
	    }
		private void add(int i, Key x){
	        if (i < 0 || i >= maxN) throw new IllegalArgumentException();
	        if (contains(i)) throw new IllegalArgumentException("index is already in the priority queue");
	        n++;
	        qp[i] = n;
	        pq[n] = i;
	        keys[i] = x;
	        up(n);
		}
		private void up(int k){
			while(k>1&&less(k,k/2)){
				exch(k,k/2);
				k/=2;
			}
		}
		private void down(int k){
			while(2*k<=n){
				int j=2*k;
				if(j<n&&less(j+1,j)) j++;
				if(less(k,j)) break;
				exch(k,j);
				k=j;
			}
		}

		public boolean less(int i, int j){
	        if (comparator == null) {
	            return ((Comparable<Key>) keys[pq[i]]).compareTo(keys[pq[j]]) < 0;
	        }
	        else {
	            return comparator.compare(keys[pq[i]], keys[pq[j]]) < 0;
	        }
		}

		public void exch(int i, int j){
	        int swap = pq[i];
	        pq[i] = pq[j];
	        pq[j] = swap;
	        qp[pq[i]] = i;
	        qp[pq[j]] = j;
		}

		@Override
		public Iterator<Key> iterator() {
			// TODO Auto-generated method stub
			return null;
		}
	}

    private static class InputReader
    {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int zcurChar;
        private int znumChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream)
        {
            this.stream = stream;
        }

        public int read()
        {
            if (znumChars == -1)
                throw new InputMismatchException();
            if (zcurChar >= znumChars)
            {
            	zcurChar = 0;
                try
                {
                    znumChars = stream.read(buf);
                } catch (IOException e)
                {
                    throw new InputMismatchException();
                }
                if (znumChars <= 0)
                    return -1;
            }
            return buf[zcurChar++];
        }

        public int nextInt()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-')
            {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do
            {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public String nextString()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do
            {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public double nextDouble()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-')
            {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.')
            {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.')
            {
                c = read();
                double m = 1;
                while (!isSpaceChar(c))
                {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public long nextLong()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-')
            {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do
            {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c)
        {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next()
        {
            return nextString();
        }

        public interface SpaceCharFilter
        {
            public boolean isSpaceChar(int ch);
        }
        public int[] readIntArray(int n) {
            int[] ret = new int[n];
            for (int i = 0; i < n; i++) {
                ret[i] = nextInt();
            }
            return ret;
        }
    }

	static class Dumper {
		static void print_int_arr(int[] arr) {
			for (int i = 0; i < arr.length; i++) {
				System.out.print(arr[i] + " ");
			}
			System.out.println();
			System.out.println("---------------------");
		}

		static void print_char_arr(char[] arr) {
			for (int i = 0; i < arr.length; i++) {
				System.out.print(arr[i] + " ");
			}
			System.out.println();
			System.out.println("---------------------");
		}

		static void print_double_arr(double[] arr) {
			for (int i = 0; i < arr.length; i++) {
				System.out.print(arr[i] + " ");
			}
			System.out.println();
			System.out.println("---------------------");
		}

		static void print_2d_arr(int[][] arr, int x, int y) {
			for (int i = 0; i < x; i++) {
				for (int j = 0; j < y; j++) {
					System.out.print(arr[i][j] + " ");
				}
				System.out.println();
			}
			System.out.println();
			System.out.println("---------------------");
		}

		static void print_2d_arr(boolean[][] arr, int x, int y) {
			for (int i = 0; i < x; i++) {
				for (int j = 0; j < y; j++) {
					System.out.print(arr[i][j] + " ");
				}
				System.out.println();
			}
			System.out.println();
			System.out.println("---------------------");
		}

		static void print(Object o) {
			System.out.println(o.toString());
		}

		static void getc() {
			System.out.println("here");
		}
	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.BufferedInputStream;
import java.util.HashMap;
import java.util.ArrayList;
import java.io.FilterInputStream;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Comparator;
import java.util.Collections;
import java.io.InputStream;

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

    static class F2SameSumBlocksHard {
        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            int n = in.scanInt();
            long arr[] = new long[n];
            for (int i = 0; i < n; i++) {
                arr[i] = in.scanLong();
            }

            HashMap<Long, ArrayList<pair>> hm = new HashMap<>();
            for (int i = 0; i < n; i++) {
                long sum = 0;
                for (int j = i; j < n; j++) {
                    sum += arr[j];
                    if (hm.containsKey(sum)) {
                        hm.get(sum).add(new pair(i + 1, j + 1));
                    } else {
                        hm.put(sum, new ArrayList<>());
                        hm.get(sum).add(new pair(i + 1, j + 1));
                    }
                }
            }

            long maxi_sum = -1;
            long sum = 0;
            for (Map.Entry<Long, ArrayList<pair>> k : hm.entrySet()) {
                Collections.sort(k.getValue(), new Comparator<pair>() {

                    public int compare(pair o1, pair o2) {
                        return o1.r - o2.r;
                    }
                });

                int count = k.getValue().size() > 0 ? 1 : 0;
                int index = 0;
                for (int i = 1; i < k.getValue().size(); i++) {
                    if (k.getValue().get(i).l > k.getValue().get(index).r) {
                        count++;
                        index = i;
                    }
                }

                if (count > maxi_sum) {
                    maxi_sum = count;
                    sum = k.getKey();
                }
            }

            out.println(maxi_sum);
            ArrayList<pair> tt = hm.get(sum);
            Collections.sort(tt, new Comparator<pair>() {

                public int compare(pair o1, pair o2) {
                    return o1.r - o2.r;
                }
            });

            out.println(tt.size() > 0 ? (tt.get(0).l + " " + tt.get(0).r) : (" "));
            int index = 0;
            for (int i = 1; i < tt.size(); i++) {
                if (tt.get(i).l > tt.get(index).r) {
                    out.println(tt.get(i).l + " " + tt.get(i).r);
                    index = i;
                }
            }

        }

        class pair {
            int l;
            int r;

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

        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int INDEX;
        private BufferedInputStream in;
        private int TOTAL;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (INDEX >= TOTAL) {
                INDEX = 0;
                try {
                    TOTAL = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (TOTAL <= 0) return -1;
            }
            return buf[INDEX++];
        }

        public int scanInt() {
            int I = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    I *= 10;
                    I += n - '0';
                    n = scan();
                }
            }
            return neg * I;
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

        public long scanLong() {
            long I = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    I *= 10;
                    I += n - '0';
                    n = scan();
                }
            }
            return neg * I;
        }

    }
}


import java.util.*;
import java.lang.*;
import java.io.*;
import java.awt.*;

// U KNOW THAT IF THIS DAY WILL BE URS THEN NO ONE CAN DEFEAT U HERE................
//JUst keep faith in ur strengths ..................................................

// ASCII = 48 + i ;// 2^28 = 268,435,456  > 2* 10^8 // log 10 base 2 = 3.3219
// odd:: (x^2+1)/2 , (x^2-1)/2 ; x>=3// even:: (x^2/4)+1 ,(x^2/4)-1  x >=4
// FOR ANY ODD NO N : N,N-1,N-2
//ALL ARE PAIRWISE COPRIME
//THEIR COMBINED LCM IS PRODUCT OF ALL THESE NOS

// two consecutive odds are always coprime to each other
// two consecutive even have always gcd  = 2 ;

// Rectangle r = new Rectangle(int x , int y,int widht,int height)
//Creates a rect. with bottom left cordinates as (x, y) and top right as ((x+width),(y+height))

//BY DEFAULT Priority Queue is MIN in nature in java
//to use as max , just push with negative sign and change sign after removal

// We can make a sieve of max size 1e7 .(no time or space issue)
// In 1e7 starting nos we have about 66*1e4 prime nos

 public class Main
{

    // static int[] arr = new int[100002] ;
    // static int[] dp = new int[100002] ;

     static PrintWriter out;

	static class FastReader{
		BufferedReader br;
		StringTokenizer st;
		public FastReader(){
			br=new BufferedReader(new InputStreamReader(System.in));
			out=new PrintWriter(System.out);
		}
		String next(){
			while(st==null || !st.hasMoreElements()){
				try{
					st= new StringTokenizer(br.readLine());
				}
				catch (IOException e){
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}
		int nextInt(){
			return Integer.parseInt(next());
		}
		long nextLong(){
			return Long.parseLong(next());
		}
		double nextDouble(){
			return Double.parseDouble(next());
		}
		String nextLine(){
			String str = "";
			try{
				str=br.readLine();
			}
			catch(IOException e){
				e.printStackTrace();
			}
			return str;
		}
	}

////////////////////////////////////////////////////////////////////////////////////
 public static int countDigit(long n)
    {
        return (int)Math.floor(Math.log10(n) + 1);
    }

/////////////////////////////////////////////////////////////////////////////////////////

 public static int sumOfDigits(long n)
 {

  if( n< 0)return -1 ;

  int sum = 0;

  while( n > 0)
  {
      sum = sum + (int)( n %10) ;

      n /= 10 ;
  }

  return sum ;

 }

 //////////////////////////////////////////////////////////////////////////////////////////////////

public static long arraySum(int[] arr , int start , int end)
{
    long ans = 0 ;

    for(int i = start ; i <= end  ; i++)ans += arr[i] ;

    return ans  ;
}

/////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////

public static void swapArray(int[] arr , int start , int end)
{
    while(start < end)
    {
        int temp = arr[start] ;
        arr[start] = arr[end];
        arr[end] = temp;
        start++ ;end-- ;
    }
}

//////////////////////////////////////////////////////////////////////////////////

static long factorial(long a)
{
    if(a== 0L || a==1L)return 1L ;

    return a*factorial(a-1L) ;
}

///////////////////////////////////////////////////////////////////////////////

public static int[][] rotate(int[][] input){

int n =input.length;
int m = input[0].length ;
int[][] output = new int [m][n];

for (int i=0; i<n; i++)
	for (int j=0;j<m; j++)
		output [j][n-1-i] = input[i][j];
return output;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////// ////////////////////////////////////////////////

public static boolean isPowerOfTwo(long n)
{
    if(n==0)
    return false;

if(((n ) & (n-1)) == 0 ) return true ;
else return false  ;

}

/////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////

public static String reverse(String input)
{
  StringBuilder str  = new StringBuilder("") ;

    for(int i =input.length()-1 ; i >= 0  ; i-- )
    {
        str.append(input.charAt(i));
    }

return str.toString() ;
}
///////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////
public static boolean isPossibleTriangle(int a  ,int b , int c)
{
      if( a + b > c && c+b > a && a +c > b)return true  ;
      else return false  ;
}

////////////////////////////////////////////////////////////////////////////////////////////
static long xnor(long num1, long num2) {
		if (num1 < num2) {
			long temp = num1;
			num1 = num2;
			num2 = temp;
		}
		num1 = togglebit(num1);
		return num1 ^ num2;
	}

	static long togglebit(long n) {
		if (n == 0)
			return 1;
		long i = n;
		n |= n >> 1;
		n |= n >> 2;
		n |= n >> 4;
		n |= n >> 8;
		n |= n >> 16;
		return i ^ n;
	}

///////////////////////////////////////////////////////////////////////////////////////////////

public static int xorOfFirstN(int n)
{

 if( n % 4 ==0)return n ;

 else if( n % 4 == 1)return 1 ;

 else if( n % 4 == 2)return n+1 ;

 else return 0 ;

}
//////////////////////////////////////////////////////////////////////////////////////////////

public static int gcd(int a, int b )
{

if(b==0)return a ;

else return gcd(b,a%b) ;

}

public static long gcd(long a, long b )
{

if(b==0)return a ;

else return gcd(b,a%b) ;

}

////////////////////////////////////////////////////////////////////////////////////

public static int lcm(int a, int b ,int c , int d )
{

int temp = lcm(a,b , c) ;

 int ans = lcm(temp ,d ) ;

return ans  ;

}

///////////////////////////////////////////////////////////////////////////////////////////

public static int lcm(int a, int b ,int c )
{

int temp = lcm(a,b) ;

int ans =  lcm(temp ,c) ;

return ans  ;

}

////////////////////////////////////////////////////////////////////////////////////////

public static int lcm(int a , int b )
{

int gc = gcd(a,b);

return (a/gc)*b ;
}

public static long lcm(long a , long b )
{

long gc = gcd(a,b);

return (a/gc)*b;
}

///////////////////////////////////////////////////////////////////////////////////////////
static boolean isPrime(long n)
{
      if(n==1)
      {
            return false  ;
      }

      boolean ans =  true  ;

      for(long i = 2L; i*i <= n ;i++)
      {
            if(n% i ==0)
            {
                  ans = false  ;break ;
            }
      }

      return ans  ;
}

static boolean isPrime(int n)
{
      if(n==1)
      {
            return false  ;
      }

      boolean ans =  true  ;

      for(int i = 2; i*i <= n ;i++)
      {
            if(n% i ==0)
            {
                  ans = false  ;break ;
            }
      }

      return ans  ;
}

///////////////////////////////////////////////////////////////////////////

static int sieve =  1000000 ;

static boolean[] prime =  new boolean[sieve + 1] ;

public static void sieveOfEratosthenes()
    {
        // FALSE == prime

        // TRUE ==  COMPOSITE

        // FALSE== 1

        // time complexity = 0(NlogLogN)== o(N)

        // gives prime nos bw 1 to N

        for(int i = 4; i<= sieve ; i++)
        {
            prime[i] = true  ;
            i++ ;
        }

        for(int p = 3; p*p <= sieve; p++)
        {

            if(prime[p] == false)
            {

                for(int i = p*p; i <= sieve; i += p)
                    prime[i] = true;
            }

            p++ ;
        }

    }

///////////////////////////////////////////////////////////////////////////////////

public static void sortD(int[] arr , int s  , int e)
{
      sort(arr ,s , e) ;

      int i =s ; int j = e  ;

      while( i < j)
      {
            int temp = arr[i] ;
            arr[i] =arr[j] ;
            arr[j] = temp ;
            i++ ; j-- ;
      }

      return ;
}

/////////////////////////////////////////////////////////////////////////////////////////

public static long countSubarraysSumToK(long[] arr ,long sum )
    {
      HashMap<Long,Long> map = new HashMap<>() ;

      int n = arr.length ;

      long prefixsum = 0 ;

      long count = 0L ;
      for(int i  = 0; i < n ; i++)
      {
          prefixsum  = prefixsum +  arr[i] ;

          if(sum == prefixsum)count = count+1 ;

          if(map.containsKey(prefixsum -sum))
          {
              count = count + map.get(prefixsum -sum) ;
          }

          if(map.containsKey(prefixsum ))
          {
              map.put(prefixsum , map.get(prefixsum) +1 );
          }

          else{
              map.put(prefixsum , 1L );
          }

      }

      return count  ;

    }

///////////////////////////////////////////////////////////////////////////////////////////////

// KMP ALGORITHM : TIME COMPL:O(N+M)
// FINDS THE OCCURENCES OF PATTERN AS A  SUBSTRING IN STRING
//RETURN THE ARRAYLIST OF INDEXES
// IF SIZE OF LIST IS ZERO MEANS PATTERN IS NOT PRESENT IN STRING

public static ArrayList<Integer> kmpAlgorithm(String str , String pat)
     {
        ArrayList<Integer> list =new ArrayList<>();

        int n = str.length() ;
        int m = pat.length() ;

        String q = pat + "#" + str ;

        int[] lps  =new int[n+m+1] ;

         longestPefixSuffix(lps, q,(n+m+1)) ;

         for(int i =m+1 ; i < (n+m+1) ; i++ )
         {
             if(lps[i] == m)
             {
                 list.add(i-2*m) ;
             }
         }

        return list ;

    }

public static void longestPefixSuffix(int[] lps ,String str , int n)
    {
        lps[0] =  0 ;

        for(int i = 1  ; i<= n-1; i++)
        {
          int l = lps[i-1] ;

          while( l > 0 && str.charAt(i) != str.charAt(l))
          {
              l = lps[l-1] ;
          }

          if(str.charAt(i) == str.charAt(l))
          {
              l++ ;
          }

          lps[i] = l ;
        }

    }

///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////

 // CALCULATE TOTIENT Fn FOR ALL VALUES FROM 1 TO n
    // TOTIENT(N) = count of nos less than n and grater than 1 whose gcd with n is 1
    // or n and the no  will be coprime in nature
    //time : O(n*(log(logn)))

    public static void eulerTotientFunction(int[] arr ,int n )
    {

      for(int i = 1; i <= n  ;i++)arr[i] =i  ;

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

              for(int j =2*i ; j<= n  ; j+= i )
              {
                  arr[j] = (arr[j]*(i-1))/i ;
              }

          }
      }

      return  ;

    }

/////////////////////////////////////////////////////////////////////////////////////////////
public static long nCr(int n,int k)
{
    long ans=1L;
    k=k>n-k?n-k:k;
    int j=1;
    for(;j<=k;j++,n--)
    {
        if(n%j==0)
        {
            ans*=n/j;
        }else
        if(ans%j==0)
        {
            ans=ans/j*n;
        }else
        {
            ans=(ans*n)/j;
        }
    }
    return ans;
}

///////////////////////////////////////////////////////////////////////////////////////////

public static ArrayList<Integer> allFactors(int n)
{
      ArrayList<Integer> list = new ArrayList<>() ;

    for(int i = 1; i*i <= n ;i++)
    {
          if( n % i == 0)
          {
              if(i*i == n)
              {
                    list.add(i) ;
              }
              else{
                    list.add(i) ;
                    list.add(n/i) ;

              }
          }
    }

     return list ;

}

public static ArrayList<Long> allFactors(long n)
{
      ArrayList<Long> list = new ArrayList<>() ;

    for(long i = 1L; i*i <= n ;i++)
    {
          if( n % i == 0)
          {
              if(i*i == n)
              {
                    list.add(i) ;
              }
              else{
                    list.add(i) ;
                    list.add(n/i) ;

              }
          }
    }

     return list ;

}
////////////////////////////////////////////////////////////////////////////////////////////////////

  static final int MAXN = 1000001;

    static int spf[] = new int[MAXN];

    static void sieve()
    {
        spf[1] = 1;
        for (int i=2; i<MAXN; i++)

            spf[i] = i;

        for (int i=4; i<MAXN; i+=2)
            spf[i] = 2;

        for (int i=3; i*i<MAXN; i++)
        {

            if (spf[i] == i)
            {

                for (int j=i*i; j<MAXN; j+=i)

                    if (spf[j]==j)
                        spf[j] = i;
            }
        }
    }

    static ArrayList<Integer> getPrimeFactorization(int x)
    {
        ArrayList<Integer> ret = new ArrayList<Integer>();
        while (x != 1)
        {
            ret.add(spf[x]);
            x = x / spf[x];
        }
        return ret;
    }

 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////

public static void merge(int arr[], int l, int m, int r)
    {
        // Find sizes of two subarrays to be merged
        int n1 = m - l + 1;
        int n2 = r - m;

        /* Create temp arrays */
        int L[] = new int[n1];
        int R[] = new int[n2];

       //Copy data to temp arrays
        for (int i=0; i<n1; ++i)
            L[i] = arr[l + i];
        for (int j=0; j<n2; ++j)
            R[j] = arr[m + 1+ j];

        /* Merge the temp arrays */

        // Initial indexes of first and second subarrays
        int i = 0, j = 0;

        // Initial index of merged subarry array
        int k = l;
        while (i < n1 && j < n2)
        {
            if (L[i] <= R[j])
            {
                arr[k] = L[i];
                i++;
            }
            else
            {
                arr[k] = R[j];
                j++;
            }
            k++;
        }

        /* Copy remaining elements of L[] if any */
        while (i < n1)
        {
            arr[k] = L[i];
            i++;
            k++;
        }

        /* Copy remaining elements of R[] if any */
        while (j < n2)
        {
            arr[k] = R[j];
            j++;
            k++;
        }
    }

    // Main function that sorts arr[l..r] using
    // merge()
  public static void sort(int arr[], int l, int r)
    {
        if (l < r)
        {
            // Find the middle point
            int m = (l+r)/2;

            // Sort first and second halves
            sort(arr, l, m);
            sort(arr , m+1, r);

            // Merge the sorted halves
            merge(arr, l, m, r);
        }
    }

public static void sort(long arr[], int l, int r)
    {
        if (l < r)
        {
            // Find the middle point
            int m = (l+r)/2;

            // Sort first and second halves
            sort(arr, l, m);
            sort(arr , m+1, r);

            // Merge the sorted halves
            merge(arr, l, m, r);
        }
    }

public static void merge(long arr[], int l, int m, int r)
    {
        // Find sizes of two subarrays to be merged
        int n1 = m - l + 1;
        int n2 = r - m;

        /* Create temp arrays */
        long L[] = new long[n1];
        long R[] = new long[n2];

        //Copy data to temp arrays
        for (int i=0; i<n1; ++i)
            L[i] = arr[l + i];
        for (int j=0; j<n2; ++j)
            R[j] = arr[m + 1+ j];

        /* Merge the temp arrays */

        // Initial indexes of first and second subarrays
        int i = 0, j = 0;

        // Initial index of merged subarry array
        int k = l;
        while (i < n1 && j < n2)
        {
            if (L[i] <= R[j])
            {
                arr[k] = L[i];
                i++;
            }
            else
            {
                arr[k] = R[j];
                j++;
            }
            k++;
        }

        /* Copy remaining elements of L[] if any */
        while (i < n1)
        {
            arr[k] = L[i];
            i++;
            k++;
        }

        /* Copy remaining elements of R[] if any */
        while (j < n2)
        {
            arr[k] = R[j];
            j++;
            k++;
        }
    }

 /////////////////////////////////////////////////////////////////////////////////////////

	public static long knapsack(int[] weight,long value[],int maxWeight){

        int n=  value.length ;

	//dp[i] stores the profit with KnapSack capacity "i"
  long []dp = new long[maxWeight+1];

    //initially profit with 0 to W KnapSack capacity is 0
    Arrays.fill(dp, 0);

    // iterate through all items
    for(int i=0; i < n; i++)

        //traverse dp array from right to left
        for(int j = maxWeight; j >= weight[i]; j--)
            dp[j] = Math.max(dp[j] , value[i] + dp[j - weight[i]]);

    /*above line finds out maximum of dp[j](excluding ith element value)
    and val[i] + dp[j-wt[i]] (including ith element value and the
    profit with "KnapSack capacity - ith element weight") */
    return dp[maxWeight];
	}

///////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////

// to return max sum of any subarray in given array
public static long kadanesAlgorithm(long[] arr)
{

    if(arr.length == 0)return  0 ;

      long[] dp = new long[arr.length] ;

      dp[0] = arr[0] ;
      long max =  dp[0] ;

      for(int i = 1; i <  arr.length ; i++)
      {
            if(dp[i-1] > 0)
            {
                  dp[i] = dp[i-1] + arr[i] ;
            }
            else{
                  dp[i] = arr[i] ;
            }

            if(dp[i] >  max)max = dp[i] ;

      }

      return max  ;

}
/////////////////////////////////////////////////////////////////////////////////////////////
public static long kadanesAlgorithm(int[] arr)
{
     if(arr.length == 0)return  0 ;

      long[] dp = new long[arr.length] ;

      dp[0] = arr[0] ;
      long max =  dp[0] ;

      for(int i = 1; i <  arr.length ; i++)
      {
            if(dp[i-1] > 0)
            {
                  dp[i] = dp[i-1] + arr[i] ;
            }
            else{
                  dp[i] = arr[i] ;
            }

            if(dp[i] >  max)max = dp[i] ;

      }

      return max  ;

}

///////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////

//TO GENERATE ALL(DUPLICATE ALSO EXIST) PERMUTATIONS OF A STRING

// JUST CALL generatePermutation( str,  start,  end) start :inclusive ,end : exclusive

//Function for swapping the characters at position I with character at position j
    public static String swapString(String a, int i, int j) {
        char[] b =a.toCharArray();
        char ch;
        ch = b[i];
        b[i] = b[j];
        b[j] = ch;
        return String.valueOf(b);
    }

//Function for generating different permutations of the string
    public static void generatePermutation(String str, int start, int end)
    {
        //Prints the permutations
        if (start == end-1)
            System.out.println(str);
        else
        {
            for (int i = start; i < end; i++)
            {
                //Swapping the string by fixing a character
                str = swapString(str,start,i);
                //Recursively calling function generatePermutation() for rest of the characters
                generatePermutation(str,start+1,end);
                //Backtracking and swapping the characters again.
                str = swapString(str,start,i);
            }
        }
    }

////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////

public static long factMod(long n, long mod) {
    if (n <= 1) return 1;
    long ans = 1;
    for (int i = 1; i <= n; i++) {
      ans = (ans * i) % mod;
    }
    return ans;
  }

/////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////

public static long power(int a  ,int b)
    {
        //time comp : o(logn)

        long x = (long)(a) ;
         long n = (long)(b) ;

        if(n==0)return 1 ;
        if(n==1)return x;

        long ans =1L  ;

      while(n>0)
      {
          if(n % 2 ==1)
          {
              ans = ans *x ;
          }

          n = n/2L ;

          x =  x*x ;

      }

      return ans ;
    }

    public static long power(long a  ,long b)
    {
        //time comp : o(logn)

        long x = (a) ;
         long n = (b) ;

        if(n==0)return 1L ;
        if(n==1)return x;

        long ans =1L  ;

      while(n>0)
      {
          if(n % 2 ==1)
          {
              ans = ans *x ;
          }

          n = n/2L ;

          x =  x*x ;

      }

      return ans ;
    }

////////////////////////////////////////////////////////////////////////////////////////////////////
public static long powerMod(long x, long n, long mod) {
    //time comp : o(logn)

    if(n==0)return 1L ;
        if(n==1)return x;

    long ans = 1;
    while (n > 0) {
      if (n % 2 == 1) ans = (ans * x) % mod;
      x = (x * x) % mod;
      n /= 2;
    }
    return ans;
  }

//////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////

/*
lowerBound - finds largest element equal or less than value paased
upperBound - finds smallest element equal or more than value passed

if not present return -1;

*/

public static long lowerBound(long[] arr,long k)
	{
		long ans=-1;

		int start=0;
		int end=arr.length-1;

		while(start<=end)
		{
			int mid=(start+end)/2;

			if(arr[mid]<=k)
			{
				ans=arr[mid];
				start=mid+1;
			}
			else
			{
				end=mid-1;
			}

		}

		return ans;

	}

	public static int lowerBound(int[] arr,int k)
	{
		int ans=-1;

		int start=0;
		int end=arr.length-1;

		while(start<=end)
		{
			int mid=(start+end)/2;

			if(arr[mid]<=k)
			{
				ans=arr[mid];
				start=mid+1;
			}
			else
			{
				end=mid-1;
			}

		}

		return ans;

	}

	public static long upperBound(long[] arr,long k)
	{
		long ans=-1;

		int start=0;
		int end=arr.length-1;

		while(start<=end)
		{
			int mid=(start+end)/2;

			if(arr[mid]>=k)
			{
				ans=arr[mid];
				end=mid-1;
			}
			else
			{
				start=mid+1;
			}

		}

		return ans;
	}

	public static int upperBound(int[] arr,int k)
	{
		int ans=-1;

		int start=0;
		int end=arr.length-1;

		while(start<=end)
		{
			int mid=(start+end)/2;

			if(arr[mid]>=k)
			{
				ans=arr[mid];
				end=mid-1;
			}
			else
			{
				start=mid+1;
			}

		}

		return ans;
	}

//////////////////////////////////////////////////////////////////////////////////////////

public static void printArray(int[] arr , int si ,int ei)
{
    for(int i = si  ; i  <= ei ; i++)
    {
        out.print(arr[i] +" ") ;
    }

}

public static void printArrayln(int[] arr , int si ,int ei)
{
    for(int i = si  ; i  <= ei ; i++)
    {
        out.print(arr[i] +" ") ;
    }
    out.println() ;
}

public static void printLArray(long[] arr , int si , int ei)
{
    for(int i = si ; i  <= ei ; i++)
    {
        out.print(arr[i] +" ") ;
    }

}

public static void printLArrayln(long[] arr , int si , int ei)
{
    for(int i = si ; i  <= ei ; i++)
    {
        out.print(arr[i] +" ") ;
    }
    out.println() ;

}

public static void printtwodArray(int[][] ans)
{
    for(int i = 0; i< ans.length ; i++)
    {
        for(int j  = 0 ; j <  ans[0].length ; j++)out.print(ans[i][j] +" ");
        out.println() ;
    }
    out.println() ;

}

   static long modPow(long a, long x, long p) {
    //calculates a^x mod p in logarithmic time.

    a = a % p ;

    if(a == 0)return 0L ;

    long res = 1L;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x =x/2;
    }
    return res;
}

  static long modInverse(long a, long p) {
    //calculates the modular multiplicative of a mod p.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}

 static long[] factorial =  new long[1000001] ;

 static void modfac(long mod)
 {
     factorial[0]=1L ; factorial[1]=1L ;

     for(int i = 2; i<= 1000000 ;i++)
     {
         factorial[i] = factorial[i-1] *(long)(i) ;
          factorial[i] = factorial[i] % mod ;
     }

 }

static long modBinomial(long n, long r, long p) {
// calculates C(n,r) mod p (assuming p is prime).

  if(n < r) return 0L ;

    long num = factorial[(int)(n)] ;

    long den = (factorial[(int)(r)]*factorial[(int)(n-r)]) %  p ;

    long ans  = num*(modInverse(den,p)) ;

    ans = ans % p ;

    return ans  ;

}

 static void update(int val , long[] bit ,int n)
 {
     for( ; val <= n ; val += (val &(-val)) )
     {
         bit[val]++ ;
     }

 }

 static long query(int val , long[] bit , int n)
 {
     long ans = 0L;
     for( ; val >=1 ; val-=(val&(-val))  )ans += bit[val];

     return ans ;
 }

static int countSetBits(long n)
    {
        int count = 0;
        while (n > 0) {
            n = (n) & (n - 1L);
            count++;
        }
        return count;
    }

static int abs(int x)
{
    if(x < 0)x = -1*x ;

    return x ;
}

static long abs(long x)
{
    if(x < 0)x = -1L*x ;

    return x ;

}

////////////////////////////////////////////////////////////////////////////////////////////////
static void p(int val)
{
    out.print(val) ;
}

static void p()
{
    out.print(" ") ;
}

static void pln(int val)
{
    out.println(val) ;
}

static void pln()
{
    out.println() ;
}

static void p(long val)
{
    out.print(val) ;
}

static void pln(long val)
{
    out.println(val) ;
}

////////////////////////////////////////////////////////////////////////////////////////////

 // calculate total no of nos greater than or equal to key in  sorted array arr

static  int bs(int[] arr, int s ,int e  ,int key)
{
    if( s> e)return 0 ;

     int mid = (s+e)/2 ;

        if(arr[mid] <key)
        {
            return bs(arr ,mid+1,e , key) ;

        }

        else{

             return bs(arr ,s ,mid-1, key)  + e-mid+1;

        }
}

// static ArrayList<Integer>[] adj ;
// static int mod= 1000000007 ;

//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////

public static void solve()
{
FastReader scn = new FastReader() ;

//Scanner scn = new Scanner(System.in);
//int[] store = {2 ,3, 5 , 7  ,11 , 13 , 17 , 19 , 23 , 29 , 31 , 37 } ;

// product of first 11 prime nos is greater than 10 ^ 12;
//sieve() ;
//ArrayList<Integer> arr[] = new ArrayList[n] ;
ArrayList<Integer> list = new ArrayList<>() ;
ArrayList<Long> lista = new ArrayList<>() ;
ArrayList<Long> listb = new ArrayList<>() ;
// ArrayList<Integer> lista = new ArrayList<>() ;
// ArrayList<Integer> listb = new ArrayList<>() ;
//ArrayList<String> lists = new ArrayList<>() ;

HashMap<Integer,ArrayList<Pair>> map = new HashMap<>() ;
//HashMap<Long,Long> map = new HashMap<>() ;
HashMap<Integer,Integer> mapx  = new HashMap<>() ;
HashMap<Integer,Integer> mapy  = new HashMap<>() ;
//HashMap<String,Integer> maps = new HashMap<>() ;
//HashMap<Integer,Boolean> mapb = new HashMap<>() ;
//HashMap<Point,Integer> point = new HashMap<>() ;

 Set<Integer> set = new HashSet<>() ;
 Set<Integer> setx = new HashSet<>() ;
 Set<Integer> sety = new HashSet<>() ;

StringBuilder sb =new StringBuilder("") ;

//Collections.sort(list);

//if(map.containsKey(arr[i]))map.put(arr[i] , map.get(arr[i]) +1 ) ;
//else map.put(arr[i],1) ;

// if(map.containsKey(temp))map.put(temp , map.get(temp) +1 ) ;
// else map.put(temp,1) ;

//int bit  =Integer.bitCount(n);
// gives total no of set bits in n;

// Arrays.sort(arr, new Comparator<Pair>() {
// 			@Override
// 			public int compare(Pair a, Pair b) {
// 				if (a.first != b.first) {
// 					return a.first - b.first; // for increasing order of first
// 				}
// 				return a.second - b.second ; //if first is same then sort on second basis
// 			}
// 		});

int testcase = 1;
 //testcase = scn.nextInt() ;
for(int testcases =1  ; testcases <= testcase ;testcases++)
{

 //if(map.containsKey(arr[i]))map.put(arr[i],map.get(arr[i])+1) ;else map.put(arr[i],1) ;
 //if(map.containsKey(temp))map.put(temp,map.get(temp)+1) ;else map.put(temp,1) ;

 //adj = new ArrayList[n] ;

// for(int i = 0; i< n; i++)
// {
//     adj[i] = new ArrayList<Integer>();
// }

// long n = scn.nextLong() ;
//String s = scn.next() ;

int n= scn.nextInt() ;
int[] arr= new int[n] ;

for(int i=0; i < n;i++)
{
    arr[i]= scn.nextInt();
}

for(int r= 0 ; r < n ;r++)
{
    int sum = 0 ;
    for(int l =r ;l>= 0 ;l--)
    {
       sum = sum + arr[l] ;

       if(map.containsKey(sum))
       {
           map.get(sum).add(new Pair(l,r)) ;
       }
       else{

           map.put(sum,new ArrayList<Pair>());
            map.get(sum).add(new Pair(l,r)) ;
       }
    }
}

 ArrayList<Pair> ans = null ;

 int bestcount = 0 ;

for(int x : map.keySet())
{

    ArrayList<Pair> curr = map.get(x) ;
    ArrayList<Pair> now = new ArrayList<Pair>() ;

    int r=-1  ;

    int count = 0 ;

    for(Pair seg : curr)
    {

      if(seg.first > r)
      {
          count++ ;
          now.add(seg) ;
          r= seg.second  ;
      }

    }

    if(count > bestcount)
    {
        ans = now ;
        bestcount = count  ;
    }

}

pln(bestcount) ;

if(bestcount >0)
{
for(Pair x :  ans)
{
    out.println((x.first+1) +" " +( x.second+1)) ;
}
}

//out.println(ans) ;
//out.println(ans+" "+in) ;

//out.println("Case #" + testcases + ": "  + ans ) ;
//out.println("@") ;
set.clear() ;
sb.delete(0 , sb.length()) ;
list.clear() ;lista.clear() ;listb.clear() ;
map.clear() ;
mapx.clear() ;
mapy.clear() ;
setx.clear() ;sety.clear() ;

} // test case  end loop

out.flush() ;
} // solve fn ends

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

solve() ;

}

}

 class Pair
{
  int first ;

int second  ;

   public Pair(int l , int r)
   {
       first = l ;second = r ;
   }

@Override
	public String toString() {

	String ans = "" ;
	ans  += this.first ;
	ans += " ";
	ans += this.second ;

	return ans  ;
	}

}


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();
        }

    }
}


import static java.lang.Integer.compare;
import static java.util.Comparator.comparingInt;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

public class SameSumBlocks {

    public static void main(String[] args) {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        String[] numbersAsString = input.lines()
                                        .skip(1)
                                        .findFirst()
                                        .get()
                                        .split(" ");
        int[] numbers = Arrays.stream(numbersAsString).mapToInt(Integer::parseInt).toArray();
        List<PairOfInt> sameSumBlocks = findSameSumBlocks(numbers);
        System.out.println(sameSumBlocks.size());
        sameSumBlocks.forEach(System.out::println);
    }

    static List<PairOfInt> findSameSumBlocks(int[] numbers) {

        List<List<PairOfInt>> potentials = buildPotentialsSum(numbers);

        List<List<PairOfInt>> sortedPairList = potentials.stream()
                                                         .filter(p -> p.size() > 0)
                                                         .sorted((l1, l2) -> compare(l2.size(), l1.size()))
                                                         .collect(Collectors.toList());

        List<PairOfInt> max = new ArrayList<>();
        max.add(PairOfInt.of(1, 1));
        for (int i = 0; i < sortedPairList.size(); i++) {
            List<PairOfInt> result = sortedPairList.get(i);
            result.sort(comparingInt(p -> p.b));
            List<PairOfInt> maxDisjoint = maxDisjointPair(result);
            if (maxDisjoint.size() > max.size()) {
                max = maxDisjoint;
                if (i + 1 < sortedPairList.size() && maxDisjoint.size() >= sortedPairList.get(i + 1).size()) {
                    return maxDisjoint;
                }
            }
        }

        return max;
    }

    public static List<PairOfInt> maxDisjointPair(List<PairOfInt> result) {
        if (result.size() == 0)
            return result;

        boolean over = false;
        while (!over) {
            int i;
            for (i = 1; i < result.size(); i++) {
                if (result.get(i).a <= result.get(i - 1).b) {
                    result.remove(result.get(i));
                    break;
                }
            }
            if (i == result.size()) {
                over = true;
            }
        }
        return result;
    }

    private static List<List<PairOfInt>> buildPotentialsSum(int[] numbers) {
        Map<Integer, List<PairOfInt>> result = new HashMap<>();
        for (int i = 0; i < numbers.length; i++) {
            int blockSum = 0;
            for (int j = i; j < numbers.length; j++) {
                blockSum += numbers[j];
                final int tmpi = i, tmpj = j;
                result.compute(blockSum, (k, l) -> {
                    if (l == null) {
                        l = new ArrayList<>();
                    }
                    l.add(PairOfInt.of(tmpi + 1, tmpj + 1));
                    return l;
                });
                if(blockSum == 0) {
                    break;
                }
            }
        }
        return new ArrayList<>(result.values());
    }

    public static class PairOfInt {
        final int a, b;

        public static PairOfInt of(int a, int b) {
            return new PairOfInt(a, b);
        }

        private PairOfInt(int a, int b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public String toString() {
            return a + " " + b;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            PairOfInt pairOfInt = (PairOfInt) o;
            return a == pairOfInt.a &&
                    b == pairOfInt.b;
        }

        @Override
        public int hashCode() {
            return Objects.hash(a, b);
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

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

    static class F2SameSumBlocksHard {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.nextInt();

            long[] a = in.nextLongArray(n);

            long[] p = in.calculatePrefixSum(a);

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

            for (int i = 0; i < n; i++) {
                long sum = 0;
                for (int j = i; j < n; j++) {
                    sum += a[j];
                    map.merge(sum, 1, (x, y) -> x + y);
                }
            }

            List<sum> sums = new ArrayList<>();
            for (long sum : map.keySet()) {
                sums.add(new sum(sum, map.get(sum)));
            }

            sums.sort((x, y) -> y.c - x.c);

            int ans = -1;

            int[] fca = null;
            long mxsum = -1;
            for (int i = 0; i < sums.size(); i++) {
                sum cs = sums.get(i);
                long sum = cs.sum;
                long c = cs.c;

                if (c < ans) {
                    continue;
                }

                Map<Long, Integer> lm = new HashMap<>();

                int[] ca = new int[n];
                lm.put(0l, -1);
                for (int j = 0; j < n; j++) {
                    long val = p[j];

                    if (j > 0) {
                        ca[j] = ca[j - 1];
                    }
                    long req = val - sum;

                    if (lm.containsKey(req)) {
                        int li = lm.get(req);
                        if (li == -1)
                            ca[j] = Math.max(1, ca[j]);
                        else
                            ca[j] = Math.max(1 + ca[li], ca[j]);
                    }

                    lm.put(val, j);
                }

                if (ca[n - 1] > ans) {
                    ans = ca[n - 1];
                    mxsum = sum;
                    fca = ca;
                }
            }

            List<Integer> al = new ArrayList<>();

            long sum = 0;
            for (int i = n - 1; i >= 0; i--) {
                if (i > 0 && fca[i] != fca[i - 1]) {
                    sum = 0;
                    al.add(i + 1);
                    do {
                        sum += a[i];
                        i--;
                    } while (i >= 0 && sum != mxsum);
                    i++;
                    al.add(i + 1);
                } else if (i == 0) {
                    if (a[i] == mxsum) {
                        al.add(i + 1);
                        al.add(i + 1);
                    }
                }
            }

            out.println(al.size() / 2);

            for (int i = al.size() - 1; i >= 0; i -= 2) {
                out.println(al.get(i) + " " + al.get(i - 1));
            }
        }

        class sum {
            long sum;
            int c;

            public sum(long sum, int c) {
                this.sum = sum;
                this.c = c;
            }

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public long[] nextLongArray(int n) {
            long[] array = new long[n];
            for (int i = 0; i < n; ++i) array[i] = nextLong();
            return array;
        }

        public long[] calculatePrefixSum(long[] a) {
            int n = a.length;

            long[] prefixSum = new long[n];

            prefixSum[0] = a[0];

            for (int i = 1; i < n; i++) {
                prefixSum[i] = prefixSum[i - 1] + a[i];
            }

            return prefixSum;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void println(Object... objects) {
            print(objects);
            writer.println();
        }

        public void close() {
            writer.close();
        }

        public void println(int i) {
            writer.println(i);
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.Set;
import java.util.HashMap;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.util.Map;
import java.util.Map.Entry;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * 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;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskF solver = new TaskF();
        solver.solve(1, in, out);
        out.close();
    }

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

            Map<Integer, List<Range>> rgs = new HashMap<Integer, List<Range>>();

            for (int i = 0; i < n; i++) {
                int s = 0;
                for (int j = i; j < n; j++) {
                    s += a[j];

                    if (rgs.get(s) == null) {  rgs.put(s, new ArrayList<Range>()); }

                    rgs.get(s).add(new Range(i, j));
                }
            }

            Iterator it = rgs.entrySet().iterator();
            List<Range> ans = new ArrayList<Range>();

            while (it.hasNext()) {
                Map.Entry pair = (Map.Entry) it.next();
                int sum = (int) pair.getKey();
                List<Range> ranges = rgs.get(sum);

                List<Range> cand = new ArrayList<Range>();

                for (Range r : ranges) {
                    if (cand.size() == 0) {
                        cand.add(r);
                        continue;
                    }

                    if (cand.get(cand.size() - 1).j < r.i) {
                        cand.add(r);
                    } else {
                        if (cand.get(cand.size() - 1).j > r.j) {
                            cand.remove(cand.size() - 1);
                            cand.add(r);
                        }
                    }
                }

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

            out.println(ans.size());
            for (Range r : ans) {
                out.println((r.i + 1) + " " + (r.j + 1));
            }
        }

        public class Range implements Comparable {
            public int i;
            public int j;

            public Range(int i, int j) {
                this.i = i;
                this.j = j;
            }

            public int compareTo(Object o) {
                Range t = (Range) o;
                if (this.i == t.i) {
                    if (this.j < t.j) return 1;
                    else return 0;
                }
                if (this.i < t.i) return 1;
                return 0;
            }
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}


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);
        }

    }

}


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.util.List;

public class Q6 {

    public static void main(String[] args) {
        InputReader s = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int t = 1;
//        t = s.nextInt();
        nexttest:
        while (t-- > 0) {
            int n = s.nextInt();
            int a[] = s.nextIntArray(n);

            HashMap<Integer, List<Pair>> sets = new HashMap<>();
            int pre[] = new int[n + 1];
            for (int i = 1; i <= n; i++) {
                pre[i] = a[i - 1] + pre[i - 1];
            }

            for (int i = 1; i <= n; i++) {
                for (int j = i; j <= n; j++) {
                    final Integer key = pre[j] - pre[i - 1];
                    if (!sets.containsKey(key)) {
                        sets.put(key, new ArrayList<>());
                    }

                    sets.get(key).add(new Pair(i, j));
                }
            }
//            System.out.println(sets);
            int ans = 0;
            List<Pair> answer = new ArrayList<>();
            int[] ansNextPos = new int[1];
            boolean[] ansTaken = new boolean[1];
            for (List<Pair> intervals : sets.values()) {

                Collections.sort(intervals);
                int[] nextPos = new int[intervals.size()];
                boolean[] taken = new boolean[intervals.size()];

                int[] dp = new int[intervals.size()];
                dp[intervals.size() - 1] = 1;
                taken[intervals.size() - 1] = true;
                nextPos[intervals.size() - 1] = -1;

                for (int i = intervals.size() - 2; i >= 0; i--) {
                    dp[i] = dp[i + 1];
                    taken[i] = false;
                    nextPos[i] = i + 1;

                    int ll = i + 1;
                    int rr = intervals.size();

                    while (ll < rr) {
                        int mid = ll + rr;
                        mid /= 2;
                        if (intervals.get(mid).x > intervals.get(i).y) {
                            rr = mid;
                        } else {
                            ll = mid + 1;
                        }
                    }
                    if (ll < intervals.size()) {
                        if (dp[i] < 1 + dp[ll]) {
                            dp[i] = Math.max(dp[i], 1 + dp[ll]);
                            taken[i] = true;
                            nextPos[i] = ll;
                        }
                    }
                }

                if (dp[0] > ans) {
                    ans = dp[0];
                    answer = intervals;
                    ansNextPos = nextPos;
                    ansTaken = taken;
                }
            }

            out.println(ans);
            int cur = 0;
            while (cur != -1) {
                if (ansTaken[cur]) {
                    out.println(answer.get(cur));
                }
                cur = ansNextPos[cur];
            }
        }

        out.close();
    }

    static class Pair implements Comparable<Pair> {
        int x;
        int y;

        @Override
        public String toString() {
            return x + " " + y;
        }

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

        @Override
        public int compareTo(final Pair o) {
            return this.x - o.x;
        }
    }

    static class InputReader {

        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int snext() {
            if (snumChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= snumChars) {
                curChar = 0;
                try {
                    snumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (snumChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = snext();
            while (isSpaceChar(c)) {
                c = snext();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = snext();
            while (isSpaceChar(c)) {
                c = snext();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int[] nextIntArray(int n) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextInt();
            }
            return a;
        }

        public String readString() {
            int c = snext();
            while (isSpaceChar(c)) {
                c = snext();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public String nextLine() {
            int c = snext();
            while (isSpaceChar(c)) {
                c = snext();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
}


// Don't place your source in a package
import java.lang.reflect.Array;
import java.text.DecimalFormat;
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
import java.util.stream.Stream;

// Please name your class Main
public class Main {
    static FastScanner fs=new FastScanner();
    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        public String next() {
            while (!st.hasMoreElements())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }
        int Int() {
            return Integer.parseInt(next());
        }

        long Long() {
            return Long.parseLong(next());
        }

        String Str(){
            return next();
        }
    }

    public static void main (String[] args) throws java.lang.Exception {
        PrintWriter out = new PrintWriter(System.out);

        int T=1;
        for(int t=0;t<T;t++){
            int n=Int();
            int A[]=new int[n];
            for(int i=0;i<n;i++){
                A[i]=Int();
            }

            Solution sol=new Solution();
            sol.solution(out,A);
        }
        out.flush();

    }

    public static int Int(){
        return fs.Int();
    }
    public static long Long(){
        return fs.Long();
    }
    public static String Str(){
        return fs.Str();
    }

}

class Solution{
    public void solution(PrintWriter out,int A[]){
        Map<Integer,List<int[]>>f=new HashMap<>();
        List<int[]>res=new ArrayList<>();
        for(int i=0;i<A.length;i++){
            int sum=0;
            for(int j=i;j<A.length;j++){
                sum+=A[j];
                if(!f.containsKey(sum))f.put(sum,new ArrayList<>());
                List<int[]>list=f.get(sum);
                list.add(new int[]{i,j});
            }
        }

        for(Integer key:f.keySet()){
            List<int[]>list=f.get(key);
            Collections.sort(list,(a,b)->{
                return a[1]-b[1];
            });
            int pre[]=new int[list.size()];
            Arrays.fill(pre,-1);

            int dp[][]=new int[list.size()][2];
            dp[0][0]=1;
            dp[0][1]=0;

            for(int i=1;i<list.size();i++){
                int pair[]=list.get(i);
                int l=0,r=i-1;
                int pos=-1;
                while(l<=r){
                    int mid=l+(r-l)/2;
                    if(list.get(mid)[1]<pair[0]){
                        pos=mid;
                        l=mid+1;
                    }
                    else{
                        r=mid-1;
                    }
                }

                if(pos!=-1){
                    int mx=1+dp[pos][0];
                    if(mx>=dp[i-1][0]){
                        dp[i][0]=mx;
                        dp[i][1]=i;
                        pre[i]=dp[pos][1];
                    }
                    else{
                        dp[i][0]=dp[i-1][0];
                        dp[i][1]=dp[i-1][1];
                    }
                }
                else{
                    dp[i][0]=dp[i-1][0];
                    dp[i][1]=dp[i-1][1];
                }
            }

            int n=list.size();
            if(dp[n-1][0]>res.size()){
                res=new ArrayList<>();
                int j=dp[n-1][1];
                while(j!=-1){
                    res.add(list.get(j));
                    j=pre[j];
                }
            }

        }

        out.println(res.size());
        for(int p[]:res){
            out.println((p[0]+1)+" "+(p[1]+1));
        }
    }

}

/*
                             ;\
                            |' \
         _                  ; : ;
        / `-.              /: : |
       |  ,-.`-.          ,': : |
       \  :  `. `.       ,'-. : |
        \ ;    ;  `-.__,'    `-.|
         \ ;   ;  :::  ,::'`:.  `.
          \ `-. :  `    :.    `.  \
           \   \    ,   ;   ,:    (\
            \   :., :.    ,'o)): ` `-.
           ,/,' ;' ,::"'`.`---'   `.  `-._
         ,/  :  ; '"      `;'          ,--`.
        ;/   :; ;             ,:'     (   ,:)
          ,.,:.    ; ,:.,  ,-._ `.     \""'/
          '::'     `:'`  ,'(  \`._____.-'"'
             ;,   ;  `.  `. `._`-.  \\
             ;:.  ;:       `-._`-.\  \`.
              '`:. :        |' `. `\  ) \
      -hrr-      ` ;:       |    `--\__,'
                   '`      ,'
                        ,-'

                      free bug dog
*/