#include <bits/stdc++.h>   using namespace std;   long long read() {     long long w = 0, f = 1;     char c =    ;     while (c <  0  || c >  9 ) c = getchar(), f = c ==  -  ? -1 : f;     while (c >=  0  && c <=  9 ) w = w * 10 + c - 48, c = getchar();     return w * f;   }   long long read14() {     char c = getchar();     while (c !=  U  && c !=  D  && c !=  L  && c !=  R ) c = getchar();     if (c ==  U ) return 1;     if (c ==  D ) return 2;     if (c ==  L ) return 3;     return 4;   }   long long n, m, p[200005], dl[200005], dr[200005];   vector<long long> a[200005], e[200005];   long long pos(long long x, long long y) {     if (x >= 1 && x <= n && y >= 1 && y <= m) return (x - 1) * m + y;     return n * m + 1 + ((x + y) & 1);   }   long long minn[200005 << 2], tag[200005 << 2], val[200005 << 2];   void build(long long p, long long l, long long r) {     if (l == r) {       val[p] = 1;       return;     }     long long mid = (l + r) >> 1;     build(p << 1, l, mid);     build(p << 1 | 1, mid + 1, r);     val[p] = val[p << 1] + val[p << 1 | 1];   }   void down(long long p, long long l, long long r) {     if (!tag[p]) return;     minn[p << 1] += tag[p];     minn[p << 1 | 1] += tag[p];     tag[p << 1] += tag[p];     tag[p << 1 | 1] += tag[p];     tag[p] = 0;   }   void update(long long p, long long x, long long y, long long v, long long l,               long long r) {     if (x <= l && y >= r) {       minn[p] += v, tag[p] += v;       return;     }     down(p, l, r);     long long mid = (l + r) >> 1;     if (x <= mid) update(p << 1, x, y, v, l, mid);     if (y > mid) update(p << 1 | 1, x, y, v, mid + 1, r);     if (minn[p << 1] == minn[p << 1 | 1])       val[p] = val[p << 1] + val[p << 1 | 1];     else if (minn[p << 1] < minn[p << 1 | 1])       val[p] = val[p << 1];     else       val[p] = val[p << 1 | 1];     minn[p] = min(minn[p << 1], minn[p << 1 | 1]);   }   long long now, ans;   void dfs1(long long u) {     dl[u] = ++now;     for (auto v : e[u]) dfs1(v);     dr[u] = now;   }   void dfs2(long long u, long long rt) {     if (u != rt) update(1, dl[p[u]], dr[p[u]], 1, 1, now), ans -= val[1] - 1;     for (auto v : e[u]) dfs2(v, rt);     if (u != rt) update(1, dl[p[u]], dr[p[u]], -1, 1, now);   }   signed main() {     n = read(), m = read(), ans = n * n * m * m / 4;     for (long long i = 1; i <= n; i++) {       a[i].push_back(0);       for (long long j = 1; j <= m; j++) {         a[i].push_back(read14());         if (a[i][j] == 1)           e[pos(i + 2, j)].push_back(pos(i, j)), p[pos(i, j)] = pos(i + 1, j);         if (a[i][j] == 2)           e[pos(i - 2, j)].push_back(pos(i, j)), p[pos(i, j)] = pos(i - 1, j);         if (a[i][j] == 3)           e[pos(i, j + 2)].push_back(pos(i, j)), p[pos(i, j)] = pos(i, j + 1);         if (a[i][j] == 4)           e[pos(i, j - 2)].push_back(pos(i, j)), p[pos(i, j)] = pos(i, j - 1);       }     }     dfs1(n * m + 1);     build(1, 1, now);     dfs2(n * m + 2, n * m + 2);     printf( %lld , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, apple[200000], a, b;   long long tot = 0;   vector<int> adj[200000];   int GCD(long long x, long long y) {     if (y == 0) return x;     return GCD(y, x % y);   }   pair<long long, long long> DFS(int ant, int act) {     if (adj[act].size() == 1) return make_pair(apple[act], 1);     vector<pair<long long, long long> > V;     for (int i = 0; i < adj[act].size(); i++) {       if (adj[act][i] == ant) continue;       V.push_back(DFS(act, adj[act][i]));     }     long long mn = V[0].first;     for (int i = 0; i < V.size(); i++) mn = min(mn, V[i].first);     long long mcm = V[0].second;     for (int i = 1; i < V.size(); i++) {       if (mcm > mn) break;       mcm = (mcm * V[i].second) / GCD(mcm, V[i].second);     }     return make_pair(V.size() * mcm * (mn / mcm), V.size() * mcm);   }   int main() {     scanf( %d , &(n));     for (int i = 1; i <= n; i++) {       scanf( %d , &(apple[i]));       tot += apple[i];     }     for (int i = 1; i < n; i++) {       scanf( %d%d , &(a), &(b));       adj[a].push_back(b);       adj[b].push_back(a);     }     adj[1].push_back(0);     cout << tot - DFS(0, 1).first << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char* argv[]) {     int k, n;     cin >> n >> k;     int val[100000];     int awake[100000];     for (int i = 0; i < n; ++i) {       cin >> val[i];     }     int sum = 0;     int extra = 0;     int max = 0;     for (int i = 0; i < n; ++i) {       cin >> awake[i];       if (awake[i]) {         sum += val[i];         val[i] = 0;       }       if (i < k) {         extra += val[i];       } else {         extra = extra + val[i] - val[i - k];       }       if (extra > max) {         max = extra;       }     }     sum += max;     cout << sum << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     cin >> n;     long long int c, e = 0;     long long int s = 0, a;     for (long long int i = 0; i < n; i++) {       cin >> a;       s += a;       if (a % 2 != 0) {         e++;         if (e == 1)           c = a;         else if (e > 1)           c = min(c, a);       }     }     if (e % 2 != 0) s -= c;     cout << s;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = int(2e5 + 5);   int n, m, S;   int POW[25];   int f[MAXN];   bool vis[MAXN];   bool flag[MAXN];   long long tmp, tot, Ans, t;   struct edge {     int u, v, id;     int w, c;   } e[MAXN];   struct node {     int to, id;     node() {}     node(int T, int I) : to(T), id(I) {}   };   vector<node> G[MAXN];   void Addedge(int u, int v, int id) {     G[u].push_back(node(v, id));     G[v].push_back(node(u, id));   }   void Init() {     POW[0] = 1;     for (int i = 1; i <= 25; i++) POW[i] = 2 * POW[i - 1];   }   int Find(int x) { return x == f[x] ? x : f[x] = Find(f[x]); }   bool cmp(edge a, edge b) { return a.w < b.w; }   bool cmp2(edge a, edge b) { return a.id < b.id; }   void Kruskal() {     sort(e + 1, e + m + 1, cmp);     for (int i = 1; i <= n; i++) f[i] = i;     t = 0;     e[0].c = int(1e9 + 5);     for (int i = 1; i <= m; i++) {       int u = e[i].u, v = e[i].v;       int fx = Find(u), fy = Find(v);       if (fx != fy) {         Addedge(u, v, i);         f[fx] = fy;         vis[i] = 1;         tmp += e[i].w;         if (e[i].c < e[t].c) t = i;       }     }     tot = tmp;     tmp -= S / e[t].c;   }   int MaxId(int a, int b) { return (e[a].w < e[b].w) ? b : a; }   int Max[MAXN][25 + 5];   int fa[MAXN][25 + 5];   int dep[MAXN];   void Dfs(int u) {     for (int i = 1; i <= 25; i++) {       fa[u][i] = fa[fa[u][i - 1]][i - 1];       Max[u][i] = MaxId(Max[u][i - 1], Max[fa[u][i - 1]][i - 1]);     }     for (int i = 0; i < G[u].size(); i++) {       int v = G[u][i].to;       if (v == fa[u][0]) continue;       dep[v] = dep[u] + 1;       Max[v][0] = G[u][i].id;       fa[v][0] = u;       Dfs(v);     }   }   int LCA(int u, int v) {     if (dep[u] < dep[v]) swap(u, v);     int t = dep[u] - dep[v];     for (int i = 0; POW[i] <= t; i++)       if (POW[i] & t) u = fa[u][i];     if (u == v) return u;     for (int i = 25; i >= 0; i--)       if (fa[u][i] != fa[v][i]) u = fa[u][i], v = fa[v][i];     return fa[u][0];   }   int Query(int u, int v) {     int t = dep[u] - dep[v];     int ret = 0;     for (int i = 0; POW[i] <= t; i++)       if (POW[i] & t) {         ret = MaxId(ret, Max[u][i]);         u = fa[u][i];       }     return ret;   }   int main() {     Init();     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       e[i].id = i;       scanf( %d , &e[i].w);     }     for (int i = 1; i <= m; i++) scanf( %d , &e[i].c);     for (int i = 1; i <= m; i++) scanf( %d%d , &e[i].u, &e[i].v);     scanf( %d , &S);     Kruskal();     e[0].w = -int(1e9 + 5);     fill(Max[1], Max[1] + 25 + 1, 0);     Dfs(1);     long long Ans = tmp;     int Last = -1, now = -1;     for (int i = 1; i <= m; i++)       if (e[i].c < e[t].c) {         int u = e[i].u, v = e[i].v;         int q = LCA(u, v);         int x = MaxId(Query(u, q), Query(v, q));         tmp = (long long)tot - e[x].w + e[i].w - S / e[i].c;         if (Ans > tmp) {           Ans = tmp;           vis[(Last != -1) ? Last : 0] = 1;           vis[x] = 0;           Last = x;           vis[(now != -1) ? now : 0] = 0;           vis[i] = 1;           now = i;         }       }     printf( %I64d n , Ans);     if (now == -1) now = t;     for (int i = 1; i <= m; i++)       if (vis[i]) {         if (now == i) e[i].w -= S / e[i].c;         flag[e[i].id] = 1;       }     sort(e + 1, e + m + 1, cmp2);     for (int i = 1; i <= m; i++)       if (flag[i]) printf( %d %d n , i, e[i].w);   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 10;   const long long inf = 1e14 + 10;   long long n, k;   long long a[N];   long long ps[N];   long long fen[N];   vector<long long> vec;   void upd(long long x) {     for (; x < N; x += (x & (-x))) {       fen[x]++;     }   }   long long get(long long x) {     long long ret = 0;     for (; x > 0; x -= (x & (-x))) {       ret += fen[x];     }     return ret;   }   bool check(long long K) {     long long res = 0;     for (long long i = 0; i < N; i++) {       fen[i] = 0;     }     for (long long i = 1; i <= n; i++) {       long long val = ps[i] - K;       long long ind = upper_bound(vec.begin(), vec.end(), val) - vec.begin();       res += get(ind);       ind = upper_bound(vec.begin(), vec.end(), ps[i]) - vec.begin();       upd(ind);       if (ps[i] >= K) {         res++;       }     }     if (res >= k) {       return true;     } else {       return false;     }   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> k;     for (long long i = 1; i <= n; i++) {       cin >> a[i];       ps[i] = ps[i - 1] + a[i];       vec.push_back(ps[i]);     }     sort(vec.begin(), vec.end());     long long L = -inf;     long long R = inf;     while (R - L > 1) {       long long mid = (L + R) / 2;       if (check(mid)) {         L = mid;       } else {         R = mid;       }     }     cout << L;     return 0;   }


#include <bits/stdc++.h>   int cmpfunc(const void* a, const void* b) { return (*(int*)a - *(int*)b); }   int main() {     int t, x, i, j, c;     scanf( %d , &t);     while (t--) {       char n[101];       int m[101];       scanf( %s , &n);       x = strlen(n);       j = 0;       c = 0;       for (i = 0; i < x; i++) {         if (n[i] ==  1 )           c++;         else if (c > 0) {           m[j++] = c;           c = 0;         }       }       if (c > 0) m[j++] = c;       qsort(m, j, sizeof(int), cmpfunc);       c = 0;       for (i = j - 1; i >= 0; i = i - 2) c = c + m[i];       printf( %d n , c);     }   }


