#include<bits/stdc++.h>   typedef long long int ll;   #define io ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);   #define fr(i,l,r) for(ll i=l;i<r;i++)   #define lop ll t;cin>>t;while(t--)   #define maxi 1000   #define mod 1000000007   #define f first   #define s second   ll dp[maxi];   using namespace std;         /*      a1 + a2 +... +an = k*m     long n,k;          cin>>n>>k;if(k<n){      k=n/k*k+(n%k!=0)*k;     }     cout<<k/n+(k%n!=0)<<endl;               */         void solve(){       ll n , k ; cin >> n >> k ;       if(k < n) k = k*(n/k) + (n%k != 0)*k ;       cout << k/n + (k%n != 0) << endl ;   }         int main(){       io;       int t ; cin >> t ;       while(t--){           solve() ;       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, sum = 0;     cin >> n >> k;     pair<int, int> p[n];     for (int i = 0; i < n; i++) {       cin >> p[i].first;       p[i].second = i + 1;     }     sort(p, p + n);     for (int i = 0; i < n; i++) {       k -= p[sum].first;       if (k >= 0)         sum++;       else         break;     }     cout << sum << endl;     for (int i = 0; i < sum; i++) {       cout << p[i].second <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 59;   struct State {     char c[MAX_N][MAX_N];   };   int H, W;   vector<pair<int, int>> solve(State S) {     vector<pair<int, int>> D;     for (int t = 1; t <= 100000; t++) {       bool flag = false;       if (H % 2 == 0) {         for (int i = 1; i <= H; i++) {           for (int j = 1; j <= W; j++) {             if (i % 2 == 1 && S.c[i][j] !=  U ) flag = true;             if (i % 2 == 0 && S.c[i][j] !=  D ) flag = true;           }         }       } else {         for (int i = 1; i <= H; i++) {           for (int j = 1; j <= W; j++) {             if (j % 2 == 1 && S.c[i][j] !=  L ) flag = true;             if (j % 2 == 0 && S.c[i][j] !=  R ) flag = true;           }         }       }       if (flag == false) return D;       for (int i = 1; i <= H - 1; i++) {         for (int j = 1; j <= W - 1; j++) {           if (t % 2 == 1) {             if (S.c[i][j] ==  U  && S.c[i][j + 1] ==  U  &&                 S.c[i + 1][j] ==  D  && S.c[i + 1][j + 1] ==  D ) {               S.c[i + 0][j + 0] =  L ;               S.c[i + 0][j + 1] =  R ;               S.c[i + 1][j + 0] =  L ;               S.c[i + 1][j + 1] =  R ;               D.push_back(make_pair(i, j));             }           }           if (t % 2 == 0) {             if (S.c[i][j] ==  L  && S.c[i][j + 1] ==  R  &&                 S.c[i + 1][j] ==  L  && S.c[i + 1][j + 1] ==  R ) {               S.c[i + 0][j + 0] =  U ;               S.c[i + 0][j + 1] =  U ;               S.c[i + 1][j + 0] =  D ;               S.c[i + 1][j + 1] =  D ;               D.push_back(make_pair(i, j));             }           }         }       }     }     return D;   }   int main() {     cin >> H >> W;     State T, U;     for (int i = 1; i <= H; i++) {       for (int j = 1; j <= W; j++) cin >> T.c[i][j];     }     vector<pair<int, int>> D1 = solve(T);     for (int i = 1; i <= H; i++) {       for (int j = 1; j <= W; j++) cin >> U.c[i][j];     }     vector<pair<int, int>> D2 = solve(U);     vector<pair<int, int>> D3 = D1;     for (int i = D2.size() - 1; i >= 0; i--) D3.push_back(D2[i]);     cout << D3.size() << endl;     for (int i = 0; i < D3.size(); i++)       cout << D3[i].first <<     << D3[i].second << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = (long long)2 * 1e9;   const long long MOD = (long long)1e9 + 7;   const long long P = 239;   const long long MAX_N = 100000;   const long long ABC = 26;   const long double pi = 3.1415926535897932384626;   const long double eps = 1e-6;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.precision(20);     long long c, h1, h2, w1, w2;     cin >> c >> h1 >> h2 >> w1 >> w2;     if (w2 > w1) {       swap(h1, h2);       swap(w1, w2);     }     if (w1 * w1 >= c) {       long long ans = 0;       for (long long i = 0; i * w1 <= c; i++)         ans = max(ans, i * h1 + (c - i * w1) / w2 * h2);       cout << ans;     } else {       if (h1 * w2 < h2 * w1) {         swap(h1, h2);         swap(w1, w2);       }       long long ans = 0;       for (long long i = 0; i < w1 && i * w2 <= c; i++)         ans = max(ans, i * h2 + (c - i * w2) / w1 * h1);       cout << ans;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 1000006, maxm = 1005;   const long long mod = 1000000007;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long powermod(long long a, long long b) {     a = a;     long long ans = 1;     while (b) {       if (b % 2) ans = (ans * a);       b = b / 2;       a = (a * a);     }     return ans;   }   long long a[100005];   long long flag[100005];   int main() {     long long t;     scanf( %lld , &t);     while (t--) {       long long n, m, i, j, k;       scanf( %lld%lld , &n, &k);       long long vis1 = 0, vis2 = 0;       for (i = 1; i <= n; i++) {         scanf( %lld , &a[i]);         if (a[i] == k) vis1 = 1;         if (i >= 2) {           if (a[i] >= k && (a[i - 1] >= k || a[i - 2] >= k)) vis2 = 1;         }       }       if ((vis1 == 1 && vis2 == 1) || (n == 1 && vis1 == 1))         printf( yes n );       else         printf( no n );     }   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > e;   vector<long long> val;   vector<long long> mp, mn;   vector<int> deg;   vector<bool> vis;   pair<long long, long long> dfs(int x) {     vis[x] = true;     long long mx = 0, mi = 0;     for (int to : e[x]) {       if (!vis[to]) {         auto p = dfs(to);         mx = max(mx, p.first);         mi = max(mi, p.second);       }     }     long long d = val[x] + mx - mi;     mp[x] = mx;     mn[x] = mi;     if (d > 0)       mi += d;     else       mx -= d;     return make_pair(mx, mi);   }   int main(int argc, char **argv) {     int n;     scanf( %d , &n);     deg = vector<int>(n);     mp = mn = val = vector<long long>(n);     vis = vector<bool>(n);     e = vector<vector<int> >(n);     for (int i = 0; i < n - 1; i++) {       int a, b;       scanf( %d %d , &a, &b);       e[a - 1].push_back(b - 1);       e[b - 1].push_back(a - 1);       deg[a - 1]++;       deg[b - 1]++;     }     for (int i = 0; i < n; i++) {       int t;       scanf( %d , &t);       val[i] = t;     }     auto p = dfs(0);     cout << p.first + p.second << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long N, x, y, awal, centre, nb, a;   bool visited[100005];   vector<long long> adj[100005];   vector<int> ans;   void dfs(int x) {     int s = adj[x].size();     visited[x] = 1;     bool cek = 1;     for (int i = 0; i < s; i++) {       nb = adj[x][i];       if (!visited[nb]) {         cek = 0;         dfs(nb);       }     }     if (cek) ans.push_back(x);   }   int main() {     cin >> N;     for (int i = 1; i < N; i++) {       cin >> x >> y;       adj[x].push_back(y);       adj[y].push_back(x);     }     for (int i = 1; i <= N; i++) {       if (adj[i].size() >= 3) {         awal = i;         centre++;       }     }     if (centre > 1)       cout <<  No n ;     else {       if (centre == 0) {         dfs(1);         cout <<  Yes n  << 1 <<   n ;         for (int i = 1; i <= N; i++) {           if (adj[i].size() == 1) {             cout << i;             a++;             if (a == 1) cout <<    ;           }         }         cout <<   n ;       }       if (centre == 1) {         dfs(awal);         cout <<  Yes n  << ans.size() <<   n ;         for (int i = 0; i < ans.size(); i++) {           cout << awal <<     << ans[i] <<   n ;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100100;   const long long INF = 1000 * 1000 * 1000LL * 1000 * 1000;   vector<pair<int, int> > adj1[N];   vector<pair<long long, pair<int, int> > > e;   set<pair<long long, int> > s;   long long d[N];   int p[N], par[N], sz[N], flag(1);   void Dijkstra() {     while (s.size()) {       auto u = *s.begin();       s.erase(u);       for (auto v : adj1[u.second]) {         long long w = u.first + v.second;         if (w < d[v.first]) {           s.erase({d[v.first], v.first});           d[v.first] = w;           p[v.first] = p[u.second];           s.insert({d[v.first], v.first});         }       }     }     return;   }   int findpar(int v) {     if (v == par[v]) return v;     return (par[v] = findpar(par[v]));   }   bool merge(int u, int v) {     u = findpar(u), v = findpar(v);     if (u == v) return 0;     if (sz[u] < sz[v]) swap(u, v);     sz[u] += sz[v];     par[v] = u;     return 1;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int n, m, k, u, v, w;     cin >> n >> m;     for (int i = 0; i < m; i++) {       cin >> u >> v >> w;       adj1[--u].push_back({--v, w});       adj1[v].push_back({u, w});     }     fill(d, d + n, INF);     cin >> k;     for (int i = 0; i < k; i++) {       cin >> u;       d[--u] = 0;       if (!u) flag = 0;     }     for (int i = 0; i < n; i++) {       p[i] = i;       par[i] = i, sz[i] = 1;       s.insert({d[i], i});     }     Dijkstra();     for (int i = 0; i < n; i++)       for (auto u : adj1[i])         if (p[i] < p[u.first]) {           long long w = d[i] + d[u.first] + u.second;           e.push_back({w, {p[i], p[u.first]}});         }     int cmp = k;     long long ans(0), ans2(0);     sort(e.begin(), e.end());     for (int i = 0; i < e.size() && cmp > 1; i++) {       if (merge(e[i].second.first, e[i].second.second)) {         cmp--;         ans += e[i].first;       }     }     if (flag) ans += d[0];     cout << ((cmp == 1) ? ans : -1) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     map<int, int> mp;     vector<int> l(n), a(n);     for (int i = 0; i < n; i++) cin >> l[i];     vector<int> r(n);     for (int i = 0; i < n; i++) {       cin >> r[i];       a[i] = l[i] + r[i];       mp[a[i]]++;     }     int curr = 1;     map<int, int> mp2;     for (auto it = mp.rbegin(); it != mp.rend(); it++) {       mp2[it->first] = curr++;     }     for (int i = 0; i < n; i++) {       a[i] = mp2[a[i]];     }     for (int i = 0; i < n; i++) {       int cnt1 = 0, cnt2 = 0;       for (int j = 0; j < n; j++) {         if (j == i) continue;         if (a[j] > a[i]) {           if (j > i)             cnt2++;           else             cnt1++;         }       }       if (cnt1 != l[i] || cnt2 != r[i]) {         cout <<  NO n ;         return 0;       }     }     cout <<  YES n ;     for (auto it : a) cout << it <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve();   int main(int argc, char const *argv[]) { solve(); }   void solve() {     map<int, int> arr;     cin >> arr[0] >> arr[1] >> arr[2] >> arr[3];     int total = arr[0] + arr[1] + arr[2] + arr[3];     for (int st = 0; st < 4; st++)       if (arr[st]) {         vector<int> res;         auto t = arr;         t[st]--;         res.push_back(st);         int last = st;         for (int i = 0; i < total - 1; i++) {           if (t[last - 1]) {             t[last - 1]--;             res.push_back(last - 1);             last--;           } else if (t[last + 1]) {             t[last + 1]--;             res.push_back(last + 1);             last++;           } else             break;         }         if ((int)res.size() == total) {           cout <<  YES n ;           for (int i : res) printf( %d  , i);           cout << endl;           return;         }       }     cout <<  NO n ;     return;   }


