codeparrot/codecomplex huggingface dataset:
// Problem: 35_C. Fire Again
// Time complexity: cubic
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;


public class R035CRetry {
    public void debug(Object... objects) { System.err.println(Arrays.deepToString(objects)); }
    public static final int INF = 987654321;
    public static final long LINF = 987654321987654321L;
    public static final double EPS = 1e-9;
    
    Scanner scanner;
    PrintWriter out;
    boolean[][] bss;
    
    public R035CRetry() {
        try {
            this.scanner = new Scanner(new File("input.txt"));
            this.out = new PrintWriter("output.txt");
        } catch(FileNotFoundException ex) { ex.printStackTrace(); }
    }
    
    class Point implements Comparable<Point> {
        int x, y, count;
        Point(int x, int y) { this.x = x; this.y = y; }
        public int hashCode() { return x * 17 + y; }
        public boolean equals(Object o) {
            if(!(o instanceof Point)) return false;
            Point that = (Point)o;
            return this.x == that.x && this.y == that.y;
        }
        public int compareTo(Point that) { return this.count - that.count; }
        public String toString()  { return "(" + x + ", " + y + ":" + count + ")"; }
    }

    
    int[] dx = new int[] {  0, 0, -1, 1 };
    int[] dy= new int[] { -1, 1,  0, 0 };
    int n, m;
    
    Queue<Point> q;
    
    Point bfs() {
        int max = -INF;
        Point p = null;
        while(!q.isEmpty()) {
            Point cur = q.remove();
            if(max < cur.count) { max = cur.count; p = cur; } 
            for(int i=0; i<dx.length; i++) {
                int nx = cur.x + dx[i];
                int ny = cur.y + dy[i];
                if(nx < 0 || nx >= n) { continue; }
                if(ny < 0 || ny >= m) { continue; }
                Point np = new Point(nx, ny);
                if(bss[nx][ny] ) { continue; } 
                np.count = cur.count+1;
                bss[nx][ny] = true;
                q.add(np);
            }
        }
        return p;
    }
    
    private void solve() {
        this.n = scanner.nextInt();
        this.m = scanner.nextInt();
        this.bss = new boolean[n][m];
        int k = scanner.nextInt();
        q = new PriorityQueue<Point>();
        for(int i=0; i<k; i++) {
            int x = scanner.nextInt() - 1;
            int y = scanner.nextInt() - 1;
            Point init = new Point(x, y);
            init.count = 1;
            q.add(init);
            bss[x][y] = true;
        }
        Point p = bfs();
        out.println((p.x+1) + " " + (p.y+1));
    }
    
    private void finish() { this.out.close(); }
    
    public static void main(String[] args) { 
        R035CRetry obj = new R035CRetry();
        obj.solve();
        obj.finish();
    }
}
// Problem: 35_C. Fire Again
// Time complexity: cubic
import java.io.*;
import java.util.*;

public class cf35c {
	public static void main(String[] args) throws Exception {
		Scanner in = new Scanner(new File("input.txt"));
		PrintWriter out = new PrintWriter(new File("output.txt"));
		int[] dx = {0,0,1,-1};
		int[] dy = {1,-1,0,0};
		int n = in.nextInt();
		int m = in.nextInt();
		int[][] seen = new int[n][m];
		for(int i=0; i<n; i++)
			Arrays.fill(seen[i], -1);
		Queue<Integer> q = new LinkedList<Integer>();
		int k = in.nextInt();
		for(int i=0; i<k; i++) {
			int x = in.nextInt()-1;
			int y = in.nextInt()-1;
			q.add(x);
			q.add(y);
			q.add(0);
			seen[x][y] = 0;
		}
		while(!q.isEmpty()) {
			int x = q.poll();
			int y = q.poll();
			int t = q.poll();
			for(int i=0; i<dx.length; i++) {
				int nx = x + dx[i];
				int ny = y + dy[i];
				if(nx < 0 || nx >= n || ny < 0 || ny >= m)
					continue;
				if(seen[nx][ny] != -1) continue;
				seen[nx][ny] = t+1;
				q.add(nx);
				q.add(ny);
				q.add(t+1);
			}
		}
		int best=-1,x=0,y=0;
		for(int i=0; i<n; i++)
			for(int j=0; j<m; j++)
				if(seen[i][j] > best) {
					best = seen[i][j];
					x = i+1;
					y = j+1;
				}
		out.println(x + " " +y);
		out.close();
	}
}
// Problem: 35_C. Fire Again
// Time complexity: cubic
import java.io.*;
import java.util.*;

