#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, inf = 1e9 + 7;
set<pair<int, pair<int, int> > > st;
int lft[N], rgt[N], vis[N];
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    if (i == 1)
      lft[i] = -1;
    else
      lft[i] = i - 1;
    if (i == n)
      rgt[i] = -1;
    else
      rgt[i] = i + 1;
  }
  string s, ss;
  cin >> ss;
  s = "#" + ss;
  int Arr[n + 2];
  for (int i = 1; i <= n; i++) cin >> Arr[i];
  for (int i = 1; i < n; i++) {
    if (s[i] == s[i + 1]) continue;
    st.insert(make_pair(abs(Arr[i] - Arr[i + 1]), make_pair(i, i + 1)));
  }
  vector<pair<int, int> > res;
  set<pair<int, pair<int, int> > >::iterator it;
  while (!st.empty()) {
    it = st.begin();
    int l = it->second.first, r = it->second.second;
    if (vis[l] || vis[r]) {
      st.erase(it);
      continue;
    }
    vis[l] = vis[r] = true;
    res.push_back(make_pair(l, r));
    if (lft[l] != -1) rgt[lft[l]] = rgt[r];
    if (rgt[r] != -1) lft[rgt[r]] = lft[l];
    if (lft[l] != -1 && rgt[r] != -1 && s[lft[l]] != s[rgt[r]]) {
      st.insert(
          make_pair(abs(Arr[lft[l]] - Arr[rgt[r]]), make_pair(lft[l], rgt[r])));
      lft[l] = rgt[r] = -1;
    }
    st.erase(it);
  }
  cout << res.size() << "\n";
  for (auto x : res) cout << x.first << " " << x.second << "\n";
}