#include <bits/stdc++.h>   using namespace std;   enum { EMPTY, LINE, INF };   int Type(int a, int b, int c) {     if (a == 0 && b == 0)       if (c == 0)         return INF;       else         return EMPTY;     return LINE;   }   void Exit(int ans) {     printf( %d n , ans);     exit(0);   }   int main() {     int a1, b1, c1;     int a2, b2, c2;     scanf( %d%d%d , &a1, &b1, &c1);     scanf( %d%d%d , &a2, &b2, &c2);     int t1 = Type(a1, b1, c1);     int t2 = Type(a2, b2, c2);     if (t1 == EMPTY || t2 == EMPTY) Exit(0);     if (t1 == INF || t2 == INF) Exit(-1);     if (a1 * b2 - a2 * b1 != 0) Exit(1);     if (a1 * c2 - a2 * c1 == 0 && b1 * c2 - b2 * c1 == 0) Exit(-1);     Exit(0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     long long i, j, x, n, m, l, r;     cin >> n >> m;     vector<long long> v;     for (i = 0; i < n; i++) {       cin >> x;       v.push_back(x);     }     for (i = 0; i < m; i++) {       cin >> l >> r >> x;       long long c = 0;       if (x < l || x > r) {         cout <<  Yes n ;         continue;       }       for (j = l - 1; j < r; j++) {         if (v[j] < v[x - 1]) {           c++;         }       }       if (c == (x - l)) {         cout <<  Yes n ;       } else {         cout <<  No n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   map<pair<long long, long long>, long long> cost;   map<long long, int> vis;   map<long long, int> freq;   int main() {     int q;     cin >> q;     while (q--) {       int e;       long long v, u;       cin >> e >> v >> u;       long long tv = v;       long long tu = u;       if (e == 1) {         long long w;         cin >> w;         if (u == v) continue;         while (tv > 0) {           freq[tv]++;           tv /= 2;         }         while (tu > 0) {           ++freq[tu];           tu /= 2;         }         tv = v;         tu = u;         while (freq[tv] == 1 && tv > 1) {           cost[make_pair(tv, tv / 2)] += w;           tv /= 2;         }         while (freq[tu] == 1 && tu > 1) {           cost[make_pair(tu, tu / 2)] += w;           tu /= 2;         }       } else {         long long ans = 0;         while (tv > 0) {           freq[tv]++;           tv /= 2;         }         while (tu > 0) {           ++freq[tu];           tu /= 2;         }         tv = v;         tu = u;         while (freq[tv] == 1 && tv > 1) {           ans += cost[make_pair(tv, tv / 2)];           tv /= 2;         }         while (freq[tu] == 1 && tu > 1) {           ans += cost[make_pair(tu, tu / 2)];           tu /= 2;         }         cout << ans << endl;       }       freq.clear();     }   }


#include <iostream>   #include <vector>      using namespace std;      int l[200005], r[200005];   vector<int> e[200005];   long long int dp[2][200005];      void dfs(int u, int fa) {       dp[0][u] = dp[1][u] = 0;       for (auto v : e[u]) {           if (v == fa) continue;           dfs(v, u);           dp[0][u] += max(dp[0][v] + abs(l[u] - l[v]), dp[1][v] + abs(l[u] - r[v]));           dp[1][u] += max(dp[0][v] + abs(r[u] - l[v]), dp[1][v] + abs(r[u] - r[v]));       }   }      int main(void) {       int t;       scanf( %d , &t);       while (t--) {           int n;           scanf( %d , &n);           for (int i = 1;i <= n;i++) scanf( %d %d , &l[i], &r[i]);           for (int i = 1;i <= n;i++) e[i].clear();           for (int i = 0;i < n - 1;i++) {               int u, v;               scanf( %d %d , &u, &v);               e[u].emplace_back(v);               e[v].emplace_back(u);           }           dfs(1, -1);           printf( %lld n , max(dp[0][1], dp[1][1]));       }   }


#include <bits/stdc++.h>   using namespace std;   class Solution {    public:     void solve(std::istream& in, std::ostream& out) {       int w, h;       in >> w >> h;       vector<string> m(h);       for (string& s : m) in >> s;       for (int i = 0; i < 2 * w; ++i) {         for (int j = 0; j < 2 * h; ++j) out << m[j / 2][i / 2];         out <<   n ;       }     }   };   void solve(std::istream& in, std::ostream& out) {     out << std::setprecision(12);     Solution solution;     solution.solve(in, out);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     istream& in = cin;     ostream& out = cout;     solve(in, out);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long double eps = 1e-9, pi = acos(-1.0);   struct vec {     long double i, x, y;   } vectors[100005];   long double cala(const vec& v) {     long double ang = acos(v.x / sqrt(v.x * v.x + v.y * v.y));     ang = v.y > -eps ? ang : 2 * pi - ang;     return ang;   }   bool cmp(const vec& v1, const vec& v2) { return cala(v1) < cala(v2); }   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++)       cin >> vectors[i].x >> vectors[i].y, vectors[i].i = i;     sort(vectors, vectors + n, cmp);     int minp = n - 1;     long double minv =         abs((long double)2 * pi - (cala(vectors[n - 1]) - cala(vectors[0])));     for (int i = 0; i < n - 1; i++) {       if (abs(cala(vectors[i + 1]) - cala(vectors[i])) < minv)         minp = i, minv = abs(cala(vectors[i + 1]) - cala(vectors[i]));     }     if (minp == n - 1)       cout << vectors[minp].i + 1 <<     << vectors[0].i + 1 << endl;     else       cout << vectors[minp].i + 1 <<     << vectors[minp + 1].i + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       if (n <= 30)         cout <<  NO n ;       else {         cout <<  YES n ;         if (n == 36 || n == 40 || n == 44)           cout <<  6 10 15   << n - 31 <<   n ;         else           cout <<  6 10 14   << n - 30 <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   vector<int> p;   long long dp1[555555];   long long dp2[555555];   long long fp(long long x) {     long long ret = 1;     long long mul = 2;     while (x) {       if (x & 1) {         ret *= mul;         ret %= mod;       }       mul *= mul;       mul %= mod;       x >>= 1;     }     return ret;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     p.push_back(2);     p.push_back(3);     p.push_back(5);     p.push_back(7);     p.push_back(11);     p.push_back(13);     p.push_back(17);     p.push_back(19);     p.push_back(23);     p.push_back(29);     p.push_back(31);     p.push_back(37);     p.push_back(41);     p.push_back(43);     p.push_back(47);     p.push_back(53);     p.push_back(59);     p.push_back(61);     p.push_back(67);     int k = p.size();     int cnt[80] = {};     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int add;       cin >> add;       cnt[add]++;     }     dp1[0] = 1;     for (int i = 1; i < 70 + 1; i++) {       if (!cnt[i]) continue;       int shift = 0;       int rem = i;       for (int j = 0; j < k; j++) {         while (rem % p[j] == 0) {           shift ^= (1 << j);           rem /= p[j];         }       }       memset(dp2, 0, sizeof(dp2));       ;       long long add = fp(cnt[i] - 1);       for (int j = 0; j < 1 << k; j++) {         dp2[j] += dp1[j] * add % mod;         dp2[j] %= mod;         dp2[j ^ shift] += dp1[j] * add % mod;         dp2[j ^ shift] %= mod;       }       for (int j = 0; j < 1 << k; j++) {         dp1[j] = dp2[j];       }     }     cout << (dp1[0] + mod - 1) % mod << endl;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1024000000,1024000000 )   using namespace std;   int sum[4000005];   int cover[4000005];   int n, m;   void up(int rt) {     if (cover[rt << 1] == cover[rt << 1 | 1] && cover[rt << 1] != -1 &&         cover[rt << 1])       cover[rt] = cover[rt << 1];     else       cover[rt] = -1;   }   void down(int rt) {     if (cover[rt] == 1) {       cover[rt << 1] = cover[rt << 1 | 1] = cover[rt];       if (sum[rt << 1] == 0) sum[rt << 1] = sum[rt];       if (sum[rt << 1 | 1] == 0) sum[rt << 1 | 1] = sum[rt];     }   }   void build(int l, int r, int rt) {     cover[rt] = 0;     if (l == r) {       cover[rt] = 0;       sum[rt] = 0;       return;     }     int m = (l + r) >> 1;     build(l, m, rt << 1);     build(m + 1, r, rt << 1 | 1);     up(rt);   }   void update(int L, int R, int d, int l, int r, int rt) {     if (L <= l && R >= r) {       if (cover[rt] == 1) return;       if (cover[rt] == 0) {         cover[rt] = 1;         sum[rt] = d;         down(rt);         return;       }     }     int m = (l + r) >> 1;     if (L <= m) update(L, R, d, l, m, rt << 1);     if (R > m) update(L, R, d, m + 1, r, rt << 1 | 1);     up(rt);   }   int query(int p, int l, int r, int rt) {     if (l == r) return sum[rt];     int m = (l + r) >> 1;     int res = 0;     if (p <= m) res += query(p, l, m, rt << 1);     if (p > m) res += query(p, m + 1, r, rt << 1 | 1);     return res;   }   int main() {     while (~scanf( %d%d , &n, &m)) {       build(1, n, 1);       for (int i = 0; i < m; i++) {         int a, b, w;         scanf( %d%d%d , &a, &b, &w);         if (w - 1 >= a) update(a, w - 1, w, 1, n, 1);         if (w + 1 <= b) update(w + 1, b, w, 1, n, 1);       }       for (int i = 1; i <= n; i++)         printf(i == n ?  %d n  :  %d  , query(i, 1, n, 1));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string arr[12] = { C ,   C# ,  D ,   D# ,  E ,  F ,                      F# ,  G ,   G# ,  A ,   B ,  H },          a, b, c;   int ok(int a1, int a2, int a3) {     int dis1, dis2;     if (a2 > a1)       dis1 = a2 - a1;     else       dis1 = 12 - a1 + a2;     if (a3 > a2)       dis2 = a3 - a2;     else       dis2 = 12 - a2 + a3;     if (dis1 == 4 && dis2 == 3) return 1;     if (dis1 == 3 && dis2 == 4) return 0;     return 2;   }   int main() {     cin >> a >> b >> c;     int ind1, ind2, ind3;     for (int i = 0; i < 12; i++) {       if (arr[i] == a) ind1 = i;       if (arr[i] == b) ind2 = i;       if (arr[i] == c) ind3 = i;     }     if (ok(ind1, ind2, ind3) == 1 || ok(ind1, ind3, ind2) == 1 ||         ok(ind2, ind1, ind3) == 1 || ok(ind2, ind3, ind1) == 1 ||         ok(ind3, ind1, ind2) == 1 || ok(ind3, ind2, ind1) == 1)       cout <<  major  << endl;     else {       if (ok(ind1, ind2, ind3) == 0 || ok(ind1, ind3, ind2) == 0 ||           ok(ind2, ind1, ind3) == 0 || ok(ind2, ind3, ind1) == 0 ||           ok(ind3, ind1, ind2) == 0 || ok(ind3, ind2, ind1) == 0)         cout <<  minor  << endl;       else         cout <<  strange  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   ostream& operator<<(ostream& out, const vector<T>& v) {     out <<  [ ;     for (auto vi : v) out << vi <<  ,  ;     out <<  ] n ;     return out;   }   const int MAX_N = 1024;   const int MOD = 1e9 + 7;   struct RSQ {     static const int len = 1024;     vector<double> a = vector<double>(len * 2 + 1, 0.0);     void add(int i, double value, int node = 1, int l = 0, int r = len - 1) {       if (l <= i && i <= r) {         a[node] += value;         if (l < r) {           int m = (l + r) / 2;           add(i, value, node * 2, l, m);           add(i, value, node * 2 + 1, m + 1, r);         }       }     }     double sum(int ql, int qr, int node = 1, int l = 0, int r = len - 1) {       if (ql <= l && r <= qr) {         return a[node];       } else if (qr < l || r < ql) {         return 0;       } else {         int m = (l + r) / 2;         return sum(ql, qr, node * 2, l, m) + sum(ql, qr, node * 2 + 1, m + 1, r);       }     }   };   int n;   vector<vector<int> > a(MAX_N, vector<int>(MAX_N));   vector<vector<vector<int> > > _len2zero(       MAX_N, vector<vector<int> >(MAX_N, vector<int>(8, -1)));   const int DX[] = {-1, -1, 0, +1, +1, +1, 0, -1};   const int DY[] = {0, +1, +1, +1, 0, -1, -1, -1};   int len2zero(int x, int y, int dir) {     if (!(0 <= x && x < n && 0 <= y && y < n) || a[x][y] == 0) {       return 0;     }     int& res = _len2zero[x][y][dir];     if (res == -1) {       res = 1 + len2zero(x + DX[dir], y + DY[dir], dir);     }     return res;   }   RSQ sumLine[MAX_N * 2], sumColumn[MAX_N * 2], sumMainD[MAX_N * 2],       sumMinorD[MAX_N * 2];   long long solution() {     vector<double> ln({-1, log(1.0), log(2.0), log(3.0)});     for (int x = 0; x < n; x++) {       for (int y = 0; y < n; y++) {         sumLine[x].add(y, ln[a[x][y]]);         sumColumn[y].add(x, ln[a[x][y]]);         sumMainD[n + x - y].add(x, ln[a[x][y]]);         sumMinorD[x + y].add(x, ln[a[x][y]]);       }     }     tuple<double, int, int, int, bool> best;     for (int x = 0; x < n; x++) {       for (int y = 0; y < n; y++) {         int d = 100500;         for (int dir : {0, 2, 4, 6}) {           d = min(d, len2zero(x, y, dir));         }         if (d) d--;         double logSum = sumLine[x].sum(y - d, y + d) +                         sumColumn[y].sum(x - d, x + d) - ln[a[x][y]];         if (logSum > get<0>(best)) {           best = make_tuple(logSum, x, y, d, true);         }         d = 100500;         for (int dir : {1, 3, 5, 7}) {           d = min(d, len2zero(x, y, dir));         }         if (d) d--;         logSum = sumMainD[n + x - y].sum(x - d, x + d) +                  sumMinorD[x + y].sum(x - d, x + d) - ln[a[x][y]];         if (logSum > get<0>(best)) {           best = make_tuple(logSum, x, y, d, false);         }       }     }     double temp;     int x, y, d;     bool isNormal;     tie(temp, x, y, d, isNormal) = best;     long long result = a[x][y];     if (isNormal) {       for (int dd = 1; dd <= d; dd++) {         for (int dir : {0, 2, 4, 6}) {           result *= a[x + DX[dir] * dd][y + DY[dir] * dd];           result %= MOD;         }       }     } else {       for (int dd = 1; dd <= d; dd++) {         for (int dir : {1, 3, 5, 7}) {           result *= a[x + DX[dir] * dd][y + DY[dir] * dd];           result %= MOD;         }       }     }     return result;   }   void readData() {     cin >> n;     for (int i = 0; i < n; i++) {       string s;       cin >> s;       assert(s.size() == n);       for (int j = 0; j < (int)s.size(); j++) {         a[i][j] = s[j] -  0 ;       }     }   }   int main() {     ios::sync_with_stdio(false);     readData();     cout << solution() <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   class domino {    public:     int data[4];     bool IsEqual(domino b) {       for (long long move = 0; move <= 3; move++) {         bool f = true;         for (long long i = 0; i <= 3; i++)           if (data[i] != b.data[(i + move) % 4]) f = false;         if (f) return true;       }       return false;     }   };   vector<domino> a;   int main() {     int n;     cin >> n;     for (long long i = 1; i <= n; i++) {       domino temp;       string s;       cin >> s;       temp.data[0] = s[0] -  0 ;       temp.data[1] = s[1] -  0 ;       cin >> s;       temp.data[3] = s[0] -  0 ;       temp.data[2] = s[1] -  0 ;       bool f = true;       if (a.size() == 0) a.push_back(temp);       for (long long k = 0; k <= a.size() - 1; k++)         if (temp.IsEqual(a[k])) f = false;       if (f) a.push_back(temp);       if (i != n) cin >> s;     }     cout << a.size();   }


