#include <bits/stdc++.h>
using namespace std;
long long BigMod(long long B, long long P, long long M) {
  long long R = 1;
  while (P > 0) {
    if (P % 2 == 1) {
      R = (R * B) % M;
    }
    P /= 2;
    B = (B * B) % M;
  }
  return R;
}
struct data {
  int dif, L, R;
  bool operator<(const data &a) const {
    if (a.dif < dif) return 1;
    if (a.dif > dif) return 0;
    if (a.dif == dif) return a.L < L;
  }
};
priority_queue<data> Q;
set<int> st;
int ara[200005];
vector<pair<int, int> > v;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  int n;
  cin >> n;
  string str;
  cin >> str;
  for (int i = 0; i < n; i++) cin >> ara[i];
  for (int i = 0; i < n; i++) st.insert(i);
  for (int i = 0; i < str.size() - 1; i++)
    if (str[i] != str[i + 1])
      Q.push({((ara[i] - ara[i + 1]) < 0 ? -(ara[i] - ara[i + 1])
                                         : (ara[i] - ara[i + 1])),
              i, i + 1});
  while (not Q.empty()) {
    data A = Q.top();
    Q.pop();
    if (st.find(A.L) == st.end()) continue;
    if (st.find(A.R) == st.end()) continue;
    v.push_back({A.L, A.R});
    st.erase(st.find(A.L));
    st.erase(st.find(A.R));
    auto it = st.upper_bound(A.R);
    auto pt = st.lower_bound(A.L);
    if (pt == st.begin()) continue;
    pt--;
    if (it == st.end()) continue;
    if (str[*pt] != str[*it]) {
      Q.push({((ara[*pt] - ara[*it]) < 0 ? -(ara[*pt] - ara[*it])
                                         : (ara[*pt] - ara[*it])),
              *pt, *it});
    }
  }
  cout << v.size() << "\n";
  for (int i = 0; i < v.size(); i++) {
    cout << v[i].first + 1 << " " << v[i].second + 1 << "\n";
  }
}
