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;
struct NodeH {
  long long x;
  int y;
} heap[100005];
struct Node {
  int x, y, z;
} tmp[100005];
vector<pair<int, int> > A[100005];
int N, M, pos[100005], size, ans1, ans2;
long long ans;
bool cmp(const Node a, const Node b) {
  return a.x < b.x || a.x == b.x && a.y > b.y;
}
void refresh(int x, int y) {
  if (heap[x].x + heap[y].x > ans) {
    ans = heap[x].x + heap[y].x;
    ans1 = heap[x].y;
    ans2 = heap[y].y;
  }
}
void swap(int a, int b) {
  NodeH tmp = heap[a];
  heap[a] = heap[b];
  heap[b] = tmp;
  pos[heap[a].y] = a;
  pos[heap[b].y] = b;
}
void up(int x) {
  while (x > 1) {
    if (heap[x].x <= heap[x / 2].x) break;
    swap(x, x / 2);
    x /= 2;
  }
}
void down(int x) {
  while (x << 1 <= size) {
    int p = x;
    if (x << 1 <= size && heap[x << 1].x > heap[p].x) p = x << 1;
    if ((x << 1) + 1 <= size && heap[(x << 1) + 1].x > heap[p].x)
      p = (x << 1) + 1;
    if (p == x) break;
    swap(x, p);
    x = p;
  }
}
void add(int x, int y) {
  heap[++size].x = x;
  heap[size].y = y;
  pos[y] = size;
  up(size);
}
void del(int x) {
  heap[x] = heap[size];
  pos[heap[x].y] = x;
  --size;
  up(x);
  down(x);
}
void modify(int x, long long y) {
  heap[x].x += y;
  up(x);
}
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) {
    scanf("%d%d", &tmp[i].x, &tmp[i].y);
    tmp[i].z = i;
  }
  sort(tmp + 1, tmp + N + 1, cmp);
  M = 1;
  A[1].push_back(make_pair(tmp[1].y, tmp[1].z));
  for (int i = 2; i <= N; ++i) {
    if (tmp[i].x != tmp[i - 1].x) ++M;
    A[M].push_back(make_pair(tmp[i].y, tmp[i].z));
  }
  for (int i = 1; i <= M; ++i) add(A[i][0].first, i);
  ans = heap[1].x + heap[2].x;
  ans1 = heap[1].y;
  ans2 = heap[2].y;
  refresh(1, 3);
  for (int i = 2; size > 1; ++i) {
    for (int j = 1; j <= M; ++j) {
      if (A[j].size() == i - 2) del(pos[j]);
      if (A[j].size() >= i) modify(pos[j], A[j][i - 1].first);
    }
    if (size > 1) refresh(1, 2);
    if (size > 2) refresh(1, 3);
  }
  cout << ans << endl;
  if (A[ans1].size() < A[ans2].size()) {
    int tmp = ans1;
    ans1 = ans2;
    ans2 = tmp;
  }
  int x = min(A[ans1].size(), A[ans2].size());
  if (A[ans1].size() > x)
    printf("%d\n", x + x + 1);
  else
    printf("%d\n", x + x);
  for (int i = 0; i < x; ++i) {
    if (i) printf(" ");
    printf("%d %d", A[ans1][i].second, A[ans2][i].second);
  }
  if (A[ans1].size() > x) printf(" %d", A[ans1][x].second);
  printf("\n");
  return 0;
}