/**
 * GetSharpe.io — Market Data Feed Parser
 *
 * Parse a raw market data feed of order book messages and output
 * BBO (Best Bid and Offer) snapshots at regular intervals.
 *
 * Input format (stdin):
 *   Line 1: NUM_MESSAGES SNAPSHOT_INTERVAL
 *   Lines 2..N+1: One of:
 *     A,TIMESTAMP,ORDER_ID,SIDE,PRICE,QUANTITY    (Add order)
 *     M,TIMESTAMP,ORDER_ID,NEW_QUANTITY            (Modify order)
 *     D,TIMESTAMP,ORDER_ID                         (Delete order)
 *     T,TIMESTAMP,ORDER_ID,EXEC_QUANTITY            (Trade/execute)
 *
 * Output format (stdout):
 *   After every SNAPSHOT_INTERVAL messages, output:
 *     TIMESTAMP,BID_PRICE,BID_QUANTITY,ASK_PRICE,ASK_QUANTITY
 *
 * Compile: g++ -O2 -std=c++20 -o solution solution.cpp
 */

#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <unordered_map>
#include <map>

int main() {
    int num_messages, snapshot_interval;
    scanf("%d %d", &num_messages, &snapshot_interval);

    // TODO: Implement your order book here
    //
    // Suggested data structures:
    //   - std::unordered_map<int64_t, Order> orders;   // order_id -> order details
    //   - std::map<int64_t, int64_t> bids;             // price -> aggregate quantity (best = rbegin)
    //   - std::map<int64_t, int64_t> asks;             // price -> aggregate quantity (best = begin)
    //
    // For each message:
    //   1. Parse the message type and fields
    //   2. Update the order book state
    //   3. If (message_number % snapshot_interval == 0), output the BBO

    for (int i = 1; i <= num_messages; i++) {
        // TODO: Read and parse each message line
        // TODO: Update the book based on message type (A/M/D/T)

        if (i % snapshot_interval == 0) {
            // TODO: Output BBO snapshot
            // printf("%ld,%ld,%ld,%ld,%ld\n", timestamp, bid_price, bid_qty, ask_price, ask_qty);
        }
    }

    return 0;
}
