#include "bits/stdc++.h"
using namespace std;
struct TapePos
{
int wrap;
double distance;
int index;
TapePos(int wrap, double distance, int index)
{
this->wrap = wrap;
this->distance = distance;
this->index = index;
}
bool operator <(const TapePos& other) const
{
return distance < other.distance;
}
};
vector<TapePos> reorder(const vector<TapePos>& points)
{
vector<TapePos> forward, backward;
for (int i = 0; i < (int)points.size(); i++)
{
if (points[i].wrap % 2 == 0)
forward.push_back(points[i]);
else
backward.push_back(points[i]);
}
sort(forward.begin(), forward.end());
sort(backward.rbegin(), backward.rend());
vector<TapePos> result = forward;
result.insert(result.end(), backward.begin(), backward.end());
return result;
}
int main(int argc, char* argv[])
{
//ios::sync_with_stdio(false); cin.tie(0);
int n;
cin>>n;
vector<TapePos> points;
for (int i = 0; i < n; i++)
{
int w;
double d;
cin>>w>>d;
points.push_back(TapePos(w, d, i));
}
vector<TapePos> result = reorder(points);
for (int i = 0; i < (int)result.size(); i++)
{
cout<<result[i].index<<' ';
}
cout<<endl;
}