CF884D Boxes And Balls

Description

Ivan has $ n $ different boxes. The first of them contains some balls of $ n $ different colors. Ivan wants to play a strange game. He wants to distribute the balls into boxes in such a way that for every $ i $ ( $ 1

Input Format

N/A

Output Format

N/A

Explanation/Hint

In the first example you take all the balls from the first box, choose $ k=3 $ and sort all colors to corresponding boxes. Penalty is $ 6 $ . In the second example you make two turns: 1. Take all the balls from the first box, choose $ k=3 $ , put balls of color $ 3 $ to the third box, of color $ 4 $ — to the fourth box and the rest put back into the first box. Penalty is $ 14 $ ; 2. Take all the balls from the first box, choose $ k=2 $ , put balls of color $ 1 $ to the first box, of color $ 2 $ — to the second box. Penalty is $ 5 $ . Total penalty is $ 19 $ .