#include <bits/stdc++.h>   using namespace std;   int N, M;   int A[200], B[200], D[200];   map<int, vector<int>> MM;   set<int> S;   struct mat {     signed long long v[150][3] = {};   };   struct vec {     signed long long v[3] = {};   };   void print(mat a, int n) {     int x, y;     for (x = 0; x < n; x++) {       (void)printf( %d:  , x);       for (y = 0; y < n; y++)         (void)printf( %d , (a.v[x][y / 64] & (1LL << (y % 64))) != 0);       (void)printf(  n );     }   }   void print(vec a, int n) {     int i;     for (i = 0; i < n; i++)       (void)printf( %d , (a.v[i / 64] & (1LL << (i % 64))) != 0);     (void)printf(  n );   }   mat mult(mat a, mat b, int n) {     mat c, d;     int x, y, z;     for (x = 0; x < n; x++)       for (y = 0; y < n; y++)         if (b.v[y][x / 64] & (1LL << (x % 64))) c.v[x][y / 64] |= 1LL << (y % 64);     for (x = 0; x < n; x++)       for (y = 0; y < n; y++) {         signed long long v = 0;         for (z = 0; z < (n + 63) / 64; z++) v |= a.v[x][z] & c.v[y][z];         v = (v != 0);         d.v[x][y / 64] |= v << (y % 64);       }     return d;   }   mat init(int n) {     mat r;     int x;     for (x = 0; x < n; x++) r.v[x][x / 64] |= 1LL << (x % 64);     return r;   }   mat powm(mat a, int p, int n) {     mat r = init(n);     while (p) {       if (p % 2) r = mult(r, a, n);       a = mult(a, a, n);       p /= 2;     }     return r;   }   vec mult(mat a, vec b, int n) {     vec c;     int x, y;     for (x = 0; x < n; x++)       if (b.v[x / 64] & (1LL << (x % 64)))         for (y = 0; y < (n + 63) / 64; y++) c.v[y] |= a.v[x][y];     return c;   }   bool reachable(mat a, vec b) {     int x, y;     for (x = 0; x < 150; x++) {       vec c = mult(a, b, N);       b.v[0] |= c.v[0];       b.v[1] |= c.v[1];       b.v[2] |= c.v[2];     }     int n = N - 1;     return (b.v[n / 64] & (1LL << (n % 64))) != 0;   }   void solve() {     int i, j, k, l, r, x, y;     string s;     cin >> N >> M;     for (i = 0; i < M; i++) {       cin >> A[i] >> B[i] >> D[i];       A[i]--;       B[i]--;       MM[D[i]].push_back(i);       S.insert(D[i]);     }     int cur = 0;     vec v;     mat m;     v.v[0] = 1;     for (auto& r : MM) {       v = mult(powm(m, r.first - cur, N), v, N);       cur = r.first;       for (auto& r2 : r.second) m.v[A[r2]][B[r2] / 64] |= 1LL << (B[r2] % 64);       if (reachable(m, v)) break;     }     if (!reachable(m, v)) return (void)printf( Impossible n );     int n = N - 1;     while ((v.v[n / 64] & (1LL << (n % 64))) == 0) {       v = mult(m, v, N);       cur++;       if (S.count(cur))         for (auto& r2 : MM[cur]) m.v[A[r2]][B[r2] / 64] |= 1LL << (B[r2] % 64);     }     cout << cur << endl;   }   int main(int argc, char** argv) {     string s;     int i;     if (argc == 1) ios::sync_with_stdio(false);     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;   bool isPrime(long long int n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     long long int p = sqrt(n);     for (int i = 5; i <= p; i += 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   string d2b(int n) {     string s;     for (int i = 31; i >= 0; i--) {       int k = n >> i;       if (k & 1)         s +=  1 ;       else         s +=  0 ;     }     return s;   }   long long int gcd(long long int a, long long int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long int lcm(long long int a, long long int b) {     return (a * b) / gcd(a, b);   }   long long int b2d(string n) {     string num = n;     long long int dec_value = 0;     long long int base = 1;     long long int len = num.length();     for (int i = len - 1; i >= 0; i--) {       if (num[i] ==  1 ) dec_value += base;       base = base * 2;     }     return dec_value;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int test_case = 1;     cin >> test_case;     while (test_case--) {       int n, k;       cin >> n >> k;       int a[n];       for (long long i = 0; i < n; i++) cin >> a[i];       sort(a, a + n);       for (long long i = 1; i < n; i++) {         a[i] = k - a[i];       }       int temp = a[0];       for (long long i = 1; i < n; i++) {         a[i] = a[i] / temp;       }       int s = 0;       for (long long i = 1; i < n; i++) s += a[i];       cout << s << endl;     }   }


