#include <bits/stdc++.h>   using namespace std;   long long power(long long a, long long n) {     if (a == 0) return 0;     if (a == 1 || n == 0) return 1;     if (n == 1) return a % 1000000007;     long long t = power(a, n / 2);     t = t * t % 1000000007;     if (n & 1) return t * a % 1000000007;     return t;   }   int popcount(long long a) {     int c = 0;     while (a) {       c++;       a -= a & -a;     }     return c;   }   void factorize(int a) {}   void update(int tree[], int idx, int val, int maxval) {     for (; idx <= maxval; idx += idx & -idx) {       tree[idx] += val;     }   }   int read(int tree[], int idx) {     long long sum = 0;     for (; idx > 0; idx -= idx & -idx) {       sum += tree[idx];     }     return sum;   }   struct node2 {     int id, val;     node2() {       static int ctx = 1;       id = ctx++;     };     node2(int a, int b = 0, int c = 0, int d = 0, int e = 0, int f = 0) {       val = a;     }   };   struct comp2 {     bool operator()(int a, int b) { return b < a; }   };   bool cmp2(int a, int b) { return b < a; }   struct node {     long long x, y;   };   struct comp {     bool operator()(int a, int b) { return b < a; }   };   bool cmp(int a, int b) { return b < a; }   int n, m, a, b, c, d, k, h, w, x, y, p, q, t, res, ma, mi, T, act = 0, pas = 1,                                                                 cur, flag, now;   int deg[100009];   char s[1];   double e, f, z;   vector<int> v[100009], vec;   node ans[100009];   set<int> sett;   map<int, int> mapp;   void print() {}   void print2() {}   void input() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     for (int i = 1; i < n; i++) {       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);       deg[x]++;       deg[y]++;     }   }   int Y[] = {0, 1, 0, -1, 0};   int X[] = {0, 0, 1, 0, -1};   int bgfjsvf[] = {0, 3, 4, 1, 2};   void calc(int id, int par, long long y, long long x, long long dist, int dir) {     ans[id].x = x;     ans[id].y = y;     int block = 1;     for (auto u : v[id]) {       if (u == par) continue;       if (block == dir) block++;       calc(u, id, y + Y[block] * dist, x + X[block] * dist, dist / 2,            bgfjsvf[block]);       block++;     }   }   void solve() {     for (int i = 1; i < n + 1; i++)       if (deg[i] > 4) {         flag = 1;         return;       }     calc(1, 0, 0, 0, 1e9, 0);   }   void output() {     if (flag == 1)       cout <<  NO ;     else {       cout <<  YES  << endl;       for (int i = 1; i < n + 1; i++) cout << ans[i].x <<     << ans[i].y << endl;     }   }   int main() {     input();     solve();     output();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int LEN = 100009;   int n;   int a[LEN];   int ch = 0, nech = 0;   int ans = 0;   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) {       if (a[i] % 2 == 0)         ch++;       else         nech++;     }     ans = min(ch, nech);     while (nech > 1) {       nech -= 2;       ch++;       ans = max(ans, min(ch, nech));     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   set<pair<long long, long long> > st;   const long long INF = 1 << 30;   const long long N = 100005;   long long p[N], n, m;   long long nxt[N], pre[N];   long long a[N], x[N];   inline long long read() {     long long x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 1) + (x << 3) + (ch ^ 48);       ch = getchar();     }     return x * f;   }   bool cmp(long long x, long long y) { return p[x] < p[y]; }   long long calc(long long x, long long y) {     if (x == y) return INF;     long long d = (p[y] - p[x] + m) % m;     if (x > y) d = (d + a[y]) % m;     if (d <= a[x]) return 1;     if (a[x] <= a[y]) return INF;     long long dis = a[x] - a[y];     return (d - a[y] - 1) / dis + 1;   }   signed main() {     n = read();     m = read();     for (long long i = 1; i <= n; i++) {       p[i] = read();       a[i] = read();       x[i] = i;     }     sort(x + 1, x + n + 1, cmp);     for (long long i = 1; i <= n; i++) {       if (i < n)         nxt[x[i]] = x[i + 1];       else         nxt[x[i]] = x[1];       pre[nxt[x[i]]] = x[i];     }     for (long long i = 1; i <= n; i++) {       st.insert(make_pair(calc(i, nxt[i]), i));     }     while (!st.empty()) {       set<pair<long long, long long> >::iterator it = st.begin();       if ((*it).first == INF) break;       long long i = (*it).second;       st.erase(it);       st.erase(make_pair(calc(nxt[i], nxt[nxt[i]]), nxt[i]));       st.erase(make_pair(calc(pre[i], i), pre[i]));       p[i] += calc(i, nxt[i]);       --a[i];       nxt[i] = nxt[nxt[i]];       pre[nxt[i]] = i;       st.insert(make_pair(calc(pre[i], i), pre[i]));       st.insert(make_pair(calc(i, nxt[i]), i));     }     printf( %d n , st.size());     for (set<pair<long long, long long> >::iterator it = st.begin();          it != st.end(); it++)       printf( %lld  , (*it).second);   }


#include <bits/stdc++.h>   using namespace std;   int h, t, R;   int n, m;   vector<pair<int, int> > H, T;   int D[201][201];   int shortestWin() {     memset(D, -1, sizeof(D));     queue<pair<int, int> > q;     for (int i = 1; i <= n; i++) {       pair<int, int> s;       s.first = i;       s.second = 0;       if (i <= R && H[i - 1].first == 0 && H[i - 1].second == 0) {         q.push(s);         D[i][0] = 1;       }     }     for (int i = 1; i <= m; i++) {       pair<int, int> s;       s.first = 0;       s.second = i;       if (i <= R && T[i - 1].first == 0 && T[i - 1].second == 0) {         q.push(s);         D[0][i] = 1;       }     }     while (!q.empty()) {       pair<int, int> u = q.front();       q.pop();       for (int i = 0; i < n; i++) {         pair<int, int> v;         v.first = u.first + (i + 1) - (H[i].first);         v.second = u.second - (H[i].second);         if (v.first + v.second <= R) {           if (v.first >= 0 && v.second >= 0 && v.first >= (i + 1)) {             if (D[v.first][v.second] == -1) {               D[v.first][v.second] = D[u.first][u.second] + 1;               q.push(v);             }           }         }       }       for (int i = 0; i < m; i++) {         pair<int, int> v;         v.first = u.first - (T[i].first);         v.second = u.second + (i + 1) - (T[i].second);         if (v.first + v.second <= R) {           if (v.first >= 0 && v.second >= 0 && v.second >= (i + 1)) {             if (D[v.first][v.second] == -1) {               D[v.first][v.second] = D[u.first][u.second] + 1;               q.push(v);             }           }         }       }     }     return D[h][t];   }   int V[201][201];   int dp(int h, int t) {     if (h + t > R || h < 0 || t < 0) {       return 0;     }     if (V[h][t] == 1) {       return 1000000000;     }     if (D[h][t] != -1) {       return D[h][t];     }     V[h][t] = 1;     int best = 0;     for (int i = 0; i < n; i++) {       if (i + 1 > h) break;       int vh = h - (i + 1) + H[i].first;       int vt = t + H[i].second;       best = max(best, dp(vh, vt) + 1);     }     for (int i = 0; i < m; i++) {       if (i + 1 > t) break;       int vh = h + T[i].first;       int vt = t - (i + 1) + T[i].second;       best = max(best, dp(vh, vt) + 1);     }     D[h][t] = best;     V[h][t] = 2;     return D[h][t];   }   int main() {     cin >> h >> t >> R;     cin >> n;     H.resize(n);     for (int i = 0; i < n; i++) {       cin >> H[i].first >> H[i].second;     }     cin >> m;     T.resize(m);     for (int i = 0; i < m; i++) {       cin >> T[i].first >> T[i].second;     }     int winningPath = shortestWin();     if (winningPath != -1) {       cout <<  Ivan n  << winningPath <<   n ;     } else {       memset(D, -1, sizeof(D));       memset(V, 0, sizeof(V));       int losingPath = dp(h, t);       if (losingPath >= 1000000000) {         cout <<  Draw n ;       } else {         cout <<  Zmey n  << losingPath <<   n ;       }     }   }


