#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const int INF = 0x3f3f3f3f;   const int MOD = 1e9 + 7;   const double EPS = 1e-9;   int n, k, deg[1000015], ans, vis[1000015];   vector<int> e[1000015];   int dfs(int u) {     if (e[u].size() == 1) return 1;     vis[u] = 1;     vector<int> d;     for (int i = 0; i < e[u].size(); ++i) {       int v = e[u][i];       if (vis[v]) continue;       int x = dfs(v);       if (~x) d.push_back(x);     }     sort(d.begin(), d.end());     if (0 == d.size()) {       return -1;     } else if (1 == d.size()) {       if (d[0] >= k) {         ++ans;         return -1;       } else {         return ~d[0] ? d[0] + 1 : d[0];       }     }     int i = 0;     while (i + 1 < d.size() && d[i] + d[i + 1] <= k) ++i;     ans += d.size() - i - 1;     return ~d[i] ? d[i] + 1 : d[i];   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i < n; ++i) {       int u, v;       scanf( %d%d , &u, &v);       ++deg[u], ++deg[v];       e[u].push_back(v), e[v].push_back(u);     }     for (int i = 1; i <= n; ++i) {       if (1 != deg[i]) {         if (~dfs(i)) ++ans;         break;       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 2e18 + 7;   const long long mod = 1e9 + 7;   const double eps = 1e-9;   const double PI = 2 * acos(0.0);   const double E = 2.71828;   int n;   pair<int, int> a[200005];   int main(void) {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       int x, y;       scanf( %d %d , &x, &y);       a[i] = {x + y, x - y};     }     sort(a, a + n);     int mx = -mod;     int res = 0;     for (int i = 0; i < n; ++i) {       if (mx <= a[i].second) {         mx = a[i].first;         ++res;       }     }     printf( %d n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     int a, b, q;     cin >> q;     for (int i = 0; i < q; i++) {       cin >> n >> a >> b;       if (a * 2 <= b)         cout << n * a << endl;       else {         {           if (n % 2 == 0)             cout << b * n / 2 << endl;           else             cout << b * (n / 2) + a << endl;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int64_t max(int32_t a, int64_t b) { return max((int64_t)a, b); }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     pair<int64_t, int64_t> lc, rc;     cin >> rc.second >> rc.first;     lc.first = lc.second = 1;     int64_t k;     cin >> k;     int64_t cnt = 0;     int64_t ans = 0;     int64_t cur = 1;     while (cnt < k) {       ans += (rc.first - lc.first + 1) * (rc.second - lc.second + 1);       rc.first--;       rc.second--;       lc.second++;       lc.first++;       ans -= (rc.first - lc.first + 1) * (rc.second - lc.second + 1);       cnt++;       rc.first--;       rc.second--;       lc.second++;       lc.first++;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int T;     cin >> T;     while (T--) {       long long n, side = 0, ans = 0;       cin >> n;       int i = (n + 1) % 4;       if (i == 0)         ans = n + 1;       else if (i == 1 || i == 3)         ans = 4 * n + 1;       else         ans = 2 * n + 1;       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s1, s2, s;     cin >> s1 >> s2 >> s;     string s3 = s1 + s2;     sort(s3.begin(), s3.end());     sort(s.begin(), s.end());     if (s == s3)       cout <<  YES n ;     else       cout <<  NO n ;     return 0;   }


#include <bits/stdc++.h>   struct node {     int x, y, next;   } e[100861];   int head[100861], book[100861] = {0}, b[100861];   int main() {     memset(head, -1, sizeof(head));     int n, m, a;     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d%d , &e[i].x, &e[i].y);       e[i].next = head[e[i].x];       head[e[i].x] = i;       book[e[i].y]++;     }     int sum = 0, flag = 1, maxx = 0, f;     for (int i = 1; i <= n; i++)       if (book[i] == 0) {         b[sum++] = i;       }     if (sum != 1) flag = 0;     for (int i = 0; i < sum; i++) {       int num = 0;       for (int j = head[b[i]]; j != -1; j = e[j].next) {         book[e[j].y]--;         if (book[e[j].y] == 0) {           b[sum++] = e[j].y;           num++;           if (j > maxx) maxx = j;         }       }       if (num > 1) flag = 0;     }     if (flag == 0 || sum < n)       printf( -1 n );     else       printf( %d n , maxx);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void reader() {}   const long long MOD = 1e9 + 7;   const long long N = 3e7 + 5;   const long long inf = 1e18;   long long Set(long long qq, long long pos) { return (qq | (1 << pos)); }   long long chk(long long qq, long long pos) { return (qq & (1 << pos)); }   void solve() {     long long n, first, second;     cin >> n >> first >> second;     vector<long long> dp(n + 1);     dp[1] = first;     dp[0] = 0;     for (long long i = 2; i <= n; i++) {       if (i % 2 == 0)         dp[i] = min(dp[i - 1] + first, dp[i / 2] + second);       else         dp[i] = min(dp[(1 + i) / 2] + first + second, dp[i - 1] + first);     }     cout << dp[n];   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     reader();     solve();   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100100;   int ar[MAXN];   int N;   int main() {     int sum = 0;     for (int i = 0; i < 6; ++i) {       scanf( %d , ar + i);       sum ^= ar[i];     }     sort(ar, ar + 6);     if (ar[0] != ar[3] && ar[1] != ar[4] && ar[2] != ar[5]) {       printf( Alien n );     } else if (sum) {       printf( Bear n );     } else {       printf( Elephant n );     }   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   bool uin(T &a, T b) {     return a > b ? (a = b, true) : false;   }   template <class T>   bool uax(T &a, T b) {     return a < b ? (a = b, true) : false;   }   int n, a, b;   void solve() {     cin >> n >> a >> b;     string s;     cin >> s;     a--;     b--;     if (s[a] == s[b]) {       cout << 0;     } else {       cout << 1;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int N = 110031;   long long n, m;   vector<vector<long long> > one(int sz) {     vector<vector<long long> > ret;     ret.resize(sz);     for (int i = 0; i < ret.size(); i++) {       ret[i].resize(sz);       for (int j = 0; j < ret.size(); j++) {         ret[i][j] = (i == j);       }     }     return ret;   }   vector<vector<long long> > mult(vector<vector<long long> > a,                                   vector<vector<long long> > b) {     vector<vector<long long> > ret;     ret.resize(a.size());     for (int i = 0; i < ret.size(); i++) {       ret[i].resize(a.size());       for (int j = 0; j < ret.size(); j++) {         ret[i][j] = 0;       }     }     for (int k = 0; k < ret.size(); k++) {       for (int i = 0; i < a.size(); i++) {         for (int j = 0; j < b.size(); j++) {           ret[i][j] = (ret[i][j] + a[i][k] * b[k][j]);           ret[i][j] %= 1000000007;         }       }     }     return ret;   }   vector<vector<long long> > pw(vector<vector<long long> > a, long long b) {     if (b == 0) return one((int)a.size());     if (b % 2) return mult(a, pw(a, b - 1));     return pw(mult(a, a), b / 2);   }   vector<vector<long long> > dp;   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> m;     dp.resize(m);     for (int i = 0; i < m; i++) {       dp[i].resize(m);     }     for (int i = 0; i < dp.size(); i++) {       for (int j = 0; j < dp.size(); j++) {         dp[i][j] = 0;       }     }     for (int i = 0; i < dp.size(); i++) {       dp[i][(i + 1) % m]++;     }     dp[0][0]++;     dp = pw(dp, n);     cout << dp[0][0] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int f[10005];   int vis[100005];   void init() {     f[1] = 1;     f[2] = 1;     vis[1] = 1;     for (int i = 3; i <= 20; i++) {       f[i] = f[i - 1] + f[i - 2];       vis[f[i]] = 1;     }   }   int main() {     int n;     scanf( %d , &n);     init();     for (int i = 1; i <= n; i++) {       if (vis[i] == 1)         printf( O );       else         printf( o );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200005;   string s, t;   int pre[maxn][26], pos[26];   int f[maxn];   int g[maxn];   void solve(string &s, string &t, int f[]) {     for (int i = 0; i < 26; i++) pos[i] = -1;     int n = t.size(), m = s.size();     for (int i = 0; i <= n; i++) {       for (int j = 0; j < 26; j++) {         pre[i][j] = pos[j];       }       if (i < n) pos[t[i] -  a ] = i;     }     int len = 0;     for (int i = 0; i < m; i++) {       if (len < n && s[i] == t[len]) {         f[i] = ++len;       } else {         f[i] = pre[len][s[i] -  a ] + 1;       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> s >> t;     solve(s, t, f);     reverse(s.begin(), s.end());     reverse(t.begin(), t.end());     solve(s, t, g);     bool ok = true;     int m = s.size(), n = t.size();     for (int i = 0; i < m; i++) {       if (f[i] + g[m - i - 1] - 1 < n) {         ok = false;         break;       }     }     if (ok)       cout <<  Yes n ;     else       cout <<  No n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long sqr(long long x) { return (x * x); }   inline long long dist(pair<long long, long long> a,                         pair<long long, long long> b) {     return sqr(a.first - b.first) + sqr(a.second - b.second);   }   int main() {     vector<pair<long long, pair<long long, long long> > > a;     int d;     double answer;     int n;     scanf( %d , &n);     long long x, y, r;     for (int i = 0; i < n; i++) {       scanf( %I64d %I64d %I64d , &x, &y, &r);       a.push_back(make_pair(r, make_pair(x, y)));     }     sort(a.begin(), a.end());     for (int i = 0; i < n; i++) {       d = 0;       for (int j = i + 1; j < n; j++)         if (dist(a[i].second, a[j].second) <= sqr(a[j].first)) d++;       answer += (double)acos(-1) * sqr(a[i].first) * ((!d || d & 1) ? 1 : -1);     }     printf( %.10lf n , answer);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   static const int INF = 0x3f3f3f3f;   static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;   template <typename T, typename U>   static void amin(T &x, U y) {     if (y < x) x = y;   }   template <typename T, typename U>   static void amax(T &x, U y) {     if (x < y) x = y;   }   template <typename It>   void make_fenwick(It beg, size_t n) {     for (size_t i = 0; i < n; i++) {       size_t p = i | (i + 1);       if (p < n) beg[p] += beg[i];     }   }   template <typename It, typename Val>   void add_fenwick(It beg, size_t n, size_t i, Val val) {     for (; i < n; i |= i + 1) beg[i] += val;   }   template <typename It, typename Val>   Val sum_fenwick(It beg, size_t i, Val sum) {     for (; i > 0; i = i & (i - 1)) sum += beg[i - 1];     return sum;   }   template <typename It>   typename std::iterator_traits<It>::value_type sum_fenwick(It beg, size_t i) {     return sum_fenwick(beg, i, typename std::iterator_traits<It>::value_type());   }   size_t highestOneBit(size_t v) {     v |= v >> 1;     v |= v >> 2;     v |= v >> 4;     v |= v >> 8;     v |= v >> 16;     return (v >> 1) + 1;   }   template <typename It, typename Val, typename Cmp>   size_t search_fenwick(It beg, size_t n, Val val, Val left, Cmp cmp) {     if (!cmp(left, val)) return 0;     size_t i = 0;     for (size_t w = highestOneBit(n); w > 0; w >>= 1) {       if (i + w <= n) {         Val mid = left;         mid += beg[i + w - 1];         if (cmp(mid, val)) {           i += w;           left = mid;         }       }     }     return i + 1;   }   template <typename It, typename Val>   size_t lower_bound_fenwick(It beg, size_t n, Val val) {     return search_fenwick(beg, n, val, Val(), std::less<Val>());   }   int main() {     int n;     int m;     while (~scanf( %d%d , &n, &m)) {       vector<vector<int> > graph(n);       for (int i = 0; i < m; ++i) {         int u, v;         scanf( %d%d , &u, &v), --u, --v;         graph[u].push_back(v);         graph[v].push_back(u);       }       int w;       scanf( %d , &w);       vector<vector<pair<int, int> > > shops(n);       vector<int> prices;       for (int(i) = 0; (i) < (int)(w); ++(i)) {         int c;         int k;         int p;         scanf( %d%d%d , &c, &k, &p), --c;         shops[c].emplace_back(k, p);         prices.push_back(p);       }       sort(prices.begin(), prices.end());       prices.erase(unique(prices.begin(), prices.end()), prices.end());       int P = (int)prices.size();       for (int(i) = 0; (i) < (int)(n); ++(i))         for (auto &s : shops[i])           s.second = (int)(lower_bound(prices.begin(), prices.end(), s.second) -                            prices.begin());       int q;       scanf( %d , &q);       vector<int> que(n), dist, ft;       vector<long long> ftsum;       for (int(ii) = 0; (ii) < (int)(q); ++(ii)) {         int g;         int r;         int a;         scanf( %d%d%d , &g, &r, &a), --g;         int qt = 0;         que[qt++] = g;         dist.assign(n, INF);         dist[g] = 0;         ft.assign(P, 0);         ftsum.assign(P, 0);         int ans = -1;         for (int qh = 0; qh < qt; ++qh) {           int i = que[qh];           int d = dist[i];           for (auto s : shops[i]) {             int k, pi;             tie(k, pi) = s;             add_fenwick(ft.begin(), ft.size(), pi, k);             add_fenwick(ftsum.begin(), ftsum.size(), pi,                         (long long)k * prices[pi]);           }           int pi = lower_bound_fenwick(ft.begin(), ft.size(), r) - 1;           if (pi < P) {             long long p = sum_fenwick(ftsum.begin(), pi);             p += (long long)prices[pi] * (r - sum_fenwick(ft.begin(), pi));             if (p <= a) {               ans = d;               break;             }           }           for (int j : graph[i]) {             if (dist[j] != INF) continue;             dist[j] = dist[i] + 1;             que[qt++] = j;           }         }         printf( %d n , ans);       }     }     return 0;   }


