#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 1e2 + 10;
char matrix[MAX_N][MAX_N] = { '.' };
bool used[MAX_N][MAX_N] = { false };

int main () {
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    int N, M, cnt = 0;
    scanf("%d%d", &N, &M);
    for(int i = 0; i < N; i += 1) {
        for(int j = 0; j < M; j += 1) {
            scanf(" %c", &matrix[i][j]);
        }
    }
    vector < pair < pair <int, int>, int> > ans;
//    for(int rep = 0; rep < 100; rep += 1) {
        for(int i = 1; i < N - 1; i += 1) {
            for(int j = 1; j < M - 1; j += 1) {
                if(matrix[i][j] == '*' && matrix[i - 1][j] == '*' && matrix[i + 1][j] == '*' && matrix[i][j + 1] == '*' && matrix[i][j - 1] == '*') {
                    int cntLeft = 0, cntRight = 0, cntTop = 0, cntBot = 0;
                    int ii = i + 1, jj = j + 1;
                    while(ii < N && matrix[ii][j] == '*') {
                        cntRight += 1;
                        ii += 1;
                    }
                    ii = i - 1;
                    while(ii >= 0 && matrix[ii][j] == '*') {
                        cntLeft += 1;
                        ii -= 1;
                    }
                    while(jj < M && matrix[i][jj] == '*') {
                        cntBot += 1;
                        jj += 1;
                    }
                    jj = j - 1;
                    while(jj >= 0 && matrix[i][jj] == '*') {
                        cntTop += 1;
                        jj -= 1;
                    }
                    int cnt1 = min(min(cntRight, cntLeft), min(cntTop, cntBot));
                    if(cnt1 >= 1) {
                        ii = i + 1, jj = j + 1;
                        ans.push_back({{i + 1, j + 1}, {cnt1}});
                        used[i][j] = true;
                        cnt += 1;
                        int currCnt = cnt1;
                        while(ii < N && matrix[ii][j] == '*' && currCnt != 0) {
                            used[ii][j] = true;
                            ii += 1;
                            currCnt -= 1;
                        }
                        ii = i - 1;
                        currCnt = cnt1;
                        while(ii >= 0 && matrix[ii][j] == '*' && currCnt != 0) {
                            used[ii][j] = true;
                            ii -= 1;
                            currCnt -= 1;
                        }
                        currCnt = cnt1;
                        while(jj < M && matrix[i][jj] == '*' && currCnt != 0) {
                            used[i][jj] = true;
                            jj += 1;
                            currCnt -= 1;
                        }
                        jj = j - 1;
                        currCnt = cnt1;
                        while(jj >= 0 && matrix[i][jj] == '*' && currCnt != 0) {
                            used[i][jj] = true;
                            jj -= 1;
                            currCnt -= 1;
                        }
                    }
                }
            }
        }
//    }
    for(int i = 0; i < N; i += 1) {
        for(int j = 0; j < M; j += 1) {
            if(matrix[i][j] == '*' && !used[i][j]) {
                printf("-1\n");
                return 0;
            }
        }
    }
    printf("%d\n", cnt);
    for(int i = 0; i < cnt; i += 1) {
        printf("%d %d %d\n", ans[i].first.first, ans[i].first.second, ans[i].second);
    }
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long  ll;
typedef pair<int, int> pii;

char grid[1000][1000];
bool vis[1000][1000];
int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    //ifstream cin("hack2.txt");
    memset(vis, false, sizeof(vis));
    int n, m; cin>>n>>m;
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            cin>>grid[i][j];
        }
    }
    vector<pair<pii, int>> ans;
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            if(grid[i][j]=='.')continue;
            int x1 = j, x2 = j, y1 = i, y2 = i;
            int siz = -1;
            while(x1>=0&&x2<m&&y1>=0&&y2<n&&
                  grid[i][x1]=='*'&&grid[i][x2]=='*'&&grid[y1][j]=='*'&&grid[y2][j]=='*'){
                siz++;
                if(siz>=1){
                    vis[i][x1]=true;
                    vis[i][x2]=true;
                    vis[y1][j]=true;
                    vis[y2][j]=true;
                }
                x1--; x2++; y1--; y2++;
              }
            //cout<<i+1<<' '<<j+1<<' '<<siz<<'\n';
            if(siz>=1){
                vis[i][j]=true;
                ans.push_back({{i+1, j+1},siz});
            }
        }
    }
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            if(grid[i][j]=='*'&&!vis[i][j]){
                cout<<-1;
                return 0;
            }
        }
    }
    cout<<ans.size()<<endl;
    for(auto i:ans)cout<<i.first.first<<' '<<i.first.second<<' '<<i.second<<'\n';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 1e4 + 10;
char matrix[MAX_N][MAX_N] = { '.' };
bool used[MAX_N][MAX_N] = { false };

int main () {
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    int N, M, cnt = 0;
    scanf("%d%d", &N, &M);
    for(int i = 0; i < N; i += 1) {
        for(int j = 0; j < M; j += 1) {
            scanf(" %c", &matrix[i][j]);
        }
    }
    vector < pair < pair <int, int>, int> > ans;
//    for(int rep = 0; rep < 100; rep += 1) {
        for(int i = 1; i < N - 1; i += 1) {
            for(int j = 1; j < M - 1; j += 1) {
                if(matrix[i][j] == '*' && matrix[i - 1][j] == '*' && matrix[i + 1][j] == '*' && matrix[i][j + 1] == '*' && matrix[i][j - 1] == '*') {
                    int cntLeft = 0, cntRight = 0, cntTop = 0, cntBot = 0;
                    int ii = i + 1, jj = j + 1;
                    while(ii < N && matrix[ii][j] == '*') {
                        cntRight += 1;
                        ii += 1;
                    }
                    ii = i - 1;
                    while(ii >= 0 && matrix[ii][j] == '*') {
                        cntLeft += 1;
                        ii -= 1;
                    }
                    while(jj < M && matrix[i][jj] == '*') {
                        cntBot += 1;
                        jj += 1;
                    }
                    jj = j - 1;
                    while(jj >= 0 && matrix[i][jj] == '*') {
                        cntTop += 1;
                        jj -= 1;
                    }
                    int cnt1 = min(min(cntRight, cntLeft), min(cntTop, cntBot));
                    if(cnt1 >= 1) {
                        ii = i + 1, jj = j + 1;
                        ans.push_back({{i + 1, j + 1}, {cnt1}});
                        used[i][j] = true;
                        cnt += 1;
                        int currCnt = cnt1;
                        while(ii < N && matrix[ii][j] == '*' && currCnt != 0) {
                            used[ii][j] = true;
                            ii += 1;
                            currCnt -= 1;
                        }
                        ii = i - 1;
                        currCnt = cnt1;
                        while(ii >= 0 && matrix[ii][j] == '*' && currCnt != 0) {
                            used[ii][j] = true;
                            ii -= 1;
                            currCnt -= 1;
                        }
                        currCnt = cnt1;
                        while(jj < M && matrix[i][jj] == '*' && currCnt != 0) {
                            used[i][jj] = true;
                            jj += 1;
                            currCnt -= 1;
                        }
                        jj = j - 1;
                        currCnt = cnt1;
                        while(jj >= 0 && matrix[i][jj] == '*' && currCnt != 0) {
                            used[i][jj] = true;
                            jj -= 1;
                            currCnt -= 1;
                        }
                    }
                }
            }
        }
//    }
    for(int i = 0; i < N; i += 1) {
        for(int j = 0; j < M; j += 1) {
            if(matrix[i][j] == '*' && !used[i][j]) {
                printf("-1\n");
                return 0;
            }
        }
    }
    printf("%d\n", cnt);
    for(int i = 0; i < cnt; i += 1) {
        printf("%d %d %d\n", ans[i].first.first, ans[i].first.second, ans[i].second);
    }
	return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define forn(i, s, n)  for(int i=(int)s; i<int(n); i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define pll pair<long long int, long long int>
#define pii pair<int, int>
#define pss pair<string, string>
#define ull unsigned long long int
#define lld long double
#define F first
#define S second
#define PI 3.141592653589793238
#define prec(n) fixed<<setprecision(n)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define itsval(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); itval(_it, args); }
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

void itval(istream_iterator<string> it) {}
template<typename T, typename... Args>
void itval(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
itval(++it, args...);
}
const ll MOD= 1e+9+7;
template <typename T>
inline void print(T x){cout<<x<<"\n";}
template <typename T>
inline void printvec(T x){for(auto a:x) cout<<a<<' '; cout<<'\n';}
// -----------------------------------------------------------------------

struct custom{
    bool operator()(const pii &p1, const pii &p2)const{
                if(p1.F==p2.F)
                {
                    return true;
                }
                return p1.F>p2.F;
        }
};

// Calculate a^b % MOD -------------------------------------------------
ll get_pow(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b & 1) res = (res*a)%MOD;
        a = (a*a)%MOD;
        b >>= 1;
    }
    return res;
}
// ---------------------------------------------------------------------
const ll N = 2e5+10, inf=4e18;

void solve()
{
    int n,m;
    cin>>n>>m;
    std::vector<string> v(n);
    forn(i,0,n)
    cin>>v[i];
    bool used[n][m], have[n][m];
    forn(i,0,n)
    {
        forn(j,0,m)
        {
            have[i][j]=0;
            used[i][j]=0;
            if(v[i][j]=='*')
            {
                have[i][j]=1;
            }
        }
    }
    std::vector<pair<pii, int>> ans, rws, cls;
    std::vector<std::vector<int>> rpref(n);
    std::vector<std::vector<int>> cpref(m);
    forn(i,0,n)
    {
        rpref[i].resize(m);
        forn(j,0,m)
        {
            rpref[i][j]=int(v[i][j]!='*');
            if(j>0)
                rpref[i][j]+=rpref[i][j-1];
        }
    }
    forn(j,0,m)
    {
        cpref[j].resize(n);
        forn(i,0,n)
        {
            cpref[j][i]=int(v[i][j]!='*');
            if(i>0)
                cpref[j][i]+=cpref[j][i-1];
        }
    }
    // forn(i,0,n)
    // {
    //     forn(j,0,m)
    //     cout<<rpref[i][j]<<' ';
    //     cout<<"\n";

    // }
    forn(i,1,n-1)
    {
        forn(j,1,m-1)
        {
            if(v[i][j]=='*' && v[i][j-1]=='*' && v[i+1][j]=='*' && v[i-1][j]=='*' && v[i][j+1]=='*')
            {
                auto l = (rpref[i].begin()+j) - lower_bound(rpref[i].begin(), rpref[i].begin()+j, rpref[i][j]);
                auto r = upper_bound(rpref[i].begin()+j+1, rpref[i].end(), rpref[i][j]+1)-(rpref[i].begin()+j+1);
                auto up = (cpref[j].begin()+i) - lower_bound(cpref[j].begin(), cpref[j].begin()+i, cpref[j][i]);
                auto d = upper_bound(cpref[j].begin()+i+1, cpref[j].end(), cpref[j][i]+1)-(cpref[j].begin()+i+1);

                l--;up--;r--;d--;
                if(rpref[i][j]==0)
                    l=j;
                if(cpref[j][i]==0)
                    up=i;
                if(rpref[i][j]==rpref[i].back())
                    r=m-j;
                if(cpref[j][i]==cpref[j].back())
                    d=n-i;
                int lo = min(min(l,r), min(up, d));
               // itsval(i,j,l,r,up,d);
                used[i][j]=1;
                rws.pb({{i-lo, i+lo}, j});
                cls.pb({{j-lo, j+lo}, i});
                ans.pb({{i,j}, lo});
            }
        }
    }
    for(auto p:rws)
    {
        forn(i,p.F.F, p.F.S+1)
        used[i][p.S]=1;
    }
    for(auto p:cls)
    {
        forn(i,p.F.F, p.F.S+1)
        used[p.S][i]=1;
    }
    forn(i,0,n)
    {
        forn(j,0,m)
        {
            if(have[i][j]!=used[i][j])
            {
                cout<<"-1\n";
                return;
            }
        }
    }
    cout<<ans.size()<<'\n';
    for(auto p:ans)
        cout<<p.F.F+1<<' '<<p.F.S+1<<' '<<p.S<<'\n';

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test=1;
    //cin>>test;
    clock_t z=clock();
    forn(tes, 0, test)
    {
        solve();
    }
    debug("Total Time:%.4f\n",(double)(clock()-z)/CLOCKS_PER_SEC);
    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define forn(i, s, n)  for(int i=(int)s; i<int(n); i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define pll pair<long long int, long long int>
#define pii pair<int, int>
#define pss pair<string, string>
#define ull unsigned long long int
#define lld long double
#define F first
#define S second
#define PI 3.141592653589793238
#define prec(n) fixed<<setprecision(n)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define itsval(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); itval(_it, args); }
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

void itval(istream_iterator<string> it) {}
template<typename T, typename... Args>
void itval(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
itval(++it, args...);
}
const ll MOD= 1e+9+7;
template <typename T>
inline void print(T x){cout<<x<<"\n";}
template <typename T>
inline void printvec(T x){for(auto a:x) cout<<a<<' '; cout<<'\n';}
// -----------------------------------------------------------------------

struct custom{
    bool operator()(const pii &p1, const pii &p2)const{
                if(p1.F==p2.F)
                {
                    return true;
                }
                return p1.F>p2.F;
        }
};

// Calculate a^b % MOD -------------------------------------------------
ll get_pow(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b & 1) res = (res*a)%MOD;
        a = (a*a)%MOD;
        b >>= 1;
    }
    return res;
}
// ---------------------------------------------------------------------
const ll N = 2e5+10, inf=4e18;

