#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(i,a,b) for(int i = a; i<b ; i++)
#define FIO ios_base::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);
#define pb push_back
#define M 1000000007
int mod(int x){
return ((x%M + M)%M);
}
int add(int a,int b){
return mod(mod(a)+mod(b));
}
int mul(int a,int b){
return mod(mod(a)*mod(b));
}
// ****************************************************************************
bool isValid(double l,double r,double x,double y){
    if(l>=x && l<=y)
    return true;
    if(x>=l && x<=r)
    return true;
    return false;
}
void solve(){
    int n;
    cin>>n;
    vector<pair<double,double>>v;
    double temp = 0.1;
    fo(i,0,n){
        int x;
        cin>>x;
        double l,r;
        cin>>l>>r;
        if(x==2)
        v.pb({l,r-temp});
        else if(x==3)
        v.pb({l+temp,r});
        else if(x==4) v.pb({l+temp,r-temp});
        else v.pb({l,r});
    }
    int ans = 0;
    fo(i,0,n){
        fo(j,i+1,n){
            if(isValid(v[i].first,v[i].second,v[j].first,v[j].second)){
            // cout<<v[i].first<<" "<<v[i].second<<"\n"<<v[j].first<<" "<<v[j].second<<"\n";
            ans++;
            }
        }
    }
    cout<<ans;
}
signed main()
{
FIO
int t;
t=1;
// cin>>t;
while(t--)
{
solve();
}
}
#include <bits/stdc++.h>
using namespace std;
#define DBG cerr << __LINE__ << ' ' << __FUNCTION__ << endl
#define CLOSE ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mem(t, v) memset ((t) , v, sizeof(t))
#define pb push_back
#define mk make_pair
#define sz(x) (int)(x).size()
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define eps 1e-8
#define LL long long
#define ULL unsigned long long
#define LF putchar('\n')
#define SP putchar(' ')

template<typename T>
void read(T &x) {x = 0;char ch = getchar();LL f = 1;while(!isdigit(ch)){if(ch == '-')f *= -1;ch = getchar();}while(isdigit(ch)){x = x * 10 + ch - 48; ch = getchar();}x *= f;}
template<typename T, typename... Args>
void read(T &first, Args& ... args) {read(first);read(args...);}
template<typename T>
void write(T arg) {T x = arg;if(x < 0) {putchar('-'); x =- x;}if(x > 9) {write(x / 10);}putchar(x % 10 + '0');}
template<typename T, typename ... Ts>
void write(T arg, Ts ... args) {write(arg);if(sizeof...(args) != 0) {putchar(' ');write(args ...);}}
using namespace std;

const LL mod = 1e9 + 7;
const int N = 1e5 + 50;

LL n, a[N], f[N][2];

int main() {
	cin >> n;
	for(int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	LL x = 1, y = 1;
	f[1][1] = a[1];
	for(int i = 2; i <= n; ++i) {
		f[i][1] = (f[i-1][0] + f[i-1][1] + x * a[i] % mod) % mod;
		f[i][0] = (f[i-1][1] + y * ((-1LL * a[i] + mod) % mod) % mod) % mod;
		LL t = x;
		x = (x + y) % mod;
		y = t;
	}
	cout << (f[n][1] + f[n][0]) % mod << endl;
    return 0;
}