/******************************
Author: jhnah917(Justice_Hui)
g++ -std=c++17 -DLOCAL
******************************/

#include <bits/stdc++.h>
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define compress(v) sort(all(v)), v.erase(unique(all(v)), v.end())
#define IDX(v, x) (lower_bound(all(v), x) - v.begin())
using namespace std;

using uint = unsigned;
using ll = long long;
using ull = unsigned long long;
using PII = pair<int, int>;
constexpr ll MOD = 1e9+7;

ll N, A[3030], S[3030][3030];
int D[3030][3030];
vector<int> G[3030][3030];

void Add(int &a, int b){
    a += b; if(a >= MOD) a -= MOD;
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    cin >> N;
    for(int i=1; i<=N; i++) cin >> A[i];
    for(int i=1; i<=N; i++){
        partial_sum(A+1, A+N+1, S[i]+1);
        for(int j=1; j<=N; j++) S[i][j] %= i;
        for(int j=1; j<=N; j++) G[i][S[i][j]].push_back(j);
    }
    for(int i=1; i<=N; i++) D[1][i] = 1;
    for(int i=1; i<=N; i++){
        for(int j=1; j<=N; j++){
            if(!D[i][j]) continue;
            auto &vec = G[i+1][S[i+1][j]];
            for(auto it=upper_bound(all(vec), j); it!=vec.end(); ++it) Add(D[i+1][*it], D[i][j]);
        }
    }
    ll ans = 0;
    for(int i=1; i<=N; i++) ans += D[i][N];
    cout << ans % MOD;
}
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define w(x)    int x; cin>>x; while(x--)
#define pi (3.141592653589)
#define mod 1000000007
#define int long long
#define float double
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mii             map<int,int>
#define msi          map<string,int>
#define vi               vector<int>
#define vs            vector<string>
#define si                  set<int>
#define all(c) c.begin(), c.end()
#define min3(a, b, c) min(c, min(a, b))
#define min4(a, b, c, d) min(d, min(c, min(a, b)))
#define rrep(i, n) for(int i=n-1;i>=0;i--)
#define rep(i,n) for(int i=0;i<n;i++)
#define print(x)        for(auto it=x.begin();it!=x.end();it++) cout<<*it<<' '; cout<<endl;
#define printii(x)      for(auto it=x.begin();it!=x.end();it++) cout<<it->F<<' '<<it->S<<endl;
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define lamba INT_MAX
#define chota INT_MIN
#define yes "YES"
#define no "NO"
#define MX 200010
//vector < int > graph[MX];
//bool vis[MX];
//vector<pair<int,int>>Graph[MX];

long double a[2002][3];

void solve()
{
  int n,i,j,cnt=0,t;
  cin>>n;
  double delta =0.1;
  for(i=0;i<n;i++)
  {
      cin>>t;
      if(t==1)
      cin>>a[i][0]>>a[i][1];
      else if(t==2)
      {
          cin>>a[i][0]>>a[i][1];
          a[i][1]-=delta;
      }
      else if(t==3)
      {
          cin>>a[i][0]>>a[i][1];
          a[i][0]+=delta;
      }
      else if(t==4)
      {
          cin>>a[i][0]>>a[i][1];
          a[i][0]+=delta;
          a[i][1]-=delta;
      }
  }
  for(i=0;i<n;i++)
  {
      double l,r;
      l=a[i][0],r=a[i][1];
      for(j=i+1;j<n;j++)
      {
          double L,R;
          L=a[j][0];
          R=a[j][1];
          cnt += (max(l,L) <= min(r,R));
        //   if(L>=l&&R<=r||L<=l&&R>=r)
        //   {
        //       if(L>=l&&R<=r)
        //       {
        //           cnt+=ceil(R-L);
        //       }
        //       else if(L<=l&&R>=r)
        //       {
        //           cnt+=ceil(r-l);
        //       }
        //   }
        //   else if(L>=l&&r>=L||R>=l&&r>=R)
        //   {
        //       if(L>=l&&r>=L)
        //       cnt+=ceil(r-l);
        //       else if(R>=l&&r>=R)
        //       cnt+=ceil(R-l);
        //   }
      }
  }
  cout<<cnt<<endl;
  return ;
}


int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//precalc();
  //w(x)
    // {
solve();
 //}
return 0;
}
