P5118 [USACO18DEC] Back and Forth B

Description

Farmer John has two milking barns. In each barn, there is a milk tank and a storage cabinet holding $10$ buckets of various sizes. He likes to carry milk back and forth between the two barns as a form of exercise. On Monday, Farmer John measured exactly $1000$ gallons of milk into the tank in the first barn, and also measured exactly $1000$ gallons of milk into the tank in the second barn. On Tuesday, he takes one bucket from the first barn, fills it with milk, then carries the milk to the second barn and pours it into the tank. He leaves this bucket in the second barn. On Wednesday, he takes one bucket from the second barn (possibly the one left there on Tuesday), fills it with milk, then carries the milk to the first barn and pours it into the tank. He leaves this bucket in the first barn. On Thursday, he takes one bucket from the first barn (possibly the one left there on Wednesday), fills it with milk, then carries the milk to the second barn and pours it into the tank. He leaves this bucket in the second barn. On Friday, he takes one bucket from the second barn (possibly the one left there on Tuesday or Thursday), fills it with milk, then carries the milk to the first barn and pours it into the tank. He leaves this bucket in the first barn. At this point, Farmer John measures the milk in the tank in the first barn. How many different readings could he possibly get in total?

Input Format

The first line contains $10$ integers, the capacities of the buckets initially in the first barn. The second line also contains $10$ integers, the capacities of the buckets initially in the second barn. All bucket capacities are in the range $1\dots 100$.

Output Format

Output the number of possible readings Farmer John could get when measuring the milk in the tank in the first barn after Friday.

Explanation/Hint

In this example, there are $5$ possible final amounts of milk in the first barn's tank: $1000$: FJ can carry the same bucket on every trip, so the amount of milk in the first barn's tank does not change. $1003$: FJ can move $2$ units on Tuesday, $5$ units on Wednesday, $1$ unit on Thursday, and $1$ unit on Friday. $1004$: FJ can move $1$ unit on Tuesday, $5$ units on Wednesday, $1$ unit on Thursday, and $1$ unit on Friday. $1007$: FJ can move $1$ unit on Tuesday, $5$ units on Wednesday, $2$ units on Thursday, and $5$ units on Friday. $1008$: FJ can move $1$ unit on Tuesday, $5$ units on Wednesday, $1$ unit on Thursday, and $5$ units on Friday. Translated by ChatGPT 5