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;
int color[111111], colorCnt;
vector<int> id[111111];
vector<long long> height[111111];
long long maxHeight[111111][2];
int from[111111][2];
int n;
int c[111111], s[111111];
bool cmp(int x, int y) { return s[x] > s[y]; }
void update(long long h, int level, int id) {
  if (h > maxHeight[level][0]) {
    maxHeight[level][1] = maxHeight[level][0];
    from[level][1] = from[level][0];
    maxHeight[level][0] = h;
    from[level][0] = id;
  } else if (h > maxHeight[level][1]) {
    maxHeight[level][1] = h;
    from[level][1] = id;
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> c[i] >> s[i];
  }
  for (int i = 0; i < n; ++i) {
    color[i] = c[i];
  }
  sort(color, color + n);
  colorCnt = unique(color, color + n) - color;
  for (int i = 0; i < n; ++i) {
    c[i] = lower_bound(color, color + colorCnt, c[i]) - color;
  }
  for (int i = 0; i < n; ++i) {
    id[c[i]].push_back(i);
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < 2; ++j) {
      maxHeight[i][j] = 0LL;
      from[i][j] = -1;
    }
  }
  for (int c = 0; c < colorCnt; ++c) {
    sort(id[c].begin(), id[c].end(), cmp);
    height[c].resize(id[c].size() + 2, 0LL);
    height[c][0] = 0LL;
    for (int i = 0; i < id[c].size(); ++i) {
      height[c][i + 1] = height[c][i] + (long long)s[id[c][i]];
    }
    for (int i = 1; i <= id[c].size(); ++i) {
      update(height[c][i], i, c);
    }
  }
  long long res = 0LL;
  int c1, c2, h1, h2;
  for (int c = 0; c < colorCnt; ++c) {
    int curH = id[c].size();
    if (curH == 0) {
      continue;
    }
    for (int h = 0; h < 2; ++h) {
      for (int k = 0; k < 2; ++k) {
        if (from[curH + h][k] != -1 && from[curH + h][k] != c) {
          if (res < height[c][curH] + maxHeight[curH + h][k]) {
            res = height[c][curH] + maxHeight[curH + h][k];
            c1 = c;
            c2 = from[curH + h][k];
            h1 = curH;
            h2 = curH + h;
          }
        }
      }
    }
  }
  cout << res << endl;
  cout << h1 + h2 << endl;
  vector<int> ans;
  int p1 = 0, p2 = 0;
  for (int i = 0; i < h1 + h2; ++i) {
    cout << id[c2][p2] + 1;
    if (i < h1 + h2 - 1) cout << " ";
    p2 += 1;
    swap(c1, c2);
    swap(p1, p2);
  }
  cout << endl;
}