void solve()
{
    int n,m;
    cin>>n>>m;
    std::vector<string> v(n);
    forn(i,0,n)
    cin>>v[i];
    bool used[n][m], have[n][m];
    forn(i,0,n)
    {
        forn(j,0,m)
        {
            have[i][j]=0;
            used[i][j]=0;
            if(v[i][j]=='*')
            {
                have[i][j]=1;
            }
        }
    }
    std::vector<pair<pii, int>> ans, rws, cls;
    std::vector<std::vector<int>> rpref(n);
    std::vector<std::vector<int>> cpref(m);
    forn(i,0,n)
    {
        rpref[i].resize(m);
        forn(j,0,m)
        {
            rpref[i][j]=int(v[i][j]!='*');
            if(j>0)
                rpref[i][j]+=rpref[i][j-1];
        }
    }
    forn(j,0,m)
    {
        cpref[j].resize(n);
        forn(i,0,n)
        {
            cpref[j][i]=int(v[i][j]!='*');
            if(i>0)
                cpref[j][i]+=cpref[j][i-1];
        }
    }
    // forn(i,0,n)
    // {
    //     forn(j,0,m)
    //     cout<<rpref[i][j]<<' ';
    //     cout<<"\n";

    // }
    forn(i,1,n-1)
    {
        forn(j,1,m-1)
        {
            if(v[i][j]=='*' && v[i][j-1]=='*' && v[i+1][j]=='*' && v[i-1][j]=='*' && v[i][j+1]=='*')
            {
                auto l = lower_bound(rpref[i].begin(), rpref[i].end(), rpref[i][j]) - rpref[i].begin();
                auto r =  upper_bound(rpref[i].begin(), rpref[i].end(), rpref[i][j])- rpref[i].begin();
                auto up = lower_bound(cpref[j].begin(), cpref[j].end(), cpref[j][i]) - cpref[j].begin();
                auto d = upper_bound(cpref[j].begin(), cpref[j].end(), cpref[j][i])- cpref[j].begin();

                l = j-l-1;
                r = r-j-1;
                up = i-up-1;
                d = d-i-1;
                if(rpref[i][j]==0)
                    l=j;
                if(cpref[j][i]==0)
                    up=i;
                if(rpref[i][j]==rpref[i].back())
                    r=m-j;
                if(cpref[j][i]==cpref[j].back())
                    d=n-i;
                int lo = min(min(l,r), min(up, d));
               // itsval(i,j,l,r,up,d);
                used[i][j]=1;
                rws.pb({{i-lo, i+lo}, j});
                cls.pb({{j-lo, j+lo}, i});
                ans.pb({{i,j}, lo});
            }
        }
    }
    for(auto p:rws)
    {
        forn(i,p.F.F, p.F.S+1)
        used[i][p.S]=1;
    }
    for(auto p:cls)
    {
        forn(i,p.F.F, p.F.S+1)
        used[p.S][i]=1;
    }
    forn(i,0,n)
    {
        forn(j,0,m)
        {
            if(have[i][j]!=used[i][j])
            {
                cout<<"-1\n";
                return;
            }
        }
    }
    cout<<ans.size()<<'\n';
    for(auto p:ans)
        cout<<p.F.F+1<<' '<<p.F.S+1<<' '<<p.S<<'\n';

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test=1;
    //cin>>test;
    clock_t z=clock();
    forn(tes, 0, test)
    {
        solve();
    }
    debug("Total Time:%.4f\n",(double)(clock()-z)/CLOCKS_PER_SEC);
    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define forn(i, s, n)  for(int i=(int)s; i<int(n); i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define pll pair<long long int, long long int>
#define pii pair<int, int>
#define pss pair<string, string>
#define ull unsigned long long int
#define lld long double
#define F first
#define S second
#define PI 3.141592653589793238
#define prec(n) fixed<<setprecision(n)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define itsval(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); itval(_it, args); }
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

void itval(istream_iterator<string> it) {}
template<typename T, typename... Args>
void itval(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
itval(++it, args...);
}
const ll MOD= 1e+9+7;
template <typename T>
inline void print(T x){cout<<x<<"\n";}
template <typename T>
inline void printvec(T x){for(auto a:x) cout<<a<<' '; cout<<'\n';}
// -----------------------------------------------------------------------

struct custom{
    bool operator()(const pii &p1, const pii &p2)const{
                if(p1.F==p2.F)
                {
                    return true;
                }
                return p1.F>p2.F;
        }
};

// Calculate a^b % MOD -------------------------------------------------
ll get_pow(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b & 1) res = (res*a)%MOD;
        a = (a*a)%MOD;
        b >>= 1;
    }
    return res;
}
// ---------------------------------------------------------------------
const ll N = 2e5+10, inf=4e18;

void solve()
{
    int n,m;
    cin>>n>>m;
    std::vector<string> v(n);
    forn(i,0,n)
    cin>>v[i];
    bool used[n][m], have[n][m];
    forn(i,0,n)
    {
        forn(j,0,m)
        {
            have[i][j]=0;
            used[i][j]=0;
            if(v[i][j]=='*')
            {
                have[i][j]=1;
            }
        }
    }
    std::vector<pair<pii, int>> ans, rws, cls;

    forn(i,1,n-1)
    {
        forn(j,1,m-1)
        {
            if(v[i][j]=='*' && v[i][j-1]=='*' && v[i+1][j]=='*' && v[i-1][j]=='*' && v[i][j+1]=='*')
            {
                int r=min(min(n-i-1,m-j-1), min(i,j)),lo=0;
                int hi=r+1;
                while(lo+1<hi){
                    int mid = (hi+lo)/2;
                    bool check=1;
                    forn(k,1,mid+1)
                    {
                        check&=(v[i+k][j]=='*');
                        check&=(v[i-k][j]=='*');
                        check&=(v[i][j+k]=='*');
                        check&=(v[i][j-k]=='*');
                    }
                    if(check)
                        lo=mid;
                    else
                        hi=mid;
                }
                //itsval(i,j, lo);
                used[i][j]=1;
                rws.pb({{i-lo, i+lo}, j});
                cls.pb({{j-lo, j+lo}, i});
                ans.pb({{i,j}, lo});
            }
        }
    }
    for(auto p:rws)
    {
        forn(i,p.F.F, p.F.S+1)
        used[i][p.S]=1;
    }
    for(auto p:cls)
    {
        forn(i,p.F.F, p.F.S+1)
        used[p.S][i]=1;
    }
    forn(i,0,n)
    {
        forn(j,0,m)
        {
            if(have[i][j]!=used[i][j])
            {
                cout<<"-1\n";
                return;
            }
        }
    }
    cout<<ans.size()<<'\n';
    for(auto p:ans)
        cout<<p.F.F+1<<' '<<p.F.S+1<<' '<<p.S<<'\n';

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test=1;
    //cin>>test;
    clock_t z=clock();
    forn(tes, 0, test)
    {
        solve();
    }
    debug("Total Time:%.4f\n",(double)(clock()-z)/CLOCKS_PER_SEC);
    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define forn(i, s, n)  for(int i=(int)s; i<int(n); i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define pll pair<long long int, long long int>
#define pii pair<int, int>
#define pss pair<string, string>
#define ull unsigned long long int
#define lld long double
#define F first
#define S second
#define PI 3.141592653589793238
#define prec(n) fixed<<setprecision(n)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define itsval(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); itval(_it, args); }
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

void itval(istream_iterator<string> it) {}
template<typename T, typename... Args>
void itval(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
itval(++it, args...);
}
const ll MOD= 1e+9+7;
template <typename T>
inline void print(T x){cout<<x<<"\n";}
template <typename T>
inline void printvec(T x){for(auto a:x) cout<<a<<' '; cout<<'\n';}
// -----------------------------------------------------------------------

struct custom{
    bool operator()(const pii &p1, const pii &p2)const{
                if(p1.F==p2.F)
                {
                    return true;
                }
                return p1.F>p2.F;
        }
};

// Calculate a^b % MOD -------------------------------------------------
ll get_pow(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b & 1) res = (res*a)%MOD;
        a = (a*a)%MOD;
        b >>= 1;
    }
    return res;
}
// ---------------------------------------------------------------------
const ll N = 2e5+10, inf=4e18;

void solve()
{
    int n,m;
    cin>>n>>m;
    std::vector<string> v(n);
    forn(i,0,n)
    cin>>v[i];
    bool used[n][m], have[n][m];
    forn(i,0,n)
    {
        forn(j,0,m)
        {
            have[i][j]=0;
            used[i][j]=0;
            if(v[i][j]=='*')
            {
                have[i][j]=1;
            }
        }
    }
    std::vector<pair<pii, int>> ans, rws, cls;
    std::vector<std::vector<int>> rpref(n);
    std::vector<std::vector<int>> cpref(m);
    forn(i,0,n)
    {
        rpref[i].resize(m);
        forn(j,0,m)
        {
            rpref[i][j]=int(v[i][j]!='*');
            if(j>0)
                rpref[i][j]+=rpref[i][j-1];
        }
    }
    forn(j,0,m)
    {
        cpref[j].resize(n);
        forn(i,0,n)
        {
            cpref[j][i]=int(v[i][j]!='*');
            if(i>0)
                cpref[j][i]+=cpref[j][i-1];
        }
    }
    // forn(i,0,n)
    // {
    //     forn(j,0,m)
    //     cout<<rpref[i][j]<<' ';
    //     cout<<"\n";

    // }
    forn(i,1,n-1)
    {
        forn(j,1,m-1)
        {
            if(v[i][j]=='*' && v[i][j-1]=='*' && v[i+1][j]=='*' && v[i-1][j]=='*' && v[i][j+1]=='*')
            {
                auto l = lower_bound(rpref[i].begin(), rpref[i].end(), rpref[i][j]) - rpref[i].begin();
                auto r =  upper_bound(rpref[i].begin(), rpref[i].end(), rpref[i][j])- rpref[i].begin();
                auto up = lower_bound(cpref[j].begin(), cpref[j].end(), cpref[j][i]) - cpref[j].begin();
                auto d = upper_bound(cpref[j].begin(), cpref[j].end(), cpref[j][i])- cpref[j].begin();

                l = j-l-1;
                r = r-j-1;
                up = i-up-1;
                d = d-i-1;
                if(rpref[i][j]==0)
                    l=j;
                if(cpref[j][i]==0)
                    up=i;
                if(rpref[i][j]==rpref[i].back())
                    r=m-j-1;
                if(cpref[j][i]==cpref[j].back())
                    d=n-i-1;
                int lo = min(min(l,r), min(up, d));
               // itsval(i,j,l,r,up,d);
                used[i][j]=1;
                rws.pb({{i-lo, i+lo}, j});
                cls.pb({{j-lo, j+lo}, i});
                ans.pb({{i,j}, lo});
            }
        }
    }
    for(auto p:rws)
    {
        forn(i,p.F.F, p.F.S+1)
        used[i][p.S]=1;
    }
    for(auto p:cls)
    {
        forn(i,p.F.F, p.F.S+1)
        used[p.S][i]=1;
    }
    forn(i,0,n)
    {
        forn(j,0,m)
        {
            if(have[i][j]!=used[i][j])
            {
                cout<<"-1\n";
                return;
            }
        }
    }
    cout<<ans.size()<<'\n';
    for(auto p:ans)
        cout<<p.F.F+1<<' '<<p.F.S+1<<' '<<p.S<<'\n';

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test=1;
    //cin>>test;
    clock_t z=clock();
    forn(tes, 0, test)
    {
        solve();
    }
    debug("Total Time:%.4f\n",(double)(clock()-z)/CLOCKS_PER_SEC);
    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define forn(i, s, n)  for(int i=(int)s; i<int(n); i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define pll pair<long long int, long long int>
#define pii pair<int, int>
#define pss pair<string, string>
#define ull unsigned long long int
#define lld long double
#define F first
#define S second
#define PI 3.141592653589793238
#define prec(n) fixed<<setprecision(n)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define itsval(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); itval(_it, args); }
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

void itval(istream_iterator<string> it) {}
template<typename T, typename... Args>
void itval(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
itval(++it, args...);
}
const ll MOD= 1e+9+7;
template <typename T>
inline void print(T x){cout<<x<<"\n";}
template <typename T>
inline void printvec(T x){for(auto a:x) cout<<a<<' '; cout<<'\n';}
// -----------------------------------------------------------------------

struct custom{
    bool operator()(const pii &p1, const pii &p2)const{
                if(p1.F==p2.F)
                {
                    return true;
                }
                return p1.F>p2.F;
        }
};

// Calculate a^b % MOD -------------------------------------------------
ll get_pow(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b & 1) res = (res*a)%MOD;
        a = (a*a)%MOD;
        b >>= 1;
    }
    return res;
}
// ---------------------------------------------------------------------
const ll N = 2e5+10, inf=4e18;