#include <bits/stdc++.h>   const int MAXN = 300011;   int N;   struct Pair {     int Val;     long long Mask;   } P[MAXN];   long long Sum;   int main() {     scanf( %d , &N);     for (int i = 1; i <= N; ++i) {       scanf( %d%I64d , &P[i].Val, &P[i].Mask);       Sum += P[i].Val;     }     if (Sum < 0LL) {       for (int i = 1; i <= N; ++i) P[i].Val = -P[i].Val;     }     long long Ans = 0LL, Tmp;     for (int i = 61; i >= 0; --i) {       Tmp = 0LL;       for (int j = 1; j <= N; ++j)         if ((P[j].Mask >> i) & 1 && ((P[j].Mask & ((1LL << i) - 1)) == 0))           Tmp += P[j].Val;       if (Tmp > 0LL) {         Ans ^= (1LL << i);         for (int j = 1; j <= N; ++j)           if ((P[j].Mask >> i) & 1) P[j].Val = -P[j].Val;       }     }     printf( %I64d n , Ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200010;   const int mod = 1e9 + 7;   namespace DSU {   int fa[maxn], cycle[maxn], sz[maxn];   void init() {     for (int i = 1; i < maxn; i++) fa[i] = i, sz[i] = 1, cycle[i] = 0;   }   int find_set(int x) {     if (x == fa[x])       return x;     else       return fa[x] = find_set(fa[x]);   }   void union_set(int x, int y) {     int fx = find_set(x);     int fy = find_set(y);     if (fx == fy) {       cycle[fx] = 1;     } else {       fa[fy] = fx;       sz[fx] += sz[fy];       cycle[fx] |= cycle[fy];     }   }   }  // namespace DSU   using namespace DSU;   int main() {     int n;     cin >> n;     init();     long long ans = 1;     for (int i = 1; i <= n; i++) {       int x, y;       cin >> x >> y;       if (x == y) {         cycle[find_set(x)] = 2;         continue;       }       union_set(x, y);     }     for (int i = 1; i <= 2 * n; i++) {       if (find_set(i) == i) {         if (cycle[i] == 1)           ans = ans * 2 % mod;         else {           if (cycle[i] == 0) ans = ans * sz[i] % mod;         }       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 50 + 5;   int R, C, K;   char g[maxn][maxn];   int sx, sy, tx, ty;   bool flag[300];   int mindist;   string ans;   const int dx[] = {0, 1, -1, 0};   const int dy[] = {1, 0, 0, -1};   bool mark[maxn][maxn];   int dist[maxn][maxn];   string board[maxn][maxn];   set<pair<int, int> > grid[maxn * maxn];   void calc() {     memset(dist, -1, sizeof dist);     memset(mark, false, sizeof mark);     queue<pair<int, int> > q;     dist[tx][ty] = 0;     board[tx][ty] =   ;     q.push(make_pair(tx, ty));     while (!q.empty()) {       int x = q.front().first;       int y = q.front().second;       q.pop();       for (int i = 0; i < 4; ++i) {         int xx = x + dx[i], yy = y + dy[i];         if (xx >= 0 && xx < R && yy >= 0 && yy < C &&             (flag[g[xx][yy]] || g[xx][yy] ==  S )) {           if (dist[xx][yy] == -1) {             dist[xx][yy] = dist[x][y] + 1;             q.push(make_pair(xx, yy));           }         }       }     }     if (dist[sx][sy] == -1) return;     string ret =   ;     int curd = dist[sx][sy];     grid[curd].clear();     grid[curd].insert(make_pair(sx, sy));     while (curd > 0) {       char best =  z  + 1;       for (set<pair<int, int> >::iterator it = grid[curd].begin();            it != grid[curd].end(); ++it) {         for (int i = 0; i < 4; ++i) {           int xx = it->first + dx[i], yy = it->second + dy[i];           if (xx >= 0 && xx < R && yy >= 0 && yy < C &&               dist[xx][yy] + 1 == curd) {             if (g[xx][yy] < best) {               best = g[xx][yy];               grid[curd - 1].clear();               grid[curd - 1].insert(make_pair(xx, yy));             } else if (best == g[xx][yy]) {               grid[curd - 1].insert(make_pair(xx, yy));             }           }         }       }       ret += best;       curd--;     }     ret = ret.substr(0, (int)ret.size() - 1);     if (mindist == -1 || dist[sx][sy] < mindist ||         dist[sx][sy] == mindist && ret < ans) {       ans = ret;       mindist = dist[sx][sy];     }   }   void dfs(int dep, int last) {     if (last == 26) {       if (dep == 0) {         calc();       }       return;     }     dfs(dep, last + 1);     if (dep > 0) {       flag[ a  + last] = 1;       dfs(dep - 1, last + 1);       flag[ a  + last] = 0;     }   }   int main() {     scanf( %d%d%d , &R, &C, &K);     for (int i = 0; i < R; ++i) {       scanf( %s , g[i]);     }     for (int i = 0; i < R; ++i) {       for (int j = 0; j < C; ++j) {         if (g[i][j] ==  S ) {           sx = i;           sy = j;         }         if (g[i][j] ==  T ) {           tx = i;           ty = j;         }       }     }     if (abs(sx - tx) + abs(tx - ty) == 1) {       puts(  );       return 0;     }     ans =   ;     mindist = -1;     memset(flag, 0, sizeof flag);     dfs(K, 0);     if (mindist == -1) {       printf( %d n , -1);     } else {       puts(ans.c_str());     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int board[9][9];   int bBoard[9][9];   int best, N, M;   void saveBoard() {     for (int i = 0; i < N; i++)       for (int j = 0; j < M; j++) bBoard[i][j] = board[j][i];   }   void printBoard() {     for (int i = 0; i < N; i++, cout << endl)       for (int j = 0; j < M; j++)         cout << (char)(bBoard[i][j] +  A  ==  A  ?  .  : bBoard[i][j] +  A  - 1);   }   int dx[][5] = {       {0, -1, -2, -1, -1},       {-2, 0, -1, -2, -2},       {-1, -1, 0, -1, -2},       {0, 0, -1, -2, 0},   };   int dy[][5] = {       {0, 0, 0, -1, -2},       {0, -1, -1, -1, -2},       {0, -1, -2, -2, -2},       {0, -1, -1, -1, -2},   };   bool place(int x, int y, int cur, int t) {     for (int i = 0; i < 5; i++) {       int nx = x + dx[t][i], ny = y + dy[t][i];       if (nx < 0 || ny < 0 || board[nx][ny]) return false;     }     for (int i = 0; i < 5; i++) {       int nx = x + dx[t][i], ny = y + dy[t][i];       board[nx][ny] = cur;     }     return true;   }   void unplace(int x, int y, int cur, int t) {     for (int i = 0; i < 5; i++) {       int nx = x + dx[t][i], ny = y + dy[t][i];       board[nx][ny] = 0;     }   }   void search(int x, int y, int cur) {     if (M * (N - y) + M - x <= 5 * (best - cur)) return;     if (x == M) {       y++;       x = 0;     }     if (y == N) {       if (cur > best) {         best = cur;         saveBoard();       }       return;     }     for (int i = 0; i < 4; i++) {       if (place(x, y, cur, i)) {         search(x + 1, y, cur + 1);         unplace(x, y, cur, i);       }     }     search(x + 1, y, cur);   }   int main() {     cin >> N >> M;     search(0, 0, 1);     cout << (best - 1) << endl;     printBoard();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 5;   const int mod = 1e9 + 7;   const long long INF = 2e15;   long long qpower(long long a, long long b) {     long long ans = 1;     while (b > 0) {       if (b & 1) ans = ans * a % mod;       b >>= 1;       a = a * a % mod;     }     return ans;   }   long long n, k;   int main(int argc, char const *argv[]) {     std::cin >> n >> k;     if (k == 0) {       std::cout << n <<   n ;       return 0;     }     int cnt = 0;     for (int i = 0; i < k; i++) {       if (n % 10 == 0) {         cnt++;         n /= 10;       } else         break;     }     for (int i = cnt; i < k; i++) {       if (n % 5 == 0) n /= 5;       if (n % 2 == 0) n /= 2;     }     for (int i = 1; i <= k; i++) {       n *= 10;     }     std::cout << n <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   ostream &operator<<(ostream &out, string str) {     for (char c : str) out << c;     return out;   }   template <class L, class R>   ostream &operator<<(ostream &out, pair<L, R> p) {     return out <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <class T>   auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) {     out <<  { ;     for (auto it = a.begin(); it != a.end(); it = next(it))       out << (it != a.begin() ?  ,   :   ) << *it;     return out <<  } ;   }   void dump() { cerr <<   n ; }   template <class T, class... Ts>   void dump(T a, Ts... x) {     cerr << a <<  ,  ;     dump(x...);   }   template <class T>   int size(T &&a) {     return a.size();   }   using LL = long long;   using PII = pair<int, int>;   mt19937 _gen(chrono::system_clock::now().time_since_epoch().count());   int rd(int a, int b) { return uniform_int_distribution<int>(a, b)(_gen); }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     for (int _t = 0; _t < t; _t++) {       int n, m;       cin >> n >> m;       vector<vector<int>> v(n, vector<int>(m));       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++) cin >> v[i][j];       vector<int> ord(m);       vector<int> mx(m);       for (int j = 0; j < m; j++) {         ord[j] = j;         for (int i = 0; i < n; i++) mx[j] = max(mx[j], v[i][j]);       }       sort(ord.begin(), ord.end(), [&](int a, int b) { return mx[a] > mx[b]; });       vector<int> rev;       for (int i = 0; i < min(n, m); i++) rev.emplace_back(ord[i]);       vector<vector<int>> t(n, vector<int>(size(rev)));       for (int i = 0; i < n; i++)         for (int j = 0; j < size(rev); j++) t[i][j] = v[i][rev[j]];       m = size(rev);       int p = (1 << n);       vector<vector<int>> dp(m, vector<int>(p));       vector<vector<int>> sum(m, vector<int>(p));       auto mymod = [&](int val) {         if (val >= n) return val - n;         return val;       };       for (int j = 0; j < m; j++) {         for (int k = 0; k < p; k++) {           for (int r = 0; r < n; r++) {             int sumka = 0;             for (int i = 0; i < n; i++) {               if (k & (1 << mymod(i + r))) sumka += t[i][j];             }             sum[j][k] = max(sum[j][k], sumka);           }           false;         }       }       for (int j = 0; j < m; j++) {         if (j != 0) dp[j] = dp[j - 1];         for (int k = 0; k < p; k++) {           if (j == 0)             dp[j][k] = sum[j][k];           else {             for (int l = k; l > 0; l = (l - 1) & k) {               dp[j][k] = max(dp[j][k], dp[j - 1][k ^ l] + sum[j][l]);             }           }         }         false;       }       cout << dp[m - 1][p - 1] <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       string s;       cin >> s;       vector<int> v(m);       for (int i = 0; i < m; i++) {         cin >> v[i];       }       sort(v.begin(), v.end());       vector<int> ans(26);       for (int i = 0; i < n; i++) {         int k = v.end() - upper_bound(v.begin(), v.end(), i);         ans[s[i] -  a ] += (k + 1);       }       for (auto x : ans) cout << x <<    ;       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > g[100000];   vector<pair<int, int> > t[100000];   int n, k;   int dp[100000][2];   bool cmp(pair<int, int> f, pair<int, int> s) {     if (dp[f.first][0] + f.second != dp[s.first][0] + s.second)       return dp[f.first][0] + f.second > dp[s.first][0] + s.second;     else       return f.first < s.first;   }   void dfs(int cur, int par = -1) {     for (int i = 0; i < g[cur].size(); i++) {       if (g[cur][i].first == par) continue;       dfs(g[cur][i].first, cur);       t[cur].push_back(g[cur][i]);     }     sort(t[cur].begin(), t[cur].end(), cmp);     for (int i = 0; i < min(k - 1, (int)t[cur].size()); i++) {       dp[cur][0] += dp[t[cur][i].first][0] + t[cur][i].second;     }     int add = 0;     if (t[cur].size() >= k) {       add = dp[t[cur][k - 1].first][0] + t[cur][k - 1].second;     }     for (int i = 0; i < t[cur].size(); i++) {       if (i < k) {         dp[cur][1] = max(dp[cur][1], dp[cur][0] + dp[t[cur][i].first][1] -                                          dp[t[cur][i].first][0] + add);       } else {         dp[cur][1] = max(dp[cur][1],                          dp[cur][0] + dp[t[cur][i].first][1] + t[cur][i].second);       }     }   }   int main() {     scanf( %d %d , &n, &k);     for (int i = 0; i < n - 1; i++) {       int a, b, c;       scanf( %d %d %d , &a, &b, &c);       g[a].push_back(make_pair(b, c));       g[b].push_back(make_pair(a, c));     }     dfs(0);     cout << max(dp[0][0], dp[0][1]) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, h;   int m[100001];   int v[100001];   int id[100001];   int match[100001];   int res[100001];   double eps = 1e-9;   void qsort1(int, int);   void qsort2(int, int);   bool ok(double);   int main() {     cin >> n >> k >> h;     for (int i = 1; i <= n; i++) {       cin >> m[i];       id[i] = i;     }     for (int i = 1; i <= n; i++) cin >> v[i];     qsort1(1, n);     int first = 1;     for (int i = 2; i <= n; i++)       if (m[i] != m[i - 1]) {         qsort2(first, i - 1);         first = i;       }     if (m[n] == m[n - 1]) qsort2(first, n);     double hi, lo;     lo = 0;     hi = 1e9;     for (int j = 1; j <= 100; j++) {       double mid = (hi + lo) / 2;       if (ok(mid)) {         hi = mid;         for (int i = 1; i <= k; i++) res[i] = match[i];       } else         lo = mid;     }     for (int i = 1; i <= k; i++) cout << res[i] <<    ;     cout << endl;     return 0;   }   bool ok(double mid) {     int j = 1;     for (int i = 1; i <= k; i++) {       while (j <= n && double(i * h) / double(v[j]) > mid + eps) j++;       if (j > n) return false;       match[i] = id[j];       j++;     }     return true;   }   void qsort1(int l, int r) {     if (l >= r) return;     int i = l;     int j = r;     int mid = m[(l + r) / 2];     while (i < j) {       while (m[i] < mid) i++;       while (mid < m[j]) j--;       if (i <= j) {         swap(m[i], m[j]);         swap(v[i], v[j]);         swap(id[i], id[j]);         i++;         j--;       }     }     qsort1(i, r);     qsort1(l, j);   }   void qsort2(int l, int r) {     if (l >= r) return;     int i = l;     int j = r;     int mid = v[(l + r) / 2];     while (i < j) {       while (v[i] < mid) i++;       while (mid < v[j]) j--;       if (i <= j) {         swap(v[i], v[j]);         swap(m[i], m[j]);         swap(id[i], id[j]);         i++;         j--;       }     }     qsort2(i, r);     qsort2(l, j);   }


