Best Machine Rental Profit

No attempts yetTime limit2sMemory limit512 MB

Problem

A rental company owns machines whose performance changes over time. In each time unit a machine works at one of seven performance levels, and the level fixes the profit or the loss of that time unit.

LetterPerformanceProfit per time unit
ooutstandingSGD 100
eextraordinarySGD 10
ggoodSGD 1
aaverageSGD 0
bbadSGD -1
iinsufficientSGD -10
uunsatisfactorySGD -100

A customer rents a machine for one contiguous interval of time units, so the profit of a rental is the sum of the values of the letters inside that interval. For each machine, find the largest profit that a contiguous interval reaches. A customer may also walk away without renting, so the answer is 0 when every interval ends in a loss.

The record aabbg gives 1, because only the last time unit earns anything. The record ggbgg gives 3: absorbing the single loss in the middle and renting the whole runtime pays better. The record ggbggbuoeg gives 111, reached on the interval oeg.

For the record ggue the distinct intervals and their profits are:

IntervalProfit
g1
gg2
ggu-98
ggue-88
gu-99
gue-89
u-100
ue-90
e10

The largest of them is 10, so the answer for ggue is 10.

Input

The input is a single stream of characters that lists the record of one machine after another. A comma , separates the record of a machine from the record of the next one, and a period . follows the record of the last machine. A record uses the performance letters u, i, b, a, g, e, o described above. Spaces and line breaks carry no meaning and are ignored.

Output

Print one number per line. The number on line i is the largest profit that a contiguous interval of machine i reaches. The number of printed lines equals the number of commas and periods in the input.