#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
using namespace std;

typedef long long ll;

struct Node{
	int idx, cnt;
	Node *nxt[26], *fail;
};

int nidx = 2, L;
Node nodes[400002];
ll st[200001], ed[200001];

void add(char *s, Node *cur, int si, int di){
	for(int i = 0, val; s[i]; i++, si += di){
		val = s[i] - 'a';
		if(!(cur->nxt[val])){

			cur->nxt[val] = &nodes[nidx++];
		}
		cur = cur->nxt[val];
	}
	cur->cnt++;
}

void set_fail(Node *head){
	head->fail = head;
	queue<Node*> q;
	q.push(head);
	while(!q.empty()){
		Node *cur = q.front(); q.pop();
		for(int i = 0; i < 26; i++){
			Node *nxt = cur->nxt[i], *fail = cur->fail;
			if(!nxt) continue;
			while(fail != head && fail->nxt[i] == NULL)
				fail = fail->fail;
			if(cur != head && fail->nxt[i])
				nxt->fail = fail->nxt[i];
			else nxt->fail = head;
			nxt->cnt += nxt->fail->cnt;
			q.push(nxt);
		}
	}
}

char t[200001], str[200001];

int main()
{
	int N; scanf("%s %d", t, &N);
	L = strlen(t);
	for(int i = 0; i < N; i++){
		scanf("%s", str);
		add(str, &nodes[0], 0, 1);
		int len = strlen(str);
		for(int j = (len - 1) / 2; j >= 0; j--)
			swap(str[j], str[len - j - 1]);
		add(str, &nodes[1], len - 1, -1);
	}

	set_fail(&nodes[0]);
	set_fail(&nodes[1]);

	Node *cur = &nodes[0];
	for(int i = 0; i < L; i++){
		int nval = t[i] - 'a';
		while(cur != &nodes[0] && cur->nxt[nval] == NULL)
			cur = cur->fail;
		if(cur->nxt[nval]) cur = cur->nxt[nval];
		ed[i] += cur->cnt;
	}

	cur = &nodes[1];
	for(int i = L - 1; i >= 0; i--){
		int nval = t[i] - 'a';
		while(cur != &nodes[1] && cur->nxt[nval] == NULL)
			cur = cur->fail;
		if(cur->nxt[nval]) cur = cur->nxt[nval];
		st[i] += cur->cnt;
	}

	ll ans = 0;
	for(int i = 1; i < L; i++)
		ans += ed[i - 1] * st[i];
	printf("%I64d\n", ans);

	return 0;
}


/*
	Name: Harshit Jain
	Institution: IIIT Vadodara
*/
#include <bits/stdc++.h>
#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
const double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define pb push_back
#define mp make_pair
#define ll long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ull unsigned long long
#define rep(i,a,b) for(ll i = a; i < b; ++i)
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeofa((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define p(a) cout << a << "\n";
#define p1(a) cout << a << " ";

#define PI 3.141592653589793
#define MOD (ll)(1e9 + 7)
#define m(a) ((a)%MOD)

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> ii;
//=======================
int up[1010][1010], down[1010][1010], l[1010][1010], r[1010][1010];
int n,m;
char arr[1010][1010];

struct node
{
	int x, y, range;
};
vector<node> vec;

bool check()
{
	int hor[1010][1010], ver[1010][1010];
	memset(hor, 0, sizeof(hor));
	memset(ver, 0, sizeof(ver));
	rep(i,0,vec.size())
	{
		// trace3(vec[i].x, vec[i].y, vec[i].range)
		if(vec[i].y-1-vec[i].range >= 0)
		{
			hor[vec[i].x-1][vec[i].y-1-vec[i].range] += 1;
			hor[vec[i].x-1][vec[i].y+vec[i].range] -= 1;
		}
		if(vec[i].x-1-vec[i].range >= 0)
		{
			ver[vec[i].x-1-vec[i].range][vec[i].y-1] += 1;
			ver[vec[i].x+vec[i].range][vec[i].y-1] -= 1;
		}
	}
	rep(i,0,n)
	{
		rep(j,1,m)
		{
			hor[i][j] += hor[i][j-1];
		}
	}
	rep(i,0,m)
	{
		rep(j,1,n)
		{
			ver[j][i] += ver[j-1][i];
		}
	}
	rep(i,0,n)
	{
		rep(j,0,m)
		{
			if(arr[i][j] == '*' && !(hor[i][j] || ver[i][j]))
			{
				// trace2(i, j)
				p("-1")
				return true;
			}
		}
	}
	return false;
}

void solve()
{
	cin >> n >> m;
	rep(i,0,n)
	{
		rep(j,0,m)
		{
			cin >> arr[i][j];
		}
	}
	rep(i,0,n)
	{
		rep(j,0,m)
		{
			if(arr[i][j] == '.')
			{
				up[i][j] = 0;
				l[i][j] = 0;
			}
			else
			{
				(i > 0)?(up[i][j] = up[i-1][j] + 1):(up[i][j] = i+1);
				(j > 0)?(l[i][j] = l[i][j-1] + 1):(l[i][j] = j+1);
			}
		}
	}
	for(int i = n-1; i >= 0; --i)
	{
		for(int j = m-1; j >= 0; --j)
		{
			if(arr[i][j] == '.')
			{
				down[i][j] = 0;
				r[i][j] = 0;
			}
			else
			{
				(i+1 < n)?(down[i][j] = down[i+1][j] + 1):(down[i][j] = i+1);
				(j+1 < m)?(r[i][j] = r[i][j+1] + 1):(r[i][j] = j+1);
			}
		}
	}
	rep(i,0,n)
	{
		rep(j,0,m)
		{
			if(arr[i][j] == '*')
			{
				ll t = min(abs(up[i][j]), min(abs(down[i][j]), min(abs(l[i][j]), abs(r[i][j])))) - 1;
				if(t > 0)
				{
					// trace4(up[i][j], down[i][j], l[i][j], r[i][j])
					node temp;
					temp.x = i+1;
					temp.y = j+1;
					// if(t > 1e5)
					// {
					// 	t = 1;
					// }
					temp.range = t;
					vec.pb(temp);
				}
			}
		}
	}
	if(!check())
	{
		p(vec.size())
		rep(i,0,vec.size())
		{
			cout << vec[i].x << " " << vec[i].y << " " << vec[i].range << "\n";
		}
	}
}

//=======================
int main()
{
	bool testing = false;
	IOS
	if(testing)
	{
		freopen("test.txt","rt",stdin);
		int start = clock();
		solve();
		int end = clock();
		cout << "time: " << (end - start)/(double)(CLOCKS_PER_SEC)*1000 << " milliseconds\n";
	}
	else
	{
		solve();
	}
}


#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define ll long long
#define ld long double

#define mp make_pair
#define fi first
#define se second
#define mod 1000000007LL

//typedefs
#define pii pair<int,int>
#define piii pair<pii,int>

#define pll pair<ll,ll>
#define Vpii vector<pii>
#define Vpll vector<pll>
#define Vll vector<ll>
#define Vi vector<int>
#define Vc vector<char>
#define Mii map<int,int>
#define Si  set<int>
#define Sl set<ll>
//functions
#define all(c) c.begin(),c.end()
#define fill(c,val) memset(c,val,sizeof(c))
//#define for(i,j,n)    for(ll i=j;i<n;i++)

//misc
#define bitcount __builtin_popcount
#define next_string next_permutation

int star[1009][1009];
int fin[1009][1009];
int val[1009][1009][4];

int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

int t=1;
//cin>>t;

while(t--){

vector<int> vec,vec1,vec2;

int n,m;
cin>>n>>m;

string s[n];

for(int i=0;i<n;i++)
{
    cin>>s[i];

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

            if(s[i][j]=='*')
                star[i][j]=1;

            if(((i==0 || j==0 ) || (i==n-1 || j==m-1))&& s[i][j]=='*')
            {
                star[i][j]=1;
                for(int k=0;k<4;k++)
                    val[i][j][k]=1;

            }

    }
}

for(int i=1;i<=n-2;i++){
    for(int j=1;j<=m-2;j++){

     if(s[i][j]=='*'){

        val[i][j][0] = val[i][j-1][0]+1;
        val[i][j][1] = val[i-1][j][1]+1;

     }

    }
}

for(int i=n-2;i>=1;i--){
    for(int j=m-2;j>=1;j--){

            if(s[i][j]=='*'){

        val[i][j][2] = val[i][j+1][2]+1;
        val[i][j][3] = val[i+1][j][3]+1;

     }

    }
}

for(int i=1;i<=n-2;i++){
    for(int j=1;j<=m-2;j++){

    int len=10008;

    for(int k=0;k<4;k++)
     len = min(len,val[i][j][k]);

     len--;

    if(len>0){
        vec.pb(i+1);
        vec1.pb(j+1);
        vec2.pb(len);

//cout<<i<<" "<<j<<endl;

        for(int k=0;k<=len;k++){
            star[i][j+k]=0;
            star[i][j-k]=0;
            star[i+k][j]=0;
            star[i-k][j]=0;
        }

    }

    }
}

for(int i=0;i<n;i++)
{
    for(int j=0;j<m;j++)
        if(star[i][j]==1)
    {
        cout<<-1;
        return 0;
    }
}

int sz  = vec.size();
cout<<sz<<endl;

for(int i=0;i<sz;i++)
{
    printf("%I64d %I64d %I64d\n",vec[i],vec1[i],vec2[i]);
//cout<<vec[i]<<" "<<vec1[i]<<" "<<vec2[i]<<endl;
}

}
}


#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define ll long long
#define ld long double

#define mp make_pair
#define fi first
#define se second
#define mod 1000000007LL

//typedefs
#define pii pair<int,int>
#define piii pair<pii,int>

#define pll pair<ll,ll>
#define Vpii vector<pii>
#define Vpll vector<pll>
#define Vll vector<ll>
#define Vi vector<int>
#define Vc vector<char>
#define Mii map<int,int>
#define Si  set<int>
#define Sl set<ll>
//functions
#define all(c) c.begin(),c.end()
#define fill(c,val) memset(c,val,sizeof(c))
//#define for(i,j,n)    for(ll i=j;i<n;i++)

//misc
#define bitcount __builtin_popcount
#define next_string next_permutation

int star[1009][1009];
int fin[1009][1009];
int val[1009][1009][4];

int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

int t=1;
//cin>>t;

while(t--){

vector<int> vec,vec1,vec2;

int n,m;
cin>>n>>m;

string s[n];

for(int i=0;i<n;i++)
{
    cin>>s[i];

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

            if(s[i][j]=='*')
                star[i][j]=1;

            if(((i==0 || j==0 ) || (i==n-1 || j==m-1))&& s[i][j]=='*')
            {
                star[i][j]=1;
                for(int k=0;k<4;k++)
                    val[i][j][k]=1;

            }

    }
}

for(int i=1;i<=n-2;i++){
    for(int j=1;j<=m-2;j++){

     if(s[i][j]=='*'){

        val[i][j][0] = val[i][j-1][0]+1;
        val[i][j][1] = val[i-1][j][1]+1;

     }

    }
}

for(int i=n-2;i>=1;i--){
    for(int j=m-2;j>=1;j--){

            if(s[i][j]=='*'){

        val[i][j][2] = val[i][j+1][2]+1;
        val[i][j][3] = val[i+1][j][3]+1;

     }

    }
}

for(int i=1;i<=n-2;i++){
    for(int j=1;j<=m-2;j++){

    if(s[i][j]=='*'){
        int a[4];

        fill(a,0);

for(int k=0;k<4;k++)
a[k]=val[i][j][k]-1;

sort(a,a+4);

    if(a[0]>0){
        vec.pb(i+1);
        vec1.pb(j+1);
        vec2.pb(a[0]);

        star[i][j]=0;

//cout<<i<<" "<<j<<endl;

        int len = a[0];

         for(int k=i+1;k<=i+len;k++)
            star[k][j]=0;

                 for(int k=i-1;k>=i-len;k--)
            star[k][j]=0;
             for(int k=j+1;k<=j+len;k++)
            star[i][k]=0;
             for(int k=j-1;k>=j-len;k--)
            star[i][k]=0;

    }

    }

    }
}

for(int i=0;i<n;i++)
{
    for(int j=0;j<m;j++)
        if(star[i][j]==1)
    {
        cout<<-1;
        return 0;
    }
}

int sz  = vec.size();
cout<<sz<<endl;

for(int i=0;i<sz;i++)
{
cout<<vec[i]<<" "<<vec1[i]<<" "<<vec2[i]<<endl;
}

}
}


#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define ll long long
#define ld long double

#define mp make_pair
#define fi first
#define se second
#define mod 1000000007LL

//typedefs
#define pii pair<int,int>
#define piii pair<pii,int>

#define pll pair<ll,ll>
#define Vpii vector<pii>
#define Vpll vector<pll>
#define Vll vector<ll>
#define Vi vector<int>
#define Vc vector<char>
#define Mii map<int,int>
#define Si  set<int>
#define Sl set<ll>
//functions
#define all(c) c.begin(),c.end()
#define fill(c,val) memset(c,val,sizeof(c))
//#define for(i,j,n)    for(ll i=j;i<n;i++)

//misc
#define bitcount __builtin_popcount
#define next_string next_permutation

int star[1009][1009];
int fin[1009][1009];
int val[1009][1009][4];

int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

int t=1;
//cin>>t;

while(t--){

vector<int> vec,vec1,vec2;

int n,m;
cin>>n>>m;

string s[n];

for(int i=0;i<n;i++)
{
    cin>>s[i];

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

            if(s[i][j]=='*')
                star[i][j]=1;

            if(((i==0 || j==0 ) || (i==n-1 || j==m-1))&& s[i][j]=='*')
            {
                star[i][j]=1;
                for(int k=0;k<4;k++)
                    val[i][j][k]=1;

            }

    }
}

for(int i=1;i<=n-2;i++){
    for(int j=1;j<=m-2;j++){

     if(s[i][j]=='*'){

        val[i][j][0] = val[i][j-1][0]+1;
        val[i][j][1] = val[i-1][j][1]+1;

     }

    }
}

