#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <queue>
#include <iomanip>

using namespace std ;

#define FOREACH(it,c) for( __typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define FOR(i,a,b) for( int i=(a),_b=(b);i<=_b;i++)
#define DOW(i,b,a) for( int i=(b),_a=(a);i>=_a;i--)
#define REP(i,n) FOR(i,0,(n)-1)
#define DEP(i,n) DOW(i,(n)-1,0)
#define all(a) (a).begin() , (a).end()
#define mp(a,b) make_pair((a),(b))
#define RESET(c,x) memset (c, x, sizeof (c))
#define oo 1000111000
#define PI acos(-1.0)
#define fi first
#define se second
#define SIZE(c) (c).size()

typedef vector<int> VI ;
typedef vector<string> VS ;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;

template<class T> inline int size(const T&c) { return c.size(); }

using namespace std;
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }

const int maxn = 100000+10;
const int cmod = 1000000007;
int b[maxn];
int C[maxn][110];
int a[maxn][110];
int n,m,l,r,k;
int main()
{
    //freopen("C407.inp","r",stdin);
    //freopen("C407.out","w",stdout);
    scanf("%d%d",&n,&m);
    for (int i = 1; i <= n; i++) scanf("%d",&b[i]);
    C[0][0] = 1;
    for (int i = 1; i <= n; i++)
    {
        C[i][0] = 1;
        for (int j = 1; j <= 100; j++)
            C[i][j] = (C[i-1][j] + C[i-1][j-1])% cmod;
    }
    for (int i = 1; i <= m; i++)
    {
        scanf("%d%d%d",&l,&r,&k);
        a[l][k] = (a[l][k] + 1) % cmod;
        for (int j = 0; j <= k; j++)
            a[r+1][k - j] = (a[r+1][k - j] - C[r - l + j][j]) % cmod;
    }

    for (int j = 100; j >= 0; j--){
            for (int i = 1; i <= n; i++)
                {
                a[i][j] = ((a[i-1][j] + a[i][j+1]) % cmod + a[i][j]) % cmod;
                    //cout<<a[i][j];
                }
                //cout<<endl;
    }
    for (int i = 1; i <= n; i++)
        printf("%d ",((a[i][0] + b[i])  % cmod + cmod ) % cmod);
    //1 1 1 1 -1
    //1 2 3 4
    //1 3 6 10
    fclose(stdin);
    fclose(stdout);
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int maxn = 100010;

const int mod = 1e9+7;

int C[maxn][120];

typedef long long ll;

int p[maxn], ip[maxn];

ll paw( int a, int b ) {

	if (!b) return 1;

	ll ans = paw( a, b/2 );

	ans = ( ans * ans ) % mod;

	if ( b & 1 ) ans = ans * a % mod;

	return ans;

}

int calc_C( int b, int a ) {

	int ans = ((( 1LL * p[b] * ip[b-a] ) % mod * ip[a] % mod ) % mod );

	return ans;

}

int a[maxn];

int main() {

	p[0] = 1;

	ip[0] = 1;

	int n, m, L, R, k;

	scanf("%d%d", &n, &m);

	for( int i = 1; i < maxn; i ++ ) {

		p[i] = ( 1ll * p[i-1] * i ) % mod;

		ip[i] = paw( p[i], mod - 2 );

	}

	for( int i = 1; i <= n; i ++ ) scanf("%d", a+i);

	for( int i = 0; i < m;  i++ ) {

		scanf("%d%d%d", &L, &R, &k );

		C[L][k] = ( C[L][k] + 1 ) % mod;

		for( int j = 0; j <= k; j ++ ) {

			C[R+1][j] = ( 1LL * C[R+1][j] - calc_C( k - j + R - L, k - j ) + mod ) % mod;

		}

	}

	for( int i = 110; i >= 0; i -- ) {

		for( int j = 1; j <= n; j ++ ) {

			C[j][i] = ( 1ll*C[j][i] + C[j][i+1] + C[j-1][i] + mod ) % mod;

		}

	}

	int tot = 0;

	for( int i = 1; i <= n; i ++ ){

//		cout << C[i][0] << endl;

		cout << ( a[i] + C[i][0] ) % mod << ' ';

	}

	puts("");

	return 0;

}


#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define MOD 1000000007

#define pb push_back

#define sq(x) ((x)*(x))

#define x first

#define y second

#define eps 1e-9

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

template<class T>inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T, class T1>inline void gn(T &x, T1 &y) {gn(x); gn(y);}

template<class T, class T1, class T2>inline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}

template<class T>inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

template<class T>inline void printsp(T x) {print(x); putchar(' ');}

template<class T>inline void println(T x) {print(x); putchar('\n');}

template<class T, class U>inline void print(T x, U y) {printsp(x); println(y);}

template<class T, class U, class V>inline void print(T x, U y, V z) {printsp(x); printsp(y); println(z);}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;

	return ans;

}

int main() {

#ifndef ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	const int NN=101010;

	static int val[102][NN], a[NN], C[NN][101];

	int n, m;

	for (int i=0; i<NN; i++) {

		for (int j=0; j<=min(i, 100); j++) {

			if (j==0 || i==j) C[i][j]=1;

			else C[i][j]=(C[i-1][j-1]+C[i-1][j])%MOD;

		}

	}

	gn(n, m);

	for (int i=1; i<=n; i++) gn(a[i]);

	int L, R, K;

	while (m--) {

		gn(L, R, K);

		val[K][L]=(val[K][L]+1)%MOD;

		for (int i=0; i<=K; i++) {

			val[i][R+1]=(val[i][R+1]+MOD-C[K-i+R-L][K-i])%MOD;

		}

	}

	for (int i=100; i>=0; i--) {

		for (int j=1; j<=n; j++) {

			val[i][j]=(val[i][j]+(INT)val[i][j-1]+val[i+1][j])%MOD;

		}

	}

	for (int i=1; i<=n; i++) printsp((a[i]+val[0][i])%MOD);puts("");

	return 0;

}


#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define MOD 1000000007

#define pb push_back

#define sq(x) ((x)*(x))

#define x first

#define y second

#define eps 1e-9

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

template<class T>inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T, class T1>inline void gn(T &x, T1 &y) {gn(x); gn(y);}

template<class T, class T1, class T2>inline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}

template<class T>inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

template<class T>inline void printsp(T x) {print(x); putchar(' ');}

template<class T>inline void println(T x) {print(x); putchar('\n');}

template<class T, class U>inline void print(T x, U y) {printsp(x); println(y);}

template<class T, class U, class V>inline void print(T x, U y, V z) {printsp(x); printsp(y); println(z);}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;

	return ans;

}

int main() {

#ifndef ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	const int NN=101010;

	static int val[102][NN], a[NN], C[NN][101];

	int n, m;

	for (int i=0; i<NN; i++) {

		for (int j=0; j<=min(i, 100); j++) {

			if (j==0 || i==j) C[i][j]=1;

			else C[i][j]=(C[i-1][j-1]+C[i-1][j])%MOD;

		}

	}

	gn(n, m);

	for (int i=1; i<=n; i++) gn(a[i]);

	int L, R, K;

	while (m--) {

		gn(L, R, K);

		val[K][L]=(val[K][L]+1)%MOD;

		for (int i=0; i<=K; i++) {

			val[i][R+1]=(val[i][R+1]+MOD-C[K-i+R-L][K-i])%MOD;

		}

	}

	for (int i=100; i>=0; i--) {

		for (int j=1; j<=n; j++) {

			val[i][j]=(val[i][j]+(INT)val[i][j-1]+val[i+1][j])%MOD;

		}

	}

	for (int i=1; i<=n; i++) printsp(a[i]+val[0][i]);puts("");

	return 0;

}


#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define MOD 1000000007

#define pb push_back

#define sq(x) ((x)*(x))

#define x first

#define y second

#define eps 1e-8

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

#define debug(x) cout << #x << " = " << x << endl

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

#define NN 101100

int mat[110][NN], C[NN][110], a[NN];

void pre(){

	for(int i=0; i<NN; i++){

		for(int j=0; j<=min(i, 100); j++){

			if(!j) C[i][j]=1;

			else C[i][j]=(C[i-1][j-1]+C[i-1][j])%MOD;

		}

	}

}

int main() {

	pre();

	int n, m;

	cin >> n >> m;

	for(int i=1; i<=n; i++) scanf("%d", a+i);

	int L, R, k;

	for(int i=0; i<m; i++){

		scanf("%d %d %d", &L, &R, &k);

		mat[k][L]=(mat[k][L]+1)%MOD;

		for(int j=0; j<=k; j++){

			mat[j][R+1]=(mat[j][R+1]+MOD-C[k-j+R-L][k-j])%MOD;

		}

	}

	for(int i=100; i>=0; i--){

		for(int j=1; j<=n; j++){

			mat[i][j]=((INT)mat[i][j-1]+mat[i+1][j]+mat[i][j])%MOD;

		}

	}

	for(int i=1; i<=n; i++) printf("%d ", (a[i]+mat[0][i])%MOD);

	return 0;

}


#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define MOD 1000000007

#define pb push_back

#define sq(x) ((x)*(x))

#define x first

#define y second

#define eps 1e-8

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

#define debug(x) cout << #x << " = " << x << endl

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

#define NN 101100

int mat[110][NN], C[NN][110], a[NN];

void pre(){

	for(int i=0; i<NN; i++) C[i][0]=C[i][i]=1;

	for(int i=1; i<NN; i++){

		for(int j=1; j<min(i, 110); j++) C[i][j]=(C[i-1][j-1]+C[i-1][j])%MOD;

	}

}

int main() {

	pre();

	int n, m;

	cin >> n >> m;

	for(int i=1; i<=n; i++) scanf("%d", a+i);

	int L, R, k;

	for(int i=0; i<m; i++){

		scanf("%d %d %d", &L, &R, &k);

		mat[k][L]=(mat[k][L]+1)%MOD;

		for(int j=0; j<=k; j++){

			mat[j][R+1]=(mat[j][R+1]+MOD-C[k-j+R-L][k-j])%MOD;

		}

	}

	for(int i=100; i>=0; i--){

		for(int j=1; j<=n; j++){

			mat[i][j]=((INT)mat[i][j-1]+mat[i+1][j]+mat[i][j])%MOD;

		}

	}

	for(int i=1; i<=n; i++) printf("%d ", (a[i]+mat[0][i])%MOD);

	return 0;

}


#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define MOD 1000000007

#define pb push_back

#define sq(x) ((x)*(x))

#define x first

#define y second

#define eps 1e-8

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

#define debug(x) cout << #x << " = " << x << endl

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

#define NN 100110

int mat[110][NN], C[NN][110], a[NN];

void pre(){

	for(int i=0; i<NN; i++) C[i][0]=C[i][i]=1;

	for(int i=1; i<NN; i++){

		for(int j=1; j<min(i, 110); j++) C[i][j]=(C[i-1][j-1]+C[i-1][j])%MOD;

	}

}

int main() {

	pre();

	int n, m;

	cin >> n >> m;

	for(int i=1; i<=n; i++) scanf("%d", a+i);

	int L, R, k;

	for(int i=0; i<m; i++){

		scanf("%d %d %d", &L, &R, &k);

		mat[k][L]=(mat[k][L]+1)%MOD;

		for(int j=0; j<=k; j++){

			mat[j][R+1]=(mat[j][R+1]+MOD-C[k-j+R-L][k-j])%MOD;

		}

	}

	for(int i=100; i--; ){

		for(int j=1; j<=n; j++){

			mat[i][j]=((INT)mat[i][j-1]+mat[i+1][j]+mat[i][j])%MOD;

		}

	}

	for(int i=1; i<=n; i++) printf("%d ", (a[i]+mat[0][i])%MOD);

	return 0;

}


#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define MOD 1000000007

#define pb push_back

#define sq(x) ((x)*(x))

#define x first

#define y second

#define eps 1e-8

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

#define debug(x) cout << #x << " = " << x << endl

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

#define NN 100110

int mat[110][NN], C[NN][110], a[NN];

void pre(){

	for(int i=0; i<NN; i++) C[i][0]=C[i][i]=1;

	for(int i=1; i<NN; i++){

		for(int j=1; j<min(i, 110); j++) C[i][j]=(C[i-1][j-1]+C[i-1][j])%MOD;

	}

}

int main() {

	pre();

	int n, m;

	cin >> n >> m;

	for(int i=1; i<=n; i++) scanf("%d", a+i);

	int L, R, k;

	for(int i=0; i<m; i++){

		scanf("%d %d %d", &L, &R, &k);

		mat[k][L]+=(mat[k][L]+1)%MOD;

		for(int j=0; j<=k; j++){

			mat[j][R+1]=(mat[j][R+1]+MOD-C[k-j+R-L][k-j])%MOD;

		}

	}

	for(int i=100; i--; ){

		for(int j=1; j<=n; j++){

			mat[i][j]=((INT)mat[i][j-1]+mat[i+1][j]+mat[i][j])%MOD;

		}

	}

	for(int i=1; i<=n; i++) printf("%d ", (a[i]+mat[0][i])%MOD);

	return 0;

}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

#define FOREACH(i, c) for(__typeof( (c).begin() ) i = (c).begin(); i != (c).end(); ++i)
#define FOR(i, a, n) for(__typeof(n) i = (a); i<(n); ++i)
#define REP(i, a, n) for(__typeof(n) i = (a); i<=(n); ++i)
#define ROF(i, n, a) for(__typeof(n) i = (n); i>=(a); --i)
#define error(n) cout << #n << " = " << n << endl
#define all(c) c.begin(), c.end()
#define pb push_back
#define po pop_back
#define Size(n) ((int)(n).size())
#define X first
#define Y second
int _ ;
#define scanf _ = scanf
// #define X real()
// #define Y imag()

typedef long long   ll ;
typedef long double ld ;
typedef pair<int,int> pii ;

const int maxk = 102;
const int maxn = 101 * 1000;
const ll mod = 1000LL * 1000 * 1000 + 7;

int n, m;

ll a[maxn];
int choice[maxk][maxk];
int sum[maxn][maxk];

int Sum(ll a , ll b) {
    return (a+b)%mod;
}

int Mul(ll a , ll b) {
    return (a*b)%mod;
}

ll Pow(ll a , ll b) {
    if (b == 0) return 1%mod;
    ll c = Pow(a,b/2);
    c = Mul(c,c);
    if (b%2 == 1)
        c = Mul(c,a);
    return c;
}

ll Reverse(ll x) {
    return Pow(x,mod-2);
}

