#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
map<int, vector<pair<int, int> > > mp;
vector<pair<long long, int> > num[N];
int arr[N];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int c, s;
    scanf("%d%d", &c, &s);
    mp[c].push_back({s, i});
  }
  for (auto &it : mp) {
    sort(it.second.rbegin(), it.second.rend());
    int cnt = 0;
    long long sum = 0;
    for (auto &itt : it.second) {
      cnt++;
      sum += itt.first;
      num[cnt].push_back({sum, it.first});
    }
  }
  for (int i = 0; i < N; i++) {
    sort(num[i].rbegin(), num[i].rend());
  }
  int c1, c2, x1, x2;
  long long mx = 0;
  for (int i = 1; i < N - 1; i++) {
    long long sum = 0;
    if (num[i].size() > 1) {
      sum = num[i][0].first + num[i][1].first;
      if (sum > mx) {
        c1 = num[i][0].second;
        c2 = num[i][1].second;
        x1 = i;
        x2 = i;
        mx = sum;
      }
    }
    if (num[i].size() && num[i + 1].size()) {
      if (num[i][0].second == num[i + 1][0].second) {
        if (num[i].size() > 1) {
          sum = num[i][1].first + num[i + 1][0].first;
          if (sum > mx) {
            c1 = num[i][1].second;
            c2 = num[i + 1][0].second;
            x1 = i;
            x2 = i + 1;
            mx = sum;
          }
        }
        if (num[i + 1].size() > 1) {
          sum = num[i][0].first + num[i + 1][1].first;
          if (sum > mx) {
            c1 = num[i][0].second;
            c2 = num[i + 1][1].second;
            x1 = i;
            x2 = i + 1;
            mx = sum;
          }
        }
      } else {
        sum = num[i][0].first + num[i + 1][0].first;
        if (sum > mx) {
          c1 = num[i][0].second;
          c2 = num[i + 1][0].second;
          x1 = i;
          x2 = i + 1;
          mx = sum;
        }
      }
    }
  }
  long long S = 0;
  vector<pair<int, int> > v1 = mp[c1];
  vector<pair<int, int> > v2 = mp[c2];
  for (int i = 0; i < x2; i++) {
    int idx = i * 2 + 1;
    arr[idx] = v2[i].second;
    S += v2[i].first;
  }
  for (int i = 0; i < x1; i++) {
    int idx = i * 2 + 2;
    arr[idx] = v1[i].second;
    S += v1[i].first;
  }
  printf("%I64d\n%d\n", S, x1 + x2);
  for (int i = 1; i <= x1 + x2; i++) {
    printf("%d ", arr[i]);
  }
  return 0;
}
