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 long long n_max = 100004;
long long n, i, color, j, x;
pair<long long, pair<long long, long long> > a[n_max];
struct Cube {
  long long size, index, sum;
  Cube(void) { sum = 0; }
} K;
bool operator<(Cube a, Cube b) { return a.size > b.size; }
vector<Cube> v[n_max];
struct Cub {
  long long color, sum;
  Cub(void) { sum = 0; }
} L, Ans1, Ans2;
bool operator<(Cub a, Cub b) { return a.sum < b.sum; };
priority_queue<Cub> Q[n_max];
void check(Cub a, Cub b) {
  if (Ans1.sum + Ans2.sum < a.sum + b.sum) {
    Ans1 = a;
    Ans2 = b;
  }
}
void prnt() {
  long long sum1 = 0, sum2 = 0, i = 0, col1 = Ans1.color;
  long long col2 = Ans2.color, u = 0, k = 0;
  while (sum1 < Ans1.sum && sum2 < Ans2.sum) {
    sum1 = v[col1][i].sum;
    sum2 = v[col2][i].sum;
    u++;
    k++;
    i++;
  }
  if (sum1 < Ans1.sum) u++;
  cout << u + k << endl;
  for (i = 0; i < k; i++) {
    cout << v[col1][i].index << ' ';
    cout << v[col2][i].index << ' ';
  }
  if (u == k + 1) cout << v[col1][u - 1].index << ' ';
  cout << endl;
}
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d %d", &a[i].first, &a[i].second.first);
    a[i].second.second = i;
  }
  sort(a + 1, a + n + 1);
  for (i = 1; i <= n; i++) {
    if (a[i].first != a[i - 1].first) color++;
    K.index = a[i].second.second;
    K.size = a[i].second.first;
    v[color].push_back(K);
  }
  for (i = 1; i <= color; i++) {
    if (v[i].size() > x) x = v[i].size();
    sort(v[i].begin(), v[i].end());
    v[i][0].sum = v[i][0].size;
    for (j = 1; j < v[i].size(); j++)
      v[i][j].sum = v[i][j - 1].sum + v[i][j].size;
  }
  for (i = 1; i <= x; i++)
    for (j = 1; j <= color; j++)
      if (v[j].size() >= i) {
        L.color = j;
        L.sum = v[j][i - 1].sum;
        Q[i].push(L);
      }
  for (i = 1; i <= x; i++) {
    L = Q[i].top();
    Q[i].pop();
    if (!Q[i].empty()) check(L, Q[i].top());
    Q[i].push(L);
  }
  for (i = 2; i <= x; i++) {
    L = Q[i - 1].top();
    if (L.color == Q[i].top().color) {
      Q[i - 1].pop();
      if (!Q[i - 1].empty()) check(Q[i].top(), Q[i - 1].top());
      Q[i - 1].push(L);
    } else
      check(Q[i].top(), L);
  }
  for (i = 1; i < x; i++) {
    L = Q[i + 1].top();
    if (L.color == Q[i].top().color) {
      Q[i + 1].pop();
      if (!Q[i + 1].empty()) check(Q[i + 1].top(), Q[i].top());
      Q[i + 1].push(L);
    } else
      check(L, Q[i].top());
  }
  cout << Ans1.sum + Ans2.sum << endl;
  prnt();
}