#include <bits/stdc++.h> n int n, ans, a[15][15]; n inline void maxx(int& a, int b) { a = (a > b ? a : b); } n inline void minx(int& a, int b) { a = (a < b ? a : b); } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= n; j++) scanf( %d , &a[i][j]); n   for (int k = 1; k <= n; k++) n     for (int i = 1; i <= n; i++) n       for (int j = 1; j <= n; j++) minx(a[i][j], a[i][k] + a[k][j]); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= n; j++) maxx(ans, a[i][j]); n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N, K, ans; n vector<int> ady[1000005]; n set<int> dfs(int x, int p) { n   set<int> s; n   if (ady[x].size() == 1) { n     s.insert(0); n     return s; n   } n   for (auto v : ady[x]) { n     if (v == p) continue; n     set<int> tmp = dfs(v, x); n     for (auto aux : tmp) { n       aux++; n       if (aux > K) n         ans++; n       else if (s.find(aux) != s.end() && aux + aux > K) n         ans++; n       else n         s.insert(aux); n     } n   } n   auto it = s.begin(); n   while (s.begin() != s.end()) { n     auto it2 = it; n     it2++; n     if (it2 == s.end()) break; n     if (*it + *it2 <= K) s.erase(it); n     it = it2; n   } n   return s; n } n int main() { n   cin.tie(0); n   ios_base::sync_with_stdio(0); n   cin >> N >> K; n   for (int i = 1; i < N; i++) { n     int u, v; n     cin >> u >> v; n     ady[u].push_back(v); n     ady[v].push_back(u); n   } n   int root = 1; n   while (ady[root].size() == 1) root++; n   ans += dfs(root, 0).size(); n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   long long ans = 0; n   for (int i = (0); i < (n); ++i) { n     long long t, T, x, cost; n     cin >> t >> T >> x >> cost; n     if (t >= T) { n       ans += cost + m * x; n       continue; n     } n     long long aux1 = cost; n     if (m > (T - t)) aux1 += m * x; n     long long aux2 = (long long)ceil((double)(m - (T - t)) / (T - t)) + 1; n     aux2 *= cost; n     ans += min(aux1, aux2); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-10; n struct rec { n   double x, y; n } a[110], s, e, f[2]; n int g[2], n, m, i; n double ans; n double XJ(rec a, rec b, rec c) { n   return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x); n } n double dist(rec a, rec b) { n   return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); n } n void cross(rec a, rec b, rec c, rec d) { n   double t1 = XJ(a, c, b), t2 = XJ(a, b, d), t3 = XJ(c, a, d), t4 = XJ(c, d, b); n   if (fabs(t1) < eps && fabs(t2) < eps) return; n   if (fabs(dist(a, c) + dist(b, c) - dist(a, b)) < eps) { n     f[m] = c; n     g[m++] = i; n     return; n   } n   if (t1 * t2 > eps && t3 * t4 > eps) { n     f[m].x = (t1 * d.x + t2 * c.x) / (t1 + t2); n     f[m].y = (t1 * d.y + t2 * c.y) / (t1 + t2); n     g[m++] = i; n     return; n   } n } n double calc(int st, int ed, int s, int e) { n   if (ed == 1) n     ed = n; n   else n     ed--; n   double ans = dist(f[s], a[st]); n   for (int i = st; i != ed; i == n ? i = 1 : i++) n     ans += dist(a[i], a[i == n ? 1 : i + 1]); n   return ans + dist(a[ed], f[e]); n } n int main() { n   scanf( %lf%lf%lf%lf%d , &s.x, &s.y, &e.x, &e.y, &n); n   for (i = 1; i <= n; i++) cin >> a[i].x >> a[i].y; n   a[0] = a[n]; n   for (i = 1; i <= n; i++) cross(s, e, a[i - 1], a[i]); n   if (m > 1) { n     if (dist(s, f[0]) > dist(s, f[1])) swap(f[0], f[1]), swap(g[0], g[1]); n     ans = min(calc(g[0], g[1], 0, 1), calc(g[1], g[0], 1, 0)); n     ans = min(ans, 2 * dist(f[0], f[1])); n     ans += dist(s, f[0]) + dist(f[1], e); n   } else n     ans = dist(s, e); n   printf( %.10lf n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[2500000]; n int main() { n   int all; n   scanf( %d , &all); n   for (int i = 1; i <= all; i++) { n     scanf( %I64d , &a[i]); n   } n   sort(a + 1, a + all + 1); n   reverse(a + 1, a + all + 1); n   long long sum = 0; n   for (int fro = 1; fro <= all; fro = fro << 2) { n     for (int p = 1; p <= fro; p++) { n       sum += a[p]; n     } n   } n   long long temp = 0, area = 1; n   printf( %I64d , sum); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   cin >> n >> k; n   vector<int> a(n + 1); n   vector<vector<int> > inc(n + 1); n   vector<vector<int> > dec(n + 2); n   for (int i = 0; i < n; i++) { n     cin >> a[i + 1]; n   } n   for (int i = 0; i <= n; i++) { n     if (i == 0) n       ; n     else { n       inc[i] = inc[i - 1]; n       inc[i].push_back(a[i]); n       sort(inc[i].begin(), inc[i].end()); n     } n   } n   for (int i = n; i >= 1; i--) { n     if (i == n) n       dec[i].push_back(a[i]); n     else { n       dec[i] = dec[i + 1]; n       dec[i].push_back(a[i]); n       sort(dec[i].begin(), dec[i].end()); n     } n   } n   int fsum = accumulate(a.begin(), a.end(), 0); n   for (int i = 1; i <= n; i++) { n     for (int j = i; j <= n; j++) { n       vector<int> tmp(j - i + 1); n       copy(a.begin() + i, a.begin() + j + 1, tmp.begin()); n       sort(tmp.begin(), tmp.end(), greater<int>()); n       vector<int> incb = inc[i - 1]; n       vector<int> deca = dec[j + 1]; n       int swaps = 0, tmpsum = 0; n       while (swaps < k && tmp.size()) { n         int src = 0; n         int v1 = INT_MIN, v2 = INT_MIN, finval = INT_MIN; n         if (incb.size()) v1 = incb.back(); n         if (deca.size()) v2 = deca.back(); n         if (v1 == INT_MIN && v2 == INT_MIN) break; n         if (v1 >= v2) { n           src = 1; n           finval = v1; n         } else if (v1 < v2) { n           src = 2; n           finval = v2; n         } n         swaps++; n         if (finval > tmp.back()) { n           tmpsum += finval; n           if (src == 1) n             incb.pop_back(); n           else if (src == 2) n             deca.pop_back(); n           tmp.pop_back(); n         } else n           break; n       } n       fsum = max(fsum, tmpsum + accumulate(tmp.begin(), tmp.end(), 0)); n     } n   } n   cout << fsum; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int zsern = 1e6 + 1000; n const long long mod = 1e9 + 7; n const double pi = acos(-1.0); n long long n, k; n long long a[zsern]; n std::vector<long long> num; n void gst(int id, int zser) { n   if (id - 1 >= 0 && id - 1 != zser) n     gst(id - 1, zser); n   else if (id - 2 >= 0 && id - 2 != zser) n     gst(id - 2, zser); n   num.push_back(1 << id); n   if (id - 1 >= 0 && id - 1 != zser) n     gst(id - 1, zser); n   else if (id - 2 >= 0 && id - 2 != zser) n     gst(id - 2, zser); n } n void AC() { n   long long x; n   while (~scanf( %lld%lld , &n, &x)) { n     long long zser = 0; n     for (int i = 0; i <= 18; i++) { n       if ((1ll << i) <= x) zser = i; n     } n     for (int i = n - 1; i >= 0; i--) { n       if (i != zser) { n         gst(i, zser); n         break; n       } n     } n     cout << num.size() << endl; n     for (int i = 0; i < num.size(); i++) printf( %lld  , num[i]); n   } n } n int main() { n   AC(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   int n = s.size(), c = 0, c1 = 0, k = 0, k1 = 0; n   if (n % 2 != 0) n     cout << -1; n   else { n     for (int i = 0; i < n; i++) { n       if (s[i] ==  R ) n         c++; n       else if (s[i] ==  L ) n         c1++; n       else if (s[i] ==  U ) n         k++; n       else if (s[i] ==  D ) n         k1++; n     } n     n = abs(c - c1) + abs(k - k1); n     n = n / 2; n     cout << n; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int32_t mod = 1e9 + 7; n const long long inf = 1e18; n set<long long> S; n void doq() { n   for (long long i = 0; i < 40; i++) { n     for (long long j = 0; j < 40; j++) { n       long long a = 3 * i + 7 * j; n       if (a <= 100) S.insert(a); n     } n   } n } n void solve() { n   long long n; n   cin >> n; n   if (S.find(n) != S.end()) n     cout <<  YES n ; n   else n     cout <<  NO n ; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   doq(); n   long long tcs = 1; n   cin >> tcs; n   while (tcs--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   long long int n, x, d = 0; n   cin >> n >> x; n   while (n--) { n     long long int t; n     char s; n     cin >> s; n     cin >> t; n     if (s ==  + ) { n       x += t; n     } else { n       if (x - t >= 0) n         x -= t; n       else n         d++; n     } n   } n   cout << x <<     << d; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void setIO(string s =   ) { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   if ((int)s.size()) { n     freopen((s +  .in ).c_str(),  r , stdin); n     freopen((s +  .out ).c_str(),  w , stdout); n   } n } n int main() { n   setIO(); n   int n; n   string s; n   cin >> n >> s; n   string result; n   result += s[0]; n   for (int i = 1; i < n; i++) { n     if (i % 2) { n       result = s[i] + result; n     } else { n       result += s[i]; n     } n   } n   if (n % 2) { n     cout << result << endl; n   } else { n     reverse((result).begin(), (result).end()); n     cout << result << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 1000; n bool fg[55][55]; n long long n, m, dy[4] = {1, 0, -1, 0}, dx[4] = {0, 1, 0, -1}; n bool flag; n char s[55][55]; n void dfs(long long x, long long y, long long st, long long ed) { n   fg[x][y] = true; n   for (long long i = 0; i < 4; i++) { n     long long a = x + dx[i], b = y + dy[i]; n     if (a >= 1 && a <= n && b >= 1 && b <= m && s[a][b] == s[x][y] && n         (st != a || ed != b)) { n       if (fg[a][b]) { n         flag = true; n         break; n       } n       dfs(a, b, x, y); n     } n   } n } n signed main() { n   memset(fg, false, sizeof fg); n   cin >> n >> m; n   flag = false; n   for (long long i = 1; i <= n; i++) scanf( %s , s[i] + 1); n   for (long long i = 1; i <= n; i++) { n     for (long long j = 1; j <= m; j++) { n       if (!fg[i][j]) { n         fg[i][j] = true; n         dfs(i, j, i, j); n         if (flag) break; n       } n     } n     if (flag) break; n   } n   if (flag) n     cout <<  Yes ; n   else n     cout <<  No ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n #define pb push_back n #define endl   n  n #define F first n #define S second n #define pp pop_back n ll mod = 1e9+7; n ll dp[200200][2]; n ll st[200200]; n ll n; n  n ll rec(ll level,int curr){ n     if(st[level]==1||st[level]==0){ n         if(curr!=st[level])return 0; n     } n     if(level==n-1){ n         return 1; n     } n     if(dp[level][curr]!=-1)return dp[level][curr]; n     return dp[level][curr] = 1+rec(level+1,1-curr); n } n  n  n int main() n { n     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); n     ll t;cin>>t; n     while(t--){ n         memset(dp,-1,sizeof(dp));memset(st,-1,sizeof(st)); n         string s;cin>>s; n         n = (ll)s.size(); n         for(ll i=0;i<n;i++){ n             if(s[i]== 1  ||s[i]== 0 ){st[i]=s[i]- 0 ;} n             else{ n                 st[i]=3; n             } n         } n         ll ans = 0; n         for(int i=0;i<n;i++){ n             ans+=max(rec(i,1),rec(i,0)); n         } n         cout<<ans<<endl; n     } 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(0); n   cout.tie(0); n   long long n, m; n   cin >> n >> m; n   long long a[n][m]; n   vector<long long> b(n); n   for (int i = 0; i < n; i++) { n     long long k = 0; n     for (int j = 0; j < m; j++) { n       cin >> a[i][j]; n       k += a[i][j]; n     } n     b[i] = k; n   } n   if (n <= 4 || m <= 4) { n     long long res = 0; n     for (int i = 0; i < n; i++) res += b[i]; n     cout << res; n     return 0; n   } n   vector<long long> c(m); n   for (int j = 0; j < m; j++) { n     long long k = 0; n     for (int i = 0; i < n; i++) { n       k += a[i][j]; n     } n     c[j] = k; n   } n   long long res = 0; n   vector<long long> d = b; n   vector<long long> e = c; n   sort(d.begin(), d.end()); n   sort(e.begin(), e.end()); n   res = max(d[n - 1] + d[n - 2] + d[n - 3] + d[n - 4], n             e[m - 1] + e[m - 2] + e[m - 3] + e[m - 4]); n   for (int i = 0; i < n; i++) { n     vector<long long> f; n     for (int j = 0; j < m; j++) { n       f.push_back(c[j] - a[i][j]); n     } n     sort(f.begin(), f.end()); n     res = max(res, b[i] + f[m - 1] + f[m - 2] + f[m - 3]); n   } n   for (int j = 0; j < m; j++) { n     vector<long long> f; n     for (int i = 0; i < n; i++) { n       f.push_back(b[i] - a[i][j]); n     } n     sort(f.begin(), f.end()); n     res = max(res, c[j] + f[n - 1] + f[n - 2] + f[n - 3]); n   } n   if (n <= m) { n     for (int i = 0; i < n; i++) { n       for (int l = i + 1; i < n; i++) { n         vector<long long> f; n         for (int j = 0; j < m; j++) { n           f.push_back(c[j] - a[i][j] - a[l][j]); n         } n         sort(f.begin(), f.end()); n         res = max(res, b[i] + b[l] + f[m - 1] + f[m - 2]); n       } n     } n   } else { n     for (int j = 0; j < m; j++) { n       for (int l = j + 1; j < m; j++) { n         vector<long long> f; n         for (int i = 0; i < n; i++) { n           f.push_back(b[i] - a[i][j] - a[i][l]); n         } n         sort(f.begin(), f.end()); n         res = max(res, c[j] + c[l] + f[n - 1] + f[n - 2]); n       } n     } n   } n   cout << res; n } n