int main() {
    scanf ("%d %d",&n,&m);
    REP (i,1,n) {
        int x;
        scanf ("%d",&x);
        a[i] = x;
    }
    //
    for (int i = 0 ; i < maxk ; ++i) {
        choice[i][0] = choice[i][i] = 1;
        for (int j = 1 ; j < i ; ++j) {
            choice[i][j] = Sum(choice[i-1][j-1],choice[i-1][j]);
        }
    }
    //
    FOR (i,0,m) {
        int l , r , k;
        scanf ("%d %d %d",&l,&r,&k);
        int x = 0;
        for (int j = l ; x <= k && j <= r ; ++j , ++x) {
            sum[j][x] = Sum(sum[j][x],choice[k][x]);
        }
        --x;
        if (r-l <= k) {
            ll cur = choice[k][x];
            int start = k-(r-l);
//             cerr << endl;
//             cerr << start << " " << cur << endl;
            for (int j = start , lp = k , rp = k-x ; j <= k ; ++j , ++lp , ++rp) {
                if (j > start) {
//                     cerr << lp << " " << rp << " --> " ;
                    cur = Mul(Mul(cur,lp) ,Reverse(rp) );
                }
//                 cerr << k-j << " : " << cur << endl;
                sum[r+1][k-j] = Sum(sum[r+1][k-j],(-cur%mod)+mod);
            }
//             cerr << endl;
        } else {
            ll cur = 1;
            for (int j = 0 ; j <= k ; ++j) {
                if (j) {
                    cur = Mul(cur,Mul(r-l+j,Reverse(j)));
                }
                sum[r+1][k-j] = Sum(sum[r+1][k-j],(-cur%mod)+mod);
            }
        }
    }
    //
    REP (i,1,n) {
        for (int j = maxk-2 ; j >= 0 ; --j) {
            sum[i][j] = Sum(sum[i][j],Sum(sum[i][j+1],sum[i-1][j]));
        }
        printf("%d ",Sum(sum[i][0],a[i]));
    }
    printf("\n");
    return 0 ;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

#define FOREACH(i, c) for(__typeof( (c).begin() ) i = (c).begin(); i != (c).end(); ++i)
#define FOR(i, a, n) for(__typeof(n) i = (a); i<(n); ++i)
#define REP(i, a, n) for(__typeof(n) i = (a); i<=(n); ++i)
#define ROF(i, n, a) for(__typeof(n) i = (n); i>=(a); --i)
#define error(n) cout << #n << " = " << n << endl
#define all(c) c.begin(), c.end()
#define pb push_back
#define po pop_back
#define Size(n) ((int)(n).size())
#define X first
#define Y second
int _ ;
#define scanf _ = scanf
// #define X real()
// #define Y imag()

typedef long long   ll ;
typedef long double ld ;
typedef pair<int,int> pii ;

const int maxk = 102;
const int maxn = 101 * 1000;
const ll mod = 1000LL * 1000 * 1000 + 7;

int n, m;

ll a[maxn];
int choice[maxk][maxk];
int sum[maxn][maxk];

int Sum(ll a , ll b) {
    return (a+b)%mod;
}

int Mul(ll a , ll b) {
    return (a*b)%mod;
}

ll Pow(ll a , ll b) {
    if (b == 0) return 1%mod;
    ll c = Pow(a,b/2);
    c = Mul(c,c);
    if (b%2 == 0)
        c = Mul(c,a);
    return c;
}

ll Reverse(ll x) {
    return Pow(x,mod-2);
}

int main() {
    scanf ("%d %d",&n,&m);
    REP (i,1,n) {
        int x;
        scanf ("%d",&x);
        a[i] = x;
    }
    //
    for (int i = 0 ; i < maxk ; ++i) {
        choice[i][0] = choice[i][i] = 1;
        for (int j = 1 ; j < i ; ++j) {
            choice[i][j] = Sum(choice[i-1][j-1],choice[i-1][j]);
        }
    }
    //
    FOR (i,0,m) {
        int l , r , k;
        scanf ("%d %d %d",&l,&r,&k);
        for (int j = l , x = 0 ; x <= k && j <= r ; ++j , ++x) {
//             cerr << j << " " << x << " : ";
            sum[j][x] = Sum(sum[j][x],choice[k][x]);
//             cerr << sum[j][x] << endl;
        }
        ll cur = 1;
        for (int j = 0 ; j <= k ; ++j) {
            if (j) {
                cur = Mul(cur,Mul(r-l+j,Reverse(j)));
            }
//             cerr << j << " " << cur << endl;
            sum[r+1][k-j] = Sum(sum[r+1][k-j],(-cur%mod)+mod);
        }
    }
    //
    REP (i,1,n) {
        for (int j = maxk-2 ; j >= 0 ; --j) {
            sum[i][j] = Sum(sum[i][j],Sum(sum[i][j+1],sum[i-1][j]));
        }
        printf("%d ",Sum(sum[i][0],a[i]));
    }
    printf("\n");
    return 0 ;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

#define FOREACH(i, c) for(__typeof( (c).begin() ) i = (c).begin(); i != (c).end(); ++i)
#define FOR(i, a, n) for(__typeof(n) i = (a); i<(n); ++i)
#define REP(i, a, n) for(__typeof(n) i = (a); i<=(n); ++i)
#define ROF(i, n, a) for(__typeof(n) i = (n); i>=(a); --i)
#define error(n) cout << #n << " = " << n << endl
#define all(c) c.begin(), c.end()
#define pb push_back
#define po pop_back
#define Size(n) ((int)(n).size())
#define X first
#define Y second
int _ ;
#define scanf _ = scanf
// #define X real()
// #define Y imag()

typedef long long   ll ;
typedef long double ld ;
typedef pair<int,int> pii ;

const int maxk = 102;
const int maxn = 101 * 1000;
const ll mod = 1000LL * 1000 * 1000 + 7;

int n, m;

ll a[maxn];
ll rev[maxn];
int choice[maxk][maxk];
int sum[maxn][maxk];

int Sum(ll a , ll b) {
    return (a+b)%mod;
}

int Mul(ll a , ll b) {
    return (a*b)%mod;
}

ll Pow(ll a , ll b) {
    if (b == 0) return 1%mod;
    ll c = Pow(a,b/2);
    c = Mul(c,c);
    if (b%2 == 1)
        c = Mul(c,a);
    return c;
}

ll Reverse(ll x) {
    return Pow(x,mod-2);
}

int main() {
    for (int i = 0 ; i < maxn ; ++i)
        rev[i] = Reverse(i);
    scanf ("%d %d",&n,&m);
    REP (i,1,n) {
        int x;
        scanf ("%d",&x);
        a[i] = x;
    }
    //
    for (int i = 0 ; i < maxk ; ++i) {
        choice[i][0] = choice[i][i] = 1;
        for (int j = 1 ; j < i ; ++j) {
            choice[i][j] = Sum(choice[i-1][j-1],choice[i-1][j]);
        }
    }
    //
    FOR (i,0,m) {
        int l , r , k;
        scanf ("%d %d %d",&l,&r,&k);
        int x = 0;
        for (int j = l ; x <= k && j <= r ; ++j , ++x) {
            sum[j][x] = Sum(sum[j][x],choice[k][x]);
        }
        --x;
        if (r-l <= k) {
            ll cur = choice[k][x];
            int start = k-(r-l);
            for (int j = start , lp = k , rp = k-x ; j <= k ; ++j , ++lp , ++rp) {
                if (j > start) {
                    cur = Mul(Mul(cur,lp) ,rev[rp] );
                }
                sum[r+1][k-j] = Sum(sum[r+1][k-j],(-cur%mod)+mod);
            }
        } else {
            ll cur = 1;
            for (int j = 0 ; j <= k ; ++j) {
                if (j) {
                    cur = Mul(cur,Mul(r-l+j,rev[j]));
                }
                sum[r+1][k-j] = Sum(sum[r+1][k-j],(-cur%mod)+mod);
            }
        }
    }
    //
    REP (i,1,n) {
        for (int j = maxk-2 ; j >= 0 ; --j) {
            sum[i][j] = Sum(sum[i][j],Sum(sum[i][j+1],sum[i-1][j]));
        }
        printf("%d ",Sum(sum[i][0],a[i]));
    }
    printf("\n");
    return 0 ;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

#define FOREACH(i, c) for(__typeof( (c).begin() ) i = (c).begin(); i != (c).end(); ++i)
#define FOR(i, a, n) for(__typeof(n) i = (a); i<(n); ++i)
#define REP(i, a, n) for(__typeof(n) i = (a); i<=(n); ++i)
#define ROF(i, n, a) for(__typeof(n) i = (n); i>=(a); --i)
#define error(n) cout << #n << " = " << n << endl
#define all(c) c.begin(), c.end()
#define pb push_back
#define po pop_back
#define Size(n) ((int)(n).size())
#define X first
#define Y second
int _ ;
#define scanf _ = scanf
// #define X real()
// #define Y imag()

typedef long long   ll ;
typedef long double ld ;
typedef pair<int,int> pii ;

const int maxk = 102;
const int maxn = 101 * 1000;
const ll mod = 1000LL * 1000 * 1000 + 7;

int n, m;

ll a[maxn];
int choice[maxk][maxk];
int sum[maxn][maxk];

int Sum(ll a , ll b) {
    return (a+b)%mod;
}

int Mul(ll a , ll b) {
    return (a*b)%mod;
}

ll Pow(ll a , ll b) {
    if (b == 0) return 1%mod;
    ll c = Pow(a,b/2);
    c = Mul(c,c);
    if (b%2 == 1)
        c = Mul(c,a);
    return c;
}

ll Reverse(ll x) {
    return Pow(x,mod-2);
}

int main() {
    scanf ("%d %d",&n,&m);
    REP (i,1,n) {
        int x;
        scanf ("%d",&x);
        a[i] = x;
    }
    //
    for (int i = 0 ; i < maxk ; ++i) {
        choice[i][0] = choice[i][i] = 1;
        for (int j = 1 ; j < i ; ++j) {
            choice[i][j] = Sum(choice[i-1][j-1],choice[i-1][j]);
        }
    }
    //
    FOR (i,0,m) {
        int l , r , k;
        scanf ("%d %d %d",&l,&r,&k);
        int x = 0;
        for (int j = l ; x <= k && j <= r ; ++j , ++x) {
            sum[j][x] = Sum(sum[j][x],choice[k][x]);
        }
        --x;
        if (r-l <= k) {
            ll cur = choice[k][x];
            int start = k-(r-l);
            for (int j = start , lp = k , rp = x ; j <= k ; ++j , ++lp , ++rp) {
                if (j > start) {
                    cur = Mul(Mul(cur,lp) ,Reverse(rp) );
                }
                sum[r+1][k-j] = Sum(sum[r+1][k-j],(-cur%mod)+mod);
            }
        } else {
            ll cur = 1;
            for (int j = 0 ; j <= k ; ++j) {
                if (j) {
                    cur = Mul(cur,Mul(r-l+j,Reverse(j)));
                }
                sum[r+1][k-j] = Sum(sum[r+1][k-j],(-cur%mod)+mod);
            }
        }
    }
    //
    REP (i,1,n) {
        for (int j = maxk-2 ; j >= 0 ; --j) {
            sum[i][j] = Sum(sum[i][j],Sum(sum[i][j+1],sum[i-1][j]));
        }
        printf("%d ",Sum(sum[i][0],a[i]));
    }
    printf("\n");
    return 0 ;
}


#include <bits/stdc++.h>

#define mp make_pair
#define st first
#define nd second
#define pb push_back

using namespace std;

typedef long long ll;
typedef pair< ll,ll > pll;
typedef pair< int,int > pii;

const int inf = 1000000000, N = 100000, K = 100, mod = 1000000007;

int n, m, a[N+5], d[K+5][N+5], comb[N+K+5][K+5];

int main()
{
	int l, r, k;

	scanf("%d %d", &n, &m);

	comb[0][0] = 1;

	for (int i = 1; i <= n+K; i++) {
		comb[i][0] = 1;
		for (int j = 1; j <= min(K, i); j++)
			comb[i][j] = (comb[i-1][j] + comb[i-1][j-1]) % mod;
	}

	for (int i = 1; i <= n; i++) {
		scanf("%d", a+i);
	}

	for (int i = 1; i <= m; i++) {
		scanf("%d %d %d", &l, &r, &k);

		d[k][l]++;
		d[k][l] %= mod;
		for (int i = 0; i <= k; i++) {
			d[k-i][r+1] = (d[k-i][r+1] - comb[r-l+i][i]) % mod;
			d[k-i][r+1] += mod;
			d[k-i][r+1] %= mod;
		}
	}

	for (int i = K; i >= 0; i--) {
		for (int j = 1; j <= n; j++)
			d[i][j] = ((ll) d[i][j] + d[i+1][j] + d[i][j-1]) % mod;
	}

	for (int i = 1; i <= n; i++)
		printf("%d ", (a[i] + d[0][i]) % mod);

	return 0;
}


#include <bits/stdc++.h>

#define mp make_pair
#define st first
#define nd second
#define pb push_back

using namespace std;

typedef long long ll;
typedef pair< ll,ll > pll;
typedef pair< int,int > pii;

const int inf = 1000000000, N = 100000, K = 100, mod = 1000000007;

int n, m, a[N+5], d[K+5][N+5], comb[N+5][K+5];

int main()
{
	int l, r, k;

	scanf("%d %d", &n, &m);

	comb[0][0] = 1;

	for (int i = 1; i <= n; i++) {
		comb[i][0] = 1;
		for (int j = 1; j <= min(K, i); j++)
			comb[i][j] = (comb[i-1][j] + comb[i-1][j-1]) % mod;
	}

	for (int i = 1; i <= n; i++) {
		scanf("%d", a+i);
	}

	for (int i = 1; i <= m; i++) {
		scanf("%d %d %d", &l, &r, &k);

		d[k][l]++;
		for (int i = 0; i <= k; i++) {
			d[k-i][r+1] -= comb[r-l+i][i];
			d[k-i][r+1] += mod;
			d[k-i][r+1] %= mod;
		}
	}

	for (int i = K; i >= 0; i--) {
		for (int j = 1; j <= n; j++)
			d[i][j] = (d[i][j] + d[i+1][j] + d[i][j-1]) % mod;
	}

	for (int i = 1; i <= n; i++)
		printf("%d ", (a[i] + d[0][i]) % mod);

	return 0;
}


#include <bits/stdc++.h>

#define mp make_pair
#define st first
#define nd second
#define pb push_back

using namespace std;

typedef long long ll;
typedef pair< ll,ll > pll;
typedef pair< int,int > pii;

const int inf = 1000000000, N = 100000, K = 100, mod = 1000000007;

int n, m, a[N+5], d[K+5][N+5], comb[N+K+5][K+5];

int main()
{
	int l, r, k;

	scanf("%d %d", &n, &m);

	comb[0][0] = 1;

	for (int i = 1; i <= n+K; i++) {
		comb[i][0] = 1;
		for (int j = 1; j <= min(K, i); j++)
			comb[i][j] = (comb[i-1][j] + comb[i-1][j-1]) % mod;
	}

	for (int i = 1; i <= n; i++) {
		scanf("%d", a+i);
	}

	for (int i = 1; i <= m; i++) {
		scanf("%d %d %d", &l, &r, &k);

		d[k][l]++;
		d[k][l] %= mod;
		for (int i = 0; i <= k; i++) {
			d[k-i][r+1] = (d[k-i][r+1] - comb[r-l+i][i]) % mod;
			d[k-i][r+1] += mod;
			d[k-i][r+1] %= mod;
		}
	}

	for (int i = K; i >= 0; i--) {
		for (int j = 1; j <= n; j++)
			d[i][j] = (d[i][j] + d[i+1][j] + d[i][j-1]) % mod;
	}

	for (int i = 1; i <= n; i++)
		printf("%d ", (a[i] + d[0][i]) % mod);

	return 0;
}


#include <bits/stdc++.h>

#define mp make_pair
#define st first
#define nd second
#define pb push_back

using namespace std;

typedef long long ll;
typedef pair< ll,ll > pll;
typedef pair< int,int > pii;

const int inf = 1000000000, N = 100000, K = 100, mod = 1000000007;

int n, m, a[N+5], d[K+5][N+5], comb[N+K+5][K+5];

int main()
{
	int l, r, k;

	scanf("%d %d", &n, &m);

	comb[0][0] = 1;

	for (int i = 1; i <= n+K; i++) {
		comb[i][0] = 1;
		for (int j = 1; j <= min(K, i); j++)
			comb[i][j] = (comb[i-1][j] + comb[i-1][j-1]) % mod;
	}

	for (int i = 1; i <= n; i++) {
		scanf("%d", a+i);
	}

	for (int i = 1; i <= m; i++) {
		scanf("%d %d %d", &l, &r, &k);

		d[k][l]++;
		for (int i = 0; i <= k; i++) {
			d[k-i][r+1] -= comb[r-l+i][i];
			d[k-i][r+1] += mod;
			d[k-i][r+1] %= mod;
		}
	}

	for (int i = K; i >= 0; i--) {
		for (int j = 1; j <= n; j++)
			d[i][j] = (d[i][j] + d[i+1][j] + d[i][j-1]) % mod;
	}

	for (int i = 1; i <= n; i++)
		printf("%d ", (a[i] + d[0][i]) % mod);

	return 0;
}


#include <bits/stdc++.h>

#define mp make_pair
#define st first
#define nd second
#define pb push_back

using namespace std;

typedef long long ll;
typedef pair< ll,ll > pll;
typedef pair< int,int > pii;

const int inf = 1000000000, N = 1000, mod = 10007;

int n, b[N+5][N+5], cnt[4][N+5][N+5], cnt2[N+5], a[N+5][N+5], temp[N+5][N+5], sum[4][N+5][N+5];

void rotate (int a[][N+5]) {
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++)
			temp[i][j] = a[j][n-i+1];
	}

	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			a[i][j] = temp[i][j];
}

void print (int a[][N+5]) {
	for (int i = 1; i <= n; i++, puts(""))
		for (int j = 1; j <= n; j++)
			printf("%d ", a[i][j]);

	puts("");
}

void histogram_pass(int a[], int cnt[]) {
	memset(cnt2, 0, sizeof cnt2);
	stack<pii> s;

	for (int i = 1; i <= n+1; i++) {
		int h, j = i;

		while (!s.empty() && s.top().st >= a[i]) {
			h = s.top().st;
			j = s.top().nd;
			s.pop();

			int t = s.empty() ? 0 : s.top().st;

			cnt[j] += h - max(a[i], t);
			cnt[i] -= h - max(a[i], t);
			cnt2[i] -= (h - max(a[i], t)) * (i - j);

			cnt[i] %= mod;
			cnt2[i] %= mod;
		}

		s.push( mp(a[i], j) );
	}

	for (int i = 1; i <= n; i++) {
		cnt[i] += cnt[i-1];
		cnt[i] %= mod;
	}
	for (int i = 1; i <= n; i++) {
		cnt[i] += cnt[i-1] + cnt2[i];
		cnt[i] %= mod;
	}
	for (int i = 1; i <= n; i++) {
		if (a[i] > 0)
			cnt[i]--;
		cnt[i] += mod;
		cnt[i] %= mod;
	}
}

int main()
{
	char ch;

	scanf("%d", &n);

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			scanf(" %c", &ch);

			if (ch == 'C')
				a[i][j] = 1;
		}
	}

	for (int i = 0; i < 4; i++) {
		for (int j = 1; j <= n; j++) {
			for (int k = 1; k <= n; k++)
				b[j][k] = (b[j-1][k] + 1) * (a[j][k]);
		}

		for (int j = 1; j <= n; j++) {
			histogram_pass(b[j], cnt[i][j]);
		}

		for (int j = i; j < 4; j++)
			rotate(cnt[i]);

		rotate(a);
	}

	for (int i = 0; i < 4; i++) {
		for (int j = 1; j <= n; j++)
			for (int k = 1; k <= n; k++) {
				sum[i][j][k] = sum[i][j-1][k] + sum[i][j][k-1] - sum[i][j-1][k-1] + cnt[i][j][k];
				sum[i][j][k] %= mod;
				sum[i][j][k] += mod;
				sum[i][j][k] %= mod;
			}
	}

	int ans = 0;

	for (int i = 1; i <= n; i++) {
		ans += (sum[1][n][i] - sum[1][n][i-1]) * (sum[0][n][i-1]) % mod;
	}

	for (int i = 1; i <= n; i++) {
		ans += (sum[2][i][n] - sum[2][i-1][n]) * (sum[0][i-1][n]) % mod;
	}

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			ans -= cnt[0][i][j] * (sum[2][n][n] - sum[2][i][n] - sum[2][n][j] + sum[2][i][j]) % mod;
			ans -= cnt[1][i][j] * (sum[3][n][j-1] - sum[3][i][j-1]) % mod;
			ans %= mod;
		}
	}

	printf("%d\n", (ans % mod + mod) % mod);

	return 0;
}


