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;
struct cube {
  int c, s;
  int id;
  bool operator<(const cube& x) const {
    if (c == x.c) return s > x.s;
    return c < x.c;
  }
} C[100005];
struct rec {
  long long a;
  int label;
  rec() {
    a = 0LL;
    label = 0;
  }
  bool operator<(const rec& x) const { return a > x.a; }
} ans[100005][2], tmp[10];
int main(int argc, char** argv) {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d%d", &C[i].c, &C[i].s);
  for (int i = 0; i < n; ++i) C[i].id = i + 1;
  sort(C, C + n);
  int label = -1, cnt = -1;
  long long now = 0;
  for (int i = 0; i < n; ++i) {
    if (label != C[i].c) {
      label = C[i].c;
      now = C[i].s;
      cnt = 1;
    } else {
      now += C[i].s;
      cnt++;
    }
    tmp[0].a = now, tmp[0].label = label;
    tmp[1] = ans[cnt][0], tmp[2] = ans[cnt][1];
    sort(tmp, tmp + 3);
    ans[cnt][0] = tmp[0], ans[cnt][1] = tmp[1];
  }
  long long output = ans[1][0].a + ans[1][1].a;
  int color1 = ans[1][0].label, color2 = ans[1][1].label, cnt1 = 1, cnt2 = 1;
  for (int i = 1; i < n; ++i) {
    if (ans[i][0].label == 0)
      continue;
    else {
      if (ans[i][1].label != 0) {
        if (output < ans[i][1].a + ans[i][0].a) {
          output = ans[i][1].a + ans[i][0].a;
          color1 = ans[i][0].label, color2 = ans[i][1].label;
          cnt1 = cnt2 = i;
        }
        if (ans[i + 1][0].label != 0 &&
            ans[i + 1][0].label != ans[i][1].label &&
            output < ans[i][1].a + ans[i + 1][0].a) {
          output = ans[i][1].a + ans[i + 1][0].a;
          color1 = ans[i][1].label, color2 = ans[i + 1][0].label;
          cnt1 = i, cnt2 = i + 1;
        }
        if (ans[i + 1][1].label != 0 &&
            ans[i + 1][1].label != ans[i][1].label &&
            output < ans[i][1].a + ans[i + 1][1].a) {
          output = ans[i][1].a + ans[i + 1][1].a;
          color1 = ans[i][1].label, color2 = ans[i + 1][1].label;
          cnt1 = i, cnt2 = i + 1;
        }
      }
      if (ans[i + 1][0].label != 0 && ans[i + 1][0].label != ans[i][0].label) {
        if (output < ans[i][0].a + ans[i + 1][0].a) {
          output = ans[i][0].a + ans[i + 1][0].a;
          color1 = ans[i][0].label, color2 = ans[i + 1][0].label;
          cnt1 = i, cnt2 = i + 1;
        }
      }
      if (ans[i + 1][1].label != 0 && ans[i + 1][1].label != ans[i][0].label) {
        if (output < ans[i][0].a + ans[i + 1][1].a) {
          output = ans[i][0].a + ans[i + 1][1].a;
          color1 = ans[i][0].label, color2 = ans[i + 1][1].label;
          cnt1 = i, cnt2 = i + 1;
        }
      }
    }
  }
  cout << output << endl << cnt1 + cnt2 << endl;
  int b1, b2;
  for (int i = 0; i < n; ++i)
    if (C[i].c == color1) {
      b1 = i;
      break;
    }
  for (int i = 0; i < n; ++i)
    if (C[i].c == color2) {
      b2 = i;
      break;
    }
  cout << C[b2++].id;
  for (int i = 0; i < cnt1 + cnt2 - 1; ++i) {
    if (i & 1) {
      cout << " " << C[b2++].id;
    } else {
      cout << " " << C[b1++].id;
    }
  }
  cout << endl;
  return 0;
}