#include using namespace std; #define FOR(a, b, c) for(int a = b; a < c; ++a) #define SZ(a) (int)((a).size()) using ll = long long; const int N = 20; enum { SOIL, GRASS, CARCASS }; struct Tile { int cnt = 3; int type = SOIL; }; Tile tab[N][N]; struct Animal { int x, y; int cnt; }; vector sheeps, wolves; int t, n, m; int done[N][N]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> t >> n >> m; FOR(i, 0, n) { string s; cin >> s; FOR(j, 0, m) { char c = s[j]; if(c == '.') { } else if(c == 'S') { Animal xd; xd.x = i, xd.y = j; xd.cnt = 5; sheeps.push_back(xd); } else if(c == 'W') { Animal xd; xd.x = i, xd.y = j; xd.cnt = 10; wolves.push_back(xd); } } } while(t--) { for(auto& w : wolves) { w.y = (w.y + 1) % m; w.cnt--; } for(auto& s : sheeps) { s.x = (s.x + 1) % n; s.cnt--; } for(auto& w : wolves) { for(int i = SZ(sheeps) - 1; i >= 0; i--) { auto& s = sheeps[i]; if(w.x == s.x and w.y == s.y) { tab[w.x][s.y].type = CARCASS; sheeps.erase(sheeps.begin() + i); w.cnt = 10; } } } for(auto& s : sheeps) { if(tab[s.x][s.y].type == GRASS) { tab[s.x][s.y].type = SOIL; tab[s.x][s.y].cnt = 4; s.cnt = 5; } } for(int i = SZ(wolves) - 1; i >= 0; i--) { if(wolves[i].cnt == 0) { tab[wolves[i].x][wolves[i].y].type = CARCASS; wolves.erase(wolves.begin() + i); } } for(int i = SZ(sheeps) - 1; i >= 0; i--) { if(sheeps[i].cnt == 0) { tab[sheeps[i].x][sheeps[i].y].type = CARCASS; sheeps.erase(sheeps.begin() + i); } } FOR(i, 0, n) FOR(j, 0, m) { tab[i][j].cnt--; if(tab[i][j].cnt == 0) { if(tab[i][j].type == SOIL) { tab[i][j].type = GRASS; } } } // for(auto& w : wolves) { // w.cnt--; // } // for(auto& s : sheeps) { // s.cnt--; // } } for(auto& i : sheeps) { done[i.x][i.y] = 1; } for(auto& i : wolves) { done[i.x][i.y] = 2; } FOR(i, 0, n) { FOR(j, 0, m) { if(done[i][j] == 2) { cout << 'W'; } else if(done[i][j] == 1) { cout << 'S'; } else if(tab[i][j].type == SOIL) { cout << '.'; } else if(tab[i][j].type == GRASS) { cout << '#'; } else if(tab[i][j].type == CARCASS) { cout << '*'; } } cout << "\n"; } }