#include <bits/stdc++.h>   using namespace std;   long long ans[100004] = {0};   vector<long long> v[100005];   int main() {     long long n, m, i, j, ms = 0, sum = 0, res = 0;     scanf( %lld %lld , &n, &m);     for (i = 0; i < n; i++) {       long long a, b;       scanf( %lld %lld , &a, &b);       v[a].push_back(b);     }     for (i = 1; i <= m; i++) {       sum = 0;       sort(v[i].begin(), v[i].end());       long long si = v[i].size();       ms = max(ms, si);       for (j = si - 1; j >= 0; j--) {         sum += v[i][j];         if (sum > 0)           ans[si - j] += sum;         else           break;       }     }     for (i = 1; i <= ms; i++) res = max(res, ans[i]);     printf( %lld n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int cmx = 1e5 + 5;   int n, k;   char a[505][505];   int id[505][505];   int cc_sz[505 * 505];   int seen[505 * 505];   bool inside(int x, int y) {     if (0 <= min(x, y) and max(x, y) < n) return true;     return false;   }   int dx[] = {1, -1, 0, 0};   int dy[] = {0, 0, -1, 1};   void dfs(int x, int y, int cc_no) {     id[x][y] = cc_no;     cc_sz[cc_no]++;     for (int i = 0; i < 4; i++) {       int nx = x + dx[i];       int ny = y + dy[i];       if (inside(nx, ny) and (id[nx][ny] == 0 and a[nx][ny] ==  . ))         dfs(nx, ny, cc_no);     }   }   void add(int x, int y, int &ans, int flag) {     if (a[x][y] ==  .  and seen[id[x][y]] != flag) {       seen[id[x][y]] = flag;       ans += cc_sz[id[x][y]];     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> k;     for (int i = (0); i <= (n - 1); ++i)       for (int j = (0); j <= (n - 1); ++j) cin >> a[i][j];     int which_cc = 0;     for (int i = (0); i <= (n - 1); ++i)       for (int j = (0); j <= (n - 1); ++j) {         if (id[i][j] == 0 and a[i][j] ==  . ) {           dfs(i, j, ++which_cc);         }       }     int counter = 1;     int best_ans = 0;     for (int y_low = 0; (y_low + k) <= n; y_low++) {       for (int x = 0; x < k; x++)         for (int y = y_low; y < (y_low + k); y++) --cc_sz[id[x][y]];       for (int x_low = 0; (x_low + k) <= n; x_low++) {         int ans = k * k;         for (int x = 0; x < k; x++) {           if (inside(x_low + x, y_low - 1))             add(x_low + x, y_low - 1, ans, counter);           if (inside(x_low + x, y_low + k))             add(x_low + x, y_low + k, ans, counter);         }         for (int y = 0; y < k; y++) {           if (inside(x_low - 1, y_low + y))             add(x_low - 1, y_low + y, ans, counter);           if (inside(x_low + k, y_low + y))             add(x_low + k, y_low + y, ans, counter);         }         counter++;         best_ans = max(best_ans, ans);         if ((x_low + k) != n) {           for (int y = 0; y < k; y++) {             ++cc_sz[id[x_low][y + y_low]];             --cc_sz[id[x_low + k][y + y_low]];           }         }       }       for (int x = n - k; x < n; x++)         for (int y = 0; y < k; y++) ++cc_sz[id[x][y_low + y]];     }     cout << best_ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     string s;     cin >> s;     int mark = 1;     for (int i = 1; i < s.size(); i++) {       if (s[i] != s[i - 1]) {         mark = -1;         break;       }     }     if (mark == 1) {       cout << s;       for (int i = 1; i < k; i++) {         cout << s[0];       }       return 0;     }     for (int i = s.size() - 1; i >= 1; i--) {       string t1 = s.substr(0, i);       string t2 = s.substr(s.size() - i, i);       if (t1 == t2) {         int len = s.size() - i;         string ost = s.substr(i, len);         string ans = s;         for (int j = 1; j < k; j++) {           ans += ost;         }         int kol = 0;         for (int j = 0; j + s.size() <= ans.size(); j++) {           string mr = ans.substr(j, s.size());           if (mr == s) {             kol++;             if (kol == k) {               string prt = ans.substr(0, j + s.size());               cout << prt << endl;               return 0;             }           }         }       }     }     for (int i = 1; i <= k; i++) {       cout << s;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, s[200003], m, cnt, ans[200003];   vector<pair<int, int> > v[200003], g[200003];   bool vis[200003];   int dfs(int x) {     vis[x] = 1;     int ret = 0, tmp;     for (int i = 0; i < v[x].size(); i++)       if (!vis[v[x][i].first]) {         tmp = dfs(v[x][i].first);         ret += tmp;         ans[v[x][i].second] = -tmp;       }     for (int i = 0; i < g[x].size(); i++)       if (!vis[g[x][i].first]) {         tmp = dfs(g[x][i].first);         ret += tmp;         ans[g[x][i].second] = tmp;       }     return ret - s[x];   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) scanf( %d , s + i), cnt += s[i];     cin >> m;     for (int i = 0; i < m; i++) {       int x, y;       scanf( %d%d , &x, &y);       x--;       y--;       v[x].push_back(make_pair(y, i));       g[y].push_back(make_pair(x, i));     }     if (cnt) {       cout <<  Impossible ;       return 0;     }     cout <<  Possible ;     dfs(0);     for (int i = 0; i < m; i++) printf(  n%d , ans[i]);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, j = 0;     cin >> a >> b >> c;     for (int i = 1; i <= a; i++) {       if (b >= 2 * i && c >= 4 * i) j++;     }     cout << j + 2 * j + 4 * j;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Counter {     static int k;     Counter() { k++; }     ~Counter() { k--; }   };   int Counter::k = 0;   template <typename T>   void pr(const string& name, T t) {     cout << name <<   =   << t << endl;   }   template <typename T, typename... Types>   void pr(const string& names, T t, Types... rest) {     auto comma_pos = names.find( , );     cout << names.substr(0, comma_pos) <<   =   << t <<  ,  ;     auto next_name_pos = names.find_first_not_of(   t n , comma_pos + 1);     pr(string(names, next_name_pos), rest...);   }   void mod(long long& a, long long b) {     a %= b;     if (a < 0) a += b;   }   const long long MOD = 1000000007;   deque<long long> DQ;   long long Days[15], N, M;   int main() {     cin >> N >> M;     string line;     Days[1] = 0;     Days[2] = 31;     Days[3] = 59;     Days[4] = 90;     Days[5] = 120;     Days[6] = 151;     Days[7] = 181;     Days[8] = 212;     Days[9] = 243;     Days[10] = 273;     Days[11] = 304;     Days[12] = 334;     getline(cin, line);     while (true) {       getline(cin, line);       if (cin.eof()) break;       long long year = 0, month = 0, day = 0;       for (int i = (0); i <= (3); i++) year = 10 * year + line[i] -  0 ;       for (int i = (5); i <= (6); i++) month = 10 * month + line[i] -  0 ;       for (int i = (8); i <= (9); i++) day = 10 * day + line[i] -  0 ;       long long days = 365 * (year - 1) + Days[month] + day - 1;       days += (year - 1) / 4;       if (year % 4 == 0 && month > 2) days++;       long long hr = 10 * (line[11] -  0 ) + line[12] -  0 ;       long long mn = 10 * (line[14] -  0 ) + line[15] -  0 ;       long long sc = 10 * (line[17] -  0 ) + line[18] -  0 ;       long long sec = days * 60 * 60 * 24 + 3600 * hr + 60 * mn + sc;       if (!DQ.empty() && sec - DQ.front() >= N) DQ.pop_front();       DQ.push_back(sec);       if (DQ.size() >= M) {         cout << line.substr(0, 19) <<   n ;         return 0;       }     }     cout <<  -1 ;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, a[102], b[102];   int main(void) {     scanf( %d %d , &n, &m);     for (int i = 0; i < m; ++i) scanf( %d %d , &a[i], &b[i]);     for (int x = 1; x <= n; ++x) {       int c = 0;       for (int i = 0; i < m; ++i)         if (x >= a[i] && x <= b[i]) ++c;       if (c != 1) {         printf( %d %d n , x, c);         return 0;       }     }     puts( OK );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100100;   long double a[maxn];   int main() {     int n, s;     long long k, b;     while (~scanf( %d , &n)) {       s = 0;       for (int i = 0; i < n; i++) {         scanf( %I64d %I64d , &k, &b);         if (k != 0) {           a[s++] = -(double)(b * 1.0) / (k * 1.0);         }       }       sort(a, a + s);       int count = 0;       for (int i = 1; i < s; i++) {         if (fabs(a[i] - a[i - 1]) > 0) {           count++;         }       }       if (s > 0) {         count++;       }       printf( %d n , count);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long bip(long long x, long long n, long long mod) {     long long res = 1;     while (n) {       if (n & 1) {         res = (res * x) % mod;       }       x = (x * x) % mod;       n >>= 1;     }     return res;   }   const int maxn = INT_MAX;   const long long inf = 1e18;   const int mod = 998244353;   const int N = 1e5 + 10;   void solve() {     string a, b;     cin >> a >> b;     if ((int)b.size() > (int)a.size()) {       sort(a.begin(), a.end());       reverse(a.begin(), a.end());       cout << a;       return;     }     vector<int> cnt(10, 0);     for (int i = 0; i < (int)a.size(); i++) cnt[a[i] -  0 ]++;     vector<int> ans;     for (int i = 0; i < (int)b.size(); i++) {       int k = b[i] -  0 ;       bool ok = 0;       for (int j = k; j >= 0; j--) {         if (cnt[j]) {           ok = 1;           cnt[j]--;           ans.push_back(j);           if (j < k) {             for (int l = 9; l >= 0; l--) {               while (cnt[l]--) ans.push_back(l);             }             for (auto it : ans) cout << it;             return;           }           break;         }       }       if (ok == 0) {         for (int p = i - 1; p >= 0; p--) {           int k = b[p] -  0 ;           ans.pop_back();           cnt[k]++;           bool ok = 0;           for (int j = k - 1; j >= 0; j--) {             if (cnt[j]) {               ok = 1;               break;             }           }           if (ok) {             for (int j = k - 1; j >= 0; j--) {               if (cnt[j]) {                 ans.push_back(j);                 cnt[j]--;                 for (int l = 9; l >= 0; l--) {                   while (cnt[l]--) ans.push_back(l);                 }                 for (auto it : ans) cout << it;                 return;               }             }           }         }       }     }     for (auto it : ans) cout << it;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int tt = 1;     while (tt--) {       solve();       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int Maxn = 100000 + 19;   int a[Maxn], Le[Maxn], Ri[Maxn], cnt, L, R, n, i, ans;   int main() {     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d , &a[i]);     Le[cnt = 1] = 1;     a[++n] = a[n - 1] - 1;     for (i = 1; i <= n; i++)       if (a[i] <= a[i - 1]) {         Ri[cnt] = i - 1;         ans = max(ans, Ri[cnt] - Le[cnt] + 1);         Le[++cnt] = i;       }     for (i = 1; i < cnt; i++) {       if (Ri[i] < n - 1 || Le[i] > 1) ans = max(ans, Ri[i] - Le[i] + 2);       if (i > 1)         if (Ri[i - 1] > Le[i - 1] && Ri[i] > Le[i]) {           if (a[Ri[i - 1] - 1] < a[Le[i]] - 1 || a[Ri[i - 1]] < a[Le[i] + 1] - 1)             ans = max(ans, Ri[i] - Le[i - 1] + 1);         } else {           if (Ri[i - 1] == Le[i - 1]) ans = max(ans, Ri[i] - Le[i] + 2);           if (Ri[i] == Le[i]) ans = max(ans, Ri[i - 1] - Le[i - 1] + 2);         }     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   vector<int> path[1005];   long long d[105], t[105];   int n, m, u, v;   queue<int> q;   void work(int now) {     for (int i = 1; i <= n; i++) {       d[i] = 1 << 30;       t[i] = 0;     }     d[now] = 0;     t[now] = 1;     q.push(now);     while (!q.empty()) {       u = q.front();       q.pop();       for (int i = 0; i < path[u].size(); i++) {         v = path[u][i];         if (d[v] > d[u] + 1) {           d[v] = d[u] + 1;           t[v] = t[u];           q.push(v);         } else if (d[v] == d[u] + 1) {           t[v] += t[u];         }       }     }   }   int main() {     long long len = 0, tmp = 0;     double ans = 1.0;     scanf( %d %d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d %d , &u, &v);       path[u].push_back(v);       path[v].push_back(u);     }     int start = 1;     work(start), start++;     len = d[n], tmp = t[n];     for (int i = start; i < n; i++) {       start = 1;       work(i);       int see = 0;       see = d[start] + d[n];       if (see == len) {         double k = 0;         k = (double)(2.0 * t[start] * t[n]) / (1.0 * tmp);         ans = max(ans, k);       }     }     printf( %.12lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long p, q, b, n, tmp;   long long gcd(int x, int y) { return y ? gcd(y, x % y) : x; }   int main() {     ios::sync_with_stdio(false);     cin.tie();     cout.tie();     cin >> n;     for (int i = 0; i < n; i++) {       cin >> p >> q >> b;       q = q / gcd(q, p);       while ((tmp = gcd(q, b)) != 1)         while (q % tmp == 0) q /= tmp;       if (q == 1)         cout <<  Finite  << endl;       else         cout <<  Infinite  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   long long binpow(long long a, long long b) {     if (b == 0) return 1;     long long res = binpow(a, b / 2);     if (b % 2)       return res * res * a;     else       return res * res;   }   vector<int> adj[200006];   bool vis[200006];   bool color[200006];   bool dfs(int x) {     vis[x] = 1;     for (int i = 0; i < adj[x].size(); i++) {       if (!vis[adj[x][i]]) {         color[adj[x][i]] = !color[x];         if (!dfs(adj[x][i])) return false;       } else if (color[adj[x][i]] == color[x]) {         return false;       }     }     return true;   }   bool check(int a, int b) {     while (a != 0) {       int x = a % 10;       if (x == 7) return 1;       a /= 10;     }     while (b != 0) {       int xx = b % 10;       if (xx == 7) return 1;       b /= 10;     }     return 0;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int tt;     cin >> tt;     vector<pair<pair<int, int>, char>> vv;     int ewq = 0;     while (tt--) {       char c;       int r, l;       cin >> c >> l >> r;       vv.push_back({{l, r}, c});     }     sort(vv.begin(), vv.end());     int F = 0;     int M = 0;     for (int i = 1; i <= 366; i++) {       F = 0;       M = 0;       for (int j = 0; j < vv.size(); j++) {         if (i >= vv[j].first.first && i <= vv[j].first.second) {           if (vv[j].second ==  F )             F++;           else             M++;         }       }       ewq = max(min(F, M), ewq);     }     cout << ewq * 2 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, k;     cin >> n >> k;     string x;     cin >> x;     string ans = x;     string y =   ;     long long p = n;     for (long long i = 1; i < n; i++) {       long long j;       y =   ;       for (j = 0; i + j < n; j++) {         if (x[i + j] != ans[j]) break;         y += ans[j];       }       if (i + j == n) {         p = i;         break;       }     }     p = n - p;     while (p--) {       ans.erase(ans.begin());     }     cout << x;     while (--k) {       cout << ans;     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1005;   const int W = 1005;   const long long inf = 1e18;   struct dsu {     vector<int> pr;     vector<int> weights;     vector<long long> beauties;     set<int> roots;     dsu(int _n) {       pr.resize(_n + 5);       weights.resize(_n + 5);       beauties.resize(_n + 5);       iota((pr).begin(), (pr).end(), 0);       for (int u = (1); u <= ((_n)); u += (+1)) {         roots.insert(u);       }     }     int find(int u) { return pr[u] == u ? u : pr[u] = find(pr[u]); }     bool unite(int u, int v) {       u = find(u);       v = find(v);       if (u != v) {         pr[u] = v;         beauties[v] += beauties[u];         weights[v] += weights[u];         roots.erase(u);         return true;       }       return false;     }   };   set<int> who[W];   long long dp[W];   int weights[N];   long long beauties[N];   bool done[W];   int n, m, max_w;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout.precision(15);     cin >> n >> m >> max_w;     dsu dg(n);     for (int u = (1); u <= ((n)); u += (+1)) {       int w;       cin >> w;       dg.weights[u] = weights[u] = w;     }     for (int u = (1); u <= ((n)); u += (+1)) {       long long b;       cin >> b;       dg.beauties[u] = beauties[u] = b;     }     for (int i = (0); i <= ((m)-1); i += (+1)) {       int u, v;       cin >> u >> v;       dg.unite(u, v);     }     done[0] = true;     for (int u : dg.roots) {       for (int w = (max_w); w >= (0); w += (-1)) {         if (w - dg.weights[u] < 0) {           break;         }         int ru = dg.find(u);         if (dp[w - dg.weights[u]] + dg.beauties[u] > dp[w] &&             !who[w - dg.weights[ru]].count(ru) && done[w - dg.weights[u]]) {           done[w] = true;           dp[w] = dp[w - dg.weights[u]] + dg.beauties[u];           who[w] = who[w - dg.weights[u]];           who[w].insert(ru);         }       }     }     for (int u = (1); u <= ((n)); u += (+1)) {       for (int w = (max_w); w >= (0); w += (-1)) {         if (w - weights[u] < 0) {           break;         }         int ru = dg.find(u);         if (dp[w - weights[u]] + beauties[u] > dp[w] &&             !who[w - weights[u]].count(ru) && done[w - weights[u]]) {           done[w] = true;           dp[w] = dp[w - weights[u]] + beauties[u];           who[w] = who[w - weights[u]];           who[w].insert(ru);         }       }     }     cout << *max_element(dp, dp + max_w + 1) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char c[600];   vector<int> check;   int n;   vector<int> cal;   int calculate() {     int num = 0;     cal.clear();     int minimum = INT_MAX;     for (int i = 1; i <= n; i++) {       if (c[i - 1] ==  ( ) {         num++;         minimum = min(minimum, num);         cal.push_back(num);       } else {         num--;         minimum = min(minimum, num);         cal.push_back(num);       }     }     int ret = 0;     for (int i = 1; i <= n; i++) {       if (minimum == cal[i - 1]) {         ret++;       }     }     return ret;   }   int main() {     scanf( %d , &n);     scanf( %s , c);     int ans_l = 1, ans_r = 1;     int beauty = INT_MIN;     int cnt = 0;     for (int i = 1; i <= n; i++) {       if (c[i - 1] ==  ( ) {         cnt++;       } else {         cnt--;       }     }     if (cnt != 0) {       printf( 0 n1 1 );       return 0;     }     for (int i = 1; i <= n; i++) {       for (int j = i; j <= n; j++) {         char temp = c[j - 1];         c[j - 1] = c[i - 1];         c[i - 1] = temp;         int now_beauty = calculate();         if (beauty < now_beauty) {           beauty = now_beauty;           ans_l = i;           ans_r = j;         }         temp = c[j - 1];         c[j - 1] = c[i - 1];         c[i - 1] = temp;       }     }     printf( %d n%d %d , beauty, ans_l, ans_r);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   const long long MOD = 1e9 + 7;   const int N = 1e6;   int T, n, r, A[1005];   void solve() {     cin >> n >> r;     for (int i = 1; i <= n; i++) {       cin >> A[i];     }     int ans = 0;     int z;     for (int i = 1; i <= n; i = z + r) {       bool can_warm = false;       z = -1;       int left = max(i - r + 1, 0), right = min(i + r, n + 1);       for (int j = left; j < right; j++) {         if (A[j]) {           can_warm = true;           z = j;         }       }       if (!can_warm) {         cout << -1;         return;       }       ans++;     }     cout << ans;   }   int(main)() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     T = 1;     while (T--) {       solve();     }   }


