#include #define int long long using namespace std; string to_string(string s) { return s; } template string to_string(T v) { string res = "["; for (const auto &x : v) { res += to_string(x) + ", "; } res += "]"; return res; } void dbg_out() { cout << endl; } template void dbg_out(Head H, Tail... T) { cout << ' ' << to_string(H); dbg_out(T...); } #ifdef DEBUG #define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__) #else #define dbg(...) #endif using ll = long long; using vi = vector; #define rep(i, a, b) for (int i = (a); i < (b); ++i) #define all(v) (v).begin(), (v).end() #define sz(v) ((int)(v).size()) const int MAX_NODES = 42; struct edge { int a, b, color; }; string Color[MAX_NODES]; vector Edges; int nbNodes; int Check(int mask) { int sz = 0; for (int i = 0; i < nbNodes; i ++) sz += (mask >> i) & 1; int bound = (3 * nbNodes + 3) / 4; if (2 * sz > bound || nbNodes - sz - 1 > bound) return 0; int color = 0; for (edge e : Edges) { int i = e.a, j = e.b; if (((mask >> i) & 1) != ((mask >> j) & 1)) { int c = e.color; if (color > 0 && c > 0 && color != c) return 0; if (c > 0) color = c; } } for (int i = 0; i < nbNodes; i ++) { for (int j = 0; j < nbNodes; j ++) { if (Color[i][j] == '?') { if (((mask >> i) & 1) || ((mask >> j) & 1)) Color[i][j] = color == 1 ? 'F' : 'S'; else Color[i][j] = color == 1 ? 'S' : 'F'; } } } return 1; } void Read() { cin >> nbNodes; for (int i = 0; i < nbNodes; i ++) { cin >> Color[i]; for (int j = 0; j < nbNodes; j ++) { if (Color[i][j] == 'F') Edges.push_back({i, j, 1}); else if (Color[i][j] == 'S') Edges.push_back({i, j, 2}); } } for (int mask = 0; mask < (1 << nbNodes); mask ++) { if (Check(mask)) { for (int i = 0; i < nbNodes; i ++) cout << Color[i] << endl; return; } } assert(false); return; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); Read(); return 0; }