#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 4;   int n, c[maxn];   string s[maxn];   long long dp[maxn][2];   long long best(int ind, bool rev) {     if (ind == n) {       return 0;     }     if (dp[ind][rev] != -1) {       return dp[ind][rev];     }     string t = s[ind - 1];     if (rev) {       reverse(t.begin(), t.end());     }     string v = s[ind];     reverse(v.begin(), v.end());     if (s[ind] < t && v < t) {       return dp[ind][rev] = 1e17;     }     if (s[ind] >= t && v >= t) {       return dp[ind][rev] =                  min(c[ind] + best(ind + 1, true), best(ind + 1, false));     }     if (s[ind] >= t) {       return dp[ind][rev] = best(ind + 1, false);     }     return dp[ind][rev] = c[ind] + best(ind + 1, true);   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> c[i];     }     for (int i = 0; i < n; i++) {       cin >> s[i];     }     memset(dp, -1, sizeof dp);     long long res1 = c[0] + best(1, true);     long long res2 = best(1, false);     long long res = min(res1, res2);     if (res > 1e15) {       res = -1;     }     cout << res;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T abs(T x) {     return x < 0 ? -x : x;   }   const double EPS = 1e-9;   int n, m, a[55], b[55], mx, ans, x;   double cur;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %d , a + i);     scanf( %d , &m);     for (int i = 0; i < m; ++i) scanf( %d , b + i);     mx = 0;     ans = 0;     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) {         cur = (b[j] + 0.) / a[i];         if (abs((int)cur - cur) < EPS) {           x = (int)cur;           if (x > mx) {             mx = x;             ans = 1;           } else if (x == mx)             ++ans;         }       }     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> get(int n) {     if (n == 1) {       return {1};     }     if (n == 2) {       return {3, 4};     }     vector<int> a;     if (n % 2 == 0) {       int k = n / 2;       for (int i = 1; i <= 2 * k - 1; i++) {         a.push_back(1);       }       a.push_back(k - 1);     } else {       int k = n / 2;       for (int i = 1; i <= 2 * k - 1; i++) {         a.push_back(1);       }       a.push_back(2);       a.push_back(k + 1);     }     return a;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     vector<int> a = get(n), b = get(m);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cout << a[i] * b[j] <<    ;       }       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     string a;     vector<string> v, b;     bool u = false, l = false;     for (int i = 0; i < 4 * n; i++) {       cin >> a;       int k = 0;       u = false;       for (int j = (int)a.length() - 1; j >= 0; j--) {         if (a[j] ==  a  || a[j] ==  e  || a[j] ==  i  || a[j] ==  o  ||             a[j] ==  u )           k++;         if (k >= m) {           v.push_back(a.substr(j));           u = true;           break;         }       }       if (!u) {         l = true;       }     }     if (l) {       cout <<  NO ;       return 0;     }     for (int i = 0; i < n; i++) {       if (v[i * 4] == v[i * 4 + 1] && v[i * 4 + 1] == v[i * 4 + 2] &&           v[i * 4 + 2] == v[i * 4 + 3]) {         continue;       }       if (v[i * 4] == v[i * 4 + 1] && v[i * 4 + 2] == v[i * 4 + 3]) {         b.push_back( aabb );         continue;       }       if (v[i * 4 + 0] == v[i * 4 + 3] && v[i * 4 + 1] == v[i * 4 + 2]) {         b.push_back( abba );         continue;       }       if (v[i * 4 + 0] == v[i * 4 + 2] && v[i * 4 + 1] == v[i * 4 + 3]) {         b.push_back( abab );         continue;       }       cout <<  NO ;       return 0;     }     if ((int)b.size() == 0) {       cout <<  aaaa ;       return 0;     }     bool h = true;     for (int i = 1; i < (int)b.size(); i++) {       if (b[i] != b[i - 1]) {         h = false;         break;       }     }     if (h)       cout << b[0];     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());   template <typename T>   bool uax(T& a, T b) {     if (a < b) {       a = b;       return true;     }     return false;   }   template <typename T>   bool uin(T& a, const T b) {     if (a > b) {       a = b;       return true;     }     return false;   }   template <typename T1, typename T2>   istream& operator>>(istream& in, pair<T1, T2>& p) {     in >> p.first >> p.second;     return in;   }   template <typename T1, typename T2>   ostream& operator<<(ostream& out, pair<T1, T2>& p) {     out << p.first <<     << p.second;     return out;   }   const int N = 200 + 7;   int n;   vector<int> g[N];   vector<int> p[N];   int sz[N];   int ans[N];   vector<int> wr;   int s[N];   bool used[N];   int last_ind = 0;   int arr[N];   void del(int x) {     used[x] = true;     for (int i = 0; i < p[x].size(); i++) {       s[p[x][i]]--;       if (s[p[x][i]] == 1) {         arr[last_ind++] = p[x][i];       }     }   }   bool solve(int x) {     last_ind = 0;     for (int i = 0; i <= n; i++) {       s[i] = sz[i];       used[i] = false;     }     ans[0] = x;     del(x);     for (int i = 1; i < n; i++) {       if (last_ind != 1) {         return false;       }       int ind = arr[0];       int cur = 0;       for (int j = 0; j < g[ind].size(); j++) {         if (!used[g[ind][j]]) cur = g[ind][j];       }       ans[i] = cur;       wr.clear();       for (int j = 0; j < sz[ind]; j++) {         wr.push_back(ans[i - j]);       }       sort(wr.begin(), wr.end());       for (int j = 0; j < g[ind].size(); j++) {         if (g[ind][j] != wr[j]) return false;       }       last_ind = 0;       del(cur);     }     for (int i = 0; i < n; i++) {       cout << ans[i] <<    ;     }     cout <<   n ;     return true;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long T;     cin >> T;     while (T--) {       fill(p, p + n + 1, vector<int>());       cin >> n;       int k;       for (int i = 0; i < n - 1; i++) {         cin >> k;         g[i].resize(k);         sz[i] = k;         for (int j = 0; j < k; j++) {           cin >> g[i][j];           p[g[i][j]].push_back(i);         }       }       for (int i = 1; i <= n; i++) {         if (solve(i)) {           break;         }       }     }   }


#include <bits/stdc++.h>   int query(long long q) {     printf( ? %lld n , q);     fflush(stdout);     int gcd;     scanf( %d , &gcd);     return gcd;   }   void printAnswer(int answer) {     printf( ! %d n , answer);     fflush(stdout);   }   const int MAX_PRIMES = 617;   const int MAX_X = 1000 * 1000 * 1000;   const long long MAX_QUERY = 1000LL * 1000LL * 1000LL * 1000LL * 1000LL * 1000LL;   bool isPrime[1 + MAX_PRIMES];   int main() {     for (int i = 2; i <= MAX_PRIMES; i++) {       isPrime[i] = true;     }     std::vector<long long> queries;     queries.push_back(1);     for (int p = 2; p <= MAX_PRIMES; p++) {       if (isPrime[p]) {         for (int m = p * p; m <= MAX_PRIMES; m += p) {           isPrime[m] = false;         }         if (queries.back() <= MAX_QUERY / p) {           long long b = queries.back();           queries.pop_back();           queries.push_back(b * p);         } else {           queries.push_back(p);         }       }     }     int t;     scanf( %d , &t);     for (int _ = 0; _ < t; _++) {       std::vector<int> primeDivs;       for (long long q : queries) {         int gcd = query(q);         for (int p = 2; p <= MAX_PRIMES; p++) {           if (gcd % p == 0) {             primeDivs.push_back(p);             while (gcd % p == 0) {               gcd /= p;             }           }         }       }       for (int &p : primeDivs) {         int copy = p;         while (p <= MAX_X / copy) {           p *= copy;         }       }       if (primeDivs.size() % 2 == 1) {         primeDivs.push_back(1);       }       int sureAnswer = 1;       for (int i = 0; i < (int)primeDivs.size(); i += 2) {         long long q = (long long)primeDivs[i] * primeDivs[i + 1];         int gcd = query(q);         for (int p = 2; p <= MAX_PRIMES; p++) {           int exp = 0;           while (gcd % p == 0) {             gcd /= p;             exp++;           }           sureAnswer *= exp + 1;         }       }       int guessAnswer = std::max(sureAnswer + 7, sureAnswer * 2);       printAnswer(guessAnswer);       primeDivs.clear();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long ar[500005];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %lld , &ar[i]);     }     string s;     cin >> s;     long long gain = 0;     long long loss = 0;     long long bob = 0;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  B ) {         bob += ar[i];       }     }     long long ma = 0;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  A ) {         gain += ar[i];       } else {         loss += ar[i];       }       ma = max(ma, gain - loss);     }     gain = 0;     loss = 0;     for (int i = s.length() - 1; i >= 0; i--) {       if (s[i] ==  A ) {         gain += ar[i];       } else {         loss += ar[i];       }       ma = max(ma, gain - loss);     }     bob += ma;     printf( %lld , bob);   }


#include <bits/stdc++.h>   using namespace std;   const int MX = 100 + 3;   int n, m, k;   bool mat[MX][MX], tmp[MX][MX];   void solve1() {     int q = (1 << m);     int cnt = 0;     int ans = 20;     for (int z = 0; z < q; z++) {       cnt = 0;       memset(tmp, false, sizeof(tmp));       for (int j = 0; j < m; j++) {         if (z & (1 << j)) tmp[0][j] = true;         if (tmp[0][j] != mat[0][j]) cnt++;       }       for (int i = 1; i < n; i++) {         int p = 0;         for (int j = 0; j < m; j++) {           tmp[i][j] = !tmp[i - 1][j];           if (tmp[i][j] != mat[i][j]) p++;         }         p = min(p, m - p);         cnt += p;       }       ans = min(cnt, ans);     }     if (ans > k)       cout << -1 << endl;     else       cout << ans << endl;     exit(0);   }   void swp() {     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) tmp[i][j] = mat[i][j];     for (int i = 0; i < m; i++)       for (int j = 0; j < n; j++) mat[i][j] = tmp[j][i];     swap(n, m);   }   void solve2() {     int ans = 20;     int cnt = 0;     if (n > k) {       for (int i = 0; i < n; i++) {         cnt = 0;         memset(tmp, false, sizeof(tmp));         for (int j = 0; j < m; j++) tmp[i][j] = mat[i][j];         for (int k = 0; k < n; k++) {           if (k != i) {             int p = 0;             for (int j = 0; j < m; j++) {               tmp[k][j] = !tmp[i][j];               if (tmp[k][j] != mat[k][j]) p++;             }             p = min(p, m - p);             cnt += p;           }         }         ans = min(ans, cnt);       }     } else {       swp();       memset(tmp, false, sizeof(tmp));       for (int i = 0; i < n; i++) {         cnt = 0;         for (int j = 0; j < m; j++) tmp[i][j] = mat[i][j];         for (int k = 0; k < n; k++) {           if (k != i) {             int p = 0;             for (int j = 0; j < m; j++) {               tmp[k][j] = !tmp[i][j];               if (tmp[k][j] != mat[k][j]) p++;             }             p = min(p, m - p);             cnt += p;           }         }         ans = min(ans, cnt);       }     }     if (ans <= k)       cout << ans << endl;     else       cout << -1 << endl;     exit(0);   }   int main() {     cin >> n >> m >> k;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) cin >> mat[i][j];     if (n <= k && m <= k)       solve1();     else       solve2();     return 0;   }


