import java.util.*;

public class problem11Asequence {

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

        int n = scan.nextInt();
        int d = scan.nextInt();
        int[] array = new int[n];

        for (int i = 0; i < n; i++) {
            array[i] = scan.nextInt();
        }
        scan.close();

        int i = 0;
        int k = 0;
        while (i<n-1) {
            if (array[i]>=array[i+1]) {
                k++;
                array[i+1]+=d;
            } else
                i++;
        }

        System.out.println(k);
    }

}


import java.util.Scanner;

public class IncreasingSequence {
	Scanner stream ;
	public IncreasingSequence(){
		stream = new Scanner (System.in);
		int n = stream.nextInt ();
		int d = stream.nextInt() ;
		int [] arr = new int [n];
		for (int i = 0 ; i <n ; i++){
			arr[i] = stream.nextInt () ;
		}
		sequance (arr , d);
	}
	public void sequance (int[] arr , int d){
		int count = 0 ;
		int num ;
		for (int i = 1 ; i < arr.length ; i++){
			if (arr[i] < arr[i-1]){
				num = arr[i-1] - arr[i] ;
				count += num/d + 1 ;
				arr[i] += (num/d + 1)*d ;
			}else if (arr[i] == arr [i-1]){
				arr[i] += d ;
				count ++ ;
			}
		}
		System.out.println(count);
	}
	public static void main (String [] args){
		new IncreasingSequence ();
	}
}


import java.util.Scanner;

public class IncreasingSequence {
	Scanner stream ;
	public IncreasingSequence(){
		stream = new Scanner (System.in);
		int n = stream.nextInt ();
		int d = stream.nextInt() ;
		int [] arr = new int [n];
		for (int i = 0 ; i <n ; i++){
			arr[i] = stream.nextInt () ;
		}
		sequance (arr , d);
	}
	public void sequance (int[] arr , int d){
		int count = 0 ;
		for (int i = 1 ; i < arr.length ; i++){
			while (arr[i] <= arr[i-1]){
				arr[i] += d;
				count++ ;
			}
		}
		System.out.println(count);
	}
	public static void main (String [] args){
		new IncreasingSequence ();
	}
}


import java.util.Scanner;

public class IncreasingSequence {
	Scanner stream ;
	public IncreasingSequence(){
		stream = new Scanner (System.in);
		int n = stream.nextInt ();
		int d = stream.nextInt() ;
		int [] arr = new int [n];
		for (int i = 0 ; i <n ; i++){
			arr[i] = stream.nextInt () ;
		}
		sequance (arr , d);
	}
	public void sequance (int[] arr , int d){
		int count = 0 ;
		int num ;
		for (int i = 1 ; i < arr.length ; i++){
			if (arr[i] < arr[i-1]){
				num = arr[i-1] - arr[i] ;
				if (num %d == 0){
					count += num/d ;
					arr[i] += num ;
				}else {
					count += num/d + 1 ;
					arr[i] += (num/d + 1)*d ;
				}
			}else if (arr[i] == arr [i-1]){
				arr[i] += d ;
				count ++ ;
			}
		}
		System.out.println(count);
	}
	public static void main (String [] args){
		new IncreasingSequence ();
	}
}


import static java.util.Arrays.*;
import java.util.*;

public class a {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int  n = sc.nextInt();
        int d = sc.nextInt();
        int[] nums = new int[n];
        int cnt=0;
        for(int i=0; i<n; ++i) {
            nums[i] = sc.nextInt();
            if(i!=0) {
                if(nums[i]<=nums[i-1]) {
                    while(true) {
                        nums[i]+=d;
                        cnt++;
                        if(nums[i]>nums[i-1]) break;
                    }
                }
            }
        }

        System.out.println(cnt);
    }
}


import java.util.*;
import java.io.*;

public class a {
	public static void main(String[] args) throws Exception {
		// Scanner sc = new Scanner(System.in);
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(in.readLine());
		int n = Integer.parseInt(st.nextToken());
		int d = Integer.parseInt(st.nextToken());
		st = new StringTokenizer(in.readLine());
		int[] nums = new int[n];
		int cnt = 0;
		for (int i = 0; i < n; ++i) {
			nums[i] = Integer.parseInt(st.nextToken());
			if(i==0) continue;

			if (nums[i - 1] >= nums[i]) {
				int k = (nums[i - 1] - nums[i]) / d + 1;
				cnt += k;
				nums[i] += k * d;
			}
		}

		System.out.println(cnt);
	}
}


import static java.util.Arrays.*;
import java.util.*;
import java.io.*;
public class a {

    public static void main(String[] args) throws Exception {
        // Scanner sc = new Scanner(System.in);
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(in.readLine());
        int  n = Integer.parseInt(st.nextToken());
        int d = Integer.parseInt(st.nextToken());
        st = new StringTokenizer(in.readLine());
        int[] nums = new int[n];
        int cnt=0;
        for(int i=0; i<n; ++i) {
            nums[i] = Integer.parseInt(st.nextToken());
            if(i!=0) {
                int mid = nums[i-1]-nums[i];
                if(mid>=0) {
                    if(mid<d) {
                        cnt++;
                        nums[i]+=d;
                    } else {
                        cnt+= mid/d+1;
                        nums[i]+= mid/d*d+d;
                    }
                }
            }
        }

        System.out.println(cnt);
    }
}


import static java.util.Arrays.*;
import java.util.*;
import java.io.*;
public class a {

    public static void main(String[] args) throws Exception {
        // Scanner sc = new Scanner(System.in);
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(in.readLine());
        int  n = Integer.parseInt(st.nextToken());
        int d = Integer.parseInt(st.nextToken());
        st = new StringTokenizer(in.readLine());
        int[] nums = new int[n];
        int cnt=0;
        for(int i=0; i<n; ++i) {
            nums[i] = Integer.parseInt(st.nextToken());
            if(i!=0) {
                int mid = nums[i-1]-nums[i];
                if(mid>=0) {
                    if(mid<d) {
                        cnt++;
                        nums[i]+=d;
                    } else {
                        cnt+= mid/d+1;
                        nums[i]+= mid/d*d+d;
                        System.out.println(nums[i]);
                        System.out.println("_______________________");
                    }
                }
            }
        }

        System.out.println(cnt);
    }
}


import static java.util.Arrays.*;
import java.util.*;
import java.io.*;
public class a {

    public static void main(String[] args) throws Exception {
        // Scanner sc = new Scanner(System.in);
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(in.readLine());
        int  n = Integer.parseInt(st.nextToken());
        int d = Integer.parseInt(st.nextToken());
        int[] nums = new int[n];
        int cnt=0;
        for(int i=0; i<n; ++i) {
            nums[i] = Integer.parseInt(st.nextToken());
            if(i!=0) {
                if(nums[i]<=nums[i-1]) {
                    while(true) {
                        nums[i]+=d;
                        cnt++;
                        if(nums[i]>nums[i-1]) break;
                    }
                }
            }
        }

        System.out.println(cnt);
    }
}


import java.util.*;
import java.io.*;
public class a {
	  public static void main(String[] args) throws Exception {
	        // Scanner sc = new Scanner(System.in);
	        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	        StringTokenizer st = new StringTokenizer(in.readLine());
	        int  n = Integer.parseInt(st.nextToken());
	        int d = Integer.parseInt(st.nextToken());
	        st = new StringTokenizer(in.readLine());
	        int[] nums = new int[n];
	        int cnt=0;
	        for(int i=1; i<n; ++i) {
	                if(nums[i-1]>=nums[i]) {
	                    int k = (nums[i-1]-nums[i])/d+1;
	                    cnt+=k;
	                    nums[i] += k*d;
	                }
	        }

	        System.out.println(cnt);
	    }
}


import static java.util.Arrays.*;
import java.util.*;
import java.io.*;
public class a {

    public static void main(String[] args) throws Exception {
        // Scanner sc = new Scanner(System.in);
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(in.readLine());
        int  n = Integer.parseInt(st.nextToken());
        int d = Integer.parseInt(st.nextToken());
        st = new StringTokenizer(in.readLine());
        int[] nums = new int[n];
        int cnt=0;
        for(int i=0; i<n; ++i) {
            nums[i] = Integer.parseInt(st.nextToken());
            if(i!=0) {
                if(nums[i]<=nums[i-1]) {
                    while(true) {
                        nums[i]+=d;
                        cnt++;
                        if(nums[i]>nums[i-1]) break;
                    }
                }
            }
        }

        System.out.println(cnt);
    }
}


import java.io.*;
import java.util.*;

public class sequence {
	static BufferedReader br;
	static StringTokenizer st;
	static PrintWriter out;
	public static void main(String[] args) throws IOException {
		InputStream input = System.in;
		//InputStream input = new FileInputStream("fileIn.in");
		OutputStream output = System.out;
		//OutputStream output = new FileOutputStream("fileOut.out");
		br = new BufferedReader(new InputStreamReader(input));
		out = new PrintWriter(output);
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken());
		int d = Integer.parseInt(st.nextToken());
		int[] nums = new int[n];
		st = new StringTokenizer(br.readLine());
		for (int i = 0; i < n; i++)
			nums[i] = Integer.parseInt(st.nextToken());
		int count = 0;
		for (int i = 1; i < n; i++)
			{
			while (nums[i-1] >= nums[i])
				{
				nums[i] += d;
				count++;
				}
			}
		out.println(count);
		out.close();
	}
}


import java.io.*;
import java.util.*;

public class sequence {
	static BufferedReader br;
	static StringTokenizer st;
	static PrintWriter out;
	public static void main(String[] args) throws IOException {
		InputStream input = System.in;
		//InputStream input = new FileInputStream("fileIn.in");
		OutputStream output = System.out;
		//OutputStream output = new FileOutputStream("fileOut.out");
		br = new BufferedReader(new InputStreamReader(input));
		out = new PrintWriter(output);
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken());
		int d = Integer.parseInt(st.nextToken());
		int[] nums = new int[n];
		st = new StringTokenizer(br.readLine());
		for (int i = 0; i < n; i++)
			nums[i] = Integer.parseInt(st.nextToken());
		int count = 0;
		int last = nums[0];
		for (int i = 1; i < n; i++)
			{
			if (last-nums[i] >= 0)
				{
				int add = (last-nums[i])/d+1;
				count += add;
				last = nums[i] + add*d;
				}
			else
				last = nums[i];
			}
		out.println(count);
		out.close();
	}
}


import java.io.*;
import java.util.*;

public class sequence {
	static BufferedReader br;
	static StringTokenizer st;
	static PrintWriter out;
	public static void main(String[] args) throws IOException {
		InputStream input = System.in;
		//InputStream input = new FileInputStream("fileIn.in");
		OutputStream output = System.out;
		//OutputStream output = new FileOutputStream("fileOut.out");
		br = new BufferedReader(new InputStreamReader(input));
		out = new PrintWriter(output);
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken());
		int d = Integer.parseInt(st.nextToken());
		int[] nums = new int[n];
		st = new StringTokenizer(br.readLine());
		for (int i = 0; i < n; i++)
			nums[i] = Integer.parseInt(st.nextToken());
		int count = 0;
		int last = nums[0];
		for (int i = 1; i < n; i++)
			{
			if (last-nums[i] >= 0)
				{
				int add = (last-nums[i])/d+1;
				count += add;
				last = last + add*d;
				}
			else
				last = nums[i];
			}
		out.println(count);
		out.close();
	}
}


