import java.math.BigInteger;
import java.util.Scanner;

public class ReverseNumber {
    public static void main(final String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int b = sc.nextInt();
        int d = sc.nextInt();
        int waste = 0;
        int count = 0;
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            if (x <= b) {
                waste += x;
            }
            if (waste > d) {
                count++;
                waste = 0;
            }
        }
        System.out.println(count);
    }
}


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

// CodeForces : https://codeforces.com/contest/709/problem/A
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        Problem solver = new Problem();
        solver.solve(1, in, out);
        out.close();
    }

    static class Problem {
        public void solve(int tt, InputReader in, OutputWriter out) {
            int n = in.nextInt();
            int b = in.nextInt();
            int d = in.nextInt();
            int sum = 0;
            int ans = 0;
            for (int i = 0; i < n; i++) {
                int a = in.nextInt();
                if (a <= b) {
                    sum += a;
                }
                if (sum > d) {
                    sum = 0;
                    ans++;
                }
            }
            out.println(ans);
        }
    }

    static class OutputWriter extends PrintWriter {
        public OutputWriter(String fileName) throws FileNotFoundException {
            super(fileName);
        }

        public OutputWriter(OutputStream outputStream) {
            super(outputStream);
        }

        public OutputWriter(Writer writer) {
            super(writer);
        }

    }

    static class InputReader {
        BufferedReader br;
        StringTokenizer in;

        public InputReader(String fileName) {
            try {
                br = new BufferedReader(new FileReader(fileName));
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

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

        boolean hasMoreTokens() {
            while (in == null || !in.hasMoreTokens()) {
                String s = nextLine();
                if (s == null) {
                    return false;
                }
                in = new StringTokenizer(s);
            }
            return true;
        }

        public String nextString() {
            return hasMoreTokens() ? in.nextToken() : null;
        }

        public String nextLine() {
            try {
                in = null;
                return br.readLine();
            } catch (Exception e) {
                e.printStackTrace();
                return null;
            }
        }

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

        public long nextLong() {
            return Long.parseLong(nextString());
        }

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

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

    }
}


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

// CodeForces : https://codeforces.com/contest/709/problem/A
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        Problem solver = new Problem();
        solver.solve(1, in, out);
        out.close();
    }

    static class Problem {
        public void solve(int tt, InputReader in, OutputWriter out) {
            int n = in.nextInt();
            int b = in.nextInt();
            int d = in.nextInt();
            int a[] = new int[n];
            int sum = 0;
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
                if (a[i] < b) {
                    sum += a[i];
                }
            }
            out.println(sum / d);
        }
    }

    static class OutputWriter extends PrintWriter {
        public OutputWriter(String fileName) throws FileNotFoundException {
            super(fileName);
        }

        public OutputWriter(OutputStream outputStream) {
            super(outputStream);
        }

        public OutputWriter(Writer writer) {
            super(writer);
        }

    }

    static class InputReader {
        BufferedReader br;
        StringTokenizer in;

        public InputReader(String fileName) {
            try {
                br = new BufferedReader(new FileReader(fileName));
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

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

        boolean hasMoreTokens() {
            while (in == null || !in.hasMoreTokens()) {
                String s = nextLine();
                if (s == null) {
                    return false;
                }
                in = new StringTokenizer(s);
            }
            return true;
        }

        public String nextString() {
            return hasMoreTokens() ? in.nextToken() : null;
        }

        public String nextLine() {
            try {
                in = null;
                return br.readLine();
            } catch (Exception e) {
                e.printStackTrace();
                return null;
            }
        }

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

        public long nextLong() {
            return Long.parseLong(nextString());
        }

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

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

    }
}


import java.util.*;

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

         int n = sc.nextInt();
         int b = sc.nextInt();
         int d = sc.nextInt();

         int a[] = new int[n];

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

         int count = 0;
         int d1 = d;

         for(int i=0;i<n;i++){
            if(a[i] <= b){
                d1 -= a[i];
                if(d1 < 0){
                    count++;
                    d1 = d;
                }
            }
         }

         System.out.println(count);
     }
}


import java.util.Scanner;

        public class Main {

            public static void main(String[] args) {

                Scanner in=new Scanner(System.in);
                int c=0;
                int d=0;
                int n=in.nextInt();
                int m=in.nextInt();
                int w=in.nextInt();
                int []ar=new int[n];
                for (int i=0;i<n;i++){
                    ar[i]=in.nextInt();
                }
             for (int k=0;k<n;k++){
                 if (ar[k]<m) {
                     c+=ar[k];
                 }
                 if (c>=w){
                     c=c-w;
                    d++;
                 }
             }

                System.out.println(d);
            }
               }


import java.util.Scanner;

        public class Main {

            public static void main(String[] args) {

                Scanner in=new Scanner(System.in);
                int c=0;
                int d=0;
                int n=in.nextInt();
                int m=in.nextInt();
                int w=in.nextInt();
                int []ar=new int[n];
                for (int i=0;i<n;i++){
                    ar[i]=in.nextInt();
                }
             for (int k=0;k<n;k++){
                 if (ar[k]>m) continue;
                  else  c+=ar[k];

                 if (c>=w){
                     c=0;
                    d++;
                 }
             }

                System.out.println(d);
            }
               }


import java.util.Scanner;

        public class Main {

            public static void main(String[] args) {

                Scanner in=new Scanner(System.in);
                int c=0;
                int d=0;
                int n=in.nextInt();
                int m=in.nextInt();
                int w=in.nextInt();
                int []ar=new int[n];
                for (int i=0;i<n;i++){
                    ar[i]=in.nextInt();
                    if (ar[i]>m) continue;
                    else  c+=ar[i];
                    if (c>=w){
                        c=0;
                        d++;
                    }

                }

                System.out.println(d);
            }
               }


import java.util.Scanner;

        public class Main {

            public static void main(String[] args) {

                Scanner in=new Scanner(System.in);
                int c=0;
                int d=0;
                int n=in.nextInt();
                int m=in.nextInt();
                int w=in.nextInt();
                int []ar=new int[n];
                for (int i=0;i<n;++i){
                    ar[i]=in.nextInt();
                    if (ar[i]>m) continue;
                    else  c+=ar[i];
                    if (c>w){
                        c=0;
                        d++;
                    }

                }

                System.out.println(d);
            }
               }


import java.util.Scanner;

        public class Main {

            public static void main(String[] args) {

                Scanner in=new Scanner(System.in);
                int c=0;
                int d=0;
                int n=in.nextInt();
                int m=in.nextInt();
                int w=in.nextInt();
                int []ar=new int[n];
                for (int i=0;i<n;i++){
                    ar[i]=in.nextInt();
                }
             for (int k=0;k<n;k++){
                 if (ar[k]<m) {
                     c+=ar[k];
                 }
                 if (c>=w){
                     c=0;
                    d++;
                 }
             }

                System.out.println(d);
            }
               }


import java.util.Scanner;

        public class Main {

            public static void main(String[] args) {

                Scanner in=new Scanner(System.in);
                int c=0;
                int n=in.nextInt();
                int m=in.nextInt();
                int w=in.nextInt();
                int []ar=new int[n];
                for (int i=0;i<n;i++){
                    ar[i]=in.nextInt();
                }
             for (int k=0;k<n;k++){
                 if (ar[k]<m) {
                     c+=ar[k];
                 }
             }
                int a=c-(c%w);
             int b=a/w;

                System.out.println(b);
            }
               }


import java.util.Scanner;

        public class Main {

            public static void main(String[] args) {

                Scanner in=new Scanner(System.in);
                int c=0;
                int d=0;
                int n=in.nextInt();
                int m=in.nextInt();
                int w=in.nextInt();
                int []ar=new int[n];
                for (int i=0;i<n;++i){
                    ar[i]=in.nextInt();
                    if (ar[i]>m) continue;
                    else  c+=ar[i];
                    if (c>=w){
                        c=0;
                        d++;
                    }

                }

                System.out.println(d);
            }
               }


import java.util.*;
public class problem1372A25 {
    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int t = sc.nextInt();
        while (t > 0) {
            int n = sc.nextInt();
            int b=sc.nextInt();
            int d=sc.nextInt();
           int[] arr=new int[n];
            for (int i = 0; i <n ; i++)
           arr[i]=sc.nextInt();
            int c=0,sum=0;
            for (int i = 0; i <n ; i++) {
                if(arr[i]<=b)
                {
                    if(sum<=d)
                        sum+=arr[i];
                    else {
                        c++;
                        sum=0;
                    }
                }
            }
            System.out.println(c);

            t--;
        }
    }
}


import java.util.*;
public class problem1372A25 {
    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
//        int t = sc.nextInt();
//        while (t > 0) {
            int n = sc.nextInt();
            int b=sc.nextInt();
            int d=sc.nextInt();
           int[] arr=new int[n];
            for (int i = 0; i <n ; i++)
           arr[i]=sc.nextInt();
            int c=0,sum=0;
            for (int i = 0; i <n ; i++) {
                if(arr[i]<=b)
                {
                    if(sum+arr[i]<=d)
                        sum+=arr[i];
                    else {
                        c++;
                        sum=0;
                    }
                }
            }
            System.out.println(c);

//            t--;
//        }
    }
}


import java.util.*;
public class problem1372A25 {
    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
//        int t = sc.nextInt();
//        while (t > 0) {
            int n = sc.nextInt();
            int b=sc.nextInt();
            int d=sc.nextInt();
           int[] arr=new int[n];
            for (int i = 0; i <n ; i++)
           arr[i]=sc.nextInt();
            int c=0,sum=0;
            for (int i = 0; i <n ; i++) {
                if(arr[i]<=b)
                {
                    if(sum<=d)
                        sum+=arr[i];
                    else {
                        c++;
                        sum=0;
                    }
                }
            }
            System.out.println(c);

//            t--;
//        }
    }
}


import java.util.Scanner;

public class test {
    public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int n = in.nextInt(),b = in.nextInt() ,d = in.nextInt();
    int waste = 0;
    int fict = 0;
        for (int i = 0; i < n; i++)
        {
            int a = in.nextInt();
            if (a>b)continue;
            else
                {
                    waste += a;
                    if (waste>d)
                    {
                        fict++;
                        waste = 0;

                    }
                }

        }
        System.out.println(fict);

    }

}


// https://codeforces.com/contest/725/submission/68385647
import java.math.*;
import java.util.*;
import java.io.*;

public class A {

    static BufferedReader in;
    static String file = "../in";

    public static void main(String[] args) throws Exception
    {
        int test = 10,   // 0 for local testing, 1 for std input
            _k = Integer.valueOf("1");
        if(test > 0) in = new BufferedReader(new InputStreamReader(System.in));
        else in = new BufferedReader(new FileReader(file));
        if(test < 0) {String[] str = in.readLine().split(" ");}

        /****************************************************/
        /****************************************************/
        /****************************************************/
        /****************************************************/

        // int n = Integer.valueOf(in.readLine());
        String[] sp = in.readLine().split(" ");
        int n = Integer.valueOf(sp[0]),
            b = Integer.valueOf(sp[1]),
            d = Integer.valueOf(sp[2]);
        sp = in.readLine().split(" ");

        int cap = 0;
        int count = 0;
        for(int i = 0; i < n; i++)
        {
            int orange = Integer.valueOf(sp[i]);
            if(orange > b) continue;
            cap += orange;
            if(cap > d)
            {
                count++;
                cap = 0;
            }
        }

        System.out.println(count);

    }
}


