#include int n; struct co {int x[2];}; struct co cs[200000]; struct co coss[200000]; struct co coss2[200000]; int starts[200000]; void bucket(int s, struct co* from, struct co *to) { int i; memset(starts, 0, 10002 * sizeof (int)); for (i = 0; i < n; i++) starts[from[i].x[s]+1]++; for (i = 0; i <= 10000; i++) starts[i+1]+= starts[i]; for (i = 0; i < n; i++) to[starts[from[i].x[s]]++] = from[i]; } int main(void) { int i; unsigned long long sum; while (1) { scanf("%d", &n); if (!n) return 0; for (i = 0; i < n; i++) scanf("%d%d", cs[i].x, cs[i].x + 1); sum = 0; bucket(0, cs, coss); bucket(1, coss, coss2); for (i = 0; i < n; i+=2) { sum += coss2[i+1].x[0] - coss2[i].x[0]; } bucket(1, cs, coss); bucket(0, coss, coss2); for (i = 0; i < n; i+=2) { sum += coss2[i+1].x[1] - coss2[i].x[1]; } printf("The length of the fence will be %lld units.\n", sum); } return 0; }