#include <bits/stdc++.h>

#define mp make_pair
#define st first
#define nd second
#define pb push_back

using namespace std;

typedef long long ll;
typedef pair< ll,ll > pll;
typedef pair< int,int > pii;

const int inf = 1000000000, N = 100000, K = 100, mod = 1000000007;

int n, m, a[N+5], d[K+5][N+5], comb[N+K+5][K+5];

int main()
{
	int l, r, k;

	scanf("%d %d", &n, &m);

	comb[0][0] = 1;

	for (int i = 1; i <= n+K; i++) {
		comb[i][0] = 1;
		for (int j = 1; j <= min(K, i); j++)
			comb[i][j] = (comb[i-1][j] + comb[i-1][j-1]) % mod;
	}

	for (int i = 1; i <= n; i++) {
		scanf("%d", a+i);
	}

	for (int i = 1; i <= m; i++) {
		scanf("%d %d %d", &l, &r, &k);

		d[k][l]++;
		for (int i = 0; i <= k; i++) {
			d[k-i][r+1] = (d[k-i][r+1] - comb[r-l+i][i]) % mod;
			d[k-i][r+1] += mod;
			d[k-i][r+1] %= mod;
		}
	}

	for (int i = K; i >= 0; i--) {
		for (int j = 1; j <= n; j++)
			d[i][j] = (d[i][j] + d[i+1][j] + d[i][j-1]) % mod;
	}

	for (int i = 1; i <= n; i++)
		printf("%d ", (a[i] + d[0][i]) % mod);

	return 0;
}


#include <bits/stdc++.h>

#define mp make_pair
#define st first
#define nd second
#define pb push_back

using namespace std;

typedef long long ll;
typedef pair< ll,ll > pll;
typedef pair< int,int > pii;

const int inf = 1000000000, N = 100000, K = 100;

int n, m, a[N+5], d[K+5][N+5], comb[N+5][K+5];

int main()
{
	int l, r, k;

	scanf("%d %d", &n, &m);

	comb[0][0] = 1;

	for (int i = 1; i <= n; i++) {
		comb[i][0] = 1;
		for (int j = 1; j <= min(K, i); j++)
			comb[i][j] = comb[i-1][j] + comb[i-1][j-1];
	}

	for (int i = 1; i <= n; i++) {
		scanf("%d", a+i);
	}

	for (int i = 1; i <= m; i++) {
		scanf("%d %d %d", &l, &r, &k);

		d[k][l]++;
		for (int i = 0; i <= k; i++) {
			d[k-i][r+1] -= comb[r-l+1][i];
		}
	}

	for (int i = K; i >= 0; i--) {
		for (int j = 1; j <= n; j++)
			d[i][j] += d[i+1][j] + d[i][j-1];
	}

	for (int i = 1; i <= n; i++)
		printf("%d ", a[i] + d[0][i]);

	return 0;
}


#include <bits/stdc++.h>

#define mp make_pair
#define st first
#define nd second
#define pb push_back

using namespace std;

typedef long long ll;
typedef pair< ll,ll > pll;
typedef pair< int,int > pii;

const int inf = 1000000000, N = 100000, K = 100, mod = 1000000007;

int n, m, a[N+5], d[K+5][N+5], comb[N+K+5][K+5];

int main()
{
	int l, r, k;

	scanf("%d %d", &n, &m);

	comb[0][0] = 1;

	for (int i = 1; i <= n+k; i++) {
		comb[i][0] = 1;
		for (int j = 1; j <= min(K, i); j++)
			comb[i][j] = (comb[i-1][j] + comb[i-1][j-1]) % mod;
	}

	for (int i = 1; i <= n; i++) {
		scanf("%d", a+i);
	}

	for (int i = 1; i <= m; i++) {
		scanf("%d %d %d", &l, &r, &k);

		d[k][l]++;
		for (int i = 0; i <= k; i++) {
			d[k-i][r+1] -= comb[r-l+i][i];
			d[k-i][r+1] += mod;
			d[k-i][r+1] %= mod;
		}
	}

	for (int i = K; i >= 0; i--) {
		for (int j = 1; j <= n; j++)
			d[i][j] = (d[i][j] + d[i+1][j] + d[i][j-1]) % mod;
	}

	for (int i = 1; i <= n; i++)
		printf("%d ", (a[i] + d[0][i]) % mod);

	return 0;
}


#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cmath>
#include<ctime>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<iomanip>
#include<utility>
using namespace std;
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define rg register
#define il inline
#define lch(x) ((x)<<1)
#define rch(x) ((x)<<1^1)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define rep0(i,n) for(register int i=0;i<(n);++i)
#define rep(i,st,ed) for(register int i=(st);i<=(ed);++i)
#define per(i,ed,st) for(register int i=(ed);i>=(st);--i)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef double dbl;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> il T qmin(const T &a,const T &b){return a<b?a:b;}
template<typename T> il T qmax(const T &a,const T &b){return a>b?a:b;}
template<typename T> il void getmin(T &a,const T &b){if(a>b) a=b;}
template<typename T> il void getmax(T &a,const T &b){if(a<b) a=b;}
il void fileio(string s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}

const int mod=(int)1e9+7;
const ll linf=(ll)1e17+7;
const int N=1e5+7;

int b[N][105],a[N],rev[105],n,m;

il void inc(int &x,const int &y=1){
	x+=y;
	if(x>=mod) x-=mod;
}

il void dec(int &x,const int &y=1){
	x-=y;
	if(x<0) x+=mod;
}

il int qpow(ll x,int y){
	ll ans=1;
	while(y){
		if(y&1) ans=ans*x%mod;
		x=x*x%mod;
		y>>=1;
	}
	return ans;
}

il void init(){
	rev[0]=1;
	rep(i,1,100) rev[i]=(ll)rev[i-1]*qpow(i,mod-2)%mod;
}

il int c(int n,int k){
	ll ans=rev[k];
	rep(i,n-k+1,n) ans=ans*i%mod;
	return ans;
}

int main(){
	init();
	scanf("%d%d",&n,&m);
	rep(i,1,n) scanf("%d",a+i);
	while(m--){
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		inc(b[l][k]);
		rep(i,0,k) dec(b[r+1][k-i],c(r-l+i,i));
	}
/*	rep(i,1,n){
		rep(j,0,3) cerr<<b[i][j]<<" ";
		cerr<<endl;
	}
	cerr<<endl;
*/	rep(i,1,n){
		per(j,100,0){
			inc(b[i][j],b[i][j+1]);
			inc(b[i][j],b[i-1][j]);
		}
		inc(a[i],b[i][0]);
		printf("%d ",a[i]);
	}
	return puts(""),0;
}


#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cmath>
#include<ctime>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<iomanip>
#include<utility>
using namespace std;
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define rg register
#define il inline
#define lch(x) ((x)<<1)
#define rch(x) ((x)<<1^1)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define rep0(i,n) for(register int i=0;i<(n);++i)
#define rep(i,st,ed) for(register int i=(st);i<=(ed);++i)
#define per(i,ed,st) for(register int i=(ed);i>=(st);--i)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef double dbl;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> il T qmin(const T &a,const T &b){return a<b?a:b;}
template<typename T> il T qmax(const T &a,const T &b){return a>b?a:b;}
template<typename T> il void getmin(T &a,const T &b){if(a>b) a=b;}
template<typename T> il void getmax(T &a,const T &b){if(a<b) a=b;}
il void fileio(string s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}

const int mod=(int)1e9+7;
const ll linf=(ll)1e17+7;
const int N=1e5+7;

int b[N][105],a[N],fac[N],rev[N],n,m;

il void inc(int &x,const int &y=1){
	x+=y;
	if(x>=mod) x-=mod;
}

il void dec(int &x,const int &y=1){
	x-=y;
	if(x<0) x+=mod;
}

il int qpow(ll x,int y){
	ll ans=1;
	while(y){
		if(y&1) ans=ans*x%mod;
		x=x*x%mod;
		y>>=1;
	}
	return ans;
}

il void init(){
	fac[0]=rev[0]=1;
	rep(i,1,N-1){
		fac[i]=(ll)fac[i-1]*i%mod;
		rev[i]=qpow(fac[i],mod-2);
	}
}

il int c(int n,int k){
	return (ll)fac[n]*rev[n-k]%mod*rev[k]%mod;
}

int main(){
//	fileio("data");
	init();
	scanf("%d%d",&n,&m);
	rep(i,1,n) scanf("%d",a+i);
	while(m--){
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		inc(b[l][k]);
		rep(i,0,k) dec(b[r+1][k-i],c(r-l+i,i));
	}
/*	rep(i,1,n){
		rep(j,0,3) cerr<<b[i][j]<<" ";
		cerr<<endl;
	}
	cerr<<endl;
*/	rep(i,1,n){
		per(j,100,0){
			inc(b[i][j],b[i][j+1]);
			inc(b[i][j],b[i-1][j]);
		}
		inc(a[i],b[i][0]);
		printf("%d ",a[i]);
	}
//	cerr<<(dbl)clock()/CLOCKS_PER_SEC<<endl;
	return puts(""),0;
}