// https://codeforces.com/contest/725/submission/68385647
import java.math.*;
import java.util.*;
import java.io.*;

public class A {

    static BufferedReader in;
    static String file = "../in";

    public static void main(String[] args) throws Exception
    {
        int test = 10,   // 0 for local testing, 1 for std input
            _k = Integer.valueOf("1");
        if(test > 0) in = new BufferedReader(new InputStreamReader(System.in));
        else in = new BufferedReader(new FileReader(file));
        if(test < 0) {String[] str = in.readLine().split(" ");}

        /****************************************************/
        /****************************************************/
        /****************************************************/
        /****************************************************/

        // int n = Integer.valueOf(in.readLine());
        String[] sp = in.readLine().split(" ");
        int n = Integer.valueOf(sp[0]),
            b = Integer.valueOf(sp[1]),
            d = Integer.valueOf(sp[2]);
        sp = in.readLine().split(" ");

        int cap = 0;
        int count = 0;
        for(int i = 0; i < n; i++)
        {
            int orange = Integer.valueOf(sp[i]);
            if(orange > b) continue;
            cap += orange;
            if(cap > d)
            {
                count++;
                cap %= d;
            }
        }

        System.out.println(count);

    }
}


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

        int n = s.nextInt();
        int maxSize = s.nextInt();
        int maxWaste = s.nextInt();

        int numRemovals = 0;
        int currWaste = 0;
        for (int i = 0; i < n; i++) {
            int orange = s.nextInt();

            if (orange < maxSize) {
                if (currWaste + orange >= maxWaste) {
                    currWaste = 0;
                    numRemovals++;
                }
                currWaste += orange;
            }
        }
        System.out.println(numRemovals);
	}
}


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

        int n = s.nextInt();
        int maxSize = s.nextInt();
        int maxWaste = s.nextInt();

        int numRemovals = 0;
        int currWaste = 0;
        for (int i = 0; i < n; i++) {
            int orange = s.nextInt();

            if (orange < maxSize) {

                currWaste += orange;
                if (currWaste > maxWaste) {
                    currWaste = 0;
                    numRemovals++;
                }
            }
        }
        System.out.println(numRemovals);
	}
}


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

        int n = s.nextInt();
        int maxSize = s.nextInt();
        int maxWaste = s.nextInt();

        int numRemovals = 0;
        int currWaste = 0;
        for (int i = 0; i < n; i++) {
            int orange = s.nextInt();

            if (orange <= maxSize) {

                currWaste += orange;
                if (currWaste > maxWaste) {
                    currWaste = 0;
                    numRemovals++;
                }
            }
        }
        System.out.println(numRemovals);
	}
}


import java.util.Scanner;

public class Mango {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int v = sc.nextInt();
        int w = sc.nextInt();
        int sum = 0;
        int c =0;
        int[] x = new int[n];
        for (int i = 0; i < n; i++) {
            x[i] = sc.nextInt();
        if(x[i] > v){
        continue;
        }
        else{
        sum += x[i];
        if(sum > w){
        ++c;
        sum = 0;
        }
        }
        }
        System.out.println(c);
    }
}


import java.util.Scanner;

public class Mango {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int v = sc.nextInt();
        int w = sc.nextInt();
        int sum = 0;
        int c ;
        int[] x = new int[n];
        for (int i = 0; i < n; i++) {
            x[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            if (x[i] <= v) {
                sum = sum + x[i];
            }
        }
        if (sum == w || sum < w) {
            System.out.println("0");
        } else {
            c = sum / w;
            System.out.println(c);
        }
    }
}


import java.util.Scanner;

public class Mango {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int v = sc.nextInt();
        int w = sc.nextInt();
        int sum = 0;
        int c ;
        int[] x = new int[n];
        for (int i = 0; i < n; i++) {
            x[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            if (x[i] < v) {
                sum = sum + x[i];
            }
        }
        if (sum == w) {
            System.out.println("0");
        } else {
            c = sum / w;
            System.out.println(c);
        }
    }
}


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);

		int n = in.nextInt();
		int b = in.nextInt();
		int d = in.nextInt();

		int arr[] = new int[n];

		long sum = 0;
		int numberOfRecycle = 0;
		for(int i = 0; i < arr.length ; i++) {
			arr[i] = in.nextInt();

			if(arr[i] <= b) {

				sum += arr[i];

				if(sum > d) {
					sum -= d;
					numberOfRecycle++;

				}

			}

		}
		System.out.println(numberOfRecycle);

	}
}


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);

		int n = in.nextInt();
		int b = in.nextInt();
		int d = in.nextInt();

		int arr[] = new int[n];

		int sum = 0;
		int numberOfRecycle = 0;
		for(int i = 0; i < arr.length ; i++) {
			arr[i] = in.nextInt();

			if(arr[i] < b) {

				sum += arr[i];

				if(sum > d) {
					sum -= d;
					numberOfRecycle++;

				}

			}

		}
		System.out.println(numberOfRecycle);

	}
}


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);

		int n = in.nextInt();
		int b = in.nextInt();
		int d = in.nextInt();

		int arr[] = new int[n];

		long sum = 0;
		int numberOfRecycle = 0;
		for(int i = 0; i < arr.length ; i++) {
			arr[i] = in.nextInt();

			if(arr[i] <= b) {

				sum += arr[i];

				if(sum > d) {
					sum = 0;
					numberOfRecycle++;

				}

			}

		}
		System.out.println(numberOfRecycle);

	}
}


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);

		int n = in.nextInt();
		int b = in.nextInt();
		int d = in.nextInt();

		int arr[] = new int[n];

		long sum = 0;
		int numberOfRecycle = 0;
		for(int i = 0; i < arr.length ; i++) {
			arr[i] = in.nextInt();

			if(arr[i] < b) {

				sum += arr[i];

				if(sum > d) {
					sum -= d;
					numberOfRecycle++;

				}

			}

		}
		System.out.println(numberOfRecycle);

	}
}


import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int b = scanner.nextInt();
        int d = scanner.nextInt();
        int ans = 0;
        int sum = 0;
        for (int i = 0; i < n; i++) {
            int a = scanner.nextInt();
            if (a <= b) {
                sum += a;
                if (sum > d) {
                    ans += 1;
                    sum = 0;
                }
            }
        }
        System.out.println(ans);
    }

}


//package com.company;

import java.util.Scanner;

public class Main {

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

        long n=in.nextLong();
        long b=in.nextLong();
        long d=in.nextLong();
        long a[]=new long[(int) n];
        long count=0;
        long sum=0;
        for (int i = 0; i <n ; i++) {
            a[i]=in.nextInt();
            if(a[i]<b) sum+=a[i];
            if(sum>d){
                sum=0;
                count++;
            }
        }
        System.out.println(count);

    }
}


//package com.company;

import java.util.Scanner;

public class Main {

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

        int n=in.nextInt();
        int b=in.nextInt();
        int d=in.nextInt();
        int a[]=new int[n];
        int count=0;
        int sum=0;
        for (int i = 0; i <n ; i++) {
            a[i]=in.nextInt();
            if(a[i]<b) sum+=a[i];
            if(sum>d){
                sum=0;
                count++;
            }
        }
        System.out.println(count);

    }
}


//package com.company;

import java.util.Scanner;

public class Main {

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

        long n=in.nextLong();
        long b=in.nextLong();
        long d=in.nextLong();
        long a[]=new long[(int) n];
        long count=0;
        long sum=0;
        for (int i = 0; i <n ; i++) {
            a[i]=in.nextInt();
            if(a[i]<=b) sum+=a[i];
            if(sum>d){
                sum=0;
                count++;
            }
        }
        System.out.println(count);

    }
}


import java.util.Scanner;

public class JavaApplication16 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();    //2
        int arr [] = new int [n];
        int b = sc.nextInt();    //7
        int d = sc.nextInt();    //10
        int cont = 0 , w ,a;

        for ( int i = 0 ; i < n ; i++){
              arr[i] =sc.nextInt() ;  // 5 6
        }
        for ( int i = 0 ; i < arr.length ; i++){
            if (arr [i] > b)
                continue ;
            else
                cont += arr[i];     //11
        }
        if (cont > d)
            w = cont / d;
        else w =0 ;
        System.out.println(w);
    }

    }


package javaapplication16;

import java.util.Scanner;

public class JavaApplication16 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();    //2
        int arr [] = new int [n];
        int b = sc.nextInt();    //7
        int d = sc.nextInt();    //10
        int cont = 0 , w ,a;

        for ( int i = 0 ; i < n ; i++){
              arr[i] =sc.nextInt() ;  // 5 6
        }
        for ( int i = 0 ; i < arr.length ; i++){
            if (arr [i] > b)
                continue ;
            else
                cont += arr[i];     //11
        }
        if (cont > d)
            w = cont / d;
        else w =0 ;
        System.out.println(w);
    }

    }


import java.util.Scanner;

public class JavaApplication16 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();    //2
        int arr [] = new int [n];
        int b = sc.nextInt();    //7
        int d = sc.nextInt();    //10
        long cont = 0 , w=0 ,a;

        for ( int i = 0 ; i < n ; i++){
              arr[i] =sc.nextInt() ;  // 5 6
        }
        for ( int i = 0 ; i < arr.length ; i++){
            if (arr [i] > b)
                continue ;
            else
                cont += arr[i];     //3245325
        }
        if (cont > d)
            w = cont / d;
        else w = 0 ;
        System.out.println(w);
    }

    }


import java.util.Scanner;

public class JavaApplication16 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();    //2
        int arr [] = new int [n];
        int b = sc.nextInt();    //7
        int d = sc.nextInt();    //10
        long cont = 0 , w=0 ,a;

        for ( int i = 0 ; i < n ; i++){
              arr[i] =sc.nextInt() ;  // 5 6
        }
        for ( int i = 0 ; i < arr.length ; i++){
            if (arr [i] > b)
                continue ;
            else
                cont += arr[i];

        if (cont > d){
            cont = 0 ;
            w++ ;
        }
    }
        System.out.println(w);
    }

    }


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int b = sc.nextInt();
        int d = sc.nextInt();

        int c=0,res=0;
        for (int i = 0; i < n; i++) {
            int o = sc.nextInt();
            if (o <= b) {
                c+=o;
                if(c>=d){res++;
                c=0;}
            }
        }
        System.out.println(res);
    }
}


package com.company;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int b = sc.nextInt();
        int d = sc.nextInt();

        int c=0,res=0;
        for (int i = 0; i < n; i++) {
            int o = sc.nextInt();
            if (o <= b) {
                c+=o;
                if(c>d){res++;
                c=0;}
            }
        }
        System.out.println(res);
    }
}


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int b = sc.nextInt();
        int d = sc.nextInt();

        int c=0,res=0;
        for (int i = 0; i < n; i++) {
            int o = sc.nextInt();
            if (o <= b) {
                c+=o;
                if(c>d){res++;
                c=0;}
            }
        }
        System.out.println(res);
    }
}


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

