#include <bits/stdc++.h>   using namespace std;   inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }   const int INF = 1 << 29;   inline int two(int n) { return 1 << n; }   inline int test(int n, int b) { return (n >> b) & 1; }   inline void set_bit(int& n, int b) { n |= two(b); }   inline void unset_bit(int& n, int b) { n &= ~two(b); }   inline int last_bit(int n) { return n & (-n); }   inline int ones(int n) {     int res = 0;     while (n && ++res) n -= n & (-n);     return res;   }   template <class T>   void chmax(T& a, const T& b) {     a = max(a, b);   }   template <class T>   void chmin(T& a, const T& b) {     a = min(a, b);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, m, k, cnt = 0;     cin >> n >> m >> k;     vector<char> V;     for (int i = 0; i < n - 1; i++) {       ++cnt;       V.push_back( U );     }     for (int i = 0; i < m - 1; i++) {       ++cnt;       V.push_back( L );     }     int flag = 1;     for (int i = 0; i < m - 1; i++) V.push_back( R ), ++cnt;     for (int i = 0; i < n - 1; i++) {       ++cnt;       V.push_back( D );       if (flag == 1) {         for (int i = 0; i < m - 1; i++) V.push_back( L ), ++cnt;       } else {         for (int i = 0; i < m - 1; i++) V.push_back( R ), ++cnt;       }       flag *= -1;     }     cout << cnt;     cout << endl;     for (auto u : V) cout << u;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   int n, m, len[maxn << 2];   bool first[maxn << 2];   long long mm[maxn], rr[maxn], ss[maxn], last[maxn << 2];   vector<long long> summ[maxn << 2], sumr[maxn << 2];   vector<int> tree[maxn << 2];   bool cmp(int a, int b) { return mm[a] * rr[b] < mm[b] * rr[a]; }   void build(int cur, int l, int r) {     len[cur] = 0;     first[cur] = true, last[cur] = -1;     tree[cur].clear();     tree[cur].push_back(0);     for (int i = l; i <= r; i++)       if (mm[i] != 0 && rr[i] != 0) tree[cur].push_back(i), len[cur]++;     sort(tree[cur].begin() + 1, tree[cur].end(), cmp);     summ[cur].clear();     sumr[cur].clear();     summ[cur].push_back(0);     sumr[cur].push_back(0);     long long sr = 0, sm = 0;     for (int i = 1; i <= len[cur]; i++) {       sr += rr[tree[cur][i]];       sm += mm[tree[cur][i]];       sumr[cur].push_back(sr);       summ[cur].push_back(sm);     }     if (l != r) {       build((cur << 1), l, ((l + r) >> 1));       build((cur << 1 | 1), ((l + r) >> 1) + 1, r);     }   }   int find(int cur, long long t) {     int l = 1, r = len[cur];     while (l <= r) {       if (t * rr[tree[cur][((l + r) >> 1)]] >= mm[tree[cur][((l + r) >> 1)]])         l = ((l + r) >> 1) + 1;       else         r = ((l + r) >> 1) - 1;     }     return l - 1;   }   long long ask(int cur, int l, int r, long long t) {     if (l == r && first[cur]) {       long long ret = min(mm[l], t * rr[l] + ss[l]);       ss[l] = 0, first[cur] = false;       return ret;     }     if (last[cur] != -1) {       long long delta = t - last[cur];       int mid = find(cur, delta);       long long ret = 0;       ret += summ[cur][mid];       ret += (sumr[cur][len[cur]] - sumr[cur][mid]) * delta;       return ret;     }     long long ret = 0;     ret += ask((cur << 1), l, ((l + r) >> 1), t);     ret += ask((cur << 1 | 1), ((l + r) >> 1) + 1, r, t);     return ret;   }   void down(int cur) {     if (last[cur] != -1) {       first[(cur << 1)] = first[(cur << 1 | 1)] = false;       last[(cur << 1)] = last[(cur << 1 | 1)] = last[cur];       last[cur] = -1;     }   }   long long query(int cur, int l, int r, int ql, int qr, long long t) {     if (ql <= l && r <= qr) {       long long ret = ask(cur, l, r, t);       first[cur] = false, last[cur] = t;       return ret;     }     down(cur);     long long ret = 0;     if (ql <= ((l + r) >> 1))       ret += query((cur << 1), l, ((l + r) >> 1), ql, qr, t);     if (qr > ((l + r) >> 1))       ret += query((cur << 1 | 1), ((l + r) >> 1) + 1, r, ql, qr, t);     return ret;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %I64d%I64d%I64d , &ss[i], &mm[i], &rr[i]);     build(1, 1, n);     scanf( %d , &m);     int qq = 0;     while (m--) {       ++qq;       int t, l, r;       scanf( %d%d%d , &t, &l, &r);       printf( %I64d n , query(1, 1, n, l, r, t));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e6;   const long long INF = 1e18;   const long long mod = 1e9 + 7;   long long y;   long long n, m;   vector<long long> v;   void rec(long long x) {     if (x > m) {       return;     }     if (x == m) {       cout <<  YES  << endl;       y = 1;     }     rec(x * 2);     rec(x * 10 + 1);     if (y) {       v.push_back(x);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> m;     rec(n);     if (!y) {       cout <<  NO ;       return 0;     }     sort(v.begin(), v.end());     reverse(v.begin(), v.end());     for (int i = 0; i < v.size() - 1; i++) {       if (v[i] / 2 == v[i + 1] || v[i] / 10 == v[i + 1]) {         continue;       }       v.erase(v.begin() + i + 1);       i--;     }     cout << v.size() << endl;     for (int i = v.size() - 1; i >= 0; i--) {       cout << v[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   vector<int> a;   vector<pair<pair<int, int>, int> > b;   vector<int> k;   vector<int> ans;   signed main() {     ios_base::sync_with_stdio(0);     int n, m;     cin >> n;     a.resize(n);     b.resize(n);     ans.resize(n);     for (int i = 0; i < n; i++) {       cin >> b[i].first.first >> b[i].second;     }     cin >> m;     b.resize(n + m);     k.resize(m);     for (int i = 0; i < n; i++) {       b[i].first.second = i + m;     }     for (int i = n; i < m + n; i++) {       cin >> b[i].first.first >> b[i].second >> k[i - n];       b[i].first.second = i - n;     }     sort(b.begin(), b.end());     set<pair<int, int> > d;     bool poss = true;     for (int i = 0; i < n + m; i++) {       if (b[i].first.second < m)         d.insert(make_pair(b[i].second, b[i].first.second));       else {         set<pair<int, int> >::iterator it =             d.upper_bound(make_pair(b[i].second - 1, m));         if (it == d.end()) {           poss = false;           continue;         }         k[it->second]--;         ans[b[i].first.second - m] = it->second + 1;         if (k[it->second] == 0) d.erase(it);       }     }     if (poss) {       cout <<  YES  << endl;       for (int i = 0; i < n; i++) {         cout << ans[i] <<    ;       }       cout << endl;     } else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[100010], cnt[100010];   int main() {     int max1 = 0, max2 = 0;     cin >> n;     ;     for (int i = 1; i <= n; i++) {       cin >> a[i];       ;     }     for (int i = 1; i <= n; i++) {       if (a[i] > max1) {         max2 = max1;         max1 = a[i];         cnt[a[i]]--;       } else {         if (a[i] > max2) {           cnt[max1]++;           max2 = a[i];         }       }     }     int ans, max3 = -100000;     for (int i = 1; i <= n; i++) {       if (cnt[i] > max3) {         max3 = cnt[i];         ans = i;       }     }     cout << ans;     ;   }


#include <bits/stdc++.h>   using namespace std;   class Solution {    public:     Solution(int _n) : N(_n) {}     void guess(long long n, int k) {       long long l = 1;       long long r = n;       int M = min(4LL * k, n);       mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());       string ans;       for (int i = 0; i < N; ++i) {         if (r - l + 1 <= M) {           uniform_int_distribution<long long> dist(l, r);           long long p = dist(gen);           cout << p <<     << p << endl;           fflush(stdout);           cin >> ans;           if (ans[0] ==  y  || ans[0] ==  Y ) {             return;           }         } else {           long long m = l + (r - l) / 2;           cout << l <<     << m << endl;           fflush(stdout);           cin >> ans;           if (ans[0] ==  y  || ans[0] ==  Y ) {             r = m;           } else {             l = m + 1;           }         }         l = max(1LL, l - k);         r = min(n, r + k);       }     }       private:     int N;   };   int main(int argc, char** argv) {     ios::sync_with_stdio(false);     cin.tie(0);     long long n;     int k;     long long p;     cin >> n >> k;     Solution sol(4500);     sol.guess(n, k);     return 0;   }


#include <bits/stdc++.h>   int main() {     char ch[116];     int i, j = 1, k, m, n, c, s, e;     scanf( %d %d  , &n, &m);     while (j <= n) {       scanf( %s , ch);       for (i = 0; ch[i] !=   0 ; i++) {         if (ch[i] ==  B ) {           s = i;           while (ch[++i] ==  B )             ;           e = i - 1;           c = (e - s + 1) / 2;           printf( %d %d , j + c, s + 1 + c);           return 0;         }       }       j++;     }   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<pair<int, int>, int> > v, ans;   vector<pair<int, int> > an;   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int val, state;       cin >> val >> state;       v.push_back(make_pair(make_pair(val, !state), i));     }     sort(v.begin(), v.end());     int cur = 2;     for (int i = 0; i < m; i++) {       if (!v[i].first.second) {         if (cur > n) {           cout << -1;           return 0;         }         ans.push_back(make_pair(make_pair(cur, 1), v[i].second));         for (int j = 2; j < cur; j++) {           if (an.size() < m) {             an.push_back(make_pair(cur, j));           } else {             break;           }         }         cur++;       } else {         if (an.size() == 0) {           cout << -1;           return 0;         } else {           ans.push_back(make_pair(an[an.size() - 1], v[i].second));           an.pop_back();         }       }     }     int k = ans.size();     vector<pair<int, int> > out(k, make_pair(0, 0));     for (int i = 0; i < k; i++) {       out[ans[i].second] = ans[i].first;     }     for (int i = 0; i < k; i++) {       cout << out[i].first <<     << out[i].second << endl;     }     return 0;   }


#include <bits/stdc++.h>   int modul(long long x, long long y) {     if (x < y)       return y - x;     else       return x - y;   }   long long rez, n, i, ant, x;   int main() {     scanf( %I64d , &n);     ant = 0;     for (i = 1; i <= n; i++) {       scanf( %I64d , &x);       rez += modul(x, ant);       ant = x;     }     printf( %I64d , rez);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     cin.ignore();     vector<vector<string> > templa(n);     for (int c = 0; c < n; c++) {       string s;       getline(cin, s);       for (int c2 = 0; c2 < s.size(); c2++)         if ((s[c2] >=  a  && s[c2] <=  z ) || (s[c2] >=  A  && s[c2] <=  Z ) ||             (s[c2] >=  0  && s[c2] <=  9 ))           continue;         else           s[c2] =    ;       stringstream ss(s);       bool first = true;       while (!ss.eof()) {         string z;         ss >> z;         if (z.size() > 0 && !first) {           templa[c].push_back(z);         }         first = false;       }     }     int m;     cin >> m;     vector<pair<string, string> > var(m);     for (int c = 0; c < m; c++) cin >> var[c].first >> var[c].second;     int k;     cin >> k;     cin.ignore();     vector<vector<string> > appel(k);     for (int c = 0; c < k; c++) {       string s;       getline(cin, s);       for (int c2 = 0; c2 < s.size(); c2++)         if ((s[c2] >=  a  && s[c2] <=  z ) || (s[c2] >=  A  && s[c2] <=  Z ) ||             (s[c2] >=  0  && s[c2] <=  9 ))           continue;         else           s[c2] =    ;       stringstream ss(s);       while (!ss.eof()) {         string z;         ss >> z;         if (z.size() > 0) {           appel[c].push_back(z);         }       }       int res = 0;       for (int c2 = 0; c2 < templa.size(); c2++) {         if (templa[c2][0] != appel[c][0] || templa[c2].size() != appel[c].size())           continue;         for (int c3 = 1; c3 < templa[c2].size(); c3++) {           if (templa[c2][c3] ==  T ) continue;           for (int c4 = 0; c4 < var.size(); c4++) {             if (appel[c][c3] == var[c4].second) {               if (templa[c2][c3] != var[c4].first) goto end;             }           }         }         res++;       end:;       }       cout << res << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int s = (int)1e5 + 10;   int a[s], p[s];   int main() {     int x, y;     int s = 0;     int i = 0, j = 0;     cin >> x >> y;     while (i != x || j != y) {       if (i == 0 && j == 0) {         i = 1;         j = 0;         continue;       }       if (i >= 0 && j <= 0) {         if (i == 1 - j) {           s++;         }       } else if (abs(i) == abs(j)) {         s++;       }       if (abs(j) < abs(i)) {         if (i > 0)           j++;         else           j--;       } else if (abs(j) > abs(i)) {         if (j < 0)           i++;         else           i--;       } else if (abs(i) == abs(j)) {         if (i > 0 && j > 0)           i--;         else if (i < 0 && j > 0)           j--;         else if (i < 0 && j < 0)           i++;         else if (i > 0 && j < 0)           i++;       }     }     cout << s << endl;     return 0;   }


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


