#C10687. Custom List Operations
Custom List Operations
Custom List Operations
You are given a number of operations to perform on a custom list of integers. This list supports the following operations:
- insert x: Insert the integer \(x\) at the end of the list.
- remove i: Remove the element at index \(i\) (0-indexed). If the index is out of bounds, do nothing.
- multiply m: Multiply every element in the list by the integer \(m\). That is, each element \(a_i\) becomes \(m \times a_i\).
- sum: Output the sum of all elements in the list. The sum is defined as \(\sum_{i=1}^{n} a_i\), and if the list is empty, the sum is 0.
You need to process a sequence of operations on the list. For every sum
operation, output the current sum on a separate line.
Note: The list is initially empty.
inputFormat
The first line contains an integer \(Q\) representing the number of operations. Each of the following \(Q\) lines contains one of the commands:
insert x
— where \(x\) is an integer.remove i
— where \(i\) is the 0-indexed position to remove.multiply m
— where \(m\) is an integer multiplier.sum
— output the sum of all elements in the list.
outputFormat
For each sum
operation encountered in the input, print the resulting sum on a new line.
4
insert 1
insert 2
insert 3
sum
6
</p>