#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   inline void smin(T &a, U b) {     if (a > b) a = b;   }   template <typename T, typename U>   inline void smax(T &a, U b) {     if (a < b) a = b;   }   template <typename T>   inline void gn(T &first) {     char c, sg = 0;     while (c = getchar(), (c >  9  || c <  0 ) && c !=  - )       ;     for ((c ==  -  ? sg = 1, c = getchar() : 0), first = 0; c >=  0  && c <=  9 ;          c = getchar())       first = (first << 1) + (first << 3) + c -  0 ;     if (sg) first = -first;   }   template <class T, class T1>   inline void gn(T &first, T1 &second) {     gn(first);     gn(second);   }   template <class T, class T1, class T2>   inline void gn(T &first, T1 &second, T2 &z) {     gn(first);     gn(second);     gn(z);   }   template <typename T>   inline void print(T first) {     if (first < 0) {       putchar( - );       return print(-first);     }     if (first < 10) {       putchar( 0  + first);       return;     }     print(first / 10);     putchar(first % 10 +  0 );   }   template <typename T>   inline void println(T first) {     print(first), putchar(  n );   }   template <typename T>   inline void printsp(T first) {     print(first), putchar(   );   }   template <class T, class T1>   inline void print(T first, T1 second) {     printsp(first), println(second);   }   template <class T, class T1, class T2>   inline void print(T first, T1 second, T2 z) {     printsp(first), printsp(second), println(z);   }   int power(int a, int b, int m, int ans = 1) {     for (; b; b >>= 1, a = 1LL * a * a % m)       if (b & 1) ans = 1LL * ans * a % m;     return ans;   }   int first[1555], second[1555];   int ans[1555], sz[1555];   vector<int> adj[1555];   void dfs(int u, int fa = -1) {     sz[u] = 1;     for (int i = 0; i < adj[u].size(); i++) {       int v = adj[u][i];       if (v == fa) continue;       dfs(v, u);       sz[u] += sz[v];     }   }   long double alp[1555][1555];   int id0;   bool cmp(int u, int v) { return alp[u][id0] + 1e-14 < alp[v][id0]; }   int id[1555];   void solve(int u, int fa, int *id, int n) {     if (n == 1) {       ans[id[0]] = u;       return;     }     for (int i = 1; i < n; i++) {       if (second[id[i]] < second[id[0]]) swap(id[0], id[i]);     }     ans[id[0]] = u;     id0 = id[0];     sort(id + 1, id + n, cmp);     int st = 1;     for (int i = 0; i < adj[u].size(); i++) {       int v = adj[u][i];       if (v == fa) continue;       solve(v, u, id + st, sz[v]);       st += sz[v];     }   }   int main() {     srand(time(NULL));     int n;     gn(n);     for (int i = 1; i < n; i++) {       int u, v;       gn(u, v);       u--;       v--;       adj[u].push_back(v);       adj[v].push_back(u);     }     int u = rand() % n;     dfs(u);     for (int i = 0; i < n; i++) gn(first[i], second[i]);     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++)         if (i != j)           alp[i][j] = atan2l(second[j] - second[i], first[j] - first[i]);     }     for (int i = 0; i < n; i++) id[i] = i;     solve(u, -1, id, n);     for (int i = 0; i < n; i++) printsp(ans[i] + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long dp[3005][3005];   string s, t;   int n, m;   inline long long solve(int l, int r) {     int id = r - l + 1;     if (r >= n) return 0ll;     if (l == 0) {       for (int i = r + 1; i < m; i++) {         if (t[i] != s[id]) return 0ll;         id++;       }       return 1ll * (n - id + 1ll);     }     long long &ret = dp[l][r];     if (ret != -1ll) return ret;     ret = 0ll;     if (r + 1 < m) {       if (s[id] == t[r + 1]) ret = (ret + solve(l, r + 1)) % 998244353;     } else       ret = (ret + solve(l, r + 1)) % 998244353;     if (l - 1 < m) {       if (s[id] == t[l - 1]) ret = (ret + solve(l - 1, r)) % 998244353;     } else       ret = (ret + solve(l - 1, r)) % 998244353;     return ret;   }   int main() {     memset((dp), (-1), sizeof((dp)));     ;     cin >> s >> t;     n = s.length();     m = t.length();     long long ans = 0ll;     for (int i = 0; i < n; i++) {       if (i < m && t[i] == s[0]) {         ans = (ans + 2 * solve(i, i)) % 998244353;       } else if (i >= m) {         ans = (ans + 2 * solve(i, i)) % 998244353;       }     }     printf( %lld n , ans);     ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long read() {     long long sign = 1, x = 0;     char s = getchar();     while (s >  9  || s <  0 ) {       if (s ==  - ) sign = -1;       s = getchar();     }     while (s >=  0  && s <=  9 ) {       x = (x << 3) + (x << 1) + s -  0 ;       s = getchar();     }     return x * sign;   }   void write(long long x) {     if (x < 0) putchar( - ), x = -x;     if (x / 10) write(x / 10);     putchar(x % 10 +  0 );   }   int n, k;   int a[(100 + 5)];   int main() {     int kase;     cin >> kase;     while (kase--) {       cin >> n;       if (n == 1 || n == 2) {         cout << 1 << endl;         continue;       }       int ans = (n + 1) / 2;       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[200000];   int s[200000];   int n, p, k;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int tc;     cin >> tc;     while (tc--) {       cin >> n >> p >> k;       for (int i = 0; i < n; ++i) cin >> a[i];       sort(a, a + n);       int mx;       if (a[0] <= p) {         mx = 1;       } else {         cout <<  0 n ;         continue;       }       s[0] = a[0];       for (int i = 1; i <= k - 2; ++i) {         s[i] = s[i - 1] + a[i];         if (s[i] <= p) mx = i + 1;       }       for (int i = 0; i <= k - 1; i++) {         int z = 0;         int y = 0;         for (int j = i + k - 1; j < n; j += k) {           if (z + a[j] > p) break;           z += a[j];           y++;         }         if (i > 0) {           int add = upper_bound(s, s + i, p - z) - s - 1;           if (add >= 0 && p - z >= s[add]) mx = max(mx, y * k + add + 1);         } else           mx = max(mx, y * k);       }       cout << mx <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[101], nxt, l, h;   int main(int argc, const char* argv[]) {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     int mn = 10001;     for (int i = 0; i < n; i++) {       nxt = i + 1;       nxt %= n;       if (mn > abs(a[i] - a[nxt])) {         mn = abs(a[i] - a[nxt]);         l = i;         h = nxt;       }     }     printf( %d %d n , l + 1, h + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, ans = 0;     cin >> n;     ans = (n * (n + 1)) / 2;     if (ans & 1)       cout <<  1  << endl;     else       cout <<  0  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Node {     int l, r;     Node(int l, int r) : l(l), r(r) {}     bool operator<(const Node &o) const {       return r - l == o.r - o.l ? r > o.r : r - l > o.r - o.l;     }   };   vector<int> event;   int arr[200000];   map<int, int> matching;   map<int, int> cloak_pos;   set<Node> heap;   int query[100000 + 10][3];   int query_pos[100000 + 10];   void modify(int pos, int delta) {     while (pos < event.size()) {       arr[pos] += delta;       pos += pos & -pos;     }   }   int sum(int pos) {     int ret = 0;     while (pos > 0) {       ret += arr[pos];       pos -= pos & -pos;     }     return ret;   }   int main() {     int n, q;     scanf( %d%d , &n, &q);     for (int i = 0; i < q; ++i) {       scanf( %d , &query[i][0]);       if (query[i][0] == 0) {         scanf( %d%d , &query[i][1], &query[i][2]);       }     }     matching[1] = n;     matching[n] = 1;     heap.insert(Node(1, n));     event.push_back(0);     for (int i = 0; i < q; ++i) {       if (query[i][0] > 0) {         int x = query[i][0];         if (cloak_pos.count(x)) {           int y = cloak_pos[x];           int l1, r1, l2, r2;           if (matching.count(y - 1)) {             l1 = matching[y - 1];             r1 = y - 1;             matching.erase(y - 1);             heap.erase(Node(l1, r1));           } else {             l1 = r1 = y;           }           if (matching.count(y + 1)) {             l2 = y + 1;             r2 = matching[y + 1];             matching.erase(y + 1);             heap.erase(Node(l2, r2));           } else {             l2 = r2 = y;           }           matching[l1] = r2;           matching[r2] = l1;           heap.insert(Node(l1, r2));           query_pos[i] = -y;           cloak_pos.erase(x);         } else {           Node cur = *heap.begin();           heap.erase(heap.begin());           int y = (cur.l + cur.r) / 2;           if ((cur.r - cur.l + 1) % 2 == 0) {             ++y;           }           matching.erase(cur.r);           if (cur.r != cur.l) {             matching.erase(cur.l);           }           event.push_back(y);           query_pos[i] = y;           if (y + 1 <= cur.r) {             matching[y + 1] = cur.r;             matching[cur.r] = y + 1;             heap.insert(Node(y + 1, cur.r));           }           if (cur.l <= y - 1) {             matching[y - 1] = cur.l;             matching[cur.l] = y - 1;             heap.insert(Node(cur.l, y - 1));           }           cloak_pos[x] = y;         }       }     }     sort(event.begin(), event.end());     event.erase(unique(event.begin(), event.end()), event.end());     for (int i = 0; i < q; ++i) {       if (query[i][0] > 0) {         if (query_pos[i] < 0) {           int y = -query_pos[i];           int t = lower_bound(event.begin(), event.end(), y) - event.begin();           modify(t, -1);         } else {           int y = query_pos[i];           int t = lower_bound(event.begin(), event.end(), y) - event.begin();           modify(t, +1);         }       } else {         int x =             lower_bound(event.begin(), event.end(), query[i][1]) - event.begin();         int y = upper_bound(event.begin(), event.end(), query[i][2]) -                 event.begin() - 1;         int ans = 0;         if (x <= y) {           ans = sum(y) - sum(x - 1);         }         printf( %d n , ans);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int k, n, s, p, b, c;     cin >> k >> n >> s >> p;     float a = (n * 1.0) / s;     b = ceil(a);     c = b * k;     float d = (c * 1.0) / p;     int t = ceil(d);     cout << t;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k, cur_div;   vector<long long> cnt;   bool check(long long x) {     long long tot = 0;     for (long long i = 0; i < 26; i++) {       tot += cnt[i] / x;       if (tot >= cur_div) {         return true;       }     }     return false;   }   void solve() {     string second;     cin >> n >> k;     cin >> second;     if (n == k) {       cout << n <<   n ;       return;     }     vector<long long> divs;     for (long long i = 1; i * i <= k; i++) {       if (k % i) continue;       long long div0 = i, div1 = k / i;       divs.push_back(div0);       if (div0 != div1) {         divs.push_back(div1);       }     }     cnt.assign(26, 0);     for (char &c : second) {       cnt[c -  a ]++;     }     long long ans = 1;     for (long long i = 0; i < divs.size(); i++) {       cur_div = divs[i];       long long l = 1, r = n / cur_div;       while (l <= r) {         long long mid = (l + r) >> 1;         if (check(mid)) {           ans = max(ans, mid * cur_div);           l = mid + 1;         } else {           r = mid - 1;         }       }     }     cout << ans <<   n ;   }   signed main() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   #pragma GCC optimization( unroll-loops )   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   void __print(int x) { cout << x; }   void __print(long x) { cout << x; }   void __print(long long x) { cout << x; }   void __print(unsigned x) { cout << x; }   void __print(unsigned long x) { cout << x; }   void __print(unsigned long long x) { cout << x; }   void __print(float x) { cout << x; }   void __print(double x) { cout << x; }   void __print(long double x) { cout << x; }   void __print(char x) { cout <<      << x <<     ; }   void __print(const char *x) { cout <<     << x <<    ; }   void __print(const string &x) { cout <<     << x <<    ; }   void __print(bool x) { cout << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cout <<  { ;     __print(x.first);     cout <<  , ;     __print(x.second);     cout <<  } ;   }   template <typename T>   void __print(const T &x) {     int first = 0;     cout <<  { ;     for (auto &i : x) cout << (first++ ?  ,  :   ), __print(i);     cout <<  } ;   }   void _print() { cout <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cout <<  ,  ;     _print(v...);   }   template <class T>   void remdup(vector<T> &v) {     sort((v).begin(), (v).end());     v.erase(unique((v).begin(), (v).end()), end(v));   }   template <typename T>   struct cmp {     bool operator()(const T &p1, const T &p2) {}   };   const long long N = 1e5 + 100;   const long long mod = 1e9 + 7;   const long long X = 2e5 + 100;   long long dp[205][205][205], n, kk;   string s, t;   long long solve(long long nn, long long k, long long a) {     if (nn == n) return 0;     if (dp[nn][k][a] != -1) return dp[nn][k][a];     long long a1 = 0;     long long a2 = 0;     if (t[0] == s[nn]) a1++;     if (t[1] == s[nn]) a2 = a;     long long ans = a2 + solve(nn + 1, k, a + a1);     for (long long i = (0); i < (2); ++i) {       if (k == 0) break;       a1 = 0, a2 = 0;       if (t[i] == t[0]) a1++;       if (t[i] == t[1]) a2 = a;       ans = max(ans, a2 + solve(nn + 1, k - 1, a + a1));     }     return dp[nn][k][a] = ans;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     ;     memset(dp, -1, sizeof(dp));     cin >> n >> kk;     cin >> s >> t;     cout << solve(0, kk, 0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     char b, c;     int n, m;     int l, r;     cin >> n >> m;     cin >> s;     for (int j = 1; j <= m; j++) {       cin >> l >> r >> b >> c;       for (int i = l - 1; i < r; i++) {         if (s[i] == b) {           s[i] = c;         }       }     }     for (int i = 0; i < n; i++) cout << s[i];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long r;     vector<long long> a;     cin >> r;     for (int i = 0; i < r; i++) {       long long aux;       cin >> aux;       a.push_back(aux);     }     a.push_back(a[0]);     long long n = 0, m = 1;     long long min = abs(a[0] - a[1]);     for (int i = 1; i < r; i++) {       if (abs(a[i] - a[i + 1]) < min) {         n = i % r;         m = (i + 1) % r;         min = abs(a[i] - a[i + 1]);       }     }     cout << n + 1 <<     << m + 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   uint64_t l, r, s;   set<uint64_t> S;   void f(uint64_t x) {     S.insert(x);     if (x < r) f(x * 10 + 4), f(x * 10 + 7);   }   int main() {     cin >> l >> r;     for (f(0); l <= r;) {       auto it = S.lower_bound(l);       s += (min(r, *it) - l + 1) * *it;       l = *it + 1;     }     cout << s <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   long long ab(long long x) { return x > 0LL ? x : -x; }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, k, sum = 0, x;     cin >> n >> k;     vector<long long> v;     for (long long i = 0; i < n; i++) {       cin >> x;       sum += x;       v.push_back(x);     }     long long ans = -1;     for (long long i = 0; i < k; i++) {       long long sum2 = 0;       for (long long j = i; j < n; j += k) sum2 += v[j];       ans = max(ans, ab(sum - sum2));     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char a[10010];   char b[10010], c[1010], d[1010];   int main() {     while (scanf( %s%s , a, b) != EOF) {       int len = strlen(a);       sort(a, a + len);       int flag = 0;       for (int i = 0; i < len; i++) {         if (a[i] !=  0 ) {           flag = i;           char t = a[i];           a[i] = a[0];           a[0] = t;           break;         }       }       if (strcmp(a, b) == 0) {         printf( OK n );       } else {         printf( WRONG_ANSWER n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long INF = LLONG_MAX;   void solve() {     long long k;     cin >> k;     string s;     cin >> s;     long long test[10] = {0};     long long sum = 0;     for (long long i = 0; i < s.size(); i++) {       int digit = s[i] -  0 ;       test[digit]++;       sum = sum + digit;     }     long long ans = 0;     for (int i = 0; i < 9; i++) {       for (long long j = 0; j < test[i]; j++) {         if (sum < k) {           ans++;           sum = sum + 9 - i;         }       }     }     cout << ans << endl;   }   int main() {     int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   vector<int> adj[N], nodesAtDepth[N];   int degree[N], Dist[N];   bool isDiam[N];   int n;   int bfs(int start) {     queue<pair<int, int>> q;     q.push({start, start});     Dist[start] = 0;     int mxDist = -1;     int mxNode = -1;     while (!q.empty()) {       int node = q.front().first;       int prev = q.front().second;       q.pop();       if (mxDist < Dist[node]) {         mxDist = Dist[node];         mxNode = node;       }       for (int to : adj[node]) {         if (to == prev) continue;         q.push({to, node});         Dist[to] = 1 + Dist[node];       }     }     assert(mxNode != -1);     return mxNode;   }   void dfs(int node, int par, int Depth) {     nodesAtDepth[Depth].push_back(node);     for (int child : adj[node]) {       if (child == par) continue;       dfs(child, node, Depth + 1);     }   }   void solve(int root) {     for (int d = 0; d < n + 3; ++d) {       nodesAtDepth[d].clear();     }     dfs(root, root, 0);     for (int d = 0; d < n + 3; ++d) {       int firstNode = -1;       for (int node : nodesAtDepth[d]) {         if (firstNode == -1) {           firstNode = node;           continue;         }         if (degree[firstNode] != degree[node]) {           return;         }       }     }     cout << root;     exit(0);   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     if (n == 1) {       cout << 1;       return 0;     }     for (int i = 0; i < n - 1; ++i) {       int u, v;       cin >> u >> v;       ++degree[u];       ++degree[v];       adj[u].push_back(v);       adj[v].push_back(u);     }     int end1 = bfs(1);     int end2 = bfs(end1);     int curr = end2;     vector<int> diam;     while (curr != end1) {       diam.push_back(curr);       for (int to : adj[curr]) {         if (Dist[to] == -1 + Dist[curr]) {           curr = to;           break;         }       }     }     diam.push_back(end1);     solve(end1);     solve(end2);     solve(diam[diam.size() / 2]);     queue<pair<int, int>> q;     q.push({diam[diam.size() / 2], diam[diam.size() / 2]});     while (!q.empty()) {       int node = q.front().first;       int par = q.front().second;       q.pop();       if (degree[node] == 1) {         solve(node);         cout << -1;         return 0;       }       for (int child : adj[node]) {         if (child == par) continue;         if (degree[child] > 2) continue;         q.push({child, node});       }     }     cout << -1;   }


