malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int n, m;   vector<pair<int, int> > e[N];   vector<int> ans[2];   bool fla[2], flag;   int E[N], d[N];   vector<int> cnt[2];   void DFS(int first, int o, int res) {     if (flag) return;     d[first] = o;     cnt[o].push_back(first);     for (auto& i : e[first]) {       if (flag) return;       int second = (i.second + o) % 2;       if (d[i.first] == -1)         DFS(i.first, second != res, res);       else if (d[i.first] != (second != res))         flag = true;     }   }   void SOLVE(int res) {     memset(d, -1, sizeof(d));     flag = false;     for (int i(1); i <= n; i++)       if (d[i] == -1) {         cnt[0].clear();         cnt[1].clear();         DFS(i, 0, res);         if (flag) {           fla[res] = true;           return;         }         for (bool ___ = 1; ___; ___ = 0) {           int mx = (cnt[1].size() < cnt[0].size());           for (auto& i : cnt[mx]) ans[res].push_back(i);         }       }   }   int main() {     n = ({       long long first = 0;       int n = 0, c = getchar();       for (; !isdigit(c); c = getchar()) n = c ==  - ;       for (; isdigit(c); c = getchar()) first = first * 10 + c -  0 ;       n ? -first : first;     }),     m = ({       long long first = 0;       int n = 0, c = getchar();       for (; !isdigit(c); c = getchar()) n = c ==  - ;       for (; isdigit(c); c = getchar()) first = first * 10 + c -  0 ;       n ? -first : first;     });     for (int i(1); i <= m; i++) {       int first = ({         long long first = 0;         int n = 0, c = getchar();         for (; !isdigit(c); c = getchar()) n = c ==  - ;         for (; isdigit(c); c = getchar()) first = first * 10 + c -  0 ;         n ? -first : first;       }),           second = ({             long long first = 0;             int n = 0, c = getchar();             for (; !isdigit(c); c = getchar()) n = c ==  - ;             for (; isdigit(c); c = getchar()) first = first * 10 + c -  0 ;             n ? -first : first;           });       int c = ({                 char c = getchar();                 while (c ==     || c ==   n ) c = getchar();                 c;               }) ==  R ;       e[first].push_back({second, c});       e[second].push_back({first, c});     }     SOLVE(0);     SOLVE(1);     for (bool ___ = 1; ___; ___ = 0) {       int res;       if (fla[0] && fla[1])         return cout << -1 <<   n , 0;       else if (fla[0])         res = 1;       else if (fla[1])         res = 0;       else if (ans[0].size() < ans[1].size())         res = 0;       else         res = 1;       cout << ans[res].size() <<   n ;       for (auto& i : ans[res]) cout << i <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   class BLongtailHedgehog {    public:     int N, M;     vector<int> dist, deg_in, deg;     vector<vector<int>> G;     void input(std::istream& in, std::ostream& out) {       ios_base::sync_with_stdio(false);       in >> N >> M;       dist = vector<int>(N, -1);       deg_in = vector<int>(N, 0);       deg = vector<int>(N, 0);       G = vector<vector<int>>(N, vector<int>());       for (int(i) = (0); (i) < (M); ++(i)) {         int u, v;         in >> u >> v;         u--, v--;         if (u > v) swap(u, v);         G[u].push_back(v);         deg_in[v]++, deg[u]++, deg[v]++;       }     }     void bfs(int s) {       queue<int> q;       dist[s] = 1, q.push(s);       while (!q.empty()) {         int u = q.front();         q.pop();         for (auto v : G[u]) {           deg_in[v]--;           dist[v] = max(dist[v], dist[u] + 1);           if (deg_in[v] == 0) {             q.push(v);           }         }       }     }     void solve(std::istream& in, std::ostream& out) {       input(in, out);       for (int(i) = (0); (i) < (N); ++(i)) {         if (dist[i] == -1) bfs(i);       }       long long ans = 0;       for (int(i) = (0); (i) < (N); ++(i)) ans = max(ans, 1LL * dist[i] * deg[i]);       out << ans <<   n ;     }   };   int main() {     BLongtailHedgehog solver;     std::istream& in(std::cin);     std::ostream& out(std::cout);     solver.solve(in, out);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void hi() {     static long long i = 0;     cout <<  Check Point :   << ++i <<   n ;     return;   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long t;     t = 1;     while (t--) {       string str;       cin >> str;       long long n = str.length();       stack<char> stk;       for (long long i = 0; i < n; i++) {         if (!stk.empty() && ((stk.top() ==  +  && str[i] ==  + ) ||                              ((stk.top() ==  -  && str[i] ==  - )))) {           stk.pop();         } else {           stk.push(str[i]);         }       }       if (stk.empty()) {         cout <<  Yes               <<   n ;       } else {         cout <<  No               <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 400010;   int gcds[N], a[N], b[N];   int c[N], mx[N];   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i - 1]);       gcds[i] = gcd(i, n);     }     long long ans = 0;     for (int i = 1; i < n; i++) {       if (n % i) continue;       for (int j = 1; j <= n; j++) c[j] = c[j - 1] + (i == gcds[j]);       for (int j = 0; j < i; j++) mx[j] = a[j];       for (int j = i; j < n; j++) mx[j % i] = max(mx[j % i], a[j]);       for (int j = 0; j < n; j++) b[j] = b[j + n] = mx[j % i] == a[j];       for (int j = 2 * n - 2; j >= 0; j--)         if (b[j]) b[j] += b[j + 1];       for (int j = 0; j < n; j++) ans += c[min(n - 1, b[j])];     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[23][23];   char s[23][23];   int dp[1 << 23];   int n, m;   int cost[23][23];   int st[23][23];   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) scanf( %s , s[i]);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) scanf( %d , &a[i][j]);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         int mx = -0x3f3f3f3f;         int ans = 0;         for (int k = 0; k < n; k++) {           if (s[i][j] == s[k][j]) {             ans += a[k][j];             mx = max(mx, a[k][j]);             st[i][j] |= 1 << k;           }         }         ans -= mx;         cost[i][j] = ans;       }     for (int i = 1; i < (1 << n); i++) dp[i] = 0x3f3f3f3f;     dp[0] = 0;     for (int i = 0; i < (1 << n); i++)       for (int j = 0; j < n; j++)         if ((i & (1 << j)) == 0) {           for (int k = 0; k < m; k++) {             dp[i | (1 << j)] = min(dp[i | (1 << j)], dp[i] + a[j][k]);             dp[i | st[j][k]] = min(dp[i | st[j][k]], dp[i] + cost[j][k]);           }         }     printf( %d n , dp[(1 << n) - 1]);     return 0;   }
#include <bits/stdc++.h>   long long int a[300000];   int main() {     long long int n, i, hei, bai;     while (scanf( %lld , &n) != EOF) {       hei = bai = 0;       for (i = 0; i < n; i++) {         scanf( %lld , &a[i]);         if (i % 2) {           hei += (a[i] + 1) / 2;           bai += a[i] / 2;         } else {           bai += (a[i] + 1) / 2;           hei += a[i] / 2;         }       }       printf( %lld n , bai < hei ? bai : hei);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = INT_MAX;   const long long INFL = LLONG_MAX;   const int output_precision = 15;   const long double pi = acos(-1);   const bool debug = true;   int N;   int A[5];   int check() {     vector<int> B(4);     for (int(i) = 1, j1234 = 4; (i) <= j1234; (i)++) B[i - 1] = A[i];     sort(B.begin(), B.end());     int x1 = B[0] + B[1] + B[2] + B[3];     int x2 = 2 * (B[1] + B[2]);     int x3 = 4 * (B[3] - B[0]);     return x1 == x2 && x2 == x3;   }   int main() {     ios_base::sync_with_stdio(0);     cout.precision(output_precision);     cout << fixed;     cout.tie(0);     cin >> N;     for (int(i) = 1, j1234 = N; (i) <= j1234; (i)++) cin >> A[i];     if (N == 0) {       cout <<  YES  <<   n ;       cout << 1 <<   n ;       cout << 1 <<   n ;       cout << 3 <<   n ;       cout << 3 <<   n ;       return 0;     }     if (N == 1) {       int a = A[1];       cout <<  YES  <<   n ;       cout << a <<   n ;       cout << 3 * a <<   n ;       cout << 3 * a <<   n ;       return 0;     }     if (N == 2) {       for (int(x) = 1, j1234 = 1500; (x) <= j1234; (x)++)         for (int(y) = 1, j1234 = 1500; (y) <= j1234; (y)++) {           A[3] = x;           A[4] = y;           if (check()) {             cout <<  YES  <<   n ;             cout << x <<   n ;             cout << y <<   n ;             return 0;           }         }       cout <<  NO  <<   n ;       return 0;     }     if (N == 3) {       for (int(i) = 1, j1234 = 1500; (i) <= j1234; (i)++) {         A[4] = i;         if (check()) {           cout <<  YES  <<   n ;           cout << i <<   n ;           return 0;         }       }       cout <<  NO  <<   n ;       return 0;     }     if (N == 4) {       if (check()) {         cout <<  YES  <<   n ;       } else {         cout <<  NO  <<   n ;       }       return 0;     }   }
#include <bits/stdc++.h>   using namespace std;   void islam() {     ios::sync_with_stdio(false);     cin.tie(NULL);   }   void get(long long &x) { cin >> x; }   class ghost {    public:     ghost() {       get(n);       for (int i = 0; i < n; i++) {         get(arr[i]);         s += arr[i];       }       s /= n;     }     void solve() {       long long c = 0;       for (int i = 0; i < n; i++) {         c += s - arr[i];         a += abs(c);       }     }     void print() { cout << a; }       private:     long long n, s;     long long arr[50000 + 10], a = 0;   };   int main() {     islam();     ghost x;     x.solve();     x.print();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, i, j, k, l, m, t;   int a[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   int main() {     cin >> m >> t;     a[m] -= 7 - t + 1;     if (a[m] % 7 == 0) {       cout << a[m] / 7 + 1;     } else {       cout << a[m] / 7 + 2;     }   }
#include <bits/stdc++.h>   using namespace std;   queue<int> fila;   struct G {     double d;     int m, p, r;   } g[250002];   bool mk[250002];   int a2[9000000];   bool cmp2(int a, int b) { return g[a].d < g[b].d; }   int pos = 0;   int ind = 0;   struct T {     int m;     int* e;     void pdt(int a, int* b) { m = a, e = b; }   } mas[2 * 250002];   bool cmp(T a, T b) { return a.m < b.m; }   int ls[4 * 250002];   int s[4 * 250002][2];   int r[4 * 250002];   int build(int a, int b, int f) {     int p = ind++;     ls[p] = pos;     r[p] = b;     int i = ls[f];     for (int i = ls[f]; a2[i] >= 0; i++) {       if (g[a2[i]].m >= a && g[a2[i]].m <= b) a2[pos] = a2[i], pos++;     }     a2[pos] = -1;     pos++;     if (a != b)       s[p][0] = build(a, (a + b) / 2, p),       s[p][1] = build(((a + b) / 2) + 1, b, p);     else       s[p][0] = s[p][1] = -1;     return p;   }   void get(int p, int power, int ray) {     if (r[p] <= power) {       for (int i = ls[p]; a2[i] >= 0; i++) {         if (g[a2[i]].d <= ray + 1e-2) {           if (!mk[a2[i]]) fila.push(a2[i]), mk[a2[i]] = true;           ls[p] = i + 1;         } else           break;       }     } else {       get(s[p][0], power, ray);       if (power > r[s[p][0]]) get(s[p][1], power, ray);     }   }   int main() {     double x0, y0;     int pp, rr, n;     scanf( %lf %lf %d %d %d , &x0, &y0, &pp, &rr, &n);     int tot = 0;     mas[tot++].pdt(pp, &pp);     double x, y;     for (int i = 0; i < n; i++) {       scanf( %lf %lf %d %d %d , &x, &y, &g[i].m, &g[i].p, &g[i].r);       x -= x0;       y -= y0;       g[i].d = sqrt(x * x + y * y);       mk[i] = false;       a2[i] = i;       mas[tot++].pdt(g[i].m, &g[i].m), mas[tot++].pdt(g[i].p, &g[i].p);     }     a2[n] = -1;     sort(mas, mas + tot, cmp);     int v = 1;     int tmp = mas[0].m;     *mas[0].e = v;     for (int i = 1; i < tot; i++) {       if (mas[i].m != tmp) v++;       tmp = mas[i].m;       *mas[i].e = v;     }     sort(a2, a2 + n, cmp2);     r[0] = v;     ls[0] = 0;     ind = 1;     pos = n + 1;     if (n >= 2) s[0][0] = build(1, v / 2, 0), s[0][1] = build((v / 2) + 1, v, 0);     get(0, pp, rr);     int resp = 0;     while (fila.size()) {       resp++;       int u = fila.front();       fila.pop();       get(0, g[u].p, g[u].r);     }     printf( %d n , resp);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int run(int n) {     int i, a[n];     for (i = 0; i < n; i++) cin >> a[i];     sort(a, a + i);     int ans = 0;     int tempCount = 0;     for (i = 0; i < n; i++) {       tempCount++;       if (a[i] == tempCount) {         ans++;         tempCount = 0;       }     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     int n;     while (t--) {       cin >> n;       cout << run(n) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, s = 1;     char a;     string b[10], c;     cin >> n;     b[0] =   ;     b[1] =   ;     b[2] =  2 ;     b[3] =  3 ;     b[4] =  322 ;     b[5] =  5 ;     b[6] =  53 ;     b[7] =  7 ;     b[8] =  7222 ;     b[9] =  7332 ;     int k = 0;     int d = 0;     for (int i = 1; i <= n; i++) {       cin >> a;       s = a - 48;       if (s != 1 && s != 0) c = c + b[s];     }     sort(c.begin(), c.end());     k = c.size();     for (int i = k - 1; i >= 0; i--) cout << c[i];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     scanf( %lld , &n);     long long int a[n];     long long int i, j, k;     long long int ans = 0;     k = 0;     for (i = 0; i < n; i++) {       scanf( %lld , &j);       if (j == 1) {         a[k++] = i;       }     }     if (k == 0) {       ans = 0;     } else if (k == 1) {       ans = 1;     } else {       ans = 1;       for (i = 1; i < k; i++) {         if ((a[i] - a[i - 1]) == 1) {           ans++;         } else {           ans += 2;         }       }     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   int b[1000005], a[1000005];   int main() {     int n, i;     scanf( %d , &n);     for (i = 0; i < n; i++) scanf( %d , &a[i]);     b[n - 1] = a[n - 1];     for (i = n - 2; i >= 0; i--) b[i] = a[i] + a[i + 1];     for (i = 0; i < n; i++) printf( %d  , b[i]);     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   namespace io {   template <typename T>   inline void read(T &x) {     bool flag = false;     char c = getchar();     while ((c <  0  || c >  9 ) && c !=  - ) c = getchar();     c ==  -  ? flag = true, x = 0 : x = c -  0 ;     c = getchar();     while (c >=  0  && c <=  9 ) x = (x << 3) + (x << 1) + c -  0 , c = getchar();     if (flag) x = -x;   }   template <typename T>   inline void write(T x) {     char st[10010];     int cnt = 0;     if (x < 0) x = -x, putchar( - );     if (x == 0) putchar( 0 );     while (x) {       st[++cnt] = x % 10 + 48;       x /= 10;     }     while (cnt) {       putchar(st[cnt--]);     }   }   }  // namespace io   using namespace io;   int main() {     int a, ans = 0;     read(a);     while (a) {       ans += (a % 8 == 1);       a /= 8;     }     write(ans);     puts(  );     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1073741824 )   using namespace std;   const int N = 3e5 + 100;   int col[N], d[N][2];   vector<int> v[N];   int main() {   #pragma warning(disable : 4996)     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       int a, b;       scanf( %d%d , &a, &b);       a--, b--;       v[a].push_back(b);       v[b].push_back(a);     }     queue<int> q;     for (int i = 0; i < n; i++) {       d[i][0] = v[i].size();       if (d[i][0] > 1) q.push(i);     }     while (!q.empty()) {       int node = q.front();       q.pop();       if (d[node][col[node]] > 1) {         col[node] ^= 1;         for (int to : v[node]) {           d[to][col[node]]++;           d[to][col[node] ^ 1]--;           if (d[to][col[to]] > 1) q.push(to);         }       }     }     for (int i = 0; i < n; i++) printf( %d , col[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000005;   const long long mod = 1e9 + 7;   const int N = 1e6;   vector<int> rec[maxn];   long long fac[maxn], ans;   int n, m;   int ord[maxn], bit;   bool comp(int a, int b) { return rec[a][bit] < rec[b][bit]; }   void mysort(int l, int r, int j) {     if (l == r) return;     bit = j;     sort(ord + l, ord + r + 1, comp);     int p = l;     while (p <= r && rec[ord[p]][j] == -1) ++p;     int cnt = 1;     for (int i = l + 1; i < p; i++)       if (rec[ord[i]][j - 1] == rec[ord[i - 1]][j - 1])         ++cnt;       else {         (ans *= fac[cnt]) %= mod;         cnt = 1;       }     (ans *= fac[cnt]) %= mod;     int t = p;     while (t <= r) {       p = t;       while (p <= r && rec[ord[p]][j] == rec[ord[t]][j]) ++p;       mysort(t, p - 1, j + 1);       t = p;     }   }   int main() {     fac[0] = 1ll;     for (int i = 1; i <= N; i++) fac[i] = fac[i - 1] * i % mod;     scanf( %d %d , &n, &m);     for (int i = 1; i <= m; i++) rec[i].push_back(0);     for (int g, i = 1; i <= n; i++) {       scanf( %d , &g);       for (int v, j = 1; j <= g; j++) scanf( %d , &v), rec[v].push_back(i);     }     for (int i = 1; i <= m; i++) {       sort(rec[i].begin(), rec[i].end());       rec[i].push_back(-1);       ord[i] = i;     }     ans = 1ll;     mysort(1, m, 1);     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int Power(int base, int exp) {     int ans = 1;     while (exp > 0) {       if (exp & 1) ans = (1LL * ans * base) % 1000000007;       exp = exp >> 1;       base = (1LL * base * base) % 1000000007;     }     return ans;   }   vector<map<long double, int> > p_CntS(2005);   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long int n;     cin >> n;     long double x[n], y[n];     for (int i = 0; i < n; i += 1) cin >> x[i] >> y[i];     long double slope;     for (int p1 = 0; p1 < n; p1 += 1)       for (int p2 = 0; p2 < n; p2 += 1) {         if (p1 == p2) continue;         slope = y[p2] - y[p1];         if (x[p2] - x[p1] == 0)           p_CntS[p1][600.0]++;         else           p_CntS[p1][300.0 + slope / (x[p2] - x[p1])]++;       }     long long int ans = (1LL * n * (n - 1) * (n - 2)) / 6, ans_ = 0;     int cnt;     for (int i = 0; i < n; i += 1) {       map<long double, int>::iterator it = p_CntS[i].begin();       while (it != p_CntS[i].end()) {         cnt = (*it).second;         ans_ += 1LL * cnt * (cnt - 1) / 2;         it++;       }     }     cout << ans - ans_ / 3 <<   n ;   }
#include <bits/stdc++.h>   int ans = 0;   double H = 100, len = 100000;   int F[110000], T[110000], FF[110000], TT[110000];   bool vis[110000];   int judge(bool fuck, double st, double t) {     int ret = 0;     int top, flo;     double point = st;     memset(vis, 0, sizeof(vis));     while (point < len) {       top = (int)ceil(point);       flo = (int)floor(point);       if (fuck) {         if (T[top] < 0 || T[flo] < 0 || T[top] != T[flo]) {           return -1;         }         if (vis[TT[top]] == 1) return -1;         ret += T[top];         vis[TT[top]] = 1;         fuck = !fuck;       } else {         if (F[top] < 0 || F[flo] < 0 || F[top] != F[flo]) {           return -1;         }         if (vis[FF[top]] == 1) return -1;         ret += F[top];         vis[FF[top]] = 1;         fuck = !fuck;       }       point += t;     }     if (ans < ret) ans = ret;     return ret;   }   int work() {     int n, i, j, val, x, y;     char c;     double A, B, t;     double hl, hr;     scanf( %lf%lf%d , &hl, &hr, &n);     memset(T, -1, sizeof(T));     memset(F, -1, sizeof(F));     for (i = 1; i <= n; i++) {       scanf( %d %c%d%d , &val, &c, &x, &y);       if (c ==  T ) {         for (j = x; j <= y; j++) T[j] = val, TT[j] = i;       } else {         for (j = x; j <= y; j++) F[j] = val, FF[j] = i;       }     }     A = hl / H;     B = hr / H;     for (i = 0; i <= 100; i++) {       if ((i & 1) == 0) {         t = len / (A + B + i);         judge(0, A * t, t);       }       if ((i & 1) == 1) {         t = len / ((1 - A) + B + i);         judge(1, (1 - A) * t, t);       }       if ((i & 1) == 1) {         t = len / (A + (1 - B) + i);         judge(0, A * t, t);       }       if ((i & 1) == 0) {         t = len / ((1 - A) + (1 - B) + i);         judge(1, (1 - A) * t, t);       }     }     printf( %d n , ans);     return 1;   }   int main() {     work();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct point {     int x, y;     point() {}     point(int x, int y) : x(x), y(y) {}   } p[1010];   point operator-(const point &a, const point &b) {     return point(a.x - b.x, a.y - b.y);   }   long long operator*(const point &a, const point &b) {     return (long long)a.x * b.y - (long long)a.y * b.x;   }   int main() {     int n, i, x, y, low, high;     cin >> n;     for (i = 0; i < n; i++) {       cin >> x >> y;       p[i] = point(x, y);     }     low = p[0].x;     high = p[1].x;     if (low > high) swap(low, high);     p[n] = p[0];     for (i = 0; i < n; i++) {       while (low <= high && (p[i + 1] - p[i]) * (point(low, p[0].y) - p[i]) > 0)         low++;       while (low <= high && (p[i + 1] - p[i]) * (point(high, p[0].y) - p[i]) > 0)         high--;     }     cout << high - low + 1 << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 500000;   const long long minx = -0x5fffffffffffffff;   struct nn {     long long x, y;     nn() { y = minx; }   };   int n, u, v;   nn num[N];   vector<int> node[N];   long long dfs(int f, int x) {     for (int i = 0; i < node[x].size(); i++) {       if (node[x][i] == f) continue;       long long r = dfs(x, node[x][i]);       num[x].y += r;     }     return num[x].y;   }   long long dfs1(int f, int x, long long &ans) {     long long m1 = minx;     long long m2 = minx;     for (int i = 0; i < node[x].size(); i++) {       if (node[x][i] == f) continue;       long long r = dfs1(x, node[x][i], ans);       if (m1 < r) {         m2 = m1;         m1 = r;       } else if (m2 < r) {         m2 = r;       }     }     if (m2 != minx) {       if (ans < m1 + m2) ans = m1 + m2;     }     return m1 > num[x].y ? m1 : num[x].y;   }   int main() {     long long ans;     while (scanf( %d , &n) != EOF) {       ans = minx;       for (int i = 0; i < N; i++) node[i].clear();       for (int i = 1; i <= n; i++) {         scanf( %lld , &num[i].x);         num[i].y = num[i].x;       }       for (int i = 0; i < n - 1; i++) {         scanf( %d%d , &u, &v);         node[u].push_back(v);         node[v].push_back(u);       }       dfs(0, 1);       dfs1(0, 1, ans);       if (ans != minx)         printf( %lld n , ans);       else         printf( Impossible n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int n, k;     cin >> n >> k;     if (k > (n * n + 1) / 2) {       cout <<  NO ;       return 0;     }     cout <<  YES n ;     int tmp = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (j % 2 == i % 2 && tmp != k) {           cout <<  L ;           tmp++;         } else           cout <<  S ;       }       cout <<   n ;     }   }