malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n, k;   map<int, int> mapa;   int arr[400100];   int main() {     scanf( %d %d , &n, &k);     for (int i = 0; i < n; i++) scanf( %d , &arr[i]);     long long res = 0;     int ini = 0, fin = 0;     int x, y;     while (fin < n) {       mapa[arr[fin]]++;       x = mapa[arr[fin]];       if (x >= k) {         do {           mapa[arr[ini]]--;           res += (n - fin);           if (arr[ini] == arr[fin]) {             ini++;             break;           }           ini++;         } while (ini <= fin);         fin++;       } else         fin++;     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<unordered_set<long long>> v1(2e5), v2(2e5);   void solve() {     long long n, m;     cin >> n >> m;     for (auto i = 0; i < m; i++) {       long long a, b;       cin >> a >> b;       a--;       b--;       v1[min(a, b)].insert(max(a, b));     }     v2 = v1;     long long count = 0;     for (auto j = 0; j < n; j++) {       if (v2[j].size() == 0) {         count++;       }     }     long long q;     cin >> q;     for (auto i = 0; i < q; i++) {       long long a;       cin >> a;       if (a != 3) {         long long b, c;         cin >> b >> c;         b--;         c--;         if (a == 1) {           v2[min(b, c)].insert(max(b, c));           if (v2[min(b, c)].size() == 1) count -= 1;         } else {           v2[min(b, c)].erase(max(b, c));           if (v2[min(b, c)].size() == 0) count += 1;         }       } else {         cout << count <<   n ;       }     }   }   int main() { solve(); }
#include <bits/stdc++.h>   using namespace std;   long long n, m, q;   long long gcd(long long a, long long b) {     if (a < b) swap(a, b);     if (b == 0) return a;     return gcd(b, a % b);   }   int main() {     cin >> n >> m >> q;     long long v = gcd(n, m);     long long innersize = n / v;     long long outersize = m / v;     for (int i = 0; i < q; i++) {       long long s1, x1, s2, x2;       cin >> s1 >> x1 >> s2 >> x2;       x1--;       x2--;       if (s1 == 1) {         x1 /= innersize;       } else {         x1 /= outersize;       }       if (s2 == 1) {         x2 /= innersize;       } else {         x2 /= outersize;       }       if (x1 == x2) {         cout <<  YES n ;       } else {         cout <<  NO n ;       }     }   }
#include <bits/stdc++.h>   #pragma optimize( Ofast )   using namespace std;   using ll = long long int;   using ull = unsigned long long int;   using dd = double;   using ldd = long double;   using si = short int;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   int main() {     ios_base::sync_with_stdio(0);     cout.tie(0);     cin.tie(0);     int n;     cin >> n;     vector<ll> arr(n);     for (int i = 0; i < n; ++i) cin >> arr[i];     string s;     cin >> s;     ll wg, ww;     wg = ww = 0;     ll e = 0;     ll ans = 0;     bool was_w = 0;     vector<ll> tos;     for (int i = 0; i < n; ++i) {       if (s[i] ==  L ) {         if (arr[i] <= e) {           e -= arr[i];           ans += arr[i];           ww = wg = 0;         } else {           e -= arr[i];           ans += arr[i];           if (was_w) {             ans -= e * 3;           } else {             ans -= e * 5;           }           e = 0;           ww = wg = 0;         }         tos.push_back(e);         continue;       }       if (s[i] ==  W ) {         was_w = 1;         ans += arr[i] * 3;         ww += arr[i];         e += arr[i];         tos.push_back(e);         continue;       }       if (s[i] ==  G ) {         ans += arr[i] * 5;         wg += arr[i];         e += arr[i];         tos.push_back(e);         continue;       }     }     for (int i = tos.size() - 2; i >= 0; --i) tos[i] = min(tos[i], tos[i + 1]);     ll mi = 0;     for (int i = 0; i < n; ++i) {       tos[i] -= mi;       if (s[i] ==  G ) {         if (arr[i] * 2 <= tos[i]) {           ans -= arr[i] * 4;           tos[i] -= arr[i] * 2;           mi += arr[i] * 2;         } else {           mi += tos[i];           ans -= tos[i] * 2;           tos[i] = 0;         }       }     }     for (int i = tos.size() - 2; i >= 0; --i) tos[i] = min(tos[i], tos[i + 1]);     mi = 0;     for (int i = 0; i < n; ++i) {       tos[i] -= mi;       if (s[i] ==  W ) {         if (arr[i] * 2 <= tos[i]) {           tos[i] -= arr[i] * 2;           mi += arr[i] * 2;           ans -= arr[i] * 2;         } else {           mi += tos[i];           ans -= tos[i];           tos[i] = 0;         }       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int m = 0, k = 0, p = 0, i = 1;     string s;     cin >> s;     int n, a[27];     cin >> n;     for (i = 1; i < 27; i++) cin >> a[i], m = max(m, a[i]);     for (i = 0; i < s.length(); i++) k += a[s[i] - 96] * (i + 1);     while (n--) i++, p += i * m;     cout << k + p;   }
#include <bits/stdc++.h>   int v[1000005];   int main() {     int i, j, k;     int n, m, a, b;     int f[1010];     while (~scanf( %d , &n)) {       memset(v, 0, sizeof(v));       a = b = 0;       for (i = 0; i < n; i++) {         scanf( %d , &f[i]);         v[f[i]]++;         if (v[f[i]] > b) {           a = f[i];           b = v[f[i]];         }       }       printf( %d n , a);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     vector<string> S(26);     for (auto ch : s) {       S[ch -  a ] += ch;       if (S[ch -  a ].size() == 100) {         cout << S[ch -  a ] << endl;         return 0;       }     }     int n = s.size();     int f[n + 1][n + 1];     int g[n + 1][n + 1];     for (int len = 1; len <= n; ++len)       for (int i = 0; i + len - 1 < n; ++i) {         if (len == 1)           f[len][i] = 1;         else if (len == 2 && s[i] == s[i + len - 1])           f[len][i] = 2;         else {           int a = f[len - 1][i] < f[len - 1][i + 1] ? f[len - 1][i + 1]                                                     : f[len - 1][i];           if (f[len - 1][i] == a)             g[len][i] = 0;           else             g[len][i] = 1;           if (len > 2 && s[i] == s[i + len - 1] && 2 + f[len - 2][i + 1] > a) {             a = 2 + f[len - 2][i + 1];             g[len][i] = 2;           }           f[len][i] = a;         }       }     vector<int> v;     int len = n, x = 0;     while (true) {       if (len == 1) {         v.push_back(x);         break;       }       if (len == 2 && s[x] == s[x + len - 1]) {         v.push_back(x);         v.push_back(x + 1);         break;       }       if (g[len][x] == 0)         --len;       else if (g[len][x] == 1) {         --len;         ++x;       } else {         v.push_back(x);         v.push_back(x + len - 1);         len -= 2;         ++x;       }     }     sort(v.begin(), v.end());     int take = 50;     for (int i = 0; i < v.size(); ++i)       if (i < take || i + take >= v.size()) cout << s[v[i]];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char buf[200010];   char a[200010];   int n, t;   int l;   int digp;   set<int> s;   int main() {     scanf( %d%d , &n, &t);     scanf( %s , buf);     for (int i = n - 1; 0 <= i; --i) {       if (buf[i] ==  . ) {         digp = n - 1 - i;         continue;       }       a[l++] = buf[i];     }     for (int i = l; i <= 200005; ++i) a[i] =  0 ;     for (int i = 0; a[i]; ++i) {       if (a[i] ==  . ) continue;       if (a[i] >=  5  && i < digp) s.insert(i);     }     int clear_until = 0;     for (; t--;) {       if (s.empty()) break;       int pt = *--s.end();       s.clear();       clear_until = max(clear_until, pt);       a[pt] =  0 ;       for (int i = pt + 1; a[i]; ++i) {         if (a[i] ==  9 ) {           a[i] =  0 ;         } else {           ++a[i];           if (a[i] >=  5  && i < digp) s.insert(i);           break;         }       }     }     for (int i = 0; i < clear_until; ++i) a[i] =  0 ;     int last_exist = digp;     for (int i = 0; i < digp; ++i)       if (a[i] !=  0 ) {         last_exist = min(last_exist, i);       }     bool started = false;     for (int i = 200005; last_exist <= i; --i) {       if (a[i] >  0 ) {         started = true;       }       if (started) putchar(a[i]);       if (i == digp) {         if (last_exist < i) {           if (!started) putchar( 0 );           putchar( . );           started = true;         } else {           break;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     cout << k * (6 * n - 1) << endl;     for (int i = 0; i < n; i++) {       cout << (6 * i + 1) * k <<     << (6 * i + 2) * k <<     << (6 * i + 3) * k            <<     << (6 * i + 5) * k << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long power(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) {         res = (res * x) % p;       }       y = y >> 1;       x = (x * x) % p;     }     return res;   }   long long modInverse(long long a, long long p) { return power(a, p - 2, p); }   void gcd(long long a, long long b, long long& d, long long& u, long long& v) {     if (b == 0) {       d = a;       u = 1;       v = 0;     } else {       gcd(b, a % b, d, v, u);       v -= a / b * u;     }   }   long long Inverse(long long a, long long m) {     a %= m;     if (a < 0) a += m;     long long d, u, v;     gcd(a, m, d, u, v);     assert(d == 1);     u %= m;     if (u < 0) u += m;     return u;   }   long long gcd(long long x, long long y) {     if (x == 0 || y == 0) {       return max(y, x);     }     return gcd(y % x, x);   }   long long gcdExtended(long long a, long long b, long long& x, long long& y) {     if (a == 0) {       x = 0;       y = 1;       return b;     }     long long x1, y1;     long long gcd = gcdExtended(b % a, a, x1, y1);     x = y1 - (b / a) * x1;     y = x1;     return gcd;   };   int main() {     long long n;     scanf( %lld , &n);     ;     vector<long long> a;     for (long long i = 0; i < n; i++) {       long long x;       scanf( %lld , &x);       a.push_back(x);     }     vector<long long> sum;     long long z = 0;     for (long long i = 0; i < n; i++) {       z += a[i];       sum.push_back(z);     }     long long p = 2;     long long ans = 1e18;     while (p * p <= z) {       if (z % p == 0) {         while (z % p == 0) z /= p;         long long ret = 0;         for (long long i = 0; i < n - 1; i++) {           ret += (min(sum[i] % p, p - sum[i] % p));         }         ans = min(ans, ret);       }       p++;     }     if (z != 1) {       p = z;       long long ret = 0;       for (long long i = 0; i < n - 1; i++) {         ret += (min(sum[i] % p, p - sum[i] % p));       }       ans = min(ans, ret);     }     if (ans == 1e18) ans = -1;     cout << ans << endl;   }
#include <bits/stdc++.h>   const int N = 1000001;   using namespace std;   char sub[N], s[N], l[N];   int a[10];   int main() {     scanf( %s , s);     int i, j, len1, len2;     len1 = strlen(s);     for (i = 0; i < len1; i++) a[s[i] -  0 ]++;     scanf( %s , sub);     len2 = strlen(sub);     for (i = 0; i < len2; i++) a[sub[i] -  0 ]--;     int lt = 1, rt = 1000000, mid, t, w;     while (lt <= rt) {       mid = (lt + rt) >> 1;       t = mid;       w = 0;       while (t > 0) {         w++;         t /= 10;       }       if (mid + w == len1)         break;       else if (mid + w < len1)         lt = mid + 1;       else         rt = mid - 1;     }     t = mid;     while (t > 0) {       a[t % 10]--;       t /= 10;     }     bool ok = true;     if (a[0] > 0 || sub[0] ==  0 ) {       ok = false;       for (i = 1; i < 10; i++)         if (a[i] > 0) break;       if (i < 10) {         ok = true;         if (i < sub[0] -  0 ) {           a[i]--;           printf( %d , i);         } else if (i > sub[0] -  0 ) {           if (sub[0] !=  0 ) {             printf( %s , sub);             for (i = 0; i < 10; i++)               for (j = 1; j <= a[i]; j++) printf( %d , i);             return 0;           }           printf( %d , i);           a[i]--;         } else {           int p = 0, q;           a[i]--;           l[p++] = (char)(i +  0 );           for (i = 0; i < 10; i++)             for (j = 1; j <= a[i]; j++) l[p++] = (char)(i +  0 );           q = p;           if (p < len2) {             for (i = 0; p < len2; i++) l[p++] = sub[i];           }           for (i = 0; i < len2; i++)             if (l[i] != sub[i]) break;           if (i < len2 && sub[i] < l[i]) {             l[q] =   0 ;             sort(l, l + q);             printf( %s%s , sub, l);             return 0;           }           printf( %c , sub[0]);         }       }     }     int p = 0, q;     for (i = 0; i < 10; i++)       for (j = 1; j <= a[i]; j++) l[p++] = (char)(i +  0 );     l[p] =   0 ;     if (!ok) {       printf( %s%s , sub, l);       return 0;     }     if (p == 0) {       printf( %s , sub);       return 0;     }     for (i = 0; i < p; i++) {       if (l[i] < sub[0]) {         printf( %c , l[i]);         continue;       }       if (l[i] > sub[0]) {         printf( %s , sub);         printf( %s , l + i);         return 0;       }       for (j = 1; j < len2; j++)         if (sub[j] != sub[0]) break;       if (j == len2 || sub[j] < sub[0]) {         printf( %s , sub);         printf( %s , l + i);         return 0;       } else {         for (; l[i] == sub[0]; i++) printf( %c , l[i]);         printf( %s , sub);         printf( %s , l + i);         return 0;       }     }     printf( %s , sub);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = (int)1e9 + 7;   const int MAXK = 405;   int dp[MAXK][2 * MAXK];   inline void mod(int &x) {     if (x >= MOD) x -= MOD;   }   inline void add(int &x, int y) {     x += y;     mod(x);   }   int main() {     int i, k;     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     cin >> k;     dp[1][0] = dp[1][1] = 1;     for (i = 2; i <= k; i++) {       for (int a = 0; a <= k; a++) {         if (dp[i - 1][a] == 0) continue;         for (int b = 0; b <= k; b++) {           if (dp[i - 1][b] == 0) continue;           int x = (1LL * dp[i - 1][a] * dp[i - 1][b]) % MOD;           add(dp[i][a + b], (2LL * x * (a + b) + x) % MOD);           add(dp[i][a + b + 1], x);           if (a + b > 0) {             int two = (a + b) * (a + b - 1);             add(dp[i][a + b - 1], (1LL * two * x) % MOD);           }         }       }     }     cout << dp[k][1];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int N = 4e5 + 2, inf = 1e12 + 7;   vector<pair<int, int> > vec[N];   pair<int, pair<int, int> > edg[N];   long long int n, dis[N], dis2[N], st[N], ed[N];   long long int T[2 * N], lzy[2 * N], tim;   void dfs(int u, int pr) {     st[u] = ++tim;     for (auto x : vec[u]) {       int v = x.first, w = x.second;       if (v == pr) continue;       dis[v] = dis[u] + w;       dfs(v, u);     }     ed[u] = tim;   }   void push_down(int nod, int lo, int hi) {     T[nod] += lzy[nod];     if (lo != hi) {       lzy[2 * nod] += lzy[nod];       lzy[2 * nod + 1] += lzy[nod];     }     lzy[nod] = 0;   }   void updt(int nod, int lo, int hi, int l, int r, int vl) {     if (lzy[nod]) push_down(nod, lo, hi);     if (hi < l || lo > r || lo > hi) return;     if (lo >= l && hi <= r) {       T[nod] += vl;       if (lo != hi) {         lzy[2 * nod] += vl;         lzy[2 * nod + 1] += vl;       }       return;     }     int md = (lo + hi) >> 1;     updt(2 * nod, lo, md, l, r, vl);     updt(2 * nod + 1, md + 1, hi, l, r, vl);     T[nod] = min(T[2 * nod], T[2 * nod + 1]);   }   long long int qry(int nod, int lo, int hi, int l, int r) {     if (lzy[nod]) push_down(nod, lo, hi);     if (hi < l || lo > r || lo > hi) return inf;     if (lo >= l && hi <= r) return T[nod];     int md = (lo + hi) >> 1;     return min(qry(2 * nod, lo, md, l, r), qry(2 * nod + 1, md + 1, hi, l, r));   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int tc = 1, t = 0;     while (tc--) {       int q;       cin >> n >> q;       for (int i = 1; i < n; i++) {         int u, v, c;         cin >> u >> v >> c;         vec[u].push_back(make_pair(v, c));         edg[i] = make_pair(u, make_pair(v, c));       }       for (int i = n; i < n + n - 1; i++) {         int u, v, c;         cin >> u >> v >> c;         edg[i] = make_pair(u, make_pair(v, c));         dis2[u] = c;       }       dfs(1, -1);       for (int i = 1; i <= n; i++) updt(1, 1, n, st[i], st[i], dis[i] + dis2[i]);       while (q--) {         int typ;         cin >> typ;         if (typ == 1) {           int id, w;           cin >> id >> w;           int u = edg[id].first, v = edg[id].second.first;           int c = edg[id].second.second;           if (id < n) {             updt(1, 1, n, st[v], ed[v], -c);             updt(1, 1, n, st[v], ed[v], w);             edg[id].second.second = w;           } else {             updt(1, 1, n, st[u], st[u], -c);             updt(1, 1, n, st[u], st[u], w);             edg[id].second.second = w;             dis2[u] = w;           }         } else {           int u, v;           cin >> u >> v;           if (st[v] >= st[u] && ed[u] >= ed[v]) {             cout << qry(1, 1, n, st[v], st[v]) - qry(1, 1, n, st[u], st[u]) +                         dis2[u] - dis2[v]                  <<   n ;           } else {             long long int rs = qry(1, 1, n, st[u], ed[u]);             rs -= qry(1, 1, n, st[u], st[u]);             rs += qry(1, 1, n, st[v], st[v]);             rs += dis2[u] - dis2[v];             cout << rs <<   n ;           }         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   void Anivia_kid() {     long long n;     cin >> n;     long long res = 1 + 3 * n * (n + 1);     cout << res <<   n ;     return;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int q = 1;     while (q--) {       Anivia_kid();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100000;   const int inf = (int)1e9 + 1;   const long long big = (long long)1e18 + 1;   const int P = 239;   const int MOD = (int)1e9 + 7;   const int MOD1 = (int)1e9 + 9;   const double eps = 1e-9;   const double pi = atan2(0, -1);   const int ABC = 26;   vector<int> g[N];   bool used[N];   vector<int> comp;   void dfs(int u) {     used[u] = true;     comp.push_back(u);     for (int v : g[u])       if (!used[v]) dfs(v);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.precision(20);     int n, A, B;     cin >> n >> A >> B;     int a[n];     map<int, int> mapa;     for (int i = 0; i < n; i++) {       cin >> a[i];       mapa[a[i]] = i;     }     for (int i = 0; i < n; i++) {       if (mapa.find(A - a[i]) != mapa.end()) g[i].push_back(mapa[A - a[i]]);       if (mapa.find(B - a[i]) != mapa.end()) g[i].push_back(mapa[B - a[i]]);     }     int ans[n];     for (int i = 0; i < n; i++)       if (!used[i]) {         comp.clear();         dfs(i);         int mask = 3;         for (int j : comp) {           int cur = 0;           if (mapa.find(A - a[j]) != mapa.end()) cur |= 1;           if (mapa.find(B - a[j]) != mapa.end()) cur |= 2;           mask &= cur;         }         if (mask == 0) {           cout <<  NO n ;           return 0;         }         if (mask & 1) {           for (int j : comp) ans[j] = 0;         } else {           for (int j : comp) ans[j] = 1;         }       }     cout <<  YES n ;     for (int i = 0; i < n; i++) cout << ans[i] <<    ;     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s;     bool flag = false;     cin >> s;     stringstream ss(s);     char arr[2 * n];     int min0 = 10;     int max0 = 0;     int min1 = 10;     int max1 = 0;     for (int i = 0; i < 2 * n; i++) {       arr[i] = s.at(i);       if (i < n) {         if (min0 > (int)arr[i] - 48) {           min0 = (int)arr[i] - 48;         }         if (max0 < (int)arr[i] - 48) {           max0 = (int)arr[i] - 48;         }       } else {         if (min1 > (int)arr[i] - 48) {           min1 = (int)arr[i] - 48;         }         if (max1 < (int)arr[i] - 48) {           max1 = (int)arr[i] - 48;         }       }     }     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         if ((int)arr[i] - 48 > (int)arr[j] - 48) {           char temp = arr[i];           arr[i] = arr[j];           arr[j] = temp;         }         if ((int)arr[i + n] - 48 > (int)arr[j + n] - 48) {           char temp = arr[i + n];           arr[i + n] = arr[j + n];           arr[j + n] = temp;         }       }     }     if (min0 < min1) {       for (int i = 0; i < n; i++) {         if (int(arr[i]) >= int(arr[i + n])) {           flag = true;           break;         }       }     } else {       for (int i = 0; i < n; i++) {         if (int(arr[i]) <= int(arr[i + n])) {           flag = true;           break;         }       }     }     if (flag) {       cout <<  NO  << endl;     } else {       cout <<  YES  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void a15hx() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, l, r, x;     cin >> n >> l >> r >> x;     long long diff[n];     for (long long i = 0; i < n; i++) {       cin >> diff[i];     }     long long ways = 0;     for (long long i = 0; i < 1 << n; i++) {       if (__builtin_popcount(i) >= 2) {         long long tot_diff = 0, easy = INT32_MAX, hard = INT32_MIN;         for (long long j = 0; j < n; j++) {           if (i >> j & 1) {             tot_diff += diff[j];             easy = min(easy, diff[j]);             hard = max(hard, diff[j]);           }         }         if (tot_diff <= r && tot_diff >= l && hard - easy >= x) {           ways++;         }       }     }     cout << ways;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     a15hx();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2;   const int MO = 1e9 + 7;   const int K = 5e8 + 4;   struct Matrix {     int a[N][N];     Matrix(bool ident = 0) {       for (int i = int(0); i <= int((N)-1); i++)         for (int j = int(0); j <= int((N)-1); j++) a[i][j] = 0;       if (ident) {         for (int i = int(0); i <= int((N)-1); i++) a[i][i] = 1;       }     }     int *operator[](int i) { return a[i]; }     const int *operator[](int i) const { return a[i]; }   };   void add(int &x, int y) {     x += y;     if (x >= MO) x -= MO;   }   Matrix operator*(const Matrix &a, const Matrix &b) {     Matrix c;     for (int i = int(0); i <= int((N)-1); i++)       for (int j = int(0); j <= int((N)-1); j++)         for (int k = int(0); k <= int((N)-1); k++) {           add(c[i][j], 1LL * a[i][k] * b[k][j] % MO);         }     return c;   }   Matrix powd(Matrix a, long long b) {     Matrix ans(1);     while (b) {       if (b & 1) ans = ans * a;       a = a * a;       b >>= 1;     }     return ans;   }   int powd(int a, long long b) {     int ans = 1;     while (b) {       if (b & 1) ans = 1LL * ans * a % MO;       b >>= 1;       a = 1LL * a * a % MO;     }     return ans;   }   int main() {     Matrix magic;     magic[0][0] = magic[1][0] = 1, magic[0][1] = 2;     int n;     cin >> n;     Matrix now = magic;     int down = 2;     for (int i = int(0); i <= int((n)-1); i++) {       long long x;       scanf( %I64d , &x);       now = powd(now, x);       down = powd(down, x);     }     cout << 1LL * now[1][1] * K % MO <<  /  << 1LL * down * K % MO << endl;     return 0;   }