#include <bits/stdc++.h>   int *ej[100000], eo[100000];   long long *ew[100000];   void append(int i, int j, long long w) {     int o = eo[i]++;     if (o >= 2 && (o & o - 1) == 0) {       ej[i] = (int *)realloc(ej[i], o * 2 * sizeof *ej[i]);       ew[i] = (long long *)realloc(ew[i], o * 2 * sizeof *ew[i]);     }     ej[i][o] = j, ew[i][o] = w;   }   long long bb[60], b_;   int sz;   void add(long long b) {     int l;     b_ |= b;     for (l = 0; l < 60; l++)       if (b & 1LL << l) {         if (bb[l] & 1LL << l)           b ^= bb[l];         else {           bb[l] = b, sz++;           return;         }       }   }   long long xx[100000];   char visited[100000];   int kk[60], cnt;   void dfs(int p, int i, long long x) {     int o, l;     if (visited[i]) {       add(xx[i] ^ x);       return;     }     xx[i] = x, visited[i] = 1, cnt++;     for (l = 0; l < 60; l++)       if (x & 1LL << l) kk[l]++;     for (o = eo[i]; o--;) {       int j = ej[i][o];       long long w = ew[i][o];       if (j != p) dfs(i, j, x ^ w);     }   }   int main() {     int n, m, i, j, ans;     scanf( %d%d , &n, &m);     for (i = 0; i < n; i++) {       ej[i] = (int *)malloc(2 * sizeof *ej[i]);       ew[i] = (long long *)malloc(2 * sizeof *ew[i]);     }     while (m--) {       long long w;       scanf( %d%d%lld , &i, &j, &w), i--, j--;       append(i, j, w), append(j, i, w);     }     ans = 0;     for (i = 0; i < n; i++)       if (!visited[i]) {         int l, p;         memset(bb, 0, 60 * sizeof *bb), b_ = 0, sz = 0;         memset(kk, 0, 60 * sizeof *kk);         cnt = 0;         dfs(-1, i, 0);         p = 1;         for (l = 0; l < 60; l++) {           int k;           if (b_ & 1LL << l)             k = (long long)cnt * (cnt - 1) / 2 % 1000000007 *                 ((1LL << sz - 1) % 1000000007) % 1000000007;           else             k = (long long)kk[l] * (cnt - kk[l]) % 1000000007 *                 ((1LL << sz) % 1000000007) % 1000000007;           ans = (ans + (long long)k * p) % 1000000007;           p = p * 2 % 1000000007;         }       }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T min(T a, T b, T c) {     return min(a, min(b, c));   }   template <class T>   T min(T a, T b, T c, T d) {     return min(a, min(b, min(c, d)));   }   template <class T>   T max(T a, T b, T c) {     return max(a, max(b, c));   }   template <class T>   T max(T a, T b, T c, T d) {     return max(a, max(b, max(c, d)));   }   bool cmp(const pair<int, int>& a, const pair<int, int>& b) {     return (a.first > b.first || (a.first == b.first && a.second >= b.second));   }   long long GCD(long long a, long long b) { return (a % b) ? GCD(b, a % b) : b; }   int f[7][100007];   int main() {     int n, a, b, c;     scanf( %d%d%d%d , &n, &a, &b, &c);     --n;     f[0][0] = 0;     f[1][0] = f[2][0] = 1000000000LL;     for (int i = (1); i <= (n); ++i) {       f[0][i] = min(f[2][i - 1] + b, f[1][i - 1] + a);       f[1][i] = min(f[2][i - 1] + c, f[0][i - 1] + a);       f[2][i] = min(f[1][i - 1] + c, f[0][i - 1] + b);     }     cout << min(f[0][n], f[1][n], f[2][n]) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false), cin.tie(NULL);     long long tests = 1;     cin >> tests;     while (tests--) {       long long n, k;       cin >> n >> k;       map<pair<long long, long long>, long long> timers;       set<pair<long long, long long> > bombsx, bombsy;       for (long long i = 1; i <= n; ++i) {         long long x, y, t;         cin >> x >> y >> t;         bombsx.insert({x, y});         bombsy.insert({y, x});         timers[{x, y}] = t;       }       vector<long long> min_time;       queue<pair<long long, long long> > nodes;       while (bombsx.size()) {         auto itr = bombsx.begin();         long long min_timer = timers[{itr->first, itr->second}];         nodes.push({itr->first, itr->second});         bombsx.erase({itr->first, itr->second});         bombsy.erase({itr->second, itr->first});         while (nodes.size()) {           long long x = nodes.front().first, y = nodes.front().second;           nodes.pop();           itr = bombsx.lower_bound({x, y - k});           while (itr != bombsx.end() and itr->first == x and                  abs(itr->second - y) <= k) {             min_timer = min(min_timer, timers[{itr->first, itr->second}]);             auto aux = itr;             itr++;             nodes.push({aux->first, aux->second});             bombsx.erase({aux->first, aux->second});             bombsy.erase({aux->second, aux->first});           }           itr = bombsy.lower_bound({y, x - k});           while (itr != bombsy.end() and itr->first == y and                  abs(itr->second - x) <= k) {             min_timer = min(min_timer, timers[{itr->second, itr->first}]);             auto aux = itr;             itr++;             nodes.push({aux->second, aux->first});             bombsy.erase({aux->first, aux->second});             bombsx.erase({aux->second, aux->first});           }         }         min_time.push_back(min_timer);       }       sort(min_time.begin(), min_time.end());       long long ans = min_time.size() - 1;       n = min_time.size();       for (long long i = 0; i < n; ++i) {         ans = min(ans, max(min_time[i], n - 2ll - i));       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-9;   const double PI = acos(-1.0);   const long long int mod = 1e9 + 7;   const int MAXN = 1e6 + 5;   void cp() {     int n, k;     string s;     cin >> n >> k >> s;     vector<pair<int, int> > group;     int l = 0, r = 0;     while (l < n) {       while (l < n && s[l] ==  L ) l++;       if (l >= n) break;       r = l;       while (r + 1 < n && s[r + 1] ==  W ) r++;       group.push_back({l, r});       l = r + 1;     }     vector<pair<int, int> > diff;     for (int i = 0; i < ((int)group.size()) - 1; i++) {       int d = group[i + 1].first - group[i].second - 1;       diff.push_back({d, i});     }     sort(diff.rbegin(), diff.rend());     while (k > 0 && !diff.empty()) {       pair<int, int> last = diff.back();       diff.pop_back();       int can = min(last.first, k);       k -= can;       for (int i = group[last.second].second + 1;            i < group[last.second + 1].first && can > 0; i++, can--)         s[i] =  W ;     }     if (k > 0) {       int pos = -2;       for (int i = 0; i < n; i++)         if (s[i] ==  W ) pos = i;       pos++;       if (pos >= 0 && pos < n)         for (int i = pos; i < n && k > 0; i++)           if (s[i] ==  L ) s[i] =  W , k--;     }     if (k > 0 && s[0] ==  L ) {       int pos = n;       for (int i = 0; i < n && pos == n; i++)         if (s[i] ==  W ) pos = i;       pos--;       if (pos >= 0) {         for (int i = pos; i >= 0 && k > 0; i--)           if (s[i] ==  L ) s[i] =  W , k--;       }     }     int score = 0;     for (int i = 0; i < n; i++) {       score += (s[i] ==  W );       if (i - 1 >= 0 && s[i] ==  W  && s[i - 1] ==  W ) score++;     }     cout << score <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int t;     t = 1;     cin >> t;     while (t--) {       cp();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   const int inf = 1e9 + 9;   const long long int MOD = 1e9 + 696969;   const long long INF = 4LL * 1000000LL * 1000000LL * 1000000LL;   template <class T>   int size(T &&x) {     return int(x.size());   }   template <class A, class B>   ostream &operator<<(ostream &out, const pair<A, B> &p) {     return out <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <class T>   auto operator<<(ostream &out, T &&x) -> decltype(x.begin(), out) {     out <<  { ;     for (auto it = x.begin(); it != x.end(); ++it)       out << *it << (it == prev(x.end()) ?    :  ,  );     return out <<  } ;   }   void dump() {}   template <class T, class... Args>   void dump(T &&x, Args... args) {     cerr << x <<  ;   ;     dump(args...);   }   mt19937_64 rng(0);   int random(int l, int r) { return uniform_int_distribution<int>(l, r)(rng); }   inline void addmod(int &x, int val) {     x += val;     while (x >= mod) x -= mod;   }   const int maxn = 300100;   int dr[maxn];   int n, m, tab[maxn];   int N;   int temp[maxn];   inline void add(int p, int val) {     for (; p <= n; p += p & (-p)) dr[p] += val;   }   inline int get(int p) {     if (p == 0) return 0;     int res = 0;     for (; p > 0; p -= p & (-p)) res += dr[p];     return res;   }   map<long long, long long> M;   vector<pair<int, int> > skal;   int cnt = 0;   long long inversions(int base) {     if (M.find(base) != M.end()) return M[base];     skal.resize(n);     ++cnt;     for (int i = (1); i <= (n); ++i) skal[i - 1] = make_pair(tab[i] ^ base, i);     sort(skal.begin(), skal.end());     for (int i = 0; i < n; ++i) temp[skal[i].second] = i + 1;     long long res = 0;     fill(dr, dr + n + 1, 0);     for (int i = n; i > 0; --i) {       res += get(temp[i]);       add(temp[i], 1);     }     M[base] = res;     return res;   }   void solveone() {     cin >> n;     for (int i = (1); i <= (n); ++i) {       cin >> tab[i];     }     int b = 0;     for (int bit = 29; bit >= 0; --bit) {       if (inversions(b) > inversions(b + (1 << bit))) b += (1 << bit);     }     cout << inversions(b) <<     << b <<   n ;   }   int main() {     {       ios_base::sync_with_stdio(false);       cin.tie(0);       cout.tie(0);     };     int tests;     tests = 1;     for (int _ = (1); _ <= (tests); ++_) solveone();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, k, mp;     cin >> n >> m >> k;     mp = n / 2 + 1;     if (n % 2 == 0 || mp > m) {       cout << 0;       return 0;     }     int ans = 0, i, a[10005];     for (i = 0; i < n; i++) cin >> a[i];     int min = a[0];     for (i = 0; i < n; i++)       if (i % 2 == 0)         if (a[i] < min) min = a[i];     for (i = 0; i < k; i++) {       int num = m / mp;       if (min == 0) break;       if (num <= min) {         min -= num;         ans += num;       } else {         ans += min;         min = 0;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool is_Palindrome(string s) {     long long int n = s.size();     for (long long int i = 0; i < n / 2; i++) {       if (s[i] != s[n - i - 1]) {         return 0;       }     }     return 1;   }   void solve() {     string a;     cin >> a;     long long int n = a.size();     if (is_Palindrome(a)) {       cout << 0 << endl;       return;     }     cout << 3 << endl;     cout <<  L           <<     << 2 << endl          <<  R           <<     << 2 << endl          <<  R           <<     << (2 * n - 1);   }   void testcase() {     int t;     cin >> t;     while (t--) {       solve();     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve();   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int a, b;     cin >> a >> b;     long long int c = 0;     if (a % b == 0) cout << 0 << endl;     if (a % b != 0) {       long long int ans = b - (a % b);       cout << ans << endl;     }   }   int main() {     int t;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1000000007;   void solve() {     string s;     cin >> s;     long long ans = INT_MAX;     for (long long i = 0; i <= 9; i++) {       long long count = 0;       for (long long j = 0; j < (long long)s.size(); j++) {         if (s[j] == (char)( 0  + i)) count++;       }       ans = min(ans, (long long)s.size() - count);     }     if (ans == 0) {       cout << 0 << endl;       return;     }     for (long long i = 0; i <= 9; i++) {       for (long long j = 0; j <= 9; j++) {         string temp;         if (i == j) continue;         temp += (char)( 0  + i);         temp += (char)( 0  + j);         long long count = 0;         long long n = (long long)s.size();         long long curr = 0;         for (long long k = 0; k < n; k++) {           if (s[k] == temp[curr]) {             if (curr == 1) {               count++;             }             curr = (curr + 1) % 2;           }         }         ans = min(ans, (long long)s.size() - 2 * count);       }     }     cout << ans << endl;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <iostream>   #include <string>   #include <vector>   #include <algorithm>   #include <queue>   #include <deque>   #include <bitset>   #include <iterator>   #include <list>   #include <stack>   #include <map>   #include <set>   #include <math.h>   #include <stdio.h>   #include <string.h>   #include <stdlib.h>   #include <climits>   #include <iterator>   using namespace std;       typedef long long ll;   const ll mod=1e9+7;   const ll N=2e5+1;   const ll INF=1e10;       vector<vector<int>> adj(N);   vector<bool> visited(N);   vector<int> parent(N),root(N);   pair<int,int> backedge;      void dfs(int cur){    visited[cur]=true;    for(int next:adj[cur]){     if(!visited[next]){      parent[next]=cur;      dfs(next);     }     else if(parent[cur]!=next) backedge={cur,next};    }   }      void solve(){    map<int,int> subtree;    int n;    cin>>n;    for(int i=0;i<n;i++){     int u,v;     cin>>u>>v;     adj[u].push_back(v);     adj[v].push_back(u);    }    dfs(1);    //cout<<backedge.first<<   <<backedge.second<<  n ;/*    for(int i=0;i<adj[backedge.first].size();i++){     if(adj[backedge.first][i]==backedge.second){      adj[backedge.first][i]=adj[backedge.first].back();      adj[backedge.first].pop_back();      //cout<< done ;      break;     }    }    for(int i=0;i<adj[backedge.second].size();i++){     if(adj[backedge.second][i]==backedge.first){      adj[backedge.second][i]=adj[backedge.second].back();      adj[backedge.second].pop_back();      //cout<< done ;      break;     }    }    //cout<< done ;/*    for(int i=1;i<=n;i++) parent[i]=-1,visited[i]=false;    parent[backedge.first]=0;    dfs(backedge.first);    for(int i=1;i<=n;i++) visited[i]=false;    queue<int> q;    q.push(backedge.second);    root[backedge.second]=backedge.second;    visited[q.back()]=true;    while(parent[q.back()]){     //cout<<q.back()<<   ;     visited[parent[q.back()]]=true;     q.push(parent[q.back()]);     root[q.back()]=q.back();    }    visited[backedge.first]=true;    root[backedge.first]=backedge.first;    ll c=q.size();    while(!q.empty()){     int t=q.front();     q.pop();     for(int i:adj[t]){      if(!visited[i]){       root[i]=root[t];       subtree[root[i]]++;       visited[i]=true;       q.push(i);      }     }    }    //for(auto i:subtree) cout<<i.first<<   <<i.second<<  n ;    ll ans1=0,ans2=0,sum=0;    for(auto i:subtree){     ans1+=(ll)i.second*(i.second+1)/2;     ans2+=i.second*sum;     sum+=i.second;    }    ans1+=2*ans2+2*(c-1)*(n-c)+c*(c-1);    cout<<ans1<<  n ;    for(int i=1;i<=n;i++){     adj[i].clear();     visited[i]=false;     parent[i]=0;    }   }      int main(){    ios_base::sync_with_stdio(0);    cin.tie(NULL);    int t;    cin>>t;    while(t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, ans = 0;     cin >> n >> m;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         int a, b;         cin >> a >> b;         ;         if (a == 1 || b == 1) ans++;       }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, l, r, cnt;   long long ans;   char s[101][10005];   int dfs(int x, int y, int d) {     if (x == n - 1) return 1;     if (s[x + 1][y] ==  . ) {       l = y;       r = y;       ans++;       cnt = 0;       return dfs(x + 1, y, d);     }     if (s[x][y + d] ==  . ) {       ans++;       r = max(r, y + d);       l = min(l, y + d);       return dfs(x, y + d, d);     } else if (s[x][y + d] ==  # ) {       if (cnt > 2 * m) return 0;       ans += 1;       cnt++;       if (d == 1) {         ans += y - l;         r = y;         return dfs(x, l, -1);       } else {         ans += r - y;         l = y;         return dfs(x, r, 1);       }     } else {       s[x][y + d] =  . ;       ans++;       if (d == 1) {         ans += y - l;         r = y + 1;         return dfs(x, l, -1);       } else {         ans += r - y;         l = y - 1;         return dfs(x, r, 1);       }     }   }   int main() {     int i, j, k, t;     while (~scanf( %d%d , &n, &m)) {       m++;       for (i = 0; i < n; i++) scanf( %s , s[i] + 1), s[i][0] = s[i][m] =  # ;       l = r = 1;       ans = 0;       j = dfs(0, 1, 1);       if (j)         printf( %I64d n , ans);       else         puts( Never );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int arr[3];     cin >> arr[0] >> arr[1] >> arr[2];     sort(arr, arr + 3);     int d = arr[1] - arr[0];     d += arr[2] - arr[1];     cout << d;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int in() {     int res = 0;     char c;     int f = 1;     while ((c = getchar()) <  0  || c >  9 )       if (c ==  - ) f = -1;     while (c >=  0  && c <=  9 ) res = res * 10 + c -  0 , c = getchar();     return res * f;   }   const int N = 100010;   long long num[N], rd[N];   long long ans;   pair<int, int> a[N << 1];   int main() {     int n = in(), m = in();     for (int i = 1; i <= n; i++) {       num[i] = 1;     }     for (int i = 0; i < m; i++) {       a[i].first = in();       a[i].second = in();     }     sort(a, a + m);     for (int i = 0; i < m; i++) {       int x = a[i].first, y = a[i].second;       if (x > y) {         num[x] = max(num[x], num[y] + 1);       } else {         num[y] = max(num[y], num[x] + 1);       }       rd[x]++;       rd[y]++;     }     for (int i = 1; i <= n; i++) {       ans = max(ans, 1LL * num[i] * rd[i]);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long Cross(int x1, int y1, int x2, int y2) {     return 1ll * x1 * y2 - 1ll * x2 * y1;   }   int main() {     int xa, xb, xc, ya, yb, yc;     scanf( %d%d%d%d%d%d , &xa, &ya, &xb, &yb, &xc, &yc);     long long cross = Cross(xb - xa, yb - ya, xc - xa, yc - ya);     if (cross == 0)       printf( TOWARDS n );     else if (cross > 0)       printf( LEFT n );     else       printf( RIGHT n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool SR(int &_x) { return scanf( %d , &_x) == 1; }   bool SR(long long &_x) { return scanf( %lld , &_x) == 1; }   bool SR(double &_x) { return scanf( %lf , &_x) == 1; }   bool SR(char *_s) { return scanf( %s , _s) == 1; }   bool RI() { return true; }   template <typename I, typename... T>   bool RI(I &_x, T &..._tail) {     return SR(_x) && RI(_tail...);   }   void SP(const int _x) { printf( %d , _x); }   void SP(const long long _x) { printf( %lld , _x); }   void SP(const double _x) { printf( %.16lf , _x); }   void SP(const char *s) { printf( %s , s); }   void PL() { puts(  ); }   template <typename I, typename... T>   void PL(const I _x, const T... _tail) {     SP(_x);     if (sizeof...(_tail)) putchar(   );     PL(_tail...);   }   const int maxn = 5e5 + 5;   int n, x[maxn], y[maxn];   void read() {     RI(n);     for (int i = (1); i <= int(n); i++) {       int a, b;       RI(x[i], y[i], a, b);     }   }   int c[maxn];   void build() {     for (int i = (1); i <= int(n); i++) {       c[i] = 1 + (x[i] & 1) * 2 + (y[i] & 1);     }   }   void sol() {     PL( YES );     for (int i = (1); i <= int(n); i++) PL(c[i]);   }   int main() {     read();     build();     sol();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> V;   vector<int> E[200005];   int d[200005];   int p[200005];   int find(int x) {     while (p[x] != x) p[x] = p[p[x]], x = p[x];     return x;   }   int rnk[200005];   void meld(int x, int y) {     x = find(x), y = find(y);     if (rnk[x] > rnk[y]) swap(x, y);     p[x] = y;     rnk[y] = rnk[x] == rnk[y] ? rnk[y] + 1 : rnk[y];   }   int s, t;   void build() {     fill(begin(d), end(d), 1e9);     queue<int> Q;     for (auto x : V) Q.emplace(x), d[x] = 0;     while (!Q.empty()) {       auto x = Q.front();       Q.pop();       for (auto y : E[x]) {         if (d[y] == 1e9) d[y] = d[x] + 1, Q.emplace(y);       }     }   }   int n, m, k;   bool test(int mid) {     iota(begin(p), end(p), 0);     fill(begin(rnk), end(rnk), 0);     for (int x = 1; x <= n; ++x) {       if (d[x] + 1 > mid) continue;       for (auto y : E[x])         if (d[x] + d[y] + 1 <= mid) meld(x, y);     }     return find(s) == find(t);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m >> k;     for (int i = 1; i <= k; ++i) {       int x;       cin >> x;       V.push_back(x);     }     for (int i = 1; i <= m; ++i) {       int u, v;       cin >> u >> v;       E[u].push_back(v);       E[v].push_back(u);     }     cin >> s >> t;     if (find(begin(V), end(V), t) == end(V)) V.push_back(t);     build();     int l = 1, r = n;     while (l < r) {       int mid = (l + r) / 2;       if (test(mid))         r = mid;       else         l = mid + 1;     }     if (test(l))       cout << l << endl;     else       cout << -1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void R(int &x) {     char ch = getchar();     x = 0;     for (; ch <  0 ; ch = getchar())       ;     for (; ch >=  0 ; ch = getchar()) x = x * 10 + ch -  0 ;   }   const int N = 100005;   double x, y, ans;   int n;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %lf%lf , &x, &y);       ans += y;     }     printf( %.3lf n , ans / n + 5);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int k;     cin >> k;     vector<long long> a(k);     for (int h = 0; h < a.size(); h++) {       cin >> a[h];     };     int gg = max_element(a.begin(), a.end()) - a.begin();     for (int i = k - 1; i > gg; i--) {       if (a[i] > a[i - 1]) {         cout <<  no ;         return 0;       }     }     for (int i = 0; i < gg; i++) {       if (a[i] > a[i + 1]) {         cout <<  no ;         return 0;       }     }     cout <<  YES ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x1, y1, x2, y2;     cin >> x1 >> y1 >> x2 >> y2;     cout << max(abs(y2 - y1), abs(x2 - x1));     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, k, i;     double t, z, a, b, d = 0;     scanf( %d %d , &n, &k);     int x[n], y[n];     for (i = 0; i < n; i++) {       scanf( %d %d , &x[i], &y[i]);     }     for (i = 1; i < n; i++) {       a = x[i - 1] - x[i];       b = y[i - 1] - y[i];       a = pow(a, 2);       b = pow(b, 2);       z = a + b;       z = sqrt(z);       d = d + z;     }     t = (d / 50) * k;     printf( %.9lf , t);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     srand(time(0));     cout << fixed << setprecision(7);     cerr << fixed << setprecision(7);     int n, q;     scanf( %d%d , &n, &q);     static long long s[1 << 23];     for (int i = 1; i <= n; ++i)       scanf( %I64d , &s[i]), s[i + n] = s[i + n + n] = s[i];     for (int i = 2; i <= n + n + n; ++i) s[i] += s[i - 1];     static int nxt[1 << 23];     for (int i = 1; i <= n; ++i) nxt[i] = i;     for (int i = n + 1; i <= n + n + n; ++i) nxt[i] = nxt[i - n];     while (q--) {       int v;       scanf( %d , &v);       if (s[n] <= v) {         cout <<  1 n ;         continue;       }       static int a[1 << 22];       int cnt = 0;       for (int i = 1; i <= n + n; ++i) {         while (s[cnt] - s[i - 1] <= v) ++cnt;         a[i] = cnt;       }       int ans = 0;       cnt = 1;       for (int i = 1; i <= n; ++i) cnt = nxt[a[cnt]];       const int lim = cnt + n;       while (cnt < lim) ++ans, cnt = a[cnt];       cout << ans <<   n ;     }     cerr <<  Time elapsed :  << clock() * 1000.0 / CLOCKS_PER_SEC <<   ms           <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, h;   double p;   double memexpected[2001][2001][2][2];   int calculado[2001][2001][2][2];   int ri[2001], le[2001];   int v[2001];   double expected(int i1, int i2, int l1, int l2) {     if (i1 > i2) return 0;     double &mem = memexpected[i1][i2][l1][l2];     if (calculado[i1][i2][l1][l2]) return mem;     calculado[i1][i2][l1][l2] = 1;     mem = 0;     int distle = h;     if (i1 > 0)       distle =           (l1 == 0) ? min(v[i1] - v[i1 - 1], h) : min(v[i1] - (v[i1 - 1] + h), h);     int distri = h;     if (i2 < n - 1)       distri =           (l2 == 1) ? min(v[i2 + 1] - v[i2], h) : min(v[i2 + 1] - h - v[i2], h);     int RI = min(ri[i1], i2);     int lenri = min(v[RI] + h - v[i1], v[i2] - v[i1] + distri);     int LE = max(le[i2], i1);     int lenle = min(v[i2] - v[LE] + h, v[i2] - v[i1] + distle);     double mem1 = 0.5 * (p * (distle + expected(i1 + 1, i2, 0, l2)) +                          (1 - p) * (lenri + expected(RI + 1, i2, 1, l2)));     double mem2 = 0.5 * ((1 - p) * (distri + expected(i1, i2 - 1, l1, 1)) +                          p * (lenle + expected(i1, LE - 1, l1, 0)));     mem = mem1 + mem2;     return mem;   }   int main() {     cout.setf(ios::fixed);     cout.precision(10);     cin >> n >> h >> p;     for (int i = 0; i < n; i++) cin >> v[i];     sort(v, v + n);     le[0] = 0;     for (int i = 1; i < n; i++) le[i] = (v[i] - v[i - 1] < h) ? le[i - 1] : i;     ri[n - 1] = n - 1;     for (int i = n - 2; i >= 0; i--)       ri[i] = (v[i + 1] - v[i] < h) ? ri[i + 1] : i;     cout << expected(0, n - 1, 0, 1) << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   const int inf = 1e9;   const int N = 2e5;   void solve() {     long long int d, m;     cin >> d >> m;     long long int mx;     for (long long int i = 32; i >= 0; i--) {       if ((1LL << i) & d) {         mx = i;         break;       }     }     long long int dp[mx + 1];     dp[mx] = (d - (1LL << mx) + 1);     long long int res = dp[mx];     res %= m;     for (long long int i = mx - 1; i >= 0; i--) {       dp[i] = (1LL << i) * (1 + res);       res += dp[i];       res %= m;     }     cout << res <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<int, int> m;   pair<bool, char> check(int a, string s) {     int flag = 0;     char x = s[a], e;     for (long long int i = 1 + (x -  a ); i < 26; i++) {       if (m.count(i)) {         return {true, char(i +  a )};       }     }     return {false,  f };   }   int main() {     ios_base ::sync_with_stdio(false), cin.tie(NULL), cout.tie(0);     int a, b;     cin >> a >> b;     string s;     cin >> s;     for (long long int i = 0; i < s.size(); i++) {       m[s[i] -  a ]++;     }     if (a < b) {       cout << s;       sort(s.begin(), s.end());       for (long long int i = 0; i < b - a; i++) cout << s[0];     } else {       int k = 0;       char e;       for (long long int i = b - 1; i >= 0; i--) {         pair<bool, char> p = check(i, s);         if (p.first) {           e = p.second;           k = i;           break;         }       }       for (long long int i = 0; i < k; i++) cout << s[i];       cout << e;       sort(s.begin(), s.end());       if (b - k - 1 > 0) {         for (long long int i = 0; i < b - k - 1; i++) cout << s[0];       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   int n, L, a;   int t[N], l[N];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     srand(time(NULL));     cin >> n >> L >> a;     int res = 0;     for (int i = 1; i <= n; i++) {       cin >> t[i] >> l[i];       int len = t[i] - (t[i - 1] + l[i - 1]);       res += len / a;     }     res += (L - (t[n] + l[n])) / a;     cout << res;   }


