#include <bits/stdc++.h> n using namespace std; n char str[100005]; n int main() { n   cin.getline(str, 100005); n   int y = 0; n   int l = strlen(str); n   int has = 0; n   for (int i = 0; i < l; i++) { n     if (y == 1 && str[i] !=    ) { n       cout << str[i]; n       continue; n     } n     if (str[i] ==    ) { n       if (y == 0) { n         y = 1; n         if (has) { n           cout <<  >  << endl; n           has = 0; n         } n         cout <<  < ; n       } else if (y == 1) { n         cout <<  >  << endl; n         y = 0; n       } n       continue; n     } n     if (str[i] ==    ) { n       if (has) { n         cout <<  >  << endl; n         has = 0; n       } n       continue; n     } n     if (has) n       cout << str[i]; n     else { n       has = 1; n       cout <<  <  << str[i]; n     } n   } n   if (str[l - 1] !=     && str[l - 1] !=    ) cout <<  >  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n, k, p, total = 0; n   cin >> n; n   k = (n - 11) / 2; n   for (int i = 1; i <= n; i++) { n     char temp; n     cin >> temp; n     if (temp ==  8 ) { n       total++; n       if (total == k + 1) p = i; n     } n   } n   if (total <= k) n     cout <<  NO ; n   else { n     p -= k; n     if ((p - 1) <= k) n       cout <<  YES ; n     else n       cout <<  NO ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = 1e15; n void Tez() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n } n int main() { n   Tez(); n   long long n, k; n   cin >> n >> k; n   long long cap[k]; n   for (int i = 0; i < k; i++) cin >> cap[i]; n   long long tp = 1, no = 0, maxam = 0; n   for (int i = 0; i < k; i++) { n     long long x = n / cap[i]; n     long long am = x * cap[i]; n     if (am > maxam) { n       no = x; n       maxam = am; n       tp = i + 1; n     } n   } n   cout << tp <<     << no; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int vis[2000007]; n string s; n int main() { n   int n, k, i, j, l, x, len = 0, pos; n   string in; n   cin >> n; n   for (i = 0; i < 2000007; i++) s +=  a ; n   for (i = 0; i < n; i++) { n     cin >> in >> k; n     pos = -(int)in.length(); n     for (j = 1; j <= k; j++) { n       cin >> x; n       len = max(len, x + (int)in.length()); n       for (l = max(0, pos + (int)in.length() - x); l < in.length(); l++) n         s[l + x] = in[l]; n       pos = x; n     } n   } n   for (i = 1; i < len; i++) cout << s[i]; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n const int maxn = 502; n int a[maxn][maxn]; n int izq[maxn][maxn], arr[maxn][maxn]; n void solve() { n   int n, m; n   cin >> n >> m; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       char c; n       cin >> c; n       if (c ==  . ) a[i][j] = 1; n     } n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       izq[i][j] = izq[i][j - 1]; n       if (a[i][j] && a[i][j - 1]) { n         izq[i][j]++; n       } n     } n   } n   for (int j = 1; j <= m; j++) { n     for (int i = 1; i <= n; i++) { n       arr[i][j] = arr[i - 1][j]; n       if (a[i][j] && a[i - 1][j]) { n         arr[i][j]++; n       } n     } n   } n   int q; n   cin >> q; n   while (q--) { n     int r1, c1, r2, c2; n     cin >> r1 >> c1 >> r2 >> c2; n     long long int ans = 0; n     for (int f = r1; f <= r2; f++) { n       long long int res = izq[f][c2] - izq[f][c1 - 1]; n       if (a[f][c1] && a[f][c1 - 1]) res--; n       ans += res; n     } n     for (int c = c1; c <= c2; c++) { n       long long int res = arr[r2][c] - arr[r1 - 1][c]; n       if (a[r1][c] && a[r1 - 1][c]) res--; n       ans += res; n     } n     cout << ans <<   n ; n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[5][5]; n pair<int, int> cost[5]; n int n; n int main() { n   cin >> n; n   for (int i = 1; i <= 4; i++) n     for (int j = 1; j <= 4; j++) cin >> a[i][j]; n   for (int i = 1; i <= 4; i++) { n     cost[i].first = n         min(a[i][1] + a[i][3], n             min(a[i][1] + a[i][4], min(a[i][2] + a[i][3], a[i][2] + a[i][4]))); n     cost[i].second = i; n   } n   sort(cost + 1, cost + 5); n   if (cost[1].first > n) n     cout << -1; n   else { n     cout << cost[1].second <<    ; n     int u = cost[1].second; n     if (cost[1].first == a[u][1] + a[u][3]) n       cout << a[u][1] <<     << n - a[u][1]; n     else if (cost[1].first == a[u][1] + a[u][4]) n       cout << a[u][1] <<     << n - a[u][1]; n     else if (cost[1].first == a[u][2] + a[u][3]) n       cout << a[u][2] <<     << n - a[u][2]; n     else n       cout << a[u][2] <<     << n - a[u][2]; n   } n } n


#include <bits/stdc++.h> n const int dx[] = {1, -1, 0, 0}; n const int dy[] = {0, 0, -1, 1}; n using namespace std; n long long tests; n long long n, m, b, MOD, dp[5256][5256], a[5256], ans; n void solve() { n   scanf( %I64d%I64d%I64d%I64d , &n, &m, &b, &MOD); n   for (int i = 1; i <= n; i += 1) { n     scanf( %I64d , &a[i]); n   } n   dp[0][0] = 1; n   for (int i = 1; i <= n; i += 1) n     for (int j = 0; j <= m; j += 1) n       for (int k = 0; k <= b; k += 1) n         if (k + a[i] <= b) { n           dp[j + 1][k + a[i]] += dp[j][k]; n           dp[j + 1][k + a[i]] %= MOD; n         } n   for (int i = 0; i <= b; i += 1) { n     ans += dp[m][i]; n     ans %= MOD; n   } n   printf( %I64d , ans); n } n int main() { solve(); } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); } n long long min(long long a, long long b) { return a < b ? a : b; } n long long max(long long a, long long b) { return a > b ? a : b; } n long long max3(long long a, long long b, long long c) { n   return max(max(a, b), c); n } n long long max4(long long a, long long b, long long c, long long d) { n   return max(max(a, b), max(c, d)); n } n long long min3(long long a, long long b, long long c) { n   return min(min(a, b), c); n } n long long min4(long long a, long long b, long long c, long long d) { n   return min(min(a, b), min(c, d)); n } n long long po(long long x, long long n, long long mod = 1000000007) { n   if (n == 0) { n     return 1; n   } n   long long m = po(x, n / 2, mod); n   m *= m; n   m %= mod; n   if (n % 2) { n     m *= x; n     m %= mod; n   } n   return m; n } n long long n, k; n vector<string> v(2005); n vector<string> num{ 1110111 ,  0010010 ,  1011101 ,  1011011 ,  0111010 , n                     1101011 ,  1101111 ,  1010010 ,  1111111 ,  1111011 }; n long long check(string a, string b) { n   long long count = 0; n   for (long long i = 0; i < 7; i++) { n     if (a[i] ==  1  && b[i] ==  0 ) { n       return -1; n     } else if (a[i] ==  0  && b[i] ==  1 ) { n       count++; n     } n   } n   return count; n } n bool comp(char a, char b) { n   if (b ==  - ) { n     return 1; n   } else if (a ==  - ) { n     return 0; n   } n   return a >= b; n } n vector<long long> ans; n long long dp[2005][2005]; n bool stored[2005][2005]; n long long solve(long long rem, long long index) { n   if (rem < 0) { n     return -1; n   } n   if (stored[rem][index]) { n     return dp[rem][index]; n   } n   if (index == n - 1) { n     for (long long j = 9; j >= 0; j--) { n       if (check(v[index], num[j]) == rem) { n         stored[rem][index] = 1; n         ans.push_back(j); n         return dp[rem][index] = 1; n       } n     } n     stored[rem][index] = 1; n     return dp[rem][index] = -1; n   } n   stored[rem][index] = 1; n   for (long long j = 9; j >= 0; j--) { n     if (check(v[index], num[j]) == -1) { n       continue; n     } n     if (solve(rem - check(v[index], num[j]), index + 1) != -1) { n       ans.push_back(j); n       return dp[rem][index] = 1; n     } n   } n   return dp[rem][index] = -1; n } n int32_t main() { n   cin.tie(0); n   cout.tie(0); n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   clock_t startTime = clock(); n   cout << fixed << setprecision(12); n   cin >> n >> k; n   for (long long i = 0; i < n; i++) cin >> v[i]; n   if (solve(k, 0) == -1) { n     cout << -1; n   } else { n     reverse((ans).begin(), (ans).end()); n     for (long long i = 0; i < n; i++) { n       cout << ans[i]; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n inline char gc() { n   static char buf[100000], *p1 = buf, *p2 = buf; n   return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) n              ? EOF n              : *p1++; n } n inline long long read() { n   long long x = 0; n   char ch = getchar(); n   bool positive = 1; n   for (; !isdigit(ch); ch = getchar()) n     if (ch ==  - ) positive = 0; n   for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ; n   return positive ? x : -x; n } n inline void write(long long a) { n   if (a < 0) { n     a = -a; n     putchar( - ); n   } n   if (a >= 10) write(a / 10); n   putchar( 0  + a % 10); n } n inline void writeln(long long a) { n   write(a); n   puts(  ); n } n inline void wri(long long a) { n   write(a); n   putchar(   ); n } n const int N = 100005, M = 1 << 18 | 3; n const long long inf = 1e18; n int n, ans, w[N], g[N], h[N]; n long long lim, pre[N], suf[N], max_p[M], lazy[M], max_suf[M], sp[M]; n vector<int> v[N]; n stack<int> q; n inline void cao(int nod, long long de) { n   lazy[nod] += de; n   max_suf[nod] += de; n   sp[nod] += de; n } n inline void pushdown(int nod) { n   if (lazy[nod]) { n     cao(nod << 1, lazy[nod]); n     cao(nod << 1 | 1, lazy[nod]); n     lazy[nod] = 0; n   } n } n long long calc(int l, int r, long long dq, int nod) { n   if (l == r) return dq - max_p[nod]; n   pushdown(nod); n   int mid = (l + r) >> 1; n   return dq > max_suf[nod << 1] n              ? min(dq - max_p[nod << 1], calc(mid + 1, r, dq, nod << 1 | 1)) n              : min(sp[nod], calc(l, mid, dq, nod << 1)); n } n void build(int l, int r, int nod) { n   if (l == r) { n     max_suf[nod] = max_p[nod] = suf[l]; n     return; n   } n   int mid = (l + r) >> 1; n   build(l, mid, nod << 1); n   build(mid + 1, r, nod << 1 | 1); n   max_p[nod] = max(max_p[nod << 1], max_p[nod << 1 | 1]); n   max_suf[nod] = max(max_suf[nod << 1], max_suf[nod << 1 | 1]), n   sp[nod] = calc(mid + 1, r, max_suf[nod << 1], nod << 1 | 1); n } n void insert(int l, int r, int i, int j, long long de, int nod) { n   if (i > j) return; n   if (l == i && r == j) { n     cao(nod, de); n     return; n   } n   pushdown(nod); n   int mid = (l + r) >> 1; n   if (j <= mid) n     insert(l, mid, i, j, de, nod << 1); n   else if (i > mid) n     insert(mid + 1, r, i, j, de, nod << 1 | 1); n   else { n     insert(l, mid, i, mid, de, nod << 1); n     insert(mid + 1, r, mid + 1, j, de, nod << 1 | 1); n   } n   max_suf[nod] = max(max_suf[nod << 1], max_suf[nod << 1 | 1]), n   sp[nod] = calc(mid + 1, r, max_suf[nod << 1], nod << 1 | 1); n } n int solve(int l, int r, long long dq, int nod) { n   if (l == r) return dq - max_p[nod] > lim ? 0 : l; n   pushdown(nod); n   int mid = (l + r) >> 1; n   if (dq - max_p[nod << 1 | 1] <= lim) n     return solve(mid + 1, r, dq, nod << 1 | 1); n   else n     return solve(l, mid, dq, nod << 1); n } n int ask(int l, int r, long long dq, int nod) { n   if (l == r) return dq - max_p[nod] > lim ? 0 : l; n   pushdown(nod); n   int mid = (l + r) >> 1; n   if (sp[nod] > lim && dq <= max_suf[nod << 1]) n     return ask(l, mid, dq, nod << 1); n   int ans = ask(mid + 1, r, max(dq, max_suf[nod << 1]), nod << 1 | 1); n   return ans ? ans : solve(l, mid, dq, nod << 1); n } n void solve(int x) { n   h[++*h] = x; n   int l = 0, r = *h; n   while (l < r) { n     int mid = (l + r + 1) >> 1; n     if (pre[x] - pre[h[mid]] <= lim) n       r = mid - 1; n     else n       l = mid; n   } n   insert(1, n, 1, x - 1, -inf, 1); n   if (l) insert(1, n, h[l], n, inf, 1); n   ans = max(ans, ask(1, n, -inf, 1) - x + 1); n   if (l) insert(1, n, h[l], n, -inf, 1); n   insert(1, n, 1, x - 1, inf, 1); n   for (auto i : v[x]) { n     insert(1, n, x - 1, n, pre[i] - pre[x], 1); n     solve(i); n     insert(1, n, x - 1, n, pre[x] - pre[i], 1); n   } n   (*h)--; n } n int main() { n   n = read(); n   lim = read(); n   for (int i = 1; i < n; i++) w[i] = read(); n   for (int i = 1; i <= n; i++) g[i] = read(); n   for (int i = 1; i < n; i++) { n     pre[i + 1] = pre[i] - w[i] + g[i]; n     suf[i + 1] = suf[i] - w[i] + g[i + 1]; n   } n   build(1, n, 1); n   for (int i = 1; i <= n; i++) { n     while (q.size() && pre[i] < pre[q.top()]) { n       v[i].push_back(q.top()); n       q.pop(); n     } n     q.push(i); n   } n   while (q.size()) { n     solve(q.top()); n     q.pop(); n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n string s; n char a; n int b, c, d, i, k, n; n int main() { n   cin >> s; n   k = s.size(); n   if (k < 2) d = 1; n   while (n < 100 && d == 0) { n     while (i < k - 2 && d == 0) { n       if (s[i] > s[i + 2]) { n         a = s[i + 2]; n         s[i + 2] = s[i]; n         s[i] = a; n       } n       i += 2; n     } n     n++; n     i = 0; n   } n   cout << s; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, k; n struct Edge { n   int u; n   int v; n } e[1000000]; n int dp[3000][3000]; n bool Judge1(int x, int y) { n   for (int i = 0; i < n; i++) n     if (!(x & (1 << i)) && (y & (1 << i))) return false; n   return true; n } n bool Judge2(int u, int v, int x, int y) { n   if ((1 << (u - 1)) & x && !((1 << (v - 1)) & x)) return true; n   return false; n } n int Count(int x) { n   int ret = 0; n   for (int i = 0; i < n; i++) n     if ((1 << i) & x) ret++; n   return ret; n } n void PUT(int x) { n   for (int i = 0; i < n; i++) n     if (x & (1 << i)) n       cout << 1; n     else n       cout << 0; n } n int ans; n int main() { n   cin >> n >> m >> k; n   for (int i = 1; i <= m; i++) { n     cin >> e[i].u >> e[i].v; n     int temp = 0; n     temp |= (1 << (e[i].u - 1)); n     temp |= (1 << (e[i].v - 1)); n     dp[temp][temp] = 1; n   } n   for (int i = 0; i <= (1 << n) - 1; i++) n     for (int j = 0; j <= (1 << n) - 1; j++) n       if (Judge1(i, j)) n         for (int g = 1; g <= m; g++) { n           if (Judge2(e[g].u, e[g].v, i, j)) { n             int temp = j; n             temp |= (1 << (e[g].v - 1)); n             if (temp & (1 << (e[g].u - 1))) temp ^= (1 << (e[g].u - 1)); n             bool pd = false; n             for (int q = e[g].v + 1; q <= n; q++) n               if ((1 << (q - 1)) & temp) { n                 pd = true; n                 break; n               } n             int st = i; n             st |= 1 << (e[g].v - 1); n             if (!pd) dp[st][temp] += dp[i][j]; n           } else if (Judge2(e[g].v, e[g].u, i, j)) { n             swap(e[g].v, e[g].u); n             int temp = j; n             temp |= (1 << (e[g].v - 1)); n             if (temp & (1 << (e[g].u - 1))) temp ^= (1 << (e[g].u - 1)); n             bool pd = false; n             for (int q = e[g].v + 1; q <= n; q++) n               if ((1 << (q - 1)) & temp) { n                 pd = true; n                 break; n               } n             int st = i; n             st |= 1 << (e[g].v - 1); n             if (!pd) dp[st][temp] += dp[i][j]; n           } n         } n   for (int i = 0; i <= (1 << n) - 1; i++) n     for (int j = 0; j <= (1 << n) - 1; j++) { n       if (Count(j) == k && (i == ((1 << n) - 1))) ans += dp[i][j]; n     } n   cout << ans << endl; n   return 0; n } n


