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 type {
  int size, color, idx;
  long long presum;
  type() {}
  type(int a, int b, int i) {
    color = a;
    size = b;
    idx = i;
  }
};
bool cmp(const type& a, const type& b) { return a.size > b.size; }
int main() {
  int n;
  cin >> n;
  map<int, vector<type> > converter;
  for (int i = 0; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    converter[a].push_back(type(a, b, i));
  }
  vector<vector<type> > arr;
  for (map<int, vector<type> >::iterator it = converter.begin();
       it != converter.end(); it++) {
    arr.push_back(it->second);
  }
  for (int i = 0; i < arr.size(); i++) {
    sort(arr[i].begin(), arr[i].end(), cmp);
  }
  for (int i = 0; i < arr.size(); i++) {
    arr[i][0].presum = arr[i][0].size;
    for (int j = 1; j < arr[i].size(); j++) {
      arr[i][j].presum = arr[i][j - 1].presum + arr[i][j].size;
    }
  }
  long long bestHeight = -1;
  pair<int, int> res1 = make_pair(-1, -1);
  pair<int, int> res2 = res1;
  for (int i = 0; i < arr.size(); i++) {
    if (arr[i][0].presum > bestHeight) {
      bestHeight = arr[i][0].presum;
      res1 = make_pair(i, arr[i][0].idx);
    }
  }
  for (int z = 2; z <= n; z++) {
    if (z % 2) {
      long long maxb1 = -1;
      long long maxb2 = -1;
      long long maxs1 = -1;
      long long maxs2 = -1;
      pair<int, int> b1;
      pair<int, int> b2;
      pair<int, int> s1;
      pair<int, int> s2;
      for (int i = 0; i < arr.size(); i++) {
        if (arr[i].size() >= z / 2 + 1) {
          if (arr[i][z / 2].presum >= maxb1) {
            maxb2 = maxb1;
            maxb1 = arr[i][z / 2].presum;
            b2 = b1;
            b1 = make_pair(i, arr[i][z / 2].idx);
          } else {
            if (arr[i][z / 2].presum > maxb2) {
              maxb2 = arr[i][z / 2].presum;
              b2 = make_pair(i, arr[i][z / 2].idx);
            }
          }
        }
        if (arr[i].size() >= z / 2) {
          if (arr[i][z / 2 - 1].presum >= maxs1) {
            maxs2 = maxs1;
            maxs1 = arr[i][z / 2 - 1].presum;
            s2 = s1;
            s1 = make_pair(i, arr[i][z / 2 - 1].idx);
          } else {
            if (arr[i][z / 2 - 1].presum > maxs2) {
              maxs2 = arr[i][z / 2 - 1].presum;
              s2 = make_pair(i, arr[i][z / 2 - 1].idx);
            }
          }
        }
      }
      if (maxs2 == -1) {
        break;
      }
      if (b1.first != s1.first) {
        if (maxb1 + maxs1 > bestHeight) {
          res1 = b1;
          res2 = s1;
          bestHeight = maxb1 + maxs1;
        }
      } else {
        if (maxb1 + maxs2 > bestHeight) {
          res1 = b1;
          res2 = s2;
          bestHeight = maxb1 + maxs2;
        }
        if (maxb2 + maxs1 > bestHeight) {
          res1 = b2;
          res2 = s1;
          bestHeight = maxb2 + maxs1;
        }
      }
    } else {
      long long maxb1 = -1;
      long long maxb2 = -1;
      pair<int, int> b1;
      pair<int, int> b2;
      for (int i = 0; i < arr.size(); i++) {
        if (arr[i].size() >= z / 2) {
          if (arr[i][z / 2 - 1].presum >= maxb1) {
            maxb2 = maxb1;
            maxb1 = arr[i][z / 2 - 1].presum;
            b2 = b1;
            b1 = make_pair(i, arr[i][z / 2 - 1].idx);
          } else {
            if (arr[i][z / 2 - 1].presum > maxb2) {
              maxb2 = arr[i][z / 2 - 1].presum;
              b2 = make_pair(i, arr[i][z / 2 - 1].idx);
            }
          }
        }
      }
      if (maxb1 == -1 || maxb2 == -1) {
        break;
      }
      if (maxb1 + maxb2 > bestHeight) {
        res1 = b1;
        res2 = b2;
        bestHeight = maxb1 + maxb2;
      }
    }
  }
  vector<int> answer;
  int q = 0;
  int w = 0;
  while (arr[res1.first][q].idx != res1.second) {
    answer.push_back(arr[res1.first][q].idx);
    answer.push_back(arr[res2.first][w].idx);
    q++;
    w++;
  }
  if (arr[res1.first][q].idx == res1.second) {
    answer.push_back(arr[res1.first][q].idx);
  }
  if (w < arr[res2.first].size() && arr[res2.first][w].idx == res2.second) {
    answer.push_back(arr[res2.first][w].idx);
  }
  cout << bestHeight << endl;
  cout << answer.size() << endl;
  for (int i = 0; i < answer.size(); i++) {
    cout << answer[i] + 1 << " ";
  }
  cout << endl;
  return 0;
}