#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
struct node {
  int c, h, i;
  friend bool operator<(const node &a, const node &b) {
    if (a.c != b.c) return a.c < b.c;
    return a.h > b.h;
  }
} t[N];
struct node2 {
  int s, t, i, size;
  friend bool operator<(const node2 &a, const node2 &b) {
    return a.size > b.size;
  }
} prepare[N];
int n, ss[N], rest[N], cnt, ans1, ans2;
long long sum[N], Max;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &t[i].c, &t[i].h);
    t[i].i = i;
  }
  sort(t + 1, t + n + 1);
  for (int i = 1; i <= n; i++) {
    int s = 0, j;
    for (j = i + 1; t[j].c == t[i].c && j <= n; j++)
      ;
    ss[++cnt] = j - i;
    prepare[cnt].s = i, prepare[cnt].t = j;
    prepare[cnt].i = cnt, prepare[cnt].size = j - i;
    i = j - 1;
  }
  sort(prepare + 1, prepare + cnt + 1);
  for (int i = 1; i <= cnt; i++) rest[i] = prepare[i].size;
  for (int p = cnt, s = 0; p > 1;) {
    int delta = 10000000;
    for (int i = p; i > 0; i--) delta = min(delta, rest[i]);
    for (int i = p; i > 0; i--) {
      for (int j = 1; j <= delta; j++) sum[i] += t[prepare[i].s + s + j - 1].h;
      rest[i] -= delta;
    }
    s += delta;
    for (int i = p; i > 0; i--)
      if (rest[i] > 0) sum[i] += t[prepare[i].s + s].h;
    int p1 = 0, p2 = 0;
    for (int i = p; i > 0; i--)
      if (sum[i] > sum[p1])
        p2 = p1, p1 = i;
      else if (sum[i] == sum[p1])
        p2 = i;
      else if (sum[i] > sum[p2])
        p2 = i;
    if (sum[p1] + sum[p2] > Max) Max = sum[p1] + sum[p2], ans1 = p1, ans2 = p2;
    for (int i = p; i > 0; i--)
      if (rest[i] > 0) sum[i] -= t[prepare[i].s + s].h;
    while (rest[p] == 0 && p > 0) p--;
  }
  cout << Max << endl;
  if (ss[prepare[ans1].i] == ss[prepare[ans2].i]) {
    printf("%d\n", ss[prepare[ans1].i] * 2);
    for (int i = 1; i < ss[prepare[ans1].i]; i++)
      printf("%d %d ", t[prepare[ans1].s + i - 1].i,
             t[prepare[ans2].s + i - 1].i);
    printf("%d %d\n", t[prepare[ans1].t - 1].i, t[prepare[ans2].t - 1].i);
  } else {
    if (ss[prepare[ans1].i] > ss[prepare[ans2].i]) swap(ans1, ans2);
    printf("%d\n%d", ss[prepare[ans1].i] * 2 + 1, t[prepare[ans2].s].i);
    for (int i = 1; i <= ss[prepare[ans1].i]; i++)
      printf(" %d %d", t[prepare[ans1].s + i - 1].i, t[prepare[ans2].s + i].i);
    printf("\n");
  }
  return 0;
}
