#include <bits/stdc++.h>
struct BG {
  int diff;
  int pos;
  int second;
  BG() {}
  BG(int diff, int pos, int second) : diff(diff), pos(pos), second(second) {}
  bool operator<(BG const& p) const {
    if (diff != p.diff) return diff > p.diff;
    return pos > p.pos;
  }
};
struct Using {
  int n;
  std::vector<int> next;
  std::vector<int> prev;
  Using() {}
  Using(int n) : n(n) {
    next.resize(n);
    for (int i = 0; i < n; ++i) next[i] = i;
    prev.resize(n);
    for (int i = 0; i < n; ++i) prev[i] = i;
  }
  void use(int i) {
    if (!used(i)) {
      next[i] = i + 1;
      prev[i] = i - 1;
    }
  }
  int get_next(int i) {
    if (i == n) return n;
    if (next[i] != i) {
      next[i] = get_next(next[i]);
    }
    return next[i];
  }
  int get_prev(int i) {
    if (i == -1) return -1;
    if (prev[i] != i) {
      prev[i] = get_prev(prev[i]);
    }
    return prev[i];
  }
  bool used(int i) { return next[i] != i; }
};
int const N = 200100;
char s[N];
int a[N];
int main() {
  int n;
  scanf("%d", &n);
  Using poses(n);
  scanf("%s", s);
  for (int i = 0; i < n; ++i) scanf("%d", a + i);
  std::priority_queue<BG> pairs;
  for (int i = 0; i + 1 < n; ++i) {
    if (s[i] != s[i + 1]) {
      pairs.push(BG(std::abs(a[i] - a[i + 1]), i, i + 1));
    }
  }
  std::vector<BG> ans;
  while (!pairs.empty()) {
    BG p = pairs.top();
    pairs.pop();
    if (poses.used(p.pos) || poses.used(p.second)) continue;
    ans.push_back(p);
    poses.use(p.pos);
    poses.use(p.second);
    int i = poses.get_prev(p.pos);
    int j = poses.get_next(p.second);
    if (i != -1 && j != n && s[i] != s[j]) {
      pairs.push(BG(std::abs(a[i] - a[j]), i, j));
    }
  }
  printf("%d\n", (int)ans.size());
  for (BG p : ans) {
    printf("%d %d\n", p.pos + 1, p.second + 1);
  }
}