#include <bits/stdc++.h> n using namespace std; n int a[100010]; n int b[100010]; n int ans[100010]; n int main() { n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     b[a[i]] = i; n   } n   ans[b[n]] = 0; n   for (int i = n - 1; i >= 1; i--) { n     int idx = b[i]; n     int flag = 0; n     for (int j = idx + i; j <= n; j += i) { n       if (a[j] > i && ans[j] == 0) { n         flag = 1; n         break; n       } n     } n     for (int j = idx - i; j >= 1; j -= i) { n       if (a[j] > i && ans[j] == 0) { n         flag = 1; n         break; n       } n     } n     if (flag == 1) { n       ans[idx] = 1; n     } else { n       ans[idx] = 0; n     } n   } n   for (int i = 1; i <= n; i++) { n     if (ans[i]) { n       cout <<  A ; n     } else { n       cout <<  B ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 1e7; n vector<long long> primes; n vector<long long> p(N, 1); n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long n, p, w, d; n   cin >> n >> p >> w >> d; n   long long l = 0, r = n; n   while (r - l > 10000000) { n     long long wins = (l + r) / 2; n     if (w * wins > p) { n       r = wins - 1; n       continue; n     } n     long long draws = (p - (wins * w)) / d; n     if (draws < 0) { n       l = wins + 1; n       continue; n     } n     long long points = w * wins + d * draws; n     cerr << wins <<     << draws <<     << points <<   n ; n     if (points == p) { n       if (wins + draws <= n) { n         cout << wins <<     << draws <<     << n - wins - draws <<   n ; n         return 0; n       } else { n         l = wins + 1; n       } n     } else { n       if (points < p) { n         l = wins + 1; n       } else { n         r = wins - 1; n       } n     } n   } n   for (long long wins = l; wins <= r; wins++) { n     if (w * wins > p) { n       continue; n     } n     long long draws = (p - (wins * w)) / d; n     if (draws < 0) { n       continue; n     } n     long long points = w * wins + d * draws; n     if (points == p) { n       if (wins + draws <= n) { n         cout << wins <<     << draws <<     << n - wins - draws <<   n ; n         return 0; n       } n     } n   } n   cout << -1 <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct chip { n   int l; n   int r; n   int u; n   int d; n }; n vector<char> a[5005]; n vector<chip> link1[5005], link2[5005]; n int n, m, kq, res; n void nhap() { n   ios_base::sync_with_stdio(0); n   cin >> n >> m; n   char x; n   for (int i = 1; i <= n; ++i) a[i].push_back(   ); n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= m; ++j) { n       cin >> x; n       a[i].push_back(x); n     } n   for (int i = 1; i <= n; ++i) a[i].push_back(   ); n   for (int i = 0; i <= m + 1; ++i) { n     a[0].push_back(   ); n     a[n + 1].push_back(   ); n   } n   for (int i = 0; i <= n + 1; ++i) n     for (int j = 0; j <= m + 1; ++j) { n       chip x; n       x.l = 0; n       x.r = 0; n       x.u = 0; n       x.d = 0; n       link1[i].push_back(x); n       link2[i].push_back(x); n     } n } n void prep() { n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= m; ++j) n       if (a[i][j] !=  . ) { n         int l = j - 1, r = j + 1, u = i - 1, d = i + 1; n         while (a[i][l] ==  .  && l > 0) --l; n         while (a[i][r] ==  .  && r <= m) ++r; n         while (a[u][j] ==  .  && u > 0) --u; n         while (a[d][j] ==  .  && d <= n) ++d; n         link1[i][j].l = l; n         link1[i][j].r = r; n         link1[i][j].u = u; n         link1[i][j].d = d; n       } n } n void xl(int x, int y) { n   int dem = 0; n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= m; ++j) link2[i][j] = link1[i][j]; n   while (a[x][y] !=  .  && x > 0 && x <= n && y > 0 && y <= m) { n     ++dem; n     int l = link2[x][y].l, r = link2[x][y].r, u = link2[x][y].u, n         d = link2[x][y].d; n     link2[x][l].r = r; n     link2[x][r].l = l; n     link2[u][y].d = d; n     link2[d][y].u = u; n     if (a[x][y] ==  L ) n       y = l; n     else if (a[x][y] ==  R ) n       y = r; n     else if (a[x][y] ==  U ) n       x = u; n     else if (a[x][y] ==  D ) n       x = d; n   } n   kq = max(kq, dem); n } n void xl1(int x, int y) { n   int dem = 0; n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= m; ++j) link2[i][j] = link1[i][j]; n   while (a[x][y] !=  .  && x > 0 && x <= n && y > 0 && y <= m) { n     ++dem; n     int l = link2[x][y].l, r = link2[x][y].r, u = link2[x][y].u, n         d = link2[x][y].d; n     link2[x][l].r = r; n     link2[x][r].l = l; n     link2[u][y].d = d; n     link2[d][y].u = u; n     if (a[x][y] ==  L ) n       y = l; n     else if (a[x][y] ==  R ) n       y = r; n     else if (a[x][y] ==  U ) n       x = u; n     else if (a[x][y] ==  D ) n       x = d; n   } n   if (dem == kq) ++res; n } n int main() { n   nhap(); n   prep(); n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= m; ++j) n       if (a[i][j] !=  . ) xl(i, j); n   cout << kq <<    ; n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= m; ++j) n       if (a[i][j] !=  . ) xl1(i, j); n   cout << res; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   vector<vector<pair<int, int> > > e(n, vector<pair<int, int> >()); n   for (int i = 1; i < n; ++i) { n     int u, v, d; n     scanf( %d%d%d , &u, &v, &d); n     e[--u].push_back(make_pair(--v, d)); n   } n   vector<pair<int, int> > info; n   vector<set<int> > adt(n, set<int>()), eve(n, set<int>()); n   for (int i = 0; i < m; ++i) { n     int s, t; n     scanf( %d%d , &s, &t); n     info.push_back(make_pair(--s, t)); n     adt[s].insert(i); n   } n   vector<pair<long long, long long> > seg, rseg; n   auto upd_seg = [&](int x, int y, long long adt, bool add = 1) { n     auto tmp = make_pair(info[x].second + adt, info[y].second + adt); n     if (add) { n       seg.push_back(tmp); n     } else { n       rseg.push_back(tmp); n     } n   }; n   vector<int> dsu(n, -1); n   function<int(int)> dsu_find = [&](int u) { n     return dsu[u] < 0 ? u : (dsu[u] = dsu_find(dsu[u])); n   }; n   auto dsu_check = [&](int x, int y) { n     return dsu_find(info[x].first) == dsu_find(info[y].first); n   }; n   function<void(int, long long)> dfs = [&](int u, long long dis) { n     for (auto &it : e[u]) { n       int &v = it.first; n       dfs(v, dis + it.second); n       if (eve[u].size() < eve[v].size()) eve[u].swap(eve[v]); n       set<int>::iterator vL = eve[v].begin(); n       while (vL != eve[v].end()) { n         set<int>::iterator uR = eve[u].lower_bound(*vL); n         if (uR != eve[u].begin()) { n           set<int>::iterator uL = uR; n           --uL; n           if (uR != eve[u].end() && !dsu_check(*uL, *uR)) n             upd_seg(*uL, *uR, dis, 0); n           upd_seg(*uL, *vL, dis); n         } n         if (uR == eve[u].end()) { n           eve[u].insert(vL, eve[v].end()); n           vL = eve[v].end(); n         } else { n           int upp = *uR; n           set<int>::iterator vR = vL; n           while (vR != eve[v].end() && *vR < upp) { n             eve[u].insert(*vR); n             vL = vR++; n           } n           upd_seg(*vL, upp, dis); n           if (vR != eve[v].end() && !dsu_check(*vL, *vR)) n             upd_seg(*vL, *vR, dis, 0); n           ++vL; n         } n       } n       set<int>().swap(eve[v]); n     } n     if (!eve[u].empty()) { n       int low = *eve[u].begin(); n       if (dsu_find(info[low].first) != e[u].back().first) n         seg.push_back(make_pair(0LL, info[low].second + dis)); n     } n     eve[u].insert(adt[u].begin(), adt[u].end()); n     set<int>().swap(adt[u]); n     for (auto &it : e[u]) dsu[it.first] = u; n   }; n   dfs(0, 0); n   sort(seg.begin(), seg.end()); n   sort(rseg.begin(), rseg.end()); n   auto it = seg.begin(), jt = it, kt = rseg.begin(); n   while (it != seg.end()) { n     if (kt != rseg.end() && *it == *kt) { n       ++kt; n     } else if (it == jt) { n       ++jt; n     } else { n       *(jt++) = *it; n     } n     ++it; n   } n   assert(kt == rseg.end()); n   seg.erase(jt, seg.end()); n   long long cur = 0, lim = -1; n   it = seg.begin(); n   priority_queue<long long, vector<long long>, greater<long long> > Q; n   while (it != seg.end() || !Q.empty()) { n     if (Q.empty() && (it->first) > cur) cur = it->first; n     while (it != seg.end() && (it->first) <= cur) Q.push((it++)->second); n     long long upp = Q.top(); n     Q.pop(); n     if (cur >= upp) { n       lim = upp; n       break; n     } n     ++cur; n   } n   int cnt = 0; n   if (lim == -1) { n     cnt += (int)seg.size(); n   } else { n     for (auto &it : seg) cnt += it.second < lim; n   } n   printf( %lld %d n , lim, cnt); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const long long INFF = 0x3f3f3f3f3f3f3f3fll; n const long long M = 1e9 + 7; n const long long maxn = 2e6 + 7; n const double eps = 0.00000001; n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n template <typename T> n inline T abs(T a) { n   return a > 0 ? a : -a; n } n template <typename T> n inline T powMM(T a, T b) { n   T ret = 1; n   for (; b; b >>= 1ll, a = a * a % M) ret = 1ll * ret * a % M; n   return ret; n } n set<int> SET; n set<int>::iterator it; n int n, m, t; n int i; n int len; n int mx; n char a[maxn], s[maxn]; n int main() { n   scanf( %d , &n); n   for (i = 0; i <= 2e6; i++) SET.insert(i); n   while (n--) { n     scanf( %s , s); n     len = strlen(s); n     scanf( %d , &m); n     while (m--) { n       scanf( %d , &t); n       t--; n       for (it = SET.lower_bound(t); it != SET.end() && *it < t + len; n            it = SET.lower_bound(t)) { n         a[*it] = s[*it - t]; n         if (mx < *it) mx = *it; n         SET.erase(it); n       } n     } n   } n   for (i = 0; i < mx + 1; i++) { n     if (a[i]) n       putchar(a[i]); n     else n       putchar( a ); n   } n } n


#include <bits/stdc++.h> n const int N = 1e6 + 5; n const int mod = 1e9 + 7; n const int MOD = mod - 1; n const double eps = 1e-18; n const double PI = acos(-1.0); n using namespace std; n char s[200]; n int main() { n   int n, m; n   scanf( %d , &n), scanf( %d , &m); n   scanf( %s , s + 1); n   int l = strlen(s + 1); n   while (m--) { n     int l, r; n     char a, b; n     scanf( %d %d %c %c , &l, &r, &a, &b); n     getchar(); n     for (int i = l; i <= r; i++) n       if (s[i] == a) s[i] = b; n   } n   puts(s + 1); n } n


