#include <bits/stdc++.h>
using namespace std;
struct Node {
  int c, s, num;
} data[100005];
struct T {
  int st;
  long long sum;
} t[100005][2];
bool cmp(Node a, Node b) {
  if (a.c != b.c) return a.c < b.c;
  return a.s > b.s;
}
int n;
long long find(int h, int st, int &ed) {
  int k = 0;
  if (t[h][0].st == st) k++;
  ed = t[h][k].st;
  return t[h][k].sum;
}
void insert(int h, int st, long long sum) {
  if (t[h][0].st == -1 || t[h][0].sum < sum) {
    t[h][1] = t[h][0];
    t[h][0].st = st;
    t[h][0].sum = sum;
  } else if (t[h][1].st == -1 || t[h][1].sum < sum) {
    t[h][1].st = st;
    t[h][1].sum = sum;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    data[i].num = i + 1;
    scanf("%d%d", &data[i].c, &data[i].s);
  }
  sort(data, data + n, cmp);
  long long sum;
  int st, num;
  memset(t, -1, sizeof(t));
  for (int i = 0; i < n; i++) {
    if (i == 0 || data[i].c != data[i - 1].c) {
      st = i;
      num = 1;
      sum = data[i].s;
    } else
      num++, sum += data[i].s;
    insert(num, st, sum);
  }
  long long ans = -1;
  int g, h, l1, l2;
  st = 0, num = 1, sum = data[0].s;
  for (int i = 1; i <= n; i++) {
    if (data[i].c != data[i - 1].c) {
      int ed;
      long long k = find(num - 1, st, ed);
      if (ed != -1 && k + sum > ans) {
        ans = k + sum;
        g = st, h = ed, l1 = num, l2 = num - 1;
      }
      k = find(num, st, ed);
      if (ed != -1 && k + sum > ans) {
        ans = k + sum;
        g = st, h = ed, l1 = num, l2 = num;
      }
      k = find(num + 1, st, ed);
      if (ed != -1 && k + sum > ans) {
        ans = k + sum;
        g = st, h = ed, l1 = num, l2 = num + 1;
      }
      num = 1;
      st = i;
      sum = data[i].s;
    } else
      num++, sum += data[i].s;
  }
  cout << ans << endl << l1 + l2 << endl;
  if (l2 > l1) {
    printf("%d ", data[h++].num);
    l2--;
  }
  for (int i = 0; i < l1 + l2; i++) {
    if (i != 0) printf(" ");
    printf("%d", (i % 2 == 0) ? data[g++].num : data[h++].num);
  }
  return 0;
}