import java.util.Scanner;

public class JavaApplication156 {
    public static void main(String[] args) {

        Scanner reader=new Scanner(System.in);
        int n=reader.nextInt();
        int k=reader.nextInt();

        int arr[]=new int[n];

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

        int cnt=0;

        for (int i = 0 ; i<(n-1);i++)
        {
            while (arr[i]>=arr[i+1])
            {
                int minus=arr[i+1]-arr[i];
                int div=minus/k;
                arr[i+1]+=div;
                cnt+=div;
            }
        }

        System.out.println(cnt);

    }}


import java.util.Scanner;

public class JavaApplication156 {
    public static void main(String[] args) {

        Scanner reader=new Scanner(System.in);
        int n=reader.nextInt();
        int k=reader.nextInt();

        int arr[]=new int[n];

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

        int cnt=0;

        for (int i = 0 ; i<(n-1);i++)
        {
               while (arr[i]>arr[i+1])
            {
                int minus=arr[i]-arr[i+1];
                double div=minus/(k*1.0);
                arr[i+1]+=(Math.ceil(div)*k);
                cnt+=Math.ceil(div);
            }
          if (arr[i]==arr[i+1])
            {

                arr[i+1]+=k;
                cnt+=1;
            }
        }

        System.out.println(cnt);

    }}


import java.util.ArrayList;
import java.util.Scanner;

public class JavaApplication156 {
    public static void main(String[] args) {

        Scanner reader=new Scanner(System.in);
        int n=reader.nextInt();
        int k=reader.nextInt();

        int arr[]=new int[n];

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

        int cnt=0;

        for (int i = 0 ; i<(n-1);i++)
        {
            while (arr[i]>=arr[i+1])
            {
                arr[i+1]+=k;
                cnt++;
            }
        }

        System.out.println(cnt);

    }}


/**
 * Author   : KillerCage
 * Language : Java
 * Time     : 2014 / 08
 * Quote    : E'la nostra ora incisa sull'anello
 */

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

public class Main {

	static InputStreamReader inp = new InputStreamReader( System.in );
	static BufferedReader buf = new BufferedReader( inp );
	static StreamTokenizer tok = new StreamTokenizer( buf );

	static OutputStreamWriter out = new OutputStreamWriter( System.out );
	static PrintWriter wri = new PrintWriter( out );

	static int nextInt() throws IOException {
		tok.nextToken(); return ( int ) tok.nval;
	}

	public static void main( String[] args ) throws IOException {
		int n = nextInt();
		int d = nextInt();
		int[] b = new int[n];
		for ( int i = 0; i < n; i ++ ) {
			b[i] = nextInt();
		}
		int ans = 0;
		for ( int i = 1; i < n; i ++ ) {
			if ( b[i] <= b[i - 1] ) {
				int c = ( b[i - 1] - b[i] ) / d + 1;
				ans += c;
				b[i] += d * c;
			}
		}
		wri.println( ans + "" );
		wri.flush();
	}
}


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);

        int x = scan.nextInt();
        int y = scan.nextInt();
        int[] n = new int[x];

        int suma = 0;

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

        for (int i = 1; i < n.length; i++) {
            if (n[i] <= n[i - 1]) {
                suma += ((n[i - 1] - n[i]) / y) + 1;
                n[i] += (((n[i - 1] - n[i]) / y) + 1) * y;
            }
        }

        System.out.println(suma);
    }
}


import java.util.Scanner;

public class Main{

    public static void main(String[] args){

        Scanner scan = new Scanner(System.in);

        int x = scan.nextInt();
        int y = scan.nextInt();
        int[] n = new int[x];

        int suma=0;

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

        for (int i = 0; i < x-1; i++) {
            while(n[i+1]<=n[i]){
                   n[i+1] = n[i+1]+y;
                   suma++;
            }
        }
        System.out.println(suma);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{

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

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

        String numeros[] = bufer.readLine().split("\\s+");
        String cadena[] = bufer.readLine().split("\\s+");

        int a,suma=0;

        for (int i = 0; i < Integer.parseInt(numeros[0])-1; i++) {
            while(Integer.parseInt(cadena[i+1])<=Integer.parseInt(cadena[i])){
                    a = Integer.parseInt(cadena[i+1])+Integer.parseInt(numeros[1]);
                    cadena[i+1]=String.valueOf(a);
                    suma++;
            }
        }

        System.out.println(suma);
    }
}


import java.util.Scanner;

public class Main{

    public static void main(String[] args){

        Scanner scan = new Scanner(System.in);

        int x = scan.nextInt();
        int y = scan.nextInt();
        int[] n = new int[x];

        int suma=0;

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

        for (int i = 0; i < x-1; i++) {
            if(n[i+1]<=n[i]){
                   n[i+1] = n[i+1]+y;
                   suma++;
                   i--;
            }
        }
        System.out.println(suma);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{

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

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

        String numeros[] = bufer.readLine().split("\\s+");
        String cadena[] = bufer.readLine().split("\\s+");

        int suma=0,b=Integer.parseInt(numeros[1]);

        for (int i = 0; i < Integer.parseInt(numeros[0])-1; i++) {
            if(Integer.parseInt(cadena[i+1])<=Integer.parseInt(cadena[i])){
                   cadena[i+1] = String.valueOf(Integer.parseInt(cadena[i+1])+b);
                    suma++;
                    i--;
            }
        }
        System.out.println(suma);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{

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

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

        String numeros[] = bufer.readLine().split("\\s+");
        String cadena[] = bufer.readLine().split("\\s+");

        int suma=0,b=Integer.parseInt(numeros[1]);

        for (int i = 0; i < Integer.parseInt(numeros[0])-1; i++) {
            while(Integer.parseInt(cadena[i+1])<=Integer.parseInt(cadena[i])){
                   cadena[i+1] = String.valueOf(Integer.parseInt(cadena[i+1])+b);
                    suma++;
            }
        }
        System.out.println(suma);
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Driver
{
    public static void main(String args[])
    {
        try
        {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            PrintWriter pw = new PrintWriter(System.out);

            String[] str = br.readLine().trim().split(" ");
            int n = Integer.parseInt(str[0]);
            int d = Integer.parseInt(str[1]);

            long[] arr = new long[n];

            String[] seq = br.readLine().trim().split(" ");
            for(int i = 0; i < n; i++){
                arr[i] = Long.parseLong(seq[i]);
            }

            long current = arr[0];
            long count = 0;
            for(int i = 1; i < arr.length; i++){
                if(arr[i] <= current){
                    long diff = current - arr[i];
                    if(diff <= d){
                        count++;
                        arr[i] += d;
                        if(arr[i] == current){
                            arr[i] += d;
                            count++;
                        }
                    } else {
                        long div = (long)Math.ceil((double)diff / d);
                        if(diff % d == 0){
                            div += 1;
                        }
                        count += div;
                        arr[i] += d * div;
                    }
                }

                current = arr[i];
            }

            pw.println(count);

            pw.close();
        }
        catch(Exception ex)
        {
            System.out.println("ERROR");
        }
    }

}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Driver
{
    public static void main(String args[])
    {
        try
        {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            PrintWriter pw = new PrintWriter(System.out);

            String[] str = br.readLine().trim().split(" ");
            int n = Integer.parseInt(str[0]);
            int d = Integer.parseInt(str[1]);

            long[] arr = new long[n];

            String[] seq = br.readLine().trim().split(" ");
            for(int i = 0; i < n; i++){
                arr[i] = Long.parseLong(seq[i]);
            }

            long current = arr[0];
            long count = 0;
            for(int i = 1; i < arr.length; i++){
                if(arr[i] <= current){
                    long diff = current - arr[i];
                    if(diff <= d){
                        count++;
                        arr[i] += d;
                    } else {
                        long div = (long)Math.ceil((double)diff / d);
                        if(diff % d == 0){
                            div += 1;
                        }
                        count += div;
                        arr[i] += d * div;
                    }
                }

                current = arr[i];
            }

            pw.println(count);

            pw.close();
        }
        catch(Exception ex)
        {
            System.out.println("ERROR");
        }
    }

}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Driver
{
    public static void main(String args[])
    {
        try
        {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            PrintWriter pw = new PrintWriter(System.out);

            String[] str = br.readLine().trim().split(" ");
            int n = Integer.parseInt(str[0]);
            int d = Integer.parseInt(str[1]);

            long[] arr = new long[n];

            String[] seq = br.readLine().trim().split(" ");
            for(int i = 0; i < n; i++){
                arr[i] = Long.parseLong(seq[i]);
            }

            long current = arr[0];
            long count = 0;
            for(int i = 1; i < arr.length; i++){
                if(arr[i] <= current){
                    long diff = current - arr[i];
                    if(diff <= d){
                        count++;
                        arr[i] += d;
                    } else {
                        long div = (long)Math.ceil((double)diff / d);
                        count += div;
                        arr[i] += d * div;
                    }
                }

                current = arr[i];
            }

            pw.println(count);

            pw.close();
        }
        catch(Exception ex)
        {
            System.out.println("ERROR");
        }
    }

}


import java.io.*;
import java.util.*;

public class CF {

	void realSolve() {
		int n = in.nextInt();
		int d = in.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = in.nextInt();
		}
		long res = 0;
		int last = a[0];
		for (int i = 1; i < n; i++) {
			if (a[i] <= last) {
				int cnt = 1 + (last - a[i]) / d;
				res += cnt;
				last = a[i] + cnt * d;
			} else {
				last = a[i];
			}
		}
		out.println(res);
	}

	private class InputReader {
		StringTokenizer st;
		BufferedReader br;

		public InputReader(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		public InputReader(InputStream f) {
			br = new BufferedReader(new InputStreamReader(f));
		}

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

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

		double nextDouble() {
			return Double.parseDouble(next());
		}

		boolean hasMoreElements() {
			while (st == null || !st.hasMoreElements()) {
				String s;
				try {
					s = br.readLine();
				} catch (IOException e) {
					return false;
				}
				st = new StringTokenizer(s);
			}
			return st.hasMoreElements();
		}

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

	InputReader in;
	PrintWriter out;

	void solve() {
		in = new InputReader(new File("object.in"));
		try {
			out = new PrintWriter(new File("object.out"));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}

		realSolve();

		out.close();
	}

	void solveIO() {
		in = new InputReader(System.in);
		out = new PrintWriter(System.out);

		realSolve();

		out.close();

	}

	public static void main(String[] args) {
		new CF().solveIO();
	}
}


import java.util.Scanner;

public class C11A {
    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);

        int n = in.nextInt();
        int d = in.nextInt();
        int a[] = new int[n];

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

        int sum = 0;

        for (int i = 1; i < n; i++)
            if(a[i] <= a[i - 1]){
                int k = (a[i - 1] - a[i])/d + 1;

                sum += k;

                a[i] += k*d;
            }

        System.out.println(sum);
    }
}


import java.util.Scanner;

public class C11A {
    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);

        int n = in.nextInt();
        int d = in.nextInt();
        int a[] = new int[n];

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

        int sum = 0;

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

        System.out.println(sum);
    }
}


import java.util.Scanner;
public class A11 {
	public static void main (String[]args) {
		int x = 0;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int c = sc.nextInt();
		int[] sequence = new int[n];
		for(int i = 0; i<n; i++) {sequence[i]=sc.nextInt();}
		for(int i = 0; i<n-1; i++) {
			if(sequence[i]>sequence[i+1]) {
				double a = (sequence[i]-sequence[i+1])/(c+0.0);
				int y = (int) a;
				y = (a>y)?y+1:y;
				sequence[i+1] = sequence[i+1] + y*c;
				x += y;
			}
			else if(sequence[i]==sequence[i+1]) {
				sequence[i+1] += c;
				x++;
			}
		}
		System.out.print(x);
	}
}


import java.util.Scanner;
public class A11 {
	public static void main (String[]args) {
		int x = 0;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int c = sc.nextInt();
		int[] sequence = new int[n];
		for(int i = 0; i<n; i++) {sequence[i]=sc.nextInt();}
		for(int i = 0; i<n-1; i++) {
			while(sequence[i]>=sequence[i+1]) {
				sequence[i+1] += c;
				x++;
			}
			if(i == n-2)
				System.out.print(x);
		}
	}
}


import java.util.Scanner;
public class A11 {
	public static int x = 0;
	public static int[] increment(int[] list, int number, int position) {
		for(int i = position; i<list.length; i++) {
			list[i] = list[i] + number;
			x++;
		}
		return list;
	}
	public static void main (String[]args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int c = sc.nextInt();
		int[] sequence = new int[n];
		for(int i = 0; i<n; i++) {sequence[i]=sc.nextInt();}
		for(int i = n-1; i>0; i--) {
			if(sequence[i]<=sequence[i-1])
				sequence = increment(sequence,c,i);
			else if(i==1)
				System.out.print(x);
		}
	}
}


import java.util.Scanner;
public class A11 {
	public static int x = 0;
	public static int[] increment(int[] list, int number, int position) {
		for(int i = position; i<list.length; i++) {
			list[i] = list[i] + number;
			x++;
		}
		return list;
	}
	public static void main (String[]args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int c = sc.nextInt();
		int[] sequence = new int[n];
		for(int i = 0; i<n; i++) {sequence[i]=sc.nextInt();}
		for(int i = n-1; i>0; i--) {
			if(sequence[i]<=sequence[i-1])
				sequence = increment(sequence,c,i);
			if(i==1)
				System.out.print(x);
		}
	}
}


import java.util.Scanner;
public class A11 {
	public static void main (String[]args) {
		int x = 0;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int c = sc.nextInt();
		int[] sequence = new int[n];
		for(int i = 0; i<n; i++) {sequence[i]=sc.nextInt();}
		for(int i = 0; i<n-1; i++) {
			if(sequence[i]>sequence[i+1]) {
				double a = (sequence[i]-sequence[i+1])/(c+0.0);
				int y = (int) a; y = (a>y)?y+1:y;
				sequence[i+1] = sequence[i+1] + y*c;
				x += y;
			}
			if(sequence[i]==sequence[i+1]) {
				sequence[i+1] += c;
				x++;
			}
		}
		System.out.print(x);
	}
}


import java.util.Scanner;
public class A11 {
	public static void main (String[]args) {
		Scanner sc = new Scanner(System.in);
		int x = 0;
		int n = sc.nextInt();
		int c = sc.nextInt();
		int[] sequence = new int[n];
		for(int i = 0; i<n; i++) {sequence[i]=sc.nextInt();}
		for(int i = 0; i<n-1; i++) {
			if(sequence[i]>sequence[i+1]) {
				int a = (int) (sequence[i]-sequence[i+1])/c+1;
				sequence[i+1] = sequence[i+1] + a*c;
				x += a;
			}
		}
		System.out.print(x);
	}
}


import java.util.Scanner;
public class A11 {
	public static void main (String[]args) {
		int x = 0;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int c = sc.nextInt();
		int[] sequence = new int[n];
		for(int i = 0; i<n; i++) {sequence[i]=sc.nextInt();}
		for(int i = n-1; i>0; i--) {
			while(sequence[i]<=sequence[i-1]) {
				sequence[i] += c;
				x++; i = n-1;
			}
			if(i==1)
				System.out.print(x);
		}
	}
}


import java.util.Scanner;
public class A11 {
	public static void main (String[]args) {
		Scanner sc = new Scanner(System.in);
		int x = 0;
		int n = sc.nextInt();
		int c = sc.nextInt();
		int[] sequence = new int[n];
		for(int i = 0; i<n; i++) {sequence[i]=sc.nextInt();}
		for(int i = 0; i<n-1; i++) {
			if(sequence[i]>=sequence[i+1]) {
				int a = (int) ((sequence[i]-sequence[i+1])/c)+1;
				sequence[i+1] = sequence[i+1] + a*c;
				x += a;
			}
		}
		System.out.print(x);
	}
}


import java.util.Scanner;

public class A {