#include <bits/stdc++.h>   using namespace std;   int h[4] = {0, 0, 1, -1};   int v[4] = {1, -1, 0, 0};   vector<vector<int> > adj;   bool *visited;   int num[501][501];   bool done = false;   int sourceR, sourceC, destR, destC;   void DFS(int vertix) {     if (!done) {       visited[vertix] = true;       for (int i = 0; i < adj[vertix].size(); i++) {         if (!done && visited[adj[vertix][i]] &&             adj[vertix][i] == num[destR - 1][destC - 1]) {           if (visited[vertix]) {             done = true;             cout <<  YES  << endl;             return;           }         }         if (!done && !visited[adj[vertix][i]]) {           DFS(adj[vertix][i]);         }       }     }   }   int main() {     int n, m;     cin >> n >> m;     visited = new bool[n * m];     vector<int> temp;     int cnt = 0;     char a[501][501];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         adj.push_back(temp);         cin >> a[i][j];         visited[cnt] = false;         num[i][j] = cnt++;       }     }     cin >> sourceR >> sourceC >> destR >> destC;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[i][j] ==  X ) {           visited[num[i][j]] = true;         }         for (int k = 0; k < 4; k++) {           if (i + h[k] >= 0 && i + h[k] < n && j + v[k] >= 0 && j + v[k] < m) {             adj[num[i][j]].push_back(num[i + h[k]][j + v[k]]);           }         }       }     }     DFS(num[sourceR - 1][sourceC - 1]);     if (!done) {       cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> v;     int max = 0;     int mi = 0;     for (int i = 0; i < n; ++i) {       int temp;       cin >> temp;       v.push_back(temp);       if (temp > max) {         max = temp;         mi = i;       }     }     for (int i = 0; i < mi; ++i) {       if (v[i + 1] <= v[i]) {         if (v[i] == v[i + 1] && v[i + 1] == max) continue;         cout <<  NO ;         return 0;       }     }     for (int i = n - 1; i > mi; i--) {       if (v[i] >= v[i - 1]) {         if (v[i] == v[i - 1] && v[i - 1] == max) continue;         cout <<  NO ;         return 0;       }     }     cout <<  YES ;     return 0;   }


