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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


#include <bits/stdc++.h> n using namespace std; n long long dx[] = {1, 0, -1, 0}; n long long dy[] = {0, 1, 0, -1}; n long long gcd(long long x, long long y) { n   if (y == 0) n     return x; n   else n     return gcd(y, x % y); n } n long long expo(long long n, long long m, long long p) { n   long long r = 1; n   n = n % p; n   while (m > 0) { n     if (m % 2) r = (r * n) % p; n     n = (n * n) % p; n     m = m / 2; n   } n   return r % p; n } n bool isPrime(long long n) { n   if (n <= 1) return false; n   if (n <= 3) return true; n   if (n % 2 == 0 || n % 3 == 0) return false; n   for (long long i = 5; i * i <= n; i = i + 6) n     if (n % i == 0 || n % (i + 2) == 0) return false; n   return true; n } n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   long long n; n   cin >> n; n   map<double, long long> p; n   vector<string> v(n); n   for (long long j = 0; j < n; j++) { n     string s; n     cin >> s; n     v[j] = s; n     long long a = 0, b = 0, c = 0; n     long long i = 1; n     while (s[i] !=  + ) { n       a = a * 10 + s[i] -  0 ; n       i++; n     } n     i++; n     while (s[i] !=  ) ) { n       b = b * 10 + s[i] -  0 ; n       i++; n     } n     i++; n     i++; n     while (i != s.size()) { n       c = c * 10 + s[i] -  0 ; n       i++; n     } n     double aa = (a * 1.0 + b) / c; n     p[aa]++; n   } n   for (long long j = 0; j < n; j++) { n     string s = v[j]; n     long long a = 0, b = 0, c = 0; n     long long i = 1; n     while (s[i] !=  + ) { n       a = a * 10 + s[i] -  0 ; n       i++; n     } n     i++; n     while (s[i] !=  ) ) { n       b = b * 10 + s[i] -  0 ; n       i++; n     } n     i++; n     i++; n     while (i != s.size()) { n       c = c * 10 + s[i] -  0 ; n       i++; n     } n     double aa = (a * 1.0 + b) / c; n     cout << p[aa] <<    ; n   } n   cout <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n   n mt19937_64 rng(time(0)); n const long double eps = 1e-15; n #define rep(i, a, b) for(int i = a; i < (b); ++i) n #define trav(a, x) for(auto& a : x) n #define all(x) x.begin(), x.end() n #define sz(x) (int)(x).size() n typedef long long ll; n typedef pair<int, int> pii; n typedef pair<ll,ll> pll; n typedef vector<int> vi; n const int mn=300+10; n const ll mod=1e9+7; n  n ll po(ll a,ll b=mod-2){ n  ll ans=1; n  for(;b;b>>=1,a*=a,a%=mod)if(b&1)ans*=a,ans%=mod; n  return ans; n } n  n ll c[mn],b[mn]; n ll ans[mn*2]; n ll dp[2][10100]; n  n int main() { n  cin.tie(0); n  cin.sync_with_stdio(0); n  int n; n  cin>>n; n  for(int i=0;i<n;i++)cin>>c[i]; n  for(int i=1;i<n;i++)cin>>b[i],b[i]+=b[i-1]; n  for(int i=1;i<n;i++)b[i]+=b[i-1]; n  int ma=INT_MAX,mi=INT_MAX,sa=0,si=0; n  for(int i=0;i<n;i++){ n   sa+=c[i]; n   si+=0; n   ma=min(ll(ma),(sa-b[i])/(i+1)+1); n   mi=min(ll(mi),(si-b[i])/(i+1)-1); n  } n  //cerr<<mi<<   <<ma<<endl; n   n  for(int m=mi;m<=ma;m++){ n   memset(dp,0,sizeof(dp)); n   dp[0][0]=1; n   for(int i=0;i<n;i++){ n    ll lim = m*(i+1)+b[i]; n    //cerr<<lim<<endl; n    for(int j=1;j<10100;j++)dp[0][j]+=dp[0][j-1],dp[0][j]%=mod; n    for(int j=0;j<10100;j++){ n     dp[1][j]=(dp[0][j]-((j>=c[i]+1)?dp[0][j-c[i]-1]:0))%mod; n    } n    for(int j=0;j<min(lim,ll(10100));j++)dp[1][j]=0; n    memcpy(dp[0],dp[1],sizeof(dp[0])); n    memset(dp[1],0,sizeof(dp[1])); n   } n   for(int i=0;i<10100;i++)ans[m-mi]+=dp[0][i],ans[m-mi]%=mod; n   if(ans[m-mi]<0)ans[m-mi]+=mod; n  } n  int q; n  cin>>q; n  ll aa=1; n  for(int i=0;i<n;i++)aa*=c[i]+1,aa%=mod; n  for(int i=0;i<q;i++){ n   ll x; n   cin>>x; n   if(x<mi){ n    printf( %lld n ,aa); n   } n   else if(x>ma)printf( 0 n ); n   else printf( %lld n ,ans[x-mi]); n  } n } n


