#include <bits/stdc++.h>
using namespace std;
struct Cube {
  int color, height, idx;
};
struct CubeSet {
  int len;
  int pos;
};
Cube cubes[100010];
CubeSet cs[100010];
long long maxHeight[100010];
int maxIdx[100010];
bool cubeSort(Cube, Cube);
bool colorSort(CubeSet, CubeSet);
int main() {
  ios_base::sync_with_stdio(false);
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> cubes[i].color;
    cin >> cubes[i].height;
    cubes[i].idx = (i + 1);
  }
  sort(cubes, cubes + N, cubeSort);
  int colorLen = 0;
  int j = 0;
  int minH = 100010;
  for (int i = 0; i < N; i = j) {
    cs[colorLen].pos = i;
    for (j = i; j < N && cubes[j].color == cubes[i].color; j++)
      cs[colorLen].len++;
    minH = min(minH, cs[colorLen].len);
    colorLen++;
  }
  sort(cs, cs + colorLen, colorSort);
  memset(maxHeight, 0, sizeof(maxHeight));
  memset(maxIdx, 0, sizeof(maxIdx));
  long long ans = 0;
  int bestA_idx, bestA_len, bestB_idx, bestB_len;
  for (int i = 0; i < colorLen; i++) {
    long long curH = 0;
    for (int j = 0; j < minH - 1; j++) curH += cubes[cs[i].pos + j].height;
    for (int j = minH - 1; j < cs[i].len; j++) {
      curH += cubes[cs[i].pos + j].height;
      for (int k = j; k <= j + 1; k++) {
        if (maxHeight[k] != 0 && (curH + maxHeight[k]) > ans) {
          ans = curH + maxHeight[k];
          bestA_idx = i, bestB_idx = maxIdx[k];
          bestA_len = j + 1, bestB_len = k;
        }
      }
    }
    if (curH > maxHeight[cs[i].len]) {
      maxHeight[cs[i].len] = curH;
      maxIdx[cs[i].len] = i;
    }
  }
  cout << ans << endl;
  cout << (bestA_len + bestB_len) << endl;
  for (int i = 0; i < bestA_len; i++) {
    cout << cubes[cs[bestA_idx].pos + i].idx;
    if (i < bestB_len) cout << " " << cubes[cs[bestB_idx].pos + i].idx << " ";
  }
  cout << endl;
}
bool cubeSort(Cube a, Cube b) {
  if (a.color != b.color) return a.color < b.color;
  return a.height > b.height;
}
bool colorSort(CubeSet a, CubeSet b) { return a.len < b.len; }