public class Main {
    public static void main(String args[]) throws IOException {
        Scanner scan = new Scanner(System.in);
        PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        int num = scan.nextInt();
        int max = scan.nextInt();
        int maxWaste = scan.nextInt();
        int ans = 0, waste = 0;
        while (num-- > 0) {
            int o = scan.nextInt();
            if (o <= max) {
                waste += o;
            }
            while (waste > maxWaste) {
                ans++;
                waste -= maxWaste;
            }
        }
        out.println(ans);

        out.close();
    }
}


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

public class Main {
    public static void main(String args[]) throws IOException {
        Scanner scan = new Scanner(System.in);
        PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        int num = scan.nextInt();
        int max = scan.nextInt();
        int maxWaste = scan.nextInt();
        int ans = 0, waste = 0;
        while (num-- > 0) {
            int o = scan.nextInt();
            if (o <= max) {
                waste += o;
            }
            while (waste > maxWaste) {
                ans++;
                waste = 0;
            }
        }
        out.println(ans);

        out.close();
    }
}


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

public class Main {
    public static void main(String args[]) throws IOException {
        Scanner scan = new Scanner(System.in);
        PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        int num = scan.nextInt();
        int max = scan.nextInt();
        int maxWaste = scan.nextInt();
        int ans = 0, waste = 0;
        while (num-- > 0) {
            int o = scan.nextInt();
            if (o <= max) {
                waste += o;
            }
            while (waste > maxWaste) {
                ans++;
                waste -= 10;
            }
        }
        out.println(ans);

        out.close();
    }
}


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

public class Main {
    public static void main(String args[]) throws IOException {
        Scanner scan = new Scanner(System.in);
        PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        int num = scan.nextInt();
        int max = scan.nextInt();
        int maxWaste = scan.nextInt();
        int ans = 0, waste = 0;
        while (num-- > 0) {
            int o = scan.nextInt();
            if (o <= max) {
                waste += o;
            }
            if (waste > maxWaste) {
                ans++;
                waste -= 10;
            }
        }
        out.println(ans);

        out.close();
    }
}


import java.util.Arrays;
import java.util.Scanner;

public class Pp {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in) ;
		//number of oranges , the max. size of juicer ,empty indicator

		int n = in.nextInt() , b = in.nextInt() , d = in.nextInt() ;
		int [] sizes = new int [n] ;
		for (int i = 0; i < sizes.length; i++) {
			sizes[i]=in.nextInt() ;
		}
		sizes=check(sizes, b);
		// temp var
		int c = 0 ,counter = 0 ;
		for (int i = 0; i < sizes.length; i++) {
			c = c +sizes[i] ;
			if( c>=d) {
				counter++;
				c = 0 ;
			}
		}
		System.out.println(counter);
	}

	public static int [] check(int [] array , int max) {
		for (int i = 0; i < array.length; i++) {
			if (array[i] < max)
				continue ;
			else
				array[i]=0;
		}
		return array ;
	}
}


import java.util.Arrays;
import java.util.Scanner;

public class Pp {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in) ;
		//number of oranges , the max. size of juicer ,empty indicator

		int n = in.nextInt() , b = in.nextInt() , d = in.nextInt() ;
		int [] sizes = new int [n] ;
		int sum = 0 ,counter = 0 ;
		for (int i = 0; i < sizes.length; i++) {
			sizes[i]=in.nextInt() ;
			if(sizes[i]>b)
			{
				continue;
			}
			sum +=sizes[i] ;
			if( sum > d) {
				++counter ;
				sum = 0 ;
			}
		}
		System.out.println(counter);
	}
}


import java.util.Arrays;
import java.util.Scanner;

public class Pp {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in) ;
		//number of oranges , the max. size of juicer ,empty indicator

		int n = in.nextInt() , b = in.nextInt() , d = in.nextInt() ;
		int [] sizes = new int [n] ;
		for (int i = 0; i < sizes.length; i++) {
			sizes[i]=in.nextInt() ;
		}
		sizes=check(sizes, b);
		// temp var
		int c = 0 ,counter = 0 ;
		for (int i = 0; i < sizes.length; i++) {
			c +=sizes[i] ;
			if( c >=d ) {
				counter++;
				c = 0 ;
			}
			else
			{
				if(i==sizes.length-1 && (c>0 && c<d))
				{
					counter ++;
				}
			}
		}
		System.out.println(counter);
	}

	public static int [] check(int [] array , int max) {
		for (int i = 0; i < array.length; i++) {
			if (array[i] < max)
				continue ;
			else
				array[i]=0;
		}
		return array ;
	}
}


import java.util.Scanner;

public class Juicer {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(); //number of oranges
        int b = sc.nextInt(); //juicers limit
        int d = sc.nextInt(); //waste sections limit
        int orange = 0;
        int juicer = 0;
        int res = 0;

        for (int i = 0; i < n; i++) {
            orange = sc.nextInt();
            if (orange <= b)
                juicer += orange;
            if (juicer > d) {
                res++;
                juicer = 0;
            }

        }
        System.out.println(res);
        sc.close();
    }
}


import java.util.*;
public class p38 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in  = new Scanner(System.in);
		int n = in.nextInt();
		int b = in.nextInt();
		int d = in.nextInt();
		int c=0;
		int sum = 0 ;
//		int []a= new int[n];
		for (int i = 0; i < n; i++) {
//			a[i]=in.nextInt();
			int x = in.nextInt();
			if(x<b) {
				sum+=x;
			}
			if (sum>=d) {
				c++;
				sum=0;
			}

		}
		System.out.println(c);

	}

}


import java.util.*;
public class p38 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in  = new Scanner(System.in);
		int n = in.nextInt();
		int b = in.nextInt();
		int d = in.nextInt();
		int c=0;
		int sum = 0 ;
		for (int i = 0; i < n; i++) {
			int x = in.nextInt();
			if(x<=b) {
				sum+=x;
			}
			if (sum>d) {
				c++;
				sum=0;
			}

		}
		System.out.println(c);

	}

}


import java.util.*;
public class Learning2 {
 public static void main(String[] args) {
	 Scanner input = new Scanner(System.in);
	 int n = input.nextInt();
	 int b = input.nextInt();
	 int d = input.nextInt();
	 int[] oranges = new int[n];
	 int sum = 0;
	 int emptyingCounter = 0;
	 for(int i=0 ; i<n ; i++){
		 oranges[i] = input.nextInt();

		 if(oranges[i] <= b)
		   sum += oranges[i];
	 }
	 while(sum >= d){
		 sum -= d;
		 emptyingCounter++;
	 }
	 System.out.println(emptyingCounter);
 }
}


import java.util.*;
public class Learning2 {
 public static void main(String[] args) {
	 Scanner input = new Scanner(System.in);
	 int n = input.nextInt();
	 int b = input.nextInt();
	 int d = input.nextInt();
	 int[] oranges = new int[n];
	long int sum = 0;
	 int emptyingCounter = 0;
	 for(int i=0 ; i<n ; i++){
		 oranges[i] = input.nextInt();

		 if(oranges[i] <= b)
		   sum += oranges[i];
	 }
	 while(sum > d){
		 sum -= d;
		 emptyingCounter++;
	 }
	 System.out.println(emptyingCounter);
 }
}


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int b = input.nextInt();
        int d = input.nextInt();
        int collect = 0;
        int throwTimes = 0;
        for (int i = 0; i < n; i++){
            int orangeSize = input.nextInt();
            if(orangeSize > b){
                continue;
            }
            collect += orangeSize;
            if(collect > d){
                throwTimes++;
                collect = 0;
            }
        }
        System.out.println(throwTimes);
    }
}


import java.util.*;
public class Learning2 {
 public static void main(String[] args) {
	 Scanner input = new Scanner(System.in);
	 int n = input.nextInt();
	 int b = input.nextInt();
	 int d = input.nextInt();
	 int[] oranges = new int[n];
	 int sum = 0;
	 int emptyingCounter = 0;
	 for(int i=0 ; i<n ; i++){
		 oranges[i] = input.nextInt();

		 if(oranges[i] <= b)
		   sum += oranges[i];
	 }
	 while(sum > d){
		 sum -= d;
		 emptyingCounter++;
	 }
	 System.out.println(emptyingCounter);
 }
}


import java.util.*;
public class Learning2 {
 public static void main(String[] args) {
	 Scanner input = new Scanner(System.in);
	 int n = input.nextInt();
	 int b = input.nextInt();
	 int d = input.nextInt();
	 int[] oranges = new int[n];
	 long sum = 0;
	 int emptyingCounter = 0;
	 for(int i=0 ; i<n ; i++){
		 oranges[i] = input.nextInt();

		 if(oranges[i] <= b)
		   sum += oranges[i];
	 }
	 while(sum > d){
		 sum -= d;
		 emptyingCounter++;
	 }
	 System.out.println(emptyingCounter);
 }
}


#include <iostream>
#include <cstring>
#include <string>
using namespace std;

int main()
{
    long unsigned int n , b ,d ,w=0 , counter = 0;
    cin >> n >> b >> d;
    long unsigned int arr[n];
    for (int x = 0; x < n; x++)
        cin >> arr[x];
    for (int x = 0; x < n; x++){
        if (arr[x] < b)
            w = w + arr[x];
        if (w >= d){
          w = 0;
          counter++;
        }
    }
cout << counter;
    return 0;
}


#include <iostream>
#include <cstring>
#include <string>
using namespace std;

int main()
{
    long unsigned int n , b ,d ,w=0 , counter = 0;
    cin >> n >> b >> d;
    long unsigned int arr[n];
    for (int x = 0; x < n; x++)
        cin >> arr[x];
    for (int x = 0; x < n; x++){
        if (arr[x] < b)
            w = w + arr[x];
        if (w >= d){
          w = 0;
          counter++;
        }
    }
cout <<  counter;
    return 0;
}


#include <iostream>
#include <cstring>
#include <string>
using namespace std;

int main()
{
    int n , b ,d ,w=0;
    cin >> n >> b >> d;
    int arr[n];
    for (int x = 0; x < n; x++)
        cin >> arr[x];
    for (int x = 0; x < n; x++){
        if (arr[x] < b){
            w+=arr[x];
        }
    }
cout << w/d;
    return 0;
}


#include<iostream>
#include<string>
#include<cmath>
using namespace std;

int main()
{
    long long n , b ,d ,w=0 , counter = 0;
    cin >> n >> b >> d;
    long  long arr[n];
    for (int x = 0; x < n; x++)
        cin >> arr[x];
    for (int x = 0; x < n; x++){
        if (arr[x] <= b)
            w = w + arr[x];
        if (w >= d){
          w = 0;
          counter++;
        }
    }
cout <<  counter;
    return 0;
}


#include<iostream>
#include<string>
#include<cmath>
using namespace std;

int main()
{
    long long n , b ,d ,w=0 , counter = 0;
    cin >> n >> b >> d;
    long  long arr[n];
    for (int x = 0; x < n; x++)
        cin >> arr[x];
    for (int x = 0; x < n; x++){
        if (arr[x] <= b)
            w = w + arr[x];
        if (w > d){
          w = 0;
          counter++;
        }
    }
cout <<  counter;
    return 0;
}


