malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const long long INF = (long long)1e18 + 100;   long long safe_sum(long long a, long long b) {     long long s = (a + b);     s = min(s, INF);     return s;   }   long long safe_mult(long long a, long long b) {     if (a == 0 || b == 0) return 0;     if (a >= ((INF + b - 1) / b)) return INF;     return (a * b);   }   const int maxN = 1005;   long long c[maxN][maxN];   long long gcd(long long x, long long y) {     while (x > 0 && y > 0) {       if (x < y) swap(x, y);       x %= y;     }     return (x + y);   }   long long cnk(long long x, int a) {     vector<long long> cur;     for (int i = 0; i < a; i++) {       cur.push_back(x - i);     }     for (int j = 1; j <= a; j++) {       int now = j;       for (auto& it : cur) {         if (now == 1) break;         int d = (int)(gcd(it, now));         it /= d;         now /= d;       }     }     long long ans = 1;     for (auto& it : cur) ans = safe_mult(ans, it);     return ans;   }   int n;   long long k;   const int maxT = 2 * (int)1e5 + 100;   const int BUBEN = 10;   long long a[maxT];   long long get_cnk(long long x, long long y) {     if (x - y < y) return get_cnk(x, x - y);     if (x < y) return 0;     if (x < maxN) {       return c[x][y];     }     if (y >= BUBEN)       return INF;     else       return cnk(x, (int)y);   }   bool ok(long long who) {     long long f = 0;     for (int i = 0; i < n; i++) {       f = safe_sum(f, safe_mult(a[i], get_cnk(n - i - 1 + who - 1, who - 1)));       if (f >= k) return true;     }     return (f >= k);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     c[0][0] = 1;     for (int i = 1; i < maxN; i++) {       c[i][0] = 1;       for (int j = 1; j <= i; j++) {         c[i][j] = safe_sum(c[i - 1][j], c[i - 1][j - 1]);       }     }     cin >> n >> k;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] >= k) {         cout << 0;         return 0;       }     }     long long l = 0;     long long r = (long long)(1e18) + 100;     while (r - l > 1) {       long long mid = (l + r) / 2;       if (ok(mid))         r = mid;       else         l = mid;     }     cout << r;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1005;   int a[N][N];   int dp1[N][N] = {0}, dp2[N][N] = {0}, dp3[N][N] = {0}, dp4[N][N] = {0};   int main() {     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) cin >> a[i][j];     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         dp1[i][j] = max(dp1[i - 1][j], dp1[i][j - 1]) + a[i][j];       }     for (int i = n; i >= 1; i--)       for (int j = m; j >= 1; j--) {         dp2[i][j] = max(dp2[i + 1][j], dp2[i][j + 1]) + a[i][j];       }     for (int i = n; i >= 1; i--)       for (int j = 1; j <= m; j++) {         dp3[i][j] = max(dp3[i + 1][j], dp3[i][j - 1]) + a[i][j];       }     for (int i = 1; i <= n; i++)       for (int j = m; j >= 1; j--) {         dp4[i][j] = max(dp4[i - 1][j], dp4[i][j + 1]) + a[i][j];       }     int ans = 0;     for (int i = 2; i < n; i++)       for (int j = 2; j < m; j++) {         ans = max(dp1[i - 1][j] + dp2[i + 1][j] + dp3[i][j - 1] + dp4[i][j + 1],                   ans);         ans = max(dp1[i][j - 1] + dp2[i][j + 1] + dp3[i + 1][j] + dp4[i - 1][j],                   ans);       }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct pvec {     long long int x, y;     pvec(long long int x = 0, long long int y = 0) : x(x), y(y) {}     pvec operator-(pvec p) { return pvec(x - p.x, y - p.y); }     bool operator==(pvec p) { return x == p.x and y == p.y; }     long long int dot(pvec p) { return x * p.x + y * p.y; }     long long int abs2() { return x * x + y * y; }   };   pvec v[12], Q[12], R[12];   long long int Qi[12], Ri[12];   long long int perm[][3] = {{1, 2, 3}, {1, 3, 2}, {2, 1, 3},                              {2, 3, 1}, {3, 1, 2}, {3, 2, 1}};   inline bool quadrado() {     for (long long int i = 0; i < 6; i++) {       pvec p0 = Q[0];       pvec p1 = Q[perm[i][0]];       pvec p2 = Q[perm[i][1]];       pvec p3 = Q[perm[i][2]];       pvec v1 = p1 - p0, v2 = p2 - p1, v3 = (p2 - p3), v4 = (p3 - p0);       if (!(v1 == v3 and v2 == v4)) continue;       if (v1.abs2() != v2.abs2()) continue;       if (v1.dot(v2) != 0) continue;       return true;     }     return false;   }   inline bool retangulo() {     for (long long int i = 0; i < 6; i++) {       pvec p0 = R[0];       pvec p1 = R[perm[i][0]];       pvec p2 = R[perm[i][1]];       pvec p3 = R[perm[i][2]];       pvec v1 = p1 - p0, v2 = p2 - p1, v3 = (p2 - p3), v4 = (p3 - p0);       if (!(v1 == v3 and v2 == v4)) continue;       if (v1.dot(v2) != 0) continue;       return true;     }     return false;   }   bool da(long long int u, long long int quad, long long int ret) {     if (quad > 4 or ret > 4) return false;     if (u == 8) {       if (quadrado() and retangulo()) return true;       return false;     }     Q[quad] = v[u];     Qi[quad] = u;     if (da(u + 1, quad + 1, ret)) return true;     R[ret] = v[u];     Ri[ret] = u;     if (da(u + 1, quad, ret + 1)) return true;     return false;   }   int main() {     for (long long int i = 0; i < 8; i++) {       long long int x, y;       cin >> x >> y;       v[i] = pvec(x, y);     }     if (!da(0, 0, 0)) {       cout <<  NO  << endl;     } else {       cout <<  YES  << endl;       for (long long int i = 0; i < 4; i++) {         if (i) printf(   );         cout << Qi[i] + 1;       }       cout << endl;       for (long long int i = 0; i < 4; i++) {         if (i) printf(   );         cout << Ri[i] + 1;       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long l, r, b, c, a;       long long m;       cin >> l >> r >> m;       for (long long i = l; i <= r; i++) {         a = i;         long long n = m / a, temp = a * n, diff = m - temp;         if (n > 0 && abs(m - temp) <= r - l) {           if (diff >= 0) {             b = r;             c = r - m + temp;           } else {             b = l;             c = l + temp - m;           }           cout << a <<     << b <<     << c <<   n ;           break;         }         n = m / a + 1, temp = a * n, diff = m - temp;         if (abs(m - temp) <= r - l) {           if (diff >= 0) {             b = r;             c = r - m + temp;           } else {             b = l;             c = l + temp - m;           }           cout << a <<     << b <<     << c <<   n ;           break;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   double a, v, d, w, l, ans, mid, t2, t;   bool check(double maxv) {     return d - ((maxv + w) / 2) * (((maxv - w) * 2) / a) > 1e-8;   }   int main() {     scanf( %lf %lf %lf %lf %lf , &a, &v, &l, &d, &w);     w = min(min(w, v), sqrt(2 * a * d));     if (2 * a * d + w * w > 2 * v * v) {       t = (d - v * v / a + w * w / a / 2) / v + (2 * v - w) / a;     } else {       t = (2 * sqrt(a * d + w * w / 2) - w) / a;     }     l = l - d;     t2 = (v - w) / a;     if (l - w * t2 - 0.5 * a * t2 * t2 > 0) {       t2 = t2 + (l - w * t2 - 0.5 * a * t2 * t2) / v;     } else {       t2 = (-w + sqrt(w * w + 2.0 * a * l)) / a;     }     printf( %.10f n , t + t2);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int Maxn = 200020;   int n, a[Maxn];   long long sum[Maxn];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , a + i);     for (int i = 0; i < n - 1; i++) {       int cur;       for (cur = 1; cur <= i;) {         int val = i / cur;         int ncur = i / val + 1;         if (a[i + 2] < a[val + 1]) {           sum[cur]++;           sum[ncur]--;         }         cur = ncur;       }       if (a[i + 2] < a[1]) sum[cur]++, sum[n]--;     }     for (int i = 1; i < n; i++) sum[i] += sum[i - 1], printf( %I64d n , sum[i]);     ;   }
#include <bits/stdc++.h>   int main() {     int n, i;     int maximum, maxIndex, target;     int A[1000];     scanf( %d , &n);     maximum = -1;     for (i = 0; i < n; ++i) {       scanf( %d , &A[i]);       if (A[i] > maximum) {         maximum = A[i];         maxIndex = i;       }     }     A[maxIndex] = -2;     target = -1;     for (i = 0; i < n; ++i) {       if (A[i] > target) {         target = A[i];       }     }     printf( %d %d , maxIndex + 1, target);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];       a[i]--;     }     vector<int> v(n), d(n);     queue<int> q;     q.push(0);     v[0] = 1;     int l = 0;     while (!q.empty()) {       int nn = q.size();       while (nn-- > 0) {         int t = q.front();         q.pop();         d[t] = l;         if (t > 0 && v[t - 1] == 0) {           q.push(t - 1);           v[t - 1] = 1;         }         if (t < n - 1 && v[t + 1] == 0) {           q.push(t + 1);           v[t + 1] = 1;         }         if (v[a[t]] == 0) {           q.push(a[t]);           v[a[t]] = 1;         }       }       l++;     }     for (int i : d) cout << i <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   int n, k;   int a[2011];   long long pre[1 << 11 + 1];   long long cur[1 << 11 + 1];   void solve() {     memset(pre, 0, sizeof(pre));     pre[0] = 1;     for (int i = 0; i < n; i++) {       memset(cur, 0, sizeof(cur));       for (int j = 0; j < (1 << k) + 1; j++) {         if (a[i] == 2 || a[i] == 0) {           int nj = min(j + 2, 1 << k);           cur[nj] = (cur[nj] + pre[j]) % mod;         }         if (a[i] == 4 || a[i] == 0) {           int nj = min(j + 4, 1 << k);           if ((j & 2) != 0) {             nj = 4;           }           cur[nj] = (cur[nj] + pre[j]) % mod;         }       }       memcpy(pre, cur, sizeof(cur));     }     cout << pre[1 << k] << endl;   }   void coding() {     while (cin >> n >> k) {       for (int i = 0; i < n; i++) cin >> a[i];       solve();     }   }   int main() { coding(); }
#include <bits/stdc++.h>   using namespace std;   const long long dp = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int n, a;     cin >> n >> a;     vector<int> vec(n);     int cnt = 0;     for (int i = 0; i < n; i++) {       cin >> vec[i];       if (vec[i]) cnt++;     }     for (int i = 0; i < a; i++) {       if (vec[a - 1 - i] + vec[a - 1 + i] == 1) cnt--;       if (i >= n - a) break;     }     cout << cnt <<   n ;     return 0;   }
#include <bits/stdc++.h>   const int maxn = 2005;   const int inf = 1e9;   using namespace std;   vector<pair<int, int>> G[maxn];   vector<int> C[maxn], v;   bool critical[maxn * maxn];   vector<int> seen, sum, col, depth, up;   void dfs(int node, int ind) {     seen[node] = 1;     int minFromSons = inf;     up[node] = depth[node];     for (auto tmp : G[node]) {       if (seen[tmp.first] && tmp.second != ind)         up[node] = min(up[node], depth[tmp.first]);       else if (!seen[tmp.first]) {         depth[tmp.first] = depth[node] + 1;         dfs(tmp.first, tmp.second);         minFromSons = min(minFromSons, up[tmp.first]);       }     }     up[node] = min(up[node], minFromSons);     if (minFromSons >= depth[node] && ind != -1) {       critical[ind] = 1;     }   }   void dfsColor(int node, int color) {     col[node] = color;     v[color]++;     for (auto tmp : G[node]) {       if (critical[tmp.second] == 1 && col[tmp.first] == 0) continue;       if (critical[tmp.second] == 1 && col[tmp.first]) {         C[col[tmp.first]].push_back(color);         C[color].push_back(col[tmp.first]);         continue;       } else if (col[tmp.first] == 0)         dfsColor(tmp.first, color);     }   }   void dfsSub(int node) {     seen[node] = 1;     sum[node] = v[node];     for (auto tmp : C[node])       if (!seen[tmp]) {         dfsSub(tmp);         sum[node] += sum[tmp];       }   }   int main() {     ios_base ::sync_with_stdio(false);     int n, m;     cin >> n >> m;     for (int i = 0; i < m; ++i) {       int a, b;       cin >> a >> b;       G[a].push_back(make_pair(b, i));       G[b].push_back(make_pair(a, i));     }     seen = vector<int>(n + 1, 0);     depth = vector<int>(n + 1, 0);     up = vector<int>(n + 1, 0);     dfs(1, -1);     int c = 0;     col = vector<int>(n + 1, 0);     v = vector<int>(n + 1, 0);     int all = 0;     for (int i = 1; i <= n; ++i)       if (col[i] == 0) {         ++c;         dfsColor(i, c);         all += v[c] * v[c];       }     int ans = 0;     for (int i = 1; i <= c; ++i) {       seen = vector<int>(c + 1, 0);       sum = vector<int>(c + 1, 0);       dfsSub(i);       int tmp = 0;       for (int j = 1; j <= c; ++j) tmp += sum[j] * v[j];       vector<int> can(n + 1, 0);       can[0] = 1;       for (auto tmp : C[i]) {         for (int j = n; j >= 0; --j)           if (can[j] && j + sum[tmp] <= n) can[j + sum[tmp]] = 1;       }       int res = -1;       for (int j = (n - v[i]) / 2; j >= 0; --j)         if (can[j]) {           res = j;           break;         }       tmp += res * (n - v[i] - res);       ans = max(ans, tmp);     }     cerr << all <<   n ;     cout << ans <<   n ;   }
#include <bits/stdc++.h>   int main() {     int x, count = 0, i;     char ar[50];     for (i = 0; i < 9; i++) scanf(  %c , &ar[i]);     for (i = 0; i < 9; i++) {       if (ar[i] == ar[8 - i]) count++;     }     if (count == 9)       printf( YES );     else       printf( NO );   }
#include <bits/stdc++.h>   using namespace std;   const int shape[4][4][2] = {{{1, 0}, {2, 0}, {1, 1}, {1, 2}},                               {{1, 0}, {2, 0}, {2, -1}, {2, 1}},                               {{0, 1}, {0, 2}, {-1, 2}, {1, 2}},                               {{0, 1}, {0, 2}, {1, 1}, {2, 1}}};   int x, y;   struct node {     char g[9][9];     int num;     int sx, sy;     int layer;     node() {       layer = 0;       sx = sy = 0;       memset(g, 0, sizeof(g));       num = 0;     }     void printNode() {       for (int i = 0; i < y; i++) {         for (int j = 0; j < x; j++) printf( %c , g[i][j] ? g[i][j] :  . );         cout <<    << endl;       }     }   };   stack<node> q;   int ans;   node ansNode;   int maxG[9][9][4];   void bfs() {     while (!q.empty()) {       node now = q.top();       q.pop();       if (now.num > ans) {         ans = now.num;         ansNode = now;       }       now.num++;       char ch =  A  + now.num - 1;       for (int i = now.sy; i < y; i++) {         for (int j = 0; j < x; j++) {           if (!now.g[i][j]) {             for (int k = 0; k < 4; k++) {               if (maxG[i][j][k] > now.num + 1) continue;               bool flag = true;               for (int l = 0; l < 4 && flag; l++) {                 int tx = j + shape[k][l][1];                 int ty = i + shape[k][l][0];                 if (tx < 0 || tx >= x || ty < 0 || ty >= y || now.g[ty][tx]) {                   flag = false;                 }               }               if (flag) {                 node tNode = now;                 tNode.g[i][j] = ch;                 for (int l = 0; l < 4; l++) {                   int tx = j + shape[k][l][1];                   int ty = i + shape[k][l][0];                   tNode.g[ty][tx] = ch;                 }                 tNode.sx = j + 1;                 tNode.sy = i;                 tNode.layer++;                 q.push(tNode);                 maxG[i][j][k] = max(maxG[i][j][k], now.num);               }             }           }         }       }     }   }   int main() {     ans = -1;     cin >> y >> x;     while (!q.empty()) q.pop();     q.push(node());     bfs();     cout << ans << endl;     ansNode.printNode();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100009;   int sol, qs[N], qe[N], sorted[N], ans[N], a[N], s, e;   unordered_map<int, int> freq;   void add(int el) {     sol -= !(freq[el] ^ el);     freq[el]++;     sol += !(freq[el] ^ el);   }   void remove(int el) {     sol -= !(freq[el] ^ el);     freq[el]--;     sol += !(freq[el] ^ el);   }   void mo(int idx) {     while (s > qs[idx]) add(a[--s]);     while (e <= qe[idx]) add(a[e++]);     while (s < qs[idx]) remove(a[s++]);     while (e > qe[idx] + 1) remove(a[--e]);     ans[idx] = sol;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < m; i++) {       cin >> qs[i] >> qe[i];       qs[i]--, qe[i]--;       sorted[i] = i;     }     int sq = sqrt(n);     sort(sorted, sorted + m, [sq](int i, int j) {       return make_pair(qs[i] / sq, qe[i]) < make_pair(qs[j] / sq, qe[j]);     });     for (int i = 0; i < m; i++) mo(sorted[i]);     for (int i = 0; i < m; i++) cout << ans[i] <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   using min_pq = priority_queue<T, vector<T>, greater<T>>;   const int MAXN = 1e5 + 10, MAXQ = 3e5 + 10, MAXL = 20, ALP = 26, MOD = 1e9 + 7,             MAXK = 17, INF = 1e9 + 10, MAXA = 30, MAXB = 24, MAXBB = (1 << MAXB);   const string no =  NO n , yes =  YES n ;   const int hA[4] = {1, 0, -1, 0}, kA[4] = {0, 1, 0, -1};   void solve() {     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         int a;         cin >> a;         if ((a & 1) != ((i + j) & 1)) a++;         cout << a <<    ;       }       cout <<   n ;     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int t = 1;     cin >> t;     while (t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n, sum1 = 0, res1 = 0, last = 0;     bool flag = true;     cin >> n;     unordered_map<long long int, long long int> m;     vector<pair<long long int, long long int>> v;     for (long long int i = 0; i < n; i++) {       long long int element;       cin >> element;       m[element]++;       v.emplace_back(make_pair(element, i));     }     if (n == 1) {       cout << 1 <<   n ;       cout << v[0].first <<                <<  0 n ;       return 0;     }     sort(v.begin(), v.end());     vector<pair<long long int, long long int>> v1;     for (long long int i = 0; i < v.size() - 1; i++) {       flag = true;       if (i < v.size() - 1 && v[i].first == v[i + 1].first)         sum1 = v[i + 1].second - v[i].second;       else if (i < v.size() - 1)         sum1 = 0;       while (i < v.size() - 1 && v[i].first == v[i + 1].first) {         res1 = v[i + 1].second - v[i].second;         if (res1 != sum1) {           flag = false;           break;         }         i++;       }       if (flag == true) {         v1.push_back(make_pair(v[i].first, sum1));       }       while (i < v.size() - 1 && v[i].first == v[i + 1].first) {         i++;       }     }     if (v[v.size() - 1].first != v[v.size() - 2].first) {       v1.emplace_back(make_pair(v[v.size() - 1].first, 0));     }     cout << v1.size() <<   n ;     for (long long int i = 0; i < v1.size(); i++) {       cout << v1[i].first <<     << v1[i].second <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     long long int t, temp, i, ans = 0, n, m, index, j;     cin >> n >> m;     vector<pair<long long int, long long int> > pa;     vector<long long int> v(n), finger(m);     for (i = 0; i < n; i++) {       cin >> v[i];     }     for (i = 0; i < m; i++) {       cin >> finger[i];       for (j = 0; j < n; j++) {         if (v[j] == finger[i]) {           pa.push_back(make_pair(j, finger[i]));         }       }     }     sort(pa.begin(), pa.end());     if (pa.size() == 0)       cout <<   n ;     else {       for (auto it = pa.begin(); it != pa.end(); it++) {         cout << it->second <<    ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   long long m, l, r, k;   struct Matrix {     long long W[2][2];   };   Matrix operator*(const Matrix& A, const Matrix& B) {     Matrix S;     memset(S.W, 0, sizeof(S.W));     for (int i = 0; i < 2; ++i)       for (int j = 0; j < 2; ++j)         for (int l = 0; l < 2; ++l)           S.W[i][j] = (S.W[i][j] + A.W[i][l] * B.W[l][j]) % m;     return S;   }   Matrix operator^(Matrix A, long long e) {     Matrix S;     S.W[0][0] = S.W[1][1] = 1;     S.W[0][1] = S.W[1][0] = 0;     while (e) {       if (e & 1) S = S * A;       A = A * A;       e >>= 1;     }     return S;   }   long long gcd() {     long long s = 1;     for (long long i = 1; i * i <= r; ++i) {       if (r / i - (l - 1) / i >= k && i > s) s = i;       long long e = r / i;       if (i - (l - 1) / e >= k && e > s) s = e;     }     return s;   }   int main() {     cin >> m >> l >> r >> k;     long long n = gcd();     if (n <= 2)       cout << 1 % m << endl;     else {       Matrix D, S;       D.W[0][0] = 0;       D.W[0][1] = D.W[1][0] = D.W[1][1] = 1;       S = D ^ (n - 2);       cout << (S.W[0][1] + S.W[1][1]) % m << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N;   vector<int> a, b, c;   multiset<int> m;   int main(void) {     ios::sync_with_stdio(false);     cin.tie(NULL), cout.tie(NULL);     cin >> N;     a.resize(N);     b.resize(N);     c.resize(N);     for (int i = 0; i < N; i++) {       cin >> a[i];     }     for (int i = 0; i < N; i++) {       cin >> b[i];       m.insert(b[i]);     }     for (int i = 0; i < N; i++) {       int cur = N - a[i];       multiset<int>::iterator iter = m.lower_bound(cur);       if (iter == m.end()) {         iter = m.begin();       }       c[i] = (a[i] + (*iter)) % N;       m.erase(iter);     }     for (int i = 0; i < N; i++) {       cout << c[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int h, w, r;   } edge[110];   bool vis[11];   int x[5000000];   int n, k, t;   void init() {     cin >> n >> k >> t;     for (int i = 1; i <= k; i++) cin >> edge[i].h >> edge[i].w >> edge[i].r;   }   void solve() {     int l = 0;     for (int j = 1; j <= (1 << k) - 1; j++) {       int t = 0;       for (int i = 1; i <= k; i++)         if ((j & (1 << (i - 1))) != 0) t++;       if (t > n) continue;       memset(vis, 0, sizeof(vis));       int s = 0;       bool flag = true;       for (int i = 1; i <= k; i++)         if ((j & (1 << (i - 1))) != 0) {           if (vis[edge[i].h] || vis[edge[i].w + n]) {             flag = false;             break;           }           vis[edge[i].h] = vis[edge[i].w + n] = true;           s += edge[i].r;         }       if (flag) x[++l] = s;     }     sort(x, x + l + 1);     cout << x[t - 1] << endl;   }   int main() {     ios::sync_with_stdio(false);     init();     solve();     return 0;   }