#include<iostream>   #include <bits/stdc++.h>   using namespace std;   #define ll long long   #define mod 1000000007   #define INF 100000007   #define MAX 1000000   #define nl   n    #define F first   #define S second   #define pb(a) push_back(a)   typedef vector<ll> vi;   typedef priority_queue<ll , vector<ll> , greater<ll>()> pqmx;   typedef priority_queue<ll> pqmn;   typedef pair<ll , ll> pi;   typedef vector< pair<int , int> > vpi;   #define fr(i,n) for(i=0;i<n;i++)   #define rep(i,a,n) for(i=a;i<n;i++)   int n , t , m , temp , temp2, root , p ,q , k , i , j;      struct comp {        bool operator()( pair<int, int> const& a, pair<int, int> const& b) {            return a.first < b.first || (a.first == b.first && a.second > b.second);       }    };       void func(){       ll A , B , C;       cin>>A>>B>>C;       if((A + B + C)%9 != 0){           cout<< NO <<  n ;           return;       }       ll p = (A + B + C) / 9;       if(p > A || p > B || p > C){           cout<< NO <<  n ;           return;       }       cout<< YES <<  n ;   }            int main(){   #ifndef ONLINE_JUDGE       freopen( input.txt  ,  r  , stdin);       freopen( output.txt  ,  w  , stdout);   #endif       cin>>t;       while(t--){           func();       }   }


#include <bits/stdc++.h>   #pragma warning(disable : 4996)   using namespace std;   namespace Xrocks {}   using namespace Xrocks;   namespace Xrocks {   class in {   } user_input;   class out {   } output;   in& operator>>(in& X, int& Y) {     scanf( %d , &Y);     return X;   }   in& operator>>(in& X, char* Y) {     scanf( %s , Y);     return X;   }   in& operator>>(in& X, float& Y) {     scanf( %f , &Y);     return X;   }   in& operator>>(in& X, double& Y) {     scanf( %lf , &Y);     return X;   }   in& operator>>(in& X, char& C) {     scanf( %c , &C);     return X;   }   in& operator>>(in& X, string& Y) {     cin >> Y;     return X;   }   in& operator>>(in& X, long long& Y) {     scanf( %lld , &Y);     return X;   }   template <typename T>   in& operator>>(in& X, vector<T>& Y) {     for (auto& x : Y) user_input >> x;     return X;   }   template <typename T>   out& operator<<(out& X, T Y) {     cout << Y;     return X;   }   template <typename T>   out& operator<<(out& X, vector<T>& Y) {     for (auto& x : Y) output << x <<    ;     return X;   }   out& operator<<(out& X, const int& Y) {     printf( %d , Y);     return X;   }   out& operator<<(out& X, const char& C) {     printf( %c , C);     return X;   }   out& operator<<(out& X, const string& Y) {     printf( %s , Y.c_str());     return X;   }   out& operator<<(out& X, const long long& Y) {     printf( %lld , Y);     return X;   }   out& operator<<(out& X, const float& Y) {     printf( %f , Y);     return X;   }   out& operator<<(out& X, const double& Y) {     printf( %lf , Y);     return X;   }   out& operator<<(out& X, const char Y[]) {     printf( %s , Y);     return X;   }   template <typename T>   T max(T A) {     return A;   }   template <typename T, typename... args>   T max(T A, T B, args... S) {     return max(A > B ? A : B, S...);   }   template <typename T>   T min(T A) {     return A;   }   template <typename T, typename... args>   T min(T A, T B, args... S) {     return min(A < B ? A : B, S...);   }   template <typename T>   void vectorize(int y, vector<T>& A) {     A.resize(y);   }   template <typename T, typename... args>   void vectorize(int y, vector<T>& A, args&&... S) {     A.resize(y);     vectorize(y, S...);   }   long long fast(long long a, long long b, long long pr) {     if (b == 0) return 1 % pr;     long long ans = 1 % pr;     while (b) {       if (b & 1) ans = (ans * a) % pr;       b >>= 1;       a = (a * a) % pr;     }     return ans;   }   int readInt() {     int n = 0;     scanf( %d , &n);     return n;     int ch = getchar_unlocked();     int sign = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) sign = -1;       ch = getchar_unlocked();     }     while (ch >=  0  && ch <=  9 )       n = (n << 3) + (n << 1) + ch -  0 , ch = getchar_unlocked();     n = n * sign;     return n;   }   long long readLong() {     long long n = 0;     int ch = getchar_unlocked();     int sign = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) sign = -1;       ch = getchar_unlocked();     }     while (ch >=  0  && ch <=  9 )       n = (n << 3) + (n << 1) + ch -  0 , ch = getchar_unlocked();     n = n * sign;     return n;   }   long long inv_(long long val,                  long long pr = static_cast<long long>(163577857)) {     return fast(val, pr - 2, pr);   }   }  // namespace Xrocks   int op1(int a, int b) { return a | b; }   int op2(int a, int b) { return a & b; }   int op3(int a, int b) { return a ^ b; }   class solve {    public:     solve() {       vector<int (*)(int, int)> g = {op1, op2, op3};       vector<int> v{0, 1, 2};       vector<int> w(4);       user_input >> w;       int x = 0;       do {         vector<int (*)(int, int)> f = g;         for (int i = 0; i < 3; i++) f[i] = g[v[i]];         if (x == 5)           output << f[0](f[1](f[0](w[0], w[1]), f[2](w[2], w[3])),                          f[2](f[1](w[1], w[2]), f[0](w[3], w[0])))                  <<   n ;         ++x;       } while (next_permutation(v.begin(), v.end()));     }   };   int32_t main() {     int t = 1, i = 1;     if (0) scanf( %d , &t);     while (t--) {       if (0) printf( Case #%d:  , i++);       new solve;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void err(istream_iterator<string> it) {}   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a << endl;     err(++it, args...);   }   template <class T, class R>   ostream& operator<<(ostream& os, pair<T, R>& v) {     os <<  (  << v.first <<     << v.second <<  )  <<    ;     return os;   }   template <class T>   ostream& operator<<(ostream& os, vector<T>& v) {     for (auto i : v) os << i <<    ;     return os;   }   template <class T>   ostream& operator<<(ostream& os, set<T>& v) {     for (auto i : v) os << i <<    ;     return os;   }   unordered_map<string, string*> some;   struct Node {     Node* parent;     vector<Node*> children;     int wordsCount;     string* word;     Node(Node* parent = nullptr) : parent(parent), wordsCount(0), word(nullptr) {       children.resize(26, nullptr);     }     Node* getChild(char c) {       if (children[c -  a ] == nullptr) {         children[c -  a ] = new Node(this);       }       return children[c -  a ];     }   };   struct Bor {     unordered_set<string> words;     Node* root;     Bor() : root(new Node()) {}     int addWord(string& s) {       bool was = (words.find(s) != words.end());       Node* now = root;       int ans = 0;       int step = 1;       int stepForStep = 1e9;       int len = 0;       bool gg = false;       for (char& x : s) {         len++;         now = now->getChild(x);         stepForStep--;         if (stepForStep == 0) step = 1;         ans += step;         if (!gg && now->wordsCount == 1) {           if (was && len != s.size()) {             ans++;             step = 0;             stepForStep = 1e9;           } else if (now->word != nullptr && now->word->size() != len &&                      *now->word == s.substr(0, now->word->size())) {             ans++;             step = 0;             stepForStep = now->word->size() - len + 1;           }           gg = true;         }       }       if (step != 0) {         if (now->word == nullptr) now->word = new string(s);         auto kek = now->word;         while (now != root) {           now->wordsCount += 1;           if (now->wordsCount == 1) now->word = kek;           now = now->parent;         }         if (now->wordsCount == 1) now->word = kek;         now->wordsCount += 1;       }       words.insert(s);       return ans;     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     string s;     int ans = 0;     int count = 0;     Bor bor;     int gl = 0;     int vsego = 0;     while (getline(cin, s)) {       vsego += s.size() + 1;       ans += 1;       string now;       for (char x : s) {         if (x >=  a  && x <=  z  || x >=  A  && x <=  Z ) {           now += x;         } else {           ans++;           if (now !=   ) {             int cnt = bor.addWord(now);             ans += cnt;             gl += cnt;             now =   ;           }         }       }       if (now !=   ) {         int cnt = bor.addWord(now);         ans += cnt;         gl += cnt;       }     }     cout << ans;   }


