#include <bits/stdc++.h>   static const int MAXN = 100005;   int n = 0, m, ans_len = 0;   char s[MAXN], ans[MAXN] = {  0 };   std::pair<char, int> p[MAXN];   std::set<int> marked;   std::multiset<int> distance;   int main() {     scanf( %d , &m);     getchar();     while ((s[n] = getchar()) >=  a  && s[n] <=  z ) ++n;     for (int i = 0; i < n; ++i) p[i] = std::make_pair(s[i], i);     std::sort(p, p + n);     marked.insert(-1);     marked.insert(n);     distance.insert(n + 1);     for (char c =  a ; c <=  z ; ++c) {       for (int i = 0; i < n; ++i)         if (p[i].first == c) {           std::set<int>::iterator prev = marked.lower_bound(p[i].second),                                   succ = prev--;           int j = i + 1;           while (j < n && p[j].first == c && p[j].second < *succ) ++j;           int last_marked = *prev;           if (*succ <= last_marked + m) continue;           for (int k = i; k < j; ++k) {             while (k < j && p[k].second <= last_marked + m) ++k;             --k;             if (k < i || p[k].second == last_marked) break;             prev = marked.lower_bound(p[k].second), succ = prev--;             ans[ans_len++] = p[k].first;             marked.insert(p[k].second);             distance.erase(distance.find(*succ - *prev));             distance.insert(*succ - p[k].second);             distance.insert(p[k].second - *prev);             last_marked = p[k].second;             if (*succ <= last_marked + m) break;           }           i = j - 1;         }       if (*(distance.rbegin()) <= m) break;       for (int i = 0; i < n; ++i)         if (p[i].first == c) {           if (marked.find(p[i].second) != marked.end()) continue;           std::set<int>::iterator prev = marked.lower_bound(p[i].second),                                   succ = prev--;           ans[ans_len++] = p[i].first;           marked.insert(p[i].second);           distance.erase(distance.find(*succ - *prev));           distance.insert(*succ - p[i].second);           distance.insert(p[i].second - *prev);         }     }     puts(ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char vis[305][305];   int main() {     int n;     cin >> n;     vector<int> v(n);     for (int i = 0; i < n; i++) cin >> v[i];     char c;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         cin >> vis[i][j];       }     }     for (int k = 0; k < n; k++) {       for (int i = 0; i < n; i++) {         for (int j = 0; j < n; j++) {           if (vis[i][k] ==  1  && vis[k][j] ==  1 ) vis[i][j] =  1 ;         }       }     }     for (int i = 0; i < n; i++) {       int in = i;       for (int j = i + 1; j < n; j++) {         if (v[in] > v[j] && vis[in][j] ==  1 ) {           in = j;         }       }       swap(v[i], v[in]);     }     for (int i = 0; i < n; i++) cout << v[i] <<    ;     return 0;   }


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


#include <bits/stdc++.h>   template <typename T>   class IntegerIterator       : public std::iterator<std::input_iterator_tag, T, std::ptrdiff_t, T*, T> {    public:     explicit IntegerIterator(T value) : value(value) {}     IntegerIterator& operator++() {       ++value;       return *this;     }     IntegerIterator operator++(int) {       IntegerIterator copy = *this;       ++value;       return copy;     }     IntegerIterator& operator--() {       --value;       return *this;     }     IntegerIterator operator--(int) {       IntegerIterator copy = *this;       --value;       return copy;     }     T operator*() const { return value; }     bool operator==(IntegerIterator rhs) const { return value == rhs.value; }     bool operator!=(IntegerIterator rhs) const { return !(*this == rhs); }       private:     T value;   };   template <typename T>   class IntegerRange {    public:     IntegerRange(T begin, T end) : begin_(begin), end_(end) { ; }     IntegerIterator<T> begin() const { return IntegerIterator<T>(begin_); }     IntegerIterator<T> end() const { return IntegerIterator<T>(end_); }       private:     T begin_;     T end_;   };   template <typename T>   class ReversedIntegerRange {     using IteratorType = std::reverse_iterator<IntegerIterator<T>>;       public:     ReversedIntegerRange(T begin, T end) : begin_(begin), end_(end) { ; }     IteratorType begin() const {       return IteratorType(IntegerIterator<T>(begin_));     }     IteratorType end() const { return IteratorType(IntegerIterator<T>(end_)); }       private:     T begin_;     T end_;   };   template <typename T>   IntegerRange<T> range(T to) {     return IntegerRange<T>(0, to);   }   template <typename T>   IntegerRange<T> range(T from, T to) {     return IntegerRange<T>(from, to);   }   template <typename T>   IntegerRange<T> inclusiveRange(T to) {     return IntegerRange<T>(0, to + 1);   }   template <typename T>   IntegerRange<T> inclusiveRange(T from, T to) {     return IntegerRange<T>(from, to + 1);   }   template <typename T>   ReversedIntegerRange<T> downrange(T from) {     return ReversedIntegerRange<T>(from, 0);   }   template <typename T>   ReversedIntegerRange<T> downrange(T from, T to) {     return ReversedIntegerRange<T>(from, to);   }   template <typename T>   ReversedIntegerRange<T> inclusiveDownrange(T from) {     return ReversedIntegerRange<T>(from + 1, 0);   }   template <typename T>   ReversedIntegerRange<T> inclusiveDownrange(T from, T to) {     return ReversedIntegerRange<T>(from + 1, to);   }   std::vector<int> linearSieve(int maxN) {     ;     std::vector<int> leastPrimes(maxN + 1);     std::vector<int> primes;     for (int i = 2; i <= maxN; ++i) {       if (leastPrimes[i] == 0) {         leastPrimes[i] = i;         primes.push_back(i);       }       for (int prime : primes) {         if (i * prime > maxN) {           break;         }         leastPrimes[i * prime] = prime;       }     }     return leastPrimes;   }   template <typename T>   T gcd(T a, T b) {     while (b) {       T tmp = a % b;       a = b;       b = tmp;     }     return a;   }   template <typename R>   void sort(R& range) {     std::sort(range.begin(), range.end());   }   template <typename R, typename Comp>   void sort(R& range, Comp comp) {     std::sort(range.begin(), range.end(), comp);   }   template <typename R>   void reverse(R& range) {     std::reverse(range.begin(), range.end());   }   template <typename R, typename T>   auto lower_bound(const R& range, const T& value) -> decltype(range.begin()) {     return std::lower_bound(range.begin(), range.end(), value);   }   template <typename R, typename T, typename Comp>   auto lower_bound(const R& range, const T& value, Comp comp)       -> decltype(range.begin()) {     return std::lower_bound(range.begin(), range.end(), value, comp);   }   template <typename R, typename T>   auto upper_bound(const R& range, const T& value) -> decltype(range.begin()) {     return std::upper_bound(range.begin(), range.end(), value);   }   template <typename R, typename T, typename Comp>   auto upper_bound(const R& range, const T& value, Comp comp)       -> decltype(range.begin()) {     return std::upper_bound(range.begin(), range.end(), value, comp);   }   template <typename R>   auto min_element(const R& range) -> decltype(range.begin()) {     return std::min_element(range.begin(), range.end());   }   template <typename R>   auto max_element(const R& range) -> decltype(range.begin()) {     return std::max_element(range.begin(), range.end());   }   template <typename R>   bool next_permutation(R& range) {     return std::next_permutation(range.begin(), range.end());   }   template <typename T>   void unique(std::vector<T>& range) {     range.erase(std::unique(range.begin(), range.end()), range.end());   }   template <typename R>   R sorted(R range) {     sort(range);     return range;   }   template <typename R, typename Comp>   R sorted(R range, Comp comp) {     sort(range, comp);     return range;   }   template <typename R>   R reversed(R range) {     reverse(range);     return range;   }   using namespace std;   class TaskF {    public:     void solve(std::istream& in, std::ostream& out) {       int n;       in >> n;       vector<int> a(n);       int magic = 300000;       auto lp = linearSieve(magic);       int globalGcd = 0;       for (int i : range(n)) {         in >> a[i];         auto& c = a[i];         while (c != 1 && c % (lp[c] * lp[c]) == 0) {           c /= lp[c];         }         globalGcd = gcd(globalGcd, a[i]);       }       if (globalGcd != 1) {         out << -1;         return;         ;       }       sort(a);       unique(a);       vector<int64_t> cnt(magic);       for (int x : a) {         ++cnt[x];       }       vector<int64_t> cntsev = cnt;       for (int i = 1;; ++i) {         if (cntsev[1]) {           out << i <<   n ;           return;         }         vector<int64_t> cntsum(magic);         for (int x : downrange(magic, 1)) {           for (int t = x; t < magic; t += x) {             cntsum[x] += cnt[t];           }         }         vector<int64_t> cntsevsum(magic);         for (int x : downrange(magic, 1)) {           for (int t = x; t < magic; t += x) {             cntsevsum[x] += cntsev[t];           }         }         vector<int64_t> cntnextsum(magic);         for (int x : downrange(magic, 1)) {           cntnextsum[x] = cntsevsum[x] * cntsum[x];         }         vector<int64_t> cntnext = cntnextsum;         for (int x : downrange(magic, 1)) {           for (int t = 2 * x; t < magic; t += x) {             cntnext[x] -= cntnext[t];           }         }         for (int x : downrange(magic, 1)) {           if (cntnext[x] != 0) {             cntnext[x] = 1;           }         }         cntsev = cntnext;       }     }   };   int main() {     std::ios_base::sync_with_stdio(false);     TaskF solver;     std::istream& in(std::cin);     std::ostream& out(std::cout);     in.tie(nullptr);     out << std::fixed;     out.precision(20);     solver.solve(in, out);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<vector<int>, int> mp;   map<int, int> dp[100050];   set<int> ans;   vector<int> vec[100050];   int n, cnt = 0;   int getid(vector<int> t) {     if (mp.find(t) == mp.end())       return mp[t] = ++cnt;     else       return mp[t];   }   int getv(int x, int y) {     if (dp[x].find(y) != dp[x].end()) return dp[x][y];     vector<int> tmp;     tmp.clear();     for (int i = 0; i <= (int)vec[x].size() - 1; i++) {       int t = vec[x][i];       if (t == y) continue;       tmp.push_back(getv(t, x));     }     sort(tmp.begin(), tmp.end());     return dp[x][y] = getid(tmp);   }   int main() {     scanf( %d , &n);     for (int i = 2; i <= n; i++) {       int x, y;       scanf( %d%d , &x, &y);       vec[x].push_back(y), vec[y].push_back(x);     }     for (int i = 1; i <= n; i++)       if ((int)vec[i].size() < 4) ans.insert(getv(i, 0));     printf( %d n , (int)ans.size());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct people {     int a, d, id;     bool operator<(people other) const {       if (a != other.a) return a > other.a;       return id < other.id;     }   };   people s[111];   int n;   int main() {     int i, j, ans = 0;     scanf( %d , &n);     for (i = 1; i <= n; ++i) {       scanf( %d%d , &s[i].a, &s[i].d);       s[i].id = i;     }     sort(s + 1, s + 1 + n);     vector<int> ret;     for (i = 1; i <= n; ++i) {       if (s[i].d < 0) {         ret.push_back(s[i].id);       }     }     for (auto v : ret) {       for (i = 1; i <= n; ++i) {         if (s[i].id == v) {           j = i;           while (j < n &&                  (s[j].a + s[j].d < s[j + 1].a ||                   (s[j].a + s[j].d == s[j + 1].a && s[j].id > s[j + 1].id))) {             swap(s[j], s[j + 1]);             ans++;             j++;           }           s[j].a = s[j].a + s[j].d;           break;         }       }     }     ret.clear();     for (i = n; i >= 1; --i) {       if (s[i].d > 0) {         ret.push_back(s[i].id);       }     }     for (auto v : ret) {       for (i = n; i >= 1; --i) {         if (s[i].id == v) {           j = i;           while (j > 1 &&                  (s[j].a + s[j].d > s[j - 1].a ||                   (s[j].a + s[j].d == s[j - 1].a && s[j].id < s[j - 1].id))) {             swap(s[j], s[j - 1]);             ans++;             j--;           }           s[j].a = s[j].a + s[j].d;           break;         }       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int N = 2e5 + 5;   struct tree {     int l, r, add, lv, rv;     ll sum;   } tr[N << 2];   int n, q, a[N];   void Add(int rt, int x) {     tr[rt].lv = tr[rt].rv = tr[rt].add = x;     tr[rt].sum = 1ll * (tr[rt].r - tr[rt].l + 1) * x;   }   void Pushdown(int rt) {     if (tr[rt].add) {       Add(rt << 1, tr[rt].add);       Add(rt << 1 | 1, tr[rt].add);       tr[rt].add = 0;     }   }   void Pushup(int rt) {     tr[rt].lv = tr[rt << 1].lv;     tr[rt].rv = tr[rt << 1 | 1].rv;     tr[rt].sum = tr[rt << 1].sum + tr[rt << 1 | 1].sum;   }   void Build(int rt, int l, int r) {     tr[rt].l = l, tr[rt].r = r;     if (l == r) {       tr[rt].sum = tr[rt].lv = tr[rt].rv = a[l];       tr[rt].add = 0;       return;     }     int mid = (l + r) >> 1;     Build(rt << 1, l, mid), Build(rt << 1 | 1, mid + 1, r);     Pushup(rt);   }   void Modify(int rt, int x, int y) {     if (tr[rt].l > x) return;     if (tr[rt].rv >= y) return;     if (tr[rt].lv <= y && tr[rt].r <= x) return Add(rt, y);     Pushdown(rt);     Modify(rt << 1, x, y), Modify(rt << 1 | 1, x, y);     Pushup(rt);   }   int Ask(int rt, int x, int &y) {     if (y < tr[rt].rv || tr[rt].r < x) return 0;     int ret = 0;     if (tr[rt].l >= x && tr[rt].sum <= y)       return y -= tr[rt].sum, x = tr[rt].r + 1, tr[rt].r - tr[rt].l + 1;     if (tr[rt].l == tr[rt].r) return 0;     Pushdown(rt);     ret += Ask(rt << 1, x, y);     ret += Ask(rt << 1 | 1, x, y);     return ret;   }   int main() {     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; ++i) scanf( %d , a + i);     Build(1, 1, n);     while (q--) {       int op, x, y;       scanf( %d%d%d , &op, &x, &y);       if (op == 1)         Modify(1, x, y);       else         printf( %d n , Ask(1, x, y));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read(T &x) {     x = 0;     char ch = getchar();     int fh = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) fh = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     x *= fh;   }   struct Po {     long long x, y, t;   } po[200010];   struct shj {     long long t, x, zh;   } a[200010];   int n, l;   bool an1[2000010], an2[2000010];   bool c1(const shj &a, const shj &b) { return a.t < b.t; }   int main() {     read(n);     read(l);     for (int i = 1; i <= n; i++) {       read(po[i].t);       read(po[i].x);       read(po[i].y);     }     for (int i = 1; i <= n; i++) {       a[i].t = po[i].t % l;       a[i].x = po[i].x + po[i].y + po[i].t;       if (a[i].x % 2 == 1 || a[i].x < 0) {         puts( NO );         return 0;       } else         a[i].x /= 2;       a[i].zh = po[i].t / l;     }     a[n + 1] = (shj){0, 0, 0};     a[n + 2] = (shj){l, 0, -1};     sort(a + 1, a + n + 3, c1);     long long nl = 0, nr = l;     for (int i = 1; i <= n + 1; i++) {       long long x = a[i + 1].t - a[i].t, y = a[i + 1].zh - a[i].zh,                 z = a[i + 1].x - a[i].x;       if (y > 0) {         if ((z - x) % y == 0)           nl = max(nl, (z - x) / y);         else           nl = max(nl, (z - x) / y + 1);         nr = min(nr, z / y);       }       if (y < 0) {         z = -z;         y = -y;         if (z % y == 0)           nl = max(nl, z / y);         else           nl = max(nl, z / y + 1);         nr = min(nr, (z + x) / y);       }     }     if (nl > nr) {       puts( NO );       return 0;     }     for (int i = 1; i <= n + 1; i++) {       long long su = a[i + 1].x - a[i].x - (a[i + 1].zh - a[i].zh) * nl;       for (int j = a[i].t + 1; j <= a[i + 1].t; j++)         if (su) {           an1[j] = 1;           su--;         } else           an1[j] = 0;     }     for (int i = 1; i <= n; i++) {       a[i].t = po[i].t % l;       a[i].x = po[i].y - po[i].x + po[i].t;       if (a[i].x % 2 == 1 || a[i].x < 0) {         puts( NO );         return 0;       } else         a[i].x /= 2;       a[i].zh = po[i].t / l;     }     a[n + 1] = (shj){0, 0, 0};     a[n + 2] = (shj){l, 0, -1};     sort(a + 1, a + n + 3, c1);     nl = 0, nr = l;     for (int i = 1; i <= n + 1; i++) {       long long x = a[i + 1].t - a[i].t, y = a[i + 1].zh - a[i].zh,                 z = a[i + 1].x - a[i].x;       if (y > 0) {         if ((z - x) % y == 0)           nl = max(nl, (z - x) / y);         else           nl = max(nl, (z - x) / y + 1);         nr = min(nr, z / y);       }       if (y < 0) {         z = -z;         y = -y;         if (z % y == 0)           nl = max(nl, z / y);         else           nl = max(nl, z / y + 1);         nr = min(nr, (z + x) / y);       }     }     if (nl > nr) {       puts( NO );       return 0;     }     for (int i = 1; i <= n + 1; i++) {       long long su = a[i + 1].x - a[i].x - (a[i + 1].zh - a[i].zh) * nl;       for (int j = a[i].t + 1; j <= a[i + 1].t; j++) {         if (su) {           an2[j] = 1;           su--;         } else           an2[j] = 0;       }     }     for (int i = 1; i <= l; i++) printf( %c ,  DLRU [2 * an1[i] + an2[i]]);     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long const N = 35;   long long dp[N][2][2];   long long get(long long l, long long r) {     if (l < 0 || r < 0) return 0;     memset(dp, 0, sizeof dp);     dp[35][1][1] = 1;     for (long long i = 34; i >= 0; i--) {       for (long long j = 0; j <= 1; j++) {         for (long long k = 0; k <= 1; k++) {           long long x = (j && !((l >> i) & 1ll)), y = (k && !((r >> i) & 1ll));           dp[i][x][y] += dp[i + 1][j][k];           if (!j || ((l >> i) & 1ll)) dp[i][j][y] += dp[i + 1][j][k];           if (!k || ((r >> i) & 1ll)) dp[i][x][k] += dp[i + 1][j][k];         }       }     }     return dp[0][0][0] + dp[0][1][0] + dp[0][1][1] + dp[0][0][1];   }   signed main() {     long long T, l, r;     scanf( %lld , &T);     while (T--) {       scanf( %lld%lld , &l, &r);       long long ans = get(r, r) - get(l - 1, r) * 2 + get(l - 1, l - 1);       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void task();   int main() {     task();     return 0;   }   const int N = 6400 + 2;   const int S = N - 2;   const int T = N - 1;   struct Rib {     int to;     int cap;     int flow;     int back;     int cost;   };   const int INF = 0x3f3f3f3f;   vector<Rib> g[N];   int n, m;   int a[81][81];   const int shift[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};   pair<int, int> par[N];   int d[N];   int in[N];   int ok(int i, int j) { return i >= 0 && i < n && j >= 0 && j < m; }   void add_rib(int a, int b, int cap, int cost) {     g[a].push_back(Rib{b, cap, 0, ((int)((g[b]).size())), cost});     g[b].push_back(Rib{a, 0, 0, ((int)((g[a]).size())) - 1, -cost});   }   int get_id(int i, int j) { return (i * m + j) / 2 + ((i + j) % 2) * n * m / 2; }   int spfa() {     memset(d, 0x3f, sizeof(d));     d[S] = 0;     deque<int> q;     q.push_back(S);     in[S] = 1;     while (!q.empty()) {       int v = q.front();       q.pop_front();       in[v] = 0;       int i = 0;       for (Rib& r : g[v]) {         if (r.cap - r.flow && d[v] + r.cost < d[r.to]) {           d[r.to] = d[v] + r.cost;           par[r.to] = pair<int, int>{v, i};           if (!in[r.to]) q.push_back(r.to);           in[r.to] = 1;         }         ++i;       }     }     return d[T] != INF;   }   int mcmf() {     int res = 0;     while (spfa()) {       ++res;       int v = T;       while (v != S) {         Rib& r = g[par[v].first][par[v].second];         r.flow++;         g[r.to][r.back].flow--;         v = par[v].first;       }     }     return res;   }   void task() {     scanf( %d %d , &n, &m);     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) scanf( %d , &a[i][j]);     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) {         if ((i + j) % 2) {           add_rib(get_id(i, j), T, 1, 0);         } else {           add_rib(S, get_id(i, j), 1, 0);           for (int h = 0; h < 4; ++h) {             int ii = i + shift[h][0];             int jj = j + shift[h][1];             if (!ok(ii, jj)) continue;             add_rib(get_id(i, j), get_id(ii, jj), 1, a[i][j] != a[ii][jj]);           }         }       }     mcmf();     int ans = 0;     for (int i = 0; i < n * m / 2; ++i)       for (Rib& r : g[i])         if (r.flow > 0) ans += r.cost;     printf( %d , ans);   }