	public static void main(String[] args){
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		int d=in.nextInt();
		int count=0;
		int[] var=new int[n];
		for(int i=0;i<n;i++){
			var[i]=in.nextInt();
		}
		in.close();
		for(int i=1;i<n;i++){
			if(var[i]<=var[i-1]){
				if(var[i]==var[i-1]){
					var[i]+=d;
					count++;
				}
				else{
					int t=((var[i-1]-var[i])/d)+1;
					var[i]+=t*d;
					count=count+t;
				}
			}
		}
		System.out.println(count);
	}

}


import java.util.Scanner;

public class A {

	public static void main(String[] args){
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		int d=in.nextInt();
		int count=0;
		int[] var=new int[n];
		for(int i=0;i<n;i++){
			var[i]=in.nextInt();
		}
		in.close();
		for(int i=1;i<n;i++){
			if(var[i]<=var[i-1]){
				if(var[i]==var[i-1]){
					var[i]+=d;
					count++;
				}
				else{
					int t=((var[i-1]-var[i])/d)+1;
					var[i]*=t;
					count=count+t;
				}
			}
		}
		System.out.println(count);
	}

}


import java.util.Scanner;

public class A {

	public static void main(String[] args){
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		int d=in.nextInt();
		int count=0;
		int[] var=new int[n];
		for(int i=0;i<n;i++){
			var[i]=in.nextInt();
		}
		in.close();
		for(int i=1;i<n;i++){
			while(var[i]<=var[i-1]){
				var[i]=var[i]+d;
				count++;
			}
		}
		System.out.println(count);
	}

}


import java.util.Scanner;

public class A {

	public static void main(String[] args){
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		int d=in.nextInt();
		int count=0;
		int[] var=new int[n];
		for(int i=0;i<n;i++){
			var[i]=in.nextInt();
		}
		in.close();
		for(int i=1;i<n;i++){
			while(var[i]<var[i-1]){
				var[i]+=d;
				count++;
			}
		}
		System.out.println(count);
	}

}


import java.util.Scanner;

public class A {

	public static void main(String[] args){
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		int d=in.nextInt();
		int count=0;
		int[] var=new int[n];
		for(int i=0;i<n;i++){
			var[i]=in.nextInt();
		}
		in.close();
		for(int i=1;i<n;i++){
			if(var[i]<=var[i-1]){
				if(var[i]==var[i-1]){
					var[i]+=d;
					count++;
				}
				else{
					int t=((var[i-1]-var[i])/d)+1;
					var[i]*=t*d;
					count=count+t;
				}
			}
		}
		System.out.println(count);
	}

}


import java.util.Scanner;

public class A {

	public static void main(String[] args){
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		int d=in.nextInt();
		int count=0;
		int[] var=new int[n];
		for(int i=0;i<n;i++){
			var[i]=in.nextInt();
		}
		in.close();
		for(int i=1;i<n;i++){
			if(var[i]<=var[i-1]){
				if(var[i]==var[i-1])
					count++;
				else
					count=count+((var[i-1]-var[i])/d)+1;
			}
		}
		System.out.println(count);
	}

}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.security.KeyStore.Entry;
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.Map;
import java.util.StringTokenizer;

public class Main {
    static FastReader in = new FastReader(new BufferedReader(new InputStreamReader(System.in)));
    static PrintWriter out = new PrintWriter(System.out);
    static boolean file = false;
    static final int maxn = (int)2e3 + 111;
    static int inf = (1<<30)-1;
    static int n,m;
    static Integer a[] = new Integer [maxn];

    private static void solve() throws Exception {
        n = in.nextInt();
        int d = in.nextInt();
        int ans = 0;

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

        for (int i=2; i<=n; i++) {
            if (a[i]>a[i-1]) continue;
            int t = a[i-1]-a[i];
            t /= d;
            a[i]+=(t*d);
            ans+=t;
            if (a[i]<=a[i-1]) {
                a[i]+=d;
                ans++;
            }
        }

        out.println(ans);

    }

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

        if (file) {
            in = new FastReader(new BufferedReader(new FileReader("sumdist.in")));
            out = new PrintWriter ("sumdist.out");
        }

        solve();
        out.close();
    }

}

class Pair {
    int x,y;
    public Pair (int x, int y) {
        this.x = x;
        this.y = y;
    }
    @Override
    public boolean equals(Object obj) {
        Pair p = (Pair)obj;
        if (p.x == x && p.y==y) return true;
        return false;
    }
    @Override
    public int hashCode() {
        // TODO Auto-generated method stub
        return x;
    }

}

class FastReader {
    BufferedReader bf;
    StringTokenizer tk = null;

    public FastReader(BufferedReader bf) {
        this.bf = bf;
    }