public class FireAgain {

    public static void main(String[] args) throws IOException {
		System.setIn(new FileInputStream("input.txt"));
		System.setOut(new PrintStream("output.txt"));
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		String s[] = r.readLine().split("\\s+");
		int n = Integer.parseInt(s[0]);
		int m = Integer.parseInt(s[1]);
		int k = Integer.parseInt(r.readLine());
		int[][] a = new int[n][m];
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < m; j++)
				a[i][j] = Integer.MAX_VALUE;
		}
		assert k >= 1 && k < n * m;
		int max = 0;
		StringTokenizer st = new StringTokenizer(r.readLine());
		assert st.countTokens() == k;
		for(; k > 0; k--) {
			int x = Integer.parseInt(st.nextToken()) - 1;
			int y = Integer.parseInt(st.nextToken()) - 1;
			assert x >= 1 && x <= n && y >= 1 && y <= n;

			for(int i = 0; i < n; i++) {
				for(int j = 0; j < m; j++) {
					int d = Math.abs(i - x) + Math.abs(j - y);
					if(a[i][j] > d)
						a[i][j] = d;
					if(k == 1 && a[i][j] > max)
						max = a[i][j];
				}
			}
		}

		for(int i = 0; i < n; i++) {
			for(int j = 0; j < m; j++) {
				if(a[i][j] == max) {
					System.out.println((i + 1) + " " + (j + 1));
					return;
				}
			}
		}
    }

}
// Problem: 35_C. Fire Again
// Time complexity: cubic
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;


public class C2 {

    public static void main(String[] args) throws IOException{
        Scanner sc = new Scanner(new File("input.txt"));
        PrintWriter pw = new PrintWriter(new File("output.txt"));
        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();
        int[]x = new int[k+1], y = new int[k+1];
        for (int i = 1; i <= k; i++) {
            y[i] = sc.nextInt();
            x[i] = sc.nextInt();
        }
        int max = -1, y0 = 0, x0 = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                int min = n+m+2;
                for (int j2 = 1; j2 <= k; j2++) {
                    min = Math.min(min, Math.abs(i-y[j2])+Math.abs(j-x[j2]));
                }
                if (min > max) {
                    max = min;
                    y0 = i;
                    x0 = j;
                }
            }
        }
        pw.println(y0+" "+x0);
        pw.close();
    }

}
// Problem: 35_C. Fire Again
// Time complexity: cubic
import java.util.Scanner;
import java.util.HashSet;
import java.io.PrintWriter;
import java.io.File;
public class FireAgain {

    public static void main(String[] args){
	
	File in = new File("input.txt");
	File out = new File("output.txt");
	Scanner sc;
	PrintWriter pw;
	try{
	    sc = new Scanner(in);
	    pw = new PrintWriter(out);
	}catch(Exception e){
	    sc = new Scanner(System.in);
	    pw = null;
	}

	int max_x = sc.nextInt();
	int max_y = sc.nextInt();
	int start_num = sc.nextInt();
	HashSet<int[]> start = new HashSet<int[]>();
	for(int i=0; i<start_num; i++){
	    int[] cell = new int[2];
	    cell[0] = sc.nextInt();
	    cell[1] = sc.nextInt();
	    start.add(cell);
	}

	int[] result = new int[]{1,1};
	int resultLen = 0;
	for(int i=1; i<=max_x; i++){
	    for(int j=1; j<=max_y; j++){
		int[] sh = new int[]{1,1};
		int shLen = Integer.MAX_VALUE;
		for(int[] fired: start){
		    int len = Math.abs(i - fired[0]) + Math.abs(j - fired[1]);
		    if(len < shLen){
			sh[0] = i;
			sh[1] = j;
			shLen = len;
		    }
		}
		if(shLen > resultLen){
		    result[0] = sh[0];
		    result[1] = sh[1];
		    resultLen = shLen;
		}
	    }
	}
	pw.print(result[0] + " " + result[1]);
	pw.close();
	return ;
    }
}
// Problem: 35_C. Fire Again
// Time complexity: cubic
import java.io.*;
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.StringTokenizer;

