#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define All(a) a.begin(), a.end()
#define us unordered_set
#define eb emplace_back
#define pb push_back
#define pf push_front
#define ll long long
#define vt vector
#define mod 1000000007

#include <bits/stdc++.h>

using namespace std;

int main() {
    int n;
    cin >> n;
    vt<vt<double>> m(n, vt<double>(2));
    rep(i, n) {
        int t;
        cin >> t >> m[i][0] >> m[i][1];
        if (t == 2) m[i][1] -= 0.1;
        if (t == 3) m[i][0] += 0.1;
        if (t == 4) {
            m[i][0] += 0.1;
            m[i][1] -= 0.1;
        }
    }
    int ans = 0;
    for (int i = 0; i < n - 1; i++) {
        for (int j = i + 1; j < n; j++) {
            if (m[i][0] <= m[j][0] && m[i][1] >= m[j][0])
                ans++;
            else if (m[i][0] >= m[j][0] && m[i][0] <= m[j][1])
                ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>
//#include <atcoder/all>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
template <class T>
inline bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;
//using namespace atcoder;

template<int mod>
struct Modint{
    int x;
    Modint():x(0){}
    Modint(int64_t y):x((y%mod+mod)%mod){}

    Modint &operator+=(const Modint &p){
			if((x+=p.x)>=mod)
				x -= mod;
			return *this;
		}

		Modint &operator-=(const Modint &p){
			if((x+=mod-p.x)>=mod)
				x -= mod;
			return *this;
		}

		Modint &operator*=(const Modint &p){
			x = (1LL * x * p.x) % mod;
			return *this;
		}

		Modint &operator/=(const Modint &p){
			*this *= p.inverse();
			return *this;
		}

		Modint operator-() const { return Modint(-x); }
		Modint operator+(const Modint &p) const{
			return Modint(*this) += p;
		}
		Modint operator-(const Modint &p) const{
			return Modint(*this) -= p;
		}
		Modint operator*(const Modint &p) const{
			return Modint(*this) *= p;
		}
		Modint operator/(const Modint &p) const{
			return Modint(*this) /= p;
		}

		bool operator==(const Modint &p) const { return x == p.x; }
		bool operator!=(const Modint &p) const{return x != p.x;}

		Modint inverse() const{//非再帰拡張ユークリッド
			int a = x, b = mod, u = 1, v = 0;
			while(b>0){
				int t = a / b;
				swap(a -= t * b, b);
				swap(u -= t * v, v);
			}
			return Modint(u);
		}

		Modint pow(int64_t n) const{//繰り返し二乗法
			Modint ret(1), mul(x);
			while(n>0){
				if(n&1)
					ret *= mul;
				mul *= mul;
				n >>= 1;
			}
			return ret;
		}

		friend ostream &operator<<(ostream &os,const Modint &p){
			return os << p.x;
		}
};

using modint = Modint<mod>;

void solve(){
	ll h,w;
	cin>>h>>w;
	ll sum=0;
	vector<string>s(h);
	rep(i,h)cin>>s[i];
	rep(i,h){
		rep(j,w){
			if(s[i][j]=='.')++sum;
		}
	}
	vector<vector<ll>>l(h,vector<ll>(w)),r(h,vector<ll>(w)),u(h,vector<ll>(w)),d(h,vector<ll>(w));
	rep(i,h){
		ll val=0;
		rep(j,w){
			if(s[i][j]!='#')r[i][j]=val,val++;
			else val=0;
		}
		val=0;
		for(int j=w-1;j>=0;--j){
			if(s[i][j]!='#')l[i][j]=val,val++;
			else val=0;
		}
	}
	rep(i,w){
		ll val=0;
		rep(j,h){
			if(s[j][i]!='#')u[j][i]=val,val++;
			else val=0;
		}
		val=0;
		for(int j=h-1;j>=0;--j){
			if(s[j][i]!='#')d[j][i]=val,val++;
			else val=0;
		}
	}
	modint ans=0;
	rep(i,h){
		rep(j,w){
			if(s[i][j]=='#')continue;
			ll cnt=l[i][j]+r[i][j]+u[i][j]+d[i][j]+1;
			modint x=2;
			x=x.pow(cnt);
			x-=1;
			modint y=2;
			y=y.pow(sum-cnt);
			ans+=x*y;
		}
	}
	cout<<ans;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}
