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 t>
ostream &operator<<(ostream &tout, const vector<t> &s) {
  tout << '[';
  for (long long i = 0; i < s.size(); i++)
    if (i + 1 == s.size())
      tout << s[i];
    else
      tout << s[i] << ',';
  tout << ']';
  return (tout);
}
template <class a, class b>
ostream &operator<<(ostream &tout, const pair<a, b> &c) {
  return (tout << '(' << c.first << ',' << c.second << ')');
}
template <class T>
struct __set__print {
  __set__print(ostream &out) : tout(out), __cnt__(0) {}
  void operator()(T x) {
    if (__cnt__ > 0) tout << ',';
    tout << x;
    ++__cnt__;
  }
  ostream &tout;
  long long __cnt__;
};
template <class T>
ostream &operator<<(ostream &tout, const set<T> &s) {
  tout << '{';
  for_each(s.begin(), s.end(), __set__print<T>(tout));
  return (tout << '}');
}
template <class T, class Q>
struct print_map {
  print_map(ostream &out) : tout(out), __cnt__(0) {}
  void operator()(const pair<T, Q> &x) {
    if (__cnt__ > 0) tout << ',';
    tout << '(' << x.first << " => " << x.second << ')';
    ++__cnt__;
  }
  ostream &tout;
  long long __cnt__;
};
template <class T, class Q>
ostream &operator<<(ostream &tout, map<T, Q> s) {
  tout << '{';
  for_each(s.begin(), s.end(), print_map<T, Q>(tout));
  return (tout << '}');
}
template <class T>
string to_string(T s) {
  stringstream tin;
  tin << s;
  string res;
  getline(tin, res);
  return (res);
}
template <class T>
vector<T> to_vector(T *s, long long n) {
  vector<T> result;
  for (long long i = 0; i < n; i++) result.push_back(s[i]);
  return (result);
}
long long n;
map<long long, long long> __cnt__;
vector<pair<long long, long long> > all;
bool df(long long ss, long long tt) {
  pair<long long, long long> s = all[ss], t = all[tt];
  if (__cnt__[s.first] != __cnt__[t.first])
    return (__cnt__[s.first] > __cnt__[t.first]);
  if (s.first != t.first) return (s.first > t.first);
  if (s.second != t.second) return (s.second > t.second);
  return (ss > tt);
}
map<long long, vector<long long> > ort;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    long long a, b;
    cin >> a >> b;
    all.push_back(pair<long long, long long>(a, b));
    __cnt__[a]++;
    ort[a].push_back(b);
  }
  vector<pair<long long, long long> > best[2];
  best[0] = vector<pair<long long, long long> >(
      n + 1, pair<long long, long long>(-1, -1));
  best[1] = vector<pair<long long, long long> >(
      n + 1, pair<long long, long long>(-1, -1));
  for (map<long long, vector<long long> >::iterator i = ort.begin();
       i != ort.end(); i++) {
    sort(i->second.begin(), i->second.end());
    reverse(i->second.begin(), i->second.end());
    long long sm = 0;
    for (long long j = 0; j < i->second.size(); j++) {
      sm += i->second[j];
      if (best[0][j] < pair<long long, long long>(sm, i->first)) {
        swap(best[0][j], best[1][j]);
        best[0][j] = pair<long long, long long>(sm, i->first);
      } else if (best[1][j] < pair<long long, long long>(sm, i->first))
        best[1][j] = pair<long long, long long>(sm, i->first);
    }
  }
  long long mx = 0;
  long long c1 = -1, c2 = -1;
  for (long long i = 0; i + 1 < best[0].size(); i++)
    for (long long a = 0; a <= 1; a++)
      for (long long b = 0; b <= 1; b++) {
        if (best[a][i].second != best[b][i].second && best[a][i].first >= 0 &&
            best[b][i].first >= 0) {
          if (mx < best[a][i].first + best[b][i].first) {
            mx = best[a][i].first + best[b][i].first;
            c1 = best[a][i].second;
            c2 = best[b][i].second;
          }
        }
        if (best[a][i + 1].second != best[b][i].second &&
            best[a][i + 1].first >= 0 && best[b][i].first >= 0) {
          if (mx < best[a][i + 1].first + best[b][i].first) {
            mx = best[a][i + 1].first + best[b][i].first;
            c1 = best[a][i + 1].second;
            c2 = best[b][i].second;
          }
        }
      }
  vector<long long> sorted;
  for (long long i = 0; i < all.size(); i++) sorted.push_back(i);
  sort(sorted.begin(), sorted.end(), df);
  vector<long long> t;
  for (long long i = 0; i < sorted.size(); i++) {
    if (all[sorted[i]].first != c1 && all[sorted[i]].first != c2) continue;
    t.push_back(sorted[i]);
  }
  sorted = t;
  vector<long long> inds;
  long long p1 = 0, p2 = sorted.size() - 1;
  while (p1 <= p2) {
    if (inds.size() % 2) {
      inds.push_back(sorted[p2]);
      p2--;
    } else {
      inds.push_back(sorted[p1]);
      p1++;
    }
  }
  vector<long long> res;
  for (long long i = 0; i < inds.size(); i++)
    if (res.size() == 0 || all[inds[i]].first != all[res.back()].first)
      res.push_back(inds[i]);
  long long ans = 0;
  for (long long i = 0; i < res.size(); i++) ans += all[res[i]].second;
  cout << ans << endl;
  cout << res.size() << endl;
  for (long long i = 0; i < res.size(); i++) cout << res[i] + 1 << ' ';
  cout << endl;
}