#include <bits/stdc++.h>   using namespace std;   long long x, x2, y, y2, n, m, k, a, b, rep, koliko, koliko2, p;   long long hi, lo, mid;   bool t;   char c;   string s;   int main() {     vector<long long> V;     cin >> n >> k;     k = n - k;     for (int i = 0; i < n; i++) {       cin >> x;       V.push_back(x);     }     lo = 1;     hi = 1000000010;     while (lo < hi) {       mid = (lo + hi) / 2;       koliko = 0;       p = 0;       while (p < V.size()) {         if (V[p] > mid) {           koliko++;           p++;         } else {           p += 2;         }       }       koliko2 = 0;       p = 1;       while (p < V.size()) {         if (V[p] > mid) {           koliko2++;           p++;         } else {           p += 2;         }       }       if (min(koliko, koliko2) <= k) {         hi = mid;       } else {         lo = mid + 1;       }     }     cout << lo <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int a[26];   int b[26];   bool ok;   inline void go(int v, int rem, int cur, int last) {     if (v == n) {       ok = 1;       for (int i = 1; i <= n && ok; ++i)         if (b[i]) ok = 0;       if (ok) {         puts( YES );         exit(0);       }     }     if (rem == 1) {       if (cur == 1) return;       if (v + 1 != n) ++b[a[v]];       go(v + 1, a[v + 1], 0, n);       if (v + 1 != n) --b[a[v]];       return;     }     if (!cur) {       for (int i = rem - 2; i >= 1; --i) {         if (!b[i]) continue;         --b[i];         go(v, rem - i, cur + 1, i);         ++b[i];       }     } else {       for (int i = min(rem - 1, last); i >= 1; --i) {         if (!b[i]) continue;         --b[i];         go(v, rem - i, cur + 1, i);         ++b[i];       }     }   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %d , &a[i]);     sort(a, a + n);     ok = 1;     for (int i = 0; i < n; ++i)       if (a[i] == 2) ok = 0;     if (a[n - 1] != n || !ok) {       puts( NO );       return 0;     }     go(0, a[0], 0, n);     puts( NO );     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:66777216 )   using namespace std;   inline pair<int, int> operator-(const pair<int, int> &a,                                   const pair<int, int> &b) {     return make_pair(a.first - b.first, a.second - b.second);   }   inline int vec(const pair<int, int> &a, const pair<int, int> &b) {     return a.first * b.second - b.first * a.second;   }   int a, b, c, d, n, m, k;   pair<int, int> mas[3005], tmp[3005], res[3005], hull[3005];   inline int dist(const pair<int, int> &a, const pair<int, int> &b) {     return (a.first - b.first) * (a.first - b.first) +            (a.second - b.second) * (a.second - b.second);   }   inline bool cool(pair<int, int> *mas, int n, long double xx) {     if (n < 2) return 0;     int k = 0;     for (int _n((2) - 1), iter(0); iter <= _n; iter++) {       int h = 0;       for (int _n((n)-1), i(0); i <= _n; i++) {         while (h >= 2 &&                vec(mas[i] - hull[h - 1], hull[h - 1] - hull[h - 2]) <= 0)           --h;         hull[h++] = mas[i];       }       --h;       for (int _n((h)-1), i(0); i <= _n; i++) res[k++] = hull[i];       reverse(mas, mas + n);     }     if (k == 2) {       if (dist(res[0], res[1]) >= xx)         return 1;       else         return 0;     }     int a = 0;     for (int _n((k)-1), i(0); i <= _n; i++) {       if (a == i) {         a = i + 1;         if (a == k) a = 0;       }       while (1) {         int t = a + 1;         if (t >= k) t = 0;         if (t == i) break;         int s1 = dist(res[i], res[a]);         int s2 = dist(res[i], res[t]);         if (s2 >= s1)           a = t;         else           break;       }       if (dist(res[i], res[a]) >= xx) return 1;     }     return 0;   }   inline bool check(long double xx) {     for (int _n((n)-1), v(0); v <= _n; v++) {       int k = 0;       for (int _n(n - 1), i(v + 1); i <= _n; i++) {         int s = (mas[v].first - mas[i].first) * (mas[v].first - mas[i].first) +                 (mas[v].second - mas[i].second) * (mas[v].second - mas[i].second);         if (s >= xx) {           tmp[k++] = mas[i];         }       }       if (cool(tmp, k, xx)) return 1;     }     return 0;   }   int main() {     scanf( %d , &n);     for (int _n((n)-1), i(0); i <= _n; i++) {       scanf( %d%d , &mas[i].first, &mas[i].second);     }     sort(mas, mas + n);     long double l = 0.0, r = 4.1e9;     for (int _n((55) - 1), hhod(0); hhod <= _n; hhod++) {       long double xx = (r + l) / 2.0;       if (check(xx))         l = xx;       else         r = xx;     }     double ans = (double)(sqrt(l / 4));     printf( %.12lf n , (double)(sqrt(l / 4)));   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   #pragma GCC optimize(3)   #pragma GCC optimize( Ofast )   #pragma GCC optimize( inline )   #pragma GCC optimize( -fgcse )   #pragma GCC optimize( -fgcse-lm )   #pragma GCC optimize( -fipa-sra )   #pragma GCC optimize( -ftree-pre )   #pragma GCC optimize( -ftree-vrp )   #pragma GCC optimize( -fpeephole2 )   #pragma GCC optimize( -ffast-math )   #pragma GCC optimize( -fsched-spec )   #pragma GCC optimize( unroll-loops )   #pragma GCC optimize( -falign-jumps )   #pragma GCC optimize( -falign-loops )   #pragma GCC optimize( -falign-labels )   #pragma GCC optimize( -fdevirtualize )   #pragma GCC optimize( -fcaller-saves )   #pragma GCC optimize( -fcrossjumping )   #pragma GCC optimize( -fthread-jumps )   #pragma GCC optimize( -funroll-loops )   #pragma GCC optimize( -fwhole-program )   #pragma GCC optimize( -freorder-blocks )   #pragma GCC optimize( -fschedule-insns )   #pragma GCC optimize( inline-functions )   #pragma GCC optimize( -ftree-tail-merge )   #pragma GCC optimize( -fschedule-insns2 )   #pragma GCC optimize( -fstrict-aliasing )   #pragma GCC optimize( -fstrict-overflow )   #pragma GCC optimize( -falign-functions )   #pragma GCC optimize( -fcse-skip-blocks )   #pragma GCC optimize( -fcse-follow-jumps )   #pragma GCC optimize( -fsched-interblock )   #pragma GCC optimize( -fpartial-inlining )   #pragma GCC optimize( no-stack-protector )   #pragma GCC optimize( -freorder-functions )   #pragma GCC optimize( -findirect-inlining )   #pragma GCC optimize( -fhoist-adjacent-loads )   #pragma GCC optimize( -frerun-cse-after-loop )   #pragma GCC optimize( inline-small-functions )   #pragma GCC optimize( -finline-small-functions )   #pragma GCC optimize( -ftree-switch-conversion )   #pragma GCC optimize( -foptimize-sibling-calls )   #pragma GCC optimize( -fexpensive-optimizations )   #pragma GCC optimize( -funsafe-loop-optimizations )   #pragma GCC optimize( inline-functions-called-once )   #pragma GCC optimize( -fdelete-null-pointer-checks )   using namespace std;   inline int read() {     int s = 0, w = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) w = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) s = s * 10 + ch -  0 , ch = getchar();     return s * w;   }   inline void write(int x) {     if (x < 0) {       putchar( - );       x = -x;     }     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );   }   int a[25];   int main() {     ios::sync_with_stdio(false);     int n, k, l = 0, i = 1;     n = read();     k = read();     if (k == 1) {       write(n);       puts(  );     } else {       while (i++) {         while (n % i == 0) {           n /= i;           a[++l] = i;           if (k == l + 1) {             if (n == 1) {               puts( -1 );               break;             }             for (register int j = 1; j <= l; j++) {               write(a[j]);               putchar(   );             }             write(n);             break;           }         }         if (k == l + 1) break;         if (i > n) {           puts( -1 );           break;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7, N = 1e5 + 5;   int n, c[N], x;   long long dp[N][2];   vector<int> g[N];   void dfs(int v) {     dp[v][0] = 1LL;     for (int u : g[v]) {       dfs(u);       (dp[u][0] += dp[u][1]) %= mod;       dp[v][1] = (dp[v][1] * dp[u][0] + dp[v][0] * dp[u][1]) % mod;       dp[v][0] = (dp[v][0] * dp[u][0]) % mod;     }     if (c[v]) {       dp[v][1] = dp[v][0];       dp[v][0] = 0;     }   }   int main() {     ios::sync_with_stdio(0), cin.tie(0);     cin >> n;     for (int i = 1; i < n; i++) {       cin >> x;       g[x].push_back(i);     }     for (int i = 0; i < n; i++) cin >> c[i];     dfs(0);     cout << dp[0][1];   }


