You are given transaction-level cost data that may contain duplicate records and missing cost values. Write a PostgreSQL query that returns one reporting row per customer and month, using the latest version of each transaction, removing duplicate transaction records, and replacing null cost values with the customer’s average non-null cost for that month. If a customer-month has no non-null cost at all, use 0.