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 {
  int color, height, idx;
};
struct CubeSet {
  int len;
  int pos;
};
Cube cubes[100010];
CubeSet cs[100010];
long long maxHeight[100010];
int maxIdx[100010];
bool cubeSort(Cube, Cube);
bool colorSort(CubeSet, CubeSet);
int main() {
  ios_base::sync_with_stdio(false);
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> cubes[i].color;
    cin >> cubes[i].height;
    cubes[i].idx = (i + 1);
  }
  sort(cubes, cubes + N, cubeSort);
  int colorLen = 0;
  int j = 0;
  int minH = 100010;
  for (int i = 0; i < N; i = j) {
    cs[colorLen].pos = i;
    for (j = i; j < N && cubes[j].color == cubes[i].color; j++)
      cs[colorLen].len++;
    minH = min(minH, cs[colorLen].len);
    colorLen++;
  }
  sort(cs, cs + colorLen, colorSort);
  memset(maxHeight, 0, sizeof(maxHeight));
  memset(maxIdx, 0, sizeof(maxIdx));
  long long ans = 0;
  int bestA_idx, bestA_len, bestB_idx, bestB_len;
  for (int i = 0; i < colorLen; i++) {
    long long curH = 0;
    for (int j = 0; j < minH - 1; j++) curH += cubes[cs[i].pos + j].height;
    for (int j = minH - 1; j < cs[i].len; j++) {
      curH += cubes[cs[i].pos + j].height;
      for (int k = j; k <= j + 1; k++) {
        if (maxHeight[k] != 0 && (curH + maxHeight[k]) > ans) {
          ans = curH + maxHeight[k];
          bestA_idx = i, bestB_idx = maxIdx[k];
          bestA_len = j + 1, bestB_len = k;
        }
      }
    }
    if (curH > maxHeight[cs[i].len]) {
      maxHeight[cs[i].len] = curH;
      maxIdx[cs[i].len] = i;
    }
  }
  cout << ans << endl;
  cout << (bestA_len + bestB_len) << endl;
  for (int i = 0; i < bestA_len; i++) {
    cout << cubes[cs[bestA_idx].pos + i].idx;
    if (i < bestB_len) cout << " " << cubes[cs[bestB_idx].pos + i].idx << " ";
  }
  cout << endl;
}
bool cubeSort(Cube a, Cube b) {
  if (a.color != b.color) return a.color < b.color;
  return a.height > b.height;
}
bool colorSort(CubeSet a, CubeSet b) { return a.len < b.len; }