malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   struct coor {     int x[3];   };   int x[6][3] = {0, 1, 2, 0, 2, 1, 1, 0, 2, 1, 2, 0, 2, 0, 1, 2, 1, 0};   bool judge(coor a, coor b) {     bool flag = 0;     b.x[2] += 18;     if (b.x[2] < a.x[2]) {       flag = 1;     } else if (b.x[2] > a.x[2]) {     } else if (a.x[2] == b.x[2]) {       if (b.x[1] < a.x[1]) {         flag = 1;       } else if (b.x[1] > a.x[1]) {       } else if (b.x[1] == a.x[1]) {         if (b.x[0] < a.x[0]) {           flag = 1;         } else if (b.x[0] > a.x[0]) {         } else if (b.x[0] == a.x[0]) {           flag = 1;         }       }     }     return flag;   }   bool hefa(coor a) {     if (a.x[1] < 1 || a.x[1] > 12) return 0;     if (a.x[1] == 1 || a.x[1] == 3 || a.x[1] == 5 || a.x[1] == 7 || a.x[1] == 8 ||         a.x[1] == 10 || a.x[1] == 12) {       if (a.x[0] < 1 || a.x[0] > 31) return 0;     } else if (a.x[1] == 2) {       if (a.x[2] % 4 == 0) {         if (a.x[0] < 1 || a.x[0] > 29) return 0;       } else {         if (a.x[0] < 1 || a.x[0] > 28) return 0;       }     } else {       if (a.x[0] < 1 || a.x[0] > 30) return 0;     }     return 1;   }   int main() {     int i, j;     coor a, b, c;     scanf( %d.%d.%d , &a.x[0], &a.x[1], &a.x[2]);     scanf( %d.%d.%d , &b.x[0], &b.x[1], &b.x[2]);     bool flag = 0;     for (i = 0; i < 6; i++) {       c.x[0] = b.x[x[i][0]];       c.x[1] = b.x[x[i][1]];       c.x[2] = b.x[x[i][2]];       if (hefa(c)) {         if (judge(a, c)) {           flag = 1;           break;         }       }     }     if (flag)       printf( YES n );     else       printf( NO n );     return 0;   }
#include <bits/stdc++.h>   const long long mn = 1000000009;   long long x, n, m;   long long minu(long long val) {     if (val == 0) return mn - 1;     return val - 1;   }   long long getmod(long long val) {     long long ret = 1;     for (long long i = 0; i < val; i++) {       ret *= 2;       ret %= mn;     }     return minu(ret);   }   int main() {     scanf( %d %d , &n, &m);     x = getmod(m);     long long ans = 1;     while (n--) {       ans *= x;       ans %= mn;       x = minu(x);     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(NULL);     cin.tie(NULL);     string s;     cin >> s;     long long int n, i, j, cnt;     n = s.length();     cnt = j = 0;     for (i = 0; i < n; i++) {       if (s[i] ==  1 ) {         cnt++;         j = i;       }     }     if (cnt == 1)       cout << n + j - cnt;     else       cout << n + j - cnt + 2;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int leer() {     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;   }   int n, m, d[300010], cabeza[300010], vis[300010], cnt, tot, ans[300010];   struct edge {     int to;     int po;     int next;   } e[300010 * 2];   bool dfs(int u) {     vis[u] = 1;     int pd = 0;     for (int i = cabeza[u]; i; i = e[i].next) {       if (vis[e[i].to]) continue;       int flag = dfs(e[i].to);       pd ^= flag;       if (flag) ans[++cnt] = e[i].po;     }     if (pd == d[u] || d[u] == -1) return false;     return true;   }   int main() {     n = leer();     m = leer();     int root = 0;     for (int i = 1; i <= n; i++) {       d[i] = leer();       if (d[i] == -1) root = i;     }     if (!root) root = 1;     for (int i = 1; i <= m; i++) {       int u = leer(), v = leer();       e[++tot].to = v;       e[tot].next = cabeza[u];       cabeza[u] = tot;       e[tot].po = i;       e[++tot].to = u;       e[tot].next = cabeza[v];       cabeza[v] = tot;       e[tot].po = i;     }     if (dfs(root))       puts( -1 );     else {       printf( %d n , cnt);       for (int i = 1; i <= cnt; i++) printf( %d n , ans[i]);     }   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:64000000 )   using namespace std;   const int maxn = 3000000;   const long long MANY = 1000000;   int main() {     long long n;     cin >> n;     while (n % 3 == 0) n /= 3;     long long ans = (n % 3 ? 1 : 0) + n / 3;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int toBinary(int num) {     vector<int> vec;     while (num > 0) {       vec.push_back(num % 2);       num = num / 2;     }     while (vec.size() < 8) {       vec.push_back(0);     }     int temp = 0;     for (int i = 0; i < vec.size(); i++) {       temp += vec[7 - i] * pow(2, i);     }     return temp;   }   int main() {     string s;     getline(cin, s);     int last = 0, x;     for (int i = 0; i < s.size(); i++) {       x = toBinary((int)s[i]);       cout << ((last - x) % 256 + 256) % 256 << endl;       last = x;     }   }
#include <bits/stdc++.h>   int k, x, y;   using namespace std;   int main() {     scanf( %d , &k);     x = 1000000 - k % 2000;     y = (k + x - 2000 * x) / 2000;     printf( 2000 n );     for (int i = 1; i <= 1998; i++) printf( 0  );     printf( %d %d n , y, x);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   const long double INF = 1e18;   const long double PI = acos(-1.0);   int n;   pair<long long, long long> o, origin, p[N];   long long r_1 = 0;   long double r_2 = INF;   long long sqDist(pair<long long, long long> a, pair<long long, long long> b) {     return (a.first - b.first) * (a.first - b.first) +            (a.second - b.second) * (a.second - b.second);   }   bool isObtuse(pair<long long, long long> a, pair<long long, long long> b,                 pair<long long, long long> c) {     long long ab = sqDist(a, b), bc = sqDist(b, c), ca = sqDist(c, a);     return ab + bc <= ca;   }   long double minDist(pair<long long, long long> a,                       pair<long long, long long> b) {     long double diff_x = b.first - a.first, diff_y = b.second - a.second;     if (diff_x == 0 and diff_y == 0) {       diff_x = a.first;       diff_y = a.second;       return diff_x * diff_x + diff_y * diff_y;     }     long double t = (-a.first * diff_x - a.second * diff_y) /                     (1.0 * diff_x * diff_x + 1.0 * diff_y * diff_y);     if (t < 0) {       diff_x = a.first;       diff_y = a.second;     } else if (t > 1) {       diff_x = b.first;       diff_y = b.second;     } else {       diff_x = a.first + t * diff_x;       diff_y = a.second + t * diff_y;     }     return diff_x * diff_x + diff_y * diff_y;   }   int main() {     origin = pair<long long, long long>(0, 0);     scanf( %d %lld %lld , &n, &o.first, &o.second);     for (int i = 0; i < n; ++i) {       scanf( %lld %lld , &p[i].first, &p[i].second);       p[i].first -= o.first, p[i].second -= o.second;       r_1 = max(r_1, sqDist(p[i], origin));       r_2 = min(r_2, (long double)sqDist(p[i], origin));     }     p[n] = p[0];     for (int i = 0; i < n; ++i) {       r_2 = min(r_2, minDist(p[i], p[i + 1]));     }     long double ans = max((long double)0.0, PI * (r_1 - r_2));     printf( %0.16f n , (double)ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void read() {}   int main() {     read();     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       int n, m;       cin >> n >> m;       string s;       int a[n][m];       for (int i = 0; i < n; i++) {         cin >> s;         for (int j = 0; j < m; j++) {           if (s[j] ==  1 )             a[i][j] = 1;           else             a[i][j] = 0;         }       }       int o, p;       cin >> o >> p;       int b[o][p];       for (int i = 0; i < o; i++) {         cin >> s;         for (int j = 0; j < p; j++)           if (s[j] ==  1 )             b[i][j] = 1;           else             b[i][j] = 0;       }       int final_ans = -1, ans = 0, a1 = 0, a2 = 0;       for (int i = -50; i < 51; i++) {         for (int j = -50; j < 51; j++) {           ans = 0;           for (int k = 0; k < n; k++) {             if (k + i < 0 or k + i >= o) continue;             for (int l = 0; l < m; l++) {               if (l + j < 0 or l + j >= p) continue;               ans += a[k][l] * b[k + i][l + j];             }           }           if (ans > final_ans) {             a1 = i;             a2 = j;             final_ans = ans;           }         }       }       cout << a1 <<     << a2 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long double Pi = 3.14159265359;   const long long MOD = (long long)1e9 + 7;   const long long MAXN = (long long)1e6 + 10;   const long long INF = (long long)9223372036854775;   const long double EPS = (long double)1e-8;   long long dp[MAXN];   long long dpx[MAXN];   long long a[MAXN];   deque<long long> de;   stack<long long> s;   long long mk[MAXN];   long long lb[MAXN];   int main() {     long long n, k;     scanf( %lld , &n);     scanf( %lld , &k);     for (int i = 0; i < n; i++) scanf( %lld , &a[i]);     for (int i = 0; i < k - 1; i++) {       while (de.size() != 0) {         if (a[de.back()] <= a[i])           de.pop_back();         else           break;       }       de.push_back(i);     }     for (int i = k - 1; i < n; i++) {       while (de.size() != 0) {         if (a[de.back()] <= a[i])           de.pop_back();         else           break;       }       de.push_back(i);       if (i - de.front() >= k) de.pop_front();       mk[i] = de.front();     }     de.clear();     for (int i = 0; i < n; i++) {       while (de.size() != 0) {         if (a[de.back()] <= a[i])           de.pop_back();         else           break;       }       if (de.size() == 0)         lb[i] = -1;       else         lb[i] = de.back();       de.push_back(i);     }     long long nex, cnt, pa;     for (int i = k - 1; i < n; i++) {       nex = lb[mk[i]];       if (nex == -1) {         dpx[i] = ((a[mk[i]]) * (i / (k - 1))) % MOD;       } else {         cnt = i - nex - 1;         pa = cnt / (k - 1);         dpx[i] = (dpx[i - (pa * (k - 1))] + ((a[mk[i]]) * pa)) % MOD;       }     }     long long ans = 0;     for (int i = 0; i < n; i++) ans = (ans + dpx[i]) % MOD;     printf( %lld , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[300010];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);     }     long long ans = 0;     vector<int> v;     for (int i = 1; i <= n; ++i) {       ans += a[i] / 2;       if (a[i] % 2 != 0) {         v.push_back(i);       }     }     stack<int> q;     if (v.size() == 0) {       cout << ans << endl;       return 0;     }     q.push(v[0]);     for (int i = 1; i < v.size(); ++i) {       if (q.size() && (v[i] - q.top()) % 2 != 0) {         q.pop();         ans++;         continue;       }       q.push(v[i]);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const double eps = 1e-11;   void fastIO() {     std::ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int dig[10];   int main() {     fastIO();     long long ans = 0;     long long k;     string s;     cin >> k >> s;     long long sm = 0;     for (int i = 0; i < int((s).size()); i++) {       dig[s[i] -  0 ]++;       sm += (s[i] -  0 );     }     for (int i = 0; i < 9; i++) {       while (dig[i] && sm < k) {         sm += (9 - i);         ans++;         dig[i]--;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5, B = 350, Mod = 998244353;   int n, lim, siz, block_cnt, cnt[maxn], a[maxn], b[maxn], sum_b[1005],       sum_f[1005][1005], f[maxn];   vector<int> pos[maxn];   void cal(int w) {     memset(sum_f[w], 0, sizeof sum_f[w]);     int tmp = 0;     for (int i = w * siz; i > w * siz - siz; i--)       tmp += b[i], sum_f[w][tmp + B] = (sum_f[w][tmp + B] + f[i - 1]) % Mod;     for (int i = -siz + 1; i <= siz; i++)       sum_f[w][i + B] = (sum_f[w][i + B] + sum_f[w][i - 1 + B]) % Mod;     sum_b[w] = tmp;   }   int main() {     f[0] = 1;     cin >> n >> lim;     for (int i = 1; i <= n; i++) cin >> a[i], pos[a[i]].push_back(i);     siz = sqrt(n);     block_cnt = (n - 1) / siz + 1;     for (int i = 1; i <= block_cnt; i++) {       for (int j = i * siz - siz + 1; j <= min(i * siz, n); j++) {         if (cnt[a[j]] == 1) {           int p = pos[a[j]][cnt[a[j]] - 1];           b[p] = -1;           if (p <= i * siz - siz) cal((p - 1) / siz + 1);         } else if (cnt[a[j]] > 1) {           int p1 = pos[a[j]][cnt[a[j]] - 2], p2 = pos[a[j]][cnt[a[j]] - 1];           b[p1] = 0;           b[p2] = -1;           if (p1 <= i * siz - siz) cal((p1 - 1) / siz + 1);           if (p2 <= i * siz - siz) cal((p2 - 1) / siz + 1);         }         b[j] = 1;         cnt[a[j]]++;         int tmp = 0;         for (int k = j; k > i * siz - siz; k--) {           tmp += b[k];           if (tmp <= lim) f[j] = (f[j] + f[k - 1]) % Mod;         }         for (int k = i - 1; k; k--) {           if (lim - tmp >= -siz)             f[j] = (f[j] + sum_f[k][min(lim - tmp, siz) + B]) % Mod;           tmp += sum_b[k];         }       }       if (i < block_cnt) cal(i);     }     cout << f[n] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long x, y, z, f[5010][5010], lsg, n, xx, yy, zz;   signed main() {     cin >> x >> y >> z;     n = max(x, max(y, z));     lsg = 998244353;     for (long long i = 0; i <= n; i++) f[0][i] = f[i][0] = 1;     for (long long i = 1; i <= n; i++)       for (long long j = 1; j <= n; j++)         (f[i][j] = f[i - 1][j - 1] * i + f[i][j - 1]) %= lsg;     xx = max(f[x][y], f[y][x]);     yy = max(f[x][z], f[z][x]);     zz = max(f[z][y], f[y][z]);     cout << xx * yy % lsg * zz % lsg << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1010, MAXM = 14, MAXS = MAXM * MAXM, MOD = 1e9 + 9;   void setmax(int &x, int y) {     if (x < y) {       x = y;     }   }   void add(int &x, int y) { x = (x + y) % MOD; }   int N, M;   string str[MAXM];   map<string, int> mp;   int ind;   int dp[MAXN][MAXS][MAXM];   int nxt[MAXS][4];   int suff[MAXS];   int main() {     if (fopen( input.txt ,  r )) {       freopen( input.txt ,  r , stdin);     }     ios::sync_with_stdio(false);     cin >> N >> M;     mp[  ] = ind++;     int maxlen = 0;     for (int i = 0; i < M; i++) {       cin >> str[i];       setmax(maxlen, str[i].length());       string t;       for (char c : str[i]) {         t += c;         if (!mp.count(t)) {           mp[t] = ind++;         }       }     }     for (auto it = (mp).begin(); it != (mp).end(); it++) {       string s;       for (int i = 0; i < 4; i++) {         s = it->first +  ACGT [i];         while (!mp.count(s)) {           s.erase(s.begin());         }         nxt[it->second][i] = mp[s];       }       s = it->first;       for (int i = 0; i < M; i++) {         string t = str[i];         if (s.length() < t.length()) {           continue;         }         bool match = true;         for (int i = int(s.length()) - 1, j = int(t.length()) - 1; j >= 0;              i--, j--) {           if (s[i] != t[j]) {             match = false;             break;           }         }         if (match) {           setmax(suff[it->second], t.length());         }       }     }     dp[0][0][0] = 1;     for (int i = 0; i < N; i++) {       for (int j = 0; j < ind; j++) {         for (int k = 0; k < maxlen; k++) {           for (int c = 0; c < 4; c++) {             int nj = nxt[j][c], nk = k + 1;             if (nk <= suff[nj]) {               nk = 0;             }             if (nk >= maxlen) {               continue;             }             add(dp[i + 1][nj][nk], dp[i][j][k]);           }         }       }     }     int ans = 0;     for (int i = 0; i < ind; i++) {       add(ans, dp[N][i][0]);     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   struct query {     int en, ll, rr, ind;   };   int tr[3][3000000], mx, h, w, n, m, ok[400000];   vector<int> vrx[300000], vry[300000];   vector<query> qrx[300000], qry[300000];   void build(int x, int l, int r, int tp) {     if (l == r) {       tr[tp][x] = 300000;       return;     }     int mid = (r + l) / 2;     build(x * 2, l, mid, tp);     build(x * 2 + 1, mid + 1, r, tp);     tr[tp][x] = max(tr[tp][x * 2], tr[tp][x * 2 + 1]);   }   void md(int x, int l, int r, int ll, int y, int tp) {     if (l == r) {       tr[tp][x] = y;       return;     }     int mid = (r + l) / 2;     if (ll <= mid)       md(x * 2, l, mid, ll, y, tp);     else       md(x * 2 + 1, mid + 1, r, ll, y, tp);     tr[tp][x] = max(tr[tp][x * 2], tr[tp][x * 2 + 1]);   }   void findmx(int x, int l, int r, int ll, int rr, int tp) {     if (ll <= l && r <= rr) {       if (mx < tr[tp][x]) mx = tr[tp][x];       return;     }     int mid = (r + l) / 2;     if (ll <= mid) findmx(x * 2, l, mid, ll, rr, tp);     if (rr > mid) findmx(x * 2 + 1, mid + 1, r, ll, rr, tp);     tr[tp][x] = max(tr[tp][x * 2], tr[tp][x * 2 + 1]);   }   int main() {     ios_base::sync_with_stdio(0);     cin >> h >> w >> n >> m;     for (int i = 1; i <= n; i++) {       int x, y;       cin >> x >> y;       vrx[x].push_back(y);       vry[y].push_back(x);     }     for (int i = 1; i <= m; i++) {       int xb, yb, xe, ye;       cin >> xb >> yb >> xe >> ye;       qrx[xb].push_back((query){xe, yb, ye, i});       qry[yb].push_back((query){ye, xb, xe, i});     }     build(1, 1, h, 0);     build(1, 1, w, 1);     for (int i = h; i >= 1; i--) {       for (int j = 0; j < vrx[i].size(); j++) {         int y = vrx[i][j];         md(1, 1, w, y, i, 1);       }       for (int j = 0; j < qrx[i].size(); j++) {         int y = qrx[i][j].en;         int l = qrx[i][j].ll;         int r = qrx[i][j].rr;         int sl = qrx[i][j].ind;         mx = 0;         findmx(1, 1, w, l, r, 1);         if (mx <= y) ok[sl] = 1;       }     }     for (int i = w; i >= 1; i--) {       for (int j = 0; j < vry[i].size(); j++) {         int x = vry[i][j];         md(1, 1, h, x, i, 0);       }       for (int j = 0; j < qry[i].size(); j++) {         int x = qry[i][j].en;         int l = qry[i][j].ll;         int r = qry[i][j].rr;         int sl = qry[i][j].ind;         mx = 0;         findmx(1, 1, h, l, r, 0);         if (mx <= x) ok[sl] = 1;       }     }     for (int i = 1; i <= m; i++)       if (ok[i] == 1)         cout <<  YES n ;       else         cout <<  NO n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   queue<char> qq[2][310][310];   vector<vector<int> > res1;   vector<vector<int> > res2;   void move(int x, int y, int p, int q, int k) {     qq[k][p][q].push(qq[k][x][y].front());     qq[k][x][y].pop();     if (k)       res2.push_back(vector<int>({p, q, x, y}));     else       res1.push_back(vector<int>({x, y, p, q}));   }   int main() {     int n, m;     cin >> n >> m;     string s;     for (int k = 0; k < 2; ++k)       for (int i = 1; i <= n; ++i)         for (int j = 1; j <= m; ++j) {           cin >> s;           if (!k) reverse(s.begin(), s.end());           for (char c : s) qq[k][i][j].push(c);         }     for (int k = 0; k < 2; ++k) {       for (int i = 2; i <= n; ++i)         while (!qq[k][i][1].empty()) move(i, 1, 1, 1, k);       for (int i = 2; i <= m; ++i)         while (!qq[k][1][i].empty()) move(1, i, 1, 1, k);       while (!qq[k][1][1].empty())         if (qq[k][1][1].front() -  0 ) {           move(1, 1, 1, 2, k);         } else {           move(1, 1, 2, 1, k);         }       for (int i = 2; i <= n; ++i)         for (int j = 2; j <= m; ++j) {           while (!qq[k][i][j].empty())             if (qq[k][i][j].front() -  0 ) {               if (j == 2)                 move(i, j, 1, 2, k);               else {                 move(i, j, 1, j, k);                 move(1, j, 1, 2, k);               }             } else {               if (i == 2)                 move(i, j, 2, 1, k);               else {                 move(i, j, i, 1, k);                 move(i, 1, 2, 1, k);               }             }         }     }     cout << res1.size() + res2.size() << endl;     for (int i = 0; i < res1.size(); ++i) {       for (int j = 0; j < 4; ++j) printf( %d  , res1[i][j]);       printf(  n );     }     for (int i = res2.size() - 1; i >= 0; --i) {       for (int j = 0; j < 4; ++j) printf( %d  , res2[i][j]);       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long cal(int a, int b, int c, int l) {     int x = min(l, a - b - c);     if (x < 0) return 0;     return (long long)(x + 2) * (x + 1) / 2;   }   int main() {     int a, b, c, l;     cin >> a >> b >> c >> l;     long long ans = (long long)(l + 1) * (l + 2) * (l + 3) / 6;     for (int i = 0; i <= l; ++i) {       ans -= cal(a + i, b, c, l - i);       ans -= cal(b + i, a, c, l - i);       ans -= cal(c + i, a, b, l - i);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int K = 110;   const int MOD = 998244353;   const int PHI = MOD - 1;   int _w;   void add_phi(int &a, int b) {     a += b;     a -= a >= PHI ? PHI : 0;   }   int pow_mod(int a, int b, int p) {     if (!b) return 1;     long long rtn = pow_mod(a, b >> 1, p);     rtn = rtn * rtn % p;     if (b & 1) rtn = rtn * a % p;     return int(rtn);   }   int inv(int x, int p) { return pow_mod(x, p - 2, p); }   void exgcd(int a, int b, int &d, long long &x, long long &y) {     if (!b) {       d = a, x = 1, y = 0;     } else {       exgcd(b, a % b, d, y, x);       y -= a / b * x;     }   }   int k, b[K], n, m;   int A[K][K], Q[K][K];   void mul(int A[K][K], int B[K][K], int C[K][K]) {     static int tmp[K][K];     memset(tmp, 0, sizeof tmp);     for (int i = 0; i < k; ++i)       for (int j = 0; j < k; ++j)         for (int kk = 0; kk < k; ++kk)           add_phi(tmp[i][j], int(1LL * A[i][kk] * B[kk][j] % PHI));     for (int i = 0; i < k; ++i)       for (int j = 0; j < k; ++j) C[i][j] = tmp[i][j];   }   void fpow(int A[K][K], int b, int C[K][K]) {     static int tmp[K][K];     memset(tmp, 0, sizeof tmp);     for (int i = 0; i < k; ++i) tmp[i][i] = 1;     while (b) {       if (b & 1) mul(tmp, A, tmp);       mul(A, A, A);       b >>= 1;     }     for (int i = 0; i < k; ++i)       for (int j = 0; j < k; ++j) C[i][j] = tmp[i][j];   }   int solve() {     A[0][k - 1] = 1;     for (int i = 1; i < k; ++i) Q[i][i - 1] = 1;     for (int i = 0; i < k; ++i) Q[i][k - 1] = b[i] % PHI;     fpow(Q, n - k, Q);     mul(A, Q, A);     return A[0][k - 1];   }   map<long long, int> mp;   int bsgs(int a, int b, int p) {     mp.clear();     int m = int(sqrt(p) + 1);     long long e = 1;     for (int i = 0; i < m; ++i) {       if (!mp.count(e)) mp[e] = i;       e = e * a % p;     }     long long iv = inv(int(e), p);     int orb = b;     for (int i = 0; i < m; ++i) {       if (mp.count(b)) {         int x = i * m + mp[b];         if (pow_mod(a, x, p) == orb) return x;       }       b = int(b * iv % p);     }     return -1;   }   void kleft(int P, int A, int B) {     int g = 3, bk = bsgs(g, B, P), phip = P - 1;     int d;     long long xk, n;     exgcd(A, -phip, d, xk, n);     if (bk % d) {       puts( -1 );       return;     }     xk *= bk / d, n *= bk / d;     int phip2 = abs(phip / d);     xk = (xk % phip2 + phip2) % phip2;     mp.clear();     long long x = pow_mod(g, int(xk), P);     printf( %lld n , x);   }   int main() {     _w = scanf( %d , &k);     for (int i = 0; i < k; ++i) _w = scanf( %d , b + i);     reverse(b, b + k);     _w = scanf( %d%d , &n, &m);     int tmp = solve();     kleft(MOD, tmp, m);     return 0;   }