output_description: Print the minimum necessary amount of money in order to build roads so that it
  will be possible to travel between every pair of towns by traversing roads.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      x_1 y_1
      x_2 y_2
      :
      x_N y_N
attempt: """
  
  
  
                                                ...(ggNMMMMMMMMMNg+...
                                         ..(gMH9"^`                ?"YMa,
                                    ..gMY"!                             7Mm.
                              ` ..gM9^                                    (Ma.`  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `
      `  `  `  `  `  `  `  ` .JM9^                           `              ?Ma
                         ..M#"`            .h       ..g   `     `             TN,
                       .d#^                 (b ..+MY"!               `         ?N.
     `             `..M"               ` `..&M#"!                               UN   `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `
                 `.+#^           .b  `..MY"! ,N             `  `  `              M[
        `  `  ` .J#^              WJ+#"`     .gNe                     `  `       dF
               .M=             ..gHN    ..J#9= W/         `                      JF
              J@              ."`  d|.-"=      .N.    `                     `    MF
            .dF                    ,N         ..M#=           `  `  `           .M`    `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `
     `  `  .MD                      Up  ...k#M=     `  ..`             `      `.M^
           dF             `          ?"""!   ,p  ...gM9"`                 `   (#!
          .#                                 .MgMD^         `      `        .M"
          d]                             ..H94#N-TWMNag+J......J+ggMWY    .MD`
          M}                          .J9^  .M!,b           `         `.+M"
          M]                        T"`    .B`  vb                  .(MD`                                                          ` ...JgMH""""""MNa,`
          -N.                            .Mt     Up             ..gM"'                                                      ` ..(gMH9"^`             TN,
           ?N,                         .J@`       W[        ..gM"!                                                   `  ..JH#""!                      .Hp
            .Wm,                       (!         ,@    ..+MB=                                                   ` ..+MB"!                             .M[
              .TNa,                          .,  ...&MMY"^                                                   `...g#"!                                   ,N,
                 .TWNg... `       `  ...    .MMH9"=`                                                     .gWH9"!                                         db
                      _7T"HMMNHQQkMM9"`M.   d\                                                                                                       ... .M,
                                       J]   #                     `   `              `   ` ` ................                       .......JggHMMM"""""`  dN
                                       .N. .#                               ` .....JggHMMH""""""""""7"""""""""""HMMMNNg+-....     7"""7?!                 .M[
                                        -b .#       `  `            ` ...gHM""""!`                                       ?7"T"HMMNg+....                   (N.
                                         vp M.             `  ...(gMMMMNNggg+(....                                                  _?""WMNNg...            M\
                                          ?bJ]           ..gMY""!`           `??""WMNJ,                                                      _7TWMNgJ..                 `  ...JggHHNag-,. `
                                           ,HN.   `   .+M9^                          _TMNJ,                                                          ?TWMNJ..   `  `  ..gM9"!          ?"Ma,
                                     `       ,H\   .(MD!                                 ?WNx.                                                             ?THNg.,..dB=                   .TN,
                                                 .d#^                                       ?MN,                      Q,                                        ?TMm.                        TN,
                                         `     .d#^                         ..&MM;            .TN,                     .W,                                                                    .Mp `
                                      `      .(M=                      ..gMB@!                  .WN,                     ?b                                                                     Wb
                                           `.M"          ...   `    `  ?`   M.                    ?Me                     ?b                                                                     Mp
                                          .j#`      ..&MH"79                db                     .Mb                     ?b                                           ........                 ,M,
                                     `   .MF  ...gM#"4,                     .M,                      UN.                    ?b                                          `     ?""HNgJ,            JN
                                        .M$   (=`    M[           `          ,M] ..                   TN.                    Tb                                                      TD            M]
                                        dF           Jb                     .(HY""!                    UN.                    Wb                                                                   -N.
                                       .M`           ,M,              `   ,"^                           Mb                     Mc                                                                   M]
                                     ` dF             -W:..gMM@   `                                     ,M.                    ,N.                                           ""9Sa,.                J#
                                       M]         ` ..gM9"`           .m                                 M]                     H]                                                 `                ,M.
                                       M]    `     T=`                 M_                                db                     -N                                                                   M)
                                       MF                              M)                                J#                     ,M.                                         .aJ.....                 M]
                                       d@                       `   `  M)                                J#                     .M_                                               ?7TBNgJ,           M]
                                       J#    `                        .M+..(gx                           J#                     .M`                                                      ?^          M]
                                     ` ,M.        `         `          _7?!                              dF                     .#                                      .,                           M%
                                        M]                      `                                        MF                     JF                                   .(M"                           .M!
                                        JN.             `           `                                   .M}                                                    ` ..g#"`                             dF
                                         WN   `     `                                                   -#                                                ` ..JMY"!                                .M`
                                     `    WN.               `                       ...&gM]             MF                                           `  ..gM9^               ,NJ,                 .M^
                                           TN,                 `   `   `    ...JgMHB"=`               `(#                                       `  ..gMB"!                     ?TMMNggJ.........gM@`
                                            ?N,   `   `                ..gMW""!                       .M!                                     ..&MY"!                                 `?7"""""7!
                                     `       ?N,          `       ..&MB"`                           .dB`                               ` ..+MY"!
                                              (Ma.           ..+MB"!                              `.MD                          `  ...gMB"!
                                                7Ma.   `    .=`                                  .J#'                     `  `..JMH9"`
                                     `   `        ?HN,                                       ` .uM=                      ..+MY"^
                                                    .TMg,                                   .JM9!                ` ...gM""!
                                                       .TMN.,                            .+M9'                ..&M#"=`
                                     `    `   `            ?TMNg...            ..    ..gM"!            ...gMY"=`
                                                                ?"""HMMMMMMMY""=(.gMM9^         ...JkMB"^
                                                                            .T"9"!      ...JdM"""!
                                     `   `        `                          .....JdT"""!
                                             `        `   `                ?!`
  """
problem_description: Statement
  
  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.
  
  You 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.
  
  Your 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?
samples: [{"input": "3\n    1 5\n    3 9\n    7 8", "output": "3\n    \n\nBuild a road between Towns 1 and 2, and another between Towns 2 and 3. The\ntotal cost is 2+1=3 yen.\n\n* * *"}, {"input": "6\n    8 3\n    4 9\n    12 19\n    18 1\n    13 5\n    7 6", "output": "8"}]