#include <bits/stdc++.h> n  n #define all(v) (v).begin(), (v).end() n #define sortv(v) sort(all(v)) n #define uniqv(v) (v).erase(unique(all(v)), (v).end()) n #define pb push_back n #define FI first n #define SE second n #define lb lower_bound n #define ub upper_bound n #define mp make_pair n #define test 1 n #define TEST if(test) n   n using namespace std; n   n typedef long long ll; n typedef pair<int, int> pii; n typedef pair<ll, ll> pll; n typedef vector<int> vi; n   n const int MOD = 1000000007; // 998244353 n const int INF = 2e9; n const ll INFLL = 1e18; n const int MAX_N = 100; n  n int T; n int N, K; n int h[MAX_N+1]; n  n int main(){ n  scanf( %d , &T); n  while(T--){ n   scanf( %d%d , &N, &K); n   for(int i=1; i<=N; i++){ n    scanf( %d , &h[i]); n   } n   bool tf = true; n   int ans = 0; n   for(int i=1; i<=K; i++){ n    int pos = 1; n    while(pos!=N){ n     if(h[pos]>=h[pos+1]) pos++; n     else break; n    } n    if(pos==N){ n     tf = false; n     printf( -1 n ); n     break; n    }else{ n     ans = pos; n     h[pos]++; n    } n   } n   if(tf){ n    printf( %d n , ans); n   } n  } n  return 0; n }


#include <bits/stdc++.h> n using namespace std; n int f(int n, vector<int> &a); n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     vector<int> a(n); n     for (int i = 0; i <= n - 1; i++) { n       cin >> a[i]; n     } n     cout << f(n, a) <<   n ; n   } n   return 0; n } n int f(int n, vector<int> &a) { n   sort(a.begin(), a.end()); n   bool flag = 0; n   for (int k = 1; k <= 1023; k++) { n     flag = 0; n     for (int i = 0; i <= n - 1; i++) { n       int x = a[i] ^ k; n       if (!binary_search(a.begin(), a.end(), x)) { n         flag = 1; n         break; n       } n     } n     if (flag == 0) { n       return k; n     } n   } n   return -1; n } n


#include <bits/stdc++.h> n using namespace std; n int oo = (int)1e9; n int get(string str) { n   int f = 0; n   for (int i = 0; i < (int)str.size(); ++i) { n     if (str[i] !=  - ) { n       if (str[i] != str[0]) f = 1; n     } n   } n   if (f == 0) return f; n   for (int i = 1; i < (int)str.size(); ++i) { n     if (str[i] !=  - ) { n       if (str[i] >= str[i - 1 - (i == 3 || i == 6)]) f = 2; n     } n   } n   return f; n } n int main() { n   int n; n   cin >> n; n   string cn; n   vector<string> vs(n); n   vector<vector<int> > cnt(n, vector<int>(3, 0)); n   for (int i = 0; i < n; ++i) { n     int s; n     cin >> s >> vs[i]; n     for (int j = 0; j < s; ++j) { n       cin >> cn; n       cnt[i][get(cn)]++; n     } n   } n   vector<vector<int> > res(3); n   for (int i = 0; i < 3; ++i) { n     int mx = 0; n     for (int j = 0; j < n; ++j) { n       mx = max(mx, cnt[j][i]); n     } n     for (int j = 0; j < n; ++j) { n       if (cnt[j][i] == mx) { n         res[i].push_back(j); n       } n     } n   } n   cout <<  If you want to call a taxi, you should call:  ; n   for (int i = 0; i < (int)res[0].size(); ++i) { n     if (i) cout <<  ,  ; n     cout << vs[res[0][i]]; n   } n   cout <<  . nIf you want to order a pizza, you should call:  ; n   for (int i = 0; i < (int)res[1].size(); ++i) { n     if (i) cout <<  ,  ; n     cout << vs[res[1][i]]; n   } n   cout <<  . nIf you want to go to a cafe with a wonderful girl, you should   n            call:  ; n   for (int i = 0; i < (int)res[2].size(); ++i) { n     if (i) cout <<  ,  ; n     cout << vs[res[2][i]]; n   } n   cout <<  .  << endl; n   return 0; n } n