#include <bits/stdc++.h>   using namespace std;   struct Node {     bool fr;     int lb, rb;     Node *lc, *rc;   };   void buildSeg(Node *&p, int l, int r) {     p = new Node;     p->fr = true;     p->lb = l;     p->rb = r;     if (p->lb < p->rb) {       int mid = (p->lb + p->rb) / 2;       buildSeg(p->lc, p->lb, mid);       buildSeg(p->rc, mid + 1, p->rb);     }   }   void setVal(Node *p, int x, bool val) {     if (p->lb == p->rb)       p->fr = val;     else {       int mid = (p->lb + p->rb) / 2;       if (x <= mid)         setVal(p->lc, x, val);       else         setVal(p->rc, x, val);       p->fr = p->lc->fr | p->rc->fr;     }   }   int findFr(Node *p, int l, int r) {     if (p->fr) {       if (p->lb == p->rb)         return p->lb;       else {         int mid = (p->lb + p->rb) / 2, ret = -1;         if (l <= mid) ret = findFr(p->lc, l, r);         if ((mid + 1 <= r) && (ret == -1)) ret = findFr(p->rc, l, r);         return ret;       }     }     return -1;   }   const int _N = 200010;   int h, m, n, ptN, pt[_N];   long long cost;   pair<int, int> inP[_N];   Node *rt;   map<int, int> ps;   void initSeg() {     ptN = 0;     int cnt = 0;     for (int i = 0; i < h; i++) inP[i].first = -1;     for (int i = 0; i < h; i++)       if (inP[i].first == -1) {         pt[ptN] = cnt;         for (int j = i; inP[j].first == -1; j = (j + m) % h)           inP[j] = pair<int, int>(ptN, cnt++);         ptN++;       }     pt[ptN] = cnt;     buildSeg(rt, 0, cnt - 1);   }   void pushHash(int i, int v) {     int p = findFr(rt, inP[v].second, pt[inP[v].first + 1] - 1);     if (p == -1) p = findFr(rt, pt[inP[v].first], inP[v].second - 1);     setVal(rt, p, false);     ps.insert(pair<int, int>(i, p));     cost += (p >= inP[v].second)                 ? (p - inP[v].second)                 : (pt[inP[v].first + 1] - inP[v].second + p - pt[inP[v].first]);   }   void popHash(int i) {     map<int, int>::iterator x = ps.find(i);     setVal(rt, x->second, true);     ps.erase(x);   }   int main() {     ios::sync_with_stdio(false);     cin >> h >> m >> n;     initSeg();     cost = 0;     for (int k = 0; k < n; k++) {       char c;       int i;       cin >> c >> i;       if (c ==  + ) {         int v;         cin >> v;         pushHash(i, v);       } else         popHash(i);     }     cout << cost << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1000000007;   long long mod2 = 998244353;   long long mod3 = 1000003;   long long mod4 = 998244853;   long long mod5 = 1000000009;   long long inf = 1LL << 60;   double pi = 3.141592653589793238462643383279L;   double eps = 1e-9;   int dh[4] = {1, -1, 0, 0};   int dw[4] = {0, 0, 1, -1};   int ddh[8] = {-1, -1, -1, 0, 0, 1, 1, 1};   int ddw[8] = {-1, 0, 1, -1, 1, -1, 0, 1};   long long gcd(long long a, long long b) {     if (a < b) swap(a, b);     if (b == 0) return a;     if (a % b == 0) return b;     return gcd(b, a % b);   }   long long Pow(long long n, long long k) {     long long ret = 1;     long long now = n;     while (k > 0) {       if (k & 1) ret *= now;       now *= now;       k /= 2;     }     return ret;   }   long long beki(long long n, long long k, long long md) {     long long ret = 1;     long long now = n;     while (k > 0) {       if (k % 2 == 1) {         ret *= now;         ret %= md;       }       now *= now;       now %= md;       k /= 2;     }     return ret;   }   long long gyaku(long long n, long long md) { return beki(n, md - 2, md); }   long long popcount(long long n) {     long long ret = 0;     long long u = n;     while (u > 0) {       ret += u % 2;       u /= 2;     }     return ret;   }   struct BIT {    private:     long long u;     vector<long long> bit;       public:     BIT(long long n) {       u = 1;       while (u < n) u *= 2;       bit.resize(u + 10, 0);     }     void add(long long n, long long x) {       long long i = n;       bit[i] += x;       bit[i] %= mod;       while (i < u) {         i += i & (-i);         bit[i] += x;         bit[i] %= mod;       }     }     long long sum(long long n) {       long long i = n;       long long ret = 0;       while (i > 0) {         ret += bit[i];         i -= i & (-i);         ret %= mod;       }       return ret;     }   };   long long gya[1000010];   long long kai[1000010];   void nckinit(long long n, long long md) {     kai[0] = 1;     kai[1] = 1;     for (int i = 2; i <= n; i++) {       kai[i] = kai[i - 1] * i;       kai[i] %= md;     }     gya[n] = gyaku(kai[n], md);     for (int i = n - 1; i >= 1; i--) {       gya[i] = gya[i + 1] * (i + 1);       gya[i] %= md;     }     gya[0] = 1;   }   long long nck(long long n, long long k, long long md) {     if (k < 0) return 0;     if (k == 0 || n == k) return 1;     long long ret = kai[n];     ret *= gya[n - k];     ret %= md;     ret *= gya[k];     ret %= md;     return ret;   }   long long npk(long long n, long long k, long long md) {     if (k < 0) return 0;     if (k == 0) return 1;     long long ret = kai[n];     ret *= gya[n - k];     ret %= md;     return ret;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     long long p[n];     long long l = 0;     bool used[n + 1];     fill(used, used + n + 1, false);     long long pla[n + 1];     for (long long i = 0; i < n; i++) {       cin >> p[i];       if (p[i] == -1)         l++;       else {         used[p[i]] = true;         pla[p[i]] = i + 1;       }     }     long long dp[l + 1];     dp[0] = 0;     dp[1] = 0;     nckinit(n + 1, mod2);     for (long long i = 2; i < l + 1; i++) {       dp[i] = i * (i - 1) / 2;       dp[i] %= mod2;       (dp[i] *= kai[i - 1]) %= mod2;       (dp[i] += dp[i - 1] * i) %= mod2;     }     long long su[n + 1];     su[n] = 0;     for (long long i = n - 1; i >= 0; i--) {       su[i] = su[i + 1];       if (p[i] == -1) su[i]++;     }     long long cnt = 0;     BIT bit(n + 1);     long long ans = dp[l];     for (long long i = n; i >= 1; i--) {       if (used[i]) {         long long r = bit.sum(pla[i]);         (ans += r * kai[l]) %= mod2;         bit.add(pla[i], 1);         cnt += su[pla[i] - 1];         cnt %= mod2;       } else {         (ans += cnt * kai[l - 1]) %= mod2;       }     }     long long su2[n + 1];     su2[0] = 0;     for (long long i = 0; i < n; i++) {       su2[i + 1] = su2[i];       if (p[i] == -1) su2[i + 1]++;     }     cnt = 0;     for (long long i = 1; i < n + 1; i++) {       if (used[i]) {         cnt += su2[pla[i]];         cnt %= mod2;       } else {         (ans += cnt * kai[l - 1]) %= mod2;       }     }     ans *= gya[l];     cout << ans % mod2 << endl;   }


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