#include <bits/stdc++.h> n using namespace std; n int n, k; n int main() { n   long long s = 0; n   cin >> n >> k; n   for (int i = 0; i < n; i++) { n     int a, b; n     cin >> a >> b; n     s += b - a + 1; n   } n   s %= k; n   if (s) s = k - s; n   cout << s << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1e9 + 9; n const int MAXN = 3e5 + 1; n int l[MAXN], r[MAXN]; n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     vector<int> v(n); n     for (int i = (int)(0); i < (int)(n); ++i) { n       l[i] = INF; n       r[i] = -INF; n     } n     for (int i = (int)(0); i < (int)(n); ++i) { n       cin >> v[i]; n       --v[i]; n       l[v[i]] = min(l[v[i]], i); n       r[v[i]] = max(r[v[i]], i); n     } n     sort(v.begin(), v.end()); n     v.erase(unique(v.begin(), v.end()), v.end()); n     vector<int> dp(n, 0); n     int ans = n; n     for (int i = 0; i < v.size(); ++i) { n       if (!i || l[v[i]] <= r[v[i - 1]]) n         dp[i] = 1; n       else n         dp[i] = dp[i - 1] + 1; n       ans = min(ans, (int)(v.size() - dp[i])); n     } n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n  n #define ed end() n #define bg begin() n #define mp make_pair n #define pb push_back n #define vv(T) v(v(T)) n #define v(T) vector<T> n #define all(x) x.bg,x.ed n #define newline puts(  ) n #define si(x) ((int)x.size()) n #define rep(i,n) for(int i=1;i<=n;++i) n #define rrep(i,n) for(int i=0;i<n;++i) n #define srep(i,s,t) for(int i=s;i<=t;++i) n #define drep(i,s,t) for(int i=t;i>=s;--i) n  n #define DEBUG n #define d1(x) std::cout << #x   =   << (x) << std::endl n #define d2(x, y) std::cout << #x   =   << (x) <<   ,  #y   =   << (y) << std::endl n #define disp(arry, fr, to)   n     {   n         std::cout << #arry   :  ;   n         for(int _i = fr; _i <= to; _i++) std::cout << arry[_i] <<    ;   n         std::cout << std::endl;   n     } n  n using namespace std; n typedef long long ll; n typedef pair<int,int> pii; n const int Maxn = 2e5+10; n const int Inf = 0x7f7f7f7f; n const ll Inf_ll = 1ll*Inf*Inf; n const int Mod = 1e9+7; n const double eps = 1e-7; n  n int n, a[Maxn], tol; n ll Sum, sum[Maxn], s[Maxn]; n  n int calc(int l, int r, ll x){ n     // if( l > r )  return 0; n     int ll = l, rr = r, ans = l-1; n     while( ll <= rr ) n     { n         int mid = (ll+rr) >> 1; n         if( s[mid] - s[l-1] <= x )  ll = mid+1, ans = mid; n         else rr = mid-1; n     } n     // printf( l = %d, r = %d, x = %lld, ans = %d n , l, r, x, ans-l+1 + (x>=0)); n     return ans-l+1 + (x>=0); n } n  n ll work(){ n     tol = 0; n     ll ans = 0, las = 0; n     for(int i=1;i<=n;i+=2) n     {    n         s[++tol] = las + a[i]; n         las += a[i]; n     } n     for(int i=1,j=1;i<=n;i+=2,j++) n     { n         if( n&1 ) n         { n             ll tmp = (Sum-1)/2 - sum[i]; n             ans += calc(j+1, tol-1, tmp); n             if( i+1 < n ) n                 ans += calc(j+1, tol-1, tmp-a[n]); n             if( i != 1 ) n             { n                 ans += calc(j+1, tol-1, tmp+a[1]); n                 if( i+1 < n ) n                     ans += calc(j+1, tol-1, tmp-a[n]+a[1]); n             } n         } n         else  n         { n             ll tmp = (Sum-1)/2 - sum[i]; n             ans += calc(j+1, tol, tmp); n             if( i+1 < n ) n                 ans += calc(j+1, tol-1, tmp-a[n]); n             if( i != 1 ) n             { n                 ans += calc(j+1, tol, tmp+a[1]); n                 if( i+1 < n ) n                     ans += calc(j+1, tol-1, tmp-a[n]+a[1]); n             } n         } n         // d2(i, ans); n     } n     las = tol = 0; n  n     for(int i=2;i<=n;i+=2) n     { n         s[++tol] = las + a[i]; n         las += a[i]; n     } n     for(int i=2,j=1;i<=n;i+=2,j++) n     { n         if( n&1 ) n         { n             ll tmp = (Sum-1)/2 - sum[i]; n             ans += calc(j+1, tol, tmp); n             if( i+1 < n ) n                 ans += calc(j+1, tol-1, tmp-a[n]); n             if( i != 1 ) n             { n                 ans += calc(j+1, tol, tmp+a[1]); n                 if( i+1 < n ) n                     ans += calc(j+1, tol-1, tmp-a[n]+a[1]); n             } n         } n         else  n         { n             ll tmp = (Sum-1)/2 - sum[i]; n             ans += calc(j+1, tol-1, tmp); n             if( i+1 < n ) n                 ans += calc(j+1, tol-1, tmp-a[n]); n             if( i != 1 ) n             { n                 ans += calc(j+1, tol-1, tmp+a[1]); n                 if( i+1 < n ) n                     ans += calc(j+1, tol-1, tmp-a[n]+a[1]); n             } n         } n         // d2(i, ans); n     } n     las = 0; n     for(int i=n;i>=3;i--) n     { n         las += a[i]; n         if( las*2 >= Sum )  break; n         ans++; n     } n     return ans + 1; n } n  n void solve(){ n     scanf( %d ,&n); n     Sum = 0; n     for(int i=1;i<=n;i++) n     { n         scanf( %d ,&a[i]); n         Sum += a[i]; n         sum[i] = sum[i-1] + a[i]; n     } n     printf( %lld n , work()%998244353); n }    n  n int main(){ n     int T; n     scanf( %d ,&T); n     for(int _=1;_<=T;_++) n     { n         solve(); n     } n     return 0; n }


