import java.util.*;

public class mapreduce {

	public static void main(String[] args) {

		System.out.println("Taco bell options = "+combowrep(new int[]{20,6}));
		System.out.println("Number of nonneg int sols to a+b+c+d+e+f<=20 is "+numinequalities(new int[]{20,6}));
	}
	
	/*** Problem B: Original Combinations with repetition ***/
	
	// Returns the number of ways to buy n objects from r unique objects with unlimited repeats.
	public static long combowrep(int[] input) {
		
		// Split up my input into its pieces.
		int n = input[0];
		int r = input[1];
	
		long[][] tri = new long[n+r][n+r];
		for (int i=0; i<n+r; i++) {
			tri[i][0] = 1;
			tri[i][i] = 1;
		}
		
		for (int i=2; i<n+r; i++)
			for (int j=1; j<i; j++)
				tri[i][j] = tri[i-1][j-1] + tri[i-1][j];
				
		return tri[n+r-1][n]; // return tri[n+r-1][r-1].
	}
	
	/*** This is the mapping reducibility function f ***/
	
	// Takes an input into the problem how many integer solutions to a+b+c... <= n.
	// Produces an output which is the number of items to buy and number of categories of items
	// to buy from.
	public static int[] mapfunc(int[] lteinput) {
		
		int[] res = new int[2];
		res[0] = lteinput[0];
		
		// We add the one because it's like adding the slack variable as a new variable
		// for the input of the regular combo with repetition problem.
		res[1] = lteinput[1] + 1;
		return res;
	}
	
	// Returns the number of non-neg int solutions to a + b + c + ... <= n, 
	// where n is input[0] and the number of variables on the LHS is input[1].
	public static long numinequalities(int[] input) {
		int[] newinput = mapfunc(input);
		return combowrep(newinput);
	}
}