#include using namespace std; #define pb push_back #define mp make_pair #define ALL(x) (x).begin(),(x).end() typedef long long ll; typedef unsigned long long ull; typedef pair pii; const int maxn = 5e2 + 70; const int INF = 0x3f3f3f3f; const ll inf = 0x3f3f3f3f3f3f3f3f; const int MOD = 1e9 + 7; const double eps = 1e-7; const double PI = acos(-1.0); int n, x, y; int a[maxn][maxn]; int calc(vector& V){ int ans = 0, cnt = 1, res = 1, sum = 0, k = 0, p = 0; while(true){ ans++; while(res && p < V.size()){ k += V[p++]; res--; } sum += k; while(sum >= 8*cnt*cnt) cnt++, res++; if(cnt >= 9) return ans; } } int solve(int x1, int y1){ vector V; V.pb(a[x1][y1]); for(int x2=x1-3;x2<=x1+3;x2++){ for(int y2=y1-3;y2<=y1+3;y2++){ if(x2 >= 1 && x2 <= n && y2 >= 1 && y2 <= n){ int d = abs(x2-x1)+abs(y2-y1); if(d > 0 && d <= 3) V.pb(a[x2][y2]); } } } sort(V.begin()+1,V.end()); reverse(V.begin()+1,V.end()); //for(int i=0;i>T; while(T--){ scanf("%d %d %d",&n,&x,&y); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) scanf("%d",&a[i][j]); int ans = INF; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++){ ans = min(ans, solve(i,j) + (abs(x-i)+abs(y-j)+1)/2); //cout << i << " " << j << " " << 1+(abs(x-i)+abs(y-j)-1)/2 << ": " << ans << endl; } printf("%d\n",ans); } return 0; }