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>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
template <class T>
inline T sqr(T x) {
  return x * x;
}
const double eps = 1e-9;
const double pi = acos(-1.0);
const long long INF = (long long)1e18;
const int maxn = (int)1e5 + 10;
struct cube {
  long long h;
  int id;
  cube() : h(-INF), id(-1) {}
  cube(long long h, int id) : h(h), id(id) {}
};
bool cmp(cube a, cube b) { return a.h > b.h; }
cube ma1[maxn], ma2[maxn];
int main() {
  map<int, vector<cube> > d;
  int n, a, b;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &a, &b);
    d[a].push_back(cube(b, i + 1));
  }
  for (map<int, vector<cube> >::iterator it = d.begin(); it != d.end(); it++) {
    sort((it->second).begin(), (it->second).end(), cmp);
    long long h = 0;
    for (int i = 0; i < (int)(it->second).size(); i++) {
      h += it->second[i].h;
      if (ma1[i].h < h) {
        ma2[i] = ma1[i];
        ma1[i] = cube(h, it->first);
      } else if (ma2[i].h < h) {
        ma2[i] = cube(h, it->first);
      }
    }
  }
  long long best = 0;
  int num1 = -1, num2 = -1;
  int id1 = -1, id2 = -1;
  for (int i = 0; i < maxn; i++) {
    if (i && ma1[i].id != ma1[i - 1].id && best < ma1[i].h + ma1[i - 1].h) {
      best = ma1[i].h + ma1[i - 1].h;
      num1 = i + 1;
      num2 = i;
      id1 = ma1[i].id;
      id2 = ma1[i - 1].id;
    }
    for (int x = 0; x < 2; x++)
      for (int y = 0; y < 2; y++)
        if (i - x >= 0 && i - y >= 0 && ma1[i - x].id != ma2[i - y].id &&
            best < ma1[i - x].h + ma2[i - y].h) {
          best = ma1[i - x].h + ma2[i - y].h;
          num1 = i - x + 1;
          num2 = i - y + 1;
          id1 = ma1[i - x].id;
          id2 = ma2[i - y].id;
        }
  }
  cout << best << endl << num1 + num2 << endl;
  if (num1 < num2) {
    swap(num1, num2);
    swap(id1, id2);
  }
  int i = 0;
  int j = 0;
  int k = 0;
  while (i < num1 || j < num2) {
    if (k == 0) {
      printf("%d ", d[id1][i].id);
      i++;
    } else {
      printf("%d ", d[id2][j].id);
      j++;
    }
    k = 1 - k;
  }
  return 0;
}