#include <bits/stdc++.h>   using namespace std;   const int dx[] = {-1, -2, -2, -1, 1, 2, 2, 1};   const int dy[] = {-2, -1, 1, 2, 2, 1, -1, -2};   set<pair<int, pair<int, int> > > heap;   vector<vector<int> > now;   int main() {     int n, m;     cin >> n >> m;     if (n >= 10 && m >= 10) {       cout << (m * n + 1) / 2 << endl;       return 0;     }     now.assign(n, vector<int>(m, 0));     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         int cnt = 1;         for (int k = 0; k < 8; k++) {           int nx = i + dx[k];           int ny = j + dy[k];           if (nx < 0 || nx >= n || ny < 0 || ny >= m) continue;           cnt++;         }         heap.insert(make_pair(cnt, make_pair(i, j)));         now[i][j] = cnt;       }     int ans = 0;     while (!heap.empty()) {       pair<int, pair<int, int> > v = *heap.begin();       heap.erase(heap.begin());       ans++;       int x = v.second.first;       int y = v.second.second;       for (int i = 0; i < 8; i++) {         int nx = x + dx[i];         int ny = y + dy[i];         if (nx < 0 || nx >= n || ny < 0 || ny >= m) continue;         int cnt = now[nx][ny];         if (heap.count(make_pair(cnt, make_pair(nx, ny)))) {           heap.erase(make_pair(cnt, make_pair(nx, ny)));           for (int j = 0; j < 8; j++) {             int x = nx + dx[j];             int y = ny + dy[j];             if (x < 0 || x >= n || y < 0 || y >= m) continue;             int cnt = now[x][y];             if (heap.count(make_pair(cnt, make_pair(x, y)))) {               heap.erase(make_pair(cnt, make_pair(x, y)));               now[x][y]--;               cnt--;               heap.insert(make_pair(cnt, make_pair(x, y)));             }           }         }       }     }     cout << max(ans, (m * n + 1) / 2) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     scanf( %d %d , &n, &k);     bool first = 1;     for (int i = n; i >= n - k + 1; --i) {       if (first) {         printf( %d , i);         first = !first;       } else         printf(  %d , i);     }     for (int i = 1; i <= n - k; ++i) {       if (first) {         printf( %d , i);         first = !first;       } else         printf(  %d , i);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     size_t rnn;     cin >> rnn;     size_t rnsize = 2 * rnn;     size_t rncnt = rnsize;     vector<long> rnvec(rnsize);     while (rncnt--) cin >> rnvec[rncnt];     sort(rnvec.begin(), rnvec.end());     long rnsum_fin = 999999;     long rnsum = 0;     for (size_t rncnt1 = 0; rncnt1 < rnsize; ++rncnt1)       for (size_t rncnt2 = 0; rncnt2 < rncnt1; ++rncnt2) {         rnsum = 0;         for (size_t rncnt3 = 0, rnpos = 0; rncnt3 < rnsize; ++rncnt3)           if (rncnt3 != rncnt1 && rncnt3 != rncnt2) {             ++rnpos;             if (rnpos % 2)               rnsum -= rnvec[rncnt3];             else               rnsum += rnvec[rncnt3];           }         rnsum_fin = min(rnsum, rnsum_fin);       }     cout << rnsum_fin;   }