#include <bits/stdc++.h>   using ul = std::uint32_t;   using li = std::int32_t;   using ull = std::uint64_t;   using ll = std::int64_t;   using vul = std::vector<ul>;   using vvul = std::vector<vul>;   using vb = std::vector<bool>;   using vvb = std::vector<vb>;   using vvvb = std::vector<vvb>;   using vull = std::vector<ull>;   using vvull = std::vector<vull>;   using vli = std::vector<li>;   using vll = std::vector<ll>;   using pulul = std::pair<ul, ul>;   using vpulul = std::vector<pulul>;   ul n;   ll s;   class point {    public:     li x = 0;     li y = 0;     point() = default;     point(li a, li b) : x(a), y(b) {}   };   point operator-(const point& a, const point& b) {     return point(a.x - b.x, a.y - b.y);   }   point operator+(const point& a, const point& b) {     return point(a.x + b.x, a.y + b.y);   }   ul region(const point& a) {     if (a.x < 0) {       if (a.y < 0) {         return 3;       } else {         return 2;       }     } else {       if (a.y < 0) {         return 4;       } else {         return 1;       }     }   }   class lessbydir {    public:     bool operator()(const point& a, const point& b) {       if (region(a) != region(b)) {         return region(a) < region(b);       } else {         return ll(a.x) * b.y > ll(b.x) * a.y;       }     }   } less;   std::vector<point> points(2000);   vul order(2000);   vul pos(2000);   std::vector<std::pair<ul, ul>> vecs;   ll det(const point& a, const point& b) { return ll(a.x) * b.y - ll(b.x) * a.y; }   ll inner(const point& a, const point& b) {     return ll(a.x) * b.x + ll(a.y) * b.y;   }   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(0);     std::cin >> n >> s;     s <<= 1;     points.resize(n);     order.resize(n);     for (ul i = 0; i != n; ++i) {       std::cin >> points[i].x >> points[i].y;       order[i] = i;     }     for (ul i = 0; i != n; ++i) {       for (ul j = 0; j != n; ++j) {         if (i == j) {           continue;         }         vecs.push_back(std::pair<ul, ul>(i, j));       }     }     std::sort(vecs.begin(), vecs.end(), [&](const pulul& a, const pulul& b) {       return less(points[a.second] - points[a.first],                   points[b.second] - points[b.first]);     });     point dir0 = points[vecs[0].second] - points[vecs[0].first];     std::sort(order.begin(), order.end(), [&](ul a, ul b) {       return det(dir0, points[a]) < det(dir0, points[b]);     });     for (ul i = 0; i != n; ++i) {       pos[order[i]] = i;     }     for (auto vec : vecs) {       ul i = vec.first;       ul j = vec.second;       ul l = 0, r = n;       point dir = points[j] - points[i];       while (l + 1 != r) {         ul mid = l + r >> 1;         if (det(dir, points[order[mid]] - points[i]) > s) {           r = mid;         } else {           l = mid;         }       }       if (det(points[j] - points[i], points[order[l]] - points[i]) == s) {         std::cout <<  Yes  << std::endl;         std::cout << points[i].x <<     << points[i].y << std::endl;         std::cout << points[j].x <<     << points[j].y << std::endl;         std::cout << points[order[l]].x <<     << points[order[l]].y << std::endl;         return 0;       }       if (pos[j] > pos[i]) {         std::swap(order[pos[j]], order[pos[i]]);         std::swap(pos[j], pos[i]);       }     }     std::cout <<  No  << std::endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MaxN = 1000;   int n, m;   int cnt[MaxN + 5][MaxN + 5];   bool Check(int x, int y) {     if (x < 0) return false;     if (y < 0) return false;     if (x > n) return false;     if (y > n) return false;     return true;   }   int main() {     while (~scanf( %d%d , &n, &m)) {       memset(cnt, 0, sizeof(cnt));       for (int i = 1; i <= m; i++) {         int x, y;         scanf( %d%d , &x, &y);         for (int nx = x - 2; nx <= x; nx++)           for (int ny = y - 2; ny <= y; ny++)             if (Check(nx, ny)) {               cnt[nx][ny]++;               if (cnt[nx][ny] == 9) {                 printf( %d n , i);                 return 0;               }             }       }       printf( -1 n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int www = 9;   const int Size = 10000;   char buffer[Size];   int dr[] = {-1, 0, 1, 0};   int dc[] = {0, 1, 0, -1};   const int inf = 0x0fffffff;   const int size = 1000;   int d[size];   int solution(int nTest) {     int k, a, b;     scanf( %d%d%d , &k, &a, &b);     scanf( %s , buffer);     string s = buffer;     int n = s.size();     if (n / k >= a && (n + k - 1) / k <= b) {       vector<string> res;       int t = n / k;       int tt = (n + k - 1) / k;       int r = k - (n % k);       for (int i = 0; i < k - (n % k); i++) {         res.push_back(s.substr(i * t, t));       }       for (int i = 0; i < n % k; i++) {         res.push_back(s.substr(t * r + i * tt, tt));       }       for (int i = 0; i < res.size(); i++) {         puts(res[i].c_str());       }       return 0;     }     puts( No solution );     return 0;   }   int main() {     int i = 0, n = 9999;     while (i < n && solution(i)) {       i++;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int radix_len = 1e7 + 5;   long long cnt[radix_len];   int main() {     int n, k, a;     ios_base::sync_with_stdio(false);     cin >> n >> k;     long long tot = 0;     for (int i = (0), i_end_ = (n); i < i_end_; ++i) {       cin >> a;       cnt[a]++;       tot += a;     }     if (tot < k) {       cout << -1 << endl;       return 0;     }     auto bound = 1;     auto sum = 0LL;     for (int i = radix_len - 1; i > 0; i--) {       sum += cnt[i];       if (sum >= k) {         bound = i;         break;       }     }     for (int i = radix_len - 1; i > 1; i--) {       if (i / 2 < bound) break;       cnt[i / 2] += cnt[i];       cnt[i - i / 2] += cnt[i];       sum += cnt[i];       cnt[i] = 0;       while (sum - cnt[bound] >= k) {         sum -= cnt[bound];         bound++;       }     }     cout << bound << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k;     cin >> n >> k;     if (k < n / 2) {       cout << -1;       return 0;     }     if (n == 1) {       if (k)         cout << -1;       else         cout << 1;       return 0;     }     int x = k - (n - 2) / 2;     cout << x <<     << 2 * x <<    ;     for (int i = 2, j = 2 * x + 1; i < n; i++, j++) cout << j <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<string, int> Map;   string s[181], sn;   int n, i;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> sn;     cin >> n;     s[1] =  January ;     s[2] =  February ;     s[3] =  March ;     s[4] =  April ;     s[5] =  May ;     s[6] =  June ;     s[7] =  July ;     s[8] =  August ;     s[9] =  September ;     s[10] =  October ;     s[11] =  November ;     s[12] =  December ;     for (i = 13; i <= 24; i++) s[i] = s[i - 12];     for (i = 1; i <= 12; i++) Map[s[i]] = i;     cout << s[Map[sn] + n % 12] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, h;   struct Node {     int m, v;     int id;     bool operator<(const Node &x) const {       if (m != x.m) return m < x.m;       return v < x.v;     }   } q[100005];   bool ok(double times) {     int i, j;     for (j = 1, i = 0; i < n; i++) {       if (q[i].v * times - (double)j * h >= -1e-9) j++;       if (j > k) return true;     }     return false;   }   int main() {     int i, j;     cin >> n >> k >> h;     for (i = 0; i < n; i++) cin >> q[i].m;     for (i = 0; i < n; i++) {       cin >> q[i].v;       q[i].id = i + 1;     }     sort(q, q + n);     double l, r, mid;     l = 0, r = 1e20;     for (int i = 0; i < 200; i++) {       mid = (l + r) * 0.5;       if (!ok(mid))         l = mid;       else         r = mid;     }     j = 1;     for (i = 0; i < n; i++) {       if (q[i].v * r - (double)j * h >= -1e-9) {         cout << q[i].id <<    ;         j++;       }       if (j > k) break;     }   }


