luogu#P5118. [USACO18DEC] Back and Forth B

[USACO18DEC] Back and Forth B

Problem Description

Farmer John has two milking barns. In each barn, there is a milk tank and a storage cabinet holding 1010 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 10001000 gallons of milk into the tank in the first barn, and also measured exactly 10001000 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 1010 integers, the capacities of the buckets initially in the first barn. The second line also contains 1010 integers, the capacities of the buckets initially in the second barn. All bucket capacities are in the range 11001\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.

1 1 1 1 1 1 1 1 1 2
5 5 5 5 5 5 5 5 5 5
5

Hint

In this example, there are 55 possible final amounts of milk in the first barn's tank:

10001000: FJ can carry the same bucket on every trip, so the amount of milk in the first barn's tank does not change.

10031003: FJ can move 22 units on Tuesday, 55 units on Wednesday, 11 unit on Thursday, and 11 unit on Friday.

10041004: FJ can move 11 unit on Tuesday, 55 units on Wednesday, 11 unit on Thursday, and 11 unit on Friday.

10071007: FJ can move 11 unit on Tuesday, 55 units on Wednesday, 22 units on Thursday, and 55 units on Friday.

10081008: FJ can move 11 unit on Tuesday, 55 units on Wednesday, 11 unit on Thursday, and 55 units on Friday.

Translated by ChatGPT 5