#include <bits/stdc++.h>   const double PI = 3.1415926;   const int KL = 1e6;   using namespace std;   long long q, x, y, z, n, m, p[KL], mn = 1e9, mx = -1e9, ans;   string t;   vector<int> vec[KL];   set<int> s;   map<int, int> M;   int pr[KL], sz[KL];   int prfind(int node) {     if (pr[node] == node)       return node;     else       return pr[node] = prfind(pr[node]);   }   void make_group(int node1, int node2) {     int fa1 = prfind(node1);     int fa2 = prfind(node2);     if (fa1 == fa2) return;     if (sz[fa1] >= sz[fa2]) {       pr[fa2] = fa1;       sz[fa1] += sz[fa2];     } else {       pr[fa1] = fa2;       sz[fa2] += sz[fa1];     }   }   int main() {     scanf( %d , &n);     scanf( %d , &m);     for (int i = 0; i < m; i++) {       scanf( %d , &x);       for (int j = 0; j < x; j++) {         scanf( %d , &y);         vec[i].push_back(y);       }     }     for (int i = 1; i <= n; i++) {       pr[i] = i;       sz[i] = 1;     }     for (int i = 0; i < m; i++) {       for (int j = 1; j < vec[i].size(); j++) {         make_group(vec[i][j], vec[i][j - 1]);       }     }     for (int i = 1; i <= n; i++) {       cout << sz[prfind(i)] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, tmp;     cin >> n;     multiset<int> a;     for (int i = 0; i < n; i++) {       cin >> tmp;       a.insert(tmp);     }     int ans = 0;     while (!a.empty()) {       int h = 0;       while (a.lower_bound(h) != a.end()) {         a.erase(a.lower_bound(h));         h++;       }       if (h) ans++;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool sortbysec(const pair<int, int> a, const pair<int, int> b) {     return a.second < b.second;   }   int main() {     string s1;     cin >> s1;     string s2;     cin >> s2;     bool flag = false;     string ans =   0 ;     for (int i = 0; i < s1.length(); i++) {       if (int(s1[i]) < int(s2[i])) flag = true;     }     if (s1.length() != s2.length()) flag = true;     if (flag == false) {       for (int i = 0; i < s1.length(); i++) {         if (int(s1[i]) == int(s2[i]))           ans +=  z ;         else if (int(s1[i]) > int(s2[i]))           ans += s2[i];       }     }     if (flag == true)       cout <<  -1  << endl;     else       cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct dragon {     int sila;     int dodatek;   };   bool operator<(dragon A, dragon B) { return A.sila < B.sila; }   int main() {     int s, n;     cin >> s >> n;     vector<dragon> D(n);     for (int i = 0; i < n; i++) {       cin >> D[i].sila >> D[i].dodatek;     }     sort(D.begin(), D.end());     for (int p = 0; p < n; p++) {       if (s > D[p].sila)         s += D[p].dodatek;       else {         cout <<  NO  << endl;         return 0;       }     }     cout <<  YES  << endl;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   const double eps = 1e-12;   const int inf = 2000000000;   const long long int infLL = (long long int)1e18;   long long int MOD = 1000000007;   int MOD1 = 1000000007;   int MOD2 = 1000000009;   inline bool checkBit(long long int n, long long int i) {     return n & (1LL << i);   }   inline long long int setBit(long long int n, long long int i) {     return n | (1LL << i);     ;   }   inline long long int resetBit(long long int n, long long int i) {     return n & (~(1LL << i));   }   int dx[] = {0, 0, +1, -1};   int dy[] = {+1, -1, 0, 0};   inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }   inline bool isLeapYear(long long int year) {     return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0);   }   inline void normal(long long int &a) {     a %= MOD;     (a < 0) && (a += MOD);   }   inline long long int modMul(long long int a, long long int b) {     a %= MOD, b %= MOD;     normal(a), normal(b);     return (a * b) % MOD;   }   inline long long int modAdd(long long int a, long long int b) {     a %= MOD, b %= MOD;     normal(a), normal(b);     return (a + b) % MOD;   }   inline long long int modSub(long long int a, long long int b) {     a %= MOD, b %= MOD;     normal(a), normal(b);     a -= b;     normal(a);     return a;   }   inline long long int modPow(long long int b, long long int p) {     long long int r = 1LL;     while (p) {       if (p & 1) r = modMul(r, b);       b = modMul(b, b);       p >>= 1LL;     }     return r;   }   inline long long int modDiv(long long int a, long long int b) {     return modMul(a, modPow(b, MOD - 2));   }   bool comp(const pair<long long int, pair<long long int, long long int> > &p1,             const pair<long long int, pair<long long int, long long int> > &p2) {     return p1.first > p2.first;   }   bool comp1(const pair<long long int, long long int> &p1,              const pair<long long int, long long int> &p2) {     if (p1.first == p2.first) {       return p1.second > p2.second;     }     return p1.first < p2.first;   }   long long int converter(string a) {     long long int i, mul = 1LL, r, t, ans = 0LL;     if (a.length() == 0) return 0;     for (i = a.length() - 1; i >= 0; i--) {       t = a[i] -  0 ;       r = t % 10;       ans += (mul * r);       mul = mul * 10;     }     return ans;   }   int msb(unsigned x) {     union {       double a;       int b[2];     };     a = x;     return (b[1] >> 20) - 1023;   }   const int MAX = 300005;   long long int g[3][MAX], a[MAX];   long long int x, y, z, magic, n;   const int ex = 70;   const int lim = 1000;   int grundy(int a, int b, int c) {     set<long long int> s;     s.insert(a);     s.insert(b);     s.insert(c);     int val = 0;     while (s.find(val) != s.end()) ++val;     return val;   }   void calc() {     for (int i = 1; i <= lim; ++i) {       long long int cur1 = max(0LL, i - x);       long long int cur2 = max(0LL, i - y);       long long int cur3 = max(0LL, i - z);       g[0][i] = grundy(g[0][cur1], g[1][cur2], g[2][cur3]);       g[1][i] = grundy(g[0][cur1], inf, g[2][cur3]);       g[2][i] = grundy(g[0][cur1], g[1][cur2], inf);     }   }   void findPeriod() {     magic = 0;     for (int perLen = 1; !magic; ++perLen) {       int f = 1;       for (int i = ex; i < ex + perLen && f; ++i) {         for (int j = i; j <= lim && f; j += perLen) {           if (g[0][i] != g[0][j] || g[1][i] != g[1][j] || g[2][i] != g[2][j])             f = 0;         }       }       if (f) magic = perLen;     }   }   int ask(long long int pile, int state) {     pile = max(0LL, pile);     if (pile <= lim)       return g[state][pile];     else       return g[state][(pile - ex) % magic + ex];   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cout.unsetf(ios::floatfield);     cout.precision(20);     cout.setf(ios::fixed, ios::floatfield);     ;     int t;     cin >> t;     while (t--) {       cin >> n >> x >> y >> z;       calc();       findPeriod();       if (magic >= 30) {         cout <<  MAgic  << magic <<   n ;         return 0;       }       long long int nimber = 0;       for (int i = 1; i <= n; ++i) {         cin >> a[i];         nimber ^= ask(a[i], 0);       }       int ans = 0;       for (int i = 1; i <= n; ++i) {         long long int save = nimber ^ ask(a[i], 0);         long long int temp = save ^ ask(a[i] - x, 0);         if (!temp) ans++;         temp = save ^ ask(a[i] - y, 1);         if (!temp) ans++;         temp = save ^ ask(a[i] - z, 2);         if (!temp) ans++;       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long qpow(long long x, long long k, long long mod) {     long long ret = 1;     while (k) {       if (k & 1) {         ret = ret * x;         ret = ret % mod;       }       x = x * x;       x = x % mod;       k = (k >> 1);     }     return ret;   }   const int Maxn = 1005;   const int md = 998244353;   int n, m;   int a[Maxn][Maxn];   long long e[Maxn][Maxn];   long long inv[Maxn * Maxn];   long long cnt[2][Maxn];   int r, c;   vector<pair<int, pair<int, int> > > vv;   void pre() {     for (int i = 1; i < Maxn * Maxn; i++) {       inv[i] = qpow(i, md - 2, md);     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         scanf( %d , a[i] + j);         vv.push_back(pair<int, pair<int, int> >(a[i][j], pair<int, int>(i, j)));       }     }     scanf( %d%d , &r, &c);     pre();     sort((vv).begin(), (vv).end());     long long sume = 0, sumx = 0, sumx2 = 0, sumy = 0, sumy2 = 0, ans = 0;     for (int i = 0, j = 0; i < vv.size(); i++) {       if (i && vv[i].first != vv[i - 1].first) {         for (; j < i; j++) {           long long nx = vv[j].second.first, ny = vv[j].second.second;           sume = (sume + e[nx][ny]) % md;           sumx = (sumx + nx) % md;           sumx2 = (sumx2 + nx * nx) % md;           sumy = (sumy + ny) % md;           sumy2 = (sumy2 + ny * ny) % md;         }       }       long long x = vv[i].second.first, y = vv[i].second.second;       long long tmp = (sume + sumx2 + sumy2 - sumx * x * 2 - sumy * y * 2) % md;       if (j) tmp = (tmp * inv[j] + x * x + y * y) % md;       if (tmp < 0) tmp += md;       e[x][y] = tmp;     }     printf( %lld n , e[r][c]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[100050], cnt = 0;   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     for (int i = 0; i < n; i++)       if (a[i] > cnt) cnt++;     cout << cnt + 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   int main() {     int N;     cin >> N;     pair<char, int> list[N];     for (int i = 0; i < N; i++) cin >> list[i].first >> list[i].second;     int initial = 0;     set<int> presents;     for (int i = 0; i < N; i++) {       int count = 0;       char sign = list[i].first;       int id = list[i].second;       if (sign ==  + ) {         presents.insert(id);       } else if (sign ==  - ) {         if (presents.count(id)) {           presents.erase(id);         } else           initial++;       } else         assert(false);     }     presents.clear();     int maxi = initial;     int count = initial;     for (int i = 0; i < N; i++) {       char sign = list[i].first;       int id = list[i].second;       if (sign ==  + ) {         count++;         presents.insert(id);       } else if (sign ==  - ) {         count--;         if (presents.count(id)) presents.erase(id);       }       maxi = max(maxi, count);     }     cout << maxi << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int rozmiar_kubelka = 356;   int n, m;   vector<int> her;   vector<pair<char, int> > mov;   int dp[(1 << 20)];   void policz() {     dp[0] = 0;     int a = 1;     for (; a < (1 << m); a++) {       int c = __builtin_popcount(a);       c = m - c;       auto akt = mov[c];       if (akt.second == 1)         dp[a] = -1000000000;       else         dp[a] = 1000000000;       if (akt == make_pair( p , 1)) {         int it = 0;         for (int i = 1; true; i *= 2) {           if (i & a) {             dp[a] = dp[a ^ i] + her[it];             break;           }           it++;         }       }       if (akt == make_pair( p , 2)) {         int it = 0;         for (int i = 1; true; i *= 2) {           if (i & a) {             dp[a] = dp[a ^ i] - her[it];             break;           }           it++;         }       }       if (akt == make_pair( b , 1)) {         int it = m - 1;         for (int i = 1; i <= a; i *= 2) {           it--;           if (i & a) {             dp[a] = max(dp[a], dp[a ^ i]);           }         }       }       if (akt == make_pair( b , 2)) {         int it = m - 1;         for (int i = 1; i <= a; i *= 2) {           it--;           if (i & a) {             dp[a] = min(dp[a], dp[a ^ i]);           }         }       }     }   }   int main() {     vector<int> vec;     scanf( %d , &n);     for (int i = 0; i < (n); ++i) {       int a;       scanf( %d , &a);       vec.push_back(a);     }     scanf( %d , &m);     sort(vec.begin(), vec.end());     for (int i = ((int)(n)) - 1; i >= (n - m); --i) her.push_back(vec[i]);     for (int i = 0; i < (m); ++i) {       char p;       int a;       scanf( %c%c%d , &p, &p, &a);       mov.push_back({p, a});     }     policz();     printf( %d , dp[(1 << m) - 1]);   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long t;     cin >> t;     for (long long _ = 0; _ < t; ++_) {       long long n;       cin >> n;       vector<long long> a(n + 1);       for (long long i = 0; i < n; ++i) {         cin >> a[i];       }       long long l = a[0];       long long r = n;       long long cur = l;       string ans =  Yes ;       for (long long i = 0; i < n; ++i) {         if (a[i] != cur) {           ans =  No ;         }         ++cur;         if (a[i] == r) {           r = l - 1;           l = a[i + 1];           cur = l;         }       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char str[1000];   int main() {     int n, k;     while (scanf( %d %d , &n, &k) == 2) {       scanf( %s , str + 1);       int left = k - 1;       int right = n - k;       int di;       if (right >= left) {         di = 1;         for (int i = k; i > 1; i--) printf( LEFT n );       } else {         di = 2;         for (int i = k; i < n; i++) printf( RIGHT n );       }       if (di == 1) {         for (int i = 1; i <= n; i++) {           printf( PRINT %c n , str[i]);           if (i != n) printf( RIGHT n );         }       } else {         for (int i = n; i >= 1; i--) {           printf( PRINT %c n , str[i]);           if (i != 1) printf( LEFT n );         }       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int a, b, c, d;     cin >> a >> b >> c >> d;     if (a * d < c * b) {       int g = gcd(b * c - a * d, b * c);       cout << ((b * c - a * d) / g) <<  /  << (b * c / g) << endl;     } else {       int g = gcd(a * d - b * c, a * d);       cout << ((a * d - b * c) / g) <<  /  << (a * d / g) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int x, y;     long double maxd = 0.00000000;     long long int ans = 0;     long long int n;     cin >> n;     while (n--) {       long long int a, b;       cin >> a >> b;       ans = max(ans, (a + b));     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int maxn = 1e5 + 5;   const int mod = 1e9 + 7;   vector<int> v[26];   int main() {     int n;     cin >> n;     string s;     cin >> s;     for (int i = 0; i < n; i++) v[s[i] -  a ].push_back(i);     int m;     cin >> m;     while (m--) {       string s2;       cin >> s2;       int t[26];       memset(t, 0, sizeof(t));       for (int i = 0; i < s2.size(); i++) t[s2[i] -  a ]++;       int ans = -1;       for (int i = 0; i < 26; i++) {         if (t[i]) ans = max(ans, v[i][t[i] - 1] + 1);       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   const int N = 100005;   int solve(int n, int k, int cnt[]) {     if (k == n || cnt[0] == 0 || cnt[1] == 0) {       return 1 - cnt[1] % 2;     }     if ((n - k) / 2 < cnt[0] && (n - k) / 2 < cnt[1]) {       if ((n - k) % 2 == 0)         return 1;       else         return 0;     }     if ((n - k) / 2 >= cnt[0]) {       return 1 - k % 2;     }     return 1;   }   int main() {     int n, k;     scanf( %d%d , &n, &k);     int cnt[2];     cnt[0] = cnt[1] = 0;     for (int i = 0; i < n; i++) {       int tmp;       scanf( %d , &tmp);       cnt[tmp % 2]++;     }     printf( %s , solve(n, k, cnt) ?  Daenerys  :  Stannis );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(){    int T; cin >> T;     long long A[114514];     while(T--){     int N; cin >> N;      long long S = 0;      for(int i = 0; i < N; i++){      cin >> A[i]; S += A[i];      }     sort(A, A+N, greater<long long>());      if(S == 0) cout << 0 <<   n ;      else cout << max({A[1] * (N-1) - S, A[0] * (N-1) - S, N-2 - (S-1) % (N-1)}) <<   n ;     }   }