#include<bits/stdc++.h> n using namespace std; n int main() n { n     int t; n     cin>>t; n     while(t--) n     { n         int a,b,c; n         cin>>a>>b>>c; n         int sum=a+b+c; n         if(sum<7) n             cout<< No <<endl; n         else n         { n             if(sum%9==0) n             { n                 sum=sum/9; n                 if(a>=sum && b>=sum && c>=sum) n                     cout<< Yes <<endl; n                 else n                     cout<< No <<endl; n             } n             else n                 cout<< No <<endl; n         } n     } n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int x, d; n   cin >> x >> d; n   long long start = 1; n   vector<long long> arr; n   while (x > 0) { n     int toPrint = 1; n     while ((1LL << toPrint) - 1 <= x) toPrint++; n     toPrint--; n     for (long long i = start; i < start + toPrint; i++) arr.push_back(start); n     start += toPrint + d + 1; n     x -= ((1LL << toPrint) - 1); n   } n   if (arr.size() > 1e4 || start >= 1e18) { n     cout <<  -1 ; n     return 0; n   } n   cout << arr.size() << endl; n   for (int i = 0; i < arr.size(); i++) cout << arr[i] <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5; n int T, n, m; n int t1, t2; n bool w; n map<pair<int, long long>, int> mex; n int solve(int rem = 60, long long msk = (1 << 60) - 1) { n   if (mex.count({rem, msk})) { n     return mex[{rem, msk}]; n   } n   mex[{rem, msk}] = 0; n   int x = 0; n   set<int> s; n   for (int i = 1; i <= rem; ++i) { n     if ((msk >> i) & 1) n       s.insert( n           solve(rem - i, ((1ll << (rem - i + 1)) - 1) & (msk & ~(1ll << i)))); n   } n   while (s.count(x)) ++x; n   return mex[{rem, msk}] = x; n } n int main() { n   scanf( %d , &n); n   scanf( %d , &t1); n   T = solve(t1, (1ll << t1 + 1) - 1); n   for (int i = 1; i < n; ++i) { n     scanf( %d , &t1); n     T ^= solve(t1, (1ll << t1 + 1) - 1); n   } n   if (T) { n     printf( NO ); n   } else { n     printf( YES ); n   } n   printf(  n ); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 5, M = 2e3 + 5; n const long long INF = 1e18 + 5; n inline long long read() { n   long long sum = 0, fh = 1; n   char c = getchar(); n   while (c <  0  || c >  9 ) { n     if (c ==  - ) fh = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     sum = sum * 10 + c -  0 ; n     c = getchar(); n   } n   return sum * fh; n } n inline int read2() { n   char c = getchar(); n   while (c <  0  || c >  9 ) c = getchar(); n   return c -  0 ; n } n inline int read3() { n   char c = getchar(); n   while (c <  a  || c >  z ) { n     c = getchar(); n   } n   return c -  a ; n } n inline void write(long long x) { n   if (x < 0) putchar( - ), x = -x; n   if (x > 9) write(x / 10); n   putchar(x % 10 +  0 ); n } n inline int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); } n inline long long ab(long long x) { return x < 0 ? -x : x; } n inline long long fpow(long long qwe, long long asd, long long zxc) { n   if (asd < 0) return 0; n   long long a = qwe, b = 1, c = asd; n   while (c) { n     if (c & 1) b = b * a % zxc; n     a = a * a % zxc; n     c >>= 1; n   } n   return b; n } n struct miaow { n   int f, t, l; n   long long c; n   miaow(int f = 0, int t = 0, long long c = 0, int l = 0) n       : f(f), t(t), c(c), l(l) {} n } imap[N * 2 + 5]; n int str[N * 2 + 5] = {0}, cou = 2; n inline void jb(int f, int t, long long c = 0) { n   imap[cou] = miaow(f, t, c, str[f]); n   str[f] = cou++; n   imap[cou] = miaow(t, f, c, str[t]); n   str[t] = cou++; n } n struct meow { n   long long t, x, y; n   meow(long long t = 0, long long x = 0, long long y = 0) : t(t), x(x), y(y) {} n   inline bool operator<(const meow& qwe) const { n     return t == qwe.t ? x < qwe.x : t > qwe.t; n   } n }; n int sy[N][2]; n long long dp[N][2], zz[N], p = 1e9 + 7, ans = 0; n priority_queue<meow> qwe; n int main() { n   int n = read(), m = read(); n   long long q = read(), ny = fpow(2, p - 2, p); n   meow zxczxc = (0, 0, 0); n   for (int i = 1; i <= m; ++i) { n     int x = read(), y = read(), z = read(); n     jb(x, y, z); n     zxczxc = min(zxczxc, meow(z, x, y)); n   } n   sy[1][0] = 1; n   int cs = 1; n   for (int i = 1; i <= min(q, m * 2 + (long long)1); ++i) { n     for (int j = 1; j <= n; ++j) dp[i][cs] = sy[i][cs] = 0, zz[i] = 0; n     long long sum = 0; n     for (int j = 2; j < cou; ++j) { n       int f = imap[j].f, t = imap[j].t; n       long long c = imap[j].c; n       if (sy[f][cs ^ 1]) { n         sy[t][cs] = 1; n         if (dp[t][cs] < dp[f][cs ^ 1] + c) { n           dp[t][cs] = dp[f][cs ^ 1] + c; n           zz[t] = c; n         } else if (dp[t][cs] == dp[f][cs ^ 1] + c && c > zz[t]) n           zz[t] = c; n         sum = max(sum, dp[t][cs]); n       } n     } n     cs ^= 1; n     if (i != m * 2 + 1ll || i == q) ans = (ans + sum) % p; n   } n   long long t = m * 2 + 1, x = 0, y = 0; n   vector<meow> zzz; n   for (int i = 1; i <= n; ++i) { n     long long y1 = zz[i], x1 = dp[i][1]; n     if (x1 > x) { n       x = x1, y = y1; n     } else if (x1 == x && y1 > y) n       y = y1; n     for (int j = i + 1; j <= n; ++j) { n       long long y2 = zz[j], x2 = dp[j][1]; n       long long x3 = x1, y3 = y1; n       if (y2 < y3) { n         if (x2 <= x3) continue; n         swap(y3, y2), swap(x3, x2); n       } else if (y2 > y3) { n         if (x2 >= x3) continue; n       } else n         continue; n       long long tt = (x3 - x2) / (y2 - y3); n       qwe.push(meow(t + tt + 1, x2 + (tt + 1) * y2, y2)); n       if (x2 + (tt + 1) * y2 < 0) exit(1); n     } n   } n   long long ttt = t, aaa = ans, xxx = x, yyy = y; n   if (t > q) { n     cout << ans << endl; n     return 0; n   } n   qwe.push(meow(q, 0, 0)); n   long long tbj = 0; n   while (t < q) { n     meow asd = qwe.top(); n     qwe.pop(); n     long long t2 = asd.t, x2 = asd.x, y2 = asd.y; n     if (t2 < t) continue; n     if (t2 != t) n       ans = (ans + (x + x + (t2 - t - 1) * y) % p * (t2 - t) % p * ny % p) % p; n     x = x + y * (t2 - t); n     if (x < x2) { n       if (!tbj) tbj = t2; n       x = x2, y = y2; n     } else if (x == x2 && y < y2) { n       if (!tbj) tbj = t2; n       y = y2; n     } n     t = t2; n   } n   ans = (ans + x) % p; n   if (ans == 30604365) { n     for (int i = 0; i < zzz.size(); ++i) n       cout << zzz[i].t <<     << zzz[i].x <<     << zzz[i].y << endl; n   } n   if (ans == 30604365) cout << x <<     << y <<     << t <<     << tbj << endl; n   if (ans == 30604365) n     cout << xxx <<     << yyy <<     << ttt <<     << aaa << endl; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void fre() { n   freopen( c://test//input.in ,  r , stdin); n   freopen( c://test//output.out ,  w , stdout); n } n template <class T1, class T2> n inline void gmax(T1 &a, T2 b) { n   if (b > a) a = b; n } n template <class T1, class T2> n inline void gmin(T1 &a, T2 b) { n   if (b < a) a = b; n } n const int N = 0, M = 0, Z = 1e9 + 7, ms63 = 0x3f3f3f3f; n int casenum, casei; n long long n; n void solve1e6(long long n) { n   int step = 0; n   while (n) { n     int x = n; n     int mx = 0; n     while (x) gmax(mx, x % 10), x /= 10; n     n -= mx; n     ++step; n   } n   printf( %d n , step); n } n struct A { n   long long x; n   int y; n   void add(const A &b) { n     x += b.x; n     y = b.y; n   } n }; n int a[20]; n A f[20][10][10]; n A dp(int p, int mx, int tim, int tp) { n   if (p == -1) { n     if (mx == 0) return {0, 0}; n     if (tim) return {0, tim - 1}; n     return {1, mx - 1}; n   } n   if (!tp && ~f[p][mx][tim].x) return f[p][mx][tim]; n   A ret = {0, tim}; n   int top = tp ? a[p] : 9; n   for (int i = top; i >= 0; --i) { n     ret.add(dp(p - 1, max(mx, i), ret.y, tp && i == top)); n   } n   if (!tp) f[p][mx][tim] = ret; n   return ret; n } n void solve1e18(long long n) { n   int p = -1; n   while (n) a[++p] = n % 10, n /= 10; n   if (p == -1) a[++p] = 0; n   for (int i = 0; i <= p; ++i) { n     for (int j = 0; j < 10; ++j) { n       for (int k = 0; k < 10; ++k) f[i][j][k].x = -1; n     } n   } n   printf( %lld n , dp(p, 0, 0, 1).x); n } n int main() { n   while (~scanf( %lld , &n)) { n     solve1e18(n); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct xy { n   int x, y; n }; n int a[1212121], par[1212121], depth[1212121]; n vector<int> C[1212121]; n void dfs(int w, int dep) { n   depth[w] = dep; n   for (int nxt : C[w]) dfs(nxt, dep + 1); n } n int Hn = 0, myH[1212121], sz[1212121], root[1212121], ppar[1212121]; n int find(int x) { n   if (ppar[x] == x) return x; n   return ppar[x] = find(ppar[x]); n } n multiset<int> S[1212121], ansS; n void push(int x) { n   sz[x] = 1; n   int mx = 0, mxw; n   for (int child : C[x]) { n     sz[x] += sz[child]; n     if (mx < sz[child] && S[myH[child]].size() > 0) mx = sz[child], mxw = child; n   } n   if (mx == 0) { n     int hIdx = ++Hn; n     myH[x] = hIdx; n     root[hIdx] = x; n     S[hIdx].insert(depth[x]); n     ppar[hIdx] = hIdx; n     ansS.insert(0); n   } else { n     int hIdx = myH[x] = myH[mxw]; n     root[hIdx] = x; n     int dep = (*S[hIdx].rbegin()) - depth[mxw]; n     ansS.erase(ansS.find(dep)); n     S[hIdx].insert(depth[x]); n     for (int child : C[x]) n       if (child != mxw) { n         if (!S[myH[child]].empty()) { n           for (auto &v : S[myH[child]]) S[hIdx].insert(v); n           ppar[myH[child]] = hIdx; n           int dep = (*S[myH[child]].rbegin()) - depth[child]; n           ansS.erase(ansS.find(dep)); n         } n         S[myH[child]].clear(); n       } n     dep = (*S[hIdx].rbegin()) - depth[x]; n     ansS.insert(dep); n   } n } n void pop(int x) { n   int hIdx = find(myH[x]); n   int dep = (*S[hIdx].rbegin()) - depth[root[hIdx]]; n   ansS.erase(ansS.find(dep)); n   S[hIdx].erase(S[hIdx].find(depth[x])); n   if (S[hIdx].empty()) return; n   dep = (*S[hIdx].rbegin()) - depth[root[hIdx]]; n   ansS.insert(dep); n } n int main() { n   int n, k, i, j; n   scanf( %d%d , &n, &k); n   for (i = 1; i <= n; i++) scanf( %d , &a[i]); n   vector<xy> ST; n   ST.push_back({n + 1, n + 1}); n   for (i = n; i >= 1; i--) { n     while (ST.back().x <= a[i]) ST.pop_back(); n     par[i] = ST.back().y; n     C[par[i]].push_back(i); n     ST.push_back({a[i], i}); n   } n   dfs(n + 1, 0); n   for (i = 1; i <= n; i++) { n     push(i); n     if (k <= i) { n       printf( %d  , *ansS.rbegin() + 1); n       if (i != n) pop(i - k + 1); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int x, y; n   scanf( %d %d , &x, &y); n   printf( %d , (x * y - 1) / (y - 1)); n } n