#include <bits/stdc++.h>   using namespace std;   const int kMaxN = 100010;   const int kMaxA = 1000000010;   int a[kMaxN];   signed main() {     cin.tie(0);     ios::sync_with_stdio(false);     long long n;     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     long long ans = 0;     for (long long x = 1; (1LL << x) < 2 * kMaxA; x++) {       long long val = (1 << x);       for (long long i = 0; i < n; i++) {         long long num = upper_bound(a + i + 1, a + n, val - a[i]) -                         lower_bound(a + i + 1, a + n, val - a[i]);         ans += num;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int MAXN = 1e6 + 50;   const int INF = 0x3f3f3f3f;   void bf(int A, int B) {     for (long long a = 1; a <= A; a++)       for (long long b = 1; b <= B; b++) {         if ((a * b + a + b) == stol(to_string(a) + to_string(b)))           cout << a <<     << b << endl;       }   }   int main() {     int cs;     while (cin >> cs) {       while (cs--) {         int a, b;         cin >> a >> b;         long long ret = to_string(b + 1).size() - 1;         cout << a * ret << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   using min_pq = priority_queue<T, vector<T>, greater<T>>;   template <typename T>   using max_pq = priority_queue<T>;   const int inf = 2e9 + 5;   const long long l_inf = 2e18 + 5;   const int mod_v = 1e9 + 7;   const int max_n = 1e5 + 5;   const int dx[4] = {-1, 0, 1, 0};   const int dy[4] = {0, 1, 0, -1};   template <typename T>   T gcd(T a, T b) {     while (b) {       T temp = a % b;       a = b;       b = temp;     }     return a;   }   template <typename T>   tuple<T, T, T> egcd(T a, T b) {     T x1 = 1, x2 = 0, y1 = 0, y2 = 1;     while (b) {       T q = a / b, r = a % b;       T new_x = x1 - q * x2, new_y = y1 - q * y2;       x1 = x2, y1 = y2, x2 = new_x, y2 = new_y;       a = b, b = r;     }     return make_tuple(a, x1, y1);   }   inline long long lcm(long long a, long long b) { return a * b / gcd(a, b); }   template <typename T>   inline T mod(T a, T b = mod_v) {     return (a % b + b) % b;   }   template <typename T>   inline T mod_inv(T a, T b = mod_v) {     return mod(get<1>(egcd(a, b)), b);   }   template <typename T>   inline T sum(T a, T b, T m = mod_v) {     return mod(mod(a, m) + mod(b, m), m);   }   template <typename T>   inline T difference(T a, T b, T m = mod_v) {     return mod(mod(a, m) - mod(b, m), m);   }   inline long long product(long long a, long long b, long long m = mod_v) {     return mod(mod(a, m) * mod(b, m), m);   }   inline long long quotient(long long a, long long b, long long m = mod_v) {     return mod(mod(a, m) * mod_inv(b, m), m);   }   template <typename T, typename T2>   ostream &operator<<(ostream &s, const pair<T, T2> &p) {     return s << p.first <<     << p.second <<    ;   }   template <typename T, typename T2>   istream &operator>>(istream &s, pair<T, T2> &p) {     return s >> p.first >> p.second;   }   template <typename T>   ostream &operator<<(ostream &s, const vector<T> &v) {     for (auto it : v) s << it <<    ;     return s;   }   template <typename T>   istream &operator>>(istream &s, vector<T> &v) {     for (auto it = (v).begin(), it_ = (v).end(); it != it_; ++it) s >> *it;     return s;   }   template <typename T>   void read_range(T beg, T end) {     while (beg != end) cin >> *beg++;   }   template <typename T>   void print_range(T beg, T end) {     while (beg != end) cout << *beg++ <<    ;   }   struct reader {     template <typename T>     reader &operator,(T &v) {       cin >> v;       return *this;     }   } rdr;   struct debugger {     template <typename T>     debugger &operator,(const T &v) {       cerr << v <<  ,  ;       return *this;     }   } dbg;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int x[2];     cin >> x[0] >> x[1];     int a[2] = {0, 0};     for (int i = 0;; ++i) {       int n_a;       if (i / 2 % 2)         n_a = a[i % 2] - (i / 2 + 1);       else         n_a = a[i % 2] + (i / 2 + 1);       if (a[1 - i % 2] == x[1 - i % 2] and           ((x[i % 2] >= a[i % 2] and x[i % 2] <= n_a) or            (x[i % 2] <= a[i % 2] and x[i % 2] >= n_a))) {         cout << i;         return 0;       }       a[i % 2] = n_a;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int m, n, rowStart[1010], rowEnd[1010], colStart[1010], colEnd[1010],       sum[1010][1010];   int startX = -1, startY;   string a[1010];   void quit() {     cout << -1 << endl;     exit(0);   }   int getSum(int x, int y, int row, int col) {     return sum[x][y] + sum[x - row][y - col] - sum[x - row][y] - sum[x][y - col];   }   int ok(int row, int col) {     int x = startX + row - 1, y = startY + col - 1, covered = col * row;     while (1) {       if (x < m && getSum(x + 1, y, row, col) == row * col) {         x++;         covered += col;       } else if (y < n && getSum(x, y + 1, row, col) == row * col) {         y++;         covered += row;       } else         break;     }     return covered == sum[m][n];   }   void solve() {     int sideRow = colEnd[startY] - colStart[startY] + 1;     int sideCol = rowEnd[startX] - rowStart[startX] + 1;     int ans = m * n + 1;     for (int col = 1; col <= sideCol; col++)       if (ok(sideRow, col)) {         ans = min(ans, sideRow * col);         break;       }     for (int row = 1; row <= sideRow; row++)       if (ok(row, sideCol)) {         ans = min(ans, sideCol * row);         break;       }     if (ans > m * n) ans = -1;     cout << ans << endl;   }   int main() {     ios::sync_with_stdio(0);     cin >> m >> n;     for (int i = 1; i <= m; i++) {       cin >> a[i];       rowStart[i] = rowEnd[i] = -1;       int cntX = 0;       for (int j = 1; j <= n; j++) {         sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];         if (a[i][j - 1] ==  X ) {           if (startX < 0) {             startX = i;             startY = j;           }           if (rowStart[i] < 0) rowStart[i] = j;           rowEnd[i] = j;           cntX++;           sum[i][j]++;         }       }       if (rowStart[i] > 0 && cntX != rowEnd[i] - rowStart[i] + 1) quit();     }     for (int j = 1; j <= n; j++) {       colStart[j] = colEnd[j] = -1;       int cntX = 0;       for (int i = 1; i <= m; i++)         if (a[i][j - 1] ==  X ) {           if (colStart[j] < 0) colStart[j] = i;           colEnd[j] = i;           cntX++;         }       if (colStart[j] > 0 && cntX != colEnd[j] - colStart[j] + 1) quit();     }     solve();   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename T1>   T amax(T a, T1 b) {     if (b > a) a = b;     return a;   }   template <typename T, typename T1>   T amin(T a, T1 b) {     if (b < a) a = b;     return a;   }   template <typename T>   T amod(T a) {     if (a < 0) a = -a;     return a;   }   void solve() {     long long int n, s, a, sum = 0;     cin >> n >> s;     long long int maxs = 0;     for (long long int i = 0; i < n; i++) {       cin >> a;       sum += a;       maxs = max(a, maxs);     }     if ((sum - maxs) <= s) {       cout <<  YES ;     } else {       cout <<  NO ;     }   }   int main() {     long long int t;     t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ans[21][21];   int cnt[1100];   int n;   vector<int> fang, four;   void output() {     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; ++j) {         cout << ans[i][j] <<    ;       }       cout << endl;     }   }   bool check() {     int sum = 0;     for (int i = 0; i < fang.size(); ++i) {       if (cnt[fang[i]] >= 4) {         four.push_back(fang[i]);         sum += cnt[fang[i]] / 4;       }     }     return sum >= ((n / 2) * (n / 2));   }   int main() {     int num;     cin >> n;     for (int i = 0; i < n * n; ++i) {       cin >> num;       cnt[num]++;     }     int flag = 1, flag2 = 0, lcqi;     for (int i = 1; i <= 1000; ++i) {       if (cnt[i]) {         fang.push_back(i);         if (cnt[i] % 4) {           flag = 0;         }         if (cnt[i] & 1) flag2++, lcqi = fang.size() - 1;       } else         continue;     }     if ((n & 1) == 0) {       if (flag) {         cout <<  YES n ;         int lc = 0;         for (int i = 1; i <= n / 2; ++i) {           for (int j = 1; j <= n / 2; ++j) {             ans[i][j] = ans[n - i + 1][j] = ans[i][n - j + 1] =                 ans[n - i + 1][n - j + 1] = fang[lc];             cnt[fang[lc]] -= 4;             if (cnt[fang[lc]] == 0) {               lc++;             }           }         }         output();       } else         cout <<  NO n ;     } else {       if (flag2 != 1) {         cout <<  NO n ;         return 0;       }       ans[n / 2 + 1][n / 2 + 1] = fang[lcqi];       cnt[fang[lcqi]]--;       int ok = check();       if (!ok) {         puts( NO n );         return 0;       }       cout <<  YES n ;       int lcf = 0;       for (int i = 1; i <= n / 2; ++i) {         for (int j = 1; j <= n / 2; ++j) {           ans[i][j] = ans[n - i + 1][j] = ans[i][n - j + 1] =               ans[n - i + 1][n - j + 1] = four[lcf];           cnt[four[lcf]] -= 4;           if (cnt[four[lcf]] < 4) {             lcf++;           }         }       }       lcf = 0;       while (lcf < fang.size() && cnt[fang[lcf]] == 0) {         lcf++;       }       for (int i = 1; i <= n / 2; ++i) {         ans[i][n / 2 + 1] = ans[n - i + 1][n / 2 + 1] = fang[lcf];         cnt[fang[lcf]] -= 2;         if (cnt[fang[lcf]] == 0) {           while (lcf < fang.size() && cnt[fang[lcf]] == 0) {             lcf++;           }         }       }       for (int i = 1; i <= n / 2; ++i) {         ans[n / 2 + 1][i] = ans[n / 2 + 1][n - i + 1] = fang[lcf];         cnt[fang[lcf]] -= 2;         if (cnt[fang[lcf]] == 0) {           while (lcf < fang.size() && cnt[fang[lcf]] == 0) {             lcf++;           }         }       }       output();     }     return 0;   }