void solve()
{
    int n,m;
    cin>>n>>m;
    std::vector<string> v(n);
    forn(i,0,n)
    cin>>v[i];
    bool used[n][m], have[n][m];
    forn(i,0,n)
    {
        forn(j,0,m)
        {
            have[i][j]=0;
            used[i][j]=0;
            if(v[i][j]=='*')
            {
                have[i][j]=1;
            }
        }
    }
    std::vector<pair<pii, int>> ans, rws, cls;

    forn(i,1,n-1)
    {
        forn(j,1,m-1)
        {
            if(v[i][j]=='*' && v[i][j-1]=='*' && v[i+1][j]=='*' && v[i-1][j]=='*' && v[i][j+1]=='*')
            {
                int r=min(min(n-i,m-j), min(i,j)),lo=0;
                int hi=r+1;
                while(lo+1<hi){
                    int mid = (hi+lo)/2;
                    bool check=1;
                    forn(k,1,mid+1)
                    {
                        check&=(v[i+k][j]=='*');
                        check&=(v[i-k][j]=='*');
                        check&=(v[i][j+k]=='*');
                        check&=(v[i][j-k]=='*');
                    }
                    if(check)
                        lo=mid;
                    else
                        hi=mid;
                }
                used[i][j]=1;
                rws.pb({{i-lo, i+lo}, j});
                cls.pb({{j-lo, j+lo}, i});
                ans.pb({{i,j}, lo});
            }
        }
    }
    for(auto p:rws)
    {
        forn(i,p.F.F, p.F.S+1)
        used[i][p.S]=1;
    }
    for(auto p:cls)
    {
        forn(i,p.F.F, p.F.S+1)
        used[p.S][i]=1;
    }
    forn(i,0,n)
    {
        forn(j,0,m)
        {
            if(have[i][j]!=used[i][j])
            {
                cout<<"-1\n";
                return;
            }
        }
    }
    cout<<ans.size()<<'\n';
    for(auto p:ans)
        cout<<p.F.F+1<<' '<<p.F.S+1<<' '<<p.S<<'\n';

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test=1;
    //cin>>test;
    clock_t z=clock();
    forn(tes, 0, test)
    {
        solve();
    }
    debug("Total Time:%.4f\n",(double)(clock()-z)/CLOCKS_PER_SEC);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long  long ll;
const ll mod = 1000000007  , ar = 2000005;
char arr[1005][1005];
char vis[1005][1005];
int x,y;

int valid(int i , int j ) {
int co = 0,z = 0, z2 = 0 ,z3 = 0 ;
for(int w = i ; w >= 1 ;w-- ) {
    if(arr[w][j] =='*') co++;
    else break ;
}

if(co == 0)return -1;
for(int w = i ; w <= x; w++) {
    if(arr[w][j] =='*')z++;
    else break;
}
if(z == 0)return -1;
for(int w = j ; w >= 1; w--) {
    if(arr[i][w] =='*')z2++;
    else break;
}
if(z2 == 0)return -1;
for(int w = j ; w <=y; w++) {
    if(arr[i][w] =='*') z3++;
    else break;
}
if(z3 == 0) return -1;
int ans =  min(co,min(z,min(z2,z3)));
if(ans > 1) return ans ;
return -1 ;
}
void change(int i ,int j, int z  ) {
for(int w = i , k = z ; k > 0; w++, k--) vis[w][j] ='*' ;
for(int w = i , k = z ; k > 0; w--, k--) vis[w][j] ='*' ;
for(int w = j , k = z ; k > 0; w++, k--) vis[i][w] ='*' ;
for(int w = j , k = z ; k > 0; w--, k--) vis[i][w] ='*' ;
vis[i][j] ='*' ;

}
int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
      scanf("%d%d",&x,&y);
  vector<pair<int,pair<int,int> > > vec;
  memset(arr,'+',sizeof arr);
  memset(vis,'.',sizeof vis) ;
  for(int w = 1 ;w <= x; w++) {

    scanf("%s",arr[w]+1);
  }
  for(int i = 1 ;i <=x;i++ ) {
    for(int j = 1 ; j <= y; j++) {
        int z = valid(i,j);
        if(z != -1  && arr[i][j] =='*' ) {
            vec.push_back({z,{i,j}});
        }
    }
  }

  int res = 0 ;
  for(int w = 0 ; w< vec.size(); w++)  {
    change(vec[w].second.first,vec[w].second.second,vec[w].first);
  }
  for(int w = 1; w<=x; w++) {
    for(int i = 1 ;i <= y; i++) {
       if(arr[w][i] ==vis[w][i])res++;

    }
  }

    if(res == x*y) {
             printf("%d\n",vec.size()) ;
    for(int w = 0 ;w < vec.size(); w++)  {
            vec[w].first--;
         printf("%d %d %d\n",vec[w].second.first,vec[w].second.second,vec[w].first);
    }
    }
    else printf("-1");

        return 0;
    }


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int oo=0x3f3f3f3f ;
ll mod=1e9+7;
double eps=1e-9;
double pi=acos(-1);
using namespace std;
ll mini=1e18;
char arr[1001][1001];
int sumu[1001][1001],sumd[1001][1001],sumr[1001][1001],suml[1001][1001];
char vis[1005][1005];
void change(int i ,int j, int z  ) {
for(int w = i , k = z ; k > 0; w++, k--) vis[w][j] ='*' ;
for(int w = i , k = z ; k > 0; w--, k--) vis[w][j] ='*' ;
for(int w = j , k = z ; k > 0; w++, k--) vis[i][w] ='*' ;
for(int w = j , k = z ; k > 0; w--, k--) vis[i][w] ='*' ;
vis[i][j] ='*' ;

}
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n,m;
    cin >> n >> m ;
    memset(vis,'.',sizeof vis);
   for (int i=1;i<=n;i++)
   {

    for(int j =1 ; j<=m; j++) {
        cin >> arr[i][j];
    }
   }
  for (int i=1;i<=n;i++)
  {
      for (int j=1;j<=m;j++)
      {
          if (arr[i][j]=='*')
          {
              suml[i][j]=suml[i][j-1]+1;
              sumu[i][j]=sumu[i-1][j]+1;
          }
      }
  }

  for (int i=n;i>=1;i--)
  {
      for (int j=m;j>=1;j--)
      {
          if (arr[i][j]=='*')
          {
              sumd[i][j]=sumd[i+1][j]+1;
              sumr[i][j]=sumr[i][j+1]+1;

          }
      }
  }
  vector<pair<int,pair<int,int>>>ans;
   for (int i=1;i<=n;i++)
   {

       for (int j=1;j<=m;j++)
       {
        if (arr[i][j]=='*')
        {
            ll mini=min(min(sumd[i][j],sumu[i][j]),min(suml[i][j],sumr[i][j]));
            mini--;
            if(mini>0){ans.push_back({i,{j,mini}});}
        }
       }
   }
   for (int i=0;i<ans.size();i++)
   {
      change(ans[i].first, ans[i].second.first,ans[i].second.second+1);
   }
   int res = 0 ;
    for(int w = 1; w<=n; w++) {
    for(int i = 1 ;i <= m; i++) {
       if(arr[w][i] ==vis[w][i])res++;
   // cout << vis[w][i] ;
    }
    //cout << endl;
  }
  if(res == n*m) {
   cout << ans.size() << endl;
    for(int w = 0 ;w < ans.size(); w++) {
     cout << ans[w].first << " " << ans[w].second.first << " " << ans[w].second.second << endl;
    }
  }
  else cout << -1 << endl;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int oo=0x3f3f3f3f ;
ll mod=1e9+7;
double eps=1e-9;
double pi=acos(-1);
using namespace std;
ll mini=1e18;
char arr[1001][1001];
int sumu[1001][1001],sumd[1001][1001],sumr[1001][1001],suml[1001][1001];
char vis[1005][1005];
void change(int i ,int j, int z  ) {
for(int w = i , k = z ; k > 0; w++, k--) vis[w][j] ='*' ;
for(int w = i , k = z ; k > 0; w--, k--) vis[w][j] ='*' ;
for(int w = j , k = z ; k > 0; w++, k--) vis[i][w] ='*' ;
for(int w = j , k = z ; k > 0; w--, k--) vis[i][w] ='*' ;
vis[i][j] ='*' ;

}
int main()
{
    int n,m;
    cin>>n>>m;
    memset(vis,'.',sizeof vis);
   for (int i=1;i<=n;i++)
   {

       for (int j=1;j<=m;j++)
       {
           cin>>arr[i][j];
       }
   }
  for (int i=1;i<=n;i++)
  {
      for (int j=1;j<=m;j++)
      {
          if (arr[i][j]=='*')
          {
              suml[i][j]=suml[i][j-1]+1;
              sumu[i][j]=sumu[i-1][j]+1;
          }
      }
  }

  for (int i=n;i>=1;i--)
  {
      for (int j=m;j>=1;j--)
      {
          if (arr[i][j]=='*')
          {
              sumd[i][j]=sumd[i+1][j]+1;
              sumr[i][j]=sumr[i][j+1]+1;

          }
      }
  }
  vector<pair<ll,pair<ll,ll>>>ans;
   for (int i=1;i<=n;i++)
   {

       for (int j=1;j<=m;j++)
       {
        if (arr[i][j]=='*')
        {
            ll mini=min(min(sumd[i][j],sumu[i][j]),min(suml[i][j],sumr[i][j]));
            mini--;
            if(mini>0){ans.push_back({i,{j,mini}});}
        }
       }
   }
   for (int i=0;i<ans.size();i++)
   {
      change(ans[i].first, ans[i].second.first,ans[i].second.second+1);
   }
   int res = 0 ;
    for(int w = 1; w<=n; w++) {
    for(int i = 1 ;i <= m; i++) {
       if(arr[w][i] ==vis[w][i])res++;
   // cout << vis[w][i] ;
    }
    //cout << endl;
  }
  if(res == n*m) {
    cout << ans.size() << endl;
    for(int w = 0 ;w < ans.size(); w++) {
        cout << ans[w].first << " " << ans[w].second.first << " " << ans[w].second.second << endl;
    }
  }
  else cout << -1 << endl;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long  long ll;
const ll mod = 1000000007  , ar = 2000005;
char arr[1005][1005];
char vis[1005][1005];
int x,y;

int valid(int i , int j ) {
int co = 0,z = 0, z2 = 0 ,z3 = 0 ;
for(int w = i ; w >= 1 ;w-- ) {
    if(arr[w][j] =='*') co++;
    else break ;
}

if(co == 0)return -1;
for(int w = i ; w <= x; w++) {
    if(arr[w][j] =='*')z++;
    else break;
}
if(z == 0)return -1;
for(int w = j ; w >= 1; w--) {
    if(arr[i][w] =='*')z2++;
    else break;
}
if(z2 == 0)return -1;
for(int w = j ; w <=y; w++) {
    if(arr[i][w] =='*') z3++;
    else break;
}
if(z3 == 0) return -1;
int ans =  min(co,min(z,min(z2,z3)));
if(ans > 1) return ans ;
return -1 ;
}
void change(int i ,int j, int z  ) {
for(int w = i , k = z ; k > 0; w++, k--) vis[w][j] ='*' ;
for(int w = i , k = z ; k > 0; w--, k--) vis[w][j] ='*' ;
for(int w = j , k = z ; k > 0; w++, k--) vis[i][w] ='*' ;
for(int w = j , k = z ; k > 0; w--, k--) vis[i][w] ='*' ;
vis[i][j] ='*' ;

}
int main() {

      scanf("%d%d",&x,&y);
  vector<pair<int,pair<int,int> > > vec;
  memset(arr,'+',sizeof arr);
  memset(vis,'.',sizeof vis) ;
  for(int w = 1 ;w <= x; w++) {

    scanf("%s",arr[w]+1);
  }
  for(int i = 1 ;i <=x;i++ ) {
    for(int j = 1 ; j <= y; j++) {
        int z = valid(i,j);
        if(z != -1  && arr[i][j] =='*' ) {
            vec.push_back({z,{i,j}});
        }
    }
  }

  int res = 0 ;
  for(int w = 0 ; w< vec.size(); w++)  {
    change(vec[w].second.first,vec[w].second.second,vec[w].first);
  }
  for(int w = 1; w<=x; w++) {
    for(int i = 1 ;i <= y; i++) {
       if(arr[w][i] ==vis[w][i])res++;

    }
  }

    if(res == x*y) {
             printf("%d\n",vec.size()) ;
    for(int w = 0 ;w < vec.size(); w++)  {
            vec[w].first--;
         printf("%d %d %d\n",vec[w].second.first,vec[w].second.second,vec[w].first);
    }
    }
    else printf("-1");

        return 0;
    }


#include<bits/stdc++.h>
using namespace std;
typedef long  long ll;
const ll mod = 1000000007  , ar = 2000005;
char arr[105][105];
char vis[105][105];
int x,y;

int valid(int i , int j ) {
int co = 0,z = 0, z2 = 0 ,z3 = 0 ;
for(int w = i ; w >= 1 ;w-- ) {
    if(arr[w][j] =='*') co++;
    else break ;
}

if(co == 0)return -1;
for(int w = i ; w <= x; w++) {
    if(arr[w][j] =='*')z++;
    else break;
}
if(z == 0)return -1;
for(int w = j ; w >= 1; w--) {
    if(arr[i][w] =='*')z2++;
    else break;
}
if(z2 == 0)return -1;
for(int w = j ; w <=y; w++) {
    if(arr[i][w] =='*') z3++;
    else break;
}
if(z3 == 0) return -1;
int ans =  min(co,min(z,min(z2,z3)));
if(ans > 1) return ans ;
return -1 ;
}
void change(int i ,int j, int z  ) {
for(int w = i , k = z ; k > 0; w++, k--) vis[w][j] ='*' ;
for(int w = i , k = z ; k > 0; w--, k--) vis[w][j] ='*' ;
for(int w = j , k = z ; k > 0; w++, k--) vis[i][w] ='*' ;
for(int w = j , k = z ; k > 0; w--, k--) vis[i][w] ='*' ;
vis[i][j] ='*' ;

}
int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cin >> x >> y;
  vector<pair<int,pair<int,int> > > vec;
  memset(arr,'+',sizeof arr);
  memset(vis,'.',sizeof vis) ;
  for(int w = 1 ;w <= x; w++) {
    for(int i = 1; i <=y; i++) {
        cin >> arr[w][i];
    }
  }
  for(int i = 1 ;i <=x;i++ ) {
    for(int j = 1 ; j <= y; j++) {
        int z = valid(i,j);
        if(z != -1  && arr[i][j] =='*' ) {
            vec.push_back({z,{i,j}});
        }
    }
  }

  int res = 0 ;
  for(int w = 0 ; w< vec.size(); w++)  {
    change(vec[w].second.first,vec[w].second.second,vec[w].first);
  }
  for(int w = 1; w<=x; w++) {
    for(int i = 1 ;i <= y; i++) {
       if(arr[w][i] ==vis[w][i])res++;

    }
  }

    if(res == x*y) {
            cout << vec.size() << endl;
    for(int w = 0 ;w < vec.size(); w++)  {
        cout << vec[w].second.first << " " << vec[w].second.second << " " << vec[w].first-1 << endl;
    }
    }
    else cout << -1 <<endl;

        return 0;
    }


