#include #include #include #include #include #include using namespace std; int8_t A[50][4000]; int main() { int h, w; cin >> h >> w; for(int j = 0; j < h; ++j) { for(int i = 0; i < w; ++i) { char c; cin >> c; if(c == 'r') A[i][j] = 1 << 0; if(c == 'g') A[i][j] = 1 << 1; if(c == 'b') A[i][j] = 1 << 2; if(c == 'w') A[i][j] = 1 << 3; } } int g = gcd(h, w); int hg = h / g; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); auto rnd = [&](long long mod) { unsigned long long r = rng(); return (r * mod) >> 32; }; time_t start = clock(); while(true) { for(int i = 0; i < 1000000; ++i) { int xl = rnd(w); int xr = rnd(w); if(xr < xl) swap(xl, xr); int yl = rnd(h); int y_delta = g * rnd(hg); int yh = yl + (xr - xl) + y_delta; if(yh >= h) yh -= h; if(yh >= h) yh -= h; if(yh >= h) yh -= h; // cerr << xl << " " << xr << " " << yl << " " << yh << endl; if((A[xl][yl] | A[xl][yh] | A[xr][yl] | A[xr][yh]) == 15) { cout << "possible\n"; return 0; } } if(clock() - start > 1.4 * CLOCKS_PER_SEC) break; } cout << "impossible\n"; }