#include<stdio.h>
#define N 25
using namespace std;
int vis[N],a[N][N];
int n,m,k,x,y,z,i,l,r,mid;
int DFS(int x,int now){
	if (now>mid) return 0;
	if (x>n) return 1;
	int ret=DFS(x+1,now);
	for (int i=1;i<=n&&ret<k;i++)
		if (!vis[i]&&a[x][i])
			vis[i]=1,ret+=DFS(x+1,now+a[x][i]),vis[i]=0;
	if (ret>=k) ret=k;
	return ret;
}
int main(){
	scanf("%d%d%d",&n,&m,&k);
	for (i=1;i<=m;i++)
		scanf("%d%d%d",&x,&y,&z),a[x][y]=z;
	l=0;r=1000*n;
	while (l<r){
		mid=(l+r)>>1;
		if (DFS(1,0)>=k) r=mid;else l=mid+1;
  }printf("%d\n",l);
}

#include <bits/stdc++.h>

typedef long long LL;
typedef double DB;

#define sf scanf
#define pf printf
#define mp make_pair
#define nl printf("\n")

#define FOR(i,a,b) for(i = a; i <= b; ++i)
#define FORD(i,a,b) for(i = a; i >= b; --i)
#define FORS(i,n) for(i = 0; i < n; ++i)
#define FORM(i,n) for(i = n - 1; i >= 0; --i)
#define reset(i,n) memset(i, n, sizeof(i))
#define open freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
#define close fclose(stdin); fclose(stdout)

using namespace std;

const LL mod = 1e9 + 7;
const LL INF = 4e18;
const int inf = 2e9;
const double eps = 1e-13;

int gcd(int a, int b) { return b? gcd(b, a%b): a; }
int lcm(int a, int b) { return a/ gcd(a, b)*b; }

int suami[25];
int harem[25];
int poin[25][25];
vector<int> ans;
int n;

void find(int mask, int man, int temp) {
    int i;
    if(man == n) {
        //FORS(i, n) pf("suami %d adalah %d\n", i, suami[i]);
        //pf("suka %d\n\n", temp);
        ans.push_back(temp);
        return;
    }
    if(mask & (1 << man)) {
        FORS(i, n) {
            if(suami[i] == 0 && poin[man+1][i+1]) {
                suami[i] = man + 1;
                find(mask, man + 1, temp + poin[man+1][i+1]);
                suami[i] = 0;
            }
        }
    } else {
        find(mask, man + 1, temp);
    }
}

int main(void)
{
    //open;
    int i, j, k, t;
    sf("%d %d %d", &n, &k, &t);
    while(k--) {
        int a, b, c;
        sf("%d %d %d", &a, &b, &c);
        harem[a]++;
        poin[a][b] = c;
    }
    int pol = (1 << n), mask;
    FORS(mask, pol) {
        bool valid = 1;
        FORS(i, n) {
            if((mask & (1 << i)) && harem[i+1] == 0) {
                valid = 0;
                break;
            }
        }
        if(!valid) continue;
        find(mask, 0, 0);
    }
    sort(ans.begin(), ans.end());
    cout << ans[t-1] << endl;
    //FORS(i, ans.size()) pf("%d ", ans[i]); nl;

    //close;
    return 0;
}

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

const int N = 22, M = 102;
int n, k, t, res;
int a[M], b[M], w[M];
bool sta[N], stb[N];

void dfs(int i, int m, int cur)
{
	if(cur > m) return;
	if(res >= t) return;
	if(i == k)
	{
		++res;
		return;
	}
	dfs(i+1, m, cur);
	if(!sta[a[i]] && !stb[b[i]])
	{
		sta[a[i]] = stb[b[i]] = true;
		dfs(i + 1, m, cur + w[i]);
		sta[a[i]] = stb[b[i]] = false;
	}
}

int main()
{
	cin >> n >> k >> t;
	for(int i = 0; i < k; ++i)
		cin >> a[i] >> b[i] >> w[i];
	int lo = 0, hi = 100000;
	while(lo < hi)
	{
		int m = lo + hi >> 1;
		res = 0;
		dfs(0, m, 0);
		if(res >= t) hi = m;
		else lo = m + 1;
	}
	cout << lo << endl;
	return 0;
}

#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
#define w first
#define m second
using namespace std;
typedef pair<int, long long> PIL;
const int N = 22, M = 102;
int n, k, t, cnt;
PIL e[M];

void dfs(int i, int m, int val, long long mask)
{
	if(cnt >= t || i == k) return;
	if(val + e[i].w > m) return;
	if(!(e[i].m & mask))
	{
		++cnt;
		dfs(i + 1, m, val + e[i].w, mask | e[i].m);
	}
	dfs(i + 1, m, val, mask);
}

int main()
{
	cin >> n >> k >> t;
	for(int i = 0, h, w; i < k; ++i)
	{
		cin >> h >> w >> e[i].w;
		e[i].m |= (1ll << h + n) | (1 << w);
	}
	sort(e, e + k);
	int lo = 0, hi = 100000;
	while(lo < hi)
	{
		int m = lo + hi >> 1;
		cnt = 1;
		dfs(0, m, 0, 0);
		if(cnt >= t) hi = m;
		else lo = m + 1;
	}
	cout << lo << endl;
	return 0;
}

#include<bits/stdc++.h>
#define ii pair<int,int>

using namespace std;

int mid,n,k,m,x,y,z,l,r;
bool vis[25];
vector<ii>edge[25];

int dfs(int id,int res)
{
    if (res>mid) return 0;
    if (id>n) return 1;
    int ret=0;
    for (auto v:edge[id])
    {
        if (ret>=k) break;
        if (!vis[v.first])
        {
            vis[v.first]=1;
            ret+=dfs(id+1,res+v.second);
            vis[v.first]=0;
        }
    }
    if (ret>=k) return k;
    return min(ret+dfs(id+1,res),k);
}

bool cmp(ii a,ii b)
{
    return a.second>b.second;
}

int main()
{
    scanf("%d%d%d",&n,&m,&k);
    for (int i=1;i<=m;i++)
    {
        scanf("%d%d%d",&x,&y,&z);
        edge[x].push_back(ii(y,z));
    }
    for (int i=1;i<=n;i++)
        sort(edge[i].begin(),edge[i].end(),cmp);
    l=0,r=n*1000;
    while (l<r)
    {
        mid=(l+r)>>1;
        if (dfs(1,0)>=k) r=mid;
        else l=mid+1;
    }
    printf("%d\n",l);
}

#include <bits/stdc++.h>
using namespace std;
int n, m, t;
vector<pair<int, pair<int, int> > > e;
struct Node {
	int mask1, mask2, cur, sum;
	Node() {}
	Node(int m1, int m2, int c, int s) : mask1(m1), mask2(m2), cur(c), sum(s) {}
	bool operator < (const Node &oth) const {
		return sum > oth.sum;
	}
};
priority_queue<Node> pq;
int main() {
	scanf("%d%d%d", &n, &m, &t);
	for (int i = 0; i < m; i++) {
		int u, v, w;
		scanf("%d%d%d", &u, &v, &w);
		u--, v--;
		e.push_back(make_pair(w, make_pair(u, v)));
	}
	sort(e.begin(), e.end());
	pq.push(Node(0, 0, 0, 0));
	for (int _ = 1; _ < t; _++) {
		Node nd = pq.top();
		pq.pop();
		for (int i = nd.cur; i < m; i++) if (!(nd.mask1 & (1 << e[i].second.first)) && !(nd.mask2 & (1 << e[i].second.second))) {
			Node nnd(nd.mask1 ^ (1 << e[i].second.first), nd.mask2 ^ (1 << e[i].second.second), i + 1, nd.sum + e[i].first);
			pq.push(nnd);
		}
	}
	printf("%d\n", pq.top().sum);
	return 0;
}

/// In The Name Of God

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

using namespace std;

#define REP(i,n) for((i)=0;(i)<(n);(i)++)
typedef long long ll;

priority_queue<int> pq;
int visit[32];
int maxFind=1000*1000;
vector<pair<int,int> > g[32];
int n,t;

void back(int node,int ans){
    if(node==n){
        pq.push(ans);
        if(pq.size()>t){
            maxFind=pq.top();
            pq.pop();
        }
        return ;
    }
    int i,k;
    for(i=0;i<g[node].size();i++){
        k = g[node][i].first;
        if(!visit[k]){
            visit[k]=true;
            if(ans+g[node][i].second<maxFind){
                back(node+1,ans+g[node][i].second);
            }
            visit[k]=false;
        }
    }
    if(ans<maxFind)
        back(node+1,ans);
}

int main(){
    ios::sync_with_stdio(false);
    int k,i,a,b,c;
    cin>>n>>k>>t;
    REP(i,k){
        cin>>a>>b>>c;
        a--;b--;
        g[a].push_back(make_pair(b,c));
    }
    back(0,0);
    cout<<(pq.top())<<endl;
    return 0;
}

#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
int i,j,k,l,n,m,a[120][120],t,x,y;
priority_queue <int> q;
void dfs(int l,int s,int val){
    if(q.size()==t && val>q.top())return;
    if(l==n+1){
        q.push(val);
        if(q.size()>t)q.pop();
        return;
    }
    dfs(l+1,s,val);
    for(int i=1;i<=n;++i)if(!(s>>i-1&1) && a[l][i])
        dfs(l+1,s|1<<i-1,val+a[l][i]);
}
int main(){
    scanf("%d%d%d",&n,&m,&t);
    for(i=1;i<=m;++i){
        scanf("%d%d%d",&x,&y,&k);
        a[x][y]=k;
    }
    dfs(1,0,0);
    printf("%d\n",q.top());
}

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#define FOR(i, n) for (int i = 0; i < (n); ++i)
#define TR(it, c) for (typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define MAX 200000
using namespace std;

int n, k, t, w[20][20];
vector<int> g[20];
priority_queue<int> pq;
bool v[20];

void dfs(int x, int total = 0) {
	if (x == n) {
		pq.push(total);
		if (pq.size() > t) pq.pop();
	} else {
		dfs(x + 1, total);
		TR (it, g[x]) if (!v[*it] && (pq.size() < t || total + w[x][*it] < pq.top())) {
			v[*it] = true;
			dfs(x + 1, total + w[x][*it]);
			v[*it] = false;
		}
	}
}

int main() {
	scanf("%d%d%d", &n, &k, &t);
	FOR (i, k) {
		int u, v, c;
		scanf("%d%d%d", &u, &v, &c); --u; --v;
		g[u].push_back(v);
		w[u][v] = c;
	}
	dfs(0);
	printf("%d\n", pq.top());
	return 0;
}

//This code was writen by Alexander Dryapko (sdryapko)
#include<sstream>
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<string.h>
#define gcd(a,b) __gcd((a),(b));
#define sqr(a) ((a)*(a))
#define odd(a) ((a)&1)
#define pw2(x) (1ll<<(x))
#define F first
#define S second
const int maxi=2000000000;
const int maxq=1000000000;
const double eps=1e-10;
const double pi=3.1415926535897932;
const double inf=1e+18;
const int mo=1000000007;

using namespace std;
int stn,ms[1111][1111],n,k,t,st[1111111],x,y,z,sum;
bool f[11111];
void rec(int x,int y) {
	sum+=ms[x][y];
	if (x==n) {
		stn++;
		st[stn]=sum;
	}
	if (y) f[y]=true;
	if (x<n) for (int i=0;i<=n;i++) if (f[i]==false&&(ms[x+1][i]||i==0)) rec(x+1,i);
	sum-=ms[x][y];
	f[y]=false;
}
int main(){
        //freopen("input.txt","r",stdin);
        //freopen("output.txt","w",stdout);
        cin>>n>>k>>t;
        for (int i=0;i<k;i++) {
        	cin>>x>>y>>z;
        	ms[x][y]=z;
        }
      //  stn++;
      //  st[stn]=0;
        for (int i=0;i<=n;i++) if (ms[1][i]||i==0) rec(1,i);
        sort(st+1,st+stn+1);
//       	cout<<stn+1<<endl;
 //      for (int i=1;i<=stn;i++) cout<<st[i]<<endl;
        cout<<st[t]<<endl;
      	return 0;
}

#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
int i,j,k,l,n,m,a[120][120],t,x,y;
priority_queue <int> q;
void dfs(int l,int s,int val){
	if(q.size()==t && val>q.top())return;
	if(l==n+1){
		q.push(val);
		if(q.size()>t)q.pop();
		return;
	}
	dfs(l+1,s,val);
	for(int i=1;i<=n;++i)if(!(s>>i-1&1) && a[l][i])
		dfs(l+1,s|1<<i-1,val+a[l][i]);
}
int main(){
	scanf("%d%d%d",&n,&m,&t);
	for(i=1;i<=m;++i){
		scanf("%d%d%d",&x,&y,&k);
		a[x][y]=k;
	}
	dfs(1,0,0);
	printf("%d\n",q.top());
}

#include <cstdio>
#include <queue>
#include <algorithm>
using namespace std;

const int INF = 1000000007;
const long long LINF = 1ll*INF*INF;

int n,m,t,a[20][20],e[20];
priority_queue<int> u;

void gao(int x, int sum, int mask){
    if(u.size()==t && sum>=u.top()) return;
    if(x==n){
        if(u.size()==t) u.pop();
        return u.push(sum);
    }
    gao(x+1,sum,mask);
    for(int s=e[x]&mask;s;s&=s-1){
        int y=__builtin_ctz(s);
        gao(x+1,sum+a[x][y],mask^1<<y);
    }
}

int main(){
    scanf("%d%d%d",&n,&m,&t);
    for(int i=0;i<m;i++){
        int x,y,c;
        scanf("%d%d%d",&x,&y,&c);
        a[--x][--y]+=c;
        e[x]|=1<<y;
    }
    gao(0,0,(1<<n)-1);
    printf("%d\n",u.top());
}

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

int n, k, t;
int h[101], w[101], r[101];
bool va[5], vb[5];

int main() {
//freopen("input.txt", "r", stdin);
    cin >> n >> k >> t;
    for (int i = 0; i < k; i++) {
        cin >> h[i] >> w[i] >> r[i];
        h[i]--;
        w[i]--;
    }

    int maxB = 1 << k;
    vector<int> v;
    for (int mask = 0; mask < maxB; mask++) {
        memset(va, false, sizeof(va));
        memset(vb, false, sizeof(vb));
        bool ok = true;
        int tot = 0;
        for (int i = 0; i < k; i++) {
            if (mask & (1 << i)) {
                if (va[h[i]] || vb[w[i]]) {
                    ok = false;
                    break;
                }
                tot += r[i];
                va[h[i]] = true;
                vb[w[i]] = true;
            }
        }
        if (ok) v.push_back(tot);
    }
    sort(v.begin(), v.end());
    cout << v[t - 1] << endl;
    return 0;
}

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<math.h>
#include<string>
#include<map>
#include<set>
using namespace std;
typedef long long ll;

vector<pair<int,int> > e[22];
int n,vis[22];
vector<int> ans;
int cnt,t;
void dfs(int pos,int sum,int val)
{
	if(val<=sum)
		return;
	if(pos>n){
		if(val>sum){
			cnt++;
		}
		return;
	}
	dfs(pos+1,sum,val);
	if(cnt>=t) return;
	for(int i=0;i<(int)e[pos].size();i++){
		int v=e[pos][i].first;
		if(vis[v]==0){
			vis[v]=1;
			dfs(pos+1,sum+e[pos][i].second,val);
			if(cnt>=t) return;
			vis[v]=0;
		}
	}
	return;
}
int solve(int val)
{
	memset(vis,0,sizeof(vis));
	cnt=0;
	dfs(1,0,val);
	if(cnt>=t) return 1;
	memset(vis,0,sizeof(vis));
	cnt=0;
	dfs(1,0,val+1);
	if(cnt<t) return -1;
	return 0;
}
int main() {

	int k,x,y,z;
	scanf("%d%d%d",&n,&k,&t);
	for(int i=0;i<k;i++){
		scanf("%d%d%d",&x,&y,&z);
		e[x].push_back(make_pair(y,z));
	}
	int left=0,right=40000,mid,ans=-1;
	while(left<=right){
		mid=(left+right)/2;
		int f=solve(mid);
		if(f==1)
			right=mid-1;
		else if(f==-1)
			left=mid+1;
		else{
			ans=mid;
			break;
		}
	}
	printf("%d\n",ans);
}

//In the name of Allah
//
//
//////////////////////
// Program:
// Written By Alireza Farhadi (LGM)
//////////////////////
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cctype>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <utility>
#include <vector>
#include <bitset>
#include <deque>
#include <iomanip>
#include <complex>
#include <fstream>
#include <sstream>
#include <map>
//#include <climits>
//#include <list>

using namespace std;

#if ( _WIN32 || __WIN32__ )
    #define LLD "%I64d"
#else
    #define LLD "%lld"
#endif

#define show(x) cerr<<((#x))<<" = "<<((x))<<" "<<endl
#define bit(a,b) (((a)>>(b))&1)
#define gcd __gcd
#define endl '\n'
#define bcnt(x) ((__builtin_popcount(x)))
#define sz(x) ((int((x).size())))
#define sqr(x) ((((x))*((x))))
#define fx(x) fixed<<setprecision(x)

template<class T> inline void smn(T &a,const T &b){if(b<a) a=b;}
template<class T> inline void smx(T &a,const T &b){if(b>a) a=b;}
template<class T> inline T rev(const T & a){T _=a; reverse(_.begin(),_.end()); return _;}

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

const double eps=1e-9;
const ld leps=1e-14;
const int MN=1000;
int n,k,t;
vector <int> list[MN];
vector <int> w[MN];
vector <int> res;
set<pie> me;
int cnt;
void bt(int a,int b,int c)
{
	if (me.size()==t && c>=me.rbegin()->first) return ;
	if (a==n)
	{
		me.insert(pie(c,cnt++));
		while (me.size()>t)
			me.erase(*me.rbegin());
		return ;
	}
	bt(a+1,b,c);
	for (int i=0;i<list[a].size();i++) if (bit(b,list[a][i])==1)
	{
		int v=list[a][i];
		bt(a+1,b^(1<<v),c+w[a][i]);
	}
}
int main(int argc,char * argv[])
{
	ios_base::sync_with_stdio(false);
	cin>>n>>k>>t;
	for (int i=0;i<k;i++)
	{
		int a,b,c;
		cin>>a>>b>>c; a--; b--;
		list[a].push_back(b);
		w[a].push_back(c);
	}
	bt(0,(1<<n)-1,0);
	cout<<me.rbegin()->first<<endl;
	return 0;
}

#include <iostream>

using namespace std;

int n, k, t;
bool wf[20];
int rw[20][20], rr[20][20], rk[20] = {0};
int cnt, mr;

void go(int h)
{
    if (h == n)
        return;
    go(h + 1);
    for (int i = 0; i < rk[h]; ++i)
        if (wf[rw[h][i]] && (rr[h][i] <= mr))
        {
            if (++cnt >= t)
                return;
            wf[rw[h][i]] = false;
            mr -= rr[h][i];
            go(h + 1);
            mr += rr[h][i];
            wf[rw[h][i]] = true;
            if (cnt >= t)
                return;
        }
}

bool count(int maxr)
{
    int i;
    for (i = 0; i < n; ++i)
        wf[i] = true;
    cnt = 1;
    mr = maxr;
    go(0);
    return cnt >= t;
}

void bs(int l, int r)
{
    int m;
    while (l < r)
    {
        m = (l + r) / 2;
        if (count(m))
            r = m;
        else
            l = m + 1;
    }
    cout << l << endl;
}

int main(void)
{
    cin >> n >> k >> t;
    int sum = 0, mx = 0, h, w, r;
    for (int i = 0; i < k; ++i)
    {
        cin >> h >> w >> r;
        --h;
        --w;
        rw[h][rk[h]] = w;
        rr[h][rk[h]++] = r;
        sum += r;
        if (r > mx)
            mx = r;
    }
    if (n * mx < sum)
        sum = n * mx;
    bs(0, sum);
    return 0;
}

#include<iostream>
#include<list>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
using namespace std;

int grafo[20][20];
vector<int> sol;
bool assigned[20];
int N, k, t, peso=0;
void findSol(int chi)
{
	if(chi==N)
	{
		sol.push_back(peso);
		return;
	}
	findSol(chi+1);
	for(int i=0;i<N;i++)
		if(!assigned[i]&&grafo[chi][i]>0)
		{
			assigned[i]=true;
			peso+=grafo[chi][i];
			findSol(chi+1);
			assigned[i]=false;
			peso-=grafo[chi][i];
		}
}

int main(void)
{
	cin >> N >> k >> t;
	for(int i=0;i<k;i++)
	{
		int da, a, x;
		cin >> da >> a >> x;
		da--;a--;
		grafo[da][a]=x;
	}
	findSol(0);
	sort(sol.begin(), sol.end());
	//cout << sol.size() << endl;
	cout << sol[t-1];
	return 0;
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <cmath>
#include <set>
#include <map>
#include <cstdio>
#include <stdlib.h>
#include <stack>
#include <numeric>
#include <bitset>
#include <cctype>
typedef long long ll;
#define MAX 25
using namespace std;
int n,m;
#define INF 2147483647
#define inf 1<<30
#define MOD 1000000007
#define EPS 1e-20
#define G 9.8
#define PI acos(-1)
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
bool debug = false;
int k;
int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};

int mp[MAX][MAX],t;
priority_queue<int> q;
void dfs(int x, int s, int val) {
    if (q.size()==t && val > q.top()) return;
    if (x == n) {
        q.push(val);
        if (q.size() > t) q.pop();
        return;
    }
    dfs(x+1,s,val);
    REP(i,n) if (((s>>i) & 1)==0) {
        if (mp[x][i]) {
            dfs(x+1, s | (1<<i), val + mp[x][i]);
        }
    }
}
int main(){
    scanf("%d%d%d", &n, &k, &t);
    int h,w,r;
    REP(i,k) {
        scanf("%d%d%d", &h, &w, &r); h--; w--;
        mp[h][w]=r;
    }
    dfs(0, 0, 0);
    printf("%d\n", q.top());
    return 0;
}

#include<stdio.h>
#define N 25
using namespace std;
int vis[N],a[N][N];
int n,m,k,x,y,z,i,l,r,mid;
int DFS(int x,int now){
	if (now>mid) return 0;
	if (x>n) return 1;
	int ret=DFS(x+1,now);
	for (int i=1;i<=n&&ret<k;i++)
		if (!vis[i]&&a[x][i])
			vis[i]=1,ret+=DFS(x+1,now+a[x][i]),vis[i]=0;
	if (ret>=k) ret=k;
	return ret;
}
int main(){
	scanf("%d%d%d",&n,&m,&k);
	for (i=1;i<=m;i++)
		scanf("%d%d%d",&x,&y,&z),a[x][y]=z;
	l=0;r=1000*n;
	while (l<r){
		mid=(l+r)>>1;
		if (DFS(1,0)>=k) r=mid;else l=mid+1;
  }printf("%d\n",l);
}

/**
 * @author neko13
 */
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
// 13C
#define DBG 0
#define sz(c) ((int)(c).size())
#define   forl(i, a, b) for(int i = (a); i <  (b); ++i)
#define  forle(i, a, b) for(int i = (a); i <= (b); ++i)
#define   forg(i, a, b) for(int i = (a); i >  (b); --i)
#define  forge(i, a, b) for(int i = (a); i >= (b); --i)
#define  forlc(i, a, b) for(int i##_b = (b), i = (a); i <  i##_b; ++i)
#define forlec(i, a, b) for(int i##_b = (b), i = (a); i <= i##_b; ++i)
#define  forgc(i, a, b) for(int i##_b = (b), i = (a); i >  i##_b; --i)
#define forgec(i, a, b) for(int i##_b = (b), i = (a); i >= i##_b; --i)
#define forall(i, v   ) forlc(i, 0,   sz(v))
#define forlla(i, v   ) forge(i, sz(v)-1, 0)
#define  forls(i, n, a, b) for(int i = a; i != b; i = n[i])
#define rep(n)  for(int               repp = 0; repp <    (n); ++repp)
#define repc(n) for(int repp_b = (n), repp = 0; repp < repp_b; ++repp)
#define rst(a, v) memset(a, v, sizeof a)
#define cpy(a, b) memcpy(a, b, sizeof a)
#define rstn(a, v, n) memset(a, v, (n)*sizeof((a)[0]))
#define cpyn(a, b, n) memcpy(a, b, (n)*sizeof((a)[0]))
#define pr(x) #x"=" << (x) << " | "
#define dout  DBG && cerr << __LINE__ << ">>| "
#define mk(x) DBG && cerr << __LINE__ << "**| "#x << endl
#define dlist(args...) DBG && (dout << #args", = ", (void)(dbgr, args), cerr << " |" << endl)
#define ast(b) if(DBG && !(b)) { fprintf(stderr, "%d!!|\n", __LINE__); while(1) getchar(); }
#define pra(arr, a, b) if(DBG) { \
    dout<<#arr"[] | "; \
    forlec(i, a, b) cerr<<"["<<i<<"]="<<arr[i]<<" |"<<((i-(a)+1)%13?" ":"\n"); \
    if(((b)-(a)+1)%13) cerr<<endl; \
  }
#define rd(type, x) type x; cin >> x
inline int     rdi() { int d; scanf("%d", &d); return d; }
inline char    rdc() { scanf(" "); return getchar(); }
inline string  rds() { rd(string, s); return s; }
inline double rddb() { double d; scanf("%lf", &d); return d; }
template<class T> inline bool setmin(T& a, T b) { return a>b? a=b, true: false; }
template<class T> inline bool setmax(T& a, T b) { return a<b? a=b, true: false; }
struct debugger { template<typename T> debugger& operator , (const T& x) { cerr << x << ","; return *this; } } dbgr;

const int N = 32;

priority_queue<int> q;
int n, m, t, vs[N], a[N][N];

void dfs(int u, int m, int s) {
  if(sz(q)==t && s>=q.top()) return;
  if(u == n) {
    if(sz(q) == t) q.pop();
    return q.push(s);
  }
  dfs(u+1, m, s);
  for(int b = vs[u]&m; b; b &= b-1) {
    int v = __builtin_ctz(b);
    dfs(u+1, m^1<<v, s+a[u][v]);
  }
}

int main() {
  n = rdi(), m = rdi(), t = rdi();
  rep(m) {
    int u = rdi()-1, v = rdi()-1;
    a[u][v] += rdi(), vs[u] |= 1<<v;
  }
  dfs(0, (1<<n)-1, 0);
  printf("%d\n", q.top());
  return 0;
}

/**
 * @author neko13
 */
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
#define pb push_back
#define all(c) c.begin(), c.end()
// 13C
#define DBG 1
#define sz(c) ((int)(c).size())
#define   forl(i, a, b) for(int i = (a); i <  (b); ++i)
#define  forle(i, a, b) for(int i = (a); i <= (b); ++i)
#define   forg(i, a, b) for(int i = (a); i >  (b); --i)
#define  forge(i, a, b) for(int i = (a); i >= (b); --i)
#define  forlc(i, a, b) for(int i##_b = (b), i = (a); i <  i##_b; ++i)
#define forlec(i, a, b) for(int i##_b = (b), i = (a); i <= i##_b; ++i)
#define  forgc(i, a, b) for(int i##_b = (b), i = (a); i >  i##_b; --i)
#define forgec(i, a, b) for(int i##_b = (b), i = (a); i >= i##_b; --i)
#define forall(i, v   ) forlc(i, 0,   sz(v))
#define forlla(i, v   ) forge(i, sz(v)-1, 0)
#define  forls(i, n, a, b) for(int i = a; i != b; i = n[i])
#define rep(n)  for(int               repp = 0; repp <    (n); ++repp)
#define repc(n) for(int repp_b = (n), repp = 0; repp < repp_b; ++repp)
#define rst(a, v) memset(a, v, sizeof a)
#define cpy(a, b) memcpy(a, b, sizeof a)
#define rstn(a, v, n) memset(a, v, (n)*sizeof((a)[0]))
#define cpyn(a, b, n) memcpy(a, b, (n)*sizeof((a)[0]))
#define pr(x) #x"=" << (x) << " | "
#define dout  DBG && cerr << __LINE__ << ">>| "
#define mk(x) DBG && cerr << __LINE__ << "**| "#x << endl
#define dlist(args...) DBG && (dout << #args", = ", (void)(dbgr, args), cerr << " |" << endl)
#define ast(b) if(DBG && !(b)) { fprintf(stderr, "%d!!|\n", __LINE__); while(1) getchar(); }
#define pra(arr, a, b) if(DBG) { \
    dout<<#arr"[] | "; \
    forlec(i, a, b) cerr<<"["<<i<<"]="<<arr[i]<<" |"<<((i-(a)+1)%13?" ":"\n"); \
    if(((b)-(a)+1)%13) cerr<<endl; \
  }
#define rd(type, x) type x; cin >> x
inline int     rdi() { int d; scanf("%d", &d); return d; }
inline char    rdc() { scanf(" "); return getchar(); }
inline string  rds() { rd(string, s); return s; }
inline double rddb() { double d; scanf("%lf", &d); return d; }
template<class T> inline bool setmin(T& a, T b) { return a>b? a=b, true: false; }
template<class T> inline bool setmax(T& a, T b) { return a<b? a=b, true: false; }
struct debugger { template<typename T> debugger& operator , (const T& x) { cerr << x << ","; return *this; } } dbgr;

const int N = 20;

struct Graph {
  int v;
  bool ma[N], mb[N];
  bool operator < (const Graph& r) const {
    return v < r.v;
  }
} g;
int n, k, t;
vector<Graph> vg;

int main() {
  vg.pb(g), n = rdi(), k = rdi(), t = rdi();
  rep(k) {
    int u = rdi()-1, v = rdi()-1, w = rdi();
    forall(i, vg)
      if(!vg[i].ma[u] && !vg[i].mb[v]) {
          vg[i].ma[u]  =  vg[i].mb[v] = true , vg[i].v += w;
          vg.pb(vg[i]);
          vg[i].ma[u]  =  vg[i].mb[v] = false, vg[i].v -= w;
      }
    if(sz(vg) > t) {
      nth_element(vg.begin(), vg.begin()+t-1, vg.end());
      vg.erase(vg.begin()+t, vg.end());
    }
  }
  nth_element(vg.begin(), vg.begin()+t-1, vg.end());
  cout << vg[t-1].v << endl;
  return 0;
}

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>

using namespace std;

int	N, K, T, map[21][21], visit[21];
priority_queue<int> w;

inline int	read()
{
	char ch = getchar(); int x = 0; bool flag = 0;
	for (; ch != '-' && (ch < '0' || ch > '9'); ch = getchar());
	if (ch == '-') 	{	flag = 1;	ch = getchar();	}
	for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
	if (flag) return - x; return x;
}

void	dfs(int x, int y)
{
	if (w.size() == T)
	{
		if (w.top() <= y) return;
	}
	if (x == N + 1)
	{
		if (w.size() == T)	w.pop();
		w.push(y);
		return;
	}
	dfs(x + 1, y);
	for (int i = 1; i <= N; ++ i)
		if (!visit[i] && map[x][i])
		{
			visit[i] = 1;
			dfs(x + 1, y + map[x][i]);
			visit[i] = 0;
		}
}

int main()
{
	//freopen("a.in", "r", stdin);
	//freopen("a2.out", "w", stdout);
	N = read(); K = read(); T = read();
	for (int i = 1; i <= K; ++ i)
	{
		int x = read(), y = read();
		map[x][y] = read();
	}
	dfs(1, 0);
	printf("%d\n", w.top());
	//system("pause");
	return 0;
}

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

const int maxn=22;
int n, k, t;
priority_queue<int> que;
int ditu[maxn][maxn];
bool used[maxn];

void dfs(int step, int tot)
{
    if(que.size()>=t && tot>=que.top())
        return ;
    if(step>n)
    {
        que.push(tot);
        while(que.size()>t)
            que.pop();
        return ;
    }
    dfs(step+1, tot);
    for(int i=1;i<=n;++i)
        if(!used[i] && ditu[step][i]!=0)
        {
            used[i]=true;
            dfs(step+1, tot+ditu[step][i]);
            used[i]=false;
        }
}