#include <bits/stdc++.h>   int n, a[1000][1000];   int main() {     for (int i = 1; i <= 100; i++)       for (int j = 1; j <= 100; j++) a[i][j] = 0;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int t, v;       scanf( %d , &t);       for (int j = 1; j <= t; j++) {         scanf( %d , &v);         a[i][v] = 1;       }     }     bool f1;     for (int i = 1; i <= n; i++) {       f1 = true;       bool f;       for (int j = 1; j <= n; j++)         if (i != j) {           f = false;           for (int k = 1; k <= 100; k++)             if (a[j][k] == 1 && a[i][k] == 0) {               f = true;               break;             }           if (f == false) {             f1 = false;             break;           }         }       if (f1 == true)         printf( YES );       else         printf( NO );       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N[10];   string shirt[5] = { S ,  M ,  L ,  XL ,  XXL };   map<string, int> mp;   int main() {     int K, i, d;     for ((i) = 0; (i) < (int)(5); (i)++) cin >> N[i];     cin >> K;     for ((i) = 0; (i) < (int)(5); (i)++) mp[shirt[i]] = i;     for ((i) = 0; (i) < (int)(K); (i)++) {       string s;       cin >> s;       int x = mp[s];       int ans = -1;       for (d = 0;; d++) {         if (x + d >= 0 && x + d < 5 && N[x + d] > 0) {           ans = x + d;           break;         }         if (x - d >= 0 && x - d < 5 && N[x - d] > 0) {           ans = x - d;           break;         }       }       N[ans]--;       cout << shirt[ans] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T Abs(T a) {     return a > 0 ? a : -a;   }   template <typename T>   inline T sqr(T a) {     return a * a;   }   template <typename T>   inline void relaxMin(T &a, T b) {     if (b < a) a = b;   }   template <typename T>   inline void relaxMax(T &a, T b) {     if (b > a) a = b;   }   const int INF = (int)1E9;   const long double EPS = 1E-6;   const long double PI = 3.1415926535897932384626433832795;   int dp[2000][2000];   int mod = 1000000007;   void solve() {     int n;     cin >> n;     int k;     int x = 0, y = 0;     for (int i(0), _bb(n); i < _bb; ++i) {       cin >> k;       if (k == 1)         x++;       else         y++;     }     dp[0][0] = 1;     dp[1][0] = dp[1][1] = 1;     for (int i(2), _bb(1001); i < _bb; ++i) {       dp[i][0] = (dp[i - 1][0] + (i - 1) * 1LL * dp[i - 2][0]) % mod;       for (int j(1), _bb(1001); j < _bb; ++j)         dp[i][j] = (dp[i - 1][j - 1] * 1LL * i) % mod;     }     cout << dp[n][y] << endl;   }   int main() {     srand(0xA1B2C3D4);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   void update(int *c, int x, int v) {     while (x <= m) {       c[x] += v;       x += x & -x;     }   }   long long sum(int *c, int x) {     long long ret = 0;     while (x > 0) {       ret += c[x];       x -= x & -x;     }     return ret;   }   long long calc(int *c, int L, int R) { return sum(c, R) - sum(c, L - 1); }   int c[3060 + 3060][3060], L[3060][3060], R[3060][3060], Ld[3060][3060];   char s[3060][3060];   vector<pair<int, int> > g[3060];   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) scanf( %s , s[i] + 1);     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j) {         if (s[i][j] ==  . )           L[i][j] = 0;         else           L[i][j] = L[i][j - 1] + 1;       }     for (int i = n; i > 0; --i)       for (int j = m; j > 0; --j) {         if (s[i][j] ==  . )           R[i][j] = 0;         else           R[i][j] = R[i][j + 1] + 1;         if (s[i][j] ==  . )           Ld[i][j] = 0;         else           Ld[i][j] = Ld[i + 1][j - 1] + 1;       }     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j) g[j + R[i][j] - 1].push_back(make_pair(i, j));     long long ans = 0;     for (int j = m; j > 0; --j) {       for (int i = 0; i < g[j].size(); ++i) {         int x = g[j][i].first;         int y = g[j][i].second;         update(c[x + y], y, 1);       }       for (int i = 1; i <= n; ++i) {         int mi = min(L[i][j], Ld[i][j]);         if (!mi) continue;         ans += calc(c[i + j], j - mi + 1, j);       }     }     cout << ans << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   template <int mod>   struct ModInt {     int x;     ModInt() : x(0) {}     ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}     ModInt &operator+=(const ModInt &p) {       if ((x += p.x) >= mod) x -= mod;       return *this;     }     ModInt &operator-=(const ModInt &p) {       if ((x += mod - p.x) >= mod) x -= mod;       return *this;     }     ModInt &operator*=(const ModInt &p) {       x = (int)(1LL * x * p.x % mod);       return *this;     }     ModInt &operator/=(const ModInt &p) {       *this *= p.inverse();       return *this;     }     ModInt operator-() const { return ModInt(-x); }     ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }     ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }     ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }     ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }     bool operator==(const ModInt &p) const { return x == p.x; }     bool operator!=(const ModInt &p) const { return x != p.x; }     ModInt inverse() const {       int a = x, b = mod, u = 1, v = 0, t;       while (b > 0) {         t = a / b;         swap(a -= t * b, b);         swap(u -= t * v, v);       }       return ModInt(u);     }     ModInt pow(int64_t n) const {       ModInt ret(1), mul(x);       while (n > 0) {         if (n & 1) ret *= mul;         mul *= mul;         n >>= 1;       }       return ret;     }     friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }     friend istream &operator>>(istream &is, ModInt &a) {       int64_t t;       is >> t;       a = ModInt<mod>(t);       return (is);     }     static int get_mod() { return mod; }   };   using mint = ModInt<MOD>;   long long mod_pow(long long x, long long n) {     if (n == 0) return 1;     long long res = mod_pow(x * x % MOD, n / 2);     if (n & 1) res = res * x % MOD;     return res;   }   long long power(long long num, long long pw) {     if (pw == 0) return 1;     long long res = power(num * num, pw / 2);     if (pw & 1) res *= pw;     return res;   }   long long ln(long long num, long long base) {     int steps = 0;     while (num > 1) {       num /= base;       steps++;     }     return steps;   }   int S = 100001;   vector<int> Seive(S);   void seive() {     fill(Seive.begin(), Seive.end(), 0);     Seive[0] = 0;     Seive[1] = 0;     for (long long i = 2; i <= S; i++) {       if (Seive[i]) continue;       for (long long j = i * i; j <= S; j += i) Seive[j] = 1;     }   }   long long gcd(long long int a, long long int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long lcm(int a, int b) { return (a / gcd(a, b)) * b; }   bool sortbysec(const pair<long long, long long> &a,                  const pair<long long, long long> &b) {     if (a.second == b.second) return a.first < b.first;     return (a.second < b.second);   }   bool compare(const pair<string, int> &a, const pair<string, int> &b) {     for (int i = 0; i < a.first.length(); i++) {       if (i % 2 == 0) {         if (a.first[i] < b.first[i]) return true;         if (a.first[i] > b.first[i]) return false;       } else {         if (a.first[i] > b.first[i]) return true;         if (a.first[i] < b.first[i]) return false;       }     }   }   int binarySearch(vector<pair<int, int>> a) {     int r = a.size();     int l = 1;     int ans = r;     while (l <= r) {       int mid = (l + r) / 2;       int rem = mid, curr = 0;       for (int i = 0; i < a.size(); i++) {         if (a[i].first >= rem - 1) {           if (a[i].second >= curr) {             curr++;             rem--;           }         }       }       if (rem <= 0) {         ans = mid;         l = mid + 1;       } else {         r = mid - 1;       }     }     return ans;   }   void toggle(bool &x) { x ^= 1; }   void solve() {     int q;     cin >> q;     map<int, list<int>> m;     int i = 0;     while (q--) {       int num;       cin >> num;       if (num == 1) {         int x;         cin >> x;         m[x].push_back(i);         i++;       } else {         int x, y;         cin >> x >> y;         if (x == y) continue;         if (m[x].size() > m[y].size()) m[x].swap(m[y]);         for (auto &i : m[x]) {           m[y].push_back(i);         }         m.erase(x);       }     }     vector<pair<int, int>> v;     for (auto x : m) {       for (auto y : x.second) {         v.push_back({x.first, y});       }     }     sort(v.begin(), v.end(), sortbysec);     for (auto x : v) {       cout << x.first <<    ;     }     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 1;     for (int T = 1; T <= t; T++) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   long long pow(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) {         res = (res * a) % 1000000007;       }       b >>= 1;       a = (a * a) % 1000000007;     }     return res;   }   int main() {     long long n, k;     cin >> n >> k;     long long ans = (pow(k, k - 1) * pow(n - k, n - k)) % 1000000007;     cout << ans << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   void Yahia74() {     ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);   }   const int N = 3e5 + 74, OO = 0x3f3f3f3f, MOD = (int)1e9 + 7;   int main() {     Yahia74();     long long n, d;     cin >> n >> d;     long long ans = n, c = 9, t = 10;     while (c <= n) {       long long st = 0, ed = 1e18 / t;       while (st < ed) {         long long m = st + (ed - st + 1) / 2;         if (m * t + c <= n)           st = m;         else           ed = m - 1;       }       if (st * t + c <= n && st * t + c >= n - d) ans = st * t + c;       t *= 10;       c = c * 10 + 9;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   int main() {     long long n, p;     scanf( %I64d , &n);     if (n % 2 == 0 && n != 0)       p = n + 1;     else       p = (n + 1) / 2;     printf( %I64d , p);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool isopen(char ch) {     if (ch ==  <  || ch ==  {  || ch ==  (  || ch ==  [ ) return true;     return false;   }   int main() {     int k, sum = 0, ans = 0;     string s;     cin >> k >> s;     int c[10] = {0};     for (long long int i = 0; i < s.size(); i++) {       sum = sum + s[i] -  0 ;       int d = s[i] -  0 ;       c[d]++;     }     for (int i = 0; i < 9; i++)       for (int j = 0; j < c[i]; j++) {         if (k > sum) {           sum = sum + 9 - i;           ans++;         }       }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   void scan(int &x) {     bool neg = false;     register int c;     x = 0;     c = getchar();     if (c ==  - ) {       neg = true;       c = getchar();     }     for (; (c > 47 && c < 58); c = getchar()) x = (x << 1) + (x << 3) + c - 48;     if (neg) x *= -1;   }   int main() {     string s;     cin >> s;     int k;     cin >> k;     int n = s.size();     if (k > n)       cout <<  impossible ;     else {       bool ch[26] = {false};       int cnt = 0;       for (int i = 0; i < n; i++) {         if (!ch[s[i] -  a ]) {           cnt++;           ch[s[i] -  a ] = true;         }       }       if (k - cnt >= 0)         cout << k - cnt;       else         cout <<  0 ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dy[] = {-1, 1, 0, 0};   int dx[] = {0, 0, -1, 1};   int n, m;   char mp[1005][1005];   int k;   pair<int, int> p[30];   int row[1005][1005];   int col[1005][1005];   pair<int, int> d[100005];   int return_dir(char dir) {     if (dir ==  N )       return 0;     else if (dir ==  S )       return 1;     else if (dir ==  W )       return 2;     else       return 3;   }   int main() {     for (int i = 0; i < 30; i++) p[i].first = -1;     char ch;     scanf( %d %d , &n, &m);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         ch = getchar();         while (ch == 32 || ch ==   n ) ch = getchar();         mp[i][j] = ch;         if (mp[i][j] >=  A  && mp[i][j] <=  Z )           p[mp[i][j] -  A ] = make_pair(i, j);       }     }     int c = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (mp[i][j] ==  # )           c++;         else           row[i][j] = c;       }     }     c = 0;     for (int j = 0; j < m; j++) {       for (int i = 0; i < n; i++) {         if (mp[i][j] ==  # )           c++;         else           col[i][j] = c;       }     }     scanf( %d , &k);     for (int i = 0; i < k; i++) {       string s;       cin >> s;       int a;       cin >> a;       d[i].first = return_dir(s[0]);       d[i].second = a;     }     bool was = false;     for (int i = 0; i < 30; i++) {       if (p[i].first == -1) continue;       bool ok = true;       int si = p[i].first;       int sj = p[i].second;       for (int j = 0; j < k; j++) {         int ni = si + dy[d[j].first] * d[j].second;         int nj = sj + dx[d[j].first] * d[j].second;         if (ni >= n || nj >= m || ni < 0 || nj < 0) {           ok = false;           break;         }         if (d[j].first < 2) {           if (col[ni][nj] != col[si][sj] || mp[ni][nj] ==  # ) ok = false;         } else {           if (row[ni][nj] != row[si][sj] || mp[ni][nj] ==  # ) ok = false;         }         si = ni;         sj = nj;       }       if (ok) {         was = true;         putchar( A  + i);       }     }     if (!was) cout <<  no solution ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, b;     cin >> n >> b;     long long a[n + 1];     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     a[n] = b;     sort(a, a + n + 1);     if (a[0] == b) {       cout << a[n - 1] - a[0];     } else {       if (a[n] == b) {         cout << a[n] - a[1];       } else {         long long s1, s2, s3, s4, ans;         s1 = (b - a[0]) + (a[n - 1] - a[0]);         ans = s1;         s2 = (a[n] - b) + (a[n] - a[1]);         ans = min(ans, s2);         s3 = (b - a[1]) + (a[n] - a[1]);         ans = min(ans, s3);         s4 = (a[n - 1] - b) + (a[n - 1] - a[0]);         ans = min(ans, s4);         cout << ans;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   long long int n, a[100005], dis[100005] = {0}, vis[100050] = {0}, cnt = 0;   vector<pair<long long int, long long int> > v[100005];   void dfs(long long int s, long long int f) {     vis[s] = 1;     long long int i;     for (i = 0; i < v[s].size(); i++) {       long long int x = v[s][i].first, y = v[s][i].second;       if (!vis[x]) {         if (f == 0) {           dis[x] = max(y + dis[s], y);           if (dis[x] > a[x]) {             cnt++;             dfs(x, 1);           } else             dfs(x, 0);         } else {           cnt++;           dfs(x, f);         }       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     memset(dis, 0, sizeof(dis[0]));     memset(vis, 0, sizeof(vis[0]));     long long int i, j, x, y;     cin >> n;     for (i = 1; i <= n; i++) cin >> a[i];     for (i = 2; i <= n; i++) {       cin >> x >> y;       v[i].push_back({x, y});       v[x].push_back({i, y});     }     for (i = 1; i <= n; i++) {       if (!vis[i]) dfs(i, 0);     }     cout << cnt;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100000;   int p[N], u[N];   int main() {     int n, k;     cin >> n >> k;     for (int i = 1; i <= k; i++) {       int x;       cin >> x;       if (p[x] == 0) p[x] = i;       u[x] = i;     }     long long rez = 0;     for (int i = 1; i <= n; i++) {       if (p[i] == 0) {         if (i == 1 || i == n)           rez += 2;         else           rez += 3;       } else {         if (i < n && (p[i] > u[i + 1])) rez++;         if (i > 1 && (p[i] > u[i - 1])) rez++;       }     }     cout << rez;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e9 + 7;   const long long INF = 1LL << 60;   template <class T>   inline bool chmax(T& a, T b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   template <class T>   inline bool chmin(T& a, T b) {     if (a > b) {       a = b;       return 1;     }     return 0;   }   struct UnionFind {     vector<long long> par, w;     UnionFind(long long n) : par(n, -1), w(n, 0) {}     void init(long long n) {       par.assign(n, -1);       w.assign(n, 0);     }     long long root(long long x) {       if (par[x] < 0)         return x;       else         return par[x] = root(par[x]);     }     bool issame(long long x, long long y) { return root(x) == root(y); }     bool merge(long long x, long long y) {       x = root(x);       y = root(y);       if (x == y) {         ++w[x];         return false;       }       if (par[x] > par[y]) swap(x, y);       par[x] += par[y];       par[y] = x;       w[x] += w[y];       ++w[x];       return true;     }     long long size(long long x) { return -par[root(x)]; }     long long wei(long long x) { return w[root(x)]; }   };   void solve() {     long long n, m, q;     cin >> n >> m >> q;     UnionFind uf(n + m);     long long cnt = n + m;     for (long long i = 0; i < q; ++i) {       long long r, c;       cin >> r >> c;       --r, --c;       if (!uf.issame(r, c + n)) {         uf.merge(r, c + n);         --cnt;       }     }     cout << cnt - 1 <<   n ;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct union_find {     vector<int> uf;     vector<int> num_segments;     vector<bool> used;     union_find(int n) {       uf.assign(n, -1);       num_segments.assign(n, 0);       used.assign(n, false);       for (int i = 0; i < n; ++i) {         if (i % 2 == 0) num_segments[i] = 1;       }     }     int find(int i) {       if (uf[i] < 0)         return i;       else         return uf[i] = find(uf[i]);     }     bool merge(int a, int b) {       a = find(a);       b = find(b);       if (a == b) return false;       if (uf[a] <= uf[b]) {         uf[b] = a;         if (uf[a] == uf[b]) {           uf[a]--;         }         num_segments[a] =             min(num_segments[a] + num_segments[b], 2 * (int)uf.size());         used[a] = used[a] || used[b];       } else if (uf[b] < uf[a]) {         uf[a] = b;         num_segments[b] =             min(num_segments[a] + num_segments[b], 2 * (int)uf.size());         used[b] = used[a] || used[b];       }       return true;     }   };   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int N, K;     cin >> N >> K;     string s;     cin >> s;     vector<vector<int>> groups(K);     vector<vector<int>> groups_for_bit(N);     for (int i = 0; i < K; ++i) {       int k;       cin >> k;       groups[i].resize(k);       for (int j = 0; j < k; ++j) {         cin >> groups[i][j];         groups[i][j]--;         groups_for_bit[groups[i][j]].push_back(i);       }     }     auto inverse = [](int x) { return x ^ 1; };     union_find uf(2 * K);     int num_segments = 0;     auto unset = [&](int i) {       if (uf.used[i]) {         uf.used[i] = false;         num_segments -= uf.num_segments[i];         ;       }     };     auto set = [&](int i) {       assert(!uf.used[i]);       uf.used[i] = true;       num_segments += uf.num_segments[i];       ;     };     for (int i = 0; i < N; ++i) {       ;       int g = -1;       if (groups_for_bit[i].size() == 0) {         ;       } else if (groups_for_bit[i].size() == 1) {         g = uf.find(2 * groups_for_bit[i][0]);         int ig = uf.find(inverse(g));         ;         unset(g);         unset(ig);         if (s[i] ==  0 ) {           uf.num_segments[ig] = N * 3;         } else {           uf.num_segments[g] = N * 3;         }       } else {         g = uf.find(2 * groups_for_bit[i][0]);         int h = uf.find(2 * groups_for_bit[i][1]);         int ig = uf.find(inverse(g));         int ih = uf.find(inverse(h));         ;         ;         unset(g);         unset(ig);         unset(h);         unset(ih);         if (s[i] ==  0 ) {           uf.merge(ig, h);           uf.merge(g, ih);         } else {           uf.merge(g, h);           uf.merge(ig, ih);         }       }       if (g >= 0) {         g = uf.find(g);         int ig = uf.find(inverse(g));         set(uf.num_segments[g] <= uf.num_segments[ig] ? g : ig);       }       cout << num_segments <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const pair<int, int> Dir[8] = {{0, 1}, {0, -1}, {1, 0},   {-1, 0},                                  {1, 1}, {1, -1}, {-1, -1}, {-1, 1}};   template <typename A, size_t N, typename T>   void Fill(A (&array)[N], const T &val) {     std::fill((T *)array, (T *)(array + N), val);   }   signed main() {     long long n;     scanf( %lld , &n);     long long dp[2] = {1, 2};     long long turn = 1;     while (1) {       long long next = dp[0] + dp[1];       if (next > n) {         break;       }       dp[0] = dp[1];       dp[1] = next;       turn++;     }     printf( %lld n , turn);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, ad, a[444444], u[444444];   char str[11];   int getnum(char str[]) {     int ret = 0, neg = -1, i = 1;     if (str[0] !=  - ) {       neg = 1;       i = 0;     }     for (; str[i]; i++) {       ret = ret * 10 + str[i] -  0 ;     }     ret *= neg;     return ret;   }   int main() {     int i, j, fg = 0, nd, pd, ll, lt, rt, ds, mid, ld;     scanf( %d%d , &n, &k);     ad = k;     for (i = 1; i <= n; i++) {       scanf( %s , str);       if (str[0] ==  ? )         a[i + ad] = 1;       else         u[i + ad] = getnum(str);     }     for (i = 1; i <= ad; i++) {       u[i] = -1010000000 + i;       u[ad + n + i] = 1010000000 + i;     }     for (i = 1; i <= k; i++) {       if (fg) break;       nd = pd = -1;       ll = u[i];       for (j = i + k; j <= n + 2 * ad; j += k) {         if (a[j]) continue;         if (u[j] <= ll) {           fg = 1;           break;         }         ll = u[j];       }       if (fg) break;       for (j = i; j <= n + 2 * ad; j += k) {         if (pd == -1 && !a[j] && u[j] >= 0) {           pd = j;           break;         }       }       for (j = pd; j >= 1; j -= k) {         if (nd == -1 && !a[j] && u[j] < 0) {           nd = j;           break;         }       }       for (j = pd + k; j <= n + 2 * ad; j += k) {         ld = j - k;         if (!a[j]) {           if (u[ld] >= u[j]) fg = 1;           continue;         }         if (fg) break;         a[j] = 0;         u[j] = u[ld] + 1;       }       if (fg) break;       for (j = nd - k; j >= 1; j -= k) {         ld = j + k;         if (!a[j]) {           if (u[j] >= u[ld]) fg = 1;           continue;         }         if (fg) break;         a[j] = 0;         u[j] = u[ld] - 1;       }       mid = (pd - nd) / k - 1;       if (mid > u[pd] - u[nd]) {         fg = 1;         break;       }       lt = -((mid - 1) / 2);       rt = mid / 2;       if (u[pd] <= rt) {         ds = rt - u[pd] + 1;         rt -= ds;         lt -= ds;       }       if (u[nd] >= lt) {         ds = u[nd] - lt + 1;         rt += ds;         lt += ds;       }       for (j = nd + k; j < pd; j += k) {         u[j] = lt;         lt++;       }     }     if (fg)       puts( Incorrect sequence );     else {       for (i = k + 1; i <= k + n; i++) printf( %d  , u[i]);       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int kMod = 10007;   char buf[222];   int m, n, l;   int dp[222][222][222];   int f[222];   int s;   struct Matrix {     int v[444][444];     void clear() { memset(v, 0, sizeof(v)); }   } I, A, F;   Matrix operator*(const Matrix &a, const Matrix &b) {     Matrix c;     c.clear();     for (int i = 0; i < s; ++i)       for (int k = 0; k <= i; ++k)         if (a.v[i][k])           for (int j = 0; j <= k; ++j)             if (b.v[k][j]) c.v[i][j] = (c.v[i][j] + a.v[i][k] * b.v[k][j]) % kMod;     return c;   }   Matrix powMod(const Matrix &a, int b) {     Matrix res = I, tmp = a;     while (b) {       if (b & 1) res = res * tmp;       b >>= 1;       tmp = tmp * tmp;     }     return res;   }   int main() {     scanf( %s , buf + 1);     m = strlen(buf + 1);     scanf( %d , &n);     l = m + n;     if (buf[1] != buf[m]) {       dp[0][0][1] = 1;     } else {       dp[0][0][0] = 1;     }     for (int l = 0; l < m; ++l) {       for (int r = 0; r < m - l; ++r) {         for (int k = 0; k < 222; ++k)           if (dp[l][r][k]) {             if (buf[l + 1] != buf[m - r]) {               int i, j;               i = l + 1, j = r;               if (buf[i + 1] != buf[m - j]) {                 dp[i][j][k + 1] += dp[l][r][k];                 dp[i][j][k + 1] %= kMod;               } else {                 dp[i][j][k] += dp[l][r][k];                 dp[i][j][k] %= kMod;               }               i = l, j = r + 1;               if (buf[i + 1] != buf[m - j]) {                 dp[i][j][k + 1] += dp[l][r][k];                 dp[i][j][k + 1] %= kMod;               } else {                 dp[i][j][k] += dp[l][r][k];                 dp[i][j][k] %= kMod;               }             } else {               int i, j;               i = l + 1, j = r + 1;               if (i + j >= m) {                 f[k] += dp[l][r][k];                 f[k] %= kMod;               } else {                 if (buf[i + 1] != buf[m - j]) {                   dp[i][j][k + 1] += dp[l][r][k];                   dp[i][j][k + 1] %= kMod;                 } else {                   dp[i][j][k] += dp[l][r][k];                   dp[i][j][k] %= kMod;                 }               }             }           }       }     }     s = (m - 1) + ((m - 1) / 2 + 1) * 2;     for (int i = 0; i < s; ++i) I.v[i][i] = 1;     for (int i = 0; i < m - 1; ++i) {       A.v[i + 1][i]++;       A.v[i][i] += 24;     }     for (int i = m - 1; i < (m - 1) + ((m - 1) / 2 + 1); ++i) {       if (i + 1 < (m - 1) + ((m - 1) / 2) + 1) A.v[i + 1][i]++;       A.v[i][i] += 25;       A.v[(m - 1) + ((m - 1) / 2 + 1) + (i - (m - 1))][i]++;     }     for (int i = (m - 1) + ((m - 1) / 2 + 1); i < s; ++i) {       A.v[i][i] += 26;     }     for (int i = 0; i < m; ++i) {       F.v[i][i] = 1;     }     F = powMod(A, (l - 1) / 2 + 1) * F;     int ans = 0;     for (int k = 0; k < 222; ++k)       if (f[k]) {         int n24 = k, n25 = (m - k - 1) / 2 + 1;         int from = (m - 1) - k;         int to = (m - 1) + ((m - 1) / 2 + 1) + n25 - 1;         ans = (ans + F.v[to][from] * f[k]) % kMod;       }     if (l & 1) {       F.clear();       for (int i = 0; i < m; ++i) {         F.v[i][i] = 1;       }       F = powMod(A, (l - 1) / 2) * F;       for (int k = 0; k < 222; ++k)         if (f[k]) {           int n24 = k, n25 = (m - k - 1) / 2 + 1;           if ((m - n24) % 2 == 0) {             int from = (m - 1) - k;             int to = (m - 1) + n25 - 1;             ans -= F.v[to][from] * f[k] % kMod;             if (ans < 0) ans += kMod;           }         }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int c, t, n, a[1000005], b[1000005], used[100005];   int main() {     cin >> t;     while (t--) {       cin >> n;       for (int i = 1; i <= n; i++) {         cin >> a[i];         used[i] = 0;       }       for (int i = 1; i <= n; i++) cin >> b[i];       if (n % 2 == 1 && a[n / 2 + 1] != b[n / 2 + 1]) {         cout <<  NO  << endl;         continue;       }       c = 1;       long long int l, r;       if (n % 2 == 1)         l = n / 2, r = n / 2 + 2;       else         l = n / 2, r = n / 2 + 1;       for (int j = l; j >= 1; j--) {         long long int ok = 1;         for (int i = 1; i <= n / 2; i++) {           if (used[i] == 1) continue;           if ((a[i] == b[l] && a[n - i + 1] == b[r]) ||               (a[i] == b[r] && a[n - i + 1] == b[l])) {             used[i] = 1;             ok = 0;             break;           }         }         if (ok == 1) {           c = 0;           break;         }         l--;         r++;       }       if (c == 1)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }   }