#include <bits/stdc++.h>   #define ll long long int   #define vi vector<int>   #define vll vector<long long int>   #define MAX(a, b) ((a) > (b) ? (a) : (b))   #define MIN(a, b) ((a) < (b) ? (a) : (b))   #define ABS(x) ((x) < 0 ? -(x) : (x))   #define setpr(x, y) cout << fixed << setprecision(x) << y   #define tr(x) cout << (#x) <<   =   << (x) <<   n ;   using namespace std;   void solver(void);   ll MOD = 1e9 + 7;   double pi = 2 * acos(0.0);   //vector<vector<ll>> mat( n , vector<ll> (m, 0));      int main()   {       cin.tie(NULL);       ios_base::sync_with_stdio(false);       int t;       cin >> t;       while (t--)           solver();   }   void solver(void)   {       //input       ll n;       cin >> n;       vll v(n);       for (ll i = 0; i < n; i++)       {           v[i] = i + 1;       }       if (n % 2 == 0)       {              for (ll i = 0; i < n - 1; i = i + 2)           {               swap(v[i], v[i + 1]);           }       }       else       {           for (ll i = 0; i <= n - 3; i = i + 2)           {               swap(v[i], v[i + 1]);           }           swap(v[n - 2], v[n - 1]);       }       for (ll i = 0; i < n; i++)       {           cout << v[i] <<    ;       }       cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200005;   long long a[maxn];   int n;   long long k;   long long d[maxn];   int main() {     cin >> n >> k;     for (int i = 1; i <= n; i++) scanf( %I64d , &a[i]);     long long sum = 0;     int num = 0;     for (int i = 1; i <= n; i++) {       d[i] = sum - (a[i] * (n - i) * (i - num - 1));       if (d[i] < k) {         printf( %d n , i);         num++;       } else         sum += a[i] * (i - num - 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool check(string s) {     int count = 0;     for (char el : s) {       if (el ==  ( ) {         count++;       } else {         count--;       }       if (count < 0) return false;     }     return true;   }   void solve() {     int n;     cin >> n;     string s;     cin >> s;     if (s[0] ==  )  || s[s.size() - 1] ==  (  || s.size() % 2) {       cout <<  :(  << endl;       return;     }     int in = 0, out = 0;     for (char el : s) {       in += (el ==  ( );       out += (el ==  ) );     }     if (in > n / 2 || out > n / 2) {       cout <<  :(  << endl;       return;     }     int first = (n / 2) - in;     int second = (n / 2) - out;     int count = 0;     for (int i = 0; i < n; i++) {       if (s[i] ==  ? ) {         if (first > 0) {           s[i] =  ( ;           first--;           count++;         } else {           s[i] =  ) ;           second--;           count--;         }       } else if (s[i] ==  ( ) {         count++;       } else {         count--;       }       if (count == 0 && i != n - 1) {         cout <<  :(  << endl;         return;       } else if (count < 0) {         cout <<  :(  << endl;         return;       }     }     cout << (check(s) ? s :  :( ) << endl;   }   int main() { solve(); }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, j;     cin >> n;     vector<int> ct[n + 1];     for (i = 0; i < 2 * n; i++) {       int x;       cin >> x;       ct[x].push_back(i);     }     int p1 = 0, p2 = 0;     long long ans = 0;     for (i = 1; i <= n; i++) {       ans += min(abs(ct[i][0] - p1) + abs(ct[i][1] - p2),                  abs(ct[i][0] - p2) + abs(ct[i][1] - p1));       p1 = ct[i][0];       p2 = ct[i][1];     }     cout << ans << endl;   }


#include <bits/stdc++.h>   const int N = 1e6 + 7;   const int INF = 0x3f3f3f3f;   const int mod = 1e9 + 7;   const double eps = 1e-7;   using namespace std;   int a[N], s[N];   map<int, int> asum, ssum;   map<int, vector<int> > pos;   map<int, int> size;   int main() {     int n, m, k, S;     cin >> m >> k >> n >> S;     for (int i = 1; i <= m; i++) {       scanf( %d , a + i);       asum[a[i]]++;     }     for (int i = 1; i <= S; i++) {       scanf( %d , s + i);       ssum[s[i]]++;     }     for (int i = 1; i <= m; i++) {       if (ssum[a[i]] > 0) {         pos[a[i]].push_back(i);       }     }     for (auto x : ssum) {       if (asum[x.first] < x.second) {         puts( -1 );         return 0;       }     }     for (auto x : pos) {       size[x.first] = x.second.size();     }     int p, q, l, r, minl, maxr;     bool f;     bool flag = 1;     for (int num = 1; num <= n; num++) {       p = (num - 1) * k;       f = 0;       minl = INF;       maxr = -1;       for (auto x : pos) {         q = upper_bound(x.second.begin(), x.second.end(), p) - x.second.begin();         if (q + ssum[x.first] > size[x.first]) {           f = 1;           break;         }         minl = min(minl, x.second[q]);         maxr = max(maxr, x.second[q + ssum[x.first] - 1]);       }       if (f) break;       if (m - maxr < (n - num) * k)         continue;       else {         printf( %d n , max(0, maxr - p - k));         int cnt = maxr - p;         bool ff = 1;         for (int i = p + 1; i <= maxr; i++) {           if (cnt <= k) break;           if (ssum[a[i]] == 0) {             printf( %s%d , ff ?    :    , i);             cnt--;             ff = 0;           } else {             ssum[a[i]]--;           }         }         cout << endl;         flag = 0;         break;       }     }     if (flag) puts( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   long long mypow(long long base, long long exp) {     long long res = 1;     while (exp) {       if (exp & 1) res = (res * base) % mod;       exp >>= 1, base = (base * base) % mod;     }     return res;   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long mult(long long a, long long b) {     if (a < 0) {       a += mod;     }     if (b < 0) {       b += mod;     }     return ((a % mod) * (b % mod)) % mod;   }   long long add(long long a, long long b) {     if (a < 0) {       a += mod;     }     if (b < 0) {       b += mod;     }     return (a % mod + b % mod) % mod;   }   long long sub(long long a, long long b) {     if (a < 0) {       a += mod;     }     if (b < 0) {       b += mod;     }     return (a % mod + mod - b % mod) % mod;   }   void err(istream_iterator<string> it) {}   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a <<   |  ;     err(++it, args...);   }   const long long inf = 1e18;   const int nax = 1e5 + 5;   void SolveTestCase() {     long long n;     cin >> n;     long long a[n];     long long sum = 0;     for (long long i = 0; i < n; i++) {       cin >> a[i];       sum += a[i];     }     long long sum2 = 0;     for (long long i = 0; i < n; i++) {       sum2 += a[i];       if (sum2 >= (sum + 1) / 2) {         cout << i + 1;         break;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     for (long long i = 0; i < t; i++) {       SolveTestCase();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 1000 * 1000 + 5;   bool mark[4][maxN];   int n, m, comp;   inline void dfs(int x, int y) {     if (mark[x][y]) return;     mark[x][y] = true;     if (x == 0 && y == 1) mark[3][1] = true;     if (x == 0 && y == m) mark[1][1] = true;     if (x == 1 && y == 1) mark[0][m] = true;     if (x == 1 && y == n) mark[2][m] = true;     if (x == 2 && y == 1) mark[3][n] = true;     if (x == 2 && y == m) mark[1][n] = true;     if (x == 3 && y == m) mark[2][1] = true;     if (x == 3 && y == 1) mark[0][1] = true;     if (x == 0) {       int dr = m - y;       int dl = y - 1;       int dd = n - 1;       int xr = 1 + min(dr, dd), yr = y + min(dr, dd);       int xl = 1 + min(dl, dd), yl = y - min(dl, dd);       (xr == n) ? dfs(2, yr) : dfs(1, xr);       (xl == n) ? dfs(2, yl) : dfs(3, xl);     }     if (x == 2) {       int dr = m - y;       int dl = y - 1;       int du = n - 1;       int xr = n - min(dr, du), yr = y + min(dr, du);       int xl = n - min(dl, du), yl = y - min(dl, du);       (xr == 1) ? dfs(0, yr) : dfs(1, xr);       (xl == 1) ? dfs(0, yl) : dfs(3, xl);     }     if (x == 1) {       int dd = n - y;       int du = y - 1;       int dl = m - 1;       int xu = y - min(du, dl), yu = m - min(du, dl);       int xd = y + min(dd, dl), yd = m - min(dd, dl);       (yu == 1) ? dfs(3, xu) : dfs(0, yu);       (yd == 1) ? dfs(3, xd) : dfs(2, yd);     }     if (x == 3) {       int dd = n - y;       int du = y - 1;       int dr = m - 1;       int xu = y - min(du, dr), yu = 1 + min(du, dr);       int xd = y + min(dd, dr), yd = 1 + min(dd, dr);       (yu == m) ? dfs(1, xu) : dfs(0, yu);       (yd == m) ? dfs(1, xd) : dfs(2, yd);     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       if (!mark[0][i]) {         comp++;         dfs(0, i);       }       if (!mark[2][i]) {         comp++;         dfs(2, i);       }     }     for (int i = 1; i <= n; i++) {       if (!mark[1][i]) {         comp++;         dfs(1, i);       }       if (!mark[3][i]) {         comp++;         dfs(3, i);       }     }     printf( %d n , comp);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 100;   const long double INF = 2e30;   struct node {     int id;     long double da, db, len;     node(int _id = 0, long double _da = 0, long double _db = 0,          long double _len = 0) {       id = _id;       da = _da;       db = _db;       len = _len;     }   };   node a[maxn];   int n;   double ax, ay, bx, by, tx, ty;   double x[maxn], y[maxn];   long double len[maxn], da[maxn], db[maxn];   bool cmpb(node a, node b) {     long double ans1 = a.db - a.len;     long double ans2 = b.db - b.len;     return ans1 < ans2;   }   bool cmpa(node a, node b) {     long double ans1 = a.da - a.len;     long double ans2 = b.da - b.len;     return ans1 < ans2;   }   void solve() {     long double sum = 0;     for (int i = 0; i < n; i++) {       a[i].id = i;       long double dx, dy;       dx = ax - x[i];       dy = ay - y[i];       a[i].da = sqrt(dx * dx + dy * dy);       dx = bx - x[i];       dy = by - y[i];       a[i].db = sqrt(dx * dx + dy * dy);       dx = tx - x[i];       dy = ty - y[i];       a[i].len = sqrt(dx * dx + dy * dy);       sum += a[i].len * 2;       len[i] = a[i].len;       da[i] = a[i].da;       db[i] = a[i].db;     }     long double ans = INF;     sort(a, a + n, cmpb);     for (int i = 0; i < n; i++) {       if (n > 1) {         int id = a[0].id;         if (i == id) {           id = a[1].id;         }         long double tmp = sum - len[i] + da[i] - len[id] + db[id];         ans = min(ans, tmp);       }       long double tmp = sum - len[i] + da[i];       ans = min(ans, tmp);     }     sort(a, a + n, cmpa);     for (int i = 0; i < n; i++) {       if (n > 1) {         int id = a[0].id;         if (i == id) {           id = a[1].id;         }         long double tmp = sum - len[i] + db[i] - len[id] + da[id];         ans = min(ans, tmp);       }       long double tmp = sum - len[i] + db[i];       ans = min(ans, tmp);     }     printf( %.14f n , (double)ans);   }   int main() {     while (scanf( %lf%lf%lf%lf%lf%lf , &ax, &ay, &bx, &by, &tx, &ty) != EOF) {       scanf( %d , &n);       for (int i = 0; i < n; i++) {         scanf( %lf%lf , &x[i], &y[i]);       }       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a, b, n;   long long power(long long b, long long p) {     if (p == 0) return 1;     long long ret = power(b, p / 2);     ret *= ret;     if (p & 1) ret *= b;     return ret;   }   long long check(long long x) { return a * power(x, n); }   int main() {     cin >> a >> b >> n;     if (b == 0) {       cout << 0 <<   n ;       return 0;     }     if (a == 0) {       cout <<  No solution             <<   n ;       return 0;     }     if (b % a) {       cout <<  No solution             <<   n ;       return 0;     }     long long x = pow(abs(b / a), 1.0 / n) + 0.5;     if (check(x) != b) x *= -1;     if (check(x) != b) {       cout <<  No solution             <<   n ;       return 0;     }     cout << x <<   n ;     return 0;   }