#include <bits/stdc++.h> n using namespace std; n long long M = 1000000007; n int sum(int n) { n   int ans = 0; n   while (n) { n     ans += n % 10; n     n = n / 10; n   } n   return ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int k; n   cin >> k; n   int ans = 18; n   while (k) { n     ans++; n     if (sum(ans) == 10) k--; n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename X> n inline X abs(const X& a) { n   return a < 0 ? -a : a; n } n template <typename X> n inline X sqr(const X& a) { n   return a * a; n } n long long combine(long long n, int k) { n   long long ans = 1; n   for (int i = 0; i < k; i++) ans = (ans * (n - i)) / (i + 1); n   return ans; n } n long long pw(long long a, long long p) { n   long long ans = 1; n   for (int i = 0; i < p; i++) ans *= a; n   return ans; n } n int toint(string s) { n   int n = 0, k = 1; n   for (int i = (int)s.size() - 1; i >= 0; i--) { n     n += (s[i] -  0 ) * k; n     k *= 10; n   } n   return n; n } n int main() { n   int k, m, n, p; n   int a = 0, b; n   cin >> n >> k >> p, b = n * p; n   while (n > 1) { n     m = 1; n     while (2 * m <= n) m <<= 1; n     a += m * k + m / 2; n     n = n - m + m / 2; n   } n   cout << a <<     << b << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n pair<int, int> a[210000], b[2100000]; n vector<pair<int, int> > ans; n int main() { n   int N, M, i, j, k; n   scanf( %d%d , &N, &M); n   if (N <= M) { n     puts( -1 ); n     return 0; n   } n   for (i = 0; i < N; i++) scanf( %d%d , &a[i].first, &a[i].second); n   sort(a, a + N); n   for (i = 0; i <= M; i++) n     for (j = 0; i + j <= M; j++) { n       int l = i, r = N - 1 - j; n       int first = a[l].first + a[r].first, second = a[l].second + a[r].second; n       bool flag = 1; n       for (k = l; k <= r; k++) n         b[k] = make_pair(first - a[k].first, second - a[k].second); n       reverse(b + l, b + r + 1); n       int p = l, q = l, cnt = 0; n       while (p <= r && q <= r) { n         if (a[p] < b[q]) n           ++p; n         else if (a[p] > b[q]) n           ++q; n         else { n           ++cnt; n           ++p; n           ++q; n         } n       } n       if (r - l + 1 - cnt + i + j <= M) ans.push_back(make_pair(first, second)); n     } n   sort(ans.begin(), ans.end()); n   ans.resize(unique(ans.begin(), ans.end()) - ans.begin()); n   cout << ans.size() << endl; n   for (i = 0; i < ans.size(); i++) n     printf( %.12f %.12f n , ans[i].first / 2.0, ans[i].second / 2.0); n } n


#include <bits/stdc++.h> n using namespace std; n long long N, L, W; n vector<long long> neg, pos; n long long INF32 = 0x7fffffff; n inline long long div_floor(long long a, long long b) { n   return (long long)floor(1.0 * a / b); n } n int main() { n   cin >> N >> L >> W; n   for (int i = 0; i < N; ++i) { n     long long x, d; n     cin >> x >> d; n     (d == 1 ? pos : neg).push_back(d == 1 ? x : x + L); n   } n   sort(pos.begin(), pos.end()); n   sort(neg.begin(), neg.end()); n   long long ans = 0; n   for (auto x : pos) { n     long long lval = max(-x - 1, x); n     if (W == 1) { n       if (x < 0) { n       } else { n         lval = INF32; n       } n     } else { n       lval = max(lval, div_floor(((W + 1) * x), (W - 1))); n     } n     auto l = upper_bound(neg.begin(), neg.end(), lval); n     ans += int(neg.end() - l); n     lval = max(x, div_floor((W - 1) * x, (W + 1))); n     long long rval = -x; n     l = upper_bound(neg.begin(), neg.end(), lval); n     auto r = lower_bound(neg.begin(), neg.end(), rval); n     ans += max(0, int(r - l)); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int l[5005], r[5005], v[105][105], t[105][105]; n double res[105], c[5005], f[105][105], cc[105][105]; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < m; i++) { n     int a, b, x; n     scanf( %d%d%d , &a, &b, &x); n     l[i] = (--a); n     r[i] = (--b); n     c[i] = x; n     v[a][b] = (v[a][b] == 0) ? x : min(v[a][b], x); n     t[a][b]++; n     t[b][a]++; n   } n   int k = n - 2; n   for (int i = 1; i <= k; i++) { n     for (int j = 0; j < n; j++) { n       f[i][i] += t[j][i]; n       f[i][j] -= t[j][i]; n     } n     f[i][n - 1] = -f[i][0]; n   } n   for (int i = 1; i <= k; i++) { n     int t = i; n     while (!f[t][i] && t <= k) t++; n     if (t > k) continue; n     for (int j = i; j <= k + 1; j++) swap(f[i][j], f[t][j]); n     for (int j = 1; j <= k; j++) { n       if (j != i) { n         double tt = f[j][i] / f[i][i]; n         for (int x = 1; x <= k + 1; x++) f[j][x] -= tt * f[i][x]; n       } n     } n   } n   for (int i = 1; i <= k; i++) { n     if (f[i][i] == 0) continue; n     double x = f[i][i]; n     for (int j = 1; j <= k + 1; j++) f[i][j] /= x; n     res[i] = f[i][k + 1]; n   } n   res[0] = 1; n   double mn = 1e9 + 7; n   for (int i = 0; i < m; i++) { n     double x = fabs(res[l[i]] - res[r[i]]); n     if (x < 1e-10) continue; n     mn = min(mn, c[i] / x); n   } n   double ans = 0; n   for (int i = 0; i < m; i++) cc[l[i]][r[i]] = mn * (res[l[i]] - res[r[i]]); n   for (int i = 0; i < m; i++) { n     if (l[i] == 0) ans += cc[l[i]][r[i]]; n     if (r[i] == 0) ans -= cc[l[i]][r[i]]; n   } n   printf( %.5lf n , ans); n   for (int i = 0; i < m; i++) printf( %.5lf n , cc[l[i]][r[i]]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = 1000000000000000; n const int mod = 1000000007; n int n, m, k; n int s[1000010]; n long long a[1000010]; n bool pos[1000010]; n int lst[1000010]; n long long get(int l) { n   int r = 0; n   int i = -1; n   long long res = 0; n   while (r < n) { n     if (lst[r] <= i) { n       return inf; n     } n     i = lst[r]; n     r = lst[r] + l; n     ++res; n   } n   return res; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> n >> m >> k; n   for (int i = 0; i < m; i++) { n     cin >> s[i]; n   } n   for (int i = 0; i < k; i++) { n     cin >> a[i]; n   } n   for (int i = 0; i < n; i++) { n     pos[i] = true; n   } n   for (int i = 0; i < m; i++) { n     pos[s[i]] = false; n   } n   for (int i = 0; i < n; i++) { n     if (pos[i]) { n       lst[i] = i; n     } else if (i) { n       lst[i] = lst[i - 1]; n     } else n       lst[i] = -1; n   } n   long long ans = inf; n   for (int i = 0; i < k; i++) { n     long long t = get(i + 1); n     if (t != inf) { n       ans = min(ans, a[i] * t); n     } n   } n   if (ans == inf) { n     ans = -1; n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int Pow10(int deg) { n   int res = 1; n   while (deg-- > 0) res *= 10; n   return res; n } n int ToInt(const string& from) { n   int res = 0; n   for (int i = 0; i < ((int)(from).size()); ++i) res = 10 * res + from[i] -  0 ; n   return res; n } n void Solve() { n   string buf; n   do { n     getline(cin, buf); n   } while (((int)(buf).size()) < 4); n   string year = buf.substr(4); n   int lo = 1988; n   for (int i = ((int)(year).size()) - 1; i >= 0; --i) { n     int add = Pow10(((int)(year).size()) - i); n     int base = lo / add; n     int rem = ToInt(year.substr(i)); n     while (base * add + rem <= lo) ++base; n     lo = base * add + rem; n   } n   cout << lo <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   int q; n   cin >> q; n   while (q-- > 0) Solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int N = 1e5 + 1, mod = 1000000007; n vector<long long int> adj[N]; n signed main() { n   ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); n   long long int pro = 1, temp, t, n, i, m, k, j, l, r, mid, x, y, z, rem, n                 carry = 0, ind, ans = 0, mx = -LONG_LONG_MAX, n                 mn = LONG_LONG_MAX, cnt = 0, curr = 0, prev, sum = 0, flag = 0, n                 i1 = -1, i2 = -1; n   cin >> n >> m; n   for (i = 1; i <= m; i++) { n     cin >> x >> y; n     adj[x].push_back(y); n     adj[y].push_back(x); n   } n   if (n < 2 || m >= (n * (n - 1)) / 2) { n     return cout <<  NO , 0; n   } n   cout <<  YES n ; n   long long int a[n + 1], b[n + 1]; n   for (i = 1; i <= n; i++) { n     b[i] = 1; n   } n   curr = 2; n   for (i = 1; i <= n; i++) { n     flag = 0; n     for (auto it : adj[i]) { n       if (b[it] == b[i]) { n         flag = 1; n         b[it] = curr; n       } n     } n     if (flag) { n       curr++; n     } n   } n   vector<pair<long long int, long long int> > v; n   v.push_back({-1, 0}); n   for (i = 1; i <= n; i++) { n     v.push_back({b[i], i}); n   } n   sort(v.begin(), v.end()); n   for (i = 1; i <= n; i++) { n     a[v[i].second] = i; n   } n   for (i = 1; i <= n; i++) { n     cout << a[i] <<    ; n   } n   cout << endl; n   for (i = 1; i <= n; i++) { n     cout << b[i] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimization( O3 ) n using namespace std; n template <typename T> n inline void Cin(T& first) { n   char c; n   T sign = 1; n   first = 0; n   for (c = getchar(); c <  0  || c >  9 ; c = getchar()) n     if (c ==  - ) sign = -1; n   for (; c >=  0  && c <=  9 ; c = getchar()) first = first * 10 + c -  0 ; n   first *= sign; n } n template <typename T> n inline void Out(T first) { n   if (first > 9) Out(first / 10); n   putchar(first % 10 +  0 ); n } n template <typename T> n inline void Cout(T first, char c) { n   if (first < 0) putchar( - ); n   first = abs(first); n   Out(first); n   putchar(c); n } n template <typename T, typename... Args> n inline void Cin(T& a, Args&... args) { n   Cin(a); n   Cin(args...); n } n template <typename T, typename... Args> n inline void Cout(T a, char c, Args... args) { n   Cout(a, c); n   Cout(args...); n } n const int N = 107; n const long double eps = 1e-8; n const long double e = 2.7182818284590452353602874713527; n int n, k, first[N], second[N]; n long double low, high, mid, s, w, p[N], f[N][N]; n void Enter() { n   cin >> n >> k >> w; n   w = 1 - w / 1000; n   for (int i = 0; i <= n; ++i) cin >> first[i] >> second[i]; n } n int SqrDis(int i) { n   return (first[i] - first[0]) * (first[i] - first[0]) + n          (second[i] - second[0]) * (second[i] - second[0]); n } n bool Check() { n   for (int i = 1; i <= n; ++i) { n     if ((long double)SqrDis(i) <= mid * mid) n       p[i] = 1; n     else n       p[i] = pow(e, (1 - (long double)SqrDis(i) / (mid * mid))); n   } n   memset(&f, 0, sizeof f); n   f[1][1] = p[1]; n   f[1][0] = 1 - p[1]; n   for (int i = 2; i <= n; ++i) { n     f[i][0] = f[i - 1][0] * (1 - p[i]); n     f[i][i] = f[i - 1][i - 1] * p[i]; n     for (int j = 1; j < i; ++j) n       f[i][j] = f[i - 1][j - 1] * p[i] + f[i - 1][j] * (1 - p[i]); n   } n   s = 0; n   for (int i = k; i <= n; ++i) s += f[n][i]; n   return s >= w; n } n void Solve() { n   low = eps, high = 5000; n   while (low + eps <= high) { n     mid = (low + high) / 2.0; n     if (Check()) n       high = mid - eps; n     else n       low = mid + eps; n   } n   cout << fixed << setprecision(9) << low; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   if (fopen( test  n              .inp , n              r )) { n     freopen( n          test  n          .inp , n          r , stdin); n     freopen( n          test  n          .out , n          w , stdout); n   } n   Enter(), Solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n void maxtt(T& t1, T t2) { n   t1 = max(t1, t2); n } n template <typename T> n void mintt(T& t1, T t2) { n   t1 = min(t1, t2); n } n bool debug = 0; n int n, m, k; n int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; n string direc =  URDL ; n const long long MOD2 = (long long)998244353 * (long long)998244353; n long long ln, lk, lm; n void etp(bool f = 0) { n   puts(f ?  YES  :  NO ); n   exit(0); n } n void addmod(int& x, int y, int mod = 998244353) { n   assert(y >= 0); n   x += y; n   if (x >= mod) x -= mod; n   assert(x >= 0 && x < mod); n } n void et(int x = -1) { n   printf( %d n , x); n   exit(0); n } n long long fastPow(long long x, long long y, int mod = 998244353) { n   long long ans = 1; n   while (y > 0) { n     if (y & 1) ans = (x * ans) % mod; n     x = x * x % mod; n     y >>= 1; n   } n   return ans; n } n long long gcd1(long long x, long long y) { return y ? gcd1(y, x % y) : x; } n pair<pair<int, int>, int> p[100035][4]; n void cal(set<pair<pair<int, int>, int> >* S) { n   n = (int)S[0].size(); n   if (n == 1) return; n   set<pair<pair<int, int>, int> >::iterator it[4]; n   vector<int> vp(5, -(1 << 30)); n   for (int(j) = 0; (j) < (int)(4); (j)++) it[j] = S[j].begin(); n   for (int(cnt) = 1; (cnt) <= (int)(n); (cnt)++) { n     for (int(j) = 0; (j) < (int)(4); (j)++) n       maxtt(vp[j], (it[j]++)->first.second); n     for (int(j) = 0; (j) < (int)(4); (j)++) n       if (vp[j] <= it[j]->first.first) { n         set<pair<pair<int, int>, int> > T[4]; n         auto it = S[j].begin(); n         for (int(i) = 0; (i) < (int)(cnt); (i)++) { n           int id = it->second; n           it++; n           for (int(j) = 0; (j) < (int)(4); (j)++) { n             T[j].insert(p[id][j]); n             S[j].erase(p[id][j]); n           } n         } n         cal(S); n         cal(T); n         return; n       } n   } n   etp(); n } n void fmain(int tid) { n   scanf( %d , &n); n   for (int(i) = 1; (i) <= (int)(n); (i)++) { n     int a, b, c, d; n     scanf( %d%d%d%d , &a, &b, &c, &d); n     p[i][0] = {{a, c}, i}; n     p[i][1] = {{b, d}, i}; n     p[i][2] = {{-c, -a}, i}; n     p[i][3] = {{-d, -b}, i}; n   } n   set<pair<pair<int, int>, int> > s[4]; n   for (int(i) = 1; (i) <= (int)(n); (i)++) n     for (int(j) = 0; (j) < (int)(4); (j)++) s[j].insert(p[i][j]); n   cal(s); n   etp(1); n } n int main() { n   int t = 1; n   for (int(i) = 1; (i) <= (int)(t); (i)++) { n     fmain(i); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int OHT = 100100; n const int MAXINF = (2 << 26); n const int MININF = (~(2 << 26)); n int vis1[110], vis2[110]; n int main() { n   int n, m, i, j; n   cin >> n >> m; n   vector<pair<int, int> > v; n   for (i = 2; i <= n; i++) v.push_back(make_pair(i, 1)); n   for (j = 1; j <= m; j++) v.push_back(make_pair(1, j)); n   cout << v.size() << endl; n   for (i = 0; i < v.size(); i++) n     cout << v[i].first <<     << v[i].second << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1000000007; n long long POW(long long a, long long b, long long MMM = MOD) { n   long long ret = 1; n   for (; b; b >>= 1, a = (a * a) % MMM) n     if (b & 1) ret = (ret * a) % MMM; n   return ret; n } n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n long long lcm(long long a, long long b) { n   if (a == 0 || b == 0) return a + b; n   return a * (b / gcd(a, b)); n } n int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; n int ddx[] = {0, 0, 1, 1, 1, -1, -1, -1}, ddy[] = {1, -1, 1, 0, -1, 1, 0, -1}; n tuple<int, int, int, int> query[100000]; n int ans[100000]; n map<int, vector<tuple<int, int, int> > > M; n int cc; n void upd(int i, vector<int>& tree, int k) { n   int n = tree.size(); n   while (i < n) { n     tree[i] += k; n     i += (i & -i); n   } n } n int sum(int i, vector<int>& tree) { n   int c = 0; n   while (i > 0) { n     c += tree[i]; n     i -= (i & -i); n   } n   return c; n } n int main() { n   int n; n   scanf( %d , &n); n   for (int(i) = (0); (i) <= (n - 1); (i) += (1)) { n     int x, y, z; n     scanf( %d%d%d , &x, &y, &z); n     if (x == 3) n       M[z].push_back(tuple<int, int, int>(x, y, cc++)); n     else n       M[z].push_back(tuple<int, int, int>(x, y, -1)); n   } n   for (auto it = M.begin(); it != M.end(); it++) { n     vector<tuple<int, int, int> > v = it->second; n     int N = v.size(); n     vector<int> vv; n     for (int(i) = (0); (i) <= (N - 1); (i) += (1)) vv.push_back(get<1>(v[i])); n     sort(vv.begin(), vv.end()); n     vv.resize(unique(vv.begin(), vv.end()) - vv.begin()); n     for (int(i) = (0); (i) <= (N - 1); (i) += (1)) n       get<1>(v[i]) = n           lower_bound(vv.begin(), vv.end(), get<1>(v[i])) - vv.begin(); n     vector<int> tree(N + 5, 0); n     for (int(i) = (0); (i) <= (N - 1); (i) += (1)) { n       int x, y, z; n       tie(x, y, z) = v[i]; n       if (x == 1) n         upd(y + 1, tree, 1); n       else if (x == 2) n         upd(y + 1, tree, -1); n       else n         ans[z] = sum(y + 1, tree); n     } n   } n   for (int(i) = (0); (i) <= (cc - 1); (i) += (1)) printf( %d n , ans[i]); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string n; n   int index = 0; n   cin >> n; n   int l = n.length(); n   for (int i = l - 1; i > -1; i--) { n     if (n[i] ==  4 ) n       index += pow(2, (l - 1 - i)); n     else n       index += 2 * pow(2, (l - 1 - i)); n   } n   cout << index << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 113; n int add(int x, int y) { n   x += y; n   if (x >= 1000000007) x -= 1000000007; n   return x; n } n int sub(int x, int y) { n   if (x < y) x += 1000000007; n   x -= y; n   return x; n } n int mul(int x, int y) { return (long long)x * y % 1000000007; } n int qpow(int x, int y, int p = 1000000007) { n   int res = 1; n   while (y) { n     if (y & 1) res = mul(res, x); n     x = mul(x, x); n     y >>= 1; n   } n   return res; n } n vector<int> G[N]; n int f[N][N][N], g[N], h[N], d[N][N], sz[N]; n void dfs(int x, int fa) { n   f[x][1][0] = 1; n   sz[x] = 1; n   for (int j = 0; j < G[x].size(); j++) n     if (G[x][j] != fa) { n       int v = G[x][j]; n       dfs(v, x); n       memset(d, 0, sizeof d); n       for (int xsz = sz[x]; xsz >= 1; xsz--) { n         for (int xedges = sz[x]; xedges >= 0; xedges--) { n           if (f[x][xsz][xedges]) { n             for (int sonedges = sz[v]; sonedges >= 0; sonedges--) { n               for (int sonsz = sz[v]; sonsz >= 1; sonsz--) n                 if (f[v][sonsz][sonedges]) { n                   d[xsz][xedges + sonedges] = n                       add(d[xsz][xedges + sonedges], n                           mul(f[x][xsz][xedges], f[v][sonsz][sonedges])); n                   d[xsz + sonsz][xedges + sonedges + 1] = n                       add(d[xsz + sonsz][xedges + sonedges + 1], n                           mul(mul(f[x][xsz][xedges], f[v][sonsz][sonedges]), n                               mul(qpow(mul(xsz, sonsz), 1000000007 - 2), n                                   xsz + sonsz))); n                 } n             } n           } n         } n       } n       memcpy(f[x], d, sizeof f[x]); n       sz[x] += sz[v]; n     } n } n int n; n int binom[N][N]; n int main() { n   binom[0][0] = 1; n   for (int i = 1; i < N; i++) { n     binom[i][0] = 1; n     for (int j = 1; j <= i; j++) { n       binom[i][j] = add(binom[i - 1][j], binom[i - 1][j - 1]); n     } n   } n   scanf( %d , &n); n   for (int i = 1; i < n; i++) { n     int u, v; n     scanf( %d%d , &u, &v); n     G[u].push_back(v); n     G[v].push_back(u); n   } n   dfs(1, 0); n   for (int num = 0; num < n; num++) { n     for (int sz = 1; sz <= n; sz++) { n       g[num] = add(g[num], f[1][sz][num]); n     } n     g[num] = mul(g[num], qpow(n, 1000000007 - 1 + n - num - 2)); n   } n   for (int num = n - 1; num >= 0; num--) { n     for (int _num = num; _num < n; _num++) { n       h[num] = add(h[num], (_num - num) & 1 n                                ? 1000000007 - mul(binom[_num][num], g[_num]) n                                : mul(binom[_num][num], g[_num])); n     } n   } n   for (int i = 0; i < n; i++) printf( %d  , h[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int read() { n   int res = 0, p = 1; n   char ch = getchar(); n   while (!isdigit(ch)) { n     if (ch ==  - ) p = -1; n     ch = getchar(); n   } n   while (isdigit(ch)) res = res * 10 + ch -  0 , ch = getchar(); n   return res * p; n } n const int mod = 1e9 + 7; n int t; n int main() { n   t = read(); n   while (t--) { n     long long n = read() * 2; n     long long x = 1; n     for (int i = 3; i <= n; ++i) { n       x = (x * i) % mod; n     } n     printf( %d n , x); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, p, flag; n char s[1111]; n int a[1111]; n void dfs(int x) { n   if (!x) { n     flag = 0; n     return; n   } n   while (1) { n     a[x]++; n     if (a[x] > p) { n       dfs(x - 1); n       a[x] = 0; n       continue; n     } n     if (!(x > 1 && a[x] == a[x - 1] || x > 2 && a[x] == a[x - 2])) break; n   } n   if (x == n) n     for (int i = 0; i < n; i++) s[i] = a[i + 1] - 1 +  a ; n } n int main() { n   cin >> n >> p; n   gets(s); n   gets(s); n   for (int i = 0; i < n; i++) a[i + 1] = s[i] -  a  + 1; n   flag = 1; n   dfs(n); n   if (flag) n     puts(s); n   else n     puts( NO ); n } n