public class CodeForces {
    public static void main(String[] args) throws FileNotFoundException {
        FastIO io = new FastIO();

        int width = io.nextInt();
        int height = io.nextInt();

        int initials = io.nextInt();

        boolean[][] visited = new boolean[width][height];

        Queue<Coordinate> q = new ArrayDeque<>();

        for (int i = 0; i < initials; i++) {
            q.add(new Coordinate(io.nextInt() - 1, io.nextInt() - 1));
        }

        Coordinate oneOfLast = null;

        while (!q.isEmpty()) {
            int len = q.size();
            for (int times = 0; times < len; times++) {
                Coordinate c = q.poll();
                if (visited[c.x][c.y]) {
                    continue;
                }

                oneOfLast = c;
                visited[c.x][c.y] = true;

                int[][] deltas = new int[][]{
                        {-1, 0}, {0, -1}, {1, 0}, {0, 1}
                };

                for (int[] delta : deltas) {
                    int ci = c.y + delta[0];
                    int cj = c.x + delta[1];

                    if (ci >= 0 && cj >= 0 && ci < height && cj < width) {
                        q.add(new Coordinate(cj, ci));
                    }
                }
            }
        }

        io.println((oneOfLast.x + 1) + " " + (oneOfLast.y + 1));

        io.close();
    }

    static class Coordinate {
        int x;
        int y;

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

    static class FastIO extends PrintWriter {
        BufferedReader br;
        StringTokenizer st;

        public FastIO() throws FileNotFoundException {
            super(new BufferedOutputStream(new FileOutputStream("output.txt")));
            br = new BufferedReader(new InputStreamReader(new FileInputStream("input.txt")));
        }

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

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

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

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

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

        String nextLine() {
            try {
                return br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return "";
        }
    }
}
// Problem: 1497E2
// Time complexity: cubic
import java.util.*;
import java.io.*;

public class Solve{
    public static void main(String[] args) throws Exception{
        Scanner sc=new Scanner(System.in);
        PrintWriter out =new PrintWriter(System.out);
        int size=(int)1e7+1;
        int[] pr=new int[size];
        for(int i=0;i<size;i++){
            pr[i]=i;
        }
        for(int i=2;i*i<size;i++){
          int val=i*i;
            for(int j=val;j<=size;j+=val){
                 pr[j]=j/val;
            }
        }
        int t=sc.nextInt();
        int[] dp=new int[size];
        Arrays.fill(dp,-1);
        while(t-->0){
            int n=sc.nextInt();
            int k=sc.nextInt();
            int[] ar=new int[n];
            for(int i=0;i<n;i++){
                int a=sc.nextInt();
                ar[i]=pr[a];
            }
            int[] ans=new int[k+1];
            int[] ind=new int[k+1];
            for(int i=0;i<n;i++){
                for(int h=k;h>=0;h--){
                    if(dp[ar[i]]>=ind[h]){
                        ans[h]++;
                        ind[h]=i;
                    }
                    if(h>0 && (ans[h-1]<ans[h] ||(ans[h-1]==ans[h] && ind[h-1]>ind[h])))
                    {
                        ans[h]=ans[h-1];
                        ind[h]=ind[h-1];
                    }
                }
                dp[ar[i]]=i;
            }
            out.println(ans[k]+1);
            for(int i=0;i<n;i++)dp[ar[i]]=-1;
        }
        out.close();
    }
}
// Problem: 1497E2
// Time complexity: cubic
import java.io.*;
import java.util.*;

public class E2 {
    static ArrayList<Integer> primes;
    static int[] mind;
    final static int MAXA = (int) 1e7;