#include<iostream>   #include<bits/stdc++.h>   using namespace std;   #define boost ios_base::sync_with_stdio(false); cin.tie(NULL)   #define ll unsigned long long int   #define tinput int t; cin>>t; while(t--)   #define rep(i,n,s) for((i)=(s); (i)<(n); (i)++)      template <typename T>   T getmini(T x, T y) { return (x<y)?x:y; }   template <typename T>   T getmaxi(T x, T y) { return (x>y)?x:y; }      int main(){       #ifndef ONLINE_JUDGE       freopen( b_input.txt ,  r , stdin);  freopen( b_output.txt ,  w , stdout);       #endif       boost;              tinput {        int x, y;        cin>>x>>y;        int ans = x+y;        if(abs(x-y)>1) {         ans = ans + abs(x-y) - 1;        }        cout<<ans<<endl;       }          return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   int pa[maxn], a[maxn], b[maxn];   struct Edge {     int u, v, w;     friend bool operator<(const Edge& a, const Edge& b) { return a.w > b.w; }   } e[maxn];   void init(int n) {     for (int i = 1; i <= n; i++) pa[i] = i, b[i] = 1;   }   int find(int x) {     if (x == pa[x]) return x;     return pa[x] = find(pa[x]);   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     init(n);     for (int i = 1; i <= m; i++) {       scanf( %d%d , &e[i].u, &e[i].v);       e[i].w = min(a[e[i].u], a[e[i].v]);     }     sort(e + 1, e + m + 1);     double sum = 0;     for (int i = 1; i <= m; i++) {       int fu = find(e[i].u);       int fv = find(e[i].v);       if (fu != fv) {         sum += 1.0 * e[i].w * b[fu] * b[fv];         pa[fv] = fu;         b[fu] += b[fv];         b[fv] = 1;       }     }     printf( %.6f n , sum * 2 / (1.0 * n * (n - 1)));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long M = 1e9 + 7;   long long power(long long a, long long p) {     if (p == 0) return 1;     long long ans = power(a, p / 2);     ans = (ans * ans) % M;     if (p % 2) ans = (ans * a) % M;     return ans;   }   int nC2(int n) { return (n * (n - 1)) / 2; }   int fact(int n) {     if (n == 0 || n == 1) {       return 1;     } else {       return n * fact(n - 1);     }   }   int countOne(int n) { return __builtin_popcount(n); }   int checkParity(int n) { return __builtin_parity(n); }   int digitCount(int n) { return floor(log10(n)) + 1; }   int log2(int x) {     int res = 0;     while (x >>= 1) res++;     return res;   }   int isPowerof2(int x) { return (x && !(x & x - 1)); }   bool is_prime(int n) {     if (n == 1) {       return false;     }     int i = 2;     while (i * i <= n) {       if (n % i == 0) {         return false;       }       i += 1;     }     return true;   }   int main() {     int test, n, m, x, y, counter = 0, sum = 0, ans = 0, res = 0, rem = 0;     bool flag = true;     bool check = true;     string s;     cin >> n;     for (int i = 0; i < n; i++) {       if (i % 2 == 0 && flag == true) {         cout <<  a ;         check = true;       } else if (i % 2 != 0 && check == true) {         cout <<  b ;         flag = false;       } else if (i % 2 == 0 && flag == false) {         cout <<  b ;         check = false;       } else if (i % 2 != 0 && check == false) {         cout <<  a ;         flag = true;       }     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void test_case();   long long power(int n, int p);   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       test_case();     }     return 0;   }   void test_case() {     int n, x;     cin >> n >> x;     vector<int> arr(n);     for (int i = 0; i < n; i++) cin >> arr[i];     sort(arr.begin(), arr.end());     int teams = 0;     int cnt = 1;     for (int ptr = n - 1; ptr >= 0; ptr--) {       if (arr[ptr] * cnt >= x) {         teams++;         cnt = 1;       } else         cnt++;     }     cout << teams <<   n ;   }   long long power(int n, int p) {     long long ans = 1;     if (p == 0) return 1;     long long temp = power(n, p / 2);     if (p % 2 == 0)       ans = (temp * temp) % 1000000007;     else {       ans = (ans * n) % 1000000007;       ans *= (temp * temp) % 1000000007;     }     return ans;   }


