#include <bits/stdc++.h>
using namespace std;
template <class t>
ostream &operator<<(ostream &tout, const vector<t> &s) {
  tout << '[';
  for (long long i = 0; i < s.size(); i++)
    if (i + 1 == s.size())
      tout << s[i];
    else
      tout << s[i] << ',';
  tout << ']';
  return (tout);
}
template <class a, class b>
ostream &operator<<(ostream &tout, const pair<a, b> &c) {
  return (tout << '(' << c.first << ',' << c.second << ')');
}
template <class T>
struct __set__print {
  __set__print(ostream &out) : tout(out), __cnt__(0) {}
  void operator()(T x) {
    if (__cnt__ > 0) tout << ',';
    tout << x;
    ++__cnt__;
  }
  ostream &tout;
  long long __cnt__;
};
template <class T>
ostream &operator<<(ostream &tout, const set<T> &s) {
  tout << '{';
  for_each(s.begin(), s.end(), __set__print<T>(tout));
  return (tout << '}');
}
template <class T, class Q>
struct print_map {
  print_map(ostream &out) : tout(out), __cnt__(0) {}
  void operator()(const pair<T, Q> &x) {
    if (__cnt__ > 0) tout << ',';
    tout << '(' << x.first << " => " << x.second << ')';
    ++__cnt__;
  }
  ostream &tout;
  long long __cnt__;
};
template <class T, class Q>
ostream &operator<<(ostream &tout, map<T, Q> s) {
  tout << '{';
  for_each(s.begin(), s.end(), print_map<T, Q>(tout));
  return (tout << '}');
}
template <class T>
string to_string(T s) {
  stringstream tin;
  tin << s;
  string res;
  getline(tin, res);
  return (res);
}
template <class T>
vector<T> to_vector(T *s, long long n) {
  vector<T> result;
  for (long long i = 0; i < n; i++) result.push_back(s[i]);
  return (result);
}
long long n;
map<long long, long long> __cnt__;
vector<pair<long long, long long> > all;
bool df(long long ss, long long tt) {
  pair<long long, long long> s = all[ss], t = all[tt];
  if (__cnt__[s.first] != __cnt__[t.first])
    return (__cnt__[s.first] > __cnt__[t.first]);
  if (s.first != t.first) return (s.first > t.first);
  if (s.second != t.second) return (s.second > t.second);
  return (ss > tt);
}
map<long long, vector<long long> > ort;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    long long a, b;
    cin >> a >> b;
    all.push_back(pair<long long, long long>(a, b));
    __cnt__[a]++;
    ort[a].push_back(b);
  }
  vector<pair<long long, long long> > best[2];
  best[0] = vector<pair<long long, long long> >(
      n + 1, pair<long long, long long>(-1, -1));
  best[1] = vector<pair<long long, long long> >(
      n + 1, pair<long long, long long>(-1, -1));
  for (map<long long, vector<long long> >::iterator i = ort.begin();
       i != ort.end(); i++) {
    sort(i->second.begin(), i->second.end());
    reverse(i->second.begin(), i->second.end());
    long long sm = 0;
    for (long long j = 0; j < i->second.size(); j++) {
      sm += i->second[j];
      if (best[0][j] < pair<long long, long long>(sm, i->first)) {
        swap(best[0][j], best[1][j]);
        best[0][j] = pair<long long, long long>(sm, i->first);
      } else if (best[1][j] < pair<long long, long long>(sm, i->first))
        best[1][j] = pair<long long, long long>(sm, i->first);
    }
  }
  long long mx = 0;
  long long c1 = -1, c2 = -1;
  for (long long i = 0; i + 1 < best[0].size(); i++)
    for (long long a = 0; a <= 1; a++)
      for (long long b = 0; b <= 1; b++) {
        if (best[a][i].second != best[b][i].second && best[a][i].first >= 0 &&
            best[b][i].first >= 0) {
          if (mx < best[a][i].first + best[b][i].first) {
            mx = best[a][i].first + best[b][i].first;
            c1 = best[a][i].second;
            c2 = best[b][i].second;
          }
        }
        if (best[a][i + 1].second != best[b][i].second &&
            best[a][i + 1].first >= 0 && best[b][i].first >= 0) {
          if (mx < best[a][i + 1].first + best[b][i].first) {
            mx = best[a][i + 1].first + best[b][i].first;
            c1 = best[a][i + 1].second;
            c2 = best[b][i].second;
          }
        }
      }
  vector<long long> sorted;
  for (long long i = 0; i < all.size(); i++) sorted.push_back(i);
  sort(sorted.begin(), sorted.end(), df);
  vector<long long> t;
  for (long long i = 0; i < sorted.size(); i++) {
    if (all[sorted[i]].first != c1 && all[sorted[i]].first != c2) continue;
    t.push_back(sorted[i]);
  }
  sorted = t;
  vector<long long> inds;
  long long p1 = 0, p2 = sorted.size() - 1;
  while (p1 <= p2) {
    if (inds.size() % 2) {
      inds.push_back(sorted[p2]);
      p2--;
    } else {
      inds.push_back(sorted[p1]);
      p1++;
    }
  }
  vector<long long> res;
  for (long long i = 0; i < inds.size(); i++)
    if (res.size() == 0 || all[inds[i]].first != all[res.back()].first)
      res.push_back(inds[i]);
  long long ans = 0;
  for (long long i = 0; i < res.size(); i++) ans += all[res[i]].second;
  cout << ans << endl;
  cout << res.size() << endl;
  for (long long i = 0; i < res.size(); i++) cout << res[i] + 1 << ' ';
  cout << endl;
}