#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cmath>
#include<ctime>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<iomanip>
#include<utility>
using namespace std;
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define rg register
#define il inline
#define lch(x) ((x)<<1)
#define rch(x) ((x)<<1^1)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define rep0(i,n) for(register int i=0;i<(n);++i)
#define rep(i,st,ed) for(register int i=(st);i<=(ed);++i)
#define per(i,ed,st) for(register int i=(ed);i>=(st);--i)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef double dbl;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> il T qmin(const T &a,const T &b){return a<b?a:b;}
template<typename T> il T qmax(const T &a,const T &b){return a>b?a:b;}
template<typename T> il void getmin(T &a,const T &b){if(a>b) a=b;}
template<typename T> il void getmax(T &a,const T &b){if(a<b) a=b;}
il void fileio(string s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}

const int mod=(int)1e9+7;
const ll linf=(ll)1e17+7;
const int N=1e5+7;

int b[N][105],a[N],rev[105],n,m;

il void inc(int &x,const int &y=1){
	x+=y;
	if(x>=mod) x-=mod;
}

il void dec(int &x,const int &y=1){
	x-=y;
	if(x<0) x+=mod;
}

il int qpow(ll x,int y){
	ll ans=1;
	while(y){
		if(y&1) ans=ans*x%mod;
		x=x*x%mod;
		y>>=1;
	}
	return ans;
}

il void init(){
	rev[0]=1;
	rep(i,1,100) rev[i]=(ll)rev[i-1]*qpow(i,mod-2)%mod;
}

il int c(int n,int k){
	ll ans=rev[k];
	rep(i,n-k+1,n) ans=ans*i%mod;
	return ans;
}

int main(){
	init();
	scanf("%d%d",&n,&m);
	rep(i,1,n) scanf("%d",a+i);
	while(m--){
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		inc(b[l][k]);
		rep(i,0,k) dec(b[r+1][k-i],c(k+r-l,i));
	}
/*	rep(i,1,n){
		rep(j,0,3) cerr<<b[i][j]<<" ";
		cerr<<endl;
	}
	cerr<<endl;
*/	rep(i,1,n){
		per(j,100,0){
			inc(b[i][j],b[i][j+1]);
			inc(b[i][j],b[i-1][j]);
		}
		inc(a[i],b[i][0]);
		printf("%d ",a[i]);
	}
	return puts(""),0;
}


/// *********************************************** K
/// B *                                           * H
/// I *    Solved By : Bir Bahadur Khatri(B'ru)   * A
/// R *      Be Positive,be Happy.                * T
/// U *                                           * R
/// *********************************************** I

#include<bits/stdc++.h>

#define LL long long int
#define ULL unsigned LL
#define PI 2.0*acos(0.0)
#define D double
#define sz size()
#define PB push_back
#define cp printf("here\n");
#define NL printf("\n")
#define CHR getchar()
#define SQR(n) (n*n)
#define MEM(a,val) memset(a,val,sizeof(a))
#define Max(a,b) ((a>b)?a:b)
#define Min(a,b) ((a<b)?a:b)
#define _Max(a,b,c) Max(a,Max(b,c))
#define _Min(a,b,c) Min(a,Min(b,c))
#define S1(a) a=in<int>()
#define S2(a,b) a=in<int>(),b=in<int>()
#define S3(a,b,c) a=in<int>(),b=in<int>(),c=in<int>()
#define SL1(a) a=in<LL>()
#define SL2(a,b) a=in<LL>(),b=in<LL>()
#define SL3(a,b,c) a=in<LL>(),b=in<LL>(),c=in<LL>()
#define F(i,a,b) for(int i=a;i<b; i++)
#define R(i,a,b) for(int i=a-1;i>=b; i--)
#define all(a) a.begin(),a.end()
#define cnt_bit(a) __builtin_popcountll(a)
#define InpOut freopen("A.in","r",stdin),freopen("A1.out","w",stdout)
#define _cin ios_base::sync_with_stdio(0)
#include <time.h>

using namespace std;
template <typename T> T in(){char ch;T n = 0;bool ng = false;while (1){ch = getchar();if (ch == '-'){ng = true;ch = getchar();break;}if (ch>='0' && ch<='9')     break;}while (1){n = n*10 + (ch - '0');ch = getchar();if (ch<'0' || ch>'9')   break;}return (ng?-n:n);}
template<typename T>inline T Dist(T x1,T y1,T x2, T y2){return sqrt( SQR(x1-x2) + SQR(y1-y2) );}
template<typename T>inline T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
template<typename T>inline T ABS(T a) {if(a<0)return -a;else return a;}
template<typename T>inline T Gcd(T a,T b){if(a<0)return Gcd(-a,b);if(b<0)return Gcd(a,-b);return (b==0)?a:Gcd(b,a%b);}
template<typename T>inline T Lcm(T a,T b) {if(a<0)return Lcm(-a,b);if(b<0)return Lcm(a,-b);return a*(b/Gcd(a,b));}
long long Bigmod(long long base, long long power, long long MOD){long long ret=1;while(power){if(power & 1)ret=(ret*base)%MOD;base=(base*base)%MOD;power>>=1;}return ret;}
long long ModInverse(long long number, long long MOD){return Bigmod(number, MOD-2, MOD);}
int Set(int N,int pos){ return N=N | (1<<pos);}
int Reset(int N,int pos){return N= N & ~(1<<pos);}
bool Chkbit(int N,int pos){return (bool)(N & (1<<pos));}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
bool isConst(char ch){if (isalpha(ch) && !isVowel(ch)) return true; return false;}
int toInt(string s)  { int sm; stringstream ss(s); ss>>sm; return sm; }
long long int toLlint(string s) { long long int sm; stringstream ss(s); ss>>sm; return sm;}
template <typename T> LL isLeft(T a,T b,T c) { return (a.x-b.x)*(b.y-c.y)-(b.x-c.x)*(a.y-b.y); }
///**********************************************************//

///         0123456789
#define MX  100005
#define MOD 1000000007
#define INF (1<<28)
#define eps 1e-9

/// ==========================================////

LL ncr[102][100002],dp[102][MX];

int ar[MX];

int main()
{
    ncr[0][0]=1ll;
    for(int i=1;i<=100000;i++) ncr[0][i]=1ll;
    for(int i=1;i<=100;i++){
        ncr[i][0]=1ll;
        for(int j=1;j<=100000;j++){
            ncr[i][j]=(ncr[i][j-1]+ncr[i-1][j])%MOD;
        }
    }

    int n,q;
    S2(n,q);

    for(int i=1;i<=n;i++) S1(ar[i]);

    while(q--) {
        int l,r,k;
        S3(l,r,k);

        dp[k][l]=(dp[k][l]+1)%MOD;

        for(int j=0;j<=k;j++) {
            dp[j][r+1]=(dp[j][r+1]-ncr[k-j][ r-l ]+MOD)%MOD;
        }
    }

    for(int i=100;i>=0;i--) {
        for(int j=1;j<=n;j++) {
            dp[i][j]=(dp[i][j-1]+dp[i+1][j]+dp[i][j])%MOD;
        }
    }

    for(int i=1;i<=n;i++) {
        printf("%lld ",(ar[i]+dp[0][i])%MOD);
    }

    return 0;
}

///============= Thank You ===================///


/// *********************************************** K
/// B *                                           * H
/// I *    Solved By : Bir Bahadur Khatri(B'ru)   * A
/// R *      Be Positive,be Happy.                * T
/// U *                                           * R
/// *********************************************** I

#include<bits/stdc++.h>

#define LL long long int
#define ULL unsigned LL
#define PI 2.0*acos(0.0)
#define D double
#define sz size()
#define PB push_back
#define cp printf("here\n");
#define NL printf("\n")
#define CHR getchar()
#define SQR(n) (n*n)
#define MEM(a,val) memset(a,val,sizeof(a))
#define Max(a,b) ((a>b)?a:b)
#define Min(a,b) ((a<b)?a:b)
#define _Max(a,b,c) Max(a,Max(b,c))
#define _Min(a,b,c) Min(a,Min(b,c))
#define S1(a) a=in<int>()
#define S2(a,b) a=in<int>(),b=in<int>()
#define S3(a,b,c) a=in<int>(),b=in<int>(),c=in<int>()
#define SL1(a) a=in<LL>()
#define SL2(a,b) a=in<LL>(),b=in<LL>()
#define SL3(a,b,c) a=in<LL>(),b=in<LL>(),c=in<LL>()
#define F(i,a,b) for(int i=a;i<b; i++)
#define R(i,a,b) for(int i=a-1;i>=b; i--)
#define all(a) a.begin(),a.end()
#define cnt_bit(a) __builtin_popcountll(a)
#define InpOut freopen("A.in","r",stdin),freopen("A1.out","w",stdout)
#define _cin ios_base::sync_with_stdio(0)
#include <time.h>

using namespace std;
template <typename T> T in(){char ch;T n = 0;bool ng = false;while (1){ch = getchar();if (ch == '-'){ng = true;ch = getchar();break;}if (ch>='0' && ch<='9')     break;}while (1){n = n*10 + (ch - '0');ch = getchar();if (ch<'0' || ch>'9')   break;}return (ng?-n:n);}
template<typename T>inline T Dist(T x1,T y1,T x2, T y2){return sqrt( SQR(x1-x2) + SQR(y1-y2) );}
template<typename T>inline T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
template<typename T>inline T ABS(T a) {if(a<0)return -a;else return a;}
template<typename T>inline T Gcd(T a,T b){if(a<0)return Gcd(-a,b);if(b<0)return Gcd(a,-b);return (b==0)?a:Gcd(b,a%b);}
template<typename T>inline T Lcm(T a,T b) {if(a<0)return Lcm(-a,b);if(b<0)return Lcm(a,-b);return a*(b/Gcd(a,b));}
long long Bigmod(long long base, long long power, long long MOD){long long ret=1;while(power){if(power & 1)ret=(ret*base)%MOD;base=(base*base)%MOD;power>>=1;}return ret;}
long long ModInverse(long long number, long long MOD){return Bigmod(number, MOD-2, MOD);}
int Set(int N,int pos){ return N=N | (1<<pos);}
int Reset(int N,int pos){return N= N & ~(1<<pos);}
bool Chkbit(int N,int pos){return (bool)(N & (1<<pos));}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
bool isConst(char ch){if (isalpha(ch) && !isVowel(ch)) return true; return false;}
int toInt(string s)  { int sm; stringstream ss(s); ss>>sm; return sm; }
long long int toLlint(string s) { long long int sm; stringstream ss(s); ss>>sm; return sm;}
template <typename T> LL isLeft(T a,T b,T c) { return (a.x-b.x)*(b.y-c.y)-(b.x-c.x)*(a.y-b.y); }
///**********************************************************//

///         0123456789
#define MX  100005
#define MOD 1000000007
#define INF (1<<28)
#define eps 1e-9

/// ==========================================////

LL Ncr[100002][102],dp[102][MX];

int ar[MX];

int main()
{
    Ncr[0][0]=Ncr[1][0]=Ncr[1][1]=1;
    for(int i=2;i<=100000;i++) {
        Ncr[i][0]=Ncr[i][i]=1;
        for(int j=1;j<=100;j++) {
            Ncr[i][j]=(Ncr[i-1][j-1]+Ncr[i-1][j])%MOD;
        }
    }

    int n,q;
    S2(n,q);

    for(int i=1;i<=n;i++) S1(ar[i]);

    while(q--) {
        int l,r,k;
        S3(l,r,k);

        dp[k][l]=(dp[k][l]+1)%MOD;

        for(int j=0;j<=k;j++) {
            dp[j][r+1]=(dp[j][r+1]-Ncr[ r-l ][k-j]+MOD)%MOD;
        }
    }

    for(int i=100;i>=0;i--) {
        for(int j=1;j<=n;j++) {
            dp[i][j]=(dp[i][j-1]+dp[i+1][j]+dp[i][j])%MOD;
        }
    }

    for(int i=1;i<=n;i++) {
        printf("%lld ",(ar[i]+dp[0][i])%MOD);
    }

    return 0;
}

///============= Thank You ===================///


/// *********************************************** K
/// B *                                           * H
/// I *    Solved By : Bir Bahadur Khatri(B'ru)   * A
/// R *      Be Positive,be Happy.                * T
/// U *                                           * R
/// *********************************************** I

#include<bits/stdc++.h>

#define LL long long int
#define ULL unsigned LL
#define PI 2.0*acos(0.0)
#define D double
#define sz size()
#define PB push_back
#define cp printf("here\n");
#define NL printf("\n")
#define CHR getchar()
#define SQR(n) (n*n)
#define MEM(a,val) memset(a,val,sizeof(a))
#define Max(a,b) ((a>b)?a:b)
#define Min(a,b) ((a<b)?a:b)
#define _Max(a,b,c) Max(a,Max(b,c))
#define _Min(a,b,c) Min(a,Min(b,c))
#define S1(a) a=in<int>()
#define S2(a,b) a=in<int>(),b=in<int>()
#define S3(a,b,c) a=in<int>(),b=in<int>(),c=in<int>()
#define SL1(a) a=in<LL>()
#define SL2(a,b) a=in<LL>(),b=in<LL>()
#define SL3(a,b,c) a=in<LL>(),b=in<LL>(),c=in<LL>()
#define F(i,a,b) for(int i=a;i<b; i++)
#define R(i,a,b) for(int i=a-1;i>=b; i--)
#define all(a) a.begin(),a.end()
#define cnt_bit(a) __builtin_popcountll(a)
#define InpOut freopen("A.in","r",stdin),freopen("A1.out","w",stdout)
#define _cin ios_base::sync_with_stdio(0)
#include <time.h>