int main()
{
    scanf("%d%d%d", &n, &k, &t);
    ++t;
    memset(ditu, 0, sizeof(ditu));
    int x, y;
    for(int i=1;i<=k;++i)
    {
        scanf("%d%d", &x, &y);
        scanf("%d", &ditu[x][y]);
    }
    memset(used, false, sizeof(used));

    que.push(0);
    dfs(1, 0);
    printf("%d\n", que.top());
//    system("pause");
    return 0;
}

#include <iostream>
#include <cstdio>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <iterator>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define x0 abc
#define y0 ABC
#define x1 abcd
#define y1 ABCD
#define xn abcde
#define yn ABCDE

#define l_b lower_bound
#define u_b upper_bound

#define in insert
#define er erase

#define fi first
#define se second
#define m_p make_pair

#define p_b push_back
#define po_b pop_back

#define uns unsigned

#define ld long double
#define ll long long

#define cont continue
#define re return

#define MAXLL 9000000000000000000LL
#define MAXINT 2000000000

#define MINLL -9000000000000000000LL
#define MININT -2000000000

#define pi acos(-1.)

#define endl '\n'

#define OUT cout << "-------" << endl;

using namespace std;

using namespace __gnu_pbds;

typedef tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

vector <int> v;

int a[181], b[181], c[181], n, i, k, t, sum;

bool pole[181], pole1[181];

    void rec(int nom)
    {
        if (nom == k + 1) {
            v.p_b(sum);

            re;
        }

        if (!pole[a[nom]] && !pole1[b[nom]]) {
            pole[a[nom]] = pole1[b[nom]] = true;

            sum += c[nom];

            rec(nom + 1);

            pole[a[nom]] = pole1[b[nom]] = false;

            sum -= c[nom];

            rec(nom + 1);

            re;
        }

        rec(nom + 1);
    }

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

    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> k >> t;

    for (i = 1; i <= k; i++) cin >> a[i] >> b[i] >> c[i];

    rec(1);

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

    cout << v[t - 1] << endl;

    re 0;
}

#include <cstdio>
#include <set>
#include <vector>
using namespace std;

const int Maxn = 25;

int n, k, t;
vector <int> w[Maxn], r[Maxn];
bool taken[Maxn];
multiset <int> res;

int Calc(int v, int l)
{
    if (!l) return 1;
    else {
        int res = 0;
        for (int i = v; i <= n; i++)
            for (int j = 0; j < w[i].size(); j++) if (!taken[w[i][j]]) {
                taken[w[i][j]] = true;
                res += Calc(v + 1, l - 1);
                taken[w[i][j]] = false;
            }
        return res;
    }
}

void Gen(int v, int l, int d)
{
    if (!l) {
        if (res.size() < t) res.insert(d);
        else if (d < *res.rbegin()) { res.erase(res.find(*res.rbegin())); res.insert(d); }
    } else for (int i = v; i <= n; i++)
              for (int j = 0; j < w[i].size(); j++) if (!taken[w[i][j]]) {
                  taken[w[i][j]] = true;
                  Gen(i + 1, l - 1, d + r[i][j]);
                  taken[w[i][j]] = false;
              }
}

int main()
{
    scanf("%d %d %d", &n, &k, &t);
    while (k--) {
        int hi, wi, ri; scanf("%d %d %d", &hi, &wi, &ri);
        w[hi].push_back(wi); r[hi].push_back(ri);
    }
    int add = 0;
    int i;
   /* for (i = 0; i <= n; i++) {
        add += Calc(1, i);
        if (t <= add) break;
    }*/
    for (i = n; i >= 0; i--) Gen(1, i, 0);
    printf("%d\n", *res.rbegin());
    return 0;
}

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
const int N=131072;
int sz,n,k,i,t,x,y,z,hp[N];
pair<int,pair<int,int> > w[N];
void up(int x){
	while(x>1 && hp[x]>hp[x/2]){
		swap(hp[x],hp[x/2]);
		x/=2;
	}
}
void dw(int x){
	int j;
	while(x+x<=sz){
		j=x;
		if(hp[x+x]>hp[x])j=x+x;
		if(x+x+1<=sz && hp[x+x+1]>hp[j])j=x+x+1;
		if(x==j)return;
		swap(hp[x],hp[j]);
		x=j;
	}

}
void th(int x){
	hp[++sz]=x;
	up(sz);
}
void dfs(int x,int mask1,int mask2,int q){
	if(sz==t && hp[1]<=q)return;
	if(x>k){
		if(sz<t)th(q);else {
			hp[1]=q;
			dw(1);
		}
		return;
	}
	int pe1=w[x].second.first,pe2=w[x].second.second;
	if((!(mask1&(1<<pe1))&&(!(mask2&(1<<pe2)))))
		dfs(x+1,mask1|(1<<pe1),mask2|(1<<pe2),q+w[x].first);
	dfs(x+1,mask1,mask2,q);
}
int main(){
	//freopen("input.txt","r",stdin);
	scanf("%d%d%d",&n,&k,&t);
	sz=0;
        for(i=1;i<=k;++i){
        	scanf("%d%d%d",&x,&y,&z);
        	w[i]=make_pair(z,make_pair(x,y));
        }
        sort(w+1,w+k+1);
        reverse(w+1,w+k+1);
        dfs(1,0,0,0);
        printf("%d\n",hp[1]);
        return 0;
}

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

using namespace std;

int n, k, t;
bool mf[5], ff[5];
int h[100], w[100], r[100];
vector<int> val;

void rec(int ind, int sum){
    if(ind == k - 1){
        val.push_back(sum);
        if(mf[h[ind] - 1] & ff[w[ind] - 1]) val.push_back(sum + r[ind]);
        return;
    }
    rec(ind+1, sum);
    if(mf[h[ind] - 1] & ff[w[ind] - 1]){
        mf[h[ind] - 1] = false; ff[w[ind] - 1] = false;
        rec(ind+1, sum + r[ind]);
        mf[h[ind] - 1] = true; ff[w[ind] - 1] = true;
    }
}

int main(){
    cin>>n>>k>>t;
    for(int i = 0; i < n; i++) mf[i] = ff[i] = true;
    for(int i = 0; i < k; i++){
        cin>>h[i]>>w[i]>>r[i];
    }
    rec(0, 0);
    sort(val.begin(), val.end());
    cout<<val[t-1];
    return 0;
}

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>

using namespace std;

int	N, K, T, map[21][21], visit[21], W, w[1000000];

inline int	read()
{
	char ch = getchar(); int x = 0; bool flag = 0;
	for (; ch != '-' && (ch < '0' || ch > '9'); ch = getchar());
	if (ch == '-') 	{	flag = 1;	ch = getchar();	}
	for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
	if (flag) return - x; return x;
}

void	dfs(int x, int y)
{
	if (x == N + 1)
	{
		w[++ W] = y;
		return;
	}
	dfs(x + 1, y);
	for (int i = 1; i <= N; ++ i)
		if (!visit[i] && map[x][i])
		{
			visit[i] = 1;
			dfs(x + 1, y + map[x][i]);
			visit[i] = 0;
		}
}

int main()
{
	N = read(); K = read(); T = read();
	for (int i = 1; i <= K; ++ i)
	{
		int x = read(), y = read();
		map[x][y] = read();
	}
	dfs(1, 0);
	sort(w + 1, w + W + 1);
	printf("%d\n", w[T]);
	//system("pause");
	return 0;
}

#include <iostream>
#include <vector>
#include <queue>
#include <cstdio>
#include <cstdio>
#include <stack>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <ctime>
#include <math.h>
#include <cassert>

#define forn(i, n) for(int i=0;i<n;++i)
#define for1(i, n) for(int i=1;i<=n;++i)
#define forv(i, v) for(int i=0;i<v.size();++i)
#define sz(v) v.size()
#define all(v) v.begin(), v.end()
#define pb push_back
#define mp make_pair
#define ld double
#define li long long
#define X first
#define Y second
#define P (259)

using namespace std;

typedef pair <ld, ld> pt;
const li N = 105, M = 502,  INF = 1000*1000*1000 + 7;
const ld  eps = 1e-9;
const ld pi = 3.1415926535897932384626433832795;

int p[N][N];

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

    int n,k,t;
    cin >> n >> k >> t;
    forn(i, k) {
        int t, b, l;
        cin >> t >> b >> l;
        p[t-1][b-1] = l;
    }
    vector<int> girl(n);

    t--;
    if (!t) {
        cout << 0;
        return 0;
    }

    vector<int> ans;
    set<vector<pair<int, int>>> us;

    for1(mask, (1 << n) - 1) {
        forn(i, n)
                girl[i] = i;
        do {
            int tmp = 0;
            vector<pair<int, int>> edges;
            forn(i, n) {
                if ((mask & (1 << i)) && p[i][girl[i]]) {
                    edges.pb(mp(i, girl[i]));
                    tmp += p[i][girl[i]];
                }
            }
            sort(all(edges));
            if (!us.count(edges) && sz(edges)) {
                ans.pb(tmp);
                us.insert(edges);
            }
        }while (next_permutation(all(girl)));
    }

    sort(all(ans));

    cout << ans[t-1];

    return 0;
}

#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <stdlib.h>
#include <sstream>
#include <assert.h>

#include <time.h>
#pragma comment(linker, "/STACK:20000000")

#define fr(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define fd(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define mp make_pair
#define pb push_back
#define ll long long

using namespace std;

int ri(){int x;scanf("%d",&x);return x;}
ll rll(){ll x;scanf("%lld",&x);return x;}

int mas[30][30];
//multiset<pair<int,int> > st;
multiset<int> st;
set<int> M;
int P;
int n,m,t;
int now=0;
int T;

void go(int pos,int MASK,int hm)
{
	if (pos==0)
	{
		if (M.find(hm)==M.end())
			st.insert(now),M.insert(hm);
		return;
	}
	fr(i,0,n-1)
		fr(j,n,2*n-1)
		{
			if (MASK & (1<<i) || MASK & (1<<j))
				continue;
			if (mas[i+1][j-n+1]==0)
				continue;
			int buf=mas[i+1][j-n+1];
			now+=buf;
			int pf=(1<<(i*n+j-n));
			go(pos-1,MASK|(1<<i)|(1<<j),hm|pf);
			now-=buf;
		}
}

void solve()
{
	n=ri(),m=ri(),t=ri();
	fr(i,1,m)
	{
		int a=ri(),b=ri(),r=ri();
		mas[a][b]=r;
	}
	for(P=1;P<=n;P++)
		T=0,go(P,0,0);
	st.insert(0);
	multiset<int > ::iterator it=st.begin();
	fr(i,2,t)
		it++;
	cout << *it << endl;
}

int main()
{
	#ifndef ONLINE_JUDGE
		freopen("C:/Users/CleRIC/Desktop/Универ/acm.timus.ru/input.txt","rt",stdin);
		freopen("C:/Users/CleRIC/Desktop/Универ/acm.timus.ru/output.txt","wt",stdout);
	#else
		//freopen("input.in","rt",stdin);
		//freopen("output.out","wt",stdout);
	#endif

	solve();

	#ifndef ONLINE_JUDGE
		printf("\n\ntime-%.3lf",clock()*1e-3);
	#endif

	return 0;
}

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

using namespace std;

const int MN = 100 + 10;

priority_queue <int> h;

vector <int> g[MN], w[MN];

bool used[MN];

int n, k, t;

void solve(int pos, int ww, bool ins) {
    if (!ins) {
        if (h.size() < t)
            h.push(ww);
        else if (ww < h.top()) {
            h.pop();
            h.push(ww);
        }
        else return;
        ins = true;
    }
    if (pos == n)
        return;
    solve(pos + 1, ww, ins);
    for(int i = 0; i < g[pos].size(); i ++) {
        int npos = g[pos][i];
        if (!used[npos]) {
            used[npos] = true;
            solve(pos + 1, ww + w[pos][i], false);
            used[npos] = false;
        }
    }
}

int main () {
    cin >> n >> k >> t;
    for(int i = 0; i < k; i ++) {
        int x, y, ww;
        cin >> x >> y >> ww;
        x --, y --;
        g[x].push_back(y);
        w[x].push_back(ww);
    }
    solve(0, 0, false);
    cout << (h.top()) << endl;
    return 0;
}

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

template <class T>
struct triple {
	T first;
	T second;
	T third;
};

vector<int> result (vector< triple<int> >& arg, vector< pair<bool, bool> > colour, int i) {
	vector<int> res, temp;
	colour[arg[i].first].first = true;
	colour[arg[i].second].second = true;
	res.push_back(arg[i].third);
	for (int j = i + 1; j < arg.size(); ++j) {
		if (!colour[arg[j].first].first && !colour[arg[j].second].second) {
			colour[arg[j].first].first = true;
			colour[arg[j].second].second = true;
			temp = result(arg, colour, j);
			colour[arg[j].first].first = false;
			colour[arg[j].second].second = false;
			for (int k = 0; k < temp.size(); ++k) {
				res.push_back(temp[k] + arg[i].third);
			}
		}
	}
	return res;
}
int compare (const void* lhs, const void* rhs) {
	return *(const int*)lhs - * (const int*)rhs;
}

int main() {
	int n, k, t;
	cin >> n >> k >> t;
	vector< triple<int> > arr(k);
	vector<int> sum, temp;
	for (int i = 0; i < k; ++i) {
		cin >> arr[i].first >> arr[i].second >> arr[i].third;
	}
	sum.push_back(0);
	for (int i = 0; i < k; ++i) {
		vector< pair<bool, bool> > colour(k, pair<bool, bool>(false, false));
		temp = result(arr, colour, i);
		sum.insert(sum.end(), temp.begin(), temp.end());
	}
	qsort(&sum[0], sum.size(), sizeof(int), compare);
	cout << sum[t - 1];
	return 0;
}

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

using namespace std;

#define ll long long

const int MN = 100 + 10;

struct block {
	int x, y, w;
	block () {};
	block (int xx, int yy, int ww) {
		x = xx, y = yy, w = ww;
	}
};

vector <block> sp;
vector <int> v;

bool bad[MN][MN];

int n, k, t;

bool can(int mask) {
	for(int i = 0; i < k; i ++) {
		if (mask & (1 << i)) {
			for(int j = i + 1; j < k; j ++)
				if ((mask & (1 << j)) && bad[i][j])
					return false;
		}
	}
	return true;
}

int main () {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin >> n >> k >> t;
	for(int i = 0; i < k; i ++) {
		int x, y, w;
		cin >> x >> y >> w;
		sp.push_back(block(x, y, w));
	}
	for(int i = 0; i < k; i ++)
		for(int j = 0; j < k; j ++)
			if (sp[i].x == sp[j].x || sp[i].y == sp[j].y)
				bad[i][j] = true;
	for(int mask = 0; mask < (1 << k); mask ++) {
		if (can(mask)) {
			int sum = 0;
			for(int i = 0; i < k; i ++)
				if (mask & (1 << i))
					sum += sp[i].w;
			v.push_back(sum);
		}
	}
	sort(v.begin(), v.end());
	cout << v[t - 1] << endl;
	return 0;
}

#include <iostream>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <cstdio>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <sstream>
using namespace std;

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

#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define sz(s) (int)(s).size()
#define pb push_back
#define mp make_pair
#define sqr(x) (x)*(x)
typedef unsigned long long Int;
const int inf=1000000000;
const int MOD=1000000007;

vector< pair<int,int> >g[22];
int q[5000000],qq,n;

void go(int id,int mask,int sum)
{
	if(id==n+1)
	{
		q[++qq]=sum;
		return ;
	}
	FOR(i,0,sz(g[id])-1)
	{
		int to=g[id][i].first;
		if(mask&(1<<(to-1)))
		{
		}else
		{
			go(id+1,mask|(1<<(to-1)),sum+g[id][i].second);
		}
	}
	go(id+1,mask,sum);
}

int main()
{
	//freopen("input.txt","r",stdin);
	int k,t;
	cin>>n>>k>>t;
	FOR(i,1,k)
	{
		int x,y,z;
		cin>>x>>y>>z;
		g[x].pb(mp(y,z));
	}

	qq=0;
	go(1,0,0);

	sort(q+1,q+qq+1);
	cout<<q[t]<<endl;
}

#include<iostream>
#include<cstdio>
#include <string>
#include<set>
#include<algorithm>
#include<vector>
#include<map>
#include<time.h>
using namespace std;

int a[1000000], ind = 0;
int h[25], w[25], r[25], h1[25], w1[25], r1[25], st[25];
bool u1[5], u2[5];
bool good[33554432];

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

    int n, k, t;
    cin >> n >> k >> t;
    for (int i = 0; i < k; i++)
    {
        cin >> h1[i] >> w1[i] >> r1[i];
        h1[i] --;
        w1[i] --;
        st[i] = i;
    }
    random_shuffle(st, st + k);
    for (int i = 0; i < k; i++)
    {
        h[i] = h1[st[i]];
        w[i] = w1[st[i]];
        r[i] = r1[st[i]];
    }

    good[0] = 1;
    int mask = 1;
    for (int i = 0; i < (1 << k); i++)
    {
        if ((mask << 1) <= i)
            mask = (mask << 1);
        if (i > 0 && !good[i - mask])
            continue;

        for (int j = 0; j < n; j++)
            u1[j] = u2[j] = 0;
        bool OK = 1;

        int x = i, cur = 0;
        for (int j = 0; x > 0; j++)
        {
            if (x & 1)
                if (u1[h[j]] || u2[w[j]])
                {
                    OK = 0;
                    break;
                }
                else
                {
                    u1[h[j]] = u2[w[j]] = 1;
                    cur += r[j];
                }

            x = (x >> 1);
        }

        if (OK)
        {
            a[ind] = cur;
            ind++;
        }
        good[i] = OK;
    }

    sort(a, a + ind);
    cout << a[t - 1];
}

#include <algorithm>
#include <iostream>
#include <valarray>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <numeric>
#include <complex>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>

using namespace std;

#define FOREACH(i, c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define FOR(i, a, n) for (int i = (a); i < int(n); ++i)
#define error(x) cout << #x << " = " << (x) << endl;
#define all(n) (n).begin(), (n).end()
#define Size(n) ((int)(n).size())
#define mk make_pair
#define pb push_back
#define F first
#define S second
#define X real()
#define Y imag()

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef complex<double> point;

template <class P, class Q> void smin(P &a, Q b) { if (b < a) a = b; }
template <class P, class Q> void smax(P &a, Q b) { if (b > a) a = b; }
template <class T> bool by_second(T a, T b) { return a.S < b.S; }

const int MAXN = 120, LIM = 201*1000;

int n, k, a[MAXN], b[MAXN], w[MAXN], tot = 0, threshold, cnt = 0, um, uw;

void bt(int pos) {
	if (pos == k) {
		cnt++;
		return;
	}
	if (!(um&(1<<a[pos])) && !(uw&(1<<b[pos])) && tot+w[pos] <= threshold) {
		um ^= 1<<a[pos]; uw ^= 1<<b[pos]; tot += w[pos];
		bt(pos+1);
		um ^= 1<<a[pos]; uw ^= 1<<b[pos]; tot -= w[pos];
	}
	bt(pos+1);
}

int calc(int _t) {
	threshold = _t;
	um = uw = 0;
	cnt = tot = 0;
	bt(0);
	return cnt;
}

int main() {
	ios::sync_with_stdio(false);
	int t;
	cin >> n >> k >> t;
	FOR(i, 0, k) cin >> a[i] >> b[i] >> w[i];
	int mn = 0, mx = n*1000;
	while (mn < mx) {
		int mid = (mn+mx)/2;
		if (calc(mid) < t)
			mn = mid+1;
		else
			mx = mid;
	}
	cout << mn << endl;
	return 0;
}

#include <queue>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

bool test(int i, int j) {
    return ((i >> j) & 1) != 0;
}

int set(int i, int j) {
    return i | (1 << j);
}

int main() {
    int n, m, q;
    int a, b, c, d;
    vector<pair<int, pair<int, int>>> e;

    scanf("%d%d%d", &n, &m, &q);
    for (int i = 0; i < m; ++i) {
        scanf("%d%d%d", &a, &b, &c);
        e.push_back({c, {a - 1, b - 1}});
    }
    sort(e.rbegin(), e.rend());

    priority_queue<pair<pair<int, int>, pair<int, int>>> pq;
    pq.push({{0, e.size()}, {0, 0}});
    while (q > 0) {
        d = pq.top().first.first;
        c = pq.top().first.second;
        b = pq.top().second.first;
        a = pq.top().second.second;
        pq.pop();
        if (--q == 0) {
            printf("%d\n", -d);
            break;
        }
        for (int i = c - 1; i >= 0; --i) {
            if (!test(b, e[i].second.first) && !test(a, e[i].second.second)) {
                pq.push({{d - e[i].first, i},
                    {set(b, e[i].second.first), set(a, e[i].second.second)}});
            }
        }
    }

    return 0;
}

#include <algorithm>
#include <iostream>
#include <valarray>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <numeric>
#include <complex>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>

using namespace std;

#define FOREACH(i, c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define FOR(i, a, n) for (int i = (a); i < int(n); ++i)
#define error(x) cout << #x << " = " << (x) << endl;
#define all(n) (n).begin(), (n).end()
#define Size(n) ((int)(n).size())
#define mk make_pair
#define pb push_back
#define F first
#define S second
#define X real()
#define Y imag()

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef complex<double> point;

template <class P, class Q> void smin(P &a, Q b) { if (b < a) a = b; }
template <class P, class Q> void smax(P &a, Q b) { if (b > a) a = b; }
template <class T> bool by_second(T a, T b) { return a.S < b.S; }

const int MAXN = 21, LIM = 201*1000;

int n, k, w[MAXN], tot = 0, threshold, cnt = 0, used[MAXN];
vector<pii> adj[MAXN];

void bt(int i) {
	if (i == n) {
		cnt++;
		return;
	}
	FOR(j, 0, Size(adj[i])) if (!used[adj[i][j].F]){
		used[adj[i][j].F] = true; tot += adj[i][j].S;
		if (tot <= threshold) bt(i+1);
		used[adj[i][j].F] = false; tot -= adj[i][j].S;
	}
	bt(i+1);
}

int calc(int _t) {
	threshold = _t;
	memset(used, 0, sizeof used);
	cnt = tot = 0;
	bt(0);
	return cnt;
}

int main() {
	ios::sync_with_stdio(false);
	int t;
	cin >> n >> k >> t;
	FOR(i, 0, k) {
		int x, y, z;
		cin >> x >> y >> z;
		x--; y--;
		adj[x].pb(pii(y, z));
	}
	int mn = 0, mx = n*1000;
	while (mn < mx) {
		int mid = (mn+mx)/2;
		if (calc(mid) < t)
			mn = mid+1;
		else
			mx = mid;
	}
	cout << mn << endl;
	return 0;
}

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

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define PI 3.14159265358979
#define forn(i, n) for(int i = 0; i < n; ++i)
#define ALL(x) x.begin(), x.end()
#define L(s) (int)((s).size())
#define ms(x) memset(x,0,sizeof(x))
#define del(y,x) erase(y.begin()+x)

typedef long long ll;
using namespace std;
typedef pair<int,int> pii;
const int INF = 2147483647;
const ll LLINF = 9223372036854775807LL;
const int ST = 100010;
const int ST1 = 1000010;
const ll MOD = 1000000007;

ll ABS(ll a)
{
	if(a<0)
		return a*(-1);
	else
		return a;
}

vector<ll> pr;
vector<ll> cost;
bool used[22];
bool used2[22];
vector<vector<pii> > vv(22);
ll ans = 0;
int n;

void dfs(int v,int p,ll sum)
{
	used[v] = true;
	used2[p] = true;
	for(int i = v+1;i < n;i++)
	{
		if(!used[i])
		{
			for(int j = 0;j < L(vv[i]);j++)
				if(!used2[vv[i][j].X])
					dfs(i,vv[i][j].X,sum+vv[i][j].Y);
		}
	}
	used[v] = false;
	used2[p] = false;
	pr.pb(sum);
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
	int k,t;
	cin >> n >> k >> t;
	pr.pb(0);
	t--;
	for(int i = 0;i < k;i++)
	{
		int a,b,c;
		cin >> a >> b >> c;
		a--;b--;
		vv[a].pb(mp(b,c));
	}
	for(int i = 0;i < n;i++)
	{
		for(int j = 0;j < L(vv[i]);j++)
		{
			used[i] = true;
			used2[vv[i][j].X] = true;
			dfs(i,vv[i][j].X,vv[i][j].Y);
			used[i] = false;
			used2[vv[i][j].X] = false;
			//pr.pb(vv[i][j].Y);
		}
	}
	sort(ALL(pr));
	//vector<int>::iterator it = unique (pr.begin(), pr.end());
	//pr.resize( it - pr.begin() );
	cout << pr[t];
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <iomanip>
#include <cmath>
#include <sstream>
//#include <windows.h>

using namespace std;

/*void timer (string s)
{
	SYSTEMTIME time;
	GetSystemTime(&time);
	WORD millis = (time.wSecond * 1000) + time.wMilliseconds;
	cerr << s << ' ' << millis << endl;
}*/

#define pie pair <int, int>
#define ff first
#define ss second

const int maxN = 20 + 10;

int n, k, t;
int a[maxN][maxN];

vector <vector <int> > v;
vector <int> s;
void fill (int l) {
	if (l == n) {
		v.push_back (s);
		return;
	}
	for (int i = 0; i <= n; i++)
		s.push_back (i),
		fill (l + 1),
		s.pop_back ();
}

int f[maxN];

int main()
{
	ios::sync_with_stdio (false);

	cin >> n >> k >> t;
	memset (a, -1, sizeof a);
	for (int i = 0; i < k; i++) {
		int x, y, r; cin >> x >> y >> r; x--; y--;
		a[x][y] = r;
	}

	fill (0);

	vector <int> res;
	for (int i = 0; i < v.size(); i++) {
		vector <int> &vv = v[i];
		memset (f, 0, sizeof f);
		int valid = 1, ans = 0;
		for (int j = 0; j < n; j++) {
			f[vv[j]]++;
			if (vv[j])
				if (a[j][vv[j] - 1] == -1)
					valid = 0;
				else
					ans += a[j][vv[j] - 1];
		}
		for (int j = 1; j <= n; j++)
			if (f[j] > 1) valid = 0;
		if (valid)
			res.push_back (ans);
	}

	sort (res.begin(), res.end());
	cout << res[t - 1] << endl;

	return 0;
}

#include <cstdio>
#include <iostream>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stack>

using namespace std;

#define forn(i, n) for(int i = 0; i < int(n); i++)
#define forv(i, v) for(int i = 0; i < int(v.size()); i++)

#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()

typedef long long ll;
typedef long double ld;

inline int ni() { int a; scanf("%d", &a); return a; }

const int border = 100010;

pair < int, pair < int, int > > wds[100];
priority_queue < int > q;
bool mu[20], wu[20];
vector < int > reses;

void rec(int step, int limit, int price) {
    if(int(q.size()) >= border) {
        int max_value = q.top();
        if(max_value <= price) return;
    }
    if(step == limit) {
        q.push(price);
        while(q.size() > border) q.pop();
        return;
    }

    rec(limit, limit, price);

    for(int i = step; i < limit; i++) {
        int m = wds[i].second.first, w = wds[i].second.second;
        int np = wds[i].first;

        if(!mu[m] && !wu[w]) {
            mu[m] = wu[w] = true;
            rec(i + 1, limit, price + np);
            mu[m] = wu[w] = false;
        }
    }
}

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

    int n = ni(), k = ni(), t = ni();

    forn(i, k) {
        wds[i].second.first = ni() - 1, wds[i].second.second = ni() - 1;
        wds[i].first = ni();
    }

    sort(wds, wds + k);

    rec(0, k, 0);

    while(q.size() > 0) {
        reses.pb(q.top());
        q.pop();
    }

    sort(all(reses));

    cout << reses[t - 1] << endl;

    return 0;
}

#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cmath>
#include <cctype>

#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <list>
#include <iterator>
#include <functional>

using namespace std;

typedef long long int64;
typedef unsigned long long uint64;

int64 labs(int64 a)
{
		return a<0 ? (-a) : a;
}
int64 max(int64 a, int64 b)
{
		return a>b?a:b;
}
int64 min(int64 a, int64 b)
{
		return a<b?a:b;
}

#define mp make_pair
#define pb push_back
#define sqr(x) ((x)*(x))
#define forn(i, n) for(int (i)=0; (i)<(n); (i)++)
#define forr(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define forit(i,c) for((i)=(c).begin(); (i)!=(c).end(); (i)++)
#define all(x) (x).begin(), (x).end()
#define zero(a) memset((a), 0, sizeof(a))
#define sqr(x) ((x)*(x))

typedef vector<int> vint;
typedef vector<bool> vbool;
typedef vector<int64> vint64;
typedef pair<int, int> pii;
typedef pair<int64, int64> pii64;

const int MAXN = 6;
const int MAXK = 26;
const int MAXRES = 5 * 1001;

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

Var v[MAXK];
int res[MAXRES];

int n, k, t;

bool was1[MAXN];
bool was2[MAXN];
void Solve(int mask)
{
	zero(was1);
	zero(was2);

	int sum = 0;
	forn(i, k)
	{
		if (mask & 1)
		{
			if (was1[v[i].a] || was2[v[i].b])
			{
				return;
			}
			was1[v[i].a] = 1;
			was2[v[i].b] = 1;
			sum += v[i].c;
		}
		mask >>= 1;
	}
	res[sum]++;
}

int main()
{
	//freopen("input.txt", "r", stdin);
	cin >> n >> k >> t;
	if (t == 1)
	{
		cout << 0 << endl;
		return 0;
	}

	zero(res);
	forn(i, k)
	{
		cin >> v[i].a >> v[i].b >> v[i].c;
		v[i].a--;
		v[i].b--;
	}
	for(int mask = 0; mask < (1 << k); mask ++)
	{
		Solve(mask);
	}

	int cur = 0;
	forn(i, MAXRES)
	{
		cur += res[i];
		if (cur >= t)
		{
			cout << i << endl;
			return 0;
		}
	}

	return 0;
}
/*
5 25 2
1 1 1
1 2 1
1 3 1
1 4 1
1 5 1
2 1 1
2 2 1
2 3 1
2 4 1
2 5 1
3 1 1
3 2 1
3 3 1
3 4 1
3 5 1
4 1 1
4 2 1
4 3 1
4 4 1
4 5 1
5 1 1
5 2 1
5 3 1
5 4 1
5 5 1

1 1000000001
1 1000000000

3
2
1 2
2 3
1
1 3
*/

#ifndef SOURCE_IS_SPLICED
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
void run();int main(){
  #ifdef twentyone
  freopen("F.in","r",stdin);
  #endif
  ios::sync_with_stdio(false);run();}
#endif

ll a[25],b[25],c[25];
bool used[100];

ll n,k,t;
map<ll,ll> ways;
ll tot;

void dfs(ll p,ll score=0){
  if (p==0){
    ++ways[score];
    ++tot;
    return;
  }
  p--;

  if (not used[a[p]] and not used[n+b[p]]){
    used[a[p]]=used[n+b[p]]=true;
    dfs(p,score+c[p]);
    used[a[p]]=used[n+b[p]]=false;
  }
  dfs(p,score);
}

void run(){
  cin>>n>>k>>t;

  for (int i=k; i--;) cin>>a[i]>>b[i]>>c[i], --a[i],--b[i];
  dfs(k);
  for (auto it: ways){
    t-=it.second;
    if (t<=0) {cout<<it.first<<endl;return;}
  }
}

#include <iostream>
#include <algorithm>
#include <queue>

using namespace std;

int n,t,k;
int cost[22][22];
bool used[22];
int numFind;
int anss[200005];
priority_queue <int> pq;

void back(int num,int get){
	if(num==n){
		//anss[numFind++]=get;
		if(numFind >= t){
			if(!pq.empty() && get < pq.top()){
				pq.pop();
				pq.push(get);
			}
		}
		else{
			pq.push(get);
			numFind++;
		}
		return;
	}
	back(num+1,get);
	for(int i=0;i<n;i++){
		if(!used[i] && cost[num][i]){
			if(numFind<t || get+cost[num][i] < pq.top() ){
				used[i]=true;
				back(num+1,get+cost[num][i]);
				used[i]=false;
			}
		}
	}
}

int main(){

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

	cin>>n>>k>>t;

	int tmp1,tmp2;
	for(int i=0;i<k;i++){
		cin>>tmp1>>tmp2;
		cin>>cost[tmp1-1][tmp2-1];
	}

	back(0,0);

	//sort(anss,anss+numFind);
	int i;
	for(i=0;i<numFind;i++){
		anss[i]=pq.top();
		pq.pop();
	}
	cout<<anss[t-i]<<endl;

	//cout<<anss[t-1]<<endl;

	return 0;
}

