#include <bits/stdc++.h>
#define PB push_back
#define MP(x,y) make_pair(x,y)
#define F first
#define S second
#define loop(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rloop(i,m,n) for(int i=(int)(m) ; i > (int) (n) ; --i )
#define lp(i,n) loop(i,0,n)
#define rlp(i,n) rloop(i,n,0)
#define mod 1000000007
using namespace std;
typedef long long int lli;
typedef pair<int,int> pii;
int main(){
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    int N;
    scanf("%d", &N);
    vector<pair<int, lli> > edges[N];
    int u, v;
    lli w;
    lp(i, N-1) {
        scanf("%d%d%lld", &u, &v, &w);
        --u; --v;
        edges[u].PB(MP(v,w));
        edges[v].PB(MP(u,w));
    }
    vector<lli> XOR(N);
    vector<bool> visited(N, false);
    queue<pair<int, lli> > q;
    lli d;
    q.push(MP(0, 0));
    visited[0] = true;
    while (!q.empty()) {
        u = q.front().F;
        d = q.front().S;
        q.pop();
        XOR[u] = d;
        for(vector<pair<int, lli> >::iterator it = edges[u].begin(); it != edges[u].end(); ++it) {
            v = it->F;
            w = it->S;
            if (visited[v]) continue;
            visited[v] = true;
            q.push(MP(v, d^w));
        }
    }
    lli ans = 0, add, cnt;
    lp(bit, 60) {
        cnt = 0;
        lp(i, N)
            if (XOR[i]&(((lli)1)<<bit)) ++cnt;
        add = ((((lli)1)<<bit)%mod)*cnt;
        add %= mod;
        add = add * (N-cnt);
        add %= mod;
        // printf("%d %lld %lld\n", bit, cnt, add);
        ans += add%mod;
        ans %= mod;
    }
    // lp(i, N) {
    //     loop(j, i+1, N) {
    //         ans += XOR[i]^XOR[j];
    //         ans %= mod;
    //     }
    // }
    printf("%lld", ans);
    return 0;
}

/*
 *
 *   1 0 0 1 1 0 A
 *   0 0 1 1 0 1 B
 *
 *   1 0 1 0 1 1 A ^ B
 *   1 0 0 1 1 0 A
 * 1 0 1 0 0 0 1 A + A^B
 *
 * 0 0 1 1 0 1 0 2B
 *
 * 1 0 0 1 1 0 0 2A
 *
 *
 * 010
 * 011
 * 001
 *
 * 001
 * 011
 * 010
 *
 */

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wfloat-conversion"

#include <iostream> // IO
#include <cmath> // sqrt, trig, ceil, log
#include <utility> // swap, pair 
// #include <chrono> // non c style time

// #include <algorithm> // sort, binary search, reverse, merge
// #include <bitset>
// #include <cstdio> 
// #include <cstdlib> //abs, atoi, rand 
// #include <iterator> 
// #include <map>  
// #include <queue>
// #include <set> 
// #include <stack> 
// #include <string> // std string
// #include <vector> 

// #include <complex>
// #include <deque>
// #include <iomanip> // setprecision
// #include <tuple>

#define fo(i, a, b) for(i=a; i<=b; i++)
#define ro(i, b, a) for(i=b; i>=a; i--)
#define foe(it, x) for(auto it=x.begin(); it!=x.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define fil(x, y) memset(x, y, sizeof(x))
#define deb(x) cout << #x << " " << x << "\n"
#define sz(a) ((int)(a.size()))

using namespace std;

using ll = long long;

const ll N = 3e3+3;
const int inf = 1e9+3;
const ll M = 1e9+7;
const ll T = 998244353;
const double pi = acos(-1);

void solve()
{
    ll n,i,j,ans=0;cin>>n;
    ll dp[n+1][n+1];
    ll a[n+1];
    ll p[n+1];
    p[0]=0;
    fo(i,1,n){
        cin>>a[i];
        p[i]=p[i-1]+a[i];
    }
    fo(i,0,n){
        fo(j,0,n){
            dp[i][j]=0;
        }
    }
    dp[0][0]=1;
    for(j=1;j<=n;j++){
        ll adj[n+1];
        fo(i,0,n){
            adj[i]=0;
        }
        for(i=0;i<=n;i++){
            dp[i][j]=(dp[i][j]+(adj[p[i]%j]))%M;
            adj[p[i]%j]=(adj[p[i]%j]+dp[i][j-1])%M;
        }
    }
    for(j=1;j<=n;j++){
        ans=(ans+dp[n][j])%M;
    }
    cout << ans << "\n";
}

signed main()
{
    // auto s1 = std::chrono::system_clock::now().time_since_epoch();
    // auto start_time = std::chrono::duration_cast<std::chrono::microseconds>(s1).count();

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    #ifdef Holmes7 
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif

    int _t=1,i;
    //cin >> _t;
    for(i=1;i<=_t;i++){
        //cout << "Case #" << i << ": ";
        solve();
    }

    // auto s2 = std::chrono::system_clock::now().time_since_epoch();
    // auto end_time = std::chrono::duration_cast<std::chrono::microseconds>(s2).count();
    // cerr << "Time: " << (end_time-start_time) << "\n";

    return 0;
}
