#include <bits/stdc++.h>
using namespace std;
int n;
char s[200022];
int ans[200022][3];
int ansLen;
int abs(int a) { return a < 0 ? -a : a; }
int Diff(int a, int b) {
  if (a < 0 && b > 0 || a > 0 && b < 0) return abs(a + b);
  return 1000000000;
}
struct bnode {
  int num;
  bnode *pre, *next;
  int d[500];
  int min, optPos;
  int id[500];
  int tail;
} block[520];
void Update(int v, bool t = false) {
  if (t) {
    block[v].min = 1000000000;
    for (int i = 0; i < block[v].tail; i++) {
      int last = Diff(block[v].d[i], block[v].d[i + 1]);
      if (last < block[v].min) {
        block[v].min = last;
        block[v].optPos = i;
      }
    }
  }
  if (!block[v].next) return;
  int last = Diff(block[v].next->d[0], block[v].d[block[v].tail]);
  if (block[v].tail == 0) block[v].min = 1000000000;
  if (last < block[v].min) {
    block[v].min = last;
    block[v].optPos = block[v].tail;
  }
}
void DeleteB(int v) {
  if (block[v].pre) block[v].pre->next = block[v].next;
  if (block[v].next) block[v].next->pre = block[v].pre;
}
void DeleteP(int v, int pos) {
  for (int j = pos; j < block[v].tail; j++) {
    block[v].d[j] = block[v].d[j + 1];
    block[v].id[j] = block[v].id[j + 1];
  }
  block[v].tail--;
  if (block[v].tail == -1)
    DeleteB(v);
  else
    Update(v, true);
  if (block[v].pre) Update(block[v].pre->num, true);
}
bool Dance() {
  int min = 1000000000, v;
  for (bnode *pb = block[0].next; pb; pb = pb->next)
    if (pb->min < min) min = pb->min, v = pb->num;
  if (min == 1000000000) return false;
  ansLen++;
  ans[ansLen][2] = min;
  if (block[v].optPos == block[v].tail) {
    ans[ansLen][0] = block[v].id[block[v].tail];
    ans[ansLen][1] = block[v].next->id[0];
    DeleteP(v, block[v].tail);
    DeleteP(block[v].next->num, 0);
  } else {
    ans[ansLen][0] = block[v].id[block[v].optPos];
    ans[ansLen][1] = block[v].id[block[v].optPos + 1];
    int t = block[v].optPos;
    DeleteP(v, t);
    DeleteP(v, t);
  }
  return true;
}
void Init() {
  block[0].next = &block[1];
  for (int i = 1; i <= n / 500 + 1; i++) {
    block[i].num = i;
    block[i].pre = &block[i - 1];
    block[i].next = &block[i + 1];
    block[i].min = 1000000000;
  }
  block[(n - 1) / 500 + 1].next = 0;
}
int main() {
  ansLen = 0;
  scanf("%d", &n);
  scanf("%s", s);
  Init();
  for (int i = 0; i < n; i++) {
    block[i / 500 + 1].d[i % 500] = s[i] == 'B' ? -1 : 1;
    block[i / 500 + 1].id[i % 500] = i + 1;
    block[i / 500 + 1].tail = i % 500;
  }
  for (int i = 0; i < n; i++) {
    int t;
    scanf("%d", &t);
    block[i / 500 + 1].d[i % 500] *= t;
  }
  for (int i = 1; i <= n / 500 + 1; i++) Update(i, true);
  while (Dance())
    ;
  printf("%d\n", ansLen);
  for (int i = 1; i <= ansLen; i++) printf("%d %d\n", ans[i][0], ans[i][1]);
  return 0;
}
