Here, you have to efficiently keep a list of integer numbers, which is initially empty. Let the current list be x0, …, xn−1. There are just two operations:
Input
Input consists of several cases. Every case begins with the number of operations m, followed by the m operations. We have an M for reporting the maximum, and I x j for inserting. Assume 1 ≤ m ≤ 2 · 105, −1012 ≤ x ≤ 1012, and that j is between 0 and the current list size.
Output
For every case, and for every M operation, print the maximum sum of consecutive elements inside the current list. Print a line with 10 dashes at the end of each case.
Input
8 I 5 0 M I 1 1 M I -3 1 M I 4 2 M 3 M I -100 0 M 6 I 1000000000000 0 I 1000000000000 0 I -1 1 M I 1000000000000 3 M
Output
5 6 5 7 ---------- 0 0 ---------- 1999999999999 2999999999999 ----------