#include <bits/stdc++.h>
using namespace std;
struct node {
  node *left, *right;
  int skill, index;
  char gender;
};
class item {
 public:
  node *pos;
  int skill, l_index, r_index;
  item(node *x) {
    assert(x->right != NULL);
    node *y = x->right;
    l_index = x->index;
    r_index = y->index;
    skill = abs((x->skill) - (y->skill));
    pos = x;
  }
};
class item_comp {
 public:
  bool operator()(const item &a, const item &b) const {
    if (a.skill == b.skill) return a.l_index > b.l_index;
    return a.skill > b.skill;
  }
};
int main(void) {
  priority_queue<item, vector<item>, item_comp> Q;
  int n, a[100000 * 2 + 100];
  char s[100000 * 2 + 100];
  scanf("%d", &n);
  scanf("%s", s);
  for (register int i = (0); i < (int)n; ++i) scanf("%d", &a[i]);
  node *now = NULL;
  for (register int i = (0); i < (int)n; ++i) {
    node *tmp = new node;
    if (i) now->right = tmp;
    tmp->index = i;
    tmp->gender = s[i];
    tmp->skill = a[i];
    tmp->left = now;
    tmp->right = NULL;
    if (i != 0 && s[i] != s[i - 1]) {
      item z(now);
      Q.push(z);
    }
    now = tmp;
  }
  bool gone[100000 * 2 + 100];
  memset(gone, 0, sizeof gone);
  vector<pair<int, int> > res;
  while (!Q.empty()) {
    item cur = Q.top();
    Q.pop();
    if (cur.pos == NULL) continue;
    if (cur.pos->right == NULL) continue;
    node *x = cur.pos;
    node *y = x->right;
    if (gone[x->index] || gone[y->index]) continue;
    if (cur.l_index != x->index || cur.r_index != y->index) continue;
    if (x->gender == y->gender) continue;
    if (abs((x->skill) - (y->skill)) != cur.skill) continue;
    res.push_back(make_pair(x->index, y->index));
    gone[x->index] = gone[y->index] = true;
    if (x->left == NULL || y->right == NULL) continue;
    x->left->right = y->right;
    y->right->left = x->left;
    if (x->left->gender != y->right->gender) {
      Q.push(item(x->left));
    }
  }
  printf("%d\n", ((int)(res).size()));
  for (register int i = (0); i < (int)((int)(res).size()); ++i)
    printf("%d %d\n", res[i].first + 1, res[i].second + 1);
  return 0;
}
