#include <bits/stdc++.h>
using namespace std;
long long* highest;
long long* secondHighest;
int* highNum;
int* secondNum;
class Cube {
 public:
  int size;
  int id;
  Cube() {}
  Cube(int intoSize, int intoId) {
    size = intoSize;
    id = intoId;
  }
  bool operator<(Cube comp) const { return size < comp.size; }
};
class Colour {
 public:
  priority_queue<Cube> cubeQueue;
  Cube* cubeArray;
  long long* cuml;
  Colour* next;
  int number;
  int cubeNum;
  Colour() {}
  Colour(int intoNumber) {
    number = intoNumber;
    next = NULL;
  }
  void add(Cube cube) { cubeQueue.push(cube); }
  void org() {
    cubeNum = cubeQueue.size();
    cubeArray = new Cube[cubeNum];
    cuml = new long long[cubeNum + 1];
    cuml[0] = 0;
    for (int i = 1; i <= cubeNum; i++) {
      cubeArray[i - 1] = cubeQueue.top();
      cuml[i] = cuml[i - 1] + cubeArray[i - 1].size;
      if (cuml[i] > highest[i]) {
        secondHighest[i] = highest[i];
        secondNum[i] = highNum[i];
        highest[i] = cuml[i];
        highNum[i] = number;
      } else {
        if (cuml[i] > secondHighest[i]) {
          secondHighest[i] = cuml[i];
          secondNum[i] = number;
        }
      }
      cubeQueue.pop();
    }
  }
};
class Hash {
 public:
  Colour** colArray;
  Hash() {
    colArray = new Colour*[75000];
    for (int i = 0; i < 75000; i++) colArray[i] = NULL;
  }
  Colour* get(int number) {
    Colour* current = colArray[number % 75000];
    while (current != NULL) {
      if (current->number == number) return current;
      current = current->next;
    }
    return NULL;
  }
  void add(Colour* col) {
    col->next = colArray[col->number % 75000];
    colArray[col->number % 75000] = col;
  }
  void orgAll() {
    for (int i = 0; i < 75000; i++) {
      Colour* current = colArray[i];
      while (current != NULL) {
        current->org();
        current = current->next;
      }
    }
  }
};
long long tallest(int first, int second) {
  if (first == second) {
    if (highest[first] == -1 || secondHighest[second] == -1)
      return -1;
    else
      return highest[first] + secondHighest[second];
  } else {
    if (highNum[first] == highNum[second]) {
      if (highest[first] == -1 || secondHighest[second] == -1)
        return -1;
      else
        return highest[first] + secondHighest[second];
    } else {
      if (highest[first] == -1 || highest[second] == -1)
        return -1;
      else
        return highest[first] + highest[second];
    }
  }
}
int main() {
  int cubeNum, i;
  cin >> cubeNum;
  highest = new long long[cubeNum + 1];
  secondHighest = new long long[cubeNum + 1];
  highNum = new int[cubeNum + 1];
  secondNum = new int[cubeNum + 1];
  highest[0] = 0;
  secondHighest[0] = 0;
  highNum[0] = 0;
  secondNum[0] = 0;
  for (i = 1; i <= cubeNum; i++) {
    highest[i] = -1;
    secondHighest[i] = -1;
  }
  Hash h;
  for (i = 0; i < cubeNum; i++) {
    int colour, size;
    cin >> colour >> size;
    Colour* col = h.get(colour);
    if (col == NULL) {
      col = new Colour(colour);
      h.add(col);
    }
    col->add(*new Cube(size, i + 1));
  }
  h.orgAll();
  long long best = 0;
  int bestNum1, bestNum2, bestHeight1, bestHeight2;
  for (i = 1; i <= cubeNum; i++) {
    long long result = tallest(i, i - 1);
    if (result > best) {
      best = result;
      bestNum1 = highNum[i];
      if (highNum[i] != highNum[i - 1])
        bestNum2 = highNum[i - 1];
      else
        bestNum2 = secondNum[i - 1];
      bestHeight1 = i;
      bestHeight2 = i - 1;
    }
    result = tallest(i, i);
    if (result > best) {
      best = result;
      bestNum1 = highNum[i];
      bestNum2 = secondNum[i];
      bestHeight1 = i;
      bestHeight2 = i;
    }
    result = tallest(i, i + 1);
    if (result > best) {
      best = result;
      bestNum1 = highNum[i];
      if (highNum[i] != highNum[i + 1])
        bestNum2 = highNum[i + 1];
      else
        bestNum2 = secondNum[i + 1];
      bestHeight1 = i;
      bestHeight2 = i + 1;
    }
  }
  int shortest = bestHeight1 < bestHeight2 ? bestHeight1 : bestHeight2;
  int shortestNum, tallNum;
  if (bestHeight1 < bestHeight2) {
    shortestNum = bestNum1;
    tallNum = bestNum2;
  } else {
    shortestNum = bestNum2;
    tallNum = bestNum1;
  }
  int tall = bestHeight1 > bestHeight2 ? bestHeight1 : bestHeight2;
  Colour* colour1 = h.get(tallNum);
  Colour* colour2 = h.get(shortestNum);
  cout << best << endl;
  cout << (bestHeight1 + bestHeight2) << endl;
  for (i = 0; i < shortest; i++) {
    cout << colour1->cubeArray[i].id << " ";
    cout << colour2->cubeArray[i].id << " ";
  }
  if (i < tall) cout << colour1->cubeArray[i].id << " ";
  cout << endl;
  return 0;
}