#include <bits/stdc++.h>   using namespace std;   struct rec {     int l, r;   };   rec f[2222][2223];   bool can[2222][2223];   int n, m, k, x, y, xx, yy;   void del(int x, int y) {     can[x][y] = false;     for (int i = 1; i <= m; i++) {       f[x][i].l = f[x][i - 1].l;       if (can[x][i - 1]) f[x][i].l = i - 1;     }     for (int i = m; i >= 1; i--) {       f[x][i].r = f[x][i + 1].r;       if (can[x][i + 1]) f[x][i].r = i + 1;     }     return;   }   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         f[i][j].l = j - 1;         f[i][j].r = j + 1;         can[i][j] = true;       }     for (int i = 1; i <= n; i++) {       f[i][m + 1].r = m + m;     }     while (k--) {       int ans = n + m + n + m;       scanf( %d%d , &x, &y);       for (int i = 1; i <= n; i++) {         int u = abs(i - x);         if (can[i][y]) {           if (ans > u) {             ans = u;             xx = i;             yy = y;           }         } else {           if (f[i][y].l > 0 && ans > u + abs(f[i][y].l - y)) {             ans = u + abs(f[i][y].l - y);             xx = i;             yy = f[i][y].l;           }           if (f[i][y].r < m + 1 && ans > u + abs(f[i][y].r - y)) {             ans = u + abs(f[i][y].r - y);             xx = i;             yy = f[i][y].r;           }         }         if (ans == 0) break;       }       printf( %d %d n , xx, yy);       del(xx, yy);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   const int N = 132007;   int n, a, b;   int rev[N], fac[N], finv[N], f[N], g[N], h[N];   inline int qpow(int x, int k, int r = 1) {     for (; k; k >>= 1, x = 1ll * x * x % mod)       if (k & 1) r = 1ll * r * x % mod;     return r;   }   inline void ntt(int *a, int len, int opt) {     for (int i = 0; i < len; ++i)       if (i < rev[i]) swap(a[i], a[rev[i]]);     for (int i = 1; i < len; i <<= 1) {       int wn = qpow(3, (mod - 1) / (i << 1));       for (int j = 0; j < len; j += i << 1) {         int w = 1;         for (int k = 0; k < i; ++k, w = 1ll * w * wn % mod) {           int x = a[j + k], y = 1ll * a[j + k + i] * w % mod;           a[j + k] = (x + y) % mod;           a[j + k + i] = (x - y + mod) % mod;         }       }     }     if (~opt) return;     reverse(a + 1, a + len);     const int inv = qpow(len, mod - 2);     for (int i = 0; i < len; ++i) a[i] = 1ll * a[i] * inv % mod;   }   void solve(int n) {     if (!n) return g[1] = 1, void();     int t = n - 1 >> 1, mid = n + 1 >> 1, len = 1, bit = 0;     for (; len <= n + 2; len <<= 1, ++bit)       ;     solve(t);     for (int i = 0; i < len; ++i) rev[i] = rev[i >> 1] >> 1 | (i & 1) << bit - 1;     for (int i = f[0] = 1; i <= mid; ++i) f[i] = 1ll * f[i - 1] * mid % mod;     for (int i = 0; i <= mid; ++i)       f[i] = 1ll * f[i] * finv[i] % mod, h[i] = 1ll * g[i] * fac[i] % mod;     for (int i = mid + 1; i < len; ++i) f[i] = h[i] = 0;     reverse(f, f + mid + 2);     ntt(f, len, 1);     ntt(h, len, 1);     for (int i = 0; i < len; ++i) h[i] = 1ll * f[i] * h[i] % mod;     ntt(h, len, -1);     for (int i = 0; i <= mid; ++i) h[i] = 1ll * h[i + mid + 1] * finv[i] % mod;     for (int i = mid + 1; i < len; ++i) h[i] = 0;     ntt(g, len, 1);     ntt(h, len, 1);     for (int i = 0; i < len; ++i) g[i] = 1ll * g[i] * h[i] % mod;     ntt(g, len, -1);     if (n & 1) return;     for (int i = mid + mid + 1; i < len; ++i) g[i] = 0;     for (int i = len - 1; i; --i) g[i] = (g[i - 1] + 1ll * g[i] * n) % mod;   }   inline int C(int n, int m) {     return 1ll * fac[n] * finv[m] % mod * finv[n - m] % mod;   }   int main() {     scanf( %d%d%d , &n, &a, &b);     long long ans = 0;     if (a == b && a == 1) return printf( %d n , n == 1) & 0;     if (a + b > n + 1 || !a || !b) return printf( %d n , 0) & 0;     for (int i = fac[0] = 1; i <= n; ++i) fac[i] = 1ll * fac[i - 1] * i % mod;     finv[n] = qpow(fac[n], mod - 2);     for (int i = n; i; --i) finv[i - 1] = 1ll * finv[i] * i % mod;     solve(n - 2);     return printf( %lld n , 1ll * g[a + b - 2] * C(a + b - 2, a - 1) % mod) & 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, x;   vector<int> v;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d , &x);       int a = lower_bound(v.begin(), v.end(), x) - v.begin();       if (a == v.size())         v.push_back(x);       else         v[a] = x;     }     printf( %d n , v.size());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int b;     cin >> n >> b;     int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     int mini[n];     mini[0] = a[0];     for (int i = 1; i < n; i++) {       mini[i] = min(mini[i - 1], a[i]);     }     int maxi = b;     for (int i = 1; i < n; i++) {       maxi = max(maxi, b % mini[i] + (b / mini[i]) * a[i]);     }     cout << maxi;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e5 + 10;   int n, m, x, y, w, cnt, col[maxn], dis[maxn], vis[maxn], d[maxn], head[maxn];   struct node {     int nxt, to, val;   } e[maxn << 1];   void add(int x, int y, int w) {     e[++cnt].to = y;     e[cnt].nxt = head[x];     head[x] = cnt;     e[cnt].val = w;   }   queue<int> q;   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; ++i) {       scanf( %d%d%d , &x, &y, &w);       add(y, x, w);     }     if (n == 1) {       cout <<  0  << endl <<  0 ;       return 0;     }     memset(col, -1, sizeof(col));     q.push(n);     vis[n] = 0;     while (q.size()) {       int x = q.front();       q.pop();       if (x == 1) {         break;       }       for (int i = head[x]; i; i = e[i].nxt) {         int v = e[i].to;         if (vis[v]) continue;         if (col[v] == -1 || col[v] == 1 - e[i].val) {           col[v] = 1 - e[i].val;         } else {           q.push(v);           d[v] = d[x] + 1;           vis[v] = 1;         }       }     }     if (d[1]) {       cout << d[1] << endl;     } else {       cout <<  -1  << endl;     }     for (int i = 1; i <= n; ++i) {       if (col[i] == -1) {         cout <<  0 ;       } else {         cout << col[i];       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int fpow(long long int n, long long int k,                      long long int p = 1000000007) {     long long int r = 1;     n = n % p;     while (k > 0) {       if (k & 1) {         r = (r * n) % p;       }       k = k >> 1;       n = (n * n) % p;     }     return r;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int n;     cin >> n;     if (n <= 9) {       cout << 1 <<   n ;       cout << n;     } else {       long long int ans = -1;       for (long long int i = 1; i <= 9; i++) {         if (n % i == 0) ans = i;       }       cout << n / ans <<   n ;       for (long long int i = 1; i <= n / ans; i++) cout << ans <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 51, MOD = 1e9 + 7;   struct Matrix {     int num[6][6];     Matrix() { memset(num, 0, sizeof(num)); }     inline int* operator[](const int& x) { return num[x]; }     inline const int* operator[](const int& x) const { return num[x]; }   };   Matrix mat, mat2, x, x2;   int f1, f2, f3, c, res;   long long int n;   inline long long int read() {     register long long int num = 0, neg = 1;     register char ch = getchar();     while (!isdigit(ch) && ch !=  - ) {       ch = getchar();     }     if (ch ==  - ) {       neg = -1;       ch = getchar();     }     while (isdigit(ch)) {       num = (num << 3) + (num << 1) + (ch -  0 );       ch = getchar();     }     return num * neg;   }   inline int qpow(int base, int exponent) {     int res = 1;     while (exponent) {       if (exponent & 1) {         res = (long long int)res * base % MOD;       }       base = (long long int)base * base % MOD, exponent >>= 1;     }     return res;   }   inline Matrix operator*(Matrix x, Matrix y) {     Matrix res;     for (register int i = 1; i <= 5; i++) {       for (register int j = 1; j <= 5; j++) {         for (register int k = 1; k <= 5; k++) {           res[i][j] = (res[i][j] + (long long int)x[i][k] * y[k][j] % (MOD - 1)) %                       (MOD - 1);         }       }     }     return res;   }   inline Matrix qpow(Matrix base, long long int exponent) {     Matrix res;     for (register int i = 1; i <= 5; i++) {       res[i][i] = 1;     }     while (exponent) {       if (exponent & 1) {         res = res * base;       }       base = base * base, exponent >>= 1;     }     return res;   }   int main() {     n = read(), f1 = read(), f2 = read(), f3 = read(), c = read(), res = 1;     mat[1][1] = mat[2][1] = mat[3][1] = mat[1][2] = mat[2][3] = mat[4][4] =         mat[5][4] = 1;     mat[5][5] = x[1][5] = mat2[1][1] = 1, mat[4][1] = 2, mat[5][1] = MOD - 5,     x[1][4] = 3;     mat2[2][1] = mat2[3][1] = mat2[1][2] = mat2[2][3] = x2[1][3] = 1;     res = qpow(c, (x * qpow(mat, n - 3))[1][1]);     res = (long long int)res * qpow(f1, (x2 * qpow(mat2, n - 3))[1][1]) % MOD,     x2[1][3] = 0, x2[1][2] = 1;     res = (long long int)res * qpow(f2, (x2 * qpow(mat2, n - 3))[1][1]) % MOD,     x2[1][2] = 0, x2[1][1] = 1;     res = (long long int)res * qpow(f3, (x2 * qpow(mat2, n - 3))[1][1]) % MOD,     printf( %d n , res);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t, i, n, ans = 0, k = 0, mx;     cin >> n;     long long int a[n];     for (i = 0; i < n; i++) {       cin >> a[i];     }     ans = a[0] / 3;     k = a[0] % 3;     for (i = 1; i < n; i++) {       mx = min(k, a[i] / 2);       ans += mx;       k -= mx;       a[i] -= 2 * mx;       ans += a[i] / 3;       k += a[i] % 3;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void data() {}   const int N = 1e6 + 100;   const long long mod = 998244353;   const long long mod2 = 1e9 + 7;   int main() {     data();     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long k;     cin >> k;     string second;     cin >> second;     vector<long long> pos;     long long ans = 0;     if (k == 0) {       long long ans = 0;       long long cur = 0;       for (long long i = 0; i < second.size(); i++) {         if (second[i] ==  0 ) {           cur++;         } else {           ans += cur * (cur + 1) / 2;           cur = 0;         }       }       ans += cur * (cur + 1) / 2;       cout << ans <<   n ;       return 0;     }     pos.push_back(0);     for (long long i = 0; i < second.size(); i++) {       if (second[i] ==  0 ) {         continue;       }       pos.push_back(i + 1);     }     pos.push_back(second.size() + 1);     long long cur = 0;     for (long long i = 0; i < second.size(); i++) {       if (second[i] ==  0 ) {         continue;       }       cur++;       if (cur >= k) {         ans += (pos[cur - k + 1] - pos[cur - k]) * (pos[cur + 1] - pos[cur]);       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   const int INF = (1 << 30) - 1;   long long Gcd(long long a, long long b) {     while (a > 0 && b > 0) {       if (a > b)         a %= b;       else         b %= a;     }     return a + b;   }   long long x, y;   int main() {     cin >> x >> y;     if (Gcd(x, y) != 1) {       printf( Impossible n );       return 0;     }     vector<char> ans;     while (x > 0 && y > 0) {       if (x > y) {         long long k = x / y;         x %= y;         if (x == 0) k--;         vector<char> g;         while (k) {           g.push_back(k % 10 +  0 );           k /= 10;         }         for (int i = g.size() - 1; i >= 0; --i) ans.push_back(g[i]);         ans.push_back( A );       } else {         long long k = y / x;         y %= x;         if (y == 0) k--;         vector<char> g;         while (k) {           g.push_back(k % 10 +  0 );           k /= 10;         }         for (int i = g.size() - 1; i >= 0; --i) ans.push_back(g[i]);         ans.push_back( B );       }     }     for (int i = 0; i < ans.size(); ++i) printf( %c , ans[i]);     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long read() {     char ch;     for (ch = getchar(); ch <  0  || ch >  9 ; ch = getchar())       ;     long long x = ch -  0 ;     for (ch = getchar(); ch >=  0  && ch <=  9 ; ch = getchar())       x = x * 10 + ch -  0 ;     return x;   }   const int N = 2 * 1e5 + 5;   struct node {     long long j, k;     node(long long _j = 0, long long _k = 0) {       j = _j;       k = _k;     }     friend bool operator<(node x, node y) {       return x.j > y.j || x.j == y.j && x.k > y.k;     }   };   set<node> f;   long long a[N];   int main() {     int n = read();     for (int i = 1; i <= n; i++) a[i] = read();     f.insert(node(a[1] - 1, 0));     for (int i = 1; i <= n - 1; i++) {       long long m = a[i + 1], Mx = 0;       bool pty = 0;       while (1) {         set<node>::iterator pos = f.begin();         long long j = (*pos).j, k = (*pos).k;         if (j < m) break;         pty = 1;         Mx = max(Mx, k + (long long)i * ((j + 1) / m * m - m));         f.insert(node(j % m, k + (long long)i * (j - j % m)));         f.erase(pos);       }       if (pty) f.insert(node(m - 1, Mx));     }     long long ans = 0;     for (set<node>::iterator pos = f.begin(); pos != f.end(); pos++) {       long long j = (*pos).j, k = (*pos).k;       ans = max(ans, k + (long long)j * n);     }     printf( %I64d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10, inf = 1e9 + 10, P = 53, MOD = 1e9 + 7;   vector<int> a, b;   int main() {     ios_base::sync_with_stdio(false);     long long n, x, t = 0;     long long ans = 1;     cin >> n >> x;     for (int i = 0; i < 42; i++)       if ((1ll << i) & x) {         ans *= 2;         n -= (1ll << i);         t++;       }     if (n < 0 || (n == 0 && t == 1)) {       cout << 0;       return 0;     }     if (n == 0) {       cout << ans - 2;       return 0;     }     for (int i = 0; i < 42; i++)       if (!((1ll << i) & x))         if ((1ll << (i + 1)) & n) n -= (1ll << (i + 1));     if (n == 0)       cout << ans;     else       cout << 0;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 110000;   const int M = 1100000;   const long long mod = 1e9 + 7;   const int inf = (int)1e9;   const double eps = 1e-9;   long long n, k, a[N];   long long f[N], inv[N], fac[N], sinv[N], g[N];   long long pw[N];   long long pow_mod(long long a, long long e) {     long long res = 1;     for (; e; a = a * a % mod, e >>= 1)       if (e & 1) res = res * a % mod;     return res;   }   long long num;   long long C(int n, int m) {     long long res = fac[n] * sinv[m] % mod;     res = res * sinv[n - m] % mod;     return res;   }   map<int, int> S;   long long cal(int i) {     if (g[i] != -1) return g[i];     long long fm = pow_mod(pow_mod(k, num), mod - 2);     long long res = 0;     for (int j = 0; j <= num; j++) {       long long tmp = C(num, j) * f[i + j] % mod;       res = (res + tmp * pw[num - j]) % mod;     }     res = res * fm % mod;     g[i] = res;     return g[i];   }   int main() {     cin.sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> a[i];       if (a[i] == -1)         num++;       else         S[a[i]]++;     }     inv[0] = inv[1] = 1;     for (int i = 2; i <= n; i++) inv[i] = pow_mod(i, mod - 2);     fac[0] = 1;     for (int i = 1; i <= n; i++) fac[i] = (fac[i - 1] * (long long)i) % mod;     sinv[0] = 1;     for (int i = 1; i <= n; i++) sinv[i] = (sinv[i - 1] * inv[i]) % mod;     f[0] = 0, f[1] = 0;     for (int i = 2; i <= n; i++) {       long long a = i - 1;       long long tmp1 = (k - 1) * a + n - a;       tmp1 %= mod;       tmp1 = tmp1 * f[i - 1] % mod;       long long tmp2 = (k - 1) * a % mod;       tmp2 %= mod;       tmp2 = tmp2 * f[i - 2] % mod;       long long tmp3 = a * k % mod;       long long tmp = (tmp1 - tmp2 - tmp3 + mod + mod) % mod;       f[i] = tmp * inv[n - a] % mod;     }     pw[0] = 1;     for (int i = 1; i <= n; i++) pw[i] = (pw[i - 1] * (k - 1)) % mod;     memset(g, -1, sizeof(g));     long long ans = 0;     for (auto p : S) {       int val = p.second;       ans = (ans + cal(val)) % mod;     }     ans = (ans + (k - S.size()) * cal(0)) % mod;     cout << (ans - f[n] + mod) % mod <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     int n, m;     cin >> n >> m;     vector<vector<int>> pr(n);     vector<vector<int>> nx(n);     vector<int> a(m);     long long tot = 0;     for (int i = 0; i < m; i++) {       cin >> a[i];       a[i]--;       if (i) {         tot += labs(a[i] - a[i - 1]);         pr[a[i]].push_back(a[i - 1]);         nx[a[i - 1]].push_back(a[i]);       } else {         pr[a[i]].push_back(a[i]);       }     }     nx[a[m - 1]].push_back(a[m - 1]);     long long res = tot;     for (int x = 0; x < n; x++) {       if (!pr[x].size()) continue;       long long was = 0;       for (int i = 0; i < pr[x].size(); i++)         was += labs(x - pr[x][i]) + labs(x - nx[x][i]);       vector<int> v;       for (int i = 0; i < pr[x].size(); i++) {         if (pr[x][i] != x) v.push_back(pr[x][i]);         if (nx[x][i] != x) v.push_back(nx[x][i]);       }       sort(v.rbegin(), v.rend());       long long now = 0;       for (int i = 0; i < v.size(); i++) now += v[0] - v[i];       long long best = now;       for (int i = 1; i < v.size(); i++) {         now += i * (v[i - 1] - v[i]);         now -= ((int)v.size() - i) * (v[i - 1] - v[i]);         best = min(best, now);       }       res = min(res, tot - was + best);     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class X, class Y>   bool minimize(X &x, const Y &y) {     X eps = 1e-9;     if (x > y + eps) {       x = y;       return true;     } else       return false;   }   template <class X, class Y>   bool maximize(X &x, const Y &y) {     X eps = 1e-9;     if (x + eps < y) {       x = y;       return true;     } else       return false;   }   template <class T>   T Abs(const T &x) {     return (x < 0 ? -x : x);   }   const int MOD = (int)1e9 + 7;   int numRow, numCol;   char board[2020][2020];   int range[2020][2020][2], limit[2020][2020][2];   int numWay[2020][2020][2], sumRow[2020][2020][2], sumCol[2020][2020][2];   void init(void) {     scanf( %d%d , &numRow, &numCol);     for (int i = (1), _b = (numRow); i <= _b; i++) scanf( %s , board[i] + 1);     if (board[1][1] ==  R  || board[numRow][numCol] ==  R ) {       cout << 0 << endl;       exit(EXIT_SUCCESS);     }     if (numRow == 1 && numCol == 1) {       cout << 1 << endl;       exit(EXIT_SUCCESS);     }   }   void add(int &x, const int &y) {     x += y;     if (x >= MOD) x -= MOD;   }   int sum(int x, int y) { return x + y >= MOD ? x + y - MOD : x + y; }   int diff(int x, int y) { return x < y ? x - y + MOD : x - y; }   void optimize(void) {     for (int i = (1), _b = (numRow); i <= _b; i++) {       int cntRock = 0;       for (int j = (numCol), _a = (1); j >= _a; j--) {         range[i][j][1] = numCol - cntRock;         if (board[i][j] ==  R ) cntRock++;       }       int k = numCol;       for (int j = (numCol), _a = (1); j >= _a; j--) {         while (k >= 1 && range[i][k][1] >= j) k--;         k++;         limit[i][j][1] = k;       }     }     for (int j = (1), _b = (numCol); j <= _b; j++) {       int cntRock = 0;       for (int i = (numRow), _a = (1); i >= _a; i--) {         range[i][j][0] = numRow - cntRock;         if (board[i][j] ==  R ) cntRock++;       }       int k = numRow;       for (int i = (numRow), _a = (1); i >= _a; i--) {         while (k >= 1 && range[k][j][0] >= i) k--;         k++;         limit[i][j][0] = k;       }     }     for (int i = (2), _b = (numRow); i <= _b; i++) {       if (i <= range[1][1][0]) numWay[i][1][0] = 1;       sumCol[i][1][0] = sum(sumCol[i - 1][1][0], numWay[i][1][0]);       sumRow[i][1][0] = numWay[i][1][0];     }     for (int j = (2), _b = (numCol); j <= _b; j++) {       if (j <= range[1][1][1]) numWay[1][j][1] = 1;       sumRow[1][j][1] = sum(sumRow[1][j - 1][1], numWay[1][j][1]);       sumCol[1][j][1] = numWay[1][j][1];     }     for (int i = (2), _b = (numRow); i <= _b; i++)       for (int j = (2), _b = (numCol); j <= _b; j++) {         int k = limit[i][j][1];         numWay[i][j][1] = diff(sumRow[i][j - 1][0], sumRow[i][k - 1][0]);         k = limit[i][j][0];         numWay[i][j][0] = diff(sumCol[i - 1][j][1], sumCol[k - 1][j][1]);         for (int k = 0, _n = (2); k < _n; k++) {           sumRow[i][j][k] = sum(sumRow[i][j - 1][k], numWay[i][j][k]);           sumCol[i][j][k] = sum(sumCol[i - 1][j][k], numWay[i][j][k]);         }       }     printf( %d n , sum(numWay[numRow][numCol][1], numWay[numRow][numCol][0]));   }   int main(void) {     init();     optimize();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c;     cin >> a >> b >> c;     cout << (a - 1) * (b + c - 1) + b * c << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     ll t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       int ar[n];       int su = 0;       for (int i = 0; i < n; i++) {         cin >> ar[i];         su += ar[i];       }       int ans = min(su, m);       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const long long int INF = 1e12;   int n, k;   int memo[101][101][101];   int solve(string &str, int i, int N, int _max) {     _max = max(N, _max);     int &a = memo[i][N][_max];     if (a != -1) return a;     if (i == n) {       if (_max == k) return a = 1;       return a = 0;     }     if (str[i] ==  Y )       return a = solve(str, i + 1, 0, _max);     else if (str[i] ==  N )       return a = solve(str, i + 1, N + 1, _max);     else {       if (solve(str, i + 1, 0, _max)) return a = 1;       return a = solve(str, i + 1, N + 1, _max);     }     return a = 0;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     memset(memo, -1, sizeof(memo));     cin >> n >> k;     string str;     cin >> str;     if (solve(str, 0, 0, 0))       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int type, pos, len, start[100020], dest[100020], a[100020], b[100020], q, n,       seg[4 * 100020];   bool mark[4 * 100020];   void setVal(int v, int vl, int vr, int val, int l, int r) {     if (l <= vl && vr <= r) {       seg[v] = max(seg[v], val);       mark[v] = true;       return;     }     if (r < vl || l > vr || vl == vr) return;     if (mark[v]) {       mark[v] = false;       mark[2 * v] = mark[2 * v + 1] = true;       seg[2 * v] = max(seg[2 * v], seg[v]);       seg[2 * v + 1] = max(seg[2 * v + 1], seg[v]);     }     int mid = (vl + vr) / 2;     setVal(2 * v, vl, mid, val, l, r);     setVal(2 * v + 1, mid + 1, vr, val, l, r);     seg[v] = max(seg[2 * v], seg[2 * v + 1]);   }   int getVal(int v, int vl, int vr, int p) {     int mid = (vl + vr) / 2;     if (vl == vr) return seg[v];     if (mark[v]) {       mark[v] = false;       mark[2 * v] = mark[2 * v + 1] = true;       seg[2 * v] = max(seg[2 * v], seg[v]);       seg[2 * v + 1] = max(seg[2 * v + 1], seg[v]);     }     if (p <= mid)       return getVal(2 * v, vl, mid, p);     else       return getVal(2 * v + 1, mid + 1, vr, p);   }   int main() {     scanf( %d %d , &n, &q);     for (__typeof(n) i = (1); i <= (n); i++) scanf( %d , &b[i]);     for (__typeof(n) i = (1); i <= (n); i++) scanf( %d , &a[i]);     for (__typeof(q) i = (1); i <= (q); i++) {       scanf( %d , &type);       if (type == 2) {         scanf( %d , &pos);         int idx = getVal(1, 1, n, pos);         if (idx == 0)           printf( %d n , a[pos]);         else           printf( %d n , b[start[idx] + pos - dest[idx]]);       } else {         scanf( %d %d %d , &start[i], &dest[i], &len);         setVal(1, 1, n, i, dest[i], dest[i] + len - 1);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int y, b, r, ans = 0;     cin >> y >> b >> r;     if (y + 1 <= b && y + 2 <= r) {       ans = max(ans, 3 * y + 3);     }     if (b + 1 <= r && b - 1 <= y) {       ans = max(ans, 3 * b);     }     if (r - 1 <= b && r - 2 <= y) {       ans = max(ans, 3 * r - 3);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void umin(T &a, T b) {     a = min(a, b);   }   template <class T>   inline void umax(T &a, T b) {     a = max(a, b);   }   const int INF = 0x3f3f3f3f;   long long mod = 1e9 + 7;   const int N = 100005;   char s[N];   struct Trie {     static const int maxnode = 100005;     static const int sigma_size = 26;     int ch[maxnode][sigma_size];     int val[maxnode];     int p[maxnode];     int d[maxnode], ms[maxnode];     priority_queue<int> q[maxnode];     int sz;     void clear() {       sz = 1;       memset(ch[0], 0, sizeof(ch[0]));     }     int idx(char c) { return c -  a ; }     void insert(const char *s, int v) {       int u = 0, n = strlen(s);       for (int i = 0; i < n; i++) {         int c = idx(s[i]);         if (!ch[u][c]) {           memset(ch[sz], 0, sizeof(ch[sz]));           val[sz] = 0;           ch[u][c] = sz++;           d[ch[u][c]] = d[u] + 1;         }         p[ch[u][c]] = u;         u = ch[u][c];       }       val[u] = v;     }     void dfs(int u) {       for (int i = 0; i < 26; i++) {         int v = ch[u][i];         if (v) {           dfs(v);           while (!q[v].empty()) {             q[u].push(q[v].top());             q[v].pop();           }         }       }       if (u == 0) return;       if (val[u] == 0) {         q[u].pop();         q[u].push(d[u]);       } else {         q[u].push(d[u]);       }     }     int solve() {       dfs(0);       int ans = 0;       while (!q[0].empty()) {         ans += q[0].top();         q[0].pop();       }       return ans;     }   } wc;   int main() {     int n;     scanf( %d , &n);     wc.clear();     for (int i = 0; i < n; i++) {       scanf( %s , s);       wc.insert(s, 1);     }     printf( %d n , wc.solve());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int idata = 2e5 + 7;   int i, j, k;   int judge, flag;   long long step[idata];   long long temp;   int n, m, t;   double maxx = 0, minn = inf;   long long cnt, len, sum, ans;   long long high, wigh;   map<long long, int> pre[2];   signed main() {     while (cin >> n >> k) {       memset(step, 0, sizeof step);       for (i = 1; i <= n; i++) {         cin >> step[i];         pre[0][step[i]]++;       }       for (i = 1; i <= n; i++) {         pre[0][step[i]]--;         if (step[i] % k == 0) {           ans += (long long)pre[1][step[i] / k] * pre[0][step[i] * k];         }         pre[1][step[i]]++;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000005;   int n;   int a[MAXN];   int x[MAXN];   int y[MAXN];   int match[MAXN];   bool vis[MAXN];   int main() {     ios::sync_with_stdio(0);     cin >> n;     if (~n & 1) {       cout <<  First  << endl;       for (int i = 1; i <= n; i++) cout << i <<    ;       for (int i = 1; i <= n; i++) cout << i <<    ;       cout << endl;       cout.flush();       return 0;     } else {       cout <<  Second  << endl;       for (int i = 1; i <= 2 * n; i++) {         cin >> a[i];         if (x[a[i]])           y[a[i]] = i;         else           x[a[i]] = i;       }       for (int i = 1; i <= n; i++) {         match[x[i]] = y[i];         match[y[i]] = x[i];       }       for (int i = 1; i <= n; i++) {         int cur = i;         if (vis[i] || vis[i + n]) continue;         while (!vis[cur]) {           vis[cur] = 1;           cur = (match[cur] > n ? match[cur] - n : match[cur] + n);         }       }       int sum = 0;       for (int i = 1; i <= 2 * n; i++)         if (vis[i]) (sum += i) %= (2 * n);       if (sum) {         for (int i = 1; i <= 2 * n; i++) vis[i] ^= 1;       }       for (int i = 1; i <= 2 * n; i++)         if (vis[i]) cout << i <<    ;       cout << endl;       cout.flush();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, m, x, y, i, j, k, l;     cin >> n >> m >> x >> y;     cout << x <<     << y <<   n ;     for (i = 1; i <= m; i++)       if (i != y) cout << x <<     << i <<   n ;     int c;     for (i = 1, j = m; i <= n; i++)       if (i != x)         for (k = 1; k <= m; k++) {           cout << i <<     << j <<   n ;           if (j == m)             c = -1;           else if (j == 1)             c = 1;           if (k != m) j += c;         }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   set<int> s;   const int MAX = 150000;   int t[MAX];   int main() {     int n, q, k;     cin >> n >> k >> q;     for (int i = 0; i < n; i++) scanf( %d , t + i);     for (int i = 0; i < q; i++) {       int query;       scanf( %d , &query);       int x;       scanf( %d , &x);       x = t[x - 1];       if (query == 1) {         if (s.size() == k) {           set<int>::iterator it = s.begin();           if (x > *it) {             s.erase(*it);             s.insert(x);           }         } else {           s.insert(x);         }       } else {         if (s.count(x))           printf( YES n );         else           printf( NO n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> v[110];   int cur[110];   int main() {     int n, w;     scanf( %d %d , &n, &w);     for (int i = 0; i < n; ++i) {       scanf( %d , &v[i].first);       v[i].second = i;     }     sort(v, v + n);     reverse(v, v + n);     for (int i = 0; i < n; ++i) {       w -= (v[i].first + 1) / 2;       if (w < 0) return puts( -1 ), 0;       cur[i] = (v[i].first + 1) / 2;     }     for (int i = 0; i < n - 1; ++i) {       if (cur[i] < cur[i + 1]) {         int dif = cur[i + 1] - cur[i];         if (cur[i] == cur[i + 1]) dif++;         if (w >= dif) {           cur[i] += dif;           w -= dif;         } else if (cur[i + 1] >= dif) {           cur[i + 1] -= dif;           cur[i] += dif;         } else           return puts( -1 );       }     }     for (int i = 0; i < n; ++i) {       if (w) {         int dif = v[i].first - cur[i];         if (w >= dif) {           cur[i] += dif;           w -= dif;         } else if (dif >= w) {           cur[i] += w;           w = 0;         }       } else         break;     }     for (int i = 0; i < n; ++i) v[v[i].second].first = cur[i];     for (int i = 0; i < n; ++i) printf( %d  , v[i].first);     puts(  );     return 0;   }


