#include <bits/stdc++.h>   using namespace std;   long long int trash = 0;   long long int a[50], c[50];   long long int value2power[50];   long long int n, m;   priority_queue<long long int> mainPQ;   vector<long long int> queueArray;   bool test(priority_queue<long long int> &PQ, long long int *b,             long long int n) {     for (long long int i = n; i >= 1; i--) {       for (long long int j = 1; j <= b[i]; j++) {         if (PQ.empty()) {           return true;         }         long long int top = PQ.top();         PQ.pop();         if (top >= value2power[i + 1]) {           return false;         }       }     }     if (PQ.empty()) {       return true;     } else {       return false;     }   }   bool cutoffRemain(long long int num, long long int n) {     priority_queue<long long int> auxiliaryPQ;     long long int size = queueArray.size();     for (long long int i = 1; i <= size; i++) {       auxiliaryPQ.push(queueArray[i - 1]);     }     for (long long int i = 1; i <= n; i++) {       c[i] = a[i];     }     for (long long int i = 1; i <= n; i++) {       if (c[i] > num) {         for (long long int j = 1; j <= c[i] - num; j++) {           auxiliaryPQ.push(value2power[i]);         }         c[i] = num;       }     }     long long int temp = c[n];     for (long long int i = n; i >= 2; i--) {       c[i] = c[i - 1] - c[i];     }     for (long long int i = 1; i <= n - 1; i++) {       c[i] = c[i + 1];     }     c[n] = temp;     return test(auxiliaryPQ, c, n);   }   int main() {     value2power[1] = 1;     for (long long int i = 2; i <= 49; i++) {       value2power[i] = 2 * value2power[i - 1];     }     long long int temp;     cin >> m;     for (long long int i = 1; i <= m; i++) {       scanf( %lld , &temp);       bool mark = true;       for (long long int j = 1; j <= 49; j++) {         if (temp == value2power[j]) {           a[j]++;           mark = false;           break;         }       }       if (mark) {         queueArray.push_back(temp);         mainPQ.push(temp);       }     }     long long int n = 0;     for (long long int i = 1; i <= 40; i++) {       if (a[i] < a[i + 1]) {         for (long long int j = 1; j <= a[i + 1] - a[i]; j++) {           queueArray.push_back(value2power[i + 1]);           mainPQ.push(value2power[i + 1]);         }         a[i + 1] = a[i];       }     }     for (long long int i = 40; i >= 1; i--) {       if (a[i] != 0) {         n = i;         break;       }     }     if (mainPQ.size() > a[1]) {       cout << -1;     } else {       bool v = cutoffRemain(a[1], n);       if (v == false) {         cout << -1;       } else {         long long int minremain = 0;         long long int maxremain = a[1];         while (minremain < maxremain) {           long long int mid = (minremain + maxremain) / 2;           if (cutoffRemain(mid, n)) {             maxremain = mid;           } else {             minremain = mid + 1;           }         }         for (long long int i = minremain; i <= a[1]; i++) {           printf( %lld  , i);         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e6;   const long long mod = 1e9 + 7;   vector<long long> primes;   bool not_prime[N];   void sieve_of_eratosthenes(long long n) {     for (long long i = 2; i < N; i++) {       if (not_prime[i]) continue;       primes.push_back(i);       for (long long j = 2 * i; j < N; j += i) {         not_prime[j] = 1;       }     }   }   void solve() {     long long n;     cin >> n;     long long ans = upper_bound(primes.begin(), primes.end(), n) - primes.begin();     ans += 1;     long long sq = sqrt(n);     ans -= (upper_bound(primes.begin(), primes.end(), sq) - primes.begin());     cout << ans;   }   int32_t main() {     sieve_of_eratosthenes(1e6);     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t = 1;     cin >> t;     while (t--) {       solve();       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> a[100005], vis(100005, 0), tree[100005], lev[2];   long long n, m, k;   set<long long> v;   stack<long long> st;   void dfs(long long node, long long par) {     vis[node] = 1;     st.push(node);     for (auto i : a[node])       if (!vis[i] and v.find(i) != v.end()) {         tree[node].push_back(i);         tree[i].push_back(node);         dfs(i, node);       } else if (v.find(i) != v.end() and i != par) {         cout << 2 <<   n ;         vector<long long> ans;         while (!st.empty() and st.top() != i) {           ans.push_back(st.top());           st.pop();         }         ans.push_back(i);         cout << (long long)ans.size() <<   n ;         for (auto i : ans) cout << i <<    ;         exit(0);       }     st.pop();   }   void dfs1(long long node, long long par, long long d) {     lev[d].push_back(node);     for (auto i : tree[node])       if (i != par) {         dfs1(i, node, 1 - d);       }   }   void get_subgraph() {     queue<long long> q;     q.push(1);     v.insert(1);     while (!q.empty()) {       auto cur = q.front();       q.pop();       for (auto i : a[cur]) {         if (v.find(i) == v.end()) {           v.insert(i);           q.push(i);           if ((long long)v.size() == k) break;         }       }       if ((long long)v.size() == k) break;     }   }   void solve() {     cin >> n >> m >> k;     for (long long i = 0; i < m; i++) {       long long x, y;       cin >> x >> y;       a[x].push_back(y);       a[y].push_back(x);     }     get_subgraph();     dfs(1, -1);     dfs1(1, -1, 0);     long long req = (k + 1) / 2;     cout << 1 <<   n ;     vector<long long> ans;     if ((long long)lev[0].size() >= req)       ans = lev[0];     else       ans = lev[1];     for (long long i = 0; i < req; i++) cout << ans[i] <<    ;   }   signed main() {     long long TESTS = 1;     while (TESTS--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool comp(pair<unsigned long long, unsigned long long> a,             pair<unsigned long long, unsigned long long> b) {     unsigned long long s1, s2, h1, h2;     tie(s1, h1) = a;     tie(s2, h2) = b;     if (s1 * h2 > s2 * h1) return true;     return false;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     unsigned long long ans = 0;     string str;     vector<pair<unsigned long long, unsigned long long> > arr(n);     for (int i = 0; i < n; i++) {       cin >> str;       unsigned long long s1 = 0, h = 0;       for (auto x : str) {         if (x ==  s )           s1++;         else if (x ==  h )           h++, ans += s1;       }       arr[i] = make_pair(s1, h);     }     sort((arr).begin(), (arr).end(), comp);     unsigned long long s1 = 0;     for (auto i : arr) {       ans += s1 * 1LL * (i.second);       s1 += i.first;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long s[1000], x[1000], size;   void tob(long long a, long long arr[], long long& len) {     len = 0;     while (a != 0) {       arr[len++] = a % 2;       a /= 2;     }   }   long long DP(long long n, long long carry) {     if (n >= size) return 1 - carry;     if (x[n] == 1) {       if (((carry + 1) % 2) == s[n]) {         return 2 * DP(n + 1, carry);       } else         return 0;     } else {       long long ans = 0;       if ((carry) == s[n]) {         ans += DP(n + 1, 0);       }       if (((carry + 2) % 2) == s[n]) {         ans += DP(n + 1, 1);       }       return ans;     }   }   void solve(long long n, long long m) {     long long len1, len2, ans;     tob(n, s, len1);     tob(m, x, len2);     size = max(len1, len2);     ans = DP(0, 0);     if (n == m)       cout << ans - 2 << endl;     else       cout << ans << endl;   }   int main() {     long long n, m;     cin >> n >> m;     solve(n, m);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, d[210000];   long long cnt[210000];   long long solve() {     cnt[1] *= 2;     cnt[n] *= 2;     int Min = cnt[1], Max = cnt[1];     for (int i = 1; i <= n; ++i) {       if (Min > cnt[i])         Min = cnt[i];       else if (Max < cnt[i])         Max = cnt[i];     }     if (Min == Max) {       for (int i = 2; i <= n; ++i)         if (d[i] - d[i - 1] != d[2] - d[1]) return -1;       return cnt[1] * (d[n] - d[1]) - d[2] + d[1];     } else {       long long temp = 0;       for (int i = 1; i < n; ++i) {         temp += (d[i + 1] - d[i]) * min(cnt[i], cnt[i + 1]);       }       return temp;     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , &d[i]);     scanf( %d , &m);     for (int i = 1; i <= m; ++i) {       int temp;       scanf( %d , &temp);       ++cnt[temp];     }     printf( %I64d n , solve());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int main() {     int n, num[105], ans;     scanf( %d , &n);     for (int i = 1; i <= n; i++) cin >> num[i];     sort(num + 1, num + 1 + n);     ans = num[1];     for (int i = 2; i <= n; i++) ans = gcd(ans, num[i]);     printf( %d n , ans * n);   }


#include <bits/stdc++.h>   using namespace std;   int arr[(int)1e5 + 1];   int q[(int)1e5 + 1];   int sol[(int)1e5 + 1];   int main() {     int n, m;     cin >> n;     cin >> arr[0];     for (int i = 1; i < n; i++) {       int x;       cin >> x;       arr[i] = arr[i - 1] + x;     }     cin >> m;     for (int i = 0; i < m; i++) {       cin >> q[i];     }     for (int i = 0; i < m; i++) {       int lo = 0, hi = n - 1, res = -1;       while (lo <= hi) {         int md = (hi + lo) >> 1;         if (arr[md] >= q[i] && q[i] >= arr[md - 1]) {           hi = md - 1;           res = md;         } else if (arr[md] >= q[i])           hi = md - 1;         else           lo = md + 1;       }       sol[i] = res + 1;     }     for (int i = 0; i < m; i++) {       cout << sol[i] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int m, n, j, k, l, i, o, p, __t;   int V[200][2000], tim[200][2000], T[200], cop[200][2000];   char ch;   void read(int &a) {     for (ch = getchar(); (ch <  0  || ch >  9 ) && (ch !=  - ); ch = getchar())       ;     if (ch ==  - )       a = 0, __t = -1;     else       a = ch -  0 , __t = 1;     for (ch = getchar(); ch >=  0  && ch <=  9 ; ch = getchar())       a = a * 10 + ch -  0 ;     a *= __t;   }   int main() {     read(m), read(n);     for (int i = 1; i <= m; i++) {       read(T[i]);       for (int j = 1; j <= T[i]; j++)         read(V[i][j]), read(tim[i][j]), cop[i][j] = tim[i][j];     }     int ans = 0;     for (int i = 1; i <= m; i++) {       for (int j = i + 1; j <= m; j++) {         for (int k = 1; k <= T[i]; k++) tim[i][k] = cop[i][k];         for (int k = 1; k <= T[j]; k++) tim[j][k] = cop[j][k];         int x0 = 0, x1 = 0, who = 0;         if (V[i][1] > V[j][1])           who = -1;         else           who = 1;         for (int t1 = 1, t2 = 1; t1 <= T[i] && t2 <= T[j];) {           int dece = min(tim[i][t1], tim[j][t2]);           int y0 = x0 + dece * V[i][t1];           int y1 = x1 + dece * V[j][t2], nexwho;           if (y0 == y1)             nexwho = who;           else if (y0 < y1)             nexwho = 1;           else             nexwho = -1;           if (nexwho != who) ans++;           who = nexwho;           x0 = y0, x1 = y1;           tim[i][t1] -= dece;           tim[j][t2] -= dece;           if (tim[i][t1] == 0) t1++;           if (tim[j][t2] == 0) t2++;         }       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, t, cur;   void solve() {     scanf( %d %d , &n, &k);     t = n - k;     for (int i = 1; i <= t; i++) printf( %d  , i);     for (int i = k, j = 1; i >= 1; i--, j *= -1) {       t += i * j;       printf( %d  , t);     }   }   int main(void) {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ans, n;   vector<pair<int, int> > vec;   string s, t;   int lcp1[5005][5005];   int lcp2[5005][5005];   void LCP(string &s, string &t, int lcp[5005][5005]) {     for (int i = (int)s.size() - 1; i >= 0; i--) {       for (int j = (int)t.size() - 1; j >= 0; j--) {         if (s[i] == t[j]) {           lcp[i][j] = lcp[i + 1][j + 1] + 1;         } else {           lcp[i][j] = 0;         }       }     }   }   void solve() {     LCP(s, t, lcp1);     reverse(s.begin(), s.end());     LCP(s, t, lcp2);     for (int ti = 0; ti < t.size();) {       int mx1 = 0, mx1_si = -1;       int mx2 = 0, mx2_si = -1;       for (int si = 0; si < s.size(); si++) {         if (mx1 < lcp1[si][ti]) {           mx1 = lcp1[si][ti];           mx1_si = si;         }         if (mx2 < lcp2[si][ti]) {           mx2 = lcp2[si][ti];           mx2_si = si;         }       }       if (mx1 == 0 && mx2 == 0) {         ans = -1;         break;       } else if (mx1 >= mx2) {         ans++;         vec.push_back(pair<int, int>(mx1_si + 1, mx1_si + mx1 - 1 + 1));         ti += mx1;       } else {         ans++;         vec.push_back(pair<int, int>(n - mx2_si, n - (mx2_si + mx2 - 1)));         ti += mx2;       }     }     cout << ans << endl;     for (int i = 0; i < (ans); i++) {       cout << vec[i].first <<     << vec[i].second << endl;     }   }   int main() {     cin >> s;     cin >> t;     n = (int)s.size();     solve();     return 0;   }


