public void solve() throws IOException {
    while (true) {
      int numtargets = nextInt();
      if (numtargets == 0)
        break;

      int[][] points = new int[numtargets + 2][3];
      for (int x = 0; x < numtargets; x++)
        for (int y = 0; y < 3; y++)
          points[x + 1][y] = nextInt();
      points[numtargets + 1][0] = 100;
      points[numtargets + 1][1] = 100;

      int pos = 0;
      double total = 0;
      while (pos != numtargets + 1) {
        int move = pos + 1;
        double distance = getdist(points[pos][0] - points[pos + 1][0], points[pos][1]
            - points[pos + 1][1]) + 1;
        double mindist = distance;
        int penalty = points[pos + 1][2];
        for (int x = pos + 2; x < numtargets + 2; x++) {
          distance += getdist(points[x - 1][0] - points[x][0], points[x - 1][1] - points[x][1]) + 1;
          double newdist = getdist(points[pos][0] - points[x][0], points[pos][1] - points[x][1]) + 1;
          newdist += penalty;
          System.out.println(distance + " " + newdist);
          if (newdist < distance) {
            move = x;
            mindist = newdist;
          }
          penalty += points[x][2];
        }
        System.out.println(move);
        pos = move;
        total += mindist;
      }

      System.out.println(total);

      // DecimalFormat df = new DecimalFormat("#.00");
      // System.out.println(df.format((double)Math.round(1 * 100) / 100));
    }
  }