#!/usr/bin/env python3
"""Ring Buffer Challenge - Python skeleton."""


class Tick:
    def __init__(self, timestamp, price, volume):
        self.timestamp = timestamp
        self.price = price
        self.volume = volume


class RingBuffer:
    def __init__(self, capacity):
        self.capacity = capacity
        self.buffer = [None] * capacity
        self.head = 0
        self.tail = 0
        self.count = 0

    def push(self, timestamp, price, volume):
        tick = Tick(timestamp, price, volume)
        self.buffer[self.tail] = tick
        self.tail = (self.tail + 1) % self.capacity

        if self.count < self.capacity:
            self.count += 1
        else:
            self.head = (self.head + 1) % self.capacity

    def pop(self):
        if self.count == 0:
            return None
        tick = self.buffer[self.head]
        self.head = (self.head + 1) % self.capacity
        self.count -= 1
        return tick

    def peek(self):
        if self.count == 0:
            return None
        return self.buffer[self.head]

    def stats(self):
        if self.count == 0:
            return 0, 0, 0, 0, 0

        min_price = float('inf')
        max_price = float('-inf')
        sum_price = 0
        total_volume = 0

        for i in range(self.count):
            idx = (self.head + i) % self.capacity
            tick = self.buffer[idx]
            min_price = min(min_price, tick.price)
            max_price = max(max_price, tick.price)
            sum_price += tick.price
            total_volume += tick.volume

        mean_price = sum_price / self.count

        return self.count, min_price, max_price, mean_price, total_volume


def main():
    n, c = map(int, input().split())
    rb = RingBuffer(c)

    for _ in range(n):
        line = input().split()
        op = line[0]

        if op == "PUSH":
            timestamp = int(line[1])
            price = float(line[2])
            volume = int(line[3])
            rb.push(timestamp, price, volume)
        elif op == "POP":
            tick = rb.pop()
            if tick is None:
                print("EMPTY")
            else:
                print(f"{tick.timestamp} {tick.price:.1f} {tick.volume}")
        elif op == "PEEK":
            tick = rb.peek()
            if tick is None:
                print("EMPTY")
            else:
                print(f"{tick.timestamp} {tick.price:.1f} {tick.volume}")
        elif op == "STATS":
            cnt, min_price, max_price, mean_price, total_volume = rb.stats()
            if cnt == 0:
                print("0 0.000000 0.000000 0.000000 0")
            else:
                print(f"{cnt} {min_price:.6f} {max_price:.6f} {mean_price:.6f} {total_volume}")


if __name__ == "__main__":
    main()
