cswork / OAOpen practice workspace

Goldman SachsOA #27

Product of the Maximum and Minimum in a Dataset

Estimated MediumJudge-ready

Topics (AI-labelled)Stacks & HeapsHashing

Starting from an empty multiset, process the operations in order: push x inserts one x; pop x removes a single copy of an x that is currently present. After each operation, output the product of the current minimum and maximum of the set; if the set is empty, output 0, consistent with all three implementations in the fixed source (Python, Java, C++).

Input

The first line contains the number of operations n, followed by n lines, each push x or pop x. Complete original constraints: 1≤n≤100000, 1≤x≤10^9; whenever a pop is executed, the current multiset contains at least one x. The ranges of the fixed complete raw are kept; the standard input/output is this site's wrapper.

Output

On each line, output the product after the corresponding operation; output 0 when the multiset is empty. Compute the product as a 64-bit integer.

Example 1

Input:

4
push 1
push 2
push 3
pop 1

Output:

1
2
3
6

Example notes

Duplicate values are handled as a multiset, and pop removes only one copy; this behavior matches the reference implementations in the three languages of the fixed source.

Editorial

Loading solution…