#include <bits/stdc++.h>   using namespace std;   const long double eps = 1e-13;   const long double PI = acos(-1);   const int INF = (int)1e9;   const long long INFF = (long long)1e18;   const int mod = (int)1e9 + 7;   const int MXN = (int)1e6 + 7;   int n, k;   vector<int> edge[MXN];   vector<int> re_edge[MXN];   int prt[MXN];   int dp[21][MXN];   void init() {     scanf( %d %d , &n, &k);     for (int i = 2; i < n + 1; i++) {       scanf( %d , prt + i);       edge[prt[i]].push_back(i);       re_edge[i].push_back(prt[i]);       dp[0][i] = prt[i];     }     return;   }   bool leaf[MXN];   struct Scc {     int re[MXN], cntp;     int in[MXN];     int siz[MXN], gp[MXN];     int num[MXN];     int val[MXN];     int fd(int u) { return gp[u] == u ? u : gp[u] = fd(gp[u]); }     void uni(int u, int v) {       u = fd(u), v = fd(v);       if (u == v) return;       if (siz[u] > siz[v]) swap(u, v);       gp[u] = v;       siz[u] += siz[v];       return;     }     void dfs(int u) {       in[u] = 1;       for (int v : edge[u]) {         if (!in[v]) dfs(v);       }       re[++cntp] = u;       return;     }     void dfs2(int u, int la) {       in[u] = 1;       uni(u, la);       for (int v : re_edge[u]) {         if (!in[v]) dfs2(v, la);       }     }     void pre() {       for (int i = 1; i < n + 1; i++) siz[i] = 1, gp[i] = i;       for (int i = 1; i < n + 1; i++)         if (!in[i]) dfs(i);       memset(in, 0, sizeof(in));       ;       for (int i = n; i >= 1; i--)         if (!in[re[i]]) dfs2(re[i], re[i]);       for (int i = 1; i < n + 1; i++)         if (leaf[i]) {           num[fd(i)]++;           val[fd(i)]++;         }       return;     }     int solve() {       pre();       int ans = 0;       for (int i = 1; i < n + 1; i++) {         ans = max(ans, val[fd(i)]);         for (int v : edge[re[i]]) {           int p1 = fd(v);           int p2 = fd(re[i]);           if (p1 == p2) continue;           val[p2] = max(val[p2], num[p2] + val[p1]);           ans = max(ans, val[p2]);         }       }       return ans;     }   } scc;   int dep[MXN];   void dfs(int u, int dpt) {     dep[u] = dpt;     for (int v : edge[u]) dfs(v, dpt + 1);     return;   }   int up(int u, int d) {     for (int i = 0; i < 21; i++) {       if (d & (1 << i)) {         u = dp[i][u];       }     }     return u;   }   void sol() {     dfs(1, 1);     for (int i = 1; i < 21; i++)       for (int j = 1; j < n + 1; j++) {         dp[i][j] = dp[i - 1][dp[i - 1][j]];       }     for (int i = 1; i < n + 1; i++)       if (edge[i].empty()) {         leaf[i] = 1;         int p = 0;         if (dep[i] <= k)           p = 1;         else           p = up(i, k);         edge[i].push_back(p);         re_edge[p].push_back(i);       }     int ans = scc.solve();     printf( %d n , ans);     return;   }   int main(void) {     init();     sol();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXL = 2000005;   string pat[100005];   int beg[2000005];   int bel[2000005];   int id[4200000];   int L = 0;   inline void modify(int a, int b, int val, int v = 1, int l = 1, int r = MAXL) {     if (b < l || a > r) return;     if (a <= l && r <= b) {       id[v] = val;       return;     }     int m = l + r >> 1;     if (id[v]) id[v << 1] = id[v << 1 | 1] = id[v];     id[v] = 0;     modify(a, b, val, v << 1, l, m);     modify(a, b, val, v << 1 | 1, m + 1, r);     return;   }   inline int query(int p, int v = 1, int l = 1, int r = MAXL) {     if (p < l || p > r) return 0;     if (id[v]) return id[v];     if (l == r) return 0;     int m = l + r >> 1;     return max(query(p, v << 1, l, m), query(p, v << 1 | 1, m + 1, r));   }   int cnt = 0;   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> pat[i];       int len = pat[i].size();       int m;       cin >> m;       while (m--) {         cin >> beg[++cnt];         bel[cnt] = i;         modify(beg[cnt], beg[cnt] + len - 1, cnt);         L = max(L, beg[cnt] + len - 1);       }     }     for (int i = 1; i <= L; ++i) {       int q = query(i);       if (!q)         cout <<  a ;       else {         cout << pat[bel[q]][i - beg[q]];       }     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void optimizeIO() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   int32_t main() {     optimizeIO();     long long tt = 1;     cin >> tt;     while (tt--) {       long long n;       cin >> n;       vector<bool> v(65, 0);       while (n) {         long long temp = 1;         long long ind = 0;         while (temp < n) {           temp *= 3;           ind++;         }         if (temp != n) {           temp /= 3;           ind--;         }         if (!v[ind])           v[ind] = true;         else {           for (long long i = ind; i < 65; i++) {             if (v[i])               v[i] = !v[i];             else {               v[i] = true;               break;             }           }           break;         }         n -= temp;       }       long long res = 0;       for (long long i = (long long)(0); i < (long long)(65); i++) {         if (v[i]) {           long long temp = 1;           for (long long j = (long long)(0); j < (long long)(i); j++) {             temp *= 3;           }           res += temp;         }       }       cout << res << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string str[51];   bool visited[51][51], flag = false;   int arrx[] = {1, -1, 0, 0}, arry[] = {0, 0, 1, -1}, n, m;   void dfs(int x, int y, int oldX, int oldY, char renk) {     if (x < 0 || x >= n || y < 0 || y >= m) return;     if (str[x][y] != renk) return;     if (visited[x][y] == true) {       flag = true;       return;     }     visited[x][y] = true;     for (int i = 0; i < 4; i++) {       int newX = x + arrx[i], newY = y + arry[i];       if (newX == oldX && newY == oldY) continue;       dfs(newX, newY, x, y, renk);     }   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> str[i];     memset(visited, 0, sizeof(visited));     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (!visited[i][j]) dfs(i, j, -1, -1, str[i][j]);       }     }     cout << (flag ?  Yes  :  No ) << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma warning(disable : 4996)   #pragma comment(linker,  /STACK:666000000 )   using namespace std;   const int inf = (1 << 30) - 1;   const long double eps = 1e-9;   const long double pi = fabs(atan2(0.0, -1.0));   void ML(const bool v) {     if (v) return;     int *ass;     for (;;) {       ass = new int[2500000];       for (int i = 0; i < 2500000; i++) ass[i] = rand();     }   }   void TL(const bool v) {     if (v) return;     int *ass;     ass = new int[250];     for (;;) {       for (int i = 0; i < 250; i++) ass[i] = rand();     }   }   void PE(const bool v) {     if (v) return;     puts( ass 1 2 3 4 5 6 fuck );     exit(0);   }   int n, m;   bool was[300][300];   void LoAd() { cin >> n >> m; }   vector<pair<int, int> > res;   bool swapped;   int x = 1, y = 1;   bool can_dn() { return !was[x + 1][y]; }   bool can_up() { return !was[x - 1][y]; }   bool can_lt() { return !was[x][y - 1]; }   bool can_rt() { return !was[x][y + 1]; }   void go_dn() {     res.push_back(make_pair(x, y));     was[x][y] = true;     x++;   }   void go_up() {     res.push_back(make_pair(x, y));     was[x][y] = true;     x--;   }   void go_lt() {     res.push_back(make_pair(x, y));     was[x][y] = true;     y--;   }   void go_rt() {     res.push_back(make_pair(x, y));     was[x][y] = true;     y++;   }   void SoLvE() {     if (min(n, m) == 1 && max(n, m) == 2) {       puts( 0 );       for (int i = 1; i <= n; i++)         for (int j = 1; j <= m; j++) printf( %d %d n , i, j);       printf( 1 1 );       return;     }     if (n == 1 || m == 1) {       puts( 1 );       printf( %d %d %d %d n , n, m, 1, 1);       for (int i = 1; i <= n; i++)         for (int j = 1; j <= m; j++) printf( %d %d n , i, j);       printf( 1 1 );       return;     }     if (n % 2 == 0 && m % 2 == 1) {       swap(n, m);       swapped = true;     }     for (int i = 0; i < 300; i++)       for (int j = 0; j < 300; j++)         if (1 <= i && i <= n && 1 <= j && j <= m)           was[i][j] = false;         else           was[i][j] = true;     if (1 == n % 2 && 1 == m % 2) {       puts( 1 );       printf( %d %d %d %d n , n, m, 1, 1);       while (x != n || y != m) {         while (can_dn()) go_dn();         if (can_rt()) go_rt();         while (can_up()) go_up();         if (can_rt()) go_rt();       }       res.push_back(make_pair(n, m));       res.push_back(make_pair(1, 1));     } else {       puts( 0 );       while (true) {         while (can_dn()) go_dn();         if (can_rt()) go_rt();         if (x == n && y == m) break;         while (can_up() && x > 2) go_up();         if (can_rt()) go_rt();       }       while (can_up()) go_up();       while (can_lt()) go_lt();       res.push_back(make_pair(x, y));       res.push_back(make_pair(1, 1));     }     for (int i = 0; i < (int)res.size(); i++) {       if (swapped) swap(res[i].first, res[i].second);       printf( %d %d n , res[i].first, res[i].second);     }   }   int main() {     srand((int)time(NULL));     LoAd();     SoLvE();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[1000005], b[1000005], ans[1000005];   int main() {     int n;     cin >> n;     vector<int> v;     int y = 1;     while (y < n) {       v.push_back(y);       y *= 2;     }     int j = v.size() - 1, x;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (i < n - 1) {         x = a[i] + b[i];         if (i == 0)           ans[i] = x;         else           ans[i] = ans[i - 1] + x;         while (i + v[j] >= n && j < v.size()) {           j--;         }         b[i + v[j]] += x;       }     }     for (int i = 0; i < n - 1; i++) cout << ans[i] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long PLUS = -1;   const long long MULT = -2;   string fo;   vector<long long> tmp, whereMULT;   long long i, nr, lo, hi, total, add, crt, j, p, ans;   int main() {     cin >> fo;     fo =  1*  + fo +  *1 ;     for (i = 0; i < fo.size();) {       if (!( 0  <= fo[i] && fo[i] <=  9 )) {         (fo[i] ==  + ) ? tmp.push_back(PLUS) : tmp.push_back(MULT);         i += 1;       }       long long nr = 0;       while ( 0  <= fo[i] && fo[i] <=  9 ) {         nr = nr * 10 + fo[i] -  0 ;         i += 1;       }       tmp.push_back(nr);     }     for (i = 0; i < tmp.size(); ++i)       if (tmp[i] == MULT) whereMULT.push_back(i);     for (i = 0; i < whereMULT.size(); ++i)       for (j = i + 1; j < whereMULT.size(); ++j) {         lo = whereMULT[i] + 1, hi = whereMULT[j] - 1;         crt = 0;         add = tmp[lo];         lo += 1;         p = 0;         while (lo <= hi) {           if (tmp[lo] == MULT) {             lo += 1;             add *= tmp[lo];             lo += 1;           } else {             crt += add;             lo += 1;             add = tmp[lo];             lo += 1;           }         }         crt += add;         lo = 1, hi = tmp.size() - 1;         total = 0, add = 1;         while (lo <= hi) {           if (lo == whereMULT[i]) {             add *= crt;             lo = whereMULT[j];             continue;           }           if (tmp[lo] == MULT) {             lo += 1;             add *= tmp[lo];             lo += 1;           } else {             total += add;             lo += 1;             add = tmp[lo];             lo += 1;           }         }         total += add;         ans = max(ans, total);       }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int su(int n) {     int r, sum = 0;     while (n != 0) {       r = n % 10;       sum = sum + r;       n = n / 10;     }     return sum;   }   int main() {     int n;     cin >> n;     int k = n;     int i = 0;     while (i != 10) {       int d = su(k + i);       if (d % 4 == 0) {         cout << k + i << endl;         break;       }       i++;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     t = 1;     while (t--) {       int n, m;       cin >> n >> m;       string s[n];       for (int i = 0; i < n; ++i) {         cin >> s[i];       }       int cnt = 0;       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           if (s[i][j] ==  B ) cnt++;         }       }       cnt = sqrt(cnt);       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           if (s[i][j] ==  B ) {             cout << i + cnt / 2 + 1 <<     << j + cnt / 2 + 1 << endl;             return 0;           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long res, d, e, k;   int N;   int h[2020];   long long dp[2020][2020];   long long pw(long long a, long long n) {     long long ret = 1;     while (n) {       if (n % 2) ret *= a, ret %= 998244353;       a *= a, a %= 998244353;       n >>= 1;     }     return ret;   }   long long C(long long n, long long r) {     if (r == 0 || r == n) return 1;     if (dp[n][r]) return dp[n][r];     return dp[n][r] = (C(n - 1, r - 1) + C(n - 1, r)) % 998244353;   }   int main() {     scanf( %d %d , &N, &k);     if (k == 1) return !printf( 0 );     for (int i = 0; i < N; i++) scanf( %d , &h[i]);     for (int i = 0; i < N; i++) {       if (h[i] == h[(i + 1) % N])         e++;       else         d++;     }     for (long long s = 0; s < d; s++) {       long long mul = 1;       mul *= pw(k - 2, s);       mul %= 998244353;       mul *= C(d, s);       mul %= 998244353;       long long sum = 0;       for (long long m = 0; m <= (d - s - 1) / 2; m++) {         sum += C(d - s, m);         sum %= 998244353;       }       mul *= sum;       mul %= 998244353;       res += mul;       res %= 998244353;     }     res *= pw(k, e);     res %= 998244353;     printf( %lld , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w,       x, y, z, ans, maxi, mini, res;   string s1, s2;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> x;     if (x == 2)       cout << 2;     else       cout << 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int on[100005];   int prime[100005], cnt = 0;   void ola() {     for (int i = 2; i <= 100005; i++) {       if (!on[i]) prime[cnt++] = i;       for (int j = 0; j < cnt && i * prime[j] <= 100005; j++) {         on[i * prime[j]] = 1;         if (i % prime[j] == 0) break;       }     }   }   int main() {     int n, flag = 0;     cin >> n;     ola();     for (int i = 2; i <= n + 1; i++) {       if (on[i] == 1) {         on[i] = 2;         flag = 1;       } else         on[i] = 1;     }     if (flag == 1)       cout << 2 << endl;     else       cout << 1 << endl;     for (int i = 2; i <= n; i++) cout << on[i] <<    ;     cout << on[n + 1] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 400005;   int n, q, a[maxn];   namespace SGT {   int Min[maxn << 2];   void modify(int l, int r, int id, int x, int y) {     if (l == r) {       Min[id] = y;       return;     }     int mid = (l + r) >> 1;     if (x <= mid)       modify(l, mid, id << 1, x, y);     else       modify(mid + 1, r, id << 1 | 1, x, y);     Min[id] = min(Min[id << 1], Min[id << 1 | 1]);   }   int query(int l, int r, int id, int L, int R) {     if (L <= l && r <= R) return Min[id];     int mid = (l + r) >> 1, res = 1e9;     if (L <= mid) res = min(res, query(l, mid, id << 1, L, R));     if (R > mid) res = min(res, query(mid + 1, r, id << 1 | 1, L, R));     return res;   }   }  // namespace SGT   struct query {     int r1, c1, c2, id;     query() {}     query(int _r1, int _c1, int _c2, int _i) {       r1 = _r1, c1 = _c1, c2 = _c2, id = _i;     }   };   int ans[maxn], now[maxn];   vector<query> Q[2][maxn];   void solve(vector<query> *Q) {     static int st[maxn], num[maxn], top;     top = 0;     for (int i = 1; i <= n; i++) {       while (top && num[top] >= a[i]) top--;       st[++top] = i;       num[top] = a[i];       SGT ::modify(1, n, 1, top, -2 * i + a[i]);       for (auto u : Q[i]) {         int r1 = u.r1, c1 = u.c1, r2 = i, c2 = u.c2, id = u.id;         int res = r2 - r1 + c2 + 1;         int L = lower_bound(st + 1, st + top + 1, r1) - st, R = top;         now[id] = min(c1, num[L]);         res = min(res, r2 - r1 + abs(c2 - now[id]));         int pos = lower_bound(num + L, num + R + 1, c2) - num;         if (pos <= R) res = min(res, r2 - r1 + 1 + abs(c2 - num[pos]));         if (pos > L)           res = min(res, r2 - r1 + 1 + abs(c2 - num[pos - 1]));         else {           assert(pos == L);           pos = upper_bound(num + 1, num + R + 1, c2) - num - 1;           if (pos && st[pos] <= r1)             res = min(res, r1 + r2 - 2 * st[pos] + (c1 < num[pos]) +                                abs(c2 - num[pos]));         }         if (pos + 1 < L) {           R = L - 1, L = pos + 1;           int mid = upper_bound(num + L, num + R + 1, c1) - num;           if (mid <= R)             res = min(res, r1 + r2 + 1 + SGT ::query(1, n, 1, mid, R) - c2);           if (L < mid)             res = min(res, r1 + r2 + SGT ::query(1, n, 1, L, mid - 1) - c2);         }         ans[id] = res;       }     }     top = 0;     for (int i = n; i >= 1; i--) {       while (top && num[top] >= a[i]) top--;       st[++top] = i;       num[top] = a[i];       SGT ::modify(1, n, 1, top, 2 * i + a[i]);       for (auto u : Q[i]) {         int r1 = u.r1, r2 = i, c2 = u.c2, id = u.id;         int pos = upper_bound(num + 1, num + top + 1, c2) - num - 1, res = 1e9;         if (pos)           res = -(r1 + r2) + 2 * st[pos] + (now[id] < num[pos]) +                 abs(c2 - num[pos]);         if (pos + 1 <= top) {           int L = pos + 1, R = top;           int mid = upper_bound(num + L, num + R + 1, now[id]) - num;           if (mid <= R)             res = min(res, -(r1 + r2) + 1 + SGT ::query(1, n, 1, mid, R) - c2);           if (L < mid)             res = min(res, -(r1 + r2) + SGT ::query(1, n, 1, L, mid - 1) - c2);         }         ans[id] = min(ans[id], res);       }     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     scanf( %d , &q);     for (int i = 1, r1, c1, r2, c2; i <= q; i++) {       scanf( %d%d%d%d , &r1, &c1, &r2, &c2);       if (r1 <= r2)         Q[0][r2].push_back(query(r1, c1, c2, i));       else         Q[1][n - r2 + 1].push_back(query(n - r1 + 1, c1, c2, i));     }     solve(Q[0]);     reverse(a + 1, a + n + 1);     solve(Q[1]);     for (int i = 1; i <= q; i++) printf( %d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double EPS = 1E-9;   const int INF = 1000000000;   const long long INF64 = (long long)1E18;   const double PI = 3.1415926535897932384626433832795;   long long gcd(long long a, long long b) {     if (a < b) return gcd(b, a);     if (b == 0) return a;     return gcd(b, a % b);   }   int main() {     char *s = new char[2000000];     char *z = new char[2000000];     long long i, j, n, a, b, c, x = 0, y = 0, slen;     memset(s, 0, 2000000);     memset(z, 0, 2000000);     cin >> s;     slen = strlen(s);     for (i = 0; i < slen; ++i)       if (s[i] ==  x )         x++;       else         y++;     if (x > y) {       x = x - y;       for (i = 0; i < x; ++i) z[i] =  x ;     } else {       y = y - x;       for (i = 0; i < y; ++i) z[i] =  y ;     }     cout << z;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k, T;   long long doit(long long n, long long k) {     if (n == 1) return k * (k + 1) / 2;     long long tp = (n - 1) / k + 1, v1 = doit(tp, k), tp2 = (n - 1) % k + 1;     long long f1 = (tp - 1) * (k * k + 1), f2 = v1 - f1;     if (tp2 * k < f2)       return (f1 * 2 + tp2 * 2 * k - k + 1) * k / 2;     else if ((tp2 - 1) * k >= f2)       return (f1 * 2 - k + 3 + tp2 * 2 * k) * k / 2;     else       return (f1 * 2 - k + 1 + tp2 * 2 * k) * k / 2 + tp2 * k - f2 + 1;   }   long long solve(long long n, long long k) {     long long tp = (n - 1) / (k * k + 1) + 1, st = doit(tp, k);     if (n == st)       return tp * (k + 1);     else       return (n - tp + (n < st) - 1) / k + n - tp + (n < st);   }   int main() {     scanf( %d , &T);     while (T--) scanf( %lld%lld , &n, &k), printf( %lld n , solve(n, k));   }


