#include<bits/stdc++.h>
using namespace std;

int main(){
    int n,m,k;
    cin>>n>>m>>k;
    int a[n][m],b[n][m],c[n][m];
    int profit=0;
    string s[n],s1,s2;
    int i,j;
    for(i=0;i<n;i++){
        cin>>s[i];
        for(int x=0;x<m;x++){
            cin>>a[i][x]>>b[i][x]>>c[i][x];
        }
    }
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            if(i!=j){
                pair<int, int> p[m];
                for(int x=0;x<m;x++){
                    p[x]=make_pair(b[i][x]-a[j][x],c[j][x]);
        //            cout<<s[i]<<" "<<s[j]<<" "<<p[x].first<<" "<<p[x].second<<endl;
                }
                sort(p,p+m);
                int temp=k,prft=0;
                int ii=m-1;
                while(temp>0&&ii>=0&&p[ii].first>0){
                    prft+=(p[ii].first)*(min(temp,p[ii].second));
                    temp=max(0,temp-p[ii].second);
                    ii--;
                }
                if(prft>profit){
                    profit=prft;
                }
            }
        }
    }
    cout<<profit<<endl;
}


#include <iostream>
#include <string>

using namespace std;

#define REP(i, n) for (int i = 0; i < n; ++i)

int a[11][101];
int b[11][101];
int c[11][101];

int ta[11][101];
int tb[11][101];
int tc[11][101];

