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 comp {
  bool operator()(const vector<int>& lhs, const vector<int>& rhs) const {
    return lhs.size() > rhs.size();
  }
};
struct comps {
  bool operator()(const string& lhs, const string& rhs) const {
    return lhs > rhs;
  }
};
bool ff(pair<int, int> a, pair<int, int> b) { return a.first < b.first; }
double dis(double x1, double y1, double x2, double y2) {
  return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
}
int gcd(long long unsigned int a, long long unsigned int b) {
  return (b == 0) ? a : gcd(b, a % b);
}
int comb(int a, int b) {
  if (a == 0) return 1;
  if (a < b) return 1;
  if (a == b) return 1;
  if (b == 1) return a;
  if (b == 0) return 1;
  long long unsigned int aa = 1, bb = 1;
  for (int i = b; i > 0; i--, a--) {
    aa *= a;
    bb *= i;
    int gc = gcd(aa, bb);
    if (gc > 1) {
      aa /= gc;
      bb /= gc;
    }
  }
  return aa % 1000000007;
}
bool isprime(long long unsigned int n) {
  for (int i = 2; i <= sqrt(n); i++)
    if (n % i == 0) return false;
  return true;
}
int main() {
  int n;
  long long int maxx = 0;
  map<int, vector<pair<long long int, long long int> > > mm;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    long long int a, b;
    cin >> a;
    cin >> b;
    mm[a].push_back(make_pair(b, i + 1));
  }
  for (map<int, vector<pair<long long int, long long int> > >::iterator it =
           mm.begin();
       it != mm.end(); it++) {
    sort((it->second).begin(), (it->second).end());
    reverse((it->second).begin(), (it->second).end());
    for (int i = 1; i < (it->second).size(); i++)
      (it->second)[i].first += (it->second)[i - 1].first;
  }
  int maxpos = 0;
  int mxcolor;
  for (map<int, vector<pair<long long int, long long int> > >::iterator it =
           mm.begin();
       it != mm.end(); it++) {
    maxpos = max(maxpos, (int)(it->second).size());
    if (maxpos == (it->second).size()) mxcolor = it->first;
  }
  int mxpos2 = 0;
  for (map<int, vector<pair<long long int, long long int> > >::iterator it =
           mm.begin();
       it != mm.end(); it++) {
    if (it->first == mxcolor) continue;
    mxpos2 = max(mxpos2, (int)(it->second).size());
  }
  maxpos += mxpos2;
  long long int mx[100005];
  bool f[100005] = {false};
  pair<int, int> p[100005];
  for (int i = 2; i <= maxpos; i++) {
    mx[i] = 0;
    int color;
    long long int mxx = 0;
    if (i % 2 == 0) {
      for (map<int, vector<pair<long long int, long long int> > >::iterator it =
               mm.begin();
           it != mm.end(); it++) {
        if ((it->second).size() < i / 2) continue;
        mx[i] = max(mx[i], (it->second)[i / 2 - 1].first);
        if (mx[i] == (it->second)[i / 2 - 1].first) {
          color = it->first;
          p[i].first = it->first;
        }
      }
      for (map<int, vector<pair<long long int, long long int> > >::iterator it =
               mm.begin();
           it != mm.end(); it++) {
        if (it->first == color) continue;
        if ((it->second).size() < i / 2) continue;
        mxx = max(mxx, (it->second)[i / 2 - 1].first);
        if (mxx == (it->second)[i / 2 - 1].first) p[i].second = it->first;
      }
      mx[i] += mxx;
    } else {
      for (map<int, vector<pair<long long int, long long int> > >::iterator it =
               mm.begin();
           it != mm.end(); it++) {
        if ((it->second).size() < i / 2) continue;
        mx[i] = max(mx[i], (it->second)[i / 2 - 1].first);
        if (mx[i] == (it->second)[i / 2 - 1].first) {
          color = it->first;
          p[i].first = it->first;
        }
      }
      for (map<int, vector<pair<long long int, long long int> > >::iterator it =
               mm.begin();
           it != mm.end(); it++) {
        if (it->first == color) continue;
        if ((it->second).size() < i / 2 + 1) continue;
        mxx = max(mxx, (it->second)[i / 2].first);
        if (mxx == (it->second)[i / 2].first) p[i].second = it->first;
      }
      mx[i] += mxx;
      long long int mmxx = 0, mmxxx = 0;
      int pp;
      int ppp;
      for (map<int, vector<pair<long long int, long long int> > >::iterator it =
               mm.begin();
           it != mm.end(); it++) {
        if ((it->second).size() < i / 2 + 1) continue;
        mmxx = max(mmxx, (it->second)[i / 2].first);
        if (mmxx == (it->second)[i / 2].first) {
          color = it->first;
          pp = it->first;
        }
      }
      for (map<int, vector<pair<long long int, long long int> > >::iterator it =
               mm.begin();
           it != mm.end(); it++) {
        if (it->first == color) continue;
        if ((it->second).size() < i / 2) continue;
        mmxxx = max(mmxxx, (it->second)[i / 2 - 1].first);
        if (mmxxx == (it->second)[i / 2 - 1].first) ppp = it->first;
      }
      if (mmxxx + mmxx > mx[i]) {
        mx[i] = mmxx + mmxxx;
        p[i].first = pp;
        p[i].second = ppp;
        f[i] = true;
      }
    }
  }
  long long int totalmax = 0;
  int c1, c2;
  int index1, index2;
  for (int i = 2; i <= maxpos; i++) {
    totalmax = max(mx[i], totalmax);
    if (totalmax == mx[i]) {
      c1 = p[i].first;
      c2 = p[i].second;
      if (i % 2) {
        if (!f[i]) {
          index1 = i / 2;
          index2 = i / 2 + 1;
        } else {
          index1 = i / 2 + 1;
          index2 = i / 2;
        }
      } else {
        index1 = index2 = i / 2;
      }
    }
  }
  cout << totalmax << endl << index1 + index2 << endl;
  if (index1 == index2)
    for (int i = 0; i < index1; i++)
      cout << mm[c1][i].second << " " << mm[c2][i].second << " ";
  else if (index1 > index2) {
    for (int i = 0; i < index2; i++)
      cout << mm[c1][i].second << " " << mm[c2][i].second << " ";
    cout << mm[c1][index2].second;
  } else if (index2 > index1) {
    for (int i = 0; i < index1; i++)
      cout << mm[c2][i].second << " " << mm[c1][i].second << " ";
    cout << mm[c2][index1].second;
  }
  return 0;
}