#include <bits/stdc++.h>
using namespace std;
inline long long &height(pair<long long, int> &p) { return p.first; }
inline int &color(pair<long long, int> &p) { return p.second; }
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  map<int, vector<pair<long long, int> > > table;
  vector<pair<pair<long long, int>, pair<long long, int> > > sum(
      n + 2, pair<pair<long long, int>, pair<long long, int> >(
                 pair<long long, int>(-1, -1), pair<long long, int>(-1, -1)));
  for (int i = 0; i < n; ++i) {
    int c, s;
    cin >> c >> s;
    table[c].push_back(pair<long long, int>(s, i));
  }
  for (map<int, vector<pair<long long, int> > >::iterator it = table.begin();
       it != table.end(); ++it) {
    sort(it->second.rbegin(), it->second.rend());
    for (int i = 1; i < it->second.size(); ++i) {
      it->second[i].first += it->second[i - 1].first;
    }
    for (int i = 0; i < it->second.size(); ++i) {
      if (sum[i].first < it->second[i]) {
        sum[i].second = sum[i].first;
        sum[i].first = pair<long long, int>(it->second[i].first, it->first);
      } else if (sum[i].second < it->second[i]) {
        sum[i].second = pair<long long, int>(it->second[i].first, it->first);
      }
    }
  }
  long long answer = 0;
  int first = -1, second = -1;
  for (int i = 0; color(sum[i].first) > 0; ++i) {
    long long c1h = height(sum[i].first), c2h = height(sum[i].second);
    int c1c = color(sum[i].first), c2c = color(sum[i].second);
    long long n1h = height(sum[i + 1].first), n2h = height(sum[i + 1].second);
    int n1c = color(sum[i + 1].first), n2c = color(sum[i + 1].second);
    if (c1c > 0 && c2c > 0 && c1c != c2c) {
      if (answer < c1h + c2h) {
        answer = c1h + c2h;
        first = c1c;
        second = c2c;
      }
    }
    if (c1c > 0 && n1c > 0 && c1c != n1c) {
      if (answer < c1h + n1h) {
        answer = c1h + n1h;
        first = n1c;
        second = c1c;
      }
    }
    if (c1c > 0 && n2c > 0 && c1c != n2c) {
      if (answer < c1h + n2h) {
        answer = c1h + n2h;
        first = n2h;
        second = c1h;
      }
    }
    if (c2c > 0 && n1c > 0 && c2c != n1c) {
      if (answer < c2h + n1h) {
        answer = c2h + n1h;
        first = n1c;
        second = c2c;
      }
    }
    if (c2c > 0 && n2c > 0 && c2c != n2c) {
      if (answer < c2h + n2h) {
        answer = c2h + n2h;
        first = n2c;
        second = c2c;
      }
    }
  }
  if (first < 0 || second < 0) {
    cout << 0 << endl;
    cout << 0 << endl;
  } else {
    vector<pair<long long, int> > &a = table[first];
    vector<pair<long long, int> > &b = table[second];
    if (a.size() == 0 || b.size() == 0) {
      cout << 0 << endl;
      cout << 0 << endl;
    } else {
      cout << answer << endl;
      int an = a.size(), bn = b.size();
      an = min(bn + 1, an);
      cout << an + bn << endl;
      for (int i = 0; i < bn; ++i) {
        cout << a[i].second + 1 << " " << b[i].second + 1;
        if (i != bn - 1) {
          cout << " ";
        }
      }
      if (an != bn) {
        cout << " " << a[bn].second + 1;
      }
      cout << endl;
    }
  }
  return 0;
}