#include <bits/stdc++.h> n using namespace std; n long long mod = 998244353; n long long powmod(long long a, long long b) { n   long long r = 1; n   while (b) { n     if (b & 1) r = (r * a) % mod; n     a = (a * a) % mod, b >>= 1; n   } n   return r; n } n long long modd(long long a, long long b) { return ((a % b) + b) % b; } n long long extendedEuclid(long long a, long long b, long long& x, long long& y) { n   long long xx = y = 0, yy = x = 1, t; n   while (b) { n     long long q = a / b; n     a %= b; n     swap(a, b); n     t = xx; n     xx = x - q * xx; n     x = t; n     t = yy; n     yy = y - q * yy; n     y = t; n   } n   return a; n } n long long modularInverse(long long a) { n   long long x, y, d = extendedEuclid(a, mod, x, y); n   if (d > 1) return -1; n   return modd(x, mod); n } n long long f[300000], fi[300000]; n long long binom(long long a, long long b) { n   return (((f[a] * fi[a - b]) % mod) * fi[b]) % mod; n } n int n, k, h[300000]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout << fixed << setprecision(10); n   cin >> n >> k; n   for (int i = 0; i < n; i++) cin >> h[i]; n   f[0] = 1; n   fi[0] = 1; n   for (int i = 1; i <= n; i++) n     f[i] = (f[i - 1] * i) % mod, fi[i] = modularInverse(f[i]); n   int c = 0; n   for (int i = 0; i < n; i++) c += h[i] != h[(i + 1) % n]; n   long long r = 0; n   for (int s = 1; s <= c; s++) { n     long long h = powmod(2, s); n     if ((s & 1) == 0) h = (h + mod - binom(s, s / 2)) % mod; n     h = (h * fi[2]) % mod; n     h = (h * binom(c, s)) % mod; n     r = (r + h * powmod(k - 2, c - s)) % mod; n   } n   r = (r * powmod(k, n - c)) % mod; n   cout << r <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, b, cnt[105] = {0}; n   cin >> n; n   vector<int> a; n   for (int i = 0; i < n; i++) { n     cin >> b; n     a.push_back(b); n     cnt[a[i]] = cnt[a[i]] + 1; n   } n   int y = 0; n   int x; n   x = *max_element(a.begin(), a.end()); n   for (int i = 0; i <= x; i++) { n     if (cnt[i] >= y) { n       y = cnt[i]; n     } n   } n   cout << y << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T, class U> n inline bool chkmax(T& a, U b) { n   return (a < b) ? (a = b, true) : false; n } n template <class T, class U> n inline bool chkmin(T& a, U b) { n   return (a > b) ? (a = b, true) : false; n } n template <class T> n inline vector<T> uniq(vector<T> vec) { n   sort((vec).begin(), (vec).end()), n       vec.erase(unique((vec).begin(), (vec).end()), end(vec)); n   return vec; n } n void solve(); n int main(int argc, char** argv) { n   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   cout.setf(ios_base::fixed), cout.precision(10); n   solve(); n   double times = (clock() * 1.0 / CLOCKS_PER_SEC); n   do { n   } while (0); n } n template <int NV> n class undirectedEulerPath { n  public: n   vector<int> path; n   multiset<int> G[NV]; n   void addedge(int u, int v) { G[u].insert(v), G[v].insert(u); } n   void dfs(int cur) { n     while (!G[cur].empty()) { n       int tar = *G[cur].begin(); n       G[cur].erase(G[cur].begin()); n       G[tar].erase(G[tar].find(cur)); n       dfs(tar); n     } n     path.push_back(cur); n   } n   bool get() { n     int src = -1, odd = 0, tot = 0; n     for (int i = 0; i < NV; i++) { n       tot += G[i].size(); n       if (G[i].size() % 2 == 1) { n         odd++, src = (~src) ? src : i; n       } n     } n     if (odd != 0 && odd != 2) return false; n     dfs(odd ? src : 0); n     reverse(path.begin(), path.end()); n     return (int)path.size() == tot / 2 + 1; n   } n }; n undirectedEulerPath<202020> solver; n void solve() { n   int n; n   cin >> n; n   vector<int> b(n - 1), c(n - 1); n   for (int i = 0; i < n - 1; i++) cin >> b[i]; n   for (int i = 0; i < n - 1; i++) cin >> c[i]; n   for (int i = 0; i < n - 1; i++) { n     if (b[i] > c[i]) do { n         cout << ( -1 ) <<   n ; n         return; n       } while (0); n   } n   vector<int> index; n   for (int i = 0; i < n - 1; i++) { n     index.push_back(b[i]), index.push_back(c[i]); n   } n   index = uniq(index); n   for (int i = 0; i < n - 1; i++) { n     b[i] = lower_bound((index).begin(), (index).end(), b[i]) - index.begin(); n     c[i] = lower_bound((index).begin(), (index).end(), c[i]) - index.begin(); n     solver.addedge(b[i], c[i]); n   } n   if (solver.get()) { n     for (auto& x : solver.path) cout << index[x] <<    ; n   } else { n     do { n       cout << ( -1 ) <<   n ; n       return; n     } while (0); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int m, k, d[2000], s[2000], n = 0, big = 0, ans = 0; n   cin >> m >> k; n   for (int i = 0; i < m; i++) cin >> d[i]; n   for (int i = 0; i < m; i++) cin >> s[i]; n   for (int i = 0; i < m; i++) { n     n += s[i]; n     if (s[i] > big) big = s[i]; n     while (n < d[i]) { n       n += big; n       ans += k; n     } n     n -= d[i]; n     ans += d[i]; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void rd(T &x) { n   x = 0; n   int f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) n     x = (x << 3) + (x << 1) + ch -  0 , ch = getchar(); n   x *= f; n } n const long long inf = 1e16; n const int maxn = 505; n int n; n long long f[maxn][maxn]; n int nxt(int a, int b) { n   int c = a + b; n   if (c > n) n     return c % n; n   else n     return c; n } n long long dfs(int l, int r) { n   if (nxt(l, 1) == r) return 0; n   if (f[l][r]) return f[l][r]; n   if (nxt(l, 2) == r) return l * nxt(l, 1) * nxt(l, 2); n   long long res = inf; n   int u = nxt(l, 1); n   while (u != r) { n     res = min(res, l * r * u + dfs(l, u) + dfs(u, r)); n     u = nxt(u, 1); n   } n   return f[l][r] = res; n } n int main() { n   rd(n); n   printf( %lld n , dfs(1, n)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int MOD = 998244353; n long long int INF = 1e18; n long long int vv; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int i, j, k = 0, l = 0, r = 0, m = 0, n, c, p = 0, cnt = 0, n                       cnt1 = 0, x, y, z = 0, a, b, low, mid, high, ans = 0, n                       maxi = 0, mini = INF, t, x1, y1; n   string s; n   cin >> s; n   n = s.size(); n   queue<long long int> q; n   long long int V[n]; n   bool visited[10]; n   long long int dist[10]; n   long long int ds[10][10]; n   for (i = 0; i < n; i++) { n     k = s[i]; n     k = k - 48; n     V[i] = k; n   } n   for (i = 0; i <= 9; i++) { n     for (j = 0; j <= 9; j++) { n       for (l = 0; l <= 9; l++) { n         for (r = 0; r <= 9; r++) { n           ds[l][r] = -1; n         } n       } n       for (l = 0; l <= 9; l++) { n         for (r = 0; r <= 9; r++) { n           visited[r] = false; n           dist[r] = INF; n         } n         q.push(l); n         dist[l] = 0; n         if (i == 0 || j == 0) { n           ds[l][l] = 1; n           visited[l] = true; n         } n         while (!q.empty()) { n           k = q.front(); n           q.pop(); n           r = (k + i) % 10; n           if (visited[r] == false) { n             visited[r] = true; n             dist[r] = (dist[k] + 1); n             ds[l][r] = dist[r]; n             q.push(r); n           } n           r = (k + j) % 10; n           if (visited[r] == false) { n             visited[r] = true; n             dist[r] = (dist[k] + 1); n             ds[l][r] = dist[r]; n             q.push(r); n           } n         } n       } n       cnt = 0; n       for (l = 0; l < n - 1; l++) { n         if (ds[V[l]][V[l + 1]] == -1) { n           cnt = -1; n           goto last; n         } else { n           cnt += ds[V[l]][V[l + 1]] - 1; n         } n       } n     last: n       cout << cnt <<    ; n     } n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m; n long long a[201]; n char s[30]; n long long b[30]; n long long dp[2000000]; n long long f(long long mask) { n   if (mask == (1 << m) - 1) return 0; n   if (dp[mask] != -1) return dp[mask]; n   long long count = __builtin_popcount(mask); n   char ch = s[count]; n   long long move = b[count]; n   long long ans = -1e8; n   long long sign = 1; n   if (move == 2) sign = -1; n   ans *= sign; n   for (long long i = 0; i < m; i++) { n     if ((mask) & (1 << i)) continue; n     if (ch ==  p ) { n       if (sign == 1) n         ans = max(ans, f((mask | (1 << i))) + sign * a[i]); n       else n         ans = min(ans, f((mask | (1 << i))) + sign * a[i]); n     } else { n       if (sign == 1) n         ans = max(ans, f((mask | (1 << i)))); n       else n         ans = min(ans, f((mask | (1 << i)))); n     } n   } n   return dp[mask] = ans; n } n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   cin >> n; n   for (long long i = 0; i < n; i++) cin >> a[i]; n   sort(a, a + n); n   reverse(a, a + n); n   cin >> m; n   for (long long i = 0; i < m; i++) cin >> s[i] >> b[i]; n   memset(dp, -1, sizeof(dp)); n   cout << f(0); n } n


