#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define popcount __builtin_popcount using namespace std; typedef long long int ll; typedef pair P; struct edge{ int to, cap, rev; ll cost; edge(int to, int cap, ll cost, int rev):to(to), cap(cap), cost(cost), rev(rev){} }; int V; vector g[10010]; ll h[10010]; ll dist[10010]; int prevv[10010], preve[10010]; void add_edge(int from, int to, int cap, ll cost){ edge e=edge(to, cap, cost, g[to].size()); g[from].push_back(e); e=edge(from, 0, -cost, g[from].size()-1); g[to].push_back(e); } ll min_cost_flow(int s, int t, int f){ using P=pair; const ll INF=1e18; ll res=0; fill(h, h+V, 0); while(f>0){ priority_queue, greater

> que; fill(dist, dist+V, INF); dist[s]=0; que.push({0, s}); while(!que.empty()){ P p=que.top(); que.pop(); int v=p.second; if(dist[v]0 && dist[e.to]>dist[v]+e.cost+h[v]-h[e.to]){ dist[e.to]=dist[v]+e.cost+h[v]-h[e.to]; prevv[e.to]=v; preve[e.to]=i; que.push({dist[e.to], e.to}); } } } for(int v=0; v>n; cin>>str; for(int i=0; i>v[i]; int s=2*n, t=2*n+1; int S=2*n+2, T=2*n+3; V=2*n+4; ll ans=0; int f=0; add_edge(S, s, n/4, 0); add_edge(t, T, n/4, 0); for(int i=0; i