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-8;
const double pi = acos(-1.0);
int dblcmp(double d) {
  if (fabs(d) < eps) return 0;
  return d > eps ? 1 : -1;
}
int n;
int c[111111], s[111111];
vector<pair<int, int> > a[111111];
map<int, int> v;
int b[111111];
set<pair<long long, int> > p[111111];
void up(int x, pair<long long, int> t) {
  p[x].insert(t);
  if ((int)((p[x]).size()) > 2) {
    p[x].erase(p[x].begin());
  }
}
bool cmp(const pair<int, int>& a, const pair<int, int>& b) {
  if (a.first == b.first) return a.second < b.second;
  return a.first > b.first;
}
int main() {
  int i, j, k;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d%d", &c[i], &s[i]);
    v[c[i]];
  }
  i = 0;
  for (__typeof(v.begin()) e = v.begin(); e != v.end(); ++e) {
    v[e->first] = i;
    b[i++] = e->first;
  }
  int z = i;
  for (i = 0; i < n; i++) {
    c[i] = v[c[i]];
    a[c[i]].push_back(make_pair(s[i], i + 1));
  }
  for (i = 0; i < z; i++) {
    sort(a[i].begin(), a[i].end(), cmp);
    long long sum = 0;
    for (j = 0; j < (int)((a[i]).size()); j++) {
      sum += (long long)a[i][j].first;
      up(j + 1, make_pair(sum, b[i]));
    }
  }
  long long mx = 0;
  int p1 = 0, p2 = 0;
  for (i = 2; i <= n; i++) {
    if (p[i].empty() == false && p[i - 1].empty() == false) {
      long long r;
      if (p[i].rbegin()->second == p[i - 1].rbegin()->second) {
        if ((int)((p[i - 1]).size()) == 1) continue;
        r = p[i].rbegin()->first + p[i - 1].begin()->first;
      } else {
        r = p[i].rbegin()->first + p[i - 1].rbegin()->first;
      }
      if (r > mx) {
        mx = r;
        if (p[i].rbegin()->second == p[i - 1].rbegin()->second) {
          p1 = p[i].rbegin()->second;
          p2 = p[i - 1].begin()->second;
        } else {
          p1 = p[i].rbegin()->second;
          p2 = p[i - 1].rbegin()->second;
        }
      }
    }
  }
  for (i = 1; i < n; i++) {
    if (p[i].empty() == false && p[i + 1].empty() == false) {
      long long r;
      if (p[i].rbegin()->second == p[i + 1].rbegin()->second) {
        if ((int)((p[i + 1]).size()) == 1) continue;
        r = p[i].rbegin()->first + p[i + 1].begin()->first;
      } else {
        r = p[i].rbegin()->first + p[i + 1].rbegin()->first;
      }
      if (r > mx) {
        mx = r;
        if (p[i].rbegin()->second == p[i + 1].rbegin()->second) {
          p1 = p[i].rbegin()->second;
          p2 = p[i + 1].begin()->second;
        } else {
          p1 = p[i].rbegin()->second;
          p2 = p[i + 1].rbegin()->second;
        }
      }
    }
  }
  for (i = 1; i <= n; i++) {
    if ((int)((p[i]).size()) >= 2) {
      long long r = p[i].rbegin()->first + p[i].begin()->first;
      if (r > mx) {
        mx = r;
        p1 = p[i].rbegin()->second;
        p2 = p[i].begin()->second;
      }
    }
  }
  cout << mx << endl;
  p1 = v[p1];
  p2 = v[p2];
  int s1 = (int)((a[p1]).size()), s2 = (int)((a[p2]).size());
  if (s1 > s2) {
    printf("%d\n", s2 * 2 + 1);
    j = 0, k = 0;
    for (i = 0; i < s2 * 2 + 1; i++) {
      if (i & 1) {
        printf("%d\n", a[p2][k].second);
        k++;
      } else {
        printf("%d\n", a[p1][j].second);
        j++;
      }
    }
  } else if (s1 == s2) {
    printf("%d\n", s2 * 2);
    j = 0, k = 0;
    for (i = 0; i < s2 * 2; i++) {
      if (i & 1) {
        printf("%d\n", a[p2][k].second);
        k++;
      } else {
        printf("%d\n", a[p1][j].second);
        j++;
      }
    }
  } else {
    printf("%d\n", s1 * 2 + 1);
    for (i = 0; i < s1 * 2 + 1; i++) {
      if (i & 1) {
        printf("%d\n", a[p1][k].second);
        k++;
      } else {
        printf("%d\n", a[p2][j].second);
        j++;
      }
    }
  }
  return 0;
}