#include #include __extension__ typedef unsigned long long res_t; #define MAXP 128000 static unsigned points[MAXP][2]; static size_t column; unsigned p; static int cmp (const void *xa, const void *xb) { const unsigned *a, *b; a = xa; b = xb; if (a[column] > b[column]) return 1; if (a[column] < b[column]) return -1; if (a[1 - column] > b[1 - column]) return 1; if (a[1 - column] < b[1 - column]) return -1; return 0; } __inline__ static res_t count (void) { size_t i; res_t r; r = 0; for (i = 0; i < p - 1; i++) { if (points[i][column] == points[i + 1][column]) { r += points[i + 1][1 - column] - points[i][1 - column]; i++; } } return r; } int main (void) { for (;;) { size_t i; res_t res; scanf ("%u", &p); if (p == 0) break; for (i = 0; i < p; i++) scanf ("%u%u", points[i], points[i] + 1); res = 0; for (column = 0; column < 2; column++) { qsort (points, p, sizeof (*points), cmp); res += count (); } printf ("The length of the fence will be %llu units.\n", res); } return EXIT_SUCCESS; }