using namespace std;
template <typename T> T in(){char ch;T n = 0;bool ng = false;while (1){ch = getchar();if (ch == '-'){ng = true;ch = getchar();break;}if (ch>='0' && ch<='9')     break;}while (1){n = n*10 + (ch - '0');ch = getchar();if (ch<'0' || ch>'9')   break;}return (ng?-n:n);}
template<typename T>inline T Dist(T x1,T y1,T x2, T y2){return sqrt( SQR(x1-x2) + SQR(y1-y2) );}
template<typename T>inline T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
template<typename T>inline T ABS(T a) {if(a<0)return -a;else return a;}
template<typename T>inline T Gcd(T a,T b){if(a<0)return Gcd(-a,b);if(b<0)return Gcd(a,-b);return (b==0)?a:Gcd(b,a%b);}
template<typename T>inline T Lcm(T a,T b) {if(a<0)return Lcm(-a,b);if(b<0)return Lcm(a,-b);return a*(b/Gcd(a,b));}
long long Bigmod(long long base, long long power, long long MOD){long long ret=1;while(power){if(power & 1)ret=(ret*base)%MOD;base=(base*base)%MOD;power>>=1;}return ret;}
long long ModInverse(long long number, long long MOD){return Bigmod(number, MOD-2, MOD);}
int Set(int N,int pos){ return N=N | (1<<pos);}
int Reset(int N,int pos){return N= N & ~(1<<pos);}
bool Chkbit(int N,int pos){return (bool)(N & (1<<pos));}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
bool isConst(char ch){if (isalpha(ch) && !isVowel(ch)) return true; return false;}
int toInt(string s)  { int sm; stringstream ss(s); ss>>sm; return sm; }
long long int toLlint(string s) { long long int sm; stringstream ss(s); ss>>sm; return sm;}
template <typename T> LL isLeft(T a,T b,T c) { return (a.x-b.x)*(b.y-c.y)-(b.x-c.x)*(a.y-b.y); }
///**********************************************************//

///         0123456789
#define MX  100005
#define MOD 1000000007
#define INF (1<<28)
#define eps 1e-9

/// ==========================================////

LL ncr[102][100002],dp[102][MX];

int ar[MX];

int main()
{
    ncr[0][0]=1ll;
    for(int i=1;i<=100000;i++) ncr[0][i]=1ll;
    for(int i=1;i<=100000;i++){
        ncr[i][0]=1ll;
        for(int j=1;j<=100;j++){
            ncr[i][j]=(ncr[i][j-1]+ncr[i-1][j])%MOD;
        }
    }

    int n,q;
    S2(n,q);

    for(int i=1;i<=n;i++) S1(ar[i]);

    while(q--) {
        int l,r,k;
        S3(l,r,k);

        dp[k][l]=(dp[k][l]+1)%MOD;

        for(int j=0;j<=k;j++) {
            dp[j][r+1]=(dp[j][r+1]-ncr[k-j][ r-l ]+MOD)%MOD;
        }
    }

    for(int i=100;i>=0;i--) {
        for(int j=1;j<=n;j++) {
            dp[i][j]=(dp[i][j-1]+dp[i+1][j]+dp[i][j])%MOD;
        }
    }

    for(int i=1;i<=n;i++) {
        printf("%lld ",(ar[i]+dp[0][i])%MOD);
    }

    return 0;
}

///============= Thank You ===================///


#include<iostream>
#include<fstream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<ctime>
#include<cstring>
#include<climits>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<algorithm>
#include<stack>
#include<deque>
#include<list>
#include<vector>
#define LL long long
using namespace std;
int n,m,cnt,snt,times;
int oo=1000000007;
int c[100110][105];
int f[100010][105];
void prepare()
{
    for (int i=0;i<=n+100;i++) c[i][0]=1;
    for (int j=1;j<=101;j++)
    for (int i=1;i<=n+100;i++)
    {
        c[i][j]=(c[i-1][j]+c[i-1][j-1])%oo;
    }
}
int C(int x,int y)
{
    if (y==0) return 1;
    if (x==y) return 1;
    return C(x-1,y)+C(x-1,y-1);
}
void work()
{
    prepare();
    for (int i=1;i<=m;i++)
    {
        int l,r,k;
        cin>>l>>r>>k;
        for (int j=1;j<=k;j++)
        {
            f[r+1][j]=(f[r+1][j]-c[k+r-l-j+1][k-j+1]+oo)%oo;
        }
        f[r+1][k+1]=(oo+f[r+1][k+1]-1)%oo;
        f[l][k+1]=(f[l][k+1]+1)%oo;
    }
    for (int j=101;j>=1;j--)
    {
        int sum=0;
        for (int i=1;i<=n+1;i++)
        {
            sum=(sum+f[i][j])%oo;
            f[i][j-1]=(f[i][j-1]+sum)%oo;
        }
    }
    for (int i=1;i<=n;i++)
    printf("%d ",f[i][0]);
    printf("\n");
}
int main()
{
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;i++) cin>>f[i][0],f[i][0]%=oo;
    work();
    return 0;
}


#include<iostream>
#include<fstream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<ctime>
#include<cstring>
#include<climits>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<algorithm>
#include<stack>
#include<deque>
#include<list>
#include<vector>
#define LL long long
using namespace std;
int n,m,cnt,snt,times;
int oo=1000000007;
int c[100010][105];
int f[100010][105];
LL C(int x,int y)
{
    if (x<0) return 0;
    if (x<y) return 0;
    if (x==y) return 1;
    if (y==0) return 1;
    if (c[x][y]!=-1) return c[x][y];
    return c[x][y]=(C(x-1,y)+C(x-1,y-1))%oo;
}
void work()
{
    for (int i=1;i<=m;i++)
    {
        int l,r,k;
        cin>>l>>r>>k;
        for (int j=1;j<=k;j++)
        {
            f[r+1][j]=(f[r+1][j]-C(k+r-l-j+1,k-j+1)+oo)%oo;
        }
        f[r+1][k+1]=(oo+f[r+1][k+1]-1)%oo;
        f[l][k+1]=(f[l][k+1]+1)%oo;
    }
    for (int j=101;j>=1;j--)
    {
        int sum=0;
        for (int i=1;i<=n+1;i++)
        {
            sum=(sum+f[i][j])%oo;
            f[i][j-1]=(f[i][j-1]+sum)%oo;
        }
    }
    for (int i=1;i<=n;i++)
    printf("%d ",f[i][0]);
    printf("\n");
}
int main()
{
    scanf("%d%d",&n,&m);
    memset(c,-1,sizeof(c));
    for (int i=1;i<=n;i++) cin>>f[i][0],f[i][0]%=oo;
    work();
    return 0;
}


#include<iostream>
#include<fstream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<ctime>
#include<cstring>
#include<climits>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<algorithm>
#include<stack>
#include<deque>
#include<list>
#include<vector>
#define LL long long
using namespace std;
int n,m,cnt,snt,times;
int oo=1000000007;
int c[100010][105];
int f[100010][105];
inline LL C(int x,int y)
{
    if (x<0) return 0;
    if (x<y) return 0;
    if (x==y) return 1;
    if (y==0) return 1;
    if (c[x][y]!=-1) return c[x][y];
    return c[x][y]=(C(x-1,y)+C(x-1,y-1))%oo;
}
void work()
{
    for (int i=1;i<=m;i++)
    {
        int l,r,k;
        cin>>l>>r>>k;
        for (int j=1;j<=k;j++)
        {
            f[r+1][j]=(oo+f[r+1][j]-C(k+r-l-j+1,k-j+1))%oo;
        }
        f[r+1][k+1]=(oo+f[r+1][k+1]-1)%oo;
        f[l][k+1]=(f[l][k+1]+1)%oo;
    }
    for (int j=101;j>=1;j--)
    {
        int sum=0;
        for (int i=1;i<=n+1;i++)
        {
            sum=(sum+f[i][j])%oo;
            f[i][j-1]=(f[i][j-1]+sum)%oo;
        }
    }
    for (int i=1;i<=n;i++)
    printf("%d ",f[i][0]);
    printf("\n");
}
int main()
{
    scanf("%d%d",&n,&m);
    memset(c,-1,sizeof(c));
    for (int i=1;i<=n;i++) cin>>f[i][0];
    work();
    return 0;
}


#include<iostream>
#include<fstream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<ctime>
#include<cstring>
#include<climits>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<algorithm>
#include<stack>
#include<deque>
#include<list>
#include<vector>
#define LL long long
using namespace std;
int n,m,cnt,snt,times;
LL oo=1000000007;
LL c[100010][105];
LL f[100010][105];
inline LL C(int x,int y)
{
    if (x<0) return 0;
    if (x<y) return 0;
    if (x==y) return 1;
    if (y==0) return 1;
    if (c[x][y]!=-1) return c[x][y];
    return c[x][y]=(C(x-1,y)+C(x-1,y-1))%oo;
}
void work()
{
    for (int i=1;i<=m;i++)
    {
        int l,r,k;
        cin>>l>>r>>k;
        for (int j=1;j<=k;j++)
        {
            f[r+1][j]=(f[r+1][j]-C(k+r-l-j+1,k-j+1)+oo)%oo;
        }
        f[r+1][k+1]=(oo+f[r+1][k+1]-1)%oo;
        f[l][k+1]=(f[l][k+1]+1)%oo;
    }
    for (int j=101;j>=1;j--)
    {
        int sum=0;
        for (int i=1;i<=n+1;i++)
        {
            sum=(sum+f[i][j])%oo;
            f[i][j-1]=(f[i][j-1]+sum)%oo;
        }
    }
    for (int i=1;i<=n;i++)
    cout<<f[i][0]<<" ";
    printf("\n");
}
int main()
{
    scanf("%d%d",&n,&m);
    memset(c,-1,sizeof(c));
    for (int i=1;i<=n;i++) cin>>f[i][0];
    work();
    return 0;
}


#include<iostream>
#include<fstream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<ctime>
#include<cstring>
#include<climits>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<algorithm>
#include<stack>
#include<deque>
#include<list>
#include<vector>
#define LL long long
using namespace std;
int n,m,cnt,snt,times;
int oo=1000000007;
int c[100010][105];
int f[100010][105];
inline LL C(int x,int y)
{
    if (x<0) return 0;
    if (x<y) return 0;
    if (x==y) return 1;
    if (y==0) return 1;
    if (c[x][y]!=-1) return c[x][y];
    return c[x][y]=(C(x-1,y)+C(x-1,y-1))%oo;
}
void work()
{
    for (int i=1;i<=m;i++)
    {
        int l,r,k;
        cin>>l>>r>>k;
        for (int j=1;j<=k;j++)
        {
            f[r+1][j]=(f[r+1][j]-C(k+r-l-j+1,k-j+1)+oo)%oo;
        }
        f[r+1][k+1]=(oo+f[r+1][k+1]-1)%oo;
        f[l][k+1]=(f[l][k+1]+1)%oo;
    }
    for (int j=101;j>=1;j--)
    {
        int sum=0;
        for (int i=1;i<=n+1;i++)
        {
            sum=(sum+f[i][j])%oo;
            f[i][j-1]=(f[i][j-1]+sum)%oo;
        }
    }
    for (int i=1;i<=n;i++)
    printf("%d ",f[i][0]);
    printf("\n");
}
int main()
{
    scanf("%d%d",&n,&m);
    memset(c,-1,sizeof(c));
    for (int i=1;i<=n;i++) cin>>f[i][0];
    work();
    return 0;
}


#include<iostream>
#include<fstream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<ctime>
#include<cstring>
#include<climits>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<algorithm>
#include<stack>
#include<deque>
#include<list>
#include<vector>
#define LL long long
using namespace std;
int n,m,cnt,snt,times;
int oo=1000000007;
int c[100010][105];
int f[100010][105];
inline LL C(int x,int y)
{
    if (x<0) return 0;
    if (x<y) return 0;
    if (x==y) return 1;
    if (y==0) return 1;
    if (c[x][y]!=-1) return c[x][y];
    return c[x][y]=(C(x-1,y)+C(x-1,y-1))%oo;
}
void work()
{
    for (int i=1;i<=m;i++)
    {
        int l,r,k;
        cin>>l>>r>>k;
        for (int j=1;j<=k;j++)
        {
            f[r+1][j]=(f[r+1][j]-C(k+r-l-j+1,k-j+1)+oo)%oo;
        }
        f[r+1][k+1]=(oo+f[r+1][k+1]-1)%oo;
        f[l][k+1]=(f[l][k+1]+1)%oo;
    }
    for (int j=101;j>=1;j--)
    {
        int sum=0;
        for (int i=1;i<=n+1;i++)
        {
            sum=(sum+f[i][j])%oo;
            f[i][j-1]=(f[i][j-1]+sum)%oo;
        }
    }
    for (int i=1;i<=n;i++)
    printf("%d ",f[i][0]);
    printf("\n");
}
int main()
{
    scanf("%d%d",&n,&m);
    memset(c,-1,sizeof(c));
    for (int i=1;i<=n;i++) cin>>f[i][0],f[i][0]%=oo;
    work();
    return 0;
}


#include<iostream>
#include<fstream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<ctime>
#include<cstring>
#include<climits>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<algorithm>
#include<stack>
#include<deque>
#include<list>
#include<vector>
#define LL long long
using namespace std;
int n,m,cnt,snt,times;
int oo=1000000007;
int c[100110][105];
int f[100010][105];
void prepare()
{
    for (int i=0;i<=n+100;i++) c[i][0]=1;
    for (int j=1;j<=101;j++)
    for (int i=1;i<=n+100;i++)
    {
        c[i][j]=(c[i-1][j]+c[i-1][j-1])%oo;
    }
}
void work()
{
    prepare();
    for (int i=1;i<=m;i++)
    {
        int l,r,k;
        cin>>l>>r>>k;
        for (int j=1;j<=k;j++)
        {
            f[r+1][j]=(f[r+1][j]-c[k+r-l-j+1][k-j+1]+oo)%oo;
        }
        f[r+1][k+1]=(oo+f[r+1][k+1]-1)%oo;
        f[l][k+1]=(f[l][k+1]+1)%oo;
    }
    for (int j=101;j>=1;j--)
    {
        int sum=0;
        for (int i=1;i<=n+1;i++)
        {
            sum=(sum+f[i][j])%oo;
            f[i][j-1]=(f[i][j-1]+sum)%oo;
        }
    }
    for (int i=1;i<=n;i++)
    printf("%d ",f[i][0]);
    printf("\n");
}
int main()
{
    scanf("%d%d",&n,&m);
    memset(c,-1,sizeof(c));
    for (int i=1;i<=n;i++) cin>>f[i][0],f[i][0]%=oo;
    work();
    return 0;
}


#include<iostream>
#include<fstream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<ctime>
#include<cstring>
#include<climits>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<algorithm>
#include<stack>
#include<deque>
#include<list>
#include<vector>
#define LL long long
using namespace std;
int n,m,cnt,snt,times;
int oo=1000000007;
int c[100110][105];
int f[100010][105];
void prepare()
{
    for (int i=0;i<=n+100;i++) c[i][0]=1;
    for (int i=1;i<=n+100;i++)
    for (int j=1;j<=101;j++)
    {
        c[i][j]=(c[i-1][j]+c[i-1][j-1])%oo;
    }
}
void work()
{
    prepare();
    for (int i=1;i<=m;i++)
    {
        int l,r,k;
        cin>>l>>r>>k;
        for (int j=1;j<=k;j++)
        {
            f[r+1][j]=(f[r+1][j]-c[k+r-l-j+1][k-j+1]+oo)%oo;
        }
        f[r+1][k+1]=(oo+f[r+1][k+1]-1)%oo;
        f[l][k+1]=(f[l][k+1]+1)%oo;
    }
    for (int j=101;j>=1;j--)
    {
        int sum=0;
        for (int i=1;i<=n+1;i++)
        {
            sum=(sum+f[i][j])%oo;
            f[i][j-1]=(f[i][j-1]+sum)%oo;
        }
    }
    for (int i=1;i<=n;i++)
    printf("%d ",f[i][0]);
    printf("\n");
}
int main()
{
    scanf("%d%d",&n,&m);
    memset(c,-1,sizeof(c));
    for (int i=1;i<=n;i++) cin>>f[i][0],f[i][0]%=oo;
    work();
    return 0;
}


