#include<iostream>
#include<vector>
#include<algorithm>

int main() {
	int n;
	std::cin >> n;
	std::vector<int> t(n),l(n), r(n);
	for (int i = 0; i < n; i++) {
		std::cin >> t[i] >> l[i] >> r[i];
	}

	int count = 0;
	for (int i = 0; i < n-1; i++) {
		for (int j = i + 1; j < n; j++) {
			//printf("%d %d %d %d\n",l[i],l[j],r[i],r[j]);
			if (std::min(r[i], r[j]) - std::max(l[i], l[j]) >= 0)count++;
			if (r[i] == l[j] || r[j] == l[i]) {
				if (l[i] < l[j]) {
					if(((t[i]==1)||t[i]==3)&&(t[j]==2||t[j]==1)){}
					else count--;
				}
				else {
					if (((t[j] == 1) || t[j] == 3) && (t[i] == 2 || t[i] == 1)) {}
					else count--;
				}

			}
		}
	}
	std::cout << count << std::endl;
}
#include <bits/stdc++.h>
using namespace std;

#define maxn 105

string arr[maxn];
bool vis[maxn];
int n;

int dfs(int x) {
    int ret = 1;
    vis[x] =  true;
    for(int y = 0; y < n; y++) {
        if(!vis[y] && arr[y][x] == '1') {
            ret += dfs(y);
        }
    }
    return ret;
}

int main() {
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    double ans = 0.0;
    for(int i = 0; i < n; i++) {
        memset(vis, 0, sizeof(vis));
        ans += 1.00 / dfs(i); 
    }
    printf("%.12f\n", ans);
    return 0;
}