int main() {
	int n, m, k;
	cin >> n >> m >> k;
	string s;
	REP(i, n) {
		cin >> s;
		REP(j, m) {
			cin >> ta[i][j] >> tb[i][j] >> tc[i][j];
		}
	}
	int ans = 0;
	REP(i, n) REP(j, n) if ( i != j ) {
		int res = 0;
		REP(ii, n) REP(jj, m) {
			a[ii][jj] = ta[ii][jj];
			b[ii][jj] = tb[ii][jj];
			c[ii][jj] = tc[ii][jj];
		}
		REP(ii, k) {
			int maxn = -1;
			int type = -1;
			REP(t, m) if ( c[i][t] > 0 && b[j][t] - a[i][t] > maxn ) {
				maxn = b[j][t] - a[i][t];
				type = t;
			}
			if ( maxn != -1 ) {
				res += b[j][type] - a[i][type];
				--c[i][type];
			}
		}
		ans = max(ans, res);
	}
	cout << ans << endl;

	//system("pause");
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <deque>
#include <stack>

#define FOR(i, a, b) for(int i = a; i <= b; ++i)
#define FRD(i, a, b) for(int i = a; i >= b; --i)
#define FR(i, a)     for(int i = 0; i < a; ++i)
#define REP(i, a)    for(int i = 1; i <= a; ++i)
#define FRSZ(i, x)   for(int i = 0; i < (int)x.size(); ++i)
#define bug(x, y)    cout << (x) << " " << (y) << endl
#define bg(a, m, n)  FOR(i, m, n) cout << (a[i]) << " "; cout << endl;
#define MP 	     make_pair
using namespace std;

typedef long long ll;
typedef unsigned long long Qword;
typedef pair <int, int> TPair;
#define x first
#define y second

const int MAXINT = 0x7fffffff;

int n, m, k, a[15][105][5];

vector <TPair> res;
int ans;

int main() {
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    scanf("%d %d %d\n", &n, &m, &k);
    FOR(i, 1, n) {
        string tt; getline(cin, tt);
        FOR(j, 1, m)
            FOR(tt, 1, 3) scanf("%d", &a[i][j][tt]);
        scanf("\n");
    }
    FOR(i, 1, n)
        FOR(j, 1, n)
        if (i != j) {

            int pf = 0, cap = k;
            vector <TPair> res;
            FOR(t, 1, m)
                if (a[i][t][1] < a[j][t][2] && a[i][t][3] > 0)
                    res.push_back(TPair(a[j][t][2] - a[i][t][1], a[i][t][3]));
            sort(res.begin(), res.end());
            FRD(t, res.size() -1, 0) {
                int num = min(cap, res[t].y);
                pf += num * res[t].x;
                cap -= num;
                if (cap == 0) { ans = max(ans, pf); break; }
            }
            ans = max(ans, pf);
        }
    cout << ans << endl;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
using namespace std;

int table[16][128][4];
int profit[128][16][16];

int main()
{
    int n, m, k;
    cin >> n >> m >> k;

    for ( int i=0 ; i<n ;++i )
    {
        string name;
        cin >> name;
        for ( int j=0 ; j<m ; ++j )
        {
            cin >> table[i][j][0] >> table[i][j][1] >> table[i][j][2];
        }
    }

    for ( int i=0 ; i<m ; ++i )
    {
        for ( int j=0 ; j<n ; ++j )
        {
            for ( int l=0 ; l<n ; ++l )
            {
                profit[i][j][l] = table[l][i][1] - table[j][i][0];
            }
        }
    }

    int res = 0;
    for ( int i=0 ; i<n ; ++i )
    {
        for ( int j=0 ; j<n ; ++j )
        {
            if ( i != j )
            {
                int a[m];
                for ( int ii=0 ; ii<m ; ++ii ) a[ii] = ii;

                //sort
                for ( int ii=0 ; ii<m ; ++ii )
                {
                    for ( int jj=ii+1 ; jj<m ; ++jj )
                    {
                        if ( profit[a[ii]][i][j] < profit[a[jj]][i][j] )
                        {
                            swap(a[ii], a[jj]);
                        }
                    }
                }

                int buy = k;
                int total = 0;
                for ( int ii=0 ; ii<m ; ++ii )
                {
                    if ( profit[a[ii]][i][j] > 0 )
                    {
                        int b = min(buy, table[i][a[ii]][2]);
                        buy -= b;
                        total += b * profit[a[ii]][i][j];
                    }
                }
                res = max(res, total);
            }
        }
    }

    cout << res << endl;

    return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>

using namespace std;

typedef unsigned long long ull;
typedef pair<int,int> pii;
#define mp make_pair

struct Planet
{
    vector<int> b, s, c;

    void add(int bb, int ss, int cc)
    {
        b.push_back(bb);
        s.push_back(ss);
        c.push_back(cc);
    }
};

int n, m, k;
vector<Planet> P;

struct good
{
    int s;
    int b;
    int c;

    good(int b, int s, int c) : b(b), c(c), s(s) {}

    bool operator <(good g)
    {
        int p1 = s - b,
            p2 = g.s - g.b;
        if (p1 == p2)
            return c > g.c;
        return p1 > p2;
    }
};

int solve(int i, int j)
{
    vector<good> g;
    for (int q = 0; q < m; ++q)
    {
        if (P[i].c[q] == 0)
            continue;
        g.push_back(good(P[i].b[q], P[j].s[q], P[i].c[q]));
    }

    sort(g.begin(), g.end());

    int left(k), need(0), profit(0);
    for (int q=0; q<g.size(); ++q)
    {
        if (left == 0) break;
        if (g[q].b < g[q].s)
        {
            int bo = min(g[q].c, left);
            left -= bo;
            need += bo * g[q].b;
            profit += bo * g[q].s;
        }
    }

    return profit - need;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    string s;
    cin >> n >> m >> k;
    for (int i=0; i<n; ++i)
    {
        cin >> s;
        P.push_back(Planet());
        for (int j=0; j<m; ++j)
        {
            int s, b, c;
            cin >> b >> s >> c;
            P.back().add(b, s, c);
        }
    }

    int result = 0, r;
    for (int i=0; i<n; ++i)
    {
        for (int j=0; j<n; ++j)
        {
            if (i != j)
            {
                r = solve(i, j);
                result = max(result, r);
            }
        }
    }

    cout << result;
    return 0;
}


// C.cpp : Defines the entry point for the console application.
//

#include <stdio.h>
#include <cmath>
#include <map>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
#include <iostream>
#include <cstring>
#include <string>

using namespace std;

int a[11][102];
int b[11][102];
int c[11][102];
int d[102],cnt[102];

int dp[101];

int main()
{
	int n,m,k;
	char name[20],b2;
	scanf("%d%d%d",&n,&m,&k);
	int res=-12;
	int maxi,id;

	int a1,b1,c1;
	for(int i=0;i<n;i++)
	{
		scanf("%1c",&b2);
		scanf("%s",&name);
		for(int j=0;j<m;j++)
		{
			scanf("%d%d%d",&a1,&b1,&c1);
			a[i][j]=a1;
			b[i][j]=b1;
			c[i][j]=c1;
		}
	}//for(int i=0;i<n;i++)

	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(i!=j)
			{
				for(int h=0;h<m;h++)
				{
					d[h]=b[j][h]-a[i][h];
					cnt[h]=c[i][h];
				}

				for(int h=0;h<k;h++)
				{
					dp[h]=-1;
				}

				dp[0]=0;

				for(int h=1;h<=k;h++)
				{
					maxi=0;
					id=-1;
					for(int g=0;g<m;g++)
					{
						if(cnt[g]>0 && maxi<d[g])
						{
							maxi=d[g];
							id=g;
						}
					}

					dp[h]=dp[h-1]+maxi;
					cnt[id]--;
				}//for(int h=0;h<k;h++)

				for(int h=0;h<=k;h++)
				{
					if(dp[h]>res)
					{
						res=dp[h];
					}
				}
			}//if(i!=j)
		}
	}

	cout<<res;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>

typedef struct trip{
    ll a,b,c;
}trip;

bool comp(pll a,pll b){
    return a.first>b.first;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll n,m,k;
    cin>>n>>m>>k;
    // each planet has name and a vector of triplets
    // a=buy,b=sell,c=no.of items
    string sl;
    ll a1,b1,c1;
    vector<vector<trip>> planets;
    for(ll i=0;i<n;i++){
        vector<trip> temp(m);
        cin>>sl;
        for(ll j=0;j<m;j++){
            cin>>temp[j].a>>temp[j].b>>temp[j].c;
        }
        planets.pb(temp);
    }
    ll maxprof = 0;
    // ll i=0,j=1;
    for(ll i=0;i<n;i++){
        for(ll j=0;j<n;j++){
            vector<pll> tv;
            if(i!=j){
                for(ll it = 0;it<m;it++){
                    tv.pb(mp(planets[j][it].b-planets[i][it].a,planets[i][it].c));
                    // cout<<tv[it].first<<' '<<tv[it].second<<endl;
                }
                sort(tv.begin(),tv.end(),comp);
                ll k1=k,it=0,prof=0;
                while(k1>0 && it<m && tv[it].first>0){
                    ll q=min(tv[it].second,k1);
                    prof += q*tv[it].first;
                    k1 -= q;
                    it++;
                }
                // cout<<i<<' '<<j<<' '<<prof<<endl;
                maxprof = max(maxprof,prof);
            }
        }
    }
    cout<<maxprof<<endl;
}


#include <cstdio>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;

const int nmax = 100111;

int n , m , k , buy[200][200] , sell[200][200] , val[200][200] , maxval = 0;
string s;

int Try(int from , int to)
{
    int used = 0;
    int pr = 0;
    int lf[200];
    for (int i = 1 ; i <= m ; i ++ )
        lf[i] = val[from][i];
    while ( used != k )
    {
        int best = -1;
        for (int i = 1 ; i <= m ; i ++ )
            if ( lf[i] != 0 && ((sell[to][best] - buy[from][best]) < (sell[to][i] - buy[from][i])  || best == -1) && (sell[to][i] - buy[from][i]) > 0 )
                best = i;
        if ( best == -1 )
            break;
        int get = min(lf[best] , k - used);
        used += get;
        lf[best] -= get;
        pr += get * (sell[to][best] - buy[from][best]);
    }
    return pr;
}

int main()
{
//("input.txt","r",stdin);
//("output.txt","w",stdout);
scanf("%d%d%d",&n,&m,&k);
for (int i = 1 ; i <= n ; i ++ )
{
    cin >> s;
    for (int j = 1 ; j <= m ; j ++ )
        scanf("%d%d%d",&buy[i][j],&sell[i][j],&val[i][j]);
}
for (int i = 1 ; i <= n ; i ++ )
    for (int j = 1 ; j <= n ; j ++ )
        if ( i != j )
        maxval = max(maxval , Try(i , j) );
cout << maxval << endl;
return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <math.h>
using namespace std;

struct t{
       int a, b, c;
};

struct delt{
       int delta, kol;
};

bool cmp( delt a, delt b )
{
     return a.delta < b.delta ;
}

main(){
              int n, m, k, i, j, l, ans = 0;
       cin>>n>>m>>k;
       string x;

       vector < vector < t > > tov( n, vector < t > (m) );

       vector < delt > Delta( m );

       for( i=0; i<n; i++ )
       {
            cin>>x;
            for( j=0; j<m; j++ )
              cin>>tov[i][j].a>>tov[i][j].b>>tov[i][j].c ;
       }

       for( i=0; i<n; i++ )
         for( j=0; j<n; j++ )
           if( j!=i )
           {
               int CUR_ANS = 0;

               for( l=0; l<m; l++ )
               {
                 Delta[l].delta = tov[i][l].a - tov[j][l].b ;
                 Delta[l].kol = tov[i][l].c ;
               }

               sort( Delta.begin(), Delta.end(), &cmp );

               int CUR_K = k;

               for( l=0; l<m && CUR_K>0 ; l++ )
               {
                    if( Delta[l].delta > 0 )
                      break;

                    int MAX_NUM_CUR = min( Delta[l].kol, CUR_K );

                    CUR_ANS += MAX_NUM_CUR * (-Delta[l].delta);

                    CUR_K -= MAX_NUM_CUR;

               }

               if( CUR_ANS > ans )
                 ans = CUR_ANS;
           }

       cout<<ans;
}


#include <vector>
#include <numeric>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <limits>
#include <iomanip>

using namespace std;

#define FOR(i,a,b)		for(int i=(a),_b=(b);i<(_b);++i)
#define FORD(i,a,b)		for(int i=(a),_b=(b);i>(_b);--i)
#define pb			push_back
#define mp			make_pair
#define	all(c)			(c).begin(),(c).end()
#define	tr(c,i)	for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define	present(c,x)		((c).find(x) != (c).end())
#define	cpresent(c,x)		(find(all(c),x) != (c).end())

typedef long long			ll;
typedef unsigned long long	ull;
typedef unsigned char	 	byte;
typedef vector<int>			vi;
typedef pair<int, int>		pii;
typedef pair<ll, ll>		pll;
typedef vector<pii>			vpii;

const int N = 25;

typedef struct {
	int a,b,c;
} planet;

int main(int argc, char *argv[])
{
#ifndef ONLINE_JUDGE
	freopen(argv[1],"r",stdin);
#endif
#ifndef ONLINE_JUDGE
	ifstream cin(argv[1]);
#endif
#if 0
	ofstream cout(argv[2]);
#endif
	int n,m,K;
	cin >> n >> m >> K;
	planet p[n][m];
	string s;
	FOR(i,0,n) {
		cin >> s;
		FOR(j,0,m) cin >> p[i][j].a >> p[i][j].b >> p[i][j].c;
	}
	int best = 0;
	FOR(i,0,n) FOR(j,0,n) {
		if (j == i) continue;
		pii tmp[m];
		FOR(k,0,m) {
			tmp[k].first = p[j][k].b-p[i][k].a;
			tmp[k].second = k;
		}
		sort(tmp,tmp+m);
		int s = 0;
		int profit = 0;
		FORD(k,m-1,-1) {
			if (s >= K) break;
			if (tmp[k].first <= 0) break;
			int l = tmp[k].second;
			int buy = min(K-s,p[i][l].c);
			profit += buy*tmp[k].first;
			s += buy;
		}
		best = max(best,profit);
	}
	cout << best << endl;

	return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
struct ban
{
	int a,b,c;
};
struct ban1
{
	int x,d;
};
bool operator<(const ban1& a,const ban1& b)
{
	return a.d>b.d;
}

int n,m,k;
string s;
ban a[12][102];
ban1 b[102];
int ans;
int main()
{
	int i,j,ii,jj;
	cin>>n>>m>>k;
	int ck=k;
	for(i=0;i<n;++i)
	{
		cin>>s;
		for(j=0;j<m;++j)
		{
			cin>>a[i][j].a>>a[i][j].b>>a[i][j].c;
		}
	}
	for(i=0;i<n;++i)
	{
		for(j=0;j<n;++j)
		{
			if(j==i)
				continue;
			k=ck;
			int yans=0;
			for(ii=0;ii<m;++ii)
			{
				b[ii].x=ii;
				b[ii].d=-a[i][ii].a+a[j][ii].b;
			}
			sort(b,b+m);
			for(ii=0;ii<m;++ii)
			{
				if(b[ii].d<=0)
					break;
				int inchqan=a[i][b[ii].x].c;
				if(k>=inchqan)
				{
					k-=inchqan;
					yans+=inchqan*b[ii].d;
				}
				else
				{
					inchqan=k;
					yans+=inchqan*b[ii].d;
					break;
				}
			}
			ans=max(ans,yans);
		}
	}
	cout<<ans<<endl;
//	system("pause");
	return 0;
}


#include<set>
#include<cmath>
#include<vector>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

struct profit
{
    int p;
    int num;
}pro[105];

bool cmp(profit a,profit b)
{
    return (a.p>b.p);
}

int main()
{
    int n,m,k,buy[15][105],sell[15][105],num[15][105];
    while(cin>>n>>m>>k)
    {
        for (int i=0;i<n;i++)
        {
            string pn;
            cin>>pn;
            for (int j=0;j<m;j++)
                cin>>buy[i][j]>>sell[i][j]>>num[i][j];
        }
        int ans(0);
        for (int i=0;i<n;i++)
            for (int j=0;j<n;j++)
            {
                if (i==j) continue;
                int sum(0);
                for (int z=0;z<m;z++)
                {
                    pro[z].p=sell[j][z]-buy[i][z];
                    pro[z].num=z;
                }
                sort(pro,pro+m,cmp);
                int kk=k;
                for (int z=0;z<m;z++)
                {
                    if (pro[z].p<0) break;;
                    if (num[i][pro[z].num]<=kk)
                    {
                        sum+=pro[z].p*num[i][pro[z].num];
                        kk-=num[i][pro[z].num];
                    }
                    else
                    {
                        sum+=pro[z].p*kk;
                        kk=0;
                    }

                }
                if (sum>ans) ans=sum;
//                cout<<i<<" "<<j<<" "<<sum<<endl;
//                for (int z=0;z<m;z++)
//                    cout<<pro[z].p<<" ";
//                cout<<endl;
            }
        cout<<ans<<endl;
    }
}


//Solution by Zhussupov Nurlan
#include <iostream>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <ctime>

using namespace std;

typedef long long LL;
typedef map<string , int> MSI;
typedef vector<int> VI;

#define PB(x) push_back(x)
#define sqr(x) ((x)*(x))
#define F first
#define S second
#define SZ(t) ((int)t.size())
#define len(t) ((int)t.length())
#define base 10
#define fname ""
#define sz 200
#define EPS (1e-8)
#define INF ((int)1e9 + 9)
#define write(xx) printf("%d" , xx);
#define readln(xx) getline(cin , xx)
#define read(xx) scanf("%d" , &xx)
#define for(xx1 , yy1 , zz1) for(int zz1 = xx1 ; zz1 <= yy1 ; zz1++)

const double PI  = acos(-1.0);

int n , m , k , a[sz][sz] , b[sz][sz] , c[sz][sz] , o , ans , kk;
string s;
pair <int , int > d[sz];

int main(){
	//freopen(fname"in", "r", stdin);
	//freopen(fname"out", "w", stdout);

	cin >> n >> m >> k;

	for (1 , n , i)
	{
		cin >> s;
		for (1 , m , j)
			cin >> a[i][j] >> b[i][j] >> c[i][j];
	}

	for (1 , n , i)
		for (1 , n , j)
		if (i != j)
		{
			for (1 , m , t)
			{
				d[t].F = -(b[j][t] - a[i][t]);
				d[t].S = c[i][t];
			}
			sort(d + 1 , d + 1 + m);
			kk = k;
			o = 0;
			for (1 , m , t)
			{
				d[t].F = -d[t].F;
				if (d[t].F <= 0) break;
				while (kk > 0 && d[t].S > 0)
				{
					o += d[t].F;
					kk--;
					d[t].S--;
				}
			}
			ans = max(o , ans);
		}
	cout << ans;

    	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

struct stock
{
    int sell,buy,q;
};
struct item
{
    int prof,q;
};

stock planets[11][101];
int n,m,k;

bool SortEm(item a,item b)
{
    return (a.prof>b.prof);
}

int Profit(int buyplanet,int sellplanet)
{
    item objects[101];
    int i;
    int totalprofit=0;
    int usedspace=0;
    int webuy;

    for (i=1;i<=m;i++)
    {
        objects[i].q=planets[buyplanet][i].q;
        objects[i].prof=planets[sellplanet][i].sell-planets[buyplanet][i].buy;
    }
    sort(objects+1,objects+1+m,SortEm);

    for (i=1;i<=m;i++)
    {
        if (objects[i].prof<=0)
        break;

        if (usedspace+objects[i].q<k)
        {
            usedspace=usedspace+objects[i].q;
            totalprofit=totalprofit+objects[i].q*objects[i].prof;
        }
        else
        {
            webuy=k-usedspace;
            totalprofit=totalprofit+objects[i].prof*webuy;
            break;
        }
    }
    return totalprofit;
}

int main()
{
    string useless;
    int i,j;
    int maxprofit=0;
    int currprofit;

    cin>>n>>m>>k;

    for (i=1;i<=n;i++)
    {
        cin>>useless;
        for (j=1;j<=m;j++)
        {
            cin>>planets[i][j].buy;
            cin>>planets[i][j].sell;
            cin>>planets[i][j].q;
        }
    }
    for (i=1;i<=n;i++)
    {
        for (j=1;j<=n;j++)
        {
            if (i==j)
            continue;

            currprofit=Profit(i,j);
            if ( currprofit>maxprofit )
            maxprofit=currprofit;

        }
    }
    cout<<maxprofit<<endl;
    return 0;
}


#include <iostream>
#include <map>
#include <string>
#include <string.h>
#include <algorithm>

using namespace std;

int sell[12][102];
int buy[12][102];
int rem[12][102];

int n,m,cap,prf;

struct ans{
	int pl,jens;
};
//
//int findMax(){
//	int max=0;
//	int maxInd;
//	for(int i=0;i<m;i++){
//		int best=30000;
//		int bestInd;
//		for(int j=0;j<n;j++){
//			if(rem[i][j] && (buy[i][j]<best) ){
//				best=buy[i][j];
//				bestInd=j;
//			}
//		}
//		if(best<3000){
//			if(sell[i]-buy[i][bestInd]>max){
//				max=sell[i][be]-buy[i][bestInd];
//				maxInd=i;
//			}
//		}
//	}
//	if(max>0){
//		return maxInd;
//	}
//	else
//		return -1;
//}

int calc(int from,int to){
	int rcap=cap;
	int ans=0;
	bool used[103]={false};
	while(rcap>0){
		int max=0;
		int maxInd;
		for(int i=0;i<m;i++){
			if(!used[i] && sell[to][i]-buy[from][i]>max){
				max=sell[to][i]-buy[from][i];
				maxInd=i;
			}
		}
		if(max==0)
			return ans;
		used[maxInd]=true;
		int val= rem[from][maxInd]>rcap ? rcap : rem[from][maxInd];
		rcap-=val;
		ans+=val*(sell[to][maxInd]-buy[from][maxInd]);

	}
	return ans;
}

int main(){
	//freopen("inf.txt","r",stdin);

	cin>>n>>m>>cap;

	string inp;
	int sl;

	for(int i=0;i<n;i++){
		cin>>inp;
		for(int j=0;j<m;j++){
			scanf("%d%d%d",&buy[i][j],&sell[i][j],&rem[i][j]);
		}
	}

	int res;
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++){
			if(i==j)
				continue;
			 res=calc(i,j);
			 if(res>prf)
				 prf=res;

		}
		cout<<prf<<endl;
/*
	while(cap>0){
		int ind=findMax();
		if(ind==-1)
			break;
		int min=4000,minInd;
		for(int i=0;i<n;i++){
			if(buy[ind][i]<min && rem[ind][i]){
				min=buy[ind][i];
				minInd=i;
			}
		}
		if(min==4000)
			break;
		prf+=rem[ind][minInd]*(sell[ind]-buy[ind][minInd]);
		cap-=rem[ind][minInd];
		rem[ind][minInd]=0;
	}

	cout<<prf<<endl;
*/

	return 0;
}


#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#define pi (2*acos(0))
#define ll long long int

using namespace std;

int c[15][105],s[15][105],cap[15][105],n,m,k;
vector <pair <int,int> > vec;

int calc(int x,int y)
{
    int i,j,r=0,f,sc,q=k;

    vec.clear();

    for(i=0;i<m;i++)
    {
        vec.push_back(   make_pair(s[y][i]-c[x][i] , cap[x][i])  );
    }

    sort(vec.begin(),vec.end());
    reverse(vec.begin(),vec.end());

    for(i=0;i<vec.size() && q;i++)
    {
        f=vec[i].first;
        sc=vec[i].second;

        if(f<0) continue;

        if(sc>=q)
        {
            r+=q*f;
            q=0;
        }

        else
        {
            r+=sc*f;
            q-=sc;
        }
    }

    return r;
}

int main()
{
    int i,j,p,r=0;
    char str[15];

    scanf("%d %d %d",&n,&m,&k);

    for(i=0;i<n;i++)
    {
        scanf("%s",str);

        for(j=0;j<m;j++)
        {
            scanf("%d %d %d",&c[i][j],&s[i][j],&cap[i][j]);
        }
    }

    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            if(i==j) continue;

            r=max(r,calc(i,j));
        }
    }

    printf("%d\n",r);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;

int const N = 10 + 5, M = 100 + 20;
int n, m, k, a[N][M], b[N][M], c[N][M], ans;
string s;

int main() {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cin >> n >> m >> k;
  for (int i = 0; i < n; i ++){
    cin >> s;
    for (int j = 0; j < m; j ++) cin >> a[i][j] >> b[i][j] >> c[i][j];
  }

  for (int p1 = 0; p1 < n; p1 ++){
    for (int p2 = 0; p2 < n; p2 ++){
      vector <pii> v;

      for (int i = 0; i < m; i ++) v.push_back({max(0, b[p2][i] - a[p1][i]), c[p1][i]});

      sort(v.begin(), v.end());
      int rem = k, pr = 0;
      for (int i = v.size() - 1; i >= 0; i --){
	if (rem > v[i].second) pr += v[i].first * v[i].second, rem -= v[i].second;
	else pr += v[i].first * rem, rem = 0;
      }

      ans = max(ans, pr);
    }
  }

  return cout << ans << endl, 0;
}


#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<iomanip>
#include<vector>
#include<map>
#include<deque>
#include<stack>
#include<queue>
#include<list>
#include<algorithm>
using namespace std;
struct sell
{
    int profit,stock;  //盈利，存量
};
sell pro[110];
int main()
{
    string name;
    int n,m,k,kk,i,j,l,t,p,s,num,max_sum;
    int sum;
    int a[11][101],b[11][101],c[11][101];
    while(cin>>n>>m>>kk)
    {
        for(i=0;i<n;i++)
        {
            cin>>name;
            for(j=0;j<m;j++)
            {
                cin>>a[i][j]>>b[i][j]>>c[i][j];
            }
        }
        max_sum=0;
        for(i=0;i<n;i++)
        {
            for(t=0;t<n;t++)
            {
                if(t==i)
                    continue;
                num=0;
                for(j=0;j<m;j++)
                {
                    p=b[t][j]-a[i][j];
                    s=c[i][j];
                    if(p>0&&s>0)
                    {
                        pro[num].profit=p;
                        pro[num].stock=s;
                        num++;
                    }
                }
                sum=0;
                k=kk;
                while(k>0)
                {
                    int max=0,tag=-1;
                    for(l=0;l<num;l++)
                    {
                        if(pro[l].profit>max)
                        {
                            max=pro[l].profit;
                            tag=l;
                        }
                    }
                    if(tag==-1)
                        break;
                    pro[tag].profit=0;
                    s=pro[tag].stock;
                    if(k>=s)
                    {
                        sum=sum+max*s;
                        k=k-s;
                    }
                    else
                    {
                        sum=sum+max*k;
                        k=0;
                    }
                 }
                if(sum>max_sum)
                    max_sum=sum;
            }
        }
        cout<<max_sum<<endl;
    }
    return 0;
}


#define nganggo using
#define nemspes namespace
#define standar std
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<cstdlib>
#include<cctype>
#include<bitset>
#include<string>
#include<map>
#include<complex>
#include<set>

#define FOR(_i,_n,_m) for(int (_i)=(_n),_t=(_m);_i<(_t);++(_i))
#define FORN(_i,_n,_m) for(int (_i)=(_n),_t=(_m);_i<=(_t);++(_i))
#define FORD(_i,_n,_m) for(int (_i)=(_n),_t=(_m);_i>=(_t);--(_i))
#define FORLL(_i,_n,_m) for(long long (_i)=(_n),_t=(_m);_i<(_t);++(_i))
#define FORNLL(_i,_n,_m) for(long long (_i)=(_n),_t=(_m);(_i)<=(_t);++(_i))
#define FORDLL(_i,_n,_m) for(long long (_i)=(_n),_t=(_m);(_i)>=(_t);--(_i))
#define FOREACH(_i,_a) for (__typeof(_a.begin()) _i=_a.begin();_i!=_a.end();++_i)
#define RESET(_a,_value) memset(_a,_value,sizeof(_a))
#define debugln clog << "----OK----" << endl;
#define debug(_a) clog << "Value of " <<  #_a << " is: " << (_a) << endl;
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define ff first
#define ss second
#define mp make_pair
#define SIZE(_a) (int)_a.size()
#define VSORT(_a) sort(_a.begin(),_a.end())
#define SSORT(_a,_val) sort(_a,_a+(_val))
#define ALL(_a) _a.begin(),_a.end()
#define MAX(_a,_b) (((_a)>(_b))?(_a):(_b))
#define MIN(_a,_b) (((_a)<(_b))?(_a):(_b))

nganggo nemspes standar;

const int dr[]={ 1, 0,-1, 0, 1, 1,-1,-1};
const int dc[]={ 0, 1, 0,-1, 1,-1,-1, 1};
const double eps=1e-9;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<ll> vll;
typedef pair<double,double> pdd;
typedef vector<pdd> vpdd;
const int INF=0x7FFFFFFF;
const ll INFLL=0x7FFFFFFFFFFFFFFFLL;
const double pi=acos(-1);

struct point_i
{
	int x,y;
	point_i (int _x=0,int _y=0) {x=_x;y=_y;}
};

struct point
{
	double x,y;
	point (double _x=0,double _y=0) {x=_x;y=_y;}
	bool operator < (const point &other) const
	{
		if (fabs(x-other.x)<eps)
			return y<other.y;
		return x<other.x;
	}
};

struct line_s
{
	point beg,end;
	line_s () {beg=point(0,0);end=point(0,0);}
	line_s (point a,point b) : beg(a),end(b) {}
	bool intersect (const line_s &other,point &ans)
	{
		double mua,mub;
		double denom,numera,numerb;

		denom  = (other.end.y-other.beg.y) * (end.x-beg.x) - (other.end.x-other.beg.x) * (end.y-beg.y);
		numera = (other.end.x-other.beg.x) * (beg.y-other.beg.y) - (other.end.y-other.beg.y) * (beg.x-other.beg.x);
		numerb = (end.x-beg.x) * (beg.y-other.beg.y) - (end.y-beg.y) * (beg.x-other.beg.x);

		if (denom==0 && numera==0 && numerb==0) return 0;

		mua=numera/denom;
		mub=numerb/denom;
		if (mua<0 || mua>1 || mub<0 || mub>1)
		{
			ans.x=0;
			ans.y=0;
			return 0;
		}
		ans.x=beg.x+mua*(end.x-beg.x);
		ans.y=beg.y+mua*(end.y-beg.y);
		return 1;
	}
};

struct line
{
	double a,b,c,len;
	line () {a=b=c=0.0;}
	line (const point &a_,const point &b_)
	{
		if (fabs(a_.x-b_.x)<eps)
		{
			a=1.0;
			b=0.0;
			c=-a_.x;
		}
		else
		{
			a=-(double)(a_.y-b_.y)/(a_.x-b_.x);
			b=1.0;
			c=-(double)(a_.x*a)-(double)(a_.y*b);
		}
		if (fabs(a)<eps) a=fabs(a);
		if (fabs(b)<eps) b=fabs(b);
		if (fabs(c)<eps) c=fabs(c);
		double x=a_.x-b_.x,y=a_.y-b_.y;
		len=sqrt((x*x)+(y*y));
	}
	bool parallel (const line &other)
	{
		return (fabs(a-other.a)<eps && fabs(b-other.b)<eps);
	}
	bool same (const line &other)
	{
		return (*this).parallel(other) && fabs(c-other.c)<eps;
	}
};

//using sokokaleb's template v2.2.4

typedef pair<pll,ll> pl3;
typedef vector<pl3> vpl3;

ll n,m,k,a,b,c;
ll ans;
string st;
vector<vpl3> vc;

int main()
{
	// ans=-INFLL+3;
	ans=0LL;
	cin >> n >> m >> k;
	vpl3 z;
	z.clear();
	vc.assign(n+1,z);
	FOR (iz,0,n)
	{
		cin >> st;
		FOR (i,0,m)
		{
			cin >> a >> b >> c;
			vc[iz].pb(mp(mp(a,b),c));
		}
	}
	FOR (iz,0,n)
	{
		FOR (jz,0,n)
		if (iz==jz) continue;
		else
		{
			vpll tmp;
			tmp.clear();
			FOR (i,0,m) tmp.pb(mp(vc[jz][i].ff.ss-vc[iz][i].ff.ff,vc[iz][i].ss));
			sort(ALL(tmp),greater<pll>());
			ll anz=0,tmpk=k;
			FOR (i,0,SIZE(tmp))
			{
				if (tmp[i].ff<0) break;
				if (tmp[i].ss<tmpk)
				{
					tmpk-=tmp[i].ss;
					anz+=tmp[i].ss*tmp[i].ff;
				}
				else
				{
					anz+=tmpk*tmp[i].ff;
					break;
				}
			}
			if (anz>ans) ans=anz;
		}
	}
	cout << ans << endl;
	return 0;
}


#include<cstdio>
#include<algorithm>
int n,m,k;
char w[10001];
int a[11][101],b[11][101],c[11][101];
struct wang
{
	int z;
	int v;
};
bool cmp(wang a,wang b)
{
	if(a.z>b.z) return 1;
	else return 0;
}
wang joy[1001];
int main()
{
	int ans;
	while(scanf("%d%d%d",&n,&m,&k)==3)
	{
		ans=0;
		for(int i=0;i<n;i++)
		{
			scanf("%s",w);
			for(int j=0;j<m;j++)
			{
				scanf("%d%d%d",&a[i][j],&b[i][j],&c[i][j]);
			}
		}
		for(int i=0;i<n;i++)//買
		{
			for(int j=0;j<n;j++)//賣
			{
				 if(i==j) continue;
				 for(int p=0;p<m;p++)
				 {
					joy[p].z=b[j][p]-a[i][p];
					if(joy[p].z<0) joy[p].z=0;
					joy[p].v=c[i][p];
				 }
   			     std::sort(joy,joy+m,cmp);
				 int t=0,x=0;
				 for(int p=0;p<m;p++)
				 {
					if(t+joy[p].v<k)
					{
						x=x+joy[p].z*joy[p].v;
						t=t+joy[p].v;
					}
					else if(t+joy[p].v>=k)
					{
						x=x+joy[p].z*(k-t);
						break;
					}
				}
				if(x>ans)
				{
					ans=x;
				}
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}


#include <stdio.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <list>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
using namespace std;
int n,m,k;
int x,y,z;

int dp[101];
char name[11];

int maxgain=0;
int tekgain=0;

struct diff
{
       int id;
       int amt;
};
diff D[101];
bool comp_less(diff a, diff b)
{
     if (a.amt!=b.amt) return (a.amt>b.amt);
     return (a.id>b.id);
}

struct item
{
       int buy;
       int sell;
       int amt;
};
item It[11][101];
int main()
{
    scanf("%d%d%d",&n,&m,&k);
    for (int i=0;i<n;i++)
    {
        scanf("%s",&name);
        for (int j=0;j<m;j++)
        {
            scanf("%d%d%d",&x,&y,&z);
            It[i][j].buy=x;
            It[i][j].sell=y;
            It[i][j].amt=z;
        }
    }
    for (int i=0;i<n;i++)
    {
        for (int j=0;j<n;j++)
        {
            if (i!=j)
            {
                     tekgain=0;
                     for (int K=0;K<m;K++)
                     {
                         D[K].id=K;
                         D[K].amt= It[j][K].sell - It[i][K].buy;
                     }
                     sort(D,D+m,comp_less);
                     int loaded=0;
                     for (int it=0;it<m&&loaded<k;it++)
                     {
                         if (D[it].amt<=0) break;
                         else
                         {
                             int it1=D[it].id;
                             if (It[i][it1].amt<=k-loaded)
                             {
                               tekgain+=D[it].amt*It[i][it1].amt;
                               loaded+=It[i][it1].amt;
                             }
                             else
                             {
                               int delta=k-loaded;
                               tekgain+=D[it].amt*delta;
                               loaded+=delta;
                             }
                         }
                     }
                     if (tekgain>maxgain) maxgain=tekgain;
            }
        }
    }
    printf("%d\n",maxgain);
    return 0;
}


#include<iostream>
#include<string>
#include<vector>
#include <cmath>
#include<algorithm>
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define LL long long
using namespace std;
typedef pair<int, int> pii;
const double eps = 1e-9;
int a[11][111],b[11][111],c[11][111];
int main()
{
	int n,m,k;
	int res = 0;
	cin>>n>>m>>k;
	string s;
	for(int i = 0; i < n; i++)
	{
		cin>>s;
		for(int j = 0; j < m; j++)
			cin>>a[i][j]>>b[i][j]>>c[i][j];
	}
	vector<pii> v(m);
	for(int i = 0; i < n; i++)
		for(int j = 0; j < n; j++)
		{
			if (i == j) continue;
			for(int r = 0; r < m; r++)
			{
				v[r].first = b[j][r] - a[i][r];
				v[r].second = c[i][r];
			}
			sort(all(v));
			int K = k,sum = 0;
			for(int r = m - 1; r >= 0; r--)
			{
				if (v[r].first > 0)
				{
					if (v[r].second >= K)
					{
						sum += K * v[r].first;
						break;
					}
					K -= v[r].second;
					sum += v[r].second * v[r].first;
				} else break;
			}
			res = max(res,sum);
		}
	cout<<res<<endl;
 	return 0;
}


#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <map>
#include <deque>
#include <set>
using namespace std;

#define sz size()
#define FOR(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define ROF(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define rep(i,n) for (int (i) = 0; (i) < (n); ++(i))
#define fe(i,a) for (int (i) = 0; (i) < int((a).size()); ++(i))
#define C(a) memset((a),0,sizeof(a))
#define inf 1000000000
#define pb push_back
#define ppb pop_back
#define all(c) (c).begin(), (c).end()
#define pi 2*acos(0.0)
#define sqr(a) (a)*(a)
#define mp(a,b) make_pair((a), (b))
#define X first
#define Y second
#define y huy

typedef vector<int> vint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int INF=2000000000;
 int a[100][3000],b[100][3000],c[100][3000];
int main( ) {
    //freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
  //  freopen("input.txt","r",stdin);
    int n,cnt=0,m,k;
    cin>>n>>m>>k;
    rep(i,n){
        string s;cin>>s;
        rep(j,m){
            cin>>a[i][j]>>b[i][j]>>c[i][j];
        }

    }
    int ans=0;
    rep(i,n)rep(j,n)if(i^j){
        vector<pii > v(m);
        rep(u,m)v[u]=mp(b[j][u]-a[i][u],c[i][u]);
        sort(all(v));
        reverse(all(v));
        int u=0,h=0;
        for(int g=0;g<k && u<m;){
            while(g<k && v[u].second){
                g++; v[u].second--;
                h+=v[u].first;
                ans=max(ans,h);
            }
            u++;
        }
    }
    cout<<ans;

    return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

#define F first
#define S second
#define MP make_pair
typedef pair<int, int> pii;

const int MAXn = 10, MAXm = 100;
int n, m, k;
int b[MAXn][MAXm], s[MAXn][MAXm], r[MAXn][MAXm];
string str;
long long ans;
pii ez[MAXm];
int rem;
long long prof;

bool cmp(pii x, pii y)
{
	return x.F>y.F;
}

int main()
{
	cin >> n >> m >> k;
	for(int i=0; i<n; i++)
	{
		cin >> str;
		for(int j=0; j<m; j++)
			cin >> b[i][j] >> s[i][j] >> r[i][j];
	}

	for(int i=0; i<n; i++)
		for(int j=0; j<n; j++)
		{
			for(int z=0; z<m; z++)
				ez[z].F = s[j][z]-b[i][z], ez[z].S = r[i][z];
			sort(ez, ez+m, cmp);

			rem = k, prof = 0;
			for(int z=0; z<m and ez[z].F>0; z++)
			{
				prof += min(rem, ez[z].S)*ez[z].F;
				rem -= min(rem, ez[z].S);
			}

			ans = max(ans, prof);
		}

	cout << ans << endl;

	return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<map>
#include<string>
#include<vector>
#include<stack>
#include<list>
#include<queue>
#include<set>
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define INF 987654321
typedef __int64 LL;
using namespace std;
/////////////////////////////////////////////////
#define MAXN 110
int a[MAXN][MAXN],b[MAXN][MAXN],c[MAXN][MAXN];
char s[MAXN];
bool vis[MAXN];
int n,m,t;
int Sale(int x,int y,int res)
{
	bool flag;
	int ans=0,i,big,id,cnt;
	memset(vis,false,sizeof(vis));
	flag=true;
	while(flag&&res)
	{
		big=0;
		flag=false;
		for(i=1;i<=m;i++)
		{
			if(!vis[i])
			{
				flag=true;
				if(b[y][i]-a[x][i]>big)
				{
					big=b[y][i]-a[x][i];
					id=i;
				}
			}
		}
		if(big==0)
			break;
		cnt=MIN(res,c[x][id]);
		ans+=cnt*big;
		res-=cnt;
		vis[id]=true;
	}
	return ans;
}
int main()
{
	int i,j,k,ans,temp;
	while(~scanf("%d%d%d",&n,&m,&t))
	{
		for(i=1;i<=n;i++)
		{
			scanf(" %s",s);
			for(j=1;j<=m;j++)
				scanf("%d%d%d",&a[i][j],&b[i][j],&c[i][j]);
		}
		ans=0;
		for(i=1;i<=n;i++)
		{
			for(j=1;j<=n;j++)
			{
				temp=Sale(i,j,t);
				ans=MAX(ans,temp);
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}


// rc.cpp
//

#include <math.h>
#include <string.h>

#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <algorithm>
#include <numeric>

using namespace std;

typedef unsigned char uchar;
typedef unsigned int uint;
typedef unsigned __int64 uint64;

#define PI 3.1415926535897932384626433832795
#define EPS 1E-8

int p[101][101],
	ai[1000],
	bi[1000];
uint ci[1000];

int main(int argc, char* argv[])
{
	uint n, m, k;
	cin >> n >> m >> k;

	string u;
	uint o = 0;
	for (uint i = 0; i < n; ++i)
	{
		cin >> u;
		for (uint j = 0; j < m; ++j)
		{
			uint ix = o + j;
			cin >> ai[ix] >> bi[ix] >> ci[ix];
		}

		o += m;
	}

	uint e = n * m;
	int	ma = 0;
	for (uint u = 0; u < e; u += m)
	{
		for (uint v = 0; v < e; v += m)
		{
			if (u == v)
				continue;
			for (uint i = 1; i <= m; ++i)
			{
				uint ix = u + i - 1;
				for (uint j = 1; j <= k; ++j)
				{
					int mx = p[j][i - 1];
					for (uint x = 1; x <= ci[ix] && x <= j; ++x)
					{
						int mm = p[j - x][i - 1] + (bi[v + i - 1] - ai[ix]) * x;
						if (mm > mx)
							mx = mm;
					}
					p[j][i] = mx;
				}
			}

			if (p[k][m] > ma)
				ma = p[k][m];
		}
	}

	cout << ma << endl;
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <utility>
#include <iostream>
using namespace std;

struct Thing
{
	int a, b, c;
};

struct Planet
{
	string name;
	vector <Thing> things;
};

int main()
{
#ifdef _DEBUG
	freopen("test.in", "a+", stdin);
#endif

	int n, m, k;
	cin >> n >> m >> k;
	vector <Planet> arr(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> arr[i].name;
		arr[i].things.resize(m);
		for (int j = 0; j < m; ++j)
			cin >> arr[i].things[j].a >> arr[i].things[j].b >> arr[i].things[j].c;
	}

	vector < vector < vector < pair <int, int> > > > other (n);
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < n; ++j)
		{
			other[i].push_back(vector < pair <int, int> > (m));
			for (int t = 0; t < m; ++t)
			{
				other[i][j][t].first = arr[j].things[t].b - arr[i].things[t].a;
				other[i][j][t].second = min(k, arr[i].things[t].c);
			}
			sort(other[i][j].begin(), other[i][j].end());
		}
	}

	int cnt = 0;
	int trum, temp_cnt;
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < n; ++j)
		{
			if (i == j)
				continue;
			trum = 0;
			temp_cnt = 0;
			for (int t = m - 1; t >= 0; --t)
			{
				if (other[i][j][t].first < 0)
					continue;
				if (other[i][j][t].second <= k - trum)
				{
					temp_cnt += other[i][j][t].first * other[i][j][t].second;
					trum += other[i][j][t].second;
				}
				else
				{
					temp_cnt += other[i][j][t].first * (k - trum);
					break;
				}
			}
			cnt = max(cnt, temp_cnt);
		}
	}

	cout << cnt;
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
	char temp[11];
	int n,m,k;
	cin >> n >> m >> k;
	int a[10][100],b[10][100],c[10][100];
	for( int i = 0; i < n; i++ )
	{
		cin >> temp;
		for( int j = 0; j < m; j++ )
			cin >> a[i][j] >> b[i][j] >> c[i][j];
	}
	int maxi = 0;
	for( int i = 0; i < n; i++ )
		for( int j = 0; j < n; j++ )
		{
			if( i == j )
				continue;
			vector< pair<int,int> > diff(m);
			for( int t = 0; t < m; t++ )
				diff[t] = make_pair(b[j][t]-a[i][t],t);
			sort(diff.rbegin(),diff.rend());
			int kc = k, cur = 0;
			for( int t = 0; kc > 0 && t < m && diff[t].first > 0 ; t++ )
			{
				cur += min(kc,c[i][diff[t].second])*diff[t].first;
				kc -= min(kc,c[i][diff[t].second]);
			}
			//cout << i << " " << j << " " << cur << endl;
			maxi = max(maxi,cur);
		}
	cout << maxi << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 103;

int a, b, k, n, m;
int memo[N][N];
int visi[N][N];
int turn;
int qt[20][N], be[20][N], cs[20][N];
char str[20];

int dp (int i, int k) {
    if (i == m || k <= 0)
        return 0;

    int & me = memo[i][k];
    if (visi[i][k] == turn)
        return me;
    visi[i][k] = turn;

    me = dp(i+1, k);
    int pr = be[b][i]-cs[a][i];

    if (pr <= 0)
        return me;

    for (int j = 1; j <= min(qt[a][i], k); j++) {
        me = max(me, pr*j + dp(i+1, k-j));
    }

    return me;
}

int main ( ){
    scanf("%d %d %d", &n, &m, &k);
    for (int i = 0; i < n; i++) {
        scanf(" %s", str);
        for (int j = 0; j < m; j++) {
            scanf("%d", &cs[i][j]);
            scanf("%d", &be[i][j]);
            scanf("%d", &qt[i][j]);
        }
    }

    int res = 0;
    for (int i = 0; i < n ; i++) {
        for (int j = 0; j < n; j++) {
            if (i == j)
                continue;
            turn++;
            a = i;
            b = j;
            int val = dp(0, k);
            res = max(res, val);
        }
    }

    printf("%d\n", res);
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

bool lessp(const pair<int,int> a, const pair<int,int> &b){
	return a.first==b.first? a.second>b.second : a.first>b.first;
};

int n,m,k;

struct good{
	int a,b,c;
};

struct planet{
	vector<good> goods;
	planet(){
		goods.resize(m);
	}
};

vector<planet> data;

int main(){
	scanf("%d%d%d",&n,&m,&k);
	data.resize(n);
	for (int i=0; i<n; i++){
		char s[10];
		scanf("%s\n",s);
		for (int j=0; j<m; j++)
			scanf("%d%d%d",&data[i].goods[j].a,&data[i].goods[j].b,&data[i].goods[j].c);
	}
	int ans=0;
	for (int i=0; i<n; i++)
		for (int j=0; j<n; j++)
			if (i!=j){
				vector<pair<int,int> > sprice(m);
				for (int q=0; q<m; q++){
					sprice[q].first=data[j].goods[q].b-data[i].goods[q].a;
					sprice[q].second=data[i].goods[q].c;
				}
				sort(sprice.begin(),sprice.end(),lessp);
				int ck=k,cans=0,i=0;
				while (i<m && sprice[i].first>0 && ck>0){
					cans+=sprice[i].first*min(ck,sprice[i].second);
					ck-=min(ck,sprice[i].second);
					i++;
				}
				ans=max(ans,cans);
			}
	printf("%d\n",ans);
	return 0;
}


#pragma comment(linker, "/STACK:500000000")
#include <functional>
#include <algorithm>
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <sstream>
#include <ctype.h>
#include <stdio.h>
#include <vector>
#include <string>
#include <math.h>
#include <time.h>
#include <queue>
#include <stack>
#include <map>
#include <set>
#define Int long long
#define INF 0x3F3F3F3F
#define eps 1e-10
using namespace std;

vector <int> A;
int a[111][111], b[111][111], c[111][111];
int bs[111], k;

int ff()
{
	int sum = 0;
	sort(A.begin(), A.end(), greater<int>());
	for(int i = 0, sz = min(k, (int)A.size()); i < sz; i++)
		sum += A[i];
	A.clear();
	return sum;
}

int main()
{
	int n, m,  i, j, h, v;
	scanf("%d %d %d", &n, &m, &k);
	for(i = 0; i < n; i++)
	{
		scanf("%*s");
		for(j = 0; j < m; j++)
		{
			scanf("%d %d %d", &a[i][j], &b[i][j], &c[i][j]);
		}
	}
	int res = 0;
	for(i = 0; i < n; i++)
	{
		for(j = 0; j < n; j++)
		{
			if (i != j)
			{
				for(v = 0; v < m; v++)
				{
					for(int lol = c[i][v]; lol--; )
					{
						if (b[j][v] - a[i][v] > 0)
						{
							A.push_back(b[j][v] - a[i][v]);
						}
					}
				}
				res = max(res, ff());
			}
		}
	}
	cout << res << endl;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>

using namespace std;

bool comp (pair<int, int> a, pair<int, int> b){
    return (a.second < b.second);
}

int main(){
    int n, m, k;
    int buf;
    string name;
    vector<vector<int> > buy;
    vector<vector<int> > sale;
    vector<vector<int> > numb;
    cin>>n>>m>>k;
    for(int i = 0; i < n; i++){
        cin>>name;
        vector<int> v;
        buy.push_back(v);
        sale.push_back(v);
        numb.push_back(v);
        for(int j = 0; j < m; j++){
            cin>>buf;
            buy[i].push_back(buf);
            cin>>buf;
            sale[i].push_back(buf);
            cin>>buf;
            numb[i].push_back(buf);
        }
    }
    int min = 0, it;
    int cur;
    int space;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(i!=j){
                cur = 0;
                priority_queue<int> diff;
                for(int k =0; k < m; k++){
                   diff.push((sale[j][k] - buy[i][k]) * 1000 + numb[i][k]);
                }
                space = k;
                while(space > 0 & !diff.empty()){
                    buf = diff.top();
                    if(buf < 0)break;
                    diff.pop();
                    if(buf % 1000 <= space) it = buf % 1000; else it = space;
                    cur+=buf/1000 * it;
                    space -= it;
                }
                if(cur > min) min = cur;
            }

        }
    }

    cout<<min;
    return 0;
}


#include <iostream>
#include <vector>
#include <utility>
#include <set>
#include <string>

struct product {
    int bvalue;
    int svalue;
    int quantity;
};

struct planet {
    std::vector<struct product> merc;
};

int max_profit (struct planet a, struct planet b, int m, int k) {
    std::multiset<std::pair<int,int>> profit_table;

    for (int i = 0; i < m; ++i) {
        std::pair<int,int> profit_merc;
        profit_merc.first = a.merc[i].bvalue - b.merc[i].svalue;
        profit_merc.second = a.merc[i].quantity;
        profit_table.insert(profit_merc);
    }

    int profit = 0;
    for (auto merc_profit : profit_table) {
        if (merc_profit.first > 0) break;
        if (k > merc_profit.second) {
            profit += -merc_profit.first*merc_profit.second;
            k -= merc_profit.second;
        } else {
            profit += -merc_profit.first*k;
            break;
        }
    }

    return profit;
}

int main(void)
{
    int n, m, k;

    std::cin >> n >> m >> k;

    std::vector<struct planet> planets (n);
    for (int i = 0; i < n; ++i) {
        std::string foo;
        std::cin >> foo;
        for (int j = 0; j < m; ++j) {
            struct product p;
            std::cin >> p.bvalue;
            std::cin >> p.svalue;
            std::cin >> p.quantity;
            planets[i].merc.push_back(p);
        }
    }

    int max = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            int temp = max_profit(planets[i], planets[j], m, k);
            if (temp > max) max = temp;
        }
    }

    std::cout << max << std::endl;

    return 0;
}


#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<math.h>

using namespace std;

int A[12][105][5],n,m,k,l,i,j,a1,a2,ma,q,a,s;
multiset <pair<int, int> > b;
pair <int, int> top;
char str[15];

main()
{

  scanf("%d%d%d",&n,&m,&k);
  for (i=1;i<=n;i++)
  {
    scanf("%s",&str);
    for (j=1;j<=m;j++)
      scanf("%d%d%d",&A[i][j][1],&A[i][j][2],&A[i][j][3]);
  }

  ma=0;
  for (i=1;i<=n;i++)
  {
    for (j=1;j<=n;j++)
    {
      if (i!=j)
      {
        b.clear();
        for (q=1;q<=m;q++)
        {
          a=A[j][q][2]-A[i][q][1];
          b.insert(pair<int, int> (2000-a,A[i][q][3]));
        }
        l=k;
        s=0;
        while (!b.empty())
        {
          top=*b.begin();
          b.erase(b.begin());
          a1=2000-top.first;
          a2=top.second;
          if (a1>0)
          {
            if (l>=a2) {s=s+a1*a2;l=l-a2;}
              else {s=s+a1*l;l=0;}
          } else break;
          if (l==0) break;
        }
        if (s>ma) ma=s;
      }
    }
  }
  printf("%d\n",ma);
}


#include <iomanip>
#include <algorithm>
#include <fstream>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <cmath>
#include <iostream>
#include <string>
#include <set>

using namespace std;

int kol[100][200],b[100][200],s[100][200];

bool F(pair<int,int> a, pair<int,int> b)
{
	return (a.first > b.first);
};

int main()
{
	int n,m,k;
	scanf("%d%d%d",&n,&m,&k);

	for (int i = 0; i < n; i++)
	{
		string name;
		cin >> name;
		for (int j = 0; j < m; j++)
		{
			cin >> b[i][j] >> s[i][j] >> kol[i][j];
		}
	}
	int ans = 0;

	for (int A = 0; A < n; A++)
	for (int B = 0; B < n; B++)
	{
		if (A == B) continue;
		vector< pair<int,int> > pr;
		pr.clear();
		for (int i = 0; i < m; i++)
		{
			pr.push_back(make_pair(-b[A][i] + s[B][i],i));
		}
		sort(pr.begin(),pr.end(), F);

		int sum = 0, k1 = k;
		for (int i = 0; i < pr.size(); i++)
		{
			if (k1 == 0) break;
			int j = pr[i].second;
			if (pr[i].first <= 0) break;
			int K = min(k1, kol[A][j]);
			sum += K * pr[i].first;
			k1 -= K;
		}
		ans = max(ans,sum);
	}
	cout << ans << endl;

	return 0;
}


// iTwin
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <string>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

int a[110][110];
int b[110][110];
int c[110][110];
vector<pair<int,int> > XD;
int main(){
    #ifdef LOCAL
    freopen("a.in", "r", stdin);
    freopen("a.out", "w", stdout);
    #endif
    int n,m,k,i,j,q,w;
    scanf("%d%d%d",&n,&m,&k);
    for(i=0;i<n;i++){
        scanf("%*s");
        for(j=0;j<m;j++)scanf("%d%d%d",&a[i][j],&b[i][j],&c[i][j]);
    }
    int ans=0;
    for(i=0;i<n;i++)for(j=0;j<n;j++){
        XD.clear();
        for(q=0;q<m;q++)if(a[i][q]<b[j][q]){
            XD.push_back(make_pair(-(b[j][q]-a[i][q]),c[i][q]));
        }
        sort(XD.begin(),XD.end());
        int r=0,kk=k;
        for(q=0;q<XD.size()&&kk;q++){
            if(XD[q].second<kk){
                r+=-XD[q].first*XD[q].second;
                kk-=XD[q].second;
            }else{
                r+=-XD[q].first*kk;
                kk=0;
            }
        }
        if(ans<r)ans=r;
    }
    printf("%d\n",ans);
}


#include<cstdio>
#include<vector>
#include<utility>
#include<algorithm>

using namespace std;

int main(void){

    int n, m, k, a, b, c;
    char tx[16];
    int p[12][128][4];
    int max = 0;

    scanf("%d %d %d", &n, &m, &k);

    for(int i = 0; i < n; ++i){

        gets(tx);
        gets(tx);

        for(int j = 0; j < m; ++j){
            scanf("%d %d %d", &a, &b, &c);
            p[i][j][0] = a;
            p[i][j][1] = b;
            p[i][j][2] = c;
        }
    }

    for(int i = 0; i < n; ++i){

        for(int j = 0; j < n; ++j){

            if(i == j)continue;

            vector< pair<int, int> > vc;

            for(int z = 0; z < m; ++z){
                vc.push_back( make_pair( p[j][z][1] - p[i][z][0], p[i][z][2] ));
            }

            sort(vc.begin(), vc.end());
            reverse(vc.begin(), vc.end());

            int ct = 0;
            int ret = 0;

            for(int z = 0; z < m; ++z){

                if(vc[z].first <= 0) continue;

                int qt = min(vc[z].second, (k-ct));

                ct += qt;
                ret += qt * vc[z].first;
                if(ct == k)break;

            }

            if(ret > max){
                max = ret;
            }
        }
    }

    printf("%d\n", max);

    return 0;
}


#include <fstream>
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <vector>

using namespace std;

//ifstream cin ("input.txt"); ofstream cout ("output.txt");
int n , m , k;

struct good {
	int b;
	int a;
	int c;
	good (int a = 0 , int b = 0 , int c = 0) : a (a) , b (b) , c(c) {}
};

int maximize (const vector <good>& source ,const  vector <good>& dist) {
	int kk = k;
	vector <pair <int , int> > v;
	for (int i = 0; i < source.size(); ++i) {
		v.push_back (make_pair (-(dist[i].b - source[i].a) , source[i].c));
	}

	sort (v.begin() , v.end());
	int res = 0  ;
	for (int i = 0; i < v.size() && kk > 0 && v[i].first < 0; ++i) {
		res += -v[i].first * (min (kk , v[i].second));
		kk -= v[i].second;
	}
	return res;
}

int main () {

	cin >> n >> m >> k;
	vector <vector <good> > v;
	string s;
	v.resize (n);
	for (int i = 0; i < n; ++i) {
		cin >> s;
		int a , b , c;
		for (int j = 0; j < m; ++j) {
			cin >> a >> b >> c;
			v[i].push_back (good (a , b , c) );
		}
	}

	int res = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			if (i == j) continue;
			res = max (res , maximize (v[i] , v[j]));
		}
	}

	cout << res;

}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef long long ll;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define mp make_pair
#define go(i,n) for(int i=0;i<n;i++)
#define go3(i,j,n) for(int i=j;i<n;i++)
#define inf 1000000000

int a[15][1005];
int b[15][1005];
int c[15][1005];

void oku(){

 int n,m,K;
 cin>>n>>m>>K;
 string s;

 int x,y,z;

 go(i,n){
   cin>>s;
   go(j,m){
    cin>>a[i][j]>>b[i][j]>>c[i][j];
   }
 }

 int best=0,cost,q,take,u,v,cc,loc;

 typedef pair<int,int> node;

 for(int i=0;i<n;i++)
 for(int j=0;j<n;j++){
 if(i==j) continue;

 priority_queue<node> pq;

  for(int k=0;k<m;k++)
  {

   cost=b[j][k]-a[i][k];
   //printf("i=%d j=%d cost=%d\n",i,j,cost);
   pq.push(mp(cost,c[i][k]));
  }

  for(take=K,loc=0 ;take>0 && !pq.empty();){
   u=pq.top().first; cc=pq.top().second; pq.pop();
   cc=min(cc,take);
   if(u>0) loc+=u*cc;
   take-=cc;
  }
  //printf("i=%d j=%d loc=%d\n",i,j,loc);
  best=max(best,loc);
 }

 cout<<best;

}

int main(){
//freopen("input.txt","r",stdin);

oku();

return 0;}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 128;

int n, m, k, i, j, ans, buyPlanet, sellPlanet, willChange;
int a[MAXN][MAXN], b[MAXN][MAXN], c[MAXN][MAXN];
int F[MAXN], NF[MAXN];
string uselessInformation;

int main() {
	//freopen("input.txt", "r", stdin);
	ios_base::sync_with_stdio(0);
	cin >> n >> m >> k;
	for (i = 1; i <= n; i++) {
		cin >> uselessInformation;
		for (j = 1; j <= m; j++) cin >> a[i][j] >> b[i][j] >> c[i][j];
	}
	ans = 0;
	for (buyPlanet = 1; buyPlanet <= n; buyPlanet++) {
		for (sellPlanet = 1; sellPlanet <= n; sellPlanet++) {
			if (buyPlanet == sellPlanet) continue;
			for (j = 0; j <= k; j++) F[j] = -1;
			F[0] = 0;
			for (i = 1; i <= m; i++) {
				for (j = 0; j <= k; j++) NF[j] = -1;
				for (willChange = 0; willChange <= c[buyPlanet][i]; willChange++) {
					for (j = 0; j + willChange <= k; j++) {
						NF[j + willChange] = max(NF[j + willChange], F[j] + (b[sellPlanet][i] - a[buyPlanet][i]) * willChange);
					}
				}
				for (j = 0; j <= k; j++) NF[j] = max(NF[j], F[j]);
				for (j = 0; j <= k; j++) F[j] = NF[j];
			}
			for (j = 0; j <= k; j++) ans = max(ans, F[j]);
		}
	}
	printf("%d\n", ans);
	return 0;
}


//lxrtxdy!
#include <bits/stdc++.h>
#define int long long
#define mp make_pair
#define pb push_back
using namespace std;
const int N = 1123456;
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
int read()
{
    int x;
    scanf("%I64d", &x);
    return x;
}
int a[101][101];
int b[101][101];
int c[101][101];
main()
{
    int n, m, k, i, j;
    cin >> n >> m >> k;
    for(i = 1; i <= n; i ++) {
        string s;
        cin >> s;
        for(j = 1; j <= m; j ++) {
            a[i][j] = read();
            b[i][j] = read();
            c[i][j] = read();
        }
    }
    int ans = 0;
    for(i = 1; i <= n; i ++) {
        for(j = 1; j <= n; j ++) {
            if(i == j)
                continue;
            vector <pair <int, int> > v;
            for(int l = 1; l <= m; l ++) {
                if(a[i][l] < b[j][l]) {
                    v.push_back(mp(b[j][l] - a[i][l], c[i][l]));
                }
            }
            sort(v.begin(), v.end());
            reverse(v.begin(), v.end());
            int kt = k, s = 0;
            for(int l = 0; l < v.size(); l ++) {
                int t = min(v[l].second, kt);
                s += (v[l].first * t);
                kt -= t;
            }
            ans = max(ans, s);
        }
    }
    cout << ans;
}
//hellobig_tq//hellobig_tq
//orzlxr!


#include<set>
#include<map>
#include<queue>
#include<deque>
#include<cmath>
#include<string>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
#define maxn 10000
#define maxm 1000000
#define inf 1234567890
int n,m,kp;
struct TNode
{
    int a[105],b[105],c[105];
}nod[15],p1,p2;
char str[100];
int main()
{
    int i,j,k,l,re,ri,t,maxl;
    while(scanf("%d%d%d",&n,&m,&kp)!=EOF)
    {
        for(i=0;i<n;i++)
        {
            scanf("%s",str);
            for(j=0;j<m;j++)
                scanf("%d%d%d",&nod[i].a[j],&nod[i].b[j],&nod[i].c[j]);
        }
        for(i=0,maxl=-1;i<n;i++)
        {
            for(j=0;j<n;j++)
            {
                if(i==j) continue;
                p1=nod[i];
                p2=nod[j];
                for(k=0;k<m;k++)
                {
                    for(l=k+1;l<m;l++)
                    {
                        if(p2.b[l]-p1.a[l]>p2.b[k]-p1.a[k])
                        {
                            swap(p2.a[l],p2.a[k]);
                            swap(p2.b[l],p2.b[k]);
                            swap(p2.c[l],p2.c[k]);
                            swap(p1.a[l],p1.a[k]);
                            swap(p1.b[l],p1.b[k]);
                            swap(p1.c[l],p1.c[k]);
                        }
                    }
                }
                t=0,l=kp;
                for(k=0;k<m;k++)
                {
                    if(p2.b[k]-p1.a[k]<=0) break;
                    if(p1.c[k]<=l)
                    {
                        t+=(p2.b[k]-p1.a[k])*p1.c[k];
                        l-=p1.c[k];
                    }
                    else
                    {
                        t+=(p2.b[k]-p1.a[k])*l;
                        l=0;
                    }
                    if(l==0) break;
                }
                maxl=max(maxl,t);
            }
        }
        printf("%d\n",maxl);
    }
    return 0;
}


//
//  main.cpp
//  codeforces-c
//
//  Created by Andriy Medvid' on 20.04.12.
//  Copyright (c) 2012 taran studio. All rights reserved.
//

#include <cstdio>

int main(int argc, const char * argv[])
{
    char name[100];
    int n, m, k;
    int goods[10][100][3], bonus[1010], max_result = 0;

    scanf("%d%d%d", &n, &m, &k);
    for(int i = 0; i < n; i++)
    {
        scanf("%s", &name);
        for(int j = 0; j < m; j++)
        {
            scanf("%d%d%d", &goods[i][j][0], &goods[i][j][1], &goods[i][j][2]);
        }
    }
    for(int i = 0; i < n; i++)
    {
        for(int ii = 0; ii < n; ii++)
        {
            int result = 0;

            for(int i=0; i < 1001; i++)
                bonus[i] = 0;

            for(int j = 0; j < m; j++)
                if(goods[i][j][0] < goods[ii][j][1])
                {
                    bonus[goods[ii][j][1] - goods[i][j][0]] += goods[i][j][2];
                }

            int new_k = k;
            for(int i = 1000; i>0; i--)
            {
                int min = bonus[i] < new_k?bonus[i]:new_k;
                result += min * i;
                new_k -= min;
            }
            if(result > max_result)
                max_result = result;
        }
    }

    printf("%d\n", max_result);
    return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include <vector>
#include <string>

using namespace std;

bool cmp(const pair<int, int> & p1, const pair<int, int> & p2)
{
    return p1.first > p2.first;
}

int main()
{
    int n, m, k;
    string name;
    cin >> n >> m >> k;
    vector<vector<int> > a(n, vector<int>(m)), b(n, vector<int>(m)), c(n, vector<int>(m));
    for(int i = 0; i < n; i++)
    {
        cin >> name;
        for(int j = 0; j < m; j++)
        {
            cin >> a[i][j] >> b[i][j] >> c[i][j];
        }
    }
    int ans = 0;
    vector<pair<int, int> > res;
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++)
        {
            if(i != j)
            {
                for(int l = 0; l < m; l++)
                {
                    res.push_back(make_pair(b[j][l]-a[i][l], c[i][l]));
                }
                sort(res.begin(), res.end(), cmp);
                int temp = 0, r = 0, p = k;
                while(p > 0 && r < res.size() && res[r].first > 0)
                {
                    if(p >= res[r].second)
                    {
                        p -= res[r].second;
                        temp += res[r].first * res[r].second;
                        r++;
                    }
                    else
                    {
                        temp += res[r].first * p;
                        p = 0;
                    }
                }
                if(temp > ans) ans = temp;
                res.clear();
            }
        }
    }
    cout << ans << endl;
    return 0;
}


#include<cmath>
#include<cstdio>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<vector>
#include<sstream>
#include<iomanip>
#include<iostream>
#include<algorithm>
#include<time.h>
#include<stdlib.h>
#include<assert.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define sz(x) ((int)(x).size())
#define rep(i,l,r) for(int i=(l);i<(r);++i)
typedef long long ll;
typedef pair<int, int> pii;
const int N = 1e2 + 7;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const double Pi = acos(-1.0);
const double EPS = 1e-8;
//--------head--------
int n, m, k;
int a[N][N], b[N][N], c[N][N];
char str[N];
struct Node {
	int buy, sell, cnt;
	Node() {
	}
	Node(int _buy, int _sell, int _cnt) {
		buy = _buy, sell = _sell, cnt = _cnt;
	}
	bool operator<(const Node &p) const {
		return sell - buy > p.sell - p.buy;
	}
};
vector<Node> item;
int main() {
	scanf("%d%d%d", &n, &m, &k);
	rep(i, 0, n) {
		scanf(" %s", str);
		rep(j, 0, m)
			scanf("%d%d%d", &a[i][j], &b[i][j], &c[i][j]);
	}
	int ans = 0;
	rep(i, 0, n)
		rep(j, 0, n) { // i -> j
			item.clear();
			rep(r, 0, m)
				item.pb(Node(a[i][r], b[j][r], c[i][r]));
			sort(item.begin(), item.end());
			int profit = 0, can = k;
			rep(r, 0, sz(item)) {
				int num = min(can, item[r].cnt);
				if (item[r].sell - item[r].buy < 0)
					break;
				profit += num * (item[r].sell - item[r].buy);
				can -= num;
				if (can == 0)
					break;
			}
			ans = max(ans, profit);
		}
	printf("%d\n", ans);
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

#define FR(i,n) for(int i=0;i<n;i++)
#define PII pair<int,int>
#define ll long long

struct P
{
	int buy[100],sell[100],cnt[100];
} a[10];

int main()
{
	//freopen("in.txt","r",stdin);
	int n,m,cap; cin>>n>>m>>cap;
	FR(i,n)
	{
		string s; cin>>s;
		FR(j,m) cin>>a[i].buy[j]>>a[i].sell[j]>>a[i].cnt[j];
	}

	ll res=0;
	FR(i,n)
	{
		int cn[100];
		FR(j,n)
		{
			if(i==j) continue;
			FR(k,m) cn[k]=a[i].cnt[k];
			int C=cap;
			bool f=true;
			ll sum=0;
			while(C>0 && f)
			{
				f=false;
				int mx=0,ind;
				FR(k,m)
				{
					int t=a[j].sell[k]-a[i].buy[k];
					if(cn[k] && t>mx)
					{
						mx=t;
						ind=k;
						f=true;
					}
				}
				if(!f) continue;
				int q=min(C,cn[ind]);
				sum+=mx*q;
				cn[ind]-=q;
				C-=q;
			}
			res=max(sum,res);
		}
	}

	cout<<res<<endl;

	return 0;
}


#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <queue>
#include <set>
#define MAXN 1010
#define INF 1000000007
#define MP(x,y) make_pair(x,y)
#define FI first
#define SE second
#define EPS 1e-8
using namespace std;
int goods[20][MAXN][3];
char str[MAXN];
pair<int,int> pa[MAXN];
int main()
{
    //freopen("/home/moor/Code/input","r",stdin);
    int n,m,k,ans=0;
    scanf("%d%d%d",&n,&m,&k);
    for(int i=0;i<n;++i)
    {
        scanf("%s",str);
        for(int j=0;j<m;++j)
            for(int l=0;l<3;++l)
                scanf("%d",&goods[i][j][l]);
    }
    for(int i=0;i<n;++i)
        for(int j=0;j<n;++j)
        {
            for(int l=0;l<m;++l)    pa[l]=MP(goods[j][l][1]-goods[i][l][0],goods[i][l][2]);
            sort(pa,pa+m);
            int tk=k,tmp=0;
            for(int l=m-1;l>=0&&tk&&pa[l].FI>0;--l)
            {
                tmp+=pa[l].FI*min(tk,pa[l].SE);
                tk-=min(tk,pa[l].SE);
            }
            ans=max(ans,tmp);
        }
    printf("%d\n",ans);
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <ctime>
#include <cassert>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define li long long
#define ld long double
#define all(v) v.begin(),v.end()

int st[11][101];
int pr[11][101];
int kol[11][101];

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n,m,k;
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++)
    {
        string s;
        cin>>s;
        int a,b,c;
        for(int j=0;j<m;j++)
        {
            cin>>a>>b>>c;
            st[i][j]=a;
            pr[i][j]=b;
            kol[i][j]=c;
        }
    }
    int ans=0;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
        {
            if(i==j)
                continue;

            vector<pair<int,int> >v;
            v.resize(m);
            for(int l=0;l<m;l++)
                v[l]=mp(pr[j][l]-st[i][l],kol[i][l]);
            sort(all(v));
            int tek=0;
            int now=0;
            for(int l=m-1;l>=0;l--)
                if(v[l].first>0 && v[l].second+now<=k)
                {
                    tek+=v[l].first*v[l].second;
                    now+=v[l].second;
                }
                else
                    if(v[l].first>0 && v[l].second+now>k)
                    {
                        tek+=v[l].first*(k-now);
                        break;
                    }
            ans=max(ans,tek);
        }
    cout<<ans<<endl;
    return 0;
}


#define _CRT_SECURE_NO_DEPRECATE
#pragma comment(linker, "/STACK:100000000")
#include <iostream>
#include <vector>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <set>
#include <string>
using namespace std;
struct data {
    long a, b, c;
};
int main() {
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
    long n, m, k, i, j, l;
    cin >> n >> m >> k;
    vector < vector < data > > v(n, vector < data > (m));
    string tmp;
    for(i = 0; i < n; i++) {
        cin >> tmp;
        for(j = 0; j < m; j++)
            cin >> v[i][j].a >> v[i][j].b >> v[i][j].c;
    }
    long long ans = 0;
    for(l = 0; l < n; l++)
        for(j = 0; j < n ;j++)
            if(l != j) {
                vector < pair < long, long > > d(m);
                for(i = 0; i < m; i++) {
                    d[i].first = v[l][i].b - v[j][i].a;
                    d[i].second = v[j][i].c;
                }
                sort(d.begin(), d.end());
                long sm = 0;
                long long p = 0;
                for(i = m - 1; i >= 0; i--) {
                    if(d[i].first <= 0)
                        break;
                    if(d[i].second + sm > k) {
                        p += (k - sm) * d[i].first;
                        break;
                    }
                    p += d[i].second * d[i].first;
                    sm += d[i].second;
                }
                ans = max(ans, p);
            }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
//#include <math.h>
//#include <vector.h>
//#include <string>
//typedef long long ll;
using namespace std;

int main()
{
    int n,m,k;
    long sum,max=0;
    cin>>n>>m>>k;
    short a[10][100];
    short b[10][100];
    short c[10][100];
    string s;
    for (int i=0;i<n;i++)
    {
        cin>>s;
        for (int j=0;j<m;j++)
            cin>>a[i][j]>>b[i][j]>>c[i][j];
    }
    for (int i=0;i<n;i++)
        for (int j=0;j<n;j++)
            if (i!=j)
            {
                int w,wi;
                int masa=0;
                sum=0;
                bool used[100];
                for (int i1=0;i1<m;i1++)
                    used[i1]=false;

                for (int i1=0;i1<m;i1++)
                {
                    w=-1;wi=-1;
                    for (int j1=0;j1<m;j1++)
                        if (!used[j1] && (b[i][j1]-a[j][j1])>w)
                        {
                            w=b[i][j1]-a[j][j1];
                            wi=j1;
                        }
                    if (w>0)
                    {
                        sum+=min((int) c[j][wi],k-masa)*w;
                        used[wi]=true;
                        masa+=min((int) c[j][wi],k-masa);
                        if (k-masa==0) break;
                    }
                }
                if (sum>max) max=sum;
            }

    cout<<max;
   // system("Pause");
    return 0;

}


#pragma comment(linker, "/STACK:256000000")

#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <ctime>
#include <math.h>
#include <vector>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string.h>
#include <algorithm>

using namespace std;

template<class T>
double sqrt(T x)
{
	return sqrt((double) x);
}

template<class T>
T sqr (T x)
{
	return x*x;
}

#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define X first
#define Y second
#define pb push_back
#define mp make_pair
//#define foreach(e,x) for(__typeof(x.begin()) e=x.begin();e!=x.end();++e)

const double PI = acos(-1.0);
const int INF = 1000000000;
const int MOD = 1000000007;

//#define ONLINE_JUDGE

int main()
{
	double TIME_START = clock();
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
#endif

	int n,m,k, a,b,c;
	cin >> n >> m >> k;
	string s;

	int sell[15][105], buy[15][105], amount[15][105];
	/*
	vector< vector<int > > sell(n, vector<int> (m));

	vector< vector<int> > buy(n, vector<int> (m));
	vector< vector<int> > amount(n, vector<int> (m));
	*/

	for (int x = 0 ; x < n ; x++)
	{
		cin >> s;
		for (int y = 0 ; y < m ; y++)
		{
			cin >> a >> b >> c;
			sell[x][y] = b;
			buy[x][y] = a;
			amount[x][y] = c;
		}

	}

	// buy sell thing
	pair<int,int> profit[15][15][105];
	for (int x = 0 ; x < n ; x++)
		for (int y = 0 ; y < n ; y++)
		{
			if ( x == y ) continue;
			for (int z = 0; z < m; z++)
			{
				profit[x][y][z].X = -buy[x][z]  + sell[y][z];
				profit[x][y][z].Y = z;
			}
		}

	for (int x = 0 ; x < n ; x++)
		for (int y = 0 ; y < n ; y++) sort( profit[x][y], profit[x][y] + m , greater<pair<int,int> >() );

	int ans = -1;
	int cur,in;

	for (int x = 0 ; x < n ; x++)
	{
		for (int y = 0 ; y < n; y++)
		{
			if ( x == y ) continue;
			cur = 0;
			in = k;

			for (int z = 0 ; z < m ; z++)
			{
				if ( profit[x][y][z].X > 0 )
				{
					cur += profit[x][y][z].X * min(in,amount[x][ profit[x][y][z].Y ]);
					in -=  amount[x][ profit[x][y][z].Y ];
					if ( in <= 0  ) break;
				}
				else break;
			}

			//eprintf("%d\n",cur);

			if ( cur > ans )
			{
				//eprintf("%d %d %d\n", x, y, cur);
				ans = cur;
			}
		}
	}

	cout << ans;

	eprintf("\n\n%.15lf\n\n",(double)(clock() - TIME_START)/CLOCKS_PER_SEC);
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <set>
#include <queue>
#include <string>
#include <map>
#include <list>
#include <deque>
#include <algorithm>
using namespace std;

const int nmax=105;

struct goods
{
	int a,b,c;
}d[12][nmax];

int dif[nmax],ID[nmax];
int MAX=0;
int comp(const void*a,const void*b)
{
	int aa=*(int*)a,bb=*(int*)b;
	return -(dif[aa]-dif[bb]);
}

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	int n,m,i,k,j,p;
	string s;

	cin >>n>>m>>k;
	for (i=0;i<n;i++)
	{
		cin >>s;
		for (j=0;j<m;j++)
		{
			cin >>d[i][j].a>>d[i][j].b>>d[i][j].c;
		}
	}
	for (i=0;i<n;i++)
	{
		for (j=0;j<n;j++)
		{
			if (i==j)continue;
			for (p=0;p<m;p++)
			{
				dif[p]=d[j][p].b-d[i][p].a;
				ID[p]=p;
			}
			qsort(ID,m,sizeof(int),comp);
			int cur=0,has=k,take;
			for (p=0;p<m;p++)
			{
				if (dif[ID[p]]<=0)break;
				take=min(has,d[i][ID[p]].c);
				has-=take;
				cur+=dif[ID[p]]*take;
				if (has==0)break;
			}
			MAX=max(MAX,cur);
		}
	}
	cout <<MAX;
	return 0;
}


#include <sstream>
#include <iostream>
#include <cstdio>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <queue>
#include <deque>

using namespace std;

typedef long long ll;
typedef vector<int> VI;
typedef pair<int, int> PI;

#define foru(i,a,b) for(int i = int(a); i <= int(b); ++i)
#define ford(i,b,a) for(int i = int(b); i >= int(a); --i)
#define rep(i, n) for(int i = 0; i < int(n); ++i)
#define all(a) a.begin(),a.end()
#define fill(a,x) memset(a, (x), sizeof(a))
#define mp(x,y) make_pair((x), (y))
#define pb(x) push_back((x))
#define fr first
#define sc second

const int MAX_N = 20;
const int MAX_M = 110;

int a[MAX_N][MAX_M], b[MAX_N][MAX_M], c[MAX_N][MAX_M];
vector< PI > w;

int main() {
   int n, m, k, res = 0;
   cin >> n >> m >> k;
   foru(i, 1, n) {
      string s;
      getline(cin, s);
      getline(cin, s);
      foru(j, 1, m) scanf("%d%d%d", &a[i][j], &b[i][j], &c[i][j]);
   }
   foru(i, 1, n)
      foru(j, 1, n) if (i != j) {
         w.clear();
         foru(t, 1, m)
            w.pb(mp(b[j][t]-a[i][t], c[i][t]));
         sort(all(w));
         int sumW = 0, sumC = 0;
         ford(t, m-1, 0)
            if (w[t].fr <= 0 || sumC == k) break;
            else {
               int x = min(k-sumC, w[t].sc);
               sumW += x*w[t].fr;
               sumC += x;
            }
         res = max(res, sumW);
      }
   cout << res;
   return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstdint>
#include<climits>
#include<numeric>
#include<stack>
#include<set>
#include<queue>
#include<map>
#include<string>
#include<cstring>
#include<iomanip>
#include<functional>
using namespace std;
long long NWD(long long a, long long b) { return (b == 0) ? a : NWD(b, a % b); }
inline long long NWW(long long a, long long b) { return a / NWD(a, b) * b; }
inline long long normalize(long long x, long long MOD) { return ((x % MOD) + MOD) % MOD; }
class GCD_Type { public: long long x, y; };
GCD_Type exGCD(long long a, long long b)
{
	if (b == 0) return{ 1, 0 };
	GCD_Type pom = exGCD(b, a % b);
	return{ pom.y, pom.x - (a / b) * pom.y };
}
using CRT_Var_Type = long long;
class CRT_Equation_Type
{
public:
	CRT_Var_Type a, m;
	inline bool operator==(const CRT_Equation_Type& other)
	{
		return a == other.a && m == other.m;
	}
	inline bool operator!=(const CRT_Equation_Type& other)
	{
		return a != other.a || m != other.m;
	}
};
class ChineseRemainderTheorem // system of equations x = ai (mod mi) i = 0,1,2,...
{
	vector<CRT_Equation_Type>equations;
public:
	static constexpr CRT_Equation_Type Failed = { -1, -1 }; // returned when no solutions
	void clear() // clears system of equations
	{
		equations.clear();
	}
	void addEquation(CRT_Var_Type a, CRT_Var_Type m) // adds equation of form x = a (mod m)
	{
		a %= m; if (a < 0) a += m;
		equations.push_back({ a, m });
	}
	CRT_Equation_Type solve()
	{
		if (equations.empty() == true) return Failed;
		CRT_Equation_Type ans = equations[0];
		for (int i = 1; i < equations.size(); i++)
		{
			CRT_Equation_Type next = equations[i];
			CRT_Var_Type g = NWD(ans.m, next.m);
			if (ans.a % g != next.a % g) return Failed;
			GCD_Type Bezout = exGCD(ans.m / g, next.m / g);
			CRT_Var_Type lcm = ans.m / g * next.m;
			ans.a = (ans.a % lcm + (next.a - ans.a) / g * Bezout.x % (next.m / g) * ans.m % lcm) % lcm;
			if (ans.a < 0) ans.a += lcm;
			ans.m = lcm;
		}
		return ans;
	}
};
long long n, m, x, y, vx, vy, wynik = LLONG_MAX;
ChineseRemainderTheorem Uklad;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m >> x >> y >> vx >> vy;
	if (vx == 0)
	{
		if (x == 0 || x == n) cout << x << " " << (~vy ? m : 0) << endl;
		else return cout << -1 << endl, 0;
	}
	else if (vy == 0)
	{
		if (y == 0 || y == m) cout << (~vx ? n : 0) << " " << y << endl;
		else return cout << -1 << endl, 0;
	}
	else
	{
		for (int i = 0; i < 4; i++)
		{
			Uklad.addEquation(vx * ((i / 2) * n - x), 2 * n);
			Uklad.addEquation(vy * ((i % 2) * m - y), 2 * m);
			auto SystemSolution = Uklad.solve();
			if (SystemSolution != ChineseRemainderTheorem::Failed) wynik = min(wynik, SystemSolution.a);
			Uklad.clear();
		}
		x = normalize(x + wynik * vx, 2 * n);
		y = normalize(y + wynik * vy, 2 * m);
		(wynik == LLONG_MAX) ? (cout << -1 << endl) : (cout << x << " " << y << endl);
	}

	getchar();
	getchar();
	return 0;
}


#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <iostream>
#include <iterator>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <sstream>

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef pair<int, int> PII;

#define FOR(i,x,y) for(LL i=x; i<=y; i++)
#define REP(i,n) for(LL i=0; i<n; i++)

#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define UNIQ(c) SORT(c),(c).resize(unique(ALL(c))-(c).begin())
#define SZ(c) (int)(c).size()

#define pb push_back
#define mp make_pair
#define X first
#define Y second

const double eps = 1.0e-11;
const double pi = acos(-1.0);

struct team {
    int good, fail, points, games;
    string name;
    team() : good(0), fail(0), points(0), games(0) {}
};

bool operator < (const team& t1, const team& t2) {
    if (t1.points != t2.points)
        return t1.points > t2.points;
    if (t1.good - t1.fail != t2.good - t2.fail)
        return t1.good - t1.fail > t2.good - t2.fail;
    if (t1.good != t2.good)
        return t1.good > t2.good;
    return t1.name < t2.name;
}

map <string, team> table;

pair<int, int> best(100, 10);
string oponent;
const string B = "BERLAND";

void Up(int g, int f) {
    map <string, team> table1 = table;
    if (g <= f)
        return;
    table1[B].fail += f, table1[B].good += g;
    table1[oponent].fail += g, table1[oponent].good += f;
    string n1 = B, n2 = oponent;
    int g1 = g, g2 = f;
    if (g1 > g2)
        table1[n1].points += 3;
    if (g1 < g2)
        table1[n2].points += 3;
    if (g1 == g2)
        table1[n1].points += 1, table1[n2].points += 1;
    vector<team> tt;
    for (map<string, team>::iterator it = table1.begin(); it != table1.end(); ++it)
        tt.push_back(it->second);
    SORT(tt);
    if (tt[0].name == B || tt[1].name == B) {
        if (best.first - best.second > g - f)
            best = mp(g, f);
        if (best.first - best.second == g - f && best.second > f)
            best = mp(g, f);
    }
}

int main() {
    REP(i, 5) {
        string n1, n2, score;
        int g1, g2;
        cin >> n1 >> n2 >> score;
        g1 = score[0] - '0';
        g2 = score[2] - '0';
        table[n1].good += g1, table[n1].fail += g2, table[n1].name = n1, table[n1].games++;
        table[n2].good += g2, table[n2].fail += g1, table[n2].name = n2, table[n2].games++;
        if (g1 > g2)
            table[n1].points += 3;
        if (g1 < g2)
            table[n2].points += 3;
        if (g1 == g2)
            table[n1].points += 1, table[n2].points += 1;
    }
    for (map<string, team>::iterator it = table.begin(); it != table.end(); ++it)
        if (it->first != B && it->second.games == 2)
            oponent = it->second.name;

    REP(i, 100)
        REP(j, 100)
            Up(i, j);
    if (best == mp(100, 10)) {
        cout << "IMPOSSIBLE\n";
        return 0;
    }

    cout << best.first << ":" << best.second << endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
using namespace std;
int f(int x){
	int ans=x+1;
	while(ans%10==0&&ans!=0){
		ans/=10;
	}
	return ans;
}
map<int,int> m;
int main(){
	int x,ans=0;
	cin>>x;
	while(x){
		ans++;
		m[x]=1;
		x=f(x);
		if(m[x]) break;
		else m[x]=1;
	}
	cout<<ans<<endl;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <vector>
#include <stack>
#include <array>
#include <list>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <bitset>
#include <sstream>
#include <tuple>
#include <cstdint>
#include <memory>

using namespace std;

typedef unsigned int uint;
typedef unsigned long long int llu;

#define rep(n) for (int i = 0; i < (n); i++)
#define get(type, variable) type variable; cin >> variable;
#define forq(n) for (int q = 0; q < (n); q++)
#define all(c) c.begin(), c.end()
#define pb push_back
#define el endl

int main() {
    int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;

    int d1 = 0;
    if (r1 == r2 && c1 == c2)
        d1 = 0;
    else if (r1 == r2)
        d1 = 1;
    else if (c1 == c2)
        d1 = 1;
    else
        d1 = 2;

    int d2 = 0;
    if (r1 == r2 && c1 == c2)
        d2 = 0;
    else if (abs(r1 - r2) == abs(c1 - c2))
        d2 = 1;
    else
        d2 = 2;
    int n = abs(r1 - r2) + abs(c1 - c2);
    if (n % 2)
        d2 = 0;

    int d3 = 0;
    d3 = max(abs(r1 - r2), abs(c1 - c2));

    cout << d1 << " " << d2 << " " << d3 << endl;

    return 0;
}


/*input
6 3 3 1
*/
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long k,sum=0,end,cap,f,tank;
	cin>>end>>cap>>f>>k;
	for(tank=cap;--k;f=end-f){
		if(tank<f||cap<end-f) return cout<<-1,0;
		if(tank>=2*end-f)
			tank-=end;
		else{
			++sum;
			tank=cap-(end-f);
		}
	}
	if(tank<f ||  cap<end-f) return cout<<-1,0;
	if(tank<end) ++sum;
	cout<<sum;
}


#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;

typedef long long ll;

int main()
{
    long long int a;
    long long int b;
    cin>>a>>b;
    int ans=0;
    for(int i=2;i<62;i++)
    {
        ll c=1LL<<i;
        c--;
        for(int j=0;j<i-1;j++)
        {
            ll d=c-(1LL<<j);
            if(d>=a&&d<=b)
                ans++;
        }
    }
    cout<<ans;
    return 0;
}
/*
1 1
2 1 0
3 1 1
4 1 0 0

1 0 1
1 1 0
1 1 1
1 0 0 0
1 0 0 1
1 0 1 0

1 0 1 1
1 1 0 0
1 1 0 1
1 1 1 0
1 1 1 1
1 0 0 0 0
1 0 0 0 1
*/


#include <iostream>
using namespace std;

int main()
{
	setlocale(LC_ALL, "RUS");
	int m[3], m2[3];
	for (int i = 0; i < 3; i++)
		cin >> m[i];
	for (int i = 0; i < 3; i++)
		cin >> m2[i];
	if (m[0] != m2[0] && m[1] != m2[1] && m[2] != m2[2])
		cout << "NO";
	else
		cout << "YES";
	return 0;
}


#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x)
#define debug(x)
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	ll n;
	cin>>n;
	ll ans=0;
	ans+=2LL*4*3*(1LL<<(2*(2*n-2-(n+1))));
	ans+=(n-3)*4*3*3*(1LL<<(2*(2*n-2-(n+2))));
	cout<<ans<<endl;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}


#include <bits/stdc++.h>
#define maxn 20010
using namespace std;
int n, mod, w[2][2 * maxn + 5], s[2][2 * maxn + 5], ans[55];
int main()
{
	cin >> n >> mod;
	w[0][maxn] = s[0][maxn] = 1;
	for (int i = maxn; i <= 2 * maxn; i ++ ) s[0][i] = 1;
	for (int i = 1; i <= n; i ++ )
	{
		int curs = 1, I = i & 1, J = I ^ 1;
		memset(w[I], 0, sizeof(w[I])), memset(s[I], 0, sizeof(s[I]));
		for (int u = i * (i - 1) / 2, j = -u + maxn; j <= u + maxn; j ++ ) w[I][j] = curs, curs = (0ll + curs - s[J][j] + s[J][j - i] + s[J][j + i] - s[J][j] + 2ll * mod) % mod;
		for (int j = maxn - i * (i - 1) / 2, v = (i + 2) * (i + 1) / 2 + maxn; j <= v; j ++ ) s[I][j] = (s[I][j - 1] + w[I][j]) % mod;
		for (int j = 1; j < i; j ++ ) ans[i] = (ans[i] + 1ll * (s[J][(i + 1) * i / 2 + maxn] - s[J][j + maxn] + mod) % mod * (i - j)) % mod;
	}
	for (int i = 2; i <= n; i ++ ) ans[i] = (ans[i] + 1ll * i * ans[i - 1]) % mod;
	cout << ans[n] << endl;
}


#include<stdio.h>
int main(){
int n;
scanf("%d",&n);
int s[n];
int i;
for(i=0;i<n;i++){
scanf("%d",&s[i]);
}
for (i=0;i<(n-2);i++){
if(s[i]-s[i+1]==s[i+1]-s[i+2])
continue;
else{printf("%d\n",s[n-1]);return 0;}
}
printf("%d\n",s[n-1]-(s[0]-s[1]));
return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<memory.h>
int main()
{
   int a,b,n,i,x[6];
   memset(x,0,sizeof(x));
   scanf("%d",&n);
     for(i=0;i<n;i++)
        {
                scanf("%d%d",&a,&b);

             x[a]++;
             x[b]++;
          }
    int pd=0;
    for(i=1;i<=5;i++)
       {
            if(x[i]>=3 || x[i]<2)   {pd=1;break;}
            }
    if(!pd) printf("FAIL\n");
    else printf("WIN\n");
    //system("pause");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int MAXN = 105;
int n, m;
int cnt[MAXN];

int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 0; i < m; i++)
    {
        int x;
        scanf("%d", &x);
        cnt[x]++;
    }
    for (int i = 100; i >= 1; i--)
    {
        int sum = 0;
        for (int j = 1; j <= 100; j++)
        {
            sum += (cnt[j]/i);
        }
        if (sum >= n)
        {
            printf("%d\n", i);
            return 0;
        }
    }
    printf("0\n");
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

long long MOD=1e9+7;
int n,k,d;
int dp[107][107][2];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin>>n>>k>>d;
	memset(dp,0,sizeof(dp));
	dp[0][0][0]=1;

	for(int i=0;i<=n;++i){
		for(int w=0;w<=n;++w){
			for(int z=0;z<=1;++z){
				for(int nextW=1;nextW<=k;++nextW){
					if(w+nextW<=n){
						int z2=0;
						if(z==1||nextW>=d){
							z2=1;
						}
						dp[i+1][w+nextW][z2]=(dp[i+1][w+nextW][z2]+dp[i][w][z])%MOD;
					}
				}
			}
		}
	}
	int ans=0;
	for(int i=0;i<=n;++i){
		ans=(ans+dp[i][n][1])%MOD;
	}
	cout<<ans<<"\n";
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;

int main(){
  int te;
  cin>>te;
  while(te--){
      ll n,ans = 0;
      cin >> n;
      set<ll>mp;
      for(int i=1;i*i<=n;i++){
        ans++;
        mp.insert(i*i);
      }
      for(int i=1;i*i*i<=n;i++){
        ans++;
        mp.insert(i*i*i);
      }
      cout << mp.size() << endl;
  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 110;

int a[N];

int main() {
  int n, x;
  cin >> n >> x;
  for (int i = 0; i < n; i++) {
    int foo;
    cin >> foo;
    if (foo <= x) {
      a[foo] = 1;
    }
  }
  int ans = 0;
  for (int i = 0; i < x; i++) {
    ans += (a[i] == 0);
  }
  ans += (a[x] == 1);
  cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;;

ll gcd(ll a,ll b)
{
  if (b==0)
    return a;
  else
    return gcd(b,a%b);
}
int main()
{
  ll l,r,x,y,n;

  cin >> l >> r >> x >> y;

  if (y%x == 0)
  n = y/x;
  else
  n = 0;
  //cout <<"n"  << n << endl;

  ll c = 0;
  for (ll i = 1; i*i <= n; i++)
  {
      if (n%i == 0 and i*x>=l and i*x<=r and (n/i)*x >=l and (n/i)*x <=r and gcd(i,n/i) == 1)
      {
        if (i*i != n)
          c++;
        c++;
      }
  }

  cout << c;

}


#include <iostream>
#include <vector>
using namespace std;

const int Max=100000 +10;
vector <int> v[Max];
vector <int> p[Max];

bool mark[Max];
bool mark2[Max];
int arr[Max];

void dfs(int u)
{
    mark[u] = 1;
    for(int i = 0 ; i < v[u].size() ; i++)
        if(mark[v[u][i]] == 0)
            dfs(v[u][i]);
}

void dfs2(int u)
{
    mark2[u] = 1;
    if( arr[u]!=1)
        for(int i = 0 ; i < p[u].size() ; i++)
            if(!mark2[p[u][i]])
                dfs2(p[u][i]);
}

int main()
{
    int n,m;
    cin >> n >>m;
    for(int i=1;i<=n;i++)
        cin >> arr[i];
    for(int i=1;i<=m;i++)
    {
        int tmp1,tmp2;
        cin >> tmp1 >> tmp2 ;
        v[tmp1].push_back(tmp2);
        p[tmp2].push_back(tmp1);
    }

    for(int i = 1 ; i <= n ; i++)
        if(arr[i] == 1 && mark[i] == 0)
            dfs(i);

    for(int i = 1 ; i <= n ; i++)
        if(arr[i] == 2 && mark2[i] == 0)
            dfs2(i);
    for (int i = 1 ; i <= n ; i++)
    {
        int k=mark2[i] * mark[i];
        cout << k <<endl;
    }
}


#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#include <iterator>
using namespace std;

int main() {
    long long a,b,c;
    cin >> a >> b >> c;

    long long ans = 2*c + min(a,b) + min(max(a,b), min(a,b)+1);
    cout << ans;
}


#include "stdio.h"
#include <iostream>

using namespace std;

int main()
{
    long c, d, n, m, k;
    long a[100*100+1];
    scanf ("%ld %ld", &c, &d);
    scanf ("%ld %ld", &n, &m);
    scanf ("%ld", &k);
    for (int i = 0; i <= n*m; i++)
        a[i] = LONG_MAX;
    for (int i = 0; i <= k; i++)
        a[i] = 0;
    for (int i = k+1; i <= n*m; i++)
        if (i >= n)
            if (a[i-1] + d < a[i-n] + c)
                a[i] = a[i-1] + d;
            else
                a[i] = a[i-n] + c;
        else
            a[i] = a[i-1] + d;
    if (n*m == k)
        printf ("0");
    else
        printf ("%ld", a[n*m]);
}


#include <iostream>
using namespace std;
int main()
{
	long long n,a,b,c,l,s;
	cin>>n>>a>>b>>c;
	if (n<4)
	{n=4+n;}

	if (n%4==0)
	{
		l=0;
	}
	if (n%4==3)
	{
		l=a;
		if (b+c<l)
		{l=b+c;}
		c=c*3;
		if (c<l)
		{l=c;}
	}
	if (n%4==2)
	{
		l=b;
		a=a*2;
		if (a<b)
		{
			l=a;
		}
		c=c*2;
		if (c<l)
		{l=c;}
	}
	if (n%4==1)
	{
		l=c;
		b=a+b;
		a=a*3;
		if (a<l)
		{
			l=a;
		}
		if (b<l)
		{l=b;}
	}
	cout<<l<<endl;
	return 0;
}


#include <cstdio>
#include <iostream>
#include <string>
#include <cstddef>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <vector>
#include <deque>
#include <utility>
#include <unordered_map>
#include <algorithm>
#include <string>
#include <cstdio>
#include <iostream>
#include <set>
#include <map>
#include <functional>
#include <iterator>
#include <cstdlib>
#include <cstring>

//#define ONLINE_JUDGE 1

int solve();

int main(int, char**)
{
#ifndef ONLINE_JUDGE
	(void)freopen("input.txt", "r", stdin);
	(void)freopen("output.txt", "w", stdout);
#endif

#ifdef ONLINE_JUDGE
	::std::ios::sync_with_stdio(false);
	::std::cin.tie(0);
#endif

	int Q = 1;
	//std::cin >> Q;
	while (Q--)
		solve();

	return 0;
}

//12 33 45     f(12,12) =  1 1 2 2

constexpr int MOD = 998244353;
constexpr int MAXN = 3008;

int d[MAXN][MAXN];
int mi[MAXN][MAXN];

int solve()
{
	using namespace std;
	int N, M, A, B;
	cin >> N >> M >> A >> B;

	int g, x, y, z;
	cin >> g >> x >> y >> z;

	for (int i = 0; i < N; ++i)
	{
		for (int j = 0; j < M; ++j)
		{
			d[i][j] = g;
			g = (g * 1LL * x + y) % z;
		}
	}

	for (int i = 0; i < N; ++i)
	{
		deque< pair<int, int > > Q;

		for (int j = 0; j < M; ++j)
		{
			while (!Q.empty() && Q.back().first >= d[i][j])
				Q.pop_back();

			Q.push_back(make_pair(d[i][j],j) );

			while (!Q.empty() && Q.front().second < j - B + 1)
				Q.pop_front();

			mi[i][j] = Q.front().first;
		}

	}

	for (int j = 0; j < M; ++j) {
		deque< pair< int, int > > Q;
		for (int i = 0; i < N; ++i) {
			while (!Q.empty() && Q.back().first >= mi[i][j])
				Q.pop_back();

			Q.push_back(make_pair(mi[i][j], i));

			while (!Q.empty() && Q.front().second < i - A + 1)
				Q.pop_front();

			mi[i][j] = Q.front().first;
		}
	}

	long long sum = 0;
	for (int i = A-1; i < N; ++i) {
		for (int j = B-1; j < M; ++j) sum += (long long)mi[i][j];
	}

	cout << sum << endl;

	// g[0]  given
	// g[1] = (g[0] * x + y) mod z
	// g[2] = (g[1] * x + y) mod z = (g[0]*x^2 + y * x + y ) mod z
	// g[3] = (g[2] * x + y) mod z = (g[0]*x^3 + y * x^2 + y * x + y) mod z

	// g[i] = (g[0] * x^i + y*(x^(i-1) + x^(i-2) + ... + x^0) ) mod z

	return 0;
}


#include<bits/stdc++.h>
using  namespace  std;

#define all(p) p.begin(), p.end()
#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define ll long long
#define llu unsigned long long
#define ld long double
#define vll vector<long long int>
#define vi vector<int>
#define pii pair <int, int>
#define pll pair <long long int, long long int>
#define vpii vector<pair<int,int> >
#define nl cout<<"\n"
#define sp cout<<" "
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)

const  int  INF = 0x7f7f7f7f;

int  main ()
{
	ios_base::sync_with_stdio(false);
    //freopen ("input.txt", "r", stdin);
    //freopen ("output.txt", "w", stdout);

	ll m;
	cin>>m;

	ll lo = 1;
	ll hi = 1e18;
	ll ans = -1;

	while(lo<=hi)
	{
		ll mid = (lo+hi)/2;
		ll ways = 0;
		ll k = 2;

		while(true)
		{
			ll q = mid;
			rep(i, 1, 3)
				q = q/k;

			if(q==0) break;
			ways += q;
			k++;
		}

		if(ways==m) {ans = mid; hi = mid-1;}
		else if(ways<m)	lo = mid+1;
		else hi = mid-1;
	}

	cout<<ans;nl;

    return  0;
}


#include<bits/stdc++.h>
using namespace std;
int n,m,x;
int main()
{
	cin>>n>>m;
	x=pow(2,n);
	cout<<m%x<<endl;
	return 0;
}