// Arup Guha
// 12/5/2023
// Solution to COP 3502 Final Exam Part A - Thursday Version (Section 4)

#include <stdio.h>
#include <stdlib.h>

long long distsq(long long* pt1, long long* pt2);
int farthest(int curI, int* used, long long** pts, int n);
int beat(long long** pts, int curI, int i, int j);

int main() {

    // Get # of points.
    int n;
    scanf("%d", &n);

    // Allocate space to store points.
    long long** pts = calloc(n, sizeof(long long*));
    for (int i=0; i<n; i++) pts[i] = calloc(2, sizeof (long long));

    // Read in points.
    for (int i=0; i<n; i++)
        scanf("%lld%lld", &pts[i][0], &pts[i][1]);

    // Initialize used array so all items are unused except for location 0.
    int* used = calloc(n, sizeof(int));
    used[0] = 1;

    // Set up current location and accumulator.
    int curI = 0;
    long long res = 0;

    // Take n-1 trips.
    for (int i=0; i<n-1; i++) {

        // Find the index of the farthest unused point.
        int nextI = farthest(curI, used, pts, n);

        // Mark this point as used.
        used[nextI] = 1;

        // Add in the money made for this trip into our accumulator.
        res += distsq(pts[curI], pts[nextI]);

        // Update the current location for the next loop iteration.
        curI = nextI;
    }

    // Ta da!
    printf("%lld\n", res);

    // Free stuff.
    for (int i=0; i<n; i++)
        free(pts[i]);
    free(pts);
    free(used);

    return 0;
}

// Returns the distance squared between the points pointed to by pt1 and pt2.
long long distsq(long long* pt1, long long* pt2) {
    return (pt1[0]-pt2[0])*(pt1[0]-pt2[0]) + (pt1[1]-pt2[1])*(pt1[1]-pt2[1]);
}

// Returns the index of the farthest point from pts[curI] that hasn't been visited yet.
// n is the length of pts and used[i] = 1 iff location i has already been visited.
int farthest(int curI, int* used, long long** pts, int n) {

    // Store best index here.
    int res = -1;

    // Try each option next.
    for (int i=0; i<n; i++) {

        // We've used this one before.
        if (used[i]) continue;

        // Obvious update.
        if (res == -1) res = i;

        // If i is better then res, change res to i.
        else if (beat(pts, curI, i, res))
            res = i;
    }

    // This is the best place.
    return res;
}

// Returns 1 iff the distance from point curI to i is greater than the distance from curI to j, OR
// if these distances are equal but curI to i wins in a tie-breaker to curI to j.
int beat(long long** pts, int curI, int i, int j) {

    // First do distance squared calculations.
    long long d1 = distsq(pts[curI], pts[i]);
    long long d2 = distsq(pts[curI], pts[j]);

    // This case is easy.
    if (d1 > d2) return 1;

    // We also win if our distance is equal but x coordinate of the destination is less.
    if (d1 == d2 && pts[curI][0] < pts[i][0]) return 1;

    // Or if the first two metrics are equal the the y coordinate is less.
    if (d1 == d2 && pts[curI][0] == pts[i][0] && pts[curI][1] < pts[i][1]) return 1;

    // Otherwise, we don't win.
    return 0;
}