#include <bits/stdc++.h> n int n, m, a, b, c; n int ans[110][110]; n int find(int i, int j) { n   for (int k = 1; k <= 10; k++) { n     if (k != ans[i][j - 1] && k != ans[i - 1][j] && k != ans[i + 1][j - 1] && n         k != ans[i - 1][j + 1]) n       return k; n   } n } n void output() { n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) printf( %c , ans[i][j] +  a  - 1); n     printf(  n ); n   } n } n int getans(int n, int m, int a, int b, int c) { n   if (b < 0) return 0; n   int test = c * 4 + (a / 2) * 4 + (b / 2) * 4; n   if (test < n * m) return 0; n   for (int i = 1; i < n; i += 2) { n     for (int j = 1; j < m; j += 2) { n       if (c > 0) { n         ans[i][j] = ans[i][j + 1] = ans[i + 1][j] = ans[i + 1][j + 1] = n             find(i, j); n         c--; n       } else if (a >= 2) { n         ans[i][j] = ans[i][j + 1] = find(i, j); n         ans[i + 1][j] = ans[i + 1][j + 1] = find(i + 1, j); n         a -= 2; n       } else { n         ans[i][j] = ans[i + 1][j] = find(i, j); n         ans[i][j + 1] = ans[i + 1][j + 1] = find(i, j + 1); n         b -= 2; n       } n     } n   } n   return 1; n } n int main() { n   while (scanf( %d %d %d %d %d , &n, &m, &a, &b, &c) != EOF) { n     memset(ans, 0, sizeof(ans)); n     if (n % 2 == 1 && m % 2 == 1) n       printf( IMPOSSIBLE n ); n     else if (n % 2 == 0 && m % 2 == 1) { n       if (b * 2 < n) n         printf( IMPOSSIBLE n ); n       else { n         int found = 1; n         b -= n / 2; n         found = getans(n, m - 1, a, b, c); n         for (int i = 1; i < n; i += 2) ans[i][m] = ans[i + 1][m] = find(i, m); n         if (found == 0) n           printf( IMPOSSIBLE n ); n         else n           output(); n       } n     } else if (n % 2 == 1 && m % 2 == 0) { n       if (a * 2 < m) n         printf( IMPOSSIBLE n ); n       else { n         int found = 1; n         a -= m / 2; n         found = getans(n - 1, m, a, b, c); n         for (int i = 1; i < m; i += 2) ans[n][i] = ans[n][i + 1] = find(n, i); n         if (found == 0) n           printf( IMPOSSIBLE n ); n         else n           output(); n       } n     } else { n       int found = getans(n, m, a, b, c); n       if (found == 0) n         printf( IMPOSSIBLE n ); n       else n         output(); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string a, b; n bool ok(string s) { n   if (s ==   ) return false; n   if (s.length() == 1 && s[0] ==  0 ) return true; n   if (s[0] ==  0 ) return false; n   for (char c : s) { n     if (c <  0  || c >  9 ) return false; n   } n   return true; n } n void cal(string s) { n   if (ok(s)) n     a += s +  , ; n   else n     b += s +  , ; n } n void go(string &ret) { n   if (ret ==   ) n     ret =  - ; n   else { n     ret =     + ret; n     ret[ret.length() - 1] =    ; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   string s, t =   ; n   cin >> s; n   for (char c : s) { n     if (c ==  ,  || c ==  ; ) { n       cal(t); n       t =   ; n     } else { n       t += c; n     } n   } n   cal(t); n   go(a); n   go(b); n   cout << a <<   n  << b; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n int getRand(int l, int r) { n   uniform_int_distribution<int> uid(l, r); n   return uid(rng); n } n unordered_map<string, int> X; n long long get_sum(long long n) { n   if (n == 1) { n     return 1; n   } n   return get_sum(n / 2) + n; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int t, num; n   long long n, sum = 0, temp; n   string str; n   cin >> t; n   while (t--) { n     sum = 0; n     temp = 1; n     cin >> n; n     while (n > 0) { n       temp = 1; n       while (temp <= n) { n         temp *= 2; n       } n       sum += get_sum(temp / 2); n       n = n - (temp / 2); n     } n     cout << sum << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6; n const long long int inf = 1e18; n vector<long long int> v, arr; n void pf() {} n long long int sqrtfun(long long int num) { n   long long int lo = 0, hi = (long long int)2e9, mid; n   if (num == 1) return num; n   while (lo + 1 < hi) { n     mid = lo + hi >> 1LL; n     if (mid * mid == num) n       return mid; n     else if (mid * mid > num) n       hi = mid; n     else n       lo = mid; n   } n   return (mid * mid > num) ? mid - 1 : mid; n } n long long int get(long long int r) { n   int ans = upper_bound(arr.begin(), arr.end(), r) - arr.begin(); n   return ans + sqrtfun(r) - 1; n } n void solve() { n   for (long long int i = 2; i <= N; i++) { n     for (long long int j = i * i * i; j <= inf; j *= i) { n       long long int x = sqrtfun(j); n       if (x * x != j) v.push_back(j); n       if (inf / i < j) break; n     } n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int t, l, r, ans = 0; n   cin >> t; n   solve(); n   sort(v.begin(), v.end()); n   for (auto i : v) { n     if (arr.empty()) n       arr.push_back(i); n     else if (arr.back() != i) n       arr.push_back(i); n   } n   while (t--) { n     cin >> r; n     cout << r - get(r) - 1 <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long call(long long n) { n   if (n == 1) n     return 1; n   else n     return n + call(n / 2); n } n void fun() { n   long long n; n   cin >> n; n   cout << call(n); n } n int main() { n   long long t; n   cin >> t; n   while (t--) { n     fun(); n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dx[4] = {1, -1, 0, 0}; n int dy[4] = {0, 0, 1, -1}; n long long gcd(long long a, long long b) { n   for (; b; a %= b, swap(a, b)) n     ; n   return a; n } n int main(void) { n   ios::sync_with_stdio(0); n   cin.tie(0), cout.tie(0); n   int t; n   cin >> t; n   while (t--) { n     string n; n     int k; n     cin >> n; n     cin >> k; n     while (true) { n       set<char> s; n       for (int i = 0; i < n.size(); i++) s.insert(n[i]); n       if (s.size() <= k) { n         cout << n <<   n ; n         break; n       } n       s.clear(); n       int ptr = 0; n       while (true) { n         s.insert(n[ptr]); n         if (s.size() > k) { n           while (n[ptr] ==  9 ) ptr--; n           n[ptr]++; n           for (int i = ptr + 1; i < n.size(); i++) n[i] =  0 ; n           break; n         } n         ptr++; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int x, n, m; n   cin >> n >> m; n   if (n < m) { n     cout <<  -1 n ; n     return 0; n   } n   if (n % 2 == 0) n     x = n / 2; n   else n     x = (n / 2) + 1; n   while (x % m != 0) { n     x++; n   } n   cout << x <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n void err(istream_iterator<string> it) {} n template <typename T, typename... Args> n void err(istream_iterator<string> it, T a, Args... args) { n   cerr << *it <<   =   << a <<   n ; n   err(++it, args...); n } n long long powMod(long long x, long long y) { n   long long p = 1; n   while (y) { n     if (y % 2) { n       p = (p * x) % ((long long)1e9 + 7); n     } n     y /= 2; n     x = (x * x) % ((long long)1e9 + 7); n   } n   return p; n } n long long CpowMod(long long x, long long y, long long w) { n   long long p = 1; n   while (y) { n     if (y % 2) { n       p = (p * x) % w; n     } n     y /= 2; n     x = (x * x) % w; n   } n   return p; n } n long long invMod(long long x) { return powMod(x, ((long long)1e9 + 7) - 2); } n long long CinvMod(long long x, long long w) { return CpowMod(x, w - 2, w); } n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n long long exGcd(long long a, long long b, long long &x, long long &y) { n   if (b == 0) { n     y = 0; n     x = 1; n     return a; n   } n   long long xtmp, ytmp; n   long long g = exGcd(b, a % b, xtmp, ytmp); n   x = ytmp; n   y = xtmp - (a / b) * ytmp; n   return g; n } n void solve() { n   long long t; n   cin >> t; n   while (t--) { n     long long n; n     long long x; n     cin >> n >> x; n     long long cnt = 0, eve = 0; n     for (long long i = 0; i <= n - 1; i++) { n       long long y; n       cin >> y; n       if (y % 2) n         cnt++; n       else n         eve++; n     } n     if (cnt == 0) { n       cout <<  NO  <<   n ; n       continue; n     } n     long long mn; n     if (x % 2 == 1) { n       mn = 0; n     } else n       mn = 1; n     if (cnt % 2 == 0) { n       x -= (cnt - 1); n     } else n       x -= cnt; n     x = max(mn, x); n     if (eve >= x) { n       cout <<  YES  <<   n ; n     } else n       cout <<  NO  <<   n ; n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n void fastio() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n } n int main() { n   fastio(); n   int n, m, temp; n   cin >> n >> m; n   vector<int> boys(n); n   vector<int> girls(m); n   int hb; n   cin >> hb; n   for (int i = 0; i < hb; i++) cin >> temp, boys[temp] = 1; n   int hg; n   cin >> hg; n   for (int i = 0; i < hg; i++) cin >> temp, girls[temp] = 1; n   int len = 100 * 100; n   int a, b; n   for (int i = 0; i < len; i++) { n     a = i % n; n     b = i % m; n     if (boys[a] == 1 || girls[b] == 1) boys[a] = 1, girls[b] = 1; n   } n   for (int i = 0; i < n; i++) n     if (boys[i] == 0) { n       cout <<  No n ; n       return 0; n     } n   for (int i = 0; i < m; i++) n     if (girls[i] == 0) { n       cout <<  No n ; n       return 0; n     } n   cout <<  Yes n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool check(int x, pair<int, int> a) { return a.first <= x && x <= a.second; } n signed main() { n   int n; n   scanf( %d , &n); n   vector<pair<int, pair<int, int>>> vert; n   vector<pair<int, pair<int, int>>> hor; n   while (n--) { n     int x1, y1, x2, y2; n     scanf( %d%d%d%d , &x1, &y1, &x2, &y2); n     if (x1 > x2) swap(x1, x2); n     if (y1 > y2) swap(y1, y2); n     if (x1 == x2) { n       vert.push_back({x1, {y1, y2}}); n     } else { n       hor.push_back({y1, {x1, x2}}); n     } n   } n   if (signed(hor.size()) < signed(vert.size())) swap(hor, vert); n   vector<bitset<5000>> inter(signed(vert.size())); n   for (int i = 0; i < signed(vert.size()); ++i) n     for (int j = 0; j < signed(hor.size()); ++j) n       inter[i][j] = check(hor[j].first, vert[i].second) && n                     check(vert[i].first, hor[j].second); n   long long ans = 0; n   for (int i = 0; i < signed(vert.size()); ++i) n     for (int j = i + 1; j < signed(vert.size()); ++j) { n       int cnt = (inter[i] & inter[j]).count(); n       ans += cnt * (cnt - 1) / 2; n     } n   printf( %I64d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int f(long long int a, long long int b) { n   long long int z = b, x = 0; n   while (z > 1) { n     z /= 2; n     x++; n   } n   long long int y = pow(2, x); n   if (a == b) n     return a; n   else if (y <= a) n     return f(a - y, b - y) + y; n   else if (pow(2, x + 1) - 1 <= b) n     return pow(2, x + 1) - 1; n   else n     return y - 1; n } n int main() { n   long long int i, n, a, b; n   cin >> n; n   while (n--) { n     cin >> a >> b; n     long long int x = f(a, b); n     cout << x << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, m, a, cnt = 0, tmp; n   scanf( %lld%lld%lld , &n, &m, &a); n   cnt = (m / a) * (n / a); n   if (n % a != 0) cnt += (m / a); n   if (m % a != 0) cnt += (n / a); n   if (m % a != 0 && n % a != 0) cnt += 1; n   printf( %lld n , cnt); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int number[120], prime[120], primecounter = 0; n void sieve() { n   for (int i = 0; i <= 100; i++) number[i] = 1; n   number[0] = 0; n   number[1] = 0; n   for (int i = 4; i <= 100; i = i + 2) number[i] = 0; n   for (int i = 3; i * i <= 100; i = i + 2) { n     for (int j = 2 * i; j <= 100; j = j + i) { n       if (number[j] == 1) number[j] = 0; n     } n   } n   for (int i = 2; i <= 100; i = i + 1) { n     if (number[i] == 1) { n       primecounter++; n       prime[primecounter] = i; n     } n   } n } n int main(void) { n   sieve(); n   char line[50]; n   int save[100 + 20]; n   int yes = 0, no = 0, s; n   for (int i = 1; prime[i] <= 53; i++) { n     printf( %d n , prime[i]); n     fflush(stdout); n     scanf( %s , line); n     if (strcmp( yes , line) == 0) { n       yes++; n       s = prime[i]; n     } else n       no++; n   } n   if (yes == 0) { n     printf( prime n ); n     fflush(stdout); n     return 0; n   } else if (yes > 1) { n     printf( composite n ); n     fflush(stdout); n     return 0; n   } else if (yes == 1) { n     int v = s * s; n     if (v <= 100) { n       printf( %d n , v); n       fflush(stdout); n       scanf( %s , line); n       if (strcmp( yes , line) == 0) { n         printf( composite n ); n         fflush(stdout); n         return 0; n       } else { n         printf( prime n ); n         fflush(stdout); n         return 0; n       } n     } else { n       printf( prime n ); n       fflush(stdout); n       return 0; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-9; n const int inf = 2000000000; n const long long infLL = 9000000000000000000; n template <typename first, typename second> n ostream& operator<<(ostream& os, const pair<first, second>& p) { n   return os <<  (  << p.first <<  ,   << p.second <<  ) ; n } n template <typename T> n ostream& operator<<(ostream& os, const vector<T>& v) { n   os <<  { ; n   for (auto it = v.begin(); it != v.end(); ++it) { n     if (it != v.begin()) os <<  ,  ; n     os << *it; n   } n   return os <<  } ; n } n template <typename T> n ostream& operator<<(ostream& os, const set<T>& v) { n   os <<  [ ; n   for (auto it = v.begin(); it != v.end(); ++it) { n     if (it != v.begin()) os <<  , ; n     os << *it; n   } n   return os <<  ] ; n } n template <typename T> n ostream& operator<<(ostream& os, const multiset<T>& v) { n   os <<  [ ; n   for (auto it = v.begin(); it != v.end(); ++it) { n     if (it != v.begin()) os <<  ,  ; n     os << *it; n   } n   return os <<  ] ; n } n template <typename first, typename second> n ostream& operator<<(ostream& os, const map<first, second>& v) { n   os <<  [ ; n   for (auto it = v.begin(); it != v.end(); ++it) { n     if (it != v.begin()) os <<  ,  ; n     os << it->first <<   =   << it->second; n   } n   return os <<  ] ; n } n void faltu() { cerr <<   n ; } n template <typename T> n void faltu(T a[], int n) { n   for (int i = 0; i < n; ++i) cerr << a[i] <<    ; n   cerr <<   n ; n } n template <typename T, typename... hello> n void faltu(T arg, const hello&... rest) { n   cerr << arg <<    ; n   faltu(rest...); n } n inline bool checkBit(long long n, int i) { return n & (1LL << i); } n inline long long setBit(long long n, int i) { n   return n | (1LL << i); n   ; n } n inline long long resetBit(long long n, int i) { return n & (~(1LL << i)); } n const int mx = 1e6 + 5; n int n, k; n int a[mx]; n struct Vertex { n   Vertex() {} n   int zero = -1, one = -1; n   int dp_zero = 0, dp_one = 0; n }; n vector<Vertex> trie; n void add(int num, int node, int pos) { n   if (pos == -1) { n     ++trie[node].dp_one; n     return; n   } n   if (checkBit(num, pos)) { n     if (trie[node].one == -1) { n       trie[node].one = (int)trie.size(); n       int node_child = (int)trie.size(); n       trie.push_back(Vertex()); n       add(num, node_child, pos - 1); n     } else { n       int node_child = trie[node].one; n       add(num, node_child, pos - 1); n     } n     ++trie[node].dp_one; n   } else { n     if (trie[node].zero == -1) { n       trie[node].zero = (int)trie.size(); n       int node_child = (int)trie.size(); n       trie.push_back(Vertex()); n       add(num, node_child, pos - 1); n     } else { n       int node_child = trie[node].zero; n       add(num, node_child, pos - 1); n     } n     ++trie[node].dp_zero; n   } n } n long long ans = 0; n int amount; n void dfs(int num, int node, int pos) { n   if (pos == -1) { n     ans += trie[node].dp_one; n     return; n   } n   if (checkBit(k, pos)) { n     if (checkBit(num, pos)) { n       if (trie[node].zero != -1) { n         int node_child = trie[node].zero; n         if (pos == 0) amount = trie[node].dp_zero; n         dfs(num, node_child, pos - 1); n       } n     } else { n       if (trie[node].one != -1) { n         int node_child = trie[node].one; n         if (pos == 0) amount = trie[node].dp_one; n         dfs(num, node_child, pos - 1); n       } n     } n   } else { n     if (checkBit(num, pos)) { n       ans += trie[node].dp_zero; n       int node_child = trie[node].one; n       if (pos == 0) amount = trie[node].dp_one; n       if (node_child != -1) dfs(num, node_child, pos - 1); n     } else { n       ans += trie[node].dp_one; n       int node_child = trie[node].zero; n       if (pos == 0) amount = trie[node].dp_zero; n       if (node_child != -1) dfs(num, node_child, pos - 1); n     } n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   cin >> n >> k; n   trie.push_back(Vertex()); n   add(0, 0, 30); n   for (int i = 1; i <= n; ++i) cin >> a[i]; n   long long Xor = 0; n   for (int i = 1; i <= n; ++i) { n     Xor ^= a[i]; n     dfs(Xor, 0, 30); n     add(Xor, 0, 30); n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n vector<pair<char, int> > vec(100); n int n; n bool check(vector<bool> &bitmask) { n   bool flag = 1; n   for (int i = 0; i < n; i++) { n     for (int j = i + 1; j < n; j++) { n       if (vec[i].first == vec[j].first) { n         if (vec[i].second != vec[j].second) { n           if (bitmask[vec[i].second - 1] == 1 || n               bitmask[vec[j].second - 1] == 1) { n             continue; n           } else { n             flag = 0; n             return flag; n           } n         } else { n           continue; n         } n       } else { n         if (vec[i].second == vec[j].second) { n           if ((vec[i].first ==  R  || vec[j].first ==  R ) && bitmask[5] == 1) { n             continue; n           } else if ((vec[i].first ==  G  || vec[j].first ==  G ) && n                      bitmask[6] == 1) { n             continue; n           } else if ((vec[i].first ==  B  || vec[j].first ==  B ) && n                      bitmask[7] == 1) { n             continue; n           } else if ((vec[i].first ==  Y  || vec[j].first ==  Y ) && n                      bitmask[8] == 1) { n             continue; n           } else if ((vec[i].first ==  W  || vec[j].first ==  W ) && n                      bitmask[9] == 1) { n             continue; n           } else { n             flag = 0; n             return flag; n           } n         } else { n           if ((vec[i].first ==  R  || vec[j].first ==  R ) && bitmask[5] == 1) { n             continue; n           } else if ((vec[i].first ==  G  || vec[j].first ==  G ) && n                      bitmask[6] == 1) { n             continue; n           } else if ((vec[i].first ==  B  || vec[j].first ==  B ) && n                      bitmask[7] == 1) { n             continue; n           } else if ((vec[i].first ==  Y  || vec[j].first ==  Y ) && n                      bitmask[8] == 1) { n             continue; n           } else if ((vec[i].first ==  W  || vec[j].first ==  W ) && n                      bitmask[9] == 1) { n             continue; n           } else if (bitmask[vec[i].second - 1] == 1 || n                      bitmask[vec[j].second - 1] == 1) { n             continue; n           } else { n             flag = 0; n             return flag; n           } n         } n       } n     } n   } n   return flag; n } n int solve() { n   vector<bool> counter(10, 0); n   int ans = 100; n   while (1) { n     if (check(counter)) { n       int cnt = 0; n       for (int i = 0; i < 10; i++) { n         if (counter[i] == 1) { n           cnt++; n         } n       } n       ans = min(ans, cnt); n     } n     int i = 0; n     while (i < 10 && counter[i] == 1) counter[i++] = 0; n     if (i == 10) break; n     counter[i] = 1; n   } n   return ans; n } n int main() { n   int t = 1; n   while (t--) { n     cin >> n; n     for (int i = 0; i < n; i++) { n       cin >> vec[i].first >> vec[i].second; n     } n     int ans = solve(); n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 300000; n int n, m, q, p[MAXN + 3], rk[MAXN + 3], dia[MAXN + 3], type, x, y, n     dist[MAXN + 3]; n bool flag[MAXN + 3]; n vector<int> adj[MAXN + 3]; n int ceil(int n) { n   if (!n) return 0; n   return (n - 1) / 2 + 1; n } n int find(int x) { return (p[x] == x ? x : (p[x] = find(p[x]))); } n void join(int x, int y) { n   x = find(x); n   y = find(y); n   if (x == y) return; n   if (rk[x] < rk[y]) swap(x, y); n   rk[x] += rk[y]; n   p[y] = x; n } n void join2(int x, int y) { n   x = find(x); n   y = find(y); n   if (x == y) return; n   if (rk[x] < rk[y]) swap(x, y); n   dia[x] = max(max(dia[x], dia[y]), ceil(dia[x]) + ceil(dia[y]) + 1); n   rk[x] += rk[y]; n   p[y] = x; n } n int calDia(int p) { n   queue<int> q; n   q.push(p); n   flag[p] = true; n   dist[p] = 0; n   int u, v; n   while (!q.empty()) { n     u = q.front(); n     q.pop(); n     for (int i = 0; i < (int)adj[u].size(); ++i) { n       v = adj[u][i]; n       if (!flag[v]) { n         flag[v] = true; n         dist[v] = dist[u] + 1; n         q.push(v); n       } n     } n   } n   q.push(u); n   flag[u] = false; n   dist[u] = 0; n   while (!q.empty()) { n     u = q.front(); n     q.pop(); n     for (int i = 0; i < (int)adj[u].size(); ++i) { n       v = adj[u][i]; n       if (flag[v]) { n         flag[v] = false; n         dist[v] = dist[u] + 1; n         q.push(v); n       } n     } n   } n   return dist[u]; n } n int main() { n   scanf( %d %d %d , &n, &m, &q); n   for (int i = 1; i <= n; ++i) p[i] = i, rk[i] = 1; n   for (int i = 1; i <= m; ++i) { n     scanf( %d %d , &x, &y); n     join(x, y); n     adj[x].push_back(y); n     adj[y].push_back(x); n   } n   for (int i = 1; i <= n; ++i) n     if (find(i) == i) { n       dia[i] = calDia(i); n     } n   while (q-- > 0) { n     scanf( %d %d , &type, &x); n     if (type == 1) { n       printf( %d n , dia[find(x)]); n     } else { n       scanf( %d , &y); n       join2(x, y); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n ostream &operator<<(ostream &os, const vector<T> &v) { n   for (T i : v) os << i <<  ,  ; n   return os; n } n template <class T> n ostream &operator<<(ostream &os, const set<T> &v) { n   for (T i : v) os << i <<    ; n   return os; n } n template <class T> n ostream &operator<<(ostream &os, const multiset<T> &v) { n   for (T i : v) os << i <<    ; n   return os; n } n template <class T, class second> n ostream &operator<<(ostream &os, const pair<T, second> &v) { n   os << v.first <<     << v.second; n   return os; n } n template <class T, class second> n ostream &operator<<(ostream &os, const map<T, second> &v) { n   for (auto i : v) os <<  (  << i.first <<   =>   << i.second <<  )  <<    ; n   return os; n } n void fast() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n } n int n, k; n long long x; n vector<long long> v; n void solve() { n   int zero = 0, pos = 0, neg = 0; n   for (long long &i : v) { n     if (i == 0) n       zero++; n     else if (i > 0) n       pos++; n     else n       neg++; n   } n   if (zero > k) { n     for (long long &i : v) cout << i <<    ; n     cout <<   n ; n     return; n   } n   if (zero) { n     if (neg % 2 == 1) { n       for (long long &i : v) n         if (i == 0 && k > 0) i += x, k--; n     } else { n       bool f = 0; n       for (long long &i : v) { n         if (i == 0 && k > 0) { n           if (f == 0) n             i -= x; n           else n             i += x; n           f = 1; n           k--; n         } n       } n     } n   } n   int f = 0; n   for (long long &i : v) n     if (i < 0) f ^= 1; n   if (f == 0) { n     int idx = 0; n     for (int i = 0; i < n; i++) { n       if (abs(v[i]) < abs(v[idx])) idx = i; n     } n     if (v[idx] < 0) { n       while (v[idx] <= 0 && k > 0) { n         v[idx] += x; n         k--; n       } n     } else { n       while (v[idx] >= 0 && k > 0) { n         v[idx] -= x; n         k--; n       } n     } n   } n   set<pair<long long, int>> s; n   for (int i = 0; i < n; i++) { n     s.insert({abs(v[i]), i}); n   } n   while (k > 0) { n     auto it = *s.begin(); n     s.erase(s.begin()); n     if (v[it.second] < 0) n       v[it.second] -= x; n     else n       v[it.second] += x; n     s.insert({abs(v[it.second]), it.second}); n     k--; n   } n   for (long long &i : v) cout << i <<    ; n   cout <<   n ; n } n int main() { n   fast(); n   cin >> n >> k >> x; n   for (int i = 0; i < n; i++) { n     long long a; n     cin >> a; n     v.push_back(a); n   } n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n struct BookInfo { n   int t; n   int a; n   int b; n   int i; n }; n struct CombinedBook { n   int t; n   BookInfo b1; n   BookInfo b2; n   bool isCombined; n }; n int main() { n   ios_base::sync_with_stdio(0); n   cout << fixed << setprecision(10); n   cerr << fixed << setprecision(10); n   cin.tie(0); n   int n, k; n   cin >> n >> k; n   vector<BookInfo> allBooks; n   int aliceLikes = 0; n   int bobLikes = 0; n   for (int i = 0; i < n; i++) { n     BookInfo info; n     cin >> info.t >> info.a >> info.b; n     info.i = i + 1; n     if (info.a) { n       aliceLikes++; n     } n     if (info.b) { n       bobLikes++; n     } n     allBooks.push_back(info); n   } n   if (aliceLikes < k || bobLikes < k) { n     cout << -1 << endl; n     return 0; n   } n   sort(allBooks.begin(), allBooks.end(), n        [](const BookInfo &a, const BookInfo &b) -> bool { return a.t < b.t; }); n   vector<BookInfo> aliceBooks; n   vector<BookInfo> bobBooks; n   vector<CombinedBook> combined; n   vector<BookInfo> other; n   for (BookInfo &book : allBooks) { n     if (book.a && book.b) { n       CombinedBook item; n       item.t = book.t; n       item.b1 = book; n       item.b2 = book; n       item.isCombined = false; n       combined.push_back(item); n     } else if (!book.a && !book.b) { n       other.push_back(book); n     } else if (book.a) { n       aliceBooks.push_back(book); n     } else if (book.b) { n       bobBooks.push_back(book); n     } n   } n   for (int i = 0; i < n; i++) { n     if (i < aliceBooks.size() && i < bobBooks.size()) { n       CombinedBook item; n       item.isCombined = true; n       item.b1 = aliceBooks[i]; n       item.b2 = bobBooks[i]; n       item.t = item.b1.t + item.b2.t; n       combined.push_back(item); n     } else if (i < aliceBooks.size()) { n       other.push_back(aliceBooks[i]); n     } else if (i < bobBooks.size()) { n       other.push_back(bobBooks[i]); n     } n   } n   if (combined.size() < k) { n     cout << -1 << endl; n     return 0; n   } n   sort(combined.begin(), combined.end(), n        [](const CombinedBook &a, const CombinedBook &b) -> bool { n          return a.t < b.t; n        }); n   vector<int> result; n   int sum = 0; n   int leftLikes = k; n   for (int i = 0; i < k; i++) { n     sum += combined[i].t; n   } n   cout << sum << endl; n } n