#include <bits/stdc++.h>   struct data {     int val;     data(int val) : val(val) {}   };   bool operator<(const data lhs, const data rhs) {     std::cout <<  ?   << lhs.val <<     << rhs.val << std::endl;     char c;     std::cin >> c;     return c ==  < ;   }   int t, n;   std::set<data> a, b;   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(nullptr);     std::cout.tie(nullptr);     std::cin >> t;     while (t--) {       std::cin >> n;       a.clear();       b.clear();       for (int i = 1; i <= 2 * n; ++i) {         if (a.size() < b.size())           a.emplace(i);         else           b.emplace(i);         if (a.size() + b.size() > n)           if (*a.begin() < *b.begin())             a.erase(a.begin());           else             b.erase(b.begin());       }       std::cout <<  !  << std::endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int n;   long long int f(long long int x) {     long long int sq = sqrt(x);     for (long long int i = 2; i <= sq; i++)       if (x % i == 0) return 0;     return 1;   }   int main() {     cin >> n;     if (f(n)) {       cout << 1 << endl << n << endl;       return 0;     }     cout << 3 << endl;     cout << 3 <<    ;     n -= 3;     for (long long int i = 2; i < n; i++) {       if (f(i) && f(n - i)) return cout << i <<     << n - i << endl, 0;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, q;   const int N = 2e5 + 10;   const int inf = 1e9;   char s[N];   struct Node {     Node() {       for (int i = 0; i < 5; i++) {         for (int j = 0; j < 5; j++) {           dp[i][j] = (i == j) ? 0 : inf;         }       }     }     int dp[5][5];   };   Node operator*(const Node& u, const Node& v) {     Node ans;     for (int i = 0; i < 5; i++) {       for (int j = 0; j < 5; j++) {         ans.dp[i][j] = inf;         for (int k = 0; k < 5; k++) {           ans.dp[i][j] = min(u.dp[i][k] + v.dp[k][j], ans.dp[i][j]);         }       }     }     return ans;   }   Node nodes[N * 4];   void build_tree(int l, int r, int rt) {     Node& v = nodes[rt];     if (l == r) {       char c = s[l - 1];       if (c ==  2 ) {         v.dp[0][0] = 1;         v.dp[0][1] = 0;       } else if (c ==  0 ) {         v.dp[1][1] = 1;         v.dp[1][2] = 0;       } else if (c ==  1 ) {         v.dp[2][2] = 1;         v.dp[2][3] = 0;       } else if (c ==  7 ) {         v.dp[3][3] = 1;         v.dp[3][4] = 0;       } else if (c ==  6 ) {         v.dp[3][3] = 1;         v.dp[4][4] = 1;       }       return;     }     int m = (l + r) >> 1;     build_tree(l, m, 2 * rt);     build_tree(m + 1, r, 2 * rt + 1);     v = nodes[2 * rt] * nodes[2 * rt + 1];   }   Node query(int L, int R, int l, int r, int rt) {     Node& v = nodes[rt];     if (L <= l && R >= r) return v;     int m = (l + r) >> 1;     bool left = false, right = false;     Node ltemp, rtemp;     if (L <= m) {       ltemp = query(L, R, l, m, rt * 2);       left = true;     }     if (R > m) {       rtemp = query(L, R, m + 1, r, rt * 2 + 1);       right = true;     }     if (left && right) return ltemp * rtemp;     if (left) return ltemp;     if (right) return rtemp;   }   int main() {     scanf( %d %d , &n, &q);     scanf( %s , s);     build_tree(1, n, 1);     for (int i = 0; i < q; i++) {       int l, r;       scanf( %d %d , &l, &r);       Node v = query(l, r, 1, n, 1);       if (v.dp[0][4] == inf)         cout << -1 << endl;       else         cout << v.dp[0][4] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Point {     int x;     int y;     Point(int x_, int y_) : x(x_), y(y_) {}   };   template <class T>   T sqr(const T& t) {     return t * t;   }   template <class T>   T abs(const T& t) {     return ((t > 0) ? (t) : (-t));   }   void initialize() {     freopen( _.in ,  r , stdin);     freopen( _.out ,  w , stdout);   }   bool isSqr(int x) {     int a = static_cast<int>(sqrt(static_cast<double>(x)));     return (a * a == x);   }   int sqrt(int x) { return static_cast<int>(sqrt(static_cast<double>(x))); }   int sign(int x) {     if (x < 0) return 0;     return 1;   }   int main() {     int x, y;     cin >> x >> y;     int r = x * x + y * y;     bool ok = true;     int b = sqrt(r);     int val = 2 + sign(x * y) + sqrt(r);     if (isSqr(r) || (sign(x * y) + sqrt(r)) % 2 == 1) {       cout <<  black ;     } else {       cout <<  white ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int res[100005], sz;   bool prime[100005], used[100005];   int main() {     int n;     cin >> n;     for (int p = 2; p <= n / 2; ++p) {       if (prime[p]) continue;       for (int j = p; j <= n; j += p) prime[j] = 1;       if (p == 2) continue;       int len = 0;       for (int j = p; j <= n; j += p) {         if (j == 2 * p) continue;         if (used[j]) continue;         used[j] = 1;         res[sz++] = j;         len++;       }       if (len & 1) {         res[sz++] = 2 * p;         used[2 * p] = 1;       }     }     for (int i = 2; i <= n; i += 2)       if (!used[i]) res[sz++] = i;     cout << sz / 2 << endl;     for (int i = 0; i + 1 < sz; i += 2) printf( %d %d n , res[i], res[i + 1]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mul(long long a, long long b) { return (a * b) % 1000000007; }   long long add(long long a, long long b) {     a += b;     if (a >= 1000000007) a -= 1000000007;     return a;   }   long long binary_expo(long long base, long long expo) {     long long res = 1;     while (expo) {       if (expo % 2) {         res = mul(res, base);       }       expo /= 2;       base = mul(base, base);     }     return res;   }   void solve() {     long long n;     cin >> n;     cout << n <<   n ;     for (long long i = 1; i <= n; i++) {       cout <<  1  ;     }     cout <<   n ;   }   signed main() {     long long t;     ios_base::sync_with_stdio(false);     t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   long long n, a[3][333333], x, y, sum[4][333333], r[4][333333];   set<pair<long long, long long> > s[333333];   map<pair<long long, long long>, long long> d;   map<long long, long long> last[4];   void read(long long &x) { scanf( %lld , &x); }   int main() {     cin >> n;     for (long long i = 1; i <= 2; i++)       for (long long j = 1; j <= n; j++) read(a[i][j]);     for (long long i = 1; i <= 2; i++)       for (long long j = n; j >= 1; j--) {         sum[i][j] = sum[i][j + 1] + a[i][j];         sum[3][j] += sum[i][j];       }     last[1][0] = last[2][0] = last[3][0] = n + 1;     r[1][n + 1] = r[2][n + 1] = r[3][n + 1] = n + 1;     for (long long i = 1; i <= 3; i++)       for (long long j = n; j >= 1; j--) {         r[i][j] = r[i][j + 1];         if (last[i].count(sum[i][j]))           r[i][j] = min(r[i][j], last[i][sum[i][j]] - 1);         last[i][sum[i][j]] = j;       }     s[0].insert(make_pair(0, 0));     d[make_pair(0, 0)] = 0;     for (long long i = 0; i < n; i++) {       for (pair<long long, long long> cur : s[i]) {         x = cur.first;         y = cur.second;         if (x <= y) {           s[min(x + 1, y)].insert(make_pair(x + 1, y));           d[make_pair(x + 1, y)] =               max(d[make_pair(x + 1, y)], d[make_pair(x, y)]);           s[min(r[1][x + 1], y)].insert(make_pair(r[1][x + 1], y));           d[make_pair(r[1][x + 1], y)] =               max(d[make_pair(r[1][x + 1], y)], d[make_pair(x, y)] + 1);         }         if (y <= x) {           s[min(x, y + 1)].insert(make_pair(x, y + 1));           d[make_pair(x, y + 1)] =               max(d[make_pair(x, y + 1)], d[make_pair(x, y)]);           s[min(r[2][y + 1], x)].insert(make_pair(x, r[2][y + 1]));           d[make_pair(x, r[2][y + 1])] =               max(d[make_pair(x, r[2][y + 1])], d[make_pair(x, y)] + 1);         }         if (x == y) {           s[r[3][x + 1]].insert(make_pair(r[3][x + 1], r[3][x + 1]));           d[make_pair(r[3][x + 1], r[3][x + 1])] =               max(d[make_pair(r[3][x + 1], r[3][x + 1])], d[make_pair(x, y)] + 1);         }         d.erase(make_pair(x, y));       }       s[i].clear();     }     assert(d.size() <= 4 * n);     cout << d[make_pair(n, n)];   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (a > b) swap(a, b);     if (a == 0) return b;     return gcd(b % a, a);   }   int log2(int x, int max) { return max - __builtin_clz(x) - 1; }   long long powerMod(long long x, long long y) {     long long res = 1;     x %= 1000000007;     while (y > 0) {       if (y & 1) res = (res * x) % 1000000007;       y = y >> 1;       x = (x * x) % 1000000007;     }     return res;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     ;     int n, m, i, j, k, l, x, y, c;     vector<pair<int, int> > v, dir;     cin >> n >> m;     string s[n];     int row[n][m];     int col[n][m];     memset((row), 0, sizeof((row)));     memset((col), 0, sizeof((col)));     for (i = 0; i < n; i++) {       row[i][0] = 1;     }     for (i = 0; i < m; i++) {       col[0][i] = 1;     }     for (i = 0; i < n; i++) {       cin >> s[i];       for (j = 0; j < m; j++) {         if (s[i][j] >=  A  && s[i][j] <=  Z ) v.push_back(make_pair(i, j));         if (j > 0) {           if (s[i][j] ==  # )             row[i][j] = row[i][j - 1] + 1;           else             row[i][j] = row[i][j - 1];         }         if (i > 0) {           if (s[i][j] ==  # )             col[i][j] = col[i - 1][j] + 1;           else             col[i][j] = col[i - 1][j];         }       }     }     cin >> k;     string st;     for (i = 0; i < k; i++) {       cin >> st >> l;       if (st[0] ==  N ) dir.push_back(make_pair(0, l));       if (st[0] ==  S ) dir.push_back(make_pair(1, l));       if (st[0] ==  E ) dir.push_back(make_pair(2, l));       if (st[0] ==  W ) dir.push_back(make_pair(3, l));     }     st =   ;     for (l = 0; l < v.size(); l++) {       x = v[l].first, y = v[l].second;       for (i = 0; i < k; i++) {         j = dir[i].first;         c = dir[i].second;         if (j == 0) {           if (x < c) goto loop;           if (col[x][y] - col[x - c][y] == 0 && s[x - c][y] !=  # )             x -= c;           else             goto loop;         }         if (j == 1) {           if (x + c >= n) goto loop;           if (col[x + c][y] - col[x][y] == 0)             x += c;           else             goto loop;         }         if (j == 2) {           if (y + c >= m) goto loop;           if (row[x][y + c] - row[x][y] == 0)             y += c;           else             goto loop;         }         if (j == 3) {           if (y < c) goto loop;           if (row[x][y] - row[x][y - c] == 0 && s[x][y - c] !=  # )             y -= c;           else             goto loop;         }       }       st += s[v[l].first][v[l].second];     loop:;     }     if (st ==   ) {       cout <<  no solution n ;       return 0;     }     sort(st.begin(), st.end());     cout << st << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e9;   const long long base = 1e9 + 7;   const int N = 5e3 + 2;   int n, m, k;   int a[N][N];   pair<int, int> h[N], c[N];   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> m >> k;     long long x, y, z;     for (int i = (1), b_ = (k); i <= b_; ++i) {       cin >> x >> y >> z;       if (x == 1) {         h[y].first = z;         h[y].second = i;       } else {         c[y].first = z;         c[y].second = i;       }     }     for (int i = (1), b_ = (n); i <= b_; ++i) {       for (int j = (1), b_ = (m); j <= b_; ++j) {         if (h[i].second == 0 && c[j].second == 0)           cout << 0 <<    ;         else if (h[i].second > c[j].second)           cout << h[i].first <<    ;         else           cout << c[j].first <<    ;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = (int)1e5 + 5, INF = (int)1e9;   const long double EPS = 1e-9;   int t[N], h[N], m[N];   bool used[N];   int main() {     int n, cur, ans = 0, ans1 = 0, tp, v = -1, first;     cin >> n >> first;     cur = first;     for (int i = 0; i < n; i++) cin >> t[i] >> h[i] >> m[i];     for (int i = 0; i < n; i++)       if (t[i] == 0 && h[i] <= cur && (v == -1 || m[i] > m[v])) v = i;     tp = 0;     if (v != -1) {       used[v] = 1;       cur += m[v];       ans++;     }     for (int i = 0; i < n; i++) {       v = -1;       for (int j = 0; j < n; j++)         if (!used[j] && t[j] != tp && h[j] <= cur && (v == -1 || m[j] > m[v]))           v = j;       if (v == -1)         break;       else {         tp = 1 - tp;         used[v] = 1;         cur += m[v];         ans++;       }     }     tp = 1;     v = -1;     cur = first;     for (int i = 0; i < n; i++) used[i] = 0;     for (int i = 0; i < n; i++)       if (t[i] == 1 && h[i] <= cur && (v == -1 || m[i] > m[v])) v = i;     if (v != -1) {       used[v] = 1;       cur += m[v];       ans1++;     }     for (int i = 0; i < n; i++) {       v = -1;       for (int j = 0; j < n; j++)         if (!used[j] && t[j] != tp && h[j] <= cur && (v == -1 || m[j] > m[v]))           v = j;       if (v == -1)         break;       else {         tp = 1 - tp;         used[v] = 1;         cur += m[v];         ans1++;       }     }     cout << max(ans, ans1) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 7;   long long arr[maxn];   string s;   int main() {     std::ios::sync_with_stdio(false);     int n;     cin >> n;     long long tot = 0;     for (int i = 0; i < n; i++) {       cin >> arr[i];       arr[i] *= 2;       tot += arr[i];     }     cin >> s;     long long W = 0, G = 0, flag = 5;     for (int i = 0; i < n; i++) {       if (s[i] ==  G )         G += arr[i];       else if (s[i] ==  W )         W += arr[i], flag = 3;       long long cur = arr[i], sta;       sta = min(cur / 2, W), tot += sta * 2, cur -= sta * 2, W -= sta;       sta = min(cur / 2, G), tot += sta * 4, cur -= sta * 2, G -= sta;       tot += flag * cur;     }     cout << tot / 2 << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     string s, A( a );     cin >> s;     vector<vector<int> > a(26);     for (int i = 0; i < k; i++) a[s[i] - A[0]].push_back(i);     for (int i = 0; i < n; i++) {       cin >> s;       long long ans = 0;       for (int j = 0; j < s.size(); j++) {         int b = (int)s[j] - A[0];         int r = (int)a[b].size();         if (r == 0)           ans += s.size();         else {           r--;           int l = 0;           while (r - l > 1) {             int m = (l + r) / 2;             if (a[b][m] >= j)               r = m;             else               l = m;           }           ans += min(abs(a[b][l] - j), abs(a[b][r] - j));         }       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());   void print_time() {}   template <typename T>   void update_max(T& x, T y) {     x = max(x, y);   }   template <typename T>   void update_min(T& x, T y) {     x = min(x, y);   }   template <class T1, class T2>   ostream& operator<<(ostream& out, pair<T1, T2> pair) {     return out <<  (  << pair.first <<  ,   << pair.second <<  ) ;   }   template <class T>   ostream& operator<<(ostream& out, vector<T> vec) {     out <<  ( ;     for (auto& v : vec) out << v <<  ,  ;     return out <<  ) ;   }   template <class T>   ostream& operator<<(ostream& out, set<T> vec) {     out <<  ( ;     for (auto& v : vec) out << v <<  ,  ;     return out <<  ) ;   }   template <class L, class R>   ostream& operator<<(ostream& out, map<L, R> vec) {     out <<  ( ;     for (auto& v : vec) out << v <<  ,  ;     return out <<  ) ;   }   long long ask(long long t, long long i, long long j, long long k) {     ++i, ++j, ++k;     cout << t <<     << i <<     << j <<     << k << endl;     long long res;     cin >> res;     return res;   }   void ans(vector<long long> p) {     cout <<  0  ;     for (long long pp : p) {       cout << pp + 1 <<    ;     }     cout << endl;   }   int main() {     cout << fixed << setprecision(20);     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     long long n;     cin >> n;     vector<long long> area(n);     vector<long long> sign(n);     for (long long i = 2; i < n; ++i) {       area[i] = ask(1, 0, 1, i);       sign[i] = ask(2, 0, 1, i);     }     vector<long long> cnt_sign(2);     vector<set<pair<long long, long long>>> pos(2);     for (long long i = 2; i < n; ++i) {       pos[(sign[i] + 1) / 2].insert({area[i], i});       ++cnt_sign[(sign[i] + 1) / 2];     }     vector<vector<long long>> sorted(2);     for (long long kek = 0; kek < 2; ++kek) {       sorted[kek] = vector<long long>(cnt_sign[kek]);       long long l = 0;       long long r = cnt_sign[kek] - 1;       while (!pos[kek].empty()) {         pair<long long, long long> curr = *pos[kek].begin();         pos[kek].erase(pos[kek].begin());         long long i = 0;         long long j = curr.second;         if (pos[kek].empty()) {           sorted[kek][l] = j;           break;         }         long long k = pos[kek].begin()->second;         long long q = ask(2, i, j, k);         if (q > 0) {           sorted[kek][l++] = j;         } else {           sorted[kek][r--] = j;         }       }     }     vector<long long> p;     p.push_back(0);     for (long long v : sorted[0]) p.push_back(v);     p.push_back(1);     for (long long v : sorted[1]) p.push_back(v);     ans(p);     print_time();     return 0;   }