#include <bits/stdc++.h>   using namespace std;   int t, n, m, a[5][200], ans;   vector<pair<int, int> > v, vec;   int getidx(int i, int j) { return (i - 1) * m + j; }   int geti(int idx) { return (idx - 1) / m; }   int getj(int idx) { return (((idx - 1) % m) + 1); }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> t;     while (t--) {       cin >> n >> m;       v.clear();       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= m; j++) {           cin >> a[i][j];           v.push_back({a[i][j], getidx(i, j)});         }       }       ans = 0;       sort(v.rbegin(), v.rend());       if (n < 4 || m == 1) {         for (int i = 0; i < n; i++) {           ans += v[i].first;         }       } else {         int ar[] = {0, 0, 0, 0, 1, 1, 1, 1};         do {           int tmp = 0;           vec.clear();           for (int i = 0; i < 8; i++) {             if (ar[i] == 1) {               int ii = geti(v[i].second);               int jj = getj(v[i].second);               vec.push_back({jj, ii});               tmp += v[i].first;             }           }           sort(vec.begin(), vec.end());           int ct = 1;           for (int i = 1; i < 4; i++)             if (vec[i].first != vec[i - 1].first) ct++;           if (ct != 2 || vec[1].first == vec[2].first ||               ((vec[1].second - vec[0].second + 4) % 2 ==                (vec[3].second - vec[2].second + 4) % 2)) {             ans = max(ans, tmp);           }         } while (next_permutation(ar, ar + 8));       }       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   const int INF = 2147483647;   using namespace std;   unsigned char like[7][7];   int fenzu[7];   int n, totjy[3];   int getnum(char l[50]) {     switch (l[0]) {       case  A :         return 0;       case  C :         if (l[1] ==  h )           return 1;         else           return 2;       case  T :         return 3;       case  D :         return 4;       case  S :         return 5;       case  H :         return 6;     }   }   void init_and_read() {     int i;     char pa[50], pb[50];     scanf( %d , &n);     memset(like, 0, sizeof(like));     for (i = 1; i <= n; i++) {       scanf( %s likes %s , &pa, &pb);       like[getnum(pa)][getnum(pb)] = 1;     }     for (i = 0; i < 3; i++) scanf( %d , &totjy[i]);   }   void Dec_To_Three(int x) {     int i = 0;     while (i < 7) {       fenzu[i] = x % 3;       x /= 3;       i++;     }   }   int Abs(int x) { return (x > 0) ? x : (-x); }   int max(int a, int b, int c) {     a = (a > b) ? a : b;     return (a > c) ? a : c;   }   void solve_and_print() {     int i, j, k, flag, peplo[3], jingyan[3], minidif = INF, maxlike = -INF;     int tmp, totlike;     for (i = 0; i <= 2186; i++) {       Dec_To_Three(i);       peplo[0] = peplo[1] = peplo[2] = 0;       for (j = 0; j <= 6; j++) {         peplo[fenzu[j]]++;       }       flag = 0;       for (j = 0; j <= 2; j++) {         if (!peplo[j]) {           flag = 1;           break;         }         jingyan[j] = totjy[j] / peplo[j];       }       if (flag) continue;       tmp = max(Abs(jingyan[0] - jingyan[1]), Abs(jingyan[0] - jingyan[2]),                 Abs(jingyan[1] - jingyan[2]));       if (tmp < minidif) {         minidif = tmp;         maxlike = -INF;       }       if (tmp == minidif) {         totlike = 0;         for (j = 0; j <= 6; j++) {           for (k = 0; k <= 6; k++) {             if ((fenzu[j] == fenzu[k]) && (like[j][k])) {               totlike++;             }           }         }       }       if (totlike > maxlike) maxlike = totlike;     }     printf( %d %d n , minidif, maxlike);   }   int main() {     init_and_read();     solve_and_print();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 1e6 + 7;   const long double maxx = 1e11;   int tmp[MAXN];   int main() {     int n, k;     cin >> n >> k;     string s;     cin >> s;     k--;     if (k >= n / 2) k = n - k - 1;     int ans = 0, l = 0, r = 0;     for (int i = 0, j = n - 1; i < j; i++, j--) {       tmp[i] = min(abs(s[i] - s[j]), 26 - abs(s[i] - s[j]));     }     for (int i = 1; i <= n / 2; i++) tmp[i] += tmp[i - 1];     for (int i = 0; i < n / 2; i++) {       if (tmp[i]) {         l = i;         break;       }     }     for (int i = 0; i < n / 2; i++)       if (tmp[i] == tmp[n / 2]) {         r = i;         break;       }     if (tmp[n / 2]) ans = tmp[n / 2] + min(abs(k - l), abs(k - r)) + abs(l - r);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, tmp, curr = 0;     cin >> n;     int v[n], res[n];     for (int i = 0; i < n; i++) {       cin >> tmp;       v[tmp] = i + 1;     }     for (int i = 0; i < n; i++) {       cin >> tmp;       if (v[tmp] > curr) {         res[i] = v[tmp] - curr;         curr = v[tmp];       } else         res[i] = 0;     }     for (int i = 0; i < n; i++) cout << res[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   int Time = 0;   string s;   bool dp[2][(int)1e5 + 10];   struct Node {     int nxt[26];     bool leaf;     Node() {       for (int i = 0; i < 26; i++) nxt[i] = -1;       leaf = 1;     }   } trie[(int)1e5 + 10];   void dodaj(string s) {     int niz[100010];     for (int i = 0; i < s.size(); i++) niz[i] = s[i] -  a ;     int tr = 0;     for (int i = 0; i < s.size(); i++) {       if (trie[tr].nxt[niz[i]] == -1) trie[tr].nxt[niz[i]] = ++Time;       trie[tr].leaf = 0;       tr = trie[tr].nxt[niz[i]];     }   }   bool uradi0(int tr, bool minn) {     if (trie[tr].leaf) {       dp[0][tr] = 1;       return 1;     }     for (int i = 0; i < 26; i++) {       if (trie[tr].nxt[i] != -1) minn = min(minn, uradi0(trie[tr].nxt[i], 1));     }     dp[0][tr] = 1 ^ minn;     return dp[0][tr];   }   bool uradi1(int tr, bool minn) {     if (trie[tr].leaf) {       dp[1][tr] = 0;       return 0;     }     for (int i = 0; i < 26; i++) {       if (trie[tr].nxt[i] != -1) minn = min(minn, uradi1(trie[tr].nxt[i], 1));     }     dp[1][tr] = 1 ^ minn;     return dp[1][tr];   }   int main() {     cin >> n >> k;     for (int i = 0; i < n; i++) {       cin >> s;       dodaj(s);     }     uradi0(0, 1);     uradi1(0, 1);     if (dp[0][0] == 1 && dp[1][0] == 1)       cout <<  First  << endl;     else if (dp[0][0] == 1)       cout <<  Second  << endl;     else if (dp[1][0] == 1)       cout << ((k % 2 == 1) ?  First  :  Second ) << endl;     else       cout <<  Second  << endl;   }


#include <bits/stdc++.h>   int main() {     int n, t, i;     scanf( %d%d , &n, &t);     if (n == 1 && t == 10)       printf( -1 );     else {       if (t == 10) {         printf( 1 );         for (i = 0; i < n - 1; i++) printf( 0 );       } else         for (i = 0; i < n; i++) printf( %d , t);     }     return 0;   }