for(int i=n-2;i>=1;i--){
    for(int j=m-2;j>=1;j--){

            if(s[i][j]=='*'){

        val[i][j][2] = val[i][j+1][2]+1;
        val[i][j][3] = val[i+1][j][3]+1;

     }

    }
}

for(int i=1;i<=n-2;i++){
    for(int j=1;j<=m-2;j++){

    if(s[i][j]=='*'){
        int a[4];

        fill(a,0);

for(int k=0;k<4;k++)
a[k]=val[i][j][k]-1;

sort(a,a+4);

    if(a[0]>0){
        vec.pb(i+1);
        vec1.pb(j+1);
        vec2.pb(a[0]);

        star[i][j]=0;

//cout<<i<<" "<<j<<endl;

        int len = a[0];

        for(int k=0;k<=len;k++){
            star[i][j+k]=0;
            star[i][j-k]=0;
            star[i+k][j]=0;
            star[i-k][j]=0;
        }

    }

    }

    }
}

for(int i=0;i<n;i++)
{
    for(int j=0;j<m;j++)
        if(star[i][j]==1)
    {
        cout<<-1;
        return 0;
    }
}

int sz  = vec.size();
cout<<sz<<endl;

for(int i=0;i<sz;i++)
{
cout<<vec[i]<<" "<<vec1[i]<<" "<<vec2[i]<<endl;
}

}
}


#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define ll long long
#define ld long double

#define mp make_pair
#define fi first
#define se second
#define mod 1000000007LL

//typedefs
#define pii pair<int,int>
#define piii pair<pii,int>

#define pll pair<ll,ll>
#define Vpii vector<pii>
#define Vpll vector<pll>
#define Vll vector<ll>
#define Vi vector<int>
#define Vc vector<char>
#define Mii map<int,int>
#define Si  set<int>
#define Sl set<ll>
//functions
#define all(c) c.begin(),c.end()
#define fill(c,val) memset(c,val,sizeof(c))
//#define for(i,j,n)    for(ll i=j;i<n;i++)

//misc
#define bitcount __builtin_popcount
#define next_string next_permutation

int star[1009][1009];
int fin[1009][1009];
int val[1009][1009][4];

int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

int t=1;
//cin>>t;

while(t--){

vector<int> vec,vec1,vec2;

int n,m;
cin>>n>>m;

string s[n];

for(int i=0;i<n;i++)
{
    cin>>s[i];

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

            if(s[i][j]=='*')
                star[i][j]=1;

            if(((i==0 || j==0 ) || (i==n-1 || j==m-1))&& s[i][j]=='*')
            {
                star[i][j]=1;
                for(int k=0;k<4;k++)
                    val[i][j][k]=1;

            }

    }
}

for(int i=1;i<=n-2;i++){
    for(int j=1;j<=m-2;j++){

     if(s[i][j]=='*'){

        val[i][j][0] = val[i][j-1][0]+1;
        val[i][j][1] = val[i-1][j][1]+1;

     }

    }
}

for(int i=n-2;i>=1;i--){
    for(int j=m-2;j>=1;j--){

            if(s[i][j]=='*'){

        val[i][j][2] = val[i][j+1][2]+1;
        val[i][j][3] = val[i+1][j][3]+1;

     }

    }
}

for(int i=1;i<=n-2;i++){
    for(int j=1;j<=m-2;j++){

    int len=10008;

    for(int k=0;k<4;k++)
     len = min(len,val[i][j][k]);

     len--;

    if(len>0){
        vec.pb(i+1);
        vec1.pb(j+1);
        vec2.pb(len);

//cout<<i<<" "<<j<<endl;

        for(int k=0;k<=len;k++){
            star[i][j+k]=0;
            star[i][j-k]=0;
            star[i+k][j]=0;
            star[i-k][j]=0;
        }

    }

    }
}

for(int i=0;i<n;i++)
{
    for(int j=0;j<m;j++)
        if(star[i][j]==1)
    {
        cout<<-1;
        return 0;
    }
}

int sz  = vec.size();
cout<<sz<<endl;

for(int i=0;i<sz;i++)
{
cout<<vec[i]<<" "<<vec1[i]<<" "<<vec2[i]<<endl;
}

}
}


#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define ll long long
#define ld long double

#define mp make_pair
#define fi first
#define se second
#define mod 1000000007LL

//typedefs
#define pii pair<int,int>
#define piii pair<pii,int>

#define pll pair<ll,ll>
#define Vpii vector<pii>
#define Vpll vector<pll>
#define Vll vector<ll>
#define Vi vector<int>
#define Vc vector<char>
#define Mii map<int,int>
#define Si  set<int>
#define Sl set<ll>
//functions
#define all(c) c.begin(),c.end()
#define fill(c,val) memset(c,val,sizeof(c))
//#define for(i,j,n)    for(ll i=j;i<n;i++)

//misc
#define bitcount __builtin_popcount
#define next_string next_permutation

int star[109][109];
int fin[109][109];
int val[109][109][4];

int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

int t=1;
//cin>>t;

while(t--){

vector<int> vec,vec1,vec2;

int n,m;
cin>>n>>m;

string s[n];

for(int i=0;i<n;i++)
{
    cin>>s[i];

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

            if(s[i][j]=='*')
                star[i][j]=1;

            if(((i==0 || j==0 ) || (i==n-1 || j==m-1))&& s[i][j]=='*')
            {
                star[i][j]=1;
                for(int k=0;k<4;k++)
                    val[i][j][k]=1;

            }

    }
}

for(int i=1;i<=n-2;i++){
    for(int j=1;j<=m-2;j++){

     if(s[i][j]=='*'){

        val[i][j][0] = val[i][j-1][0]+1;
        val[i][j][1] = val[i-1][j][1]+1;

     }

    }
}

for(int i=n-2;i>=1;i--){
    for(int j=m-2;j>=1;j--){

            if(s[i][j]=='*'){

        val[i][j][2] = val[i][j+1][2]+1;
        val[i][j][3] = val[i+1][j][3]+1;

     }

    }
}

for(int i=1;i<=n-2;i++){
    for(int j=1;j<=m-2;j++){

    if(s[i][j]=='*'){
        int a[4];

        fill(a,0);

for(int k=0;k<4;k++)
a[k]=val[i][j][k]-1;

sort(a,a+4);

    if(a[0]>0){
        vec.pb(i+1);
        vec1.pb(j+1);
        vec2.pb(a[0]);

        star[i][j]=0;

//cout<<i<<" "<<j<<endl;

        int len = a[0];

        for(int k=0;k<=len;k++){
            star[i][j+k]=0;
            star[i][j-k]=0;
            star[i+k][j]=0;
            star[i-k][j]=0;
        }

    }

    }

    }
}

for(int i=0;i<n;i++)
{
    for(int j=0;j<m;j++)
        if(star[i][j]==1)
    {
        cout<<-1;
        return 0;
    }
}

int sz  = vec.size();
cout<<sz<<endl;

for(int i=0;i<sz;i++)
{
cout<<vec[i]<<" "<<vec1[i]<<" "<<vec2[i]<<endl;
}

}
}


#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define ll long long
#define ld long double

#define mp make_pair
#define fi first
#define se second
#define mod 1000000007LL

//typedefs
#define pii pair<int,int>
#define piii pair<pii,int>

#define pll pair<ll,ll>
#define Vpii vector<pii>
#define Vpll vector<pll>
#define Vll vector<ll>
#define Vi vector<int>
#define Vc vector<char>
#define Mii map<int,int>
#define Si  set<int>
#define Sl set<ll>
//functions
#define all(c) c.begin(),c.end()
#define fill(c,val) memset(c,val,sizeof(c))
//#define for(i,j,n)    for(ll i=j;i<n;i++)

//misc
#define bitcount __builtin_popcount
#define next_string next_permutation

int star[1009][1009];
int fin[1009][1009];
int val[1009][1009][4];

int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

int t=1;
//cin>>t;

while(t--){

vector<int> vec,vec1,vec2;

int n,m;
cin>>n>>m;

string s[n];

for(int i=0;i<n;i++)
{
    cin>>s[i];

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

            if(s[i][j]=='*')
                star[i][j]=1;

            if(((i==0 || j==0 ) || (i==n-1 || j==m-1))&& s[i][j]=='*')
            {
                star[i][j]=1;
                for(int k=0;k<4;k++)
                    val[i][j][k]=1;

            }

    }
}

for(int i=1;i<=n-2;i++){
    for(int j=1;j<=m-2;j++){

     if(s[i][j]=='*'){

        val[i][j][0] = val[i][j-1][0]+1;
        val[i][j][1] = val[i-1][j][1]+1;

     }

    }
}

for(int i=n-2;i>=1;i--){
    for(int j=m-2;j>=1;j--){

            if(s[i][j]=='*'){

        val[i][j][2] = val[i][j+1][2]+1;
        val[i][j][3] = val[i+1][j][3]+1;

     }

    }
}

for(int i=1;i<=n-2;i++){
    for(int j=1;j<=m-2;j++){

    int len=10008;

    for(int k=0;k<4;k++)
     len = min(len,val[i][j][k]);

     len--;

    if(len>0){
        vec.pb(i+1);
        vec1.pb(j+1);
        vec2.pb(len);

//cout<<i<<" "<<j<<endl;

        for(int k=0;k<=len;k++){
            star[i][j+k]=0;
            star[i][j-k]=0;
            star[i+k][j]=0;
            star[i-k][j]=0;
        }

    }

    }
}

for(int i=0;i<n;i++)
{
    for(int j=0;j<m;j++)
        if(star[i][j]==1)
    {
        cout<<-1;
        return 0;
    }
}

int sz  = vec.size();
cout<<sz<<endl;

for(int i=0;i<sz;i++)
{
    printf("%I64d %I64d %I64d\n",vec[i],vec1[i+1],vec2[i+2]);
//cout<<vec[i]<<" "<<vec1[i]<<" "<<vec2[i]<<endl;
}

}
}


#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define ll long long
#define ld long double

#define mp make_pair
#define fi first
#define se second
#define mod 1000000007LL

//typedefs
#define pii pair<int,int>
#define piii pair<pii,int>

#define pll pair<ll,ll>
#define Vpii vector<pii>
#define Vpll vector<pll>
#define Vll vector<ll>
#define Vi vector<int>
#define Vc vector<char>
#define Mii map<int,int>
#define Si  set<int>
#define Sl set<ll>
//functions
#define all(c) c.begin(),c.end()
#define fill(c,val) memset(c,val,sizeof(c))
//#define for(i,j,n)    for(ll i=j;i<n;i++)

//misc
#define bitcount __builtin_popcount
#define next_string next_permutation

int star[1009][1009];
int fin[1009][1009];
int fin1[1009][1009];

int val[1009][1009][4];

int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

int t=1;
//cin>>t;

while(t--){

vector<int> vec,vec1,vec2;

int n,m;
cin>>n>>m;

string s[n];

for(int i=0;i<n;i++)
{
    cin>>s[i];

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

            if(s[i][j]=='*')
            {
                star[i][j]=1;

            }

            if(((i==0 || j==0 ) || (i==n-1 || j==m-1))&& s[i][j]=='*')
            {
                star[i][j]=1;
                for(int k=0;k<4;k++)
                    val[i][j][k]=1;

            }

    }
}

for(int i=1;i<=n-2;i++){
    for(int j=1;j<=m-2;j++){

     if(s[i][j]=='*'){

        val[i][j][0] = val[i][j-1][0]+1;
        val[i][j][1] = val[i-1][j][1]+1;

     }

    }
}

for(int i=n-2;i>=1;i--){
    for(int j=m-2;j>=1;j--){

            if(s[i][j]=='*'){

        val[i][j][2] = val[i][j+1][2]+1;
        val[i][j][3] = val[i+1][j][3]+1;

     }

    }
}

for(int i=1;i<=n-2;i++){
    for(int j=1;j<=m-2;j++){

    if(s[i][j]=='*'){
        int a[4];

        fill(a,0);

for(int k=0;k<4;k++)
a[k]=val[i][j][k]-1;

sort(a,a+4);
//cout<<i<<" "<<j<<" "<<a[0]<<endl;

    if(a[0]>0){
        vec.pb(i+1);
        vec1.pb(j+1);
        vec2.pb(a[0]);

        int len = a[0];

        fin[i-len][j]+=1;
        fin1[i][j-len]+=1;

        if(j+len+1 < m)
        fin1[i][j+len+1]-=1;
        if((i+len+1) <n)
        fin[i+len+1][j]-=1;

    }

    }

    }
}

for(int i=0;i<n;i++)
{
    for(int j=1;j<m;j++)
        fin1[i][j]+=fin1[i][j-1];

}

for(int j=0;j<m;j++)
{
    for(int i=1;i<n;i++)
        {fin[i][j]+=fin[i-1][j];}

}

/*for(int i=0;i<n;i++)
{
    for(int j=0;j<m;j++)
cout<<fin[i][j]<<" ";
cout<<endl;

}
*/

for(int i=0;i<n;i++)
{
    for(int j=0;j<m;j++)
        if(s[i][j]=='*' && (fin[i][j]==0 && fin1[i][j]==0) )
    {
        cout<<-1;
        return 0;
    }
}

int sz  = vec.size();
cout<<sz<<endl;

for(int i=0;i<sz;i++)
{
cout<<vec[i]<<" "<<vec1[i]<<" "<<vec2[i]<<endl;
}

}
}


#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define ll long long
#define ld long double

#define mp make_pair
#define fi first
#define se second
#define mod 1000000007LL

//typedefs
#define pii pair<int,int>
#define piii pair<pii,int>

#define pll pair<ll,ll>
#define Vpii vector<pii>
#define Vpll vector<pll>
#define Vll vector<ll>
#define Vi vector<int>
#define Vc vector<char>
#define Mii map<int,int>
#define Si  set<int>
#define Sl set<ll>
//functions
#define all(c) c.begin(),c.end()
#define fill(c,val) memset(c,val,sizeof(c))
//#define for(i,j,n)    for(ll i=j;i<n;i++)

//misc
#define bitcount __builtin_popcount
#define next_string next_permutation

int star[1009][1009];
int fin[1009][1009];
int val[1009][1009][4];

int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