    public String nextToken () throws Exception {
        if (tk==null || !tk.hasMoreTokens()) {
            tk = new StringTokenizer(bf.readLine());
        }
        return tk.nextToken();
    }

    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String [] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BufferedOutputStream bos = new BufferedOutputStream(System.out);
		String eol = System.getProperty("line.separator");
		byte[] eolb  = eol.getBytes();
		try {
			String str = br.readLine();
			int blank = str.indexOf( " ");
			int n = Integer.parseInt(str.substring(0,blank));
			int d = Integer.parseInt(str.substring(blank+1));
			long [] seq = new long[n];
			str = br.readLine();
			int length = str.length();
			int j = 0;
			int s = 0;
			int k = 0;
			while(j<length) {
				while(j<length) {
					if(str.charAt(j) == ' ') {
						 break;
					} else {
						j++;
					}
				}
				seq[k] = Integer.parseInt(str.substring(s,j));
				j++;
				s=j;
				k++;
			}
			long add = 0;
			for(int i= 1 ; i < n ; i++) {
				if(seq[i]<=seq[i-1]) {
					long extra = seq[i-1] -seq[i];
					long a = ((extra/d) + 1 );
					seq[i] += (a*d);
					add+= a;
				}
			}
			bos.write(new Long(add).toString().getBytes());
			bos.write(eolb);
			bos.flush();
		} catch(IOException ioe) {
			ioe.printStackTrace();
		}
	}
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class CodeForces{
    static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer token;
    public static void main(String args[])throws Exception{
        token = new StringTokenizer(reader.readLine());
        int n = Integer.parseInt(token.nextToken());
        int d = Integer.parseInt(token.nextToken());
        token = new StringTokenizer(reader.readLine());
        int [] list= new int[n];
        for (int i = 0; i < n; i++) {
            list[i] = Integer.parseInt(token.nextToken());
        }
        int counter= 0;
        for (int i = 0; i < n - 1; i++) {
            while(list[i + 1] <= list[i]){
                counter++;
                list[i + 1] += d;
            }
        }

        while(list[n - 1] <= list[n - 2]){
            counter++;
            list[n - 1]+= d;
        }
        System.out.println(counter);
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class CodeForces{
    static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer token;
    public static void main(String args[])throws Exception{
        token = new StringTokenizer(reader.readLine());
        int n = Integer.parseInt(token.nextToken());
        int d = Integer.parseInt(token.nextToken());
        token = new StringTokenizer(reader.readLine());
        int [] list= new int[n];
        for (int i = 0; i < n; i++) {
            list[i] = Integer.parseInt(token.nextToken());
        }
        int counter= 0;
        for (int i = 0; i < n - 1; i++) {
            if(list[i + 1] <= list[i]){
                int temp = list[i] - list[i + 1];
                //sama
                if(temp == 0){
                    counter++;
                    list[i + 1] += d;
                }else{
                    int lol = temp;
                    temp = (int) Math.ceil(1.0 * temp/d);
                    if(lol%d==0){
                        temp++;
                    }
                    counter += temp;
                    list[i + 1] += (temp*d);
                }
            }
        }

        if(list[n - 1] <= list[n - 2]){
            int temp = list[n - 2] - list[n - 1];
            //sama
            if(temp == 0){
                counter++;
            }else{
                int lol = temp;
                temp = (int) Math.ceil(1.0 * temp/d);
                if(lol%d==0){
                    temp++;
                }
                counter += temp;
            }
        }
        System.out.println(counter);
    }
}


/***********************************/
/*MAC0327 - Desafios de Programacao*/
/***********************************/
/***Evandro Augusto Nunes Sanches***/
/***********************************/
/**********NUSP  5388861************/
/***********************************/
/***********Problema 04*************/
/***********************************/

#include<stdio.h>

#define MAX 100001
#define TESTE 0
#define JOG1 0
#define JOG2 1

long int buscabin(int *vetor, long int esq, long int dir, long int key);

int main(){
    long int n;
    int entrada[MAX], acumulado[2][MAX], vencedor;
    long int saida[MAX][2];
    char c;
    long int pontosMax, setsJogador1, setsJogador2, procura;
    long int fimSetAnterior;
    long int indice[2];
    long int npossibilidades;

    /*controle*/
    long int i;

    /*Entrada*/
    scanf("%ld", &n);

    /*
    while(scanf("%c", &c) && c == '\n');
    entrada[0] = c - '0';
    if(entrada[0] == 1){
        acumulado[JOG1][0] = 1;
        acumulado[JOG2][0] = 0;
    }
    else{
        acumulado[JOG1][0] = 0;
        acumulado[JOG2][0] = 1;
    }
    */
    acumulado[JOG1][0] = 0;
    acumulado[JOG2][0] = 0;
    n++;

    for(i = 1; i < n; i++){
        while(scanf("%c", &c) && (c == '\n' || c == ' '));
        entrada[i] = c - '0';
        if(entrada[i] == 1){
            acumulado[JOG1][i] = acumulado[JOG1][i-1] + 1;
            acumulado[JOG2][i] = acumulado[JOG2][i-1];
        }
        else{
            acumulado[JOG1][i] = acumulado[JOG1][i-1];
            acumulado[JOG2][i] = acumulado[JOG2][i-1] + 1;
        }
    }

    if(entrada[n-1] == 1){
        vencedor = JOG1;
        pontosMax = acumulado[JOG1][n - 1];
    }
    else{
        vencedor = JOG2;
        pontosMax = acumulado[JOG2][n - 1];
    }

    /***/
    if(TESTE){
        for(i = 0; i < n; i++){
            printf("%d",entrada[i]);
        }
        printf("\n");
        for(i = 0; i < n; i++){
            printf("%d",acumulado[JOG1][i]);
        }
        printf("\n");
        for(i = 0; i < n; i++){
            printf("%d",acumulado[JOG2][i]);
        }
        printf("\n");
    }
    /***/

    /*Processamento*/
    npossibilidades = 0;
    for(i = pontosMax; i > 0; i--){
       /*verifica se jogo de i pontos e valido*/
        setsJogador1 = 0;
        setsJogador2 = 0;
        fimSetAnterior = 0;
        while(fimSetAnterior < n - 1){
            procura = acumulado[JOG1][fimSetAnterior] + i;
            indice[JOG1] = buscabin(acumulado[JOG1],fimSetAnterior + 1, n-1, procura);
            procura = acumulado[JOG2][fimSetAnterior] + i;
            indice[JOG2] = buscabin(acumulado[JOG2],fimSetAnterior + 1, n-1, procura);
            /***/
            if(TESTE){
                printf("indices devolvidos: JOG1:%ld, JOG2:%ld\n", indice[JOG1], indice[JOG2]);
            }
            /***/
            if(indice[JOG1] < indice[JOG2]){
                fimSetAnterior = indice[JOG1];
                setsJogador1++;
            }
            else{
                fimSetAnterior = indice[JOG2];
                setsJogador2++;
            }
        }
        if(fimSetAnterior < MAX){
            if(setsJogador1 > setsJogador2 && vencedor == JOG1){
                saida[npossibilidades][0] = setsJogador1;
                saida[npossibilidades][1] = i;
                npossibilidades++;
            }
            else if(setsJogador1 < setsJogador2 && vencedor == JOG2){
                saida[npossibilidades][0] = setsJogador2;
                saida[npossibilidades][1] = i;
                npossibilidades++;
            }
        }
    }

    /*Saida*/
    printf("%ld\n", npossibilidades);
    for( i = 0; i < npossibilidades; i++){
        printf("%ld %ld\n", saida[i][0], saida[i][1]);
    }
    /*retorna jogos validos em ordem crescente [sets] [points]*/

    return 0;
}

long int buscabin(int *vetor, long int esq, long int dir, long int key){

    /***/
    if(TESTE){
        long int i;
        printf("Dentro do buscabin:\n");
        printf("Procurando key = %ld, de %ld a %ld\n", key, esq, dir);
        for(i = esq; i <= dir; i++){
           printf("%d ", vetor[i]);
        }
        printf("\n");
        /*return MAX;<=====================*/
    }
    /***/
    if(dir < esq)
        return MAX;
    else{
        long int meio = (dir - esq)/2 + esq;

        if(vetor[meio] > key)
            return buscabin(vetor, esq, meio - 1, key);
        else if(vetor[meio] < key)
            return buscabin(vetor, meio + 1, dir, key);
        else if( vetor[meio - 1] == key)
            return buscabin(vetor, esq, meio - 1, key);
        else
            return meio;
    }
}


/***********************************/
/*MAC0327 - Desafios de Programacao*/
/***********************************/
/***Evandro Augusto Nunes Sanches***/
/***********************************/
/**********NUSP  5388861************/
/***********************************/
/***********Problema 04*************/
/***********************************/

#include<stdio.h>

#define MAX 100001
#define TESTE 0
#define JOG1 0
#define JOG2 1

long int buscabin(int *vetor, long int esq, long int dir, long int key);
int insereSaida(long int *matriz, long int posicao, long int sets, long int pontos);

int main(){
    long int n;
    int entrada[MAX], acumulado[2][MAX], vencedor;
    long int saida[MAX][2];
    char c;
    long int pontosMax, setsJogador1, setsJogador2, procura;
    long int fimSetAnterior;
    long int indice[2];
    long int npossibilidades;

    /*controle*/
    long int i;

    /*Entrada*/
    scanf("%ld", &n);

    /*
    while(scanf("%c", &c) && c == '\n');
    entrada[0] = c - '0';
    if(entrada[0] == 1){
        acumulado[JOG1][0] = 1;
        acumulado[JOG2][0] = 0;
    }
    else{
        acumulado[JOG1][0] = 0;
        acumulado[JOG2][0] = 1;
    }
    */
    acumulado[JOG1][0] = 0;
    acumulado[JOG2][0] = 0;
    n++;

    for(i = 1; i < n; i++){
        while(scanf("%c", &c) && (c == '\n' || c == ' '));
        entrada[i] = c - '0';
        if(entrada[i] == 1){
            acumulado[JOG1][i] = acumulado[JOG1][i-1] + 1;
            acumulado[JOG2][i] = acumulado[JOG2][i-1];
        }
        else{
            acumulado[JOG1][i] = acumulado[JOG1][i-1];
            acumulado[JOG2][i] = acumulado[JOG2][i-1] + 1;
        }
    }

    if(entrada[n-1] == 1){
        vencedor = JOG1;
        pontosMax = acumulado[JOG1][n - 1];
    }
    else{
        vencedor = JOG2;
        pontosMax = acumulado[JOG2][n - 1];
    }

    /***/
    if(TESTE){
        for(i = 0; i < n; i++){
            printf("%d",entrada[i]);
        }
        printf("\n");
        for(i = 0; i < n; i++){
            printf("%d",acumulado[JOG1][i]);
        }
        printf("\n");
        for(i = 0; i < n; i++){
            printf("%d",acumulado[JOG2][i]);
        }
        printf("\n");
    }
    /***/

    /*Processamento*/
    npossibilidades = 0;
    for(i = pontosMax; i > 0; i--){
       /*verifica se jogo de i pontos e valido*/
        setsJogador1 = 0;
        setsJogador2 = 0;
        fimSetAnterior = 0;
        while(fimSetAnterior < n - 1){
            procura = acumulado[JOG1][fimSetAnterior] + i;
            indice[JOG1] = buscabin(acumulado[JOG1],fimSetAnterior + 1, n-1, procura);
            procura = acumulado[JOG2][fimSetAnterior] + i;
            indice[JOG2] = buscabin(acumulado[JOG2],fimSetAnterior + 1, n-1, procura);
            /***/
            if(TESTE){
                printf("indices devolvidos: JOG1:%ld, JOG2:%ld\n", indice[JOG1], indice[JOG2]);
            }
            /***/
            if(indice[JOG1] < indice[JOG2]){
                fimSetAnterior = indice[JOG1];
                setsJogador1++;
            }
            else{
                fimSetAnterior = indice[JOG2];
                setsJogador2++;
            }
        }
        if(fimSetAnterior < MAX){
            if(setsJogador1 > setsJogador2 && vencedor == JOG1){
                insereSaida((long int *)saida,npossibilidades,setsJogador1,i);
                npossibilidades++;
            }
            else if(setsJogador1 < setsJogador2 && vencedor == JOG2){
                insereSaida((long int*)saida,npossibilidades,setsJogador2,i);
                npossibilidades++;
            }
        }
    }

    /*Saida*/
    printf("%ld\n", npossibilidades);
    for( i = 0; i < npossibilidades; i++){
        printf("%ld %ld\n", saida[i][0], saida[i][1]);
    }
    /*retorna jogos validos em ordem crescente [sets] [points]*/

    return 0;
}

long int buscabin(int *vetor, long int esq, long int dir, long int key){

    /***/
    if(TESTE){
        long int i;
        printf("Dentro do buscabin:\n");
        printf("Procurando key = %ld, de %ld a %ld\n", key, esq, dir);
        for(i = esq; i <= dir; i++){
           printf("%d ", vetor[i]);
        }
        printf("\n");
        /*return MAX;<=====================*/
    }
    /***/
    if(dir < esq)
        return MAX;
    else{
        long int meio = (dir - esq)/2 + esq;

        if(vetor[meio] > key)
            return buscabin(vetor, esq, meio - 1, key);
        else if(vetor[meio] < key)
            return buscabin(vetor, meio + 1, dir, key);
        else if( vetor[meio - 1] == key)
            return buscabin(vetor, esq, meio - 1, key);
        else
            return meio;
    }
}

int insereSaida(long int *matriz, long int posicao, long int sets, long int pontos){
    if(posicao != 0){
        while(*((matriz+(posicao - 1)*2)+0) > sets){
            *((matriz+(posicao)*2)+0) = *((matriz+(posicao - 1)*2)+0);
            /*matriz[posicao][0] = matriz[posicao - 1][0];*/
            *((matriz+(posicao)*2)+1) = *((matriz+(posicao - 1)*2)+1);
            /*matriz[posicao][1] = matriz[posicao - 1][1];*/
            posicao--;
        }
        while(*((matriz+(posicao - 1)*2)+0) == sets && *((matriz+(posicao - 1)*2)+1) > pontos){
            *((matriz+(posicao)*2)+0) = *((matriz+(posicao - 1)*2)+0);
            /*matriz[posicao][0] = matriz[posicao - 1][0];*/
            *((matriz+(posicao)*2)+1) = *((matriz+(posicao - 1)*2)+1);
            /*matriz[posicao][1] = matriz[posicao - 1][1];*/
            posicao--;
        }
    }
    *((matriz+(posicao)*2)+0) = sets;
    /*matriz[posicao][0] = matriz[posicao - 1][0];*/
    *((matriz+(posicao)*2)+1) = pontos;
    /*matriz[posicao][1] = matriz[posicao - 1][1];*/
    return 0;
}


/***********************************/
/*MAC0327 - Desafios de Programacao*/
/***********************************/
/***Evandro Augusto Nunes Sanches***/
/***********************************/
/**********NUSP  5388861************/
/***********************************/
/***********Problema 04*************/
/***********************************/

#include<stdio.h>

#define MAX 100001
#define TESTE 0
#define JOG1 0
#define JOG2 1

long int buscabin(int *vetor, long int esq, long int dir, long int key);

int main(){
    long int n;
    int entrada[MAX], acumulado[2][MAX], vencedor;
    long int saida[MAX][2];
    char c;
    long int pontosMax, setsJogador1, setsJogador2, procura;
    long int fimSetAnterior;
    long int indice[2];
    long int npossibilidades;

    /*controle*/
    long int i;

    /*Entrada*/
    scanf("%ld", &n);

    /*
    while(scanf("%c", &c) && c == '\n');
    entrada[0] = c - '0';
    if(entrada[0] == 1){
        acumulado[JOG1][0] = 1;
        acumulado[JOG2][0] = 0;
    }
    else{
        acumulado[JOG1][0] = 0;
        acumulado[JOG2][0] = 1;
    }
    */
    acumulado[JOG1][0] = 0;
    acumulado[JOG2][0] = 0;
    n++;

    for(i = 1; i < n; i++){
        while(scanf("%c", &c) && c == '\n');
        entrada[i] = c - '0';
        if(entrada[i] == 1){
            acumulado[JOG1][i] = acumulado[JOG1][i-1] + 1;
            acumulado[JOG2][i] = acumulado[JOG2][i-1];
        }
        else{
            acumulado[JOG1][i] = acumulado[JOG1][i-1];
            acumulado[JOG2][i] = acumulado[JOG2][i-1] + 1;
        }
    }

    if(entrada[n-1] == 1){
        vencedor = JOG1;
        pontosMax = acumulado[JOG1][n - 1];
    }
    else{
        vencedor = JOG2;
        pontosMax = acumulado[JOG2][n - 1];
    }

    /***/
    if(TESTE){
        for(i = 0; i < n; i++){
            printf("%d",entrada[i]);
        }
        printf("\n");
        for(i = 0; i < n; i++){
            printf("%d",acumulado[JOG1][i]);
        }
        printf("\n");
        for(i = 0; i < n; i++){
            printf("%d",acumulado[JOG2][i]);
        }
        printf("\n");
    }
    /***/

    /*Processamento*/
    npossibilidades = 0;
    for(i = pontosMax; i > 0; i--){
       /*verifica se jogo de i pontos e valido*/
        setsJogador1 = 0;
        setsJogador2 = 0;
        fimSetAnterior = 0;
        while(fimSetAnterior < n - 1){
            procura = acumulado[JOG1][fimSetAnterior] + i;
            indice[JOG1] = buscabin(acumulado[JOG1],fimSetAnterior + 1, n-1, procura);
            procura = acumulado[JOG2][fimSetAnterior] + i;
            indice[JOG2] = buscabin(acumulado[JOG2],fimSetAnterior + 1, n-1, procura);
            /***/
            if(TESTE){
                printf("indices devolvidos: JOG1:%ld, JOG2:%ld\n", indice[JOG1], indice[JOG2]);
            }
            /***/
            if(indice[JOG1] < indice[JOG2]){
                fimSetAnterior = indice[JOG1];
                setsJogador1++;
            }
            else{
                fimSetAnterior = indice[JOG2];
                setsJogador2++;
            }
        }
        if(fimSetAnterior < MAX){
            if(setsJogador1 > setsJogador2 && vencedor == JOG1){
                saida[npossibilidades][0] = setsJogador1;
                saida[npossibilidades][1] = i;
                npossibilidades++;
            }
            else if(setsJogador1 < setsJogador2 && vencedor == JOG2){
                saida[npossibilidades][0] = setsJogador2;
                saida[npossibilidades][1] = i;
                npossibilidades++;
            }
        }
    }

    /*Saida*/
    printf("%ld\n", npossibilidades);
    for( i = 0; i < npossibilidades; i++){
        printf("%ld %ld\n", saida[i][0], saida[i][1]);
    }
    /*retorna jogos validos em ordem crescente [sets] [points]*/

    return 0;
}

long int buscabin(int *vetor, long int esq, long int dir, long int key){

    /***/
    if(TESTE){
        long int i;
        printf("Dentro do buscabin:\n");
        printf("Procurando key = %ld, de %ld a %ld\n", key, esq, dir);
        for(i = esq; i <= dir; i++){
           printf("%d ", vetor[i]);
        }
        printf("\n");
        /*return MAX;<=====================*/
    }
    /***/
    if(dir < esq)
        return MAX;
    else{
        long int meio = (dir - esq)/2 + esq;

        if(vetor[meio] > key)
            return buscabin(vetor, esq, meio - 1, key);
        else if(vetor[meio] < key)
            return buscabin(vetor, meio + 1, dir, key);
        else if( vetor[meio - 1] == key)
            return buscabin(vetor, esq, meio - 1, key);
        else
            return meio;
    }
}


#include <stdio.h>
int main()
{
    long n,i,setgena,setpetya,set,ponto,pontogena,pontopetya,aux,cont,N[1000][2];
    int M[100001],correto;
    cont = 0;
    scanf("%li",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&M[i]);
    }
    for(set=1;set<=n;set++)
    {
        aux = (n+2*set -1)/(4*set-2);
        if(aux ==0)
        {
            aux = 1;
        }
        for(ponto=aux;ponto*set<=n;ponto++)
        {
            correto = 0;
            setgena=setpetya=pontogena=pontopetya=0;
            for(i=1;i<=n&&correto == 0;i++)
            {
                if(setpetya>setgena)
                {
                    aux = set - setpetya;
                }
                else
                {
                    aux = set - setgena;
                }
                if(setgena == set || setpetya == set|| ((pontogena==0 &&pontopetya==0)&&(ponto*(aux)>n-i+1)) || ((pontogena==0 &&pontopetya==0)&&((2*ponto-1)*(2*set - setgena -setpetya -1)<n-i+1)))
                {
                    correto =1;
                }
                if(M[i]==1)
                {
                    pontopetya = pontopetya+1;
                }
                else
                {
                    pontogena = pontogena+1;
                }
                if(pontogena==ponto)
                {
                    setgena = setgena +1;
                    pontogena = pontopetya =0;
                }
                if(pontopetya==ponto)
                {
                    setpetya = setpetya+1;
                    pontogena = pontopetya =0;
                }
            }
            if(setgena!=set && setpetya!=set)
            {
                correto =1;
            }
            if(correto == 0)
            {
                cont = cont+1;
                N[cont][1] =set;
                N[cont][2] =ponto;
            }
        }
    }
    printf("%li",cont);
    for(i=1;i<=cont;i++)
    {
        printf("\n%li %li",N[i][1], N[i][2]);
    }
    return 0;
}


#include <stdio.h>
int main()
{
    long n,i,setgena,setpetya,set,ponto,pontogena,pontopetya,cont,N[1000][2];
    int M[100001],achou, ultimo;
    cont = 0;
    scanf("%li",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&M[i]);
    }
    for(ponto=n;ponto>=1;ponto--)
    {
        pontogena = pontopetya = setgena = setpetya =0;
        for(i=1;i<=n;i++)
        {
            ultimo = M[i];
            if(M[i]==1)
            {
                pontopetya = pontopetya+1;
            }
            else
            {
                pontogena = pontogena+1;
            }
            if(pontogena ==ponto)
            {
                setgena = setgena+1;
                pontogena = pontopetya = 0;
            }
            else
            {
                if(pontopetya == ponto)
                {
                    setpetya = setpetya +1;
                    pontogena = pontopetya = 0;
                }
            }
        }
        if(setpetya != setgena && pontogena==0 && pontopetya ==0&&((ultimo == 1 && setpetya>setgena)||(ultimo==2&&setgena>setpetya)))
        {
            cont = cont+1;
            if(setgena>setpetya)
            {
                set = setgena;
            }
            else
            {
                set = setpetya;
            }
            if(cont==1 ||( cont>1&& N[cont-1][1]!=set))
            {
                N[cont][1]= set;
                N[cont][2]= ponto;
            }
            else
            {
                if(N[cont-1][1]==set)
                {
                    achou=0;
                    for(i=1;i<cont&&achou==0;i++)
                    {
                        if(M[i]==set)
                        {
                           achou =i;
                        }
                    }
                    for(i=cont-1;i>=achou;i--)
                    {
                        N[i+1][1]=N[i][1];
                        N[i+1][2]=N[i][2];
                    }
                    N[achou][1]=set;
                    N[achou][2]=ponto;
                }
            }
        }
    }
    printf("%li",cont);
    for(i=1;i<=cont;i++)
    {
        printf("\n%li %li",N[i][1], N[i][2]);
    }
    return 0;
}


#include <stdio.h>
int main()
{
    long n,i,setgena,setpetya,set,ponto,pontogena,pontopetya,cont,N[1000][2];
    int M[100001],achou;
    cont = 0;
    scanf("%li",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&M[i]);
    }
    for(ponto=n;ponto>=1;ponto--)
    {
        pontogena = pontopetya = setgena = setpetya =0;
        for(i=1;i<=n;i++)
        {
            if(M[i]==1)
            {
                pontopetya = pontopetya+1;
            }
            else
            {
                pontogena = pontogena+1;
            }
            if(pontogena ==ponto)
            {
                setgena = setgena+1;
                pontogena = pontopetya = 0;
            }
            else
            {
                if(pontopetya == ponto)
                {
                    setpetya = setpetya +1;
                    pontogena = pontopetya = 0;
                }
            }
        }
        if(setpetya != setgena && pontogena==0 && pontopetya ==0)
        {
            cont = cont+1;
            if(setgena>setpetya)
            {
                set = setgena;
            }
            else
            {
                set = setpetya;
            }
            if(cont==1 ||( cont>1&& N[cont-1][1]!=set))
            {
                N[cont][1]= set;
                N[cont][2]= ponto;
            }
            else
            {
                if(N[cont-1][1]==set)
                {
                    achou=0;
                    for(i=1;i<cont&&achou==0;i++)
                    {
                        if(M[i]==set)
                        {
                           achou =i;
                        }
                    }
                    for(i=cont-1;i>=achou;i--)
                    {
                        N[i+1][1]=N[i][1];
                        N[i+1][2]=N[i][2];
                    }
                    N[achou][1]=set;
                    N[achou][2]=ponto;
                }
            }
        }
    }
    printf("%li",cont);
    for(i=1;i<=cont;i++)
    {
        printf("\n%li %li",N[i][1], N[i][2]);
    }
    return 0;
}


