#include<bits/stdc++.h>
typedef long long ll;
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define nep(i,r,l) for(int i=r;i>=l;i--)
void re(int &x){scanf("%d",&x);}
void re(int &x,int &y){scanf("%d %d",&x,&y);}
void re(ll &x){scanf("%lld",&x);}
void re(ll &x,ll &y){scanf("%lld %lld",&x,&y);}
void re(double &x){scanf("%lf",&x);}
void re(double &x,int &y){scanf("%lf %lf",&x,&y);}
using namespace std;
const int N=5e5+5;
const int inf=0x3f3f3f3f;

int a[N];
int sum[N];
map<ll,int> mp;
int main()
{
    int n;cin>>n;
    rep(i,0,n-1) cin>>a[i];
    ll ans=0;
    ll sum=0;
    mp[0]=1;
    rep(i,0,n-1)
    {
        if(i%2==0)
        {
            sum+=a[i];
        }
        else sum-=a[i];
        ans+=mp[sum];
        mp[sum]++;
    }
    cout<<ans<<endl;

    return 0;
}
// 5 2 3 4 1

#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define ll long long
#define rep(i,x,y) for(int i=x; i<y; i++)
int n,m;
vector<vector<int>> a;
bool check(int x){
	int b[n][n];
	//memset(b,0,sizeof b);
	
	//cout<<x<<'\n';
	rep(i,0,n){
		rep(j,0,n){
			b[i][j]=(a[i][j]<=x);
			if(i>0)b[i][j]+=b[i-1][j];
			if(j>0)b[i][j]+=b[i][j-1];
			if(i>0 && j>0)b[i][j]-=b[i-1][j-1];
			//cout<<b[i][j]<<' ';
		}
		//cout<<'\n';
	}
	
	//bool ans=0;
	rep(i,m-1,n){
		rep(j,m-1,n){
			int sum=b[i][j];
			if(j-m>=0)sum-=b[i][j-m];
			if(i-m>=0)sum-=b[i-m][j];
			if(i-m>=0 && j-m>=0)sum+=b[i-m][j-m];
			if(sum>=(m*m+1)/2){return true;}
			//cout<<sum<<' ';
		}
		//cout<<'\n';
	}
	return false;
}
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	cin>>n>>m;
	a.resize(n,vector<int>(n));
	set<int> s;
	rep(i,0,n){
		rep(j,0,n){cin>>a[i][j];s.insert(a[i][j]);}
	}
	
	vector<int> v(s.begin(),s.end());
	
	int ans;
	
	int l=0,h=v.size()-1;
	
	// check(0);
	 // rep(i,0,h+1){
		 // cout<<check(i)<<' ';
	 // }
	 // cout<<'\n';
	
	 while(l<=h){
		 int mid=(l+h)/2;
		 if(check(v[mid])){
		 	ans=v[mid];
			 h=mid-1;
		 }
		else {
			 l=mid+1;
		 }
	 }
	cout<<ans;
	return 0;
}