malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long f[3], x, y, z, k;   int main() {     long long a, b, c;     long long r;     cin >> f[0] >> f[1] >> f[2] >> k;     sort(f, f + 3);     k += 3;     k = min(k, f[0] + f[1] + f[2]);     a = f[0] * 3 <= k ? f[0] : k / 3;     r = k - a;     b = f[1] * 2 <= r ? f[1] : r >> 1;     c = k - a - b;     cout << a * b * c << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = (int)1e6 + 9;   int n, d[N];   int digit(int x) {     int s = 0;     while (x > 0) {       s += x % 10;       x /= 10;     }     return s;   }   vector<int> b[10];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n;     for (int i = 1; i < 10; ++i) d[i] = i;     for (int i = 10; i < N; ++i) d[i] = d[digit(i)];     for (int i = 1; i <= n; ++i) b[d[i]].emplace_back(i);     long long ans = 0;     for (int i = 1, cnt; i <= n; ++i) {       for (int j = 1; j < 10; ++j)         if (!b[j].empty()) {           cnt = upper_bound(b[j].begin(), b[j].end(), n / i) - b[j].begin();           ans += (long long)b[j].size() * b[d[d[i] * j]].size() - cnt;         }     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 300001;   const int logn = 20;   bool s[maxn][logn];   int nxt[maxn][logn];   int f[maxn][logn];   int a[maxn];   int tmp[maxn];   int n, q;   int main() {     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     for (int j = 0; j < logn; j++) {       int cnt = 0;       for (int i = 1; i <= n; i++) {         if (!(a[i] >> j & 1)) continue;         s[i][j] = 1;         tmp[++cnt] = i;       }       for (int i = 1; i < cnt; i++) {         nxt[tmp[i]][j] = tmp[i + 1];       }     }     for (int i = n; i >= 1; i--) {       for (int j = 0; j < logn; j++) {         if (s[i][j])           f[i][j] = i;         else {           f[i][j] = n + 1;           for (int k = 0; k < logn; k++) {             if (s[i][k] && nxt[i][k]) f[i][j] = min(f[i][j], f[nxt[i][k]][j]);           }         }       }     }     for (int i = 1; i <= q; i++) {       int x, y;       scanf( %d%d , &x, &y);       bool ans = 0;       for (int j = 0; j < logn; j++) {         if (s[y][j] && f[x][j] <= y) ans = 1;       }       if (ans)         printf( Shi n );       else         printf( Fou n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Bug {     int a, id;   } B[100005];   struct Stu {     int b, c, id;     bool operator<(const Stu &A) const { return c > A.c; }   } S[100005];   int n, m, s;   int ans[100005];   int ans1[100005];   bool cmp(Bug A, Bug B) { return A.a > B.a; }   bool cmp1(Stu A, Stu B) { return A.b > B.b; }   bool check(int k) {     int cost = s;     int l = 0, r = 0;     priority_queue<Stu> P;     while (l < m) {       while (r < n && S[r].b >= B[l].a) {         P.push(S[r++]);       }       Stu T;       if (P.size())         T = P.top(), P.pop();       else {         return false;       }       cost -= T.c;       if (cost < 0) return false;       for (int i = l; i < l + k && i < m; i++) ans1[B[i].id] = T.id + 1;       l += k;     }     for (int i = 0; i < m; i++) ans[i] = ans1[i];     return true;   }   int main() {     scanf( %d%d%d , &n, &m, &s);     int Max = 0, Min = 0;     for (int i = 0; i < m; i++) {       scanf( %d , &B[i].a);       B[i].id = i;       if (B[i].a > Min) Min = B[i].a;     }     for (int i = 0; i < n; i++) {       scanf( %d , &S[i].b);       S[i].id = i;     }     for (int i = 0; i < n; i++) {       scanf( %d , &S[i].c);       if (S[i].b > Max && S[i].c <= s) Max = S[i].b;     }     sort(B, B + m, cmp);     sort(S, S + n, cmp1);     int l = 1, r = m + 1;     while (l < r) {       int m = (l + r) / 2;       if (check(m))         r = m;       else         l = m + 1;     }     if (Max < Min)       puts( NO );     else {       puts( YES );       for (int i = 0; i < m; i++) printf( %d  , ans[i]);       puts(  );     }     return 0;   }
#include<bits/stdc++.h>   using namespace std;   #define ll long long int   #define rep(i,a,b) for(int i=a;i<b;i++)   #define arrr int n;cin>>n;int a[n];for(int i=0;i<n;i++){cin>>a[i];}   const int N = 1e6;   // bool prime[1000001]={true};      // void sieve(){   //    memset(prime,1,sizeof(prime));   //    prime[0]=prime[1]=false;   //    for(ll i=2 ; i*i<=N ; i++){   //          for(int j=i*2 ; j<=N;j+=i){   //             prime[j] = false;   //          }   //    }   // }                void solve(){      int n;      cin>>n;      if(n>1099){         cout<< YES <<  n ;         return;      }         while(n>=0){         if(n%11 == 0){            cout<< YES <<  n ;            return;         }         n-=111;      }      cout<< NO <<  n ;   }       int main(){          ios_base::sync_with_stdio(false);      cin.tie(NULL); cout.tie(NULL);               int t;      t=1;      cin>>t;      while(t--)solve();                                     }
#include <bits/stdc++.h>   using namespace std;   long long MOD = 1000000007;   long long power(long long x, long long n, long long mod) {     if (n == 0) {       return 0;     }     long long temp = power(x, n / 2, mod);     if (n % 2 == 1) {       return (x * temp * temp) % mod;     } else {       return (temp * temp) % mod;     }   }   long long abs(long long a, long long b) {     if (a > b) {       return a - b;     }     return b - a;   }   int main(int argc, const char* argv[]) {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n;     cin >> n;     if (n % 2 == 0) {       cout <<  NO  << endl;       return 0;     }     cout <<  YES  << endl;     for (long long i = 1; i <= (n); i++) {       if (i != 1) {         cout <<    ;       }       cout << 2 * i - 1 + (i % 2 == 0);     }     for (long long i = 1; i <= (n); i++) {       if (i != 0) {         cout <<    ;       }       cout << 2 * i - 1 + (i % 2 == 1);     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[200222];   int main() {     while (scanf( %s , s) > 0) {       int n = strlen(s);       int a, b, c;       a = b = c = 0;       for (int i = 0; i < n; i++) {         if (s[i] ==  0 )           a++;         else if (s[i] ==  1 )           b++;       }       int fst = (n - 1) / 2;       int snd = (n - 2) / 2;       if (b <= fst) puts( 00 );       if (a <= snd + 1 && b + (s[n - 1] ==  ? ) <= fst + 1 && s[n - 1] !=  0 )         puts( 01 );       if (b <= fst + 1 && a + (s[n - 1] ==  ? ) <= snd + 1 && s[n - 1] !=  1 )         puts( 10 );       if (a <= snd) puts( 11 );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ans = 0, visited[200005] = {0};   vector<int> edges[200005];   void dfs(int x) {     visited[x] = 1;     if (visited[edges[x][0]] == 1)       ans++;     else       dfs(edges[x][0]);   }   int main() {     int n, i, x, count = 0;     cin >> n;     for (i = 1; i <= n; i++) {       cin >> x;       edges[i].push_back(x);     }     for (i = 1; i <= n; i++) {       cin >> x;       if (x == 1) count++;     }     for (i = 1; i <= n; i++)       if (visited[i] == 0) dfs(i);     if (ans == 1) ans = 0;     if (count % 2 == 0) ans++;     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const int Maxn = 200 * 1000 + 10;   int n, arr[Maxn], ind[Maxn], ans;   int main() {     cin >> n;     for (int i = 0; i < n; i++) scanf( %d , &arr[i]);     int a;     for (int i = 0; i < n; i++) {       scanf( %d , &a);       ind[a] = i;     }     int prev = 0;     for (int i = 0; i < n; i++) {       if (ind[arr[i]] < prev) {         cout << n - i << endl;         return 0;       }       prev = ind[arr[i]];     }     cout << 0 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   int a[maxn], vis[maxn];   int main() {     int n, p, flag = 0, mark = 0, tot = 0, Min = 1e9 + 7, cur, Max = -1e9 - 7,               Maxcur;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       if (a[i] == 0)         vis[i] = 1, mark = 1;       else if (a[i] < 0) {         flag++;         if (a[i] < Min) cur = i;         Min = min(Min, a[i]);         if (a[i] > Max) Maxcur = i;         Max = max(Max, a[i]);       }     }     if (flag % 2) vis[Maxcur] = 1, mark = 1;     for (int i = 1; i <= n; i++)       if (vis[i]) {         p = i;         break;       }     for (int i = p + 1; i <= n; i++)       if (vis[i]) printf( 1 %d %d n , p, i), p = i, tot++;     if (tot != n - 1 && mark) printf( 2 %d n , p);     for (int i = 1; i <= n; i++)       if (!vis[i]) {         p = i;         break;       }     for (int i = p + 1; i <= n; i++)       if (!vis[i]) printf( 1 %d %d n , p, i), p = i;   }
#include <bits/stdc++.h>   using namespace std;   long long a1, b1, a2, b2;   int main() {     cin >> a1 >> b1 >> a2 >> b2;     long long t1, t2, t3, t4;     t1 = a1 * b1;     t2 = a2 * b2;     int c12, c13;     int c22, c23;     c12 = c13 = c22 = c23 = 0;     while (t1 % 2LL == 0LL) {       c12++;       t1 /= 2LL;     }     while (t1 % 3LL == 0LL) {       c13++;       t1 /= 3LL;     }     while (t2 % 2LL == 0LL) {       c22++;       t2 /= 2LL;     }     while (t2 % 3LL == 0LL) {       c23++;       t2 /= 3LL;     }     if (t1 != t2) {       cout <<  -1  << endl;       return 0;     }     int d13, d23;     int d12, d22;     d13 = d23 = 0;     while (c13 > c23) c13--, c12++, d13++;     while (c23 > c13) c23--, c22++, d23++;     d12 = d22 = 0;     if (c12 > c22)       d12 = c12 - c22;     else       d22 = c22 - c12;     cout << d12 + d22 + d23 + d13 << endl;     while (d13) {       if (a1 % 3 == 0) {         a1 /= 3LL;         a1 *= 2LL;       } else {         b1 /= 3LL;         b1 *= 2LL;       }       d13--;     }     while (d12) {       if (a1 % 2LL == 0) {         a1 /= 2LL;       } else {         b1 /= 2LL;       }       d12--;     }     while (d23) {       if (a2 % 3 == 0) {         a2 /= 3LL;         a2 *= 2LL;       } else {         b2 /= 3LL;         b2 *= 2LL;       }       d23--;     }     while (d22) {       if (a2 % 2 == 0) {         a2 /= 2LL;       } else {         b2 /= 2LL;       }       d22--;     }     cout << a1 <<     << b1 << endl;     cout << a2 <<     << b2 << endl;     ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000000;   int cnt[N + 1];   int check[N + 1];   set<pair<int, int> > s;   int main() {     int n, A;     scanf( %d %d , &n, &A);     for (int i = 1; i <= N; i++) {       cnt[i] = 0;       s.insert({cnt[i], i});     }     for (int i = 0; i < n; i++) {       int foo;       scanf( %d , &foo);       if (!check[foo]) {         s.erase(s.find({cnt[foo], foo}));         s.insert({++cnt[foo], foo});       }       while ((!s.empty()) && s.begin()->first < cnt[A]) {         check[s.begin()->second] = 1;         s.erase(s.begin());       }     }     for (auto x : s) {       if (x.second != A) {         cout << x.second << endl;         return 0;       }     }     puts( -1 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int l, r, sum = 0, tempVariable, doneTillHereInArrayOfNumbers = 3;   long long int arrayOfNumbers[100000];   long long int createNextLuckyNumber() {     if (doneTillHereInArrayOfNumbers % 2 == 0) {       arrayOfNumbers[doneTillHereInArrayOfNumbers] =           (arrayOfNumbers[doneTillHereInArrayOfNumbers / 2 - 1] * 10) + 7;     } else {       arrayOfNumbers[doneTillHereInArrayOfNumbers] =           (arrayOfNumbers[doneTillHereInArrayOfNumbers / 2] * 10) + 4;     }     return arrayOfNumbers[doneTillHereInArrayOfNumbers++];   }   long long int FirstLuckyNumberGreaterThanOrEqualToL() {     if (4 < l) {       goto down;     }     if (4 >= l && 4 <= r) {       sum += 4 * (4 - l + 1);       l = 5;     } else if (4 >= l && 4 > r) {       sum += 4 * (r - l + 1);       l = r;       cout << sum;       exit(0);     }   down:     if (7 < l) {       goto down2;     }     if (7 >= l && 7 <= r) {       sum += 7 * (7 - l + 1);       l = 8;     } else if (7 >= l && 7 > r) {       sum += 7 * (r - l + 1);       cout << sum;       exit(0);     }   down2:     long long int num = 0;     while (num < l) {       num = createNextLuckyNumber();     }     return num;   }   int main() {     cin >> l >> r;     arrayOfNumbers[1] = 4;     arrayOfNumbers[2] = 7;     tempVariable = FirstLuckyNumberGreaterThanOrEqualToL();     if (tempVariable <= r) {       sum += tempVariable * (tempVariable - l + 1);       l = tempVariable;     } else {       sum += tempVariable * (r - l + 1);       cout << sum;       exit(0);     }     l++;     while (l <= r) {       tempVariable = createNextLuckyNumber();       if (tempVariable <= r) {         sum += tempVariable * (tempVariable - l + 1);         l = tempVariable;       } else {         sum += tempVariable * (r - l + 1);         break;       }       l++;     }     cout << sum;     return 0;   }
#include <bits/stdc++.h>   const int INF = 1000000009;   using namespace std;   int main() {     int n, i, l = 0, r = 0;     string s;     cin >> n >> s;     s =  .  + s;     for (i = 1; i < s.size(); i++)       if (s[i] ==  L )         l = 1;       else if (s[i] ==  R )         r = 1;     if (r && l)       cout << s.find( R ) <<     << s.find( L ) - 1 <<   n ;     else if (r && !l)       cout << s.find( R ) <<     << s.rfind( R ) + 1 <<   n ;     else       cout << s.rfind( L ) <<     << s.find( L ) - 1 <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int const N = 1e5 + 10;   vector<int> e[N], b[N], d[N];   bool v[N], in[N];   void dfs(int root, int parent, int depth) {     v[root] = true, in[root] = true;     d[depth].push_back(root);     for (auto child : e[root]) {       if (in[child]) b[root].push_back(child);       if (!v[child]) dfs(child, root, depth + 1);     }     in[root] = false;   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     if (m & 1) return puts( No solution ), 0;     for (int i = 0, x, y; i < m; ++i) {       scanf( %d%d , &x, &y);       e[x].push_back(y), e[y].push_back(x);     }     dfs(1, -1, 0);     for (int t = n - 1, i; t >= 0; --t) {       for (auto x : d[t]) {         int sz = (int)b[x].size();         for (i = sz - 1; i >= 1; i -= 2)           printf( %d %d %d n , b[x][i], x, b[x][i - 1]);         if (sz & 1) b[b[x][0]].push_back(x);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int oo = 0x3f3f3f3f;   const long long ooo = 9223372036854775807ll;   const int _cnt = 1000 * 1000 + 7;   const int _p = 1000 * 1000 * 1000 + 7;   const int N = 100005;   const double PI = acos(-1.0);   const double eps = 1e-9;   int o(int x) { return x % _p; }   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; }   void file_put() {     string s =  /home/jslijin/jslijin/code/ ;     freopen((s +  code.in ).c_str(),  r , stdin);     freopen((s +  code.out ).c_str(),  w , stdout);   }   int n, q, last[N], a[N], cnt[N], ans = 0, op, x, y, B;   inline void get(int x) {     if (x + a[x] >= n || x / B != (x + a[x]) / B)       cnt[x] = 1, last[x] = x;     else       cnt[x] = cnt[x + a[x]] + 1, last[x] = last[x + a[x]];   }   int main() {     scanf( %d%d , &n, &q), B = sqrt(n) + 0.5;     for (int i = (0); i <= (n - 1); ++i) scanf( %d , &a[i]);     for (int i = (n - 1); i >= (0); --i) get(i);     while (q--) {       scanf( %d%d , &op, &x), --x;       if (op) {         ans = 0;         int ret = x;         for (; x < n; ret = last[x], x = ret + a[last[x]]) ans += cnt[x];         printf( %d %d n , ++ret, ans);       } else {         scanf( %d , &y), a[x] = y;         for (int i = (x); i >= (x / B * B); --i) get(i);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     scanf( %d %d , &n, &m);     vector<string> grid;     int start_x, start_y;     for (int i = 0; i < n; i++) {       string s;       cin >> s;       grid.push_back(s);       for (int j = 0; j < s.size(); j++) {         if (s[j] ==  S ) {           start_x = i;           start_y = j;         }       }     }     string actions;     cin >> actions;     int out = 0;     vector<pair<int, int>> mapping = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}};     do {       bool found = false;       int x = start_x;       int y = start_y;       for (int i = 0; i < actions.size(); i++) {         int action = actions[i] -  0 ;         x += mapping[action].first;         y += mapping[action].second;         if (x < 0 || x >= n || y < 0 || y >= m || grid[x][y] ==  # ) {           break;         }         if (grid[x][y] ==  E ) {           found = true;           break;         }       }       out += found;     } while (next_permutation(mapping.begin(), mapping.end()));     printf( %d , out);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100000;   const double pi = acos(-1.0);   int n, q, a[100100], seg[1700000], rev[1700000], tag[1700000];   char s[10];   int read() {     int x = 0, f = 1;     char ch = getchar();     while ((ch <  0 ) || (ch >  9 )) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while ((ch >=  0 ) && (ch <=  9 )) {       x = x * 10 + (ch -  0 );       ch = getchar();     }     return x * f;   }   void pushdown(int id, int l, int r) {     if (tag[id] != -1) {       seg[id << 1] = tag[id];       seg[id << 1 | 1] = tag[id];       tag[id << 1] = tag[id];       tag[id << 1 | 1] = tag[id];       rev[id << 1] = 0;       rev[id << 1 | 1] = 0;       tag[id] = -1;     }     if (rev[id]) {       rev[id << 1] ^= 1;       rev[id << 1 | 1] ^= 1;       seg[id << 1] ^= 1;       seg[id << 1 | 1] ^= 1;       rev[id] = 0;     }   }   void modify_val(int id, int l, int r, int ql, int qr, int val) {     if (ql > qr) return;     pushdown(id, l, r);     if ((l >= ql) && (r <= qr)) {       seg[id] = val;       tag[id] = val;       return;     }     int mid = (l + r) >> 1;     if (ql <= mid) modify_val(id << 1, l, mid, ql, qr, val);     if (qr > mid) modify_val(id << 1 | 1, mid + 1, r, ql, qr, val);   }   void modify_rev(int id, int l, int r, int ql, int qr) {     if (ql > qr) return;     pushdown(id, l, r);     if ((l >= ql) && (r <= qr)) {       seg[id] ^= 1;       rev[id] = 1;       return;     }     int mid = (l + r) >> 1;     if (ql <= mid) modify_rev(id << 1, l, mid, ql, qr);     if (qr > mid) modify_rev(id << 1 | 1, mid + 1, r, ql, qr);   }   int query(int id, int l, int r, int pos) {     pushdown(id, l, r);     if (l == r) return seg[id];     int mid = (l + r) >> 1;     if (pos <= mid)       return query(id << 1, l, mid, pos);     else       return query(id << 1 | 1, mid + 1, r, pos);   }   int main() {     n = read();     q = read();     for (int i = 1; i <= n; i++) a[i] = read();     memset(tag, -1, sizeof(tag));     while (q--) {       scanf( %s , s);       int x = read();       if (s[0] ==  > ) {         if (x >= 0) {           modify_val(1, -N, N, x + 1, N, 1);           modify_val(1, -N, N, -N, -x - 1, 0);         } else {           modify_val(1, -N, N, -x, N, 1);           modify_val(1, -N, N, -N, x, 0);           modify_rev(1, -N, N, x + 1, -x - 1);         }       } else {         if (x <= 0) {           modify_val(1, -N, N, -N, x - 1, 1);           modify_val(1, -N, N, -x + 1, N, 0);         } else {           modify_val(1, -N, N, x, N, 0);           modify_val(1, -N, N, -N, -x, 1);           modify_rev(1, -N, N, -x + 1, x - 1);         }       }     }     for (int i = 1; i <= n; i++) {       if (query(1, -N, N, a[i])) a[i] *= -1;       printf( %d  , a[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 3000 + 10;   int sum, d[maxn], dp[maxn][2];   vector<pair<int, int> > edge[maxn];   int min(int a, int b) { return a < b ? a : b; }   void dfs(int u, int f, int w) {     if (f == -1) {       sum = 0;       d[u] = 0;       dp[u][0] = dp[u][1] = 0;     } else {       dp[u][1] = dp[f][1] + w;       dp[u][0] = min(dp[f][0], dp[f][1]) + !w;       d[u] = d[f] + w;     }     for (vector<pair<int, int> >::iterator it = edge[u].begin();          it != edge[u].end(); it++) {       int to = it->first;       int wt = it->second;       if (to == f) continue;       sum += wt;       dfs(to, u, wt);     }   }   int main() {     int n, u, v, ret = maxn;     cin >> n;     for (int i = 0; i < n - 1; i++) {       cin >> u >> v;       edge[u].push_back(make_pair(v, 0));       edge[v].push_back(make_pair(u, 1));     }     for (int i = 1; i <= n; i++) {       dfs(i, -1, 0);       for (int j = 1; j <= n; j++) {         ret = min(ret, sum + min(dp[j][0], dp[j][1]) - d[j]);       }     }     cout << ret << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s;   int stx, sty, i;   int f[2000][2000];   int main() {     cin >> s;     stx = 100;     sty = 100;     f[stx][sty] = 1;     for (i = 0; i < s.size(); i++) {       if (s[i] ==  U ) stx--;       if (s[i] ==  D ) stx++;       if (s[i] ==  L ) sty--;       if (s[i] ==  R ) sty++;       f[stx][sty]++;       if (f[stx - 1][sty] + f[stx + 1][sty] + f[stx][sty - 1] + f[stx][sty + 1] +               f[stx][sty] >=           3) {         cout <<  BUG  << endl;         return 0;       }     }     cout <<  OK  << endl;   }
#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   void run() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int32_t main() {     run();     vector<long long> dp((long long)(3e6), 0);     dp[3] = 4;     for (long long i = 4; i < (long long)(3e6); i++) {       long long temp1 = (2 * dp[i - 2] + dp[i - 1]);       long long temp2 = 4 + (4 * dp[i - 4] + 4 * dp[i - 3] + dp[i - 2]);       if (i % 3 == 0) {         dp[i] = temp2;       } else {         dp[i] = temp1;       }       dp[i] %= (long long)(1e9 + 7);     }     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       cout << dp[n] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, dfs_low[100100], dfs_num[100100], cont;   int vis[100100];   vector<int> AdjList[100100];   long long int v[100100];   long long int sum = 0, numWay = 1;   vector<int> S;   void tarjan(int u) {     dfs_low[u] = dfs_num[u] = cont++;     vis[u] = 1;     S.push_back(u);     for (int i = 0; i < (int)AdjList[u].size(); i++) {       int v = AdjList[u][i];       if (vis[v] == -1) tarjan(v);       if (vis[v]) dfs_low[u] = min(dfs_low[u], dfs_low[v]);     }     if (dfs_low[u] == dfs_num[u]) {       int qtd = 1;       long long int val = 10000000100000;       while (true) {         int p = S.back();         S.pop_back();         vis[p] = 0;         if (v[p] < val) {           val = v[p];           qtd = 1;         } else if (v[p] == val)           qtd++;         if (u == p) break;       }       sum += val;       numWay = (numWay * qtd) % 1000000007;     }   }   int main() {     int a, b;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %lld , &v[i]);     }     scanf( %d , &m);     for (int i = 0; i < m; i++) {       scanf( %d%d , &a, &b);       AdjList[a].push_back(b);     }     memset(vis, -1, sizeof vis);     for (int i = 1; i <= n; i++) {       if (!dfs_num[i]) tarjan(i);     }     cout << sum <<     << numWay << endl;   }
#include <bits/stdc++.h>   using namespace std;   char a[1005];   int f[1005], flag[1005], prime[1005], g[1005];   int n, num, ok[1005], k, i, id, ans, cnt, j;   int main() {     scanf( %s , a + 1);     n = strlen(a + 1);     num = 1;     ok[1] = 1;     for (i = 1; a[i]; i++) g[a[i] -  a ]++;     for (i = 2; i <= n; i++) {       if (!flag[i])         if ((prime[++cnt] = i) > n / 2) ok[i] = 1, num++;       for (j = 1; j <= cnt && prime[j] * i <= n; j++) flag[prime[j] * i] = 1;     }     for (i = 0; i < 26; i++)       if (ans < g[i]) ans = g[i], id = i;     num = n - num;     if (ans < num) return puts( NO ), 0;     puts( YES );     for (i = 1; i <= n; i++)       if (!ok[i])         putchar( a  + id);       else {         for (k = 0; k < 26; k++)           if (k != id && g[k]) {             putchar( a  + k);             g[k]--;             break;           }         if (k == 26) putchar( a  + id);       }   }