#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;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 2e5+10 , OO = 0x3f3f3f3f ;
//const int mod = 1000000007;

#define clr(arr,val) memset(arr , val , sizeof (arr))
#define loop(i,n) for(int i = 0;i < int(n);i++)
#define rloop(i,n) for(int i = int(n)-1;i >= 0;i--)
#define xloop(i,a,b) for(int i = int(a);i <= int(b);i++)
#define range(vec) for(auto &x : vec) cin >> x;
#define ALL(v) ((v).begin()) , ((v).end())
#define SZ(v)  ((int)((v).size()))
int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction

int n , a , b , c;

int main()
{
   // startTime = (double)clock();
    #ifndef ONLINE_JUDGE
        //freopen("in.in", "r", stdin);
        //freopen("out.in", "w", stdout);
    #endif
	//ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    int k ;
    string s;
    cin >> s >> k;

    for(int i = 0 ; i < k ; ++i) s += "?";

    int len = s.size();
    vector < int > sizes;
    for(int st = 0 ; st < len - k ; ++st){ // try all valid starts 'st' with end 'e'
        for(int e = st ; e < len ; ++e){
            string now = s.substr(st , e - st + 1);
            //cout << "string now = " << now << "\n";
            if(SZ(now) & 1)
                continue;
            int n = SZ(now) / 2;
            int sz = 0;
            for(int r = 0 ; r < n ; ++r){
                if(now[r] != now[r + n] and now[r + n] != '?')
                    break;
                sz += 2;
            }
            sizes.push_back(sz);
        }
        //for(auto x : sizes) cout << x << " ";

    }
    int mx = *max_element(sizes.begin() , sizes.end());
    printf("%d\n" , mx);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll int
#define N 4100010
ll yu;
ll n;
ll f[N];
ll fir[N],nxt[N],val[N],cnt=0;
inline void add(ll &x,ll y)
{
	if(y<0)y+=yu;
	x+=y;
	if(x>=yu)x-=yu;
}
ll tmp=0;
ll g[N];
ll st[N],top=0;
int main()
{
	//freopen("test1.in","r",stdin);
	cin>>n>>yu;
	f[1]=1;
	ll sum=1;
	for(int i=2;i<=n;i++)
	{
		top=0;
		add(f[i],sum);
		for(int j=fir[i];j;j=nxt[j])
		{
			ll o=val[j];
			//ll o=q[i].front();
			g[o]++;
			add(tmp,f[g[o]]-f[g[o]-1]);
			st[++top]=j;
			//q[i].pop();
			//q[i+o].push(o);
		}
		while(top)
		{
			ll o=st[top--];
			if(i+val[o]<=n)nxt[o]=fir[i+val[o]];
			if(i+val[o]<=n)fir[i+val[o]]=o;
		}
		tmp+=1;
		add(f[i],tmp);
		g[i]=1;
		cnt++;
		val[cnt]=i;
		if(2*i<=n)nxt[cnt]=fir[2*i];
		if(2*i<=n)fir[2*i]=cnt;
		add(sum,f[i]);
	}
	cout<<f[n]<<endl;
	return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <functional>
#include <unordered_map>
#include <unordered_set>

using namespace std;

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

	queue<pair<int, int>> kids;

	for (int i = 0; i < n; ++i) {
		int x;
		cin >> x;
		kids.push(make_pair(i, x));
	}

	while (kids.size() > 1) {
		pair<int, int> current = kids.front();
		kids.pop();
		current.second -= m;

		if (current.second > 0) {
			kids.push(current);
		}
	}

	cout << kids.front().first + 1;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
bool a[1000][1000];
bool arr[1000];
int main()
{
    int x,y,a,b,q,i=1;
    cin >>x>>y>>a>>b;
    if(max(x,y)%min(x,y)==0){
        q=max(x,y);
    }
    else{
        while(true){
            if(max(x,y)*i%min(x,y)==0){
                q=max(x,y)*i;
                break;
            }
            i++;
        }
    }
    cout <<(b/q)-((a-1)/q);
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include<sstream>
using namespace std;
const int N = 1e5 + 7, M = 1e7, OO = 0x3f3f3f3f;
#define endl '\n'
#define  ll long long
#define loop(i,n) for(int i = 0;i < int(n);++i)
#define rloop(i,n) for(int i = int(n);i >= 0;--i)
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define p(a) printf("%d",a)
#define S(n) scanf("%d",&n)
int t;
bool LuckyNumber(ll int x){
        x++;
        while (x) {
            if (abs(x%10) == 8)
                return true;
            x /= 10;
        }
        return false;
}
int main () {
ll int x,cnt=1;cin>>x;
    while (!LuckyNumber(x)) {cnt++;x++;}
    cout<<cnt;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int a[110];
int main()
{
    int n,t,i;
    scanf("%d",&n);
    int k=1;
    int sum1=0;
    int sum2=0;
        int sum3=0;
    int sum4=0;
    int k1=n;
    int kkk=n/2;
    for(i=0;i<kkk;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a,a+kkk);
    for(i=1;i<=n/2;i++)
    {
        t=a[i-1];
        if(t>k)
        {
            sum1=sum1+t-k;
        }
        else if(t<k)
        {
            sum1=sum1+k-t;
        }
        k++;
        if(t>k)
        {
            sum2=sum2+t-k;
        }
        else if(t<k)
        {
            sum2=sum2+k-t;
        }
        k++;
        if(t>k1)
        {
            sum3=sum3+t-k1;
        }
        else if(t<k1)
        {
            sum3=sum3+k1-t;
        }
        k1--;
        if(t>k1)
        {
            sum4=sum4+t-k1;
        }
        else if(t<k1)
        {
            sum4=sum4+k1-t;
        }
        k1--;
    }
int kk;
kk=min(sum1,sum2);
kk=min(kk,sum3);
kk=min(kk,sum4);
printf("%d",kk);
    return 0;
}


/*
    Problem: 678B. The Same Calendar

    Solution: calendar, implementation, O(n)

    Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru
*/

#include <iostream>
#include <vector>
#include <string>

typedef long long ll;

std::vector<int> days_per_month = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

struct Record {
    int year, month, day, id;

    Record next() const {
        Record ret = *this;
        (ret.id += 1) %= 7;
        ret.day++;
        int need_to_add = month == 1 && (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0));
        if (ret.day == days_per_month[month] + need_to_add) {
            ret.day = 0;
            ret.month++;
            if (ret.month >= 12) {
                ret.month = 0;
                ret.year++;
            }
        }
        return ret;
    }
};

int main() {
    int year; std::cin >> year;
    Record cur{year, 0, 0, 0};
    std::vector<std::string> arr;
    while (true) {
        if (cur.year - year >= (int)arr.size()) {
            if (arr.size() > 1u && arr.back() == arr.front()) {
                std::cout << cur.year - 1 << std::endl;
                return 0;
            }
            arr.push_back("");
        }
        arr[cur.year - year].push_back(char('0'+cur.id));
        cur = cur.next();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int k,pa,pb;
int A,B;
int f[1005][1005];
const int p=1000000007;
inline int ksm(int b,int pp)
{
	pp--;
    int a=b;
    while(pp>0)
    {
    	if(pp%2==1) a=(1LL*b*a)%p;
        b=(1LL*b*b)%p;
    	pp/=2;
    }
    return a%p;
}
inline int inv(int x)
{
	return ksm(x,p-2);
}
int dp(int i,int j)
{
	if(i+j>=k) return (i+j+1LL*pa*inv(pb)%p)%p;
	if(f[i][j]!=-1) return f[i][j];
	return f[i][j]=(1LL*((1LL*pa*dp(i+1,j))%p+(1LL*pb*dp(i,i+j))%p)*inv(pb+pa))%p;
}
int main(){
	scanf("%d%d%d",&k,&pa,&pb);
	memset(f,-1,sizeof f);
	printf("%d\n",dp(1,0));
}


#include <iostream>

using namespace std;

int main()
{
    int ar[90000];
    int n,d,m,result=0,t;
    cin>>n>>d;
    for(int i=0;i<n;i++){
        cin>>ar[i];
    }
    cin>>m;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(ar[i]>ar[j]){
                int t=ar[i];
                ar[i]=ar[j];
                ar[j]=t;
            }
        }
    }
    t=m;
    for(int i=0;i<n;i++){
        result+=ar[i];
        t--;
        if(t==0){
            cout<<result;
            return 0;
        }

    }
    for(int i=0;i<m-n;i++){
        result-=d;
    }
    cout<<result;

}


#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <stack>
#include<iomanip>
using namespace std;
long long MOD = 1e9 + 7;
long long phi(long long n)
{
	long long result = n;
	for (long long i = 2; i*i <= n; ++i)
		if (n % i == 0) {
			while (n % i == 0)
				n /= i;
			result -= result / i;
		}
	if (n > 1)
		result -= result / n;
	return result;
}

int main()
{
	long long n; long long k; cin >> n >> k;
	long long docnt = (k + 1) / 2;
	long long ans = n;
	for (long long i = 0; i < docnt; ++i)
	{
		if (ans == 1) { cout << "1"; return 0; }
		ans = phi(ans);
	}
	cout << ans % MOD;
}


/*
 _     _    ___  ___  __ __
| |   | |  |__ \|__ \/_ /_ |
| |__ | |__   ) |  ) || || |
| '_ \| '_ \ / /  / / | || |
| |_) | |_) / /_ / /_ | || |
|_.__/|_.__/____|____||_||_|

*/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define INF         9223372036854775807
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
using namespace std;

#define N  100005
ll expo(ll base,ll exponent,ll mod){
    ll ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(ans*base)%mod;
        base=(base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        ll n,ans;
        cin>>n;
        ll fac[2*n];
        fac[0]=1;
        rep(i,1,2*n)
        {
            fac[i]=(fac[i-1]*i)%hell;
        }
        ans=((2*((fac[2*n-1]*expo((fac[n]*fac[n-1])%hell,hell-2,hell))%hell))%hell-n+hell)%hell;
        cout<<ans<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define For(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
#define MAX 100005
#define endl '\n'
using namespace std;
ll power(int x,int y){
	ll res=1LL;
	while(y){
		if(y&1){
			res*=x;
		}
		x=x*x;
		y/=2;
	}
	return res;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	int l,r;
	cin>>l>>r;
	vector<int> two,three;
	int cnt=0;
	for(int i=0;i<=31;i++){
		two.pb(1<<i);
	}
	for(int i=0;i<=19;i++){
		three.pb(power(3LL,(ll)i));
	}
	for(int i=0;i<32;i++){
		for(int j=0;j<=19;j++){
			if(two[i]*1LL*three[j]>=l && two[i]*1LL*three[j]<=r){
				cnt++;
			}
		}
	}
	cout<<cnt<<endl;
}


/*
 * File:      main.cpp
 * Author:    Hrayr [HarHro94]
 * Problem:
 * IDE:       Visual C++ 2012
 */
#pragma comment(linker, "/STACK:66777216")
#define _CRT_SECURE_NO_WARNINGS
#include <functional>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <fstream>
#include <cassert>
#include <iomanip>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
using namespace std;

typedef long long LL;
typedef long double LD;
#define pb push_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

/*
int [107], ans;
void rec(int cur)
{
    if (cur == n + 1)
    {
        vector<int> cnt(n + 1, 0);
        for (int i = 1; i <= n; ++i)
        {
            ++cnt[a[i]];
        }
        int sum = 0;
        for (int i = 1; i <= n; ++i)
        {
            if (cnt[i] == i)
            {
                sum += i;
            }
        }
        if (n - sum == k)
        {
            ++ans;
        }
        return;
    }
    for (int i = 1; i <= n; ++i)
    {
        a[cur] = i;
        rec(cur + 1);
    }
}
*/
/*
#define MOD 777777777LL
LL dp[600][600][600], C[600][600];
int n, k;

void calcBinomials(int n = 599)
{
    int i, j;
    for (i = 0; i <= n; ++i)
    {
        C[i][0] = 1;
    }
    for (i = 1; i <= n; ++i)
    {
        for (j = 1; j <= n; ++j)
        {
            C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD;
        }
    }
}

void precalc(int n)
{
    //dp[answer][all][wrong];
    for (int i = 0; i <= n; ++i)
    {
        for (int j = 0; j <= n; ++j)
        {
            for (int k = 0; k <= n; ++k)
            {
                dp[i][j][k] = 0LL;
            }
        }
    }
    dp[0][0][0] = 1LL;
    for (int i = 1; i <= n; ++i)
    {
        for (int all = 0; all <= n; ++all)
        {
            for (int wrong = 0; wrong <= all; ++wrong)
            {
                if (all >= i) // right answer
                {
                    dp[i][all][wrong] += (C[n - all + i][i] * dp[i - 1][all - i][wrong]) % MOD;
                    if (dp[i][all][wrong] >= MOD)
                    {
                        dp[i][all][wrong] -= MOD;
                    }
                }
                for (int j = 0; j <= wrong; ++j)
                {
                    if (j == i)
                    {
                        continue;
                    }
                    dp[i][all][wrong] += (C[n - all + j][j] * dp[i - 1][all - j][wrong - j]) % MOD;
                    if (dp[i][all][wrong] >= MOD)
                    {
                        dp[i][all][wrong] -= MOD;
                    }
                }
            }
        }
    }
}
*/

int ans[600][600] =
{
    {1, 0},
    {1, 2, 1},
    {5, 32, 30, 80, 109},
    {541, 6824, 59808, 147224, 415870, 1757896, 1897056, 4898872, 7593125},
    {166257661, 776830421, 290516100, 746623577, 293783147, 33900006, 735127505, 565460332, 428982705, 472062098, 161873957, 117354594, 515619293, 578944191, 312106242, 569389279, 391464593},
    {464207287, 261086313, 584837659, 683961846, 468868529, 211593382, 736955478, 229471758, 157617135, 398169441, 360252438, 629394768, 264125799, 647490480, 342079395, 391579767, 225200475, 486011304, 513156108, 628771752, 132906648, 142138221, 20119449, 444199674, 195188679, 387329805, 44684703, 651912135, 737154512, 612549793, 519860281, 186175544, 212568440},
    {382725349, 240805271, 239509872, 581127897, 6511239, 156126222, 509425833, 672407328, 366667722, 459185405, 509737025, 554790222, 165216555, 703150560, 74806569, 398730015, 383350905, 506108358, 51326142, 298053147, 104256117, 391428765, 374020479, 206607807, 87664059, 275899176, 56407680, 551553401, 448939463, 582889860, 129676638, 226078251, 135769095, 61292868, 578972226, 190181628, 390739055, 184587732, 446575689, 732674124, 232198470, 676760679, 352474101, 611444862, 575661807, 628905585, 320813094, 522840969, 469781928, 156006018, 554473341, 239654268, 643714911, 433540170, 199307003, 496385218, 291740751, 67309914, 370826673, 202356819, 279421821, 421203111, 63744786, 520987612, 550671827},
    {642497124, 482164403, 768209115, 462063756, 154906374, 36099042, 341766705, 678182556, 621882744, 478771358, 231881111, 175889805, 243630450, 168908523, 671961765, 55761813, 652682670, 773939082, 517628076, 756201264, 124604900, 750976272, 498253248, 676047609, 137170026, 705610017, 495032139, 561797418, 703097347, 500815609, 95984586, 739707108, 265613565, 387099846, 777331779, 594676173, 591219559, 407997044, 208947235, 93337440, 478908360, 685013007, 487033953, 671903001, 39521181, 738490312, 33785059, 465470131, 310453920, 54648783, 346831137, 427694175, 474743430, 705296781, 435828036, 429824745, 663532359, 261388683, 244690731, 533997135, 596108961, 506813013, 371892402, 590145264, 104733162, 143420103, 654339672, 700348950, 685038942, 578826927, 286484229, 501639192, 434962491, 299270097, 27702486, 335375775, 111746817, 565603164, 294926121, 676063665, 735862995, 710035809, 437011960, 668528077, 138765186, 508213986, 615036450, 353784942, 624827616, 343900011, 241289776, 52410890, 72018835, 352406796, 415705878, 4802637, 376367145, 65589678, 333633477, 341834527, 303717460, 282387700, 42951006, 254706039, 423048528, 526429710, 68131467, 669954708, 12787348, 500636381, 317959019, 479433192, 657133515, 416259390, 610216692, 340129188, 44594256, 257373347, 138718678, 530767740, 292922628, 37220268, 605295159, 480722613, 458170419, 30540300, 487159055, 232966794, 149150650},
    {507720408, 412133651, 386543325, 139952108, 289303402, 102404925, 317067177, 396414708, 80515854, 663739304, 317300809, 228877044, 493725043, 715317967, 490300965, 315527373, 743539734, 488329191, 553627998, 533025234, 242583957, 706116537, 614109258, 645447222, 523195911, 492109128, 722623041, 111085128, 766395126, 654378921, 691964847, 496688157, 399056049, 654363234, 102052314, 191720088, 473910948, 259736526, 332840025, 388047555, 665791056, 627111387, 139696515, 441456687, 443032569, 283264821, 771641703, 452641455, 511306362, 117572859, 127701891, 721298331, 176520078, 357242229, 611296308, 696994956, 405628839, 429224274, 465336054, 695091546, 689828796, 574648641, 351220905, 507964023, 675326610, 517248963, 453528621, 220301928, 494463186, 681789969, 339589656, 44524053, 417125457, 339589404, 747135963, 341780733, 734158215, 396817281, 21997836, 5728464, 147611205, 456248898, 714128667, 377654949, 3862068, 128418948, 589390074, 304947090, 11703825, 228266073, 127304142, 429215724, 361541124, 521572968, 468358191, 341231688, 65323503, 613778508, 15985323, 291661029, 410970006, 591638112, 349541550, 89967528, 224922159, 361094166, 584206074, 640051812, 324264456, 652625388, 693768537, 11740617, 309238398, 211085469, 194905872, 639416484, 110110707, 296645895, 748118511, 131177718, 511142751, 775975599, 421403409, 475528473, 434685258, 1768977, 80301375, 708023862, 569195676, 56238084, 632887668, 88089750, 631539342, 396695565, 38780154, 695798271, 469819224, 439587099, 69045921, 682966116, 112310856, 64943298, 534475872, 40215357, 389728458, 286368453, 736006257, 501181650, 54829908, 603489402, 338032656, 512182818, 627500097, 462674016, 3103092, 157324491, 43978329, 596818971, 259025598, 9088632, 91991781, 577291428, 211245489, 429471231, 142626330, 172560633, 510907446, 444609585, 758102058, 375112647, 744786693, 276174402, 19259856, 233672418, 745389414, 225772848, 23385663, 324290610, 519804558, 120337812, 402578568, 360676008, 450089262, 551043738, 337388940, 512108856, 28879011, 690040638, 106017282, 558262341, 99972432, 608226003, 612152037, 42414435, 776201013, 39580443, 518796945, 494437752, 583194366, 723936555, 415359657, 309569589, 751104774, 166684527, 249229170, 353120823, 130668327, 753823584, 580966092, 561963717, 543672234, 393846327, 586278000, 327398400, 278403867, 156455586, 363920382, 190245195, 290039148, 547014447, 466218648, 146037150, 585462906, 666008595, 691786683, 374707494, 622498779, 231158277, 685740951, 115612245, 681825249, 545555745, 551718468, 277206615, 640171035, 757727334, 195193908, 658656684, 457760646, 225925875, 505761984, 18685233, 506832921, 112511021, 396846646, 290147622, 113924623, 669986155, 336008070, 63611061, 238586775, 119956662, 616557739, 772784623, 334527774, 410403148, 51933421}
};

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

    /*
    calcBinomials();
    for (int i = 0; i <= 8; ++i)
    {
        int n = (1 << i);
        precalc(n);
        printf("{");
        for (int k = 0; k <= n; ++k)
        {
            if (k == n)
            {
                printf("%d}\n", dp[n][n][k]);
            }
            else
            {
                printf("%d, ", dp[n][n][k]);
            }
        }
    }
    */
    int n, k;
    scanf("%d%d", &n, &k);
    int nn;
    for (int i = 0; i <= 8; ++i)
    {
        if ((1 << i) == n)
        {
            nn = i;
        }
    }
    printf("%d\n", ans[nn][k]);

#ifdef harhro94
    cerr << fixed << setprecision(3) << "\nExecution time = " << clock() / 1000.0 << "s\n";
#endif
    return 0;
}


#include<bits/stdc++.h>
#define fastio     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define debug(x)   cerr<<#x<<": "<<x<<endl;
#define all(x)     (x).begin() , (x).end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define endl       '\n'
#define MAX        1000000
typedef long long int ll;
using namespace std;

const ll mod = 1e9+7;
const double eps = 1e-9;

void solve(){
    ll n ,m;
    cin>>n>>m;
    if(n>m) {
        swap(n,m);
    }
    ll pairs=0;
    for(int i=1;i<=n;i++) {
        if(i<5) {
            ll find = 5 - i;
            pairs += (m-find+5)/5;
        }
        else {
            ll find=(i + 4)/5;
            find*=5;
            find=find-i;
            if(find==0)find=5;
            pairs+= (m-find+5)/5;
        }
    }
    cout<<pairs;
}

int main(){
    fastio
    int test=1;
    while(test--)
        solve();
    return 0;
}


//Lasha Bukhnikashvili
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<string>
#define INF 1000000001
#define Pi 3.14159265358
#define mod9 %1000000009
#define mod7 %1000000007
#define time clock()/(double)CLOCKS_PER_SEC
using namespace std;
 int a,b,l,i,j,k;
 int prime[1000001],primes[1000001];
 void MakePrime(){
      prime[0]=prime[1]=0;
      for (i=2;i<=1000000;i++){
          if (prime[i]==0){
             for (j=i*2;j<=1000000;j+=i)
                 prime[j]=1;
          };
          primes[i]+=primes[i-1]+1-prime[i];
      };
 };
 void BinarySearch(){
      int l=1,r=b-a+1,mid;
      while (l<r){
            if (r-l==1) break;
            mid=(l+r)/2;
            int stop=0;
            for (i=a;i<=b-mid+1;i++)
                if (primes[i+mid-1]-primes[i-1]<k) stop=1;
            if (stop) l=mid+1; else r=mid;
      };
      int stop=0;
      for (i=a;i<=b-l+1;i++)
          if (primes[i+l-1]-primes[i-1]<k) stop=1;
      if (stop) l=r;
      stop=0;
      for (i=a;i<=b-r+1;i++)
          if (primes[i+r-1]-primes[i-1]<k) stop=1;
      if (stop) cout<<-1; else cout<<l;
 };
int main(){
 //freopen("input.txt","r",stdin);
 //freopen("output.txt","w",stdout);
   cin>>a>>b>>k;
   MakePrime();
   BinarySearch();
 return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n, k; cin >> n >> k;
    if (k % 2 !=0) {
        cout << k / 2 + 1;
    }
    else {
        cout << n / 2 - k / 2 + 1;
    }
}


/******In the name of ALLAH******/
#include <bits/stdc++.h>

using namespace std;

#define inf 1000000221
#define MAX 1001101
#define PI 3.14159265

struct Point
{
	long double x,y,z,t,h;
}a;

vector<Point> v;

long double dot(Point &a, Point &b , Point&c){
	long double x1 = a.x -c.x;
	long double x2 = b.x -c.x;
	long double y2 = b.y -c.y;
	long double y1 = a.y -c.y;
	long double z1 = a.z -c.z;
	long double z2 = b.z -c.z;
	long double h1 = a.h -c.h;
	long double h2 = b.h -c.h;
	long double t1 = a.t -c.t;
	long double t2 = b.t -c.t;
	return x1*x2 + y1*y2 + h1*h2 + z1*z2  + t1*t2;
}

long double as(Point &a  , Point &c){
	long double temp = sqrt(dot(a,a,c));
	return temp;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n ;
	cin>>n;
	for(int i =0 ; i < n ; i++){
		cin>>a.x>>a.y>>a.z>>a.t>>a.h;
		v.push_back(a);
	}

	if( n == 1){
		cout<<1<<endl;
		cout<<1;
		return 0;
	}
	if(n == 2){
		cout<<2<<endl;
		cout<<1<<endl;
		cout<<2;
		return 0;
	}
	long double temp,tt;

	for(int i =0 ; i < n ; i++){
		bool f =0;
		for(int j = 0 ; j < n ; j++){
			if(i == j)continue;
			for(int k = 0 ;k < n ; k ++){
				if(k == j || k == i)continue;
				temp = dot(v[j],v[k],v[i]);
				temp /= as(v[k] , v[i]);
				temp /=  as(v[j] ,v[i]);
				tt = acos(temp) * 180.0 / PI;
				if(tt < 90.0 ){
					f = 1;
					break;
				}
			}
			if(f)break;
		}
		if(f == 0){
			cout<<1<<endl;
			cout<< i + 1;
			return 0;
		}
	}
	cout<<0;

	return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
using namespace std;

long long mod = 1E9 + 7;
int main()
{
	int n, a, pos;
	cin >> n >> a >> pos;
	long long ans = 1;
	int l = 0, r = n, middle = 0,cntb = 0,cntm = 0;
	while (l < r) {
		middle = (l + r) / 2;
		if (pos < middle) {
			ans = (ans * (n - a - cntb)) % mod;
			cntb++;
			r = middle;
		}
		else if (pos >= middle){
			if (pos != middle) {
				ans = (ans * (a - 1 - cntm)) % mod;
				cntm++;
			}
			l = middle + 1;
		}
	}
	for (int i = n - 1 - cntb - cntm; i >= 1; i--) {
		ans = (ans * i) % mod;
	}
	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <cstring>
#include <vector>

typedef long long ll;

const ll MOD = ll(1e9) + 7;
const int ms = 51;
const int me = 22;

int n;

int a[ms];

ll fexp(ll x, ll e)
{
	ll ans = 1;
	for(; e > 0; e /= 2)
	{
		if(e & 1)
			ans = ans * x % MOD;
		x = x * x % MOD;
	}
	return ans;
}

ll fat[ms];
ll ifat[ms];
ll comb(int a, int b)
{
	if(a < b || b < 0 || a < 0)
		return 0;
	ll ans = fat[a] * ifat[b] % MOD;
	return ans * ifat[a - b] % MOD;
}

int memo[ms][me][me][2][me][me][2];
int dp(int on, std::vector<int> prv, std::vector<int> nxt)
{
	int max = prv[0];
	int min = prv[0];
	int sum = 0;
	for(int i = 0; i < 3; i++)
	{
		max = std::max(max, std::max(prv[i], nxt[i]));
		min = std::min(min, std::min(prv[i], nxt[i]));
		sum += prv[i] + nxt[i];
	}
	if(max > me || min < 0)
		return 0;
	if(on == n)
	{
		//std::cout << "on " << on << ", (" << prv[0] << ", " << prv[1] << ", " << prv[2] << ") - (" << nxt[0] << ", " << nxt[1] << ", " << nxt[2] << ")\n";
		return sum == 0;
	}
	if(sum == 0)
		return 0;
	int &ans = memo[on][prv[0]][prv[1]][prv[2]][nxt[0]][nxt[1]][nxt[2]];
	if(ans != -1)
		return ans;
	ans = 0;
	if(prv[0] + prv[1] + prv[2] == 0)
		return ans = dp(on, nxt, prv);
	//std::cout << "on " << on << ", (" << prv[0] << ", " << prv[1] << ", " << prv[2] << ") - (" << nxt[0] << ", " << nxt[1] << ", " << nxt[2] << ")\n";
	for(int i = 0; i <= a[on] && i <= prv[0]; i++)
	{
		ll cost1 = comb(prv[0], i);
		for(int j = 0; i + j <= a[on] && j <= prv[1]; j++)
		{
			ll cost2 = cost1 * comb(prv[1], j) % MOD;
			for(int k = 0; i + j + k <= a[on] && k <= prv[2]; k++)
			{
				if(i + j + k != 1)
					continue;
				ll cost3 = cost2 * comb(prv[2], k) % MOD;
				for(int ii = 0; i + j + k + ii <= a[on] && ii <= nxt[0]; ii++)
				{
					ll cost4 = cost3 * comb(nxt[0], ii) % MOD;
					for(int jj = 0; i + j + k + ii + jj <= a[on] && jj <= nxt[1]; jj++)
					{
						ll cost5 = cost4 * comb(nxt[1], jj) % MOD;
						for(int kk = 0; i + j + k + ii + jj + kk <= a[on] && kk <= nxt[2]; kk++)
						{
							ll cost6 = cost5 * comb(nxt[2], kk) % MOD;
							//std::cout << "\non " << on << ", (" << prv[0] << ", " << prv[1] << ", " << prv[2] << ") - (" << nxt[0] << ", " << nxt[1] << ", " << nxt[2] << ")\n";

							prv[0] += j - i;
							prv[1] += k - j;
							prv[2] += -k;
							nxt[0] += jj - ii;
							nxt[1] += kk - jj;
							nxt[2] += -kk;
							//std::cout << "cost is " << cost6 << ", (" << i << ", " << j << ", " << k << ", " << ii << ", " << jj << ", " << kk << ")\n";
							if(i + j + k + ii + jj + kk < a[on])
								nxt[a[on] - (i + j + k + ii + jj + kk) - 1]++;
							ans = (ans + cost6 * dp(on + 1, prv, nxt)) % MOD;
							if(i + j + k + ii + jj + kk < a[on])
								nxt[a[on] - (i + j + k + ii + jj + kk) - 1]--;
							prv[0] -= j - i;
							prv[1] -= k - j;
							prv[2] -= -k;
							nxt[0] -= jj - ii;
							nxt[1] -= kk - jj;
							nxt[2] -= -kk;
						}
					}
				}
			}
		}
	}
	//std::cout << "on " << on << ", (" << prv[0] << ", " << prv[1] << ", " << prv[2] << ") - (" << nxt[0] << ", " << nxt[1] << ", " << nxt[2] << ") ans is " << ans << "\n";
	return ans;
}

int main()
{
	fat[0] = ifat[0] = 1;
	for(int i = 1; i < ms; i++)
	{
		fat[i] = fat[i - 1] * i % MOD;
		ifat[i] = fexp(fat[i], MOD - 2);
	}
	std::cin >> n;
	for(int i = 0; i < n; i++)
		std::cin >> a[i];
	memset(memo, -1, sizeof memo);
	a[0]++;
	std::vector<int> prv, nxt;
	prv = nxt = std::vector<int>(3, 0);
	prv[0] = 1;
	std::cout << dp(0, prv, nxt) << '\n';
}


#include<iostream>
using namespace std;
long long a,b,c,d,mid,n,ans=999999999999;
int main(){
	cin>>n;
	c=0;
	d=n+2;
  for(long long i=0;i<90000000;i++)
  i++;
	while(true)
  {
		if(c+1>=d)
    break;
		mid=(c+d)/2;
		a=mid/2;
		b=mid-a;

		if(a*b>=n){
			if(ans>mid)

      ans=mid;
			d=mid;

		}

    else

    {
			c=mid;
		}
	}
	cout<<ans;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>

int main(){
    int a, ta, b, tb;
    while(scanf("%d%d%d%d", &a, &ta, &b, &tb) > 0){

        char aux[10];
        scanf("%s", aux);

        char* str = strtok(aux, ":");
        int depa = atoi(str) * 60;
        str = strtok(NULL, "");
        depa += atoi(str);

        int depb = 5*60;
        while(depb < 24*60 and depb+tb <= depa) depb += b;

        int qtd = 0;
        while(depb < 24*60 and depb < depa+ta) depb += b, qtd++;

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


#include <iostream>
#include <cmath>
using namespace std;
long long int n,county,kolvo,k,i;
int a[1000];
int main()
{
	cin >> n >> k;
	county = 2;
	while (county <= sqrt(n)) {
		if (n % county == 0) {
			n /= county;
			kolvo++;
			a[kolvo] = county;
		}
		else { county++; }
	}
	a[kolvo + 1] = n;
	kolvo++;
	if (kolvo < k) {
		cout << -1;
	}
	else {
		while (kolvo != k) {
			a[kolvo - 1] *= a[kolvo];
			kolvo --;
		}
		for (i = 1; i <= k; i++) {
			cout << a[i] << " ";

		}
	}
}


#include<stdio.h>

int max,n,i;

int enBuyuk(int x){

	max = 0;
	while(x){
		int a = x%10;
		if(a > max)
			max = a;
		x /= 10;
	}

	return max;
}

int main(){

	scanf("%d",&n);

	int s = 0;
	while(n > 0){
		n -= enBuyuk(n);
		s++;
	}

   printf("%d",s);

	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#define INF 2000000000
double X1, Y1, X2, Y2;
double Xw1, Yw1,Xw2, Yw2, Xm1, Ym1, Xm2, Ym2;
double A, B, C;
double Aw, Bw, Cw;
double Am, Bm, Cm;
void ecuatie_dreapta(double x1, double y1, double x2, double y2, double &A, double &B, double &C){
	A = y1-y2;
	B = x2-x1;
	C = x1*y2 - x2*y1;
}
double semn_segment(double A, double B, double C, double x, double y){
	if(A*x + B * y + C > 0) return 1;
	if(A*x + B*y + C < 0) return -1;
	return 0;
}
int egal_drepte(double A, double B, double C, double A1, double B1, double C1){
	if(A1 * A == 0 && A1 + A != 0) return 0;
	if(B1 * B == 0 && B1 + B != 0) return 0;
	if(C1 * C == 0 && C1 + C != 0) return 0;
	double v[6]; int  nr = 0;
	if(A) v[++nr] =  A1 / A;
	if(B) v[++nr] = B1 / B;
	if(C) v[++nr] = C1 / C;
	for(int i = 1; i < nr; ++i)
		if(v[i] != v[i+1]) return 0;
	return 1;
}
int if_intersectie(double x1, double y1, double x2, double y2, double xp1,double yp1,double xp2,double yp2, int R){
	double A, B, C, Ap, Bp, Cp;
	//R = 0;
	ecuatie_dreapta(x1,y1,x2,y2,A,B,C);
	ecuatie_dreapta(xp1,yp1,xp2,yp2,Ap,Bp,Cp);
	if(egal_drepte(A , B, C, Ap, Bp, Cp))
		if(R && ((x1 <= xp1 && xp1 <= x2) || (x2 <= xp1 && xp1 <= x1)) ) return 1;
		else return 0;
	if((double)semn_segment(A, B, C, xp1, yp1) * semn_segment(A,B,C,xp2,yp2) > 0.0) return 0;
	if((double)semn_segment(Ap,Bp,Cp,x1,y1) * semn_segment(Ap,Bp,Cp,x2,y2) > 0.0) return 0;
	return 1;
}
void perpendicular(double x, double y, double &xp, double &yp){
	double A = Xm2 - Xm1, B = Ym2-Ym1, C = x*(Xm1-Xm2) + y*(Ym1-Ym2);
	yp = (Am*C - A * Cm) / (A*Bm - Am*B);
	xp = (Bm*C - B * Cm) / (B * Am - Bm*A);
}
void pcte_inters(double A1,double B1, double C1, double A2, double B2, double C2, double &xsol, double &ysol){
	ysol = (A2*C1- A1*C2) / (A1*B2 - A2*B1);
	xsol = (B2*C1 - B1*C2) / (B1 *A2 - B2*A1);
}
int main(){
	//freopen("E.in" ,"r", stdin);
	//freopen("E.out", "w", stdout);
	scanf("%lf%lf%lf%lf", &X1, &Y1, &X2, &Y2);
	scanf("%lf%lf%lf%lf", &Xw1, &Yw1, &Xw2, &Yw2);
	scanf("%lf%lf%lf%lf", &Xm1, &Ym1, &Xm2, &Ym2);
	ecuatie_dreapta(X1, Y1, X2, Y2, A, B , C);
	ecuatie_dreapta(Xw1, Yw1, Xw2, Yw2, Aw, Bw, Cw);
	ecuatie_dreapta(Xm1, Ym1, Xm2, Ym2, Am, Bm, Cm);
	if(if_intersectie(X1, Y1, X2, Y2, Xm1, Ym1, Xm2, Ym2,0)){
		printf("NO");
		return 0;
	}
	if(!if_intersectie(X1, Y1, X2, Y2, Xw1, Yw1, Xw2, Yw2,1)){
		printf("YES");
		return 0;
	}
	if((egal_drepte(A,B,C,Am,Bm,Cm) || semn_segment(Am, Bm, Cm, X1,Y1) != semn_segment(Am, Bm, Cm, X2, Y2)) || (semn_segment(Am, Bm, Cm,X1,Y1) == 0 && semn_segment(Am,Bm,Cm,X2,Y2)==0)){
		printf("NO");
		return 0;
	}
	/*else if( if_intersectie(X1, Y1, X2, Y2, Xw1, Yw1, Xw2, Yw2,1) ){
		printf("YES");
		return 0;
	}*/
	double X1perp, Y1perp;
	perpendicular(X1, Y1, X1perp, Y1perp);
	double X1prim = X1perp + (X1perp - X1), Y1prim = Y1perp + (Y1perp-Y1);
	//if(if_intersectie(X2, Y2, X1prim, Y1prim, Xw1, Yw1, Xw2, Yw2,1)) {printf("NO"); return 0;}
	//if(X2 == X1prim && Y2 == Y1prim) {printf("NO"); return 0;}

	double Aseg,Bseg,Cseg;
	ecuatie_dreapta(X1prim, Y1prim, X2, Y2, Aseg, Bseg,Cseg);
	double xinters,yinters;

	pcte_inters(Am,Bm, Cm, Aseg,Bseg, Cseg,xinters,yinters);
	if( !( ((Xm1 <= xinters && xinters <= Xm2) || (Xm2 <= xinters && xinters <= Xm1)) && ((Ym1 <= yinters && yinters <= Ym2) || (Ym2 <= yinters && yinters <= Ym1)) ) ) {printf("NO");return 0;}

	if(if_intersectie(X1, Y1, xinters,yinters, Xw1, Yw1, Xw2, Yw2,1)) {printf("NO"); return 0;}
	if(if_intersectie(X2, Y2, xinters,yinters,Xw1,Yw1,Xw2,Yw2,1)) {printf("NO"); return 0;}
	printf("YES");
	return 0;
}


#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <iostream>
int n; // number of songs;
int T; // total expected length of playlist
const int max_n = 15; // max num of songs

struct song{
  int len; //(1-15)
  int genre; // 1-3
};

struct song songs[max_n];
bool song_mask[max_n];
long long int possible = 0;

int playlist[max_n];

long long int genre_possibilities;
int genre_ll;

int genre_order_plist[max_n];

void  genre_order_possibilities(int songs_so_far)
{
  for (int i = 0 ; i!= genre_ll; ++i)
    {
      //  if (songs_so_far <1 )
      //printf("(%d) i:%d. ll%d\n", songs_so_far, i, genre_ll);
      if (! song_mask[i] && ( (!songs_so_far) || songs[playlist[i]].genre != genre_order_plist[songs_so_far-1]) )
	{
	  if ( songs_so_far+1 == genre_ll)
	    {
	      genre_possibilities++;
	    }
	  else
	    {
	      song_mask[i] = true;
	      genre_order_plist[songs_so_far] = songs[playlist[i]].genre;
	      genre_order_possibilities(songs_so_far+1);
	      song_mask[i] = false;
	    }
	}
    }

}

const int tmax = 14348907;
long long int checklist [tmax];;

void count_playlist_permutations_real(int n_s)
{
  /* now playlist has playlist of desirable length, but not sure if desirable mix of genres */
  //puts("o2");

  //printf("ll:%d\n", n_s);

  genre_ll = n_s;
  genre_possibilities = 0;
  genre_order_possibilities(0);
  //possible+= genre_possibilities;

}

void count_playlist_permutations(int n_s)
{
  int ternary = 0;
  int ternary_base = 1;

  int genres[3] = {0,0,0};
  int tmp[15];
  int i;
  //puts("ordcnt");
  for (i = 0 ; i!= n_s ; ++i) {
    genres[songs[playlist[i]].genre-1]++;
    //printf("%d ",playlist[i]);
  }
  //putchar(10);

  std::sort(genres, genres+3);
  if (genres[2] > (n_s+1)/2) return;

  for (i = 0 ; i != genres[0] ; ++i)
    tmp[i] = 0;
  for (; i != genres[0] + genres[1] ; ++i)
    tmp[i] = 1;
  for (; i!= n_s ; ++i)
    tmp[i] = 2;

  for (int i = 0 ; i!= n_s ; ++i) {
    ternary += tmp[i]*ternary_base;
    ternary_base *= 3;
  }

  if (checklist[ternary] == -1)
    {
      count_playlist_permutations_real(n_s);
      checklist[ternary] = genre_possibilities;
      //printf("checklist[%d] = %ld;\n", ternary, genre_possibilities% 1000000007UL);
    }

  possible+=checklist[ternary];
  if (possible > 1000000007ULL)
    possible %= 1000000007ULL;

}

void search_pos(int len_so_far, int songs_so_far)
{
  //  int lsf = len_so_far;
  int prev_song = 0;
  if (songs_so_far)
    {
      prev_song = playlist[songs_so_far-1]+1;
    }

  for (int i = prev_song ; i!= n; ++i)
    {
      //if (! song_mask[i] && ( (!len_so_far) || songs[i].genre != songs[playlist[songs_so_far-1]].genre) )
	{
	  if ( songs[i].len+len_so_far == T)
	    {
	      playlist[songs_so_far] = i;
	      count_playlist_permutations(songs_so_far+1);
	      // possible++;
	      // if (possible == 1000000007)
	      // 	possible = 0;
	    }
	  else if ( songs[i].len+len_so_far <= T)
	    {
	      //song_mask[i] = true;
	      playlist[songs_so_far] = i;
	      search_pos(songs[i].len+len_so_far, songs_so_far+1);
	      //song_mask[i] = false;
	    }
	}
    }
}

int main(int argc, char ** argv)
{
  scanf ( "%d %d\n" , &n, &T);

  for (int i = 0 ; i!= n ; ++i)
    {
      scanf ( "%d %d\n" , & (songs [ i ] . len ) , & (songs [ i ] . genre ));
    }
  memset(checklist, 0xff, 14348907*sizeof(long long));
  checklist[14319261] = 420863916;//12420864000UL;
  checklist[1593225] = 35596800;
  checklist[530334] = 10160640;
  checklist[1591029] = 88646400;
  checklist[1593945] = 3628800;
  checklist[4781871] = 123379200;
  checklist[4779675] = 596160000;
  checklist[4773087] = 115596793;
  checklist[1591002] = 115292160;
  checklist[14347813] = 203212800;
  checklist[14345625] = 66867193;

  search_pos(0,0);
  std::cout << possible << std::endl;
  return 0;
}


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

template <typename T>

void read(T &a)
{
	T x = 0,f = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9')
	{
		if (ch == '-') f = -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9')
	{
		x = (x << 1) + (x << 3) + (ch ^ 48);
		ch = getchar();
	}
	a = x * f;
}

template <typename T,typename... Args> void read(T &t,Args &... args) {read(t); read(args...); }

int n,a[1000005],fac[25];

signed main()
{
	fac[0] = 1;
	for (int i = 1; i <= 20; i++) fac[i] = fac[i - 1] * i;
	int t = 1;
	while (t--)
	{
		read(n);
		printf("%lld\n",fac[n] / fac[n / 2] / fac[n / 2] * fac[n / 2 - 1] * fac[n / 2 - 1] / 2);
	}
	return 0;
}


//
/*==========================================================*/
/*    Template ver 2017-0720    |    Created by JollyBee    */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
const double EPS=(double)1e-9;
const double PI=(double)acos(-1.0);
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define FOR(i,n) for(int i=0;i<n;i++)
#define REPP(i,l,r,c) for(int i=l;i<=r;i+=c)
#define REP(i,l,r) REPP(i,l,r,1)
#define FORD(i,n) for(int i=n-1;i>=0;i--)
#define REVV(i,l,r,c) for(int i=l;i>=r;i-=c)
#define REV(i,l,r) REVV(i,l,r,1)
//random
int irand(int lo, int hi){
    return (((double)rand())/(RAND_MAX+1.0)) * (hi-lo+1) + lo;
}
//ll to string
string toString(ll x) {
    stringstream ss;
    ss << x;
    return ss.str();
}
//string to ll
ll toNumber(string S) {
    ll ret;
    sscanf(S.c_str(),"%lld",&ret);
    return ret;
}
// std::fill(start, end, value);
// for(auto it: DS){}

const int INF=(int)2e9;
const ll MOD=(ll)1e9+7;
/*==========================================================*/
/*                     END OF TEMPLATE                      */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/

ll dat[15];

int dp[10005];
ll solve(const ll& w, const ll& summ){
    if(summ <= w) return summ;
    //do: target -= 400
    ll target = max((ll)0, w-(ll)400);
    REV(num,8,1){
        ll ret = min(dat[num], target/(ll)num);
        ret = max((ll)0, ret-100);
        dat[num] -= ret;
        target -= (ll)num * ret;
    }
    //change target
    int _w = (int)min(w, (ll)400 + target);
    //maximize
    REP(num,1,8) dat[num] = min(dat[num], (ll)1e4);
    //reset
    FOR(i,10003) dp[i] = (i==0);
    //knapsack
    REP(num,1,8) for(; dat[num] > 0; dat[num]--){
        //fill
        REV(i,_w,num) dp[i] |= dp[i-num];
    }
    //find
    int maxx = 0;
    FOR(i,10003) if(dp[i] == 1) maxx = i;
    //return
    return w - (ll)(_w-maxx);
}

int main(){
    ll summ = (ll)0;
    //input
    ll w; scanf("%lld", &w);
    REP(i,1,8) scanf("%lld", dat+i), summ += (ll)i * dat[i];
    //print
    printf("%lld\n", solve(w, summ));
    return 0;
}