#include <bits/stdc++.h>   using namespace std;   const long long INF = LLONG_MAX;   const int mxn = 1011;   bool DEBUG = 0;   string s[mxn];   bool grid[mxn][mxn], chg[mxn][mxn];   long long dist[mxn][mxn];   const int dx[] = {-1, 0, 1, 0};   const int dy[] = {0, -1, 0, 1};   int n, m;   bool check(int x, int y) {     if (0 <= x && x < n && 0 <= y && y < m) return 1;     return 0;   }   void init() {     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (chg[i][j]) continue;         bool f = 0;         for (int k = 0; k < 4 && !f; k++) {           int x = i + dx[k];           int y = j + dy[k];           if (!check(x, y)) continue;           if (grid[x][y] == grid[i][j]) {             f = 1;             chg[x][y] = 1;           }         }         if (f)           chg[i][j] = 1;         else           chg[i][j] = 0;       }     }   }   void bfs(int x, int y) {     queue<pair<int, int> > q;     q.push(pair<int, int>(x, y));     while (!q.empty()) {       pair<int, int> now = q.front();       x = now.first;       y = now.second;       q.pop();       for (int i = 0; i < 4; i++) {         int X = x + dx[i];         int Y = y + dy[i];         if (!check(X, Y)) continue;         if (dist[x][y] + 1 < dist[X][Y]) {           dist[X][Y] = dist[x][y] + 1;           q.push(pair<int, int>(X, Y));         }       }     }     return;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int q;     cin >> n >> m >> q;     for (int i = 0; i < n; i++) {       cin >> s[i];       for (int j = 0; j < m; j++) {         grid[i][j] = s[i][j] ==  1 ;       }     }     init();     vector<pair<int, int> > visit;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (chg[i][j]) {           dist[i][j] = 0;           visit.emplace_back(i, j);         } else {           dist[i][j] = 1e18 + 1;         }       }     }     for (auto cor : visit) {       bfs(cor.first, cor.second);     }     int a, b;     long long t;     while (q--) {       cin >> a >> b >> t;       a--;       b--;       if (t < dist[a][b]) {         cout << grid[a][b] <<   n ;       } else {         t -= dist[a][b];         if (t % 2)           cout << int(grid[a][b] ^ 1) <<   n ;         else           cout << grid[a][b] <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     cin >> q;     while (q--) {       map<char, long long int> d;       string p;       int n, m;       cin >> n >> m;       cin >> p;       vector<map<char, long long int>> x(n + 2);       for (int i = 0; i < n; i++) {         x[i][p[i]]++;         for (char j =  a ; j <=  z ; j++) {           x[i + 1][j] = x[i][j];           if (i == n - 1) d[j] = x[i][j];         }       }       for (int i = 0; i < m; i++) {         int y;         cin >> y;         y--;         for (char j =  a ; j <=  z ; j++) {           d[j] += x[y][j];         }       }       for (char j =  a ; j <=  z ; j++) {         cout << d[j] <<    ;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read(T &x) {     x = 0;     char c = getchar();     T sig = 1;     for (; !isdigit(c); c = getchar())       if (c ==  - ) sig = -1;     for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c -  0 ;     x *= sig;   }   class Solution {    public:     void solve() {       int n;       read(n);       set<pair<int, int>> s;       for (int i = 0; i < n; ++i) {         string t;         cin >> t;         int b = 0;         for (char c : t) b += c ==  B ;         s.insert({b, t.size() - b});       };       vector<pair<int, int>> vs(s.begin(), s.end());       auto check = [&](int l, bool output) {         int xl = 0, xr = 5e5, yl = 0, yr = 5e5, zl = -5e5, zr = 5e5;         for (auto p : vs) {           xl = max(xl, p.first - l);           xr = min(xr, p.first + l);           yl = max(yl, p.second - l);           yr = min(yr, p.second + l);           zl = max(zl, p.first - p.second - l);           zr = min(zr, p.first - p.second + l);         }         if (xl > xr || yl > yr || zl > zr) return false;         int zl1 = xl - yr, zr1 = xr - yl;         if (output) {           int x = min(xr, zr + yr);           int y = min(yr, x - zl);           string s(x,  B ), t(y,  N );           printf( %s , (s + t).c_str());         }         return max(zl, zl1) <= min(zr, zr1);       };       int lo = 0, hi = 1e6;       while (lo <= hi) {         int mid = (lo + hi) >> 1;         if (check(mid, false))           hi = mid - 1;         else           lo = mid + 1;       }       printf( %d n , lo);       check(lo, true);     }   };   int main() {     Solution solution = Solution();     solution.solve();   }