#include <bits/stdc++.h> n using namespace std; n int a[210][210], b[210][210]; n int n, m; n int main() { n   while (cin >> n >> m) { n     int ra = 1, rb = 1, ca = 1, cb = 1; n     for (int i = 1; i <= m; i++) n       if (i % 2) { n         a[ra++][ca] = i; n         if (ra > n) ra = 1, ca++; n       } else { n         b[rb++][cb] = i; n         if (rb > n) rb = 1, cb++; n       } n     for (int i = 1; i <= n; i++) { n       for (int j = ca; j >= 1; j--) { n         if (!a[i][j]) continue; n         cout << a[i][j] <<    ; n       } n       for (int j = cb; j >= 1; j--) { n         if (!b[i][j]) continue; n         cout << b[i][j] <<    ; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, bear, ans, a, aux, votes[128]; n priority_queue<int> q; n int Solution() { n   int ans = 0; n   while (bear <= q.top()) { n     aux = q.top(); n     if (bear <= aux) { n       bear++; n       aux--; n       q.pop(); n       q.push(aux); n       ans++; n     } n   } n   return ans; n } n int main() { n   scanf( %d , &n); n   scanf( %d , &bear); n   for (int i = 0; i < n - 1; ++i) { n     scanf( %d , &a); n     q.push(a); n   } n   ans = Solution(); n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long fpm(long long b, long long e, long long m) { n   long long t = 1; n   for (; e; e >>= 1, b = b * b % m) e & 1 ? t = t * b % m : 0; n   return t; n } n template <class T> n inline bool chkmin(T &a, T b) { n   return a > b ? a = b, true : false; n } n template <class T> n inline bool chkmax(T &a, T b) { n   return a < b ? a = b, true : false; n } n template <class T> n inline T sqr(T x) { n   return x * x; n } n template <class edge> n struct Graph { n   vector<vector<edge> > adj; n   Graph(int n) { n     adj.clear(); n     adj.resize(n + 5); n   } n   void adde(int s, edge e) { adj[s].push_back(e); } n   typename vector<edge>::iterator operator[](int t) { return adj[t].begin(); } n }; n const int maxn = 1100; n typedef int arr32[maxn]; n arr32 col, row, vrow, vcol; n int noans, mod; n int main() { n   ios_base::sync_with_stdio(false); n   int n, m, K; n   cin >> n >> m >> K; n   for (int i = 1; i <= n; ++i) row[i] = m, vrow[i] = 1; n   for (int j = 1; j <= m; ++j) col[j] = n, vcol[j] = 1; n   for (int i = 1, a, b, c; i <= K; ++i) n     cin >> a >> b >> c, --row[a], --col[b], vrow[a] *= c, vcol[b] *= c; n   int unx = 0; n   if (K < n) { n     for (int i = 1; i <= n; ++i) n       if (row[i]) n         unx += row[i] - 1; n       else if (vrow[i] != -1) n         noans = 1; n     unx -= m - 1; n   } else { n     for (int j = 1; j <= m; ++j) n       if (col[j]) n         unx += col[j] - 1; n       else if (vcol[j] != -1) n         noans = 1; n     unx -= n - 1; n   } n   cin >> mod; n   if (noans || (n & 1) != (m & 1)) n     cout << 0 << endl; n   else n     cout << fpm(2, unx, mod) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 1e5 + 3; n map<int, vector<int>> sign; n int a[MAX]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   multiset<int> st; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     st.insert(a[i]); n   } n   vector<pair<int, int>> v; n   for (int i = 0; i < n - 1; i++) { n     int x = *st.rbegin(); n     st.erase(st.find(x)); n     int y = *st.rbegin(); n     st.erase(st.find(y)); n     st.insert(x - y); n     v.push_back({x, y}); n   } n   int S = *st.rbegin(); n   sign[S].push_back(1); n   for (int i = n - 2; i >= 0; i--) { n     int x = v[i].first, y = v[i].second; n     int p = sign[x - y].back(); n     sign[x - y].pop_back(); n     sign[x].push_back(p), sign[y].push_back(p ^ 1); n   } n   for (int i = 1; i <= n; i++) { n     if (sign[a[i]].back()) n       cout <<  + ; n     else n       cout <<  - ; n     sign[a[i]].pop_back(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int num[105]; n double cal(int w, int e, int s) { n   if (e < s) return 1.0; n   double res = 1, dw = (double)w, de = (double)e; n   for (int i = 0; i < s; i++) { n     res = res * de / dw; n     dw--; n     de--; n   } n   return 1.0 - res; n } n int main() { n   int n, m, h; n   int s; n   while (~scanf( %d%d%d , &n, &m, &h)) { n     s = 0; n     for (int i = 1; i <= m; i++) { n       scanf( %d , &num[i]); n       s += num[i]; n     } n     if (s < n) n       printf( -1.0 n ); n     else { n       printf( %.7lf n , cal(s - 1, s - num[h], n - 1)); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n const ll M = 1e4 + 10; n const ll G = 1e3 + 10; n ll n, m, g, r; n vector<ll> d; n ll ansDep = -1; n ll ansT = -1; n bool seen[M][G]; n ll ans = 1e17; n void bfs() { n   deque<tuple<ll, ll, ll> > q; n   q.emplace_front(0, 0, 0); n   while (!q.empty()) { n     auto at = q.front(); n     q.pop_front(); n     ll v = get<0>(at), tempo = get<1>(at), dep = get<2>(at); n     if (v == m - 1) { n       ans = min(ans, (r + g) * dep + tempo); n       continue; n     } n     seen[v][tempo] = true; n     ll distance = d[v + 1] - d[v]; n     ll nt = distance + tempo; n     if (nt <= g and !seen[v + 1][nt % g]) { n       seen[v + 1][nt % g] = true; n       if (nt == g) { n         if (v + 1 != m - 1) n           q.emplace_back(v + 1, 0, dep + 1); n         else n           q.emplace_back(v + 1, g, dep); n       } else n         q.emplace_front(v + 1, nt, dep); n     } n     if (v > 0) { n       distance = d[v] - d[v - 1]; n       nt = distance + tempo; n       if (nt <= g and !seen[v - 1][nt % g]) { n         seen[v - 1][nt % g] = true; n         if (nt == g) n           q.emplace_back(v - 1, 0, dep + 1); n         else n           q.emplace_front(v - 1, nt, dep); n       } n     } n   } n } n int main() { n   ios::sync_with_stdio(false); n   memset(seen, false, sizeof seen); n   cin >> n >> m; n   d.resize(m); n   for (ll &i : d) cin >> i; n   sort(d.begin(), d.end()); n   cin >> g >> r; n   bfs(); n   if (ans == 1e17) n     cout <<  -1 n ; n   else n     cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long res, cur, n, dp[1000006]; n struct info { n   long long x, y; n   long long a; n   bool operator<(const info &b) const { return x < b.x; } n }; n struct P { n   long long x, y; n   P operator+(const P &a) const { return (P){x + a.x, y + a.y}; } n   P operator-(const P &a) const { return (P){x - a.x, y - a.y}; } n   long long operator*(const P &a) const { n     double u, v; n     if (x == 0 && a.x == 0) return 0; n     if (x == 0) { n       if (y == 0) return 0; n       return 2 * ((y > 0 && a.x < 0) || (y < 0 && a.x > 0)) - 1; n     } n     if (a.x == 0) { n       if (a.y == 0) return 0; n       return 2 * ((a.y > 0 && x > 0) || (a.y < 0 && x < 0)) - 1; n     } n     u = y; n     u /= x; n     v = a.y; n     v /= a.x; n     if (u == v) return 0; n     return (2 * (v > u) - 1) * n            (2 * ((x > 0 && a.x > 0) || (x < 0 && a.x < 0)) - 1); n   } n   long long V(long long pos, int k) { return (pos - x) * k + y; } n }; n vector<info> var; n vector<P> vex; n int main() { n   scanf( %d , &n); n   var.resize(n + 1); n   var[0] = (info){0, INT_MAX, 0}; n   for (int i = 1; i <= n; i++) { n     scanf( %d %d %lld , &var[i].x, &var[i].y, &var[i].a); n   } n   sort(var.begin(), var.end()); n   vex.push_back((P){0, 0}); n   for (int i = 1; i <= n; i++) { n     while (cur < vex.size() - 1 && n            vex[cur].V(var[i].x, var[i].y) < vex[cur + 1].V(var[i].x, var[i].y)) n       cur++; n     dp[i] = vex[cur].V(var[i].x, var[i].y) - var[i].a; n     P lar = (P){var[i].x, dp[i]}; n     while (vex.size() > 1 && n            (lar - vex[vex.size() - 2]) * n                    (vex[vex.size() - 1] - vex[vex.size() - 2]) <= n                0) { n       if (cur == vex.size() - 1) cur--; n       vex.pop_back(); n     } n     vex.push_back(lar); n   } n   for (int i = 0; i <= n; i++) res = max(res, dp[i]); n   printf( %lld , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n bool chkmin(T &x, T y) { n   return x > y ? x = y, 1 : 0; n } n template <typename T> n bool chkmax(T &x, T y) { n   return x < y ? x = y, 1 : 0; n } n int readint() { n   int x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n const int cys = 1000000009; n int n, m, tot; n long long d[105][105], siz[105], tmp[105], ans[105], v[20005], nxt[20005], n     h[105], fac[105], inv[105], rt[105], f[105][105], rs[105]; n bool vis[105]; n long long mod(long long x) { return x >= cys ? x - cys : x; } n long long qpow(long long x, long long p) { n   long long ret = 1; n   for (; p; p >>= 1, x = x * x % cys) n     if (p & 1) ret = ret * x % cys; n   return ret; n } n void addedge(int x, int y) { n   v[++tot] = y; n   nxt[tot] = h[x]; n   h[x] = tot; n   v[++tot] = x; n   nxt[tot] = h[y]; n   h[y] = tot; n } n void dfs(int u, int r) { n   memset(d[u], 0, sizeof(d[u])); n   d[u][0] = 1; n   siz[u] = 1; n   if (r) rt[u] = r; n   int cnt = 0; n   for (int p = h[u]; p; p = nxt[p]) { n     if (vis[v[p]]) { n       cnt++; n       continue; n     } n     vis[v[p]] = 1; n     dfs(v[p], r); n     for (int i = 0; i <= siz[u] + siz[v[p]]; i++) tmp[i] = 0; n     for (int i = 0; i < siz[u]; i++) n       for (int j = 0; j <= siz[v[p]]; j++) n         tmp[i + j] = mod(tmp[i + j] + d[u][i] * d[v[p]][j] % cys * fac[i + j] % n                                           cys * inv[i] % cys * inv[j] % cys); n     siz[u] += siz[v[p]]; n     for (int i = 0; i <= siz[u]; i++) d[u][i] = tmp[i]; n   } n   if (cnt <= 1) d[u][siz[u]] = d[u][siz[u] - 1]; n   if (u == r) rs[u] = siz[u]; n } n int main() { n   n = readint(); n   m = readint(); n   fac[0] = inv[0] = 1; n   for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % cys; n   inv[n] = qpow(fac[n], cys - 2); n   for (int i = n - 1; i >= 1; i--) inv[i] = inv[i + 1] * (i + 1) % cys; n   for (int i = 1; i <= m; i++) addedge(readint(), readint()); n   ans[0] = 1; n   for (int i = 1; i <= n; i++) { n     if (!vis[i]) { n       vis[i] = true; n       dfs(i, i); n       for (int j = 0; j <= n; j++) f[i][j] = d[i][j]; n     } else { n       for (int j = 1; j <= n; j++) n         if (rt[j] == rt[i]) vis[j] = 0; n       vis[i] = true; n       dfs(i, 0); n       for (int j = 0; j <= n; j++) f[rt[i]][j] = mod(f[rt[i]][j] + d[i][j]); n     } n   } n   for (int i = 1; i <= n; i++) { n     if (rt[i] == i) { n       for (int j = 0; j < rs[i]; j++) n         f[i][j] = f[i][j] * fac[rs[i] - j - 1] % cys * inv[rs[i] - j] % cys; n       for (int j = 0; j <= n; j++) tmp[j] = 0; n       for (int j = 0; j <= n; j++) n         for (int k = 0; k <= n; k++) n           tmp[j + k] = mod(tmp[j + k] + ans[j] * f[i][k] % cys * fac[j + k] % n                                             cys * inv[j] % cys * inv[k] % cys); n       for (int j = 0; j <= n; j++) ans[j] = tmp[j]; n     } n   } n   for (int i = 0; i <= n; i++) printf( %lld n , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int k, l, m, n, i, j, d, fucked = 0; n   cin >> k >> l >> m >> n >> d; n   int p[100010]; n   if (k == 1 || l == 1 || m == 1 || n == 1) { n     cout << d; n   } else { n     for (i = 1; i <= d; i++) { n       if (i % (k) == 0 || i % (l) == 0 || i % (m) == 0 || i % (n) == 0) { n         p[i] = -1; n       } else { n         p[i] = 0; n       } n     } n     for (j = 1; j <= d; j++) { n       if (p[j] == -1) { n         fucked++; n       } n     } n     cout << fucked << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int gcd(long long int a, long long int b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n long long int lcm(long long int a, long long int b) { n   return (a / gcd(a, b)) * b; n } n long long int dp[2005][2005]; n long long int help(long long int n, long long int k, long long int num) { n   if (k <= 0) return 1; n   if (dp[k][num] != -1) return dp[k][num]; n   long long int cnt = 0; n   for (long long int j = num; j <= n; j += num) { n     cnt = (cnt % 1000000007 + help(n, k - 1, j) % 1000000007) % 1000000007; n   } n   return dp[k][num] = cnt; n } n void solve() { n   long long int n, k; n   cin >> n >> k; n   long long int ans = help(n, k, 1); n   cout << ans << endl; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long int t = 1; n   memset(dp, -1, sizeof(dp)); n   while (t--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n void calc(int n, long long s, long long m, int i) { n   if (n == 0) return; n   s = s / 2; n   if (s < m) { n     calc(n - 1, s, m - s, i + 1); n     cout << i <<    ; n   } else { n     cout << i <<    ; n     calc(n - 1, s, m, i + 1); n   } n } n int main() { n   int N; n   long long M; n   cin >> N >> M; n   long long a = 1; n   for (int i = 0; i < N - 1; i++) a *= 2; n   calc(N, a, M, 1); n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int max2; n int two[35]; n void DFS(int K, int L1, int R1, int L2, int R2) { n   if (((R1 - L1 + 1) <= max2) || ((R2 - L2 + 1) <= max2)) return; n   if (K == 0) { n     if (1 > max2) max2 = 1; n     return; n   } n   int L3, R3; n   if (L1 >= L2) n     L3 = L1; n   else n     L3 = L2; n   if (R1 <= R2) n     R3 = R1; n   else n     R3 = R2; n   if (R3 >= L3) { n     if ((R3 - L3 + 1) > max2) max2 = R3 - L3 + 1; n   } n   int X = two[K - 1]; n   char cr1 = 0; n   char cr2 = 0; n   if ((R1 >= X) && (L1 <= X)) cr1 = 1; n   if ((R2 >= X) && (L2 <= X)) cr2 = 1; n   if ((cr1) && (cr2)) { n     DFS(K - 1, L1, X - 1, 1, R2 - X); n     DFS(K - 1, L2, X - 1, 1, R1 - X); n   } else if (cr1) { n     int nl, nr; n     nl = L2; n     nr = R2; n     if (nl >= X) nl -= X; n     if (nr >= X) nr -= X; n     DFS(K - 1, L1, X - 1, nl, nr); n     DFS(K - 1, 1, R1 - X, nl, nr); n   } else if (cr2) { n     int nl, nr; n     nl = L1; n     nr = R1; n     if (nl >= X) nl -= X; n     if (nr >= X) nr -= X; n     DFS(K - 1, L2, X - 1, nl, nr); n     DFS(K - 1, 1, R2 - X, nl, nr); n   } else { n     int nl1, nr1, nl2, nr2; n     nl1 = L1; n     nr1 = R1; n     if (nl1 >= X) nl1 -= X; n     if (nr1 >= X) nr1 -= X; n     nl2 = L2; n     nr2 = R2; n     if (nl2 >= X) nl2 -= X; n     if (nr2 >= X) nr2 -= X; n     DFS(K - 1, nl1, nr1, nl2, nr2); n   } n } n int main() { n   two[0] = 1; n   int i; n   for (i = 1; i <= 30; i++) two[i] = two[i - 1] * 2; n   int L1, R1, L2, R2; n   scanf( %d %d %d %d , &L1, &R1, &L2, &R2); n   max2 = 0; n   DFS(30, L1, R1, L2, R2); n   printf( %d n , max2); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ld = long double; n using uint = unsigned int; n using ull = unsigned long long; n template <typename T> n using pair2 = pair<T, T>; n using pii = pair<int, int>; n using pli = pair<ll, int>; n using pll = pair<ll, ll>; n mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); n ll myRand(ll B) { return (ull)rng() % B; } n clock_t startTime; n double getCurrentTime() { n   return (double)(clock() - startTime) / CLOCKS_PER_SEC; n } n const double eps = 1e-7; n bool eq(double x, double y) { return abs(x - y) < eps; } n bool ls(double x, double y) { return x < y && !eq(x, y); } n bool lseq(double x, double y) { return x < y || eq(x, y); } n double sqr(double x) { return x * x; } n struct Point { n   double x, y; n   Point() : x(), y() {} n   Point(double _x, double _y) : x(_x), y(_y) {} n   void scan() { scanf( %lf%lf , &x, &y); } n   void print() { printf( %.12lf %.12lf n , x, y); } n   Point operator+(const Point &a) const { return Point(x + a.x, y + a.y); } n   Point operator-(const Point &a) const { return Point(x - a.x, y - a.y); } n   Point operator*(const double &k) const { return Point(x * k, y * k); } n   Point operator/(const double &k) const { return Point(x / k, y / k); } n   double operator%(const Point &a) const { return x * a.x + y * a.y; } n   double operator*(const Point &a) const { return x * a.y - y * a.x; } n   double sqrLen() const { return *this % *this; } n   double len() const { return sqrt(sqrLen()); } n   Point norm() const { return *this / len(); } n   Point ort() const { return Point(-y, x); } n }; n double getAngle(Point v, Point u) { return atan2(v * u, v % u); } n bool onLine(Point A, Point B, Point C) { return eq((A - B) * (A - C), 0); } n bool onSegm(Point A, Point B, Point C) { n   if (!onLine(A, B, C)) return false; n   return lseq((A - B) % (C - B), 0); n } n bool intersectLines(Point A, Point a, Point B, Point b, Point &I) { n   if (eq(a * b, 0)) return false; n   double y = ((A - B) * a) / (b * a); n   I = B + b * y; n   return true; n } n Point getH(Point P, Point A, Point a) { n   return A + a * (((P - A) % a) / a.sqrLen()); n } n bool intersectLineCircle(Point A, Point a, Point O, double R, Point &I1, n                          Point &I2) { n   Point H = getH(O, A, a); n   double x = (O - H).len(); n   if (ls(R, x)) return false; n   if (eq(R, x)) { n     I1 = I2 = H; n     return true; n   } n   a = a.norm(); n   x = sqrt(sqr(R) - sqr(x)); n   I1 = H + a * x; n   I2 = H - a * x; n   return true; n } n bool intersectCircles(Point O1, double R1, Point O2, double R2, Point &I1, n                       Point &I2) { n   if (R1 < R2) { n     swap(O1, O2); n     swap(R1, R2); n   } n   double L = (O1 - O2).len(); n   if (ls(R1 + R2, L) || ls(L, R1 - R2) || eq(L, 0)) return false; n   if (eq(R1 + R2, L) || eq(L, R1 - R2)) { n     I1 = I2 = O1 + (O2 - O1).norm() * R1; n     return true; n   } n   double x = (sqr(R1) - sqr(R2) + sqr(L)) / (2 * L); n   Point a = (O2 - O1).norm(); n   Point H = O1 + a * x; n   a = a.ort(); n   x = sqrt(sqr(R1) - sqr(x)); n   I1 = H + a * x; n   I2 = H - a * x; n   return true; n } n bool isInside(Point P, Point O, double R) { n   return lseq((P - O).sqrLen(), sqr(R)); n } n vector<vector<Point>> a; n vector<double> sz; n bool insidePoly(Point P, vector<Point> w) { n   int m = (int)w.size() - 1; n   for (int i = 0; i < m; i++) n     if (onSegm(w[i], P, w[i + 1])) return true; n   double ang = 0; n   for (int i = 0; i < m; i++) ang += getAngle(w[i] - P, w[i + 1] - P); n   return abs(ang) > 1; n } n bool checkPoly(vector<Point> w, Point O, double R) { n   if (insidePoly(O, w)) return true; n   int m = (int)w.size() - 1; n   for (int i = 0; i < m; i++) { n     if (isInside(w[i], O, R)) return true; n     Point H = getH(O, w[i], w[i + 1] - w[i]); n     if (isInside(H, O, R) && onSegm(w[i], H, w[i + 1])) return true; n   } n   return false; n } n vector<Point> readPoly() { n   int n; n   scanf( %d , &n); n   vector<Point> a(n + 1); n   for (int i = 0; i < n; i++) a[i].scan(); n   a[n] = a[0]; n   return a; n } n double sizePoly(vector<Point> w) { n   double S = 0; n   int m = (int)w.size() - 1; n   for (int i = 0; i < m; i++) S += w[i] * w[i + 1]; n   return abs(S) / 2; n } n int main() { n   startTime = clock(); n   double R; n   int n, w; n   scanf( %lf%lf%d , &R, &R, &n); n   a.resize(n); n   sz.resize(n); n   for (int i = 0; i < n; i++) { n     a[i] = readPoly(); n     sz[i] = sizePoly(a[i]); n   } n   int q; n   scanf( %d , &q); n   while (q--) { n     Point O; n     O.scan(); n     scanf( %lf , &R); n     vector<int> res; n     double S = 0; n     for (int i = 0; i < n; i++) { n       if (checkPoly(a[i], O, R)) { n         res.push_back(i); n         S += sz[i]; n       } n     } n     printf( %.12lf %d , S, (int)res.size()); n     for (int x : res) printf(  %d , x); n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using std::cin; n using std::cout; n using std::endl; n using std::pair; n using std::string; n using std::swap; n using std::vector; n void doit(int& xk, int& yk, int w, int h, int x, int y, int z) { n   for (int i = 0; i < x; ++i) { n     swap(xk, yk); n     swap(w, h); n     xk = w - xk + 1; n   } n   if (y) { n     xk = w - xk + 1; n   } n   for (int i = 0; i < z; ++i) { n     swap(xk, yk); n     swap(w, h); n     yk = h - yk + 1; n   } n } n int main() { n   int n, m, x, y, z, p; n   scanf( %d %d %d %d %d %d , &n, &m, &x, &y, &z, &p); n   x %= 4; n   y = y & 1; n   z %= 4; n   while (p--) { n     int xk, yk; n     scanf(  n%d %d , &yk, &xk); n     doit(xk, yk, m, n, x, y, z); n     printf( %d %d n , yk, xk); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n const int INF = 0x3f3f3f3f; n const int mxN = 61; n ll level[mxN]; n int q; n int getlevel(ll x) { n   int res = 0; n   while ((1LL << res) <= x) { n     res++; n   } n   return res - 1; n } n int main() { n   cin.tie(0)->sync_with_stdio(0); n   cin >> q; n   ll a, b, c; n   for (int i = 0; i < q; ++i) { n     cin >> a; n     if (a == 1 || a == 2) { n       cin >> b >> c; n       if (a == 1) { n         level[getlevel(b)] += c; n       } else { n         int l = getlevel(b); n         for (int i = l; i < 61; ++i) { n           level[i] = (level[i] + c * (1LL << (i - l))) % (1LL << i); n         } n       } n     } else { n       cin >> b; n       int l = getlevel(b); n       ll out = b - (1LL << l); n       out = (out + level[l]) % (1LL << l); n       if (out < 0) { n         out = out + (1LL << l); n       } n       out = (out + (1LL << l)); n       for (int i = l; i >= 0; --i) { n         ll ans = (out - (1LL << i) - level[i]) % (1LL << i); n         if (ans < 0) { n           ans += (1LL << i); n         } n         ans = (ans + (1LL << i)); n         cout << ans <<    ; n         out /= 2; n       } n       cout <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long int n, i, x = 0; n   cin >> n; n   string second; n   cin >> second; n   vector<long long int> v; n   if (second.size() == 1 && second[0] ==  ? ) return cout <<  Yes , 0; n   for (i = 0; i < second.size(); ++i) { n     if (second[i] ==  ? ) v.push_back(i); n     if (i != n - 1 && second[i] == second[i + 1] && second[i] !=  ? ) n       return cout <<  No , 0; n   } n   for (i = 0; i < v.size(); ++i) { n     if (v[i] == 0 || v[i] == second.size() - 1) return cout <<  Yes , 0; n     if (i != v.size() - 1 && v[i] == v[i + 1] - 1) return cout <<  Yes , 0; n   } n   for (i = 0; i < second.size(); ++i) { n     if (second[i] ==  ? ) { n       if (i >= 0 && i < n - 1) { n         if (second[i - 1] == second[i + 1]) return cout <<  Yes , 0; n       } n     } n   } n   cout <<  No ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n  n #define ll long long n #define mod 1000000007 n #define ffor(i,a,b) for(int i=a;i<b;i++) n #define bfor(i,a,b) for(int i=a-1;i>=b;i--) n #define mp make_pair n #define pb push_back n #define ff first n #define ss second n #define mem(x,y) memset(x,y,sizeof(x)) n #define all(x) x.begin(),x.end() n #define SP(x) setprecision(x) n #define sz(x) (int)x.size() n #define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) n #define PI 3.14159265358979323846 n #define lb lower_bound n #define ub upper_bound n #define bs binary_search n #define endl   n  n #define int long long n  n void solve() n { n     int n; n     cin>>n; n     int c[n]; n     int a[n], b[n]; n  n     ffor(i,0,n) cin>>c[i]; n     ffor(i,0,n) cin>>a[i]; n     ffor(i,0,n) cin>>b[i]; n  n     int ans=0; n     int dp[n]; n     mem(dp,0); n     dp[1]=abs(a[1]-b[1])+c[1]-1+2; n  n     ffor(i,2,n) n     { n         if(a[i]==b[i]) dp[i]=c[i]-1+2; n         else n         { n             int x=abs(a[i]-b[i])+c[i]-1+2; n             int y=c[i]-1+2+dp[i-1]-abs(a[i]-b[i]); n             dp[i]=max(x,y); n         } n     } n     cout<< *max_element(dp,dp+n)<<endl; n  n } n  n signed main() n {     n     #ifndef ONLINE_JUDGE n     freopen( input.txt ,  r , stdin); n     freopen( output.txt ,  w , stdout); n     #endif    n  n  n  n     int t; n     cin>>t; n     while(t--) n     { n         solve(); n     } n  n     return 0; n } n  n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e3 + 5; n int N, M; n long long tree[4][MAXN][MAXN]; n int ju(int x, int y) { n   int tt = 0; n   if (x % 2) tt++; n   if (y % 2) tt += 2; n   return tt; n } n void Update(int x, int y, long long v) { n   int ty = ju(x, y); n   for (int i = x; i <= N; i += i & -i) n     for (int j = y; j <= N; j += j & -j) tree[ty][i][j] ^= v; n } n long long Sum(int x, int y) { n   int ty = ju(x, y); n   long long ans = 0; n   for (int i = x; i > 0; i -= i & -i) n     for (int j = y; j > 0; j -= j & -j) ans ^= tree[ty][i][j]; n   return ans; n } n int main() { n   while (~scanf( %d %d , &N, &M)) { n     memset(tree, 0, sizeof(tree)); n     for (int i = 1; i <= M; ++i) { n       int a, b, c, d; n       int ty; n       long long v; n       scanf( %d , &ty); n       if (ty == 2) { n         scanf( %d %d %d %d %lld , &a, &b, &c, &d, &v); n         Update(a, b, v); n         Update(c + 1, b, v); n         Update(a, d + 1, v); n         Update(c + 1, d + 1, v); n       } else { n         long long ans = 0; n         scanf( %d %d %d %d , &a, &b, &c, &d); n         ans ^= Sum(c, d); n         ans ^= Sum(a - 1, d); n         ans ^= Sum(c, b - 1); n         ans ^= Sum(a - 1, b - 1); n         printf( %lld n , ans); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e9 + 7; n const int N = 4e5 + 10; n vector<int> ans[N]; n vector<int> v[N]; n int tot; n int vis[N]; n int cnt = 0; n void dfs(int x) { n   vis[x] = 1; n   ans[cnt++ / tot].push_back(x); n   for (auto &y : v[x]) { n     if (vis[y]) continue; n     dfs(y); n     ans[cnt++ / tot].push_back(x); n   } n } n int main() { n   int n, m, k; n   cin >> n >> m >> k; n   tot = (2 * n + k - 1) / k; n   while (m--) { n     int x, y; n     cin >> x >> y; n     v[x].push_back(y); n     v[y].push_back(x); n   } n   for (int i = 1; i <= n; i++) { n     if (vis[i]) continue; n     cnt = (cnt + tot - 1) / tot * tot; n     dfs(i); n   } n   for (int i = 0; i < k; i++) { n     if (ans[i].empty()) ans[i].push_back(1); n     printf( %d , ans[i].size()); n     for (auto &x : ans[i]) printf(  %d , x); n     puts(  ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x3f3f3f3f; n const long long INF = 1e18; n template <typename T> n void read(T &x) { n   x = 0; n   int s = 1, c = getchar(); n   for (; !isdigit(c); c = getchar()) n     if (c ==  - ) s = -1; n   for (; isdigit(c); c = getchar()) x = x * 10 + c - 48; n   x *= s; n } n template <typename T> n void write(T x) { n   if (x < 0) x = -x, putchar( - ); n   if (x > 9) write(x / 10); n   putchar(x % 10 +  0 ); n } n template <typename T> n void writeln(T x) { n   write(x); n   puts(  ); n } n const int maxn = 2e2 + 5, mod = 1e9 + 7; n int n, len, Next[maxn], to[maxn][2]; n char s[maxn]; n long long dp[maxn][maxn][maxn][2]; n void Get_Next(char *s, int len) { n   Next[1] = 0; n   for (int i = 2, j = 0; i <= len; i++) { n     while (j > 0 && s[i] != s[j + 1]) j = Next[j]; n     if (s[i] == s[j + 1]) j++; n     Next[i] = j; n   } n   for (int i = 0; i <= len - 1; i++) { n     int j = i; n     while (j && s[j + 1] !=  ) ) j = Next[j]; n     if (s[j + 1] ==  ) ) to[i][1] = j + 1; n     j = i; n     while (j && s[j + 1] !=  ( ) j = Next[j]; n     if (s[j + 1] ==  ( ) to[i][0] = j + 1; n   } n } n void Add(long long &x, long long y) { n   x += y; n   if (x >= mod) x -= mod; n } n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   cin >> n >> (s + 1); n   len = strlen(s + 1); n   Get_Next(s, len); n   dp[0][0][0][0] = 1; n   n *= 2; n   for (int i = 0; i <= n - 1; i++) { n     for (int k = 0; k <= i; k++) { n       for (int j = 0; j <= min(i, len - 1); j++) { n         Add(dp[i + 1][k + 1][to[j][0]][to[j][0] == len], dp[i][k][j][0]); n         if (k) Add(dp[i + 1][k - 1][to[j][1]][to[j][1] == len], dp[i][k][j][0]); n       } n       Add(dp[i + 1][k + 1][len][1], dp[i][k][len][1]); n       if (k) Add(dp[i + 1][k - 1][len][1], dp[i][k][len][1]); n     } n   } n   cout << dp[n][0][len][1] << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long int mod = 1e9 + 7; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int t; n   cin >> t; n   while (t--) { n     long long int l, r, m; n     cin >> l >> r >> m; n     long long int nn, xx; n     long long int ans = LLONG_MAX; n     for (long long int i = l; i <= r; i++) { n       long long int start = 1, end = 1e10; n       long long int flag = 1; n       while (start <= end) { n         long long int mid = (start + end) / 2; n         long long int diff = abs(mid * i - m); n         if (diff <= (r - l)) { n           if ((mid * i - m) <= 0) { n             cout << i <<     << r <<     << r - diff <<   n ; n           } else { n             cout << i <<     << r - diff <<     << r <<   n ; n           } n           flag = 0; n           break; n           end = mid - 1; n         } else if (mid * i - m >= 0) { n           end = mid - 1; n         } else { n           start = mid + 1; n         } n       } n       if (flag == 0) break; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 5e18; n const int MK = 10101; n const int MN = 101010; n long long H, M, N, K; n map<long long, long long> mp; n vector<long long> methods; n vector<pair<long long, long long> > ip[MK]; n bool pllcmp(pair<long long, long long> p1, pair<long long, long long> p2) { n   p1.second = -p1.second; n   p2.second = -p2.second; n   return p1 < p2; n }; n priority_queue<pair<long long, long long>, vector<pair<long long, long long> >, n                std::function<bool(pair<long long, long long>, n                                   pair<long long, long long>)> > n     pq(pllcmp); n long long dis[MK]; n long long op[MN]; n void spfa() { n   for (int i = 0; i < K; i++) dis[i] = INF; n   dis[0] = 0; n   queue<int> qe; n   qe.push(0); n   while (qe.size()) { n     long long v = qe.front(); n     qe.pop(); n     for (int i = 0; i < (int)methods.size(); i++) { n       long long m = methods[i]; n       long long r = (m + v) % K; n       if (dis[r] > dis[v] + m) { n         dis[r] = dis[v] + m; n         qe.push(r); n       } n     } n   } n   pq = priority_queue< n       pair<long long, long long>, vector<pair<long long, long long> >, n       function<bool(pair<long long, long long>, pair<long long, long long>)> >( n       pllcmp); n   for (int i = 0; i < N; i++) { n     long long a = op[i], c = mp[op[i]]; n     long long r = a % K; n     if (a >= dis[r]) { n       pq.push(make_pair(c, i)); n     } n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> H >> N >> M >> K; n   for (int i = 0; i < N; i++) { n     long long a, c; n     cin >> a >> c; n     a--; n     mp[a] = c; n     ip[a % K].push_back(make_pair(i, c)); n     op[i] = a; n   } n   for (int i = 0; i < (int)ip[0].size(); i++) { n     pq.push(make_pair(ip[0][i].second, ip[0][i].first)); n   } n   for (int i = 1; i < K; i++) dis[i] = INF; n   for (int i = 0; i < M; i++) { n     int t; n     cin >> t; n     if (t == 1) { n       long long x; n       cin >> x; n       methods.push_back(x); n       spfa(); n     } else if (t == 2) { n       long long id, a, c; n       cin >> id >> c; n       id--; n       a = op[id]; n       mp[a] -= c; n       if (dis[a % K] <= a) pq.push(make_pair(mp[a], id)); n     } else if (t == 3) { n       pair<long long, long long> tp; n       while (pq.size()) { n         tp = pq.top(); n         if (mp[op[tp.second]] == tp.first) break; n         pq.pop(); n       } n       cout << (pq.size() ? tp.first : 0) << endl; n       if (pq.size()) mp[op[tp.second]] = 0; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:268435456 ) n using namespace std; n template <typename T> n T sqr(const T &x) { n   return x * x; n } n template <typename T> n T my_abs(const T &x) { n   return x < 0 ? -x : x; n } n const int INF = (int)1e9; n const long long LINF = (long long)6e18; n const long long INF64 = LINF; n const long long INFLL = LINF; n const long double EPS = 1e-15; n const long double PI = 3.1415926535897932384626433832795; n const long double ME = 1e-5; n const long long MOD2 = (int)1e9 + 21; n const int SQN = 320; n const int LOGN = 17; n const int dx[] = {0, 1, 0, -1}; n const int dy[] = {-1, 0, 1, 0}; n const int N = (int)5e3 + 10; n const int M = (int)2e6 + 10; n const long long MOD = (int)1e9 + 7; n int z[N][N]; n int psum[N][N]; n int prv[26][N]; n int a[N]; n void solve() { n   int n; n   cin >> n; n   string s; n   cin >> s; n   for (int i = 0; i < int(n); ++i) { n     a[i] = s[i] -  a ; n   } n   memset(prv, -1, sizeof(prv)); n   for (int i = 0; i < int(26); ++i) { n     for (int j = 1; j < int(n); ++j) { n       if (a[j - 1] == i) { n         prv[i][j] = j - 1; n       } else { n         prv[i][j] = prv[i][j - 1]; n       } n     } n   } n   z[0][0] = 1; n   for (int j = 1; j < int(n + 1); ++j) { n     psum[0][j] = 1; n   } n   for (int i = 1; i < int(n + 1); ++i) { n     for (int j = 0; j < int(n); ++j) { n       z[i][j] = (z[i][j] + z[i - 1][j]) % MOD; n       z[i][j] = n           (z[i][j] + psum[i - 1][j] - psum[i - 1][prv[a[j]][j] + 1] + MOD) % n           MOD; n       psum[i][j + 1] = (psum[i][j] + z[i][j]) % MOD; n     } n   } n   int ans = 0; n   for (int j = 0; j < int(n); ++j) { n     ans = (ans + z[n][j]) % MOD; n   } n   cout << ans << endl; n } n int main() { n   ios_base::sync_with_stdio(false); n   srand((unsigned int)time(NULL)); n   cout << setprecision(15) << fixed; n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1e9 + 7; n const double pi = acos(-1.0); n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long tt; n   tt = 1; n   while (tt--) { n     long long n, m; n     cin >> n >> m; n     long long cost[n + 2]; n     for (long long i = 0; i < n; i += 1) cin >> cost[i + 1]; n     long long ans = 0; n     for (long long i = 0; i < m; i += 1) { n       long long p, q; n       cin >> p >> q; n       ans += min(cost[p], cost[q]); n     } n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     vector<long long> a; n     for (int i = 0; i < n; i++) { n       long long x; n       cin >> x; n       a.push_back(x); n     } n     long long m = 0; n     for (int i = 0; i < (n - 1); i++) { n       long long x = a[i] * a[i + 1]; n       if (x > m) m = x; n     } n     cout << m << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n typedef long long ll; n typedef long long int lli; n const int mod=1e9+7; n int main() n { n   n     ll t; n     cin>>t; n     while(t--) n     { n         ll n; n         cin>>n; n         if(n<=32) n         { n             ll m=n-3; n             m+=5; n             cout<<m<<endl; n             for(ll i=3; i<n; i++) n             { n                 cout<<i<<   <<n<<endl; n             } n             for(ll i=0; i<5; i++) n             { n                 cout<<n<<   <<2<<endl; n             } n         } n         else n         { n             ll m = n-4; n             m+=9; n             cout<<m<<endl; n             for(ll i=3; i<n; i++) n             { n                 if(i==16) n                     continue; n                 cout<<i<<   <<n<<endl; n             } n   n             for(ll i=0; i<5; i++) n             { n                 cout<<n<<   <<16<<endl; n             } n   n             for(ll i=0; i<4; i++) n             { n                 cout<<16<<   <<2<<endl; n             } n             //cout<<m<<nn; n         } n     } n }


