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 int N = 100005;
int buf[N], cnt;
int height[N];
inline int pos(int x) { return lower_bound(buf, buf + cnt, x) - buf; }
vector<pair<long long, int> > G[N];
struct Node {
  long long val;
  int cr, num;
  Node() {}
  Node(long long _a, int _b, int _c) : val(_a), cr(_b), num(_c) {}
};
struct Point {
  int c, s, id;
  bool operator<(const Point &p) const { return s > p.s; }
} PP[N];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &PP[i].c, &PP[i].s);
    buf[cnt++] = PP[i].c;
    PP[i].id = i + 1;
  }
  sort(PP, PP + n);
  sort(buf, buf + cnt);
  cnt = unique(buf, buf + cnt) - buf;
  for (int i = 0; i < n; i++) {
    G[pos(PP[i].c)].push_back(make_pair(PP[i].s, PP[i].id));
  }
  int ch = 0;
  for (int i = 0; i < cnt; i++) {
    for (int j = 1; j < G[i].size(); j++) {
      G[i][j].first += G[i][j - 1].first;
    }
    height[ch++] = G[i].size();
  }
  sort(height, height + ch);
  ch = unique(height, height + ch) - height;
  long long ret = 0;
  pair<int, int> t1, t2;
  for (int i = 0; i < ch; i++) {
    int cur_h = height[i];
    Node tmp1(-1, -1, -1);
    Node tmp2(-1, -1, -1);
    for (int j = 0; j < cnt; j++) {
      if (G[j].size() < cur_h) continue;
      int n_h = min((int)G[j].size() - 1, cur_h);
      if (G[j][n_h].first > tmp1.val) {
        tmp2.val = tmp1.val, tmp2.cr = tmp1.cr, tmp2.num = tmp1.num;
        tmp1.val = G[j][n_h].first;
        tmp1.cr = j;
        tmp1.num = n_h;
      } else if (G[j][n_h].first > tmp2.val) {
        tmp2.val = G[j][n_h].first;
        tmp2.cr = j;
        tmp2.num = n_h;
      }
    }
    if (tmp2.val == -1) continue;
    if (tmp1.val + tmp2.val > ret) {
      ret = tmp1.val + tmp2.val;
      t1.first = tmp1.cr, t1.second = tmp1.num;
      t2.first = tmp2.cr, t2.second = tmp2.num;
    }
  }
  cout << ret << endl;
  vector<int> v1, v2;
  for (int i = 0; i <= t1.second; i++) v1.push_back(G[t1.first][i].second);
  for (int i = 0; i <= t2.second; i++) v2.push_back(G[t2.first][i].second);
  int mm = min(v1.size(), v2.size());
  printf("%d\n", v1.size() + v2.size());
  if (v1.size() > v2.size()) {
    for (int i = 0; i < v2.size(); i++) printf("%d %d ", v1[i], v2[i]);
    printf("%d", v1.back());
  } else {
    for (int i = 0; i < v1.size(); i++) printf("%d %d ", v2[i], v1[i]);
    if (v2.size() > v1.size()) printf("%d", v2.back());
  }
  return 0;
}