#include <bits/stdc++.h>
using namespace std;
struct Cube {
  int col, siz, id;
  Cube() {}
  Cube(int _col, int _siz, int _id) {
    col = _col;
    siz = _siz;
    id = _id;
  }
  friend bool operator<(const Cube& a, const Cube& b) {
    if (a.col == b.col) return a.siz < b.siz;
    return a.col < b.col;
  }
};
struct C {
  int siz, id;
  C() {}
  C(int _siz, int _id) {
    siz = _siz;
    id = _id;
  }
};
int n;
vector<Cube> cube;
vector<C> c[100000];
vector<pair<int, int> > tmp;
int totc;
long long sum[100000];
long long geth(int p, int t, int nowt) {
  if (t == nowt) return sum[p];
  if (c[p].size() < nowt) return sum[p];
  return sum[p] - c[p][nowt - 1].siz;
}
long long ans;
int c0, c1, u0, u1;
void check(int p0, int t0, int p1, int t1) {
  long long h0, h1;
  int nowt = max(t0, t1);
  h0 = geth(p0, t0, nowt);
  h1 = geth(p1, t1, nowt);
  if (ans < h0 + h1) {
    ans = h0 + h1;
    c0 = p0;
    c1 = p1;
    u0 = t0;
    u1 = t1;
  }
}
int main() {
  while (scanf("%d", &n) != EOF) {
    cube.clear();
    for (int i = 0; i < n; i++) {
      int c, s;
      scanf("%d%d", &c, &s);
      cube.push_back(Cube(c, s, i));
    }
    sort(cube.begin(), cube.end());
    totc = 1;
    c[totc - 1].clear();
    c[totc - 1].push_back(C(cube[0].siz, cube[0].id));
    for (int i = 1; i < n; i++)
      if (cube[i].col == cube[i - 1].col)
        c[totc - 1].push_back(C(cube[i].siz, cube[i].id));
      else {
        c[totc].clear();
        c[totc++].push_back(C(cube[i].siz, cube[i].id));
      }
    int maxh = 0;
    tmp.clear();
    for (int i = 0; i < totc; i++) {
      maxh = max(maxh, (int)c[i].size());
      reverse(c[i].begin(), c[i].end());
      sum[i] = 0;
      tmp.push_back(make_pair(c[i].size(), i));
    }
    sort(tmp.begin(), tmp.end());
    int op = 0;
    int pmax0, pmax1;
    pmax0 = pmax1 = -1;
    ans = 0;
    for (int i = 1; i <= maxh; i++) {
      int max0, max1;
      max0 = max1 = -1;
      for (; tmp[op].first < i; op++)
        ;
      for (int jj = op; jj < tmp.size(); jj++) {
        int j = tmp[jj].second;
        sum[j] += c[j][i - 1].siz;
        if (max0 == -1 || sum[j] >= sum[max0]) {
          max1 = max0;
          max0 = j;
        } else if (max1 == -1 || sum[j] > sum[max1])
          max1 = j;
      }
      if (max0 != pmax0 && pmax0 != -1) check(max0, i, pmax0, i - 1);
      if (max0 != pmax1 && pmax1 != -1) check(max0, i, pmax1, i - 1);
      if (max1 != pmax0 && pmax0 != -1) check(max1, i, pmax0, i - 1);
      if (max1 != pmax1 && pmax1 != -1) check(max1, i, pmax1, i - 1);
      if (max1 != -1) check(max0, i, max1, i);
      pmax0 = max0;
      pmax1 = max1;
    }
    cout << ans << endl;
    printf("%d\n", u0 + u1);
    for (int i = 0; i < u0; i++) {
      printf("%d ", c[c0][i].id + 1);
      if (i < u1) printf("%d ", c[c1][i].id + 1);
    }
    printf("\n");
  }
  return 0;
}
