#include <bits/stdc++.h>
using namespace std;
long long ans;
pair<int, int> ti;
void solve(pair<long long, int> x, pair<long long, int> y) {
  if (x.first + y.first > ans) {
    ans = x.first + y.first;
    ti = {x.second, y.second};
  }
}
int main() {
  int n, x, y, c1;
  set<int> maxi;
  scanf("%d", &n);
  map<int, vector<pair<long long, int>>> mp;
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &x, &y);
    mp[x].push_back({y, i});
  }
  for (auto &it : mp) {
    maxi.insert(it.second.size());
    sort(it.second.rbegin(), it.second.rend());
    for (int i = 1; i < it.second.size(); i++)
      it.second[i].first += it.second[i - 1].first;
  }
  for (auto i : maxi) {
    priority_queue<pair<long long, int>> pqi, pqipo;
    for (auto it : mp) {
      if (it.second.size() >= i) pqi.push({it.second[i - 1].first, it.first});
      if (it.second.size() > i) pqipo.push({it.second[i].first, it.first});
    }
    vector<pair<long long, int>> v1, v2;
    for (int j = 0; j < 3; j++)
      if (pqi.size() > 0) v1.push_back(pqi.top()), pqi.pop();
    for (int j = 0; j < 3; j++)
      if (pqipo.size() > 0) v2.push_back(pqipo.top()), pqipo.pop();
    if (v1.size() > 0)
      if (ans < mp[v1[0].second][0].first)
        ans = mp[v1[0].second][0].first, ti = {v1[0].second, v1[0].second};
    if (v1.size() > 1) solve(v1[0], v1[1]);
    for (int k = 0; k < v1.size(); k++)
      for (int j = 0; j < v2.size(); j++)
        if (v1[k].second != v2[j].second) solve(v1[k], v2[j]);
  }
  if (ti.second == ti.first)
    return cout << mp[ti.first][0].first << "\n1\n"
                << mp[ti.first][0].second,
           0;
  vector<int> v;
  printf("%I64d\n", ans);
  if (mp[ti.second].size() > mp[ti.first].size()) {
    for (int i = 0; i < mp[ti.first].size(); i++)
      v.push_back(mp[ti.second][i].second), v.push_back(mp[ti.first][i].second);
    v.push_back(mp[ti.second][mp[ti.first].size()].second);
  } else {
    for (int i = 0; i < mp[ti.first].size(); i++)
      v.push_back(mp[ti.first][i].second), v.push_back(mp[ti.second][i].second);
    if (mp[ti.second].size() < mp[ti.first].size())
      v.push_back(mp[ti.first][mp[ti.second].size()].second);
  }
  printf("%d\n", v.size());
  for (auto it : v) printf("%d ", it);
  return 0;
}
