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;
long long* highest;
long long* secondHighest;
int* highNum;
int* secondNum;
class Cube {
 public:
  int size;
  int id;
  Cube() {}
  Cube(int intoSize, int intoId) {
    size = intoSize;
    id = intoId;
  }
  bool operator<(Cube comp) const { return size < comp.size; }
};
class Colour {
 public:
  priority_queue<Cube> cubeQueue;
  Cube* cubeArray;
  long long* cuml;
  Colour* next;
  int number;
  int cubeNum;
  Colour() {}
  Colour(int intoNumber) {
    number = intoNumber;
    next = NULL;
  }
  void add(Cube cube) { cubeQueue.push(cube); }
  void org() {
    cubeNum = cubeQueue.size();
    cubeArray = new Cube[cubeNum];
    cuml = new long long[cubeNum + 1];
    cuml[0] = 0;
    for (int i = 1; i <= cubeNum; i++) {
      cubeArray[i - 1] = cubeQueue.top();
      cuml[i] = cuml[i - 1] + cubeArray[i - 1].size;
      if (cuml[i] > highest[i]) {
        secondHighest[i] = highest[i];
        secondNum[i] = highNum[i];
        highest[i] = cuml[i];
        highNum[i] = number;
      } else {
        if (cuml[i] > secondHighest[i]) {
          secondHighest[i] = cuml[i];
          secondNum[i] = number;
        }
      }
      cubeQueue.pop();
    }
  }
};
class Hash {
 public:
  Colour** colArray;
  Hash() {
    colArray = new Colour*[75000];
    for (int i = 0; i < 75000; i++) colArray[i] = NULL;
  }
  Colour* get(int number) {
    Colour* current = colArray[number % 75000];
    while (current != NULL) {
      if (current->number == number) return current;
      current = current->next;
    }
    return NULL;
  }
  void add(Colour* col) {
    col->next = colArray[col->number % 75000];
    colArray[col->number % 75000] = col;
  }
  void orgAll() {
    for (int i = 0; i < 75000; i++) {
      Colour* current = colArray[i];
      while (current != NULL) {
        current->org();
        current = current->next;
      }
    }
  }
};
long long tallest(int first, int second) {
  if (first == second) {
    if (highest[first] == -1 || secondHighest[second] == -1)
      return -1;
    else
      return highest[first] + secondHighest[second];
  } else {
    if (highNum[first] == highNum[second]) {
      if (highest[first] == -1 || secondHighest[second] == -1)
        return -1;
      else
        return highest[first] + secondHighest[second];
    } else {
      if (highest[first] == -1 || highest[second] == -1)
        return -1;
      else
        return highest[first] + highest[second];
    }
  }
}
int main() {
  int cubeNum, i;
  cin >> cubeNum;
  highest = new long long[cubeNum + 1];
  secondHighest = new long long[cubeNum + 1];
  highNum = new int[cubeNum + 1];
  secondNum = new int[cubeNum + 1];
  highest[0] = 0;
  secondHighest[0] = 0;
  highNum[0] = 0;
  secondNum[0] = 0;
  for (i = 1; i <= cubeNum; i++) {
    highest[i] = -1;
    secondHighest[i] = -1;
  }
  Hash h;
  for (i = 0; i < cubeNum; i++) {
    int colour, size;
    cin >> colour >> size;
    Colour* col = h.get(colour);
    if (col == NULL) {
      col = new Colour(colour);
      h.add(col);
    }
    col->add(*new Cube(size, i + 1));
  }
  h.orgAll();
  long long best = 0;
  int bestNum1, bestNum2, bestHeight1, bestHeight2;
  for (i = 1; i <= cubeNum; i++) {
    long long result = tallest(i, i - 1);
    if (result > best) {
      best = result;
      bestNum1 = highNum[i];
      if (highNum[i] != highNum[i - 1])
        bestNum2 = highNum[i - 1];
      else
        bestNum2 = secondNum[i - 1];
      bestHeight1 = i;
      bestHeight2 = i - 1;
    }
    result = tallest(i, i);
    if (result > best) {
      best = result;
      bestNum1 = highNum[i];
      bestNum2 = secondNum[i];
      bestHeight1 = i;
      bestHeight2 = i;
    }
    result = tallest(i, i + 1);
    if (result > best) {
      best = result;
      bestNum1 = highNum[i];
      if (highNum[i] != highNum[i + 1])
        bestNum2 = highNum[i + 1];
      else
        bestNum2 = secondNum[i + 1];
      bestHeight1 = i;
      bestHeight2 = i + 1;
    }
  }
  int shortest = bestHeight1 < bestHeight2 ? bestHeight1 : bestHeight2;
  int shortestNum, tallNum;
  if (bestHeight1 < bestHeight2) {
    shortestNum = bestNum1;
    tallNum = bestNum2;
  } else {
    shortestNum = bestNum2;
    tallNum = bestNum1;
  }
  int tall = bestHeight1 > bestHeight2 ? bestHeight1 : bestHeight2;
  Colour* colour1 = h.get(tallNum);
  Colour* colour2 = h.get(shortestNum);
  cout << best << endl;
  cout << (bestHeight1 + bestHeight2) << endl;
  for (i = 0; i < shortest; i++) {
    cout << colour1->cubeArray[i].id << " ";
    cout << colour2->cubeArray[i].id << " ";
  }
  if (i < tall) cout << colour1->cubeArray[i].id << " ";
  cout << endl;
  return 0;
}