#P4832. Maximum Integer Sum from Trigonometric Squares
Maximum Integer Sum from Trigonometric Squares
Maximum Integer Sum from Trigonometric Squares
You are given a list of expressions, each of which is either \(\sin^2x\) or \(\cos^2x\) with \(x = \frac{\pi}{7}\). Recall that for any angle \(x\), the identity \(\sin^2x + \cos^2x = 1\) always holds. You are allowed to choose a subset of these expressions such that the sum of the chosen values is an integer. Determine the maximum integer value you can obtain.
Explanation: The only way to obtain an integer sum is to select an equal number of \(\sin^2x\) and \(\cos^2x\) terms because each pair contributes exactly \(1\) to the sum. Therefore, the maximum integer sum is equal to the minimum of the count of \(\sin^2x\) and \(\cos^2x\) in the provided list.
inputFormat
The first line contains an integer \(n\) representing the number of expressions. The second line contains \(n\) space-separated strings. Each string is either sin
(representing \(\sin^2x\)) or cos
(representing \(\cos^2x\)).
outputFormat
Output a single integer: the maximum integer sum that can be obtained by choosing a subset of the given expressions.
sample
4
sin cos cos sin
2