#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 100;
map<int, int> color_m;
vector<pair<int, int> > cols[MAX];
long long bestsum[MAX];
int bestindex[MAX];
bool sizesort(const vector<pair<int, int> > &a,
              const vector<pair<int, int> > &b) {
  return (a.size() > b.size());
}
bool revs(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.first > b.first);
}
int main() {
  int n;
  cin >> n;
  int CCC = 0;
  for (int i = 0; i < n; ++i) {
    int color, he1ight;
    cin >> color >> he1ight;
    if (color_m.find(color) != color_m.end())
      color = color_m[color];
    else {
      color_m[color] = CCC;
      color = CCC;
      CCC++;
    }
    cols[color].push_back(make_pair(he1ight, i));
  }
  sort(cols, cols + CCC, sizesort);
  long long ans = 0;
  int a = 0, b = 0;
  for (int i = 0; i < CCC; ++i) {
    sort(cols[i].begin(), cols[i].end(), revs);
    long long sum = 0;
    for (int j = 0; j < cols[i].size(); ++j) sum += cols[i][j].first;
    int sz = cols[i].size();
    if (bestsum[sz] + sum > ans and bestsum[sz] != 0 and sum != 0) {
      ans = bestsum[sz] + sum;
      a = bestindex[sz];
      b = i;
    }
    if (bestsum[sz + 1] + sum > ans and bestsum[sz + 1] != 0 and sum != 0) {
      ans = bestsum[sz + 1] + sum;
      a = bestindex[sz + 1];
      b = i;
    }
    sum = 0;
    for (int j = 0; j < cols[i].size(); ++j) {
      sum += cols[i][j].first;
      if (sum > bestsum[j + 1]) {
        bestsum[j + 1] = sum;
        bestindex[j + 1] = i;
      }
    }
  }
  int SIZE = cols[b].size() * 2;
  if (cols[a].size() != cols[b].size()) SIZE++;
  cout << fixed << ans << endl;
  cout << SIZE << endl;
  int uplimit = cols[b].size();
  if (cols[a].size() != uplimit) uplimit++;
  for (int i = 0; i < uplimit; ++i) {
    cout << cols[a][i].second + 1 << " ";
    if (i < cols[b].size()) cout << cols[b][i].second + 1 << " ";
  }
  cout << endl;
  return 0;
}