#include <bits/stdc++.h>   #pragma GCC optimize(2)   #pragma GCC optimize(3)   #pragma GCC optimize( Ofast )   #pragma GCC optimize( inline )   using std::pair;   using std::set;   using std::vector;   template <class T>   inline void read(T &x) {     T f = 1;     x = 0;     char s = getchar();     while (s <  0  || s >  9 ) {       if (s ==  - ) f = -1;       s = getchar();     }     while (s >=  0  && s <=  9 ) {       x = (x << 1) + (x << 3) + (s & 15);       s = getchar();     }     x *= f;   }   template <class T>   inline T fabs(T a) {     return a > 0 ? a : -a;   }   template <class T>   inline T max(T a, T b) {     return a > b ? a : b;   }   template <class T>   inline T min(T a, T b) {     return a < b ? a : b;   }   template <class T>   inline T po(T a) {     return a * a;   }   const long long maxn = 1e6 + 5;   struct Edge {     long long u, v, w;   } e[maxn];   inline bool cmp(Edge a, Edge b) { return a.w > b.w; }   long long fa[maxn], m, n, cnt, fx, fy, ans, siz[maxn], MAX, val[maxn];   inline long long find(long long x) {     return (fa[x] == x) ? x : fa[x] = find(fa[x]);   }   signed main() {     read(n);     read(m);     for (long long i = 1; i <= n; i++) fa[i] = i, siz[i] = 1, read(val[i]);     for (long long i = 1; i <= m; i++)       read(e[i].u), read(e[i].v), e[i].w = min(val[e[i].u], val[e[i].v]);     std::sort(e + 1, e + m + 1, cmp);     for (long long i = 1; i <= m; i++) {       fx = find(e[i].u);       fy = find(e[i].v);       if (fx == fy) continue;       ans += siz[fx] * siz[fy] * e[i].w;       fa[fx] = fy;       siz[fy] += siz[fx];       cnt++;       if (cnt == (n - 1)) break;     }     MAX = ((n * (n - 1)) >> 1);     printf( %.6Lf , ((long double)(ans)) / ((long double)(MAX)));   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n, p, x;     cin >> t;     for (int u = 0; u < t; u++) {       cin >> n >> p;       x = 2 * n + p;       for (int i = 0; i < n; i++) {         for (int j = i + 1; j < n; j++) {           cout << i + 1 <<     << j + 1 <<   n ;           x--;           if (x == 0) {             break;           }         }         if (x == 0) {           break;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, c = getchar(), f = 0;     for (; c >  9  || c <  0 ; f = c ==  - , c = getchar())       ;     for (; c >=  0  && c <=  9 ; c = getchar()) x = (x << 1) + (x << 3) + c -  0 ;     return f ? -x : x;   }   const int maxn = 2e5 + 10;   const int inf = 0x3f3f3f3f;   int a[maxn];   int n, k;   map<int, int> vis;   int main() {     n = read();     k = 0;     for (int i = 1; i <= n; i++) {       int x = read();       if (vis[x] == 0) vis[x] = ++k;       a[vis[x]]++;     }     sort(a + 1, a + k + 1);     int ans = 0;     for (int i = 1; i <= n; i++) {       int x = i, temp = 0, y = 0;       while (true) {         int id = lower_bound(a + y + 1, a + k + 1, x) - a;         if (id == k + 1) break;         temp += x;         x *= 2;         y = id;       }       ans = max(ans, temp);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /stack:256000000 )   using namespace std;   const int INF = 1000000000;   const long long LINF = 4000000000000000000LL;   const double eps = 1e-9;   void prepare() {}   struct Chat {     string name, text;     unsigned int hname;     set<unsigned int> words;     vector<int> possibles;   };   int n, m;   vector<Chat> chats;   vector<string> names;   vector<int> res;   vector<unsigned int> hnames;   int p[100500];   unsigned int getHash(string s) {     unsigned int h = 0;     for (int i = (0); i < (((int)(s).size())); i++) h = h * 3137 + s[i];     return h;   }   Chat readChat() {     Chat chat;     string s;     getline(cin, s);     int ix = s.find( : );     chat.name = s.substr(0, ix);     chat.hname = getHash(chat.name);     chat.text = s.substr(ix + 1);     s = chat.text;     for (int i = (0); i < (((int)(s).size())); i++) {       if (!isalnum(s[i])) s[i] =    ;     }     stringstream ss(s);     while (ss >> s) {       chat.words.insert(getHash(s));     }     return chat;   }   void read() {     names.clear();     hnames.clear();     chats.clear();     string s;     scanf( %d , &n);     getline(cin, s);     getline(cin, s);     stringstream ss(s);     while (ss >> s) {       names.push_back(s);       hnames.push_back(getHash(s));     }     scanf( %d , &m);     getline(cin, s);     for (int i = (0); i < ((m)); i++) {       chats.push_back(readChat());     }   }   bool rec(int cc) {     if (cc >= m) return true;     int id = p[cc];     for (int i = (0); i < (((int)(chats[id].possibles).size())); i++) {       int prid = chats[id].possibles[i];       unsigned int pr = hnames[prid];       if ((id == 0 || chats[id - 1].hname != pr) &&           (id + 1 >= m || chats[id + 1].hname != pr)) {         unsigned int ph = chats[id].hname;         chats[id].hname = pr;         res[id] = prid;         if (rec(cc + 1)) return true;         chats[id].hname = ph;       }     }     return false;   }   bool cmp(const int &a, const int &b) {     return chats[a].possibles.size() < chats[b].possibles.size();   }   bool solve() {     res.clear();     res.resize(m);     for (int i = (0); i < ((m)); i++) {       if (chats[i].name !=  ? ) {         int id =             find((names).begin(), (names).end(), chats[i].name) - names.begin();         chats[i].possibles.push_back(id);         continue;       }       for (int j = (0); j < ((n)); j++) {         if (!chats[i].words.count(hnames[j])) chats[i].possibles.push_back(j);       }     }     for (int i = (0); i < ((m)); i++) p[i] = i;     sort(p, p + m, cmp);     if (rec(0)) {       for (int i = (0); i < ((m)); i++) {         printf( %s:%s n , names[res[i]].c_str(), chats[i].text.c_str());       }     } else {       printf( Impossible n );     }     return false;   }   int main() {     prepare();     int t;     scanf( %d , &t);     for (int i = (0); i < ((t)); i++) {       read();       while (solve())         ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 7;   const int mod = 998244353;   int ans[1007][1007];   int num[1007];   int n, k;   void print(int l, int r) {     cout <<  ?   << r - l + 1 <<    ;     for (int i = l; i <= r; i++) cout << i <<    ;     cout << endl;     fflush(stdout);   }   int ggg(int x) {     for (int i = 1; i <= k; i++)       for (int j = 1; j <= num[i]; j++) {         if (ans[i][j] == x) {           return i;         }       }   }   int main() {     ios::sync_with_stdio(false);     int zs;     cin >> zs;     while (zs--) {       cin >> n >> k;       for (int i = 1; i <= k; i++) {         cin >> num[i];         for (int j = 1; j <= num[i]; j++) cin >> ans[i][j];       }       int ma;       print(1, n);       cin >> ma;       int l = 1, r = n;       while (l < r) {         int mid = (l + r) / 2;         print(l, mid);         int x;         cin >> x;         if (x == ma)           r = mid;         else           l = mid + 1;       }       int t = ggg(l);       int vis[1007] = {0};       for (int i = 1; i <= num[t]; i++) vis[ans[t][i]] = 1;       cout <<  ?   << n - num[t] <<    ;       for (int i = 1; i <= n; i++)         if (!vis[i]) cout << i <<    ;       cout << endl;       fflush(stdout);       int se;       cin >> se;       cout <<  !  <<    ;       for (int i = 1; i <= k; i++)         if (i == t)           cout << se <<    ;         else           cout << ma <<    ;       cout << endl;       string s;       cin >> s;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e3;   const int maxx = 1e6;   const int inf = 0x3f3f3f3f;   int n, m, tot, c[maxx + 10], ans = inf;   pair<int, int> a[maxn + 10], b[maxn + 10];   set<pair<int, int> > s;   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) scanf( %d%d , &a[i].first, &a[i].second);     for (int i = 1; i <= m; ++i) scanf( %d%d , &b[i].first, &b[i].second);     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j)         if (b[j].first >= a[i].first && b[j].second >= a[i].second)           c[b[j].first - a[i].first] =               max(c[b[j].first - a[i].first], b[j].second - a[i].second + 1);     for (int i = maxx; i >= 0; --i) c[i] = max(c[i], c[i + 1]);     for (int i = 0; i <= maxx; ++i) ans = min(ans, i + c[i]);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long modn = 1000000007;   inline long long mod(long long x) { return x % modn; }   template <class num>   inline void rd(num &x) {     char c;     while (isspace(c = getchar()))       ;     bool neg = false;     if (!isdigit(c))       neg = (c ==  - ), x = 0;     else       x = c -  0 ;     while (isdigit(c = getchar())) x = (x << 3) + (x << 1) + c -  0 ;     if (neg) x = -x;   }   int n;   const int N = 1123456;   vector<long long> query[N];   vector<pair<long long, long long> > ans[N];   int A[N];   long long H[N], l[N];   long long acc[N], tmp[N];   int tn;   void dfs(int u, long long d) {     if (u > n) return;     tmp[tn++] = d;     dfs(2 * u, d + l[2 * u]);     dfs(2 * u + 1, d + l[2 * u + 1]);   }   void answer_for(int u) {     tn = 0;     dfs(u, 0);     sort(tmp, tmp + tn);     acc[0] = tmp[0];     for (int i = 1; i < tn; i++) acc[i] = acc[i - 1] + tmp[i];     sort(query[u].begin(), query[u].end());     ans[u].resize(query[u].size());     for (int i = int(query[u].size()) - 1; i >= 0; i--) {       while (tn > 0 && tmp[tn - 1] > query[u][i]) tn--;       ans[u][i] = pair<long long, long long>(tn, tn ? acc[tn - 1] : 0ll);     }   }   inline void reg(int u, long long v) { query[u].push_back(v); }   inline pair<long long, long long> get(int u, long long v) {     return ans[u][lower_bound(query[u].begin(), query[u].end(), v) -                   query[u].begin()];   }   int main() {     int m;     int i;     rd(n);     rd(m);     for (i = 2; i <= n; i++) rd(l[i]);     for (i = 0; i < m; i++) {       rd(A[i]);       rd(H[i]);       int ai = A[i];       long long hi = H[i];       reg(ai, hi);       int nx = ai;       hi -= l[ai];       ai = ai / 2;       while (ai && hi > 0) {         reg(ai, hi);         if (hi - l[nx] > 0) reg(nx, hi - l[nx]);         nx = ai;         hi -= l[ai];         ai = ai / 2;       }     }     for (int i = 1; i <= n; i++) answer_for(i);     for (i = 0; i < m; i++) {       int ai = A[i];       long long hi = H[i];       pair<long long, long long> ans = get(ai, hi);       int nx = ai;       hi -= l[ai];       ai = ai / 2;       while (ai && hi > 0) {         pair<long long, long long> p = get(ai, hi);         ans.first += p.first;         ans.second += p.first * (H[i] - hi) + p.second;         if (hi - l[nx] > 0) {           pair<long long, long long> p = get(nx, hi - l[nx]);           ans.first -= p.first;           ans.second -= p.first * (H[i] - hi + l[nx]) + p.second;         }         nx = ai;         hi -= l[ai];         ai = ai / 2;       }       printf( %lld n , ans.first * H[i] - ans.second);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     vector<int> a(n, 0);     for (int i = 0; i < n; i++) cin >> a[i];     sort(a.begin(), a.end());     int s = 0, cnt = 0;     for (int i = 0; i < n; i++) {       if (m == 0) break;       if (a[i] < 0) {         s += abs(a[i]);         m--;       }     }     cout << abs(s);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cups[1001];   int main() {     int size;     cin >> size;     int sum = 0;     int avg;     for (int i = 1; i <= size; ++i) {       cin >> cups[i];       sum += cups[i];     }     avg = sum / size;     if (size * avg != sum) {       cout <<  Unrecoverable configuration.  << endl;       return 0;     }     int diff = 0;     int from, to;     bool done = false;     for (int i = 1; i <= size; ++i) {       if (cups[i] != avg) {         if (diff == 0) {           diff = avg - cups[i];           if (diff > 0)             from = i;           else             to = i;         } else if (done) {           cout <<  Unrecoverable configuration.  << endl;           return 0;         } else {           if (cups[i] - diff == avg) {             done = true;             if (diff > 0)               to = i;             else               from = i;             diff = abs(diff);           } else {             cout <<  Unrecoverable configuration.  << endl;             return 0;           }         }       }     }     if (diff == 0) {       cout <<  Exemplary pages.  << endl;       return 0;     }     cout << diff <<   ml. from cup #  << from <<   to cup #  << to <<  .  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, k, i, j;     cin >> n >> k;     int a[n - k + 1];     string s;     for (i = 0; i < n - k + 1; i++) {       cin >> s;       if (s[0] ==  Y )         a[i] = 0;       else         a[i] = 1;     }     vector<string> ans;     char a1 =  a , b =  a ;     string v =   ;     i = 0;     for (i = 0; i < k; i++) {       ans.push_back(v + a1);       if (a1 ==  z ) {         v = b;         b++;         a1 =  a ;       } else         a1++;     }     if (a[0] == 1) {       ans[k - 1] = ans[0];       a1--;     }     j = 1;     for (i = 1; i < n - k + 1; i++) {       if (a[i] == 1)         ans.push_back(ans[i]);       else {         ans.push_back(v + a1);         if (a1 ==  z ) {           v = b;           b++;           a1 =  a ;         } else           a1++;       }     }     for (i = 0; i < n; i++) ans[i][0] -= 32;     for (i = 0; i < n; i++) cout << ans[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   map<long long int, long long int> mp, mk;   set<long long int> s1, s2;   vector<long long int> v, w;   string s =   , p =   , q =   ;   char ch;   long long int m, n, c, i, j, k, l, r, x, t, y, u, e, f, g, h, mn, mx, d, z;   int main() {     cin >> n >> t;     if (t == 10) {       if (n == 1) {         cout << -1;         return 0;       } else {         cout << 1;         for (i = 1; i < n; i++) cout << 0;         return 0;       }     }     for (i = 1; i <= n; i++) cout << t;   }