//#pragma GCC optimize( Ofast )      #include <iostream>   #include <vector>   #include <map>   #include <algorithm>   #include <random>   #include <chrono>   #include <complex>   #include <cstdio>   #include <deque>   #include <cmath>   #include <bitset>   #include <set>   #include <cassert>      using namespace std;      #define ll long long   #define ull unsigned long long   #define pb push_back   #define se second   #define fi first   #define forn(i,n) for(int i = 0; i < (n); i++)   #define read(a) for(int i = 0; i < a.size(); i++){cin >> a[i];}   #define all(a) a.begin(),a.end()   #define make_unique(a) sort(all(a)); a.resize(unique(a.begin(),a.end())-a.begin());   const int mod = 1e9 + 7;   //#define int long long      const int N = 10000000;   int lp[N+1];   vector<int> pr;      void solve(){       int t;       cin >> t;          for (int i=2; i<=N; ++i) {           if (lp[i] == 0) {               lp[i] = i;               pr.push_back (i);           }           for (int j=0; j<(int)pr.size() && pr[j]<=lp[i] && i*pr[j]<=N; ++j)               lp[i * pr[j]] = pr[j];       }          set<vector<int>> se;          while(t--){           int n,k;           cin >> n >> k;           vector<int> a(n);           read(a);           ll ans = 1;           se.clear();           for(int i = 0; i < n; ++i){               vector<int> qw;               int nw = a[i];               while(nw != 1){                   if(!qw.empty() && qw.back() == lp[nw]){                       qw.pop_back();                       nw /= lp[nw];                       continue;                   }                   if(qw.empty() || qw.back() != lp[nw]){                       qw.push_back(lp[nw]);                   }                   nw /= lp[nw];                                  }               if(se.count(qw)){                   ans++;                   se.clear();               }               se.insert(qw);           }           cout << ans <<   n ;       }      }            signed main() {       ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);   #ifdef Debugg       freopen( ain.txt , r ,stdin);       freopen( aout.txt , w ,stdout);   #endif       solve();   #ifdef Debugg       cout <<   n  << (double)clock()/CLOCKS_PER_SEC;   #endif   }