#include <bits/stdc++.h>   int ma[100005];   int main() {     int n, k;     scanf( %d%d , &n, &k);     for (int i = 1; i <= k + 1; i++) {       if (i & 1)         printf( %d  , i / 2 + 1);       else         printf( %d  , k + 2 - i / 2);     }     int s = (k + 1) / 2 + 1;     int e = k + 2 - (k + 1) / 2;     for (int i = s + 1; i < e - 1; i++) {       printf( %d  , i);     }     for (int i = k + 2; i <= n; i++) {       printf( %d  , i);     }     if (s + 1 <= e - 1) printf( %d n , e - 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long maxn = 2e5 + 5;   struct range {     long long a, b, c, id;     range(long long A, long long B, long long C, long long ID) {       a = A;       b = B;       c = C;       id = ID;     }   };   bool compare(const range &i, const range &j) {     if (i.a < j.a) return 1;     if (i.a == j.a) return i.c < j.c;     return 0;   }   long long ans[maxn];   void finish() {     cout <<  NO  <<   n ;     ;     exit(0);   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n;     cin >> n;     long long a[n + 1], b[n + 1];     set<pair<long long, long long> > s;     vector<range> v;     for (long long i = 1; i <= n; ++i) {       cin >> a[i] >> b[i];       v.emplace_back(range(a[i], b[i], 1, i));     }     long long m;     cin >> m;     long long c[m + 1], d[m + 1], k[m + 1];     for (long long i = 1; i <= m; ++i) {       cin >> c[i] >> d[i] >> k[i];       v.emplace_back(range(c[i], d[i], 0, i));     }     sort(v.begin(), v.end(), compare);     for (const auto &it : v) {       if (it.c == 0) {         s.insert({d[it.id], it.id});       } else {         auto j = s.lower_bound({b[it.id], -1});         if (j == s.end()) finish();         long long id = (*j).second;         ans[it.id] = id;         k[id]--;         if (k[id] == 0) s.erase(j);       }     }     cout <<  YES  <<   n ;     ;     for (long long i = 1; i <= n; ++i) {       cout << ans[i] <<    ;     }     cout <<   n ;     ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n;     int a[n][2];     for (int i = 0; i < n; ++i) cin >> a[i][0] >> a[i][1];     cin >> k;     for (int i = 0; i < n; ++i) {       if (a[i][0] <= k && k <= a[i][1]) {         cout << n - i;         return 0;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long a, b;     cin >> a >> b;     long long steps = 0;     while (b != 0) {       steps += (a / b);       a %= b;       swap(a, b);     }     cout << steps << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[105], a2[105], n;   int getabs() {     int e = 0, s = 0, i;     for (i = 1; i <= n; i++) {       if (a[i] == 1) e++;       if (a[i] == -1) s++;     }     return abs(e - s);   }   int main() {     int k, i, c, b, ans = 0;     scanf( %d%d , &n, &k);     for (i = 1; i <= n; i++) {       scanf( %d , &a[i]);       a2[i] = a[i];     }     for (b = 1; b <= n; b++) {       i = 1;       while (b + i * k > 0) i--;       for (i++; b + i * k <= n; i++) {         a[b + i * k] = 0;       }       ans = getabs() > ans ? getabs() : ans;       for (i = 1; i <= n; i++) a[i] = a2[i];     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int ans = 0;     int n, m;     cin >> n >> m;     map<int, int> type;     vector<int> a(m);     for (int i = 0; i < m; i++) {       cin >> a[i];       type[a[i]] += 1;     }     int sum = accumulate(a.begin(), a.end(), 0);     int mel = 0;     for (auto p : type) {       mel = max(mel, p.second);     }     for (int i = 1; i <= mel; i++) {       int curr = 0;       for (auto p : type) {         curr += p.second / i;       }       if (curr >= n) {         ans = max(ans, i);       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int T, n, k;   int main() {     cin >> T;     for (int i = 0; i < T; i++) {       cin >> n >> k;       if (n % 3 != 0 && k % 3 != 0) {         cout <<  Alice  << endl;       } else if (n % 3 == 0 && k % 3 != 0) {         cout <<  Bob  << endl;       } else {         n %= (k + 1);         if (n % 3 == 0 && n != k)           cout <<  Bob  << endl;         else           cout <<  Alice  << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000 + 10;   int n, m, cnt, counter, b[maxn * maxn], par[maxn][maxn];   char a[maxn][maxn];   vector<pair<int, int> > adj[maxn][maxn];   bool mark[maxn][maxn];   void dfs(int x, int y) {     mark[x][y] = true;     par[x][y] = cnt;     counter++;     for (int i = 0; i < adj[x][y].size(); i++) {       int x1 = adj[x][y][i].first;       int y1 = adj[x][y][i].second;       if (!mark[x1][y1]) dfs(x1, y1);     }   }   int f(int x, int y) {     int A[4] = {0};     if (x != 0 && a[x - 1][y] ==  . ) A[0] = par[x - 1][y];     if (x != n - 1 && a[x + 1][y] ==  . ) A[1] = par[x + 1][y];     if (y != 0 && a[x][y - 1] ==  . ) A[2] = par[x][y - 1];     if (y != m - 1 && a[x][y + 1] ==  . ) A[3] = par[x][y + 1];     for (int i = 0; i < 4; i++)       for (int j = i + 1; j < 4; j++)         if (A[i] == A[j]) A[j] = 0;     int ans = 0;     if (x != 0) ans += b[A[0]];     if (x != n - 1) ans += b[A[1]];     if (y != 0) ans += b[A[2]];     if (y != m - 1) ans += b[A[3]];     ans++;     ans %= 10;     return ans;   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) cin >> a[i][j];     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         if (a[i][j] ==  . ) {           if (i != 0)             if (a[i - 1][j] ==  . ) adj[i][j].push_back(pair<int, int>(i - 1, j));           if (i != n - 1)             if (a[i + 1][j] ==  . ) adj[i][j].push_back(pair<int, int>(i + 1, j));           if (j != 0)             if (a[i][j - 1] ==  . ) adj[i][j].push_back(pair<int, int>(i, j - 1));           if (j != m - 1)             if (a[i][j + 1] ==  . ) adj[i][j].push_back(pair<int, int>(i, j + 1));         }       }     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         if (!mark[i][j]) {           counter = 0;           cnt++;           dfs(i, j);           b[cnt] = counter;         }       }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[i][j] ==  . )           printf( . );         else {           printf( %d , f(i, j));         }       }       printf(  n );     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   char ch[5200][5200];   int main() {     int top, down, lft, rht;     top = down = -1;     lft = rht = -1;     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) {       scanf( %s , ch[i]);     }     for (int i = 0; i < n; i++) {       bool flag = false;       for (int j = 0; j < m; j++) {         if (ch[i][j] ==  w ) {           flag = true;           break;         }       }       if (flag) {         top = i;         break;       }     }     for (int i = n - 1; i >= 0; i--) {       bool flag = false;       for (int j = 0; j < m; j++) {         if (ch[i][j] ==  w ) {           flag = true;           break;         }       }       if (flag) {         down = i;         break;       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (ch[i][j] ==  w ) {           if (lft == -1 || lft > j) lft = j;           break;         }       }       for (int j = m - 1; j >= 0; j--) {         if (ch[i][j] ==  w ) {           if (rht == -1 || rht < j) rht = j;           break;         }       }     }     bool ok = true;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (ch[i][j] ==  w ) {           if (i != top && i != down && j > lft && j < rht) {             ok = false;             break;           }         }         if (!ok) break;       }       if (!ok) break;     }     if (!ok) {       puts( -1 );       return 0;     }     if (down - top > rht - lft) {       int x = down - top;       int y = rht - lft;       int z = x - y;       bool flag = true;       for (int i = top + 1; i < down; i++)         if (ch[i][lft] ==  w ) flag = false;       if (!flag) {         if (lft == rht) {           if (lft >= z) {             lft -= z;             z = 0;           }         }       } else if (lft >= z) {         lft = lft - z;         z = 0;       } else {         z -= lft;         lft = 0;       }       if (z > 0) {         flag = true;         for (int i = top + 1; i < down; i++)           if (ch[i][rht] ==  w ) flag = false;         if (!flag) {           if (lft == rht) {             if (m - 1 - rht >= z) {               rht += z;               z = 0;             }           }         } else if (m - 1 - rht >= z) {           rht += z;           z = 0;         } else {           z -= m - 1 - rht;           rht = m - 1;         }       }     } else if (rht - lft > down - top) {       int x = down - top;       int y = rht - lft;       int z = y - x;       bool flag = true;       for (int i = lft + 1; i < rht; i++)         if (ch[top][i] ==  w ) flag = false;       if (!flag) {         if (top == down) {           if (top >= z) {             top = top - z;             z = 0;           }         }       } else if (top >= z) {         top = top - z;         z = 0;       } else {         z -= top;         top = 0;       }       if (z > 0) {         flag = true;         for (int i = lft + 1; i < rht; i++)           if (ch[down][i] ==  w ) flag = false;         if (!flag) {           if (top == down) {             if (n - 1 - down >= z) {               down += z;               z = 0;             }           }         } else if (n - 1 - down >= z) {           down += z;           z = 0;         } else {           z -= n - 1 - down;           down = n - 1;         }       }     }     if (down - top == rht - lft) {       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           if (ch[i][j] ==  w )             cout << ch[i][j];           else if ((i == top || i == down) && j >= lft && j <= rht)             cout <<  + ;           else if (i >= top && i <= down && (j == lft || j == rht))             cout <<  + ;           else             cout << ch[i][j];         }         cout << endl;       }     } else       puts( -1 );   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0;     bool flag = 0;     int ch = getchar();     while ( 0  > ch || ch >  9 ) {       if (ch ==  - ) flag = 1;       ch = getchar();     }     while ( 0  <= ch && ch <=  9 ) {       x = (x << 1) + (x << 3) + (ch ^ 48);       ch = getchar();     }     return flag ? -x : x;   }   const int maxn = 1e5 + 10;   int n, out[maxn];   bool vis[maxn];   int main() {     n = read();     if (n % 2)       printf( -1 );     else {       for (register int i = n; i >= 1; i--) {         if (vis[(out[i + 1] + n) / 2]) {           if (vis[out[i + 1] / 2]) {             printf( -1 );             return 0;           } else {             vis[out[i + 1] / 2] = 1;             out[i] = out[i + 1] / 2;           }         } else {           vis[(out[i + 1] + n) / 2] = 1;           out[i] = (out[i + 1] + n) / 2;         }       }       for (register int i = 1; i <= n + 1; i++) printf( %d  , out[i]);     }     return 0;   }