#include <bits/stdc++.h>   #define mp make_pair   #define fi first   #define se second   #define pb push_back   #define eb emplace_back   #define all(x) (x).begin(), (x).end()   #define rall(x) (x).rbegin(), (x).rend()   #define forn(i, n) for (int i = 0; i < (int)(n); ++i)   #define for1(i, n) for (int i = 1; i <= (int)(n); ++i)   #define ms(x, y) memset(x, y, sizeof(x))   #define SZ(x) int(x.size())   #define fk cout<< fk <<endl   #define db(x) cout<<(#x)<< = <<(x)<<endl   #define db2(x,y) cout<<(#x)<< = <<(x)<<   <<(#y)<< = <<(y)<<endl   using namespace std;   typedef pair<int, int> pii;   typedef vector<int> vi;   typedef long long i64;   template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }   template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }   void fastio(){ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout<<fixed;}   //1.integer overflow (1e5 * 1e5) (2e9 + 2e9)   //2.runtime error   //3.boundary condition   int tc,n,k,cnt[30],need[30];   string s;   int main() {       fastio();          cin>>tc;       while(tc--){           cin>>n>>k;           cin>>s;           ms(cnt,0);           for(int i=0; i<n; ++i){               int num=int(s[i])-int( a );               ++cnt[num];           }           bool ok=true;           for(int i=0; i<26; ++i){               if(cnt[i]%k!=0) ok=false;           }           if(ok){               cout<<s<<  n ;               continue;           }           bool have=false;           string ans=  ;           for(int i=n-1; i>=0; --i){               string res=  ;               int cur=int(s[i])-int( a );               --cnt[cur];               if(cur==25) continue;               int all_need=0;               ms(need,0);               for(int j=0; j<26; ++j){                   int goal=(cnt[j]+k-1)/k*k;                   need[j]=goal-cnt[j];                   all_need+=goal-cnt[j];               }               if(all_need<=n-i){                   if(all_need==n-i){                       int find=-1;                       for(int j=cur+1; j<26; ++j){                           if(need[j]>0){                               find=j;                               break;                           }                       }                       if(find!=-1){                           have=true;                           for(int j=0; j<i; ++j) res+=s[j];                           char ch=char(int( a )+find);                           res+=ch;                           --need[find];                           for(int j=0; j<26; ++j){                               while(need[j]>0){                                   char ch_temp=char(int( a )+j);                                   res+=ch_temp;                                   need[j]--;                               }                           }                           ans=res;                           break;                       }                   } else{                       if(((n-i)-all_need)%k==0){                           int find=-1;                           for(int j=cur+1; j<26; ++j){                               if(need[j]>0){                                   find=j;                                   break;                               }                           }                           if(find==cur+1){                               need[0]+=(n-i)-all_need;                               have=true;                               for(int j=0; j<i; ++j) res+=s[j];                               res+=char(int( a )+cur+1);                               --need[cur+1];                               for(int j=0; j<26; ++j){                                   while(need[j]>0){                                       res+=char(int( a )+j);                                       --need[j];                                   }                               }                               ans=res;                               break;                           } else{                               need[cur+1]+=k;                               need[0]+=(n-i)-all_need-k;                               have=true;                               for(int j=0; j<i; ++j) res+=s[j];                               res+=char(int( a )+cur+1);                               --need[cur+1];                               for(int j=0; j<26; ++j){                                   while(need[j]>0){                                       res+=char(int( a )+j);                                       --need[j];                                   }                               }                               ans=res;                               break;                           }                       }                   }               }           }        //   if(have) assert(SZ(ans)==n);           if(have) cout<<ans<<  n ;           else cout<<-1<<  n ;       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int main() {     scanf( %d%d , &n, &m);     if (n > m) swap(n, m);     int ans;     if (n == 1)       ans = m;     else if (n == 2) {       if (m % 4 <= 2)         ans = m + m % 4;       else         ans = m + 1;     } else       ans = (n * m + 1) / 2;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   using namespace std;   long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); }   long long lcm(long long a, long long b) { return ((a * b) / (gcd(a, b))); }   bool compare(const pair<long long, long long> &a,                const pair<long long, long long> &b) {     return a.second < b.second;   }   long long ceil(long long a, long long b) { return (a + b - 1) / b; }   long long binpowmod(long long a, long long b, long long m) {     long long res = 1;     while (b > 0) {       if (b & 1) {         res = ((res % m) * (a % m)) % m;       }       a = ((a % m) * (a % m)) % m;       b >>= 1;     }     res %= m;     return res;   }   long long binpow(long long a, long long b) {     long long res = 1;     while (b > 0) {       if (b & 1) {         res = ((res) * (a));       }       a = ((a) * (a));       b >>= 1;     }     return res;   }   void swap(long long *a, long long *b) {     long long temp = *a;     *a = *b;     *b = temp;   }   long long sum_digits(long long x) {     long long s = 0;     while (x) {       s += (x % 10);       x /= 10;     }     return s;   }   bool is_perfect_square(long long n) {     return (floor(double(sqrt(n))) == ceil(double(sqrt(n))));   }   vector<int> pr;   void prime() {     const int N = 10000000;     int lp[N + 1] = {0};     for (int i = 2; i <= N; ++i) {       if (lp[i] == 0) {         lp[i] = i;         pr.push_back(i);       }       for (int j = 0; j < (int)pr.size() && pr[j] <= lp[i] && i * pr[j] <= N; ++j)         lp[i * pr[j]] = pr[j];     }   }   long long bs(vector<long long> &arr, long long l, long long r, long long x) {     long long mid = 0;     if (r >= l) {       mid = l + (r - l) / 2;       if (arr[mid] == x) return mid;       if (arr[mid] > x) return bs(arr, l, mid - 1, x);       return bs(arr, mid + 1, r, x);     }     return -1;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     std::vector<long long> v;     int c1 = 0, c2 = 0;     for (int i = (0); i < (n); i++) {       int x;       cin >> x;       if (x == 1)         c1++;       else         c2++;     }     if (c1 == 0)       v = std::vector<long long>(n, 2);     else if (c2 == 0)       v = std::vector<long long>(n, 1);     else {       v.push_back(2);       c2--;       v.push_back(1);       c1--;       while ((c2)--) v.push_back(2);       while ((c1)--) v.push_back(1);     }     for (int i = (0); i < (n); i++) cout << v[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int a[200100];   int sub[200100];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       for (int i = 1; i <= n; i++) {         cin >> a[i];       }       sort(a + 1, a + n + 1);       for (int i = 1; i <= n; i++) {         sub[i] = sub[i - 1] + a[i - 1];         a[i] = a[i] - sub[i];       }       sort(a + 1, a + 1 + n);       cout << a[n] << endl;       memset(sub, 0, sizeof(sub));     }   }


