#C4788. Process Sequence Operations

    ID: 48364 Type: Default 1000ms 256MiB

Process Sequence Operations

Process Sequence Operations

You are given an initially empty integer sequence and a list of operations to perform on this sequence. After each operation, you must output the current sum of all integers in the sequence.

The allowed operations are:

  • ADD X: Append integer \(X\) to the sequence.
  • REMOVE X: Remove the first occurrence of integer \(X\) from the sequence if it exists.
  • REPLACE X Y: Replace the first occurrence of integer \(X\) with integer \(Y\) if \(X\) exists.

Let \(S\) denote the sum of all elements in the sequence. Initially, \(S=0\). After each operation, update \(S\) accordingly and print its value.

inputFormat

The first line contains an integer \(n\), the number of operations.

Each of the next \(n\) lines contains a single operation in one of the formats:

  • ADD X
  • REMOVE X
  • REPLACE X Y

Here \(X\) and \(Y\) are integers.

outputFormat

Print \(n\) lines. The \(i\)-th line should contain the current sum of the sequence after executing the first \(i\) operations.

## sample
5
ADD 5
ADD 3
REMOVE 5
ADD 10
REPLACE 3 7
5

8 3 13 17

</p>