malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   int n, ans, G[8][8], vis[8];   vector<pair<int, int> > Edge;   void dfs(int x) {     if (x > n) {       int res = 0;       for (auto tmp : Edge) {         int u = vis[tmp.first];         int v = vis[tmp.second];         if (u > v) swap(u, v);         if (!G[u][v]) res++, G[u][v] = 1;       }       ans = max(ans, res);       for (auto tmp : Edge) {         int u = vis[tmp.first];         int v = vis[tmp.second];         if (u > v) swap(u, v);         G[u][v] = 0;       }       return;     }     for (int i = 1; i <= 6; i++) {       vis[x] = i;       dfs(x + 1);     }   }   int main() {     int u, v, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d%d , &u, &v);       Edge.push_back(make_pair(u, v));     }     dfs(1);     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int SIZE = 1e6 + 10;   int a[SIZE], b[SIZE], c[SIZE], cnt[SIZE];   bool used[SIZE];   vector<int> r[SIZE];   set<int> H;   void print_array(vector<int>& arr) {     for (int i = 0; i < (((int)(arr).size())); ++i) {       if (i) printf(   );       printf( %d , arr[i]);     }     puts(  );   }   bool check(int r_id) {     if (b[r_id] == c[r_id]) {       if (a[r_id] == b[r_id]) {         return cnt[c[r_id]] < 9;       } else {         return cnt[c[r_id]] < 8;       }     } else {       if (a[r_id] != b[r_id]) {         if (cnt[b[r_id]] == 9) return false;       }       if (a[r_id] != c[r_id]) {         if (cnt[c[r_id]] == 9) return false;       }       return true;     }   }   int main() {     int(n);     scanf( %d , &n);     for (int i = 0; i < (4 * n); ++i) {       scanf( %d%d%d , &(a[i]), &(b[i]), &(c[i]));       r[a[i]].push_back(i);       r[b[i]].push_back(i);       r[c[i]].push_back(i);       H.insert(i);     }     for (int i = 0; i < (n); ++i) cnt[i + 1] = 4;     puts( YES );     vector<int> an;     while (((int)(H).size())) {       int me = *H.begin();       used[me] = 1;       H.erase(me);       int now[3] = {a[me], b[me], c[me]};       cnt[a[me]]--;       cnt[b[me]]++;       cnt[c[me]]++;       an.push_back(me + 1);       for (int k = 0; k < (3); ++k) {         int id = now[k];         for (int i = 0; i < (((int)(r[id]).size())); ++i) {           int r_id = r[id][i];           if (!used[r_id]) {             if (check(r_id)) {               H.insert(r_id);             } else {               if (H.count(r_id)) H.erase(r_id);             }           }         }       }     }     print_array(an);     assert(((int)(an).size()) == n * 4);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[200001], t[200001];   int main() {     int i;     int n, m;     scanf( %d %d %s %s , &n, &m, s, t);     for (i = 0; i < n; i++) {       if (s[i] ==  * ) break;     }     if (i == n) {       if (n != m) {         printf( NO n );         return 0;       }       for (i = 0; i < n; i++) {         if (s[i] != t[i]) {           printf( NO n );           return 0;         }       }       printf( YES n );     } else {       int p = i;       if (m < n - 1) {         printf( NO n );         return 0;       }       for (i = 0; i < p; i++) {         if (s[i] != t[i]) {           printf( NO n );           return 0;         }       }       for (i = n - 1; i > p; i--) {         if (s[i] != t[m - (n - 1 - i) - 1]) {           printf( NO n );           return 0;         }       }       printf( YES n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int a0, a1, a2, b0, b1, b2, ex0, ex1, ex2, ever, only0, only1, only2;       cin >> a0 >> a1 >> a2 >> b0 >> b1 >> b2 >> ever >> ex2 >> ex1 >> only0 >>           ex0 >> only1 >> only2;       int s0 = ever + ex1 + ex2 + only0, s1 = ever + ex0 + ex2 + only1,           s2 = ever + ex0 + ex1 + only2;       if (s0 > a0 + b0 || s1 > a1 + b1 || s2 > a2 + b2) {         cout <<  -1 n ;         continue;       }       int anime = ever + ex0 + ex1 + ex2;       bool ok = false;       for (int i = 0; i <= anime; i++) {         int luex0 = i + max(-a0, ex0 - anime),             ruex0 = ex0 + min(0, b0 + i - anime),             luex1 = i + max(-a1, ex1 - anime),             ruex1 = ex1 + min(0, b1 + i - anime),             luex2 = i + max(-a2, ex2 - anime),             ruex2 = ex2 + min(0, b2 + i - anime);         luex0 = max(0, luex0);         luex1 = max(0, luex1);         luex2 = max(0, luex2);         if (luex0 > ruex0 || luex1 > ruex1 || luex2 > ruex2 ||             min(i, ruex0 + ruex1 + ruex2) <                 max(max(0, i - ever), luex0 + luex1 + luex2))           continue;         int uex0 = max(luex0, max(0, i - ever) - ruex1 - ruex2),             uex1 = max(luex1, max(0, i - ever) - uex0 - ruex2),             uex2 = max(luex2, max(0, i - ever) - uex0 - uex1);         int uonly0 = min(only0, a0 - i + uex0),             uonly1 = min(only1, a1 - i + uex1),             uonly2 = min(only2, a2 - i + uex2);         ok = true;         cout << i - uex0 - uex1 - uex2 <<     << uex2 <<     << uex1 <<                  << uonly0 <<     << uex0 <<     << uonly1 <<     << uonly2 <<   n ;         break;       }       if (!ok) cout <<  -1 n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int i = 1, j = n, count = 0, k = 1;     while (k <= (n - 1)) {       count = count + ((i + j) % (n + 1));       if (k % 2 == 1) {         i++;       } else {         j--;       }       k++;     }     cout << count;   }
#include <bits/stdc++.h>   using namespace std;   struct point {     int x, y, z;     double dist(point& p) {       return sqrt((double)((p.x - x) * (p.x - x) + (p.y - y) * (p.y - y) +                            (p.z - z) * (p.z - z)));     }   };   int N;   point P[5005];   double solve() {     double res = 1e10;     for (int i = 1; i < N; i++) {       for (int j = i + 1; j < N; j++) {         double per = P[i].dist(P[j]) + P[i].dist(P[0]) + P[j].dist(P[0]);         if (per < res) res = per;       }     }     return res / 2.0;   }   int main() {     while (cin >> N) {       for (int i = 0; i < N; i++) {         cin >> P[i].x >> P[i].y >> P[i].z;       }       cout << setprecision(12) << solve() << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   inline vector<int> prefix(string p) {     vector<int> pi;     int m = p.size();     for (int(i) = (0); (i) < (m); ++(i)) pi.push_back(-1);     int k = -1;     for (int(i) = (1); (i) < (m); ++(i)) {       while (k != -1 && p[k + 1] != p[i]) k = pi[k];       if (p[k + 1] == p[i]) k++;       pi[i] = k;     }     return pi;   }   set<int> s;   inline void shift(string p) {     vector<int> pi = prefix(p);     int m = p.size();     int k = pi[m - 1];     while (k != -1) {       s.insert(m - k);       k = pi[k];     }   }   int main() {     ios_base::sync_with_stdio(false);     long long n, m;     cin >> n >> m;     string p;     cin >> p;     vector<int> pi = prefix(p);     shift(p);     vector<int> v;     for (int(i) = (0); (i) < (m); ++(i)) {       int a;       cin >> a;       v.push_back(a);     }     bool ok = true;     for (int(i) = (1); (i) < (v.size()); ++(i)) {       long long r = v[i], l = v[i - 1];       if (r < (l + p.size()) && s.find((r - l + 1)) == s.end()) {         cout << 0 << endl;         ok = false;         break;       }       if ((p.size() + r - 1) > n && ok) {         cout << 0 << endl;         ok = false;         break;       }     }     long long first = n;     if (ok) {       v.push_back(2000000000);       for (int(i) = (0); (i) < (v.size() - 1); ++(i))         first -= min((int)p.size(), v[i + 1] - v[i]);     }     long long ans = 1;     if (first < 0 && ok) {       cout << 0 << endl;       ok = false;     }     for (int(i) = (0); (i) < (first); ++(i))       ans = (ans * (long long)26) % 1000000007;     if (ok) cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, oh, wow;     cin >> n >> oh >> wow;     vector<int> res;     res.push_back(1);     int sum = 1;     for (int i = 0; i < wow; i++) {       res.push_back(sum + 1);       sum += sum + 1;     }     if (!wow && oh) res.push_back(1);     for (int i = 0; i < oh; i++) {       res.push_back(res.back() + 1);     }     while ((int)res.size() < n) res.push_back(1);     if ((int)res.size() > n) {       cout <<  -1 n ;       return 0;     }     for (int i = 0; i < n; i++)       if (res[i] > 50000) {         cout <<  -1 n ;         return 0;       }     for (int i = 0; i < n; i++) {       if (i) cout <<    ;       cout << res[i];     }     cout <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   long long rdtsc() {     long long tmp;     asm( rdtsc  :  =A (tmp));     return tmp;   }   inline int myrand() { return abs((rand() << 15) ^ rand()); }   inline int rnd(int x) { return myrand() % x; }   const int INF = (int)1e9 + 1;   const long double EPS = 1e-9;   void precalc() {}   int gcd(int a, int b) {     for (; b; a %= b, swap(a, b))       ;     return a;   }   int getFunc(const pair<int, int> &a, const pair<int, int> &b) {     return gcd(abs(a.first - b.first), abs(a.second - b.second));   }   long long inside(int n, pair<int, int> *ps, long long G = -1) {     if (n < 3) {       return 0;     }     bool needG = (G == -1);     if (needG) {       G = 0;     }     long long S2 = 0;     for (int i = 0; i < n; ++i) {       int in = (i == n - 1 ? 0 : (i + 1));       int dx = ps[in].first - ps[i].first;       S2 += (long long)dx * (ps[in].second + ps[i].second);       if (needG) {         G += getFunc(ps[i], ps[in]);       }     }     S2 = abs(S2);     long long res = S2 + 2 - G;     assert(!(res & 1));     return res / 2;   }   const int maxn = (int)1e5 + 10;   pair<int, int> ps[maxn * 2];   int n;   bool read() {     if (scanf( %d , &n) < 1) {       return 0;     }     for (int i = 0; i < n; ++i) {       scanf( %d%d , &ps[i].first, &ps[i].second);     }     return 1;   }   long long cnts[maxn];   int gcdn[maxn * 2];   int gcdc[maxn];   void solve() {     for (int i = 0; i < n; ++i) {       cnts[i] = 0;       ps[n + i] = ps[i];     }     for (int i = 0; i < n; ++i) {       gcdc[i] = gcdn[i] = gcdn[i + n] = getFunc(ps[i], ps[i + 1]);     }     long long whole = inside(n, ps);     long double up, down;     long double prob;     if (n <= 100) {       up = 1;       for (int i = 0; i < n; ++i) {         up *= 2;       }       down = up - (long double)(n * (n - 1) / 2 + n + 1);       up /= 8;       up -= 1;     } else {       prob = 1;       prob /= 8;     }     pair<int, int> tmp[3];     long double res = whole;     for (int k = 3; k < min(60, n); ++k) {       assert(k <= 150);       if (n <= 100) {         prob = up / down;       }       for (int i = 0; i < n; ++i) {         long long &cnt = cnts[i];         tmp[0] = ps[i], tmp[1] = ps[i + k - 2], tmp[2] = ps[i + k - 1];         int ngcd = getFunc(ps[i], ps[i + k - 1]);         cnt += inside(3, tmp, (long long)gcdc[i] + gcdn[i + k - 2] + ngcd) +                ngcd - 1;         gcdc[i] = ngcd;         res -= prob * cnt;       }       if (n <= 100) {         up -= 1;         up /= 2;       } else {         prob /= 2;       }     }     printf( %.18f n , (double)res);   }   int main() {     srand(rdtsc());     precalc();     while (1) {       if (!read()) {         break;       }       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[1000010];   long long cnt[1000010];   int main() {     ios::sync_with_stdio(0);     int n;     cin >> n;     long long s = 0;     for (int i = 0; i < n; ++i) {       cin >> a[i];       s += a[i];     }     if (s % 3 != 0)       cout <<  0 n ;     else {       s /= 3;       long long ss = 0;       for (int i = n - 1; i >= 0; --i) {         ss += a[i];         if (ss == s) cnt[i] = 1;       }       for (int i = n - 2; i >= 0; --i) cnt[i] += cnt[i + 1];       long long ans = 0;       ss = 0;       for (int i = 0; i + 2 < n; ++i) {         ss += a[i];         if (ss == s) ans += cnt[i + 2];       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(int argc, char** argv) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int x1, y1, x2, y2;     cin >> x1 >> y1 >> x2 >> y2;     double slope;     slope = x2 == x1 ? INT_MAX : (double)(y2 - y1) / (double)(x2 - x1);     if (slope == 0 || abs(slope) == 1 || abs(slope) == INT_MAX) {       if (slope == 0) {         int sideSq = abs(x2 - x1);         int next_y = y1 + sideSq;         if (next_y > 1000) {           next_y = y1 - sideSq;           if (next_y < -1000) {             cout << -1 <<   n ;             return 0;           }         }         cout << x1 <<     << next_y <<     << x2 <<     << next_y <<   n ;       } else if (slope == INT_MAX) {         int sideSq = abs(y2 - y1);         int next_x = x1 + sideSq;         if (next_x > 1000) {           next_x = x1 - sideSq;           if (next_x < -1000) {             cout << -1 <<   n ;             return 0;           }         }         cout << next_x <<     << y1 <<     << next_x <<     << y2 <<   n ;       } else {         cout << x1 <<     << y2 <<     << x2 <<     << y1 <<   n ;       }     } else {       cout << -1 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, M;   int For[100000], Against[100000];   int TotalFor = 0, TotalAgainst = 0;   int Vote[100000];   int Sign[100000];   int J[100000];   int R[100000];   void Solve() {     int c = 0;     for (int i = 0; i < N; i++) {       J[i] = true;       if (For[i] + TotalAgainst - Against[i] != M) {         J[i] = false;       } else {         J[i] = true;         c++;       }     }     for (int i = 0; i < N; i++) {       if (!J[Vote[i]]) {         if (Sign[i] > 0)           R[i] = 2;         else           R[i] = 1;       } else if (c == 1) {         if (Sign[i] > 0)           R[i] = 1;         else           R[i] = 2;       }       if (R[i] == 0)         printf( Not defined n );       else if (R[i] == 1)         printf( Truth n );       else         printf( Lie n );     }   }   int main() {     scanf( %d %d , &N, &M);     char c;     for (int i = 0; i < N; i++) {       scanf(  %c%d , &c, &Vote[i]);       Vote[i]--;       if (c ==  + ) {         For[Vote[i]]++;         Sign[i] = 1;         TotalFor++;       } else {         Against[Vote[i]]++;         Sign[i] = -1;         TotalAgainst++;       }     }     Solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 10;   long long a[maxn];   int main() {     long long n, k, x;     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> x;       a[i] = a[i - 1] + x;     }     long long ans = a[n] * k;     sort(a + 1, a + n);     for (int i = 1; i < k; i++) ans -= a[i];     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>      using namespace std;      typedef long long ll;   typedef pair<int, int> pii;      const int N = 510;   const int MOD = 998244353;      int a[N];   int b[N];   int dp[N][N];      void add_self(int& x, int y) {       if ((x += y) >= MOD) {           x -= MOD;       }   }      void sub_self(int& x, int y) {       if ((x -= y) < 0) {           x += MOD;       }   }      int add(int x, int y) {       return add_self(x, y), x;   }      int sub(int x, int y) {       return sub_self(x, y), x;   }      int mul(int x, int y) {       return (ll)x * y % MOD;   }      int main() {       int n;       cin >> n;          for (int i = 0; i < n; i++) {           char c;           scanf(  %c , &c);           if (c ==  + ) {               b[i] = 1;               scanf( %d , a + i);           }       }          int answer = 0;          for (int k = 0; k < n; k++) {           if (!b[k]) {               continue;           }              memset(dp, 0, sizeof(dp));              for (int j = 0; j <= n; j++) {               dp[n][j] = 1;           }              for (int i = n - 1; ~i; --i) {               for (int j = 0; j < n; j++) {                   if (i == k) {                       dp[i][j] = dp[i + 1][j];                   } else {                       dp[i][j] = dp[i + 1][j];                       if (b[i]) {                           add_self(dp[i][j], dp[i + 1][j + (pii(a[i], i) < pii(a[k], k))]);                       } else if (i < k || j > 0) {                           add_self(dp[i][j], dp[i + 1][max(0, j - 1)]);                       }                   }               }           }              add_self(answer, mul(a[k], dp[0][0]));       }          cout << answer << endl;   }
#include <bits/stdc++.h>   using namespace std;      const int N = 102;   int t, n, m, r[N], b[N];      int main() {    ios::sync_with_stdio(0);    cin.tie(0);    cin >> t;    for(int ti = 1; ti <= t; ++ti) {     cin >> n;     for(int i = 1; i <= n; ++i) {      cin >> r[i];      r[i] += r[i - 1];     }     cin >> m;     for(int i = 1; i <= m; ++i) {      cin >> b[i];      b[i] += b[i - 1];     }     int fp = 0;     for(int i = 0; i <= n; ++i) {      for(int j = 0; j <= m; ++j) {       fp = max(fp, r[i] + b[j]);      }     }     cout << fp <<   n ;    }    return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxi = 1e6 + 6;   int b, di;   string a, c, t;   pair<int, int> d[maxi], d1[maxi];   int ob[maxi];   int main() {     cin >> b >> di;     cin >> a;     cin >> c;     int n = a.size();     int m = c.size();     for (int i = 0; i < m; i++) {       int id = 0;       for (int j = 0; j < n; j++)         if (c[i] == a[j]) id++;       if (!id) {         printf( %d n , 0);         return 0;       }     }     for (int i = 0; i < (m + 1); i++) t += a;     int cur = 0;     for (int j = 0; j < n; j++) {       cur = 0;       for (int i = j; i < (m + 1) * n; i++) {         if (c[cur] == t[i]) cur++;         if (cur == m) {           d[j] = {i / n, i % n};           break;         }       }     }     for (int j = 0; j < n; j++) {       int posl = -1;       int cur = 0;       int tt = 0;       for (int k = j; k < n; k++) {         if (a[k] == c[cur]) cur++;         if (cur == m) {           posl = k;           cur = 0;           tt++;         }       }       d1[j] = {tt, posl};     }     int tot = 0;     int ans = 0;     int c1 = 0;     while (ans < b) {       if (d[c1].first > 0) {         tot++;         ans += d[c1].first;         c1 = d[c1].second;         c1++;         if (c1 == n) {           c1 -= n;           ans++;           if (ans == b) {             printf( %d n , tot / di);             return 0;           }         }       } else {         tot += d1[c1].first;         c1 = d1[c1].second;         c1++;         if (c1 == n) {           c1 -= n;           ans++;           if (ans == b) {             printf( %d n , tot / di);             return 0;           }         }       }     }     tot--;     cout << tot / di <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n;     cin >> k;     vector<string> s(n);     set<string> exist;     for (int i = 0; i < n; i++) {       cin >> s[i];       exist.insert(s[i]);     }     long long int count = 0;     for (int x = 0; x < n - 1; x++) {       for (int y = x + 1; y < n; y++) {         string temp =   ;         for (int i = 0; i < k; i++) {           if (s[x][i] == s[y][i]) {             temp += s[x][i];           } else if ((s[x][i] ==  S  && s[y][i] ==  T ) ||                      (s[x][i] ==  T  && s[y][i] ==  S )) {             temp +=  E ;           } else if ((s[x][i] ==  S  && s[y][i] ==  E ) ||                      (s[x][i] ==  E  && s[y][i] ==  S )) {             temp +=  T ;           } else if ((s[x][i] ==  E  && s[y][i] ==  T ) ||                      (s[x][i] ==  T  && s[y][i] ==  E )) {             temp +=  S ;           }         }         if (exist.find(temp) != exist.end()) {           count++;         }       }     }     cout << count / 3 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long max(long long a, long long b) { return a > b ? a : b; }   inline long long min(long long a, long long b) { return a > b ? b : a; }   template <typename T>   inline int read(T& res) {     long long x = 0, f = 1, flag = 0;     char ch;     flag = ch = getchar();     if (flag == -1) return -1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       flag = ch = getchar();       if (flag == -1) return -1;     }     while (ch >=  0  && ch <=  9  && flag != -1) {       x = (x << 1) + (x << 3) + (ch ^ 48);       flag = ch = getchar();     }     res = x * f;     return flag;   }   template <typename T, typename... Args>   inline int read(T& t, Args&... a) {     int res;     res = read(t);     if (res == -1) return -1;     res = read(a...);     return res;   }   const int maxn = 5511, mod = 1e9 + 9;   long long n, m, k;   long long qpow(long long x, long long y) {     long long ans = 1;     while (y) {       if (y & 1) ans = (ans * x) % mod;       y >>= 1;       x = (x * x) % mod;     }     return ans % mod;   }   long long A1, A2, C1[maxn], C2[maxn], w, b;   inline void solve() {     long long ans = 0, mx = max(w, b);     A1 = A2 = 1;     for (int i = 2; i <= w; i++) A1 = (A1 * i) % mod;     for (int i = 2; i <= b; i++) A2 = (A2 * i) % mod;     C1[2] = w - 1;     C2[2] = b - 1;     C1[1] = C2[1] = 1;     for (int i = 3; i <= mx; i++) {       long long inv = qpow(i - 1, mod - 2);       C1[i] = (C1[i - 1] * (w - i + 1) % mod * inv) % mod,       C2[i] = (C2[i - 1] * (b - i + 1) % mod * inv) % mod;     }     int lim = max(1, n - w);     for (int x = min(n - 2, b); x >= lim; x--) {       ans = (ans + (((((n - x - 1) * A1 % mod) * C1[n - x] % mod) * A2) % mod) *                        C2[x]) %             mod;     }     cout << ans << endl;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int t = 1;     while (cin >> n >> w >> b) solve();   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t;     scanf( %d%d , &n, &t);     int x, y;     vector<pair<int, int> > v(n);     for (int i = 0; i < (int)(n); ++i) {       scanf( %d%d , &x, &y);       v[i].first = x;       v[i].second = y;     }     int a[4] = {v[0].first, v[0].second, 7 - v[0].first, 7 - v[0].second};     bool f = true;     for (int i = 0; i < (int)(n); ++i) {       if (find(a, a + 4, v[i].first) == a + 4 or           find(a, a + 4, v[i].second) == a + 4)         f = false;     }     cout << (f ?  YES  :  NO );   }
#include <bits/stdc++.h>   using namespace std;   int n;   int m;   int p[100];   int f() {     int r = 0;     for (int i = 0; i < n; i++) {       int m = p[i];       for (int j = i; j < n; j++) {         if (m > p[j]) m = p[j];         r += m;       }     }     return r;   }   void print() {     for (int i = 0; i < n; i++) {       cout << p[i] <<    ;     }     cout << endl;   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 99; i >= 0; i--) {       p[i] = i + 1;     }     int ma = f();     iota(p, p + 100, 1);     int i = 0;     do {       if (f() == ma) {         i++;         if (i == m) {           print();           break;         }       }     } while (next_permutation(p, p + n));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string a, b, c, d;   int pref[123456];   int main() {     int n, k;     cin >> n >> k;     string s;     cin >> s;     s =  .  + s;     for (int i = 1; i < s.length(); i++) {       pref[i] = pref[i - 1];       if (s[i] ==  0 ) pref[i]++;     }     int ans = INT_MAX;     for (int i = 1; i < s.length(); i++) {       if (s[i] ==  0 ) {         int lo = k / 2;         int hi = s.length() - 1;         while (hi - lo > 2) {           int mid = (lo + hi) / 2;           int lft = max(0, i - mid);           int cccc = s.length() - 1;           int rt = min(cccc, i + mid);           if (pref[rt] - pref[lft - 1] < k + 1)             lo = mid;           else             hi = mid;         }         while (lo <= hi) {           int lft = max(0, i - lo);           int cccc = s.length() - 1;           int rt = min(cccc, i + lo);           if (pref[rt] - pref[lft - 1] < k + 1) lo++;           if (pref[rt] - pref[lft - 1] >= k + 1) break;         }         ans = min(ans, lo);       }     }     cout << ans;   }