malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> len(n);     vector<string> s(n);     for (int i = 0; i < n; i++) {       cin >> s[i];       len[i] = s[i].length();     }     const int all = n - 1 + accumulate(len.begin(), len.end(), 0);     vector<vector<bool>> eq(n, vector<bool>(n, false));     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (s[i] == s[j]) eq[i][j] = true;       }     }     vector<vector<int>> dp(n, vector<int>(n, 0));     for (int i = n - 1; i >= 0; i--) {       for (int j = n - 1; j >= 0; j--)         if (eq[i][j]) {           if (i + 1 < n and j + 1 < n)             dp[i][j] = dp[i + 1][j + 1] + 1;           else             dp[i][j] = 1;         }     }     int ans = all;     for (int i = 0; i < n; i++) {       int sum = 0;       for (int d = 0; i + d < n; d++) {         int cnt = 1;         sum += len[i + d];         for (int pos = i + d + 1; pos < n; pos++) {           if (dp[i][pos] > d) {             cnt++;             pos += d;           }         }         int res = all - sum * cnt + cnt;         if (cnt > 1 and ans > res) ans = res;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10, N = 2000;   long long m, n, shroo, I[maxn], tmm, id[maxn], J[maxn], W[maxn], Su[maxn],       dp1[maxn], dp2[maxn];   vector<pair<long long, long long> > hel1;   vector<int> tmp, in[maxn], out[maxn];   bool amx(int i, int j) { return id[I[i]] > id[I[j]]; }   void dfs_1(int i) {     id[i] = 1;     for (auto A : out[i])       if (!id[A]) dfs_1(A);     tmp.push_back(i);   }   void dfs_2(int i) {     id[i] = tmm;     for (auto A : in[i])       if (!id[A]) dfs_2(A);   }   void scc() {     for (int y = 1; y <= n; y++)       if (!id[y]) dfs_1(y);     memset(id, 0, sizeof id);     reverse(tmp.begin(), tmp.end());     for (auto A : tmp)       if (!id[A]) tmm++, dfs_2(A);   }   long long gett(long long x) {     int st = 0, en = 2e4 + 5, md, i;     while (st <= en) {       md = st + ((en - st) >> 1);       if (2 * x >= md * (md + 1))         st = md + 1, i = md;       else         en = md - 1;     }     return (i + 1) * x - 1LL * i * (i + 1) * (i + 2) / 6;   }   int main() {     scanf( %d%d , &n, &m);     for (int y = 1; y <= m; y++) {       scanf( %d%d%d , &I[y], &J[y], &W[y]);       in[J[y]].push_back(I[y]);       out[I[y]].push_back(J[y]);       Su[y] = gett(W[y]);     }     scc();     tmp.clear();     cin >> shroo;     for (int y = 1; y <= m; y++)       if (id[I[y]] == id[J[y]]) dp2[id[I[y]]] += Su[y];     for (int y = 1; y <= m; y++)       if (id[I[y]] != id[J[y]]) tmp.push_back(y);     sort(tmp.begin(), tmp.end(), amx);     for (int y = 1; y <= n; y++) dp1[y] = dp2[y];     for (auto A : tmp)       dp1[id[I[A]]] = max(dp1[id[I[A]]], dp2[id[I[A]]] + W[A] + dp1[id[J[A]]]);     printf( %lld , dp1[id[shroo]]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100500;   struct matrix {     long double a[3][3];     void clear() { memset(a, 0, sizeof(a)); }     matrix operator*(const matrix &y) {       matrix ans;       ans.clear();       for (int i = (0), iend = (2); i <= iend; i++)         for (int j = (0), jend = (2); j <= jend; j++)           for (int k = (0), kend = (2); k <= kend; k++)             ans.a[i][j] += a[i][k] * y.a[k][j];       return ans;     }   } basis;   struct segment_tree {     matrix sum[maxn << 2];     void push_up(int rt) { sum[rt] = sum[(rt << 1)] * sum[(rt << 1 | 1)]; }     void upd(int l, int r, int rt, int tar, long double val) {       if (l == r) {         sum[rt].clear();         sum[rt].a[1][0] = 1;         sum[rt].a[2][1] = 1;         sum[rt].a[1][2] = (val - 1) / val;         sum[rt].a[2][2] = 1 / val;         return;       }       int mid = (l + r) >> 1;       if (tar <= mid)         upd(l, mid, (rt << 1), tar, val);       else         upd(mid + 1, r, (rt << 1 | 1), tar, val);       push_up(rt);     }     matrix query(int l, int r, int rt, int tl, int tr) {       if (tl <= l && r <= tr) return sum[rt];       int mid = (l + r) >> 1;       matrix ans = basis;       if (tl <= mid) ans = ans * query(l, mid, (rt << 1), tl, tr);       if (tr >= mid + 1) ans = ans * query(mid + 1, r, (rt << 1 | 1), tl, tr);       return ans;     }   } t;   int main() {     basis.clear();     for (int i = (0), iend = (2); i <= iend; i++) basis.a[i][i] = 1;     int n, q;     scanf( %d%d , &n, &q);     for (int i = (1), iend = (n); i <= iend; i++) {       int a, b;       scanf( %d%d , &a, &b);       t.upd(1, n, 1, i, (long double)(a) / b);     }     for (int i = (1), iend = (q); i <= iend; i++) {       int ty;       scanf( %d , &ty);       if (ty == 1) {         int idx, a, b;         scanf( %d%d%d , &idx, &a, &b);         t.upd(1, n, 1, idx, (long double)(a) / b);       } else {         int l, r;         scanf( %d%d , &l, &r);         matrix ans;         ans.clear();         ans.a[0][2] = 1;         ans = ans * t.query(1, n, 1, l, r);         long double out = (long double)(1) / ans.a[0][2];         if (isnan(out)) out = 0;         printf( %.7lf n , (double)(out));       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int mn = 101000;   vector<int> e[mn];   int c[mn], s[mn], sc[mn], sv[mn];   int R[mn], vis[mn];   int n, m, i, j, k, nc, tt;   long long ans;   bool cmpc(int i, int j) { return c[i] > c[j]; }   bool cmps(int i, int j) { return s[i] < s[j]; }   void add(int i, int d, int l) {     s[0] = l;     int j = lower_bound(sv + 1, sv + 1 + n, 0, cmps) - sv;     if (j == n + 1) return;     j = sv[j];     if (s[j] != l || c[j] > d) return;     e[j].push_back(i);   }   inline bool dfs(int r) {     int p, i;     vis[r] = nc;     for (p = 0; p < e[r].size(); ++p) {       i = e[r][p];       if (R[i] == 0 || (vis[R[i]] != nc && dfs(R[i]))) {         R[i] = r;         return 1;       }     }     return 0;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (i = 1; i <= n; ++i) cin >> c[i] >> s[i];     for (i = 1; i <= n; ++i) sc[i] = sv[i] = i;     sort(sc + 1, sc + 1 + n, cmpc);     sort(sv + 1, sv + 1 + n, cmps);     cin >> m;     for (i = 1; i <= m; ++i) {       cin >> j >> k;       add(i, j, k);       add(i, j, k + 1);     }     for (i = 1; i <= n; ++i) {       ++nc;       if (dfs(sc[i])) ++tt, ans += c[sc[i]];     }     cout << ans << endl;     cout << tt << endl;     for (i = 1; i <= m; ++i)       if (R[i]) cout << i <<     << R[i] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MX = 2e5 + 3;   long long n, k, arr[MX], sum;   multiset<long long> st;   string s;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> k;     for (long long i = 0; i < n; i++) cin >> arr[i];     cin >> s;     st.insert(-arr[0]);     for (long long i = 1; i < n; i++) {       if (s[i] == s[i - 1])         st.insert(-arr[i]);       else {         long long a = 0;         for (auto u : st) {           if (a == k) break;           sum -= u;           a++;         }         st.clear();         st.insert(-arr[i]);       }     }     long long a = 0;     for (auto u : st) {       if (a == k) break;       sum -= u;       a++;     }     cout << sum << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int n, root;   vector<int> adj[N];   int dp[N][2], deg[N];   bool mark[N];   void dfs(int u, int pre) {     for (int v : adj[u]) {       if (v == pre) continue;       dfs(v, u);     }     for (int p = 0, _n = (2); p < _n; p++) {       int d = (deg[u] + ((p == 0 && pre != -1) ? -1 : 0));       vector<int> ban;       for (int v : adj[u])         if (v != pre) {           if (!dp[v][0]) ban.push_back(v);         }       bool flag = false;       for (int v : ban) {         if (!dp[v][1]) {           flag = true;           break;         }       }       if (flag) continue;       if ((d - ban.size()) % 2 == 1) {         flag = true;         for (int v : adj[u])           if (v != pre && dp[v][0]) {             if (dp[v][1]) flag = false;           }         if (flag) continue;       }       dp[u][p] = 1;     }   }   void print_ans(int u, int pre, int p) {     int d = (deg[u] + ((p == 0 && pre != -1) ? -1 : 0)), cnt = 0;     for (int v : adj[u])       if (v != pre) {         if (!dp[v][0]) {           cnt++;           print_ans(v, u, 1);           mark[v] = 1;         }       }     if ((d - cnt) % 2 == 1) {       for (int v : adj[u])         if (v != pre && dp[v][0] && dp[v][1]) {           print_ans(v, u, 1);           mark[v] = 1;           break;         }     }     cout << u <<   n ;     for (int v : adj[u])       if (v != pre && !mark[v]) print_ans(v, u, 0);   }   int main(int argc, char const *argv[]) {     ios_base::sync_with_stdio(0);     cin.tie(0);     clock_t tStart = clock();     cin >> n;     for (int i = (1), _b = (n); i <= _b; i++) {       int j;       cin >> j;       if (j == 0)         root = i;       else {         adj[i].push_back(j);         adj[j].push_back(i);         deg[i]++;         deg[j]++;       }     }     dfs(root, -1);     if (!dp[root][0]) {       cout <<  NO  <<   n ;       return 0;     } else {       cout <<  YES  <<   n ;       print_ans(root, -1, 0);     }     fprintf(stderr,  Time taken: %.2fs n ,             (double)(clock() - tStart) / CLOCKS_PER_SEC);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     double weight = 0;     long n, m;     cin >> n >> m;     long long a[n];     long long b[n];     bool flag = 0;     for (long i = 0; i < n; i++) {       cin >> a[i];       if (a[i] == 1) {         flag = 1;       }     }     for (long i = 0; i < n; i++) {       cin >> b[i];       if (b[i] == 1) {         flag = 1;       }     }     if (flag == 1) {       cout << -1 << endl;       exit(0);     }     weight = m;     weight += double(weight) / double(b[0] - 1);     for (long i = n - 1; i > 0; i--) {       weight += double(weight) / double(a[i] - 1);       weight += double(weight) / double(b[i] - 1);     }     weight += double(weight) / double(a[0] - 1);     cout << setprecision(30) << weight - m << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 10050;   const int inf = 0x7fffffff;   string str;   int buf[maxn];   vector<int> sans[10];   int save[300] = {};   string ansstr;   string bk;   int bK;   int main(void) {     int n, K;     cin >> n >> K >> str;     int ans = inf;     for (int k = ( 0 ); k <= ( 9 ); ++k) {       for (int i = 0; i < (n); ++i) buf[i] = abs(k - str[i]);       sort(buf, buf + n);       int res = accumulate(buf, buf + K, 0);       if (ans > res) ans = res;       save[k] = res;     }     cout << ans << endl;     for (int i = 0; i < (n); ++i) ansstr.push_back( 9 );     bk = str;     bK = K;     for (int no = ( 0 ); no <= ( 9 ); ++no)       if (save[no] == ans) {         K = bK;         str = bk;         for (int i = 0; i < (10); ++i) sans[i].clear();         for (int i = 0; i < (n); ++i) {           if (str[i] >= no)             sans[abs(no - str[i])].push_back(i);           else             sans[abs(no - str[i])].push_back(1000000 - i);         }         for (int i = 0; i < (10); ++i) sort(sans[i].begin(), sans[i].end());         for (int i = 0; i < (10); ++i)           for (int j = 0; j < (sans[i].size()); ++j) {             if (K <= 0) break;             K--;             int cnt = sans[i][j];             if (cnt > 500000) cnt -= 1000000;             str[abs(cnt)] = no;           }         if (str < ansstr) ansstr = str;       }     cout << ansstr << endl;   }
#include <bits/stdc++.h>   int n, m, a, b, mna = 101, mnb = 101, mxa, mxb;   void No() { printf( -1 ); }   void Yes(int n) { printf( %d , n); }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n;          i++, scanf( %d , &a), mna = std::min(mna, a), mxa = std::max(mxa, a))       ;     for (int i = 0; i < m; i++, scanf( %d , &b), mnb = std::min(mnb, b))       ;     mxa = std::max(mxa, 2 * mna);     if (mxa >= mnb)       No();     else       Yes(mxa);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T bigmod(T p, T e, T M) {     long long int 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>   inline T bpow(T p, T e) {     long long int ret = 1;     for (; e > 0; e >>= 1) {       if (e & 1) ret = (ret * p);       p = (p * p);     }     return (T)ret;   }   int toInt(string s) {     int sm;     stringstream ss(s);     ss >> sm;     return sm;   }   int toLlint(string s) {     long long int sm;     stringstream ss(s);     ss >> sm;     return sm;   }   int ts, kk = 1;   int n, a[1000006];   bool bl[1000006];   char s[1000006];   int p[2][2][1000006];   int dp(bool st, bool c, int i) {     if (i == n) {       if (c && st) return -1;       return 0;     }     int &pr = p[st][c][i];     if (pr != -1) return pr;     pr = 0;     pr = max(pr, dp(st, 0, i + 1));     if (bl[i] == 0) {       if (c == 0) pr = max(dp((i == 0) || st, 1, i + 1) + 1, pr);       if (a[i] > 1) pr = max(dp(st, 1, i + 1) + 1, pr);     } else {       if (c == 0) pr = max(dp((i == 0) || st, 1, i + 1) + 1, pr);       if (a[i] > 1) pr = max(dp(st, 1, i + 1) + 1, pr);     }     return pr;   }   void prnt(bool st, bool c, int i) {     if (i == n) {       puts(  );       return;     }     int &pr = p[st][c][i];     if (dp(st, 0, i + 1) == pr) {       prnt(st, 0, i + 1);       return;     }     if (bl[i] == 0) {       if (c == 0 && dp((i == 0), 1, i + 1) + 1 == pr) {         printf( %d 0 0 n , i);         prnt((i == 0), 1, i + 1);         return;       }       if (a[i] > 1 && pr == dp(st, 1, i + 1) + 1) {         printf( %d 0 1 n , i);         prnt(st, 1, i + 1);         return;       }     } else {       if (c == 0 && dp((i == 0), 1, i + 1) + 1 == pr) {         printf( %d 1 0 n , i);         prnt((i == 0), 1, i + 1);         return;       }       if (a[i] > 1 && pr == dp(st, 1, i + 1) + 1) {         printf( %d 1 1 n , i);         prnt(st, 1, i + 1);         return;       }     }   }   int main() {     int t, i, j, k;     memset(p, -1, sizeof(p));     scanf(  %s , s);     k = strlen(s);     bl[0] = s[0] -  0 ;     n = 1;     for (i = 0; i < k; i++) {       if ((bool)(s[i] -  0 ) == bl[n - 1])         a[n - 1]++;       else {         bl[n] = (s[i] -  0 );         a[n++] = 1;       }     }     if (n > 1 && bl[n - 1] == bl[0]) {       a[0] += a[n - 1];       n--;     }     k = dp(0, 0, 0);     printf( %d n , k);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   set<pair<int, pair<int, int> > > l, u;   set<pair<int, pair<int, int> > >::iterator itu, itl;   const int INF = 1000 * 1000 * 1000LL + 10;   int main() {     int n, q, a, b, ll, lm, lt, uu, um, ut;     char c;     long long ans;     cin >> n >> q;     for (int i = 0; i < q; i++) {       scanf( %d %d %c , &a, &b, &c);       ans = 0;       if (c ==  U ) {         l.insert(make_pair(b, make_pair(INF, INF)));         u.insert(make_pair(a, make_pair(0, 0)));         itl = l.find(make_pair(b, make_pair(INF, INF)));         itu = u.find(make_pair(a, make_pair(0, 0)));         itu++;         if (itl == l.begin()) {           ll = 0;           lm = 0;           lt = q;         } else {           itl--;           ll = (*itl).first;           lm = (*itl).second.first;           lt = (*itl).second.second;           itl++;         }         if (itu == u.end()) {           uu = 0;           um = 0;           ut = q;         } else {           uu = n - (*itu).first + 1;           um = (*itu).second.first;           ut = (*itu).second.second;         }         itu--;         l.erase(itl);         u.erase(itu);         if (uu > ll || (ll == uu && ut < lt)) {           if (uu != b) ans += (um + b - uu);           u.insert(make_pair(a, make_pair(um + b - uu, i + 1)));         } else {           ans += (b - ll);           u.insert(make_pair(a, make_pair(b - ll, i + 1)));         }       } else {         l.insert(make_pair(b, make_pair(0, 0)));         u.insert(make_pair(a, make_pair(INF, INF)));         itl = l.find(make_pair(b, make_pair(0, 0)));         itu = u.find(make_pair(a, make_pair(INF, INF)));         itl++;         if (itl == l.end()) {           ll = n + 1;           lm = 0;           lt = q;         } else {           ll = (*itl).first;           lm = (*itl).second.first;           lt = (*itl).second.second;         }         if (itu == u.begin()) {           uu = n + 1;           um = 0;           ut = q;         } else {           itu--;           uu = n - (*itu).first + 1;           um = (*itu).second.first;           ut = (*itu).second.second;           itu++;         }         itl--;         l.erase(itl);         u.erase(itu);         if (uu > ll || (ll == uu && ut > lt)) {           if (ll != b) ans += (lm + ll - b);           l.insert(make_pair(b, make_pair(lm + ll - b, i + 1)));         } else {           ans += (uu - b);           l.insert(make_pair(b, make_pair(uu - b, i + 1)));         }       }       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 4040;   map<int, int> cnt1;   map<int, int> cnt2;   pair<int, int> a[200020];   int main() {     int ans = 0;     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i].first >> a[i].second;       cnt1[a[i].first + a[i].second]++;       cnt2[a[i].first - a[i].second]++;     }     for (int i = 0; i < n; i++) {       int curx = a[i].first;       int cury = a[i].second;       ans += cnt2[curx - cury] - 1 + cnt1[curx + cury] - 1;     }     cout << ans / 2 << endl;   }
#include <bits/stdc++.h>   using namespace std;   int a[2000];   int n;   inline bool check() {     int c = 0;     for (int i = 0; i < n; ++i)       if (a[i] + 1 == a[i + 1]) ++c;     if (c == n)       return true;     else       return false;   }   inline void push() {     for (int i = 0; i <= n; ++i) {       if (i % 2 == 0) {         if (a[i] == n)           a[i] = 0;         else           a[i] = a[i] + 1;       } else {         if (a[i] == 0)           a[i] = n;         else           a[i] = a[i] - 1;       }     }   }   int main() {     scanf( %d , &n);     --n;     for (int i = 0; i <= n; ++i) {       scanf( %d , &a[i]);       if (i % 2 == 0) {         if (a[i] == n)           a[i] = 0;         else           a[i] = a[i] + 1;       } else {         if (a[i] == 0)           a[i] = n;         else           a[i] = a[i] - 1;       }     }     if (check()) {       puts( Yes );       return 0;     } else {       for (int i = 0; i < n; ++i) {         push();         if (check()) {           puts( Yes );           return 0;         }       }     }     puts( No );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 55;   int n, l;   int a[maxn], b[maxn];   bool check(int d, int x, int y) {     int i = x + 1, j = y + 1;     i %= n;     j %= n;     while (i != x && j != y) {       if ((a[i] - b[j] + l) % l == d) {         i++;         i %= n;         j++;         j %= n;       } else {         return false;       }     }     return true;   }   int main() {     cin >> n >> l;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) cin >> b[i];     bool flag = false;     for (int i = 0; i < n && !flag; i++) {       for (int j = 0; j < n && !flag; j++) {         int d = (a[i] - b[j] + l) % l;         if (check(d, i, j)) {           flag = true;         }       }     }     if (flag)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxN = 100000 + 10;   int main() {     long long n, a[maxN], c = 0, min = 1000000001, index;     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> a[i];       if (a[i] < min) {         min = a[i];         c = 0;         index = i;       } else if (a[i] == min) {         c++;       }     }     if (c == 0)       cout << index + 1;     else       cout <<  Still Rozdil ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c = 0;     cin >> a >> b;     int x[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};     for (int i = a; i <= b; i++) {       int y = i;       while (y != 0) {         c += x[y % 10];         y = y / 10;       }     }     cout << c;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   using ld = long double;   const int MN = 2e5 + 3, MOD = 1e9 + 7;   void solve() {     int n, a, b;     scanf( %d %d %d , &n, &a, &b);     if (a > b) swap(a, b);     printf( %d %d n , min(n, max(1, a + b + 1 - n)), min(n, a + b - 1));   }   int main() {     int t;     scanf( %d , &t);     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dx[] = {1, 0, -1, 0};   int dy[] = {0, 1, 0, -1};   const int N = (int)2e5 + 7;   const int MOD = (int)1e9 + 7;   const int INF = (int)2e7;   const long long BIG = 1e18;   int a[N], b[N], c[N], d[N];   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     ;     int n, ans = 0;     cin >> n;     unordered_map<int, int> cnt;     for (int i = 0; i < n; i++) cin >> a[i], cnt[a[i]]++;     set<pair<int, int> > q;     for (auto x : cnt) q.insert(make_pair(x.second, x.first));     while (int(q.size()) >= 3) {       vector<pair<int, int> > del;       auto it = q.end();       --it;       b[ans] = it->second;       del.push_back(*it);       --it;       c[ans] = it->second;       del.push_back(*it);       --it;       d[ans] = it->second;       del.push_back(*it);       ++ans;       for (auto x : del) {         pair<int, int> w = x;         q.erase(w);         if (w.first != 1) q.insert(make_pair(w.first - 1, w.second));       }     }     cout << ans <<   n ;     for (int i = 0; i < ans; i++) {       vector<int> p = {b[i], c[i], d[i]};       sort(p.begin(), p.end());       cout << p[2] <<     << p[1] <<     << p[0] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 151;   int m, n;   char gd[N][N];   inline int fab(int x) { return x > 0 ? x : -x; }   int main() {     while (scanf( %d%d , &m, &n) != -1) {       for (int i = 0; i < m; i++) scanf( %s , gd[i]);       int ans = 0, x = 0, y = 0;       for (int i = 0; i < m; i++)         for (int j = (i & 1 ? n - 1 : 0); 0 <= j && j < n; j += (i & 1 ? -1 : 1))           if (gd[i][j] ==  W ) {             ans += fab(i - x) + fab(j - y);             x = i;             y = j;           }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long g, r;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, m;     cin >> n >> m;     vector<int> d;     for (int i = 0; i < m; i++) {       long long dt;       cin >> dt;       d.push_back(dt);     }     sort(d.begin(), d.end());     cin >> g >> r;     vector<vector<bool>> vis(m, vector<bool>(g + 1));     vector<vector<int>> dis(m, vector<int>(g + 1, 0));     deque<tuple<int, int>> dq;     dq.push_back(make_tuple(0, 0));     long long ans = 1e9;     vis[0][0] = 1;     while (!dq.empty()) {       int i, t;       tie(i, t) = dq.front();       dq.pop_front();       if (t == 0) {         int ttn = n - d[i];         if (ttn <= g) {           ans = min(ans, dis[i][t] * (r + g) + ttn);         }       }       if (t == g) {         if (!vis[i][0]) {           dq.push_back(make_tuple(i, 0));           dis[i][0] = dis[i][t] + 1;           vis[i][0] = 1;         }         continue;       }       if (i) {         int rs = t + d[i] - d[i - 1];         if (rs <= g && !vis[i - 1][rs]) {           dis[i - 1][rs] = dis[i][t];           dq.push_front(make_tuple(i - 1, rs));           vis[i - 1][rs] = 1;         }       }       if (i < m - 1) {         int rs = t + d[i + 1] - d[i];         if (rs <= g && !vis[i + 1][rs]) {           dis[i + 1][rs] = dis[i][t];           dq.push_front(make_tuple(i + 1, rs));           vis[i + 1][rs] = 1;         }       }     }     if (ans == 1e9) {       cout << -1 <<   n ;     } else {       cout << ans <<   n ;     }   }