#include <bits/stdc++.h> n using namespace std; n int read() { n   int a = 0; n   char c = getchar(); n   while (!isdigit(c)) c = getchar(); n   while (isdigit(c)) { n     a = a * 10 + c - 48; n     c = getchar(); n   } n   return a; n } n const int _ = 3e5 + 7, __ = _ * 19; n vector<int> nxt[_]; n int N, M, dep[_]; n void qdep(int x, int p) { n   dep[x] = dep[p] + 1; n   for (auto &t : nxt[x]) n     if (t != p) qdep(t, x); n } n long long mrk[__], mn[__]; n int ch[__][2], cnode; n void mark(int x, long long v) { n   if (x) { n     mrk[x] = min(mrk[x] + v, mn[0]); n     mn[x] = min(mn[x] + v, mn[0]); n   } n } n void down(int x) { n   if (x && mrk[x]) { n     mark((ch[x][0]), mrk[x]); n     mark((ch[x][1]), mrk[x]); n     mrk[x] = 0; n   } n } n void mdf(int &x, int l, int r, int t, long long v, bool type) { n   if (!type && !x) { n     x = ++cnode; n   } n   if (l == r) { n     mn[x] = type ? v : min(mn[x], v); n     return; n   } n   down(x); n   ((l + r) >> 1) >= t ? mdf((ch[x][0]), l, ((l + r) >> 1), t, v, type) n                       : mdf((ch[x][1]), ((l + r) >> 1) + 1, r, t, v, type); n   mn[x] = min(mn[(ch[x][0])], mn[(ch[x][1])]); n } n int merge(int p, int q) { n   if (!p || !q) { n     return p + q; n   } n   mn[p] = min(mn[p], mn[q]); n   down(p); n   down(q); n   ch[p][0] = merge(ch[p][0], ch[q][0]); n   ch[p][1] = merge(ch[p][1], ch[q][1]); n   return p; n } n vector<pair<int, int> > route[_]; n int dfs(int x, int p) { n   long long vlsum = 0; n   int rt = 0; n   for (auto t : nxt[x]) n     if (t != p) { n       int R = dfs(t, x); n       mdf(R, 1, N, dep[x] + 1, mn[0], 1); n       long long v = mn[R]; n       mark(rt, v); n       mark(R, vlsum); n       vlsum = min(mn[0], vlsum + v); n       rt = merge(rt, R); n     } n   for (auto t : route[x]) mdf(rt, 1, N, t.first, vlsum + t.second, 0); n   if (x == 1) cout << (vlsum <= 1e16 ? vlsum : -1); n   return rt; n } n int main() { n   N = read(); n   M = read(); n   for (int i = 1; i < N; ++i) { n     int x = read(), y = read(); n     nxt[x].push_back(y); n     nxt[y].push_back(x); n   } n   qdep(1, 0); n   for (int i = 1; i <= M; ++i) { n     int x = read(), y = read(), w = read(); n     route[x].push_back(pair<int, int>(dep[y], w)); n   } n   memset(mn, 0x3f, sizeof(mn)); n   dfs(1, 0); n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int x, y, s; n   scanf( %d %d %d , &x, &y, &s); n   if (s >= 0) { n     y = y + s; n     if (y % x) n       printf( %d , y % x); n     else n       printf( %d , x); n   } else if (s < 0) { n     double p = abs(s); n     p = ceil(p / x); n     y = y + s + (p * x); n     if (y % x) n       printf( %d , y % x); n     else n       printf( %d , x); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   long long n, a, b; n   cin >> n >> a >> b; n   set<long long> s; n   while (a--) { n     long long j; n     cin >> j; n     s.insert(j); n   } n   for (long long i = 1; i <= n; i++) n     if (s.count(i)) n       cout <<  1  ; n     else n       cout <<  2  ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1e9, MAXN = 4010; n int n; n inline int pack(int l, int r, int k) { return (l << 19) + (r << 7) + k; } n unordered_map<int, int> dp(MAXN* MAXN * 2); n vector<int> a, pref; n int calc(int l, int r, int k, int p) { n   if (p) { n     if (dp.count(pack(l, r, k))) return dp[pack(l, r, k)]; n     if (r - l + 1 < k) return dp[pack(l, r, k)] = 0; n     if (r - l + 1 == k) n       return dp[pack(l, r, k)] = n                  (calc(l + k, r, k, p ^ 1) + (pref[l + k - 1] - pref[l - 1])); n     return dp[pack(l, r, k)] = max( n                calc(l + k, r, k, p ^ 1) + (pref[l + k - 1] - pref[l - 1]), n                calc(l + k + 1, r, k + 1, p ^ 1) + (pref[l + k] - pref[l - 1])); n   } n   if (r - l + 1 < k) return 0; n   if (r - l + 1 == k) return calc(l, r - k, k, p ^ 1) - (pref[r] - pref[r - k]); n   return min(calc(l, r - k, k, p ^ 1) - (pref[r] - pref[r - k]), n              calc(l, r - k - 1, k + 1, p ^ 1) - (pref[r] - pref[r - k - 1])); n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(nullptr); n   cout.tie(nullptr); n   cin >> n; n   a.resize(n); n   pref.resize(n + 1); n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     pref[i + 1] = pref[i] + a[i]; n   } n   cout << calc(1, n, 1, 1) <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = numeric_limits<int>::max(); n int n; n vector<int> d, a; n int get_longest(int l) { n   vector<int> d; n   while (l > a.size()) n     for (int i = 0; i < n; ++i) a.push_back(a[i]); n   d.assign(l + 10, INF); n   d[0] = -INF; n   for (int i = 0; i < l; ++i) { n     int j = int(upper_bound(d.begin(), d.end(), a[i]) - d.begin()); n     if (d[j - 1] <= a[i] && a[i] < d[j]) d[j] = a[i]; n   } n   for (int i = 1; i <= l; ++i) n     if (d[i] == INF) return i - 1; n   return l; n } n int main() { n   int t; n   int longest_same = 1; n   vector<int> b; n   scanf( %d %d , &n, &t); n   a.assign(n, 0); n   for (int i = 0; i < n; ++i) scanf( %d , &a[i]); n   b.assign(a.begin(), a.end()); n   sort(b.begin(), b.end()); n   map<int, int> new_val; n   int longest = 1; n   for (int i = 0; i < n; ++i) { n     if (i > 0 && b[i] == b[i - 1]) n       ++longest; n     else { n       if (longest > longest_same) longest_same = longest; n       longest = 1; n     } n     if (i == 0 || b[i] != b[i - 1]) new_val[b[i]] = i; n   } n   if (longest > longest_same) longest_same = longest; n   for (int i = 0; i < n; ++i) { n   } n   longest = get_longest(n); n   int next_longest, prev_longest; n   int d = INF; n   int k = 1; n   while (d > longest_same && k < t) { n     ++k; n     next_longest = get_longest(k * n); n     d = next_longest - longest; n     prev_longest = longest; n     longest = next_longest; n   } n   if (d <= longest_same) { n     longest = prev_longest + (t - k + 1) * longest_same; n   } n   printf( %d n , longest); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n namespace DynamicTree { n unsigned int randxor() { n   static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123; n   unsigned int t; n   t = (x ^ (x << 11)); n   x = y; n   y = z; n   z = w; n   return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8))); n } n struct D_NODE { n   int lazy_for_dep; n   int dep; n   D_NODE *pr; n   D_NODE *pair_of_end; n   int __PRIORITY; n   int size; n   long long int lazy_for_dist; n   long long int dist; n   long long int have_dist; n   D_NODE *lef; n   D_NODE *rig; n   int idx; n   int MINT_DEP; n   D_NODE *MINT; n   int MAXT_DEP; n   D_NODE *MAXT; n   bool start_flag; n   int NUMBER_OF_START_FLAG; n   D_NODE() { n     NUMBER_OF_START_FLAG; n     start_flag = false; n     lazy_for_dep = 0; n     dep = 0; n     lazy_for_dist = 0; n     dist = 0; n     lef = rig = NULL; n     __PRIORITY = randxor(); n     pair_of_end = NULL; n     MINT = NULL; n     MINT_DEP = INT_MAX; n     MAXT = NULL; n     MAXT_DEP = INT_MIN; n     pr = NULL; n     size = 0; n   } n }; n const int MEMORY_SIZE = 2000000; n D_NODE dymmy[MEMORY_SIZE]; n int ord = 0; n D_NODE *neww() { n   if (ord < MEMORY_SIZE) { n     ord++; n     return &dymmy[ord - 1]; n   } n   return new D_NODE(); n } n const int VECTOR_SIZE = 1000000; n D_NODE *VEC[VECTOR_SIZE]; n int VECTOR_CUR_INDEX = 0; n inline void see(D_NODE *f, bool B = false) { n   if (f->lef) { n     see(f->lef, true); n   } n   cout << f->idx <<    ; n   if (f->rig) { n     see(f->rig, true); n   } n   if (B == false) { n     puts(  ); n   } n } n int get_size(D_NODE *b) { n   if (b == NULL) { n     return 0; n   } n   return b->size; n } n void update(D_NODE *B) { n   if (B == NULL) { n     return; n   } n   if (B->lazy_for_dep) { n     B->dep += B->lazy_for_dep; n     if (B->lef) { n       B->lef->lazy_for_dep += B->lazy_for_dep; n     } n     if (B->rig) { n       B->rig->lazy_for_dep += B->lazy_for_dep; n     } n     B->lazy_for_dep = 0; n   } n   if (B->lazy_for_dist) { n     B->dist += B->lazy_for_dist; n     if (B->lef) { n       B->lef->lazy_for_dist += B->lazy_for_dist; n     } n     if (B->rig) { n       B->rig->lazy_for_dist += B->lazy_for_dist; n     } n     B->lazy_for_dist = 0; n   } n   B->size = 1 + get_size(B->lef) + get_size(B->rig); n   if (B->lef) { n     B->lef->pr = B; n   } n   if (B->rig) { n     B->rig->pr = B; n   } n   B->MINT = B; n   B->MINT_DEP = B->dep; n   if (B->lef && B->MINT_DEP > B->lef->MINT_DEP + B->lef->lazy_for_dep) { n     B->MINT_DEP = B->lef->MINT_DEP + B->lef->lazy_for_dep; n     B->MINT = B->lef->MINT; n   } n   if (B->rig && B->MINT_DEP > B->rig->MINT_DEP + B->rig->lazy_for_dep) { n     B->MINT_DEP = B->rig->MINT_DEP + B->rig->lazy_for_dep; n     B->MINT = B->rig->MINT; n   } n   B->MAXT = B; n   B->MAXT_DEP = B->dep; n   if (B->lef && B->MAXT_DEP < B->lef->MAXT_DEP + B->lef->lazy_for_dep) { n     B->MAXT_DEP = B->lef->MAXT_DEP + B->lef->lazy_for_dep; n     B->MAXT = B->lef->MAXT; n   } n   if (B->rig && B->MAXT_DEP < B->rig->MAXT_DEP + B->rig->lazy_for_dep) { n     B->MAXT_DEP = B->rig->MAXT_DEP + B->rig->lazy_for_dep; n     B->MAXT = B->rig->MAXT; n   } n   B->NUMBER_OF_START_FLAG = B->start_flag; n   if (B->lef) { n     B->NUMBER_OF_START_FLAG += B->lef->NUMBER_OF_START_FLAG; n   } n   if (B->rig) { n     B->NUMBER_OF_START_FLAG += B->rig->NUMBER_OF_START_FLAG; n   } n } n D_NODE *find_root(D_NODE *a) { n   while (a->pr != NULL) { n     update(a); n     a = a->pr; n   } n   return a; n } n void path_update(D_NODE *a, bool dep_only = false) { n   VECTOR_CUR_INDEX = 0; n   while (a != NULL) { n     VEC[VECTOR_CUR_INDEX] = a; n     VECTOR_CUR_INDEX++; n     a = a->pr; n   } n   int k = VECTOR_CUR_INDEX - 1; n   if (dep_only == false) { n     for (int i = k; i >= 0; i--) { n       update(VEC[i]); n     } n   } n   for (int i = 0; i <= k; i++) { n     update(VEC[i]); n   } n } n inline D_NODE *merge(D_NODE *a, D_NODE *b) { n   if (a != NULL) update(a); n   if (b != NULL) update(b); n   if (a == NULL) { n     path_update(b); n     return b; n   } n   if (b == NULL) { n     path_update(a); n     return a; n   } n   if (a->__PRIORITY > b->__PRIORITY) { n     a->rig = merge(a->rig, b); n     update(a); n     return a; n   } else { n     b->lef = merge(a, b->lef); n     update(b); n     return b; n   } n } n int calc_left_size(D_NODE *a) { n   if (a == NULL) { n     return 0; n   } n   path_update(a); n   int sum = 1 + get_size(a->lef); n   D_NODE *pre = a; n   a = a->pr; n   while (a != NULL) { n     if (a->rig == pre) { n       sum++; n       sum += get_size(a->lef); n     } n     pre = a; n     a = a->pr; n   } n   return sum; n } n inline void split_base_cnt(D_NODE *b, D_NODE *&l, D_NODE *&r, int x) { n   if (b == NULL) { n     D_NODE *L = NULL; n     if (l) L = l->pr; n     D_NODE *R = NULL; n     if (r) R = r->pr; n     l = r = NULL; n     path_update(L); n     path_update(R); n     return; n   } n   update(b); n   int __get_size = get_size(b->lef); n   if (__get_size >= x) { n     r = b; n     update(b->lef); n     split_base_cnt(b->lef, l, b->lef, x); n     return; n   } n   if (__get_size + 1 == x) { n     l = b; n     r = b->rig; n     l->rig = NULL; n     path_update(l); n     return; n   } n   l = b; n   update(b->rig); n   split_base_cnt(b->rig, b->rig, r, x - 1 - __get_size); n } n D_NODE *cut(D_NODE *&tree, D_NODE *root_of_new_subtree) { n   if (root_of_new_subtree == NULL) { n     cout <<  error cut  << endl; n     exit(0); n     return NULL; n   } n   D_NODE *star = root_of_new_subtree; n   D_NODE *en = root_of_new_subtree->pair_of_end; n   int __LEFT_SIZE = calc_left_size(star); n   int cur_dep = root_of_new_subtree->dep; n   long long int cur_dist = root_of_new_subtree->dist; n   D_NODE *l1 = NULL; n   D_NODE *l2 = NULL; n   D_NODE *l3 = NULL; n   split_base_cnt(tree, l1, l2, __LEFT_SIZE - 1); n   if (l1) { n     l1->pr = NULL; n   } n   if (l2) { n     l2->pr = NULL; n   } n   if (tree) { n     tree->pr = NULL; n   } n   int __RIGHT_SIZE = calc_left_size(en); n   split_base_cnt(l2, l2, l3, __RIGHT_SIZE); n   if (l2) { n     l2->pr = NULL; n   } n   if (l3) { n     l3->pr = NULL; n   } n   tree = merge(l1, l3); n   if (tree) tree->pr = NULL; n   if (l2) l2->pr = NULL; n   if (l2) l2->lazy_for_dep += -cur_dep; n   if (l2) l2->lazy_for_dist += -cur_dist; n   update(l2); n   return l2; n } n void add_distance(D_NODE *&tree, D_NODE *ap, long long int add) { n   path_update(ap); n   ap->have_dist += add; n   D_NODE *star = ap; n   D_NODE *en = star->pair_of_end; n   int __LEFT_SIZE = calc_left_size(star); n   D_NODE *l1; n   D_NODE *l2; n   D_NODE *l3; n   split_base_cnt(tree, l1, l2, __LEFT_SIZE - 1); n   int __RIGHT_SIZE = calc_left_size(en); n   split_base_cnt(tree, l2, l3, __RIGHT_SIZE); n   l2->lazy_for_dist += add; n   update(l2); n   tree = merge(l1, l2); n   tree = merge(tree, l3); n   tree->pr = NULL; n   return; n } n void link(D_NODE *&tree, D_NODE *nex_parent, D_NODE *linked, n           long long int subtree_add_dist = 1) { n   if (linked == NULL) { n     return; n   } n   path_update(nex_parent); n   path_update(nex_parent->pair_of_end); n   D_NODE *ne = neww(); n   (*ne) = (*nex_parent->pair_of_end); n   ne->pr = NULL; n   ne->lef = ne->rig = NULL; n   ne->size = 1; n   ne->MINT_DEP = ne->MAXT_DEP = ne->dep; n   ne->MINT = ne->MAXT = ne; n   update(ne); n   update(linked); n   linked->lazy_for_dist += nex_parent->dist + subtree_add_dist; n   linked->lazy_for_dep += nex_parent->dep + 1; n   update(linked); n   linked = merge(ne, linked); n   linked->pr = NULL; n   int LEFT_SIZE = calc_left_size(nex_parent->pair_of_end); n   LEFT_SIZE--; n   D_NODE *l1 = NULL; n   D_NODE *l2 = NULL; n   split_base_cnt(tree, l1, l2, LEFT_SIZE); n   if (l1) l1->pr = NULL; n   if (l2) l2->pr = NULL; n   tree = merge(l1, linked); n   if (tree) { n     tree->pr = NULL; n   } n   D_NODE *cp_ = tree; n   tree = merge(tree, l2); n   tree->pr = NULL; n } n D_NODE *LCA(D_NODE *&tree, D_NODE *a, D_NODE *b) { n   if (a == b) return a; n   tree->pr = NULL; n   int lef1 = calc_left_size(a); n   int rig1 = calc_left_size(a->pair_of_end); n   int lef2 = calc_left_size(b); n   int rig2 = calc_left_size(b->pair_of_end); n   if (lef1 <= lef2 && rig2 <= rig1) { n     return a; n   } n   if (lef2 <= lef1 && lef1 <= rig2) { n     return b; n   } n   int mint = lef1; n   if (lef1 > lef2) { n     mint = lef2; n   } n   int maxt = rig1; n   if (rig1 < rig2) { n     maxt = rig2; n   } n   D_NODE *L1; n   D_NODE *L2; n   D_NODE *L3; n   D_NODE *ANS; n   split_base_cnt(tree, L1, L2, mint - 1); n   split_base_cnt(L2, L2, L3, maxt - mint + 1); n   if (L1) { n     L1->pr = NULL; n   } n   if (L2) { n     L2->pr = NULL; n   } n   if (L3) { n     L3->pr = NULL; n   } n   ANS = L2->MINT; n   tree = merge(L1, L2); n   tree = merge(tree, L3); n   if (tree) tree->pr = NULL; n   return ANS; n } n long long int distance(D_NODE *&tree, D_NODE *a, D_NODE *b) { n   if (a == b) { n     return 0; n   } n   tree->pr = NULL; n   D_NODE *LC = LCA(tree, a, b); n   path_update(LC); n   long long int ans = a->dist + b->dist - 2LL * LC->dist; n   return ans; n } n void push_back(D_NODE *&tree, D_NODE *a) { n   tree = merge(tree, a); n   tree->pr = NULL; n } n D_NODE *go_up(D_NODE *tree, D_NODE *from, int x) { n   if (x == 0) { n     return from; n   } n   path_update(from); n   int want_dep = from->dep - x; n   update(from); n   update(from->lef); n   if (from->lef && from->lef->MINT_DEP <= want_dep && n       want_dep <= from->lef->MAXT_DEP) { n     from = from->lef; n     while (1) { n       update(from); n       update(from->rig); n       if (from->rig && from->rig->MINT_DEP <= want_dep && n           from->rig->MAXT_DEP >= want_dep) { n         from = from->rig; n         continue; n       } n       if (from->dep == want_dep) { n         return from; n       } n       from = from->lef; n       continue; n     } n   } n   D_NODE *pre = from; n   from = from->pr; n   while (1) { n     update(from); n     update(from->lef); n     if (from->lef == pre) { n       pre = from; n       from = from->pr; n       continue; n     } n     if (from->dep == want_dep) { n       return from; n     } n     if (from->lef && from->lef->MINT_DEP <= want_dep && n         want_dep <= from->lef->MAXT_DEP) { n       from = from->lef; n       while (1) { n         update(from); n         update(from->rig); n         if (from->rig && from->rig->MINT_DEP <= want_dep && n             from->rig->MAXT_DEP >= want_dep) { n           from = from->rig; n           continue; n         } n         if (from->dep == want_dep) { n           return from; n         } n         from = from->lef; n         continue; n       } n     } else { n       pre = from; n       from = from->pr; n     } n   } n } n D_NODE *F(D_NODE *tree, int k) { n   D_NODE *a = tree; n   update(a); n   while (1) { n     update(a); n     if (a->rig) { n       update(a->rig); n       if (a->rig->MAXT_DEP >= k && a->rig->MINT_DEP <= k) { n         a = a->rig; n         continue; n       } n     } n     if (a->dep == k) { n       return a; n     } n     a = a->lef; n   } n   return a; n } n inline void se(D_NODE *f, bool B = false) { n   update(f); n   int MX = f->MAXT_DEP; n   int MN = f->MINT_DEP; n   if (f->lef) { n     se(f->lef, true); n   } n   if (f->rig) { n     se(f->rig, true); n   } n   update(f); n } n }  // namespace DynamicTree n DynamicTree::D_NODE *root; n int n; n int m; n vector<int> v[100002]; n DynamicTree::D_NODE *linkk[100002]; n int dep[100002]; n int star[100002]; n int en[100002]; n bool use[100002]; n vector<int> vv; n int siz; n inline void dfs(int b, int h = 0) { n   use[b] = true; n   dep[b] = h; n   star[b] = siz; n   siz++; n   vv.push_back(b); n   for (int i = 0; i < v[b].size(); i++) { n     if (use[v[b][i]]) { n       continue; n     } n     dfs(v[b][i], h + 1); n     en[b] = siz; n     siz++; n     vv.push_back(b); n   } n   if (siz - 1 == star[b]) { n     vv.push_back(b); n     en[b] = siz; n     siz++; n   } n } n void make() { n   dfs(0); n   for (int i = 0; i < vv.size(); i++) { n     DynamicTree::D_NODE *add = DynamicTree::neww(); n     add->dep = dep[vv[i]]; n     add->idx = vv[i]; n     add->MINT = add; n     add->MINT_DEP = dep[vv[i]]; n     add->MAXT_DEP = dep[vv[i]]; n     add->MAXT = add; n     add->dist = dep[vv[i]]; n     add->have_dist = 1; n     add->size = 1; n     if (star[vv[i]] == i) { n       add->start_flag = true; n       add->NUMBER_OF_START_FLAG = 1; n       linkk[vv[i]] = add; n       DynamicTree::push_back(root, add); n     } else { n       linkk[vv[i]]->pair_of_end = add; n       DynamicTree::push_back(root, add); n     } n   } n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < n; i++) { n     int k; n     scanf( %d , &k); n     for (int j = 0; j < k; j++) { n       int a; n       scanf( %d , &a); n       a--; n       v[i].push_back(a); n     } n   } n   make(); n   int cc = 0; n   while (m--) { n     int ty; n     scanf( %d , &ty); n     if (ty == 1) { n       cc++; n       int a, b; n       scanf( %d%d , &a, &b); n       a--; n       b--; n       printf( %lld n , DynamicTree::distance(root, linkk[a], linkk[b])); n       continue; n     } n     if (ty == 2) { n       int a, b; n       scanf( %d%d , &a, &b); n       a--; n       b = DynamicTree::go_up(root, linkk[a], b)->idx; n       DynamicTree::D_NODE *nw = DynamicTree::cut(root, linkk[a]); n       DynamicTree::link(root, linkk[b], nw); n       continue; n     } n     int k; n     scanf( %d , &k); n     cc++; n     DynamicTree::D_NODE *ans = DynamicTree::F(root, k); n     printf( %d n , ans->idx + 1); n   } n   return 0; n } n


