#include <bits/stdc++.h>
const long long mod = 1e9 + 7;
using namespace std;
int main() {
  int n;
  cin >> n;
  map<long long, vector<pair<long long, long long>>> idxs;
  map<long long, vector<pair<long long, long long>>> highests;
  long long temphigh = 0, tempidx = 0;
  for (int i = 0; i < n; i++) {
    long long c, s;
    cin >> c >> s;
    idxs[c].push_back({s, i + 1});
    if (s > temphigh) {
      temphigh = s;
      tempidx = i + 1;
    }
  }
  long long mx = 0;
  for (auto it : idxs) {
    long long curr = 0;
    sort(it.second.rbegin(), it.second.rend());
    for (int i = 1; i <= it.second.size(); i++) {
      int idx = i - 1;
      it.second[idx].first;
      curr += it.second[idx].first;
      highests[i].push_back({curr, it.first});
    }
    mx = max(mx, (long long)it.second.size());
  }
  long long high = 0;
  long long c1 = -1, h1 = 0;
  long long c2 = -1, h2 = 0;
  bool found = false;
  for (int i = 1; i <= mx; i++) {
    sort(highests[i].rbegin(), highests[i].rend());
    if (highests[i].size() >= 2) {
      if (highests[i][0].first + highests[i][1].first > high) {
        high = highests[i][0].first + highests[i][1].first;
        c1 = highests[i][0].second;
        h1 = i;
        c2 = highests[i][1].second;
        h2 = i;
        found = true;
      }
    }
    if (i - 1 >= 1) {
      int q = 0;
      while (q < highests[i - 1].size() &&
             highests[i - 1][q].second == highests[i][0].second)
        q++;
      if (q < highests[i - 1].size()) {
        if (highests[i].size() && highests[i - 1].size()) {
          if (highests[i][0].first + highests[i - 1][q].first > high) {
            high = highests[i][0].first + highests[i - 1][q].first;
            c1 = highests[i][0].second;
            h1 = i;
            c2 = highests[i - 1][q].second;
            h2 = i - 1;
            found = true;
          }
        }
      }
    }
    if (i + 1 <= n) {
      int q = 0;
      while (q < highests[i + 1].size() &&
             highests[i + 1][q].second == highests[i][0].second)
        q++;
      if (q < highests[i + 1].size()) {
        if (highests[i].size() && highests[i + 1].size()) {
          if (highests[i][0].first + highests[i + 1][q].first > high) {
            high = highests[i][0].first + highests[i + 1][q].first;
            c1 = highests[i + 1][q].second;
            h1 = i + 1;
            c2 = highests[i][0].second;
            h2 = i;
            found = true;
          }
        }
      }
    }
  }
  if (!found) {
    cout << temphigh << '\n' << 1 << '\n' << tempidx;
    return 0;
  }
  cout << high << '\n';
  cout << h1 + h2 << '\n';
  sort(idxs[c1].rbegin(), idxs[c1].rend());
  sort(idxs[c2].rbegin(), idxs[c2].rend());
  if (h1 == h2) {
    for (int i = 0; i < h2; i++)
      cout << idxs[c1][i].second << ' ' << idxs[c2][i].second << ' ';
  } else {
    cout << idxs[c1][0].second << ' ';
    for (int i = 0; i < h2; i++) {
      cout << idxs[c2][i].second << ' ' << idxs[c1][i + 1].second << ' ';
    }
  }
  return 0;
}