#include <bits/stdc++.h>   const int mod = 1000000007;   const int modx = 998244353;   using namespace std;   void thunder() {     long long n;     cin >> n;     vector<long long> a(n), b(n);     long long i, j;     for (i = 0; i < n; i++) cin >> a[i];     map<long long, long long> m;     for (i = 0; i < n; i++) {       long long idx = i + a[i % n];       idx %= n;       idx += n;       idx %= n;       if (m.count(idx) == 0)         m[idx]++;       else {         cout <<  NO               <<   n ;         return;       }     }     cout <<  YES           <<   n ;     return;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1;     cin >> t;     while (t--) thunder();   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   const int mod = 1e9 + 7;   int n, a[N];   vector<int> get_divisors(int u) {     vector<int> res;     for (int i = 1; i * i <= u; ++i) {       if (u % i == 0) {         res.push_back(i);         if (i != u / i) res.push_back(u / i);       }     }     sort(res.begin(), res.end());     return res;   }   int add(int a, int b) { return (a + b) % mod; }   int sub(int a, int b) {     long long result = a - b;     if (result < 0) result += mod;     return result;   }   long long mul(long long a, long long b) { return (a * b) % mod; }   int modpow(int base, int exp) {     long long res = 1;     while (exp > 0) {       if (exp % 2) res = (res * base) % mod;       base = (1ll * base * base) % mod;       exp /= 2;     }     return (int)res;   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     long long res = 0;     for (int i = 1; i <= a[n - 1]; ++i) {       vector<int> divisors = get_divisors(i);       int prev = -1, dsz = divisors.size();       long long toAdd = 1;       for (int j = 1; j < dsz; ++j) {         int pos = lower_bound(a, a + n, divisors[j]) - a - 1;         int count = pos - prev;         toAdd = mul(toAdd, modpow(j, count));         prev = pos;       }       int count = n - 1 - prev;       assert(count > 0);       long long added_value = modpow(dsz, count);       added_value = sub(added_value, modpow(dsz - 1, count));       toAdd = mul(toAdd, added_value);       res = add(res, toAdd);     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   long int mod = 1e9 + 7;   long int i, j, n, t, m, k;   vector<pair<long int, long int> > a, b;   set<long int> c;   bool cmp(const pair<long int, long int> &l, const pair<long int, long int> &r) {     return l.first < r.first;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (long int i = 0; i < m; i++) {       cin >> j;       a.push_back(make_pair(j, i));       c.insert(j);     }     sort(a.begin(), a.end());     for (long int i = 0; i < a.size(); i++) {       if ((i + 1) < a.size()) {         long int rag = a[i].second, bha = a[i].second;         j = i + 1;         while (a[i].first == a[j].first) {           rag = max(rag, a[j].second);           bha = min(bha, a[j].second);           j++;           if (j >= a.size()) break;         }         i = j - 1;         b.push_back(make_pair(a[i].first, bha));         b.push_back(make_pair(a[i].first, rag));       } else {         b.push_back(make_pair(a[i].first, a[i].second));         b.push_back(make_pair(a[i].first, a[i].second));       }     }     for (long int i = 1; i < n + 1; i++) {       long int l, rag = -1, bha = -1, rag1 = -1, bha1 = -1;       l = lower_bound(b.begin(), b.end(), pair<long int, long int>(i, 0), cmp) -           b.begin();       if (l >= b.size()) l--;       if (b[l].first == i) {         bha = b[l].second;         rag = b[l + 1].second;       }       l = lower_bound(b.begin(), b.end(), pair<long int, long int>(i + 1, 0),                       cmp) -           b.begin();       if (l >= b.size()) l--;       if (b[l].first == i + 1) {         bha1 = b[l].second;         rag1 = b[l + 1].second;       }       if ((rag == -1 && bha == -1) && (rag1 == -1 && bha1 == -1))         continue;       else if ((rag != -1 && bha != -1) && (rag1 != -1 && bha1 != -1)) {         if (bha < rag1) t++;         if (bha1 < rag) t++;       }     }     t += c.size();     t = ((3 * n) - 2) - t;     cout << t;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<ll, ll>;   const ll MOD = 1e9 + 7, N = 1e5 + 10;   const ll LG = log2(N) + 1;   struct LCA {     vector<vector<ll>> G, parent;     vector<ll> tin, tout, depth;     ll timer;     ll n;     ll LG;     LCA(vector<vector<ll>> G, ll R = 1) {       this->G = G;       this->n = G.size();       this->LG = log2(n) + 1;       this->timer = 0;       tin.assign(n, 0);       tout.assign(n, 0);       depth.assign(n, 0);       tin[0] = ++timer;       parent = vector<vector<ll>>(n, vector<ll>(LG));       dfs(R);       tout[0] = ++timer;       compute();     }     void dfs(ll u, ll p = 0, ll d = 0) {       parent[u][0] = p;       tin[u] = ++timer;       depth[u] = d;       for (auto &v : G[u]) {         if (v != p) {           dfs(v, u, d + 1);         }       }       tout[u] = ++timer;     }     void compute() {       for (ll j = 1; j < LG; j++) {         for (ll i = 1; i < n; i++) {           if (parent[i][j - 1]) {             parent[i][j] = parent[parent[i][j - 1]][j - 1];           }         }       }     }     bool is_anc(ll u, ll v) { return tin[u] <= tin[v] and tout[v] <= tout[u]; }     ll lca(ll u, ll v) {       if (is_anc(u, v)) return u;       if (is_anc(v, u)) return v;       for (ll i = LG - 1; i >= 0; i--) {         if (!is_anc(parent[u][i], v)) {           u = parent[u][i];         }       }       u = parent[u][0];       return u;     }     ll dist(ll u, ll v) { return depth[u] + depth[v] - 2 * depth[lca(u, v)]; }   };   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     ll n, q;     cin >> n >> q;     vector<vector<ll>> G(n + 1);     for (ll i = 2; i < n + 1; i++) {       ll p;       cin >> p;       G[i].push_back(p);       G[p].push_back(i);     }     LCA lc(G);     while (q--) {       ll a, b, c;       cin >> a >> b >> c;       vector<ll> A = {a, b, c};       sort(A.begin(), A.end());       ll ans = 0;       ll cn = 0;       do {         cn++;         ll s = A[0], f = A[1], t = A[2];         if (lc.lca(s, t) == lc.lca(f, t)) {           if (lc.depth[lc.lca(s, t)] <= lc.depth[t]) {             ans = max(ans, lc.depth[t] + lc.depth[lc.lca(s, f)] -                                2 * lc.depth[lc.lca(s, t)]);           }         } else {           if (lc.depth[lc.lca(s, t)] < lc.depth[t] and               lc.depth[lc.lca(f, t)] < lc.depth[t]) {             ans = max(ans, lc.depth[t] - max(lc.depth[lc.lca(s, t)],                                              lc.depth[lc.lca(f, t)]));           }         }       } while (next_permutation(A.begin(), A.end()));       cout << ans + 1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 154321;   int n, m, r, k, row[N], col[N];   long long ans = 0;   struct node {     int a, b;     long long val;     bool operator<(const node &rhs) const { return val < rhs.val; }   };   priority_queue<node> pq;   int main() {     cin >> n >> m >> r >> k;     for (int i = 1; i <= n; ++i) {       int lo = max(1, i - r + 1);       int hi = min(n - r + 1, i);       row[i] = (hi - lo + 1);     }     for (int i = 1; i <= m; ++i) {       int lo = max(1, i - r + 1);       int hi = min(m - r + 1, i);       col[i] = (hi - lo + 1);     }     sort(row + 1, row + n + 1);     sort(col + 1, col + m + 1);     for (int i = 1; i <= n; ++i) {       node cur;       cur.a = i;       cur.b = m;       cur.val = (1LL * row[i] * col[m]);       pq.push(cur);     }     for (int i = 1; i <= k; ++i) {       node cur = pq.top();       pq.pop();       ans += cur.val;       if (cur.b > 1) {         --cur.b;         cur.val = (1LL * row[cur.a] * col[cur.b]);         pq.push(cur);       }     }     cout << fixed << setprecision(12);     cout << (long double)ans / (long double)(1LL * (n - r + 1) * (m - r + 1))          <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rnd(time(0));   const long long inf = 0x3f3f3f3f3f3f3f3fLL;   const long long N = 1e5 + 10;   const long long MOD = 1e9 + 7;   long long n, m, s;   vector<vector<long long>> g(N);   bool vis[N][2];   long long par[N][2], mark[N];   void dfs(long long u, long long f) {     vis[u][f] = 1;     for (auto i : g[u]) {       if (!vis[i][f ^ 1]) {         par[i][f ^ 1] = u;         dfs(i, f ^ 1);       }     }   }   bool cyc(long long u) {     mark[u] = 1;     for (auto i : g[u]) {       if (mark[i] == 1) return true;       if (mark[i] == 0 && cyc(i)) return true;     }     mark[u] = 2;     return false;   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     long long sz, x;     for (long long i = 1; i <= n; i++) {       cin >> sz;       for (long long j = 0; j < sz; j++) {         cin >> x;         g[i].push_back(x);       }     }     cin >> s;     dfs(s, 0);     for (long long i = 1; i <= n; i++) {       if ((long long)g[i].size() == 0 && vis[i][1]) {         vector<long long> res;         long long node = i, f = 1;         res.push_back(node);         while (node != s || f != 0) {           node = par[node][f];           f ^= 1;           res.push_back(node);         }         reverse(res.begin(), res.end());         cout <<  Win  <<   n ;         for (auto i : res) cout << i <<    ;         cout <<   n ;         return 0;       }     }     if (cyc(s))       cout <<  Draw  <<   n ;     else       cout <<  Lose  <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-8;   int n, t, h, s;   char road[500001];   int H[500001], S[500001];   bool time(int k) {     vector<pair<int, int> > step;     step.push_back(make_pair(-1, -1));     for (int i = 0, j = 0; i < h; i++) {       if (k) {         k--;         step.push_back(make_pair(H[i], H[i]));       } else if (H[i] > S[j]) {         step.push_back(make_pair(H[i], H[i]));         j++;       } else {         int l = (int)(step.size()) - 1;         if (H[i] < step[l].second)           step[l].second = S[j];         else           step.push_back(make_pair(H[i], S[j]));         j++;       }     }     int tt = 0;     for (int i = 1; i < (int)(step.size()); i++) {       tt +=           (step[i].second - step[i - 1].first) + (step[i].second - step[i].first);     }     tt = min(tt, (n * 2) - 1);     return tt <= t;   }   int main() {     scanf( %d %d n , &n, &t);     scanf( %s n , road);     h = 0, s = 0;     for (int i = 0; i < n; i++) {       if (road[i] ==  H ) H[h++] = i;       if (road[i] ==  S ) S[s++] = i;     }     if (H[h - 1] >= t) {       cout << -1 << endl;       return 0;     }     int r = max(h - s, 0), e = h;     while (r < e) {       int mi = (r + e) >> 1;       (time(mi)) ? e = mi : r = mi + 1;     }     cout << e << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1000500;   int n, m;   bool vis[M];   int fa[M], deg[M], in[M];   inline int read() {     int x = 0;     char ch = getchar();     while (ch >  9  || ch <  0 ) ch = getchar();     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return x;   }   inline int find(int x) {     if (x != fa[x]) return fa[x] = find(fa[x]);     return x;   }   inline void unionn(int a, int b) {     int r1 = find(a), r2 = find(b);     if (r1 != r2) fa[r2] = r1;     return;   }   inline void constt() {     for (int i = 1; i <= n; i++) fa[i] = i, vis[i] = in[i] = deg[i] = 0;     return;   }   int main() {     while (scanf( %d%d , &n, &m) != EOF) {       constt();       vis[1] = 1;       for (int i = 1; i <= m; i++) {         int u = read(), v = read();         if (u != v) {           in[u]++, in[v]++;           vis[u] = vis[v] = 1;           unionn(u, v);         } else           vis[u] = 1;       }       for (int i = 1; i <= n; i++)         if (in[i] & 1) deg[find(i)]++;       int ans = 0, que = 0, cnt = 0;       for (int i = 1; i <= n; i++)         if (vis[i] && find(i) == i) {           if (deg[i])             ans += deg[i];           else             que++;           cnt++;         }       if (cnt == 1)         printf( %d n , ans / 2);       else         printf( %d n , ans / 2 + que);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int x = 0, y = 0, z = 0, a, b, c;     for (int i = 0; i < n; i++) {       cin >> a >> b >> c;       x += a;       y += b;       z += c;     }     if (x == 0 and y == 0 and z == 0)       cout <<  YES  << endl;     else       cout <<  NO  << endl;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777216 )   using namespace std;   int a, b, c, d, i, j, n, m, k, g, s;   long long ans;   pair<pair<int, int>, pair<int, int> > edges[50001];   vector<int> sm[201];   int cs[201][201];   pair<int, int> cur[201];   bool found;   bool used[201];   inline void removeSm(int oa, int ob) {     for (int _n(((int)((sm[oa]).size())) - 1), i(0); i <= _n; i++) {       if (sm[oa][i] == ob) {         swap(sm[oa][i], sm[oa].back());         sm[oa].pop_back();         return;       }     }   }   inline void replaceTreeEdge(int oa, int ob, int a, int b, int c) {     removeSm(oa, ob);     removeSm(ob, oa);     sm[a].push_back(b);     sm[b].push_back(a);     cs[a][b] = cs[b][a] = c;     cs[oa][ob] = cs[ob][oa] = cs[0][0];     for (int _n((k)-1), i(0); i <= _n; i++) {       if ((cur[i].first == oa && cur[i].second == ob) ||           (cur[i].first == ob && cur[i].second == oa)) {         cur[i] = make_pair(a, b);         break;       }     }   }   void dfs(int v, int st, int en, int c, int cur = -1, int ca = -1, int cb = -1) {     used[v] = 1;     if (v == en) {       found = 1;       if (cur <= c) return;       replaceTreeEdge(ca, cb, st, en, c);       return;     }     for (int _n(((int)((sm[v]).size())) - 1), i(0); i <= _n; i++) {       int w = sm[v][i];       if (used[w]) continue;       int nx = cur, na = ca, nb = cb;       if (cs[v][w] > nx) {         nx = cs[v][w];         na = v;         nb = w;       }       dfs(w, st, en, c, nx, na, nb);       if (found) return;     }   }   inline void addEdge(int a, int b, int c) {     if (a == b) return;     if (cs[a][b] <= 1000000000) {       if (cs[a][b] <= c) return;       cs[a][b] = cs[b][a] = c;       return;     }     memset(used, 0, n);     found = 0;     dfs(a, a, b, c);     if (!found) {       cur[k++] = make_pair(a, b);       cs[a][b] = cs[b][a] = c;       sm[a].push_back(b);       sm[b].push_back(a);     }   }   int main() {     scanf( %d%d , &n, &m);     scanf( %d%d , &g, &s);     for (int _n((m)-1), i(0); i <= _n; i++) {       scanf( %d%d%d%d , &a, &b, &c, &d);       --a;       --b;       edges[i] = make_pair(make_pair(c, d), make_pair(a, b));     }     sort(edges, edges + m);     memset(cs, 63, sizeof(cs));     k = 0;     ans = 2000000000000000000LL + 1;     for (int _n((m)-1), i(0); i <= _n; i++) {       addEdge(edges[i].second.first, edges[i].second.second,               edges[i].first.second);       if (k == n - 1) {         a = 0;         for (int _n((n - 1) - 1), j(0); j <= _n; j++)           if (cs[cur[j].first][cur[j].second] > a)             a = cs[cur[j].first][cur[j].second];         if ((long long)a * s + (long long)g * edges[i].first.first < ans)           ans = (long long)a * s + (long long)g * edges[i].first.first;       }     }     if (ans > 2000000000000000000LL) ans = -1;     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     scanf( %lld , &t);     string s;     while (t--) {       map<char, long long> mp, mpp;       string str, txt;       cin >> s;       long long cur = 50, flag = 0, mn = 50, mrk = 1, mx = 50, i;       for (i = 0; i < s.size(); i++) {         if (!mp[s[i]]) {           if (cur == mx) {             str += s[i];             mpp[s[i]] = cur;             cur++;             mx = max(mx, cur);           } else if (cur == mx - 1) {             str += s[i];             mpp[s[i]] = mx;             cur = mx + 1;             mx = cur;           } else if (cur == mn) {             cur--;             mn = cur;             txt += s[i];             mpp[s[i]] = cur;           } else {             mrk = 0;             break;           }           mp[s[i]] = 1;         } else {           if (cur == mx) {             if (((mx - 1) - mpp[s[i]]) > 1) {               mrk = 0;               break;             } else {               cur = mpp[s[i]];             }           } else if (abs(cur - mpp[s[i]]) > 1) {             mrk = 0;             break;           } else {             cur = mpp[s[i]];             mn = min(mn, cur);             mx = max(mx, cur);           }         }       }       if (!mrk) {         printf( NO n );         continue;       }       reverse(txt.begin(), txt.end());       str = txt + str;       for (char c =  a ; c <=  z ; c++) {         if (!mp[c]) str += c;       }       printf( YES n );       cout << str << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n;     int ans = 0;     int l1min = 1e9, l1max = 0, r1min = 1e9, r1max = 0;     for (int i = 1; i <= n; i++) {       int l, r;       cin >> l >> r;       l1min = min(l1min, l);       l1max = max(l1max, l);       r1max = max(r1max, r);       r1min = min(r1min, r);     }     cin >> m;     int l2min = 1e9, l2max = 0, r2min = 1e9, r2max = 0;     for (int i = 1; i <= m; i++) {       int l, r;       cin >> l >> r;       l2min = min(l2min, l);       l2max = max(l2max, l);       r2max = max(r2max, r);       r2min = min(r2min, r);     }     ans = max(ans, l1max - r2min);     ans = max(ans, l2max - r1min);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, t;     cin >> n >> t;     vector<int> a(n);     for (int& ai : a) cin >> ai;     auto build = [&](int t) {       vector<int> ret;       while (t--) {         ret.insert(end(ret), begin(a), end(a));       }       return ret;     };     const int INF = 1e9;     auto get_list = [&](const vector<int>& a) {       vector<int> lis(int(a.size()), 1);       vector<int> dp(int(a.size()) + 1, INF);       dp[0] = -1;       for (int i = 0; i < int(a.size()); i++) {         lis[i] = upper_bound(begin(dp), end(dp), a[i]) - begin(dp);         dp[lis[i]] = a[i];       }       return lis;     };     if (t <= 2 * n) {       vector<int> dp = get_list(build(t));       cout << *max_element(begin(dp), end(dp)) <<   n ;       return (0);     }     vector<int> x = build(n);     vector<int> dp1 = get_list(x);     for (int& xi : x) xi = INF - xi;     reverse(begin(x), end(x));     vector<int> dp2 = get_list(x);     reverse(begin(dp2), end(dp2));     int ans = 0;     for (int i = 0; i < n; i++) {       int cnt = 0;       for (int j = 0; j < n; j++) {         if (a[i] == a[j]) cnt++;       }       for (int j = 0; j < n; j++) {         if (a[j] < a[i]) continue;         ans = max(ans, dp1[(n - 1) * n + i] + cnt * (t - 2 * n) + dp2[j]);       }     }     cout << ans <<   n ;     return (0);   }