int t=1;
//cin>>t;

while(t--){

vector<int> vec,vec1,vec2;

int n,m;
cin>>n>>m;

string s[n];

for(int i=0;i<n;i++)
{
    cin>>s[i];

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

            if(s[i][j]=='*')
                star[i][j]=1;

            if(((i==0 || j==0 ) || (i==n-1 || j==m-1))&& s[i][j]=='*')
            {
                star[i][j]=1;
                for(int k=0;k<4;k++)
                    val[i][j][k]=1;

            }

    }
}

for(int i=1;i<=n-2;i++){
    for(int j=1;j<=m-2;j++){

     if(s[i][j]=='*'){

        val[i][j][0] = val[i][j-1][0]+1;
        val[i][j][1] = val[i-1][j][1]+1;

     }

    }
}

for(int i=n-2;i>=1;i--){
    for(int j=m-2;j>=1;j--){

            if(s[i][j]=='*'){

        val[i][j][2] = val[i][j+1][2]+1;
        val[i][j][3] = val[i+1][j][3]+1;

     }

    }
}

for(int i=1;i<=n-2;i++){
    for(int j=1;j<=m-2;j++){

    int len=10008;

    for(int k=0;k<4;k++)
     len = min(len,val[i][j][k]);

     len--;

    if(len>0){
        vec.pb(i+1);
        vec1.pb(j+1);
        vec2.pb(len);

//cout<<i<<" "<<j<<endl;

        for(int k=0;k<=len;k++){
            star[i][j+k]=0;
            star[i][j-k]=0;
            star[i+k][j]=0;
            star[i-k][j]=0;
        }

    }

    }
}

for(int i=0;i<n;i++)
{
    for(int j=0;j<m;j++)
        if(star[i][j]==1)
    {
        cout<<-1;
        return 0;
    }
}

int sz  = vec.size();
cout<<sz<<endl;

for(int i=0;i<sz;i++)
{
    printf("%d %d %d\n",vec[i],vec1[i],vec2[i]);
//cout<<vec[i]<<" "<vec1[i]<<" "<<vec2[i]<<endl;
}

}
}


#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define ll long long
#define ld long double

#define mp make_pair
#define fi first
#define se second
#define mod 1000000007LL

//typedefs
#define pii pair<int,int>
#define piii pair<pii,int>

#define pll pair<ll,ll>
#define Vpii vector<pii>
#define Vpll vector<pll>
#define Vll vector<ll>
#define Vi vector<int>
#define Vc vector<char>
#define Mii map<int,int>
#define Si  set<int>
#define Sl set<ll>
//functions
#define all(c) c.begin(),c.end()
#define fill(c,val) memset(c,val,sizeof(c))
//#define for(i,j,n)    for(ll i=j;i<n;i++)

//misc
#define bitcount __builtin_popcount
#define next_string next_permutation

int star[1009][1009];
int fin[1009][1009];
int val[1009][1009][4];

int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

int t=1;
//cin>>t;

while(t--){

vector<int> vec,vec1,vec2;

int n,m;
cin>>n>>m;

string s[n];

for(int i=0;i<n;i++)
{
    cin>>s[i];

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

            if(s[i][j]=='*')
            {
                star[i][j]=1;
                fin[i][j]=1;
            }

            if(((i==0 || j==0 ) || (i==n-1 || j==m-1))&& s[i][j]=='*')
            {
                star[i][j]=1;
                for(int k=0;k<4;k++)
                    val[i][j][k]=1;

            }

    }
}

for(int i=1;i<=n-2;i++){
    for(int j=1;j<=m-2;j++){

     if(s[i][j]=='*'){

        val[i][j][0] = val[i][j-1][0]+1;
        val[i][j][1] = val[i-1][j][1]+1;

     }

    }
}

for(int i=n-2;i>=1;i--){
    for(int j=m-2;j>=1;j--){

            if(s[i][j]=='*'){

        val[i][j][2] = val[i][j+1][2]+1;
        val[i][j][3] = val[i+1][j][3]+1;

     }

    }
}

for(int i=1;i<=n-2;i++){
    for(int j=1;j<=m-2;j++){

    if(s[i][j]=='*'){
        int a[4];

        fill(a,0);

for(int k=0;k<4;k++)
a[k]=val[i][j][k]-1;

sort(a,a+4);

    if(a[0]>0){
        vec.pb(i+1);
        vec1.pb(j+1);
        vec2.pb(a[0]);

        star[i][j]=0;

//cout<<i<<" "<<j<<endl;

        int len = a[0];

        fin[i-len][j]-=1;
        fin[i][j-len]-=1;

        if(j+len+1 < m)
        fin[i][j+len+1]+=1;
        if(i+len+1 <n)
        fin[i+len+1][j]+=1;

    }

    }

    }
}

for(int i=0;i<n;i++)
{
    for(int j=1;j<m;j++)
        fin[i][j]+=fin[i][j-1];

}

for(int j=0;j<m;j++)
{
    for(int i=1;i<n;i++)
        fin[i][j]+=fin[i-1][j];

}

for(int i=0;i<n;i++)
{
    for(int j=0;j<m;j++)
        if(s[i][j]=='*' && fin[i][j]==0)
    {
        cout<<-1;
        return 0;
    }
}

int sz  = vec.size();
cout<<sz<<endl;

for(int i=0;i<sz;i++)
{
cout<<vec[i]<<" "<<vec1[i]<<" "<<vec2[i]<<endl;
}

}
}


#include<iostream>
#include<string.h>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
using namespace std;
const int maxn=1234;
char plat[maxn][maxn];
bool sign[maxn][maxn];
struct Data{
	int row,col,val;
}data[1234567];
vector<Data>ans;
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
    	for(int j=1;j<=m;j++)
    	{
    		cin>>plat[i][j];
		}
	}
    for(int i=1;i<=n;i++)
    {
    	for(int j=1;j<=m;j++)
    	{
    		if(plat[i][j]=='*')
    		{
    			if(sign[i][j])continue;
    			int len=0;
    			for(int p=1;;p++)
    			{
    				if(plat[i+p][j]=='*'&&plat[i][j+p]=='*'&&plat[i-p][j]=='*'&&plat[i][j-p]=='*')len++;
    				else break;
				}
				if(len)
				{
					sign[i][j]=1;
					for(int p=1;p<=len;p++)
					{
						sign[i+p][j]=1;sign[i][j+p]=1;sign[i-p][j]=1;sign[i][j-p]=1;
					}
					Data a;
					a.row=i;a.col=j;a.val=len;
					ans.push_back(a);
				}
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(plat[i][j]=='*')
			{
				if(!sign[i][j])
				{
					cout<<"-1";
					return 0;
				}
			}
		}
	}
	cout<<ans.size()<<endl;
	for(Data i:ans)
	{
		cout<<i.row<<" "<<i.col<<" "<<i.val<<endl;
	}
	return 0;
}


#include<iostream>
#include<string.h>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
using namespace std;
const int maxn=1234;
char plat[maxn][maxn];
bool sign[maxn][maxn];
struct Data{
	int row,col,val;
}data[1234567];
vector<Data>ans;
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
    	for(int j=1;j<=m;j++)
    	{
    		scanf("%c",&plat[i][j]);
		}
	}
    for(int i=1;i<=n;i++)
    {
    	for(int j=1;j<=m;j++)
    	{
    		if(plat[i][j]=='*')
    		{
    			int len=0;
    			for(int p=1;;p++)
    			{
    				if(plat[i+p][j]=='*'&&plat[i][j+p]=='*'&&plat[i-p][j]=='*'&&plat[i][j-p]=='*')len++;
    				else break;
				}
				if(len)
				{
					sign[i][j]=1;
					for(int p=1;p<=len;p++)
					{
						sign[i+p][j]=1;sign[i][j+p]=1;sign[i-p][j]=1;sign[i][j-p]=1;
					}
					Data a;
					a.row=i;a.col=j;a.val=len;
					ans.push_back(a);
				}
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(plat[i][j]=='*')
			{
				if(!sign[i][j])
				{
					cout<<"-1";
					return 0;
				}
			}
		}
	}
	cout<<ans.size()<<endl;
	for(Data i:ans)
	{
		printf("%d%d%d\n",i.row,i.col,i.val);
	}
	return 0;
}


#include<iostream>
#include<string.h>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
using namespace std;
const int maxn=1234;
char plat[maxn][maxn];
bool sign[maxn][maxn];
struct Data{
	int row,col,val;
}data[1234567];
vector<Data>ans;
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
    	for(int j=1;j<=m;j++)
    	{
    		cin>>plat[i][j];
		}
	}
    for(int i=1;i<=n;i++)
    {
    	for(int j=1;j<=m;j++)
    	{
    		if(plat[i][j]=='*')
    		{
    			int len=0;
    			for(int p=1;;p++)
    			{
    				if(plat[i+p][j]=='*'&&plat[i][j+p]=='*'&&plat[i-p][j]=='*'&&plat[i][j-p]=='*')len++;
    				else break;
				}
				if(len)
				{
					sign[i][j]=1;
					for(int p=1;p<=len;p++)
					{
						sign[i+p][j]=1;sign[i][j+p]=1;sign[i-p][j]=1;sign[i][j-p]=1;
					}
					Data a;
					a.row=i;a.col=j;a.val=len;
					ans.push_back(a);
				}
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(plat[i][j]=='*')
			{
				if(!sign[i][j])
				{
					cout<<"-1";
					return 0;
				}
			}
		}
	}
	cout<<ans.size()<<endl;
	for(Data i:ans)
	{
		printf("%d %d %d\n",i.row,i.col,i.val);
	}
	return 0;
}


#include<iostream>
#include<string.h>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
#include<stdio.h>
using namespace std;
const int maxn=1234;
char plat[maxn][maxn];
bool sign[maxn][maxn];
struct Data{
	int row,col,val;
}data[1234567];
vector<Data>ans;
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
    	for(int j=1;j<=m;j++)
    	{
    		scanf("%d%d",&plat[i][j]);
		}
	}
    for(int i=1;i<=n;i++)
    {
    	for(int j=1;j<=m;j++)
    	{
    		if(plat[i][j]=='*')
    		{
    			int len=0;
    			for(int p=1;;p++)
    			{
    				if(plat[i+p][j]=='*'&&plat[i][j+p]=='*'&&plat[i-p][j]=='*'&&plat[i][j-p]=='*')len++;
    				else break;
				}
				if(len)
				{
					sign[i][j]=1;
					for(int p=1;p<=len;p++)
					{
						sign[i+p][j]=1;sign[i][j+p]=1;sign[i-p][j]=1;sign[i][j-p]=1;
					}
					Data a;
					a.row=i;a.col=j;a.val=len;
					ans.push_back(a);
				}
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(plat[i][j]=='*')
			{
				if(!sign[i][j])
				{
					cout<<"-1";
					return 0;
				}
			}
		}
	}
	cout<<ans.size()<<endl;
	for(Data i:ans)
	{
		printf("%lld%lld%lld\n",i.row,i.col,i.val);
	}
	return 0;
}


#include<iostream>
#include<string.h>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
using namespace std;
const int maxn=1234;
char plat[maxn][maxn];
bool sign[maxn][maxn];
struct Data{
	int row,col,val;
}data[1234567];
vector<Data>ans;
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
    	for(int j=1;j<=m;j++)
    	{
    		cin>>plat[i][j];
		}
	}
    for(int i=1;i<=n;i++)
    {
    	for(int j=1;j<=m;j++)
    	{
    		if(plat[i][j]=='*')
    		{
    			int len=0;
    			for(int p=1;;p++)
    			{
    				if(plat[i+p][j]=='*'&&plat[i][j+p]=='*'&&plat[i-p][j]=='*'&&plat[i][j-p]=='*')len++;
    				else break;
				}
				if(len)
				{
					sign[i][j]=1;
					for(int p=1;p<=len;p++)
					{
						sign[i+p][j]=1;sign[i][j+p]=1;sign[i-p][j]=1;sign[i][j-p]=1;
					}
					Data a;
					a.row=i;a.col=j;a.val=len;
					ans.push_back(a);
				}
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(plat[i][j]=='*')
			{
				if(!sign[i][j])
				{
					cout<<"-1";
					return 0;
				}
			}
		}
	}
	cout<<ans.size()<<endl;
	for(Data i:ans)
	{
		cout<<i.row<<" "<<i.col<<" "<<i.val<<endl;
	}
	return 0;
}


#include<iostream>
#include<string.h>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
#include<stdio.h>
using namespace std;
const int maxn=1234;
char plat[maxn][maxn];
bool sign[maxn][maxn];
struct Data{
	int row,col,val;
}data[1234567];
vector<Data>ans;
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
    	for(int j=1;j<=m;j++)
    	{
    		scanf("%d%d",&plat[i][j]);
		}
	}
    for(int i=1;i<=n;i++)
    {
    	for(int j=1;j<=m;j++)
    	{
    		if(plat[i][j]=='*')
    		{
    			int len=0;
    			for(int p=1;;p++)
    			{
    				if(plat[i+p][j]=='*'&&plat[i][j+p]=='*'&&plat[i-p][j]=='*'&&plat[i][j-p]=='*')len++;
    				else break;
				}
				if(len)
				{
					sign[i][j]=1;
					for(int p=1;p<=len;p++)
					{
						sign[i+p][j]=1;sign[i][j+p]=1;sign[i-p][j]=1;sign[i][j-p]=1;
					}
					Data a;
					a.row=i;a.col=j;a.val=len;
					ans.push_back(a);
				}
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(plat[i][j]=='*')
			{
				if(!sign[i][j])
				{
					cout<<"-1";
					return 0;
				}
			}
		}
	}
	cout<<ans.size()<<endl;
	for(Data i:ans)
	{
		printf("%lld%lld%lld\n",i.cow,i.col,i.val);
	}
	return 0;
}


