#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e5 + 20;
long long n, sz;
map<long long, long long> mp;
vector<pair<long long, long long>> vec[MAXN], sec[MAXN];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (long long i = 0; i < n; i++) {
    long long a, b;
    cin >> a >> b;
    if (mp.count(a))
      a = mp[a];
    else
      a = mp[a] = sz++;
    vec[a].push_back({b, i + 1});
  }
  long long cn = 0;
  for (long long i = 0; i < sz; i++) {
    sort(vec[i].begin(), vec[i].end(), greater<pair<long long, long long>>());
    long long sum = 0;
    for (long long j = 0; j < (long long)vec[i].size(); j++) {
      sum += vec[i][j].first;
      sec[j + 1].push_back({sum, i});
    }
    cn = max(cn, (long long)vec[i].size());
  }
  long long maxi = 0, ind = 0, sind = -1;
  for (long long i = 1; i <= cn; i++) {
    sort(sec[i].begin(), sec[i].end(), greater<pair<long long, long long>>());
    if (sec[i].size() > 1 && maxi < sec[i][0].first + sec[i][1].first) {
      maxi = sec[i][0].first + sec[i][1].first;
      ind = sec[i][0].second;
      sind = sec[i][1].second;
    }
    if (i > 1) {
      if (sec[i][0].second != sec[i - 1][0].second &&
          maxi < sec[i][0].first + sec[i - 1][0].first) {
        maxi = sec[i][0].first + sec[i - 1][0].first;
        ind = sec[i][0].second;
        sind = sec[i - 1][0].second;
      }
      if (sec[i - 1].size() > 1 && sec[i][0].second != sec[i - 1][1].second &&
          maxi < sec[i][0].first + sec[i - 1][1].first) {
        maxi = sec[i][0].first + sec[i - 1][1].first;
        ind = sec[i][0].second;
        sind = sec[i - 1][1].second;
      }
      if (sec[i].size() > 1 && sec[i][1].second != sec[i - 1][0].second &&
          maxi < sec[i][1].first + sec[i - 1][0].first) {
        maxi = sec[i][1].first + sec[i - 1][0].first;
        ind = sec[i][1].second;
        sind = sec[i - 1][0].second;
      }
    }
  }
  cout << maxi << "\n";
  long long x = min((long long)vec[ind].size(), (long long)vec[sind].size());
  cout << 2 * x + bool((long long)vec[ind].size() > x ||
                       (long long)vec[sind].size() > x)
       << "\n";
  if ((long long)vec[ind].size() < (long long)vec[sind].size()) swap(ind, sind);
  for (long long i = 0; i < 2 * x + bool(vec[ind].size() > x); i++) {
    if (i % 2 == 0)
      cout << vec[ind][i / 2].second << " ";
    else
      cout << vec[sind][i / 2].second << " ";
  }
  cout << endl;
  return 0;
}
