#include <bits/stdc++.h>
using namespace std;
struct comp {
  bool operator()(const vector<int>& lhs, const vector<int>& rhs) const {
    return lhs.size() > rhs.size();
  }
};
struct comps {
  bool operator()(const string& lhs, const string& rhs) const {
    return lhs > rhs;
  }
};
bool ff(pair<int, int> a, pair<int, int> b) { return a.first < b.first; }
double dis(double x1, double y1, double x2, double y2) {
  return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
}
int gcd(long long unsigned int a, long long unsigned int b) {
  return (b == 0) ? a : gcd(b, a % b);
}
int comb(int a, int b) {
  if (a == 0) return 1;
  if (a < b) return 1;
  if (a == b) return 1;
  if (b == 1) return a;
  if (b == 0) return 1;
  long long unsigned int aa = 1, bb = 1;
  for (int i = b; i > 0; i--, a--) {
    aa *= a;
    bb *= i;
    int gc = gcd(aa, bb);
    if (gc > 1) {
      aa /= gc;
      bb /= gc;
    }
  }
  return aa % 1000000007;
}
bool isprime(long long unsigned int n) {
  for (int i = 2; i <= sqrt(n); i++)
    if (n % i == 0) return false;
  return true;
}
int main() {
  int n;
  long long int maxx = 0;
  map<int, vector<pair<long long int, long long int> > > mm;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    long long int a, b;
    cin >> a;
    cin >> b;
    mm[a].push_back(make_pair(b, i + 1));
  }
  for (map<int, vector<pair<long long int, long long int> > >::iterator it =
           mm.begin();
       it != mm.end(); it++) {
    sort((it->second).begin(), (it->second).end());
    reverse((it->second).begin(), (it->second).end());
    for (int i = 1; i < (it->second).size(); i++)
      (it->second)[i].first += (it->second)[i - 1].first;
  }
  int maxpos = 0;
  int mxcolor;
  for (map<int, vector<pair<long long int, long long int> > >::iterator it =
           mm.begin();
       it != mm.end(); it++) {
    maxpos = max(maxpos, (int)(it->second).size());
    if (maxpos == (it->second).size()) mxcolor = it->first;
  }
  int mxpos2 = 0;
  for (map<int, vector<pair<long long int, long long int> > >::iterator it =
           mm.begin();
       it != mm.end(); it++) {
    if (it->first == mxcolor) continue;
    mxpos2 = max(mxpos2, (int)(it->second).size());
  }
  maxpos += mxpos2;
  long long int mx[100005];
  bool f[100005] = {false};
  pair<int, int> p[100005];
  for (int i = 2; i <= maxpos; i++) {
    mx[i] = 0;
    int color;
    long long int mxx = 0;
    if (i % 2 == 0) {
      for (map<int, vector<pair<long long int, long long int> > >::iterator it =
               mm.begin();
           it != mm.end(); it++) {
        if ((it->second).size() < i / 2) continue;
        mx[i] = max(mx[i], (it->second)[i / 2 - 1].first);
        if (mx[i] == (it->second)[i / 2 - 1].first) {
          color = it->first;
          p[i].first = it->first;
        }
      }
      for (map<int, vector<pair<long long int, long long int> > >::iterator it =
               mm.begin();
           it != mm.end(); it++) {
        if (it->first == color) continue;
        if ((it->second).size() < i / 2) continue;
        mxx = max(mxx, (it->second)[i / 2 - 1].first);
        if (mxx == (it->second)[i / 2 - 1].first) p[i].second = it->first;
      }
      mx[i] += mxx;
    } else {
      for (map<int, vector<pair<long long int, long long int> > >::iterator it =
               mm.begin();
           it != mm.end(); it++) {
        if ((it->second).size() < i / 2) continue;
        mx[i] = max(mx[i], (it->second)[i / 2 - 1].first);
        if (mx[i] == (it->second)[i / 2 - 1].first) {
          color = it->first;
          p[i].first = it->first;
        }
      }
      for (map<int, vector<pair<long long int, long long int> > >::iterator it =
               mm.begin();
           it != mm.end(); it++) {
        if (it->first == color) continue;
        if ((it->second).size() < i / 2 + 1) continue;
        mxx = max(mxx, (it->second)[i / 2].first);
        if (mxx == (it->second)[i / 2].first) p[i].second = it->first;
      }
      mx[i] += mxx;
      long long int mmxx = 0, mmxxx = 0;
      int pp;
      int ppp;
      for (map<int, vector<pair<long long int, long long int> > >::iterator it =
               mm.begin();
           it != mm.end(); it++) {
        if ((it->second).size() < i / 2 + 1) continue;
        mmxx = max(mmxx, (it->second)[i / 2].first);
        if (mmxx == (it->second)[i / 2].first) {
          color = it->first;
          pp = it->first;
        }
      }
      for (map<int, vector<pair<long long int, long long int> > >::iterator it =
               mm.begin();
           it != mm.end(); it++) {
        if (it->first == color) continue;
        if ((it->second).size() < i / 2) continue;
        mmxxx = max(mmxxx, (it->second)[i / 2 - 1].first);
        if (mmxxx == (it->second)[i / 2 - 1].first) ppp = it->first;
      }
      if (mmxxx + mmxx > mx[i]) {
        mx[i] = mmxx + mmxxx;
        p[i].first = pp;
        p[i].second = ppp;
        f[i] = true;
      }
    }
  }
  long long int totalmax = 0;
  int c1, c2;
  int index1, index2;
  for (int i = 2; i <= maxpos; i++) {
    totalmax = max(mx[i], totalmax);
    if (totalmax == mx[i]) {
      c1 = p[i].first;
      c2 = p[i].second;
      if (i % 2) {
        if (!f[i]) {
          index1 = i / 2;
          index2 = i / 2 + 1;
        } else {
          index1 = i / 2 + 1;
          index2 = i / 2;
        }
      } else {
        index1 = index2 = i / 2;
      }
    }
  }
  cout << totalmax << endl << index1 + index2 << endl;
  if (index1 == index2)
    for (int i = 0; i < index1; i++)
      cout << mm[c1][i].second << " " << mm[c2][i].second << " ";
  else if (index1 > index2) {
    for (int i = 0; i < index2; i++)
      cout << mm[c1][i].second << " " << mm[c2][i].second << " ";
    cout << mm[c1][index2].second;
  } else if (index2 > index1) {
    for (int i = 0; i < index1; i++)
      cout << mm[c2][i].second << " " << mm[c1][i].second << " ";
    cout << mm[c2][index1].second;
  }
  return 0;
}
