#include using namespace std; #define mp make_pair #define pb push_back #define st first #define nd second typedef long long ll; typedef long double ld; typedef pair pii; #define maxn 22 int t[maxn][maxn]; int s[maxn][maxn]; int sfood[maxn*maxn], wfood[maxn*maxn]; vector sheeps, wolfes; int odp[maxn][maxn]; bool notgrow[maxn][maxn]; int T, n, m; void sim_sheeps(){ for(int i=0; im) a=1; sfood[i]++; sheeps[i].st=a; t[a][b]++; } } void sim_wolfes(){ for(int i=0; in) b=1; wfood[i]++; wolfes[i].nd=b; if(t[a][b]>0){ wfood[i]=0; for(int j=0; j=10){ wfood[i]=-1; s[a][b]=-1; } } } void sheepdeaths(){ for(int i=0; i=3){ s[a][b]=0; notgrow[a][b]=1; sfood[i]=0; } if(sfood[i]>=5){ sfood[i]=-1; s[a][b]=-1; t[a][b]--; } } } void sim_soil(){ for(int i=1; i<=m; i++){ for(int j=1; j<=n; j++){ if(s[i][j]!=-1){ if(notgrow[i][j]) notgrow[i][j]=0; else s[i][j]++; } } } } int main(){ scanf("%d%d%d", &T, &m, &n); for(int i=1; i<=m; i++){ for(int j=1; j<=n; j++){ char h; scanf(" %c", &h); if(h=='S'){ sheeps.pb(mp(i, j)); t[i][j]++; } if(h=='W') wolfes.pb(mp(i, j)); } } for(int i=1; i<=T; i++){ //sim_soil(); sim_sheeps(); sim_wolfes(); sheepdeaths(); sim_soil(); } for(int i=0; i=3 && odp[i][j]==0) odp[i][j]=4; } } for(int i=1; i<=m; i++){ for(int j=1; j<=n; j++){ if(odp[i][j]==0) printf("."); if(odp[i][j]==1) printf("S"); if(odp[i][j]==2) printf("W"); if(odp[i][j]==3) printf("*"); if(odp[i][j]==4) printf("#"); } printf("\n"); } }