#include <iostream>   #include <cmath>      using namespace std;       const int N=2e3+3;   int a[N];   int b[N];       int main(){    int n;    cin>>n;    n<<=1;    for(int i=1;i<=n;i++) cin>>a[i];        int ans=n;        for(int C=0;C<=1;C++){        for(int j=1;j<=n;j++) b[j]=a[j];        int cnt=0;    for(int i=0;i<n;i++){     int ok=1;     for(int j=1;j<=n;j++) ok&=b[j]==j;     if(ok) ans=min(ans,i);          if(cnt^C) for(int j=1;j<=n;j+=2) swap(b[j],b[j+1]);     else for(int j=1;j<=n>>1;j++) swap(b[j],b[j+n/2]);          cnt^=1;     }       }       if(ans==n) cout<<-1;       else cout<<ans;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T min(T a, T b, T c) {     return min(min(a, b), c);   }   template <class T>   inline T min(T a, T b, T c, T d) {     return min(min(a, b), min(c, d));   }   template <class T>   inline T max(T a, T b, T c) {     return max(max(a, b), c);   }   template <class T>   inline T max(T a, T b, T c, T d) {     return max(max(a, b), max(c, d));   }   const int INF = 1e9;   const long long INF_LL = 4e18;   const double pi = acos(-1.0);   int dx[] = {-1, 1, 0, 0};   int dy[] = {0, 0, -1, 1};   int n;   vector<long long> odd;   int main() {     scanf( %d , &n);     long long ans = 0;     for (int i = 0; i < n; i++) {       long long x;       cin >> x;       if (x % 2L)         odd.push_back(x);       else         ans += x;     }     sort((odd).begin(), (odd).end());     for (int i = int((odd).size()) % 2; i < int((odd).size()); i++) ans += odd[i];     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long double nb;     cin >> nb;     if (nb <= 127)       cout <<  byte ;     else if (nb <= 32767)       cout <<  short ;     else if (nb <= 2147483647)       cout <<  int ;     else if (nb <= 9223372036854775807LL)       cout <<  long ;     else       cout <<  BigInteger ;   }


#include <bits/stdc++.h>   using namespace std;   long long a1, a2, b1, b2, c1, c2;   int main() {     ios_base::sync_with_stdio(0);     cin.tie();     cout.tie();     cin >> a1 >> b1 >> c1 >> a2 >> b2 >> c2;     if (!a1 && !b1 && c1 || !a2 && !b2 && c2) {       cout <<  0 ;       return 0;     }     if (a1 * b2 != a2 * b1) {       cout << 1;       return 0;     }     if (c1 * b2 == c2 * b1 && c1 * a2 == c2 * a1) {       cout <<  -1 ;       return 0;     }     cout << 0;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1e5 + 5;   int A[M];   char B[M];   int main() {     int n;     scanf( %d , &n);     for (int j = 0; j < n; j++) scanf( %d , &A[j]);     scanf( %s , B);     int cnt = 0;     for (int j = 0; j < n; j++)       if (B[j] ==  1 ) cnt += A[j];     int ans = cnt, sum = 0, sum1 = 0;     for (int j = 0; j < n; j++) {       if (B[j] ==  1 ) {         ans = max(ans, cnt - A[j] + sum1 - sum);         sum += A[j];       }       sum1 += A[j];     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n;     cin >> n;     long long a[n];     for (long long i = 0; i < n; i++) cin >> a[i];     long long f[n - 1];     long long s[n - 1];     for (long long i = 0; i < n - 1; i++) {       f[i] = abs((a[i] - a[i + 1])) * pow(-1, i);       s[i] = abs((a[i] - a[i + 1])) * (pow(-1, i + 1));     }     long long curr = f[0];     long long max_sofar = f[0];     for (long long i = 1; i <= n - 2; i++) {       curr = max(f[i], curr + f[i]);       max_sofar = max(max_sofar, curr);     }     if (n > 2) curr = s[1];     max_sofar = max(max_sofar, curr);     for (long long i = 2; i <= n - 2; i++) {       curr = max(s[i], curr + s[i]);       max_sofar = max(max_sofar, curr);     }     cout << max_sofar;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       while (n--) {         if (n == 0) {           cout <<  1  <<   n ;         } else {           cout <<  1  ;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int a, b;   int main() {     scanf( %d:%d , &a, &b);     if (a > 11) a = a - 12;     cout << (b / 2.0 + a * 30) <<     << 6 * b;   }


#include <bits/stdc++.h>   using namespace std;   int a[4];   int cur[100005];   void work(int x, int y, int z, int w, int tp) {     if (x + z < y + w) return;     if (x + z >= y + w + 2) return;     int nlen = x + y + z + w;     for (int pl = 1; pl <= nlen; pl += 2) {       if (x)         cur[pl] = 0, x--;       else         cur[pl] = 2, z--;     }     for (int pl = 2; pl <= nlen; pl += 2) {       if (y)         cur[pl] = 1, y--;       else         cur[pl] = 3, w--;     }     for (int pl = 1; pl < nlen; pl++)       if (abs(cur[pl] - cur[pl + 1]) != 1) return;     printf( YES n );     for (int i = 1; i <= nlen; i++) {       if (tp)         printf( %d  , 3 - cur[i]);       else         printf( %d  , cur[i]);     }     exit(0);   }   int main() {     cin >> a[0] >> a[1] >> a[2] >> a[3];     work(a[0], a[1], a[2], a[3], 0);     work(a[3], a[2], a[1], a[0], 1);     printf( NO n );     return 0;   }


#include <bits/stdc++.h>   namespace ringo {   template <class T>   inline void read(T &x) {     x = 0;     char c = getchar();     bool f = 0;     while (!isdigit(c)) f ^= c ==  - , c = getchar();     while (isdigit(c)) x = x * 10 + c -  0 , c = getchar();     if (f) x = -x;   }   template <class T>   inline void print(T x) {     if (x < 0) putchar( - ), x = -x;     if (x > 9) print(x / 10);     putchar( 0  + x % 10);   }   template <class T>   inline void print(const std::vector<T> &vet) {     for (auto it : vet) print(it), putchar(   );   }   template <class T>   inline void print(T x, char c) {     print(x), putchar(c);   }   template <class T>   inline void print(T a, int l, int r, std::string s =   ) {     if (s !=   ) std::cout << s <<  :  ;     for (int i = l; i <= r; i++) print(a[i],    n [i == r]);   }   const int N = 110, M = 1e5 + 10, mod = 1e9 + 7;   bool vis[N];   std::map<int, int> map;   std::vector<int> node, vet, dp[N][2];   int n, m, ans, sum, cnt, nod, fa[N], fa_x[N], fac[M], ifac[M], mov[1 << 20];   struct edge_t {     int u, v, w;   };   std::vector<edge_t> e, edge, rest, G[N];   inline int dec(int a, int b) {     a -= b;     return a < 0 ? a + mod : a;   }   inline int inc(int a, int b) {     a += b;     return a >= mod ? a - mod : a;   }   inline int mul(int a, int b) {     return (long long)a * b - (long long)a * b / mod * mod;   }   inline void inc_f(int &a, int b) {     a += b;     if (a >= mod) a -= mod;   }   inline int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }   inline int find_x(int x) {     return fa_x[x] == x ? x : fa_x[x] = find_x(fa_x[x]);   }   inline int binom(int n, int m) {     return n < m ? 0 : mul(fac[n], mul(ifac[m], ifac[n - m]));   }   int get_id(int x) {     auto it = map.find(x);     return it == map.end() ? map[x] = ++nod : it->second;   }   std::vector<int> inc(const std::vector<int> &a, const std::vector<int> &b) {     std::vector<int> c(std::max(a.size(), b.size()));     for (int i = 0; i < a.size(); i++) c[i] = a[i];     for (int i = 0; i < b.size(); i++) c[i] = inc(c[i], b[i]);     return c;   }   std::vector<int> mul(const std::vector<int> &a, const std::vector<int> &b) {     std::vector<int> c(a.size() + b.size() - 1);     for (int i = 0; i < a.size(); i++)       for (int j = 0; j < b.size(); j++)         c[i + j] = (c[i + j] + (long long)a[i] * b[j]) % mod;     return c;   }   void init_fac(int n) {     fac[0] = fac[1] = ifac[0] = ifac[1] = 1;     for (int i = 2; i <= n; i++) fac[i] = mul(fac[i - 1], i);     for (int i = 2; i <= n; i++) ifac[i] = mul(mod - mod / i, ifac[mod % i]);     for (int i = 2; i <= n; i++) ifac[i] = mul(ifac[i - 1], ifac[i]);   }   void dfs(int u, int father) {     dp[u][0] = std::vector<int>{1};     dp[u][1] = std::vector<int>{};     for (auto it : G[u]) {       int v = it.v, w = it.w;       if (v != father) {         dfs(v, u);         if (!vis[u] && !vis[v]) {           dp[u][1] = inc(mul(dp[u][1], inc(dp[v][0], dp[v][1])),                          mul(dp[u][0], mul(dp[v][0], std::vector<int>{0, w})));         } else {           dp[u][1] = mul(dp[u][1], inc(dp[v][0], dp[v][1]));         }         dp[u][0] = mul(dp[u][0], inc(dp[v][0], dp[v][1]));       }     }   }   std::vector<int> solve(int now) {     node.clear(), edge.clear();     for (int i = 1; i <= nod; i++)       if (find(i) == now) node.push_back(i);     for (const auto &it : e)       if (find(it.u) == now) edge.push_back(it);     if (node.size() == 1) return std::vector<int>{1};     std::vector<int> res(edge.size() + 1);     if (node.size() <= 20) {       std::map<int, int> map;       for (int i = 0; i < node.size(); i++) map[node[i]] = i;       memset(mov, 0, 1 << node.size() << 2);       mov[0] = 1;       for (int i = 0, u, v; i < edge.size(); i++) {         u = map[edge[i].u], v = map[edge[i].v];         for (int x = (1 << node.size()) - 1; x >= 0; x--)           if (mov[x] && (x & (1 << u)) == 0 && (x & (1 << v)) == 0) {             inc_f(mov[x | (1 << u) | (1 << v)], mul(mov[x], edge[i].w));           }       }       for (int x = 0; x < (1 << node.size()); x++)         if (mov[x]) {           inc_f(res[__builtin_popcount(x) >> 1], mov[x]);         }       return res;     } else {       rest.clear();       for (auto it : node) fa_x[it] = it;       for (auto it : edge)         if (find_x(it.u) != find_x(it.v)) {           G[it.u].push_back({it.u, it.v, it.w});           G[it.v].push_back({it.v, it.u, it.w});           fa_x[find_x(it.u)] = find_x(it.v);         } else {           rest.push_back(it);         }       for (int x = 0; x < (1 << rest.size()); x++) {         sum = 1, cnt = 0;         memset(vis, 0, nod + 1);         for (int i = 0; i < rest.size(); i++)           if ((x >> i) & 1) {             if (vis[rest[i].u] || vis[rest[i].v]) {               sum = 0;               break;             }             ++cnt, sum = mul(sum, rest[i].w);             vis[rest[i].u] = vis[rest[i].v] = 1;           }         if (sum) {           dfs(now, 0);           std::vector<int> tmp(cnt + 1);           tmp[cnt] = sum;           res = inc(res, mul(tmp, inc(dp[now][0], dp[now][1])));         }       }       return res;     }   }   void main() {     read(m), read(n), init_fac(std::max(n, m));     for (int x, y, w, i = 1; i <= n; i++) {       read(x), read(y), read(w);       if (w != 1) e.push_back({get_id(x), get_id(y + m), w - 1});     }     for (int i = 1; i <= nod; i++) fa[i] = i;     for (edge_t it : e) fa[find(it.u)] = find(it.v);     vet.push_back(1);     for (int i = 1; i <= nod; i++)       if (find(i) == i) {         vet = mul(vet, solve(i));       }     for (int i = 0; i < vet.size() && i <= m; i++) {       ans = inc(ans, mul(vet[i], fac[m - i]));     }     print(ans,   n );   }   }  // namespace ringo   signed main() { return ringo::main(), 0; }