#include <bits/stdc++.h> n using namespace std; n int a[2010], b[2010]; n bool vis[2010]; n char *p1, *p2, buf[100000]; n int rd() { n   int x = 0, f = 1; n   char c = n       (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) n            ? EOF n            : *p1++); n   while (c < 48) { n     if (c ==  - ) f = -1; n     c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) n              ? EOF n              : *p1++); n   } n   while (c > 47) { n     x = (((x << 2) + x) << 1) + (c ^ 48), n     c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) n              ? EOF n              : *p1++); n   } n   return x * f; n } n map<int, int> MP; n int n; n bool check(int x) { n   for (int i = 1; i <= n - x + 1; i++) { n     memset(vis, false, sizeof vis); n     bool flag = true; n     for (int j = 1; j < i; j++) { n       if (vis[a[j]]) { n         flag = false; n       } n       vis[a[j]] = true; n     } n     for (int j = i + x; j <= n; j++) { n       if (vis[a[j]]) { n         flag = false; n       } n       vis[a[j]] = true; n     } n     if (flag) { n       return true; n     } n   } n   return false; n } n int main() { n   n = rd(); n   for (int i = 1; i <= n; i++) { n     a[i] = rd(); n     b[i] = a[i]; n   } n   sort(b + 1, b + n + 1); n   b[0] = b[1] - 1; n   int cnt = 0; n   for (int i = 1; i <= n; i++) { n     if (b[i] != b[i - 1]) { n       MP[b[i]] = ++cnt; n     } n   } n   for (int i = 1; i <= n; i++) { n     a[i] = MP[a[i]]; n   } n   if (cnt == n) { n     puts( 0 ); n     return 0; n   } n   int ans = n; n   int l = 1, r = n; n   while (l <= r) { n     int mid = (l + r) >> 1; n     if (check(mid)) { n       ans = mid; n       r = mid - 1; n     } else { n       l = mid + 1; n     } n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O2 ) n using namespace std; n inline long long input() { n   long long n; n   cin >> n; n   return n; n } n string base2(long long n) { n   string a =   ; n   while (n >= 2) { n     a += (char)(n % 2 +  0 ); n     n /= 2; n   } n   a += (char)(n +  0 ); n   reverse((a).begin(), (a).end()); n   return a; n } n const int MAXN = 1e6 + 10; n const int MOD = 1e9 + 7; n const int MOD2 = 998244353; n const long long INF = 8e18; n long long pw(long long a, long long b) { n   return (!b ? 1 n              : (b & 1 ? (a * pw(a * a % MOD, b / 2)) % MOD n                       : pw(a * a % MOD, b / 2))); n } n int cnt[256], p[256]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   int q; n   cin >> q; n   while (q--) { n     for (int i = 0; i < 256; i++) { n       cnt[i] = 0; n       p[i] = 0; n     } n     string s, s2, t; n     cin >> s >> s2; n     int n = (int)s.size(); n     for (int i = 0; i < n; i++) { n       p[(int)s[i]] = i; n       cnt[(int)s[i]]++; n     } n     for (int i = 0; i < 256; i++) { n       for (int j = 0; j < cnt[i]; j++) { n         t += string(1, i); n       } n     } n     for (int i = 0; i < n; i++) { n       if (s[i] != t[i]) { n         swap(s[i], s[p[(int)t[i]]]); n         break; n       } n     } n     if (s >= s2) { n       cout <<  ---  n            <<   n ; n     } else { n       cout << s <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100000 + 5; n int g[10][10]; n int a[5]; n int ans; n int cal() { n   int sum = 0; n   for (int i = 0; i < 5; ++i) { n     for (int j = i; j < 4; j += 2) sum += g[a[j]][a[j + 1]] + g[a[j + 1]][a[j]]; n   } n   return sum; n } n int main() { n   for (int i = 0; i < 5; ++i) n     for (int j = 0; j < 5; ++j) cin >> g[i][j]; n   for (int i = 0; i < 5; ++i) a[i] = i; n   ans = -1; n   do { n     ans = max(ans, cal()); n   } while (next_permutation(a, a + 5)); n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long arr[330]; n set<long long> st; n map<long long, bool> mp; n int main() { n   long long t, n, i, j, k, l, m; n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   long long p; n   cin >> t; n   while (t--) { n     cin >> n; n     for (i = 1; i <= n; i++) cin >> arr[i], mp[arr[i]] = 1; n     sort(arr + 1, arr + n + 1); n     i = 1, j = n; n     while (i <= j) { n       long long op = arr[i] * arr[j]; n       st.insert(op); n       i++; n       j--; n     } n     if (st.size() == 1) { n       bool flag = 1; n       long long ans = *(st.begin()); n       for (i = 2; i <= sqrt(ans); i++) { n         if (ans % i == 0) { n           if (mp.find(i) == mp.end() || mp.find(ans / i) == mp.end()) n             flag = false; n         } n       } n       if (flag) n         cout << *(st.begin()) <<   n ; n       else n         cout << -1 <<   n ; n     } else n       cout << -1 <<   n ; n     st.clear(); n     mp.clear(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, s; n int even_odd[100005][2]; n int visited[100005]; n vector<int> ans; n vector<int> v[100005]; n int dfs(int s, int p) { n   if (v[s].empty() && p) { n     ans.push_back(s); n     return 1; n   } n   for (auto it : v[s]) { n     if (even_odd[it][p ^ 1] == 0) { n       even_odd[it][p ^ 1] = s; n       if (dfs(it, p ^ 1) == 1) { n         ans.push_back(s); n         return 1; n       } n     } n   } n   return 0; n } n bool dfs2(int source) { n   visited[source] = 1; n   for (auto it : v[source]) n     if (visited[it] == 1 || (visited[it] == 0 && dfs2(it))) return true; n   visited[source] = 2; n   return false; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> m; n   for (int i = 0; i < n; i++) { n     int k; n     cin >> k; n     for (int j = 0; j < k; j++) { n       int a; n       cin >> a; n       v[i + 1].push_back(a); n     } n   } n   cin >> s; n   if (dfs(s, 0)) { n     cout <<  Win n ; n     for (int i = ans.size() - 1; i >= 0; i--) cout << ans[i] <<    ; n     return 0; n   } n   if (dfs2(s)) { n     cout <<  Draw n ; n     return 0; n   } n   cout <<  Lose n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long t; n   scanf( %lld , &t); n   while (t--) { n     long long a, b, c, d, k; n     scanf( %lld%lld%lld , &a, &b, &c); n     scanf( %lld %lld , &d, &k); n     long long x = (a - 1 + c) / c; n     long long y = (b + d - 1) / d; n     if (x + y <= k) { n       printf( %lld %lld n , k - y, y); n     } else { n       printf( -1 n ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n int a[100010], i, j, k, n, x, y; n int main() { n   while (scanf( %d , &n) == 1) { n     if (n % 4 != 1 && n % 4 != 0) { n       printf( -1 n ); n       continue; n     } n     if (n == 1) { n       printf( 1 n ); n       continue; n     } n     if (n % 4 == 1) { n       a[n / 2 + 1] = n / 2 + 1; n       x = 1; n       y = n; n       while (y != x) { n         a[x] = x + 1; n         a[x + 1] = y; n         a[y - 1] = x; n         a[y] = y - 1; n         x += 2; n         y -= 2; n       } n     } else { n       x = 1; n       y = n; n       while (x - 1 != y) { n         a[x] = x + 1; n         a[x + 1] = y; n         a[y - 1] = x; n         a[y] = y - 1; n         x += 2; n         y -= 2; n       } n     } n     for (i = 1; i <= n - 1; i++) printf( %d  , a[i]); n     printf( %d n , a[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double n, sum = 0; n int a[21], b[21]; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   for (int i = 0; i < n; i++) { n     cin >> b[i]; n   } n   for (int i = 0; i < 1000000; i++) { n     for (int j = 0; j < n; j++) { n       if (i % a[j] == b[j]) { n         sum++; n         break; n       } n     } n   } n   printf( %.6f , (double)sum / 1000000.0); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxc = 1000000000; n int main() { n   long long n, k, l, r; n   scanf( %lld%lld%lld%lld , &n, &l, &r, &k); n   long long d = r - l + 1; n   if (l > r) { n     d = n - l + 1 + r; n   } n   if (d == n) { n     long long ans = -1; n     for (long long i = 1; i * i <= k + 1; i++) { n       if (k % i == 0) { n         if (i >= n && i <= 2 * n) ans = max(ans, i - n); n         if (k / i >= n && k / i <= 2 * n) ans = max(ans, k / i - n); n       } n       if ((k + 1) % i == 0) { n         if (i > n && i <= 2 * n) ans = max(ans, i - n); n         if ((k + 1) / i > n && (k + 1) / i <= 2 * n) n           ans = max(ans, (k + 1) / i - n); n       } n     } n     printf( %lld n , ans); n     return 0; n   } n   if (n < 3e7) { n     long long ans = -1; n     for (int i = 0; i <= n; i++) { n       long long res = k % (n + i); n       if (res < d) continue; n       if (res > 2 * d) continue; n       long long u = res - d; n       if (u > i) continue; n       long long uu = i - u; n       if (n - d < uu - 1) continue; n       ans = i; n     } n     printf( %lld n , ans); n     return 0; n   } n   long long best = -1; n   for (int cyc = 0; cyc < 5000; cyc++) { n     long long l = -1, r = 1e12; n     long long lo = 0, hi = n + 1; n     while (lo != hi) { n       long long mid = (lo + hi) / 2; n       int ok = 1; n       if (k / (n + mid) > cyc) ok = 0; n       long long res = k - (long long)cyc * (n + mid); n       if (res > 2 * d) ok = 0; n       if (res > d + mid) ok = 0; n       if (ok) n         hi = mid; n       else n         lo = mid + 1; n     } n     l = lo; n     lo = -1, hi = n + 1; n     while (lo != hi) { n       long long mid = (lo + hi + 1) / 2; n       int ok = 1; n       if (k / (n + mid) < cyc) ok = 0; n       long long res = k - (long long)cyc * (n + mid); n       if (res < d) ok = 0; n       long long need = max(0ll, mid - (n - d) - 1); n       if (cyc == 0 && mid == 5) ( ! %lld %lld n , need, res); n       if (res < d + need) ok = 0; n       if (ok) n         lo = mid; n       else n         hi = mid - 1; n     } n     r = lo; n     if (l == n + 1 || k < (long long)cyc * n) r = -1; n     ( cyc %d l %lld r %lld n , cyc, l, r); n     if (l > r) continue; n     best = max(best, r); n     ; n   } n   printf( %lld n , best); n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 10; n signed main() { n   int a, b, c, d, e, f; n   cin >> a >> b >> c >> d >> e >> f; n   int ans = 0; n   if (e >= f) { n     int dec = min(a, d); n     a -= dec; n     d -= dec; n     ans += dec * e; n     ans += min(min(b, c), d) * f; n   } else { n     int dec = min(min(b, c), d); n     b -= dec, c -= dec, d -= dec; n     ans += dec * f; n     ans += min(a, d) * e; n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 1e9 + 7; n template <class T> n T ABS(const T& x) { n   return x > 0 ? x : -x; n } n long long int gcd(long long int n1, long long int n2) { n   return n2 == 0 ? ABS(n1) : gcd(n2, n1 % n2); n } n long long int lcm(long long int n1, long long int n2) { n   return n1 == 0 && n2 == 0 ? 0 : ABS(n1 * n2) / gcd(n1, n2); n } n long long int ceil2(long long int a, long long int b) { n   return (a + b - 1) / b; n } n int n; n void divisors(vector<int>& d) { n   vector<int> v; n   for (int i = 1; i <= sqrt(n); ++i) { n     if (n % i == 0) { n       if (n / i == i) { n         d.push_back(i); n       } else { n         d.push_back(i); n         v.push_back(n / i); n       } n     } n   } n   for (int i = v.size() - 1; i >= 0; --i) { n     d.push_back(v[i]); n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> n; n   int arr[n]; n   for (int i = 0; i < (n); ++i) { n     cin >> arr[i]; n   } n   vector<int> d; n   divisors(d); n   bool v[n]; n   for (int i = d.size() - 1; i >= 0; --i) { n     int size = n / d[i]; n     if (size < 3) continue; n     memset(v, false, sizeof(v)); n     int k = d[i], cnt = 0; n     for (int l = 0; l < n; ++l) { n       int prev = (l - k + n) % n, next = (l + k) % n; n       if (arr[l] && arr[prev] && arr[next]) { n         v[l] = true; n         cnt++; n       } else { n         v[l] = false; n       } n     } n     if (cnt >= size) { n       cout <<  YES n ; n       return 0; n     } n   } n   cout <<  NO n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n namespace jyy { n const int mod = 998244353, N = 600010; n const double eps = 1e-8; n inline int read() { n   static int x = 0, f = 1; n   x = 0, f = 1; n   static char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     (ch ==  - ) ? f *= -1 : f; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) x = x * 10 + int(ch - 48), ch = getchar(); n   return x * f; n } n inline void fw(int x) { n   if (x < 0) putchar( - ), x = -x; n   x >= 10 ? fw(x / 10), 1 : 0; n   putchar(char(x % 10 + 48)); n } n inline int qmo(int x) { return x + ((x >> 31) & mod); } n inline int ksm(int x, int y) { n   int tmp = 1; n   for (; y; y >>= 1, x = 1ll * x * x % mod) n     if (y & 1) tmp = 1ll * tmp * x % mod; n   return tmp; n } n inline int inv(int x) { return ksm(x, mod - 2); } n int tot, head[N], fa[N]; n struct edge { n   int to, next; n } dat[N * 2]; n void add_edge(int x, int y) { dat[++tot] = (edge){y, head[x]}, head[x] = tot; } n inline int find(int x) { return fa[x] ? fa[x] = find(fa[x]) : x; } n inline int merge(int x, int y) { n   return find(x) != find(y) ? fa[find(x)] = find(y), 0 : 1; n } n inline int low(int x) { return x & -x; } n int ifac[N], fac[N]; n inline void init(int x) { n   fac[0] = ifac[0] = 1; n   for (int i = 1; i <= x; i++) fac[i] = 1ll * fac[i - 1] * i % mod; n   ifac[x] = inv(fac[x]); n   for (int i = x - 1; i >= 1; i--) ifac[i] = 1ll * ifac[i + 1] * (i + 1) % mod; n } n inline int C(int x, int y) { n   return (x < y || y < 0 || x < 0) n              ? 0 n              : 1ll * fac[x] * ifac[y] % mod * ifac[x - y] % mod; n } n }  // namespace jyy n using namespace jyy; n int pd[N], n, R[N], a[N], vis[N], dep[N], m, b[N]; n char c[N]; n void dfs(int x, int f) { n   vis[x] = 1; n   dep[x] = dep[f] + 1; n   fa[x] = f; n   for (int i = head[x]; i; i = dat[i].next) { n     int t = dat[i].to; n     if (t == f || vis[t]) continue; n     dfs(t, x); n   } n } n void work(int x, int y) { n   deque<int> q1, q2; n   while (dep[x] > dep[y]) q1.push_back(x), x = fa[x]; n   while (dep[x] < dep[y]) q2.push_front(y), y = fa[y]; n   while (x != y) q1.push_back(x), q2.push_front(y), x = fa[x], y = fa[y]; n   q1.push_back(x); n   cout << q1.size() + q2.size() << endl; n   while (q1.size()) printf( %d  , q1.front()), q1.pop_front(); n   while (q2.size()) printf( %d  , q2.front()), q2.pop_front(); n   puts(  ); n } n void solve() { n   n = read(), m = read(); n   for (int i = 1, x, y; i <= m; i++) n     x = read(), y = read(), add_edge(x, y), add_edge(y, x); n   dfs(1, 0); n   int q = read(); n   for (int i = 1; i <= q; i++) { n     a[i] = read(), b[i] = read(); n     pd[a[i]] ^= 1; n     pd[b[i]] ^= 1; n   } n   int cnt = 0; n   for (int i = 1; i <= n; i++) cnt += pd[i]; n   if (cnt) { n     puts( NO ); n     cout << cnt / 2 << endl; n     return; n   } n   puts( YES ); n   for (int i = 1; i <= q; i++) { n     work(a[i], b[i]); n   } n } n int main() { n   int T = 1; n   while (T--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) { n   return (a.first > b.first); n } n double gcd(double a, double b) { n   if (b == 0) return a; n   return gcd(b, double(int(a) % int(b))); n } n long long int power(long long int b, long long int e, long long int m) { n   if (e == 0) return 1; n   if (e & 1) return b * power(b * b % m, e / 2, m) % m; n   return power(b * b % m, e / 2, m); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int a; n   cin >> a; n   ; n   long long int b; n   cin >> b; n   ; n   long long int c; n   cin >> c; n   ; n   long long int d; n   cin >> d; n   ; n   long long int e; n   cin >> e; n   ; n   long long int f; n   cin >> f; n   ; n   long long int z = 0, ans = 0; n   if (f >= e) { n     z = min(c, d); n     z = min(z, b); n     ans += (f * z); n     d -= z; n     z = min(d, a); n     ans += (e * z); n   } else { n     z = min(a, d); n     ans += (e * z); n     d -= z; n     z = min(b, c); n     z = min(z, d); n     ans += (f * z); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n, k, p; n   cin >> n >> k >> p; n   bool odd = false, even = false; n   string ans =   ; n   if (n % 2 == 0) n     even = true; n   else { n     odd = true; n     k--; n   } n   for (int i = 0; i < p; i++) { n     long long tmp; n     cin >> tmp; n     if (even) { n       if (tmp % 2 == 0 && n - 2 * k < tmp) n         ans +=  X ; n       else if (tmp % 2 == 1 && n - 2 * (k - n / 2) < tmp) n         ans +=  X ; n       else n         ans +=  . ; n     } else { n       if (tmp == n && k >= 0) { n         ans +=  X ; n         continue; n       } n       if (tmp % 2 == 0 && n - 2 * k <= tmp) n         ans +=  X ; n       else if (tmp % 2 == 1 && n - 2 * (k - n / 2) <= tmp) n         ans +=  X ; n       else n         ans +=  . ; n     } n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int n, start, x; n int order[50005]; n pair<int, int> ask(int idx) { n   printf( ? %d n , idx); n   fflush(stdout); n   int val, nxt; n   scanf( %d%d , &val, &nxt); n   return pair<int, int>(val, nxt); n } n int main() { n   srand(time(0)); n   for (int i = 1; i < 50005; i++) order[i] = i; n   scanf( %d%d%d , &n, &start, &x); n   random_shuffle(order + 1, order + n + 1); n   int ptr = start, ptr_val = INT_MIN; n   for (int i = 1; i <= min(n, 1200); i++) { n     pair<int, int> p = ask(order[i]); n     if (p.first <= x && p.first >= ptr_val) ptr = order[i], ptr_val = p.first; n   } n   int ans = -1; n   while (ptr != -1) { n     pair<int, int> y = ask(ptr); n     if (y.first >= x) { n       ans = y.first; n       break; n     } n     ptr = y.second; n   } n   printf( ! %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n void optIO() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n } n const long long mod = 1e9 + 7, mod2 = 998244353, mod3 = 1e9 + 9; n long long p[5020], pp = 31, hh[5020]; n long long p2[5020], pp2 = 37, hh2[5020]; n int dp[5020]; n bool can[5020][5020]; n map<long long, bool> ms; n void solve() { n   int n, a, b; n   cin >> n >> a >> b; n   string s; n   cin >> s; n   p[0] = 1; n   p2[0] = 1; n   for (int i = 1; i < n + 1; ++i) { n     p[i] = (p[i - 1] * pp) % mod; n     p2[i] = (p2[i - 1] * pp2) % mod2; n     hh[i] = (hh[i - 1] + (s[i - 1] -  a  + 1) * p[i]) % mod; n     hh2[i] = (hh2[i - 1] + (s[i - 1] -  a  + 1) * p2[i]) % mod2; n   } n   for (int j = 1; j < n + 1; ++j) { n     for (int i = 1; i < n + 1; ++i) { n       if (i - 2 * j < 0) continue; n       long long y = n           ((hh[i - j] - hh[i - 2 * j] + mod) % mod * p[n - (i - j)]) % mod; n       long long y2 = n           ((hh2[i - j] - hh2[i - 2 * j] + mod2) % mod2 * p2[n - (i - j)]) % n           mod2; n       ms[y * mod2 + y2] = 1; n       long long x = ((hh[i] - hh[i - j] + mod) % mod * p[n - i]) % mod; n       long long x2 = ((hh2[i] - hh2[i - j] + mod2) % mod2 * p2[n - i]) % mod2; n       if (ms.find(x * mod2 + x2) != ms.end()) can[i][j] = 1; n     } n     ms.clear(); n   } n   for (int i = 1; i < n + 1; ++i) { n     dp[i] = dp[i - 1] + a; n     for (int j = 1; j < i + 1; ++j) { n       if (can[i][j]) dp[i] = min(dp[i], dp[i - j] + b); n     } n   } n   cout << dp[n] <<   n ; n } n int main() { n   optIO(); n   int t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n int n, x, y, att, cnt; n using namespace std; n int main() { n   cin >> n >> x >> y; n   if (x > y) return cout << n, 0; n   for (int i = (1); i <= (n); i++) { n     cin >> att; n     if (att <= x) cnt++; n   } n   cout << (cnt + 1) / 2; n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 6e5; n int n, d, f[M]; n int main() { n   cin >> n >> d; n   f[0] = 1; n   int now = 0, times = 0; n   for (int i = 0; i < n; i++) { n     int x; n     cin >> x; n     for (int j = M - 1; j >= x; j--) f[j] |= f[j - x]; n   } n   while (1) { n     int old = now; n     for (int i = 1; i <= d; i++) n       if (f[i + old]) now = old + i; n     if (now == old) break; n     times++; n   } n   cout << now <<     << times << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct point { n   double x, y; n   point operator-(point A) { return (point){x - A.x, y - A.y}; } n   double operator*(point A) { return x * A.y - y * A.x; } n   double dis() { return sqrt(x * x + y * y); } n } a[1005][1005], t[1005], E[1005]; n int n, vis[1005][1005]; n double r[1005][1005]; n point Mid(point a, point b) { n   return (point){(a.x + b.x) / 2, (a.y + b.y) / 2}; n } n double disline(int i, point A) { return abs(E[i] * (A - t[i]) / E[i].dis()); } n int ch(int R) { return R % n ? R % n : n; } n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) scanf( %lf%lf , &t[i].x, &t[i].y); n   for (int i = 1; i <= 2 * n; i++) t[n + i] = t[i]; n   for (int i = 1; i <= 3 * n; i++) E[i] = t[i + 1] - t[i]; n   for (int L = 1, R = L + 1, nw = L; L <= n; L++) n     for (R--, nw = max(L, nw); R == L || E[L] * E[R] > 0.5; R++) { n       while (nw < R && disline(L, t[nw + 1]) < disline(R, t[nw + 1])) ++nw; n       point le = t[nw], ri = t[nw + 1]; n       for (int j = 1; j <= 42; j++) { n         point mid = Mid(le, ri); n         if (disline(L, mid) < disline(R, mid)) n           le = mid; n         else n           ri = mid; n       } n       point P = Mid(le, ri); n       a[L][ch(R)] = P; n       r[L][ch(R)] = max(disline(L, P), disline(R, P)); n       vis[L][ch(R)] = 1; n     } n   double ans = 1e7; n   point a1, a2; n   for (int L = 1; L <= n; L++) n     for (int R = L; R <= L + n; R++) n       if (vis[L][ch(R)] && vis[ch(R + 1)][ch(L - 1 + n)]) { n         double newr = max(r[L][ch(R)], r[ch(R + 1)][ch(L - 1 + n)]); n         if (newr < ans) n           ans = newr, a1 = a[L][ch(R)], a2 = a[ch(R + 1)][ch(L - 1 + n)]; n       } n   printf( %.10f n%.10f %.10f n%.10f %.10f n , ans, a1.x, a1.y, a2.x, a2.y); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int Solve(int n) { n   int ten = 1; n   int ans = 0; n   while (n != 0) { n     if (n % 10 != 0) { n       ans += (ten * (n % 10)); n       ten *= 10; n     } n     n /= 10; n   } n   return ans; n } n long long int gcd(long long int a, long long int b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n bool prime(long long int i) { n   if (i == 1) return false; n   if ((i == 2) || (i == 3)) return true; n   if ((i % 2 == 0) || (i % 3 == 0)) n     return false; n   else { n     for (long long int j = 5; j * j <= i; j += 6) n       if ((i % j == 0) || (i % (j + 2) == 0)) return false; n   } n   return true; n } n int main() { n   int flag = 0; n   bool ok; n   int n, m, test, sum = 0, id1 = 0, id2 = 0, id3 = 0, dig1, dig2, dig3; n   int a, b; n   cin >> a >> b; n   int c = a + b; n   dig1 = Solve(a); n   dig2 = Solve(b); n   dig3 = Solve(c); n   if (dig1 + dig2 == dig3) { n     cout <<  YES ; n   } else { n     cout <<  NO ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n; n long long calcCards(long long x) { return x * (x + 1) + (x - 1) * x / 2; } n bool P(int x) { return calcCards(x) <= n; } n long long bs(long long l = 0, long long h = n) { n   long long m; n   while (l < h) { n     m = (l + h + 1) / 2; n     if (P(m)) n       l = m; n     else n       h = m - 1; n   } n   return l; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   cout << fixed; n   cout << setprecision(10); n   int t; n   cin >> t; n   while (t--) { n     cin >> n; n     int ans = 0; n     while (n >= 2) { n       ans++; n       n -= calcCards(bs()); n     } n     cout << ans << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = acos(-1.0); n void Fast() { n   std::ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n } n long long gcd(long long a, long long b) { return a ? gcd(b % a, a) : b; } n long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } n long long fact(long long n) { n   long long f = 1; n   for (int i = 2; i <= n; i++) { n     f *= i; n   } n   return f; n } n long long ncr(long long n, long long r) { n   return fact(n) / (fact(r) * fact(n - r)); n } n long long npr(long long n, long long r) { return fact(n) / fact(n - r); } n bool prime(long long n) { n   for (long long i = 2; i * i <= n; i++) { n     if (n % i == 0) { n       return 0; n       break; n     } n   } n   return 1; n } n char arr[55][55]; n void solve() { n   int n, m; n   cin >> n >> m; n   int r1 = INT_MIN, r2 = INT_MAX, c1 = INT_MIN, c2 = INT_MAX; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       cin >> arr[i][j]; n       if (arr[i][j] ==  * ) { n         r1 = max(r1, i); n         r2 = min(r2, i); n         c1 = max(c1, j); n         c2 = min(c2, j); n       } n     } n   } n   for (int i = r2; i <= r1; i++) { n     for (int j = c2; j <= c1; j++) { n       cout << arr[i][j]; n     } n     cout <<   n ; n   } n } n int main() { n   Fast(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n, d; n     cin >> n >> d; n     int ld = 0, rd = n * (n - 1) / 2; n     for (int i = 1, cd = 0; i <= n; ++i) { n       if (!(i & (i - 1))) ++cd; n       ld += cd - 1; n     } n     if (!(ld <= d && d <= rd)) { n       cout <<  NO  << endl; n       continue; n     } n     vector<int> par(n); n     iota(par.begin(), par.end(), -1); n     vector<int> cnt(n, 1); n     cnt[n - 1] = 0; n     vector<int> bad(n); n     vector<int> dep(n); n     iota(dep.begin(), dep.end(), 0); n     int cur = n * (n - 1) / 2; n     while (cur > d) { n       int v = -1; n       for (int i = 0; i < n; ++i) { n         if (!bad[i] && cnt[i] == 0 && (v == -1 || dep[v] > dep[i])) { n           v = i; n         } n       } n       assert(v != -1); n       int p = -1; n       for (int i = 0; i < n; ++i) { n         if (cnt[i] < 2 && dep[i] < dep[v] - 1 && (p == -1 || dep[p] < dep[i])) { n           p = i; n         } n       } n       if (p == -1) { n         bad[v] = 1; n         continue; n       } n       assert(dep[v] - dep[p] == 2); n       --cnt[par[v]]; n       --dep[v]; n       ++cnt[p]; n       par[v] = p; n       --cur; n     } n     cout <<  YES  << endl; n     for (int i = 1; i < n; ++i) cout << par[i] + 1 <<    ; n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N, K, D[1010], S[1010], ans, tt, crtMax; n int main() { n   int i; n   scanf( %i %i , &N, &K); n   for (i = 1; i <= N; i++) scanf( %i , &D[i]); n   for (i = 1; i <= N; i++) scanf( %i , &S[i]); n   for (i = 1; i <= N; i++) { n     crtMax = max(crtMax, S[i]); n     ans += S[i]; n     while (ans < D[i]) { n       ans += crtMax; n       tt += K; n     } n     tt += D[i]; n     ans -= D[i]; n   } n   printf( %i n , tt); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200000 + 10; n const long long INF = 0x3f3f3f3f3f3f3f3fLL; n long long dp[105][105][105]; n long long c[105], val[105][105], ans = INF; n int main() { n   int i, j, K, n, m, k; n   cin >> n >> m >> K; n   for (i = 1; i <= n; i++) cin >> c[i]; n   for (i = 1; i <= n; i++) { n     for (j = 1; j <= m; j++) { n       cin >> val[i][j]; n     } n   } n   memset(dp, 0x3f, sizeof(dp)); n   dp[0][0][0] = 0; n   for (i = 0; i < n; i++) { n     for (j = 0; j <= m; j++) { n       for (k = 0; k <= i; k++) { n         if (dp[i][j][k] != INF) { n           if (c[i + 1]) { n             dp[i + 1][c[i + 1]][k + (c[i + 1] != j)] = n                 min(dp[i + 1][c[i + 1]][k + (c[i + 1] != j)], dp[i][j][k]); n           } else { n             for (int p = 1; p <= m; p++) { n               dp[i + 1][p][k + (p != j)] = n                   min(dp[i][j][k] + val[i + 1][p], dp[i + 1][p][k + (p != j)]); n             } n           } n         } n       } n     } n   } n   for (i = 1; i <= m; i++) { n     ans = min(dp[n][i][K], ans); n   } n   if (ans == INF) n     cout << -1 << endl; n   else n     cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long fast_power(long long x, long long y) { n   if (y == 0) return 1; n   long long temp = fast_power(x, y / 2); n   temp = ((temp % 1000000007) * (temp % 1000000007)) % 1000000007; n   if (y % 2 != 0) temp = ((temp % 1000000007) * (x % 1000000007)) % 1000000007; n   return temp; n } n long long f[1000001]; n long long inv[1000001]; n long long ncr(long long n, long long r) { n   return ((((f[n] % 1000000007) * (inv[n - r] % 1000000007)) % 1000000007) * n           inv[r]) % n          1000000007; n } n long long nCr(long long n, long long r) { n   long long f = 1; n   long long x = 1; n   for (long long i = n; i > n - r; i--) { n     f *= i; n     f /= x++; n   } n   return f; n } n long long npr(long long n, long long r) { n   return (f[n] % 1000000007 * inv[n - r] % 1000000007) % 1000000007; n } n int main() { n   long long n, r, t; n   cin >> n >> r >> t; n   f[0] = 1; n   inv[0] = 1; n   for (long long i = 1; i <= n; i++) { n     f[i] = (f[i - 1] * i) % 1000000007; n     inv[i] = fast_power(f[i], 1000000007 - 2); n   } n   long long sum = 0; n   if (n >= 4) n     for (long long i = 4; i < t; i++) { n       if (t - i <= r) sum += nCr(n, i) * nCr(r, t - i); n     } n   cout << sum <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   int n, m; n   cin >> n >> m; n   vector<int> a(n); n   for (auto& x : a) cin >> x, --x; n   vector<int> k(m); n   for (auto& x : k) cin >> x; n   for (int i = 0; i < n; ++i) n     for (int j = i + 1; j <= n; ++j) { n       vector<int> cur(m); n       for (int l = i; l < j; ++l) ++cur[a[l]]; n       if (cur == k) { n         cout <<  YES n ; n         return 0; n       } n     } n   cout <<  NO n ; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n void nexts(T *, int); n template <typename T> n void dump(T *arr, int cnt, char sep =    ); n void __init__(bool, bool); n const int MAXMAXMAX = 1000 * 1000 * 1000; n string a, b, c; n char ans[100015]; n vector<int> cnt_a(26); n vector<int> cnt_b(26); n vector<int> cnt_c(26); n int main() { n   __init__(1, 0); n   cin >> a >> b >> c; n   for (int(i) = (0); (i) < (a.size()); ++(i)) ++cnt_a[a[i] -  a ]; n   for (int(i) = (0); (i) < (b.size()); ++(i)) ++cnt_b[b[i] -  a ]; n   for (int(i) = (0); (i) < (c.size()); ++(i)) ++cnt_c[c[i] -  a ]; n   int b_max = MAXMAXMAX; n   for (int(i) = (0); (i) < (26); ++(i)) n     if (cnt_b[i] != 0) b_max = min(b_max, cnt_a[i] / cnt_b[i]); n   int max_ans = 0; n   int max_b = 0; n   int max_c = 0; n   if (b_max == MAXMAXMAX) b_max = 0; n   vector<int> tmp = cnt_a; n   for (int(i) = (0); (i) < (b_max + 1); ++(i)) { n     if (i != 0) n       for (int(i) = (0); (i) < (26); ++(i)) tmp[i] -= cnt_b[i]; n     int c_max = MAXMAXMAX; n     for (int(i) = (0); (i) < (26); ++(i)) n       if (cnt_c[i] != 0) c_max = min(c_max, tmp[i] / cnt_c[i]); n     if (c_max == MAXMAXMAX) b_max = 0; n     if (i + c_max > max_ans) { n       max_ans = i + c_max; n       max_b = i; n       max_c = c_max; n     } n   } n   for (int(i) = (0); (i) < (max_b); ++(i)) cout << b; n   for (int(i) = (0); (i) < (max_c); ++(i)) cout << c; n   for (int(i) = (0); (i) < (26); ++(i)) { n     cnt_a[i] -= max_b * cnt_b[i] + max_c * cnt_c[i]; n     for (int(j) = (0); (j) < (cnt_a[i]); ++(j)) cout << (char)( a  + i); n   } n   cout <<   n ; n   return 0; n } n template <typename T> n void nexts(T *arr, int cnt) { n   for (int i = 0; i < cnt; ++i) cin >> arr[i]; n } n template <typename T> n void dump(T *arr, int cnt, char sep) { n   for (int i = 0; i < cnt; ++i) cout << arr[i] << sep; n } n void __init__(bool fastIOstream, bool acmp) { n   if (fastIOstream) { n     ios_base::sync_with_stdio(false); n     cin.tie(0); n   } n   if (acmp) { n     freopen( INPUT.TXT ,  rt , stdin); n     freopen( OUTPUT.TXT ,  wt , stdout); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, c; n   cin >> a >> b >> c; n   int x = sqrt(a * c / b), y = sqrt(a * b / c), z = sqrt(b * c / a); n   cout << (x + y + z) * 4; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long nMod = 1e9 + 7; n inline long long GCD(long long a, long long b) { n   while (b != 0) { n     long long c = a % b; n     a = b; n     b = c; n   } n   return a; n }; n inline long long LCM(long long a, long long b) { return (a / GCD(a, b)) * b; }; n int m, n, k; n vector<set<int>> st(55); n void vietnakid() { n   cin >> m >> n; n   for (int i = 0; i < m; i++) { n     cin >> k; n     for (int j = 0; j < k; j++) { n       int x; n       cin >> x; n       st[i].insert(x); n     } n   } n   bool check = true; n   for (int i = 0; i < m; i++) { n     if (!check) break; n     for (int j = 0; j < m; j++) { n       bool ok = false; n       for (auto x : st[i]) { n         if (ok) break; n         if (st[j].count(x)) { n           ok = true; n         } n       } n       if (!ok) { n         check = false; n         break; n       } n     } n   } n   if (check) { n     cout <<  possible n ; n   } else { n     cout <<  impossible n ; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(); n   vietnakid(); n   cerr <<   nTime elapsed:   << 1000 * clock() / CLOCKS_PER_SEC <<  ms n ; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3,unroll-loops ) n #pragma pack(0) n using namespace std; n vector<string> v[1000001]; n string s; n int ptr = 0, maxd = 0; n void dfs(int dis) { n   maxd = max(maxd, dis); n   int k = 0, f = ptr; n   for (; ptr < s.length(); ptr++) n     if (s[ptr] ==  , ) break; n   string t = s.substr(f, ptr - f); n   ptr++; n   for (; ptr < s.length(); ptr++) { n     if (s[ptr] ==  , ) break; n     k = k * 10 + (s[ptr] -  0 ); n   } n   ptr++; n   v[dis].emplace_back(t); n   for (int i = 1; i <= k; i++) dfs(dis + 1); n } n signed main() { n   ios::sync_with_stdio(0), cin.tie(0); n   cin >> s; n   while (ptr < s.length()) dfs(0); n   cout << maxd + 1 <<   n ; n   for (int i = 0; !v[i].empty(); i++) { n     for (auto j : v[i]) cout << j <<    ; n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n class Solution { n   int n, x[2]; n   vector<pair<long long, int>> A; n  n  public: n   void run() { n     cin >> n >> x[0] >> x[1]; n     for (int i = 0; i < n; ++i) { n       int c; n       cin >> c; n       A.emplace_back(c, i); n     } n     sort(A.begin(), A.end()); n     for (int i = 0; i < n; ++i) { n       int a = A[i].first; n       int j = (x[0] + a - 1) / a + i; n       if (j < n and x[1] <= A[j].first * (n - j)) { n         cout <<  Yes n ; n         cout << j - i <<     << n - j <<   n ; n         for (int k = i; k < j; ++k) n           cout << A[k].second + 1 <<    n [k == j - 1]; n         for (int k = j; k < n; ++k) n           cout << A[k].second + 1 <<    n [k == n - 1]; n         return; n       } n       j = (x[1] + a - 1) / a + i; n       if (j < n and x[0] <= A[j].first * (n - j)) { n         cout <<  Yes n ; n         cout << n - j <<     << j - i <<   n ; n         for (int k = j; k < n; ++k) n           cout << A[k].second + 1 <<    n [k == n - 1]; n         for (int k = i; k < j; ++k) n           cout << A[k].second + 1 <<    n [k == j - 1]; n         return; n       } n     } n     cout <<  No n ; n   } n }; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   Solution().run(); n } n


