#include <fstream>
#include <iostream>

#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <map>
#include <memory>
#include <numeric>
#include <optional>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <cassert>
#include <climits>
#include <cmath>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <ctime>

#define all(container) (container).begin(), (container).end()
#define sz(container) static_cast<int>((container).size())

using namespace std;

class Solver {
public:
  void solve(istream& in, ostream& out) {
    out.precision(20);

    int tests = 1;
    for (int test = 1; test <= tests; test++) {
      solveOne(in, out);
    }
  }

private:
  void solveOne(istream& in, ostream& out) {
    int N;
    in >> N;
    vector<int64_t> A(N), B(N);
    for (auto& a : A) {
      in >> a;
    }
    for (auto& b : B) {
      in >> b;
    }
    vector<int> oddA, evenA, oddB, evenB;
    for (int i = 0; i < N; i++) {
      if (A[i] >= B[i]) {
        if (i % 2 == 0) evenA.push_back(i);
        else oddA.push_back(i);
      } else {
        if (i % 2 == 0) evenB.push_back(i);
        else oddB.push_back(i);
      }
    }
    auto byA = [&](int lhs, int rhs) {
      return (A[lhs] - B[lhs]) < (A[rhs] - B[rhs]);
    };
    auto byB = [&](int lhs, int rhs) {
      return (B[lhs] - A[lhs]) < (B[rhs] - A[rhs]);
    };
    sort(all(oddA), byA);
    sort(all(evenA), byA);
    sort(all(oddB), byB);
    sort(all(evenB), byB);
    int64_t answer = 0;
    while (!oddA.empty() && !evenA.empty()) {
      answer += A[oddA.back()];
      oddA.pop_back();
      answer += A[evenA.back()];
      evenA.pop_back();
    }
    while (!oddB.empty() && !evenB.empty()) {
      answer += B[oddB.back()];
      oddB.pop_back();
      answer += B[evenB.back()];
      evenB.pop_back();
    }
    auto lastMatch = [&](vector<int> aPos, vector<int> bPos) {
      assert(sz(aPos) == sz(bPos));
      reverse(all(bPos));
      int n = sz(aPos);
      for (int i = 0; i < n; i++) {
        answer += max(A[aPos[i]] + A[bPos[i]], B[aPos[i]] + B[bPos[i]]);
      }
    };
    lastMatch(oddA, evenB);
    lastMatch(evenA, oddB);
    out << answer << endl;
  }
};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  Solver solver;
  solver.solve(cin, cout);

  return 0;
}

#include"bits/stdc++.h"
using namespace std;
using ll = long long;
const ll mod = 1000000007;
#define rep(i,m,n) for(ll i=m;i<n;i++)

int main() {
	ll n;
	string s;
	cin >> n >> s;
	ll ans = n;
	vector<bool>f(n);
	rep(i, 0, n-2) {
		if (f[i] == 0&&f[i+1]==0&&f[i+2]==0) {
			if (s[i] == 'f' && s[i + 1] == 'o' && s[i + 2] == 'x') {
				f[i] = 1;
				f[i + 1] = 1;
				f[i + 2] = 1;
				ans -= 3;
				ll first = i - 2;
				ll second = i - 1;
				ll third = i + 3;
				ll fourth = i + 4;
			retry:
				while (1) {
					if (second <= 0)break;
					if (f[second] == 1)second--;
					else break;
				}
				first = second - 1;
				while (1) {
					if (first < 0)break;
					if (f[first] == 1)first--;
					else break;
				}
				while (1) {
					if (third >= n - 1)break;
					if (f[third] == 1) {
						third++;
					}
					else break;
				}
				fourth = third + 1;
				while (1) {
					if (fourth > n - 1)break;
					if (f[fourth] == 1)fourth++;
					else break;
				}
				while (1) {
					bool flag = 0;
					if (first >= 0 && third <= n - 1) {
						if (s[first] == 'f' && s[second] == 'o' && s[third] == 'x') {
							ans -= 3;
							//cout << front - 1 << " " << front << " " << back << endl;
							f[first] = 1;
							f[second] = 1;
							f[third] = 1;
							goto retry;
							flag = 1;
						}
					}
					if (second >= 0 && fourth <= n - 1) {
						if (s[second] == 'f' && s[third] == 'o' && s[fourth] == 'x') {
							ans -= 3;
							//cout << front << " " << back << " " << back + 1 << endl;
							f[second] = 1;
							f[third] = 1;
							f[fourth] = 1;
							goto retry;
							flag = 1;
						}
					}
					if (flag == 0)break;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}