#include<iostream> n #include<map> n #include<cstring> n #include<cmath> n #include<algorithm> n #include <queue> n #include<map> n using namespace std; n typedef long long ll; n inline ll gcd(ll a,ll b) { n     return b>0 ? gcd(b,a%b):a; n } n int main() n { n  ll T,m1,m,k,a,b; n  cin>>T; n  while(T--){ n   int a[30]={0},n; n   cin>>n; n   string str; n   cin>>str; n   int num=-1,f=1; n   for(int i=0;i<str.length();i++){ n    int tmp=str[i]- A ; n    if(tmp!=num) n    { n     if(a[tmp]) n     f=0; n     else n     { n      num=tmp; n      a[tmp]++; n     }  n    } n   } n   if(f) n   cout<< YES n ; n   else n   cout<< NO n ; n  } n  } n  n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, a, b, c, ans[4010]; n   scanf( %d %d %d %d , &n, &a, &b, &c); n   memset(ans, -1, sizeof(ans)); n   ans[0] = 0; n   for (int i = 0; i <= n; i++) { n     if (i >= a && ans[i - a] != -1) ans[i] = ans[i - a] + 1; n     if (i >= b && ans[i - b] != -1) ans[i] = max(ans[i], ans[i - b] + 1); n     if (i >= c && ans[i - c] != -1) ans[i] = max(ans[i], ans[i - c] + 1); n   } n   printf( %d n , ans[n]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int M = 1e18 + 7; n const long long int mod = 1e9 + 7; n const long long int infi = LLONG_MAX; n long long int i, j, ans, k, n, x, y, m, mymax = LLONG_MIN, mymin = LLONG_MAX, b, n                                         c, z, sum; n int main() { n   long long int x1, x2, s, p, t1, t2, d; n   scanf( %lld %lld %lld , &s, &x1, &x2); n   scanf( %lld %lld , &t1, &t2); n   scanf( %lld %lld , &p, &d); n   if (x2 < x1) { n     ans = (x1 - x2) * t2; n     if (d == 1) { n       if (p <= x2) { n         ans = min(ans, (2 * s - x2 - p) * t1); n       } else if (p > x2 && p <= x1) { n         ans = min(ans, (2 * s - x2 - p) * t1); n       } else { n         ans = min(ans, (2 * s - p - x2) * t1); n       } n     } else { n       if (p < x2) { n         ans = min(ans, (2 * s - x2 + p) * t1); n       } else if (p >= x2 && p < x1) { n         ans = min(ans, (2 * s - x2 + p) * t1); n       } else { n         ans = min(ans, (p - x2) * t1); n       } n     } n     printf( %lld n , ans); n     return 0; n   } n   ans = (x2 - x1) * t2; n   if (d == 1) { n     if (p <= x1) { n       ans = min(ans, (x2 - p) * t1); n     } else if (p > x1 && p <= x2) { n       ans = min(ans, (2 * s + x2 - p) * t1); n     } else { n       ans = min(ans, (2 * s - p + x2) * t1); n     } n   } else { n     if (p < min(x1, x2)) { n       ans = min(ans, (x2 + p) * t1); n     } else if (p >= x1 && p <= x2) { n       ans = min(ans, (p + x2) * t1); n     } else { n       ans = min(ans, (p + x2) * t1); n     } n   } n   printf( %lld n , ans); n   return 0; n } n


