#include <bits/stdc++.h>
using namespace std;
int k = 1, n, x, y, k2, k1, p2, p1, i, j, mx;
vector<pair<int, int> > a[100005];
vector<long long> second[100005];
long long ans = 0, d[2][100005], p[2][100005];
map<int, int> m;
int main() {
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> x >> y;
    if (!m[x]) {
      m[x] = k;
      k++;
    }
    a[m[x]].push_back(make_pair(y, i));
  }
  for (i = 1; i < k; i++) {
    sort(a[i].begin(), a[i].end());
    reverse(a[i].begin(), a[i].end());
    second[i].push_back(a[i][0].first);
    for (j = 1; j < a[i].size(); j++)
      second[i].push_back(second[i][j - 1] + a[i][j].first);
    mx = max(mx, (int)a[i].size());
  }
  for (j = 1; j < k; j++)
    for (i = 0; i < a[j].size(); i++)
      if (d[0][i] < second[j][i]) {
        d[1][i] = d[0][i];
        p[1][i] = p[0][i];
        d[0][i] = second[j][i];
        p[0][i] = j;
      } else if (d[1][i] < second[j][i]) {
        d[1][i] = second[j][i];
        p[1][i] = j;
      }
  for (i = 0; i < mx; i++) {
    if (p[1][i] && d[0][i] + d[1][i] > ans) {
      ans = d[0][i] + d[1][i];
      p1 = p[0][i];
      p2 = p[1][i];
      k1 = i;
      k2 = i;
    }
    if (i < mx - 1 && p[0][i] && p[0][i + 1] && p[0][i] != p[0][i + 1] &&
        d[0][i] + d[0][i + 1] > ans) {
      ans = d[0][i] + d[0][i + 1];
      p1 = p[0][i];
      p2 = p[0][i + 1];
      k1 = i;
      k2 = i + 1;
    }
    if (i < mx - 1 && p[0][i] && p[1][i + 1] && p[0][i] != p[1][i + 1] &&
        d[0][i] + d[1][i + 1] > ans) {
      ans = d[0][i] + d[1][i + 1];
      p1 = p[0][i];
      p2 = p[1][i + 1];
      k1 = i;
      k2 = i + 1;
    }
    if (i < mx - 1 && p[1][i] && p[0][i + 1] && p[1][i] != p[0][i + 1] &&
        d[1][i] + d[0][i + 1] > ans) {
      ans = d[1][i] + d[0][i + 1];
      p1 = p[1][i];
      p2 = p[0][i + 1];
      k1 = i;
      k2 = i + 1;
    }
  }
  cout << ans << endl << k1 + k2 + 2 << endl;
  for (i = 0; i <= k1; i++)
    cout << a[p2][i].second << " " << a[p1][i].second << " ";
  if (k2 > k1) cout << a[p2][k2].second;
  return 0;
}