#include <bits/stdc++.h>   using namespace std;   inline void pisz(int n) { printf( %d n , n); }   int dl[1000][1000];   int dr[1000][1000];   int ul[1000][1000];   int ur[1000][1000];   int g[1000][1000];   int n, m;   int recdl(int i, int j) {     if (i < 0 || i == n || j < 0 || j == m) return -1001001001;     if (i == n - 1 && j == 0) return g[i][j];     if (dl[i][j] != -1) return dl[i][j];     return dl[i][j] =                g[i][j] + (recdl(i + 1, j) < recdl(i, j - 1) ? recdl(i, j - 1)                                                             : recdl(i + 1, j));   }   int recdr(int i, int j) {     if (i < 0 || i == n || j < 0 || j == m) return -1001001001;     if (i == n - 1 && j == m - 1) return g[i][j];     if (dr[i][j] != -1) return dr[i][j];     return dr[i][j] =                g[i][j] + (recdr(i + 1, j) < recdr(i, j + 1) ? recdr(i, j + 1)                                                             : recdr(i + 1, j));   }   int recul(int i, int j) {     if (i < 0 || i == n || j < 0 || j == m) return -1001001001;     if (i == 0 && j == 0) return g[i][j];     if (ul[i][j] != -1) return ul[i][j];     return ul[i][j] =                g[i][j] + (recul(i - 1, j) < recul(i, j - 1) ? recul(i, j - 1)                                                             : recul(i - 1, j));   }   int recur(int i, int j) {     if (i < 0 || i == n || j < 0 || j == m) return -1001001001;     if (i == 0 && j == m - 1) return g[i][j];     if (ur[i][j] != -1) return ur[i][j];     return ur[i][j] =                g[i][j] + (recur(i - 1, j) < recur(i, j + 1) ? recur(i, j + 1)                                                             : recur(i - 1, j));   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) cin >> g[i][j];     memset(dl, -1, sizeof(dl));     memset(dr, -1, sizeof(dr));     memset(ul, -1, sizeof(ul));     memset(ur, -1, sizeof(ur));     int res = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         int b1 = recul(i - 1, j) + recdl(i, j - 1);         int a1 = recdr(i + 1, j) + recur(i, j + 1);         int b2 = recul(i, j - 1) + recdl(i + 1, j);         int a2 = recdr(i, j + 1) + recur(i - 1, j);         res = (res < (b1 + a1 < b2 + a2 ? b2 + a2 : b1 + a1)                    ? (b1 + a1 < b2 + a2 ? b2 + a2 : b1 + a1)                    : res);       }     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const double eps = 0.0000000001;   const int N = 100000 + 100;   int head[N];   int tot;   struct node {     int to, next;   } edge[N << 1];   int color[N];   int vis[N];   int a[N];   int b[N];   int num[N];   void init() {     memset(head, -1, sizeof(head));     tot = 0;   }   void add(int u, int v) {     edge[tot].to = v;     edge[tot].next = head[u];     head[u] = tot++;   }   int DFS(int u, int t) {     if (vis[u] == 0) {       if (color[u] == 0) a[t]++;       if (color[u] == 1) b[t]++;       num[t]++;     }     vis[u] = 1;     for (int i = head[u]; i != -1; i = edge[i].next) {       int v = edge[i].to;       if (color[v] == 0) {         color[v] = color[u] ^ 1;         if (DFS(v, t) == 0) return 0;       } else if (color[u] == color[v]) {         return 0;       }     }     return 1;   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     init();     int u, v;     for (int i = 1; i <= m; i++) {       scanf( %d%d , &u, &v);       add(u, v);       add(v, u);     }     if (m == 0) {       cout << 3 <<     << (long long)n * (n - 1) * (n - 2) / 6 << endl;       return 0;     }     memset(color, 0, sizeof(color));     memset(vis, 0, sizeof(vis));     int flag = 0;     int t = 0;     for (int i = 1; i <= n; i++) {       if (color[i] == 0 && vis[i] == 0) {         if (DFS(i, ++t) == 0) {           color[i] = 0;           flag = 1;           break;         }       }     }     if (flag == 1) {       cout << 0 <<     << 1 << endl;       return 0;     }     long long ans = 0;     flag = 0;     for (int i = 1; i <= t; i++) {       if (num[i] <= 2) {         flag++;         continue;       }       ans = ans + (long long)a[i] * (a[i] - 1) / 2 +             (long long)b[i] * (b[i] - 1) / 2;     }     if (flag != t)       cout << 1 <<     << ans << endl;     else {       cout << 2 <<     << (long long)m * (n - 2) << endl;     }   }