#include <iostream> n #include <algorithm> n #include <vector> n #include <string> n #include <set> n // #include <stdlib.h> n // #include <stdio.h> n // #include <ctype.h> n  n using namespace std; n  n int main(void){ n  n     int n = 0; n     cin >> n; n     for(; n > 0; n--){ n         int num; n         cin >> num; n         int input, last = -1; n         int count = 1, max = 1; n         if(num == 0){ n             cout <<  0  << endl; n             continue; n         } n         for(; num > 0; num--){ n             cin >> input; n             if(input == last){ n                 count++; n                 if(count > max){ n                     max = count; n                 } n             } n             else{ n                 count = 1; n             } n             last = input; n         } n         cout << max << endl; n          n  n     } n  n  n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n  n int MOD; n struct modint { n  n private: n  n     int v; n  n     static int minv(int a, int m) { n         a %= m; n         assert(a); n         return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a); n     } n  n public: n  n     modint() : v(0) {} n     modint(ll v_) : v(int(v_ % MOD)) { if (v < 0) v += MOD; } n     explicit operator int() const { return v; } n     friend std::ostream& operator << (std::ostream& out, const modint& n) { return out << int(n); } n     friend std::istream& operator >> (std::istream& in, modint& n) { ll v_; in >> v_; n = modint(v_); return in; } n  n     friend bool operator == (const modint& a, const modint& b) { return a.v == b.v; } n     friend bool operator != (const modint& a, const modint& b) { return a.v != b.v; } n  n     modint inv() const { n         modint res; n         res.v = minv(v, MOD); n         return res; n     } n     friend modint inv(const modint& m) { return m.inv(); } n     modint neg() const { n         modint res; n         res.v = v ? MOD-v : 0; n         return res; n     } n     friend modint neg(const modint& m) { return m.neg(); } n  n     modint operator- () const { n         return neg(); n     } n     modint operator+ () const { n         return modint(*this); n     } n  n     modint& operator ++ () { n         v ++; n         if (v == MOD) v = 0; n         return *this; n     } n     modint& operator -- () { n         if (v == 0) v = MOD; n         v --; n         return *this; n     } n     modint& operator += (const modint& o) { n         v += o.v; n         if (v >= MOD) v -= MOD; n         return *this; n     } n     modint& operator -= (const modint& o) { n         v -= o.v; n         if (v < 0) v += MOD; n         return *this; n     } n     modint& operator *= (const modint& o) { n         v = int(ll(v) * ll(o.v) % MOD); n         return *this; n     } n     modint& operator /= (const modint& o) { n         return *this *= o.inv(); n     } n  n     friend modint operator ++ (modint& a, int) { modint r = a; ++a; return r; } n     friend modint operator -- (modint& a, int) { modint r = a; --a; return r; } n     friend modint operator + (const modint& a, const modint& b) { return modint(a) += b; } n     friend modint operator - (const modint& a, const modint& b) { return modint(a) -= b; } n     friend modint operator * (const modint& a, const modint& b) { return modint(a) *= b; } n     friend modint operator / (const modint& a, const modint& b) { return modint(a) /= b; } n }; n namespace IO { n     template<class T> n     void _R(T &x) { cin >> x; } n     void _R(int &x) { scanf( %d , &x); } n     void _R(ll &x) { scanf( %lld , &x); } n     void _R(double &x) { scanf( %lf , &x); } n     void _R(char &x) { x = getchar(); } n     void _R(char *x) { scanf( %s , x); } n     void R() {} n     template<class T, class... U> n     void R(T &head, U &... tail) { _R(head), R(tail...); } n     template<class T> n     void _W(const T &x) { cout << x; } n     void _W(const int &x) { printf( %d , x); } n     void _W(const ll &x) { printf( %lld , x); } n     void _W(const double &x) { printf( %.16f , x); } n     void _W(const char &x) { putchar(x); } n     void _W(const char *x) { printf( %s , x); } n     template<class T, class U> n     void _W(const pair<T, U> &x) { _W(x.first), putchar(   ), _W(x.second); } n     template<class T> n     void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(   ); } n     void W() {} n     template<class T, class... U> n     void W(const T &head, const U &... tail) { _W(head), putchar(sizeof...(tail) ?     :   n ), W(tail...); } n } n using namespace IO; n template <typename T> T pow(T a, long long b) { n     assert(b >= 0); n     T r = 1; while (b) { if (b & 1) r *= a; b >>= 1; a *= a; } return r; n } n  n const int maxn = 2e5+50; n const int maxp = maxn*32+5; n const int K = 20; n const int M = 1 << K; n int ls[maxp], rs[maxp], tot; n // 0, 1, cnt, XOR n int t0[maxp], t1[maxp], p[maxp], txor[maxp], tor[maxp]; n  n inline void pushup(int x) { n     p[x] = p[ls[x]] + p[rs[x]]; n     t0[x] = t0[ls[x]] | t0[rs[x]]; n     t1[x] = t1[ls[x]] | t1[rs[x]]; n } n inline void XOR(int x, int t) { n     if (!x) return; n     txor[x] ^= t; n     if (~tor[x] && t >> tor[x] & 1) swap(ls[x], rs[x]); n     int a = (t0[x] & (~t)) | (t1[x] & t), b = (t1[x] & (~t)) | (t0[x] & t); n     t0[x] = a, t1[x] = b; n } n inline void pushdown(int x) { n     if (txor[x]) { n         XOR(ls[x], txor[x]), XOR(rs[x], txor[x]); n         txor[x] = 0; n     } n } n inline void insert(int &x, int s, int k) { n     if (!x) x = ++tot; n     tor[x] = k; n     if (k == -1) { n         t1[x] = s, t0[x] = s ^ (M - 1); n         p[x] = 1; n         return; n     } n     insert((s >> k & 1) ? rs[x] : ls[x], s, k - 1); n     pushup(x); n } n inline void split(int &x, int &y, int l, int r, int le, int re) { n     if (!x || re < l || le > r) { n         y = 0; n         return; n     } n     if (le <= l && r <= re) { n         y = x; n         x = 0; n         return; n     } n     int mid = l + r >> 1; pushdown(x); n     tor[y = ++tot] = tor[x]; n     split(ls[x], ls[y], l, mid, le, re); n     split(rs[x], rs[y], mid + 1, r, le, re); n     pushup(x), pushup(y); n } n inline void merge(int &x, int y) { n     if (!x || !y) { n         x = x | y; n         return; n     } n     pushdown(x), pushdown(y); n     merge(ls[x], ls[y]), merge(rs[x], rs[y]); n     if (~tor[x]) pushup(x); n } n inline void OR(int x, int s) { n     if (!x) return; n     if (!(s & t0[x] & t1[x])) { n         XOR(x, s & t0[x]); n         return; n     } n     pushdown(x); n     if (s >> tor[x] & 1) XOR(ls[x], 1 << tor[x]), merge(rs[x], ls[x]), ls[x] = 0; n     OR(ls[x], s), OR(rs[x], s); n     pushup(x); n } n  n int main() { n     int n, q, x = 0; n     R(n, q); n     for (int i = 1; i <= n; ++i) { n         int v; R(v); insert(x, v, K - 1); n     } n     for (; q; --q) { n         int oth; n         int t, l, r, v; R(t, l, r); n         split(x, oth, 0, M - 1, l, r); n         if (t == 1) R(v),XOR(oth, M - 1),OR(oth, v ^ (M - 1)),XOR(oth, M - 1); n         else if (t == 2) R(v),OR(oth, v); n         else if (t == 3) R(v), XOR(oth, v); n         else W(p[oth]); n         merge(x, oth); n     } n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n const int maxN = 20; n const int maxn = (1 << maxN) + 20; n int t[maxn], r[maxn][maxN + 3], x[maxn][maxN + 3]; n string s[maxN]; n void cal(int n, int k) { n   if (!n) return; n   cal(n - 1, k); n   cal(n - 1, k + (1 << (n - 1))); n   for (int i = 0; i < (1 << n); i++) n     for (int j = 0; j <= n; j++) x[k + i][j] = r[k + i][j]; n   for (int i = 0; i < (1 << (n - 1)); i++) n     for (int j = 1; j <= n; j++) { n       r[k + i][j] += x[k + i + (1 << (n - 1))][j - 1]; n       r[k + i + (1 << (n - 1))][j] += x[k + i][j - 1]; n     } n } n int main() { n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < n; i++) cin >> s[i]; n   for (int i = 0; i < m; i++) { n     for (int j = 0; j < n; j++) t[i] = (t[i] * 2 + (s[j][i] ==  1 )); n     r[t[i]][0]++; n   } n   cal(n, 0); n   int ans = 1e9; n   for (int mask = 0; mask < (1 << n); mask++) { n     int res = 0; n     for (int j = 0; j <= n; j++) res += r[mask][j] * min(j, n - j); n     ans = min(ans, res); n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main(void) { n   int n, bar; n   vector<int> choco; n   cin >> n; n   for (int i = 0; i < n; ++i) { n     cin >> bar; n     choco.push_back(bar); n   } n   if (n == 1) n     cout <<  1 0 n ; n   else { n     auto l = choco.begin(); n     auto r = choco.end() - 1; n     int diff = 0; n     int l_count = 0; n     int r_count = 0; n     while (true) { n       if ((l + 1) == r) { n         ++l_count; n         ++r_count; n         break; n       } n       diff = (*l) - (*r); n       if (diff < 0) { n         (*r) -= (*l); n         ++l_count; n         ++l; n       } else if (diff > 0) { n         (*l) -= (*r); n         ++r_count; n         --r; n       } else { n         ++l_count; n         (*l) = 0; n         if ((l + 2) == r) n           ++l; n         else { n           ++r_count; n           (*r) = 0; n           ++l; n           --r; n         } n       } n     } n     cout << l_count <<     << r_count <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int oo = 0x3f3f3f3f; n int f[1 << 23], pre[1 << 23], zt[1 << 23], tot, ans[23]; n int n, fn[23], fri[23][23]; n int tans[23], Ans[23][23]; n void Solve(int o) { n   int ni, st = 1 << (o - 1), ed = (1 << n) - 1; n   for (int i = (1); i <= (int)(fn[o]); ++i) st |= 1 << (fri[o][i] - 1); n   memset(f, oo, sizeof(f)); n   f[st] = 1; n   for (int i = (st); i <= (int)(ed); ++i) { n     if (f[i] == oo) continue; n     for (int j = (1); j <= (int)(n); ++j) n       if (i & (1 << (j - 1))) { n         ni = i; n         for (int k = (1); k <= (int)(fn[j]); ++k) ni |= 1 << (fri[j][k] - 1); n         if (f[ni] > f[i] + 1) { n           f[ni] = f[i] + 1; n           pre[ni] = i; n           zt[ni] = j; n         } n       } n   } n   int now = ed, tp = 0; n   while (now != st) { n     ans[++tp] = zt[now]; n     now = pre[now]; n   } n   Ans[o][tans[o] = 1] = o; n   while (tp) Ans[o][++tans[o]] = ans[tp--]; n } n int main() { n   int m, u, v; n   scanf( %d%d , &n, &m); n   if (m == n * (n - 1) / 2) { n     puts( 0 ); n     puts(  ); n     return 0; n   } n   int mx = 0; n   for (int i = (1); i <= (int)(m); ++i) { n     scanf( %d%d , &u, &v); n     fri[u][++fn[u]] = v; n     fri[v][++fn[v]] = u; n     mx = max(mx, max(fn[u], fn[v])); n   } n   int mn = n + 1, id; n   for (int i = (1); i <= (int)(n); ++i) { n     Solve(i); n     if (fn[i] < mx - 6) continue; n     if (tans[i] < mn) mn = tans[i], id = i; n   } n   printf( %d n , tans[id]); n   for (int i = (1); i <= (int)(tans[id]); ++i) n     printf( %d%c , Ans[id][i], i == tans[id] ?   n  :    ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int n, m, q; n long long int gcd(long long int t, long long int u) { n   if (u == 0) { n     return t; n   } n   return gcd(u, t % u); n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> n >> m >> q; n   long long int gcd_nm = gcd(n, m); n   long long int a, b; n   a = n / gcd_nm; n   b = m / gcd_nm; n   for (int i = 1; i <= q; i++) { n     long long int sx, sy, ex, ey; n     cin >> sx >> sy >> ex >> ey; n     sy--; n     ey--; n     if (sx == 1) { n       sy /= a; n     } else { n       sy /= b; n     } n     if (ex == 1) { n       ey /= a; n     } else { n       ey /= b; n     } n     if (sy == ey) { n       cout <<  YES  << endl; n     } else { n       cout <<  NO  << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int a, b, r; n   scanf( %d %d %d , &a, &b, &r); n   r *= 2; n   if (r > a || r > b) { n     printf( Second n ); n     return 0; n   } n   printf( First n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int sz = 105; n long long int r[sz], a[sz][sz], b[sz][sz], ans[sz][sz], m; n void multiply(long long int a[][sz], long long int b[][sz]) { n   for (int i = 0; i < m; i++) { n     for (int j = 0; j < m; j++) { n       ans[i][j] = 0; n       for (int k = 0; k < m; k++) { n         ans[i][j] += a[i][k] * b[k][j] % 1000000007; n         ans[i][j] %= 1000000007; n       } n     } n   } n   for (int i = 0; i < m; i++) { n     for (int j = 0; j < m; j++) { n       a[i][j] = ans[i][j]; n     } n   } n } n void power(long long int a[][sz], long long int n) { n   if (n <= 1) { n     return; n   } n   power(a, n / 2); n   multiply(a, a); n   if (n % 2 == 1) { n     multiply(a, b); n   } n } n int main() { n   long long int n; n   cin >> n >> m; n   r[0] = 1; n   for (int i = 1; i <= m; i++) { n     r[i] = r[i - 1]; n     if (i - m >= 0) { n       r[i] += r[i - m]; n     } n     r[i] %= 1000000007; n   } n   for (int i = 1; i < m; i++) { n     a[i][i - 1] = b[i][i - 1] = 1; n   } n   a[0][m - 1] = b[0][m - 1] = 1; n   a[m - 1][m - 1] = b[m - 1][m - 1] = 1; n   power(a, n); n   long long int res = 0; n   for (int k = 0; k < m; k++) { n     res += r[k] * a[k][0] % 1000000007; n     res %= 1000000007; n   } n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long modexpo(long long x, long long p) { n   long long res = 1; n   x = x % 1000000007; n   while (p) { n     if (p % 2) res = res * x; n     p >>= 1; n     x = x * x % 1000000007; n     res %= 1000000007; n   } n   return res; n } n long long max(long long a, long long b) { return (a > b ? a : b); } n long long min(long long a, long long b) { return (a < b ? a : b); } n struct edge { n   long long u, v, w; n   edge(long long a, long long b, long long c) { n     u = a; n     v = b; n     w = c; n   } n }; n struct compare { n   bool operator()(const edge a, const edge b) const { n     if (a.u == b.u) { n       if (a.v == b.v) { n         return a.w < b.w; n       } n       return a.v < b.v; n     } n     return a.u < b.u; n   } n }; n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long t; n   cin >> t; n   while (t--) { n     long long l, r, d; n     cin >> l >> r >> d; n     if (d < l) { n       cout << d <<   n ; n     } else if (r % d == 0) { n       cout << r + d <<   n ; n     } else { n       long long x = ceil((long double)r / (long double)d); n       cout << x * d <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1000000007; n int Comb[2015][2015], Fact[2015], used[2015], a[2015]; n int main() { n   cin.sync_with_stdio(false); n   int n, m = 0, k = 0; n   cin >> n; n   for (int i = 1; i <= n; ++i) { n     cin >> a[i]; n     if (a[i] != -1) used[a[i]] = 1; n   } n   Fact[0] = 1; n   for (int i = 1; i <= n; ++i) { n     if (used[i] == 0) { n       ++m; n       if (a[i] == -1) ++k; n     } n     Fact[i] = 1LL * Fact[i - 1] * i % MOD; n   } n   for (int i = 0; i <= n; ++i) { n     Comb[i][0] = 1; n     for (int j = 1; j <= i; ++j) n       Comb[i][j] = (Comb[i - 1][j] + Comb[i - 1][j - 1]) % MOD; n   } n   int sol = 0; n   for (int i = 1; i <= k; ++i) { n     int x = (1LL * Comb[k][i] * Fact[m - i]) % MOD; n     if (i & 1) n       sol = (sol + x) % MOD; n     else n       sol = (0LL + sol + MOD - x) % MOD; n   } n   cout << (0LL + Fact[m] + MOD - sol) % MOD; n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n constexpr long double pi{3.1415926535897932384}; n constexpr long long mod{1000000007}; n long long power(long long x, long long y) { n   long long res = 1; n   x = x % mod; n   while (y > 0) { n     if (y & 1) res = (res * x) % mod; n     y = y >> 1; n     x = (x * x) % mod; n   } n   return res; n } n long long gcd(long long a, long long b) { n   if (a == 0) return b; n   return gcd(b % a, a); n } n long long lcm(long long a, long long b) { return (a / gcd(a, b) * b); } n pair<long long, long long> v[3001]; n long long n, dp[3001][3001]; n const long long INF = 1000000000000000; n long long getAns(long long pos, long long pre) { n   if (pos > n) return 0; n   if (dp[pos][pre] != -INF) return dp[pos][pre]; n   long long x = v[pos].second + getAns(pos + 1, pos); n   long long y = v[pos].first - v[pre].first + getAns(pos + 1, pre); n   return dp[pos][pre] = min(x, y); n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   cin >> n; n   for (long long i = 1; i <= n; i++) { n     cin >> v[i].first >> v[i].second; n   } n   sort(v + 1, v + n + 1); n   for (long long i = 0; i <= n; i++) { n     for (long long j = 0; j <= n; j++) { n       dp[i][j] = -INF; n     } n   } n   long long ans = getAns(2, 1) + v[1].second; n   cout << ans <<   n ; n   return 0; n } n