#include<iostream>
#include<string.h>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
#include<stdio.h>
using namespace std;
const int maxn=1234;
char plat[maxn][maxn];
bool sign[maxn][maxn];
struct Data{
	int row,col,val;
}data[1234567];
vector<Data>ans;
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
    	for(int j=1;j<=m;j++)
    	{
    		cin>>plat[i][j];
		}
	}
	for(int i=1;i<=n;i++)
    {
    	for(int j=1;j<=m;j++)
    	{
    		printf("%c",plat[i][j]);
		}
		printf("\n");
	}
    for(int i=1;i<=n;i++)
    {
    	for(int j=1;j<=m;j++)
    	{
    		if(plat[i][j]=='*')
    		{
    			int len=0;
    			for(int p=1;;p++)
    			{
    				if(plat[i+p][j]=='*'&&plat[i][j+p]=='*'&&plat[i-p][j]=='*'&&plat[i][j-p]=='*')len++;
    				else break;
				}
				if(len)
				{
					sign[i][j]=1;
					for(int p=1;p<=len;p++)
					{
						sign[i+p][j]=1;sign[i][j+p]=1;sign[i-p][j]=1;sign[i][j-p]=1;
					}
					Data a;
					a.row=i;a.col=j;a.val=len;
					ans.push_back(a);
				}
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(plat[i][j]=='*')
			{
				if(!sign[i][j])
				{
					cout<<"-1";
					return 0;
				}
			}
		}
	}
	cout<<ans.size()<<endl;
	for(Data i:ans)
	{
		printf("%d%d%d\n",i.row,i.col,i.val);
	}
	return 0;
}


#include<iostream>
#include<string.h>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
using namespace std;
const int maxn=1234;
char plat[maxn][maxn];
bool sign[maxn][maxn];
struct Data{
	int row,col,val;
}data[1234567];
vector<Data>ans;
int main()
{
	ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
    	for(int j=1;j<=m;j++)
    	{
    		cin>>plat[i][j];
		}
	}
    for(int i=1;i<=n;i++)
    {
    	for(int j=1;j<=m;j++)
    	{
    		if(plat[i][j]=='*')
    		{
    			int len=0;
    			for(int p=1;;p++)
    			{
    				if(plat[i+p][j]=='*'&&plat[i][j+p]=='*'&&plat[i-p][j]=='*'&&plat[i][j-p]=='*')len++;
    				else break;
				}
				if(len)
				{
					sign[i][j]=1;
					for(int p=1;p<=len;p++)
					{
						sign[i+p][j]=1;sign[i][j+p]=1;sign[i-p][j]=1;sign[i][j-p]=1;
					}
					Data a;
					a.row=i;a.col=j;a.val=len;
					ans.push_back(a);
				}
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(plat[i][j]=='*')
			{
				if(!sign[i][j])
				{
					cout<<"-1";
					return 0;
				}
			}
		}
	}
	cout<<ans.size()<<endl;
	for(Data i:ans)
	{
		cout<<i.row<<" "<<i.col<<" "<<i.val<<endl;
	}
	return 0;
}


#include<iostream>
#include<string.h>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
#include<stdio.h>
using namespace std;
const int maxn=1234;
char plat[maxn][maxn];
bool sign[maxn][maxn];
struct Data{
	int row,col,val;
}data[1234567];
vector<Data>ans;
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
    	for(int j=1;j<=m;j++)
    	{
    		cin>>plat[i][j];
		}
	}
    for(int i=1;i<=n;i++)
    {
    	for(int j=1;j<=m;j++)
    	{
    		if(plat[i][j]=='*')
    		{
    			int len=0;
    			for(int p=1;;p++)
    			{
    				if(plat[i+p][j]=='*'&&plat[i][j+p]=='*'&&plat[i-p][j]=='*'&&plat[i][j-p]=='*')len++;
    				else break;
				}
				if(len)
				{
					sign[i][j]=1;
					for(int p=1;p<=len;p++)
					{
						sign[i+p][j]=1;sign[i][j+p]=1;sign[i-p][j]=1;sign[i][j-p]=1;
					}
					Data a;
					a.row=i;a.col=j;a.val=len;
					ans.push_back(a);
				}
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(plat[i][j]=='*')
			{
				if(!sign[i][j])
				{
					cout<<"-1";
					return 0;
				}
			}
		}
	}
	cout<<ans.size()<<endl;
	for(Data i:ans)
	{
		printf("%d %d %d\n",i.row,i.col,i.val);
	}
	return 0;
}


#include<iostream>
#include<string.h>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
using namespace std;
const int maxn=1234;
char plat[maxn][maxn];
bool sign[maxn][maxn];
struct Data{
	int row,col,val;
}data[1234567];
vector<Data>ans;
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
    	for(int j=1;j<=m;j++)
    	{
    		cin>>plat[i][j];
		}
	}
    for(int i=1;i<=n;i++)
    {
    	for(int j=1;j<=m;j++)
    	{
    		if(plat[i][j]=='*')
    		{
    			int len=0;
    			for(int p=1;;p++)
    			{
    				if(plat[i+p][j]=='*'&&plat[i][j+p]=='*'&&plat[i-p][j]=='*'&&plat[i][j-p]=='*')len++;
    				else break;
				}
				if(len)
				{
					sign[i][j]=1;
					for(int p=1;p<=len;p++)
					{
						sign[i+p][j]=1;sign[i][j+p]=1;sign[i-p][j]=1;sign[i][j-p]=1;
					}
					Data a;
					a.row=i;a.col=j;a.val=len;
					ans.push_back(a);
				}
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(plat[i][j]=='*')
			{
				if(!sign[i][j])
				{
					cout<<"-1";
					return 0;
				}
			}
		}
	}
	cout<<ans.size()<<endl;
	for(Data i:ans)
	{
		printf("%d%d%d",i.row,i.col,i.val);
	}
	return 0;
}


#include<iostream>
#include<string.h>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
using namespace std;
const int maxn=1234;
char plat[maxn][maxn];
bool sign[maxn][maxn];
struct Data{
	int row,col,val;
}data[1234567];
vector<Data>ans;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
    	for(int j=1;j<=m;j++)
    	{
    		cin>>plat[i][j];
		}
	}
    for(int i=1;i<=n;i++)
    {
    	for(int j=1;j<=m;j++)
    	{
    		if(plat[i][j]=='*')
    		{
    			int len=0;
    			for(int p=1;;p++)
    			{
    				if(plat[i+p][j]=='*'&&plat[i][j+p]=='*'&&plat[i-p][j]=='*'&&plat[i][j-p]=='*')len++;
    				else break;
				}
				if(len)
				{
					sign[i][j]=1;
					for(int p=1;p<=len;p++)
					{
						sign[i+p][j]=1;sign[i][j+p]=1;sign[i-p][j]=1;sign[i][j-p]=1;
					}
					Data a;
					a.row=i;a.col=j;a.val=len;
					ans.push_back(a);
				}
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(plat[i][j]=='*')
			{
				if(!sign[i][j])
				{
					cout<<"-1";
					return 0;
				}
			}
		}
	}
	cout<<ans.size()<<endl;
	for(Data i:ans)
	{
		cout<<i.row<<" "<<i.col<<" "<<i.val<<endl;
	}
	return 0;
}


//I’ve fallen in love many times…
// but always with you.
#include <bits/stdc++.h>
using namespace std;
#define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi       acos(-1)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
//#define int long long ////////////
#define MOD 1000000007    ////////
#define POD 998244353 ////////
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define maxc(v) max_element(all(v))
#define minc(v) min_element(all(v))
#define fr first
#define sc second
#define ppb pop_back
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) (m*n)/GCD(m,n)
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define initarr(a,n,x) for (int i=0;i<n;++i) a[i]=x
#define rep(i,a,n)  for(int i=a ; i<n ; i++)
#define repe(i,a,n) for(int i=a;i<=n;i++)
#define rev(i,a,b) for(int i=a;i>=b;i--)
//define ll long long
//#define ld long double

#define pii std::pair<int, int>
#define pll std::pair<ll, ll>
#define mii map<int,int>
#define mci map<char,int>
#define msi map<string,int>
#define vi vector<int>
#define vvi vector<vi >
#define vii vector<pii >

#define itv for(auto it= v.begin(); it != v.end(); ++it )

#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(ALL(container),element) != container.end())
//#define invect(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.pb(tmp);commands}
//#define inset(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.insert(tmp);commands}
//#define trav(a, x) for(auto& a : x)
//#define display(x) trav(a,x) cout<<a<<" ";cout<<endl

#define bs binary_search
#define  lb(v,val) = lower_bound(ALL(v), val);

#define dbg1(a) cout<<" *"<<a<<" ";
#define dbg2(a,b) cout<<" *"<<a<<" **"<<b<<" "     /////
#define dbg cout<<"hi"
#define nl endl
#define sz(s)         (int)((s).size())
#define coutsp(k)   cout<<setprecision(k)  //set precision (total length k icluding decimal and non decimal)
#define coutfsp(k)   cout<<fixed<<setprecision(k)  //fixed set precision(after decimal fixing)
#define  INF   (int)2e18

void quickly_quickly_kro()
{
int n,m; cin>>n>>m;

int a[n][m];

map<pii,int> M;

rep(i,0,n)
{
  rep(j,0,m)
  {
    char c; cin>>c;
    if(c=='.')
    a[i][j]=0;
    else
      a[i][j]=1;
  }
}

int co=0,d=MOD;

rep(i,1,n-1)
{
  rep(j,1,m-1)
  {

   if(a[i][j]==1)
   {
     d=MOD;
     co=0;
     rep(k,j+1,m)
     {

     if(a[i][k]==1)
     co++;
   else
    break;
     }
     d=min(d,co);
     co=0;

      rev(k,j-1,0)
     {
     if(a[i][k]==1)
     co++;
   else
    break;
     }
     d=min(d,co);

     co=0;
     rep(k,i+1,n)
     {
     if(a[k][j]==1)
     co++;
   else
    break;
     }
     d=min(d,co);

     co=0;
     rev(k,i-1,0)
     {
     if(a[k][j]==1)
     co++;
   else
    break;
     }
     d=min(d,co);

     ////
     if(d>0)
     M[{i+1,j+1}]=d;

   }

  }
}

for(auto l:M)
{
  auto d=l.first;
  auto e=l.second;
  auto i=d.first-1;
  auto j=d.second-1;

 if(e>0)
     {
      a[i][j]=0;
     }

     repe(k,j+1,j+e)
     {
     a[i][k]=0;
     }

     rev(k,j-1,j-e)
     {
     a[i][k]=0;
     }

         repe(k,i+1,i+e)
     {
     a[k][j]=0;
     }

     rev(k,i-1,i-e)
     {
     a[k][j]=0;
     }

}

co=0;
rep(i,0,n)
{

  rep(j,0,m)
  {
  //  cout<<a[i][j];
  if(a[i][j]==0)
    co++;
}
//cout<<nl;
}

if(co!=n*m)
cout<<-1;
else
{
cout<<M.size()<<"\n";

for(auto l:M)
{
  auto d=l.first;
  auto e=l.second;
  auto i=d.first;
  auto j=d.second;

    cout<<i<<" "<<j<<" "<<e<<"\n";

}

}

}

signed main()
{

   FAST
  // SieveOfEratosthenes(1001);
   int t;
   t=1;
      //   cin>>t;

    while(t--)
    {

      quickly_quickly_kro();
      cout<<nl;

}

  return 0;
}


//I’ve fallen in love many times…
// but always with you.
#include <bits/stdc++.h>
using namespace std;
#define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi       acos(-1)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define int long long ////////////
#define MOD 1000000007    ////////
#define POD 998244353 ////////
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define maxc(v) max_element(all(v))
#define minc(v) min_element(all(v))
#define fr first
#define sc second
#define ppb pop_back
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) (m*n)/GCD(m,n)
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define initarr(a,n,x) for (int i=0;i<n;++i) a[i]=x
#define rep(i,a,n)  for(int i=a ; i<n ; i++)
#define repe(i,a,n) for(int i=a;i<=n;i++)
#define rev(i,a,b) for(int i=a;i>=b;i--)
//define ll long long
//#define ld long double

#define pii std::pair<int, int>
#define pll std::pair<ll, ll>
#define mii map<int,int>
#define mci map<char,int>
#define msi map<string,int>
#define vi vector<int>
#define vvi vector<vi >
#define vii vector<pii >

#define itv for(auto it= v.begin(); it != v.end(); ++it )

#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(ALL(container),element) != container.end())
//#define invect(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.pb(tmp);commands}
//#define inset(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.insert(tmp);commands}
//#define trav(a, x) for(auto& a : x)
//#define display(x) trav(a,x) cout<<a<<" ";cout<<endl

#define bs binary_search
#define  lb(v,val) = lower_bound(ALL(v), val);

#define dbg1(a) cout<<" *"<<a<<" ";
#define dbg2(a,b) cout<<" *"<<a<<" **"<<b<<" "     /////
#define dbg cout<<"hi"
#define nl endl
#define sz(s)         (int)((s).size())
#define coutsp(k)   cout<<setprecision(k)  //set precision (total length k icluding decimal and non decimal)
#define coutfsp(k)   cout<<fixed<<setprecision(k)  //fixed set precision(after decimal fixing)
#define  INF   (int)2e18

int fast_pow(int base, int n,int M)
{
    if(n==0)
       return 1;
    if(n==1)
    return base;
    int halfn=fast_pow(base,n/2,M);
    if(n%2==0)
        return ( halfn * halfn ) % M;
    else
        return ( ( ( halfn * halfn ) % M ) * base ) % M;
}

void psu(vector<int> v)
{

int n=sz(v);

int sum[sz(v)];
int su=0;

rep(i,0,n)
{

  su+=v[i];
  sum[i]=su;
}

//cout<<sum[n-1];

}

