// Saarland University: <(OvO)> #include #define sz(a) ((int)(a).size()) #define divceil(a, b) ((a) + (b) - 1) / (b) using namespace std; #ifdef ONPC string to_string(const char* s) { return s; } template string to_string(const T& cont) { string ans = ""; for (bool fst = true; const auto& val: cont) { if (!fst) { ans += ", "; } ans += to_string(val); fst = false; } return ans + "}"; } void debug_print_collection() { cerr << endl; } template void debug_print_collection(First val, Args... args) { cerr << " " << to_string(val); debug_print_collection(args...); } #define debug(...) { cerr << "@@@ [" << #__VA_ARGS__ << "] ="; debug_print_collection(__VA_ARGS__);} #else #define debug(...) ; #define NDEBUG #endif mt19937 rnd(123); typedef long long ll; typedef long double ld; int solve() { int n; if (!(cin >> n)) { return 1; } vector g(n); int S = 0, F = 0; for (int i = 0; i < n; i++) { cin >> g[i]; S += count(g[i].begin(), g[i].end(), 'S'); F += count(g[i].begin(), g[i].end(), 'F'); } bool swaped = false; if (S > F) { swaped = true; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (g[i][j] == 'S') { g[i][j] = 'F'; } else if (g[i][j] == 'F') { g[i][j] = 'S'; } } } } vector gi(n); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (g[i][j] == 'F') { gi[i] |= (1 << j); } } } vector v, u; vector col(n, 0); int totcs = 0; for (int i = 0; i < n; i++) { if (count(g[i].begin(), g[i].end(), 'S')) { col[i] = 1; totcs++; } else { } } int mx = (3 * n + 3) / 4 + 2; for (int ms = 0; ms < (1 << n); ms++) { int csx = 0; int X = 0; bool ok = true; for (int i = 0; i < n; i++) { if ((ms >> i) & 1) { X++; if (col[i]) { csx++; } } else if (gi[i] & ms) { ok = false; break; } } if (!ok) { continue; } int csy = totcs - csx; int Y = n - X; if (X <= Y && 2 * X + csy <= mx && Y <= mx) { for (int i = 0; i < n; i++) { col[i] = ((ms >> i) & 1); } break; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i != j && g[i][j] == '?') { if (col[i] == col[j]) { g[i][j] = 'F'; } else { g[i][j] = 'S'; } } } } if (swaped) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (g[i][j] == 'S') { g[i][j] = 'F'; } else if (g[i][j] == 'F') { g[i][j] = 'S'; } } } } for (int i = 0; i < n; i++) { cout << g[i] << '\n'; } return 0; } int32_t main() { #ifdef ONPC assert(freopen("D.txt", "r", stdin)); #endif int TET = 1e9; // cin >> TET; for (int i = 1; i <= TET; i ++) { if (solve()) { break; } #ifdef ONPC cout << "__________________" << endl; #endif } #ifdef ONPC cerr << endl << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl; #endif } /* g++ -std=c++20 -Wall -Wextra -Wshadow -D_GLIBCXX_DEBUG -DONPC -O2 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover -o ex template.cpp && ./ex */