#include <iostream>
#include <cstring>
#include <string>
using namespace std;

int main()
{
    long int n , b ,d ,w=0;
    cin >> n >> b >> d;
    int arr[n];
    for (int x = 0; x < n; x++)
        cin >> arr[x];
    for (int x = 0; x < n; x++){
        if (arr[x] < b)
            w = w + arr[x];
    }
cout << w/d;
    return 0;
}


#include <iostream>
#include <cstring>
#include <string>
using namespace std;

int main()
{
    unsigned int n , b ,d ,w=0;
    cin >> n >> b >> d;
    unsigned int arr[n];
    for (int x = 0; x < n; x++)
        cin >> arr[x];
    for (int x = 0; x < n; x++){
        if (arr[x] < b)
            w = w + arr[x];
    }
cout << w/d;
    return 0;
}


#include<iostream>
#include<string>
using namespace std;
int main()
{
    int n,b,d,a,s1=0,s2=0;
    cin>>n>>b>>d;
    while(n--)
    {
        cin>>a;
        if(a<b)
        {
            s1+=a;
            if(s1>d)
            {
                s2++;
                s1=0;
            }
        }
    }
    cout<<s2;
    return 0;
}


#include<iostream>
#include<string>
using namespace std;
int main()
{
    int n,b,d,a,s1=0,s2=0;
    cin>>n>>b>>d;
    while(n--)
    {
        cin>>a;
        if(a<b)
        {
            s1+=a;
            if(s1>d)
            {
                s2++;
                s1=s1-(s1-d);
            }
        }
    }
    cout<<s2;
    return 0;
}


#include<iostream>
#include<string>
using namespace std;
int main()
{
    int n,s2=0;
    long int b,d,a,s1=0;
    cin>>n>>b>>d;
    while(n--)
    {
        cin>>a;
        if(a<b)
        {
            s1+=a;
            if(s1>d)
            {
                s2++;
                s1=0;
            }
        }
    }
    cout<<s2;
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    long long n,b,d,a,s=0,c=0;
    cin>>n>>b>>d;
    while(n--)
    {
        cin>>a;
        if(a<b)
        {
            s+=a;
            if(s>d)
            {
                c++;
                s=0;
            }
        }
    }
    cout<<c;
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    long long n,b,d,a,s=0,c=0;
    cin>>n>>b>>d;
    while(n--)
    {
        cin>>a;
        if(a<=b)
        {
            s+=a;
            if(s>d)
            {
                c++;
                s=0;
            }
        }
    }
    cout<<c;
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int n;
    long int b,d,a,s=0,c=0;
    cin>>n>>b>>d;
    while(n--)
    {
        cin>>a;
        if(a<b)
        {
            s+=a;
            if(s>d)
            {
                c++;
                s=0;
            }
        }
    }
    cout<<c;
    return 0;
}


#include<iostream>
#include<string>
using namespace std;
int main()
{
    int n,a,s2=0;
    long int b,d,a,s1=0;
    cin>>n>>b>>d;
    while(n--)
    {
        cin>>a;
        if(a<b)
        {
            s1+=a;
            if(s1>d)
            {
                s2++;
                s1=0;
            }
        }
    }
    cout<<s2;
    return 0;
}


#include<iostream>
#include<string>
using namespace std;
int main()
{
    int n,s2=0;
    long int b,d,a,s1=0;
    cin>>n>>b>>d;
    while(n--)
    {
        cin>>a;
        if(a<b)
        {
            s1+=a;
            if(s1>d)
            {
                s2++;
                s1=s1-(s1-d);
            }
        }
    }
    cout<<s2;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n,b,d;
    long long a[100005],c=0,x;
    cin>>n>>b>>d;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]<=b)c+=a[i];
    }
    if(c==0||c==d)cout<<0<<endl;
    x=c/d;
    else cout<<x<<endl;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n,b,d,a[100005],c=0;
    cin>>n>>b>>d;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]<=b)c+=a[i];
    }
    cout<<c/d<<endl;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n,b,d;
    long long a[100005],c=0;
    cin>>n>>b>>d;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]<=b)c+=a[i];
    }
    if(c==0||c==d)cout<<0<<endl;
    else cout<<c/d<<endl;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n,b,d,a[100005],c=0;
    cin>>n>>b>>d;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]<=b)c+=a[i];
    }
    if(c==0||c==d)cout<<0<<endl;
    else cout<<c/d<<endl;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    long long n,b,d;
    long long a[100005],c=0,k=0;
    cin>>n>>b>>d;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]<=b)c+=a[i];
        if(c>=d){k++; c%=d;}
    }
    //x=c/d;
    if(c==0||c==d)cout<<0<<endl;
    else cout<<k<<endl;
    return 0;
}


/*#include <iostream>

using namespace std;

int main()
{
    long long n,b,d;
    long long a[100005],c=0,k=0;
    cin>>n>>b>>d;
    for(int i=0;i<n;i++){
        cin>>a[i];

        if(a[i]<=b){c+=a[i];
        if(c>d){k++; c=0;}
        }
    }
    cout<<k<<endl;
    return 0;
}
*/

#include <iostream>

using namespace std;

int main()
{
    long long n,b,d;
    long long a[100005],c=0,k=0;
    cin>>n>>b>>d;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]<=b){c+=a[i];
        if(c>d){k++; c=0;}}
    }

    //if(c==0||c==d)cout<<0<<endl;
    //else
        cout<<k<<endl;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    long long n,b,d;
    long long a[100005],c=0,k=0;
    cin>>n>>b>>d;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]<=b){c+=a[i];
        if(c>d){k++; c%=d;}}
    }

    if(c==0||c==d)cout<<0<<endl;
    else cout<<k<<endl;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    long long n,b,d;
    long long a[100005],c=0,x;
    cin>>n>>b>>d;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]<=b)c+=a[i];
    }
    x=c/d;
    if(c==0||c==d)cout<<0<<endl;
    else cout<<x<<endl;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n,b,d;
    long long a[100005],c=0,x;
    cin>>n>>b>>d;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]<=b)c+=a[i];
    }
    x=c/d;
    if(c==0||c==d)cout<<0<<endl;
    else cout<<x<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define nn 5009
#define ll long long
vector<int> to[nn];
int n;int m;int more[nn];int maxi;
int main()
{
	scanf("%d%d",&n,&m);
	while(m--)
	{
		int x,y;scanf("%d%d",&x,&y);
		x--,y--;
		to[x].push_back(y);
	}
	for(int i=0;i<n;i++) maxi=max(maxi,(int)to[i].size());
	for(int i=0;i<n;i++)
	{

		more[i]=1e9;
		for(int j=0;j<to[i].size();j++)
			more[i]=min(more[i],(to[i][j]-i+n)%n);
	}
	ll bas=maxi-1;bas*=n;
	for(int st=0;st<n;st++)
	{
		ll ans=0;
		int p=0;
		for(int i=st;!(p and i==st);i=(i+1)%n,p=1)
		{
			int t=to[i].size();
			if(t)
			ans=max(ans,(t-1ll)*n+more[i]+(i-st+n)%n);
		}
		printf("%lld ",ans);
	}
}


#include<bits/stdc++.h>
using namespace std;
#define nn 5009
#define ll long long
vector<int> to[nn];
int n;int m;int more[nn];int maxi;
int main()
{
	scanf("%d%d",&n,&m);
	while(m--)
	{
		int x,y;scanf("%d%d",&x,&y);
		x--,y--;
		to[x].push_back(y);
	}
	for(int i=0;i<n;i++) maxi=max(maxi,(int)to[i].size());
	for(int i=0;i<n;i++)
	{

		more[i]=1e9;
		for(int j=0;j<to[i].size();j++)
			more[i]=min(more[i],(to[i][j]-i+n)%n);
	}
	ll bas=maxi-1;bas*=n;
	for(int st=0;st<n;st++)
	{
		int ans=0;
		int p=0;
		for(int i=st;!(p and i==st);i=(i+1)%n,p=1)
		{
			ans=max(ans,(int)((int)to[i].size()-1)*n+more[i]+(i-st+n)%n);
		}
		printf("%d ",ans);
	}
}


#include<bits/stdc++.h>
using namespace std;
#define nn 5009
#define ll long long
vector<int> to[nn];
int n;int m;int more[nn];int maxi;
int main()
{
	scanf("%d%d",&n,&m);
	while(m--)
	{
		int x,y;scanf("%d%d",&x,&y);
		x--,y--;
		to[x].push_back(y);
	}
	for(int i=0;i<n;i++) maxi=max(maxi,(int)to[i].size());
	for(int i=0;i<n;i++)
	{

		more[i]=1e9;
		for(int j=0;j<to[i].size();j++)
			more[i]=min(more[i],(to[i][j]-i+n)%n);
	}
	ll bas=maxi-1;bas*=n;
	for(int st=0;st<n;st++)
	{
		int ans=0;
		int p=0;
		for(int i=st;!(p and i==st);i=(i+1)%n,p=1)
		{
			if(to[i].size())
				ans=max(ans,(int)((int)to[i].size()-1)*n+more[i]+(i-st+n)%n);
		}
		printf("%lld ",ans);
	}
}


#include<bits/stdc++.h>
using namespace std;
#define nn 5009
#define ll long long
vector<int> to[nn];
int n;int m;int more[nn];int maxi;
int main()
{
	scanf("%d%d",&n,&m);
	while(m--)
	{
		int x,y;scanf("%d%d",&x,&y);
		x--,y--;
		to[x].push_back(y);
	}
	for(int i=0;i<n;i++) maxi=max(maxi,(int)to[i].size());
	for(int i=0;i<n;i++)
	{

		more[i]=1e9;
		for(int j=0;j<to[i].size();j++)
			more[i]=min(more[i],(to[i][j]-i+n)%n);
	}
	ll bas=maxi-1;bas*=n;
	for(int st=0;st<n;st++)
	{
		int ans=0;
		int p=0;
		for(int i=st;!(p and i==st);i=(i+1)%n,p=1)
		{
			if(to[i].size())
				ans=max(ans,(int)(to[i].size()-1)*n+more[i]+(i-st+n)%n);
		}
		printf("%lld ",ans);
	}
}


#include<bits/stdc++.h>
using namespace std;
#define nn 5003
#define ll long long
vector<int> to[nn];
int n;int m;int more[nn];int maxi;
int main()
{
	scanf("%d%d",&n,&m);
	while(m--)
	{
		int x,y;scanf("%d%d",&x,&y);
		x--,y--;
		to[x].push_back(y);
	}
	for(int i=0;i<n;i++) maxi=max(maxi,(int)to[i].size());
	for(int i=0;i<n;i++)
	{
		if(maxi==to[i].size())
		{
			more[i]=1e9;
			for(int j=0;j<to[i].size();j++)
				more[i]=min(more[i],(to[i][j]-i+n)%n);
		}
	}
	ll bas=maxi-1;bas*=n;
	for(int st=0;st<n;st++)
	{
		int ans=0;
		int p=0;
		for(int i=st;!(p and i==st);i=(i+1)%n,p=1)
		{
			if(to[i].size()==maxi)
				ans=max(ans,more[i]+(i-st+n)%n);
		}
		printf("%lld ",ans+bas);
	}
}