void quickly_quickly_kro()
{
int n,m; cin>>n>>m;

int a[n][m];

map<pii,int> M;

rep(i,0,n)
{
  rep(j,0,m)
  {
    char c; cin>>c;
    if(c=='.')
    a[i][j]=0;
    else
      a[i][j]=1;
  }
}

rep(i,1,n-1)
{
  rep(j,1,m-1)
  {

   if(a[i][j]==1)
   {
    int d=MOD;
     int co=0;
     rep(k,j+1,m)
     {

     if(a[i][k]==1)
     co++;
   else
    break;
     }
     d=min(d,co);
     co=0;

      rev(k,j-1,0)
     {
     if(a[i][k]==1)
     co++;
   else
    break;
     }
     d=min(d,co);

     co=0;
     rep(k,i+1,n)
     {
     if(a[k][j]==1)
     co++;
   else
    break;
     }
     d=min(d,co);

     co=0;
     rev(k,i-1,0)
     {
     if(a[k][j]==1)
     co++;
   else
    break;
     }
     d=min(d,co);

     ////
     if(d>0)
     M[{i+1,j+1}]=d;

   }

  }
}

for(auto l:M)
{
  auto d=l.first;
  auto e=l.second;
  auto i=d.first-1;
  auto j=d.second-1;

 if(e>0)
     {
      a[i][j]=0;
     }

     repe(k,j+1,j+e)
     {
     a[i][k]=0;
     }

     rev(k,j-1,j-e)
     {
     a[i][k]=0;
     }

         repe(k,i+1,i+e)
     {
     a[k][j]=0;
     }

     rev(k,i-1,i-e)
     {
     a[k][j]=0;
     }

}

int co1=0;
rep(i,0,n)
{

  rep(j,0,m)
  {
  //  cout<<a[i][j];
  if(a[i][j]==0)
    co1++;
}
//cout<<nl;
}

if(co1!=n*m)
cout<<-1;
else
{
cout<<M.size()<<nl;

for(auto l:M)
{
  auto d=l.first;
  auto e=l.second;
  auto i=d.first;
  auto j=d.second;

     cout<<i<<" "<<j<<" "<<e<<nl;

}

}

}

signed main()
{

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);

    freopen("error.txt","w", stderr);
    #endif

   FAST
  // SieveOfEratosthenes(1001);
   int t;
   t=1;
      //   cin>>t;

    while(t--)
    {

      quickly_quickly_kro();
      cout<<nl;

}

 #ifndef ONLINE_JUDGE
  cerr<<(1000*clock())/CLOCKS_PER_SEC<<"ms";
 #endif

  return 0;
}


//I’ve fallen in love many times…
// but always with you.
#include <bits/stdc++.h>
using namespace std;
#define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi       acos(-1)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define int long long ////////////
#define MOD 1000000007    ////////
#define POD 998244353 ////////
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define maxc(v) max_element(all(v))
#define minc(v) min_element(all(v))
#define fr first
#define sc second
#define ppb pop_back
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) (m*n)/GCD(m,n)
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define initarr(a,n,x) for (int i=0;i<n;++i) a[i]=x
#define rep(i,a,n)  for(int i=a ; i<n ; i++)
#define repe(i,a,n) for(int i=a;i<=n;i++)
#define rev(i,a,b) for(int i=a;i>=b;i--)
//define ll long long
#define ld long double

#define pii std::pair<int, int>
#define pll std::pair<ll, ll>
#define mii map<int,int>
#define mci map<char,int>
#define msi map<string,int>
#define vi vector<int>
#define vvi vector<vi >
#define vii vector<pii >

#define itv for(auto it= v.begin(); it != v.end(); ++it )

#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(ALL(container),element) != container.end())
//#define invect(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.pb(tmp);commands}
//#define inset(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.insert(tmp);commands}
//#define trav(a, x) for(auto& a : x)
//#define display(x) trav(a,x) cout<<a<<" ";cout<<endl

#define bs binary_search
#define  lb(v,val) = lower_bound(ALL(v), val);

#define dbg1(a) cout<<" *"<<a<<" ";
#define dbg2(a,b) cout<<" *"<<a<<" **"<<b<<" "     /////
#define dbg cout<<"hi"
#define nl endl
#define sz(s)         (int)((s).size())
#define coutsp(k)   cout<<setprecision(k)  //set precision (total length k icluding decimal and non decimal)
#define coutfsp(k)   cout<<fixed<<setprecision(k)  //fixed set precision(after decimal fixing)
#define  INF   (int)2e18

int fast_pow(int base, int n,int M)
{
    if(n==0)
       return 1;
    if(n==1)
    return base;
    int halfn=fast_pow(base,n/2,M);
    if(n%2==0)
        return ( halfn * halfn ) % M;
    else
        return ( ( ( halfn * halfn ) % M ) * base ) % M;
}

void psu(vector<int> v)
{

int n=sz(v);

int sum[sz(v)];
int su=0;

rep(i,0,n)
{

  su+=v[i];
  sum[i]=su;
}

//cout<<sum[n-1];

}

void quickly_quickly_kro()
{
int n,m; cin>>n>>m;

int a[n][m];

map<pii,int> M;

rep(i,0,n)
{
  rep(j,0,m)
  {
    char c; cin>>c;
    if(c=='.')
    a[i][j]=0;
    else
      a[i][j]=1;
  }
}

rep(i,1,n-1)
{
  rep(j,1,m-1)
  {

   if(a[i][j]==1)
   {
    int d=MOD;
     int co=0;
     rep(k,j+1,m)
     {

     if(a[i][k]==1)
     co++;
   else
    break;
     }
     d=min(d,co);
     co=0;

      rev(k,j-1,0)
     {
     if(a[i][k]==1)
     co++;
   else
    break;
     }
     d=min(d,co);

     co=0;
     rep(k,i+1,n)
     {
     if(a[k][j]==1)
     co++;
   else
    break;
     }
     d=min(d,co);

     co=0;
     rev(k,i-1,0)
     {
     if(a[k][j]==1)
     co++;
   else
    break;
     }
     d=min(d,co);

     ////
     if(d>0)
     M[{i+1,j+1}]=d;

   }

  }
}

for(auto l:M)
{
  auto d=l.first;
  auto e=l.second;
  auto i=d.first-1;
  auto j=d.second-1;

 if(e>0)
     {
      a[i][j]=0;
     }

     repe(k,j+1,j+e)
     {
     a[i][k]=0;
     }

     rev(k,j-1,j-e)
     {
     a[i][k]=0;
     }

         repe(k,i+1,i+e)
     {
     a[k][j]=0;
     }

     rev(k,i-1,i-e)
     {
     a[k][j]=0;
     }

}

int co1=0;
rep(i,0,n)
{

  rep(j,0,m)
  {
  //  cout<<a[i][j];
  if(a[i][j]==0)
    co1++;
}
//cout<<nl;
}

if(co1!=n*m)
cout<<-1;
else
{
cout<<M.size()<<nl;

for(auto l:M)
{
  auto d=l.first;
  auto e=l.second;
  auto i=d.first;
  auto j=d.second;

     cout<<i<<" "<<j<<" "<<e<<nl;

}

}

}

signed main()
{

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);

    freopen("error.txt","w", stderr);
    #endif

   FAST
  // SieveOfEratosthenes(1001);
   int t;
   t=1;
      //   cin>>t;

    while(t--)
    {

      quickly_quickly_kro();
      cout<<nl;

}

 #ifndef ONLINE_JUDGE
  cerr<<(1000*clock())/CLOCKS_PER_SEC<<"ms";
 #endif

  return 0;
}


//I’ve fallen in love many times…
// but always with you.
#include <bits/stdc++.h>
using namespace std;
#define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi       acos(-1)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
//#define int long long ////////////
#define MOD 1000000007    ////////
#define POD 998244353 ////////
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define maxc(v) max_element(all(v))
#define minc(v) min_element(all(v))
#define fr first
#define sc second
#define ppb pop_back
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) (m*n)/GCD(m,n)
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define initarr(a,n,x) for (int i=0;i<n;++i) a[i]=x
#define rep(i,a,n)  for(int i=a ; i<n ; i++)
#define repe(i,a,n) for(int i=a;i<=n;i++)
#define rev(i,a,b) for(int i=a;i>=b;i--)
//define ll long long
//#define ld long double

#define pii std::pair<int, int>
#define pll std::pair<ll, ll>
#define mii map<int,int>
#define mci map<char,int>
#define msi map<string,int>
#define vi vector<int>
#define vvi vector<vi >
#define vii vector<pii >

#define itv for(auto it= v.begin(); it != v.end(); ++it )

#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(ALL(container),element) != container.end())
//#define invect(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.pb(tmp);commands}
//#define inset(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.insert(tmp);commands}
//#define trav(a, x) for(auto& a : x)
//#define display(x) trav(a,x) cout<<a<<" ";cout<<endl

#define bs binary_search
#define  lb(v,val) = lower_bound(ALL(v), val);

#define dbg1(a) cout<<" *"<<a<<" ";
#define dbg2(a,b) cout<<" *"<<a<<" **"<<b<<" "     /////
#define dbg cout<<"hi"
#define nl endl
#define sz(s)         (int)((s).size())
#define coutsp(k)   cout<<setprecision(k)  //set precision (total length k icluding decimal and non decimal)
#define coutfsp(k)   cout<<fixed<<setprecision(k)  //fixed set precision(after decimal fixing)
#define  INF   (int)2e18

int fast_pow(int base, int n,int M)
{
    if(n==0)
       return 1;
    if(n==1)
    return base;
    int halfn=fast_pow(base,n/2,M);
    if(n%2==0)
        return ( halfn * halfn ) % M;
    else
        return ( ( ( halfn * halfn ) % M ) * base ) % M;
}

void psu(vector<int> v)
{

int n=sz(v);

int sum[sz(v)];
int su=0;

rep(i,0,n)
{

  su+=v[i];
  sum[i]=su;
}

//cout<<sum[n-1];

}

void quickly_quickly_kro()
{
int n,m; cin>>n>>m;

int a[n][m];

map<pii,int> M;

rep(i,0,n)
{
  rep(j,0,m)
  {
    char c; cin>>c;
    if(c=='.')
    a[i][j]=0;
    else
      a[i][j]=1;
  }
}

rep(i,1,n-1)
{
  rep(j,1,m-1)
  {

   if(a[i][j]==1)
   {
    int d=MOD;
     int co=0;
     rep(k,j+1,m)
     {

     if(a[i][k]==1)
     co++;
   else
    break;
     }
     d=min(d,co);
     co=0;

      rev(k,j-1,0)
     {
     if(a[i][k]==1)
     co++;
   else
    break;
     }
     d=min(d,co);

     co=0;
     rep(k,i+1,n)
     {
     if(a[k][j]==1)
     co++;
   else
    break;
     }
     d=min(d,co);

     co=0;
     rev(k,i-1,0)
     {
     if(a[k][j]==1)
     co++;
   else
    break;
     }
     d=min(d,co);

     ////
     if(d>0)
     M[{i+1,j+1}]=d;

   }

  }
}

for(auto l:M)
{
  auto d=l.first;
  auto e=l.second;
  auto i=d.first-1;
  auto j=d.second-1;

 if(e>0)
     {
      a[i][j]=0;
     }

     repe(k,j+1,j+e)
     {
     a[i][k]=0;
     }

     rev(k,j-1,j-e)
     {
     a[i][k]=0;
     }

         repe(k,i+1,i+e)
     {
     a[k][j]=0;
     }

     rev(k,i-1,i-e)
     {
     a[k][j]=0;
     }

}

int co1=0;
rep(i,0,n)
{

  rep(j,0,m)
  {
  //  cout<<a[i][j];
  if(a[i][j]==0)
    co1++;
}
//cout<<nl;
}

if(co1!=n*m)
cout<<-1;
else
{
cout<<M.size()<<"\n";

for(auto l:M)
{
  auto d=l.first;
  auto e=l.second;
  auto i=d.first;
  auto j=d.second;

    cout<<i<<" "<<j<<" "<<e<<"\n";

}

}

}

signed main()
{

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);

    freopen("error.txt","w", stderr);
    #endif

   FAST
  // SieveOfEratosthenes(1001);
   int t;
   t=1;
      //   cin>>t;

    while(t--)
    {

      quickly_quickly_kro();
      cout<<nl;

}

 #ifndef ONLINE_JUDGE
  cerr<<(1000*clock())/CLOCKS_PER_SEC<<"ms";
 #endif

  return 0;
}


//I’ve fallen in love many times…
// but always with you.
#include <bits/stdc++.h>
using namespace std;
#define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi       acos(-1)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
//#define int long long ////////////
#define MOD 1000000007    ////////
#define POD 998244353 ////////
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define maxc(v) max_element(all(v))
#define minc(v) min_element(all(v))
#define fr first
#define sc second
#define ppb pop_back
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) (m*n)/GCD(m,n)
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define initarr(a,n,x) for (int i=0;i<n;++i) a[i]=x
#define rep(i,a,n)  for(int i=a ; i<n ; i++)
#define repe(i,a,n) for(int i=a;i<=n;i++)
#define rev(i,a,b) for(int i=a;i>=b;i--)
//define ll long long
//#define ld long double

#define pii std::pair<int, int>
#define pll std::pair<ll, ll>
#define mii map<int,int>
#define mci map<char,int>
#define msi map<string,int>
#define vi vector<int>
#define vvi vector<vi >
#define vii vector<pii >

#define itv for(auto it= v.begin(); it != v.end(); ++it )

#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(ALL(container),element) != container.end())
//#define invect(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.pb(tmp);commands}
//#define inset(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.insert(tmp);commands}
//#define trav(a, x) for(auto& a : x)
//#define display(x) trav(a,x) cout<<a<<" ";cout<<endl

#define bs binary_search
#define  lb(v,val) = lower_bound(ALL(v), val);

#define dbg1(a) cout<<" *"<<a<<" ";
#define dbg2(a,b) cout<<" *"<<a<<" **"<<b<<" "     /////
#define dbg cout<<"hi"
#define nl endl
#define sz(s)         (int)((s).size())
#define coutsp(k)   cout<<setprecision(k)  //set precision (total length k icluding decimal and non decimal)
#define coutfsp(k)   cout<<fixed<<setprecision(k)  //fixed set precision(after decimal fixing)
#define  INF   (int)2e18

int fast_pow(int base, int n,int M)
{
    if(n==0)
       return 1;
    if(n==1)
    return base;
    int halfn=fast_pow(base,n/2,M);
    if(n%2==0)
        return ( halfn * halfn ) % M;
    else
        return ( ( ( halfn * halfn ) % M ) * base ) % M;
}

void psu(vector<int> v)
{

int n=sz(v);

int sum[sz(v)];
int su=0;

rep(i,0,n)
{

  su+=v[i];
  sum[i]=su;
}

//cout<<sum[n-1];

}

