#!/usr/bin/env python3
"""
FIX Protocol Parser Challenge - Python Skeleton
"""


def parse_fix_message(line):
    """
    Parse a FIX message (pipe-delimited key=value pairs) into a dict.

    Args:
        line: A FIX message string, e.g., "8=FIX.4.2|35=D|11=ORD001|55=AAPL|..."

    Returns:
        A dictionary mapping tag (string) to value (string)
    """
    msg = {}
    # TODO: Parse the pipe-delimited key=value pairs
    return msg


def main():
    n = int(input())

    # TODO: Initialize state tracking variables
    # - orders: dict mapping ClOrdID to order state
    # - Counters for each metric
    # - Sets/dicts for symbols and symbol fill tracking

    for _ in range(n):
        line = input()
        msg = parse_fix_message(line)

        # TODO: Extract message type and ClOrdID
        msg_type = msg.get('35', '')
        clord_id = msg.get('11', '')

        # TODO: Handle different message types:
        # - 'D': NewOrderSingle - register new order
        # - '8': ExecutionReport - update order state
        # - 'F': OrderCancelRequest - mark pending cancel
        # - '9': OrderCancelReject - ignore

        if msg_type == 'D':
            # NewOrderSingle: extract symbol, side, qty, price
            # Register order with initial state
            pass

        elif msg_type == '8':
            # ExecutionReport: extract exec_type, cum_qty, leaves_qty, last_px, last_qty
            # Update order state based on exec_type (0=New, 1=PartialFill, 2=Fill, 4=Canceled, 8=Rejected)
            pass

        elif msg_type == 'F':
            # OrderCancelRequest: mark order as pending cancel
            pass

        elif msg_type == '9':
            # OrderCancelReject: do nothing
            pass

    # TODO: Calculate final metrics
    # - Count fully filled orders
    # - Count partially filled orders
    # - Count canceled orders
    # - Count rejected orders
    # - Count buy/sell orders
    # - Sum total filled qty
    # - Calculate VWAP (sum of qty*price / total qty)
    # - Find symbol with highest filled qty

    # TODO: Output results (one per line, in order):
    # 1. Total messages processed
    # 2. Total unique orders
    # 3. Total fully filled orders
    # 4. Total partially filled orders
    # 5. Total canceled orders
    # 6. Total rejected orders
    # 7. Total buy orders
    # 8. Total sell orders
    # 9. Total filled quantity
    # 10. Volume-weighted average fill price (6 decimal places)
    # 11. Number of unique symbols
    # 12. Symbol with highest total filled quantity


if __name__ == "__main__":
    main()