#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <map>

#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
#define abs(x) ((x)>=0?(x):-(x))
#define i64 long long
#define u32 unsigned int
#define u64 unsigned long long
#define clr(x,y) memset(x,y,sizeof(x))
#define CLR(x) x.clear()
#define ph(x) push(x)
#define pb(x) push_back(x)
#define Len(x) x.length()
#define SZ(x) x.size()
#define PI acos(-1.0)
#define sqr(x) ((x)*(x))
#define MP(x,y) make_pair(x,y)

#define FOR0(i,x) for(i=0;i<x;i++)
#define FOR1(i,x) for(i=1;i<=x;i++)
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define FORL0(i,a) for(i=a;i>=0;i--)
#define FORL1(i,a) for(i=a;i>=1;i--)
#define FORL(i,a,b)for(i=a;i>=b;i--)
#define EPS 1e-10

#define rush() int CC;for(scanf("%d",&CC);CC--;)
#define Rush(n)  while(scanf("%d",&n)!=-1)
using namespace std;

void RD(int &x){scanf("%d",&x);}
void RD(i64 &x){scanf("%I64d",&x);}
void RD(u64 &x){scanf("%I64u",&x);}
void RD(u32 &x){scanf("%u",&x);}
void RD(double &x){scanf("%lf",&x);}
void RD(int &x,int &y){scanf("%d%d",&x,&y);}
void RD(i64 &x,i64 &y){scanf("%I64d%I64d",&x,&y);}
void RD(u32 &x,u32 &y){scanf("%u%u",&x,&y);}
void RD(double &x,double &y){scanf("%lf%lf",&x,&y);}
void RD(int &x,int &y,int &z){scanf("%d%d%d",&x,&y,&z);}
void RD(i64 &x,i64 &y,i64 &z){scanf("%I64d%I64d%I64d",&x,&y,&z);}
void RD(u32 &x,u32 &y,u32 &z){scanf("%u%u%u",&x,&y,&z);}
void RD(double &x,double &y,double &z){scanf("%lf%lf%lf",&x,&y,&z);}
void RD(char &x){x=getchar();}
void RD(char *s){scanf("%s",s);}
void RD(string &s){cin>>s;}

void PR(int x) {printf("%d\n",x);}
void PR(int x,int y) {printf("%d %d\n",x,y);}
void PR(i64 x) {printf("%I64d\n",x);}
void PR(u32 x) {printf("%u\n",x);}
void PR(u64 x) {printf("%I64u\n",x);}
void PR(double x) {printf("%.9lf\n",x);}
void PR(char x) {printf("%c\n",x);}
void PR(char *x) {printf("%s\n",x);}
void PR(string x) {cout<<x<<endl;}

void upMax(int &x,int y){if(x<y) x=y;}
void upMax(i64 &x,i64 y){if(x<y) x=y;}
void upMax(double &x,double y){if(x<y) x=y;}
void upMin(int &x,int y){if(x>y) x=y;}
void upMin(i64 &x,i64 y){if(x>y) x=y;}
void upMin(double &x,double y){if(x>y) x=y;}

int getInt()
{
    int x=0;
    char c=getchar();
    while(!isdigit(c)) c=getchar();
    while(isdigit(c)) x=x*10+c-48,c=getchar();
    return x;
}

const int mod=1000000007;
const i64 inf=((i64)1)<<60;
const double dinf=1e50;
const int INF=2000000005;
const int N=100105;

int C[N][105];

void init()
{
    int i,j;
    C[0][0]=1;
    for(i=1;i<N;i++)
    {
        C[i][0]=C[i][i]=1;
        for(j=1;j<=101;j++) C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
    }
}

int a[N],f[105][N],n,m;

int main()
{
    init();
    RD(n,m);
    int i,j,k;
    FOR1(i,n) a[i]=getInt();
    while(m--)
    {
        int L,R,k;
        RD(L,R,k);
        (f[k+1][L]+=1)%=mod;
        for(i=1;i<=k+1;i++)
        {
            (f[i][R+1]-=C[R-L+k+1-i][k+1-i])%=mod;
        }
    }
    for(i=100;i>=0;i--)
    {
        k=0;
        for(j=1;j<=n;j++)
        {
            (k+=f[i+1][j])%=mod;
            (f[i][j]+=k)%=mod;
        }
    }
    for(i=1;i<=n;i++)
    {
        (f[0][i]+=a[i])%=mod;
        if(f[0][i]<0) f[0][i]+=mod;
        printf("%d",f[0][i]);
        if(i<n) putchar(' ');
    }
    puts("");

}


#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <map>

#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
#define abs(x) ((x)>=0?(x):-(x))
#define i64 long long
#define u32 unsigned int
#define u64 unsigned long long
#define clr(x,y) memset(x,y,sizeof(x))
#define CLR(x) x.clear()
#define ph(x) push(x)
#define pb(x) push_back(x)
#define Len(x) x.length()
#define SZ(x) x.size()
#define PI acos(-1.0)
#define sqr(x) ((x)*(x))
#define MP(x,y) make_pair(x,y)

#define FOR0(i,x) for(i=0;i<x;i++)
#define FOR1(i,x) for(i=1;i<=x;i++)
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define FORL0(i,a) for(i=a;i>=0;i--)
#define FORL1(i,a) for(i=a;i>=1;i--)
#define FORL(i,a,b)for(i=a;i>=b;i--)
#define EPS 1e-10

#define rush() int CC;for(scanf("%d",&CC);CC--;)
#define Rush(n)  while(scanf("%d",&n)!=-1)
using namespace std;

void RD(int &x){scanf("%d",&x);}
void RD(i64 &x){scanf("%I64d",&x);}
void RD(u64 &x){scanf("%I64u",&x);}
void RD(u32 &x){scanf("%u",&x);}
void RD(double &x){scanf("%lf",&x);}
void RD(int &x,int &y){scanf("%d%d",&x,&y);}
void RD(i64 &x,i64 &y){scanf("%I64d%I64d",&x,&y);}
void RD(u32 &x,u32 &y){scanf("%u%u",&x,&y);}
void RD(double &x,double &y){scanf("%lf%lf",&x,&y);}
void RD(int &x,int &y,int &z){scanf("%d%d%d",&x,&y,&z);}
void RD(i64 &x,i64 &y,i64 &z){scanf("%I64d%I64d%I64d",&x,&y,&z);}
void RD(u32 &x,u32 &y,u32 &z){scanf("%u%u%u",&x,&y,&z);}
void RD(double &x,double &y,double &z){scanf("%lf%lf%lf",&x,&y,&z);}
void RD(char &x){x=getchar();}
void RD(char *s){scanf("%s",s);}
void RD(string &s){cin>>s;}

void PR(int x) {printf("%d\n",x);}
void PR(int x,int y) {printf("%d %d\n",x,y);}
void PR(i64 x) {printf("%I64d\n",x);}
void PR(u32 x) {printf("%u\n",x);}
void PR(u64 x) {printf("%I64u\n",x);}
void PR(double x) {printf("%.9lf\n",x);}
void PR(char x) {printf("%c\n",x);}
void PR(char *x) {printf("%s\n",x);}
void PR(string x) {cout<<x<<endl;}

void upMax(int &x,int y){if(x<y) x=y;}
void upMax(i64 &x,i64 y){if(x<y) x=y;}
void upMax(double &x,double y){if(x<y) x=y;}
void upMin(int &x,int y){if(x>y) x=y;}
void upMin(i64 &x,i64 y){if(x>y) x=y;}
void upMin(double &x,double y){if(x>y) x=y;}

int getInt()
{
    int x=0;
    char c=getchar();
    while(!isdigit(c)) c=getchar();
    while(isdigit(c)) x=x*10+c-48,c=getchar();
    return x;
}

const int mod=1000000007;
const i64 inf=((i64)1)<<60;
const double dinf=1e50;
const int INF=2000000005;
const int N=100105;

int C[N][105];

void init()
{
    int i,j;
    C[0][0]=1;
    for(i=1;i<N;i++)
    {
        C[i][0]=C[i][i]=1;
        for(j=1;j<min(i,105);j++) C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
    }
}

int a[N],f[105][N],n,m;

int main()
{
    init();
    RD(n,m);
    int i,j,k;
    FOR1(i,n) a[i]=getInt();
    while(m--)
    {
        int L,R,k;
        RD(L,R,k);
        (f[k+1][L]+=1)%=mod;
        for(i=1;i<=k+1;i++)
        {
            (f[i][R+1]-=C[R-L+k+1-i][k+1-i])%=mod;
        }
    }
    for(i=100;i>=0;i--)
    {
        k=0;
        for(j=1;j<=n;j++)
        {
            (k+=f[i+1][j])%=mod;
            (f[i][j]+=k)%=mod;
        }
    }
    for(i=1;i<=n;i++)
    {
        (f[0][i]+=a[i])%=mod;
        if(f[0][i]<0) f[0][i]+=mod;
        printf("%d",f[0][i]);
        if(i<n) putchar(' ');
    }
    puts("");

}


#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <map>

#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
#define abs(x) ((x)>=0?(x):-(x))
#define i64 long long
#define u32 unsigned int
#define u64 unsigned long long
#define clr(x,y) memset(x,y,sizeof(x))
#define CLR(x) x.clear()
#define ph(x) push(x)
#define pb(x) push_back(x)
#define Len(x) x.length()
#define SZ(x) x.size()
#define PI acos(-1.0)
#define sqr(x) ((x)*(x))
#define MP(x,y) make_pair(x,y)

#define FOR0(i,x) for(i=0;i<x;i++)
#define FOR1(i,x) for(i=1;i<=x;i++)
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define FORL0(i,a) for(i=a;i>=0;i--)
#define FORL1(i,a) for(i=a;i>=1;i--)
#define FORL(i,a,b)for(i=a;i>=b;i--)
#define EPS 1e-10

#define rush() int CC;for(scanf("%d",&CC);CC--;)
#define Rush(n)  while(scanf("%d",&n)!=-1)
using namespace std;

void RD(int &x){scanf("%d",&x);}
void RD(i64 &x){scanf("%I64d",&x);}
void RD(u64 &x){scanf("%I64u",&x);}
void RD(u32 &x){scanf("%u",&x);}
void RD(double &x){scanf("%lf",&x);}
void RD(int &x,int &y){scanf("%d%d",&x,&y);}
void RD(i64 &x,i64 &y){scanf("%I64d%I64d",&x,&y);}
void RD(u32 &x,u32 &y){scanf("%u%u",&x,&y);}
void RD(double &x,double &y){scanf("%lf%lf",&x,&y);}
void RD(int &x,int &y,int &z){scanf("%d%d%d",&x,&y,&z);}
void RD(i64 &x,i64 &y,i64 &z){scanf("%I64d%I64d%I64d",&x,&y,&z);}
void RD(u32 &x,u32 &y,u32 &z){scanf("%u%u%u",&x,&y,&z);}
void RD(double &x,double &y,double &z){scanf("%lf%lf%lf",&x,&y,&z);}
void RD(char &x){x=getchar();}
void RD(char *s){scanf("%s",s);}
void RD(string &s){cin>>s;}

void PR(int x) {printf("%d\n",x);}
void PR(int x,int y) {printf("%d %d\n",x,y);}
void PR(i64 x) {printf("%I64d\n",x);}
void PR(u32 x) {printf("%u\n",x);}
void PR(u64 x) {printf("%I64u\n",x);}
void PR(double x) {printf("%.9lf\n",x);}
void PR(char x) {printf("%c\n",x);}
void PR(char *x) {printf("%s\n",x);}
void PR(string x) {cout<<x<<endl;}

void upMax(int &x,int y){if(x<y) x=y;}
void upMax(i64 &x,i64 y){if(x<y) x=y;}
void upMax(double &x,double y){if(x<y) x=y;}
void upMin(int &x,int y){if(x>y) x=y;}
void upMin(i64 &x,i64 y){if(x>y) x=y;}
void upMin(double &x,double y){if(x>y) x=y;}

const int mod=1000000007;
const i64 inf=((i64)1)<<60;
const double dinf=1e50;
const int INF=2000000005;
const int N=100105;

int C[N][105];

void init()
{
    int i,j;
    C[0][0]=1;
    for(i=1;i<N;i++)
    {
        C[i][0]=C[i][i]=1;
        for(j=1;j<105;j++) C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
    }
}

int a[N],f[105][N],n,m;

int main()
{
    init();
    RD(n,m);
    int i,j,k;
    FOR1(i,n) RD(a[i]);
    while(m--)
    {
        int L,R,k;
        RD(L,R,k);
        (f[k+1][L]+=1)%=mod;
        for(i=1;i<=k+1;i++)
        {
            (f[i][R+1]-=C[R-L+k+1-i][k+1-i])%=mod;
        }
    }
    for(i=100;i>=0;i--)
    {
        k=0;
        for(j=1;j<=n;j++)
        {
            (k+=f[i+1][j])%=mod;
            (f[i][j]+=k)%=mod;
        }
    }
    for(i=1;i<=n;i++)
    {
        (f[0][i]+=a[i])%=mod;
        if(f[0][i]<0) f[0][i]+=mod;
        printf("%d",f[0][i]);
        if(i<n) putchar(' ');
    }
    puts("");

}


#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <map>

#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
#define abs(x) ((x)>=0?(x):-(x))
#define i64 long long
#define u32 unsigned int
#define u64 unsigned long long
#define clr(x,y) memset(x,y,sizeof(x))
#define CLR(x) x.clear()
#define ph(x) push(x)
#define pb(x) push_back(x)
#define Len(x) x.length()
#define SZ(x) x.size()
#define PI acos(-1.0)
#define sqr(x) ((x)*(x))
#define MP(x,y) make_pair(x,y)

#define FOR0(i,x) for(i=0;i<x;i++)
#define FOR1(i,x) for(i=1;i<=x;i++)
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define FORL0(i,a) for(i=a;i>=0;i--)
#define FORL1(i,a) for(i=a;i>=1;i--)
#define FORL(i,a,b)for(i=a;i>=b;i--)
#define EPS 1e-10

#define rush() int CC;for(scanf("%d",&CC);CC--;)
#define Rush(n)  while(scanf("%d",&n)!=-1)
using namespace std;

