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;
int n;
vector<vector<pair<long long, long long> > > heights;
vector<vector<long long> > sum;
vector<vector<pair<long long, long long> > > maximum;
const bool compare(const vector<pair<long long, long long> > &a,
                   const vector<pair<long long, long long> > &b) {
  return a.size() < b.size();
}
vector<vector<pair<long long, long long> > > l;
class RMQ {
 private:
  vector<int> val;
  int n;

 public:
  RMQ(int size) {
    n = 1;
    while (n < size) n <<= 1;
    val = vector<int>(2 * n, INT_MIN);
  }
  void update(int x, int a) {
    x += n - 1;
    val[x] = a;
    while (x > 0) {
      x = (x - 1) / 2;
      val[x] = max(val[x * 2 + 1], val[x * 2 + 2]);
    }
  }
  int minimum(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r == -1) r = n;
    if (r <= a || b <= l) return INT_MAX;
    if (a <= l && r <= b) {
      return val[k];
    } else {
      return max(minimum(a, b, k * 2 + 1, l, (l + r) / 2),
                 minimum(a, b, k * 2 + 2, (l + r) / 2, r));
    }
  }
};
vector<pair<long long, long long> > len;
pair<pair<long long, long long>, int> in[100001];
void show(vector<vector<long long> > &a) {
  cout << "--- debug start ---" << endl;
  for (int i = 0; i < (int)a.size(); i++) {
    for (int j = 0; j < (int)a[i].size(); j++) {
      cout << a[i][j] << " ";
    }
    cout << endl;
  }
  cout << "--- debug end ---" << endl;
}
void show(vector<vector<pair<long long, long long> > > &a) {
  cout << "--- debug start ---" << endl;
  for (int i = 0; i < (int)a.size(); i++) {
    for (int j = 0; j < (int)a[i].size(); j++) {
      cout << a[i][j].first << "," << a[i][j].second << " ";
    }
    cout << endl;
  }
  cout << "--- debug end ---" << endl;
}
int next(int v) {
  vector<pair<long long, long long> >::iterator tmp =
      lower_bound(len.begin(), len.end(), pair<long long, long long>(v, 0));
  return maximum.size() - 1;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> in[i].first.first >> in[i].first.second;
    in[i].second = i;
  }
  sort(in, in + n);
  for (int i = 0; i < n; i++) {
    if (i && in[i - 1].first.first == in[i].first.first) {
      heights.back().push_back(
          pair<long long, long long>(in[i].first.second, in[i].second));
    } else {
      vector<pair<long long, long long> > tmp;
      heights.push_back(tmp);
      heights.back().push_back(
          pair<long long, long long>(in[i].first.second, in[i].second));
    }
  }
  sort(heights.begin(), heights.end(), compare);
  for (int i = 0; i < (int)heights.size(); i++) {
    sort(heights[i].begin(), heights[i].end(),
         greater<pair<long long, long long> >());
  }
  sum = vector<vector<long long> >(heights.size());
  for (int i = 0; i < (int)heights.size(); i++) {
    sum[i] = vector<long long>(heights[i].size() + 1);
    for (int j = 0; j < (int)heights[i].size(); j++) {
      sum[i][j + 1] = sum[i][j] + heights[i][j].first;
    }
  }
  maximum = vector<vector<pair<long long, long long> > >(heights.size());
  for (int i = 0; i < (int)heights.size(); i++) {
    maximum[i] = vector<pair<long long, long long> >(heights[i].size());
  }
  for (int i = 0; i < (int)maximum[0].size(); i++) {
    maximum[0][i] = pair<long long, long long>(sum[0][i + 1], 0);
  }
  for (int i = 1; i < (int)maximum.size(); i++) {
    for (int j = 0; j < (int)maximum[i - 1].size(); j++) {
      maximum[i][j] =
          max(maximum[i - 1][j], pair<long long, long long>(sum[i][j + 1], i));
    }
    for (int j = maximum[i - 1].size(); j < maximum[i].size(); j++) {
      maximum[i][j] = pair<long long, long long>(sum[i][j + 1], i);
    }
  }
  l = vector<vector<pair<long long, long long> > >(maximum.back().size() + 1);
  for (int i = 0; i < maximum.size(); i++) {
    for (int j = 0; j < (int)maximum[i].size(); j++) {
      l[j].push_back(pair<long long, long long>(sum[i][j + 1], i));
    }
  }
  for (int i = 0; i < (int)l.size(); i++) {
    sort(l[i].begin(), l[i].end(), greater<pair<long long, long long> >());
  }
  long long ans = 0;
  int type = 0;
  for (int i = 0; i < (int)l.size(); i++) {
    if (l[i].size() > 1) {
      if (ans < l[i][0].first + l[i][1].first) {
        ans = l[i][0].first + l[i][1].first;
        type = -i - 1;
      }
    }
  }
  int back = 0;
  for (int i = 0; i < (int)maximum.size(); i++) {
    if (i && maximum[i].size() == maximum[i - 1].size()) {
      continue;
    }
    len.push_back(pair<long long, long long>(maximum[i].size(), i));
  }
  for (int i = 0; i < (int)sum.size(); i++) {
    if (maximum[i].size()) {
      if (upper_bound(len.begin(), len.end(),
                      pair<long long, long long>(maximum[i].size() + 1, -1)) ==
          len.end())
        continue;
      if (ans <
          maximum[i][maximum[i].size() - 1].first +
              maximum[next(maximum[i].size() + 1)][maximum[i].size()].first) {
        ans = maximum[i][maximum[i].size() - 1].first +
              maximum[next(maximum[i].size() + 1)][maximum[i].size()].first;
        type = i;
      }
    }
  }
  cout << ans << endl;
  if (type < 0) {
    type = type + 1;
    type *= -1;
    cout << (type + 1) * 2 << endl;
    for (int i = 0; i < (int)(type + 1) * 2; i++) {
      if (i % 2) cout << " " << heights[l[type][0].second][i / 2].second + 1;
      if (i % 2) cout << " " << heights[l[type][1].second][i / 2].second + 1;
    }
  } else {
    cout << maximum[type].size() * 2 + 1 << endl;
    int x =
        maximum[next(maximum[type].size() + 1)][maximum[type].size()].second;
    int y = maximum[type][maximum[type].size() - 1].second;
    for (int i = 0; i < maximum[type].size() * 2 + 1; i++) {
      if (i % 2 == 0) {
        cout << heights[x][i / 2].second + 1 << " ";
      } else {
        cout << heights[y][i / 2].second + 1 << " ";
      }
    }
  }
  return 0;
}