#include <stdio.h>
int main()
{
    long n,i,setgena,setpetya,set,ponto,pontogena,pontopetya,cont,N[1000][3];
    int M[100001],achou, ultimo;
    N[0][1]=N[0][2] = 0;
    cont = 0;
    scanf("%li",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&M[i]);
    }
    for(ponto=n;ponto>=1;ponto--)
    {
        pontogena = pontopetya = setgena = setpetya =0;
        for(i=1;i<=n;i++)
        {
            ultimo = M[i];
            if(M[i]==1)
            {
                pontopetya = pontopetya+1;
            }
            else
            {
                pontogena = pontogena+1;
            }
            if(pontogena ==ponto)
            {
                setgena = setgena+1;
                pontogena = pontopetya = 0;
            }
            else
            {
                if(pontopetya == ponto)
                {
                    setpetya = setpetya +1;
                    pontogena = pontopetya = 0;
                }
            }
        }
        if(setpetya != setgena && pontogena==0 && pontopetya ==0&&((ultimo == 1 && setpetya>setgena)||(ultimo==2&&setgena>setpetya)))
        {
            cont = cont+1;
            if(setgena>setpetya)
            {
                set = setgena;
            }
            else
            {
                set = setpetya;
            }
            if(cont==1 ||(N[cont-1][1]!=set))
            {
                N[cont][1]= set;
                N[cont][2]= ponto;
            }
            else
            {
                    achou=0;
                    for(i=cont-1;i>=1&&achou==0;i--)
                    {
                        if(N[i][1]!=set)
                        {
                           achou =i+1;
                        }
                    }
                    for(i=cont-1;i>=achou;i--)
                    {
                        N[i+1][1]=N[i][1];
                        N[i+1][2]=N[i][2];
                    }
                    N[achou][1]=set;
                    N[achou][2]=ponto;
            }
        }
    }
    printf("%li",cont);
    for(i=1;i<=cont;i++)
    {
        printf("\n%li %li",N[i][1], N[i][2]);
    }
    return 0;
}


