#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1002015;
int n;
pair<pair<int, int>, int> s[MAX_N];
bool cmp2_0(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {
  return a.first.second < b.first.second;
}
bool cmp2_1(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {
  return a.first.second > b.first.second;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &s[i].first.first, &s[i].first.second);
    s[i].second = i;
  }
  sort(s, s + n);
  int sqrt_n = int(sqrt(n));
  int j = 0;
  int cnt = 0;
  for (int i = 1000; j < n; i += 1000) {
    cnt = !cnt;
    int op = j;
    while (j < n && s[j].first.first <= i) ++j;
    if (cnt)
      sort(s + op, s + j, cmp2_1);
    else
      sort(s + op, s + j, cmp2_0);
  }
  for (int i = 0; i < n; ++i) {
    printf("%d ", s[i].second + 1);
  }
  puts("");
  return 0;
}
