#include <bits/stdc++.h>
using namespace std;
map<int, vector<pair<int, long long> > > g;
vector<pair<int, long long> > f[(200000)];
int n;
long long ans;
pair<int, int> ansa, ansb;
bool cmp(pair<int, long long> a, pair<int, long long> b) {
  return a.second > b.second;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    int x;
    long long v;
    scanf("%d%I64d", &x, &v);
    g[x].push_back(make_pair(i, v));
  }
  for (map<int, vector<pair<int, long long> > >::iterator iter = g.begin();
       iter != g.end(); ++iter) {
    vector<pair<int, long long> >& a = iter->second;
    sort(a.begin(), a.end(), cmp);
    long long sum = 0ll;
    for (int i = 0; i < a.size(); ++i) {
      sum += a[i].second;
      f[i + 1].push_back(make_pair(iter->first, sum));
    }
  }
  for (int i = 1; i <= n; ++i) sort(f[i].begin(), f[i].end(), cmp);
  ans = -1ll;
  for (int i = 1; i <= n; ++i)
    if (f[i].size() >= 2) {
      long long v = f[i][0].second + f[i][1].second;
      if (v > ans)
        ans = v, ansa = make_pair(f[i][0].first, i),
        ansb = make_pair(f[i][1].first, i);
    }
  for (int i = 1; i < n; ++i)
    if (f[i].size() >= 1 && f[i + 1].size() >= 1 &&
        f[i][0].first != f[i + 1][0].first) {
      long long v = f[i][0].second + f[i + 1][0].second;
      if (v > ans)
        ans = v, ansa = make_pair(f[i][0].first, i),
        ansb = make_pair(f[i + 1][0].first, i + 1);
    }
  for (int i = 1; i < n; ++i)
    if (f[i].size() >= 1 && f[i + 1].size() >= 2 &&
        f[i][0].first != f[i + 1][1].first) {
      long long v = f[i][0].second + f[i + 1][1].second;
      if (v > ans)
        ans = v, ansa = make_pair(f[i][0].first, i),
        ansb = make_pair(f[i + 1][1].first, i + 1);
    }
  for (int i = 1; i < n; ++i)
    if (f[i].size() >= 2 && f[i + 1].size() >= 1 &&
        f[i][1].first != f[i + 1][0].first) {
      long long v = f[i][1].second + f[i + 1][0].second;
      if (v > ans)
        ans = v, ansa = make_pair(f[i][1].first, i),
        ansb = make_pair(f[i + 1][0].first, i + 1);
    }
  printf("%I64d\n%d\n", ans, ansa.second + ansb.second);
  for (int i = 1; i <= ansa.second; ++i) {
    printf("%d %d", g[ansb.first][i - 1].first, g[ansa.first][i - 1].first);
    if (i < ansa.second) printf(" ");
  }
  if (ansb.second > ansa.second)
    printf(" %d\n", g[ansb.first][ansb.second - 1].first);
  else
    printf("\n");
  return 0;
}
