The Cost of Moving

No attempts yetTime limit3sMemory limit256 MB

Problem

Warehouses store products in a row. Reorder them alphabetically by moving each product to its sorted position. Sum the total warehouse-distance each product moves.

Input

Several test cases: count nn, then nn unique product names. Input ends with 00.

Output

For each site, print Site k: total.