#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T S(T a) {
  return a * a;
}
template <typename T>
inline string tostring(T a) {
  ostringstream os("");
  os << a;
  return os.str();
}
template <typename T>
inline long long tolong(T a) {
  long long res;
  istringstream os(a);
  os >> res;
  return res;
}
template <typename T>
inline T gcd(T a, T b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
template <typename T>
inline unsigned long long bigmod(T a, T b, T m) {
  if (b == 0)
    return 1;
  else if (b % 2 == 0)
    return S(bigmod(a, b / 2, m)) % m;
  else
    return (a % m * bigmod(a, b - 1, m)) % m;
}
template <typename T>
inline vector<string> parse(T str) {
  vector<string> res;
  string s;
  istringstream os(str);
  while (os >> s) res.push_back(s);
  return res;
}
template <typename T>
inline unsigned long long dist(T A, T B) {
  unsigned long long res =
      (A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y);
  return res;
}
map<int, int> M;
struct Z {
  int h;
  int ind;
};
Z z;
vector<Z> V[100005];
vector<unsigned long long> v[100005];
bool operator<(Z A, Z B) { return A.h < B.h; }
struct P {
  int IND;
  int H;
};
bool operator<(P A, P B) { return A.H < B.H; }
P arr[100005];
int col[100005];
unsigned long long maxi[100005];
int main() {
  int C, H;
  int cnt = 1;
  int n, i, j, k, c;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    cin >> C >> z.h;
    if (!M[C]) M[C] = cnt++;
    c = M[C];
    z.ind = i;
    V[c].push_back(z);
  }
  for (i = 1; i < cnt; i++) {
    sort((V[i]).begin(), (V[i]).end());
    reverse((V[i]).begin(), (V[i]).end());
  }
  int la, lb, lc;
  unsigned long long sumab, sumbc, sumac, suma;
  for (i = 1; i < cnt; i++) {
    la = V[i].size();
    suma = 0;
    for (j = 0; j < la; j++) {
      suma += V[i][j].h;
      v[i].push_back(suma);
    }
  }
  P p;
  for (i = 1; i < cnt; i++) {
    arr[i].IND = i;
    arr[i].H = v[i].size();
  }
  sort(arr + 1, arr + cnt);
  int a = cnt - 2, b = cnt - 1;
  unsigned long long sc;
  int x, y;
  i = arr[b].IND;
  for (j = 0; j < arr[b].H; j++) {
    maxi[j] = v[i][j];
    col[j] = i;
  }
  unsigned long long ly, gy, gm = 0, lm, cu;
  for (j = cnt - 2; j >= 1; j--) {
    i = arr[j].IND;
    cu = arr[j].H;
    {
      if (maxi[cu - 1] > maxi[cu]) {
        lm = maxi[cu - 1] + v[i].back();
        ly = col[cu - 1];
      } else {
        lm = maxi[cu] + v[i].back();
        ly = col[cu];
      }
    }
    if (gm < lm) {
      gm = lm;
      x = i;
      gy = ly;
    }
    sc = 0;
    for (k = 0; k < arr[j].H; k++) {
      if (maxi[k] < sc + V[i][k].h) {
        maxi[k] = sc + V[i][k].h;
        col[k] = i;
      }
      sc += V[i][k].h;
    }
  }
  cout << gm << endl;
  int ma, mb;
  if (V[gy].size() > V[x].size())
    ma = 2 * (V[x].size()) + 1;
  else if (V[gy].size() < V[x].size())
    ma = 2 * (V[y].size()) + 1;
  else
    ma = 2 * V[x].size();
  cout << ma << endl;
  if (V[gy].size() > V[x].size()) {
    cout << V[gy][0].ind;
    for (i = 0; i < V[x].size(); i++) {
      cout << " " << V[x][i].ind << " " << V[gy][i + 1].ind;
    }
  } else if (V[gy].size() < V[x].size()) {
    cout << V[x][0].ind;
    for (i = 0; i < V[gy].size(); i++) {
      cout << " " << V[gy][i].ind << " " << V[x][i + 1].ind;
    }
  } else {
    cout << V[gy][0].ind << " " << V[x][0].ind;
    for (i = 1; i < V[x].size(); i++) {
      cout << " " << V[gy][i].ind << " " << V[x][i].ind;
    }
  }
  cout << endl;
  return 0;
}
