#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200000 + 10;
struct st {
  int a, b;
  st(int A, int B) {
    a = A;
    b = B;
  }
};
int n, num[MAXN], tree[MAXN];
char g[MAXN];
bool mark[MAXN];
vector<pair<int, int> > answer;
struct cmp {
  bool operator()(const st &a, const st &b) {
    return abs(num[a.a] - num[a.b]) != abs(num[b.a] - num[b.b])
               ? abs(num[a.a] - num[a.b]) < abs(num[b.a] - num[b.b])
               : a.a < b.b;
  }
};
set<st, cmp> sit;
void do_add(int k, int x) {
  while (k <= MAXN) {
    tree[k] += x;
    k += (k & -k);
  }
}
int do_get(int k) {
  int ans = 0;
  while (k) {
    ans += tree[k];
    k -= (k & -k);
  }
  return ans;
}
int find_prev(int k) {
  int b = 0, e = k - 1;
  int x = do_get(k);
  while (b < e) {
    int m = (b + e) / 2;
    if (do_get(m) < x)
      b = m + 1;
    else
      e = m;
  }
  return b;
}
int find_next(int k) {
  if (do_get(n) == do_get(k)) return 0;
  int b = k + 1, e = n;
  int x = do_get(k);
  while (b < e) {
    int m = (b + e) / 2;
    if (do_get(m) <= x)
      b = m + 1;
    else
      e = m;
  }
  return b;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf(" %c", &g[i]);
  for (int i = 1; i <= n; i++) scanf("%d", &num[i]);
  for (int i = 1; i <= n; i++) do_add(i, 1);
  for (int i = 1; i < n; i++)
    if (g[i] != g[i + 1]) sit.insert(st(i, i + 1));
  while (!sit.empty()) {
    st h = *sit.begin();
    sit.erase(sit.begin());
    if (!mark[h.a] && !mark[h.b]) {
      mark[h.a] = mark[h.b] = 1;
      answer.push_back(pair<int, int>(h.a, h.b));
      do_add(h.a, -1);
      do_add(h.b, -1);
      int a = find_prev(h.a);
      int b = find_next(h.b);
      if (a != 0 && b != 0 && g[a] != g[b]) sit.insert(st(a, b));
    }
  }
  printf("%d\n", answer.size());
  for (int i = 0; i < answer.size(); i++)
    printf("%d %d\n", answer[i].first, answer[i].second);
  return 0;
}