#include <bits/stdc++.h>   int main() {     int n, pur, foo = 0, quz = 1, bar = 0, baz = 0;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d , &pur);       foo += pur, bar++;       if (foo * quz > bar * baz) quz = bar, baz = foo;     }     printf( %.6lf n , (double)baz / quz);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void fun() {}   long long int md = 998244353;   long long int __gcd(long long int a, long long int b) {     if (b == 0) return a;     return __gcd(b, a % b);   }   long long int poww(long long int a, long long int b, long long int md) {     if (b < 0) return 0;     if (a == 0) return 0;     long long int res = 1;     while (b) {       if (b & 1) {         res = (1ll * res * a) % md;       }       a = (1ll * a * a) % md;       b >>= 1;     }     return res;   }   long long int poww(long long int a, long long int b) {     if (b < 0) return 0;     if (a == 0) return 0;     long long int res = 1;     while (b) {       if (b & 1) {         res = (1ll * res * a);       }       a = (1ll * a * a);       b >>= 1;     }     return res;   }   void ainp(long long int arr[], long long int n) {     for (long long int i = 1; i <= n; i++) cin >> arr[i];   }   void disp(long long int arr[], long long int n) {     for (long long int i = 1; i <= n; i++) cout << arr[i] <<    ;     cout <<   n ;   }   void dispv(vector<long long int> &v) {     for (long long int i = 0; i < v.size(); i++) cout << v[i] <<    ;     cout <<   n ;   }   long long int divide(long long int a, long long int b, long long int md) {     long long int rr = a * (poww(b, md - 2, md));     rr %= md;     return rr;   }   const long long int size = 2e5 + 5;   long long int n, m, k, u, v;   vector<long long int> g[size];   pair<long long int, long long int> dis[size], prr[size];   queue<long long int> q;   long long int arr[size], suffmax[size];   bool fnn(pair<long long int, long long int> &p1,            pair<long long int, long long int> &p2) {     return (p1.first - p1.second < p2.first - p2.second);   }   void bfs() {     dis[1].first = 0;     q.push(1);     while (!q.empty()) {       long long int node = q.front();       q.pop();       for (long long int child : g[node]) {         if (dis[child].first > dis[node].first + 1 ||             (child != 1 && dis[child].first == 0)) {           dis[child].first = dis[node].first + 1;           q.push(child);         }       }     }     q.push(n);     dis[n].second = 0;     while (!q.empty()) {       long long int node = q.front();       q.pop();       for (long long int child : g[node]) {         if (dis[child].second > dis[node].second + 1 ||             (child != n && dis[child].second == 0)) {           dis[child].second = dis[node].second + 1;           q.push(child);         }       }     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     fun();     cin >> n >> m >> k;     ainp(arr, k);     for (long long int i = 1; i <= m; i++) {       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     bfs();     for (long long int i = 1; i <= k; i++) prr[i] = dis[arr[i]];     sort(prr + 1, prr + 1 + k, fnn);     for (long long int i = k; i > 0; i--)       suffmax[i] = max(suffmax[i + 1], prr[i].second);     long long int cost = dis[n].first;     long long int cst = 0;     for (long long int i = 1; i < k; i++) {       cst = max(suffmax[i + 1] + 1 + prr[i].first, cst);     }     cout << min(cst, cost) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, M, T;   int A[20000];   int rans;   vector<int> ans;   set<pair<int, int>> online;   multiset<pair<int, int>> events;   bool solve() {     bool good = false;     for (int i = 0; i < N; i++) events.insert({A[i], -1});     while (!events.empty()) {       int t = events.begin()->first;       int v = events.begin()->second;       events.erase(events.begin());       if (v == -1) {         if ((int)online.size() < M) {           rans++;           online.insert({t + T - 1, rans});           events.insert({t + T - 1, rans});           ans.push_back(rans);         } else {           pair<int, int> guy = *online.rbegin();           online.erase(guy);           events.erase(events.find(guy));           guy.first = t + T - 1;           online.insert(guy);           events.insert(guy);           ans.push_back(guy.second);         }         good |= (int)online.size() == M;       } else         online.erase({t, v});     }     return good;   }   int main() {     scanf( %d%d%d , &N, &M, &T);     int hh, mm, ss;     for (int i = 0; i < N; i++) {       scanf( %d:%d:%d , &hh, &mm, &ss);       A[i] = hh * 3600 + mm * 60 + ss;     }     if (!solve())       printf( No solution n );     else {       printf( %d n , rans);       for (auto& it : ans) printf( %d n , it);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void init_code() {}   int main() {     init_code();     long long t;     cin >> t;     while (t--) {       long long n, k;       cin >> n >> k;       long long num = 1, res = 0;       while (k) {         if (k & 1) {           res += num;           res %= 1000000000 + 7;         }         k >>= 1;         num *= n;         num %= 1000000000 + 7;       }       cout << res <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     for (; b; a %= b, swap(a, b))       ;     return a;   }   int dx[4] = {1, -1, 0, 0};   int dy[4] = {0, 0, 1, -1};   int main(void) {     ios::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     int t;     cin >> t;     while (t--) {       int n, k;       cin >> n >> k;       int ones = 0;       vector<int> one(k);       string st;       cin >> st;       for (int i = 0; i < n; i++) {         if (st[i] ==  1 ) {           one[i % k]++;           ones++;         }       }       int ans = ones;       for (int i = 0; i < k; i++) {         int tmp = ones - one[i % k];         string t =   ;         vector<int> cnt;         cnt.push_back(0);         for (int j = i; j < n; j += k) {           t += st[j];           if (cnt.size() == 0)             cnt.push_back(st[j] -  0 );           else             cnt.push_back(cnt.back() + st[j] -  0 );         }         int len = t.size();         vector<int> dp(len + 1);         int res = 1e9;         for (int j = 1; j <= len; j++) {           int p = (t[j - 1] ==  0  ? 1 : 0);           dp[j] = min(dp[j - 1] + p, cnt[j - 1] + p);         }         for (int j = 1; j <= len; j++) res = min(res, dp[j] + cnt[len] - cnt[j]);         ans = min(ans, res + tmp);       }       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 501;   int a[N][N], b[N][N];   void solve() {     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> a[i][j];       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> b[i][j];       }     }     for (int i = 0; i < m; i++) {       vector<int> comp1, comp2;       int x = 0, y = i;       while (x < n && y >= 0) {         comp1.push_back(a[x][y]);         comp2.push_back(b[x][y]);         x++, y--;       }       sort(comp1.begin(), comp1.end());       sort(comp2.begin(), comp2.end());       if (comp1 != comp2) {         cout <<  NO n ;         return;       }     }     for (int i = 1; i < n; i++) {       vector<int> comp1, comp2;       int x = i, y = m - 1;       while (x < n && y >= 0) {         comp1.push_back(a[x][y]);         comp2.push_back(b[x][y]);         x++, y--;       }       sort(comp1.begin(), comp1.end());       sort(comp2.begin(), comp2.end());       if (comp1 != comp2) {         cout <<  NO n ;         return;       }     }     cout <<  YES n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t = 1;     for (int tt = 1; tt <= t; tt++) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int mirror(int num) {     int res = 0;     for (int i = 0; i < 4; ++i) {       res |= (num & (1 << i)) << (7 - i - i);       res |= (num & (1 << (7 - i))) >> (7 - i - i);     }     return res;   }   int main() {     int num;     string s;     vector<int> res;     getline(cin, s);     num = (0 + 256 - mirror((int)s[0])) % 256;     res.push_back(num);     for (int i = 1; i < s.size(); ++i) {       num = (-mirror(s[i]) + 256 + mirror(s[i - 1])) % 256;       res.push_back(num);     }     for (int i = 0; i < res.size(); ++i) {       cout << res[i] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   struct edge {     int to, nxt, w;   } e[N << 1];   int head[N], tot = 0;   int n, m;   int vis[N], mxd, id;   int sum[N], dr[N], cnt = 0, pa[N], used[N];   int dp[N], a[N], b[N], siz[N], anc[N], mp[N];   void adde(int u, int v, int w) {     e[++tot] = edge{v, head[u], w}, head[u] = tot;   }   void dfs(int u, int fa, int dep) {     pa[u] = fa;     if (vis[u] && dep > mxd) id = u, mxd = dep;     for (int i = head[u]; i; i = e[i].nxt) {       int v = e[i].to;       if (v == fa) continue;       dfs(v, u, dep + e[i].w);     }     return;   }   void gtag(int u, int fa, int *a, int dep) {     a[u] = dep;     for (int i = head[u]; i; i = e[i].nxt) {       int v = e[i].to;       if (v == fa) continue;       gtag(v, u, a, dep + e[i].w);     }     return;   }   void Dfs(int u, int fa, int rt) {     siz[u] = vis[u];     anc[u] = rt;     for (int i = head[u]; i; i = e[i].nxt) {       int v = e[i].to;       if (v == fa) continue;       if (used[v]) continue;       Dfs(v, u, rt);       siz[u] += siz[v];       dp[u] = max(dp[u], dp[v] + e[i].w);     }     return;   }   int main() {     scanf( %d%d , &n, &m);     int x;     for (int i = 1; i <= m; i++) scanf( %d , &x), vis[x] = 1;     int u, v, w;     for (int i = 1; i < n; i++) {       scanf( %d%d%d , &u, &v, &w);       adde(u, v, w), adde(v, u, w);     }     id = mxd = -1;     dfs(1, 0, 0);     int s = id;     id = mxd = -1;     dfs(s, 0, 0);     int t = id;     swap(s, t);     for (int now = s; now; now = pa[now])       dr[++cnt] = now, used[now] = 1, mp[now] = cnt;     dr[cnt + 1] = n + 1;     mp[n + 1] = cnt + 1;     gtag(s, 0, a, 0);     gtag(t, 0, b, 0);     for (int i = 1; i <= cnt; i++) Dfs(dr[i], 0, dr[i]);     int ans = 0;     for (int i = 1; i <= n; i++)       if (!used[i] && !vis[i]) ans = max(ans, siz[i]);     for (int i = 1; i <= n; i++) {       if (!vis[i]) continue;       int u = anc[i];       int d = max(a[u], b[u]);       int k = mp[u];       if (dp[u] == d || (a[u] == d && b[u] == d))         sum[k]++, sum[k + 1]--;       else {         if (a[u] == d)           sum[0]++, sum[k + 1]--;         else           sum[k]++;       }     }     for (int i = 1; i <= cnt; i++) sum[i] += sum[i - 1];     for (int i = 1; i <= cnt; i++)       if (!vis[dr[i]]) ans = max(ans, sum[i]);     int amou = 0;     for (int i = 1; i <= n; i++)       if (!used[i] && !vis[i] && siz[i] == ans) amou++;     for (int i = 1; i <= cnt; i++)       if (!vis[dr[i]] && sum[i] == ans) amou++;     printf( %d %d n , ans, amou);     return 0;   }


#include <bits/stdc++.h>   using std::abs;   using std::bitset;   using std::cerr;   using std::cin;   using std::copy;   using std::cout;   using std::deque;   using std::endl;   using std::fill;   using std::fixed;   using std::greater;   using std::iota;   using std::istream;   using std::lower_bound;   using std::make_pair;   using std::make_tuple;   using std::map;   using std::max;   using std::max_element;   using std::min;   using std::min_element;   using std::multiset;   using std::next_permutation;   using std::nth_element;   using std::ostream;   using std::pair;   using std::priority_queue;   using std::queue;   using std::reverse;   using std::rotate;   using std::set;   using std::sort;   using std::string;   using std::swap;   using std::tie;   using std::tuple;   using std::unique;   using std::unordered_map;   using std::unordered_set;   using std::upper_bound;   using std::vector;   long long rnd(long long x, long long y) {     static auto gen = std::bind(std::uniform_int_distribution<long long>(),                                 std::mt19937(960172));     return gen() % (y - x + 1) + x;   }   long long gcd(long long a, long long b) {     while (b > 0) {       long long t = a % b;       a = b;       b = t;     }     return a;   }   template <typename T>   T sqr(T const& a) {     return a * a;   }   int const INF = 100 + (int)1e9;   long long const INFL = 100 + (long long)1e18;   long double const PI = 3.1415926535897932384626433832795028;   int const N = 211;   int const A = 26;   int next[N][A];   int link[N];   int go[N][A];   int prev[N];   int back[N];   int leaf[N];   int sz;   int getNode(int pr, int edge) {     std::fill(next[sz], next[sz] + A, -1);     link[sz] = -1;     std::fill(go[sz], go[sz] + A, -1);     prev[sz] = pr;     back[sz] = edge;     leaf[sz] = 0;     return sz++;   }   int getGo(int, int);   int getLink(int v) {     if (link[v] == -1) {       if (v == 0 || prev[v] == 0) {         link[v] = 0;       } else {         link[v] = getGo(getLink(prev[v]), back[v]);       }     }     return link[v];   }   int getGo(int v, int x) {     if (go[v][x] == -1) {       if (next[v][x] != -1) {         go[v][x] = next[v][x];       } else if (v == 0) {         go[v][x] = v;       } else {         go[v][x] = getGo(getLink(v), x);       }     }     return go[v][x];   }   void mul(long long a[N][N], long long b[N][N], long long c[N][N]) {     static long long t[N][N];     for (int i = 0; i < N; ++i) {       for (int j = 0; j < N; ++j) {         long long cur = -INFL;         for (int k = 0; k < N; ++k) {           cur = max(cur, a[i][k] + b[k][j]);         }         t[i][j] = cur;       }     }     for (int i = 0; i < N; ++i) {       for (int j = 0; j < N; ++j) {         c[i][j] = t[i][j];       }     }   }   int a[N];   void solve() {     int n;     long long L;     scanf(          %d           %lld ,         &n, &L);     for (int i = 0; i < n; ++i) {       scanf( %d , a + i);     }     static char buf[N];     gets(buf);     getNode(0, 0);     for (int i = 0; i < n; ++i) {       gets(buf);       int v = 0;       for (int j = 0; buf[j]; ++j) {         int x = buf[j] -  a ;         if (next[v][x] == -1) {           next[v][x] = getNode(v, x);         }         v = next[v][x];       }       leaf[v] += a[i];     }     {       vector<int> q = {0};       for (int head = 0; head < (int)q.size(); ++head) {         int v = q[head];         leaf[v] += leaf[getLink(v)];         for (int x = 0; x < A; ++x) {           int to = next[v][x];           if (to >= 0) {             q.push_back(to);           }         }       }     }     static long long mat[N][N];     for (int i = 0; i < N; ++i) {       fill(mat[i], mat[i] + N, -INFL);     }     for (int from = 0; from < sz; ++from) {       for (int x = 0; x < A; ++x) {         int to = getGo(from, x);         if (mat[to][from] == -INFL) {           mat[to][from] = 0;         }         mat[to][from] += leaf[to];       }     }     static long long dp[N];     fill(dp, dp + N, -INFL);     dp[0] = 0;     for (long long l = L; l > 0; l /= 2) {       if (l % 2 == 1) {         static long long dp1[N];         for (int v = 0; v < N; ++v) {           long long cur = -INFL;           for (int u = 0; u < N; ++u) {             cur = max(cur, dp[u] + mat[v][u]);           }           dp1[v] = cur;         }         for (int i = 0; i < N; ++i) {           dp[i] = dp1[i];         }       }       mul(mat, mat, mat);     }     cout << *max_element(dp, dp + N) << endl;   }   int main() {     cout.precision(15);     cout << fixed;     cerr.precision(6);     cerr << fixed;     solve();   }


