#include using namespace std; using ll = long long; #define int ll using VI = vector; using VVI = vector; using PII = pair; #define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(x) x.begin(), x.end() #define PB push_back const ll LLINF = (1LL<<60); const int INF = (1LL<<30); const int MOD = 1000000007; template T &chmin(T &a, const T &b) { return a = min(a, b); } template T &chmax(T &a, const T &b) { return a = max(a, b); } template bool IN(T a, T b, T x) { return a<=x&&x T ceil(T a, T b) { return a/b + !!(a%b); } template ostream &operator <<(ostream& out,const pair& a){ out<<'('< ostream &operator <<(ostream& out,const vector& a){ out<<'['; REP(i, a.size()) {out<> h >> w; vector s(h); REP(i, h) cin >> s[i]; double ans = LLINF; int x = 1, y = 0; while(x <= w) { double tmp = 0; REP(i, h) REP(j, w) { if(s[i][j]=='1') tmp += hypot(x-j-1, y-i-1); } chmin(ans, tmp); x++; } x = 1, y = h+1; while(x <= w) { double tmp = 0; REP(i, h) REP(j, w) { if(s[i][j]=='1') tmp += hypot(x-j-1, y-i-1); } chmin(ans, tmp); x++; } x = 0, y = 1; while(y <= h) { double tmp = 0; REP(i, h) REP(j, w) { if(s[i][j]=='1') tmp += hypot(x-j-1, y-i-1); } chmin(ans, tmp); y++; } x = w+1, y = 1; while(y <= h) { double tmp = 0; REP(i, h) REP(j, w) { if(s[i][j]=='1') tmp += hypot(x-j-1, y-i-1); } chmin(ans, tmp); y++; } cout << fixed << setprecision(15) << ans << endl; return 0; }