#include <bits/stdc++.h> n template <typename Tp> n inline void read(Tp &x) { n   x = 0; n   bool f = true; n   char ch = getchar(); n   for (; ch <  0  || ch >  9 ; ch = getchar()) f ^= ch ==  - ; n   for (; ch >=  0  && ch <=  9 ; ch = getchar()) x = x * 10 + (ch ^ 48); n   x = f ? x : -x; n } n const int N = 15e4; n struct Node { n   long long k, b; n   bool exist; n }; n struct Segment_Tree { n   Node Tre[N * 4 + 5]; n   void build(int p, int l, int r) { n     Tre[p].k = Tre[p].b = 0, Tre[p].exist = false; n     if (l == r) return; n     int mid = (l + r) >> 1; n     build(p << 1, l, mid), build(p << 1 | 1, mid + 1, r); n   } n   void update(int p, int l, int r, long long k, long long b) { n     if (!Tre[p].exist) { n       Tre[p].exist = true; n       Tre[p].k = k, Tre[p].b = b; n       return; n     } n     long long l1 = k * l + b, r1 = k * r + b, l2 = Tre[p].k * l + Tre[p].b, n               r2 = Tre[p].k * r + Tre[p].b; n     if (l1 <= l2 && r1 <= r2) return; n     if (l1 >= l2 && r1 >= r2) { n       Tre[p].k = k, Tre[p].b = b; n       return; n     } n     double x = 1.0 * (b - Tre[p].b) / (Tre[p].k - k); n     int mid = (l + r) >> 1; n     if (l1 > l2) { n       if (x <= mid) n         update(p << 1, l, mid, k, b); n       else { n         update(p << 1 | 1, mid + 1, r, Tre[p].k, Tre[p].b); n         Tre[p].k = k, Tre[p].b = b; n       } n     } else { n       if (x <= mid) { n         update(p << 1, l, mid, Tre[p].k, Tre[p].b); n         Tre[p].k = k, Tre[p].b = b; n       } else n         update(p << 1 | 1, mid + 1, r, k, b); n     } n   } n   long long query(int p, int l, int r, int x) { n     if (l == r) return Tre[p].k * x + Tre[p].b; n     int mid = (l + r) >> 1; n     long long res = Tre[p].k * x + Tre[p].b; n     if (x <= mid) n       return std::max(res, query(p << 1, l, mid, x)); n     else n       return std::max(res, query(p << 1 | 1, mid + 1, r, x)); n   } n }; n Segment_Tree T; n int a[N + 5], siz[N + 5], rt, SZ, Max; n bool vis[N + 5]; n long long ans; n std::vector<int> Vec[N + 5]; n void find(int u, int ff) { n   siz[u] = 1; n   int mx = 0; n   for (int i = 0; i < (int)Vec[u].size(); ++i) { n     int v = Vec[u][i]; n     if (v == ff || vis[v]) continue; n     find(v, u); n     siz[u] += siz[v]; n     mx = std::max(mx, siz[v]); n   } n   mx = std::max(mx, SZ - siz[u]); n   if (mx < Max) Max = mx, rt = u; n } n int m; n void dfs1(int u, int ff, int dep) { n   m = std::max(m, dep); n   for (int i = 0; i < (int)Vec[u].size(); ++i) { n     int v = Vec[u][i]; n     if (vis[v] || v == ff) continue; n     dfs1(v, u, dep + 1); n   } n } n void dfs2(int u, int ff, long long sum, long long ssum, int dep) { n   ssum += sum + a[u]; n   int cnt = 0; n   for (int i = 0; i < (int)Vec[u].size(); ++i) { n     int v = Vec[u][i]; n     if (v == ff || vis[v]) continue; n     ++cnt; n     dfs2(v, u, sum + a[u], ssum, dep + 1); n   } n   if (!cnt) ans = std::max(ans, ssum + T.query(1, 1, m, dep)); n } n void dfs3(int u, int ff, long long sum, long long ssum, int dep) { n   sum += a[u]; n   ssum += 1LL * dep * a[u]; n   int cnt = 0; n   for (int i = 0; i < (int)Vec[u].size(); ++i) { n     int v = Vec[u][i]; n     if (v == ff || vis[v]) continue; n     ++cnt; n     dfs3(v, u, sum, ssum, dep + 1); n   } n   if (!cnt) T.update(1, 1, m, sum, ssum); n } n inline void solve(int u) { n   m = 0; n   dfs1(u, 0, 1); n   T.build(1, 1, m); n   for (int i = 0; i < (int)Vec[u].size(); ++i) { n     int v = Vec[u][i]; n     if (vis[v]) continue; n     dfs2(v, u, a[u], a[u], 2); n     dfs3(v, u, 0, 0, 1); n   } n   T.build(1, 1, m); n   for (int i = (int)Vec[u].size() - 1; i >= 0; --i) { n     int v = Vec[u][i]; n     if (vis[v]) continue; n     dfs2(v, u, a[u], a[u], 2); n     dfs3(v, u, 0, 0, 1); n   } n   ans = std::max(ans, a[u] + T.query(1, 1, m, 1)); n } n void divide(int u) { n   solve(u); n   vis[u] = true; n   for (int i = 0; i < (int)Vec[u].size(); ++i) { n     int v = Vec[u][i]; n     if (vis[v]) continue; n     SZ = Max = siz[v]; n     find(v, 0); n     divide(rt); n   } n } n int main() { n   int n; n   read(n); n   for (int i = 1; i < n; ++i) { n     int u, v; n     read(u), read(v); n     Vec[u].push_back(v), Vec[v].push_back(u); n   } n   for (int i = 1; i <= n; ++i) read(a[i]); n   Max = SZ = n; n   find(1, 0); n   divide(rt); n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const signed int inf = (signed)((1u << 31) - 1); n const signed long long llf = (signed long long)((1ull << 61) - 1); n const double eps = 1e-6; n const int binary_limit = 128; n template <typename T> n inline bool readInteger(T& u) { n   char x; n   int aFlag = 1; n   while (!isdigit((x = getchar())) && x !=  -  && x != -1) n     ; n   if (x == -1) { n     ungetc(x, stdin); n     return false; n   } n   if (x ==  - ) { n     x = getchar(); n     aFlag = -1; n   } n   for (u = x -  0 ; isdigit((x = getchar())); u = (u << 1) + (u << 3) + x -  0 ) n     ; n   ungetc(x, stdin); n   u *= aFlag; n   return true; n } n int n; n char a[1005]; n char b[1005]; n map<char, char> ctc; n const char utl =  a  -  A ; n inline void init() { n   gets(a); n   gets(b); n   for (int i = 0; a[i]; i++) { n     ctc[a[i]] = b[i]; n     ctc[a[i] - utl] = b[i] - utl; n   } n } n inline void solve() { n   gets(a); n   for (int i = 0; a[i]; i++) { n     if ((a[i] >=  a  && a[i] <=  z ) || (a[i] >=  A  && a[i] <=  Z )) { n       putchar(ctc[a[i]]); n     } else { n       putchar(a[i]); n     } n   } n } n int main() { n   init(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXLEN = 100000; n long long have; n char s[MAXLEN + 1]; n int slen; n typedef struct Node { n   int start, end; n   int childs[4]; n   int suffix; n   Node(int start, int end) : start(start), end(end) { n     memset(childs, -1, sizeof(childs)); n     suffix = -1; n   } n } Node; n vector<Node> nodes; n int addnode(int start, int end) { n   nodes.push_back(Node(start, end)); n   return ((int)(nodes).size()) - 1; n } n int create() { n   int root = addnode(0, 0); n   int atnode = root, atedge = 0, atlen = 0, rem = 0, prev = -1; n   for (int i = 0; i < slen; ++i) { n     ++rem; n     prev = -1; n     while (rem > 0) { n       int tonode = nodes[atnode].childs[s[atedge] -  A ]; n       int tostart = tonode == -1 ? -1 : nodes[tonode].start; n       if (tonode != -1 && nodes[tonode].start + atlen >= nodes[tonode].end) { n         atedge += nodes[tonode].end - nodes[tonode].start; n         atlen -= nodes[tonode].end - nodes[tonode].start; n         atnode = tonode; n         continue; n       } n       if (tonode == -1) { n         int leaf = addnode(i, slen); n         nodes[atnode].childs[s[atedge] -  A ] = leaf; n         if (prev != -1) nodes[prev].suffix = atnode; n         prev = atnode; n       } else if (s[tostart + atlen] == s[i]) { n         ++atlen; n         if (prev != -1) nodes[prev].suffix = atnode; n         prev = atnode; n         break; n       } else { n         int branch = addnode(tostart, tostart + atlen); n         nodes[tonode].start += atlen; n         int leaf = addnode(i, slen); n         nodes[atnode].childs[s[atedge] -  A ] = branch; n         nodes[branch].childs[s[tostart + atlen] -  A ] = tonode; n         nodes[branch].childs[s[i] -  A ] = leaf; n         if (prev != -1) nodes[prev].suffix = branch; n         prev = branch; n       } n       --rem; n       if (atnode == root) { n         if (atlen > 0) --atlen; n         atedge++; n       } else { n         atnode = nodes[atnode].suffix; n       } n     } n   } n   return root; n } n void print(int node, int depth) { n   for (int i = 0; i < depth; ++i) printf(    ); n   printf(   ); n   for (int i = nodes[node].start; i < nodes[node].end; ++i) printf( %c , s[i]); n   printf(   ); n   printf(  -> %d , node); n   if (nodes[node].suffix != -1) printf(  [%d] , nodes[node].suffix); n   puts(  ); n   for (int i = 0; i < 4; ++i) n     if (nodes[node].childs[i] != -1) print(nodes[node].childs[i], depth + 1); n } n int cst[4][4]; n int bst[5][4][4]; n void update(int a, int b, int cur) { n   if (cur < cst[a][b]) cst[a][b] = cur; n } n void dfs(int node, int a, int len) { n   int clen = nodes[node].end - nodes[node].start; n   if (clen > 1) { n     int x = s[nodes[node].start + 1] -  A ; n     for (int b = (0); b < (4); ++b) update(a, b, len + 2 + (b == x ? 1 : 0)); n   } else n     for (int i = (0); i < (4); ++i) { n       if (nodes[node].childs[i] != -1) n         dfs(nodes[node].childs[i], a, len + 1); n       else n         for (int b = (0); b < (4); ++b) n           update(a, b, len + 2 + (b != i ? 1 : 0)); n     } n } n void run() { n   scanf( %I64d%s , &have, s); n   slen = strlen(s); n   for (int i = (0); i < (4); ++i) n     for (int j = (0); j < (4); ++j) cst[i][j] = INT_MAX; n   int root = create(); n   for (int i = (0); i < (4); ++i) dfs(nodes[root].childs[i], i, 0); n   for (int i = (0); i < (4); ++i) n     for (int j = (0); j < (4); ++j) bst[1][i][j] = cst[i][j]; n   for (int len = (2); len <= (4); ++len) n     for (int i = (0); i < (4); ++i) n       for (int j = (0); j < (4); ++j) { n         bst[len][i][j] = INT_MAX; n         for (int k = (0); k < (4); ++k) n           if (bst[len - 1][i][k] + cst[k][j] - 1 < bst[len][i][j]) n             bst[len][i][j] = bst[len - 1][i][k] + cst[k][j] - 1; n       } n   long long ret = 1; n   for (int i = (0); i < (4); ++i) n     for (int j = (0); j < (4); ++j) n       for (int k = (0); k < (4); ++k) n         for (int cyc = (1); cyc <= (4); ++cyc) n           for (int pre = (i == j ? 0 : 1); pre < (cyc); ++pre) n             for (int suf = (j == k ? 0 : 1); suf < (cyc); ++suf) { n               long long rem = have - 1; n               if (pre > 0) rem -= bst[pre][i][j] - 1; n               if (suf > 0) rem -= bst[suf][j][k] - 1; n               if (rem < 0) continue; n               long long times = rem / (bst[cyc][j][j] - 1); n               long long cur = pre + times * cyc + suf + 1; n               if (cur > ret) ret = cur; n             } n   printf( %I64d n , ret); n } n int main() { n   run(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int main() { n   int i; n   scanf( %d , &n); n   if (n == 2) { n     printf( -1 n ); n     return 0; n   } else { n     printf( 6 n10 n15 n ); n     for (i = 0; i < n - 3; i++) printf( %d n , 15 * (i + 2)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, memo[100001]; n vector<long long> a; n long long x; n long long rek(int pos) { n   long long &ret = memo[pos]; n   if (ret != -1) return ret; n   ret = rek(pos - 1) + 20; n   x = upper_bound(a.begin(), a.end(), a[pos] - 90) - a.begin(); n   if (x) n     ret = min(ret, rek(x - 1) + 50); n   else n     ret = min(ret, 50LL); n   x = upper_bound(a.begin(), a.end(), a[pos] - 1440) - a.begin(); n   if (x) n     ret = min(ret, rek(x - 1) + 120); n   else n     ret = min(ret, 120LL); n   return ret; n } n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> x; n     a.push_back(x); n   } n   memset(memo, -1, sizeof(memo)); n   memo[0] = 20; n   rek(n - 1); n   for (int i = 0; i < n; i++) n     if (!i) n       cout << memo[i] << endl; n     else n       cout << memo[i] - memo[i - 1] << endl; n } n