#include <bits/stdc++.h>   using namespace std;   struct rec {     int x, p;   } a[101];   vector<rec> ans;   int n;   bool was[101];   bool cmp(rec a, rec b) { return a.x > b.x; }   void dfs(int v) {     was[v] = true;     for (int i = v + 1; i < n; ++i) {       if (a[v].x == 0) break;       if (!was[i]) {         a[v].x--;         rec r;         r.x = a[v].p;         r.p = a[i].p;         ans.push_back(r);         dfs(i);       }     }   }   int main() {     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> a[i].x;       a[i].p = i;     }     sort(a + 1, a + n, cmp);     dfs(0);     for (int i = 0; i < n; ++i)       if (!was[i]) {         cout << -1;         return 0;       }     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); ++i) {       cout << ans[i].x + 1 <<     << ans[i].p + 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[1000100];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int x;       scanf( %i , &x);       a[x]++;     }     int res = 0;     for (int i = 0; i < 1000100 - 1; i++) {       a[i + 1] += a[i] / 2;       a[i] %= 2;       res += a[i];     }     printf( %i n , res);   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void DBGpair(T a, string s =   ) {     cerr << s << (s ==    ?    :  :  ) << a.first <<  ,   << a.second <<   n ;   }   template <class T>   void DBGvec(vector<T> a) {     for (T i : a) cerr << i <<    ;     cerr <<   n ;   }   int dx[] = {0, 0, 1, -1};   int dy[] = {1, -1, 0, 0};   char dir[] = { R ,  L ,  D ,  U };   const int MOD = 1e9 + 7;   const long long INF = 1e9;   void setIO(string filename) {     if (fopen((filename +  .in ).c_str(),  r )) {       freopen((filename +  .in ).c_str(),  r , stdin);       freopen((filename +  .out ).c_str(),  w , stdout);     }   }   struct bit {     vector<long long> tree;     bit(int n) { tree = vector<long long>(n + 5, 0); }     long long rsq(int idx) {       long long sum = 0;       while (idx > 0) {         sum += tree[idx];         idx -= idx & -idx;       }       return sum;     }     long long rsq(int a, int b) {       a++;       b++;       return rsq(b) - (a == 1 ? 0 : rsq(a - 1));     }     void upd(int idx, int val) {       idx++;       while (idx < tree.size() - 1) {         tree[idx] += val;         idx += idx & -idx;       }     }   };   void solve() {     int n;     cin >> n;     vector<long long> a(n);     for (auto &i : a) cin >> i;     vector<long long> t(n);     for (auto &i : t) cin >> i;     vector<long long> psums(n + 1);     for (int i = 1; i <= n; i++) psums[i] = psums[i - 1] + t[i - 1];     bit tree(n);     vector<long long> pos(n + 1);     for (int i = 0; i < n; i++) tree.upd(i, 1);     for (int i = 0; i < n; i++) {       int idx = upper_bound((psums).begin(), (psums).end(), a[i] + psums[i]) -                 psums.begin();       if (idx == psums.size()) continue;       idx--;       pos[idx] += a[i] + psums[i] - psums[idx];       tree.upd(idx, -1);     }     for (int i = 0; i < n; i++) {       long long ans = tree.rsq(0, i) * t[i] + pos[i];       cout << ans <<    ;     }     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t = 1;     for (int i = 1; i <= t; i++) solve();   }


#include <bits/stdc++.h>   const int MAXN = 50 + 10;   bool row[MAXN];   bool column[MAXN];   int main() {     int n, x, y;     std::cin >> n;     for (int i = 0; i <= n * n; i++) {       std::cin >> x >> y;       if (row[x - 1] == false && column[y - 1] == false) {         row[x - 1] = true;         column[y - 1] = true;         std::cout << i + 1 <<    ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   istream& operator>>(istream& is, vector<T>& v) {     for (T& x : v) is >> x;     return is;   }   ostream& operator<<(ostream& os, const pair<int, int>& unit) {     return os <<  y =   << unit.first <<  x +   << unit.second;   }   template <class T>   ostream& operator<<(ostream& os, const vector<T>& v) {     if (!v.empty()) {       os << v.front();       for (int i = 1; i < v.size(); ++i) os <<     << v[i];     }     return os;   }   const int P = 1000000007;   int norm(int x) { return x >= P ? x - P : x; }   void add(int& x, int y) {     if ((x += y) >= P) x -= P;   }   pair<long long, long long> operator+(const pair<long long, long long>& lhs,                                        const pair<long long, long long>& rhs) {     return pair<long long, long long>(lhs.first + rhs.first,                                       lhs.second + rhs.second);   }   pair<long long, long long> operator-(const pair<long long, long long>& lhs) {     return pair<long long, long long>(-lhs.first, -lhs.second);   }   pair<long long, long long> operator-(const pair<long long, long long>& lhs,                                        const pair<long long, long long>& rhs) {     return lhs + (-rhs);   }   long long operator^(const pair<long long, long long>& lhs,                       const pair<long long, long long>& rhs) {     return lhs.first * rhs.first + lhs.second * rhs.second;   }   long long operator*(const pair<long long, long long>& lhs,                       const pair<long long, long long>& rhs) {     return lhs.first * rhs.second - lhs.second * rhs.first;   }   long long dfrac(long long x, long long y) {     if (x < 0) return (x - y + 1) / y;     return x / y;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int n, m, q;     cin >> n >> m >> q;     vector<int> u(m), v(m), w(m);     for (int i = 0; i < m; ++i) {       cin >> u[i] >> v[i] >> w[i];       --u[i];       --v[i];     }     vector<int> dp(n, numeric_limits<int>::min());     dp[0] = 0;     int ans = 0;     for (int i = 0; i < n; ++i) {       add(ans, *max_element(dp.begin(), dp.end()) % P);       vector<int> ndp(n, numeric_limits<int>::min());       for (int j = 0; j < m; ++j) {         ndp[u[j]] = max(ndp[u[j]], dp[v[j]] + w[j]);         ndp[v[j]] = max(ndp[v[j]], dp[u[j]] + w[j]);       }       swap(dp, ndp);     }     vector<pair<long long, long long> > pts;     for (int i = 0; i < m; ++i) {       int val = max(dp[u[i]], dp[v[i]]);       pts.emplace_back(w[i], val - w[i] * n);     }     sort(pts.begin(), pts.end());     vector<pair<long long, long long> > stk;     for (const auto& pt : pts) {       if (!stk.empty() && stk.back().first == pt.first) stk.pop_back();       while (stk.size() > 1 && ((stk[stk.size() - 1] - stk[stk.size() - 2]) *                                 (pt - stk[stk.size() - 1])) >= 0) {         stk.pop_back();       }       stk.push_back(pt);     }     auto contrib = [&](long long l, long long r,                        const pair<long long, long long>& lne) {       l = max(l, (long long)n);       r = min(r, (long long)q);       if (l <= r)         ans = (ans + (r - l + 1) * lne.second % P +                (l + r) * (r - l + 1LL) / 2 % P * lne.first) %               P;       if (ans < 0) ans += P;     };     long long cur = numeric_limits<long long>::min();     for (int i = 0; i + 1 < stk.size(); ++i) {       long long nxt = dfrac(stk[i].second - stk[i + 1].second,                             stk[i + 1].first - stk[i].first);       contrib(cur + 1, nxt, stk[i]);       cur = nxt;     }     contrib(cur + 1, numeric_limits<long long>::max(), stk.back());     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> vec[200005];   queue<int> Q;   int n, m;   int cvp[200005];   int top[200005], in[200005];   int a[200005], b[200005], c[200005];   void oku() {     int f, s, cost, i;     scanf( %d %d , &n, &m);     for (i = 1; i <= m; i++) {       scanf( %d %d %d , &f, &s, &cost);       vec[f].push_back(i);       vec[s].push_back(i);       a[i] = f;       b[i] = s;       c[i] = cost;       top[f] += cost;       top[s] += cost;     }     return;   }   void coz() {     int nod, s;     vector<int>::iterator it;     memset(cvp, -1, sizeof cvp);     Q.push(1);     while (!Q.empty()) {       nod = Q.front();       Q.pop();       for (it = vec[nod].begin(); it != vec[nod].end(); it++)         if (cvp[*it] == -1) {           if (nod == b[*it])             s = a[*it];           else             s = b[*it];           cvp[*it] = (nod == b[*it]);           in[s] += c[*it];           if (s != n && top[s] == 2 * in[s]) Q.push(s);         }     }     for (int i = 1; i <= m; i++) printf( %d n , cvp[i]);     return;   }   int main() {     oku();     coz();     return 0;   }


