#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  string str;
  cin >> str;
  char ch[n + 5];
  long long lvl[n + 5];
  long long l[n + 5];
  long long r[n + 5];
  for (long long i = 1; i <= n; i++) ch[i] = str[i - 1];
  for (long long i = 1; i <= n; i++) cin >> lvl[i];
  for (int i = 1; i <= n; i++) {
    l[i] = i - 1;
    r[i] = i + 1;
  }
  vector<pair<long long, long long>> ans;
  set<pair<long long, long long>> second;
  for (long long i = 1; i < n; i++) {
    if (ch[i] != ch[i + 1]) {
      second.insert(make_pair(abs(lvl[i] - lvl[i + 1]), i));
    }
  }
  while (second.size()) {
    auto it = second.begin();
    long long a = it->second;
    long long b = r[a];
    second.erase(it);
    ans.push_back(make_pair(a, b));
    if (l[a] != 0 and ch[l[a]] != ch[a])
      second.erase(make_pair(abs(lvl[l[a]] - lvl[a]), l[a]));
    if (r[b] != n + 1 and ch[r[b]] != ch[b])
      second.erase(make_pair(abs(lvl[r[b]] - lvl[b]), b));
    if (l[a] != 0 and r[b] != n + 1 and ch[l[a]] != ch[r[b]])
      second.insert(make_pair(abs(lvl[l[a]] - lvl[r[b]]), l[a]));
    if (l[a] != -1) r[l[a]] = r[b];
    if (r[b] != n + 1) l[r[b]] = l[a];
  }
  cout << ans.size() << "\n";
  for (long long i = 0; i < ans.size(); i++)
    cout << ans[i].first << " " << ans[i].second << "\n";
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long t;
  t = 1;
  while (t--) solve();
  return 0;
}
