#include <bits/stdc++.h>
using namespace std;
struct query {
  int l, r, id;
} a[1000010];
int n, i, b[1000010], gap;
int read() {
  char c = getchar();
  int w = 0;
  while (c < '0' || c > '9') c = getchar();
  while (c <= '9' && c >= '0') {
    w = w * 10 + c - '0';
    c = getchar();
  }
  return w;
}
int my_comp(const query &x, const query &y) {
  if (b[x.l] == b[y.l]) {
    if (b[x.l] % 2 == 0)
      return x.r < y.r;
    else
      return x.r > y.r;
  }
  return x.l < y.l;
}
int main() {
  n = read();
  gap = sqrt(1.0 * n);
  for (i = 1; i <= 1000001; i++) b[i] = (i - 1) / gap + 1;
  for (i = 1; i <= n; i++) {
    a[i].l = read() + 1, a[i].r = read() + 1;
    a[i].id = i;
  }
  sort(a + 1, a + n + 1, my_comp);
  for (i = 1; i <= n; i++) printf("%d ", a[i].id);
  puts("");
  return 0;
}
