#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>

struct Tick {
    long long timestamp;
    double price;
    int volume;
};

class RingBuffer {
private:
    std::vector<Tick> buffer;
    int capacity;
    int head;
    int tail;
    int count;

public:
    RingBuffer(int cap) : capacity(cap), head(0), tail(0), count(0) {
        buffer.resize(capacity);
    }

    void push(long long timestamp, double price, int volume) {
        Tick tick = {timestamp, price, volume};
        buffer[tail] = tick;
        tail = (tail + 1) % capacity;

        if (count < capacity) {
            count++;
        } else {
            head = (head + 1) % capacity;
        }
    }

    bool pop(long long& timestamp, double& price, int& volume) {
        if (count == 0) {
            return false;
        }
        Tick tick = buffer[head];
        timestamp = tick.timestamp;
        price = tick.price;
        volume = tick.volume;
        head = (head + 1) % capacity;
        count--;
        return true;
    }

    bool peek(long long& timestamp, double& price, int& volume) {
        if (count == 0) {
            return false;
        }
        Tick tick = buffer[head];
        timestamp = tick.timestamp;
        price = tick.price;
        volume = tick.volume;
        return true;
    }

    void stats(int& cnt, double& min_price, double& max_price, double& mean_price,
               long long& total_volume) {
        if (count == 0) {
            cnt = 0;
            min_price = 0;
            max_price = 0;
            mean_price = 0;
            total_volume = 0;
            return;
        }

        cnt = count;
        min_price = 1e18;
        max_price = -1e18;
        double sum_price = 0;
        total_volume = 0;

        for (int i = 0; i < count; i++) {
            int idx = (head + i) % capacity;
            Tick tick = buffer[idx];
            min_price = std::min(min_price, tick.price);
            max_price = std::max(max_price, tick.price);
            sum_price += tick.price;
            total_volume += tick.volume;
        }

        mean_price = sum_price / count;
    }
};

int main() {
    int n, c;
    if (scanf("%d %d", &n, &c) != 2) return 1;

    RingBuffer rb(c);
    char op[10];

    for (int i = 0; i < n; i++) {
        if (scanf("%s", op) != 1) break;

        if (op[0] == 'P' && op[1] == 'U') {  // PUSH
            long long timestamp;
            double price;
            int volume;
            if (scanf("%lld %lf %d", &timestamp, &price, &volume) != 3) break;
            rb.push(timestamp, price, volume);
        } else if (op[0] == 'P' && op[1] == 'O') {  // POP
            long long timestamp;
            double price;
            int volume;
            if (rb.pop(timestamp, price, volume)) {
                printf("%lld %.1f %d\n", timestamp, price, volume);
            } else {
                printf("EMPTY\n");
            }
        } else if (op[0] == 'P' && op[1] == 'E') {  // PEEK
            long long timestamp;
            double price;
            int volume;
            if (rb.peek(timestamp, price, volume)) {
                printf("%lld %.1f %d\n", timestamp, price, volume);
            } else {
                printf("EMPTY\n");
            }
        } else if (op[0] == 'S') {  // STATS
            int cnt;
            double min_price, max_price, mean_price;
            long long total_volume;
            rb.stats(cnt, min_price, max_price, mean_price, total_volume);
            printf("%d %.6f %.6f %.6f %lld\n", cnt, min_price, max_price, mean_price,
                   total_volume);
        }
    }

    return 0;
}
