P23193 [AtCoder] [ABC027D] Robot
提高
题目描述

Problem Description

A robot is placed at the origin of a number line. Initially, the robot's happiness is $ 0 $.

The robot is given a sequence of commands. The command sequence consists of the following $ 3 $ characters only, and they are executed from the beginning to the end in order.

  • M : Move a distance of $ 1 $ in either a positive or negative direction.
  • + : If the current coordinate is $ x $, the happiness changes by $ +x $.
  • - : If the current coordinate is $ x $, the happiness changes by $ -x $.

After executing the command sequence, the robot must be back at the origin. During the execution of the command sequence, the robot's coordinate and happiness can be negative.

Determine the final happiness when the robot moves to maximize the final happiness.

Input Format

The input is given from the standard input in the following format.

$ S $

  • The first line contains the command sequence $ S $ ($ 1≦|S|≦10^5 $). $ S $ consists only of M, +, and -, and contains an even number of Ms.

Output Format

Output the final happiness when the robot moves to maximize the final happiness in one line. End the output with a newline.

Sample Input and Output

Sample Input #1

M+MM-M

Sample Output #1

2

Sample Input #2

MMM+M

Sample Output #2

1

Sample Input #3

MMM+--MMM

Sample Output #3

3

Sample Input #4

+

Sample Output #4

0

Notes/Hints

Partial Points

This problem has partial points.

  • If you correctly solve the dataset where $ 1≦|S|≦1,000 $, you will get $ 30 $ points.

Sample Explanation 1

Here, a move in the positive direction is represented by >, and a move in the negative direction by <. Moving like >+<<-> is good.

Sample Explanation 2

For example, moving like >>><+< is good.

Sample Explanation 3

Moving like <<<+-->-> is good.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
M+MM-M
样例输出
2