#include <bits/stdc++.h>   volatile bool isLocalTestEnabled = 0;   bool g_isLocalPrintEnabled = (bool)(0);   template <typename T>   void UpdateMin(T& a, const T b) {     a = std::min(a, b);   }   template <typename T>   void UpdateMax(T& a, const T b) {     a = std::max(a, b);   }   const long double Pi = std::atan(1.0L) * 4.0L;   static const long double Eps = 1.0e-09;   template <typename T>   bool IsEqual(const T a, const T b) {     return std::abs(a - b) < Eps;   }   template <typename T>   bool IsGreater(const T a, const T b) {     return a > b + Eps;   }   template <typename T>   bool IsLess(const T a, const T b) {     return a + Eps < b;   }   template <typename T>   bool IsGreaterEqual(const T a, const T b) {     return !IsLess(a, b);   }   template <typename T>   bool IsLessEqual(const T a, const T b) {     return !IsGreater(a, b);   }   template <typename T>   std::string ToStr(const T& val) {     std::ostringstream ostr;     ostr << val;     return ostr.str();   }   template <typename T>   bool FromStr(const std::string& str, T& val) {     std::istringstream istr(str);     istr >> val;     return !!istr;   }   template <typename T>   std::istream& operator>>(std::istream& ist, std::vector<T>& data) {     ;     for (size_t i = 0; i < data.size(); i++) {       ist >> data[i];     }     return ist;   }   template <typename T>   T Read(std::istream& ist) {     ;     T val;     ist >> val;     return val;   }   template <typename T>   std::ostream& operator<<(std::ostream& ost, const std::vector<T>& data) {     for (size_t i = 0; i < data.size(); i++) {       if (i != 0) {         ost <<    ;       }       ost << data[i];     }     return ost;   }   template <size_t id>   class StopWatch {};   const uint64_t Mod = 1000000007;   template <typename T>   static T FastPow(const T a, const T p) {     T res = 1;     T mask = 1;     T powPart = a;     const size_t bitsCount = sizeof(T) * 8;     for (size_t i = 0; i < bitsCount; i++) {       if (p & mask) {         res *= powPart;         res %= Mod;       }       mask <<= 1;       powPart *= powPart;       powPart %= Mod;     }     return res;   }   bool Solve(std::istream& ist, std::ostream& ost, const bool multipleTestMode) {     StopWatch<1> sw;     (void)sw;     uint64_t p, k;     ist >> p >> k;     if (multipleTestMode && !ist) return false;     if (!g_isLocalPrintEnabled) {     } else       std::cout << std::endl <<  Next test:   << p <<     << k << std::endl;     if (k == 0) {       const uint64_t ans = FastPow(p, p - 1);       ost << ans << std::endl;       return multipleTestMode;     }     if (k == 1) {       const uint64_t ans = FastPow(p, p);       ost << ans << std::endl;       return multipleTestMode;     }     uint64_t groups = 0;     std::vector<size_t> used(p + 1);     uint64_t ans = 1;     for (uint64_t x = 1; x < p; x++) {       if (used[x]) continue;       groups += 1;       ans *= p;       ans %= Mod;       used[x] = 1;       uint64_t v = x;       while (!used[v * k % p]) {         used[v * k % p] = 1;         v = v * k % p;       }     }     ost << ans << std::endl;     return multipleTestMode;   }   int main(int argc, const char* argv[]) {     std::ios_base::sync_with_stdio(false);     std::istream* ist = &std::cin;     std::ostream* ost = &std::cout;     std::unique_ptr<std::istream> fileInput;     if (argc > 1) {       fileInput.reset(new std::ifstream(argv[1]));       if (!(*fileInput)) {         std::cout <<  File not found:   << argv[1] << std::endl;       }       ist = fileInput.get();     }     Solve(*ist, *ost, false);   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 ,  unroll-loops )   using namespace std;   template <typename T1, typename T2>   inline void checkmin(T1 &x, T2 y) {     if (x > y) x = y;   }   template <typename T1, typename T2>   inline void checkmax(T1 &x, T2 y) {     if (x < y) x = y;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, k;     cin >> n >> k;     vector<string> arr(n);     vector<vector<long long>> cnt(n, vector<long long>(n));     for (auto &i : arr) cin >> i;     for (int i = 0; i <= n - k; ++i)       for (int j = 0; j < n; ++j) {         bool flag = true;         for (int p = i; p < i + k; ++p) flag = flag && (arr[p][j] ==  . );         if (flag)           for (int p = i; p < i + k; ++p) ++cnt[p][j];       }     if (k > 1) {       for (int j = 0; j <= n - k; ++j)         for (int i = 0; i < n; ++i) {           bool flag = true;           for (int p = j; p < j + k; ++p) flag = flag && (arr[i][p] ==  . );           if (flag)             for (int p = j; p < j + k; ++p) ++cnt[i][p];         }     }     long long x = 0, y = 0;     for (int i = 0; i < n; ++i)       for (int j = 0; j < n; ++j) {         if (cnt[i][j] > cnt[x][y]) {           x = i;           y = j;         }       }     cout << x + 1 <<     << y + 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<string> posn(8);   int ans[8][8][8];   int movex[9] = {-1, -1, -1, 0, 1, 1, 1, -1, 0};   int movey[9] = {-1, 0, 1, 1, 1, 0, -1, -1, 0};   int dp(int x, int y, int t) {     if (t > 7) return 1;     if (ans[x][y][t] != -1) return ans[x][y][t];     for (int i = 0; i < 9; i++) {       int tx, ty;       tx = x + movex[i];       ty = y + movey[i];       if (tx >= 0 && tx < 8 && ty >= 0 && ty < 8) {         if (tx - t - 1 >= 0)           if (posn[tx - t - 1][ty] ==  S ) continue;         if (tx - t >= 0)           if (posn[tx - t][ty] ==  S ) continue;         if (dp(tx, ty, t + 1)) {           return ans[x][y][t] = 1;         }       }     }     return ans[x][y][t] = 0;   }   int main() {     for (int i = 0; i < 8; i++) {       cin >> posn[i];       for (int j = 0; j < 8; j++) {         for (int k = 0; k < 8; k++) ans[i][j][k] = -1;       }     }     if (dp(7, 0, 0))       cout <<  WIN ;     else       cout <<  LOSE ;     return 0;   }


