Disposable Cup
Time limit1sMemory limit32 MB
Given A, B, and N, find every total height achievable by stacking N cups, where same-facing neighbors add A and opposite-facing ones add A+B.
- Level
Medium4 of 10
- Topics
- Combinatorics, Math
- Solved
- No attempts yet
Problem
Chanwoo stacks paper cups into one tower. He thinks a triangle is too hard to build, so the tower runs straight up and down. A single cup has the shape below.

One cup is tall. When a cup is nested onto a cup that faces the same way, the upper cup sinks into the lower one, so the tower grows by only . Two neighbouring cups that face opposite ways meet rim to rim or base to base and do not nest, so the two parts simply add their heights.
Six cups stacked in the pattern )(())) look like this.

With and , that tower is 156mm tall.
Chanwoo can choose the direction of every cup. Write a program that finds every tower height Chanwoo can build with cups.
Input
The first line contains , , and separated by spaces. (, )
Output
Print every achievable tower height in ascending order on one line, separated by spaces.