malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   using namespace std;   int a[510][510];   int mi[510][510];   int main() {     ios_base::sync_with_stdio(0);     int n, m, k, q;     cin >> n >> m >> k >> q;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         a[i][j] = -1;         mi[i][j] = -1;       }     for (int i = 1; i <= q; i++) {       int x, y, z;       cin >> x >> y >> z;       a[x][y] = z;     }     for (int i = 1; i <= n; i++) {       multiset<int> st;       for (int j = 1; j <= k; j++) {         st.insert(a[i][j]);       }       for (int j = k + 1; j <= m + 1; j++) {         auto kk = st.end();         kk--;         if ((*st.begin()) != -1) mi[i][j - k] = (*kk);         st.erase(st.find(a[i][j - k]));         st.insert(a[i][j]);       }     }     int ans = 2e9;     for (int j = 1; j <= m - k + 1; j++) {       multiset<int> st;       for (int i = 1; i <= k; i++) {         st.insert(mi[i][j]);       }       for (int i = k + 1; i <= n + 1; i++) {         auto kk = st.end();         kk--;         if ((*st.begin()) != -1) ans = min(ans, (*kk));         st.erase(st.find(mi[i - k][j]));         st.insert(mi[i][j]);       }     }     if (ans == 2e9)       cout << -1;     else       cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     node* child[26];     priority_queue<int> pq;     bool leaf;     node() {       memset(child, 0, sizeof child);       leaf = false;     }   };   void insert(node* curr, const string& x) {     for (auto c : x) {       if (!curr->child[c -  a ]) curr->child[c -  a ] = new node();       curr = curr->child[c -  a ];     }     curr->leaf = true;   }   void dfs(node* curr, int lev) {     for (int i = 0; i < 26; i++) {       if (!curr->child[i]) continue;       dfs(curr->child[i], lev + 1);       while (!curr->child[i]->pq.empty())         curr->pq.push(curr->child[i]->pq.top()), curr->child[i]->pq.pop();     }     if (curr->leaf)       curr->pq.push(lev);     else {       if (!curr->pq.empty() && lev) curr->pq.pop(), curr->pq.push(lev);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     node* root = new node();     while (n--) {       string x;       cin >> x;       insert(root, x);     }     dfs(root, 0);     long long ans = 0;     while (!root->pq.empty()) ans += root->pq.top(), root->pq.pop();     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using INT = long long;   using pii = pair<INT, INT>;   using pi3 = pair<pii, INT>;   INT a[5010];   bool dp[5010][5010];   INT val[5010];   vector<pi3> ans;   int main() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     INT n, k, v;     cin >> n >> k >> v;     for (INT i = 1; i <= n; i++) cin >> a[i];     INT sum = 0;     for (INT i = 1; i <= n; i++) sum += a[i];     if (sum < v) {       cout <<  NO  << endl;       return 0;     }     for (INT i = 0; i < k; i++) val[i] = n + 1;     dp[0][0] = 1;     for (INT i = 1; i <= n; i++) {       for (INT j = 0; j < k; j++)         if (dp[i - 1][j]) {           INT temp = (j + a[i]) % k;           dp[i][temp] = 1;           dp[i][j] = 1;           val[temp] = min(val[temp], i);         }       dp[i][a[i] % k] = 1;       val[a[i] % k] = min(val[a[i] % k], i);     }     INT p = v % k;     int fff = 0;     INT ID, sz;     if (p == 0) {       cout <<  YES  << endl;       if (a[1]) cout << (a[1] + k - 1) / k <<   1 2  << endl;       a[2] += a[1];       fff = 1;       ID = 1;       sz = 0;     }     if (!fff) {       INT id = val[p];       if (id == n + 1) {         cout <<  NO  << endl;         return 0;       }       cout <<  YES  << endl;       ID = id;       p -= (a[id] % k);       if (p < 0) p += k;       sz = a[id];       id = val[p];       while (p != 0) {         p -= (a[id] % k);         ans.push_back(pi3(pii(a[id] / k + 1, id), ID));         sz += a[id];         a[id] = 0;         if (p < 0) p += k;         id = val[p];       }     }     INT sr = 1;     if (ID == sr) sr = n;     for (INT i = 1; i <= n; i++) {       if (a[i] == 0 || i == ID || i == sr) continue;       ans.push_back(pi3(pii((a[i] + k - 1) / k, i), sr));     }     INT val = (v - sz) / k;     if (val > 0) {       ans.push_back(pi3(pii(val, sr), ID));     }     if (val < 0) {       ans.push_back(pi3(pii(-val, ID), sr));     }     for (auto p : ans) {       INT u = p.first.first;       INT sr = p.first.second;       INT ta = p.second;       cout << u <<     << sr <<     << ta << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k;   vector<vector<int> > g;   vector<vector<int> > revg;   int active[1000005];   int del;   int limx, limy, limz;   unordered_set<int> visited;   void add(int a, int b) {     if (active[a] && active[b]) {       g[a].push_back(b);       revg[b].push_back(a);     }   }   int get(int a, int b, int c) { return a * m * k + b * k + c; }   bool downlimit(int v) {     if (v == del) return false;     int z(v % k);     v /= k;     int y(v % m);     int x(v / m);     return x <= limx && y <= limy && z <= limz;   }   void dfs(int v) {     visited.insert(v);     for (int i(0), _l((int)(((int)g[v].size())) - 1); i <= _l; ++i) {       int to(g[v][i]);       if (downlimit(to)) dfs(to);     }   }   void solve() {     memset((active), 0, sizeof(active));     scanf( %d%d%d n , &n, &m, &k);     g.resize(n * m * k);     revg.resize(n * m * k);     for (int i(0), _l((int)(n)-1); i <= _l; ++i)       for (int j(0), _l((int)(m)-1); j <= _l; ++j) {         string s;         getline(cin, s);         for (int q(0), _l((int)(k)-1); q <= _l; ++q)           active[get(i, j, q)] = (s[q] ==  1 );         if (j == m - 1) getline(cin, s);       }     for (int i(0), _l((int)(n)-1); i <= _l; ++i)       for (int j(0), _l((int)(m)-1); j <= _l; ++j)         for (int q(0), _l((int)(k)-1); q <= _l; ++q) {           if (i < n - 1) add(get(i, j, q), get(i + 1, j, q));           if (j < m - 1) add(get(i, j, q), get(i, j + 1, q));           if (q < k - 1) add(get(i, j, q), get(i, j, q + 1));         }     int ans(0);     for (int x(0), _l((int)(n)-1); x <= _l; ++x)       for (int y(0), _l((int)(m)-1); y <= _l; ++y)         for (int z(0), _l((int)(k)-1); z <= _l; ++z) {           int v(get(x, y, z));           del = v;           limx = x + 1, limy = y + 1, limz = z + 1;           bool frogs(false);           for (int i(0), _l((int)(((int)revg[v].size())) - 1); i <= _l; ++i) {             int from(revg[v][i]);             visited.clear();             dfs(from);             for (int j(0), _l((int)(((int)g[v].size())) - 1); j <= _l; ++j) {               int to(g[v][j]);               if (!visited.count(to)) frogs = true;               if (frogs) break;             }             if (frogs) break;           }           ans += frogs;         }     printf( %d n , ans);   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {}   const int maxn = (int)1e6 + 420;   const int MOD = (int)1e9 + 7;   int n;   int dp[maxn][4][4];   void contr() {     cout << 0 <<   n ;     exit(0);   }   int madd(int a, int b) {     long long sum = a + b;     sum %= MOD;     return sum;   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     string s;     cin >> s;     n = (int)s.size();     s =  .  + s;     dp[0][0][0] = 1;     for (int i = 1; i <= n; i++) {       for (int l = 0; l <= 3; l++) {         for (int m = 0; m <= 3; m++) {           for (int r = 0; r <= 3; r++) {             if ((i == 1) and !(l == 0 and m == 0)) continue;             if ((i == 2) and !(l == 0)) continue;             bool ok = true;             if (i >= 2) {               if (m == 0 and (l == 3 or r == 3)) {                 ok = false;                 continue;               }               if (m == 1 and !(l == 3 ^ r == 3)) {                 ok = false;                 continue;               }               if (m == 2 and (l != 3 or r != 3)) {                 ok = false;                 continue;               }             }             if (r == 0 and m == 3) {               ok = false;               continue;             }             if (r == 2 and m != 3) {               ok = false;               continue;             }             if (r == 1 and i == n and m != 3) {               ok = false;               continue;             }             if (r == 2 and i == n) {               ok = false;               continue;             }             vector<int> v = {r, m, l};             for (int j = 0; j < 3; j++) {               if (s[i - j] ==  ? ) continue;               if (i - j < 1) continue;               if ((v[j] == 3)) {                 if (s[i - j] !=  * ) {                   ok = false;                   continue;                 }               } else if (s[i - j] -  0  != v[j]) {                 ok = false;                 continue;               }             }             if (ok) {               dp[i][m][r] = madd(dp[i][m][r], dp[i - 1][l][m]);             }           }         }       }     }     int ans = 0;     for (int i = 0; i <= 3; i++) {       for (int j = 0; j <= 3; j++) {         ans = madd(ans, dp[n][i][j]);       }     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     int a[n], e = 0, s = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] == 1)         e++;       else         s++;     }     int ans = 0;     for (int b = 0; b < k; b++) {       int c = b, ee = e, second = s;       while (c < n) {         if (a[c] == 1)           ee--;         else           second--;         c += k;       }       ans = max(ans, abs(ee - second));     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   long long int gcd(long long int a, long long int b) {     if (a == 0)       return b;     else       return gcd(b % a, a);   }   long long int power(long long int a, long long int b, long long int m) {     long long int ans = 1;     while (b) {       if (b & 1) ans = (ans * a) % m;       b /= 2;       a = (a * a) % m;     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n, k;     cin >> n >> k;     long long int ans = 6;     if (n == 2) {       cout << ans << endl;       return 0;     }     if (k == 1 || k == n) {       ans = ans + 3 * (n - 2);     } else {       k = min(k, n - k + 1);       for (long long int i = 1; i < k - 1; i++) ans = ans + 3;       ans = ans + (k - 1);       ans = ans + 3 * (n - k);     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int T, t[200010], n;   int dp[2000][2000];   int main() {     scanf( %d , &T);     while (T--) {       scanf( %d , &n);       for (int i = 1; i <= n; ++i)         for (int j = 1; j <= n + n; ++j) dp[i][j] = (1 << 30);       for (int i = 1; i <= n; ++i) scanf( %d , &t[i]);       sort(t + 1, t + n + 1);       for (int i = 1; i <= n; ++i) {         for (int j = i; j <= n + n; ++j) {           if (j == 1) {             dp[i][j] = abs(t[i] - 1);             continue;           }           for (int k = 1; k < j; ++k) {             dp[i][j] = min(dp[i][j], dp[i - 1][k] + abs(j - t[i]));           }         }       }       int ans = (1 << 30);       for (int i = 1; i <= n + n; ++i) ans = min(ans, dp[n][i]);       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void input(T &x) {     char c = getchar();     x = 0;     for (; (c < 48 || c > 57); c = getchar())       ;     for (; c > 47 && c < 58; c = getchar()) {       x = (x << 1) + (x << 3) + c - 48;     }   }   inline long long bigmod(long long p, long long e, long long M) {     long long ret = 1;     for (; e > 0; e >>= 1) {       if (e & 1) ret = (ret * p) % M;       p = (p * p) % M;     }     return ret;   }   template <class T>   inline T gcd(T a, T b) {     if (b == 0) return a;     return gcd(b, a % b);   }   template <class T>   inline T modinverse(T a, T M) {     return bigmod(a, M - 2, M);   }   const int N = 10005;   int dp[N];   int n;   int a[N];   int main() {     input(n);     for (int i = 0; i < n; i++) input(a[i]);     long long ans = 0;     for (int round = 0; round < n; round++) {       int f = (n - round) % n;       vector<pair<int, int> > v;       v.push_back(make_pair(0, 0));       for (int j = 1; j < n; j++) {         int now = (f + j) % n;         int range = a[now];         int iMin = 1e8;         for (int k = v.size() - 1; k >= 0; k--) {           int pos = v[k].second;           if (j - range <= pos)             iMin = min(iMin, 1 + v[k].first);           else             break;         }         while (v.size() && v.back().first >= iMin) v.pop_back();         v.push_back(make_pair(iMin, j));       }       ans += v.back().first;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, M, dp[109][109][26];   vector<pair<int, char> > v[109];   void solve(int i, int j, int k) {     if (dp[i][j][k] != -1) return;     dp[i][j][k] = 0;     for (auto e : v[i])       if (e.second >= k) {         solve(j, e.first, e.second);         if (dp[j][e.first][e.second] == 0) {           dp[i][j][k] = 1;           break;         }       }   }   int main() {     scanf( %d %d , &N, &M);     while (M--) {       int x, y;       char c;       scanf( %d %d %c n , &x, &y, &c), c -=  a ;       v[x].push_back({y, c});     }     for (int k = 25; k >= 0; k--)       for (int i = 1; i <= N; i++)         for (int j = 1; j <= N; j++) dp[i][j][k] = -1;     for (int k = 25; k >= 0; k--)       for (int i = 1; i <= N; i++)         for (int j = 1; j <= N; j++) solve(i, j, k);     for (int i = 1; i <= N; i++, printf(  n ))       for (int j = 1; j <= N; j++) {         bool win = 0;         for (auto e : v[i])           if (dp[j][e.first][e.second] == 0) {             win = 1;             break;           }         if (win)           printf( A );         else           printf( B );       }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000009;   const int MAXN = 128;   const int MAXK = 4;   struct TrieNode {     int next[MAXK], fail;     int danger;     void init() {       fail = -1;       danger = 0;       for (int i = 0; i < MAXK; ++i) next[i] = -1;     }   } T[MAXN];   int root, Top;   void Init() {     root = 0, Top = 1;     T[root].init();   }   int GetId(char ch) {     switch (ch) {       case  A :         return 0;       case  G :         return 1;       case  C :         return 2;       case  T :         return 3;     }   }   void TrieIns(char *s) {     int i = 0;     int p = root;     while (s[i]) {       int idx = GetId(s[i]);       if (T[p].next[idx] == -1) {         T[Top].init();         T[p].next[idx] = Top++;       }       p = T[p].next[idx];       i++;     }     T[p].danger = strlen(s);   }   void Build_AC_Automation() {     int cur, tmp;     queue<int> q;     T[root].fail = root;     T[root].danger = 0;     q.push(root);     while (!q.empty()) {       cur = q.front();       q.pop();       for (int i = 0; i < MAXK; ++i) {         if (T[cur].next[i] != -1) {           tmp = T[cur].next[i];           if (cur == root)             T[tmp].fail = root;           else {             T[tmp].fail = T[T[cur].fail].next[i];             T[tmp].danger = max(T[tmp].danger, T[T[tmp].fail].danger);           }           q.push(tmp);         } else {           if (cur == root)             T[cur].next[i] = root;           else             T[cur].next[i] = T[T[cur].fail].next[i];         }       }     }   }   long long dp[1010][128][11];   int n, m;   int main() {     memset(dp, 0, sizeof(dp));     cin >> n >> m;     Init();     for (int i = 0; i < m; ++i) {       char str[20];       cin >> str;       TrieIns(str);     }     Build_AC_Automation();     dp[0][0][0] = 1;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < Top; ++j) {         for (int k = 0; k <= 10; ++k) {           if (dp[i][j][k] == 0) continue;           for (int t = 0; t < MAXK; ++t) {             int aa = T[j].next[t];             if (T[aa].danger > k) {               dp[i + 1][aa][0] += dp[i][j][k];               dp[i + 1][aa][0] %= MOD;             } else if (k + 1 <= 10) {               dp[i + 1][aa][k + 1] += dp[i][j][k];               dp[i + 1][aa][k + 1] %= MOD;             }           }         }       }     }     long long ans = 0;     for (int i = 0; i < Top; ++i) {       ans = ans + dp[n][i][0];       ans %= MOD;     }     cout << ans % MOD << endl;   }
#include <bits/stdc++.h>   using namespace std;   int digit(int n) {     int counter = 0;     while (n != 0) {       counter++;       n /= 10;     }     return counter;   }   int main() {     int T;     cin >> T;     for (int i = 0; i < T; i++) {       int n;       cin >> n;       if (n == 1) {         cout << -1 <<   n ;       } else {         cout << 5;         for (int j = 0; j < n - 1; j++) {           cout << 7;         }         cout <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   void base() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);   }   int32_t main() {     base();     int n, num;     cin >> n >> num;     int turn = 1;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (turn == j) {           cout << num <<    ;         } else {           cout << 0 <<    ;         }       }       cout << endl;       turn++;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct edge {     int v, id;     edge *next;   } * h[233333], pool[555555];   int top;   inline void addedge(int u, int v, int id) {     edge *tmp = &pool[top++];     tmp->v = v;     tmp->id = id;     tmp->next = h[u];     h[u] = tmp;     edge *pmt = &pool[top++];     pmt->v = u;     pmt->id = -id;     pmt->next = h[v];     h[v] = pmt;   }   int n, m;   int s[233333], f[233333], vis[233333], pa[233333];   void dfs(int u) {     vis[u] = 1;     for (edge *tmp = h[u]; tmp; tmp = tmp->next) {       if (tmp->v != pa[u] && !vis[tmp->v]) {         pa[tmp->v] = u;         dfs(tmp->v);         if (s[tmp->v]) {           if (tmp->id > 0)             f[tmp->id] += s[tmp->v];           else             f[-tmp->id] -= s[tmp->v];           s[u] += s[tmp->v];         }       }     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &s[i]);     scanf( %d , &m);     int u, v;     for (int i = 1; i <= m; i++) {       scanf( %d%d , &u, &v);       addedge(u, v, i);     }     for (int i = 1; i <= n; i++) {       if (!vis[i]) {         dfs(i);         if (s[i] != 0) {           printf( Impossible n );           return 0;         }       }     }     printf( Possible n );     for (int i = 1; i <= m; i++) printf( %d n , f[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, m, count = 0;     cin >> n >> m;     long long a[m];     for (long long i = 0; i < m; i++) {       cin >> a[i];       for (long long j = 0; j < i; j++) {         if (a[j] < a[i]) count++;       }     }     cout << count <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   const int N = 100001;   using namespace std;   long long a[N], sum[N];   int main() {     int n;     while (scanf( %d , &n) == 1) {       for (int i = 1; i <= n; i++) scanf( %I64d , &a[i]);       for (int i = 1, j; i < n; i++) {         for (j = 0; (1 << j) + i <= n; j++)           ;         j--;         a[i + (1 << j)] += a[i];       }       long long ans = 0;       for (int i = 1; i < n; i++) {         ans += a[i];         printf( %I64d n , ans);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int main() {     scanf( %d%d , &n, &m);     if (n == 1 && m == 2) {       printf( 0 n1 1 n1 2 n1 1 n );       return 0;     }     if (n == 2 && m == 1) {       printf( 0 n1 1 n2 1 n1 1 n );       return 0;     }     if (n * m % 2 == 1 || n == 1 || m == 1) {       printf( %d n%d %d %d %d n , 1, n, m, 1, 1);       for (int i = 1; i <= n; ++i) {         if (i % 2 == 1) {           for (int j = 1; j <= m; ++j) printf( %d %d n , i, j);         } else {           for (int j = m; j > 0; --j) printf( %d %d n , i, j);         }       }       printf( %d %d n , 1, 1);     } else if (n % 2 == 0) {       printf( 0 n1 1 n );       for (int i = 1; i <= n; ++i) {         if (i % 2 == 1) {           for (int j = 2; j <= m; ++j) printf( %d %d n , i, j);         } else {           for (int j = m; j > 1; --j) printf( %d %d n , i, j);         }       }       for (int i = n; i > 0; --i) printf( %d %d n , i, 1);     } else {       printf( 0 n1 1 n );       for (int j = 1; j <= m; ++j) {         if (j % 2 == 1) {           for (int i = 2; i <= n; ++i) printf( %d %d n , i, j);         } else {           for (int i = n; i > 1; --i) printf( %d %d n , i, j);         }       }       for (int j = m; j > 0; --j) printf( %d %d n , 1, j);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool b[123][123];   int arr[123][123];   int k[123];   int z[123];   int main() {     cin.tie(0);     ios_base::sync_with_stdio(0);     bool valid = 0, flag = 0;     pair<int, int> ans1, ans2;     int n;     cin >> n;     string s, t;     cin >> s >> t;     for (int i = 0; i < s.size(); i++) {       if (s[i] != t[i]) {         if (b[t[i] -  a ][s[i] -  a ]) {           ans2 = make_pair(arr[t[i] -  a ][s[i] -  a ] + 1, i + 1);           flag = 1;           break;         }         if (!valid) {           if (z[t[i] -  a ] == 1) {             ans1 = make_pair(k[t[i] -  a ] + 1, i + 1);             valid = 1;           } else if (z[s[i] -  a ] == 2) {             ans1 = make_pair(k[s[i] -  a ] + 1, i + 1);             valid = 1;           }         }         z[s[i] -  a ] = 1;         z[t[i] -  a ] = 2;         k[s[i] -  a ] = i;         k[t[i] -  a ] = i;         b[s[i] -  a ][t[i] -  a ] = 1;         arr[s[i] -  a ][t[i] -  a ] = i;       }     }     int h = 0;     for (int i = 0; i < s.size(); i++) {       if (s[i] != t[i]) h++;     }     if (flag) {       cout << h - 2 << endl;       cout << ans2.first <<     << ans2.second << endl;     } else if (valid) {       cout << h - 1 << endl;       cout << ans1.first <<     << ans1.second << endl;     } else {       cout << h << endl;       cout <<  -1             <<                <<  -1  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m;   long long a[100];   long long ans = 1e18;   long long po[100];   map<long long, long long> ma;   long long fun(long long left1) {     long long ans1 = 1e18;     if (left1 <= 0) {       return 0;     }     for (long long i = 0; i < n; i++) {       long long left = left1;       long long temp = 0;       if (po[i] >= left)         left = 0, temp = a[i];       else if (left % po[i] == 0) {         temp = left / po[i];         temp *= a[i];         left = 0;       } else {         temp = left / po[i];         temp *= a[i];         left = left % po[i];       }       if (ma[left] != 0)         ans1 = min(ans1, temp + ma[left]);       else {         ma[left] = fun(left);         ans1 = min(ans1, temp + ma[left]);       }     }     return ans1;   }   int main() {     cin >> n >> m;     for (long long i = 0; i < n; i++) cin >> a[i];     po[0] = 1;     for (long long i = 1; i <= 30; i++) {       po[i] = po[i - 1] * 2;     }     for (long long i = 0; i < n; i++) {       long long left = m;       long long temp;       if (po[i] >= left)         left = 0, temp = a[i];       else if (left % po[i] == 0) {         temp = left / po[i];         temp *= a[i];         left = 0;       } else {         temp = left / po[i];         temp *= a[i];         left = left % po[i];       }       ans = min(ans, temp + fun(left));     }     cout << ans;     return 0;   }