https://www.acmicpc.net/problem/1018
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
chess = []
result = []
for _ in range(n):
arr = list(input())
arr.pop()
chess.append(arr)
for a in range(n-7):
for b in range(m-7):
index1 = 0
index2 = 0
for i in range(a, a+8):
for j in range(b, b+8):
if (i+j) % 2 == 0:
if chess[i][j] != 'W':
index1 += 1
if chess[i][j] != 'B':
index2 += 1
else:
if chess[i][j] != 'B':
index1 += 1
if chess[i][j] != 'W':
index2 += 1
result.append(min(index1, index2))
print(min(result))
설마 4중 반복문일줄이야.. 이거밖에 방법이 없다고 생각했는데 맞았다^^!..