#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
int main() {
	int n, m, x = 0, ma = 0;
	cin >> n >> m;
	vector<multiset<int>>a(n);
	for (int i = 0; i < m; i++) {
		int v, u;
		cin >> v >> u;
		a[v - 1].insert(u - 1);
		ma = max((int)a[v - 1].size(), ma);
	}
	for (int i = 0; i < n; i++) {
		int ans = 0;
		for (int j = 0; j < n; j++) {
			if (a[j].size() == ma) {
				auto it = a[j].begin();
				int u = *it;
				if (j < i){
					if (u <= i && u<j) {
						ans = max(ans, 2 * n - i + u);
					}
					else {
						ans = max(ans, n + u - i);
					}
				}
				else {
					if (u > i && u > j) {
						ans = max(ans, u - i);
					}
					else {
						ans = max(ans, n + u-i);
					}
				}
			}
		}
		cout << (ma - 1)*n+ans << " ";
	}
	//system("pause");
	return 0;
}


#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
int main() {
	int n, m;
	cin >> n >> m;
	vector<multiset<int>>a(n);
	for (int i = 0; i < m; i++) {
		int v, u;
		cin >> v >> u;
		a[v - 1].insert(u - 1);
	}
	for (int i = 0; i < n; i++) {
		multiset <int> y;
		vector <multiset <int> > b = a;
		int x = i, tmp = m, ind = 0, ma, s = 0;
		while (tmp) {
			if (a[x].size() > 0) {
				ma = -1000000000;
				ind = 0;
				for (auto u : a[x]) {
					if (u >= x) {
						if (ma < u - x) {
							ind = u;
							ma = u - x;
						}
					}
					else {
						ma = max(ma, n - x + u);
						if (ma == n - x + u)
							ind = u;
					}
				}
				auto it = a[x].find(ind);
				y.insert(*it);
				a[x].erase(it);
			}
			if (y.find(x) != y.end()) {
				tmp -= y.count(x);
				y.erase(x);
			}
			if (x + 1 == n)
				x = 0;
			else
				x++;
			s++;
		}
		a = b;
		cout << s - 1 << ' ';
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
int main() {
	int n, m, x = 0, ma = 0, ans;
	cin >> n >> m;
	vector<multiset<int>>a(n);
	for (int i = 0; i < m; i++) {
		int j, u;
		cin >> j >> u;
		j--;
		u--;
		ans = 0;
		if (j < u) {
			a[j].insert(u-j);
		}
		else {
			a[j].insert(n + u - j);
		}
		ma = max((int)a[j].size(), ma);
	}
	for (int i = 0; i < n; i++) {
		int ans = 0;
		for (int j = 0; j < n; j++) {
			if (a[j].size() == ma) {
				auto it = a[j].begin();
				int u = *it;
				if (j < i) {
					ans = max(ans, u + 2*n - i + j);
				}
				else {
					ans = max(ans, n+u + j - i);
				}
			}
			if (a[j].size() == ma-1 && ma!=1) {
				auto it = a[j].begin();
				int u = *it;
				if (j < i) {
					ans = max(ans, u + n - i + j);
				}
				else {
					ans = max(ans, u + j - i);
				}
			}
		}
		cout << (ma - 2)*n+ans << " ";
	}
	//system("pause");
	return 0;
}


#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
int main() {
	int n, m, x = 0, ma = 0, ans;
	cin >> n >> m;
	vector<multiset<int>>a(n);
	for (int i = 0; i < m; i++) {
		int j, u;
		cin >> j >> u;
		j--;
		u--;
		ans = 0;
		if (j < u) {
			a[j].insert(u-j);
		}
		else {
			a[j].insert( n + u - j);
		}
		ma = max((int)a[j].size(), ma);
	}
	for (int i = 0; i < n; i++) {
		int ans = 0;
		for (int j = 0; j < n; j++) {
			if (a[j].size() == ma) {
				auto it = a[j].begin();
				int u = *it;
				if (j <= i) {
					ans = max(ans, u + n - i + j);
				}
				else {
					ans = max(ans, u + j - i);
				}
			}
		}
		cout << (ma - 1)*n+ans << " ";
	}
	//system("pause");
	return 0;
}


#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
int main() {
	int n, m, x = 0, ma = 0, ans;
	cin >> n >> m;
	vector<multiset<int>>a(n);
	for (int i = 0; i < m; i++) {
		int j, u;
		cin >> j >> u;
		j--;
		u--;
		ans = 0;
		if (j < u) {
			a[j].insert(u-j);
		}
		else {
			a[j].insert( n + u - j);
		}
		ma = max((int)a[j].size(), ma);
	}
	for (int i = 0; i < n; i++) {
		int ans = 0;
		for (int j = 0; j < n; j++) {
			if (a[j].size() == ma) {
				auto it = a[j].begin();
				int u = *it;
				if (j < i) {
					ans = max(ans, u + n - i + j);
				}
				else {
					ans = max(ans, u + j - i);
				}
			}
		}
		cout << (ma - 1)*n+ans << " ";
	}
	//system("pause");
	return 0;
}


#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
int main() {
	int n, m, x = 0, ma = 0, ans;
	cin >> n >> m;
	vector<multiset<int>>a(n);
	for (int i = 0; i < m; i++) {
		int j, u;
		cin >> j >> u;
		j--;
		u--;
		ans = 0;
		if (j <= u) {
			a[j].insert(u-j);
		}
		else {
			a[j].insert( n + u - j);
		}
		ma = max((int)a[j].size(), ma);
	}
	for (int i = 0; i < n; i++) {
		int ans = 0;
		for (int j = 0; j < n; j++) {
			if (a[j].size() == ma) {
				auto it = a[j].begin();
				int u = *it;
				if (j < i) {
					ans = max(ans, u + n - i + j);
				}
				else {
					ans = max(ans, u + j - i);
				}
			}
		}
		cout << (ma - 1)*n+ans << " ";
	}
	//system("pause");
	return 0;
}


#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
int main() {
	int n, m, x = 0, ma = 0;
	cin >> n >> m;
	vector<multiset<int>>a(n);
	for (int i = 0; i < m; i++) {
		int v, u;
		cin >> v >> u;
		a[v - 1].insert(u - 1);
		ma = max((int)a[v - 1].size(), ma);
	}
	for (int i = 0; i < n; i++) {
		int ans = 0;
		for (int j = 0; j < n; j++) {
			if (a[j].size() == ma) {
				auto it = a[j].begin();
				int u = *it;
				if (j < i){
					if (u <= i && u<=j) {
						ans = max(ans, 2 * n - i + u);
					}
					else {
						ans = max(ans, n + u - i);
					}
				}
				else {
					if (u > i && u >= j) {
						ans = max(ans, u - i);
					}
					else {
						ans = max(ans, n + u-i);
					}
				}
			}
		}
		cout << (ma - 1)*n+ans << " ";
	}
	//system("pause");
	return 0;
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStream;

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

    static class DTowers {
        int MAXN = 5005;
        PrintWriter out;
        InputReader in;
        int n;
        long[] pf = new long[MAXN];
        long[][] dp = new long[MAXN][MAXN];

        long go(int ind, int last) {
            if (ind == n + 1)
                return 0;
            if (dp[ind][last] != -1)
                return dp[ind][last];
            long val = 1 + go(ind + 1, last + 1);
            long last_sum = pf[ind - 1] - pf[last];
            int lo = ind, hi = n - 1;
            while (lo <= hi) {
                int mid = (lo + hi) >> 1;
                if (pf[mid] - pf[ind - 1] < last_sum)
                    lo = mid + 1;
                else
                    hi = mid - 1;
            }
            lo++;
            //System.out.println(ind +" "+lo+" "+last);
            long nxt_sum = pf[lo - 1] - pf[ind - 1];
            if (pf[n] - pf[lo - 1] >= nxt_sum) {
                int len = lo - ind;
                long cost = len - 1;
                val = Math.min(val, go(lo, ind - 1) + cost);
            } else {
                int len = n + 1 - ind;
                long cost = len - 1;
                val = Math.min(val, go(n + 1, ind - 1) + cost);
            }
            dp[ind][last] = val;
            return val;
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            this.out = out;
            this.in = in;
            n = ni();
            int i = 0;
            for (i = 1; i <= n; i++)
                pf[i] = pf[i - 1] + nl();
            for (i = 0; i <= n; i++)
                Arrays.fill(dp[i], -1);
            long min = (int) 1e9;
            if (n == 1) {
                pn(0);
                return;
            }
            for (i = 1; i <= n; i++) {
                //pn(i);
                if (pf[n] - pf[i] >= pf[i]) {
                    int len = i;
                    long cost = len - 1;
                    min = Math.min(min, go(i + 1, 0) + cost);
                } else {
                    int len = n;
                    long cost = len - 1;
                    min = Math.min(min, go(n + 1, 0) + cost);
                }
            }
            pn(min);
        }

        int ni() {
            return in.nextInt();
        }

        long nl() {
            return in.nextLong();
        }

        void pn(long zx) {
            out.println(zx);
        }

    }

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

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

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

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

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

        public String next() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

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

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStream;

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

    static class DTowers {
        int MAXN = 5005;
        PrintWriter out;
        InputReader in;
        int n;
        long[] pf = new long[MAXN];
        long[][] dp = new long[MAXN][MAXN];

        long go(int ind, int last) {
            if (ind == n + 1)
                return 0;
            if (dp[ind][last] != -1)
                return dp[ind][last];
            long val = (int) 1e8;
            long last_sum = pf[ind - 1] - pf[last];
            int lo = ind, hi = n - 1;
            while (lo <= hi) {
                int mid = (lo + hi) >> 1;
                if (pf[mid] - pf[ind - 1] < last_sum)
                    lo = mid + 1;
                else
                    hi = mid - 1;
            }
            lo++;
            //pn(ind +" "+last +" "+lo);
            int i = 0;
            for (i = lo; i <= n + 1; i++) {
                if (pf[n] - pf[i - 1] >= pf[i - 1] - pf[ind - 1]) {
                    int len = i - ind;
                    long cost = len - 1;
                    val = Math.min(val, go(i, ind - 1) + cost);
                } else {
                    int len = n + 1 - ind;
                    long cost = len - 1;
                    val = Math.min(val, go(n + 1, ind - 1) + cost);
                    break;
                }
            }
            dp[ind][last] = val;
            return val;
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            this.out = out;
            this.in = in;
            n = ni();
            int i = 0;
            for (i = 1; i <= n; i++)
                pf[i] = pf[i - 1] + nl();
            for (i = 0; i <= n; i++)
                Arrays.fill(dp[i], -1);
            long min = (int) 1e9;
            if (n == 1) {
                pn(0);
                return;
            }
            for (i = 1; i <= n; i++) {
                //pn(i);
                if (pf[n] - pf[i] >= pf[i]) {
                    int len = i;
                    long cost = len - 1;
                    min = Math.min(min, go(i + 1, 0) + cost);
                } else {
                    int len = n;
                    long cost = len - 1;
                    min = Math.min(min, go(n + 1, 0) + cost);
                }
            }
            pn(min);
        }

        int ni() {
            return in.nextInt();
        }

        long nl() {
            return in.nextLong();
        }

        void pn(long zx) {
            out.println(zx);
        }

    }

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

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

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

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

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

        public String next() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

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

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStream;

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

    static class DTowers {
        int MAXN = 5005;
        PrintWriter out;
        InputReader in;
        int n;
        long[] pf = new long[MAXN];
        long[][] dp = new long[MAXN][MAXN];

        long go(int ind, int last) {
            if (ind == n + 1)
                return 0;
            if (dp[ind][last] != -1)
                return dp[ind][last];
            long val = (int) 1e8;
            long last_sum = pf[ind - 1] - pf[last];
            int lo = ind, hi = n - 1;
            while (lo <= hi) {
                int mid = (lo + hi) >> 1;
                if (pf[mid] - pf[ind - 1] < last_sum)
                    lo = mid + 1;
                else
                    hi = mid - 1;
            }
            lo++;
            int i = 0;
            for (i = lo; i <= n; i++) {
                if (pf[n] - pf[i - 1] >= pf[i - 1] - pf[ind - 1]) {
                    int len = i - ind;
                    long cost = len - 1;
                    val = Math.min(val, go(i, ind - 1) + cost);
                } else {
                    int len = n + 1 - ind;
                    long cost = len - 1;
                    val = Math.min(val, go(n + 1, ind - 1) + cost);
                    break;
                }
            }
            dp[ind][last] = val;
            return val;
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            this.out = out;
            this.in = in;
            n = ni();
            int i = 0;
            for (i = 1; i <= n; i++)
                pf[i] = pf[i - 1] + nl();
            for (i = 0; i <= n; i++)
                Arrays.fill(dp[i], -1);
            long min = (int) 1e9;
            if (n == 1) {
                pn(0);
                return;
            }
            for (i = 1; i <= n; i++) {
                //pn(i);
                if (pf[n] - pf[i] >= pf[i]) {
                    int len = i;
                    long cost = len - 1;
                    min = Math.min(min, go(i + 1, 0) + cost);
                } else {
                    int len = n;
                    long cost = len - 1;
                    min = Math.min(min, go(n + 1, 0) + cost);
                }
            }
            pn(min);
        }

        int ni() {
            return in.nextInt();
        }

        long nl() {
            return in.nextLong();
        }

        void pn(long zx) {
            out.println(zx);
        }

    }

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

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

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

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

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

        public String next() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

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

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStream;

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

    static class DTowers {
        int MAXN = 5005;
        PrintWriter out;
        InputReader in;
        int n;
        long[] pf = new long[MAXN];
        long[][] dp = new long[MAXN][MAXN];

        long go(int ind, int last) {
            if (ind == n + 1)
                return 0;
            if (dp[ind][last] != -1)
                return dp[ind][last];
            long val = (int) 1e8;
            long last_sum = pf[ind - 1] - pf[last];
            int lo = ind, hi = n - 1;
            while (lo <= hi) {
                int mid = (lo + hi) >> 1;
                if (pf[mid] - pf[ind - 1] < last_sum)
                    lo = mid + 1;
                else
                    hi = mid - 1;
            }
            lo++;
            //System.out.println(ind +" "+lo+" "+last);
            long nxt_sum = pf[lo - 1] - pf[ind - 1];
            if (pf[n] - pf[lo - 1] >= nxt_sum) {
                int len = lo - ind;
                long cost = len - 1;
                val = Math.min(val, go(lo, ind - 1) + cost);
            } else {
                int len = n + 1 - ind;
                long cost = len - 1;
                val = Math.min(val, go(n + 1, ind - 1) + cost);
            }
            dp[ind][last] = val;
            return val;
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            this.out = out;
            this.in = in;
            n = ni();
            int i = 0;
            for (i = 1; i <= n; i++)
                pf[i] = pf[i - 1] + nl();
            for (i = 0; i <= n; i++)
                Arrays.fill(dp[i], -1);
            long min = (int) 1e9;
            if (n == 1) {
                pn(0);
                return;
            }
            for (i = 1; i <= n; i++) {
                if (pf[n] - pf[i] >= pf[i]) {
                    int len = i;
                    long cost = len - 1;
                    min = Math.min(min, go(i + 1, 0) + cost);
                } else {
                    //pn(i);
                    int len = n;
                    long cost = len - 1;
                    min = Math.min(min, go(n + 1, 0) + cost);
                }
            }
            pn(min);
        }

        int ni() {
            return in.nextInt();
        }

        long nl() {
            return in.nextLong();
        }

        void pn(long zx) {
            out.println(zx);
        }

    }

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

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

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

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

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

        public String next() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

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

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStream;

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

    static class DTowers {
        int MAXN = 5005;
        PrintWriter out;
        InputReader in;
        int n;
        long[] pf = new long[MAXN];
        long[][] dp = new long[MAXN][MAXN];

        long go(int ind, int last) {
            if (ind == n + 1)
                return 0;
            if (dp[ind][last] != -1)
                return dp[ind][last];
            long val = 1 + go(ind + 1, last);
            long last_sum = pf[ind - 1] - pf[last];
            int lo = ind, hi = n - 1;
            while (lo <= hi) {
                int mid = (lo + hi) >> 1;
                if (pf[mid] - pf[ind - 1] < last_sum)
                    lo = mid + 1;
                else
                    hi = mid - 1;
            }
            lo++;
            //System.out.println(ind +" "+lo+" "+last);
            long nxt_sum = pf[lo - 1] - pf[ind - 1];
            if (pf[n] - pf[lo - 1] >= nxt_sum) {
                int len = lo - ind;
                long cost = len - 1;
                val = Math.min(val, go(lo, ind - 1) + cost);
            } else {
                int len = n + 1 - ind;
                long cost = len - 1;
                val = Math.min(val, go(n + 1, ind - 1) + cost);
            }
            dp[ind][last] = val;
            return val;
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            this.out = out;
            this.in = in;
            n = ni();
            int i = 0;
            for (i = 1; i <= n; i++)
                pf[i] = pf[i - 1] + nl();
            for (i = 0; i <= n; i++)
                Arrays.fill(dp[i], -1);
            long min = (int) 1e9;
            if (n == 1) {
                pn(0);
                return;
            }
            for (i = 1; i <= n; i++) {
                //pn(i);
                if (pf[n] - pf[i] >= pf[i]) {
                    int len = i;
                    long cost = len - 1;
                    min = Math.min(min, go(i + 1, 0) + cost);
                } else {
                    int len = n;
                    long cost = len - 1;
                    min = Math.min(min, go(n + 1, 0) + cost);
                }
            }
            pn(min);
        }

        int ni() {
            return in.nextInt();
        }

        long nl() {
            return in.nextLong();
        }

        void pn(long zx) {
            out.println(zx);
        }

    }

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

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

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

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

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

        public String next() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

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

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStream;

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

    static class DTowers {
        int MAXN = 5005;
        PrintWriter out;
        InputReader in;
        int n;
        long[] pf = new long[MAXN];
        long[][] dp = new long[MAXN][MAXN];

        long go(int ind, int last) {
            if (ind == n + 1)
                return 0;
            if (dp[ind][last] != -1)
                return dp[ind][last];
            long val = (int) 1e8;
            long last_sum = pf[ind - 1] - pf[last];
            int lo = ind, hi = n - 1;
            while (lo <= hi) {
                int mid = (lo + hi) >> 1;
                if (pf[mid] - pf[ind - 1] < last_sum)
                    lo = mid + 1;
                else
                    hi = mid - 1;
            }
            lo++;
            //System.out.println(ind +" "+lo+" "+last);
            long nxt_sum = pf[lo - 1] - pf[ind - 1];
            if (pf[n] - pf[lo - 1] >= nxt_sum) {
                int len = lo - ind;
                int x = len / 2;
                int y = len - 1 - x;
                long cost = (x * (x + 1) + y * (y + 1)) >> 1;
                val = Math.min(val, go(lo, ind - 1) + cost);
            } else {
                int len = n + 1 - ind;
                int x = len / 2;
                int y = len - 1 - x;
                long cost = (x * (x + 1) + y * (y + 1)) >> 1;
                val = Math.min(val, go(n + 1, ind - 1) + cost);
            }
            dp[ind][last] = val;
            return val;
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            this.out = out;
            this.in = in;
            n = ni();
            int i = 0;
            for (i = 1; i <= n; i++)
                pf[i] = pf[i - 1] + nl();
            for (i = 0; i <= n; i++)
                Arrays.fill(dp[i], -1);
            long min = (int) 1e9;
            for (i = 2; i <= n; i++) {
                if (pf[n] - pf[i - 1] >= pf[i]) {
                    int len = i;
                    int x = len / 2;
                    int y = len - 1 - x;
                    long cost = (x * (x + 1) + y * (y + 1)) >> 1;
                    min = Math.min(min, go(i + 1, 0) + cost);
                } else {
                    int len = n;
                    int x = len / 2;
                    int y = len - 1 - x;
                    long cost = (x * (x + 1) + y * (y + 1)) >> 1;
                    min = Math.min(min, go(n + 1, 0) + cost);
                }
            }
            pn(min);
        }

        int ni() {
            return in.nextInt();
        }

        long nl() {
            return in.nextLong();
        }

        void pn(long zx) {
            out.println(zx);
        }

    }

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

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

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

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

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

        public String next() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

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

    }
}


/*
⣿⣿⣿⣿⣿⣿⡷⣯⢿⣿⣷⣻⢯⣿⡽⣻⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣇⠸⣿⣿⣆⠹⣿⣿⢾⣟⣯⣿⣿⣿⣿⣿⣿⣽⣻⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣻⣽⡿⣿⣎⠙⣿⣞⣷⡌⢻⣟⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣿⣿⡄⠹⣿⣿⡆⠻⣿⣟⣯⡿⣽⡿⣿⣿⣿⣿⣽⡷⣯⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣟⣷⣿⣿⣿⡀⠹⣟⣾⣟⣆⠹⣯⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢠⡘⣿⣿⡄⠉⢿⣿⣽⡷⣿⣻⣿⣿⣿⣿⡝⣷⣯⢿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣯⢿⣾⢿⣿⡄⢄⠘⢿⣞⡿⣧⡈⢷⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢸⣧⠘⣿⣷⠈⣦⠙⢿⣽⣷⣻⣽⣿⣿⣿⣿⣌⢿⣯⢿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣟⣯⣿⢿⣿⡆⢸⡷⡈⢻⡽⣷⡷⡄⠻⣽⣿⣿⡿⣿⣿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣏⢰⣯⢷⠈⣿⡆⢹⢷⡌⠻⡾⢋⣱⣯⣿⣿⣿⣿⡆⢻⡿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⡎⣿⢾⡿⣿⡆⢸⣽⢻⣄⠹⣷⣟⣿⣄⠹⣟⣿⣿⣟⣿⣿⣿⣿⣿⣿⣽⣿⣿⣿⡇⢸⣯⣟⣧⠘⣷⠈⡯⠛⢀⡐⢾⣟⣷⣻⣿⣿⣿⡿⡌⢿⣻⣿⣿
⣿⣿⣿⣿⣿⣿⣧⢸⡿⣟⣿⡇⢸⣯⣟⣮⢧⡈⢿⣞⡿⣦⠘⠏⣹⣿⣽⢿⣿⣿⣿⣿⣯⣿⣿⣿⡇⢸⣿⣿⣾⡆⠹⢀⣠⣾⣟⣷⡈⢿⣞⣯⢿⣿⣿⣿⢷⠘⣯⣿⣿
⣿⣿⣿⣿⣿⣿⣿⡈⣿⢿⣽⡇⠘⠛⠛⠛⠓⠓⠈⠛⠛⠟⠇⢀⢿⣻⣿⣯⢿⣿⣿⣿⣷⢿⣿⣿⠁⣾⣿⣿⣿⣧⡄⠇⣹⣿⣾⣯⣿⡄⠻⣽⣯⢿⣻⣿⣿⡇⢹⣾⣿
⣿⣿⣿⣿⣿⣿⣿⡇⢹⣿⡽⡇⢸⣿⣿⣿⣿⣿⣞⣆⠰⣶⣶⡄⢀⢻⡿⣯⣿⡽⣿⣿⣿⢯⣟⡿⢀⣿⣿⣿⣿⣿⣧⠐⣸⣿⣿⣷⣿⣿⣆⠹⣯⣿⣻⣿⣿⣿⢀⣿⢿
⣿⣿⣿⣿⣿⣿⣿⣿⠘⣯⡿⡇⢸⣿⣿⣿⣿⣿⣿⣿⣧⡈⢿⣳⠘⡄⠻⣿⢾⣽⣟⡿⣿⢯⣿⡇⢸⣿⣿⣿⣿⣿⣿⡀⢾⣿⣿⣿⣿⣿⣿⣆⠹⣾⣷⣻⣿⡿⡇⢸⣿
⣿⣿⣿⣿⣿⣿⣿⣿⡇⢹⣿⠇⢸⣿⣿⣿⣿⣿⣿⣿⣿⣷⣄⠻⡇⢹⣆⠹⣟⣾⣽⣻⣟⣿⣽⠁⣾⣿⣿⣿⣿⣿⣿⣇⣿⣿⠿⠛⠛⠉⠙⠋⢀⠁⢘⣯⣿⣿⣧⠘⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⡈⣿⡃⢼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⡙⠌⣿⣆⠘⣿⣞⡿⣞⡿⡞⢠⣿⣿⣿⣿⣿⡿⠛⠉⠁⢀⣀⣠⣤⣤⣶⣶⣶⡆⢻⣽⣞⡿⣷⠈⣿
⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⠘⠁⠉⠉⠉⠉⠉⠉⠉⠉⠉⠙⠛⠛⢿⣄⢻⣿⣧⠘⢯⣟⡿⣽⠁⣾⣿⣿⣿⣿⣿⡃⢀⢀⠘⠛⠿⢿⣻⣟⣯⣽⣻⣵⡀⢿⣯⣟⣿⢀⣿
⣿⣿⣿⣟⣿⣿⣿⣿⣶⣶⡆⢀⣿⣾⣿⣾⣷⣿⣶⠿⠚⠉⢀⢀⣤⣿⣷⣿⣿⣷⡈⢿⣻⢃⣼⣿⣿⣿⣿⣻⣿⣿⣿⡶⣦⣤⣄⣀⡀⠉⠛⠛⠷⣯⣳⠈⣾⡽⣾⢀⣿
⣿⢿⣿⣿⣻⣿⣿⣿⣿⣿⡿⠐⣿⣿⣿⣿⠿⠋⠁⢀⢀⣤⣾⣿⣿⣿⣿⣿⣿⣿⣿⣌⣥⣾⡿⣿⣿⣷⣿⣿⢿⣷⣿⣿⣟⣾⣽⣳⢯⣟⣶⣦⣤⡾⣟⣦⠘⣿⢾⡁⢺
⣿⣻⣿⣿⡷⣿⣿⣿⣿⣿⡗⣦⠸⡿⠋⠁⢀⢀⣠⣴⢿⣿⣽⣻⢽⣾⣟⣷⣿⣟⣿⣿⣿⣳⠿⣵⣧⣼⣿⣿⣿⣿⣿⣾⣿⣿⣿⣿⣿⣽⣳⣯⣿⣿⣿⣽⢀⢷⣻⠄⠘
⣿⢷⣻⣿⣿⣷⣻⣿⣿⣿⡷⠛⣁⢀⣀⣤⣶⣿⣛⡿⣿⣮⣽⡻⣿⣮⣽⣻⢯⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣯⢀⢸⣿⢀⡆
⠸⣟⣯⣿⣿⣷⢿⣽⣿⣿⣷⣿⣷⣆⠹⣿⣶⣯⠿⣿⣶⣟⣻⢿⣷⣽⣻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢀⣯⣟⢀⡇
⣇⠹⣟⣾⣻⣿⣿⢾⡽⣿⣿⣿⣿⣿⣆⢹⣶⣿⣻⣷⣯⣟⣿⣿⣽⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⢀⡿⡇⢸⡇
⣿⣆⠹⣷⡻⣽⣿⣯⢿⣽⣻⣿⣿⣿⣿⣆⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠛⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠇⢸⣿⠇⣼⡇
⡙⠾⣆⠹⣿⣦⠛⣿⢯⣷⢿⡽⣿⣿⣿⣿⣆⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠃⠎⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠏⢀⣿⣾⣣⡿⡇
⣿⣷⡌⢦⠙⣿⣿⣌⠻⣽⢯⣿⣽⣻⣿⣿⣿⣧⠩⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡏⢰⢣⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⢀⢀⢿⣞⣷⢿⡇
⣿⣽⣆⠹⣧⠘⣿⣿⡷⣌⠙⢷⣯⡷⣟⣿⣿⣿⣷⡀⡹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣈⠃⣸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⢀⣴⡧⢀⠸⣿⡽⣿⢀
⢻⣽⣿⡄⢻⣷⡈⢿⣿⣿⢧⢀⠙⢿⣻⡾⣽⣻⣿⣿⣄⠌⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠛⢁⣰⣾⣟⡿⢀⡄⢿⣟⣿⢀
⡄⢿⣿⣷⢀⠹⣟⣆⠻⣿⣿⣆⢀⣀⠉⠻⣿⡽⣯⣿⣿⣷⣈⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⢀⣠⠘⣯⣷⣿⡟⢀⢆⠸⣿⡟⢸
⣷⡈⢿⣿⣇⢱⡘⢿⣷⣬⣙⠿⣧⠘⣆⢀⠈⠻⣷⣟⣾⢿⣿⣆⠹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⣠⡞⢡⣿⢀⣿⣿⣿⠇⡄⢸⡄⢻⡇⣼
⣿⣷⡈⢿⣿⡆⢣⡀⠙⢾⣟⣿⣿⣷⡈⠂⠘⣦⡈⠿⣯⣿⢾⣿⣆⠙⠻⠿⠿⠿⠿⡿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠛⢋⣠⣾⡟⢠⣿⣿⢀⣿⣿⡟⢠⣿⢈⣧⠘⢠⣿
⣿⣿⣿⣄⠻⣿⡄⢳⡄⢆⡙⠾⣽⣿⣿⣆⡀⢹⡷⣄⠙⢿⣿⡾⣿⣆⢀⡀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⣀⣠⣴⡿⣯⠏⣠⣿⣿⡏⢸⣿⡿⢁⣿⣿⢀⣿⠆⢸⣿
⣿⣿⣿⣿⣦⡙⣿⣆⢻⡌⢿⣶⢤⣉⣙⣿⣷⡀⠙⠽⠷⠄⠹⣿⣟⣿⣆⢙⣋⣤⣤⣤⣄⣀⢀⢀⢀⢀⣾⣿⣟⡷⣯⡿⢃⣼⣿⣿⣿⠇⣼⡟⣡⣿⣿⣿⢀⡿⢠⠈⣿
⣿⣿⣿⣿⣿⣷⣮⣿⣿⣿⡌⠁⢤⣤⣤⣤⣬⣭⣴⣶⣶⣶⣆⠈⢻⣿⣿⣆⢻⣿⣿⣿⣿⣿⣿⣷⣶⣤⣌⣉⡘⠛⠻⠶⣿⣿⣿⣿⡟⣰⣫⣴⣿⣿⣿⣿⠄⣷⣿⣿⣿
*/

#include <bits/stdc++.h>

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back
#define sqr(a) ((a) * (a))
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
	return out << "(" << a.x << ", " << a.y << ")";
}

