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>
namespace {
int n;
struct elem {
  int id;
  int c;
  int s;
  bool operator<(const elem& e) const {
    return s < e.s || (s == e.s && (c < e.c || (c == e.c && id < e.id)));
  }
} mas[100111];
struct elem2 {
  unsigned long long size;
  elem2* perent;
  elem* e;
  int len;
  elem2(unsigned long long s, elem2* per, elem* e_)
      : size(s), perent(per), e(e_), len((per ? per->len : 0) + 1) {}
} * arr[100111];
struct comp {
  bool operator()(const elem2* a, const elem2* b) const {
    if (a->len != b->len) return a->len < b->len;
    if (a->size != b->size) return a->size < b->size;
    if (a->perent != b->perent) return a->perent < b->perent;
    return a->e < b->e;
  }
};
std::map<int, elem2*> colors;
std::map<int, elem2*>::iterator it;
}  // namespace
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &mas[i].c, &mas[i].s);
    mas[i].id = i + 1;
  }
  std::sort(&mas[0], &mas[n]);
  for (int i = n - 1; i >= 0; --i) {
    it = colors.find(mas[i].c);
    if (it == colors.end()) {
      arr[i] = new elem2(mas[i].s, NULL, &mas[i]);
      colors[mas[i].c] = arr[i];
    } else {
      arr[i] = new elem2((unsigned long long)mas[i].s + it->second->size,
                         it->second, &mas[i]);
      it->second = arr[i];
    }
  }
  std::sort(&arr[0], &arr[n], comp());
  int last = 0, last1 = 0;
  unsigned long long max = 0;
  elem2 *good1 = NULL, *good2 = arr[last];
  for (int i = last + 1; i < n; ++i) {
    if (arr[i]->len <= arr[last]->len + 1 &&
        arr[i]->size + arr[last]->size > max) {
      good1 = arr[last];
      good2 = arr[i];
      max = good1->size + good2->size;
    }
    if (i + 1 < n && arr[i]->e->c != arr[i + 1]->e->c) last = i;
  }
  for (int i = last1 + 1; i < n; ++i) {
    if (arr[i]->len <= arr[last1]->len + 1 &&
        arr[i]->size + arr[last1]->size > max &&
        arr[i]->e->c != arr[last1]->e->c) {
      good1 = arr[last1];
      good2 = arr[i];
      max = good1->size + good2->size;
    }
    if (last1 > 0 && arr[i]->len <= arr[last1 - 1]->len + 1 &&
        arr[i]->size + arr[last1 - 1]->size > max &&
        arr[i]->e->c != arr[last1 - 1]->e->c) {
      good1 = arr[last1 - 1];
      good2 = arr[i];
      max = good1->size + good2->size;
    }
    if (i + 1 < n && arr[i]->len != arr[i + 1]->len) last1 = i;
  }
  std::cout << good1->size + good2->size << std::endl;
  std::cout << good1->len + good2->len << std::endl;
  while (good1) {
    std::cout << good2->e->id << " " << good1->e->id << " ";
    good2 = good2->perent;
    good1 = good1->perent;
  }
  if (good2) {
    std::cout << good2->e->id;
  }
  return 0;
}