#include <bits/stdc++.h>   using namespace std;   int N;   int P[101010];   int V[101010];   vector<int> E[101010];   double T[101010];   void dfs(int cur, double tim) {     tim += 1;     T[cur] = tim;     for (auto& r : E[cur]) {       double el = (V[cur] - 1 - V[r]) * 0.5;       dfs(r, tim + el);     }   }   void solve() {     int i, j, k, l, r, x, y;     string s;     cin >> N;     for (i = 1; i < N; i++) cin >> P[i], P[i]--, E[P[i]].push_back(i);     for (i = N - 1; i >= 0; i--) {       V[i]++;       if (i) V[P[i]] += V[i];     }     dfs(0, 0);     for (i = 0; i < (N); i++)       (void)printf( %lf%c , T[i], (i == N - 1) ?   n  :    );   }   int main(int argc, char** argv) {     string s;     int i;     if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);     for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s +=   n ;     for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, n, m, ar[200] = {0}, tp = 1;     cin >> n >> m;     for (int i = 1; i <= n; i++) {       cin >> a >> b;       for (int j = a + 1; j <= b; j++) {         if (!ar[j]) tp++, ar[j]++;       }     }     cout << ((tp == m + 1) ?  YES  :  NO ) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e12;   const int maxn = 2e5 + 30;   int n;   long long dp[maxn][2], val[maxn], h[maxn], ans;   vector<int> G[maxn];   void Min(long long &x, long long y) {     if (x > y) x = y;   }   void dfs(int u, int fa) {     for (auto v : G[u]) {       if (v == fa) continue;       dfs(v, u);     }     long long s = 0;     vector<long long> r, sum;     r.clear();     for (auto v : G[u]) {       if (v == fa) continue;       s += dp[v][0];       r.push_back(dp[v][1] - dp[v][0]);     }     sort(r.begin(), r.end());     int m = r.size();     sum.resize(m + 1);     sum[0] = 0;     for (int i = 0; i < m; i++) sum[i + 1] = sum[i] + r[i];     if (!fa) {       dp[u][0] = inf;       for (int i = 0; i <= m; i++)         Min(dp[u][0], s + sum[i] + val[u] * abs((m - i) - i));     } else {       dp[u][0] = inf;       dp[u][1] = inf;       for (int i = 0; i <= m; i++) {         Min(dp[u][0], s + sum[i] + val[u] * abs((m - i) - (i + 1)));         Min(dp[u][1], s + sum[i] + val[u] * abs((m - i + 1) - i));       }       if (h[u] < h[fa]) dp[u][0] = inf;       if (h[u] > h[fa]) dp[u][1] = inf;     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %lld , &val[i]);     for (int i = 1; i <= n; i++) scanf( %lld , &h[i]);     for (int i = 1; i < n; i++) {       int u, v;       scanf( %d%d , &u, &v);       G[u].push_back(v);       G[v].push_back(u);       ans += val[u] + val[v];     }     dfs(1, 0);     cout << (ans + dp[1][0]) / 2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long bruh = -1e18;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     vector<long long> v(n);     for (int i = 0; i < n; i++) {       cin >> v[i];     }     sort(v.begin(), v.end());     long long sum = accumulate(v.begin(), v.end(), bruh);     int q;     cin >> q;     while (q--) {       long long x, y;       cin >> x >> y;       int idx = lower_bound(v.begin(), v.end(), x) - v.begin();       int idxx = upper_bound(v.begin(), v.end(), x) - v.begin();       if (idxx == n) {         idxx--;       }       if (idx == n) {         idx--;       }       long long ans = LLONG_MAX;       long long tt = 0;       tt += (x - v[idx] > 0 ? x - v[idx] : 0);       tt += (sum - v[idx] - bruh < y ? y - sum + bruh + v[idx] : 0);       ans = min(ans, tt);       tt = 0;       tt += (x - v[idx - 1] > 0 ? x - v[idx - 1] : 0);       tt += (sum - bruh - v[idx - 1] < y ? y - sum + bruh + v[idx - 1] : 0);       ans = min(ans, tt);       tt = 0;       tt += (x - v[idxx] > 0 ? x - v[idxx] : 0);       tt += (sum - v[idxx] - bruh < y ? y - sum + v[idxx] + bruh : 0);       ans = min(ans, tt);       tt = 0;       tt += (x - v[idxx - 1] > 0 ? x - v[idxx - 1] : 0);       tt += (sum - v[idxx - 1] - bruh < y ? y - sum + v[idxx - 1] + bruh : 0);       ans = min(ans, tt);       tt = 0;       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<complex<double> > vec;   double minDist(complex<double> &a, complex<double> &b, complex<double> &p) {     complex<double> ab = ((b) - (a)), ap = ((p) - (a)), ba = ((a) - (b)),                     bp = ((p) - (b));     double distPB = sqrt(((conj(bp) * (bp)).real())),            distPA = sqrt(((conj(ap) * (ap)).real())),            distAB = sqrt(((conj(ab) * (ab)).real()));     double thetaA = acos(((conj(ab) * (ap)).real()) / distAB / distPA);     double thetaB = acos(((conj(ba) * (bp)).real()) / distAB / distPB);     double ans;     if (fabs(thetaA) >= 3.14159265358979323846 / 2)       ans = distPA;     else if (fabs(thetaB) >= 3.14159265358979323846 / 2)       ans = distPB;     else       ans = sin(fabs(thetaA)) * distPA;     return ans;   }   int main() {     int n;     long long px, py, tempX, tempY;     scanf( %d %I64d %I64d , &n, &px, &py);     double maxi = 0, mini = 1E12, dist;     for (int i = 0; i < n; i++) {       scanf( %I64d %I64d , &tempX, &tempY);       dist = sqrt((tempX - px) * (tempX - px) + (tempY - py) * (tempY - py));       maxi = max(maxi, dist);       complex<double> xx = complex<double>(tempX, tempY);       vec.push_back(xx);     }     vec.push_back(vec[0]);     maxi *= maxi;     complex<double> P = complex<double>(px, py);     for (int i = 0; i < n; i++) {       mini = min(mini, minDist(vec[i], vec[i + 1], P));     }     mini *= mini;     double ans = (maxi - mini);     ans *= 3.14159265358979323846;     printf( %0.8f , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int ABS(long long int a) {     if (a < 0) return (-a);     return a;   }   vector<long long int> g[100001];   vector<long long int> p[100001];   map<pair<long long int, long long int>, int> l;   int visited[100001];   long long int ans[100001][4];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     priority_queue<pair<long long int, long long int> > q;     long long int n, m, count = 0, z = 0;     cin >> n >> m;     for (int i = (0); i < (m); ++i) {       long long int a, b, c;       cin >> a >> b >> c;       g[a].push_back(b);       g[b].push_back(a);       p[a].push_back(c);       p[b].push_back(c);       l[make_pair(a, b)] = c;       if (c == 1) z++;     }     for (int i = (1); i < (n + 1); ++i) ans[i][0] = 1000000000LL;     long long int start = 1;     ans[start][1] = 0;     ans[start][0] = 0;     visited[start] = -1;     q.push(make_pair(0, start));     while (!q.empty()) {       long long int a = q.top().second;       long long int d = -q.top().first;       q.pop();       for (long long int ii = 0; ii < g[a].size(); ii++) {         long long int i = g[a][ii];         if (visited[i] == 1) continue;         if (ans[i][0] > d + 1 or             (ans[i][0] == d + 1 and ans[i][1] <= ans[a][1] + p[a][ii])) {           ans[i][0] = d + 1;           ans[i][1] = ans[a][1] + p[a][ii];           ans[i][2] = a;         }         if (visited[i] == 0 and i != n) {           visited[i] = -1;           q.push(make_pair(-ans[i][0], i));         }       }       visited[a] = 1;     }     vector<long long int> aens[3];     long long int i = n;     while (i != 1) {       long long int nei = ans[i][2];       if (l.find(make_pair(i, nei)) != l.end()) {         if (l[make_pair(i, nei)] == 0) {           aens[0].push_back(i);           aens[1].push_back(nei);           aens[2].push_back(1);         }         l[make_pair(i, nei)] = 2;       } else {         if (l[make_pair(nei, i)] == 0) {           aens[0].push_back(i);           aens[1].push_back(nei);           aens[2].push_back(1);         }         l[make_pair(nei, i)] = 2;       }       i = nei;     }     for (auto &it : l) {       if (it.second == 1) {         aens[0].push_back(it.first.first);         aens[1].push_back(it.first.second);         aens[2].push_back(0);       }     }     cout << aens[1].size() <<   n ;     for (int i = (0); i < (aens[1].size()); ++i)       cout << aens[0][i] <<     << aens[1][i] <<     << aens[2][i] <<   n ;     return 0;   }