#include <bits/stdc++.h>   using namespace std;   int n, ntot, ieven, rs[6], ord[6 + 1], iord[6 + 1];   vector<int> xs;   inline int imake(int i) { return i > 0 ? ord[i] : -ord[-i]; }   void iextend_even(int p, vector<int> &vi) {     vector<int> vr[2], vg;     vr[1] = vi;     for (int i = (int)vi.size() - 1; i >= 0; i--) vr[0].push_back(-vi[i]);     vr[0][0] = imake(p + 1);     vr[1][0] = imake(p + 1);     vg = vi;     for (int k = 1, l = 0; k < xs[p]; k++, l ^= 1) {       vg[vg.size() - k] = imake(-(p + 1));       vg.insert(vg.end() - k, vr[l].begin(), vr[l].end());     }     vi = vg;   }   void iextend_odd(int p, vector<int> &vi) {     vector<int> vr[2], vg;     vr[1] = vi;     for (int i = (int)vi.size() - 1; i >= 0; i--) vr[0].push_back(-vi[i]);     int vrz = vr[0][0];     vg = vi;     for (int k = 1, m = rs[p] - 1; k < xs[p]; k += 2, m -= 2) {       if (m > 0) {         vr[0][0] = imake(-(p + 1));         vg[vg.size() - k] = imake(p + 1);         vg.insert(vg.end() - k, vr[0].begin(), vr[0].end());         vg.insert(vg.end() - k, imake(p + 1));         vg.insert(vg.end() - k - 1, vr[1].begin(), vr[1].end());         vg.insert(vg.end() - k - 1 - vr[1].size(), imake(-(p + 1)));       } else {         vr[0][0] = vrz;         vg.push_back(imake(p + 1));         vg.insert(vg.end(), vr[0].begin(), vr[0].end());         vg.push_back(imake(p + 1));         vg.insert(vg.end(), vr[1].begin(), vr[1].end());       }     }     vi = vg;   }   vector<int> iinit_even() {     int p = xs[1];     vector<int> vg, vi;     for (int i = 0; i < p - 1; i++) vi.push_back(imake(2));     vi.push_back(imake(1));     for (int i = 0; i < p - 1; i++) vi.push_back(imake(-2));     vi.push_back(imake(-1));     vg = vi;     vi[0] = imake(1);     for (int i = 1, k = 2; i < xs[0] / 2; i++, k += 2) {       vg[vg.size() - k] = imake(-1);       vg.insert(vg.end() - k, vi.begin(), vi.end());     }     return vg;   }   vector<int> iinit_odd() {     int p = (rs[0] - 1) % 2, q = (rs[1] - 1) % 2, pp = xs[0], qq = xs[1], k, kl,         kr, ku, kd;     vector<int> vg, vil, virx, viry, viu, vid;     if (!(p == 1 && q == 1) && (p == 1 || q == 1)) return vg;     for (int i : {-1, -1, 2, 2, 1, -2}) vil.push_back(imake(i));     for (int i : {1, 2, 1, -2, -2, -1}) virx.push_back(imake(i));     for (int i : {1, 1, -2, -2, -1, 2}) viry.push_back(imake(i));     viu.resize(pp * 2);     vid.resize(pp * 2);     viu[0] = imake(2), viu[1] = imake(2), viu[pp + 1] = imake(-2);     vid[0] = imake(-2), vid[1] = imake(-2), vid[pp + 1] = imake(2);     for (int i = 2; i < pp + 1; i++) viu[i] = imake(1), vid[i] = imake(-1);     for (int i = pp + 2; i < pp * 2; i++) viu[i] = imake(-1), vid[i] = imake(1);     if (p == 1 && q == 1) {       for (int i : {1, -2, -1, -1, 2, 2, 1, 1}) vg.push_back(imake(i));       p++, q++, kl = 4, kr = 1, ku = 6, kd = 2;     } else if (rs[0] == 1 && rs[1] == 1) {       for (int i : {2, 2, 1, 1, -2, -2, -1, 2}) vg.push_back(imake(i));       p = q = 2, kl = 0, kr = 4, ku = 2, kd = 6;     } else if (rs[0] == 1 && rs[1] != 1) {       for (int i : {1, 1, -2, -2, -1, -1, 2, 1}) vg.push_back(imake(i));       p = q = 2, kl = 6, kr = 2, ku = 0, kd = 4;     } else if (rs[0] != 1 && rs[1] != 1) {       for (int i : {-2, -2, -1, -1, 2, 2, 1, -2}) vg.push_back(imake(i));       p = q = 2, kl = 4, kr = 0, ku = 6, kd = 2;     } else if (rs[0] != 1 && rs[1] == 1) {       for (int i : {-1, -1, 2, 2, 1, 1, -2, -1}) vg.push_back(imake(i));       p = q = 2, kl = 2, kr = 6, ku = 4, kd = 0;     }     if (p < rs[0] - 1 && ku == 0) ku = 8;     if (rs[0] - 1 < pp - 1 && kd == 0) kd = 8;     for (k = p; k < rs[0] - 1; k += 2, kl += 2) {       vg[kl] = imake(1);       vg.insert(vg.begin() + kl, vil.begin(), vil.end());       ku += 2;       kr > kl && (kr += 6);       kd > kl && (kd += 6);     }     if (kr == 1) {       for (; k < pp - 1; k += 2, kr += 4) {         vg[kr] = imake(-1);         vg.insert(vg.begin() + kr, virx.begin(), virx.end());         ku > kr && (ku += 6);         kd += 4;       }     } else {       for (; k < pp - 1; k += 2, kr += 2) {         vg[kr] = imake(-1);         vg.insert(vg.begin() + kr, viry.begin(), viry.end());         ku > kr && (ku += 6);         kd += 2;       }     }     for (k = q; k < rs[1] - 1; k += 2, kd += 2) {       vg[kd] = imake(2);       vg.insert(vg.begin() + kd, vid.begin(), vid.end());       ku > kd && (ku += vid.size());     }     for (; k < qq - 1; k += 2, ku += 2) {       vg[ku] = imake(-2);       vg.insert(vg.begin() + ku, viu.begin(), viu.end());     }     return vg;   }   inline void iapply(int *px, int op) {     op < 0 ? px[iord[-op] - 1]-- : px[iord[op] - 1]++;   }   bool iequal(int *px, int *py) {     for (int i = 0; i < n; i++)       if (px[i] != py[i]) return false;     return true;   }   void icycle(vector<int> &vi) {     int px[n], k;     for (int i = 1; i <= n; i++) iord[ord[i]] = i;     for (int i = 0; i < n; i++) px[i] = 1;     for (k = 0; k < (int)vi.size(); k++) {       if (iequal(px, rs)) break;       iapply(px, vi[k]);     }     if (k != 0) {       vi.insert(vi.end(), vi.begin(), vi.begin() + k);       vi.erase(vi.begin(), vi.begin() + k);     }   }   void iprint(vector<int> &vi) {     for (auto i : vi)       i > 0 ? (cout <<  inc   << i << endl) : (cout <<  dec   << -i << endl);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     ntot = 1;     xs.resize(n);     for (int i = 0; i < n; i++) cin >> xs[i], ntot *= xs[i];     for (int i = 0; i < n; i++) cin >> rs[i];     if (n == 1) {       if (xs[0] == 2 && rs[0] == 1) {         cout <<  Cycle  << endl;         cout <<  inc 1  << endl;         cout <<  dec 1  << endl;       } else if (xs[0] == 2 && rs[0] == 2) {         cout <<  Cycle  << endl;         cout <<  dec 1  << endl;         cout <<  inc 1  << endl;       } else if (rs[0] == 1) {         cout <<  Path  << endl;         for (int i = 1; i < xs[0]; i++) cout <<  inc 1  << endl;       } else if (rs[0] == xs[0]) {         cout <<  Path  << endl;         for (int i = 1; i < xs[0]; i++) cout <<  dec 1  << endl;       } else         cout <<  No  << endl;     } else {       for (int i = 1; i <= n; i++) ord[i] = i;       for (int i = 0; i < n; i++)         if (xs[i] % 2 == 0) {           swap(xs[0], xs[i]);           swap(rs[0], rs[i]);           swap(ord[1], ord[i + 1]);           break;         }       vector<int> vi;       if (xs[0] % 2 == 0) {         cout <<  Cycle  << endl;         vi = iinit_even();         for (int p = 2; p < n; p++) iextend_even(p, vi);         if (xs[ieven] % 2 == 0) icycle(vi);       } else {         for (int i = 1; i < n; i++)           if (rs[i] % 2 == 0) {             if (rs[0] % 2 != 0) {               swap(xs[0], xs[i]);               swap(rs[0], rs[i]);               swap(ord[1], ord[i + 1]);             } else if (rs[1] % 2 != 0) {               swap(xs[1], xs[i]);               swap(rs[1], rs[i]);               swap(ord[2], ord[i + 1]);             } else               break;           }         bool ok = true;         for (int i = 2; i < n; i++)           if (rs[i] % 2 == 0) ok = false;         vi = iinit_odd();         if (vi.size() == 0 || !ok) {           cout <<  No  << endl;           vi.clear();         } else {           cout <<  Path  << endl;           for (int p = 2; p < n; p++) iextend_odd(p, vi);         }       }       iprint(vi);     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int t;     scanf( %d , &t);     while (t--) {       int n, i;       scanf( %d , &n);       if (n % 4 != 0)         printf( NO n );       else {         printf( YES n );         int sum1 = 0, sum2 = 0;         for (i = 0; i < n / 2; i++) {           printf( %d  , 2 * (i + 1));           sum1 += 2 * (i + 1);         }         for (i = 0; i < n / 2 - 1; i++) {           printf( %d  , 2 * (i + 1) - 1);           sum2 += 2 * (i + 1) - 1;         }         printf( %d n , sum1 - sum2);       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N_ = 105;   int N, M, X, Y;   int len(int x) {     for (int l = 1, v = 7;; l++) {       if (v >= x) return l;       v *= 7;     }   }   set<long long> S;   bool chk[100];   void dfs(int i, long long p, long long q) {     if (p >= N || q >= M) return;     if (i == X + Y) {       S.insert(p * (long long)1e9 + q);       return;     }     for (int d = 0; d < 7; d++) {       if (!chk[d]) {         chk[d] = true;         ((i < X ? p : q) *= 7) += d;         dfs(i + 1, p, q);         ((i < X ? p : q) -= d) /= 7;         chk[d] = false;       }     }   }   int main() {     scanf( %d %d , &N, &M);     X = len(N), Y = len(M);     if (X + Y > 7) return 0 & puts( 0 );     dfs(0, 0, 0);     printf( %lu n , S.size());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 85;   long long fibo[N + 5];   long long dp[N + 5][3][3];   long long arr[N + 5];   void pre() {     fibo[0] = 1, fibo[1] = 2;     for (int i = 2; i <= N; i++) {       fibo[i] = fibo[i - 1] + fibo[i - 2];     }   }   long long solve(int idx, int cur1, int cur2) {     if (idx == -1) {       if (cur1 + cur2 != 0) return 0;       return 1;     }     long long &res = dp[idx][cur1][cur2];     if (res != -1) return res;     res = 0;     if (cur1 + arr[idx] > 2) return 0;     if (cur1 + arr[idx] <= 1) res += solve(idx - 1, cur2, 0);     if (cur1 + arr[idx] == 1) res += solve(idx - 1, cur2 + 1, 1);     if (cur1 + arr[idx] == 2) res += solve(idx - 1, cur2 + 1, 1);     return res;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     pre();     int ntc;     cin >> ntc;     while (ntc--) {       long long x;       cin >> x;       for (int i = N; i >= 0; i--) {         arr[i] = 0;         if (x < fibo[i]) continue;         x -= fibo[i];         arr[i] = 1;       }       memset(dp, -1, sizeof dp);       cout << solve(N, 0, 0) << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100100;   const long long MOD = 100030001, H = 47;   map<int, long long> d[N];   vector<int> adj[N];   set<pair<long long, int> > s;   vector<pair<int, pair<long long, int> > > nei[N];   long long r[N], l[N], num[N], ch[N], h[3 * N], n, sz, ans, o = 10, c = 11;   void add(int ind, int val) {     auto it = s.lower_bound({ind, val});     if (it == s.end() || it->first != ind)       s.insert({ind, val});     else {       if (it->second + val != 0) s.insert({ind, it->second + val});       s.erase(it);     }     return;   }   void f(int v, int u) {     add(d[v][v], -1);     add(d[u][u], 1);     add(d[v][u], 1);     add(d[u][v], -1);     return;   }   void DFS1(int v, int par = 0) {     for (int u : adj[v]) {       if (u != par) {         DFS1(u, v);         ch[v] += ch[u];         nei[v].push_back({d[u][v], {ch[u], u}});       }     }     ch[v]++;     long long ans = o;     sort(nei[v].begin(), nei[v].end());     for (auto u : nei[v]) {       ans = ans * h[2 * u.second.first] % MOD;       ans = (ans + u.first) % MOD;     }     d[v][par] = (ans * H + c) % MOD;     return;   }   void DFS2(int v, int par = 0) {     nei[v].clear();     for (int u : adj[v]) {       nei[v].push_back({d[u][v], {ch[u], u}});       if (u == par) nei[v].back().second.first = n - ch[v];     }     sort(nei[v].begin(), nei[v].end());     l[0] = o, r[nei[v].size() + 1] = c, num[nei[v].size() + 1] = 1;     for (int i = 1; i <= nei[v].size(); i++) {       auto u = nei[v][i - 1];       l[i] = (l[i - 1] * h[u.second.first * 2] + d[u.second.second][v]) % MOD;     }     for (int i = nei[v].size(); i > 0; i--) {       auto u = nei[v][i - 1];       num[i] = num[i + 1] + u.second.first * 2;       r[i] = (r[i + 1] + d[u.second.second][v] * h[num[i + 1]]) % MOD;     }     for (int i = 0; i < nei[v].size(); i++) {       d[v][nei[v][i].second.second] = (l[i] * h[num[i + 2]] + r[i + 2]) % MOD;     }     for (int u : adj[v])       if (u != par) DFS2(u, v);     add(d[v][par], 1);     return;   }   void DFS3(int v, int par = 0) {     if (s.size() > sz) {       ans = v;       sz = s.size();     }     for (int u : adj[v]) {       if (u != par) {         f(v, u);         DFS3(u, v);       }     }     f(v, par);     return;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int u, v;     cin >> n;     h[0] = 1;     for (int i = 0; i <= n * 2 + 10; i++) h[i + 1] = h[i] * H % MOD;     for (int i = 1; i < n; i++) {       cin >> u >> v;       adj[--u].push_back(--v);       adj[v].push_back(u);     }     if (n == 1) {       cout << 1 << endl;       return 0;     }     DFS1(0);     DFS2(0);     DFS3(0);     cout << ans + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct MinCostFlow {     struct Edge {       int t;       int f;       int c;       Edge *next, *rev;       Edge(int _t, int _f, int _c, Edge* _next)           : t(_t), f(_f), c(_c), next(_next) {}     };     vector<Edge*> E;     int addV() {       E.push_back((Edge*)0);       return E.size() - 1;     }     Edge* makeEdge(int s, int t, int f, int c) {       return E[s] = new Edge(t, f, c, E[s]);     }     void addEdge(int s, int t, int f, int c) {       Edge *e1 = makeEdge(s, t, f, c), *e2 = makeEdge(t, s, 0, -c);       e1->rev = e2, e2->rev = e1;     }     pair<int, int> minCostFlow(int vs, int vt, bool maxFlow) {       int n = E.size();       int flow = 0;       int cost = 0;       const int MAX_COST = ~0U >> 1;       const int MAX_FLOW = ~0U >> 1;       for (;;) {         vector<int> dist(n, MAX_COST);         vector<int> am(n, 0);         vector<Edge*> prev(n);         vector<bool> inQ(n, false);         queue<int> que;         dist[vs] = 0;         am[vs] = MAX_FLOW;         que.push(vs);         inQ[vs] = true;         while (!que.empty()) {           int u = que.front();           int c = dist[u];           que.pop();           inQ[u] = false;           for (Edge* e = E[u]; e; e = e->next)             if (e->f > 0) {               int nc = c + e->c;               if (nc < dist[e->t]) {                 dist[e->t] = nc;                 prev[e->t] = e;                 am[e->t] = min(am[u], e->f);                 if (!inQ[e->t]) {                   que.push(e->t);                   inQ[e->t] = true;                 }               }             }         }         if (maxFlow) {           if (dist[vt] == MAX_COST) break;         } else {           if (dist[vt] >= 0) break;         }         int by = am[vt];         int u = vt;         flow += by;         cost += by * dist[vt];         while (u != vs) {           Edge* e = prev[u];           e->f -= by;           e->rev->f += by;           u = e->rev->t;         }       }       return make_pair(flow, cost);     }   };   const int MAX_N = 100 + 10;   int n, m;   string how[MAX_N];   int A[MAX_N], B[MAX_N];   int ia[MAX_N], ib[MAX_N];   int notKillAll() {     MinCostFlow net;     int vs = net.addV(), vt = net.addV();     for (int i = 0; i < n; ++i) {       ia[i] = net.addV();       net.addEdge(vs, ia[i], 1, 0);     }     for (int i = 0; i < m; ++i) {       ib[i] = net.addV();       net.addEdge(ib[i], vt, 1, 0);     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         if (B[j] > A[i] && how[i] ==  ATK ) {           net.addEdge(ia[i], ib[j], 1, -(B[j] - A[i]));         }       }     }     return -net.minCostFlow(vs, vt, false).second;   }   int killAll() {     MinCostFlow net;     int vs = net.addV(), vt = net.addV();     for (int i = 0; i < m; ++i) {       ia[i] = net.addV();       net.addEdge(vs, ia[i], 1, 0);     }     for (int i = 0; i < m; ++i) {       ib[i] = net.addV();       net.addEdge(ib[i], vt, 1, 0);     }     for (int i = 0; i < m; ++i) {       for (int j = 0; j < m; ++j) {         if (i < n) {           if (how[i] ==  ATK ) {             if (B[j] >= A[i]) net.addEdge(ia[i], ib[j], 1, -(B[j] - A[i]));           } else {             if (B[j] > A[i]) net.addEdge(ia[i], ib[j], 1, 0);           }         } else {           net.addEdge(ia[i], ib[j], 1, -B[j]);         }       }     }     pair<int, int> ret = net.minCostFlow(vs, vt, true);     if (ret.first == m) return -ret.second;     return 0;   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; ++i) {       cin >> how[i] >> A[i];     }     for (int i = 0; i < m; ++i) {       cin >> B[i];     }     int ans = notKillAll();     if (m > n) ans = max(ans, killAll());     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int k;   bool debug = false;   char mp[170][170];   int l[170], r[170];   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       scanf( %s , mp[i]);       l[i] = m;       r[i] = -1;       for (int j = 0; j < m; j++)         if (mp[i][j] ==  W ) {           l[i] = j;           break;         }       for (int j = m - 1; j >= 0; j--)         if (mp[i][j] ==  W ) {           r[i] = j;           break;         }     }     int ans = 0, pos = 0, dir = 1;     for (int i = 0, j = 1; i < n; i = j) {       j = i + 1;       while (j < n && r[j] == -1) j++;       if (r[i] != -1) {         if (dir == 1) {           ans += r[i] - pos;           pos = r[i];         } else {           ans += pos - l[i];           pos = l[i];         }       }       if (j == n)         break;       else {         dir = (j - i) % 2 == 1 ? 1 - dir : dir;         int npos;         if (dir == 1) {           npos = min(l[j], pos);         } else {           npos = max(r[j], pos);         }         ans += abs(npos - pos);         pos = npos;         ans += (j - i);       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     vector<long long> cnt(26);     string s;     for (int ss = 0; ss < (int)n; ss++) {       cin >> s;       for (int i = 0; i < (int)s.size(); i++) s[i] -=  a ;       int nfst = 0, nlst = 0;       while (nfst < s.size() && s[nfst] == s[0]) nfst++;       while (nlst < s.size() && s[s.size() - nlst - 1] == s.back()) nlst++;       vector<long long> old(cnt);       fill(cnt.begin(), cnt.end(), 0);       for (int i = 0; i < (int)26; i++) cnt[i] = old[i] > 0;       if (nfst == s.size())         cnt[s[0]] = (old[s[0]] + 1) * nfst + old[s[0]];       else if (s[0] == s.back()) {         if (old[s[0]]) cnt[s[0]] = nfst + 1 + nlst;       } else {         if (old[s[0]]) cnt[s[0]] = nfst + 1;         if (old[s.back()]) cnt[s.back()] = 1 + nlst;       }       char cur = s[0];       long long streak = 1;       cnt[cur] = max(cnt[cur], streak);       for (int i = 1; i < s.size(); i++) {         if (s[i] == cur)           streak++;         else {           cur = s[i];           streak = 1;         }         cnt[cur] = max(cnt[cur], streak);       }       for (int i = 0; i < (int)26; i++) cnt[i] = min(cnt[i], (long long)1e9);     }     long long ans = 0;     for (int i = 0; i < (int)26; i++) ans = max(ans, cnt[i]);     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<long long, long long> > v;   map<long long, long long> m;   int qpow(long long a, long long b, long long m) {     long long c = 1;     while (b) {       if (b & 1) c = c * a % m;       b >>= 1;       a = a * a % m;     }     return c;   }   int main() {     ios::sync_with_stdio(false);     long long num, n, s, t;     cin >> n >> s;     if (8 * s / n < 63) {       num = pow(2, 8 * s / n);     } else {       num = 0x7fffffffffffffff;     }     for (int i = (0); i < (n); ++i) {       cin >> t;       if (m.count(t) == 0) {         v.push_back(make_pair(t, 0));         m[t] = 1;       } else {         m[t]++;       }     }     int len = v.size();     for (int i = (0); i < (len); ++i) {       v[i].second = m[v[i].first];     }     sort(v.begin(), v.end());     long long l = -1, r = len;     long long ans = 0;     while (l < r && len > num) {       l++;       ans += v[l].second;       len--;     }     long long minn = ans;     while (l >= 0) {       if (l >= r) {         cout << n;         return 0;       }       ans -= v[l].second;       len++;       l--;       while (len > num) {         r--;         ans += v[r].second;         len--;       }       minn = min(ans, minn);     }     cout << minn;     return 0;   }