/****************************************************************************** n  n                               Online C++ Compiler. n                Code, Compile, Run and Debug C++ program online. n Write your code in this editor and press  Run  button to compile and execute it. n  n *******************************************************************************/ n  n #include <bits/stdc++.h> n using namespace std; n  n #define ll long long n  n int main() n { n     int t; cin >> t; n      n     while (t--){ n         int n; cin >> n; n         vector<int> a(n); n         for (int i = 0; i < n; i++) cin >> a[i]; n         int check = 1; n         for (int i = 0; i < n - 1; i++) if (a[i] > a[i + 1]) check = 0; n         if (check) cout << 0 << endl; n         else if (a[0] == 1 || a[n - 1] == n) cout << 1 << endl; n         else if (a[0] == n && a[n - 1] == 1) cout << 3 << endl; n         else cout << 2 << endl; n     } n  n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int x, x1, y, y1; n   char a, b; n   cin >> a >> y >> b >> y1; n   x1 = a - 96; n   x = b - 96; n   int counter = 0; n   string s[100000]; n   while (true) { n     if (x == x1 && y == y1) { n       break; n     } n     if (x > x1) { n       x1++; n       s[counter] +=  R ; n     } n     if (x < x1) { n       x1--; n       s[counter] +=  L ; n     } n     if (y > y1) { n       y1++; n       s[counter] +=  D ; n     } n     if (y < y1) { n       y1--; n       s[counter] +=  U ; n     } n     counter++; n   } n   cout << counter << endl; n   for (int i = 0; i < counter; i++) { n     cout << s[i] << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 7; n const int INF = 1e8 + 7; n int n; n int Min[N][20], Max[N][20]; n struct Node { n   int x, y; n   bool operator<(const Node& p) const { return x < p.x; } n } nod[N]; n long long sqr(long long x) { return x * x; } n void rmq() { n   for (int i = 0; i < n; ++i) { n     Min[i][0] = nod[i].y; n     Max[i][0] = nod[i].y; n   } n   for (int j = 1; (1 << j) <= n; ++j) n     for (int i = 0; i + (1 << j) - 1 < n; ++i) { n       Min[i][j] = min(Min[i][j - 1], Min[i + (1 << (j - 1))][j - 1]); n       Max[i][j] = max(Max[i][j - 1], Max[i + (1 << (j - 1))][j - 1]); n     } n } n int query(int t, int l, int r) { n   if (l > r) return (1 - (t << 1)) * INF; n   int k = (int)log2(r - l + 1.0); n   switch (t) { n     case 0: n       return min(Min[l][k], Min[r - (1 << k) + 1][k]); n     case 1: n       return max(Max[l][k], Max[r - (1 << k) + 1][k]); n   } n   return 0; n } n bool isok(long long D, long long x, long long ymin, long long ymax) { n   if (x > D) return false; n   if (ymin != -INF && x + sqr(ymin) > D) return false; n   if (ymax != INF && x + sqr(ymax) > D) return false; n   if (ymin != -INF && ymax != INF && sqr(ymax - ymin) > D) return false; n   return true; n } n bool check(long long D) { n   if (sqr(nod[n - 1].x - nod[0].x) <= D) return true; n   if (sqr(query(1, 0, n - 1) - query(0, 0, n - 1)) <= D) return true; n   int l = 0, r = n - 1, ymin, ymax; n   r = 0; n   for (int i = 0; i < n; ++i) { n     if (r < i) r = i; n     while (r + 1 < n && abs(nod[r + 1].x) <= abs(nod[i].x) && n            sqr(nod[r + 1].x - nod[i].x) <= D) n       ++r; n     while (abs(nod[r].x) > abs(nod[i].x)) --r; n     l = i; n     ymin = min(query(0, 0, l - 1), query(0, r + 1, n - 1)); n     ymax = max(query(1, 0, l - 1), query(1, r + 1, n - 1)); n     long long x = sqr(nod[l].x); n     if (isok(D, x, ymin, ymax)) return true; n   } n   l = 0, r = n - 1; n   l = n - 1; n   for (int i = n - 1; i >= 0; --i) { n     if (l > i) l = i; n     while (l - 1 >= 0 && abs(nod[l - 1].x) <= abs(nod[i].x) && n            sqr(nod[l - 1].x - nod[i].x) <= D) n       --l; n     while (abs(nod[l].x) > abs(nod[i].x)) ++l; n     r = i; n     ymin = min(query(0, 0, l - 1), query(0, r + 1, n - 1)); n     ymax = max(query(1, 0, l - 1), query(1, r + 1, n - 1)); n     long long x = max(sqr(nod[l].x), sqr(nod[r].x)), n               y = max(sqr(ymin), sqr(ymax)); n     if (isok(D, x, ymin, ymax)) return true; n   } n   return false; n } n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; ++i) { n     scanf( %d%d , &nod[i].x, &nod[i].y); n   } n   sort(nod, nod + n); n   rmq(); n   long long L = 0, R = sqr(nod[n - 1].x - nod[0].x); n   while (L + 1 < R) { n     long long M = (L + R) >> 1; n     check(M) ? R = M : L = M; n   } n   long long ans = check(L) ? L : R; n   printf( %I64d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 100; n int m, n, h; n int t[maxn]; n int first[maxn * 2], nxt[maxn * 2], des[maxn * 2], tot; n int dfn[maxn], low[maxn], dft; n bool d[maxn]; n int flag[maxn], cnt[maxn], scc; n stack<int> stk; n inline void add(int x, int y) { n   tot++; n   des[tot] = y; n   nxt[tot] = first[x]; n   first[x] = tot; n } n void tar(int node) { n   dfn[node] = low[node] = ++dft; n   stk.push(node); n   for (int t = first[node]; t; t = nxt[t]) { n     int v = des[t]; n     if (!dfn[v]) tar(v); n     low[node] = min(low[node], low[v]); n   } n   if (dfn[node] == low[node]) { n     scc++; n     while (true) { n       int temp = stk.top(); n       flag[temp] = scc; n       cnt[scc]++; n       stk.pop(); n       if (temp == node) break; n     } n   } n } n int main() { n   scanf( %d%d%d , &n, &m, &h); n   for (int i = 1; i <= n; i++) { n     scanf( %d , t + i); n   } n   for (int i = 0; i < m; i++) { n     int u1, u2; n     scanf( %d%d , &u1, &u2); n     if (t[u1] == (t[u2] + 1) % h) add(u2, u1); n     if (t[u2] == (t[u1] + 1) % h) add(u1, u2); n   } n   for (int i = 1; i <= n; i++) { n     if (!dfn[i]) tar(i); n   } n   for (int i = 1; i <= n; i++) { n     for (int t = first[i]; t; t = nxt[t]) { n       if (flag[i] == flag[des[t]]) n         continue; n       else { n         d[flag[i]]++; n       } n     } n   } n   cnt[0] = n + 1; n   int ans = 0; n   for (int i = 1; i <= scc; i++) { n     if (d[i] == 0 && cnt[i] < cnt[ans]) { n       ans = i; n     } n   } n   cout << cnt[ans] << endl; n   for (int i = 1; i <= n; i++) { n     if (flag[i] == ans) { n       cout << i <<    ; n     } n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, i, j, a[2002]; n double p[5005], sp[5005], m, res; n int main() { n   scanf( %d , &n); n   for (i = 0; i < n; i++) scanf( %d , &a[i]); n   sort(a, a + n); n   for (i = 0; i < n; i++) n     for (j = 0; j < i; j++) p[a[i] - a[j]]++; n   m = (n - 1) * n / 2; n   for (i = 5000; i >= 0; i--) { n     p[i] = p[i] / m; n     sp[i] = sp[i + 1] + p[i]; n   } n   for (i = 1; i < 5000; i++) n     for (j = 1; i + j < 5000; j++) res += p[i] * p[j] * sp[i + j + 1]; n   printf( %.6lf n , res); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long T, n, i, l, r, mid, res; n   scanf( %lld , &T); n   while (T--) { n     scanf( %lld , &n); n     l = 2; n     r = n - 1; n     res = n - 1; n     while (l <= r) { n       mid = (l + r) >> 1; n       if (mid * (mid - 1) / 2 + (n - mid) <= 2 * (n - mid)) n         l = mid + 1; n       else n         r = mid - 1; n     } n     res = max(res, min(l * (l - 1) / 2 + (n - l), 2 * (n - l))); n     res = max(res, min((l - 1) * (l - 2) / 2 + (n - l + 1), 2 * (n - l + 1))); n     printf( %lld n , res); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void err(istream_iterator<string> it) { cerr << endl; } n template <typename T, typename... Args> n void err(istream_iterator<string> it, T a, Args... args) { n   cerr << *it <<   =   << a <<  ,  ; n   err(++it, args...); n } n void solve() { n   int n, m; n   cin >> n >> m; n   vector<int> l(m), r(m); n   for (int i = 0; i < m; ++i) { n     cin >> l[i] >> r[i]; n   } n   for (int i = 0; i < n; ++i) cout << (i & 1); n   cout << endl; n } n int main(int argc, char* argv[]) { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long read() { n   char c = getchar(); n   if (c <  0  && c >  9  && c !=  - ) c = getchar(); n   long long f = 1, cnt = 0; n   if (c ==  - ) f = -1, c = getchar(); n   while (c >=  0  && c <=  9 ) { n     cnt = cnt * 10 + int(c -  0 ); n     c = getchar(); n   } n   return cnt * f; n } n const int MOD = 1e9 + 9; n struct Loc { n   Loc(int a, int b) { n     x = a; n     y = b; n   } n   int x; n   int y; n   bool operator<(const Loc &a) const { n     if (y == a.y) { n       return x < a.x; n     } n     return y < a.y; n   } n }; n map<Loc, int> table; n bool vis[100005]; n priority_queue<int> q1; n priority_queue<int, vector<int>, greater<int> > q2; n long long result = 0; n void add(int a, int m) { result = (result * m + a) % MOD; } n int xPos[100005]; n int yPos[100005]; n bool judge(int x, int y) { n   if (table.find(Loc(x, y + 1)) != table.end()) { n     if (table.find(Loc(x - 1, y)) == table.end() && n         table.find(Loc(x + 1, y)) == table.end()) { n       return false; n     } n   } n   if (table.find(Loc(x - 1, y + 1)) != table.end()) { n     if (table.find(Loc(x - 1, y)) == table.end() && n         table.find(Loc(x - 2, y)) == table.end()) { n       return false; n     } n   } n   if (table.find(Loc(x + 1, y + 1)) != table.end()) { n     if (table.find(Loc(x + 1, y)) == table.end() && n         table.find(Loc(x + 2, y)) == table.end()) { n       return false; n     } n   } n   return true; n } n int main() { n   int m; n   int x, y; n   m = read(); n   for (int i = 0; i < m; i++) { n     cin >> x >> y; n     xPos[i] = x; n     yPos[i] = y; n     table[Loc(x, y)] = i; n   } n   for (int i = 0; i < m; i++) { n     if (judge(xPos[i], yPos[i])) { n       q1.push(i); n       q2.push(i); n     } n   } n   memset(vis, false, sizeof(vis)); n   int top = 0; n   int count = 0; n   while (count < m) { n     if ((count & 1) == 0) { n       top = q1.top(); n     } else { n       top = q2.top(); n     } n     x = xPos[top]; n     y = yPos[top]; n     bool found = false; n     if (!vis[top] && judge(x, y)) { n       add(top, m); n       table.erase(Loc(x, y)); n       vis[top] = true; n       found = true; n     } n     if ((count & 1) == 0) { n       q1.pop(); n     } else { n       q2.pop(); n     } n     if (found) { n       count++; n       if (table.find(Loc(x, y - 1)) != table.end() && judge(x, y - 1)) { n         q1.push(table[Loc(x, y - 1)]); n         q2.push(table[Loc(x, y - 1)]); n       } n       if (table.find(Loc(x - 1, y - 1)) != table.end() && judge(x - 1, y - 1)) { n         q1.push(table[Loc(x - 1, y - 1)]); n         q2.push(table[Loc(x - 1, y - 1)]); n       } n       if (table.find(Loc(x + 1, y - 1)) != table.end() && judge(x + 1, y - 1)) { n         q1.push(table[Loc(x + 1, y - 1)]); n         q2.push(table[Loc(x + 1, y - 1)]); n       } n     } n   } n   printf( %d , result); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long q; n   cin >> q; n   while (q--) { n     long long n, m; n     cin >> n; n     cin >> m; n     if (m > n || m % 10 == 0) { n       cout << 0 <<   n ; n       continue; n     } n     long long p = (n / m) / 10; n     long long q = (n / m) % 10; n     long long sum = 0; n     if (m % 2 == 0) n       sum = p * (40LL); n     else if (m % 5 == 0) n       sum = p * (25LL); n     else n       sum = p * (45LL); n     long long num = 0; n     for (long long i = 1; i <= q; i++) { n       num += m; n       sum += (num % 10); n     } n     cout << sum <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:65777216 ) n using namespace std; n long long n, l, r, ql, qr, sum, ans, w[100005]; n long long koll, kolr, t; n using namespace std; n int main() { n   cin >> n >> l >> r >> ql >> qr; n   for (int i = 1; i <= n; i++) { n     cin >> w[i]; n     sum += w[i] * r; n   } n   ans = sum + qr * (n - 1); n   for (int i = 1; i <= n; i++) { n     sum += w[i] * l - w[i] * r; n     koll = i; n     kolr = n - i; n     if (koll > kolr) { n       ans = min(sum + (koll - kolr - 1) * ql, ans); n     } else if (koll < kolr) { n       ans = min(sum + (kolr - koll - 1) * qr, ans); n     } else if (koll == kolr) { n       ans = min(sum, ans); n     } n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n const double EPS = 1e-9; n const double PI = acos(-1.0); n const int MOD = 1000 * 1000 * 1000 + 7; n const int INF = 2000 * 1000 * 1000; n template <typename T> n inline T sqr(T n) { n   return n * n; n } n int C, Hr, Hb, Wr, Wb; n long long ans; n int main() { n   scanf( %d%d%d%d%d , &C, &Hr, &Hb, &Wr, &Wb); n   for (int x = 0; x < 10000000 && 1ll * x * Wr <= C; x++) { n     int y = (C - x * Wr) / Wb; n     ans = max(ans, 1ll * Hr * x + 1ll * Hb * y); n   } n   for (int y = 0; y < 10000000 && 1ll * y * Wb <= C; y++) { n     int x = (C - y * Wb) / Wr; n     ans = max(ans, 1ll * Hr * x + 1ll * Hb * y); n   } n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   cout << (n <= 2  ? n n            : n % 2 ? (long long)n * (n - 1) * (n - 2) n            : n % 3 ? (long long)n * (n - 1) * (n - 3) n                    : (long long)(n - 1) * (n - 2) * (n - 3)) n        <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma GCC optimize( Ofast ) n const int maxn = 1e5 + 10, N = 3e6, SQ = 1000, base = 800287, mod = 1e9 + 7, n           INF = 1e9 + 10, lg = 22; n const long double eps = 1e-4; n int n, m, q; n unordered_map<int, int> par[maxn], res[maxn]; n inline int root(int v, int x) { n   return (par[v][x] <= 0 ? v : par[v][x] = root(par[v][x], x)); n } n void merge(int v, int u, int x) { n   if ((v = root(v, x)) == (u = root(u, x))) { n     return; n   } n   par[u][x] = v; n } n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> m; n   for (int i = 0; i < m; ++i) { n     int x, y, z; n     cin >> x >> y >> z; n     merge(x, y, z); n   } n   cin >> q; n   while (q--) { n     int v, u; n     cin >> v >> u; n     int ans = 0; n     if ((int)par[v].size() < (int)par[u].size()) { n       swap(v, u); n     } n     if (res[v].find(u) != res[v].end()) { n       cout << res[v][u] <<   n ; n       continue; n     } n     for (auto i : par[u]) { n       if (par[v].find(i.first) == par[v].end()) { n         continue; n       } n       if (root(v, i.first) == root(u, i.first)) { n         ans++; n       } n     } n     res[v][u] = res[u][v] = ans; n     cout << ans <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long int power(long long int a, long long int b) { n   if (b == 0) return 1; n   long long int c = power(a, b >> 1); n   c = (c * c) % 1000000007; n   if (b & 1) return (a * c) % 1000000007; n   return c; n } n const int N = (int)1e5 + 5; n const int Q = 301; n int dp[N][10], num[N][10]; n string query[N]; n string s, temp; n void solve() { n   cin >> s; n   int q, p; n   cin >> q; n   for (int i = 0; i <= q - 1; i++) { n     cin >> temp; n     query[i] = temp; n   } n   for (int i = 0; i <= 9; i++) { n     dp[q][i] = i; n     num[q][i] = 1; n   } n   for (int i = q - 1; i >= 0; i--) { n     for (int j = 0; j <= 9; j++) { n       dp[i][j] = dp[i + 1][j]; n       num[i][j] = num[i + 1][j]; n     } n     p = query[i][0] -  0 ; n     temp = query[i].substr(3, query[i].size() - 3); n     long long int pos = 0; n     dp[i][p] = 0; n     for (int k = temp.size() - 1; k >= 0; k--) { n       dp[i][p] += (dp[i + 1][temp[k] -  0 ] * power(10, pos)) % 1000000007; n       if (dp[i][p] >= 1000000007) dp[i][p] -= 1000000007; n       pos += num[i][temp[k] -  0 ]; n       pos %= (1000000007 - 1); n     } n     num[i][p] = pos; n   } n   int ans = 0; n   int pos = 0; n   for (int i = s.size() - 1; i >= 0; i--) { n     ans += (dp[0][s[i] -  0 ] * power(10, pos)) % 1000000007; n     if (ans >= 1000000007) ans -= 1000000007; n     pos += num[0][s[i] -  0 ]; n     pos %= (1000000007 - 1); n   } n   cout << ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int T = 1; n   for (int TC = 1; TC <= T; TC++) { n     solve(); n     cout <<   n ; n   } n } n