Programming Problem #31
"Football Scores"

The National Football League is considering changing the scoring rules. Currently a touchdown is worth 6 points, a PAT (points after touchdown) is worth either 1 or 2 points, a field goal is worth 3 points, and a safety is worth 2 points. (If you are not familiar with football, it is not necessary to know what these actions are in order to solve this problem.) As it experiments with different scoring rules, the NFL wants to know how many ways a given score can be obtained. For example, under the current rules the score 9 can be obtained in four different ways: (1) 3 field goals; (2) a touchdown, no PAT, and a field goal; (3) a touchdown with a 1-point PAT and a safety; and (4) a field goal and three safeties.

The input will consist of one or more lines, each of which will contain five positive integers, separated by spaces: T, P, F, S, and A. The first four numbers are the points to be scored for a touchdown, PAT, field goal, and safety; each will be less than 100. A is a potential score to be analyzed, and will be less than 1000. For each line of input, output a line indicating the number of different ways that the score A could be obtained, subject to the requirement that at most one PAT can be scored per touchdown. The output format must be exactly as shown in the examples below.

Input must be read from the file "prob31.in", and output must be written to the file "prob31.out". All output to the screen will be ignored.


Example Input

<BOF>
6 1 3 2 7
6 1 3 2 6
6 1 3 2 1
4 2 3 5 13
13 7 9 8 23
<EOF>

Example Output

6,1,3,2: 7 can be obtained in 2 way(s)
6,1,3,2: 6 can be obtained in 3 way(s)
6,1,3,2: 1 can be obtained in 0 way(s)
4,2,3,5: 13 can be obtained in 4 way(s)
13,7,9,8: 23 can be obtained in 0 way(s)

A version of this problem originally appeared in the 1991 ACM North Central regional programming contest.

Dr. Eric Shade