malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100100;   inline long long int max(long long int a, long long int b) {     return a > b ? a : b;   }   inline long long int min(long long int a, long long int b) {     return a > b ? b : a;   }   inline int read() {     int x = 0;     char c = getchar();     while (c <  0  || c >  9 ) c = getchar();     while (c >=  0  && c <=  9 ) x = x * 10 + c -  0 , c = getchar();     return x;   }   long long int sum[maxn * 4], mq[maxn * 4], dl[maxn * 4], dr[maxn * 4];   int lb[maxn * 4], rb[maxn * 4];   int N, M;   int a[maxn];   inline void update(int i) {     if (lb[i] == rb[i]) {       sum[i] = fabs(dr[i]);       mq[i] = max(dl[i], 0) + max(dr[i], 0);       return;     }     sum[i] = sum[i << 1] + sum[(i << 1) + 1];     mq[i] = min(mq[i << 1], mq[(i << 1) + 1]);   }   inline void updateall(int i) {     while (i > 1) {       update(i);       i = i >> 1;     }     update(1);   }   void build(int i, int l, int r) {     lb[i] = l;     rb[i] = r;     if (l == r) {       dl[i] = a[l - 1] - a[l];       dr[i] = a[l + 1] - a[l];       sum[i] = fabs(dr[i]);       mq[i] = max(dl[i], 0) + max(dr[i], 0);     } else {       int m = (l + r) >> 1;       build(i << 1, l, m);       build((i << 1) + 1, m + 1, r);       update(i);     }   }   long long int getmq(int i, int l, int r) {     if (l == lb[i] && r == rb[i]) return mq[i];     int m = (lb[i] + rb[i]) >> 1;     long long int re = 1e9 + 10;     if (l <= m) re = min(re, getmq(i << 1, l, min(m, r)));     if (r > m) re = min(re, getmq((i << 1) + 1, max(m + 1, l), r));     return re;   }   int find(int x, int i) {     if (lb[i] == rb[i] && lb[i] == x)       return i;     else if (x <= ((lb[i] + rb[i]) >> 1))       return find(x, i << 1);     else       return find(x, (i << 1) + 1);   }   inline long long int solve1(int l, int r, int x) {     if (l == r) {       int p = find(l, 1);       return fabs(dl[p] - x) + fabs(dr[p] - x) - fabs(dl[p]) - fabs(dr[p]) +              sum[1];     } else {       return max(0, 2 * x - 2 * getmq(1, l, r)) + sum[1];     }   }   inline void solve2(int l, int r, int x) {     int p = find(l, 1);     dl[p] -= x;     updateall(p);     p = find(l - 1, 1);     dr[p] += x;     updateall(p);     p = find(r, 1);     dr[p] -= x;     updateall(p);     p = find(r + 1, 1);     dl[p] += x;     updateall(p);   }   int main() {     int i, j, k, x, y;     N = read();     for (i = 1; i <= N; i++) a[i] = read();     a[N + 1] = a[N];     a[0] = a[1];     build(1, 1, N);     M = read();     for (i = 1; i <= M; i++) {       j = read();       k = read();       x = read();       y = read();       if (j == 1) {         printf( %I64d n , solve1(k, x, y));       } else {         solve2(k, x, y);       }     }   }
#include <bits/stdc++.h>   long long T, n, k;   long long a, sum, num;   int main() {     scanf( %I64d%I64d , &n, &k);     for (long long i = 1; i <= n; i++) {       scanf( %I64d , &a);       if (sum - (i - 1 - num) * (n - i) * a >= k)         sum += a * (i - 1 - num);       else {         printf( %I64d n , i);         num++;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9, MOD = 1e9 + 7,             around[] = {0, 1, 1, -1, -1, 0, -1, 1, 0, 0};   const long long LINF = 1e18;   const long double PI = abs(acos(-1));   int a, b, c;   int main() {     cin >> a >> b >> c;     for (int x1 = (0); x1 < (3); x1++) {       for (int x2 = (0); x2 < (3); x2++) {         for (int x3 = (0); x3 < (3); x3++) {           bool li[1500 * 1510 + 1] = {};           int ma = 0;           for (int i = (0); i < (max(a, max(b, c))); i++) {             li[x1 + a * i] = li[x2 + b * i] = li[x3 + c * i] = true;             ma = max(x1 + a * i, max(x2 + b * i, x3 + c * i));           }           for (int i = 0; x1 + a * i < ma; i++) li[x1 + a * i] = true;           for (int i = 0; x2 + b * i < ma; i++) li[x2 + b * i] = true;           for (int i = 0; x3 + c * i < ma; i++) li[x3 + c * i] = true;           bool f = true;           for (int i = (0); i < (ma + 1); i++) f = f & li[i];           if (f) {             cout <<  YES  << endl;             return 0;           }         }       }     }     cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dp[3001];   int n;   struct node {     int pos, val;     bool operator<(const node& a) const { return val < a.val; }   } nodes[3001];   int main() {     int t;     scanf( %d , &t);     while (t--) {       int ans = 0;       scanf( %d , &n);       for (int i = 0; i < n; i++) {         scanf( %d , &nodes[i].val);         nodes[i].pos = i;       }       sort(nodes, nodes + n);       dp[0] = 1;       for (int i = 1; i < n; i++) {         if (nodes[i - 1].pos < nodes[i].pos)           dp[i] = dp[i - 1] + 1;         else           dp[i] = 1;         ans = max(ans, dp[i]);       }       ans = max(ans, dp[0]);       printf( %d n , n - ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = ~0u >> 1, MOD = 1e9 + 7;   inline int rd() {     int first = 0, c = 0, f = 1;     for (; c <  0  || c >  9 ; c = getchar()) f = c !=  - ;     for (; c >=  0  && c <=  9 ; c = getchar()) first = first * 10 + c -  0 ;     return f ? first : -first;   }   const int N = 2e5 + 11;   struct Edge {     int v, id;     Edge *nex;   } pl[N << 1], *cur = pl, *G[N];   void ins(int u, int v, int id) {     cur->v = v, cur->id = id;     cur->nex = G[u], G[u] = cur++;   }   int wx[N], wy[N], n, m;   int f[N], vis[N], g[N];   void dfs(int first) {     vis[first] = 1;     for (Edge *i = G[first]; i; i = i->nex)       if (!vis[i->v]) {         dfs(i->v);         if (f[i->v]) {           f[i->v] = 0;           f[first] ^= 1;           g[i->id] ^= 1;         }       }   }   int q[N];   int main() {     n = rd(), m = rd();     for (int i = (1), i_end = (m); i <= i_end; i++) {       wx[i] = rd(), wy[i] = rd();       ins(wx[i], wy[i], i), ins(wy[i], wx[i], i);       f[wx[i]] ^= 1;     }     for (int i = (1), i_end = (n); i <= i_end; i++)       if (!vis[i]) dfs(i);     int ans = m;     for (int i = (1), i_end = (n); i <= i_end; i++)       if (f[i]) ans--;     printf( %d n , ans >> 1);     for (int first = (1), x_end = (n); first <= x_end; first++) {       int cnt = 0;       for (Edge *i = G[first]; i; i = i->nex)         if ((wy[i->id] != first) ^ g[i->id]) {           q[++cnt] = (wx[i->id] ^ wy[i->id] ^ first);         }       for (int i = 1; i < cnt; i += 2) {         printf( %d %d %d n , q[i], first, q[i + 1]);       }     }   }
#include <bits/stdc++.h>   using namespace std;   int lsb(int val) { return val & ((val ^ (val - 1))); }   pair<int, pair<int, int> > a[600666];   int Arb[600666], SEG[600666], result[600666];   bool comp(pair<int, pair<int, int> > i1, pair<int, pair<int, int> > i2) {     return i1.second.second < i2.second.second;   }   int query(int pos) {     if (pos) return Arb[pos] + query(pos - lsb(pos));     return 0;   }   void update(int pos, int n) {     if (pos > n) return;     Arb[pos]++;     update(pos + lsb(pos), n);   }   int bs(int value, int n, int A[]) {     int left = 1, right = n + 1;     while (left < right - 1) {       int mid = (right + left) / 2;       if (A[mid] <= value)         left = mid;       else         right = mid;     }     return left;   }   int main() {     cin.sync_with_stdio(false);     int n, i, nr_seg = 0;     cin >> n;     for (i = 1; i <= n; ++i) {       cin >> a[i].second.first >> a[i].second.second;       a[i].first = i;       SEG[++nr_seg] = a[i].second.first;       SEG[++nr_seg] = a[i].second.second;     }     sort(SEG + 1, SEG + nr_seg + 1);     sort(a + 1, a + n + 1, comp);     for (i = 1; i <= n; ++i) {       a[i].second.first = bs(a[i].second.first, nr_seg, SEG);       a[i].second.second = bs(a[i].second.second, nr_seg, SEG);     }     for (i = 1; i <= n; ++i) {       result[a[i].first] = query(a[i].second.second) - query(a[i].second.first);       update(a[i].second.first, n * 2);     }     for (i = 1; i <= n; ++i) cout << result[i] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     while (b != 0) {       int r = a % b;       a = b;       b = r;     }     return a;   }   void FindMinimum(int a[], int &n) {     int g = gcd(a[0], a[1]);     for (int i = 2; i < n; ++i) g = gcd(a[i], g);     cout << g * n;   }   int main() {     int n, a[100];     cin >> n;     for (int i = 0; i < n; ++i) cin >> a[i];     sort(a, a + n);     FindMinimum(a, n);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int expo(int base, int exponent, int mod) {     int ans = 1;     while (exponent != 0) {       if (exponent & 1) ans = (1LL * ans * base) % mod;       base = (1LL * base * base) % mod;       exponent >>= 1;     }     return ans % mod;   }   int n, a[5005], ans[10005], pre[5005], inv[5005];   int up[5005][10005];   int get_down(int l, int r) {     if (l <= 0 or r < 0) return 0;     if (r == 0) return 1;     r = l + r - 1;     if (r >= n) return 0;     return 1LL * pre[r] * inv[l - 1] % 1000000007;   }   void solve() {     cin >> n;     for (int i = 1; i < n; i++) cin >> a[i];     a[0] = pre[0] = inv[0] = 1;     for (int i = 1; i < n + 1; i++)       pre[i] = 1LL * a[i] * pre[i - 1] % 1000000007,       inv[i] = expo(pre[i], 1000000007 - 2, 1000000007);     for (int i = 1; i < n + 1; i++) {       for (int j = 1; j < 2 * n - 1; j++) {         if (i >= 2)           up[i][j] = (0LL + up[i - 1][j - 1] + get_down(i - 1, j - 1) -                       get_down(i, j - 2) + 1000000007) %                      1000000007;         ans[j] = (ans[j] + 1LL * pre[i - 1] * (up[i][j] + get_down(i, j))) %                  1000000007;       }     }     for (int i = 1; i < 2 * n - 1; i++)       cout << 1LL * ans[i] * (1000000007 + 1) / 2 % 1000000007 <<    ;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int nax = 2e5 + 10;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, f;     cin >> n >> f;     vector<int> k(n), l(n);     vector<pair<int, int> > a;     for (int i = 0; i < n; i++) {       cin >> k[i] >> l[i];       a.push_back({min(2 * k[i], l[i]) - min(k[i], l[i]), i});     }     sort(a.rbegin(), a.rend());     ll ans = 0;     for (int i = 0; i < f; i++) {       ans += min(2 * k[a[i].second], l[a[i].second]);     }     for (int i = f; i < n; i++) {       ans += min(k[a[i].second], l[a[i].second]);     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 987654321;   bool adj[4010][4010];   int n, m, u, v, cnt[4010];   vector<vector<int> > node;   int main() {     scanf( %d%d , &n, &m);     node.resize(n + 1);     while (m--) {       scanf( %d%d , &u, &v);       node[u].push_back(v);       node[v].push_back(u);       adj[u][v] = adj[v][u] = true;     }     for (int i = 1; i <= n; ++i) cnt[i] = node[i].size();     int sol = INF;     for (int i = 1; i <= n; ++i) {       for (int j = i + 1; j <= n; ++j) {         if (!adj[i][j]) continue;         for (int a = 0; a < node[i].size(); ++a) {           int k = node[i][a];           if (!adj[k][j]) continue;           sol = min(sol, cnt[i] + cnt[j] + cnt[k] - 6);         }       }     }     printf( %d n , sol == INF ? -1 : sol);   }
#include <bits/stdc++.h>   using namespace std;   struct wall {     double x, y;     wall() {}     wall(double x, double y) : x(x), y(y) {}   };   struct tx {     double d;     int v;     tx() {}     tx(double d, int v) : d(d), v(v) {}   };   bool cmp2(const tx& p1, const tx& p2) { return p1.d < p2.d; }   bool cmp(const wall& p1, const wall& p2) { return p1.x < p2.x; }   int dcmp(double x) { return fabs(x) < 1e-8 ? 0 : (x > 0 ? 1 : -1); }   wall w[2000001];   wall ans[2000001];   int n, m;   int f[2000001];   double V;   tx ang[2000001];   int main() {     scanf( %d %lf , &n, &V);     for (int i = 1; i <= n; i++) {       scanf( %lf , &ang[i].d);       ang[i].v = i;     }     scanf( %d , &m);     for (int i = 1; i <= m; i++) scanf( %lf %lf , &w[i].x, &w[i].y);     sort(w + 1, w + 1 + m, cmp);     sort(ang + 1, ang + 1 + n, cmp2);     int tp = 1;     for (int i = 1; i <= n; i++) {       int flag = 0;       if (tp > m) ans[i] = wall(V * V * sin(2 * ang[i].d) / 9.8, 0.0);       while (tp <= m) {         double tmpx = (w[tp].x * sin(2 * ang[i].d) / 2.0) -                       (9.8 * w[tp].x * w[tp].x / (2.0 * V * V));         tmpx /= cos(ang[i].d) * cos(ang[i].d);         if (tmpx <= 0.0) {           ans[i] = wall(V * V * sin(2 * ang[i].d) / 9.8, 0.0), flag = 1;           break;         } else if (!dcmp(tmpx - w[tp].y) || tmpx < w[tp].y) {           ans[i] = wall(w[tp].x, tmpx);           flag = 1;           break;         } else           tp++;       }       if (!flag) ans[i] = wall(V * V * sin(2 * ang[i].d) / 9.8, 0.0);     }     for (int i = 1; i <= n; i++) f[ang[i].v] = i;     for (int i = 1; i <= n; i++)       printf( %.9lf %.9lf n , ans[f[i]].x, ans[f[i]].y);     return 0;   }
#include <bits/stdc++.h>   #define mset(arr, val) memset(arr, val, sizeof(arr))   #define all(v) v.begin(), v.end()   #define F first   #define S second   #define endl   n    using namespace std;   // const double PI = acos(-1.0);   // const double E = exp(1.0);   // const double EPS = 1e-9;   const int MOD = (int)1e9 + 7;   const int N = (int)2e5;      int main() {   #ifdef MY_LOCAL       freopen( in.txt ,  r , stdin);       freopen( out.txt ,  w , stdout);   #endif       ios_base::sync_with_stdio(false);       cin.tie(0);          int T;       cin >> T;       for (int tc = 1; tc <= T; tc++) {           int n;           cin >> n;           vector<int> a(n);           map<int, int> mp;           cin >> a[0];           mp[a[0]] = 0;           for (int i = 1; i < n; i++) {               cin >> a[i];               if (a[i] != a[i - 1]) {                   mp[a[i]]++;               }           }                      int ans = INT32_MAX;           for (auto x : mp) {               if (x.first != a[n - 1]) {                   x.second++;               }               ans = min(ans, x.second);           }           if (ans == INT32_MAX) {               ans = 0;           }           cout << ans << endl;       }          return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e3 + 5;   vector<int> mp[maxn];   vector<int> R[maxn];   vector<int> L[maxn];   int ans = 0;   bool vis[maxn];   int n, m;   struct node {     int last_L;     int last_R;   } last[maxn];   void dfs(int now, int l, int r) {     if (now == n) {       ans = max(ans, r - l + 1);       return;     }     for (int i = 0; i < mp[now].size(); i++) {       if (vis[mp[now][i]]) continue;       int nl = max(l, L[now][i]);       int nr = min(r, R[now][i]);       vis[mp[now][i]] = 1;       if (nl <= nr && nr - nl + 1 > ans &&           !(last[mp[now][i]].last_L <= nl && last[mp[now][i]].last_R >= nr))         last[mp[now][i]].last_L = nl, last[mp[now][i]].last_R = nr,         dfs(mp[now][i], nl, nr);       vis[mp[now][i]] = 0;     }     return;   }   int main() {     ios::sync_with_stdio(0);     cin >> n >> m;     for (int i = 1; i <= m; i++) {       int a, b, l, r;       cin >> a >> b >> l >> r;       mp[a].push_back(b);       mp[b].push_back(a);       L[a].push_back(l);       L[b].push_back(l);       R[a].push_back(r);       R[b].push_back(r);     }     vis[1] = 1;     last[1].last_L = 1;     last[1].last_R = INT_MAX;     dfs(1, 1, INT_MAX);     if (!ans)       cout <<  Nice work, Dima!  << endl;     else       cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Data {     int Value, Number;   };   bool operator<(Data A, Data B) { return A.Value < B.Value; }   int Get() {     char c;     while (c = getchar(), c <  0  || c >  9 )       ;     int X = 0;     while (c >=  0  && c <=  9 ) {       X = X * 10 + c - 48;       c = getchar();     }     return X;   }   void Output(int X) {     int Len = 0, Data[10];     while (X) {       Data[Len++] = X % 10;       X /= 10;     }     if (!Len) Data[Len++] = 0;     while (Len--) putchar(Data[Len] + 48);   }   int main() {     int N = Get();     static Data A[100000];     for (int i = 0; i < N; i++) {       A[i].Value = Get();       A[i].Number = i;     }     sort(A, A + N);     static int X[100000], Y[100000];     memset(X, 0, sizeof(X));     memset(Y, 0, sizeof(Y));     int K = (N - 1) / 3 + 1, T = N - K * 2;     for (int i = 0; i < K; i++) {       X[A[i].Number] = A[i].Value;       Y[A[i + K].Number] = A[i + K].Value;     }     for (int i = K * 2; i < N; i++) {       X[A[i].Number] = A[i].Value - N + i;       Y[A[i].Number] = N - i;     }     printf( YES n );     for (int i = 0; i < N; i++) {       Output(X[i]);       putchar((i + 1 == N) ?   n  :    );     }     for (int i = 0; i < N; i++) {       Output(Y[i]);       putchar((i + 1 == N) ?   n  :    );     }     return 0;   }
#include <bits/stdc++.h>   int64_t a[400005], b[200005];   int64_t len;   int n;   bool check(int64_t value) {     std::vector<std::pair<int64_t, int64_t>> v;     for (int i = 0; i < n; ++i) {       auto rg = std::make_pair(b[i] - value, b[i] + value);       if (rg.first < 0) {         rg.first += len;         rg.second += len;       }       v.push_back(rg);       if (rg.second < len) v.emplace_back(rg.first + len, rg.second + len);     }     std::sort(v.begin(), v.end());     int pa = 0, pr = 0;     while (pr < (int)v.size()) {       while (pa < n * 2 && (a[pa] < v[pr].first || a[pa] > v[pr].second)) ++pa;       if (pa >= n * 2)         return false;       else {         ++pa;         ++pr;       }     }     return true;   }   int main(int argc, char* argv[]) {     scanf( %d%lld , &n, &len);     for (int i = 0; i < n; ++i) scanf( %lld , &a[i]);     for (int i = 0; i < n; ++i) scanf( %lld , &b[i]);     std::sort(a, a + n);     for (int i = 0; i < n; ++i) a[n + i] = a[i] + len;     int64_t left = 0, right = len;     int64_t ans = 0;     while (right >= left) {       int64_t mid = (left + right) / 2;       if (check(mid)) {         ans = mid;         right = mid - 1;       } else         left = mid + 1;     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   inline int add(int a, int b) {     if ((a += b) >= mod) a -= mod;     return a;   }   inline int mult(int a, int b) {     long long t = 1ll * a * b;     if (t >= mod) t %= mod;     return t;   }   inline int dec(int a, int b) {     if ((a -= b) < 0) a += mod;     return a;   }   int n, q, a[200010], w[200010];   inline int lowbit(int x) { return x & (-x); }   class tree1 {    public:     long long dat[200010];     void modify(int p, int v) {       for (; p <= n; p += lowbit(p)) dat[p] += v;     }     long long query(int p) {       long long ret = 0;       for (; p; p -= lowbit(p)) ret += dat[p];       return ret;     }     long long query(int l, int r) { return query(r) - query(l - 1); }   } T1;   class tree2 {    public:     int dat[200010];     void modify(int p, int v) {       for (; p <= n; p += lowbit(p)) dat[p] = add(dat[p], v);     }     int query(int p) {       int ret = 0;       for (; p; p -= lowbit(p)) ret = add(ret, dat[p]);       return ret;     }     int query(int l, int r) { return dec(query(r), query(l - 1)); }   } T2;   int x, y;   int main() {     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++) {       scanf( %d , &w[i]);       T1.modify(i, w[i]);       T2.modify(i, mult(w[i], a[i] - i));     }     while (q--) {       scanf( %d%d , &x, &y);       if (x < 0) {         x = -x;         T1.modify(x, y - w[x]);         T2.modify(x, mult(dec(y, w[x]), a[x] - x));         w[x] = y;       } else {         if (x == y) {           puts( 0 );           continue;         }         int L = x, R = y, pos = L;         while (L <= R) {           int mid = (L + R) >> 1;           if (T1.query(x, mid) >= T1.query(mid + 1, y))             pos = mid, R = mid - 1;           else             L = mid + 1;         }         printf( %d n , add(dec(mult(a[pos] - pos, T1.query(x, pos) % mod),                                T2.query(x, pos)),                            dec(T2.query(pos, y),                                mult(a[pos] - pos, T1.query(pos, y) % mod))));       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int main() {     cin >> n;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     bool b = false;     for (int i = 2; i < n; i++) {       if (a[i - 2] + a[i - 1] > a[i] && a[i] + a[i - 1] > a[i - 2] &&           a[i - 2] + a[i] > a[i - 1]) {         b = true;         break;       }     }     cout << (b ?  YES  :  NO ) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int nCase;     scanf( %d , &nCase);     while (nCase--) {       int a, b;       scanf( %d%d , &a, &b);       if (a == 0) {         if (b == 0)           printf( 1 n );         else           printf( 0.5 n );         continue;       }       if (b == 0) {         printf( 1 n );         continue;       }       b *= 4;       if (a >= b)         printf( %.6f n , (0.5 * (a - b + a) * b + 1.0 * a * b) / (2.0 * b * a));       else         printf( %.6f n , (1.0 * a * b + 0.5 * a * a) / (2.0 * b * a));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void faster() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   const int MAXN = 2e5 + 1;   const long long INF = 1e18;   const long long MOD = 1e9 + 7;   const long double PI = acos(-1);   long long n, a[MAXN], dp[MAXN], d[MAXN], cnt[MAXN], ans;   vector<pair<int, bool>> g[MAXN];   bool is_lucky(int x) {     bool res = 1;     while (x) {       res &= (((x % 10) == 7) | ((x % 10) == 4));       x /= 10;     }     return res;   }   void dfs(int v, int pr = 0) {     cnt[v] = 1;     for (pair<int, int> x : g[v]) {       int to = x.first, cost = x.second;       if (to == pr) continue;       dfs(to, v);       cnt[v] += cnt[to];       if (cost)         d[v] += cnt[to];       else         d[v] += d[to];     }   }   void dfs_a(int v, int pr, long long res) {     ans += (res * (res - 1));     for (pair<int, int> x : g[v]) {       int to = x.first, cost = x.second;       if (pr == to) continue;       if (cost)         dfs_a(to, v, d[to] + (cnt[1] - cnt[to]));       else         dfs_a(to, v, res);     }   }   int main() {     faster();     cin >> n;     for (int i = 1, v, u, w; i < n; ++i) {       cin >> u >> v >> w;       w = is_lucky(w);       g[u].push_back({v, w});       g[v].push_back({u, w});     }     dfs(1);     dfs_a(1, 0, d[1]);     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int powmod(int x, int y, int p) {     int res = 1;     x = x % p;     if (x == 0) return 0;     while (y > 0) {       if (y % 2 == 1) res = (res * x) % p;       y /= 2;       x = (x * x) % p;     }     return res;   }   string dectobin(int x) {     string s =   ;     while (x > 0) {       int t = x % 2;       s.push_back(t +  0 );       x /= 2;     }     reverse(s.begin(), s.end());     if (s.compare(  ) == 0)       return  0 ;     else       return s;   }   int long long bintodec(string s) {     int long long ans = 0;     int long long n = s.size();     for (int long long i = n - 1; i >= 0; i--) {       if (s[i] ==  1 ) ans += pow(2, n - i - 1);     }     return ans;   }   int find(int k, int n) { return ((n & (1 << (k - 1))) >> (k - 1)); }   int long long f[100000 + 1];   int32_t main() {     f[0] = 1;     f[1] = 1;     for (int i = 2; i <= 100000; i++) {       f[i] = ((i << 1) - 1ll) * f[i - 1] % 1000000007 * (i << 1) % 1000000007;     }     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       int long long n;       cin >> n;       cout << f[n] <<   n ;     }   }