#include <bits/stdc++.h>
using namespace std;
void desperate_optimization(int precision) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.setf(ios::fixed);
  cout.setf(ios::showpoint);
  cout.precision(precision);
}
const int BLOCKS = 1e3;
const int N = 1e6;
pair<pair<int, int>, int> vec[N + 5];
vector<pair<pair<int, int>, int> > tmp;
bool cmp1(pair<pair<int, int>, int> &A, pair<pair<int, int>, int> &B) {
  return A.first.second < B.first.second;
}
bool cmp2(pair<pair<int, int>, int> &A, pair<pair<int, int>, int> &B) {
  return A.first.second > B.first.second;
}
void hora(int tc) {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    vec[i] = {{x, y}, i + 1};
  }
  sort(vec, vec + n);
  int j = 0;
  for (int i = 0; i < n; i += BLOCKS) {
    tmp.clear();
    for (int j = i; j < min(n, i + BLOCKS); j++) tmp.push_back(vec[j]);
    if (i / BLOCKS % 2)
      sort(tmp.begin(), tmp.end(), cmp2);
    else
      sort(tmp.begin(), tmp.end(), cmp1);
    for (auto x : tmp) printf("%d ", x.second);
  }
  printf("\n");
}
int main() {
  desperate_optimization(10);
  int ntc = 1;
  for (int tc = 1; tc <= ntc; tc++) hora(tc);
  return 0;
}