#include<stdio.h>
#define N 25
using namespace std;
int vis[N],a[N][N];
int n,m,k,x,y,z,i,l,r,mid;
int DFS(int x,int now){
	if (now>mid) return 0;
	if (x>n) return 1;
	int ret=DFS(x+1,now);
	for (int i=1;i<=n&&ret<k;i++)
		if (!vis[i]&&a[x][i])
			vis[i]=1,ret+=DFS(x+1,now+a[x][i]),vis[i]=0;
	if (ret>=k) ret=k;
	return ret;
}
int main(){
	scanf("%d%d%d",&n,&m,&k);
	for (i=1;i<=m;i++)
		scanf("%d%d%d",&x,&y,&z),a[x][y]=z;
	l=0;r=1000*n;
	while (l<r){
		mid=(l+r)>>1;
		if (DFS(1,0)>=k) r=mid;else l=mid+1;
  }printf("%d\n",l);
}

#include <bits/stdc++.h>
#define L first
#define R second
#define MP make_pair
#define PB push_back

using namespace std;

int n, m, k;
vector<pair<pair<int, int>, int> > E;
int d[2][20], res;

inline bool chk(int &mask) {
	res = 0;
	memset(d, 0, sizeof d);
	for(int i = 0;i < E.size();i ++)
		if(mask & (1<<i)) {
			res += E[i].R,
			d[0][E[i].L.L] ++, d[1][E[i].L.R] ++;
			if(d[0][E[i].L.L] > 1 || d[1][E[i].L.R] > 1) return false;
		}
	return true;
}

main() {
	cin >> n >> m >> k;
	int fi, se, w;
	for(int i = 0;i < m;i ++)
		cin >> fi >> se >> w, E.PB(MP(MP(fi, se), w));
	vector<int> Q(0);
	for(int mask = 0;mask < (1<<E.size());mask ++)
		if(chk(mask))
			Q.PB(res);
	sort(Q.begin(), Q.end());
	cout << Q[k - 1] << endl;
	return 0;
}

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

int a[30],b[30],c[30];
int cntx[6],cnty[6];
int use[30],N,K,T;
vector<int> ans;

void dfs(int k,int n)
{
    if(n>N) return;
    if(k>=K)
    {
        int tmp=0;
        memset(cnty,0,sizeof(cnty));
        memset(cntx,0,sizeof(cntx));
        for(int i=1;i<=K;i++) if(use[i])
        {
            cntx[a[i]]++;
            cnty[b[i]]++;
            tmp+=c[i];
        }
        bool flag=true;
        for(int i=1;i<=N;i++)
            if(cntx[i]>1||cnty[i]>1) flag=false;
        if(flag&&tmp) ans.push_back(tmp);
        return;
    }
    use[k+1]=1;
    dfs(k+1,n+1);
    use[k+1]=0;
    dfs(k+1,n);
}
int main()
{
    cin>>N>>K>>T;
    for(int i=1;i<=K;i++) scanf("%d%d%d",a+i,b+i,c+i);
    dfs(0,0);
    ans.push_back(0);
    sort(ans.begin(),ans.end());
    cout<<ans[T-1]<<endl;
    /*
    cout<<ans.size()<<endl;
    for(int i=0;i<ans.size();i++) cout<<ans[i]<<endl;
    */
    return 0;
}

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
#define REP(i,m) for(int i=0;i<m;++i)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
using namespace std;
static const int INF =500000000;
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
typedef long long int lint;
typedef pair<int,int> pi;
int n,k,t;
vector<pi> g[25];
int used[25];
int lim,cnt;
bool dfs(int v,int sum){
	++cnt;
	if(cnt==t) return true;
	if(v==n) return false;
	REP(i,g[v].size()){
		pi& e=g[v][i];
		if(used[e.fr] || sum+e.sc>=lim) continue;
		used[e.fr]=1;
		if(dfs(v+1,sum+e.sc)) return true;
		used[e.fr]=0;
	}
	--cnt;
	if(dfs(v+1,sum)) return true;
	return false;
}

int main(){
	scanf("%d%d%d",&n,&k,&t);
	REP(i,k){
		int a,b,r;scanf("%d%d%d",&a,&b,&r);--a;--b;
		g[a].pb(mp(b,r));
	}
	int lb=0,ub=1000*20+5;
	while(ub-lb>1){
		int md=(ub+lb)>>1;
		lim=md;cnt=0;
		memset(used,0,sizeof(used));
		if(dfs(0,0)) ub=md;
		else lb=md;
	}
	printf("%d\n",lb);
	return 0;
}

#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;

#define PB push_back
#define MP make_pair

#define rep(i,n) for(int i=0;i<(n);++i)
#define REP(i,n) for(int i=1;i<=(n);++i)
#define FOR(i,l,h) for(int i=(l);i<=(h);++i)
#define FORD(i,h,l) for(int i=(h);i>=(l);--i)
#define print(expr) cout<<(#expr)<<" : "<<(expr)<<endl
#define tr(it,c) for(auto it=(c).begin(); it!=(c).end(); ++it)
#define all(c) (c).begin(), (c).end()

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef long long int64;
typedef pair<int,int> pii;

int dis[10][10]={};
int n,k,t;

int main(void)
{
	memset(dis,-1,sizeof dis);
	ios::sync_with_stdio(false);
	cin>>n>>k>>t;
	rep(i,k)
	{
		int a,b,c; cin>>a>>b>>c; --a;--b;
		dis[a][b]=c;
	}
	VI ans;
	rep(mask1,1<<n) rep(mask2,1<<n)
	{
		bitset<5> b1(mask1), b2(mask2);
		if(b1.count()!=b2.count()) continue;
		int l=b1.count();
		VI a1,a2;
		rep(i,n) if(b1[i]) a1.PB(i);
		rep(i,n) if(b2[i]) a2.PB(i);
		VI p(l);
		rep(i,l) p[i]=i;
		do{
			int res=0;
			bool tag=false;
			rep(i,l)
			{
				if(dis[a1[i]][a2[p[i]]]==-1) { tag=true; break;}
				res+=dis[a1[i]][a2[p[i]]];
			}
			if(!tag) ans.PB(res);
		}while(next_permutation(all(p)));
	}
	sort(all(ans));
	cout<<ans[t-1]<<endl;
	return 0;
}

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<set>
#include<vector>
#define REP(i,m) for(int i=0;i<m;++i)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
using namespace std;
static const int INF =500000000;
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
typedef long long int lint;
typedef pair<int,int> pi;
int g[10][10];
int all[1000000];
int cnt;
set<vector<int> >done;
int main(){
	int n,k,t;scanf("%d%d%d",&n,&k,&t);
	REP(i,k){
		int a,b,c;scanf("%d%d%d",&a,&b,&c);--a;--b;
		g[a][b]=c;
	}
	int per[10];
	REP(i,n) per[i]=i;
	do{
		REP(i,1<<n){
			vector<int> state(n);
			int score=0,fail=0;
			REP(j,n){
				if(i>>j&1){
					state[j]=per[j];
					if(g[j][per[j]]==0) fail=1;
					else score+=g[j][per[j]];
				}else state[j]=-1;
			}
			if(fail) continue;
			if(done.count(state)==0) all[cnt++]=score,done.insert(state);
		}
	}while(next_permutation(per,per+n));

	sort(all,all+cnt);
	printf("%d\n",all[t-1]);
	return 0;
}

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <math.h>
using namespace std;
typedef unsigned short us;
typedef unsigned int ui;
typedef long long i64;
typedef unsigned long long ui64;
long n,k,t,h,w,r;
us be[30];us bew[30]={0};
ui64 z=0;vector<ui64> b;
vector<pair<long,long>> a[1000];
void rec(long z,int m){
	if(m==n+1){b.push_back(z);return;}
	for(int i=0;i<a[m].size();i++)
		if(!bew[a[m][i].first])
	{
		bew[a[m][i].first]=1;
		rec(z+a[m][i].second,m+1);
		bew[a[m][i].first]=0;}
	rec(z,m+1);
}
class marry{
public:
	int m;int w;int r;
	marry(int m1,int w1,int r1){m=m1;w=w1;r=r1;}
	bool operator<(const marry* mm){return r<mm->r;}
};
bool cmp(marry* m1,marry* m2){return m1->r<m2->r;}

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

	cin>>n>>k>>t;long long g=(long long)pow((double)2,(double)k);
	for(int i=1;i<=k;i++){cin>>h>>w>>r;a[h].push_back(make_pair(w,r));}
	//sort(a.begin(),a.end(),&cmp);
	rec(0,1);
	sort(b.begin(),b.end());
	cout<<b[t-1];
	return 0;
}

#include <set>
#include <map>
#include <ctime>
#include <cmath>
#include <queue>
#include <string>
#include <vector>
#include <fstream>
#include <cstring>
#include <iostream>
#include <iterator>
#include <algorithm>
//#include <unordered_set>

/*#include <Windows.h>
#include <Psapi.h>*/

//#include "../../../../../Desktop/Treap.h"

using namespace std;

typedef long long ll;

const double eps = 1E-9;

int main(int argc, char **argv) {

    ios::sync_with_stdio(false);

    //freopen("in.txt", "r", stdin);

    int n, k, t;
    cin >> n >> k >> t;

    vector<vector<pair<int, int>>> v(n);
    for(int i = 0; i < k; ++i) {
        int u, r, w;
        cin >> u >> r >> w;
        v[u - 1].push_back(make_pair(r - 1, w));
    }

    int ccolor = 10000;
    vector<int> used(n);
    vector<ll> ans(1, 0);

    //1
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < v[i].size(); ++j)
            ans.push_back(v[i][j].second);
    }

    //2
    for(int i = 0; i < n - 1; ++i) {
        for(int y = 0; y < v[i].size(); ++y) {
            used[v[i][y].first] = ccolor;
            for(int j = i + 1; j < n; ++j) {
                for(int x = 0; x < v[j].size(); ++x)
                    if(used[v[j][x].first] != ccolor)
                        ans.push_back(v[i][y].second + v[j][x].second);
            }
            ++ccolor;
        }
    }

    //3
    int ccolor2 = -1000;
    for(int i = 0; i < n - 2; ++i) {
        for(int x = 0; x < v[i].size(); ++x) {
            used[v[i][x].first] = ccolor;
            for(int j = i + 1; j < n - 1; ++j) {
                for(int y = 0; y < v[j].size(); ++y) {
                    if(used[v[j][y].first] != ccolor) {
                        used[v[j][y].first] = ccolor2;
                        for(int l = j + 1; l < n; ++l) {
                            for(int z = 0; z < v[l].size(); ++z) {
                                if(used[v[l][z].first] != ccolor && used[v[l][z].first] != ccolor2)
                                    ans.push_back(v[i][x].second + v[j][y].second + v[l][z].second);
                            }
                        }
                        ++ccolor2;
                    }
                }
            }
            ++ccolor;
        }
    }

    //4
    int ccolor3 = -10000;
    for(int i = 0; i < n - 3; ++i) {
        for(int x = 0; x < v[i].size(); ++x) {
            used[v[i][x].first] = ccolor;
            for(int j = i + 1; j < n - 2; ++j) {
                for(int y = 0; y < v[j].size(); ++y) {
                    if(used[v[j][y].first] != ccolor) {
                        used[v[j][y].first] = ccolor2;
                        for(int l = j + 1; l < n - 1; ++l) {
                            for(int z = 0; z < v[l].size(); ++z) {
                                if(used[v[l][z].first] != ccolor && used[v[l][z].first] != ccolor2) {
                                    used[v[l][z].first] = ccolor3;
                                    for(int q = l + 1; q < n; ++q) {
                                        for(int w = 0; w < v[q].size(); ++w) {
                                            if(used[v[q][w].first] != ccolor && used[v[q][w].first] != ccolor2 && used[v[q][w].first] != ccolor3)
                                                ans.push_back(v[i][x].second + v[j][y].second + v[l][z].second + v[q][w].second);
                                        }
                                    }
                                    ++ccolor3;
                                }
                            }
                        }
                        ++ccolor2;
                    }
                }
            }
            ++ccolor;
        }
    }

    //5
    int ccolor4 = -100000;
    for(int i = 0; i < n - 4; ++i) {
        for(int x = 0; x < v[i].size(); ++x) {
            used[v[i][x].first] = ccolor;
            for(int j = i + 1; j < n - 3; ++j) {
                for(int y = 0; y < v[j].size(); ++y) {
                    if(used[v[j][y].first] != ccolor) {
                        used[v[j][y].first] = ccolor2;
                        for(int l = j + 1; l < n - 2; ++l) {
                            for(int z = 0; z < v[l].size(); ++z) {
                                if(used[v[l][z].first] != ccolor && used[v[l][z].first] != ccolor2) {
                                    used[v[l][z].first] = ccolor3;
                                    for(int q = l + 1; q < n - 1; ++q) {
                                        for(int w = 0; w < v[q].size(); ++w) {
                                            if(used[v[q][w].first] != ccolor && used[v[q][w].first] != ccolor2 && used[v[q][w].first] != ccolor3) {
                                                used[v[q][w].first] = ccolor4;
                                                for(int p = q + 1; p < n; ++p) {
                                                    for(int g = 0; g < v[p].size(); ++g) {
                                                        if(used[v[p][g].first] != ccolor && used[v[p][g].first] != ccolor2 && used[v[p][g].first] != ccolor3 && used[v[p][g].first] != ccolor4)
                                                            ans.push_back(v[i][x].second + v[j][y].second + v[l][z].second + v[q][w].second + v[p][g].second);
                                                    }
                                                }
                                                ++ccolor4;
                                            }
                                        }
                                    }
                                    ++ccolor3;
                                }
                            }
                        }
                        ++ccolor2;
                    }
                }
            }
            ++ccolor;
        }
    }
    sort(ans.begin(), ans.end());
    cout << (t > ans.size() ? -1 : ans[t - 1]) << endl;
//  copy(ans.begin(), ans.end(), ostream_iterator<ll>(cout, " "));
    //cout << endl;
    return 0;
}

#include <cstdio>
#include <iostream>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stack>

using namespace std;

#define forn(i, n) for(int i = 0; i < int(n); i++)
#define forv(i, v) for(int i = 0; i < int(v.size()); i++)

#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()

typedef long long ll;
typedef long double ld;

inline int ni() { int a; scanf("%d", &a); return a; }

const int border = 200010;

pair < int, pair < int, int > > wds[100];
priority_queue < int > q;
bool mu[20], wu[20];
vector < int > reses;

void rec(int step, int limit, int price) {
    if(int(q.size()) >= border) {
        int max_value = q.top();
        if(max_value <= price) return;
    }
    if(step == limit) {
        q.push(price);
        while(q.size() > border) q.pop();
        return;
    }

    rec(limit, limit, price);

    for(int i = step; i < limit; i++) {
        int m = wds[i].second.first, w = wds[i].second.second;
        int np = wds[i].first;

        if(!mu[m] && !wu[w]) {
            mu[m] = wu[w] = true;
            rec(i + 1, limit, price + np);
            mu[m] = wu[w] = false;
        }
    }
}

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

    int n = ni(), k = ni(), t = ni();

    forn(i, k) {
        wds[i].second.first = ni() - 1, wds[i].second.second = ni() - 1;
        wds[i].first = ni();
    }

    sort(wds, wds + k);

    rec(0, k, 0);

    while(q.size() > 0) {
        reses.pb(q.top());
        q.pop();
    }

    sort(all(reses));

    cout << reses[t - 1] << endl;

    return 0;
}

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
int n,m,K,mat[21][21];
typedef pair<int,int> state;
int main(){
    cin>>n>>m>>K;
    for(int i=1;i<=m;i++){
        int h,w,r;
        cin>>h>>w>>r;
        mat[h][w]=r;
    }
    priority_queue<state,vector<state> > Q,TQ;
    Q.push(state(0,0));
    for(int i=1;i<=n;i++){
        TQ=Q;
        while(!Q.empty()){
            state t=Q.top();
            for(int j=0;j<n;j++)
                if(mat[i][j+1]&&!(t.second&(1<<j))&&(TQ.size()<K||TQ.top().first>t.first+mat[i][j+1]))
                    TQ.push(state(t.first+mat[i][j+1],t.second|(1<<j)));
            Q.pop();
        }
        while(TQ.size()>K) TQ.pop();
        Q=TQ;
    }
    cout<<Q.top().first<<endl;
}

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
int n,m,K,mat[21][21];
typedef pair<int,int> state;
int main(){
//
    cin>>n>>m>>K;
    for(int i=1;i<=m;i++){
        int h,w,r;
        cin>>h>>w>>r;
        mat[h][w]=r;
    }
    priority_queue<state,vector<state> > Q,TQ;
    Q.push(state(0,0));
    for(int i=1;i<=n;i++){
        TQ=Q;
        while(!Q.empty()){
            state t=Q.top();
            for(int j=0;j<n;j++)
                if(mat[i][j+1]&&!(t.second&(1<<j))&&(TQ.size()<K||TQ.top().first>t.first+mat[i][j+1]))
                    TQ.push(state(t.first+mat[i][j+1],t.second|(1<<j)));
            Q.pop();
        }
        while(TQ.size()>K) TQ.pop();
        Q=TQ;
    }
    cout<<Q.top().first<<endl;
}

//#define PROB "test"           /* Comment to use standard I/O everywhere    */
//#define STDIO               /* Uncomment to use standard I/O on local PC */

//{{{ Preamble
#if !defined(LOCAL_PC) && !defined(NDEBUG)
#define NDEBUG
#endif
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;typedef long long ll;typedef unsigned long long ull;static
struct _{ios_base::Init i;_(){cin.sync_with_stdio(false);cin.tie(NULL);}}_;
const double pi=3.14159265358979323846;const double E=2.7182818284590452354;
#if defined(PROB) && (!defined(LOCAL_PC) || !defined(STDIO))
static struct __{__(){cin.rdbuf(a.open(PROB".in",ios::in));cout.rdbuf(b.open(
PROB".out",ios::out));}~__(){cin.rdbuf(NULL);cout.rdbuf(NULL);}filebuf a,b;}__;
#endif
#define _O    static inline ostream&operator<<(ostream&o,
#define _W(f) o<<"[ ";while(!s.empty()){o<<s.f()<<" ";s.pop();}return o<<"]";
template<class T>struct _f{typedef typename T::iterator t;};template<class T>
struct _f<const T>{typedef typename T::const_iterator t;};template<class T>_O
stack<T>s){_W(top)}template<class T>_O queue<T>s){_W(front)}namespace std{
template<class A,class B>_O const pair<A,B>&p){return o<<p.first<<"="<<p.second
;}}template<class T>static inline ostream&_o(ostream&o,const T&c){o<<"[ ";copy(
c.begin(),c.end(),ostream_iterator<typename T::value_type>(o," "));return o<<
"]";}template<class T,class A,template<class T,class A>class C>_O const C<T,A>&
c){return _o(o,c);}template<class T>_O const set<T>&s){return _o(o,s);}template
<class K,class V>_O const map<K,V>&m){return _o(o,m);}template<class T,size_t M
,size_t N>_O const T(&a)[M][N]){for(size_t j=0;j<M;j++){o<<"\n"<<string(14,' ')
<<"\t";for(size_t i=0;i<N;i++)o<<a[j][i]<<" ";}return o;}static inline ostream&
endl(ostream&os){return os<<"\n";}
#if defined(_MSC_VER) && _MSC_VER >= 1600
#  define __typeof__ decltype
#endif
#define FOREACH(i,c) for(_f<__typeof__(c)>::t i=c.begin();i!=c.end();++i)
#define pb           push_back
#define mp           make_pair
#ifdef LOCAL_PC
#define BLOG cerr<<std::right<<setw(9)<<__FUNCTION__<<" "<<setw(3)<<__LINE__<<":"
#define DOLOG(x) <<std::left<<"\t"<<#x<<" = "<<(x)
#define ELOG     <<std::endl
#else
#define BLOG     0
#define DOLOG(x)
#define ELOG
#endif
#define LOG(x)      static_cast<void>(BLOG DOLOG(x) ELOG)
#define LOG2(x,y)   static_cast<void>(BLOG DOLOG(x) DOLOG(y) ELOG)
#define LOG3(x,y,z) static_cast<void>(BLOG DOLOG(x) DOLOG(y) DOLOG(z) ELOG)
//}}}

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

	static int gain[6][6];
	for (int i = 0; i < k; i++)
	{
		int h, w, r;
		cin >> h >> w >> r;
		gain[h-1][w-1] = r;
	}

	vector<int> res;
	bool used_h[6], used_w[6];
	for (int s = 0; s < 1<<(n*n); s++)
	{
		int r = 0;
		memset(used_h, 0, sizeof(used_h));
		memset(used_w, 0, sizeof(used_w));
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < n; j++)
			{
				if (s & 1<<(i*n+j))
				{
					if (used_h[i] || used_w[j] || !gain[i][j])
						goto next;
					else
					{
						used_h[i] = used_w[j] = true;
						r += gain[i][j];
					}
				}
			}
		}
		res.pb(r);
next:	;
	}
	LOG(res);

	sort(res.begin(), res.end());
	cout << res[t-1] << endl;
}

#include<iostream>
#include<queue>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<string>
#include<cstring>
#include<map>
#include<numeric>
#include<sstream>
#include<cmath>
using namespace std;
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).end,(v).begin
#define pb push_back
#define f(i,x,y) for(int i=x;i<y;i++)
#define FOR(it,A) for(typeof A.begin() it = A.begin();it!=A.end();it++)
#define sqr(x) (x)*(x)
#define mp make_pair
#define clr(x,y) memset(x,y,sizeof x)
typedef pair<int,int> pii;
typedef long long ll;
typedef long double ld;
int n,k,t;
vector < pair < pair<int,int> ,int > > v;
vector <ll> res;
void imp(int mask){
   f(i,0,n)if(mask&(1<<i))cout<<"1";
   else cout<<"0";
   cout<<endl;
}
void go(int pos,int mask1,int mask2,int val){
   //cout<<"pos "<<pos<<" "<<val<<endl;
   //imp(mask1);
   //imp(mask2);

   if(pos>=k){
     // cout<<"fin "<<val<<endl;
      res.pb(val);
      return;
   }
   int a,b;
   {
      a=v[pos].first.first;
      b=v[pos].first.second;
      if((mask1&(1<<a)) && (mask2&(1<<b))){
         mask1&=~(1<<a);
         mask2&=~(1<<b);
         go(pos+1,mask1,mask2,val+v[pos].second);
         mask1+=(1<<a);
         mask2+=(1<<b);
      }
   }
   go(pos+1,mask1,mask2,val);
}
int main(){

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

   int a,b;
   ll va;
   f(i,0,k){
      cin>>a>>b>>va;
      a--,b--;
      v.pb(make_pair( mp(a,b),va));

   }
   int mask1,mask2;

   mask1=1<<n;
   mask1--;
   mask2=mask1;
   go(0,mask1,mask2,0);
   sort(all(res));
   t--;
   //f(i,0,res.size())cout<<" "<<res[i];cout<<endl;
   cout<<res[t]<<endl;
   return 0;
}

#include<bits/stdc++.h>
#define LL long long
#define ull unsigned long long
#define ULL ull
#define mp make_pair
#define pii pair<int,int>
#define piii pair<int, pii >
#define pll pair <ll,ll>
#define pb push_back
#define big 20160116
#define INF 2147483647
#define pq priority_queue
#define rank rk124232
#define y1 y20160116
#define y0 y20160110
#define _ 0
using namespace std;
#ifndef MY
	#define putchar IO::_putchar
	#define getchar IO::_getchar
#endif
namespace IO
{
    const int sz=1<<15;
    char inbuf[sz],outbuf[sz];
    char *pinbuf=inbuf+sz;
    char *poutbuf=outbuf;
    inline char _getchar()
    {
        if (pinbuf==inbuf+sz)fread(inbuf,1,sz,stdin),pinbuf=inbuf;
        return *(pinbuf++);
    }
    inline void _putchar(char x)
    {
        if (poutbuf==outbuf+sz)fwrite(outbuf,1,sz,stdout),poutbuf=outbuf;
        *(poutbuf++)=x;
    }
    inline void flush()
    {
        if (poutbuf!=outbuf)fwrite(outbuf,1,poutbuf-outbuf,stdout),poutbuf=outbuf;
    }
}
inline int read()
{
    int x=0,p=1;
	char c=getchar();
    while (c<'0' || c>'9'){
    	if (c=='-') p=-1;
    	c=getchar();
	}
    while (c>='0' && c<='9') x=x*10+c-48,c=getchar();
    return x*p;
}
const int Maxn=22;
const int Maxm=105;
int eu[Maxm],ev[Maxm],ew[Maxm],n,m,t;
int dat[500005][Maxn],W[500005];
LL Ha[500005];
bool usey[500005][Maxn];
vector<int> CanUse;
struct S{
	int I;
	bool operator<(const S &s)const{
		if (W[I]!=W[s.I])return W[I]<W[s.I];
		return I<s.I;
	}
};
multiset<S> id;
unordered_set<LL> Vis;
int main(){
	scanf("%d %d %d",&n,&m,&t);
	for (int i=0;i<m;i++){
		scanf("%d %d %d",&eu[i],&ev[i],&ew[i]);
	}
	for (int i=1;i<500005;i++) CanUse.pb(i);
	S zero;
	zero.I=0;
	id.insert(zero);
	int lim=2e9;
	while (!id.empty()){
		int Id=(*id.begin()).I;
		id.erase(id.begin());
		t--;
		if (t==0){
			printf("%d\n",W[Id]);
			return 0;
		}
		for (int i=0;i<m;i++){
			if (!dat[Id][eu[i]] && !usey[Id][ev[i]]){
				//cerr<<i<<endl;
				int TW=W[Id]+ew[i];
				if (TW>=lim) continue;
				int nid=CanUse.back();CanUse.pop_back();
			//	cout<<"Nid"<<nid<<endl;
				for (int j=1;j<=n;j++) dat[nid][j]=dat[Id][j];
				for (int j=1;j<=n;j++) usey[nid][j]=usey[Id][j];
				usey[nid][ev[i]]=1;
				dat[nid][eu[i]]=ev[i];
				Ha[nid]=0;
				W[nid]=TW;
				for (int j=1;j<=n;j++){
					Ha[nid]=Ha[nid]*394291323+dat[nid][j];
				}
			//	cout<<Ha[nid]<<endl;
				if (Vis.find(Ha[nid])!=Vis.end()){
					CanUse.pb(nid);
					continue;
				}
				Vis.insert(Ha[nid]);
				S tt;
				tt.I=nid;
				//cout<<"Ins"<<' '<<TW<<endl;
				id.insert(tt);
			}
		}
		if (id.size()>t){
			while (id.size()!=t){
				int tmp=(*id.rbegin()).I;
				CanUse.pb(tmp);
				Vis.erase(Ha[tmp]);
				id.erase(*id.rbegin());
			}
			int tmp=(*id.rbegin()).I;
			lim=W[tmp];
		}
	//	CanUse.pb(Id);
	}
	return ~~(0^_^0);
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <cmath>
#include <set>
#include <map>
#include <cstdio>
#include <stdlib.h>
#include <stack>
#include <numeric>
#include <bitset>
#include <cctype>
typedef long long ll;
#define MAX 25
using namespace std;
int n,m;
#define INF 2147483647
#define inf 1<<30
#define MOD 1000000007
#define EPS 1e-20
#define G 9.8
#define PI acos(-1)
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
bool debug = false;
int k;
int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};

int mp[MAX][MAX],t;
priority_queue<int> q;
void dfs(int x, int s, int val) {
    if (q.size()==t && val > q.top()) return;
    if (x == n) {
        q.push(val);
        if (q.size() > t) q.pop();
        return;
    }
    dfs(x+1,s,val);
    REP(i,n) if (((s>>i) & 1)==0) {
        if (mp[x][i]) {
            dfs(x+1, s | (1<<i), val + mp[x][i]);
        }
    }
}
int main(){
    scanf("%d%d%d", &n, &k, &t);
    int h,w,r;
    REP(i,k) {
        scanf("%d%d%d", &h, &w, &r); h--; w--;
        mp[h][w]=r;
    }
    dfs(0, 0, 0);
    printf("%d\n", q.top());
    return 0;
}

//#include"C:\Users\sugon\OneDrive\ACM\模块\模板\acm.h"
//#include"C:\Users\Harborfan\OneDrive\ACM\模块\模板\acm.h"
#include<map>
#include<queue>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define scd(x) scanf("%llf",&x)
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b) - 1; i >= (a); --i)
#define dd(a) cout << #a << " = " << (a) << " "
#define de(a) cout << #a << " = " << (a) << endl
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pw(a) (1ll << (a))
#define endl "\n"
typedef double db;
typedef long long ll;
typedef long long LL;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
const int inf = 0x3f3f3f3f;
const ll linf = 0x3f3f3f3f3f3f3f3f;

const int maxn = 20+10;
int n,k,t;
int cnt,sum,mid;

struct node
{
	int x,y,z;
}a[maxn*maxn];
bool vis[maxn*2];

void dfs(int d)
{
	if(cnt>t) return ;
	if(d>=k)
	{
		cnt++;
//		cout<<cnt<<' '<<sum<<endl;
		return ;
	}

	dfs(d+1);
	if(!vis[a[d].x]&&!vis[a[d].y])
	{
		sum += a[d].z;
		if(sum>mid)
		{
			sum -= a[d].z;
			return ;
		}

		vis[a[d].x] = 1;
		vis[a[d].y] = 1;

		dfs(d+1);

		sum -= a[d].z;
		vis[a[d].x] = 0;
		vis[a[d].y] = 0;
	}

}

int main()
{
	sci(n); sci(k); sci(t);
	memset(vis,0,sizeof vis);
	for(int i = 0;i < k;i++)
	{
		int x,y,z;
		sci(a[i].x);
		sci(a[i].y);
		a[i].y+=maxn;
		sci(a[i].z);
	}

	int l = -1,r = inf;
	mid = 10;
	dfs(0);

	while(l<r-1)
	{
		cnt = sum = 0;
		mid = l+r>>1;
		dfs(0);
//		cout<<mid<<' '<<cnt<<' '<<(cnt>=t)<<endl;
		if(cnt>=t)
		{
			r = mid;
		}
		else// if(cnt==t)
		{
			l = mid;
		}
	}
	printf("%d\n",r);
}

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;
const int inf=0x3fffffff;
const int maxn=25;

int k,n,m;
vector<int>g[maxn],w[maxn];
bool hash[maxn];

priority_queue<int>q;

void dfs(int cur,int sum)
{
    q.push(sum);
    if(q.size()>k)q.pop();
    if(cur>n)return;
    for(int i=cur; i<=n; i++)
        for(int j=0; j<g[i].size(); j++)
        {
            int v=g[i][j];
            if(hash[v])continue;
            hash[v]=1;
            dfs(i+1,sum+w[i][j]);
            hash[v]=0;
        }
}

int main()
{
    scanf("%d%d%d",&n,&m,&k);
    int u,v,ww;
    while(m--)
    {
        scanf("%d%d%d",&u,&v,&ww);
        g[u].push_back(v);
        w[u].push_back(ww);
    }
    dfs(1,0);
    printf("%d\n",q.top());
    return 0;
}

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

using ll = long long;

int n, k, t;
vector<pair<int,ll>> edges;

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> n >> k >> t;
	edges.resize(k);
	for (int i = 0; i < k; i++) {
		int h, w, r;
		cin >> h >> w >> r;
		h--; w--;
		ll mask = ll(1) << h;
		mask |= ll(1) << (n+w);
		edges[i] = {r, mask};
	}
	sort(edges.begin(), edges.end());
	int s = -1, e = n * 1000;
	while (s+1 < e) {
		int mid = (s+e)/2;
		int tot = 1;
		function<void(int,int,ll)> enumerate = [&](int cur, int cur_cost, ll mask) {
			if (cur == k) return;
			if (tot >= t) return;
			int new_cost = cur_cost + edges[cur].first;
			if (new_cost <= mid) {
				if (!(mask & edges[cur].second)) {
					tot += 1;
					enumerate(cur+1, new_cost, mask | edges[cur].second);
				}
				enumerate(cur+1, cur_cost, mask);
			}
		};
		enumerate(0, 0, 0);
		if (tot >= t) {
			e = mid;
		} else {
			s = mid;
		}
	}
	cout << e << '\n';
}

