#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int INF = 1e+15;
int n;
int x[17], y[17], z[17];
int dp[1 << 17][17];

int dist(int i, int j) {
	return abs(x[j] - x[i]) + abs(y[j] - y[i]) + max(0LL, z[j] - z[i]);
}

signed main() {
	int i, j, k;
	
	cin >> n;
	rep(i, n) cin >> x[i] >> y[i] >> z[i];
	
	rep(i, (1 << n)) rep(j, n) dp[i][j] = INF;
	
	dp[1][0] = 0;
	rep(i, (1 << n)) {
		rep(j, n) {
			rep(k, n) {
				dp[i | (1 << k)][k] = min(dp[i | (1 << k)][k], dp[i][j] + dist(j, k));
			}
		}
	}
	
	int ans = INF;
	rep(i, n) {
		ans = min(ans, dp[(1 << n) - 1][i] + dist(i, 0));
	}
	cout << ans << endl;
	return 0;
}
#include<bits/stdc++.h>
using namespace std;

#define int long long
#define print(x) cout << "[" << #x << ": " << x << "]";
#define println(x) cout << "[" << #x << ": " << x << "]\n";
#define pb push_back
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define INF 1e18 + 5
#define MOD 1e9 + 7

void solve(){
    int n; cin >> n;
    string s; cin >> s;
    vector<char> rem;
    for(int i = 0; i < n; i++){
      rem.pb(s[i]);
      if(rem.size() > 2){
        int x = rem.size()-1;
        if(rem[x] == 'x' && rem[x-1] == 'o' && rem[x-2] == 'f'){
//          println(x)
          rem.pop_back();
          rem.pop_back();
          rem.pop_back();
        }
      }
    }
    cout << rem.size() << '\n';
	return;
}

int32_t main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL); 
	int tt = 1;
	while(tt--){
		solve();
		cout << '\n';
	}
	cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " s" << '\n'; 
}