#include<bits/stdc++.h>   using namespace std;   int main()   {    ios_base::sync_with_stdio(false);       cin.tie(NULL);    long long t;    cin >> t;    while(t--)    {     long long n;     cin >> n;     string a[n];     for(long long i=0;i<n;i++)     {      cin >> a[i];     }     for(long long i=0;i<10;i++)     {      long long ans=0;      std::vector<pair<long long,long long> > x,y;      for(long long j=0;j<n;j++)      {       for(long long k=0;k<n;k++)       {        if(a[j][k]==((char)i+ 0 ))        {         x.push_back(make_pair(j,k) );         y.push_back(make_pair(k,j) );        }       }      }      sort(x.begin(), x.end());      sort(y.begin(), y.end());      for(long long k=0;k<x.size();k++)       {        long long x1=x[0].first,y1=x[0].second,x2=x[k].first,y2=x[k].second;        ans=max(ans,abs(x1-x2)*max(max(y1,n-y1-1),max(y2,n-y2-1)));        ans=max(ans,abs(y1-y2)*max(max(x1,n-x1-1),max(x2,n-x2-1)));       }      for(long long k=0;k<x.size();k++)       {        long long x1=x[k].first,y1=x[k].second,x2=x[x.size()-1].first,y2=x[x.size()-1].second;        ans=max(ans,abs(x1-x2)*max(max(y1,n-y1-1),max(y2,n-y2-1)));        ans=max(ans,abs(y1-y2)*max(max(x1,n-x1-1),max(x2,n-x2-1)));       }      for(long long k=0;k<y.size();k++)       {        long long y1=y[0].first,x1=y[0].second,y2=y[k].first,x2=y[k].second;        ans=max(ans,abs(x1-x2)*max(max(y1,n-y1-1),max(y2,n-y2-1)));        ans=max(ans,abs(y1-y2)*max(max(x1,n-x1-1),max(x2,n-x2-1)));       }      for(long long k=0;k<y.size();k++)       {        long long y1=y[k].first,x1=y[k].second,y2=y[y.size()-1].first,x2=y[y.size()-1].second;        ans=max(ans,abs(x1-x2)*max(max(y1,n-y1-1),max(y2,n-y2-1)));        ans=max(ans,abs(y1-y2)*max(max(x1,n-x1-1),max(x2,n-x2-1)));       }      //}      cout << ans <<    ;     }     cout << endl;    }   }


