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;
map<long long int, vector<long long int> > m;
map<long long int, vector<long long int> >::iterator it;
map<long long int, pair<long long int, long long int> > keep;
map<long long int, pair<long long int, long long int> > keep2;
map<long long int, pair<long long int, long long int> >::iterator pt;
map<long long int, pair<long long int, long long int> >::iterator gt;
map<pair<long long int, long long int>, vector<long long int> > idx;
map<pair<long long int, long long int>, long long int> hold;
vector<long long int> storing1;
vector<long long int> storing2;
int main() {
  long long int cce;
  long long int sumVale;
  long long int nodeVale;
  long long int n;
  long long int i;
  long long int l;
  long long int clr;
  long long int sz;
  long long int j;
  long long int val;
  long long int prev;
  long long int prevNode;
  long long int now;
  long long int nowNode;
  long long int ans;
  long long int cc, cc2;
  long long int sumVal, sumVal2;
  long long int nodeVal, nodeVal2;
  long long int ccf, ccf2;
  long long int sumValf, sumValf2;
  long long int nodeValf, nodeValf2;
  long long int color1;
  long long int color2;
  m.clear();
  keep.clear();
  keep2.clear();
  idx.clear();
  hold.clear();
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> clr >> sz;
    m[clr].push_back(sz);
    idx[pair<long long int, long long int>(clr, sz)].push_back(i);
    hold[pair<long long int, long long int>(clr, sz)]++;
  }
  for (it = m.begin(); it != m.end(); it++) {
    sort((*it).second.begin(), (*it).second.end(), greater<long long int>());
    l = (*it).second.size();
    val = 0;
    for (j = 0; j < l; j++) {
      val = val + (*it).second[j];
      pt = keep.find(j + 1);
      if (pt == keep.end())
        keep[j + 1] = pair<long long int, long long int>(val, (*it).first);
      else {
        prev = keep[j + 1].first;
        prevNode = keep[j + 1].second;
        gt = keep2.find(j + 1);
        if (gt == keep2.end()) {
          if (val > prev) {
            keep[j + 1] = pair<long long int, long long int>(val, (*it).first);
            keep2[j + 1] = pair<long long int, long long int>(prev, prevNode);
          } else
            keep2[j + 1] = pair<long long int, long long int>(val, (*it).first);
        } else {
          now = keep2[j + 1].first;
          nowNode = keep2[j + 1].second;
          if (val > prev) {
            keep[j + 1] = pair<long long int, long long int>(val, (*it).first);
            keep2[j + 1] = pair<long long int, long long int>(prev, prevNode);
          } else if (val > now) {
            keep2[j + 1] = pair<long long int, long long int>(val, (*it).first);
          }
        }
      }
    }
  }
  ans = 0;
  for (pt = keep.begin(); pt != keep.end(); pt++) {
    cc = (*pt).first;
    sumVal = (*pt).second.first;
    nodeVal = (*pt).second.second;
    cce = -1;
    sumVale = -1;
    nodeVale = -1;
    gt = keep2.find(cc);
    if (gt != keep2.end()) {
      cc2 = (*gt).first;
      sumVal2 = (*gt).second.first;
      nodeVal2 = (*gt).second.second;
      cce = cc2;
      sumVale = sumVal2;
      nodeVale = nodeVal2;
      if (sumVal + sumVal2 > ans) {
        ans = sumVal + sumVal2;
        color1 = nodeVal;
        color2 = nodeVal2;
      }
    }
    gt = keep.find(cc + 1);
    if (gt != keep.end()) {
      cc2 = (*gt).first;
      sumVal2 = (*gt).second.first;
      nodeVal2 = (*gt).second.second;
      if (nodeVal != nodeVal2) {
        if (sumVal + sumVal2 > ans) {
          ans = sumVal + sumVal2;
          color1 = nodeVal;
          color2 = nodeVal2;
        }
      } else {
        if (cce != -1 && nodeVale != nodeVal2) {
          if (sumVale + sumVal2 > ans) {
            ans = sumVale + sumVal2;
            color1 = nodeVale;
            color2 = nodeVal2;
          }
        }
        gt = keep2.find(cc + 1);
        if (gt != keep2.end()) {
          if (sumVal + (*gt).second.first > ans) {
            ans = sumVal + (*gt).second.first;
            color1 = nodeVal;
            color2 = (*gt).second.second;
          }
        }
      }
    }
  }
  long long int ll1;
  long long int ll2;
  long long int ccc = 0;
  long long int flag = 0;
  long long int toPrint;
  long long int use;
  vector<long long int> v1;
  vector<long long int> v2;
  v1 = m[color1];
  v2 = m[color2];
  ll1 = v1.size();
  ll2 = v2.size();
  cout << ans << endl;
  if (ll1 != ll2)
    cout << 2 * min(ll1, ll2) + 1 << endl;
  else
    cout << 2 * ll1 << endl;
  if (ll1 <= ll2) {
    for (i = 0; i < ll1; i++) {
      use = hold[pair<long long int, long long int>(color1, v1[i])];
      hold[pair<long long int, long long int>(color1, v1[i])]--;
      toPrint = idx[pair<long long int, long long int>(color1, v1[i])][use - 1];
      storing1.push_back(toPrint + 1);
      use = hold[pair<long long int, long long int>(color2, v2[i])];
      hold[pair<long long int, long long int>(color2, v2[i])]--;
      toPrint = idx[pair<long long int, long long int>(color2, v2[i])][use - 1];
      storing2.push_back(toPrint + 1);
    }
    if (ll1 < ll2) {
      use = hold[pair<long long int, long long int>(color2, v2[i])];
      hold[pair<long long int, long long int>(color2, v2[i])]--;
      toPrint = idx[pair<long long int, long long int>(color2, v2[i])][use - 1];
      storing2.push_back(toPrint + 1);
    }
  } else {
    for (i = 0; i < ll2; i++) {
      use = hold[pair<long long int, long long int>(color2, v2[i])];
      hold[pair<long long int, long long int>(color2, v2[i])]--;
      toPrint = idx[pair<long long int, long long int>(color2, v2[i])][use - 1];
      storing2.push_back(toPrint + 1);
      use = hold[pair<long long int, long long int>(color1, v1[i])];
      hold[pair<long long int, long long int>(color1, v1[i])]--;
      toPrint = idx[pair<long long int, long long int>(color1, v1[i])][use - 1];
      storing1.push_back(toPrint + 1);
    }
    use = hold[pair<long long int, long long int>(color1, v1[i])];
    hold[pair<long long int, long long int>(color1, v1[i])]--;
    toPrint = idx[pair<long long int, long long int>(color1, v1[i])][use - 1];
    storing1.push_back(toPrint + 1);
  }
  sort(storing1.begin(), storing1.end(), greater<long long int>());
  sort(storing2.begin(), storing2.end(), greater<long long int>());
  if (ll1 <= ll2) {
    while (1) {
      if (ccc >= ll1) break;
      if (flag == 0) {
        cout << storing2[ccc];
        flag = 1;
      } else if (flag == 1) {
        cout << " " << storing2[ccc];
      }
      if (flag == 0) {
        cout << storing1[ccc];
      } else
        cout << " " << storing1[ccc];
      ccc++;
    }
    if (ll1 < ll2) {
      cout << " " << storing2[ccc];
    }
  } else {
    ccc = 0;
    while (1) {
      if (ccc >= ll2) break;
      if (flag == 0) {
        cout << storing1[ccc];
        flag = 1;
      } else if (flag == 1) {
        cout << " " << storing1[ccc];
      }
      if (flag == 0) {
        cout << storing2[ccc];
      } else
        cout << " " << storing2[ccc];
      ccc++;
    }
    cout << " " << storing1[ccc];
  }
  cout << endl;
  return 0;
}