#C5371. Median Database

    ID: 49013 Type: Default 1000ms 256MiB

Median Database

Median Database

You are given an initially empty database that supports three operations:

  • a x: Add the integer x to the database.
  • r x: Remove one occurrence of the integer x from the database if it exists. If it does not exist, ignore the operation.
  • m: Output the median of the current database.

The median is defined as follows:

If the sorted database is \(a_0, a_1, \ldots, a_{n-1}\), then

  • If \(n\) is odd, the median is \(a_{\lfloor n/2 \rfloor}\).
  • If \(n\) is even, the median is \(\frac{a_{n/2-1}+a_{n/2}}{2}\).

The output must display the median as a floating point number with one decimal place. If a median query is issued when the database is empty, print "Wrong!".

inputFormat

The first line contains an integer Q representing the number of operations. The following Q lines each contain an operation in one of the following formats:

  • a x: add integer x
  • r x: remove integer x
  • m: output the median value of the current database

All input is read from stdin.

outputFormat

For every median query (m), output the median on a new line. The median must be printed as a floating point number with one decimal place. If the database is empty when a median query is issued, print "Wrong!". All output should be written to stdout.

## sample
9
a 1
a 3
m
a 5
m
r 3
m
a 2
m
2.0

3.0 3.0 2.0

</p>