#define pb push_back
#define mp make_pair
#define _(a,b) memset((a),(b),sizeof(a))
#define sz(a) (int)(a).size()
const int maxn = 10100;
struct Edge
{
int a, b, cap, flow, id;
};
vector<Edge> e;
vector<int> g[maxn];
int S, T;
int dist[maxn], ptr[maxn], q[maxn], sq;
void adde(int a, int b, int cap)
{
Edge t;
t.a = a;
t.b = b;
t.id = sz(e);
t.cap = cap;
t.flow = 0;
e.pb(t);
g[t.a].pb(t.id);
swap(t.a, t.b);
t.id++;
t.cap = 0;
e.pb(t);
g[t.a].pb(t.id);
}
bool bfs()
{
_(dist, -1);
sq = 0;
q[sq++] = S;
dist[S] = 0;
for (int i = 0; i < sq; i++)
{
int id = q[i];
for (int j = 0; j < sz(g[id]); j++)
{
Edge &t = e[g[id][j]];
if (dist[t.b] < 0 && t.flow < t.cap)
{
q[sq++] = t.b;
dist[t.b] = dist[t.a] + 1;
}
}
}
return dist[T] >= 0;
}
int dfs(int id, int exp)
{
if (exp == 0 || id == T)
return exp;
for (int &i = ptr[id]; i < sz(g[id]); i++)
{
Edge &t = e[g[id][i]];
if (dist[t.b] == dist[t.a] + 1)
{
int push = dfs(t.b, min(exp, t.cap - t.flow));
if (push)
{
t.flow += push;
e[t.id ^ 1].flow -= push;
return push;
}
}
}
return 0;
}
int flow()
{
int ret = 0, x;
while (bfs())
{
_(ptr, 0);
while (x = dfs(S, INF))
ret += x;
}
return ret;
}
I2RlZmluZSBwYiBwdXNoX2JhY2sKI2RlZmluZSBtcCBtYWtlX3BhaXIKI2RlZmluZSBfKGEsYikgbWVtc2V0KChhKSwoYiksc2l6ZW9mKGEpKQojZGVmaW5lIHN6KGEpIChpbnQpKGEpLnNpemUoKQoKY29uc3QgaW50IG1heG4gPSAxMDEwMDsKCnN0cnVjdCBFZGdlCnsKICAgIGludCBhLCBiLCBjYXAsIGZsb3csIGlkOwp9OwoKdmVjdG9yPEVkZ2U+IGU7CnZlY3RvcjxpbnQ+IGdbbWF4bl07CmludCBTLCBUOwppbnQgZGlzd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