malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   char buf[1 << 15], *fs, *ft;   inline char getc() {     return (ft == fs &&             (ft = (fs = buf) + fread(buf, 1, 1 << 15, stdin), ft == fs))                ? 0                : *fs++;   }   template <typename T>   inline void read(T &x) {     x = 0;     T f = 1, ch = getchar();     while (!isdigit(ch) && ch ^  - ) ch = getchar();     if (ch ==  - ) f = -1, ch = getchar();     while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();     x *= f;   }   template <typename T>   inline void write(T &x) {     if (!x) {       putchar( 0 ), putchar(  n );       return;     }     if (x < 0) putchar( - ), x = -x;     T num = 0, ch[16];     while (x) ch[++num] = x % 10 + 48, x /= 10;     while (num) putchar(ch[num--]);     putchar(  n );   }   int q[maxn], now;   long long f[2][maxn], a[maxn], d[maxn], sum[maxn];   inline long long getUp(int j, int k) {     return (f[now ^ 1][j] + sum[j]) - (f[now ^ 1][k] + sum[k]);   }   inline long long getDw(int j, int k) { return j - k; }   int main() {     int n, m, p;     read(n);     read(m);     read(p);     for (int i = 2; i <= n; ++i) read(d[i]), d[i] += d[i - 1];     for (int i = 1; i <= m; ++i) {       int h;       long long t;       read(h);       read(t);       a[i] = t - d[h];     }     sort(a + 1, a + m + 1);     for (int i = 1; i <= m; ++i) sum[i] = sum[i - 1] + a[i], f[0][i] = 1e18;     long long ans = 1e18;     now = 1;     for (int t = 1; t <= p; ++t) {       int l = 1, r = 1;       q[1] = 0;       for (int i = 1; i <= m; ++i) {         while (l < r && getUp(q[l + 1], q[l]) <= a[i] * getDw(q[l + 1], q[l]))           ++l;         f[now][i] = f[now ^ 1][q[l]] + (long long)a[i] * (i - q[l]) -                     (sum[i] - sum[q[l]]);         while (l < r && getUp(i, q[r]) * getDw(q[r], q[r - 1]) <=                             getUp(q[r], q[r - 1]) * getDw(i, q[r]))           --r;         q[++r] = i;       }       ans = min(ans, f[now][m]);       now ^= 1;     }     write(ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int gcd(long long int a, long long int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   int main() {     long long int n, a[100001], sum = 0, m;     cin >> n;     for (int i = 0; i < n; ++i) cin >> a[i];     sort(a, a + n);     for (int i = 1; i < n; ++i) {       sum += i * a[i] - a[i - 1];       a[i] += a[i - 1];     }     sum = 2 * sum + a[n - 1];     m = gcd(sum, n);     cout << sum / m <<     << n / m;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int T, money;     cin >> T >> money;     int n;     int g;     vector<int> lista;     for (int i = 1; i <= T; i++) {       cin >> n;       int brk = 0;       for (int j = 0; j < n; j++) {         cin >> g;         if (brk == 0 && money > g) {           lista.push_back(i);           brk = 1;         }       }     }     cout << lista.size() << endl;     for (int i = 0; i < lista.size(); i++) {       cout << lista[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize(3,  inline ,  Ofast )   using namespace std;   int p[1010];   bool vis[1010];   void dfs(int pos) {     if (vis[pos])       return (void)(printf( %d  , pos));     else       vis[pos] = 1, dfs(p[pos]);   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &p[i]);     for (int i = 1; i <= n; i++) memset(vis, 0, sizeof vis), dfs(i);   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100100;   bool vis[maxn];   long long val[3][maxn];   long long mii[3];   vector<int> g[maxn];   vector<int> a;   int ans[maxn];   int d[maxn];   void dfs(int now) {     a.push_back(now);     vis[now] = 1;     for (int i = 0; i < g[now].size(); i++) {       if (vis[g[now][i]]) continue;       dfs(g[now][i]);     }   }   int main() {     int n;     scanf( %d , &n);     for (int j = 0; j < 3; j++) {       for (int i = 1; i <= n; i++) {         scanf( %d , &val[j][i]);       }     }     for (int i = 0; i < n - 1; i++) {       int f, t;       scanf( %d%d , &f, &t);       g[f].push_back(t);       g[t].push_back(f);       d[f]++;       d[t]++;       if (d[f] > 2 || d[t] > 2) {         printf( -1 n );         return 0;       }     }     vector<int> temp;     temp.push_back(0);     temp.push_back(1);     temp.push_back(2);     for (int i = 1; i <= n; i++) {       if (d[i] == 1) {         dfs(i);         break;       }     }     long long mi = 1ll << 60;     for (int _ = 0; _ < 6; _++) {       long long now = 0;       for (int i = 0; i < n; i++) {         now += val[temp[i % 3]][a[i]];       }       if (now < mi) {         mi = now;         for (int j = 0; j < 3; j++) {           mii[j] = temp[j];         }       }       next_permutation(temp.begin(), temp.end());     }     printf( %lld n , mi);     for (int i = 0; i < n; i++) {       ans[a[i]] = mii[i % 3];     }     for (int i = 1; i <= n; i++) {       printf( %d  , ans[i] + 1);     }     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dp[510][510];   long long MOD;   vector<string> v;   long long nc2(long long num) { return (num * (num - 1)) / 2; }   int recur(int ones, int zeros) {     if (ones == 0 and zeros == 0) return 1;     if (dp[ones][zeros] != -1) {       return dp[ones][zeros] % MOD;     }     long long ret = 0;     if (ones > 1) {       ret = (ret + ((recur(ones - 2, zeros) * nc2(ones)) % MOD)) % MOD;     }     if (zeros > 1) {       ret = (ret + ((recur(ones + 2, zeros - 2) * nc2(zeros)) % MOD)) % MOD;     }     if (ones >= 1 && zeros >= 1) {       ret =           (ret + ((recur(ones, zeros - 1) * ((ones * zeros) % MOD)) % MOD)) % MOD;     }     dp[ones][zeros] = ret % MOD;     return dp[ones][zeros];   }   int solve(int n, int m) {     int ones = 0;     int zeros = 0;     for (int i = 0; i < n; i++) {       int cnt = 0;       for (int j = 0; j < m; j++) {         if (v[j][i] ==  1 ) cnt++;       }       if (cnt == 1) ones++;       if (cnt == 0) zeros++;     }     memset(dp, -1, sizeof(dp));     int res = recur(ones, zeros);     return res;   }   int main() {     int n, m;     cin >> n >> m >> MOD;     string line =   ;     for (int i = 0; i < m; i++) {       cin >> line;       v.push_back(line);     }     int res = solve(n, m);     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 10;   inline int read() {     char ch = getchar();     int x = 0, f = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 1) + (x << 3) -  0  + ch;       ch = getchar();     }     return x * f;   }   int n, k, size[N];   long long ans, f[N][5];   vector<int> g[N];   void dfs(int u, int fa, int d) {     size[u] = 1;     f[u][d % k] = 1;     for (auto &v : g[u]) {       if (v == fa) continue;       dfs(v, u, d + 1);       size[u] += size[v];       ans += 1ll * (n - size[v]) * size[v];       for (int i = 0; i < k; i++) {         for (int j = 0; j < k; j++) {           int z = ((i + j - 2 * d) % k + k) % k;           z = (k - z) % k;           ans += 1ll * z * f[u][i] * f[v][j];         }       }       for (int i = 0; i < k; i++) f[u][i] += f[v][i];     }   }   int main() {     n = read(), k = read();     for (int i = 1; i <= n - 1; i++) {       int a = read(), b = read();       g[a].push_back(b);       g[b].push_back(a);     }     dfs(1, 0, 0);     printf( %lld n , ans / k);   }
#include <bits/stdc++.h>   using namespace std;   int main(void) {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     string a[n], b[n];     map<string, int> m;     for (int i = 0; i < n; ++i) {       cin >> a[i];       ++m[a[i]];     }     for (int i = 0; i < n; ++i) {       cin >> b[i];       --m[b[i]];     }     int ans = 0;     vector<string> v = { XXXL ,  XXXS ,  XXL ,  XXS ,  XL ,  XS ,  S ,  L ,  M };     ans = (abs(m[ XXXL ]) + abs(m[ XXXS ])) / 2;     ans += (abs(m[ XXL ]) + abs(m[ XXS ])) / 2;     ans += (abs(m[ XL ]) + abs(m[ XS ])) / 2;     ans += (abs(m[ S ]) + abs(m[ L ]) + abs(m[ M ])) / 2;     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   long long n, q, ans[50005], sum[50005], a[50005], p[50005], x[50005], cont, pos,       us[50005];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> q;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 2; i <= n; i++) cin >> p[i];     for (int i = 0; i < q; i++) cin >> x[i];     for (int i = 1; i <= n; i++) {       pos = i;       cont = 1;       while (pos != 1) {         us[pos] = cont;         cont++;         pos = p[pos];       }       us[pos] = cont;       for (int j = 0; j < q; j++) {         sum[j] += us[x[j]];         if (us[x[j]]) {           ans[j]++;           j += a[i] - 1;         }       }       pos = i;       cont = 1;       while (pos != 1) {         us[pos] = 0;         cont++;         pos = p[pos];       }       us[pos] = 0;     }     for (int i = 0; i < q; i++) cout << sum[i] - ans[i] <<     << ans[i] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string S, T;   int n, m;   int nxt[200005][30];   unsigned long long hashS[200005][30], hashT[200005][30], bpw[200005];   unsigned long long ht;   int base = 10007;   int f[30];   vector<int> ans;   bool chk(int p) {     memset(f, 0, sizeof(f));     int ps, pt;     unsigned long long hps, hpt, temp = 0;     for (int j = 1; j <= 26; j++) {       if (nxt[p][j] > p + m - 1) continue;       ps = j;       pt = T[(nxt[p][j] - p) + 1] -  a  + 1;       if (f[ps] == pt)         continue;       else if (f[ps] && f[ps] != pt)         return 0;       else {         f[ps] = pt;         f[pt] = ps;         hps = hashS[p + m - 1][ps] - bpw[m] * hashS[p - 1][ps];         hpt = hashT[m][pt];         if (hps != hpt ||             hashS[p + m - 1][pt] - bpw[m] * hashS[p - 1][pt] != hashT[m][ps]) {           return 0;         }         temp += hps * pt;         if (ps != pt) temp += ps * hashT[m][ps];       }     }     return temp == ht;   }   int main() {     scanf( %d%d , &n, &m);     cin >> S >> T;     S =  %  + S;     T =  %  + T;     for (int i = 1; i <= m; i++) {       ht = ht * base + T[i] -  a  + 1;     }     for (int i = 1; i <= 26; i++) {       nxt[n + 1][i] = n + 1;     }     for (int i = n; i >= 1; i--) {       for (int j = 1; j <= 26; j++) {         if (S[i] ==  a  + j - 1)           nxt[i][j] = i;         else           nxt[i][j] = nxt[i + 1][j];       }     }     bpw[0] = 1;     for (int i = 1; i <= n; i++) {       bpw[i] = bpw[i - 1] * base;     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= 26; j++) {         hashS[i][j] = hashS[i - 1][j] * base + (S[i] == ( a  + j - 1) ? 1 : 0);       }     }     for (int i = 1; i <= m; i++) {       for (int j = 1; j <= 26; j++) {         hashT[i][j] = hashT[i - 1][j] * base + (T[i] == ( a  + j - 1) ? 1 : 0);       }     }     for (int i = 1; i <= n - m + 1; i++) {       if (chk(i)) ans.push_back(i);     }     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); i++) {       printf( %d  , ans[i]);     }     return 0;   }
#include <bits/stdc++.h>   int main() {     int t, n;     scanf( %d , &t);     while (t--) {       scanf( %d , &n);       if (n == 1) {         printf( -1 n );       } else {         printf( 2 );         for (int i = 1; i < n; i++) {           printf( 7 );         }         printf(  n );       }     }   }
#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long x = 0, f = 1;     char c = getchar();     while ((c <  0  || c >  9 ) && (c !=  - )) c = getchar();     if (c ==  - ) f = -1, c = getchar();     while (c >=  0  && c <=  9 ) x = x * 10 + c -  0 , c = getchar();     return x * f;   }   const int N = 3e4 + 10;   int n;   vector<int> e[N];   int cnt, p[N], fa[N], vis[N];   bool flag[N];   inline void dfs(int u) {     vis[u] = 1;     for (auto v : e[u]) {       if (v == fa[u]) continue;       fa[v] = u;       if (!vis[v])         dfs(v);       else {         for (int now = u; now != v; now = fa[now]) flag[p[++cnt] = now] = 1;         flag[p[++cnt] = v] = 1;       }       if (cnt) break;     }   }   long long f[N], g[N], siz[N];   inline void dfs(int u, int fa) {     siz[u] = 1;     for (auto v : e[u]) {       if (v == fa || flag[v]) continue;       dfs(v, u), f[u] += g[v], siz[u] += siz[v];     }     g[u] = f[u] + siz[u];   }   long long dp[N], last[N], pre[N], ans;   inline void dfs(int u, int fa, long long sum) {     ans = max(ans, sum + n + f[u]);     for (auto v : e[u])       if (v != fa) dfs(v, u, sum + n - siz[v] + f[u] - g[v]);   }   inline void solve() {     long long sum = 0;     for (register int i = (1); i <= (cnt * 2); i++)       last[i] = siz[p[i]], pre[i] = pre[i - 1] + last[i], sum += f[p[i]];     for (register int i = (2); i <= (cnt - 1); i++) {       for (register int l = (1); l <= (cnt * 2 - i + 1); l++) {         int r = l + i - 1;         long long tmp = pre[r] - pre[l - 1];         dp[l] = max(last[l] + tmp, last[l + 1] + tmp);       }       for (register int j = (1); j <= (cnt * 2 - i + 1); j++) last[j] = dp[j];     }     ans = 0;     for (register int i = (1); i <= (cnt); i++) {       ans = max(ans, n + sum / 2 + dp[i + 1]);       for (auto v : e[p[i]])         if (!flag[v])           dfs(v, p[i],               n - siz[v] + sum / 2 - f[p[i]] + f[p[i]] - g[v] + dp[i + 1]);     }     printf( %lld n , ans);   }   int main() {     n = read();     for (register int i = (1); i <= (n); i++) {       int x = read() + 1, y = read() + 1;       e[x].push_back(y), e[y].push_back(x);     }     dfs(1);     for (register int i = (1); i <= (cnt); i++) dfs(p[i], 0);     for (register int i = (1); i <= (cnt); i++) p[cnt + i] = p[i];     solve();   }
#include <bits/stdc++.h>   using namespace std;   long long inv_euclid(long long a, long long m = 998244353) {     long long m0 = m;     long long y = 0, x = 1;     if (m == 1) return 0;     while (a > 1) {       long long q = a / m;       long long t = m;       m = a % m, a = t;       t = y;       y = x - q * y;       x = t;     }     if (x < 0) x += m0;     return x;   }   long long power(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     if (x == 0) return 0;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   long long max(long long a, long long b) {     if (a > b) return a;     return b;   }   long long min(long long a, long long b) {     if (a < b) return a;     return b;   }   long long ssum(long long n) { return (n * (n + 1)) / 2; }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long lcm(long long a, long long b) { return (a * b) / (gcd(a, b)); }   void solve() {     long long n;     cin >> n;     vector<long long> v(n);     for (long long i = 0; i < n; i++) cin >> v[i];     while (v.size() && v[v.size() - 1] == 0) v.pop_back();     reverse(v.begin(), v.end());     while (v.size() && v[v.size() - 1] == 0) v.pop_back();     long long ans = 0;     for (auto i : v) ans += (i == 0);     cout << ans <<   n ;   }   int main() {     long long tttt;     cin >> tttt;     while (tttt--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, m, k, i, j, count = 0, sum = 0, maxi = 0, mini = 1e18, flag = 0;     cin >> n;     vector<long long> res;     vector<char> temp;     string a, b;     cin >> a >> b;     if (a == b) {       cout << 0 <<   n ;       return;     }     if (n == 1 && a[0] != b[0]) {       cout << 1 <<     << 1 <<   n ;       return;     }     for (i = 0; i < n / 2; i++) {       temp.push_back(a[i]);       if (a[n - i - 1] ==  1 )         temp.push_back( 0 );       else         temp.push_back( 1 );     }     if (n % 2) temp.push_back(a[n / 2]);     i = 0;     j = n - 1;     while (j > 0) {       if (temp[i] == b[j]) {         res.push_back(0);         res.push_back(j);       } else         res.push_back(j);       j--;       i++;     }     if (j == 0) {       if (temp[i] == b[j])         ;       else         res.push_back(0);     }     cout << res.size() <<    ;     for (i = 0; i < res.size(); i++) {       cout << res[i] + 1 <<    ;     }     cout <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1;     cin >> t;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 5005;   int u[maxn], v[maxn], w[maxn], dp[maxn][maxn], parent[maxn][maxn], x[maxn];   int main() {     int n, m, t, pos;     cin >> n >> m >> t;     for (int i = 0; i < m; i++) {       cin >> u[i] >> v[i] >> w[i];     }     memset(dp, 0x3f, sizeof(dp));     dp[1][1] = 0;     for (int i = 2; i <= n; i++) {       for (int j = 0; j < m; j++) {         if (dp[i - 1][u[j]] + w[j] < dp[i][v[j]]) {           dp[i][v[j]] = dp[i - 1][u[j]] + w[j];           parent[i][v[j]] = u[j];         }       }       if (dp[i][n] <= t) pos = i;     }     int id = n;     for (int i = pos; i >= 1; i--) {       x[i] = id;       id = parent[i][id];     }     cout << pos << endl;     for (int i = 1; i <= pos; i++) cout << x[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int k, n, m;   const int dx[4] = {-1, 1, 0, 0};   const int dy[4] = {0, 0, -1, 1};   int bx, by, s, ansx[1000000], ansy[1000000];   bool g[510][510];   char ansc[1000000];   int dfs(int x, int y) {     if (x > 0 && y > 0 && x <= n && y <= m && g[x][y] == 0) {       g[x][y] = 1;       s++;       ansc[s] =  B ;       ansx[s] = x;       ansy[s] = y;       int nx, ny;       for (int i = 0; i < 4; i++) {         nx = x + dx[i];         ny = y + dy[i];         dfs(nx, ny);       }       if (bx != x || by != y) {         s++;         ansc[s] =  D ;         ansx[s] = x;         ansy[s] = y;         s++;         ansc[s] =  R ;         ansx[s] = x;         ansy[s] = y;       }     }   }   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         char c;         cin >> c;         if (c ==  # ) g[i][j] = true;       }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (!g[i][j]) bx = i, by = j, dfs(i, j);     cout << s << endl;     for (int i = 1; i <= s; i++) printf( %c %d %d n , ansc[i], ansx[i], ansy[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   int n, c1, c2;   long long f[501];   long long c[501][501];   long long dp[501][501];   long long gao(int a, int b) {     if (a == 0 && b == 0) {       return 1;     }     if (dp[a][b] == -1) {       long long& cur = dp[a][b] = 0;       if (a > 0) {         if (a >= 1) {           for (int i = 0; i <= b; ++i) {             cur = (cur + gao(a - 1, b - i) * c[b][i] % MOD * f[i]) % MOD;           }         }         if (a >= 2) {           for (int i = 0; i <= b; ++i) {             cur = (cur +                    gao(a - 2, b - i) * c[b][i] % MOD * (a - 1) % MOD * f[i + 1]) %                   MOD;           }         }       } else {         for (int i = 0; i < b; ++i) {           cur = (cur + gao(a, b - i - 1) * c[b - 1][i] % MOD * f[i]) % MOD;         }       }     }     return dp[a][b] % MOD;   }   int main() {     for (int i = f[0] = 1; i <= 500; ++i) {       f[i] = f[i - 1] * i % MOD;     }     for (int i = 0; i <= 500; ++i) {       c[i][0] = c[i][i] = 1;       for (int j = 1; j < i; ++j) {         c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % MOD;       }     }     c1 = c2 = 0;     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       int x;       scanf( %d , &x);       ++(x == 1 ? c1 : c2);     }     memset(dp, -1, sizeof(dp));     int res = gao(c1, c2) % MOD;     printf( %d n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   ostream& operator<<(ostream& out, const vector<T>& vec) {     out <<  [ ;     for (int x : vec) out << x <<  ,  ;     out <<  ] ;     return out;   }   int main() {     int M;     long long N, A, D;     cin >> N >> M >> A >> D;     vector<long long> T;     for (int m = 0; m < M; ++m) {       long long t;       cin >> t;       T.push_back(t);     }     T.push_back(N * A);     ++M;     sort(T.begin(), T.end());     long long last = -D - 1;     long long ans = 0;     for (int i = 0; i < M;) {       while (i < M && last >= T[i]) {         ++i;       }       if (i == M) {         break;       }       last = max(last, 0LL);       long long u = last / A + 1;       if (u < N && u * A < T[i]) {         long long v = D / A + 1;         long long w = ((T[i] - 1) / A - u) / v + 1;         last = A * (u + v * (w - 1)) + D;         ans += w;       }       if (last < T[i]) {         last = T[i] + D;         ++ans;       }     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const long long M = 1000 * 1000 * 1000 + 7;   const int INF = 0x3f3f3f3f;   const int MAX = 200009;   long long n, f1, f2, f3, c;   vector<vector<long long> > operator*(const vector<vector<long long> > &a,                                        const vector<vector<long long> > &b) {     vector<vector<long long> > t(3, vector<long long>(3, 0));     for (int i = 0; i < 3; i++)       for (int j = 0; j < 3; j++)         for (int k = 0; k < 3; k++)           t[i][j] = (t[i][j] + a[i][k] * b[k][j]) % (M - 1);     return t;   }   vector<vector<long long> > mat_pow(vector<vector<long long> > a, long long b) {     vector<vector<long long> > c(3, vector<long long>(3, 0));     for (int i = 0; i < 3; i++) c[i][i] = 1;     while (b) {       if (b & 1) c = c * a;       a = a * a;       b >>= 1;     }     return c;   }   long long ll_pow(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = (res * a) % M;       a = (a * a) % M;       b >>= 1;     }     return res;   }   int main() {     while (cin >> n >> f1 >> f2 >> f3 >> c) {       vector<vector<long long> > a{{0, 1, 0}, {0, 0, 1}, {1, 1, 1}};       a = mat_pow(a, n - 3);       long long ans = ll_pow(f1 * c % M, a[2][0]) *                       ll_pow(f2 * c % M * c % M, a[2][1]) % M *                       ll_pow(f3 * c % M * c % M * c % M, a[2][2]) % M *                       ll_pow(ll_pow(c, n), M - 2) % M;       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int count = 0;     int a[(int)(pow(2.0, (double)(n + 1)) - 2)];     int x = (int)pow(2.0, (double)(n + 1)) - 2;     for (int i = 0; i < x; i++) {       cin >> a[i];     }     int y = (int)(pow(2.0, (double)(n + 1)) - pow(2.0, (double)n));     int b[y];     for (int i = 0; i < y; i++) b[i] = 0;     for (int i = 0; i < y; i++) {       for (int j = 0; j < n; j = j + 1)         b[i] = b[i] +                a[(int)((pow(2.0, (double)n) + i) / (pow(2.0, (double)j))) - 2];     }     for (int j = 1; j <= n; j++)       for (int i = y - 1; i >= 0; i = i - (int)pow(2.0, (double)j)) {         count = count + abs(b[i] - b[i - (int)pow(2.0, (double)(j - 1))]);         if (b[i] > b[i - (int)pow(2.0, (double)(j - 1))])           b[i - (int)pow(2.0, (double)(j - 1))] = b[i];         else           b[i] = b[i - (int)pow(2.0, (double)(j - 1))];       }     cout << count << endl;   }