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;
vector<pair<long long, long long> > V[100003];
pair<long long, long long> all[100003][2];
long long cnt[100003][2];
map<int, int> FT;
int TF[100003], N;
int add(int i) {
  if (FT.find(i) != FT.end()) return FT[i];
  int sz = FT.size();
  FT[i] = sz;
  TF[sz] = i;
  return sz;
}
vector<pair<long long, long long> > tmp(3), w(4);
void add1(pair<long long, long long> p, int idx) {
  tmp[0] = (all[idx][0]);
  tmp[1] = (all[idx][1]);
  tmp[2] = (p);
  sort(tmp.rbegin(), tmp.rend());
  all[idx][0] = tmp[0];
  all[idx][1] = tmp[1];
}
void make(long long &mx,
          pair<pair<long long, long long>, pair<long long, long long> > &R,
          int id) {
  w[0] = all[id][0];
  w[1] = all[id][1];
  w[2] = all[id + 1][0];
  w[3] = all[id + 1][1];
  for (int i = 0; i < 4; ++i) {
    if (w[i].first == -1) continue;
    for (int j = i + 1; j < 4; ++j) {
      if (w[j].first == -1) continue;
      if (w[i].first + w[j].first > mx && w[i].second != w[j].second) {
        mx = w[i].first + w[j].first;
        R = make_pair(make_pair(w[i].second, (i <= 1) ? id : id + 1),
                      make_pair(w[j].second, (j <= 1) ? id : id + 1));
      }
    }
  }
}
int main() {
  memset(cnt, 0, sizeof(cnt));
  FT.clear();
  for (int i = 0; i < 100003; ++i) {
    all[i][0] = make_pair(-1, -1), all[i][1] = make_pair(-1, -1);
    V[i].clear();
  }
  int c, s;
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) {
    scanf("%d%d", &c, &s);
    V[add(c)].push_back(make_pair(s, i));
  }
  int SZ = FT.size();
  for (int i = 0; i < SZ; ++i) {
    sort(V[i].rbegin(), V[i].rend());
    long long sum = 0;
    for (int j = 0; j < (int)V[i].size(); ++j) {
      sum += V[i][j].first;
      add1(make_pair(sum, TF[i]), j + 1);
    }
  }
  long long mx = -1;
  pair<pair<long long, long long>, pair<long long, long long> > R;
  for (int i = 0; i < 100003 - 1; ++i) {
    make(mx, R, i);
  }
  cout << mx << endl;
  long long idx1 = FT[R.first.first];
  long long idx2 = FT[R.second.first];
  long long N1 = R.first.second, N2 = R.second.second;
  sort(V[idx1].rbegin(), V[idx1].rend());
  sort(V[idx2].rbegin(), V[idx2].rend());
  vector<long long> P;
  for (int i = 0; i < min(N1, N2); ++i) {
    if (N1 >= N2) {
      P.push_back(V[idx1][i].second + 1);
      P.push_back(V[idx2][i].second + 1);
    } else {
      P.push_back(V[idx2][i].second + 1);
      P.push_back(V[idx1][i].second + 1);
    }
  }
  long long mn = min(N1, N2);
  if (N1 - mn > 0) {
    P.push_back(V[idx1][mn].second + 1);
  } else if (N2 - mn > 0) {
    P.push_back(V[idx2][mn].second + 1);
  }
  cout << P.size() << endl;
  string st = "";
  for (int i = 0; i < (int)P.size(); ++i) cout << st << P[i], st = " ";
  cout << endl;
}