#include <bits/stdc++.h>
using namespace std;
int color[111111], colorCnt;
vector<int> id[111111];
vector<long long> height[111111];
long long maxHeight[111111][2];
int from[111111][2];
int n;
int c[111111], s[111111];
bool cmp(int x, int y) { return s[x] > s[y]; }
void update(long long h, int level, int id) {
  if (h > maxHeight[level][0]) {
    maxHeight[level][1] = maxHeight[level][0];
    from[level][1] = from[level][0];
    maxHeight[level][0] = h;
    from[level][0] = id;
  } else if (h > maxHeight[level][1]) {
    maxHeight[level][1] = h;
    from[level][1] = id;
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> c[i] >> s[i];
  }
  for (int i = 0; i < n; ++i) {
    color[i] = c[i];
  }
  sort(color, color + n);
  colorCnt = unique(color, color + n) - color;
  for (int i = 0; i < n; ++i) {
    c[i] = lower_bound(color, color + colorCnt, c[i]) - color;
  }
  for (int i = 0; i < n; ++i) {
    id[c[i]].push_back(i);
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < 2; ++j) {
      maxHeight[i][j] = 0LL;
      from[i][j] = -1;
    }
  }
  for (int c = 0; c < colorCnt; ++c) {
    sort(id[c].begin(), id[c].end(), cmp);
    height[c].resize(id[c].size() + 2, 0LL);
    height[c][0] = 0LL;
    for (int i = 0; i < id[c].size(); ++i) {
      height[c][i + 1] = height[c][i] + (long long)s[id[c][i]];
    }
    for (int i = 1; i <= id[c].size(); ++i) {
      update(height[c][i], i, c);
    }
  }
  long long res = 0LL;
  int c1, c2, h1, h2;
  for (int c = 0; c < colorCnt; ++c) {
    int curH = id[c].size();
    if (curH == 0) {
      continue;
    }
    for (int h = 0; h < 2; ++h) {
      for (int k = 0; k < 2; ++k) {
        if (from[curH + h][k] != -1 && from[curH + h][k] != c) {
          if (res < height[c][curH] + maxHeight[curH + h][k]) {
            res = height[c][curH] + maxHeight[curH + h][k];
            c1 = c;
            c2 = from[curH + h][k];
            h1 = curH;
            h2 = curH + h;
          }
        }
      }
    }
  }
  cout << res << endl;
  cout << h1 + h2 << endl;
  vector<int> ans;
  int p1 = 0, p2 = 0;
  for (int i = 0; i < h1 + h2; ++i) {
    cout << id[c2][p2] + 1;
    if (i < h1 + h2 - 1) cout << " ";
    p2 += 1;
    swap(c1, c2);
    swap(p1, p2);
  }
  cout << endl;
}