#include <bits/stdc++.h>   using namespace std;   string t;   vector<string> query(3);   void ask(string &q) {     cout <<  ?   << q <<   n ;     fflush(stdout);     cin >> q;   }   int main() {     ios_base::sync_with_stdio(false);     ;     cin >> t;     for (int i = 0; i < t.length(); i++) {       query[0] += (char)( a  + (i % 26));       query[1] += (char)( a  + ((i % (26 * 26)) / (26)));       query[2] += (char)( a  + (i % (26 * 26 * 26)) / (26 * 26));     }     ask(query[0]);     ask(query[1]);     ask(query[2]);     string ans(t.length(),    );     for (int i = 0; i < t.length(); i++) {       int pos = (query[0][i] -  a ) + (query[1][i] -  a ) * 26 +                 (query[2][i] -  a ) * 26 * 26;       ans[pos] = t[i];     }     cout <<  !   << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 500010, INF = MAXN + 1;   struct Query {     int pos, l, r;   };   struct AddEvent {     int pos, value, start_valid;   };   int n, m;   int as[MAXN];   int close[MAXN];   Query queries[MAXN];   AddEvent add_events[MAXN];   int results[MAXN];   int st[4 * MAXN];   void update(int v, int l, int r, int ind, int val) {     if (l == r) {       assert(st[v] == INF);       st[v] = val;     } else {       int m = (l + r) >> 1;       if (ind <= m)         update(v + v, l, m, ind, val);       else         update(v + v + 1, m + 1, r, ind, val);       st[v] = min(st[v + v], st[v + v + 1]);     }   }   int get(int v, int l, int r, int tl, int tr) {     assert(l <= tl && tr <= r && tl <= tr);     if (l == tl && r == tr) return st[v];     int res = INF, m = (l + r) >> 1;     if (tl <= m) res = get(v + v, l, m, tl, min(tr, m));     if (tr > m) res = min(res, get(v + v + 1, m + 1, r, max(m + 1, tl), tr));     return res;   }   int main() {     for (int i = 0; i < int(4 * MAXN); ++i) st[i] = INF;     scanf( %d%d , &n, &m);     for (int i = 0; i < int(n); ++i) scanf( %d , &as[i]);     for (int i = 0; i < int(m); ++i) {       scanf( %d%d , &queries[i].l, &queries[i].r);       --queries[i].l, --queries[i].r;       queries[i].pos = i;     }     sort(queries, queries + m, [](Query a, Query b) { return a.r < b.r; });     map<int, int> last;     for (int i = n - 1; i >= 0; i--) {       auto it = last.find(as[i]);       if (it == last.end()) {         close[i] = INF;       } else {         close[i] = it->second - i;       }       last[as[i]] = i;     }     for (int i = 0; i < int(n); ++i) {       add_events[i] = {i, close[i], i + close[i]};     }     sort(add_events, add_events + n,          [](AddEvent a, AddEvent b) { return a.start_valid < b.start_valid; });     int qp = 0, ap = 0;     for (int i = 0; i < n; i++) {       while (ap < n && add_events[ap].start_valid == i) {         update(1, 0, n - 1, add_events[ap].pos, add_events[ap].value);         ++ap;       }       while (qp < m && queries[qp].r == i) {         results[queries[qp].pos] = get(1, 0, n - 1, queries[qp].l, queries[qp].r);         ++qp;       }     }     for (int i = 0; i < int(m); ++i) {       if (results[i] == INF) results[i] = -1;       printf( %d n , results[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 11;   int a[N], b[N];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     for (int i = 1; i <= m; i++) {       cin >> a[i] >> b[i];     }     vector<int> v;     for (int p = 1; p <= 200; p++) {       int x = 0;       for (int i = 1; i <= m; i++) {         int d = (a[i] / p);         if (a[i] % p != 0) d++;         if (b[i] != d) {           x = 1;           break;         }       }       if (x == 0) {         int d = (n / p);         if (n % p != 0) d++;         v.push_back(d);       }     }     sort(v.begin(), v.end());     if (v[0] != v[v.size() - 1]) {       cout << -1 << endl;     } else       cout << v[0] << endl;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> sieve(int n) {     vector<bool> prime(n + 1, true);     prime[0] = false;     prime[1] = false;     int m = sqrt(n);     vector<int> ans;     for (int p = 2; p <= m; p++) {       if (prime[p]) {         for (int i = p * 2; i <= n; i += p) prime[i] = false;       }     }     for (int i = 0; i < n; i++)       if (prime[i]) ans.push_back(i);     return ans;   }   int gcd(int a, int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int mod = 1e9 + 7;   int power(int a, long long b) {     int res = 1;     while (b) {       if (b & 1) res = 1LL * res * a % mod;       a = 1LL * a * a % mod;       b >>= 1;     }     return res;   }   long long min(int a, long long b) {     if (a > b) return b;     return a;   }   long long max(int a, long long b) {     if (a > b) return a;     return b;   }   void solve() {     long long n, m;     cin >> n >> m;     vector<pair<int, int>> p;     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       p.push_back({x, y});     }     long long ans =         max(p[0].first + p[0].second - 1, p[m - 1].second + (n - p[m - 1].first));     for (int i = 1; i < m; i++) {       if (abs(p[i].second - p[i - 1].second) > p[i].first - p[i - 1].first) {         cout <<  IMPOSSIBLE ;         return;       }       ans = max(ans, max(p[i].second, p[i - 1].second) +                          (p[i].first - p[i - 1].first -                           abs(p[i].second - p[i - 1].second)) /                              2);     }     cout << ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int mul = 0;     if (mul == 1) {       int t;       cin >> t;       while (t--) {         solve();         cout <<   n ;       }     } else {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 10;   const int MOD = 1e9 + 7;   int n;   long long int a[MAXN], minn;   bool have[MAXN], flag;   int main() {     while (scanf( %d , &n) != EOF) {       a[1] = 0;       minn = 0;       memset(have, false, sizeof(have));       flag = true;       for (int i = 1; i < n; ++i) {         int num;         scanf( %I64d , &num);         a[i + 1] = a[i] + num;         minn = min(minn, a[i + 1]);       }       for (int i = 1; i <= n; ++i) {         a[i] += -minn + 1;         if (a[i] > n || have[a[i]]) {           printf( -1 n );           flag = false;           break;         }         have[a[i]] = true;       }       if (flag) {         for (int i = 1; i <= n; ++i) {           i == n ? printf( %I64d n , a[i]) : printf( %I64d  , a[i]);         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename S>   ostream &operator<<(ostream &os, const pair<T, S> &v) {     os <<  ( ;     os << v.first <<  ,  << v.second <<  ) ;     return os;   }   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &v) {     os <<  [ ;     long long sz = v.size();     for (long long i = 0; i < sz; ++i) {       os << v[i];       if (i != sz - 1) os <<  , ;     }     os <<  ] n ;     return os;   }   template <typename T>   ostream &operator<<(ostream &os, const set<T> &v) {     T last = *v.rbegin();     os <<  [ ;     for (auto it : v) {       os << it;       if (it != last) os <<  , ;     }     os <<  ] n ;     return os;   }   template <typename T, typename S>   ostream &operator<<(ostream &os, const map<T, S> &v) {     for (auto it : v) {       os << it.first <<   :   << it.second <<   n ;     }     return os;   }   long long power(long long a, long long b) {     long long res = 1;     while (b) {       if (b % 2) {         res = (res * a) % 1000000007;       }       b /= 2;       a = (a * a) % 1000000007;     }     return res;   }   template <typename Arg1>   void __f(const char *name, Arg1 &&arg1) {     cerr << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char *names, Arg1 &&arg1, Args &&...args) {     const char *comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   const long long N = 1005;   long long arr[N];   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     for (__typeof(1) i = 1; i <= n; i++) cin >> arr[i];     long long res = 0;     for (__typeof(2) i = 2; i <= n - 1; i++) {       if ((arr[i] > arr[i - 1] && arr[i] > arr[i + 1]) ||           (arr[i] < arr[i - 1] && arr[i] < arr[i + 1]))         ++res;     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e6 + 7;   int A[N], B[N], n, ans, pos[N], s1[N], s2[N], cnt;   int main() {     cin >> n;     for (int i = 1; i <= n; ++i) cin >> A[i], pos[A[i]] = i;     for (int i = 1; i <= n; ++i) cin >> B[i], A[pos[B[i]]] = i;     for (int i = 1; i <= n; ++i) pos[A[i]] = i;   ZXY:;     int st = 1;     while (A[st] == st) st++;     for (int i = st; i <= n; ++i)       if (A[i] > i) {         for (int j = i + 1; j <= n; ++j)           if (A[j] <= i && j <= A[i]) {             ans += j - i;             s1[++cnt] = i, s2[cnt] = j;             swap(A[i], A[j]);             goto ZXY;           }       }     cout << ans << endl << cnt << endl;     for (int i = 1; i <= cnt; ++i) cout << s1[i] <<     << s2[i] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, res = 0, a, b;     cin >> n;     vector<pair<long long, long long>> nums;     for (int i = 0; i < n; i++) {       cin >> a >> b;       nums.push_back({a, b});     }     for (int i = 0; i < n; i++) {       bool l = false, r = false, u = false, d = false;       for (int j = 0; j < n; j++)         if (i != j) {           if (nums[j].second == nums[i].second && nums[j].first > nums[i].first)             r = true;           if (nums[j].second == nums[i].second && nums[j].first < nums[i].first)             l = true;           if (nums[j].second > nums[i].second && nums[j].first == nums[i].first)             u = true;           if (nums[j].second < nums[i].second && nums[j].first == nums[i].first)             d = true;         }       res += (bool)(l && r && u && d);     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   int main() {     int a, b, c, d;     while (scanf( %d%d%d%d , &a, &b, &c, &d) == 4) {       if (c >= b - 1 && c <= 2 * (b + 1)) {         printf( YES n );         continue;       }       if (d >= a - 1 && d <= 2 * (a + 1)) {         printf( YES n );         continue;       }       printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int A[1000001];   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> A[i];     }     map<int, int> change_v;     int above = 0, below = 0;     long long sum = 0;     long long best_i = 0;     for (int i = 0; i < n; i++) {       int xs = A[i] - i - 1;       int x = (xs > 0) ? xs : -1 * xs;       if (xs < 0) {         change_v[x]++;       }       if (xs < 0) {         below++;       } else {         above++;       }       sum += x;     }     long long best_sum = sum;     for (int i = 0; i < n - 1; i++) {       long long xs = A[i] - n;       long long x = (xs > 0) ? xs : -1 * xs;       long long cnt = change_v[i + 1];       if (xs < 0) {         change_v[x + i + 1]++;       }       int cur_below_d = (A[i] - 1 < 0) ? 1 : 0;       int cur_above_d = (A[i] - 1 >= 0) ? 1 : 0;       sum -= below - cur_below_d;       sum += above - cur_above_d;       sum -= (A[i] - 1 > 0) ? A[i] - 1 : 1 - A[i];       sum += x;       above += cnt;       below -= cnt;       if (xs < 0 && A[i] - 1 >= 0) {         below++;         above--;       }       if (sum < best_sum) {         best_i = i + 1;         best_sum = sum;       }     }     if (best_i != 0) {       best_i = n - best_i;     }     cout << best_sum <<     << best_i;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T power(T a, T b) {     T x;     if (b == 0)       x = 1;     else       x = a;     for (size_t i = 1; i < b; i++) x *= a;     return x;   }   long long int gcd(long long int a, long long int b) {     return b == 0 ? a : gcd(b, a % b);   }   long long int n, m, a, b, c, ab, ba, x, y, z, avg, total, ans, sum;   long long int arr2[300001], arr3[100001], arr4[100001], arr5[100001];   char c1, c2;   vector<pair<string, long long int> > vec;   vector<long long int> v;   bool f, f1, f2, found;   string str, s1, s2, s3, s4;   map<long long int, long long int> mp, mp1;   set<int> seto;   double d, d1;   long long int x1, x2, y11, y2;   long long int mini = 10000000000, maxi = 0;   set<string> sets;   int main() {     cin >> n >> str;     for (long long int i = 0; i < str.size(); i++) {       if (str[i] ==  > )         f1 = 1;       else         f = 1;     }     if (f && f1) {       for (long long int i = 0; i < str.size(); i++)         if (str[i] ==  < )           sum++;         else           break;       reverse(str.rbegin(), str.rend());       for (long long int i = 0; i < str.size(); i++)         if (str[i] ==  > )           sum++;         else           break;     } else       sum = str.size();     cout << sum;   }


