| The 21st UESTC Programming Contest Final |
|---|
| Закончено |
Given a set of $$$n$$$ binary strings, each containing only the digits $$$\texttt{0}$$$ and $$$\texttt{1}$$$, you need to find an arrangement of these strings that minimizes the total number of inverse pairs in the final concatenated string. You may rearrange the strings in any order to achieve the minimum number of inverse pairs in the concatenated string.
Let's denote the $$$i$$$-th digit of the final concatenated string as $$$s_i$$$. An inverse pair is defined as a pair of indices $$$(i,j)$$$ such that $$$i \lt j$$$ and $$$s_i \gt s_j$$$.
The first line contains an integer $$$n$$$ ($$$1 \le n \le 10^6$$$), indicating the number of binary strings.
Each of the next $$$n$$$ lines contains a binary string. The sum of the lengths of all binary strings does not exceed $$$10^6$$$.
Output a single integer representing the minimum number of inverse pairs.
3 1 11 101
1
For the sample, the final concatenated string with the minimum number of inverse pairs is $$$\texttt{101111}$$$.
| Название |
|---|


