#include #include #include #include #include #include using namespace std; int main() { int n, m; cin>>n>>m; m+=2; string a=string(m, '.'); for(int i=0; i>t; a+="."+t+"."; } a+=string(m, '.'); unordered_set s; vector dir={-m-1, -m, -m+1, -1, 1, m-1, m, m+1}; for(int i=0; i=a.size() or a[k]=='.') continue; s.insert(k); } } vector v(a.size(), 1<<30); queue q; for(int e: s) { q.push(e); v[e]=1; } while (q.size()) { int p=q.front(); q.pop(); for(int d: dir) { int np=p+d; if (np<0 or np>=a.size() or a[np]=='.' or v[np]<=v[p]+1) continue; q.push(np); v[np]=v[p]+1; } } int res=0; for(int i=0; i