#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
int i,j,k,l,n,m,a[120][120],t,x,y;
priority_queue <int> q;
void dfs(int l,int s,int val){
	if(q.size()==t && val>q.top())return;
	if(l==n+1){
		q.push(val);
		if(q.size()>t)q.pop();
		return;
	}
	dfs(l+1,s,val);
	for(int i=1;i<=n;++i)if(!(s>>i-1&1) && a[l][i])
		dfs(l+1,s|1<<i-1,val+a[l][i]);
}
int main(){
	scanf("%d%d%d",&n,&m,&t);
	for(i=1;i<=m;++i){
		scanf("%d%d%d",&x,&y,&k);
		a[x][y]=k;
	}
	dfs(1,0,0);
	printf("%d\n",q.top());
}

/* 先用二分搜索猜測第 $t$ 個匹配的權重和，
 * 再用遞迴+剪枝枚舉出有多少個匹配權重和必超過該值。
 * 邊(x, y) 代表著一側的第 x 個點和另一側的第 y 個點相連的邊
 */
#include<cstdio>
#include<vector>
struct EDGE{
    int y, v;
    EDGE(int y, int v):y(y),v(v){}
};
const int MAX_N = 20;
int n, k, t; // 題目裡就有的參數
std::vector<EDGE> e[MAX_N + 1];
int choosen[MAX_N + 1];
int mid; // 二分搜索時，猜測的答案
int cnt; // 計數器
void dfs(int x, int now_cost_sum){
	if (now_cost_sum > mid) return;  // 超過猜測答案就剪枝
    if (cnt >= t) return; // 匹配數目已達 t 就剪枝
	if (x > n) {
        cnt++; // 以枚舉到一組匹配，把計數器加 1
        return;
    }
	dfs(x + 1, now_cost_sum); // 匹配中不選任何和 x 相連的邊
	for (auto [y, v]: e[x]) {
		if (!choosen[y]) { // 檢查邊(x, y) 可不可以加入匹配
			choosen[y] = 1;           // 紀錄 y 已被選取
            dfs(x + 1, now_cost_sum + v); // 呼叫下一層遞迴
            choosen[y] = 0;           // 取消 y 被選取的紀錄
        }
    }
}
int main(){
    // 讀入參數
	scanf("%d%d%d", &n, &k, &t);
	for (int i = 1; i <= k; i++) {
        int h, w, r;
		scanf("%d%d%d", &h, &w, &r);
        e[h].push_back(EDGE(w, r));
    }
    /* * 二分搜索
     * 匹配可能最大值為最大權重乘最多邊數
     * [low, high] 為當前還可能是答案的區間
     */
	int low = 0, high = 1000 * n;
	while (low < high) {
		mid = (low + high) >> 1;
        cnt = 0; // 計數器歸零
        dfs(1, 0);
		if (cnt >= t) high = mid;
        else low = mid + 1;
    }
    printf("%d\n", low);
}

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

using namespace std;

vector<int> sol;
int n,M[5][5];

void search(int pos, int mask, int sum){
    if(pos == -1) sol.push_back(sum);
    else{
        search(pos - 1,mask,sum);

        for(int i = 0;i < n;++i)
            if((mask & (1 << i)) == 0 && M[pos][i] != -1)
                search(pos - 1,mask | (1 << i),sum + M[pos][i]);
    }
}

int main(){
    int m,t;

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

    memset(M,-1,sizeof M);

    for(int i = 0,u,v,w;i < m;++i){
        scanf("%d %d %d",&u,&v,&w);
        --u; --v;

        M[u][v] = w;
    }

    search(n - 1,0,0);

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

    printf("%d\n",sol[t - 1]);

    return 0;
}

#include <cstdio>
#include <cstring>
#include <algorithm>
#define FOR(i,s,e) for (int i=(s); i<(e); i++)
#define FOE(i,s,e) for (int i=(s); i<=(e); i++)
#define CLR(a,x) memset(a, x, sizeof(a))
#define EXP(i,l) for (int i=(l); i; i=qn[i])
using namespace std;

int n, m, x, y, w, th, ok, sum, t;
int p[10], u[10], a[10][10], v[10000];

void dfs(int x, int s){
	if (x == n) v[t++] = s;
	else{
		FOR(i,0,n)
		if (!u[i] && a[x][i]){
			u[i] = 1;
			dfs(x+1, s + a[x][i]);
			u[i] = 0;
		}

		dfs(x+1, s);
	}
}

int main(){
	scanf("%d%d%d", &n, &m, &th);
	while (m--){
		scanf("%d%d%d", &x, &y, &w);
		x--, y--;
		a[x][y] = w;
	}

	dfs(0, 0);
	sort(v, v + t);
	printf("%d\n", v[th-1]);
	return 0;
}

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

using namespace std;

int n,k,t;
vector<vector<pair<int,int> > > a;
vector<int> ans;
vector<bool> was;

void perebor(int cur=0, const int ccheer=0){
	if (cur>=n){
		ans.push_back(ccheer);
		return;
	}
	perebor(cur+1,ccheer);
	for (unsigned i=0; i<a[cur].size(); i++)
		if (!was[a[cur][i].first]){
			was[a[cur][i].first]=true;
			perebor(cur+1,ccheer+a[cur][i].second);
			was[a[cur][i].first]=false;
		}
}

int main(){
	scanf("%d%d%d",&n,&k,&t);
	a.resize(n);
	was.resize(n,false);
	for (int i=0; i<k; i++){
		int q,w,e;
		scanf("%d%d%d",&q,&w,&e);
		a[--q].push_back(make_pair(--w,e));
	}
	perebor();
	sort(ans.begin(),ans.end());
	printf("%d\n",ans[t-1]);
	return 0;
}

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

#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <memory.h>

using namespace std;

#define REP(i,n) for(int i=0;i<n;++i)
#define ABS(n) ((n)<0 ? -(n) : (n))
#define SQR(a) (a)*(a)
#define MIN(a,b) (a<b?a:b)
#define MAX(a,b) (a>b?a:b)
#define MP make_pair
#define PB push_back
#define FILL(a) memset(a,0,sizeof(a));
#define COPY(a,b) memcpy(a,b,sizeof (b));
#define SI(a) (int)((a).size())
#define ALL(a) (a).begin(),(a).end()
#define y1 yyyyy1
#define prev prevvvvv
#define LL long long
const double PI = 2*acos(0.0);
const double EPS = 1e-8;
const int INF = (1<<30)-1;

int n, k, t, r[20][20];
vector<int> p;

inline int estimate (){
	int res = 0;
	REP(i,n) if (p[i] >= 0){
		if (r[i][p[i]] == 0) return -1;
		res += r[i][p[i]];
	}
	return res;
}

bool myperm(vector<int>& p){
	do{
		vector<int> cp;
		REP(i,SI(p)) cp.PB(p[i]);
		if (!next_permutation (p.begin(), p.end())) return false;
		int i = 0;
		while (p[i]==cp[i]) ++i;
		if (i < n) return true;
	}while (true);
}

int main(){
	////freopen ("input.txt", "r", stdin);
	//freopen ("output.txt", "w", stdout);
	cin >> n >> k >> t;
	REP(i,k){
		int a, b, w;
		cin >> a >> b >> w;
		--a; --b;
		r[a][b] = w;
	}
	REP(i,n) p.PB(-1);
	REP(i,n) p.PB(i);

	vector<int> o;
	do{
		int res = estimate();
		if (res >= 0) o.PB(res);
	}while (myperm (p));
	sort (o.begin(), o.end());

	cout << o[t-1];

	return 0;
};

#include<bits/stdc++.h>

using namespace std;

int a[30][30];
int mid,n,k;
bool vis[30];

int dfs(int id,int res)
{
    if (res>mid) return 0;
    if (id>n) return 1;
    int ret=dfs(id+1,res);
    for (int i=1;i<=n;i++)
    {
        if (!vis[i]&&a[id][i])
        {
            vis[i]=1;
            ret+=dfs(id+1,res+a[id][i]);
            vis[i]=0;
            if (ret>k) break;
        }
    }
    if (ret>k) ret=k;
    return ret;
}

int main()
{
    int m;
    scanf("%d%d%d",&n,&m,&k);
    memset(a,0,sizeof(a));
    int x,y,z;
    for (int i=1;i<=m;i++)
    {
        scanf("%d%d%d",&x,&y,&z);
        a[x][y]=z;
    }
    int l=0,r=n*1000;
    while (l<r)
    {
        mid=(l+r)>>1;
        if (dfs(1,0)>=k) r=mid;
        else l=mid+1;
    }
    printf("%d\n",l);
}

#include <bits/stdc++.h>

//#pragma GCC optimize(2)
#define fi first
#define se second
#define ls (rt<<1)
#define rs (rt<<1|1)
#define y1 uintnttjjtjtj
#define M 30
#define MP make_pair
#define PB push_back
#define showtime  cerr<<(clock()/CLOCKS_PER_SEC)<<'\n'
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef vector<int> vi;
const int maxn = 40;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
void MOD(int &x) { if (x >= mod) x -= mod; }
void MOD(ll &x) { if (x >= mod) x -= mod; }
ll powmod(ll x, ll n) {
	ll ret = 1;
	for (; n > 0; n >>= 1, x = x * x % mod) if (n & 1) ret = ret * x % mod;
	return ret;
}
int n, m, k;
vector<pii> v[maxn];
int c[maxn][maxn];
bool vis[maxn];
int dfs(int p, int w, int limt) {
	if (limt < w) return 0;
	if (p == n + 1) return 1;
	int r = dfs(p + 1, w, limt);
	for (int i = 1; i <= n; ++i) {
		if (!vis[i] && c[p][i]) {
			vis[i] = 1;
			r += dfs(p + 1, w + c[p][i], limt);
			vis[i] = 0;
		}
		if (r > k) return r;
	}
	return r;
}
int main() {
//	freopen("1.in", "r", stdin);
//	freopen("1.out", "w", stdout);
//	srand(time(NULL));
//	ios::sync_with_stdio(0), cin.tie(0);
	cin >> n >> m >> k;
	for (int i = 1; i <= m; ++i) {
		int x, y, w;
		cin >> x >> y >> w;
//		v[x].PB(MP(y, w));
		c[x][y] = w;
	}
	int l = 0, r = n * 1000;
	while (l < r) {
		int mid = l + r >> 1;
		int x = dfs(1, 0, mid);
		if (x >= k) r = mid;
		else l = mid + 1;
	}
	cout << l << '\n';
	return 0;
}

#include <cstdio>
#include <set>
#include <vector>
using namespace std;

const int Maxn = 25;

int n, k, t;
vector <int> w[Maxn], r[Maxn];
bool taken[Maxn];
multiset <int> res;

int Calc(int v, int l)
{
    if (!l) return 1;
    else {
        int res = 0;
        for (int i = v; i <= n; i++)
            for (int j = 0; j < w[i].size(); j++) if (!taken[w[i][j]]) {
                taken[w[i][j]] = true;
                res += Calc(v + 1, l - 1);
                taken[w[i][j]] = false;
            }
        return res;
    }
}

void Gen(int v, int l, int d)
{
    if (!l) {
        if (res.size() < t) res.insert(d);
        else if (d < *res.rbegin()) { res.erase(res.find(*res.rbegin())); res.insert(d); }
    } else for (int i = v; i <= n; i++)
              for (int j = 0; j < w[i].size(); j++) if (!taken[w[i][j]]) {
                  taken[w[i][j]] = true;
                  Gen(i + 1, l - 1, d + r[i][j]);
                  taken[w[i][j]] = false;
              }
}

int main()
{
    scanf("%d %d %d", &n, &k, &t);
    while (k--) {
        int hi, wi, ri; scanf("%d %d %d", &hi, &wi, &ri);
        w[hi].push_back(wi); r[hi].push_back(ri);
    }
    int add = 0;
    int i;
   /* for (i = 0; i <= n; i++) {
        add += Calc(1, i);
        if (t <= add) break;
    }*/
    for (i = n; i >= 0; i--) Gen(1, i, 0);
    printf("%d\n", *res.rbegin());
    return 0;
}

#include <bits/stdc++.h>

//#pragma GCC optimize(2)
#define fi first
#define se second
#define ls (rt<<1)
#define rs (rt<<1|1)
#define y1 uintnttjjtjtj
#define M 30
#define MP make_pair
#define PB push_back
#define showtime  cerr<<(clock()/CLOCKS_PER_SEC)<<'\n'
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef vector<int> vi;
const int maxn = 100;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
void MOD(int &x) { if (x >= mod) x -= mod; }
void MOD(ll &x) { if (x >= mod) x -= mod; }
ll powmod(ll x, ll n) {
	ll ret = 1;
	for (; n > 0; n >>= 1, x = x * x % mod) if (n & 1) ret = ret * x % mod;
	return ret;
}
int n, m, k;
vector<pii> v[maxn];
bool vis[maxn];
int dfs(int p, int w, int limt) {
	if (limt < w) return 0;
	if (p == n + 1) return 1;
	int r = dfs(p + 1, w, limt);
	for (auto &u:v[p]) {
		if (r > k) break;
		if (!vis[u.fi]) {
			vis[u.fi] = 1;
			r += dfs(p + 1, w + u.se, limt);
			vis[u.fi] = 0;
		}
	}
	return r;
}
int main() {
//	freopen("1.in", "r", stdin);
//	freopen("1.out", "w", stdout);
//	srand(time(NULL));
//	ios::sync_with_stdio(0), cin.tie(0);
	cin >> n >> m >> k;
	for (int i = 1; i <= m; ++i) {
		int x, y, w;
		cin >> x >> y >> w;
		v[x].PB(MP(y, w));
	}
	int l = 0, r = n * 1000;
	while (l < r) {
		int mid = l + r >> 1;
		int x = dfs(1, 0, mid);
		if (x >= k) r = mid;
		else l = mid + 1;
	}
	cout << l << '\n';
	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 = 22;

int n, sum = 0;
vector< PI > e[MAX_N];
bool ok[MAX_N];
VI a;

void gen(int i) {
   if (i > n) {
      a.pb(sum);
      return;
   }
   gen(i+1);
   rep(j, e[i].size()) {
      int v = e[i][j].sc;
      if (ok[v]) {
         ok[v] = false;
         sum += e[i][j].fr;
         gen(i+1);
         sum -= e[i][j].fr;
         ok[v] = true;
      }
   }
}

int main() {
   int t, m;
   cin >> n >> m >> t;
   foru(i, 1, m) {
      int x, y, w;
      scanf("%d%d%d", &x, &y, &w);
      e[x].pb(mp(w, y));
   }
   fill(ok, true);
   gen(1);
   sort(all(a));
   cout << a[t-1];
   return 0;
}

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

using namespace std;

void ASS(bool bb)
{
    if (!bb)
    {
        ++*(int*)0;
    }
}

#define FOR(i, x) for (int i = 0; i < (int)(x); i++)
#define CL(x) memset(x, 0, sizeof(x))
#define CLX(x, y) memset(x, y, sizeof(x))

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

typedef vector<int> vi;

typedef long long LL;

struct S
{
    int x;
    LL m;
    bool operator < (const S& s) const
    {
        return x < s.x;
    }
};

vector<S> g[1 << 20];

int main()
{
    int n, k, T;
    cin >> n >> k >> T;
    vector<S> v;
    FOR(i, k)
    {
        S s;
        int x, y;
        cin >> x >> y >> s.x;
        x--;
        y--;
        s.m = (1LL << x) + (1LL << (y + n));
        v.push_back(s);
    }
    sort(v.begin(), v.end());
    vector<S> q;
    {
        S s;
        s.m = 0;
        s.x = 0;
        q.push_back(s);
    }
    FOR(z, k)
    {
        int Max = 0;
        FOR(i, q.size())
            if (0 == (v[z].m & q[i].m)) {
                S t = q[i];
                t.m |= v[z].m;
                t.x += v[z].x;
                g[t.x].push_back(t);
                Max = max(Max, t.x + 1);
            }
        vector<S> q2;
        q2.reserve(T);
        FOR(i, Max) if (g[i].size())
        {
            FOR(j, g[i].size())
                q2.push_back(g[i][j]);
            g[i].clear();
        }
//        sort(q2.begin(), q2.end());
        vector<S> res(q.size() + q2.size());
        merge(q.begin(), q.end(), q2.begin(), q2.end(), res.begin());
        if (res.size() > T)
            res.resize(T);
        q = res;
    }
    cout << q[T - 1].x << endl;
    return 0;
}

#include<bits/stdc++.h>

using namespace std;

#define FC ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define deb(args...) std::cerr<<"DEBUG------"<<'\n';std::cerr<<#args<<"------>";err(args)

void err(){
    std::cerr<<'\n'<<"END OF DEBUG"<<'\n'<<'\n';
}

template<typename T,typename... Args>
void err(T a,Args... args){
    std::cerr<<a<<", ";
    err(args...);
}

template<template<typename...> class T,typename t,typename... Args>
void err(T<t> a, Args... args){
    for(auto x: a){
        std::cerr<<x<<", ";
    }
    err(args...);
}

const long double PI=acos(-1.0);
const long double eps=1e-6;
const long long maxw=(long long)1e17+(long long)10;

using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

/*head------[@cordercorder]*/

const int maxn=25;

struct node{
    int to;
    int w;
};

vector<node> e[maxn+maxn];
int n,k,t,cnt;
bool isv[maxn+maxn];

void dfs(int u,int sum,int lim){
    if(cnt>=t){
        return ;
    }
    if(u>n){
        cnt++;
        return ;
    }
    dfs(u+1,sum,lim);
    int v,w;
    for(int i=0;i<(int)e[u].size();i++){
        v=e[u][i].to;
        w=e[u][i].w;
        if(!isv[v]&&w+sum<=lim){
            isv[v]=true;
            dfs(u+1,w+sum,lim);
            isv[v]=false;
        }
    }
}

void solve(){
    int l=0,r=(int)1e5+10,mid;
    while(l<r){
        mid=(l+r)>>1;
        cnt=0;
        dfs(1,0,mid);
        if(cnt>=t){
            r=mid;
        }
        else{
            l=mid+1;
        }
    }
    printf("%d\n",l);
}

int main(void){
    int u,v,w;
    scanf("%d %d %d",&n,&k,&t);
    for(int i=1;i<=k;i++){
        scanf("%d %d %d",&u,&v,&w);
        v+=n;
        e[u].push_back({v,w});
        e[v].push_back({u,w});
    }
    solve();
    return 0;
}

//177F
#include<cstdio>
#include<map>
#include<algorithm>
using namespace std;

multimap<int, int> tree;
multimap<int, int>::iterator it;
int n, k, t, top, t1, v[105], c[105], next[105], head[25], s1[4000005], s2[4000005];

bool full = false;

int main() {
  scanf("%d %d %d", &n, &k, &t);
  for (int i = 1; i <= k; i++) {
    scanf("%d %d %d", &t1, &v[i], &c[i]);
    v[i]--;
    next[i] = head[t1]; head[t1] = i;
  }
  tree.insert(make_pair(0, 0));
  for (int i = 1; i <= n; i++) {
    top = 0;
    for (it = tree.begin(); it != tree.end(); it++) {
      for (int j = head[i]; j; j = next[j]) {
        if ((it->second & (1 << v[j])) == 0) {
          top++;
          s1[top] = it->first + c[j];
          s2[top] = (it->second) | (1 << v[j]);
          if (full && tree.rbegin()->first <= s1[top]) top--;
        }
      }
    }
    for (int j = 1; j <= top; j++) {
      tree.insert(make_pair(s1[j], s2[j]));
      if (tree.size() > t) {
        it = tree.end(); it--;
        tree.erase(it);
      }
    }
    if (tree.size() == t) full = true;
  }
  printf("%d\n", tree.rbegin()->first);
  return 0;
}

#include <cstdio>
#include <sstream>
#include <iostream>

#include <set>
#include <map>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <cstring>

#include <ctime>
#include <cmath>
#include <cstdlib>
#include <algorithm>
using namespace std;

#define REP(i,n) for (int i = 0; i < (n); ++i)
#define FOR(i,a,b) for (int i = (a); b; ++i)
#define REPI(i,c) for (typeof(c.begin()) i = c.begin(); i != c.end(); ++i)
#define ALL(c) c.begin(), c.end()
#define SZ(x) ((int)(x).size())

#define DB(x) cout << #x << " = " << x << endl;

const int MAX = 25;
const int MAXP = MAX*1010;

int N, K, T;
int m[MAX], w[MAX], a[MAX];
int um[MAX], uw[MAX];
int pc[MAXP];

int main()
{
    ios::sync_with_stdio(false);

    cin >> N >> K >> T;

    REP(i, K)
    {
        cin >> m[i] >> w[i] >> a[i];
        --m[i];
        --w[i];
    }

    int dt = 0;
    REP(i, 1<<K)
    {
        int p = 0;
        ++dt;

        REP(j, K)
            if (i & (1 << j))
            {
                p += a[j];
                if (um[ m[j] ] == dt) goto err;
                if (uw[ w[j] ] == dt) goto err;
                um[ m[j] ] = dt;
                uw[ w[j] ] = dt;
            }

        ++pc[p];
        err:;
    }

    int t = 0;
    REP(i, MAXP)
    {
        t += pc[i];
        if (t >= T)
        {
            cout << i << endl;
            exit(0);
        }
    }

    return 0;
}// (++UH)++ :: agarwaen

#include<stdio.h>
#define N 25
using namespace std;
int vis[N],a[N][N];
int n,m,k,x,y,z,i,l,r,mid;
int DFS(int x,int now){
	if (now>mid) return 0;
	if (x>n) return 1;
	int ret=DFS(x+1,now);
	for (int i=1;i<=n&&ret<k;i++)
		if (!vis[i]&&a[x][i])
			vis[i]=1,ret+=DFS(x+1,now+a[x][i]),vis[i]=0;
	if (ret>=k) ret=k;
	return ret;
}
int main(){
	scanf("%d%d%d",&n,&m,&k);
	for (i=1;i<=m;i++)
		scanf("%d%d%d",&x,&y,&z),a[x][y]=z;
	l=0;r=1000*n;
	while (l<r){
		mid=(l+r)>>1;
		if (DFS(1,0)>=k) r=mid;else l=mid+1;
  }printf("%d\n",l);
}

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
priority_queue<int > h;
int n,m,k,x,y,z,a[22][22];
bool b[22];
void dfs(int x,int y)
{
	if (h.size()==k) if (y>=h.top()) return;
	if (x>n){
		if (h.size()==k) h.pop();
		h.push(y); return;
		}
	dfs(x+1,y);
	for (int i=1;i<=n;i++) if (!b[i] && a[x][i])
		b[i]=1,dfs(x+1,y+a[x][i]),b[i]=0;
}
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	for (int i=1;i<=m;i++) scanf("%d%d%d",&x,&y,&z),a[x][y]=z;
	dfs(1,0); printf("%d\n",h.top()); return 0;
}

#include <bits/stdc++.h>

//#pragma GCC optimize(2)
#define fi first
#define se second
#define ls (rt<<1)
#define rs (rt<<1|1)
#define y1 uintnttjjtjtj
#define M 30
#define MP make_pair
#define PB push_back
#define showtime  cerr<<(clock()/CLOCKS_PER_SEC)<<'\n'
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef vector<int> vi;
const int maxn = 100;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
void MOD(int &x) { if (x >= mod) x -= mod; }
void MOD(ll &x) { if (x >= mod) x -= mod; }
ll powmod(ll x, ll n) {
	ll ret = 1;
	for (; n > 0; n >>= 1, x = x * x % mod) if (n & 1) ret = ret * x % mod;
	return ret;
}
int n, m, k;
vector<pii> v[maxn];
bool vis[maxn];
struct edge {
		int x, y, w;
		ll sta;
} E[maxn];
int cnt = 0;
int dfs(int p, int w, int limt, ll sta) {
	if (limt < w || cnt >= k) return 0;
	if (p == m + 1) {
		cnt++;
		return 1;
	}
	int r = 0, u = E[p].x, v = E[p].y;
	if (!(sta & E[p].sta)) {
		r = dfs(p + 1, w + E[p].w, limt, sta | E[p].sta);
	}
	if (r >= k) return r;
	r += dfs(p + 1, w, limt, sta);
	return r;
}
int main() {
//	freopen("1.in", "r", stdin);
//	freopen("1.out", "w", stdout);
//	srand(time(NULL));
//	ios::sync_with_stdio(0), cin.tie(0);
	cin >> n >> m >> k;
	for (int i = 1; i <= m; ++i) {
		int x, y, w;
		cin >> x >> y >> w;
		E[i] = {x, y, w};
		ll s = 1ll << (x + n);
		s |= 1ll << y;
		E[i].sta = s;
	}
	sort(E + 1, E + m + 1, [](const edge &a, const edge &b) {
			return a.w < b.w;
	});
	int l = 0, r = n * 1000;
	while (l < r) {
		int mid = l + r >> 1;
		cnt = 0;
		int x = dfs(1, 0, mid, 0);
		x = cnt;
		if (x >= k) r = mid;
		else l = mid + 1;
	}
	cout << l << '\n';
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

int r[5][5];

int main() {
    int n, k, t;
    scanf("%d %d %d", &n, &k, &t);
    memset(r, -1, sizeof r);
    while(k--) {
        int u, v, c;
        scanf("%d %d %d", &u, &v, &c);
        r[u - 1][v - 1] = c;
    }
    vector<int> all(n + n, -1);
    map<vector<int>, int> valid;
    for(int i = 0; i < n; ++i) {
        all[i + n] = i;
    }
    do {
        bool ok = true;
        for(int i = 0; i < n; ++i) {
            ok &= all[i] == -1 || r[i][all[i]] != -1;
        }
        if(!ok) continue;
        int sum = 0;
        for(int i = 0; i < n; ++i) {
            if(all[i] != -1) {
                sum += r[i][all[i]];
            }
        }
        valid[vector<int>(all.begin(), all.begin() + n)] = sum;
    }while(next_permutation(all.begin(), all.end()));
    vector<int> total;
    for(auto item : valid) {
        total.push_back(item.second);
    }
    sort(total.begin(), total.end());
    printf("%d\n", total[t - 1]);
    return 0;
}

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <list>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
using namespace std;
int n,k,t;
int h,w,r;

struct Edge
{
       int h,w,r;
};
Edge graf[101];
bool mark[41];

vector<int> marr;

void recgen(int id, int tsum)
{
  for (int i=id;i<k;i++)
  {
      if (!mark[graf[i].h]&&!mark[graf[i].w+n])
      {
        mark[graf[i].h]=true;
        mark[graf[i].w+n]=true;
        tsum+=graf[i].r;
        //printf("used edge %d\n",i);
        recgen(i+1,tsum);
        tsum-=graf[i].r;
        mark[graf[i].h]=false;
        mark[graf[i].w+n]=false;
      }
  }
      //printf("%d\n", tsum);
      marr.push_back(tsum);
}
int main()
{
    scanf("%d%d%d",&n,&k,&t);
    for (int i=0;i<2*n;i++) mark[i]=false;
    for (int i=0;i<k;i++)
    {
        scanf("%d%d%d",&h,&w,&r);
        graf[i].h=h-1;
        graf[i].w=w-1;
        graf[i].r=r;
    }
    recgen(0,0);
    sort(marr.begin(),marr.end());
    printf("%d\n",marr[t-1]);
    //scanf("%d",&n);
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

#include <ext/rope>

using namespace __gnu_cxx;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;

#define int long long

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;

#define add push_back
#define rem pop_back
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REV(x) reverse(ALL(x))
#define F first
#define S second
#define DEBUG(x) cout << #x << " " << x << endl;
#define forn(i, a, b) for(int i = a; i <= b; i++)

template<typename T1, typename T2> auto max ( T1 a, T2 b ) { auto max = a > b ? a : b; return max; }
template<typename T1, typename T2> auto min ( T1 a, T2 b ) { auto min = a < b ? a : b; return min; }
template<typename T1, typename T2> void updmax ( T1 &a, T2 b ) { a = a > b ? a : b; }
template<typename T1, typename T2> void updmin ( T1 &a, T2 b ) { a = a < b ? a : b; }

const double EPS = 1e-9;
const double PI = acos ( -1. );
const int mod = 1e9 + 7;
int inf = __INT64_MAX__;
string YN[] = {"NO", "YES"};

#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a)*((b)/gcd(a,b)))

inline int gcd_e( int a, int b, int & x, int & y )
{
        if ( !a ) {
                x = 0;
                y = 1;
                return b;
        }
        int x1, y1;
        int d = gcd_e ( b % a, a, x1, y1 );
        x = y1 - ( b / a ) * x1;
        y = x1;
        return d;
}

inline int div_mod( int a, int b, int m = mod )
{
        int x, y;
        int g = gcd_e( b, m, x, y );
        x = ( x % m + m ) % m;
        return ( a * x ) % m;
}

int pow_mod ( int a, int n, int m = mod )
{
        int res = 1;
        while ( n ) {
                if ( n & 1 )
                        res = ( res * a ) % m;
                a = ( a * a ) % m;
                n >>= 1;
        }
        return res;
}

int px[] = { 1, -1, 0, 0 };
int py[] = { 0, 0, -1, 1 };
int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
int dy[] = { 0, 1, 0, -1, 1, -1, 1, -1 };

//tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> tr;

static const int MAXN = 1 << 20;
static int a[MAXN], b[MAXN], p[MAXN], c[20][20];

int n, m, k;
int res, cnt[MAXN];
string s;

vector<int> ans;
vector<int> used;
void rec( int i, int s, vector<int> used ){

	if( i == n ){
		ans.add( s );
		return;
	}
	rec( i + 1, s, used );
	for( int j = 0; j < n; j++ )
		if( !used[j] && c[i][j] ){
			used[j] = 1;
			rec( i + 1, s + c[i][j], used );
			used[j] = 0;
		}
}
void solution()
{
	cin >> n >> m >> k;
	used.resize( n, 0 );
	while( m-- ){
		int x, y, w;
		cin >> x >> y >> w;
		x--;
		y--;
		c[x][y] = w;
	}
	rec( 0, 0, used );
	sort( ALL( ans ) );
	cout << ans[k - 1] << endl;
}

int32_t main ( )
{

        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);

        ios_base::sync_with_stdio ( false ); cin.tie ( nullptr ); cout.tie ( nullptr );
        //cout.precision(15);

        int query = 1;
        // cin >> query;

        while ( query-- ) solution();

        return 0;

}

#include<iostream>
#include<iomanip>
#include<cstring>
using namespace std;
const int maxn = 1e3+7;
struct Edge{
    int nxt,to,w;
}edge[maxn];
int tot=0,head[maxn],mid,n,cnt,vis[maxn],t;
void add(int u,int v,int w){
    edge[tot].to=v;
    edge[tot].w=w;
    edge[tot].nxt=head[u];
    head[u]=tot++;
}

void dfs(int sum,int u){
    if(u > n){
        cnt++;
        return ;
    }
    dfs(sum,u+1);
    for(int i=head[u];i!=-1;i=edge[i].nxt){
        int v=edge[i].to;
        if(!vis[v]&&cnt < t&&sum+edge[i].w<=mid){
            vis[v]=1;
            dfs(sum+edge[i].w,u+1);
            vis[v]=0;
        }
    }
}
int main(){
    memset(head,-1,sizeof(head));
    memset(vis,0,sizeof(vis));
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);

    int m;
    cin>>n>>m>>t;
    int a,b,c;
    for(int i=0;i<m;i++){
        cin>>a>>b>>c;
        add(a,b,c);
    }
    int l=0,r=1000*n;
    while(l<r){
        cnt=0;
        mid=(l+r)/2;
        dfs(0,1);
        if(cnt>=t){
            r=mid;
        }else{
            l=mid+1;
        }
    }
    cout<<l<<endl;
}

