n,m = map(int, input().split())
tetromino = []
result = []
sum = 0
for i in range(n):
tetromino.append(list(map(int, input().split())))
#1
for i in range(n-1):
for j in range(m-2):
sum=tetromino[i][j]+tetromino[i+1][j]+tetromino[i+1][j+1]+tetromino[i+1][j+2]
result.append(sum)
for i in range(n-2):
for j in range(m-1):
sum=tetromino[i][j]+tetromino[i+1][j]+tetromino[i+1][j+1]+tetromino[i+2][j+1]
result.append(sum)
for i in range(n-2):
for j in range(m-1):
sum=tetromino[i][j]+tetromino[i+1][j]+tetromino[i+1][j+1]+tetromino[i+2][j]
result.append(sum)
for i in range(n-2):
for j in range(m-1):
sum=tetromino[i][j]+tetromino[i+1][j]+tetromino[i+2][j]+tetromino[i+2][j+1]
result.append(sum)
for i in range(n-3):
for j in range(m):
sum=tetromino[i][j]+tetromino[i+1][j]+tetromino[i+2][j]+tetromino[i+3][j]
result.append(sum)
#2
for i in range(n-1):
for j in range(m-1):
sum=tetromino[i][j]+tetromino[i][j+1]+tetromino[i+1][j]+tetromino[i+1][j+1]
result.append(sum)
for i in range(n-2):
for j in range(m-1):
sum=tetromino[i][j]+tetromino[i][j+1]+tetromino[i+2][j+1]+tetromino[i+1][j+1]
result.append(sum)
for i in range(n-1):
for j in range(m-2):
sum=tetromino[i][j]+tetromino[i][j+1]+tetromino[i+1][j+2]+tetromino[i+1][j+1]
result.append(sum)
for i in range(n-1):
for j in range(m-2):
sum=tetromino[i][j+1]+tetromino[i+1][j]+tetromino[i+1][j+1]+tetromino[i+1][j+2]
result.append(sum)
for i in range(n-2):
for j in range(m-1):
sum=tetromino[i][j+1]+tetromino[i+1][j]+tetromino[i+1][j+1]+tetromino[i+2][j]
result.append(sum)
for i in range(n-1):
for j in range(m-2):
sum=tetromino[i][j+1]+tetromino[i][j+2]+tetromino[i+1][j]+tetromino[i+1][j+1]
result.append(sum)
for i in range(n-2):
for j in range(m-1):
sum=tetromino[i][j+1]+tetromino[i+1][j]+tetromino[i+1][j+1]+tetromino[i+2][j+1]
result.append(sum)
for i in range(n-2):
for j in range(m-1):
sum=tetromino[i][j]+tetromino[i][j+1]+tetromino[i+1][j]+tetromino[i+2][j]
result.append(sum)
for i in range(n-2):
for j in range(m-1):
sum=tetromino[i][j+1]+tetromino[i+1][j+1]+tetromino[i+2][j]+tetromino[i+2][j+1]
result.append(sum)
#3
for i in range(n-1):
for j in range(m-2):
sum=tetromino[i][j]+tetromino[i][j+1]+tetromino[i][j+2]+tetromino[i+1][j]
result.append(sum)
for i in range(n-1):
for j in range(m-2):
sum=tetromino[i][j]+tetromino[i][j+1]+tetromino[i][j+2]+tetromino[i+1][j+1]
result.append(sum)
for i in range(n-1):
for j in range(m-2):
sum=tetromino[i][j]+tetromino[i][j+1]+tetromino[i][j+2]+tetromino[i+1][j+2]
result.append(sum)
for i in range(n-1):
for j in range(m-2):
sum=tetromino[i][j+2]+tetromino[i+1][j]+tetromino[i+1][j+1]+tetromino[i+1][j+2]
result.append(sum)
#4
for i in range(n):
for j in range(m-3):
sum=tetromino[i][j]+tetromino[i][j+1]+tetromino[i][j+2]+tetromino[i][j+3]
result.append(sum)
print(max(result))
'백준' 카테고리의 다른 글
백준 2960번: 에라토스테네스의 체 (0) | 2021.07.02 |
---|---|
백준 14891번: 톱니바퀴 (0) | 2021.07.02 |
백준 4949번: 균형잡힌 세상 (0) | 2021.06.29 |
백준 11866번: 요세푸스 문제 0 (0) | 2021.06.27 |
백준 4963번: 섬의 개수 (0) | 2021.05.20 |