Back and Forth#10395

Back and Forth

1 second
128 megabytes
Medium

Farmer John has two milking barns, each with a large milk tank and a storage closet containing 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 measures exactly gallons of milk in the tank of the first barn and exactly gallons of milk in the tank of the second barn.

On Tuesday, he takes a bucket from the first barn, fills it, carries the milk to the second barn, and pours it into the tank there. He leaves the bucket at the second barn.

On Wednesday, he takes a bucket from the second barn (possibly the one he left there on Tuesday), fills it, carries the milk to the first barn, and pours it into the tank there. He leaves the bucket at the first barn.

On Thursday, he takes a bucket from the first barn (possibly the one he left there on Wednesday), fills it, carries the milk to the second barn, and pours it into the tank there. He leaves the bucket at the second barn.

On Friday, he takes a bucket from the second barn (possibly one of those he left there on Tuesday or Thursday), fills it, carries the milk to the first barn, and pours it into the tank there. He leaves the bucket at the first barn.

Farmer John then measures the milk in the tank of the first barn. How many different readings could he possibly see?

Input

The first line contains integers — the sizes of the buckets initially located at the first barn. The second line contains more integers — the sizes of the buckets initially located at the second barn. All bucket sizes are integers from to .

Output

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

Examples

In this example, there are possible values for the final amount of milk in the tank of the first barn:

: FJ could carry the same bucket back and forth on every trip, leaving the amount of milk in the tank of the first barn unchanged.

: FJ could carry gallons on Tuesday, gallons on Wednesday, gallon on Thursday, and gallon on Friday.

: FJ could carry gallon on Tuesday, gallons on Wednesday, gallon on Thursday, and gallon on Friday.

: FJ could carry gallon on Tuesday, gallons on Wednesday, gallons on Thursday, and gallons on Friday.

: FJ could carry gallon on Tuesday, gallons on Wednesday, gallon on Thursday, and gallons on Friday.

Example 1

Loading
Loading