#include <bits/stdc++.h> n using namespace std; n void input(vector<long long>& v, long n) { n   for (long long i = 0; i < n; i++) { n     long long in; n     cin >> in; n     v.push_back(in); n   } n } n void output(vector<long long> v) { n   for (long long i = 0; i < v.size(); i++) cout << v[i] <<    ; n } n long long max_of_three(long long a, long long b, long long c) { n   if (a >= b && a >= c) n     return a; n   else if (b >= a && b >= c) n     return b; n   else n     return c; n } n long long max_of_4(long long a, long long b, long long c, long long d) { n   if (a >= b && a >= c && a >= d) n     return a; n   else if (b >= a && b >= c && b >= d) n     return b; n   else if (c >= a && c >= d && c >= b) n     return c; n   else n     return d; n } n map<long long, long long> frequency(vector<long long> v) { n   map<long long, long long> m; n   for (long long i = 0; i < v.size(); i++) { n     if (m.find(v[i]) != m.end()) n       m[v[i]]++; n     else { n       m.insert({v[i], 1}); n     } n   } n   return m; n } n long long max_occuring_int(std::map<long long, long long> m) { n   long long max_x = 0; n   long long i = 0, n = m.size(); n   std::map<long long, long long>::iterator it = m.begin(); n   for (i = 0; i < n; i++) { n     if (it->second > max_x) max_x = it->second; n     it++; n   } n   return max_x; n } n vector<long long> give_unique_in_vector(vector<long long> v) { n   sort((v).begin(), (v).end()); n   auto it = unique((v).begin(), (v).end()); n   v.resize(std::distance(v.begin(), it)); n   vector<long long> x = v; n   return x; n } n bool isVowel(char c) { n   return (c ==  a  | c ==  e  || c ==  i  || c ==  o  || c ==  u  || c ==  y  || n           c ==  A  || c ==  E  || c ==  I  || c ==  O  || c ==  U  || c ==  Y ); n } n string removeWord(string str, string word) { n   if (str.find(word) != string::npos) { n     size_t p = -1; n     string tempWord = word +    ; n     while ((p = str.find(word)) != string::npos) n       str.replace(p, tempWord.length(),   ); n     tempWord =     + word; n     while ((p = str.find(word)) != string::npos) n       str.replace(p, tempWord.length(),   ); n   } n   return str; n } n long long calc(long long i, long long j, long long n) { n   return (i + 1 - 1) * n + j + 1; n } n bool compare_descending(long long a, long long b) { return a > b; } n void solve() { n   int n, k, i; n   string s; n   cin >> n >> k >> s; n   if (n - k < k - 1) { n     for (i = k - 1; i < n - 1; i++) cout <<  RIGHT n ; n     for (i; i >= 0; i--) { n       cout <<  PRINT   << s[i] << endl; n       if (i != 0) cout <<  LEFT n ; n     } n   } else { n     for (i = k - 1; i > 0; i--) cout <<  LEFT n ; n     for (i; i < n; i++) { n       cout <<  PRINT   << s[i] << endl; n       if (i != n - 1) cout <<  RIGHT n ; n     } n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 1e5 + 5; n const long long INF = 1e10; n const int MOD = 1e9 + 7; n const double EPS = 1e-7; n const double PI = acos(-1.0); n pair<long long, long long> p[N]; n long long n, k, a[N]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL), cout.tie(NULL); n   cin >> n >> k; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     p[i] = {a[i], i}; n   } n   sort(p, p + n); n   long long ans = LLONG_MIN; n   for (int l = 0; l < n; l++) { n     for (int r = l; r < n; r++) { n       long long sum = 0; n       vector<long long> subarr(r - l + 1); n       for (int i = l, j = 0; i <= r; i++, j++) { n         subarr[j] = a[i]; n         sum += a[i]; n       } n       sort(subarr.begin(), subarr.end()); n       for (int i = 0, j = n - 1; i < min(k, r - l + 1ll); i++) { n         while (j >= 0 && p[j].second <= r && p[j].second >= l) { n           j--; n         } n         if (j >= 0) { n           sum = max(sum, sum - subarr[i] + p[j].first); n           j--; n         } n       } n       ans = max(ans, sum); n     } n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n const int infi = 2147483600; n const long long infl = 1e17; n int n; n pair<int, int> pbef[200005]; n struct SegmentTree { n  private: n   int N; n   vector<long long> node; n   long long e; n  n  public: n   SegmentTree() {} n   SegmentTree(long long e) : e(e) {} n   void __init__(int sz) { n     N = 1; n     while (N < sz) N *= 2; n     node.resize(2 * N - 1, e); n   } n   void build(vector<long long> &v) { n     int sz = int(v.size()); n     __init__(sz); n     for (long long i = 0; i < (long long)sz; i++) { n       node[i + N - 1] = v[i]; n     } n     for (int i = N - 2; i >= 0; i--) { n       node[i] = (node[i * 2 + 1] + node[i * 2 + 2]); n     } n   } n   void update(int k, long long x) { n     k += N - 1; n     node[k] = x; n     while (k > 0) { n       k = (k - 1) / 2; n       node[k] = (node[2 * k + 1] + node[2 * k + 2]); n     } n   } n   void renew(int b, int e, long long x) { n     renew(b, e, 0, 0, N, x); n     return; n   } n   void renew(int b, int e, int k, int l, int r, long long x) { n     if (e <= 0 || b >= N) return; n     if (k > 0) { n       node[k] = (node[k] + node[(k - 1) / 2]); n     } n     if (r < b || e < l) return; n     if (b <= l && r <= e) { n       node[k] = min(node[k], x); n       return; n     } else if (k < N - 1) { n       renew(b, e, 2 * k + 1, l, (l + r) / 2, x); n       renew(b, e, 2 * k + 2, (l + r) / 2, r, x); n       return; n     } n     return; n   } n   long long get(int i) { n     int k = i + N - 1; n     long long res = node[k]; n     while (k > 0) { n       k = (k - 1) / 2; n       res = min(res, node[k]); n     } n     return res; n   } n   long long query(int a, int b) { return query(a, b, 0, 0, N); } n   long long query(int a, int b, int k, int l, int r) { n     if (b <= l || r <= a) return e; n     if (a <= l && r <= b) return node[k]; n     long long vl, vr; n     vl = query(a, b, 2 * k + 1, l, (l + r) / 2); n     vr = query(a, b, 2 * k + 2, (l + r) / 2, r); n     return (vl + vr); n   } n   void recalc() { n     for (long long k = 0; k < (long long)N - 1; k++) { n       node[2 * k + 1] = (node[2 * k * 1] + node[k]); n       node[2 * k + 2] = (node[2 * k * 2] + node[k]); n     } n   } n   long long show_one(int i) { return node[i + N - 1]; } n   void show() { n     for (long long i = 0; i < (long long)N; i++) cout << node[i] <<    ; n     cout << endl; n     return; n   } n }; n int main() { n   set<int> xapper, yapper; n   map<int, int> xidx, yidx; n   cin >> n; n   for (long long i = 0; i < (long long)n; i++) { n     int x, y; n     cin >> x >> y; n     xapper.insert(x); n     yapper.insert(y); n     pbef[i] = make_pair(x, y); n   } n   int xcnt = 0; n   for (auto x : xapper) { n     xidx[x] = xcnt; n     xcnt++; n   } n   int ycnt = 0; n   for (auto y : yapper) { n     yidx[y] = ycnt; n     ycnt++; n   } n   ycnt--; n   map<int, set<int>> p; n   for (long long i = 0; i < (long long)n; i++) { n     p[yidx[pbef[i].second]].insert(xidx[pbef[i].first]); n   } n   SegmentTree seg(0); n   seg.__init__(xcnt); n   long long ans = 0; n   int bef = 0; n   for (long long y = (long long)ycnt; y > (long long)-1; y--) { n     int cnt = 0; n     int nwe = 0; n     int bef = 0; n     for (auto x : p[y]) { n       seg.update(x, 1); n     } n     for (auto x : p[y]) { n       if (seg.show_one(x) == 0) { n         ans += (seg.query(0, x + 1) - bef) * seg.query(x, xcnt); n         nwe++; n       } else { n         ans += (seg.query(0, x + 1) - bef) * seg.query(x, xcnt); n       } n       bef = seg.query(0, x + 1); n       cnt++; n     } n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200200; n struct BIT { n   int a[N]; n   void add(int x, int v = 1) { n     for (; x < N; x += x & -x) { n       a[x] += v; n     } n   } n   int kth(int k) { n     int x = 0; n     for (int i = 18; i >= 0; i--) { n       if (x + (1 << i) < N) { n         int tot = a[x + (1 << i)]; n         if (k > tot) { n           k -= tot; n           x += (1 << i); n         } n       } n     } n     return x + 1; n   } n }; n BIT tr; n pair<int, int> p[N]; n pair<pair<int, int>, int> q[N]; n int a[N]; n int ans[N]; n int main() { n   ios::sync_with_stdio(false); n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     p[i].first = -a[i]; n     p[i].second = i; n   } n   sort(p, p + n); n   int m; n   cin >> m; n   for (int i = 0; i < m; i++) { n     cin >> q[i].first.first >> q[i].first.second; n     q[i].second = i; n   } n   sort(q, q + m); n   int x = 0; n   for (int i = 0; i < n; i++) { n     tr.add(p[i].second + 1); n     while (x < m && q[x].first.first == i + 1) { n       ans[q[x].second] = a[tr.kth(q[x].first.second) - 1]; n       x++; n     } n   } n   for (int i = 0; i < m; i++) { n     printf( %d n , ans[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename Arg1> n void __f(const char* name, Arg1&& arg1) { n   cout << name <<  :  << arg1 <<   n ; n } n template <typename Arg1, typename... Args> n void __f(const char* names, Arg1&& arg1, Args&&... args) { n   const char* comma = strchr(names + 1,  , ); n   cout.write(names, comma - names) <<  :  << arg1 <<   | ; n   __f(comma + 1, args...); n } n void Ishan_Pandey() { n   cin.tie(0); n   cout.tie(0); n   ios_base::sync_with_stdio(0); n   cout << setprecision(16) << fixed; n } n const long long int N = 200010; n long long int parent[N], rank1[N]; n void make_set(long long int v) { n   parent[v] = v; n   rank1[v] = 0; n } n long long int find_set(long long int v) { n   if (v == parent[v]) return v; n   return parent[v] = find_set(parent[v]); n } n void union_sets(long long int a, long long int b) { n   a = find_set(a); n   b = find_set(b); n   if (a != b) { n     if (rank1[a] < rank1[b]) swap(a, b); n     parent[b] = a; n     if (rank1[a] == rank1[b]) rank1[a]++; n   } n } n void solve() { n   long long int n; n   cin >> n; n   vector<long long int> a(n + 2, 0); n   for (long long int i = 1; i <= n; i++) { n     cin >> a[i]; n   } n   long long int ans = 0; n   for (long long int i = 1; i <= n; i++) a[i] = min(a[i], a[i - 1] + 1); n   for (long long int i = n; i >= 1; i--) a[i] = min(a[i], a[i + 1] + 1); n   for (long long int i = 1; i <= n; i++) ans = max(ans, a[i]); n   cout << ans; n } n int32_t main() { n   Ishan_Pandey(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int mostFrequent(int arr[], int n) { n   sort(arr, arr + n); n   int max_count = 1, res = arr[0], curr_count = 1; n   for (int i = 1; i < n; i++) { n     if (arr[i] == arr[i - 1]) n       curr_count++; n     else { n       if (curr_count > max_count) { n         max_count = curr_count; n         res = arr[i - 1]; n       } n       curr_count = 1; n     } n   } n   if (curr_count > max_count) { n     max_count = curr_count; n     res = arr[n - 1]; n   } n   return res; n } n unsigned int countDivisors(unsigned int n) { n   int cnt = 0; n   for (int i = 1; i <= sqrt(n); i++) { n     if (n % i == 0) { n       if (n / i == i) n         cnt++; n       else n         cnt = cnt + 2; n     } n   } n   return cnt; n } n int main() { n   int n, a; n   long long int back = 0, biceps = 0, chest = 0; n   cin >> n; n   for (int i = 1; i <= (n); ++i) { n     cin >> a; n     if (i % 3 == 0) { n       back += a; n     } else if (i % 3 == 1) { n       chest += a; n     } else if (i % 3 == 2) { n       biceps += a; n     } n   } n   long long int maxi = max(back, max(biceps, chest)); n   if (maxi == back) n     cout <<  back ; n   else if (maxi == biceps) n     cout <<  biceps ; n   else if (maxi == chest) n     cout <<  chest ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 998244353; n const int N = 100005; n int n, x, y, a, b, jc[N], ans; n char s[2]; n int ksm(int a, int k) { n   int ret = 1; n   while (k) { n     if (k & 1) ret = 1ll * ret * a % mod; n     a = 1ll * a * a % mod; n     k >>= 1; n   } n   return ret; n } n int C(int n, int m) { n   return 1ll * jc[n] * ksm(1ll * jc[n - m] * jc[m] % mod, mod - 2) % mod; n } n int main() { n   scanf( %d , &n); n   jc[0] = 1; n   int res = 1, fl1 = 1, fl2 = 1; n   for (int i = 1; i < N; ++i) jc[i] = 1ll * jc[i - 1] * i % mod; n   for (int i = 1; i <= n; ++i) { n     scanf( %s , s); n     if (s[0] ==  W ) ++x; n     if (s[0] ==  ? ) ++y; n     if (s[1] ==  B ) ++a; n     if (s[1] ==  ? ) ++b; n     if (s[0] ==  ?  && s[1] ==  ? ) n       res = (res * 2) % mod; n     else if (s[0] == s[1]) n       res = 0; n     if (s[0] ==  W  || s[1] ==  B ) fl1 = 0; n     if (s[1] ==  W  || s[0] ==  B ) fl2 = 0; n   } n   res -= fl1; n   res -= fl2; n   for (int i = max(a, x); i <= min(x + y, a + b); ++i) n     (ans += 1ll * C(y, i - x) * C(b, i - a) % mod) %= mod; n   printf( %d , ans - res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long mo(long long a) { return a % (long long)(1e9 + 7); } n long long po(long long x, long long y, long long p) { n   long long res = 1; n   x = x % p; n   while (y > 0) { n     if (y & 1) res = (res * x) % p; n     y >>= 1; n     x = (x * x) % p; n   } n   return res % p; n } n vector<vector<pair<long long, long long>>> g; n vector<long long> vis, col; n vector<vector<long long>> ty; n void dfs(long long par, long long anc = -1, long long type = -1) { n   if (anc == -1) { n     col[par] = 0; n     ty[col[par]].push_back(par); n   } else { n     if (type) { n       col[par] = !col[anc]; n       ty[col[par]].push_back(par); n     } else { n       col[par] = col[anc]; n       ty[col[par]].push_back(par); n     } n   } n   vis[par] = 1; n   for (pair<long long, long long> e : g[par]) { n     if (!vis[e.first]) { n       dfs(e.first, par, e.second); n     } n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long t; n   cin >> t; n   while (t--) { n     long long n; n     cin >> n; n     vector<vector<long long>> r(n, vector<long long>(2, -1)), n         c(n, vector<long long>(2, -1)); n     for (long long i = 0; i < 2; i++) { n       for (long long j = 0; j < n; j++) { n         long long x; n         cin >> x; n         x--; n         if (r[x][0] == -1) n           r[x][0] = i; n         else n           r[x][1] = i; n         if (c[x][0] == -1) n           c[x][0] = j; n         else n           c[x][1] = j; n       } n     } n     long long pos = 1; n     for (long long i = 0; i < n; i++) { n       if (r[i][0] == -1 || r[i][1] == -1) pos = 0; n     } n     if (!pos) { n       cout << -1 <<   n ; n       continue; n     } n     g.assign(n, {}); n     vis.assign(n, 0); n     col.assign(n, -1); n     ty.assign(2, {}); n     for (long long i = 0; i < n; i++) { n       if (r[i][0] == r[i][1] && c[i][0] != c[i][1]) { n         g[c[i][0]].push_back({c[i][1], 1}); n         g[c[i][1]].push_back({c[i][0], 1}); n       } n       if (r[i][0] != r[i][1] && c[i][0] != c[i][1]) { n         g[c[i][1]].push_back({c[i][0], 0}); n         g[c[i][0]].push_back({c[i][1], 0}); n       } n     } n     vector<long long> ans; n     for (long long i = 0; i < n; i++) { n       if (!vis[i]) { n         ty[0].clear(); n         ty[1].clear(); n         dfs(i); n         if (ty[0].size() > ty[1].size()) swap(ty[0], ty[1]); n         for (long long e : ty[0]) ans.push_back(e); n       } n     } n     cout << ans.size() <<   n ; n     for (long long e : ans) cout << e + 1 <<    ; n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, a, b, max_dollars, min_tokens, n_tokens; n   string raw_input; n   cin >> n >> a >> b; n   vector<string> tokens(n); n   for (int i = 0; i < n; i++) cin >> tokens[i]; n   for (int i = 0; i < n; i++) { n     n_tokens = stoll(tokens[i]); n     max_dollars = n_tokens * a / b; n     if (stoll(tokens[i]) * a % b != 0) { n       min_tokens = ceil((max_dollars * 1.0) * b / a); n       cout << n_tokens - min_tokens <<    ; n     } else { n       cout << 0 <<    ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long int t, x, y, a, b; n   cin >> t; n   while (t--) { n     cin >> x >> y >> a >> b; n     if (2 * a < b) n       cout << a * (x + y) <<   n ; n     else n       cout << b * min(x, y) + a * abs(x - y) <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int tc; n   cin >> tc; n   while (tc--) { n     int n; n     cin >> n; n     string s; n     cin >> s; n     if (n == 2) { n       if (s[0] >= s[1]) { n         cout <<  NO  n              <<   n ; n       } else { n         cout <<  YES  n              <<   n ; n         cout <<  2  n              <<   n ; n         cout << s[0] <<     << s[1] <<   n ; n       } n     } else { n       cout <<  YES  n            <<   n ; n       cout <<  2  n            <<   n ; n       cout << s[0] <<    ; n       for (int i = 1; i < n; i++) { n         cout << s[i]; n       } n       cout << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const int mod = 1e9 + 7; n const int maxn = 1000000 + 5; n const double PI = acos(-1.0); n const double E = 2.718281828459; n const double eps = 1e-7; n int T, n, num[100005]; n int main() { n   long k, n = 19, x = 0, m; n   scanf( %ld , &k); n   while (k - 1 > 0) { n     x = 0; n     n++; n     m = n; n     while (m > 0) { n       x += m % 10; n       m /= 10; n     } n     if (x == 10) { n       k--; n     } n   } n   printf( %ld n , n); n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> solve(int n) { n   vector<int> v(n, 1); n   if (n == 1) return v; n   if (n == 2) { n     v[0] = 3, v[1] = 4; n     return v; n   } n   int k = n - 1; n   if (k & 1) { n     int p = k >> 1; n     v[n - 1] = p; n   } else { n     k = k - 1 + 4; n     int p = k >> 1; n     v[n - 2] = 2, v[n - 1] = p; n   } n   return v; n } n int main() { n   int n, m; n   while (cin >> n >> m) { n     vector<int> v1 = solve(n), v2 = solve(m); n     for (int i = 0; i < n; i++) n       for (int j = 0; j < m; j++) n         printf( %d%c , v1[i] * v2[j], j + 1 == m ? 10 : 32); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, n, d, x, y; n   vector<pair<int, int> > v; n   cin >> n >> d >> a >> b; n   for (int i = 0; i < n; i++) { n     cin >> x >> y; n     v.push_back({x * a + y * b, i}); n   } n   sort(v.begin(), v.end()); n   long long sum = 0, in = 0; n   for (int i = 0; i < n; i++) { n     if (sum + v[i].first > d) break; n     sum += v[i].first; n     in++; n   } n   cout << in << endl; n   for (int i = 0; i < in - 1; i++) cout << v[i].second + 1 <<    ; n   if (in > 0) cout << v[in - 1].second + 1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int hy, ay, dy; n int hm, am, dm; n int h, a, d; n bool firstok = true; n bool ok(int H, int A, int D) { n   int d1 = max(0, A - dm); n   int d2 = max(0, am - D); n   if (d1 == 0 && d2 == 0) return false; n   if (d2 == 0) return true; n   if (d1 == 0) return false; n   int r1 = (int)ceil(double(hm) / d1); n   if (H % d2 == 0 && r1 < H / d2) n     return true; n   else if (H % d2 != 0 && r1 <= H / d2) n     return true; n   return false; n } n int main() { n   cin >> hy >> ay >> dy; n   cin >> hm >> am >> dm; n   cin >> h >> a >> d; n   int minm = 100000000; n   for (__typeof(200) i = 0; i < (200); ++i) n     for (__typeof(200) j = 0; j < (200); ++j) { n       int A = ay + i; n       int D = dy + j; n       int k1 = max(0, A - dm); n       int k2 = max(0, am - D); n       if (k1 == 0) continue; n       if (k2 == 0) { n         minm = min(minm, i * a + j * d); n         continue; n       } n       int t = (int)ceil((double)hm / k1); n       int k = t * k2 - hy + 1; n       k = max(0, k); n       minm = min(minm, i * a + j * d + k * h); n     } n   cout << minm << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int a[n * 2], b[n * 2]; n   for (int i = 0; i < (n); ++i) { n     cin >> a[i] >> b[i]; n     a[i + n] = a[i]; n     b[i + n] = b[i]; n   } n   int flag = 1; n   if (n % 2 == 1) flag = 0; n   for (int i = 0; i < (n); ++i) { n     int x = a[i + 1] - a[i]; n     int y = b[i + 1] - b[i]; n     if (a[i + n / 2 + 1] - a[i + n / 2] != -x) flag = 0; n     if (b[i + n / 2 + 1] - b[i + n / 2] != -y) flag = 0; n   } n   if (flag) { n     puts( YES ); n   } else { n     puts( NO ); n   }; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long t, n; n   cin >> n; n   if (n == 0) n     cout << 1 << endl; n   else if (n % 4 == 1) n     cout << 8 << endl; n   else if (n % 4 == 2) n     cout << 4 << endl; n   else if (n % 4 == 3) n     cout << 2 << endl; n   else n     cout << 6 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int LIS(vector<int> A) { n   int N = A.size(), i; n   multiset<int> s; n   multiset<int>::iterator k; n   for (i = 0; i < N; i++) { n     s.insert(A[i]); n     if (1) { n       k = s.find(A[i]); n       k++; n       if (k != s.end()) s.erase(k); n     } n   } n   return s.size(); n } n int main() { n   int n; n   cin >> n; n   string s; n   cin >> s; n   for (int i = 1; i < n; i++) { n     for (int j = 0; j + 4 * i < n; j++) { n       if (s[j] !=  * ) continue; n       if (s[j + i] == s[j] && s[j + 2 * i] == s[j] && s[j + 3 * i] == s[j] && n           s[j + 4 * i] == s[j]) { n         cout <<  yes ; n         return 0; n       } n     } n   } n   cout <<  no ; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int maxx = 1e5 + 20; n long long a[maxx]; n int main() { n   int n, i; n   cin >> n; n   for (i = 0; i < n; i++) cin >> a[i]; n   sort(a, a + n); n   int r; n   while (a[0] % 2 == 0) a[0] /= 2; n   while (a[0] % 3 == 0) a[0] /= 3; n   r = a[0]; n   for (i = 1; i < n; i++) { n     while (a[i] % 2 == 0) a[i] /= 2; n     while (a[i] % 3 == 0) a[i] /= 3; n     if (a[i] != r) { n       cout <<  No ; n       return 0; n     } n   } n   cout <<  Yes ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct CC { n   long long x1, x2, y1, y2; n }; n CC jiao(CC a, CC b) { n   CC c1; n   c1.x1 = max(a.x1, b.x1); n   c1.y1 = max(a.y1, b.y1); n   c1.x2 = min(a.x2, b.x2); n   c1.y2 = min(a.y2, b.y2); n   return c1; n } n int main() { n   CC w, b1, b2; n   cin >> w.x1 >> w.y1 >> w.x2 >> w.y2 >> b1.x1 >> b1.y1 >> b1.x2 >> b1.y2 >> n       b2.x1 >> b2.y1 >> b2.x2 >> b2.y2; n   CC j1 = jiao(w, b1); n   CC j2 = jiao(w, b2); n   CC j3 = jiao(j1, j2); n   long long s, s1, s2, s3; n   s = (w.x2 - w.x1) * (w.y2 - w.y1); n   if (j1.x1 > j1.x2 || j1.y1 > j1.y2) n     s1 = 0; n   else n     s1 = (j1.x2 - j1.x1) * (j1.y2 - j1.y1); n   if (j2.x1 > j2.x2 || j2.y1 > j2.y2) n     s2 = 0; n   else n     s2 = (j2.x2 - j2.x1) * (j2.y2 - j2.y1); n   if (j3.x1 > j3.x2 || j3.y1 > j3.y2) n     s3 = 0; n   else n     s3 = (j3.x2 - j3.x1) * (j3.y2 - j3.y1); n   if (s1 + s2 - s3 == s) n     cout <<  NO  << endl; n   else n     cout <<  YES  << endl; n   return 0; n } n


