malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int N, M;   vector<int> graph[200005];   int nd[2], deg[2];   int cnt[2][200005];   int dsu[200005];   int olddsu[200005];   int sz[4];   int getrt(int n) { return dsu[n] = (dsu[n] == n ? n : getrt(dsu[n])); }   int getoldrt(int n) {     return olddsu[n] = (olddsu[n] == n ? n : getoldrt(olddsu[n]));   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> N >> M;     for (int i = 1; i <= M; i++) {       int a, b;       cin >> a >> b;       graph[a].push_back(b);       graph[b].push_back(a);     }     cin >> nd[0] >> nd[1] >> deg[0] >> deg[1];     for (int i = 1; i <= N; i++) {       dsu[i] = i;     }     vector<pair<int, int>> ans;     for (int n = 1; n <= N; n++) {       for (int e : graph[n]) {         if (n != nd[0] && n != nd[1] && e != nd[0] && e != nd[1]) {           if (getrt(n) != getrt(e)) {             dsu[getrt(n)] = getrt(e);             ans.emplace_back(n, e);           }         }       }     }     bool spedge = 0;     for (int k = 0; k < 2; k++) {       for (int e : graph[nd[k]]) {         cnt[k][getrt(e)]++;         if (e == nd[0] || e == nd[1]) {           spedge = 1;         }       }       cnt[k][nd[0]] = cnt[k][nd[1]] = 0;     }     for (int i = 1; i <= N; i++) {       olddsu[i] = dsu[i];     }     for (int k = 0; k < 2; k++) {       for (int e : graph[nd[k]]) {         if (getrt(e) != getrt(nd[k]) && cnt[k][getoldrt(e)] &&             !cnt[k ^ 1][getoldrt(e)]) {           ans.emplace_back(e, nd[k]);           dsu[getrt(e)] = getrt(nd[k]);           deg[k]--;         }       }     }     for (int k = 0; k < 2; k++) {       for (int e : graph[nd[k]]) {         if (cnt[k][getoldrt(e)] && cnt[k ^ 1][getoldrt(e)] &&             getrt(e) != getrt(nd[k]) && deg[k] > 0) {           ans.emplace_back(e, nd[k]);           dsu[getrt(e)] = getrt(nd[k]);           deg[k]--;         }       }     }     if (deg[0] > 0 && deg[1] > 0 && spedge && getrt(nd[0]) != getrt(nd[1])) {       deg[0]--, deg[1]--;       ans.emplace_back(nd[0], nd[1]);       dsu[getrt(nd[0])] = getrt(nd[1]);     }     if (ans.size() == N - 1 && deg[0] >= 0 && deg[1] >= 0) {       cout <<  Yes n ;       for (auto p : ans) {         cout << p.first <<     << p.second <<   n ;       }     } else {       cout <<  No n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int a[200];   int main() {     int n, k;     cin >> n >> k;     for (int i = 0; i < n; i++) {       string d;       cin >> d;       a[d.size()]++;     }     string s;     cin >> s;     int k1 = s.size();     int r = 0;     for (int i = 1; i < 150; i++) {       if (k1 > i) r += a[i];     }     int p = r / k;     cout << p * 5 + r + 1 <<    ;     r += a[k1];     r--;     p = r / k;     cout << p * 5 + r + 1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int Maxn = 40005;   int n, m, c, s, t, ct, cnt, ans, b[Maxn], dis[Maxn], head[Maxn], cur[Maxn],       a[205][205], id[205][205];   long long tot;   bool vis[Maxn];   struct edg {     int nxt, to, w;   } edge[10 * Maxn];   void add(int x, int y, int w) {     edge[++cnt] = (edg){head[x], y, w};     head[x] = cnt;     edge[++cnt] = (edg){head[y], x, 0};     head[y] = cnt;   }   int dfs(int u, int T, int mini) {     if (u == T || !mini) return mini;     int w, used = 0;     vis[u] = true;     for (int i = head[u]; i; i = edge[i].nxt) {       int to = edge[i].to;       if (!vis[to] && edge[i].w) {         w = dfs(to, T, min(mini - used, edge[i].w));         used += w, edge[i].w -= w, edge[((i - 1) ^ 1) + 1].w += w;         if (mini == used) return used;       }     }     return used;   }   void dinic(int S = s, int T = t, int W = 0x3f3f3f3f, bool type = false) {     int used;     while (memset(vis, 0, sizeof(bool[ct + 1])), used = dfs(S, T, W))       W -= used, ans += type ? -used : used;   }   int main() {     scanf( %d , &n);     s = ++ct, t = ++ct;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) {         id[i][j] = ++ct;         scanf( %d , &a[i][j]);         if (a[i][j] > 0) b[++m] = a[i][j];         if (!a[i][j]) c++;       }     sort(b + 1, b + 1 + m);     m = unique(b + 1, b + 1 + m) - b - 1;     for (int j = 1; j <= n; j++)       for (int k = 1; k <= n; k++) {         if (a[j][k] == -1) continue;         if (j != n && a[j + 1][k] != -1)           add(id[j][k], id[j + 1][k], 1), add(id[j + 1][k], id[j][k], 1);         if (k != n && a[j][k + 1] != -1)           add(id[j][k], id[j][k + 1], 1), add(id[j][k + 1], id[j][k], 1);         if (a[j][k] <= 0) continue;         add(id[j][k], t, 0x3f3f3f3f);       }     for (int i = 1; i < m; i++) {       for (int j = 1; j <= n; j++)         for (int k = 1; k <= n; k++)           if (a[j][k] == b[i]) {             int w;             for (int q = head[id[j][k]]; q; q = edge[q].nxt)               if (edge[q].to == t) {                 w = edge[q].w;                 edge[q].w = edge[((q - 1) ^ 1) + 1].w = 0;                 break;               }             dinic(id[j][k], s, 0x3f3f3f3f - w, true);             add(s, id[j][k], 0x3f3f3f3f);           }       dinic();       tot += ans * (long long)(b[i + 1] - b[i]);     }     printf( %lld , tot);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   vector<int> a[1000001];   int main() {     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; ++i) {       int g;       scanf(  %d , &g);       while (g--) {         int p;         scanf(  %d , &p);         a[p].push_back(i);       }     }     sort(a, a + m + 1);     int t = 1, ans = 1;     for (int i = 2; i <= m; ++i) {       if (a[i] == a[i - 1])         ans = (long long)ans * ++t % mod;       else         t = 1;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct debugger {     template <typename T>     debugger& operator,(const T& v) {       cerr << v <<    ;       return *this;     }   } dbg;   const double PI = acos(-1);   template <class T>   T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   int n, m, a, b;   int A[100001], B[100001], L[100001];   int main() {     int n, m, a, b;     scanf( %d%d%d%d , &n, &m, &a, &b);     int width = b - a;     for (int i = 0; i < n; i++) scanf( %d , A + i);     for (int i = 0; i < m; i++) scanf( %d , B + i);     for (int i = 0; i < m; i++) scanf( %d , L + i);     double ans = -1;     int ans_a = -1, ans_b = -1;     for (int i = 0; i < m; i++) {       double ay = (double)((double)a / b) * B[i];       int aid = lower_bound(A, A + n, ay) - A;       for (int j = max(0, aid - 1); j <= min(n - 1, aid + 1); j++) {         double OA = sqrt((long long)pow(a, 2) + (long long)pow(A[j], 2));         double river_dist =             sqrt((long long)pow(width, 2) + (long long)pow(A[j] - B[i], 2));         double B_to_village = L[i];         double total_dist = OA + river_dist + B_to_village;         if (ans == -1 || total_dist < ans) {           ans = total_dist;           ans_a = j + 1;           ans_b = i + 1;         }       }     }     printf( %d %d , ans_a, ans_b);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     scanf( %d , &t);     cin.ignore();     while (t--) {       int n, arr[1030];       map<int, int> maps;       scanf( %d , &n);       for (int i = 0; i < n; i++) {         scanf( %d , &arr[i]);         maps[arr[i]]++;       }       int ans = -1;       for (int i = 1; i < 1025; i++) {         map<int, int> cpmaps;         cpmaps = maps;         bool pass = true;         for (int j = 0; j < n; j++) {           int a = arr[j] ^ i;           if (cpmaps[a])             cpmaps[a]--;           else {             pass = false;             break;           }         }         if (pass) {           ans = i;           break;         }       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> fibonacci;   void createFibbo(int num);   int main() {     int num;     cin >> num;     if (num == 0)       cout <<  0 0 0 n ;     else if (num == 1)       cout <<  0 0 1 n ;     else if (num == 2)       cout <<  0 1 1 n ;     else if (num == 3)       cout <<  1 1 1 n ;     else       createFibbo(num);     return 0;   }   void createFibbo(int num) {     int nvo = 0;     int pos = 2;     fibonacci.push_back(0);     fibonacci.push_back(1);     while (nvo != num) {       nvo = fibonacci[pos - 1] + fibonacci[pos - 2];       fibonacci.push_back(nvo);       pos++;     }     pos--;     cout << fibonacci[pos - 4] <<     << fibonacci[pos - 3] <<              << fibonacci[pos - 1] <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   bool debug = 1;   int n, m, k;   int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};   long long ln, lk, lm;   int dp[1 << 20], s[105], t[105];   string ac[105];   int main() {     scanf( %d , &n);     for (int(i) = 0; (i) < (int)(n); (i)++) scanf( %d , s + i);     sort(s, s + n);     reverse(s, s + n);     scanf( %d , &m);     for (int(i) = 0; (i) < (int)(m); (i)++) cin >> ac[i] >> t[i];     for (int i = 1; i < (1 << m); i++) {       int id = m - __builtin_popcount(i);       dp[i] = t[id] == 1 ? -(1e8) : ((1e8));       for (int j = 0; j < m; j++) {         if ((1 << j) & i) {           if (t[id] == 1) {             dp[i] = max(dp[i], (ac[id] ==  p  ? s[j] : 0) + dp[i - (1 << j)]);           } else {             dp[i] = min(dp[i], (ac[id] ==  p  ? -s[j] : 0) + dp[i - (1 << j)]);           }         }       }     }     cout << dp[(1 << m) - 1] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long n, m;     cin >> n >> m;     map<string, long> ma;     vector<string> v;     for (long i = 0; i < n; i++) {       string a;       cin >> a;       v.push_back(a);       ma[a] = 1;     }     long k = 0;     long count = 0;     for (long i = 0; i < n - 1; i++) {       for (long j = i + 1; j < n; j++) {         long ck = 0;         string c =   ;         for (long h = 0; h < m; h++) {           if (v[i][h] == v[j][h]) {             c += v[i][h];           } else {             c += char( S  +  E  +  T  - v[i][h] - v[j][h]);           }         }         if (ck == 0) {           if (ma[c] == 1) count++;         }       }     }     cout << count / 3 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const long long INF = 1e9;   const long long LINF = INF * INF;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const int N = 1 << 19;   int n, k;   vector<pair<long long, long long>> g[N];   long long dp[N][2];   int cmp(pair<long long, long long> x, pair<long long, long long> y) {     return x.second - x.first > y.second - y.first;   }   long long get(int treba, vector<pair<long long, long long>>& vec) {     long long ans = 0;     for (int i = (0); i < (treba); ++i) ans += max(vec[i].first, vec[i].second);     for (int i = (treba); i < ((int)((vec).size())); ++i) ans += vec[i].first;     return ans;   }   void dfs(int v, int p) {     int sz = (int)((g[v]).size());     if (v) --sz;     vector<pair<long long, long long>> vec(sz);     int ptr = 0;     for (auto i : g[v])       if (i.first != p) {         dfs(i.first, v);         vec[ptr++] = {dp[i.first][0], dp[i.first][1] + i.second};       }     sort(vec.begin(), vec.end(), cmp);     int zara = min((int)((vec).size()), k);     dp[v][0] = get(zara, vec);     zara = min((int)((vec).size()), k - 1);     dp[v][1] = get(zara, vec);   }   void solve() {     cin >> n >> k;     for (int i = (0); i < (n); ++i) g[i].clear();     for (int i = (0); i < (n - 1); ++i) {       int u, v, w;       cin >> u >> v >> w;       --u;       --v;       g[u].push_back({v, w});       g[v].push_back({u, w});     }     dfs(0, -1);     cout << dp[0][0] << endl;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int t;     cin >> t;     while (t--) solve();     cerr <<  Time elapsed:   << clock() / (double)CLOCKS_PER_SEC << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0;     bool f = 0;     char ch = getchar();     while (!isdigit(ch)) f |= ch ==  - , ch = getchar();     while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();     return f ? -x : x;   }   inline void write(int x) {     if (x < 0) putchar( - ), x = -x;     if (x > 9) write(x / 10);     putchar(48 + x % 10);   }   inline void writeln(int x) {     write(x);     putchar(  n );   }   inline void writebl(int x) {     write(x);     putchar(   );   }   const int maxn = 2e5 + 5;   struct edge {     int v, w, next;   } e[maxn];   int head[maxn], ecnt;   int color[maxn], out[maxn];   int tot1, tot2, n, ans = -1, want;   queue<int> q;   void dfs(int x) {     if (color[x])       ++tot1;     else       ++tot2;     q.push(x);     for (register int i = head[x]; i; i = e[i].next) {       int v = e[i].v, w = color[x] ^ want ^ e[i].w;       if (color[v] < 0) {         color[v] = w;         dfs(v);         if (tot1 < 0) return;       } else if (color[v] != w) {         tot1 = -1;         return;       }     }   }   inline void solve(int op) {     want = op;     int res = 0;     memset(color, -1, sizeof(color));     for (register int i = 1; i <= n; ++i)       if (color[i] < 0) {         while (q.size()) q.pop();         tot1 = tot2 = 0;         color[i] = 1;         dfs(i);         if (tot1 < 0) {           res = -1;           break;         }         res += tot1 < tot2 ? tot1 : tot2;         register bool t = tot1 > tot2;         while (q.size()) color[q.front()] ^= t, q.pop();       }     if ((ans == -1 || ans > res) && res != -1) {       for (register int i = 1; i <= n; ++i) out[i] = color[i];       ans = res;     }   }   int main() {     n = read();     int m = read();     for (register int i = 1; i <= m; ++i) {       int u = read(), v = read(), w;       char ch = getchar();       while (ch !=  R  && ch !=  B ) ch = getchar();       w = ch ==  R ;       e[++ecnt] = (edge){v, w, head[u]}, head[u] = ecnt;       e[++ecnt] = (edge){u, w, head[v]}, head[v] = ecnt;     }     solve(0);     solve(1);     writeln(ans);     if (ans != -1)       for (register int i = 1; i <= n; ++i)         if (out[i]) writebl(i);   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3fffffff;   const int maxn = 100010;   int n, k;   int main() {     cin >> n >> k;     if (k > (n - 1) / 2)       puts( -1 );     else {       printf( %d n , n * k);       for (int i = 0; i < n; ++i)         for (int j = 1; j <= k; ++j) printf( %d %d n , i + 1, (i + j) % n + 1);     }   }
#include <bits/stdc++.h>   using namespace std;   long long C[5001][5001], fak[5000], a, b, c, ans1, ans2, ans3;   const long long MOD = 998244353;   void generate() {     C[0][0] = 1;     for (long long i = 1; i <= 5000; i++) {       C[i][0] = 1;       for (long long j = 1; j <= i; j++) {         C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % MOD;       }     }     fak[0] = 1;     for (long long i = 1; i <= 5000; i++) {       fak[i] = (fak[i - 1] * i) % MOD;     }   }   int main() {     generate();     cin >> a >> b >> c;     for (long long i = 0; i <= min(a, b); i++) {       ans1 = (ans1 + ((C[a][i] * C[b][i]) % MOD * fak[i]) % MOD) % MOD;     }     for (long long i = 0; i <= min(b, c); i++) {       ans2 = (ans2 + ((C[c][i] * C[b][i]) % MOD * fak[i]) % MOD) % MOD;     }     for (long long i = 0; i <= min(a, c); i++) {       ans3 = (ans3 + ((C[a][i] * C[c][i]) % MOD * fak[i]) % MOD) % MOD;     }     cout << ((ans1 * ans2) % MOD * ans3) % MOD <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int long long a[200005], b[200005];   vector<int> v;   int main() {     int n, t;     scanf( %d , &t);     while (t--) {       scanf( %d , &n);       int long long neg = 0, ans = 0;       for (int i = 0; i < n; i++) {         scanf( %lld , &a[i]);       }       for (int i = n - 1; i >= 0; i--) {         neg += a[i];         if (a[i] > 0) {           if (neg > 0) {             ans += neg;             neg = 0;           }         }       }       printf( %lld n , ans);     }     return 0;   }
#include <bits/stdc++.h>   int main(int argc, char *argv[]) {     std::string s;     int n;     std::cin >> n >> s;     int con = 0;     int ans = 0;     for (int i = 0; i < s.length();) {       while (s[i] ==  x ) {         con++;         i++;       }       if (s[i] !=  x ) {         if (con >= 3) {           ans += con - 2;         }         con = 0;         i++;       }     }     if (con >= 3) {       ans += con - 2;     }     std::cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   struct FenwickTree {     vector<int> tree;     FenwickTree(int n = 0) { tree.resize(n); }     void update(int i, int delta) {       for (; i < (int)tree.size(); i |= i + 1) tree[i] += delta;     }     int sum(int ind) {       int sum = 0;       while (ind >= 0) {         sum += tree[ind];         ind &= ind + 1;         ind--;       }       return sum;     }     int sumRange(int hi, int lo) { return sum(hi) - sum(lo); }     int val(int i) { return sum(i) - sum(i - 1); }   };   int N, Q;   int main() {     scanf( %d%d , &N, &Q);     FenwickTree ft(100010);     for (int i = 1; i <= N; i++) ft.update(i, 1);     int L = 0, R = N;     bool l = true;     while (Q--) {       int op, a, b;       scanf( %d%d , &op, &a);       if (op == 1) {         int ra = R - L - a;         if (l) {           if (a <= ra) {             L += a;             for (int i = 0; i < a; i++) ft.update(L + i + 1, ft.val(L - i));           } else {             R -= ra;             for (int i = 0; i < ra; i++) ft.update(R - i, ft.val(R + i + 1));             l = false;           }         } else {           if (a <= ra) {             R -= a;             for (int i = 0; i < a; i++) ft.update(R - i, ft.val(R + i + 1));           } else {             L += ra;             for (int i = 0; i < ra; i++) ft.update(L + i + 1, ft.val(L - i));             l = true;           }         }       } else {         scanf( %d , &b);         int ans = l ? ft.sumRange(L + b, L + a) : ft.sumRange(R - a, R - b);         printf( %d n , ans);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       int n, k;       cin >> n >> k;       for (int i = 0; i < n; i++) {         char c =  a  + i % k;         cout << c;       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool sortbysec(const array<long long int, 2> &a,                  const array<long long int, 2> &b) {     return (a[0] > b[0]);   }   long long int gcd(long long int a, long long int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   bool inline isPrime(long long int n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (long long int i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   bool isPowerOfTwo(long long int n) {     if (n == 0) return false;     return (ceil(log2(n)) == floor(log2(n)));   }   bool prtv(vector<long long int> e) {     for (auto &i : e) cout << i <<    ;     cout <<   n ;   }   void prt(int i) {     if (i == 1)       cout <<  YES n ;     else       cout <<  NO n ;   }   int getSum(int n) {     int sum = 0;     while (n != 0) {       sum = sum + n % 10;       n = n / 10;     }     return sum;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int test = 1;     while (test--) {       set<string> hai;       queue<string> bachi;       long long int count = 0, k, ans = 0, n;       cin >> n >> k;       string s;       cin >> s;       bachi.push(s);       while (!bachi.empty() && count < k) {         string temp = bachi.front();         bachi.pop();         long long int sz = temp.size();         if (hai.find(temp) != hai.end()) continue;         hai.insert(temp);         count++;         ans += (n - sz);         if (sz == 1) continue;         string foo;         for (long long int i = (0); i < (sz); i += 1) {           foo = temp;           foo = foo.erase(i, 1);           bachi.push(foo);         }       }       if (count == k - 1) ans += n;       if (count < k - 1) ans = -1;       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1000000000;   const int MAXN = 1 << 20;   const long long MOD = 1e9 + 7;   template <typename T>   void chmin(T &a, T b) {     if (a > b) a = b;   }   template <typename T>   void chmax(T &a, T b) {     if (a < b) a = b;   }   template <typename T>   void add(T &a, T b) {     a += b;     if (a < 0) a += MOD;     if (a >= MOD) a -= MOD;   }   int in() {     int x;     scanf( %d , &x);     return x;   }   long long lin() {     long long x;     scanf( %lld , &x);     return x;   }   double din() {     double x;     scanf( %lf , &x);     return x;   }   long long p2[64];   void initP2() {     p2[0] = 1;     for (int i = (1); i <= (63); ++i) {       p2[i] = p2[i - 1] * 2;     }   }   int countBitsBaseB(long long n, long long b) {     if (n == 0) return 1;     int ret = 0;     while (n) {       ret++;       n /= b;     }     return ret;   }   int count1(long long n) {     int ret = 0;     while (n) {       ret += n & 1;       n >>= 1;     }     return ret;   }   long long c[1024][1024] = {0};   void initC() {     for (int i = 0; i < (1024); ++i) {       for (int j = 0; j < (i + 1); ++j) {         if (j == 0 || j == i) {           c[i][j] = 1;         } else {           c[i][j] = c[i - 1][j - 1];           add(c[i][j], c[i - 1][j]);         }       }     }   }   void init() {     initP2();     initC();   }   void mul(int a[(1 << 8)][(1 << 8)], int b[(1 << 8)][(1 << 8)], int n) {     int c[(1 << 8)][(1 << 8)] = {0};     for (int i = 0; i < (n); ++i) {       for (int k = 0; k < (n); ++k) {         if (a[i][k])           for (int j = 0; j < (n); ++j) {             if (b[k][j]) {               long long tmp = (long long)a[i][k] * b[k][j];               if (tmp >= MOD) tmp %= MOD;               add(c[i][j], (int)tmp);             }           }       }     }     for (int i = 0; i < (n); ++i) {       for (int j = 0; j < (n); ++j) {         a[i][j] = c[i][j];       }     }   }   int mat[(1 << 8)][(1 << 8)];   int ret[(1 << 8)][(1 << 8)];   int pos(int x, int y, int n) { return x * n + y; }   int main() {     init();     int n = in();     int f = in();     int m = in();     memset((mat), (0), sizeof((mat)));     memset((ret), (0), sizeof((ret)));     const int matSize = (f + 1) * p2[m];     for (int i = 0; i < (matSize); ++i) {       ret[i][i] = 1;     }     for (int i = 0; i < (f + 1); ++i) {       for (int j = 0; j < (p2[m]); ++j) {         const int to = pos(i, j, p2[m]);         int from = pos(i, (j << 1) & (p2[m] - 1), p2[m]);         mat[from][to]++;         if (i + 1 <= f) {           from = pos(i + 1, ((j << 1) | 1) & (p2[m] - 1), p2[m]);           mat[from][to] += 1 + count1(j);         }       }     }     while (n) {       if (n & 1) {         mul(ret, mat, matSize);       }       mul(mat, mat, matSize);       n >>= 1;     }     long long ans = 0;     for (int i = 0; i < (p2[m]); ++i) {       ans += ret[pos(f, i, p2[m])][pos(0, 0, p2[m])];     }     cout << ans % MOD << endl;     return 0;   }