#include<bits/stdc++.h>
using namespace std;
typedef long  long ll;
const ll mod = 1000000007  , ar = 2000005;
char arr[1005][1005];
char vis[1005][1005];
int x,y;

int valid(int i , int j ) {
int co = 0,z = 0, z2 = 0 ,z3 = 0 ;
for(int w = i ; w >= 1 ;w-- ) {
    if(arr[w][j] =='*') co++;
    else break ;
}

if(co == 0)return -1;
for(int w = i ; w <= x; w++) {
    if(arr[w][j] =='*')z++;
    else break;
}
if(z == 0)return -1;
for(int w = j ; w >= 1; w--) {
    if(arr[i][w] =='*')z2++;
    else break;
}
if(z2 == 0)return -1;
for(int w = j ; w <=y; w++) {
    if(arr[i][w] =='*') z3++;
    else break;
}
if(z3 == 0) return -1;
int ans =  min(co,min(z,min(z2,z3)));
if(ans > 1) return ans ;
return -1 ;
}
void change(int i ,int j, int z  ) {
for(int w = i , k = z ; k > 0; w++, k--) vis[w][j] ='*' ;
for(int w = i , k = z ; k > 0; w--, k--) vis[w][j] ='*' ;
for(int w = j , k = z ; k > 0; w++, k--) vis[i][w] ='*' ;
for(int w = j , k = z ; k > 0; w--, k--) vis[i][w] ='*' ;
vis[i][j] ='*' ;

}
int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cin >> x >> y;
  vector<pair<int,pair<int,int> > > vec;
  memset(arr,'+',sizeof arr);
  memset(vis,'.',sizeof vis) ;
  for(int w = 1 ;w <= x; w++) {
    for(int i = 1; i <=y; i++) {
        cin >> arr[w][i];
    }
  }
  for(int i = 1 ;i <=x;i++ ) {
    for(int j = 1 ; j <= y; j++) {
        int z = valid(i,j);
        if(z != -1  && arr[i][j] =='*' ) {
            vec.push_back({z,{i,j}});
        }
    }
  }

  int res = 0 ;
  for(int w = 0 ; w< vec.size(); w++)  {
    change(vec[w].second.first,vec[w].second.second,vec[w].first);
  }
  for(int w = 1; w<=x; w++) {
    for(int i = 1 ;i <= y; i++) {
       if(arr[w][i] ==vis[w][i])res++;

    }
  }

    if(res == x*y) {
            cout << vec.size() << endl;
    for(int w = 0 ;w < vec.size(); w++)  {
        cout << vec[w].second.first << " " << vec[w].second.second << " " << vec[w].first-1 << endl;
    }
    }
    else cout << -1 <<endl;

        return 0;
    }


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int oo=0x3f3f3f3f ;
ll mod=1e9+7;
double eps=1e-9;
double pi=acos(-1);
using namespace std;
ll mini=1e18;
char arr[1001][1001];
int sumu[1001][1001],sumd[1001][1001],sumr[1001][1001],suml[1001][1001];
char vis[1005][1005];
void change(int i ,int j, int z  ) {
for(int w = i , k = z ; k > 0; w++, k--) vis[w][j] ='*' ;
for(int w = i , k = z ; k > 0; w--, k--) vis[w][j] ='*' ;
for(int w = j , k = z ; k > 0; w++, k--) vis[i][w] ='*' ;
for(int w = j , k = z ; k > 0; w--, k--) vis[i][w] ='*' ;
vis[i][j] ='*' ;

}
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    memset(vis,'.',sizeof vis);
   for (int i=1;i<=n;i++)
   {

    scanf("%s",arr[i]+1);
   }
  for (int i=1;i<=n;i++)
  {
      for (int j=1;j<=m;j++)
      {
          if (arr[i][j]=='*')
          {
              suml[i][j]=suml[i][j-1]+1;
              sumu[i][j]=sumu[i-1][j]+1;
          }
      }
  }

  for (int i=n;i>=1;i--)
  {
      for (int j=m;j>=1;j--)
      {
          if (arr[i][j]=='*')
          {
              sumd[i][j]=sumd[i+1][j]+1;
              sumr[i][j]=sumr[i][j+1]+1;

          }
      }
  }
  vector<pair<int,pair<int,int>>>ans;
   for (int i=1;i<=n;i++)
   {

       for (int j=1;j<=m;j++)
       {
        if (arr[i][j]=='*')
        {
            ll mini=min(min(sumd[i][j],sumu[i][j]),min(suml[i][j],sumr[i][j]));
            mini--;
            if(mini>0){ans.push_back({i,{j,mini}});}
        }
       }
   }
   for (int i=0;i<ans.size();i++)
   {
      change(ans[i].first, ans[i].second.first,ans[i].second.second+1);
   }
   int res = 0 ;
    for(int w = 1; w<=n; w++) {
    for(int i = 1 ;i <= m; i++) {
       if(arr[w][i] ==vis[w][i])res++;
   // cout << vis[w][i] ;
    }
    //cout << endl;
  }
  if(res == n*m) {
    printf("%d\n",ans.size()) ;
    for(int w = 0 ;w < ans.size(); w++) {
       printf("%d %d %d\n",ans[w].first,ans[w].second.first,ans[w].second.second);
    }
  }
  else printf("-1");
return 0;
}


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

const long long MOD = 1e9 + 7;
const int INF = 1e9;
const int MAXN = 1e3 + 1;

char s[MAXN][MAXN];
int a[MAXN][MAXN];

struct coor {
	int x, y, s;
};

void solve() {
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			cin >> s[i][j];

	vector <coor> vt;
	for (int i = 2; i <= n - 1; i++) {
		for (int j = 2; j <= m - 1; j++) {
			if (s[i][j] == '.')
				continue;
			int i1 = i - 1, i2 = i + 1, j1 = j - 1, j2 = j + 1;
			int cnt = 0;
			while (true) {
				if (i1 < 1 || i2 > n || j1 < 1 || j2 > m ||
					s[i][j1] != '*' || s[i][j2] != '*' || s[i1][j] != '*' || s[i2][j] != '*')
					break;
				a[i][j1] = a[i][j2] = a[i1][j] = a[i2][j] = 1;
				i1--, i2++, j1--, j2++;
				cnt++;
			}
			if (cnt != 0) {
				a[i][j] = 1;
				vt.push_back ({i, j, cnt});
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (a[i][j] == 0 && s[i][j] == '*') {
				cout << -1 << endl;
				return;
			}
		}
	}
	cout << vt.size() << endl;
	for (int i = 0; i < vt.size(); i++) {
		cout << vt[i].x << ' ' << vt[i].y << ' ' << vt[i].s << endl;
	}
}

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

	solve();
}


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

const long long MOD = 1e9 + 7;
const int INF = 1e9;
const int MAXN = 1e3 + 1;

char s[MAXN][MAXN];
int a[MAXN][MAXN];

struct coor {
	int x, y, s;
};

void solve() {
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			cin >> s[i][j];

	vector <coor> vt;
	for (int i1 = 2; i <= n - 1; i++) {
		for (int j = 2; j <= m - 1; j++) {
			if (s[i][j] == '.')
				continue;
			int i1 = i - 1, i2 = i + 1, j1 = j - 1, j2 = j + 1;
			int cnt = 0;
			while (true) {
				if (i1 < 1 || i2 > n || j1 < 1 || j2 > m ||
					s[i][j1] != '*' || s[i][j2] != '*' || s[i1][j] != '*' || s[i2][j] != '*')
					break;
				a[i][j1] = a[i][j2] = a[i1][j] = a[i2][j] = 1;
				i1--, i2++, j1--, j2++;
				cnt++;
			}
			if (cnt != 0) {
				a[i][j] = 1;
				vt.push_back ({i, j, cnt});
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (a[i][j] == 0 && s[i][j] == '*') {
				cout << -1 << endl;
				return;
			}
		}
	}
	cout << vt.size() << endl;
	for (int i = 0; i < vt.size(); i++) {
		cout << vt[i].x << ' ' << vt[i].y << ' ' << vt[i].s << endl;
	}
}

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

	solve();
}


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

const long long MOD = 1e9 + 7;
const int INF = 1e9;
const int MAXN = 1e3 + 1;

int n, m;

vector<string> draw(vector<pair<pair<int, int>, int> > ans) {
	vector<string> f (n, string (m, '.'));
	vector<vector<int> > strings (n, vector<int> (m));
	vector<vector<int> > columns (n, vector<int> (m));

	for (auto it : ans) {
		int x = it.first.first;
		int y = it.first.second;
		int len = it.second;
		strings[x - len][y]++;
		if (x + len + 1 < n)
			strings[x + len + 1][y]--;
		columns[x][y - len]++;
		if (y + len + 1 < m)
			columns[x][y + len + 1]--;
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (i > 0)
				strings[i][j] += strings[i - 1][j];
			if (j > 0)
				columns[i][j] += columns[i][j - 1];
			if (strings[i][j] > 0 || columns[i][j] > 0) {
				f[i][j] = '*';
			}
		}
	}

	return f;
}

void solve() {
	cin >> n >> m;
	vector<string> s (n);
	for (int i = 0; i < n; i++)
		cin >> s[i];

	vector<vector<int> > left (n, vector<int> (m));
	vector<vector<int> > up (n, vector<int> (m));
	vector<vector<int> > right (n, vector<int> (m));
	vector<vector<int> > down (n, vector<int> (m));

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

			if (i > 0) {
				if (s[i][j] == '.')
					up[i][j] = 0;
				else
					up[i][j] = up[i - 1][j] + 1;
			}
			else {
				up[i][j] = (s[i][j] != '.');
			}

			if (j > 0) {
				if (s[i][j] == '.')
					left[i][j] = 0;
				else
					left[i][j] = left[i][j - 1] + 1;
			}
			else {
				left[i][j] = (s[i][j] != '.');
			}
		}
	}

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

			if (i < n - 1) {
				if (s[i][j] == '.')
					down[i][j] = 0;
				else
					down[i][j] = down[i + 1][j] + 1;
			}
			else {
				down[i][j] = (s[i][j] != '.');
			}

			if (j < m - 1) {
				if (s[i][j] == '.')
					right[i][j] = 0;
				else
					right[i][j] = right[i][j + 1] + 1;
			}
			else {
				right[i][j] = (s[i][j] != '.');
			}

		}
	}

	vector<pair<pair<int, int>, int> > ans;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (s[i][j] == '*') {
				int len = min (min (left[i][j], up[i][j]), min (right[i][j], down[i][j])) - 1;
				if (len > 0) {
					ans.push_back({ {i, j}, len});
				}
			}
		}
	}

	if (draw(ans) != s) {
		cout << -1 << endl;
	}
	else {
		cout << ans.size() << endl;
		for (auto it : ans) {
			cout << it.first.first + 1 << ' ' << it.first.second + 1 << ' ' << it.second << endl;
		}
	}
}

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

	solve();
}


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

const long long MOD = 1e9 + 7;
const int INF = 1e9;
const int MAXN = 1e3 + 1;

char s[MAXN][MAXN];
int a[MAXN][MAXN];

struct coor {
	int x, y, s;
};

void solve() {
	int n, m;
	cin >> n >> m;
	int cnt1 = 0, cnt2 = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			cin >> s[i][j];
			if (s[i][j] == '*')
				cnt1++;
		}
	}

	vector <coor> vt;
	for (int i = 2; i <= n - 1; i++) {
		for (int j = 2; j <= m - 1; j++) {
			if (s[i][j] == '.')
				continue;
			int i1 = i - 1, i2 = i + 1, j1 = j - 1, j2 = j + 1;
			int cnt = 0;
			while (true) {
				if (i1 < 1 || i2 > n || j1 < 1 || j2 > m ||
					s[i][j1] != '*' || s[i][j2] != '*' || s[i1][j] != '*' || s[i2][j] != '*')
					break;
				if (a[i][j1] == 0)
					cnt2++;
				if (a[i][j2] == 0)
					cnt2++;
				if (a[i1][j] == 0)
					cnt2++;
				if (a[i2][j1] == 0)
					cnt2++;
				a[i][j1] = a[i][j2] = a[i1][j] = a[i2][j] = 1;
				i1--, i2++, j1--, j2++;
				cnt++;
			}
			if (cnt != 0) {
				a[i][j] = 1;
				vt.push_back ({i, j, cnt});
			}
			if (cnt2 == cnt1)
				break;
		}
		if (cnt2 == cnt1)
			break;
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (a[i][j] == 0 && s[i][j] == '*') {
				cout << -1 << endl;
				return;
			}
		}
	}
	cout << vt.size() << endl;
	for (int i = 0; i < vt.size(); i++) {
		cout << vt[i].x << ' ' << vt[i].y << ' ' << vt[i].s << endl;
	}
}

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

	solve();
}


