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;
template <class T1>
void deb(T1 e1) {
  cout << e1 << endl;
}
template <class T1, class T2>
void deb(T1 e1, T2 e2) {
  cout << e1 << " " << e2 << endl;
}
template <class T1, class T2, class T3>
void deb(T1 e1, T2 e2, T3 e3) {
  cout << e1 << " " << e2 << " " << e3 << endl;
}
template <class T1, class T2, class T3, class T4>
void deb(T1 e1, T2 e2, T3 e3, T4 e4) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << endl;
}
template <class T1, class T2, class T3, class T4, class T5>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << endl;
}
template <class T1, class T2, class T3, class T4, class T5, class T6>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << " " << e6
       << endl;
}
int X[] = {0, 0, 1, 0, 0, -1};
int Y[] = {0, 1, 0, 0, -1, 0};
int Z[] = {1, 0, 0, -1, 0, 0};
struct node {
  long long c, s;
  node() {}
  node(long long c, long long s) : c(c), s(s) {}
  bool operator<(const node& p) const { return s > p.s; }
};
struct data {
  long long x, val;
  data() {}
  data(long long x, long long val) : x(x), val(val) {}
  bool operator<(const data& p) const { return x > p.x; }
};
data a[3][100004];
long long b[100006];
vector<node> v[100005];
map<long long, long long> mp;
int main() {
  long long i, j, k, l = 1, x, y, z, t, m, n;
  cin >> n;
  for (i = 1; i <= n; i++) {
    scanf("%lld %lld", &x, &y);
    if (!mp[x]) mp[x] = l++;
    v[mp[x]].push_back(node(i, y));
  }
  for (i = 1; i < l; i++) sort(v[i].begin(), v[i].end());
  memset(a, 0, sizeof(a));
  for (i = 1; i < l; i++) {
    m = 1;
    x = 0;
    for (j = 0; j < v[i].size(); j++) {
      y = v[i][j].s;
      x += y;
      if (a[0][m].val < x) {
        a[1][m].val = a[0][m].val;
        a[1][m].x = a[0][m].x;
        a[0][m].val = x;
        a[0][m].x = i;
      } else if (a[1][m].val < x) {
        a[1][m].val = x;
        a[1][m].x = i;
      }
      m++;
    }
    b[i] = x;
  }
  long long p, q, w = 0, p1, q1;
  for (i = 1; i < l; i++) {
    x = v[i].size();
    z = b[i];
    if (a[0][x].x != i) {
      if (a[0][x].val != 0) {
        z += a[0][x].val;
        if (w < z) {
          w = z;
          p = i;
          p1 = x;
          q = a[0][x].x;
          q1 = x;
        }
      }
    } else {
      if (a[1][x].val != 0) {
        z += a[1][x].val;
        if (w < z) {
          w = z;
          p = i;
          p1 = x;
          q = a[1][x].x;
          q1 = x;
        }
      }
    }
    z = b[i];
    if (a[0][x + 1].x != i) {
      if (a[0][x + 1].val != 0) {
        z += a[0][x + 1].val;
        if (w < z) {
          w = z;
          p = i;
          q = a[0][x + 1].x;
          p1 = x;
          q1 = x + 1;
        }
      }
    } else {
      if (a[1][x + 1].val != 0) {
        z += a[1][x + 1].val;
        if (w < z) {
          w = z;
          p = i;
          q = a[1][x + 1].x;
          p1 = x;
          q1 = x + 1;
        }
      }
    }
  }
  vector<data> vec1, vec2;
  for (i = 0; i < p1; i++) {
    vec1.push_back(data(v[p][i].c, v[p][i].s));
  }
  for (i = 0; i < q1; i++) {
    vec2.push_back(data(v[q][i].c, v[q][i].s));
  }
  sort(vec1.begin(), vec1.end());
  sort(vec2.begin(), vec2.end());
  deb(w);
  deb(vec1.size() + vec2.size());
  if (vec1.size() > vec2.size())
    t = 1;
  else
    t = 0;
  j = 0, k = 0;
  for (i = 0; i < vec1.size() + vec2.size(); i++) {
    if (i % 2 == 0) {
      if (t)
        printf("%lld ", vec1[j++]);
      else
        printf("%lld ", vec2[k++]);
    }
    if (i % 2 == 1) {
      if (t)
        printf("%lld ", vec2[k++]);
      else
        printf("%lld ", vec1[j++]);
    }
  }
  return 0;
}