#include <bits/stdc++.h>
using namespace std;
map<int, int> g;
vector<vector<pair<long long, int> > > vec;
const int MAXN = 100010;
pair<long long, int> msum[MAXN][2];
bool cmp2(pair<long long, int> a, pair<long long, int> b) {
  return b.first < a.first;
}
int main() {
  int n, c, s;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d %d", &c, &s);
    if (g.find(c) == g.end()) {
      g[c] = vec.size();
      vec.push_back(vector<pair<long long, int> >());
    }
    int id = g[c];
    vec[id].push_back(make_pair(s, i + 1));
  }
  int len = 0;
  for (int i = 0; i < vec.size(); ++i) {
    sort(vec[i].begin(), vec[i].end(), cmp2);
    len = max(len, (int)vec[i].size());
    for (int j = 0; j < vec[i].size(); ++j) {
      if (j != 0) vec[i][j].first += vec[i][j - 1].first;
      if (vec[i][j].first >= msum[j][0].first) {
        msum[j][1] = msum[j][0];
        msum[j][0].first = vec[i][j].first;
        msum[j][0].second = i;
      } else if (vec[i][j].first > msum[j][1].first) {
        msum[j][1].first = vec[i][j].first;
        msum[j][1].second = i;
      }
    }
  }
  long long ans = 0;
  int fc = -1, fl, sc, sl;
  for (int i = 0; i < len; ++i) {
    if (msum[i][0].first == 0) continue;
    if (msum[i][1].first != 0) {
      if (msum[i][0].first + msum[i][1].first > ans) {
        ans = msum[i][0].first + msum[i][1].first;
        fc = msum[i][0].second, fl = i + 1;
        sc = msum[i][1].second, sl = i + 1;
      }
    }
    if (i + 1 == len || msum[i + 1][0].first == 0) continue;
    if (msum[i + 1][0].second != msum[i][0].second) {
      if (msum[i][0].first + msum[i + 1][0].first > ans) {
        ans = msum[i][0].first + msum[i + 1][0].first;
        fc = msum[i][0].second, fl = i + 1;
        sc = msum[i + 1][0].second, sl = i + 2;
      }
    } else {
      if (msum[i][1].first != 0 &&
          msum[i][1].first + msum[i + 1][0].first > ans) {
        ans = msum[i][1].first + msum[i + 1][0].first;
        fc = msum[i][1].second, fl = i + 1;
        sc = msum[i + 1][0].second, sl = i + 2;
      }
      if (msum[i + 1][1].first != 0 &&
          msum[i][0].first + msum[i + 1][1].first > ans) {
        ans = msum[i][0].first + msum[i + 1][1].first;
        fc = msum[i][0].second, fl = i + 1;
        sc = msum[i + 1][1].second, sl = i + 2;
      }
    }
  }
  cout << ans << endl;
  if (fc != -1) {
    cout << fl + sl << endl;
    for (int i = 0; i < fl; ++i) {
      if (i) putchar(' ');
      printf("%d %d", vec[sc][i].second, vec[fc][i].second);
    }
    if (sl != fl) {
      printf(" %d", vec[sc][fl].second);
    }
    puts("");
  } else {
    cout << 0 << endl;
  }
  return 0;
}
