#include <bits/stdc++.h>

using namespace std;
int main()
{
    int n,x=0,y=0,z;
    cin >>n;
    vector<int> a(n),b(n);
    vector<pair<int,int> > c,d;
    vector<int>::iterator it;
    for(int i=0;i<n;i++)
    {
        cin >>a[i]>>b[i];
        if(a[i]>b[i]){x++;c.push_back({a[i],i});}
        else {y++;d.push_back({b[i],i});}
    }
    z=c.size();
    if(x>=y)
    {
        cout <<x<<endl;
        sort(c.begin(),c.end());
        for(int i=0;i<z;++i)
        {
            cout <<c[i].second+1<<' ';
        }
    }
    else
    {
        cout <<y<<endl;
        sort(d.begin(),d.end());
        for(int i=n-z-1;i>=0;--i)
        {
            cout <<d[i].second+1<<' ';
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int main()
{
    int n,x=0,y=0,z;
    cin >>n;
    vector<int> a(n),b(n),c,d;
    vector<int>::iterator it;
    for(int i=0;i<n;i++)
    {
        cin >>a[i]>>b[i];
        if(a[i]>b[i]){x++;c.push_back(a[i]);}
        else {y++;d.push_back(b[i]);}
    }
    z=c.size();
    if(x>=y)
    {
        cout <<x<<endl;
        sort(c.begin(),c.end());
        for(int i=0;i<z;++i)
        {
            it=find(a.begin(),a.end(),c[i]);
            cout <<it-a.begin()+1<<' ';
        }
    }
    else
    {
        cout <<y<<endl;
        sort(d.begin(),d.end());
        for(int i=n-z-1;i>=0;++i)
        {
            it=find(b.begin(),b.end(),d[i]);
            cout <<it-b.begin()+1<<' ';
        }
    }
    return 0;
}


#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>

using namespace std;

int n;

vector<int>mic;
vector<int>mare;

struct {
  int a, b, i;
} v[300002];

bool cmp (int i, int j) {
  return v[i].a < v[j].a;
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> v[i].a >> v[i].b;
    v[i].i = i;
    if (v[i].a < v[i].b)
      mic.push_back(i);
    else
      mare.push_back(i);
  }
  if (mic.size() < mare.size()) {
    sort(mare.begin(), mare.end(), cmp);
    cout << mare.size() << "\n";
    for (int i = 0; i < mare.size(); i++)
      cout << mare[i] << " ";
  }
  else {
    sort(mic.begin(), mic.end(), cmp);
    reverse(mic.begin(), mic.end());
    cout << mic.size() << "\n";
    for (int i = 0;i < mic.size(); i++)
      cout << mic[i] << " ";
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n;

vector<int>mic;
vector<int>mare;

struct {
  int a, b, i;
} v[300002];

bool cmp (int i, int j) {
  return v[i].a < v[j].a;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> v[i].a >> v[i].b;
    v[i].i = i;
    if (v[i].a < v[i].b)
      mic.push_back(i);
    else
      mare.push_back(i);
  }
  if (mic.size() < mare.size()) {
    sort(mare.begin(), mare.end(), cmp);
    cout << mare.size() << "\n";
    for (int i = 0; i < mare.size(); i++)
      cout << mare[i] << " ";
  }
  else {
    sort(mic.begin(), mic.end(), cmp);
    reverse(mic.begin(), mic.end());
    cout << mic.size() << "\n";
    for (int i = 0;i < mic.size(); i++)
      cout << mic[i] << " ";
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n;

vector<int>mic;
vector<int>mare;

struct {
  int a, b, i;
} v[300002];

bool cmp (int i, int j) {
  return v[i].a < v[j].a;
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> v[i].a >> v[i].b;
    v[i].i = i;
    if (v[i].a < v[i].b)
      mic.push_back(i);
    else
      mare.push_back(i);
  }
  if (mic.size() < mare.size()) {
    sort(mare.begin(), mare.end(), cmp);
    cout << mare.size() << "\n";
    for (int i = 0; i < mare.size(); i++)
      cout << mare[i] << " ";
  }
  else {
    sort(mic.begin(), mic.end(), cmp);
    reverse(mic.begin(), mic.end());
    cout << mic.size() << "\n";
    for (int i = 0;i < mic.size(); i++)
      cout << mic[i] << " ";
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n;

vector<int>mic;
vector<int>mare;

struct {
  int a, b, i;
} v[300002];

bool cmp (int i, int j) {
  return v[i].a < v[j].b;
}

int main()
{
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> v[i].a >> v[i].b;
    v[i].i = i;
    if (v[i].a < v[i].b)
      mic.push_back(i);
    else
      mare.push_back(i);
  }
  if (mic.size() < mare.size()) {
    sort(mare.begin(), mare.end(), cmp);
    cout << mare.size() << "\n";
    for (int i = 0; i < mare.size(); i++)
      cout << mare[i] << " ";
  }
  else {
    sort(mic.begin(), mic.begin(), cmp);
    reverse(mic.begin(), mic.begin());
    cout << mic.size() << "\n";
    for (int i = 0;i < mic.size(); i++)
      cout << mic[i] << " ";
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n;

vector<int>mic;
vector<int>mare;

struct {
  int a, b, i;
} v[300002];

bool cmp (int i, int j) {
  return v[i].a < v[j].a;
}

int main()
{
std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
  std::cerr.tie(nullptr);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> v[i].a >> v[i].b;
    v[i].i = i;
    if (v[i].a < v[i].b)
      mic.push_back(i);
    else
      mare.push_back(i);
  }
  if (mic.size() < mare.size()) {
    sort(mare.begin(), mare.end(), cmp);
    cout << mare.size() << "\n";
    for (int i = 0; i < mare.size(); i++)
      cout << mare[i] << " ";
  }
  else {
    sort(mic.begin(), mic.end(), cmp);
    reverse(mic.begin(), mic.end());
    cout << mic.size() << "\n";
    for (int i = 0;i < mic.size(); i++)
      cout << mic[i] << " ";
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n;

vector<int>mic;
vector<int>mare;

struct {
  int a, b, i;
} v[300002];

bool cmp (int i, int j) {
  return v[i].a < v[j].a;
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> v[i].a >> v[i].b;
    v[i].i = i;
    if (v[i].a < v[i].b)
      mic.push_back(i);
    else
      mare.push_back(i);
  }
  if (mic.size() < mare.size()) {
    sort(mare.begin(), mare.end(), cmp);
    cout << mare.size() << "\n";
    for (int i = 0; i < mare.size(); i++)
      cout << mare[i] << " ";
  }
  else {
    sort(mic.begin(), mic.end(), cmp);
    reverse(mic.begin(), mic.end());
    cout << mic.size() << "\n";
    for (int i = 0;i < mic.size(); i++)
      cout << mic[i] << " ";
  }
  return 0;
}


//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize(3)
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC target("sse3","sse2","sse")
//#pragma GCC target("avx","sse4","sse4.1","sse4.2","ssse3")
//#pragma GCC target("f16c")
//#pragma GCC optimize("inline","fast-math","unroll-loops","no-stack-protector")
//#pragma GCC diagnostic error "-fwhole-program"
//#pragma GCC diagnostic error "-fcse-skip-blocks"
//#pragma GCC diagnostic error "-funsafe-loop-optimizations"
//#pragma GCC diagnostic error "-std=c++14"

#include <bits/stdc++.h>

using namespace std;

int n;

vector<int>mic;
vector<int>mare;

struct {
  int a, b, i;
} v[300002];

bool cmp (int i, int j) {
  return v[i].a < v[j].a;
}

int main()
{
  //ios_base::sync_with_stdio(false);
  //cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> v[i].a >> v[i].b;
    v[i].i = i;
    if (v[i].a < v[i].b)
      mic.push_back(i);
    else
      mare.push_back(i);
  }
  if (mic.size() < mare.size()) {
    sort(mare.begin(), mare.end(), cmp);
    cout << mare.size() << "\n";
    for (int i = 0; i < mare.size(); i++)
      cout << mare[i] << " ";
  }
  else {
    sort(mic.begin(), mic.end(), cmp);
    reverse(mic.begin(), mic.end());
    cout << mic.size() << "\n";
    for (int i = 0;i < mic.size(); i++)
      cout << mic[i] << " ";
  }
  return 0;
}


#pragma comment(linker, "/STACK:1024000000,1024000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")

#include <bits/stdc++.h>

using namespace std;

int n;

vector<int>mic;
vector<int>mare;

struct {
  int a, b, i;
} v[300002];

bool cmp (int i, int j) {
  return v[i].a < v[j].a;
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> v[i].a >> v[i].b;
    v[i].i = i;
    if (v[i].a < v[i].b)
      mic.push_back(i);
    else
      mare.push_back(i);
  }
  if (mic.size() < mare.size()) {
    sort(mare.begin(), mare.end(), cmp);
    cout << mare.size() << "\n";
    for (int i = 0; i < mare.size(); i++)
      cout << mare[i] << " ";
  }
  else {
    sort(mic.begin(), mic.end(), cmp);
    reverse(mic.begin(), mic.end());
    cout << mic.size() << "\n";
    for (int i = 0;i < mic.size(); i++)
      cout << mic[i] << " ";
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n;

vector<int>mic;
vector<int>mare;

struct {
  int a, b, i;
} v[300002];

bool cmp (int i, int j) {
  return v[i].a < v[j].b;
}

int main()
{
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> v[i].a >> v[i].b;
    v[i].i = i;
    if (v[i].a < v[i].b)
      mic.push_back(i);
    else
      mare.push_back(i);
  }
  if (mic.size() < mare.size()) {
    sort(mare.begin(), mare.end(), cmp);
    cout << mare.size() << "\n";
    for (int i = 0; i < mare.size(); i++)
      cout << mare[i] << " ";
  }
  else {
    sort(mic.begin(), mic.end(), cmp);
    reverse(mic.begin(), mic.end());
    cout << mic.size() << "\n";
    for (int i = 0;i < mic.size(); i++)
      cout << mic[i] << " ";
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n;

vector<int>mic;
vector<int>mare;

struct {
  int a, b, i;
} v[300002];

bool cmp (int i, int j) {
  return v[i].a < v[j].b;
}

int main()
{
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> v[i].a >> v[i].b;
    v[i].i = i;
    if (v[i].a < v[i].b)
      mic.push_back(i);
    else
      mare.push_back(i);
  }
  if (mic.size() < mare.size()) {
    sort(mare.begin(), mare.end(), cmp);
    cout << mare.size() << "\n";
    for (int i = 0; i < mare.size(); i++)
      cout << mare[i] << " ";
  }
  else {
    //sort(mic.begin(), mic.end(), cmp);
    //reverse(mic.begin(), mic.end());
    cout << mic.size() << "\n";
    for (int i = 0;i < mic.size(); i++)
      cout << mic[i] << " ";
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n;

vector<int>mic;
vector<int>mare;

struct {
  int a, b, i;
} v[300002];

bool cmp (int i, int j) {
  return v[i].a < v[j].a;
}

int main()
{
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> v[i].a >> v[i].b;
    v[i].i = i;
    if (v[i].a < v[i].b)
      mic.push_back(i);
    else
      mare.push_back(i);
  }
  if (mic.size() < mare.size()) {
    sort(mare.begin(), mare.end(), cmp);
    cout << mare.size() << "\n";
    for (int i = 0; i < mare.size(); i++)
      cout << mare[i] << " ";
  }
  else {
    sort(mic.begin(), mic.end(), cmp);
    reverse(mic.begin(), mic.end());
    cout << mic.size() << "\n";
    for (int i = 0;i < mic.size(); i++)
      cout << mic[i] << " ";
  }
  return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <memory.h>
#include <cstdio>
#include <bitset>
#include <random>
#include <string>
#include <string.h>
#include <istream>
#include <ostream>
#include <ctime>
#include <complex>
#include <assert.h>
#include <fstream>
#include <cassert>

#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
#define dashafominaKisa ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ll INF = 1e18;
const ld PI = acos(-1);
const ld EPS = 1e-7;
const ll MOD = 1e9 + 7;
const ll MAXN = 200001;

void solve() {
    ll n;
    cin >> n;
    set < tuple < ll, ll, ll > > a, b;
    for (int i = 1; i <= n; ++i) {
        ll x, y;
        cin >> x >> y;
        if (x < y)
            a.insert({x, y, i});
        else
            b.insert({y, x, i});
    }
    vector < ll > ansa, ansb;
    while (!a.empty()) {
        auto [x, y, i] = *a.rbegin();
        ansa.emplace_back(i);
        a.erase({x, y, i});
    }
    while (!b.empty()) {
        auto [y, x, i] = *b.begin();
        ansb.emplace_back(i);
        b.erase({y, x, i});
    }
    if (ansa.size() > ansb.size()) {
        cout << ansa.size() << '\n';
        for (auto x: ansa)
            cout << x << ' ';
        cout << '\n';
    }
    else {
        cout << ansb.size() << '\n';
        for (auto x: ansb)
            cout << x << ' ';
        cout << '\n';
    }
}

int main() {
#if (DEBUG_LEVEL)
    freopen("../input.txt", "r", stdin);
    freopen("../output.txt", "w", stdout);
#endif
    dashafominaKisa

    solve();

    return 0;
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#pragma warning( disable : 4244 4267 4018 4996 4800 )
//#pragma comment( linker, "/stack:10000000" )
using namespace std;
typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<string> vs; typedef vector<double> vd;
typedef vector<vd> vvd; typedef long long ll; typedef vector<ll> vll; typedef vector<vll> vvll; typedef pair<int, int> pii;
#define all(v) begin(v), end(v)

#ifdef LOCAL
ifstream in("d.in");
#else
istream & in = cin;
#endif
ostream & out = cout;
template <class T> void read(T & t) { for (auto & x : t) in >> x; } template <class T> int sz(T const & t) { return (int)t.size(); }

vi solve(vi idx, vector<pii> const & v) {
    sort(all(idx), [&](int a, int b) {
        return v[a].first < v[b].first;
    });
    reverse(all(idx));
    return idx;
}

int main() {
    ios_base::sync_with_stdio(false);
    int n; in >> n;
    vector<pii> p;
    vi v, w;
    for (int i = 0; i < n; ++i) {
        int a, b; in >> a >> b;
        if (a < b)
            p.push_back({ a, b }), v.push_back(i);
        else
            p.push_back({ b, a }), w.push_back(i);
    }
    vi res;
    if (v.size() > w.size())
        res = solve(v, p);
    else
        res = solve(w, p), std::reverse(all(res));
    out << res.size() << "\n";
    for (int i = 0; i < res.size(); ++i)
        out << res[i] + 1 << ' ';
    return 0;
}


#include <cassert>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <chrono>
#include <algorithm>
#include <numeric>
#include <atomic>
#include <tuple>
#include <fstream>
#include <random>
#include <future>
#include <iterator>
#include <functional>
#include <thread>
#include <bitset>
#include <cstddef>
#include <utility>
#include <type_traits>
#include <complex>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
auto _fast_io = []() { std::ios::sync_with_stdio(false); cin.tie(nullptr); return cout.tie(nullptr); }();

template <typename T>
istream& operator>>(istream& in, vector<T>& v) {
    for (size_t i = 0; i < v.size(); ++i) {
        in >> v[i];
    }
    return in;
}

template <typename T>
ostream& operator<<(ostream& out, vector<T>& v) {
    out << '{';
    if (!v.empty()) {
        out << v.front();
        for (size_t i = 0; i < v.size(); ++i) {
            out << ", " << v[i];
        }
    }
    out << '}';
    return out;
}

template <typename T, size_t Size>
istream& operator>>(istream& in, array<T, Size>& v) {
    for (size_t i = 0; i < Size; ++i) {
        in >> v[i];
    }
    return in;
}

bool operator<(const pi& l, const pi& r) {
    return l.first < r.first || (l.first == r.first && l.second < r.second);
}

struct pe
{
    pe(int i, int f, int s) : index(i), pair(f, s) {}
    int index;
    pi pair;
};

int main() {
    int n;
    cin >> n;
    vector<pe> ls, gt;
    for (int i = 0; i < n; ++i) {
        int t1, t2;
        cin >> t1 >> t2;
        if (t1 < t2) ls.emplace_back(i + 1, t1, t2);
        else gt.emplace_back(i + 1, t1, t2);
    }
    if (ls.size() > gt.size()) {
        sort(ls.begin(), ls.end(), [](auto left, auto right) { return left.pair.second > right.pair.second; });
    }
    else {
        sort(gt.begin(), gt.end(), [](auto left, auto right) { return left.pair.second < right.pair.second; });
        ls = std::move(gt);
    }
    cout << ls.size() << '\n';
    for (auto p : ls) { cout << p.index << ' '; }
    cout << endl;
}


#include <stdio.h>
#include <algorithm>

using namespace std;

struct node {
	int a , b , i;
} s[310000] , t[310000];
int n , n1 , n2;
bool cmp1 ( node x1 , node x2 ) {
	return x1.b > x2.b;
}
bool cmp2 ( node x1 , node x2 ) {
	return x1.b < x2.b;
}
void work () {
	int i , x , y;
	scanf ( "%d" , &n );
	for ( i = 1 ; i <= n ; i++ ) {
		scanf ( "%d%d" , &x , &y );
		if ( x < y ) {
			n1++;
			s[n1].a = x;
			s[n1].b = y;
			s[n1].i = i;
		}
		else {
			n2++;
			t[n2].a = x;
			t[n2].b = y;
			t[n2].i = i;
		}
	}
	sort ( s + 1 , s + 1 + n1 , cmp1 );
	sort ( t + 1 , t + 1 + n2 , cmp2 );
	if ( n1 >= n2 ) {
		printf ( "%d\n" , n1 );
		for ( i = 1 ; i <= n1 ; i++ ) {
			printf ( "%d%c" , s[i].i , i==n1?'\n':' ' );
		}
	}
	else {
		printf ( "%d\n" , n2 );
		for ( i = 1 ; i <= n2 ; i++ ) {
			printf ( "%d%c" , t[i].i , i==n2?'\n':' ' );
		}
	}
}
int main () {
	work ();
	return 0;
}


#include<cstdio>
#include<cmath>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

bool func(const pair<pair<int,int>,int> &a, const pair<pair<int,int>,int> &b)
{
	return a.first.first < b.first.first;
}

bool func2(const pair<pair<int,int>,int> &a, const pair<pair<int,int>,int> &b)
{
	return a.first.first > b.first.first;
}

int main()
{
	int i;
	vector<pair<pair<int,int>,int>> inc, dec;
	vector<int> incsol, decsol;
	int input1, input2;
	int n;
	int cnt1 = 0, cnt2 = 0;
	int prev, cur;

	scanf("%d", &n);

	for (i = 0; i < n; i++)
	{
		scanf("%d %d", &input1, &input2);

		if (input1 < input2)
		{
			inc.push_back(pair<pair<int, int>, int>(pair<int, int>(input1, input2), i + 1));
		}

		else
		{
			dec.push_back(pair<pair<int,int>,int>(pair<int, int>(input1, input2), i + 1));
		}
	}

	sort(inc.begin(), inc.end(), func2);
	sort(dec.begin(), dec.end(), func);

	if (!inc.empty())
	{
		cnt1++;

		incsol.push_back(inc[0].second);
		prev = inc[0].first.first;
		cur = inc[0].first.second;

		for (i = 1; i < inc.size(); i++)
		{
			if (inc[i].first.first < cur)
			{
				cnt1++;

				incsol.push_back(inc[i].second);
				prev = inc[i].first.first;
				cur = inc[i].first.second;
			}

			else if (inc[i].first.first<prev && inc[i].first.second>cur)
			{
				incsol.pop_back();
				incsol.push_back(inc[i].second);
				prev = inc[i].first.first;
				cur = inc[i].first.second;
			}
		}
	}

	if (!dec.empty())
	{
		cnt2++;

		decsol.push_back(dec[0].second);
		prev = dec[0].first.first;
		cur = dec[0].first.second;

		for (i = 1; i < dec.size(); i++)
		{
			if (dec[i].first.first > cur)
			{
				cnt2++;

				decsol.push_back(dec[i].second);
				prev = dec[i].first.first;
				cur = dec[i].first.second;
			}

			else if (dec[i].first.first>prev && dec[i].first.second<cur)
			{
				decsol.pop_back();
				decsol.push_back(dec[i].second);
				prev = dec[i].first.first;
				cur = dec[i].first.second;
			}
		}
	}

	if (cnt1 >= cnt2)
	{
		printf("%d\n", cnt1);

		for (i = 0; i < cnt1; i++)
		{
			printf("%d ", incsol[i]);
		}
	}

	else
	{
		printf("%d\n", cnt2);

		for (i = 0; i < cnt2; i++)
		{
			printf("%d ", decsol[i]);
		}
	}

	return 0;
}


#include<vector>
#include<iostream>
#include<fstream>
#include<string>
#include<cassert>
#include<algorithm>
#include<random>
#include<map>
#include<set>
#include <bitset>
#include<queue>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<ll>> vvl;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ld, ld>> vpld;
typedef vector<pair<int, int>> vpi;
typedef pair<ld, ld> pld;
#define mp make_pair
#define pb push_back

int mod = 998244353;
//int mod = 1e9 + 7;

int sum(int a, int b)
{
	int c = a + b;
	if (c >= mod)
	{
		c -= mod;
	}
	return c;
}

int dif(int a, int b)
{
	int c = a - b;
	if (c < 0)
	{
		c += mod;
	}
	return c;
}

int mlt(int a, int b)
{
	ll c = a * 1LL * b;
	return c % mod;
}

int ibit(int n, int i)
{
	return ((n >> i) & 1);
}

void outp1(vl &ou, string s = " ")
{
	cerr << s << endl;
	for (int i = 0; i < ou.size(); i++)
	{
		cerr << ou[i] << ' ';
	}
	cerr << endl;
}

void outp1(vi &ou, string s = " ")
{
	cerr << s << endl;
	for (int i = 0; i < ou.size(); i++)
	{
		cerr << ou[i] << ' ';
	}
	cerr << endl;
}

void outp2(vector<vector<ll>> &ou, string s = " ")
{
	cerr << s << endl;
	for (int i = 0; i < ou.size(); i++)
	{
		for (int j = 0; j < ou[i].size(); j++)
		{
			cerr << ou[i][j] << ' ';
		}
		cerr << '\n';
	}
}

int bp(int x, int y)
{
	if (y == 0)
	{
		return 1;
	}
	int a = 0;
	if (!(y % 2))
	{
		a = bp(x, y / 2);
	}
	return (y % 2) ? mlt(bp(x, y - 1), x) : mlt(a, a);
}

int obr(int x)
{
	return bp(x, mod - 2);
}

const int maxn = 301;
int fact[maxn], ofact[maxn];

void prec()
{
	fact[0] = 1;
	ofact[0] = 1;
	for (int i = 1; i < maxn; i++)
	{
		fact[i] = mlt(fact[i - 1], i);
	}
	//cerr << "sdsds" << endl;
	ofact[maxn - 1] = obr(fact[maxn - 1]);
	for (int i = maxn - 2; i > 0; i--)
	{
		ofact[i] = mlt(ofact[i + 1], i + 1);
	}
}

int c(int a, int b)
{
	return ((a <= b) && (a >= 0)) ? mlt(fact[b], mlt(ofact[a], ofact[b - a])) : 0;
}

int inf = 1e9 + 110;

void swp(vector<pair<int, int>>&swaps, vector<int>&p, int a, int b, vector<int>&pinv)
{
	swaps.pb({a, b});
	int x=p[a];
	p[a]=p[b];
	p[b]=x;
	pinv[p[a]]=a;
	pinv[p[b]]=b;
}

void solve(istream &cin = std::cin, ostream &cout = std::cout)
{
	int n;
	cin>>n;
	vector<pair<int, int>>pr(n);
	vector<pair<int, int>>big, small;
	for(int i=0; i<n; i++)
	{
		int x, y;
		cin>>x>>y;
		pr[i]={x, y};
		if(x<y)
			small.pb({-x, i}); // по уменьшению 1
		else
			big.pb({y, i}); // по увеличению 2
	}
	if(small.size()<big.size())
	{
		small=big;
	}
	sort(small.begin(), small.end());
	for(auto par: small)
		cout<<par.second+1<<' ';
	cout<<'\n';
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int tests = 1;
	//cin >> tests;
	for (int i = 0; i < tests; i++)
		solve();
}


#include<vector>
#include<iostream>
#include<fstream>
#include<string>
#include<cassert>
#include<algorithm>
#include<random>
#include<map>
#include<set>
#include <bitset>
#include<queue>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<ll>> vvl;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ld, ld>> vpld;
typedef vector<pair<int, int>> vpi;
typedef pair<ld, ld> pld;
#define mp make_pair
#define pb push_back

int mod = 998244353;
//int mod = 1e9 + 7;

int sum(int a, int b)
{
	int c = a + b;
	if (c >= mod)
	{
		c -= mod;
	}
	return c;
}

int dif(int a, int b)
{
	int c = a - b;
	if (c < 0)
	{
		c += mod;
	}
	return c;
}

int mlt(int a, int b)
{
	ll c = a * 1LL * b;
	return c % mod;
}

int ibit(int n, int i)
{
	return ((n >> i) & 1);
}

void outp1(vl &ou, string s = " ")
{
	cerr << s << endl;
	for (int i = 0; i < ou.size(); i++)
	{
		cerr << ou[i] << ' ';
	}
	cerr << endl;
}

void outp1(vi &ou, string s = " ")
{
	cerr << s << endl;
	for (int i = 0; i < ou.size(); i++)
	{
		cerr << ou[i] << ' ';
	}
	cerr << endl;
}

void outp2(vector<vector<ll>> &ou, string s = " ")
{
	cerr << s << endl;
	for (int i = 0; i < ou.size(); i++)
	{
		for (int j = 0; j < ou[i].size(); j++)
		{
			cerr << ou[i][j] << ' ';
		}
		cerr << '\n';
	}
}

int bp(int x, int y)
{
	if (y == 0)
	{
		return 1;
	}
	int a = 0;
	if (!(y % 2))
	{
		a = bp(x, y / 2);
	}
	return (y % 2) ? mlt(bp(x, y - 1), x) : mlt(a, a);
}

int obr(int x)
{
	return bp(x, mod - 2);
}

const int maxn = 301;
int fact[maxn], ofact[maxn];

void prec()
{
	fact[0] = 1;
	ofact[0] = 1;
	for (int i = 1; i < maxn; i++)
	{
		fact[i] = mlt(fact[i - 1], i);
	}
	//cerr << "sdsds" << endl;
	ofact[maxn - 1] = obr(fact[maxn - 1]);
	for (int i = maxn - 2; i > 0; i--)
	{
		ofact[i] = mlt(ofact[i + 1], i + 1);
	}
}

int c(int a, int b)
{
	return ((a <= b) && (a >= 0)) ? mlt(fact[b], mlt(ofact[a], ofact[b - a])) : 0;
}

int inf = 1e9 + 110;

void swp(vector<pair<int, int>>&swaps, vector<int>&p, int a, int b, vector<int>&pinv)
{
	swaps.pb({a, b});
	int x=p[a];
	p[a]=p[b];
	p[b]=x;
	pinv[p[a]]=a;
	pinv[p[b]]=b;
}

void solve(istream &cin = std::cin, ostream &cout = std::cout)
{
	int n;
	cin>>n;
	vector<pair<int, int>>pr(n);
	vector<pair<int, int>>big, small;
	for(int i=0; i<n; i++)
	{
		int x, y;
		cin>>x>>y;
		pr[i]={x, y};
		if(x<y)
			small.pb({-x, i}); // по уменьшению 1
		else
			big.pb({y, i}); // по увеличению 2
	}
	if(small.size()<big.size())
	{
		small=big;
	}
	sort(small.begin(), small.end());
	cout<<small.size()<<'\n';
	for(auto par: small)
		cout<<par.second+1<<' ';
	cout<<'\n';
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int tests = 1;
	//cin >> tests;
	for (int i = 0; i < tests; i++)
		solve();
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int comp(pair< pair <int, int>, int> a, pair< pair <int, int>, int> b) {
	return a.first.second < b.first.second;
}
int main()
{
	int n;
	cin >> n;
	vector <pair < pair <int, int>, int> > voz;
	vector <pair < pair <int, int> , int> > ub;
	for (int i = 0; i < n; i++) {
		int x, y;
		cin >> x >> y;
		if (x > y) {
			ub.push_back({ { x, y }, i + 1 });
		}
		else {
			voz.push_back({ { x, y }, i + 1 });
		}
	}
	if (ub.size() < voz.size()) {
		sort(voz.begin(), voz.end());
		cout << voz.size() << endl;
		for (auto& i : voz)cout << i.second << " ";
	}
	else {
		sort(ub.begin(), ub.end(), comp);
		cout << ub.size() << endl;
		for (auto& i : ub)cout  << i.second << " ";
	}
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int comp(pair< pair <int, int>, int> a, pair< pair <int, int>, int> b) {
	return a.first.second < b.first.second;
}

int comp1(pair< pair <int, int>, int> a, pair< pair <int, int>, int> b) {
	return a.first.second > b.first.second;
}

int main()
{
	int n;
	cin >> n;
	vector <pair < pair <int, int>, int> > voz;
	vector <pair < pair <int, int> , int> > ub;
	for (int i = 0; i < n; i++) {
		int x, y;
		cin >> x >> y;
		if (x > y) {
			ub.push_back({ { x, y }, i + 1 });
		}
		else {
			voz.push_back({ { x, y }, i + 1 });
		}
	}
	if (ub.size() < voz.size()) {
		sort(voz.begin(), voz.end(), comp1);
		cout << voz.size() << endl;
		for (auto& i : voz)cout << i.second << " ";
	}
	else {
		sort(ub.begin(), ub.end(), comp);
		cout << ub.size() << endl;
		for (auto& i : ub)cout  << i.second << " ";
	}
}


#include <iostream>
#include <algorithm>
#include <vector>

int n;

std::vector<int> a, b;

struct pair {
    int a;
    int b;
    int index;
};

bool left(const pair& p, const pair& q) {
    return p.a < q.a;
}

bool right(const pair& p, const pair& q) {
    return p.b < q.b;
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);

    std::cin >> n;

    a.resize(n);
    b.resize(n);

    int l = 0;
    for (int i = 0; i < n; ++i) {
        std::cin >> a[i] >> b[i];
        if (a[i] < b[i]) {
            l++;
        }

    }

    std::vector<pair> p;

    if (l > n - l) {
       for (int i = 0; i < n; ++i) {
           if (a[i] < b[i]) {
               p.push_back({a[i], b[i], i + 1});
           }
       }
    } else {
       for (int i = 0; i < n; ++i) {
           if (a[i] > b[i]) {
               p.push_back({a[i], b[i], i + 1});
           }
       }
    }

    std::cout << p.size() << std::endl;

    if (l > n - l) {
        std::sort(p.begin(), p.end(), left);
    } else {
        std::sort(p.begin(), p.end(), right);
    }

    for (const auto& pp : p) {
        std::cout << pp.index << " ";
    }
    std::cout << "\n";
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>

int n;

std::vector<int> a, b;

struct pair {
    int a;
    int b;
    int index;
};

bool left(const pair& p, const pair& q) {
    return p.a < q.a;
}

bool right(const pair& p, const pair& q) {
    return p.b > q.b;
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);

    std::cin >> n;

    a.resize(n);
    b.resize(n);

    int l = 0;
    for (int i = 0; i < n; ++i) {
        std::cin >> a[i] >> b[i];
        if (a[i] < b[i]) {
            l++;
        }

    }

    std::vector<pair> p;

    if (l > n - l) {
       for (int i = 0; i < n; ++i) {
           if (a[i] < b[i]) {
               p.push_back({a[i], b[i], i + 1});
           }
       }
    } else {
       for (int i = 0; i < n; ++i) {
           if (a[i] > b[i]) {
               p.push_back({a[i], b[i], i + 1});
           }
       }
    }

    std::cout << p.size() << std::endl;

    if (l > n - l) {
        std::sort(p.begin(), p.end(), left);
    } else {
        std::sort(p.begin(), p.end(), right);
    }

    for (const auto& pp : p) {
        std::cout << pp.index << " ";
    }
    std::cout << "\n";

    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>

int n;

std::vector<int> a, b;

struct pair {
    int a;
    int b;
    int index;
};

bool left(const pair& p, const pair& q) {
    return p.a > q.a;
}

bool right(const pair& p, const pair& q) {
    return p.b < q.b;
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);

    std::cin >> n;

    a.resize(n);
    b.resize(n);

    int l = 0;
    for (int i = 0; i < n; ++i) {
        std::cin >> a[i] >> b[i];
        if (a[i] < b[i]) {
            l++;
        }

    }

    std::vector<pair> p;

    if (l > n - l) {
       for (int i = 0; i < n; ++i) {
           if (a[i] < b[i]) {
               p.push_back({a[i], b[i], i + 1});
           }
       }
    } else {
       for (int i = 0; i < n; ++i) {
           if (a[i] > b[i]) {
               p.push_back({a[i], b[i], i + 1});
           }
       }
    }

    std::cout << p.size() << std::endl;

    if (l > n - l) {
        std::sort(p.begin(), p.end(), left);
    } else {
        std::sort(p.begin(), p.end(), right);
    }

    for (const auto& pp : p) {
        std::cout << pp.index << " ";
    }
    std::cout << "\n";

    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

struct node
{
    int x;
    int y;
    int index;
    node(int _x, int _y, int _index) : x(_x), y(_y), index(_index) {

    }
};

vector<node> A;
vector<node> B;

int n;

void input()
{
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        int x, y;
        cin >> x >> y;
        if (x < y)
        {
            A.push_back(node(x, y, i));
        }
        else {
            B.push_back(node(x, y, i));
        }
    }
}

bool compare_a(const node& p, const node& q)
{
    if (p.y > q.x && p.x > q.y)
        return true;
    return p.y > q.x && p.x < q.y && p.y < q.y;
}

bool compare_b(const node& p, const node& q)
{
    if (p.y < q.x && p.x < q.y)
        return true;
    return p.y < q.x && p.x > q.y && p.y > q.y;
}

void output(vector<node>& A)
{
    cout << A.size() << "\n";
    for (int i = 0; i < A.size(); ++i)
    {
        if (i != 0)
            cout << ' ';
        cout << A[i].index + 1;
    }
    cout << "\n";
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    input();
    if (A.size() >= B.size())
    {
        sort(A.begin(), A.end(), compare_a);
        output(A);
    }
    else
    {
        sort(B.begin(), B.end(), compare_b);
        output(B);
    }
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);

	int n;
	cin >> n;

	vector<pair<pair<int, int>, int>> inc;
	vector<pair<pair<int,int>, int>> dec;

	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		if (a < b) {
			inc.push_back({ {a,b}, i + 1 });
		}
		else {
			dec.push_back({ {a,b}, i + 1 });
		}
	}

	if (inc.size() > dec.size()) {
		cout << inc.size() << endl;

		sort(inc.rbegin(), inc.rend());
		for (int i = 0; i < inc.size(); i++) {
			cout << inc[i].second << " ";
		}
		cout << endl;
	}
	else {
		cout << dec.size() << endl;

		sort(dec.begin(), dec.end());
		for (int i = 0; i < dec.size(); i++) {
			cout << dec[i].second << " ";
		}
		cout << endl;
	}
}


#include <iomanip>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <ctime>
#include <cstdio>
#include <cmath>
#include <queue>
#include <bitset>
#include <string>

#define ll long long
#define mp make_pair
#define pb push_back

using namespace std;

const int N = 300010;
const ll INF = 1e18;
const int MOD = 1e9+7;

int n;
vector <pair<int, int> > v1, v2;

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        int a, b;
        scanf("%d%d", &a, &b);
        if (a < b) v1.pb(mp(b, i));
        else v2.pb(mp(b, i));
    }
    sort(v1.begin(), v1.end());
    reverse(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());
    if (v1.size() > v2.size()) {
        printf("%d\n", v1.size());
        for (int i = 0; i < v1.size(); i++) printf("%d ", v1[i].second);
    }
    else {
        printf("%d\n", v2.size());
        for (int i = 0; i < v2.size(); i++) printf("%d ", v2[i].second);
    }
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<map>
#include<bitset>
#include<utility>
#ifdef LOCAL
#include"file.h"
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
const double eps = 1e-6;
//const int dir[4][2] = { -1,0,1,0,0,-1,0,1 };
//const int dir[8][2] = { -2,-1,-2,1,2,-1,2,1,-1,2,-1,-2,1,2,1,-2 };

const int maxn = 3e5 + 5;
LL n;
LL t[maxn];

struct opt {
	LL i, j, d;
	opt(LL i0, LL j0, LL d0) :i(i0), j(j0), d(d0) {}
};
vector<opt>ans;

struct node1 {
	LL a;
	LL pos;
	bool operator <(const node1 &oth)const {
		return a < oth.a;
	}
	node1(LL a0=-1, LL pos0=-1) :a(a0), pos(pos0) {}
}s[maxn];

LL c[maxn];

struct node {
	LL a;
	LL pos;
	bool operator <(const node &oth)const {
		return pos > oth.pos;
	}
	node(LL a0, LL pos0) :a(a0), pos(pos0) {}
};

priority_queue<node>pq;

int main() {
#ifdef LOCAL
	fileopen();
#endif
	scanf("%lld", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%lld", &s[i].a);
		s[i].pos = i;
	}
	for (int i = 1; i <= n; i++) {
		scanf("%lld", &t[i]);
	}
	sort(s + 1, s + 1 + n);
	sort(t + 1, t + 1 + n);

	for (int i = 1; i <= n; i++){
		c[i] = s[i].a - t[i];
		if (c[i] > 0) {
			pq.push(node(c[i], i));
		}
	}

	bool ok = true;
	for (int i = 1; i <= n&&ok; i++)if (c[i]) {
		if (c[i] > 0) {
			ok = false;
			break;
		}

		while (c[i]) {
			if (pq.empty()) {
				ok = false;
				break;
			}
			node temp = pq.top(); pq.pop();
			if (temp.a > (-c[i])) {
				ans.push_back(opt(s[i].pos, s[temp.pos].pos, (-c[i])));

				temp.a += c[i];
				c[temp.pos] += c[i];
				c[i] = 0;
				pq.push(temp);
				break;
			}
			else {
				ans.push_back(opt(s[i].pos, s[temp.pos].pos, temp.a));
				c[i] += temp.a;
				temp.a = 0;
				c[temp.pos] = 0;
			}
		}

	}
	if (ok) {
		printf("YES\n");
		printf("%d\n", ans.size());
		for (int i = 0; i < ans.size(); i++) {
			printf("%lld %lld %lld\n", ans[i].i, ans[i].j, ans[i].d);
		}
	}
	else printf("NO\n");

#ifdef LOCAL
	fileclose();
#endif
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<map>
#include<bitset>
#include<utility>
#ifdef LOCAL
#include"file.h"
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
const double eps = 1e-6;
//const int dir[4][2] = { -1,0,1,0,0,-1,0,1 };
//const int dir[8][2] = { -2,-1,-2,1,2,-1,2,1,-1,2,-1,-2,1,2,1,-2 };

const int maxn = 3e5 + 5;
struct node {
	int a, b, pos;

	bool operator <(const node &oth)const {
		return a < oth.a;
	}

}w1[maxn],w2[maxn];
int p1 = 0, p2 = 0;
int n;

int main() {
#ifdef LOCAL
	fileopen();
#endif
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		if (a < b) {
			w1[++p1].a = a;
			w1[p1].b = b;
			w1[p1].pos = i;
		}
		else {
			a = -a; b = -b;
			w2[++p2].a = a;
			w2[p2].b = b;
			w2[p2].pos = i;
		}
	}

	sort(w1 + 1, w1 + 1 + p1);
	sort(w2 + 1, w2 + 1 + p2);
	if (p1 >= p2) {
		printf("%d\n", p1);
		for (int i = 1; i <= p1; i++)
			printf("%d ", w1[i].pos);
	}
	else {
		printf("%d\n", p2);
		for (int i = 1; i <= p2; i++)
			printf("%d ", w2[i].pos);
	}

#ifdef LOCAL
	fileclose();
#endif
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<map>
#include<bitset>
#include<utility>
#ifdef LOCAL
#include"file.h"
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
const double eps = 1e-6;
//const int dir[4][2] = { -1,0,1,0,0,-1,0,1 };
//const int dir[8][2] = { -2,-1,-2,1,2,-1,2,1,-1,2,-1,-2,1,2,1,-2 };

const int maxn = 3e5 + 5;
struct node {
	int a, b, pos;

	bool operator <(const node &oth)const {
		return a < oth.a;
	}

}w1[maxn],w2[maxn];
int p1 = 0, p2 = 0;
int n;

int main() {
#ifdef LOCAL
	fileopen();
#endif
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		if (a < b) {
			a = -a; b = -b;
			w1[++p1].a = a;
			w1[p1].b = b;
			w1[p1].pos = i;
		}
		else {

			w2[++p2].a = a;
			w2[p2].b = b;
			w2[p2].pos = i;
		}
	}

	sort(w1 + 1, w1 + 1 + p1);
	sort(w2 + 1, w2 + 1 + p2);
	if (p1 >= p2) {
		printf("%d\n", p1);
		for (int i = 1; i <= p1; i++)
			printf("%d ", w1[i].pos);
	}
	else {
		printf("%d\n", p2);
		for (int i = 1; i <= p2; i++)
			printf("%d ", w2[i].pos);
	}

#ifdef LOCAL
	fileclose();
#endif
	return 0;
}


#include <stdio.h>
#include <algorithm>

using namespace std;

class soya
{
public:
	int a, b, pos;
};

class cmp1
{
public:
	bool operator()(const soya& u, const soya& v)
	{
		if (u.a < v.a)
			return 1;
		else
			return 0;
	}
};

class cmp2
{
public:
	bool operator()(const soya& u, const soya& v)
	{
		if (u.a > v.a)
			return 1;
		else
		{
			return 0;
		}
	}
};

soya t1[300001];
soya t2[300001];

int main()
{
	//freopen("input.txt", "r", stdin);

	int n1, n2;
	int N;
	n1 = 0;
	n2 = 0;

	scanf("%d", &N);

	int i;

	for (i = 0; i < N; i++)
	{
		int x, y;

		scanf("%d %d", &x, &y);
		if (x < y)
		{
			t1[n1].a = x;
			t1[n1].b = y;
			t1[n1].pos = i + 1;
			n1++;
		}
		else
		{
			t2[n2].a = x;
			t2[n2].b = y;
			t2[n2].pos = i + 1;
			n2++;
		}
	}

	if (n1 > n2)
	{
		sort(t1, t1 + n1, cmp1());
		printf("%d\n", n1);
		for (i = n1-1; i >= 0; i--)
		{
			printf("%d ", t1[i].pos);
		}
	}
	else
	{
		sort(t2, t2 + n2, cmp2());
		printf("%d\n", n2);
		for (i = n2-1; i >= 0; i--)
		{
			printf("%d ", t2[i].pos);
		}
	}

	return 0;
}


#include <cstdio>
#include <cstring>
#include <cassert>
#include <cmath>

#include <algorithm>
#include <queue>
#include <functional>
#include <stack>
#include <vector>
#include <tuple>
#include <iostream>
#include <map>
#include <string>
#include <deque>
#include <set>

using namespace std;

using lint = long long;

using ii = pair < int, int >;
using ll = pair < lint, lint >;
using ti = tuple < int, int, int >;
using il = pair < int, lint >;
using tl = tuple < lint, lint, lint >;

#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define sc(x) scanf("%d", &x)

int n, m, k;
const int N = 1e6 + 5;
int a[N], b[N];
char s[N];

vector < ii > v1, v2;

void input() {
    sc(n);
    for(int i=1;i<=n;i++){
        int x,y;
        sc(x);
        sc(y);
        if(x<y){
            v1.push_back(ii(x,i));
        }
        else if(x>y){
            v2.push_back(ii(x,i));
        }
    }
    sort(v1.rbegin(), v1.rend());
    sort(all(v2));
    if(v1.size() > v2.size()){
        printf("%d\n", v1.size());
        for(auto p:v1){
            printf("%d ", p.second);
        }
    }
    else{
        printf("%d\n", v2.size());
        for(auto p:v2){
            printf("%d ", p.second);
        }
    }
}

void go() {

}

#define D

int main() {
#ifdef Da
    freopen("in.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    input();
    go();
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <stdio.h>
#include <stdarg.h>
#include <string>
#include <fstream>
#include <sstream>
#include <cstdio>

using namespace std;

struct Myp
{
  pair<int, int> p;
  int i;
};

bool mycmp1(const Myp& a, const Myp& b)
{
  return a.p.first < b.p.first;
}
bool mycmp2(const Myp& a, const Myp& b)
{
  return a.p.second > b.p.second;
}
Myp a[333333];

void print(const vector<Myp>& a)
{
  cout << a.size() << "\n";
  for (int i = 0; i < a.size(); ++i)
    cout << a[i].i << " ";
}

int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  cin >> n;

  vector<Myp> f, s;
  for (int i = 0; i < n; ++i)
  {
    cin >> a[i].p.first >> a[i].p.second;
    a[i].i = i+1;
    if (a[i].p.first > a[i].p.second)
      f.push_back(a[i]);
    else
      s.push_back(a[i]);
  }

  if (f.size() >= s.size())
  {
    sort(f.begin(), f.end(), mycmp1);
    print(f);
  }
  else
  {
    sort(s.begin(), s.end(), mycmp2);
    print(s);
  }

}


#include <iostream>
#include <cmath>
#include <queue>
#include <unordered_map>
#include <map>
#include <string>
#include <set>
using namespace std;

bool greater(const pair<int, int> &a, const pair<int, int> &b) {
	return a > b;
}

int main()
{
	int n, asize, bsize;
	pair<int, int> temp;
	cin >> n;
	vector<pair<int, int>> a, b;

	for (int i = 1; i <= n; i++) {
		cin >> temp.first >> temp.second;
		if (temp.first > temp.second) {
			temp.second = i;
			a.push_back(temp);
		}
		else {
			temp.second = i;
			b.push_back(temp);
		}
	}
	asize = a.size();
	bsize = b.size();

	if (asize > bsize) {
		sort(a.begin(), a.end());
		cout << asize << endl;
		for (int i = 0; i < asize; i++) {
			cout << a[i].second << ' ';
		}
	}
	else {
		sort(b.begin(), b.end(), greater);
		cout << bsize << endl;
		for (int i = 0; i < bsize; i++) {
			cout << b[i].second << ' ';
		}
	}

	return 0;
}


#include<stdio.h>
#include<vector>
#include<tuple>
#include<algorithm>

using namespace std;

vector<pair<int, int> > v[2];

bool cmp(pair<int, int> a, pair<int, int> b){
	return a.second > b.second;
}

int main(void){
	int N;
	scanf("%d", &N);
	for(int i=0; i<N; i++){
		int x,y;
		scanf("%d %d", &x, &y);
		if(x<y) v[0].push_back({i+1,y});
		else v[1].push_back({i+1,-y});
	}
	sort(v[0].begin(), v[0].end(),cmp);
	sort(v[1].begin(), v[1].end(),cmp);
	if(v[0].size()>v[1].size()) {printf("%d\n", v[0].size());for(auto i:v[0]) printf("%d ",i.first);}
	else {printf("%d\n", v[1].size());for(auto i:v[1]) printf("%d ",i.first);}

}


#include <iostream>
#include <vector>
#include <algorithm>

#define max(a, b) a > b ? a : b;

std::vector<std::pair<int, int>> v;
std::vector<std::pair<int, int>> v1;

int main() {
	int n, a, b;
	std::cin >> n;
	for (int i = 0; i < n; i++) {
		std::cin >> a >> b;
		if (a > b) {
			v.push_back(std::make_pair(a, i+1));
		}
		else v1.push_back(std::make_pair(a, i+1));
	}
	std::sort(v.begin(), v.end());
	std::sort(v1.rbegin(), v1.rend());
	int interm = max(v.size(), v1.size());
	std::cout << interm << std::endl;
	if (v.size() >= v1.size()) {
		for (int i = 0; i < v.size(); i++) {
			std::cout << v[i].second << " ";
		}
	}
	else {
		for (int i = 0; i < v1.size(); i++) {
			std::cout << v1[i].second << " ";
		}
	}
	return 0;
}


#include <iostream>
#include <queue>

int MAXX  = 6 * int(1e5) + 1;
using namespace std;

int ch1[int(1e6)], ch2[int(1e6)], id1[int(1e6)], id2[int(1e6)];
pair<int, int> p1[int(1e6)], p2[int(1e6)];
int q1[int(1e6)], q2[int(1e6)];
queue<int> que1, que2;

int main()
{
	int n, t1 = 0, t2 = 0, t = 0;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		int x, y;
		cin >> x >> y;
		if (x < y)
		{
			t1++;
			p1[t1] = { x,y };
			ch1[y + 1] = 1;
			id1[y] = i;
		}
		else
		{
			t2++;
			p2[t2] = { x,y };
			ch2[y - 1] = 1;
			id2[y] = i;
		}
	}

	int dem = int(1e8);
	for (int i = 1; i <= MAXX; i++) ch1[i] += ch1[i - 1];
	for (int i = MAXX; i >= 0; i--)
		if (id1[i] != 0)
		{
			if (dem == 1)
			{
				que1.push(id1[i]);
				break;
			}
			if (dem == int(1e8) || ch1[i] == dem - 1)
			{
				que1.push(id1[i]);
				dem = ch1[i];
				if (dem == 0)
					break;
			}
		}
	t1 = que1.size();

	dem = int(1e8);
	for (int i = MAXX - 1; i >= 0; i--) ch2[i] += ch2[i + 1];
	for (int i = 0; i <= MAXX; i++)
		if (id2[i] != 0)
		{
			if (dem == 1)
			{
				que2.push(id2[i]);
				break;
			}
			if (dem == int(1e8) || ch2[i] == dem - 1)
			{
				que2.push(id2[i]);
				dem = ch2[i];
				if (dem == 0)
					break;
			}
		}
	t2 = que2.size();

	if (t1 >= t2)
	{
		cout << t1 << endl;
		for (int i = 0; i < t1; i++)
		{
			cout << que1.front() << " ";
			que1.pop();
		}
	}
	else
	{
		cout << t2<< endl;
		for (int i = 0; i < t2; i++)
		{
			cout << que2.front() << " ";
			que2.pop();
		}
	}

	return 0;
}


#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
using namespace std;
struct mystruct {
	int first, second, index;
	mystruct(int a, int b, int c) :first(a), second(b), index(c) {}
	mystruct() :mystruct(0, 0, 0) {}
	bool operator<(const mystruct &a) const {
		return first < a.first;
	}
};
int main() {
//	ofstream cout("out.txt");
//	ifstream cin("in.txt");
	vector<mystruct> v1, v2;
	int n;
	cin >> n;
	for (int i=1;i<=n;i++) {
		int x, y;
		cin >> x >> y;
		if (x > y) v1.push_back(mystruct(x,y,i));
		else v2.push_back(mystruct(x, y, i));
	}
	if (v1.size() > v2.size()) {
		sort(v1.begin(), v1.end());
		cout << v1.size() << endl;
		for (auto i = v1.begin(); i != v1.end(); i++) cout << i->index << " ";
	}
	else {
		sort(v2.begin(), v2.end());
		cout << v2.size() << endl;
		for (auto i = v2.begin(); i != v2.end(); i++) cout << i->index << " ";
	}
}


#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
using namespace std;
struct mystruct {
	int first, second, index;
	mystruct(int a, int b, int c) :first(a), second(b), index(c) {}
	mystruct() :mystruct(0, 0, 0) {}
	bool operator<(const mystruct &a) const {
		return first < a.first;
	}
};
int main() {
	ofstream cout("out.txt");
	ifstream cin("in.txt");
	vector<mystruct> v1, v2;
	int n;
	//cin >> n;
	scanf("%d\n", &n);
	for (int i=1;i<=n;i++) {
		int x, y;
		scanf("%d %d", &x,&y);
		//cin >> x >> y;
		if (x > y) v1.push_back(mystruct(x,y,i));
		else v2.push_back(mystruct(x, y, i));
	}
	if (v1.size() > v2.size()) {
		sort(v1.begin(), v1.end());
		cout << v1.size() << endl;
		for (auto i = v1.begin(); i != v1.end(); i++) printf("%d ", i->index);
	}
	else {
		sort(v2.begin(), v2.end());
		cout << v2.size() << endl;
		for (auto i = v2.rbegin(); i != v2.rend(); i++) printf("%d ", i->index);
	}
}


#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
using namespace std;
struct mystruct {
	int first, second, index;
	mystruct(int a, int b, int c) :first(a), second(b), index(c) {}
	mystruct() :mystruct(0, 0, 0) {}
	bool operator<(const mystruct &a) const {
		return first < a.first;
	}
};
int main() {
//	ofstream cout("out.txt");
//	ifstream cin("in.txt");
	vector<mystruct> v1, v2;
	int n;
	//cin >> n;
	scanf("%d\n", &n);
	for (int i=1;i<=n;i++) {
		int x, y;
		scanf("%d %d", &x,&y);
		//cin >> x >> y;
		if (x > y) v1.push_back(mystruct(x,y,i));
		else v2.push_back(mystruct(x, y, i));
	}
	if (v1.size() > v2.size()) {
		sort(v1.begin(), v1.end());
		cout << v1.size() << endl;
		for (auto i = v1.begin(); i != v1.end(); i++) printf("%d ", i->index);
	}
	else {
		sort(v2.begin(), v2.end());
		cout << v2.size() << endl;
		for (auto i = v2.rbegin(); i != v2.rend(); i++) printf("%d ", i->index);
	}
}


#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
using namespace std;
struct mystruct {
	int first, second, index;
	mystruct(int a, int b, int c) :first(a), second(b), index(c) {}
	mystruct() :mystruct(0, 0, 0) {}
	bool operator<(const mystruct &a) const {
		return first < a.first;
	}
};
int main() {
//	ofstream cout("out.txt");
//	ifstream cin("in.txt");
	vector<mystruct> v1, v2;
	int n;
	cin >> n;
	for (int i=1;i<=n;i++) {
		int x, y;
		cin >> x >> y;
		if (x > y) v1.push_back(mystruct(x,y,i));
		else v2.push_back(mystruct(x, y, i));
	}
	if (v1.size() > v2.size()) {
		sort(v1.begin(), v1.end());
		cout << v1.size() << endl;
		for (auto i = v1.begin(); i != v1.end(); i++) cout << i->index << " ";
	}
	else {
		sort(v2.begin(), v2.end());
		cout << v2.size() << endl;
		for (auto i = v2.rbegin(); i != v2.rend(); i++) cout << i->index << " ";
	}
}


#include<cstdio>
#include<string>
#include<string.h>
#include<map>
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<stack>
#define inf 0x3f3f3f3f
#define P(x,y)  make_pair(x,y)
#define lowbit(i1) (i1)&(-i1)
using namespace std;

struct node
{
	int x, y, id;
}edge1[300010],edge2[300010];//1:x<y   2:x>y

bool cmp1(node a, node b)
{
	return a.x >= b.x;
}

bool cmp2(node a, node b)
{
	return a.x <= b.x;
}

int main()
{
	int n;
	while (scanf_s("%d", &n) != EOF)
	{
		int p1=0, p2=0;
		for (int i = 1; i <= n; i++)
		{
			int x, y;
			scanf_s("%d%d", &x, &y);
			if (x > y)//2
			{
				edge2[++p2].x = x;
				edge2[p2].y = y;
				edge2[p2].id = i;
			}
			else if (x < y)//1
			{
				edge1[++p1].x = x;
				edge1[p1].y = y;
				edge1[p1].id = i;
			}
		}
		sort(edge1 + 1, edge1 + 1 + p1, cmp1);
		sort(edge2 + 1, edge2 + 1 + p2, cmp2);
		if (p1 >= p2)
			for (int i = 1; i <= p1; i++)
				printf("%d ", edge1[i].id);
		else
			for (int i = 1; i <= p2; i++)
				printf("%d ", edge2[i].id);
		printf("\n");
	}
	return 0;
}


#include<cstdio>
#include<string>
#include<string.h>
#include<map>
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<stack>
#define inf 0x3f3f3f3f
#define P(x,y)  make_pair(x,y)
#define lowbit(i1) (i1)&(-i1)
using namespace std;

struct node
{
	int x, y, id;
}edge1[300010],edge2[300010];//1:x<y   2:x>y

bool cmp1(node a, node b)
{
	return a.x >= b.x;
}

bool cmp2(node a, node b)
{
	return a.x <= b.x;
}

int main()
{
	int n;
	while (scanf_s("%d", &n) != EOF)
	{
		int p1=0, p2=0;
		for (int i = 1; i <= n; i++)
		{
			int x, y;
			scanf_s("%d%d", &x, &y);
			if (x > y)//2
			{
				edge2[++p2].x = x;
				edge2[p2].y = y;
				edge2[p2].id = i;
			}
			else if (x < y)//1
			{
				edge1[++p1].x = x;
				edge1[p1].y = y;
				edge1[p1].id = i;
			}
		}
		sort(edge1 + 1, edge1 + 1 + p1, cmp1);
		sort(edge2 + 1, edge2 + 1 + p2, cmp2);
		if (p1 >= p2)
		{
			printf("%d\n", p1);
			for (int i = 1; i <= p1; i++)
				printf("%d ", edge1[i].id);
		}
		else
		{
			printf("%d\n", p2);
			for (int i = 1; i <= p2; i++)
				printf("%d ", edge2[i].id);
		}
		printf("\n");
	}
	return 0;
}


#include <iostream>
#include <vector>
#include<iomanip>
#include <cstring>
#include <string.h>
#include <iterator>
#include <math.h>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <limits.h>
#include <string>
#include <bitset>
#include <map>
#include <numeric>
#include<unordered_map>

#define endl cout<<"\n"
#define lli long long int
#define ld long double
#define M_PI (3.14159265358979323846264338327950288)
#define MOD (1000000007)

using namespace std;

//fast-exponentiation-lli
lli expo_fast(lli a, lli b) {
	a = a;
	lli result = 1;
	while (b) {
		//multiplyint(tos(result), a);
		if (b & 1)result = (result * a);
		b >>= 1;
		a = (a*a);
	}
	return (result);
}

void take_in(vector<lli> *arr) {
	for (int i = 0; i < arr->size(); i++)cin >> (*(arr))[i];
}

void disp_arr(vector<lli>* arr) {
	for (int i = 0; i < arr->size(); i++)cout << (*(arr))[i] << " ";
}

lli gcd(lli a, lli b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);

}

/* Iterative Function to calculate (x^y)%p in O(log y) */
lli power(lli x, unsigned lli y, lli p)
{
	lli res = 1;      // Initialize result
	x = x % p;  // Update x if it is more than or
				// equal to p
	while (y > 0)
	{
		// If y is odd, multiply x with result
		if (y & 1)
			res = (res*x) % p;
		// y must be even now
		y = y >> 1;
		x = (x*x) % p;
	}
	return res;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n; cin >> n;
	vector<pair<lli, lli>> l, r;
	multimap<pair<lli, lli>, int> mmap;
	for (int i = 0; i < n; i++) {
		lli a, b; cin >> a >> b;
		if (b > a)l.push_back(make_pair(a, b));
		else r.push_back(make_pair(a, b));
		mmap.insert(make_pair(make_pair(a, b), i));
	}

	sort(l.rbegin(), l.rend());
	//reverse(l.begin(), l.end());
	sort(r.begin(), r.end());

	if (l.size() >= r.size()) {
		cout << l.size(); endl;
		for (auto x : l) {
			cout << (*mmap.find(x)).second + 1 << " ";
		}
	}
	else {
		cout << r.size(); endl;
		for (auto x : r) {
			cout << (*mmap.find(x)).second + 1 << " ";
		}
	}
//	system("PAUSE");
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <stdio.h>
#include <stack>
#include <iomanip>
#include <cmath>
#include <functional>
#define f(n) for(ll i=0;i<n;i++)
#define mp make_pair
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define INF 2e9
#define MOD 1000000007  //998244353
#define eps 0.00000001
#define pi 3.1415926535

inline int mul(int a, int b) {
	return int(a * 1ll * b % MOD);
}

inline int norm(int a) {
	if (a >= MOD)
		a -= MOD;
	if (a < 0)
		a += MOD;
	return a;
}

inline int binPow(int a, int k) {
	int ans = 1;
	while (k > 0) {
		if (k & 1)
			ans = mul(ans, a);
		a = mul(a, a);
		k >>= 1;
	}
	return ans;
}

inline int subtract(int a, int b) {
	return norm(a - b);
}

inline int sum(int a, int b) {
	return int((a + b) % MOD);
}

inline int inv(int a) {   //a/k=a*inv(k) divizion with MOD q^-1
	return binPow(a, MOD - 2);
}

//**************************************START*****************************

int main() {
	ll n;
	cin >> n;
	vector<pair<pair<int,int>,int>>a(n);
	vector<pii>b(n);
	ll ans = 0;
	vector<int>res;
	vector<int>real;
	for (int i = 0; i < n; i++) {
		int r, k;
		cin >> r >> k;
		a[i].first.first = r;
		a[i].first.second = k;
		a[i].second = i + 1;
	}
	sort(all(a));
	ll cur = 1;

	pii prev = { a[0].first.first,a[0].first.second };
	res.push_back(a[0].second);
	for (int i = 0; i < n-1; i++) {
		if (prev.first < prev.second && a[i + 1].first.first < prev.second && a[i + 1].first.first<a[i + 1].first.second) {
			cur++;
			prev = { a[i+1].first.first,a[i+1].first.second };
			res.push_back(a[i+1].second);
		}
	}
	if (cur > ans) {
		ans = cur;
		real = res;
		cur = 1;

	}res.clear(); cur = 1;

	prev = { a[n-1].first.first,a[n-1].first.second };
	res.push_back(a[n-1].second);
	for (int i = n-1; i >=1; i--) {
		if (prev.first < prev.second && a[i - 1].first.first < prev.second && a[i -1].first.first < a[i - 1].first.second) {
			cur++;
			prev = { a[i-1].first.first,a[i-1].first.second };
			res.push_back(a[i-1].second);
		}
	}
	if (cur > ans) {
		ans = cur;
		real = res;
		cur = 1;

	}res.clear(); cur = 1;
	prev = { a[0].first.first,a[0].first.second };
	res.push_back(a[0].second);
	for (int i = 0; i < n - 1; i++) {
		if (prev.first > prev.second && a[i + 1].first.first > prev.second && a[i + 1].first.first > a[i + 1].first.second) {
			cur++;
			prev = { a[i+1].first.first,a[i+1].first.second };
			res.push_back(a[i+1].second);
		}
	}
	if (cur > ans) {
		ans = cur;
		real = res;
		cur = 1;

	}	res.clear(); cur = 1;
	prev = { a[n - 1].first.first,a[n - 1].first.second };
	res.push_back(a[n-1].second);
	for (int i = n - 1; i >= 1; i--) {
		if (prev.first > prev.second && a[i - 1].first.first > prev.second && a[i - 1].first.first > a[i - 1].first.second) {
			cur++;
			prev = { a[i-1].first.first,a[i-1].first.second };
			res.push_back(a[i-1].second);
		}
	}
	if (cur > ans) {
		ans = cur;
		real = res;
		cur = 1;

	}res.clear(); cur = 1;
	for (int i = 0; i < n; i++) {
		swap(a[i].first.first, a[i].first.second);
	}	sort(all(a));
	 cur = 1;

	 prev = { a[0].first.first,a[0].first.second };
	res.push_back(a[0].second);
	for (int i = 0; i < n - 1; i++) {
		if (prev.first < prev.second && a[i + 1].first.first < prev.second && a[i + 1].first.first < a[i + 1].first.second) {
			cur++;
			prev = { a[i + 1].first.first,a[i + 1].first.second };
			res.push_back(a[i + 1].second);
		}
	}
	if (cur > ans) {
		ans = cur;
		real = res;
		cur = 1;

	}res.clear(); cur = 1;

	prev = { a[n - 1].first.first,a[n - 1].first.second };
	res.push_back(a[n - 1].second);
	for (int i = n - 1; i >= 1; i--) {
		if (prev.first < prev.second && a[i - 1].first.first < prev.second && a[i - 1].first.first < a[i - 1].first.second) {
			cur++;
			prev = { a[i - 1].first.first,a[i - 1].first.second };
			res.push_back(a[i - 1].second);
		}
	}
	if (cur > ans) {
		ans = cur;
		real = res;
		cur = 1;

	}res.clear(); cur = 1;
	prev = { a[0].first.first,a[0].first.second };
	res.push_back(a[0].second);
	for (int i = 0; i < n - 1; i++) {
		if (prev.first > prev.second && a[i + 1].first.first > prev.second && a[i + 1].first.first > a[i + 1].first.second) {
			cur++;
			prev = { a[i + 1].first.first,a[i + 1].first.second };
			res.push_back(a[i + 1].second);
		}
	}
	if (cur > ans) {
		ans = cur;
		real = res;
		cur = 1;

	}	res.clear(); cur = 1;
	prev = { a[n - 1].first.first,a[n - 1].first.second };
	res.push_back(a[n - 1].second);
	for (int i = n - 1; i >= 1; i--) {
		if (prev.first > prev.second && a[i - 1].first.first > prev.second && a[i - 1].first.first > a[i - 1].first.second) {
			cur++;
			prev = { a[i - 1].first.first,a[i - 1].first.second };
			res.push_back(a[i - 1].second);
		}
	}
	if (cur > ans) {
		ans = cur;
		real = res;
		cur = 1;

	}res.clear(); cur = 1;
	cout << ans << endl;
	for (int i = 0; i < ans; i++) {
		cout << real[i] << " ";
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <stdio.h>
#include <stack>
#include <iomanip>
#include <cmath>
#include <functional>
#define f(n) for(ll i=0;i<n;i++)
#define mp make_pair
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define INF 2e9
#define MOD 1000000007  //998244353
#define eps 0.00000001
#define pi 3.1415926535

inline int mul(int a, int b) {
	return int(a * 1ll * b % MOD);
}

inline int norm(int a) {
	if (a >= MOD)
		a -= MOD;
	if (a < 0)
		a += MOD;
	return a;
}

inline int binPow(int a, int k) {
	int ans = 1;
	while (k > 0) {
		if (k & 1)
			ans = mul(ans, a);
		a = mul(a, a);
		k >>= 1;
	}
	return ans;
}

inline int subtract(int a, int b) {
	return norm(a - b);
}

inline int sum(int a, int b) {
	return int((a + b) % MOD);
}

inline int inv(int a) {   //a/k=a*inv(k) divizion with MOD q^-1
	return binPow(a, MOD - 2);
}

//**************************************START*****************************

int main() {
	ll n;
	cin >> n;
	vector<pair<pair<int,int>,int>>a(n);
	vector<pii>b(n);
	ll ans = 0;
	vector<int>res;
	vector<int>real;
	for (int i = 0; i < n; i++) {
		int r, k;
		cin >> r >> k;
		a[i].first.first = r;
		a[i].first.second = k;
		a[i].second = i + 1;
	}
	sort(all(a));
	ll cur = 0;
	pii prev = { a[0].first.first,a[0].first.second };
	res.push_back(a[0].second);
	for (int i = 0; i < n-1; i++) {
		if (prev.first < prev.second && a[i + 1].first.first < prev.second) {
			cur++;
			prev = { a[i].first.first,a[i].first.second };
			res.push_back(a[i+1].second);
		}
	}
	if (cur > ans) {
		ans = cur;
		real = res;
		cur = 1;
		res.clear();
	}

	prev = { a[n-1].first.first,a[n-1].first.second };
	res.push_back(a[n-1].second);
	for (int i = n-1; i >=1; i--) {
		if (prev.first < prev.second && a[i - 1].first.first < prev.second) {
			cur++;
			prev = { a[i].first.first,a[i].first.second };
			res.push_back(a[i-1].second);
		}
	}
	if (cur > ans) {
		ans = cur;
		real = res;
		cur = 1;
		res.clear();
	}
	prev = { a[0].first.first,a[0].first.second };
	res.push_back(a[0].second);
	for (int i = 0; i < n - 1; i++) {
		if (prev.first > prev.second && a[i + 1].first.first > prev.second) {
			cur++;
			prev = { a[i].first.first,a[i].first.second };
			res.push_back(a[i+1].second);
		}
	}
	if (cur > ans) {
		ans = cur;
		real = res;
		cur = 1;
		res.clear();
	}
	prev = { a[n - 1].first.first,a[n - 1].first.second };
	res.push_back(a[n-1].second);
	for (int i = n - 1; i >= 1; i--) {
		if (prev.first > prev.second && a[i - 1].first.first > prev.second) {
			cur++;
			prev = { a[i].first.first,a[i].first.second };
			res.push_back(a[i-1].second);
		}
	}
	if (cur > ans) {
		ans = cur;
		real = res;
		cur = 1;
		res.clear();
	}
	cout << ans << endl;
	for (int i = 0; i < ans; i++) {
		cout << real[i] << " ";
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <stdio.h>
#include <stack>
#include <iomanip>
#include <cmath>
#include <functional>
#define f(n) for(ll i=0;i<n;i++)
#define mp make_pair
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define INF 2e9
#define MOD 1000000007  //998244353
#define eps 0.00000001
#define pi 3.1415926535

inline int mul(int a, int b) {
	return int(a * 1ll * b % MOD);
}

inline int norm(int a) {
	if (a >= MOD)
		a -= MOD;
	if (a < 0)
		a += MOD;
	return a;
}

inline int binPow(int a, int k) {
	int ans = 1;
	while (k > 0) {
		if (k & 1)
			ans = mul(ans, a);
		a = mul(a, a);
		k >>= 1;
	}
	return ans;
}

inline int subtract(int a, int b) {
	return norm(a - b);
}

inline int sum(int a, int b) {
	return int((a + b) % MOD);
}

inline int inv(int a) {   //a/k=a*inv(k) divizion with MOD q^-1
	return binPow(a, MOD - 2);
}

//**************************************START*****************************

int main() {
	ll n;
	cin >> n;
	vector<pair<pair<int,int>,int>>a(n);
	vector<pii>b(n);
	ll ans = 0;
	vector<int>res;
	vector<int>real;
	for (int i = 0; i < n; i++) {
		int r, k;
		cin >> r >> k;
		a[i].first.first = r;
		a[i].first.second = k;
		a[i].second = i + 1;
	}
	sort(all(a));
	ll cur = 1;

	pii prev = { a[0].first.first,a[0].first.second };
	res.push_back(a[0].second);
	for (int i = 0; i < n-1; i++) {
		if (prev.first < prev.second && a[i + 1].first.first < prev.second) {
			cur++;
			prev = { a[i+1].first.first,a[i+1].first.second };
			res.push_back(a[i+1].second);
		}
	}
	if (cur > ans) {
		ans = cur;
		real = res;
		cur = 1;

	}res.clear(); cur = 1;

	prev = { a[n-1].first.first,a[n-1].first.second };
	res.push_back(a[n-1].second);
	for (int i = n-1; i >=1; i--) {
		if (prev.first < prev.second && a[i - 1].first.first < prev.second) {
			cur++;
			prev = { a[i-1].first.first,a[i-1].first.second };
			res.push_back(a[i-1].second);
		}
	}
	if (cur > ans) {
		ans = cur;
		real = res;
		cur = 1;

	}res.clear(); cur = 1;
	prev = { a[0].first.first,a[0].first.second };
	res.push_back(a[0].second);
	for (int i = 0; i < n - 1; i++) {
		if (prev.first > prev.second && a[i + 1].first.first > prev.second) {
			cur++;
			prev = { a[i+1].first.first,a[i+1].first.second };
			res.push_back(a[i+1].second);
		}
	}
	if (cur > ans) {
		ans = cur;
		real = res;
		cur = 1;

	}	res.clear(); cur = 1;
	prev = { a[n - 1].first.first,a[n - 1].first.second };
	res.push_back(a[n-1].second);
	for (int i = n - 1; i >= 1; i--) {
		if (prev.first > prev.second && a[i - 1].first.first > prev.second) {
			cur++;
			prev = { a[i-1].first.first,a[i-1].first.second };
			res.push_back(a[i-1].second);
		}
	}
	if (cur > ans) {
		ans = cur;
		real = res;
		cur = 1;

	}res.clear(); cur = 1;
	cout << ans << endl;
	for (int i = 0; i < ans; i++) {
		cout << real[i] << " ";
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <stdio.h>
#include <stack>
#include <iomanip>
#include <cmath>
#include <functional>
#define f(n) for(ll i=0;i<n;i++)
#define mp make_pair
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define INF 2e9
#define MOD 1000000007  //998244353
#define eps 0.00000001
#define pi 3.1415926535

inline int mul(int a, int b) {
	return int(a * 1ll * b % MOD);
}

inline int norm(int a) {
	if (a >= MOD)
		a -= MOD;
	if (a < 0)
		a += MOD;
	return a;
}

inline int binPow(int a, int k) {
	int ans = 1;
	while (k > 0) {
		if (k & 1)
			ans = mul(ans, a);
		a = mul(a, a);
		k >>= 1;
	}
	return ans;
}

inline int subtract(int a, int b) {
	return norm(a - b);
}

inline int sum(int a, int b) {
	return int((a + b) % MOD);
}

inline int inv(int a) {   //a/k=a*inv(k) divizion with MOD q^-1
	return binPow(a, MOD - 2);
}

//**************************************START*****************************

int main() {
	ll n;
	cin >> n;
	vector<pair<pair<int,int>,int>>a(n);
	vector<pii>b(n);
	ll ans = 0;
	vector<int>res;
	vector<int>real;
	for (int i = 0; i < n; i++) {
		int r, k;
		cin >> r >> k;
		a[i].first.first = r;
		a[i].first.second = k;
		a[i].second = i + 1;
	}
	sort(all(a));
	ll cur = 1;

	pii prev = { a[0].first.first,a[0].first.second };
	res.push_back(a[0].second);
	for (int i = 0; i < n-1; i++) {
		if (prev.first < prev.second && a[i + 1].first.first < prev.second) {
			cur++;
			prev = { a[i+1].first.first,a[i+1].first.second };
			res.push_back(a[i+1].second);
		}
	}
	if (cur > ans) {
		ans = cur;
		real = res;
		cur = 1;

	}res.clear(); cur = 1;

	prev = { a[n-1].first.first,a[n-1].first.second };
	res.push_back(a[n-1].second);
	for (int i = n-1; i >=1; i--) {
		if (prev.first < prev.second && a[i - 1].first.first < prev.second) {
			cur++;
			prev = { a[i-1].first.first,a[i-1].first.second };
			res.push_back(a[i-1].second);
		}
	}
	if (cur > ans) {
		ans = cur;
		real = res;
		cur = 1;

	}res.clear(); cur = 1;
	prev = { a[0].first.first,a[0].first.second };
	res.push_back(a[0].second);
	for (int i = 0; i < n - 1; i++) {
		if (prev.first > prev.second && a[i + 1].first.first > prev.second) {
			cur++;
			prev = { a[i+1].first.first,a[i+1].first.second };
			res.push_back(a[i+1].second);
		}
	}
	if (cur > ans) {
		ans = cur;
		real = res;
		cur = 1;

	}	res.clear(); cur = 1;
	prev = { a[n - 1].first.first,a[n - 1].first.second };
	res.push_back(a[n-1].second);
	for (int i = n - 1; i >= 1; i--) {
		if (prev.first > prev.second && a[i - 1].first.first > prev.second) {
			cur++;
			prev = { a[i-1].first.first,a[i-1].first.second };
			res.push_back(a[i-1].second);
		}
	}
	if (cur > ans) {
		ans = cur;
		real = res;
		cur = 1;

	}res.clear(); cur = 1;
	for (int i = 0; i < n; i++) {
		swap(a[i].first.first, a[i].first.second);
	}
	sort(all(a));
	 cur = 1;

	 prev = { a[0].first.first,a[0].first.second };
	res.push_back(a[0].second);
	for (int i = 0; i < n - 1; i++) {
		if (prev.first < prev.second && a[i + 1].first.first < prev.second) {
			cur++;
			prev = { a[i + 1].first.first,a[i + 1].first.second };
			res.push_back(a[i + 1].second);
		}
	}
	if (cur > ans) {
		ans = cur;
		real = res;
		cur = 1;

	}res.clear(); cur = 1;

	prev = { a[n - 1].first.first,a[n - 1].first.second };
	res.push_back(a[n - 1].second);
	for (int i = n - 1; i >= 1; i--) {
		if (prev.first < prev.second && a[i - 1].first.first < prev.second) {
			cur++;
			prev = { a[i - 1].first.first,a[i - 1].first.second };
			res.push_back(a[i - 1].second);
		}
	}
	if (cur > ans) {
		ans = cur;
		real = res;
		cur = 1;

	}res.clear(); cur = 1;
	prev = { a[0].first.first,a[0].first.second };
	res.push_back(a[0].second);
	for (int i = 0; i < n - 1; i++) {
		if (prev.first > prev.second && a[i + 1].first.first > prev.second) {
			cur++;
			prev = { a[i + 1].first.first,a[i + 1].first.second };
			res.push_back(a[i + 1].second);
		}
	}
	if (cur > ans) {
		ans = cur;
		real = res;
		cur = 1;

	}	res.clear(); cur = 1;
	prev = { a[n - 1].first.first,a[n - 1].first.second };
	res.push_back(a[n - 1].second);
	for (int i = n - 1; i >= 1; i--) {
		if (prev.first > prev.second && a[i - 1].first.first > prev.second) {
			cur++;
			prev = { a[i - 1].first.first,a[i - 1].first.second };
			res.push_back(a[i - 1].second);
		}
	}
	if (cur > ans) {
		ans = cur;
		real = res;
		cur = 1;

	}res.clear(); cur = 1;

	cout << ans << endl;
	for (int i = 0; i < ans; i++) {
		cout << real[i] << " ";
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <stdio.h>
#include <stack>
#include <iomanip>
#include <cmath>
#include <functional>
#define f(n) for(ll i=0;i<n;i++)
#define mp make_pair
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define INF 2e9
#define MOD 1000000007  //998244353
#define eps 0.00000001
#define pi 3.1415926535

inline int mul(int a, int b) {
	return int(a * 1ll * b % MOD);
}

inline int norm(int a) {
	if (a >= MOD)
		a -= MOD;
	if (a < 0)
		a += MOD;
	return a;
}

inline int binPow(int a, int k) {
	int ans = 1;
	while (k > 0) {
		if (k & 1)
			ans = mul(ans, a);
		a = mul(a, a);
		k >>= 1;
	}
	return ans;
}

inline int subtract(int a, int b) {
	return norm(a - b);
}

inline int sum(int a, int b) {
	return int((a + b) % MOD);
}

inline int inv(int a) {   //a/k=a*inv(k) divizion with MOD q^-1
	return binPow(a, MOD - 2);
}

//**************************************START*****************************

int main() {
	ll n;
	cin >> n;
	vector<pair<pair<int,int>,int>>a(n);
	vector<pii>b(n);
	ll ans = 0;
	vector<int>res;
	vector<int>real;
	for (int i = 0; i < n; i++) {
		int r, k;
		cin >> r >> k;
		a[i].first.first = r;
		a[i].first.second = k;
		a[i].second = i + 1;
	}
	sort(all(a));
	ll cur = 1;

	pii prev = { a[0].first.first,a[0].first.second };
	res.push_back(a[0].second);
	for (int i = 0; i < n-1; i++) {
		if (prev.first < prev.second && a[i + 1].first.first < prev.second && a[i + 1].first.first<a[i + 1].first.second) {
			cur++;
			prev = { a[i+1].first.first,a[i+1].first.second };
			res.push_back(a[i+1].second);
		}
	}
	if (cur > ans) {
		ans = cur;
		real = res;
		cur = 1;

	}res.clear(); cur = 1;

	prev = { a[n-1].first.first,a[n-1].first.second };
	res.push_back(a[n-1].second);
	for (int i = n-1; i >=1; i--) {
		if (prev.first < prev.second && a[i - 1].first.first < prev.second && a[i -1].first.first < a[i - 1].first.second) {
			cur++;
			prev = { a[i-1].first.first,a[i-1].first.second };
			res.push_back(a[i-1].second);
		}
	}
	if (cur > ans) {
		ans = cur;
		real = res;
		cur = 1;

	}res.clear(); cur = 1;
	prev = { a[0].first.first,a[0].first.second };
	res.push_back(a[0].second);
	for (int i = 0; i < n - 1; i++) {
		if (prev.first > prev.second && a[i + 1].first.first > prev.second && a[i + 1].first.first > a[i + 1].first.second) {
			cur++;
			prev = { a[i+1].first.first,a[i+1].first.second };
			res.push_back(a[i+1].second);
		}
	}
	if (cur > ans) {
		ans = cur;
		real = res;
		cur = 1;

	}	res.clear(); cur = 1;
	prev = { a[n - 1].first.first,a[n - 1].first.second };
	res.push_back(a[n-1].second);
	for (int i = n - 1; i >= 1; i--) {
		if (prev.first > prev.second && a[i - 1].first.first > prev.second && a[i - 1].first.first > a[i - 1].first.second) {
			cur++;
			prev = { a[i-1].first.first,a[i-1].first.second };
			res.push_back(a[i-1].second);
		}
	}
	if (cur > ans) {
		ans = cur;
		real = res;
		cur = 1;

	}res.clear(); cur = 1;
	for (int i = 0; i < n; i++) {
		swap(a[i].first.first, a[i].first.second);
	}	sort(all(a));
	for (int i = 0; i < n; i++) {
		swap(a[i].first.first, a[i].first.second);
	}
	 cur = 1;

	 prev = { a[0].first.first,a[0].first.second };
	res.push_back(a[0].second);
	for (int i = 0; i < n - 1; i++) {
		if (prev.first < prev.second && a[i + 1].first.first < prev.second && a[i + 1].first.first < a[i + 1].first.second) {
			cur++;
			prev = { a[i + 1].first.first,a[i + 1].first.second };
			res.push_back(a[i + 1].second);
		}
	}
	if (cur > ans) {
		ans = cur;
		real = res;
		cur = 1;

	}res.clear(); cur = 1;

	prev = { a[n - 1].first.first,a[n - 1].first.second };
	res.push_back(a[n - 1].second);
	for (int i = n - 1; i >= 1; i--) {
		if (prev.first < prev.second && a[i - 1].first.first < prev.second && a[i - 1].first.first < a[i - 1].first.second) {
			cur++;
			prev = { a[i - 1].first.first,a[i - 1].first.second };
			res.push_back(a[i - 1].second);
		}
	}
	if (cur > ans) {
		ans = cur;
		real = res;
		cur = 1;

	}res.clear(); cur = 1;
	prev = { a[0].first.first,a[0].first.second };
	res.push_back(a[0].second);
	for (int i = 0; i < n - 1; i++) {
		if (prev.first > prev.second && a[i + 1].first.first > prev.second && a[i + 1].first.first > a[i + 1].first.second) {
			cur++;
			prev = { a[i + 1].first.first,a[i + 1].first.second };
			res.push_back(a[i + 1].second);
		}
	}
	if (cur > ans) {
		ans = cur;
		real = res;
		cur = 1;

	}	res.clear(); cur = 1;
	prev = { a[n - 1].first.first,a[n - 1].first.second };
	res.push_back(a[n - 1].second);
	for (int i = n - 1; i >= 1; i--) {
		if (prev.first > prev.second && a[i - 1].first.first > prev.second && a[i - 1].first.first > a[i - 1].first.second) {
			cur++;
			prev = { a[i - 1].first.first,a[i - 1].first.second };
			res.push_back(a[i - 1].second);
		}
	}
	if (cur > ans) {
		ans = cur;
		real = res;
		cur = 1;

	}res.clear(); cur = 1;
	cout << ans << endl;
	for (int i = 0; i < ans; i++) {
		cout << real[i] << " ";
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <stdio.h>
#include <stack>
#include <iomanip>
#include <cmath>
#include <functional>
#define f(n) for(ll i=0;i<n;i++)
#define mp make_pair
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define INF 2e9
#define MOD 1000000007  //998244353
#define eps 0.00000001
#define pi 3.1415926535

inline int mul(int a, int b) {
	return int(a * 1ll * b % MOD);
}

inline int norm(int a) {
	if (a >= MOD)
		a -= MOD;
	if (a < 0)
		a += MOD;
	return a;
}

inline int binPow(int a, int k) {
	int ans = 1;
	while (k > 0) {
		if (k & 1)
			ans = mul(ans, a);
		a = mul(a, a);
		k >>= 1;
	}
	return ans;
}

inline int subtract(int a, int b) {
	return norm(a - b);
}

inline int sum(int a, int b) {
	return int((a + b) % MOD);
}

inline int inv(int a) {   //a/k=a*inv(k) divizion with MOD q^-1
	return binPow(a, MOD - 2);
}

//**************************************START*****************************

int main() {
	ll n;
	cin >> n;
	vector<pair<pair<int,int>,int>>a(n);
	vector<pii>b(n);
	ll ans = 0;
	vector<int>res;
	vector<int>real;
	for (int i = 0; i < n; i++) {
		int r, k;
		cin >> r >> k;
		a[i].first.first = r;
		a[i].first.second = k;
		a[i].second = i + 1;
	}
	sort(all(a));
	ll cur = 1;

	pii prev = { a[0].first.first,a[0].first.second };
	res.push_back(a[0].second);
	for (int i = 0; i < n-1; i++) {
		if (prev.first < prev.second && a[i + 1].first.first < prev.second) {
			cur++;
			prev = { a[i].first.first,a[i].first.second };
			res.push_back(a[i+1].second);
		}
	}
	if (cur > ans) {
		ans = cur;
		real = res;
		cur = 1;

	}res.clear(); cur = 1;

	prev = { a[n-1].first.first,a[n-1].first.second };
	res.push_back(a[n-1].second);
	for (int i = n-1; i >=1; i--) {
		if (prev.first < prev.second && a[i - 1].first.first < prev.second) {
			cur++;
			prev = { a[i].first.first,a[i].first.second };
			res.push_back(a[i-1].second);
		}
	}
	if (cur > ans) {
		ans = cur;
		real = res;
		cur = 1;

	}res.clear(); cur = 1;
	prev = { a[0].first.first,a[0].first.second };
	res.push_back(a[0].second);
	for (int i = 0; i < n - 1; i++) {
		if (prev.first > prev.second && a[i + 1].first.first > prev.second) {
			cur++;
			prev = { a[i].first.first,a[i].first.second };
			res.push_back(a[i+1].second);
		}
	}
	if (cur > ans) {
		ans = cur;
		real = res;
		cur = 1;

	}	res.clear(); cur = 1;
	prev = { a[n - 1].first.first,a[n - 1].first.second };
	res.push_back(a[n-1].second);
	for (int i = n - 1; i >= 1; i--) {
		if (prev.first > prev.second && a[i - 1].first.first > prev.second) {
			cur++;
			prev = { a[i].first.first,a[i].first.second };
			res.push_back(a[i-1].second);
		}
	}
	if (cur > ans) {
		ans = cur;
		real = res;
		cur = 1;

	}res.clear(); cur = 1;
	cout << ans << endl;
	for (int i = 0; i < ans; i++) {
		cout << real[i] << " ";
	}
}


#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:256000000")
#include<utility>
#include<iostream>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

//4Head

#define mp make_pair
#define X first
#define Y second

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(NULL));

ll const maxn = 3e5 + 5;
ll n;

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	vector<pair<pair<ll,ll>,ll>>p1, p2;
	for (ll i = 0; i < n; i++) {
		ll x, y; cin >> x >> y;
		if (x < y) p1.push_back({ { x,y },i + 1 });
		else p2.push_back({ { x,y },i + 1 });
	}
	sort(p1.begin(), p1.end(), [&](pair<pair<ll, ll>, ll>a, pair<pair<ll, ll>, ll>b) {
		return a.X.Y > b.X.Y;
	});
	sort(begin(p2), end(p2), [&](pair<pair<ll, ll>, ll>a, pair<pair<ll, ll>, ll>b) {
		return a.X.Y < b.X.Y;
	});
	if (p1.size() > p2.size()) {
		cout << p1.size() << endl;
		for (auto now : p1) {
			cout << now.Y << ' ';
		}
	}
	else {
		cout << p2.size() << endl;
		for (auto now : p2) {
			cout << now.Y << ' ';
		}
	}
	return 0;
}

/*

*/


#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <math.h>
#include <string>
#include <time.h>
#include <random>
#include <memory.h>
#include <bitset>
using namespace std;

#define FILE0
#define MAGIC0
mt19937 rnd(time(0)); //rnd()

#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mii map<int, int>
#define mll map<ll, ll>
#define msl map<string, ll>
#define mls map<ll, string>
#define MOD (1000000007ll)
#define MOD2 (1000000009ll)
#define BIGMOD (1000000000000000007ll)
#define RMOD int(5e8 + rnd() % (int) 5e8)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#ifdef FILE1
ifstream in("input.txt");
ofstream out("output.txt");
#endif
#ifdef MAGIC1
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#endif

bool isPrime(ll a)
{
	ll i;
	for (i = 2; i*i <= a; i++)
	{
		if (a%i == 0)
		{
			return 0;
		}
	}
	return (a != 1);
}

bool isPalindrom(const string &s, int l, int r)
{
	for (int i = 0; i < (r - l + 1) / 2; i++)
	{
		if (s[l + i] != s[r - i])
		{
			return 0;
		}
	}
	return 1;
}

template <class type1> type1 gcd(type1 a, type1 b)
{
	type1 t;
	while (b)
	{
		t = b;
		b = a%b;
		a = t;
	}
	return a;
}

ll positiveMod(ll v, ll md)
{
	v = v%md;
	if (v < 0)
	{
		v += md;
	}
	return v;
}

//-----------------------------------------------------end--------------------------------------//

vector <ll> res;

set <pll> s1, s2;

vector <pair<pll, ll > > t1, t2, tt;
vector <pll> dat;

int main()
{
	fast;

	ll n, m, i, j, a, b;

	cin >> n;
	dat.push_back({ 0, 0 });
	for (i = 1; i <= n; i++)
	{
		cin >> a >> b;

		if (a < b)
		{
			t1.push_back({ { a, b }, i });
		}
		else
		{
			t2.push_back({ { a, b }, i });
		}
		dat.push_back({ a, b });
	}

	if (t1.size()>t2.size())
	{
		tt = t1;
	}
	else
	{
		tt = t2;
	}

	sort(tt.begin(), tt.end());
	reverse(tt.begin(), tt.end());

	for (auto& it : tt)
	{
		res.push_back(it.second);
	}

	for (j = 0; j < 30; j++)
	{
		for (i = 0; i < res.size() - 1; i++)
		{
			if (dat[res[0]].first < dat[res[0]].second)
			{
				if (dat[res[i]].second<dat[res[i + 1]].first)
				{
					swap(res[i], res[i + 1]);
				}
			}
			else
			{
				if (dat[res[i]].second>dat[res[i + 1]].first)
				{
					swap(res[i], res[i + 1]);
				}
			}
		}
	}

	cout << res.size() << "\n";
	for (auto it : res)
	{
		cout << it << " ";
	}

	return 0;
}


#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <math.h>
#include <string>
#include <time.h>
#include <random>
#include <memory.h>
#include <bitset>
using namespace std;

#define FILE0
#define MAGIC0
mt19937 rnd(time(0)); //rnd()

#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mii map<int, int>
#define mll map<ll, ll>
#define msl map<string, ll>
#define mls map<ll, string>
#define MOD (1000000007ll)
#define MOD2 (1000000009ll)
#define BIGMOD (1000000000000000007ll)
#define RMOD int(5e8 + rnd() % (int) 5e8)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#ifdef FILE1
ifstream in("input.txt");
ofstream out("output.txt");
#endif
#ifdef MAGIC1
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#endif

bool isPrime(ll a)
{
	ll i;
	for (i = 2; i*i <= a; i++)
	{
		if (a%i == 0)
		{
			return 0;
		}
	}
	return (a != 1);
}

bool isPalindrom(const string &s, int l, int r)
{
	for (int i = 0; i < (r - l + 1) / 2; i++)
	{
		if (s[l + i] != s[r - i])
		{
			return 0;
		}
	}
	return 1;
}

template <class type1> type1 gcd(type1 a, type1 b)
{
	type1 t;
	while (b)
	{
		t = b;
		b = a%b;
		a = t;
	}
	return a;
}

ll positiveMod(ll v, ll md)
{
	v = v%md;
	if (v < 0)
	{
		v += md;
	}
	return v;
}

//-----------------------------------------------------end--------------------------------------//

vector <ll> res;

set <pll> s1, s2;

vector <pair<pll, ll > > t1, t2, tt;
vector <pll> dat;

int main()
{
	fast;

	ll n, m, i, j, a, b;

	cin >> n;
	dat.push_back({ 0, 0 });
	for (i = 1; i <= n; i++)
	{
		cin >> a >> b;

		if (a < b)
		{
			t1.push_back({ { a, b }, i });
		}
		else
		{
			t2.push_back({ { a, b }, i });
		}
		dat.push_back({ a, b });
	}

	if (t1.size()>t2.size())
	{
		tt = t1;
	}
	else
	{
		tt = t2;
	}

	sort(tt.begin(), tt.end());
	reverse(tt.begin(), tt.end());

	for (auto& it : tt)
	{
		res.push_back(it.second);
	}

	for (i = 0; i < res.size() - 1; i++)
	{
		if (dat[res[0]].first < dat[res[0]].second)
		{
			if (dat[res[i]].second<dat[res[i+1]].first)
			{
				swap(res[i], res[i + 1]);
			}
		}
		else
		{
			if (dat[res[i]].second>dat[res[i + 1]].first)
			{
				swap(res[i], res[i + 1]);
			}
		}
	}

	cout << res.size() << "\n";
	for (auto it : res)
	{
		cout << it << " ";
	}

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<iostream>
#include<fstream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<climits>
#include<set>
#include<map>
#include<cmath>
#include<iomanip>
#include<iterator>
#include<queue>
#include<stack>
#include<cctype>
#include<deque>
//by Skeef79

typedef long long ll;
#define pb push_back
#define endline '\n'
#define forn(i,n) for(int i = 0;i<n;i++)

using namespace std;
//НЕ ИСПОЛЬЗУЙ endl, есть свой endline!!
//Иногда нужно не просто придумывать решение, а метматически расписать систему уравнений
//не скачи между задачами - проеб времени

void Out(vector<ll> & a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
}

void Input(vector<ll> & a)
{
	for (int i = 0; i < a.size(); i++)
		cin >> a[i];
}

struct elem
{
	int first, second;
	int ind;
};

bool comp1(elem a, elem b)
{
	return a.second > b.second;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;
	vector<elem> a, b;
	for (int i = 1; i <= n; i++)
	{
		int x, y;
		cin >> x >> y;
		if (x < y)
		{
			elem t;
			t.first = x;
			t.second = y;
			t.ind = i;
			a.pb(t);
		}
		else
		{
			elem t;
			t.first = x;
			t.second = y;
			t.ind = i;
			b.pb(t);
		}

	}

	if (a.size() > b.size())
	{
		cout << a.size() << endline;
		sort(a.begin(), a.end(), comp1);
		for (auto to : a)
			cout << to.ind << ' ';

	}
	else
	{
		cout << b.size() << endline;
		sort(b.begin(), b.end(), comp1);
		reverse(b.begin(), b.end());

		for (auto to : b)
			cout << to.ind << ' ';

	}

}


#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<map>
//#include<regex>
#include<cstdio>
#define up(i,a,b)  for(int i=a;i<b;i++)
#define dw(i,a,b)  for(int i=a;i>b;i--)
#define upd(i,a,b) for(int i=a;i<=b;i++)
#define dwd(i,a,b) for(int i=a;i>=b;i--)
//#define local
typedef long long ll;
const double esp = 1e-6;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int inf = 1e9;
using namespace std;
int read()
{
	char ch = getchar(); int x = 0, f = 1;
	while (ch<'0' || ch>'9') { if (ch == '-')f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
typedef pair<int, int> pir;
const int N = 3e5 + 10;
struct node { int id, fi, se; bool operator<(const node&a)const { return fi < a.fi; } };
set<node >sup;
set<node >sdn;
int n;
int main()
{
	n = read();
	int x, y;
	up(i, 0, n)
	{
		x = read(); y = read();
		if (x < y)
			sup.insert(node{ i,x,y });
		else sdn.insert(node{ i,x,y });
	}
	if (sup.size() > sdn.size())
	{
		cout << sup.size()<<endl;
		while (!sup.empty())
		{
			cout << (--sup.end())->id +1<< " ";
			sup.erase(--sup.end());
		}
	}
	else
	{
		cout << sdn.size() << endl;
		while (!sdn.empty())
		{
			cout << sdn.begin()->id +1<< " ";
			sdn.erase(sdn.begin());
		}
	}
	return 0;
}


#include <algorithm>
#include <functional>
#include <cmath>
#include <limits>
#include <cfloat>
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef int64_t I64;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef tuple<int, int, int> tri;

#define fr(i,a,b) for (int i = a; i <= b; i++)
#define fr2(i,a,b) for (int i = a; i < b; i++)

bool comp(const tri& a, const tri& b) {
	return get<0>(a) < get<0>(b);
}

bool revcomp(const tri& a, const tri& b) {
	return get<1>(a) < get<1>(b);
}

int main() {
	ios_base::sync_with_stdio(false);

	int n;
	cin >> n;

	vector<tri> incv, decv;
	fr2(i, 0, n) {
		int a, b;
		cin >> a >> b;
		if (a < b) incv.push_back({ a,b,i });
		else decv.push_back({ a,b,i });
	}

	sort(incv.rbegin(), incv.rend(), comp);
	sort(decv.begin(), decv.end(), revcomp);

	if (incv.size() > decv.size()) {
		cout << incv.size() << "\n";
		for (tri &t : incv) {
			cout << (get<2>(t) + 1) << " ";
		}
	} else {
		cout << decv.size() << "\n";
		for (tri &t : decv) {
			cout << (get<2>(t) + 1) << " ";
		}
	}

	return 0;
}


#include <algorithm>
#include <functional>
#include <cmath>
#include <limits>
#include <cfloat>
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef int64_t I64;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef tuple<int, int, int> tri;

#define fr(i,a,b) for (int i = a; i <= b; i++)
#define fr2(i,a,b) for (int i = a; i < b; i++)

bool comp(const tri& a, const tri& b) {
	return get<0>(a) < get<0>(b);
}

bool revcomp(const tri& a, const tri& b) {
	return get<1>(a) < get<1>(b);
}

int main() {
	ios_base::sync_with_stdio(false);

	int n;
	cin >> n;

	vector<tri> incv, decv;
	fr2(i, 0, n) {
		int a, b;
		cin >> a >> b;
		if (a < b) incv.push_back({ a,b,i });
		else decv.push_back({ a,b,i });
	}

	sort(incv.begin(), incv.end(), comp);
	sort(decv.begin(), decv.end(), revcomp);

	if (incv.size() > decv.size()) {
		cout << incv.size() << "\n";
		for (tri &t : incv) {
			cout << (get<2>(t) + 1) << " ";
		}
	} else {
		cout << decv.size() << "\n";
		for (tri &t : decv) {
			cout << (get<2>(t) + 1) << " ";
		}
	}

	return 0;
}


#include <algorithm>
#include <functional>
#include <cmath>
#include <limits>
#include <cfloat>
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef int64_t I64;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef tuple<int, int, int> tri;

#define fr(i,a,b) for (int i = a; i <= b; i++)
#define fr2(i,a,b) for (int i = a; i < b; i++)

bool revcomp(const tri& a, const tri& b) {
	return get<1>(a) < get<1>(b);
}

int main() {
	ios_base::sync_with_stdio(false);

	int n;
	cin >> n;

	vector<tri> incv, decv;
	fr2(i, 0, n) {
		int a, b;
		cin >> a >> b;
		if (a < b) incv.push_back({ a,b,i });
		else decv.push_back({ a,b,i });
	}

	sort(incv.begin(), incv.end());
	sort(decv.begin(), decv.end(), revcomp);

	if (incv.size() > decv.size()) {
		cout << incv.size() << "\n";
		for (tri &t : incv) {
			cout << (get<2>(t) + 1) << " ";
		}
	} else {
		cout << decv.size() << "\n";
		for (tri &t : decv) {
			cout << (get<2>(t) + 1) << " ";
		}
	}

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <time.h>
//#include <math.h>
#include <cmath>
#include <fstream>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <stdlib.h>
#include <iomanip>
#include <cstdio>
#include <cassert>
#include <bitset>

using namespace std;

#define flu fflush(stdout)
#define gg return 0
#define mp make_pair

long long mod = /*27449*//*998244353*/ 1e9 + 7 /*1e9 + 9*/;
long long inf = 1e9;
double eps = 1e-8;
double pi = acos(-1);
ifstream in("input.txt");
ofstream out("output.txt");

bool cmp(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b)
{
	if (a.first.first != b.first.first) return a.first.first > b.first.first;
	else return a.first.second < b.first.second;
}
int main()
{
	int n;
	cin >> n;
	vector<pair<pair<int, int>, int>> a, b;
	pair<pair<int, int>, int> maxa = {{-1, -1}, -1};
	pair<pair<int, int>, int> maxb = {{-1, -1}, -1};
	for (int i = 0; i < n; i++)
	{
		int x, y;
		cin >> x >> y;
		if (x < y)
		{
			if (maxa.first.second < y)
			{
				if (maxa.second != -1) a.push_back(maxa);
				maxa = { { x, y }, i + 1 };
			}
			else
			{
				a.push_back({ {x, y}, i + 1 });
			}
		}
		else
		{
			if (maxb.first.second < x)
			{
				if (maxb.second != -1) b.push_back(maxb);
				maxb = { { y, x }, i + 1 };
			}
			else
			{
				b.push_back({ { y, x }, i + 1 });
			}
		}
	}
	sort(a.begin(), a.end(), cmp);
	sort(b.begin(), b.end(), cmp);
	vector<pair<pair<int, int>, int>> a1;
	vector<pair<pair<int, int>, int>> b1;
	if (maxa.second != -1)
	{
		a1.push_back(maxa);
		for (int i = 0; i < a.size(); i++)
		{
			if (a[i].first.first < a1.back().first.second)
			{
				a1.push_back(a[i]);
			}
		}
	}
	if (maxb.second != -1)
	{
		b1.push_back(maxb);
		for (int i = 0; i < b.size(); i++)
		{
			if (b[i].first.first < b1.back().first.second)
			{
				b1.push_back(b[i]);
			}
		}
	}
	if (b1.size() < a1.size())
	{
		cout << a1.size() << endl;
		for (int i = 0; i < a1.size(); i++)
		{
			cout << a1[i].second << " ";
		}
	}
	else
	{
		cout << b1.size() << endl;
		for (int i = 0; i < b1.size(); i++)
		{
			cout << b1[i].second << " ";
		}
	}
	gg;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <time.h>
//#include <math.h>
#include <cmath>
#include <fstream>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <stdlib.h>
#include <iomanip>
#include <cstdio>
#include <cassert>
#include <bitset>

using namespace std;

#define flu fflush(stdout)
#define gg return 0
#define mp make_pair

long long mod = /*27449*//*998244353*/ 1e9 + 7 /*1e9 + 9*/;
long long inf = 1e9;
double eps = 1e-8;
double pi = acos(-1);
ifstream in("input.txt");
ofstream out("output.txt");

bool cmp(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b)
{
	if (a.first.first != b.first.first) return a.first.first > b.first.first;
	else return a.first.second < b.first.second;
}

bool cmp1(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b)
{
	if (a.first.second != b.first.second) return a.first.second > b.first.second;
	else return a.first.first < b.first.first;
}

int main()
{
	int n;
	cin >> n;
	vector<pair<pair<int, int>, int>> a, b;
	for (int i = 0; i < n; i++)
	{
		int x, y;
		cin >> x >> y;
		if (x < y)
		{
			a.push_back({ {x, y}, i + 1 });
		}
		else
		{
			b.push_back({ {-x, -y}, i + 1 });
		}
	}
	sort(a.rbegin(), a.rend());
	sort(b.rbegin(), b.rend());
	if (b.size() < a.size())
	{
		cout << a.size() << endl;
		for (int i = 0; i < a.size(); i++)
		{
			cout << a[i].second << " ";
		}
	}
	else
	{
		cout << b.size() << endl;
		for (int i = 0; i < b.size(); i++)
		{
			cout << b[i].second << " ";
		}
	}
	gg;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <time.h>
//#include <math.h>
#include <cmath>
#include <fstream>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <stdlib.h>
#include <iomanip>
#include <cstdio>
#include <cassert>
#include <bitset>

using namespace std;

#define flu fflush(stdout)
#define gg return 0
#define mp make_pair

long long mod = /*27449*//*998244353*/ 1e9 + 7 /*1e9 + 9*/;
long long inf = 1e9;
double eps = 1e-8;
double pi = acos(-1);
ifstream in("input.txt");
ofstream out("output.txt");

bool cmp(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b)
{
	if (a.first.first != b.first.first) return a.first.first > b.first.first;
	else return a.first.second < b.first.second;
}
int main()
{
	int n;
	cin >> n;
	vector<pair<pair<int, int>, int>> a, b;
	pair<pair<int, int>, int> maxa = {{-1, -1}, -1};
	pair<pair<int, int>, int> maxb = {{-1, -1}, -1};
	for (int i = 0; i < n; i++)
	{
		int x, y;
		cin >> x >> y;
		if (x < y)
		{
			if (maxa.first.second < y)
			{
				if (maxa.second != -1) a.push_back(maxa);
				maxa = { { x, y }, i + 1 };
			}
			else
			{
				a.push_back({ {x, y}, i + 1 });
			}
		}
		else
		{
			if (maxb.first.first < x)
			{
				if (maxb.second != -1) b.push_back(maxb);
				maxb = { { x, y }, i + 1 };
			}
			else
			{
				b.push_back({ { x, y }, i + 1 });
			}
		}
	}
	sort(a.begin(), a.end(), cmp);
	sort(b.begin(), b.end());
	vector<pair<pair<int, int>, int>> a1;
	vector<pair<pair<int, int>, int>> b1;
	if (maxa.second != -1)
	{
		a1.push_back(maxa);
		for (int i = 0; i < a.size(); i++)
		{
			if (a[i].first.first < a1.back().first.second)
			{
				a1.push_back(a[i]);
			}
		}
	}
	if (maxb.second != -1)
	{
		b1.push_back(maxb);
		for (int i = 0; i < b.size(); i++)
		{
			if (b[i].first.first > b1.back().first.second)
			{
				b1.push_back(b[i]);
			}
		}
	}
	if (b1.size() < a1.size())
	{
		cout << a1.size() << endl;
		for (int i = 0; i < a1.size(); i++)
		{
			cout << a1[i].second << " ";
		}
	}
	else
	{
		cout << b1.size() << endl;
		for (int i = 0; i < b1.size(); i++)
		{
			cout << b1[i].second << " ";
		}
	}
	gg;
}