#include <bits/stdc++.h>
using namespace std;
set<pair<long long, int> > cols[1000000];
map<int, vector<pair<long long, int> > > inpu;
long long res = 0;
int num, cora, corb, ta, tb;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    int c, v;
    scanf("%d%d", &c, &v);
    inpu[c].push_back(make_pair(v, i));
  }
  for (typeof(inpu.begin()) it = inpu.begin(); it != inpu.end(); ++it) {
    sort(it->second.begin(), it->second.end(),
         greater<pair<long long, int> >());
    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)
      cols[i].insert(make_pair(-it->second[i].first, it->first));
  }
  for (int i = 0; i < 1000000; ++i) {
    if (cols[i].empty()) break;
    pair<long long, int> a = *cols[i].begin();
    if (cols[i].size() > 1) {
      pair<long long, int> b = *(++cols[i].begin());
      long long aux = -(a.first + b.first);
      if (aux > res)
        res = aux, num = (i + 1) * 2, cora = a.second, corb = b.second,
        ta = i + 1, tb = i + 1;
    }
    if (i) {
      pair<long long, int> b = *cols[i - 1].begin();
      bool d = 1;
      if (b.second == a.second) {
        if (cols[i - 1].size() < 2)
          d = 0;
        else
          b = *(++cols[i - 1].begin());
      }
      if (d) {
        long long aux = -(a.first + b.first);
        if (aux > res)
          res = aux, num = 2 * i + 1, cora = a.second, corb = b.second,
          ta = i + 1, tb = i;
      }
    }
  }
  cout << res << endl << num << endl;
  vector<pair<long long, int> >& a = inpu[cora];
  vector<pair<long long, int> >& b = inpu[corb];
  for (int i = 0; i < ta; ++i) {
    printf("%d ", a[i].second);
    if (i < tb) printf("%d ", b[i].second);
  }
  printf("\n");
  return 0;
}