#include<bits/stdc++.h>
using namespace std;
int n,m,t,x,y,z,res,lst;
long long msk;
priority_queue<pair<int,pair<long long,int> > > pq;
pair<int,pair<int,int> > edge[444];
int main()
{
	scanf("%d%d%d",&n,&m,&t);
	pq.push(make_pair(0,make_pair(0,0)));
	for (int i=1;i<=m;i++)
	{
		scanf("%d%d%d",&x,&y,&z);
		edge[i]=make_pair(z,make_pair(x,y));
	}
	sort(edge+1,edge+m+1);
	for (int i=1;i<=t;i++)
	{
		res=-pq.top().first;msk=pq.top().second.first;lst=pq.top().second.second;
	//	cout<<res<<" "<<msk<<" "<<lst<<endl;
		pq.pop();
		for (int j=lst+1;j<=m;j++)
		{
			if ((msk&(1ll<<edge[j].second.first)) || (msk&(1ll<<(edge[j].second.second+n)))) continue;
			pq.push(make_pair(-res-edge[j].first,make_pair(msk|(1ll<<edge[j].second.first)|(1ll<<(edge[j].second.second+n)),j)));
			break;
		}
		if (lst)
		{
			msk^=(1ll<<edge[lst].second.first);msk^=(1ll<<(edge[lst].second.second+n));
			for (int j=lst+1;j<=m;j++)
			{
				if ((msk&(1ll<<edge[j].second.first)) || (msk&(1ll<<(edge[j].second.second+n)))) continue;
				pq.push(make_pair(-res-edge[j].first+edge[lst].first,make_pair(msk|(1ll<<edge[j].second.first)|(1ll<<(edge[j].second.second+n)),j)));
				break;
			}
		}
	}
	printf("%d\n",res);
	return 0;
}

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

const int maxM = 100;
int n, m, cnt;
int x[maxM], y[maxM], r[maxM];
int p[maxM];
struct State {
	int val;
	int S, T, i;
	State(int v, int S, int T, int i) :
		val(v), S(S), T(T), i(i) {}
	bool operator < (const State &rhs) const {
		return val < rhs.val;
	}
	bool operator > (const State &rhs) const {
		return val > rhs.val;
	}
};
priority_queue< State, vector<State>, std::greater<State> > pq;

bool cmp(int x, int y) {
	return r[x] < r[y];
}

bool extend(int val, int S, int T, int i) {
	if(i < m) {
		int SS = S | (1 << x[p[i]]);
		int TT = T | (1 << y[p[i]]);
		if(SS == S || TT == T) return false;
		pq.emplace(val + r[p[i]], SS, TT, i + 1);
		return true;
	}
	return false;
}

int main() {
	cin >> n >> m >> cnt;
	for(int i = 0; i < m; ++i) {
		cin >> x[i] >> y[i] >> r[i];
		x[i]--; y[i]--;
		p[i] = i;
	}
	std::sort(p, p + m, cmp);
	pq.emplace(0, 0, 0, 0);
	cnt--;
	while(cnt--) {
		auto u = pq.top(); pq.pop();
		int val = u.val, S = u.S, T = u.T, i = u.i;
		for(int j = i; j < m; ++j) extend(val, S, T, j);
	}
	cout << pq.top().val << endl;
	return 0;
}

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<bitset>

#define ls (t<<1)
#define rs ((t<<1)+1)
#define fi first
#define se second
#define mk make_pair

#define N 105
#define M 200005
#define seed 23333
#define Mo 998244353

using namespace std;
int i,j,m,n,p,k,t,sum,vis[N],a[N][N],l,r,mid,x,y;
bool dfs(int x,int y)
{
	  if (x==n+1)
	  {
	  	 ++sum;
	  	 if (sum==t) return 1;
	  	 return 0;
	  }
	  int i;
	  for (i=1;i<=n;++i)
	    if (a[x][i]&&!vis[i]&&y+a[x][i]<=mid)
	    {
	    	  vis[i]=1;
	    	  if (dfs(x+1,y+a[x][i])) { vis[i]=0; return 1; }
	    	  vis[i]=0;
	    }
	  if (dfs(x+1,y)) return 1;
	  return 0;
}
int main()
{
	  scanf("%d%d%d",&n,&m,&t);
	  l=0,r=4000000,mid=0;
	  for (i=1;i<=m;++i)
	  {
	     scanf("%d%d",&x,&y);
		 scanf("%d",&a[x][y]);
	  }
	  while ((l+r)>>1!=mid)
	  {
	  	  mid=(l+r)>>1; sum=0;
	  	  if (dfs(1,0)) r=mid; else l=mid;
	  }
	  printf("%d\n",r);
}

#include<stdio.h>

using namespace std;

int a[25][25];
int mid,n,k,m,x,y,z,l,r;
bool vis[25];

int dfs(int id,int res)
{
    if (res>mid) return 0;
    if (id>n) return 1;
    int ret=dfs(id+1,res);
    for (int i=1;i<=n&&ret<k;i++)
    {
        if (!vis[i]&&a[id][i])
        {
            vis[i]=1;
            ret+=dfs(id+1,res+a[id][i]);
            vis[i]=0;
        }
    }
    if (ret>=k) ret=k;
    return ret;
}

int main()
{
    scanf("%d%d%d",&n,&m,&k);
    for (int i=1;i<=m;i++)
    {
        scanf("%d%d%d",&x,&y,&z);
        a[x][y]=z;
    }
    l=0,r=n*1000;
    while (l<r)
    {
        mid=(l+r)>>1;
        if (dfs(1,0)>=k) r=mid;
        else l=mid+1;
    }
    printf("%d\n",l);
}

#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 5e3 + 10;
const int mask = (1 << 5) - 1;
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	typedef pair<int, pair<LL, LL>> Node;
	priority_queue<Node, vector<Node>, greater<Node>> pq;
	map < pair<LL, LL>, int> vis;
	pq.emplace(0, make_pair(0LL, 0LL));
	priority_queue<int> q;
	q.push(0);
	int n, k, m;
	vector<tuple<int, int, int>> vp;
	cin >> n >> k >> m;
	while (k--)
	{
		int h, w, r;
		cin >> h >> w >> r;
		vp.emplace_back(r, h, w);
	}
	sort(vp.begin(), vp.end());
	int cost = 0;
	while (!pq.empty())
	{
		int val;
		pair<LL, LL> v;
		tie(val, v) = pq.top();
		pq.pop();
		cost++;
		if (cost == m)
		{
			cout << val << endl;
			break;
		}
		LL a, b;
		tie(a, b) = v;
		int flag[41];
		MEM(flag, 0);
		for (int i = 0; i < 60; i += 5)
		{
			int x = a >> i & mask;
			int y = b >> i & mask;
			if (x) flag[n + x] = flag[i / 5 + 1] = 1;
			if (y) flag[n + y] = flag[i / 5 + 13] = 1;
		}
		for (auto& p : vp)
		{
			int w, x, y;
			tie(w, x, y) = p;
			if (flag[x] || flag[y + n]) continue;
			while (q.size() > m) q.pop();
			if (q.size() == m && w + val >= q.top()) break;
			LL A = a, B = b;
			if (x <= 12) A |= LL(y) << ((x - 1) * 5);
			else B |= LL(y) << ((x - 13) * 5);
			if (vis.count({ A,B })) continue;
			vis[make_pair(A, B)] = 1;
			pq.emplace(w + val, make_pair(A, B));
			q.push(w + val);
		}
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int x,y,z,n,m,k,med,cnt;
pair<int,long long>a[100];
void dfs(int id,int v,long long mask){
    if(id==m)return;
    if(cnt>=k)return;
    if(v+a[id].first>med)return;
    if(!(mask&a[id].second)){
        cnt++;
        dfs(id+1,v+a[id].first,mask|a[id].second);
    }
    dfs(id+1,v,mask);
}
int main(){
    scanf("%d%d%d",&n,&m,&k);
    if(k==1)return puts("0"),0;
    for(int i=0;i<m;i++) {
        scanf("%d%d%d",&x,&y,&z);
        a[i]=make_pair(z,(1LL<<(x+n))|(1LL<<y));
    }
    sort(a,a+m);
    int ans=0,t;
    for(t=1;;t<<=1){
        med=t;
        cnt=1;
        dfs(0,0,0);
        if(cnt>=k){
            ans=t>>1;
            break;
        }
    }
    for(t=ans>>1;t;t>>=1){
        med=ans+t;
        cnt=1;
        dfs(0,0,0);
        if(cnt<k)ans+=t;
    }
    cout<<ans+1<<endl;
}

#include<cstdio>
const int MAX_N = 20;
int n, k, t; // 题目里就有的参数
int e[MAX_N + 1][MAX_N + 1]; // e[x][y] 存在若且唯若边(x, y) 存在
int choosen[MAX_N + 1];
int mid; // 二分搜索时，猜测的答案
int cnt; // 计数器
void dfs(int x, int now_cost_sum) {
    if (x > n) {
        cnt++; // 以枚举到一组匹配，把计数器加 1
        return;
    }
    dfs(x + 1, now_cost_sum); // 匹配中不选任何和 x 相连的边
    // 枚举 x 要和谁匹配的同时，满足条件的匹配数目达到 t 即剪枝
    for (int y = 1; y <= n && cnt < t; y++) {
        // 检查边 (x, y) 可否加入匹配，加入会权值和超过限制就剪枝
        if (!choosen[y] && e[x][y] && now_cost_sum + e[x][y] <= mid) {
            choosen[y] = 1;           // 记录 y 已被选取
            dfs(x + 1, now_cost_sum + e[x][y]); // 调用下一层递归
            choosen[y] = 0;           // 取消 y 被选取的记录
        }
    }
}
int main() {
    // 读入参数
    scanf("%d%d%d", &n, &k, &t);
    for (int i = 1; i <= k; i++) {
        int h, w, r;
        scanf("%d%d%d", &h, &w, &r);
        e[h][w] = r;
    }
    /* * 二分搜索
     * 匹配可能最大值为最大权重乘最多边数
     * [low, high] 为当前还可能是答案的区间
     */
    int low = 0, high = 1000 * n;
    while (low < high) {
        mid = (low + high) >> 1;
        cnt = 0; // 计数器归零
        dfs(1, 0);
        if (cnt >= t) high = mid;
        else low = mid + 1;
    }
    printf("%d\n", low);
}

#include<bits/stdc++.h>
using namespace std;
#define nn 22
vector<int> v[nn],c[nn];
int n,k,t;
struct node{
	int state;
	int val;
	int lst;
	int now;
	node (int a=0,int b=0,int c=0,int d=0)
	{
		state=a,val=b,lst=c,now=d;
	}
	void spread(priority_queue<node> &pq)
	{
		if(now==n) return ;
		for(int i=0;i<v[now].size();i++)
		{
			int j=v[now][i];
			if((1<<j)&state) continue;
			pq.push(node((1<<j)|state,val+c[now][i],1,now+1));
		}
		pq.push(node(state,val,0,now+1));
	}
};
bool operator<(node a,node b)
{
	return a.val>b.val;
}
priority_queue<node> pq;

int main()
{
	scanf("%d%d%d",&n,&k,&t);
	while(k--)
	{
		int x,y,w;scanf("%d%d%d",&x,&y,&w);x--,y--;
		v[x].push_back(y);c[x].push_back(w);
	}
	pq.push(node(0,0,1,0));
	while(1)
	{
		node nr=pq.top();pq.pop();
		nr.spread(pq);t-=nr.lst;
	//	cout<<nr.state<<nr.now<<"\n";
		if(t==0)
		{
			printf("%d\n",nr.val);
			return 0;
		}
	}
	puts("CYKA BLYAT!");
}

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <vector>
#include <cctype>
#include <string>
#include <ctime>
#include <cmath>
#include <set>
#include <map>

typedef long double LD;
typedef long long LL;

using namespace std;

#define sz(A) (A).size()
#define mp make_pair
#define pb push_back

const int N = 25;
int cost[N][N], n, k, t, perm[N], sum;
vector<int> pos;

int main() {
    cin >> n >> k >> t;
    for (int i = 0; i < k; i++) {
        int h, w;
        cin >> h >> w;
        h--, w--;
        cin >> cost[h][w];
    }

    int top = (1 << n);

    pos.pb(0);

    for (int i = 0; i < n; i++)
        perm[i] = i;

    do {
        for (int j = 1; j < top; j++) {

            bool ok = true;
            sum = 0;

            for (int i = 0, p = 1; i < n; i++, p *= 2) {
                if (!(p & j)) continue;
                if (!cost[i][ perm[i] ])
                    ok = false;
                sum += cost[i][ perm[i] ];
            }

            if (ok)
                pos.pb(sum);
        }
    }
    while (next_permutation(perm, perm + n));

    sort(pos.begin(), pos.end());
    cout << pos[t - 1] << endl;

    return 0;
}

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

using namespace std;

void ASS(bool bb)
{
    if (!bb)
    {
        ++*(int*)0;
    }
}

#define FOR(i, x) for (int i = 0; i < (int)(x); i++)
#define CL(x) memset(x, 0, sizeof(x))
#define CLX(x, y) memset(x, y, sizeof(x))

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

typedef vector<int> vi;

typedef long long LL;

const int K = 128;
int pwz[K];

struct S2
{
    LL x;
    S2()
    {
        x = 0;
    }
    void set(int x)
    {
        x += pwz[x];
    }
    bool operator < (const S2& s) const
    {
        return x < s.x;
    }
};

struct S
{
    int x;
    LL m;
    S2 s2;
    bool operator < (const S& s) const
    {
        return x > s.x;
    }
};

int main()
{
    pwz[0] = 1;
    FOR(i, K - 1)
        pwz[i + 1] = pwz[i] * 3731;

    int n, k, t;
    cin >> n >> k >> t;
    vector<S> v;
    FOR(i, k)
    {
        S s;
        int x, y;
        cin >> x >> y >> s.x;
        x--;
        y--;
        s.m = (1LL << x) + (1LL << (y + n));
        v.push_back(s);
    }
    sort(v.begin(), v.end());
    priority_queue<S> q;
    {
        S s;
        s.m = 0;
        s.x = 0;
        q.push(s);
    }
    map<S2, int> st;
    vi all;
    while (q.size() > 0 && st.size() < (1 << 19))
    {
        S s = q.top();
        q.pop();
        all.push_back(s.x);
        FOR(i, k)
            if ((s.m & v[i].m) == 0)
            {
                S t = s;
                t.m |= v[i].m;
                t.x += v[i].x;
                t.s2.set(i);
                int& g = st[t.s2];
                if (g == 0)
                {
                    g = 1;
                    q.push(t);
                }
            }
    }
    while (!q.empty()) {
        all.push_back(q.top().x);
        q.pop();
    }
    sort(all.begin(), all.end());
    cout << all[t - 1] << endl;
    return 0;
}

#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
typedef pair <int, int> pii;
typedef vector <int> vi;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
const int N = 17;
const int M = 1 << N;
int n, k, t, x, y, w, S;
int a[N][N], cnt[M];
multiset <short int> m[N][M];
vi ans, tmp;
int main()
{
  cin >> n >> k >> t;
  if (n > 15)
    return cout << "qwerty", 0;
  S = 1 << n;
  for(int i = 1; i < S; i++)
  {
    int x = i;
    while(x)
    {
      cnt[i] += x % 2;
      x /= 2;
    }
  }
  for(int i = 0; i < k; i++)
  {
    scanf("%d%d%d", &x, &y, &w);
    a[x - 1][y - 1] = w;
  }
  m[0][0].insert(0);
  for(int i = 0; i < n; i++)
    for(int j = 0; j < S; j++)
      if (cnt[j] <= i)
      {
        tmp.clear();
        for(multiset <short int> :: iterator q = m[i][j].begin(); q != m[i][j].end(); q++)
        {
          tmp.pb(*q);
          m[i + 1][j].insert(*q);
        }
        for(int q = 0; q < n; q++)
          if ((j & (1 << q)) == 0 && a[i][q])
          {
            int m1 = j | (1 << q);
            for(int z = 0; z < (int)tmp.size(); z++)
            {
              //cout << i + 1 << " " << m1 << " " << tmp[z] + a[i][q] << endl;
              m[i + 1][m1].insert(tmp[z] + a[i][q]);
            }
          }
      }
  for(int i = 0; i < S; i++)
    for(multiset <short int> :: iterator q = m[n][i].begin(); q != m[n][i].end(); q++)
      ans.pb(*q);
  sort(ans.begin(), ans.end());
  /*for(int i = 0; i < (int)ans.size(); i++)
    cout << ans[i] << " ";
  cout << endl;*/
  cout << ans[t - 1];
  return 0;
}

#include<iostream>
#include<list>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
using namespace std;

int grafo[20][20];
vector<int> sol;
bool assigned[20];
int N, k, t, peso=0;
void findSol(int chi)
{
	if(chi==N)
	{
		sol.push_back(peso);
		return;
	}
	findSol(chi+1);
	for(int i=0;i<N;i++)
		if(!assigned[i])
		{
			assigned[i]=true;
			peso+=grafo[chi][i];
			findSol(chi+1);
			assigned[i]=false;
			peso-=grafo[chi][i];
		}
}

int main(void)
{
	cin >> N >> k >> t;
	for(int i=0;i<k;i++)
	{
		int da, a, x;
		cin >> da >> a >> x;
		da--;a--;
		grafo[da][a]=x;
	}
	findSol(0);
	sort(sol.begin(), sol.end());
	//cout << sol.size() << endl;
	cout << sol[t-1];
	return 0;
}

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

using ll = long long;

int n, k, t;
vector<pair<ll,int>> edges;

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> n >> k >> t;
	edges.resize(k);
	for (int i = 0; i < k; i++) {
		int h, w, r;
		cin >> h >> w >> r;
		h--; w--;
		ll mask = ll(1) << h;
		mask |= ll(1) << (n+w);
		edges[i] = {r, mask};
	}
	sort(edges.begin(), edges.end());
	int s = -1, e = n * 1000;
	while (s+1 < e) {
		int mid = (s+e)/2;
		int tot = 1;
		function<void(int,int,ll)> enumerate = [&](int cur, int cur_cost, ll mask) {
			if (tot == t) return;
			if (cur == k) return;
			int new_cost = cur_cost + edges[cur].first;
			if (new_cost <= mid) {
				enumerate(cur+1, cur_cost, mask);
				if (tot < t && !(mask & edges[cur].second)) {
					tot += 1;
					enumerate(cur+1, new_cost, mask | edges[cur].second);
				}
			}
		};
		enumerate(0, 0, 0);
		if (tot == t) {
			e = mid;
		} else {
			s = mid;
		}
	}
	cout << e << '\n';
}

#include<bits/stdc++.h>
#define MP make_pair
#define R second
#define L first
using namespace std;
const int maxn=100000+100;
int a[maxn], b[maxn];
int d[maxn];

int main(){
	int n, m, p;
	cin >> n >> m >> p;
	for(int i=0;i<n;i++)
		cin >> a[i];
	for(int i=0;i<m;i++)
		cin >> b[i], d[i]+=b[i], d[n-m+i+1]-=b[i];
	for(int i=1;i<n;i++)
		d[i]+=d[i-1];
	for(int i=0;i<n;i++)
		cout << (a[i]+d[i])%p << " ";
	cout << endl;
}

# include<map>
# include<set>
# include<queue>
# include<stack>
# include<deque>
# include<math.h>
# include<vector>
# include<bitset>
# include<stdio.h>
# include<ctype.h>
# include<iostream>
# include<stdlib.h>
# include<string.h>
# include<algorithm>
# define si size
# define er erase
# define sc scanf
# define be begin
# define fr first
# define se second
# define pr printf
# define pb push_back
# define mp make_pair
# define INF 100000000
# define Int long long int
using namespace std;
int n, k, t, x, y, z, a[25][25], i, j, p, u[25];
vector<int>ans;
void rec(int l, int v)
{
    ans.pb(v);
    for(int i=l;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(!u[j])
            {
                u[j] = 1;
                rec(i+1, v+a[i][j]);
                u[j] = 0;
            }
        }
    }
}
main()
{
//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
sc("%d%d%d",&n,&k,&t);
for(i=0;i<k;i++)
{
    sc("%d%d%d",&x,&y,&z);
    a[x][y]=z;
}
rec(1,0);
sort(ans.be(), ans.end());
pr("%d\n",ans[t-1]);
return 0;
}

#pragma comment(linker, "/STACK:65777216")
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <queue>
#include <string>
#include <memory.h>
#include <iterator>
#define mem(A,X) memset(A,X,sizeof(A))
#define memo(A) memset(A,0,sizeof(A))
#define forn(I,B) for (int I=1;I<=(B);I++)
#define forg(H,V) for (int H=first[V];h;h=next[H])
#define rep(I,B) for (int I=0;I<(B);I++)
#define labs(X) (((X)>0)?(X):(-(X)))
#define ropen(X) freopen(X,"r",stdin)
#define wopen(X) freopen(X,"w",stdout)
#define rwopen(X) freopen(X".in","r",stdin);freopen(X".out","w",stdout)
#define pb push_back
#define mp make_pair
#define all(X) (X).begin(),(X).end()
#define sqr(X) ((X)*(X))

using namespace std;

typedef pair <int,int> pii;
typedef pair <long long,long long> pll;
typedef double ld;
typedef long long ll;
typedef vector<int> vi;
const int N=22;
const int INF=111111111;
const double eps=1e-9;
const double pi=3.14159265358979;

int n,k,ne,g[N][N],a[N],c;
pair<string,int> t[111111];

inline bool cmp(pair<string,int> a,pair<string,int> b){
	return a.second<b.second || a.second==b.second && a.first<b.first;
}

inline void check(){
	rep(msk,1<<n){
		forn(i,n) if ((msk&(1<<(i-1))) && !g[i][a[i]]) break;
		string f;
		int cur=0;
		forn(i,n) if (msk&(1<<(i-1))){
			f+=(char)('0'+i);
			f+=(char)('0'+a[i]);
			cur+=g[i][a[i]];
		}
		t[++c].first=f;
		t[c].second=cur;
	}
}

int main(){
	cin>>n>>k>>ne;
	forn(i,k){
		int a,b,c;
		cin>>a>>b>>c;
		g[a][b]=c;
	}
	forn(i,n) a[i]=i;
	do{
		check();
	} while (next_permutation(a+1,a+n+1));
	sort(t+1,t+c+1,cmp);
	int cur=1;
	forn(i,c){
		if (t[i].first!=t[i-1].first) ++cur;
		if (cur==ne){
			cout<<t[i].second<<endl;
			return 0;
		}
	}
	return 0;
}

#include <iostream>
#include <vector>
#include <queue>
#include <cstdio>
#include <cstdio>
#include <stack>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <ctime>
#include <math.h>
#include <cassert>

#define forn(i, n) for(int i=0;i<n;++i)
#define for1(i, n) for(int i=1;i<=n;++i)
#define forv(i, v) for(int i=0;i<v.size();++i)
#define sz(v) v.size()
#define all(v) v.begin(), v.end()
#define pb push_back
#define mp make_pair
#define ld double
#define li long long
#define X first
#define Y second
#define P (259)

using namespace std;

typedef pair <ld, ld> pt;
const li N = 105, M = 502,  INF = 1000*1000*1000 + 7;
const ld  eps = 1e-9;
const ld pi = 3.1415926535897932384626433832795;

struct node {
    int from;
    int to;
    int l;
};
bool operator <(node &a, node &b) {
    return a.l < b.l;
}

int p[N][N];
vector<node> a;

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

    int n,k,t;
    cin >> n >> k >> t;
    a.resize(k);
    forn(i, k) {
        int t, b, l;
        cin >> t >> b >> l;
        node tmp;
        tmp.from = t;
        tmp.to = b;
        tmp.l = l;
        a[i] = tmp;
    }
    sort(all(a));
    t--;
    if (!t) {
        cout << 0;
        return 0;
    }
    set<pair<int, pair<int, int>>> kit;
    forn(i, k) {
        int k1 = 0;
        int k2 = 0;
        k1 |= (1 << a[i].from);
        k2 |= (1 << a[i].to);
        kit.insert(mp(a[i].l, mp(k1, k2)));
    }
    vector<bool> us(k, 0);
    int cnt= 0;
    while (1) {
        int size = kit.size();
        forn(j, k) {
            bool ok = 0;
            if (us[j])
                continue;
            set<pair<int, pair<int, int>>> tmp;
            for(set<pair<int, pair<int, int>>>::iterator i = kit.begin(); i != kit.end(); i++) {
                int k1 = i->second.first;
                int k2 = i->second.second;
                if ((k1 & (1 << a[j].from)) > 0 || (k2 & (1 << a[j].to)) > 0)
                    continue;
                ok = 1;
                k1 |= (1 << a[j].from);
                k2 |= (1 << a[j].to);
                tmp.insert(mp(i->first + a[j].l, mp(k1, k2)));
            }
            for(set<pair<int, pair<int, int>>>::iterator i = tmp.begin(); i != tmp.end(); i++)
                kit.insert(*i);
            if (!ok)  {
                us[j] = 1;
                cnt++;
            }
        }
        if (size == kit.size())
            break;
    }
    int j=t;
    for(set<pair<int, pair<int, int>>>::iterator i = kit.begin(); i != kit.end(); i++) {
        j--;
        if (j == 0) {
            cout << i->first;
            return 0;
        }
    }

    return 0;
}

#include <iostream>
#include <vector>
#include <queue>
#include <cstdio>
#include <cstdio>
#include <stack>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <ctime>
#include <math.h>
#include <cassert>

#define forn(i, n) for(int i=0;i<n;++i)
#define for1(i, n) for(int i=1;i<=n;++i)
#define forv(i, v) for(int i=0;i<v.size();++i)
#define sz(v) v.size()
#define all(v) v.begin(), v.end()
#define pb push_back
#define mp make_pair
#define ld double
#define li long long
#define X first
#define Y second
#define P (259)

using namespace std;

typedef pair <ld, ld> pt;
const li N = 105, M = 502,  INF = 1000*1000*1000 + 7;
const ld  eps = 1e-9;
const ld pi = 3.1415926535897932384626433832795;

int p[N][N];

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

    int n,k,t;
    cin >> n >> k >> t;
    forn(i, k) {
        int t, b, l;
        cin >> t >> b >> l;
        p[t-1][b-1] = l;
    }
    vector<int> girl(n);
    forn(i, n)
        girl[i] = i;
    t--;
    if (!t) {
        cout << 0;
        return 0;
    }

    vector<int> ans;

    do {
        for1(mask, (1 << n) - 1) {
            int tmp = 0;
            forn(i, n) {
                if ((mask & (1 << i)) && p[i][girl[i]]) {
                    tmp += p[i][girl[i]];
                }
            }
            ans.pb(tmp);
        }
    }while (next_permutation(all(girl)));

    sort(all(ans));
    cout << ans[t-1];

    return 0;
}

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

using namespace std;

void ASS(bool bb)
{
    if (!bb)
    {
        ++*(int*)0;
    }
}

#define FOR(i, x) for (int i = 0; i < (int)(x); i++)
#define CL(x) memset(x, 0, sizeof(x))
#define CLX(x, y) memset(x, y, sizeof(x))

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

typedef vector<int> vi;

typedef long long LL;

struct S
{
    int x;
    LL m;
    bool operator < (const S& s) const
    {
        return x < s.x;
    }
};

int main()
{
    int n, k, T;
    cin >> n >> k >> T;
    vector<S> v;
    FOR(i, k)
    {
        S s;
        int x, y;
        cin >> x >> y >> s.x;
        x--;
        y--;
        s.m = (1LL << x) + (1LL << (y + n));
        v.push_back(s);
    }
    sort(v.begin(), v.end());
    vector<S> q;
    {
        S s;
        s.m = 0;
        s.x = 0;
        q.push_back(s);
    }
    FOR(z, k)
    {
        vector<S> q2 = q;
        FOR(i, q.size())
            if (0 == (v[z].m & q[i].m)) {
                S t = q[i];
                t.m |= v[z].m;
                t.x += v[z].x;
                q2.push_back(t);
            }
        sort(q2.begin(), q2.end());
        vector<S> res(q.size() + q2.size());
        merge(q.begin(), q.end(), q2.begin(), q2.end(), res.begin());
        if (res.size() > T)
            res.resize(T);
        q = res;
    }
    cout << q[T - 1].x << endl;
    return 0;
}

//mohem tarin kar ine ke bekeshi be ham
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define X first
#define Y second
const int maxN=1e5+12;
const int INF=1e18+12;
const int Inf=1e9+12;

int a[10][10],n,k,t;
vector<int>v;
bool f[10];

void make(int cnt,int pos=1,int k=0,int val=0){
  //cout<<pos<<endl;
  if(pos==n+1&&k==cnt){
    v.push_back(val);
    return ;
  }
  if(pos>n)return ;
  make(cnt,pos+1,k,val);
  for(int i=1;i<=n;i++){
    if(a[pos][i]&&!f[i]&&k<cnt){
      f[i]=true;
      make(cnt,pos+1,k+1,val+a[pos][i]);
      f[i]=false;
    }
  }
}

int32_t main(){
   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
   cin>>n>>k>>t;
   for(int i=0;i<k;i++){
     int x,y,val;
     cin>>x>>y>>val;
     a[x][y]=val;
   }
   for(int i=1;i<=n;i++)make(i);
   sort(v.begin(),v.end());
   cout<<v[t-2]<<endl;
}

#include <iostream>
#include <vector>
#include <queue>
#include <cstdio>
#include <cstdio>
#include <stack>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <ctime>
#include <math.h>
#include <cassert>

#define forn(i, n) for(int i=0;i<n;++i)
#define for1(i, n) for(int i=1;i<=n;++i)
#define forv(i, v) for(int i=0;i<v.size();++i)
#define sz(v) v.size()
#define all(v) v.begin(), v.end()
#define pb push_back
#define mp make_pair
#define ld double
#define li long long
#define X first
#define Y second
#define P (259)

using namespace std;

typedef pair <ld, ld> pt;
const li N = 105, M = 502,  INF = 1000*1000*1000 + 7;
const ld  eps = 1e-9;
const ld pi = 3.1415926535897932384626433832795;

int p[N][N];

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

    int n,k,t;
    cin >> n >> k >> t;
    forn(i, k) {
        int t, b, l;
        cin >> t >> b >> l;
        p[t-1][b-1] = l;
    }
    vector<int> girl(n);
    forn(i, n)
        girl[i] = i;
    t--;
    if (!t) {
        cout << 0;
        return 0;
    }

    vector<int> ans;
    for1(mask, (1 << n) - 1) {
        set<vector<pair<int, int>>> us;
        do {
            int tmp = 0;
            vector<pair<int, int>> edges;
            forn(i, n) {
                if ((mask & (1 << i)) && p[i][girl[i]]) {
                    edges.pb(mp(i, girl[i]));
                    tmp += p[i][girl[i]];
                }
            }
            if (!us.count(edges)) {
                ans.pb(tmp);
                us.insert(edges);
            }
        }while (next_permutation(all(girl)));
    }

    sort(all(ans));
    cout << ans[t-1];

    return 0;
}

// In the name of God

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <complex>
#include <cmath>
#include <fstream>
#include <iomanip>

using namespace std;

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

const int maxn = 20 + 2;

vector<int> v;
int n,k,t;
int d[maxn][maxn];
int vis[maxn];

const vector<int> make(int start,int w)
{
  vector<int> ret;
  if(start == n){
    ret.push_back(d[start][w]);
    return ret;
  }
  for(int i=0;i<=n;++i)
    if(vis[i] == 0 || i == 0){
      vis[i] = 1;
      vector<int> help;
      help = make(start + 1 , i);
      vis[i] = 0;
      for(int j=0;j<help.size();++j)
	ret.push_back(help[j] + d[start][w]);
    }
  return ret;
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin >> n >> k >> t;
  for(int i=0;i<k;++i){
    int v1,v2,w;
    cin >> v1 >> v2 >> w;
    d[v1][v2] = w;
  }

  for(int i=0;i<=n;++i)  {
    vis[i] = 1;
    vector<int> help = make(1,i);
    vis[i] = 0;
    for(int j=0;j<help.size();++j)
      v.push_back(help[j]);
  }

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

  cout << v[t-1] << endl;

  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 a[101];
int b[101];
map<pair<int,int>,int> c;
set<pair<int,int> >was;
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n,k,t;
    cin>>n>>k>>t;
    for(int i=1;i<=k;i++)
    {
        int x,y,z;
        cin>>x>>y>>z;
        x--;
        y--;
        a[i]=x;
        b[i]=y;
        c[mp(x,y)]=z;
        was.insert(mp(x,y));
    }

    vector<int>kol;
    kol.pb(0);
    for(int l=0;l<(1<<n);l++)
    {
        int g[10];

        for(int j=0;j<n;j++)
            g[j]=j;

        do{
            int tek=0;
            bool fl=1;
            int p=0;
            for(int i=0;i<n;i++)
            {
                if(((l>>i) & 1) == 0)
                    continue;
                p++;
                if(was.count(mp(i,g[i]))==0)
                    fl=0;
                tek+=c[mp(i,g[i])];
                //cout<<l<<' '<<tek<<endl;
            }
            if(fl && p)
                kol.pb(tek);
        }
        while (next_permutation(g,g+n));
    }
    sort(all(kol));
    //cout<<kol.size()<<endl;
    /*for(int i=0;i<kol.size();i++)
        cout<<kol[i]<<' ';
    cout<<endl;*/
    cout<<kol[t-1]<<endl;
    return 0;
}