#include <bits/stdc++.h>   using namespace std;   long long mult(long long a, long long b, long long p = 1000000007) {     long long ans = a;     ans *= b;     return ((ans >= p) ? ans % p : ans);   }   long long add(long long a, long long b, long long p = 1000000007) {     long long ans = a + b;     return ((ans >= p) ? ans - p : ans);   }   long long fpow(long long n, long long k, long long p = 1000000007) {     long long r = 1;     for (; k; k >>= 1) {       if (k & 1) r = r * n % p;       n = n * n % p;     }     return r;   }   long long inv(long long a, long long p = 1000000007) {     return fpow(a, p - 2, p);   }   int n;   map<int, vector<pair<int, int> > > store;   bool comp(const pair<int, int> &a, const pair<int, int> &b) {     if (a.second != b.second)       return a.second < b.second;     else       return a.first < b.first;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     cin >> n;     vector<int> arr(n);     vector<int> presum(n + 1, 0);     for (int i = 0; i < n; i++) {       cin >> arr[i];       presum[i + 1] = presum[i] + arr[i];     }     for (int i = 0; i < n + 1; i++) {       for (int j = i + 1; j < n + 1; j++) {         int sums = presum[j] - presum[i];         auto it = store.find(sums);         if (it == store.end()) {           vector<pair<int, int> > temp;           temp.push_back({i + 1, j});           store[sums] = temp;         } else           it->second.push_back({i + 1, j});       }     }     int maxans = 0, maxind = -1;     for (auto &e : store) {       int locmax = 0;       int curfirst = -1, cursecond = -1;       sort(e.second.begin(), e.second.end(), comp);       for (auto &ee : e.second) {         if (ee.first <= cursecond)           continue;         else {           locmax++;           curfirst = ee.first;           cursecond = ee.second;         }       }       if (locmax > maxans) {         maxans = locmax;         maxind = e.first;       }     }     cout << maxans << endl;     auto it = store.find(maxind);     int curfirst = -1, cursecond = -1;     for (auto &ee : it->second) {       if (ee.first <= cursecond)         continue;       else {         curfirst = ee.first;         cursecond = ee.second;         cout << curfirst <<     << cursecond << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool cur1;   int A[100005];   void check_min(int &x, int y) {     if (x > y) x = y;   }   void check_max(int &x, int y) {     if (x < y) x = y;   }   struct node {     int sum;     int mx, L, R;     int mxL, ToL, mxR, ToR;     void Init(int d, int x) {       sum = d;       mx = d;       mxL = d;       mxR = d;       L = x, R = x, ToL = x, ToR = x;     }     node operator+(const node &_) const {       node res;       res.sum = sum + _.sum;       res.mx = max(mx, _.mx);       if (mx == res.mx)         res.L = L, res.R = R;       else         res.L = _.L, res.R = _.R;       if (mxR + _.mxL > res.mx) {         res.mx = mxR + _.mxL;         res.L = ToR;         res.R = _.ToL;       }       res.mxL = mxL;       res.ToL = ToL;       if (sum + _.mxL > res.mxL) {         res.mxL = sum + _.mxL;         res.ToL = _.ToL;       }       res.mxR = _.mxR;       res.ToR = _.ToR;       if (_.sum + mxR > res.mxR) {         res.mxR = _.sum + mxR;         res.ToR = ToR;       }       return res;     }     void Print() {       printf( sum=%d n , sum);       printf( res=%d [%d %d] n , mx, L, R);       printf( sumL=%d ToL=%d n , mxL, ToL);       printf( sumR=%d ToR=%d n , mxR, ToR);     }   };   struct Segment_tree {     struct tree_node {       int L, R;       node val1, val2;       bool Lazy;       void Reverse() {         Lazy = !Lazy;         swap(val1, val2);       }       tree_node operator+(const tree_node &_) const {         tree_node res;         res.L = L;         res.R = _.R;         res.val1 = val1 + _.val1;         res.val2 = val2 + _.val2;         return res;       }     } tree[100005 << 2];     int Pc[100005];     void Up(int p) {       tree[p].val1 = tree[p << 1].val1 + tree[p << 1 | 1].val1;       tree[p].val2 = tree[p << 1].val2 + tree[p << 1 | 1].val2;     }     void Down(int p) {       if (!tree[p].Lazy) return;       tree[p << 1].Reverse();       tree[p << 1 | 1].Reverse();       tree[p].Lazy = false;     }     void Build(int L, int R, int p) {       tree[p].L = L, tree[p].R = R;       tree[p].Lazy = false;       if (L == R) {         Pc[L] = p;         tree[p].val1.Init(A[L], L);         tree[p].val2.Init(-A[L], L);         return;       }       int mid = (L + R) >> 1;       Build(L, mid, p << 1);       Build(mid + 1, R, p << 1 | 1);       Up(p);     }     void Change(int L, int R, int p) {       if (L <= tree[p].L && tree[p].R <= R) {         tree[p].Reverse();         return;       }       Down(p);       int mid = (tree[p].L + tree[p].R) >> 1;       if (R <= mid)         Change(L, R, p << 1);       else if (L > mid)         Change(L, R, p << 1 | 1);       else         Change(L, mid, p << 1), Change(mid + 1, R, p << 1 | 1);       Up(p);     }     tree_node Query(int L, int R, int p) {       if (L <= tree[p].L && tree[p].R <= R) return tree[p];       Down(p);       int mid = (tree[p].L + tree[p].R) >> 1;       if (R <= mid)         return Query(L, R, p << 1);       else if (L > mid)         return Query(L, R, p << 1 | 1);       else         return Query(L, mid, p << 1) + Query(mid + 1, R, p << 1 | 1);     }     int STK[100005];     void Updata(int x) {       int p = Pc[x], top = 0;       while (p) {         STK[++top] = p;         p >>= 1;       }       for (int i = top; i >= 2; i--) Down(STK[i]);       tree[Pc[x]].val1.Init(A[x], x);       tree[Pc[x]].val2.Init(-A[x], x);       for (int i = 2; i <= top; i++) Up(STK[i]);     }   } ST;   int stk[100005][2];   bool cur2;   int main() {     int n, m;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &A[i]);     ST.Build(1, n, 1);     scanf( %d , &m);     while (m--) {       int op;       scanf( %d , &op);       if (op == 0) {         int x, d;         scanf( %d%d , &x, &d);         A[x] = d;         ST.Updata(x);       } else {         int L, R, K;         scanf( %d%d%d , &L, &R, &K);         int ans = 0, top = 0;         while (K--) {           node res = ST.Query(L, R, 1).val1;           if (res.mx < 0) break;           ans += res.mx;           ST.Change(res.L, res.R, 1);           top++;           stk[top][0] = res.L, stk[top][1] = res.R;         }         while (top) ST.Change(stk[top][0], stk[top][1], 1), top--;         printf( %d n , ans);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int id;     int no;   } a[100001];   int n, tot = 1, minn = 2100000000;   bool cmp(node a, node b) {     if (a.no != b.no) return a.no < b.no;     return a.id < b.id;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i].no);       a[i].id = i;     }     sort(a + 1, a + n + 1, cmp);     while (a[tot].no == a[tot + 1].no) {       minn = min(minn, a[tot + 1].id - a[tot].id);       tot++;     }     printf( %d , minn);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long maxi = LLONG_MIN;   long long mini = LLONG_MAX;   void fast() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   long long t, i, j, k, n, temp, flag, ans, m;   string s;   int main() {     int k;     cin >> k;     int f = -1;     for (int i = 5; i * i <= k; i++) {       if (k % i == 0) {         f = i;         break;       }     }     if (f == -1) {       cout << -1;     } else {       int n = f;       int m = k / n;       for (int i = 0; i < n; i++) {         if (i % 5 == 0) {           int j = 0;           for (j = 0; j < m - 4; j += 5) {             s +=  aeiou ;           }           j--;           if (m - j - 1 == 1) {             s +=  a ;           } else if (m - j - 1 == 2) {             s +=  ae ;           } else if (m - j - 1 == 3) {             s +=  aei ;           } else if (m - j - 1 == 4) {             s +=  aeio ;           }         } else if (i % 5 == 1) {           int j = 0;           for (j = 0; j < m - 4; j += 5) {             s +=  eioua ;           }           j--;           if (m - j - 1 == 1) {             s +=  e ;           } else if (m - j - 1 == 2) {             s +=  ei ;           } else if (m - j - 1 == 3) {             s +=  eio ;           } else if (m - j - 1 == 4) {             s +=  eiou ;           }         } else if (i % 5 == 2) {           int j = 0;           for (j = 0; j < m - 4; j += 5) {             s +=  iouae ;           }           j--;           if (m - j - 1 == 1) {             s +=  i ;           } else if (m - j - 1 == 2) {             s +=  io ;           } else if (m - j - 1 == 3) {             s +=  iou ;           } else if (m - j - 1 == 4) {             s +=  ioua ;           }         } else if (i % 5 == 3) {           int j = 0;           for (j = 0; j < m - 4; j += 5) {             s +=  ouaei ;           }           j--;           if (m - j - 1 == 1) {             s +=  o ;           } else if (m - j - 1 == 2) {             s +=  ou ;           } else if (m - j - 1 == 3) {             s +=  oua ;           } else if (m - j - 1 == 4) {             s +=  ouae ;           }         } else {           int j = 0;           for (j = 0; j < m - 4; j += 5) {             s +=  uaeio ;           }           j--;           if (m - j - 1 == 1) {             s +=  u ;           } else if (m - j - 1 == 2) {             s +=  ua ;           } else if (m - j - 1 == 3) {             s +=  uae ;           } else if (m - j - 1 == 4) {             s +=  uaei ;           }         }       }       cout << s;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, q, PREV, pos;   ;   int arr[200005];   long long ps[200005], x, sebelum;   long long k[200005];   bool good;   void binser() {     int ki = PREV, ka = n;     pos = 1;     x += sebelum;     while (ki <= ka) {       int mid = (ki + ka) / 2;       if (ps[mid] <= x) {         ki = mid + 1;       } else {         good = 1;         pos = mid;         ka = mid - 1;       }     }     sebelum = x;     if (!good) sebelum = 0;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> q;     for (int i = 1; i <= n; i++) {       cin >> arr[i];       ps[i] = ps[i - 1] + arr[i];     }     PREV = 1;     for (int i = 1; i <= q; i++) {       cin >> x;       good = false;       binser();       cout << n - pos + 1 << endl;       PREV = pos;     }   }


