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, P[100010], E[100010];
vector<pair<pair<int, int>, int> > Q, R;
bool cmpQ(const pair<pair<int, int>, int>& t1,
          const pair<pair<int, int>, int>& t2) {
  if (t1.first.first == t2.first.first)
    return t1.first.second > t2.first.second;
  else
    return t1.first.first < t2.first.first;
}
bool cmpR(const pair<pair<int, int>, int>& t1,
          const pair<pair<int, int>, int>& t2) {
  return t1.first.second - t1.first.first > t2.first.second - t2.first.first;
}
struct NODE {
  long long h, fv, sv;
  int fn, sn, n;
} T[100010 << 2];
void pushup(int rt, int nn) {
  NODE& t = T[rt];
  NODE ll = T[rt << 1], rr = T[rt << 1 | 1];
  if (ll.n == nn && ll.n > rr.n) {
    t.fv = ll.fv, t.fn = ll.fn, t.sv = ll.sv, t.sn = ll.sn, t.n = nn;
    return;
  } else if (rr.n == nn && ll.n < rr.n) {
    t.fv = rr.fv, t.fn = rr.fn, t.sv = rr.sv, t.sn = rr.sn, t.n = nn;
    return;
  } else if (ll.n < nn && rr.n < nn) {
    t.fv = t.sv = 0LL;
    t.fn = t.sn = t.n = 0;
    return;
  }
  t.n = nn;
  if (ll.fv >= rr.fv) {
    t.fv = ll.fv, t.fn = ll.fn;
    if (rr.fv >= ll.sv)
      t.sv = rr.fv, t.sn = rr.fn;
    else
      t.sv = ll.sv, t.sn = ll.sn;
  } else if (ll.fv < rr.fv) {
    t.fv = rr.fv, t.fn = rr.fn;
    if (ll.fv >= rr.sv)
      t.sv = ll.fv, t.sn = ll.fn;
    else
      t.sv = rr.sv, t.sn = rr.sn;
  }
}
void add(int rt, int l, int r, int pos, long long val, int nn) {
  if (pos < l || pos > r) return;
  if (l == r) {
    NODE& t = T[rt];
    t.h += val, t.n++;
    t.sv = 0LL, t.sn = 0;
    t.fn = pos, t.fv = t.h;
    return;
  }
  int mid = (l + r) >> 1;
  add(rt << 1, l, mid, pos, val, nn);
  add(rt << 1 | 1, mid + 1, r, pos, val, nn);
  pushup(rt, nn);
}
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    int c, s;
    scanf("%d%d", &c, &s);
    Q.push_back(make_pair(make_pair(c, s), i + 1));
  }
  sort(Q.begin(), Q.end(), cmpQ);
  int st, en, cc, mx = 0, len, pc = Q[0].first.first;
  for (st = en = 0, cc = 1; en < Q.size();) {
    E[cc] = en;
    while (Q[en].first.first == pc) en++;
    R.push_back(make_pair(make_pair(st, en), cc));
    mx = max(mx, en - st);
    st = en, cc++, pc = Q[en].first.first;
  }
  len = R.size();
  sort(R.begin(), R.end(), cmpR);
  memset(T, 0, sizeof(T));
  for (int i = 0; i < R.size(); i++) P[i] = R[i].first.first;
  int cnt1, cnt2, n1, n2;
  long long pfv, psv, cfv, csv, ans = 0LL;
  int pfn, psn, cfn, csn;
  pfv = psv = 0LL, pfn = psn = 0;
  for (int i = 1; i <= mx; i++) {
    for (int j = 0; j < R.size(); j++) {
      if (P[j] == R[j].first.second) break;
      add(1, 1, len, R[j].second, 1LL * Q[P[j]].first.second, i);
      P[j]++;
    }
    cfv = T[1].fv, cfn = T[1].fn, csv = T[1].sv, csn = T[1].sn;
    if (cfn != 0 && csn != 0 && ans < cfv + csv) {
      ans = cfv + csv;
      cnt1 = cnt2 = i;
      n1 = cfn, n2 = csn;
    }
    if (pfn != 0 && cfn != 0 && pfn != cfn && ans < pfv + cfv) {
      ans = pfv + cfv;
      cnt1 = i - 1, cnt2 = i;
      n1 = pfn, n2 = cfn;
    }
    if (pfn != 0 && csn != 0 && pfn != csn && ans < pfv + csv) {
      ans = pfv + csv;
      cnt1 = i - 1, cnt2 = i;
      n1 = pfn, n2 = csn;
    }
    if (psn != 0 && cfn != 0 && psn != cfn && ans < psv + cfv) {
      ans = psv + cfv;
      cnt1 = i - 1, cnt2 = i;
      n1 = psn, n2 = cfn;
    }
    pfv = cfv, pfn = cfn, psv = csv, psn = csn;
  }
  cout << ans << endl;
  cout << cnt1 + cnt2 << endl;
  int p1 = E[n1], p2 = E[n2];
  if (cnt1 == cnt2) {
    for (int i = 1, k = 0; i <= cnt1 + cnt2; i++, k = 1 - k) {
      if (k == 0)
        printf("%d ", Q[p1++].second);
      else
        printf("%d ", Q[p2++].second);
    }
  } else if (cnt1 > cnt2) {
    printf("%d ", Q[p1++].second);
    for (int i = 1, k = 1; i <= cnt1 + cnt2 - 1; i++, k = 1 - k) {
      if (k == 0)
        printf("%d ", Q[p1++].second);
      else
        printf("%d ", Q[p2++].second);
    }
  } else if (cnt1 < cnt2) {
    printf("%d ", Q[p2++].second);
    for (int i = 1, k = 0; i <= cnt1 + cnt2 - 1; i++, k = 1 - k) {
      if (k == 0)
        printf("%d ", Q[p1++].second);
      else
        printf("%d ", Q[p2++].second);
    }
  }
  cout << endl;
  return 0;
}