#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <utility>
#include <string>
#include <string.h>
#include <map>
#include <locale>
#include <math.h>

#define frup(FRUP_I,FROM,TO) for(long FRUP_I=FROM;FRUP_I<=TO;FRUP_I++)
#define frdn(FRDN_I,FROM,TO) for(long FRDN_I=FROM;FRDN_I<TO;FRDN_I++)

#define pub(VALUE) push_back(VALUE)
#define pob() pop_back()
#define mp(FST,SEC) make_pair(FST,SEC)
#define len(STR) STR.length()

#define IN "input.txt"
#define OUT "output.txt"

#define refresh(ARRAY,TARGET,VALUE) frdn(DEFINED_I,0,TARGET)ARRAY[DEFINED_I]=VALUE
#define watch(VALUE) {cout<<#VALUE;printf("=");cout<<VALUE;printf("\n");}
#define stop exit(0)

using namespace std;

typedef pair<long,long> ll;

const long INF=(long)1e09;

struct node{
       int h,w,r;
       };

int n,m,j,k,ans=0,c,t,z,next=0;
vector<int>all,a(30,0);
set<int>hus,wiw;
vector<node>d;

bool comp(node a, node b){
 return a.r>b.r;
}

int main(){
   // freopen(IN,"r",stdin);
   // freopen(OUT,"w",stdout);
      scanf("%d %d %d",&n,&k,&t);
      node l;
      l.h=0;
      l.w=0;
      l.r=0;
       d.pub(l);
       frup(i,1,k){
                   int x,y,z;
                    scanf("%d %d %d",&x,&y,&z);
                      node l;
      l.h=x;
      l.w=y;
      l.r=z;
                    d.pub(l);
                   }

sort(d.begin()+1,d.end(),comp);

  while(true){
              hus.clear();
              wiw.clear();
               long res=0;
               bool f=1;
                frup(i,1,k)
                  if(a[i]>0){
                            if(hus.count(d[i].h)||wiw.count(d[i].w)){
                                                                 f=0;
                                                                 break;
                                                                 }
                              hus.insert(d[i].h);
                              wiw.insert(d[i].w);
                              res+=d[i].r;
                            }
               if(f)all.pub(res);
               if(all.size()>t*2){
                                  sort(all.begin(),all.end());
printf("%d",all[t-1]);
return 0;
                                  }
               a[k]++;
               z=k;
                while(z>0){
                           if(a[z]>1){
                                      a[z-1]++;
                                      a[z]=0;
                                      }
                             z--;
                           }
               if(a[0])break;
              }
sort(all.begin(),all.end());
printf("%d",all[t-1]);
return 0;
}

# include<map>
# include<set>
# include<queue>
# include<stack>
# include<deque>
# include<math.h>
# include<vector>
# include<bitset>
# include<stdio.h>
# include<ctype.h>
# include<iostream>
# include<stdlib.h>
# include<string.h>
# include<algorithm>
# define si size
# define er erase
# define sc scanf
# define be begin
# define fr first
# define se second
# define pr printf
# define pb push_back
# define mp make_pair
# define INF 100000000
# define Int long long int
using namespace std;
int n, k, t, l, x, y, z, a[25][25], i[5], j[5], p, u[25];
vector<int>ans;
main()
{
//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
sc("%d%d%d",&n,&k,&t);
for(i[0]=0;i[0]<k;i[0]++)
{
    sc("%d%d%d",&x,&y,&z);
    a[x][y]=z;
}
ans.pb(0);
p=0;
for(i[0]=1;i[0]<=n;i[0]++)
    for(j[0]=1;j[0]<=n;j[0]++)
        if(a[i[0]][j[0]]!=0)
        {
            u[j[0]] = 1;
            p=a[i[0]][j[0]];
            ans.pb(p);
            if(n>1)
                for(i[1]=i[0]+1;i[1]<=n;i[1]++)
                    for(j[1]=1;j[1]<=n;j[1]++)
                        if(!u[j[1]]&&a[i[1]][j[1]]!=0)
                        {
                            u[j[1]] = 1;
                            p+=a[i[1]][j[1]];
                            ans.pb(p);
                            if(n>2)
                                for(i[2]=i[1]+1;i[2]<=n;i[2]++)
                                    for(j[2]=1;j[2]<=n;j[2]++)
                                        if(!u[j[2]]&&a[i[2]][j[2]]!=0)
                                        {
                                            u[j[2]] = 1;
                                            p+=a[i[2]][j[2]];
                                            ans.pb(p);
                                            if(n>3)
                                                for(i[3]=i[2]+1;i[3]<=n;i[3]++)
                                                    for(j[3]=1;j[3]<=n;j[3]++)
                                                        if(!u[j[3]]&&a[i[3]][j[3]]!=0)
                                                        {
                                                            u[j[3]] = 1;
                                                            p+=a[i[3]][j[3]];
                                                            ans.pb(p);
                                                            if(n>4)
                                                                for(i[4]=i[3]+1;i[4]<=n;i[4]++)
                                                                    for(j[4]=1;j[4]<=n;j[4]++)
                                                                        if(!u[j[4]]&&a[i[4]][j[4]]!=0)
                                                                        {
                                                                            u[j[4]] = 1;
                                                                            p+=a[i[4]][j[4]];
                                                                            ans.pb(p);
                                                                            u[j[4]] = 0;
                                                                        }
                                                            u[j[3]] = 0;
                                                        }
                                            u[j[2]] = 0;
                                        }
                            u[j[1]] = 0;

                        }
            u[j[0]] = 0;
        }
sort(ans.be(),ans.end());/*
for(i[0]=0;i[0]<ans.si();i[0]++)
{
    pr("%d\n",ans[i[0]]);
}*/
pr("%d\n",ans[t-1]);
return 0;
}

// In the name of God

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <complex>
#include <cmath>
#include <fstream>
#include <iomanip>

using namespace std;

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

const int maxn = 20 + 2;

vector<int> v;
int n,k,t;
int d[maxn][maxn];
int vis[maxn];

inline vector<int> make(int start,int w)
{
  vector<int> ret;
  if(start == n){
    ret.push_back(d[start][w]);
    return ret;
  }
  for(int i=0;i<=n;++i)
    if(vis[i] == 0 || i == 0){
      vis[i] = 1;
      vector<int> help;
      help = make(start + 1 , i);
      vis[i] = 0;
      for(int j=0;j<help.size();++j)
	ret.push_back(help[j] + d[start][w]);
    }
  return ret;
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin >> n >> k >> t;
  for(int i=0;i<k;++i){
    int v1,v2,w;
    cin >> v1 >> v2 >> w;
    d[v1][v2] = w;
  }

  for(int i=0;i<=n;++i)  {
    vis[i] = 1;
    vector<int> help = make(1,i);
    vis[i] = 0;
    for(int j=0;j<help.size();++j)
      v.push_back(help[j]);
  }

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

  cout << v[t-1] << endl;

  return 0;
}

#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <set>
#include <map>
#include <algorithm>

#define sz(a) int((a).size())
#define tr(c, i) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(c) (c).begin(),(c).end()
#define INF 2000000000
#define EPS 1e-5
#define PB push_back
#define MP make_pair
#define S second
#define F first
#define X first
#define Y second
#define DEBUG(x) printf("debugging.. %d\n", x);
using namespace std;

typedef long long ll;
typedef pair <int, int> ii;

int n, k, t;
vector <ii> mg[6];
int memo[1000005] = {0}, wused[6] = {0};

void solve(int man, int tot) {
//	printf("solve(%d,%d)\n", man, tot);
	if(man == n) {
		memo[tot] = 1;
		return;
	}

	solve(man + 1, tot);	// skip this man

	for(int j = 0; j < sz(mg[man]); ++j) {
		int woman = mg[man][j].F, v = mg[man][j].S;
		if(wused[woman]) continue;

		// coba pasangkan man dgn woman
		wused[woman] = 1;
		solve(man + 1, tot + v);
		wused[woman] = 0;
	}
}

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

	for(int i = 0; i < k; ++i) {
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);

		a--; b--;

		mg[a].PB(ii(b, c));
	}
//	puts("hello");
	solve(0, 0);

	vector <int> psb;
	for(int i = 0; i < 1000000; ++i)
		if(memo[i]) psb.PB(i);

	printf("%d\n", psb[t-1]);

	return 0;
}

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

int n, k, t;
int h[101], w[101], r[101];
bool va[5], vb[5];

int main() {
//freopen("input.txt", "r", stdin);
    cin >> n >> k >> t;
    for (int i = 0; i < k; i++) {
        cin >> h[i] >> w[i] >> r[i];
        h[i]--;
        w[i]--;
    }

    int maxB = 1 << k;
    vector<int> v;
    for (int mask = 0; mask < maxB; mask++) {
        memset(va, false, sizeof(va));
        memset(vb, false, sizeof(vb));
        bool ok = true;
        int tot = 0;
        for (int i = 0; i < k; i++) {
            if (mask & (1 << i)) {
                if (va[h[i]] || vb[w[i]]) {
                    ok = false;
                    break;
                }
                tot += r[i];
                va[h[i]] = true;
                vb[w[i]] = true;
            }
        }
        if (ok) v.push_back(tot);
    }
    cout << v[t - 1] << endl;
    return 0;
}

#include <cstdio>
#include <set>
#include <vector>
using namespace std;

const int Maxn = 25;

int n, k, t;
vector <int> w[Maxn], r[Maxn];
bool taken[Maxn];
multiset <int> res;

void Gen(int v, int l, int d)
{
    if (!l) {
        if (res.size() < t) res.insert(d);
        else if (d < *res.rbegin()) { res.erase(res.find(*res.rbegin())); res.insert(d); }
    } else for (int i = v; i <= n; i++)
              for (int j = 0; j < w[i].size(); j++) if (!taken[w[i][j]]) {
                  taken[w[i][j]] = true;
                  Gen(i + 1, l - 1, d + r[i][j]);
                  taken[w[i][j]] = false;
              }
}

int main()
{
    scanf("%d %d %d", &n, &k, &t);
    while (k--) {
        int hi, wi, ri; scanf("%d %d %d", &hi, &wi, &ri);
        w[hi].push_back(wi); r[hi].push_back(ri);
    }
    int sum = 1;
    int i;
    for (i = 0; i <= n; i++)
        if (t <= sum) break;
        else {
            t -= sum;
            sum = sum * (n - i) * (n - i) / (i + 1);
        }
    Gen(1, i, 0);
    printf("%d\n", *res.rbegin());
    return 0;
}

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <math.h>
using namespace std;
typedef unsigned short us;
typedef unsigned int ui;
typedef long long i64;
typedef unsigned long long ui64;
long n,k,t,h,w,r;
us be[30];us bew[30];
ui64 z=0;
class marry{
public:
	int m;int w;int r;
	marry(int m1,int w1,int r1){m=m1;w=w1;r=r1;}
	bool operator<(const marry* mm){return r<mm->r;}
};
bool cmp(marry* m1,marry* m2){return m1->r<m2->r;}
vector<marry*> a;
vector<ui64> b;
int main(){
#ifndef ONLINE_JUDGE
	freopen("input.txt","rt",stdin);freopen("output.txt","wt",stdout);
#endif

	cin>>n>>k>>t;long long g=(long long)pow((double)2,(double)k);
	for(int i=1;i<=k;i++){cin>>h>>w>>r;a.push_back(new marry(h,w,r));}
	//sort(a.begin(),a.end(),&cmp);
	long j=0;long p=0;
	do{
		long d=j++;bool f=true;z=0;
		memset(be,0,sizeof(be));
		memset(bew,0,sizeof(bew));
		for(long i=0;i<a.size() && d>0;i++){
			long tt=d%2;d/=2;
			if(tt){
				z+=a[i]->r;
				if(be[a[i]->m] || bew[a[i]->w]){f=false;break;}
				be[a[i]->m]=1;bew[a[i]->w]=1;
			}
		}
		if(f){
			b.push_back(z);p++;
			//cout<<j-1<<' '<<z<<endl;
		}
	}while((p<k+3||p<t) && j<g);
	sort(b.begin(),b.end());
	cout<<b[t-1];
	return 0;
}

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

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define PI 3.14159265358979
#define forn(i, n) for(int i = 0; i < n; ++i)
#define ALL(x) x.begin(), x.end()
#define L(s) (int)((s).size())
#define ms(x) memset(x,0,sizeof(x))
#define del(y,x) erase(y.begin()+x)

typedef long long ll;
using namespace std;
typedef pair<int,int> pii;
const int INF = 2147483647;
const ll LLINF = 9223372036854775807LL;
const int ST = 100010;
const int ST1 = 1000010;
const ll MOD = 1000000007;

ll ABS(ll a)
{
	if(a<0)
		return a*(-1);
	else
		return a;
}

vector<ll> pr;
vector<ll> cost;
bool used[7];
bool used2[7];
vector<vector<pii> > vv(7);
ll ans = 0;
int n;

void dfs(int v,int p,ll sum)
{
	used[v] = true;
	used2[p] = true;
	for(int i = 0;i < n;i++)
	{
		if(!used[i])
		{
			for(int j = 0;j < L(vv[i]);j++)
				if(!used2[vv[i][j].X])
					dfs(i,vv[i][j].X,sum+vv[i][j].Y);
		}
	}
	used[v] = false;
	used2[p] = false;
	pr.pb(sum);
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
	int k,t;
	cin >> n >> k >> t;
	pr.pb(0);
	pr.pb(0);
	t--;
	for(int i = 0;i < k;i++)
	{
		int a,b,c;
		cin >> a >> b >> c;
		a--;b--;
		vv[a].pb(mp(b,c));
	}
	for(int i = 0;i < n;i++)
	{
		for(int j = 0;j < L(vv[i]);j++)
		{
			used[i] = true;
			used2[vv[i][j].X] = true;
			dfs(i,vv[i][j].X,vv[i][j].Y);
			used[i] = false;
			used2[vv[i][j].X] = false;
			pr.pb(vv[i][j].Y);
		}
	}
	t*=2;
	sort(ALL(pr));
	//vector<int>::iterator it = unique (pr.begin(), pr.end());
	//pr.resize( it - pr.begin() );
	cout << pr[t];
}

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

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define PI 3.14159265358979
#define forn(i, n) for(int i = 0; i < n; ++i)
#define ALL(x) x.begin(), x.end()
#define L(s) (int)((s).size())
#define ms(x) memset(x,0,sizeof(x))
#define del(y,x) erase(y.begin()+x)

typedef long long ll;
using namespace std;
typedef pair<int,int> pii;
const int INF = 2147483647;
const ll LLINF = 9223372036854775807LL;
const int ST = 100010;
const int ST1 = 1000010;
const ll MOD = 1000000007;

ll ABS(ll a)
{
	if(a<0)
		return a*(-1);
	else
		return a;
}

vector<int> pr;
vector<int> cost;
bool used[6];
bool used2[6];
vector<vector<pii> > vv(6);
ll ans = 0;
int n;

void dfs(int v,int p,int sum)
{
	used[v] = true;
	used2[p] = true;
	for(int i = 0;i < n;i++)
	{
		if(!used[i])
		{
			for(int j = 0;j < L(vv[i]);j++)
				if(!used2[vv[i][j].X])
					dfs(i,vv[i][j].X,sum+vv[i][j].Y);
		}
	}
	used[v] = false;
	used2[p] = false;
	pr.pb(sum);
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
	int k,t;
	cin >> n >> k >> t;
	pr.pb(0);
//	pr.pb(0);
	t--;
	for(int i = 0;i < k;i++)
	{
		int a,b,c;
		cin >> a >> b >> c;
		a--;b--;
		vv[a].pb(mp(b,c));
	}
	for(int i = 0;i < n;i++)
	{
		for(int j = 0;j < L(vv[i]);j++)
		{
			used[i] = true;
			used2[j] = true;
			dfs(i,vv[i][j].X,vv[i][j].Y);
			used[i] = false;
			used2[j] = false;
//			pr.pb(vv[i][j].Y);
		}
	}
//	t*=2;
	sort(ALL(pr));
	vector<int>::iterator it = unique (pr.begin(), pr.end());
	pr.resize( it - pr.begin() );
	cout << pr[t];
}

#include<iostream>
#include<vector>
#include<queue>
#include<functional>
#define f first
#define s second
#define mp make_pair
using namespace std;

struct Edge {
	int h, w, r;
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n, k, t;
	cin >> n >> k >> t;

	//Now the edges
	vector<Edge> edges(k);
	for(int i=0;i<k;i++)
		cin >> edges[i].h >> edges[i].w >> edges[i].r;

	//Now the front
	//format: (cost, (taken, edgeIndex) )
	priority_queue<pair<int, pair<long long, int> >, vector<pair<int, pair<long long, int> > >,
				greater<pair<int, pair<long long, int> > > > front;

	front.push( mp(0, mp(0, 0) ) );

	while(front.size() > 0) {

		auto cur = front.top();
		front.pop();

		t--;
		if(t == 0) {
			cout << cur.f << '\n';
			return 0;
		}

		for(int i=cur.s.s; i < k;i++) {
			auto& ce = edges[i];

			if( (cur.s.f & (1<<ce.h)) == 0 && (cur.s.f & (1<<(20+ce.w))) == 0) {
				front.push(mp(cur.f + ce.r, mp(cur.s.f + (1<<ce.h) + (1<<(20+ce.w)), i+1) ) );
			}
		}
	}

	return 0;
}

#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
typedef pair <int, int> pii;
typedef vector <int> vi;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
const int N = 15;
const int M = 1 << N;
int n, k, t, x, y, w, S;
int a[N][N], cnt[M];
multiset <short int> m[N][M];
vi ans, tmp;
int main()
{
  cin >> n >> k >> t;
  if (n > 15)
    return cout << "qwerty", 0;
  S = 1 << n;
  for(int i = 1; i < S; i++)
  {
    int x = i;
    while(x)
    {
      cnt[i] += x % 2;
      x /= 2;
    }
  }
  for(int i = 0; i < k; i++)
  {
    scanf("%d%d%d", &x, &y, &w);
    a[x - 1][y - 1] = w;
  }
  m[0][0].insert(0);
  for(int i = 0; i < n; i++)
    for(int j = 0; j < S; j++)
      if (cnt[j] <= i)
      {
        tmp.clear();
        for(multiset <short int> :: iterator q = m[i][j].begin(); q != m[i][j].end(); q++)
        {
          tmp.pb(*q);
          m[i + 1][j].insert(*q);
        }
        for(int q = 0; q < n; q++)
          if ((j & (1 << q)) == 0 && a[i][q])
          {
            int m1 = j | (1 << q);
            for(int z = 0; z < (int)tmp.size(); z++)
            {
              //cout << i + 1 << " " << m1 << " " << tmp[z] + a[i][q] << endl;
              m[i + 1][m1].insert(tmp[z] + a[i][q]);
            }
          }
      }
  for(int i = 0; i < S; i++)
    for(multiset <short int> :: iterator q = m[n][i].begin(); q != m[n][i].end(); q++)
      ans.pb(*q);
  sort(ans.begin(), ans.end());
  /*for(int i = 0; i < (int)ans.size(); i++)
    cout << ans[i] << " ";
  cout << endl;*/
  cout << ans[t - 1];
  return 0;
}

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

using ll = long long;

int n, k, t;
vector<pair<ll,int>> edges;

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> n >> k >> t;
	edges.resize(k);
	for (int i = 0; i < k; i++) {
		int h, w, r;
		cin >> h >> w >> r;
		h--; w--;
		ll mask = ll(1) << h;
		mask |= ll(1) << (n+w);
		edges[i] = {r, mask};
	}
	sort(edges.begin(), edges.end());
	int s = -1, e = n * 1000;
	while (s+1 < e) {
		int mid = (s+e)/2;
		int tot = 1;
		function<void(int,int,ll)> enumerate = [&](int cur, int cur_cost, ll mask) {
			if (tot == t) return;
			if (cur == k) return;
			int new_cost = cur_cost + edges[cur].first;
			if (new_cost <= mid) {
				enumerate(cur+1, cur_cost, mask);
				if (tot < t && !(mask & edges[cur].second)) {
					tot += 1;
					enumerate(cur+1, new_cost, mask | edges[cur].second);
				}
			}
		};
		enumerate(0, 0, 0);
		if (tot == t) {
			e = mid;
		} else {
			s = mid;
		}
	}
	cout << e << '\n';
}

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

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define PI 3.14159265358979
#define forn(i, n) for(int i = 0; i < n; ++i)
#define ALL(x) x.begin(), x.end()
#define L(s) (int)((s).size())
#define ms(x) memset(x,0,sizeof(x))
#define del(y,x) erase(y.begin()+x)

typedef long long ll;
using namespace std;
typedef pair<int,int> pii;
const int INF = 2147483647;
const ll LLINF = 9223372036854775807LL;
const int ST = 100010;
const int ST1 = 1000010;
const ll MOD = 1000000007;

ll ABS(ll a)
{
	if(a<0)
		return a*(-1);
	else
		return a;
}

vector<int> pr;
vector<int> cost;
bool used[6];
bool used2[6];
vector<vector<pii> > vv(6);
ll ans = 0;
int n;

void dfs(int v,int p,int sum)
{
	used[v] = true;
	used2[p] = true;
	for(int i = 0;i < n;i++)
	{
		if(!used[i])
		{
			for(int j = 0;j < L(vv[i]);j++)
				if(!used2[vv[i][j].X])
					dfs(i,vv[i][j].X,sum+vv[i][j].Y);
		}
	}
	used[v] = false;
	used2[p] = false;
	pr.pb(sum);
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
	int k,t;
	cin >> n >> k >> t;
	pr.pb(0);
	pr.pb(0);
	t--;
	for(int i = 0;i < k;i++)
	{
		int a,b,c;
		cin >> a >> b >> c;
		a--;b--;
		vv[a].pb(mp(b,c));
	}
	for(int i = 0;i < n;i++)
	{
		for(int j = 0;j < L(vv[i]);j++)
		{
			//used[i] = true;
			//used2[j] = true;
			dfs(i,vv[i][j].X,vv[i][j].Y);
			//used[i] = false;
			//used2[j] = false;
			pr.pb(vv[i][j].Y);
		}
	}
	sort(ALL(pr));
	vector<int>::iterator it = unique (pr.begin(), pr.end());
	pr.resize( it - pr.begin() );
	cout << pr[t];
}

#include <bits/stdc++.h>

using namespace std;

#include <ext/rope>

using namespace __gnu_cxx;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;

#define int long long

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;

#define add push_back
#define rem pop_back
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REV(x) reverse(ALL(x))
#define F first
#define S second
#define DEBUG(x) cout << #x << " " << x << endl;
#define forn(i, a, b) for(int i = a; i <= b; i++)

template<typename T1, typename T2> auto max ( T1 a, T2 b ) { auto max = a > b ? a : b; return max; }
template<typename T1, typename T2> auto min ( T1 a, T2 b ) { auto min = a < b ? a : b; return min; }
template<typename T1, typename T2> void updmax ( T1 &a, T2 b ) { a = a > b ? a : b; }
template<typename T1, typename T2> void updmin ( T1 &a, T2 b ) { a = a < b ? a : b; }

const double EPS = 1e-9;
const double PI = acos ( -1. );
const int mod = 1e9 + 7;
int inf = __INT64_MAX__;
string YN[] = {"NO", "YES"};

#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a)*((b)/gcd(a,b)))

inline int gcd_e( int a, int b, int & x, int & y )
{
        if ( !a ) {
                x = 0;
                y = 1;
                return b;
        }
        int x1, y1;
        int d = gcd_e ( b % a, a, x1, y1 );
        x = y1 - ( b / a ) * x1;
        y = x1;
        return d;
}

inline int div_mod( int a, int b, int m = mod )
{
        int x, y;
        int g = gcd_e( b, m, x, y );
        x = ( x % m + m ) % m;
        return ( a * x ) % m;
}

int pow_mod ( int a, int n, int m = mod )
{
        int res = 1;
        while ( n ) {
                if ( n & 1 )
                        res = ( res * a ) % m;
                a = ( a * a ) % m;
                n >>= 1;
        }
        return res;
}

int px[] = { 1, -1, 0, 0 };
int py[] = { 0, 0, -1, 1 };
int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
int dy[] = { 0, 1, 0, -1, 1, -1, 1, -1 };

//tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> tr;

static const int MAXN = 1 << 20;
static int a[MAXN], b[MAXN], p[MAXN], c[20][20];

int n, m, k;
int res, cnt[MAXN];
string s;

vector<int> ans;
vector<int> used;
void rec( int i, int s, vector<int> used ){

	if( i == n ){
		ans.add( s );
		return;
	}
	rec( i + 1, s, used );
	for( int j = 0; j < n; j++ )
		if( !used[j] ){
			used[j] = 1;
			rec( i + 1, s + c[i][j], used );
			used[j] = 0;
		}
}
void solution()
{
	cin >> n >> m >> k;
	used.resize( n, 0 );
	while( m-- ){
		int x, y, w;
		cin >> x >> y >> w;
		x--;
		y--;
		c[x][y] = w;
	}
	rec( 0, 0, used );
	sort( ALL( ans ) );
	cout << ans[k - 1] << endl;
}

int32_t main ( )
{

        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);

        ios_base::sync_with_stdio ( false ); cin.tie ( nullptr ); cout.tie ( nullptr );
        //cout.precision(15);

        int query = 1;
        // cin >> query;

        while ( query-- ) solution();

        return 0;

}

#include <cstdio>
#include <sstream>
#include <iostream>

#include <set>
#include <map>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <cstring>

#include <ctime>
#include <cmath>
#include <cstdlib>
#include <algorithm>
using namespace std;

#define REP(i,n) for (int i = 0; i < (n); ++i)
#define FOR(i,a,b) for (int i = (a); b; ++i)
#define REPI(i,c) for (typeof(c.begin()) i = c.begin(); i != c.end(); ++i)
#define ALL(c) c.begin(), c.end()
#define SZ(x) ((int)(x).size())

#define DB(x) cout << #x << " = " << x << endl;

const int MAX = 25;

int N, K, T;
int m[MAX], w[MAX], a[MAX];
int um[MAX], uw[MAX];
multiset<int> S;

int main()
{
    ios::sync_with_stdio(false);

    cin >> N >> K >> T;

    REP(i, K)
    {
        cin >> m[i] >> w[i] >> a[i];
        --m[i];
        --w[i];
    }

    int dt = 0;
    REP(i, 1<<K)
    {
        int p = 0;
        ++dt;

        REP(j, K)
            if (i & (1 << j))
            {
                p += a[j];
                //DB(m[j]);
                //DB(w[j]);
                if (um[ m[j] ] == dt) goto err;
                if (uw[ w[j] ] == dt) goto err;
                um[ m[j] ] = dt;
                uw[ w[j] ] = dt;
            }

        if (SZ(S) < T)
            S.insert(p);
        else
        {
            int w = *S.rbegin();
            if (w > p)
            {
                S.erase(w);
                S.insert(p);
            }
        }

        err:;
    }

    int ans;
    while (T--) ans = *S.begin(), S.erase(S.begin());

    //REPI(i, S) DB(*i);

    cout << ans << endl;

    return 0;
}// (++UH)++ :: agarwaen

#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;

#define PB push_back
#define MP make_pair

#define rep(i,n) for(int i=0;i<(n);++i)
#define REP(i,n) for(int i=1;i<=(n);++i)
#define FOR(i,l,h) for(int i=(l);i<=(h);++i)
#define FORD(i,h,l) for(int i=(h);i>=(l);--i)
#define print(expr) cout<<(#expr)<<" : "<<(expr)<<endl
#define tr(it,c) for(auto it=(c).begin(); it!=(c).end(); ++it)
#define all(c) (c).begin(), (c).end()

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef long long int64;
typedef pair<int,int> pii;

int dis[10][10]={};
int n,k,t;

int main(void)
{
	ios::sync_with_stdio(false);
	cin>>n>>k>>t;
	rep(i,k)
	{
		int a,b,c; cin>>a>>b>>c; --a;--b;
		dis[a][b]=c;
	}
	VI ans;
	rep(mask1,1<<n) rep(mask2,1<<n)
	{
		bitset<5> b1(mask1), b2(mask2);
		if(b1.count()!=b2.count()) continue;
		int l=b1.count();
		VI a1,a2;
		rep(i,n) if(b1[i]) a1.PB(i);
		rep(i,n) if(b2[i]) a2.PB(i);
		VI p(l);
		rep(i,l) p[i]=i;
		do{
			int res=0;
			rep(i,l) res+=dis[a1[i]][a2[p[i]]];
			ans.PB(res);
		}while(next_permutation(all(p)));
	}
	sort(all(ans));
	cout<<ans[t-1]<<endl;
	return 0;
}

#include<iostream>
#include<iomanip>
#include<cstring>
using namespace std;
const int maxn = 1e3+7;
struct Edge{
    int nxt,to,w;
}edge[maxn];
int tot=0,head[maxn],mid,n,cnt,vis[maxn];
void add(int u,int v,int w){
    edge[tot].to=v;
    edge[tot].w=w;
    edge[tot].nxt=head[u];
    head[u]=tot++;
}

void dfs(int sum,int u){
    if(sum > mid){
        return ;
    }
    if(u > n){
        cnt++;
        return ;
    }
    dfs(sum,u+1);
    for(int i=head[u];i!=-1;i=edge[i].nxt){
        int v=edge[i].to;
        if(!vis[v]){
            vis[v]=1;
            dfs(sum+edge[i].w,u+1);
            vis[v]=0;
        }
    }
}
int main(){
    memset(head,-1,sizeof(head));
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
    int m,t;
    cin>>n>>m>>t;
    int a,b,c;
    for(int i=0;i<m;i++){
        cin>>a>>b>>c;
        add(a,b,c);
    }
    int l=1,r=1000*n+1;
    while(l<r){
        cnt=0;
        mid=(l+r)/2;
        dfs(0,1);
        if(cnt>=t){
            r=mid;
        }else{
            l=mid+1;
        }
    }
    cout<<l<<endl;
}

#include <iostream>
#include <cstdio>
#include <set>
using namespace std;

int n, k, t;
int a[100][100];

set < pair <int, int> > h;

bool used[100];

void solve(int m, int res, int mask)
{
    if (m == n+1)
    {
        h.insert(make_pair(res, mask));
        return;
    }
    solve(m+1, res, mask*10);
    for (int i=1; i<=n; i++)
        if (!used[i])
        {
            used[i] = true;
            solve(m+1, res + a[m][i], mask*10+i);
            used[i] = false;
        }
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    cin >> n >> k >> t;
    for (int i=0; i<k; i++)
    {
        int m, w, r;
        cin >> m >> w >> r;
        a[m][w] = r;
    }
    solve(1, 0, 0);
    set < pair <int, int> > :: iterator i = h.begin();
    t--;
    while (t--)
        i++;
    cout << i->first;
    return 0;
}

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

int n, k, t;
int a[100][100];

vector <int> h;

bool used[100];

void solve(int m, int res)
{
    if (m == n+1)
    {
        h.push_back(res);
        return;
    }
    solve(m+1, res);
    for (int i=1; i<=n; i++)
        if (!used[i])
        {
            used[i] = true;
            solve(m+1, res + a[m][i]);
            used[i] = false;
        }
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    cin >> n >> k >> t;
    for (int i=0; i<k; i++)
    {
        int m, w, r;
        cin >> m >> w >> r;
        a[m][w] = r;
    }
    solve(1, 0);
    sort(h.begin(), h.end());
    cout << h[t-1];
    return 0;
}

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int a[6][12],n;
vector <int> ans;
bool used[6];
void gen(int cnt,int pos=1,int k=0,int s=0)
{
    if (pos==n+1 && k==cnt)
        ans.push_back(s);
    else if (pos<=n)
    {
        gen(cnt,pos+1,k,s);
        for(int i=1;i<=n;i++)
            if (a[pos][i+n] && !used[i] && k<cnt)
            {
                used[i]=true;
                gen(cnt,pos+1,k+1,s+a[pos][i+n]);
                used[i]=false;
            }
    }
}
int main()
{
    int k,t,x,y,z;
    cin>>n>>k>>t;
    for(int i=0;i<k;i++)
    {
        cin>>x>>y>>z;
        a[x][y+n]=z;
    }
    if (t==1)
    {
        cout<<0;
        return 0;
    }
    t--;
    for(int i=1;;i++)
    {
        ans.clear();
        gen(i);
        sort(ans.begin(),ans.end());
        if (ans.size()>=t)
        {
            cout<<ans[t-1];
            break;
        }
        t-=ans.size();
    }
    return 0;
}

