malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   using ll = int64_t;   using ull = uint64_t;   inline void solve() {}   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     string s;     cin >> s;     int lucky = 0;     for (auto const &c : s) lucky += c ==  4  || c ==  7 ;     bool is_lucky = lucky > 0;     while (lucky) {       int x = lucky % 10;       if (!(x == 4 || x == 7)) is_lucky = false;       lucky /= 10;     }     cout << (is_lucky ?  YES  :  NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int mod = 1e9 + 7;   const double eps = 1e-6;   const int N = 1 << 17;   char S[N], T[N];   int AS[N], AT[N], BS[N], BT[N];   int main() {     cin >> (S + 1) >> (T + 1);     int n = strlen(S + 1), m = strlen(T + 1);     for (int i = 1; i <= n; i++) {       AS[i] = S[i] ==  A  ? AS[i - 1] + 1 : 0;       BS[i] = BS[i - 1] + (S[i] ==  B  || S[i] ==  C );     }     for (int i = 1; i <= m; i++) {       AT[i] = T[i] ==  A  ? AT[i - 1] + 1 : 0;       BT[i] = BT[i - 1] + (T[i] ==  B  || T[i] ==  C );     }     int q;     cin >> q;     while (q--) {       static int a, b, c, d;       cin >> a >> b >> c >> d;       int ss = BS[b] - BS[a - 1];       int tt = BT[d] - BT[c - 1];       if (ss > tt || (ss & 1) ^ (tt & 1))         cout << 0;       else {         int x = min(b - a + 1, AS[b]), y = min(d - c + 1, AT[d]);         if (x < y)           cout << 0;         else if (x > y && (x - y) % 3 && ss + 2 > tt)           cout << 0;         else if (x == y && x == b - a + 1 && y != d - c + 1)           cout << 0;         else           cout << 1;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int N, P, M, T;     cin >> N >> P >> M >> T;     deque<int> dq(N, 1);     for (int x = 0; x < T; x++) {       int typ, pos;       cin >> typ >> pos;       if (typ) {         dq.push_back(1);         if (pos <= P) P++;         cout << dq.size() <<     << P <<   n ;       } else {         int seg1 = pos;         if (P <= seg1) {           int Ind = dq.size() - seg1;           while (Ind > 0) {             dq.pop_back();             Ind--;           }           cout << dq.size() <<     << P <<   n ;         } else {           P -= seg1;           while (seg1 > 0) {             dq.pop_front();             seg1--;           }           cout << dq.size() <<     << P <<   n ;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100100;   int segTree[N * 4], n, x, y, z, l, r, val;   map<int, int> TMp, NMp;   vector<pair<int, int>> vv;   vector<int> v, numm[N];   struct Query {     int type, tim, num, ind;   };   Query q[N];   void update(int i, int j, int pos) {     if (i > r || j < l) return;     if (i == j) {       if (val == 0)         segTree[pos] = 0;       else         segTree[pos] += val;       return;     }     int mid = (i + j) / 2;     update(i, mid, pos * 2);     update(mid + 1, j, pos * 2 + 1);     segTree[pos] = segTree[pos * 2] + segTree[pos * 2 + 1];   }   int get(int i, int j, int pos) {     if (i > r || j < l) {       return 0;     }     if (l <= i && r >= j) {       return segTree[pos];     }     int mid = (i + j) / 2;     return get(i, mid, pos * 2) + get(mid + 1, j, pos * 2 + 1);   }   int main() {     scanf( %d , &n);     int c = 1;     for (int i = 0; i < n; i++) {       scanf( %d%d%d , &x, &y, &z);       if (NMp[z] == 0) {         NMp[z] = c;         c++;       }       numm[NMp[z]].push_back(i);       q[i].type = x;       q[i].tim = y;       q[i].num = NMp[z];       q[i].ind = i;       v.push_back(y);     }     sort(v.begin(), v.end());     int co = 1;     for (int i = 0; i < v.size(); i++) {       if (TMp[v[i]] == 0) {         TMp[v[i]] = co;         co++;       }     }     for (int j = 1; j < c; j++) {       for (int i = 0; i < numm[j].size(); i++) {         int x = numm[j][i];         if (q[x].type == 1) {           l = TMp[q[x].tim];           r = TMp[q[x].tim];           val = 1;           update(1, N, 1);         } else if (q[x].type == 2) {           l = TMp[q[x].tim];           r = TMp[q[x].tim];           val = -1;           update(1, N, 1);         } else if (q[x].type == 3) {           l = 1;           r = TMp[q[x].tim];           int ans = get(1, N, 1);           vv.push_back(make_pair(q[x].ind, ans));         }       }       for (int i = 0; i < numm[j].size(); i++) {         l = TMp[q[numm[j][i]].tim];         r = TMp[q[numm[j][i]].tim];         val = 0;         update(1, N, 1);       }     }     sort(vv.begin(), vv.end());     for (int i = 0; i < vv.size(); i++) {       printf( %d n , vv[i].second);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 10001;   vector<int> g[maxn];   int res;   int color[maxn];   int vis[maxn];   void solve(int root, int c) {     vis[root] = 1;     if (color[root] != c) res++;     for (int i = 0; i < g[root].size(); i++) {       int to = g[root][i];       if (vis[to]) continue;       solve(to, color[root]);     }   }   int main() {     int n;     scanf( %d , &n);     memset(vis, 0, sizeof(vis));     for (int i = 2; i <= n; i++) {       int t;       scanf( %d , &t);       g[i].push_back(t);       g[t].push_back(i);     }     for (int i = 1; i <= n; i++) scanf( %d , &color[i]);     res = 1;     solve(1, color[1]);     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     node *arr[27];     int ind;     node() {       memset(arr, 0, sizeof arr);       ind = 0;     }   };   const int N = 1e5 + 5;   int dp[N][2];   node *root;   int nodes = 0;   void insert(string &s) {     node *cur = root;     for (int i = 0; i < s.size(); i++) {       int x = s[i] -  a ;       if (!cur->arr[x]) cur->arr[x] = new node(), cur->arr[x]->ind = ++nodes;       cur = cur->arr[x];     }   }   bool solve(node *cur, bool f) {     int &ret = dp[cur->ind][f];     if (ret != -1) return ret;     bool flag = 0, flag1 = 0, flag2 = 1;     for (int i = 0; i < 26; i++) {       if (cur->arr[i]) {         flag = 1;         flag1 |= solve(cur->arr[i], !f);         flag2 &= solve(cur->arr[i], !f);       }     }     if (!flag) return ret = !f;     if (f) return ret = flag1;     return ret = flag2;   }   int dp2[N][2];   bool solve2(node *cur, bool f) {     int &ret = dp2[cur->ind][f];     if (ret != -1) return ret;     bool flag = 0, flag1 = 0, flag2 = 1;     for (int i = 0; i < 26; i++) {       if (cur->arr[i]) {         flag = 1;         flag1 |= solve2(cur->arr[i], !f);         flag2 &= solve2(cur->arr[i], !f);       }     }     if (!flag) return ret = !f;     if (f) return ret = flag2;     return ret = flag1;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     memset(dp, -1, sizeof dp);     memset(dp2, -1, sizeof dp2);     root = new node();     int n, k;     cin >> n >> k;     for (int i = 0; i < n; i++) {       string s;       cin >> s;       insert(s);     }     node *cur = root;     if (solve(cur, 1) && !solve2(cur, 1))       cout <<  First ;     else if (solve(cur, 1)) {       if (k % 2 == 1)         cout <<  First ;       else         cout <<  Second ;     } else       cout <<  Second ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int px, py;   int tx, ty;   int decide(int x, int y, int x2, int y2) {     px = tx;     py = ty;     px -= x;     py -= y;     x2 -= x;     y2 -= y;     int dis = x2 * py - y2 * px;     return dis >= 0;   }   int main() {     int n, d;     cin >> n >> d;     int ele;     cin >> ele;     while (ele--) {       int cnt = 0;       cin >> tx >> ty;       cnt += decide(d, 0, n, n - d);       cnt += decide(n, n - d, n - d, n);       cnt += decide(n - d, n, 0, d);       cnt += decide(0, d, d, 0);       if (cnt == 4)         printf( YES n );       else         printf( NO n );     }   }
#include <bits/stdc++.h>   using namespace std;   const int cstMax = 1e6 + 100;   const int cstAlphaSize = 26;   char a[cstMax], b[cstMax];   int c[cstMax][cstAlphaSize];   long long getGcd(long long a, long long b) {     long long r;     while (b != 0) r = a % b, a = b, b = r;     return a;   }   int main() {     long long n, m;     long long alen, blen, gcd, lcm;     long long cycleValue, nCicles;     while (cin >> n >> m) {       cin >> a >> b;       alen = strlen(a);       blen = strlen(b);       gcd = getGcd(alen, blen);       lcm = alen / gcd * blen;       cycleValue = lcm;       nCicles = n * alen / lcm;       memset(c, 0, sizeof c);       for (int i = (0); (i) < int(alen); ++i) ++c[i % gcd][int(a[i] -  a )];       for (int i = (0); (i) < int(blen); ++i)         cycleValue -= c[i % gcd][int(b[i] -  a )];       cout << (cycleValue * nCicles) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     std::vector<long long> x0, x1, y0, y1;     long long a[n][4];     for (long long int i = 0; i < n; i++) {       cin >> a[i][0] >> a[i][1] >> a[i][2] >> a[i][3];       x0.push_back(a[i][0]);       x1.push_back(a[i][2] + 1);       y0.push_back(a[i][1]);       y1.push_back(a[i][3] + 1);     }     sort((x0).begin(), (x0).end());     sort((x1).begin(), (x1).end());     sort((y0).begin(), (y0).end());     sort((y1).begin(), (y1).end());     long long lx = x0[n - 1];     long long ly = y0[n - 1];     long long ux = x1[0];     long long uy = y1[0];     for (long long int i = 0; i < n; i++) {       long long xi = a[i][0];       long long xf = a[i][2] + 1;       long long yi = a[i][1];       long long yf = a[i][3] + 1;       long long x00 = lx;       long long x11 = ux;       long long y00 = ly;       long long y11 = uy;       if (xi == lx) {         x00 = x0[n - 2];       }       if (xf == ux) {         x11 = x1[1];       }       if (yi == ly) {         y00 = y0[n - 2];       }       if (yf == uy) {         y11 = y1[1];       }       if (x00 < x11 && y00 < y11) {         cout << x00 <<     << y00;         return 0;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   char x[1001][1001];   int check(int i, int j) {     if (x[i][j] ==  . ) {       for (int a = -1; a <= 1; a++) {         for (int k = -1; k <= 1; k++) {           if (i + a >= 0 && i + a < n && j + k >= 0 && j + k < m &&               x[i + a][j + k] ==  * ) {             return 1;           }         }       }     } else {       int cnt = 0;       for (int a = -1; a <= 1; a++) {         for (int k = -1; k <= 1; k++) {           if (i + a >= 0 && i + a < n && j + k >= 0 && j + k < m &&               x[i + a][j + k] ==  * ) {             cnt++;           }         }       }       if (cnt != x[i][j] -  0 ) {         return 1;       }     }     return 0;   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       scanf( %s , x[i]);     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (x[i][j] !=  *  && check(i, j)) {           printf( NO n );           return 0;         }       }     }     printf( YES n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100000 + 100;   int n, m, k, ans;   int num[maxn];   int main() {     ios::sync_with_stdio(false);     while (scanf( %d%d%d , &n, &m, &k) != EOF) {       ans = 0;       for (int i = 0; i < n; ++i) {         scanf( %d , &num[i]);       }       ans = num[n - 1] - num[0] + 1;       for (int i = 0; i < n; ++i) {         num[i] = num[i + 1] - num[i] - 1;       }       sort(num, num + n - 1);       for (int i = 0; i < k - 1; ++i) {         ans -= num[n - 2 - i];       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, k, m;   long long t[300005];   long long a[300005];   long long s;   long long res[300005], ans[300005];   long long cnt[300005];   long long pre[300005], p[300005], pp[300005];   struct query {     long long l;     long long r;     long long id;   } q[300005];   bool cmp(query a, query b) {     if (a.l / s != b.l / s) return a.l / s < b.l / s;     return a.r / s < b.r / s;   }   void in() {     scanf( %lld%lld , &n, &k);     s = sqrt(n);     for (long long i = 1; i <= n; i++) {       scanf( %lld , &t[i]);     }     pre[0] = 0;     for (long long i = 1; i <= n; i++) {       scanf( %lld , &a[i]);       if (t[i] == 1) {         pre[i] = pre[i - 1] + a[i];       } else {         pre[i] = pre[i - 1] - a[i];       }     }     set<long long> al;     map<long long, long long> idx;     long long cnt = 0;     for (long long i = 0; i <= n; i++) {       if (al.empty() || al.find(pre[i] - k) == al.end()) {         al.insert(pre[i] - k);         cnt++;         idx[pre[i] - k] = cnt;         p[i] = cnt;       } else {         p[i] = idx[pre[i] - k];       }       if (al.empty() || al.find(pre[i] + k) == al.end()) {         al.insert(pre[i] + k);         cnt++;         idx[pre[i] + k] = cnt;         pp[i] = cnt;       } else {         pp[i] = idx[pre[i] + k];       }       if (al.empty() || al.find(pre[i]) == al.end()) {         al.insert(pre[i]);         cnt++;         idx[pre[i]] = cnt;         pre[i] = cnt;       } else {         pre[i] = idx[pre[i]];       }     }     scanf( %lld , &m);     for (long long i = 1; i <= m; i++) {       scanf( %lld%lld , &q[i].l, &q[i].r);       q[i].id = i;     }   }   void solve() {     sort(q + 1, q + m + 1, cmp);     long long l = 1, r = 0;     long long rf = 0;     for (long long i = 1; i <= m; i++) {       long long cur = 0;       while (l < q[i].l) {         cnt[pre[l]]--;         cur -= cnt[pp[l]];         l++;       }       while (l > q[i].l) {         l--;         cur += cnt[pp[l]];         cnt[pre[l]]++;       }       while (r < q[i].r) {         r++;         cur += cnt[p[r]];         cnt[pre[r]]++;       }       while (r > q[i].r) {         cnt[pre[r]]--;         cur -= cnt[p[r]];         r--;       }       rf += cur;       res[q[i].id] = rf + cnt[pp[l - 1]];     }   }   void ou() {     for (long long i = 1; i <= m; i++) {       printf( %lld n , res[i]);     }   }   signed main() {     in();     solve();     ou();   }
#include <bits/stdc++.h>   using namespace std;   int64_t b, s, c;   int64_t pr[3];   int64_t m;   int64_t req[] = {0, 0, 0};   bool binary_search(int64_t mid) {     int64_t to[3];     for (int64_t i = 0; i < 3; i++) {       to[i] = req[i] * mid;     }     to[0] -= b;     to[1] -= s;     to[2] -= c;     int64_t cost = 0;     for (int64_t i = 0; i < 3; i++)       if (to[i] > 0) cost += to[i] * pr[i];     if (cost <= m) return true;     return false;   }   signed main() {     string ss;     cin >> ss;     for (char i : ss) {       if (i ==  B )         req[0]++;       else if (i ==  S )         req[1]++;       else         req[2]++;     }     cin >> b >> s >> c;     for (int64_t i = 0; i < 3; i++) cin >> pr[i];     cin >> m;     int64_t st = 0;     int64_t en = 1e14;     int64_t ans = 0;     while (st <= en) {       int64_t mid = st + (en - st) / 2;       if (binary_search(mid)) {         ans = mid;         st = mid + 1;       } else {         en = mid - 1;       }     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const int mod = 1000000007;   const int inf = 0x3f3f3f3f;   const int maxn = 200005;   void task() {     int r1, c1, r2, c2;     cin >> r1 >> c1 >> r2 >> c2;     int Rook = 0, Bishop = 0, King = 0;     if (r1 == r2 or c1 == c2)       Rook = 1;     else       Rook = 2;     if ((r1 + c1) == (r2 + c2) or (r2 - r1) == (c2 - c1))       Bishop = 1;     else if ((r1 + c1) % 2 == (r2 + c2) % 2)       Bishop = 2;     else       Bishop = 0;     King = max(abs(r1 - r2), abs(c1 - c2));     cout << Rook <<     << Bishop <<     << King <<   n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int T = 1;     while (T--) {       task();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ans = 0;   int m;   void dfs(int parent, int s, int cnt, vector<int> &cats,            vector<vector<int> > &adj) {     if (cats[s] == 1)       cnt++;     else       cnt = 0;     if (cnt > m) return;     if (s != 1 && adj[s].size() == 1) {       ans++;       return;     }     for (int i : adj[s]) {       if (i != parent) dfs(s, i, cnt, cats, adj);     }   }   int main() {     int n;     int x, y;     cin >> n >> m;     vector<int> cats(n + 1);     for (int i = 1; i <= n; i++) cin >> cats[i];     vector<vector<int> > adj(n + 1);     for (int i = 0; i < n - 1; i++) {       cin >> x >> y;       adj[x].push_back(y);       adj[y].push_back(x);     }     dfs(0, 1, 0, cats, adj);     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, a[1000006], ans[1000006];   bool b[1000006];   stack<pair<int, int> > s1, s2;   int main() {     int i, j;     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d , &a[i]);     scanf( %d , &m);     for (i = 1; i <= m; i++) {       scanf( %d , &j);       b[j] = true;     }     for (i = 1; i <= n; i++) {       if (b[i]) {         while (s1.size()) {           if (s1.top().first == a[i] && s2.size() == 0) {             break;           } else if (s2.size() && s1.top().first == s2.top().first) {             ans[s1.top().second] = 1;             ans[s2.top().second] = -1;             s1.pop();             s2.pop();           } else {             s2.push(s1.top());             s1.pop();           }         }         if (s1.size() == 0) return cout <<  NO  << endl, 0;         ans[s1.top().second] = 1;         ans[i] = -1;         s1.pop();       } else {         s1.push({a[i], i});       }     }     while (s1.size()) {       if (s2.size() == 0) {         s2.push(s1.top());         s1.pop();       } else if (s1.top().first == s2.top().first) {         ans[s1.top().second] = 1;         ans[s2.top().second] = -1;         s1.pop();         s2.pop();       } else {         s2.push(s1.top());         s1.pop();       }     }     if (s2.size()) return cout <<  NO  << endl, 0;     printf( YES n );     for (i = 1; i <= n; i++) printf( %d  , a[i] * ans[i]);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e2, W = 10;   long long dp[N + 5][N + 5][W + 5][W + 5];   int n1, n2, k1, k2;   int main() {     memset(dp, -1, sizeof(dp));     cin >> n1 >> n2 >> k1 >> k2;     for (int i = 0; i <= n1; i++) {       for (int j = 0; j <= n2; j++) {         for (int k = 0; k <= k1; k++) {           for (int l = 0; l <= k2; l++) {             long long ans = 0;             if ((i + j) == 0) {               ans = 1;             } else {               ans = 0;               if (i > 0 && k > 0)                 ans = (ans + dp[i - 1][j][k - 1][k2]) % 100000000;               if (j > 0 && l > 0)                 ans = (ans + dp[i][j - 1][k1][l - 1]) % 100000000;             }             dp[i][j][k][l] = ans;           }         }       }     }     cout << dp[n1][n2][k1][k2] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ans[] = {0,   1,  1, 1, 2,  1, 2,  1, 5,  2, 2,  1, 5,  1, 2, 1,                14,  1,  5, 1, 5,  2, 2,  1, 15, 2, 2,  5, 4,  1, 4, 1,                51,  1,  2, 1, 14, 1, 2,  2, 14, 1, 6,  1, 4,  2, 2, 1,                52,  2,  5, 1, 5,  1, 15, 2, 13, 2, 2,  1, 13, 1, 2, 4,                267, 1,  4, 1, 5,  1, 4,  1, 50, 1, 2,  3, 4,  1, 6, 1,                52,  15, 2, 1, 15, 1, 2,  1, 12, 1, 10, 1, 4,  2};   int main() {     int a;     cin >> a;     cout << ans[a];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long EPS = 1000000007;   const int INF = 1000000000;   double PI = 3.14159265358979323846;   const int MAXN = 1000040;   long long abss(long long h) { return max(h, -h); }   double fabss(double h) { return max(h, -h); }   long long ceill(long long x, long long y) {     if (x % y != 0) return (x / y) + 1;     return x / y;   }   string itos(long long num) {     string str =   ;     if (num == 0) return  0 ;     while (num != 0) {       str += ((num % 10) +  0 );       num /= 10;     }     reverse(str.begin(), str.end());     return str;   }   long long sstoi(string num) {     long long count = 1;     for (int i = 0; i < (int)num.size() - 1; i++) {       count *= 10;     }     long long ans = 0;     for (int i = 0; i < (int)num.size(); i++) {       ans += (num[i] -  0 ) * count;       count /= 10;     }     return ans;   }   long long n, m, k, h;   pair<char, int> a[MAXN];   int b[MAXN];   int c[MAXN];   pair<char, int> t[MAXN];   void build(int v, int tl, int tr) {     if (tl == tr) {       t[v].first = a[tl].first;       t[v].second = a[tl].second;     } else {       int tm = (tl + tr) / 2;       build(v * 2, tl, tm);       build(v * 2 + 1, tm + 1, tr);       if (t[v * 2].first > t[v * 2 + 1].first) {         t[v] = t[v * 2 + 1];       } else if (t[v * 2].first < t[v * 2 + 1].first) {         t[v] = t[v * 2];       } else if (t[v * 2].first == t[v * 2 + 1].first &&                  t[v * 2].second > t[v * 2 + 1].second) {         t[v] = t[v * 2];       } else {         t[v] = t[v * 2 + 1];       }     }   }   pair<char, int> sum(int v, int tl, int tr, int l, int r) {     if (l > r) return make_pair( z , -1);     if (l == tl && r == tr) return t[v];     int tm = (tl + tr) / 2;     pair<char, int> q1 = sum(v * 2, tl, tm, l, min(r, tm));     pair<char, int> q2 = sum(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r);     if (q1.first > q2.first) {       return q2;     } else if (q1.first < q2.first) {       return q1;     } else if (q1.first == q2.first && q1.second > q2.second) {       return q1;     } else {       return q2;     }   }   int counter[30];   int main() {     int m;     cin >> m;     string str;     cin >> str;     int n = str.size();     for (int i = 0; i < n; i++) {       a[i].first = str[i];       a[i].second = i;       counter[str[i] -  a ]++;     }     build(1, 0, n - 1);     int index = 0;     vector<char> answer;     char maxChar =  a ;     while (true) {       pair<char, int> w = sum(1, 0, n - 1, index, index + m - 1);       answer.push_back(w.first);       maxChar = max(maxChar, w.first);       index = w.second;       if (index + m - 1 >= n - 1) {         break;       }       index++;     }     sort(answer.begin(), answer.end());     for (char i =  a ; i <=  z ; i++) {       if (i != maxChar) {         for (int j = 0; j < counter[i -  a ]; j++) {           cout << i;         }       } else {         for (int j = 0; j < answer.size(); j++) {           if (answer[j] == maxChar) {             cout << maxChar;           }         }         break;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (a == 0) return b;     return (b % a, a);   }   int binarysearch(int a[], int ele, int n) {     int beg = 0, end = n, mid, ans;     while (beg <= end) {       mid = beg + (end - beg) / 2;       if (a[mid] > ele) {         ans = mid;         end = mid - 1;       } else         beg = mid + 1;     }     return ans;   }   bool checkpallin(string a) {     int i = 0, j = a.length() - 1;     while (i < j) {       if (a[i] != a[j]) return false;       i++, j--;     }     return true;   }   bool comp(string a, string b) { return a.length() < b.length(); }   int main(void) {     int n, a;     cin >> n >> a;     if (a & 1)       cout << 1 + a / 2;     else       cout << 1 + (n - a) / 2;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 505;   int dis[N][N];   int vis[N], arr[N];   long long ans[N];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; ++j) {         cin >> dis[i][j];       }     }     for (int i = 1; i <= n; ++i) {       cin >> arr[i];     }     for (int i = n; i > 0; --i) {       int x = arr[i];       vis[x] = 1;       for (int j = 1; j <= n; ++j) {         for (int k = 1; k <= n; ++k) {           dis[j][k] = min(dis[j][k], dis[j][x] + dis[x][k]);           if (vis[j] && vis[k]) ans[i] += dis[j][k];         }       }     }     for (int i = 1; i <= n; ++i) cout << ans[i] <<    ;     return 0;   }