#define _CRT_SECURE_NO_WARNINGS //#define _GLIBCXX_DEBUG #include using namespace std; typedef long long ll; typedef vector vi; typedef vector vvi; typedef pair pii; #define all(c) (c).begin(), (c).end() #define loop(i,a,b) for(ll i=a; i ostream & operator<<(ostream & os, vector const &); template typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple const &){} template typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple const & t){ os << (n==0?"":" ") << get(t); _ot(os, t); } template ostream & operator<<(ostream & os, tuple const & t){ _ot<0>(os, t); return os; } template ostream & operator<<(ostream & os, pair const & p){ return os << "(" << p.first << ", " << p.second << ") "; } template ostream & operator<<(ostream & os, vector const & v){ rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" "); return os; } #ifdef DEBUG #define dump(...) (cerr<<#__VA_ARGS__<<" = "<> n; rep(_,n){ string s; cin >> s; dump(s); typedef priority_queue pq; pq r,g,w; rep(i,s.size()){ if(s[i]=='R'){ r.push(i); } if(s[i]=='G'){ g.push(i); } if(s[i]=='W'){ w.push(i); } } bool ok = true; dump(w.size() , g.size(), r.size()); if(s.back()=='W') ok = false; if(ok && (r.size()==0 || g.size()==0)) ok = false; if(ok && r.size() != g.size()) ok = false; // if(ok && w.size()%r.size() != 0) ok = false; dump(ok); while(ok && r.size()){ int a = r.top(); r.pop(); if(g.size()==0){ ok = false; break; } int b = g.top(); g.pop(); if(a < b){ ok = false; break; } } puts(ok ? "possible" : "impossible"); } }