#include<iostream>
#include<vector>
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <cctype>
#include <stack>
#include <list>
#include <queue>
#include <map>
#include <sstream>
#include <cmath>
#include <limits>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <bitset>
#include <utility>
#include <set>
#include <numeric>

//DOUBLE D UP
#define fast ios::sync_with_stdio(false);cin.tie(0);
#define ll long long
#define N 1005
#define pb push_back
#define F first
#define S second
#define pi pair<int,int>
#define pii pair<pi,int>
#define M (ll)998244353
#define ld long double
#define inf 20000000000
using namespace std;

int prer[N][N],prec[N][N],sufr[N][N],sufc[N][N],cnt1[N][N],cnt2[N][N],cnt[N][N],deg[N][N],n,m;

int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
string s[N];
bool check(int x,int y)
{
    return ((x>=0) && (x<n) && (y>=0) && (y<m) && (s[x][y]=='*'));
}
vector<pii> ans;
int main()
{
	//cout<<"hello world!"<<endl;

	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output2.txt","w",stdout);
    #endif
    fast
    int i,j,k;

    cin>>n>>m;

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

    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            int fl=1;
            for( k=0;k<4;k++)
            {
                if(!check(i+dx[k],j+dy[k]))
                {
                   fl=0;
                   break;
                }
            }
            if(fl)
                deg[i][j]=4;
        }
    }

    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            if(j==0)
                prer[i][j]=-1;
            else
                {
                    prer[i][j]=prer[i][j-1];
                    if(s[i][j-1]=='.')
                        prer[i][j]=j-1;
                }

        }
        for(j=m-1;j>=0;j--)
        {
            if(j==m-1)
                sufr[i][j]=m;
            else
                {
                    sufr[i][j]=sufr[i][j+1];
                    if(s[i][j+1]=='.')
                        sufr[i][j]=j+1;
                }

        }
    }
   // cout<<"*"<<endl;
    for(j=0;j<m;j++)
     {
       for(i=0;i<n;i++)
        {
            if(i==0)
                prec[i][j]=-1;
            else
                {
                    prec[i][j]=prec[i-1][j];
                    if(s[i-1][j]=='.')
                        prec[i][j]=i-1;
                }

        }
        for(i=n-1;i>=0;i--)
        {
            if(i==n-1)
                sufc[i][j]=n;
            else
                {
                    sufc[i][j]=sufc[i+1][j];
                    if(s[i+1][j]=='.')
                        sufc[i][j]=i+1;
                }

        }
    }
    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
        {
            if(deg[i][j]==4)
            {
                int x1=abs(j-prer[i][j]);
                int x2=abs(j-sufr[i][j]);
                int y1=abs(i-prec[i][j]);
                int y2=abs(i-sufc[i][j]);
                int z=min(min(x1,x2),min(y1,y2));
                if(z==1)
                    continue;
                ans.pb(pii(pi(i,j),z));

                cnt1[i][j-z+1]++;
                cnt1[i][min(1002,j+z)]--;

                cnt2[i-z+1][j]++;
                cnt2[min(1002,i+z)][j]--;

            }
        }

    for(i=0;i<n;i++)
    {
        int s=0;
        for(j=0;j<m;j++)
        {
            s+=cnt1[i][j];
            cnt[i][j]=s;
        }
    }
    for(i=0;i<m;i++)
    {
        int s=0;
        for(j=0;j<n;j++)
        {
            s+=cnt2[j][i];
            cnt[j][i]+=s;
        }
    }

    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
        {
            if(s[i][j]=='*' && !cnt[i][j])
            {
                cout<<-1;
                return 0;
            }
        }
        cout<<ans.size()<<endl;
    for(i=0;i<ans.size();i++)
        cout<<ans[i].F.F+1<<" "<<ans[i].F.S+1<<" "<<ans[i].S-1<<endl;
    return 0;

}


#include<iostream>
#include<vector>
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <cctype>
#include <stack>
#include <list>
#include <queue>
#include <map>
#include <sstream>
#include <cmath>
#include <limits>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <bitset>
#include <utility>
#include <set>
#include <numeric>

//DOUBLE D UP
#define fast ios::sync_with_stdio(false);cin.tie(0);
#define ll long long
#define N 1005
#define pb push_back
#define F first
#define S second
#define pi pair<int,int>
#define pii pair<pi,int>
#define M (ll)998244353
#define ld long double
#define inf 20000000000
using namespace std;

int prer[N][N],prec[N][N],sufr[N][N],sufc[N][N],cnt1[N][N],cnt2[N][N],cnt[N][N],deg[N][N],n,m;

int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
string s[N];
bool check(int x,int y)
{
    return ((x>=0) && (x<n) && (y>=0) && (y<m) && (s[x][y]=='*'));
}
vector<pii> ans;
int main()
{
	//cout<<"hello world!"<<endl;

	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output2.txt","w",stdout);
    #endif
    fast
    int i,j,k;

    cin>>n>>m;

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

    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            int fl=1;
            if(s[i][j]=='.')
                continue;
            for( k=0;k<4;k++)
            {
                if(!check(i+dx[k],j+dy[k]))
                {
                   fl=0;
                   break;
                }
            }
            if(fl)
                deg[i][j]=4;
        }
    }

    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            if(j==0)
                prer[i][j]=-1;
            else
                {
                    prer[i][j]=prer[i][j-1];
                    if(s[i][j-1]=='.')
                        prer[i][j]=j-1;
                }

        }
        for(j=m-1;j>=0;j--)
        {
            if(j==m-1)
                sufr[i][j]=m;
            else
                {
                    sufr[i][j]=sufr[i][j+1];
                    if(s[i][j+1]=='.')
                        sufr[i][j]=j+1;
                }

        }
    }
   // cout<<"*"<<endl;
    for(j=0;j<m;j++)
     {
       for(i=0;i<n;i++)
        {
            if(i==0)
                prec[i][j]=-1;
            else
                {
                    prec[i][j]=prec[i-1][j];
                    if(s[i-1][j]=='.')
                        prec[i][j]=i-1;
                }

        }
        for(i=n-1;i>=0;i--)
        {
            if(i==n-1)
                sufc[i][j]=n;
            else
                {
                    sufc[i][j]=sufc[i+1][j];
                    if(s[i+1][j]=='.')
                        sufc[i][j]=i+1;
                }

        }
    }
    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
        {
            if(deg[i][j]==4)
            {
                int x1=abs(j-prer[i][j]);
                int x2=abs(j-sufr[i][j]);
                int y1=abs(i-prec[i][j]);
                int y2=abs(i-sufc[i][j]);
                int z=min(min(x1,x2),min(y1,y2));
                if(z==1)
                    continue;
                ans.pb(pii(pi(i,j),z));

                cnt1[i][j-z+1]++;
                cnt1[i][min(1002,j+z)]--;

                cnt2[i-z+1][j]++;
                cnt2[min(1002,i+z)][j]--;

            }
        }

    for(i=0;i<n;i++)
    {
        int s=0;
        for(j=0;j<m;j++)
        {
            s+=cnt1[i][j];
            cnt[i][j]=s;
        }
    }
    for(i=0;i<m;i++)
    {
        int s=0;
        for(j=0;j<n;j++)
        {
            s+=cnt2[j][i];
            cnt[j][i]+=s;
        }
    }

    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
        {
            if(s[i][j]=='*' && !cnt[i][j])
            {
                cout<<-1;
                return 0;
            }
        }
        cout<<ans.size()<<endl;
    for(i=0;i<ans.size();i++)
        cout<<ans[i].F.F+1<<" "<<ans[i].F.S+1<<" "<<ans[i].S-1<<endl;
    return 0;

}


#include<iostream>
#include<vector>
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <cctype>
#include <stack>
#include <list>
#include <queue>
#include <map>
#include <sstream>
#include <cmath>
#include <limits>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <bitset>
#include <utility>
#include <set>
#include <numeric>

//DOUBLE D UP
#define fast ios::sync_with_stdio(false);cin.tie(0);
#define ll long long
#define N 1005
#define pb push_back
#define F first
#define S second
#define pi pair<int,int>
#define pii pair<pi,int>
#define M (ll)998244353
#define ld long double
#define inf 20000000000
using namespace std;

int prer[N][N],prec[N][N],sufr[N][N],sufc[N][N],cnt1[N][N],cnt2[N][N],cnt[N][N],deg[N][N],n,m;

int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
string s[N];
bool check(int x,int y)
{
    return ((x>=0) && (x<n) && (y>=0) && (y<m) && (s[x][y]=='*'));
}
vector<pii> ans;
int main()
{
	//cout<<"hello world!"<<endl;

	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output2.txt","w",stdout);
    #endif
    fast
    int i,j,k;

    cin>>n>>m;

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

    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            int fl=1;
            if(s[i][j]=='.')
                continue;
            for( k=0;k<4;k++)
            {
                if(!check(i+dx[k],j+dy[k]))
                {
                   fl=0;
                   break;
                }
            }
            if(fl)
                deg[i][j]=4;
        }
    }

    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            if(j==0)
                prer[i][j]=-1;
            else
                {
                    prer[i][j]=prer[i][j-1];
                    if(s[i][j-1]=='.')
                        prer[i][j]=j-1;
                }

        }
        for(j=m-1;j>=0;j--)
        {
            if(j==m-1)
                sufr[i][j]=m;
            else
                {
                    sufr[i][j]=sufr[i][j+1];
                    if(s[i][j+1]=='.')
                        sufr[i][j]=j+1;
                }

        }
    }
   // cout<<"*"<<endl;
    for(j=0;j<m;j++)
     {
       for(i=0;i<n;i++)
        {
            if(i==0)
                prec[i][j]=-1;
            else
                {
                    prec[i][j]=prec[i-1][j];
                    if(s[i-1][j]=='.')
                        prec[i][j]=i-1;
                }

        }
        for(i=n-1;i>=0;i--)
        {
            if(i==n-1)
                sufc[i][j]=n;
            else
                {
                    sufc[i][j]=sufc[i+1][j];
                    if(s[i+1][j]=='.')
                        sufc[i][j]=i+1;
                }

        }
    }
    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
        {
            if(deg[i][j]==4)
            {
                int x1=abs(j-prer[i][j]);
                int x2=abs(j-sufr[i][j]);
                int y1=abs(i-prec[i][j]);
                int y2=abs(i-sufc[i][j]);
                int z=min(min(x1,x2),min(y1,y2));
                if(z==1)
                    continue;
                ans.pb(pii(pi(i,j),z));

                cnt1[i][j-z+1]++;
                cnt1[i][min(1002,j+z)]--;

                cnt2[i-z+1][j]++;
                cnt2[min(1002,i+z)][j]--;

            }
        }

    for(i=0;i<n;i++)
    {
        int s=0;
        for(j=0;j<m;j++)
        {
            s+=cnt1[i][j];
            cnt[i][j]=s;
        }
    }
    for(i=0;i<m;i++)
    {
        int s=0;
        for(j=0;j<n;j++)
        {
            s+=cnt2[j][i];
            cnt[j][i]+=s;
        }
    }

    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
        {
            if(s[i][j]=='*' && !cnt[i][j])
            {
                cout<<-1;
                return 0;
            }
        }
        cout<<ans.size()<<endl;
    for(i=0;i<ans.size();i++)
        cout<<ans[i].F.F+1<<" "<<ans[i].F.S+1<<" "<<ans[i].S-1<<'\n';
    return 0;

}


#include<iostream>
#include<vector>
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <cctype>
#include <stack>
#include <list>
#include <queue>
#include <map>
#include <sstream>
#include <cmath>
#include <limits>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <bitset>
#include <utility>
#include <set>
#include <numeric>

//DOUBLE D UP
#define fast ios::sync_with_stdio(false);cin.tie(0);
#define ll long long
#define N 1005
#define pb push_back
#define F first
#define S second
#define pi pair<int,int>
#define pii pair<pi,int>
#define M (ll)998244353
#define ld long double
#define inf 20000000000
using namespace std;

int prer[N][N],prec[N][N],sufr[N][N],sufc[N][N],cnt1[N][N],cnt2[N][N],cnt[N][N],deg[N][N],n,m;

