#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1.0);
int dblcmp(double d) {
  if (fabs(d) < eps) return 0;
  return d > eps ? 1 : -1;
}
int n;
int c[111111], s[111111];
vector<pair<int, int> > a[111111];
map<int, int> v;
int b[111111];
set<pair<long long, int> > p[111111];
void up(int x, pair<long long, int> t) {
  p[x].insert(t);
  if ((int)((p[x]).size()) > 2) {
    p[x].erase(p[x].begin());
  }
}
bool cmp(const pair<int, int>& a, const pair<int, int>& b) {
  if (a.first == b.first) return a.second < b.second;
  return a.first > b.first;
}
int main() {
  int i, j, k;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d%d", &c[i], &s[i]);
    v[c[i]];
  }
  i = 0;
  for (__typeof(v.begin()) e = v.begin(); e != v.end(); ++e) {
    v[e->first] = i;
    b[i++] = e->first;
  }
  int z = i;
  for (i = 0; i < n; i++) {
    c[i] = v[c[i]];
    a[c[i]].push_back(make_pair(s[i], i + 1));
  }
  for (i = 0; i < z; i++) {
    sort(a[i].begin(), a[i].end(), cmp);
    long long sum = 0;
    for (j = 0; j < (int)((a[i]).size()); j++) {
      sum += (long long)a[i][j].first;
      up(j + 1, make_pair(sum, b[i]));
    }
  }
  long long mx = 0;
  int p1 = 0, p2 = 0;
  for (i = 2; i <= n; i++) {
    if (p[i].empty() == false && p[i - 1].empty() == false) {
      long long r;
      if (p[i].rbegin()->second == p[i - 1].rbegin()->second) {
        if ((int)((p[i - 1]).size()) == 1) continue;
        r = p[i].rbegin()->first + p[i - 1].begin()->first;
      } else {
        r = p[i].rbegin()->first + p[i - 1].rbegin()->first;
      }
      if (r > mx) {
        mx = r;
        if (p[i].rbegin()->second == p[i - 1].rbegin()->second) {
          p1 = p[i].rbegin()->second;
          p2 = p[i - 1].begin()->second;
        } else {
          p1 = p[i].rbegin()->second;
          p2 = p[i - 1].rbegin()->second;
        }
      }
    }
  }
  for (i = 1; i < n; i++) {
    if (p[i].empty() == false && p[i + 1].empty() == false) {
      long long r;
      if (p[i].rbegin()->second == p[i + 1].rbegin()->second) {
        if ((int)((p[i + 1]).size()) == 1) continue;
        r = p[i].rbegin()->first + p[i + 1].begin()->first;
      } else {
        r = p[i].rbegin()->first + p[i + 1].rbegin()->first;
      }
      if (r > mx) {
        mx = r;
        if (p[i].rbegin()->second == p[i + 1].rbegin()->second) {
          p1 = p[i].rbegin()->second;
          p2 = p[i + 1].begin()->second;
        } else {
          p1 = p[i].rbegin()->second;
          p2 = p[i + 1].rbegin()->second;
        }
      }
    }
  }
  for (i = 1; i <= n; i++) {
    if ((int)((p[i]).size()) >= 2) {
      long long r = p[i].rbegin()->first + p[i].begin()->first;
      if (r > mx) {
        mx = r;
        p1 = p[i].rbegin()->second;
        p2 = p[i].begin()->second;
      }
    }
  }
  cout << mx << endl;
  p1 = v[p1];
  p2 = v[p2];
  int s1 = (int)((a[p1]).size()), s2 = (int)((a[p2]).size());
  if (s1 > s2) {
    printf("%d\n", s2 * 2 + 1);
    j = 0, k = 0;
    for (i = 0; i < s2 * 2 + 1; i++) {
      if (i & 1) {
        printf("%d\n", a[p2][k].second);
        k++;
      } else {
        printf("%d\n", a[p1][j].second);
        j++;
      }
    }
  } else if (s1 == s2) {
    printf("%d\n", s2 * 2);
    j = 0, k = 0;
    for (i = 0; i < s2 * 2; i++) {
      if (i & 1) {
        printf("%d\n", a[p2][k].second);
        k++;
      } else {
        printf("%d\n", a[p1][j].second);
        j++;
      }
    }
  } else {
    printf("%d\n", s1 * 2 + 1);
    for (i = 0; i < s1 * 2 + 1; i++) {
      if (i & 1) {
        printf("%d\n", a[p1][k].second);
        k++;
      } else {
        printf("%d\n", a[p2][j].second);
        j++;
      }
    }
  }
  return 0;
}