    public static void main(String[] args) throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(f.readLine());
        int t = Integer.parseInt(st.nextToken());
        primes = new ArrayList<>();
        mind = new int[MAXA + 1];
        for (int i = 2; i <= MAXA; i++) {
            if (mind[i] == 0) {
                primes.add(i);
                mind[i] = i;
            }
            for (int x : primes) {
                if (x > mind[i] || x * i > MAXA) break;
                mind[x * i] = x;
            }
        }
        int[] count = new int[MAXA + 1];
        for (int on8y = 0; on8y < t; on8y++) {
            st = new StringTokenizer(f.readLine());
            int n = Integer.parseInt(st.nextToken());
            int k = Integer.parseInt(st.nextToken());
            int[] a = new int[n];
            Arrays.fill(a, 1);
            st = new StringTokenizer(f.readLine());
            for (int i = 0; i < n; i++) {
                int x = Integer.parseInt(st.nextToken());
                int cnt = 0;
                int last = 0;
                while (x > 1) {
                    int p = mind[x];
                    if (last == p) cnt++;
                    else {
                        if (cnt % 2 == 1) a[i] *= last;
                        last = p;
                        cnt = 1;
                    }
                    x /= p;
                }
                if (cnt % 2 == 1) a[i] *= last;
            }
            int[][] mnleft = new int[n][k + 1];
            for (int j = 0; j < k + 1; j++) {
                int l = n;
                int now = 0;
                for (int i = n - 1; i >= 0; i--) {
                    while (l - 1 >= 0 && now + ((count[a[l - 1]] > 0) ? 1 : 0) <= j) {
                        l--;
                        now += (count[a[l]] > 0) ? 1 : 0;
                        count[a[l]]++;
                    }
                    mnleft[i][j] = l;
                    if (count[a[i]] > 1) now--;
                    count[a[i]]--;
                }
            }
            int[][] dp = new int[n + 1][k + 1];
            for (int i = 0; i < n + 1; i++) {
                Arrays.fill(dp[i], (int) 1e9 + 1);
            }
            for (int i = 0; i < k + 1; i++) dp[0][i] = 0;
            for (int i = 1; i <= n; i++) {
                for (int j = 0; j <= k; j++) {
                    if (j > 0) dp[i][j] = dp[i][j - 1];
                    for (int lst = 0; lst <= j; lst++) {
                        dp[i][j] = Math.min(dp[i][j], dp[mnleft[i - 1][lst]][j - lst] + 1);
                    }
                }
            }
            int ans = (int) 1e9 + 1;
            for (int c : dp[n]) ans = Math.min(ans, c);
            System.out.println(ans);

        }
    }
}
// Problem: 1497E2
// Time complexity: cubic
// https://codeforces.com/contest/1497/submission/110250082
import java.io.*;
import java.util.*;

public class CF1497E2 extends PrintWriter {
	CF1497E2() { super(System.out); }
	static class Scanner {
		Scanner(InputStream in) { this.in = in; } InputStream in;
		byte[] bb = new byte[1 << 15]; int i, n;
		byte getc() {
			if (i == n) {
				i = n = 0;
				try { n = in.read(bb); } catch (IOException e) {}
			}
			return i < n ? bb[i++] : 0;
		}
		int nextInt() {
			byte c = 0; while (c <= ' ') c = getc();
			int a = 0; while (c > ' ') { a = a * 10 + c - '0'; c = getc(); }
			return a;
		}
	}
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		CF1497E2 o = new CF1497E2(); o.main(); o.flush();
	}