#include <bits/stdc++.h>   #pragma optimise GCC(-O2)   using namespace std;   mt19937_64 rang(       chrono::high_resolution_clock::now().time_since_epoch().count());   int rng(int lim) {     uniform_int_distribution<int> uid(0, lim - 1);     return uid(rang);   }   long long INF = LLONG_MAX;   const long long M = 1000000007;   long long powm(long long, long long);   long long perm[2000005];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n;     cin >> n;     for (int i = 0; i < 2000005; i++) perm[i] = -1;     for (int i = 1; i < n + 1; i++) perm[i] = i;     for (int i = 2; i < n + 1; i++) {       long long to_be = -1;       long long replace = 0;       while (replace * i + 1 <= n) {         swap(to_be, perm[replace * i + i - 1]);         replace++;       }       swap(to_be, perm[n + i - 1]);     }     for (int i = 0; i < 2000005; i++)       if (perm[i] != -1) cout << perm[i] <<    ;   }   long long powm(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = (res * a) % M;       a = (a * a) % M;       b >>= 1;     }     return res;   }


#include <bits/stdc++.h>   using namespace std;   long long INF = (long long)1e20;   long long mod = (long long)1e9 + 7;   pair<long long, long long> solve(       long long v, vector<vector<pair<long long, long long>>> &nodes, long long p,       long long k) {     vector<pair<pair<long long, long long>, long long>> a;     vector<pair<pair<long long, long long>, long long>> b;     for (int i = 0; i < nodes[v].size(); ++i) {       if (nodes[v][i].first != p) {         pair<long long, long long> kek = solve(nodes[v][i].first, nodes, v, k);         kek.first += nodes[v][i].second;         if (kek.second > kek.first) {           b.push_back({kek, nodes[v][i].second});         } else {           a.push_back({kek, nodes[v][i].second});         }       }     }     vector<pair<pair<long long, long long>, pair<long long, long long>>> vv(         a.size());     for (int i = 0; i < a.size(); ++i) {       vv[i] = {{a[i].first.first - a[i].first.second, a[i].second}, {a[i].first}};     }     sort(vv.rbegin(), vv.rend());     long long sum1 = 0;     for (int i = 0; i < a.size(); ++i) {       if (i < k) {         sum1 += vv[i].second.first;       } else {         sum1 += vv[i].second.second;       }     }     for (int i = 0; i < b.size(); ++i) {       sum1 += b[i].first.second;     }     long long sum = 0;     if (a.size() < k) {       sum = sum1;     }     for (int i = 0; i < a.size(); ++i) {       if (i < k) {         long long nw = sum1 - vv[i].second.first;         nw += vv[i].second.second;         sum = max(sum, nw);       } else         break;     }     return {sum, sum1};   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long q;     cin >> q;     while (q--) {       long long n, k;       cin >> n >> k;       vector<vector<pair<long long, long long>>> nodes(n);       for (int i = 0; i < n - 1; ++i) {         long long u, v, w;         cin >> u >> v >> w;         nodes[u - 1].push_back({v - 1, w});         nodes[v - 1].push_back({u - 1, w});       }       pair<long long, long long> ans = solve(0, nodes, 0, k);       cout << max(ans.first, ans.second) <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   ;   const double eps = 1e-8;   const int mod = 1e9 + 7;   const int maxn = 3e5 + 5;   const int INF = 0x3f3f3f3f;   const long long INFLL = 0x3f3f3f3f3f3f3f3f;   struct EDGE {     int v, nxt;   } edge[maxn << 1];   int head[maxn], tot;   void add_edge(int u, int v) {     edge[tot].v = v, edge[tot].nxt = head[u], head[u] = tot++;   }   long long bit[maxn];   int lowbit(int x) { return x & (-x); }   void add(int pos, int val) {     while (pos < maxn) {       bit[pos] += val, pos += lowbit(pos);     }   }   long long sum(int pos) {     long long ans = 0;     while (pos) {       ans += bit[pos], pos -= lowbit(pos);     }     return ans;   }   pair<int, int> p[maxn];   set<pair<int, int> > s;   void dfs(int l, int r) {     int mid = (l + r) >> 1;     for (int i = l; i <= r; i++) {       s.insert(make_pair(p[mid].first, p[i].second));     }     if (l < mid) dfs(l, mid - 1);     if (r > mid) dfs(mid + 1, r);   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       cin >> p[i].first >> p[i].second;     }     sort(p, p + n);     dfs(0, n - 1);     cout << s.size() << endl;     set<pair<int, int> >::iterator it;     for (it = s.begin(); it != s.end(); it++)       cout << it->first <<     << it->second << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = double;   const ll MODBASE = 1000000007LL;   const int MAXN = 100010;   const int MAXM = 1010;   const int MAXK = 110;   const int MAXQ = 200010;   int n, a[MAXN], b[MAXN], f[MAXN], t[MAXN];   void update(int u, int gt) {     while (u) {       t[u] += gt;       u = u - (u & (-u));     }   }   int get(int u) {     int res = 0;     while (u <= 100000) {       res += t[u];       u = u + (u & (-u));     }     return res;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(nullptr);     cin >> n;     for (int i = (1); i <= (n); i++) cin >> a[i];     for (int i = (1); i <= (n); i++) {       cin >> b[i];       f[b[i]] = i;     }     for (int i = (1); i <= (n); i++) update(i, 1);     int res = 0;     for (int i = (n); i >= (1); i--) {       int g = a[i];       int pos = f[g];       if (get(pos + 1)) res++;       update(pos, -1);     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   const int maxt = 1 << 20;   int p[maxn], t[maxn];   bool vis[maxn], cut[maxn];   long long x[maxn], l[maxn], cal[maxn], bit1[maxt], bit2[maxt];   vector<int> son[maxn];   void dfs1(int u, long long rem) {     rem -= l[u] << 1;     for (int i = t[u]; i < maxt; i += (i & -i))       bit1[i] += x[u], bit2[i] += x[u] * t[u];     if (rem > 0) {       int l = 0, r = maxt - 1;       long long sum = 0;       for (int i = r; i; i -= (i & -i)) cal[u] += bit1[i], sum += bit2[i];       if (sum > rem) {         while (r - l ^ 1) {           int mid = l + r >> 1;           sum = 0;           for (int i = mid; i; i -= (i & -i)) sum += bit2[i];           if (sum > rem)             r = mid;           else             l = mid;         }         cal[u] = sum = 0;         for (int i = l; i; i -= (i & -i)) cal[u] += bit1[i], sum += bit2[i];         cal[u] += (rem - sum) / r;       }     }     for (auto v : son[u]) dfs1(v, rem);     for (int i = t[u]; i < maxt; i += (i & -i))       bit1[i] -= x[u], bit2[i] -= x[u] * t[u];   }   long long dfs2(int u) {     long long max1 = 0, max2 = 0;     for (auto v : son[u]) {       long long temp = dfs2(v);       if (max2 < temp) max2 = temp;       if (max1 < max2) swap(max1, max2);     }     return max(max2, cal[u]);   }   int main() {     int n;     long long T;     cin >> n >> T;     for (int i = 1; i <= n; ++i) cin >> x[i];     for (int i = 1; i <= n; ++i) cin >> t[i];     for (int i = 2; i <= n; ++i) {       cin >> p[i] >> l[i];       son[p[i]].push_back(i);     }     dfs1(1, T);     son[1].push_back(0);     cal[0] = 0x3f3f3f3f3f3f3f3f;     cout << dfs2(1) << endl;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int N = 2e6 + 7;   const int mod = 1e9 + 7;   int a[N];   int l[N];   int c[N];   int f[N];   int binpow(int a, int b) {     int ret = 1;     while (b) {       if (b & 1) {         ret = (ret * 1LL * a) % mod;         --b;       }       a = (a * 1LL * a) % mod;       b >>= 1;     }     return ret;   }   int main() {     f[0] = 1;     for (int i = 1; i < N; ++i) f[i] = (f[i - 1] * 1LL * i) % mod;     int n;     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %d , a + i);     sort(a, a + n);     c[0] = 1;     for (int i = 1; i < n; ++i) {       l[i] = a[i] == a[i - 1] ? l[i - 1] : l[i - 1] + c[i - 1];       c[i] = a[i] == a[i - 1] ? c[i - 1] + 1 : 1;     }     int res = 0;     for (int i = 0; i < n; ++i) {       if (a[i] == a[n - 1]) break;       int v = (a[i] * 1LL * f[l[i]]) % mod;       v = (v * 1LL * f[n - l[i] - 1]) % mod;       v = (v * 1LL * f[n]) % mod;       v = (v * 1LL * binpow((f[n - l[i]] * 1LL * f[l[i]]) % mod, mod - 2)) % mod;       res = (res + v) % mod;     }     printf( %d n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;      #define pb push_back   #define ff first   #define ss second   #define lli long long int   #define ll long long   #define st string   #define vi vector<int>   #define vll vector<long long>   #define tll tuple<ll,ll,ll>   #define pii pair<int,int>   #define pll pair<ll,ll>   #define vpii vector<pii>   #define vpll vector<pll>   #define take(n) ll n;cin>>n;   #define takeinp(arr,n) for(long long int i=0;i<n;i++) cin>>arr[i];   #define gcd(a,b) __gcd(a,b)   #define mii map<int,int>   #define mll map<ll,ll>   #define all(x) x.begin(),x.end()   #define allr(x) x.rbegin(),x.rend()   #define mllitr mll::iterator itr;   #define repm(itr,mp) for(itr=mp.begin();itr!=mp.end();itr++)   #define rep(i,a,b) for(ll i=a;i<b;i++)   #define repo(i,a,b) for(ll i=a;i>b;i--)                  //GL HF//      void solve(){       string s;cin>>s;       ll n=s.length()-1;       // cout<<char( a +n)<<  n ;       if(n==0){           if(s[0]!= a ) {cout<< NO n ;return;}       }       while(n>=0){           char tmp =  a +n;           if(s[0]==tmp){               s.erase(s.begin()+0);           }else if(s[n]==tmp){               s.erase(s.begin()+n);           }else{               cout<< NO n ;               return;           }           n--;       }       cout<< YES n ;       // cout<< a +0<<  n ;   }      int main(){       ios_base::sync_with_stdio(false);       cin.tie(NULL);       cout.tie(NULL);       ll t=1;       cin>>t;       while(t--){           solve();       }   }


#include <bits/stdc++.h>   using namespace std;   char a[1111];   int main() {     int h = 0, i = 0, j;     bool isopen = false;     gets(a);     while (i < strlen(a) - 1) {       if (a[i] ==  <  && a[i + 1] !=  / ) {         if (isopen) h += 2;         for (j = 0; j < h; j++) printf(   );         printf( < );         i++;         while (i < strlen(a) && a[i] !=  < ) printf( %c , a[i]), i++;         printf(  n );         isopen = true;       } else if (a[i] ==  < ) {         if (!isopen) h -= 2;         for (j = 0; j < h; j++) printf(   );         printf( < );         i++;         while (i < strlen(a) && a[i] !=  < ) printf( %c , a[i]), i++;         printf(  n );         isopen = false;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a, b, c;   int getlength(int x, int y, int z) { return (x - y + 1) / (z); }   int main() {     int n, a, b, right, left;     cin >> n >> a >> b;     set<int> M;     int sh = (n + 1) / (b + 1);     n++;     b++;     M.insert(0);     M.insert(n);     int m, x;     cin >> m;     for (int i = 1; i <= m; i++) {       cin >> x;       auto ptr = M.upper_bound(x);       right = *ptr;       left = *--ptr;       sh -= (right - left) / b;       sh += (right - x) / b;       sh += (x - left) / b;       M.insert(x);       if (sh < a) {         cout << i << endl;         return 0;       }     }     cout << -1 << endl;   }


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