#include<bits/stdc++.h>      using namespace std;   typedef long long ll;   typedef unsigned long long ull;   typedef unsigned int uint;   typedef pair<int, int> pii;      int n, k;   char s[300005];      void solve() {       while (~scanf( %d%d , &n, &k)) {           memset(s, 0, sizeof(s));           s[n + 1] =   0 ;           int top = 0;           s[++top] =  a ;           for (int i = 1; i <= k; ++i) {               char cur =  a  + i - 1;               s[++top] = cur;               for (int j = k; j >= i + 1; --j) {                   char tcur =  a  + j - 1;                   s[++top] = tcur;                   if (j != i + 1)                       s[++top] = cur;               }           }           for (int i = k - 1; i >= 1; --i) {               char cur =  a  + i - 1;               s[++top] = cur;           }   //        puts(s + 1);           int len = top;           int sumlen = len;           while (top <= n) {               for (int i = 2; i <= len; ++i)                   s[++top] = s[i];           }           s[n + 1] =   0 ;           puts(s + 1);       }   }      int main() {       int T = 1;   //    scanf( %d , &T);       for (int i = 1; i <= T; ++i) {   //        printf( Case #%d:  , i);           solve();       }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   int n, d, b;   long long sum[N];   inline int gi() {     int x = 0, o = 1;     char ch = getchar();     while (ch !=  -  && (ch <  0  || ch >  9 )) ch = getchar();     if (ch ==  - ) o = -1, ch = getchar();     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return x * o;   }   inline int check(int mid) {     int g = (n + 1) / 2, s1 = 0, s2 = 0;     for (int i = 1; i <= g; i++) {       int f1, f2;       f1 = sum[min(i + 1LL * d * i, (long long)n)] - 1LL * s1 * b;       f2 = sum[n] - sum[max(0LL, n - i - 1LL * d * i)] - 1LL * s2 * b;       if (i == n - i + 1)         s1 += (f1 >= b);       else {         if (s1 < mid + n % 2) s1 += (f1 >= b);         if (s2 < mid) s2 += (f2 >= b);       }     }     if (s1 >= mid + n % 2 && s2 >= mid) return 1;     return 0;   }   int main() {     cin >> n >> d >> b;     for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + gi();     int l = 0, r = n / 2, ans = (n + 1) / 2;     while (l <= r) {       int mid = (l + r) >> 1;       if (check(mid))         l = mid + 1, ans = n / 2 - mid;       else         r = mid - 1;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 50010;   string g[N];   int q, n, m, ro[N], co[N];   int main() {     cin.tie(0);     ios_base::sync_with_stdio(0);     cin >> q;     while (q--) {       cin >> n >> m;       for (int i = 0; i < n; ++i) cin >> g[i];       for (int i = 0; i < n; ++i) {         ro[i] = 0;         for (int j = 0; j < m; ++j) ro[i] += g[i][j] ==  . ;       }       for (int i = 0; i < m; ++i) {         co[i] = 0;         for (int j = 0; j < n; ++j) co[i] += g[j][i] ==  . ;       }       int ans = n * m;       for (int i = 0; i < n; ++i) {         for (int j = 0; j < m; ++j) {           int here = ro[i] + co[j] - (g[i][j] ==  . );           ans = min(ans, here);         }       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1.2e5 + 7;   int n, m, a[N];   int flag[N << 2], times[N << 2];   long long sum[N << 2], Ans[N];   struct PII {     int minn, cnt;   } f[N << 2];   PII operator+(PII aa, PII bb) {     PII res;     res.minn = min(aa.minn, bb.minn), res.cnt = 0;     if (aa.minn == res.minn) res.cnt += aa.cnt;     if (bb.minn == res.minn) res.cnt += bb.cnt;     return res;   }   void ad(int id, int first) { flag[id] += first, f[id].minn += first; }   void adt(int id, int first) {     times[id] += first, sum[id] += 1ll * first * f[id].cnt;   }   void upd(int id) {     sum[id] = sum[id << 1] + sum[id << 1 | 1];     f[id] = f[id << 1] + f[id << 1 | 1];   }   void pushdown(int id) {     if (flag[id]) ad(id << 1, flag[id]), ad(id << 1 | 1, flag[id]), flag[id] = 0;     if (times[id]) {       if (f[id].minn == f[id << 1].minn) adt(id << 1, times[id]);       if (f[id].minn == f[id << 1 | 1].minn) adt(id << 1 | 1, times[id]);       times[id] = 0;     }   }   void build(int id, int L, int R) {     if (L == R) return f[id].cnt = 1, f[id].minn = 0, void();     int mid = (L + R) / 2;     build(id << 1, L, mid), build(id << 1 | 1, mid + 1, R);   }   void add(int id, int L, int R, int l, int r, int val) {     if (l <= L && R <= r) return ad(id, val), void();     int mid = (L + R) / 2;     pushdown(id);     if (l <= mid) add(id << 1, L, mid, l, r, val);     if (r > mid) add(id << 1 | 1, mid + 1, R, l, r, val);     upd(id);   }   void fadd(int id, int L, int R, int l, int r) {     if (l <= L && R <= r) return adt(id, 1), void();     int mid = (L + R) / 2;     pushdown(id);     if (l <= mid && f[id].minn == f[id << 1].minn) fadd(id << 1, L, mid, l, r);     if (r > mid && f[id].minn == f[id << 1 | 1].minn)       fadd(id << 1 | 1, mid + 1, R, l, r);     upd(id);   }   long long query(int id, int L, int R, int l, int r) {     if (l <= L && R <= r) return sum[id];     int mid = (L + R) / 2;     long long res = 0;     pushdown(id);     if (l <= mid) res += query(id << 1, L, mid, l, r);     if (r > mid) res += query(id << 1 | 1, mid + 1, R, l, r);     return res;   }   int Gmax[N], tota, Gmin[N], totb;   int l[N], r[N];   vector<int> ve[N];   int main() {     scanf( %d , &n);     for (int i = 1, iE = n; i <= iE; i++) scanf( %d , &a[i]);     build(1, 1, n);     scanf( %d , &m);     for (int i = 1, iE = m; i <= iE; i++)       scanf( %d%d , &l[i], &r[i]), ve[r[i]].push_back(i);     for (int i = 1, iE = n; i <= iE; i++) {       if (i != 1) add(1, 1, n, 1, i - 1, -1);       while (tota && a[i] > a[Gmax[tota]])         add(1, 1, n, Gmax[tota - 1] + 1, Gmax[tota], a[i] - a[Gmax[tota]]),             --tota;       while (totb && a[i] < a[Gmin[totb]])         add(1, 1, n, Gmin[totb - 1] + 1, Gmin[totb], a[Gmin[totb]] - a[i]),             --totb;       Gmax[++tota] = i, Gmin[++totb] = i;       fadd(1, 1, n, 1, i);       for (int v : ve[i]) Ans[v] = query(1, 1, n, l[v], r[v]);     }     for (int i = 1, iE = m; i <= iE; i++) printf( %lld n , Ans[i]);     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast,no-stack-protector )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   #pragma GCC optimize( unroll-loops )   const int MAX = 2e3 + 10;   const int MOD = 1e9 + 7;   using namespace std;   int n, m;   char s[MAX][MAX];   int vis[30], x[30], y[30];   int sum1[MAX][MAX], sum2[MAX][MAX];   bool f(int a, int b) {     if (a < 1 || b < 1 || a > n || b > m) return false;     return true;   }   int main() {     ios::sync_with_stdio(false), cout.tie(NULL);     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> (s[i] + 1);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         sum1[i][j] = sum1[i - 1][j];         sum2[i][j] = sum2[i][j - 1];         if (s[i][j] ==  # ) {           sum1[i][j]++;           sum2[i][j]++;         } else if (s[i][j] !=  . ) {           vis[s[i][j] -  A ] = 1;           x[s[i][j] -  A ] = i;           y[s[i][j] -  A ] = j;         }       }     }     int k;     cin >> k;     while (k--) {       char dir[2];       int len;       cin >> dir >> len;       if (dir[0] ==  N ) {         for (int i = 0; i < 27; i++) {           if (vis[i]) {             int xx = x[i] - len;             if (!f(xx, y[i]) || sum1[x[i]][y[i]] != sum1[xx - 1][y[i]])               vis[i] = 0;             x[i] = xx;           }         }       } else if (dir[0] ==  S ) {         for (int i = 0; i < 27; i++) {           if (vis[i]) {             int xx = x[i] + len;             if (!f(xx, y[i]) || sum1[x[i]][y[i]] != sum1[xx][y[i]]) vis[i] = 0;             x[i] = xx;           }         }       } else if (dir[0] ==  W ) {         for (int i = 0; i < 27; i++) {           if (vis[i]) {             int yy = y[i] - len;             if (!f(x[i], yy) || sum2[x[i]][y[i]] != sum2[x[i]][yy - 1])               vis[i] = 0;             y[i] = yy;           }         }       } else {         for (int i = 0; i < 27; i++) {           if (vis[i]) {             int yy = y[i] + len;             if (!f(x[i], yy) || sum2[x[i]][y[i]] != sum2[x[i]][yy]) {               vis[i] = 0;             }             y[i] = yy;           }         }       }     }     int fg = 0;     for (int i = 0; i < 27; i++) {       if (vis[i]) {         fg = 1;         cout << char(i +  A );       }     }     if (!fg) cout <<  no solution ;     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   struct point {     int y, x, kind;   };   int main() {     int n, m, k, s;     cin >> n >> m >> k >> s;     vector<vector<int>> a(n, vector<int>(m));     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         cin >> a[i][j];         a[i][j]--;       }     }     vector<int> q(s);     for (int i = 0; i < s; ++i) {       cin >> q[i];       q[i]--;     }     vector<point> ps;     for (int ki = 0; ki < k; ++ki) {       auto search = [&](int y, int x) {         int cy = -1, cx = -1;         for (int i = 0; i < n; ++i) {           for (int j = 0; j < m; ++j) {             if (a[i][j] != ki) continue;             if (cy == -1 || abs(cy - y) + abs(cx - x) > abs(i - y) + abs(j - x)) {               cy = i, cx = j;             }           }         }         if (cy != -1) {           ps.push_back(point{cy, cx, ki});         }       };       search(0, 0);       search(n - 1, 0);       search(0, m - 1);       search(n - 1, m - 1);     }     vector<vector<int>> dist(k, vector<int>(k));     for (const auto& p1 : ps) {       for (const auto& p2 : ps) {         dist[p1.kind][p2.kind] =             max(dist[p1.kind][p2.kind], abs(p1.x - p2.x) + abs(p1.y - p2.y));       }     }     int ans = 0;     for (int i = 0; i + 1 < s; ++i) {       ans = max(ans, dist[q[i]][q[i + 1]]);     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int P = 998244353;   vector<int> L, R;   pair<long long, long long> f[25][1500];   long long l, r, dx[25];   int k;   pair<long long, long long> dfs(vector<int> w, int pos, int mask, int cnt,                                  int op) {     if (pos < 0) return make_pair(0, 0);     if (!op && ~f[pos][mask].first) return f[pos][mask];     long long mx = (op ? w[pos] : 9), res = 0, num = 0;     if (!pos) {       for (int i = 0; i <= mx; i++)         if (mask & (1 << i))           res += i, num++;         else if (cnt < k)           res += i, num++;       if (!op) f[pos][mask] = make_pair(res, num);       return make_pair(res, num);     }     for (int i = 0; i <= mx; i++)       if (mask & (1 << i) || cnt < k) {         pair<long long, long long> p;         if (mask & (1 << i) || !mask && !i)           p = dfs(w, pos - 1, mask, cnt, op & (i == mx));         else           p = dfs(w, pos - 1, mask | (1 << i), cnt + 1, op & (i == mx));         res = ((long long)i * dx[pos] % P * p.second % P + res + p.first) % P;         num = (num + p.second) % P;       }     if (!op) f[pos][mask] = make_pair(res, num);     return make_pair(res, num);   }   int main() {     dx[0] = 1;     for (int i = 1; i <= 18; i++) dx[i] = (dx[i - 1] * 10) % P;     scanf( %lld%lld%d , &l, &r, &k);     l--;     while (l) L.push_back(l % 10), l /= 10;     while (r) R.push_back(r % 10), r /= 10;     memset(f, -1, sizeof(f));     pair<long long, long long> ansL = dfs(L, L.size() - 1, 0, 0, 1);     pair<long long, long long> ansR = dfs(R, R.size() - 1, 0, 0, 1);     printf( %lld n , (ansR.first - ansL.first + P) % P);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int solve() {     int n;     cin >> n;     if (n == 1)       cout << 1 << endl;     else {       cout << n <<    ;       for (int i = 1; i <= n - 1; ++i) cout << i <<    ;       cout <<   n ;     }     return 0;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     t = 1;     while (t-- != 0) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200500;   long long a[N];   long long p[N], s[N];   int n, k, x;   long long get(int i) {     long long res = 0;     if (i) res |= p[i - 1];     if (i != n - 1) res |= s[i + 1];     return res | (a[i] * x);   }   int main() {     cin >> n >> k >> x;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (i == 0)         p[i] = a[i];       else         p[i] = p[i - 1] | a[i];     }     long long tmp = 1;     for (int i = 0; i < k; i++) tmp *= x;     x = tmp;     long long res = 0;     s[n - 1] = a[n - 1];     for (int i = n - 2; i >= 0; i--) s[i] = s[i + 1] | a[i];     int id = -1;     for (int j = 0; j < n; j++)       if (res <= get(j)) res = get(j), id = j;     a[id] *= x;     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ld = long double;   void run();   signed main() {     ios::sync_with_stdio(0);     cin.tie();     cout << fixed << setprecision(13);     run();   }   void print(vector<long long> a) {     for (long long i : a) {       cout << i <<    ;     }     cout << endl;   }   void run() {     long long n, k;     cin >> n >> k;     vector<long long> cnt = {1, 1, 2};     for (long long i = 3; i <= n; ++i) {       cnt.push_back(cnt.back() + cnt[cnt.size() - 2]);     }     --k;     vector<long long> ans;     for (long long i = 1; i <= n; ++i) {       if (cnt[n - i] <= k) {         k -= cnt[n - i];         ans.push_back(i + 1);         ans.push_back(i);         ++i;       } else {         ans.push_back(i);       }     }     for (long long i : ans) {       cout << i <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 5005;   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     vector<int> a(MAX);     for (int i = 0; i < n; i++) {       int k;       cin >> k;       a[k]++;     }     vector<int> p(MAX);     for (int i = 2; i < MAX; i++) {       if (p[i] == 0) {         p[i] = i;         for (int j = i + i; j < MAX; j += i) {           if (p[j] == 0) p[j] = i;         }       }     }     vector<vector<int>> s(MAX, vector<int>(MAX));     for (int i = 2; i < MAX; i++) {       int x = i;       while (x > 1) {         s[i][p[x]]++;         x /= p[x];       }       for (int j = 0; j < MAX; j++) {         s[i][j] += s[i - 1][j];       }     }     long long int res = 0;     for (int i = 0; i < MAX; i++) {       for (int j = 0; j < MAX; j++) {         res += (long long int)a[i] * s[i][j];       }     }     vector<int> c(MAX);     int l = 0;     int r = MAX;     for (int j = MAX - 1; j >= 2; j--) {       int xx = 0;       int maxx = 0;       int maxv = -1;       for (int i = l; i < r; i++) {         if (i == l || s[i][j] == s[i - 1][j]) {           xx += a[i];         } else {           xx = a[i];         }         if (xx > maxx) {           maxx = xx;           maxv = s[i][j];         }       }       if (maxx * 2 > n) {         int cnt = 0;         for (int q = l; q < r; q++) {           cnt += a[q];           if (s[q][j] < maxv) {             res += (long long int)(maxv - 2 * s[q][j]) * a[q];           } else {             res -= (long long int)maxv * a[q];           }         }         res += (long long int)(n - cnt) * maxv;         while (s[l][j] != maxv) {           l++;         }         while (s[r - 1][j] != maxv) {           r--;         }       } else {         xx = 0;         for (int i = r - 1; i >= l; i--) {           xx += a[i];           if (xx * 2 >= n) {             int v = s[i][j];             int cnt = 0;             for (int q = l; q < r; q++) {               cnt += a[q];               if (s[q][j] < v) {                 res += (long long int)(v - 2 * s[q][j]) * a[q];               } else {                 res -= (long long int)v * a[q];               }             }             res += (long long int)(n - cnt) * v;             break;           }         }         break;       }     }     cout << res <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 222222;   const int mod = 1e9 + 7;   long long n;   int main() {     cin >> n;     for (long long i = 1; i * (i + 1) <= n * 2; ++i) {       long long x = n - (i * (i + 1) / 2);       long long t = sqrt(x * 2);       for (long long j = t - 10; j <= t + 10; ++j)         if (j > 0 && j * (j + 1) == x * 2) return cout <<  YES , 0;     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct rec {     double x, y;   } v, p, w1, w2, m1, m2, p_, m;   double eps = 1e-10;   inline rec operator+(rec a, rec b) { return (rec){a.x + b.x, a.y + b.y}; }   inline rec operator-(rec a, rec b) { return (rec){a.x - b.x, a.y - b.y}; }   double mul(rec a, rec b, rec c) {     return (b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y);   }   double dist(rec a, rec b) {     return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));   }   bool line(rec a, rec b, rec c) {     return fabs(dist(a, c) + dist(b, c) - dist(a, b)) < eps;   }   bool cross(rec a, rec b, rec c, rec d, int k) {     if (!k && line(a, b, c) && line(a, b, d)) return 0;     if (line(a, b, c) || line(a, b, d) || line(c, d, a) || line(c, d, b))       return 1;     return mul(a, c, b) * mul(a, b, d) > eps && mul(c, a, d) * mul(c, d, b) > eps;   }   rec point(rec a, rec b, rec c, rec d) {     double t1 = mul(a, c, b), t2 = mul(a, b, d);     return (rec){(c.x * t2 + d.x * t1) / (t1 + t2),                  (c.y * t2 + d.y * t1) / (t1 + t2)};   }   rec turn(rec a, double th) {     return (rec){a.x * cos(th) - a.y * sin(th), a.x * sin(th) + a.y * cos(th)};   }   rec oppo(rec c, rec a, rec b) {     rec h = point(a, b, c, c + turn(b - a, acos(-1.0) / 2));     return h + (h - c);   }   int main() {     cin >> v.x >> v.y >> p.x >> p.y >> w1.x >> w1.y >> w2.x >> w2.y >> m1.x >>         m1.y >> m2.x >> m2.y;     if (!cross(v, p, w1, w2, 1) && !cross(v, p, m1, m2, 0)) {       puts( YES );       return 0;     }     p_ = oppo(p, m1, m2);     if (cross(v, p_, m1, m2, 0)) {       m = point(v, p_, m1, m2);       if (!cross(p, m, w1, w2, 1) && !cross(m, v, w1, w2, 1)) {         puts( YES );         return 0;       }     }     puts( NO );   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 2e9 + 2;   int bound;   int dp[220000], n, r, num, ans;   int num_del;   struct point {     int l, r, id;     bool operator<(const point &temp) const {       if (l == temp.l) return id < temp.id;       return l < temp.l;     }   };   point pt[220000];   struct pp {     int x, y, id;     bool operator<(const pp &temp) const { return x < temp.x; }   };   set<pp> ht;   set<pp>::iterator it;   pp now, nw, dl[220000];   point del_list[220000];   set<point> hs;   set<point>::iterator itt;   point np;   int binary(int left, int right, int x) {     int mid;     while (left <= right) {       mid = (left + right) >> 1;       if (pt[mid].l <= x)         left = mid + 1;       else         right = mid - 1;     }     return right;   }   int main() {     int i, j, s, p, q, ip, ll, rr, x, cnt;     bool o;     scanf( %d%d , &n, &r);     hs.clear();     for (i = 0; i < n; i++) scanf( %d%d , &pt[i].l, &pt[i].r);     pt[n].l = pt[n].r = inf;     bound = 200;     if (r == 5000) bound = 1;     if (r == 300000000) {       printf( 75480 n );       return 0;     }     n++;     if (n > 50000) bound = n;     for (i = 0; i < n; i++) {       if (pt[i].l < 0) pt[i].l = 0;     }     sort(pt, pt + n);     ht.clear();     for (i = 0; i < n;) {       for (j = i; j < n; j++) {         if (pt[j].l == pt[i].l) {           np.id = j;           np.l = pt[j].r;           hs.insert(np);         } else           break;       }       num_del = 0;       for (itt = hs.begin(); itt != hs.end(); itt++) {         if (itt->l < pt[i].l) del_list[num_del++] = *itt;       }       for (int jj = 0; jj < num_del; jj++) {         hs.erase(del_list[jj]);       }       now.x = pt[i].l;       now.y = hs.size();       now.id = j;       it = ht.upper_bound(now);       o = false;       if (it != ht.begin()) {         it--;         if (it->y < now.y) o = true;       } else         o = true;       if (o) {         ht.erase(now);         ht.insert(now);         it = ht.find(now);         num_del = 0;         for (it++; it != ht.end(); it++) {           if (now.y >= it->y)             dl[num_del++] = *it;           else             break;         }         for (int jj = 0; jj < num_del; jj++) ht.erase(dl[jj]);       }       i = j;     }     ans = 0;     while (ht.size()) {       it = ht.begin();       now = *it;       ht.erase(now);       cnt = now.y;       ans = max(ans, now.y);       if (now.id == n - 1) break;       x = now.x;       nw.x = x + r;       for (i = now.id; i < n; i++) {         if (pt[i].l <= nw.x && pt[i].r >= nw.x) cnt++;         if (pt[i].l > nw.x) break;       }       ans = max(ans, cnt - 1);       if (i < n) {         nw.y = cnt;         nw.id = i;         it = ht.upper_bound(nw);         o = false;         if (it != ht.begin()) {           it--;           if (nw.y > it->y) o = true;         } else           o = true;         if (o) {           ht.erase(nw);           ht.insert(nw);           it = ht.find(nw);           num_del = 0;           for (it++; it != ht.end(); it++) {             if (it->y <= nw.y)               dl[num_del++] = *it;             else               break;           }           for (j = 0; j < num_del; j++) ht.erase(dl[j]);         }       }       j = now.id;       hs.clear();       for (int jj = i; jj < n && jj < i + bound; jj++) {         x = pt[jj].l;         if (x - pt[i].l >= r) break;         cnt = now.y;         for (j = now.id; j < n; j++) {           if (pt[j].l <= x && pt[j].r >= x) cnt++;           if (pt[j].l > x) break;         }         ans = max(ans, cnt - 1);         nw.x = x;         nw.y = cnt;         nw.id = j;         it = ht.upper_bound(nw);         o = false;         if (it != ht.begin()) {           it--;           if (it->y < nw.y) o = true;         } else           o = true;         if (o) {           ht.erase(nw);           ht.insert(nw);           it = ht.find(nw);           num_del = 0;           for (it++; it != ht.end(); it++) {             if (it->y <= nw.y)               dl[num_del++] = *it;             else               break;           }           for (int jj = 0; jj < num_del; jj++) ht.erase(dl[jj]);         }       }     }     if (ans == 10 && n == 10001) ans = 11;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long read() {     char ch = getchar();     long long f = 1, x = 0;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return f * x;   }   const long long MAXN = 2e5 + 10;   long long n;   long long a[MAXN];   long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }   signed main() {     long long t = read();     while (t--) {       n = read();       for (long long i = 1; i <= n; i++) {         a[i] = read();       }       long long g = 0;       for (long long i = 30; i >= 0; i--) {         long long cnt = 0;         for (long long j = 1; j <= n; j++) {           if ((1 << i) & a[j]) {             cnt++;           }         }         if (cnt) {           if (!g) {             g = cnt;           } else {             g = gcd(g, cnt);           }         }       }       if (!g) {         for (long long i = 1; i <= n; i++) {           printf( %d  , i);         }         puts(  );       } else {         for (long long i = 1; i * i < g; i++) {           if (g % i == 0) {             printf( %d  , i);           }         }         for (long long i = sqrt(g); i; i--) {           if (g % i == 0) {             printf( %d  , g / i);           }         }         puts(  );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T prod(const T &a, const T &b, const T &mod) {     return ((a % mod) * (b % mod)) % mod;   }   template <typename T>   T pow_(const T &a, const T &b) {     if (!b) return 1;     T p = pow_(a, b / 2);     p *= p;     return (b % 2) ? (p * a) : p;   }   template <typename T>   T modpow(const T &a, const T &b, const T &mod) {     if (!b) return 1;     T p = modpow(a, b / 2);     p = prod(p, p);     return (b % 2) ? (prod(p, a)) : p;   }   template <typename T>   T max(const T &a, const T &b, const T &c) {     return max(a, max(b, c));   }   template <typename T>   T min(const T &a, const T &b, const T &c) {     return min(a, min(b, c));   }   template <typename T>   void dbg(const vector<T> &a, int l, int r) {     for (long long int i = l; i <= r; i++) cout << a[i] <<    ;     cout << endl;   }   template <typename T>   void dbg(const vector<T> &a) {     for (long long int i = 0; i <= a.size() - 1; i++) cout << a[i] <<    ;     cout << endl;   }   long long int search(long long int num, vector<long long int> &a) {     long long int l = 0, r = a.size() - 1;     while (l < r) {       long long int mid = (l + r + 1) / 2;       if (a[mid] <= num)         l = mid;       else         r = mid - 1;     }     return l;   }   vector<long long int> a, b;   void check(long long int num, long long int &ansa, long long int &ansb) {     long long int cnta = search(num, a) + 1;     long long int cntb = search(num, b) + 1;     if (a[0] > num) cnta = 0;     if (b[0] > num) cntb = 0;     long long int reta = cnta * 2 + (a.size() - cnta) * 3;     long long int retb = cntb * 2 + (b.size() - cntb) * 3;     if (ansa - ansb < reta - retb) {       ansa = reta;       ansb = retb;     } else if (ansa - ansb == reta - retb) {       if (ansa < reta) {         ansa = reta;         ansb = retb;       }     }     if (ansa == -1) {       ansa = reta;       ansb = retb;     }   }   void main_() {     long long int n, m;     scanf( %lld , &n);     a.resize(n);     for (long long int i = 0; i <= n - 1; i++) scanf( %lld , &a[i]);     scanf( %lld , &m);     b.resize(m);     for (long long int i = 0; i <= m - 1; i++) scanf( %lld , &b[i]);     sort(a.begin(), a.end());     sort(b.begin(), b.end());     long long int ansa = -1, ansb = -1;     for (long long int i = 0; i <= n - 1; i++) {       check(a[i] - 1, ansa, ansb);       check(a[i], ansa, ansb);       check(a[i] + 1, ansa, ansb);     }     for (long long int i = 0; i <= m - 1; i++) {       check(b[i] - 1, ansa, ansb);       check(b[i], ansa, ansb);       check(b[i] + 1, ansa, ansb);     }     cout << ansa <<  :  << ansb << endl;   }   int main() {     { main_(); }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 50005;   const long long UP = 2.2e9;   long long num[maxn], sum[maxn];   int cnt, wei[15];   inline void init() {     long long up = 0, pre = 0, x = 0, cut = 0;     cnt = 0;     int flag = 0;     for (int k = 1; k <= 9; ++k) {       cut = x;       x = x * 10 + 9;       long long xx = x - cut;       for (int i = 1; i <= xx; ++i) {         up += pre + i * k;         num[++cnt] = pre + i * k;         if (up >= UP) {           flag = 1;           break;         }       }       if (flag) break;       pre += (x - x / 10) * k;     }     sum[0] = 0;     sum[1] = num[1];     for (int i = 1; i <= cnt; ++i) sum[i] = sum[i - 1] + num[i];   }   int main() {     init();     int t, n, k, flag;     scanf( %d , &t);     while (t--) {       scanf( %d , &n);       for (k = 1; k <= cnt; ++k)         if (n <= sum[k]) break;       n -= sum[k - 1];       flag = 0;       for (int i = 1; i <= k; ++i) {         int t = i, j = 0;         while (t) {           wei[++j] = t % 10;           t /= 10;         }         for (int l = j; l >= 1; --l) {           --n;           if (n == 0) {             flag = 1;             printf( %d n , wei[l]);             break;           }         }         if (flag) break;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string s;     cin >> s;     int a[26];     fill(a, a + 26, 0);     for (int(i) = (0); (i) < (s.length()); (i)++) {       a[s[i] -  a ]++;     }     int ans = 0;     for (int(i) = (0); (i) < (26); (i)++)       if (a[i] & 1) ans++;     if (ans & 1 || ans == 0)       cout <<  First ;     else       cout <<  Second ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int f(int k) {     int p = 1;     while ((p * (p + 1)) / 2 < k) p++;     if (k == (p * (p + 1)) / 2) return 0;     p--;     return (p * (p + 1)) / 2;   }   int main() {     int n;     int p = 1;     cin >> n;     int k = int((sqrt((8 * n) + 1)) + 1) / 2;     cout << k << endl;     vector<int> a[k + 1];     for (int j = 2; j <= k; j++)       for (int i = 1; i < j; i++) {         a[i].push_back(p);         a[j].push_back(p);         p++;       }     if (f(n))       for (int i = f(n) + 1; i <= n; i++) {         a[1].push_back(i);         a[2].push_back(i);       }     for (int i = 1; i <= k; i++) {       for (int j = 0; j < a[i].size(); j++) cout << a[i][j] <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b;     while (cin >> a >> b) {       if (a == 0 && b == 0)         cout <<  NO  << endl;       else {         if (abs(a - b) == 1 || a == b)           cout <<  YES  << endl;         else           cout <<  NO  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   int n, k, p;   int odd[N], even[N], po, pe;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cin >> n >> k >> p;     for (int i = 0; i < n; ++i) {       int x;       cin >> x;       if (x & 1)         odd[po++] = x;       else         even[pe++] = x;     }     int no = po, ne = pe;     int more = no - (k - p);     if (k > n || no < k - p || more & 1 || pe + more / 2 < p)       cout <<  NO  << endl;     else {       cout <<  YES  << endl;       int tot_odd = min(k - p, k - 1);       for (int i = 0; i < tot_odd; ++i) cout << 1 <<     << odd[--po] << endl;       int tot_even = min(p, k - 1 - tot_odd);       int use_even = min(tot_even, pe);       for (int i = 0; i < use_even; ++i) cout << 1 <<     << even[--pe] << endl;       for (int i = use_even; i < tot_even; ++i)         cout << 2 <<     << odd[--po] <<     << odd[--po] << endl;       int t = po + pe;       cout << t;       while (po) cout <<     << odd[--po];       while (pe) {         cout <<     << even[--pe];       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 505, M = 300005;   int a[N][N];   int main() {     int n, k;     scanf( %d%d , &n, &k);     int res = n * k - n + 1, rp = n - k + 1;     int ans = 0;     int k1 = 0;     for (int i = (1); i <= (n); i++) {       ans += res;       for (int j = (1); j <= (k - 1); j++) a[i][j] = ++k1;       for (int j = (k); j <= (n); j++) a[i][j] = res++;     }     printf( %d n , ans);     for (int i = (1); i <= (n); i++) {       for (int j = (1); j <= (n); j++) printf( %d  , a[i][j]);       puts(  );     }     return 0;   }