	static final int A = 10000000, K = 20;
	int[] cc = new int[A + 1]; {
		for (int a = 1; a <= A; a++)
			cc[a] = a;
		for (int a = 2; a <= A / a; a++) {
			int s = a * a;
			for (int b = s; b <= A; b += s)
				while (cc[b] % s == 0)
					cc[b] /= s;
		}
	}
	void main() {
		int[] pp = new int[A + 1]; Arrays.fill(pp, -1);
		int t = sc.nextInt();
		while (t-- > 0) {
			int n = sc.nextInt();
			int k = sc.nextInt();
			int[] aa = new int[n];
			for (int i = 0; i < n; i++)
				aa[i] = cc[sc.nextInt()];
			int[] mp = new int[k + 1];
			int[] ip = new int[k + 1];
			for (int i = 0; i < n; i++) {
				int a = aa[i];
				for (int h = k; h >= 0; h--) {
					if (pp[a] >= ip[h]) {
						mp[h]++;
						ip[h] = i;
					}
					if (h > 0 && (mp[h - 1] < mp[h] || mp[h - 1] == mp[h] && ip[h - 1] > ip[h])) {
						mp[h] = mp[h - 1];
						ip[h] = ip[h - 1];
					}
				}
				pp[a] = i;
			}
			println(mp[k] + 1);
			for (int i = 0; i < n; i++) {
				int a = aa[i];
				pp[a] = -1;
			}
		}
	}
}
// Problem: 1497E2
// Time complexity: cubic
import java.util.*;
import java.io.*;
 

 public class SolutionC{
       public static void main(String[] args) throws Exception{
               Scanner sc=new Scanner(System.in);
        PrintWriter out=new PrintWriter(System.out);
       int t=sc.nextInt();
       int[] arr=new int[10000002];
       for(int i=0;i<arr.length;i++){
           arr[i]=i;
       }
       for(int i=2;i*i<arr.length;i++){
           int b=i*i;
          for(int j=b;j<arr.length;j+=b){
              arr[j]=j/b;
          }
       }
      int[] pp = new int[10000001]; Arrays.fill(pp, -1);
       while(t-->0){
           
        int n=sc.nextInt();
        int k=sc.nextInt();
        int[] aa=new int[n];
         for(int i=0;i<n;i++){
             int a=sc.nextInt();
             aa[i]=arr[a];
         }
        
         int[] mp = new int[k + 1];
			int[] ip = new int[k + 1];
			for (int i = 0; i < n; i++) {
				int a = aa[i];
				for (int h = k; h >= 0; h--) {
					if (pp[a] >= ip[h]) {
						mp[h]++;
						ip[h] = i;
					}
					if (h > 0 && (mp[h - 1] < mp[h] || mp[h - 1] == mp[h] && ip[h - 1] > ip[h])) {
						mp[h] = mp[h - 1];
						ip[h] = ip[h - 1];
					}
				}
				pp[a] = i;
			}
         
       
        out.println(mp[k]+1);
        
       for (int i = 0; i < n; i++) {
				pp[aa[i]] = -1;
			}
        
       }
           
           out.close();
}

}
// Problem: 1497E2
// Time complexity: cubic
import java.io.*;
import java.util.*;

public class CF1497E2 extends PrintWriter {
	CF1497E2() { super(System.out); }
	static class Scanner {
		Scanner(InputStream in) { this.in = in; } InputStream in;
		byte[] bb = new byte[1 << 15]; int i, n;
		byte getc() {
			if (i == n) {
				i = n = 0;
				try { n = in.read(bb); } catch (IOException e) {}
			}
			return i < n ? bb[i++] : 0;
		}
		int nextInt() {
			byte c = 0; while (c <= ' ') c = getc();
			int a = 0; while (c > ' ') { a = a * 10 + c - '0'; c = getc(); }
			return a;
		}
	}
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		CF1497E2 o = new CF1497E2(); o.main(); o.flush();
	}

	static final int A = 10000000, K = 20;
	int[] cc = new int[A + 1]; {
		boolean[] composite = new boolean[A + 1];
		for (int a = 1; a <= A; a++)
			cc[a] = a;
		for (int a = 2; a <= A; a++) {
			if (composite[a])
				continue;
			for (int b = a + a; b <= A; b += a)
				composite[b] = true;
			if (a <= A / a) {
				int a2 = a * a;
				for (int b = a2; b <= A; b += a2) {
					int c = cc[b];
					while (c % a2 == 0)
						c /= a2;
					cc[b] = c;
				}
			}
		}
	}
	void main() {
		int[] pp = new int[A + 1]; Arrays.fill(pp, -1);
		int t = sc.nextInt();
		while (t-- > 0) {
			int n = sc.nextInt();
			int k = sc.nextInt();
			int[] aa = new int[n];
			for (int i = 0; i < n; i++)
				aa[i] = cc[sc.nextInt()];
			int[] mp = new int[k + 1];
			int[] ip = new int[k + 1];
			for (int i = 0; i < n; i++) {
				int a = aa[i];
				for (int h = k; h >= 0; h--) {
					if (pp[a] >= ip[h]) {
						mp[h]++;
						ip[h] = i;
					}
					if (h > 0 && (mp[h - 1] < mp[h] || mp[h - 1] == mp[h] && ip[h - 1] > ip[h])) {
						mp[h] = mp[h - 1];
						ip[h] = ip[h - 1];
					}
				}
				pp[a] = i;
			}
			println(mp[k] + 1);
			for (int i = 0; i < n; i++) {
				int a = aa[i];
				pp[a] = -1;
			}
		}
	}
}
// Problem: 1497E2
// Time complexity: cubic
import java.util.*;
import java.io.*;

