#P2911. Most Frequent Dice Sum
Most Frequent Dice Sum
Most Frequent Dice Sum
Bessie loves board games and role-playing games. She went to the hobby shop and purchased three fair dice with \(S_1\), \(S_2\), and \(S_3\) sides respectively, where \(2 \le S_1 \le 20\), \(2 \le S_2 \le 20\), and \(2 \le S_3 \le 40\).
Bessie rolls the dice repeatedly and wants to determine which three-dice sum appears most frequently. If more than one sum appears with the highest frequency, output the smallest such sum.
The frequency of a sum is defined as the number of outcomes (out of \(S_1 \times S_2 \times S_3\) total outcomes) that yield that sum. Formally, if the dice outcomes are \(a, b, c\) with \(1 \le a \le S_1\), \(1 \le b \le S_2\), and \(1 \le c \le S_3\), then you are to find the sum \(s = a+b+c\) that maximizes the count:
[ \text{count}(s) = #{(a, b, c) \mid a+b+c=s}. ]
If there is a tie, choose the smallest \(s\).
inputFormat
The input consists of a single line containing three space-separated integers: \(S_1\), \(S_2\), and \(S_3\).
outputFormat
Output a single integer, which is the three-dice sum that appears most frequently. In case of a tie, output the smallest sum.
sample
2 2 2
4