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 Cube {
  int col, siz, id;
  Cube() {}
  Cube(int _col, int _siz, int _id) {
    col = _col;
    siz = _siz;
    id = _id;
  }
  friend bool operator<(const Cube& a, const Cube& b) {
    if (a.col == b.col) return a.siz < b.siz;
    return a.col < b.col;
  }
};
struct C {
  int siz, id;
  C() {}
  C(int _siz, int _id) {
    siz = _siz;
    id = _id;
  }
};
int n;
vector<Cube> cube;
vector<C> c[100000];
vector<pair<int, int> > tmp;
int totc;
long long sum[100000];
long long geth(int p, int t, int nowt) {
  if (t == nowt) return sum[p];
  if (c[p].size() < nowt) return sum[p];
  return sum[p] - c[p][nowt - 1].siz;
}
long long ans;
int c0, c1, u0, u1;
void check(int p0, int t0, int p1, int t1) {
  long long h0, h1;
  int nowt = max(t0, t1);
  h0 = geth(p0, t0, nowt);
  h1 = geth(p1, t1, nowt);
  if (ans < h0 + h1) {
    ans = h0 + h1;
    c0 = p0;
    c1 = p1;
    u0 = t0;
    u1 = t1;
  }
}
int main() {
  while (scanf("%d", &n) != EOF) {
    cube.clear();
    for (int i = 0; i < n; i++) {
      int c, s;
      scanf("%d%d", &c, &s);
      cube.push_back(Cube(c, s, i));
    }
    sort(cube.begin(), cube.end());
    totc = 1;
    c[totc - 1].clear();
    c[totc - 1].push_back(C(cube[0].siz, cube[0].id));
    for (int i = 1; i < n; i++)
      if (cube[i].col == cube[i - 1].col)
        c[totc - 1].push_back(C(cube[i].siz, cube[i].id));
      else {
        c[totc].clear();
        c[totc++].push_back(C(cube[i].siz, cube[i].id));
      }
    int maxh = 0;
    tmp.clear();
    for (int i = 0; i < totc; i++) {
      maxh = max(maxh, (int)c[i].size());
      reverse(c[i].begin(), c[i].end());
      sum[i] = 0;
      tmp.push_back(make_pair(c[i].size(), i));
    }
    sort(tmp.begin(), tmp.end());
    int op = 0;
    int pmax0, pmax1;
    pmax0 = pmax1 = -1;
    ans = 0;
    for (int i = 1; i <= maxh; i++) {
      int max0, max1;
      max0 = max1 = -1;
      for (; tmp[op].first < i; op++)
        ;
      for (int jj = op; jj < tmp.size(); jj++) {
        int j = tmp[jj].second;
        sum[j] += c[j][i - 1].siz;
        if (max0 == -1 || sum[j] >= sum[max0]) {
          max1 = max0;
          max0 = j;
        } else if (max1 == -1 || sum[j] > sum[max1])
          max1 = j;
      }
      if (max0 != pmax0 && pmax0 != -1) check(max0, i, pmax0, i - 1);
      if (max0 != pmax1 && pmax1 != -1) check(max0, i, pmax1, i - 1);
      if (max1 != pmax0 && pmax0 != -1) check(max1, i, pmax0, i - 1);
      if (max1 != pmax1 && pmax1 != -1) check(max1, i, pmax1, i - 1);
      if (max1 != -1) check(max0, i, max1, i);
      pmax0 = max0;
      pmax1 = max1;
    }
    cout << ans << endl;
    printf("%d\n", u0 + u1);
    for (int i = 0; i < u0; i++) {
      printf("%d ", c[c0][i].id + 1);
      if (i < u1) printf("%d ", c[c1][i].id + 1);
    }
    printf("\n");
  }
  return 0;
}