P4832 The Beginning of Gabriel's Fall
Background
"Congratulations, Gabriel. You graduated as the top student of the year."
Gabriel, an excellent angel, graduated today as the valedictorian. From now on, she will go to the human world for further training.
"I will work hard to bring happiness to humans!" Gabriel looked forward to life in the human world.
On the first day of school, thanks to her extremely cute appearance, Gabriel was adored by her classmates. Not only was she cute, but she also had excellent grades. She was practically a goddess!
Because of her excellent grades, she was about to finish her homework quickly. However, just as she was about to finish her math homework, a cry for help came from her computer.
"Help!"
Following the cry, Gabriel looked at the computer.
"So it was a game." Gabriel saw a critically wounded warrior lying on the ground on the screen. She registered an account, chose the priest class, and healed the warrior. While Gabriel felt happy, more and more cries for help came. Gabriel healed them one by one, but her level was only 1, and her MP was certainly insufficient. When she tried to continue healing, the system prompted that MP was insufficient and displayed a pay-to-win hint: "Dragon-slaying blade, just click to get it."
"The Celestial Academy does give living expenses, but..." Gabriel looked at her bankbook, then at the screen, torn.
"Help!" "He... help..." "Help!" Gabriel watched as people cried for help one after another, yet she could do nothing. Finally, she could not hold herself back and clicked the "pay" button.
From then on, Gabriel’s fall began, and her homework got stuck on this math problem...
"Vignette, help me with my homework, please," Gabriel pleaded.
"Honestly, you’re an angel at least. You should do some of your homework yourself."
"No, I still want to play games."
"That won’t do. You’re an angel."
"I’ve decided to become a fallen angel who plays games all day and doesn’t study."
"I give up. Fine, play your game. I’ll help you write it."
Description
The problem is as follows: given some expressions composed of $\sin^2 x$ and $\cos^2 x$ with $x=\dfrac{\pi}{7}$, please find the maximum integer value you can obtain by selecting some of the expressions and summing them.
Input Format
The first line contains an integer $n$, indicating $n$ expressions.
Each of the next $n$ lines contains a string formed by $f(i)=\sin^2 x$, $\cos^2 x$ and plus signs, with $x=\dfrac{\pi}{7}$.
To simplify the input, we use `s` to represent $\sin^2 x$, `c` to represent $\cos^2 x$, and omit `f(i)=`.
Output Format
Output a single number representing the maximum integer answer. All operations are addition.
Explanation/Hint
Sample Explanation:
- If you pick all three expressions, their sum equals $3$.
Constraints:
- Let the total count of `s` and `c` be $m$.
- For $10\%$ of the testdata, $n=1$.
- For another $20\%$ of the testdata, each line is a single-term expression.
- For another $20\%$ of the testdata, $n \le 20$.
- For $100\%$ of the testdata, $n \times m \le 5 \times 10^7$, $m \le 10^6$.
Tips:
- $\forall x,\ \sin^2 x + \cos^2 x = 1$.
Translated by ChatGPT 5