import sys

def main():
    # TODO: Read first line: SIDE, TOTAL_QTY, NUM_BARS
    line = input().strip()
    parts = line.split()
    side = parts[0]  # "BUY" or "SELL"
    total_qty = int(parts[1])
    num_bars = int(parts[2])

    # TODO: Read all market data bars
    # Format: timestamp,open,high,low,close,volume
    bars = []
    for _ in range(num_bars):
        line = input().strip()
        tokens = line.split(',')
        timestamp = int(tokens[0])
        open_price = float(tokens[1])
        high_price = float(tokens[2])
        low_price = float(tokens[3])
        close_price = float(tokens[4])
        volume = int(tokens[5])
        bars.append({
            'timestamp': timestamp,
            'open': open_price,
            'high': high_price,
            'low': low_price,
            'close': close_price,
            'volume': volume
        })

    # TODO: Compute arrival_price (first bar's open)
    arrival_price = bars[0]['open']

    # TODO: TWAP Strategy
    # - base_qty = total_qty // num_bars
    # - remainder = total_qty % num_bars
    # - First 'remainder' bars execute base_qty + 1, others execute base_qty
    # - Execution price at each bar: (open + high + low + close) / 4
    twap_qty = []
    twap_total_cost = 0.0
    twap_bars_executed = 0

    # TODO: VWAP Strategy
    # - Sum total volume across all bars
    # - For each bar, compute cumulative volume fraction
    # - child_qty_i = round(total_qty * cum_frac) - already_executed
    # - Last bar gets remainder to ensure sum = total_qty
    vwap_qty = []
    vwap_total_cost = 0.0
    vwap_bars_executed = 0

    # TODO: Calculate average prices
    twap_avg_price = 0.0
    vwap_avg_price = 0.0

    # TODO: Compute implementation shortfalls
    # For BUY: shortfall = (avg_price - arrival_price) / arrival_price
    # For SELL: shortfall = (arrival_price - avg_price) / arrival_price
    twap_shortfall = 0.0
    vwap_shortfall = 0.0

    # Output 9 lines, 6 decimal places
    print(f"{arrival_price:.6f}")
    print(f"{twap_avg_price:.6f}")
    print(f"{vwap_avg_price:.6f}")
    print(f"{twap_shortfall:.6f}")
    print(f"{vwap_shortfall:.6f}")
    print(f"{twap_total_cost:.6f}")
    print(f"{vwap_total_cost:.6f}")
    print(f"{twap_bars_executed}")
    print(f"{vwap_bars_executed}")

if __name__ == '__main__':
    main()
