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 block {
  int nom;
  int siz;
  int col;
};
vector<int> colors;
vector<block> blocks[100005];
vector<block> v[100005];
map<int, int> color_map;
int col[100005];
int siz[100005];
long long siz_sum[100005];
bool comp(block a, block b) { return a.siz > b.siz; }
int main() {
  int n;
  scanf("%d", &n);
  int i;
  for (i = 0; i < n; i++) {
    int c, s;
    scanf("%d%d", &c, &s);
    col[i] = c;
    siz[i] = s;
    colors.push_back(c);
  }
  colors.resize(unique(colors.begin(), colors.end()) - colors.begin());
  int col_count = colors.size();
  for (i = 0; i < col_count; i++) {
    color_map[colors[i]] = i;
  }
  block tmp;
  for (i = 0; i < n; i++) {
    tmp.nom = i + 1;
    tmp.siz = siz[i];
    tmp.col = color_map[col[i]];
    blocks[color_map[col[i]]].push_back(tmp);
  }
  for (i = 0; i < col_count; i++) {
    tmp.nom = 0;
    tmp.siz = 0;
    tmp.col = i;
    blocks[i].push_back(tmp);
    sort(blocks[i].begin(), blocks[i].end(), comp);
    int j;
    for (j = 0; j < blocks[i].size(); j++) {
      v[j + 1].push_back(blocks[i][j]);
    }
  }
  long long best = 0;
  int col1 = -1, col2 = -1;
  for (i = 1; i <= n; i++) {
    int j;
    int max_col = -1;
    long long max_sum = -1;
    int max_col2 = -1;
    long long max_sum2 = -1;
    for (j = 0; j < v[i].size(); j++) {
      tmp = v[i][j];
      siz_sum[tmp.col] += tmp.siz;
      if (siz_sum[tmp.col] >= max_sum) {
        max_sum2 = max_sum;
        max_col2 = max_col;
        max_sum = siz_sum[tmp.col];
        max_col = tmp.col;
      } else if (siz_sum[tmp.col] > max_sum2) {
        max_sum2 = siz_sum[tmp.col];
        max_col2 = tmp.col;
      }
    }
    if (max_col2 == -1) continue;
    long long s = max_sum + max_sum2;
    if (s > best) {
      best = s;
      col1 = max_col;
      col2 = max_col2;
    }
  }
  if (blocks[col1].size() < blocks[col2].size()) {
    swap(col1, col2);
  }
  vector<int> ans;
  int i1 = 0, i2 = 0;
  for (;;) {
    if (i1 == i2) {
      if (blocks[col1][i1].siz == 0) break;
      ans.push_back(blocks[col1][i1].nom);
      i1++;
    } else {
      if (blocks[col2][i2].siz == 0) break;
      ans.push_back(blocks[col2][i2].nom);
      i2++;
    }
  }
  printf("%I64d\n", best);
  printf("%d\n", ans.size());
  for (i = 0; i < ans.size(); i++) {
    if (i > 0) printf(" ");
    printf("%d", ans[i]);
  }
  printf("\n");
  return 0;
}