malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, r, i;     cin >> n >> m;     r = m % ((n * (n + 1) / 2));     for (i = 0; i < n; i++) {       if (i + 1 > r) {         cout << r;         break;       } else         r -= i + 1;     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse4 )   using namespace std;   const int dx[8] = {1, 1, 1, 0, 0, -1, -1, -1};   const int dy[8] = {1, -1, 0, 1, -1, -1, 1, 0};   template <class T>   T gcd(T a, T b) {     return ((b == 0) ? a : gcd(b, a % b));   }   int n, m;   vector<string> s;   vector<string> g;   vector<vector<int> > dist, dist1;   bool valid(int i, int j) { return (min(i, j) >= 0 && i < n && j < m); }   bool check(int t) {     queue<pair<int, int> > q;     for (int i = 0; i < (int)(n); i++)       for (int j = 0; j < (int)(m); j++) {         g[i][j] =  . ;         dist1[i][j] = 0;         if (dist[i][j] > t) {           g[i][j] =  X ;           dist1[i][j] = t + 1;           q.push(make_pair(i, j));         }       }     while (!q.empty()) {       pair<int, int> cur = q.front();       q.pop();       for (int i = 0; i < (int)(8); i++) {         int x = cur.first + dx[i], y = cur.second + dy[i];         if (valid(x, y) && dist1[x][y] < (dist1[cur.first][cur.second] - 1)) {           dist1[x][y] = dist1[cur.first][cur.second] - 1;           q.push(make_pair(x, y));         }       }     }     for (int i = 0; i < (int)(n); i++)       for (int j = 0; j < (int)(m); j++) {         if (s[i][j] ==  . ) {           if (dist1[i][j] > 0) return 0;         } else if (dist1[i][j] <= 0)           return 0;       }     return 1;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     s.resize(n);     for (int i = 0; i < (int)(n); i++) cin >> s[i];     string a =   ;     for (int j = 0; j < (int)(m); j++) a +=  . ;     g.resize(n);     for (int i = 0; i < (int)(n); i++) g[i] = a;     dist.resize(n);     dist1.resize(n);     vector<int> b(m, 0);     for (int i = 0; i < (int)(n); i++) dist[i] = dist1[i] = b;     queue<pair<int, int> > q;     for (int i = 0; i < (int)(n); i++)       for (int j = 0; j < (int)(m); j++) {         if (s[i][j] ==  . ) {           dist[i][j] = 0;           q.push(make_pair(i, j));         } else           dist[i][j] = 1e9;       }     while (!q.empty()) {       pair<int, int> cur = q.front();       q.pop();       for (int i = 0; i < (int)(8); i++) {         int x = cur.first + dx[i], y = cur.second + dy[i];         if (valid(x, y) && dist[x][y] == 1e9) {           dist[x][y] = dist[cur.first][cur.second] + 1;           q.push(make_pair(x, y));         }       }     }     for (int i = 0; i < (int)(n); i++)       for (int j = 0; j < (int)(m); j++) {         dist[i][j] = min({dist[i][j], i + 1, j + 1, (n - i), (m - j)});       }     int l = 0, r = min(n, m) + 1;     while (l < r) {       int mid = (l + r + 1) / 2;       if (check(mid))         l = mid;       else         r = mid - 1;     }     cout << l << endl;     assert(check(l));     for (int i = 0; i < (int)(n); i++) cout << g[i] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int inf = pow(10, 9);   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int n;     cin >> n;     vector<pair<long long int, string>> v(n);     for (long long int i = 0; i < n; ++i) cin >> v[i].first >> v[i].second;     map<string, long long int> ma;     for (long long int i = 0; i < n; ++i) {       sort(v[i].second.begin(), v[i].second.end());       if (ma.find(v[i].second) == ma.end())         ma[v[i].second] = v[i].first;       else         ma[v[i].second] = min(ma[v[i].second], v[i].first);     }     vector<long long int> a;     if (ma.find( A ) != ma.end() and ma.find( B ) != ma.end() and         ma.find( C ) != ma.end())       a.push_back(ma[ A ] + ma[ B ] + ma[ C ]);     if (ma.find( A ) != ma.end() and ma.find( BC ) != ma.end())       a.push_back(ma[ A ] + ma[ BC ]);     if (ma.find( B ) != ma.end() and ma.find( AC ) != ma.end())       a.push_back(ma[ B ] + ma[ AC ]);     if (ma.find( C ) != ma.end() and ma.find( AB ) != ma.end())       a.push_back(ma[ C ] + ma[ AB ]);     if (ma.find( AB ) != ma.end() and ma.find( BC ) != ma.end())       a.push_back(ma[ AB ] + ma[ BC ]);     if (ma.find( AB ) != ma.end() and ma.find( AC ) != ma.end())       a.push_back(ma[ AB ] + ma[ AC ]);     if (ma.find( AC ) != ma.end() and ma.find( BC ) != ma.end())       a.push_back(ma[ AC ] + ma[ BC ]);     if (ma.find( ABC ) != ma.end()) a.push_back(ma[ ABC ]);     if (a.size() == 0)       cout << -1;     else       cout << *min_element(a.begin(), a.end());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s, t;   int dp[1005][1005];   int solve(int i, int j) {     if (i == s.size()) return t.size() - j;     if (j == t.size()) return s.size() - i;     if (dp[i][j] != -1) return dp[i][j];     if (s[i] == t[j]) return solve(i + 1, j + 1);     int c1 = solve(i + 1, j + 1) + 1;     int c2 = solve(i, j + 1) + 1;     int c3 = solve(i + 1, j) + 1;     return dp[i][j] = (min(c1, min(c2, c3)));   }   int shft1 = 0;   void print(int i, int j) {     if (i == s.size()) {       for (int xx = j; xx < t.size(); xx++) {         cout <<  INSERT   << 1 + xx <<     << t[xx] << endl;       }       return;     }     if (j == t.size()) {       for (int xx = 0; xx < s.size() - i; xx++) {         cout <<  DELETE   << j + 1 << endl;       }       return;     }     int c = -2;     if (s[i] == t[j]) {       return print(i + 1, j + 1);     }     int c1 = solve(i + 1, j + 1) + 1;     int c2 = solve(i, j + 1) + 1;     int c3 = solve(i + 1, j) + 1;     int optimal = solve(i, j);     if (optimal == c1) {       cout <<  REPLACE   << j + 1 <<     << t[j] << endl;       print(i + 1, j + 1);     } else if (optimal == c2) {       cout <<  INSERT   << j + 1 <<     << t[j] << endl;       shft1++;       print(i, j + 1);     } else if (optimal == c3) {       cout <<  DELETE   << j + 1 <<     << endl;       shft1--;       print(i + 1, j);     }   }   int main() {     cin >> s >> t;     memset(dp, -1, sizeof dp);     cout << solve(0, 0) << endl;     print(0, 0);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int a, b, c, d, e, f;     cin >> a >> b >> c >> d >> e >> f;     int suit1 = min(a, d);     int suit2 = min(b, min(c, d));     long long cost = 0;     for (int i = 0; i <= suit1; i++) {       long long temp = i * e;       temp += min(b, min(c, d - i)) * f;       cost = max(cost, temp);     }     for (int i = 0; i <= suit2; i++) {       long long temp = i * f;       temp += min(a, d - i) * e;       cost = max(cost, temp);     }     cout << cost << endl;   }   int main() {     int q = 1;     while (q--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int BITS = 20;   template <typename T>   struct xor_basis {     T basis[BITS];     int n = 0;     T min_value(T start = 0) const {       for (int i = 0; i < n; i++) start = min(start, start ^ basis[i]);       return start;     }     T max_value(T start = 0) const {       for (int i = 0; i < n; i++) start = max(start, start ^ basis[i]);       return start;     }     bool add(T x) {       if (n == BITS) return false;       x = min_value(x);       if (x == 0) return false;       basis[n++] = x;       for (int k = n - 1; k > 0 && basis[k] > basis[k - 1]; k--)         swap(basis[k], basis[k - 1]);       return true;     }     void merge(const xor_basis<T> &other) {       for (int i = 0; i < other.n && n < BITS; i++) add(other.basis[i]);     }   };   struct segment {     xor_basis<int> basis;     int get_max() const { return basis.max_value(); }     void join(const segment &other) { basis.merge(other.basis); }     void join(const segment &a, const segment &b) {       *this = a;       join(b);     }   };   struct basic_seg_tree {     int tree_n = 0;     vector<segment> tree;     basic_seg_tree(int n = 0) {       if (n > 0) init(n);     }     void init(int n) {       tree_n = n;       tree.assign(2 * tree_n, segment());     }     void build(const vector<segment> &initial) {       int n = initial.size();       assert(n <= tree_n);       for (int i = 0; i < n; i++) tree[tree_n + i] = initial[i];       for (int position = tree_n - 1; position > 0; position--)         tree[position].join(tree[2 * position], tree[2 * position + 1]);     }     segment query(int a, int b) {       segment answer;       for (a += tree_n, b += tree_n; a < b; a /= 2, b /= 2) {         if (a & 1) answer.join(tree[a++]);         if (b & 1) answer.join(tree[--b]);       }       return answer;     }   };   int N, Q;   int main() {     scanf( %d , &N);     vector<segment> initial;     for (int i = 0; i < N; i++) {       int burger;       scanf( %d , &burger);       initial.emplace_back();       initial.back().basis.add(burger);     }     basic_seg_tree tree(N);     tree.build(initial);     scanf( %d , &Q);     for (int q = 0; q < Q; q++) {       int L, R;       scanf( %d %d , &L, &R);       L--;       printf( %d n , tree.query(L, R).get_max());     }   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T bigmod(T p, T e, T M) {     T ret = 1;     for (; e > 0; e >>= 1) {       if (e & 1) ret = (ret * p) % M;       p = (p * p) % M;     }     return (T)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);   }   template <class T, class X>   inline bool getbit(T a, X i) {     T t = 1;     return ((a & (t << i)) > 0);   }   template <class T, class X>   inline T setbit(T a, X i) {     T t = 1;     return (a | (t << i));   }   template <class T, class X>   inline T resetbit(T a, X i) {     T t = 1;     return (a & (~(t << i)));   }   int n, m;   pair<int, int> arr[100009];   int ob[200009];   pair<pair<int, int>, int> trans[100009];   int cnt[100009];   void solve() {     memset(ob, 0, sizeof(ob));     sort(trans + 1, trans + m + 1);     for (int i = (1); i <= (m); i++) {       pair<int, int> p = trans[i].first;       int ind = trans[i].second;       if (ob[p.second] != 0) {         cnt[ob[p.second]]++;         cnt[ind]++;       }       ob[p.second] = ind;     }   }   int ans[9];   int main() {     scanf( %d %d , &n, &m);     for (int i = (1); i <= (m); i++)       scanf( %d %d , &arr[i].first, &arr[i].second);     for (int i = (1); i <= (m); i++) {       trans[i].first = arr[i];       trans[i].second = i;     }     solve();     for (int i = (1); i <= (m); i++) {       trans[i].first = make_pair(arr[i].second, arr[i].first);       trans[i].second = i;     }     solve();     for (int i = (1); i <= (m); i++) {       trans[i].first = make_pair(arr[i].second + arr[i].first - 1,                                  arr[i].second - arr[i].first + n);       trans[i].second = i;     }     solve();     for (int i = (1); i <= (m); i++) {       trans[i].first = make_pair(arr[i].second - arr[i].first + n,                                  arr[i].second + arr[i].first - 1);       trans[i].second = i;     }     solve();     for (int i = (1); i <= (m); i++) ans[cnt[i]]++;     for (int i = (0); i <= (8); i++) printf( %d  , ans[i]);     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int knigths[300006];   set<int> s;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL), cout.tie(NULL);     ios::sync_with_stdio(false), cin.tie(0);     int n, m;     cin >> n >> m;     for (int i = 1; i <= n + 1; i++) s.insert(i);     for (int i = 0; i < m; i++) {       int a, b, c;       cin >> a >> b >> c;       set<int>::iterator itl = s.lower_bound(a);       set<int>::iterator itu = s.upper_bound(b);       while (*itl < *itu) {         if (*itl != c) {           knigths[*itl] = c;         }         s.erase(itl);         itl = s.lower_bound(a);         itu = s.upper_bound(b);       }       s.insert(c);     }     for (int i = 1; i <= n; i++) cout << knigths[i] <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       vector<int> v(n);       for (int i = 0; i < (int)n; ++i) cin >> v[i];       sort((v).begin(), (v).end());       for (int i = (int)n - 1; i >= 0; --i) cout << v[i] <<    ;       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s;   map<string, vector<int> > m;   map<string, int> memoria;   string codigo(string s1, string s2) { return s1 +  #  + s2; }   int calculadicot(int la, vector<int> &va, int lb, vector<int> &vb) {     int sol = 1000000000;     for (int ia = 0; ia < int(va.size()); ia++) {       int inf = -1;       int sup = int(vb.size());       while (inf + 1 < sup) {         int med = (inf + sup) / 2;         if (vb[med] <= va[ia])           inf = med;         else           sup = med;       }       if (inf >= 0) sol = min(sol, max(va[ia] + la, vb[inf] + lb) - vb[inf]);       if (sup < int(vb.size()))         sol = min(sol, max(va[ia] + la, vb[sup] + lb) - va[ia]);     }     return sol;   }   int calculafusion(int la, vector<int> &va, int lb, vector<int> &vb) {     int ia = 0;     int ib = 0;     int sol = 1000000000;     while (ia < int(va.size()) and ib < int(vb.size())) {       if (va[ia] < vb[ib]) {         sol = min(sol, max(va[ia] + la, vb[ib] + lb) - va[ia]);         ia++;       } else {         sol = min(sol, max(va[ia] + la, vb[ib] + lb) - vb[ib]);         ib++;       }     }     return sol;   }   int calcula(int la, vector<int> &va, int lb, vector<int> &vb) {     if (int(va.size()) > int(vb.size())) return calcula(lb, vb, la, va);     if (int(va.size()) == 0) return -1;     if (int(va.size()) * 10 > int(va.size()) + int(vb.size()))       return calculafusion(la, va, lb, vb);     return calculadicot(la, va, lb, vb);   }   int main() {     cin >> s;     for (int i = 0; i < int(s.size()); i++)       for (int l = 1; l <= 4; l++) m[s.substr(i, l)].push_back(i);     int q;     cin >> q;     for (int cas = 0; cas < q; cas++) {       string a, b;       cin >> a >> b;       if (a > b) swap(a, b);       string c = codigo(a, b);       if (memoria.count(c))         cout << memoria[c] << endl;       else {         vector<int> &va = m[a];         vector<int> &vb = m[b];         memoria[c] = calcula(int(a.size()), va, int(b.size()), vb);         cout << memoria[c] << endl;       }     }   }
#include <queue>   #include <cstdio>   #include <cstring>   using namespace std;   const int Maxn=200000;   const int Inf=0x3f3f3f3f;   int n,k;   int head[Maxn+5],arrive[Maxn<<1|5],nxt[Maxn<<1|5],tot;   void add_edge(int from,int to){    arrive[++tot]=to;    nxt[tot]=head[from];    head[from]=tot;   }   queue<int> q;   int a[Maxn+5];   int dis[Maxn+5];   void init_bfs(){    memset(dis,0x3f,sizeof dis);    for(int i=1;i<=k;i++){     dis[a[i]]=0;     q.push(a[i]);    }    while(!q.empty()){     int u=q.front();     q.pop();     for(int i=head[u];i;i=nxt[i]){      int v=arrive[i];      if(dis[v]!=Inf){       continue;      }      dis[v]=dis[u]+1;      q.push(v);     }    }   }   int ans[Maxn+5];   bool del[Maxn+5];   int sz[Maxn+5];   int st[Maxn+5],top;   int dep[Maxn+5];   void size_dfs(int u,int fa){    sz[u]=1;    for(int i=head[u];i;i=nxt[i]){     int v=arrive[i];     if(v==fa||del[v]){      continue;     }     size_dfs(v,u);     sz[u]+=sz[v];    }   }   int get_weight(int x){    size_dfs(x,0);    int num=sz[x];    top=0;    st[++top]=x;    int maxn;    int root=x,root_mx=sz[x]-1;    while(top>0){     int u=st[top--];     maxn=num-sz[u];     for(int i=head[u];i;i=nxt[i]){      int v=arrive[i];      if(del[v]||sz[v]>sz[u]){       continue;      }      st[++top]=v;      maxn=max(maxn,sz[v]);     }     if(maxn<root_mx){      root=u;      root_mx=maxn;     }    }    return root;   }   void dep_sz_dfs(int u,int fa){    dep[u]=dep[fa]+1;    sz[u]=1;    for(int i=head[u];i;i=nxt[i]){     int v=arrive[i];     if(del[v]||v==fa){      continue;     }     dep_sz_dfs(v,u);     sz[u]+=sz[v];    }   }   int lis[Maxn+5],len;   int tot_sz;   void lis_dfs(int u,int fa){    if(dis[u]-1-dep[u]>=0){     lis[min(dis[u]-1-dep[u],tot_sz)]=max(lis[min(dis[u]-1-dep[u],tot_sz)],dis[u]);    }    for(int i=head[u];i;i=nxt[i]){     int v=arrive[i];     if(del[v]||v==fa){      continue;     }     lis_dfs(v,u);    }   }   void calc_dfs(int u,int fa){    ans[u]=max(ans[u],lis[dep[u]]);    for(int i=head[u];i;i=nxt[i]){     int v=arrive[i];     if(del[v]||v==fa){      continue;     }     calc_dfs(v,u);    }   }   void calc(int u){    u=get_weight(u);    dep_sz_dfs(u,0);    tot_sz=sz[u];    for(int i=0;i<=sz[u];i++){     lis[i]=-Inf;    }    lis_dfs(u,0);    for(int i=sz[u]-1;i>=0;i--){     lis[i]=max(lis[i],lis[i+1]);    }    calc_dfs(u,0);    del[u]=1;    for(int i=head[u];i;i=nxt[i]){     int v=arrive[i];     if(del[v]){      continue;     }     calc(v);    }   }   int main(){    scanf( %d ,&n);    for(int i=1;i<n;i++){     int u,v;     scanf( %d%d ,&u,&v);     add_edge(u,v);     add_edge(v,u);    }    scanf( %d ,&k);    for(int i=1;i<=k;i++){     scanf( %d ,&a[i]);    }    init_bfs();    dep[0]=-1;    calc(1);    for(int i=1;i<=n;i++){     printf( %d  ,ans[i]);    }    puts(  );    return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000000 + 5;   int vis[N], n, m;   pair<int, int> Get(int x) {     int a, b;     if (x >= n)       a = x - n + 1;     else       a = n - x + 1;     x = m - x + 1;     if (x >= n)       b = m - (x - n + 1) + 1;     else       b = m - (n - x + 1) + 1;     return pair<int, int>(a, b);   }   void dfs(int x) {     pair<int, int> cur = Get(x);     pair<int, int> nxt = Get(cur.first);     if (!vis[nxt.first]) {       vis[nxt.first] = 1;       dfs(nxt.first);     }     if (!vis[nxt.second]) {       vis[nxt.second] = 1;       dfs(nxt.second);     }     nxt = Get(cur.second);     if (!vis[nxt.first]) {       vis[nxt.first] = 1;       dfs(nxt.first);     }     if (!vis[nxt.second]) {       vis[nxt.second] = 1;       dfs(nxt.second);     }   }   int main() {     scanf( %d%d , &n, &m);     if (n > m) swap(n, m);     int ans = 0;     for (int i = 1; i <= m; i++)       if (!vis[i]) {         ans++;         vis[i] = 1;         dfs(i);       }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (a == 0) return b;     if (b == 0) return a;     if (a == b) return a;     if (a > b) return gcd(a - b, b);     return gcd(a, b - a);   }   void sol() {     long long int L, v, l, r, count = 0;     cin >> L >> v >> l >> r;     long long int p = L / v;     long long int q = (r / v) - ((l - 1) / v);     cout << p - q << endl;   }   int main() {     int t;     cin >> t;     while (t--) sol();   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     long long x, y, z;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       long long ans = 0;       scanf( %lld%lld , &x, &y);       if (x >= y) {         ans += y;         printf( %lld n , ans);         continue;       }       long long d = (y - 1) / x + 1;       z = x * d - y;       ans += z * (d - 1) * (d - 1) + (x - z) * d * d;       printf( %lld n , ans);     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200005, P = 1000000007;   int n, l[N], r[N], p[N], p2[N], ans;   int power(int a, int x) {     int ans = 1;     for (; x; x >>= 1, a = 1LL * a * a % P)       if (x & 1) ans = 1LL * ans * a % P;     return ans;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , l + i);     for (int i = 1; i <= n; ++i)       scanf( %d , r + i), p[i] = power(r[i] - l[i] + 1, P - 2);     for (int i = 1; i + 2 <= n; ++i) {       int x = max({l[i], l[i + 1], l[i + 2]}),           y = min({r[i], r[i + 1], r[i + 2]});       if (x <= y)         ans = (ans + 1LL * (y - x + 1) * p[i] % P * p[i + 1] % P * p[i + 2]) % P;     }     int sum = 0;     for (int i = 1; i + 1 <= n; ++i) {       int x = max({l[i], l[i + 1]}), y = min({r[i], r[i + 1]});       if (x <= y)         sum = (sum + (p2[i] = 1LL * (y - x + 1) * p[i] % P * p[i + 1] % P)) % P;     }     ans = 2LL * ans % P;     for (int i = 1; i + 1 <= n; ++i)       ans = (ans + 1LL * p2[i] *                        (0LL + sum - p2[i] - (i == 1 ? 0 : p2[i - 1]) -                         (i == n - 1 ? 0 : p2[i + 1]))) %             P;     ans = (ans + sum) % P;     int res = (1LL * n * n - 2LL * n * sum + ans) % P;     printf( %d n , (res + P) % P);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string s;     cin >> s;     int count = 0, check = 0;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  1 ) {         check = 1;       }       if (check == 1 && s[i] ==  0 ) count++;     }     if (count >= 6)       cout <<  yes ;     else {       cout <<  no ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int value[100005];   int main() {     int n, k, m;     while (cin >> n >> k >> m) {       map<string, int> mymap;       for (int i = 1; i <= n; i++) {         string s;         cin >> s;         mymap[s] = i;       }       for (int i = 1; i <= n; i++) scanf( %d , &value[i]);       for (int i = 1; i <= k; i++) {         int cnt, minv = 1000000000;         int t[100005];         scanf( %d , &cnt);         for (int j = 0; j < cnt; j++) {           scanf( %d , &t[j]);           minv = min(minv, value[t[j]]);         }         for (int j = 0; j < cnt; j++) value[t[j]] = minv;       }       long long ans = 0;       for (int i = 0; i < m; i++) {         string s;         cin >> s;         ans += value[mymap[s]];       }       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     char a[250];     int k;     cin >> a;     cin >> k;     int temp = k;     int curr = 0;     a[strlen(a)] =   0 ;     if (strlen(a) > 1) {       while (temp) {         int max_v = a[curr] - 48, max_p = curr;         for (int j = curr + 1; j <= curr + temp && j < strlen(a); j++) {           if (a[j] - 48 > max_v) {             max_v = a[j] - 48;             max_p = j;           }         }         if (max_p != curr) {           for (int j = max_p; j > curr; j--) {             if (temp) {               swap(a[j], a[j - 1]);               temp--;             } else               break;           }         }         curr++;         if (curr >= strlen(a)) {           break;         }         a[strlen(a)] =   0 ;       }     }     cout << a;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 105;   int n, m;   char g[maxn][maxn];   int vis[3];   map<char, int> mp;   int main() {     mp[ R ] = 0;     mp[ G ] = 1;     mp[ B ] = 2;     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) scanf( %s , g[i]);     bool ok = true;     if (g[0][0] == g[0][m - 1] && n % 3 == 0) {       int w = n / 3;       for (int i = 0; i < n && ok; i++) {         char x = g[i][0];         int but = i + w;         for (; i < but; i++)           for (int j = 0; j < m; j++)             if (g[i][j] != x) ok = false;         int id = mp[x];         if (vis[id]) {           ok = false;           break;         }         vis[id] = 1;         i--;       }     } else if (g[0][0] == g[n - 1][0] && m % 3 == 0) {       int w = m / 3;       for (int j = 0; j < m && ok; j++) {         char x = g[0][j];         int r = j + w;         for (; j < r; j++)           for (int i = 0; i < n; i++)             if (g[i][j] != x) ok = false;         int id = mp[x];         if (vis[id]) {           ok = false;           break;         }         vis[id] = 1;         j--;       }     } else       ok = false;     puts(ok ?  YES  :  NO );     return 0;   }