#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
const int INF = (int)1E9;
const long long INF64 = (long long)1E18;
const long double EPS = 1E-9;
const long double PI = 3.1415926535897932384626433832795;
const int MAXN = 100100;
map<int, vector<pair<int, int> > > m;
vector<pair<long long, int> > l[MAXN];
void process(int c, vector<pair<int, int> > &a) {
  sort((a).rbegin(), (a).rend());
  long long sum = 0;
  for (int i = 0; i < (int)(a.size()); i++) {
    sum += a[i].first;
    l[i + 1].push_back(make_pair(sum, c));
  }
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < (int)(n); i++) {
    int c, s;
    scanf("%d%d", &c, &s);
    m[c].push_back(make_pair(s, i));
  }
  for (map<int, vector<pair<int, int> > >::iterator i = m.begin(); i != m.end();
       i++)
    process(i->first, i->second);
  for (int i = 0; i < (int)(n + 1); i++) sort((l[i]).rbegin(), (l[i]).rend());
  long long sum = -INF;
  int c1, n1, c2, n2;
  for (int i = 1; i <= n; i++)
    for (int j = 0; j < (int)(min(2, (int)l[i].size())); j++) {
      for (int k = 0; k < (int)(min(2, (int)l[i].size())); k++) {
        long long cur = l[i][j].first + l[i][k].first;
        if (l[i][j].second != l[i][k].second && cur > sum) {
          sum = cur;
          c1 = l[i][j].second;
          n1 = i;
          c2 = l[i][k].second;
          n2 = i;
        }
      }
      for (int k = 0; k < (int)(min(2, (int)l[i - 1].size())); k++) {
        long long cur = l[i][j].first + l[i - 1][k].first;
        if (l[i][j].second != l[i - 1][k].second && cur > sum) {
          sum = cur;
          c1 = l[i][j].second;
          n1 = i;
          c2 = l[i - 1][k].second;
          n2 = i - 1;
        }
      }
    }
  cout << sum << endl << n1 + n2 << endl;
  vector<pair<int, int> > a1(m[c1].begin(), m[c1].begin() + n1);
  vector<pair<int, int> > a2(m[c2].begin(), m[c2].begin() + n2);
  for (int i = 0; i < (int)(min(n1, n2)); i++) {
    printf("%d ", a1[i].second + 1);
    printf("%d ", a2[i].second + 1);
  }
  if (n1 != n2) printf("%d", a1.back().second + 1);
  return 0;
}