#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1000000007ll;   const long long int MOD = 1000000009ll;   int local_debug = 0;   long long int bit_count(long long int _x) {     long long int _ret = 0;     while (_x) {       if (_x % 2 == 1) _ret++;       _x /= 2;     }     return _ret;   }   long long int bit(long long int _mask, long long int _i) {     long long int x = 1;     return (_mask & (x << _i)) == 0 ? 0 : 1;   }   long long int powermod(long long int _a, long long int _b,                          long long int _m = mod) {     long long int _r = 1;     while (_b) {       if (_b % 2 == 1) _r = (_r * _a) % _m;       _b /= 2;       _a = (_a * _a) % _m;     }     return _r;   }   long long int power(long long int _a, long long int _b) {     long long int _r = 1;     while (_b) {       if (_b % 2 == 1) _r = (_r * _a);       _b /= 2;       _a = (_a * _a);     }     return _r;   }   long long int add(long long int a, long long int b, long long int m = mod) {     a %= m;     b %= m;     long long int x = a + b;     while (x >= m) x -= m;     return x;   }   long long int sub(long long int a, long long int b, long long int m = mod) {     long long int x = a - b;     while (x < 0) x += m;     return x;   }   long long int mul(long long int a, long long int b, long long int m = mod) {     a %= m;     b %= m;     long long int x = a * b;     x %= m;     return x;   }   long long int gcd(long long int a, long long int b) {     if (a < b) {       a = a ^ b;       b = a ^ b;       a = a ^ b;     }     if (b == 0) return a;     long long int t;     while (b) {       t = b;       b = a % b;       a = t;     }     return a;   }   long long int lcm(long long int a, long long int b) {     return (a * b) / gcd(a, b);   }   long long int maxSubArraySum(vector<long long int> a, long long int size) {     long long int max_so_far = a[0];     long long int curr_max = a[0];     for (long long int i = 1; i < size; i++) {       curr_max = max(a[i], curr_max + a[i]);       max_so_far = max(max_so_far, curr_max);     }     return max_so_far;   }   int main() {     long long int n;     scanf( %lld , &n);     ;     vector<long long> hrr(n);     vector<long long> grr(n);     for (int i = 0; i < n; i++) {       scanf( %lld , &hrr[i]);       ;       scanf( %lld , &grr[i]);       ;     }     int count = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j <= n; j++) {         if (hrr[i] == grr[j]) {           count++;         }       }     }     cout << count << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 105;   int atk[N], atk2[N], def2[N];   bool mark[N];   int main() {     int n, len;     while (scanf( %d%d , &n, &len) != EOF) {       int lena = 0, lend = 0, i, j;       for (i = 0; i < n; i++) {         char s[5];         int v;         scanf(  %s%d , s, &v);         if (s[0] ==  A )           atk2[lena++] = v;         else           def2[lend++] = v;       }       for (int i = 0; i < len; i++) scanf( %d , &atk[i]);       sort(atk, atk + len);       sort(atk2, atk2 + lena);       sort(def2, def2 + lend);       memset(mark, false, sizeof(mark));       int ans1 = 0, ans2 = 0;       for (i = 0, j = 0; i < lend && j < len; i++) {         while (j < len && (mark[j] || atk[j] <= def2[i])) j++;         if (j == len) break;         mark[j] = true;       }       if (j < len) {         for (i = 0, j = 0; i < lena && j < len; i++) {           while (j < len && (mark[j] || atk[j] < atk2[i])) j++;           if (j == len) break;           mark[j] = true;           ans1 += atk[j] - atk2[i];         }         if (j < len) {           for (i = 0; i < len; i++)             if (!mark[i]) ans1 += atk[i];         } else           ans1 = 0;       }       for (i = len - 1, j = 0; i >= 0 && j < lena && atk[i] >= atk2[j];            i--, j++) {         ans2 += atk[i] - atk2[j];       }       printf( %d n , max(ans1, ans2));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, a[10000], first = -1, val, t = 1;     cin >> n;     cin >> a[0];     for (int i = 1; i < n; i++) {       cin >> a[i];       if (a[i - 1] > a[i] || a[i - 1] == a[i]) t = 0;     }     if (t == 1) {       cout <<  YES ;       return 0;     }     for (int i = 0; i < n - 1; i++) {       if (a[i] > a[i + 1] || a[i] == a[i + 1]) {         first = i;         val = a[i];         break;       }     }     if (first == -1) {       first == n - 1;       val = a[n - 1];     }     for (int i = 0; a[i] != val; i++) {       if (a[i] == a[i + 1]) {         cout <<  NO ;         return 0;       }     }     for (int i = first; i < n - 1; i++) {       if (a[i] != a[i + 1]) {         first = i;         break;       }       if (a[i + 1] == val) {         first = i + 1;       }     }     for (int i = first; i < n - 1; i++) {       if (a[i] < a[i + 1] || a[i] == a[i + 1]) {         cout <<  NO ;         return 0;       }     }     cout <<  YES ;   }


#include <bits/stdc++.h>   using namespace std;   long long int n, a, k;   char s[2000007], res[2000007];   bool vis[2000007];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     long long int maxn = -1;     for (long long int i = 0; i < n; ++i) {       cin >> s >> k;       long long int len = strlen(s);       long long int cur = INT_MIN;       for (long long int j = 0; j < k; ++j) {         cin >> a;         a--;         maxn = max(maxn, a + len);         for (long long int jj = max(cur, a); jj <= a + len - 1; ++jj) {           if (!vis[jj]) {             vis[jj] = 1;             res[jj] = s[jj - a];           }         }         cur = max(cur, a + len - 1);       }     }     for (long long int i = 0; i < maxn; ++i)       if (!res[i])         cout <<  a ;       else         cout << res[i];     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimaze( Ofast );   #pragma GCC optimize( unroll-loops )   using namespace std;   const long long maxk = 1e8 + 113;   const long long maxb = 1e18 + 113;   const long long inf = 2e18;   struct line {     long long k, b;     line() {       this->k = 0;       this->b = 0;     }     line(long long k, long long b) {       this->k = k;       this->b = b;     }     long long func(long long x) { return k * x + b; }   };   struct LiChao {     vector<line> ms;     vector<int> le, re;     long long range;     LiChao() {       this->range = maxk - 113;       ms.push_back(line());       le.push_back(-1);       re.push_back(-1);     }     LiChao(long long range) {       this->range = range;       ms.push_back(line());       le.push_back(-1);       re.push_back(-1);     }     void clear() {       ms.clear();       le.clear();       re.clear();       ms.push_back(line());       le.push_back(-1);       re.push_back(-1);     }     void push(int v, bool e) {       if (!e && le[v] == -1) {         le[v] = ms.size();         ms.push_back(ms[v]);         le.push_back(-1);         re.push_back(-1);       }       if (e && re[v] == -1) {         re[v] = ms.size();         ms.push_back(ms[v]);         le.push_back(-1);         re.push_back(-1);       }     }     void add(int v, long long l, long long r, line in) {       long long m = (l + r) >> 1;       if (l > r) return;       if (in.func(m) > ms[v].func(m)) swap(in, ms[v]);       if (l == r) return;       if (in.func(l) > ms[v].func(l)) {         push(v, 0);         add(le[v], l, m, in);       } else {         push(v, 1);         add(re[v], m + 1, r, in);       }     }     void add(line in) { add(0, -range, range, in); }     long long get(int v, long long l, long long r, long long x) {       if (l >= r) return ms[v].func(x);       long long m = (l + r) >> 1;       if (x <= m) {         if (le[v] == -1) return ms[v].func(x);         return max(get(le[v], l, m, x), ms[v].func(x));       } else {         if (re[v] == -1) return ms[v].func(x);         return max(get(re[v], m + 1, r, x), ms[v].func(x));       }     }     long long get(long long x) { return get(0, -range, range, x); }   };   signed main() {     srand(1);     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.setf(ios::fixed);     cout.precision(15);     long long n, s;     cin >> n >> s;     long long df = 0;     vector<pair<long long, long long>> ed;     for (int i = 0; i < n; i++) {       long long v, c;       cin >> v >> c;       df = max(df, v);       ed.push_back({c, -v});     }     ed.push_back({s, 1});     sort(ed.begin(), ed.end());     long long range = 1e9 + 113 + s / df;     LiChao ms(range);     long long le = -1;     for (int i = 0; i < ed.size(); i++) {       ed[i].second *= -1;       long long r = max(le, 1LL);       while (ms.get(r) < ed[i].first) r <<= 1;       r = min(r, range);       while (le + 1 < r) {         long long m = (le + r) / 2;         if (ms.get(m) < ed[i].first)           le = m;         else           r = m;       }       if (ed[i].second != -1) {         long long k = ed[i].second;         ms.add(line(k, -r * k + ms.get(r) - ed[i].first));         le = r;       } else {         cout << r;         return 0;       }     }   }


