{"raw_statement":[{"iden":"problem statement","content":"There are $N$ towns on a plane. The $i$\\-th town is located at the coordinates $(x_i,y_i)$. There may be more than one town at the same coordinates.\nYou can build a road between two towns at coordinates $(a,b)$ and $(c,d)$ for a cost of $min(|a-c|,|b-d|)$ yen (the currency of Japan). It is not possible to build other types of roads.\nYour objective is to build roads so that it will be possible to travel between every pair of towns by traversing roads. At least how much money is necessary to achieve this?"},{"iden":"constraints","content":"*   $2 ≤ N ≤ 10^5$\n*   $0 ≤ x_i,y_i ≤ 10^9$\n*   All input values are integers."},{"iden":"input","content":"Input is given from Standard Input in the following format:\n\n$N$\n$x_1$ $y_1$\n$x_2$ $y_2$\n:\n$x_N$ $y_N$"},{"iden":"sample input 1","content":"3\n1 5\n3 9\n7 8"},{"iden":"sample output 1","content":"3\n\nBuild a road between Towns $1$ and $2$, and another between Towns $2$ and $3$. The total cost is $2+1=3$ yen."},{"iden":"sample input 2","content":"6\n8 3\n4 9\n12 19\n18 1\n13 5\n7 6"},{"iden":"sample output 2","content":"8"}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}