#include <bits/stdc++.h>
using namespace std;
template <class T1>
void deb(T1 e1) {
  cout << e1 << endl;
}
template <class T1, class T2>
void deb(T1 e1, T2 e2) {
  cout << e1 << " " << e2 << endl;
}
template <class T1, class T2, class T3>
void deb(T1 e1, T2 e2, T3 e3) {
  cout << e1 << " " << e2 << " " << e3 << endl;
}
template <class T1, class T2, class T3, class T4>
void deb(T1 e1, T2 e2, T3 e3, T4 e4) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << endl;
}
template <class T1, class T2, class T3, class T4, class T5>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << endl;
}
template <class T1, class T2, class T3, class T4, class T5, class T6>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << " " << e6
       << endl;
}
struct data {
  int lpos, rpos, mn_diff;
  pair<int, int> pr;
  data() {}
} tree[4 * 200000 + 7];
int n, arr[200000 + 7];
char str[200000 + 7];
data build(int node, int base, int top) {
  data &ret = tree[node];
  if (base == top) {
    ret.pr = make_pair(-1, -1);
    ret.lpos = ret.rpos = base;
    ret.mn_diff = 100000000;
    return ret;
  }
  int left, right, mid;
  int d;
  left = 2 * node;
  right = left + 1;
  mid = (base + top) / 2;
  data a = build(left, base, mid);
  data b = build(right, mid + 1, top);
  if (str[a.rpos] != str[b.lpos]) {
    d = abs(arr[a.rpos] - arr[b.lpos]);
    if (d <= b.mn_diff) {
      ret.mn_diff = d;
      ret.pr = make_pair(a.rpos, b.lpos);
    } else {
      ret.mn_diff = b.mn_diff;
      ret.pr = b.pr;
    }
  } else {
    ret.mn_diff = b.mn_diff;
    ret.pr = b.pr;
  }
  if (a.mn_diff <= ret.mn_diff) {
    ret.mn_diff = a.mn_diff;
    ret.pr = a.pr;
  }
  ret.lpos = a.lpos;
  ret.rpos = b.rpos;
  return ret;
}
data update(int node, int base, int top, int p) {
  data &ret = tree[node];
  if (base > p or top < p) return tree[node];
  if (base == top) {
    ret.lpos = ret.rpos = -1;
    ret.pr = make_pair(-1, -1);
    ret.mn_diff = 100000000;
    return ret;
  }
  int left, right, mid;
  int d;
  left = 2 * node;
  right = left + 1;
  mid = (base + top) / 2;
  data a = update(left, base, mid, p);
  data b = update(right, mid + 1, top, p);
  if (a.lpos == -1) return ret = b;
  if (b.lpos == -1) return ret = a;
  if (str[a.rpos] != str[b.lpos]) {
    d = abs(arr[a.rpos] - arr[b.lpos]);
    if (d <= b.mn_diff) {
      ret.mn_diff = d;
      ret.pr = make_pair(a.rpos, b.lpos);
    } else {
      ret.mn_diff = b.mn_diff;
      ret.pr = b.pr;
    }
  } else {
    ret.mn_diff = b.mn_diff;
    ret.pr = b.pr;
  }
  if (a.mn_diff <= ret.mn_diff) {
    ret.mn_diff = a.mn_diff;
    ret.pr = a.pr;
  }
  ret.lpos = a.lpos;
  ret.rpos = b.rpos;
  return ret;
}
int main() {
  int sz, i, j, k;
  data ret;
  vector<pair<int, int> > ans;
  scanf("%d", &n);
  scanf("%s", str + 1);
  for (i = 1; i <= n; i++) {
    scanf("%d", &arr[i]);
  }
  ret = build(1, 1, n);
  while (ret.pr.first != -1) {
    ans.push_back(ret.pr);
    update(1, 1, n, ret.pr.first);
    ret = update(1, 1, n, ret.pr.second);
  }
  sz = ans.size();
  printf("%d\n", sz);
  for (i = 0; i < sz; i++) {
    printf("%d %d\n", ans[i].first, ans[i].second);
  }
  return 0;
}