#include <bits/stdc++.h>   using namespace std;   int n, m, k;   bool debug = false;   int main() {     scanf( %d , &n);     int x, y;     long long sum = 0, ss = 0, px = 0, py = 0;     for (int i = 0; i < n; i++) {       scanf( %d%d , &x, &y);       sum += (long long)x * x + (long long)y * y;       ss += px * x + py * y;       px += (long long)x;       py += (long long)y;     }     sum = sum * (n - 1);     sum -= 2 * ss;     cout << sum << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Maxn = 2e5;   const long long inf = 1e15;   inline int read() {     char ch = getchar();     int f = 1, x = 0;     while (ch >  9  || ch <  0 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   struct Point {     long long x, y;     Point() : x(0), y(0) {}     Point(long long X, long long Y) : x(X), y(Y) {}     inline long long Len() { return x * x + y * y; }   };   bool operator<(Point a, Point b) { return a.x == b.x ? a.y < b.y : a.x < b.x; }   inline long long Dis(Point a, Point b) {     return Point(a.x - b.x, a.y - b.y).Len();   }   int n;   long long ans = 1e15, sum[Maxn + 5];   Point P[Maxn + 5], st[Maxn + 5];   inline long long Divide(int l, int r) {     int mid = (l + r) >> 1, i, j, tot = 0;     if (l == r) return inf;     long long d;     Point pnt = P[mid];     d = min(Divide(l, mid), Divide(mid + 1, r));     i = l, j = mid + 1;     while (i <= mid && j <= r) {       if (P[i].y < P[j].y)         st[++tot] = P[i++];       else         st[++tot] = P[j++];     }     while (i <= mid) st[++tot] = P[i++];     while (j <= r) st[++tot] = P[j++];     for (int i = l; i <= r; ++i) P[i] = st[i - l + 1];     tot = 0;     for (int i = l; i <= r; ++i)       if ((pnt.x - P[i].x) * (pnt.x - P[i].x) < d) st[++tot] = P[i];     for (int i = 1; i <= tot; ++i)       for (int j = i + 1;            (st[j].y - st[i].y) * (st[j].y - st[i].y) < d && j <= tot; ++j)         d = min(d, Dis(st[i], st[j]));     return d;   }   int main() {     n = read();     for (int i = 1; i <= n; ++i) sum[i] = sum[i - 1] + read();     for (int i = 1; i <= n; ++i) P[i] = Point(i, sum[i]);     sort(P + 1, P + n + 1);     ans = Divide(1, n);     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int c[160][160];   int lowbit(int x) { return x & -x; }   int sum(int x, int y) {     int ans = 0;     for (int i = x; i; i -= lowbit(i)) {       for (int j = y; j; j -= lowbit(j)) {         ans += c[i][j];       }     }     return ans;   }   void add(int x, int y, int v) {     for (int i = x; i < 160; i += lowbit(i)) {       for (int j = y; j < 160; j += lowbit(j)) {         c[i][j] += v;       }     }   }   char grid[160][160];   int dp[2][160][160];   int n, m, ans;   void dfs(int x, int y, int id) {     if (grid[x][y] ==  W ) {       add(x, y, -1);     }     if (sum(n, m) == 0) return;     if (id == 1) {       if (x + 1 <= n && y + 1 <= m) {         int tmp = sum(x + 1, m) - sum(x + 1, y);         if (x - 1 > 0) tmp = tmp - sum(x - 1, m) + sum(x - 1, y);         if (tmp > 0)           dfs(x, y + 1, 1);         else           dfs(x + 1, y, 0);       } else if (x + 1 > n && y + 1 <= m) {         int tmp = sum(x, m) - sum(x, y);         if (x - 1 > 0) tmp = tmp - sum(x - 1, m) + sum(x - 1, y);         if (tmp > 0)           dfs(x, y + 1, 1);         else           dfs(x + 1, y, 0);       } else {         dfs(x + 1, y, 0);       }     } else {       if (x + 1 <= n && y - 1 > 0) {         int tmp = sum(x + 1, y - 1);         if (tmp > 0)           dfs(x, y - 1, 0);         else           dfs(x + 1, y, 1);       } else if (x + 1 > n && y - 1 > 0) {         int tmp = sum(x, y - 1);         if (tmp > 0)           dfs(x, y - 1, 0);         else           dfs(x + 1, y, 1);       } else         dfs(x + 1, y, 1);     }     ans++;   }   int main() {     setvbuf(stdout, NULL, _IONBF, 0);     while (scanf(  %d %d , &n, &m) == 2) {       for (int i = 1; i <= n; i++) {         scanf(  %s , grid[i] + 1);       }       memset(c, 0, sizeof(c));       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= m; j++) {           if (grid[i][j] ==  W ) {             add(i, j, 1);           }         }       }       ans = 0;       dfs(1, 1, 1);       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a, b, l, r, c, pl, pr, cl, cr;   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> a >> b >> l >> r, c = a + b;     cl = --l / c;     pl = l % c;     cr = --r / c;     pr = r % c;     if (cl == cr)       cout << min(r - l + 1, max(a - pl, 1));     else if (a <= b) {       if (cl < cr - 1)         cout << a + 1;       else {         int x = max(1, a - pl);         int y = min(a, pr + 1);         cout << min(a, x + y) + (y == a);       }     } else {       int d = a - b;       if (cl == cr - 1)         cout << max(1, min(d, a - pl)) + min(a, pr + 1);       else if (cl == cr - 2)         cout << a + max(1, d + min(0, pr - a + 1 + max(0, a - pl)));       else         cout << a + d;     }   }


#include <bits/stdc++.h>   using namespace std;   bool conn[4001][4001];   vector<int> path[4001];   struct Edge {     int a, b;   } edge[4001];   int main() {     int N, M;     cin >> N >> M;     for (int i = 0; i < M; i++) {       int a, b;       cin >> a >> b;       edge[i].a = a;       edge[i].b = b;       conn[a][b] = conn[b][a] = true;       path[a].push_back(b);       path[b].push_back(a);     }     int ans = 1000000;     for (int i = 0; i < M; i++) {       if (path[edge[i].a].size() >= 2 && path[edge[i].b].size() >= 2)         for (int k = 0; k < M; k++) {           if (path[edge[k].a].size() >= 2 && path[edge[k].b].size() >= 2)             if (i == k) continue;           int original = -1;           int total = original = path[edge[i].a].size() + path[edge[i].b].size() +                                  path[edge[k].b].size() + path[edge[k].a].size() -                                  6;           if (edge[i].a == edge[k].a) {             if (conn[edge[i].b][edge[k].b])               ans = min(ans, total - (int)path[edge[i].a].size());           } else if (edge[i].a == edge[k].b) {             if (conn[edge[i].b][edge[k].a])               ans = min(ans, total - (int)path[edge[i].a].size());           } else if (edge[i].b == edge[k].a) {             if (conn[edge[i].a][edge[k].b])               ans = min(ans, total - (int)path[edge[i].b].size());           } else if (edge[i].b == edge[k].b) {             if (conn[edge[i].a][edge[k].a])               ans = min(ans, total - (int)path[edge[i].b].size());           }         }     }     if (ans == 1000000) ans = -1;     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (n % 4 == 1 || n % 4 == 0) {       int *result = new int[n + 1];       if (n % 2 == 1) {         result[(n + 1) / 2] = n / 2 + 1;       }       for (int i = 1; i < (n + 1) / 2; i += 2) {         result[i] = i + 1;         result[i + 1] = n + 1 - i;         result[n + 1 - i] = n - i;         result[n - i] = i;       }       for (int i = 1; i <= n; i++) cout << result[i] <<    ;       delete[] result;     } else       cout << -1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 5003, mod = 1e9 + 7;   long long n, k, S[N][N], ans;   inline long long kasumi(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = (long long)res * a % mod;       a = (long long)a * a % mod;       b >>= 1;     }     return res;   }   signed main() {     scanf( %d%d , &n, &k);     S[0][0] = 1;     for (register long long i = 1; i <= k; i++)       for (register long long j = 1; j <= i; j++)         S[i][j] = ((long long)S[i - 1][j] * j + S[i - 1][j - 1]) % mod;     long long fac = 1, cho = 1;     for (register long long i = 1; i <= k && i <= n; i++) {       cho = (long long)cho * (n - i + 1) % mod * kasumi(i, mod - 2) % mod;       fac = (long long)fac * i % mod;       ans = (ans + (long long)fac * cho % mod * kasumi(2, n - i) % mod * S[k][i] %                        mod) %             mod;     }     printf( %d , ans);   }


#include <bits/stdc++.h>   using namespace std;   using namespace chrono;   void _print(long long t) { cerr << t; }   void _print(int t) { cerr << t; }   void _print(string t) { cerr << t; }   void _print(char t) { cerr << t; }   void _print(long double t) { cerr << t; }   void _print(double t) { cerr << t; }   void _print(unsigned long long t) { cerr << t; }   template <class T, class V>   void _print(pair<T, V> p);   template <class T>   void _print(vector<T> v);   template <class T>   void _print(set<T> v);   template <class T, class V>   void _print(map<T, V> v);   template <class T>   void _print(multiset<T> v);   template <class T, class V>   void _print(pair<T, V> p) {     cerr <<  { ;     _print(p.first);     cerr <<  , ;     _print(p.second);     cerr <<  } ;   }   template <class T>   void _print(vector<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T>   void _print(set<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T>   void _print(multiset<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T, class V>   void _print(map<T, V> v) {     cerr <<  [  ;     for (auto i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   long long gcd(long long a, long long b) {     if (b > a) {       return gcd(b, a);     }     if (b == 0) {       return a;     }     return gcd(b, a % b);   }   long long expo(long long a, long long b, long long mod) {     long long res = 1;     while (b > 0) {       if (b & 1) res = (res * a) % mod;       a = (a * a) % mod;       b = b >> 1;     }     return res;   }   void extendgcd(long long a, long long b, long long *v) {     if (b == 0) {       v[0] = 1;       v[1] = 0;       v[2] = a;       return;     }     extendgcd(b, a % b, v);     long long x = v[1];     v[1] = v[0] - v[1] * (a / b);     v[0] = x;     return;   }   long long mminv(long long a, long long b) {     long long arr[3];     extendgcd(a, b, arr);     return arr[0];   }   long long mminvprime(long long a, long long b) { return expo(a, b - 2, b); }   bool revsort(long long a, long long b) { return a > b; }   void swap(int &x, int &y) {     int temp = x;     x = y;     y = temp;   }   long long combination(long long n, long long r, long long m, long long *fact,                         long long *ifact) {     long long val1 = fact[n];     long long val2 = ifact[n - r];     long long val3 = ifact[r];     return (((val1 * val2) % m) * val3) % m;   }   void google(int t) { cout <<  Case #  << t <<  :  ; }   vector<long long> sieve(int n) {     int *arr = new int[n + 1]();     vector<long long> vect;     for (int i = 2; i <= n; i++)       if (arr[i] == 0) {         vect.push_back(i);         for (int j = 2 * i; j <= n; j += i) arr[j] = 1;       }     return vect;   }   long long mod_add(long long a, long long b, long long m) {     a = a % m;     b = b % m;     return (((a + b) % m) + m) % m;   }   long long mod_mul(long long a, long long b, long long m) {     a = a % m;     b = b % m;     return (((a * b) % m) + m) % m;   }   long long mod_sub(long long a, long long b, long long m) {     a = a % m;     b = b % m;     return (((a - b) % m) + m) % m;   }   long long mod_div(long long a, long long b, long long m) {     a = a % m;     b = b % m;     return (mod_mul(a, mminvprime(b, m), m) + m) % m;   }   long long phin(long long n) {     long long number = n;     if (n % 2 == 0) {       number /= 2;       while (n % 2 == 0) n /= 2;     }     for (long long i = 3; i <= sqrt(n); i += 2) {       if (n % i == 0) {         while (n % i == 0) n /= i;         number = (number / i * (i - 1));       }     }     if (n > 1) number = (number / n * (n - 1));     return number;   }   bool isPrime(long long x) {     if (x < 2) return false;     for (long long y = 2; y * y <= x; y++)       if (x % y == 0) return false;     return true;   }   long long ceil(long long a, long long b) {     long long aa = (a + b - 1) / b;     return aa;   }   const int N = 200001;   bool cmp(pair<long long, long long> a, pair<long long, long long> b) {     return a.second < b.second;   }   void solve() {     long long n, x1, y1;     cin >> n >> x1 >> y1;     vector<pair<long long, long long> > v(n);     for (long long i = 0; i < n; i++) cin >> v[i].first >> v[i].second;     long long ans = 0;     vector<long long> vis(n, 0);     for (long long i = 0; i < n; i++) {       long long x2 = v[i].first, y2 = v[i].second;       if (vis[i]) continue;       for (long long j = 0; j < n; j++) {         if (vis[j] or i == j) continue;         long long x3 = v[j].first, y3 = v[j].second;         if (((y2 - y1) * (x3 - x1) == (y3 - y1) * (x2 - x1))) vis[j] = 1;       }       vis[i] = 1;       ans++;     }     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     solve();     auto start1 = high_resolution_clock::now();     auto stop1 = high_resolution_clock::now();     auto duration = duration_cast<microseconds>(stop1 - start1);   }