#include <bits/stdc++.h>   using namespace std;   void read() {     freopen( input.txt ,  r , stdin);     freopen( output.txt ,  w , stdout);   }   string a1, a2, b1, b2;   void check() {     if (a1[0] ==  X )       swap(a1[0], a1[1]);     else if (a1[1] ==  X )       swap(a1[1], a2[1]);     else if (a2[1] ==  X )       swap(a2[1], a2[0]);     else if (a2[0] ==  X )       swap(a2[0], a1[0]);   }   void solve() {     cin >> a1 >> a2 >> b1 >> b2;     for (int i = 0; i < 65; ++i) {       check();       if (a1 == b1 && a2 == b2) {         cout <<  YES ;         return;       }     }     cout <<  NO ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int T = 1;     while (T--) {       solve();       cout <<   n ;     }     cerr <<   nTime elapsed:   << 1.0 * clock() / CLOCKS_PER_SEC <<   s. n ;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void debug(T a, T b) {     ;   }   template <class T>   void chmin(T& a, const T& b) {     if (a > b) a = b;   }   template <class T>   void chmax(T& a, const T& b) {     if (a < b) a = b;   }   namespace std {   template <class S, class T>   ostream& operator<<(ostream& out, const pair<S, T>& a) {     out <<  (  << a.first <<  ,  << a.second <<  ) ;     return out;   }   }  // namespace std   const int INF = 7e8;   int n;   int ar[300005];   int sum[300005];   vector<int> Tpos, Opos;   int solve1(int a, int b, int A, int B) {     if (B == INF) return INF;     if (b == INF) return INF;     int Tlen = B - b;     int tmp = sum[b] * 1000;     int pt = sum[b] * 100;     int Trange = Tlen * 2000;     tmp += max(0, Trange - pt);     pt -= min(Trange, pt);     tmp += 1000;     pt += 100;     int rest = (sum[n] - sum[B + 1]) * 1000;     tmp += max(0, rest - pt);     return tmp;   }   int solve2(int a, int b, int A, int B) {     if (a == -1) return INF;     if (A == -1) return INF;     int Tlen = a - A;     int tmp = sum[A] * 1000;     int pt = sum[A] * 100;     tmp += max(0, 1000 - pt);     pt -= min(pt, 1000);     int Trange = Tlen * 2000;     tmp += Trange;     pt += Tlen * 200;     int rest = (sum[n] - sum[a + 1]) * 1000;     tmp += max(0, rest - pt);     return tmp;   }   int main() {     cin >> n;     Opos.push_back(-1);     Tpos.push_back(-1);     for (int i = 0; i < (n); ++i) {       int a;       scanf( %d , &a);       ar[i] = a / 1000;       if (ar[i] == 1)         Opos.push_back(i);       else         Tpos.push_back(i);     }     Tpos.push_back(INF);     Opos.push_back(INF);     for (int i = 0; i < (n); ++i) sum[i + 1] = sum[i] + ar[i];     int res = INF;     for (int i = 0; i < (n + 1); ++i) {       int tmp = sum[i] * 1000;       int pt = sum[i] * 100;       int rest = (sum[n] - sum[i]) * 1000;       tmp += max(0, rest - pt);       chmin(res, tmp);     }     int prev = res;     for (int i = 0; i < ((int)Tpos.size() - 1); ++i) {       int a = Tpos[i], b = Tpos[i + 1];       int B = *lower_bound((Opos).begin(), (Opos).end(), b);       int A = *(--lower_bound((Opos).begin(), (Opos).end(), a));       int X = solve1(a, b, A, B);       int Y = solve2(a, b, A, B);       chmin(res, X);       chmin(res, Y);     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 2e5 + 100, inf = 0x3f3f3f3f;   const int mod97 = 1e9 + 7, mod33 = 998244353;   const int drc[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};   struct edge {     int to, cap, dis, nt;   } e[MAX];   int tot, head[555];   int MinCost, MaxFlow;   int n, m, K, Q, H;   int ans[205][205];   int a[105][105];   int b[105];   void add(int x, int y, int cap, int dis) {     e[tot].to = y;     e[tot].cap = cap;     e[tot].dis = dis;     e[tot].nt = head[x];     head[x] = tot;     tot++;   }   bool Bellman_Ford(int S, int T) {     int pre[T + 1], flow[T + 1], dis[T + 1];     bool in[T + 1];     memset(dis, 0x3f, sizeof(dis));     memset(in, 0, sizeof(in));     dis[S] = 0;     flow[S] = inf;     pre[S] = -1;     queue<int> q;     q.push(S);     in[S] = 1;     while (q.size()) {       int tmp = q.front();       q.pop();       in[tmp] = 0;       for (int i = head[tmp]; ~i; i = e[i].nt) {         int j = e[i].to;         if (e[i].cap > 0 && dis[j] > dis[tmp] + e[i].dis) {           dis[j] = dis[tmp] + e[i].dis;           flow[j] = min(flow[tmp], e[i].cap);           pre[j] = i ^ 1;           if (!in[j]) {             q.push(j);             in[j] = 1;           }         }       }     }     if (dis[T] == inf) return 0;     MinCost += dis[T] * flow[T];     MaxFlow += flow[T];     for (int i = T; i > 0; i = e[pre[i]].to) {       if (i > 0 && i < (n << 1 | 1)) {         ans[e[pre[i]].to][i] += flow[T];       }       e[pre[i]].cap += flow[T];       e[pre[i] ^ 1].cap -= flow[T];     }     return 1;   }   void Solve() {     MaxFlow = MinCost = tot = 0;     while (Bellman_Ford(0, n << 1 | 1))       ;     int sum = 0;     for (int i = 1; i <= n; ++i) sum += b[i];     if (sum != MaxFlow) {       puts( NO );       return;     }     puts( YES );     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; ++j) {         printf( %d  , ans[i][j + n] - ans[j + n][i]);       }       puts(  );     }     return;   }   int Main() {     int t = 1;     while (t--) {       while (~scanf( %d%d , &n, &m)) {         memset(head, -1, sizeof(head));         int sum1 = 0;         for (int i = 1; i <= n; ++i) {           int x;           scanf( %d , &x);           sum1 += x;           add(0, i, x, 0);           add(i, 0, 0, 0);           add(i, i + n, inf, 0);           add(i + n, i, 0, 0);         }         for (int i = 1; i <= n; ++i) {           int x;           scanf( %d , &x);           sum1 -= x;           b[i] = x;           add(i + n, n << 1 | 1, x, 0);           add(n << 1 | 1, i + n, 0, 0);         }         for (int i = 1; i <= m; ++i) {           int x, y;           scanf( %d%d , &x, &y);           add(x, y + n, inf, 0);           add(y + n, x, 0, 0);           add(y, x + n, inf, 0);           add(x + n, y, 0, 0);         }         if (sum1) {           puts( NO );           continue;         }         Solve();       }     }     return 0;   }   int main() { return Main(); }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int k = 0, l;     int n = s.length();     if (n <= 20) {       cout <<  1             <<     << n << endl;       cout << s;     } else {       int m;       if (n % 20 == 0)         m = n / 20;       else         m = (n / 20) + 1;       if (n % m == 0) {         cout << m <<     << (n / m) << endl;         for (int i = 0; i < m; i++) {           for (int j = k; j < (n / m) + k; j++) {             cout << s[j];           }           cout <<   n ;           k = k + (n / m);         }       } else {         cout << m <<     << (n / m) + 1 << endl;         l = n % m;         for (int i = 0; i < l; i++) {           for (int j = k; j <= (n / m) + k; j++) {             cout << s[j];           }           cout <<    << endl;           k = k + (n / m) + 1;         }         for (int y = 0; y < (m - l); y++) {           for (int z = k; z < k + (n / m); z++) {             cout << s[z];           }           k = k + n / m;           cout <<  *  << endl;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void fastscan(int& number) {     bool negative = false;     register int c;     number = 0;     c = getchar();     while (c == 10) c = getchar();     if (c ==  - ) {       negative = true;       c = getchar();     }     for (; (c > 47 && c < 58); c = getchar()) number = number * 10 + c - 48;     if (negative) number *= -1;   }   const int N = 150005;   struct line {     long long k, b;     line(long long K = 0, long long B = -1000000007ll * 1000000007ll) {       k = K;       b = B;     }   };   long long f(line p, long long x) { return p.k * x + p.b; }   line t[4 * N];   void cl(int k) {     k++;     k *= 4;     for (int i = 1; i <= k; i++) t[i] = line();   }   void add(int v, int l, int r, line p) {     int m = (l + r) / 2;     bool M = f(p, m) > f(t[v], m);     bool L = f(p, l) > f(t[v], l);     if (M) swap(p, t[v]);     if (r - l == 1) return;     if (L != M)       add(v * 2, l, m, p);     else       add(v * 2 + 1, m, r, p);   }   long long get(int v, int l, int r, int pos) {     if (r - l == 1) return f(t[v], pos);     int m = (l + r) / 2;     if (pos <= m)       return max(f(t[v], pos), get(v * 2, l, m, pos));     else       return max(f(t[v], pos), get(v * 2 + 1, m, r, pos));   }   int n, used[N], color[N], cnt[N], col;   long long a[N], ans;   vector<int> g[N];   void dfsCnt(int v, int p) {     cnt[v] = 1;     for (int i = 0; i < g[v].size(); i++) {       int to = g[v][i];       if (used[to] || to == p) continue;       dfsCnt(to, v);       cnt[v] += cnt[to];     }   }   int centr(int u) {     dfsCnt(u, 0);     col++;     queue<int> q;     q.push(u);     while (!q.empty()) {       int v = q.front();       q.pop();       color[v] = col;       int can = 1;       if (!can) continue;       for (int i = 0; i < g[v].size(); i++) {         int to = g[v][i];         if (used[to] || color[to] == col) continue;         if (!(cnt[u] >= 2 * cnt[to])) {           q.push(to);           can = 0;         }       }       if (can) {         used[v] = 1;         return v;       }     }     assert(0);   }   vector<line> upd;   long long pr[N], sum1[N], sum2[N], st;   int k;   void dfs(int v, int p, int d) {     pr[v] = pr[p] + a[v];     sum1[v] = sum1[p] + d * a[v];     sum2[v] = sum2[p] + pr[v];     cnt[v] = 1;     ans = max(ans, get(1, 0, k, d - 1) + sum2[v] - st * d);     ans = max(ans, sum1[v]);     upd.push_back(line(pr[v], sum1[v]));     for (int i = 0; i < g[v].size(); i++) {       int to = g[v][i];       if (used[to] || to == p) continue;       dfs(to, v, d + 1);       cnt[v] += cnt[to];     }   }   void solve(int v, int K) {     v = centr(v);     k = max(K, 1);     pr[v] = sum1[v] = sum2[v] = st = a[v];     for (int i = 0; i < g[v].size(); i++) {       int to = g[v][i];       if (used[to]) continue;       dfs(to, v, 2);       while (!upd.empty()) {         add(1, 0, k, upd.back());         upd.pop_back();       }     }     cl(k);     for (int i = g[v].size() - 1; i >= 0; i--) {       int to = g[v][i];       if (used[to]) continue;       dfs(to, v, 2);       while (!upd.empty()) {         add(1, 0, k, upd.back());         upd.pop_back();       }     }     cl(k);     for (int i = 0; i < g[v].size(); i++) {       int to = g[v][i];       if (used[to]) continue;       solve(to, cnt[to] / 2 + 1);     }   }   int main() {     cin >> n;     for (int i = 2; i <= n; i++) {       int a, b;       fastscan(a);       fastscan(b);       g[a].push_back(b);       g[b].push_back(a);     }     for (int i = 1; i <= n; i++) {       int x;       fastscan(x);       a[i] = x;     }     solve(1, n / 2 + 1);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     string s;     cin >> s;     stack<char> stack;     int left = 0, right = 0, size = 0;     for (int i = 0; i < s.length(); i++) {       stack.push(s[i]);       if (s[i] ==  ( ) {         left++;         continue;       }       if (s[i] ==  )  && left != 0) {         left--;         stack.pop();         continue;       }       if (s[i] ==  )  && left == 0) {         right++;         continue;       }     }     cout << left <<   n ;   }   int main() {     int t;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 998244353;   const int maxn = 1000000 + 100;   long long n, ans;   long long inv[maxn], pro[maxn], invpro[maxn];   void Prepare_C() {     inv[1] = 1;     for (int i = 2; i < maxn; ++i) {       inv[i] = (MOD - MOD / i) * inv[MOD % i] % MOD;     }     pro[0] = invpro[0] = 1;     for (int i = 1; i < maxn; ++i) {       pro[i] = pro[i - 1] * i % MOD;       invpro[i] = invpro[i - 1] * inv[i] % MOD;     }   }   long long get_C(long long n, long long m) {     if (n < m) {       return 0;     }     return pro[n] * invpro[m] % MOD * invpro[n - m] % MOD;   }   long long Lucas(long long n, long long m) {     if (n < MOD && m < MOD) {       return get_C(n, m);     }     long long tmp = get_C(n % MOD, m % MOD);     if (tmp == 0) {       return 0;     }     return tmp * Lucas(n / MOD, m / MOD) % MOD;   }   long long fast_pow(long long x, long long n) {     long long ans;     for (ans = 1; n != 0; n >>= 1) {       if ((n & 1) == 1) {         ans = (ans * x) % MOD;       }       x = (x * x) % MOD;     }     return ans;   }   int main() {     ios::sync_with_stdio(false);     Prepare_C();     while (scanf( %I64d , &n) != EOF) {       ans = 0;       for (long long i = 1; i <= n; ++i) {         long long first = 1;         long long second = 1;         if (i % 2 == 0) {           first = (-1 * first % MOD + MOD) % MOD;           second = first;         }         first = 2 * first % MOD * Lucas(n, i) % MOD *                 fast_pow(3, (n - i) * n + i) % MOD;         long long tmp = ((fast_pow(3, n - i) - 1) % MOD + MOD) % MOD;         tmp = ((fast_pow(tmp, n) - fast_pow(3, (n - i) * n)) % MOD + MOD) % MOD;         second = 3 * second % MOD * Lucas(n, i) % MOD * tmp % MOD;         ans = (ans + first + second) % MOD;       }       printf( %I64d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool myfunction(int i, int j) { return (i < j); }   void solve() {     long long n;     cin >> n;     set<long long> st;     long long a;     for (long long int i = 0; i < n; i++) {       cin >> a;       st.insert(a);     }     if (st.size() > 3) {       cout << -1;       return;     } else if (st.size() == 1) {       cout << 0;       return;     } else if (st.size() == 2) {       auto it = st.begin();       int a = *it;       it++;       int b = *it;       if ((a + b) % 2 == 0) {         cout << (b - a) / 2;       } else         cout << (b - a);       return;     } else {       auto it = st.begin();       int a = *it;       it++;       int b = *it;       it++;       int c = *it;       if (c - b != b - a) {         cout <<  -1 ;         return;       } else         cout << b - a;       return;     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int test = 1;     while (test--) solve();     return 0;   }