#include <bits/stdc++.h>   int inp() {     char c = getchar();     int neg = 1;     while (c <  0  || c >  9 ) {       if (c ==  - ) neg = -1;       c = getchar();     }     int sum = 0;     while (c >=  0  && c <=  9 ) {       sum = sum * 10 + c -  0 ;       c = getchar();     }     return sum * neg;   }   int n, p;   int main() {     n = inp();     p = inp();     for (int i = 1; i <= 1000; i++) {       if (n - (i * p) <= 0) break;       if (__builtin_popcount(n - (i * p)) <= i && i <= (n - (i * p))) {         printf( %d n , i);         return 0;       }     }     printf( -1 n );   }


#include <bits/stdc++.h>   using namespace std;   long long int sum, max_lev;   vector<pair<long long int, long long int>> level[5010];   vector<long long int> adj[5010];   vector<pair<long long int, long long int>> store[5010];   vector<pair<pair<long long int, long long int>, long long int>> v;   long long int vis[5010];   void bfs(long long int s, long long int lev) {     queue<pair<long long int, long long int>> q;     q.push(make_pair(s, lev));     vis[s] = 1;     while (!q.empty()) {       s = q.front().first;       lev = q.front().second;       for (long long int i = 0; i < store[s].size(); i++) {         level[lev].push_back(make_pair(store[s][i].first, store[s][i].second));         sum += store[s][i].first;       }       q.pop();       max_lev = max(lev, max_lev);       for (long long int i = 0; i < adj[s].size(); i++) {         if (vis[adj[s][i]] == 0) {           vis[adj[s][i]] = 1;           q.push(make_pair(adj[s][i], lev + 1));         }       }     }   }   bool check(long long int mid, long long int max_cost, long long int tot) {     long long int cost = 0, curr = 0, p, rem, i, j;     for (i = 0; i < v.size(); i++) {       if (v[i].second > mid) continue;       p = v[i].first.first * v[i].first.second;       if (cost + p > max_cost) {         rem = max_cost - cost;         p = rem / v[i].first.first;         curr += p;         break;       }       curr += v[i].first.second;       cost += p;     }     if (curr >= tot) return true;     return false;   }   long long int bs(long long int low, long long int high, long long int max_cost,                    long long int tot) {     long long int ans = -1;     while (low <= high) {       long long int mid = (low + high) / 2;       if (check(mid, max_cost, tot)) {         high = mid - 1;         ans = mid;       } else {         low = mid + 1;       }     }     return ans;   }   int main() {     long long int n, m, a, b, i, w, c, k, p, q, g, r, j;     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (i = 1; i <= m; i++) {       cin >> a >> b;       adj[a].push_back(b);       adj[b].push_back(a);     }     cin >> w;     for (i = 1; i <= w; i++) {       cin >> c >> k >> p;       store[c].push_back(make_pair(k, p));     }     cin >> q;     while (q--) {       sum = max_lev = 0;       cin >> g >> r >> a;       for (i = 0; i <= n; i++) level[i].clear();       v.clear();       memset(vis, 0, sizeof(vis));       bfs(g, 0);       if (sum < r) {         cout <<  -1 n ;         continue;       }       for (i = 0; i <= max_lev; i++) {         for (j = 0; j < level[i].size(); j++) {           v.push_back(               make_pair(make_pair(level[i][j].second, level[i][j].first), i));         }       }       sort(v.begin(), v.end());       cout << bs(0, max_lev, a, r) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 4000010, maxm = 2010;   long long s[maxn], f[maxn], P[maxm], Q[maxm];   int a, b, c, p[maxm], vis[maxm], mu[maxm];   void inc(long long &a, long long b) {     a += b;     if (a > (1ll << 30)) a -= (1ll << 30);   }   int main() {     scanf( %d%d%d , &a, &b, &c);     mu[1] = 1;     for (int i = 2; i <= c; i++) {       if (!vis[i]) p[++p[0]] = i, mu[i] = -1;       for (int j = 1; j <= p[0] && i * p[j] <= c; j++) {         vis[i * p[j]] = 1;         if (i % p[j] == 0) {           mu[i * p[j]] = 0;           break;         } else           mu[i * p[j]] = -mu[i];       }     }     for (int i = 1; i <= a; i++)       for (int j = 1; j <= b; j++) f[i * j]++;     for (int i = 1; i <= a * b; i++)       for (int j = 1; j <= a * b / i; j++) inc(s[i], f[i * j]);     for (int i = 1; i <= c; i++)       for (int j = 1; j <= a * b / i; j++) inc(P[i], s[i * j]);     for (int i = 1; i <= c; i++)       for (int j = 1; j <= i; j++) inc(Q[i], i / j);     long long ans = 0;     for (int i = 1; i <= c; i++)       ans = (ans + mu[i] * P[i] * Q[c / i] % (1ll << 30)) % (1ll << 30);     printf( %I64d , (ans + (1ll << 30)) % (1ll << 30));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a;     cin >> a;     while (a--) {       int b, c;       cin >> b >> c;       int arr1[b], arr2[c];       set<int> check;       for (int j = 0; j < b; j++) {         cin >> arr1[j];         check.insert(arr1[j]);       }       int x = -1;       for (int j = 0; j < c; j++) {         cin >> arr2[j];         if (check.count(arr2[j])) x = arr2[j];       }       if (x == -1)         cout <<  NO n ;       else {         cout <<  YES n ;         cout <<  1               <<     << x <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > g[110];   int seen[110][110];   int c[110];   int ans;   void dfs(int s, int end, int color) {     if (s == end && c[color] == 0) {       c[color] = 1;       ans++;       return;     }     for (int i = 0; i < (int)g[s].size(); i++) {       if ((color == 0 || color == g[s][i].second) &&           seen[s][g[s][i].first] == 0 && seen[g[s][i].first][s] == 0) {         seen[s][g[s][i].first] = 1;         seen[g[s][i].first][s] = 1;         dfs(g[s][i].first, end, g[s][i].second);         seen[s][g[s][i].first] = 0;         seen[g[s][i].first][s] = 0;       }     }   }   int main() {     int n, m;     scanf( %d %d , &n, &m);     int temp1, temp2, temp3;     for (int i = 0; i < m; i++) {       scanf( %d %d %d , &temp1, &temp2, &temp3);       g[temp1].push_back(pair<int, int>(temp2, temp3));       g[temp2].push_back(pair<int, int>(temp1, temp3));     }     int q;     scanf( %d , &q);     for (int i = 0; i < q; i++) {       scanf( %d %d , &temp1, &temp2);       dfs(temp1, temp2, 0);       printf( %d n , ans);       ans = 0;       for (int i = 0; i < 110; i++)         for (int j = 0; j < 110; j++) seen[i][j] = 0;       for (int i = 0; i < 110; i++) c[i] = 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int n, t, m = 0;     cin >> n;     vector<int> s;     for (int i = 0; i < n; i++) {       cin >> t;       s.push_back(t);     }     sort(s.begin(), s.end());     while (true) {       t = -1;       for (int i = 0; i < n; i++) {         if (s[i] != -1 && s[i] >= t + 1) {           s[i] = -1;           t++;         }       }       if (t == -1) break;       m++;     }     cout << m << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char a[20][20], ans[20];   int n, m;   bool isValid() {     for (int i = 2; i <= n; i++) {       int c = 0;       for (int j = 1; j <= m; j++) c += (ans[j] != a[i][j]);       if (c > 1) return false;     }     return true;   }   void fun() {     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> (a[i] + 1);     for (int i = 1; i <= m; i++) ans[i] = a[1][i];     ans[m + 1] =   0 ;     if (isValid())       cout << (ans + 1) <<   n ;     else {       bool isGood = false;       for (int i = 1; i <= m && !isGood; i++) {         for (char c =  a ; c <=  z  && !isGood; c++) {           if (c != a[1][i]) {             ans[i] = c;             if (isValid()) {               cout << (ans + 1) <<   n ;               isGood = true;             }           }         }         ans[i] = a[1][i];       }       if (!isGood) cout <<  -1 n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       fun();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   bool umin(T& a, T b) {     if (a > b) {       a = b;       return 1;     }     return 0;   }   template <class T>   bool umax(T& a, T b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   int main() {     int n, x = 500;     scanf( %d , &n);     for (int i = 0; i < 26 and (n or !i); i++) {       while (x * (x - 1) / 2 > n) x--;       n -= x * (x - 1) / 2;       for (int j = 0; j < x; j++) printf( %c , char(i + 97));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[100005];   int n, k, cnt[20];   bool a[20][20], mark[1 << 17], tmp[1 << 17];   inline void work(int x, int y) {     memset(tmp, 0, sizeof(tmp));     for (int i = 1, j, t; i <= n;) {       while (i <= n && s[i] -  a  != x) i++;       j = i + 1;       t = 0;       while (j <= n && s[j] -  a  != x && s[j] -  a  != y) {         t |= 1 << s[j] -  a ;         j++;       }       if (j > n) break;       if (s[j] -  a  == y) tmp[t] = 1;       if (s[j] -  a  == x)         i = j;       else         i = j + 1;     }     for (int i = 1; i < 1 << k; i++) {       if (!tmp[i]) continue;       mark[i] = 1;       for (int j = 0; j < k; j++)         if (j != x && j != y) tmp[i | 1 << j] = 1;     }   }   bool f[1 << 17];   int main() {     cin >> n >> k;     scanf( %s , s);     for (int i = 0; i < n; i++) cnt[s[i] -  a ]++;     for (int i = 0; i < k; i++)       for (int j = 0; j < k; j++) {         cin >> a[i][j];         if (!a[i][j]) work(i, j);       }     f[0] = 1;     for (int i = 0; i < 1 << k; i++) {       if (!f[i]) continue;       for (int j = 0; j < k; j++)         if (!mark[i | 1 << j]) f[i | 1 << j] = 1;     }     int ans = 0;     for (int i = 0; i < 1 << k; i++) {       if (!f[i]) continue;       int t = 0;       for (int j = 0; j < k; j++)         if (i & 1 << j) t += cnt[j];       ans = max(ans, t);     }     cout << n - ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e6 + 10;   const long long inf = 1e15;   const int mod = 1e6;   void faster() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   const long long N = 3000 * 200;   int mark[N];   int main() {     faster();     int n;     cin >> n;     int t = 0;     vector<int> v[n];     for (int i = 1; i <= n * n; i++) {       v[(i + t) % n].push_back(i);       if (i % n == 0) t++;     }     for (int i = 0; i < n; i++) {       for (auto c : v[i]) cout << c <<    ;       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100000 + 5;   const long long mod = 99999997;   long long a[maxn], k, n;   void dfs(long long l, long long r) {     if (l + 1 >= r || !k) return;     long long mid = (l + r) / 2;     k -= 2;     swap(a[mid - 1], a[mid]);     dfs(l, mid);     dfs(mid, r);   }   int main() {     cin >> n >> k;     if (k > 2 * n - 1 || k % 2 == 0) {       cout <<  -1  << endl;       return 0;     }     for (int i = 0; i < n; i++) {       a[i] = i + 1;     }     k--;     dfs(0ll, n);     for (int i = 0; i < n; i++) cout << a[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void smax(T &x, T y) {     x = max((x), (y));   }   template <class T>   inline void smin(T &x, T y) {     x = min((x), (y));   }   inline void scanInt(int &x) {     register char c = getchar();     x = 0;     bool neg = false;     while (c < 48 || c > 57) {       if (c ==  - ) neg = true;       c = getchar();     }     for (; c > 47 && c < 58; c = getchar()) {       x = (x << 1) + (x << 3) + c - 48;     }     if (neg) x *= -1;   }   int n, m;   string origin;   string s;   bool place_char_start(int inx) {     if (inx >= 2) {       for (char i = s[inx] + 1; i <  a  + m; i++)         if (i != s[inx - 1] && i != s[inx - 2] && i != s[inx]) {           s[inx] = i;           return true;         }       return false;     } else if (inx == 1) {       for (char i = s[inx] + 1; i <  a  + m; i++)         if (i != s[inx - 1] && i != s[inx]) {           s[inx] = i;           return true;         }       return false;     } else if (inx == 0) {       s[0] = s[0] + 1;       if (s[0] >=  a  + m) return false;       return true;     }     return false;   }   bool place_char(int inx) {     if (inx >= 2) {       for (char i =  a ; i <  a  + m; i++)         if (i != s[inx - 1] && i != s[inx - 2]) {           s[inx] = i;           return true;         }       return false;     } else if (inx == 1) {       for (char i =  a ; i <  a  + m; i++)         if (i != s[inx - 1]) {           s[inx] = i;           return true;         }     } else if (inx == 0) {       s[0] =  a ;       return true;     }     return false;   }   int main(int argc, const char *argv[]) {     scanInt(n);     scanInt(m);     cin >> s;     origin = s;     for (int i = (int)s.size() - 1; i >= 0; i--) {       s = origin;       bool ok = true;       ok &= place_char_start(i);       for (int j = i + 1; ok && j < s.size(); j++) {         if (place_char(j) == false) ok = false;       }       if (ok) {         cout << s;         return 0;       }     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct event {     int x[3], id;     event() { x[0] = x[1] = x[2] = id = 0; }     event(int xx, int yy, int zz, int idd) {       x[0] = xx;       x[1] = yy;       x[2] = zz;       id = idd;     }   };   int vc = 0;   bool operator<(const event &a, const event &b) {     if (a.x[vc] == b.x[vc]) return a.id < b.id;     return a.x[vc] < b.x[vc];   }   int ans[100005], ans_id[100005];   event G[3][200005];   void cdq(int L, int R, int now) {     if (L >= R) return;     vc = now;     if (now == 2) {       int last = -1, last_id = -1;       for (int i = L; i <= R; ++i) {         if (G[now][i].id > 0) {           if (last_id != -1) {             int &tmp = ans[G[now][i].id];             if (tmp == -1 || tmp < last) {               tmp = last;               ans_id[G[now][i].id] = last_id;             }           }         } else {           last = G[now][i].x[2];           last_id = -G[now][i].id;         }       }       return;     }     int mid = (L + R) / 2, cnt = 0;     cdq(L, mid, now);     for (int i = L; i <= mid; ++i)       if (G[now][i].id < 0) G[now + 1][++cnt] = G[now][i];     for (int i = mid + 1; i <= R; ++i)       if (G[now][i].id > 0) G[now + 1][++cnt] = G[now][i];     vc = now + 1;     sort(G[now + 1] + 1, G[now + 1] + cnt + 1);     cdq(1, cnt, now + 1);     cdq(mid + 1, R, now);   }   int main() {     int n, m, i, j, k, l, cnt = 0;     scanf( %d%d , &n, &m);     for (i = 1; i <= n; ++i) {       int x, y, z;       scanf( %d%d%d , &x, &y, &z);       G[0][++cnt] = event(x, -y, -z, -i);     }     for (i = 1; i <= m; ++i) {       int x, y, z;       scanf( %d%d%d , &x, &y, &z);       G[0][++cnt] = event(x, -y, -z, i);     }     memset(ans, -1, sizeof(ans));     memset(ans_id, -1, sizeof(ans));     vc = 0;     sort(G[0] + 1, G[0] + 1 + cnt);     cdq(1, cnt, 0);     for (i = 1; i <= m; ++i) printf( %d%c , ans_id[i],    n [i == m]);   }