#include <stdio.h>
int main()
{
    long n,i,setgena,setpetya,set,ponto,pontogena,pontopetya,cont,N[100001][2],max,M[100001][2],petya,gena;
    int achou, ultimo,ok;
    N[0][1]=N[0][2] = M[0][1]=M[0][2]=0;
    cont = 0;
    max =0;
    scanf("%li",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&ultimo);
        if(ultimo==1)
        {
            M[i][1] = M[i-1][1]+1;
            M[i][2] = M[i-1][2];
        }
        else
        {
            M[i][1] = M[i-1][1];
            M[i][2] = M[i-1][2]+1;
        }
    }
   /* printf("\n");
    for(i=1;i<=n;i++)
    {
        printf("%li ", M[i][1]);
    }
    printf("\n");
    for(i=1;i<=n;i++)
    {
        printf("%li ", M[i][2]);
    }  */
    if(M[n][1] >M[n][2])
    {
        max = M[n][1];
    }
    else
    {
        max = M[n][2];
    }
    for(ponto=max;ponto>=1;ponto--)
    {
        ok=0;
        pontogena = pontopetya = setgena = setpetya =petya=gena=0;
        i=0;
        while(i<n)
        {
            while(i<n&&pontogena<ponto&&pontopetya<ponto)
            {
                if(pontogena>pontopetya)
                {
                    i = i+ponto - pontogena;
                }
                else
                {
                    i=i+ponto-pontopetya;
                }
                if(i<=n)
                {
                    pontogena = M[i][1] - gena;
                    pontopetya = M[i][2] - petya;
                }
                else
                {
                    ok=1;
                }
            }
            if(i<=n)
            {
                if(pontogena == ponto&&pontopetya<pontogena)
                {
                    setgena = setgena +1;
                    gena = gena+pontogena;
                    petya = petya+pontopetya;
                    pontogena = 0;
                    pontopetya = 0;
                }
                else
                {
                    if(pontopetya == ponto&&pontogena<pontopetya)
                    {
                        setpetya = setpetya +1;
                        gena = gena+pontogena;
                        petya = petya+pontopetya;
                        pontogena = 0;
                        pontopetya = 0;
                    }
                    else
                    {
                        ok =1;
                    }
                }
            }
            else
            {
                ok =1;
            }
        }
        if(setpetya>=setgena&& ultimo ==1)
        {
            ok=1;
        }
        if(setpetya<=setgena&& ultimo ==2)
        {
            ok=1;
        }
        if(ok==0)
        {
            cont = cont+1;
            if(setgena>setpetya)
            {
                set = setgena;
            }
            else
            {
                set = setpetya;
            }
            if(cont==1 ||(N[cont-1][1]!=set))
            {
                N[cont][1]= set;
                N[cont][2]= ponto;
            }
            else
            {
                    achou=0;
                    for(i=cont-1;i>=1&&achou==0;i--)
                    {
                        if(N[i][1]!=set)
                        {
                            N[i+1][1]=set;
                            N[i+1][2]=ponto;
                            achou =1;
                        }
                        else
                        {
                            N[i+1][1]=N[i][1];
                            N[i+1][2]=N[i][2];
                        }
                    }
            }
        }
    }
    printf("%li",cont);
    for(i=1;i<=cont;i++)
    {
        printf("\n%li %li",N[i][1], N[i][2]);
    }
    return 0;
}


#include <stdio.h>
int main()
{
    long n,i,setgena,setpetya,set,ponto,pontogena,pontopetya,aux,cont,N[1000][2];
    int M[100001],correto;
    cont = 0;
    scanf("%li",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&M[i]);
    }
    for(set=1;set<=n;set++)
    {
        aux = (n+2*set -1)/(4*set-2);
        if(aux ==0)
        {
            aux = 1;
        }
        for(ponto=aux;ponto*set<=n;ponto++)
        {
            correto = 0;
            setgena=setpetya=pontogena=pontopetya=0;
            for(i=1;i<=n&&correto == 0;i++)
            {
                if(setgena == set || setpetya == set)
                {
                    correto =1;
                }
                if(M[i]==1)
                {
                    pontopetya = pontopetya+1;
                }
                else
                {
                    pontogena = pontogena+1;
                }
                if(pontogena==ponto)
                {
                    setgena = setgena +1;
                    pontogena = pontopetya =0;
                }
                if(pontopetya==ponto)
                {
                    setpetya = setpetya+1;
                    pontogena = pontopetya =0;
                }
            }
            if(setgena!=set && setpetya!=set)
            {
                correto =1;
            }
            if(correto == 0)
            {
                cont = cont+1;
                N[cont][1] =set;
                N[cont][2] =ponto;
            }
        }
    }
    printf("%li",cont);
    for(i=1;i<=cont;i++)
    {
        printf("\n%li %li",N[i][1], N[i][2]);
    }
    return 0;
}


#include <stdio.h>
/*reenvio*/
int main()
{
    long n,i,setgena,setpetya,set,ponto,pontogena,pontopetya,cont,N[100001][2],max,M[100001][2],petya,gena;
    int achou, ultimo,ok;
    N[0][1]=N[0][2] = M[0][1]=M[0][2]=0;
    cont = 0;
    max =0;
    scanf("%li",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&ultimo);
        if(ultimo==1)
        {
            M[i][1] = M[i-1][1]+1;
            M[i][2] = M[i-1][2];
        }
        else
        {
            M[i][1] = M[i-1][1];
            M[i][2] = M[i-1][2]+1;
        }
    }
   /* printf("\n");
    for(i=1;i<=n;i++)
    {
        printf("%li ", M[i][1]);
    }
    printf("\n");
    for(i=1;i<=n;i++)
    {
        printf("%li ", M[i][2]);
    }  */
    if(M[n][1] >M[n][2])
    {
        max = M[n][1];
    }
    else
    {
        max = M[n][2];
    }
    for(ponto=max;ponto>=1;ponto--)
    {
        ok=0;
        pontogena = pontopetya = setgena = setpetya =petya=gena=0;
        i=0;
        while(i<n)
        {
            while(i<n&&pontogena<ponto&&pontopetya<ponto)
            {
                if(pontogena>pontopetya)
                {
                    i = i+ponto - pontogena;
                }
                else
                {
                    i=i+ponto-pontopetya;
                }
                if(i<=n)
                {
                    pontogena = M[i][1] - gena;
                    pontopetya = M[i][2] - petya;
                }
                else
                {
                    ok=1;
                }
            }
            if(i<=n)
            {
                if(pontogena == ponto&&pontopetya<pontogena)
                {
                    setgena = setgena +1;
                    gena = gena+pontogena;
                    petya = petya+pontopetya;
                    pontogena = 0;
                    pontopetya = 0;
                }
                else
                {
                    if(pontopetya == ponto&&pontogena<pontopetya)
                    {
                        setpetya = setpetya +1;
                        gena = gena+pontogena;
                        petya = petya+pontopetya;
                        pontogena = 0;
                        pontopetya = 0;
                    }
                    else
                    {
                        ok =1;
                    }
                }
            }
            else
            {
                ok =1;
            }
        }
        if(setpetya>=setgena&& ultimo ==1)
        {
            ok=1;
        }
        if(setpetya<=setgena&& ultimo ==2)
        {
            ok=1;
        }
        if(ok==0)
        {
            cont = cont+1;
            if(setgena>setpetya)
            {
                set = setgena;
            }
            else
            {
                set = setpetya;
            }
            if(cont==1 ||(N[cont-1][1]!=set))
            {
                N[cont][1]= set;
                N[cont][2]= ponto;
            }
            else
            {
                    achou=0;
                    for(i=cont-1;i>=1&&achou==0;i--)
                    {
                        if(N[i][1]!=set)
                        {
                            N[i+1][1]=set;
                            N[i+1][2]=ponto;
                            achou =1;
                        }
                        else
                        {
                            N[i+1][1]=N[i][1];
                            N[i+1][2]=N[i][2];
                        }
                    }
            }
        }
    }
    printf("%li",cont);
    for(i=1;i<=cont;i++)
    {
        printf("\n%li %li",N[i][1], N[i][2]);
    }
    return 0;
}


