// @EXPECTED_RESULTS@: run_time_error,time_limit_exceeded // RTE because of a bad modulo. #include using namespace std; typedef long long ll; typedef long double ld; typedef pair ii; typedef vector vi; typedef vector vvi; typedef vector vii; #define x first #define y second #define pb push_back #define eb emplace_back #define rep(i, a, b) for(auto i = (a); i < (b); ++i) #define REP(i, n) rep(i, 0, n) #define all(v) (v).begin(), (v).end() #define rs resize #define DBG(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl const ld PI = acos(-1.0); template using min_queue = priority_queue, greater>; template int sz(const T& x) { return (int)x.size(); // copy the ampersand(&)! } template ostream& operator<<(ostream& os, vector& v) { os << "\n["; for(T& x : v) os << x << ','; return os << "]\n"; } struct pairhash { public: template size_t operator()(const pair& p) const { size_t lhs = hash()(p.x); size_t rhs = hash()(p.y); return lhs ^ (rhs + 0x9e3779b9 + (lhs << 6) + (lhs >> 2)); } }; const string C = "wrgb"; void run() { ll w, h; cin >> h >> w; vector> A(h, vector(w, 0)); for(ll y = 0; y < h; y++) { string s; cin >> s; for(ll x = 0; x < w; x++) { A[y][x] = 1 << (C.find(s[x])); } } ll g = gcd(w, h); for(ll x1 = 0; x1 < w; x1++) { for(ll y1 = 0; y1 < h; y1++) { for(ll x2 = x1 + 1; x2 < w; x2++) { for(ll y2 = y1 + (x2 - x1) % g; y2 < h; y2 += g) { if((A[y1][x1] | A[y2][x1] | A[y1][x2] | A[y2][x2]) == 15) { cout << "possible" << endl; return; } } // WA HERE: y1+(g+x1-x2)%g can be negative for(ll y2 = y1 + (g + x1 - x2) % g; y2 < h; y2 += g) { if((A[y1][x1] | A[y2][x1] | A[y1][x2] | A[y2][x2]) == 15) { cout << "possible" << endl; return; } } } } } cout << "impossible" << endl; } signed main() { // DON'T MIX "scanf" and "cin"! ios_base::sync_with_stdio(false); cin.tie(NULL); cout << fixed << setprecision(20); run(); return 0; }