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;
int n;
map<long int, vector<pair<long long int, int> > > pila;
long long int altezza_coppia(long int a, long int b) {
  if (pila[a].size() < pila[b].size()) swap(a, b);
  int numa = min(pila[a].size(), pila[b].size() + 1);
  int numb = pila[b].size();
  return pila[a][numa - 1].first + pila[b][numb - 1].first;
}
void migliore_coppia(int alt, long int &a, long int &b) {
  long long int best_alt = -1;
  for (map<long int, vector<pair<long long int, int> > >::iterator i =
           pila.begin();
       i != pila.end(); ++i) {
    if ((*i).second.size() < alt) continue;
    if (best_alt == -1 || (*i).second[alt - 1] > pila[best_alt][alt - 1]) {
      best_alt = (*i).first;
    }
  }
  long long int second_alt = -1;
  for (map<long int, vector<pair<long long int, int> > >::iterator i =
           pila.begin();
       i != pila.end(); ++i) {
    if ((*i).second.size() < alt) continue;
    if ((*i).first == best_alt) continue;
    if (second_alt == -1 || (*i).second[alt - 1] > pila[second_alt][alt - 1]) {
      second_alt = (*i).first;
    }
  }
  long long int best_alt_pp = -1;
  for (map<long int, vector<pair<long long int, int> > >::iterator i =
           pila.begin();
       i != pila.end(); ++i) {
    if ((*i).second.size() < alt + 1) continue;
    if (best_alt_pp == -1 || (*i).second[alt] > pila[best_alt_pp][alt]) {
      best_alt_pp = (*i).first;
    }
  }
  if (second_alt == -1 && best_alt_pp == -1) {
    a = best_alt;
    b = -1;
    return;
  }
  if (best_alt_pp == -1) {
    a = best_alt;
    b = second_alt;
    return;
  }
  if (best_alt == best_alt_pp) {
    a = best_alt_pp;
    b = second_alt;
    return;
  }
  if (pila[best_alt_pp][alt] > pila[second_alt][alt - 1]) {
    a = best_alt_pp;
    b = best_alt;
    return;
  } else {
    a = best_alt;
    b = second_alt;
    return;
  }
}
void stampa_pile(long int a, long int b) {
  if (pila[a].size() < pila[b].size()) swap(a, b);
  int numa = min(pila[a].size(), pila[b].size() + 1);
  int numb = pila[b].size();
  cout << numa + numb << "\n";
  for (int i = 0; i < min(numa, numb); ++i) {
    cout << pila[a][i].second << " ";
    cout << pila[b][i].second << " ";
  }
  if (numa > numb) cout << pila[a][numa - 1].second << " ";
  cout << "\n";
}
int main() {
  cin >> n;
  int col, lat;
  for (int i = 0; i < n; i++) {
    cin >> col >> lat;
    pila[col].push_back(make_pair(lat, i + 1));
  }
  for (map<long int, vector<pair<long long int, int> > >::iterator i =
           pila.begin();
       i != pila.end(); ++i) {
    sort((*i).second.begin(), (*i).second.end(),
         greater<pair<long long int, int> >());
    for (int j = 1; j < (*i).second.size(); ++j) {
      (*i).second[j].first += (*i).second[j - 1].first;
    }
  }
  set<long int> altezze;
  for (map<long int, vector<pair<long long int, int> > >::iterator i =
           pila.begin();
       i != pila.end(); ++i) {
    altezze.insert(-(*i).second.size());
    if ((*i).second.size() > 1) altezze.insert(-(*i).second.size() + 1);
  }
  long int a, b;
  long int aa, bb;
  long long int lmax = 0, tmp;
  for (set<long int>::iterator i = altezze.begin(); i != altezze.end(); ++i) {
    migliore_coppia(-*i, aa, bb);
    if (aa < 0 || bb < 0) continue;
    tmp = altezza_coppia(aa, bb);
    if (tmp > lmax) {
      a = aa;
      b = bb;
      lmax = tmp;
    }
  }
  cout << lmax << "\n";
  stampa_pile(a, b);
  return 0;
}