malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   char str[100003];   struct Node {     int val;     int val2;     Node* pt[26];   } node[100003];   int cnt;   int mex(Node* node) {     if (node->val != -1) return node->val;     int f[30] = {};     for (int i = 0; i < 26; ++i)       if (node->pt[i]) f[mex(node->pt[i])] = 1;     for (int i = 0; i < 30; ++i)       if (f[i] == 0) return node->val = i;   }   int mex2(Node* node) {     if (node->val2 != -1) return node->val2;     int f[30] = {};     int flag = 0;     for (int i = 0; i < 26; ++i)       if (node->pt[i]) {         f[mex2(node->pt[i])] = 1;         flag = 1;       }     if (!flag) return node->val2 = 1;     for (int i = 0; i < 30; ++i)       if (f[i] == 0) return node->val2 = i;   }   int main() {     cnt = 27;     int N, K;     cin >> N >> K;     for (int i = 0; i < 100003; ++i) node[i].val = node[i].val2 = -1;     for (int i = 0; i < N; ++i) {       cin >> str;       Node* now = node;       now->pt[str[0] -  a ] = node + str[0] -  a  + 1;       for (int j = 0; str[j]; ++j)         if (now->pt[str[j] -  a ])           now = now->pt[str[j] -  a ];         else           now = now->pt[str[j] -  a ] = node + cnt++;     }     if (mex(node) == 0)       cout <<  Second  << endl;     else if (K % 2 == 1 || mex2(node))       cout <<  First  << endl;     else       cout <<  Second  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct pairvar {     int a;     int b;     int c;     int max;   };   bool isPrime(long long x) {     if (x == 1) {       return false;     }     long long a = (long long)x;     for (int i = 2; i <= (long long)sqrt((double)a); i++) {       if (a % i == 0) {         return false;       }     }     return true;   }   int gcd(int a, int b) {     if (b == 0) {       return a;     }     return gcd(b, a % b);   }   long long factorial(long long x) {     long long sum = 1;     for (long long i = 1; i <= x; i++) {       sum *= i;     }     return sum;   }   string tostr(int x) {     string s =   ;     while (x != 0) {       s += (x % 10) +  0 ;       x /= 10;     }     string t =   ;     for (int i = s.length() - 1; i >= 0; i--) {       t += s[i];     }     return t;   }   bool cmp(const pairvar &a, const pairvar &b) {     if (a.a == b.a) return a.b < b.b;     return a.a < b.a;   }   int calc(int a, int b) { return (a * b) / gcd(a, b); }   int main() {     string s;     cin >> s;     int ans = 1;     int k = s.size() - 1;     int j = 1;     for (int i = s.size() - 1; i >= 0; i--) {       if (s[i] ==  0 ) {         k--;         j++;       } else {         if (k > j) {           ans++;           k--;           j = 1;         } else if (k == j) {           if (s[0] >= s[i]) {             j = 1;             k--;             ans++;           } else {             j++;             k--;           }         }       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, sum = 0;     cin >> n;     vector<long long> arr(n + 1);     for (long long i = 1; i <= n; i++) cin >> arr[i], sum += arr[i];     map<pair<long long, long long>, long long> ma;     long long m, a, b, c;     cin >> m;     while (m--) {       cin >> a >> b >> c;       if (!ma.count({a, b})) {         if (c > 0) {           arr[c]--;           if (arr[c] >= 0) sum--;         }       } else {         long long temp = ma[{a, b}];         arr[temp]++;         if (arr[temp] > 0) sum++;         if (c > 0) {           arr[c]--;           if (arr[c] >= 0) sum--;         } else {           ma.erase(ma.find({a, b}));         }       }       if (c != 0) ma[{a, b}] = c;       cout << sum << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const bool testing = false;   pair<long long, long long> d[100000];   int nf[100000], nb[100000];   pair<long long, long long> getmid(int a, int b) {     long long y = d[b].second - d[a].second;     long long x = d[b].first - d[a].first;     pair<long long, long long> res =         make_pair(-y + x * x + 2 * x * d[a].first, 2 * x);     return res;   }   void program() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       long long t1, t2;       cin >> t1 >> t2;       d[i] = make_pair(t1, t2);     }     std::sort(d, d + n);     int start = 0;     while (start + 1 < n && d[start + 1].first == d[start].first) start++;     {       nb[start] = -1;       int prev = start;       while (prev < n) {         int t = prev + 1;         while (t + 1 < n && d[t + 1].first == d[t].first) t++;         if (t < n) nb[t] = prev;         nf[prev] = t;         prev = t;       }     }     {       int t1 = start;       while (true) {         int t2 = nf[t1];         if (t2 == n) break;         int t3 = nf[t2];         if (t3 == n) break;         pair<long long, long long> A1 = getmid(t1, t2);         pair<long long, long long> A2 = getmid(t1, t3);         if (A2.first * A1.second <= A1.first * A2.second) {           nf[t1] = t3;           nb[t3] = t1;           if (nb[t1] != -1) t1 = nb[t1];         } else           t1 = nf[t1];       }     }     long long res = 0;     {       int t = start;       while (nf[t] != n) {         res++;         t = nf[t];       }     }     cout << res;   }   int main() {     if (!testing) {       program();       return 0;     }     FILE* fin = NULL;     fin = fopen( in.txt ,  w+ );     fprintf(fin,   n3 n-1 0 n0 2 n1 0 n );     fclose(fin);     freopen( in.txt ,  r , stdin);     printf( test case(1) => expected :  n );     printf( 2 );     printf( test case(1) => found    :  n );     program();     fin = fopen( in.txt ,  w+ );     fprintf(fin,   n5 n1 0 n1 -1 n0 -1 n-1 0 n-1 -1 n );     fclose(fin);     freopen( in.txt ,  r , stdin);     printf( test case(2) => expected :  n );     printf( 1 );     printf( test case(2) => found    :  n );     program();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int arr[n];     long long sum = 0;     for (int i = 0; i < n; i++) {       cin >> arr[i];       sum += arr[i];     }     if (sum % 2 != 0) {       sum++;     }     long long sum1 = 0;     for (int i = 0; i < n; i++) {       sum1 += arr[i];       if (sum1 >= (sum / 2)) {         cout << i + 1 << endl;         return 0;       }     }   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   T abs(T x) {     if (x < 0) return -x;     return x;   }   template <class T>   T sqr(T a) {     return a * a;   }   const double pi = acos(-1.0);   const double eps = 1e-8;   int a[100010];   int a1[100010];   int a2[100010];   int b;   int ar[100010];   int flag[100010];   int main() {     int i, n, m, k;     while (2 == scanf( %d%d , &n, &m)) {       int cnt = 0;       for (i = 1; i <= n + m; i++) {         if (i <= n)           scanf( %d , &a1[i]);         else           scanf( %d , &a2[i - n]);       }       k = 0;       for (i = 1; i <= n + m; i++) {         scanf( %d , &b);         if (b == 1) {           cnt++;           if (i <= n)             ar[cnt] = a1[i];           else             ar[cnt] = a2[i - n];         } else {           ++k;           if (i <= n)             a[k] = a1[i];           else             a[k] = a2[i - n];         }       }       k = 1;       for (i = 1; i <= n; i++) {         if (k + 1 <= cnt) {           if (abs(a[i] - ar[k]) <= abs(a[i] - ar[k + 1]))             flag[k]++;           else {             k++;             i--;           }         } else           flag[k]++;       }       for (i = 1; i <= cnt; i++) printf( %d  , flag[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   ifstream in;   ofstream out;   const long long kk = 1000;   const long long MOD = 10e9 + 7;   long long a, b, x, y;   long long GCD(long long n, unsigned long long m) {     while (n != 0 && m != 0) {       if (n > m) {         n %= m;       } else {         m %= n;       }     }     return (n + m);   }   int main() {     ios_base::sync_with_stdio(0);     cin >> a >> b >> x >> y;     long long x1, y1;     long long k = GCD(x, y);     x /= k;     y /= k;     cout << min(a / x, b / y);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200000 + 5;   int n, ex, ey;   char s[MAXN];   struct node {     int x, y;     node() {}     node(int _x, int _y) : x(_x), y(_y) {}   } p[MAXN];   bool OK(int t) {     for (int i = 0; i + t <= n; i++) {       int px = p[i].x - p[0].x + p[n].x - p[i + t].x;       int py = p[i].y - p[0].y + p[n].y - p[i + t].y;       int tx = ex - px;       int ty = ey - py;       if (abs(tx) + abs(ty) <= t) {         return true;       }     }     return false;   }   int main() {     while (~scanf( %d , &n)) {       scanf( %s , s + 1);       scanf( %d%d , &ex, &ey);       if ((n - abs(ex) - abs(ey)) < 0) {         printf( -1 n );         continue;       }       if ((n - abs(ex) - abs(ey)) & 1) {         printf( -1 n );         continue;       }       p[0] = node(0, 0);       for (int i = 1; i <= n; i++) {         if (s[i] ==  U ) {           p[i] = node(p[i - 1].x, p[i - 1].y + 1);         } else if (s[i] ==  D ) {           p[i] = node(p[i - 1].x, p[i - 1].y - 1);         } else if (s[i] ==  L ) {           p[i] = node(p[i - 1].x - 1, p[i - 1].y);         } else if (s[i] ==  R ) {           p[i] = node(p[i - 1].x + 1, p[i - 1].y);         }       }       int l = 0, r = n;       while (l <= r) {         int mid = (l + r) >> 1;         if (OK(mid)) {           r = mid - 1;         } else {           l = mid + 1;         }       }       printf( %d n , r + 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int mod = 1e9 + 7;     cin >> s;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  w  || s[i] ==  m ) {         cout << 0;         return 0;       }     }     int a, b = 1, c = 0;     for (int i = 0; i < s.length(); i++) {       if (s[i] == s[i - 1] && (s[i] ==  n  || s[i] ==  u )) {         a = (b + c) % mod;       } else         a = b;       c = b;       b = a;     }     cout << a;   }
#include <bits/stdc++.h>   using namespace std;   long long mulMod(long long a, long long b, long long m = 1000000007) {     long long x = 0, y = a % m;     while (b > 0) {       if (b % 2 == 1) x = (x + y) % m;       y = (y * 2) % m;       b /= 2;     }     return x % m;   }   long long expMod(long long b, long long e, long long m = 1000000007) {     if (!e) return 1;     long long q = expMod(b, e / 2, m);     q = mulMod(q, q, m);     return e % 2 ? mulMod(b, q, m) : q;   }   long long invFact[20], fact[20];   long long inverso(long long x) { return expMod(x, 1000000007 - 2); }   void pre() {     fact[0] = 1;     for (int i = (1); i < (20 - 2); i++) fact[i] = (fact[i - 1] * i) % 1000000007;     invFact[20 - 3] = inverso(fact[20 - 3]);     for (int i = 20 - 3 - 1; i >= 0; i--)       invFact[i] = (invFact[i + 1] * (i + 1)) % 1000000007;     return;   }   long long comb(long long nn, long long k) {     if (k < 0 || nn < k) return 0;     return (fact[nn] * invFact[k] % 1000000007) * invFact[nn - k] % 1000000007;   }   int n;   long long win[15][15];   long long get(int mask1, int mask2) {     long long ret = 1;     for (int i = (0); i < (n); i++) {       if ((mask1 >> i) & 1) {         for (int j = (0); j < (n); j++) {           if ((mask2 >> j) & 1) {             ret = ((ret * win[i][j] % 1000000007) + 1000000007) % 1000000007;             assert(ret >= 0);           }         }       }     }     return ret;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n;     vector<long long> a(n);     for (int i = (0); i < (n); i++) cin >> a[i];     for (int i = (0); i < (n); i++)       for (int j = (0); j < (n); j++)         win[i][j] = (((a[i] * inverso(a[i] + a[j])) % 1000000007) + 1000000007) %                     1000000007;     vector<long long> proba(1 << n, 1);     long long rta = 0;     for (int mask = 1; mask < (1 << n); mask++) {       for (int submask = mask & (mask - 1); submask;            submask = (submask - 1) & mask) {         proba[mask] -= proba[submask] * get(submask, mask ^ submask);         proba[mask] = ((proba[mask] % 1000000007) + 1000000007) % 1000000007;         assert(proba[mask] >= 0);       }       rta += ((__builtin_popcount(mask) * proba[mask]) % 1000000007 *               get(mask, ((1 << n) - 1) ^ mask)) %              1000000007;       rta = ((rta % 1000000007) + 1000000007) % 1000000007;     }     cout << rta <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char first[100001], second[100001], zero[100001];   int number1[10], number2[10];   int just_zero() {     char *p1 = first, *p2 = second;     while (number1[0]--) *p1++ = *p2++ =  0 ;     return p1 - first;   }   int summary_ten(int count) {     int min_rez = -1;     int t = 0;     for (int i = 1; i < 6; i++) {       if (number1[i] && number2[10 - i]) {         int now_rez = min(number1[i], number2[9 - i]) +                       min(number2[10 - i], number1[i - 1]) -                       min(number1[i] - 1, number2[9 - i]) -                       min(number2[10 - i] - 1, number1[i - 1]);         if (now_rez < min_rez || min_rez == -1) {           t = i;           min_rez = now_rez;         }       }     }     if (t) {       number1[t]--;       number2[10 - t]--;       first[count] = t +  0 ;       second[count] = (10 - t) +  0 ;       return count + 1;     }     return count;   }   int summary_nine(int count) {     char *p1 = &first[count], *p2 = &second[count];     for (int i = 0; i < 10; i++) {       int t1 = number1[9 - i];       int t2 = number2[i];       while (t1 * t2) {         *p1++ = (9 - i) +  0 ;         *p2++ = i +  0 ;         t1--;         t2--;         number1[9 - i]--;         number2[i]--;       }     }     return p1 - first;   }   int what_else(int count) {     char *zero_p = zero;     while (number1[0] * number2[0]) {       *zero_p++ =  0 ;       number1[0]--;       number2[0]--;     }     char *p1 = &first[count], *p2 = &second[count];     for (int i = 0; i < 10; i++) {       while (number1[i]) {         *p1++ = i +  0 ;         number1[i]--;       }       while (number2[i]) {         *p2++ = i +  0 ;         number2[i]--;       }     }     return p1 - first;   }   void print_screen(int count) {     char *p1 = first + count, *p2 = second + count;     while (true) {       printf( %c , *p1);       if (p1 == first) break;       *p1--;     }     printf( %s n , zero);     while (true) {       printf( %c , *p2);       if (p2 == second) break;       *p2--;     }     printf( %s , zero);     return;   }   void maximum_sum() {     int count1 = summary_ten(0);     int count2 = count1;     if (count1) count2 = summary_nine(count1);     int count3 = what_else(count2);     print_screen(count3 - 1);     return;   }   int main() {     char str[100001];     scanf( %s , &str);     char *p = &str[0];     while (*p) {       number2[*p -  0 ]++;       number1[(*p++) -  0 ]++;     }     maximum_sum();     scanf( %s , &str);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 2000;   long long calcula(long long l, long long r, long long k) {     long long d1 = -r;     long long d2 = l - r;     long long aum = d2 - d1;     long long lim1 = d1;     long long lim2 = d1 + (r * 1000000 - 1) * aum;     if (lim1 <= k && k <= lim2 && (k - d1) % aum == 0) {       long long num = (k - d1) / aum + 1;       return num;     }     return -1;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.precision(10);     cout << fixed;     long long k;     cin >> k;     for (long long i = 1; i <= N; i++) {       for (long long j = 1; j <= N; j++) {         if (i + j > N) break;         long long aux = calcula(i, j, k);         if (aux != -1) {           cout << i + j << endl;           for (long long a = 0; a < i - 1; a++) {             cout << 0 <<    ;           }           cout << -1 <<    ;           for (long long a = 0; a < j; a++) {             cout << min(aux, 1000000ll) <<    ;             aux -= min(aux, 1000000ll);           }           cout << endl;           return 0;         }       }     }     cout << -1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int cakesneeded, timek, k, timeforoven;     cin >> cakesneeded >> timek >> k >> timeforoven;     int cyclesneeded = cakesneeded / k;     if (cakesneeded % k != 0) {       cyclesneeded++;     }     int totaltime = cyclesneeded * timek;     int partialtime = totaltime - timek;     if (partialtime > timeforoven) {       cout <<  YES ;     } else {       cout <<  NO ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b, c, d;     cin >> a >> b >> c >> d;     long long w, x, y, z;     bool f = 1;     if (a == c && f) {       w = a + abs(d - b);       x = b;       y = a + abs(d - b);       z = d;       f = 0;     }     if (b == d && f) {       w = a;       x = b + abs(a - c);       y = c;       z = b + abs(a - c);       f = 0;     } else if (f) {       if (abs(a - c) == abs(b - d)) {         w = a;         x = d;         y = c;         z = b;         f = 0;       } else {         cout << -1 << endl;         ;       }     }     if (!f) cout << w <<     << x <<     << y <<     << z << endl;     ;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     while (b) {       swap(a %= b, b);     }     return a;   }   long long n, m, x, y, a, b, g;   double dist1(long long curstep) {     long long l1 = a / g * curstep;     long long l2 = b / g * curstep;     long long x1 = max(1ll, (x - (l1 - l1 / 2)));     if (x1 + l1 > n) {       x1 = n - l1;     }     long long x2 = x1 + l1;     long long y1 = max(1ll, (y - (l2 - l2 / 2)));     if (y1 + l2 > m) {       y1 = m - l2;     }     long long y2 = y1 + l2;     double c1 = (x1 + x2 + .0) / 2;     double c2 = (y1 + y2 + .0) / 2;     double tempdst = sqrt((c1 - x) * (c1 - x) + (c2 - y) * (c2 - y));     return tempdst;   }   int main() {     cin >> n >> m >> x >> y >> a >> b;     g = gcd(a, b);     a /= g;     b /= g;     long long step = min(n / a, m / b);     a *= step;     b *= step;     long long l1 = a;     long long l2 = b;     long long x1 = max(0ll, (x - (l1 - l1 / 2)));     if (x1 + l1 > n) {       x1 = n - l1;     }     long long x2 = x1 + l1;     long long y1 = max(0ll, (y - (l2 - l2 / 2)));     if (y1 + l2 > m) {       y1 = m - l2;     }     long long y2 = y1 + l2;     cout << x1 <<    ;     cout << y1 <<    ;     cout << x2 <<    ;     cout << y2;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 100;   long long n_r, n_g, n_b, r[maxn], g[maxn], b[maxn], ans;   void cal(long long n_r, long long n_g, long long n_b, long long r[],            long long g[], long long b[]) {     long long x, y, z, i, j = 1, k = 1;     for (i = 1; i <= n_g; ++i) {       y = g[i];       while (r[j] <= y && j <= n_r) ++j;       if (j == 1) continue;       --j;       x = r[j];       while (b[k] < y) ++k;       if (k > n_b) break;       z = b[k];       ans = min(ans, (x - y) * (x - y) + (y - z) * (y - z) + (z - x) * (z - x));     }   }   void solve() {     ans = 0x7fffffffffffffff;     cal(n_r, n_g, n_b, r, g, b);     cal(n_r, n_b, n_g, r, b, g);     cal(n_g, n_r, n_b, g, r, b);     cal(n_g, n_b, n_r, g, b, r);     cal(n_b, n_g, n_r, b, g, r);     cal(n_b, n_r, n_g, b, r, g);     cout << ans <<   n ;   }   int main() {     int t, i, j;     ios::sync_with_stdio(false);     cin >> t;     while (t--) {       cin >> n_r >> n_g >> n_b;       for (i = 1; i <= n_r; ++i) cin >> r[i];       for (i = 1; i <= n_g; ++i) cin >> g[i];       for (i = 1; i <= n_b; ++i) cin >> b[i];       sort(r + 1, r + 1 + n_r);       sort(g + 1, g + 1 + n_g);       sort(b + 1, b + 1 + n_b);       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> e[111];   int used[111], cnt, cnt2;   void dfs(int x) {     used[x] = 1;     cnt += e[x].size();     cnt2++;     for (int i = 0; i < e[x].size(); i++)       if (used[e[x][i]] == 0) dfs(e[x][i]);   }   int main() {     int i, j, k, n, m, stop = 0;     scanf( %d%d , &n, &m);     for (i = 0; i < m; i++) {       int x, y;       scanf( %d%d , &x, &y);       e[x].push_back(y);       e[y].push_back(x);     }     for (i = 1; i <= n; i++) {       if (!used[i]) {         cnt = 0;         cnt2 = 0;         dfs(i);         if (cnt2 % 2 == 1 && cnt2 * 2 == cnt) {           stop++;         }       }     }     printf( %d n , stop + (n - stop) % 2);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   queue<int> qx, qy;   int d[2][110000];   char s[2][110000];   int n, k;   int main() {     gets(s[0]);     sscanf(s[0],  %d %d , &n, &k);     gets(s[0]);     gets(s[1]);     memset(d, 63, sizeof(d));     d[0][0] = 0;     qx.push(0);     qy.push(0);     for (; qx.size();) {       int x = qx.front();       int y = qy.front();       qx.pop();       qy.pop();       if (d[y][x] > x) continue;       if (x + k >= n) {         printf( YES n );         return 0;       }       if (s[y][x + 1] ==  - ) {         if (d[y][x + 1] > d[y][x] + 1) {           d[y][x + 1] = d[y][x] + 1;           qx.push(x + 1);           qy.push(y);         }       }       if (x > 0 && s[y][x - 1] ==  - ) {         if (d[y][x - 1] > d[y][x] + 1) {           d[y][x - 1] = d[y][x] + 1;           qx.push(x - 1);           qy.push(y);         }       }       if (s[y ^ 1][x + k] ==  - ) {         if (d[y ^ 1][x + k] > d[y][x] + 1) {           d[y ^ 1][x + k] = d[y][x] + 1;           qx.push(x + k);           qy.push(y ^ 1);         }       }     }     printf( NO n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int t, n;   int a[200001];   int main() {     scanf( %d , &t);     while (t--) {       scanf( %d , &n);       for (int i = 1; i <= n; i++) scanf( %d , &a[i]);       bool flag = false;       for (int i = 2; i <= n; i++)         if (abs(a[i] - a[i - 1]) > 1) {           flag = true;           printf( YES n );           printf( %d %d n , i - 1, i);           break;         }       if (!flag) printf( NO n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d n , &n);     set<int> in, x;     long totalCost(0), cost(0);     while (n--) {       int a, b, c;       scanf( %d %d %d n , &a, &b, &c);       totalCost += c;       if (in.count(a) || x.count(b)) {         cost += c;         x.insert(a);         in.insert(b);       } else {         in.insert(a);         x.insert(b);       }     }     if (totalCost - cost < cost) {       cost = totalCost - cost;     }     printf( %ld n , cost);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   vector<int> a;   void printall(int x, int y, bool paren = false) {     if (paren) printf( ( );     for (int i = x; i < y; i++) printf( %d-> , a[i]);     printf( %d , a[y]);     if (paren) printf( ) );   }   int main() {     scanf( %d , &n);     a.resize(n);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     if (a.back() != 0) {       puts( NO );     } else {       if (n == 1 or a[n - 2] == 1) {         puts( YES );         printall(0, n - 1);       } else {         int i;         for (i = n - 3; i >= 0; i--)           if (a[i] == 0) break;         if (i < 0) {           puts( NO );         } else {           puts( YES );           if (i - 1 >= 0) {             printall(0, i - 1);             printf( -> );           }           printf( (0-> );           printall(i + 1, n - 2, true);           printf( )->0 );         }       }     }   }