#include <bits/stdc++.h>
using namespace std;
int n;
struct cube {
  int c, s;
  int id;
  bool operator<(const cube& x) const {
    if (c == x.c) return s > x.s;
    return c < x.c;
  }
} C[100005];
struct rec {
  long long a;
  int label;
  rec() {
    a = 0LL;
    label = 0;
  }
  bool operator<(const rec& x) const { return a > x.a; }
} ans[100005][2], tmp[10];
int main(int argc, char** argv) {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d%d", &C[i].c, &C[i].s);
  for (int i = 0; i < n; ++i) C[i].id = i + 1;
  sort(C, C + n);
  int label = -1, cnt = -1;
  long long now = 0;
  for (int i = 0; i < n; ++i) {
    if (label != C[i].c) {
      label = C[i].c;
      now = C[i].s;
      cnt = 1;
    } else {
      now += C[i].s;
      cnt++;
    }
    tmp[0].a = now, tmp[0].label = label;
    tmp[1] = ans[cnt][0], tmp[2] = ans[cnt][1];
    sort(tmp, tmp + 3);
    ans[cnt][0] = tmp[0], ans[cnt][1] = tmp[1];
  }
  long long output = ans[1][0].a + ans[1][1].a;
  int color1 = ans[1][0].label, color2 = ans[1][1].label, cnt1 = 1, cnt2 = 1;
  for (int i = 1; i < n; ++i) {
    if (ans[i][0].label == 0)
      continue;
    else {
      if (ans[i][1].label != 0) {
        if (output < ans[i][1].a + ans[i][0].a) {
          output = ans[i][1].a + ans[i][0].a;
          color1 = ans[i][0].label, color2 = ans[i][1].label;
          cnt1 = cnt2 = i;
        }
        if (ans[i + 1][0].label != 0 &&
            ans[i + 1][0].label != ans[i][1].label &&
            output < ans[i][1].a + ans[i + 1][0].a) {
          output = ans[i][1].a + ans[i + 1][0].a;
          color1 = ans[i][1].label, color2 = ans[i + 1][0].label;
          cnt1 = i, cnt2 = i + 1;
        }
        if (ans[i + 1][1].label != 0 &&
            ans[i + 1][1].label != ans[i][1].label &&
            output < ans[i][1].a + ans[i + 1][1].a) {
          output = ans[i][1].a + ans[i + 1][1].a;
          color1 = ans[i][1].label, color2 = ans[i + 1][1].label;
          cnt1 = i, cnt2 = i + 1;
        }
      }
      if (ans[i + 1][0].label != 0 && ans[i + 1][0].label != ans[i][0].label) {
        if (output < ans[i][0].a + ans[i + 1][0].a) {
          output = ans[i][0].a + ans[i + 1][0].a;
          color1 = ans[i][0].label, color2 = ans[i + 1][0].label;
          cnt1 = i, cnt2 = i + 1;
        }
      }
      if (ans[i + 1][1].label != 0 && ans[i + 1][1].label != ans[i][0].label) {
        if (output < ans[i][0].a + ans[i + 1][1].a) {
          output = ans[i][0].a + ans[i + 1][1].a;
          color1 = ans[i][0].label, color2 = ans[i + 1][1].label;
          cnt1 = i, cnt2 = i + 1;
        }
      }
    }
  }
  cout << output << endl << cnt1 + cnt2 << endl;
  int b1, b2;
  for (int i = 0; i < n; ++i)
    if (C[i].c == color1) {
      b1 = i;
      break;
    }
  for (int i = 0; i < n; ++i)
    if (C[i].c == color2) {
      b2 = i;
      break;
    }
  cout << C[b2++].id;
  for (int i = 0; i < cnt1 + cnt2 - 1; ++i) {
    if (i & 1) {
      cout << " " << C[b2++].id;
    } else {
      cout << " " << C[b1++].id;
    }
  }
  cout << endl;
  return 0;
}
