#include <bits/stdc++.h>
using namespace std;
struct data {
  int x, y, d;
  data(int _x, int _y, int _d) { x = _x, y = _y, d = _d; }
  bool operator<(const data &b) const {
    if (d == b.d) {
      if (x == b.x) return y > b.y;
      return x > b.x;
    }
    return d > b.d;
  }
};
string inp;
int n, a[200010], v[200010], Left[200010], Right[200010];
priority_queue<data> q;
int main() {
  ios_base::sync_with_stdio(0);
  memset((Left), (-1), sizeof(Left));
  ;
  memset((Right), (-1), sizeof(Right));
  ;
  cin >> n >> inp;
  for (__typeof(n) i = 0; i < (n); i++) cin >> a[i];
  for (__typeof(n) i = 0; i < (n); i++) {
    if (i) Left[i] = i - 1;
    if (i + 1 < n) Right[i] = i + 1;
    if (!i) continue;
    if (inp[i] != inp[i - 1]) q.push(data(i - 1, i, abs(a[i] - a[i - 1])));
  }
  vector<pair<int, int> > ans;
  while (!q.empty()) {
    data top = q.top();
    q.pop();
    if (v[top.x] || v[top.y]) continue;
    v[top.x] = v[top.y] = true;
    ans.push_back(make_pair(top.x, top.y));
    Right[Left[top.x]] = Right[top.y];
    Left[Right[top.y]] = Left[top.x];
    if (Left[top.x] > -1 && Right[top.y] > -1 &&
        inp[Left[top.x]] != inp[Right[top.y]])
      q.push(data(Left[top.x], Right[top.y],
                  abs(a[Left[top.x]] - a[Right[top.y]])));
  }
  cout << ((int)ans.size()) << endl;
  for (__typeof(((int)ans.size())) i = 0; i < (((int)ans.size())); i++)
    cout << ans[i].first + 1 << " " << ans[i].second + 1 << endl;
  return 0;
}
