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>
#pragma GCC optimize("O3")
using namespace std;
const int N = 1e5 + 5, M = 20 + 5, OO = 0x3f3f3f3f, mod = 1e9 + 7, base = 131,
          mod2 = 1000136437, mod3 = 998244353;
const double EPS = 1e-9;
int n, iddd = 1;
vector<vector<pair<int, int>>> v(N);
map<int, int> idd;
pair<int, int> arr[N];
map<int, vector<pair<long long, int>>> mp;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i].first >> arr[i].second;
    if (idd[arr[i].first] == 0) {
      idd[arr[i].first] = iddd++;
    }
    v[idd[arr[i].first]].push_back({arr[i].second, i});
  }
  for (int i = 1; i < N; i++) {
    if ((int)(v[i]).size()) {
      sort((v[i]).rbegin(), (v[i]).rend());
      long long acc = v[i][0].first, cnt = 1;
      mp[1].push_back({acc, i});
      for (int j = 1; j < (int)(v[i]).size(); j++) {
        cnt++;
        acc += v[i][j].first;
        mp[cnt].push_back({acc, i});
      }
    }
  }
  for (auto& i : mp) {
    sort((i.second).begin(), (i.second).end());
  }
  pair<int, int> ans1, ans2;
  long long mx = 0;
  for (int i = 1; i < N; i++) {
    if (mp[i].empty()) {
      continue;
    }
    if ((int)(mp[i]).size() == 1) {
      if ((int)(mp[i + 1]).size()) {
        if (mp[i + 1].back().second != mp[i][0].second) {
          if (mx < mp[i][0].first + mp[i + 1].back().first) {
            mx = mp[i][0].first + mp[i + 1].back().first;
            ans2 = {i, mp[i][0].second},
            ans1 = {i + 1, mp[i + 1].back().second};
          }
        } else if (mp[i + 1].back().second == mp[i][0].second &&
                   (int)(mp[i + 1]).size() > 1) {
          if (mx <
              mp[i][0].first + mp[i + 1][(int)(mp[i + 1]).size() - 2].first) {
            mx = mp[i][0].first + mp[i + 1][(int)(mp[i + 1]).size() - 2].first;
            ans2 = {i, mp[i][0].second},
            ans1 = {i + 1, mp[i + 1][(int)(mp[i + 1]).size() - 2].second};
          }
        }
      }
    } else {
      long long a, b, ida, idb;
      a = mp[i].back().first;
      b = mp[i][(int)(mp[i]).size() - 2].first;
      ida = mp[i].back().second;
      idb = mp[i][(int)(mp[i]).size() - 2].second;
      if (a + b > mx) {
        mx = a + b;
        ans1 = {i, ida}, ans2 = {i, idb};
      }
      if ((int)(mp[i + 1]).size()) {
        long long aa, bb, idaa, idbb;
        aa = mp[i + 1].back().first;
        idaa = mp[i + 1].back().second;
        if (idaa != ida && aa + a > mx) {
          mx = aa + a;
          ans1 = {i + 1, idaa}, ans2 = {i, ida};
        } else if (idaa == ida) {
          if (aa + b > mx) {
            mx = aa + b;
            ans1 = {i + 1, idaa}, ans2 = {i, idb};
          }
          if ((int)(mp[i + 1]).size() > 1) {
            bb = mp[i + 1][(int)(mp[i + 1]).size() - 2].first;
            idbb = mp[i + 1][(int)(mp[i + 1]).size() - 2].second;
            if (a + bb > mx) {
              mx = a + bb;
              ans1 = {i + 1, idbb}, ans2 = {i, ida};
            }
            if (b + bb > mx && idb != idbb) {
              mx = b + bb;
              ans1 = {i + 1, idbb}, ans2 = {i, idb};
            }
          }
        }
      }
    }
  }
  cout << mx << endl;
  if (ans1.first < ans2.first) swap(ans1, ans2);
  vector<int> a, b;
  for (int i = 0; i < ans1.first; i++)
    a.push_back(v[ans1.second][i].second + 1);
  for (int i = 0; i < ans2.first; i++)
    b.push_back(v[ans2.second][i].second + 1);
  bool aa = true;
  cout << ans1.first + ans2.first << endl;
  while ((int)(b).size() || (int)(a).size()) {
    if (aa)
      cout << a.back() << " ", a.pop_back(), aa = false;
    else
      cout << b.back() << " ", b.pop_back(), aa = true;
  }
  return 0;
}