#include <bits/stdc++.h>
using namespace std;
struct cube {
  long long h, c, i;
} np;
long long cubes, cons, val, totes, i1, i2, iv, kit = 1, nnext1 = 1, nnext2 = 2;
long long maxs[100005], max2s[100005], smax[100005], sm2[100005], res[100005];
vector<cube> clist(100005);
bool hp(cube i, cube j) {
  if (i.c != j.c) return i.c < j.c;
  return i.h > j.h;
}
int main() {
  cin >> cubes;
  for (int i = 1; i <= cubes; i++) {
    cin >> clist[i].c >> clist[i].h;
    clist[i].i = i;
  }
  sort(clist.begin() + 1, clist.begin() + 1 + cubes, hp);
  for (int i = 1; i <= cubes; i++) {
    if (clist[i].c != clist[i - 1].c) {
      cons = 0;
      val = 0;
    }
    cons++;
    val += clist[i].h;
    if (maxs[cons] < val) {
      max2s[cons] = maxs[cons];
      sm2[cons] = smax[cons];
      smax[cons] = clist[i].c;
      maxs[cons] = val;
    } else {
      if (max2s[cons] < val) {
        max2s[cons] = val;
        sm2[cons] = clist[i].c;
      }
    }
  }
  for (int i = 1; i <= cubes; i++) {
    if (maxs[i] + maxs[i - 1] > totes && smax[i - 1] != smax[i] &&
        maxs[i - 1] && maxs[i]) {
      kit = 1;
      iv = i;
      totes = maxs[i] + maxs[i - 1];
      i1 = smax[i];
      i2 = smax[i - 1];
    }
    if (maxs[i] + max2s[i - 1] > totes && smax[i] != sm2[i - 1] && maxs[i] &&
        max2s[i - 1]) {
      kit = 1;
      iv = i;
      totes = maxs[i] + max2s[i - 1];
      i1 = smax[i];
      i2 = sm2[i - 1];
    }
    if (maxs[i - 1] + max2s[i] > totes && smax[i - 1] != sm2[i] &&
        maxs[i - 1] && max2s[i]) {
      kit = 1;
      iv = i;
      totes = maxs[i - 1] + max2s[i];
      i2 = smax[i - 1];
      i1 = sm2[i];
    }
    if (maxs[i] + max2s[i] > totes && smax[i] != sm2[i] && maxs[i] &&
        max2s[i]) {
      kit = 0;
      iv = i;
      totes = maxs[i] + max2s[i];
      i2 = smax[i];
      i1 = sm2[i];
    }
  }
  cout << totes << "\n" << iv + iv - kit << "\n";
  for (int i = 1; i <= cubes; i++) {
    if (clist[i].c == i1) {
      for (int j = i; j < i + iv; j++) {
        res[nnext1] = clist[j].i;
        nnext1 += 2;
      }
      break;
    }
  }
  for (int i = 1; i <= cubes; i++) {
    if (clist[i].c == i2) {
      for (int j = i; j < (i + iv) - kit; j++) {
        res[nnext2] = clist[j].i;
        nnext2 += 2;
      }
      break;
    }
  }
  for (int i = 1; res[i] != 0; i++) {
    cout << res[i] << " ";
  }
  return 0;
}
