#P1215. [USACO1.4] 母亲的牛奶 Mother's Milk

[USACO1.4] 母亲的牛奶 Mother's Milk

Description

Farmer John has three buckets with capacities of a,b,ca, b, c liters.

Initially, buckets aa and bb are empty, and bucket cc is full of milk. From time to time, the farmer pours milk from one bucket to another until either the receiving bucket is full or the source bucket is empty.

Each pour is complete. No milk is lost.

Write a program to help the farmer find all possible amounts of milk remaining in bucket cc when bucket aa is empty.

Input Format

A single line containing three integers a,b,ca, b, c.

Output Format

Output a single line listing, in ascending order, all possible amounts of milk in bucket cc when bucket aa is empty.

8 9 10

1 2 8 9 10

2 5 10
5 6 7 8 9 10

Hint

Constraints
For 100%100\% of the testdata, 1a,b,c201 \le a, b, c \le 20.

Problem translation from NOCOW.

USACO Training Section 1.4.

Translated by ChatGPT 5