#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
const int N = 100010;
vector<pair<ll, int>> f[N];
map<int, vector<ii>> g;
int n;
int m1, m2, c1, c2;
ll ans;
bool checkAns(pair<ll, int> p, pair<ll, int> q) {
  if (p.second == q.second) return false;
  ll t = p.first + q.first;
  if (t > ans) {
    ans = t;
    c1 = p.second;
    c2 = q.second;
    return true;
  }
  return false;
}
void solve() {
  for (auto& p : g) {
    vector<ii>& v = p.second;
    int c = p.first;
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    ll sm = 0;
    for (int i = 0; i < (int)(v).size(); i++) {
      sm += v[i].first;
      f[i + 1].push_back({sm, c});
    }
  }
  for (int i = 1; i <= n; i++) {
    sort(f[i].begin(), f[i].end());
    reverse(f[i].begin(), f[i].end());
  }
  ans = 0;
  for (int i = 1; i <= n; i++) {
    if ((int)(f[i]).size() > 1 && checkAns(f[i][0], f[i][1])) {
      m1 = m2 = i;
    }
  }
  for (int i = 1; i < n; i++) {
    const auto& p = f[i];
    const auto& q = f[i + 1];
    if ((int)(p).size() > 0) {
      if ((int)(q).size() > 0 && checkAns(p[0], q[0])) {
        m1 = i;
        m2 = i + 1;
      }
      if ((int)(q).size() > 1 && checkAns(p[0], q[1])) {
        m1 = i;
        m2 = i + 1;
      }
    }
    if ((int)(p).size() > 1) {
      if ((int)(q).size() > 0 && checkAns(p[1], q[0])) {
        m1 = i;
        m2 = i + 1;
      }
      if ((int)(q).size() > 1 && checkAns(p[1], q[1])) {
        m1 = i;
        m2 = i + 1;
      }
    }
  }
  const auto& v1 = g[c1];
  const auto& v2 = g[c2];
  vector<int> res;
  for (int i = 0, j1 = 0, j2 = 0; i < m1 + m2; i++) {
    if (i & 1)
      res.push_back(v1[j1++].second);
    else
      res.push_back(v2[j2++].second);
  }
  cout << ans << "\n";
  cout << m1 + m2 << "\n";
  for (int i = 0; i < (int)(res).size(); i++) {
    cout << res[i] << (i == (int)(res).size() - 1 ? '\n' : ' ');
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int s, c;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> c >> s;
    g[c].push_back({s, i});
  }
  solve();
}
