#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
template <class T>
inline T sqr(T x) {
  return x * x;
}
const double eps = 1e-9;
const double pi = acos(-1.0);
const long long INF = (long long)1e18;
const int maxn = (int)1e5 + 10;
struct cube {
  long long h;
  int id;
  cube() : h(-INF), id(-1) {}
  cube(long long h, int id) : h(h), id(id) {}
};
bool cmp(cube a, cube b) { return a.h > b.h; }
cube ma1[maxn], ma2[maxn];
int main() {
  map<int, vector<cube> > d;
  int n, a, b;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &a, &b);
    d[a].push_back(cube(b, i + 1));
  }
  for (map<int, vector<cube> >::iterator it = d.begin(); it != d.end(); it++) {
    sort((it->second).begin(), (it->second).end(), cmp);
    long long h = 0;
    for (int i = 0; i < (int)(it->second).size(); i++) {
      h += it->second[i].h;
      if (ma1[i].h < h) {
        ma2[i] = ma1[i];
        ma1[i] = cube(h, it->first);
      } else if (ma2[i].h < h) {
        ma2[i] = cube(h, it->first);
      }
    }
  }
  long long best = 0;
  int num1 = -1, num2 = -1;
  int id1 = -1, id2 = -1;
  for (int i = 0; i < maxn; i++) {
    if (i && ma1[i].id != ma1[i - 1].id && best < ma1[i].h + ma1[i - 1].h) {
      best = ma1[i].h + ma1[i - 1].h;
      num1 = i + 1;
      num2 = i;
      id1 = ma1[i].id;
      id2 = ma1[i - 1].id;
    }
    for (int x = 0; x < 2; x++)
      for (int y = 0; y < 2; y++)
        if (i - x >= 0 && i - y >= 0 && ma1[i - x].id != ma2[i - y].id &&
            best < ma1[i - x].h + ma2[i - y].h) {
          best = ma1[i - x].h + ma2[i - y].h;
          num1 = i - x + 1;
          num2 = i - y + 1;
          id1 = ma1[i - x].id;
          id2 = ma2[i - y].id;
        }
  }
  cout << best << endl << num1 + num2 << endl;
  if (num1 < num2) {
    swap(num1, num2);
    swap(id1, id2);
  }
  int i = 0;
  int j = 0;
  int k = 0;
  while (i < num1 || j < num2) {
    if (k == 0) {
      printf("%d ", d[id1][i].id);
      i++;
    } else {
      printf("%d ", d[id2][j].id);
      j++;
    }
    k = 1 - k;
  }
  return 0;
}
