stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef long double ld;



const int N = 2e5 + 5;

int arr[N];

int main() {

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    int n, m;

    cin >> n >> m;

    ll res = 0;

    priority_queue<ld> pq;

    for (int i = 0; i < n; i++) {

        ld in;

        cin >> in;

        pq.push(in);

    }

    for (int i = 0; i < m; i++) {

        ld curr = pq.top();

        pq.pop();

        pq.push(curr / 2);

    }

    for (int i = 0; i < n; i++) {

        res += pq.top();

        pq.pop();

    }

    cout << res;

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.2410234276737155x):
#include <cstdio>

#include <cctype>

#include <queue>

#define int long long



std::priority_queue<int > a;

int n, m;



int read() {

    int ret, f = 1;

    char ch;

    while(!isdigit(ch = getchar())) (ch == '-') && (f = -1);

    for(ret = ch - '0'; isdigit(ch = getchar()); ret *= 10, ret += ch - '0');

    return ret * f;

}



void print(int x) {

    if(x < 0) putchar('-'), x = -x;

    if(x > 9) print(x / 10);

    putchar(x % 10 + '0');

}



signed main() {

    n = read(), m = read();

    for(int i = 1; i <= n; ++i) a.push(read());

    while(m--) {

        int t = a.top();

        a.pop();

        a.push(t >> 1);

    }

    int ans = 0;

    while(!a.empty()) ans += a.top(), a.pop();

    print(ans);

    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define ll long long

using namespace std;



bool cmp(const pair<int, int> &a, const pair<int, int> &b){

	if (a.second == b.second)

		return a.first < b.first;

	return a.second < b.second;

}



int main() {

	IO

	int n, m;

	cin >> n >> m;

	ll x;

	priority_queue <ll> pq;

	while (n--){

		cin >> x;

		pq.push(x);

	}

	while (m--){

		x = pq.top();

		pq.pop();

		x /= 2;

		pq.push(x);

	}

	ll sum = 0;

	while (pq.size()){

		sum += pq.top();

		pq.pop();

	}

	cout << sum;

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.110746250920792x):
#include <cstdio>

#include <cctype>

#include <queue>

#define int long long



std::priority_queue<int > a;

int n, m;



int read() {

    int ret, f = 1;

    char ch;

    while(!isdigit(ch = getchar())) (ch == '-') && (f = -1);

    for(ret = ch - '0'; isdigit(ch = getchar()); ret *= 10, ret += ch - '0');

    return ret * f;

}



void print(int x) {

    if(x < 0) putchar('-'), x = -x;

    if(x > 9) print(x / 10);

    putchar(x % 10 + '0');

}



signed main() {

    n = read(), m = read();

    for(int i = 1; i <= n; ++i) a.push(read());

    while(m--) {

        int t = a.top();

        a.pop();

        a.push(t >> 1);

    }

    int ans = 0;

    while(!a.empty()) ans += a.top(), a.pop();

    print(ans);

    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;





void Egriiiiiiiii()

{

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

}







int main()

{

     Egriiiiiiiii() ;



     /*

    int n,m ;

    cin>>n>>m;

for(int i=0 ;i<m ;i++){

    int x,y;

    cin>>x>>y;

    adj[x].push_back(y) ;

}

for(int i=1;i<=n;i++){

    dfs(i) ;

}

for(int i=0 ;i<v.size() ;i++)

    cout<<v[i]<<" ";



*/



int n,m ;

cin>>n>>m ;

priority_queue<int>pq;

int a ;

for(int i=0 ;i<n ;i++)

     cin>>a, pq.push(a) ;

for(int i=0 ;i<m ;i++){

     int y=pq.top() ;

     pq.pop() ;

     pq.push(y/2) ;

}

ll ans=0 ;

while(!pq.empty()){

    ans+=pq.top() ;

    pq.pop()  ;

}

cout<<ans ;



     return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.1057375132622413x):
#include <cstdio>

#include <cctype>

#include <queue>

#define int long long



std::priority_queue<int > a;

int n, m;



int read() {

    int ret, f = 1;

    char ch;

    while(!isdigit(ch = getchar())) (ch == '-') && (f = -1);

    for(ret = ch - '0'; isdigit(ch = getchar()); ret *= 10, ret += ch - '0');

    return ret * f;

}



void print(int x) {

    if(x < 0) putchar('-'), x = -x;

    if(x > 9) print(x / 10);

    putchar(x % 10 + '0');

}



signed main() {

    n = read(), m = read();

    for(int i = 1; i <= n; ++i) a.push(read());

    while(m--) {

        int t = a.top();

        a.pop();

        a.push(t >> 1);

    }

    int ans = 0;

    while(!a.empty()) ans += a.top(), a.pop();

    print(ans);

    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define pb push_back

#define mp make_pair

#define pii pair <int, int>

#define fi first

#define sc second

#define ALL(x) x.begin(), x.end()

#define RALL(X) x.begin(), x.end()

#define FOR(i, n, k) for(i=0; i<n; i+=k)

#define FO(i, n, k) for(i=1; i<=n; i+=k)

#define CLEAR(a, b) memset(a, b, sizeof(a))

#define N 100005

#define mid ((l+r)/2)

#define dbg(x) (cerr << #x << " : " << x << endl)

#define endl "\n"

#define MOD 100000009



using namespace std;



typedef long long lli;

#define int long long



signed main(){

	ios_base::sync_with_stdio(false);

	int n, m;

	cin >> n >> m;

	priority_queue <int> pq;

	for(int i=0; i<n; i++){

		int x;

		cin >> x;

		pq.push(x);

	}	



	for(int i=0; i<m; i++){

		int tp = pq.top();

		pq.pop();

		tp /= 2;

		pq.push(tp);

	}



	int res=0;

	while(!pq.empty()){

		res += pq.top();

		pq.pop();

	}



	cout << res;



	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.1081753034672168x):
#include <cstdio>

#include <cctype>

#include <queue>

#define int long long



std::priority_queue<int > a;

int n, m;



int read() {

    int ret, f = 1;

    char ch;

    while(!isdigit(ch = getchar())) (ch == '-') && (f = -1);

    for(ret = ch - '0'; isdigit(ch = getchar()); ret *= 10, ret += ch - '0');

    return ret * f;

}



void print(int x) {

    if(x < 0) putchar('-'), x = -x;

    if(x > 9) print(x / 10);

    putchar(x % 10 + '0');

}



signed main() {

    n = read(), m = read();

    for(int i = 1; i <= n; ++i) a.push(read());

    while(m--) {

        int t = a.top();

        a.pop();

        a.push(t >> 1);

    }

    int ans = 0;

    while(!a.empty()) ans += a.top(), a.pop();

    print(ans);

    return 0;

}
// Slower C++ solution:
#include <iostream>

#include <algorithm>

#include <set>

#include <numeric>



using namespace std;



int main()

{

    int n, m;

    cin >> n >> m;

    multiset<int> s;

    int tmp;

    for (int i = 0; i != n; ++i)

    {

        cin >> tmp;

        s.insert(tmp);

    }

    while (m--)

    {

        // cout << *(--s.end()) << '?' << endl;

        s.insert(*(--s.end()) / 2);

        s.erase(--s.end());

    }

    // for (auto i : s) cout << i << ' '; cout << endl;

    cout << accumulate(s.begin(), s.end(), 0LL) << endl;

}

// Faster C++ solution for the same problem (measured speedup: 1.1956942826624621x):
#include <cstdio>

#include <cctype>

#include <queue>

#define int long long



std::priority_queue<int > a;

int n, m;



int read() {

    int ret, f = 1;

    char ch;

    while(!isdigit(ch = getchar())) (ch == '-') && (f = -1);

    for(ret = ch - '0'; isdigit(ch = getchar()); ret *= 10, ret += ch - '0');

    return ret * f;

}



void print(int x) {

    if(x < 0) putchar('-'), x = -x;

    if(x > 9) print(x / 10);

    putchar(x % 10 + '0');

}



signed main() {

    n = read(), m = read();

    for(int i = 1; i <= n; ++i) a.push(read());

    while(m--) {

        int t = a.top();

        a.pop();

        a.push(t >> 1);

    }

    int ans = 0;

    while(!a.empty()) ans += a.top(), a.pop();

    print(ans);

    return 0;

}
// Slower C++ solution:
#include <cstdint>

#include <iostream>

#include <queue>



using std::cin;

using std::cout;

using std::priority_queue;



int main() {

    std::ios::sync_with_stdio(false);

    cin.tie(nullptr);



    int n, m;

    cin >> n >> m;

    int64_t             sum = 0;

    priority_queue<int> heap;

    while (n--) {

        int price;

        cin >> price;

        heap.push(price);

        sum += price;

    }

    for (int y = 0; y < m; ++y) {

        int max_price = heap.top();

        int cur_price = max_price >> 1;

        heap.pop();

        heap.push(cur_price);

        sum -= max_price - cur_price;

        if (!sum) break;

    }

    cout << sum << '\n';

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.0969358815693095x):
#include <cstdio>

#include <cctype>

#include <queue>

#define int long long



std::priority_queue<int > a;

int n, m;



int read() {

    int ret, f = 1;

    char ch;

    while(!isdigit(ch = getchar())) (ch == '-') && (f = -1);

    for(ret = ch - '0'; isdigit(ch = getchar()); ret *= 10, ret += ch - '0');

    return ret * f;

}



void print(int x) {

    if(x < 0) putchar('-'), x = -x;

    if(x > 9) print(x / 10);

    putchar(x % 10 + '0');

}



signed main() {

    n = read(), m = read();

    for(int i = 1; i <= n; ++i) a.push(read());

    while(m--) {

        int t = a.top();

        a.pop();

        a.push(t >> 1);

    }

    int ans = 0;

    while(!a.empty()) ans += a.top(), a.pop();

    print(ans);

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const int MAXN = 1e5 + 10;



priority_queue<ll> pq;



int main() {

	ios::sync_with_stdio(false);

	ll n, m, a;

	while(cin >> n >> m) {

		while(!pq.empty()) pq.pop();

		for(int i = 0; i < n; i++) {

			cin >> a;

			pq.push(a);

		}

		for(int i = 0; i < m; i++) {

			ll t = pq.top();

			pq.pop();

			pq.push(t / 2);

		}

		ll ans = 0;

		while(!pq.empty()) {

			ans += pq.top();

			pq.pop();

		}

		cout << ans << endl;

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.0997885692393337x):
#include <cstdio>

#include <cctype>

#include <queue>

#define int long long



std::priority_queue<int > a;

int n, m;



int read() {

    int ret, f = 1;

    char ch;

    while(!isdigit(ch = getchar())) (ch == '-') && (f = -1);

    for(ret = ch - '0'; isdigit(ch = getchar()); ret *= 10, ret += ch - '0');

    return ret * f;

}



void print(int x) {

    if(x < 0) putchar('-'), x = -x;

    if(x > 9) print(x / 10);

    putchar(x % 10 + '0');

}



signed main() {

    n = read(), m = read();

    for(int i = 1; i <= n; ++i) a.push(read());

    while(m--) {

        int t = a.top();

        a.pop();

        a.push(t >> 1);

    }

    int ans = 0;

    while(!a.empty()) ans += a.top(), a.pop();

    print(ans);

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>



#define ll long long 



using namespace std;

int main(){

	int n,m;

	priority_queue<int>q;

	cin>>n>>m;

	ll w;

	while(n--){

		cin>>w;

		q.push(w);

	}

	ll ans = 0;

	while(m){

		w = q.top()/2;

		q.pop();

		q.push(w);

		m--;

	}

	while(!q.empty()){

		ans += q.top();

		q.pop();

	}

	cout<<ans<<endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.0927120054269759x):
#include <cstdio>

#include <cctype>

#include <queue>

#define int long long



std::priority_queue<int > a;

int n, m;



int read() {

    int ret, f = 1;

    char ch;

    while(!isdigit(ch = getchar())) (ch == '-') && (f = -1);

    for(ret = ch - '0'; isdigit(ch = getchar()); ret *= 10, ret += ch - '0');

    return ret * f;

}



void print(int x) {

    if(x < 0) putchar('-'), x = -x;

    if(x > 9) print(x / 10);

    putchar(x % 10 + '0');

}



signed main() {

    n = read(), m = read();

    for(int i = 1; i <= n; ++i) a.push(read());

    while(m--) {

        int t = a.top();

        a.pop();

        a.push(t >> 1);

    }

    int ans = 0;

    while(!a.empty()) ans += a.top(), a.pop();

    print(ans);

    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;

const int N=3e5+5;

#define F first

#define S second

pair<int, pair<int,int> > f(pair<int, pair<int,int> > x)

{

    int num=x.S.F;

    int cnt=x.S.S;

    return {num/(1<<cnt)-num/(1<<(cnt+1)),{num,cnt+1}};

}

int main()

{

    ios_base::sync_with_stdio(0);

    cin.tie(0);cout.tie(0);

    int n,m;

    cin>>n>>m;

    priority_queue< pair<int, pair<int,int> > >pq;

    long long sum=0;

    for(int i=0;i<n;i++)

    {

        int x;

        cin>>x;

        sum+=x;

        pq.push(f({0,{x,0}}));

    }

    long long ans=0;



    while(m--)

    {

        pair<int, pair<int,int> > t =pq.top();

        pq.pop();

        if(t.F==0) break;

        ans+=t.F;

        pq.push(f(t));

    }



    cout<<sum-ans<<endl;

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.0893964915089243x):
#include <cstdio>

#include <cctype>

#include <queue>

#define int long long



std::priority_queue<int > a;

int n, m;



int read() {

    int ret, f = 1;

    char ch;

    while(!isdigit(ch = getchar())) (ch == '-') && (f = -1);

    for(ret = ch - '0'; isdigit(ch = getchar()); ret *= 10, ret += ch - '0');

    return ret * f;

}



void print(int x) {

    if(x < 0) putchar('-'), x = -x;

    if(x > 9) print(x / 10);

    putchar(x % 10 + '0');

}



signed main() {

    n = read(), m = read();

    for(int i = 1; i <= n; ++i) a.push(read());

    while(m--) {

        int t = a.top();

        a.pop();

        a.push(t >> 1);

    }

    int ans = 0;

    while(!a.empty()) ans += a.top(), a.pop();

    print(ans);

    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;



#define el				'\n'

#define sz(v)			((int)((v).size()))

#define all(v)          ((v).begin()),((v).end())

#define clr(v, d)		memset(v, d, sizeof(v))



double const EPS = 1e-8, PI = acos(-1);

const int N = 2e5 + 9, M = 50 + 9, OO = (int) 1e9 + 1;

const long long MOD = 1e9 + 7;



typedef long long ll;



void OUTPUT() {

	cout << fixed << setprecision(12);

	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

}



void INPUT() {

#ifndef ONLINE_JUDGE

	freopen("input.txt", "r", stdin);

	//freopen("output.txt", "w", stdout);

#endif

	cout << fixed << setprecision(12);

//	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

}



int n, m, x, y;

priority_queue<int> v;

ll cnt;



int main() {

	OUTPUT();

//	INPUT();

	cin >> n >> m;

	for (int i = 0; i < n; ++i) {

		cin >> x;

		v.push(x);

	}

	while (m && !v.empty()) {

		y = v.top();

		v.pop();

		y /= 2;

		if (y != 0)

			v.push(y);

		m--;

	}

	while (!v.empty()) {

		y = v.top();

		v.pop();

		cnt += y;

	}

	cout << cnt;



	return 0;



}


// Faster C++ solution for the same problem (measured speedup: 1.0882674819372697x):
#include <cstdio>

#include <cctype>

#include <queue>

#define int long long



std::priority_queue<int > a;

int n, m;



int read() {

    int ret, f = 1;

    char ch;

    while(!isdigit(ch = getchar())) (ch == '-') && (f = -1);

    for(ret = ch - '0'; isdigit(ch = getchar()); ret *= 10, ret += ch - '0');

    return ret * f;

}



void print(int x) {

    if(x < 0) putchar('-'), x = -x;

    if(x > 9) print(x / 10);

    putchar(x % 10 + '0');

}



signed main() {

    n = read(), m = read();

    for(int i = 1; i <= n; ++i) a.push(read());

    while(m--) {

        int t = a.top();

        a.pop();

        a.push(t >> 1);

    }

    int ans = 0;

    while(!a.empty()) ans += a.top(), a.pop();

    print(ans);

    return 0;

}
// Slower C++ solution:
#include <algorithm>

#include <iostream>

#include <queue>



using namespace std;



int main()

{

	int n, m;

	cin >> n >> m;

	

	priority_queue<long> que;

	long a[100000] = {};

	for (int i = 0; i < n; i++) {

		cin >> a[i];

		que.push(a[i]);

	}

	

	long temp;

	while(m--) {

		temp = que.top();

		que.pop();

		temp /= 2;

		que.push(temp);

	}

	

	long long sum = 0;

	for (int i = 0; i < n; i++) {

		sum += que.top();

		que.pop();

	}

	

	cout << sum;

}


// Faster C++ solution for the same problem (measured speedup: 1.770671241388021x):
#include <iostream>

#include <queue>



using namespace std;



int main()

{

  int n, m; cin >> n >> m;

  

  priority_queue<int> pq;

  while (n--) {

    int a; cin >> a;

    pq.push(a);

  }

  

  while (m--) {

    pq.push(pq.top()/2);

    pq.pop();

  }

  

  long long ans = 0;

  while (pq.size()) {

    ans += pq.top();

    pq.pop();

  }

  

  cout << ans << endl;

  return 0;

}
// Slower C++ solution:
#include<iostream>

using namespace std;

int main()

{

	int s[10] = {0}, i, a, n,j;

	while (1) {

		cin >> n;

		if (n == 0)

			break;

		for (i = 0; i < n; i++) {

			cin >> a;

			s[a]++;

		}

		for (i = 0; i < 10; i++) {

			if (s[i] == 0)

				cout << "-";

			else {

				for (j = 0; j < s[i]; j++) {

					cout << "*";

				}

			}

			cout << endl;

			s[i] = 0;

		}

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.157587887584372x):
#include<stdio.h>

int main()

{

	int a,s[10]={},b;

	scanf("%d",&a);

	while(a!=0){

	for(int i=0;i<a;i++){

		scanf("%d",&b);

		s[b]++;

	}

	for(int i=0;i<10;i++){

		for(int j=0;j<s[i];j++){

			printf("*");

		}

		if(s[i]==0)

			printf("-");

		printf("\n");

	}

	for(int i=0;i<10;i++){

		s[i]=0;

	}

	scanf("%d",&a);

	}

	return 0;

}
// Slower C++ solution:
#include <iostream>

using namespace std;



int main(){

	int n;

	while( cin >> n , n ){

		int ice[10] = {};

		for(int i=0 ; i<n ; ++i ){

			int a;

			cin >> a;

			ice[a]++;

		}

		for(int i=0 ; i<10 ; ++i ){

			for(int j=0 ; j<ice[i] ; ++j ){

				cout << "*";

			}

			if(!ice[i]) cout << "-";

			cout << endl;

		}

	}

}

// Faster C++ solution for the same problem (measured speedup: 5.15740630089492x):
#include<cstdio>



int main(){

	int i,j;

	for(int n;scanf("%d",&n),n;){

		int p[10]={};

		for(i=n;i;--i)

			scanf("%d",&j),++p[j];

		for(i=0;i<10;++i,puts("")){

			for(j=0;j<p[i];++j)

				printf("*");

			if(!p[i])printf("-");

		}

	}

}
// Slower C++ solution:
#include <iostream>

#include <sstream>

#include <string>

#include <algorithm>

#include <vector>

#include <stack>

#include <queue>

#include <set>

#include <map>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <cmath>

#include <cassert>



using namespace std;



#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)

#define REP(i,n) FOR(i,0,n)

#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)



template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }



typedef long long ll;

const int INF = 100000000;

const double EPS = 1e-8;

const int MOD = 1000000007;

typedef pair<int, int> P;

typedef pair<int, P> S;

int main(){

  int N;

  while(cin>>N && N){

    string ss, gs; cin>>ss>>gs;

    int St = 0, G = 0;

    REP(i, N){

      St |= (int)(ss[i] == 'B') << i;

      G |= (int)(gs[i] == 'B') << i;

    }

    priority_queue<S> que;

    int dist[1<<16][16];

    REP(i, 1<<N)REP(j, N) dist[i][j] = INF;

    REP(i, N){

      dist[St][i] = 0;

      que.push(S(0, P(St, i)));

    }

    while(!que.empty()){

      S s = que.top(); que.pop();

      int d = s.first * -1;

      int state = s.second.first;

      int u = s.second.second;

      if(state == G){

        cout<<d<<endl;

        break;

      }

      if(dist[state][u] < d) continue;

      REP(i, N)REP(j, N)if((state >> i & 1) != (state >> j & 1)){

        int nst = state ^ (1 << i) ^ (1 << j);

        int nd = d + abs(i - u) + abs(j - i);

        int nu = j;

        if(dist[nst][nu] > nd){

          dist[nst][nu] = nd;

          que.push(S(nd * -1, P(nst, nu)));

        }

      }

    }

  }

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.3085874972858567x):
#include <iostream>

#include <sstream>

#include <string>

#include <algorithm>

#include <vector>

#include <stack>

#include <queue>

#include <set>

#include <map>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <cmath>

#include <cassert>



using namespace std;



#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)

#define REP(i,n) FOR(i,0,n)

#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)



template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }



typedef long long ll;

const int INF = 100000000;

const double EPS = 1e-8;

const int MOD = 1000000007;

int N;

string s, g;

int dp[1<<16][16];

int dfs(int S, int u){

  if(S == (1<<N) - 1) return 0;

  if(dp[S][u] != -1) return dp[S][u];

  int res = INF;

  REP(i, N)REP(j, N) if(i != j && (S >> i & 1) == 0 && (S >> j & 1) == 0 && g[i] != g[j]){

    res = min(res, abs(u - i) + abs(i - j) + dfs(S | 1 << i | 1 << j, j));

  }

  return dp[S][u] = res;

}

int main(){

  while(cin>>N && N){

    cin>>s>>g;

    REP(S, 1<<N) REP(p, N) dp[S][p] = -1;

    int S = 0;

    REP(i, N) if(s[i] == g[i]) S |= 1<<i;

    int ans = INF;

    REP(i, N) ans = min(ans, dfs(S, i));

    cout<<ans<<endl;

  }

  return 0;

}
// Slower C++ solution:
#include <iostream>

#include <sstream>

#include <string>

#include <algorithm>

#include <vector>

#include <stack>

#include <queue>

#include <set>

#include <map>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <cmath>

#include <cassert>



using namespace std;



#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)

#define REP(i,n) FOR(i,0,n)

#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)



template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }



typedef long long ll;

const int INF = 100000000;

const double EPS = 1e-8;

const int MOD = 1000000007;

typedef pair<int, int> P;

typedef pair<int, P> S;

int main(){

  int N;

  while(cin>>N && N){

    string ss, gs; cin>>ss>>gs;

    int St = 0, G = 0;

    REP(i, N){

      St |= (int)(ss[i] == 'B') << i;

      G |= (int)(gs[i] == 'B') << i;

    }

    priority_queue<S> que;

    int dist[1<<16][16];

    REP(i, 1<<N)REP(j, N) dist[i][j] = INF;

    REP(i, N){

      dist[St][i] = 0;

      que.push(S(0, P(St, i)));

    }

    while(!que.empty()){

      S s = que.top(); que.pop();

      int d = s.first * -1;

      int state = s.second.first;

      int u = s.second.second;

      if(state == G){

        cout<<d<<endl;

        break;

      }

      if(dist[state][u] < d) continue;

      REP(i, N)REP(j, N)if((state >> i & 1) != (state >> j & 1)){

        int nst = state ^ (1 << i) ^ (1 << j);

        if(((nst ^ G) >> i & 1) && (nst ^ G) >> j & 1) continue;

        int nd = d + abs(i - u) + abs(j - i);

        int nu = j;

        if(dist[nst][nu] > nd){

          dist[nst][nu] = nd;

          que.push(S(nd * -1, P(nst, nu)));

        }

      }

    }

  }

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.2907357229724965x):
#include <iostream>

#include <sstream>

#include <string>

#include <algorithm>

#include <vector>

#include <stack>

#include <queue>

#include <set>

#include <map>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <cmath>

#include <cassert>



using namespace std;



#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)

#define REP(i,n) FOR(i,0,n)

#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)



template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }



typedef long long ll;

const int INF = 100000000;

const double EPS = 1e-8;

const int MOD = 1000000007;

int N;

string s, g;

int dp[1<<16][16];

int dfs(int S, int u){

  if(S == (1<<N) - 1) return 0;

  if(dp[S][u] != -1) return dp[S][u];

  int res = INF;

  REP(i, N)REP(j, N) if(i != j && (S >> i & 1) == 0 && (S >> j & 1) == 0 && g[i] != g[j]){

    res = min(res, abs(u - i) + abs(i - j) + dfs(S | 1 << i | 1 << j, j));

  }

  return dp[S][u] = res;

}

int main(){

  while(cin>>N && N){

    cin>>s>>g;

    REP(S, 1<<N) REP(p, N) dp[S][p] = -1;

    int S = 0;

    REP(i, N) if(s[i] == g[i]) S |= 1<<i;

    int ans = INF;

    REP(i, N) ans = min(ans, dfs(S, i));

    cout<<ans<<endl;

  }

  return 0;

}