#include <bits/stdc++.h>   int n;   char s[20];   int main() {     scanf( %d , &n);     getchar();     int ans = 0;     for (int i = 1; i <= n; i++) {       scanf( %s , s);       if (s[0] ==  T ) {         ans += 4;       } else if (s[0] ==  C ) {         ans += 6;       } else if (s[0] ==  O ) {         ans += 8;       } else if (s[0] ==  D ) {         ans += 12;       } else {         ans += 20;       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> get_pair(int a, int b) {     if (a > b) swap(a, b);     return {a, b};   }   template <class Cap, class Cost>   struct mcf_graph {    private:     int _n;     struct _edge {       int to, rev;       Cap cap;       Cost cost;     };     vector<pair<int, int>> pos;     vector<vector<_edge>> g;     vector<Cost> h;     vector<Cost> dist;     vector<int> pv, pe;     vector<bool> vis;     void norm(int s, int t) {       h.resize(_n, numeric_limits<Cost>::max());       h[s] = 0;       int ch = 1;       int it = _n;       while (ch-- && it--) {         for (int i = 0; i < _n; i++) {           if (h[i] == numeric_limits<Cost>::max()) continue;           for (auto e : g[i]) {             if (e.cap == 0) continue;             if (h[i] + e.cost < h[e.to]) {               h[e.to] = h[i] + e.cost;               ch = 1;             }           }         }         assert(it >= 0);       }       for (int i = 0; i < _n; i++) h[i] -= h[t];     }     bool dijkstra(int s, int t) {       pv.clear();       pe.clear();       vis.clear();       dist.clear();       dist.resize(_n, numeric_limits<Cost>::max());       pv.resize(_n, -1);       pe.resize(_n, -1);       vis.resize(_n, false);       priority_queue<pair<Cost, int>, vector<pair<Cost, int>>,                      greater<pair<Cost, int>>>           pq;       pq.push({0, s});       dist[s] = 0;       while (!pq.empty()) {         int x = pq.top().second;         pq.pop();         if (vis[x]) continue;         vis[x] = true;         if (x == t) break;         for (int i = 0; i < int(g[x].size()); ++i) {           auto e = g[x][i];           if (vis[e.to] || e.cap == 0) continue;           Cost cost = e.cost + h[x] - h[e.to];           if (dist[e.to] <= dist[x] + cost) continue;           dist[e.to] = dist[x] + cost;           pv[e.to] = x;           pe[e.to] = i;           pq.push({dist[e.to], e.to});         }       }       if (vis[t] == false) return false;       for (int i = 0; i < _n; ++i) {         if (!vis[i]) continue;         h[i] -= dist[t] - dist[i];       }       return true;     }       public:     mcf_graph() {}     mcf_graph(int n) : _n(n), g(n) {}     int add_edge(int from, int to, Cap cap, Cost cost) {       assert(from >= 0 && from < _n);       assert(to >= 0 && to < _n);       int m = int(pos.size());       pos.push_back({from, int(g[from].size())});       int from_id = int(g[from].size());       int to_id = int(g[to].size());       if (from == to) to_id++;       g[from].push_back(_edge{to, to_id, cap, cost});       g[to].push_back(_edge{from, from_id, 0, -cost});       return m;     }     struct edge {       int from, to;       Cap cap, flow;       Cost cost;     };     edge get_edge(int i) {       int m = int(pos.size());       assert(0 <= i && i < m);       auto _e = g[pos[i].first][pos[i].second];       auto _re = g[_e.to][_e.rev];       return edge{           pos[i].first, _e.to, _e.cap + _re.cap, _re.cap, _e.cost,       };     }     vector<edge> edges() {       int m = int(pos.size());       vector<edge> result(m);       for (int i = 0; i < m; ++i) result[i] = get_edge(i);       return result;     }     pair<Cap, Cost> flow(int s, int t, bool neg = false) {       return flow(s, t, numeric_limits<Cap>::max(), neg);     }     pair<Cap, Cost> flow(int s, int t, Cap flow_limit, bool neg = false) {       return slope(s, t, flow_limit, neg).back();     }     vector<pair<Cap, Cost>> slope(int s, int t, bool neg = false) {       return slope(s, t, numeric_limits<Cap>::max(), neg);     }     vector<pair<Cap, Cost>> slope(int s, int t, Cap flow_limit,                                   bool neg = false) {       assert(s >= 0 && s < _n);       assert(t >= 0 && t < _n);       assert(s != t);       h.clear();       if (!neg)         h.resize(_n, 0);       else         norm(s, t);       Cap flow = 0;       Cost cost = 0, prev = -1;       vector<pair<Cap, Cost>> result;       result.push_back({flow, cost});       while (flow < flow_limit) {         if (dijkstra(s, t) == false) break;         Cap c = flow_limit - flow;         for (int i = t; i != s; i = pv[i]) {           c = min(c, g[pv[i]][pe[i]].cap);         }         for (int i = t; i != s; i = pv[i]) {           auto &e = g[pv[i]][pe[i]];           e.cap -= c;           g[e.to][e.rev].cap += c;         }         Cost d = -h[s];         flow += c;         cost += c * d;         if (prev == d) result.pop_back();         result.push_back({flow, cost});         prev = d;       }       return result;     }   };   pair<vector<int>, vector<int>> bi_color(vector<pair<int, int>> &edges,                                           map<int, int> &id) {     int n = int(id.size());     vector<vector<int>> g(n);     for (auto e : edges) {       int u = id[e.first];       int v = id[e.second];       g[u].push_back(v);       g[v].push_back(u);     }     vector<int> x, y;     vector<int> col(n);     for (int i = 0; i < n; i++) {       if (col[i] > 0) continue;       queue<int> q;       col[i] = 1;       q.push(i);       x.push_back(i);       while (!q.empty()) {         auto u = q.front();         q.pop();         for (auto v : g[u]) {           if (col[v] == 0) {             col[v] = 3 - col[u];             q.push(v);             if (col[v] == 1)               x.push_back(v);             else               y.push_back(v);           } else             assert(col[v] == 3 - col[u]);         }       }     }     return {x, y};   }   void solve() {     int n, k;     cin >> n >> k;     vector<int> arr(1 << n);     for (int i = 0; i < (1 << n); i++) cin >> arr[i];     int max_edge = min((2 * n) * k + 12, n * (1 << (n - 1)));     map<pair<int, int>, bool> vis;     vector<pair<int, int>> edges;     using node = pair<int, pair<int, int>>;     priority_queue<node> pq;     vector<vector<pair<int, int>>> ord(1 << n);     for (int i = 0; i < (1 << n); i++) {       for (int j = 0; j < n; j++) {         ord[i].push_back({arr[i] + arr[i ^ (1 << j)], i ^ (1 << j)});       }       sort(ord[i].begin(), ord[i].end());       reverse(ord[i].begin(), ord[i].end());       pq.push({ord[i][0].first, {i, 0}});     }     while (!pq.empty()) {       auto a = pq.top();       pq.pop();       auto cost = a.first;       int u = a.second.first, i = a.second.second;       if (vis.find(get_pair(u, ord[u][i].second)) == vis.end()) {         vis[get_pair(u, ord[u][i].second)] = true;         edges.push_back({u, ord[u][i].second});       }       if (int(edges.size()) == max_edge) {         break;       }       if (i + 1 < n) {         pq.push({ord[u][i + 1].first, {u, i + 1}});       }     }     assert(int(edges.size()) == max_edge);     map<int, int> id;     for (int i = 0, j = 0; i < max_edge; i++) {       int a = edges[i].first;       int b = edges[i].second;       if (id.find(a) == id.end()) id[a] = j++;       if (id.find(b) == id.end()) id[b] = j++;     }     int _n = int(id.size());     mcf_graph<int, long long> g(_n + 3);     int _s = _n, _t = _n + 1;     long long inf = 1e16;     auto info = bi_color(edges, id);     for (int i = 0; i < int(info.first.size()); i++) {       g.add_edge(_s, info.first[i], 1, 0);     }     for (int i = 0; i < int(info.second.size()); i++) {       g.add_edge(info.second[i], _t, 1, 0);     }     map<int, int> first;     for (auto xx : info.first) first[xx] = true;     for (int i = 0; i < max_edge; i++) {       int a = id[edges[i].first];       int b = id[edges[i].second];       if (first[b]) swap(a, b);       g.add_edge(a, b, 1, -(arr[edges[i].first] + arr[edges[i].second]));     }     auto tt = g.flow(_s, _t, k, true);     cout << -tt.second <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     solve();   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = (long long)1e9 + 7;   const long double PI = 3.141592653589793238462643383279502884197;   long long fac[1] = {1}, inv[1] = {1};   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long mp(long long a, long long b) {     long long ret = 1;     while (b) {       if (b & 1) ret = ret * a % MOD;       a = a * a % MOD;       b >>= 1;     }     return ret;   }   long long cmb(long long r, long long c) {     return fac[r] * inv[c] % MOD * inv[r - c] % MOD;   }   int n[3];   int vec[3][200];   long long dp[201][201][201];   long long go(int a, int b, int c) {     if (dp[a][b][c] != -1) return dp[a][b][c];     long long mav = 0;     int nn[3] = {a, b, c};     for (int i = 0; i < 3; i++) {       int flag = 0;       for (int j = 0; j < 3; j++) {         if (i == j) continue;         if (nn[j] == n[j]) flag = 1;       }       if (flag) continue;       if (i == 0) mav = max(mav, go(a, b + 1, c + 1) + vec[1][b] * vec[2][c]);       if (i == 1) mav = max(mav, go(a + 1, b, c + 1) + vec[0][a] * vec[2][c]);       if (i == 2) mav = max(mav, go(a + 1, b + 1, c) + vec[0][a] * vec[1][b]);     }     return dp[a][b][c] = mav;   }   int main() {     memset(dp, -1, sizeof(dp));     scanf( %d %d %d , &n[0], &n[1], &n[2]);     for (int i = 0; i < 3; i++) {       for (int j = 0; j < n[i]; j++) scanf( %d , &vec[i][j]);       sort(vec[i], vec[i] + n[i], greater<long long>());     }     long long ans = go(0, 0, 0);     printf( %lld , ans);   }


#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   istream& operator>>(istream& in, pair<T1, T2>& a) {     in >> a.first >> a.second;     return in;   }   template <typename T1, typename T2>   ostream& operator<<(ostream& out, pair<T1, T2> a) {     out << a.first <<     << a.second;     return out;   }   template <typename T, typename T1>   T maxs(T& a, T1 b) {     if (b > a) a = b;     return a;   }   template <typename T, typename T1>   T mins(T& a, T1 b) {     if (b < a) a = b;     return a;   }   const long long maxn = 2000005;   long long p[maxn];   long long sz[maxn];   bool s1[maxn];   bool s2[maxn];   void clear(long long n = maxn) {     for (long long i = 0; i < maxn; i++) p[i] = i, sz[i] = 1;   }   long long root(long long first) {     while (first != p[first]) {       p[first] = p[p[first]];       first = p[first];     }     return first;   }   void merge(long long first, long long second) {     long long p1 = root(first);     long long p2 = root(second);     if (p1 == p2) return;     if (s1[p1] && s2[p1])       p[p2] = p1;     else if (s1[p2] && s2[p2])       p[p1] = p2;     else if (s1[p1] || s2[p1])       p[p2] = p1;     else       p[p1] = p2;   }   long long solve() {     long long n, m;     cin >> n >> m;     vector<long long> g[n + 1];     vector<pair<long long, long long> > edges;     vector<pair<long long, long long> > st;     for (long long i = 1; i < m + 1; i++) {       long long a, b;       cin >> a >> b;       g[a].push_back(b);       g[b].push_back(a);       edges.emplace_back(a, b);     }     long long s, t, ds, dt;     cin >> s >> t >> ds >> dt;     for (auto j : g[s]) {       s1[j] = 1;     }     for (auto j : g[t]) {       s2[j] = 1;     }     for (auto j : edges) {       if (j.first == s || j.first == t || j.second == s || j.second == t)         continue;       if (root(j.first) == root(j.second)) continue;       merge(j.first, j.second);       st.emplace_back(j.first, j.second);     }     long long cnts = 0, cntt = 0, cntst = 0;     set<long long> sts;     vector<long long> ss(n + 1, 0), tt(n + 1, 0);     for (long long i = 1; i < n + 1; i++) {       if (i == s || i == t) continue;       long long p = root(i);       if (s1[i]) ss[p] = i;       if (s2[i]) tt[p] = i;       sts.insert(p);     }     for (auto i : sts) {       if (ss[i] && tt[i])         cntst++;       else if (ss[i])         cnts++;       else         cntt++;     }     if (cnts > ds || cntt > dt || cntst + cntt + cnts > ds + dt) {       cout <<  No             <<   n ;       return 0;     }     if (cntst == 0 && (cnts + 1 > ds || cntt + 1 > dt)) {       cout <<  No             <<   n ;       return 0;     }     if (cntst == 0) {       st.emplace_back(s, t);       merge(s, t);       ds--, dt--;     }     for (auto i : sts) {       if (ss[i] && tt[i] == 0)         st.emplace_back(s, ss[i]), ds--, merge(s, ss[i]);       else if (tt[i] && ss[i] == 0)         st.emplace_back(t, tt[i]), dt--, merge(t, tt[i]);       else {         if (ds >= dt)           st.emplace_back(s, ss[i]), ds--, merge(s, ss[i]);         else           st.emplace_back(t, tt[i]), dt--, merge(t, tt[i]);       }     }     if (root(s) != root(t)) {       bool f = 0;       if (ds) {         for (auto i : g[s]) {           if (dt == 0 && i == t) continue;           if (root(i) != root(s)) {             f = 1;             st.emplace_back(s, i);             break;           }         }       }       if (f == 0 && dt) {         for (auto i : g[t]) {           if (ds == 0 && i == s) continue;           if (root(i) != root(t)) {             f = 1;             st.emplace_back(t, i);             break;           }         }       }       if (f == 0) {         cout <<  No               <<   n ;         return 0;       }     }     cout <<  Yes           <<   n ;     for (auto i : st) cout << i <<   n ;     return 0;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     clear();     long long t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int ar[500009], br[500009], cr[500009], tr[500009];   long long int fx[] = {-1, 1, 0, 0};   long long int fy[] = {0, 0, 1, -1};   map<long long int, long long int> mp;   vector<long long int> v;   string s;   struct evan {     long long int l, r, pos;   } st[500009];   bool com(evan i1, evan i2) { return (i1.r < i2.r); }   int main() {     long long int a, b, c, d, e, i, j, k, x, y, z, f, g, h, n, m;     cin >> a;     while (a--) {       cin >> b;       c = b / 4;       j = (b * 4) - b;       b -= c;       for (i = 1; i < b; i++) {         cout <<  9 ;       }       if (j % 4)         cout <<  8 ;       else {         cout <<  9 ;       }       for (i = 1; i <= c; i++) {         cout <<  8 ;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x1, x2, y1, y2, x, y;     cin >> x1 >> y1 >> x2 >> y2 >> x >> y;     int temp1 = abs(x1 - x2), temp2 = abs(y1 - y2);     int temp3 = temp1 / x, temp4 = temp2 / y;     if (temp1 % x == 0 && temp2 % y == 0 && temp3 % 2 == temp4 % 2)       cout <<  YES n ;     else       cout <<  NO n ;     return 0;   }


