//longlong5a6
#include <bits/stdc++.h>
#define pii pair<int,int>
#define F first
#define S second
#define bit(i, x)((x >> i) & 1)
#define sobit(i) __builtin_popcount((int)(i))
#define pb push_back
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define For(i,x,n) for(int (i)=(int)(x);(i)<=(int)(n);(i)++)
#define round(m,n) setprecision((int)m) << fixed << double(n)
#define down "\n"
#define TASK "hexangle"
#define maxn 3001
using namespace std;
int a[maxn][maxn];
int m;
void work(int k)
{
if(k == 1)
{
return;
}
int sub;
if(k == 2)
{
sub = 1;
}
else sub = ceil(1.0*k/1.5);
work(sub);
For(i, 1, m-k+1)
{
For(j, 1, i)
{
int lim = i - sub + k;
a[i][j] = max(a[i][j], max(a[lim][j], a[lim][j-sub+k]));
}
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie();
cout.tie();
if (fopen("in.txt","r"))
{
freopen("in.txt","r",stdin);
}
if (fopen(TASK".INP","r"))
{
freopen(TASK".INP","r",stdin);
freopen(TASK".OUT","w",stdout);
}
int k;
cin>>m>>k;
For(i,1,m)
{
For(j,1,i) cin>>a[i][j];
}
work(k);
long long res=0;
For(i,1,m-k+1)
{
For(j,0,i) res+=a[i][j];
}
cout<<res;
}
Ly9sb25nbG9uZzVhNgojaW5jbHVkZSA8Yml0cy9zdGRjKysuaD4KI2RlZmluZSBwaWkgcGFpcjxpbnQsaW50PgojZGVmaW5lIEYgZmlyc3QKI2RlZmluZSBTIHNlY29uZAojZGVmaW5lIGJpdChpLCB4KSgoeCA+PiBpKSAmIDEpCiNkZWZpbmUgc29iaXQoaSkgIF9fYnVpbHRpbl9wb3Bjb3VudCgoaW50KShpKSkKI2RlZmluZSBwYiBwdXNoX2JhY2sKI2RlZmluZSBhbGwoeCkgeC5iZWdpbigpLHguZW5kKCkKI2RlZmluZSB2aSB2ZWN0b3I8aW50PgojZGVmaW5lIEZvcihpLHgsbikgZm9yKGludCAoaSk9KGludCkoeCk7KGkpPD0oaW50KShuKTsoaSkrKykKI2RlZmluZSByb3VuZChtLG4pIHNldHByZWNpc2lvbigoaW50KW0pIDw8IGZpeGVkIDw8IGRvdWJsZShuKQojZGVmaW5lIGRvd24gIlxuIgojZGVmaW5lIFRBU0sgImhleGFuZ2xlIgojZGVmaW5lIG1heG4gMzAwMQoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKaW50IGFbbWF4bl1bbWF4bl07CmludCBtOwoKdm9pZCB3b3JrKGludCBrKQp7CiAgICBpZihrID09IDEpCiAgICB7CiAgICAgICAgcmV0dXJuOwogICAgfQogICAgaW50IHN1YjsKICAgIGlmKGsgPT0gMikKICAgIHsKICAgICAgICBzdWIgPSAxOwogICAgfQogICAgZWxzZSBzdWIgPSBjZWlsKDEuMCprLzEuNSk7CiAgICB3b3JrKHN1Yik7CiAgICBGb3IoaSwgMSwgbS1rKzEpCiAgICB7CiAgICAgICAgRm9yKGosIDEsIGkpCiAgICAgICAgewogICAgICAgICAgICBpbnQgbGltID0gaSAtIHN1YiArIGs7CiAgICAgICAgICAgIGFbaV1bal0gPSBtYXgoYVtpXVtqXSwgbWF4KGFbbGltXVtqXSwgYVtsaW1dW2otc3ViK2tdKSk7CiAgICAgICAgfQogICAgfQoKfQoKaW50IG1haW4oKQp7CiAgICBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKDApOwogICAgICAgIGNpbi50aWUoKTsKICAgICAgICBjb3V0LnRpZSgpOwogICAgaWYgKGZvcGVuKCJpbi50eHQiLCJyIikpCiAgICAgICAgewogICAgICAgICAgICBmcmVvcGVuKCJpbi50eHQiLCJyIixzdGRpbik7CgogICAgICAgIH0KICAgIGlmIChmb3BlbihUQVNLIi5JTlAiLCJyIikpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGZyZW9wZW4oVEFTSyIuSU5QIiwiciIsc3RkaW4pOwogICAgICAgICAgICAgICAgZnJlb3BlbihUQVNLIi5PVVQiLCJ3IixzdGRvdXQpOwogICAgICAgICAgICB9CiAgICBpbnQgazsKICAgIGNpbj4+bT4+azsKICAgIEZvcihpLDEsbSkKICAgIHsKICAgICAgICBGb3IoaiwxLGkpIGNpbj4+YVtpXVtqXTsKICAgIH0KICAgIHdvcmsoayk7CiAgICBsb25nIGxvbmcgcmVzPTA7CiAgICBGb3IoaSwxLG0taysxKQogICAgewogICAgICAgIEZvcihqLDAsaSkgcmVzKz1hW2ldW2pdOwogICAgfQogICAgY291dDw8cmVzOwp9Cg==