#include <bits/stdc++.h>   using namespace std;   const int nm = 2e5 + 3;   const long long mod = 1e9 + 7;   int n;   int pos[nm];   int main() {     ios::sync_with_stdio(0), cin.tie(0);     while (cin >> n) {       for (int i = 0; i < n; i++) cin >> pos[i];       sort(pos, pos + n);       int step = n / 2 - 1;       int res = pos[n - 1] - pos[0];       pair<double, int> loc;       for (int i = 0; i <= step; i++) {         if (pos[i + n - step - 1] - pos[i] < res) {           res = pos[i + n - step - 1] - pos[i];           loc.first = i, loc.second = i + n - step - 1;         }       }       cout << res << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 150;   int n, dp[N][N * N], sum, cnt[N], x, u[N][N * N], res;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) scanf( %d , &x), sum += x, cnt[x]++;     dp[0][0] = 1;     for (int i = 1; i <= 100; i++) {       res += (cnt[i] > 0);       for (int j = n; j >= 1; j--) {         for (int cn = 1; cn <= min(j, cnt[i]); cn++) {           for (int l = i * cn; l <= sum; l++) {             dp[j][l] += dp[j - cn][l - i * cn];           }         }       }     }     if (res == 1 || res == 2) {       cout << n << endl;       return 0;     }     for (int i = 1; i <= 100; i++)       for (int cn = 1; cn <= cnt[i]; cn++) u[cn][i * cn] = 1;     for (int i = n; i >= 1; i--) {       for (int j = 0; j <= sum; j++) {         if (dp[i][j] == 1 && u[i][j] == 1) {           cout << i << endl;           return 0;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long t, xiaoyud, dayu, n, x, pos, ans1, mo = 1e9 + 7, ans2, ans;   int main() {     cin >> n >> x >> pos;     long long l = 0, r = n;     while (l < r) {       long long mid = (l + r) / 2;       if (mid <= pos) {         l = mid + 1;         if (mid != pos) xiaoyud++;       } else {         r = mid;         dayu++;       }     }     ans1 = 1;     for (long long i = 1; i <= xiaoyud; i++) {       ans1 = (ans1 * (x - 1 - i + 1)) % mo;     }     ans2 = 1;     for (long long i = 1; i <= dayu; i++) {       ans2 = (ans2 * (n - x - i + 1)) % mo;     }     ans = (ans1 * ans2) % mo;     for (long long i = 1; i <= n - xiaoyud - dayu - 1; i++) {       ans = (ans * (n - xiaoyud - dayu - i)) % mo;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, od = 0, ev = 0, ans = 0;     cin >> n;     vector<int> vec;     vector<int>::iterator it;     while (n--) {       cin >> a;       vec.push_back(a);       if (a % 2 == 0)         ev++;       else         od++;     }     for (it = vec.begin(); it != vec.end(); it++) {       if (ev > od) {         if (*it % 2 != 0) ans = distance(vec.begin(), it);       } else if (od > ev) {         if (*it % 2 == 0) ans = distance(vec.begin(), it);       }     }     cout << ans + 1;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   string s, t;   int cnt[10], n, Num, tmp[10], cntT[10], m, tmpCnt[10];   string lmao1 =   , lmao2 =   , lmao3 =   ;   int main() {     cin.tie(0), ios_base::sync_with_stdio(0);     cin >> s;     cin >> t;     m = (int)(t.length());     n = (int)(s.length());     for (int i = 0; i < m; i++) cntT[(int)(t[i] -  0 )]++;     for (int i = 0; i < n; i++) cnt[(int)(s[i] -  0 )]++;     if ((s ==  01  || s ==  10 ) && t ==  0 ) {       cout <<  0 ;       exit(0);     }     for (int i = 1; i <= n; i++) {       for (int j = 0; j < 10; j++) tmp[j] = 0;       int x = i, sumD = 0;       while (x) {         tmp[x % 10]++;         x /= 10;         sumD++;       }       if (sumD + i != n) continue;       bool ok = 1;       for (int j = 0; j < 10; j++) ok &= (cnt[j] >= tmp[j]);       for (int j = 0; j < 10; j++) ok &= (cnt[j] - tmp[j] >= cntT[j]);       int digits = 0;       for (int j = 1; j < 10; j++) digits += (cnt[j] - tmp[j] > 0);       ok &= (digits > 0);       if (!ok) continue;       Num = i;       for (int j = 0; j < 10; j++) cnt[j] -= tmp[j];       break;     }     bool containT = 0;     int lim = 0;     for (int j = 0; j < 10; j++) tmpCnt[j] = cnt[j];     string ans =   ;     bool ok = 1;     for (int i = 1; i <= Num; i++) {       if (i <= lim) continue;       bool ck = 0;       for (int j = (i == 1); j <= 9; j++) {         if (!cnt[j]) continue;         cnt[j]--;         bool uk = 1;         if (!containT) {           for (int k = 0; k <= 9; k++) uk &= (cnt[k] >= cntT[k]);           if (i != 1) {             if (j == t[0] -  0 ) {               cnt[j]++;               lmao1 += t;               for (int k = 0; k <= 9; k++) cnt[k] -= cntT[k];               containT = 1;               lim = i + m - 1;               ck = 1;               break;             }           }           if (!uk) {             cnt[j]++;             continue;           }         }         ck = 1;         lmao1 += ( 0  + j);         break;       }       ok &= ck;     }     if (!ok) lmao1 =   ;     containT = 0, lim = 0;     ok = 1;     for (int j = 0; j < 10; j++) cnt[j] = tmpCnt[j];     for (int i = 1; i <= Num; i++) {       if (i <= lim) continue;       bool ck = 0;       for (int j = (i == 1); j <= 9; j++) {         if (!cnt[j]) continue;         cnt[j]--;         bool uk = 1;         if (!containT) {           for (int k = 0; k <= 9; k++) uk &= (cnt[k] >= cntT[k]);           if (j == t[0] -  0 ) {             cnt[j]++;             lmao3 += t;             for (int k = 0; k <= 9; k++) cnt[k] -= cntT[k];             containT = 1;             lim = i + m - 1;             ck = 1;             break;           }           if (!uk) {             cnt[j]++;             continue;           }         }         ck = 1;         lmao3 += ( 0  + j);         break;       }       ok &= ck;     }     if (!ok) lmao2 =   ;     containT = 0, lim = 0;     ok = 1;     for (int j = 0; j < 10; j++) cnt[j] = tmpCnt[j];     for (int i = 1; i <= Num; i++) {       if (i <= lim) continue;       bool ck = 0;       for (int j = (i == 1); j <= 9; j++) {         if (!cnt[j]) continue;         cnt[j]--;         bool uk = 1;         if (!containT) {           for (int k = 0; k <= 9; k++) uk &= (cnt[k] >= cntT[k]);           cnt[j]++;           if (cnt[j] - cntT[j] == 0 && j == t[0] -  0 ) {             lmao2 += t;             for (int k = 0; k <= 9; k++) cnt[k] -= cntT[k];             containT = 1;             lim = i + m - 1;             ck = 1;             break;           }           cnt[j]--;           if (!uk) {             cnt[j]++;             continue;           }         }         ck = 1;         lmao2 += ( 0  + j);         break;       }       ok &= ck;     }     if (!ok) lmao3 =   ;     if (lmao1 !=   ) ans = lmao1;     if (lmao2 !=   ) ans = lmao2;     if (lmao3 !=   ) ans = lmao3;     if (lmao1 !=   ) ans = min(ans, lmao1);     if (lmao2 !=   ) ans = min(ans, lmao2);     if (lmao3 !=   ) ans = min(ans, lmao3);     cout << ans;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   using namespace std;   int a[510][510];   int mi[510][510];   int main() {     ios_base::sync_with_stdio(0);     int n, m, k, q;     cin >> n >> m >> k >> q;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         a[i][j] = -1;         mi[i][j] = -1;       }     for (int i = 1; i <= q; i++) {       int x, y, z;       cin >> x >> y >> z;       a[x][y] = z;     }     for (int i = 1; i <= n; i++) {       multiset<int> st;       for (int j = 1; j <= k; j++) {         st.insert(a[i][j]);       }       for (int j = k + 1; j <= m + 1; j++) {         auto kk = st.end();         kk--;         if ((*st.begin()) != -1) mi[i][j - k] = (*kk);         st.erase(st.find(a[i][j - k]));         st.insert(a[i][j]);       }     }     int ans = 2e9;     for (int j = 1; j <= m - k + 1; j++) {       multiset<int> st;       for (int i = 1; i <= k; i++) {         st.insert(mi[i][j]);       }       for (int i = k + 1; i <= n + 1; i++) {         auto kk = st.end();         kk--;         if ((*st.begin()) != -1) ans = min(ans, (*kk));         st.erase(st.find(mi[i - k][j]));         st.insert(mi[i][j]);       }     }     if (ans == 2e9)       cout << -1;     else       cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     node* child[26];     priority_queue<int> pq;     bool leaf;     node() {       memset(child, 0, sizeof child);       leaf = false;     }   };   void insert(node* curr, const string& x) {     for (auto c : x) {       if (!curr->child[c -  a ]) curr->child[c -  a ] = new node();       curr = curr->child[c -  a ];     }     curr->leaf = true;   }   void dfs(node* curr, int lev) {     for (int i = 0; i < 26; i++) {       if (!curr->child[i]) continue;       dfs(curr->child[i], lev + 1);       while (!curr->child[i]->pq.empty())         curr->pq.push(curr->child[i]->pq.top()), curr->child[i]->pq.pop();     }     if (curr->leaf)       curr->pq.push(lev);     else {       if (!curr->pq.empty() && lev) curr->pq.pop(), curr->pq.push(lev);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     node* root = new node();     while (n--) {       string x;       cin >> x;       insert(root, x);     }     dfs(root, 0);     long long ans = 0;     while (!root->pq.empty()) ans += root->pq.top(), root->pq.pop();     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int Get() {     int res = 0, q = 1;     char ch = getchar();     while ((ch <  0  || ch >  9 ) && ch !=  - ) ch = getchar();     if (ch ==  - ) q = -1, ch = getchar();     while (ch >=  0  && ch <=  9 ) res = res * 10 + ch -  0 , ch = getchar();     return res * q;   }   const double eps = 1e-12, pi = M_PI;   const int oo = (int)2e9, mod = (int)1e9 + 7;   const long long INF = (long long)1e17;   const int N = (int)1e5;   typedef int arr[N + 10];   arr a, b, c, lstx, lsty, id, u, v, sc;   bool vs[10];   int d[10], ord[10];   int n, m;   bool cmp_x(const int &x, const int &y) { return a[x] < a[y]; }   bool cmp_y(const int &x, const int &y) { return b[x] < b[y]; }   struct node {     node *ch[2];     int s;   } * Rt[N + 10];   node *New() {     node *res = new node;     res->ch[0] = res->ch[1] = NULL, res->s = 0;     return res;   }   node *Copy(node *x) {     node *res = new node;     res->ch[0] = x->ch[0], res->ch[1] = x->ch[1], res->s = x->s;     return res;   }   node *New(node *x, int d) {     if (!x->ch[d]) return New();     return Copy(x->ch[d]);   }   void Update(node *x) {     x->s = 0;     if (x->ch[0]) x->s += x->ch[0]->s;     if (x->ch[1]) x->s += x->ch[1]->s;   }   void Add(int l, int r, node *&x, int pos) {     if (l == r) {       ++x->s;       return;     }     int mid = (l + r) >> 1;     if (pos <= mid)       Add(l, mid, x->ch[0] = New(x, 0), pos);     else       Add(mid + 1, r, x->ch[1] = New(x, 1), pos);     Update(x);   }   int Query(int l, int r, node *x, int ml, int mr) {     if (!x || ml > mr) return 0;     if (l >= ml && r <= mr) return x->s;     int mid = (l + r) >> 1, res = 0;     if (ml <= mid) res += Query(l, mid, x->ch[0], ml, mr);     if (mr > mid) res += Query(mid + 1, r, x->ch[1], ml, mr);     return res;   }   void Init() {     scanf(          %d            n ,         &n);     for (int i = (1), end = (n); i <= end; ++i)       scanf(            %d             %d              n ,           a + i, b + i),           u[i] = a[i], v[i] = b[i], c[i] = a[i], lstx[i] = i, lsty[i] = i;     for (int i = (1), end = (9); i <= end; ++i) scanf( %d , d + i);     c[n + 1] = oo;     sort(c + 1, c + n + 1);     int cnt = 0;     for (int i = (1), end = (n); i <= end; ++i)       if (c[i] != c[i + 1]) c[++cnt] = c[i];     for (int i = (1), end = (n); i <= end; ++i)       a[i] = lower_bound(c + 1, c + cnt + 1, a[i]) - c;     for (int i = (1), end = (n); i <= end; ++i) c[i] = b[i];     sort(c + 1, c + n + 1);     cnt = 0;     for (int i = (1), end = (n); i <= end; ++i)       if (c[i] != c[i + 1]) c[++cnt] = c[i];     m = cnt;     for (int i = (1), end = (n); i <= end; ++i)       b[i] = lower_bound(c + 1, c + cnt + 1, b[i]) - c;     sort(lstx + 1, lstx + n + 1, cmp_x);     sort(lsty + 1, lsty + n + 1, cmp_y);     Rt[0] = New();     int tot = 0;     for (int i = (1), end = (n); i <= end; ++i) {       int x = lstx[i];       if (a[x] == a[lstx[i - 1]])         Rt[i] = Rt[sc[tot]], id[x] = tot;       else         Rt[i] = Copy(Rt[sc[tot]]), sc[++tot] = i, id[x] = tot;       Add(1, m, Rt[i], b[x]);     }   }   void Check() {     int x1 = lstx[ord[1] + ord[4] + ord[7]],         x2 = lstx[ord[1] + ord[2] + ord[4] + ord[5] + ord[7] + ord[8] + 1];     int y1 = lsty[ord[7] + ord[8] + ord[9]],         y2 = lsty[ord[7] + ord[8] + ord[9] + ord[4] + ord[5] + ord[6] + 1];     int num = Query(1, m, Rt[sc[id[x1]]], b[y2], m);     if (num != ord[1]) return;     num = Query(1, m, Rt[sc[id[x1]]], b[y1] + 1, b[y2] - 1);     if (num != ord[4]) return;     num = Query(1, m, Rt[sc[id[x1]]], 1, b[y1]);     if (num != ord[7]) return;     num = Query(1, m, Rt[sc[id[x2] - 1]], b[y2], m) - ord[1];     if (num != ord[2]) return;     num = Query(1, m, Rt[sc[id[x2] - 1]], 1, b[y1]) - ord[7];     if (num != ord[8]) return;     num = Query(1, m, Rt[n], b[y2], m) - ord[1] - ord[2];     if (num != ord[3]) return;     num = Query(1, m, Rt[n], 1, b[y1]) - ord[7] - ord[8];     if (num != ord[9]) return;     num = Query(1, m, Rt[n], b[y1] + 1, b[y2] - 1) -           Query(1, m, Rt[sc[id[x2] - 1]], b[y1] + 1, b[y2] - 1);     if (num != ord[6]) return;     double px1 = (double)u[x1] + 0.5, px2 = (double)u[x2] - 0.5;     double py1 = (double)v[y1] + 0.5, py2 = (double)v[y2] - 0.5;     printf(          %.8lf                       %.8lf            n ,         px1, px2);     printf(          %.8lf                       %.8lf            n ,         py1, py2);     exit(0);   }   void Dfs(int x) {     if (x > 9) {       Check();       return;     }     for (int i = (1), end = (9); i <= end; ++i)       if (!vs[i]) {         vs[i] = 1, ord[x] = d[i];         Dfs(x + 1);         vs[i] = 0;       }   }   int main() {     Init();     Dfs(1);     printf( -1 n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 100010;   int n, m, res, l[3][maxN], r[3][maxN], g[16 * maxN], t[16 * maxN], ans[maxN],       con[maxN];   bool avail[maxN];   stack<int> s[4 * maxN];   struct ioi {     int v, p, t, k;   };   ioi c[4 * maxN];   bool cmp(ioi i, ioi j) {     if (i.v < j.v) return true;     if (i.v > j.v) return false;     if (i.t < j.t) return true;     if (i.t > j.t) return false;     if (i.t == 1)       return (i.k > j.k);     else       return (i.k < j.k);   }   void update(int k, int l, int r, int i, int x) {     if ((i < l) || (i > r)) return;     if (l == r) {       t[k] += x;       if (t[k])         g[k] = l;       else         g[k] = 0;       return;     }     int mid = (l + r) >> 1;     update(k * 2, l, mid, i, x);     update(k * 2 + 1, mid + 1, r, i, x);     t[k] = t[k * 2] + t[k * 2 + 1];     if (g[k * 2] == 0)       g[k] = g[k * 2 + 1];     else if (g[k * 2 + 1] == 0)       g[k] = g[k * 2];     else       g[k] = min(g[k * 2], g[k * 2 + 1]);   }   int get(int k, int l, int r, int i) {     if (r < i) return 0;     if (l >= i) return g[k];     if (l == r) return 0;     int mid = (l + r) >> 1;     int tmp_1 = get(k * 2, l, mid, i);     int tmp_2 = get(k * 2 + 1, mid + 1, r, i);     if (!tmp_1) return tmp_2;     if (!tmp_2) return tmp_1;     return min(tmp_1, tmp_2);   }   int main() {     scanf( %d , &n);     int x, y, z, num = 0;     for (int i = 1; i <= n; ++i) {       scanf( %d%d , &x, &y);       l[1][i] = x;       r[1][i] = y;       c[++num].v = x;       c[num].t = 1;       c[num].k = 1;       c[num].p = i;       c[++num].v = y;       c[num].t = 2;       c[num].k = 1;       c[num].p = i;     }     scanf( %d , &m);     for (int i = 1; i <= m; ++i) {       scanf( %d%d%d , &x, &y, &z);       l[2][i] = x;       r[2][i] = y;       con[i] = z;       c[++num].v = x;       c[num].t = 1;       c[num].k = 2;       c[num].p = i;       c[++num].v = y;       c[num].t = 2;       c[num].k = 2;       c[num].p = i;     }     sort(c + 1, c + num + 1, cmp);     int val = c[1].v;     c[1].v = 1;     for (int i = 2; i <= num; ++i) {       int tmp_val = c[i].v;       if (c[i].v != val)         c[i].v = c[i - 1].v + 1;       else         c[i].v = c[i - 1].v;       if (c[i].t == 1)         l[c[i].k][c[i].p] = c[i].v;       else         r[c[i].k][c[i].p] = c[i].v;       val = tmp_val;     }     for (int i = 1; i <= num; ++i) {       if (c[i].k == 1) {         if (c[i].t == 1) {           int u = get(1, 1, c[num].v, r[1][c[i].p]);           if (u == 0) {             res = -1;             break;           }           while ((!s[u].empty()) && (!avail[s[u].top()])) s[u].pop();           if (u == 0) {             res = -1;             break;           }           u = s[u].top();           ans[c[i].p] = u;           con[u]--;           if (!con[u]) update(1, 1, c[num].v, r[2][u], -1), avail[u] = 0;         }       } else if (c[i].t == 1) {         update(1, 1, c[num].v, r[2][c[i].p], 1);         s[r[2][c[i].p]].push(c[i].p);         avail[c[i].p] = 1;       } else {         update(1, 1, c[num].v, c[i].v, -1);         avail[c[i].p] = 0;       }     }     if (res == -1)       printf( NO );     else {       printf( YES n );       for (int i = 1; i <= n; ++i) printf( %d  , ans[i]);     }     fclose(stdin);     fclose(stdout);   }


