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;
int64_t mod = 1000000007, inf = 4e18;
struct comp {
  int64_t operator()(const pair<int64_t, int64_t> a,
                     const pair<int64_t, int64_t> b) {
    return a > b;
  }
};
int32_t main() {
  ios::sync_with_stdio(false), cin.tie(nullptr);
  cout << fixed << setprecision(0);
  int64_t n, tmp, tmp2;
  cin >> n;
  map<int64_t, vector<pair<int64_t, int64_t>>> mp;
  map<int64_t, int64_t> fs;
  vector<set<pair<int64_t, int64_t>, comp>> arr(n + 1);
  for (int64_t i = 0; i < int64_t(n); ++i) {
    cin >> tmp >> tmp2;
    mp[tmp].push_back(pair<int64_t, int64_t>(tmp2, i + 1));
  }
  for (auto &v : mp) {
    sort((v.second).begin(), (v.second).end(),
         [](pair<int64_t, int64_t> a, pair<int64_t, int64_t> b) {
           return a > b;
         });
    arr[0].insert(pair<int64_t, int64_t>(0, v.first));
    int64_t sum, i;
    for (i = 0, sum = 0; i < v.second.size(); i++) {
      sum += v.second[i].first;
      arr[i + 1].insert(pair<int64_t, int64_t>(sum, v.first));
    }
    fs[v.first] = sum;
  }
  int64_t maxi = -inf;
  pair<int64_t, int64_t> ind;
  for (auto &v : mp) {
    for (int64_t k = v.second.size() - 1; k <= v.second.size() + 1; k++) {
      auto it = arr[k].begin();
      if (it == arr[k].end()) continue;
      if (it->second == v.first) it++;
      if (it == arr[k].end()) continue;
      int64_t val = it->first + fs[v.first];
      if (maxi < val) {
        maxi = val;
        ind = {v.first, it->second};
      }
    }
  }
  cout << maxi << endl;
  vector<pair<int64_t, int64_t>> v1, v2;
  for (auto &v : mp) {
    if (v.first == ind.first) v1 = v.second;
    if (v.first == ind.second) v2 = v.second;
  }
  vector<int64_t> fin;
  if (v1.size() > v2.size()) swap(v1, v2);
  for (int64_t i = 0; i < v1.size(); i++) {
    fin.push_back(v2[i].second), fin.push_back(v1[i].second);
  }
  if (v1.size() != v2.size()) fin.push_back(v2[v1.size()].second);
  cout << fin.size() << endl;
  for (auto &v : fin) cout << v << ' ';
  return 0;
}