#include <bits/stdc++.h>
using namespace std;
vector<int> v;
struct po {
  int diff;
  int l;
  int r;
  bool operator()(const po& l, const po& r) {
    if (l.diff == r.diff) {
      if (l.l == r.l) return l.r > r.r;
      return l.l > r.l;
    }
    return l.diff > r.diff;
  }
};
vector<po> ans;
int vis[200005];
set<int> pos;
priority_queue<po, vector<po>, po> pq;
int main() {
  int n;
  int x;
  cin >> n;
  string s;
  cin >> s;
  po p;
  for (int i = 0; i < n; i++) {
    cin >> x;
    v.push_back(x);
    pos.insert(i + 1);
  }
  pos.insert(0);
  pos.insert(n + 1);
  for (int i = 0; i < n - 1; i++) {
    if (s[i] != s[i + 1]) {
      p.diff = abs(v[i] - v[i + 1]);
      p.l = i + 1;
      p.r = i + 2;
      pq.push(p);
    }
  }
  int cnt = 0;
  while (!pq.empty()) {
    p = pq.top();
    pq.pop();
    if (!vis[p.l] && !vis[p.r]) {
      cnt++;
      vis[p.l] = 1;
      vis[p.r] = 1;
      pos.erase(p.l);
      pos.erase(p.r);
      ans.push_back(p);
      set<int>::iterator it = (pos.lower_bound(p.l));
      int l = *(--it);
      it = (pos.lower_bound(p.r + 1));
      int r = *it;
      if (l == 0 || r == n + 1) continue;
      if (l >= 1 && r <= n && s[l - 1] != s[r - 1]) {
        po q;
        q.l = l;
        q.r = r;
        q.diff = abs(v[q.l - 1] - v[q.r - 1]);
        pq.push(q);
      }
    }
  }
  cout << cnt << endl;
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i].l << " " << ans[i].r << endl;
  }
  return 0;
}
