#include <bits/stdc++.h>
using namespace std;
struct block {
  int nom;
  int siz;
  int col;
};
vector<int> colors;
vector<block> blocks[100005];
vector<block> v[100005];
map<int, int> color_map;
int col[100005];
int siz[100005];
long long siz_sum[100005];
bool comp(block a, block b) { return a.siz > b.siz; }
int main() {
  int n;
  scanf("%d", &n);
  int i;
  for (i = 0; i < n; i++) {
    int c, s;
    scanf("%d%d", &c, &s);
    col[i] = c;
    siz[i] = s;
    colors.push_back(c);
  }
  colors.resize(unique(colors.begin(), colors.end()) - colors.begin());
  int col_count = colors.size();
  for (i = 0; i < col_count; i++) {
    color_map[colors[i]] = i;
  }
  block tmp;
  for (i = 0; i < n; i++) {
    tmp.nom = i + 1;
    tmp.siz = siz[i];
    tmp.col = color_map[col[i]];
    blocks[color_map[col[i]]].push_back(tmp);
  }
  for (i = 0; i < col_count; i++) {
    tmp.nom = 0;
    tmp.siz = 0;
    tmp.col = i;
    blocks[i].push_back(tmp);
    sort(blocks[i].begin(), blocks[i].end(), comp);
    int j;
    for (j = 0; j < blocks[i].size(); j++) {
      v[j + 1].push_back(blocks[i][j]);
    }
  }
  long long best = 0;
  int col1 = -1, col2 = -1;
  for (i = 1; i <= n; i++) {
    int j;
    int max_col = -1;
    long long max_sum = -1;
    int max_col2 = -1;
    long long max_sum2 = -1;
    for (j = 0; j < v[i].size(); j++) {
      tmp = v[i][j];
      siz_sum[tmp.col] += tmp.siz;
      if (siz_sum[tmp.col] >= max_sum) {
        max_sum2 = max_sum;
        max_col2 = max_col;
        max_sum = siz_sum[tmp.col];
        max_col = tmp.col;
      } else if (siz_sum[tmp.col] > max_sum2) {
        max_sum2 = siz_sum[tmp.col];
        max_col2 = tmp.col;
      }
    }
    if (max_col2 == -1) continue;
    long long s = max_sum + max_sum2;
    if (s > best) {
      best = s;
      col1 = max_col;
      col2 = max_col2;
    }
  }
  if (blocks[col1].size() < blocks[col2].size()) {
    swap(col1, col2);
  }
  vector<int> ans;
  int i1 = 0, i2 = 0;
  for (;;) {
    if (i1 == i2) {
      if (blocks[col1][i1].siz == 0) break;
      ans.push_back(blocks[col1][i1].nom);
      i1++;
    } else {
      if (blocks[col2][i2].siz == 0) break;
      ans.push_back(blocks[col2][i2].nom);
      i2++;
    }
  }
  printf("%I64d\n", best);
  printf("%d\n", ans.size());
  for (i = 0; i < ans.size(); i++) {
    if (i > 0) printf(" ");
    printf("%d", ans[i]);
  }
  printf("\n");
  return 0;
}