template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
	out << "[";
	forn(i, sz(v)) {
		if(i) out << ", ";
		out << v[i];
	}
	return out << "]";
}

mt19937 rnd(time(NULL));

const int INF = int(1e9);
const li INF64 = li(1e18);
const int MOD = INF + 7;
const ld EPS = 1e-9;
const ld PI = acos(-1.0);

const int N = 5000 + 7;

int n;
int a[N];

bool read () {
	if (scanf("%d", &n) != 1)
		return false;
	forn(i, n)
		scanf("%d", &a[i]);
	return true;
}

int dp[N][N];
int dp2[N];

void solve() {
	forn(i, n) forn(j, n) dp[i][j] = -INF;
	dp2[0] = 0;
	forn(m, n){
		int suml = 0, sumr = 0;
		int l = m;
		int dpmx = (m == 0 ? 0 : -INF);
		fore(r, m, n){
			sumr += a[r];
			while (l - 1 >= 0 && suml + a[l - 1] <= sumr){
				--l;
				suml += a[l];
				dpmx = max(dpmx, dp[l][m - 1]);
			}
			dp[m][r] = dpmx + 1;
		}
		dp2[m + 1] = -INF;
		forn(l, m + 1){
			dp2[m + 1] = max(dp2[m + 1], dp[l][m]);
		}
	}
	printf("%d\n", n - dp2[n]);
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	int tt = clock();

#endif

	cerr.precision(15);
	cout.precision(15);
	cerr << fixed;
	cout << fixed;

	while(read()) {
		solve();

#ifdef _DEBUG
	cerr << "TIME = " << clock() - tt << endl;
	tt = clock();
#endif

	}
}