#include <bits/stdc++.h>   namespace IO {   char buf[1000000], *p1, *p2;   inline char getc() {     if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin);     return p1 == p2 ? EOF : *(p1++);   }   template <typename tp>   inline void r(tp &n) {     n = 0;     char c = getc();     while (!isdigit(c)) c = getc();     while (isdigit(c)) n = n * 10 + c - 48, c = getc();   }   template <typename tp, typename... Args>   inline void r(tp &n, Args &...args) {     r(n);     r(args...);   }   template <typename tp>   inline void write(tp n) {     if (n / 10) write(n / 10);     putchar(n % 10 + 48);   }   template <typename tp>   inline void w(tp n, char c =   n ) {     write(n);     putchar(c);   }   };  // namespace IO   using namespace IO;   const int N = 1e6 + 2333;   using namespace std;   int m;   int dep[N], f[N][25];   int LCA(int x, int y) {     if (dep[x] < dep[y]) x ^= y ^= x ^= y;     for (int i = 20; i >= 0; --i)       if (dep[f[x][i]] >= dep[y]) x = f[x][i];     if (x == y) return x;     for (int i = 20; i >= 0; --i)       if (f[x][i] != f[y][i]) x = f[x][i], y = f[y][i];     return f[x][0];   }   int dis(int a, int b) { return dep[a] + dep[b] - dep[LCA(a, b)] * 2; }   int main() {     r(m);     int n = 4, u = 2, v = 3, nowdis = 2;     for (int i = 2; i <= 4; ++i) f[i][0] = 1, dep[i] = 1;     while (m--) {       int x;       r(x);       dep[n + 1] = dep[x] + 1, f[n + 1][0] = x;       dep[n + 2] = dep[x] + 1, f[n + 2][0] = x;       for (int i = 0; f[n + 1][i]; ++i) f[n + 1][i + 1] = f[f[n + 1][i]][i];       for (int i = 0; f[n + 2][i]; ++i) f[n + 2][i + 1] = f[f[n + 2][i]][i];       n += 2;       int a = dis(u, n), b = dis(v, n), c = nowdis;       nowdis = max(max(a, b), c);       if (nowdis == a)         v = n;       else if (nowdis == b)         u = n;       w(nowdis);     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 ,  unroll-loops )   using namespace std;   template <class T>   inline void sort(T &a) {     sort((a).begin(), (a).end());   }   template <class T>   inline void rsort(T &a) {     sort((a).rbegin(), (a).rend());   }   template <class T>   inline void reverse(T &a) {     reverse((a).begin(), (a).end());   }   template <class T, class U>   inline void checkmin(T &x, U y) {     if (x > y) x = y;   }   template <class T, class U>   inline void checkmax(T &x, U y) {     if (x < y) x = y;   }   vector<vector<int>> rev, G;   void dfs(int v, int p = -1) {     for (auto &i : G[v])       if (i != p) {         rev[i].push_back(v);         dfs(i, v);       }   }   void solve() {     int n;     cin >> n;     G = vector<vector<int>>(n);     for (int i = 1; i < n; ++i) {       int u, v;       cin >> u >> v;       --u, --v;       G[u].push_back(v);       G[v].push_back(u);     }     int k1, k2;     cin >> k1;     vector<int> arr(k1);     for (auto &i : arr) cin >> i, --i;     cin >> k2;     vector<int> brr(k2);     for (auto &i : brr) cin >> i, --i;     vector<bool> used(n);     for (auto &i : arr) used[i] = true;     cout <<  B   << brr[0] + 1 << endl;     int y;     cin >> y;     --y;     rev = vector<vector<int>>(n);     dfs(y);     y = arr[0];     while (int(rev[y].size())) {       if (!used[rev[y][0]]) break;       y = rev[y][0];     }     int start = y;     cout <<  A   << y + 1 << endl;     cin >> y;     --y;     for (auto i : brr)       if (i == y) {         cout <<  C   << start + 1 << endl;         return;       }     cout <<  C   << -1 << endl;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout << fixed << setprecision(20);     srand(time(nullptr));     int q;     cin >> q;     while (q--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     size_t n;     string s, t;     cin >> n >> s >> t;     int base = ( z  -  a ) + 1;     vector<int> l(n + 1), r(n + 1);     for (int i = 0; i < int(n); ++i) {       l[i + 1] = s[i] -  a ;     }     for (int i = 0; i < int(n); ++i) {       r[i + 1] = t[i] -  a ;     }     for (int i = n; i >= 0; --i) {       l[i] += r[i];       if (i > 0) {         l[i - 1] += l[i] / 26;         l[i] %= 26;       }     }     vector<int> res(n + 1);     for (int i = 0; i <= n; ++i) {       int rem = l[i] % 2;       l[i] /= 2;       if (i < n) {         l[i + 1] += rem * 26;       }     }     for (int i = 1; i <= n; ++i) {       cout << char(l[i] +  a );     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long n, m, a, b, c;   vector<pair<long, long> > g[220000];   long cap[220000];   map<pair<long, long>, long> mapp;   set<pair<long, long> > done;   long ans[220000];   void solve(long v) {     for (int i = 0; i < g[v].size(); i++) {       long q = g[v][i].first;       long val = g[v][i].second;       if (done.find(make_pair(v, q)) != done.end()) continue;       done.insert(make_pair(v, q));       done.insert(make_pair(q, v));       ans[mapp[make_pair(v, q)]] = 1;       cap[q] -= val;       if (cap[q] == 0 && q < n) solve(q);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> m;     for (int i = 1; i <= m; i++) {       cin >> a >> b >> c;       mapp[make_pair(b, a)] = i;       g[a].push_back(make_pair(b, c));       g[b].push_back(make_pair(a, c));       cap[a] += c;       cap[b] += c;     }     for (int i = 1; i <= n; i++) cap[i] /= 2;     cap[n] = 0;     cap[1] = 0;     solve(1);     for (int i = 1; i <= m; i++) cout << ans[i] << endl;     cin.get();     cin.get();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f, mod = 998244353;   const long long INF = 0x3f3f3f3f3f3f3f3fLL;   const double pi = acosl(-1.), eps = 1e-9;   inline void sum(int &a, int b) {     a += b;     if (a >= mod) a -= mod;   }   inline int power(int a, int b, int m = mod, int ans = 1) {     for (; b; b >>= 1, a = 1LL * a * a % m)       if (b & 1) ans = 1LL * ans * a % m;     return ans;   }   const int NN = 10010;   int ch[NN], rch[NN];   int c(int n, int m) {     if (n < m) return 0;     if (!m) return 1;     return (long long)ch[n] * rch[n - m] % mod * rch[m] % mod;   }   int dp[111][5555];   int s[111][5555];   int main() {     ch[0] = 1;     for (int i = 1; i < NN; i++) ch[i] = (long long)ch[i - 1] * i % mod;     rch[NN - 1] = power(ch[NN - 1], mod - 2);     for (int i = NN - 1; i; i--) {       rch[i - 1] = (long long)rch[i] * i % mod;     }     int N, S, R;     cin >> N >> S >> R;     if (N == 1) {       puts( 1 );       return 0;     }     int tmp;     if (R == 0) {       tmp = c(N + S - 1, N - 1);     } else {       dp[0][0] = 1;       for (int i = 0; i <= S; i++) s[0][i] = 1;       for (int i = 1; i <= N; i++) {         for (int j = 0; j <= S; j++) {           dp[i][j] = s[i - 1][j];           if (j >= R) dp[i][j] -= s[i - 1][j - R];           if (dp[i][j] < 0) dp[i][j] += mod;         }         s[i][0] = 1;         for (int j = 1; j <= S; j++) {           s[i][j] = s[i][j - 1] + dp[i][j];           if (s[i][j] >= mod) s[i][j] -= mod;         }       }       tmp = c(S + N - 1, N - 1) - dp[N][S];       if (tmp < 0) tmp += mod;     }     tmp = (long long)tmp * power(N, mod - 2) % mod;     int tot = 0;     for (int i = R; i <= S; i++) {       sum(tot, c(S - i + N - 1 - 1, N - 2));     }     tot = power(tot, mod - 2);     cout << (long long)tmp * tot % mod << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<pair<int, int>, int> e[100010];   int parent[100010];   int Rank[100010];   int sz[100010];   vector<int> v[100010];   bool mark[100010];   bool mark1[100010];   int color[100010];   vector<int> out[2];   bool success[2];   int cnt[2];   int n, m;   int find(int cur) {     if (parent[cur] == cur) return cur;     return parent[cur] = find(parent[cur]);   }   void Union(int x, int y) {     int xroot = find(x);     int yroot = find(y);     if (xroot == yroot) return;     if (Rank[xroot] < Rank[yroot])       parent[xroot] = yroot;     else if (Rank[xroot] > Rank[yroot])       parent[yroot] = xroot;     else {       Rank[xroot]++;       parent[yroot] = xroot;     }   }   void init(int n) {     int i;     for (i = 0; i <= n; ++i) {       Rank[i] = 0;       parent[i] = i;       sz[i] = 0;     }   }   bool dfs(int cur, int c) {     mark[cur] = 1;     color[cur] = c;     cnt[c] += sz[cur];     for (int i = 0; i < v[cur].size(); ++i) {       if (mark[v[cur][i]]) {         if (color[v[cur][i]] == c) return 0;         continue;       }       if (!dfs(v[cur][i], 1 - c)) return 0;     }     return 1;   }   void dfs1(int cur) {     mark1[cur] = 1;     color[cur] = 1 - color[cur];     for (int i = 0; i < v[cur].size(); ++i)       if (!mark1[v[cur][i]]) dfs1(v[cur][i]);   }   void solve(int f) {     int i;     init(n);     success[f] = 0;     for (i = 1; i <= n; ++i) v[i].clear();     for (i = 0; i < m; ++i)       if (e[i].second == f) Union(e[i].first.first, e[i].first.second);     for (i = 0; i < m; ++i)       if (e[i].second != f) {         int x = find(e[i].first.first), y = find(e[i].first.second);         if (x == y) return;         v[x].push_back(y);         v[y].push_back(x);       }     for (i = 1; i <= n; ++i) sz[find(i)]++;     memset(mark, 0, sizeof(mark));     memset(mark1, 0, sizeof(mark1));     for (i = 1; i <= n; ++i) {       cnt[0] = cnt[1] = 0;       if (mark[find(i)]) continue;       if (!dfs(find(i), 0)) return;       if (cnt[0] > cnt[1]) dfs1(find(i));     }     success[f] = 1;     for (i = 1; i <= n; ++i)       if (color[find(i)] == 0) out[f].push_back(i);   }   int main() {     int i, x, y, c;     string s;     scanf( %d , &n);     scanf( %d , &m);     for (i = 0; i < m; ++i) {       scanf( %d , &x);       scanf( %d , &y);       cin >> s;       if (s[0] ==  R )         c = 0;       else         c = 1;       e[i] = make_pair(make_pair(x, y), c);     }     solve(0);     solve(1);     int minn = 1000000, minpos;     for (i = 0; i < 2; ++i)       if (success[i])         if ((int)out[i].size() < minn) {           minn = (int)out[i].size();           minpos = i;         }     if (minn == 1000000)       printf( %d n , -1);     else {       printf( %d n , minn);       for (auto it : out[minpos]) printf( %d  , it);       printf(  n );     }   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1 << 30;   const long long int MAX = 1e9 + 7;   void array_show(int *array, int array_n, char middle =    ) {     for (int i = 0; i < array_n; i++)       printf( %d%c , array[i], (i != array_n - 1 ? middle :   n ));   }   void array_show(long long int *array, int array_n, char middle =    ) {     for (int i = 0; i < array_n; i++)       printf( %lld%c , array[i], (i != array_n - 1 ? middle :   n ));   }   void array_show(vector<int> &vec_s, int vec_n = -1, char middle =    ) {     if (vec_n == -1) vec_n = vec_s.size();     for (int i = 0; i < vec_n; i++)       printf( %d%c , vec_s[i], (i != vec_n - 1 ? middle :   n ));   }   void array_show(vector<long long int> &vec_s, int vec_n = -1,                   char middle =    ) {     if (vec_n == -1) vec_n = vec_s.size();     for (int i = 0; i < vec_n; i++)       printf( %lld%c , vec_s[i], (i != vec_n - 1 ? middle :   n ));   }   string st[110000];   int t[110000];   int string_to_int(string sa) {     int s = 0;     int a;     for (auto ca : sa) {       s *= 10;       a = (int)ca - (int) 0 ;       if (a < 0 || a >= 10) return -1;       if (s == 0 && a == 0) return -1;       s += a;     }     return s;   }   bool used[110000];   vector<string> va[2], vb[2];   vector<pair<string, string>> vs;   int main() {     int n, m;     int i, j, k;     int a, b, c;     string sa;     cin >> n;     m = 0;     for (i = 0; i < n; i++) {       cin >> st[i] >> t[i];       if (t[i] == 1) m++;     }     b = -1;     for (i = 0; i < n; i++) {       a = string_to_int(st[i]);       if (a <= 0 || a > n)         vb[t[i]].push_back(st[i]);       else {         used[a] = true;         if (t[i] == 0 && a <= m) va[0].push_back(st[i]);         if (t[i] == 1 && a > m) va[1].push_back(st[i]);       }     }     for (i = 1; i <= n; i++) {       if (!used[i]) {         b = i;         break;       }     }     if (b == -1) {       if (va[0].empty()) {         cout << 0 << endl;         return 0;       }       vs.push_back(make_pair(va[0].back(), to_string(n + 1)));       a = string_to_int(va[0].back());       used[a] = false, b = a;       va[0].pop_back();       vb[0].push_back(to_string(n + 1));     }     while (1) {       if (b <= m)         a = 1;       else         a = 0;       if (va[a].empty()) break;       vs.push_back(make_pair(va[a].back(), to_string(b)));       c = string_to_int(va[a].back());       used[c] = false, used[b] = true;       va[a].pop_back(), b = c;     }     for (i = 1; i <= n; i++) {       if (used[i]) continue;       if (i <= m)         a = 1;       else         a = 0;       if (va[a].empty()) continue;       vs.push_back(make_pair(va[a].back(), to_string(i)));       c = string_to_int(va[a].back());       used[c] = false, used[i] = true;       va[a].pop_back();     }     for (i = 1; i <= n; i++) {       if (used[i]) continue;       if (i <= m)         a = 1;       else         a = 0;       if (vb[a].empty()) continue;       vs.push_back(make_pair(vb[a].back(), to_string(i)));       vb[a].pop_back();     }     cout << vs.size() << endl;     for (auto node : vs) {       cout <<  move   << node.first <<     << node.second << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long int dp[2002][2002];   vector<long long int> col, row;   long long int sol(long int p, long int q, int n, int m, int jk) {     if (p == 0 || q == 0) {       return 0;     }     vector<long long int>::iterator it;     if (p <= 2 * n && q <= 2 * m) {       if (jk == 0) {         return (p * q - dp[p][q]);       }       return dp[p][q];     } else if (p <= 2 * n) {       it = lower_bound(col.begin(), col.end(), q);       if (*it != q) {         it--;       }       long long int ab = *it;       q = q % ab;       ab /= 2;       ab = ab * p;       return ab + sol(p, q, n, m, 1 - jk);     } else {       it = lower_bound(row.begin(), row.end(), p);       if (*it != p) {         it--;       }       long long int ab = *it;       p = p % ab;       ab /= 2;       ab = ab * q;       return ab + sol(p, q, n, m, 1 - jk);     }     return 0;   }   int main() {     int n, m, q;     cin >> n >> m >> q;     int arr[2 * n + 2][2 * m + 2];     for (int x = 1; x <= n; x++) {       string s;       cin >> s;       for (int y = 1; y <= m; y++) {         arr[x][y] = s[y - 1] -  0 ;       }     }     for (int x = 1; x <= 2 * n; x++) {       for (int y = 1; y <= 2 * m; y++) {         if (x <= n && y <= m) {         } else if (x > n && y > m) {           arr[x][y] = arr[x - n][y - m];         } else if (x > n) {           arr[x][y] = 1 - arr[x - n][y];         } else {           arr[x][y] = 1 - arr[x][y - m];         }         dp[x][y] = dp[x][y - 1] + dp[x - 1][y] - dp[x - 1][y - 1] + arr[x][y];       }     }     int sz = 0;     col.push_back(m);     while (col[sz] < INT_MAX) {       col.push_back(col[sz++] * 2);     }     sz = 0;     row.push_back(n);     while (row[sz] < INT_MAX) {       row.push_back(row[sz++] * 2);     }     while (q--) {       int x1, x2, y1, y2;       cin >> x1 >> y1 >> x2 >> y2;       long long int a = sol(x2, y2, n, m, 1);       long long int b = sol(x1 - 1, y2, n, m, 1);       long long int c = sol(x2, y1 - 1, n, m, 1);       long long int d = sol(x1 - 1, y1 - 1, n, m, 1);       cout << a + d - b - c << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   string s;   int n;   int a[26];   int b[26];   bool flag[26];   bool cmp(int x, int y) { return a[x] < a[y]; }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> s >> n;     memset(a, 0, sizeof(a));     memset(flag, 1, sizeof(flag));     for (int i = 0; i < s.size(); ++i) {       a[s[i] -  a ]++;     }     for (int i = 0; i < 26; ++i) {       b[i] = i;     }     int ans = 26;     sort(b, b + 26, cmp);     for (int i = 0; i < 26; ++i) {       if (a[b[i]] <= n) {         flag[b[i]] = 0;         n -= a[b[i]];         ans--;       }     }     cout << ans <<   n ;     for (int i = 0; i < s.size(); ++i) {       if (flag[s[i] -  a ]) cout << s[i];     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long power(long long a, long long n) {     if (a == 0) return 0;     if (a == 1 || n == 0) return 1;     if (n == 1) return a % 1000000007;     long long t = power(a, n / 2);     t = t * t % 1000000007;     if (n & 1) return t * a % 1000000007;     return t;   }   int popcount(long long a) {     int c = 0;     while (a) {       c++;       a -= a & -a;     }     return c;   }   void factorize(int a) {}   void update(int tree[], int idx, int val, int maxval) {     for (; idx <= maxval; idx += idx & -idx) {       tree[idx] += val;     }   }   int read(int tree[], int idx) {     long long sum = 0;     for (; idx > 0; idx -= idx & -idx) {       sum += tree[idx];     }     return sum;   }   struct node2 {     int id, val;     node2() {       static int ctx = 1;       id = ctx++;     };     node2(int a, int b = 0, int c = 0, int d = 0, int e = 0, int f = 0) {       val = a;     }   };   struct comp2 {     bool operator()(int a, int b) { return b < a; }   };   bool cmp2(int a, int b) { return b < a; }   struct node {     int id, val;     node() {       static int ctx = 1;       id = ctx++;     };     node(int a, int b = 0, int c = 0, int d = 0, int e = 0, int f = 0) {       val = a;     }   };   struct comp {     bool operator()(int a, int b) { return b < a; }   };   bool cmp(int a, int b) { return b < a; }   int n, m, a[100009], b, c, d, k, h, w, x, y, p, q, t, res, ma, mi, T,       act = 0, pas = 1, cur, flag, now;   int bit[33][100009];   long long ans, dp[100009][2];   char s[1];   double e, f, z;   vector<int> v[100009], vec;   set<int> sett;   map<int, int> mapp;   void print() {}   void print2() {}   void input() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     for (int i = 1; i < n + 1; i++) cin >> a[i];     for (int i = 1; i < n; i++) {       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);     }   }   void init() {     for (int pos = 0; pos < 30; pos++) {       for (int i = 1; i < n + 1; i++) {         bit[pos][i] = (((1 << pos) & a[i]) != 0);       }     }   }   void calc(int id, int par, int a[]) {     dp[id][a[id]] = 1;     for (auto u : v[id]) {       if (u == par) continue;       calc(u, id, a);       if (a[id]) {         dp[id][1] += dp[u][0];         dp[id][0] += dp[u][1];         ans += T * (dp[id][1] - dp[u][0]) * dp[u][0];         ans += T * (dp[id][0] - dp[u][1]) * dp[u][1];       } else {         dp[id][1] += dp[u][1];         dp[id][0] += dp[u][0];         ans += T * (dp[id][1] - dp[u][1]) * dp[u][0];         ans += T * (dp[id][0] - dp[u][0]) * dp[u][1];       }     }     ans += T * a[id];   }   void solve() {     init();     int l = 0;     int r = 29;     for (int pos = l; pos < r + 1; pos++) {       T = 1 << pos;       memset(dp, 0, sizeof(dp));       calc(1, 0, bit[pos]);     }   }   void output() { cout << ans; }   int main() {     input();     solve();     output();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double pi = 3.14159265358979323846;   long long MOD = 1e9 + 7;   const char nl =   n ;   const long long inf = 1e15;   long long nxt() {     long long x;     cin >> x;     return x;   }   long long mul(long long x, long long y) {     return (1ll * (x % MOD) * (y % MOD));   }   long long modpow(long long x, long long y) {     long long z = 1;     while (y > 0) {       if (y % 2) z = mul(z, x);       x = mul(x, x);       y /= 2;     }     return z;   }   long long power(long long x, long long y) {     long long z = 1;     while (y > 0) {       if (y % 2) z = z * x;       x = x * x;       y /= 2;     }     return z;   }   long long gcd(long long a, long long b) {     if (a < b) return gcd(b, a);     if (b == 0) return a;     return gcd(b, a % b);   }   long long min(long long a, long long b) {     if (a < b) return a;     return b;   }   long long max(long long a, long long b) {     if (a > b) return a;     return b;   }   long long sq(long long a) {     long long ans = (1ll * a * a);     return ans;   }   void solve() {     long long n, k;     cin >> n >> k;     long long t[n];     vector<long long> neg;     for (long long i = 0; i < n; i++) {       cin >> t[i];       if (t[i] < 0) neg.push_back(i);     }     if ((long long)(neg.size()) > k) {       cout << -1 << nl;       return;     }     if ((long long)(neg.size()) == 0) {       cout << 0 << nl;       return;     }     if (n == 1) {       if (t[0] < 0) {         cout << 1 << nl;       } else         cout << 0 << nl;       return;     }     vector<long long> dis;     for (long long i = 0; i < (long long)(neg.size()) - 1; i++) {       if (neg[i + 1] - neg[i] > 1) {         dis.push_back(neg[i + 1] - neg[i] - 1);       }     }     sort(((dis).begin()), ((dis).end()));     long long ans = (long long)(dis.size()) * 2;     ans++;     if (t[n - 1] >= 0) ans++;     long long ewd = k - (long long)(neg.size());     for (long long x : dis) {       if (ewd >= x) ewd -= x, ans -= 2;     }     long long ex = n - 1 - neg.back();     if (ewd >= ex && ex) ans--;     cout << ans <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     long long TC = 1;     while (TC--) {       solve();     }     cerr <<  Time :   << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC          <<  ms n ;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T In() {     T x;     cin >> x;     return x;   }   int main() {     ios::sync_with_stdio(false), cin.tie(0);     cout << ((In<int>() & 1) ?  Ehab  :  Mahmoud );     return cout << endl, 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   bool isprime(int a) {     for (int i = 2; i <= sqrt((double)a); i++) {       if (a % i == 0) return false;     }     return true;   }   int main() {     int n;     cin >> n;     if (n <= 7)       cout << 1 << endl << n;     else {       cout << 3 << endl << 3 <<    ;       n -= 3;       for (int i = 2; i <= n; i++) {         if (isprime(i) && isprime(n - i)) {           cout << i <<     << n - i;           return 0;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     string n1 = to_string(m);     for (int i = 0; i < n1.length() / 2; i++) {       char s = n1[i];       n1[i] = n1[n1.length() - 1 - i];       n1[n1.length() - 1 - i] = s;     }     cout << n + stoi(n1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long l, r;     cin >> l >> r;     long long ans = 0;     for (long long i = 1; i <= r; i *= 2) {       long long cur = i;       while (cur <= r) {         if (cur >= l) ans++;         cur *= 3;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s, h1, m1;   int h[10000], m[10000];   bool a[10000];   int main() {     int n;     cin >> n;     cin.ignore();     for (__typeof(n) i = (1); i <= (n); i++) {       getline(cin, s);       h1 = s.substr(1, 2);       m1 = s.substr(4, 2);       if (s[7] ==  a )         a[i] = true;       else         a[i] = false;       stringstream sh, sm;       sh.flush();       sm.flush();       sh.clear();       sm.clear();       sh << h1;       sm << m1;       sh >> h[i];       sm >> m[i];       h[i] %= 12;       if (!a[i]) h[i] += 12;     }     int ans = 1;     int k = 0;     for (__typeof(n - 1) i = (1); i <= (n - 1); i++) {       int t1 = h[i] * 10000 + m[i];       int t2 = h[i + 1] * 10000 + m[i + 1];       if (t1 == t2)         k++;       else         k = 0;       if (k == 10) {         k = 0;         ans++;         continue;       }       if (!(a[i]) && a[i + 1]) {         ans++;         continue;       }       if (t1 > t2) {         ans++;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   typedef struct {     char name[20];     char phone[200][20];     int len[200];     int avai[200];     int cnt, now;   } friends;   friends frd[20];   int total;   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       char tmp[20];       scanf( %s , tmp);       int pos = -1;       for (int j = 0; j < total; j++) {         if (!strcmp(frd[j].name, tmp)) {           pos = j;           break;         }       }       if (pos == -1) pos = total++;       int num;       scanf( %d , &num);       for (int j = 0; j < num; j++) {         char ph_num[20];         scanf( %s , ph_num);         int l = strlen(ph_num), flag = 0;         for (int k = 0; k < frd[pos].now; k++) {           if (frd[pos].avai[k]) {             if (frd[pos].len[k] >= l) {               if (!strcmp(frd[pos].phone[k] + frd[pos].len[k] - l, ph_num)) {                 flag = 1;                 break;               }             } else {               if (!strcmp(ph_num + l - frd[pos].len[k], frd[pos].phone[k])) {                 frd[pos].avai[k] = 0;                 frd[pos].cnt--;                 break;               }             }           }         }         if (!flag) {           strcpy(frd[pos].name, tmp);           strcpy(frd[pos].phone[frd[pos].now], ph_num);           frd[pos].len[frd[pos].now] = l;           frd[pos].avai[frd[pos].now] = 1;           frd[pos].cnt++;           frd[pos].now++;         }       }     }     printf( %d n , total);     for (int i = 0; i < total; i++) {       printf( %s %d , frd[i].name, frd[i].cnt);       for (int j = 0; j < frd[i].now; j++) {         if (frd[i].avai[j]) printf(  %s , frd[i].phone[j]);       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using std::cin;   using std::cout;   using std::endl;   using std::string;   using std::vector;   int zfn[100010];   int count = 0, nodes_count;   string P, T;   vector<string> str;   vector<vector<int> > connections;   void kmpPreprocess() {     int i = 0, j = -1;     zfn[0] = -1;     while (i < P.size()) {       while (j >= 0 && P[i] != P[j]) j = zfn[j];       i++;       j++;       zfn[i] = j;     }   }   void kmp_DFS(int current, int j) {     string T = str[current];     int i = 0;     while (i < T.size()) {       while (j >= 0 && T[i] != P[j]) j = zfn[j];       i++;       j++;       if (j == P.size()) {         count++;         j = zfn[j];       }     }     for (vector<int>::iterator it = connections.at(current).begin();          it != connections.at(current).end(); ++it) {       kmp_DFS(*it, j);     }   }   int main() {     cin.sync_with_stdio(false);     cin >> nodes_count;     str.resize(nodes_count + 1);     for (int i = 0; i < nodes_count; i++) {       vector<int> v;       connections.push_back(v);     }     int current_parent;     for (int current_node = 0; current_node < nodes_count - 1; current_node++) {       T =   ;       cin >> current_parent >> T;       connections[current_parent - 1].push_back(current_node + 1);       str.at(current_node + 1) = T;     }     cin >> P;     kmpPreprocess();     T =   ;     kmp_DFS(0, 0);     cout << count << endl;     return 0;   }