#include <bits/stdc++.h>      using namespace std;      typedef long long ll;   typedef long double ld;   #define int ll      set<int> s;   const int N = 200000 + 7;   const int M = 998244353;      int n;   int a[N], pre[2][N], total[N];      int getsumx(int mod, int l, int r) {     if (l > r) return 0;     return pre[mod][r] - pre[mod][l - 1];   }      int get(int pre, int fin) {     int in = 0;     in = getsumx((pre + 2) % 2, pre + 2, fin + 1);     if (fin + 2 <= n) {       in += total[n] - total[fin + 1];     }     return in;   }      int megasmart(int nn, int vec[]) {     n = nn;     int sol = 0;     int lim = 0;     for (int i = 0; i < n; i++) {       a[i] = vec[i + 1];       lim += a[i];     }     reverse(a, a + n);     for (int i = 1; i <= n; i++) {       for (int m = 0; m <= 1; m++) {         pre[m][i] = pre[m][i - 1];       }       pre[i % 2][i] += a[i - 1];       total[i] = total[i - 1] + a[i - 1];     }     lim--;     lim /= 2;     for (int it = 0; it < 2; it++) {       for (int pre = it; pre < n; pre++) {         int lo = 0, hi = (n - 1 - pre) / 2, first = n + 1;         while (lo <= hi) {           int j = (lo + hi) / 2;           int fin = pre + 2 * j;           bool ok = 0;           if (get(pre, fin) <= lim) {             ok = 1;           }           if (ok) {             first = j;             hi = j - 1;           } else {             lo = j + 1;           }         }         hi = (n - 1 - pre) / 2;         if (first <= hi) {           sol += hi - first + 1;         }         if (n - 4 - pre >= 0) {           lo = 0, hi = (n - 4 - pre) / 2;           first = n + 1;           while (lo <= hi) {             int j = (lo + hi) / 2;             int fin = pre + 2 * j;             bool ok = 0;             if (get(pre, fin) - a[n - 1] <= lim) {               ok = 1;             }             if (ok) {               first = j;               hi = j - 1;             } else {               lo = j + 1;             }           }           hi = (n - 4 - pre) / 2;           if (first <= hi) {             sol += hi - first + 1;           }         }       }       lim -= a[0];     }     lim += 2 * a[0];     {       int in = a[0];       for (int i = 1; i < n; i++) {         in += a[i];         sol += (in <= lim);       }     }     return sol % M;   }      int vec[N];      signed main() {     ios::sync_with_stdio(0); cin.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       for (int i = 1LL; i <= n; i++) {         cin >> vec[i];       }       cout << megasmart(n, vec) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int in;   int a[105][105];   int b[100000];   int max(int l, int n) {     int m = a[l][0];     int in = 0;     for (int x = 0; x < n; x++) {       if (m < a[l][x]) {         m = a[l][x];         in = x;       }     }     return in;   }   int main() {     int n, m;     cin >> n >> m;     int i, j;     for (i = 0; i < m; ++i)       for (j = 0; j < n; ++j) cin >> a[i][j];     for (j = 0; j < m; ++j) {       b[max(j, n)] += 1;     }     int m1 = b[0];     if (m != 1)       for (i = 1; i < m; ++i) {         if (m1 < b[i]) {           m1 = b[i];           in = i;         }       }     else       in = max(0, n);     cout << (in + 1);   }