#include <bits/stdc++.h>   using namespace std;   bool isPrime(int n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (int i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   void solve() {     int n;     cin >> n;     long double pi = 2.0 * acos(0.0), ans, x;     x = pi / (long double)(2.0 * n);     ans = tan(x);     cout << fixed << setprecision(9) << 1.0 / ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     ;     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimise( Ofast ,  unroll-loops)   using namespace std;   void solve() {     int n, m, k;     cin >> n >> m >> k;     long long a[n][m], b[n * m + 3], c[n][m];     memset(a, 0, sizeof(a));     memset(b, 0, sizeof(b));     memset(c, 0, sizeof(c));     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> a[i][j];       }     }     for (int i = 0; i < k; i++) {       int x, y;       cin >> x >> y;       x--;       y--;       b[y]++;       c[x][y]++;     }     for (int i = 0; i < n - 1; i++) {       long long ans = 0;       for (int j = 0; j < m; j++) {         if (a[i][j] == 1) {           ans += (b[j] - c[i][j]);         }       }       cout << ans <<    ;     }     long long ans = 0;     for (int j = 0; j < m; j++) {       if (a[n - 1][j] == 1) {         ans += (b[j] - c[n - 1][j]);       }     }     cout << ans;     return;   }   int main() {     cin.tie(0);     ios_base::sync_with_stdio(0);     int t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long a[14], tmp[14];     for (long long i = 0; i < 14; i++) cin >> a[i];     long long anss = 0;     for (long long i = 0; i < 14; i++) {       for (long long j = 0; j < 14; j++) tmp[j] = a[j];       long long ans = 0;       if (tmp[i]) {         long long k = tmp[i];         long long add = k / 14;         long long rem = k % 14;         tmp[i] = 0;         long long p = i + 1;         for (long long j = 0; j < 14; j++) {           tmp[p % 14] += add;           p++;         }         p = i + 1;         while (rem) {           tmp[p % 14]++;           p++;           rem--;         }         for (long long j = 0; j < 14; j++)           if (tmp[j] % 2 == 0) ans += tmp[j];       }       anss = max(anss, ans);     }     cout << anss;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 300002;   int n, m, l[MAXN * 4], r[MAXN * 4], d[MAXN * 4], id[MAXN];   string s;   void input() {     scanf( %d%d , &n, &m);     cin.ignore(1);     getline(cin, s);     s =  0  + s;   }   void init(int x, int left, int right) {     l[x] = left;     r[x] = right;     if (left == right) {       d[x] = 0;       id[left] = x;       return;     }     int mid = (left + right) / 2;     init(x * 2, left, mid);     init(x * 2 + 1, mid + 1, right);     d[x] = d[x * 2] + d[x * 2 + 1];     if (s[mid] ==  .  && s[mid + 1] ==  . ) d[x]++;   }   void update(int a) {     int x = id[a];     x /= 2;     while (x > 0) {       d[x] = d[x * 2] + d[x * 2 + 1];       if (s[r[x * 2]] ==  .  && s[l[x * 2 + 1]] ==  . ) d[x]++;       x /= 2;     }   }   int main() {     input();     init(1, 1, n);     int a;     char b;     for (int q = 1; q <= m; q++) {       scanf( %d %c , &a, &b);       if ((s[a] ==  .  && b ==  . ) || (s[a] !=  .  && b !=  . )) {         printf( %d n , d[1]);         continue;       }       s[a] = b;       update(a);       printf( %d n , d[1]);     }   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, len;   long long a, b, c, l;   void solve() {     long long tot = ((l + 3) * (l + 2) * (l + 1)) / 6;     long long i;     for (i = 0; i <= l; i++) {       long long x = min(a - b - c + i, l - i);       if (x < 0) continue;       tot -= ((x + 2) * (x + 1)) >> 1;     }     for (i = 0; i <= l; i++) {       long long x = min(b - a - c + i, l - i);       if (x < 0) continue;       tot -= ((x + 2) * (x + 1)) >> 1;     }     for (i = 0; i <= l; i++) {       long long x = min(c - a - b + i, l - i);       if (x < 0) continue;       tot -= ((x + 2) * (x + 1)) >> 1;     }     cout << tot <<   n ;   }   int main() {     long long i, j, k, t;     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     cin >> a >> b >> c >> l;     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000009;   const int MAXN = 100000;   int n, m;   vector<pair<int, int> > graph[MAXN + 3];   bool vis[MAXN + 3];   bool color[MAXN + 3];   vector<int> ans[2], curr, output;   int counter;   void Read() {     scanf( %d %d , &n, &m);     for (int i = 0; i < m; i++) {       int a, b, c;       char col;       scanf( %d %d %c , &a, &b, &col);       if (col ==  B )         c = 1;       else         c = 0;       graph[a].push_back(make_pair(b, c));       graph[b].push_back(make_pair(a, c));     }   }   void Clean() {     for (int i = 1; i <= n; i++) vis[i] = false;     for (int i = 1; i <= n; i++) color[i] = 0;     for (int i = 1; i <= n; i++)       for (int j = 0; j < (int)graph[i].size(); j++)         graph[i][j].second = (graph[i][j].second + 1) % 2;     curr.clear();   }   bool Dfs(int v) {     vis[v] = true;     curr.push_back(v);     if (color[v] == 0) counter++;     for (int i = 0; i < (int)graph[v].size(); i++) {       int u = graph[v][i].first;       int sum = graph[v][i].second;       if (!vis[u]) {         color[u] = (sum - color[v] + 2) % 2;         if (Dfs(u) == false) return false;       } else {         if (color[u] != (sum - color[v] + 2) % 2) return false;       }     }     return true;   }   bool Solve(int ind) {     for (int v = 1; v <= n; v++) {       if (!vis[v]) {         if (Dfs(v) == false) return false;       }       for (int i = 0; i < (int)curr.size(); i++) {         if (color[curr[i]] == 0 && 2 * counter < (int)curr.size())           ans[ind].push_back(curr[i]);         else if (color[curr[i]] == 1 && 2 * counter >= (int)curr.size())           ans[ind].push_back(curr[i]);       }       curr.clear();       counter = 0;     }     return true;   }   int main() {     Read();     bool check0 = Solve(0);     Clean();     bool check1 = Solve(1);     if (!check0 && !check1) {       puts( -1 );       return 0;     }     if (!check1 || (ans[0].size() < ans[1].size() && check0))       output = ans[0];     else       output = ans[1];     printf( %d n , (int)output.size());     for (int i = 0; i < (int)output.size(); i++) {       printf( %d  , output[i]);     }     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   string res;   map<string, int> stv;   map<int, string> vts;   vector<string> a, s({ 1110111 ,  0010010 ,  1011101 ,  1011011 ,  0111010 ,                         1101011 ,  1101111 ,  1010010 ,  1111111 ,  1111011 });   vector<vector<int>> dp;   int cnt(string f, string t) {     int res = 0;     for (int i = 0; i < 7; i++) {       if (f[i] != t[i]) {         ++res;         if (f[i] ==  1 ) return -1;       }     }     return res;   }   int bt(int in, int k) {     if (k < 0) return 0;     if (in >= n) return k == 0;     int& dpv = dp[in][k];     if (dpv == 1) return 0;     for (int i = 9; i >= 0; i--) {       int c = cnt(a[in], vts[i]);       if (c >= 0 && bt(in + 1, k - c)) {         res.push_back(i +  0 );         return 1;       }     }     dpv = 1;     return 0;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int k;     cin >> n >> k;     a.resize(n);     dp.assign(n, vector<int>(k + 1));     for (auto& i : a) cin >> i;     for (int i = 0; i < 10; i++) {       stv[s[i]] = i;       vts[i] = s[i];     }     if (bt(0, k)) {       reverse(res.begin(), res.end());       cout << res;     } else {       cout << -1;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool debug = 0;   int n, m, k;   int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};   string direc =  RDLU ;   long long ln, lk, lm;   void et(bool f = 0) {     puts(f ?  MAGIC  :  NOT MAGIC );     exit(0);   }   int a[2505][2505];   bitset<2505> bs[2505];   void fmain() {     scanf( %d , &n);     for (int(i) = 1; (i) <= (int)(n); (i)++)       for (int(j) = 1; (j) <= (int)(n); (j)++) scanf( %d , &a[i][j]);     for (int(i) = 1; (i) <= (int)(n); (i)++)       if (a[i][i] != 0) et();     for (int(i) = 1; (i) <= (int)(n); (i)++)       for (int j = i + 1; j <= n; j++)         if (a[i][j] != a[j][i]) et();     vector<pair<int, pair<int, int>>> vp;     for (int(i) = 1; (i) <= (int)(n); (i)++)       for (int(j) = 1; (j) <= (int)(n); (j)++) vp.push_back({a[i][j], {i, j}});     int N = vp.size();     sort(vp.begin(), vp.end());     for (int i = 0, j = 0; i < N; i = j) {       for (j = i; j < N && vp[i].first == vp[j].first; j++)         ;       for (int k = i; k < j; k++) {         auto p = vp[k].second;         if ((bs[p.first] & bs[p.second]).any()) et();       }       for (int k = i; k < j; k++) {         auto p = vp[k].second;         bs[p.first][p.second] = 1;       }     }     et(1);   }   int main() {     fmain();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 100, inf = 0x3f3f3f3f, mod = 1e9 + 7, M = 1e6 + 1000;   const long long INF = 0x3f3f3f3f3f3f3f3f;   long long sp(long long a, long long b, long long d) {     if (!b) return 1;     return b % 2 ? sp(a * a, b / 2, d) * a % d : sp(a * a, b / 2, d);   }   long long sp1(long long a, long long b) {     if (!b) return 1;     return b % 2 ? sp1(a * a, b / 2) * a : sp1(a * a, b / 2);   }   long long lowbit(long long x) { return x & (-x); }   long long exgcd(long long a, long long b, long long &x, long long &y) {     if (!b) {       x = 1;       y = 0;       return a;     } else {       long long d = exgcd(b, a % b, y, x);       y -= (a / b) * x;       return d;     }   }   long long t, n;   char str[N];   long long ck(char s) {     long long l = 1, r = n, x = 0;     while (l <= r) {       if (str[l] == str[r]) {         l++;         r--;       } else {         if (str[l] == s) {           l++;           x++;         } else if (str[r] == s) {           r--;           x++;         } else {           return -1;         }       }     }     return x;   }   int main() {     cin >> t;     while (t--) {       scanf( %lld%s , &n, str + 1);       long long ans = -1;       for (int i = 0; i <= 25; i++) {         char s = i +  a ;         long long x = ck(s);         if (x == -1) continue;         if (ans == -1 || ans > x) ans = x;       }       cout << ans << endl;     }   }