#include <iostream>
#include <cstdio>
#include <mm_malloc.h>
using namespace std;
//构建双向队列
typedef struct Node{
int data;
Node* next;
Node* pre;
}Node;
class LinkList{
private :
Node *head;
Node *tail;
public:
int length;
LinkList();
Node* makeNode();
void insertAsLast(int e);
void insert(int data);
int popfirst();
int remove();
void clear();
};
LinkList::LinkList(){
head = makeNode();
tail = makeNode();
head->next = tail;
head->pre = NULL;
tail->pre = head;
tail->next = NULL;
length = 0;
}
//初始化
Node* LinkList::makeNode(){
Node * node = (Node*)malloc(sizeof(Node));
return node;
}
//插入新的最大值
void LinkList::insert(int e){
Node* node = makeNode();
Node* p = makeNode();
Node* q = makeNode();
p->data = e;
node = tail->pre;
while ((node->data)<e&&node!=head) node = node->pre;
node->next->pre = p;
p->next = node->next;
node->next = p;
p->pre = node;
q = p->next;
while( q!= tail){
q->data = e;
q = q->next;
}
length++;
}
//尾部插入
void LinkList::insertAsLast(int data){
Node *node = makeNode();
tail->pre->next = node;
node->pre = tail->pre;
node->next = tail;
tail->pre = node;
node->data = data;
length++;
}
//输出最大值
int LinkList::popfirst(){
int result = head->next->data;
return result;
}
//消除
int LinkList::remove(){
int result;
Node* node = makeNode();
node = head->next;
result = node->data;
node->next->pre = head;
head->next = node->next;
free(node);
length--;
return result;
}
//析构
void LinkList::clear(){
Node* node = makeNode();
Node* n = makeNode();
node = head->next;
while(node != tail){
remove();
node = head->next;
}
}
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
//输入
setvbuf(stdin, new char[1 << 20], _IOFBF, 1 << 20);
setvbuf(stdout, new char[1 << 20], _IOFBF, 1 << 20);
int i,n; char ope; i = 0;
long long int sumvalue;
char *opex = new char[2];
scanf("%d" ,&n);
LinkList maxprice;
//操作
while(i<n&&scanf("%s",opex)!=EOF){
ope = opex[0];
if(ope == 'E'){
int price;
scanf("%d", &price);
if(maxprice.length == 0){
maxprice.insertAsLast(price);
}
else{
maxprice.insert(price);
}
sumvalue = (long long int)maxprice.popfirst()*(long long int)maxprice.length;
printf("%lld", sumvalue);
if (i != n-1) printf("\n");
}
else{
int b = maxprice.remove();
sumvalue = (long long int)maxprice.popfirst()*(long long int)maxprice.length;
printf("%lld", sumvalue);
if (i != n-1) printf("\n");
}
i++;
}
//析构
maxprice.clear();
return 0;
}