malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   void canhazfast() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);   }   template <typename T>   T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   template <typename T>   T extgcd(T a, T b, T &x, T &y) {     T x0 = 1, y0 = 0, x1 = 0, y1 = 1;     while (b) {       T q = a / b;       a %= b;       swap(a, b);       x0 -= q * x1;       swap(x0, x1);       y0 -= q * y1;       swap(y0, y1);     }     x = x0;     y = y0;     return a;   }   int ctz(unsigned x) { return __builtin_ctz(x); }   int ctzll(unsigned long long x) { return __builtin_ctzll(x); }   int clz(unsigned x) { return __builtin_clz(x); }   int clzll(unsigned long long x) { return __builtin_clzll(x); }   int popcnt(unsigned x) { return __builtin_popcount(x); }   int popcntll(unsigned long long x) { return __builtin_popcountll(x); }   int bsr(unsigned x) { return 31 ^ clz(x); }   int bsrll(unsigned long long x) { return 63 ^ clzll(x); }   void solve() {     int st, in, ex, ans;     int lo;     cin >> st >> in >> ex;     lo = (ex + in - st) >> 1;     lo = min(max(lo + 1, 0), ex + 1);     ans = ex - lo + 1;     cout << ans <<   n ;   }   int main() {     canhazfast();     int t;     cin >> t;     for (; t; --t) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int const N = 2005;   long long f(long long x, long long n) {     long long t = (x % 2 == 1 ? 1 : 2);     long long h = 1;     long long res = 0;     while (true) {       if ((x * h) > n) return res;       res += (t - (x * h + t - 1 - min(x * h + t - 1, n)));       t <<= 1;       h <<= 1;     }     return res;   }   long long bs(long long t, long long n, long long k) {     long long l = (t ? t : 2), r = (n % 2 == t ? n : n - 1);     long long res = 0;     while (l <= r) {       long long md = (l + r) / 2;       md = (md % 2 == t ? md : md - 1);       long long x = f(md, n);       if (x >= k) {         res = max(res, md);         l = md + 2;       } else         r = md - 2;     }     return res;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long n, k;     cin >> n >> k;     cout << max(bs(0, n, k), bs(1, n, k)) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int f, dp[2][2][30][30][30], ans;   void add(int &u, int x) {     u += x;     if (u >= 1000000009) u -= 1000000009;   }   int main() {     int n, h;     scanf( %d %d , &n, &h);     dp[f][1][0][0][0] = 4;     for (int i = 1, F; i < n; i++, f = F) {       F = f ^ 1;       for (int j = 2; j--;) {         for (int a = h; a--;) {           for (int b = h; b--;) {             for (int c = h; c--;) {               dp[F][j][a][b][c] = 0;             }           }         }       }       bool ok = i < h;       for (int j = 2; j--;) {         for (int a = h; a--;) {           int A = a ? (a + 1) % h : 0;           for (int b = h; b--;) {             int B = b ? (b + 1) % h : 0;             for (int c = h; c--;) {               int C = c ? (c + 1) % h : 0;               int val = dp[f][j][a][b][c];               add(dp[F][j][A][B][C], val);               add(dp[F][ok || a > 0][j][B][C], val);               add(dp[F][ok || b > 0][A][j][C], val);               add(dp[F][ok || c > 0][A][B][j], val);             }           }         }       }     }     for (int a = h; a--;) {       for (int b = h; b--;) {         for (int c = h; c--;) {           add(ans, dp[f][1][a][b][c]);           if (a || b || c) add(ans, dp[f][0][a][b][c]);         }       }     }     printf( %d , ans);   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100007;   int n, m;   long long h[maxn], p[maxn];   bool check(long long time) {     int x = 1, old_x;     for (int i = 1, _c = n; i <= _c; i++) {       if (x > m) return 1;       if (p[x] <= h[i]) {         if (h[i] - p[x] > time) return 0;         old_x = x;         while (x <= m && h[i] >= p[x]) x++;         if (old_x != x) {           while (x <= m &&                  p[x] - p[old_x] + min(p[x] - h[i], h[i] - p[old_x]) <= time)             x++;         }       } else {         while (x <= m && p[x] - h[i] <= time) x++;       }     }     return (x > m);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1, _c = n; i <= _c; i++) scanf( %I64d , &h[i]);     for (int i = 1, _c = m; i <= _c; i++) scanf( %I64d , &p[i]);     long long l, r, mid, res;     r = res = 20000000000ll;     l = 0;     while (l <= r) {       mid = (l + r) / 2;       if (check(mid)) {         res = mid;         r = mid - 1;       } else         l = mid + 1;     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MX = (int)1e6 + 17;   const int MOD = (int)1e9 + 7;   const long long oo = (long long)1e18 + 7;   const int INF = (int)999999999;   const int N = (int)1e5 + 17;   const int di[4] = {-1, 0, 1, 0};   const int dj[4] = {0, 1, 0, -1};   inline long long IN() {     long long x = 0, ch = getchar(), f = 1;     while (!isdigit(ch) && (ch !=  - ) && (ch != EOF)) ch = getchar();     if (ch ==  - ) {       f = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = (x << 1) + (x << 3) + ch -  0 ;       ch = getchar();     }     return x * f;   }   inline void OUT(long long x) {     if (x < 0) putchar( - ), x = -x;     if (x >= 10)       OUT(x / 10), putchar(x % 10 +  0 );     else       putchar(x +  0 );   }   int n, mx;   int a[N], t[N * 4];   void build(int v, int tl, int tr) {     if (tl == tr)       t[v] = a[tl];     else {       int tm = (tl + tr) / 2;       build(v * 2, tl, tm);       build(v * 2 + 1, tm + 1, tr);       t[v] = max(t[v * 2], t[v * 2 + 1]);     }   }   int get(int l, int r, int v, int tl, int tr) {     if (l <= tl && tr <= r) return t[v];     if (tr < l || tl > r) return 0;     int tm = (tl + tr) / 2;     return max(get(l, r, v * 2, tl, tm), get(l, r, v * 2 + 1, tm + 1, tr));   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     build(1, 1, n);     for (int i = 1; i <= n; i++) {       if (i < n) {         int x = get(i + 1, n, 1, 1, n);         if (x < a[i])           cout << 0 <<    ;         else           cout << x - a[i] + 1 <<    ;       } else         cout << 0 <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 100;   int n, sl, res;   int c[maxn][27];   int d[maxn][2], trace[maxn];   vector<int> a[maxn];   vector<string> q;   void init() {     q.clear();     for (int i = 1; i <= sl; i++) {       for (int j = 0; j < 26; j++) {         c[i][j] = 0;       }     }   }   void nhap() {     string s;     cin >> n;     getline(cin, s);     init();     res = 0;     sl = 1;     for (int i = 1; i <= n; i++) {       getline(cin, s);       q.push_back(s);       int root = 1;       for (int j = 0; j < s.size(); j++) {         int x = s[j] -  a ;         if (c[root][x] == 0) {           sl++;           c[root][x] = sl;         }         root = c[root][x];       }     }   }   void taodothi(string s) {     int root = 1;     int root1 = c[1][s[0] -  a ];     if (root1 == 0) return;     for (int i = 1; i < s.size(); i++) {       int x = s[i] -  a ;       root = c[root][x];       root1 = c[root1][x];       if (root1 == 0 || root == 0) {         return;       }       trace[root] = 1;       trace[root1] = 1;       a[root].push_back(root1);       a[root1].push_back(root);     }   }   void dfs(int u) {     trace[u] = 0;     d[u][0] = 0;     d[u][1] = 1;     for (int i = 0; i < a[u].size(); i++) {       int v = a[u][i];       if (trace[v] == 1) {         dfs(v);         d[u][0] += d[v][1];         d[u][1] += min(d[v][0], d[v][1]);       }     }   }   void xuli() {     for (int i = 1; i <= sl; i++) {       a[i].clear();     }     for (int i = 0; i < q.size(); i++) {       taodothi(q[i]);     }     res = sl - 1;     for (int i = 1; i <= sl; i++) {       if (trace[i] == 1) {         dfs(i);         res -= min(d[i][0], d[i][1]);       }     }     cout << res << endl;   }   int main() {     int test;     cin >> test;     while (test--) {       nhap();       xuli();     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x, y, z, xsum(0), ysum(0), zsum(0);     cin >> n;     while (n--) {       cin >> x >> y >> z;       xsum += x;       ysum += y;       zsum += z;     }     if (xsum == 0 && ysum == 0 && zsum == 0) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string to_string(string s) { return     + s +    ; }   string to_string(char s) { return string(1, s); }   string to_string(const char *s) { return to_string((string)s); }   string to_string(bool b) { return (b ?  true  :  false ); }   template <typename A>   string to_string(A);   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename A>   string to_string(A v) {     bool f = 1;     string r =  { ;     for (const auto &x : v) {       if (!f) r +=  ,  ;       f = 0;       r += to_string(x);     }     return r +  } ;   }   void debug_out() { cout << endl; }   void show() { cout << endl; }   void pret() {     cout << endl;     exit(0);   }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cout <<     << to_string(H);     debug_out(T...);   }   template <typename Head, typename... Tail>   void show(Head H, Tail... T) {     cout << H <<    ;     show(T...);   }   template <typename Head, typename... Tail>   void pret(Head H, Tail... T) {     cout << H <<    ;     pret(T...);   }   const long long MOD = 1e9 + 7;   const long long maxn = 300000 + 10;   string s[11];   long long n, m;   bool check(string &t) {     for (long long i = 0; i < n; ++i) {       long long curr = 0;       for (long long j = 0; j < m; ++j) {         curr += (s[i][j] != t[j]);       }       if (curr > 1) return 0;     }     return 1;   }   string f() {     cin >> n >> m;     for (long long i = 0; i < n; ++i) {       cin >> s[i];     }     for (long long i = 0; i < n; ++i) {       string temp = s[i];       for (long long j = 0; j < m; ++j) {         for (long long k = 0; k < 26; ++k) {           char curr = char( a  + k);           temp[j] = curr;           if (check(temp)) {             return temp;           }         }         temp[j] = s[i][j];       }     }     return  -1 ;   }   int32_t main() {     cin.tie(0);     ios_base::sync_with_stdio(0);     ;     long long t;     cin >> t;     while (t--) {       string ans = f();       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, k, d;       cin >> n >> k >> d;       long long int a[n];       for (int i = 0; i < n; i++) {         cin >> a[i];       }       map<int, int> p;       long long int l = 0, size = 0, m = 99999999;       for (int i = 0; i < n; i++) {         if (i < d) {           if (p[a[i]] == 0) {             size++;           }           p[a[i]]++;           if (i == d - 1) {             m = min(m, size);           }         } else {           if (p[a[l]] == 1) {             size--;           }           p[a[l]]--;           l++;           if (p[a[i]] == 0) {             size++;           }           p[a[i]]++;           m = min(m, size);         }       }       cout << m << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int flash_drives[100001];   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) {       scanf( %d , &flash_drives[i]);     }     sort(flash_drives, flash_drives + n, greater<int>());     int l = 0;     int sum = 0;     for (int i = 0; i < n; i++) {       if (sum < m) {         sum += flash_drives[i];         l++;       } else         break;     }     printf( %d  n , l);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, k;     cin >> n >> k;     long long minNumNod = k * (1 + k) / 2;     if (minNumNod > n || k > 1e6) {       cout << -1 << endl;       return 0;     }     long long nod = 1;     for (long long i = 2; i * i <= n; i++) {       if (minNumNod * i > n) break;       if (n % i == 0) {         if (n / i * minNumNod <= n) {           nod = n / i;           break;         } else           nod = i;       }     }     long long numNod = n / nod;     long long ost = numNod - minNumNod;     for (long long i = 1; i < k; i++) {       cout << i * nod <<    ;     }     cout << k * nod + ost * nod << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[1000000];   int main() {     long long n, s;     cin >> n >> s;     for (long long i = 0; i < n; i++) {       long long k, m;       cin >> k >> m;       a[k] = max(a[k], m);     }     long long ans = 0, last = s;     for (long long i = s; i > 0; i--) {       if (a[i]) {         ans = max(ans + last - i, a[i]);         last = i;       }     }     cout << ans + last;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   const int inf = 1 << 30;   int n, t;   int main() {     cin >> n;     int v;     set<int> s;     for (int i = 0; i < n; i++) {       cin >> v;       if (v != 0) s.insert(v);     }     int a = s.size();     if (a != 0)       cout << a << endl;     else       cout << 1 << endl;     return 0;   }
#include <bits/stdc++.h>   inline int getint() {     register char ch;     register bool neg = false;     while (!isdigit(ch = getchar()))       if (ch ==  - ) neg = true;     register int x = ch ^  0 ;     while (isdigit(ch = getchar())) x = (((x << 2) + x) << 1) + (ch ^  0 );     return neg ? -x : x;   }   const int _inf = -0x40000000;   const int N = 30001, K = 201;   int a[N];   int f[N][K][4];   int main() {     int n = getint(), k = getint();     for (register int i = 1; i <= n; i++) {       a[i] = getint();     }     for (register int j = 1; j <= k; j++) {       for (register int k = 0; k <= 3; k++) {         f[0][j][k] = _inf;       }     }     for (register int i = 1; i <= n; i++) {       for (register int j = 1; j <= k; j++) {         const int s = a[i] * ((j != 1 && j != k) ? 2 : 1);         f[i][j][0] = std::max(f[i - 1][j][0], f[i - 1][j - 1][3]) - s;         f[i][j][1] = std::max(f[i - 1][j][1], f[i][j][0]);         f[i][j][2] = std::max(f[i - 1][j][2], f[i - 1][j - 1][1]) + s;         f[i][j][3] = std::max(f[i - 1][j][3], f[i][j][2]);         if (j != 1 && j != k) {           f[i][j][1] = std::max(f[i][j][1], f[i - 1][j - 1][1]);           f[i][j][3] = std::max(f[i][j][3], f[i - 1][j - 1][3]);         }       }     }     printf( %d n , std::max(f[n][k][1], f[n][k][3]));     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:102400000,102400000 )   const int inf = 0x3f3f3f3f;   const long double PI = acos(-1);   using namespace std;   const int N = 1e5 + 10;   int t, n, ans;   char s[N];   int solve() {     for (char c =  a ; c <=  z ; c++) {       int temp = 0, i = 0, j = n - 1;       while (i < j) {         if (s[i] != s[j]) {           if (s[i] == c) {             i++, temp++;           } else if (s[j] == c) {             j--, temp++;           } else {             temp = n + 1;             break;           }         } else {           i++, j--;         }       }       ans = min(ans, temp);     }     if (ans == n + 1)       return -1;     else       return ans;   }   int main() {     ios::sync_with_stdio(false), cin.tie(0);     cin >> t;     while (t--) {       cin >> n;       for (int i = 0; i < n; i++) cin >> s[i];       ans = inf;       cout << solve() << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int N, M, C, a[100009];   int res(int p1, int p2, int p3) {     int s = 0;     if (p1 > p2) s += (p2 - p1);     if (p2 > p3) s += (p3 - p2);     return s;   }   void solve(int s) {     int G;     cin >> G;     if (G <= C / 2) {       for (int i = 1; i <= N; i++) {         if (a[i] == 0 || a[i] > G) {           cout << i << endl;           a[i] = G;           break;         }       }     } else {       for (int i = N; i >= 1; i--) {         if (a[i] == 0 || a[i] < G) {           cout << i << endl;           a[i] = G;           break;         }       }     }   }   bool check() {     for (int i = 1; i <= N - 1; i++) {       if (a[i] > a[i + 1] || a[i] == 0 || a[i + 1] == 0) return false;     }     return true;   }   int main() {     cin >> N >> M >> C;     for (int i = 1; i <= M; i++) {       solve(i);       if (check() == true) break;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       string s;       cin >> s;       int n = s.length();       int m;       cin >> m;       int b[m + 2];       for (int i = 1; i <= m; i++) {         cin >> b[i];       }       char ans[m + 2];       sort(s.begin(), s.end());       map<int, int> mp;       for (int i = 0; i < n; i++) mp[s[i] -  a ]++;       int j = n - 1;       while (true) {         vector<int> v;         int count = 0;         for (int i = 1; i <= m; i++) {           if (b[i] == 0) {             count++;             v.push_back(i);           }         }         if (count == 0) break;         if (mp[s[j] -  a ] < count) {           j = j - mp[s[j] -  a ];           continue;         }         int flag = j;         j = j - mp[s[j] -  a ];         for (int i = 1; i <= m; i++) {           if (b[i] == 0) {             ans[i] = s[flag--];             b[i] = -1;           } else {             for (int k = 0; k < v.size(); k++) {               b[i] = b[i] - abs(i - v[k]);             }           }         }       }       for (int i = 1; i <= m; i++) {         cout << ans[i];       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int heliqi;   int main() {     long long N, M, K;     cin >> N >> M >> K;     long long ans = -1;     if (N + M < K + 2) {       cout <<  -1  << endl;       return 0;     }     long long t = 2;     while (t--) {       if (K < N)         ans = max((N / (K + 1)) * M, ans);       else         ans = max(M / (K - N + 1 + 1), ans);       swap(N, M);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, k, p, i, j, max = 0;     cin >> n >> k >> p;     long long a[n + 1];     long long b[k + 1];     for (i = 1; i <= n; i++) cin >> a[i];     for (i = 1; i <= k; i++) cin >> b[i];     sort(a + 1, a + n + 1);     sort(b + 1, b + k + 1);     long long x;     long long ans = INT_MAX;     for (i = 1; i <= k - n + 1; i++) {       max = 0;       for (long long l = 1; l <= n; l++) {         x = abs(b[i + l - 1] - p) + abs(a[l] - b[i + l - 1]);         if (x > max) max = x;       }       if (max < ans) ans = max;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(NULL);     cin.sync_with_stdio(false);     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int a, b, x, y;       cin >> a >> b >> x >> y;       cout << max(max(((a - 1) - x) * b, ((b - 1) - y) * a), max((x)*b, (y)*a))            <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int x, in;   } arr[210000], qu[210000];   int n, m, k, ans, len;   int head, tail;   int cmp(node a, node b) {     if (a.x == b.x)       return a.in < b.in;     else       return a.x < b.x;   }   int main() {     int i, j, tp;     while (scanf( %d%d%d , &n, &m, &k) != EOF) {       for (i = 1; i <= n; ++i) scanf( %d , &arr[i].x), arr[i].in = i;       sort(arr + 1, arr + 1 + n, cmp);       ans = 1, len = 0;       head = 0, tail = 1;       qu[++head] = arr[1];       for (i = 2; i <= n; ++i) {         if (arr[i].x != qu[head].x) {           while (tail < head) tail++;           len = head = 0;           tail = 1;           qu[++head] = arr[i];         } else {           tp = arr[i].in - qu[head].in - 1;           if (tp + len > k) {             while (tp + len > k && tail < head) {               len -= qu[tail + 1].in - qu[tail].in - 1;               tail++;             }             if (tail == head) len = 0;           }           len += tp;           qu[++head] = arr[i];         }         if (head - tail + 1 > ans) ans = head - tail + 1;       }       printf( %d n , ans);     }   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ii = pair<int, int>;   const int MAXN = 5 + 300000;   const int MAXB = 21;   int n, arr[MAXN], nxt[MAXN][MAXB], memo[MAXN][MAXB];   int dp(int i, int k) {     if (i == n) return n;     int& ans = memo[i][k];     if (ans == -1) {       if (nxt[i][k] == i) {         ans = i;       } else {         ans = n;         assert((arr[i] & (1 << k)) == 0);         for (int j = 0; j < MAXB; ++j) {           if (arr[i] & (1 << j)) {             ans = min(ans, dp(nxt[1 + i][j], k));           }         }       }     }     return ans;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int q;     cin >> n >> q;     memset(nxt, -1, sizeof nxt);     for (int i = (int)0; i < (int)n; ++i) {       int x;       cin >> x;       arr[i] = x;       for (int k = 0; k < MAXB; ++k) {         if (x & (1 << k)) {           nxt[i][k] = i;         }       }     }     memset(memo, -1, sizeof memo);     for (int j = 0; j < MAXB; ++j) {       nxt[n][j] = n;     }     for (int i = n - 1; i >= 0; --i) {       for (int j = 0; j < MAXB; ++j) {         if (nxt[i][j] == -1) {           nxt[i][j] = nxt[1 + i][j];         }       }     }     while (q--) {       int x, y;       cin >> x >> y;       --x;       --y;       bool ans = false;       for (int j = 0; j < MAXB; ++j) {         if ((arr[y] & (1 << j)) && dp(x, j) <= y) {           ans = true;           break;         }       }       cout << (ans ?  Shi  :  Fou ) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     vector<int> v(n);     for (auto &x : v) {       scanf( %d , &x);     }     sort(v.begin(), v.end());     int pos = 0, cnt = 0;     for (int x : v) {       while (pos < n) {         if (v[pos] > x) {           pos++;           cnt++;           break;         }         pos++;       }     }     printf( %d n , cnt);     return 1 == 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, v;     scanf( %d%d , &n, &v);     if (n - v <= 1) {       printf( %d , n - 1);     } else {       printf( %d , (n - v + 1) * (n - v) / 2 + v - 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, i, j;   char cad[1000][1000];   bool marcas[10];   int main() {     bool ok = 1;     scanf( %d%d , &n, &m);     for (i = 0; i < n && ok; i++) {       scanf( %s , cad[i]);       for (j = 1; j < m && ok; j++) ok = cad[i][j] == cad[i][0];     }     for (i = 1; i < n && ok; i++)       for (j = 0; j < m && ok; j++) ok = cad[i][j] != cad[i - 1][j];     printf(ok ?  YES n  :  NO n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int ara[n + 5], ar[n + 5];     ar[0] = INT_MAX;     int j = 1, i, a = 0, b = 1;     for (i = 1; i <= n; ++i) {       cin >> ara[i];       if (ara[i] == 0) ar[j++] = i;     }     ar[j] = INT_MAX;     for (i = 1; i <= n; ++i) {       int temp = min(abs(ar[a] - i), abs(ar[b] - i));       cout << temp <<    ;       if (ara[i] == 0) ++a, ++b;     }     return 0;   }