P1215 [USACO1.4] Mother's Milk

Description

Farmer John has three buckets with capacities of $a, b, c$ liters. Initially, buckets $a$ and $b$ are empty, and bucket $c$ 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 $c$ when bucket $a$ is empty.

Input Format

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

Output Format

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

Explanation/Hint

Constraints For $100\%$ of the testdata, $1 \le a, b, c \le 20$. Problem translation from NOCOW. USACO Training Section 1.4. Translated by ChatGPT 5