malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   template <typename T>   bool GetMin(T &a, T b) {     return ((a <= b) ? false : (a = b, true));   }   template <typename T>   bool GetMax(T &a, T b) {     return ((a >= b) ? false : (a = b, true));   }   const int N = 2333;   const long double eps = 1e-8;   int n, m;   long double px[N], py[N], tx, ty, ki[N * N];   bool del[N];   bool Wow(long double x) { return x < -eps || x > eps; }   bool Judge(long double *_p) {     static long double p[N];     memcpy(p + 1, _p + 1, sizeof(long double) * n);     sort(p + 1, p + n + 1);     long double v = p[1] + p[n];     for (int i = 1; i <= n; ++i)       if (Wow(p[i] + p[n - i + 1] - v)) return false;     return true;   }   bool Check(long double ki) {     static long double p[N];     for (int i = 1; i <= n; ++i) p[i] = ki * px[i] + py[i];     return Judge(p);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %Lf%Lf , px + i, py + i);       tx += px[i];       ty += py[i];     }     tx /= n;     ty /= n;     for (int i = 1; i <= n; ++i)       if (!del[i])         for (int j = i + 1; j <= n; ++j)           if (!Wow(2 * tx - px[i] - px[j]) && !Wow(2 * ty - py[i] - py[j])) {             del[i] = true;             del[j] = true;             break;           }     int cnt = 0;     for (int i = 1; i <= n; ++i)       if (!del[i]) {         px[++cnt] = px[i];         py[cnt] = py[i];       }     n = cnt;     for (int i = 1; i <= n; ++i)       for (int j = i + 1; j <= n; ++j) {         long double x = py[i] + py[j] - 2 * ty, y = 2 * tx - px[i] - px[j];         if (Wow(x) && Wow(y)) ki[++m] = x / y;       }     if (n <= 2) {       puts( -1 );       return 0;     }     sort(ki + 1, ki + m + 1);     int ans = Judge(px) + Judge(py);     ki[m + 1] = 1e100;     for (int i = 2, cnt = 1; i <= m + 1; ++i) {       if (Wow(ki[i] - ki[i - 1])) {         if (cnt >= (n >> 1)) ans += Check(ki[i - 1]);         cnt = 1;       } else         ++cnt;     }     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MAX = 2e6 + 99;   const long long INF = 1e12;   const long long mod = 1e9 + 7;   set<pair<long long, long long>> dif;   set<pair<long long, long long>>::iterator it;   long long N, M, row[1000], col[1000], mark[500][500], imp[500][500],       arr[500][500];   void dfs() {     row[1] = 0;     for (long long A = 1; A <= M; A++) {       if (mark[1][A])         col[A] = 1 - row[1];       else         col[A] = row[1];     }     for (long long A = 2; A <= N; A++) {       if (mark[A][1])         row[A] = 1 - col[1];       else         row[A] = col[1];     }     dif.clear();     for (long long A = 2; A <= N; A++)       for (long long B = 2; B <= M; B++)         if (abs(col[B] - row[A]) != mark[A][B]) dif.insert(make_pair(A, B));     return;   }   void out_() {     cout <<  YES n ;     for (long long A = 1; A <= N; A++) cout << row[A];     cout <<   n ;     for (long long A = 1; A <= M; A++) cout << col[A];     exit(0);   }   signed main() {     ios_base::sync_with_stdio(false);     cin >> N >> M;     for (long long A = 1; A <= N; A++)       for (long long B = 1; B <= M; B++) cin >> arr[A][B];     for (long long A = 1; A <= N; A++) {       for (long long B = 1; B <= M; B++) {         if (!arr[A][B])           mark[A][B] = 1;         else           mark[A][B] = 0;       }     }     for (long long A = 1; A <= M; A++) imp[1][A] = 1;     for (long long A = 1; A <= N; A++) imp[A][1] = 1;     dfs();     if (dif.empty()) out_();     for (long long A = 1; A <= N; A++) {       for (long long B = 1; B <= M; B++) {         mark[A][B] = 1 - mark[A][B];         if (imp[A][B]) {           dfs();           if (dif.empty())             out_();           else {             it = dif.end();             it--;             if (dif.begin()->first == A and it->first == A) {               for (auto A : dif) mark[A.first][A.second] ^= 1;               out_();             }           }         }       }     }     cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[100005];   set<int> b;   set<int>::iterator it;   int main() {     long long n, i, s, x, y, z, d, st;     scanf( %lld , &n);     for (i = 0; i < n; i++) {       scanf( %lld , &x);       b.insert(x);     }     n = 0;     for (it = b.begin(); it != b.end(); it++) a[n++] = *it;     scanf( %lld%lld , &x, &y);     s = 0;     st = 0;     while (y < x) {       z = x - 1;       for (i = n - 1; i >= st; i--) {         d = x - x % a[i];         if (z > d && d >= y) z = d;       }       x = z;       while (n > st && x - x % a[st] < y) st++;       while (n > 0 && x - x % a[n - 1] < y) n--;       s++;     }     printf( %lld n , s);     return 0;   }
#include <bits/stdc++.h>   #pragma GCC_OPTIMIZE( ofast )   using namespace std;   void solve() {     long long n, k;     cin >> n >> k;     string s;     cin >> s;     string need;     for (long long i = 0; i < k - 1; i++) {       need.push_back( ( );       need.push_back( ) );     }     for (long long i = 0; i < n / 2 - (k - 1); i++) {       need.push_back( ( );     }     for (long long i = 0; i < n / 2 - (k - 1); i++) {       need.push_back( ) );     }     vector<pair<long long, long long>> ans;     for (long long i = 0; i < n; i++) {       if (s[i] != need[i]) {         for (long long j = i + 1; j < n; j++) {           if (s[j] == need[i]) {             ans.push_back(make_pair(i + 1, j + 1));             reverse(s.begin() + i, s.begin() + j + 1);             break;           }         }       }     }     cout << ans.size() <<   n ;     for (long long i = 0; i < ans.size(); i++) {       cout << ans[i].first <<     << ans[i].second <<   n ;     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long q;     cin >> q;     for (long long i = 0; i < q; i++) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   struct edge {     int index;     int disc, exit;     int val;     int depth;   };   int n, m;   edge e[200010];   vector<int> V[200010];   int disc = 1;   void calc_disc(int curr, int par, int depth) {     e[curr].disc = disc++;     e[curr].depth = depth;     for (int i = 0; i < V[curr].size(); i++) {       int next = V[curr][i];       if (next == par) continue;       calc_disc(next, curr, depth + 1);     }     e[curr].exit = disc++;   }   bool pro(const edge &e1, const edge &e2) { return e1.disc < e2.disc; }   int loga1[200010 * 2], loga2[200010 * 2];   int index_inv[200010];   void update(int x, int val, int log[]) {     for (; x < 200010 * 2; x += x & -x) log[x] += val;   }   int read(int x, int log[]) {     int rez = 0;     for (; x > 0; x -= x & -x) {       rez += log[x];     }     return rez;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %d , &e[i].val);       e[i].index = i;     }     for (int i = 0; i < n - 1; i++) {       int p1, p2;       scanf( %d%d , &p1, &p2);       V[p1].push_back(p2);       V[p2].push_back(p1);     }     calc_disc(1, -1, 1);     sort(e + 1, e + n + 1, pro);     for (int i = 1; i <= n; i++) {       index_inv[e[i].index] = i;     }     for (int i = 0; i < m; i++) {       int p;       scanf( %d , &p);       if (p == 1) {         int x, val;         scanf( %d%d , &x, &val);         edge tmp = e[index_inv[x]];         if (tmp.depth % 2 == 1) val *= -1;         update(tmp.disc, val, loga1);         update(tmp.disc, -val, loga2);         update(tmp.exit, -val, loga1);         update(tmp.exit, val, loga2);       }       if (p == 2) {         int x;         scanf( %d , &x);         edge tmp = e[index_inv[x]];         if (tmp.depth % 2 == 0)           printf( %d n , read(tmp.disc, loga1) + tmp.val);         else           printf( %d n , read(tmp.disc, loga2) + tmp.val);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int tab[100][100];   int seed = 1304104130;   int abs(int x) {     if (x < 0)       return -x;     else       return x;   }   int rand() { return seed = abs(seed * 12493LL + 142412 % 1000000009); }   int best(int a) {     int last = -1;     for (int i = 1; i * i < a; ++i) {       if (a % i == 0 && (a / i - i) % 2 == 0) last = (a / i - i) / 2;     }     return last;   }   bool issq(int x) {     int min = 0, max = x;     while (min <= max) {       long long int med = (min + max) / 2;       if (med * med == x)         return true;       else if (med * med > x)         max = med - 1;       else         min = med + 1;     }     return false;   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     if (n == 1 && m == 1) {       printf( 1 n );       return 0;     } else if (n == 1) {       for (int i = 0; i < m - 1; ++i) printf( 3  );       printf( %d n , best(9 * (m - 1)));       return 0;     } else if (m == 1) {       for (int i = 0; i < n - 1; ++i) printf( 3 n );       printf( %d n , best(9 * (n - 1)));       return 0;     }     while (true) {       for (int i = 0; i < n - 1; ++i)         for (int k = 0; k < m - 1; ++k) tab[i][k] = rand() % 3 * 8 + 8;       for (int i = 0; i < n - 1; ++i) {         int sum = 0;         for (int k = 0; k < m - 1; ++k) sum += tab[i][k] * tab[i][k];         tab[i][m - 1] = 2 * best(sum / 4);       }       for (int k = 0; k < m - 1; ++k) {         int sum = 0;         for (int i = 0; i < n - 1; ++i) sum += tab[i][k] * tab[i][k];         tab[n - 1][k] = 2 * best(sum / 4);       }       int sum1 = 0, sum2 = 0;       for (int i = 0; i < n - 1; ++i) sum1 += tab[i][m - 1] * tab[i][m - 1];       for (int k = 0; k < m - 1; ++k) sum2 += tab[n - 1][k] * tab[n - 1][k];       for (int div = 1; div * div < sum1; ++div)         if (sum1 % div == 0 && (div + sum1 / div) % 2 == 0) {           int r = (sum1 / div - div) / 2;           if (issq(r * r + sum2)) {             tab[n - 1][m - 1] = r;             for (int i = 0; i < n; ++i) {               for (int k = 0; k < m; ++k) printf( %d  , tab[i][k]);               putchar(10);             }             return 0;           }         }     }   }
#include <bits/stdc++.h>   using namespace std;   map<long long, int> mp;   int a[100001], b[100001];   int main() {     int n, i;     cin >> n;     for (i = 1; i <= n; i++) cin >> a[i];     for (i = 1; i <= n; i++) cin >> b[i];     if (a[1] != b[1] || a[n] != b[n]) {       cout <<  No ;       return 0;     }     for (i = 1; i < n; i++) mp[b[i + 1] - b[i]]++;     for (i = 1; i < n; i++)       if (!mp[a[i + 1] - a[i]]--) {         cout <<  No ;         return 0;       }     cout <<  Yes ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string t, s;     cin >> n >> s;     t = s;     sort(s.begin(), s.end());     int ret = (1 << 21);     for (int i = 0; i < s.length() + 1; i++) {       int dif = 0;       for (int i = 0; i < s.length(); i++) {         if (t[i] != s[i]) dif++;       }       ret = min(ret, dif);       rotate(s.begin(), s.begin() + 1, s.end());     }     cout << ret / 2 << endl;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     string s;     cin >> s;     vector<string> s1;     for (int i = 0; i < int((s).size()); i++) {       string s2(int((s).size()) - i,  0 );       if (s[i] !=  0 ) {         s2[0] = s[i];         s1.push_back(s2);       }     }     cout << s1.size() <<   n ;     for (auto i : s1) {       cout << i <<    ;     }     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long t = 1;     cin >> t;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int dis(int x, int y) { return (x * x + y * y); }   int main() {     int d, n, i, x, y, r, cnt = 0, R1, R2;     cin >> r >> d;     R1 = r;     R2 = r - d;     cin >> n;     while (n--) {       cin >> x >> y >> r;       d = dis(x, y);       if (d <= ((R1 - r) * (R1 - r)) && d >= ((R2 + r) * (R2 + r))) {         cnt++;       }     }     cout << cnt << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Position {     int r, c, t;     Position(int r, int c, int t) {       this->r = r;       this->c = c;       this->t = t;     }   };   int main() {     vector<string> board;     vector<pair<int, int> > s;     for (int r = 0; r < 8; r++) {       string line;       cin >> line;       board.push_back(line);       for (int c = 0; c < 8; c++)         if (line[c] ==  S ) s.push_back(make_pair(r, c));     }     queue<Position> que;     que.push(Position(7, 0, 0));     int dr[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};     int dc[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};     while (!que.empty()) {       Position pos = que.front();       que.pop();       if (pos.t > 7) break;       for (int i = 0; i < 9; i++) {         int nr = pos.r + dr[i];         int nc = pos.c + dc[i];         if (0 <= nr && nr < 8 && 0 <= nc && nc < 8) {           bool isCollision = false;           for (int j = 0; j < (int)s.size(); j++) {             if ((nr == s[j].first + pos.t && nc == s[j].second) ||                 (nr == s[j].first + pos.t + 1 && nc == s[j].second)) {               isCollision = true;               break;             }           }           if (!isCollision) {             que.push(Position(nr, nc, pos.t + 1));           }         }       }     }     cout << (que.empty() ?  LOSE  :  WIN ) << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int sz, ans = 0, cnt = 0;     cin >> s;     sz = s.size();     ans = sz;     for (int i = 0; i < sz; i++)       if (s[i] ==  a ) cnt++;     while (cnt < ((ans / 2) + 1)) ans--;     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m, q;     cin >> n >> m >> q;     vector<long long> a(n, 0);     for (int i = 0; i < n; ++i) cin >> a[i];     vector<int> weights(m, 0);     vector<int> heavyListsIds;     vector<vector<int> > lists(m, vector<int>());     int heavyBorder = ceil(sqrt(0.0 + n));     int heavyCount = 0;     for (int i = 0; i < m; ++i) {       int length;       cin >> length;       if (length > heavyBorder) {         weights[i] = 42;         ++heavyCount;         heavyListsIds.push_back(i);       } else         weights[i] = 1;       lists[i].resize(length);       for (int j = 0; j < length; ++j) cin >> lists[i][j], --lists[i][j];       sort((lists[i]).begin(), (lists[i]).end());     }     vector<vector<int> > intersectionSize(m, vector<int>(heavyCount, 0));     for (int i = 0; i < (lists).size(); ++i)       for (int j = 0; j < (heavyListsIds).size(); ++j) {         int first = i, second = heavyListsIds[j];         if (first == second) continue;         if ((lists[first]).size() > (lists[second]).size()) {           int temp = first;           first = second;           second = temp;         }         for (int k = 0; k < (lists[first]).size(); ++k)           if (binary_search(lists[second].begin(), lists[second].end(),                             lists[first][k]))             ++intersectionSize[first][j];       }     vector<long long> cachedResults(heavyCount, 0), cachedUpdates(heavyCount, 0);     for (int i = 0; i < heavyCount; ++i) {       int listId = heavyListsIds[i];       for (int j = 0; j < (lists[listId]).size(); ++j)         cachedResults[i] += a[lists[listId][j]];     }     for (int i = 0; i < q; ++i) {       char c;       cin >> c;       if (c ==  + ) {         long long k, x;         cin >> k >> x;         --k;         if (weights[k] == 42) {           int heavy_k = 0;           for (int j = 0; j < heavyCount; ++j)             if (heavyListsIds[j] == k) {               heavy_k = j;               break;             }           cachedUpdates[heavy_k] += x;         } else {           for (int j = 0; j < (lists[k]).size(); ++j) a[lists[k][j]] += x;           for (int j = 0; j < heavyCount; ++j)             cachedResults[j] += intersectionSize[k][j] * x;         }       } else {         int k;         cin >> k;         --k;         if (weights[k] == 1) {           long long result = 0;           for (int j = 0; j < (lists[k]).size(); ++j) result += a[lists[k][j]];           for (int j = 0; j < heavyCount; ++j)             result += intersectionSize[k][j] * cachedUpdates[j];           cout << result << endl;         } else {           int heavy_k = 0;           for (int j = 0; j < heavyCount; ++j)             if (heavyListsIds[j] == k) {               heavy_k = j;               break;             }           long long result =               cachedResults[heavy_k] + cachedUpdates[heavy_k] * (lists[k]).size();           for (int j = 0; j < heavyCount; ++j)             result += intersectionSize[k][j] * cachedUpdates[j];           cout << result << endl;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   T expo(T e, T n) {     T x = 1, p = e;     while (n) {       if (n & 1) x = x * p;       p = p * p;       n >>= 1;     }     return x;   }   template <typename T>   T power(T e, T n, T m) {     T x = 1, p = e;     while (n) {       if (n & 1) x = (x * p) % m;       p = (p * p) % m;       n >>= 1;     }     return x;   }   template <typename T>   T InverseEuler(T a, T m) {     return (a == 1 ? 1 : power(a, m - 2, m));   }   template <typename T>   T gcd(T a, T b) {     while (a %= b ^= a ^= b ^= a)       ;     return b;   }   template <typename T>   T lcm(T a, T b) {     return (a * (b / gcd(a, b)));   }   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   map<string, long long> M;   map<long long, string> invM;   long long n = 1;   vector<long long> g[5000], temp;   bool vis[5000];   long long in[5000], out[5000];   vector<pair<string, string> > ans;   void dfs(long long node) {     vis[node] = true;     temp.push_back(node);     for (auto it : g[node]) {       if (!vis[it]) {         dfs(it);       }     }     return;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long q;     cin >> q;     for (__typeof(q) i = 1; i <= q; ++i) {       string s, second;       cin >> s >> second;       if (M.find(s) == M.end()) {         M[s] = n;         invM[n] = s;         n++;       }       if (M.find(second) == M.end()) {         M[second] = n;         invM[n] = second;         n++;       }       g[M[s]].push_back(M[second]);       in[M[second]] += 1;       out[M[s]] += 1;     }     long long components = 0;     for (__typeof(n - 1) i = 1; i <= n - 1; ++i) {       if (!vis[i]) {         components++;         temp.clear();         dfs(i);         string A, B;         for (auto it : temp) {           if (in[it] == 0) A = invM[it];           if (out[it] == 0) B = invM[it];         }         ans.push_back({A, B});       }     }     cout << components <<   n ;     for (auto it : ans) {       cout << it.first <<     << it.second <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   int n, i;   char s[100005];   long long a[270], r;   int main() {     scanf( %s , s);     n = strlen(s);     for (i = 0; i < n; i++) a[s[i]]++;     for (i = 0; i < 270; i++) r += a[i] * a[i];     printf( %I64d n , r);   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   T mceil(T a, T b) {     if (a % b == 0)       return a / b;     else       return a / b + 1;   }   const long long int M = 1e9 + 7;   const long long int N = 2e5 + 5;   const long long int inf = 9e18;   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);     long long int n, m;     cin >> n >> m;     vector<long long int> a(n), b(m);     map<long long int, long long int> mp;     vector<pair<long long int, long long int> > v;     long long int am = -1;     long long int ans = 0;     for (long long int i = 0; i < n; i++) {       cin >> a[i];       am = max(a[i], am);       ans += a[i] * m;       v.push_back({a[i], m - 1});     }     for (long long int i = 0; i < m; i++) cin >> b[i];     sort((v).rbegin(), (v).rend());     vector<long long int> g;     for (long long int i = 0; i < m; i++) {       if (b[i] < am) {         cout << -1 <<   n ;         return 0;       } else if (b[i] == am)         continue;       else {         g.push_back(b[i]);       }     }     sort((g).rbegin(), (g).rend());     long long int ind = 0;     for (long long int i = 0; i < (int)((g).size()); i++) {       if (ind < n and v[ind].second) {         ans += g[i] - v[ind].first;         v[ind].second--;         if (v[ind].second == 0) ind++;       } else {         cout << -1;         return 0;       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x7fffffff;   int a[2010];   int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }   int main() {     int n, count = 0;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       if (a[i] == 1) ++count;     }     if (count) {       printf( %d , n - count);     } else {       int t = INF;       int i, j;       for (i = 1; i <= n; ++i) {         int x = a[i];         for (j = i + 1; j <= n; ++j) {           x = gcd(x, a[j]);           if (x == 1) {             t = min(t, j - i + 1);             break;           }         }       }       if (t == INF) {         puts( -1 );       } else {         printf( %d n , t - 1 + n - 1);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   int n;   pair<int, int> a[N];   void rec(int l, int r) {     if (l >= r) {       return;     }     int mid = (r + l) >> 1;     rec(l, mid);     rec(mid + 1, r);     for (int i = l; i <= r; i++) {       n++;       a[n] = make_pair(a[mid].first, a[i].second);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i].first >> a[i].second;     }     sort(a + 1, a + n + 1);     rec(1, n);     sort(a + 1, a + n + 1);     n = unique(a + 1, a + n + 1) - a - 1;     cout << n <<   n ;     for (int i = 1; i <= n; i++) {       cout << a[i].first <<     << a[i].second <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int higherR(int candies[], int index, int n, int c) {     int counter = 0;     for (int i = index + 1; i < n; i++) {       if (candies[i] > candies[index] && candies[i] != c) {         counter++;       }     }     return counter;   }   int higherL(int candies[], int index, int n, int c) {     int counter = 0;     for (int i = index - 1; i >= 0; i--) {       if (candies[i] > candies[index] && candies[i] != c) {         counter++;       }     }     return counter;   }   int main() {     int n;     cin >> n;     int l[n], r[n];     for (int i = 0; i < n; i++) {       cin >> l[i];     }     for (int i = 0; i < n; i++) {       cin >> r[i];     }     int candies[n];     for (int i = 0; i < n; i++) {       candies[i] = -1;     }     int currentNumberOfCandies = n - 1;     int childrenFed = 0;     bool contradiction = true;     for (int i = 0; i < n; i++) {       if (l[i] == 0 && r[i] == 0) {         candies[i] = n;         ++childrenFed;         contradiction = false;       }     }     if (contradiction) {       cout <<  NO ;       return 0;     }     while (childrenFed < n) {       if (currentNumberOfCandies < 1) {         cout <<  NO ;         return 0;       }       for (int i = 0; i < n; i++) {         if (candies[i] != -1) {           continue;         }         if (higherL(candies, i, n, currentNumberOfCandies) > l[i] ||             higherR(candies, i, n, currentNumberOfCandies) > r[i]) {           cout <<  NO ;           return 0;         }         if (higherL(candies, i, n, currentNumberOfCandies) == l[i] &&             higherR(candies, i, n, currentNumberOfCandies) == r[i]) {           candies[i] = currentNumberOfCandies;           ++childrenFed;         }       }       --currentNumberOfCandies;     }     cout <<  YES  << endl;     for (int i = 0; i < n; i++) {       cout << candies[i] <<    ;     }     return 0;   }