# 题面

(略)

## code

#include<bits/stdc++.h>
using namespace std;
#define re register
#define in inline
#define get getchar()
#define ll long long
{
int t=0; char ch=get;
while(ch<'0' || ch>'9') ch=get;
while(ch<='9' && ch>='0') t=t*10+ch-'0', ch=get;
return t;
}
#define int ll
const int _=4e5+23;
const int inf=0x3f3f3f3f3f3f3f3f;
int tot=1, S, T, h[_], n, k, A, B, C, f[110][110];
struct edge{
int to,ne,w,val;
}e[_<<5];
in void add(int x,int y,int z,int w)
{
e[++tot].ne=h[x], e[tot].to=y, e[tot].w=z, e[tot].val=w, h[x]=tot;
e[++tot].ne=h[y], e[tot].to=x, e[tot].w=0, e[tot].val=-w, h[y]=tot;
}
int dis[_], cur[_], vis[_];
in int bfs()
{
memset(vis,0,sizeof(vis));
memset(dis,0x3f,sizeof(dis));
queue<int >q;
q.push(S); dis[S]=0;
while(!q.empty())
{
int u=q.front(); q.pop();
cur[u]=h[u];vis[u]=0;
for(re int i=h[u];i;i=e[i].ne)
{
int v=e[i].to;
if(dis[v]>dis[u]+e[i].val && e[i].w)
{
dis[v]=dis[u]+e[i].val;
if(!vis[v]){ vis[v]=1; q.push(v);}
}
}
}
return dis[T]!=inf;
}
ll cost=0;
in int dfs(int u,int flow)
{
if(u==T || !flow) return flow;
int used=0, d; vis[u]=1;
for(re int i=cur[u];i;i=e[i].ne)
{
int v=e[i].to; cur[u]=i;
if(!vis[v] && e[i].w && dis[v]==dis[u]+e[i].val)
{
d=dfs(v,min(flow-used,e[i].w));
if(!d) continue;
used+=d, e[i].w-=d, e[i^1].w+=d, cost+=1ll*d*e[i].val;
if(used==flow) break;
}
}
return used;
}
int maxflow;
in void dinic()
{
int qwe;
while(bfs())
while(memset(vis,0,sizeof(vis)) && (qwe=dfs(S,inf)));
}
in int id(int k,int x,int y) //第k层,(x,y)点的标号
{
return (k-1)*n*n+(x-1)*n+y;
}
int num(int x,int y) { return id(1,x,y);}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("1.in","r",stdin);
#endif
for(re int i=1;i<=n;++i)
for(re int q=1;q<=k+1;++q){
for(re int i=1;i<=n;++i)
for(re int j=1;j<=n;++j)
{
int tt=q+1;
if(q==1 || (q<=k && f[i][j]==0))
{