malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, l;     cin >> n >> l;     vector<int> flags(n + 2);     flags[0] = 0, flags[n + 1] = l;     for (int i = 0; i < n; ++i) {       cin >> flags[i + 1];     }     vector<double> s(n + 2);     vector<double> e(n + 2);     s[0] = 0;     e[n + 1] = 0;     for (int i = 1; i < n + 2; ++i) {       s[i] = s[i - 1] + (flags[i] - flags[i - 1]) * 1.0 / i;       e[n - i + 1] =           e[n - i + 2] + (flags[n - i + 2] - flags[n - i + 1]) * 1.0 / (i);     }     for (int i = 0; i < n + 2; ++i) {       if (abs(s[i] - e[i]) < 1e-6) {         cout << s[i] <<   n ;         return;       } else if (s[i] > e[i]) {         double sspd = i;         double espd = n - i + 2;         double dist = flags[i] - flags[i - 1];         double result = espd * e[i] + sspd * s[i - 1] + dist;         result = result / (sspd + espd);         cout << result <<   n ;         return;       }     }   }   int main() {     cout << setprecision(9);     cout << fixed;     int tests;     cin >> tests;     while (tests) {       solve();       tests--;     }   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   struct Sync_stdio {     Sync_stdio() {       cin.tie(NULL);       ios_base::sync_with_stdio(false);     }   } _sync_stdio;   int main() {     int n, m, k;     cin >> n >> m >> k;     vector<vector<vector<int>>> v(n + 2,                                   vector<vector<int>>(m + 2, vector<int>(k + 2)));     vector<vector<vector<int>>> ans(         n + 2, vector<vector<int>>(m + 2, vector<int>(k + 2)));     for (int i = (0); i < (n); ++i) {       for (int j = (0); j < (m); ++j) {         string s;         cin >> s;         for (int l = (0); l < (k); ++l) {           v[i + 1][j + 1][l + 1] = s[l] -  0 ;         }       }     }     for (int i = (1); i < (n + 1); ++i) {       for (int j = (1); j < (m + 1); ++j) {         for (int l = (1); l < (k + 1); ++l) {           if (v[i][j][l] == 1 && v[i - 1][j][l] == 1 && v[i + 1][j][l] == 1) {             ans[i][j][l] = 1;           }           if (v[i][j][l] == 1 && v[i][j - 1][l] == 1 && v[i][j + 1][l] == 1) {             ans[i][j][l] = 1;           }           if (v[i][j][l] == 1 && v[i][j][l - 1] == 1 && v[i][j][l + 1] == 1) {             ans[i][j][l] = 1;           }           for (int x1 = (0); x1 < (3); ++x1) {             for (int x2 = (0); x2 < (3); ++x2) {               if (x1 == x2) {                 continue;               }               vector<int> dx1(3);               vector<int> dx2(3);               ++dx1[x1];               ++dx2[x2];               if (v[i][j][l] == 1 && v[i - dx1[0]][j - dx1[1]][l - dx1[2]] == 1 &&                   v[i + dx2[0]][j + dx2[1]][l + dx2[2]] == 1 &&                   v[i - dx1[0] + dx2[0]][j - dx1[1] + dx2[1]]                    [l - dx1[2] + dx2[2]] == 0) {                 ans[i][j][l] = 1;               }             }           }         }       }     }     int res = 0;     for (int i = (1); i < (n + 1); ++i) {       for (int j = (1); j < (m + 1); ++j) {         for (int l = (1); l < (k + 1); ++l) {           res += ans[i][j][l];         }       }     }     cout << res;   }
#include <bits/stdc++.h>   using namespace std;   string str;   int ss;   int par[10001];   int ans[2][10001];   int root(int x) {     if (par[x] != x) par[x] = root(par[x]);     return par[x];   }   map<string, int> m;   int main() {     while (getline(cin, str)) {       char ty = str[0];       int k = 2;       int z = 0;       int p = 0;       string tt =   ;       tt += ty;       tt +=    ;       while (k < str.size()) {         tt +=     ;         string t =   ;         k++;         while (k < str.size() && str[k] !=     ) t += str[k], k++;         tt += t;         z++;         if (k < str.size()) {           if (!m.count(tt)) {             m[tt] = ++ss;             par[m[tt]] = m[tt];           }           if (z > 1) {             int xx = root(m[tt]);             int yy = root(p);             if (xx != yy) {               par[xx] = yy;               ans[0][yy]++;             }           }           p = m[tt];         } else {           ans[1][root(p)]++;         }       }     }     int mx1 = 0, mx2 = 0;     for (map<string, int>::iterator it = m.begin(); it != m.end(); it++) {       mx1 = max(mx1, ans[0][it->second]);       mx2 = max(mx2, ans[1][it->second]);     }     cout << mx1 <<     << mx2;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const unsigned long long maxn = 2e6 + 10;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     string v;     cin >> v;     for (long i = 0; i < v.size(); i++) {       if (v[i] !=  1  && v[i] !=  4 ) {         cout <<  NO  << endl;         return 0;       }     }     if (v[0] !=  1 ) {       cout <<  NO  << endl;       return 0;     }     unsigned long long p = 0;     for (long i = 1; i < v.size(); i++) {       if (v[i] ==  4  && v[i - 1] ==  4 ) {         if (v[i + 1] ==  4 ) {           cout <<  NO  << endl;           p = 1;           return 0;         }       }     }     if (p == 0) {       cout <<  YES  << endl;       return 0;     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100100;   int n, m;   int was[MAXN];   vector<int> g[MAXN];   bool was2[3][MAXN];   bool dfs(int v, int col = 1) {     was[v] = col;     for (int i = 0; i < (int)g[v].size(); ++i) {       if (!was[g[v][i]]) {         if (dfs(g[v][i], 3 - col)) {           return true;         }       } else if (was[v] == was[g[v][i]])         return true;     }     return false;   }   int dfs2(int v, int col) {     was2[col][v] = true;     int res = was[v] == col;     for (int i = 0; i < (int)g[v].size(); ++i) {       if (!was2[col][g[v][i]]) {         res += dfs2(g[v][i], col);       }     }     return res;   }   unsigned long long C(int n, int k) {     if (k > n) return 0;     unsigned long long res = 1;     for (int i = 0; i < k; ++i) res *= n - i;     for (int i = 2; i <= k; ++i) res /= i;     return res;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0, a, b; i < m; ++i) {       scanf( %d%d , &a, &b);       g[a].push_back(b);       g[b].push_back(a);     }     for (int i = 1; i <= n; ++i) {       if (!was[i] && dfs(i)) {         puts( 0 1 );         return 0;       }     }     unsigned long long one = 0;     for (int i = 1; i <= n; ++i) {       if (!was2[1][i]) {         one += C(dfs2(i, 1), 2);         one += C(dfs2(i, 2), 2);       }     }     if (one) {       cout << 1 <<     << one << endl;       return 0;     }     if (m) {       cout << 2 <<     << m * 1ll * (n - 2) <<   n ;       return 0;     }     cout << 3 <<     << C(n, 3) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int longpre(string y) {     string s = y +  ? ;     reverse(y.begin(), y.end());     s += y;     int n = s.length();     int lps[n];     for (int i = 0; i < n; i++) lps[i] = 0;     int i = 0;     int j = 1;     while (j < n) {       if (s[i] == s[j]) {         lps[j] = i + 1;         i++;         j++;       } else {         if (i == 0) {           lps[j] = 0;           j++;         } else {           i = lps[i - 1];         }       }     }     return lps[n - 1];   }   int main() {     int t;     cin >> t;     while (t--) {       string s;       cin >> s;       int k = 0;       int i = 0;       int n = s.length();       int j = n - 1;       while (i < j) {         if (s[i] == s[j])           k++;         else           break;         i++;         j--;       }       string t =   ;       if (k > 0) {         t += s.substr(0, k);       }       string mid = s.substr(k, n - 2 * k);       if (mid.length() > 0) {         int prefix = longpre(mid);         reverse(mid.begin(), mid.end());         int suffix = longpre(mid);         if (prefix > suffix) {           reverse(mid.begin(), mid.end());           t += mid.substr(0, prefix);         } else {           t += mid.substr(0, suffix);         }       }       t += s.substr(n - k, k);       cout << t << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     int Q;     cin >> Q;     while (Q-- > 0) {       int n;       cin >> n;       vector<int> dp(2001, inf);       dp[0] = 0;       for (int i = 0; i < n; ++i) {         int a;         cin >> a;         vector<int> aux(dp);         fill(dp.begin(), dp.end(), inf);         for (int j = 0; j < 2001; ++j) {           if (aux[j] != inf) {             dp[max(0, j - a)] = min(dp[max(0, j - a)], aux[j] + a);             if (j + a < 2001) {               dp[j + a] = min(dp[j + a], max(0, aux[j] - a));             }           }         }       }       int res = inf;       for (int i = 0; i <= 2000; ++i) {         if (dp[i] != inf) {           res = min(res, i + dp[i]);         }       }       cout << res <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   long long x[100007], y[100007], xx, yy, m, p, q;   long long ans;   int get(int p, int q) {     while ((x[q] - x[p]) * (yy - y[p]) - (y[q] - y[p]) * (xx - x[p]) <= 0)       q = q % n + 1;     q = (q + n - 2) % n + 1;     return q;   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) scanf( %I64d%I64d , &x[i], &y[i]);     for (cin >> m; m; m--) {       cin >> xx >> yy;       int now = 0;       ans = 0;       for (int i = 1; i <= n; i++)         if ((xx - x[i]) * (y[i % n + 1] - y[i]) -                 (yy - y[i]) * (x[i % n + 1] - x[i]) <             0)           now++;       if (now != 0 && now != n) {         cout << 0 << endl;         continue;       }       for (p = 1, q = get(1, 1); p <= n; p++, q = get(p, q)) {         int r = ((q - p) % n + n) % n;         ans += ((long long)r) * (r - 1) / 2;       }       ans = ((long long)n * (n - 1) * (n - 2) / 6 - ans);       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MaxN = 100010, Block = 500, TB = 300;   struct query {     int l, r, id;     bool operator<(const query &a) const {       if (l / TB != a.l / TB) return l / TB < a.l / TB;       return r < a.r;     }   } q[MaxN];   long long ans[MaxN];   int cnt[MaxN], num[MaxN], a[MaxN];   vector<int> large;   bool vis[MaxN];   int n, m;   int tmp[MaxN];   long long get_ans() {     for (int i = 1; i <= Block * 2; ++i) tmp[i] = num[i];     long long ret = 0;     int x = 1;     for (int i = 1; i <= Block; ++i) {       if (!tmp[i]) continue;       if (tmp[i] >= 2) {         ret += (tmp[i] / 2) * i * 2;         tmp[i * 2] += tmp[i] / 2;         tmp[i] &= 1;       }       if (tmp[i] & 1) {         x = max(i + 1, x);         while (tmp[x] == 0 && i + x <= Block * 2) ++x;         if (i + x > Block * 2) break;         ret += i + x;         ++tmp[i + x];         --tmp[x];       }       tmp[i] = 0;     }     priority_queue<int, vector<int>, greater<int> > Q;     for (int i = 1; i <= Block * 2; ++i)       for (int j = 1; j <= tmp[i]; ++j) Q.push(i);     for (auto i : large)       if (cnt[i] > Block * 2) Q.push(cnt[i]);     while (Q.size() >= 2) {       int x = Q.top();       Q.pop();       int y = Q.top();       Q.pop();       ret += x + y;       Q.push(x + y);     }     return ret;   }   void reverse(int x) {     int u = a[x];     if (vis[x]) {       --num[cnt[u]];       --cnt[u];       ++num[cnt[u]];     } else {       --num[cnt[u]];       ++cnt[u];       ++num[cnt[u]];     }     vis[x] ^= 1;   }   void move(int &x, int p) {     while (x > p) {       reverse(x);       --x;     }     while (x < p) {       ++x;       reverse(x);     }   }   int main() {     scanf( %d , &n);     int mx = 0;     for (int i = 1; i <= n; ++i) {       scanf( %d , a + i);       ++cnt[a[i]];       mx = max(mx, a[i]);     }     for (int i = 1; i <= mx; ++i)       if (cnt[i] > Block * 2) large.push_back(i);     memset(cnt, 0, sizeof(cnt));     scanf( %d , &m);     for (int i = 1; i <= m; ++i) {       scanf( %d%d , &q[i].l, &q[i].r);       q[i].id = i;     }     sort(q + 1, q + m + 1);     int l = 0, r = 0;     for (int i = 1; i <= m; ++i) {       move(l, q[i].l - 1);       move(r, q[i].r);       if (q[i].l == q[i - 1].l && q[i].r == q[i - 1].r)         ans[q[i].id] = ans[q[i - 1].id];       else         ans[q[i].id] = get_ans();     }     for (int i = 1; i <= m; ++i) printf( %I64d n , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, size[55];   double f[55][55], fac[55];   int cnt, head[55], to[110], nxt[110];   void add(int x, int y) {     cnt++;     to[cnt] = y;     nxt[cnt] = head[x];     head[x] = cnt;   }   double c(int n, int m) {     if (m < 0 || m > n) {       return 0.0;     } else {       return fac[n] / fac[m] / fac[n - m];     }   }   void dfs(int x, int fa) {     size[x] = 1;     f[x][0] = 1.0;     double tmp[55];     for (int i = head[x]; i; i = nxt[i]) {       int y = to[i];       if (y == fa) {         continue;       }       dfs(y, x);       for (int j = 0; j < size[x] + size[y]; j++) {         tmp[j] = 0.0;       }       for (int j = 0; j < size[y]; j++) {         for (int k = 0; k < size[x]; k++) {           for (int h = j + k + 1; h <= size[y] + k; h++) {             tmp[h] += c(h, k) * c(size[x] + size[y] - 1 - h, size[x] - 1 - k) *                       f[x][k] * f[y][j] / 2.0;           }           tmp[j + k] += 1.0 * (size[y] - j) * c(j + k, j) *                         c(size[x] + size[y] - 1 - j - k, size[x] - 1 - k) *                         f[x][k] * f[y][j];         }       }       size[x] += size[y];       for (int j = 0; j < size[x]; j++) {         f[x][j] = tmp[j];       }     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       add(x, y);       add(y, x);     }     fac[0] = 1.0;     for (int i = 1; i <= n; i++) {       fac[i] = fac[i - 1] * i;     }     for (int i = 1; i <= n; i++) {       dfs(i, 0);       printf( %.10lf n , f[i][n - 1] / fac[n - 1]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const int SIZE = 1e6 + 5;   const long long INF = 1LL << 58;   const double eps = 1e-10;   char d[2009][2009];   char a[2009][2009];   int dy[4] = {-1, 0, 1, 0};   int dx[4] = {0, 1, 0, -1};   int dy2[8] = {-2, -1, 0, 1, 2, 1, 0, -1};   int dx2[8] = {0, 1, 2, 1, 0, -1, -2, -1};   char v2[5] =  ^>v< ;   char v[5] =  v<^> ;   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < (n); ++i) {       scanf( %s , (d[i]));       for (int j = 0; j < (m); ++j) {         if (d[i][j] ==  * )           a[i][j] =  * ;         else           a[i][j] =  . ;       }     }     queue<pair<int, int> > q;     for (int i = 0; i < (n); ++i) {       for (int j = 0; j < (m); ++j) {         if (d[i][j] ==  * ) continue;         q.push(make_pair(i, j));       }     }     while (((int)(q).size())) {       pair<int, int> cur = q.front();       q.pop();       int y = cur.first, x = cur.second;       if (a[y][x] !=  . ) continue;       int ck = -1;       for (int k = 0; k < (4); ++k) {         int ny = y + dy[k], nx = x + dx[k];         if (ny < 0 || ny >= n || nx < 0 || nx >= m) continue;         if (a[ny][nx] ==  . ) {           if (ck != -1) {             ck = -1;             break;           } else             ck = k;         }       }       if (ck == -1) continue;       int ny = y + dy[ck], nx = x + dx[ck];       a[y][x] = v[ck];       a[ny][nx] = v2[ck];       for (int k = 0; k < (8); ++k) {         int ny = y + dy2[k], nx = x + dx2[k];         if (ny < 0 || ny >= n || nx < 0 || nx >= m) continue;         q.push(make_pair(ny, nx));       }     }     for (int i = 0; i < (n); ++i) {       for (int j = 0; j < (m); ++j) {         if (a[i][j] ==  . ) {           puts( Not unique );           return 0;         }       }     }     for (int i = 0; i < (n); ++i) {       for (int j = 0; j < (m); ++j) {         printf( %c , a[i][j]);       }       puts(  );     }   }
#include <bits/stdc++.h>   using namespace std;   int N;   int K[1010];   pair<int, int> nex[1010][2520];   int P, Q;   int num[1010][2520];   int vis[1010][2520];   class SCC {    public:     static const int MV = 1010 * 2520;     vector<vector<int> > SC;     int NV, GR[MV];       private:     vector<int> E[MV], RE[MV], NUM;     int vis[MV];       public:     void init(int NV) {       this->NV = NV;       for (int i = 0; i < MV; i++) {         E[i].clear();         RE[i].clear();       }     }     void add_edge(int x, int y) {       E[x].push_back(y);       RE[y].push_back(x);     }     void dfs(int cu) {       vis[cu] = 1;       for (int i = 0; i < E[cu].size(); i++)         if (!vis[E[cu][i]]) dfs(E[cu][i]);       NUM.push_back(cu);     }     void revdfs(int cu, int ind) {       int i;       vis[cu] = 1;       GR[cu] = ind;       SC[ind].push_back(cu);       for (i = 0; i < (RE[cu].size()); i++)         if (!vis[RE[cu][i]]) revdfs(RE[cu][i], ind);     }     void scc() {       int c = 0;       SC.clear();       SC.resize(MV);       NUM.clear();       memset(vis, 0, sizeof(vis));       for (int i = 0; i < NV; i++)         if (!vis[i]) dfs(i);       memset(vis, 0, sizeof(vis));       for (int i = NUM.size() - 1; i >= 0; i--)         if (!vis[NUM[i]]) {           SC[c].clear();           revdfs(NUM[i], c);           sort(SC[c].begin(), SC[c].end());           c++;         }       SC.resize(c);     }   };   int dfs(int v, int val, vector<int>& V) {     if (vis[v][val] == 2) {       set<int> S;       int i;       for (i = V.size() - 1; i >= 0; i--) {         S.insert(V[i] / 2520);         if (V[i] == v * 2520 + val) break;       }       num[v][val] = S.size();     } else if (vis[v][val] == 0) {       vis[v][val] = 2;       V.push_back(v * 2520 + val);       num[v][val] = dfs(nex[v][val].first, nex[v][val].second, V);       V.pop_back();     }     vis[v][val] = 1;     return num[v][val];   }   void solve() {     int i, j, k, l, r, x, y;     string s;     cin >> N;     for (i = 0; i < (N); i++) {       cin >> K[i];       K[i] = (K[i] % 2520 + 2520) % 2520;     }     for (i = 0; i < (N); i++) {       vector<int> E;       cin >> x;       E.resize(x);       for (j = 0; j < (x); j++) cin >> E[j];       for (j = 0; j < (2520); j++) {         nex[i][j].first = E[(j + K[i]) % x] - 1;         nex[i][j].second = (j + K[i]) % 2520;       }     }     for (i = 0; i < (N); i++)       for (j = 0; j < (2520); j++)         if (vis[i][j] == 0) {           vector<int> V;           dfs(i, j, V);         }     cin >> Q;     while (Q--) {       cin >> x >> y;       x--;       y = (y % 2520 + 2520) % 2520;       cout << num[x][y] << endl;     }   }   int main(int argc, char** argv) {     string s;     int i;     if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);     for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s +=   n ;     for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);     cout.tie(0);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   void ingraph(vector<long long> graph[], long long m) {     long long x, y;     for (long long i = 0; i < m; i++) {       cin >> x >> y;       x--, y--;       graph[x].push_back(y);       graph[y].push_back(x);     }   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long lcm(long long a, long long b) { return a * b / gcd(a, b); }   long long modmulti(long long a, long long b) {     return ((a % mod) * 1ll * (b % mod)) % mod;   }   long long modadd(long long a, long long b) {     long long asdfgh = ((a % mod) + (b % mod) + mod + mod) % mod;     asdfgh = (asdfgh + mod) % mod;     return asdfgh;   }   long long modpower(long long a, long long n) {     if (n == 0) return 1;     if (n == 1) return a % mod;     long long b = modpower(a, n / 2);     b = modmulti(b, b);     if (n % 2 == 0) return b;     return modmulti(a, b);   }   long long modinv(long long a) { return modpower(a, mod - 2); }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long sum = 0;       vector<long long> vec;       for (long long i = 1; i <= n; i = i * 2) {         vec.push_back(i);         n = n - i;       }       if (n > 0) {         vec.push_back(n);       }       sort(vec.begin(), vec.end());       cout << (long long)(vec).size() - 1 <<   n ;       for (long long i = 1; i < (long long)(vec).size(); i++)         cout << vec[i] - vec[i - 1] <<    ;       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     while (t--) {       string s;       cin >> s;       int n = s.length();       if (n < 3) {         cout << 0 << endl;         continue;       }       if (n == 3) {         if (s ==  101  || s ==  010 )           cout << 1 << endl;         else           cout << 0 << endl;         continue;       }       long long int zero = 0, one = 0;       for (long long int i = 0; i < n; i++) {         if (s[i] ==  1 )           one++;         else           zero++;       }       if (one == n || zero == n) {         cout << 0 << endl;         continue;       }       long long int done = 0, dzero = 0;       long long int min1 = INT_MAX, min2 = INT_MAX;       for (long long int i = 0; i < n; i++) {         if (s[i] ==  1 )           done++;         else           dzero++;         min1 = min(min1, (dzero + one - done));         min2 = min(min2, (done + zero - dzero));       }       cout << min(min1, min2) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, neg = 0;   char s[1009];   int main() {     vector<int> ans;     scanf( %[^=]=%d , s, &n);     ans.push_back(n);     for (int i = 1; s[i]; i++) {       if (s[i] ==    ) continue;       if (s[i] ==  - )         neg = 1;       else if (s[i] ==  + )         neg = 0;       else if (s[i] ==  ?  && !neg) {         ans[0] -= 1;         ans.push_back(1);       } else if (s[i] ==  ? ) {         int c = 0;         ans[0] += 1;         ans.push_back(-1);       }     }     int c = 1;     while (ans[0] > n && c < ans.size()) {       if (ans[c] > 0 && ans[c] < n) {         ans[0]--;         ans[c]++;       } else         c++;     }     c = 1;     while (ans[0] <= 0 && c < ans.size()) {       if (ans[c] < 0 && abs(ans[c]) < n) {         ans[0]++;         ans[c]--;       } else         c++;     }     if (ans[0] <= 0 || ans[0] > n) {       printf( Impossible n );       return 0;     }     printf( Possible n );     printf( %d , ans[0]);     for (int i = 1; i < ans.size(); i++) {       if (ans[i] > 0)         printf(  + %d , ans[i]);       else         printf(  - %d , abs(ans[i]));     }     printf(  = %d n , n);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int x, int y) {     if (y == 0) return x;     return gcd(y, x % y);   }   int main() {     int n;     cin >> n;     int ansx = 0, ansy = 0;     for (int i = 1; i < n; i++) {       int j = n - i;       if (j <= i) break;       if (gcd(i, j) != 1) continue;       ansx = i;       ansy = j;     }     cout << ansx <<     << ansy << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f, N = 1005, MOD = 100000007;   const double eps = 1e-6;   int a[15], m, ans[N], ct;   char b;   int main() {     ct = 0;     for (int i = 1; i <= 10; i++) {       scanf( %c , &b);       if (b ==  1 ) {         a[ct++] = i;       }     }     scanf( %d , &m);     bool flag = 0;     int s[2], tmp;     int i, j, tail;     for (int k = 0; k < ct; k++) {       s[0] = s[1] = 0;       s[0] = ans[0] = a[k];       tail = k;       tmp = 1;       for (i = 1; i < m; i++) {         for (j = 0; j < ct; j++) {           if (j == tail) continue;           if (s[tmp] + a[j] > s[tmp ^ 1]) {             s[tmp] += a[j];             ans[i] = a[j];             tail = j;             tmp ^= 1;             break;           }         }         if (j == ct) {           flag = 0;           break;         }       }       if (i == m) {         flag = 1;         break;       }     }     if (flag) {       printf( YES n );       for (int k = 0; k < m; k++) {         printf( %d  , ans[k]);       }       puts(  );     } else       printf( NO n );     return 0;   }