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 <typename T>
inline T S(T a) {
  return a * a;
}
template <typename T>
inline string tostring(T a) {
  ostringstream os("");
  os << a;
  return os.str();
}
template <typename T>
inline long long tolong(T a) {
  long long res;
  istringstream os(a);
  os >> res;
  return res;
}
template <typename T>
inline T gcd(T a, T b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
template <typename T>
inline unsigned long long bigmod(T a, T b, T m) {
  if (b == 0)
    return 1;
  else if (b % 2 == 0)
    return S(bigmod(a, b / 2, m)) % m;
  else
    return (a % m * bigmod(a, b - 1, m)) % m;
}
template <typename T>
inline vector<string> parse(T str) {
  vector<string> res;
  string s;
  istringstream os(str);
  while (os >> s) res.push_back(s);
  return res;
}
template <typename T>
inline unsigned long long dist(T A, T B) {
  unsigned long long res =
      (A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y);
  return res;
}
map<int, int> M;
struct Z {
  int h;
  int ind;
};
Z z;
vector<Z> V[100005];
vector<unsigned long long> v[100005];
bool operator<(Z A, Z B) { return A.h < B.h; }
struct P {
  int IND;
  int H;
};
bool operator<(P A, P B) { return A.H < B.H; }
P arr[100005];
int col[100005];
unsigned long long maxi[100005];
int main() {
  int C, H;
  int cnt = 1;
  int n, i, j, k, c;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    cin >> C >> z.h;
    if (!M[C]) M[C] = cnt++;
    c = M[C];
    z.ind = i;
    V[c].push_back(z);
  }
  for (i = 1; i < cnt; i++) {
    sort((V[i]).begin(), (V[i]).end());
    reverse((V[i]).begin(), (V[i]).end());
  }
  int la, lb, lc;
  unsigned long long sumab, sumbc, sumac, suma;
  for (i = 1; i < cnt; i++) {
    la = V[i].size();
    suma = 0;
    for (j = 0; j < la; j++) {
      suma += V[i][j].h;
      v[i].push_back(suma);
    }
  }
  P p;
  for (i = 1; i < cnt; i++) {
    arr[i].IND = i;
    arr[i].H = v[i].size();
  }
  sort(arr + 1, arr + cnt);
  int a = cnt - 2, b = cnt - 1;
  unsigned long long sc;
  int x, y;
  i = arr[b].IND;
  for (j = 0; j < arr[b].H; j++) {
    maxi[j] = v[i][j];
    col[j] = i;
  }
  unsigned long long ly, gy, gm = 0, lm, cu;
  for (j = cnt - 2; j >= 1; j--) {
    i = arr[j].IND;
    cu = arr[j].H;
    {
      if (maxi[cu - 1] > maxi[cu]) {
        lm = maxi[cu - 1] + v[i].back();
        ly = col[cu - 1];
      } else {
        lm = maxi[cu] + v[i].back();
        ly = col[cu];
      }
    }
    if (gm < lm) {
      gm = lm;
      x = i;
      gy = ly;
    }
    sc = 0;
    for (k = 0; k < arr[j].H; k++) {
      if (maxi[k] < sc + V[i][k].h) {
        maxi[k] = sc + V[i][k].h;
        col[k] = i;
      }
      sc += V[i][k].h;
    }
  }
  cout << gm << endl;
  int ma, mb;
  if (V[gy].size() > V[x].size())
    ma = 2 * (V[x].size()) + 1;
  else if (V[gy].size() < V[x].size())
    ma = 2 * (V[y].size()) + 1;
  else
    ma = 2 * V[x].size();
  cout << ma << endl;
  if (V[gy].size() > V[x].size()) {
    cout << V[gy][0].ind;
    for (i = 0; i < V[x].size(); i++) {
      cout << " " << V[x][i].ind << " " << V[gy][i + 1].ind;
    }
  } else if (V[gy].size() < V[x].size()) {
    cout << V[x][0].ind;
    for (i = 0; i < V[gy].size(); i++) {
      cout << " " << V[gy][i].ind << " " << V[x][i + 1].ind;
    }
  } else {
    cout << V[gy][0].ind << " " << V[x][0].ind;
    for (i = 1; i < V[x].size(); i++) {
      cout << " " << V[gy][i].ind << " " << V[x][i].ind;
    }
  }
  cout << endl;
  return 0;
}