#include <bits/stdc++.h>   using namespace std;   double d = 0;   bool intersect(int, int);   bool belong(int, int);   bool none(int, int);   void solve() {     int x1, y1, r1, R1, x2, y2, r2, R2;     cin >> x1 >> y1 >> r1 >> R1;     cin >> x2 >> y2 >> r2 >> R2;     int x = abs(x1 - x2);     int y = abs(y1 - y2);     d = sqrt(x * x + y * y);     int ans = 0;     if (d <= r2 - r1 || d >= r1 + R2 || d <= r1 - R2) ++ans;     if (d <= r2 - R1 || d >= R1 + R2 || d <= R1 - R2) ++ans;     if (d <= r1 - r2 || d >= r2 + R1 || d <= r2 - R1) ++ans;     if (d <= r1 - R2 || d >= R2 + R1 || d <= R2 - R1) ++ans;     cout << ans <<   n ;   }   bool intersect(int r1, int r2) {     if (d < r1 + r2 && d > max(r1, r2) - min(r1, r2))       return true;     else       return false;   }   bool belong(int r1, int r2) {     if (d <= r2 - r1)       return true;     else       return false;   }   bool none(int r1, int r2) {     if (!belong(r1, r2) && !belong(r2, r1) && !intersect(r1, r2))       return true;     else       return false;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void read(T& num) {     char CH;     bool F = false;     for (CH = getchar(); CH <  0  || CH >  9 ; F = CH ==  - , CH = getchar())       ;     for (num = 0; CH >=  0  && CH <=  9 ;          num = num * 10 + CH -  0 , CH = getchar())       ;     F && (num = -num);   }   int stk[70], tp;   template <class T>   inline void print(T p) {     if (!p) {       puts( 0 );       return;     }     while (p) stk[++tp] = p % 10, p /= 10;     while (tp) putchar(stk[tp--] +  0 );     putchar(  n );   }   const int mod = 1e9 + 7;   const double PI = acos(-1.0);   const int inf = 1e9;   const int N = 1e6 + 20;   const int maxn = 1e5 + 110;   const double eps = 1e-12;   int main() {     int n, k;     read(n);     read(k);     cout << (n - 1) * 6 * k + 5 * k << endl;     for (int i = 1; i <= n; i++) {       int t = (i - 1) * 6 + 1;       printf( %d %d %d %d n , t * k, t * k + k, t * k + 2 * k, t * k + 4 * k);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   using min_heap = priority_queue<T, vector<T>, greater<T>>;   template <class T, class U>   inline void MAX(T &a, U b) {     if (a < b) a = b;   }   template <class T, class U>   inline void MIN(T &a, U b) {     if (a > b) a = b;   }   template <class T, class U>   inline bool ckmax(T &a, U b) {     return b > a && (a = b, true);   }   template <class T, class U>   inline bool ckmin(T &a, U b) {     return b < a && (a = b, true);   }   template <class T, class U>   inline bool INR(T i, U l, U r) {     return l <= i && i <= r;   }   const int MOD = (int)(1e9) + 7;   const int INF = 0x3f3f3f3f;   const int NINF = -0x3f3f3f40;   const long long INF_L = 0x3f3f3f3f3f3f3f3f;   const long long NINF_L = -0x3f3f3f3f3f3f3f40;   const int MAXN = 100010;   char arr[]{ A ,  C ,  Z };   bool res(int n, int i1, int j1, string &s1) {     int acc = 0;     for (int i = 1; i < n; i++) {       if (i == n - 1)         s1 += arr[i1 % 3];       else if (acc == j1)         s1 +=  Z ;       else         s1 += (s1[((int)(s1).size()) - 1] ==  C  ?  A  :  C );       if (s1[i - 1] ==  A  && s1[i] ==  C ) acc++;     }     return acc == j1;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout.precision(20);     int k, x, n, m;     cin >> k >> x >> n >> m;     for (int i1 = 0; i1 < 9; i1++) {       for (int j1 = 0; j1 <= n / 2; j1++) {         for (int i2 = 0; i2 < 9; i2++) {           for (int j2 = 0; j2 <= m / 2; j2++) {             if (n == 1 && (i1 % 4 != 0) || m == 1 && (i2 % 4 != 0)) continue;             pair<int, int> n1, n2;             n1.first = i1, n1.second = j1;             n2.first = i2, n2.second = j2;             bool bad = false;             for (int a = 0; a <= k - 3; a++) {               pair<int, int> n3;               n3.first = (n1.first / 3) * 3 + (n2.first % 3);               n3.second = n1.second + n2.second;               if (n1.first % 3 == 0 && n2.first / 3 == 1) n3.second++;               if (n3.second > x) {                 bad = true;                 break;               }               n1 = n2, n2 = n3;             }             if (bad) continue;             if (n2.second == x) {               string s1 =   , s2 =   ;               s1 += arr[i1 / 3];               if (n != 1) {                 if (!res(n, i1, j1, s1)) {                   continue;                 }               }               s2 += arr[i2 / 3];               if (m != 1) {                 if (!res(m, i2, j2, s2)) {                   continue;                 }               }               cout << s1 <<   n  << s2 <<   n ;               return 0;             }           }         }       }     }     cout <<  Happy new year!  <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   long long MOD = 998244853;   long long mpow(long long a, long long b) {     if (b == 0) return 1;     long long t1 = mpow(a, b / 2);     t1 *= t1;     t1 %= MOD;     if (b % 2) t1 *= a;     t1 %= MOD;     return t1;   }   long long mpow(long long a, long long b, long long p) {     if (b == 0) return 1;     long long t1 = mpow(a, b / 2);     t1 *= t1;     t1 %= p;     if (b % 2) t1 *= a;     t1 %= p;     return t1;   }   long long modinverse(long long a, long long m) {     long long m0 = m;     long long y = 0, x = 1;     if (m == 1) return 0;     while (a > 1) {       long long q = a / m;       long long t = m;       m = a % m, a = t;       t = y;       y = x - q * y;       x = t;     }     if (x < 0) x += m0;     return x;   }   long long range(long long l, long long r) { return l + rand() % (r - l + 1); }   void solve() {     long long n, m;     cin >> n >> m;     vector<pair<long long, long long> > s;     long long st = n + 1, en = 0;     for (long long i = 0; i < m; i++) {       pair<long long, long long> temp;       cin >> temp.first >> temp.second;       s.push_back(temp);       st = min(st, temp.first);       en = max(en, temp.first);     }     st--;     en--;     long long b[n];     for (long long i = 0; i < n; i++) cin >> b[i];     for (long long i = st; i < en + 1; i++) {       bool bo = 1;       pair<long long, long long> h[n];       for (long long i = 0; i < n; i++)         h[i] = make_pair((long long)-1, (long long)-1);       long long name = 1;       for (auto it : s) {         h[it.first - 1] = make_pair(it.second, name++);       }       for (long long j = st; j < i + 1; j++) {         pair<long long, long long> temp =             ((j == 0) ? make_pair((long long)0, (long long)0)                       : make_pair(h[j - 1].first + b[j], h[j - 1].second));         h[j] = max(h[j], temp);         if (h[j].first < 0) bo = 0;       }       for (long long j = en; j >= i; j--) {         pair<long long, long long> temp =             ((j == n - 1) ? make_pair((long long)0, (long long)0)                           : make_pair(h[j + 1].first + b[j], h[j + 1].second));         h[j] = max(h[j], temp);         if (h[j].first < 0) bo = 0;       }       if (!bo) continue;       cout << i + 1 <<   n ;       bool vis[m];       for (long long i = 0; i < m; i++) vis[i] = 0;       for (long long j = i; j >= st; j--) {         if (vis[h[j].second - 1] == 0) {           cout << h[j].second <<    ;           vis[h[j].second - 1] = 1;         }       }       for (long long j = i; j < en + 1; j++) {         if (vis[h[j].second - 1] == 0) {           cout << h[j].second <<    ;           vis[h[j].second - 1] = 1;         }       }       for (long long j = 0; j < m; j++) {         if (vis[j] == 0) {           cout << j + 1 <<    ;           vis[j] = 1;         }       }       cout <<   n ;       return;     }     cout << -1 <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t = 1;     for (long long i = 0; i < t; i++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, d;     cin >> n >> m >> d;     vector<int> v(n * m, 0);     for (int i = 0; i < n * m; i++) cin >> v[i];     int ans = INT_MAX;     for (int i = 0; i < n * m; i++) {       int temp_ans = 0;       for (int j = 0; j < n * m; j++) {         if (abs(v[j] - v[i]) % d != 0) {           temp_ans = -1;           break;         } else {           temp_ans += abs(v[j] - v[i]) / d;         }       }       ans = min(temp_ans, ans);       if (ans == -1) break;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string s1, s2, s3;     cin >> n;     while (n--) {       cin >> s1 >> s2 >> s3;       for (int i = 0; i < s1.length(); i++) {         if (s3.at(i) != s2.at(i) && s3.at(i) != s1.at(i)) {           cout <<  NO n ;           break;         }         if (i == s1.length() - 1) cout <<  YES n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int mod1 = 1000000007;   long long int mod2 = 67280421310721;   long long int mod3 = 998244353;   long long int INF = 1e18;   long long int pow1(long long int a, long long int b) {     long long int res = 1;     while (b > 0) {       if (b & 1) res = res * a;       a = a * a;       b >>= 1;     }     return res;   }   void sieve() {     long long int n;     bool prime[n + 1];     memset(prime, true, sizeof(prime));     for (int p = 2; p * p <= n; p++) {       if (prime[p] == true) {         for (int i = p * p; i <= n; i += p) prime[i] = false;       }     }   }   long long int pow2(long long int a, long long int b, long long int m) {     a %= m;     long long int res = 1;     while (b > 0) {       if (b & 1) res = res * a % m;       a = a * a % m;       b >>= 1;     }     return res;   }   long long int ncr(long long int n, long long int k) {     long long int res = 1;     if (k > n - k) k = n - k;     for (int i = 0; i < k; ++i) {       res *= (n - i);       res /= (i + 1);     }     return res;   }   void solve() {     long long int n, m;     cin >> n >> m;     long long int a[n + 1][m + 1];     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) cin >> a[i][j];     }     long long int dp[n + 1][m + 1];     memset(dp, 0, sizeof(dp));     for (int i = 1; i <= m; i++) dp[1][i] = 1;     for (int i = 2; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (a[i][j] >= a[i - 1][j])           dp[i][j] = dp[i - 1][j] + 1;         else           dp[i][j] = 1;       }     }     long long int best[n + 1];     memset(best, 0, sizeof(best));     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         best[i] = max(best[i], dp[i][j]);       }     }     long long int q;     cin >> q;     while (q--) {       long long int l, r;       cin >> l >> r;       if (best[r] <= (r - l))         cout <<  No n ;       else         cout <<  Yes n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> a;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, x, ct, i;     cin >> n;     for (i = 0; i < n; i++) {       cin >> x;       while ((x % 2) == 0) x = x / 2;       while ((x % 3) == 0) x = x / 3;       a.push_back(x);     }     ct = 0;     for (i = 1; i < n; i++)       if (a[i] == a[0]) ct++;     if (ct == (n - 1))       cout <<  Yes n ;     else       cout <<  No n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 5;   const long long INF = 2e9;   int n, m, dp[N], d[N], og[N], son[N], pr[N], top[N], num[N], sz, p[N], ans[N],       a[N], b[N];   int t[5 * N], ob[5 * N];   vector<int> g[N];   void build(int v, int l, int r) {     ob[v] = -1;     if (l == r) {       if (l == 1) {         t[v] = INF;       }       return;     }     int mid = (r + l) >> 1;     build(v + v, l, mid);     build(v + v + 1, mid + 1, r);     t[v] = max(t[v + v], t[v + v + 1]);   }   inline void push(int v, int l, int r) {     if (ob[v] != -1) {       ob[v + v + 1] = t[v + v + 1] = ob[v];       int mid = (r + l) >> 1;       ob[v + v] = t[v + v] = ob[v] - 2 * (r - mid);       ob[v] = -1;     }   }   int mx(int v, int l, int r, int tl, int tr) {     push(v, l, r);     if (l > r || l > tr || tl > r) {       return -INF;     }     if (tl <= l && r <= tr) {       return t[v];     }     int mid = (r + l) >> 1;     return max(mx(v + v, l, mid, tl, tr), mx(v + v + 1, mid + 1, r, tl, tr));   }   int get(int v, int l, int r, int tl, int tr, int val) {     push(v, l, r);     if (t[v] <= val || l > r || l > tr || tl > r) {       return -1;     }     if (l == r) {       return og[l];     }     int mid = (r + l) >> 1;     int y = get(v + v + 1, mid + 1, r, tl, tr, val);     return y == -1 ? get(v + v, l, mid, tl, tr, val) : y;   }   void update(int v, int l, int r, int tl, int tr, int val) {     push(v, l, r);     if (l > r || l > tr || tl > r) {       return;     }     if (tl <= l && r <= tr) {       t[v] = ob[v] = val - 2 * (tr - r);       return;     }     int mid = (r + l) >> 1;     update(v + v, l, mid, tl, tr, val);     update(v + v + 1, mid + 1, r, tl, tr, val);     t[v] = max(t[v + v], t[v + v + 1]);   }   void dfs(int v, int depth = 0) {     dp[v] = 1;     d[v] = depth;     for (int to : g[v]) {       dfs(to, depth + 1);       pr[to] = v;       dp[v] += dp[to];       if (!son[v] || (dp[to] > dp[son[v]])) {         son[v] = to;       }     }   }   void hld(int v) {     sz++;     og[sz] = v;     num[v] = sz;     if (son[v]) {       top[son[v]] = top[v];       hld(son[v]);     }     for (int to : g[v]) {       if (to != son[v]) {         top[to] = to;         hld(to);       }     }   }   inline bool cmp(int x, int y) {     return d[a[x]] + b[x] < d[a[y]] + b[y] ||            (d[a[x]] + b[x] == d[a[y]] + b[y] && a[x] < a[y]);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       int x;       scanf( %d , &x);       g[x].push_back(i);     }     dfs(0);     hld(0);     n++;     build(1, 1, n);     for (int i = 1; i <= m; i++) {       scanf( %d%d , &a[i], &b[i]);       p[i] = i;     }     sort(p + 1, p + m + 1, cmp);     for (int i = 1; i <= m; i++) {       int x = a[p[i]], t = b[p[i]], v;       while (true) {         if (mx(1, 1, n, num[top[x]], num[x]) > t + d[a[p[i]]]) {           v = get(1, 1, n, num[top[x]], num[x], t + d[a[p[i]]]);           break;         }         x = pr[top[x]];       }       ans[p[i]] = t + 2 * (d[a[p[i]]] - d[v]);       x = a[p[i]];       while (true) {         if (mx(1, 1, n, num[top[x]], num[x]) > t + d[a[p[i]]]) {           v = get(1, 1, n, num[top[x]], num[x], t + d[a[p[i]]]);           if (v != x) {             update(1, 1, n, num[v] + 1, num[x],                    ans[p[i]] - (d[a[p[i]]] - d[x]) + d[x]);           }           break;         } else {           update(1, 1, n, num[top[x]], num[x],                  ans[p[i]] - (d[a[p[i]]] - d[x]) + d[x]);         }         x = pr[top[x]];       }     }     for (int i = 1; i <= m; i++) {       printf( %d  , ans[i]);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int q = 1;     while (q--) {       double n, r;       cin >> n >> r;       double ans;       ans = (r) / (1 / sin(3.14159265 / n) - 1);       cout << setprecision(9) << ans;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 6;   const int MAX = 1e7 + 7;   int n, k;   int a[N];   int dp[MAX];   bool can(int x) {     memset(dp, 0, sizeof(dp));     for (int i = x; i <= MAX; i++) {       dp[i] = max(1, dp[i / 2] + dp[(i + 1) / 2]);     }     int kk = k;     for (int i = 0; i < n; i++) {       kk -= a[i] < x ? 0 : dp[a[i]];       if (kk <= 0) {         return true;       }     }     return false;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n >> k;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     int lo = 0, hi = 1e7 + 100;     while (lo + 1 < hi) {       int mid = (lo + hi) / 2;       if (!can(mid)) {         hi = mid;       } else {         lo = mid;       }     }     cout << (lo == 0 ? -1 : lo) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   bool mod(long double a, long double b) { return a / b - floor(a / b); }   int occurs(vector<int> v, int n) {     auto it = lower_bound(((v)).begin(), ((v)).end(), (n));     auto it1 = upper_bound(((v)).begin(), ((v)).end(), (n));     int x = it1 - it;     return x;   }   long double max(long double a, long double b) { return a < b ? b : a; }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n, x;       cin >> n >> x;       string s;       cin >> s;       int a[n];       int c = 0;       for (int(i) = 0; (i) < (n); ++(i)) {         if (s[i] ==  0 )           c++;         else           c--;         a[i] = c;       }       sort(a, a + n);       int ans = 0;       if (c == 0) {         for (int(i) = 0; (i) < (n); ++(i)) {           if (a[i] == x) {             ans = -1;             break;           }         }         if (x == 0 && ans == 0) ans = 1;         cout << ans <<   n ;       } else {         if ((x >= 0 && c > 0) || (x <= 0 && c < 0)) {           if (c > 0) {             for (int(i) = 0; (i) < (n); ++(i)) {               if ((x - a[i]) % c == 0 && (x - a[i]) >= 0) ans++;             }           } else {             for (int(i) = 0; (i) < (n); ++(i)) {               if ((x - a[i]) % c == 0 && (x - a[i]) <= 0) ans++;             }           }           if (x == 0) ans++;           cout << ans <<   n ;         } else {           if (c > 0) {             for (int(i) = 0; (i) < (n); ++(i)) {               if ((x - a[i]) % c == 0 && (x - a[i]) >= 0) ans++;             }           } else {             for (int(i) = 0; (i) < (n); ++(i)) {               if ((x - a[i]) % c == 0 && (x - a[i]) <= 0) ans++;             }           }           if (x == 0) ans++;           cout << ans <<   n ;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void rd(T &x) {     x = 0;     char c = getchar();     int f = 1;     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) x = x * 10 -  0  + c, c = getchar();     x *= f;   }   int curtest;   void FAIL() {     printf( NO );     exit(0);   }   long long Abs(long long x) { return x > 0 ? x : -x; }   long double eps = 1e-20;   int dcmp(long double x) { return x > -eps ? (x > eps) : -1; }   const int N = 2e6 + 10;   vector<int> pos;   struct node {     long long t, x, y;   } v[N];   long long val[N], ti[N];   int vis[N];   int m, n;   long double lb, rb;   vector<char> S;   void modify(int p, long long x, long long delt) {     if (Abs((delt * m + p) % 2) ^ Abs(x % 2)) FAIL();     if (delt == 0) return;     long long l = -p - x, r = p - x;     long double dt = -delt;     if (dt > 0)       lb = max(lb, l / dt), rb = min(rb, r / dt);     else       lb = max(lb, r / dt), rb = min(rb, l / dt);   }   void sol(vector<int> &ans) {     lb = -m, rb = m;     for (int i = 0; i + 1 < pos.size(); ++i) {       if (i + 2 == pos.size())         modify(m - pos[i], -val[pos[i]], -ti[pos[i]] - 1);       else         modify(pos[i + 1] - pos[i], val[pos[i + 1]] - val[pos[i]],                ti[pos[i + 1]] - ti[pos[i]]);       if (ti[pos[i]] == 0) {         lb = max(lb, (long double)val[pos[i]] - (m - pos[i]));         rb = min(rb, (long double)val[pos[i]] + (m - pos[i]));       }     }     long long dx = floor(rb);     if (Abs(dx % 2) ^ (m % 2)) dx--;     if (dcmp(dx - lb) < 0) FAIL();     for (int i = 0; i + 1 < pos.size(); ++i) {       int l = pos[i], r = pos[i + 1], len = r - l;       long long x = (r == m ? dx : val[r]) - val[l] - (ti[r] - ti[l]) * dx;       int d = x > 0 ? 1 : -1;       x = Abs(x);       len -= x;       while (x) x--, ans.push_back(d);       if (len < 0 || (len & 1)) FAIL();       while (len) ans.push_back(1), ans.push_back(-1), len -= 2;     }   }   long long dx, dy;   void solve(int l, int r, long long x, long long y, long long t) {     x -= t * dx, y -= t * dy;     char xx = x > 0 ?  R  :  L ;     char yy = y > 0 ?  U  :  D ;     x = Abs(x), y = Abs(y);     while (x--) S.push_back(xx), r--;     while (y--) S.push_back(yy), r--;     if (((r - l) & 1) || r - l < 0) FAIL();     while (r - l) S.push_back( U ), S.push_back( D ), r -= 2;   }   vector<int> ax, ay;   int main() {     rd(n), rd(m);     int flg = 0;     vis[0] = 1, v[0].x = v[0].y = v[0].t = 0;     for (int i = 1; i <= n; ++i) {       node A;       rd(A.t), rd(A.x), rd(A.y);       int p = A.t % m;       A.t /= m;       if (vis[p]) {         if (A.t == v[p].t) {           if (A.x != v[p].x || A.y != v[p].y) FAIL();           continue;         }         long long dt = A.t - v[p].t;         if (flg) {           if (v[p].x + dt * dx == A.x && v[p].y + dt * dy == A.y)             continue;           else             FAIL();         }         dx = A.x - v[p].x, dy = A.y - v[p].y;         if (dx % dt || dy % dt) FAIL();         dx /= dt, dy /= dt;         flg = 1;       } else         v[p] = A, vis[p] = 1;     }     if (flg) {       int p1 = 0, p2;       while (true) {         p2 = p1 + 1;         while (!vis[p2] && p2 < m) p2++;         if (p2 >= m) break;         solve(p1, p2, v[p2].x - v[p1].x, v[p2].y - v[p1].y, v[p2].t - v[p1].t);         p1 = p2;       }       solve(p1, m, dx - v[p1].x, dy - v[p1].y, -v[p1].t);       for (int i = 0; i < S.size(); ++i) putchar(S[i]);     } else {       for (int i = 0; i < m; ++i)         if (vis[i]) ti[i] = v[i].t, pos.push_back(i);       pos.push_back(m), ti[m] = 0;       for (int i = 0; i < m; ++i)         if (vis[i]) val[i] = v[i].x + v[i].y;       sol(ax);       for (int i = 0; i < m; ++i)         if (vis[i]) val[i] = v[i].x - v[i].y;       sol(ay);       for (int i = 0; i < m; ++i) {         if (ax[i] == ay[i])           putchar(ax[i] > 0 ?  R  :  L );         else           putchar(ax[i] > 0 ?  U  :  D );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 10;   int d[MAXN], s[MAXN];   vector<pair<int, int> > ans;   set<pair<int, pair<int, int> > > ver;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> d[i] >> s[i];       ver.insert({d[i], {s[i], i}});     }     while (ver.size()) {       int deg = ver.begin()->first, adj = ver.begin()->second.first,           v = ver.begin()->second.second;       ver.erase(ver.begin());       if (deg == 0) continue;       ver.erase({d[adj], {s[adj], adj}});       ans.push_back({v, adj});       s[adj] ^= v;       d[adj]--;       ver.insert({d[adj], {s[adj], adj}});     }     cout << ans.size() << endl;     for (auto u : ans) cout << u.first <<     << u.second << endl;     return 0;   }