int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
string s[N];
bool check(int x,int y)
{
    return ((x>=0) && (x<n) && (y>=0) && (y<m) && (s[x][y]=='*'));
}
vector<pii> ans;
int main()
{
	//cout<<"hello world!"<<endl;

	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output2.txt","w",stdout);
    #endif
    fast
    int i,j,k;

    cin>>n>>m;

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

    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            int fl=1;
            for( k=0;k<4;k++)
            {
                if(!check(i+dx[k],j+dy[k]))
                {
                   fl=0;
                   break;
                }
            }
            if(fl)
                deg[i][j]=4;
        }
    }

    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            if(j==0)
                prer[i][j]=-1;
            else
                {
                    prer[i][j]=prer[i][j-1];
                    if(s[i][j-1]=='.')
                        prer[i][j]=j-1;
                }

        }
        for(j=m-1;j>=0;j--)
        {
            if(j==m-1)
                sufr[i][j]=m;
            else
                {
                    sufr[i][j]=sufr[i][j+1];
                    if(s[i][j+1]=='.')
                        sufr[i][j]=j+1;
                }

        }
    }
   // cout<<"*"<<endl;
    for(j=0;j<m;j++)
     {
       for(i=0;i<n;i++)
        {
            if(i==0)
                prec[i][j]=-1;
            else
                {
                    prec[i][j]=prec[i-1][j];
                    if(s[i-1][j]=='.')
                        prec[i][j]=i-1;
                }

        }
        for(i=n-1;i>=0;i--)
        {
            if(i==n-1)
                sufc[i][j]=n;
            else
                {
                    sufc[i][j]=sufc[i+1][j];
                    if(s[i+1][j]=='.')
                        sufc[i][j]=i+1;
                }

        }
    }
    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
        {
            if(deg[i][j]==4)
            {
                int x1=abs(j-prer[i][j]);
                int x2=abs(j-sufr[i][j]);
                int y1=abs(i-prec[i][j]);
                int y2=abs(i-sufc[i][j]);
                int z=min(min(x1,x2),min(y1,y2));
                ans.pb(pii(pi(i,j),z));

                cnt1[i][j-z+1]++;
                cnt1[i][j+z]--;

                cnt2[i-z+1][j]++;
                cnt2[i+z][j]--;

            }
        }

    for(i=0;i<n;i++)
    {
        int s=0;
        for(j=0;j<m;j++)
        {
            s+=cnt1[i][j];
            cnt[i][j]=s;
        }
    }
    for(i=0;i<m;i++)
    {
        int s=0;
        for(j=0;j<n;j++)
        {
            s+=cnt2[j][i];
            cnt[j][i]+=s;
        }
    }

    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
        {
            if(s[i][j]=='*' && !cnt[i][j])
            {
                cout<<-1;
                return 0;
            }
        }
        cout<<ans.size()<<endl;
    for(i=0;i<ans.size();i++)
        cout<<ans[i].F.F+1<<" "<<ans[i].F.S+1<<" "<<ans[i].S-1<<endl;
    return 0;

}


#include<iostream>
#include<vector>
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <cctype>
#include <stack>
#include <list>
#include <queue>
#include <map>
#include <sstream>
#include <cmath>
#include <limits>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <bitset>
#include <utility>
#include <set>
#include <numeric>

//DOUBLE D UP
#define fast ios::sync_with_stdio(false);cin.tie(0);
#define ll long long
#define N 3005
#define pb push_back
#define F first
#define S second
#define pi pair<int,int>
#define pii pair<pi,int>
#define M (ll)998244353
#define ld long double
#define inf 20000000000
using namespace std;

int prer[N][N],prec[N][N],sufr[N][N],sufc[N][N],cnt1[N][N],cnt2[N][N],cnt[N][N],deg[N][N],n,m;

int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
string s[N];
bool check(int x,int y)
{
    return ((x>=0) && (x<n) && (y>=0) && (y<m) && (s[x][y]=='*'));
}
vector<pii> ans;
int main()
{
	//cout<<"hello world!"<<endl;

	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output2.txt","w",stdout);
    #endif
    fast
    int i,j,k;

    cin>>n>>m;

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

    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            int fl=1;
            for( k=0;k<4;k++)
            {
                if(!check(i+dx[k],j+dy[k]))
                {
                   fl=0;
                   break;
                }
            }
            if(fl)
                deg[i][j]=4;
        }
    }

    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            if(j==0)
                prer[i][j]=-1;
            else
                {
                    prer[i][j]=prer[i][j-1];
                    if(s[i][j-1]=='.')
                        prer[i][j]=j-1;
                }

        }
        for(j=m-1;j>=0;j--)
        {
            if(j==m-1)
                sufr[i][j]=m;
            else
                {
                    sufr[i][j]=sufr[i][j+1];
                    if(s[i][j+1]=='.')
                        sufr[i][j]=j+1;
                }

        }
    }
   // cout<<"*"<<endl;
    for(j=0;j<m;j++)
     {
       for(i=0;i<n;i++)
        {
            if(i==0)
                prec[i][j]=-1;
            else
                {
                    prec[i][j]=prec[i-1][j];
                    if(s[i-1][j]=='.')
                        prec[i][j]=i-1;
                }

        }
        for(i=n-1;i>=0;i--)
        {
            if(i==n-1)
                sufc[i][j]=n;
            else
                {
                    sufc[i][j]=sufc[i+1][j];
                    if(s[i+1][j]=='.')
                        sufc[i][j]=i+1;
                }

        }
    }
    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
        {
            if(deg[i][j]==4)
            {
                int x1=abs(j-prer[i][j]);
                int x2=abs(j-sufr[i][j]);
                int y1=abs(i-prec[i][j]);
                int y2=abs(i-sufc[i][j]);
                int z=min(min(x1,x2),min(y1,y2));
                ans.pb(pii(pi(i,j),z));

                cnt1[i][j-z+1]++;
                cnt1[i][j+z]--;

                cnt2[i-z+1][j]++;
                cnt2[i+z][j]--;

            }
        }

    for(i=0;i<n;i++)
    {
        int s=0;
        for(j=0;j<m;j++)
        {
            s+=cnt1[i][j];
            cnt[i][j]=s;
        }
    }
    for(i=0;i<m;i++)
    {
        int s=0;
        for(j=0;j<n;j++)
        {
            s+=cnt2[j][i];
            cnt[j][i]+=s;
        }
    }

    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
        {
            if(s[i][j]=='*' && !cnt[i][j])
            {
                cout<<-1;
                return 0;
            }
        }
        cout<<ans.size()<<endl;
    for(i=0;i<ans.size();i++)
        cout<<ans[i].F.F+1<<" "<<ans[i].F.S+1<<" "<<ans[i].S-1<<endl;
    return 0;

}


#include<iostream>
#include<vector>
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <cctype>
#include <stack>
#include <list>
#include <queue>
#include <map>
#include <sstream>
#include <cmath>
#include <limits>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <bitset>
#include <utility>
#include <set>
#include <numeric>

//DOUBLE D UP
#define fast ios::sync_with_stdio(false);cin.tie(0);
#define ll long long
#define N 1005
#define pb push_back
#define F first
#define S second
#define pi pair<int,int>
#define pii pair<pi,int>
#define M (ll)998244353
#define ld long double
#define inf 20000000000
using namespace std;

int prer[N][N],prec[N][N],sufr[N][N],sufc[N][N],cnt1[N][N],cnt2[N][N],cnt[N][N],deg[N][N],n,m;

int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
string s[N];
bool check(int x,int y)
{
    return ((x>=0) && (x<n) && (y>=0) && (y<m) && (s[x][y]=='*'));
}
vector<pii> ans;
int main()
{
	//cout<<"hello world!"<<endl;

	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output2.txt","w",stdout);
    #endif
    fast
    int i,j,k;

    cin>>n>>m;

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

    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            int fl=1;
            for( k=0;k<4;k++)
            {
                if(!check(i+dx[k],j+dy[k]))
                {
                   fl=0;
                   break;
                }
            }
            if(fl)
                deg[i][j]=4;
        }
    }

    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            if(j==0)
                prer[i][j]=-1;
            else
                {
                    prer[i][j]=prer[i][j-1];
                    if(s[i][j-1]=='.')
                        prer[i][j]=j-1;
                }

        }
        for(j=m-1;j>=0;j--)
        {
            if(j==m-1)
                sufr[i][j]=m;
            else
                {
                    sufr[i][j]=sufr[i][j+1];
                    if(s[i][j+1]=='.')
                        sufr[i][j]=j+1;
                }

        }
    }
    cout<<"*"<<endl;
    for(j=0;j<m;j++)
     {
       for(i=0;i<n;i++)
        {
            if(i==0)
                prec[i][j]=-1;
            else
                {
                    prec[i][j]=prec[i-1][j];
                    if(s[i-1][j]=='.')
                        prec[i][j]=i-1;
                }

        }
        for(i=n-1;i>=0;i--)
        {
            if(i==n-1)
                sufc[i][j]=n;
            else
                {
                    sufc[i][j]=sufc[i+1][j];
                    if(s[i+1][j]=='.')
                        sufc[i][j]=i+1;
                }

        }
    }
    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
        {
            if(deg[i][j]==4)
            {
                int x1=abs(j-prer[i][j]);
                int x2=abs(j-sufr[i][j]);
                int y1=abs(i-prec[i][j]);
                int y2=abs(i-sufc[i][j]);
                int z=min(min(x1,x2),min(y1,y2));
                ans.pb(pii(pi(i,j),z));

                cnt1[i][j-z+1]++;
                cnt1[i][j+z]--;

                cnt2[i-z+1][j]++;
                cnt2[i+z][j]--;

            }
        }

    for(i=0;i<n;i++)
    {
        int s=0;
        for(j=0;j<m;j++)
        {
            s+=cnt1[i][j];
            cnt[i][j]=s;
        }
    }
    for(i=0;i<m;i++)
    {
        int s=0;
        for(j=0;j<n;j++)
        {
            s+=cnt2[j][i];
            cnt[j][i]+=s;
        }
    }

    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
        {
            if(s[i][j]=='*' && !cnt[i][j])
            {
                cout<<-1;
                return 0;
            }
        }
        cout<<ans.size()<<endl;
    for(i=0;i<ans.size();i++)
        cout<<ans[i].F.F+1<<" "<<ans[i].F.S+1<<" "<<ans[i].S-1<<endl;
    return 0;

}


#include<iostream>
#include<vector>
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <cctype>
#include <stack>
#include <list>
#include <queue>
#include <map>
#include <sstream>
#include <cmath>
#include <limits>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <bitset>
#include <utility>
#include <set>
#include <numeric>

//DOUBLE D UP
#define fast ios::sync_with_stdio(false);cin.tie(0);
#define ll long long
#define N 3005
#define pb push_back
#define F first
#define S second
#define pi pair<int,int>
#define pii pair<pi,int>
#define M (ll)998244353
#define ld long double
#define inf 20000000000
using namespace std;

int prer[N][N],prec[N][N],sufr[N][N],sufc[N][N],cnt1[N][N],cnt2[N][N],cnt[N][N],deg[N][N],n,m;

int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
string s[N];
bool check(int x,int y)
{
    return ((x>=0) && (x<n) && (y>=0) && (y<m) && (s[x][y]=='*'));
}
vector<pii> ans;
int main()
{
	//cout<<"hello world!"<<endl;

	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output2.txt","w",stdout);
    #endif
    fast
    int i,j,k;

    cin>>n>>m;

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

    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            int fl=1;
            for( k=0;k<4;k++)
            {
                if(!check(i+dx[k],j+dy[k]))
                {
                   fl=0;
                   break;
                }
            }
            if(fl)
                deg[i][j]=4;
        }
    }

    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            if(j==0)
                prer[i][j]=-1;
            else
                {
                    prer[i][j]=prer[i][j-1];
                    if(s[i][j-1]=='.')
                        prer[i][j]=j-1;
                }

        }
        for(j=m-1;j>=0;j--)
        {
            if(j==m-1)
                sufr[i][j]=m;
            else
                {
                    sufr[i][j]=sufr[i][j+1];
                    if(s[i][j+1]=='.')
                        sufr[i][j]=j+1;
                }

        }
    }
   // cout<<"*"<<endl;
    for(j=0;j<m;j++)
     {
       for(i=0;i<n;i++)
        {
            if(i==0)
                prec[i][j]=-1;
            else
                {
                    prec[i][j]=prec[i-1][j];
                    if(s[i-1][j]=='.')
                        prec[i][j]=i-1;
                }

        }
        for(i=n-1;i>=0;i--)
        {
            if(i==n-1)
                sufc[i][j]=n;
            else
                {
                    sufc[i][j]=sufc[i+1][j];
                    if(s[i+1][j]=='.')
                        sufc[i][j]=i+1;
                }

        }
    }
    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
        {
            if(deg[i][j]==4)
            {
                int x1=abs(j-prer[i][j]);
                int x2=abs(j-sufr[i][j]);
                int y1=abs(i-prec[i][j]);
                int y2=abs(i-sufc[i][j]);
                int z=min(min(x1,x2),min(y1,y2));
                ans.pb(pii(pi(i,j),z));

                cnt1[i][j-z+1]++;
                cnt1[i][min(1002,j+z)]--;

                cnt2[i-z+1][j]++;
                cnt2[min(1002,i+z)][j]--;

            }
        }

    for(i=0;i<n;i++)
    {
        int s=0;
        for(j=0;j<m;j++)
        {
            s+=cnt1[i][j];
            cnt[i][j]=s;
        }
    }
    for(i=0;i<m;i++)
    {
        int s=0;
        for(j=0;j<n;j++)
        {
            s+=cnt2[j][i];
            cnt[j][i]+=s;
        }
    }

    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
        {
            if(s[i][j]=='*' && !cnt[i][j])
            {
                cout<<-1;
                return 0;
            }
        }
        cout<<ans.size()<<endl;
    for(i=0;i<ans.size();i++)
        cout<<ans[i].F.F+1<<" "<<ans[i].F.S+1<<" "<<ans[i].S-1<<endl;
    return 0;

}


#include<iostream>
#include<vector>
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <cctype>
#include <stack>
#include <list>
#include <queue>
#include <map>
#include <sstream>
#include <cmath>
#include <limits>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <bitset>
#include <utility>
#include <set>
#include <numeric>