#include <bits/stdc++.h>   using namespace std;   vector<multiset<int> > G;   vector<int> d;   void dfs(int u, vector<int> &ans) {     while (!G[u].empty()) {       int v = *G[u].begin();       G[u].erase(G[u].begin());       G[v].erase(G[v].find(u));       dfs(v, ans);     }     ans.push_back(u);   }   int main() {     int n, m;     cin >> n >> m;     G.resize(n);     d.resize(n, 0);     for (int i = 0; i < m; i++) {       int u, v;       scanf( %d %d , &u, &v);       u--;       v--;       G[u].insert(v);       G[v].insert(u);       d[u]++;       d[v]++;     }     vector<int> odd;     for (int i = 0; i < n; i++) {       if (d[i] & 1) odd.push_back(i);     }     int add = 0;     for (int i = 0; i < (int)odd.size() - 1; i += 2) {       int u = odd[i], v = odd[i + 1];       G[u].insert(v);       G[v].insert(u);       add++;     }     if (odd.size() & 1) {       int u = odd[odd.size() - 1];       G[u].insert(u);       G[u].insert(u);       add++;     }     if ((m + add) % 2) {       G[0].insert(0);       G[0].insert(0);       add++;     }     vector<int> ans;     dfs(0, ans);     cout << m + add << endl;     for (int i = 0; i < (int)ans.size() - 1; i++) {       if (i & 1)         printf( %d %d n , ans[i] + 1, ans[i + 1] + 1);       else         printf( %d %d n , ans[i + 1] + 1, ans[i] + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int arr[30] = {0};     unsigned long long sum = 0;     long long int a, b, n;     cin >> n;     for (int i = 0; i < n; i++) {       int j = 0;       cin >> a;       while (a != 0) {         b = a % 10;         arr[j] += b;         arr[j + 1] += b;         a /= 10;         j += 2;       }     }     for (unsigned long long int i = 0, ten = 1; i < 30; i++, ten = ten * 10) {       if (!arr[i]) continue;       arr[i] *= n;       unsigned long long x =           ((arr[i] % 998244353) * (ten % 998244353)) % 998244353;       sum = (sum + x) % 998244353;     }     cout << sum << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   int main() {     int n;     cin >> n;     long long int x = 2;     double d;     long long int p;     for (long long int i = 1; i <= n; i++) {       long long int B = i * (i + 1) * (i + 1) - x / i;       cout << B <<   n ;       x = i * (i + 1);     }   }