#include <bits/stdc++.h>   using namespace std;   int dp[500][500] = {0}, arr[500], n;   int check(int i, int j) {     if (dp[i][j] != 0) return dp[i][j];     if (i > j) return 0;     if (i == j) {       dp[i][j] = 1;       return 1;     }     int a = 1 + check(i + 1, j);     int m = 1e9, it;     for (it = i + 2; it <= j; it++) {       if (arr[i] == arr[it]) {         if (m > check(i + 1, it - 1) + check(it + 1, j)) {           m = check(i + 1, it - 1) + check(it + 1, j);         }       }     }     int c = 1e9;     if (arr[i] == arr[i + 1]) c = 1 + check(i + 2, j);     dp[i][j] = min(min(c, a), m);     return dp[i][j];   }   int main() {     cin >> n;     int i, j, k, l;     for (i = 0; i < n; i++) {       cin >> arr[i];     }     check(0, n - 1);     cout << dp[0][n - 1] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int N = 2e5 + 10;   long long sum[N];   long long a[N], b[N];   long long f[N][20];   int n, k, top;   long long MAX(long long x, long long y) {     if (x < y) return y;     return x;   }   void advan() {     for (int i = 1; i <= top; ++i) f[i][0] = b[i];     for (int i = 1; (1 << i) <= top; ++i) {       for (int j = 1; j + (1 << i) - 1 <= top; ++j)         f[j][i] = f[j][i - 1] < f[j + (1 << (i - 1))][i - 1]                       ? f[j + (1 << (i - 1))][i - 1]                       : f[j][i - 1];     }   }   long long query(int l, int r) {     int k = 0;     k = log2(double(r - l + 1));     return MAX(f[l][k], f[r - (1 << k) + 1][k]);   }   int main() {     scanf( %d %d , &n, &k);     for (int i = 1; i <= n; ++i) {       scanf( %lld , &a[i]);       sum[i] = sum[i - 1] + a[i];     }     top = 0;     for (int i = k; i <= n; ++i) b[++top] = sum[i] - sum[i - k];     advan();     long long maxx = 0, L = 0, R = 0, be, res = 0, en;     for (int i = 1; i <= top - k; ++i) {       L = b[i];       R = query(i + k, top);       if (L + R > maxx) {         maxx = L + R;         res = R;         be = i;       }     }     for (int i = be + k; i <= top; ++i) {       if (b[i] == res) {         en = i;         break;       }     }     printf( %lld %lld n , be, en);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, k, c, ans1, ans2, ans3, a[100005], dp[5];   pair<long long, long long> p[300005];   vector<long long> v;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     if (m == 0) {       cout << -1 <<   n ;       return 0;     }     for (long long i = 1; i <= m; i++) {       cin >> p[i].first >> p[i].second;       if (p[i].first == 1) {         v.push_back(p[i].second);       } else if (p[i].second == 1) {         v.push_back(p[i].first);       }     }     sort(v.begin(), v.end());     v.push_back(n + 1);     a[1] = 1;     for (int i = 2; i <= n; i++) {       if (i != v[k]) {         a[i] = 1;       } else {         k++;       }     }     c = v[0];     for (long long i = 1; i <= m; i++) {       if (p[i].first == c && a[p[i].second] == 0) {         a[p[i].second] = 2;       } else if (p[i].second == c && a[p[i].first] == 0) {         a[p[i].first] = 2;       }     }     for (long long i = 1; i <= n; i++) {       if (a[i] == 0) {         a[i] = 3;       }     }     for (long long i = 1; i <= n; i++) {       dp[a[i]]++;     }     if (dp[1] == 0 || dp[2] == 0 || dp[3] == 0 ||         dp[1] * dp[2] + dp[2] * dp[3] + dp[1] * dp[3] != m) {       cout << -1 <<   n ;       return 0;     }     for (long long i = 1; i <= m; i++) {       if (a[p[i].first] == a[p[i].second]) {         cout << -1 <<   n ;         return 0;       }     }     for (long long i = 1; i <= n; i++) {       cout << a[i] <<    ;     }     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long int> vec;   bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {     return (a.second < b.second);   }   long long int mark[123];   int main() {     std::ios::sync_with_stdio(false);     string str;     cin >> str;     long long int n;     cin >> n;     if (str.size() < n) {       cout <<  impossible ;       return 0;     }     for (long long int i = 0; i < str.size(); i++) {       mark[str[i]]++;     }     long long int ans = 0;     for (long long int i = 0; i < 123; i++) {       if (mark[i] > 0) ans++;     }     if (ans >= n)       cout <<  0 ;     else       cout << n - ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long m, n, i, t, j;     cin >> t;     while (t--) {       long long one = 0, zro = 0, cnt = 0, ans = 0;       cin >> n;       vector<long long> v;       for (long long j = 0; j < n; j++) {         string s;         cin >> s;         for (long long i = 0; i < s.size(); i++) {           if (s[i] ==  1 )             one++;           else             zro++;         }         v.push_back(s.size());       }       sort(v.begin(), v.end());       long long pr = one / 2 + zro / 2;       for (long long i = 0; i < v.size(); i++) {         long long need = v[i] / 2;         if (need <= pr) pr -= need, ans++;       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int x;     int y;     node(int a, int b) {       x = a;       y = b;     }   };   int n, m, k, flag;   vector<node> v;   int vis[10005], dis[10005];   const int inf = 0x3f3f3f3f;   int spfa() {     memset(dis, inf, sizeof(dis));     queue<int> q;     q.push(0);     dis[0] = 0;     while (!q.empty()) {       int Now = q.front();       q.pop();       vis[Now] = 0;       for (int i = 0; i < k; i++) {         if (i == Now) continue;         node to = v[i];         node now = v[Now];         int cost = inf;         if (abs(now.x - to.x) + abs(now.y - to.y) == 1)           cost = 0;         else if (abs(now.x - to.x) <= 2 || abs(now.y - to.y) <= 2)           cost = 1;         if (dis[i] > dis[Now] + cost) {           dis[i] = dis[Now] + cost;           if (!vis[i]) {             q.push(i);           }         }       }     }     if (dis[k - 1] < inf) return dis[k - 1];     return -1;   }   int main() {     ios::sync_with_stdio(false);     ;     while (cin >> n >> m >> k) {       flag = 0;       v.clear();       for (int i = 0; i < k; i++) {         int x, y;         cin >> x >> y;         v.push_back(node(x, y));         if (x == n && y == m) flag = 1;       }       if (!flag) {         k++;         v.push_back(node(n + 1, m + 1));       }       cout << spfa() << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   const double pi = acos(-1);   int main() {     ios_base::sync_with_stdio(false);     double w, h, a;     cin >> w >> h >> a;     if (a > 90.0) a = 180.0 - a;     cout.setf(ios::fixed);     cout.precision(10);     if (a < eps) {       cout << w * h;       return 0;     }     a /= 180.0;     a *= pi;     double f = (1 + cos(a)) / sin(a);     double x = (h * f - w) / (f * f - 1);     double y = h - x * f;     if (x >= 0 && y >= 0 && y <= h + eps && x <= w + eps) {       double ans = w * h;       ans -= x * x / tan(a);       ans -= y * y / tan(a);       cout << ans;     } else {       if (w < h) swap(w, h);       cout << h * h / sin(a);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5000 + 10;   char s[N], t[N];   int n, m, dp[N][N];   int main() {     scanf( %d%d%s%s , &n, &m, s + 1, t + 1);     int ans = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         dp[i][j] = 0;         if (i >= 1) dp[i][j] = max(dp[i][j], dp[i - 1][j] - 1);         if (j >= 1) dp[i][j] = max(dp[i][j], dp[i][j - 1] - 1);         if (i >= 1 && j >= 1 && s[i] == t[j])           dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 2);         ans = max(ans, dp[i][j]);       }     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int in() {     int x;     scanf( %d , &x);     return x;   }   long long lin() {     long long x;     scanf( %lld , &x);     return x;   }   int x[200010];   int main() {     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; ++i) a[i] = in();     int s = 0;     for (int i = 0; i < n; ++i) {       if (s <= 1) {         x[s++] = a[i];       } else if (x[s - 2] == x[s - 1] && x[s - 1] <= a[i]) {         s -= 2;         x[s++] = a[i];       } else if (x[s - 1] == a[i] && a[i] <= x[s - 2]) {         s -= 1;       } else {         x[s++] = a[i];       }     }     if (s <= 1 || (s == 2 && x[0] == x[1])) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double max(double a, double b) {     if (a >= b)       return a;     else       return b;   }   int main() {     double m[5], s, u;     for (int i = 0; i < 5; i++) cin >> m[i];     double sum = 0, sum1;     for (int i = 0; i < 5; i++) {       sum1 = 0;       double x;       cin >> x;       sum1 += ((250 - m[i]) / 250.0) * (500) * float(i + 1);       sum1 -= 50 * x;       sum += max(sum1, double(0.3 * double(i + 1) * 500.0));     }     cin >> s >> u;     cout << sum + 100 * s - 50 * u;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxlongint = 2147483647;   const int P1 = 19260817, P2 = 1000000007, N = 100011, M = 1000011;   long long mi1[M], mi2[M], ni1[M], ni2[M], s1[M], s2[M];   char st[M], Ans[M];   long long powder(int x, int a, const int& P) {     if (!a) return 1;     long long tot = powder(x, a >> 1, P);     tot = (tot * tot) % P;     if (a & 1) tot = (tot * x) % P;     return tot;   }   inline long long num(char ch) {     return ( 0  <= ch && ch <=  9 )                ? (ch -  0 )                : (( a  <= ch && ch <=  z ) ? (ch -  a  + 10) : (ch -  A  + 36));   }   void pre(int n) {     long long c = 62, nn1 = powder(c, P1 - 2, P1), nn2 = powder(c, P2 - 2, P2);     if (nn1 * 62 % P1 != 1 || nn2 * 62 % P2 != 1) printf( Sfsf n );     mi1[0] = 1;     for (int i = 1; i <= n; i++) {       mi1[i] = (mi1[i - 1] * c) % P1;       if (mi1[i] < 0)         while (1) mi1[-154151564];     }     mi2[0] = 1;     for (int i = 1; i <= n; i++) {       mi2[i] = (mi2[i - 1] * c) % P2;       if (mi2[i] < 0)         while (1) mi2[-134564522];     }     ni1[0] = 1;     for (int i = 1; i <= n; i++) ni1[i] = ni1[i - 1] * nn1 % P1;     ni2[0] = 1;     for (int i = 1; i <= n; i++) ni2[i] = ni2[i - 1] * nn2 % P2;   }   int main() {     pre(1000000);     int n;     scanf( %d , &n);     int totlen = 0;     for (int i = 1; i <= n; i++) {       scanf( %s , st + 1);       int l = strlen(st + 1);       int pos = 0;       long long c = 62;       long long sh1 = 0, sh2 = 0;       for (int j = 1; j <= l && j <= totlen; j++) {         sh1 = (sh1 * c + num(st[j])) % P1;         sh2 = (sh2 * c + num(st[j])) % P2;         if (sh1 < 0 || sh2 < 0)           while (1) putchar(  n );         if ((s1[totlen] - s1[totlen - j] * mi1[j] % P1 + P1) % P1 == sh1 &&             (s2[totlen] - s2[totlen - j] * mi2[j] % P2 + P2) % P2 == sh2)           pos = j;       }       for (int j = pos + 1; j <= l; j++) {         Ans[++totlen] = st[j];         s1[totlen] = (s1[totlen - 1] * c + num(Ans[totlen])) % P1;         s2[totlen] = (s2[totlen - 1] * c + num(Ans[totlen])) % P2;         if (s1[totlen] * c < 0 || s2[totlen] * c < 0)           while (1) putchar(  n );       }     }     for (int i = 1; i <= totlen; i++) putchar(Ans[i]);     fclose(stdin);     fclose(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct state {     bool win;     int first, second;     state() : win(false), first(0), second(1e9){};     state(bool nwin, int nfirst, int nsecond)         : win(nwin), first(nfirst), second(nsecond){};   };   bool operator<(state a, state b) {     return !(a.win > b.win ||              a.win == b.win && (a.first > b.first ||                                 a.first == b.first && a.second < b.second));   }   vector<string> dict;   int exist(string word) {     int res = 0;     for (vector<string>::iterator(i) = (dict).begin(); (i) < (dict).end(); ++(i))       if ((*i).find(word) != string::npos) ++res;     return res;   }   int score(string word) {     if (word ==   ) return 0;     int num = exist(word), value = 0, maxvalue = 0;     if (num == 0) return -1;     for (string::iterator(i) = (word).begin(); (i) < (word).end(); ++(i)) {       value += (*i) -  a  + 1;       maxvalue = max((*i) -  a  + 1, maxvalue);     }     return value * maxvalue + num;   }   map<string, state> d;   state find(string s) {     if (score(s) == -1) return state(false, 0, 0);     if (d.find(s) != d.end()) return d[s];     state res(false, 0, 1e9);     for (int i =  a ; i <=  z ; ++i)       res = max(res, max(find(char(i) + s), find(s + char(i))));     d[s] = state(res.win ^ 1, res.second + score(s), res.first);     return d[s];   }   int main() {     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       string s;       cin >> s;       dict.push_back(s);     }     state ans = find(  );     cout << (ans.win ?  Second n  :  First n ) << ans.second <<     << ans.first;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   char ch;   int x, y;   int dx[200001], dy[200001];   int ans;   bool check(int ans) {     if (ans > n) return true;     int i, iend = n - ans + 1;     for (i = 1; i <= iend; i++) {       int vx = dx[i - 1] + dx[n] - dx[i + ans - 1];       int vy = dy[i - 1] + dy[n] - dy[i + ans - 1];       if (abs(x - vx) + abs(y - vy) <= ans &&           !((abs(x - vx) + abs(y - vy)) & 1) ^ (ans & 1))         return true;     }     return false;   }   int main() {     cin >> n;     int i;     for (i = 1; i <= n; i++) {       cin >> ch;       dx[i] = dx[i - 1];       dy[i] = dy[i - 1];       switch (ch) {         case  U :           ++dy[i];           break;         case  D :           --dy[i];           break;         case  L :           --dx[i];           break;         case  R :           ++dx[i];           break;       }     }     cin >> x >> y;     if (n < abs(x) + abs(y) || (n & 1) ^ ((abs(x) + abs(y)) & 1)) {       cout << -1 << endl;       return 0;     }     if (dx[n] == x && dy[n] == y) {       cout << 0 << endl;       return 0;     }     for (i = 20; i >= 0; i--)       if (!check(ans | (1 << i))) ans |= 1 << i;     cout << ans + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i;     cin >> n;     int a[n];     for (i = 0; i < n; i++) cin >> a[i];     vector<int> b;     for (i = 0; i < n; i++) {       if (a[i] <= 1e6 - a[i])         b.push_back(a[i] - 1);       else         b.push_back(1e6 - a[i]);     }     sort(b.begin(), b.end());     cout << b[b.size() - 1];   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char a[150], b[150];     int c, d, e, f, g, x, y, z;     gets(a);     gets(b);     c = strlen(a);     for (x = 0; x < c; x++) {       if (a[x] >=  A  && a[x] <=  Z ) a[x] = a[x] + ( a  -  A );       if (b[x] >=  A  && b[x] <=  Z ) b[x] = b[x] + ( a  -  A );     }     if (strcmp(a, b) == 0)       cout <<  0  << endl;     else if (strcmp(a, b) > 0)       cout <<  1  << endl;     else       cout <<  -1  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAX = 1e5 + 5;   const long long inf = 1e18 + 9;   pair<long long, long long> dp[MAX];   long long p[MAX];   bool portal[MAX];   struct Edge {     long long from, to, cost;   };   long long Find(long long u) {     if (p[u] != u) p[u] = Find(p[u]);     return p[u];   }   void Union(long long u, long long v) { p[Find(u)] = Find(v); }   bool cmp(Edge e1, Edge e2) { return e1.cost < e2.cost; }   vector<Edge> E;   vector<pair<long long, long long> > P[MAX];   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, m;     cin >> n >> m;     for (long long i = 1; i <= n; i++) p[i] = i;     for (long long i = 1; i <= m; i++) {       long long a, b, c;       cin >> a >> b >> c;       P[a].push_back(make_pair(b, c));       P[b].push_back(make_pair(a, c));       E.push_back({a, b, c});     }     long long k;     cin >> k;     priority_queue<pair<long long, long long> > Q;     for (long long i = 1; i <= n; i++) dp[i] = {inf, -1};     for (long long i = 1; i <= k; i++) {       long long a;       cin >> a;       dp[a] = {0, a};       portal[a] = true;       Q.push(make_pair(-dp[a].first, a));     }     while (!Q.empty()) {       pair<long long, long long> akt = Q.top();       Q.pop();       akt.first *= -1;       if (akt.first != dp[akt.second].first) continue;       for (auto it : P[akt.second]) {         if (it.second + akt.first < dp[it.first].first) {           dp[it.first].first = it.second + akt.first;           dp[it.first].second = dp[akt.second].second;           Q.push(make_pair(-dp[it.first].first, it.first));         }       }     }     for (long long i = 0; i < E.size(); i++) {       E[i].cost += dp[E[i].from].first + dp[E[i].to].first;       E[i].from = dp[E[i].from].second;       E[i].to = dp[E[i].to].second;     }     sort(E.begin(), E.end(), cmp);     long long ans = 0;     for (auto it : E) {       if (Find(it.from) != Find(it.to)) {         Union(it.from, it.to);         ans += it.cost;       }     }     if (!portal[1]) ans += dp[1].first;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1024000000,1024000000 )   using namespace std;   const int maxn = 1e5 + 7;   int n, m;   long long h[maxn], p[maxn];   bool ok(long long x) {     long long cnt = 0;     for (int i = 0; i < n; i++) {       if (p[cnt] >= h[i]) {         for (int j = cnt; j < m; j++) {           if (h[i] + x >= p[j])             cnt++;           else             break;         }       } else {         if (h[i] - p[cnt] > x) continue;         long long t = max(x - (h[i] - p[cnt]) * 2, (x - (h[i] - p[cnt])) / 2);         for (int j = cnt; j < m; j++) {           if (h[i] + t >= p[j])             cnt++;           else             break;         }       }     }     if (cnt >= m)       return true;     else       return false;   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> h[i];     for (int i = 0; i < m; i++) cin >> p[i];     long long l = 0, r = 100000000000 + 7;     ;     while (l + 1 < r) {       long long m = (l + r) >> 1;       if (ok(m))         r = m;       else         l = m;     }     if (ok(l)) r = l;     cout << r << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 31;   int dp[MAXN][MAXN][MAXN * MAXN];   int F(int n, int m, int k) {     if (n > m) swap(n, m);     if (k < 0) return (1 << 30);     if (dp[n][m][k] != -1) return dp[n][m][k];     if (n * m == k || k == 0) return dp[n][m][k] = 0;     int p = 1 << 30, q = 1 << 30;     for (int i = 1; i < n; i++)       p = min(p, m * m + min(F(i, m, k - m * (n - i)), F(i, m, k)));     for (int i = 1; i < m; i++)       q = min(q, n * n + min(F(n, i, k - n * (m - i)), F(n, i, k)));     return dp[n][m][k] = min(p, q);   }   int main() {     int n, m, k, q;     memset(dp, -1, sizeof dp);     scanf( %d , &q);     while (q--) {       scanf( %d %d %d , &n, &m, &k);       printf( %d n , F(n, m, k));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int dir[5][2] = {0, 1, 0, -1, 1, 0, -1, 0, 0, 0};   const int inf = 0x7fffffff;   const int mod = 1000000;   const int Max = 1000000;   int temp[10], ans[Max];   void check(char *s) {     int index = 0, dec, sum = 0, cnt = 0;     dec = atoi(s);     memset(temp, 0, sizeof(temp));     for (int i = 0; i < strlen(s); ++i) sum += s[i];     for (int i = max((dec - sum), 0); i <= dec; ++i) {       int temp = i, t = i;       while (temp) {         t += (temp % 10);         temp /= 10;       }       if (t == dec) {         ans[cnt++] = i;       }     }     printf( %d n , cnt);     for (int i = 0; i < cnt; ++i) {       printf( %d%c , ans[i], i == cnt - 1 ?   n  :    );     }   }   int main() {     char num[10];     scanf( %s , num);     check(num);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     string s;     cin >> s;     int n = s.size();     if (n == 1) {       cout << 0;       return 0;     }     int ans = 0;     int co = 1;     vector<pair<char, int> > c;     for (int i = 1; i < n; i++) {       if (s[i] != s[i - 1]) {         c.emplace_back(s[i - 1], co);         co = 0;       }       co++;     }     c.emplace_back(s[n - 1], co);     int k = c.size();     if (k % 2 == 0) {       cout << 0;       return 0;     }     for (int i = 0; i < k / 2; i++) {       if ((c[i].first != c[k - 1 - i].first) ||           (c[i].second + c[k - 1 - i].second < 3)) {         cout << 0;         return 0;       }     }     if (c[k / 2].second == 1)       cout << 0 << endl;     else       cout << c[k / 2].second + 1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   int blocksize;   int msmo7;   struct query {     int start, en, idxofquery, blockidx, mincolor;     query() {}     query(int l, int r, int i, int adeh) {       start = l;       en = r;       idxofquery = i;       blockidx = l / blocksize;       mincolor = adeh;     }     bool operator<(const query& q) const {       if (start / blocksize != q.start / blocksize)         return start / blocksize < q.start / blocksize;       else         return en < q.en;     }   };   query queries[100005];   vector<int> arr[100005];   int subtree[100005];   int idxinorder[100005];   int treearray[100005];   int color[100005];   int ansforquery;   int answers[100005];   int bit[100010];   int freq[100005];   const int maxn = 1e5 + 5;   void update(int idx, int val) {     for (; idx <= maxn; idx += (idx & -idx)) bit[idx] += val;   }   int getsum(int idx) {     int sum = 0;     for (; idx; idx -= (idx & -idx)) sum += bit[idx];     return sum;   }   int nid = 0;   void dfs(int s, int parent) {     subtree[s] = 1;     treearray[nid++] = s;     idxinorder[s] = nid - 1;     for (int i = 0; i < arr[s].size(); ++i) {       int to = arr[s][i];       if (to != parent) {         dfs(to, s);         subtree[s] += subtree[to];       }     }   }   void add(int valueofpos) {     update(maxn - freq[color[valueofpos]]++, -1);     update(maxn - freq[color[valueofpos]], 1);   }   void rem(int valueofpos) {     update(maxn - freq[color[valueofpos]]--, -1);     update(maxn - freq[color[valueofpos]], 1);   }   int main() {     int n, m;     scanf( %d , &n);     scanf( %d , &m);     for (int i = 1; i <= n; ++i) scanf( %d , &color[i]);     int u, v;     for (int i = 1; i < n; ++i) {       scanf( %d , &u);       scanf( %d , &v);       arr[u].push_back(v);       arr[v].push_back(u);     }     dfs(1, -1);     blocksize = sqrt(n);     int k;     for (int i = 0; i < m; ++i) {       scanf( %d , &v);       scanf( %d , &k);       queries[i].start = idxinorder[v];       queries[i].en = queries[i].start + subtree[v] - 1;       queries[i].idxofquery = i;       queries[i].mincolor = k;     }     sort(queries, queries + m);     int curl = 0;     int curr = -1;     for (int i = 0; i < m; ++i) {       query& qu = queries[i];       while (curl > qu.start) add(treearray[--curl]);       while (curr < qu.en) add(treearray[++curr]);       while (curl < qu.start) rem(treearray[curl++]);       while (curr > qu.en) rem(treearray[curr--]);       answers[qu.idxofquery] = getsum(maxn - qu.mincolor);     }     for (int i = 0; i < m; ++i) printf( %d n , answers[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     string q;     cin >> q;     int n;     cin >> n;     vector<string> m(n);     for (int i = 0; i < (n); ++i) cin >> m[i];     sort(m.begin(), m.end());     for (int i = 0; i < (n); ++i) {       if (m[i].size() < q.size()) continue;       if (m[i].substr(0, q.size()) == q) {         cout << m[i] << endl;         return 0;       }     }     cout << q << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2.1e5;   const int MAXQ = 2.1e5;   int N, Q;   int P[MAXN];   char C[MAXN];   vector<int> ch[MAXN];   int depth[MAXN];   int compChild[MAXN];   int compPar[MAXN];   int cnts[MAXN][26];   int subVal[MAXN][26];   int tot[MAXN];   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> N >> Q;     P[1] = 0;     C[1] =  ? ;     for (int i = 2; i <= N; i++) {       cin >> P[i] >> C[i];     }     for (int i = 2; i <= N; i++) {       ch[P[i]].push_back(i);     }     depth[1] = 0;     for (int i = 2; i <= N; i++) {       depth[i] = depth[P[i]] + 1;     }     set<int> leafDepths;     for (int i = 1; i <= N; i++) {       if (ch[i].empty()) {         leafDepths.insert(depth[i]);       }     }     assert(!leafDepths.empty());     if (leafDepths.size() > 1) {       for (int q = 0; q < Q; q++) {         cout <<  Fou  <<   n ;       }       exit(0);     }     assert(leafDepths.size() == 1);     const int leafDepth = *leafDepths.begin();     for (int i = N; i >= 2; i--) {       compPar[i] = P[i];       compChild[i] = i;       if (ch[i].size() == 1) {         compChild[i] = compChild[ch[i][0]];         compPar[compChild[i]] = P[i];       }       if (C[i] !=  ? ) {         cnts[compChild[i]][C[i] -  a ]++;       }     }     compPar[1] = 0;     compChild[1] = 1;     for (int i = 1; i <= N; i++) {       for (auto& c : ch[i]) {         c = compChild[c];       }     }     int numBad = 0;     for (int i = N; i >= 1; i--) {       if (compChild[i] != i) continue;       for (int v = 0; v < 26; v++) {         subVal[i][v] = 0;       }       for (int j : ch[i]) {         for (int v = 0; v < 26; v++) {           subVal[i][v] = max(subVal[i][v], cnts[j][v] + subVal[j][v]);         }       }       tot[i] = 0;       for (int v = 0; v < 26; v++) {         tot[i] += subVal[i][v];       }       if (tot[i] + depth[i] > leafDepth) {         numBad++;       }     }     for (int i = 1; i <= N; i++) {     }     for (int q = 0; q < Q; q++) {       int ind;       char c;       cin >> ind >> c;       if (C[ind] !=  ? ) {         int v = C[ind] -  a ;         cnts[compChild[ind]][v]--;         for (int i = compPar[compChild[ind]]; i != 0; i = compPar[i]) {           assert(compChild[i] == i);           if (tot[i] + depth[i] > leafDepth) {             numBad--;           }           tot[i] -= subVal[i][v];           subVal[i][v] = 0;           for (int j : ch[i]) {             subVal[i][v] = max(subVal[i][v], cnts[j][v] + subVal[j][v]);           }           tot[i] += subVal[i][v];           if (tot[i] + depth[i] > leafDepth) {             numBad++;           }         }       }       C[ind] = c;       if (C[ind] !=  ? ) {         int v = C[ind] -  a ;         cnts[compChild[ind]][v]++;         for (int i = compPar[compChild[ind]]; i != 0; i = compPar[i]) {           assert(compChild[i] == i);           if (tot[i] + depth[i] > leafDepth) {             numBad--;           }           tot[i] -= subVal[i][v];           subVal[i][v] = 0;           for (int j : ch[i]) {             subVal[i][v] = max(subVal[i][v], cnts[j][v] + subVal[j][v]);           }           tot[i] += subVal[i][v];           if (tot[i] + depth[i] > leafDepth) {             numBad++;           }         }       }       if (numBad) {         cout <<  Fou  <<   n ;       } else {         long long res = 0;         for (int v = 0; v < 26; v++) {           res += 1ll * ((leafDepth - tot[1]) + subVal[1][v]) * (v + 1);         }         cout <<  Shi  <<     << res <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int n, u, v;   vector<int> arr[100001];   long double ans = 0.0;   long long int siz[100001]{0};   void dfs(int to, int from, int val) {     int ret = 1;     ans += 1.0 / val;     for (auto i : arr[to]) {       if (i != from) {         dfs(i, to, val + 1);         siz[to] += siz[i];       }     }   }   void pre() {}   void solve() {     cin >> n;     for (int i = 0; i < n - 1; i++) {       cin >> u >> v;       arr[u].push_back(v);       arr[v].push_back(u);     }     dfs(1, 0, 1);     cout << setprecision(26) << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     pre();     solve();   }


