Official algorithmic problem description and constraints.
There are balls of π different colors; the number of balls of the π-th color is ππ.
The balls can be combined into groups. Each group should contain at most 2 balls, and no more than 1 ball of each color.
Consider all 2π sets of colors. For a set of colors, let's denote its value as the minimum number of groups the balls of those colors can be distributed into. For example, if there are three colors with 3, 1 and 7 balls respectively, they can be combined into 7 groups (and not less than 7), so the value of that set of colors is 7.
Your task is to calculate the sum of values over all 2π possible sets of colors. Since the answer may be too large, print it modulo 998244353
Detailed video explanations, mathematical intuition, and clean C++ implementation code.