#include <bits/stdc++.h>   using namespace std;   using INT = long long;   using pii = pair<INT, INT>;   using pi3 = pair<pii, INT>;   INT a[5010];   bool dp[5010][5010];   INT val[5010];   vector<pi3> ans;   int main() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     INT n, k, v;     cin >> n >> k >> v;     for (INT i = 1; i <= n; i++) cin >> a[i];     INT sum = 0;     for (INT i = 1; i <= n; i++) sum += a[i];     if (sum < v) {       cout <<  NO  << endl;       return 0;     }     for (INT i = 0; i < k; i++) val[i] = n + 1;     dp[0][0] = 1;     for (INT i = 1; i <= n; i++) {       for (INT j = 0; j < k; j++)         if (dp[i - 1][j]) {           INT temp = (j + a[i]) % k;           dp[i][temp] = 1;           dp[i][j] = 1;           val[temp] = min(val[temp], i);         }       dp[i][a[i] % k] = 1;       val[a[i] % k] = min(val[a[i] % k], i);     }     INT p = v % k;     int fff = 0;     INT ID, sz;     if (p == 0) {       cout <<  YES  << endl;       if (a[1]) cout << (a[1] + k - 1) / k <<   1 2  << endl;       a[2] += a[1];       fff = 1;       ID = 1;       sz = 0;     }     if (!fff) {       INT id = val[p];       if (id == n + 1) {         cout <<  NO  << endl;         return 0;       }       cout <<  YES  << endl;       ID = id;       p -= (a[id] % k);       if (p < 0) p += k;       sz = a[id];       id = val[p];       while (p != 0) {         p -= (a[id] % k);         ans.push_back(pi3(pii(a[id] / k + 1, id), ID));         sz += a[id];         a[id] = 0;         if (p < 0) p += k;         id = val[p];       }     }     INT sr = 1;     if (ID == sr) sr = n;     for (INT i = 1; i <= n; i++) {       if (a[i] == 0 || i == ID || i == sr) continue;       ans.push_back(pi3(pii((a[i] + k - 1) / k, i), sr));     }     INT val = (v - sz) / k;     if (val > 0) {       ans.push_back(pi3(pii(val, sr), ID));     }     if (val < 0) {       ans.push_back(pi3(pii(-val, ID), sr));     }     for (auto p : ans) {       INT u = p.first.first;       INT sr = p.first.second;       INT ta = p.second;       cout << u <<     << sr <<     << ta << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k;   vector<vector<int> > g;   vector<vector<int> > revg;   int active[1000005];   int del;   int limx, limy, limz;   unordered_set<int> visited;   void add(int a, int b) {     if (active[a] && active[b]) {       g[a].push_back(b);       revg[b].push_back(a);     }   }   int get(int a, int b, int c) { return a * m * k + b * k + c; }   bool downlimit(int v) {     if (v == del) return false;     int z(v % k);     v /= k;     int y(v % m);     int x(v / m);     return x <= limx && y <= limy && z <= limz;   }   void dfs(int v) {     visited.insert(v);     for (int i(0), _l((int)(((int)g[v].size())) - 1); i <= _l; ++i) {       int to(g[v][i]);       if (downlimit(to)) dfs(to);     }   }   void solve() {     memset((active), 0, sizeof(active));     scanf( %d%d%d n , &n, &m, &k);     g.resize(n * m * k);     revg.resize(n * m * k);     for (int i(0), _l((int)(n)-1); i <= _l; ++i)       for (int j(0), _l((int)(m)-1); j <= _l; ++j) {         string s;         getline(cin, s);         for (int q(0), _l((int)(k)-1); q <= _l; ++q)           active[get(i, j, q)] = (s[q] ==  1 );         if (j == m - 1) getline(cin, s);       }     for (int i(0), _l((int)(n)-1); i <= _l; ++i)       for (int j(0), _l((int)(m)-1); j <= _l; ++j)         for (int q(0), _l((int)(k)-1); q <= _l; ++q) {           if (i < n - 1) add(get(i, j, q), get(i + 1, j, q));           if (j < m - 1) add(get(i, j, q), get(i, j + 1, q));           if (q < k - 1) add(get(i, j, q), get(i, j, q + 1));         }     int ans(0);     for (int x(0), _l((int)(n)-1); x <= _l; ++x)       for (int y(0), _l((int)(m)-1); y <= _l; ++y)         for (int z(0), _l((int)(k)-1); z <= _l; ++z) {           int v(get(x, y, z));           del = v;           limx = x + 1, limy = y + 1, limz = z + 1;           bool frogs(false);           for (int i(0), _l((int)(((int)revg[v].size())) - 1); i <= _l; ++i) {             int from(revg[v][i]);             visited.clear();             dfs(from);             for (int j(0), _l((int)(((int)g[v].size())) - 1); j <= _l; ++j) {               int to(g[v][j]);               if (!visited.count(to)) frogs = true;               if (frogs) break;             }             if (frogs) break;           }           ans += frogs;         }     printf( %d n , ans);   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int d_compare(double x, double y) {     return (fabs(x - y) <= 1e-8) ? 0 : (x > y) ? 1 : -1;   }   inline int mod(long long x, int y) {     if (y == 0) return x;     if (x < 0) x = -x;     if (x >= y) x %= y;     return x;   }   inline int cmod(int x, int y) {     if (y == 0) return x;     if (x < 0) x += (abs(x) / y + 1) * y;     if (x >= y) x = x % y;     return x;   }   int Bcount(int mask) {     int n = 0;     while (mask) n += ((mask & -mask) != 0), mask &= ~(mask & -mask);     return n;   }   inline bool Bstate(int mask, int idx) { return (mask & (1 << idx)); }   inline int B1(int mask, int idx) { return mask | (1 << idx); }   inline int B0(int mask, int idx) { return mask & ~(1 << idx); }   inline int drift(int mask, int n) { return mask & ((1 << n) - 1); }   void debugmask(int mask, int n) {     for (int i = 0; i < n; i++) cout << Bstate(mask, i);   }   class point {    public:     int x, y;     point(int i, int j) {       x = i;       y = j;     }   };   bool arr[2002][2002];   int n, m;   bool check(point wall) {     if (arr[wall.x + 1][wall.y] && arr[wall.x][wall.y + 1] &&         arr[wall.x + 1][wall.y + 1])       return 1;     if (arr[wall.x - 1][wall.y] && arr[wall.x][wall.y - 1] &&         arr[wall.x - 1][wall.y - 1])       return 1;     if (arr[wall.x + 1][wall.y] && arr[wall.x][wall.y - 1] &&         arr[wall.x + 1][wall.y - 1])       return 1;     if (arr[wall.x - 1][wall.y] && arr[wall.x][wall.y + 1] &&         arr[wall.x - 1][wall.y + 1])       return 1;     return 0;   }   void dfs(point wall) {     if (wall.x > n || wall.y > m) return;     arr[wall.x][wall.y] = 1;     if (!arr[wall.x - 1][wall.y] && check(point(wall.x - 1, wall.y)))       dfs(point(wall.x - 1, wall.y));     if (!arr[wall.x + 1][wall.y] && check(point(wall.x + 1, wall.y)))       dfs(point(wall.x + 1, wall.y));     if (!arr[wall.x][wall.y - 1] && check(point(wall.x, wall.y - 1)))       dfs(point(wall.x, wall.y - 1));     if (!arr[wall.x][wall.y + 1] && check(point(wall.x, wall.y + 1)))       dfs(point(wall.x, wall.y + 1));     if (!arr[wall.x - 1][wall.y + 1] && check(point(wall.x - 1, wall.y + 1)))       dfs(point(wall.x - 1, wall.y + 1));     if (!arr[wall.x + 1][wall.y - 1] && check(point(wall.x + 1, wall.y - 1)))       dfs(point(wall.x + 1, wall.y - 1));     if (!arr[wall.x - 1][wall.y - 1] && check(point(wall.x - 1, wall.y - 1)))       dfs(point(wall.x - 1, wall.y - 1));     if (!arr[wall.x + 1][wall.y + 1] && check(point(wall.x + 1, wall.y + 1)))       dfs(point(wall.x + 1, wall.y + 1));   }   void input() {     memset(arr, 0, sizeof arr);     char c;     cin >> n >> m;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         cin >> c;         arr[i][j] = (c ==  . );       }   }   int main() {     std::ios_base::sync_with_stdio(false);     input();     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (!arr[i][j] && check(point(i, j))) dfs(point(i, j));     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++)         if (arr[i][j])           cout <<  . ;         else           cout <<  * ;       cout << endl;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {}   const int maxn = (int)1e6 + 420;   const int MOD = (int)1e9 + 7;   int n;   int dp[maxn][4][4];   void contr() {     cout << 0 <<   n ;     exit(0);   }   int madd(int a, int b) {     long long sum = a + b;     sum %= MOD;     return sum;   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     string s;     cin >> s;     n = (int)s.size();     s =  .  + s;     dp[0][0][0] = 1;     for (int i = 1; i <= n; i++) {       for (int l = 0; l <= 3; l++) {         for (int m = 0; m <= 3; m++) {           for (int r = 0; r <= 3; r++) {             if ((i == 1) and !(l == 0 and m == 0)) continue;             if ((i == 2) and !(l == 0)) continue;             bool ok = true;             if (i >= 2) {               if (m == 0 and (l == 3 or r == 3)) {                 ok = false;                 continue;               }               if (m == 1 and !(l == 3 ^ r == 3)) {                 ok = false;                 continue;               }               if (m == 2 and (l != 3 or r != 3)) {                 ok = false;                 continue;               }             }             if (r == 0 and m == 3) {               ok = false;               continue;             }             if (r == 2 and m != 3) {               ok = false;               continue;             }             if (r == 1 and i == n and m != 3) {               ok = false;               continue;             }             if (r == 2 and i == n) {               ok = false;               continue;             }             vector<int> v = {r, m, l};             for (int j = 0; j < 3; j++) {               if (s[i - j] ==  ? ) continue;               if (i - j < 1) continue;               if ((v[j] == 3)) {                 if (s[i - j] !=  * ) {                   ok = false;                   continue;                 }               } else if (s[i - j] -  0  != v[j]) {                 ok = false;                 continue;               }             }             if (ok) {               dp[i][m][r] = madd(dp[i][m][r], dp[i - 1][l][m]);             }           }         }       }     }     int ans = 0;     for (int i = 0; i <= 3; i++) {       for (int j = 0; j <= 3; j++) {         ans = madd(ans, dp[n][i][j]);       }     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     int a[n], e = 0, s = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] == 1)         e++;       else         s++;     }     int ans = 0;     for (int b = 0; b < k; b++) {       int c = b, ee = e, second = s;       while (c < n) {         if (a[c] == 1)           ee--;         else           second--;         c += k;       }       ans = max(ans, abs(ee - second));     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   long long int gcd(long long int a, long long int b) {     if (a == 0)       return b;     else       return gcd(b % a, a);   }   long long int power(long long int a, long long int b, long long int m) {     long long int ans = 1;     while (b) {       if (b & 1) ans = (ans * a) % m;       b /= 2;       a = (a * a) % m;     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n, k;     cin >> n >> k;     long long int ans = 6;     if (n == 2) {       cout << ans << endl;       return 0;     }     if (k == 1 || k == n) {       ans = ans + 3 * (n - 2);     } else {       k = min(k, n - k + 1);       for (long long int i = 1; i < k - 1; i++) ans = ans + 3;       ans = ans + (k - 1);       ans = ans + 3 * (n - k);     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, b, c, d, s = 0;     cin >> n;     while (n--) {       cin >> a >> b >> c >> d;       s = s + (c - a + 1) * (d - b + 1);     }     printf( %d , s);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int T, t[200010], n;   int dp[2000][2000];   int main() {     scanf( %d , &T);     while (T--) {       scanf( %d , &n);       for (int i = 1; i <= n; ++i)         for (int j = 1; j <= n + n; ++j) dp[i][j] = (1 << 30);       for (int i = 1; i <= n; ++i) scanf( %d , &t[i]);       sort(t + 1, t + n + 1);       for (int i = 1; i <= n; ++i) {         for (int j = i; j <= n + n; ++j) {           if (j == 1) {             dp[i][j] = abs(t[i] - 1);             continue;           }           for (int k = 1; k < j; ++k) {             dp[i][j] = min(dp[i][j], dp[i - 1][k] + abs(j - t[i]));           }         }       }       int ans = (1 << 30);       for (int i = 1; i <= n + n; ++i) ans = min(ans, dp[n][i]);       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void input(T &x) {     char c = getchar();     x = 0;     for (; (c < 48 || c > 57); c = getchar())       ;     for (; c > 47 && c < 58; c = getchar()) {       x = (x << 1) + (x << 3) + c - 48;     }   }   inline long long bigmod(long long p, long long e, long long M) {     long long ret = 1;     for (; e > 0; e >>= 1) {       if (e & 1) ret = (ret * p) % M;       p = (p * p) % M;     }     return ret;   }   template <class T>   inline T gcd(T a, T b) {     if (b == 0) return a;     return gcd(b, a % b);   }   template <class T>   inline T modinverse(T a, T M) {     return bigmod(a, M - 2, M);   }   const int N = 10005;   int dp[N];   int n;   int a[N];   int main() {     input(n);     for (int i = 0; i < n; i++) input(a[i]);     long long ans = 0;     for (int round = 0; round < n; round++) {       int f = (n - round) % n;       vector<pair<int, int> > v;       v.push_back(make_pair(0, 0));       for (int j = 1; j < n; j++) {         int now = (f + j) % n;         int range = a[now];         int iMin = 1e8;         for (int k = v.size() - 1; k >= 0; k--) {           int pos = v[k].second;           if (j - range <= pos)             iMin = min(iMin, 1 + v[k].first);           else             break;         }         while (v.size() && v.back().first >= iMin) v.pop_back();         v.push_back(make_pair(iMin, j));       }       ans += v.back().first;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, M, dp[109][109][26];   vector<pair<int, char> > v[109];   void solve(int i, int j, int k) {     if (dp[i][j][k] != -1) return;     dp[i][j][k] = 0;     for (auto e : v[i])       if (e.second >= k) {         solve(j, e.first, e.second);         if (dp[j][e.first][e.second] == 0) {           dp[i][j][k] = 1;           break;         }       }   }   int main() {     scanf( %d %d , &N, &M);     while (M--) {       int x, y;       char c;       scanf( %d %d %c n , &x, &y, &c), c -=  a ;       v[x].push_back({y, c});     }     for (int k = 25; k >= 0; k--)       for (int i = 1; i <= N; i++)         for (int j = 1; j <= N; j++) dp[i][j][k] = -1;     for (int k = 25; k >= 0; k--)       for (int i = 1; i <= N; i++)         for (int j = 1; j <= N; j++) solve(i, j, k);     for (int i = 1; i <= N; i++, printf(  n ))       for (int j = 1; j <= N; j++) {         bool win = 0;         for (auto e : v[i])           if (dp[j][e.first][e.second] == 0) {             win = 1;             break;           }         if (win)           printf( A );         else           printf( B );       }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char str[999];     cin >> str;     str[0] = toupper(str[0]);     cout << str << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000009;   const int MAXN = 128;   const int MAXK = 4;   struct TrieNode {     int next[MAXK], fail;     int danger;     void init() {       fail = -1;       danger = 0;       for (int i = 0; i < MAXK; ++i) next[i] = -1;     }   } T[MAXN];   int root, Top;   void Init() {     root = 0, Top = 1;     T[root].init();   }   int GetId(char ch) {     switch (ch) {       case  A :         return 0;       case  G :         return 1;       case  C :         return 2;       case  T :         return 3;     }   }   void TrieIns(char *s) {     int i = 0;     int p = root;     while (s[i]) {       int idx = GetId(s[i]);       if (T[p].next[idx] == -1) {         T[Top].init();         T[p].next[idx] = Top++;       }       p = T[p].next[idx];       i++;     }     T[p].danger = strlen(s);   }   void Build_AC_Automation() {     int cur, tmp;     queue<int> q;     T[root].fail = root;     T[root].danger = 0;     q.push(root);     while (!q.empty()) {       cur = q.front();       q.pop();       for (int i = 0; i < MAXK; ++i) {         if (T[cur].next[i] != -1) {           tmp = T[cur].next[i];           if (cur == root)             T[tmp].fail = root;           else {             T[tmp].fail = T[T[cur].fail].next[i];             T[tmp].danger = max(T[tmp].danger, T[T[tmp].fail].danger);           }           q.push(tmp);         } else {           if (cur == root)             T[cur].next[i] = root;           else             T[cur].next[i] = T[T[cur].fail].next[i];         }       }     }   }   long long dp[1010][128][11];   int n, m;   int main() {     memset(dp, 0, sizeof(dp));     cin >> n >> m;     Init();     for (int i = 0; i < m; ++i) {       char str[20];       cin >> str;       TrieIns(str);     }     Build_AC_Automation();     dp[0][0][0] = 1;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < Top; ++j) {         for (int k = 0; k <= 10; ++k) {           if (dp[i][j][k] == 0) continue;           for (int t = 0; t < MAXK; ++t) {             int aa = T[j].next[t];             if (T[aa].danger > k) {               dp[i + 1][aa][0] += dp[i][j][k];               dp[i + 1][aa][0] %= MOD;             } else if (k + 1 <= 10) {               dp[i + 1][aa][k + 1] += dp[i][j][k];               dp[i + 1][aa][k + 1] %= MOD;             }           }         }       }     }     long long ans = 0;     for (int i = 0; i < Top; ++i) {       ans = ans + dp[n][i][0];       ans %= MOD;     }     cout << ans % MOD << endl;   }


