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;
struct cube {
  long long h, c, i;
} np;
long long cubes, cons, val, totes, i1, i2, iv, kit = 1, nnext1 = 1, nnext2 = 2;
long long maxs[100005], max2s[100005], smax[100005], sm2[100005], res[100005];
vector<cube> clist(100005);
bool hp(cube i, cube j) {
  if (i.c != j.c) return i.c < j.c;
  return i.h > j.h;
}
int main() {
  cin >> cubes;
  for (int i = 1; i <= cubes; i++) {
    cin >> clist[i].c >> clist[i].h;
    clist[i].i = i;
  }
  sort(clist.begin() + 1, clist.begin() + 1 + cubes, hp);
  for (int i = 1; i <= cubes; i++) {
    if (clist[i].c != clist[i - 1].c) {
      cons = 0;
      val = 0;
    }
    cons++;
    val += clist[i].h;
    if (maxs[cons] < val) {
      max2s[cons] = maxs[cons];
      sm2[cons] = smax[cons];
      smax[cons] = clist[i].c;
      maxs[cons] = val;
    } else {
      if (max2s[cons] < val) {
        max2s[cons] = val;
        sm2[cons] = clist[i].c;
      }
    }
  }
  for (int i = 1; i <= cubes; i++) {
    if (maxs[i] + maxs[i - 1] > totes && smax[i - 1] != smax[i] &&
        maxs[i - 1] && maxs[i]) {
      kit = 1;
      iv = i;
      totes = maxs[i] + maxs[i - 1];
      i1 = smax[i];
      i2 = smax[i - 1];
    }
    if (maxs[i] + max2s[i - 1] > totes && smax[i] != sm2[i - 1] && maxs[i] &&
        max2s[i - 1]) {
      kit = 1;
      iv = i;
      totes = maxs[i] + max2s[i - 1];
      i1 = smax[i];
      i2 = sm2[i - 1];
    }
    if (maxs[i - 1] + max2s[i] > totes && smax[i - 1] != sm2[i] &&
        maxs[i - 1] && max2s[i]) {
      kit = 1;
      iv = i;
      totes = maxs[i - 1] + max2s[i];
      i2 = smax[i - 1];
      i1 = sm2[i];
    }
    if (maxs[i] + max2s[i] > totes && smax[i] != sm2[i] && maxs[i] &&
        max2s[i]) {
      kit = 0;
      iv = i;
      totes = maxs[i] + max2s[i];
      i2 = smax[i];
      i1 = sm2[i];
    }
  }
  cout << totes << "\n" << iv + iv - kit << "\n";
  for (int i = 1; i <= cubes; i++) {
    if (clist[i].c == i1) {
      for (int j = i; j < i + iv; j++) {
        res[nnext1] = clist[j].i;
        nnext1 += 2;
      }
      break;
    }
  }
  for (int i = 1; i <= cubes; i++) {
    if (clist[i].c == i2) {
      for (int j = i; j < (i + iv) - kit; j++) {
        res[nnext2] = clist[j].i;
        nnext2 += 2;
      }
      break;
    }
  }
  for (int i = 1; res[i] != 0; i++) {
    cout << res[i] << " ";
  }
  return 0;
}