#include <bits/stdc++.h> n using namespace std; n bool isPrime(int a, int p) { n   return (a <= p) || ((a % p != 0) && (isPrime(a, p + 1))); n } n int main() { n   const int N = 256; n   int freq[N] = {0}; n   string s; n   cin >> s; n   int len = s.size(); n   for (int p = 0; p < len; p++) { n     ++freq[s[p]]; n   } n   string t(len, 0); n   int *m = max_element(freq, freq + N); n   for (int p = 1; p < len; p++) { n     if ((p < len / 2) || (!isPrime(p + 1, 2))) { n       t[p] = m - freq; n       (*m)--; n     } n   } n   if (*m < 0) { n     cout <<  NO  << endl; n   } else { n     int q = 0; n     for (int p = 0; p < len; p++) { n       if (!t[p]) { n         while (!freq[q]) { n           q++; n         } n         freq[t[p] = q]--; n       } n     } n     cout <<  YES  << endl << t << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n bool cmp(pair<int, int> a, pair<int, int> b) { n   if (a.first != b.first) return a.first > b.first; n   return a.second < b.second; n } n bool cmp2(pair<int, int> a, pair<int, int> b) { return a.second < b.second; } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   vector<pair<int, int> > v; n   for (int i = 1; i <= n; i++) { n     int x; n     cin >> x; n     v.push_back({x, i}); n   } n   sort(v.begin(), v.end(), cmp); n   cin >> m; n   while (m--) { n     int k, pos; n     cin >> k >> pos; n     vector<pair<int, int> > res; n     for (int i = 0; i < k; i++) { n       res.push_back(v[i]); n     } n     sort(res.begin(), res.end(), cmp2); n     cout << res[pos - 1].first <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using PII = pair<int, int>; n const int mod = 998244353; n const int inf = 1 << 30; n const int maxn = 200000 + 5; n int n, tot, tin[maxn], tout[maxn], rid[maxn], vis[maxn], deg[maxn]; n vector<int> edge[maxn]; n int query(int x, int y) { n   cout <<  ?   << x <<     << y << endl; n   cin >> x; n   assert(x >= 1 && x <= n); n   return x; n } n int ok[maxn]; n void dfs(int u, int f) { n   tin[u] = ++tot; n   rid[tot] = u; n   for (int v : edge[u]) { n     if (v == f) continue; n     dfs(v, u); n   } n   tout[u] = tot; n } n bool check(int x, int y) { return tin[x] <= tin[y] && tout[y] <= tout[x]; } n int main() { n   scanf( %d , &n); n   ok[1] = true; n   for (int i = 2, u, v; i <= n; i++) { n     scanf( %d%d , &u, &v); n     ok[i] = true; n     edge[u].push_back(v); n     edge[v].push_back(u); n     deg[u]++; n     deg[v]++; n   } n   dfs(1, 0); n   vector<int> v; n   for (int i = 1; i <= n; i++) n     if (deg[i] == 1) v.push_back(i); n   assert(v.size() >= 2); n   for (int i = 1; i < (int)v.size(); i += 2) { n     int ans = query(v[i - 1], v[i]); n     for (int y : edge[ans]) { n       if (check(ans, y)) { n         if (check(y, v[i - 1]) || check(y, v[i])) { n           for (int j = tin[y]; j <= tout[y]; j++) { n             ok[rid[j]] = false; n           } n         } n       } else { n         if (!check(ans, v[i - 1]) || !check(ans, v[i])) { n           for (int j = 1; j < tin[ans]; j++) { n             ok[rid[j]] = false; n           } n           for (int j = tout[ans] + 1; j <= n; j++) { n             ok[rid[j]] = false; n           } n         } n       } n     } n   } n   v.clear(); n   for (int i = 1; i <= n; i++) { n     if (!ok[i]) continue; n     int c = 0; n     for (int v : edge[i]) { n       if (ok[v]) c++; n     } n     assert(c <= 2); n     if (c == 1) { n       v.push_back(i); n     } n   } n   if (v.size() == 0) { n     for (int i = 1; i <= n; i++) { n       if (ok[i]) { n         cout <<  !   << i << endl; n         return 0; n       } n     } n   } else if (v.size() == 2) { n     int r = query(v[0], v[1]); n     cout <<  !   << r << endl; n   } else { n     assert(false); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1000000000; n const long long LINF = 4000000000000000000LL; n const double eps = 1e-9; n void prepare() {} n int a, n; n int day[10000008]; n void read() { scanf( %d%d , &a, &n); } n void solve() { n   read(); n   for (int i = 1; i * i < a + n; i++) { n     int ii = i * i; n     for (int j = ii; j < a + n; j += ii) day[j] = i * i; n   } n   long long res = 0; n   for (int i = a; i < a + n; i++) res += i / day[i]; n   cout << res << endl; n } n int main() { n   prepare(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 100005; n long long t, l, i, j, k, p, q, u, v, n, color[1000005]; n string s; n vector<long long> zro; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> q; n   for (l = 1; l <= q; l++) { n     cin >> n >> k >> s; n     for (i = 0; i < n; i++) { n       if (s[i] ==  0 ) n         zro.push_back(i); n       else n         color[i] = 1; n     } n     u = 0; n     v = 0; n     for (i = 0; i < zro.size(); i++) { n       if (u == n || k == 0) break; n       for (; u < n; u++) { n         if (zro[i] < u) break; n         if (color[u] == 1 && zro[i] - u <= k) { n           k -= (zro[i] - u); n           color[zro[i]] = 1; n           color[u] = 0; n           swap(s[u], s[zro[i]]); n           u++; n           break; n         } n       } n     } n     cout << s << endl; n     for (i = 0; i <= n; i++) color[i] = 0; n     zro.clear(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, sum = 0; n   string s; n   cin >> a; n   for (int i = 0; i < a; i++) { n     cin >> s; n     if (s ==  Tetrahedron ) n       sum = sum + 4; n     else if (s ==  Cube ) n       sum = sum + 6; n     else if (s ==  Octahedron ) n       sum = sum + 8; n     else if (s ==  Dodecahedron ) n       sum = sum + 12; n     else if (s ==  Icosahedron ) n       sum = sum + 20; n   } n   cout << sum; n   return 0; n } n