void quickly_quickly_kro()
{
int n,m; cin>>n>>m;

int a[n][m];

map<pii,int> M;

rep(i,0,n)
{
  rep(j,0,m)
  {
    char c; cin>>c;
    if(c=='.')
    a[i][j]=0;
    else
      a[i][j]=1;
  }
}

rep(i,1,n-1)
{
  rep(j,1,m-1)
  {

   if(a[i][j]==1)
   {
    int d=MOD;
     int co=0;
     rep(k,j+1,m)
     {

     if(a[i][k]==1)
     co++;
   else
    break;
     }
     d=min(d,co);
     co=0;

      rev(k,j-1,0)
     {
     if(a[i][k]==1)
     co++;
   else
    break;
     }
     d=min(d,co);

     co=0;
     rep(k,i+1,n)
     {
     if(a[k][j]==1)
     co++;
   else
    break;
     }
     d=min(d,co);

     co=0;
     rev(k,i-1,0)
     {
     if(a[k][j]==1)
     co++;
   else
    break;
     }
     d=min(d,co);

     ////
     if(d>0)
     M[{i+1,j+1}]=d;

   }

  }
}

for(auto l:M)
{
  auto d=l.first;
  auto e=l.second;
  auto i=d.first-1;
  auto j=d.second-1;

 if(e>0)
     {
      a[i][j]=0;
     }

     repe(k,j+1,j+e)
     {
     a[i][k]=0;
     }

     rev(k,j-1,j-e)
     {
     a[i][k]=0;
     }

         repe(k,i+1,i+e)
     {
     a[k][j]=0;
     }

     rev(k,i-1,i-e)
     {
     a[k][j]=0;
     }

}

int co1=0;
rep(i,0,n)
{

  rep(j,0,m)
  {
  //  cout<<a[i][j];
  if(a[i][j]==0)
    co1++;
}
//cout<<nl;
}

if(co1!=n*m)
cout<<-1;
else
{
cout<<M.size()<<nl;

for(auto l:M)
{
  auto d=l.first;
  auto e=l.second;
  auto i=d.first;
  auto j=d.second;

     cout<<i<<" "<<j<<" "<<e<<nl;

}

}

}

signed main()
{

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);

    freopen("error.txt","w", stderr);
    #endif

   FAST
  // SieveOfEratosthenes(1001);
   int t;
   t=1;
      //   cin>>t;

    while(t--)
    {

      quickly_quickly_kro();
      cout<<nl;

}

 #ifndef ONLINE_JUDGE
  cerr<<(1000*clock())/CLOCKS_PER_SEC<<"ms";
 #endif

  return 0;
}


//I’ve fallen in love many times…
// but always with you.
#include <bits/stdc++.h>
using namespace std;
#define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi       acos(-1)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
//#define int long long ////////////
#define MOD 1000000007    ////////
#define POD 998244353 ////////
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define maxc(v) max_element(all(v))
#define minc(v) min_element(all(v))
#define fr first
#define sc second
#define ppb pop_back
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) (m*n)/GCD(m,n)
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define initarr(a,n,x) for (int i=0;i<n;++i) a[i]=x
#define rep(i,a,n)  for(int i=a ; i<n ; i++)
#define repe(i,a,n) for(int i=a;i<=n;i++)
#define rev(i,a,b) for(int i=a;i>=b;i--)
//define ll long long
//#define ld long double

#define pii std::pair<int, int>
#define pll std::pair<ll, ll>
#define mii map<int,int>
#define mci map<char,int>
#define msi map<string,int>
#define vi vector<int>
#define vvi vector<vi >
#define vii vector<pii >

#define itv for(auto it= v.begin(); it != v.end(); ++it )

#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(ALL(container),element) != container.end())
//#define invect(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.pb(tmp);commands}
//#define inset(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.insert(tmp);commands}
//#define trav(a, x) for(auto& a : x)
//#define display(x) trav(a,x) cout<<a<<" ";cout<<endl

#define bs binary_search
#define  lb(v,val) = lower_bound(ALL(v), val);

#define dbg1(a) cout<<" *"<<a<<" ";
#define dbg2(a,b) cout<<" *"<<a<<" **"<<b<<" "     /////
#define dbg cout<<"hi"
#define nl "\n";
#define sz(s)         (int)((s).size())
#define coutsp(k)   cout<<setprecision(k)  //set precision (total length k icluding decimal and non decimal)
#define coutfsp(k)   cout<<fixed<<setprecision(k)  //fixed set precision(after decimal fixing)
#define  INF   (int)2e18

int fast_pow(int base, int n,int M)
{
    if(n==0)
       return 1;
    if(n==1)
    return base;
    int halfn=fast_pow(base,n/2,M);
    if(n%2==0)
        return ( halfn * halfn ) % M;
    else
        return ( ( ( halfn * halfn ) % M ) * base ) % M;
}

void psu(vector<int> v)
{

int n=sz(v);

int sum[sz(v)];
int su=0;

rep(i,0,n)
{

  su+=v[i];
  sum[i]=su;
}

//cout<<sum[n-1];

}

void quickly_quickly_kro()
{
int n,m; cin>>n>>m;

int a[n][m];

map<pii,int> M;

rep(i,0,n)
{
  rep(j,0,m)
  {
    char c; cin>>c;
    if(c=='.')
    a[i][j]=0;
    else
      a[i][j]=1;
  }
}

rep(i,1,n-1)
{
  rep(j,1,m-1)
  {

   if(a[i][j]==1)
   {
    int d=MOD;
     int co=0;
     rep(k,j+1,m)
     {

     if(a[i][k]==1)
     co++;
   else
    break;
     }
     d=min(d,co);
     co=0;

      rev(k,j-1,0)
     {
     if(a[i][k]==1)
     co++;
   else
    break;
     }
     d=min(d,co);

     co=0;
     rep(k,i+1,n)
     {
     if(a[k][j]==1)
     co++;
   else
    break;
     }
     d=min(d,co);

     co=0;
     rev(k,i-1,0)
     {
     if(a[k][j]==1)
     co++;
   else
    break;
     }
     d=min(d,co);

     ////
     if(d>0)
     M[{i+1,j+1}]=d;

   }

  }
}

for(auto l:M)
{
  auto d=l.first;
  auto e=l.second;
  auto i=d.first-1;
  auto j=d.second-1;

 if(e>0)
     {
      a[i][j]=0;
     }

     repe(k,j+1,j+e)
     {
     a[i][k]=0;
     }

     rev(k,j-1,j-e)
     {
     a[i][k]=0;
     }

         repe(k,i+1,i+e)
     {
     a[k][j]=0;
     }

     rev(k,i-1,i-e)
     {
     a[k][j]=0;
     }

}

int co1=0;
rep(i,0,n)
{

  rep(j,0,m)
  {
  //  cout<<a[i][j];
  if(a[i][j]==0)
    co1++;
}
//cout<<nl;
}

if(co1!=n*m)
cout<<-1;
else
{
cout<<M.size()<<nl;

for(auto l:M)
{
  auto d=l.first;
  auto e=l.second;
  auto i=d.first;
  auto j=d.second;

    cout<<i<<" "<<j<<" "<<e<<nl;

}

}

}

signed main()
{

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);

    freopen("error.txt","w", stderr);
    #endif

   FAST
  // SieveOfEratosthenes(1001);
   int t;
   t=1;
      //   cin>>t;

    while(t--)
    {

      quickly_quickly_kro();
      cout<<nl;

}

 #ifndef ONLINE_JUDGE
  cerr<<(1000*clock())/CLOCKS_PER_SEC<<"ms";
 #endif

  return 0;
}


//I’ve fallen in love many times…
// but always with you.
#include <bits/stdc++.h>
using namespace std;
#define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi       acos(-1)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define int long long ////////////
#define MOD 1000000007    ////////
#define POD 998244353 ////////
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define maxc(v) max_element(all(v))
#define minc(v) min_element(all(v))
#define fr first
#define sc second
#define ppb pop_back
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) (m*n)/GCD(m,n)
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define initarr(a,n,x) for (int i=0;i<n;++i) a[i]=x
#define rep(i,a,n)  for(int i=a ; i<n ; i++)
#define repe(i,a,n) for(int i=a;i<=n;i++)
#define rev(i,a,b) for(int i=a;i>=b;i--)
//define ll long long
//#define ld long double

#define pii std::pair<int, int>
#define pll std::pair<ll, ll>
#define mii map<int,int>
#define mci map<char,int>
#define msi map<string,int>
#define vi vector<int>
#define vvi vector<vi >
#define vii vector<pii >

#define itv for(auto it= v.begin(); it != v.end(); ++it )

#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(ALL(container),element) != container.end())
//#define invect(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.pb(tmp);commands}
//#define inset(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.insert(tmp);commands}
//#define trav(a, x) for(auto& a : x)
//#define display(x) trav(a,x) cout<<a<<" ";cout<<endl

#define bs binary_search
#define  lb(v,val) = lower_bound(ALL(v), val);

#define dbg1(a) cout<<" *"<<a<<" ";
#define dbg2(a,b) cout<<" *"<<a<<" **"<<b<<" "     /////
#define dbg cout<<"hi"
#define nl "\n";
#define sz(s)         (int)((s).size())
#define coutsp(k)   cout<<setprecision(k)  //set precision (total length k icluding decimal and non decimal)
#define coutfsp(k)   cout<<fixed<<setprecision(k)  //fixed set precision(after decimal fixing)
#define  INF   (int)2e18

int fast_pow(int base, int n,int M)
{
    if(n==0)
       return 1;
    if(n==1)
    return base;
    int halfn=fast_pow(base,n/2,M);
    if(n%2==0)
        return ( halfn * halfn ) % M;
    else
        return ( ( ( halfn * halfn ) % M ) * base ) % M;
}

void psu(vector<int> v)
{

int n=sz(v);

int sum[sz(v)];
int su=0;

rep(i,0,n)
{

  su+=v[i];
  sum[i]=su;
}

//cout<<sum[n-1];

}

void quickly_quickly_kro()
{
int n,m; cin>>n>>m;

int a[n][m];

map<pii,int> M;

rep(i,0,n)
{
  rep(j,0,m)
  {
    char c; cin>>c;
    if(c=='.')
    a[i][j]=0;
    else
      a[i][j]=1;
  }
}

rep(i,1,n-1)
{
  rep(j,1,m-1)
  {

   if(a[i][j]==1)
   {
    int d=MOD;
     int co=0;
     rep(k,j+1,m)
     {

     if(a[i][k]==1)
     co++;
   else
    break;
     }
     d=min(d,co);
     co=0;

      rev(k,j-1,0)
     {
     if(a[i][k]==1)
     co++;
   else
    break;
     }
     d=min(d,co);

     co=0;
     rep(k,i+1,n)
     {
     if(a[k][j]==1)
     co++;
   else
    break;
     }
     d=min(d,co);

     co=0;
     rev(k,i-1,0)
     {
     if(a[k][j]==1)
     co++;
   else
    break;
     }
     d=min(d,co);

     ////
     if(d>0)
     M[{i+1,j+1}]=d;

   }

  }
}

for(auto l:M)
{
  auto d=l.first;
  auto e=l.second;
  auto i=d.first-1;
  auto j=d.second-1;

 if(e>0)
     {
      a[i][j]=0;
     }

     repe(k,j+1,j+e)
     {
     a[i][k]=0;
     }

     rev(k,j-1,j-e)
     {
     a[i][k]=0;
     }

         repe(k,i+1,i+e)
     {
     a[k][j]=0;
     }

     rev(k,i-1,i-e)
     {
     a[k][j]=0;
     }

}

int co1=0;
rep(i,0,n)
{

  rep(j,0,m)
  {
  //  cout<<a[i][j];
  if(a[i][j]==0)
    co1++;
}
//cout<<nl;
}

if(co1!=n*m)
cout<<-1;
else
{
cout<<M.size()<<nl;

for(auto l:M)
{
  auto d=l.first;
  auto e=l.second;
  auto i=d.first;
  auto j=d.second;

    cout<<i<<" "<<j<<" "<<e<<nl;

}

}

}

signed main()
{

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);

    freopen("error.txt","w", stderr);
    #endif

   FAST
  // SieveOfEratosthenes(1001);
   int t;
   t=1;
      //   cin>>t;

    while(t--)
    {

      quickly_quickly_kro();
      cout<<nl;

}

 #ifndef ONLINE_JUDGE
  cerr<<(1000*clock())/CLOCKS_PER_SEC<<"ms";
 #endif

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

struct an{
    int x;
    int y;
    int sz;
    an(int x, int y, int sz) : x(x), y(y), sz(sz) {}
};