#include <bits/stdc++.h>   using namespace std;   struct node {     long long v, p, id;   } t[2000001];   bool cmp2(node a, node b) { return a.p < b.p; }   struct cmp {     bool operator()(node a, node b) { return a.v > b.v; }   };   priority_queue<node, vector<node>, cmp> q;   priority_queue<long long> q2;   long long vis[2000001];   signed main() {     long long T;     scanf( %I64d , &T);     while (T--) {       long long n;       scanf( %I64d , &n);       for (long long i = 1; i <= n; i++) vis[i] = 0;       while (!q.empty()) q.pop();       while (!q2.empty()) q2.pop();       for (long long i = 1; i <= n; i++) {         scanf( %I64d%I64d , &t[i].p, &t[i].v);         t[i].id = i;         q.push(t[i]);       }       sort(t + 1, t + n + 1, cmp2);       long long cur = 0, ans = 0;       for (long long i = 1; i <= n; i++) {         while (cur != n && cur < t[i].p) {           while (vis[q.top().id] == 1) q.pop();           if (q2.size()) {             ans += q.top().v - q2.top();             q2.pop();             vis[q.top().id] = 1;             q.pop();           } else {             ans += q.top().v;             vis[q.top().id] = 1;             q.pop();           }           cur++;         }         if (cur == n) break;         if (vis[t[i].id])           q2.push(t[i].v);         else           ++cur;         vis[t[i].id] = 1;       }       printf( %I64d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mn = 1000001;   bool shirt(int p, int s) {     int i = (s / 50) % 475;     for (int j = 0; j < 25; j++) {       i = (i * 96 + 42) % 475;       if ((26 + i) == p) return true;     }     return false;   }   int main() {     int p, x, y;     cin >> p >> x >> y;     int al = 0, temp = x;     while (1 && temp >= y) {       if (shirt(p, temp)) {         cout << 0 << endl;         return 0;       }       temp -= 50;     }     int ah = 0;     temp = x;     while (1) {       if (shirt(p, temp)) break;       if ((temp - 50) >= y) {         if (shirt(p, temp - 50)) break;       }       temp += 100;       ah++;     }     int v = temp - x;     int ans = v / 100;     cout << ah << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long solve() {     string x[12] = { C ,   C# ,  D ,   D# ,  E ,  F ,                      F# ,  G ,   G# ,  A ,   B ,  H };     map<string, long long> m;     for (long long i = 0; i < 12; ++i) {       m[x[i]] = i;     }     long long q[3];     string a, b, c;     cin >> a >> b >> c;     q[0] = m[a];     q[1] = m[b];     q[2] = m[c];     sort(q, q + 3);     do {       if ((q[0] + 4) % 12 == q[1] % 12 && (q[1] + 3) % 12 == q[2] % 12) {         cout <<  major ;         return 0;       }       if ((q[0] + 3) % 12 == q[1] % 12 && (q[1] + 4) % 12 == q[2] % 12) {         cout <<  minor ;         return 0;       }     } while (next_permutation(q, q + 3));     cout <<  strange ;   }   signed main() {     ios::sync_with_stdio(false);     long long t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int grid[2500][2500];   int s[2500 + 1][2500 + 1];   char str[2500 + 10];   long long result = 0;   char *trim_line(char *str) { return strtok(str,   r n ); }   long long mul_ll(long long x, long long y) { return x * y; }   int count_ones(int lx, int ly, int rx, int ry) {     return s[rx + 1][ry + 1] - s[lx][ry + 1] - s[rx + 1][ly] + s[lx][ly];   }   void process_x_left(int lx, int ly, int rx, int ry, int k, int *left,                       bool omg) {     int end = rx;     left[0] = end;     for (int i = 1; i <= k + 1; i++) {       int start = omg ? left[i] : (lx - 1);       while (start < end) {         int mid = start + (end - start + 1) / 2;         int nr = count_ones(mid, ly, rx, ry);         if (nr >= i) {           start = mid;         } else {           end = mid - 1;         }       }       left[i] = start;     }   }   void process_x_right(int lx, int ly, int rx, int ry, int k, int *right,                        bool omg) {     int start = lx;     right[0] = start;     for (int i = 1; i <= k + 1; i++) {       int end = omg ? right[i] : (rx + 1);       int j = i + s[lx][ry + 1] - s[lx][ly];       while (start < end) {         int mid = start + (end - start) / 2;         int nr = s[mid + 1][ry + 1] - s[mid + 1][ly];         if (nr >= j) {           end = mid;         } else {           start = mid + 1;         }       }       right[i] = start;     }   }   void process_y_left(int lx, int ly, int rx, int ry, int k, int *left) {     int end = ry;     left[0] = end;     for (int i = 1; i <= k + 1; i++) {       int start = ly - 1;       while (start < end) {         int mid = start + (end - start + 1) / 2;         int nr = count_ones(lx, mid, rx, ry);         if (nr >= i) {           start = mid;         } else {           end = mid - 1;         }       }       left[i] = start;     }     for (int i = 0; i <= k; i++) left[i] -= left[i + 1];   }   void process_y_right(int lx, int ly, int rx, int ry, int k, int *right) {     int start = ly;     right[0] = start;     for (int i = 1; i <= k + 1; i++) {       int end = ry + 1;       while (start < end) {         int mid = start + (end - start) / 2;         int nr = count_ones(lx, ly, rx, mid);         if (nr >= i) {           end = mid;         } else {           start = mid + 1;         }       }       right[i] = start;     }     for (int i = 0; i <= k; i++) right[i] = right[i + 1] - right[i];   }   void kdtree(int lx, int ly, int rx, int ry, int k) {     int left[6 + 2];     int right[6 + 2];     int dx = rx - lx;     int dy = ry - ly;     if (dx >= dy) {       if (dy == 0) {         map<int, int> cnt;         cnt[0] = 1;         for (int i = lx; i <= rx; i++) {           int nr = count_ones(lx, ly, i, ry);           if (nr >= k) result += cnt[nr - k];           ++cnt[nr];         }       } else {         int mx = lx + (rx - lx) / 2;         for (int i = ly; i <= ry; i++)           for (int j = i; j <= ry; j++) {             process_x_left(lx, i, mx, j, k, left, (i < j));             process_x_right(mx + 1, i, rx, j, k, right, (i < j));             for (int l = 0; l <= k; l++) {               int a = left[l] - left[l + 1];               int b = right[k - l + 1] - right[k - l];               result += a * b;             }           }         kdtree(lx, ly, mx, ry, k);         kdtree(mx + 1, ly, rx, ry, k);       }     } else {       if (dx == 0) {         map<int, int> cnt;         cnt[0] = 1;         for (int i = ly; i <= ry; i++) {           int nr = count_ones(lx, ly, rx, i);           if (nr >= k) result += cnt[nr - k];           ++cnt[nr];         }       } else {         int my = ly + (ry - ly) / 2;         for (int i = lx; i <= rx; i++)           for (int j = i; j <= rx; j++) {             process_y_left(i, ly, j, my, k, left);             process_y_right(i, my + 1, j, ry, k, right);             for (int l = 0; l <= k; l++) result += left[l] * right[k - l];           }         kdtree(lx, ly, rx, my, k);         kdtree(lx, my + 1, rx, ry, k);       }     }   }   int solve_problem() {     int n, m, k;     if (fgets(str, sizeof(str), stdin) == NULL) return 1;     n = atoi(strtok(str,    ));     m = atoi(strtok(NULL,    ));     k = atoi(strtok(NULL,    ));     for (int i = 0; i < n; i++) {       if (fgets(str, sizeof(str), stdin) == NULL) return 1;       for (int j = 0; j < m; j++) grid[i][j] = str[j] -  0 ;     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) s[i + 1][j + 1] = s[i + 1][j] + grid[i][j];       for (int j = 0; j < m; j++) s[i + 1][j + 1] += s[i][j + 1];     }     kdtree(0, 0, n - 1, m - 1, k);     cout << result << endl;     return 0;   }   int main() {     solve_problem();     return 0;   }