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;
long long int max(long long int a, long long int b) {
  if (a > b)
    return a;
  else
    return b;
}
long long int min(long long int a, long long int b) {
  if (a < b)
    return a;
  else
    return b;
}
const int dx[4] = {-1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
int XX[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int YY[] = {-1, 0, 1, -1, 1, -1, 0, 1};
vector<pair<long long int, long long int> > vec[100005];
set<pair<long long int, long long int> > vec3[100005];
long long int arr4[100005] = {0};
long long int arr5[100005] = {0};
vector<pair<long long int, long long int> > vec2;
void convert(long long int arr[], long long int n) {
  long long int temp[n];
  memcpy(temp, arr, n * sizeof(long long int));
  sort(temp, temp + n);
  unordered_map<long long int, long long int> umap;
  long long int val = 1;
  for (long long int i = 0; i < n; i++) umap[temp[i]] = val++;
  for (long long int i = 0; i < n; i++) arr[i] = umap[arr[i]];
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  long long int n, i, j, x, k, y, m, w, h, c, s;
  cin >> n;
  long long int arr[n];
  for (i = 0; i < n; i++) {
    cin >> c >> s;
    vec2.push_back(make_pair(c, s));
    arr[i] = c;
  }
  convert(arr, n);
  for (i = 0; i < n; i++) {
    vec2[i].first = arr[i];
  }
  for (i = 0; i < n; i++) {
    long long int ind = vec2[i].first;
    long long int val = vec2[i].second;
    vec[ind].push_back(make_pair(val, i));
  }
  for (i = 1; i <= n; i++) {
    if (vec[i].size() != 0) {
      sort(vec[i].begin(), vec[i].end());
      reverse(vec[i].begin(), vec[i].end());
      long long int sum = 0;
      for (j = 0; j < vec[i].size(); j++) {
        sum += vec[i][j].first;
        vec3[j + 1].insert(make_pair(sum, i));
      }
    }
  }
  long long int ans = 0, ind1 = -1, ind2 = -1;
  for (i = n + 2; i >= 1; i--) {
    if (vec3[i].size() >= 2) {
      pair<long long int, long long int> pa1 = *(vec3[i].rbegin());
      vec3[i].erase(pa1);
      pair<long long int, long long int> pa2 = *(vec3[i].rbegin());
      vec3[i].erase(pa2);
      if (pa1.first + pa2.first > ans) {
        ans = pa1.first + pa2.first;
        ind1 = pa1.second;
        ind2 = pa2.second;
      }
      vec3[i].insert(pa1);
      vec3[i].insert(pa2);
    }
    if (vec3[i].size() >= 1 && vec3[i + 1].size() >= 1) {
      pair<long long int, long long int> pa1 = *(vec3[i].rbegin());
      pair<long long int, long long int> pa2 = *(vec3[i + 1].rbegin());
      if (pa1.second != pa2.second) {
        if (pa1.first + pa2.first > ans) {
          ans = pa1.first + pa2.first;
          ind1 = pa1.second;
          ind2 = pa2.second;
        }
      } else {
        if (vec3[i].size() >= 2) {
          vec3[i].erase(pa1);
          pair<long long int, long long int> pa3 = *(vec3[i].rbegin());
          if (pa3.first + pa2.first > ans) {
            ans = pa3.first + pa2.first;
            ind1 = pa3.second;
            ind2 = pa2.second;
          }
          vec3[i].insert(pa1);
        }
        if (vec3[i + 1].size() >= 2) {
          vec3[i + 1].erase(pa2);
          pair<long long int, long long int> pa3 = *(vec3[i + 1].rbegin());
          if (pa3.first + pa1.first > ans) {
            ans = pa3.first + pa1.first;
            ind1 = pa3.second;
            ind2 = pa1.second;
          }
          vec3[i + 1].insert(pa2);
        }
      }
    }
  }
  cout << ans << "\n";
  vector<long long int> ans2;
  long long int flag = 0;
  if (vec[ind1].size() >= vec[ind2].size()) {
    ans2.push_back(vec[ind1][0].second);
    i = 1, j = 0;
    flag = 0;
  } else {
    ans2.push_back(vec[ind2][0].second);
    i = 0, j = 1;
    flag = 1;
  }
  while (i < vec[ind1].size() && j < vec[ind2].size()) {
    if (flag == 0) {
      ans2.push_back(vec[ind2][j].second);
      j++;
      flag = 1;
    } else {
      ans2.push_back(vec[ind1][i].second);
      i++;
      flag = 0;
    }
  }
  if (flag == 0 && j < vec[ind2].size()) {
    ans2.push_back(vec[ind2][j].second);
  } else if (flag == 1 && i < vec[ind1].size()) {
    ans2.push_back(vec[ind1][i].second);
  }
  cout << ans2.size() << "\n";
  for (i = 0; i < ans2.size(); i++) {
    cout << ans2[i] + 1 << " ";
  }
}