Problem

Source: Indian Postal Coaching 2007 set 3 p6

Tags: number theory, Sum



Define the distance between two $5$-digit numbers $\overline{a_1a_2a_3a_4a_5}$ and $\overline{b_1b_2b_3b_4b_5}$ to be the largest integer $j$ such that $a_j \ne b_j$ . (Example: the distance between $16523$ and $16452$ is $5$.) Suppose all $5$-digit numbers are written in a line in some order. What is the minimal possible sum of the distances of adjacent numbers in that written order?