#include <bits/stdc++.h>   using namespace std;   string grid[8];   int get_weight(char c) {     switch (c) {       case  q :         return 9;       case  r :         return 5;       case  b :       case  n :         return 3;       case  p :         return 1;       default:         return 0;     }   }   int main() {     ios_base::sync_with_stdio(0);     for (int i = 0; i < 8; ++i) cin >> grid[i];     int black = 0, white = 0;     for (int i = 0; i < 8; ++i)       for (int j = 0; j < 8; ++j) {         bool play1 = isupper(grid[i][j]);         int score = get_weight(tolower(grid[i][j]));         if (play1)           black += score;         else           white += score;       }     if (black == white)       cout <<  Draw ;     else if (black > white)       cout <<  White ;     else       cout <<  Black ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   char s[21][100100];   int n, m, ans = 1e9, all, inv, a[100100], bit[1100000], w[1100000], f[1100000];   int power(int a, int k) {     int ret = 1;     while (k) {       if (k & 1) ret = 1ll * ret * a % mod;       a = 1ll * a * a % mod;       k >>= 1;     }     return ret;   }   void FWT(int *a, int t) {     int pre, cur = 0;     static int f[2][1100000];     for (int i = 0; i <= all; i++) f[0][i] = a[i];     for (int i = 0; i <= n - 1; i++) {       pre = cur, cur ^= 1;       for (int s = 0; s <= all; s++)         if (!(s >> i & 1)) {           int l = f[pre][s], r = f[pre][s | (1 << i)];           f[cur][s] = (l + r) % mod;           f[cur][s | (1 << i)] = (l + mod - r) % mod;         }     }     if (t)       for (int i = 0; i <= all; i++) f[cur][i] = 1ll * f[cur][i] * inv % mod;     for (int i = 0; i <= all; i++) a[i] = f[cur][i];   }   int main() {     scanf( %d%d , &n, &m);     all = (1 << n) - 1;     inv = power(power(2, mod - 2), n);     for (int i = 1; i <= n; i++) scanf( %s , s[i] + 1);     for (int i = 1; i <= m; i++)       for (int j = 1; j <= n; j++) a[i] = (a[i] << 1) + s[j][i] -  0 ;     for (int i = 1; i <= all; i++) bit[i] = bit[i >> 1] + (i & 1);     for (int i = 1; i <= m; i++) f[a[i]]++;     for (int i = 0; i <= all; i++) w[i] = min(bit[i], n - bit[i]);     FWT(f, 0);     FWT(w, 0);     for (int i = 0; i <= all; i++) f[i] = 1ll * f[i] * w[i] % mod;     FWT(f, 1);     for (int i = 0; i <= all; i++) ans = min(ans, f[i]);     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int lim = 1e5 + 5;   int main(int argc, char const *argv[]) {     int n;     cin >> n;     std::vector<int> v(n);     for (int i = 0; i < n; ++i) {       cin >> v[i];     }     int mn = INT_MAX, ind1, ind2;     for (int i = 0; i < n - 1; ++i) {       int dif = abs(v[i] - v[i + 1]);       if (mn > dif) {         mn = dif;         ind1 = i + 1;         ind2 = i + 2;       }     }     int dif = abs(v[0] - v[n - 1]);     if (mn > dif) {       mn = dif;       ind1 = 1;       ind2 = n;     }     cout << ind1 <<     << ind2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   typedef long long ll;   #define endl   n    const int DIM = 1E5+7;   int A[DIM];   int cnt[2][DIM];   int solve() {       int n;       cin>>n;       for(int i = 1;i<=n;++i){           cin>>A[i];           ++cnt[i%2][A[i]];       }       sort(A+1,A+1+n);       int flag = 0;       for(int i = 1;i<=n;++i){           cnt[i%2][A[i]]--;       }       for(int i = 1;i<=n;++i){           if (cnt[0][A[i]] || cnt[1][A[i]])               flag = 1;           cnt[0][A[i]] = cnt[1][A[i]] = 0;       }       if (flag)           cout<< NO n ;       else cout<< YES n ;          return 1;   }   int main() {       ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);          int t;       cin>>t;       while(t--)           assert(solve());   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   string s, t;   int lenX, lenY;   long long dp[5009][5009];   inline long long go(int x, int y) {     if (x < 0 || y < 0) return 0LL;     long long &ret = dp[x][y];     if (ret != -1) return ret;     ret = 0;     if (y > 0) ret = go(x, y - 1);     if (ret >= MOD) ret -= MOD;     if (s[x] == t[y]) {       ret++;       if (x > 0 && y > 0) ret = (ret + go(x - 1, y - 1)) % MOD;     }     return ret;   }   int main() {     memset(dp, -1, sizeof(dp));     cin >> s >> t;     lenX = (int)s.length();     lenY = (int)t.length();     long long ans = 0;     for (int i = 0; i < lenX; ++i) {       ans += go(i, lenY - 1);       if (ans >= MOD) ans -= MOD;     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     const int MAXOPER = 1e5 + 123;     const int MAXN = 1e5 + 123;     vector<long long> V;     long long sz = 0;     static long long sz_after[MAXOPER];     static int oper_tip[MAXOPER];     static int oper_l[MAXOPER];     static int oper_c[MAXOPER];     static int oper_x[MAXOPER];     int n_oper;     scanf( %d , &n_oper);     for (int i_oper = 0; i_oper < (n_oper); ++i_oper) {       int tip;       scanf( %d , &tip);       oper_tip[i_oper] = tip;       if (tip == 1) {         int x;         scanf( %d , &x);         oper_x[i_oper] = x;         if ((int)V.size() < MAXN) V.push_back(x);         ++sz;       } else {         int l, c;         scanf( %d %d , &l, &c);         oper_l[i_oper] = l;         oper_c[i_oper] = c;         for (int i = 0; i < (c); ++i) {           if ((int)V.size() >= MAXN) break;           for (int j = 0; j < (l); ++j) {             if ((int)V.size() >= MAXN) break;             V.push_back(V[j]);           }         }         sz += l * c;       }       sz_after[i_oper] = sz;     }     int n_q;     scanf( %d , &n_q);     for (int i_q = 0; i_q < (n_q); ++i_q) {       long long idx;       cin >> idx;       --idx;       int o_idx = upper_bound(sz_after, sz_after + n_oper, idx) - sz_after;       long long sol;       if (oper_tip[o_idx] == 1)         sol = oper_x[o_idx];       else {         sol = V[(idx - sz_after[o_idx - 1]) % oper_l[o_idx]];       }       cout << sol;       if (i_q + 1 < n_q)         cout <<    ;       else         cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, m, count = 0;       cin >> n >> m;       string arr[n];       for (int i = 0; i < n; i++) {         cin >> arr[i];       }       for (int i = 0; i < (m - 1); i++) {         if (arr[n - 1][i] !=  R ) count++;       }       for (int i = 0; i < (n - 1); i++) {         if (arr[i][m - 1] !=  D ) count++;       }       cout << count << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000000;   template <typename T>   using V = std::vector<T>;   struct debugger {     template <typename T>     debugger &operator,(const T &v) {       cerr << v <<    ;       return *this;     }   } dbg;   using namespace std;   const double pi = acos(-1);   struct SegmentTree {     int n;     int size;     vector<pair<double, double> > dat;     vector<double> lazy;     int real_size;     SegmentTree(int n_) {       real_size = n_;       n = 1;       size = n_;       while (n < n_) n *= 2;       dat = vector<pair<double, double> >(2 * n - 1);       lazy = vector<double>(2 * n - 1);       init(0, 0, n);     }     void init(int k, int l, int r) {       if (r - l == 1) {         if (l < real_size) {           dat[k] = make_pair(1.0, 0.0);         }       } else {         int m = (l + r) / 2;         init((k * 2 + 1), l, m);         init((k * 2 + 2), m, r);         dat[k] = combine(dat[(k * 2 + 1)], dat[(k * 2 + 2)]);       }     }     void update(int a, int b, const double &d) { update(a, b + 1, 0, 0, n, d); }     void propagate(int k, int l, int r) {       double t = lazy[k];       double x = dat[k].first * cos(t) + dat[k].second * sin(t);       double y = -dat[k].first * sin(t) + dat[k].second * cos(t);       dat[k] = make_pair(x, y);       if ((k * 2 + 2) < lazy.size()) {         lazy[(k * 2 + 1)] += lazy[k];         lazy[(k * 2 + 2)] += lazy[k];       }       lazy[k] = 0.0;     }     void update(int a, int b, int k, int l, int r, const double &d) {       propagate(k, l, r);       if (r <= a || b <= l) return;       if (a <= l && r <= b) {         lazy[k] = d;         propagate(k, l, r);       } else {         int m = (l + r) / 2;         update(a, b, (k * 2 + 1), l, m, d);         update(a, b, (k * 2 + 2), m, r, d);         dat[k] = combine(dat[(k * 2 + 1)], dat[(k * 2 + 2)]);       }     }     void update(int a, int b, int k, int l, int r, int z) {       propagate(k, l, r);       if (r <= a || b <= l) return;       if (a <= l && r <= b) {         double len =             sqrt(dat[k].first * dat[k].first + dat[k].second * dat[k].second);         dat[k].first *= (len + z) / len;         dat[k].second *= (len + z) / len;       } else {         int m = (l + r) / 2;         update(a, b, (k * 2 + 1), l, m, z);         update(a, b, (k * 2 + 2), m, r, z);         dat[k] = combine(dat[(k * 2 + 1)], dat[(k * 2 + 2)]);       }     }     void update(int a, int z) { update(a, a + 1, 0, 0, n, z); }     pair<double, double> query(int a, int b) { return query(a, b + 1, 0, 0, n); }     pair<double, double> query(int a, int b, int k, int l, int r) {       if (r <= a || b <= l) return make_pair(0.0, 0.0);       propagate(k, l, r);       if (a <= l && r <= b) {         return dat[k];       } else {         pair<double, double> vl = query(a, b, (k * 2 + 1), l, (l + r) / 2);         pair<double, double> vr = query(a, b, (k * 2 + 2), (l + r) / 2, r);         return combine(vl, vr);       }     }     pair<double, double> combine(pair<double, double> vl,                                  pair<double, double> vr) {       return make_pair(vl.first + vr.first, vl.second + vr.second);     }   };   int main() {     int N, M;     scanf( %d , &N), scanf( %d , &M);     SegmentTree st(N + 1);     for (int i = 0; i < (M); i++) {       int x;       scanf( %d , &x);       if (x == 2) {         int y, z;         scanf( %d , &y), scanf( %d , &z);         st.update(y, N, z * 1.0 / 360 * 2 * pi);       } else {         int y, z;         scanf( %d , &y), scanf( %d , &z);         st.update(y, z);       }       auto ans = st.query(1, N);       printf( %.10f %.10f n , ans.first, ans.second);     }   }


#include <bits/stdc++.h>   using namespace std;   int z[150005];   long long tir[150005];   int find(int a) {     if (a != z[a]) {       z[a] = find(z[a]);     }     return z[a];   }   void mix(int a, int b) { z[find(a)] = find(b); }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       z[i] = i;       tir[i] = 0;     }     for (int j = 0; j < m; j++) {       int a, b;       scanf( %d%d , &a, &b);       mix(a, b);     }     for (int i = 1; i <= n; i++) {       tir[find(i)]++;     }     long long sum = 0;     for (int i = 1; i <= n; i++) {       sum += ((tir[i] * (tir[i] - 1)) / 2);     }     if (sum == m)       puts( YES );     else       puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using vi = vector<long long>;   template <typename T>   std::istream& operator>>(std::istream& input, std::pair<T, T>& data) {     input >> data.first >> data.second;     return input;   }   template <typename T>   std::istream& operator>>(std::istream& input, std::vector<T>& data) {     for (T& first : data) input >> first;     return input;   }   template <typename T>   std::ostream& operator<<(std::ostream& output, const pair<T, T>& data) {     output <<  (  << data.first <<  ,  << data.second <<  ) ;     return output;   }   template <typename T>   std::ostream& operator<<(std::ostream& output, const std::vector<T>& data) {     for (const T& first : data) output << first <<    ;     return output;   }   std::ostream& operator<<(std::ostream& output, const __int128& first) {     __int128 n = first;     if (n == 0) {       output <<  0 ;       return output;     }     if (n < 0) {       n = -n;       output <<  - ;     }     string s;     while (n) {       s +=  0  + (n % 10);       n /= 10;     }     reverse(s.begin(), s.end());     cout << s;     return output;   }   long long div_up(long long a, long long b) {     return a / b + ((a ^ b) > 0 && a % b);   }   long long div_down(long long a, long long b) {     return a / b - ((a ^ b) < 0 && a % b);   }   long long math_mod(long long a, long long b) { return a - b * div_down(a, b); }   template <class T>   using V = vector<T>;   template <class T>   bool ckmin(T& a, const T& b) {     return b < a ? a = b, 1 : 0;   }   template <class T>   bool ckmax(T& a, const T& b) {     return a < b ? a = b, 1 : 0;   }   long long gcd(long long a, long long b) {     while (b) {       tie(a, b) = make_pair(b, a % b);     }     return a;   }   long long Bit(long long mask, long long bit) { return (mask >> bit) & 1; }   template <long long MOD, long long RT>   struct mint {     static const long long mod = MOD;     static constexpr mint rt() { return RT; }     long long v;     explicit operator long long() const { return v; }     mint() { v = 0; }     mint(long long _v) {       v = (long long)((-MOD < _v && _v < MOD) ? _v : _v % MOD);       if (v < 0) v += MOD;     }     friend bool operator==(const mint& a, const mint& b) { return a.v == b.v; }     friend bool operator!=(const mint& a, const mint& b) { return !(a == b); }     friend bool operator<(const mint& a, const mint& b) { return a.v < b.v; }     friend string ts(mint a) { return to_string(a.v); }     mint& operator+=(const mint& m) {       if ((v += m.v) >= MOD) v -= MOD;       return *this;     }     mint& operator-=(const mint& m) {       if ((v -= m.v) < 0) v += MOD;       return *this;     }     mint& operator*=(const mint& m) {       v = (long long)((long long)v * m.v % MOD);       return *this;     }     mint& operator/=(const mint& m) { return (*this) *= inv(m); }     friend mint pow(mint a, long long p) {       mint ans = 1;       assert(p >= 0);       for (; p; p /= 2, a *= a)         if (p & 1) ans *= a;       return ans;     }     mint& operator^=(const long long& p) { return (*this) = pow(this, p); }     friend mint inv(const mint& a) {       assert(a.v != 0);       return pow(a, MOD - 2);     }     mint operator-() const { return mint(-v); }     mint& operator++() { return *this += 1; }     mint& operator--() { return *this -= 1; }     friend mint operator+(mint a, const mint& b) { return a += b; }     friend mint operator-(mint a, const mint& b) { return a -= b; }     friend mint operator*(mint a, const mint& b) { return a *= b; }     friend mint operator/(mint a, const mint& b) { return a /= b; }     friend mint operator^(mint a, const long long p) { return pow(a, p); }   };   const long long MOD = 1e9 + 7;   typedef mint<MOD, 5> mi;   std::ostream& operator<<(std::ostream& o, const mi& a) {     cout << a.v;     return o;   }   vector<vector<mi> > scmb;   void genComb(long long SZ) {     scmb.assign(SZ, vector<mi>(SZ));     scmb[0][0] = 1;     for (long long i = (1); i < (SZ); ++i)       for (long long j = (0); j < (i + 1); ++j)         scmb[i][j] = scmb[i - 1][j] + (j ? scmb[i - 1][j - 1] : 0);   }   vector<mi> invs, fac, ifac;   void genFac(long long SZ) {     invs.resize(SZ), fac.resize(SZ), ifac.resize(SZ);     invs[1] = fac[0] = ifac[0] = 1;     for (long long i = (2); i < (SZ); ++i)       invs[i] = mi(-(long long)MOD / i * (long long)invs[MOD % i]);     for (long long i = (1); i < (SZ); ++i) {       fac[i] = fac[i - 1] * i;       ifac[i] = ifac[i - 1] * invs[i];     }   }   mi comb(long long a, long long b) {     if (a < b || b < 0) return 0;     assert(a < fac.size());     return fac[a] * ifac[b] * ifac[a - b];   }   const long long N = 507;   long long link[N];   const long long K = 1 << 16;   void ANDConvolution(mi v[K]) {     for (long long step = K; step > 1; step /= 2) {       for (long long start = 0; start < K; start += step) {         for (long long w = 0; w < step / 2; w++) {           v[start + w] += v[start + w + step / 2];         }       }     }   }   void inverseANDConvolution(mi v[K]) {     for (long long step = K; step > 1; step /= 2) {       for (long long start = 0; start < K; start += step) {         for (long long w = 0; w < step / 2; w++) {           v[start + w] -= v[start + w + step / 2];         }       }     }   }   void ORConvolution(mi v[K]) {     for (long long step = K; step > 1; step /= 2) {       for (long long start = 0; start < K; start += step) {         for (long long w = 0; w < step / 2; w++) {           v[start + step / 2 + w] += v[start + w];         }       }     }   }   void inverseORConvolution(mi v[K]) {     for (long long step = K; step > 1; step /= 2) {       for (long long start = 0; start < K; start += step) {         for (long long w = 0; w < step / 2; w++) {           v[start + step / 2 + w] -= v[start + w];         }       }     }   }   mi dp[N][1 << 16];   string s;   mi A[K], B[K], C[K];   long long ptr = 0;   long long solve(long long l, long long r) {     long long v = ptr;     ptr++;     if (l == r) {       long long who = -1, add = -1;       if (s[l] ==  a ) {         who = 0;         add = 1;       } else if (s[l] ==  A ) {         who = 0;         add = 0;       } else if (s[l] ==  b ) {         who = 1;         add = 1;       } else if (s[l] ==  B ) {         who = 1;         add = 0;       } else if (s[l] ==  c ) {         who = 2;         add = 1;       } else if (s[l] ==  C ) {         who = 2;         add = 0;       } else if (s[l] ==  d ) {         who = 3;         add = 1;       } else if (s[l] ==  D ) {         who = 3;         add = 0;       } else {         assert(s[l] ==  ? );       }       if (who != -1) {         long long foo = 0;         for (long long mask = (0); mask < (16); ++mask) {           if (Bit(mask, who) ^ add) {             foo ^= 1 << mask;           }         }         dp[v][foo] += 1;       } else {         for (long long who = (0); who < (4); ++who) {           for (long long add = (0); add < (2); ++add) {             long long foo = 0;             for (long long mask = (0); mask < (16); ++mask) {               if (Bit(mask, who) ^ add) {                 foo ^= 1 << mask;               }             }             dp[v][foo] += 1;           }         }       }       return v;     }     long long L = solve(l + 1, link[l] - 1);     long long nextb = link[l] + 2;     long long R = solve(nextb + 1, link[nextb] - 1);     if (s[nextb - 1] !=  & ) {       for (long long i = (0); i < (K); ++i) {         A[i] = dp[L][i];         B[i] = dp[R][i];       }       ORConvolution(A);       ORConvolution(B);       for (long long i = 0; i < K; i++) {         C[i] = A[i] * B[i];       }       inverseORConvolution(C);       for (long long i = (0); i < (K); ++i) {         dp[v][i] += C[i];       }     }     if (s[nextb - 1] !=  | ) {       for (long long i = (0); i < (K); ++i) {         A[i] = dp[L][i];         B[i] = dp[R][i];       }       ANDConvolution(A);       ANDConvolution(B);       for (long long i = 0; i < K; i++) {         C[i] = A[i] * B[i];       }       inverseANDConvolution(C);       for (long long i = (0); i < (K); ++i) {         dp[v][i] += C[i];       }     }     return v;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> s;     long long len = s.size();     vi sk;     for (long long i = (0); i < (len); ++i) {       if (s[i] ==  ( ) {         sk.push_back(i);       } else if (s[i] ==  ) ) {         assert(sk.size());         link[sk.back()] = i;         link[i] = sk.back();         sk.pop_back();       }     }     long long root = solve(0, len - 1);     long long q;     cin >> q;     long long want = 0;     long long know = 0;     for (long long _ = (0); _ < (q); ++_) {       long long bit = 0;       for (long long i = (0); i < (4); ++i) {         long long first;         cin >> first;         if (first) {           bit ^= 1 << i;         }       }       know ^= 1 << bit;       long long res;       cin >> res;       if (res) {         want ^= 1 << bit;       }     }     mi ans = 0;     for (long long mask = (0); mask < (1 << 16); ++mask) {       bool ok = 1;       for (long long bit = (0); bit < (16); ++bit) {         if (Bit(know, bit)) {           ok &= Bit(want, bit) == Bit(mask, bit);         }       }       if (ok) {         ans += dp[root][mask];       }     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, t;     cin >> n >> t;     string s;     cin >> s;     while (t--) {       for (long long j = 1; j < n; j++) {         if (s[j - 1] ==  B  && s[j] ==  G ) {           swap(s[j - 1], s[j]);           j++;         }       }     }     cout << s << endl;     ;   }


