#include <bits/stdc++.h>
using namespace std;
const int NN = 200000 + 8;
int N, Pre[NN], Nxt[NN], Idx[NN];
int Val[NN];
char is[NN];
int head, tail;
int iabs(int v) { return v < 0 ? -v : v; }
int main(int argc, char *argv[]) {
  scanf("%d", &N);
  scanf("%s", is + 1);
  for (int i = 1; i <= N; ++i) {
    scanf("%d", Val + i);
    Pre[i] = i - 1;
    Nxt[i] = i + 1;
  }
  Nxt[0] = 1;
  tail = N + 1;
  head = 0;
  Pre[tail] = N;
  set<pair<int, int> > g;
  for (int i = 1; i < N; ++i) {
    if (is[i] != is[i + 1]) {
      g.insert(make_pair(iabs(Val[i] - Val[i + 1]), i));
    }
  }
  vector<pair<int, int> > ans;
  while (!g.empty()) {
    pair<int, int> t = *g.begin();
    g.erase(t);
    int i = t.second;
    ans.push_back(make_pair(i, Nxt[i]));
    int j = Nxt[i];
    if (Nxt[j] != tail) {
      if (is[j] != is[Nxt[j]]) {
        g.erase(make_pair(iabs(Val[j] - Val[Nxt[j]]), j));
      }
    }
    if (Pre[i] != head) {
      if (is[i] != is[Pre[i]]) {
        g.erase(make_pair(iabs(Val[i] - Val[Pre[i]]), Pre[i]));
      }
    }
    int ns = Pre[i], ne = Nxt[j];
    if (ns != head && ne != tail) {
      if (is[ns] != is[ne]) {
        g.insert(make_pair(iabs(Val[ns] - Val[ne]), ns));
      }
    }
    Pre[Nxt[j]] = Pre[j];
    Nxt[Pre[j]] = Nxt[j];
    Pre[Nxt[i]] = Pre[i];
    Nxt[Pre[i]] = Nxt[i];
  }
  printf("%d\n", (int)ans.size());
  for (int i = 0; i < ans.size(); ++i)
    printf("%d %d\n", ans[i].first, ans[i].second);
  return 0;
}