#include <bits/stdc++.h>   struct point {     double x, y, z;     point() {}     point(double _x, double _y, double _z) : x(_x), y(_y), z(_z) {}   };   const double eps = 1e-8;   double vlen(point p) { return sqrt(p.x * p.x + p.y * p.y + p.z * p.z); }   point xmult(point u, point v) {     point ret;     ret.x = u.y * v.z - v.y * u.z;     ret.y = u.z * v.x - u.x * v.z;     ret.z = u.x * v.y - u.y * v.x;     return ret;   }   point subt(point u, point v) {     point ret;     ret.x = u.x - v.x;     ret.y = u.y - v.y;     ret.z = u.z - v.z;     return ret;   }   int dot_online_in(point p, point l1, point l2) {     return (((vlen(xmult(subt(p, l1), subt(p, l2)))) > 0                  ? (vlen(xmult(subt(p, l1), subt(p, l2))))                  : -(vlen(xmult(subt(p, l1), subt(p, l2))))) < eps) &&            (l1.x - p.x) * (l2.x - p.x) < eps &&            (l1.y - p.y) * (l2.y - p.y) < eps && (l1.z - p.z) * (l2.z - p.z) < eps;   }   double x[10001], y[10001], z[10001], d[10001];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i <= n; i++) scanf( %lf %lf %lf , &x[i], &y[i], &z[i]);     double vp, vs, px, py, pz;     scanf( %lf %lf , &vp, &vs);     scanf( %lf %lf %lf , &px, &py, &pz);     double lo = 0, hi = 0;     for (int i = 1; i <= n; i++) {       d[i] = sqrt((x[i] - x[i - 1]) * (x[i] - x[i - 1]) +                   (y[i] - y[i - 1]) * (y[i] - y[i - 1]) +                   (z[i] - z[i - 1]) * (z[i] - z[i - 1]));       hi += d[i] / vs;     }     if (hi * vp < sqrt((x[n] - px) * (x[n] - px) + (y[n] - py) * (y[n] - py) +                        (z[n] - pz) * (z[n] - pz)))       printf( NO n );     else {       double X = -1, Y = -1, Z = -1;       while ((hi - lo) >= 1e-10) {         double mid = (lo + hi) / 2;         double s = mid * vs;         for (int i = 1; i <= n; i++)           if (s > d[i])             s -= d[i];           else {             double t = s / d[i];             X = x[i - 1] + (x[i] - x[i - 1]) * t;             Y = y[i - 1] + (y[i] - y[i - 1]) * t;             Z = z[i - 1] + (z[i] - z[i - 1]) * t;             if (!dot_online_in(point(X, Y, Z),                                point(x[i - 1], y[i - 1], z[i - 1]),                                point(x[i], y[i], z[i]))) {               X = x[i - 1] - (x[i] - x[i - 1]) * t;               Y = y[i - 1] - (y[i] - y[i - 1]) * t;               Z = z[i - 1] - (z[i] - z[i - 1]) * t;             }             break;           }         if (mid * vp >=             sqrt((X - px) * (X - px) + (Y - py) * (Y - py) + (Z - pz) * (Z - pz)))           hi = mid;         else           lo = mid;       }       printf( YES n );       printf( %.10lf n , lo);       printf( %.10lf %.10lf %.10lf n , X, Y, Z);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long h, w, n;   pair<long long, long long> a[2005];   long long fact[200005];   long long ifact[200005];   long long dp[2005];   long long exp(long long a, long long b) {     if (b == 0) return 1;     if (b == 1) return a;     if (b % 2 == 0) {       long long r = exp(a, b / 2);       return (r * r) % 1000000007;     }     long long r = exp(a, b - 1);     return (r * a) % 1000000007;   }   long long C(long long n, long long k) {     return (((fact[n] * ifact[k]) % 1000000007) * ifact[n - k]) % 1000000007;   }   int main() {     scanf( %lld %lld %lld , &h, &w, &n);     for (long long i = 0; i < n; i++) {       scanf( %lld %lld , &a[i].first, &a[i].second);       a[i].first--;       a[i].second--;     }     sort(a, a + n);     a[n++] = make_pair(h - 1, w - 1);     fact[0] = 1;     ifact[0] = 1;     for (long long i = 1; i <= max(w, h) * 2; i++) {       fact[i] = (fact[i - 1] * i) % 1000000007;       ifact[i] = exp(fact[i], 1000000007 - 2);     }     for (long long i = 0; i < n; i++) {       long long num = C(a[i].first + a[i].second, a[i].first);       for (long long j = 0; j < i; j++) {         if (a[j].first <= a[i].first && a[j].second <= a[i].second) {           int sub =               (dp[j] * C((a[i].first - a[j].first) + (a[i].second - a[j].second),                          a[i].first - a[j].first)) %               1000000007;           num = (num - sub + 1000000007) % 1000000007;         }       }       dp[i] = num;     }     cout << dp[n - 1] << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100000 + 2;   int lis[N], where[N], length[N], link[N], a[N], b[N];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     a[n] = INT_MAX;     int m;     cin >> m;     for (int i = 0; i < m; ++i) {       cin >> b[i];     }     sort(b, b + m);     fill(lis, lis + n + 2, INT_MAX);     fill(where, where + n + 2, -1);     lis[0] = 0;     for (int i = 0; i <= n; ++i) {       if (a[i] == -1) {         int fill = m - 1;         for (int index = n + 1; index > 0; --index) {           while (fill > 0 && b[fill - 1] > lis[index - 1]) {             --fill;           }           if (b[fill] > lis[index - 1] && b[fill] <= lis[index]) {             lis[index] = b[fill], where[index] = i;           }         }         link[i] = i - 1;         while (link[i] >= 0 && a[link[i]] != -1) {           --link[i];         }         length[i] = -1;       } else {         int index = lower_bound(lis, lis + n + 2, a[i]) - lis;         lis[index] = a[i], where[index] = i;         link[i] = where[index - 1];         length[i] = index;       }     }     int index = n, prv = -1;     while (index != -1) {       if (a[index] == -1) {         length[index] = length[prv] - 1;         int fill = m - 1;         while (b[fill] >= a[prv]) {           --fill;         }         a[index] = b[fill];         b[fill] = INT_MAX;         prv = index;         if (length[index] == 1) {           index = -1;         } else {           for (int i = 0; i < index; ++i) {             if (a[i] < a[index] && length[i] + 1 == length[index]) {               index = i;               break;             }           }           if (index == prv) {             index = link[index];           }         }       } else {         prv = index, index = link[index];       }     }     int ptr = 0;     for (int i = 0; i < n; ++i) {       if (a[i] == -1) {         while (b[ptr] == INT_MAX) {           ++ptr;         }         a[i] = b[ptr++];       }       cout << a[i] <<    ;     }     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100101;   int pre[maxn], ind[maxn], cnt[maxn], f[maxn];   vector<int> g[maxn], q;   int main() {     int n;     cin >> n;     for (int i = 2; i <= n; ++i) {       int l, r;       scanf( %d%d , &l, &r);       g[l].push_back(r);       g[r].push_back(l);       ind[l]++;       ind[r]++;     }     q.push_back(1);     for (int i = 0; i < q.size(); ++i) {       int now = q[i];       for (int j = 0; j < g[now].size(); ++j)         if (g[now][j] != pre[now]) {           pre[g[now][j]] = now;           q.push_back(g[now][j]);         }     }     bool flag = 1;     for (int i = (int)q.size() - 1; i >= 0; --i) {       int now = q[i];       int k = cnt[now] + (ind[now] > 3);       if (k) f[pre[now]]++;       if (ind[now] > 2) cnt[now]++;       cnt[pre[now]] += cnt[now];     }     int sum = cnt[1];     for (int i = 0; i < q.size(); ++i) {       int now = q[i];       for (int j = 0; j < g[now].size(); ++j)         if (g[now][j] != pre[now]) {           int k = sum - cnt[g[now][j]] - (ind[now] > 2) + (ind[now] > 3);           if (k) f[g[now][j]]++;         }     }     for (int i = 1; i <= n; ++i)       if (f[i] > 2) flag = 0;     if (flag)       printf( Yes n );     else       printf( No n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int next, to;   } a[400001];   int st[200001], vis[200001], fa[200001], last, cnt = 0, ans = 0, huan;   int roo[200001], roo2[200001];   void add(int x, int y) {     a[++cnt].to = y;     a[cnt].next = st[x];     st[x] = cnt;   }   void dfs(int x, int last) {     int i;     if (vis[x]) {       if (huan == 0) {         huan = 1;         roo[++roo[0]] = x;         roo2[roo[0]] = 1;       }       return;     }     vis[x] = 1;     for (i = st[x]; i; i = a[i].next)       if (a[i].to != last) dfs(a[i].to, x);   }   int main() {     int n, i, j;     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d , &fa[i]);       if (fa[i] == i) continue;       add(fa[i], i);       add(i, fa[i]);     }     for (i = 1; i <= n; i++) {       huan = 0;       if (vis[i] == 0) {         dfs(i, 0);         if (huan == 0) {           for (j = i; fa[j] != j; j = fa[j])             ;           roo[++roo[0]] = j;         }       }     }     for (i = 1; i <= roo[0]; i++)       if (roo2[i] == 0) break;     if (i <= roo[0]) {       ans = roo[0] - 1;       for (j = 1; j <= roo[0]; j++) fa[roo[j]] = roo[i];     } else {       ans = roo[0];       for (j = 1; j <= roo[0]; j++) fa[roo[j]] = roo[1];     }     printf( %d n , ans);     for (i = 1; i <= n; i++) printf( %d  , fa[i]);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, x;     string d;     int t, m = 0;     cin >> n >> x;     for (int i = 0; i < n; i++) {       cin >> d >> t;       if (d[0] ==  + ) x += t;       if (d[0] ==  - ) {         if (x >= t)           x -= t;         else           m++;       }     }     cout << x <<     << m;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t, n, pl;   string s;   int main() {     std::ios::sync_with_stdio(false);     cin >> t;     for (int qqw = 1; qqw <= t; qqw++) {       cin >> n;       cin >> s;       pl = -1;       for (int i = 1; i <= n; i++)         if (s[i - 1] ==  0 ) pl = i;       if (pl > 0) {         if (n % 2 == 0) {           if (pl <= n / 2) {             cout << pl <<     << n <<     << pl + 1 <<     << n <<   n ;             continue;           }           cout << 1 <<     << pl <<     << 1 <<     << pl - 1 <<   n ;         } else {           if (pl <= n / 2) {             cout << pl <<     << n <<     << pl + 1 <<     << n <<   n ;             continue;           }           cout << 1 <<     << pl <<     << 1 <<     << pl - 1 <<   n ;         }       } else {         cout << 1 <<     << n - 1 <<     << 2 <<     << n <<   n ;         continue;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct linearbasis {     long long base[64], flag, cnt;     bool add(long long x) {       for (int i = 62; ~i; i--) {         if (x >> i & 1) {           if (!base[i]) {             base[i] = x;             return false;           }           x ^= base[i];         }       }       flag = 1;       return true;     }     long long query_max(long long ans = 0) {       for (int i = 62; ~i; i--) {         if ((ans ^ base[i]) > ans) {           ans ^= base[i];         }       }       return ans;     }     long long query_min() {       for (int i = 0; i <= 62; i++) {         if (base[i]) {           return base[i];         }       }     }     void rebuild() {       cnt = 0;       for (int i = 62; i >= 0; i--) {         for (int j = i - 1; j >= 0; j--) {           if (base[i] >> j & 1) {             base[i] ^= base[j];           }         }       }       for (int i = 0; i <= 62; i++) {         if (base[i]) {           long long temp = base[i];           base[i] = 0;           base[cnt++] = temp;         }       }     }     long long query_k(long long k) {       k -= flag;       if (k == 0) return 0;       if (k >= 1ll << cnt) return -1;       long long ans = 0;       for (int i = 62; ~i; i--) {         if (k >> i & 1) {           ans ^= base[i];         }       }       return ans;     }     void init() { memset(base, 0, sizeof base), flag = cnt = 0; }   } a;   int prime[] = {2,  3,  5,  7,  11, 13, 17, 19, 23, 29,                  31, 37, 41, 43, 47, 53, 59, 61, 67};   const int mod = 1e9 + 7;   int main() {     int n, ans = 0;     cin >> n;     for (int i = 1; i <= n; i++) {       int x, value = 0;       cin >> x;       for (int j = 0; j < 19; j++) {         int cnt = 0;         while (x % prime[j] == 0) {           cnt++;           x /= prime[j];         }         if (cnt & 1) {           value |= 1 << j;         }       }       if (a.add(value)) {         ans++;       }     }     long long res = 1;     for (int i = 1; i <= ans; i++) {       res = res * 2 % mod;     }     printf( %lld n , res - 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   std::mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());   constexpr int MAXN = 1e9 + 7;   constexpr int INF = 0x3f3f3f3f;   constexpr long long INFLL = 0x3f3f3f3f3f3f3f3f;   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(nullptr);     std::cout.tie(nullptr);     int a, b;     cin >> a >> b;     if (a == b) {       cout << a <<     << 0 <<   n ;     } else {       int ans = min(a, b);       a -= ans;       b -= ans;       int left = max(a, b);       int ans2 = left / 2;       cout << ans <<     << ans2 <<   n ;     }   }


