Balance Game

Consider a puzzle with three types of tokens. Tokens of the same type have the same weight and any two tokens of different type have different weight. There are M copies of each token type. There is a two-plate scale where tokens can be placed. There is also a given object with known weight W that can be put on the plates of the scale. The goal of the puzzle is to balance the scale with some of the tokens to check the weight of the object. If used, tokens of the same type must be allocated on the same plate. For example, suppose that there are three token types with weights 20, 50, and 40 grams, respec- tively. Also, there are M = 3 copies of each token type. If the given object weights W = 140 grams, then its weight can be checked in five different ways (neglecting the order of the plates): Five different ways to achieve the goal However, it is impossible to measure the weight W = 105 with this set of tokens. Your job is to write a computer program to determine the number of different ways to check the weight of the object. Input The input consists of several test cases. The first line of each test case contains two blank-separated integers M and W (1 ≤ M ≤ 5000 and 1 ≤ W ≤ 5000000) indicating, respectively, the number of copies of each token type and the weight of the object to be checked. Then there is a line containing three distinct blank-separated integers n1, n2, and n3 representing the weigths of each token type (1≤ni ≤1000,foreach1≤i≤3,n1 ̸=n2,n1 ̸=n3,n2 ̸=n3). Output For each test case, print a single line indicating the number of different ways the given weight can be checked with the set of tokens. Sample Input 3 140 20 50 40 3 105 20 50 40 Sample Output 5 0