#include <bits/stdc++.h>   using namespace std;   int a[51];   int b[51];   int d1[51];   int d2[51];   int main() {     int n, l;     int i, j, k;     cin >> n >> l;     for (i = 1; i <= n; i++) {       cin >> a[i];       if (i >= 2) d1[i] = a[i] - a[i - 1];     }     d1[1] = a[1] + l - a[n];     for (i = 1; i <= n; i++) {       cin >> b[i];       if (i >= 2) d2[i] = b[i] - b[i - 1];     }     d2[1] = b[1] + l - b[n];     int same = 0;     for (i = 1; i <= n; i++) {       int flag = 1;       for (k = 1, j = i; k <= n; j++, k++) {         if (j > n) j = 1;         if (d1[j] != d2[k]) {           flag = 0;           break;         }       }       if (flag == 1) {         same = 1;         break;       }     }     if (same == 1)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200010, M = 1000010, P = 1e9 + 7;   const int inf = 0x3f3f3f3f;   const int INF = 0xcfcfcfcf;   const double eps = 1e-9, pi = asin(1) * 2;   long long read();   int ADD(int a, int b) { return a + b >= P ? a + b - P : a + b; }   int MINUS(int a, int b) { return a - b < 0 ? a - b + P : a - b; }   int n, k, odd = 0, even = 0;   long long read() {     long long s = 0;     bool flag = false;     char ch = getchar();     for (; ch <  0  || ch >  9 ; ch = getchar())       if (ch ==  - ) flag = true;     for (;  0  <= ch && ch <=  9 ; ch = getchar())       s = (s << 3) + (s << 1) + (ch ^  0 );     if (flag) return -s;     return s;   }   int main() {     n = read(), k = read();     for (int i = 1; i <= n; i++) {       int x = read();       if (x & 1)         odd++;       else         even++;     }     if (k == 0) {       printf( Daenerys n );       return 0;     }     if (k == n) {       if (odd & 1)         printf( Stannis n );       else         printf( Daenerys n );       return 0;     }     if (n - k & 1) {       if (odd > even) {         if (even <= n - k >> 1) {           if ((odd + even) - (n - k) & 1)             printf( Stannis n );           else             printf( Daenerys n );         } else           printf( Stannis n );       } else {         if (odd <= n - k >> 1)           printf( Daenerys n );         else           printf( Stannis n );       }     } else {       if (odd >= even) {         if (even <= (n - k >> 1)) {           if ((odd + even) - (n - k) & 1)             printf( Stannis n );           else             printf( Daenerys n );         } else           printf( Daenerys n );       } else         printf( Daenerys n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, m;     cin >> n >> m;     vector<int> h(n * m + 1), v(m * n + 1);     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];       }     }     for (int i = 0; i < n; i++) {       int a = 0;       for (int j = 0; j < m; j++) {         a = max(a, A[i][j]);       }       h[a] = 1;     }     for (int j = 0; j < m; j++) {       int a = 0;       for (int i = 0; i < n; i++) {         a = max(a, A[i][j]);       }       v[a] = 1;     }     vector<vector<int> > ans(n, vector<int>(m));     int x = -1, y = -1;     queue<pair<int, int> > q;     for (int i = n * m; i >= 1; i--) {       x += h[i];       y += v[i];       if (h[i] || v[i]) {         ans[x][y] = i;       } else {         pair<int, int> v = q.front();         q.pop();         ans[v.first][v.second] = i;       }       if (h[i]) {         for (int j = y - 1; j >= 0; j--) {           q.push({x, j});         }       }       if (v[i]) {         for (int j = x - 1; j >= 0; j--) {           q.push({j, y});         }       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cout << ans[i][j] <<    ;       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     long int n, m, a;     cin >> n >> m >> a;     long int colNum = ceil((double)a / (double)(2 * m));     a -= (colNum - 1) * m * 2;     long int rowNum = ceil((double)a / 2);     a -= rowNum * 2;     if (a == 0)       cout << colNum <<     << rowNum <<   R ;     else       cout << colNum <<     << rowNum <<   L ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int pas = 0, tem, tem1;     int n;     cin >> n;     vector<int> parent(n + 1, 0);     int x, y;     vector<vector<int> > s(n + 1, (vector<int>(3)));     for (int i = 1; i <= n; i++) {       cin >> s[i][1] >> s[i][2];     }     for (int i = 1; i <= n; i++) {       if (parent[i] == 0) {         parent[i] = i;         pas++;       }       for (int j = i + 1; j <= n; j++) {         if ((s[i][1] == s[j][1]) || (s[i][2] == s[j][2]))           if (parent[j] == 0)             parent[j] = parent[i];           else {             if (parent[i] != parent[j]) {               tem = parent[j];               tem1 = parent[i];               for (int h = 1; h <= n; h++)                 if (parent[h] == tem) parent[h] = tem1;               pas--;             }           }       }     }     pas--;     cout << pas;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const long long inf = (1LL << 60);   const double pi = acos(-1);   long long powmod(long long a, long long b) {     long long res = 1;     a %= mod;     assert(b >= 0);     for (; b; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res;   }   inline void pcas(int ca) { printf( Case %d:  , ca); }   const int maxn = 1e5 + 10;   int nex[maxn];   char s[maxn], t[maxn];   int dp[maxn], cnt[maxn];   int lens, lent;   void kmp() {     nex[0] = -1;     int j = -1;     int i = 0;     while (i < lent) {       while (j != -1 && t[i] != t[j]) j = nex[j];       nex[++i] = ++j;     }   }   int main() {     scanf( %s , s);     scanf( %s , t);     lens = strlen(s), lent = strlen(t);     kmp();     if (lens < lent) {       cout << 0;       return 0;     }     bool flag;     for (int i = lent - 1; i < lens; ++i) {       flag = 1;       for (int j = 0; j < lent; ++j) {         if (s[i - j] != t[lent - j - 1] && s[i - j] !=  ? ) {           flag = 0;           break;         }       }       dp[i] = dp[i - 1];       if (flag) {         cnt[i] = dp[i - lent];         for (int j = nex[lent]; ~j; j = nex[j]) {           cnt[i] = max(cnt[i], cnt[i - lent + j]);         }         cnt[i]++;         dp[i] = max(cnt[i], dp[i]);       }     }     printf( %d n , dp[lens - 1]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   const long long INF = 1e9 + 5;   const long long mod = 1e9 + 7;   const double pi = 3.1415926536;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     ios_base::sync_with_stdio(0);     ;     int n, m;     cin >> n >> m;     bool valid = false;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         int x;         cin >> x;         if (x == 1 && (i == 0 || j == 0 || i == (n - 1) || j == (m - 1)))           valid = true;       }     }     if (valid)       cout <<  2 n ;     else       cout <<  4 n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long n, q;       cin >> n >> q;       vector<long long> a(n);       for (long long i = 0; i < n; i++) {         cin >> a[i];       }       long long x = 0, y = 0;       for (long long i = 0; i < n; i++) {         y = max(y, x + a[i]);         x = max(x, y - a[i]);       }       cout << max(x, y) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 100005;   string A;   void solve() {     long long n, mi = 0, pl = 0;     cin >> A;     A =  +  + A;     n = A.size() - 1;     stack<char> s;     for (__typeof((n)) i = (1); i <= (n); i++) {       if (s.empty())         s.push(A[i]);       else if (s.top() == A[i])         s.pop();       else         s.push(A[i]);     }     if (s.empty())       cout <<  Yes  <<   n ;     else       cout <<  No  <<   n ;   }   signed main() {     long long t;     ios_base::sync_with_stdio(false);     t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-7;   double L, R, m1, m2, a, b, l;   double calc(double alp) {     return a * sin(alp) + b * cos(alp) - l * sin(alp) * cos(alp);   }   int main() {     scanf( %lf%lf%lf , &a, &b, &l);     if (a > b) swap(a, b);     if (l <= b) {       printf( %.8lf n , min(l, a));       return 0;     }     L = 0;     R = acos(-1) / 2;     while (R - L > eps) {       m1 = (2 * L + R) / 3;       m2 = (L + 2 * R) / 3;       if (calc(m1) > calc(m2))         L = m1;       else         R = m2;     }     L = min(calc(L), l);     if (L < eps)       puts( My poor head =( );     else       printf( %.8lf n , L);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<vector<int>> v;     v.resize(n, vector<int>(7));     for (int i = 0; i < n; i++) {       for (int j = 0; j < 7; j++) {         scanf( %1d , &v[i][j]);       }     }     int max_rooms = 0, cur = 0;     for (int i = 0; i < 7; i++) {       for (int j = 0; j < n; j++) {         cur += v[j][i];       }       max_rooms = max(max_rooms, cur);       cur = 0;     }     cout << max_rooms << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;   int n, m, g[405][405];   int in[405], dpv[405], dpb[405];   int bfs() {     queue<int> q;     q.push(1);     memset(dpv, 0x3f, sizeof dpv);     dpv[1] = 0;     while (q.size()) {       int u = q.front();       q.pop();       for (int i = 1; i <= n; ++i) {         if (!g[u][i]) continue;         if (dpv[i] == INF) {           dpv[i] = dpv[u] + 1;           q.push(i);         }       }     }     return dpv[n];   }   int bfs2() {     queue<int> q;     q.push(1);     memset(dpb, 0x3f, sizeof dpb);     dpb[1] = 0;     while (q.size()) {       int u = q.front();       q.pop();       in[u] = false;       for (int i = 1; i <= n; ++i) {         if (g[u][i] || dpb[u] + 1 == dpv[i]) continue;         if (dpb[i] == INF) {           dpb[i] = dpb[u] + 1;           q.push(i);         }       }     }     return dpb[n];   }   int main() {     ios_base::sync_with_stdio(0);     while (scanf( %d%d , &n, &m) == 2) {       memset(g, 0, sizeof g);       while (m--) {         int u, v;         scanf( %d%d , &u, &v);         g[u][v] = g[v][u] = 1;       }       int vehicle = bfs();       if (vehicle == INF)         puts( -1 );       else {         int bus = bfs2();         if (bus == INF)           puts( -1 );         else           printf( %d n , max(vehicle, bus));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, mod = 1000000007;   char t[2042];   long long dp[2042][2042], suff[2042][2042];   int solve() {     dp[n][0] = 1;     for (int cInd = n - 1; cInd >= 0; cInd--) {       dp[cInd][0] = 1;       for (int kLeft = 0; kLeft <= k; kLeft++) {         bool f = 0;         for (int d = 0; cInd + d + 1 <= n; d++) {           if (kLeft - (n - (cInd + d)) * (d + 1) >= 0) {             dp[cInd][kLeft] +=                 (1LL * dp[cInd + d + 1][kLeft - (n - (cInd + d)) * (d + 1)] *                  ( z  - t[d + cInd])) %                 mod;           } else {             f = 1;             break;           }         }         if (f) {           for (int d = n - cInd - 1; 1; d--) {             if (kLeft - (n - (cInd + d)) * (d + 1) >= 0) {               dp[cInd][kLeft] +=                   (1LL * dp[cInd + d + 1][kLeft - (n - (cInd + d)) * (d + 1)] *                    ( z  - t[d + cInd])) %                   mod;             } else {               f = 1;               break;             }           }         }         dp[cInd][kLeft] +=             (suff[cInd + 1][kLeft] + dp[cInd + 1][kLeft] * (t[cInd] -  a )) % mod;         dp[cInd][kLeft] %= mod;         suff[cInd][kLeft] += (1LL * dp[cInd + 1][kLeft] * (t[cInd] -  a ) +                               suff[cInd + 1][kLeft]) %                              mod;       }     }     return dp[0][k];   }   int main() {     cin >> n >> k;     cin >> t;     cout << solve() <<   n ;     return 0;   }


#include <bits/stdc++.h>      using namespace std;   const int c=200002, sok=2e9;   long long t[c], kom[c], h[c], ki[c], n, m, maxi;   priority_queue<pair<long long, int> > q;   vector<pair<long long, int> > ans;   int holvan(int a) {       if (!ki[a]) {           return a;       }       return ki[a]=holvan(ki[a]);   }   void unio(int a, int b) {       a=holvan(a), b=holvan(b);       ki[b]=a;       h[a]+=h[b];   }   void pb(int l, int r) {       long long sum=kom[r]-kom[l-1], d=(r-l+1), atl=(sum-1)/d;       q.push({atl, l});   }   int main()   {       ios_base::sync_with_stdio(false);       cin >> n >> m;       for (int i=1; i<=n; i++) {           cin >> t[i];           kom[i]=kom[i-1]+t[i], h[i]=1;           if (i<n) {               pb(i, i);           }       }       ans.push_back({sok, 0});       n--;       while (q.size()>0) {           long long ert=q.top().first, id=q.top().second;           q.pop();           if (!ki[id]) {               maxi=max(maxi, h[id]+h[id+h[id]]-1);               ans.push_back({ert, maxi});               int kov=id+h[id];               if (kov!=n+1) {                   unio(id, kov);                   pb(id, id+h[id]-1);               }           }       }       reverse(ans.begin(), ans.end());       int si=ans.size();       for (int i=si-2; i>=0; i--) {           ans[i].first=min(ans[i].first, ans[i+1].first);       }       for (int i=1; i<=m; i++) {           int x;           cin >> x;           int lo=-1, hi=ans.size(), mid;           while (hi-lo>1) {               mid=(lo+hi)/2;               if (ans[mid].first>=x) {                   hi=mid;               } else {                   lo=mid;               }           }           cout << ans[hi].second <<    ;       }       cout <<   n ;       return 0;   }


#include <bits/stdc++.h>   using namespace std;   unsigned long long x1, out;   unsigned long long Fac(unsigned long long x1) {     unsigned long long out = 1;     for (int i = 1; i <= x1; i++) out = out * i;     return out;   }   unsigned long long Cnk(unsigned long long a, unsigned long long b,                          unsigned long long c) {     unsigned long long outL = 1;     vector<int> fac;     if (b > c) {       unsigned long long nCount = a - b;       for (int i = 2; i <= c; i++) fac.push_back(i);       while (nCount > 0) {         outL = outL * a;         a--;         nCount--;         for (int i = 0; i < fac.size(); i++) {           if (fac[i] > -1 && outL % fac[i] == 0) {             outL = outL / fac[i];             fac[i] = -1;           }         }       }     } else {       unsigned long long nCount = a - c;       for (int i = 2; i <= b; i++) fac.push_back(i);       while (nCount > 0) {         outL = outL * a;         a--;         nCount--;         for (int i = 0; i < fac.size(); i++) {           if (fac[i] > -1 && outL % fac[i] == 0) {             outL = outL / fac[i];             fac[i] = -1;           }         }       }     }     for (int i = 0; i < fac.size(); i++) {       if (fac[i] > -1) outL = outL / fac[i];     }     return outL;   }   int main() {     int n, m, t;     cin >> n >> m >> t;     for (int i = 4; i <= n; i++) {       for (int y = 1; y <= m; y++) {         if (i + y != t) continue;         out += (Cnk(n, i, n - i) * Cnk(m, y, m - y));       }     }     cout << out;     cin >> x1;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:64000000 )   using namespace std;   const int inf = (int)1e9;   const int mod = inf + 7;   const double eps = 1e-9;   const double pi = acos(-1.0);   int n;   string second;   int a[100];   vector<int> g[202];   int dp[77][77][77][4];   int calc(vector<int> &a, int n, vector<int> &b, int m, vector<int> &c, int k) {     n = a.size() - n;     m = (int)b.size() - m;     k = (int)c.size() - k;     int x = a[n];     int cnt = 0;     for (int i = m; i < b.size(); i++)       if (b[i] < x) cnt++;     for (int i = k; i < c.size(); i++)       if (c[i] < x) cnt++;     return cnt;   }   int get(int a, int b, int c, int ty) {     if (a + b + c == 0) return 0;     int &res = dp[a][b][c][ty];     if (res != -1) return res;     res = inf;     if (a > 0) {       if (ty != 1)         res = min(res, get(a - 1, b, c, 0) + calc(g[0], a, g[1], b, g[2], c));     }     if (b > 0) {       res = min(res, get(a, b - 1, c, 1) + calc(g[1], b, g[0], a, g[2], c));     }     if (c > 0) {       res = min(res, get(a, b, c - 1, 2) + calc(g[2], c, g[1], b, g[0], a));     }     return res;   }   int main() {     cin >> n >> second;     for (int i = 0; i < n; i++) {       if (second[i] ==  V )         a[i] = 1;       else if (second[i] ==  K )         a[i] = 0;       else         a[i] = 2;       g[a[i]].push_back(i);     }     memset(dp, -1, sizeof dp);     cout << get(g[0].size(), g[1].size(), g[2].size(), 3) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     double t, a, b, c, d, k;     cin >> t;     while (t--) {       cin >> a >> b >> c >> d >> k;       double p1, p2;       p1 = ceil(a / c);       p2 = ceil(b / d);       if (p1 + p2 <= k) {         cout << p1 <<     << p2 << endl;       } else {         cout << -1 << endl;       }     }     return 0;   }