int main ()
{
    ios_base::sync_with_stdio(false);
   // freopen("input.txt", "r", stdin);
    int n, m;
    cin >> n >> m;
    vector<vector<bool> > p(n, vector<bool> (m)), myP(n, vector<bool> (m));
    for (int i = 0; i < n; i++) {
        string tmp;
        cin >> tmp;
        for (int j = 0; j < m; j++) {
            if (tmp[j] ==  '*') {
                p[i][j] = true;
            }
        }
    }

/*    vector<vector<int> > minDist(n, vector<bool (m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            minDist[i][j] = min(min(i, j), min(n-i-1, m-j-1));
        }
    }
*/

    vector<an> ans;

    for (int sz = (min(n, m)+1) / 2 - 1; sz >= 1 ; sz--) {
        for (int i = sz; i < n-sz; i++) {
            for (int j = sz; j < m-sz; j++) {
                bool ok = true;
                int cnt = 0;
           //     cout << i << " " << j << " " << sz << endl;
     //           cout << " i = " << i << " " << sz <<  endl;
                for (int u = i - sz; u <= i+sz; u++) {
     //               cout << i << " " << j << " " << i-sz << " " << i+sz << endl;
                    if (!p[u][j]) {
                        ok = false;
                        break;
                    }
                    if (!myP[u][j]) {
                        cnt++;
                    }
                }
                if (!ok) {
                    continue;
                }
                for (int r = j - sz; r <= j+sz; r++) {
                    if (!p[i][r]) {
                        ok = false;
                        break;
                    }
                    if (!myP[i][r]) {
                        cnt++;
                    }
                }

                if (ok && cnt != 0) {

                    ans.push_back(an(i+1, j+1, sz));

                    for (int u = i - sz; u <= i+sz; u++) {
                        myP[u][j] = true;
                    }
                    for (int r = j - sz; r <= j+sz; r++) {
                        myP[i][r] = true;
                    }
                }
            }
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (p[i][j] != myP[i][j]) {
                cout << -1;
                return 0;
                if (myP[i][j]) {
   //                 cout << '*';
                }
                else {
  //                  cout << '.';
                }
            }
        }
    //    cout << endl;
    }

    cout << ans.size() << endl;
    for (auto i: ans) {
        cout << i.x << " " << i.y << " " << i.sz << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define NN 1111
char s[NN][NN];
int cntl[NN][NN], cntr[NN][NN], cntu[NN][NN], cntd[NN][NN];
int flag[NN][NN];
int n, m;

struct Node{
	int x, y, val;
};
vector<Node> res;

int main () {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n >> m;
	for(int i=1; i<=n; i++) cin >> (s[i] + 1);

	for(int i=1; i<=n; i++)
		for(int j=1; j<=m; j++) if(s[i][j] == '*') {
			flag[i][j] = 1;
			cntl[i][j] = cntl[i][j-1] + 1;
			cntu[i][j] = cntu[i-1][j] + 1;
		}

	for(int i=n; i; i --)
		for(int j = m; j; j --) if(s[i][j] == '*') {
			cntr[i][j] = cntr[i][j+1] + 1;
			cntd[i][j] = cntd[i+1][j] + 1;
		}

	for(int i=1; i<=n; i++)
		for(int j=1; j<=m; j++) if(s[i][j] == '*') {
			int step = min(cntl[i][j-1], cntr[i][j+1]);
			step = min(step, cntu[i-1][j]);
			step = min(step, cntd[i+1][j]);
			if(step == 0) continue;
			flag[i][j] = 0;
			res.push_back({i, j, step});
			for(int k = 1;  k<=step; k ++) {
				flag[i-k][j] = 0;
				flag[i+k][j] = 0;
				flag[i][j-k] = flag[i][j+k] = 0;
			}
		}

	for(int i=1; i<=n; i++)
		for(int j=1; j<=m; j++) if(flag[i][j]) return puts("-1");

	cout << res.size() << endl;
	for(auto v : res) printf("%d %d %d\n", v.x, v.y, v.val);
	return 0;
}


#include<bits/stdc++.h>
#define NN 1010

using namespace std;
using pii=pair<int, int>;
using ppi=pair<pii, int>;

char s[NN][NN];
int L[NN][NN], R[NN][NN], D[NN][NN], U[NN][NN];
int vst[NN][NN];

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	int n, m;
	cin>>n>>m;
	for(int i=1; i<=n; i++) scanf("%s", s[i]+1);
	for(int i=1; i<=n; i++) {
		for(int j=1; j<=m; j++) {
			if(s[i][j]=='*') {
				vst[i][j]=1;
				if(s[i][j-1]=='*') L[i][j]=L[i][j-1]+1;
				else L[i][j]=1;
				if(s[i-1][j]=='*') U[i][j]=U[i-1][j]+1;
				else U[i][j]=1;
			}
		}
	}
	for(int i=n; i>=1; i--) {
		for(int j=m; j>=1; j--) {
			if(s[i][j]=='*') {
				if(s[i][j+1]=='*') R[i][j]=R[i][j+1]+1;
				else R[i][j]=1;
				if(s[i+1][j]=='*') D[i][j]=D[i+1][j]+1;
				else D[i][j]=1;
			}
		}
	}
	vector<ppi>ans;
	for(int i=1; i<=n; i++) {
		for(int j=1; j<=m; j++) {
			if(s[i][j]=='*') {
				int len=min(L[i][j]-1, R[i][j]-1);
				len=min(len, D[i][j]-1);
				len=min(len, U[i][j]-1);
				if(len) {
					ans.push_back(ppi(pii(i, j), len));
					for(int k=j-len; k<=j+len; k++) vst[i][k]=0;
					for(int k=i-len; k<=i+len; k++) vst[k][j]=0;
				}
			}
		}
	}
	for(int i=1; i<=n; i++) {
		for(int j=1; j<=m; j++) {
			if(vst[i][j]) {
				puts("-1");
				return 0;
			}
		}
	}

	cout<<ans.size()<<endl;
	for(auto p : ans) printf("%d %d %d\n", p.first.first, p.first.second, p.second);

	return 0;
}


#include<bits/stdc++.h>
#define NN 1010

using namespace std;
using pii=pair<int, int>;
using ppi=pair<pii, int>;

char s[NN][NN];
int L[NN][NN], R[NN][NN], D[NN][NN], U[NN][NN];
int vst[NN][NN];

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	int n, m;
	cin>>n>>m;
	for(int i=1; i<=n; i++) scanf("%s", s[i]+1);
	for(int i=1; i<=n; i++) {
		for(int j=1; j<=m; j++) {
			if(s[i][j]=='*') {
				vst[i][j]=1;
				if(s[i][j-1]=='*') L[i][j]=L[i][j-1]+1;
				else L[i][j]=1;
				if(s[i-1][j]=='*') U[i][j]=U[i-1][j]+1;
				else U[i][j]=1;
			}
		}
	}
	for(int i=n; i>=1; i--) {
		for(int j=m; j>=1; j--) {
			if(s[i][j]=='*') {
				if(s[i][j+1]=='*') R[i][j]=R[i][j+1]+1;
				else R[i][j]=1;
				if(s[i+1][j]=='*') D[i][j]=D[i+1][j]+1;
				else D[i][j]=1;
			}
		}
	}
	vector<ppi>ans;
	for(int i=1; i<=n; i++) {
		for(int j=1; j<=m; j++) {
			if(s[i][j]=='*') {
				int len=min(L[i][j]-1, R[i][j]-1);
				len=min(len, D[i][j]-1);
				len=min(len, U[i][j]-1);
				if(len) {
					ans.push_back(ppi(pii(i, j), len));
					for(int k=j-len; k<=j+len; k++) vst[i][k]=0;
					for(int k=i-len; k<=i+len; k++) vst[k][j]=0;
				}
			}
		}
	}
	for(int i=1; i<=n; i++) {
		for(int j=1; j<=m; j++) {
			if(vst[i][j]) {
				puts("-1");
				return 0;
			}
		}
	}

	cout<<ans.size()<<endl;
	for(auto p : ans) cout<<p.first.first<<" "<<p.first.second<<" "<<p.second<<endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int NN=1010;

struct triple{
	int x; int y; int z;
};

char s[NN][NN];
int vst[NN][NN];
int L[NN][NN],R[NN][NN],U[NN][NN],D[NN][NN];
int n,m;
vector<triple> ans;

void pre(){
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++)if(s[i][j]=='*')L[i][j]=L[i][j-1]+1;
		for(int j=m;j;j--)if(s[i][j]=='*')R[i][j]=R[i][j+1]+1;
	}
	for(int j=1;j<=m;j++){
		for(int i=1;i<=n;i++)if(s[i][j]=='*')U[i][j]=U[i-1][j]+1;
		for(int i=n;i;i--)if(s[i][j]=='*')D[i][j]=D[i+1][j]+1;
	}
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
#endif
	cin>>n>>m;

	for(int i=1;i<=n;i++)cin>>s[i]+1;
	pre();

	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(s[i][j]=='*'){
				int sz=min({L[i][j],R[i][j],U[i][j],D[i][j]})-1;
				if(sz)ans.push_back({i,j,sz});
			}
		}
	}

	for(auto p:ans){
		int x=p.x, y=p.y, z=p.z;
		for(int i=y-z;i<=y+z;i++)s[x][i]='.';
		for(int i=x-z;i<=x+z;i++)s[i][y]='.';
	}

	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(s[i][j]=='*'){
				puts("-1");
				return 0;
			}
		}
	}

	cout<<ans.size()<<endl;
	for(auto p:ans){
		printf("%d %d %d\n",p.x,p.y,p.z);
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define NN 1111
char s[NN][NN];
int cntl[NN][NN], cntr[NN][NN], cntu[NN][NN], cntd[NN][NN];
int flag[NN][NN];
int n, m;

struct Node{
	int x, y, val;
};
vector<Node> res;

int main () {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n >> m;
	for(int i=1; i<=n; i++) cin >> (s[i] + 1);

	for(int i=1; i<=n; i++)
		for(int j=1; j<=m; j++) if(s[i][j] == '*') {
			flag[i][j] = 1;
			cntl[i][j] = cntl[i][j-1] + 1;
			cntu[i][j] = cntu[i-1][j] + 1;
		}
	for(int i=n; i; i --)
		for(int j = m; j; j --) if(s[i][j] == '*') {
			cntr[i][j] = cntr[i][j+1] + 1;
			cntd[i][j] = cntd[i+1][j] + 1;
		}

	for(int i=1; i<=n; i++)
		for(int j=1; j<=m; j++) if(s[i][j] == '*') {
			int step = min(cntl[i][j-1], cntr[i][j+1]);
			step = min(step, cntu[i-1][j]);
			step = min(step, cntd[i+1][j]);
			if(step == 0) continue;
			flag[i][j] = 0;
			res.push_back({i, j, step});
			for(int k = 1;  k<=step; k ++) {
				flag[i-k][j] = 0;
				flag[i+k][j] = 0;
				flag[i][j-k] = flag[i][j+k] = 0;
			}
		}

	for(int i=1; i<=n; i++)
		for(int j=1; j<=m; j++) if(flag[i][j]) return puts("-1");
	cout << res.size() << endl;
	for(auto v : res) cout << v.x << " " << v.y << " " << v.val << endl;
	return 0;
}


#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pii pair<int,int>
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define vc vector
#define S second
#define F first
using namespace std;
const int inf = 1e9+9;

ll n,m;
string s[1009];
ll dp[1009][1009][4];
ll done[1009][1009][2];
vc < pair < pii , int > > v;

void fillDp(){
	int ans = 0;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(s[i][j] == '*') ans++;
			else ans = 0;
			dp[i][j][0] = ans;
		}
	}
	ans = 0;
	for(int j=0;j<m;j++){
		for(int i=0;i<n;i++){
			if(s[i][j] == '*') ans++;
			else ans = 0;
			dp[i][j][1] = ans;
		}
	}
	ans = 0;
	for(int i=0;i<n;i++){
		for(int j=m-1;j>=0;j--){
			if(s[i][j] == '*') ans++;
			else ans = 0;
			dp[i][j][2] = ans;
		}
	}
	ans = 0;
	for(int j=0;j<m;j++){
		for(int i=n-1;i>=0;i--){
			if(s[i][j] == '*') ans++;
			else ans = 0;
			dp[i][j][3] = ans;
		}
	}
}

void fillOut(){
    for(int i=0;i<n;i++){
        for(int j=1;j<m;j++){
            done[i][j][0] += done[i][j-1][0];
        }
    }
    for(int j=0;j<m;j++){
        for(int i=1;i<n;i++){
            done[i][j][1] += done[i-1][j][1];
        }
    }
}

void check(int x,int y){
	ll ret = inf;
	for(int i=0;i<4;i++){
		ret = min(ret,dp[x][y][i]);
	}
	if(ret == 1) return;
	done[x][y-ret+1][0]++;
	done[x-ret+1][y][1]++;
	done[x][y+ret][0]--;
	done[x+ret][y][1]--;
	v.pb({{x+1,y+1},ret-1});
}

int main(){
	fast,cin>>n>>m;
	for(int i=0;i<n;i++) cin>>s[i];
	fillDp();
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(s[i][j] == '*') check(i,j);
		}
	}
	fillOut();
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(s[i][j] == '.') continue;
			ll tmp = 0;
			for(int k=0;k<2;k++){
				tmp += done[i][j][k];
			}
			if(!tmp) cout<<-1<<endl,exit(0);
		}
	}
	cout<<v.size()<<endl;
	for(auto u:v){
		cout<<u.F.F<<" "<<u.F.S;
		cout<<" "<<u.S<<endl;
	}
}


#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pii pair<int,int>
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define vc vector
#define S second
#define F first
using namespace std;
const int inf = 1e9+9;

int n,m;
string s[1009];
int dp[1009][1009][4];
int done[1009][1009][2];
vc < pair < pii , int > > v;

void fillDp(){
	int ans = 0;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(s[i][j] == '*') ans++;
			else ans = 0;
			dp[i][j][0] = ans;
		}
	}
	ans = 0;
	for(int j=0;j<m;j++){
		for(int i=0;i<n;i++){
			if(s[i][j] == '*') ans++;
			else ans = 0;
			dp[i][j][1] = ans;
		}
	}
	ans = 0;
	for(int i=0;i<n;i++){
		for(int j=m-1;j>=0;j--){
			if(s[i][j] == '*') ans++;
			else ans = 0;
			dp[i][j][2] = ans;
		}
	}
	ans = 0;
	for(int j=0;j<m;j++){
		for(int i=n-1;i>=0;i--){
			if(s[i][j] == '*') ans++;
			else ans = 0;
			dp[i][j][3] = ans;
		}
	}
}

void fillOut(){
    for(int i=0;i<n;i++){
        for(int j=1;j<m;j++){
            done[i][j][0] += done[i][j-1][0];
        }
    }
    for(int j=0;j<m;j++){
        for(int i=1;i<n;i++){
            done[i][j][1] += done[i-1][j][1];
        }
    }
}

void check(int x,int y){
	int ret = inf;
	for(int i=0;i<4;i++){
		ret = min(ret,dp[x][y][i]);
	}
	if(ret == 1) return;
	done[x][y-ret+1][0]++;
	done[x-ret+1][y][1]++;
	done[x][y+ret][0]--;
	done[x+ret][y][1]--;
	v.pb({{x+1,y+1},ret-1});
}

