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 M = 100002;
struct cube {
  int c, s, id;
} c[M];
vector<cube> vec[M];
int a[M];
bool cmp(cube a, cube b) { return a.c == b.c ? a.s > b.s : a.c < b.c; }
int binsearch(int c, int m) {
  int l = 0, r = m - 1;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (a[mid] == c)
      return mid;
    else if (a[mid] < c)
      l = mid + 1;
    else
      r = mid - 1;
  }
}
long long sum[M], max1[M], max2[M];
int max1_id[M], max2_id[M];
int main() {
  memset(a, 0, sizeof(a));
  memset(sum, 0, sizeof(sum));
  memset(max1, 0, sizeof(max1));
  memset(max2, 0, sizeof(max2));
  memset(max1_id, 0, sizeof(max1_id));
  memset(max2_id, 0, sizeof(max2_id));
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &c[i].c, &c[i].s);
    c[i].id = i + 1;
  }
  sort(c, c + n, cmp);
  int m = 0;
  a[m++] = c[0].c;
  for (int i = 1; i < n; i++) {
    if (c[i].c != c[i - 1].c) a[m++] = c[i].c;
  }
  int l = 0;
  for (int i = 0; i < n; i++) {
    int k = binsearch(c[i].c, m);
    vec[k].push_back(c[i]);
    sum[k] += c[i].s;
    int len = vec[k].size();
    if (max1[len] < sum[k]) {
      max2[len] = max1[len];
      max2_id[len] = max1_id[len];
      max1[len] = sum[k];
      max1_id[len] = k;
    } else if (max2[len] < sum[k]) {
      max2[len] = sum[k];
      max2_id[len] = k;
    }
    l = max(len, l);
  }
  long long maxh = 0;
  int c1 = 0, c2 = 0, l1 = 0, l2 = 0;
  for (int i = 1; i <= l; i++) {
    if (max1[i] && max2[i]) {
      if (maxh < max1[i] + max2[i]) {
        c1 = max1_id[i];
        c2 = max2_id[i];
        l1 = l2 = i;
        maxh = max1[i] + max2[i];
      }
    }
    if (max1[i] && max1[i + 1] && max1_id[i] != max1_id[i + 1]) {
      if (maxh < max1[i] + max1[i + 1]) {
        c1 = max1_id[i];
        c2 = max1_id[i + 1];
        l1 = i, l2 = i + 1;
        maxh = max1[i] + max1[i + 1];
      }
    }
    if (max1[i] && max2[i + 1] && max1_id[i] != max2_id[i + 1]) {
      if (maxh < max1[i] + max2[i + 1]) {
        c1 = max1_id[i];
        c2 = max2_id[i + 1];
        l1 = i, l2 = i + 1;
        maxh = max1[i] + max2[i + 1];
      }
    }
    if (max1[i + 1] && max2[i] && max1_id[i + 1] != max2_id[i]) {
      if (maxh < max1[i + 1] + max2[i]) {
        c2 = max1_id[i + 1];
        c1 = max2_id[i];
        l1 = i, l2 = i + 1;
        maxh = max1[i + 1] + max2[i];
      }
    }
  }
  printf("%I64d\n%d\n", maxh, l1 + l2);
  for (int i = 0; i < l1; i++) {
    printf("%d %d ", vec[c2][i].id, vec[c1][i].id);
  }
  if (l2 > l1) printf("%d\n", vec[c2][l1].id);
  return 0;
}