n #include<bits/stdc++.h> n using namespace std; n #define ll long long n #define endl   n  n const unsigned int mod = 1000000007; n  n  n  n  n int main(){ n  n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n  n   bool prime[1000001];  n memset(prime, true, sizeof(prime));  n    n for(int p=2; p*p<=1000000; p++) {  n         // If prime[p] is not changed, then it is a prime  n         if (prime[p] == true)  n         {    n             for (int i=p*p; i<=1000000; i += p)  n                 prime[i] = false;  n         }  n } n  n  n   ll t; n   cin>>t; n   while(t--){ n     int a; n     cin>>a; n     int ans = 1; n     for(int i=a+1;i<1000001;i++){ n       if (prime[i]){ n         ans*=i;break; n       } n     } n     for(int i=ans+a;i<1000001;i++){ n       if (prime[i]){ n         ans*=i;break; n       } n     } n     cout<<ans<<endl; n   } n  n  n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n void print_container(ostream& os, const T& c) { n   const char* _s =    ; n   if (!c.empty()) { n     __typeof__(c.begin()) last = --c.end(); n     for (__typeof__((c).begin()) it = (c).begin(); it != (c).end(); ++it) { n       os << *it; n       if (it != last) os << _s; n     } n   } n } n template <typename T> n ostream& operator<<(ostream& os, const vector<T>& c) { n   print_container(os, c); n   return os; n } n template <typename T> n ostream& operator<<(ostream& os, const set<T>& c) { n   print_container(os, c); n   return os; n } n template <typename T> n ostream& operator<<(ostream& os, const multiset<T>& c) { n   print_container(os, c); n   return os; n } n template <typename T> n ostream& operator<<(ostream& os, const deque<T>& c) { n   print_container(os, c); n   return os; n } n template <typename T, typename U> n ostream& operator<<(ostream& os, const map<T, U>& c) { n   print_container(os, c); n   return os; n } n template <typename T, typename U> n ostream& operator<<(ostream& os, const pair<T, U>& p) { n   os <<  (  << p.first <<  ,   << p.second <<  ) ; n   return os; n } n template <typename T> n void print(T a, int n, const string& split =    ) { n   for (int i = 0; i < n; i++) { n     cout << a[i]; n     if (i + 1 != n) cout << split; n   } n   cout << endl; n } n template <typename T> n void print2d(T a, int w, int h, int width = -1, int br = 0) { n   for (int i = 0; i < h; ++i) { n     for (int j = 0; j < w; ++j) { n       if (width != -1) cout.width(width); n       cout << a[i][j] <<    ; n     } n     cout << endl; n   } n   while (br--) cout << endl; n } n template <typename T> n void input(T& a, int n) { n   for (int i = 0; i < n; ++i) cin >> a[i]; n } n template <typename T, typename U> n void upmin(T& a, const U& b) { n   a = min<T>(a, b); n } n template <typename T, typename U> n void upmax(T& a, const U& b) { n   a = max<T>(a, b); n } n template <typename T> n void uniq(T& a) { n   sort(a.begin(), a.end()); n   a.erase(unique(a.begin(), a.end()), a.end()); n } n template <class T> n string to_s(const T& a) { n   ostringstream os; n   os << a; n   return os.str(); n } n template <class T> n T to_T(const string& s) { n   istringstream is(s); n   T res; n   is >> res; n   return res; n } n void fast_io() { n   cin.tie(0); n   ios::sync_with_stdio(false); n } n bool in_rect(int x, int y, int w, int h) { n   return 0 <= x && x < w && 0 <= y && y < h; n } n const int dx[] = {0, 1, 0, -1}; n const int dy[] = {1, 0, -1, 0}; n int main() { n   int n; n   cin >> n; n   int c[6666] = {}; n   for (int i = 0; i < (int)(n); ++i) { n     int a; n     cin >> a; n     ++c[a]; n   } n   int res = 0; n   for (int i = 0; i < (int)(6600); ++i) { n     if (c[i] > 1) { n       res += c[i] - 1; n       c[i + 1] += c[i] - 1; n     } n   } n   cout << res << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1e9 + 7; n const int N = 200500; n void solve() { n   long long n, k; n   cin >> n >> k; n   if ((n + k) % 2 == 0 && n >= k && (n + k) / 2 >= (k * (k + 1)) / 2) { n     cout <<  YES n ; n   } else n     cout <<  NO n ; n } n int main() { n   ios::sync_with_stdio(false); n   int q = 1; n   cin >> q; n   for (int i = 1; i <= q; i++) { n     solve(); n   } n } n


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