#include <bits/stdc++.h>   int main() {     int y, k, n;     scanf( %d%d%d , &y, &k, &n);     int x = k - y % k;     int top = n - y;     if (x <= top) {       printf( %d , x);       x += k;       while (x <= top) {         printf(  %d , x);         x += k;       }       printf(  n );     } else {       printf( -1 n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, ans1 = INT_MAX, ans = -198896785;     cin >> n;     int c = 0, d = 0;     for (int i = 0; i < n; i++) {       int a;       cin >> a;       if (a < 0) {         c++;         ans = max(a, ans);       }       if (a > 0) {         d++;         ans1 = min(a, ans1);       }     }     n = (n + 1) / 2;     if (d >= n)       cout << ans1 << endl;     else if (c >= n)       cout << ans << endl;     else       cout << 0 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1010;   const int MOD = 1e9 + 7;   int dp[MAXN][MAXN][2];   int Steps[MAXN];   int add(int a, int b) { return ((a + b) >= MOD ? a + b - MOD : a + b); }   void PreproccessSteps() {     Steps[1] = 1;     for (int i = (2); i < (1010); i++)       Steps[i] = Steps[__builtin_popcount(i)] + 1;   }   int Ones(int N, string s) {     int cnt = 0;     for (int i = (1); i < (N); i++)       if (s[i] ==  1 ) cnt++;     return cnt;   }   void FillDP(int N, string s) {     for (int j = (0); j < (N + 1); j++) dp[0][j][0] = dp[0][j][1] = 1;     for (int i = (1); i < (N + 1); i++)       for (int j = (1); j < (N + 1); j++) {         if (s[j - 1] ==  1 )           dp[i][j][0] = add(dp[i - 1][j - 1][0], dp[i][j - 1][1]);         if (s[j - 1] ==  0 ) dp[i][j][0] = dp[i][j - 1][0];         dp[i][j][1] = add(dp[i - 1][j - 1][1], dp[i][j - 1][1]);       }   }   int main() {     int N, k, sum = 0;     string s;     cin >> s >> k;     reverse(s.begin(), s.end());     PreproccessSteps();     N = (int)s.size();     FillDP(N, s);     for (int i = (1); i < (N + 1); i++)       if (Steps[i] == k) sum = add(sum, dp[i][N][0]);     if (k == 1) {       cout << dp[1][N][0] - 1;       return 0;     }     if (!k) sum++;     cout << sum;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int x, y, n;     cin >> x >> y >> n;     int max = (n / x) * x;     if (max + y > n) {       max = max - x + y;     } else {       max += y;     }     cout << max <<   n ;   }   int main() {     int t;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10;   const long long mod = 1e9 + 7;   void rd(int &x) {     int f = 1;     x = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     x *= f;   }   void pr(int x) { printf( %d n , x); }   int n, a[55][55];   int go[4][2] = {-1, -1, 1, -1, -1, 1, 1, 1};   pair<int, int> g[4];   int main() {     int odd = 1, even = 2;     cin >> n;     if (n == 1) {       puts( 1 );       return 0;     }     if (n == 3) {       printf( 2 1 4 n3 5 7 n6 9 8 n );       return 0;     }     int k = (n + 1) / 2;     int l = k, r = k;     for (int i = (1); i <= k; i++) {       for (int j = (l); j <= r; j++) a[i][j] = odd, odd += 2;       l--, r++;     }     l = k, r = k;     for (int i = n; i >= k + 1; i--) {       for (int j = (l); j <= r; j++) a[i][j] = odd, odd += 2;       l--, r++;     }     for (int i = (1); i <= n; i++) {       for (int j = (1); j <= n; j++) {         if (a[i][j] == 0) a[i][j] = even, even += 2;       }     }     for (int i = (1); i <= n; i++) {       for (int j = (1); j <= n; j++) printf( %d  , a[i][j]);       puts(  );     }   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     int arr[n];     for (int i = 0; i < (n); ++i) cin >> arr[i];     int ans = 1, idx = 1, cnt = 1;     while (idx < n) {       ans = (ans > cnt) ? ans : cnt;       if (arr[idx] <= 2 * arr[idx - 1])         ++cnt;       else         cnt = 1;       ++idx;     }     ans = (ans > cnt) ? ans : cnt;     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,no-stack-protector )   using namespace std;   string s;   const int maxn = (int)1e5 + 1;   const int maxlog = 19;   struct vt {     int w[26];     vector<int> lnk[26];     vector<int> rlnk[26];     string s;     vt() {}     vt(string s) : s(s) {}     int get_cnt(int l, int r) {       int ans = 0;       for (int i = 0; i < 26; i++) {         if (lnk[i][r] >= l || i == s[r] -  a ) {           ans++;         }       }       return ans - 1;     }     vector<long long> sum[1][26];     vector<pair<int, int> > tab[1][26];     void build() {       memset(w, -1, sizeof w);       for (int i = 0; i < 26; i++) {         lnk[i].resize(s.size());         rlnk[i].resize(s.size());         for (int j = 0; j < 1; j++) {           sum[j][i].resize(s.size());           tab[j][i].resize(s.size());         }       }       for (int i = 0; i < (int)s.size(); i++) {         for (int j = 0; j < 26; j++) {           lnk[j][i] = w[j];         }         w[s[i] -  a ] = i;       }       for (int j = 0; j < 26; j++) {         w[j] = (int)s.size() - 1;       }       for (int i = (int)s.size() - 1; i >= 0; i--) {         for (int j = 0; j < 26; j++) {           rlnk[j][i] = w[j];         }         w[s[i] -  a ] = i;       }       for (int i = 0; i < (int)s.size(); i++) {         vector<int> g;         for (int j = 0; j < 26; j++) {           if (j != s[i] -  a ) {             g.push_back(lnk[j][i]);           } else {             g.push_back(i);           }         }         sort(g.rbegin(), g.rend());         int rm = i;         for (int j = 0; j < (int)g.size(); j++) {           if (g[j] == -1) {             tab[0][j][i] = tab[0][j - 1][i];             sum[0][j][i] = sum[0][j - 1][i];             continue;           }           rm = max(rm, rlnk[s[g[j]] -  a ][g[j]]);           int lm = g[j];           int cnt = get_cnt(lm, rm);           tab[0][j][i] = make_pair(cnt, rm);           sum[0][j][i] = rm;         }       }     }     vector<long long> sums[maxlog];     vector<int> tot[maxlog];     vector<int> tabs[maxlog];     void build(int k) {       for (int i = 0; i < maxlog; i++) {         sums[i].assign(s.size(), 0);         tabs[i].assign(s.size(), -1);         tot[i].assign(s.size(), 0);       }       for (int i = 0; i < (int)s.size(); i++) {         if (tab[0][k][i].first == k) {           sums[0][i] = tab[0][k][i].second;           tabs[0][i] = tab[0][k][i].second;           tot[0][i] = 1;         } else {           sums[0][i] = 0;           tabs[0][i] = i;           tot[0][i] = 0;         }       }       for (int it = 1; it < maxlog; it++) {         for (int i = 0; i < (int)s.size(); i++) {           tabs[it][i] = tabs[it - 1][tabs[it - 1][i]];           sums[it][i] = sums[it - 1][i] + sums[it - 1][tabs[it - 1][i]];           tot[it][i] = tot[it - 1][i] + tot[it - 1][tabs[it - 1][i]];         }       }     }   };   long long stup(int pos) {     int lm = pos;     int rm = pos;     int n = (int)s.size();     long long ans = 0;     while (rm - lm + 1 != n) {       ans += n - 1 - (rm - lm);       int mask = 0;       for (int i = lm; i <= rm; i++) {         mask |= (1 << (s[i] -  a ));       }       int l = lm;       while (lm > 0 && mask != 0) {         lm--;         int c = s[lm] -  a ;         if ((mask >> c) & 1) {           mask ^= (1 << c);         }       }       mask = 0;       for (int i = l; i <= rm; i++) {         mask |= (1 << (s[i] -  a ));       }       while (rm < n - 1 && mask != 0) {         rm++;         int c = s[rm] -  a ;         if ((mask >> c) & 1) {           mask ^= (1 << c);         }       }     }     return ans;   }   int main() {     cin >> s;     for (int i = 0; i < (int)1e4; i++) {     }     vt dpr = vt(s);     dpr.build();     reverse(s.begin(), s.end());     vt dpl = vt(s);     dpl.build();     reverse(s.begin(), s.end());     long long ans = 0;     long long pre = 0;     int n = (int)s.size();     vector<pair<int, int> > cur;     for (int i = 0; i < (int)s.size(); i++) {       cur.push_back(make_pair(n - 1 - i, i));       ans += n - 1;     }     for (int j = 0; j < 26; j++) {       dpr.build(j);       dpl.build(j);       for (int i = 0; i < (int)s.size(); i++) {         int lm = cur[i].first;         int rm = cur[i].second;         int cnt = dpr.get_cnt(n - 1 - lm, rm);         if (cnt == j) {           for (int it = maxlog - 1; it >= 0; it--) {             if (dpr.tot[it][rm] == (1 << it) && dpl.tot[it][lm] == (1 << it)) {               ans -= dpr.sums[it][rm];               rm = dpr.tabs[it][rm];               ans -= dpl.sums[it][lm];               ans += 2ll * (n - 1) * (1 << it);               lm = dpl.tabs[it][lm];             }           }           rm = dpr.tab[0][cnt][rm].second;           lm = dpl.tab[0][cnt][lm].second;           ans -= rm + lm;           ans += 2 * (n - 1);           cur[i].first = lm;           cur[i].second = rm;         }       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     long long a = (n * (n + 1) / 2);     cout << (6 * a) + 1;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<bool> primes(n + 1, 1);     primes[0] = primes[1] = 0;     for (int i = 2; i <= n; ++i) {       if (!primes[i]) continue;       for (int j = i * i; j <= n; j += i) primes[j] = 0;     }     vector<int> quest;     for (int i = 2; i <= n; ++i) {       if (!primes[i]) continue;       int k = i;       do {         quest.push_back(k);         k *= i;       } while (k <= n);     }     cout << quest.size() <<   n ;     for (int i = 0; i < quest.size(); ++i) cout << quest[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char mat[110][110];   int main() {     int r, c;     int cnt = 0;     int status = 0;     int i, j;     scanf( %d%d  , &r, &c);     for (i = 0; i < r; i++) {       for (j = 0; j < c; j++) {         scanf( %c , &mat[i][j]);       }       getchar();     }     for (i = 0; i < c; i++) {       if (status == 0 && mat[r - 1][i] ==  B ) {         status = 1;         cnt++;       }       if (mat[r - 1][i] ==  . ) {         status = 0;       }     }     printf( %d n , cnt);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long t, a, b, cnt, p;   long long ak[101], tot;   int main() {     cin >> t >> a >> b;     if (t == a && a == b) {       if (t == 1)         cout <<  inf ;       else         cout <<  2 ;     } else if (a == b)       cout <<  1 ;     else {       if (a == 1) {         cout <<  0 ;         return 0;       }       if (t == 1) {         p = 1;         while (p < b) {           p *= a;           if (p == b) {             cout <<  1 ;             return 0;           }         }       }       memset(ak, 0, sizeof(ak));       tot = 0;       ak[tot] = b;       while (ak[tot] / a) {         ak[tot + 1] = ak[tot] / a;         ak[tot] %= a;         tot++;       }       cnt = 0;       p = 1;       for (int i = 0; i < 70; i++) {         if (ak[i]) cnt = cnt + ak[i] * p;         p *= t;       }       if (cnt == a)         cout <<  1 ;       else         cout <<  0 ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   long long a[200100];   long long t[800800];   long long d[800800];   void build(int v, int tl, int tr) {     if (tl == tr) {       t[v] = a[tl];     } else {       int tm = (tl + tr) / 2;       build(2 * v, tl, tm);       build(2 * v + 1, tm + 1, tr);       t[v] = t[2 * v] + t[2 * v + 1];     }   }   int ind(int v, int tl, int tr, int pos) {     if (tl == tr) {       return v;     } else {       int tm = (tl + tr) / 2;       if (pos <= tm) {         return ind(2 * v, tl, tm, pos);       } else {         return ind(2 * v + 1, tm + 1, tr, pos);       }     }   }   void push(int v, int tl, int tr) {     if (d[v] != 0 && 2 * v + 1 < 800800) {       d[2 * v] += d[v];       d[2 * v + 1] += d[v];       int tm = (tl + tr) / 2;       t[2 * v] += (tm - tl + 1) * d[v];       t[2 * v + 1] += (tr - tm) * d[v];       d[v] = 0;     }   }   long long sum(int v, int tl, int tr, int l, int r) {     if (l <= tl && tr <= r) {       return t[v];     }     if (l > tr || tl > r) {       return 0;     }     int tm = (tl + tr) / 2;     push(v, tl, tr);     return sum(2 * v, tl, tm, l, r) + sum(2 * v + 1, tm + 1, tr, l, r);   }   void update(int v, int tl, int tr, int l, int r, int x) {     if (l <= tl && tr <= r) {       d[v] += x;       t[v] += (tr - tl + 1) * x;       return;     }     if (l > tr || tl > r) {       return;     }     int tm = (tl + tr) / 2;     push(v, tl, tr);     update(2 * v, tl, tm, l, r, x);     update(2 * v + 1, tm + 1, tr, l, r, x);     t[v] = t[2 * v] + t[2 * v + 1];   }   void update_new_val(int v, int tl, int tr, int pos, int new_val) {     if (tl == tr) {       t[v] = new_val;     } else {       int tm = (tl + tr) / 2;       push(v, tl, tr);       if (pos <= tm) {         update_new_val(2 * v, tl, tm, pos, new_val);       } else {         update_new_val(2 * v + 1, tm + 1, tr, pos, new_val);       }       t[v] = t[2 * v] + t[2 * v + 1];     }   }   int main() {     for (int i = 0; i < 200100; i++) {       a[i] = 0;     }     scanf( %d , &n);     long long l = 1;     for (int i = 0; i < 800800; i++) {       d[i] = 0;     }     build(1, 0, 200099);     for (int i = 0; i < n; i++) {       int z;       scanf( %d , &z);       if (z == 1) {         int k;         long long x;         cin >> k >> x;         if (x != 0) {           update(1, 0, 200099, 0, k - 1, x);         }       }       if (z == 2) {         long long new_val;         cin >> new_val;         update_new_val(1, 0, 200099, l, new_val);         l++;       }       if (z == 3) {         update_new_val(1, 0, 200099, l - 1, 0);         l--;       }       long long s = sum(1, 0, 200099, 0, 200099);       double q = l * 1.0;       double sr = (1.0 * s) / q;       printf( %.10f n , sr);     }     return 0;   }


