#include<bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;

int N, endbit, Mask;
int dp[1 << 16][16];

int rec(int bit, int ptr){
  if(bit == endbit) return 0;
  if(~dp[bit][ptr]) return dp[bit][ptr];
  int ret = INF;
  for(int i = 0; i < N; i++){
    if((bit ^ endbit) & (1 << i)){
      for(int j = i + 1; j < N; j++){
        if((bit ^ endbit) & (1 << j) && ((bit >> i) ^ (bit >> j)) & 1){
          int nextbit = bit ^ (1 << i) ^ (1 << j);
          int cost = abs(ptr - i) + j - i;
          ret = min( ret, rec( nextbit, j) + cost);
          cost = abs(ptr - j) + j - i;
          ret = min( ret, rec( nextbit, i) + cost);
        }
      }
    }
  }
  return dp[bit][ptr] = ret;
}

int main(){
  int bit;
  string A, B;

  while(cin >> N, N){
    cin >> A >> B;

    Mask = (1 << N) - 1;
    bit = 0, endbit = 0;
    for(int i = 0; i < A.length(); i++){
      bit |= (A[i] == 'W') << i;
      endbit |= (B[i] == 'W') << i;
    }

    fill_n( *dp, (1 << 16) * 16, -1);
    int ret = INF;
    for(int i = 0; i < A.length(); i++){
      ret = min( ret, rec(bit, i));
    }
    cout << ret << endl;
  }
}