#include <bits/stdc++.h>
using namespace std;
const int int_inf = 0x3f3f3f3f;
const double double_inf = 1e30;
inline int readint() {
  bool neg = 0;
  char ch, t[11];
  int k = 0;
  while ((ch = getchar()) == ' ' || ch == '\n')
    ;
  neg = ch == '-';
  ch == '-' ? neg = 1 : t[k++] = ch;
  while ((ch = getchar()) >= '0' && ch <= '9') t[k++] = ch;
  int x = 0, y = 1;
  while (k) x += (t[--k] - '0') * y, y *= 10;
  return neg ? -x : x;
}
inline void readstr(char *s) {
  char ch;
  while ((ch = getchar()) == ' ' || ch == '\n')
    ;
  *(s++) = ch;
  while ((ch = getchar()) != ' ' && ch != '\n') *(s++) = ch;
  *s = '\0';
}
inline void writestr(const char *s) {
  while (*s != '\0') putchar(*(s++));
  putchar('\n');
}
inline long long readll() {
  long long x;
  scanf("%lld", &x);
  return x;
}
int debug = 0;
const int maxn = 1e6 + 10;
vector<int> a[maxn];
pair<pair<int, int>, int> b[maxn];
int main() {
  if (debug) freopen("in.txt", "r", stdin);
  int n;
  while (~scanf("%d", &n)) {
    int R = 1000, C = 1000;
    for (int i = 1; i <= n; i++) {
      int x = readint(), y = readint();
      b[i - 1] = make_pair(make_pair(x, y), i);
    }
    sort(b, b + n);
    for (int i = 1; i <= n; i++) {
      int x = b[i - 1].first.first, y = b[i - 1].first.second,
          z = b[i - 1].second;
      int r = x / R, c = y / C;
      if (r == R) --r;
      if (c == C) --c;
      int id = r * C + c;
      a[id].push_back(z);
    }
    int len = R * C;
    int ok = 0;
    for (int i = 0, dx = 1; i < len;) {
      int sz = a[i].size();
      for (int j = 0; j <= sz - 1; j++) {
        if (ok) printf(" ");
        printf("%d", a[i][j]);
        ok = 1;
      }
      if (dx < 0 && i % C == 0 || dx > 0 && i % C == C - 1)
        i += C, dx = -dx;
      else
        i += dx;
    }
    putchar('\n');
  }
  return 0;
}

### Prompt

In Cpp, your task is to solve the following problem:

On a plane are n points (xi, yi) with integer coordinates between 0 and 106. The distance between the two points with numbers a and b is said to be the following value: <image> (the distance calculated by such formula is called Manhattan distance).

We call a hamiltonian path to be some permutation pi of numbers from 1 to n. We say that the length of this path is value <image>.

Find some hamiltonian path with a length of no more than 25 × 108. Note that you do not have to minimize the path length.

Input

The first line contains integer n (1 ≤ n ≤ 106).

The i + 1-th line contains the coordinates of the i-th point: xi and yi (0 ≤ xi, yi ≤ 106).

It is guaranteed that no two points coincide.

Output

Print the permutation of numbers pi from 1 to n — the sought Hamiltonian path. The permutation must meet the inequality <image>.

If there are multiple possible answers, print any of them.

It is guaranteed that the answer exists.

Examples

Input

5
0 7
8 10
3 4
5 0
9 12


Output

4 3 1 2 5 

Note

In the sample test the total distance is:

<image>

(|5 - 3| + |0 - 4|) + (|3 - 0| + |4 - 7|) + (|0 - 8| + |7 - 10|) + (|8 - 9| + |10 - 12|) = 2 + 4 + 3 + 3 + 8 + 3 + 1 + 2 = 26

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int int_inf = 0x3f3f3f3f;
const double double_inf = 1e30;
inline int readint() {
  bool neg = 0;
  char ch, t[11];
  int k = 0;
  while ((ch = getchar()) == ' ' || ch == '\n')
    ;
  neg = ch == '-';
  ch == '-' ? neg = 1 : t[k++] = ch;
  while ((ch = getchar()) >= '0' && ch <= '9') t[k++] = ch;
  int x = 0, y = 1;
  while (k) x += (t[--k] - '0') * y, y *= 10;
  return neg ? -x : x;
}
inline void readstr(char *s) {
  char ch;
  while ((ch = getchar()) == ' ' || ch == '\n')
    ;
  *(s++) = ch;
  while ((ch = getchar()) != ' ' && ch != '\n') *(s++) = ch;
  *s = '\0';
}
inline void writestr(const char *s) {
  while (*s != '\0') putchar(*(s++));
  putchar('\n');
}
inline long long readll() {
  long long x;
  scanf("%lld", &x);
  return x;
}
int debug = 0;
const int maxn = 1e6 + 10;
vector<int> a[maxn];
pair<pair<int, int>, int> b[maxn];
int main() {
  if (debug) freopen("in.txt", "r", stdin);
  int n;
  while (~scanf("%d", &n)) {
    int R = 1000, C = 1000;
    for (int i = 1; i <= n; i++) {
      int x = readint(), y = readint();
      b[i - 1] = make_pair(make_pair(x, y), i);
    }
    sort(b, b + n);
    for (int i = 1; i <= n; i++) {
      int x = b[i - 1].first.first, y = b[i - 1].first.second,
          z = b[i - 1].second;
      int r = x / R, c = y / C;
      if (r == R) --r;
      if (c == C) --c;
      int id = r * C + c;
      a[id].push_back(z);
    }
    int len = R * C;
    int ok = 0;
    for (int i = 0, dx = 1; i < len;) {
      int sz = a[i].size();
      for (int j = 0; j <= sz - 1; j++) {
        if (ok) printf(" ");
        printf("%d", a[i][j]);
        ok = 1;
      }
      if (dx < 0 && i % C == 0 || dx > 0 && i % C == C - 1)
        i += C, dx = -dx;
      else
        i += dx;
    }
    putchar('\n');
  }
  return 0;
}

```