#include <bits/stdc++.h>
using namespace std;
int n;
map<long int, vector<pair<long long int, int> > > pila;
long long int altezza_coppia(long int a, long int b) {
  if (pila[a].size() < pila[b].size()) swap(a, b);
  int numa = min(pila[a].size(), pila[b].size() + 1);
  int numb = pila[b].size();
  return pila[a][numa - 1].first + pila[b][numb - 1].first;
}
void migliore_coppia(int alt, long int &a, long int &b) {
  long long int best_alt = -1;
  for (map<long int, vector<pair<long long int, int> > >::iterator i =
           pila.begin();
       i != pila.end(); ++i) {
    if ((*i).second.size() < alt) continue;
    if (best_alt == -1 || (*i).second[alt - 1] > pila[best_alt][alt - 1]) {
      best_alt = (*i).first;
    }
  }
  long long int second_alt = -1;
  for (map<long int, vector<pair<long long int, int> > >::iterator i =
           pila.begin();
       i != pila.end(); ++i) {
    if ((*i).second.size() < alt) continue;
    if ((*i).first == best_alt) continue;
    if (second_alt == -1 || (*i).second[alt - 1] > pila[second_alt][alt - 1]) {
      second_alt = (*i).first;
    }
  }
  long long int best_alt_pp = -1;
  for (map<long int, vector<pair<long long int, int> > >::iterator i =
           pila.begin();
       i != pila.end(); ++i) {
    if ((*i).second.size() < alt + 1) continue;
    if (best_alt_pp == -1 || (*i).second[alt] > pila[best_alt_pp][alt]) {
      best_alt_pp = (*i).first;
    }
  }
  if (second_alt == -1 && best_alt_pp == -1) {
    a = best_alt;
    b = -1;
    return;
  }
  if (best_alt_pp == -1) {
    a = best_alt;
    b = second_alt;
    return;
  }
  if (best_alt == best_alt_pp) {
    a = best_alt_pp;
    b = second_alt;
    return;
  }
  if (pila[best_alt_pp][alt] > pila[second_alt][alt - 1]) {
    a = best_alt_pp;
    b = best_alt;
    return;
  } else {
    a = best_alt;
    b = second_alt;
    return;
  }
}
void stampa_pile(long int a, long int b) {
  if (pila[a].size() < pila[b].size()) swap(a, b);
  int numa = min(pila[a].size(), pila[b].size() + 1);
  int numb = pila[b].size();
  cout << numa + numb << "\n";
  for (int i = 0; i < min(numa, numb); ++i) {
    cout << pila[a][i].second << " ";
    cout << pila[b][i].second << " ";
  }
  if (numa > numb) cout << pila[a][numa - 1].second << " ";
  cout << "\n";
}
int main() {
  cin >> n;
  int col, lat;
  for (int i = 0; i < n; i++) {
    cin >> col >> lat;
    pila[col].push_back(make_pair(lat, i + 1));
  }
  for (map<long int, vector<pair<long long int, int> > >::iterator i =
           pila.begin();
       i != pila.end(); ++i) {
    sort((*i).second.begin(), (*i).second.end(),
         greater<pair<long long int, int> >());
    for (int j = 1; j < (*i).second.size(); ++j) {
      (*i).second[j].first += (*i).second[j - 1].first;
    }
  }
  set<long int> altezze;
  for (map<long int, vector<pair<long long int, int> > >::iterator i =
           pila.begin();
       i != pila.end(); ++i) {
    altezze.insert(-(*i).second.size());
    if ((*i).second.size() > 1) altezze.insert(-(*i).second.size() + 1);
  }
  long int a, b;
  long int aa, bb;
  long long int lmax = 0, tmp;
  for (set<long int>::iterator i = altezze.begin(); i != altezze.end(); ++i) {
    migliore_coppia(-*i, aa, bb);
    if (aa < 0 || bb < 0) continue;
    tmp = altezza_coppia(aa, bb);
    if (tmp > lmax) {
      a = aa;
      b = bb;
      lmax = tmp;
    }
  }
  cout << lmax << "\n";
  stampa_pile(a, b);
  return 0;
}