//cool
#include <iostream>
#include <fstream>
#include <set>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long int lli;
typedef int ll;
#define lp(i, wwww) for(int i=0; i<wwww; i++)
#define lp2(i, a, b) for(int i=a; i<b; i++)
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define clean(a, b) memset(a, b, sizeof(a))
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define INF 1e9
#define umax(a, b) a= max(a, b)
#define umin(a, b) a= min(a, b)

ll n;
ll now[5012], dp[5012], sum[5012];

ll main(){
	cin >> n;
	for (int i=1; i<=n; i++){
		cin >> now[i];
		dp[i]= INF;
		sum[i]= now[i]+ ( i > 0 ? sum[i-1] : 0);
		now[i]= INF;
	}
	for (int i=1; i<=n; i++){
		for (int j=0; j<i; j++){
			if (dp[i] >= dp[j]+ i- j- 1){
				if (sum[i]- sum[j] >= now[j]){
					dp[i]= dp[j]+i -j -1;
					now[i]= sum[i]- sum[j];
				}
			}
		}
	}
	cout << dp[n];
	return 0;
}


#include <iostream>
#include <cstdio>
#define maxn 5002
using namespace std;
int n,sum,a[maxn],h[maxn],f[maxn];
int main()
{
    cin.tie(0); ios_base:sync_with_stdio(0);
    cin>>n;
    for (int i=1;i<=n;i++) cin>>a[i];
    for (int i=1;i<=n;i++){
        sum=0;
        for (int j=i;j>=0;j--){
            sum+=a[j];
            if (sum>=h[j-1]){
                f[i]=f[j-1]+(i-j);
                break;
            }
        }
        h[i]=sum;
    }
    cout<<f[n];
    return 0;
}