//DOUBLE D UP
#define fast ios::sync_with_stdio(false);cin.tie(0);
#define ll long long
#define N 1005
#define pb push_back
#define F first
#define S second
#define pi pair<int,int>
#define pii pair<pi,int>
#define M (ll)998244353
#define ld long double
#define inf 20000000000
using namespace std;

int prer[N][N],prec[N][N],sufr[N][N],sufc[N][N],cnt1[N][N],cnt2[N][N],cnt[N][N],deg[N][N],n,m;

int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
string s[N];
bool check(int x,int y)
{
    return ((x>=0) && (x<n) && (y>=0) && (y<m) && (s[x][y]=='*'));
}
vector<pii> ans;
int main()
{
	//cout<<"hello world!"<<endl;

	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output2.txt","w",stdout);
    #endif
    fast
    int i,j,k;

    cin>>n>>m;

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

    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            int fl=1;
            for( k=0;k<4;k++)
            {
                if(!check(i+dx[k],j+dy[k]))
                {
                   fl=0;
                   break;
                }
            }
            if(fl)
                deg[i][j]=4;
        }
    }

    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            if(j==0)
                prer[i][j]=-1;
            else
                {
                    prer[i][j]=prer[i][j-1];
                    if(s[i][j-1]=='.')
                        prer[i][j]=j-1;
                }

        }
        for(j=m-1;j>=0;j--)
        {
            if(j==m-1)
                sufr[i][j]=m;
            else
                {
                    sufr[i][j]=sufr[i][j+1];
                    if(s[i][j+1]=='.')
                        sufr[i][j]=j+1;
                }

        }
    }
   // cout<<"*"<<endl;
    for(j=0;j<m;j++)
     {
       for(i=0;i<n;i++)
        {
            if(i==0)
                prec[i][j]=-1;
            else
                {
                    prec[i][j]=prec[i-1][j];
                    if(s[i-1][j]=='.')
                        prec[i][j]=i-1;
                }

        }
        for(i=n-1;i>=0;i--)
        {
            if(i==n-1)
                sufc[i][j]=n;
            else
                {
                    sufc[i][j]=sufc[i+1][j];
                    if(s[i+1][j]=='.')
                        sufc[i][j]=i+1;
                }

        }
    }
    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
        {
            if(deg[i][j]==4)
            {
                int x1=abs(j-prer[i][j]);
                int x2=abs(j-sufr[i][j]);
                int y1=abs(i-prec[i][j]);
                int y2=abs(i-sufc[i][j]);
                int z=min(min(x1,x2),min(y1,y2));
                ans.pb(pii(pi(i,j),z));

                cnt1[i][j-z+1]++;
                cnt1[i][min(1002,j+z)]--;

                cnt2[i-z+1][j]++;
                cnt2[min(1002,i+z)][j]--;

            }
        }

    for(i=0;i<n;i++)
    {
        int s=0;
        for(j=0;j<m;j++)
        {
            s+=cnt1[i][j];
            cnt[i][j]=s;
        }
    }
    for(i=0;i<m;i++)
    {
        int s=0;
        for(j=0;j<n;j++)
        {
            s+=cnt2[j][i];
            cnt[j][i]+=s;
        }
    }

    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
        {
            if(s[i][j]=='*' && !cnt[i][j])
            {
                cout<<-1;
                return 0;
            }
        }
        cout<<ans.size()<<endl;
    for(i=0;i<ans.size();i++)
        cout<<ans[i].F.F+1<<" "<<ans[i].F.S+1<<" "<<ans[i].S-1<<endl;
    return 0;

}


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

typedef long long ll;

#define REP(i, n) for(ll i=0; i<n; i++)
#define FOR(i, a, b) for(ll i = a; i<=b; i++)
#define FORD(i, a, b) for(ll i = a; i>=b; i--)
#define DEBUG(x) cout<<#x<<" > "<<x<<endl;
#define endl '\n'

const ll MOD = 1e9 + 7, INF = 1e9, MX = 1e5 + 4;

ll grid[1002][1002], u[1002][1002], l[1002][1002], r[1002][1002], d[1002][1002], v[1002][1002], h[1002][1002];

ll n, m;

int main()
{
	cin >> n >> m;
	REP(i, n)
	{
		REP(j, m)
		{
			char ch;
			cin >> ch;
			if(ch == '.')
				grid[i+1][j+1] = 0;
			else
			{
			/*	rowr[i] = min(rowr[i], j);
				cold[j] = min(cold[j], i);
				rowl[i] = max(rowl[i], j);
				colu[j] = max(colu[j], i);
			*/	grid[i+1][j+1] = 1;
			}
		}
	}

	vector<pair<pair<ll, ll>, ll> > bv;
/*	REP(i, n)
	{
		REP(j, m)
		{
			if(i == 0)
				continue;
			if(j == 0)
				continue;
			if(i + 1 == n)
				continue;
			if(j + 1 == m)
				continue;
			ll stsz = min((rowl[i]-j), (j-rowr[i]));
			stsz = min(stsz, min((colu[j]-i), (i-cold[j])));
			stsz = max(0, stsz);
			ll cl = j-1;
			ll cr = j+1;
			ll cu = i-1;
			ll cd = i+1;

			stsz = (grid[cu][j] && grid[cd][j] && grid[i][cr] && grid[i][cl] && grid[i][j]);

			if(stsz)
			{

				ll cf = 1;
				reff[cu][j] = reff[cd][j] = reff[i][cr] = reff[i][cl] = reff[i][j] = 1;
				FOR(i, 2, max(n,m))
				{

					cl--, cr++, cu--, cd++;
					if(cl < 0)
						break;
					if(cu < 0)
						break;
					if(cr + 1 > m)
						break;
					if(cd + 1 > n)
						break;
					stsz = (grid[cu][j] && grid[cd][j] && grid[i][cr] && grid[i][cl] && grid[i][j]);
					if(!stsz)
						break;
					reff[cu][j] = reff[cd][j] = reff[i][cr] = reff[i][cl] = reff[i][j] = 1;
					cf = i;
				}
				v.push_back({{i, j}, cf});
			}

		}
	}
*/
	// u & l

	FOR(i, 1, n)
	{
		FOR(j, 1, m)
		{
			if(i == 1)
			{
				u[i][j] = grid[i][j];
				continue;
			}
			if(j == 1)
			{
				l[i][j] = grid[i][j];
				continue;
			}

			if(grid[i][j])
				u[i][j] = u[i-1][j] + 1, l[i][j] = l[i][j-1] + 1;
		}
	}

	FORD(i, n, 1)
	{
		FORD(j, m, 1)
		{
			if(i == n)
			{
				d[i][j] = grid[i][j];
				continue;
			}
			if(j == m)
			{
				r[i][j] = grid[i][j];
				continue;
			}

			if(grid[i][j])
				d[i][j] = d[i+1][j] + 1, r[i][j] = r[i][j+1] + 1;
		}
	}
/*
	FOR(i, 1, n)
	{
		FOR(j, 1, m)
		{
			cout << max(0ll, min(min(u[i][j], l[i][j]), min(d[i][j], r[i][j])) - 1) << "";
		}
		cout << endl;
	}
	cout << endl;
*/

	FOR(i, 1, n)
	{
		FOR(j, 1, m)
		{
			if(grid[i][j])
			{
				ll cur = max(0ll, min(min(u[i][j], l[i][j]), min(d[i][j], r[i][j])) - 1);
				if(cur)
				{
					bv.push_back({{i, j}, cur});
					v[i-cur][j] += 1;
					if(i + cur + 1 <= n) v[i+cur+1][j] -= 1;
					h[i][j-cur] += 1;
					if(j + cur + 1 <= m) h[i][j+cur+1] += 1;
				}
			}
		}
	}

	FOR(i, 1, n)
	{
		FOR(j, 1, m) v[i][j] += v[i-1][j], h[i][j] += h[i][j-1];
	}
/*
	FOR(i, 1, n)
	{
		FOR(j, 1, m)
		{
			if(v[i][j] > 0 || h[i][j] > 0)
				cout << 1;
			else
				cout << 0;
		}
		cout << endl;
	}
*/
	bool f = 1;
	REP(i, n)
	{
		REP(j, m)
		{
		//	cout << (reff[i][j] == 1) ? '*' : '.';
			if(grid[i][j] != (v[i][j] > 0 || h[i][j] > 0))
				f = 0;
		}
	//	cout << endl;
	}

	if(!bv.size())
		cout << -1 << endl, exit(0);
	if(f)
	{
		cout << bv.size() << endl;

		REP(i, bv.size())
		{
			cout << bv[i].first.first << " " << bv[i].first.second << " " << bv[i].second << endl;
		}
	}
	else
		cout << -1 << endl;
}


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

typedef int ll;

#define REP(i, n) for(ll i=0; i<n; i++)
#define FOR(i, a, b) for(ll i = a; i<=b; i++)
#define FORD(i, a, b) for(ll i = a; i>=b; i--)
#define DEBUG(x) cout<<#x<<" > "<<x<<endl;
#define endl '\n'

const ll MOD = 1e9 + 7, INF = 1e9, MX = 1e5 + 4;

int grid[1002][1002], reff[1002][1002], rowr[1002], rowl[1002], cold[1002], colu[1002];

ll n, m;

int main()
{
	memset(rowr, INF, sizeof(rowr));
	memset(cold, INF, sizeof(cold));
	memset(rowl, -INF, sizeof(rowl));
	memset(colu, -INF, sizeof(colu));
	cin >> n >> m;
	REP(i, n)
	{
		REP(j, m)
		{
			char ch;
			cin >> ch;
			if(ch == '.')
				grid[i][j] = 0;
			else
			{
				rowr[i] = min(rowr[i], j);
				cold[j] = min(cold[j], i);
				rowl[i] = max(rowl[i], j);
				colu[j] = max(colu[j], i);
				grid[i][j] = 1;
			}
		}
	}

	vector<pair<pair<ll, ll>, ll> > v;
	REP(i, n)
	{
		REP(j, m)
		{
			if(i == 0)
				continue;
			if(j == 0)
				continue;
			if(i + 1 == n)
				continue;
			if(j + 1 == m)
				continue;
			ll stsz = min((rowl[i]-j), (j-rowr[i]));
			stsz = min(stsz, min((colu[j]-i), (i-cold[j])));
			stsz = max(0, stsz);
			ll cl = j-1;
			ll cr = j+1;
			ll cu = i-1;
			ll cd = i+1;
			stsz = (grid[cu][j] && grid[cd][j] && grid[i][cr] && grid[i][cl] && grid[i][j]);
			if(stsz)
			{
				ll cf = 1;
				FOR(i, 1, max(n,m))
				{
					cl--, cr++, cu--, cd++;
					stsz = (grid[cu][j] && grid[cd][j] && grid[i][cr] && grid[i][cl] && grid[i][j]);
					if(!stsz)
						break;
					cf = i;
				}
				v.push_back({{i, j}, cf});
			}

		}
	}

	bool f = 1;
	REP(i, n)
	{
		REP(j, m)
		{
	//		cout << (reff[i][j]) ? '*' : '.';
		}
	//	cout << endl;
	}
	if(!v.size())
		cout << -1 << endl, exit(0);
	if(f)
	{
		cout << v.size() << endl;

		REP(i, v.size())
		{
			cout << v[i].first.first << " " << v[i].first.second << " " << v[i].second << endl;
		}
	}
	else
		cout << -1 << endl;
}


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

typedef long long ll;

#define REP(i, n) for(ll i=0; i<n; i++)
#define FOR(i, a, b) for(ll i = a; i<=b; i++)
#define FORD(i, a, b) for(ll i = a; i>=b; i--)
#define DEBUG(x) cout<<#x<<" > "<<x<<endl;
#define endl '\n'

const ll MOD = 1e9 + 7, INF = 1e9, MX = 1e5 + 4;

ll grid[1002][1002], u[1002][1002], l[1002][1002], r[1002][1002], d[1002][1002], v[1002][1002], h[1002][1002];

ll n, m;

