malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   template <typename _T>   inline void read(_T &f) {     f = 0;     _T fu = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) fu = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       f = (f << 3) + (f << 1) + (c & 15);       c = getchar();     }     f *= fu;   }   template <typename T>   void print(T x) {     if (x < 0) putchar( - ), x = -x;     if (x < 10)       putchar(x + 48);     else       print(x / 10), putchar(x % 10 + 48);   }   template <typename T>   void print(T x, char t) {     print(x);     putchar(t);   }   const int N = 1005;   int a[N][N], ans[N][N], ans2[N][N], b[N];   int n, m;   int main() {     read(n);     read(m);     for (register int i = 1; i <= n; i++) {       for (register int j = 1; j <= m; j++) {         read(a[i][j]);       }     }     for (register int i = 1; i <= n; i++) {       for (register int j = 1; j <= m; j++) b[j] = a[i][j];       sort(b + 1, b + m + 1);       int big = unique(b + 1, b + m + 1) - b - 1;       for (register int j = 1; j <= m; j++) {         int tmp = lower_bound(b + 1, b + big + 1, a[i][j]) - b;         ans[i][j] = max(ans[i][j], tmp);         ans2[i][j] = max(ans2[i][j], big - tmp);       }     }     for (register int j = 1; j <= m; j++) {       for (register int i = 1; i <= n; i++) b[i] = a[i][j];       sort(b + 1, b + n + 1);       int big = unique(b + 1, b + n + 1) - b - 1;       for (register int i = 1; i <= n; i++) {         int tmp = lower_bound(b + 1, b + big + 1, a[i][j]) - b;         ans[i][j] = max(ans[i][j], tmp);         ans2[i][j] = max(ans2[i][j], big - tmp);       }     }     for (register int i = 1; i <= n; i++) {       for (register int j = 1; j <= m; j++) {         print(ans[i][j] + ans2[i][j], j == m ?   n  :    );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct point {     int x, y;     inline bool operator<(const point &a) const { return x < a.x; }   } arr[100005];   struct query_tp {     int col, l, r, delta;     query_tp() {}     query_tp(int _col, int _l, int _r, int _delta) {       col = _col;       l = _l;       r = _r;       delta = _delta;     }     inline bool operator<(const query_tp &a) const { return col < a.col; }   };   long long ans[100005];   int main() {     int n, k;     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) scanf( %d%d , &arr[i].x, &arr[i].y);     sort(arr, arr + n);     vector<query_tp> query;     vector<int> app;     for (int i = 0; i < n; i++) {       int l = arr[i].x - k;       if (app.size()) l = max(l, *app.rbegin());       for (int j = l + 1; j <= arr[i].x; j++) app.push_back(j);       query.push_back(query_tp(arr[i].y - k + 1, arr[i].x - k + 1, arr[i].x, 1));       query.push_back(query_tp(arr[i].y + 1, arr[i].x - k + 1, arr[i].x, -1));     }     sort(query.begin(), query.end());     int cnt = app.size(), q_cnt = query.size();     for (int i = 0; i < q_cnt; i++) {       query[i].l = lower_bound(app.begin(), app.end(), query[i].l) - app.begin();       query[i].r = lower_bound(app.begin(), app.end(), query[i].r) - app.begin();     }     app.clear();     vector<int>().swap(app);     vector<int> lst(cnt, -1e9), num(cnt, 0);     for (int i = 0; i < q_cnt; i++) {       for (int j = query[i].l; j <= query[i].r; j++) {         if (lst[j] != -1e9) ans[num[j]] += query[i].col - lst[j];         num[j] += query[i].delta;         lst[j] = query[i].col;       }     }     for (int i = 1; i <= n; i++) printf( %lld%c , ans[i],    n [i == n]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int lim = 200005;   long long int n;   vector<vector<long long int> > ans;   vector<long long int> ed;   void solve(int test) {     cin >> n;     for (int(i) = 0; (i) < n; (i)++) {       long long int v;       cin >> v;       vector<long long int>::iterator ind =           upper_bound((ed).begin(), (ed).end(), -v);       if (ind == ed.end()) {         ed.push_back(-v);         ans.push_back(vector<long long int>(1, v));       } else {         int x = ind - ed.begin();         ed[x] = -v;         ans[x].push_back(v);       }     }     for (int(i) = 0; (i) < int((ans).size()); (i)++) {       for (int(j) = 0; (j) < int((ans[i]).size()); (j)++) {         cout << ans[i][j] <<    ;       }       cout << endl;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int test = 1;     for (int(i) = 0; (i) < test; (i)++) {       solve(i + 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long nxt(long long x) {     long long mn = 10;     long long mx = 0;     long long xx = x;     while (x > 0) {       mn = min(mn, x % 10);       mx = max(mx, x % 10);       x /= 10;     }     return xx + mn * mx;   }   signed main() {     long long t;     cin >> t;     while (t--) {       long long a1, k;       cin >> a1 >> k;       k--;       while (k--) {         if (a1 == nxt(a1)) break;         a1 = nxt(a1);       }       cout << a1 <<   n ;     }   }
#include <bits/stdc++.h>   const int MAX = 2000010, mod = 1000000007;   int n, m, mp[MAX], c[MAX], d[MAX], ds[MAX];   bool ty[MAX];   void upd(int i, int x) {     x > d[i] ? d[i] = x, ds[i] = 1 : x == d[i] ? ds[i]++ : 0;   }   int main() {     scanf( %d , &n);     for (int p; n--;) scanf( %d , &p), c[p > m ? m = p : p]++;     for (int i = 2; i <= m; i++)       if (!mp[i])         for (int j = i; j <= m; j += i)           if (!mp[j]) mp[j] = i;     int s = 1, t = 0;     for (int i = m; i; i--)       for (int j = c[i]; j--;) {         if (d[i]) {           for (int x = i - 1; x > 1;) {             int p = mp[x], c = 0;             for (; x % p == 0; x /= p) c++;             for (int e = d[p]; e < c; e++) s = 1ll * s * p % mod;             upd(p, c);           }           ty[i] = 1;         } else           upd(i, 1), s = 1ll * s * i % mod;       }     for (int i = m; i; i--)       if (ty[i]) {         bool fl = 1;         for (int x = i - 1; x > 1;) {           int p = mp[x], c = 0;           for (; x % p == 0; x /= p) c++;           if (c == d[p] && ds[p] == 1) fl = 0;         }         if (fl) t = 1;       }     printf( %d n , (s + t) % mod);   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 10e5;   int minc, maxk = 0;   long long int a[maxn], c[maxn];   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cout << setprecision(30);     int n, s;     cin >> n >> s;     for (int i = 0; i < n; i++) cin >> a[i];     int l = 0, r = n + 1;     while (r - l > 1) {       long long int mid = (l + r) / 2, tc = 0;       for (int i = 0; i < n; i++) c[i] = mid * (i + 1) + a[i];       sort(c, c + n);       for (int i = 0; i < mid; i++) tc += c[i];       if (tc > s) {         r = mid;       }       if (tc <= s) {         minc = tc;         maxk = mid;         l = mid;       }     }     cout << maxk <<     << minc;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int NMax = 100005;   vector<int> G[NMax];   long double Array[NMax];   int DP[NMax], N;   void Read() {     cin >> N;     for (int i = 1; i < N; i++) {       int x;       cin >> x;       G[x].push_back(i + 1);     }   }   void buildDP(int node) {     DP[node] = 1;     for (int i = 0; i < G[node].size(); i++) {       int neighb = G[node][i];       buildDP(neighb);       DP[node] += DP[neighb];     }   }   void DFS(int node) {     int sz = G[node].size();     for (int i = 0; i < G[node].size(); i++) {       int neighb = G[node][i];       Array[neighb] =           Array[node] + 0.5 * ((long double)DP[node] - 1.0 - DP[neighb]) + 1.0;       DFS(neighb);     }   }   void Print() {     for (int i = 1; i <= N; i++)       cout << fixed << setprecision(2) << Array[i] <<    ;     cout <<   n ;   }   int main() {     Read();     buildDP(1);     Array[1] = 1.0;     DFS(1);     Print();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void no() {     cout <<  IMPOSSIBLE  << endl;     exit(0);   }   int main() {     cin.sync_with_stdio(false);     int n, m;     cin >> n >> m;     int answer = 0;     int last_day = 0, last_h = 0;     for (int i = 0; i < m; i++) {       int cur, h;       cin >> cur >> h;       if (i == 0) {         answer = h + cur - 1;       } else {         answer = max(answer, h);         int dif = abs(h - last_h);         int days = cur - last_day;         if (dif > days) no();         if (h >= last_h) {           answer = max(answer, h + (days - dif) / 2);         } else {           answer = max(answer, last_h + (days - dif) / 2);         }       }       last_day = cur;       last_h = h;     }     answer = max(answer, last_h + n - last_day);     cout << answer << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   set<pair<long long, long long> > s[17];   long long a[100002];   long long g[100002];   signed main() {     ios ::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long n, m;     cin >> n >> m;     for (long long i = 0; i <= n; i++) g[i] = (i * (i + 1)) / 2LL;     long long ans = 0;     for (long long i = 0; i <= n - 1; i++) cin >> a[i];     for (long long j = 0; j <= 16; j++) {       for (long long i = 0; i <= n - 1; i++) {         if (a[i] & (1LL << j)) {           long long len = 1;           long long st = i;           i++;           while (1) {             if (i == n or !(a[i] & (1LL << j))) {               s[j].insert({st, len});               ans += (g[len] * (1LL << j));               break;             }             len++;             i++;           }         }       }     }     while (m--) {       long long idx, val, pval;       cin >> idx >> val;       idx--;       pval = a[idx];       for (long long j = 0; j <= 16; j++) {         if (val & (1LL << j) and !(pval & (1LL << j))) {           auto it = s[j].lower_bound({idx, 1e9});           if (it == s[j].end() or (*it).first != idx + 1)             s[j].insert({idx, 1}), ans += (1LL << j);           else             ans += (1LL << j) * ((*it).second + 1),                 s[j].insert({idx, (*it).second + 1}), s[j].erase(it);           it = s[j].lower_bound({idx, -1});           if (it != s[j].begin()) {             auto pt = prev(it);             if ((*pt).second + (*pt).first - 1 == idx - 1) {               ans -= (1LL << j) * (g[(*pt).second] + g[(*it).second]),                   ans += (1LL << j) * g[(*it).second + (*pt).second],                   s[j].insert({(*pt).first, (*pt).second + (*it).second}),                   s[j].erase(it), s[j].erase(pt);             }           }         } else if (pval & (1LL << j) and !(val & (1LL << j))) {           auto it = s[j].lower_bound({idx, -1});           if (it != s[j].end() and (*it).first == idx) {             if ((*it).second == 1)               ans -= (1LL << j), s[j].erase({idx, 1});             else               ans -= (1LL << j) * ((*it).second),                   s[j].insert({idx + 1, (*it).second - 1}), s[j].erase(it);           } else {             it = prev(it);             if ((*it).first + (*it).second - 1 == idx)               ans -= (1LL << j) * ((*it).second),                   s[j].insert({(*it).first, (*it).second - 1}), s[j].erase(it);             else {               ans -= (1LL << j) * g[(*it).second],                   ans += (1LL << j) * g[idx - 1 - (*it).first + 1],                   ans +=                   (1LL << j) * g[(*it).first + (*it).second - 1 - idx - 1 + 1];               s[j].insert({(*it).first, idx - 1 - (*it).first + 1}),                   s[j].insert(                       {idx + 1, (*it).first + (*it).second - 1 - idx - 1 + 1}),                   s[j].erase(it);             }           }         }       }       a[idx] = val;       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   long long aa[33];   long long a[33], b[33], k[33], p[33];   long long n, u, r;   long long ans = -1e10;   void dfs(long long d, long long pre) {     if ((u - d) % 2 == 0) {       long long t = 0;       for (int i = 1; i <= n; i++) t = t + a[i] * k[i];       ans = max(ans, t);     }     if (d == u) return;     long long tmp[33];     for (int i = 1; i <= n; i++) tmp[i] = a[i];     for (int i = 1; i <= n; i++) aa[i] = a[i];     if (pre != 1) {       for (int i = 1; i <= n; i++) a[i] = a[i] ^ b[i];       dfs(d + 1, 1);       for (int i = 1; i <= n; i++) a[i] = tmp[i];     }     for (int i = 1; i <= n; i++) aa[i] = a[p[i]] + r;     for (int i = 1; i <= n; i++) a[i] = aa[i];     dfs(d + 1, -1);     for (int i = 1; i <= n; i++) a[i] = tmp[i];   }   int main() {     cin >> n >> u >> r;     for (int i = 1; i <= n; i++) scanf( %I64d , &a[i]);     for (int i = 1; i <= n; i++) scanf( %I64d , &b[i]);     for (int i = 1; i <= n; i++) scanf( %I64d , &k[i]);     for (int i = 1; i <= n; i++) scanf( %I64d , &p[i]);     dfs(0, -1);     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> e[300020];   int f[300020][3];   inline int Mod(int x) { return x + ((x >> 31) & 998244353); }   void DFS(int x, int p) {     int i, v;     f[x][0] = 1;     f[x][1] = 1;     f[x][2] = 1;     for (i = 0; i < (signed)e[x].size(); i++)       if ((v = e[x][i]) != p) {         DFS(v, x);         f[x][0] =             (long long)f[x][0] *             Mod(f[v][1] + 2 * Mod(f[v][0] + f[v][2] - 998244353) % 998244353 -                 998244353) %             998244353;         f[x][1] =             (long long)f[x][1] * Mod(f[v][0] + f[v][2] - 998244353) % 998244353;         f[x][2] = (long long)f[x][2] *                   Mod(2 * f[v][0] % 998244353 + f[v][2] - 998244353) % 998244353;       }     f[x][2] = Mod(f[x][2] - f[x][1]);     return;   }   int main(void) {     int n, u, v;     int i;     scanf( %d , &n);     for (i = 1; i < n; i++) {       scanf( %d %d , &u, &v);       e[--u].push_back(--v);       e[v].push_back(u);     }     DFS(0, 0);     printf( %d n , Mod(Mod(f[0][0] + f[0][2] - 998244353) - 1));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     int a[n];     map<int, int> mp;     for (int i = 0; i < n; i++) {       cin >> a[i];       mp[a[i]]++;     }     long long ans = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < 32; j++) {         int p = 1 << j;         if (p < a[i]) {           continue;         }         ans += mp[p - a[i]];         if (a[i] == p - a[i]) {           ans--;         }       }     }     ans /= 2;     cout << ans;     return 0;   }
#include <bits/stdc++.h>   int main() {     int n, m;     scanf( %d %d , &n, &m);     int msg1[n];     int msg2[m];     for (int i = 0; i < n; i++) {       scanf( %d , &msg1[i]);     }     for (int i = 0; i < m; i++) {       scanf( %d , &msg2[i]);     }     for (int i = 1; i < n; i++) {       msg1[i] = msg1[i] + msg1[i - 1];     }     for (int i = 1; i < m; i++) {       msg2[i] = msg2[i] + msg2[i - 1];     }     int count = 0;     int i = 0, j = 0;     while (i < n && j < m) {       if (msg1[i] < msg2[j])         i++;       else if (msg1[i] > msg2[j])         j++;       else {         i++;         j++;         count++;       }     }     printf( %d , count);   }
#include <bits/stdc++.h>   using namespace std;   const double pi = 3.141592653589793238462;   int n, m, r, w[70][70][70], d[70][70][2000], a, b, c;   const int inf = 2000000000;   void deb(int q) {     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) printf( %d  , d[i][j][q]);       printf(  n );     }     printf(  n );   }   int main() {     scanf( %d%d%d , &n, &m, &r);     for (int i = 1; i <= m; i++)       for (int j = 1; j <= n; j++)         for (int k = 1; k <= n; k++) scanf( %d , &w[j][k][i]);     for (int t = 1; t <= m; t++)       for (int k = 1; k <= n; k++)         for (int i = 1; i <= n; i++)           for (int j = 1; j <= n; j++)             w[i][j][t] = min(w[i][j][t], w[i][k][t] + w[k][j][t]);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) {         d[i][j][0] = inf;         for (int t = 1; t <= m; t++) d[i][j][0] = min(d[i][j][0], w[i][j][t]);       }     for (int i = 1; i <= 1000; i++)       for (int j = 1; j <= n; j++)         for (int k = 1; k <= n; k++) {           d[j][k][i] = inf;           for (int q = 1; q <= n; q++)             d[j][k][i] = min(d[j][k][i], d[j][q][i - 1] + d[q][k][0]);         }     for (int i = 1; i <= r; i++) {       scanf( %d%d%d , &a, &b, &c);       printf( %d n , d[a][b][c]);     }     return 0;   }
#include<bits/stdc++.h>      using namespace std;      const int N = 2000 + 10;      int n;   bool flag[N];      bool Query(int l1, int r1, int l2, int r2) {    printf( ? %d %d n , r1 - l1 + 1, r2 - l2 + 1);    for (int i = l1; i <= r1; i++) printf( %d%c , i,    n [i == r1]);    for (int i = l2; i <= r2; i++) printf( %d%c , i,    n [i == r2]);    fflush(stdout);    int res; scanf( %d , &res);    return res;   }      void Solve() {    scanf( %d , &n);    for (int i = 1; i <= n; i++) flag[i] = 0;    for (int i = 2; i <= n; i++) {     if (Query(1, i - 1, i, i)) {      // printf( i = %d n , i);      flag[i] = 1;      for (int j = i + 1; j <= n; j++) {       if (Query(i, i, j, j)) {        flag[j] = 1;       }      }      int L = 1, R = i - 1, ans = 0;      while (L <= R) {       // printf( L = %d, R = %d n , L, R);       int M = (L + R) >> 1;       if (Query(1, M, i, i)) R = M - 1, ans = M;       else L = M + 1;      }      // printf( ans = %d n , ans);      flag[ans] = 1;      break;     }    }    // puts( ans );    // for (int i = 1; i <= n; i++) {       // }    vector <int> ans;    for (int i = 1; i <= n; i++) {     if (!flag[i]) {      ans.push_back(i);     }    }    printf( ! %d n , ans.size());    for (auto x : ans) {     printf( %d  , x);    } puts(  );    fflush(stdout);   }      int main(){       srand(time(0));   #ifndef ONLINE_JUDGE       // freopen( data.in ,  r , stdin);       // freopen( tst.out ,  w , stdout);       clock_t st = clock();   #endif       int T = 1;    scanf( %d , &T);       while (T--) {     Solve();       }   #ifndef ONLINE_JUDGE       clock_t ed = clock();       printf( time : %.6lfs n , 1.0 * (ed - st) / CLOCKS_PER_SEC);   #endif       return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long mod = 1000000007;   int m = 0;   int block[5005];   long long f[5005];   int main() {     int n, tmp;     int num_of_for = 0;     cin >> n;     tmp = n;     while (tmp--) {       char c;       cin >> c;       if (c ==  s ) {         block[m] = num_of_for;         num_of_for = 0;         m++;       } else {         num_of_for++;       }     }     for (int k = 0; k < n; k++) {       f[k] = 1;     }     for (int i = m - 1; i >= 0; i--) {       f[0] = f[block[i]];       for (int k = 1; k < n; k++) {         if (block[i] + k < n) {           f[k] = f[k - 1] + f[block[i] + k];         } else {           f[k] = f[k - 1];         }         f[k] %= mod;       }     }     cout << (f[0] + mod) % mod;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000007LL;   long long N;   vector<long long> E[100000];   long long dp[100000][2];   long long ans = 0;   long long mod_inv(long long n) {     long long t = MOD - 2, p = 1, q = n;     while (t > 0) {       if (t % 2 == 1) p = (p * q) % MOD;       q = (q * q) % MOD;       t /= 2;     }     return p % MOD;   }   void dfs(long long v, long long p) {     bool leaf = true;     for (long long u : E[v])       if (u != p) {         dfs(u, v);         leaf = false;       }     if (leaf) {       dp[v][0] = 1;       dp[v][1] = 1;     } else {       long long ev = 1, od = 1;       for (long long u : E[v])         if (u != p) {           (ev *= dp[u][0]) %= MOD;           (od *= dp[u][1]) %= MOD;         }       dp[v][0] = (ev + od) % MOD;       dp[v][1] = (od + ev) % MOD;     }   }   void dfs2(long long v, long long p, long long ev, long long od) {     long long _ev = 1, _od = 1;     for (long long u : E[v])       if (u != p) {         (_ev *= dp[u][0]) %= MOD;         (_od *= dp[u][1]) %= MOD;       }     if (p != -1) {       long long d = _ev * ev % MOD + _od * od % MOD;       ans += d;       ans %= MOD;     } else {       ans += dp[v][0];       ans %= MOD;     }     long long cnt = 0;     for (long long u : E[v])       if (u != p) {         cnt++;       }     for (long long u : E[v])       if (u != p) {         long long nev, nod, s;         if (cnt == 1) {           s = ev + od;           nev = s;           nod = s;         } else if (p == -1) {           s = _ev * mod_inv(dp[u][0]) % MOD + _od * mod_inv(dp[u][1]) % MOD;           nev = s;           nod = s;         } else {           s = _ev * mod_inv(dp[u][0]) % MOD * ev % MOD +               _od * mod_inv(dp[u][1]) % MOD * od % MOD;           nev = s;           nod = s;         }         nev %= MOD;         nod %= MOD;         dfs2(u, v, nev, nod);       }   }   int main(void) {     cin >> N;     for (long long i = ((long long)0); i < ((long long)N - 1); i++) {       long long A, B;       cin >> A >> B;       A--;       B--;       E[A].push_back(B);       E[B].push_back(A);     }     dfs(0, -1);     dfs2(0, -1, 1, 0);     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long int Lpow(long long int a, long long int b) {     long long int ans = 1;     while (b > 0) {       if (b % 2) ans = (ans * a);       a = (a * a);       b = b / 2;     }     return ans;   }   long long int Lpow(long long int a, long long int b, long long int M) {     long long int ans = 1;     while (b > 0) {       if (b % 2) ans = (ans * a) % M;       a = (a * a) % M;       b = b / 2;     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     int n;     cin >> n;     vector<int> brr;     int f1 = 0;     int f2 = 0;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       int sum = 0;       int y;       int sum2 = 0;       for (int j = 0; j < x; j++) {         cin >> y;         if (j > ((x - 1) / 2)) sum += y;         if (j < (x / 2)) sum2 += y;         if (x % 2 == 1 && j == x / 2) brr.push_back(y);       }       f1 += sum2;       f2 += sum;     }     sort(brr.begin(), brr.end());     reverse(brr.begin(), brr.end());     for (int i = 0; i < brr.size(); i += 2) f1 += brr[i];     for (int i = 1; i < brr.size(); i -= -2) f2 += brr[i];     cout << f1 <<     << f2 <<   n ;     return 0;   }
#include <bits/stdc++.h>   const int MAX_N = 102;   using namespace std;   string s;   int dp[52][11];   long long numberOfways(int i, int digit) {     if (i == s.length()) return 1;     if (dp[i][digit] != -1) return dp[i][digit];     dp[i][digit] = 0;     int curDigit = s[i] -  0 ;     int newDigit = curDigit + digit;     if (newDigit % 2) {       return dp[i][digit] += numberOfways(i + 1, newDigit / 2) +                              numberOfways(i + 1, newDigit / 2 + 1);     } else {       return dp[i][digit] += numberOfways(i + 1, newDigit / 2);     }   }   int main() {     {       ios_base::sync_with_stdio(false);       cin.tie(NULL);     };     memset(dp, -1, sizeof(dp));     cin >> s;     long long ans = 0;     for (int i = 0; i <= 9; i++) {       ans += numberOfways(1, i);     }     bool ownNumber = true;     for (int i = 0; i < s.length() - 1; i++) {       int digit = abs(s[i] - s[i + 1]);       if (digit > 1) {         ownNumber = false;         break;       }     }     if (ownNumber) ans--;     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     vector<int> w(n);     for (int i = 0; i < n; i++) cin >> w[i];     int x = 0;     vector<int> ord(n);     vector<int> rd(m);     vector<bool> put(n, false);     for (int i = 0; i < m; i++) {       cin >> rd[i];       rd[i]--;       if (put[rd[i]])         continue;       else {         ord[x] = rd[i];         put[rd[i]] = true;         x++;       }     }     for (int i = 0; i < n; i++) {       if (!put[i]) {         ord[x] = i;         x++;       }     }     int lift = 0;     for (int i = 0; i < m; i++) {       int in = 0;       for (int j = 0; j < n; j++) {         if (ord[j] == rd[i]) {           in = j;         }       }       for (int j = in; j > 0; j--) {         ord[j] = ord[j - 1];         lift += w[ord[j]];       }       ord[0] = rd[i];     }     cout << lift << endl;   }