void RD(int &x){scanf("%d",&x);}
void RD(i64 &x){scanf("%I64d",&x);}
void RD(u64 &x){scanf("%I64u",&x);}
void RD(u32 &x){scanf("%u",&x);}
void RD(double &x){scanf("%lf",&x);}
void RD(int &x,int &y){scanf("%d%d",&x,&y);}
void RD(i64 &x,i64 &y){scanf("%I64d%I64d",&x,&y);}
void RD(u32 &x,u32 &y){scanf("%u%u",&x,&y);}
void RD(double &x,double &y){scanf("%lf%lf",&x,&y);}
void RD(int &x,int &y,int &z){scanf("%d%d%d",&x,&y,&z);}
void RD(i64 &x,i64 &y,i64 &z){scanf("%I64d%I64d%I64d",&x,&y,&z);}
void RD(u32 &x,u32 &y,u32 &z){scanf("%u%u%u",&x,&y,&z);}
void RD(double &x,double &y,double &z){scanf("%lf%lf%lf",&x,&y,&z);}
void RD(char &x){x=getchar();}
void RD(char *s){scanf("%s",s);}
void RD(string &s){cin>>s;}

void PR(int x) {printf("%d\n",x);}
void PR(int x,int y) {printf("%d %d\n",x,y);}
void PR(i64 x) {printf("%I64d\n",x);}
void PR(u32 x) {printf("%u\n",x);}
void PR(u64 x) {printf("%I64u\n",x);}
void PR(double x) {printf("%.9lf\n",x);}
void PR(char x) {printf("%c\n",x);}
void PR(char *x) {printf("%s\n",x);}
void PR(string x) {cout<<x<<endl;}

void upMax(int &x,int y){if(x<y) x=y;}
void upMax(i64 &x,i64 y){if(x<y) x=y;}
void upMax(double &x,double y){if(x<y) x=y;}
void upMin(int &x,int y){if(x>y) x=y;}
void upMin(i64 &x,i64 y){if(x>y) x=y;}
void upMin(double &x,double y){if(x>y) x=y;}

const int mod=1000000007;
const i64 inf=((i64)1)<<60;
const double dinf=1e50;
const int INF=2000000005;
const int N=100105;

int C[N][105];

void init()
{
    int i,j;
    C[0][0]=1;
    for(i=1;i<N;i++)
    {
        C[i][0]=C[i][i]=1;
        for(j=1;j<i;j++) C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
    }
}

int a[N],f[105][N],n,m;

int main()
{
    init();
    RD(n,m);
    int i,j,k;
    FOR1(i,n) RD(a[i]);
    while(m--)
    {
        int L,R,k;
        RD(L,R,k);
        (f[k+1][L]+=1)%=mod;
        for(i=1;i<=k+1;i++)
        {
            (f[i][R+1]-=C[R-L+k+1-i][k+1-i])%=mod;
        }
    }
    for(i=100;i>=0;i--)
    {
        k=0;
        for(j=1;j<=n;j++)
        {
            (k+=f[i+1][j])%=mod;
            (f[i][j]+=k)%=mod;
        }
    }
    for(i=1;i<=n;i++)
    {
        (f[0][i]+=a[i])%=mod;
        if(f[0][i]<0) f[0][i]+=mod;
        printf("%d",f[0][i]);
        if(i<n) putchar(' ');
    }
    puts("");

}


#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <map>

#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
#define abs(x) ((x)>=0?(x):-(x))
#define i64 long long
#define u32 unsigned int
#define u64 unsigned long long
#define clr(x,y) memset(x,y,sizeof(x))
#define CLR(x) x.clear()
#define ph(x) push(x)
#define pb(x) push_back(x)
#define Len(x) x.length()
#define SZ(x) x.size()
#define PI acos(-1.0)
#define sqr(x) ((x)*(x))
#define MP(x,y) make_pair(x,y)

#define FOR0(i,x) for(i=0;i<x;i++)
#define FOR1(i,x) for(i=1;i<=x;i++)
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define FORL0(i,a) for(i=a;i>=0;i--)
#define FORL1(i,a) for(i=a;i>=1;i--)
#define FORL(i,a,b)for(i=a;i>=b;i--)
#define EPS 1e-10

#define rush() int CC;for(scanf("%d",&CC);CC--;)
#define Rush(n)  while(scanf("%d",&n)!=-1)
using namespace std;

void RD(int &x){scanf("%d",&x);}
void RD(i64 &x){scanf("%I64d",&x);}
void RD(u64 &x){scanf("%I64u",&x);}
void RD(u32 &x){scanf("%u",&x);}
void RD(double &x){scanf("%lf",&x);}
void RD(int &x,int &y){scanf("%d%d",&x,&y);}
void RD(i64 &x,i64 &y){scanf("%I64d%I64d",&x,&y);}
void RD(u32 &x,u32 &y){scanf("%u%u",&x,&y);}
void RD(double &x,double &y){scanf("%lf%lf",&x,&y);}
void RD(int &x,int &y,int &z){scanf("%d%d%d",&x,&y,&z);}
void RD(i64 &x,i64 &y,i64 &z){scanf("%I64d%I64d%I64d",&x,&y,&z);}
void RD(u32 &x,u32 &y,u32 &z){scanf("%u%u%u",&x,&y,&z);}
void RD(double &x,double &y,double &z){scanf("%lf%lf%lf",&x,&y,&z);}
void RD(char &x){x=getchar();}
void RD(char *s){scanf("%s",s);}
void RD(string &s){cin>>s;}

void PR(int x) {printf("%d\n",x);}
void PR(int x,int y) {printf("%d %d\n",x,y);}
void PR(i64 x) {printf("%I64d\n",x);}
void PR(u32 x) {printf("%u\n",x);}
void PR(u64 x) {printf("%I64u\n",x);}
void PR(double x) {printf("%.9lf\n",x);}
void PR(char x) {printf("%c\n",x);}
void PR(char *x) {printf("%s\n",x);}
void PR(string x) {cout<<x<<endl;}

void upMax(int &x,int y){if(x<y) x=y;}
void upMax(i64 &x,i64 y){if(x<y) x=y;}
void upMax(double &x,double y){if(x<y) x=y;}
void upMin(int &x,int y){if(x>y) x=y;}
void upMin(i64 &x,i64 y){if(x>y) x=y;}
void upMin(double &x,double y){if(x>y) x=y;}

const int mod=1000000007;
const i64 inf=((i64)1)<<60;
const double dinf=1e50;
const int INF=2000000005;
const int N=100005;

int C[N][105];

void init()
{
    int i,j;
    C[0][0]=1;
    for(i=1;i<N;i++)
    {
        C[i][0]=C[i][i]=1;
        for(j=1;j<105;j++) C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
    }
}

int a[N],f[105][N],n,m;

int main()
{
    init();
    RD(n,m);
    int i,j,k;
    FOR1(i,n) RD(a[i]);
    while(m--)
    {
        int L,R,k;
        RD(L,R,k);
        (f[k+1][L]+=1)%=mod;
        for(i=1;i<=k+1;i++)
        {
            (f[i][R+1]-=C[R-L+k+1-i][k+1-i])%=mod;
        }
    }
    for(i=100;i>=0;i--)
    {
        k=0;
        for(j=1;j<=n;j++)
        {
            (k+=f[i+1][j])%=mod;
            (f[i][j]+=k)%=mod;
        }
    }
    for(i=1;i<=n;i++)
    {
        (f[0][i]+=a[i])%=mod;
        if(f[0][i]<0) f[0][i]+=mod;
        printf("%d",f[0][i]);
        if(i<n) putchar(' ');
    }
    puts("");

}


#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <map>

#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
#define abs(x) ((x)>=0?(x):-(x))
#define i64 long long
#define u32 unsigned int
#define u64 unsigned long long
#define clr(x,y) memset(x,y,sizeof(x))
#define CLR(x) x.clear()
#define ph(x) push(x)
#define pb(x) push_back(x)
#define Len(x) x.length()
#define SZ(x) x.size()
#define PI acos(-1.0)
#define sqr(x) ((x)*(x))
#define MP(x,y) make_pair(x,y)

#define FOR0(i,x) for(i=0;i<x;i++)
#define FOR1(i,x) for(i=1;i<=x;i++)
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define FORL0(i,a) for(i=a;i>=0;i--)
#define FORL1(i,a) for(i=a;i>=1;i--)
#define FORL(i,a,b)for(i=a;i>=b;i--)
#define EPS 1e-10

#define rush() int CC;for(scanf("%d",&CC);CC--;)
#define Rush(n)  while(scanf("%d",&n)!=-1)
using namespace std;

void RD(int &x){scanf("%d",&x);}
void RD(i64 &x){scanf("%I64d",&x);}
void RD(u64 &x){scanf("%I64u",&x);}
void RD(u32 &x){scanf("%u",&x);}
void RD(double &x){scanf("%lf",&x);}
void RD(int &x,int &y){scanf("%d%d",&x,&y);}
void RD(i64 &x,i64 &y){scanf("%I64d%I64d",&x,&y);}
void RD(u32 &x,u32 &y){scanf("%u%u",&x,&y);}
void RD(double &x,double &y){scanf("%lf%lf",&x,&y);}
void RD(int &x,int &y,int &z){scanf("%d%d%d",&x,&y,&z);}
void RD(i64 &x,i64 &y,i64 &z){scanf("%I64d%I64d%I64d",&x,&y,&z);}
void RD(u32 &x,u32 &y,u32 &z){scanf("%u%u%u",&x,&y,&z);}
void RD(double &x,double &y,double &z){scanf("%lf%lf%lf",&x,&y,&z);}
void RD(char &x){x=getchar();}
void RD(char *s){scanf("%s",s);}
void RD(string &s){cin>>s;}

void PR(int x) {printf("%d\n",x);}
void PR(int x,int y) {printf("%d %d\n",x,y);}
void PR(i64 x) {printf("%I64d\n",x);}
void PR(u32 x) {printf("%u\n",x);}
void PR(u64 x) {printf("%I64u\n",x);}
void PR(double x) {printf("%.9lf\n",x);}
void PR(char x) {printf("%c\n",x);}
void PR(char *x) {printf("%s\n",x);}
void PR(string x) {cout<<x<<endl;}

void upMax(int &x,int y){if(x<y) x=y;}
void upMax(i64 &x,i64 y){if(x<y) x=y;}
void upMax(double &x,double y){if(x<y) x=y;}
void upMin(int &x,int y){if(x>y) x=y;}
void upMin(i64 &x,i64 y){if(x>y) x=y;}
void upMin(double &x,double y){if(x>y) x=y;}

int getInt()
{
    int x=0;
    char c=getchar();
    while(!isdigit(c)) c=getchar();
    while(isdigit(c)) x=x*10+c-48,c=getchar();
    return x;
}

const int mod=1000000007;
const i64 inf=((i64)1)<<60;
const double dinf=1e50;
const int INF=2000000005;
const int N=100105;

int C[N][105];

void init()
{
    int i,j;
    C[0][0]=1;
    for(i=1;i<N;i++)
    {
        C[i][0]=1;
        for(j=1;j<=101;j++) C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
    }
}

int a[N],f[105][N],n,m;

int main()
{
    init();
    RD(n,m);
    int i,j,k;
    FOR1(i,n) a[i]=getInt();
    while(m--)
    {
        int L,R,k;
        RD(L,R,k);
        (f[k+1][L]+=1)%=mod;
        for(i=1;i<=k+1;i++)
        {
            (f[i][R+1]-=C[R-L+k+1-i][k+1-i])%=mod;
        }
    }
    for(i=100;i>=0;i--)
    {
        k=0;
        for(j=1;j<=n;j++)
        {
            (k+=f[i+1][j])%=mod;
            (f[i][j]+=k)%=mod;
        }
    }
    for(i=1;i<=n;i++)
    {
        (f[0][i]+=a[i])%=mod;
        if(f[0][i]<0) f[0][i]+=mod;
        printf("%d",f[0][i]);
        if(i<n) putchar(' ');
    }
    puts("");

}


#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

typedef long long ll;
const ll mod = 1000000007;
#define MOD(x) (((x) + mod) % mod)

void cumul(ll *A, int size)
{
	for(int i = 1; i < size; i++) A[i] = MOD(A[i] + A[i - 1]);
}

ll choose[100005][105];
void pre()
{
	memset(choose, 0, sizeof(choose));
	choose[0][0] = 1;
	for(int n = 1; n <= 100000; n++)
	{
		choose[n][0] = 1;
		for(int k = 1; k <= 100; k++) choose[n][k] = MOD(choose[n - 1][k - 1] + choose[n - 1][k]);
	}
}

int N, M;
ll S[100005];
int I[105][100005];
ll D[105][100005];

int main()
{
	pre();
	ios::sync_with_stdio(false);
	cin >> N >> M;
	for(int i = 1; i <= N; i++) cin >> S[i];
	for(int m = 0; m < M; m++)
	{
		int L, R, K;
		cin >> L >> R >> K;
		D[100 - K][L] = MOD(D[100 - K][L] + 1);
		for(int k = 0; k <= K; k++)
		{
			D[100 - K + k][R + 1] = MOD(D[100 - K + k][R + 1] - choose[R - L + K][k]);
		}
	}

	for(int k = 0; k <= 100; k++)
		for(int i = 1; i <= N; i++)
		{
			D[k][i] = MOD(D[k][i] + (k == 0 ? 0 : D[k - 1][i]) + (i == 1 ? 0 : D[k][i - 1]));
		}

	for(int i = 1; i <= N; i++) cout << MOD(S[i] + D[100][i]) << ' ';
}


#include <bits/stdc++.h>
#define F first
#define S second
#define endl '\n'

using namespace std;

class UnionFind{
private:
  vector<int> p, w, sz;
public:
  UnionFind(int n){
    w.resize(n + 1, 1);
    sz.resize(n + 1, 1);
    p.resize(n + 1);
    for (int i = 0; i <= n; i++)
      p[i] = i;
  }
  int find(int x){
    if (p[x] == x)
      return x;
    return p[x] = find(p[x]);
  }
  bool join(int x, int y){
    x = find(x);
    y = find(y);
    if (x == y)
      return false;
    if (w[x] > w[y])
      swap(x, y);
    p[x] = y;
    sz[y] += sz[x];
    if (w[x] == w[y])
      w[y]++;
    return true;
  }
  bool isSame(int x, int y){
    return find(x) == find(y);
  }
  int size(int x){
    return sz[find(x)];
  }
};
void charToBin(string &s, char &c){
  int x;
  if(c>='0' and c<='9')
    x = c-'0';
  else
    x = (c-'A') + 10;
  for(int i=3; i>=0; i--)
    s += ('0' + ((x>>i)&1));
}
typedef pair<int, int> pii;
vector<pii> splitSegments(string &s){
  int i = 0, n = s.size();
  vector<pii> ans;
  while(i < n){
    while(i<n and s[i]=='0')
      i++;
    if(i == n)
      break;
    int j = i;
    while(j<n and s[j]=='1')
      j++;
    ans.emplace_back(i, j-1);
    i = j;
  }
  return ans;
}
const int MAXM = (2<<14) + 10;