#include <bits/stdc++.h>   const long long N = 100100;   const long long Q = 10100;   const long long mod = 1e9 + 7;   const long long block = sqrt(N);   using namespace std;   int n;   int a[N];   int t[4 * N];   int rl[4 * N];   int lz[4 * N];   void push(int x) {     if (lz[x]) {       t[x * 2] += lz[x];       lz[x * 2] += lz[x];       rl[x * 2] += lz[x];       t[x * 2 + 1] += lz[x];       lz[x * 2 + 1] += lz[x];       rl[x * 2 + 1] += lz[x];       lz[x] = 0;     }   }   void up(int x) {     t[x] = min(t[x * 2], t[x * 2 + 1]);     rl[x] = min(rl[x * 2], rl[x * 2 + 1]);   }   void build(int x, int l, int r) {     if (l == r) {       t[x] = a[l] - l;       rl[x] = a[l];       return;     }     int m = (l + r) / 2;     build(x * 2, l, m);     build(x * 2 + 1, m + 1, r);     up(x);   }   void upd(int x, int l, int r, int tl, int tr, int g) {     if (tl > tr) {       return;     }     if (tl == l && r == tr) {       t[x] += g;       lz[x] += g;       rl[x] += g;       return;     }     push(x);     int m = (l + r) / 2;     upd(x * 2, l, m, tl, min(m, tr), g);     upd(x * 2 + 1, m + 1, r, max(m + 1, tl), tr, g);     up(x);   }   int get(int x, int l, int r) {     if (t[x] >= 0) {       return n + 1;     }     if (l == r) {       return l;     }     push(x);     int m = (l + r) / 2;     if (t[x * 2] < 0) {       return get(x * 2, l, m);     } else {       return get(x * 2 + 1, m + 1, r);     }   }   int get_real(int x, int l, int r, int tl, int tr) {     if (tl > tr) {       return 1e9;     }     if (l == tl && r == tr) {       return rl[x];     }     push(x);     int m = (l + r) / 2;     return min(get_real(x * 2, l, m, tl, min(m, tr)),                get_real(x * 2 + 1, m + 1, r, max(m + 1, tl), tr));   }   void solve() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       a[i] += i - 1;     }     build(1, 1, n);     int ans = 1e9;     for (int i = 1; i <= n; i++) {       int g = get(1, 1, n);       if (g <= n) {         ans = min(ans, max(get_real(1, 1, n, g, n), get_real(1, 1, n, 1, g - 1)));       }       upd(1, 1, n, 1, i, 1);       upd(1, 1, n, i + 1, n, -1);     }     if (ans == 1e9) {       ans = -1;     }     cout << ans <<   n ;   }   bool mtest = false;   int main() {     ios_base::sync_with_stdio(0);     int TE = 1;     if (mtest) cin >> TE;     while (TE--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   int i, j, k, n, m, s, t, ans1, ans2, ans;   int dp[1005][1 << 12];   struct Tree {     int head[1005];     struct edge {       int vet, next;     } E[2005];     int son[1005];     int num[1005];     int a[1005][1005];     int n, tot;     Tree() {       memset(head, -1, sizeof(head));       tot = -1;     }     void add(int u, int v) {       E[++tot] = (edge){v, head[u]};       head[u] = tot;     }     void read() {       scanf( %d , &n);       for (int i = 1; i < n; i++) {         int x, y;         scanf( %d%d , &x, &y);         add(x, y);         add(y, x);       }     }     void dfs(int u, int dad) {       son[u] = 0;       for (int e = head[u]; e != -1; e = E[e].next)         if (e != dad) {           son[u] |= 1 << (E[e].vet - 1);           dfs(E[e].vet, e ^ 1);         }     }     void getsize(int u, int dad) {       num[u] = 0;       for (int e = head[u]; e != -1; e = E[e].next)         if (e != dad) {           a[u][++num[u]] = E[e].vet;           getsize(E[e].vet, e ^ 1);         }     }   } S, T;   int powmod(const int &x, int y) {     if (y == 0) return 1;     int ret = powmod(x, y >> 1);     if (y & 1)       ret = (long long)ret * ret % mod * x % mod;     else       ret = (long long)ret * ret % mod;     return ret;   }   int dfs(int u, int num, int opt) {     if (num == 0) return opt == 0;     int x = S.a[u][num];     if (dp[x][opt] != -1) return dp[x][opt];     dp[x][opt] = dfs(u, num - 1, opt);     for (int i = 0; i < T.n; i++)       if ((1 << i) & opt) {         dp[x][opt] += (long long)dfs(u, num - 1, opt ^ (1 << i)) *                       dfs(x, S.num[x], T.son[i + 1]) % mod;         if (dp[x][opt] >= mod) dp[x][opt] -= mod;       }     return dp[x][opt];   }   int main() {     S.read();     T.read();     S.getsize(1, -1);     for (int j = 1; j <= T.n; j++) {       memset(dp, -1, sizeof(dp));       T.dfs(j, -1);       for (int i = 1; i <= S.n; i++) {         ans1 += dfs(i, S.num[i], T.son[j]);         if (ans1 >= mod) ans1 -= mod;       }     }     S = T;     S.getsize(1, -1);     for (int j = 1; j <= T.n; j++) {       memset(dp, -1, sizeof(dp));       T.dfs(j, -1);       ans2 += dfs(1, S.num[1], T.son[j]);       if (ans2 >= mod) ans2 -= mod;     }     ans = (long long)ans1 * powmod(ans2, mod - 2) % mod;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long no_of_input;     long long input;     cin >> no_of_input;     vector<long long> vect1;     for (long long i = 0; i < no_of_input; i++) {       cin >> input;       vect1.push_back(input);     }     stack<long long> stack1;     vector<long long> l(no_of_input + 1, -1);     vector<long long> r(no_of_input + 1, no_of_input);     vector<long long> ans(no_of_input + 1,                           *min_element(vect1.begin(), vect1.end()));     for (long long i = 0; i < no_of_input; i++) {       while (stack1.size() != 0 && vect1[stack1.top()] >= vect1[i]) {         stack1.pop();       }       if (stack1.size() != 0) {         l[i] = stack1.top();       }       stack1.push(i);     }     while (stack1.size() != 0) {       stack1.pop();     }     for (long long i = vect1.size() - 1; i >= 0; i--) {       while (stack1.size() != 0 && vect1[stack1.top()] >= vect1[i]) {         stack1.pop();       }       if (stack1.size() != 0) {         r[i] = stack1.top();       }       stack1.push(i);     }     for (long long i = 0; i < vect1.size(); i++) {       long long idk = r[i] - l[i] - 1;       ans[idk] = max(ans[idk], vect1[i]);     }     long long temp = ans[ans.size() - 1];     for (long long i = ans.size() - 1; i >= 1; i--) {       temp = max(temp, ans[i]);       ans[i] = max(ans[i], temp);     }     for (long long i = 1; i <= no_of_input; i++) {       cout << ans[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100100;   int n, a[N], b[N], aa[N], bb[N];   long long ans;   void go(int i, int x) {     if (ans == 0) return;     if (x == 1) {       if (a[i + 1] == 9) go(i + 1, -1);       if (ans == 0) return;       cout << i + 1 <<     << 1 <<   n ;       --ans;       ++a[i];       ++a[i + 1];     } else {       if (a[i + 1] == 0) go(i + 1, 1);       if (ans == 0) return;       cout << i + 1 <<     << -1 <<   n ;       --ans;       --a[i];       --a[i + 1];     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     int sum1 = 0, sum2 = 0;     for (int i = 0; i < n; i++) {       char c;       cin >> c;       a[i] = c -  0 ;     }     for (int i = 0; i < n; i++) {       char c;       cin >> c;       b[i] = c -  0 ;       aa[i] = a[i];       bb[i] = b[i];       if (i % 2 == 0) {         sum1 += a[i];         sum2 += b[i];       } else {         sum1 -= a[i];         sum2 -= b[i];       }     }     if (sum1 != sum2) return cout << -1, 0;     ans = 0;     for (int i = 0; i + 1 < n; i++) {       if (aa[i] < bb[i]) {         ans += bb[i] - aa[i];         aa[i + 1] += bb[i] - aa[i];       } else {         ans += aa[i] - bb[i];         aa[i + 1] -= aa[i] - bb[i];       }     }     cout << ans <<   n ;     ans = min(ans, 100000ll);     for (int i = 0; i + 1 < n; i++) {       while (ans > 0 && a[i] < b[i]) {         go(i, 1);       }       while (ans > 0 && a[i] > b[i]) {         go(i, -1);       }     }   }


