#include <bits/stdc++.h>
const int MAXN = 100005;
using namespace std;
long long ans;
pair<int, int> A[MAXN];
map<int, int> M;
int n, m, a, b, x, y, l, r;
vector<pair<int, int> > v[MAXN];
pair<long long, int> mx[MAXN][3];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &A[i].first, &A[i].second);
    M[A[i].first] = 1;
  }
  for (auto &i : M) i.second = ++m;
  for (int i = 0; i < n; i++) v[M[A[i].first]].emplace_back(A[i].second, i + 1);
  for (int i = 0; i < MAXN; i++)
    for (int j = 0; j < 2; j++) mx[i][j] = {0, -1};
  for (int i = 1; i <= m; i++) sort((v[i]).rbegin(), (v[i]).rend());
  for (int i = 1; i <= m; i++) {
    long long sm = 0;
    for (int h = 0; h < (int)v[i].size(); h++) {
      sm += v[i][h].first;
      for (int j = 0; j < 2; j++) {
        if (mx[h + 1][j].first < sm) {
          swap(mx[h + 1][j], mx[h + 1][j + 1]);
          mx[h + 1][j] = {sm, i};
          break;
        }
      }
    }
  }
  for (int i = 1; i <= m; i++) {
    long long sm = 0;
    for (int h = 0; h < (int)v[i].size(); h++) {
      sm += v[i][h].first;
      for (int j = 0; j < 2; j++) {
        if (mx[h][j].second != -1 && mx[h][j].second != i) {
          if (ans < sm + mx[h][j].first) {
            ans = sm + mx[h][j].first;
            a = i, b = mx[h][j].second, x = h + 1, y = h;
          }
          break;
        }
      }
      for (int j = 0; j < 2; j++) {
        if (mx[h + 1][j].second != -1 && mx[h + 1][j].second != i) {
          if (ans < sm + mx[h + 1][j].first) {
            ans = sm + mx[h + 1][j].first;
            a = i, b = mx[h + 1][j].second, x = h + 1, y = h + 1;
          }
          break;
        }
      }
    }
  }
  if (x < y) {
    swap(x, y);
    swap(a, b);
  }
  printf("%lld\n", ans);
  printf("%d\n", x + y);
  for (int i = 0; i < x + y; i++) {
    if (i % 2 == 0)
      printf("%d ", v[a][l].second), l++;
    else
      printf("%d ", v[b][r].second), r++;
  }
}
