https://www.acmicpc.net/problem/16956
import java.util.*;
fun main(args: Array<String>) {
val s=Scanner(System.`in`)
var r=s.nextInt()
var c=s.nextInt()
var arr=Array(r){s.next().toCharArray()}
var check: Boolean=true
var dxy = arrayOf(arrayOf(0,1),arrayOf(0,-1),arrayOf(1,0),arrayOf(-1,0))
for(i in 0 until r){
for(j in 0 until c){
if(arr[i][j]=='W'){
for(k in 0 until 4){
var x=i+dxy[k][0]
var y=j+dxy[k][1]
if(x>=0 && x<r && y>=0 && y<c){
if(arr[x][y]=='.'){
arr[x][y]='D'
}
else if(arr[x][y]=='S'){
check=false
println(0)
return
}
}
}
}
}
}
if(!check) println(0)
else{
println(1)
for(i in 0 until r){
for(j in 0 until c){
print(arr[i][j])
}
println()
}
}
}