#include <bits/stdc++.h> n const int Inf = 2e9; n long long LINF = (long long)4e18; n using namespace std; n int r1, r2, c1, c2, d1, d2; n bool ok(int i, int j, int k, int l) { n   if (i + j != r1) return false; n   if (k + l != r2) return false; n   if (i + k != c1) return false; n   if (j + l != c2) return false; n   if (i + l != d1) return false; n   if (j + k != d2) return false; n   return true; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2; n   for (int i = 1; i <= 9; i++) { n     for (int j = 1; j <= 9; j++) { n       for (int k = 1; k <= 9; k++) { n         for (int l = 1; l <= 9; l++) { n           if (i == j) continue; n           if (i == k) continue; n           if (i == l) continue; n           if (j == k) continue; n           if (j == l) continue; n           if (k == l) continue; n           if (!ok(i, j, k, l)) continue; n           cout << i <<     << j <<   n ; n           cout << k <<     << l <<   n ; n           return 0; n         } n       } n     } n   } n   cout << -1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int Maxn = 22; n int n; n int col[Maxn]; n int main() { n   scanf( %d , &n); n   int cur = 0; n   for (int a = 0; cur < n; a++) { n     bool good = true; n     for (int i = 0; i < cur && good; i++) n       for (int j = i + 1; j < cur && good; j++) n         for (int l = 0; l < cur && good; l++) n           if (i != l && j != l) good = a != col[i] + col[j] - col[l]; n     if (good) col[cur++] = a; n   } n   for (int i = 0; i < n; i++) n     for (int j = 0; j < n; j++) n       printf( %d%c , i == j ? 0 : col[i] + col[j], j + 1 < n ?     :   n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long t, n, k, z, x, s, a[31], v[31][101], c[31]; n int main() { n   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   ; n   cin >> t; n   for (int zxc = 1; zxc <= t; zxc++) { n     cin >> n >> k; n     for (int i = 1; i <= 30; i++) n       for (int j = 1; j <= 100; j++) v[i][j] = 0; n     for (int i = 1; i <= n; i++) cin >> a[i]; n     for (int i = 1; i <= n; i++) { n       long long z = a[i]; n       long long x = 0; n       while (z != 0) { n         x++; n         v[i][x] = z % k; n         z /= k; n       } n     } n     int ff = 0; n     for (int i = 1; i <= n; i++) { n       for (int j = 1; j <= 100; j++) { n         if (v[i][j] > 1) { n           ff = 1; n           break; n         } n       } n       if (ff == 1) break; n     } n     if (ff == 1) n       cout <<  NO  n            <<   n ; n     else { n       for (int j = 1; j <= 100; j++) { n         long long x = 0; n         for (int i = 1; i <= n; i++) n           if (v[i][j] == 1) x++; n         if (x > 1) { n           ff = 1; n           break; n         } n       } n       if (ff == 1) n         cout <<  NO  n              <<   n ; n       else n         cout <<  YES  n              <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int get(int xt) { n   int ans = 0; n   for (int i = 0; i < 8; i++) { n     ans *= 2; n     ans += xt % 2; n     xt /= 2; n   } n   return ans; n } n int main() { n   char a[110] =   ; n   gets(a); n   int len = strlen(a); n   int xt = 0; n   for (int i = 0; i < len; i++) { n     int tmp = a[i]; n     tmp = get(tmp); n     if (i != len) n       cout << (xt - tmp + 256) % 256 << endl; n     else n       cout << (xt - tmp + 256) % 256; n     xt = tmp; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5e3 + 7; n int dp[N][N]; n int cnt[N * N]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n; n   cin >> n; n   int a[n]; n   memset(dp, 0, sizeof(dp)); n   memset(cnt, 0, sizeof(cnt)); n   for (int i = 0; i < n; i++) cin >> a[i]; n   int ini = 0; n   for (int i = 1; i < n; i++) { n     for (int j = 0; j < n; j++) dp[i][j] = dp[i - 1][j]; n     for (int j = 0; j < n; j++) { n       if (a[i] > j) dp[i][j]++; n     } n     for (int j = 0; j < i; j++) { n       if (a[j] > a[i]) ini++; n     } n   } n   for (int i = 0; i < n; i++) { n     for (int j = i + 1; j < n; j++) { n       int val = dp[i][a[i]] + dp[j][a[j]] - dp[i][a[j]] - dp[j][a[i]]; n       val = ini - 2 * val - 1; n       cnt[val]++; n     } n   } n   for (int i = 0; i < N * N; i++) { n     if (cnt[i]) { n       cout << i <<     << cnt[i] << endl; n       break; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int query(vector<int>& v) { n   cout <<  ?  ; n   for (auto& x : v) { n     cout << x <<    ; n   } n   cout << endl; n   int a; n   cin >> a; n   return a; n } n void solve(int n) { n   int x = 1; n   vector<int> v(n, 1); n   for (int i = n; i >= 2; i--) { n     for (int j = 0; j < n - 1; j++) { n       v[j] = i; n     } n     int a = query(v); n     if (a == 0) continue; n     x = i; n     break; n   } n   vector<int> ans(n, -1); n   ans[n - 1] = x; n   for (int i = 0; i < n; i++) { n     v[i] = x; n   } n   for (int i = 1; i <= n; i++) { n     if (i == x) continue; n     v[n - 1] = i; n     int index = query(v); n     ans[index - 1] = i; n   } n   cout <<  !  ; n   for (auto& y : ans) { n     cout << y <<    ; n   } n   cout << endl; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long t = 1; n   while (t--) { n     int n; n     cin >> n; n     solve(n); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1010; n int n, m, maxw, tot, w[maxn], b[maxn], fa[maxn], sumw[maxn], sumb[maxn], n     dp[maxn << 1][maxn], f[maxn]; n vector<int> child[maxn]; n vector<pair<int, int> > vec; n unordered_set<int> ancestor; n void init() { n   for (int i = 1; i <= n; i++) { n     fa[i] = i; n     sumw[i] = w[i]; n     sumb[i] = b[i]; n   } n } n int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); } n void unite(int x, int y) { n   x = find(x), y = find(y); n   if (x == y) return; n   fa[x] = y; n   sumw[y] += sumw[x]; n   sumb[y] += sumb[x]; n } n int main() { n   scanf( %d %d %d , &n, &m, &maxw); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &w[i]); n   } n   for (int i = 1; i <= n; i++) { n     scanf( %d , &b[i]); n   } n   init(); n   while (m--) { n     int x, y; n     scanf( %d %d , &x, &y); n     unite(x, y); n   } n   for (int i = 1; i <= n; i++) { n     child[find(i)].push_back(i); n     ancestor.insert(find(i)); n   } n   for (int x : ancestor) { n     int last = tot; n     for (int y : child[x]) { n       tot++; n       for (int z = 0; z <= maxw; z++) { n         dp[tot][z] = f[z]; n         if (z >= w[y]) { n           dp[tot][z] = max(dp[tot][z], f[z - w[y]] + b[y]); n         } n       } n     } n     tot++; n     for (int y = 0; y <= maxw; y++) { n       dp[tot][y] = f[y]; n       if (y >= sumw[x]) { n         dp[tot][y] = max(dp[tot][y], f[y - sumw[x]] + sumb[x]); n       } n     } n     for (int y = last + 1; y <= tot; y++) { n       for (int z = 0; z <= maxw; z++) { n         f[z] = max(f[z], dp[y][z]); n       } n     } n   } n   printf( %d n , *max_element(f, f + maxw + 1)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 5; n long long a[N], n; n int to_sorted[N]; n int to_nature[N]; n bool done(int i, int d) { n   bool lef = (i == 0 || a[i - 1] < a[i] - d); n   bool rig = (i == n - 1 || a[i] + d < a[i + 1]); n   return lef && rig; n } n int front(int, int); n int back(int, int); n int front(int i, int d) { n   if (done(i, d)) { n     return i; n   } n   int id = upper_bound(a, a + n, a[i] + d) - a - 1; n   long long rot = 2 * abs(a[i] - a[id]); n   bool safe = (i == 0 || a[i - 1] < a[i] - (d - rot)); n   if (safe && d >= rot) { n     return front(i, d % rot); n   } n   return back(id, d - abs(a[i] - a[id])); n } n int back(int i, int d) { n   if (done(i, d)) { n     return i; n   } n   int id = lower_bound(a, a + n, a[i] - d) - a; n   long long rot = 2 * abs(a[i] - a[id]); n   bool safe = (i == n - 1 || a[i] + d - rot < a[i + 1]); n   if (safe && d >= rot) { n     return back(i, d % rot); n   } n   return front(id, d - abs(a[i] - a[id])); n } n int main() { n   int m; n   scanf( %d %d , &n, &m); n   vector<pair<int, int>> p; n   for (int i = 0; i < n; i++) { n     scanf( %I64d , a + i); n     p.emplace_back(a[i], i); n   } n   sort(a, a + n); n   sort(p.begin(), p.end()); n   for (int i = 0; i < n; i++) { n     to_sorted[p[i].second] = i; n     to_nature[i] = p[i].second; n   } n   while (m--) { n     int id, l; n     scanf( %d %d , &id, &l); n     id = to_sorted[id - 1]; n     printf( %d n , to_nature[front(id, l)] + 1); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, viz[100005], cnt, nr, x[100005], nrans, ans[400005], rad; n vector<int> v[100005]; n void dfs1(int nod) { n   viz[nod] = 1; n   nr += x[nod]; n   for (auto x : v[nod]) n     if (!viz[x]) dfs1(x); n } n void dfs(int nod, int tata) { n   viz[nod] = 1; n   nrans++; n   ans[nrans] = nod; n   x[nod] = 1 - x[nod]; n   for (auto xx : v[nod]) n     if (!viz[xx]) { n       dfs(xx, nod); n       nrans++; n       ans[nrans] = nod; n       x[nod] = 1 - x[nod]; n     } n   if ((x[nod] % 2) && (nod != rad)) { n     nrans++; n     ans[nrans] = tata; n     nrans++; n     ans[nrans] = nod; n     x[nod] = 1 - x[nod]; n     x[tata] = 1 - x[tata]; n   } n } n int main() { n   int i, xx, y; n   cin >> n >> m; n   for (i = 1; i <= m; i++) { n     cin >> xx >> y; n     v[xx].push_back(y); n     v[y].push_back(xx); n   } n   for (i = 1; i <= n; i++) cin >> x[i]; n   for (i = 1; i <= n; i++) n     if (!viz[i]) { n       nr = 0; n       dfs1(i); n       if (nr % 2) cnt++; n       if (cnt > 1) { n         cout << -1; n         return 0; n       } n     } n   for (i = 1; i <= n; i++) viz[i] = 0; n   for (i = 1; i <= n; i++) n     if (x[i] % 2) { n       rad = i; n       break; n     } n   if (!rad) rad = 1; n   dfs(rad, 0); n   if (x[rad] % 2) nrans--; n   cout << nrans <<   n ; n   for (i = 1; i <= nrans; i++) cout << ans[i] <<    ; n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n void __print(int x) { cerr << x; } n void __print(long x) { cerr << x; } n void __print(long long x) { cerr << x; } n void __print(unsigned x) { cerr << x; } n void __print(unsigned long x) { cerr << x; } n void __print(unsigned long long x) { cerr << x; } n void __print(float x) { cerr << x; } n void __print(double x) { cerr << x; } n void __print(long double x) { cerr << x; } n void __print(char x) { cerr <<      << x <<     ; } n void __print(const char *x) { cerr <<     << x <<    ; } n void __print(const string &x) { cerr <<     << x <<    ; } n void __print(bool x) { cerr << (x ?  true  :  false ); } n template <typename T, typename V> n void __print(const pair<T, V> &x) { n   cerr <<  { ; n   __print(x.first); n   cerr <<  , ; n   __print(x.second); n   cerr <<  } ; n } n template <typename T> n void __print(const T &x) { n   int f = 0; n   cerr <<  { ; n   for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i); n   cerr <<  } ; n } n void _print() { cerr <<  ] n ; } n template <typename T, typename... V> n void _print(T t, V... v) { n   __print(t); n   if (sizeof...(v)) cerr <<  ,  ; n   _print(v...); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int t = 1; n   while (t--) { n     long long int n = 0, m = 0, k = 0, i = 0, j = 0, p = 0, q = 0, x = 0, y = 0, n                   z = 0, ans = 0, cnt = 0, l = 0, r = 0, mid = 0, lo = 0, n                   hi = 0; n     string s; n     bool flag = false; n     cin >> n; n     long long int a[n + 1]; n     for (i = 1; i <= n; i++) cin >> a[i]; n     long long int dp[n + 1][n + 1][2]; n     long long int even = n / 2; n     long long int odd = (n % 2 == 0) ? n / 2 : (n / 2) + 1; n     for (i = 0; i <= n; i++) n       for (j = 0; j <= n; j++) n         for (k = 0; k < 2; k++) dp[i][j][k] = 1000000007; n     dp[0][0][0] = 0; n     dp[0][0][1] = 0; n     for (i = 1; i <= n; i++) n       if (a[i] == 0) n         for (j = 0; j <= even; j++) n           if (j > i || (i - j) > odd) n             continue; n           else n             dp[i][j][0] = min(dp[i][j][0], dp[i - 1][j - 1][0]), n             dp[i][j][0] = min(dp[i][j][0], dp[i - 1][j - 1][1] + 1), n             dp[i][j][1] = min(dp[i][j][1], dp[i - 1][j][1]), n             dp[i][j][1] = min(dp[i][j][1], dp[i - 1][j][0] + 1); n       else n         for (j = 0; j <= even; j++) { n           if (j > i || (i - j) > odd) continue; n           if (a[i] % 2 == 0) n             dp[i][j][0] = min(dp[i][j][0], dp[i - 1][j - 1][0]), n             dp[i][j][0] = min(dp[i][j][0], dp[i - 1][j - 1][1] + 1); n           else n             dp[i][j][1] = min(dp[i][j][1], dp[i - 1][j][1]), n             dp[i][j][1] = min(dp[i][j][1], dp[i - 1][j][0] + 1); n         } n     ans = 1000000007; n     for (j = 0; j <= even; j++) n       ans = min(ans, dp[n][j][0]), ans = min(ans, dp[n][j][1]); n     cout << ans << endl; n     ; n   } n   return 0; n } n