/*Victor Luiz Martins de Sousa*/
#include <stdio.h>
int main()
{
    long n,i,setgena,setpetya,set,ponto,pontogena,pontopetya,cont,N[100001][2],max,M[100001][2],petya,gena;
    int achou, ultimo,ok;
    N[0][1]=N[0][2] = M[0][1]=M[0][2]=0;
    cont = 0;
    max =0;
    scanf("%li",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&ultimo);
        if(ultimo==1)
        {
            M[i][1] = M[i-1][1]+1;
            M[i][2] = M[i-1][2];
        }
        else
        {
            M[i][1] = M[i-1][1];
            M[i][2] = M[i-1][2]+1;
        }
    }
   /* printf("\n");
    for(i=1;i<=n;i++)
    {
        printf("%li ", M[i][1]);
    }
    printf("\n");
    for(i=1;i<=n;i++)
    {
        printf("%li ", M[i][2]);
    }  */
    if(M[n][1] >M[n][2])
    {
        max = M[n][1];
    }
    else
    {
        max = M[n][2];
    }
    for(ponto=max;ponto>=1;ponto--)
    {
        ok=0;
        pontogena = pontopetya = setgena = setpetya =petya=gena=0;
        i=0;
        while(i<n)
        {
            while(i<n&&pontogena<ponto&&pontopetya<ponto)
            {
                if(pontogena>pontopetya)
                {
                    i = i+ponto - pontogena;
                }
                else
                {
                    i=i+ponto-pontopetya;
                }
                if(i<=n)
                {
                    pontogena = M[i][1] - gena;
                    pontopetya = M[i][2] - petya;
                }
                else
                {
                    ok=1;
                }
            }
            if(i<=n)
            {
                if(pontogena == ponto&&pontopetya<pontogena)
                {
                    setgena = setgena +1;
                    gena = gena+pontogena;
                    petya = petya+pontopetya;
                    pontogena = 0;
                    pontopetya = 0;
                }
                else
                {
                    if(pontopetya == ponto&&pontogena<pontopetya)
                    {
                        setpetya = setpetya +1;
                        gena = gena+pontogena;
                        petya = petya+pontopetya;
                        pontogena = 0;
                        pontopetya = 0;
                    }
                    else
                    {
                        ok =1;
                    }
                }
            }
            else
            {
                ok =1;
            }
        }
        if(setpetya>=setgena&& ultimo ==1)
        {
            ok=1;
        }
        if(setpetya<=setgena&& ultimo ==2)
        {
            ok=1;
        }
        if(ok==0)
        {
            cont = cont+1;
            if(setgena>setpetya)
            {
                set = setgena;
            }
            else
            {
                set = setpetya;
            }
            if(cont==1 ||(N[cont-1][1]!=set))
            {
                N[cont][1]= set;
                N[cont][2]= ponto;
            }
            else
            {
                    achou=0;
                    for(i=cont-1;i>=1&&achou==0;i--)
                    {
                        if(N[i][1]!=set)
                        {
                            N[i+1][1]=set;
                            N[i+1][2]=ponto;
                            achou =1;
                        }
                        else
                        {
                            N[i+1][1]=N[i][1];
                            N[i+1][2]=N[i][2];
                        }
                    }
            }
        }
    }
    printf("%li",cont);
    for(i=1;i<=cont;i++)
    {
        printf("\n%li %li",N[i][1], N[i][2]);
    }
    return 0;
}


#include <stdio.h>
int main()
{
    long n,i,setgena,setpetya,set,ponto,pontogena,pontopetya,aux,cont,N[1000][2];
    int M[100001],correto;
    cont = 0;
    scanf("%li",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&M[i]);
    }
    for(set=1;set<=n;set++)
    {
        aux = (n+2*set -1)/(4*set-2);
        if(aux ==0)
        {
            aux = 1;
        }
        for(ponto=aux;ponto*set<=n;ponto++)
        {
            correto = 0;
            setgena=setpetya=pontogena=pontopetya=0;
            for(i=1;i<=n&&correto == 0;i++)
            {
                if(setgena == set || setpetya == set|| ponto*(set - setpetya -setgena)>n-i || (2*ponto-1)*(2*(set - setpetya -setgena)-1)<n-i)
                {
                    correto =1;
                }
                if(M[i]==1)
                {
                    pontopetya = pontopetya+1;
                }
                else
                {
                    pontogena = pontogena+1;
                }
                if(pontogena==ponto)
                {
                    setgena = setgena +1;
                    pontogena = pontopetya =0;
                }
                if(pontopetya==ponto)
                {
                    setpetya = setpetya+1;
                    pontogena = pontopetya =0;
                }
            }
            if(setgena!=set && setpetya!=set)
            {
                correto =1;
            }
            if(correto == 0)
            {
                cont = cont+1;
                N[cont][1] =set;
                N[cont][2] =ponto;
            }
        }
    }
    printf("%li",cont);
    for(i=1;i<=cont;i++)
    {
        printf("\n%li %li",N[i][1], N[i][2]);
    }
    return 0;
}


#include <stdio.h>
int main()
{
    long n,i,setgena,setpetya,set,ponto,pontogena,pontopetya,cont,N[100001][3];
    int M[100001],achou, ultimo;
    N[0][1]=N[0][2] = 0;
    cont = 0;
    scanf("%li",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&M[i]);
    }
    for(ponto=n;ponto>=1;ponto--)
    {
        pontogena = pontopetya = setgena = setpetya =0;
        for(i=1;i<=n;i++)
        {
            ultimo = M[i];
            if(M[i]==1)
            {
                pontopetya = pontopetya+1;
            }
            else
            {
                pontogena = pontogena+1;
            }
            if(pontogena ==ponto)
            {
                setgena = setgena+1;
                pontogena = pontopetya = 0;
            }
            else
            {
                if(pontopetya == ponto)
                {
                    setpetya = setpetya +1;
                    pontogena = pontopetya = 0;
                }
            }
        }
        if(setpetya != setgena && pontogena==0 && pontopetya ==0&&((ultimo == 1 && setpetya>setgena)||(ultimo==2&&setgena>setpetya)))
        {
            cont = cont+1;
            if(setgena>setpetya)
            {
                set = setgena;
            }
            else
            {
                set = setpetya;
            }
            if(cont==1 ||(N[cont-1][1]!=set))
            {
                N[cont][1]= set;
                N[cont][2]= ponto;
            }
            else
            {
                    achou=0;
                    for(i=cont-1;i>=1&&achou==0;i--)
                    {
                        if(N[i][1]!=set)
                        {
                            N[i+1][1]=set;
                            N[i+1][2]=ponto;
                            achou =1;
                        }
                        else
                        {
                            N[i+1][1]=N[i][1];
                            N[i+1][2]=N[i][2];
                        }
                    }
            }
        }
    }
    printf("%li",cont);
    for(i=1;i<=cont;i++)
    {
        printf("\n%li %li",N[i][1], N[i][2]);
    }
    return 0;
}


#include <stdio.h>
int main()
{
    long n,i,setgena,setpetya,set,ponto,pontogena,pontopetya,cont,N[100001][3],max;
    int M[100001],achou, ultimo;
    N[0][1]=N[0][2] = 0;
    cont = 0;
    max =0;
    scanf("%li",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&M[i]);
        max = max + M[i] -1;
    }
    if(n-max >max)
    {
        max = n-max;
    }
    for(ponto=max;ponto>=1;ponto--)
    {
        pontogena = pontopetya = setgena = setpetya =0;
        for(i=1;i<=n;i++)
        {
            ultimo = M[i];
            if(M[i]==1)
            {
                pontopetya = pontopetya+1;
            }
            else
            {
                pontogena = pontogena+1;
            }
            if(pontogena ==ponto)
            {
                setgena = setgena+1;
                pontogena = pontopetya = 0;
            }
            else
            {
                if(pontopetya == ponto)
                {
                    setpetya = setpetya +1;
                    pontogena = pontopetya = 0;
                }
            }
        }
        if(setpetya != setgena && pontogena==0 && pontopetya ==0&&((ultimo == 1 && setpetya>setgena)||(ultimo==2&&setgena>setpetya)))
        {
            cont = cont+1;
            if(setgena>setpetya)
            {
                set = setgena;
            }
            else
            {
                set = setpetya;
            }
            if(cont==1 ||(N[cont-1][1]!=set))
            {
                N[cont][1]= set;
                N[cont][2]= ponto;
            }
            else
            {
                    achou=0;
                    for(i=cont-1;i>=1&&achou==0;i--)
                    {
                        if(N[i][1]!=set)
                        {
                            N[i+1][1]=set;
                            N[i+1][2]=ponto;
                            achou =1;
                        }
                        else
                        {
                            N[i+1][1]=N[i][1];
                            N[i+1][2]=N[i][2];
                        }
                    }
            }
        }
    }
    printf("%li",cont);
    for(i=1;i<=cont;i++)
    {
        printf("\n%li %li",N[i][1], N[i][2]);
    }
    return 0;
}


