#P5118. Back and Forth Milk Transfers

    ID: 18356 Type: Default 1000ms 256MiB

Back and Forth Milk Transfers

Back and Forth Milk Transfers

Farmer John has two milking barns. Each barn contains a milk tank and a storage cabinet with 10 buckets of distinct sizes. On Monday, he fills both tanks with exactly 1000 gallons of milk. Then, for four consecutive days he makes the following transfers:

  • Tuesday: Pick a bucket from the first barn, fill it to the brim, and transfer its milk to the second barn. Leave the bucket in the second barn.
  • Wednesday: Pick a bucket from the second barn (which now contains its original 10 buckets plus the one transferred on Tuesday), fill it, and transfer its milk to the first barn. Leave the bucket in the first barn.
  • Thursday: Pick a bucket from the first barn (which now contains 10 buckets again) to transfer milk to the second barn. Leave the bucket in the second barn.
  • Friday: Pick a bucket from the second barn (which now contains 10 buckets) to transfer milk to the first barn. Leave the bucket in the first barn.

After these transfers, the final milk quantity in the first barn is given by the formula in \(\LaTeX\):

[ \text{final} = 1000 - b + c - d + e, ]

where:

  • \(b\) is the capacity of the bucket chosen on Tuesday from the first barn.
  • \(c\) is the capacity of the bucket chosen on Wednesday from the second barn.
  • \(d\) is the capacity of the bucket chosen on Thursday from the first barn.
  • \(e\) is the capacity of the bucket chosen on Friday from the second barn.

Your task is to determine how many distinct final readings (milk quantities in the first barn) are possible given the bucket capacities.

inputFormat

The input consists of two lines:

  • The first line contains 10 space‐separated integers representing the sizes of the buckets in the first barn.
  • The second line contains 10 space‐separated integers representing the sizes of the buckets in the second barn.

outputFormat

Output a single integer denoting the number of distinct possible final milk measurements in the first barn's tank.

sample

1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1