Problem:
Score : 800 points

Problem Statement

There are X+Y+Z people, conveniently numbered 1 through X+Y+Z.
Person i has A_i gold coins, B_i silver coins and C_i bronze coins.

Snuke is thinking of getting gold coins from X of those people, silver coins from Y of the people and bronze coins from Z of the people.
It is not possible to get two or more different colors of coins from a single person.
On the other hand, a person will give all of his/her coins of the color specified by Snuke.

Snuke would like to maximize the total number of coins of all colors he gets.
Find the maximum possible number of coins.

Constraints

1 \leq X

1 \leq Y

1 \leq Z

X+Y+Z \leq 10^5

1 \leq A_i \leq 10^9

1 \leq B_i \leq 10^9

1 \leq C_i \leq 10^9

Input

Input is given from Standard Input in the following format:

X Y Z
A_1 B_1 C_1
A_2 B_2 C_2
:
A_{X+Y+Z} B_{X+Y+Z} C_{X+Y+Z}

Output

Print the maximum possible total number of coins of all colors he gets.

Sample Input 1

1 2 1
2 4 4
3 2 1
7 6 7
5 2 3

Sample Output 1

18

Get silver coins from Person 1, silver coins from Person 2, bronze coins from Person 3 and gold coins from Person 4.
In this case, the total number of coins will be 4+2+7+5=18.
It is not possible to get 19 or more coins, and the answer is therefore 18.

Sample Input 2

3 3 2
16 17 1
2 7 5
2 16 12
17 7 7
13 2 10
12 18 3
16 15 19
5 6 2

Sample Output 2

110

Sample Input 3

6 2 4
33189 87907 277349742
71616 46764 575306520
8801 53151 327161251
58589 4337 796697686
66854 17565 289910583
50598 35195 478112689
13919 88414 103962455
7953 69657 699253752
44255 98144 468443709
2332 42580 752437097
39752 19060 845062869
60126 74101 382963164

Sample Output 3

3093929975

Solution in C++14 (GCC 5.4.1) (judge verdict: Time Limit Exceeded)

#include<cstring>
#include<iostream>
#include<cstdio>
#include<queue>
#include<cmath>
#include<algorithm>
#define rep(i,l,r) for (int i=l;i<=r;i++)
#define down(i,l,r) for (int i=l;i>=r;i--)
#define clr(x,y) memset(x,y,sizeof(x))
#define low(x) (x&(-x)) 
#define maxn 100500
#define inf 1152921504606846976
#define mm 1000000007
#define ll long long
using namespace std;
int tot=1,n,t;
ll ans;
int head[maxn];
ll dis[maxn];
int uu[maxn],cur[maxn];
struct data{int from,obj,pre,c;ll w;
}e[500500*4];
ll read(){
    ll x=0,f=1; char ch=getchar();
    while (!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
    while (isdigit(ch)) {x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}
void insert(int x,int y,int c,ll w){
    e[++tot].obj=y; e[tot].from=x; e[tot].pre=head[x]; e[tot].c=c; e[tot].w=w; head[x]=tot;
    e[++tot].obj=x; e[tot].from=y; e[tot].pre=head[y]; e[tot].c=0; e[tot].w=-w; head[y]=tot;
}
bool spfa(){
    clr(uu,0);
    rep(i,0,t) dis[i]=inf; dis[0]=0;
    queue<int> q; q.push(0);
    while (!q.empty()){
        int u=q.front(); q.pop(); uu[u]=1;
        for (int j=head[u];j;j=e[j].pre){
            int v=e[j].obj;
            if (e[j].c>0&&dis[v]>dis[u]+e[j].w){
                dis[v]=dis[u]+e[j].w;
                if (uu[v]==0) uu[v]=1,q.push(v);
            }
        }
        uu[u]=0;
    }
    if (dis[t]>=inf) return 0;
    return 1;
}
int dfs(int x,int mx){
    //if (uu[x]==1) return 0;
    if (x==t||mx==0) return mx;
    uu[x]=1;
    int used=0;
    for (int j=cur[x];j;j=e[j].pre){
        int v=e[j].obj;
        if (dis[v]==dis[x]+e[j].w&&e[j].c>0&&uu[v]==0){
            int w=dfs(v,min(e[j].c,mx-used));
            ans+=1LL*w*e[j].w;
		//	printf("%d %d %lld\n",x,v,e[j].w); 
            e[j].c-=w; e[j^1].c+=w; used+=w;
            cur[x]=j;
            if (used==mx) return used;
        }
    }
    return used;
}
int main(){
//	freopen("in.txt","r",stdin);
	int fl[4];
	rep(i,1,3) fl[i]=read(),n+=fl[i];
  	t=n+4;
	rep(i,1,n) {
		insert(0,i,1,0);
		rep(j,1,3) {
			ll x=read();  insert(i,n+j,1,-x);
		}
	}
	rep(i,1,3) insert(n+i,t,fl[i],0); 
    while (spfa()){
        clr(uu,0); rep(i,0,t) cur[i]=head[i];
        dfs(0,(int)1e9);
    }
    printf("%lld\n",-ans);
    return 0;
}