#include <bits/stdc++.h>
using namespace std;
template <class T1>
void deb(T1 e1) {
  cout << e1 << endl;
}
template <class T1, class T2>
void deb(T1 e1, T2 e2) {
  cout << e1 << " " << e2 << endl;
}
template <class T1, class T2, class T3>
void deb(T1 e1, T2 e2, T3 e3) {
  cout << e1 << " " << e2 << " " << e3 << endl;
}
template <class T1, class T2, class T3, class T4>
void deb(T1 e1, T2 e2, T3 e3, T4 e4) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << endl;
}
template <class T1, class T2, class T3, class T4, class T5>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << endl;
}
template <class T1, class T2, class T3, class T4, class T5, class T6>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << " " << e6
       << endl;
}
int X[] = {0, 0, 1, 0, 0, -1};
int Y[] = {0, 1, 0, 0, -1, 0};
int Z[] = {1, 0, 0, -1, 0, 0};
struct node {
  long long c, s;
  node() {}
  node(long long c, long long s) : c(c), s(s) {}
  bool operator<(const node& p) const { return s > p.s; }
};
struct data {
  long long x, val;
  data() {}
  data(long long x, long long val) : x(x), val(val) {}
  bool operator<(const data& p) const { return x > p.x; }
};
data a[3][100004];
long long b[100006];
vector<node> v[100005];
map<long long, long long> mp;
int main() {
  long long i, j, k, l = 1, x, y, z, t, m, n;
  cin >> n;
  for (i = 1; i <= n; i++) {
    scanf("%lld %lld", &x, &y);
    if (!mp[x]) mp[x] = l++;
    v[mp[x]].push_back(node(i, y));
  }
  for (i = 1; i < l; i++) sort(v[i].begin(), v[i].end());
  memset(a, 0, sizeof(a));
  for (i = 1; i < l; i++) {
    m = 1;
    x = 0;
    for (j = 0; j < v[i].size(); j++) {
      y = v[i][j].s;
      x += y;
      if (a[0][m].val < x) {
        a[1][m].val = a[0][m].val;
        a[1][m].x = a[0][m].x;
        a[0][m].val = x;
        a[0][m].x = i;
      } else if (a[1][m].val < x) {
        a[1][m].val = x;
        a[1][m].x = i;
      }
      m++;
    }
    b[i] = x;
  }
  long long p, q, w = 0, p1, q1;
  for (i = 1; i < l; i++) {
    x = v[i].size();
    z = b[i];
    if (a[0][x].x != i) {
      if (a[0][x].val != 0) {
        z += a[0][x].val;
        if (w < z) {
          w = z;
          p = i;
          p1 = x;
          q = a[0][x].x;
          q1 = x;
        }
      }
    } else {
      if (a[1][x].val != 0) {
        z += a[1][x].val;
        if (w < z) {
          w = z;
          p = i;
          p1 = x;
          q = a[1][x].x;
          q1 = x;
        }
      }
    }
    z = b[i];
    if (a[0][x + 1].x != i) {
      if (a[0][x + 1].val != 0) {
        z += a[0][x + 1].val;
        if (w < z) {
          w = z;
          p = i;
          q = a[0][x + 1].x;
          p1 = x;
          q1 = x + 1;
        }
      }
    } else {
      if (a[1][x + 1].val != 0) {
        z += a[1][x + 1].val;
        if (w < z) {
          w = z;
          p = i;
          q = a[1][x + 1].x;
          p1 = x;
          q1 = x + 1;
        }
      }
    }
  }
  vector<data> vec1, vec2;
  for (i = 0; i < p1; i++) {
    vec1.push_back(data(v[p][i].c, v[p][i].s));
  }
  for (i = 0; i < q1; i++) {
    vec2.push_back(data(v[q][i].c, v[q][i].s));
  }
  sort(vec1.begin(), vec1.end());
  sort(vec2.begin(), vec2.end());
  deb(w);
  deb(vec1.size() + vec2.size());
  if (vec1.size() > vec2.size())
    t = 1;
  else
    t = 0;
  j = 0, k = 0;
  for (i = 0; i < vec1.size() + vec2.size(); i++) {
    if (i % 2 == 0) {
      if (t)
        printf("%lld ", vec1[j++]);
      else
        printf("%lld ", vec2[k++]);
    }
    if (i % 2 == 1) {
      if (t)
        printf("%lld ", vec2[k++]);
      else
        printf("%lld ", vec1[j++]);
    }
  }
  return 0;
}
