#include using namespace std; #ifdef LOCAL #include "settings/debug.cpp" #else #define Debug(...) void(0) #endif #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; int main() { cin.tie(nullptr)->sync_with_stdio(false); int h, w; cin >> h >> w; vector Grid(h, vector(w)); rep(i, h) rep(j, w) cin >> Grid[i][j]; double ans = 1e18; for (int x = -1; x <= h; ++x) { for (int y = -1; y <= w; ++y) { if (!(x == -1 || x == h || y == -1 || y == w)) continue; double sum = 0; rep(i, h) rep(j, w) { double d = sqrt((x - i) * (x - i) + (y - j) * (y - j)); if (Grid[i][j] == '1') sum += d; } ans = min(ans, sum); } } cout << fixed << setprecision(15) << ans << '\n'; return 0; }