#include <bits/stdc++.h>   using namespace std;   int arr[105];   int main() {     int n;     cin >> n;     int pos = 0;     int neg = 0;     int z = 0;     for (int i = 0; i < n; i++) {       cin >> arr[i];       if (arr[i] > 0)         pos++;       else if (arr[i] < 0)         neg++;       else         z++;     }     int pas = 0;     if (n % 2 == 0)       pas = n / 2;     else       pas = (n / 2) + 1;     int maxi = pos;     if (neg > pos) maxi = neg;     if (maxi >= pas && maxi == pos) {       cout << 1 << endl;     } else if (maxi >= pas && maxi == neg) {       cout << -1 << endl;     } else {       cout << 0 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[500][500];   int d[500][500];   long long int ans[500];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         int num;         cin >> num;         a[i][j] = num;         d[i][j] = num;       }     }     int b[n];     for (int i = 0; i < n; i++) {       cin >> b[i];       b[i]--;     }     reverse(b, b + n);     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         for (int s = 0; s < n; s++) {           d[j][s] = min(d[j][s], d[j][b[i]] + d[b[i]][s]);         }       }       for (int j = 0; j <= i; j++) {         for (int s = 0; s <= i; s++) {           ans[i] += d[b[j]][b[s]];         }       }     }     reverse(ans, ans + n);     for (int i = 0; i < n; i++) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   int ma[maxn];   int en[maxn];   int add = 0;   int main() {     std::ios::sync_with_stdio(false);     int n, d;     cin >> n >> d;     int sum = 0;     int mx = -40000000;     int op = 0;     for (int i = 0; i < n; i++) {       int in;       cin >> in;       if (in != 0) {         sum += in;         mx = max(mx, sum);         if (sum > d) {           cout <<  -1  << endl;           return 0;         }       } else {         if (sum >= 0) continue;         ma[op] = mx;         en[op++] = sum;         sum = 0;         mx = -400000000;       }     }     int cnt = 0;     for (int i = 0; i < op; i++) {       if (min(add, d - ma[i]) < abs(en[i])) {         cnt++;         add = d;       } else {         add = min(add, d - ma[i]) - abs(en[i]);       }     }     cout << cnt << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     vector<vector<int> > field;     int x, y;     cin >> x >> y;     field.resize(x);     for (int i = 0; i < x; ++i) field[i].resize(y);     for (int i = 0; i < x; ++i)       for (int j = 0; j < y; ++j) field[i][j] = 0;     int x0, y0;     cin >> x0 >> y0;     x0 -= 1;     y0 -= 1;     field[x0][y0] = 1;     int count = x * y - 1;     string s;     cin >> s;     cout <<  1  ;     for (unsigned int i = 0; i < s.size() - 1; ++i) {       if (s[i] ==  U  && x0 != 0) {         x0 -= 1;         if (field[x0][y0] != 1) {           field[x0][y0] = 1;           --count;           cout <<  1  ;         } else           cout <<  0  ;       } else if (s[i] ==  D  && x0 != x - 1) {         x0 += 1;         if (field[x0][y0] != 1) {           field[x0][y0] = 1;           --count;           cout <<  1  ;         } else           cout <<  0  ;       } else if (s[i] ==  L  && y0 != 0) {         y0 -= 1;         if (field[x0][y0] != 1) {           field[x0][y0] = 1;           --count;           cout <<  1  ;         } else           cout <<  0  ;       } else if (s[i] ==  R  && y0 != y - 1) {         y0 += 1;         if (field[x0][y0] != 1) {           field[x0][y0] = 1;           --count;           cout <<  1  ;         } else           cout <<  0  ;       } else         cout <<  0  ;     }     cout << count;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, a[+100500 * 2], ans;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       scanf( %I64d , &a[i]);     }     for (int i = 1; i <= n; i++) {       ans += abs(a[i] - a[i - 1]);     }     printf( %I64d , ans);     return 0;     ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> v(n);     for (int i = 0; i < n; i++) cin >> v[i];     string str;     getline(cin, str);     bool isok = true;     for (int i = 0; i < n; i++) {       getline(cin, str);       int x = 0;       for (int j = 0; j < str.length(); j++) {         if (str[j] ==  a  || str[j] ==  e  || str[j] ==  i  || str[j] ==  o  ||             str[j] ==  u  || str[j] ==  y )           x++;       }       if (x != v[i]) {         cout <<  NO  << endl;         return 0;       }     }     cout <<  YES  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long a, b;     cin >> a >> b;     vector<string> A;     for (long long i = 0; i < a; i++) {       string res =   ;       for (long long j = 0; j < b; j++) {         if (i % 4 == 0 || i % 4 == 2) {           res +=  # ;         } else if (i % 4 == 1 || i % 4 == 3) {           res +=  . ;         }       }       if (i % 4 == 1)         res[res.length() - 1] =  # ;       else if (i % 4 == 3)         res[0] =  # ;       A.push_back(res);     }     for (auto i : A) {       cout << i <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long tt(1);     while (tt--) {       solve();     }   }


#include <bits/stdc++.h>   const long long P = 1000000007;   long long N, oldA, oldB, oldC, oldD = 1, newA, newB, newC, newD;   int main() {     std::cin >> N;     for (int i = 1; i <= N; ++i) {       newA = (oldB + oldC + oldD) % P;       newB = (oldA + oldC + oldD) % P;       newC = (oldA + oldB + oldD) % P;       newD = (oldA + oldB + oldC) % P;       oldA = newA;       oldB = newB;       oldC = newC;       oldD = newD;     }     std::cout << newD;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   long long a[N][26];   int b[N];   long long ans[28];   char s[N];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       cin >> (s + 1);       for (int i = 0; i <= n; i++) {         for (int j = 0; j <= 26; j++) {           a[i][j] = 0;         }       }       for (int i = 0; i < 26; i++) ans[i] = 0;       for (int i = 0; i < m; i++) cin >> b[i];       for (int i = 1; i <= n; i++) {         int d = s[i] -  a ;         a[i][d]++;       }       for (int i = 0; i < 26; i++) {         for (int j = 2; j <= n; j++) {           a[j][i] = a[j - 1][i] + a[j][i];         }       }       for (int i = 0; i < m; i++) {         int k = b[i];         for (int j = 0; j < 26; j++) {           ans[j] += a[k][j];         }       }       for (int i = 0; i < 26; i++) {         ans[i] += a[n][i];       }       for (int i = 0; i < 26; i++) {         if (i) cout <<    ;         cout << ans[i];       }       cout << endl;     }     return 0;   }


#pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   #pragma GCC optimization ( O3 )   #pragma GCC optimization ( unroll-loops )      #include<bits/stdc++.h>   using namespace std;      #define pb push_back   #define mp make_pair   #define F first   #define S second   #define lb lower_bound   #define ub upper_bound   #define sz(x) (int)(x).size()   #define all(x) x.begin(), x.end()      typedef long long ll;   typedef long double ld;   typedef complex<ld> cd;   typedef pair<int, int> pii;   typedef pair<ll,ll> pll;   typedef pair<ld,ld> pld;   typedef vector<int> vi;   typedef vector<ld> vd;   typedef vector<ll> vl;   typedef vector<pii> vpi;   typedef vector<pll> vpl;      #define FOR(i, a, b) for (int i=a; i<(b); i++)   #define F0R(i, a) for (int i=0; i<(a); i++)   #define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)   #define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)   #define trav(a,x) for (auto& a : x)      mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());       ll powmod(ll a,ll b) {ll res=1; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a;a=a*a;}return res;}   ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}   int n,d;      void solve() {       int n; string a,b;       cin >> n >> a >> b;       if(a==b) { cout << b <<   n ; return ; }       if(a[0] ==  0 ) { F0R(i,n) cout <<  1 ; cout<<  n ; return; }       if(b.back() ==  1  || a == b) { cout << b <<   n ; return ; }        {                  int l = n-1;           while(a[l] ==  1 ) --l;           a[l]= 1 ; FOR(i,l+1,n) a[i]= 0 ;       }       if(a != b) b[n-1] =  1 ;       { cout << b <<   n ; return ; }   }         int main(){       ios_base::sync_with_stdio(false); cin.tie(NULL);         #ifndef ONLINE_JUDGE           freopen( input.txt , r ,stdin);           freopen( output.txt , w ,stdout);       #endif        int t=1,Tc=1;       while(t--){           //cout <<  Case # <<Tc<< :  ; Tc++;           solve();       }     return 0;   }