#include <bits/stdc++.h>   using namespace std;   long long MOD = 1e9 + 7;   long long MAX = 9223372036854775807;   int visited[1001][1001];   int main() {     ios_base::sync_with_stdio(0);     ;     int n, m;     cin >> n >> m;     int a[n][m], l[n][m], r[n][m], u[n][m], d[n][m];     for (int i = 0; i < n; ++i) {       string s;       cin >> s;       for (int j = 0; j < s.size(); ++j) {         if (s[j] ==  . )           a[i][j] = 0;         else           a[i][j] = 1;       }     }     for (int i = 0; i < n; ++i) {       int temp = 0;       for (int j = 0; j < m; ++j) {         l[i][j] = temp;         temp += a[i][j];         if (a[i][j] == 0) temp = 0;       }       temp = 0;       for (int j = m - 1; j >= 0; j--) {         r[i][j] = temp;         temp += a[i][j];         if (a[i][j] == 0) temp = 0;       }     }     for (int j = 0; j < m; ++j) {       int temp = 0;       for (int i = 0; i < n; ++i) {         u[i][j] = temp;         temp += a[i][j];         if (a[i][j] == 0) temp = 0;       }       temp = 0;       for (int i = n - 1; i >= 0; i--) {         d[i][j] = temp;         temp += a[i][j];         if (a[i][j] == 0) temp = 0;       }     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         if (a[i][j]) {           l[i][j] = min(min(l[i][j], r[i][j]), min(u[i][j], d[i][j]));         }       }     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         u[i][j] = 0;         r[i][j] = 0;       }     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         if (a[i][j] and l[i][j] > 0) {           int k = l[i][j];           u[i - k][j]++;           if (i + k + 1 < n) u[i + k + 1][j]--;           r[i][j - k]++;           if (j + k + 1 < m) r[i][j + k + 1]--;         }       }     }     for (int i = 0; i < n; ++i) {       int temp = 0;       for (int j = 0; j < m; ++j) {         temp += r[i][j];         visited[i][j] = temp;       }     }     for (int j = 0; j < m; ++j) {       int temp = 0;       for (int i = 0; i < n; ++i) {         temp += u[i][j];         visited[i][j] += temp;       }     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         if (a[i][j] and visited[i][j] == 0) {           cout << -1 <<   n ;           return 0;           ;         }         if (a[i][j] == 0 and visited[i][j] > 0) {           cout << -1 <<   n ;           return 0;           ;         }       }     }     vector<pair<pair<int, int>, int> > ans;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         if (a[i][j] and l[i][j] > 0) {           ans.push_back({{i + 1, j + 1}, l[i][j]});         }       }     }     cout << ans.size() <<   n ;     ;     for (auto i : ans) {       cout << i.first.first <<    ;       ;       cout << i.first.second <<    ;       ;       cout << i.second <<   n ;     }     return 0;   }   