// In the name of God

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <complex>
#include <cmath>
#include <fstream>
#include <iomanip>

using namespace std;

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

const int maxn = 20 + 2;

vector<int> v;
int n,k,t;
int d[maxn][maxn];
int vis[maxn];

const vector<int> make(int start,int w)
{
  vector<int> ret;
  if(start == n){
    ret.push_back(d[start][w]);
    return ret;
  }
  for(int i=0;i<=n;++i)
    if(vis[i] == 0 || i == 0){
      vis[i] = 1;
      vector<int> help;
      help = make(start + 1 , i);
      vis[i] = 0;
      for(int j=0;j<help.size();++j)
	ret.push_back(help[j] + d[start][w]);
    }
  return ret;
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin >> n >> k >> t;
  for(int i=0;i<k;++i){
    int v1,v2,w;
    cin >> v1 >> v2 >> w;
    d[v1][v2] = w;
  }

  for(int i=0;i<=n;++i)  {
    vis[i] = 1;
    vector<int> help = make(1,i);
    vis[i] = 0;
    for(int j=0;j<help.size();++j)
      v.push_back(help[j]);
  }

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

  cout << v[t-1] << endl;

  return 0;
}

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

using namespace std;

void ASS(bool bb)
{
    if (!bb)
    {
        ++*(int*)0;
    }
}

#define FOR(i, x) for (int i = 0; i < (int)(x); i++)
#define CL(x) memset(x, 0, sizeof(x))
#define CLX(x, y) memset(x, y, sizeof(x))

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

typedef vector<int> vi;

typedef long long LL;

const int K = 128;
int pwz[K];

struct S2
{
    LL x;
    S2()
    {
        x = 0;
    }
    void set(int ind)
    {
        x += pwz[ind];
    }
    bool operator < (const S2& s) const
    {
        return x < s.x;
    }
};

struct S
{
    int x;
    LL m;
    S2 s2;
    bool operator < (const S& s) const
    {
        return x > s.x;
    }
};

int main()
{
    pwz[0] = 1;
    FOR(i, K - 1)
        pwz[i + 1] = pwz[i] * 3731;

    int n, k, t;
    cin >> n >> k >> t;
    vector<S> v;
    FOR(i, k)
    {
        S s;
        int x, y;
        cin >> x >> y >> s.x;
        x--;
        y--;
        s.m = (1LL << x) + (1LL << (y + n));
        v.push_back(s);
    }
    sort(v.begin(), v.end());
    priority_queue<S> q;
    {
        S s;
        s.m = 0;
        s.x = 0;
        q.push(s);
    }
    map<S2, int> st;
    vi all;
    while (q.size() > 0 && st.size() < (1 << 19))
    {
        S s = q.top();
        q.pop();
        all.push_back(s.x);
        FOR(i, k)
            if ((s.m & v[i].m) == 0)
            {
                S t = s;
                t.m |= v[i].m;
                t.x += v[i].x;
                t.s2.set(i);
                int& g = st[t.s2];
                if (g == 0)
                {
                    g = 1;
                    q.push(t);
                }
            }
    }
    while (!q.empty()) {
        all.push_back(q.top().x);
        q.pop();
    }
    sort(all.begin(), all.end());
    cout << all[t - 1] << endl;
    return 0;
}

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

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define PI 3.14159265358979
#define forn(i, n) for(int i = 0; i < n; ++i)
#define ALL(x) x.begin(), x.end()
#define L(s) (int)((s).size())
#define ms(x) memset(x,0,sizeof(x))
#define del(y,x) erase(y.begin()+x)

typedef long long ll;
using namespace std;
typedef pair<int,int> pii;
const int INF = 2147483647;
const ll LLINF = 9223372036854775807LL;
const int ST = 100010;
const int ST1 = 1000010;
const ll MOD = 1000000007;

ll ABS(ll a)
{
	if(a<0)
		return a*(-1);
	else
		return a;
}

vector<int> pr;
vector<int> cost;
bool used[6];
bool used2[6];
vector<vector<pii> > vv(6);
ll ans = 0;
int n;

void dfs(int v,int p,int sum)
{
	used[v] = true;
	used2[p] = true;
	for(int i = 0;i < n;i++)
	{
		if(!used[i])
		{
			for(int j = 0;j < L(vv[i]);j++)
				if(!used2[vv[i][j].X])
					dfs(i,vv[i][j].X,sum+vv[i][j].Y);
		}
	}
	used[v] = false;
	used2[p] = false;
	pr.pb(sum);
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
	int k,t;
	cin >> n >> k >> t;
	pr.pb(0);
	pr.pb(0);
	t--;
	for(int i = 0;i < k;i++)
	{
		int a,b,c;
		cin >> a >> b >> c;
		a--;b--;
		vv[a].pb(mp(b,c));
	}
	for(int i = 0;i < n;i++)
	{
		for(int j = 0;j < L(vv[i]);j++)
		{
			//used[i] = true;
			//used2[j] = true;
			dfs(i,vv[i][j].X,vv[i][j].Y);
			//used[i] = false;
			//used2[j] = false;
			pr.pb(vv[i][j].Y);
		}
	}
	t*=2;
	sort(ALL(pr));
	cout << pr[t];
}

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

using ll = long long;

int n, k, t;
vector<pair<ll,int>> edges;

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> n >> k >> t;
	edges.resize(k);
	for (int i = 0; i < k; i++) {
		int h, w, r;
		cin >> h >> w >> r;
		h--; w--;
		ll mask = ll(1) << h;
		mask |= ll(1) << (n+w);
		edges[i] = {r, mask};
	}
	sort(edges.begin(), edges.end());
	int s = -1, e = n * 1000;
	while (s+1 < e) {
		int mid = (s+e)/2;
		int tot = 1;
		function<void(int,int,ll)> enumerate = [&](int cur, int cur_cost, ll mask) {
			if (cur == k) return;
			if (tot >= t) return;
			int new_cost = cur_cost + edges[cur].first;
			if (new_cost <= mid) {
				if (!(mask & edges[cur].second)) {
					tot += 1;
					enumerate(cur+1, new_cost, mask | edges[cur].second);
				}
				enumerate(cur+1, cur_cost, mask);
			}
		};
		enumerate(0, 0, 0);
		if (tot >= t) {
			e = mid;
		} else {
			s = mid;
		}
	}
	cout << e << '\n';
}

//By Lin
#include<cstdio>
#include<cstring>
#include<bitset>
#include<queue>
#include<set>
#define maxn 20
using namespace std;
typedef long long LL;

int     n,m,t;
int     data[maxn][3];
bitset<50> mark;
set<pair<LL,LL> > ss;
struct  Node{
//  bitset<100> bits;
    pair<LL,LL> g;
    void reset(){
        g.first = g.second = 0;
    }
    void set(int x){
        if ( x<50 ) g.first |= 1ll<<x;
        else g.second |= 1ll<<(x-50);
    }
    void reset(int x){
        if ( x<50 ) g.first &= (-1ll)^(1ll<<x);
        else g.second |= (-1ll)^(1ll<<(x-50));
    }
    bool test(int x){
        if ( x<50 ) return (g.first&(1ll<<x));
        else return (g.second&(1ll<<(x-50)));
    }
    int key;
    friend bool operator<( const Node &a , const Node &b ) {
        return a.key > b.key;
    }
}tmp;
priority_queue<Node> que;

int     main(){
    scanf("%d%d%d", &n, &m, &t );
    for (int i = 0; i<m; i++) scanf("%d%d%d", &data[i][0],&data[i][1],&data[i][2]);
    tmp.reset();
    tmp.key = 0;
    que.push(tmp);
    int ans,tt=0;
    while ( t-- ) {
        if ( que.empty() ) {
            ans = -1;
            break;
        }
        tmp = que.top();
        que.pop();
        ans = tmp.key;
        mark.reset();
//      printf("%d %d\n", ++tt );
        for (int i = 0; i<m; i++ )
            if ( tmp.test(i) ) {
                mark.set(data[i][0]),mark.set(data[i][1]+n);
//              printf("%d %d %d\n", data[i][0],data[i][1],data[i][2] );
            }
//      puts("--------");
        for (int i = 0; i<m; i++ )
            if ( !mark.test(data[i][0]) && !mark.test(data[i][1]+n) ){
                tmp.set(i);
                tmp.key += data[i][2];
                if ( ss.find(tmp.g) == ss.end() ) {
                    ss.insert(tmp.g);
                    que.push(tmp);
                }
                tmp.key -= data[i][2];
                tmp.reset(i);
            }
    }
    printf("%d\n" ,ans );

    return 0;
}

#include <iostream>
#include <vector>
#include <queue>
#include <cstdio>
#include <cstdio>
#include <stack>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <ctime>
#include <math.h>
#include <cassert>

#define forn(i, n) for(int i=0;i<n;++i)
#define for1(i, n) for(int i=1;i<=n;++i)
#define forv(i, v) for(int i=0;i<v.size();++i)
#define sz(v) v.size()
#define all(v) v.begin(), v.end()
#define pb push_back
#define mp make_pair
#define ld double
#define li long long
#define X first
#define Y second
#define P (259)

using namespace std;

typedef pair <ld, ld> pt;
const li N = 105, M = 502,  INF = 1000*1000*1000 + 7;
const ld  eps = 1e-9;
const ld pi = 3.1415926535897932384626433832795;

int p[N][N];

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

    int n,k,t;
    cin >> n >> k >> t;
    forn(i, k) {
        int t, b, l;
        cin >> t >> b >> l;
        p[t-1][b-1] = l;
    }
    vector<int> girl(n);
    forn(i, n)
        girl[i] = i;
    t--;
    if (!t) {
        cout << 0;
        return 0;
    }

    vector<int> ans;
    set<vector<pair<int, int>>> us;
    for1(mask, (1 << n) - 1) {
        do {
            int tmp = 0;
            vector<pair<int, int>> edges;
            forn(i, n) {
                if ((mask & (1 << i)) && p[i][girl[i]]) {
                    edges.pb(mp(i, girl[i]));
                    tmp += p[i][girl[i]];
                }
            }
            if (!us.count(edges)) {
                ans.pb(tmp);
                us.insert(edges);
            }
        }while (next_permutation(all(girl)));
    }

    sort(all(ans));
    cout << ans[t-1];

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
struct ed{
	int u,v,c;
};
bool vis[200]={0},bis[200]={0};
ed a[200];
int n,k,t;
int kind=0;
int sum=0,mid;
bool eis[200]={0};
void dfs(int x,int cost){
	//取这一条边
	if(x>=k){
		kind++;
		return;
	}
	if(vis[a[x].u]==0 && bis[a[x].v]==0 && cost+a[x].c<=mid){
		vis[a[x].u]=bis[a[x].v]=1;
		eis[x]=1;
		dfs(x+1,cost+a[x].c);
		eis[x]=0;
		vis[a[x].u]=bis[a[x].v]=0;
	}
	dfs(x+1,cost);
}
int main(){
	ios::sync_with_stdio(false);

	cin>>n>>k>>t;
	for(int i=0,u,v,c;i<k;i++){
		cin>>a[i].u>>a[i].v>>a[i].c;
		sum+=a[i].c;
	}
	int l=0,r=sum;
	while(l<r-1){
		mid=(l+r)>>1;
		kind=0;
		dfs(0,0);

		if(kind>=t){
			r=mid;
		}
		else{
			l=mid;
		}
	//	cout<<mid<<" "<<kind<<endl;
	}
	cout<<r;
}

#include<iostream>
#include<cstdio>
#include <string>
#include<set>
#include<algorithm>
#include<vector>
#include<map>
#include<time.h>
using namespace std;

int a[1000000], ind = 0;
int h[25], w[25], r[25], h1[25], w1[25], r1[25], st[25];
bool u1[5], u2[5];
bool good[33554432];

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

    int n, k, t;
    cin >> n >> k >> t;
    for (int i = 0; i < k; i++)
    {
        cin >> h1[i] >> w1[i] >> r1[i];
        h1[i] --;
        w1[i] --;
        st[i] = i;
    }
    random_shuffle(st, st + k);
    for (int i = 0; i < k; i++)
    {
        h[i] = h1[st[i]];
        w[i] = w1[st[i]];
        r[i] = r1[st[i]];
    }

    good[0] = 1;
    int mask = 1;
    for (int i = 0; i < (1 << k); i++)
    {
        if ((mask << 1) <= i)
            mask = (mask << 1);
        if (!good[i - mask])
            continue;

        for (int j = 0; j < n; j++)
            u1[j] = u2[j] = 0;
        bool OK = 1;

        int x = i, cur = 0;
        for (int j = 0; x > 0; j++)
        {
            if (x & 1)
                if (u1[h[j]] || u2[w[j]])
                {
                    OK = 0;
                    break;
                }
                else
                {
                    u1[h[j]] = u2[w[j]] = 1;
                    cur += r[j];
                }

            x = (x >> 1);
        }

        if (OK)
        {
            a[ind] = cur;
            ind++;
        }
        good[i] = OK;
    }

    sort(a, a + ind);
    cout << a[t - 1];
}

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <math.h>
using namespace std;
typedef unsigned short us;
typedef unsigned int ui;
typedef long long i64;
typedef unsigned long long ui64;
long n,k,t,h,w,r;
us be[30];us bew[30];
ui64 z=0;
class marry{
public:
	int m;int w;int r;
	marry(int m1,int w1,int r1){m=m1;w=w1;r=r1;}
	bool operator<(const marry* mm){return r<mm->r;}
};
bool cmp(marry* m1,marry* m2){return m1->r<m2->r;}
vector<marry*> a;
vector<ui64> b;
int main(){
#ifndef ONLINE_JUDGE
	freopen("input.txt","rt",stdin);freopen("output.txt","wt",stdout);
#endif

	cin>>n>>k>>t;long long g=(long long)pow((double)2,(double)k);
	for(int i=1;i<=k;i++){cin>>h>>w>>r;a.push_back(new marry(h,w,r));}
	//sort(a.begin(),a.end(),&cmp);
	long j=0;long p=0;
	do{
		long d=j++;bool f=true;z=0;
		memset(be,0,sizeof(be));
		memset(bew,0,sizeof(bew));
		for(long i=0;i<a.size() && d>0;i++){
			long tt=d%2;d/=2;
			if(tt){
				z+=a[i]->r;
				if(be[a[i]->m] || bew[a[i]->w]){f=false;break;}
				be[a[i]->m]=1;bew[a[i]->w]=1;
			}
		}
		if(f){
			b.push_back(z);p++;
			//cout<<j-1<<' '<<z<<endl;
		}
	}while((p<k+3||p<t) && j<g);
	sort(b.begin(),b.end());
	cout<<b[t-1];
	return 0;
}

#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 5e3 + 10;
const int mask = (1 << 5) - 1;
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	typedef pair<int, pair<LL, LL>> Node;
	priority_queue<Node, vector<Node>, greater<Node>> pq;
	map < pair<LL, LL>, int> vis;
	pq.emplace(0, make_pair(0LL, 0LL));
	int n, k, m;
	vector<tuple<int, int, int>> vp;
	cin >> n >> k >> m;
	int cost = 0;
	while (k--)
	{
		int h, w, r;
		cin >> h >> w >> r;
		vp.emplace_back(r, h, w);
	}
	//sort(vp.begin(), vp.end());
	while (!pq.empty())
	{
		int val;
		pair<LL, LL> v;
		tie(val, v) = pq.top();
		pq.pop();
		cost++;
		if (m == cost)
		{
			cout << val << endl;
			break;
		}
		LL a, b;
		tie(a, b) = v;
		int flag[41];
		MEM(flag, 0);
		for (int i = 0; i < 60; i += 5)
		{
			int x = a >> i & mask;
			int y = b >> i & mask;
			if (x) flag[x] = flag[i / 5 + 1] = 1;
			if (y) flag[y] = flag[i / 5 + 13] = 1;
		}
		for (auto& p : vp)
		{
			int w, x, y;
			tie(w, x, y) = p;
			if (flag[x] || flag[y + n]) continue;
			LL A = a, B = b;
			if (x <= 12) A |= LL(y) << ((x - 1) * 5);
			else B |= LL(y) << ((x - 13) * 5);
			if (vis.count({ A,B })) continue;
			vis[make_pair(A, B)] = 1;
			pq.emplace(w + val, make_pair(A, B));
		}
	}
	return 0;
}

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <cctype>
#include <ctime>
#include <cassert>
using namespace std;

#define eps 1e-9
#define inf 2147483647
#define N 100100
#define M 1010
#define FILE_NAME ""
#define pi 3.14159265358979323846

typedef long long ll;
typedef unsigned long long ull;

int p[M], n, m, t, sz;
int g[M][M], was[M], ans[N];

void check()
{
	int cur = 0;

	//for (int i = 1; i <= n; i++)
	//	cout << p[i] << ' ';
	//cout << endl;

	for (int i = 1; i <= n; i++)
		cur += g[i][p[i]];

	//cerr << cur << endl;

	if (!cur)
		return;
	ans[++sz] = cur;
}

void rec(int pos)
{
	if (pos > n)
	{
		check();
		return;
	}

	for (int i = 1; i <= n; i++)
		if (was[i] == 0)
		{
			p[pos] = i;
			was[i] = 1;
			rec(pos + 1);
			was[i] = 0;
		}

	p[pos] = 0;
	rec(pos + 1);
}

int main()	{

	//freopen(FILE_NAME".in", "r", stdin);
	//freopen(FILE_NAME".out", "w", stdout);

	int i, a, b, temp;

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

	for (i = 1; i <= m; i++)
	{
		scanf ("%d%d%d", &a, &b, &temp);
		g[a][b] = temp;
	}

	rec(1);

	sort(ans, ans + sz + 1);

	printf ("%d", ans[t - 1]);

	return 0;
}

#include <cstdio>
#include <algorithm>
#define len1 21

int value[len1][len1] ;
int hash[len1] ;
int seq[1<<len1] , tot = 0 ;
int N , M , K ;

void dfs( int x , int count )
{
    int i , j ;

    if ( x <= N )
    {
        dfs(x+1,count);
        for ( i = 1 ; i <= N ; ++i )
        if ( hash[i] == 0 )
        {
            hash[i] = 1 ;
            dfs(x+1,count+value[x][i]);
            hash[i] = 0 ;
        }
    }
    else
    {
        seq[++tot] = count ;
    }
}

int main()
{
    int i , j , sc,  sv , t ;

    scanf("%d%d%d",&N,&M,&K);
    for ( i = 1 ; i <= M ; ++i )
    {
        scanf("%d%d%d",&sc,&sv,&t);
        value[sc][sv] = t ;
    }
    dfs(1,0);
    std::sort(seq+1,seq+tot+1);
    printf("%d\n",seq[K]);
    return 0;
}

#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
int heap[1000000];
int map[100][100];
int n,k,t,size;

void up(int i)
{
	while (i>1&&heap[i]>heap[i/2])
	{
		int tmp;
		tmp=heap[i],heap[i]=heap[i/2],heap[i/2]=tmp;
		i=i/2;
	}
}

void down(int i)
{
	while (i+i<=size)
	{
		int j=i,tmp;
		if (heap[i+i]>heap[j]) j=i+i;
		if (i+i+1<=size&&heap[i+i+1]>heap[j]) j=i+i+1;
		if (i==j) return;
		tmp=heap[i],heap[i]=heap[i/2],heap[i/2]=tmp;
		i=j;
	}
}

void dfs(int dep, int zt,int res)
{
	if (res>heap[1]&&(size>=t)) return;
	if (dep==n+1)
	{
		//a[++len]=res;
		heap[++size]=res;up(1);
		if (size>t)
		{
			heap[1]=heap[size];
			size--;
			down(1);
		}
		return;
	}
	for (int i=1; i<=n; i++)
	{
		if (1<<i&zt) continue;
		if (map[dep][i]==0) continue;
		dfs(dep+1,zt|1<<i,res+map[dep][i]);
	}
	dfs(dep+1,zt,res);
}

int main()
{
	scanf("%d%d%d",&n,&k,&t);
	for (int i=1; i<=k; i++)
	{
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		map[x][y]=z;
	}
	dfs(1,0,0);
	printf("%d\n",heap[1]);
}

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

using ll = long long;

int n, k, t;
vector<pair<ll,int>> edges;

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> n >> k >> t;
	edges.resize(k);
	for (int i = 0; i < k; i++) {
		int h, w, r;
		cin >> h >> w >> r;
		h--; w--;
		ll mask = ll(1) << h;
		mask |= ll(1) << (n+w);
		edges[i] = {r, mask};
	}
	sort(edges.begin(), edges.end());
	int s = -1, e = n * 1000;
	while (s+1 < e) {
		int mid = (s+e)/2;
		int tot = 1;
		function<void(int,int,ll)> enumerate = [&](int cur, int cur_cost, ll mask) {
			if (tot == t) return;
			if (cur == k) return;
			int new_cost = cur_cost + edges[cur].first;
			if (new_cost <= mid) {
				enumerate(cur+1, cur_cost, mask);
				if (tot < t && !(mask & edges[cur].second)) {
					tot += 1;
					enumerate(cur+1, new_cost, mask | edges[cur].second);
				}
			}
		};
		enumerate(0, 0, 0);
		if (tot == t) {
			e = mid;
		} else {
			s = mid;
		}
	}
	cout << e << '\n';
}

#include <iostream>
#include <vector>
#include <queue>
#include <cstdio>
#include <cstdio>
#include <stack>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <ctime>
#include <math.h>
#include <cassert>

#define forn(i, n) for(int i=0;i<n;++i)
#define for1(i, n) for(int i=1;i<=n;++i)
#define forv(i, v) for(int i=0;i<v.size();++i)
#define sz(v) v.size()
#define all(v) v.begin(), v.end()
#define pb push_back
#define mp make_pair
#define ld double
#define li long long
#define X first
#define Y second
#define P (259)

using namespace std;

typedef pair <ld, ld> pt;
const li N = 105, M = 502,  INF = 1000*1000*1000 + 7;
const ld  eps = 1e-9;
const ld pi = 3.1415926535897932384626433832795;

struct node {
    int from;
    int to;
    int l;
};
bool operator <(node &a, node &b) {
    return a.l < b.l;
}

int p[N][N];
vector<node> a;

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

    int n,k,t;
    cin >> n >> k >> t;
    a.resize(k);
    forn(i, k) {
        int t, b, l;
        cin >> t >> b >> l;
        node tmp;
        tmp.from = t;
        tmp.to = b;
        tmp.l = l;
        a[i] = tmp;
    }
    sort(all(a));
    t--;
    if (!t) {
        cout << 0;
        return 0;
    }
    set<pair<int, pair<set<int>, set<int>>>> kit;
    forn(i, k) {
        set<int> k1;
        set<int> k2;
        k1.insert(a[i].from);
        k2.insert(a[i].to);
        kit.insert(mp(a[i].l, mp(k1, k2)));
    }
    forn(j, k) {
        set<pair<int, pair<set<int>, set<int>>>> tmp;
        for(set<pair<int, pair<set<int>, set<int>>>>::iterator i = kit.begin(); i != kit.end(); i++) {
            set<int> k1 = i->second.first;
            set<int> k2 = i->second.second;
            if (k1.count(a[j].from) || k2.count(a[j].to))
                continue;
            k1.insert(a[j].from);
            k2.insert(a[j].to);
            tmp.insert(mp(a[j].l + i->first, mp(k1, k2)));
        }
        for(set<pair<int, pair<set<int>, set<int>>>>::iterator i = tmp.begin(); i != tmp.end(); i++)
            kit.insert(*i);
    }
    int j=t;
    for(set<pair<int, pair<set<int>, set<int>>>>::iterator i = kit.begin(); i != kit.end(); i++) {
        j--;
        if (j == 0) {
            cout << i->first;
            return 0;
        }
    }

    return 0;
}

#include<bits/stdc++.h>

using namespace std;

#define FC ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define deb(args...) std::cerr<<"DEBUG------"<<'\n';std::cerr<<#args<<"------>";err(args)

void err(){
    std::cerr<<'\n'<<"END OF DEBUG"<<'\n'<<'\n';
}

template<typename T,typename... Args>
void err(T a,Args... args){
    std::cerr<<a<<", ";
    err(args...);
}

template<template<typename...> class T,typename t,typename... Args>
void err(T<t> a, Args... args){
    for(auto x: a){
        std::cerr<<x<<", ";
    }
    err(args...);
}

const long double PI=acos(-1.0);
const long double eps=1e-6;
const long long maxw=(long long)1e17+(long long)10;

using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

/*head------[@cordercorder]*/

const int maxn=25;

struct node{
    int to;
    int w;
};

vector<node> e[maxn+maxn];
int n,k,t,cnt;
bool isv[maxn+maxn];

void dfs(int u,int sum,int lim){
    if(u>n){
        cnt++;
        return ;
    }
    dfs(u+1,sum,lim);
    int v,w;
    for(int i=0;i<(int)e[u].size();i++){
        v=e[u][i].to;
        w=e[u][i].w;
        if(!isv[v]&&w+sum<=lim&&cnt<t){
            isv[v]=true;
            dfs(u+1,w+sum,lim);
            isv[v]=false;
        }
    }
}

void solve(){
    int l=1,r=(int)1e5+10,mid;
    while(l<r){
        mid=(l+r)>>1;
        cnt=0;
        dfs(1,0,mid);
        if(cnt>=t){
            r=mid;
        }
        else{
            l=mid+1;
        }
    }
    printf("%d\n",l);
}

int main(void){
    int u,v,w;
    scanf("%d %d %d",&n,&k,&t);
    for(int i=1;i<=k;i++){
        scanf("%d %d %d",&u,&v,&w);
        v+=n;
        e[u].push_back({v,w});
        e[v].push_back({u,w});
    }
    solve();
    return 0;
}

/* 先用二分搜索猜測第 $t$ 個匹配的權重和，
 * 再用遞迴+剪枝枚舉出有多少個匹配權重和必超過該值。
 * 邊(x, y) 代表著一側的第 x 個點和另一側的第 y 個點相連的邊
 */
#include<cstdio>
const int MAX_N = 20;
int n, k, t; // 題目裡就有的參數
int e[MAX_N + 1][MAX_N + 1]; // e[x][y] 存在若且唯若邊(x, y) 存在
int choosen[MAX_N + 1];
int mid; // 二分搜索時，猜測的答案
int cnt; // 計數器
void dfs(int x, int now_cost_sum){
	if (now_cost_sum > mid) return;  // 超過猜測答案就剪枝
    if (cnt >= t) return; // 匹配數目已達 t 就剪枝
	if (x > n) {
        cnt++; // 以枚舉到一組匹配，把計數器加 1
        return;
    }
	dfs(x + 1, now_cost_sum); // 匹配中不選任何和 x 相連的邊
	for (int y = 1; y <= n && cnt < t; y++)
		if (!choosen[y] && e[x][y]) { // 檢查邊(x, y) 可不可以加入匹配
			choosen[y] = 1;           // 紀錄 y 已被選取
            dfs(x + 1, now_cost_sum + e[x][y]); // 呼叫下一層遞迴
            choosen[y] = 0;           // 取消 y 被選取的紀錄
        }
}
int main(){
    // 讀入參數
	scanf("%d%d%d", &n, &k, &t);
	for (int i = 1; i <= k; i++) {
        int h, w, r;
		scanf("%d%d%d", &h, &w, &r);
        e[h][w] = r;
    }
    /* * 二分搜索
     * 匹配可能最大值為最大權重乘最多邊數
     * [low, high] 為當前還可能是答案的區間
     */
	int low = 1, high = 1000 * n;
	while (low < high) {
		mid = (low + high) >> 1;
        cnt = 0; // 計數器歸零
        dfs(1, 0);
		if (cnt >= t) high = mid;
        else low = mid + 1;
    }
    printf("%d\n", low);
}

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

using ll = long long;

int n, k, t;
vector<pair<ll,int>> edges;

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> n >> k >> t;
	edges.resize(k);
	for (int i = 0; i < k; i++) {
		int h, w, r;
		cin >> h >> w >> r;
		h--; w--;
		ll mask = ll(1) << h;
		mask |= ll(1) << (n+w);
		edges[i] = {r, mask};
	}
	sort(edges.begin(), edges.end());
	int s = -1, e = (n/2) * 1000;
	while (s+1 < e) {
		int mid = (s+e)/2;
		int tot = 1;
		function<void(int,int,ll)> enumerate = [&](int cur, int cur_cost, ll mask) {
			if (tot == t) return;
			if (cur == k) return;
			int new_cost = cur_cost + edges[cur].first;
			if (new_cost <= mid) {
				enumerate(cur+1, cur_cost, mask);
				if (tot < t && !(mask & edges[cur].second)) {
					tot += 1;
					enumerate(cur+1, new_cost, mask | edges[cur].second);
				}
			}
		};
		enumerate(0, 0, 0);
		if (tot == t) {
			e = mid;
		} else {
			s = mid;
		}
	}
	cout << e << '\n';
}

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

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define PI 3.14159265358979
#define forn(i, n) for(int i = 0; i < n; ++i)
#define ALL(x) x.begin(), x.end()
#define L(s) (int)((s).size())
#define ms(x) memset(x,0,sizeof(x))
#define del(y,x) erase(y.begin()+x)

typedef long long ll;
using namespace std;
typedef pair<int,int> pii;
const int INF = 2147483647;
const ll LLINF = 9223372036854775807LL;
const int ST = 100010;
const int ST1 = 1000010;
const ll MOD = 1000000007;

ll ABS(ll a)
{
	if(a<0)
		return a*(-1);
	else
		return a;
}

vector<int> pr;
vector<int> cost;
bool used[6];
bool used2[6];
vector<vector<pii> > vv(6);
ll ans = 0;
int n;

void dfs(int v,int p,int sum)
{
	used[v] = true;
	used2[p] = true;
	for(int i = 0;i < n;i++)
	{
		if(!used[i])
		{
			for(int j = 0;j < L(vv[i]);j++)
				if(!used2[vv[i][j].X])
					dfs(i,vv[i][j].X,sum+vv[i][j].Y);
		}
	}
	used[v] = false;
	used2[p] = false;
	pr.pb(sum);
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
	int k,t;
	cin >> n >> k >> t;
	pr.pb(0);
	pr.pb(0);
	t--;
	for(int i = 0;i < k;i++)
	{
		int a,b,c;
		cin >> a >> b >> c;
		a--;b--;
		vv[a].pb(mp(b,c));
	}
	for(int i = 0;i < n;i++)
	{
		for(int j = 0;j < L(vv[i]);j++)
		{
			used[i] = true;
			used2[vv[i][j].X] = true;
			dfs(i,vv[i][j].X,vv[i][j].Y);
			used[i] = false;
			used2[vv[i][j].X] = false;
			pr.pb(vv[i][j].Y);
		}
	}
	t*=2;
	sort(ALL(pr));
	//vector<int>::iterator it = unique (pr.begin(), pr.end());
	//pr.resize( it - pr.begin() );
	cout << pr[t];
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fst first
#define sec second
typedef pair<int,ll> pll;
pll es[200];
bool vs[50];
ll mid;
int N,K,T;
int cnt = 0;
void dfs(int x,ll v,ll mask) {
    if (x == K) return;
    if (cnt >= T) return;
    if (v + es[x].first > mid) return;
    if (!(mask & es[x].second)) {
        cnt++;
        dfs(x+1,v+es[x].first,v | es[x].second);
    }
    dfs(x+1,v,mask);
}
int main() {
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin >> N >> K >> T;
    for (int i = 0;i < K;i++) {
        int u,v;
        cin >> u >> v >> es[i].fst;
        es[i].sec = (1 << u) + (1LL << (v + N));
    }
    sort(es,es+K);
    ll l = 0;ll r = 1000 * N;
    while (l < r) {
        mid = (l + r) >> 1;
        cnt = 1;
        dfs(0,0,0);
        if (cnt >= T) r = mid;
        else l = mid + 1;
    }
    printf("%lld\n",l);
    return 0;
}

#include <stdio.h>
#include <iostream>
#include <string>
#include <stdlib.h>
#include <ctime>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

#define fi first
#define se second
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)