#include <bits/stdc++.h>   using namespace std;   int digit(int n) {     int counter = 0;     while (n != 0) {       counter++;       n /= 10;     }     return counter;   }   int main() {     int T;     cin >> T;     for (int i = 0; i < T; i++) {       int n;       cin >> n;       if (n == 1) {         cout << -1 <<   n ;       } else {         cout << 5;         for (int j = 0; j < n - 1; j++) {           cout << 7;         }         cout <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   void base() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);   }   int32_t main() {     base();     int n, num;     cin >> n >> num;     int turn = 1;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (turn == j) {           cout << num <<    ;         } else {           cout << 0 <<    ;         }       }       cout << endl;       turn++;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct edge {     int v, id;     edge *next;   } * h[233333], pool[555555];   int top;   inline void addedge(int u, int v, int id) {     edge *tmp = &pool[top++];     tmp->v = v;     tmp->id = id;     tmp->next = h[u];     h[u] = tmp;     edge *pmt = &pool[top++];     pmt->v = u;     pmt->id = -id;     pmt->next = h[v];     h[v] = pmt;   }   int n, m;   int s[233333], f[233333], vis[233333], pa[233333];   void dfs(int u) {     vis[u] = 1;     for (edge *tmp = h[u]; tmp; tmp = tmp->next) {       if (tmp->v != pa[u] && !vis[tmp->v]) {         pa[tmp->v] = u;         dfs(tmp->v);         if (s[tmp->v]) {           if (tmp->id > 0)             f[tmp->id] += s[tmp->v];           else             f[-tmp->id] -= s[tmp->v];           s[u] += s[tmp->v];         }       }     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &s[i]);     scanf( %d , &m);     int u, v;     for (int i = 1; i <= m; i++) {       scanf( %d%d , &u, &v);       addedge(u, v, i);     }     for (int i = 1; i <= n; i++) {       if (!vis[i]) {         dfs(i);         if (s[i] != 0) {           printf( Impossible n );           return 0;         }       }     }     printf( Possible n );     for (int i = 1; i <= m; i++) printf( %d n , f[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, m, count = 0;     cin >> n >> m;     long long a[m];     for (long long i = 0; i < m; i++) {       cin >> a[i];       for (long long j = 0; j < i; j++) {         if (a[j] < a[i]) count++;       }     }     cout << count <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   const int N = 100001;   using namespace std;   long long a[N], sum[N];   int main() {     int n;     while (scanf( %d , &n) == 1) {       for (int i = 1; i <= n; i++) scanf( %I64d , &a[i]);       for (int i = 1, j; i < n; i++) {         for (j = 0; (1 << j) + i <= n; j++)           ;         j--;         a[i + (1 << j)] += a[i];       }       long long ans = 0;       for (int i = 1; i < n; i++) {         ans += a[i];         printf( %I64d n , ans);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int main() {     scanf( %d%d , &n, &m);     if (n == 1 && m == 2) {       printf( 0 n1 1 n1 2 n1 1 n );       return 0;     }     if (n == 2 && m == 1) {       printf( 0 n1 1 n2 1 n1 1 n );       return 0;     }     if (n * m % 2 == 1 || n == 1 || m == 1) {       printf( %d n%d %d %d %d n , 1, n, m, 1, 1);       for (int i = 1; i <= n; ++i) {         if (i % 2 == 1) {           for (int j = 1; j <= m; ++j) printf( %d %d n , i, j);         } else {           for (int j = m; j > 0; --j) printf( %d %d n , i, j);         }       }       printf( %d %d n , 1, 1);     } else if (n % 2 == 0) {       printf( 0 n1 1 n );       for (int i = 1; i <= n; ++i) {         if (i % 2 == 1) {           for (int j = 2; j <= m; ++j) printf( %d %d n , i, j);         } else {           for (int j = m; j > 1; --j) printf( %d %d n , i, j);         }       }       for (int i = n; i > 0; --i) printf( %d %d n , i, 1);     } else {       printf( 0 n1 1 n );       for (int j = 1; j <= m; ++j) {         if (j % 2 == 1) {           for (int i = 2; i <= n; ++i) printf( %d %d n , i, j);         } else {           for (int i = n; i > 1; --i) printf( %d %d n , i, j);         }       }       for (int j = m; j > 0; --j) printf( %d %d n , 1, j);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool b[123][123];   int arr[123][123];   int k[123];   int z[123];   int main() {     cin.tie(0);     ios_base::sync_with_stdio(0);     bool valid = 0, flag = 0;     pair<int, int> ans1, ans2;     int n;     cin >> n;     string s, t;     cin >> s >> t;     for (int i = 0; i < s.size(); i++) {       if (s[i] != t[i]) {         if (b[t[i] -  a ][s[i] -  a ]) {           ans2 = make_pair(arr[t[i] -  a ][s[i] -  a ] + 1, i + 1);           flag = 1;           break;         }         if (!valid) {           if (z[t[i] -  a ] == 1) {             ans1 = make_pair(k[t[i] -  a ] + 1, i + 1);             valid = 1;           } else if (z[s[i] -  a ] == 2) {             ans1 = make_pair(k[s[i] -  a ] + 1, i + 1);             valid = 1;           }         }         z[s[i] -  a ] = 1;         z[t[i] -  a ] = 2;         k[s[i] -  a ] = i;         k[t[i] -  a ] = i;         b[s[i] -  a ][t[i] -  a ] = 1;         arr[s[i] -  a ][t[i] -  a ] = i;       }     }     int h = 0;     for (int i = 0; i < s.size(); i++) {       if (s[i] != t[i]) h++;     }     if (flag) {       cout << h - 2 << endl;       cout << ans2.first <<     << ans2.second << endl;     } else if (valid) {       cout << h - 1 << endl;       cout << ans1.first <<     << ans1.second << endl;     } else {       cout << h << endl;       cout <<  -1             <<                <<  -1  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m;   long long a[100];   long long ans = 1e18;   long long po[100];   map<long long, long long> ma;   long long fun(long long left1) {     long long ans1 = 1e18;     if (left1 <= 0) {       return 0;     }     for (long long i = 0; i < n; i++) {       long long left = left1;       long long temp = 0;       if (po[i] >= left)         left = 0, temp = a[i];       else if (left % po[i] == 0) {         temp = left / po[i];         temp *= a[i];         left = 0;       } else {         temp = left / po[i];         temp *= a[i];         left = left % po[i];       }       if (ma[left] != 0)         ans1 = min(ans1, temp + ma[left]);       else {         ma[left] = fun(left);         ans1 = min(ans1, temp + ma[left]);       }     }     return ans1;   }   int main() {     cin >> n >> m;     for (long long i = 0; i < n; i++) cin >> a[i];     po[0] = 1;     for (long long i = 1; i <= 30; i++) {       po[i] = po[i - 1] * 2;     }     for (long long i = 0; i < n; i++) {       long long left = m;       long long temp;       if (po[i] >= left)         left = 0, temp = a[i];       else if (left % po[i] == 0) {         temp = left / po[i];         temp *= a[i];         left = 0;       } else {         temp = left / po[i];         temp *= a[i];         left = left % po[i];       }       ans = min(ans, temp + fun(left));     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long l, r;     cin >> l >> r;     long long temp = r;     long long num = 1, ans = 1;     while (temp) {       temp /= 10;       num *= 10;     }     num--;     long long left_lim = (num) / 10;     long long mid = (num + 1) / 2;     if (r <= mid) {       ans = (num - r) * r;     } else {       if (l <= mid) {         ans = (num - mid) * (mid);       } else {         ans = (num - l) * l;       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, i, j;     cin >> n;     cin >> m;     int A[n], B[m];     for (i = 0; i < n; i++) cin >> A[i];     for (j = 0; j < m; j++) cin >> B[j];     for (j = 0; j < n; j++) {       for (i = 0; i < m; i++) {         if (A[j] == B[i]) cout << A[j] <<    ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, k, x, s, a[200005], b[200005], c[200005], d[200005], ans;   int bfind(int t) {     int lo = 0, hi = k - 1, mid;     while (lo < hi) {       mid = lo + (hi - lo + 1) / 2;       if (d[mid] > t)         hi = mid - 1;       else         lo = mid;     }     return lo;   }   int main() {     cin >> n >> m >> k >> x >> s;     for (int i = 0; i < m; i++) scanf( %I64d , &a[i]);     for (int i = 0; i < m; i++) scanf( %I64d , &b[i]);     for (int i = 0; i < k; i++) scanf( %I64d , &c[i]);     for (int i = 0; i < k; i++) scanf( %I64d , &d[i]);     ans = x * n;     for (int i = 0; i < m; i++) {       if (b[i] <= s) ans = min(ans, a[i] * n);     }     for (int i = 0; i < k; i++) {       if (d[i] <= s) ans = min(ans, x * (n - c[i]));     }     for (int i = 0; i < m; i++) {       if (b[i] + d[0] <= s) {         int idx = bfind(s - b[i]);         ans = min(ans, a[i] * (n - c[idx]));       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-10;   const int maxn = 100 + 10;   int n, m;   int a[maxn], b[maxn];   bitset<65> tt1[50000], tt2[50000];   vector<int> v;   map<int, int> mp;   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < m; i++) cin >> b[i];     bitset<65> *t1 = tt1 + 25000, *t2 = tt2 + 25000;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         t1[a[i] + b[j]][i] = 1;         t2[a[i] + b[j]][j] = 1;         if (!mp[a[i] + b[j]]) {           mp[a[i] + b[j]] = 1;           v.push_back(a[i] + b[j]);         }       }     }     int mine = -1;     for (int i = 0; i < v.size(); i++) {       for (int j = 0; j < v.size(); j++) {         int sum = (t1[v[i]] | t1[v[j]]).count() + (t2[v[i]] | t2[v[j]]).count();         if (sum > mine) mine = sum;       }     }     printf( %d n , mine);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[2001000];   int Partition(int l, int r) {     int temp = l + rand() % (r - l);     swap(a[l], a[temp]);     int x = a[l], i = l - 1, j = r + 1;     while (1) {       do i++;       while (a[i] < x);       do j--;       while (a[j] > x);       if (i < j)         swap(a[i], a[j]);       else         return j;     }   }   void QuickSort(int l, int r) {     if (l < r) {       int q = Partition(l, r);       QuickSort(l, q);       QuickSort(q + 1, r);     }   }   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     QuickSort(0, n - 1);     for (int i = 0, j = n - 1; i < j; i++, j--) swap(a[i], a[j]);     long long k = 0;     for (int i = 0; pow(4, i) <= n + 1; i++)       for (int j = 0; j < pow(4, i); j++) k += a[j];     cout << k << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T sqr(const T &a) {     return a * a;   }   template <typename T>   inline int nread(vector<T> &a) {     int n;     cin >> n;     a.clear();     a.resize(n);     for (int i = 0; i < n; i++) cin >> a[i];     return n;   }   template <typename T>   inline void nwread(int n, vector<T> &a) {     a.clear();     a.resize(n);     for (int i = 0; i < n; i++) cin >> a[i];   }   const int N = 3001;   int gr[N][N], cg[N];   int res[N * N];   pair<int, int> que[N * N];   int main() {     int n, m, k;     cin >> n >> m >> k;     for (int i = 0; i < n; i++) cg[i] = 0;     for (int i = 0; i < m; i++) {       int x, y;       scanf( %d%d , &x, &y);       x--;       y--;       gr[x][cg[x]++] = y;       gr[y][cg[y]++] = x;     }     set<pair<pair<int, int>, int> > zapr;     for (int i = 0; i < k; i++) {       int x, y, z;       scanf( %d%d%d , &x, &y, &z);       x--;       y--;       z--;       zapr.insert(make_pair(make_pair(x, y), z));     }     map<pair<int, int>, int> path;     int qi = 0, qj = 1;     que[0] = make_pair(-1, 0);     while (qi < qj) {       pair<int, int> tek = que[qi++];       int pv = tek.first, tv = tek.second;       vector<int> nreb;       for (int i = 0; i < cg[tv];) {         int fv = gr[tv][i];         if (zapr.count(make_pair(tek, fv)))           i++;         else {           que[qj++] = make_pair(tv, fv);           path[make_pair(tv, fv)] = pv;           if (fv == n - 1) {             int lr = 2;             res[0] = fv;             res[1] = tv;             while (tv != 0) {               pv = path[make_pair(tv, fv)];               res[lr++] = pv;               fv = tv;               tv = pv;             }             reverse(res, res + lr);             cout << lr - 1 << endl;             for (int i = 0; i < lr; i++) printf( %d  , res[i] + 1);             return 0;           }           if (cg[tv]) gr[tv][i] = gr[tv][cg[tv] - 1];           cg[tv]--;         }       }     }     cout << -1;   }


