You have stones to distribute between two piles with different weights. Each stone adds to pile 1 or to pile 2.
Try all possible distributions: give stones to pile 1 (0 to n).
The remaining go to pile 2.
Calculate pile 1 weight: . Calculate pile 2 weight: .
Count this as a valid outcome. Store all unique (weight1, weight2) pairs.
The answer is how many unique pairs exist. Use a set to avoid counting duplicates.