#include <stdio.h>
int main()
{
    long n,i,setgena,setpetya,set,ponto,pontogena,pontopetya,aux,cont,N[1000][2];
    int M[100001],correto,achou;
    cont = 0;
    scanf("%li",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&M[i]);
    }
    for(ponto=n;ponto>=1;ponto--)
    {
        aux = (n+2*ponto -1)/(4*ponto-2);
        if(aux ==0)
        {
            aux = 1;
        }
        achou = 0;
        for(set=aux;ponto*set<=n&&achou==0;set++)
        {
            correto = 0;
            setgena=setpetya=pontogena=pontopetya=0;
            for(i=1;i<=n&&correto == 0;i++)
            {
                if(setpetya>setgena)
                {
                    aux = set - setpetya;
                }
                else
                {
                    aux = set - setgena;
                }
                if(setgena == set || setpetya == set|| ((pontogena==0 &&pontopetya==0)&&(ponto*(aux)>n-i+1)) || ((pontogena==0 &&pontopetya==0)&&((2*ponto-1)*(2*set - setgena -setpetya -1)<n-i+1)))
                {
                    correto =1;
                }
                if(M[i]==1)
                {
                    pontopetya = pontopetya+1;
                }
                else
                {
                    pontogena = pontogena+1;
                }
                if(pontogena==ponto)
                {
                    setgena = setgena +1;
                    pontogena = pontopetya =0;
                }
                if(pontopetya==ponto)
                {
                    setpetya = setpetya+1;
                    pontogena = pontopetya =0;
                }
            }
            if(setgena!=set && setpetya!=set)
            {
                correto =1;
            }
            if(correto == 0)
            {
                achou = 1;
                cont = cont+1;
                N[cont][1] =set;
                N[cont][2] =ponto;
            }
        }
    }
    printf("%li",cont);

    for(i=1;i<=cont;i++)
    {
        printf("\n%li %li",N[i][1], N[i][2]);
    }
    return 0;
}


/***************************************************************/
/**                                                           **/
/**   Leonardo Haddad                           nº 7295361    **/
/**   Desafios de Programação              Professora Cris    **/
/**   Problema 4 - Tennis Game                  Curso: BCC    **/
/**                                                           **/
/***************************************************************/

#include<stdio.h>
#include<stdlib.h>
#define MAX_SIZE 100000
/* #define debug_on 1 */
#define true 1
#define false 0
typedef int bool;

/* read program arguments */
int readArgs (int serve_winner[MAX_SIZE], int player1Victories[MAX_SIZE], int player2Victories[MAX_SIZE]) {
	int n, loop;
	scanf("%d", &n);
	/* process first serve result */
	scanf("%d", &serve_winner[0]);
	player1Victories[0] = 2 - serve_winner[0];
	player2Victories[0] = serve_winner[0] - 1;
	/* process other serve results */
	for (loop=1; loop<n; loop++) {
		scanf("%d", &serve_winner[loop]);
		player1Victories[loop] = player1Victories[loop-1] - serve_winner[loop] + 2;
		player2Victories[loop] = player2Victories[loop-1] + serve_winner[loop] - 1;
	}
	return n;
}

#ifdef debug_on
/* print arguments */
void printArgs (int n, int serve_winner[MAX_SIZE], int player1Victories[MAX_SIZE], int player2Victories[MAX_SIZE]) {
	int loop;
	printf("\nArguments:\n");
	printf(" n=%d;\n",n);
	printf(" serve_winner:\n");
	for (loop=0; loop<n; loop++)
		printf("  %d (%d x %d)\n",serve_winner[loop],player1Victories[loop],player2Victories[loop]);
}
#endif

int int_max (int x, int y) {
	return ( (x > y) ? x : y );
}

int int_min (int x, int y) {
	return ( (x < y) ? x : y );
}

/* search for an integer in array using binary search */
int binarySearch (int x, int first, int last, int *vector) {
   if (first > last) return -1;
   else {
      int middle = (first + last)/2;
      if (vector[middle] == x) return middle;
      if (vector[middle] > x)
         return binarySearch(x, first, middle-1, vector);
      else
         return binarySearch(x, middle+1, last, vector);
   }
}

/* merge two sorted arrays in a sorted way */
void merge (int p, int q, int r, int v[MAX_SIZE][2])
{
   int i, j, k, w[MAX_SIZE][2];

   for (i = 0, k = p; k < q; ++i, ++k) {
		w[i][0] = v[k][0];
		w[i][1] = v[k][1];
   }
   for (j = r-p-1, k = q; k < r; --j, ++k) {
	   w[j][0] = v[k][0];
	   w[j][1] = v[k][1];
   }
   i = 0; j = r-p-1;
   for (k = p; k < r; ++k)
      if (w[i][0] < w[j][0]) {
		v[k][0] = w[i][0];
		v[k][1] = w[i++][1];
	  }
      else if (w[i][0] > w[j][0])  {
		v[k][0] = w[j][0];
		v[k][1] = w[j--][1];
	  }
	  else /* (w[i][0] == w[j][0]) */ {
		if (w[i][1] <= w[j][1]) {
			v[k][0] = w[i][0];
			v[k][1] = w[i++][1];
		}
		else /* (w[i][1] > w[j][1]) */ {
			v[k][0] = w[j][0];
			v[k][1] = w[j--][1];
		}
	  }
}

/* sort array using mergesort algorithm */
void merge_sort (int p, int r, int v[MAX_SIZE][2])
{
   if (p < r-1) {
      int q = (p + r)/2;
      merge_sort (p, q, v);
      merge_sort (q, r, v);
      merge (p, q, r, v);
   }
}

void trySolution (int t, int n, int player1Victories[MAX_SIZE], int player2Victories[MAX_SIZE], int result[MAX_SIZE][2], int *resultsCount) {
	int serve, maxSetDuration, p1WinsToCompleteSet, p2WinsToCompleteSet;
	int binarySearchMax, binarySearchResult, p1SetsCount, p2SetsCount;
	#ifdef debug_on
		printf("trySolution(t=%d)\n",t);
	#endif
	serve = 0;
	p1SetsCount = 0;
	p2SetsCount = 0;
	maxSetDuration = 2 * t - 1;
	p1WinsToCompleteSet = t;
	p2WinsToCompleteSet = t;
	while (serve < n)
	{
if (n == 100000 && *resultsCount == 35 && result[34][1] == 2)
	printf("testou! (%d x %d)\n",p1Sets,p2Sets);
		binarySearchMax = int_min(serve+maxSetDuration-1, n-1);
		binarySearchResult = binarySearch(p1WinsToCompleteSet, serve, binarySearchMax, player1Victories);
		if (binarySearchResult != -1) {
			p1SetsCount++;
			while (player1Victories[binarySearchResult-1] == p1WinsToCompleteSet)
				binarySearchResult--;
			p1WinsToCompleteSet = p1WinsToCompleteSet + t;
			p2WinsToCompleteSet = p2WinsToCompleteSet + (binarySearchResult - serve + 1 - t);
		}
		else {
			binarySearchMax = int_min(serve+maxSetDuration-1, n-1);
			binarySearchResult = binarySearch(p2WinsToCompleteSet, serve, binarySearchMax, player2Victories);
			if (binarySearchResult == -1)
				return;
			p2SetsCount++;
			while (player2Victories[binarySearchResult-1] == p2WinsToCompleteSet)
				binarySearchResult--;
			p1WinsToCompleteSet = p1WinsToCompleteSet + (binarySearchResult - serve + 1 - t);
			p2WinsToCompleteSet = p2WinsToCompleteSet + t;
		}
        #ifdef debug_on
        if (t==1)
            printf("WinsInSet: %d x %d (SetsWon: %d x %d) [toSet: %d %d] serve = %d\n",player1Victories[binarySearchResult],player2Victories[binarySearchResult],p1SetsCount,p2SetsCount,p1WinsToCompleteSet,p2WinsToCompleteSet,serve);
        #endif
		serve = binarySearchResult + 1;
	}
    #ifdef debug_on
    if (t==1)
        printf("|Result| p1Sets:%d; p2Sets:%d; serve:%d;\n",p1SetsCount,p2SetsCount,serve);
    #endif
	if (serve == n) {
	    if (p1SetsCount > p2SetsCount && player1Victories[n-1] > player1Victories[n-2]) {
			result[*resultsCount][0] = p1SetsCount;
			result[*resultsCount][1] = t;
			*resultsCount = *resultsCount + 1;
		}
	    else if (p2SetsCount > p1SetsCount && player2Victories[n-1] > player2Victories[n-2]) {
			result[*resultsCount][0] = p2SetsCount;
			result[*resultsCount][1] = t;
			*resultsCount = *resultsCount + 1;
		}
	}
}

/* solve the problem */
int main (int argc, char *argv[]) {
	int n, maxServesWon, setsSizeAttempt, resultsCount, loop;
	int serve_winner[MAX_SIZE], player1Victories[MAX_SIZE], player2Victories[MAX_SIZE], result[MAX_SIZE][2];
	#ifdef debug_on
		printf("\nP4 - Tennis Game:\n");
	#endif

	n = readArgs(serve_winner, player1Victories, player2Victories);

	#ifdef debug_on
		printArgs(n,serve_winner,player1Victories,player2Victories);
		printf("\nProblem Solution:\n");
	#endif

	/* solution */
	resultsCount = 0;
	maxServesWon = int_max(player1Victories[n-1], player2Victories[n-1]);

	for (setsSizeAttempt=maxServesWon; setsSizeAttempt>0; setsSizeAttempt--) {
		trySolution(setsSizeAttempt,n,player1Victories,player2Victories,result,&resultsCount);
	}
	merge_sort(0,resultsCount-1,result);
	printf("%d\n",resultsCount);
	for (loop=0; loop<resultsCount; loop++)
		printf("%d %d\n",result[loop][0],result[loop][1]);

	#ifdef debug_on
		printf("\n--------------------\n");
	#endif
	return 0;
}

/*

D. Tennis Game
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output
url: http://codeforces.com/problemset/problem/496/D

Petya and Gena love playing table tennis. A single match is played according to the following rules: a match consists of multiple sets, each set consists of multiple serves. Each serve is won by one of the players, this player scores one point. As soon as one of the players scores t points, he wins the set; then the next set starts and scores of both players are being set to 0. As soon as one of the players wins the total of s sets, he wins the match and the match is over. Here s and t are some positive integer numbers.
To spice it up, Petya and Gena choose new numbers s and t before every match. Besides, for the sake of history they keep a record of each match: that is, for each serve they write down the winner. Serve winners are recorded in the chronological order. In a record the set is over as soon as one of the players scores t points and the match is over as soon as one of the players wins s sets.
Petya and Gena have found a record of an old match. Unfortunately, the sequence of serves in the record isn't divided into sets and numbers s and t for the given match are also lost. The players now wonder what values of s and t might be. Can you determine all the possible options?

Input:
The first line contains a single integer n — the length of the sequence of games (1 ≤ n ≤ 10^5).
The second line contains n space-separated integers ai. If ai = 1, then the i-th serve was won by Petya, if ai = 2, then the i-th serve was won by Gena.
It is not guaranteed that at least one option for numbers s and t corresponds to the given record.

Output:
In the first line print a single number k — the number of options for numbers s and t.
In each of the following k lines print two integers si and ti — the option for numbers s and t. Print the options in the order of increasing si, and for equal si — in the order of increasing ti.

Sample test(s):

Input:
5
1 2 1 2 1
Output:
2
1 3
3 1

Input:
4
1 1 1 1
Output:
3
1 4
2 2
4 1

Input:
4
1 2 1 2
Output:
0

Input:
8
2 1 2 1 1 1 1 1
Output:
3
1 6
2 3
6 1

*/