#include <bits/stdc++.h>   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   bool replace(std::string& str, const std::string& from, const std::string& to) {     size_t start_pos = str.find(from);     if (start_pos == std::string::npos) return false;     str.replace(start_pos, from.length(), to);     return true;   }   inline int c(string& b) {     int w = 0;     for (auto& c : b) w = w * 10 + c -  0 ;     return w;   }   struct segtree {     vector<int> t;     vector<int> a;     int o = 0, iv = -2e9, ee;     int _func(int v, int vv) { return max(v, vv); }     int func(int v1, int v2) { return _func(t[v1], t[v2]); }     void build(vector<int>& v, int y = -2e9) {       int x = 1;       iv = y;       while (x < v.size()) x <<= 1;       x *= 2;       t.resize(x);       ee = x;       o = x >> 1;       while (v.size() < o) v.push_back(y);       for (int i = 0; i < o; i++) t[i + o] = v[i];       for (int i = o - 1; i > 0; i--) t[i] = func(i * 2, i * 2 + 1);       a.resize(x);     }     void push(int v) {       if (a[v]) {         int v1 = v * 2;         int v2 = v * 2 + 1;         t[v] += a[v];         if (v1 < ee) {           if (v1 > o)             t[v1] += a[v];           else             a[v1] += a[v];         }         if (v2 < ee) {           if (v2 > o)             t[v2] += a[v];           else             a[v2] += a[v];         }         a[v] = 0;       }     }     void _add(int v, int l, int r, int vl, int vr, int w) {       if (vl > vr) return;       if (l > vr || r < vl) return;       if (vl == vr && l <= vl && vr <= r) {         t[v] += w;         return;       }       if (l <= vl && vr <= r) {         a[v] += w;         return;       }       push(v);       int m = (vl + vr) >> 1;       _add(v << 1, l, r, vl, m, w);       _add(1 + (v << 1), l, r, m + 1, vr, w);       if (vl != vr)         t[v] = _func(t[v << 1] + a[v << 1], t[v * 2 + 1] + a[v * 2 + 1]);     }     void add(int l, int r, int v) { _add(1, l, r, 0, o - 1, v); }     int q(int v, int l, int r, int vl, int vr) {       if (vl > vr) return iv;       if (l > vr || r < vl) return iv;       push(v);       if (vl != vr)         t[v] = _func(t[v * 2] + a[v * 2], t[v * 2 + 1] + a[v * 2 + 1]);       if (l <= vl && vr <= r) return a[v] + t[v];       int m = (vl + vr) / 2;       return _func(q(v * 2, l, r, vl, m), q(v * 2 + 1, l, r, m + 1, vr));     }     int query(int l, int r) { return q(1, l, r, 0, o - 1); }   };   int32_t main(int32_t argc, char** argv) {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m, p;     cin >> n >> m >> p;     vector<pair<int, int>> a(n), b(m);     vector<pair<int, pair<int, int>>> y(p);     for (auto& e : a) cin >> e.first >> e.second;     for (auto& e : b) cin >> e.first >> e.second;     for (auto& e : y) cin >> e.first >> e.second.first >> e.second.second;     sort(a.begin(), a.end());     sort(b.begin(), b.end());     sort(y.begin(), y.end());     vector<int> s(m);     for (int i = 0; i < m; i++) s[i] = -b[i].second;     int i1 = 0;     segtree t;     t.build(s, -2e9);     int r = -2e9;     for (int i = 0; i < n; i++) {       while (i1 < y.size() && y[i1].first < a[i].first) {         pair<int, int> a = {y[i1].second.first + 1, -2e9};         auto e = upper_bound(b.begin(), b.end(), a);         int mx = (e - b.begin());         if (mx < m) {           t.add(mx, m - 1, y[i1].second.second);         }         i1++;       }       r = max(r, t.query(0, m - 1) - a[i].second);     }     cout << r;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   const double EXP = 2.7182818284590452;   const double Pi = 3.14159265;   const double EPS = 1e-13;   const int INF = 1000 * 1000 * 1000;   const long long INFL = (long long)INF * (long long)INF;   long long n;   long long res;   void accept() {     cin >> n;     for (long long i = 1, j = 1; i <= INF; i *= 10, ++j) {       res += ((0 < (((n - i + 1) < 9L * i) ? ((n - i + 1)) : (9L * i)))                   ? ((((n - i + 1) < 9L * i) ? ((n - i + 1)) : (9L * i)))                   : (0)) *              j;     }     cout << res;   }   int main(void) {     accept();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int M = 1e9 + 7;   int incr(string &s) {     int i, n = s.length();     for (i = n - 1; i >= 0; --i) {       if (s[i] !=  9 ) {         s[i]++;         return 0;       }       s[i] =  0 ;     }     for (i = n - 1; i >= 0; --i) {       s[i] =  0 ;     }     s =  1  + s;     return 0;   }   int incr2(string &s, int t) {     while (t > 0) {       for (int i = s.length() - 1; i >= 0; --i) {         if (s[i] !=  9 ) {           s[i]++;           --t;           if (s[i] ==  5 ) {             if (i == 0) {               return 1;             }             s.pop_back();             break;           } else {             return 0;           }         } else {           s[i] =  0 ;           s.pop_back();           if (i == 0) {             return 1;           }         }       }     }     for (int i = s.length() - 1; i >= 0; --i) {       if (s[i] !=  9 ) {         s[i]++;         return 0;       }     }   }   int main() {     int i, n, t;     cin >> n >> t;     string s;     cin >> s;     int di = s.find( . );     string dpart = s.substr(0, di);     s = s.substr(di + 1, n - di - 1);     if (s[0] >=  5 ) {       incr(dpart);       cout << dpart;       return 0;     }     for (i = 0; i < s.length(); i++) {       if (s[i] >=  5 ) {         break;       }     }     if (i == s.length()) {       cout << dpart <<  .  << s;       return 0;     }     s = s.substr(0, i);     int c4 = 0;     for (i = s.length() - 1; i >= 0; --i) {       if (s[i] ==  4 ) {         c4++;       } else {         break;       }     }     if (c4 == 0) {       incr2(s, 0);       cout << dpart <<  .  << s;       return 0;     }     if (c4 == s.length() && t > c4) {       incr(dpart);       cout << dpart;       return (0);     }     cout << dpart <<  . ;     if (t <= c4) {       cout << s.substr(0, s.length() - t) <<  5 ;       return 0;     }     s[s.length() - c4 - 1]++;     cout << s.substr(0, s.length() - c4);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int i, ans, f;   long long n, l, r, mid, x;   long long check(long long mid) {     if ((mid - 1) / 2 > n / mid) return n + 1;     return mid * ((1ll << i) - 1) + mid * (mid - 1) / 2;   }   int main() {     scanf( %I64d , &n);     x = (int)(sqrt(n * 2) + 1e-11);     if (x * (x + 1) == n * 2 && (x + 1) & 1) printf( %I64d n , x + 1), f = 1;     for (i = 1; (1ll << i) - 1 <= n; ++i) {       l = 1;       r = n / ((1ll << i) - 1);       while (l <= r) {         mid = (l + r) / 2;         if (check(mid) <= n)           l = mid + 1;         else           r = mid - 1;       }       if ((l - 1) & 1 && check(l - 1) == n)         printf( %I64d n , (l - 1) * 1 << i), f = 1;     }     if (!f) printf( -1 n );   }


