Problem: Little Janet likes playing with cubes. Actually, she likes to play with anything whatsoever, cubes or tesseracts, as long as they are multicolored. Each cube is described by two parameters — color ci and size si. A Zebra Tower is a tower that consists of cubes of exactly two colors. Besides, the colors of the cubes in the tower must alternate (colors of adjacent cubes must differ). The Zebra Tower should have at least two cubes. There are no other limitations. The figure below shows an example of a Zebra Tower.

<image>

A Zebra Tower's height is the sum of sizes of all cubes that form the tower. Help little Janet build the Zebra Tower of the maximum possible height, using the available cubes.

Input

The first line contains an integer n (2 ≤ n ≤ 105) — the number of cubes. Next n lines contain the descriptions of the cubes, one description per line. A cube description consists of two space-separated integers ci and si (1 ≤ ci, si ≤ 109) — the i-th cube's color and size, correspondingly. It is guaranteed that there are at least two cubes of different colors.

Output

Print the description of the Zebra Tower of the maximum height in the following form. In the first line print the tower's height, in the second line print the number of cubes that form the tower, and in the third line print the space-separated indices of cubes in the order in which they follow in the tower from the bottom to the top. Assume that the cubes are numbered from 1 to n in the order in which they were given in the input.

If there are several existing Zebra Towers with maximum heights, it is allowed to print any of them. 

Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.

Examples

Input

4
1 2
1 3
2 4
3 3


Output

9
3
2 3 1 


Input

2
1 1
2 1


Output

2
2
2 1 

Solution (in CPP):

Solution:
#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;
}