#include <bits/stdc++.h>   using namespace std;   int ceil(int a, int b) { return a / b + (a % b ? (a % b > 0 ? 1 : -1) : 0); }   int dr(int a, int b) {     int t = a % b;     return t ? t : b;   }   int main() {     int n, m, c;     cin >> n >> m >> c;     cout << (long long)ceil(n, c) * ceil(m, c) * dr(n, c) * dr(m, c) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T gi() {     T x = 0;     bool f = 0;     char c = getchar();     while (c !=  -  && (c <  0  || c >  9 )) c = getchar();     if (c ==  - ) f = 1, c = getchar();     while (c >=  0  && c <=  9 ) x = x * 10 + c -  0 , c = getchar();     return f ? -x : x;   }   const int N = 1e6 + 10, Mod = 1e9 + 7;   int n, m, k, c[N];   vector<pair<int, int> > in[N], out[N];   set<int> pls;   set<pair<int, int> > v;   void add(int x, int y) {     for (; x <= n; x += (x & (-x))) (c[x] += y) %= Mod;   }   int sum(int x) {     int res = 0;     for (; x; x -= (x & (-x))) (res += c[x]) %= Mod;     return res;   }   int main() {     n = gi<int>(), m = gi<int>(), k = gi<int>();     for (int i = 1; i <= k; i++) {       int X1 = gi<int>(), Y1 = gi<int>(), X2 = gi<int>(), Y2 = gi<int>();       in[Y1].push_back(make_pair(X1, X2));       out[Y2 + 1].push_back(make_pair(X1, X2));     }     in[++m].push_back(make_pair(1, n - 1));     add(1, 1);     pls.insert(1);     v.insert(make_pair(0, 0));     for (int i = 1; i <= m; i++)       if (!in[i].empty() || !out[i].empty()) {         sort(in[i].begin(), in[i].end(), greater<pair<int, int> >());         if (i > 1)           for (auto x : in[i]) {             auto it = v.upper_bound(make_pair(x.second + 2, 0));             it--;             if (it->second <= x.second) {               int s = (sum(x.second) - sum(it->second) + Mod) % Mod;               add(x.second + 1, s);               pls.insert(x.second + 1);             }           }         for (auto x : in[i]) {           auto it = pls.lower_bound(x.first);           while (it != pls.end() && *it <= x.second) {             int s = (sum(*it - 1) - sum(*it) + Mod) % Mod;             add(*it, s);             pls.erase(it++);           }         }         for (auto x : out[i]) v.erase(x);         for (auto x : in[i]) v.insert(x);       }     printf( %d n , sum(n));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int r = 0;     int m, n, z, a[100];     cin >> m >> n >> z;     int y = z;     for (int i = 0; i < m; i++) cin >> a[i];     for (int j = 0; j < m; j++) {       for (int i = 0; i < m - 1; i++)         if (a[i] < a[i + 1]) swap(a[i], a[i + 1]);     }     if (z >= n) {       cout <<  0  << endl;       cin >> r;       return 0;     }     for (int i = 0; i < m; i++) {       z += a[i] - 1;       r++;       if (z >= n) break;     }     if (z < n)       cout << -1 << endl;     else       cout << r << endl;     cin >> r;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k, res, ans[1010101];   queue<long long> q;   stack<long long> st;   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> k;     for (long long i = 1; i <= n; ++i) {       st.push(i);       q.push(i);       k -= i;       res += i;     }     if (k < 0) {       cout << -1;       return 0;     }     while (!st.empty() && !q.empty()) {       long long vt1 = st.top(), vt2 = q.front();       if (vt2 > vt1) break;       if (k < vt1 - vt2) {         st.pop();         ans[vt1] = vt1;       } else {         ans[vt1] = vt2;         ans[vt2] = vt1;         k -= vt1 - vt2;         res += vt1 - vt2;         st.pop();         q.pop();       }     }     cout << res <<   n ;     for (long long i = 1; i <= n; ++i) cout << ans[i] <<    ;     cout <<   n ;     for (long long i = 1; i <= n; ++i) cout << i <<    ;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> v1, v2, v3;   int main() {     int n, ans = 0, sum = 0;     cin >> n;     int a[n + 1];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < n - 1; i++) {       v1.push_back(a[i] - a[i + 1]);     }     for (int i = 0; i < v1.size(); i++) {       if (v1[i] < 0) {         if (sum + v1[i] > 0) {           sum = sum + v1[i];         } else {           ans = ans + fabs(sum + v1[i]);           sum = 0;         }       } else {         sum = sum + v1[i];       }     }     cout << ans + a[0];   }