#include <bits/stdc++.h>   const int maxx = 1000001;   int x[maxx], y[maxx];   unsigned long long hash[maxx], vl[maxx], count = 0, check = 1, mul = 1;   bool compare(unsigned long long a, unsigned long long b) { return a > b; }   unsigned long long sum1ton(unsigned long long n) { return n * (n - 1) / 2; }   int main() {     int a, b;     scanf( %d %d , &a, &b);     hash[0] = 1;     for (int i = 1; i <= a; i++) {       hash[i] = hash[i - 1] * mul + 31;       mul = mul * 13 + 23;     }     for (int i = 0; i < b; i++) {       scanf( %d %d , &x[i], &y[i]);       vl[x[i]] -= hash[y[i]];       vl[y[i]] -= hash[x[i]];     }     for (int i = 0; i < b; i++) {       if (vl[x[i]] + hash[y[i]] == vl[y[i]] + hash[x[i]]) {         count++;       }     }     std::sort(vl + 1, vl + a + 1, compare);     for (int i = 1; i < a; i++) {       if (vl[i] == vl[i + 1])         check++;       else {         count += sum1ton(check);         check = 1;       }     }     count += sum1ton(check);     printf( %I64d , count);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1010;   int d[N];   int a[N][N], b[N][N], c[N][N], row[N], col[N];   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         scanf( %d , &a[i][j]);       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         d[j] = a[i][j];       }       sort(d + 1, d + m + 1);       int k = unique(d + 1, d + m + 1) - d - 1;       for (int j = 1; j <= m; j++)         b[i][j] = lower_bound(d + 1, d + k + 1, a[i][j]) - d;       row[i] = k;     }     for (int j = 1; j <= m; j++) {       for (int i = 1; i <= n; i++) d[i] = a[i][j];       sort(d + 1, d + n + 1);       int k = unique(d + 1, d + n + 1) - d - 1;       for (int i = 1; i <= n; i++)         c[i][j] = lower_bound(d + 1, d + k + 1, a[i][j]) - d;       col[j] = k;     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         int ans = 0;         if (b[i][j] >= c[i][j]) {           ans = max(ans, row[i]);           ans = max(ans, col[j] + b[i][j] - c[i][j]);         } else {           ans = max(ans, col[j]);           ans = max(ans, row[i] + c[i][j] - b[i][j]);         }         printf( %d  , ans);       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T_key, typename T_value, bool maximum_mode = false>   struct online_prefix_max {     map<T_key, T_value> optimal;     bool better(T_value a, T_value b) { return (a < b) ^ maximum_mode; }     pair<T_key, T_value> query(T_key key_limit) const {       auto it = optimal.lower_bound(key_limit);       if (it == optimal.begin()) return {0, -1};       it--;       return *it;     }     void insert(T_key key, T_value value) {       auto it = optimal.lower_bound(key);       if (it != optimal.end() && it->first == key) {         if (!better(value, it->second)) return;       } else if (it != optimal.begin()) {         auto prev_it = it;         prev_it--;         if (!better(value, prev_it->second)) return;       }       while (it != optimal.end() && !better(it->second, value))         it = optimal.erase(it);       optimal.insert(it, {key, value});     }   };   int main() {     int n, i, j, t;     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     online_prefix_max<long long int, int> ds;     map<pair<int, long long int>, pair<int, int> > mp;     long long int l, r;     cin >> n >> t;     for (i = 0; i < n; i++) {       cin >> l >> r;       r += l;       mp[{l, r}] = {i, 0};       ds.insert(-r, l);     }     int pos, siz;     pair<long long int, int> p;     multiset<pair<int, int> > not_eaten;     while (t--) {       cin >> pos >> siz;       p = ds.query(-pos + 1);       if (p.second == -1 || p.second > pos) {         not_eaten.insert({pos, siz});       } else {         l = p.second;         r = -p.first;         pair<int, int> val = mp[{l, r}];         mp.erase({l, r});         r += siz;         val.second++;         while (1) {           auto it = not_eaten.lower_bound({l, -1});           if (it == not_eaten.end() || it->first > r) break;           r += it->second;           val.second++;           not_eaten.erase(it);         }         ds.insert(-r, l);         mp[{l, r}] = val;       }     }     pair<int, int> ans[n];     for (auto &z : mp) {       ans[z.second.first] = {z.second.second, z.first.second - z.first.first};     }     for (i = 0; i < n; i++) cout << ans[i].first <<     << ans[i].second <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int arr[n], vis[200005] = {0};       for (int i = 0; i < n; i++) {         cin >> arr[i];         if (arr[i] <= n) vis[arr[i]]++;       }       sort(arr, arr + n);       vector<int> v;       for (int i = 1; i <= n; i++) {         if (!vis[i]) v.push_back(i);       }       int m = v.size(), l = 0;       int ans = 0;       for (int i = 0; i < n; i++) {         int x = arr[i];         if (x <= n && vis[x] > 1) {           int r = vis[x], k = 1;           while (r > 1) {             if (l < m && (2 * v[l]) < x) {               ans++;               l++;             } else {               ans = -1;               k = 0;               break;             }             r--;             i++;           }           if (!k) break;         }         if (x > n) {           if (l < m && (2 * v[l]) < x) {             ans++;             l++;           } else {             ans = -1;             break;           }         }       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     vector<long long> V;     for (long long i = 1; i * i <= n; ++i) {       if (!(n % i)) {         V.push_back(i);         V.push_back(n / i);       }     }     sort(V.begin(), V.end());     for (long long i = V.size() - 1; i >= 0; --i)       if (i == V.size() - 1 || V[i + 1] != V[i])         cout << n * (2 + V[i] * (n / V[i] - 1)) / 2 / V[i] <<    ;     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k;   int main() {     cin >> n >> m >> k;     if (m >= n && k >= n)       cout <<  Yes ;     else       cout <<  No ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   int n, h, a[100005];   pair<int, int> A[100005];   void solve() {     sort(A, A + n);     for (int i = (0); i < (n); i++) a[i] = A[i].first;     int res = a[n - 1] + a[n - 2] - a[0] - a[1], ind = n - 1;     if (n >= 3) {       int v = max(a[n - 1] + a[n - 2], a[n - 1] + a[0] + h) -               min(a[1] + a[2], a[1] + a[0] + h);       if (res > v) {         res = v;         ind = 0;       }       v = max(a[n - 3] + a[n - 2], a[n - 1] + a[n - 2] + h) - (a[0] + a[1]);       if (res > v) {         res = v;         ind = n - 2;       }     }     for (int i = 1; i + 2 < n; i++) {       int v = max(a[n - 1] + a[n - 2], a[n - 1] + a[i] + h) - (a[0] + a[1]);       if (res > v) {         res = v;         ind = i;       }     }     cout << res << endl;     set<int> L;     for (int i = (0); i < (ind + 1); i++) L.insert(A[i].second);     for (int i = (0); i < (n); i++) {       printf( %d  , (L.find(i) == L.end()) + 1);     }     cout << endl;   }   int main() {     while (cin >> n >> h) {       for (int i = (0); i < (n); i++) {         scanf( %d , &A[i].first);         A[i].second = i;       }       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const long long maxx = 1e6 + 7;   const long long maxn = 5000 + 7;   const long long mod = 998244853;   const long long maxs = 5 * (1E5) + 7;   const long long maxm = 4e5 + 7;   const long long maxk = 1008 + 7;   const long long maxw = 100 + 7;   const long long maxh = 100 + 7;   const double pi = 3.1415926;   const long long ten = 10;   const int ooi = 1234567;   const long long ool = 1e18 + 7;   const long double eps = 1e-8;   const int apsz = 26;   vector<int> can[2][2];   int a[maxn];   int c[maxn];   int n;   void init() {     cin >> n;     for (long long i = (0); i < (n); i++) {       char ch;       cin >> ch;       c[i] = ch -  0 ;     }     for (long long i = (0); i < (n); i++) {       char ch;       cin >> ch;       a[i] = ch -  0 ;     }     for (long long i = (0); i < (n); i++) {       if (a[i] == 1 && c[i] == 1) can[1][1].push_back(i);       if (c[i] == 1 && a[i] == 0) can[1][0].push_back(i);       if (c[i] == 0 && a[i] == 0) can[0][0].push_back(i);       if (c[i] == 0 && a[i] == 1) can[0][1].push_back(i);     }   }   void solve() {     int nn = can[0][0].size();     int nc = can[1][0].size();     int na = can[0][1].size();     int nb = can[1][1].size();     int ans = -1;     int a, b, c, d;     for (b = 0; b <= nc; b++) {       for (c = 0; c <= na; c++) {         if ((nb + na - c - b) % 2) continue;         d = (nb + na - c - b) / 2;         a = n / 2 - b - c - d;         if (a <= nn && d <= nb && a >= 0 && d >= 0) {           ans = 1;           goto ED;         }       }     }   ED:     if (ans == -1) {       cout << ans << endl;       return;     }     vector<int> ta;     for (long long i = (0); i < (a); i++) ta.push_back(can[0][0][i]);     for (long long i = (0); i < (b); i++) ta.push_back(can[1][0][i]);     for (long long i = (0); i < (c); i++) ta.push_back(can[0][1][i]);     for (long long i = (0); i < (d); i++) ta.push_back(can[1][1][i]);     for (long long i = (0); i < (n / 2); i++) {       if (i) cout <<    ;       cout << ta[i] + 1;     }     cout << endl;   }   int main(void) {     ios::sync_with_stdio(false);     cout.tie(0);     cin.tie(0);     init();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 500005;   int n, u, v, cnt = 0, h[N] = {-1}, in[N], out[N], ans[N], val[N], pa[N];   bool chk[N];   vector<int> cur;   vector<int> adj[N];   vector<pair<int, int>> ve;   multiset<int, greater<int>> second, ed, ch[N];   struct segment_tree {     int tr[4 * N], lz[4 * N];     void apply(int i, int v) {       tr[i] += v;       lz[i] += v;     }     void down(int i) {       apply(i * 2, lz[i]);       apply(i * 2 + 1, lz[i]);       lz[i] = 0;     }     void update(int l, int r, int i, int L, int R, int v) {       if (l > R || r < L || L > R) {         return;       } else if (L <= l && r <= R) {         apply(i, v);         return;       } else {         down(i);         update(l, (l + r) / 2, i * 2, L, R, v);         update((l + r) / 2 + 1, r, i * 2 + 1, L, R, v);         tr[i] = max(tr[i * 2], tr[i * 2 + 1]);       }     }     int query(int l, int r, int i, int L, int R) {       if (l > R || r < L || L > R) {         return 0;       } else if (L <= l && r <= R) {         return tr[i];       } else {         down(i);         return max(query(l, (l + r) / 2, i * 2, L, R),                    query((l + r) / 2 + 1, r, i * 2 + 1, L, R));       }     }   } seg;   void DFS(int u, int p = 0) {     h[u] = h[p] + 1;     pa[u] = p;     in[u] = ++cnt;     seg.update(1, n, 1, in[u], in[u], h[u]);     for (int &v : adj[u]) {       if (v != p) {         DFS(v, u);       }     }     out[u] = cnt;   }   void DFS_2(int u, int p = 0) {     int pa =         max(seg.query(1, n, 1, 1, in[u] - 1), seg.query(1, n, 1, out[u] + 1, n));     ve.push_back({0, u});     if (u != 1) {       ve.push_back({pa, u});     }     for (int &v : adj[u]) {       if (v != p) {         int pa = seg.query(1, n, 1, in[v], out[v]);         ve.push_back({pa, u});         seg.update(1, n, 1, 1, n, 1);         seg.update(1, n, 1, in[v], out[v], -2);         DFS_2(v, u);         seg.update(1, n, 1, 1, n, -1);         seg.update(1, n, 1, in[v], out[v], 2);       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n;     for (int i = 1; i < n; i++) {       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     DFS(1);     DFS_2(1);     for (int i = 1; i <= n; i++) {       second.insert(val[i] = adj[i].size() + 1);     }     for (int i = 1; i <= n; i++) {       for (int &v : adj[i]) {         if (v != pa[i]) {           ch[i].insert(val[v]);         }       }       ed.insert(val[i] + *ch[i].begin() - 2);     }     sort(ve.begin(), ve.end(), greater<pair<int, int>>());     for (int i = 0; i <= n; i += 2) {       ans[i] = max(*second.begin(), *ed.begin());       while (!ve.empty() && ve.back().first == i / 2) {         int u = ve.back().second;         if (!chk[u]) {           chk[u] = true;           cur.push_back(u);         }         ve.pop_back();         second.erase(second.find(val[u]));         second.insert(val[u] - 1);         ed.erase(ed.find(val[u] + *ch[u].begin() - 2));         ed.insert(val[u] - 1 + *ch[u].begin() - 2);         if (u != 1) {           ed.erase(ed.find(val[pa[u]] + *ch[pa[u]].begin() - 2));           ch[pa[u]].erase(ch[pa[u]].find(val[u]));           ch[pa[u]].insert(val[u] - 1);           ed.insert(val[pa[u]] + *ch[pa[u]].begin() - 2);         }         val[u]--;       }       ans[i + 1] = *second.begin();       while (!cur.empty()) {         int u = cur.back();         cur.pop_back();         chk[u] = false;         ans[i + 1] = max(ans[i + 1], val[u] + 1);       }     }     for (int i = 1; i <= n; i++) {       cout << max(ans[i], 1) <<    ;     }   }


