#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;
}
