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 ent {
  int nin;
  int heig;
  int color;
  int rcolor;
  bool operator<(const ent &P) const {
    if (color > P.color) return false;
    if (color < P.color) return true;
    if (heig < P.heig) return false;
    if (heig > P.heig) return true;
    return nin < P.nin;
  }
} rd[100001];
struct blk {
  int nin;
  int heig;
  blk(){};
  blk(int a, int b) {
    nin = a;
    heig = b;
  };
};
struct zcube {
  int color, cant;
  long long totalsum;
  vector<blk> lblocks;
  vector<long long> sumas;
  bool operator<(const zcube &P) const {
    if (totalsum < P.totalsum) return false;
    if (totalsum > P.totalsum) return true;
    return cant > P.cant;
  }
} cb[100001];
int n, k, sol, aa, caa = 0, bb, cbb = 0;
long long maxh = 0;
int main() {
  scanf("%d", &n);
  for (int p = (1); p <= (n); p += (1)) {
    scanf("%d", &rd[p].color);
    scanf("%d", &rd[p].heig);
    rd[p].nin = p;
  }
  sort(rd + 1, rd + n + 1);
  k = 0;
  for (int p = (1); p <= (n); p += (1)) {
    if (1 == p || rd[p].color != rd[p - 1].color) k++;
    rd[p].rcolor = k;
  }
  for (int p = (1); p <= (k); p += (1)) {
    cb[p].cant = 0;
    cb[p].color = p;
    cb[p].totalsum = 0;
    cb[p].sumas.clear();
    cb[p].lblocks.clear();
  }
  for (int p = (1); p <= (n); p += (1)) {
    cb[rd[p].rcolor].cant++;
    cb[rd[p].rcolor].totalsum += rd[p].heig;
    cb[rd[p].rcolor].sumas.push_back(cb[rd[p].rcolor].totalsum);
    cb[rd[p].rcolor].lblocks.push_back(blk(rd[p].nin, rd[p].heig));
  }
  sort(cb + 1, cb + k + 1);
  for (int p = (1); p <= (k); p += (1))
    for (int q = (p + 1); q <= (k); q += (1)) {
      if (maxh >= cb[p].totalsum + cb[q].totalsum)
        q = k;
      else {
        int tcnt = min(cb[p].cant, cb[q].cant);
        int tcntp = tcnt, tcntq = tcnt;
        if (cb[p].cant > tcnt)
          tcntp++;
        else if (cb[q].cant > tcnt)
          tcntq++;
        long long theigp = cb[p].sumas[tcntp - 1];
        long long theigq = cb[q].sumas[tcntq - 1];
        if (theigp + theigq > maxh) {
          maxh = theigp + theigq;
          aa = p;
          caa = tcntp;
          bb = q;
          cbb = tcntq;
        }
      }
    }
  cout << maxh << endl << caa + cbb << endl;
  if (0 != caa + cbb) {
    for (int p = (1); p <= (caa + cbb); p += (1)) {
      if (p > caa && p > cbb)
        p = caa + cbb;
      else if (caa >= cbb) {
        if (p <= caa) printf("%d ", cb[aa].lblocks[p - 1].nin);
        if (p <= cbb) printf("%d ", cb[bb].lblocks[p - 1].nin);
      } else if (caa <= cbb) {
        if (p <= cbb) printf("%d ", cb[bb].lblocks[p - 1].nin);
        if (p <= caa) printf("%d ", cb[aa].lblocks[p - 1].nin);
      }
    }
  }
}