int main()
{
	cin >> n >> m;
	REP(i, n)
	{
		REP(j, m)
		{
			char ch;
			cin >> ch;
			if(ch == '.')
				grid[i+1][j+1] = 0;
			else
			{
			/*	rowr[i] = min(rowr[i], j);
				cold[j] = min(cold[j], i);
				rowl[i] = max(rowl[i], j);
				colu[j] = max(colu[j], i);
			*/	grid[i+1][j+1] = 1;
			}
		}
	}

	vector<pair<pair<ll, ll>, ll> > bv;
/*	REP(i, n)
	{
		REP(j, m)
		{
			if(i == 0)
				continue;
			if(j == 0)
				continue;
			if(i + 1 == n)
				continue;
			if(j + 1 == m)
				continue;
			ll stsz = min((rowl[i]-j), (j-rowr[i]));
			stsz = min(stsz, min((colu[j]-i), (i-cold[j])));
			stsz = max(0, stsz);
			ll cl = j-1;
			ll cr = j+1;
			ll cu = i-1;
			ll cd = i+1;

			stsz = (grid[cu][j] && grid[cd][j] && grid[i][cr] && grid[i][cl] && grid[i][j]);

			if(stsz)
			{

				ll cf = 1;
				reff[cu][j] = reff[cd][j] = reff[i][cr] = reff[i][cl] = reff[i][j] = 1;
				FOR(i, 2, max(n,m))
				{

					cl--, cr++, cu--, cd++;
					if(cl < 0)
						break;
					if(cu < 0)
						break;
					if(cr + 1 > m)
						break;
					if(cd + 1 > n)
						break;
					stsz = (grid[cu][j] && grid[cd][j] && grid[i][cr] && grid[i][cl] && grid[i][j]);
					if(!stsz)
						break;
					reff[cu][j] = reff[cd][j] = reff[i][cr] = reff[i][cl] = reff[i][j] = 1;
					cf = i;
				}
				v.push_back({{i, j}, cf});
			}

		}
	}
*/
	// u & l

	FOR(i, 1, n)
	{
		FOR(j, 1, m)
		{
			if(i == 1)
			{
				u[i][j] = grid[i][j];
				continue;
			}
			if(j == 1)
			{
				l[i][j] = grid[i][j];
				continue;
			}

			if(grid[i][j])
				u[i][j] = u[i-1][j] + 1, l[i][j] = l[i][j-1] + 1;
		}
	}

	FORD(i, n, 1)
	{
		FORD(j, m, 1)
		{
			if(i == n)
			{
				d[i][j] = grid[i][j];
				continue;
			}
			if(j == m)
			{
				r[i][j] = grid[i][j];
				continue;
			}

			if(grid[i][j])
				d[i][j] = d[i+1][j] + 1, r[i][j] = r[i][j+1] + 1;
		}
	}
/*
	FOR(i, 1, n)
	{
		FOR(j, 1, m)
		{
			cout << max(0ll, min(min(u[i][j], l[i][j]), min(d[i][j], r[i][j])) - 1) << "";
		}
		cout << endl;
	}
	cout << endl;
*/

	FOR(i, 1, n)
	{
		FOR(j, 1, m)
		{
			if(grid[i][j])
			{
				ll cur = max(0ll, min(min(u[i][j], l[i][j]), min(d[i][j], r[i][j])) - 1);
				if(cur)
				{
					bv.push_back({{i, j}, cur});
					v[i-cur][j] += 1;
					if(i + cur + 1 <= n) v[i+cur+1][j] -= 1;
					h[i][j-cur] += 1;
					if(j + cur + 1 <= m) h[i][j+cur+1] -= 1;
				}
			}
		}
	}

	FOR(i, 1, n)
	{
		FOR(j, 1, m) v[i][j] += v[i-1][j], h[i][j] += h[i][j-1];
	}
/*
	FOR(i, 1, n)
	{
		FOR(j, 1, m)
		{
			if(v[i][j] > 0 || h[i][j] > 0)
				cout << 1;
			else
				cout << 0;
		}
		cout << endl;
	}
*/
	bool f = 1;
	FOR(i, 1, n)
	{
		FOR(j, 1, m)
		{
		//	cout << (reff[i][j] == 1) ? '*' : '.';
			if(grid[i][j] != (v[i][j] > 0 || h[i][j] > 0))
				f = 0;
		}
	//	cout << endl;
	}

	if(f)
	{
		cout << bv.size() << endl;

		REP(i, bv.size())
		{
			cout << bv[i].first.first << " " << bv[i].first.second << " " << bv[i].second << endl;
		}
	}
	else
		cout << -1 << endl;
}


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

typedef long long ll;

#define REP(i, n) for(ll i=0; i<n; i++)
#define FOR(i, a, b) for(ll i = a; i<=b; i++)
#define FORD(i, a, b) for(ll i = a; i>=b; i--)
#define DEBUG(x) cout<<#x<<" > "<<x<<endl;
#define endl '\n'

const ll MOD = 1e9 + 7, INF = 1e9, MX = 1e5 + 4;

ll grid[1002][1002], u[1002][1002], l[1002][1002], r[1002][1002], d[1002][1002], v[1002][1002], h[1002][1002];

ll n, m;

int main()
{
	cin >> n >> m;
	REP(i, n)
	{
		REP(j, m)
		{
			char ch;
			cin >> ch;
			if(ch == '.')
				grid[i+1][j+1] = 0;
			else
			{
			/*	rowr[i] = min(rowr[i], j);
				cold[j] = min(cold[j], i);
				rowl[i] = max(rowl[i], j);
				colu[j] = max(colu[j], i);
			*/	grid[i+1][j+1] = 1;
			}
		}
	}

	vector<pair<pair<ll, ll>, ll> > bv;
/*	REP(i, n)
	{
		REP(j, m)
		{
			if(i == 0)
				continue;
			if(j == 0)
				continue;
			if(i + 1 == n)
				continue;
			if(j + 1 == m)
				continue;
			ll stsz = min((rowl[i]-j), (j-rowr[i]));
			stsz = min(stsz, min((colu[j]-i), (i-cold[j])));
			stsz = max(0, stsz);
			ll cl = j-1;
			ll cr = j+1;
			ll cu = i-1;
			ll cd = i+1;

			stsz = (grid[cu][j] && grid[cd][j] && grid[i][cr] && grid[i][cl] && grid[i][j]);

			if(stsz)
			{

				ll cf = 1;
				reff[cu][j] = reff[cd][j] = reff[i][cr] = reff[i][cl] = reff[i][j] = 1;
				FOR(i, 2, max(n,m))
				{

					cl--, cr++, cu--, cd++;
					if(cl < 0)
						break;
					if(cu < 0)
						break;
					if(cr + 1 > m)
						break;
					if(cd + 1 > n)
						break;
					stsz = (grid[cu][j] && grid[cd][j] && grid[i][cr] && grid[i][cl] && grid[i][j]);
					if(!stsz)
						break;
					reff[cu][j] = reff[cd][j] = reff[i][cr] = reff[i][cl] = reff[i][j] = 1;
					cf = i;
				}
				v.push_back({{i, j}, cf});
			}

		}
	}
*/
	// u & l

	FOR(i, 1, n)
	{
		FOR(j, 1, m)
		{
			if(i == 1)
			{
				u[i][j] = grid[i][j];
				continue;
			}
			if(j == 1)
			{
				l[i][j] = grid[i][j];
				continue;
			}

			if(grid[i][j])
				u[i][j] = u[i-1][j] + 1, l[i][j] = l[i][j-1] + 1;
		}
	}

	FORD(i, n, 1)
	{
		FORD(j, m, 1)
		{
			if(i == n)
			{
				d[i][j] = grid[i][j];
				continue;
			}
			if(j == m)
			{
				r[i][j] = grid[i][j];
				continue;
			}

			if(grid[i][j])
				d[i][j] = d[i+1][j] + 1, r[i][j] = r[i][j+1] + 1;
		}
	}
/*
	FOR(i, 1, n)
	{
		FOR(j, 1, m)
		{
			cout << max(0ll, min(min(u[i][j], l[i][j]), min(d[i][j], r[i][j])) - 1) << "";
		}
		cout << endl;
	}
	cout << endl;
*/

	FOR(i, 1, n)
	{
		FOR(j, 1, m)
		{
			if(grid[i][j])
			{
				ll cur = max(0ll, min(min(u[i][j], l[i][j]), min(d[i][j], r[i][j])) - 1);
				if(cur)
				{
					bv.push_back({{i, j}, cur});
					v[i-cur][j] += 1;
					if(i + cur + 1 <= n) v[i+cur+1][j] -= 1;
					h[i][j-cur] += 1;
					if(j + cur + 1 <= m) h[i][j+cur+1] -= 1;
				}
			}
		}
	}

	FOR(i, 1, n)
	{
		FOR(j, 1, m) v[i][j] += v[i-1][j], h[i][j] += h[i][j-1];
	}
/*
	FOR(i, 1, n)
	{
		FOR(j, 1, m)
		{
			if(v[i][j] > 0 || h[i][j] > 0)
				cout << 1;
			else
				cout << 0;
		}
		cout << endl;
	}
*/
	bool f = 1;
	REP(i, n)
	{
		REP(j, m)
		{
		//	cout << (reff[i][j] == 1) ? '*' : '.';
			if(grid[i][j] != (v[i][j] > 0 || h[i][j] > 0))
				f = 0;
		}
	//	cout << endl;
	}

	if(!bv.size())
		cout << -1 << endl, exit(0);
	if(f)
	{
		cout << bv.size() << endl;

		REP(i, bv.size())
		{
			cout << bv[i].first.first << " " << bv[i].first.second << " " << bv[i].second << endl;
		}
	}
	else
		cout << -1 << endl;
}


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

typedef long long ll;

#define REP(i, n) for(ll i=0; i<n; i++)
#define FOR(i, a, b) for(ll i = a; i<=b; i++)
#define FORD(i, a, b) for(ll i = a; i>=b; i--)
#define DEBUG(x) cout<<#x<<" > "<<x<<endl;
#define endl '\n'

const ll MOD = 1e9 + 7, INF = 1e9, MX = 1e5 + 4;

ll grid[1002][1002], u[1002][1002], l[1002][1002], r[1002][1002], d[1002][1002], v[1002][1002], h[1002][1002];

ll n, m;

int main()
{
	cin >> n >> m;
	REP(i, n)
	{
		REP(j, m)
		{
			char ch;
			cin >> ch;
			if(ch == '.')
				grid[i+1][j+1] = 0;
			else
			{
			/*	rowr[i] = min(rowr[i], j);
				cold[j] = min(cold[j], i);
				rowl[i] = max(rowl[i], j);
				colu[j] = max(colu[j], i);
			*/	grid[i+1][j+1] = 1;
			}
		}
	}

	vector<pair<pair<ll, ll>, ll> > bv;
/*	REP(i, n)
	{
		REP(j, m)
		{
			if(i == 0)
				continue;
			if(j == 0)
				continue;
			if(i + 1 == n)
				continue;
			if(j + 1 == m)
				continue;
			ll stsz = min((rowl[i]-j), (j-rowr[i]));
			stsz = min(stsz, min((colu[j]-i), (i-cold[j])));
			stsz = max(0, stsz);
			ll cl = j-1;
			ll cr = j+1;
			ll cu = i-1;
			ll cd = i+1;

			stsz = (grid[cu][j] && grid[cd][j] && grid[i][cr] && grid[i][cl] && grid[i][j]);

			if(stsz)
			{

				ll cf = 1;
				reff[cu][j] = reff[cd][j] = reff[i][cr] = reff[i][cl] = reff[i][j] = 1;
				FOR(i, 2, max(n,m))
				{

					cl--, cr++, cu--, cd++;
					if(cl < 0)
						break;
					if(cu < 0)
						break;
					if(cr + 1 > m)
						break;
					if(cd + 1 > n)
						break;
					stsz = (grid[cu][j] && grid[cd][j] && grid[i][cr] && grid[i][cl] && grid[i][j]);
					if(!stsz)
						break;
					reff[cu][j] = reff[cd][j] = reff[i][cr] = reff[i][cl] = reff[i][j] = 1;
					cf = i;
				}
				v.push_back({{i, j}, cf});
			}

		}
	}
*/
	// u & l

	FOR(i, 1, n)
	{
		FOR(j, 1, m)
		{
			if(i == 1)
			{
				u[i][j] = grid[i][j];
				continue;
			}
			if(j == 1)
			{
				l[i][j] = grid[i][j];
				continue;
			}

			if(grid[i][j])
				u[i][j] = u[i-1][j] + 1, l[i][j] = l[i][j-1] + 1;
		}
	}

	FORD(i, n, 1)
	{
		FORD(j, m, 1)
		{
			if(i == n)
			{
				d[i][j] = grid[i][j];
				continue;
			}
			if(j == m)
			{
				r[i][j] = grid[i][j];
				continue;
			}

			if(grid[i][j])
				d[i][j] = d[i+1][j] + 1, r[i][j] = r[i][j+1] + 1;
		}
	}
/*
	FOR(i, 1, n)
	{
		FOR(j, 1, m)
		{
			cout << max(0ll, min(min(u[i][j], l[i][j]), min(d[i][j], r[i][j])) - 1) << "";
		}
		cout << endl;
	}
	cout << endl;
*/

	FOR(i, 1, n)
	{
		FOR(j, 1, m)
		{
			if(grid[i][j])
			{
				ll cur = max(0ll, min(min(u[i][j], l[i][j]), min(d[i][j], r[i][j])) - 1);
				if(cur)
				{
					bv.push_back({{i, j}, cur});
					v[i-cur][j] += 1;
					if(i + cur + 1 <= n) v[i+cur+1][j] -= 1;
					h[i][j-cur] += 1;
					if(j + cur + 1 <= m) h[i][j+cur+1] = 1;
				}
			}
		}
	}

	FOR(i, 1, n)
	{
		FOR(j, 1, m) v[i][j] += v[i-1][j], h[i][j] += h[i][j-1];
	}
/*
	FOR(i, 1, n)
	{
		FOR(j, 1, m)
		{
			if(v[i][j] > 0 || h[i][j] > 0)
				cout << 1;
			else
				cout << 0;
		}
		cout << endl;
	}
*/
	bool f = 1;
	REP(i, n)
	{
		REP(j, m)
		{
		//	cout << (reff[i][j] == 1) ? '*' : '.';
			if(grid[i][j] != (v[i][j] > 0 || h[i][j] > 0))
				f = 0;
		}
	//	cout << endl;
	}
	if(!bv.size())
		cout << -1 << endl, exit(0);
	if(f)
	{
		cout << bv.size() << endl;

		REP(i, bv.size())
		{
			cout << bv[i].first.first << " " << bv[i].first.second << " " << bv[i].second << endl;
		}
	}
	else
		cout << -1 << endl;
}