int dad[MAXM];
int last[MAXM];

int main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL);
  int n, m;
  cin >> n >> m;

  int ans = 0;
  UnionFind uf(m);
  string lastS(m, '0');
  for(int line=0; line<n; line++){
    string aux, s;
    cin >> aux;
    for(char c: aux)
      charToBin(s, c);

    vector<pii> segments = splitSegments(s);
    UnionFind newUF(m);
    for(int i=0; i<m; i++){
      dad[i] = -1;
      last[i] = -1;
    }

    for(int i=0; i<m; i++){
      if(s[i] == '1'){
        dad[i] = uf.find(i);
        ans += (lastS[i] == '0');
      }
    }

    for(int i=0; i<m; i++){
      if(dad[i] != -1){
        if(last[dad[i]] != -1)
          newUF.join(i, last[dad[i]]);
        last[dad[i]] = i;
      }
    }

    for(auto [l, r]: segments){
      for(int i=l; i<=r; i++)
        ans -= newUF.join(i, l);
    }
    uf = newUF;
    lastS = s;
  }

  cout << ans << endl;
  return 0;
}


#include <bits/stdc++.h>
#define F first
#define S second
#define endl '\n'

using namespace std;

class UnionFind{
private:
  vector<int> p, w, sz;
public:
  UnionFind(int n){
    w.resize(n + 1, 1);
    sz.resize(n + 1, 1);
    p.resize(n + 1);
    for (int i = 0; i <= n; i++)
      p[i] = i;
  }
  int find(int x){
    if (p[x] == x)
      return x;
    return p[x] = find(p[x]);
  }
  bool join(int x, int y){
    x = find(x);
    y = find(y);
    if (x == y)
      return false;
    if (w[x] > w[y])
      swap(x, y);
    p[x] = y;
    sz[y] += sz[x];
    if (w[x] == w[y])
      w[y]++;
    return true;
  }
  bool isSame(int x, int y){
    return find(x) == find(y);
  }
  int size(int x){
    return sz[find(x)];
  }
};
void charToBin(string &s, char &c){
  int x;
  if(c>='0' and c<='9')
    x = c-'0';
  else
    x = (c-'A') + 10;
  for(int i=3; i>=0; i--)
    s += ('0' + ((x>>i)&1));
}
typedef pair<int, int> pii;
vector<pii> splitSegments(string &s){
  int i = 0, n = s.size();
  vector<pii> ans;
  while(i < n){
    while(i<n and s[i]=='0')
      i++;
    if(i == n)
      break;
    int j = i;
    while(j<n and s[j]=='1')
      j++;
    ans.emplace_back(i, j-1);
    i = j;
  }
  return ans;
}

vector<int> mp[(2<<14) + 10];

int main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL);
  int n, m;
  cin >> n >> m;

  int ans = 0;
  UnionFind uf(m);
  string lastS(m, '0');
  for(int line=0; line<n; line++){
    string aux, s;
    cin >> aux;
    for(char c: aux)
      charToBin(s, c);

    vector<pii> segments = splitSegments(s);
    UnionFind newUF(m);
    for(int i=0; i<m; i++){
      mp[i].clear();
      mp[i].shrink_to_fit();
    }

    for(int i=0; i<m; i++){
      if(s[i] == '1'){
        mp[uf.find(i)].push_back(i);
        ans += (lastS[i] == '0');
      }
    }

    for(int i=0; i<m; i++){
      auto &vt = mp[i];
      for(int j=0; j<(int)vt.size(); j++)
        newUF.join(vt[j], vt[0]);
    }

    for(auto [l, r]: segments){
      for(int i=l; i<=r; i++)
        ans -= newUF.join(i, l);
    }
    uf = newUF;
    lastS = s;
  }

  cout << ans << endl;
  return 0;
}


#include <bits/stdc++.h>
#define F first
#define S second
#define endl '\n'

using namespace std;

class UnionFind{
private:
  vector<int> p, w, sz;
  vector<bool> used;
public:
  UnionFind(int n){
    w.resize(n + 1, 1);
    sz.resize(n + 1, 1);
    used.resize(n + 1, false);
    p.resize(n + 1);
    for (int i = 0; i <= n; i++)
      p[i] = i;
  }
  int find(int x){
    if (p[x] == x)
      return x;
    return p[x] = find(p[x]);
  }
  bool join(int x, int y){
    used[x] = true;
    used[y] = true;
    x = find(x);
    y = find(y);
    if (x == y)
      return false;
    if (w[x] > w[y])
      swap(x, y);
    p[x] = y;
    sz[y] += sz[x];
    if (w[x] == w[y])
      w[y]++;
    return true;
  }
  bool isSame(int x, int y){
    return find(x) == find(y);
  }
  bool isUsed(int x){
    return used[x];
  }
  int size(int x){
    return sz[find(x)];
  }
};
string charToBin(char c){
  int x;
  if(c>='0' and c<='9')
    x = c-'0';
  else
    x = (c-'A') + 10;
  string ret;
  for(int i=3; i>=0; i--)
    ret += ('0' + ((x>>i)&1));
  return ret;
}
typedef pair<int, int> pii;
vector<pii> splitSegments(string &s){
  int i = 0, n = s.size();
  vector<pii> ans;
  while(i < n){
    while(i<n and s[i]=='0')
      i++;
    if(i == n)
      break;
    int j = i;
    while(j<n and s[j]=='1')
      j++;
    ans.emplace_back(i, j-1);
    i = j;
  }
  return ans;
}
const int MAXN = (1<<12) + 10;
string v[MAXN];
int main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL);
  int n, m;
  cin >> n >> m;

  for(int i=0; i<n; i++){
    string s;
    cin >> s;
    for(char c: s)
      v[i] += charToBin(c);
  }
  UnionFind uf(m);
  int ans = 0;
  for(int line=0; line<n; line++){
    string s = v[line];
    vector<pii> segments = splitSegments(s);
    UnionFind newUF(m);
    for(auto [l, r]: segments){
      set<int> st;
      for(int i=l; i<=r; i++){
        if(uf.isUsed(i))
          st.insert(uf.find(i));
        newUF.join(i, l);
      }
      if(st.empty()){
        ans++;
      }else{
        ans -= (st.size()-1);
      }
    }
    map<int, vector<int>> mp;
    for(int i=0; i<m; i++){
      if(s[i] == '1')
        mp[uf.find(i)].push_back(i);
    }
    for(auto [_, vt] : mp){
      int sz = vt.size();
      for(int i=1; i<sz; i++)
        newUF.join(vt[i], vt[0]);
    }
    uf = newUF;
  }

  cout << ans << endl;
  return 0;
}


#include <bits/stdc++.h>
#define F first
#define S second
#define endl '\n'

using namespace std;

class UnionFind{
private:
  vector<int> p, w, sz;
public:
  void init(int n){
    w.assign(n + 1, 1);
    sz.assign(n + 1, 1);
    p.resize(n + 1);
    for (int i = 0; i <= n; i++)
      p[i] = i;
  }
  int find(int x){
    if (p[x] == x)
      return x;
    return p[x] = find(p[x]);
  }
  bool join(int x, int y){
    x = find(x);
    y = find(y);
    if (x == y)
      return false;
    if (w[x] > w[y])
      swap(x, y);
    p[x] = y;
    sz[y] += sz[x];
    if (w[x] == w[y])
      w[y]++;
    return true;
  }
  bool isSame(int x, int y){
    return find(x) == find(y);
  }
  int size(int x){
    return sz[find(x)];
  }
};
void charToBin(string &s, char &c){
  int x;
  if(c>='0' and c<='9')
    x = c-'0';
  else
    x = (c-'A') + 10;
  for(int i=3; i>=0; i--)
    s += ('0' + ((x>>i)&1));
}
typedef pair<int, int> pii;
void splitSegments(string &s, vector<pii> &ans){
  int i = 0, n = s.size();
  while(i < n){
    while(i<n and s[i]=='0')
      i++;
    if(i == n)
      break;
    int j = i;
    while(j<n and s[j]=='1')
      j++;
    ans.emplace_back(i, j-1);
    i = j;
  }
}
const int MAXM = (2<<14) + 10;

int dad[MAXM];
int last[MAXM];

int main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL);
  int n, m;
  cin >> n >> m;

  int ans = 0;
  UnionFind uf, newUF;
  uf.init(m);
  string lastS(m, '0');
  for(int line=0; line<n; line++){
    string aux, s;
    cin >> aux;
    for(char c: aux)
      charToBin(s, c);

    vector<pii> segments;
    splitSegments(s, segments);
    for(int i=0; i<m; i++){
      dad[i] = -1;
      last[i] = -1;
    }

    for(int i=0; i<m; i++){
      if(s[i] == '1'){
        dad[i] = uf.find(i);
        ans += (lastS[i] == '0');
      }
    }
    newUF.init(m);
    for(int i=0; i<m; i++){
      if(dad[i] != -1){
        if(last[dad[i]] != -1)
          newUF.join(i, last[dad[i]]);
        last[dad[i]] = i;
      }
    }

    for(auto [l, r]: segments){
      for(int i=l; i<=r; i++)
        ans -= newUF.join(i, l);
    }
    swap(uf, newUF);
    lastS = s;
  }

  cout << ans << endl;
  return 0;
}


#include <bits/stdc++.h>
#define F first
#define S second
#define endl '\n'

using namespace std;

class UnionFind{
private:
  vector<int> p, w, sz;
public:
  void init(int n){
    w.assign(n + 1, 1);
    sz.assign(n + 1, 1);
    p.resize(n + 1);
    for (int i = 0; i <= n; i++)
      p[i] = i;
  }
  int find(int x){
    if (p[x] == x)
      return x;
    return p[x] = find(p[x]);
  }
  bool join(int x, int y){
    x = find(x);
    y = find(y);
    if (x == y)
      return false;
    if (w[x] > w[y])
      swap(x, y);
    p[x] = y;
    sz[y] += sz[x];
    if (w[x] == w[y])
      w[y]++;
    return true;
  }
  bool isSame(int x, int y){
    return find(x) == find(y);
  }
  int size(int x){
    return sz[find(x)];
  }
};
void charToBin(string &s, char &c){
  int x;
  if(c>='0' and c<='9')
    x = c-'0';
  else
    x = (c-'A') + 10;
  for(int i=3; i>=0; i--)
    s += ('0' + ((x>>i)&1));
}
typedef pair<int, int> pii;
vector<pii> splitSegments(string &s){
  int i = 0, n = s.size();
  vector<pii> ans;
  while(i < n){
    while(i<n and s[i]=='0')
      i++;
    if(i == n)
      break;
    int j = i;
    while(j<n and s[j]=='1')
      j++;
    ans.emplace_back(i, j-1);
    i = j;
  }
  return ans;
}
const int MAXM = (2<<14) + 10;

int dad[MAXM];
int last[MAXM];

int main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL);
  int n, m;
  cin >> n >> m;

  int ans = 0;
  UnionFind uf, newUF;
  uf.init(m);
  string lastS(m, '0');
  for(int line=0; line<n; line++){
    string aux, s;
    cin >> aux;
    for(char c: aux)
      charToBin(s, c);

    vector<pii> segments = splitSegments(s);
    for(int i=0; i<m; i++){
      dad[i] = -1;
      last[i] = -1;
    }

    for(int i=0; i<m; i++){
      if(s[i] == '1'){
        dad[i] = uf.find(i);
        ans += (lastS[i] == '0');
      }
    }
    newUF.init(m);
    for(int i=0; i<m; i++){
      if(dad[i] != -1){
        if(last[dad[i]] != -1)
          newUF.join(i, last[dad[i]]);
        last[dad[i]] = i;
      }
    }

    for(auto [l, r]: segments){
      for(int i=l; i<=r; i++)
        ans -= newUF.join(i, l);
    }
    swap(uf, newUF);
    lastS = s;
  }

  cout << ans << endl;
  return 0;
}


#include <bits/stdc++.h>
#define F first
#define S second
#define endl '\n'

using namespace std;

class UnionFind{
private:
  vector<int> p, w, sz;
public:
  void init(int n){
    w.assign(n + 1, 1);
    sz.assign(n + 1, 1);
    p.resize(n + 1);
    for (int i = 0; i <= n; i++)
      p[i] = i;
  }
  int find(int x){
    if (p[x] == x)
      return x;
    return p[x] = find(p[x]);
  }
  bool join(int x, int y){
    x = find(x);
    y = find(y);
    if (x == y)
      return false;
    if (w[x] > w[y])
      swap(x, y);
    p[x] = y;
    sz[y] += sz[x];
    if (w[x] == w[y])
      w[y]++;
    return true;
  }
  bool isSame(int x, int y){
    return find(x) == find(y);
  }
  int size(int x){
    return sz[find(x)];
  }
};
void charToBin(string &s, char &c){
  int x;
  if(c>='0' and c<='9')
    x = c-'0';
  else
    x = (c-'A') + 10;
  for(int i=3; i>=0; i--)
    s += ('0' + ((x>>i)&1));
}
typedef pair<int, int> pii;
void splitSegments(string &s, vector<pii> &ans){
  int i = 0, n = s.size();
  while(i < n){
    while(i<n and s[i]=='0')
      i++;
    if(i == n)
      break;
    int j = i;
    while(j<n and s[j]=='1')
      j++;
    ans.emplace_back(i, j-1);
    i = j;
  }
}
const int MAXM = (2<<14) + 10;

int dad[MAXM];
int last[MAXM];

int main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL);
  int n, m;
  cin >> n >> m;

  int ans = 0;
  UnionFind uf, newUF;
  uf.init(m);
  string lastS(m, '0');
  for(int line=0; line<n; line++){
    string aux, s;
    cin >> aux;
    for(char c: aux)
      charToBin(s, c);

    vector<pii> segments;
    splitSegments(s, segments);
    for(int i=0; i<m; i++){
      dad[i] = -1;
      last[i] = -1;
    }

    for(int i=0; i<m; i++){
      if(s[i] == '1'){
        dad[i] = uf.find(i);
        ans += (lastS[i] == '0');
      }
    }
    newUF.init(m);
    for(int i=0; i<m; i++){
      if(dad[i] != -1){
        if(last[dad[i]] != -1)
          newUF.join(i, last[dad[i]]);
        last[dad[i]] = i;
      }
    }

    for(auto &[l, r]: segments){
      for(int i=l; i<=r; i++)
        ans -= newUF.join(i, l);
    }
    swap(uf, newUF);
    lastS = s;
  }

  cout << ans << endl;
  return 0;
}