public class cf1497_Div2_E2 {
	static int[] spf;
	
	public static int factor(int n) {
		int val = 1;
		while (n > 1) {
			int cnt = 0;
			int p = spf[n];
			while (n % p == 0) {
				cnt++;
				n /= p;
			}
			if (cnt % 2 == 1)
				val *= p;
		}
		return val;
	}
	
	public static void main(String args[]) throws IOException {
		FastScanner in = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		
		int t = in.nextInt();
		int max = (int)(1e7) + 1;
		
		boolean[] prime = new boolean[max + 1]; 
		Arrays.fill(prime, true);
		prime[0] = prime[1] = false;
		spf = new int[max];
		for (int i = 2; i < max; i++) spf[i] = i;
		for (int i = 2; i * i < max; i++) {
			if (prime[i]) {
				spf[i] = i;
				for (int j = i * i; j < max; j += i) {
					prime[j] = false;
					spf[j] = i;
				}
			}
		}
		
		int[] cnts = new int[max];
		
		for ( ; t > 0; t--) {
			int n = in.nextInt();
			int k = in.nextInt();
			int[] vals = new int[n];
			for (int i = 0; i < n; i++)
				vals[i] = factor(in.nextInt());
			
			// left[i][x] = l where al ... ai such that in x moves it is valid subsequence
			int[][] left = new int[n + 1][k + 1];
			// x y z w a b c
			
			for (int x = 0; x <= k; x++) {
				int l = n;
				int now = 0;
				for (int i = n - 1; i >= 0; i--) {
					while (l - 1 >= 0 && now + ((cnts[vals[l - 1]] > 0) ? 1 : 0) <= x) {
						l--;
						now += ((cnts[vals[l]] > 0) ? 1 : 0);
						// System.out.println(now);
						cnts[vals[l]]++;
					}
					// System.out.println(i + " " + x + " " + l + " " + now);
					left[i][x] = l;
					if (cnts[vals[i]] > 1) now--;
					cnts[vals[i]]--;
				}
			}
			
			// for (int[] x: left)
				// System.out.println(Arrays.toString(x));
		
				
			int oo = (int)(1e9);
			
			int[][] dp = new int[n + 1][k + 1];
			
			for (int i = 1; i <= n; i++)
				Arrays.fill(dp[i], oo);
			
			for (int i = 1; i <= n; i++) {
				for (int j = 0; j <= k; j++) {
					if (j > 0) dp[i][j] = dp[i][j - 1];
					for (int x = 0; x <= j; x++) {
						int l = left[i - 1][x];
						dp[i][j] = Math.min(dp[i][j], dp[l][j - x] + 1);
					}
				}
			}
			
			int min = Integer.MAX_VALUE;
			for (int i = 0; i <= k; i++) {
				min = Math.min(min, dp[n][i]);
			}
			
			out.println(min);
		}
		
		out.close();
	}

	
	static class FastScanner {
	    BufferedReader br;
	    StringTokenizer st;
		
	    public FastScanner(InputStream i) {
	        br = new BufferedReader(new InputStreamReader(i));
	        st = new StringTokenizer("");
	    }
				
	    public String next() throws IOException {
	        if(st.hasMoreTokens())
	            return st.nextToken();
	        else
	            st = new StringTokenizer(br.readLine());
	        return next();
	    }

	    public int nextInt() throws IOException {
	        return Integer.parseInt(next());
	    }
	    //#
	    public long nextLong() throws IOException {
	        return Long.parseLong(next());
	    }
	    public double nextDouble() throws IOException {
	        return Double.parseDouble(next());
	    }
	    //$
	}
}