int Tab[100][100];
int mark[100];
int n;
vector<int> Ans;

void per(int i)
{
   // cout << "i = " << i <<endl;
    if(i >= n)
    {
  //      for(int j = 0; j < n; j++)
  //          cout << mark[j] << " ";
    //    cout << endl;
        int sum = 0;

        int B[20];
        for(int j = 0; j <= n; j++)
            B[j] = 0;
        for(int j = 0; j < n; j++)
        {
            if(mark[j]!=0 && B[mark[j]] == 1)
                return;
            B[mark[j]] = 1;
            sum += Tab[j + 1][mark[j]];
            //cout <<  + 1 << " " << mark[j] << " " << Tab[i + 1][mark[j]] << endl;
        }
      //  cout << sum << endl;
        Ans.pb(sum);
        return;
    }
    for(int j = 0; j <= n; j++)
    {
        mark[i] = j;
        per(i + 1);
    }
}

int main()
{
    //freopen("in.txt", "r", stdin);
    int k, t;
    cin >> n >> k >> t;
    for(int i = 0; i < k; i++)
    {
        int w, m, c;
        cin >> w >> m >> c;
        Tab[w][m] = c;
    }
    per(0);
    sort(Ans.begin(), Ans.end());
    cout << Ans[t-1] << endl;
    return 0;
}

#define _CRT_SECURE_NO_DEPRECATE
//#pragma comment(linker, "/STACK:25000000")
#include <iostream>
#include <vector>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <string>
using namespace std;
long n, m, k;
vector < vector < pair < long, long > > > g;
vector < long long > ans;
vector < long > p;
void f(long ps = 0, long long sm = 0) {
	long i;
	if(ps == n) {
		ans.push_back(sm);
		return;
	}
	f(ps + 1, sm);
	for(i = 0; i < g[ps].size(); i++) {
		if(p[g[ps][i].first] == -1) {
			long n = g[ps][i].first;
			if(n < ps)
				break;
			p[n] = ps;
			p[ps] = n;
			sm += g[ps][i].second;
			f(ps + 1, sm);
			p[n] = p[ps] = -1;
			sm -= g[ps][i].second;
		}
	}
}
int main() {
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
    cin >> n >> m >> k;
	long i, j, a, b, c;
	g.assign(n, vector < pair < long, long > > ());
	p.assign(n, -1);
	for(i = 0; i < m; i++) {
		cin >> a >> b >> c;
		a--; b--;
		g[a].push_back(make_pair(b, c));
		g[b].push_back(make_pair(a, c));
	}
	f();
	sort(ans.begin(), ans.end());
	cout << ans[k] << endl;
    return 0;
}

#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<ctime>
#include<set>
#include<queue>
#define sqr(x) (x)*(x)
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
//#define T_ int
using namespace std;
//struct bit{T_ arr[1000005];int lowbit(int x){return x&(-x);}void add(int x,T_ y){for (int i=x;i<=n;i+=lowbit(i)) arr[i]+=y;}T_ query(int x){T_ s=0;for (int i=x;i>0;i-=lowbit(i)) s+=arr[i];return s;}};
//struct seg{struct treedot{int l,r;T_ sum,add;void update(T_ x){sum+=(r-l+1)*x; add+=x;}}c[800005];void pushdown(int id){if (c[id].add){c[id*2].update(c[id].add);c[id*2+1].update(c[id].add);c[id].add=0;}}void pushup(int id){c[id].sum=c[id*2].sum+c[id*2+1].sum;}void build(int id,int l,int r){if (l>r) return;c[id].l=l;c[id].r=r;c[id].sum=0;c[id].add=0;if (l==r) c[id].sum=0;else{int mid=l+(r-l)/2;build(id*2,l,mid);build(id*2+1,mid+1,r);pushup(id);}}void update(int id,int le,int ri,T_ x){if (le>c[id].r||ri<c[id].l) return;if (le<=c[id].l&&c[id].r<=ri) c[id].update(x);else{pushdown(id);update(id*2,le,ri,x);update(id*2+1,le,ri,x);pushup(id);}}T_ query(int id,int le,int ri){if (ri<c[id].l||c[id].r<le) return 0;if (le<=c[id].l&&c[id].r<=ri) return c[id].sum;T_ ans=0;pushdown(id);ans+=query(id*2,le,ri);ans+=query(id*2+1,le,ri);pushup(id);return ans;}};
//struct bit_2d{T_ a[2005][2005];int lowbit(int x){return x&(-x);}void add(int x,int y,T_ z){int i,j;for (i=x;i<=2000;i+=lowbit(i)){for (j=y;j<=2000;j+=lowbit(j)){a[i][j]+=z;}}}T_ query(int x,int y){int i,j;T_ s=0;for (i=x;i;i-=lowbit(i)){for (j=y;j;j-=lowbit(j)){s+=a[i][j];}}return s;}T_ query(int x,int y,int xx,int yy){return query(xx,yy)-query(x-1,yy)-query(xx,y-1)+query(x-1,y-1);}};
int n,m,t,i,j,a[20][20];
priority_queue<pair<int,int> > f,g;
int main()
{
	scanf("%d%d%d",&n,&m,&t);
	fz0k(i,m)
	{
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		a[x-1][y-1]=z;
	}
	f.push(make_pair(0,0));
	fz0k(i,n)
	{
		priority_queue<pair<int,int> > e;
		swap(e,g);
		while (!f.empty())
		{
			pair<int,int> it=f.top();f.pop();
			if (g.size()>=t&&it.first>=g.top().first) continue;
			g.push(it);
			fz0k(j,n)
			{
				if (!((it.second>>j)&1)&&a[i][j])
				{
					g.push(make_pair(it.first+a[i][j],(it.first|(1<<j))));
				}
			}
			while (g.size()>t) g.pop();
		}
		f=g;
	}
	cout<<g.top().first<<endl;
	return 0;
}

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

using namespace std;

const int XX = 1e7 + 10;
const int MAXN = 20 + 2;

int n, m, k, sz, vec[XX];
int adj[MAXN], w[MAXN][MAXN], ms;

void gen(int cur = 0, int sm = 0, int ms = 0){
	if (sz == XX - 2)	return;
	vec[sz++] = sm;
	if (cur == n)	return;

	for (; cur < n; cur++){
		int z = adj[cur]&(adj[cur]^ms);
		while (z){
			int id = z&-z;
			z-=id;
			gen(cur + 1, sm + w[cur][__builtin_ctz(id)], ms | id);
		}
	}
}

int main(){
	cin >> n >> m >> k;
	while (m--){
		int a, b, c;	cin >> a >> b >> c, a--, b--;
		w[a][b] = c;
		adj[a] |= 1<<b;
	}
	gen();
	sort(vec, vec + sz);
	cout << vec[k - 1] << endl;
	return 0;
}

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

typedef unsigned short us;
typedef unsigned int ui;
typedef long long i64;
typedef unsigned long long ui64;
long n,k,t,h,w,r;
us be[30];us bew[30];
ui64 z=0;

class marry{
public:
	int m;int w;int r;
	marry(int m1,int w1,int r1){m=m1;w=w1;r=r1;}
	bool operator<(const marry* mm){return r<mm->r;}
};
bool cmp(marry* m1,marry* m2){return m1->r<m2->r;}
vector<marry*> a;

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

	cin>>n>>k>>t;
	for(int i=1;i<=k;i++){cin>>h>>w>>r;a.push_back(new marry(h,w,r));}
	sort(a.begin(),a.end(),&cmp);

	//t--;
	//t++;
	long j=0;long p=0;
	do{
		int d=j++;bool f=true;z=0;
		memset(be,0,sizeof(be));
		memset(bew,0,sizeof(bew));
		for(int i=0;i<a.size();i++){
			int tt=d%2;d/=2;
			if(tt){
				z+=a[i]->r;
				if(be[a[i]->m] || bew[a[i]->w]){f=false;break;}
				be[a[i]->m]=1;bew[a[i]->w]=1;
			}
		}
		if(f){++p;
			//cout<<j-1<<' '<<z<<endl;
		}
	}while(p<t);
	cout<<z;
	return 0;
}

//#include"C:\Users\sugon\OneDrive\ACM\模块\模板\acm.h"
//#include"C:\Users\Harborfan\OneDrive\ACM\模块\模板\acm.h"
#include<map>
#include<queue>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define scd(x) scanf("%llf",&x)
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b) - 1; i >= (a); --i)
#define dd(a) cout << #a << " = " << (a) << " "
#define de(a) cout << #a << " = " << (a) << endl
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pw(a) (1ll << (a))
#define endl "\n"
typedef double db;
typedef long long ll;
typedef long long LL;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
const int inf = 0x3f3f3f3f;
const ll linf = 0x3f3f3f3f3f3f3f3f;

const int maxn = 20+10;
int n,k,t;
int cnt,sum,mid;

struct node
{
	int x,y,z;
}a[maxn*maxn];
bool vis[maxn];

void dfs(int d)
{
	if(cnt>t) return ;
	if(d>=k)
	{
		cnt++;
//		cout<<cnt<<' '<<sum<<endl;
		return ;
	}

	dfs(d+1);
	if(!vis[a[d].x]&&!vis[a[d].y])
	{
		sum += a[d].z;
		if(sum>mid)
		{
			sum -= a[d].z;
			return ;
		}

		vis[a[d].x] = 1;
		vis[a[d].y] = 1;

		dfs(d+1);

		sum -= a[d].z;
		vis[a[d].x] = 0;
		vis[a[d].y] = 0;
	}

}

int main()
{
	sci(n); sci(k); sci(t);
	memset(vis,0,sizeof vis);
	for(int i = 0;i < k;i++)
	{
		int x,y,z;
		sci(a[i].x);
		sci(a[i].y);
		a[i].y+=maxn;
		sci(a[i].z);
	}

	int l = -1,r = inf;
	mid = 10;
	dfs(0);

	while(l<r-1)
	{
		cnt = sum = 0;
		mid = l+r>>1;
		dfs(0);
//		cout<<mid<<' '<<cnt<<' '<<(cnt>=t)<<endl;
		if(cnt>=t)
		{
			r = mid;
		}
		else// if(cnt==t)
		{
			l = mid;
		}
	}
	printf("%d\n",r);
}

#include<iostream>

using namespace std;

int n, m, k, a[100], b[100], c[100], ans;
bool mark[10], seen[10000];

void BT(int n)
{
	seen[ans] = true;
	if(n > ::n)
		return;
	BT(n + 1);
	for(int i = 0; i < m; i++)
		if(a[i] == n && !mark[b[i]])
		{
			mark[b[i]] = true;
			ans += c[i];
			BT(n + 1);
			ans -= c[i];
			mark[b[i]] = false;
		}
	return;
}

int main()
{
	cin >> n >> m >> k;
	for(int i = 0; i < m; i++)
		cin >> a[i] >> b[i] >> c[i];
	int t = 0, i = 0;
	BT(1);
	while(t < k)
	{
		if(seen[i])
			t++;
		i++;
	}
	cout << i - 1 << endl;
	return 0;
}

#include<iostream>
#include<iomanip>
#include<cstring>
using namespace std;
const int maxn = 1e3+7;
struct Edge{
    int nxt,to,w;
}edge[maxn];
int tot=0,head[maxn],mid,n,cnt,vis[maxn];
void add(int u,int v,int w){
    edge[tot].to=v;
    edge[tot].w=w;
    edge[tot].nxt=head[u];
    head[u]=tot++;
}

void dfs(int sum,int u){
    if(sum > mid){
        return ;
    }
    if(u > n){
        cnt++;
        return ;
    }
    dfs(sum,u+1);
    for(int i=head[u];i!=-1;i=edge[i].nxt){
        int v=edge[i].to;
        if(!vis[v]){
            vis[v]=1;
            dfs(sum+edge[i].w,u+1);
            vis[v]=0;
        }
    }
}
int main(){
    memset(head,-1,sizeof(head));
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
    int m,t;
    cin>>n>>m>>t;
    int a,b,c;
    for(int i=0;i<m;i++){
        cin>>a>>b>>c;
        add(a,b,c);
    }
    int l=1,r=1000*n+1;
    while(l<r){
        cnt=0;
        mid=(l+r)/2;
        dfs(0,1);
        if(cnt>=t){
            r=mid;
        }else{
            l=mid+1;
        }
    }
    cout<<l<<endl;
}

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

const int maxN = 20;
int n, m, cnt;
int x[maxN], y[maxN], r[maxN];
int p[maxN];
struct State {
	int val;
	int S, T, i;
	State(int v, int S, int T, int i) :
		val(v), S(S), T(T), i(i) {}
	bool operator < (const State &rhs) const {
		return val < rhs.val;
	}
	bool operator > (const State &rhs) const {
		return val > rhs.val;
	}
};
priority_queue< State, vector<State>, std::greater<State> > pq;

bool cmp(int x, int y) {
	return r[x] < r[y];
}

bool extend(int val, int S, int T, int i) {
	if(i < m) {
		int SS = S | (1 << x[p[i]]);
		int TT = T | (1 << y[p[i]]);
		if(SS == S || TT == T) return false;
		pq.emplace(val + r[p[i]], SS, TT, i + 1);
		return true;
	}
	return false;
}

int main() {
	cin >> n >> m >> cnt;
	for(int i = 0; i < m; ++i) {
		cin >> x[i] >> y[i] >> r[i];
		x[i]--; y[i]--;
		p[i] = i;
	}
	std::sort(p, p + m, cmp);
	pq.emplace(0, 0, 0, 0);
	cnt--;
	while(cnt--) {
		auto u = pq.top(); pq.pop();
		int val = u.val, S = u.S, T = u.T, i = u.i;
		for(int j = i; j < m; ++j) extend(val, S, T, j);
	}
	cout << pq.top().val << endl;
	return 0;
}

# include<map>
# include<set>
# include<queue>
# include<stack>
# include<deque>
# include<math.h>
# include<vector>
# include<bitset>
# include<stdio.h>
# include<ctype.h>
# include<iostream>
# include<stdlib.h>
# include<string.h>
# include<algorithm>
# define si size
# define er erase
# define sc scanf
# define be begin
# define fr first
# define se second
# define pr printf
# define pb push_back
# define mp make_pair
# define INF 100000000
# define Int long long int
using namespace std;
int n, k, t, x, y, z, a[25][25], i, j, p, u[25];
vector<int>ans;
void rec(int l, int v)
{
    ans.pb(v);
    for(int i=l;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(!u[j]&&a[i][j])
            {
                u[j] = 1;
                rec(i+1, v+a[i][j]);
                u[j] = 0;
            }
        }
    }
}
main()
{
freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
sc("%d%d%d",&n,&k,&t);
for(i=0;i<k;i++)
{
    sc("%d%d%d",&x,&y,&z);
    a[x][y]=z;
}
rec(1,0);
sort(ans.be(), ans.end());/*
for(i=0;i<ans.si();i++)
{
    pr("%d\n",ans[i]);
}*/
pr("%d\n",ans[t-1]);
return 0;
}

#include<iostream>
#include<cstdio>
#include <string>
#include<set>
#include<algorithm>
#include<vector>
#include<map>
#include<time.h>
using namespace std;

int a[1000000], ind = 0;
int h[25], w[25], r[25], h1[25], w1[25], r1[25], st[25];
bool u1[5], u2[5];
bool good[33554432];

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

    int n, k, t;
    cin >> n >> k >> t;
    for (int i = 0; i < k; i++)
    {
        cin >> h1[i] >> w1[i] >> r1[i];
        h1[i] --;
        w1[i] --;
        st[i] = i;
    }
    random_shuffle(st, st + k);
    for (int i = 0; i < k; i++)
    {
        h[i] = h1[st[i]];
        w[i] = w1[st[i]];
        r[i] = r1[st[i]];
    }

    good[0] = 1;
    for (int i = 0; i < (1 << k); i++)
    {
        if (!good[(i >> 1)])
            continue;

        for (int j = 0; j < n; j++)
            u1[j] = u2[j] = 0;
        bool OK = 1;

        int x = i, cur = 0;
        for (int j = 0; x > 0; j++)
        {
            if (x & 1)
                if (u1[h[j]] || u2[w[j]])
                {
                    OK = 0;
                    break;
                }
                else
                {
                    u1[h[j]] = u2[w[j]] = 1;
                    cur += r[j];
                }

            x = (x >> 1);
        }

        if (OK)
        {
            a[ind] = cur;
            ind++;
        }
        good[i] = OK;
    }

    sort(a, a + ind);
    cout << a[t - 1];
}

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

using namespace std;

const int XX = 1e7 + 10 + 5e6;
const int MAXN = 20;

int n, m, k, sz, vec[XX];
int adj[MAXN], w[MAXN][MAXN], ms;

void gen(int cur = 0, int sm = 0, int ms = 0){
	if (sz == XX - 2)	return;
	vec[sz++] = sm;
	if (cur == n)	return;

	for (; cur < n; cur++){
		int z = adj[cur]&(adj[cur]^ms);
		while (z){
			int id = z&-z;
			z-=id;
			gen(cur + 1, sm + w[cur][__builtin_ctz(id)], ms | id);
		}
	}
}

int main(){
	cin >> n >> m >> k;
	while (m--){
		int a, b, c;	cin >> a >> b >> c, a--, b--;
		w[a][b] = c;
		adj[a] |= 1<<b;
	}
	gen();
	sort(vec, vec + sz);
	cout << vec[k - 1] << endl;
	return 0;
}

#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
int a[1000000];
int map[100][100];
int n,k,t,len;

void dfs(int dep, int zt,int res)
{
	if (dep==n+1)
	{
		a[++len]=res;
		return;
	}
	for (int i=1; i<=n; i++)
	{
		if (1<<i&zt) continue;
		dfs(dep+1,zt|1<<i,res+map[dep][i]);
	}
	dfs(dep+1,zt,res);
}

int main()
{
	scanf("%d%d%d",&n,&k,&t);
	for (int i=1; i<=k; i++)
	{
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		map[x][y]=z;
	}
	dfs(1,0,0);
	std::sort(a+1,a+len+1);
	printf("%d\n",a[t]);
}

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <math.h>
using namespace std;
typedef unsigned short us;
typedef unsigned int ui;
typedef long long i64;
typedef unsigned long long ui64;
long n,k,t,h,w,r;
us be[30];us bew[30];
ui64 z=0;
class marry{
public:
	int m;int w;int r;
	marry(int m1,int w1,int r1){m=m1;w=w1;r=r1;}
	bool operator<(const marry* mm){return r<mm->r;}
};
bool cmp(marry* m1,marry* m2){return m1->r<m2->r;}
vector<marry*> a;
int main(){
#ifndef ONLINE_JUDGE
	freopen("input.txt","rt",stdin);freopen("output.txt","wt",stdout);
#endif

	cin>>n>>k>>t;
	for(int i=1;i<=k;i++){cin>>h>>w>>r;a.push_back(new marry(h,w,r));}
	sort(a.begin(),a.end(),&cmp);

	//t--;
	//t++;
	long j=0;long p=0;
	do{
		long d=j++;bool f=true;z=0;
		memset(be,0,sizeof(be));
		memset(bew,0,sizeof(bew));
		for(long i=0;i<a.size();i++){
			long tt=d%2;d/=2;
			if(tt){
				z+=a[i]->r;
				if(be[a[i]->m] || bew[a[i]->w]){f=false;break;}
				be[a[i]->m]=1;bew[a[i]->w]=1;
			}
		}
		if(f){++p;
			//cout<<j-1<<' '<<z<<endl;
		}
	}while(p<t);
	cout<<z;
	return 0;
}

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

using namespace std;

const int XX = 1e7 + 7e6;
const int MAXN = 20;

int n, m, k, sz, vec[XX];
int adj[MAXN], w[MAXN][MAXN], ms;

void gen(int cur = 0, int sm = 0, int ms = 0){
	if (sz == XX - 2)	return;
	vec[sz++] = sm;
	if (cur == n)	return;

	for (; cur < n; cur++){
		int z = adj[cur]&(adj[cur]^ms);
		while (z){
			int id = z&-z;
			z-=id;
			gen(cur + 1, sm + w[cur][__builtin_ctz(id)], ms | id);
		}
	}
}

int main(){
	cin >> n >> m >> k;
	while (m--){
		int a, b, c;	cin >> a >> b >> c, a--, b--;
		w[a][b] = c;
		adj[a] |= 1<<b;
	}
	gen();
	sort(vec, vec + sz);
	cout << vec[k - 1] << endl;
	return 0;
}

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <cctype>
#include <ctime>
#include <cassert>
using namespace std;

#define eps 1e-9
#define inf 2147483647
#define N 100100
#define M 1010
#define FILE_NAME ""
#define pi 3.14159265358979323846

typedef long long ll;
typedef unsigned long long ull;

int p[M], n, m, t, sz;
int g[M][M], was[M], ans[N];

void check()
{
	int cur = 0;

	//for (int i = 1; i <= n; i++)
	//	cout << p[i] << ' ';
	//cout << endl;

	for (int i = 1; i <= n; i++)
		cur += g[i][p[i]];

	//cerr << cur << endl;

	if (!cur)
		return;
	ans[++sz] = cur;
}

void rec(int pos)
{
	if (pos > n)
	{
		check();
		return;
	}

	for (int i = 1; i <= n; i++)
		if (was[i] == 0)
		{
			p[pos] = i;
			was[i] = 1;
			rec(pos + 1);
			was[i] = 0;
		}

	p[pos] = 0;
	rec(pos + 1);
}

int main()	{

	//freopen(FILE_NAME".in", "r", stdin);
	//freopen(FILE_NAME".out", "w", stdout);

	int i, a, b, temp;

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

	for (i = 1; i <= m; i++)
	{
		scanf ("%d%d%d", &a, &b, &temp);
		g[a][b] = temp;
	}

	rec(1);

	sort(ans, ans + sz + 1);

	printf ("%d", ans[t - 1]);

	return 0;
}

// In The Name Of God
#include<bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;

const int MAXN = 22 ;

int n,k,t,res,a[MAXN][MAXN];
bool mark[MAXN];
vector<int>v;

void go(int i)
{
	if(i==n+1)
	{
		v.pb(res);
		return;
	}
	for(int j=0;j<=n;j++)
	{
		if(j==0 || !mark[j])
		{
			mark[j]=true;
			res+=a[i][j];
			go(i+1);
			res-=a[i][j];
			mark[j]=false;
		}
	}
}

int main()
{
	ios::sync_with_stdio(false),cin.tie(0);
	cin>>n>>k>>t;
	for(int i=1,x,y,z;i<=k;i++)
	{
		cin>>x>>y>>z;
		a[x][y]=z;
	}
	go(1);
	sort(v.begin(),v.end());
	cout<<v[t-1];
	return 0;
}

#include <iostream>
#include <vector>
#include <queue>
#include <cstdio>
#include <cstdio>
#include <stack>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <ctime>
#include <math.h>
#include <cassert>

#define forn(i, n) for(int i=0;i<n;++i)
#define for1(i, n) for(int i=1;i<=n;++i)
#define forv(i, v) for(int i=0;i<v.size();++i)
#define sz(v) v.size()
#define all(v) v.begin(), v.end()
#define pb push_back
#define mp make_pair
#define ld double
#define li long long
#define X first
#define Y second
#define P (259)

using namespace std;

typedef pair <ld, ld> pt;
const li N = 105, M = 502,  INF = 1000*1000*1000 + 7;
const ld  eps = 1e-9;
const ld pi = 3.1415926535897932384626433832795;

int p[N][N];

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

    int n,k,t;
    cin >> n >> k >> t;
    forn(i, k) {
        int t, b, l;
        cin >> t >> b >> l;
        p[t-1][b-1] = l;
    }
    vector<int> girl(n);
    forn(i, n)
        girl[i] = i;
    t--;
    if (!t) {
        cout << 0;
        return 0;
    }

    vector<int> ans;
    set<vector<pair<int, int>>> us;
    for1(mask, (1 << n) - 1) {
        do {
            int tmp = 0;
            vector<pair<int, int>> edges;
            forn(i, n) {
                if ((mask & (1 << i)) && p[i][girl[i]]) {
                    edges.pb(mp(i, girl[i]));
                    tmp += p[i][girl[i]];
                }
            }
            sort(all(edges));
            if (!us.count(edges)) {
                ans.pb(tmp);
                us.insert(edges);
            }
        }while (next_permutation(all(girl)));
    }

    sort(all(ans));
    cout << ans[t-1];

    return 0;
}

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <iostream>

using namespace std;

#define N 100

set<int> ANS;
int n, k, t, adj[N][N];

void solve(int A[], int B[], int rem, int c) {
    if(rem == 0) {
	ANS.insert(c);
	return ;
    }

    for(int i = 1; i <= n; i++) {
	if(!A[i])
	    for(int j = 1; j <= n; j++) {
		if(!B[j] && adj[i][j]) {
		    A[i] = B[j] = 1;
		    solve(A, B, rem - 1, c + adj[i][j]);
		    A[i] = B[j] = 0;
		}
	    }

    }
}

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

    for(int i = 0; i < k; i++) {
	int u, v, w; cin >> u >> v >> w;
	adj[u][v] = w;
    }
    int A[N] = {0}, B[N] = {0};
    for(int rem = 0; rem <= n; rem++)
	solve(A, B, rem, 0);

    int counter = 0;
    for(auto it : ANS) {
	counter++;
	if(counter == t) printf("%d\n", it);
    }

    return 0;
}

#include<bits/stdc++.h>
#define MP make_pair
#define R second
#define L first
using namespace std;
const int maxn=100000+100;
int a[maxn], b[maxn];
int d[maxn];

int main(){
	int n, m, p;
	cin >> n >> m >> p;
	for(int i=0;i<n;i++)
		cin >> a[i];
	for(int i=0;i<m;i++)
		cin >> b[i], d[i]+=b[i], d[n-m+i+1]-=b[i];
	for(int i=1;i<n;i++)
		d[i]+=d[i-1];
	for(int i=0;i<n;i++)
		cout << (a[i]+d[i])%p << " ";
	cout << endl;
}

#include <cstdio>
#include <sstream>
#include <iostream>

#include <set>
#include <map>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <cstring>

#include <ctime>
#include <cmath>
#include <cstdlib>
#include <algorithm>
using namespace std;

#define REP(i,n) for (int i = 0; i < (n); ++i)
#define FOR(i,a,b) for (int i = (a); b; ++i)
#define REPI(i,c) for (typeof(c.begin()) i = c.begin(); i != c.end(); ++i)
#define ALL(c) c.begin(), c.end()
#define SZ(x) ((int)(x).size())

#define DB(x) cout << #x << " = " << x << endl;

const int MAX = 25;

int N, K, T;
int m[MAX], w[MAX], a[MAX];
int um[MAX], uw[MAX];
set<int> S;

int main()
{
    ios::sync_with_stdio(false);

    cin >> N >> K >> T;

    REP(i, K)
    {
        cin >> m[i] >> w[i] >> a[i];
        --m[i];
        --w[i];
    }

    int dt = 0;
    REP(i, 1<<K)
    {
        int p = 0;
        ++dt;

        REP(j, K)
            if (i & (1 << j))
            {
                p += a[j];
                if (um[ m[j] ] == dt) goto err;
                if (uw[ w[j] ] == dt) goto err;
                um[ m[j] ] = dt;
                uw[ w[j] ] = dt;
            }

        if (SZ(S) < T)
            S.insert(p);
        else
        {
            int w = *S.rbegin();
            if (w > p)
            {
                S.erase(w);
                S.insert(p);
            }
        }

        err:;
    }

    int ans;
    while (T--) ans = *S.begin(), S.erase(S.begin());

    //REPI(i, S) DB(*i);

    cout << ans << endl;

    return 0;
}// (++UH)++ :: agarwaen

#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <utility>
#include <string>
#include <string.h>
#include <map>
#include <locale>
#include <math.h>

#define frup(FRUP_I,FROM,TO) for(long FRUP_I=FROM;FRUP_I<=TO;FRUP_I++)
#define frdn(FRDN_I,FROM,TO) for(long FRDN_I=FROM;FRDN_I<TO;FRDN_I++)

#define pub(VALUE) push_back(VALUE)
#define pob() pop_back()
#define mp(FST,SEC) make_pair(FST,SEC)
#define len(STR) STR.length()

#define IN "input.txt"
#define OUT "output.txt"

#define refresh(ARRAY,TARGET,VALUE) frdn(DEFINED_I,0,TARGET)ARRAY[DEFINED_I]=VALUE
#define watch(VALUE) {cout<<#VALUE;printf("=");cout<<VALUE;printf("\n");}
#define stop exit(0)

using namespace std;

typedef pair<long,long> ll;

const long INF=(long)1e09;

struct node{
       long h,w,r;
       };

long n,m,j,k,ans=0,c,t,z,next=0;
vector<long>all,a(40,0);
set<long>hus,wiw;
vector<node>d;

bool comp(node a, node b){
 return a.r>b.r;
}

int main(){
  //  freopen(IN,"r",stdin);
  //  freopen(OUT,"w",stdout);
      scanf("%ld %ld %ld",&n,&k,&t);
      node l;
      l.h=0;
      l.w=0;
      l.r=0;
       d.pub(l);
       frup(i,1,k){
                   long x,y,z;
                    scanf("%ld %ld %ld",&x,&y,&z);
                      node l;
      l.h=x;
      l.w=y;
      l.r=z;
                    d.pub(l);
                   }
 sort(d.begin()+1,d.end(),comp);
  while(true){
              hus.clear();
              wiw.clear();
               long res=0;
               bool f=1;
                frup(i,1,k)
                  if(a[i]>0){
                            if(hus.count(d[i].h)||wiw.count(d[i].w)){
                                                                 f=0;
                                                                 break;
                                                                 }
                              hus.insert(d[i].h);
                              wiw.insert(d[i].w);
                              res+=d[i].r;
                            }
               if(f)next++;
               if(next==t){
                           cout<<res;
                           return 0;
                           }
               a[k]++;
               z=k;
                while(z>0){
                           if(a[z]>1){
                                      a[z-1]++;
                                      a[z]=0;
                                      }
                             z--;
                           }
               if(a[0])break;
              }
              cout<<0;
return 0;
}

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

using ll = long long;

int n, k, t;
vector<pair<ll,int>> edges;

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> n >> k >> t;
	edges.resize(k);
	for (int i = 0; i < k; i++) {
		int h, w, r;
		cin >> h >> w >> r;
		h--; w--;
		ll mask = ll(1) << h;
		mask |= ll(1) << (n+w);
		edges[i] = {r, mask};
	}
	sort(edges.begin(), edges.end());
	int s = -1, e = n * 1000;
	while (s+1 < e) {
		int mid = (s+e)/2;
		int tot = 1;
		function<void(int,int,ll)> enumerate = [&](int cur, int cur_cost, ll mask) {
			if (tot == t) return;
			if (cur == k) return;
			int new_cost = cur_cost + edges[cur].first;
			if (new_cost <= mid) {
				enumerate(cur+1, cur_cost, mask);
				if (tot < t && !(mask & edges[cur].second)) {
					tot += 1;
					enumerate(cur+1, new_cost, mask | edges[cur].second);
				}
			}
		};
		enumerate(0, 0, 0);
		if (tot == t) {
			e = mid;
		} else {
			s = mid;
		}
	}
	cout << e << '\n';
}

#include <iostream>
#include <algorithm>

using namespace std;

int n,t,k;
int cost[22][22];
bool used[22];
int numFind;
int anss[200005];

void back(int num,int get){
	if(num==n){
		anss[numFind++]=get;
		return;
	}
	back(num+1,get);
	for(int i=0;i<n;i++){
		if(!used[i] /*&& cost[num][i]*/){
			used[i]=true;
			back(num+1,get+cost[num][i]);
			used[i]=false;
		}
	}
}

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

	cin>>n>>k>>t;

	int tmp1,tmp2;
	for(int i=0;i<k;i++){
		cin>>tmp1>>tmp2;
		cin>>cost[tmp1-1][tmp2-1];
	}

	back(0,0);

	sort(anss,anss+numFind);

	cout<<anss[t-1]<<endl;

	return 0;
}