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;
const double EPS = 1e-9;
const double PI = acos(-1.0);
template <class T>
inline T sq(T x) {
  return x * x;
}
template <class T>
inline void upd_min(T &lhs, T rhs) {
  if (lhs > rhs) lhs = rhs;
}
template <class T>
inline void upd_max(T &lhs, T rhs) {
  if (lhs < rhs) lhs = rhs;
}
void upd(vector<long long> &ans, pair<long long, int> p1,
         pair<long long, int> p2, int n1, int n2) {
  if (!p1.first || !p2.first) return;
  if (p1.second == p2.second) return;
  long long ans1 = p1.first + p2.first;
  if (ans[0] < ans1) {
    ans[0] = ans1;
    ans[1] = p1.second;
    ans[2] = n1 + 1;
    ans[3] = p2.second;
    ans[4] = n2 + 1;
  }
}
void solve() {
  int n;
  scanf("%d", &n);
  map<int, vector<pair<int, int> > > m;
  for (int i = (0); i < (n); ++i) {
    int c, s;
    scanf("%d%d", &c, &s);
    m[c].push_back(make_pair(s, i + 1));
  }
  for (typeof((m).begin()) it = (m).begin(); it != (m).end(); ++it) {
    sort(it->second.rbegin(), it->second.rend());
  }
  vector<pair<long long, int> > foo(n + 1), bar(n + 1);
  for (typeof((m).begin()) it = (m).begin(); it != (m).end(); ++it) {
    long long baz = 0;
    for (int i = (0); i < (int((it->second).size())); ++i) {
      baz += it->second[i].first;
      if (baz > foo[i].first) {
        bar[i] = foo[i];
        foo[i] = make_pair(baz, it->first);
      } else if (baz > bar[i].first) {
        bar[i] = make_pair(baz, it->first);
      }
    }
  }
  vector<long long> ans(5);
  for (int i = (0); i < (n); ++i) {
    upd(ans, foo[i], bar[i], i, i);
    upd(ans, foo[i], foo[i + 1], i, i + 1);
    upd(ans, foo[i], bar[i + 1], i, i + 1);
    upd(ans, bar[i], foo[i + 1], i, i + 1);
  }
  cout << ans[0] << endl;
  cout << ans[2] + ans[4] << endl;
  for (int i = (0); i < (ans[4]); ++i) {
    cout << m[ans[3]][i].second << ' ';
    if (i < ans[2]) cout << m[ans[1]][i].second << ' ';
  }
  cout << endl;
}
int main() {
  solve();
  return 0;
}