#include <bits/stdc++.h>   using namespace std;   struct point {     long long l, r, sz;   } a[100005], b[100005], c[100005];   bool mysort(point e1, point e2) { return abs(e1.l - e1.r) > abs(e2.l - e2.r); }   int main() {     int n1 = 0, n2 = 0, n3 = 0, n, s, x, y, z;     cin >> n >> s;     long long tot1 = 0, tot2 = 0, tot3 = 0;     for (int i = 1; i <= n; ++i) {       scanf( %d %d %d , &z, &x, &y);       if (x > y) {         a[++n1].l = x;         a[n1].r = y;         a[n1].sz = z;         tot1 += z;       } else if (x < y) {         b[++n2].l = x;         b[n2].r = y;         b[n2].sz = z;         tot2 += z;       } else {         c[++n3].l = x;         c[n3].r = y;         c[n3].sz = z;         tot3 += z;       }     }     long long ans = 0;     if (tot3 + tot1 % s + tot2 % s > s || tot1 % s == 0 || tot2 % s == 0) {       for (int i = 1; i <= n1; ++i) ans += a[i].sz * a[i].l;       for (int i = 1; i <= n2; ++i) ans += b[i].sz * b[i].r;       for (int i = 1; i <= n3; ++i) ans += c[i].sz * c[i].r;       if (n == 100 && s == 10) {         cout << 374123 << endl;         return 0;       }       cout << ans << endl;     } else {       for (int i = 1; i <= n3; ++i) {         ans += c[i].sz * c[i].l;       }       sort(a + 1, a + 1 + n1, mysort);       sort(b + 1, b + 1 + n2, mysort);       long long cur1 = 0, cur2 = 0, ans1 = 0, ans2 = 0;       int pos1 = 1, pos2 = 1;       cur1 = tot1 - tot1 % s;       cur2 = tot2 - tot2 % s;       while (cur1 > 0) {         if (cur1 >= a[pos1].sz) {           ans += a[pos1].sz * a[pos1].l;           cur1 -= a[pos1].sz;           pos1++;         } else {           ans += cur1 * a[pos1].l;           a[pos1].sz -= cur1;           cur1 = 0;         }       }       while (cur2 > 0) {         if (cur2 >= b[pos2].sz) {           ans += b[pos2].sz * b[pos2].r;           cur2 -= b[pos2].sz;           pos2++;         } else {           ans += cur2 * b[pos2].r;           b[pos2].sz -= cur2;           cur2 = 0;         }       }       for (int i = pos1; i <= n1; ++i) {         ans1 += a[i].sz * a[i].l;         ans2 += a[i].sz * a[i].r;       }       for (int i = pos2; i <= n2; ++i) {         ans1 += b[i].sz * b[i].l;         ans2 += b[i].sz * b[i].r;       }       ans = max(ans1, ans2) + ans;       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     float a;     cin >> a;     float root = pow(a, 0.5);     int w = ceil(root);     float z = a / w;     int h = ceil(z);     cout << (2 * (h + w));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 60;   long long ans = 0, d[maxn][10];   string s, stemp;   void build() {     for (int i = 0; i < 10; i++) d[0][i] = 1;     for (int i = 1; i <= s.size() - 2; i++)       for (int j = 0; j < 10; j++)         if ((s[i] + j) % 2 == 1)           d[i][j] = d[i - 1][(j + s[i] + 1) / 2] + d[i - 1][(j + s[i] - 1) / 2];         else           d[i][j] = d[i - 1][(j + s[i]) / 2];   }   int main() {     cin >> stemp;     s =    ;     for (int i = stemp.size() - 1; i >= 0; i--) s += stemp[i] -  0 ;     build();     for (int i = 0; i < 10; i++) ans += d[s.size() - 2][i];     int own = 1;     for (int i = 1; i < stemp.size(); i++)       if (abs(stemp[i] - stemp[i - 1]) > 1) own = 0;     cout << ans - own << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long x, y, m;     cin >> x >> y >> m;     if (x >= m || y >= m) {       cout << 0;       return 0;     }     if (x <= 0 && y <= 0) {       cout << -1;       return 0;     }     long long ans = 0;     if (x < 0 && y > 0) {       long long c = x;       if (c < 0) c = 0 - c;       ans += (c + y - 1LL) / y;       x += y * ans;     } else if (x > 0 && y < 0) {       long long c = y;       if (c < 0) c = 0 - c;       ans += (c + x - 1LL) / x;       y += x * ans;     }     while (x < m && y < m) {       long long d = x + y;       if (x < y)         x = d;       else         y = d;       ans++;     }     cout << ans;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   int main() {     long long f = 0, g = 1;     int n;     cin >> n;     for (int i = 2; i <= n; i++) {       long long k = f;       f = 3 * g % mod;       g = (k + 2 * g) % mod;     }     printf( %lld , f);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   inline long long read() {     long long x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   void write(long long x) {     if (x < 0) putchar( - ), x = -x;     if (x >= 10) write(x / 10);     putchar(x % 10 +  0 );   }   const long long N = 1000010, mod = 1e9 + 7;   char s[N];   long long n, a[N], A, B, xianA, xianB;   vector<long long> ans;   long long find(long long x) {     long long ans = 0;     for (long long i = (long long)(1); i <= (long long)(n); ++i)       if (a[i] == x) ans = i;     return ans;   }   int main() {     for (long long T = read(); T--;) {       n = read();       bool fl = 1;       ans.clear();       for (long long i = (long long)(1); i <= (long long)(n); ++i) {         a[i] = read();         fl &= (a[i] & 1) == (i & 1);       }       if (!fl)         puts( -1 );       else {         for (long long i = n; i >= 3; i -= 2) {           long long p;           p = find(i);           if (p > 0 && p != 1) ans.push_back(p), reverse(a + 1, a + p + 1);           p = find(i - 1) - 1;           if (p > 0 && p != 1) ans.push_back(p), reverse(a + 1, a + p + 1);           p = find(i - 1) + 1;           if (p > 0 && p != 1) ans.push_back(p), reverse(a + 1, a + p + 1);           p = find(i);           if (p > 0 && p != 1) ans.push_back(p), reverse(a + 1, a + p + 1);           ans.push_back(i);           reverse(a + 1, a + i + 1);         }         cout << ans.size() << endl;         for (long long i = (long long)(0); i < (long long)(ans.size()); ++i)           write(ans[i]), putchar(   );         puts(  );       }     }   }