int main(){
	fast,cin>>n>>m;
	for(int i=0;i<n;i++) cin>>s[i];
	fillDp();
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(s[i][j] == '*') check(i,j);
		}
	}
	fillOut();
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(s[i][j] == '.') continue;
			int tmp = 0;
			for(int k=0;k<2;k++){
				tmp += done[i][j][k];
			}
			if(!tmp) cout<<-1<<endl,exit(0);
		}
	}
	cout<<v.size()<<endl;
	for(auto u:v){
		cout<<u.F.F<<" "<<u.F.S;
		cout<<" "<<u.S<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
char mat[2004][2004];
bool mataux[2004][2004];
int vec[1004][3];
int main(){
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    int N,M,i,j,p;
    cin>>N>>M;
    for(i=1;i<=N;i++){
        for(j=1;j<=M;j++){
            cin>>mat[i][j];
        }
    }
    if(mat[1][1]=='*'||mat[1][M]=='*'||mat[N][1]=='*'||mat[N][M]=='*'){
        cout<<-1;
        return 0;
    }
    int ind=0,ini,fin,m,tam;
    bool aux;
    for(i=1;i<=N;i++){
        for(j=1;j<=M;j++){
            if(mat[i][j]=='*'){
                ini=0;
                fin=min(i,j);
                while(ini<fin-1){
                    m=(ini+fin)/2;
                    aux=true;
                    for(p=i-m;p<=i+m;p++)if(mat[p][j]!='*')aux=false;
                    for(p=j-m;p<=j+m;p++)if(mat[i][p]!='*')aux=false;
                    if(aux==false){
                        fin=m;
                    }
                    else ini=m;
                    ///ini es el ultimo tamaño que funciona
                }
                tam=ini;
                if(tam>0){
                    vec[ind][0]=i;
                    vec[ind][1]=j;
                    vec[ind][2]=tam;
                    ind++;
                    for(p=i-tam;p<=i+tam;p++)mataux[p][j]=true;
                    for(p=j-tam;p<=j+tam;p++)mataux[i][p]=true;
                }
            }
        }
    }
    for(i=1;i<=N;i++){
        for(j=1;j<=M;j++){
            if(mat[i][j]=='*'){
                if(mataux[i][j]==false){
                    cout<<-1;
                    return 0;
                }
            }
        }
    }
    cout<<ind<<"\n";
    for(i=0;i<ind;i++){
        cout<<vec[i][0]<<" "<<vec[i][1]<<" "<<vec[i][2]<<"\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
char mat[2004][2004];
bool mataux[2004][2004];
int vec[1004][3];
int main(){
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    int N,M;
    cin>>N>>M;
    for(int i=1;i<=N;i++){
        for(int j=1;j<=M;j++){
            cin>>mat[i][j];
        }
    }
    if(mat[1][1]=='*'||mat[1][M]=='*'||mat[N][1]=='*'||mat[N][M]=='*'){
        cout<<-1;
        return 0;
    }
    int ind=0,tam;
    bool aux;
    for(int i=1;i<=N;i++){
        for(int j=1;j<=M;j++){
            if(mat[i][j]=='*'){
                int ini=0;
                int fin=min(i,j);
                while(ini<fin-1){
                    int m=(ini+fin)/2;
                    aux=true;
                    for(int p=i-m;p<=i+m;p++)if(mat[p][j]!='*')aux=false;
                    for(int p=j-m;p<=j+m;p++)if(mat[i][p]!='*')aux=false;
                    if(aux==false){
                        fin=m;
                    }
                    else ini=m;
                    ///ini es el ultimo tamaño que funciona
                }
                tam=ini;
                if(tam>0){
                    vec[ind][0]=i;
                    vec[ind][1]=j;
                    vec[ind][2]=tam;
                    ind++;
                    for(int p=i-tam;p<=i+tam;p++)mataux[p][j]=true;
                    for(int p=j-tam;p<=j+tam;p++)mataux[i][p]=true;
                }
            }
        }
    }
    for(int i=1;i<=N;i++){
        for(int j=1;j<=M;j++){
            if(mat[i][j]=='*'){
                if(mataux[i][j]==false){
                    cout<<-1;
                    return 0;
                }
            }
        }
    }
    cout<<ind<<"\n";
    for(int i=0;i<ind;i++){
        cout<<vec[i][0]<<" "<<vec[i][1]<<" "<<vec[i][2]<<"\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
char mat[1004][1004];
bool mataux[1004][1004];
pair<pair<int,int>,int>  par;
vector<pair<pair<int,int> ,int>  > vec;
int main(){
    int N,M;
    cin>>N>>M;
    for(int i=1;i<=N;i++){
        for(int j=1;j<=M;j++){
            cin>>mat[i][j];
        }
    }

    for(int i=1;i<=N;i++){
        for(int j=1;j<=M;j++){
            if(mat[i][j]=='*'){

                int tam=0;
                bool aux=true;
                for(tam=0;tam<101;tam++){
                    aux=true;
                    p=i-tam;
                    if(mat[p][j]!='*')aux=false;
                    p=i+tam;
                    if(mat[p][j]!='*')aux=false;
                    p=j-tam;
                    if(mat[i][p]!='*')aux=false;
                    p=j+tam;
                    if(mat[i][p]!='*')aux=false;
                    if(aux==false)break;
                    ///tam es el primer tamaño que falla
                }
                tam--;
                if(tam>0){
                    par.first.first=i;
                    par.first.second=j;
                    par.second=tam;
                    vec.push_back(par);
                    for(int p=i-tam;p<=i+tam;p++)mataux[p][j]=true;
                    for(int p=j-tam;p<=j+tam;p++)mataux[i][p]=true;
                }
            }
        }
    }
    for(int i=1;i<=N;i++){
        for(int j=1;j<=M;j++){
            if(mat[i][j]=='*'){
                if(mataux[i][j]==false){
                    cout<<-1;
                    return 0;
                }
            }
        }
    }
    int t=vec.size();
    cout<<t<<"\n";
    for(int i=0;i<t;i++){
        cout<<vec[i].first.first<<" "<<vec[i].first.second<<" "<<vec[i].second<<"\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
char mat[1004][1004];
bool mataux[1004][1004];
pair<pair<int,int>,int>  par;
vector<pair<pair<int,int> ,int>  > vec;
int main(){
    int N,M;
    cin>>N>>M;
    for(int i=1;i<=N;i++){
        for(int j=1;j<=M;j++){
            cin>>mat[i][j];
        }
    }

    for(int i=1;i<=N;i++){
        for(int j=1;j<=M;j++){
            if(mat[i][j]=='*'){

                int tam=0;
                bool aux=true;
                for(tam=0;tam<101;tam++){
                    aux=true;
                    int p=i-tam;
                    if(mat[p][j]!='*')aux=false;
                    p=i+tam;
                    if(mat[p][j]!='*')aux=false;
                    p=j-tam;
                    if(mat[i][p]!='*')aux=false;
                    p=j+tam;
                    if(mat[i][p]!='*')aux=false;
                    if(aux==false)break;
                    ///tam es el primer tamaño que falla
                }
                tam--;
                if(tam>0){
                    par.first.first=i;
                    par.first.second=j;
                    par.second=tam;
                    vec.push_back(par);
                    for(int p=i-tam;p<=i+tam;p++)mataux[p][j]=true;
                    for(int p=j-tam;p<=j+tam;p++)mataux[i][p]=true;
                }
            }
        }
    }
    for(int i=1;i<=N;i++){
        for(int j=1;j<=M;j++){
            if(mat[i][j]=='*'){
                if(mataux[i][j]==false){
                    cout<<-1;
                    return 0;
                }
            }
        }
    }
    int t=vec.size();
    cout<<t<<"\n";
    for(int i=0;i<t;i++){
        cout<<vec[i].first.first<<" "<<vec[i].first.second<<" "<<vec[i].second<<"\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
char mat[1004][1004];
bool mataux[1004][1004];
pair<pair<int,int>,int>  par;
vector<pair<pair<int,int> ,int>  > vec;
int main(){
    int N,M;
    cin>>N>>M;
    for(int i=1;i<=N;i++){
        for(int j=1;j<=M;j++){
            cin>>mat[i][j];
        }
    }

    for(int i=1;i<=N;i++){
        for(int j=1;j<=M;j++){
            if(mat[i][j]=='*'){

                int tam=0;
                bool aux=true;
                for(tam=0;tam<1001;tam++){
                    aux=true;
                    int p=i-tam;
                    if(mat[p][j]!='*')aux=false;
                    p=i+tam;
                    if(mat[p][j]!='*')aux=false;
                    p=j-tam;
                    if(mat[i][p]!='*')aux=false;
                    p=j+tam;
                    if(mat[i][p]!='*')aux=false;
                    if(aux==false)break;
                    ///tam es el primer tamaño que falla
                }
                tam--;
                if(tam>0){
                    par.first.first=i;
                    par.first.second=j;
                    par.second=tam;
                    vec.push_back(par);
                    for(int p=i-tam;p<=i+tam;p++)mataux[p][j]=true;
                    for(int p=j-tam;p<=j+tam;p++)mataux[i][p]=true;
                }
            }
        }
    }
    for(int i=1;i<=N;i++){
        for(int j=1;j<=M;j++){
            if(mat[i][j]=='*'){
                if(mataux[i][j]==false){
                    cout<<-1;
                    return 0;
                }
            }
        }
    }
    int t=vec.size();
    cout<<t<<"\n";
    for(int i=0;i<t;i++){
        cout<<vec[i].first.first<<" "<<vec[i].first.second<<" "<<vec[i].second<<"\n";
    }
}


#include <bits/stdc++.h>

#define int long long
#define mod 1000000007
#define MAX 1000010

using namespace std;

int a[1010][1010][4];

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n,m;
    cin >> n >> m;

    string s[110];

    for(int i=0;i<n;i++)
        cin >> s[i];

    for(int i=1;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(s[i][j] == '*' && s[i-1][j] == '*')
                a[i][j][0] = a[i-1][j][0] + 1;
        }
    }

    for(int i=n-2;i>=0;i--)
    {
        for(int j=0;j<m;j++)
        {
            if(s[i][j] == '*' && s[i+1][j] == '*')
                a[i][j][1] = a[i+1][j][1] + 1;
        }
    }

    for(int i=1;i<m;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(s[j][i] == '*' && s[j][i-1] == '*')
                a[j][i][2] = a[j][i-1][2] + 1;
        }
    }

    for(int i=m-2;i>=0;i--)
    {
        for(int j=0;j<n;j++)
        {
            if(s[j][i] == '*' && s[j][i+1] == '*')
                a[j][i][3] = a[j][i+1][3] + 1;
        }
    }

    vector <pair<pair<int,int>,int> > v;

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(s[i][j] == '*')
            {
                int cnt = min(min(a[i][j][0],a[i][j][1]),min(a[i][j][2],a[i][j][3]));

                if(cnt > 0)
                    v.push_back({{i,j},cnt});
            }
        }
    }

    string s1[110];

    for(int i=0;i<n;i++)
        s1[i] = string(m,'.');

    for(auto i:v)
    {
        s1[i.first.first][i.first.second] = '*';

        int cnt = i.second;

        for(int j=i.first.first+1; j<n && cnt--; j++)
            s1[j][i.first.second] = '*';

        cnt = i.second;

        for(int j=i.first.first-1; j>=0 && cnt--; j--)
            s1[j][i.first.second] = '*';

        cnt = i.second;

        for(int j=i.first.second+1; j<m && cnt--; j++)
            s1[i.first.first][j] = '*';

        cnt = i.second;

        for(int j=i.first.second-1; j>=0 && cnt--; j--)
            s1[i.first.first][j] = '*';
    }

    for(int i=0;i<n;i++)
    {
        if(s[i] != s1[i])
        {
            cout << -1 << endl;
            return 0;
        }
    }

    cout << v.size() << endl;
    for(auto i:v)
        cout << i.first.first+1 << " " << i.first.second+1 << " " << i.second << endl;
}


#include <bits/stdc++.h>

#define int long long
#define mod 1000000007
#define MAX 1000010

using namespace std;

int a[1010][1010][4];

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n,m;
    cin >> n >> m;

    string s[1010];

    for(int i=0;i<n;i++)
        cin >> s[i];

    for(int i=1;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(s[i][j] == '*' && s[i-1][j] == '*')
                a[i][j][0] = a[i-1][j][0] + 1;
        }
    }

    for(int i=n-2;i>=0;i--)
    {
        for(int j=0;j<m;j++)
        {
            if(s[i][j] == '*' && s[i+1][j] == '*')
                a[i][j][1] = a[i+1][j][1] + 1;
        }
    }

    for(int i=1;i<m;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(s[j][i] == '*' && s[j][i-1] == '*')
                a[j][i][2] = a[j][i-1][2] + 1;
        }
    }

    for(int i=m-2;i>=0;i--)
    {
        for(int j=0;j<n;j++)
        {
            if(s[j][i] == '*' && s[j][i+1] == '*')
                a[j][i][3] = a[j][i+1][3] + 1;
        }
    }

    vector <pair<pair<int,int>,int> > v;

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(s[i][j] == '*')
            {
                int cnt = min(min(a[i][j][0],a[i][j][1]),min(a[i][j][2],a[i][j][3]));

                if(cnt > 0)
                    v.push_back({{i,j},cnt});
            }
        }
    }

    string s1[1010];

    for(int i=0;i<n;i++)
        s1[i] = string(m,'.');

    for(auto i:v)
    {
        s1[i.first.first][i.first.second] = '*';

        int cnt = i.second;

        for(int j=i.first.first+1; j<n && cnt--; j++)
            s1[j][i.first.second] = '*';

        cnt = i.second;

        for(int j=i.first.first-1; j>=0 && cnt--; j--)
            s1[j][i.first.second] = '*';

        cnt = i.second;

        for(int j=i.first.second+1; j<m && cnt--; j++)
            s1[i.first.first][j] = '*';

        cnt = i.second;

        for(int j=i.first.second-1; j>=0 && cnt--; j--)
            s1[i.first.first][j] = '*';
    }

    for(int i=0;i<n;i++)
    {
        if(s[i] != s1[i])
        {
            cout << -1 << endl;
            return 0;
        }
    }

    cout << v.size() << endl;
    for(auto i:v)
        cout << i.first.first+1 << " " << i.first.second+1 << " " << i.second << endl;
}