#include <bits/stdc++.h>   using namespace std;   long long int pwr(long long int a, long long int n, long long int m) {     long long int p = 1;     while (n > 0) {       if (n % 2 == 1) p = (p * a) % m;       a = (a * a) % m;       n = n / 2;     }     return p;   }   char str[1000000];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int n, a, b, k, s = 0, i, j;     cin >> n >> a >> b >> k;     long long int f = pwr(b, k, (long long int)(1e9 + 9));     long long int g = pwr(a, k, (long long int)(1e9 + 9));     long long int r =         (f * pwr(g, (long long int)(1e9 + 9) - 2, (long long int)(1e9 + 9))) %         (long long int)(1e9 + 9);     r = ((pwr(r, (n + 1) / k, (long long int)(1e9 + 9)) - 1 +           (long long int)(1e9 + 9)) %          (long long int)(1e9 + 9) *          pwr(r - 1, (long long int)(1e9 + 9) - 2, (long long int)(1e9 + 9))) %         (long long int)(1e9 + 9);     if (r == 0) r = (n + 1) / k;     cin >> str;     for (i = 0; i < k; i++) {       if (str[i] ==  + )         s = (s +              (pwr(a, n - i, (long long int)(1e9 + 9)) *               pwr(b, i, (long long int)(1e9 + 9))) %                  (long long int)(1e9 + 9) +              (long long int)(1e9 + 9)) %             (long long int)(1e9 + 9);       else         s = (s -              (pwr(a, n - i, (long long int)(1e9 + 9)) *               pwr(b, i, (long long int)(1e9 + 9))) %                  (long long int)(1e9 + 9) +              (long long int)(1e9 + 9)) %             (long long int)(1e9 + 9);     }     cout << ((s * r) % (long long int)(1e9 + 9) + (long long int)(1e9 + 9)) %                 (long long int)(1e9 + 9)          << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000;   int main(int argc, char *argv[]) {     string s;     vector<pair<char, int> > count;     int n;     cin >> s;     n = s.size();     for (int i = 0; i < n;) {       int cnt = 0;       int prev = s[i];       while (s[i] == prev) {         cnt++;         i++;       }       count.push_back(make_pair(prev, cnt));     }     for (int i = 0; i < count.size(); i++) {       if (count[i].second >= 3) count[i].second = 2;     }     for (int i = 0; i < count.size() - 1; i++) {       if (count[i].second == 2 && count[i + 1].second == 2)         count[i + 1].second = 1;     }     for (int i = 0; i < count.size(); i++) {       for (int j = 0; j < count[i].second; j++) cout << count[i].first;     }   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     long long n, a, b, p, q;     cin >> n >> a >> b >> p >> q;     long long someGcd = gcd(a, b);     long long lcm = a * b / someGcd;     long long max = (p > q) ? p : q;     if (p > q) {       long long counta = p * (n / a);       long long countb = q * (n / b) - q * (n / lcm);       cout << counta + countb;     } else {       long long counta = p * (n / a) - p * (n / lcm);       long long countb = q * (n / b);       cout << counta + countb;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string second;     cin >> second;     bool check = 0;     string tmp(1, second[0]);     for (int i = 1; i < second.size(); i++) {       if (second[i] ==  d  && second[i + 1] ==  o  && second[i + 2] ==  t  &&           i < second.size() - 3)         tmp +=  . , i += 2;       else if (second[i] ==  a  && second[i + 1] ==  t  && !check &&                i < second.size() - 2)         tmp +=  @ , check = 1, i++;       else         tmp += second[i];     }     cout << tmp << endl;   }


#include <bits/stdc++.h>   using namespace std;   int k;   long long ans[10009];   bool chk(long long n) {     int m = 0;     while (n) {       m += (n % 10);       n /= 10;       if (m > 10) return 0;     }     return (m == 10);   }   int main() {     cin >> k;     ans[0] = 19;     for (int i = 1; i <= 10000; i++) {       ans[i] = ans[i - 1] + 9;       while (!chk(ans[i])) ans[i] += 9;     }     cout << ans[k - 1];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   void solve() {     long long n = s.length(), i, j, k;     long long piv = 0;     for (i = 0; i < n; i++)       if (s[i] ==  ^ ) {         piv = i;         break;       }     long long l = piv;     long long r = n - piv - 1;     long long c1 = 0, c2 = 0;     for (i = 0; i < l; i++) {       if (s[i] ==  = ) continue;       j = (piv - i) * (s[i] -  0 );       c1 += j;     }     for (i = piv + 1; i < n; i++) {       if (s[i] ==  = ) continue;       j = (i - piv) * (s[i] -  0 );       c2 += j;     }     if (c1 == c2) cout <<  balance n ;     if (c1 > c2) cout <<  left n ;     if (c1 < c2) cout <<  right n ;   }   int main(int argc, char const *argv[]) {     cin >> s;     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200;   int h[maxn];   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   int main() {     long long n, m, sx, sy, ex, ey;     int q;     scanf( %lld%lld%d , &n, &m, &q);     long long gc = gcd(n, m);     long long stp1 = n / gc, stp2 = m / gc;     long long num1, num2;     while (q--) {       scanf( %lld%lld%lld%lld , &sx, &sy, &ex, &ey);       num1 = num2 = 0;       if (sx == 1) {         num1 = sy / stp1;         if (sy % stp1 != 0) num1++;       } else {         num1 = sy / stp2;         if (sy % stp2 != 0) num1++;       }       if (ex == 1) {         num2 = ey / stp1;         if (ey % stp1 != 0) num2++;       } else {         num2 = ey / stp2;         if (ey % stp2 != 0) num2++;       }       if (num1 == num2)         printf( YES n );       else         printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int k[10] = {2, 7, 2, 3, 3, 4, 2, 5, 1, 2};   int main(void) {     int n;     scanf( %d , &n);     int x = n / 10, y = n % 10;     printf( %d n , k[x] * k[y]);   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void printContainer(T& a, int n = -1) {     if (n == -1) n = a.size();     cout <<  { ;     int i = 0;     for (auto it : a) {       cout << (it) <<  ,  ;       if (++i == n) break;     }     cout <<  } n ;   }   int main() {     string s[2];     cin >> s[0] >> s[1];     int typ[2];     int score = 0;     int c = 0;     for (int p = 0; p < s[0].size(); p += 2) {       for (int i = 0; i < (int)(2); ++i) {         int r = 2;         if (s[i][p] ==  [ )           r = 0;         else if (s[i][p] ==  ( )           r = 1;         typ[i] = r;       }       if (typ[0] == typ[1]) continue;       for (int i = 0; i < (int)(3); ++i)         if (((typ[0] + 1) % 3) == typ[1]) {           ++score;           goto final;         }       --score;     final:       ++c;     }     if (score == 0) {       cout <<  TIE  << endl;     } else {       cout << (score > 0 ?  TEAM 1 WINS  :  TEAM 2 WINS ) << endl;       ;     }   }


#include <bits/stdc++.h>   using namespace std;   const double PI = 2 * acos(0.0);   const double eps = 1e-9;   double toRad(int angle) { return PI * angle / 180.0; }   int a, w, h;   double angle;   complex<double> intersect(complex<double> p1, complex<double> p2,                             complex<double> p3, complex<double> p4) {     complex<double> ret;     double u = (p4.real() - p3.real()) * (p1.imag() - p3.imag()) -                (p4.imag() - p3.imag()) * (p1.real() - p3.real());     u /= (p4.imag() - p3.imag()) * (p2.real() - p1.real()) -          (p4.real() - p3.real()) * (p2.imag() - p1.imag());     return complex<double>(p1.real() + u * (p2.real() - p1.real()),                            p1.imag() + u * (p2.imag() - p1.imag()));   }   complex<double> rotate(complex<double> p, double angle) {     return complex<double>(p.real() * cos(angle) - p.imag() * sin(angle),                            p.real() * sin(angle) + p.imag() * cos(angle));   }   double dist(complex<double> a, complex<double> b) {     return (hypot((a - b).real(), (a - b).imag()));   }   int main() {     cin >> w >> h >> a;     long double ans = 0;     if (a > 90) a = 180 - a;     if (a == 0)       ans = 1.0 * w * h;     else if (a == 90)       ans = min(w, h) * min(w, h);     else {       angle = toRad(a);       if (w < h) swap(w, h);       complex<double> A(-0.5 * w, 0.5 * h);       complex<double> B(0.5 * w, 0.5 * h);       complex<double> C(0.5 * w, -0.5 * h);       complex<double> D(-0.5 * w, -0.5 * h);       complex<double> E = rotate(A, angle), F = rotate(B, angle),                       G = rotate(C, angle), H = rotate(D, angle);       complex<double> N = intersect(A, B, E, F);       complex<double> M = intersect(A, D, E, F);       complex<double> O = intersect(A, B, F, G);       complex<double> P = intersect(B, C, F, G);       ans = 1.0 * w * h;       if (G.imag() < B.imag()) {         long double area = dist(A, M) * dist(A, N) + dist(B, O) * dist(B, P);         ans -= area;       } else {         N = intersect(A, B, H, G);         M = intersect(C, D, H, G);         complex<double> K(N.real(), M.imag());         ans -= 2.0 * h * dist(C, K);         ans -= dist(K, M) * dist(N, K);       }     }     cout << fixed << setprecision(10) << ans << endl;     return 0;   }