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;
void loadData(void);
long long proc(void);
void printRes(long long);
typedef struct Cube {
  int c, index;
  long long s;
} cube;
typedef struct MaxCubePile {
  int start;
  long long totalHeight;
} maxCubePile;
int n;
cube cubes[100000];
maxCubePile maxCubePiles[100001];
long long sumAcc[100001];
vector<pair<int, int> > cubeInteval;
bool cubeCmp(const cube &ca, const cube &cb);
int getCi(int);
int resi, resj;
bool lyb_debug = false;
void printCubesInfo(void);
void printCubeIntervalInfo(void);
void printAccInfo(void);
int main(int argc, char **argv) {
  loadData();
  printRes(proc());
  return 0;
}
bool cubeCmp(const cube &ca, const cube &cb) {
  if (ca.c != cb.c) return ca.c < cb.c;
  return ca.s > cb.s;
}
long long proc(void) {
  int i, j, start;
  sort(cubes, cubes + n, cubeCmp);
  start = 0;
  cubeInteval.clear();
  for (i = start + 1; i <= n;) {
    if (i == n || cubes[i].c != cubes[start].c) {
      for (j = start; j < i; j++) {
        sumAcc[j] = (j == start ? cubes[start].s : sumAcc[j - 1] + cubes[j].s);
        if (sumAcc[j] > maxCubePiles[j - start + 1].totalHeight) {
          maxCubePiles[j - start + 1].totalHeight = sumAcc[j];
          maxCubePiles[j - start + 1].start = start;
        }
      }
      cubeInteval.push_back(make_pair(start, i));
      start = i;
      i = start + 1;
    } else
      i++;
  }
  long long maxHeight = 0;
  for (i = 0; i < cubeInteval.size(); i++) {
    int theNum = cubeInteval[i].second - cubeInteval[i].first;
    if (theNum - 1 > 0 &&
        maxCubePiles[theNum - 1].totalHeight +
                sumAcc[cubeInteval[i].second - 1] >
            maxHeight &&
        maxCubePiles[theNum - 1].start != cubeInteval[i].first) {
      maxHeight = maxCubePiles[theNum - 1].totalHeight +
                  sumAcc[cubeInteval[i].second - 1];
      resi = cubeInteval[i].first;
      resj = maxCubePiles[theNum - 1].start;
      if (lyb_debug) {
        printf("==for cubeInterval %d, theNum = %d, theNum-1 worked!==\n", i,
               theNum);
      }
    }
    if (theNum < n &&
        maxCubePiles[theNum].totalHeight + sumAcc[cubeInteval[i].second - 1] >
            maxHeight &&
        maxCubePiles[theNum].start != cubeInteval[i].first) {
      maxHeight =
          maxCubePiles[theNum].totalHeight + sumAcc[cubeInteval[i].second - 1];
      resi = cubeInteval[i].first;
      resj = maxCubePiles[theNum].start;
      if (lyb_debug) {
        printf("==for cubeInterval %d, theNum = %d, theNum worked!==\n", i,
               theNum);
      }
    }
    if (theNum + 1 < n &&
        maxCubePiles[theNum + 1].totalHeight +
                sumAcc[cubeInteval[i].second - 1] >
            maxHeight &&
        maxCubePiles[theNum + 1].start != cubeInteval[i].first) {
      maxHeight = maxCubePiles[theNum + 1].totalHeight +
                  sumAcc[cubeInteval[i].second - 1];
      resi = cubeInteval[i].first;
      resj = maxCubePiles[theNum + 1].start;
      if (lyb_debug) {
        printf("==for cubeInterval %d, theNum = %d, theNum+1 worked!==\n", i,
               theNum);
      }
    }
  }
  return maxHeight;
}
void loadData(void) {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> cubes[i].c >> cubes[i].s;
    cubes[i].index = i + 1;
  }
  return;
}
int getCi(int start) {
  for (int i = 0; i < cubeInteval.size(); i++)
    if (start == cubeInteval[i].first) return i;
  return -1;
}
void printRes(long long res) {
  if (lyb_debug) {
    printCubesInfo();
    printAccInfo();
    printCubeIntervalInfo();
  }
  cout << res << endl;
  if (lyb_debug) {
    printf("starti:%d startj:%d\n\n", resi, resj);
  }
  int ci = getCi(resi);
  int cj = getCi(resj);
  if (cubeInteval[ci].second - cubeInteval[ci].first <
      cubeInteval[cj].second - cubeInteval[cj].first)
    swap(ci, cj);
  if (lyb_debug) {
    printf("cubeInteval index:ci:%d cj:%d\n\n", ci, cj);
  }
  cout << cubeInteval[cj].second - cubeInteval[cj].first +
              min(cubeInteval[cj].second - cubeInteval[cj].first + 1,
                  cubeInteval[ci].second - cubeInteval[ci].first)
       << endl;
  int index = 0;
  while (index < cubeInteval[cj].second - cubeInteval[cj].first) {
    cout << cubes[cubeInteval[ci].first + index].index << " "
         << cubes[cubeInteval[cj].first + index].index << " ";
    index++;
  }
  if (cubeInteval[ci].first + index < cubeInteval[ci].second)
    cout << cubes[cubeInteval[ci].first + index].index;
  cout << endl;
  return;
}
void printCubeIntervalInfo(void) {
  printf("==cube interval==\n");
  for (int i = 0; i < cubeInteval.size(); i++)
    printf("*start:%d end:%d\n", cubeInteval[i].first, cubeInteval[i].second);
  printf("\n");
  return;
}
void printCubesInfo(void) {
  printf("==cubes==\n");
  for (int i = 0; i < n; i++)
    printf("*c:%d s:%lld index:%d\n", cubes[i].c, cubes[i].s, cubes[i].index);
  printf("\n");
  return;
}
void printAccInfo(void) {
  printf("==acc Info==\n");
  for (int i = 0; i <= n; i++) printf("*%lld\n", sumAcc[i]);
  printf("\n");
  return;
}