#include <bits/stdc++.h>
using namespace std;
bool compare(const pair<long long, long long>& i,
             const pair<long long, long long>& j) {
  if (i.first == j.first) return i.second < j.second;
  return i.first > j.first;
}
int main() {
  map<long long, vector<pair<long long, long long> > > cubes;
  long long n, color, size, sum;
  vector<pair<long long, long long> > best, secondbest;
  best.push_back(make_pair(0, 0));
  secondbest.push_back(make_pair(0, 0));
  best.push_back(make_pair(0, 0));
  secondbest.push_back(make_pair(0, 0));
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    best.push_back(make_pair(0, 0));
    secondbest.push_back(make_pair(0, 0));
    cin >> color >> size;
    if (cubes.find(color) == cubes.end()) {
      vector<pair<long long, long long> > newColor;
      cubes.insert(make_pair(color, newColor));
    }
    cubes[color].push_back(make_pair(size, i));
  }
  for (typeof((cubes).begin()) it = (cubes).begin(); it != (cubes).end(); it++)
    sort(it->second.begin(), it->second.end(), compare);
  for (typeof((cubes).begin()) it = (cubes).begin(); it != (cubes).end();
       it++) {
    sum = 0;
    for (long long i = 0; i < it->second.size(); ++i) {
      sum += it->second[i].first;
      if (sum > best[i + 1].first) {
        secondbest[i + 1].first = best[i + 1].first;
        secondbest[i + 1].second = best[i + 1].second;
        best[i + 1].first = sum;
        best[i + 1].second = it->first;
      } else if (sum > secondbest[i + 1].first) {
        secondbest[i + 1].first = sum;
        secondbest[i + 1].second = it->first;
      }
    }
  }
  pair<long long, long long> first(0, 0);
  pair<long long, long long> second(0, 0);
  long long result = 0;
  for (long long i = 1; i <= n; i++) {
    if (best[i].first == 0) continue;
    for (long long j = i - 1; j <= i + 1; ++j) {
      if (best[j].first == 0 || secondbest[j].first == 0) continue;
      if (best[i].second != best[j].second &&
          best[i].first + best[j].first > result) {
        result = best[i].first + best[j].first;
        first.first = i;
        first.second = best[i].second;
        second.first = j;
        second.second = best[j].second;
      }
      if (best[i].second != secondbest[j].second &&
          best[i].first + secondbest[j].first > result) {
        result = best[i].first + secondbest[j].first;
        first.first = i;
        first.second = best[i].second;
        second.first = j;
        second.second = secondbest[j].second;
      }
      if (secondbest[i].second != best[j].second &&
          secondbest[i].first + best[j].first > result) {
        result = secondbest[i].first + best[j].first;
        first.first = i;
        first.second = secondbest[i].second;
        second.first = j;
        second.second = best[j].second;
      }
    }
  }
  cout << result << endl;
  cout << first.first + second.first << endl;
  if (first.first < second.first) swap(first, second);
  map<long long, vector<pair<long long, long long> > >::iterator it1 =
      cubes.find(first.second);
  map<long long, vector<pair<long long, long long> > >::iterator it2 =
      cubes.find(second.second);
  long long j = 0;
  for (long long i = 0; i < first.first; ++i) {
    cout << it1->second[i].second << " ";
    if (j < second.first) {
      cout << it2->second[j].second << " ";
      ++j;
    }
  }
  cout << endl;
}
