#include <bits/stdc++.h>
using namespace std;
const int M = 300100;
struct partners {
  int diff, l, r;
  partners(int a = 0, int b = 0, int c = 0) {
    diff = a;
    l = b;
    r = c;
  }
  bool operator<(const partners &d) const {
    if (diff == d.diff)
      return l > d.l;
    else
      return diff > d.diff;
  }
};
priority_queue<partners> q;
set<int> pos;
int visited[M], A[M];
char typ[M];
vector<pair<int, int> > ans;
int main() {
  int n, i, j, k, temp;
  scanf("%d", &n);
  scanf("%s", typ);
  for (i = 0; i < n; i++) scanf("%d", &A[i]), pos.insert(i);
  for (i = 1; i < n; i++) {
    if (typ[i] != typ[i - 1]) {
      q.push(partners(abs(A[i] - A[i - 1]), i - 1, i));
    }
  }
  memset((visited), (false), sizeof(visited));
  while (!q.empty()) {
    partners u = q.top();
    q.pop();
    if (visited[u.l] || visited[u.r]) continue;
    visited[u.l] = visited[u.r] = true;
    pos.erase(u.l);
    pos.erase(u.r);
    ans.push_back(make_pair(u.l + 1, u.r + 1));
    set<int>::iterator lt = pos.upper_bound(u.l), rt = pos.upper_bound(u.r);
    if (lt != pos.begin()) {
      lt--;
      if (rt != pos.end()) {
        if (typ[*lt] != typ[*rt]) {
          q.push(partners(abs(A[*lt] - A[*rt]), *lt, *rt));
        }
      }
    }
  }
  printf("%d\n", ans.size());
  for (i = 0; i < ans.size(); i++)
    printf("%d %d\n", ans[i].first, ans[i].second);
  return 0;
}