#include <bits/stdc++.h> n int t, s, x; n int main() { n   scanf( %d%d%d , &t, &s, &x); n   if (x == t) { n     printf( YES n ); n     return 0; n   } n   for (int i = 1; i * s + t <= x; i++) n     if (i * s + t == x || i * s + t + 1 == x) { n       printf( YES n ); n       return 0; n     } n   printf( NO n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxN = 3042, mod = 1000000007; n const int modHash = 2013023017; n inline void add_mod(long long& a, long long b) { a = (a + b) % mod; } n inline void mult_mod(long long& a, long long b) { a = a * b % mod; } n long long dp[maxN][maxN], pref[maxN]; n unordered_set<long long> S[maxN]; n bool fld[42]; n int in[maxN]; n int main() { n   fld[12] = fld[10] = fld[7] = fld[15] = true; n   int n; n   scanf( %d , &n); n   for (int i = 1; i < (n + 1); i++) scanf( %d , in + i); n   for (int i = 1; i < (n + 1); i++) { n     int mask = 0; n     long long H[10]; n     H[3] = H[5] = 0; n     dp[i][i - 1] = 1; n     for (int j = i; j < (n + 1); j++) { n       H[3] = (H[3] * 3 + in[j] + 1) % modHash; n       H[5] = (H[5] * 5 + in[j] + 1) % modHash; n       mask >>= 1; n       mask |= in[j] << 3; n       int len = j - i + 1; n       dp[i][j] = (len >= 4 and !fld[mask]) ? dp[i][j - 4] : 0; n       for (int k = 1; k < (min(4, len + 1)); k++) dp[i][j] += dp[i][j - k]; n       dp[i][j] %= mod; n       long long M = H[3] << 32 | H[5]; n       if ((S[len].insert(M)).second) pref[j] += dp[i][j]; n     } n   } n   long long sum = 0; n   for (int i = 1; i < (n + 1); i++) { n     add_mod(sum, pref[i]); n     printf( %lld n , sum); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   cin >> n >> k; n   char ch[n + 1]; n   cin >> ch; n   int ar[200] = {0}; n   for (int i = 0; i < strlen(ch); i++) { n     ar[ch[i]]++; n   } n   sort(ar, ar + 200); n   if (ar[199] > k) n     cout <<  NO  << endl; n   else n     cout <<  YES  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MX = 300000; n int arr[MX], state[MX], n, m, meet[MX], cur, is[MX], lastoff[MX]; n int pres[MX]; n pair<int, int> last; n vector<pair<int, int> > v[MX]; n vector<int> ans; n char cc; n int main() { n   memset(meet, -1, sizeof(meet)); n   memset(is, 0, sizeof(is)); n   scanf( %d %d , &n, &m); n   for (int j = 1; j <= m; j++) { n     cin >> cc >> arr[j]; n     if (cc ==  + ) n       state[j] = 1; n     else n       state[j] = 0; n     if (meet[arr[j]] == -1) meet[arr[j]] = state[j]; n     v[arr[j]].push_back(make_pair(j, state[j])); n   } n   for (int j = 1; j <= n; j++) { n     lastoff[j] = m * 10; n     if (meet[j] == -1) ans.push_back(j); n     if (meet[j] == 0) { n       cur++; n       is[j] = 1; n     } n   } n   if (state[1] == 1 && cur == 0) is[arr[1]] = 1; n   for (int j = 1; j <= m; j++) { n     if (state[j] == 0) n       cur--; n     else n       cur++; n     pres[j] = cur; n   } n   for (int j = 1; j <= m; j++) { n     if (!is[arr[j]]) continue; n     if (state[j] == 0) { n       if (pres[j] > 0) { n         is[arr[j]] = 0; n       } n       lastoff[arr[j]] = j; n     } n   } n   int ret; n   for (int j = 1; j <= n; j++) { n     if (!is[j]) continue; n     ret = 1; n     int szo = v[j].size(); n     for (int i = 0; i < szo; i++) { n       if (v[j][i].second == 1 && i) { n         if (v[j][i].first != v[j][i - 1].first + 1) ret = 0; n       } n       last = v[j][i]; n     } n     if (last.second == 0 && last.first < m) ret = 0; n     is[j] &= ret; n     if (is[j]) ans.push_back(j); n   } n   sort(ans.begin(), ans.end()); n   cout << ans.size() << endl; n   for (int j = 0; j < ans.size(); j++) printf( %d  , ans[j]); n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e5 + 50; n const int maxn = 1e7 + 50; n const int inf = 0x3f3f3f3f; n unordered_map<int, bool> mp; n vector<int> vec; n int main() { n   int T; n   scanf( %d , &T); n   while (T--) { n     mp.clear(); n     vec.clear(); n     int n, t; n     scanf( %d , &n); n     vec.push_back(0); n     for (int i = 1; i * i <= n; i++) { n       t = n / i; n       if (!mp.count(t)) { n         mp[t] = 1; n         vec.push_back(t); n         if (n / t == i) { n           if (!mp.count(i)) { n             mp[i] = 1; n             vec.push_back(i); n           } n         } n       } n     } n     sort(vec.begin(), vec.end()); n     printf( %d n , vec.size()); n     for (int i = 0; i < vec.size(); i++) printf( %d  , vec[i]); n     putchar(10); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   double ans, B, H; n   cin >> ans; n   double ff = 999999999.9; n   for (double h = 1; h <= 10; h++) { n     for (double b = 1; b <= 10; b++) { n       double sum = h * b / sqrt(4 * h * h + b * b); n       double d = fabs(ans - sum); n       if (d < ff) { n         ff = d; n         B = b; n         H = h; n       } n     } n   } n   cout << B <<     << H << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long l, r; n   cin >> l >> r; n   long long x = r, y = 0; n   while (x > 0) { n     ++y; n     x /= 10; n   } n   x = 5; n   long long k = y; n   for (int i = 0; i < k - 1; ++i) { n     x *= 10; n   } n   if (r < x) n     x = r; n   else if (l > x) n     x = l; n   k = x; n   vector<long long> ans; n   while (k > 0) { n     ans.push_back(k % 10); n     k /= 10; n   } n   reverse(ans.begin(), ans.end()); n   y = 0; n   for (auto& i : ans) { n     y *= 10; n     y += 9 - i; n   } n   cout << x * y; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n typedef struct { n   int y, i; n   double p; n } ele; n int cmp(ele a, ele b) { return a.y > b.y || (a.y == b.y && a.i > b.i); } n vector<ele> pu[100514]; n int a[100514]; n double dp[5140][5140]; n int mp[5140]; n vector<int> e[5140]; n ele sk[5140]; n int top; n void sol() { n   int n, q; n   scanf( %d %d , &n, &q); n   for (int i = 0; i < n; i++) { n     scanf( %d , a + i); n   } n   pu[0].push_back((ele){n - 1, q, 0}); n   for (int i = 0; i < q; i++) { n     int x, y; n     double p; n     scanf( %d %d %lf , &x, &y, &p); n     pu[x - 1].push_back((ele){y - 1, i, p}); n   } n   for (int i = 0; i <= q; i++) mp[i] = -7122; n   top = 0; n   for (int i = 0; i < n; i++) { n     sort(pu[i].begin(), pu[i].end(), cmp); n     for (int j = 0; j < (int)pu[i].size(); j++) { n       sk[top++] = pu[i][j]; n     } n     mp[sk[top - 1].i] = max(mp[sk[top - 1].i], a[i]); n     for (; top && sk[top - 1].y == i; top--) { n       int t = sk[top - 1].i; n       double p = sk[top - 1].p; n       for (int j = 0; j < (int)e[t].size(); j++) { n         mp[t] = max(mp[t], mp[e[t][j]]); n       } n       for (int k = 0; k <= q + 1; k++) { n         dp[t][k] = 1; n         for (int j = 0; j < (int)e[t].size(); j++) { n           int nk = mp[t] + k - mp[e[t][j]]; n           if (q + 1 >= nk) { n             dp[t][k] *= dp[e[t][j]][nk]; n           } n         } n       } n       for (int k = q + 1; k >= 1; k--) { n         dp[t][k] = dp[t][k] * (1 - p) + dp[t][k - 1] * p; n       } n       dp[t][0] = dp[t][0] * (1 - p); n       if (top >= 2) e[sk[top - 2].i].push_back(t); n     } n     pu[i].clear(); n   } n   double ans = mp[q]; n   for (int i = 1; i <= q + 1; i++) { n     ans += (dp[q][i] - dp[q][i - 1]) * i; n   } n   printf( %.10f n , ans); n   for (int i = 0; i <= q; i++) e[i].clear(); n } n int main() { n   while (1) { n     sol(); n     break; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dp[50004][8]; n int main() { n   int m, n; n   cin >> m >> n; n   for (int i = 1; i <= m; i++) { n     for (int j = 1; j <= n; j++) cin >> dp[i][j]; n   } n   for (int i = 1; i <= m; i++) dp[i][1] += dp[i - 1][1]; n   for (int i = 1; i <= n; i++) dp[1][i] += dp[1][i - 1]; n   for (int i = 2; i <= m; i++) { n     for (int j = 2; j <= n; j++) { n       if (dp[i - 1][j] >= dp[i][j - 1]) n         dp[i][j] += dp[i - 1][j]; n       else n         dp[i][j] += dp[i][j - 1]; n     } n   } n   for (int i = 1; i <= m; i++) cout << dp[i][n] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, x, y; n   int p = 1; n   cin >> n; n   cin >> x; n   cin >> y; n   p = n * y; n   if (p % 100 != 0) n     p = p / 100 + 1; n   else n     p = p / 100; n   if (p <= x) n     cout << 0 << endl; n   else n     cout << p - x << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int dx[9] = {0, 1, -1, 0, 0, -1, -1, 1, 1}; n const int dy[9] = {0, 0, 0, -1, 1, -1, 1, -1, 1}; n const double pi = acos(-1.0); n const int N = 1e5 + 100; n long long pre[N], a[N], temp[200], ans = 0; n int n, k, ma = 0; n map<long long, long long> dic; n int main() { n   scanf( %d , &n), scanf( %d , &k); n   long long t = 1; n   temp[0] = 1; n   if (k == 1 || k == -1) { n     if (k == 1) { n       ma = 0; n       temp[0] = 1; n     } else { n       ma = 1; n       temp[0] = 1; n       temp[1] = -1; n     } n   } else { n     while (abs(t * k) < 1e15) { n       ma++; n       t = t * k; n       temp[ma] = t; n     } n   } n   for (int i = 1; i <= n; i++) scanf( %lld , &a[i]); n   for (int i = 0; i <= ma; i++) dic[temp[i] + 0]++; n   for (int i = 1; i <= n; i++) { n     pre[i] = pre[i - 1] + a[i]; n     ans += dic[pre[i]]; n     for (int j = 0; j <= ma; j++) dic[pre[i] + temp[j]]++; n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline void smin(int &a, const int &b) { n   if (b < a) a = b; n } n inline void smax(int &a, const int &b) { n   if (b > a) a = b; n } n int first[4], second[4], f[4], ans; n vector<int> dst, vx, vy; n pair<int, int> p[4], mp[4]; n inline void solve(int X, int Y, int d) { n   p[0] = pair<int, int>(X, Y), p[1] = pair<int, int>(X, Y + d), X += d; n   p[2] = pair<int, int>(X, Y), p[3] = pair<int, int>(X, Y + d); n   for (int i = 4; i--;) f[i] = i; n   do { n     int mx = 0; n     for (int i = 4; i--;) { n       if (first[i] == p[f[i]].first) n         smax(mx, abs(second[i] - p[f[i]].second)); n       else if (second[i] == p[f[i]].second) n         smax(mx, abs(first[i] - p[f[i]].first)); n       else n         mx = 0x3f3f3f3f; n     } n     if (mx < ans) { n       ans = mx; n       for (int i = 4; i--;) mp[i] = p[f[i]]; n     } n   } while (next_permutation(f, f + 4)); n } n inline void solve(int d) { n   vx.clear(), vy.clear(); n   for (int i = 4; i--;) { n     vx.push_back(first[i] - d), vx.push_back(first[i]), n         vx.push_back(first[i] + d); n     vy.push_back(second[i] - d), vy.push_back(second[i]), n         vy.push_back(second[i] + d); n     for (int j = i; j--;) { n       int xmn = min(first[i], first[j]), xmx = max(first[i], first[j]); n       int ymn = min(second[i], second[j]), ymx = max(second[i], second[j]); n       for (int k = 4; k--;) n         if (k != i && k != j) { n           smin(xmn, first[k] - d), smax(xmx, first[k] - d); n           smin(ymn, second[k] - d), smax(ymx, second[k] - d); n         } n       vx.push_back(xmn + xmx >> 1), vy.push_back(ymn + ymx >> 1); n     } n   } n   for (int first : vx) n     for (int second : vy) solve(first, second, d); n } n int main() { n   int t; n   scanf( %d , &t); n   while (t--) { n     dst.clear(); n     for (int i = 0; i < 4; i++) { n       scanf( %d %d , first + i, second + i); n       for (int j = 0; j < i; j++) { n         dst.push_back(abs(first[i] - first[j])); n         dst.push_back(abs(second[i] - second[j])); n       } n     } n     sort(dst.begin(), dst.end()); n     dst.resize(unique(dst.begin(), dst.end()) - dst.begin()); n     ans = 0x3f3f3f3f; n     for (int first : dst) solve(first); n     if (ans < 0x3f3f3f3f) { n       printf( %d n , ans); n       for (int i = 0; i < 4; i++) printf( %d %d n , mp[i].first, mp[i].second); n     } else n       puts( -1 ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n bool isprime(long long int n) { n   if (n <= 1) return false; n   if (n <= 3) return true; n   if (n % 2 == 0 || n % 3 == 0) return false; n   for (int i = 5; i * i <= n; i = i + 6) n     if (n % i == 0 || n % (i + 2) == 0) return false; n   return true; n } n vector<long long int> prime; n void sieve(long long int n) { n   bool bakh[n + 1]; n   memset(bakh, true, sizeof(bakh)); n   for (long long int p = 2; p * p <= n; p++) { n     if (bakh[p] == true) { n       for (long long int i = p * p; i <= n; i += p) bakh[i] = false; n     } n   } n   for (long long int p = 2; p <= n; p++) n     if (bakh[p]) prime.push_back(p); n } n long long int eulertotient(long long int z) { n   long long int fac = z; n   for (long long int i = 0; prime[i] * prime[i] <= z; i++) { n     if (z % prime[i] == 0) { n       fac -= (fac / prime[i]); n       while (z % prime[i] == 0) z /= prime[i]; n     } n   } n   if (z > 1) fac -= (fac / z); n   return fac; n } n long long int power(long long int x, long long int y, long long int p) { n   long long int res = 1; n   x = x % p; n   while (y > 0) { n     if (y & 1) res = (res * x) % p; n     y = y >> 1; n     x = (x * x) % p; n   } n   return res; n } n long long int gcd(long long int a, long long int b) { n   if (a == 0) return b; n   return gcd(b % a, a); n } n long long int lcm(long long int a, long long int b) { n   long long int g = gcd(a, b); n   long long int ans = (a * b) / g; n   return ans; n } n long long int modInverse(long long int a, long long int m) { n   long long int hvf = gcd(a, m); n   if (hvf == 1) return power(a, m - 2, m); n   return -1; n } n void multiply(long long int F[2][2], long long int M[2][2]) { n   long long int x = F[0][0] * M[0][0] + F[0][1] * M[1][0]; n   long long int y = F[0][0] * M[0][1] + F[0][1] * M[1][1]; n   long long int z = F[1][0] * M[0][0] + F[1][1] * M[1][0]; n   long long int w = F[1][0] * M[0][1] + F[1][1] * M[1][1]; n   F[0][0] = x; n   F[0][1] = y; n   F[1][0] = z; n   F[1][1] = w; n } n void powermat(long long int F[2][2], long long int n) { n   if (n == 0 || n == 1) return; n   long long int M[2][2] = {{1, 1}, {1, 0}}; n   powermat(F, n / 2); n   multiply(F, F); n   if (n % 2 != 0) multiply(F, M); n } n long long int fib(long long int n) { n   long long int F[2][2] = {{1, 1}, {1, 0}}; n   if (n == 0) return 0; n   powermat(F, n - 1); n   return F[0][0]; n } n vector<long long int> merge(vector<long long int> v1, n                             vector<long long int> v2) { n   vector<long long int> temp; n   long long int i = 0, j = 0; n   while (i < v1.size() && j < v2.size()) { n     if (v1[i] < v2[j]) n       temp.push_back(v1[i]), i++; n     else n       temp.push_back(v2[j]), j++; n   } n   while (i < v1.size()) temp.push_back(v1[i]), i++; n   while (j < v2.size()) temp.push_back(v2[j]), j++; n   return temp; n } n long long int n, m; n vector<long long int> mark; n vector<long long int> top; n vector<pair<long long int, long long int> > adj[100005]; n void dfs(long long int u) { n   mark[u] = 1; n   for (auto v : adj[u]) { n     if (!mark[v.first]) dfs(v.first); n   } n   top.push_back(u); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   long long int a, b; n   cin >> n >> m; n   for (long long int i = 1; i <= m; i++) n     cin >> a >> b, adj[a].push_back({b, i}); n   mark.clear(); n   mark.resize(n + 1, 0); n   for (long long int i = 1; i <= n; i++) { n     if (!mark[i]) dfs(i); n   } n   bool flag; n   long long int ans = 0; n   for (long long int i = n - 1; i > 0; i--) { n     long long int u = top[i], v = top[i - 1]; n     flag = 0; n     for (auto e : adj[u]) { n       if (e.first == v) { n         ans = max(ans, e.second); n         flag = 1; n         break; n       } n     } n     if (!flag) return cout << -1 << endl, 0; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long int fast_expo(long long int x, long long int p) { n   if (p == 0) n     return 1; n   else if (p % 2 == 0) { n     long long int t = fast_expo(x, p / 2) % 1000000007; n     return (t * t) % 1000000007; n   } else n     return (x * (fast_expo(x, p - 1)) % 1000000007) % 1000000007; n } n int main() { n   int q; n   cin >> q; n   while (q--) { n     int n; n     cin >> n; n     int a[n]; n     int i, c = 1, c1 = 1, ind; n     for (i = 0; i < n; i++) { n       cin >> a[i]; n       if (a[i] == 1) ind = i; n     } n     i = ind; n     while (c != n) { n       if (a[i] == c) { n         c++; n         if (i == n - 1) n           i = 0; n         else n           i++; n       } else n         break; n     } n     i = ind; n     while (c1 != n) { n       if (a[i] == c1) { n         c1++; n         if (i == 0) n           i = n - 1; n         else n           i--; n       } else n         break; n     } n     if (c == n || c1 == n) n       cout <<  YES  << endl; n     else n       cout <<  NO  << endl; n   } n } n