#include <bits/stdc++.h>
using namespace std;
int N, P[100010], E[100010];
vector<pair<pair<int, int>, int> > Q, R;
bool cmpQ(const pair<pair<int, int>, int>& t1,
          const pair<pair<int, int>, int>& t2) {
  if (t1.first.first == t2.first.first)
    return t1.first.second > t2.first.second;
  else
    return t1.first.first < t2.first.first;
}
bool cmpR(const pair<pair<int, int>, int>& t1,
          const pair<pair<int, int>, int>& t2) {
  return t1.first.second - t1.first.first > t2.first.second - t2.first.first;
}
struct NODE {
  long long h, fv, sv;
  int fn, sn, n;
} T[100010 << 2];
void pushup(int rt, int nn) {
  NODE& t = T[rt];
  NODE ll = T[rt << 1], rr = T[rt << 1 | 1];
  if (ll.n == nn && ll.n > rr.n) {
    t.fv = ll.fv, t.fn = ll.fn, t.sv = ll.sv, t.sn = ll.sn, t.n = nn;
    return;
  } else if (rr.n == nn && ll.n < rr.n) {
    t.fv = rr.fv, t.fn = rr.fn, t.sv = rr.sv, t.sn = rr.sn, t.n = nn;
    return;
  } else if (ll.n < nn && rr.n < nn) {
    t.fv = t.sv = 0LL;
    t.fn = t.sn = t.n = 0;
    return;
  }
  t.n = nn;
  if (ll.fv >= rr.fv) {
    t.fv = ll.fv, t.fn = ll.fn;
    if (rr.fv >= ll.sv)
      t.sv = rr.fv, t.sn = rr.fn;
    else
      t.sv = ll.sv, t.sn = ll.sn;
  } else if (ll.fv < rr.fv) {
    t.fv = rr.fv, t.fn = rr.fn;
    if (ll.fv >= rr.sv)
      t.sv = ll.fv, t.sn = ll.fn;
    else
      t.sv = rr.sv, t.sn = rr.sn;
  }
}
void add(int rt, int l, int r, int pos, long long val, int nn) {
  if (pos < l || pos > r) return;
  if (l == r) {
    NODE& t = T[rt];
    t.h += val, t.n++;
    t.sv = 0LL, t.sn = 0;
    t.fn = pos, t.fv = t.h;
    return;
  }
  int mid = (l + r) >> 1;
  add(rt << 1, l, mid, pos, val, nn);
  add(rt << 1 | 1, mid + 1, r, pos, val, nn);
  pushup(rt, nn);
}
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    int c, s;
    scanf("%d%d", &c, &s);
    Q.push_back(make_pair(make_pair(c, s), i + 1));
  }
  sort(Q.begin(), Q.end(), cmpQ);
  int st, en, cc, mx = 0, len, pc = Q[0].first.first;
  for (st = en = 0, cc = 1; en < Q.size();) {
    E[cc] = en;
    while (Q[en].first.first == pc) en++;
    R.push_back(make_pair(make_pair(st, en), cc));
    mx = max(mx, en - st);
    st = en, cc++, pc = Q[en].first.first;
  }
  len = R.size();
  sort(R.begin(), R.end(), cmpR);
  memset(T, 0, sizeof(T));
  for (int i = 0; i < R.size(); i++) P[i] = R[i].first.first;
  int cnt1, cnt2, n1, n2;
  long long pfv, psv, cfv, csv, ans = 0LL;
  int pfn, psn, cfn, csn;
  pfv = psv = 0LL, pfn = psn = 0;
  for (int i = 1; i <= mx; i++) {
    for (int j = 0; j < R.size(); j++) {
      if (P[j] == R[j].first.second) break;
      add(1, 1, len, R[j].second, 1LL * Q[P[j]].first.second, i);
      P[j]++;
    }
    cfv = T[1].fv, cfn = T[1].fn, csv = T[1].sv, csn = T[1].sn;
    if (cfn != 0 && csn != 0 && ans < cfv + csv) {
      ans = cfv + csv;
      cnt1 = cnt2 = i;
      n1 = cfn, n2 = csn;
    }
    if (pfn != 0 && cfn != 0 && pfn != cfn && ans < pfv + cfv) {
      ans = pfv + cfv;
      cnt1 = i - 1, cnt2 = i;
      n1 = pfn, n2 = cfn;
    }
    if (pfn != 0 && csn != 0 && pfn != csn && ans < pfv + csv) {
      ans = pfv + csv;
      cnt1 = i - 1, cnt2 = i;
      n1 = pfn, n2 = csn;
    }
    if (psn != 0 && cfn != 0 && psn != cfn && ans < psv + cfv) {
      ans = psv + cfv;
      cnt1 = i - 1, cnt2 = i;
      n1 = psn, n2 = cfn;
    }
    pfv = cfv, pfn = cfn, psv = csv, psn = csn;
  }
  cout << ans << endl;
  cout << cnt1 + cnt2 << endl;
  int p1 = E[n1], p2 = E[n2];
  if (cnt1 == cnt2) {
    for (int i = 1, k = 0; i <= cnt1 + cnt2; i++, k = 1 - k) {
      if (k == 0)
        printf("%d ", Q[p1++].second);
      else
        printf("%d ", Q[p2++].second);
    }
  } else if (cnt1 > cnt2) {
    printf("%d ", Q[p1++].second);
    for (int i = 1, k = 1; i <= cnt1 + cnt2 - 1; i++, k = 1 - k) {
      if (k == 0)
        printf("%d ", Q[p1++].second);
      else
        printf("%d ", Q[p2++].second);
    }
  } else if (cnt1 < cnt2) {
    printf("%d ", Q[p2++].second);
    for (int i = 1, k = 0; i <= cnt1 + cnt2 - 1; i++, k = 1 - k) {
      if (k == 0)
        printf("%d ", Q[p1++].second);
      else
        printf("%d ", Q[p2++].second);
    }
  }
  cout << endl;
  return 0;
}