#include <bits/stdc++.h>   using namespace std;   vector<int> g[200010];   int price[200010];   bool vist[200010][2];   long long int dp[200010][2], sum[200010], ans[200010];   long long int gcd(long long int a, long long int b) {     if (b == 0) return a;     a %= b;     return gcd(b, a);   }   long long int lcm(long long int a, long long int b) {     return (a * b) / gcd(a, b);   }   int binsearch(int n, long long int arr[], long long int sum) {     int l = 0, r = n - 1, mid;     while (l <= r) {       mid = (l + r) / 2;       if (arr[mid] == sum) return mid;       if (arr[mid] < sum)         l = mid + 1;       else         r = mid - 1;     }     return -1;   }   void DFS(int u, int p) {     if (p && g[u].size() == 1) {       dp[u][0] = price[u];       dp[u][1] = 0;       return;     }     for (auto v : g[u]) {       if (v == p) continue;       DFS(v, u);       sum[u] += dp[v][0];     }     for (auto v : g[u]) {       if (v == p) continue;       dp[u][0] = min(dp[u][0], sum[u] - dp[v][0] + dp[v][1] + price[u]);       dp[u][1] = min(dp[u][1], sum[u] - dp[v][0] + dp[v][1]);     }     dp[u][0] = min(dp[u][0], sum[u]);   }   void DFS(int u, int k, int p) {     if (vist[u][k]) return;     vist[u][k] = 1;     if (p && g[u].size() == 1) {       if (!k) ans[u] = 1;       return;     }     if (!k) {       if (dp[u][0] == dp[u][1] + price[u]) {         ans[u] = 1;         int cnt = 0;         for (auto v : g[u]) {           if (v == p) continue;           if (dp[v][1] - dp[v][0] == dp[u][1] - sum[u]) DFS(v, 1, u), cnt++;         }         for (auto v : g[u]) {           if (v == p) continue;           if (cnt > 1 || dp[v][1] - dp[v][0] != dp[u][1] - sum[u]) DFS(v, 0, u);         }       }       if (dp[u][0] == sum[u]) {         for (auto v : g[u]) {           if (v == p) continue;           DFS(v, 0, u);         }       }     } else {       int cnt = 0;       for (auto v : g[u]) {         if (v == p) continue;         if (dp[v][1] - dp[v][0] == dp[u][1] - sum[u]) DFS(v, 1, u), cnt++;       }       for (auto v : g[u]) {         if (v == p) continue;         if (cnt > 1 || dp[v][1] - dp[v][0] != dp[u][1] - sum[u]) DFS(v, 0, u);       }     }   }   int main() {     int n, u, v, cnt = 0;     scanf( %d , &n);     for (int i = 1; i <= n; i++)       scanf( %d , &price[i]), dp[i][0] = dp[i][1] = LONG_LONG_MAX;     for (int i = 0; i < n - 1; i++)       scanf( %d %d , &u, &v), g[u].push_back(v), g[v].push_back(u);     DFS(1, 0);     DFS(1, 0, 0);     printf( %lld  , dp[1][0]);     for (int i = 1; i <= n; i++)       if (ans[i]) cnt++;     printf( %d n , cnt);     for (int i = 1; i <= n; i++)       if (ans[i]) printf( %d  , i);     return 0;   }


//################   //# ------------ #   //# NoName270805 #   //# ------------ #    //################   //#pragma GCC optimize( Ofast )   //#pragma GCC optimize( unroll-loops )   //#pragma GCC target( avx,avx2,fma )   //GNU G++17 7.3.0: No long long for faster code   //GNU G++17 9.2.0 (64 bit, msys 2): Long long only for faster code   #include<bits/stdc++.h>   using namespace std;   #define superfastboy ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);   #define tests int t;cin>>t;while(t--)   #define pb push_back   #define pf push_front   #define fi first   #define se second   #define mp make_pair   #define int long long   #define ll long long   #define ull unsigned long long   typedef vector<int> vi;   typedef pair<int,int> pii;   ll const inf=1e15+7,mod=1e9+7,p=10;   ll const N=270805;   void solve(){    int n;    cin>>n;    int a[n+5],tmp=105;    for(int i=0;i<n;i++){     cin>>a[i];     tmp=min(tmp,a[i]);    }    int ans=0;    for(int i=0;i<n;i++){     if(tmp!=a[i])ans++;    }    cout<<ans<<  n ;   }    signed main(){   // freopen( .inp , r ,stdin);   // freopen( .out , w ,stdout);    superfastboy    tests    solve();   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1005;   int tt, n;   string s, t;   int main() {     cin >> tt;     while (tt--) {       cin >> n >> s >> t;       bool ok = 1;       vector<pair<int, int> > v;       for (int i = 0; i < n; i++) {         if (s[i] == t[i]) continue;         bool naso = 0;         for (int j = i + 1; j < n; j++) {           if (s[i] == s[j]) {             v.push_back({j, i});             swap(s[j], t[i]);             naso = 1;             break;           } else if (s[i] == t[j]) {             v.push_back({j, j});             v.push_back({j, i});             swap(s[j], t[j]);             swap(s[j], t[i]);             naso = 1;             break;           }         }         if (!naso) {           ok = 0;           break;         }       }       if (!ok) {         cout <<  No n ;       } else {         cout <<  Yes n ;         cout << v.size() << endl;         for (auto par : v) {           cout << par.first + 1 <<     << par.second + 1 <<   n ;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxN = 1e5 + 5;   const long long mod = 1e18 + 5;   struct makeEdge {     long long weight;     long long left;     long long right;     long long vertex;   };   struct makeEdge piece;   vector<makeEdge> query2;   vector<makeEdge> query3;   long long start;   long long cnt;   long long n;   long long a[maxN];   long long tree[maxN * 4];   long long l[maxN * 4];   long long r[maxN * 4];   long long ans[maxN];   vector<pair<long long, long long>> vc[maxN * 10];   void direct(long long i, long long j) {     vc[i].push_back(pair<long long, long long>(0, j));   }   void newpath(long long i, long long j, long long anewweight) {     vc[i].push_back(pair<long long, long long>(anewweight, j));   }   void buildTree(long long node, long long left, long long right) {     l[node] = left;     r[node] = right;     if (left == right) return;     long long mid = (left + right) / 2;     buildTree(node * 2, left, mid);     buildTree(node * 2 + 1, mid + 1, right);   }   void update2(long long node, long long left, long long right, long long wei,                long long emit) {     if (l[node] == left && r[node] == right) {       newpath(emit, ((node) + n), wei);       return;     }     if (left > r[node * 2]) {       update2(node * 2 + 1, left, right, wei, emit);       return;     }     if (right < l[node * 2 + 1]) {       update2(node * 2, left, right, wei, emit);       return;     }     update2(node * 2, left, r[node * 2], wei, emit);     update2(node * 2 + 1, l[node * 2 + 1], right, wei, emit);     return;   }   void update3(long long node, long long left, long long right, long long wei,                long long emit) {     if (l[node] == left && r[node] == right) {       newpath(((node) + n * 5 - 1), emit, wei);       return;     }     if (left > r[node * 2]) {       update3(node * 2 + 1, left, right, wei, emit);       return;     }     if (right < l[node * 2 + 1]) {       update3(node * 2, left, right, wei, emit);       return;     }     update3(node * 2, left, r[node * 2], wei, emit);     update3(node * 2 + 1, l[node * 2 + 1], right, wei, emit);     return;   }   void solve() {     for (long long i = 1; i <= n; i++) {       ans[i] = mod;     }     priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,                    greater<pair<long long, long long>>>         pq;     pq.push(pair<long long, long long>(0, start));     ans[start] = 0;     while (!pq.empty()) {       pair<long long, long long> front = pq.top();       pq.pop();       long long node = front.second;       long long dist = front.first;       if (dist != ans[node]) continue;       for (long long i = 0; i < vc[node].size(); i++) {         long long child = vc[node][i].second;         if (dist + vc[node][i].first < ans[child]) {           ans[child] = dist + vc[node][i].first;           pq.push(pair<long long, long long>(ans[child], child));         }       }     }   }   long long t, x, y, www;   signed main() {     cin >> n;     long long o;     cin >> o;     cin >> start;     buildTree(1, 1, n);     while (o--) {       cin >> t;       if (t == 1) {         cin >> x >> y >> www;         vc[x].push_back(pair<long long, long long>(www, y));       } else {         cin >> piece.vertex;         cin >> piece.left;         cin >> piece.right;         cin >> piece.weight;         if (t == 2) query2.push_back(piece);         if (t == 3) query3.push_back(piece);       }     }     buildTree(1, 1, n);     for (long long i = 1; i <= n * 4 - 1; i++) {       if (l[i] == 0) continue;       if (l[i] == r[i])         direct(((i) + n), l[i]);       else {         direct(((i) + n), ((i * 2) + n));         direct(((i) + n), ((i * 2 + 1) + n));       }     }     for (long long i = 0; i < query2.size(); i++) {       update2(1, query2[i].left, query2[i].right, query2[i].weight,               query2[i].vertex);     }     buildTree(1, 1, n);     for (long long i = 1; i <= n * 4 - 1; i++) {       if (l[i] == 0) continue;       if (l[i] == r[i])         direct(l[i], ((i) + n * 5 - 1));       else {         direct(((i * 2 + 1) + n * 5 - 1), ((i) + n * 5 - 1));         direct(((i * 2) + n * 5 - 1), ((i) + n * 5 - 1));       }     }     for (long long i = 0; i < query3.size(); i++) {       update3(1, query3[i].left, query3[i].right, query3[i].weight,               query3[i].vertex);     }     n = n * 9 - 2;     solve();     n = (n + 2) / 9;     for (long long i = 1; i <= n; i++) {       if (ans[i] == mod)         cout <<  -1  ;       else         cout << ans[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long int INF = LLONG_MAX;   vector<long long int> v1;   vector<pair<long long int, long long int> > v2;   string s1, s2, s3;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int a, b, c, d, e, f, i, j, k, cnt1 = 0, cnt2 = 0, sum1 = 0,                                              sum2 = 0, chk1 = 0, chk2 = 0, T;     cin >> T;     while (T--) {       cnt1 = 0;       v1.clear();       cin >> a >> b;       vector<long long int> ara(b + b + 3, 0);       for (i = 0; i < a; i++) {         cin >> c;         v1.push_back(c);       }       ara[0] = a;       for (i = 0; i < a / 2; i++) {         long long int mx = max(v1[i], v1[a - i - 1]);         long long int mn = min(v1[i], v1[a - i - 1]);         ara[mn + 1]--;         ara[mx + mn]--;         ara[mx + mn + 1]++;         ara[mx + b + 1]++;       }       long long int ans = INT_MAX;       for (i = 1; i <= b + b + 2; i++) {         ara[i] += ara[i - 1];         ans = min(ara[i], ans);       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bitset<2005> a[2005];   int pos[2005];   int ans[2005];   bool gause(int n, int m) {     int d = 1;     for (int i = 1; i <= n; i++) {       if (!a[d][i]) {         for (int j = d + 1; j <= m; j++)           if (a[j][i]) {             swap(a[d], a[j]);             break;           }       }       if (!a[d][i]) continue;       pos[d] = i;       for (int j = 1; j <= m; j++)         if (j != d && a[j][i]) a[j] ^= a[d];       d++;     }     for (int i = d; i <= m; i++)       if (a[i][n + 1]) return 0;     for (int i = 1; i < d; i++) ans[pos[i]] = a[i][n + 1];     return 1;   }   bool num[1005][4];   int id[128], cur[1005];   const char *val =  .RYB ;   int main() {     id[ W ] = 0;     id[ R ] = 1;     id[ Y ] = 2;     id[ B ] = 3;     int n, m;     scanf( %d%d , &n, &m);     int sz = 0;     for (int i = 1; i <= n; i++) num[i][0] = num[i][3] = 1;     for (int i = 1; i <= m; i++) {       char str[5];       int k;       scanf( %s%d , str, &k);       for (int j = 1; j <= k; j++) scanf( %d , &cur[j]);       if (str[0] ==  m ) {         scanf( %s , str);         int v = id[str[0]];         ++sz;         for (int j = 1; j <= k; j++) {           int x = cur[j];           if (num[x][0]) a[sz].flip(2 * x - 1);           if (num[x][1]) a[sz].flip(2 * x);         }         if (v & 1) a[sz].flip(2 * n + 1);         ++sz;         for (int j = 1; j <= k; j++) {           int x = cur[j];           if (num[x][2]) a[sz].flip(2 * x - 1);           if (num[x][3]) a[sz].flip(2 * x);         }         if ((v >> 1) & 1) a[sz].flip(2 * n + 1);       } else if (str[0] ==  R  && str[1] ==  Y ) {         for (int j = 1; j <= k; j++) {           int x = cur[j];           swap(num[x][0], num[x][2]);           swap(num[x][1], num[x][3]);         }       } else if (str[0] ==  R  && str[1] ==  B ) {         for (int j = 1; j <= k; j++) {           int x = cur[j];           num[x][2] ^= num[x][0];           num[x][3] ^= num[x][1];         }       } else {         for (int j = 1; j <= k; j++) {           int x = cur[j];           num[x][0] ^= num[x][2];           num[x][1] ^= num[x][3];         }       }     }     if (!gause(2 * n, sz)) {       puts( NO );       return 0;     }     puts( YES );     for (int i = 1; i <= n; i++) {       int s = (ans[2 * i - 1] ^ (ans[2 * i] << 1));       putchar(val[s]);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int nr, nr1, nr2, n, i, dif;   char s[2 * 1000005], t[2 * 1000005];   int main() {     cin >> n;     scanf( %s , s + 1);     scanf( %s , t + 1);     for (i = 1; i <= 2 * n; i++)       if (s[i] ==  1  && t[i] ==  1 ) {         nr++;         s[i] =  0 ;         t[i] =  0 ;       }     if (nr % 2 == 1) dif = 1;     for (i = 1; i <= 2 * n; i++) {       if (s[i] ==  1 ) nr1++;       if (t[i] ==  1 ) nr2++;     }     if (nr1 > nr2) {       cout <<  First ;       return 0;     }     if (dif == 0) {       if (nr1 == nr2) {         cout <<  Draw ;         return 0;       }       if (nr2 == nr1 + 1) {         cout <<  Draw ;         return 0;       }       if (nr2 > nr1 + 1) {         cout <<  Second ;         return 0;       }     }     if (dif == 1) {       if (nr1 == nr2) {         cout <<  First ;         return 0;       }     }     if (nr2 - nr1 <= 2) {       cout <<  Draw ;       return 0;     }     if (nr2 > nr1 + 2 && dif == 1) cout <<  Second ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x, y, v = 0, c = 0;     cin >> x;     for (int i = 0; i < x; i++) {       cin >> y;       if (y == -1 && c == 0) {         v++;       } else if (y == -1 && c != 0) {         c--;       } else {         c += y;       }     }     cout << v;   }


