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 {
  unsigned long c;
  unsigned long s;
  unsigned long i;
};
bool comp(cube a, cube b) {
  if (a.c > b.c || (a.c == b.c && a.s > b.s)) return true;
  return false;
}
int main() {
  long N;
  cube *A = new cube[100000];
  cin >> N;
  cin.ignore();
  cube c;
  for (long i = 0; i < N; i++) {
    cin >> c.c >> c.s;
    c.i = i + 1;
    cin.ignore();
    c.i = i + 1;
    A[i] = c;
  }
  sort(A, A + N, comp);
  vector<unsigned long long> *B = new vector<unsigned long long>[100000];
  long *S = new long[100000];
  long p = 0;
  long len = 1;
  unsigned long curr_c = 0;
  ;
  unsigned long long sum = 0;
  long groups_count = 0;
  while (p < N) {
    if (curr_c == A[p].c) {
      sum += A[p].s;
      B[groups_count - 1].push_back(sum);
      p++;
    } else {
      groups_count++;
      S[groups_count - 1] = p;
      sum = 0;
      curr_c = A[p].c;
    }
  }
  set<long> L;
  for (long i = 0; i < groups_count; i++) {
    L.insert(B[i].size());
  }
  unsigned long long max_sum = 0;
  unsigned long long max_count;
  unsigned long long max1, max2, j1, j2, j3, j4;
  for (set<long>::iterator i = L.begin(); i != L.end(); i++) {
    max1 = 0;
    max2 = 0;
    j1 = -1;
    j2 = -1;
    for (long j = 0; j < groups_count; j++) {
      if (B[j].size() - 1 >= *i)
        sum = B[j][*i];
      else if (B[j].size() == *i)
        sum = B[j][*i - 1];
      else
        sum = 0;
      if (sum > max1) {
        if (max1 > max2) {
          max2 = max1;
          j2 = j1;
        }
        max1 = sum;
        j1 = j;
      } else if (sum > max2) {
        max2 = sum;
        j2 = j;
      }
    }
    if (max_sum < (max1 + max2) && (j1 != -1 && j2 != -1)) {
      max_sum = (max1 + max2);
      j3 = j1;
      j4 = j2;
    }
  }
  if (B[j3].size() == B[j4].size())
    max_count = B[j3].size() * 2;
  else
    max_count = min(B[j3].size(), B[j4].size()) * 2 + 1;
  long s1 = S[j3];
  long s2 = S[j4];
  if (B[j4].size() < B[j3].size()) swap(s1, s2);
  cout << max_sum << '\n';
  cout << max_count << '\n';
  for (long i = 0; i < max_count; i++) {
    if (i % 2) {
      cout << A[i / 2 + s1].i << " ";
    } else {
      cout << A[i / 2 + s2].i << " ";
    }
  }
  return 0;
}