// precompute lookup table for each digit?       #include <iostream>   #include <unordered_map>   #include <utility>   #include <algorithm>   using namespace std;      #define MP make_pair<int, int>      int main()   {       unordered_map<int, int> lookup[10];       lookup[1].insert(MP(0, 1));       lookup[2].insert(MP(0, 2));       lookup[2].insert(MP(1, 21));       lookup[3].insert(MP(0, 3));       lookup[3].insert(MP(1, 13));       lookup[3].insert(MP(2, 23));       lookup[4].insert(MP(0, 4));       lookup[4].insert(MP(2, 14));       lookup[4].insert(MP(1, 41));       lookup[4].insert(MP(3, 43));       lookup[5].insert(MP(0, 5));       lookup[5].insert(MP(1, 51));       lookup[5].insert(MP(2, 52));       lookup[5].insert(MP(3, 53));       lookup[5].insert(MP(4, 54));       lookup[6].insert(MP(0, 6));       lookup[6].insert(MP(4, 16));       lookup[6].insert(MP(2, 26));       lookup[6].insert(MP(1, 61));       lookup[6].insert(MP(3, 63));       lookup[6].insert(MP(5, 65));       lookup[7].insert(MP(0, 7));       lookup[7].insert(MP(3, 17));       lookup[7].insert(MP(6, 27));       lookup[7].insert(MP(2, 37));       lookup[7].insert(MP(5, 47));       lookup[7].insert(MP(1, 57));       lookup[7].insert(MP(4, 67));       lookup[8].insert(MP(0, 8));       lookup[8].insert(MP(2, 18));       lookup[8].insert(MP(4, 28));       lookup[8].insert(MP(6, 38));       lookup[8].insert(MP(1, 81));       lookup[8].insert(MP(3, 83));       lookup[8].insert(MP(5, 85));       lookup[8].insert(MP(7, 87));       lookup[9].insert(MP(0, 9));       lookup[9].insert(MP(1, 19));       lookup[9].insert(MP(2, 29));       lookup[9].insert(MP(3, 39));       lookup[9].insert(MP(4, 49));       lookup[9].insert(MP(5, 59));       lookup[9].insert(MP(6, 69));       lookup[9].insert(MP(7, 79));       lookup[9].insert(MP(8, 89));       int t; cin >> t;       while (t--) {           int q, d; cin >> q >> d;           for (int i = 0; i < q; ++i) {               int x; cin >> x;               int mod = x % d;               if (lookup[d].at(mod) <= x) cout <<  YES  << endl;               else cout <<  NO  << endl;           }       }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     float h, l, ans;     cin >> h >> l;     ans = (l * l - h * h) / (2 * h);     cout << setprecision(13) << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 50;   const int mod = 1e9 + 7;   const int inf = (1 << 30);   vector<int> v[maxn][5], tpl;   int ted[maxn], com[maxn], tmp = 1;   bool visited[maxn];   bool dfs(int u, int d) {     visited[u] = 1;     bool rz = (ted[com[u]] == 1);     if (d == 1) {       com[u] = tmp;       ted[tmp]++;     }     for (auto w : v[u][d]) {       if (!visited[w]) {         rz &= dfs(w, d);       }     }     if (d == 0) tpl.push_back(u);     return rz;   }   bool dfs1(int u) {     visited[u] = 1;     bool rz = (ted[com[u]] == 1);     for (auto w : v[u][0])       if (!visited[w]) rz &= dfs1(w);     for (auto w : v[u][1])       if (!visited[w]) rz &= dfs1(w);     return rz;   }   int main() {     ios_base::sync_with_stdio(false);     int n, m;     cin >> n >> m;     for (int i = 1; i <= m; i++) {       int a, b;       cin >> a >> b;       v[a][0].push_back(b);       v[b][1].push_back(a);     }     for (int i = 1; i <= n; i++)       if (!visited[i]) dfs(i, 0);     memset(visited, 0, sizeof visited);     for (int i = n - 1; i >= 0; i--) {       int u = tpl[i];       if (!visited[u]) {         dfs(u, 1);         tmp++;       }     }     memset(visited, 0, sizeof visited);     long long ans = n;     for (int i = 1; i <= n; i++) {       if (!visited[i]) {         bool k = dfs1(i);         ans -= k;       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long am[20];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     vector<long long> a(n);     for (int i = 0, ThxDem = n; i < ThxDem; ++i) {       cin >> a[i];       for (int j = 0, ThxDem = 20; j < ThxDem; ++j)         if (a[i] & (1 << j)) am[j]++;       a[i] = 0;     }     for (int i = 0, ThxDem = n; i < ThxDem; ++i) {       for (int j = 0, ThxDem = 20; j < ThxDem; ++j)         if (am[j]) a[i] |= 1 << j, am[j]--;     }     long long ans = 0;     for (int i = 0, ThxDem = n; i < ThxDem; ++i) ans += a[i] * a[i];     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:400000000 )   int n, r;   string ans;   pair<int, int> f(int a, int b) {     if (a == 1 && b == 0) return pair<int, int>(0, 0);     if (a > 1 && b == 0) return pair<int, int>(1000000007LL, 1000000007LL);     if (a == 1 && b == 1) return pair<int, int>(1, 0);     if (a > 1 && b == 1) return pair<int, int>(2, a - 2);     pair<int, int> p = f(b, a % b);     return pair<int, int>(p.first + 1, p.second + a / b - 1);   }   void g(int a, int b) {     if (a == 1 && b == 0) return;     if (a == 1 && b == 1) {       ans +=  T ;       return;     }     if (a > 1 && b == 1) {       ans +=  TB ;       for (int i = 0; i < a - 2; i++) ans +=  B ;       return;     }     g(b, a % b);     if (ans[ans.size() - 1] ==  T ) {       ans +=  B ;       for (int i = 0; i < a / b - 1; i++) ans +=  B ;     } else {       ans +=  T ;       for (int i = 0; i < a / b - 1; i++) ans +=  T ;     }   }   int main() {     cin >> n >> r;     int mi = 1000000007LL, best = -1;     for (int i = 1; i < r + 1; i++) {       if (r > 1 && r == i) continue;       pair<int, int> p = f(r, i);       if (p.first + p.second == n && p.second < mi) mi = p.second, best = i;     }     if (best == -1)       cout <<  IMPOSSIBLE ;     else {       g(r, best);       cout << mi << endl << ans;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int U[5005], V[5005];   struct emm {     int a, b, x;   } a[5005];   bool cmp(emm x, emm y) { return x.x < y.x; }   struct Edge {     int v;     Edge *next;   } pool[5005 << 1], *h[5005];   int fa[5005], dep[5005], ans[5005];   int tot;   void addEdge(int u, int v) {     Edge *p = &pool[tot++];     p->v = v;     p->next = h[u];     h[u] = p;   }   void dfs(int u) {     for (Edge *p = h[u]; p; p = p->next) {       int v = p->v;       if (v == fa[u]) continue;       dep[v] = dep[u] + 1;       fa[v] = u;       dfs(v);     }   }   int LCA(int u, int v) {     if (dep[u] < dep[v]) swap(u, v);     while (dep[u] > dep[v]) {       u = fa[u];     }     if (u == v) return u;     while (fa[u] != fa[v]) {       u = fa[u];       v = fa[v];     }     return fa[u];   }   void update(int u, int v, int x) {     if (u == v) return;     while (u != v) {       ans[u] = x;       u = fa[u];     }   }   int check(int u, int v) {     int res = 0x3f3f3f3f;     if (u == v) return res;     while (u != v) {       res = min(res, ans[u]);       u = fa[u];     }     return res;   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       scanf( %d%d , &U[i], &V[i]);       addEdge(U[i], V[i]);       addEdge(V[i], U[i]);     }     dep[1] = 1;     dfs(1);     scanf( %d , &m);     for (int i = 1; i <= m; i++) scanf( %d%d%d , &a[i].a, &a[i].b, &a[i].x);     sort(a + 1, a + m + 1, cmp);     for (int i = 1; i <= m; i++) {       int t = LCA(a[i].a, a[i].b);       update(a[i].a, t, a[i].x);       update(a[i].b, t, a[i].x);     }     for (int i = 1; i <= m; i++) {       int t = LCA(a[i].a, a[i].b);       if (min(check(a[i].a, t), check(a[i].b, t)) != a[i].x) {         printf( -1 n );         return 0;       }     }     for (int i = 1; i < n; i++) {       if (dep[U[i]] < dep[V[i]]) swap(U[i], V[i]);       printf( %d  , max(ans[U[i]], 1));     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char a[1010];     cin >> a;     int l = strlen(a), dot;     for (int i = 0; i < l; i++) {       if (a[i] ==  . ) {         dot = i;       }     }     if (a[dot - 1] ==  9 ) {       cout <<  GOTO Vasilisa.  << endl;     } else {       if (a[dot + 1] >=  5 ) {         a[dot - 1]++;       }       for (int i = 0; i <= dot - 2; i++) {         cout << a[i];       }       cout << a[dot - 1] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e6 + 11;   int use[N], a[N], b[N];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       use[a[i]] = 1;     }     for (int j = 1; j <= n; j++) {       cin >> b[j];       use[b[j]] = 1;     }     int kol = 0;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) {         int d = a[i] ^ b[j];         if (d <= 2000000 && use[d] == 1) kol++;       }     if (kol % 2 == 0)       cout <<  Karen  << endl;     else       cout <<  Koyomi  << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int xans[200005];   bool pos;   vector<pair<int, int> > xoc[200005];   vector<pair<int, int> > V[200005];   int erased[200005];   queue<int> toErase;   int sgn(int v) { return abs(v) / v; }   vector<pair<int, int> > E[200005];   int vis[200005];   int cycleRoot;   bool assigned[200005];   bool arcUsed[200005];   void dfs(int u) {     vis[u] = 2;     for (int i = 0, v, x, i1, i2; i < E[u].size(); i++) {       v = E[u][i].first;       x = E[u][i].second;       if (!assigned[x]) {         i1 = xoc[x][1].first == u;         i2 = 1 - i1;         xans[x] = (xoc[x][i2].second == 1);         assigned[x] = true;         if (vis[v] != 2) dfs(v);       }     }   }   bool findCycle(int u) {     vis[u] = 1;     for (int i = 0, v, x; i < E[u].size(); i++) {       v = E[u][i].first;       x = E[u][i].second;       if (arcUsed[x]) continue;       arcUsed[x] = true;       if (vis[v]) {         cycleRoot = v;         return true;       } else if (findCycle(v)) {         return true;       }     }     return false;   }   void makeE(int c1) {     for (int i = 0, x, i1, i2, c2; i < V[c1].size(); i++) {       x = V[c1][i].first;       i1 = xoc[x][1].first == c1;       i2 = 1 - i1;       c2 = xoc[x][i2].first;       if (c1 < c2) {         E[c1].push_back(make_pair(c2, x));         E[c2].push_back(make_pair(c1, x));       }     }   }   void erase(int c) {     int x, s, i1, i2;     for (int i = 0; i < V[c].size(); i++) {       x = V[c][i].first;       s = V[c][i].second;       if (xoc[x].size() == 1) {         xans[x] = (xoc[x][0].second == 1);       } else {         i1 = (xoc[x][1].first == c);         i2 = 1 - i1;         if (xoc[x][i1].second == xoc[x][i2].second) {           xans[x] = xoc[x][i1].second == 1;           if (!erased[xoc[x][i2].first]) {             erased[xoc[x][i2].first] = 1;             erase(xoc[x][i2].first);           }         } else {           if (erased[xoc[x][i2].first]) {             xans[x] = xoc[x][i1].second == 1;           } else {             erased[xoc[x][i2].first] = 1;             erase(xoc[x][i2].first);           }         }       }     }   }   int main() {     scanf( %d%d , &n, &m);     int cs, x, s;     for (int i = 0; i < n; i++) {       scanf( %d , &cs);       for (int j = 0; j < cs; j++) {         scanf( %d , &x);         s = sgn(x);         x = abs(x) - 1;         V[i].push_back(make_pair(x, s));         xoc[x].push_back(make_pair(i, s));       }     }     for (int x = 0, c1, c2; x < m; x++) {       if (xoc[x].size() == 1) {         c1 = xoc[x][0].first;         if (!erased[c1]) {           erased[c1] = 1;           erase(c1);         }       } else if (xoc[x].size() == 2 && xoc[x][0].second == xoc[x][1].second) {         c1 = xoc[x][0].first;         if (!erased[c1]) {           erased[c1] = 1;           erase(c1);         }         c2 = xoc[x][1].first;         if (!erased[c2]) {           erased[c2] = 1;           erase(c2);         }       }     }     for (int i = 0; i < n; i++) {       if (!erased[i]) {         makeE(i);       }     }     pos = true;     for (int u = 0; u < n; u++) {       if (!erased[u] && !vis[u]) {         if (findCycle(u)) {           dfs(cycleRoot);         } else {           pos = false;           break;         }       }     }     if (!pos)       printf( NO n );     else {       printf( YES n );       for (int i = 0; i < m; i++) printf( %d , xans[i]);       printf(  n );     }   }


#include <bits/stdc++.h>   using namespace std;   const int MX = 1234567;   const double PI = acos(-1.0), EPS = 1e-9;   long long N, arr[MX];   long long gcd(long long a, long long b) {     while (a > 0 && b > 0) {       if (a > b)         a %= b;       else         b %= a;     }     return a + b;   }   int main() {     cin >> N;     long long g = 0;     for (int i = 0; i < N; i++) cin >> arr[i];     for (int i = 0; i < N; i++) {       g = gcd(g, arr[i]);     }     if (g != 1) {       cout <<  YES n ;       cout << 0 <<   n ;       return 0;     }     int oper = 0;     for (int i = 0; i < N; i++) {       if (arr[i] % 2 && arr[i + 1] % 2) {         i++;         oper++;       } else if (arr[i] % 2 && arr[i + 1] % 2 == 0) {         i++;         oper += 2;       }     }     cout <<  YES n ;     cout << oper <<   n ;     return 0;   }