#!/bin/python3
def hourglassSum(arr):    
    w = h = 3
    sums = []
    for i in range(len(arr) - h + 1):
        for j in range(len(arr[i]) - w + 1):
            sums.append(arr[i][j] + arr[i][j+1] + arr[i][j+2] + arr[i+1][j+1] + arr[i+2][j] + arr[i+2][j+1] + arr[i+2][j+2])
    return max(sums)

// C++
#include <bits/stdc++.h>

using namespace std;

int hourglassSum(vector<vector<int>> arr) {
    int w = 3;
    int h = 3; 
    int max_sum = INT_MIN;
    for (int i = 0; i <= arr.size() - h; ++i) {
        for (int j = 0; j <= arr[i].size() - w; ++j) {
            int sum = arr[i][j] + arr[i][j+1] + arr[i][j+2]
                                + arr[i+1][j+1]
                    + arr[i+2][j] + arr[i+2][j+1] + arr[i+2][j+2];
            max_sum = max(sum, max_sum);
        }
    }   
    return max_sum;
}
