You maintain a fixed-capacity buffer that always holds at most the k most recently appended values. When a new value arrives and the buffer is already full, the oldest value is evicted to make room.
The first line gives q and the capacity k. Then q commands follow:
APPEND x— append the integerx. If the buffer already holdskvalues, first evict the oldest. Produces no output.SUM— print the sum of the values currently in the buffer (0 if it is empty).SIZE— print how many values are currently in the buffer (between 0 andk).
Because the buffer only ever holds the last k appended values, SUM is exactly the running total over that trailing window.
Input format
Line 1: two integers q and k.
Each of the next q lines is APPEND x, SUM, or SIZE.
Output format
For each SUM command print the current window sum; for each SIZE command print the current element count. Print answers in command order, one per line.
Constraints
- 1 ≤ q ≤ 100000
- 1 ≤ k ≤ 100000
- -1000000 ≤ x ≤ 1000000
- Every command is exactly one of the three forms above.