You are given a string expression that represents an algebraic formula. The formula consists of lowercase English letters (standing for variables), the binary operators "+" and "-", and parentheses "(" and ")" used for grouping. No other characters appear.
Your task is to return the simplest equivalent expression by eliminating every unnecessary pair of parentheses and correctly flipping the signs of the enclosed terms. The output must preserve the original order of operations and evaluate to the same value as the input, assuming standard rules for addition and subtraction.
Example 1:
Input: expression = "a-(b+c)"
Output: "a-b-c"
Explanation: Removing the parentheses and distributing the negative sign results in "a-b-c".
Example 2:
Input: expression = "a-(-b-c)"
Output: "a+b+c"
Example 3:
Input: expression = "(x+y)-z"
Output: "x+y-z"
Constraints:
1 <= expression.length <= 10^5"+", "-", "(", and ")".