// Arup Guha
// 7/16/07
// Solution to BHCSI Program: Jelly Beans - Solves the subset sum problem
//                            recursively.

import java.util.*;
import java.io.*;

public class jelly {
	

	public static void main(String[] args) throws IOException {
		
		Scanner stdin = new Scanner(System.in);
		
		// Get the file.
		System.out.println("What is the file with the jelly bean information?");
		String file = stdin.next();
		Scanner fin = new Scanner(new File(file));
		
		// Get the number of desired jelly beans.
		System.out.println("How many jelly beans do you want to buy?");
		int target = stdin.nextInt();
		
		// Read in all the individual packets.
		int n = fin.nextInt();
		int[] vals = new int[n];
		for (int i=0; i<n; i++)
			vals[i] = fin.nextInt();
			
		// Call the appropriate method and output the answer!
		if (subsetSum(vals, target))
			System.out.println("It's your lucky day, you CAN buy exactly "+target+" jelly beans.");
		else
			System.out.println("Sorry, you won't be able to buy exactly "+target+" jelly beans.");
			
		fin.close();
			
	}
	
	// Returns true iff the array values has a subset of values that adds up
	// to target exactly.
	public static boolean subsetSum(int[] values, int target) {
     	return subsetSumHelp(values, target, 0);
	}
	
	// Returns true if and only if there exists a subset of values from the 
	// list values[startindex], values[startindex+1], ... 
	// values[values.length-1] that adds up to exactly target.
	public static boolean subsetSumHelp(int[] values, int target, int startindex) {
		
		// The empty set adds up to 0.
		if (target == 0)
			return true;
			
		// If we have no numbers to add, no subset can be formed.
		// Also,there are no such things as negative jelly beans, so we can
		// safely say that no negative target can be met.
		if (startindex == values.length || target < 0)
			return false;
			
		// Try NOT taking the current package, then try taking it. If either
		// option works, then this will return true, otherwise it'll return
		// false.
		return subsetSumHelp(values, target, startindex+1) ||
			   subsetSumHelp(values, target-values[startindex], startindex+1);
		
	}

}