#include <bits/stdc++.h>   using namespace std;   int a[210000];   long long dp[210000][2];   const long long INF = 1LL << 60;   int N;   void init() {     for (int i = 0; i < 210000; i++)       for (int j = 0; j < 2; j++) dp[i][j] = INF;   }   long long solve(int x, bool t) {     if (x <= 0 || x > N) return 0;     if (x == 1) return -1;     if (dp[x][t] == -INF) return dp[x][t] = -1;     if (dp[x][t] != INF) return dp[x][t];     dp[x][t] = -INF;     int i2 = x;     if (t)       i2 += a[x];     else       i2 -= a[x];     long long r = solve(i2, !t);     long long res;     if (r == -1)       res = -1;     else       res = a[x] + r;     return dp[x][t] = res;   }   int main() {     cin >> N;     for (int i = 2; i <= N; i++) cin >> a[i];     init();     for (int i = 1; i < N; i++) {       long long ret = solve(1 + i, false);       if (~ret) ret += i;       cout << ret << endl;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse4 )   using namespace std;   using ii = pair<int, int>;   using ll = long long;   const int N = 1e5 + 5;   const int mod = 1e9 + 7;   char str1[50005], str2[50005];   int n, m;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> str1;     n = strlen(str1);     for (int sz = 1; sz <= n / 2; sz++) {       m = sz;       int cur = 0;       for (int i = sz; i < n; i++) {         if (str1[i] == str1[i - sz])           cur++;         else           cur = 0;         str2[m++] = str1[i];         if (cur == sz) cur = 0, m -= sz;       }       for (int i = sz; i < m; i++) str1[i] = str2[i];       n = m;     }     for (int i = 0; i < n; i++) cout << str1[i];     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const double pi = 3.1415926535897;   int main() {     double d, h, v, e;     cin >> d >> h >> v >> e;     double s = (-1 * h) / (e - ((4 * v) / (pi * d * d)));     if (s >= 0)       cout <<  YES  << endl << s;     else       cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   void per() { cerr << endl; }   template <typename Head, typename... Tail>   void per(Head H, Tail... T) {     cerr << H <<    ;     per(T...);   }   template <class T>   bool uin(T& a, T b) {     return a > b ? (a = b, true) : false;   }   template <class T>   bool uax(T& a, T b) {     return a < b ? (a = b, true) : false;   }   template <class U, class V>   ostream& operator<<(ostream& out, const pair<U, V>& a) {     return out <<  (  << a.first <<  ,   << a.second <<  ) ;   }   template <class U, class V>   istream& operator>>(istream& in, pair<U, V>& a) {     return in >> a.first >> a.second;   }   template <typename W,             typename T = typename enable_if<!is_same<W, string>::value,                                             typename W::value_type>::type>   ostream& operator<<(ostream& out, const W& v) {     out <<  {  ;     for (const auto& first : v) out << first <<  ,  ;     return out <<  } ;   }   template <class T>   void readArr(T from, T to) {     for (auto i = from; i != to; ++i) cin >> *i;   }   mt19937 mrand(1337);   unsigned int myRand32() { return mrand() & (unsigned int)(-1); }   unsigned long long myRand64() {     return ((unsigned long long)myRand32() << 32) ^ myRand32();   }   const int mod = 1000000007;   void add(int& a, int b) {     a += b;     if (a >= mod) a -= mod;   }   void dec(int& a, int b) {     a -= b;     if (a < 0) a += mod;   }   int mult(int a, int b) { return a * (long long)b % mod; }   int bp(int a, int b) {     int res = 1;     while (b > 0) {       if (b & 1) res = mult(res, a);       a = mult(a, a);       b >>= 1;     }     return res;   }   int main() {     int vl = 1, vr = 1000000000;     cout <<  ? 1 1  << endl;     int base1;     cin >> base1;     while (vl + 1 < vr) {       int vm = (vl + vr) >> 1;       cout <<  ? 1   << vm << endl;       int first;       cin >> first;       if (first == base1 - (vm - 1))         vl = vm;       else         vr = vm;     }     int y1 = vl;     int x1 = base1 - (y1 - 1) + 1;     cout <<  ? 1000000000 1  << endl;     int base2;     cin >> base2;     int x2 = 1000000000 - (base2 - (y1 - 1));     cout <<  ? 1 1000000000  << endl;     int base3;     cin >> base3;     int y2 = 1000000000 - (base3 - (x1 - 1));     cout <<  !   << x1 <<     << y1 <<     << x2 <<     << y2 << endl;   }


#include <bits/stdc++.h>   int main() {     int i, j, k, n, t, c1, c2, c3, c4, c5;     scanf( %d%d%d%d%d , &c1, &c2, &c3, &c4, &c5);     t = c1 + c2 + c3 + c4 + c5;     if (t == 0)       printf( -1 n );     else if (t % 5 == 0)       printf( %d n , t / 5);     else       printf( -1 n );   }