#include <bits/stdc++.h>   int n;   int tot;   int top;   int tot1;   int a[2005][2005];   int stack[2005];   int instack[2005];   int visit[2005];   int dfn[2005];   int low[2005];   inline void tarjan(int u) {     if (visit[u]) return;     int v;     dfn[u] = low[u] = ++tot;     stack[++top] = u;     instack[u] = 1;     visit[u] = 1;     int i;     for (i = 1; i <= n; i++) {       if (a[u][i]) {         if (!visit[i]) {           tarjan(i);           if (low[i] < low[u]) low[u] = low[i];         } else {           if (instack[i])             if (dfn[i] < low[u]) low[u] = dfn[i];         };       };     };     if (dfn[u] == low[u]) {       ++tot1;       while (1) {         v = stack[top--];         instack[v] = 0;         if (v == u) break;       };     };   };   int main() {     scanf( %d , &n);     int i, j;     for (i = 1; i <= n; i++) {       for (j = 1; j <= n; j++) {         scanf( %d , a[i] + j);       };     };     for (i = 1; i <= n; i++) tarjan(i);     puts(tot1 == 1 ?  YES  :  NO );   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:256000000 )   #pragma gcc optimize(O3)   using namespace std;   const double eps = 1e-9;   const double pi = acos(-1.0);   const double dinf = 1e250;   const long long INF = static_cast<long long>(2e18);   const unsigned long long inf = static_cast<unsigned long long>(1e9 + 7);   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   template <class T>   void OUT(T a) {     cout << a;     exit(0);   }   template <typename T>   bool amax(T& a, T b) {     if (b > a) {       a = b;       return true;     }     return false;   }   template <typename T>   bool amin(T& a, T b) {     if (b < a) {       a = b;       return true;     }     return false;   }   mt19937 rng(static_cast<uint32_t>(       chrono::steady_clock::now().time_since_epoch().count()));   chrono::time_point<chrono::steady_clock> cl;   double time_since_start() {     return (chrono::steady_clock::now() - cl).count() / 1e9;   }   void get_time();   vector<long long> precalc;   void rec(unsigned long long n, unsigned long long cur, unsigned long long& k,            map<unsigned long long, unsigned long long>& s,            unsigned long long& w) {     w = n;     if (!n) return;     if (!k) return;     if (k >= 2 * cur - 1) {       k -= 2 * cur - 1;       rec(n - 1, cur * 2, k, s, w);       s[n - 1] += 2 * cur - 3;     }   }   void solve() {     map<unsigned long long, unsigned long long> m;     unsigned long long n, k;     cin >> n >> k;     unsigned long long cur = 1;     while (k >= cur * cur && n) {       k -= cur * cur;       cur *= 2;       n -= 1;     }     if (!n && k) {       cout <<  NO  << endl;       return;     }     unsigned long long w;     rec(n, cur, k, m, w);     m[n] += (cur - 1) * (cur - 1);     for (unsigned long long i = n; i > 0; --i) {       if (k >= m[i]) {         k -= m[i];         m[i - 1] += 4 * m[i];       }       if (k < m[i]) {         cout <<  YES   << w << endl;         return;       }     }     if (!k) {       cout <<  YES   << n << endl;       return;     }     if (k) {       cout <<  NO  << endl;       return;     }   }   int32_t main() {     ios_base::sync_with_stdio(0);     cout << fixed << setprecision(10);     cl = chrono::steady_clock::now();     cin.tie(0);     unsigned long long cur = 1;     for (unsigned long long i = 0; i < 32; ++i) {       precalc.push_back(cur);       cur *= 4;     }     for (unsigned long long i = 1; i < 32; ++i) {       precalc[i] += precalc[i - 1];     }     unsigned long long q;     cin >> q;     while (q--) {       solve();     }     return 0;   }   void get_time() {}


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2010;   const int MAXM = 4100000;   int F[MAXN];   struct node {     long long x, y, c;   } a[MAXN];   struct Edge {     long long u, v, w;   } edge[MAXM];   int tol;   vector<long long> vec1;   vector<pair<long long, long long> > vec2;   void addedge(long long u, long long v, long long w) {     edge[tol].u = u;     edge[tol].v = v;     edge[tol++].w = w;   }   bool cmp(Edge a, Edge b) { return a.w < b.w; }   long long Find(long long x) {     if (F[x] == -1)       return x;     else       return F[x] = Find(F[x]);   }   long long Kruskal(int n) {     memset(F, -1, sizeof(F));     sort(edge, edge + tol, cmp);     long long cnt = 0;     long long ans = 0;     for (int i = 0; i < tol; i++) {       long long u = edge[i].u;       long long v = edge[i].v;       long long w = edge[i].w;       long long t1 = Find(u);       long long t2 = Find(v);       if (t1 != t2) {         if (u == 0)           vec1.push_back(v);         else if (v == 0)           vec1.push_back(u);         else           vec2.push_back(make_pair(u, v));         ans += w;         F[t1] = t2;         cnt++;       }       if (cnt == n) break;     }     if (cnt < n)       return -1;     else       return ans;   }   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i].x >> a[i].y;     for (int i = 1; i <= n; i++) {       long long c;       cin >> c;       addedge(0, i, c);       addedge(i, 0, c);     }     for (int i = 1; i <= n; i++) cin >> a[i].c;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (j == i) continue;         long long ww =             (a[i].c + a[j].c) * (abs(a[i].x - a[j].x) + abs(a[i].y - a[j].y));         addedge(i, j, ww);       }     }     long long ans = Kruskal(n);     cout << ans << endl;     cout << vec1.size() << endl;     for (int i = 0; i < vec1.size(); i++) {       if (i != 0) cout <<    ;       cout << vec1[i];     }     cout << endl;     cout << vec2.size() << endl;     for (int i = 0; i < vec2.size(); i++) {       cout << vec2[i].first <<     << vec2[i].second << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 30;   const int M = 110;   const int LIT = 2500;   const int INF = 1 << 28;   string s;   int n, m;   int val[N][N];   void init() {     cin >> n;     memset(val, 0, sizeof(val));     for (int i = 1; i <= n; i++) {       string a, b;       int v;       cin >> a >> b >> v;       int aa = a[0] -  a ;       int bb = b[0] -  a ;       val[aa][bb] = v;     }   }   int dp[M][M][N];   void solve() {     memset(dp, 0, sizeof(dp));     for (int i = 0; i < 26; i++) {       int ch = s[0] -  a ;       dp[0][1][i] = 0;       dp[0][0][i] = -INF;       if (i == ch) dp[0][0][i] = 0;     }     for (int i = 1; i < s.size(); i++) {       int ch = s[i] -  a ;       for (int j = 0; j <= i + 1; j++) {         for (int k = 0; k < 26; k++) {           int Max = -INF;           if (ch == k && j <= i) {             for (int p = 0; p < 26; p++) {               int tmp = dp[i - 1][j][p] + val[p][k];               Max = max(Max, tmp);             }           } else {             for (int p = 0; j && p < 26; p++) {               int tmp = dp[i - 1][j - 1][p] + val[p][k];               Max = max(Max, tmp);             }           }           dp[i][j][k] = Max;         }       }     }     int out = s.size() - 1, res = -INF;     for (int i = 0; i <= min(out + 1, m); i++) {       for (int k = 0; k < 26; k++) {         res = max(res, dp[out][i][k]);       }     }     cout << res << endl;   }   int main() {     while (cin >> s >> m) {       init();       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   long long a[200000 + 1], b[200000 + 1];   int c[200000 + 1], t[200000 + 1];   int n, m, k, s;   vector<pair<long long, int> > v;   inline int check(int p) {     int i;     v.clear();     long long mna = (1LL << 62), mnb = (1LL << 62);     for (i = 1; i <= p; i++) {       mna = min(mna, a[i]);       mnb = min(mnb, b[i]);     }     for (i = 1; i <= m; i++) {       if (t[i] == 1)         v.push_back({1LL * mna * c[i], i});       else         v.push_back({1LL * mnb * c[i], i});     }     sort(v.begin(), v.end());     int cnt = 0;     long long aux = s;     for (i = 0; i < m; i++) {       if (aux >= v[i].first) {         aux -= v[i].first;         cnt++;       }     }     return cnt;   }   int main() {     int i;     ios::sync_with_stdio(false);     cin >> n >> m >> k >> s;     for (i = 1; i <= n; i++) cin >> a[i];     for (i = 1; i <= n; i++) cin >> b[i];     for (i = 1; i <= m; i++) cin >> t[i] >> c[i];     int rez = 0;     for (int pas = 1 << 17; pas; pas >>= 1)       if (rez + pas <= n && check(rez + pas) < k) rez += pas;     if (rez == n) {       cout << -1;       return 0;     }     rez++;     cout << rez << endl;     v.clear();     long long mna = (1LL << 62), mnb = (1LL << 62);     int pa, pb;     for (i = 1; i <= rez; i++) {       mna = min(mna, a[i]);       if (mna == a[i]) pa = i;       mnb = min(mnb, b[i]);       if (mnb == b[i]) pb = i;     }     for (i = 1; i <= m; i++) {       if (t[i] == 1)         v.push_back({1LL * mna * c[i], i});       else         v.push_back({1LL * mnb * c[i], i});     }     sort(v.begin(), v.end());     int cnt = 0;     for (i = 0; i < m && cnt < k; i++) {       if (s >= v[i].first) {         s -= v[i].first;         cnt++;         if (t[v[i].second] == 1)           cout << v[i].second <<     << pa << endl;         else           cout << v[i].second <<     << pb << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, zz;   string s;   int a[28];   int main(void) {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int ntest;     cin >> ntest;     while (ntest--) {       cin >> n >> m >> zz >> s;       for (int i = 0; i < 28; ++i) a[i] = 0;       for (int i = 0; i < s.size(); ++i) ++a[s[i] -  A ];       int ans = 1e9;       for (int i = 0; i < 27; ++i) {         vector<bool> can(zz - a[i] + 1, 0);         can[0] = 1;         for (int j = 0; j < 26; ++j)           if (j != i) {             for (int k = zz - a[i]; k >= 0; --k)               if (can[k]) can[k + a[j]] = 1;           }         for (int j = 0; j <= zz - a[i]; ++j)           if (can[j]) {             int need_n = max(0, n - j);             int need_m = max(0, m - (zz - a[i] - j));             if (need_n + need_m > a[i]) continue;             ans = min(ans, need_n * need_m);           }       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a[5], sum = 0;     for (int i = 0; i < 5; i++) {       cin >> a[i];       sum += a[i];     }     if (sum % 5 == 0 && sum != 0)       cout << (sum / 5);     else       cout << -1;   }


#include <bits/stdc++.h>   using namespace std;   const int LIM = 1e+5 + 100;   int n, m, k;   int get_rd(int i, int j) {     if (i == j) {       return n;     } else if (i < j) {       return n + (j - i);     } else {       return n - (i - j);     }   }   int get_ld(int i, int j) {     if (i + j == n) {       return n;     } else if (i + j < n) {       return i + j;     } else {       return i + j;     }   }   struct detector {     int i, j, id;     detector(int i, int j, int id) : i(i), j(j), id(id) {}     int get_rd() { return ::get_rd(i, j); }     int get_ld() { return ::get_ld(i, j); }   };   vector<bool> used(LIM, false);   vector<long long> ans(LIM, -1);   vector<vector<detector>> ld(2 * LIM);   vector<vector<detector>> rd(2 * LIM);   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n >> m >> k;     for (int i = 0; i < k; ++i) {       int pi, pj;       cin >> pi >> pj;       detector newbie(pi, pj, i);       rd[newbie.get_rd()].push_back(newbie);       ld[newbie.get_ld()].push_back(newbie);     }     int i = 0, j = 0;     int di = 1, dj = 1;     long long time = 0;     while (true) {       int d = -1;       if (di == dj) {         d = get_rd(i, j);         for (const detector& det : rd[d]) {           int id = det.id;           if (!used[id]) {             ans[id] = time + abs(i - det.i);             used[id] = true;           }         }       } else {         d = get_ld(i, j);         for (const detector& det : ld[d]) {           int id = det.id;           if (!used[id]) {             ans[id] = time + abs(i - det.i);             used[id] = true;           }         }       }       if (di == 1 && dj == 1) {         int delta = min(n - i, m - j);         time += delta;         i += delta;         j += delta;         if (i == n && j == m) {           break;         }         if (i == n)           di = -1;         else           dj = -1;       } else if (di == -1 && dj == -1) {         int delta = min(i, j);         time += delta;         i -= delta;         j -= delta;         if (i == 0 && j == 0) break;         if (i == 0)           di = 1;         else           dj = 1;       } else if (di == 1 && dj == -1) {         int delta = min(n - i, j);         time += delta;         i += delta;         j -= delta;         if (i == n && j == 0) break;         if (i == n)           di = -1;         else           dj = 1;       } else {         int delta = min(i, m - j);         time += delta;         i -= delta;         j += delta;         if (i == 0 && j == m) break;         if (i == 0)           di = 1;         else           dj = -1;       }     }     for (int i = 0; i < k; ++i) cout << ans[i] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int v[100001];   int acum[100001];   long long cnt = 0, ans[100001];   struct Q {     int i, j, p;     Q(int a, int b, int c) : i(a), j(b), p(c){};     Q() {}     bool operator<(const Q &other) const {       if (i / 300 == other.i / 300) return j < other.j;       return i / 300 < other.i / 300;     }   };   vector<Q> queries;   int freq[(1 << 20) - 1 + 1];   int main() {     int n, m, k;     scanf( %d %d %d , &n, &m, &k);     for (int i = 1; i <= n; i++) {       scanf( %d , v + i);       acum[i] = v[i] ^ acum[i - 1];     }     for (int k = 0; k < m; k++) {       int i, j;       scanf( %d %d , &i, &j);       queries.push_back(Q(i - 1, j, k));     }     sort(queries.begin(), queries.end());     int l = 0, r = 0;     freq[0] = 1;     for (int q = 0; q < m; q++) {       int i = queries[q].i, j = queries[q].j, p = queries[q].p;       while (l < i) {         freq[acum[l]]--;         cnt -= freq[acum[l] ^ k];         l++;       }       while (l > i) {         --l;         cnt += freq[acum[l] ^ k];         freq[acum[l]]++;       }       while (r < j) {         r++;         cnt += freq[acum[r] ^ k];         freq[acum[r]]++;       }       while (r > j) {         freq[acum[r]]--;         cnt -= freq[acum[r] ^ k];         r--;       }       ans[p] = cnt;     }     for (int i = 0; i < m; i++) printf( %lld n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   const int mod = 1000000007;   const int inf = 1000000009;   const long long INF = 1000000000000000009;   const long long big = 1000000000000000;   const long double eps = 0.0000000001;   using namespace std;   int DP[2005][2005], T[2005];   int main() {     ios::sync_with_stdio(false);     cin.tie();     cout.tie();     int n, h;     cin >> n >> h;     for (int i = 1; i <= n; i++) cin >> T[i];     DP[0][0] = 1;     for (int i = 1; i <= n; i++) {       int j = h - T[i];       if (j < 0) continue;       DP[i][j] = (DP[i][j] + DP[i - 1][j]) % mod;       DP[i][j] %= mod;       if (j > 0) {         DP[i][j] = (DP[i][j] + DP[i - 1][j - 1]) % mod;         DP[i][j - 1] = ((long long int)DP[i][j - 1] + DP[i - 1][j - 1] +                         (long long int)DP[i - 1][j] * j) %                        mod;         DP[i][j - 1] =             (DP[i][j - 1] + (long long int)DP[i - 1][j - 1] * (j - 1)) % mod;       }     }     cout << DP[n][0];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100;   int a[maxn], b[maxn];   int main() {     int t;     scanf( %d , &t);     while (t--) {       int n;       scanf( %d , &n);       int MIN1 = 0x7fffffff;       int MIN2 = 0x7fffffff;       for (int i = 1; i <= n; i++) {         scanf( %d , &a[i]);         MIN1 = min(MIN1, a[i]);       }       for (int i = 1; i <= n; i++) {         scanf( %d , &b[i]);         MIN2 = min(MIN2, b[i]);       }       long long ans = 0;       for (int i = 1; i <= n; i++) {         if (a[i] - MIN1 == 0 && b[i] - MIN2 != 0) {           ans += (b[i] - MIN2);           continue;         }         if (a[i] - MIN1 != 0 && b[i] - MIN2 == 0) {           ans += (a[i] - MIN1);           continue;         }         if (a[i] - MIN1 > b[i] - MIN2) {           ans += (b[i] - MIN2);           a[i] -= (b[i] - MIN2);           ans += (a[i] - MIN1);         } else {           ans += (a[i] - MIN1);           b[i] -= (a[i] - MIN1);           ans += (b[i] - MIN2);         }       }       printf( %lld n , ans);     }     return 0;   }