#include <iostream>
#include <cstdio>
#define maxn 5002
using namespace std;
int n,sum,a[maxn],h[maxn],f[maxn];
int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin>>n;
    for (int i=1;i<=n;i++) cin>>a[i];
    for (int i=1;i<=n;i++){
        sum=0;
        for (int j=i;j>=0;j--){
            sum+=a[j];
            if (sum>=h[j-1]){
                f[i]=f[j-1]+(i-j);
                break;
            }
        }
        h[i]=sum;
    }
    cout<<f[n];
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

const int MAXN = 5e3+5;
const int INF = 1e9+7;

#define ll long long
#define mp make_pair
#define pb push_back

int a[MAXN],dp[MAXN][MAXN],par[MAXN][MAXN];
// dp[i][j] = Javab baraye [0...i] ke akharin baze  hadeaksar be j khatm she

int n;

void Print()
{
    for(int i=1;i<=n;++i){
        for(int j=1;j<=n;++j){
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
}

int main()
{
    cin >> n;
    for(int i=1;i<=n;++i){
        cin >> a[i];
    }

    //Print();

    for(int i=1;i<=n;++i){
        int sums=0;
        for(int j=i;j<=n;++j){
            sums += a[j];
            par[i][j] = sums;
        }
    }

    for(int i=1;i<=n+2;++i){
        for(int j=1;j<=n+2;++j){
            dp[j][i] = INF;
        }
    }

    for(int i=1;i<=n;++i){
        for(int j=i;j>=1;--j){
            //cout << "Enter ==>  i==> " << i << " j==> " << j << endl;
            dp[j][i] = min(dp[j][i],dp[j+1][i]);
          //  cout << "After One ==> dp[j][i] ==> " << dp[j][i] << endl;
            int l=0,r=j;
            while(r-l>1){
                int mid = l + (r-l)/2;
                if(par[mid][j-1] <= par[j][i]) r = mid;
                else l = mid;
            }
            if(a[j-1] > par[j][i]) dp[j][i] = INF;
            else dp[j][i] = min(dp[j][i] , dp[r][j-1] + (i-j));
            //cout << "Sum [j...i] ==> " << par[j][i] << " r ==>" << r << endl;
           // cout << "dp[j][i] ==> " << dp[j][i] << endl;
        }
    }

   // Print();

    cout << dp[1][n];
}


#include<bits/stdc++.h>
using namespace std;

const int MAXN = 5e3+5;
const long long INF = 1e9+7;

#define ll long long
#define mp make_pair
#define pb push_back

int a[MAXN],dp[MAXN][MAXN],par[MAXN][MAXN];
// dp[i][j] = Javab baraye [0...i] ke akharin baze  hadeaksar be j khatm she

int n;

void Print()
{
    for(int i=1;i<=n;++i){
        for(int j=1;j<=n;++j){
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
}

int main()
{
    cin >> n;
    for(int i=1;i<=n;++i){
        cin >> a[i];
    }

    //Print();

    for(int i=1;i<=n;++i){
        ll sums=0;
        for(int j=i;j<=n;++j){
            sums += a[j];
            par[i][j] = sums;
        }
    }

    for(int i=1;i<=n;++i){
        for(int j=i;j>=1;--j){
            //cout << "Enter ==>  i==> " << i << " j==> " << j << endl;
            dp[j][i] = min(INF,dp[j+1][i]);
            //cout << "After One ==> dp[j][i] ==> " << dp[j][i] << endl;
            int l=-1,r=j;
            while(r-l>1){
                int mid = l + (r-l)/2;
                if(par[mid][j-1] <= par[j][i]) r = mid;
                else l = mid;
            }
            if(r==j) dp[j][i] = INF;
            else dp[j][i] = min(dp[j][i] , dp[r][j-1] + (i-j));
          //  cout << "Sum [j...i] ==> " << par[j][i] << " r ==>" << r << endl;
        //    cout << "dp[j][i] ==> " << dp[j][i] << endl;
        }
    }

   // Print();

    cout << dp[1][n]+1;
}


#include<bits/stdc++.h>
using namespace std;

const int MAXN = 5e3+5;
const long long INF = 1e9+7;

#define ll long long
#define mp make_pair
#define pb push_back

ll a[MAXN],dp[MAXN][MAXN],par[MAXN][MAXN];
// dp[i][j] = Javab baraye [0...i] ke akharin baze  hadeaksar be j khatm she

int n;

void Print()
{
    for(int i=1;i<=n;++i){
        for(int j=1;j<=n;++j){
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
}

int main()
{
    cin >> n;
    for(int i=1;i<=n;++i){
        cin >> a[i];
    }

    //Print();

    for(int i=1;i<=n;++i){
        ll sums=0;
        for(int j=i;j<=n;++j){
            sums += a[j];
            par[i][j] = sums;
        }
    }

    for(int i=1;i<=n;++i){
        for(int j=i;j>=1;--j){
            //cout << "Enter ==>  i==> " << i << " j==> " << j << endl;
            dp[j][i] = min(INF,dp[j+1][i]);
            //cout << "After One ==> dp[j][i] ==> " << dp[j][i] << endl;
            int l=-1,r=j;
            while(r-l>1){
                int mid = l + (r-l)/2;
                if(par[mid][j-1] <= par[j][i]) r = mid;
                else l = mid;
            }
            if(r==j) dp[j][i] = INF;
            else dp[j][i] = min(dp[j][i] , dp[r][j-1] + (i-j));
          //  cout << "Sum [j...i] ==> " << par[j][i] << " r ==>" << r << endl;
        //    cout << "dp[j][i] ==> " << dp[j][i] << endl;
        }
    }

   // Print();

    cout << dp[1][n]+1;
}


#include<bits/stdc++.h>
using namespace std;

const int MAXN = 5e3+5;
const int INF = 1e9+7;

#define ll long long
#define mp make_pair
#define pb push_back

int a[MAXN],dp[MAXN][MAXN],mx[MAXN][MAXN],par[MAXN][MAXN];

// dp[i][j] = Mximum javab agar [1..i] dashte bashim va groh [j..i] niz bashad

int n;

int main()
{
    cin >> n;
    for(int i=1;i<=n;++i){
        cin >> a[i];
    }

    for(int i=1;i<=n;++i){
        int sums=0;
        for(int j=i;j<=n;++j){
            sums += a[j];
            par[i][j] = sums;
        }
    }

    for(int i=1;i<=n+5;++i){
        for(int j=1;j<=n+5;++j){
            dp[i][j] = INF;
        }
    }

    for(int i=2;i<=n;++i){
        for(int j=i;j>=1;--j){
            int l=0,r=j;
            while(r-l>1){
                int mid = l + (r-l)/2;
                if(par[mid][j-1] <= par[j][i]) r=mid;
                else l=mid;
            }
            if(a[j-1] > par[j][i]) dp[j][i] = INF;
            else dp[j][i] = (i-j) + mx[j-1][r];
        }
        mx[i][i] = INF;
        for(int j=i-1;j>=1;--j){
            mx[i][j] = min(mx[i][j+1],dp[j][i]);
        }
    }

    int res=INF;
    for(int i=1;i<=n;++i){
        res = min(res,dp[i][n]);
    }
    cout << res;
}


#include<bits/stdc++.h>
using namespace std;

const int MAXN = 5e3+5;
const int INF = 1e9+7;

#define ll long long
#define mp make_pair
#define pb push_back

int a[MAXN],dp[MAXN][MAXN],mx[MAXN][MAXN],sum[MAXN];

// dp[i][j] = Mximum javab agar [1..i] dashte bashim va groh [j..i] niz bashad

int n;

int get(int l,int r){
    return sum[r] - sum[l-1];
}

int main()
{
    cin >> n;
    for(int i=1;i<=n;++i){
        cin >> a[i];
    }

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

    for(int i=1;i<=n+5;++i){
        for(int j=1;j<=n+5;++j){
            dp[i][j] = INF;
            mx[i][j] = INF;
        }
    }

    for(int i=1;i<=n;++i){
        for(int j=i;j>=1;--j){
            int l=0,r=j;
            while(r-l>1){
                int mid = l + (r-l)/2;
                if(get(mid,j-1) <= get(j,i)) r=mid;
                else l=mid;
            }
            if(r==j && j!=1){
         //       cout << i << " " << j << endl;
                dp[j][i] = INF;
            }
            else dp[j][i] = (i-j) + mx[j-1][r];
        }
        mx[i][i] = INF;
        for(int j=i-1;j>=1;--j){
            mx[i][j] = min(mx[i][j+1],dp[j][i]);
        }
    }

    int res=INF;
    for(int i=1;i<=n;++i){
        res = min(res,dp[i][n]);
    }
    cout << res;
}


#include<bits/stdc++.h>
using namespace std;

const int MAXN = 5e3+5;
const long long INF = 1e9+7;

#define ll long long
#define mp make_pair
#define pb push_back

ll a[MAXN],dp[MAXN][MAXN],par[MAXN][MAXN];
// dp[i][j] = Javab baraye [0...i] ke akharin baze  hadeaksar be j khatm she

int n;

void Print()
{
    for(int i=1;i<=n;++i){
        for(int j=1;j<=n;++j){
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
}

int main()
{
    cin >> n;
    for(int i=1;i<=n;++i){
        cin >> a[i];
    }

    //Print();

    for(int i=0;i<=n;++i){
        ll sums=0;
        for(int j=i;j<=n;++j){
            sums += a[j];
            par[i][j] = sums;
        }
    }

    for(int i=1;i<=n;++i){
        for(int j=1;j<=n;++j){
            dp[j][i] = INF;
        }
    }

    for(int i=1;i<=n;++i){
        for(int j=i;j>=1;--j){
           /// cout << "Enter ==>  i==> " << i << " j==> " << j << endl;
            dp[j][i] = min(dp[j][i],dp[j+1][i]);
         //   cout << "After One ==> dp[j][i] ==> " << dp[j][i] << endl;
            int l=0,r=j;
            while(r-l>1){
                int mid = l + (r-l)/2;
                if(par[mid][j-1] <= par[j][i]) r = mid;
                else l = mid;
            }
            if(a[j-1] > par[j][i]) dp[j][i] = INF;
            else dp[j][i] = min(dp[j][i] , dp[r][j-1] + (i-j));
           // cout << "Sum [j...i] ==> " << par[j][i] << " r ==>" << r << endl;
            //cout << "dp[j][i] ==> " << dp[j][i] << endl;
        }
    }

   // Print();

    cout << dp[1][n];
}