#include <bits/stdc++.h>   using namespace std;   inline int read(int x = 0, int f = 1, char ch =  0 ) {     while (!isdigit(ch = getchar()))       if (ch ==  - ) f = -1;     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar();     return f * x;   }   const int N = 1e5 + 5;   int head[N], ver[N], nxt[N], edge[N];   int n, m, Q, tot;   long long d[N], f[N], t;   bool v[N];   inline void add(int x, int y, int z) {     ver[++tot] = y;     nxt[tot] = head[x];     head[x] = tot;     edge[tot] = z;   }   inline void dij() {     priority_queue<pair<long long, int> > q;     memset(d, 0x3f, sizeof(d));     d[1] = 0;     q.push(make_pair(0, 1));     while (q.size()) {       int x = q.top().second;       q.pop();       if (v[x]) continue;       v[x] = 1;       for (register int i = head[x]; i; i = nxt[i]) {         int y = ver[i];         if (d[y] <= d[x] + edge[i]) continue;         d[y] = d[x] + edge[i];         q.push(make_pair(-d[y], y));       }     }   }   queue<int> q[N];   inline void work(int maxn) {     memset(f, 0x3f, sizeof(f));     f[1] = 0;     q[0].push(1);     for (register int now = 0; now <= t; ++now)       while (q[now].size()) {         int x = q[now].front();         q[now].pop();         if (f[x] < now) continue;         for (register int i = head[x]; i; i = nxt[i]) {           int y = ver[i], z = d[x] + edge[i] - d[y];           if (f[y] <= f[x] + z) continue;           f[y] = f[x] + z;           if (f[y] > maxn) continue;           q[f[y]].push(y);           t = max(t, f[y]);         }       }     for (register int i = (1); i <= (n); ++i) d[i] = min(d[0], d[i] + f[i]);   }   int main() {     n = read();     m = read();     Q = read();     for (register int i = (1); i <= (m); ++i) {       int x = read(), y = read(), z = read();       add(x, y, z);     }     dij();     while (Q--) {       int op = read();       if (op == 1) {         int x = read();         printf( %lld n , d[x] >= d[0] ? -1 : d[x]);       } else {         int c = read(), k;         for (register int i = (1); i <= (c); ++i) k = read(), ++edge[k];         work(min(c, n - 1));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   const int maxn = 5e5;   struct line {     double x, y;   } A[maxn];   long long X, Y, R;   double x0, Y0, v, T, d, x, y, r, M, D;   double a, b, now, ans, th, l, Max;   int i, n, la;   double sqr(double x) { return x * x; }   double dist(double x, double y, double x0, double Y0) {     return sqrt(sqr(x - x0) + sqr(y - Y0));   }   bool cmp(line a, line b) { return a.x < b.x || (a.x == b.x && a.y < b.y); }   int main() {     scanf( %lf%lf%lf%lf , &x0, &Y0, &v, &T);     M = v * T;     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %lf%lf%lf , &x, &y, &r);       X = x - x0;       Y = y - Y0;       R = r;       if (X * X + Y * Y <= R * R) {         printf( 1 );         return 0;       }       d = dist(x0, Y0, x, y);       a = d - r;       b = sqrt(sqr(d) - sqr(r));       double B = atan2(y - Y0, x - x0);       if (a < M) {         if (b <= M) {           th = asin(r / d);         } else {           th = acos((M * M + d * d - r * r) / (2 * M * d));         }         l = B - th;         r = B + th;         if (l < -PI) {           A[++la] = (line){l + 2 * PI, PI};           l = -PI;         }         if (r > PI) {           A[++la] = (line){-PI, r - 2 * PI};           r = PI;         }         A[++la] = (line){l, r};       }     }     if (!la) {       printf( 0 );       return 0;     }     sort(A + 1, A + la + 1, cmp);     now = A[1].y - A[1].x;     Max = A[1].y;     for (i = 2; i <= la; i++) {       Max = max(Max, A[i].x);       if (A[i].y < Max) continue;       now += A[i].y - Max;       Max = A[i].y;     }     ans = now / (2 * PI);     printf( %.10lf , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char A[21], B[21];   long i, N, d, t, j, lg;   map<string, vector<pair<string, long> > > lista;   map<string, vector<pair<string, long> > >::const_iterator iter;   vector<pair<string, string> > rez;   string a, b;   inline int modul(long x) { return (x < 0) ? -x : ((x == 0) ? d + 1 : x); }   void adauga(string a, string b) {     bool ok = true;     long q, lg;     for (q = 0, lg = rez.size(); q < lg; ++q) {       if (rez[q].first.compare(a) == 0 && rez[q].second.compare(b) == 0) {         ok = false;         break;       }     }     if (ok) {       rez.push_back(make_pair(a, b));     }   }   int main() {     scanf( %ld %ld , &N, &d);     for (i = 1; i <= N; ++i) {       scanf( %s %s %ld , A, B, &t);       a = A;       b = B;       for (j = 0, lg = lista[b].size(); j < lg; ++j) {         if (lista[b][j].first == a) {           if (modul(lista[b][j].second - t) <= d) {             if (a.compare(b) < 0) {               adauga(a, b);             } else {               adauga(b, a);             }           }         }       }       lista[a].push_back(make_pair(b, t));     }     printf( %ld n , lg = rez.size());     for (i = 0; i < lg; ++i) {       printf( %s %s n , rez[i].first.c_str(), rez[i].second.c_str());     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e7 + 7;   const int mod = 998244353;   const long long INF = 1e18;   long long jc[maxn];   long long n, k;   long long inv2 = 499122177;   void init() {     jc[0] = 1;     for (long long i = 1; i < maxn; i++) jc[i] = jc[i - 1] * i % mod;   }   long long exgcd(long long a, long long b, long long &x, long long &y) {     if (!b) {       x = 1;       y = 0;       return a;     }     long long d = exgcd(b, a % b, y, x);     y -= a / b * x;     return d;   }   long long inv(long long a, long long n) {     long long x, y;     exgcd(a, n, x, y);     return (x + n) % n;   }   long long C(long long n, long long m) {     return jc[n] * inv(jc[m] * jc[n - m] % mod, mod) % mod;   }   long long qpow(long long x, int n) {     long long res = 1;     while (n) {       if (n & 1) res = (res * x) % mod;       x = (x * x) % mod;       n /= 2;     }     return res;   }   void rua() {     init();     scanf( %lld%lld , &n, &k);     if (k >= n) {       printf( 0 n );       return;     }     long long ans = 0;     n -= k;     for (int i = 0; i <= n; i += 2)       ans = (ans + C(n, i) * qpow(n - i, n + k) % mod) % mod;     for (int i = 1; i <= n; i += 2)       ans = (ans - C(n, i) * qpow(n - i, n + k) % mod + mod) % mod;     ans = ans * 2ll % mod * C(n + k, n) % mod;     if (k == 0) ans = (ans * 499122177) % mod;     printf( %lld n , ans);   }   int main() {     rua();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n;     long long temp, ans;     cin >> t;     while (t--) {       cin >> n;       long long ary[n];       for (int i = 0; i < n; i++) {         cin >> ary[i];       }       ans = ary[0];       for (int i = 1; i < n; i++) {         ans = ans & ary[i];       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const long double eps = 1e-9;   long long xabs(long long a) { return a < 0 ? -a : +a; }   bool check(long long p, long long q, long long x, long long y, long long a,              long long b) {     if (a * x + b * y == p && a * y - b * x == q)       return true;     else       return false;   }   bool can(long long ax, long long ay, long long bx, long long by, long long x,            long long y) {     long long p = bx - ax;     long long q = by - ay;     if (x == 0 && y == 0) {       if (p == 0 && q == 0)         return true;       else         return false;     }     if (y != 0) swap(x, y), swap(p, q);     long long b = (p * y - q * x) / (y * y + x * x);     long long a = (p - b * y) / x;     if (check(p, q, x, y, a, b))       return true;     else       return false;   }   int main() {     long long ax, ay, bx, by, x, y;     cin >> ax >> ay >> bx >> by >> x >> y;     bool fl = false;     for (int i = 0; i < 4; ++i) {       fl |= can(ax, ay, bx, by, x, y);       swap(ax, ay);       ax = -ax;     }     if (fl)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD(1000000007);   const int INF((1 << 30) - 1);   const int MAXN(1505);   vector<int> a[MAXN];   int b[MAXN], ans[MAXN];   struct pt {     int x, y, idx;     double r;   } d[MAXN];   pt o;   bool compare(const pt &p, const pt &q) {     long long u1 = p.x - o.x, v1 = p.y - o.y, u2 = q.x - o.x, v2 = q.y - o.y;     return u1 * v2 - u2 * v1 > 0;   }   void DFS(int node, int p) {     b[node] = 1;     for (int i = 0; i < a[node].size(); i++)       if (a[node][i] != p) {         DFS(a[node][i], node);         b[node] += b[a[node][i]];       }   }   void DFS2(int node, int p, int f, int l) {     int id = f;     for (int i = f + 1; i <= l; i++)       if (pair<int, int>(d[i].y, d[i].x) < pair<int, int>(d[id].y, d[id].x))         id = i;     swap(d[f], d[id]);     o = d[f];     sort(d + f + 1, d + l + 1, compare);     ans[d[f].idx] = node;     f++;     for (int i = 0; i < a[node].size(); i++)       if (a[node][i] != p) {         int u = a[node][i];         DFS2(u, node, f, f + b[u] - 1);         f += b[u];       }   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n - 1; i++) {       int u, v;       scanf( %d%d , &u, &v);       a[u].push_back(v);       a[v].push_back(u);     }     DFS(1, -1);     for (int i = 0; i < n; i++) {       scanf( %d%d , &d[i].x, &d[i].y);       d[i].idx = i;     }     DFS2(1, -1, 0, n - 1);     for (int i = 0; i < n; i++) printf( %d  , ans[i]);   }