#include <bits/stdc++.h> n using namespace std; n int n, t, m[2]; n const int N = 2100000; n const int inf = 1e9 + 7; n int a[2][N], x[N]; n int dp[2][N]; n bool b[2][N], pr[2][N]; n set<int> H[2]; n int main() { n   cin >> n >> m[0] >> m[1] >> t; n   int xn = 0; n   x[xn++] = 0; n   for (int j = 0; j < 2; j++) { n     for (int i = 0; i < m[j]; i++) { n       scanf( %d , &a[j][i]); n       H[j].insert(a[j][i]); n       x[xn++] = a[j][i] + 1; n     } n   } n   if (a[0][0] == 1 && a[1][0] == 1) return puts( No ), 0; n   x[xn++] = n + 1; n   sort(x, x + xn); n   xn = unique(x, x + xn) - x; n   for (int j = 0; j < 2; j++) { n     for (int i = 0; i < m[j]; i++) n       b[j][lower_bound(x, x + xn, a[j][i] + 1) - x] = 1; n   } n   for (int i = 1; i < xn; i++) { n     dp[0][i] = dp[1][i] = inf; n     for (int j = 0; j < 2; j++) n       if (dp[j][i - 1] != inf) { n         if (b[j][i]) { n           int y = x[i] - 1; n           int cur = (x[i - 1] == y ? dp[j][i - 1] : dp[j][i - 1] + t); n           if (cur < y) { n             if (H[j].count(x[i])) { n               if (cur + t <= y) { n                 dp[j][i] = min(dp[j][i], cur + t); n               } n             } else { n               dp[j][i] = min(dp[j][i], cur); n             } n           } n         } else if (H[j].count(x[i])) { n           int y = x[i]; n           if (dp[j][i - 1] + t < y) { n             dp[j][i] = min(dp[j][i], dp[j][i - 1] + t); n           } n         } else { n           dp[j][i] = dp[j][i - 1]; n         } n       } n     for (int j = 0; j < 2; j++) { n       if (dp[j][i] < inf) { n         if (H[!j].count(x[i])) { n           continue; n         } n         if (dp[!j][i] > max(dp[j][i], x[i] - t)) { n           dp[!j][i] = max(dp[j][i], x[i] - t); n           pr[!j][i] = 1; n         } n       } n     } n   } n   if (dp[0][xn - 1] == inf && dp[1][xn - 1] == inf) return puts( No ), 0; n   puts( Yes ); n   int state = 0, pos = xn - 1; n   if (dp[1][xn - 1] < inf) state = 1; n   vector<pair<int, int> > ans; n   vector<int> changes; n   while (pos != 0) { n     ans.push_back(make_pair(state, pos)); n     int flg = pr[state][pos]; n     if (flg) { n       changes.push_back(x[pos]); n       state ^= 1; n     } else { n       pos--; n     } n   } n   ans.push_back(make_pair(state, 0)); n   if (state == 1) { n     state ^= 1; n     ans.push_back(make_pair(state, 0)); n     changes.push_back(0); n   } n   printf( %d n , changes.size()); n   reverse(changes.begin(), changes.end()); n   reverse(ans.begin(), ans.end()); n   for (int y : changes) printf( %d  , y); n   puts(  ); n   int last = t; n   vector<pair<int, int> > ret; n   for (pair<int, int> cur : ans) { n     if (cur.first != state) { n       last = max(last, x[cur.second]); n     } n     if (b[cur.first][cur.second]) { n       if (state == cur.first) n         ret.push_back(make_pair(cur.first + 1, last)), last += t; n     } n     if (H[cur.first].count(x[cur.second])) { n       if (state == cur.first) { n         b[cur.first][cur.second + 1] = 0; n         ret.push_back(make_pair(cur.first + 1, last)), last += t; n       } n     } n     state = cur.first; n   } n   printf( %d n , ret.size()); n   for (pair<int, int> cur : ret) printf( %d %d n , cur.second, cur.first); n   return 0; n } n