#include <bits/stdc++.h>   const int Maxn = 500000;   int n;   struct Answer {     int l, r;   } a[Maxn + 5];   int len;   void work(int left, int right) {     if (left == right) {       return;     }     int mid = (left + right) >> 1;     work(left, mid);     work(mid + 1, right);     for (int i = left; i <= mid; i++) {       a[++len].l = i;       a[len].r = mid + (i - left + 1);     }   }   int main() {     scanf( %d , &n);     if (n <= 2) {       puts( 0 );       return 0;     }     int lim = 1;     while (lim <= n) {       lim <<= 1;     }     lim >>= 1;     work(1, lim);     int m = n - lim;     if (m > 0) {       int sz = 1;       while (sz < m) {         sz <<= 1;       }       work(n - sz + 1, n);     }     printf( %d n , len);     for (int i = 1; i <= len; i++) {       printf( %d %d n , a[i].l, a[i].r);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class c>   struct rge {     c b, e;   };   template <class c>   rge<c> range(c i, c j) {     return rge<c>{i, j};   }   template <class c>   auto dud(c* x) -> decltype(cerr << *x, 0);   template <class c>   char dud(...);   struct debug {     template <class c>     debug& operator<<(const c&) {       return *this;     }   };   void solve() {     long long n, m;     cin >> n >> m;     long long ost = m % 10;     set<int> o;     for (int i = 0; i <= 10; ++i) {       o.insert((i * ost) % 10);     }     long long sum = 0;     for (auto x : o) sum += x;     long long d = n / m;     if (n == 0)       cout << 0 <<   n ;     else {       long long res = sum * (d / o.size());       for (int i = 0; i < (d % o.size()); ++i) {         res += ((i + 1) * m) % 10;       }       cout << res <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   long long t[100005], T[100005], x[100005], c[100005];   long long n, m;   int main() {     while (scanf( %lld%lld , &n, &m) != EOF) {       int i;       int a, b;       long long sum = 0;       for (i = 1; i <= n; i++)         scanf( %lld%lld%lld%lld , &t[i], &T[i], &x[i], &c[i]);       for (i = 1; i <= n; i++) {         if (t[i] >= T[i]) {           sum += (c[i] + x[i] * m);         } else {           if (t[i] + m <= T[i])             sum += c[i];           else {             long long a, b;             long long cha = T[i] - t[i];             long long d = m % (T[i] - t[i]);             long long w = m / (T[i] - t[i]);             if (d)               a = (w + 1) * c[i];             else               a = (w * c[i]);             b = x[i] * m + c[i];             sum += min(a, b);           }         }       }       printf( %I64d n , sum);     }   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   struct myHash {     template <class T1, class T2>     size_t operator()(const pair<T1, T2>& p) const {       auto hash1 = hash<T1>{}(p.first);       auto hash2 = hash<T2>{}(p.second);       return hash1 ^ hash2;     }   };   class segTree {     vector<long long int> a;     vector<long long int> tree;     vector<long long int> lazy;     long long int sel;     long long int minRange(long long int left, long long int right) {       return min(left, right);     }     long long int maxRange(long long int left, long long int right) {       return max(left, right);     }     long long int rangeSum(long long int left, long long int right) {       return left + right;     }     void build(long long int index, long long int start, long long int end) {       if (start > end) {         return;       }       if (start == end) {         tree[index] = a[start];         return;       }       long long int mid = (start + end) / 2;       build(2 * index, start, mid);       build(2 * index + 1, mid + 1, end);       long long int left = tree[2 * index];       long long int right = tree[2 * index + 1];       if (sel == 0) {         tree[index] = minRange(tree[2 * index], tree[2 * index + 1]);       } else if (sel == 1) {         tree[index] = maxRange(tree[2 * index], tree[2 * index + 1]);       } else if (sel == 2) {         tree[index] = rangeSum(tree[2 * index], tree[2 * index + 1]);       }     }     long long int query(long long int index, long long int start,                         long long int end, long long int l, long long int r) {       if (lazy[index] != 0) {         if (sel == 0) {           tree[index] += lazy[index];         } else if (sel == 1) {           tree[index] += lazy[index];         } else if (sel == 2) {           tree[index] += (end - start + 1) * lazy[index];         }         if (start != end) {           lazy[2 * index] += lazy[index];           lazy[2 * index + 1] += lazy[index];         }         lazy[index] = 0;       }       if (l > end || r < start) {         if (sel == 0) {           return LLONG_MAX;         } else if (sel == 1) {           return LLONG_MIN;         } else if (sel == 2) {           return 0;         }       }       if (start >= l && end <= r) {         return tree[index];       }       long long int mid = (start + end) / 2;       long long int left = query(2 * index, start, mid, l, r);       long long int right = query(2 * index + 1, mid + 1, end, l, r);       if (sel == 0) {         return minRange(left, right);       } else if (sel == 1) {         return maxRange(left, right);       } else if (sel == 2) {         return rangeSum(left, right);       }     }     void update(long long int index, long long int start, long long int end,                 long long int l, long long int r, long long int inc) {       if (lazy[index] != 0) {         if (sel == 0) {           tree[index] += lazy[index];         } else if (sel == 1) {           tree[index] += lazy[index];         } else if (sel == 2) {           tree[index] += (r - l + 1) * lazy[index];         }         if (start != end) {           lazy[2 * index] += lazy[index];           lazy[2 * index + 1] += lazy[index];         }         lazy[index] = 0;       }       if (l <= start and end <= r) {         if (sel == 0) {           tree[index] += inc;         } else if (sel == 1) {           tree[index] += inc;         } else {           tree[index] += (end - start + 1) * inc;         }         if (start != end) {           lazy[2 * index] += inc;           lazy[2 * index + 1] += inc;         }         return;       }       if (r < start || l > end) {         return;       }       if (start == end) {         tree[index] += inc;         return;       }       long long int mid = (start + end) / 2;       update(2 * index, start, mid, l, r, inc);       update(2 * index + 1, mid + 1, end, l, r, inc);       if (sel == 0) {         tree[index] = minRange(tree[2 * index], tree[2 * index + 1]);       } else if (sel == 1) {         tree[index] = maxRange(tree[2 * index], tree[2 * index + 1]);       } else if (sel == 2) {         tree[index] = rangeSum(tree[2 * index], tree[2 * index + 1]);       }     }       public:     segTree(vector<long long int> a, long long int sel) {       this->a = a;       tree.reserve(4 * a.size() + 1);       lazy.reserve(4 * a.size() + 1);       for (int i = 0; i < 4 * a.size() + 1; i++) {         lazy[i] = 0;       }       this->sel = sel;     }     void build() { build(1, 0, a.size() - 1); }     long long int query(long long int l, long long int r) {       return query(1, 0, a.size() - 1, l, r);     }     void update(long long int l, long long int r, long long int inc) {       update(1, 0, a.size() - 1, l, r, inc);     }     void update(long long int pos, long long int inc) { update(pos, pos, inc); }   };   long long int power(long long int b, long long int p,                       long long int m = 1000000007) {     long long int res = 1;     while (p > 0) {       if (p & 1) {         res = (res * b) % m;       }       b = (b * b) % m;       p = p >> 1;     }     return res;   }   long long int modInverse(long long int n, long long int m = 1000000007) {     return power(n, m - 2, m);   }   bool mySort(pair<int, int> p1, pair<int, int> p2) {     if (p1.first < p2.first) {       return true;     } else if (p1.first == p2.first and p1.second < p2.second) {       return true;     }     return false;   }   long long int lis(vector<long long int>& v) {     long long int n = v.size();     vector<long long int> dp(n);     dp[0] = 1;     long long int ans = 1;     for (int i = 1; i < n; i++) {       long long int m = 0;       for (int j = i - 1; j >= 0; j--) {         if (v[j] < v[i]) {           m = max(m, dp[j]);         }       }       dp[i] = 1 + m;       if (ans < dp[i]) {         ans = dp[i];       }     }     return ans;   }   vector<long long int> sieve(long long int n) {     vector<bool> v(n + 1, false);     v[2] = true;     for (int i = 3; i <= n; i += 2) {       v[i] = true;     }     for (int i = 3; i <= n; i += 2) {       if (v[i]) {         for (int j = i * i; j <= n; j += 2 * i) {           v[j] = false;         }       }     }     v[1] = false;     v[0] = false;     vector<long long int> primes;     for (int i = 0; i < v.size(); i++) {       if (v[i]) {         primes.push_back(i);       }     }     return primes;   }   long long int gcd(long long int a, long long int b) {     while (b > 0) {       long long int r = a % b;       a = b;       b = r;     }     return a;   }   long long int lcm(long long int a, long long int b) {     long long int g = gcd(a, b);     return (a * b) / g;   }   vector<long long int> segSieve(long long int l, long long int r) {     long long int lim = sqrt(r);     if (l < 2) {       l = 2;     }     vector<long long int> s = sieve(lim);     vector<bool> v(r - l + 1, true);     for (long long int i = 0; i < s.size(); i++) {       for (long long int j = 0; j < v.size(); j++) {         if ((j + l) % s[i] == 0 && (j + l) != s[i]) {           v[j] = false;         }       }     }     vector<long long int> primes;     for (int i = 0; i < v.size(); i++) {       if (v[i]) {         primes.push_back(i + l);       }     }     return primes;   }   vector<pair<long long int, long long int>> primeFactors(long long int n) {     vector<long long int> primes = sieve(sqrt(n));     long long int p = primes[0];     vector<pair<long long int, long long int>> f;     int i = 0;     while (p * p <= n) {       long long int count = 0;       while (n % p == 0) {         count++;         n /= p;       }       if (count > 0) {         f.push_back(make_pair(p, count));       }       i++;       p = primes[i];     }     if (n > 1) {       f.push_back(make_pair(n, 1));     }     return f;   }   vector<long long int> factors(long long int n) {     long long int lim = sqrt(n);     vector<long long int> f;     for (int i = 2; i <= lim; i++) {       if (n % i == 0) {         f.push_back(i);         f.push_back(n / i);       }     }     return f;   }   long long int ceilAB(long long int a, long long int b) {     return (a + b - 1) / b;   }   long long int low_bound(vector<long long int>& v, long long int start,                           long long int end, long long int n) {     if (start > end) {       return -1;     }     long long int mid = (start + end) / 2;     if (v[mid] == n) {       return mid;     } else if (v[mid] > n) {       long long int index = low_bound(v, start, mid - 1, n);       return index;     } else {       long long int index = low_bound(v, mid + 1, end, n);       if (index == -1) {         return mid;       }       return index;     }   }   void fastIO() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   int main(void) {     long long int n;     cin >> n;     string s;     cin >> s;     cout << n + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char ss[100050];   char b[12][12];   int len[12];   int n, m;   bool g[100050][11];   bool f[100050][11];   int dp[100050];   struct Node {     int a, b;   };   int main() {     int ll, pos;     bool tmp;     scanf( %s , ss);     n = strlen(ss);     scanf( %d , &m);     for (int i = 0; i < m; i++) {       scanf( %s , b[i]);       len[i] = strlen(b[i]);     }     memset(f, false, sizeof(f));     for (int i = 0; i < n; i++) {       for (int j = 1; j <= 10 && i - j + 1 >= 0; j++) f[i][j] = true;       for (int j = 0; j < m; j++) {         if (i + 1 >= len[j]) {           tmp = true;           for (int k = 0; k < len[j]; k++) {             if (ss[i + k + 1 - len[j]] != b[j][k]) {               tmp = false;               break;             }           }           if (tmp) f[i][len[j]] = false;         }       }       if (!i)         dp[i] = 1;       else         dp[i] = dp[i - 1] + 1;       for (int j = 1; j <= 10 && i + 1 >= j; j++)         if (!f[i][j]) {           dp[i] = j - 1;           break;         }     }     Node ans;     ans.a = ans.b = 0;     pos = 0;     for (int i = 0; i < n; i++) {       pos = max(pos, i - dp[i] + 1);       if (i - pos + 1 > 0 && i - pos + 1 >= ans.b) {         ans.a = pos;         ans.b = i - pos + 1;       }     }     printf( %d %d n , ans.b, ans.a);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       string s1;       cin >> s1;       int p1 = 0, p2 = 0, c1, c2;       set<pair<pair<int, int>, pair<int, int> > > s;       int c = 0;       for (int i = 0; i < s1.size(); i++) {         if (s1[i] ==  N ) {           c2 = p2 + 1;           c1 = p1;         } else if (s1[i] ==  S ) {           c2 = p2 - 1;           c1 = p1;         } else if (s1[i] ==  E ) {           c1 = p1 + 1;           c2 = p2;         } else if (s1[i] ==  W ) {           c1 = p1 - 1;           c2 = p2;         }         if (s.find(make_pair(make_pair(c1, c2), make_pair(p1, p2))) != s.end() ||             s.find(make_pair(make_pair(p1, p2), make_pair(c1, c2))) != s.end()) {           c = c + 1;         } else {           c = c + 5;           s.insert(make_pair(make_pair(p1, p2), make_pair(c1, c2)));         }         p1 = c1;         p2 = c2;       }       cout << c <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   long long ans;   long long cnt(long long i, long long n, long long count) {     long long c = 0, j = i, k = n;     while (k / i > 0) {       c += k / i;       k /= i;     }     c /= count;     return c;   }   void factorize(long long n, long long p) {     long long count = 0;     while (!(n % 2)) {       n >>= 1;       count++;     }     if (count) {       ans = min(ans, cnt(2, p, count));     }     long long y = n;     for (long long int i = 3; i * i <= y; i++) {       count = 0;       while (n % i == 0) {         count++;         n = n / i;       }       if (count) {         ans = min(ans, cnt(i, p, count));       }     }     if (n > 2) {       ans = min(ans, cnt(n, p, 1));     }     return;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long n, b;     cin >> n >> b;     ans = LLONG_MAX;     factorize(b, n);     if (ans != LLONG_MAX)       cout << ans << endl;     else       cout << 0 << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long N, K;   long long s1, s2, p1, p2;   long long Get(long long now, long long to) {     if (now <= to << 1) return 0;     long long re = 0;     s1 = 1;     s2 = 0;     p1 = now;     p2 = now - 1;     while (p2 >= to << 1) {       if (p2 == to << 1) return s1 + re;       if (p1 & 1) {         re += s1 + s2;         s1 = (s1 << 1) + s2;       } else {         re += s1 + s2;         s2 = (s2 << 1) + s1;       }       p2 = (p1 >> 1) - 1;       p1 = (p1 >> 1);     }     return re;   }   long long solve(long long l, long long r, long long p, long long k) {     long long mid = (l + r) >> 1;     if (k == 1) return mid;     long long tmp = Get(mid - l, p), Tmp = Get(r - mid, p + 1);     if (k > tmp + Tmp + 1)       return solve(mid + 1, r, p, k - tmp - 1);     else       return solve(l, mid - 1, p, k - Tmp - 1);   }   int main() {     scanf( %lld%lld , &N, &K);     if (K == 1) {       printf( 1 );       return 0;     }     if (K == 2) {       printf( %lld , N);       return 0;     }     N -= 2;     K -= 2;     long long l = 0, r = (N >> 1) + 1;     while (r - l > 1) {       long long mid = (l + r) >> 1;       if (Get(N, mid) < K)         r = mid;       else         l = mid;     }     printf( %lld , solve(1, N, l, K) + 1);   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2000001;   int N, M, cur, F, a[maxn], del[maxn];   int c[maxn];   inline int lowbit(int x) { return x & -x; }   inline void add(int x, int d) {     for (; x < maxn; x += lowbit(x)) {       c[x] += d;     }   }   inline int seek(int k) {     int ans = 0, sum = 0;     for (int i = 23; i >= 0; i--) {       ans += 1 << i;       if (ans > maxn || sum + c[ans] >= k)         ans -= 1 << i;       else         sum += c[ans];     }     return ans + 1;   }   int main() {     scanf( %d%d , &M, &N);     for (int i = 1; i <= N; ++i) {       scanf( %d , &del[i]);     }     while (M--) {       int d;       scanf( %d , &d);       if (d == -1) {         int x = upper_bound(del + 1, del + N + 1, cur) - del;         for (int i = x - 1; i > 0; --i) {           cur--;           int t = seek(del[i]);           add(t, -1);           a[t] = -1;         }       } else {         cur++;         add(++F, 1);         a[F] = d;       }     }     if (cur == 0) {       printf( Poor stack! n );     } else {       for (int i = 1; i <= cur; ++i) {         printf( %d , a[seek(i)]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dx[] = {-1, 1, 0, 0};   int dy[] = {0, 0, -1, 1};   long long int sizes[100001];   long long int arr[100001];   bool ok = true;   long long int A[100001];   pair<long long int, long long int> B[100001];   long long int root(long long int i) {     while (i != arr[i]) i = arr[i];     return (i);   }   void Union(long long int i, long long int j) {     long long int root_i = root(i), root_j = root(j);     if (root_i == root_j) return;     if (sizes[root_i] > sizes[root_j]) swap(root_i, root_j);     sizes[root_j] += sizes[root_i];     arr[root_i] = arr[root_j];     return;   }   long long int Arr[100001];   bool solve(long long int n) {     if (n == 1) return (true);     set<long long int> st;     for (long long int i = 0; i < n; i++) {       long long int m = (Arr[i] + i) % n;       if (m < 0) m += n;       if (st.count(m)) return (false);       st.insert(m);     }     return (true);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t;     cin >> t;     while (t--) {       string s;       cin >> s;       set<pair<pair<long long int, long long int>,                pair<long long int, long long int> > >           st;       long long int ans = 0, x = 0, y = 0;       for (long long int i = 0; i < s.size(); i++) {         long long int a, b, c, d;         if (s[i] ==  N ) {           a = x;           b = y + 1;           c = 0;           d = 1;         } else if (s[i] ==  S ) {           a = x;           b = y - 1;           c = 0;           d = -1;         } else if (s[i] ==  W ) {           a = x + 1;           b = y;           c = 1;           d = 0;         } else if (s[i] ==  E ) {           a = x - 1;           b = y;           c = -1;           d = 0;         }         if (st.count(pair<pair<long long int, long long int>,                           pair<long long int, long long int> >(                 pair<long long int, long long int>(x, y),                 pair<long long int, long long int>(a, b))))           ans++;         else if (st.count(pair<pair<long long int, long long int>,                                pair<long long int, long long int> >(                      pair<long long int, long long int>(a, b),                      pair<long long int, long long int>(x, y))))           ans++;         else           ans += 5;         st.insert(pair<pair<long long int, long long int>,                        pair<long long int, long long int> >(             pair<long long int, long long int>(x, y),             pair<long long int, long long int>(a, b)));         x += c;         y += d;       }       cout << ans <<   n ;     }     return (0);   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const ll mod = 1e9L + 7;   const int N = 121, M = 1211;   int x[N], y[N];   ll dp[N][M];   ll c[M][M];   int main() {     for (int i = 0; i < M; i++) {       c[i][0] = 1;       for (int j = 1; j <= i; j++)         c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;     }     ios ::sync_with_stdio(0);     int n;     cin >> n;     for (int i = 1; i <= n; i++) cin >> x[i];     for (int i = 1; i <= n; i++) cin >> y[i];     dp[0][0] = 1;     for (int i = 0; i <= n; i++)       for (int j = 0; j < M; j++)         for (int k = 0; k <= y[i + 1] && j + x[i + 1] - k >= 0; k++) {           dp[i + 1][j + x[i + 1] - k] += dp[i][j] * c[j + x[i + 1]][k];           dp[i + 1][j + x[i + 1] - k] %= mod;         }     ll ans = dp[n + 1][0];     int m = accumulate(x, x + n + 1, 0);     for (int i = 1; i <= n; i++) {       ans *= c[m][x[i]];       ans %= mod;       m -= x[i];     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops )   #pragma GCC optimize( no-stack-protector,fast-math )   using namespace std;   const int N = 5e5 + 100, OO = 724249387, T = 4500 + 100, M = 1e9 + 7, P = 6151,             SQ = 280, lg = 30;   map<int, int> mp;   int dp[N], l[N], r[N], t[N], seg[4][N << 2], lazy[4][N << 2];   vector<pair<int, int> > v[N];   void shift(int c, int id) {     seg[id][c << 1] += lazy[id][c];     seg[id][c << 1 | 1] += lazy[id][c];     lazy[id][c << 1] += lazy[id][c];     lazy[id][c << 1 | 1] += lazy[id][c];     lazy[id][c] = 0;   }   void upd(int id, int c, int b, int e, int l, int r, int t) {     if (e <= l || r <= b) return;     if (l <= b && e <= r) {       seg[id][c] += t;       lazy[id][c] += t;       return;     }     int mid = (b + e) >> 1;     shift(c, id);     upd(id, c << 1, b, mid, l, r, t), upd(id, c << 1 | 1, mid, e, l, r, t);     seg[id][c] = max(seg[id][c << 1 | 1], seg[id][c << 1]);   }   int get(int id, int c, int b, int e, int l, int r) {     if (r <= b || e <= l) return 0;     if (l <= b && e <= r) return seg[id][c];     int mid = (b + e) >> 1;     shift(c, id);     return max(get(id, c << 1, b, mid, l, r), get(id, c << 1 | 1, mid, e, l, r));   }   int32_t main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     int n;     cin >> n;     set<int> st;     st.insert(0);     for (int i = 0; i < n; i++) {       cin >> l[i] >> r[i] >> t[i];       st.insert(l[i]), st.insert(r[i]);     }     int cnt = 0;     for (auto u : st) mp[u] = cnt++;     for (int i = 0; i < n; i++) {       l[i] = mp[l[i]], r[i] = mp[r[i]];       v[r[i]].push_back({l[i], t[i]});     }     for (int i = 1; i < cnt; i++) {       for (auto u : v[i]) upd(u.second, 1, 0, cnt, 0, u.first, +1);       dp[i] = max(get(1, 1, 0, cnt, 0, i), get(2, 1, 0, cnt, 0, i));       upd(1, 1, 0, cnt, i, i + 1, dp[i]), upd(2, 1, 0, cnt, i, i + 1, dp[i]);     }     cout << dp[cnt - 1] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXL = 1e5;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long int k, p;     long long int ans = 0;     cin >> k >> p;     for (int i = 1; i <= k; i++) {       int x = i;       string str1, str2;       while (x) {         str1 += (x % 10 +  0 );         x /= 10;       }       for (int j = str1.size() - 1; j >= 0; j--) str2 += str1[j];       str2 += str1;       long long int sum = 0;       for (int j = 0; j < str2.size(); j++) sum = sum * 10 + str2[j] -  0 ;       ans = (ans + sum) % p;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   std::mt19937 rnd(       (int)std::chrono::steady_clock::now().time_since_epoch().count());   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   const int MAXH = 100000;   const int MAXW = 100000;   const int MAXDIM = MAXH >= MAXW ? MAXH : MAXW;   const int MAXQ = 100000;   const int MAXS = 4 * MAXDIM;   int h, w, nq;   char initlft[MAXH + 1];   char initrgt[MAXH + 1];   char inittop[MAXW + 1];   char initbot[MAXW + 1];   char qside[MAXQ];   int ql[MAXQ], qr[MAXQ], qans[MAXQ + 1];   struct SegNode {     int cost[2][2][2][2];     bool lazyfliptop, lazyflipbot;     int cntblue[2], cntred[2];   };   struct SegTree {     int n;     int crosscost, lftcost[2], rgtcost[2];     char inittop[MAXDIM + 1];     char initbot[MAXDIM + 1];     SegNode sval[MAXS];     void sfliptop(int x) {       swap(sval[x].cntblue[0], sval[x].cntred[0]);       for (int lftcol = (0); lftcol < (2); ++lftcol)         for (int rgtcol = (0); rgtcol < (2); ++rgtcol)           for (int botflip = (0); botflip < (2); ++botflip)             swap(sval[x].cost[lftcol][rgtcol][0][botflip],                  sval[x].cost[lftcol][rgtcol][1][botflip]);       sval[x].lazyfliptop = !sval[x].lazyfliptop;     }     void sflipbot(int x) {       swap(sval[x].cntblue[1], sval[x].cntred[1]);       for (int lftcol = (0); lftcol < (2); ++lftcol)         for (int rgtcol = (0); rgtcol < (2); ++rgtcol)           for (int topflip = (0); topflip < (2); ++topflip)             swap(sval[x].cost[lftcol][rgtcol][topflip][0],                  sval[x].cost[lftcol][rgtcol][topflip][1]);       sval[x].lazyflipbot = !sval[x].lazyflipbot;     }     void spush(int x) {       if (sval[x].lazyfliptop)         sfliptop(2 * x + 1), sfliptop(2 * x + 2), sval[x].lazyfliptop = false;       if (sval[x].lazyflipbot)         sflipbot(2 * x + 1), sflipbot(2 * x + 2), sval[x].lazyflipbot = false;     }     void spull(int x) {       const SegNode &a = sval[2 * x + 1];       const SegNode &b = sval[2 * x + 2];       for (int side = (0); side < (2); ++side)         sval[x].cntblue[side] = a.cntblue[side] + b.cntblue[side];       for (int side = (0); side < (2); ++side)         sval[x].cntred[side] = a.cntred[side] + b.cntred[side];       for (int lftcol = (0); lftcol < (2); ++lftcol)         for (int rgtcol = (0); rgtcol < (2); ++rgtcol)           for (int topflip = (0); topflip < (2); ++topflip)             for (int botflip = (0); botflip < (2); ++botflip) {               int cur = INT_MAX;               for (int midcol1 = (0); midcol1 < (2); ++midcol1)                 for (int midcol2 = (0); midcol2 < (2); ++midcol2) {                   int acost = a.cost[lftcol][midcol1][topflip][botflip];                   int bcost = b.cost[midcol2][rgtcol][topflip][botflip];                   int ccost = midcol1 == midcol2 ? 0 : crosscost;                   if (acost == INT_MAX || bcost == INT_MAX) continue;                   cur = min(cur, acost + bcost + ccost);                 }               sval[x].cost[lftcol][rgtcol][topflip][botflip] = cur;             }     }     void sinit(int x, int l, int r) {       sval[x].lazyfliptop = sval[x].lazyflipbot = false;       if (l == r) {         int sa = inittop[l] ==  B  ? 0 : 1;         int sb = initbot[l] ==  B  ? 0 : 1;         sval[x].cntblue[0] = sa == 0 ? 1 : 0,         sval[x].cntred[0] = 1 - sval[x].cntblue[0];         sval[x].cntblue[1] = sb == 0 ? 1 : 0,         sval[x].cntred[1] = 1 - sval[x].cntblue[1];         for (int lftcol = (0); lftcol < (2); ++lftcol)           for (int rgtcol = (0); rgtcol < (2); ++rgtcol)             for (int topflip = (0); topflip < (2); ++topflip)               for (int botflip = (0); botflip < (2); ++botflip) {                 int cur;                 if (lftcol == rgtcol) {                   int a = sa;                   if (topflip) a = 1 - a;                   int b = sb;                   if (botflip) b = 1 - b;                   cur = (a == lftcol ? 0 : 1) + (b == lftcol ? 0 : 1);                 } else {                   cur = INT_MAX;                 }                 sval[x].cost[lftcol][rgtcol][topflip][botflip] = cur;               }       } else {         int m = l + (r - l) / 2;         sinit(2 * x + 1, l, m);         sinit(2 * x + 2, m + 1, r);         spull(x);       }     }     void sflip(int x, int l, int r, int L, int R, bool istop) {       if (L <= l && r <= R) {         if (istop)           sfliptop(x);         else           sflipbot(x);       } else {         int m = l + (r - l) / 2;         spush(x);         if (L <= m) sflip(2 * x + 1, l, m, L, R, istop);         if (m + 1 <= R) sflip(2 * x + 2, m + 1, r, L, R, istop);         spull(x);       }     }     void init() { sinit(0, 0, n - 1); }     void flip(int l, int r, bool istop) { sflip(0, 0, n - 1, l, r, istop); }     int calc() {       int ret = INT_MAX;       for (int lftcol = (0); lftcol < (2); ++lftcol)         for (int rgtcol = (0); rgtcol < (2); ++rgtcol) {           int cur = sval[0].cost[lftcol][rgtcol][0][0];           if (cur == INT_MAX) continue;           cur += lftcost[lftcol];           cur += rgtcost[rgtcol];           ret = min(ret, cur);         }       return ret;     }   };   SegTree stopbot, slftrgt;   int calc() {     stopbot.lftcost[0] = slftrgt.sval[0].cntred[0],     stopbot.lftcost[1] = slftrgt.sval[0].cntblue[0];     stopbot.rgtcost[0] = slftrgt.sval[0].cntred[1],     stopbot.rgtcost[1] = slftrgt.sval[0].cntblue[1];     slftrgt.lftcost[0] = stopbot.sval[0].cntred[0],     slftrgt.lftcost[1] = stopbot.sval[0].cntblue[0];     slftrgt.rgtcost[0] = stopbot.sval[0].cntred[1],     slftrgt.rgtcost[1] = stopbot.sval[0].cntblue[1];     return min(stopbot.calc(), slftrgt.calc());   }   void solve() {     stopbot.n = w, stopbot.crosscost = h;     for (int i = (0); i <= (w); ++i)       stopbot.inittop[i] = inittop[i], stopbot.initbot[i] = initbot[i];     stopbot.init();     slftrgt.n = h, slftrgt.crosscost = w;     for (int i = (0); i <= (h); ++i)       slftrgt.inittop[i] = initlft[i], slftrgt.initbot[i] = initrgt[i];     slftrgt.init();     qans[0] = calc();     for (int i = (0); i < (nq); ++i) {       char side = qside[i];       int l = ql[i], r = qr[i];       if (side ==  U ) stopbot.flip(l, r, true);       if (side ==  D ) stopbot.flip(l, r, false);       if (side ==  L ) slftrgt.flip(l, r, true);       if (side ==  R ) slftrgt.flip(l, r, false);       qans[i + 1] = calc();     }   }   void run() {     scanf( %d%d%d , &h, &w, &nq);     scanf( %s , initlft);     scanf( %s , initrgt);     scanf( %s , inittop);     scanf( %s , initbot);     for (int i = (0); i < (nq); ++i)       scanf(  %c%d%d , &qside[i], &ql[i], &qr[i]), --ql[i], --qr[i];     solve();     for (int i = (0); i <= (nq); ++i) printf( %d n , qans[i]);   }   void stress() {     h = MAXH, w = MAXW, nq = MAXQ;     for (int i = (0); i < (h); ++i) initlft[i] =  BR [rnd() % 2];     initlft[h] =   0 ;     for (int i = (0); i < (h); ++i) initrgt[i] =  BR [rnd() % 2];     initrgt[h] =   0 ;     for (int i = (0); i < (w); ++i) inittop[i] =  BR [rnd() % 2];     inittop[w] =   0 ;     for (int i = (0); i < (w); ++i) initbot[i] =  BR [rnd() % 2];     initbot[w] =   0 ;     for (int i = (0); i < (nq); ++i) {       qside[i] =  UDLR [rnd() % 4];       int dim = qside[i] ==  U  || qside[i] ==  D  ? w : h;       ql[i] = rnd() % dim, qr[i] = rnd() % dim;       if (ql[i] > qr[i]) swap(ql[i], qr[i]);     }     solve();     printf( done n );   }   int main() {     run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     cout << n / 2 * 3 << endl;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-9;   struct _hash {     int operator()(const complex<double> &p) const {       return p.real() * 20001 + p.imag();     }   };   int n;   complex<double> p[100];   unordered_set<complex<double>, _hash> pnts;   double ans = -1;   inline int compare(const double &a, const double &b) {     if (fabs(a - b) < eps) return 0;     return a < b ? -1 : 1;   }   bool intersect(const complex<double> &a, const complex<double> &b,                  const complex<double> &p, const complex<double> &q,                  complex<double> &ret) {     double d1 = ((conj(p - a) * (b - a)).imag());     double d2 = ((conj(q - a) * (b - a)).imag());     ret = (d1 * q - d2 * p) / (d1 - d2);     return (fabs(d1 - d2) > eps);   }   complex<double> findCenter(const complex<double> &a, const complex<double> &b,                              const complex<double> &c) {     complex<double> m1 = (((a) + (b)) / 2.0);     complex<double> m2 = (((b) + (c)) / 2.0);     complex<double> p1 =         (complex<double>(-(((b) - (a))).imag(), (((b) - (a))).real()));     complex<double> p2 =         (complex<double>(-(((c) - (b))).imag(), (((c) - (b))).real()));     complex<double> r;     assert(intersect(m1, m1 + p1, m2, m2 + p2, r));     return r;   }   void check(const complex<double> &center, const double &r) {     double minDist = 1e9;     for (int i = 0; i < n; ++i)       minDist = min(minDist, (hypot((((p[i]) - (center))).real(),                                     (((p[i]) - (center))).imag())));     if (compare(minDist, r) < 0) return;     assert(compare(r, minDist) == 0);     ans = max(ans, r);   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       int x, y;       scanf( %d %d , &x, &y);       pnts.insert(p[i] = complex<double>(x, y));     }     for (int i = 0; i < n; ++i)       for (int j = i + 1; j < n; ++j)         for (int k = j + 1; k < n; ++k) {           complex<double> triangle[3] = {p[i], p[j], p[k]};           for (int a = 0; a < 3; ++a) {             int b = (a + 1) % 3;             int c = (b + 1) % 3;             double d = ((conj(((triangle[b]) - (triangle[a]))) *                          (((triangle[c]) - (triangle[a]))))                             .real());             if (d < 0) goto next;             if (d == 0) {               if (!compare((hypot((((triangle[b]) - (triangle[a]))).real(),                                   (((triangle[b]) - (triangle[a]))).imag())),                            (hypot((((triangle[c]) - (triangle[a]))).real(),                                   (((triangle[c]) - (triangle[a]))).imag())))) {                 {                   complex<double> p = ((triangle[a]) - (triangle[b]));                   complex<double> m = ((triangle[c]) - (triangle[b]));                   complex<double> _4th = conj(p / m) * m;                   if (pnts.find(_4th) == pnts.end()) goto next;                   {                     complex<double> center =                         (((triangle[b]) + (triangle[c])) / 2.0);                     check(center, (hypot((((triangle[0]) - (center))).real(),                                          (((triangle[0]) - (center))).imag())));                   }                 }               }               goto next;             }           }           {             complex<double> center =                 findCenter(triangle[0], triangle[1], triangle[2]);             check(center, (hypot((((triangle[0]) - (center))).real(),                                  (((triangle[0]) - (center))).imag())));           }         next:;         }     printf( %.17lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 400;   int x[MAXN], y[MAXN];   inline bool lt(int i, int xx, int yy) {     return x[i] < xx || (x[i] == xx && y[i] < yy);   }   inline bool gt(int i, int xx, int yy) {     return x[i] > xx || (x[i] == xx && y[i] > yy);   }   void mysort(int l, int r) {     if (l < r) {       int pivot = int((rand() / (1.0 + RAND_MAX)) * (r - l + 1)) + l;       int xx = x[pivot];       int yy = y[pivot];       int i = l;       int j = r;       while (1) {         while (lt(i, xx, yy)) ++i;         while (gt(j, xx, yy)) --j;         if (i <= j) {           swap(x[i], x[j]);           swap(y[i], y[j]);           ++i;           --j;         } else {           break;         }       }       mysort(l, j);       mysort(i, r);     }   }   bool outside(int xx, int xlo, int xhi) { return xx < xlo || xx > xhi; }   bool outside(int xx, int yy, int xlo, int xhi, int ylo, int yhi) {     return outside(xx, xlo, xhi) || outside(yy, ylo, yhi);   }   const int MAXSTEPS = 1000000;   char steps[MAXSTEPS + 1];   int dy[] = {1, 0, -1, 0};   int dx[] = {0, 1, 0, -1};   string stepcode =  URDL ;   const int OFFSET = 120;   bool board[2 * OFFSET + 1][2 * OFFSET + 1];   int from[2 * OFFSET + 1][2 * OFFSET + 1];   int n;   bool tree(int xx, int yy) {     pair<int*, int*> p_ = equal_range(x, x + n, xx);     int p = p_.first - x;     int q = p_.second - x;     cerr <<  tree:   << xx <<     << yy <<     << p <<     << q <<   n ;     if (p < n && x[p] == xx) {       int i = lower_bound(y + p, y + q, yy) - y;       cerr << i <<   n ;       return (i < q && y[i] == yy);     }     return false;   }   int main() {     int vx, vy, sx, sy;     cin >> vx >> vy >> sx >> sy >> n;     if (n == 0) {       puts( -1 );       return 0;     }     int orig_vx = vx;     int orig_vy = vy;     int orig_sx = sx;     int orig_sy = sy;     for (int i = 0; i < n; ++i) {       cin >> x[i] >> y[i];     }     mysort(0, n - 1);     for (int i = 0; i < n; ++i) {       cerr << x[i] <<     << y[i] <<   n ;     }     cerr <<   n ;     int xlo = x[0];     int xhi = x[n - 1];     int ylo = *min_element(y, y + n);     int yhi = *max_element(y, y + n);     int step = 0;     if (!outside(vx, vy, xlo, xhi, ylo, yhi) ||         !outside(sx, sy, xlo, xhi, ylo, yhi)) {       for (int i = 0; i < n; ++i) {         (board[(x[i]) + OFFSET][(y[i]) + OFFSET]) = 1;       }       memset(from, 0xff, sizeof from);       queue<pair<int, int> > Q;       Q.push(make_pair(vx, vy));       (from[(vx) + OFFSET][(vy) + OFFSET]) = 1;       while (!Q.empty()) {         pair<int, int> tmp = Q.front();         Q.pop();         int u = tmp.first;         int v = tmp.second;         for (int d = 0; d < 4; ++d) {           int r = u + dx[d];           int c = v + dy[d];           if (r + OFFSET < 0 || c + OFFSET < 0 || r > OFFSET || c > OFFSET ||               (from[(r) + OFFSET][(c) + OFFSET]) != -1 ||               (board[(r) + OFFSET][(c) + OFFSET])) {             continue;           }           (from[(r) + OFFSET][(c) + OFFSET]) = d;           if (r == sx && c == sy) {             goto BFS_DONE;           }           Q.push(make_pair(r, c));         }       }     BFS_DONE:;       if ((from[(sx) + OFFSET][(sy) + OFFSET]) == -1) {         puts( -1 );         return 0;       }       vector<int> D;       int xx = sx;       int yy = sy;       while (xx != vx || yy != vy) {         D.push_back((from[(xx) + OFFSET][(yy) + OFFSET]));         xx -= dx[D.back()];         yy -= dy[D.back()];       }       reverse(D.begin(), D.end());       cerr << D.size() <<   n ;       int at = 0;       while ((!outside(vx, vy, xlo, xhi, ylo, yhi) ||               !outside(sx, sy, xlo, xhi, ylo, yhi)) &&              (vx != sx || vy != sy)) {         assert(at < int(D.size()));         cerr << at <<     << D[at] <<   n ;         steps[step++] = stepcode[D[at]];         cerr << vx <<     << vy <<     << sx <<     << sy <<   n ;         vx += dx[D[at]];         vy += dy[D[at]];         cerr << vx <<     << vy <<     << sx <<     << sy <<   n ;         assert(!tree(vx, vy));         if (!tree(sx + dx[D[at]], sy + dy[D[at]])) {           sx += dx[D[at]];           sy += dy[D[at]];           D.push_back(D[at]);         }         cerr << vx <<     << vy <<     << sx <<     << sy <<   n ;         cerr <<   n ;         ++at;       }     }     if (vx != sx || vy != sy) {       int d = -1;       if ((vx > xhi || outside(vy, ylo, yhi)) &&           (sx > xhi || outside(sy, ylo, yhi))) {         d = 1;       } else if ((vx < xlo || outside(vy, ylo, yhi)) &&                  (sx < xlo || outside(sy, ylo, yhi))) {         d = 3;       } else if ((vy > yhi || outside(vx, xlo, xhi)) &&                  (sy > yhi || outside(sx, xlo, xhi))) {         d = 0;       } else {         assert((vy < ylo || outside(vx, xlo, xhi)) &&                (vy < ylo || outside(sx, xlo, xhi)));         d = 2;       }       vx += 500 * dx[d];       vy += 500 * dy[d];       sx += 500 * dx[d];       sy += 500 * dy[d];       for (int i = 0; i < 500; ++i) {         steps[step++] = stepcode[d];       }       cerr << vx <<     << vy <<     << sx <<     << sy <<   n ;       if (d != 0) {         if (d == 2) {           for (int i = 0; i < 500; ++i) {             steps[step++] =  R ;           }         }         vy += 1000;         sy += 1000;         for (int i = 0; i < 1000; ++i) {           steps[step++] =  U ;         }         cerr << vx <<     << vy <<     << sx <<     << sy <<   n ;         if (d == 2) {           for (int i = 0; i < 500; ++i) {             steps[step++] =  L ;           }         } else {           d = (d + 2) % 4;           cerr <<  bla   << d <<   n ;           cerr << vx <<     << vy <<     << sx <<     << sy <<   n ;           vx += 500 * dx[d];           vy += 500 * dy[d];           sx += 500 * dx[d];           sy += 500 * dy[d];           for (int i = 0; i < 500; ++i) {             steps[step++] = stepcode[d];           }           cerr << vx <<     << vy <<     << sx <<     << sy <<   n ;         }       }     }     cerr << vx <<     << vy <<     << sx <<     << sy <<   n ;     if (vx != sx) {       if (vx > sx) {         vx += 500;         sx += 500;         for (int i = 0; i < 500; ++i) {           steps[step++] =  R ;         }         int k = sy - y[n - 1];         vy -= k;         sy -= k;         for (int i = 0; i < k; ++i) {           steps[step++] =  D ;         }         while (vx != sx) {           --vx;           steps[step++] =  L ;           if (sx - 1 > x[n - 1]) {             --sx;           }         }       } else {         vx -= 500;         sx -= 500;         for (int i = 0; i < 500; ++i) {           steps[step++] =  L ;         }         int k = sy - y[0];         vy -= k;         sy -= k;         for (int i = 0; i < k; ++i) {           steps[step++] =  D ;         }         while (vx != sx) {           ++vx;           steps[step++] =  R ;           if (sx + 1 < x[0]) {             ++sx;           }         }       }     }     cerr << vx <<     << vy <<     << sx <<     << sy <<   n ;     assert(vx == sx);     if (vy != sy) {       if (vy > sy) {         vy += 2000;         sy += 2000;         for (int i = 0; i < 2000; ++i) {           steps[step++] =  U ;         }         int top = 0;         for (int i = 1; i < n; ++i) {           if (y[i] > y[top]) {             top = i;           }         }         if (vx > x[top]) {           int k = vx - x[top];           vx -= k;           sx -= k;           for (int i = 0; i < k; ++i) {             steps[step++] =  L ;           }         } else {           int k = -(vx - x[top]);           vx += k;           sx += k;           for (int i = 0; i < k; ++i) {             steps[step++] =  R ;           }         }         while (vy != sy) {           --vy;           steps[step++] =  D ;           if (sy - 1 > y[top]) {             --sy;           }         }       } else {         vy -= 2000;         sy -= 2000;         for (int i = 0; i < 2000; ++i) {           steps[step++] =  D ;         }         int bot = 0;         for (int i = 1; i < n; ++i) {           if (y[i] < y[bot]) {             bot = i;           }         }         if (vx > x[bot]) {           int k = vx - x[bot];           vx -= k;           sx -= k;           for (int i = 0; i < k; ++i) {             steps[step++] =  L ;           }         } else {           int k = -(vx - x[bot]);           vx += k;           sx += k;           for (int i = 0; i < k; ++i) {             steps[step++] =  R ;           }         }         while (vy != sy) {           ++vy;           steps[step++] =  U ;           if (sy + 1 < y[bot]) {             ++sy;           }         }       }     }     cerr << vx <<     << vy <<     << sx <<     << sy <<   n ;     int xx = orig_vx;     int yy = orig_vy;     for (int s = 0; s < step; ++s) {       int d = stepcode.find(steps[s]);       xx += dx[d];       yy += dy[d];     }     cerr << xx <<     << yy <<   expect   << vx <<     << vy;     assert(xx == vx && yy == vy);     xx = orig_sx;     yy = orig_sy;     for (int s = 0; s < step; ++s) {       int d = stepcode.find(steps[s]);       xx += dx[d];       yy += dy[d];       if (tree(xx, yy)) {         xx -= dx[d];         yy -= dy[d];       }     }     cerr << xx <<     << yy <<   expect   << sx <<     << sy;     assert(xx == sx && yy == sy);     puts(steps);     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, i, cnt = 0;     float y;     scanf( %d , &n);     int p[n];     for (i = 1; i <= n; i++) {       scanf( %d , &p[i]);       cnt += p[i];     }     y = (float)cnt / (float)n;     printf( %f , y);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     string res =   ;     if (s.find( . ) == string::npos) {       s +=  . ;     }     int d = s.find( . );     int i = d - 1;     int c = 0;     while (i >= 0) {       if (s[i] !=  - ) res = s[i] + res;       c++;       if (c == 3 && i > 0) {         if (i - 1 >= 0 && s[i - 1] !=  - ) res =  ,  + res;         c = 0;       }       i--;     }     res +=  . ;     int dc = s.length() - 1 - d;     if (dc == 0) {       res +=  00 ;     } else if (dc == 1) {       res += s[d + 1];       res +=  0 ;     } else if (dc >= 2) {       res += s[d + 1];       res += s[d + 2];     }     res =  $  + res;     if (s[0] ==  - ) res =  (  + res +  ) ;     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   int dp[505][505], dp2[505];   void solve() {     int n;     cin >> n;     vector<int> a(n);     for (auto &i : a) cin >> i;     memset(dp, 0, sizeof(dp));     for (int i = 0; i < n; i++) dp[i][i] = a[i];     for (int i = 1; i < n; i++) {       for (int j = i - 1; j >= 0; j--) {         for (int k = i; k > j; k--) {           if (dp[k][i] and dp[k][i] == dp[j][k - 1]) dp[j][i] = dp[k][i] + 1;         }       }     }     memset(dp2, INT_MAX, sizeof(dp2));     for (int i = 0; i <= n; i++) dp2[i] = i + 1;     for (int i = 0; i < n; i++) {       for (int j = 0; j <= i; j++) {         if (dp[j][i]) {           if (j == 0)             dp2[i] = 1;           else             dp2[i] = min(dp2[i], dp2[j - 1] + 1);         }       }     }     cout << dp2[n - 1];   }   int main() {     int t;     t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = (long long)1e18;   const int mod = (int)1e9 + 7;   const int MAXN = (int)1e5 + 5;   long long n;   const int bs = 350;   int a[MAXN];   int mp[600][MAXN];   vector<int> ls[1000];   void swp(int l, int r) {     int size = 0, i = 0;     vector<int> tmp1, tmp2;     for (i = 0; i <= (n - 1) / bs; i++) {       if (size + ls[i].size() > r) {         break;       }       size += ls[i].size();     }     long long sayi = 0;     for (int j = 0; j < ls[i].size(); j++) {       mp[i][ls[i][j]] = 0;       if (j + size == r) {         sayi = ls[i][j];         continue;       }       tmp1.push_back(ls[i][j]);     }     ls[i].clear();     for (int j : tmp1) {       ls[i].push_back(j);       mp[i][j]++;     }     size = 0;     i = 0;     for (i = 0; i <= (n - 1) / bs; i++) {       if (size + ls[i].size() > l) {         break;       }       size += ls[i].size();     }     if (l == n - 1) {       ls[(l / bs)].push_back(sayi);       mp[l / bs][sayi]++;       return;     }     for (int j = 0; j < ls[i].size(); j++) {       mp[i][ls[i][j]] = 0;       if (j + size == l) {         tmp2.push_back(sayi);       }       tmp2.push_back(ls[i][j]);     }     ls[i].clear();     for (int j : tmp2) {       ls[i].push_back(j);       mp[i][j]++;     }   }   long long get(long long ind, long long k) {     if (ind < 0) return 0;     long long ans = 0;     int size = 0;     int yer;     for (int i = 0; i <= (n - 1) / bs; i++) {       if (size + ls[i].size() > ind) {         yer = i;         break;       }       size += ls[i].size();       ans += mp[i][k];     }     for (int i = 0; i + size <= ind; i++) {       ans += (ls[yer][i] == k);     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       ls[i / bs].push_back(a[i]);       mp[i / bs][a[i]]++;     }     int lastans = 0;     int q;     cin >> q;     for (int i = 0; i < q; i++) {       if (i % bs == 0) {         vector<int> tmp;         for (int i = 0; i <= (n - 1) / bs; i++) {           for (auto j = ls[i].begin(); j < ls[i].end(); j++) {             tmp.push_back(*j);             mp[i][*j] = 0;           }         }         for (int j = 0; j < n; j++) {           if (j % bs == 0) {             ls[j / bs].clear();           }           mp[j / bs][tmp[j]]++;           ls[j / bs].push_back(tmp[j]);         }       }       int a;       cin >> a;       if (a == 1) {         int l, r;         cin >> l >> r;         l = (l + lastans - 1 + n) % n;         r = (r + lastans - 1 + n) % n;         if (l > r) swap(l, r);         swp(l, r);       } else {         int l, r, k;         cin >> l >> r >> k;         l = (l + lastans - 1 + n) % n;         r = (r + lastans - 1 + n) % n;         k = 1 + (k + lastans - 1 + n) % n;         if (l > r) swap(l, r);         lastans = get(r, k) - get(l - 1, k);         cout << lastans <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string name;     int counter = 0;     cin >> name;     for (int i = 0; i < name.length() / 2; i++) {       if (name[i] != name[name.length() - 1 - i]) counter++;     }     if (name.length() % 2 == 0) {       if (counter == 1)         cout <<  YES n ;       else         cout <<  NO n ;     } else {       if (counter == 1 || counter == 0)         cout <<  YES n ;       else         cout <<  NO n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long modpow(long long a, long long b,                    long long mod = (long long)(1e9 + 7)) {     if (!b) return 1;     a %= mod;     return modpow(a * a % mod, b / 2, mod) * (b & 1 ? a : 1) % mod;   }   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const int mxn = 1100;   char string1[mxn];   char string2[mxn];   int xt1[mxn], xt2[mxn], xt3[mxn];   int bound[mxn];   int n, m;   void solution() {     long long answer = 0;     scanf( %d , &n);     scanf( %d , &m);     for (int i = 0; i < n; i++) {       scanf( %s , string2);       long long composite = 0;       for (int j = 0; j < m; j++) {         if (string2[j] != string1[j]) {           xt1[j] = xt2[j];           xt2[j] = xt3[j];           xt3[j] = 1;         } else {           xt3[j]++;         }         if (j > 0) {           if (string2[j] == string2[j - 1])             bound[j]++;           else             bound[j] = 0;         }         if (xt1[j] >= xt2[j] && xt2[j] == xt3[j]) {           composite++;           if (bound[j] < xt3[j] * 3) composite = 1;         } else           composite = 0;         string1[j] = string2[j];         answer += composite;       }     }     cout << answer << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     solution();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       if (n == 2 || n == 3 || n == 4 || n == 5 || n == 6 || n == 7)         cout <<  1  << endl;       else if (n % 7 == 1)         cout << ((n - 1) / 7) + 1 << endl;       else         cout << (n / 7) + 1 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int N = 1e5 + 5;   struct edge {     int u, v;     ll w;     edge(int u, int v, ll w) : u(u), v(v), w(w) {}   };   int n, m, k, closestP[N], par[N];   ll d[N], res;   bool is1portal;   vector<int> portal;   vector<edge> adj[N], edges;   int root(int v) { return (par[v] < 0) ? v : (par[v] = root(par[v])); }   void join(int x, int y) {     if ((x = root(x)) == (y = root(y))) return;     if (par[x] > par[y]) swap(x, y);     par[x] += par[y];     par[y] = x;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = 1; i <= m; ++i) {       int u, v, w;       cin >> u >> v >> w;       adj[u].emplace_back(u, v, w);       adj[v].emplace_back(v, u, w);     }     cin >> k;     for (int i = 1; i <= k; ++i) {       int p;       cin >> p;       portal.emplace_back(p);       if (p == 1) is1portal = true;     }     priority_queue<pair<ll, pair<int, int>>> q;     for (int i = 1; i <= n; ++i) d[i] = 1e18;     for (int p : portal) q.push({d[p] = 0, {p, p}});     while (!q.empty()) {       int u = q.top().second.first;       int p = q.top().second.second;       q.pop();       if (closestP[u]) continue;       closestP[u] = p;       for (edge e : adj[u]) {         if (d[e.v] > d[u] + e.w) {           d[e.v] = d[u] + e.w;           q.push({-d[e.v], {e.v, p}});         }       }     }     for (int u = 1; u <= n; ++u) {       for (edge e : adj[u]) {         edges.emplace_back(closestP[u], closestP[e.v], d[u] + d[e.v] + e.w);       }     }     sort(edges.begin(), edges.end(),          [](const edge &x, const edge &y) { return x.w < y.w; });     for (int i = 1; i <= n; ++i) par[i] = -1;     for (edge e : edges) {       if (root(e.u) != root(e.v)) {         join(e.u, e.v);         res += e.w;       }     }     if (!is1portal) res += d[1];     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n;     cin >> n;     vector<long long> a(n);     long long sums = 0;     for (long long i = 0; i < n; i++) {       cin >> a[i];       sums += a[i];     }     if (sums % 2 == 0) {       long long maxs = -1;       for (long long i = 0; i < n; i++) {         if (a[i] > maxs) maxs = a[i];       }       if (maxs > sums - maxs) {         cout <<  NO n ;       } else {         cout <<  YES n ;       }     } else {       cout <<  NO n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int n;   string t;   map<string, int> mp;   int solve(int l, int r) {     int val = 0;     for (int i = r - 1; i >= l; i--) {       if (t[i] ==  ( ) val++;       if (t[i] ==  ) ) val--;       if (!val && (t[i] ==  +  || t[i] ==  - )) {         int L = solve(l, i);         int R = solve(i + 1, r);         if (L && R && (t[i] ==  +  || R > 1))           return 1;         else           return 0;       }     }     for (int i = r - 1; i >= l; i--) {       if (t[i] ==  ( ) val++;       if (t[i] ==  ) ) val--;       if (!val && (t[i] ==  *  || t[i] ==  / )) {         int L = solve(l, i);         int R = solve(i + 1, r);         if (L > 1 && R > 1 && (t[i] ==  *  || R > 2))           return 2;         else           return 0;       }     }     string x = t.substr(l, r - l);     if (t[l] ==  ( ) {       if (solve(l + 1, r - 1)) return 3;       return 0;     }     if (mp.count(x)) return mp[x];     return 3;   }   int Get() {     string tmp;     getline(cin, tmp);     int len = tmp.length();     t =   ;     for (int i = 0; i < len; i++)       if (tmp[i] !=    ) t += tmp[i];     return solve(0, t.length());   }   int main() {     scanf( %d , &n);     string s;     for (int i = 1; i <= n; i++) {       scanf(  #%*s );       cin >> s;       mp[s] = Get();     }     if (Get())       puts( OK );     else       puts( Suspicious );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());   const double eps = 0.00001;   const int MOD = 1000000007;   const int INF = 1000055555;   const long long LLINF = 1223372000000000555;   const int N = 1e5 + 1e4;   const int M = 1234;   const int MAGIC = 10;   vector<int> merge(vector<int> a, vector<int> b) {     vector<int> v;     int i = 0, j = 0;     while (i < a.size() || j < b.size()) {       if (v.size() == MAGIC) break;       if (i == a.size())         v.push_back(b[j++]);       else if (j == b.size())         v.push_back(a[i++]);       else if (a[i] < b[j])         v.push_back(a[i++]);       else         v.push_back(b[j++]);       if (v.size() > 1 && v[v.size() - 2] == v.back()) v.pop_back();     }     return v;   }   vector<int> g[N];   vector<int> arr[N][20];   int tin[N], tout[N], timer = 0;   int up[N][20];   void dfs(int v, int p) {     tin[v] = ++timer;     up[v][0] = p;     for (int i = 1; i < 20; i++) {       up[v][i] = up[up[v][i - 1]][i - 1];       int UP = up[v][i - 1];       arr[v][i] = merge(arr[v][i - 1], arr[UP][i - 1]);     }     for (int u : g[v]) {       if (u != p) dfs(u, v);     }     tout[v] = ++timer;   }   bool upper(int a, int b) { return (tin[a] <= tin[b] && tout[a] >= tout[b]); }   int LCA(int a, int b) {     if (upper(a, b)) return a;     if (upper(b, a)) return b;     for (int i = 19; i >= 0; i--) {       if (!upper(up[a][i], b)) a = up[a][i];     }     return up[a][0];   }   void out(vector<int> &v, int a) {     int k = min(a, ((int)v.size()));     cout << k <<    ;     for (int i = 0; i < k; i++) {       cout << v[i] <<    ;     }     cout << endl;   }   void solve() {     int n, m, q;     cin >> n >> m >> q;     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     for (int i = 1; i <= m; i++) {       int x;       cin >> x;       arr[x][0].push_back(i);     }     for (int i = 1; i <= n; i++) {       if (arr[i][0].size() > MAGIC) arr[i][0].resize(MAGIC);     }     dfs(1, 1);     while (q--) {       int u, v, a;       cin >> u >> v >> a;       if (v == u) {         out(arr[v][0], a);         continue;       }       int lca = LCA(u, v);       if (u == lca) {         vector<int> vv;         for (int i = 19; i >= 0; i--) {           if (!upper(up[v][i], lca) && up[v][i]) {             vv = merge(vv, arr[v][i]);             v = up[v][i];           }         }         vv = merge(vv, arr[u][0]);         vv = merge(vv, arr[v][0]);         out(vv, a);         continue;       }       if (v == lca) {         vector<int> vv;         for (int i = 19; i >= 0; i--) {           if (!upper(up[u][i], lca)) {             vv = merge(vv, arr[u][i]);             u = up[u][i];           }         }         vv = merge(vv, arr[u][0]);         vv = merge(vv, arr[v][0]);         out(vv, a);         continue;       }       vector<int> vv = arr[lca][0];       for (int i = 19; i >= 0; i--) {         if (!upper(up[v][i], lca)) {           vv = merge(vv, arr[v][i]);           v = up[v][i];         }       }       for (int i = 19; i >= 0; i--) {         if (!upper(up[u][i], lca)) {           vv = merge(vv, arr[u][i]);           u = up[u][i];         }       }       vv = merge(vv, arr[u][0]);       vv = merge(vv, arr[v][0]);       out(vv, a);     }   }   int main() {     ios_base::sync_with_stdio(false);     int T = 1;     while (T--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100010;   template <class T, class Comp = less<T> >   struct monoqueue {     deque<pair<T, int> > dq;     Comp comp;     int left, right;     bool one_index;     monoqueue(bool ind1)         : dq(), comp(), left(ind1), right(ind1), one_index(ind1) {}     void push(T t) {       while (!dq.empty() && comp(t, dq.back().first)) {         dq.pop_back();       }       dq.push_back(make_pair(t, right++));     }     template <class Iterator>     void push(Iterator i, Iterator j) {       for (; i != j; i++) {         push(*i);       }     }     void pop() {       assert(!empty());       if (dq.front().second == left) {         dq.pop_front();       }       left++;     }     T get() {       assert(!empty());       return dq.front().first;     }     int getind() {       assert(!empty());       return dq.front().second;     }     int size() { return right - left; }     bool empty() { return left == right; }     void clear() {       dq.clear();       left = right = 0;     }   };   int N, S, L;   int arr[MAXN];   int upto[MAXN];   monoqueue<int> dqmin(true);   monoqueue<int, greater<int> > dqmax(true);   int dp[MAXN];   int main() {     if (fopen( input.txt ,  r )) {       freopen( input.txt ,  r , stdin);     }     ios_base::sync_with_stdio(false);     cin >> N >> S >> L;     for (int i = 1; i <= N; i++) {       cin >> arr[i];     }     for (int i = 1; i <= N; i++) {       dqmin.push(arr[i]);       dqmax.push(arr[i]);       while (!dqmin.empty() && dqmax.get() - dqmin.get() > S) {         dqmin.pop();         dqmax.pop();       }       int m = dqmin.left;       if (m >= i - L + 2) {         m = i - L + 2;       }       upto[i] = m;     }     fill_n(dp + 1, N, MAXN);     dqmin.clear();     for (int i = L; i <= N; i++) {       dqmin.push(dp[i - L]);       while (dqmin.left < upto[i] - 1) {         dqmin.pop();       }       if (dqmin.empty() || dqmin.get() == MAXN) {         dp[i] = MAXN;       } else {         dp[i] = dqmin.get() + 1;       }     }     int ans = dp[N];     cout << (ans == MAXN ? -1 : ans) << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200010;   bool good[N], need[N];   int n;   void ask(vector<int> &v) {     printf( %d , (int)v.size());     for (int i = 0; i < (int)v.size(); i++) {       printf(  %d , v[i]);       good[v[i]] = true;     }     puts(  );     fflush(stdout);     int idx;     scanf( %d , &idx);     for (int i = 0; i < (int)v.size(); i++) {       good[idx] = false;       idx++;       if (idx > n) idx = 1;     }   }   int main() {     scanf( %d , &n);     if (n <= 3) {       puts( 0 );       fflush(stdout);       return 0;     }     int cur, best = 0, k;     for (int sz = 1; sz < n; sz++) {       cur = ((n + sz) / (sz + 1));       cur = n - cur - sz;       if (cur > best) {         best = cur;         k = sz;       }     }     for (int i = 1; i < n; i += k + 1) {       for (int j = i; j < min(n, i + k); j++) need[j] = true;     }     vector<int> v;     while (true) {       cur = 0;       for (int l = 1; l <= n; l++)         if (good[l]) cur++;       if (cur >= best) break;       v.clear();       for (int i = 1; i <= n; i++) {         if (need[i] && !good[i]) v.push_back(i);       }       ask(v);     }     puts( 0 );     fflush(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a1, a2, b1, b2, c1, c2;   struct Point {     long long x, y;     Point(long long x = 0, long long y = 0) : x(x), y(y) {}   };   int exgcd(int a, int b, int& x, int& y) {     if (b == 0) {       x = 1;       y = 0;       return a;     }     int d = exgcd(b, a % b, x, y);     int t = x;     x = y;     y = t - a / b * y;     return d;   }   int dcmp(int x) {     if (x == 0) return 0;     return x < 0 ? -1 : 1;   }   Point operator+(const Point& a, const Point& b) {     return Point(a.x + b.x, a.y + b.y);   }   Point ans[5];   int main() {     scanf( %lld %lld %lld %lld %lld %lld , &a1, &a2, &b1, &b2, &c1, &c2);     ans[1] = Point(b1 - a1, b2 - a2);     ans[2] = Point(b1 - a2, b2 + a1);     ans[3] = Point(b1 + a1, b2 + a2);     ans[4] = Point(b1 + a2, b2 - a1);     if (c1 == 0 && c2 == 0) {       for (int i = 1; i <= 4; i++)         if (ans[i].x == 0 && ans[i].y == 0) {           printf( YES n );           return 0;         }       printf( NO n );       return 0;     }     for (int i = 1; i <= 4; i++) {       long long t1, t2;       if ((c1 * ans[i].x + c2 * ans[i].y) % (c1 * c1 + c2 * c2) != 0) continue;       t1 = (c1 * ans[i].x + c2 * ans[i].y) / (c1 * c1 + c2 * c2);       if ((c2 * ans[i].x - c1 * ans[i].y) % (c1 * c1 + c2 * c2) != 0) continue;       t2 = (c2 * ans[i].x - c1 * ans[i].y) / (c1 * c1 + c2 * c2);       printf( YES n );       return 0;     }     printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   int n, ans, x = 201, y = 201, u[405][405];   int main() {     scanf( %d , &n);     cin >> s;     for (int i = 0; i < n; ++i) {       ans += u[x][y];       ++u[x][y];       if (s[i] ==  U ) ++x;       if (s[i] ==  D ) --x;       if (s[i] ==  R ) ++y;       if (s[i] ==  L ) --y;     }     ans += u[x][y];     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   bool umin(T& a, const T& b) {     return a > b ? a = b, true : false;   }   template <class T>   bool umax(T& a, const T& b) {     return a < b ? a = b, true : false;   }   template <long long sz>   using tut = array<long long, sz>;   void usaco(string s) {     freopen((s +  .in ).c_str(),  r , stdin);     freopen((s +  .out ).c_str(),  w , stdout);     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   const long long N = 2e5 + 5;   const long long mod = (119 << 23) + 1;   const long long inf = LLONG_MAX;   const long double Pi = acos(-1);   void add(long long& a, long long b, long long mod = ::mod) {     a = (a + b) % mod;   }   void sub(long long& a, long long b, long long mod = ::mod) {     a = ((a - b) % mod + mod) % mod;   }   void mul(long long& a, long long b, long long mod = ::mod) {     a = (a * 1ll * b) % mod;   }   long long n, m, k, t, q, ans, res, a[N];   long long rr[N];   void solve(long long t_case) {     cin >> n >> k;     for (long long i = 1; i <= n; i++) {       cin >> a[i];     }     auto check2 = [&](long long b, long long a) -> long long {       return (a - 3ll * b * b - 1);     };     auto check = [&](long long mm) -> bool {       long long cnt = 0;       for (long long i = 1; i <= n; i++) {         long long l = 0, r = a[i];         while (l < r) {           long long m = (l + r + 1) >> 1;           if (check2(m, a[i]) >= mm)             l = m;           else             r = m - 1;         }         rr[i] = l;         cnt += l;       }       return (cnt >= k);     };     long long l = -inf, r = inf;     while (l < r) {       long long m = (l + r + 1) >> 1;       if (check(m))         l = m;       else         r = m - 1;     }     check(l);     long long cnt = 0;     for (long long i = 1; i <= n; i++) cnt += rr[i];     cnt -= k;     for (long long i = 1; i <= n && cnt; i++) {       if (rr[i] && check2(rr[i], a[i]) == l) cnt--, rr[i]--;     }     for (long long i = 1; i <= n; i++) cout << rr[i] <<    ;     cout <<   n ;   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     if (0) {       long long t;       cin >> t;       for (long long t_case = 1; t_case <= t; t_case++) solve(t_case);     } else       solve(1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, m, val, sum = 0;     cin >> n;     vector<long long> v, q;     for (long long i = 0; i < n; i++) {       cin >> val;       v.push_back(val);       sum += val;     }     sort(v.begin(), v.end());     reverse(v.begin(), v.end());     cin >> m;     for (long long i = 0; i < m; i++) {       cin >> val;       cout << sum - v[val - 1] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bitset<300000010> su;   int main() {     su[1] = 1;     int l, r, ans = 0;     cin >> l >> r;     if (l < 3 && r > 1) ans++;     for (int i = 3; i * i <= r; i += 2)       if (!su[i])         for (long long j = 1LL * i * i; j <= r; j += i << 1) su[j] = 1;     while (l % 4 != 1) l++;     for (int i = l; i <= r; i += 4)       if (!su[i]) ans++;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int power(long long x, unsigned int y, int p) {     long long res = 1;     x = x % p;     if (x == 0) return 0;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   int main() {     long long n, p;     cin >> n >> p;     cout << (power(3, n, p) * 1ll + p * 1ll - 1ll) % p;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10;   string s1, s2;   int n, m;   long long dp[maxn][3][3];   int p1[maxn], p2[maxn];   int f(char a) { return a ==  G  ? 0 : (a ==  R  ? 1 : 2); }   void init(const string s, int n, const string t, int m, int p[]) {     p[0] = 0;     while (p[0] < m && s[0] != t[p[0]]) p[0]++;     p[0] = min(p[0], m - 1);     for (int i = 1; i < n; i++) {       p[i] = p[i - 1] + 1;       while (p[i] < m && s[i] != t[p[i]]) p[i]++;       p[i] = min(p[i], m - 1);     }   }   int main() {     cin >> s1;     cin >> s2;     n = s1.size();     m = s2.size();     init(s1, n, s2, m, p1);     init(s2, m, s1, n, p2);     memset(dp, 0ll, sizeof(dp));     for (int i = 1; i < m; i++) {       for (int j = 0; j < 3; j++) {         for (int k = 0; k < 3; k++) {           if (f(s2[i - 1]) == j && f(s2[i]) == k)             dp[i][j][k] = dp[i - 1][j][k] + 1;           else             dp[i][j][k] = dp[i - 1][j][k];         }       }     }     long long ret = 0;     int l = 0, r;     for (int i = 0; i < n; i++) {       r = p1[i];       while (l < m && p2[l] < i) l++;       ret += max(r - l + 1, 0);       if (i && l <= r) {         int j = f(s1[i - 1]), k = f(s1[i]);         if (j != k) {           ret -= dp[r][k][j];           if (l - 1 >= 0) ret += dp[l - 1][k][j];         }       }     }     cout << ret << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int house[300010];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     int a, b, c, d;     for (int i = 0; i < n; ++i) cin >> house[i];     a = house[0];     d = house[n - 1];     if (a != d) {       cout << n - 1 << endl;       return 0;     }     int i = 0;     while (house[++i] == a)       ;     int j = n;     while (house[--j] == d)       ;     cout << max(n - i - 1, j + 1 - 1) << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int dl = 10069;   void bib() {     for (int i = 0; i < (int)10; i++) {       cout <<   a ;     }   }   const int M = 4 * 3 * 100 * 1000 + 10;   int seg[M];   int ans[M / 2];   int n, m;   void battle(int s, int e, int winner, int l = 0, int r = n, int id = 1) {     if (s >= r || e <= l) return;     if (seg[id] != -1) return;     if (s <= l && r <= e && (winner < l || winner >= r)) {       seg[id] = winner;     }     if (r - l < 2) return;     int mid = (r + l) / 2;     battle(s, e, winner, l, mid, id * 2);     battle(s, e, winner, mid, r, id * 2 + 1);   }   void print(int l = 0, int r = n, int id = 1) {     if (r - l == 1) {       ans[l] = seg[id] + 1;       return;     }     int mid = (l + r) / 2;     print(l, mid, id * 2);     print(mid, r, id * 2 + 1);   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     for (int i = 0; i < (int)M; i++) seg[i] = -1;     for (int i = 0; i < (int)m; i++) {       int l, r, x;       cin >> l >> r >> x;       l--;       x--;       battle(l, r, x);     }     print();     for (int i = 0; i < (int)n; i++) {       cout << ans[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   int a[510];   int dp[510][510];   int dfs(int l, int r) {     if (dp[l][r] != -1) {       return dp[l][r];     }     if (l > r) {       return 0;     }     if (l == r) {       return 1;     }     int mi = 1 + dfs(l + 1, r);     if (a[l] == a[l + 1]) {       mi = min(mi, 1 + dfs(l + 2, r));     }     for (int i = l + 2; i <= r; ++i) {       if (a[i] == a[l]) {         mi = min(mi, dfs(l + 1, i - 1) + dfs(i + 1, r));       }     }     return dp[l][r] = mi;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);     }     memset(dp, -1, sizeof(dp));     printf( %d n , dfs(0, n - 1));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       long long n, a, b, c, d;       cin >> n >> a >> b >> c >> d;       int x = 0;       if (((c + d) < n * (a - b)) || ((c - d) > n * (a + b)))         cout <<  No  << endl;       else         cout <<  Yes  << endl;     }     return 0;   }