#include <bits/stdc++.h> n struct data { n   int val; n   data(int val) : val(val) {} n }; n bool operator<(const data lhs, const data rhs) { n   std::cout <<  ?   << lhs.val <<     << rhs.val << std::endl; n   char c; n   std::cin >> c; n   return c ==  < ; n } n int t, n; n std::set<data> a, b; n int main() { n   std::ios_base::sync_with_stdio(false); n   std::cin.tie(nullptr); n   std::cout.tie(nullptr); n   std::cin >> t; n   while (t--) { n     std::cin >> n; n     a.clear(); n     b.clear(); n     for (int i = 1; i <= 2 * n; ++i) { n       if (a.size() < b.size()) n         a.emplace(i); n       else n         b.emplace(i); n       if (a.size() + b.size() > n) n         if (*a.begin() < *b.begin()) n           a.erase(a.begin()); n         else n           b.erase(b.begin()); n     } n     std::cout <<  !  << std::endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int n; n long long int f(long long int x) { n   long long int sq = sqrt(x); n   for (long long int i = 2; i <= sq; i++) n     if (x % i == 0) return 0; n   return 1; n } n int main() { n   cin >> n; n   if (f(n)) { n     cout << 1 << endl << n << endl; n     return 0; n   } n   cout << 3 << endl; n   cout << 3 <<    ; n   n -= 3; n   for (long long int i = 2; i < n; i++) { n     if (f(i) && f(n - i)) return cout << i <<     << n - i << endl, 0; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, q; n const int N = 2e5 + 10; n const int inf = 1e9; n char s[N]; n struct Node { n   Node() { n     for (int i = 0; i < 5; i++) { n       for (int j = 0; j < 5; j++) { n         dp[i][j] = (i == j) ? 0 : inf; n       } n     } n   } n   int dp[5][5]; n }; n Node operator*(const Node& u, const Node& v) { n   Node ans; n   for (int i = 0; i < 5; i++) { n     for (int j = 0; j < 5; j++) { n       ans.dp[i][j] = inf; n       for (int k = 0; k < 5; k++) { n         ans.dp[i][j] = min(u.dp[i][k] + v.dp[k][j], ans.dp[i][j]); n       } n     } n   } n   return ans; n } n Node nodes[N * 4]; n void build_tree(int l, int r, int rt) { n   Node& v = nodes[rt]; n   if (l == r) { n     char c = s[l - 1]; n     if (c ==  2 ) { n       v.dp[0][0] = 1; n       v.dp[0][1] = 0; n     } else if (c ==  0 ) { n       v.dp[1][1] = 1; n       v.dp[1][2] = 0; n     } else if (c ==  1 ) { n       v.dp[2][2] = 1; n       v.dp[2][3] = 0; n     } else if (c ==  7 ) { n       v.dp[3][3] = 1; n       v.dp[3][4] = 0; n     } else if (c ==  6 ) { n       v.dp[3][3] = 1; n       v.dp[4][4] = 1; n     } n     return; n   } n   int m = (l + r) >> 1; n   build_tree(l, m, 2 * rt); n   build_tree(m + 1, r, 2 * rt + 1); n   v = nodes[2 * rt] * nodes[2 * rt + 1]; n } n Node query(int L, int R, int l, int r, int rt) { n   Node& v = nodes[rt]; n   if (L <= l && R >= r) return v; n   int m = (l + r) >> 1; n   bool left = false, right = false; n   Node ltemp, rtemp; n   if (L <= m) { n     ltemp = query(L, R, l, m, rt * 2); n     left = true; n   } n   if (R > m) { n     rtemp = query(L, R, m + 1, r, rt * 2 + 1); n     right = true; n   } n   if (left && right) return ltemp * rtemp; n   if (left) return ltemp; n   if (right) return rtemp; n } n int main() { n   scanf( %d %d , &n, &q); n   scanf( %s , s); n   build_tree(1, n, 1); n   for (int i = 0; i < q; i++) { n     int l, r; n     scanf( %d %d , &l, &r); n     Node v = query(l, r, 1, n, 1); n     if (v.dp[0][4] == inf) n       cout << -1 << endl; n     else n       cout << v.dp[0][4] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct Point { n   int x; n   int y; n   Point(int x_, int y_) : x(x_), y(y_) {} n }; n template <class T> n T sqr(const T& t) { n   return t * t; n } n template <class T> n T abs(const T& t) { n   return ((t > 0) ? (t) : (-t)); n } n void initialize() { n   freopen( _.in ,  r , stdin); n   freopen( _.out ,  w , stdout); n } n bool isSqr(int x) { n   int a = static_cast<int>(sqrt(static_cast<double>(x))); n   return (a * a == x); n } n int sqrt(int x) { return static_cast<int>(sqrt(static_cast<double>(x))); } n int sign(int x) { n   if (x < 0) return 0; n   return 1; n } n int main() { n   int x, y; n   cin >> x >> y; n   int r = x * x + y * y; n   bool ok = true; n   int b = sqrt(r); n   int val = 2 + sign(x * y) + sqrt(r); n   if (isSqr(r) || (sign(x * y) + sqrt(r)) % 2 == 1) { n     cout <<  black ; n   } else { n     cout <<  white ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int res[100005], sz; n bool prime[100005], used[100005]; n int main() { n   int n; n   cin >> n; n   for (int p = 2; p <= n / 2; ++p) { n     if (prime[p]) continue; n     for (int j = p; j <= n; j += p) prime[j] = 1; n     if (p == 2) continue; n     int len = 0; n     for (int j = p; j <= n; j += p) { n       if (j == 2 * p) continue; n       if (used[j]) continue; n       used[j] = 1; n       res[sz++] = j; n       len++; n     } n     if (len & 1) { n       res[sz++] = 2 * p; n       used[2 * p] = 1; n     } n   } n   for (int i = 2; i <= n; i += 2) n     if (!used[i]) res[sz++] = i; n   cout << sz / 2 << endl; n   for (int i = 0; i + 1 < sz; i += 2) printf( %d %d n , res[i], res[i + 1]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long mul(long long a, long long b) { return (a * b) % 1000000007; } n long long add(long long a, long long b) { n   a += b; n   if (a >= 1000000007) a -= 1000000007; n   return a; n } n long long binary_expo(long long base, long long expo) { n   long long res = 1; n   while (expo) { n     if (expo % 2) { n       res = mul(res, base); n     } n     expo /= 2; n     base = mul(base, base); n   } n   return res; n } n void solve() { n   long long n; n   cin >> n; n   cout << n <<   n ; n   for (long long i = 1; i <= n; i++) { n     cout <<  1  ; n   } n   cout <<   n ; n } n signed main() { n   long long t; n   ios_base::sync_with_stdio(false); n   t = 1; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long n, a[3][333333], x, y, sum[4][333333], r[4][333333]; n set<pair<long long, long long> > s[333333]; n map<pair<long long, long long>, long long> d; n map<long long, long long> last[4]; n void read(long long &x) { scanf( %lld , &x); } n int main() { n   cin >> n; n   for (long long i = 1; i <= 2; i++) n     for (long long j = 1; j <= n; j++) read(a[i][j]); n   for (long long i = 1; i <= 2; i++) n     for (long long j = n; j >= 1; j--) { n       sum[i][j] = sum[i][j + 1] + a[i][j]; n       sum[3][j] += sum[i][j]; n     } n   last[1][0] = last[2][0] = last[3][0] = n + 1; n   r[1][n + 1] = r[2][n + 1] = r[3][n + 1] = n + 1; n   for (long long i = 1; i <= 3; i++) n     for (long long j = n; j >= 1; j--) { n       r[i][j] = r[i][j + 1]; n       if (last[i].count(sum[i][j])) n         r[i][j] = min(r[i][j], last[i][sum[i][j]] - 1); n       last[i][sum[i][j]] = j; n     } n   s[0].insert(make_pair(0, 0)); n   d[make_pair(0, 0)] = 0; n   for (long long i = 0; i < n; i++) { n     for (pair<long long, long long> cur : s[i]) { n       x = cur.first; n       y = cur.second; n       if (x <= y) { n         s[min(x + 1, y)].insert(make_pair(x + 1, y)); n         d[make_pair(x + 1, y)] = n             max(d[make_pair(x + 1, y)], d[make_pair(x, y)]); n         s[min(r[1][x + 1], y)].insert(make_pair(r[1][x + 1], y)); n         d[make_pair(r[1][x + 1], y)] = n             max(d[make_pair(r[1][x + 1], y)], d[make_pair(x, y)] + 1); n       } n       if (y <= x) { n         s[min(x, y + 1)].insert(make_pair(x, y + 1)); n         d[make_pair(x, y + 1)] = n             max(d[make_pair(x, y + 1)], d[make_pair(x, y)]); n         s[min(r[2][y + 1], x)].insert(make_pair(x, r[2][y + 1])); n         d[make_pair(x, r[2][y + 1])] = n             max(d[make_pair(x, r[2][y + 1])], d[make_pair(x, y)] + 1); n       } n       if (x == y) { n         s[r[3][x + 1]].insert(make_pair(r[3][x + 1], r[3][x + 1])); n         d[make_pair(r[3][x + 1], r[3][x + 1])] = n             max(d[make_pair(r[3][x + 1], r[3][x + 1])], d[make_pair(x, y)] + 1); n       } n       d.erase(make_pair(x, y)); n     } n     s[i].clear(); n   } n   assert(d.size() <= 4 * n); n   cout << d[make_pair(n, n)]; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { n   if (a > b) swap(a, b); n   if (a == 0) return b; n   return gcd(b % a, a); n } n int log2(int x, int max) { return max - __builtin_clz(x) - 1; } n long long powerMod(long long x, long long y) { n   long long res = 1; n   x %= 1000000007; n   while (y > 0) { n     if (y & 1) res = (res * x) % 1000000007; n     y = y >> 1; n     x = (x * x) % 1000000007; n   } n   return res; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   int n, m, i, j, k, l, x, y, c; n   vector<pair<int, int> > v, dir; n   cin >> n >> m; n   string s[n]; n   int row[n][m]; n   int col[n][m]; n   memset((row), 0, sizeof((row))); n   memset((col), 0, sizeof((col))); n   for (i = 0; i < n; i++) { n     row[i][0] = 1; n   } n   for (i = 0; i < m; i++) { n     col[0][i] = 1; n   } n   for (i = 0; i < n; i++) { n     cin >> s[i]; n     for (j = 0; j < m; j++) { n       if (s[i][j] >=  A  && s[i][j] <=  Z ) v.push_back(make_pair(i, j)); n       if (j > 0) { n         if (s[i][j] ==  # ) n           row[i][j] = row[i][j - 1] + 1; n         else n           row[i][j] = row[i][j - 1]; n       } n       if (i > 0) { n         if (s[i][j] ==  # ) n           col[i][j] = col[i - 1][j] + 1; n         else n           col[i][j] = col[i - 1][j]; n       } n     } n   } n   cin >> k; n   string st; n   for (i = 0; i < k; i++) { n     cin >> st >> l; n     if (st[0] ==  N ) dir.push_back(make_pair(0, l)); n     if (st[0] ==  S ) dir.push_back(make_pair(1, l)); n     if (st[0] ==  E ) dir.push_back(make_pair(2, l)); n     if (st[0] ==  W ) dir.push_back(make_pair(3, l)); n   } n   st =   ; n   for (l = 0; l < v.size(); l++) { n     x = v[l].first, y = v[l].second; n     for (i = 0; i < k; i++) { n       j = dir[i].first; n       c = dir[i].second; n       if (j == 0) { n         if (x < c) goto loop; n         if (col[x][y] - col[x - c][y] == 0 && s[x - c][y] !=  # ) n           x -= c; n         else n           goto loop; n       } n       if (j == 1) { n         if (x + c >= n) goto loop; n         if (col[x + c][y] - col[x][y] == 0) n           x += c; n         else n           goto loop; n       } n       if (j == 2) { n         if (y + c >= m) goto loop; n         if (row[x][y + c] - row[x][y] == 0) n           y += c; n         else n           goto loop; n       } n       if (j == 3) { n         if (y < c) goto loop; n         if (row[x][y] - row[x][y - c] == 0 && s[x][y - c] !=  # ) n           y -= c; n         else n           goto loop; n       } n     } n     st += s[v[l].first][v[l].second]; n   loop:; n   } n   if (st ==   ) { n     cout <<  no solution n ; n     return 0; n   } n   sort(st.begin(), st.end()); n   cout << st << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = 1e9; n const long long base = 1e9 + 7; n const int N = 5e3 + 2; n int n, m, k; n int a[N][N]; n pair<int, int> h[N], c[N]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> n >> m >> k; n   long long x, y, z; n   for (int i = (1), b_ = (k); i <= b_; ++i) { n     cin >> x >> y >> z; n     if (x == 1) { n       h[y].first = z; n       h[y].second = i; n     } else { n       c[y].first = z; n       c[y].second = i; n     } n   } n   for (int i = (1), b_ = (n); i <= b_; ++i) { n     for (int j = (1), b_ = (m); j <= b_; ++j) { n       if (h[i].second == 0 && c[j].second == 0) n         cout << 0 <<    ; n       else if (h[i].second > c[j].second) n         cout << h[i].first <<    ; n       else n         cout << c[j].first <<    ; n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = (int)1e5 + 5, INF = (int)1e9; n const long double EPS = 1e-9; n int t[N], h[N], m[N]; n bool used[N]; n int main() { n   int n, cur, ans = 0, ans1 = 0, tp, v = -1, first; n   cin >> n >> first; n   cur = first; n   for (int i = 0; i < n; i++) cin >> t[i] >> h[i] >> m[i]; n   for (int i = 0; i < n; i++) n     if (t[i] == 0 && h[i] <= cur && (v == -1 || m[i] > m[v])) v = i; n   tp = 0; n   if (v != -1) { n     used[v] = 1; n     cur += m[v]; n     ans++; n   } n   for (int i = 0; i < n; i++) { n     v = -1; n     for (int j = 0; j < n; j++) n       if (!used[j] && t[j] != tp && h[j] <= cur && (v == -1 || m[j] > m[v])) n         v = j; n     if (v == -1) n       break; n     else { n       tp = 1 - tp; n       used[v] = 1; n       cur += m[v]; n       ans++; n     } n   } n   tp = 1; n   v = -1; n   cur = first; n   for (int i = 0; i < n; i++) used[i] = 0; n   for (int i = 0; i < n; i++) n     if (t[i] == 1 && h[i] <= cur && (v == -1 || m[i] > m[v])) v = i; n   if (v != -1) { n     used[v] = 1; n     cur += m[v]; n     ans1++; n   } n   for (int i = 0; i < n; i++) { n     v = -1; n     for (int j = 0; j < n; j++) n       if (!used[j] && t[j] != tp && h[j] <= cur && (v == -1 || m[j] > m[v])) n         v = j; n     if (v == -1) n       break; n     else { n       tp = 1 - tp; n       used[v] = 1; n       cur += m[v]; n       ans1++; n     } n   } n   cout << max(ans, ans1) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 7; n long long arr[maxn]; n string s; n int main() { n   std::ios::sync_with_stdio(false); n   int n; n   cin >> n; n   long long tot = 0; n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n     arr[i] *= 2; n     tot += arr[i]; n   } n   cin >> s; n   long long W = 0, G = 0, flag = 5; n   for (int i = 0; i < n; i++) { n     if (s[i] ==  G ) n       G += arr[i]; n     else if (s[i] ==  W ) n       W += arr[i], flag = 3; n     long long cur = arr[i], sta; n     sta = min(cur / 2, W), tot += sta * 2, cur -= sta * 2, W -= sta; n     sta = min(cur / 2, G), tot += sta * 4, cur -= sta * 2, G -= sta; n     tot += flag * cur; n   } n   cout << tot / 2 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   cin >> n >> k; n   string s, A( a ); n   cin >> s; n   vector<vector<int> > a(26); n   for (int i = 0; i < k; i++) a[s[i] - A[0]].push_back(i); n   for (int i = 0; i < n; i++) { n     cin >> s; n     long long ans = 0; n     for (int j = 0; j < s.size(); j++) { n       int b = (int)s[j] - A[0]; n       int r = (int)a[b].size(); n       if (r == 0) n         ans += s.size(); n       else { n         r--; n         int l = 0; n         while (r - l > 1) { n           int m = (l + r) / 2; n           if (a[b][m] >= j) n             r = m; n           else n             l = m; n         } n         ans += min(abs(a[b][l] - j), abs(a[b][r] - j)); n       } n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); n void print_time() {} n template <typename T> n void update_max(T& x, T y) { n   x = max(x, y); n } n template <typename T> n void update_min(T& x, T y) { n   x = min(x, y); n } n template <class T1, class T2> n ostream& operator<<(ostream& out, pair<T1, T2> pair) { n   return out <<  (  << pair.first <<  ,   << pair.second <<  ) ; n } n template <class T> n ostream& operator<<(ostream& out, vector<T> vec) { n   out <<  ( ; n   for (auto& v : vec) out << v <<  ,  ; n   return out <<  ) ; n } n template <class T> n ostream& operator<<(ostream& out, set<T> vec) { n   out <<  ( ; n   for (auto& v : vec) out << v <<  ,  ; n   return out <<  ) ; n } n template <class L, class R> n ostream& operator<<(ostream& out, map<L, R> vec) { n   out <<  ( ; n   for (auto& v : vec) out << v <<  ,  ; n   return out <<  ) ; n } n long long ask(long long t, long long i, long long j, long long k) { n   ++i, ++j, ++k; n   cout << t <<     << i <<     << j <<     << k << endl; n   long long res; n   cin >> res; n   return res; n } n void ans(vector<long long> p) { n   cout <<  0  ; n   for (long long pp : p) { n     cout << pp + 1 <<    ; n   } n   cout << endl; n } n int main() { n   cout << fixed << setprecision(20); n   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   long long n; n   cin >> n; n   vector<long long> area(n); n   vector<long long> sign(n); n   for (long long i = 2; i < n; ++i) { n     area[i] = ask(1, 0, 1, i); n     sign[i] = ask(2, 0, 1, i); n   } n   vector<long long> cnt_sign(2); n   vector<set<pair<long long, long long>>> pos(2); n   for (long long i = 2; i < n; ++i) { n     pos[(sign[i] + 1) / 2].insert({area[i], i}); n     ++cnt_sign[(sign[i] + 1) / 2]; n   } n   vector<vector<long long>> sorted(2); n   for (long long kek = 0; kek < 2; ++kek) { n     sorted[kek] = vector<long long>(cnt_sign[kek]); n     long long l = 0; n     long long r = cnt_sign[kek] - 1; n     while (!pos[kek].empty()) { n       pair<long long, long long> curr = *pos[kek].begin(); n       pos[kek].erase(pos[kek].begin()); n       long long i = 0; n       long long j = curr.second; n       if (pos[kek].empty()) { n         sorted[kek][l] = j; n         break; n       } n       long long k = pos[kek].begin()->second; n       long long q = ask(2, i, j, k); n       if (q > 0) { n         sorted[kek][l++] = j; n       } else { n         sorted[kek][r--] = j; n       } n     } n   } n   vector<long long> p; n   p.push_back(0); n   for (long long v : sorted[0]) p.push_back(v); n   p.push_back(1); n   for (long long v : sorted[1]) p.push_back(v); n   ans(p); n   print_time(); n   return 0; n } n


#include<bits/stdc++.h> n using namespace std; n int main() n { n  ios_base::sync_with_stdio(false); n     cin.tie(NULL); n  long long t; n  cin >> t; n  while(t--) n  { n   long long n; n   cin >> n; n   string a[n]; n   for(long long i=0;i<n;i++) n   { n    cin >> a[i]; n   } n   for(long long i=0;i<10;i++) n   { n    long long ans=0; n    std::vector<pair<long long,long long> > x,y; n    for(long long j=0;j<n;j++) n    { n     for(long long k=0;k<n;k++) n     { n      if(a[j][k]==((char)i+ 0 )) n      { n       x.push_back(make_pair(j,k) ); n       y.push_back(make_pair(k,j) ); n      } n     } n    } n    sort(x.begin(), x.end()); n    sort(y.begin(), y.end()); n    for(long long k=0;k<x.size();k++) n     { n      long long x1=x[0].first,y1=x[0].second,x2=x[k].first,y2=x[k].second; n      ans=max(ans,abs(x1-x2)*max(max(y1,n-y1-1),max(y2,n-y2-1))); n      ans=max(ans,abs(y1-y2)*max(max(x1,n-x1-1),max(x2,n-x2-1))); n     } n    for(long long k=0;k<x.size();k++) n     { n      long long x1=x[k].first,y1=x[k].second,x2=x[x.size()-1].first,y2=x[x.size()-1].second; n      ans=max(ans,abs(x1-x2)*max(max(y1,n-y1-1),max(y2,n-y2-1))); n      ans=max(ans,abs(y1-y2)*max(max(x1,n-x1-1),max(x2,n-x2-1))); n     } n    for(long long k=0;k<y.size();k++) n     { n      long long y1=y[0].first,x1=y[0].second,y2=y[k].first,x2=y[k].second; n      ans=max(ans,abs(x1-x2)*max(max(y1,n-y1-1),max(y2,n-y2-1))); n      ans=max(ans,abs(y1-y2)*max(max(x1,n-x1-1),max(x2,n-x2-1))); n     } n    for(long long k=0;k<y.size();k++) n     { n      long long y1=y[k].first,x1=y[k].second,y2=y[y.size()-1].first,x2=y[y.size()-1].second; n      ans=max(ans,abs(x1-x2)*max(max(y1,n-y1-1),max(y2,n-y2-1))); n      ans=max(ans,abs(y1-y2)*max(max(x1,n-x1-1),max(x2,n-x2-1))); n     } n    //} n    cout << ans <<    ; n   } n   cout << endl; n  } n }


#include <bits/stdc++.h> n using namespace std; n string t; n vector<string> query(3); n void ask(string &q) { n   cout <<  ?   << q <<   n ; n   fflush(stdout); n   cin >> q; n } n int main() { n   ios_base::sync_with_stdio(false); n   ; n   cin >> t; n   for (int i = 0; i < t.length(); i++) { n     query[0] += (char)( a  + (i % 26)); n     query[1] += (char)( a  + ((i % (26 * 26)) / (26))); n     query[2] += (char)( a  + (i % (26 * 26 * 26)) / (26 * 26)); n   } n   ask(query[0]); n   ask(query[1]); n   ask(query[2]); n   string ans(t.length(),    ); n   for (int i = 0; i < t.length(); i++) { n     int pos = (query[0][i] -  a ) + (query[1][i] -  a ) * 26 + n               (query[2][i] -  a ) * 26 * 26; n     ans[pos] = t[i]; n   } n   cout <<  !   << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 500010, INF = MAXN + 1; n struct Query { n   int pos, l, r; n }; n struct AddEvent { n   int pos, value, start_valid; n }; n int n, m; n int as[MAXN]; n int close[MAXN]; n Query queries[MAXN]; n AddEvent add_events[MAXN]; n int results[MAXN]; n int st[4 * MAXN]; n void update(int v, int l, int r, int ind, int val) { n   if (l == r) { n     assert(st[v] == INF); n     st[v] = val; n   } else { n     int m = (l + r) >> 1; n     if (ind <= m) n       update(v + v, l, m, ind, val); n     else n       update(v + v + 1, m + 1, r, ind, val); n     st[v] = min(st[v + v], st[v + v + 1]); n   } n } n int get(int v, int l, int r, int tl, int tr) { n   assert(l <= tl && tr <= r && tl <= tr); n   if (l == tl && r == tr) return st[v]; n   int res = INF, m = (l + r) >> 1; n   if (tl <= m) res = get(v + v, l, m, tl, min(tr, m)); n   if (tr > m) res = min(res, get(v + v + 1, m + 1, r, max(m + 1, tl), tr)); n   return res; n } n int main() { n   for (int i = 0; i < int(4 * MAXN); ++i) st[i] = INF; n   scanf( %d%d , &n, &m); n   for (int i = 0; i < int(n); ++i) scanf( %d , &as[i]); n   for (int i = 0; i < int(m); ++i) { n     scanf( %d%d , &queries[i].l, &queries[i].r); n     --queries[i].l, --queries[i].r; n     queries[i].pos = i; n   } n   sort(queries, queries + m, [](Query a, Query b) { return a.r < b.r; }); n   map<int, int> last; n   for (int i = n - 1; i >= 0; i--) { n     auto it = last.find(as[i]); n     if (it == last.end()) { n       close[i] = INF; n     } else { n       close[i] = it->second - i; n     } n     last[as[i]] = i; n   } n   for (int i = 0; i < int(n); ++i) { n     add_events[i] = {i, close[i], i + close[i]}; n   } n   sort(add_events, add_events + n, n        [](AddEvent a, AddEvent b) { return a.start_valid < b.start_valid; }); n   int qp = 0, ap = 0; n   for (int i = 0; i < n; i++) { n     while (ap < n && add_events[ap].start_valid == i) { n       update(1, 0, n - 1, add_events[ap].pos, add_events[ap].value); n       ++ap; n     } n     while (qp < m && queries[qp].r == i) { n       results[queries[qp].pos] = get(1, 0, n - 1, queries[qp].l, queries[qp].r); n       ++qp; n     } n   } n   for (int i = 0; i < int(m); ++i) { n     if (results[i] == INF) results[i] = -1; n     printf( %d n , results[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 11; n int a[N], b[N]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n, m; n   cin >> n >> m; n   for (int i = 1; i <= m; i++) { n     cin >> a[i] >> b[i]; n   } n   vector<int> v; n   for (int p = 1; p <= 200; p++) { n     int x = 0; n     for (int i = 1; i <= m; i++) { n       int d = (a[i] / p); n       if (a[i] % p != 0) d++; n       if (b[i] != d) { n         x = 1; n         break; n       } n     } n     if (x == 0) { n       int d = (n / p); n       if (n % p != 0) d++; n       v.push_back(d); n     } n   } n   sort(v.begin(), v.end()); n   if (v[0] != v[v.size() - 1]) { n     cout << -1 << endl; n   } else n     cout << v[0] << endl; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> sieve(int n) { n   vector<bool> prime(n + 1, true); n   prime[0] = false; n   prime[1] = false; n   int m = sqrt(n); n   vector<int> ans; n   for (int p = 2; p <= m; p++) { n     if (prime[p]) { n       for (int i = p * 2; i <= n; i += p) prime[i] = false; n     } n   } n   for (int i = 0; i < n; i++) n     if (prime[i]) ans.push_back(i); n   return ans; n } n int gcd(int a, int b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n int mod = 1e9 + 7; n int power(int a, long long b) { n   int res = 1; n   while (b) { n     if (b & 1) res = 1LL * res * a % mod; n     a = 1LL * a * a % mod; n     b >>= 1; n   } n   return res; n } n long long min(int a, long long b) { n   if (a > b) return b; n   return a; n } n long long max(int a, long long b) { n   if (a > b) return a; n   return b; n } n void solve() { n   long long n, m; n   cin >> n >> m; n   vector<pair<int, int>> p; n   for (int i = 0; i < m; i++) { n     int x, y; n     cin >> x >> y; n     p.push_back({x, y}); n   } n   long long ans = n       max(p[0].first + p[0].second - 1, p[m - 1].second + (n - p[m - 1].first)); n   for (int i = 1; i < m; i++) { n     if (abs(p[i].second - p[i - 1].second) > p[i].first - p[i - 1].first) { n       cout <<  IMPOSSIBLE ; n       return; n     } n     ans = max(ans, max(p[i].second, p[i - 1].second) + n                        (p[i].first - p[i - 1].first - n                         abs(p[i].second - p[i - 1].second)) / n                            2); n   } n   cout << ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int mul = 0; n   if (mul == 1) { n     int t; n     cin >> t; n     while (t--) { n       solve(); n       cout <<   n ; n     } n   } else { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 2e5 + 10; n const int MOD = 1e9 + 7; n int n; n long long int a[MAXN], minn; n bool have[MAXN], flag; n int main() { n   while (scanf( %d , &n) != EOF) { n     a[1] = 0; n     minn = 0; n     memset(have, false, sizeof(have)); n     flag = true; n     for (int i = 1; i < n; ++i) { n       int num; n       scanf( %I64d , &num); n       a[i + 1] = a[i] + num; n       minn = min(minn, a[i + 1]); n     } n     for (int i = 1; i <= n; ++i) { n       a[i] += -minn + 1; n       if (a[i] > n || have[a[i]]) { n         printf( -1 n ); n         flag = false; n         break; n       } n       have[a[i]] = true; n     } n     if (flag) { n       for (int i = 1; i <= n; ++i) { n         i == n ? printf( %I64d n , a[i]) : printf( %I64d  , a[i]); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T, typename S> n ostream &operator<<(ostream &os, const pair<T, S> &v) { n   os <<  ( ; n   os << v.first <<  ,  << v.second <<  ) ; n   return os; n } n template <typename T> n ostream &operator<<(ostream &os, const vector<T> &v) { n   os <<  [ ; n   long long sz = v.size(); n   for (long long i = 0; i < sz; ++i) { n     os << v[i]; n     if (i != sz - 1) os <<  , ; n   } n   os <<  ] n ; n   return os; n } n template <typename T> n ostream &operator<<(ostream &os, const set<T> &v) { n   T last = *v.rbegin(); n   os <<  [ ; n   for (auto it : v) { n     os << it; n     if (it != last) os <<  , ; n   } n   os <<  ] n ; n   return os; n } n template <typename T, typename S> n ostream &operator<<(ostream &os, const map<T, S> &v) { n   for (auto it : v) { n     os << it.first <<   :   << it.second <<   n ; n   } n   return os; n } n long long power(long long a, long long b) { n   long long res = 1; n   while (b) { n     if (b % 2) { n       res = (res * a) % 1000000007; n     } n     b /= 2; n     a = (a * a) % 1000000007; n   } n   return res; n } n template <typename Arg1> n void __f(const char *name, Arg1 &&arg1) { n   cerr << name <<   :   << arg1 << std::endl; n } n template <typename Arg1, typename... Args> n void __f(const char *names, Arg1 &&arg1, Args &&...args) { n   const char *comma = strchr(names + 1,  , ); n   cerr.write(names, comma - names) <<   :   << arg1 <<   |  ; n   __f(comma + 1, args...); n } n const long long N = 1005; n long long arr[N]; n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long n; n   cin >> n; n   for (__typeof(1) i = 1; i <= n; i++) cin >> arr[i]; n   long long res = 0; n   for (__typeof(2) i = 2; i <= n - 1; i++) { n     if ((arr[i] > arr[i - 1] && arr[i] > arr[i + 1]) || n         (arr[i] < arr[i - 1] && arr[i] < arr[i + 1])) n       ++res; n   } n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e6 + 7; n int A[N], B[N], n, ans, pos[N], s1[N], s2[N], cnt; n int main() { n   cin >> n; n   for (int i = 1; i <= n; ++i) cin >> A[i], pos[A[i]] = i; n   for (int i = 1; i <= n; ++i) cin >> B[i], A[pos[B[i]]] = i; n   for (int i = 1; i <= n; ++i) pos[A[i]] = i; n ZXY:; n   int st = 1; n   while (A[st] == st) st++; n   for (int i = st; i <= n; ++i) n     if (A[i] > i) { n       for (int j = i + 1; j <= n; ++j) n         if (A[j] <= i && j <= A[i]) { n           ans += j - i; n           s1[++cnt] = i, s2[cnt] = j; n           swap(A[i], A[j]); n           goto ZXY; n         } n     } n   cout << ans << endl << cnt << endl; n   for (int i = 1; i <= cnt; ++i) cout << s1[i] <<     << s2[i] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, res = 0, a, b; n   cin >> n; n   vector<pair<long long, long long>> nums; n   for (int i = 0; i < n; i++) { n     cin >> a >> b; n     nums.push_back({a, b}); n   } n   for (int i = 0; i < n; i++) { n     bool l = false, r = false, u = false, d = false; n     for (int j = 0; j < n; j++) n       if (i != j) { n         if (nums[j].second == nums[i].second && nums[j].first > nums[i].first) n           r = true; n         if (nums[j].second == nums[i].second && nums[j].first < nums[i].first) n           l = true; n         if (nums[j].second > nums[i].second && nums[j].first == nums[i].first) n           u = true; n         if (nums[j].second < nums[i].second && nums[j].first == nums[i].first) n           d = true; n       } n     res += (bool)(l && r && u && d); n   } n   cout << res; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int a, b, c, d; n   while (scanf( %d%d%d%d , &a, &b, &c, &d) == 4) { n     if (c >= b - 1 && c <= 2 * (b + 1)) { n       printf( YES n ); n       continue; n     } n     if (d >= a - 1 && d <= 2 * (a + 1)) { n       printf( YES n ); n       continue; n     } n     printf( NO n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int A[1000001]; n int main() { n   ios::sync_with_stdio(false); n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> A[i]; n   } n   map<int, int> change_v; n   int above = 0, below = 0; n   long long sum = 0; n   long long best_i = 0; n   for (int i = 0; i < n; i++) { n     int xs = A[i] - i - 1; n     int x = (xs > 0) ? xs : -1 * xs; n     if (xs < 0) { n       change_v[x]++; n     } n     if (xs < 0) { n       below++; n     } else { n       above++; n     } n     sum += x; n   } n   long long best_sum = sum; n   for (int i = 0; i < n - 1; i++) { n     long long xs = A[i] - n; n     long long x = (xs > 0) ? xs : -1 * xs; n     long long cnt = change_v[i + 1]; n     if (xs < 0) { n       change_v[x + i + 1]++; n     } n     int cur_below_d = (A[i] - 1 < 0) ? 1 : 0; n     int cur_above_d = (A[i] - 1 >= 0) ? 1 : 0; n     sum -= below - cur_below_d; n     sum += above - cur_above_d; n     sum -= (A[i] - 1 > 0) ? A[i] - 1 : 1 - A[i]; n     sum += x; n     above += cnt; n     below -= cnt; n     if (xs < 0 && A[i] - 1 >= 0) { n       below++; n       above--; n     } n     if (sum < best_sum) { n       best_i = i + 1; n       best_sum = sum; n     } n   } n   if (best_i != 0) { n     best_i = n - best_i; n   } n   cout << best_sum <<     << best_i; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n T power(T a, T b) { n   T x; n   if (b == 0) n     x = 1; n   else n     x = a; n   for (size_t i = 1; i < b; i++) x *= a; n   return x; n } n long long int gcd(long long int a, long long int b) { n   return b == 0 ? a : gcd(b, a % b); n } n long long int n, m, a, b, c, ab, ba, x, y, z, avg, total, ans, sum; n long long int arr2[300001], arr3[100001], arr4[100001], arr5[100001]; n char c1, c2; n vector<pair<string, long long int> > vec; n vector<long long int> v; n bool f, f1, f2, found; n string str, s1, s2, s3, s4; n map<long long int, long long int> mp, mp1; n set<int> seto; n double d, d1; n long long int x1, x2, y11, y2; n long long int mini = 10000000000, maxi = 0; n set<string> sets; n int main() { n   cin >> n >> str; n   for (long long int i = 0; i < str.size(); i++) { n     if (str[i] ==  > ) n       f1 = 1; n     else n       f = 1; n   } n   if (f && f1) { n     for (long long int i = 0; i < str.size(); i++) n       if (str[i] ==  < ) n         sum++; n       else n         break; n     reverse(str.rbegin(), str.rend()); n     for (long long int i = 0; i < str.size(); i++) n       if (str[i] ==  > ) n         sum++; n       else n         break; n   } else n     sum = str.size(); n   cout << sum; n } n


#include <bits/stdc++.h> n using namespace std; n const int nm = 2e5 + 3; n const long long mod = 1e9 + 7; n int n; n int pos[nm]; n int main() { n   ios::sync_with_stdio(0), cin.tie(0); n   while (cin >> n) { n     for (int i = 0; i < n; i++) cin >> pos[i]; n     sort(pos, pos + n); n     int step = n / 2 - 1; n     int res = pos[n - 1] - pos[0]; n     pair<double, int> loc; n     for (int i = 0; i <= step; i++) { n       if (pos[i + n - step - 1] - pos[i] < res) { n         res = pos[i + n - step - 1] - pos[i]; n         loc.first = i, loc.second = i + n - step - 1; n       } n     } n     cout << res << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 150; n int n, dp[N][N * N], sum, cnt[N], x, u[N][N * N], res; n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) scanf( %d , &x), sum += x, cnt[x]++; n   dp[0][0] = 1; n   for (int i = 1; i <= 100; i++) { n     res += (cnt[i] > 0); n     for (int j = n; j >= 1; j--) { n       for (int cn = 1; cn <= min(j, cnt[i]); cn++) { n         for (int l = i * cn; l <= sum; l++) { n           dp[j][l] += dp[j - cn][l - i * cn]; n         } n       } n     } n   } n   if (res == 1 || res == 2) { n     cout << n << endl; n     return 0; n   } n   for (int i = 1; i <= 100; i++) n     for (int cn = 1; cn <= cnt[i]; cn++) u[cn][i * cn] = 1; n   for (int i = n; i >= 1; i--) { n     for (int j = 0; j <= sum; j++) { n       if (dp[i][j] == 1 && u[i][j] == 1) { n         cout << i << endl; n         return 0; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long t, xiaoyud, dayu, n, x, pos, ans1, mo = 1e9 + 7, ans2, ans; n int main() { n   cin >> n >> x >> pos; n   long long l = 0, r = n; n   while (l < r) { n     long long mid = (l + r) / 2; n     if (mid <= pos) { n       l = mid + 1; n       if (mid != pos) xiaoyud++; n     } else { n       r = mid; n       dayu++; n     } n   } n   ans1 = 1; n   for (long long i = 1; i <= xiaoyud; i++) { n     ans1 = (ans1 * (x - 1 - i + 1)) % mo; n   } n   ans2 = 1; n   for (long long i = 1; i <= dayu; i++) { n     ans2 = (ans2 * (n - x - i + 1)) % mo; n   } n   ans = (ans1 * ans2) % mo; n   for (long long i = 1; i <= n - xiaoyud - dayu - 1; i++) { n     ans = (ans * (n - xiaoyud - dayu - i)) % mo; n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, a, od = 0, ev = 0, ans = 0; n   cin >> n; n   vector<int> vec; n   vector<int>::iterator it; n   while (n--) { n     cin >> a; n     vec.push_back(a); n     if (a % 2 == 0) n       ev++; n     else n       od++; n   } n   for (it = vec.begin(); it != vec.end(); it++) { n     if (ev > od) { n       if (*it % 2 != 0) ans = distance(vec.begin(), it); n     } else if (od > ev) { n       if (*it % 2 == 0) ans = distance(vec.begin(), it); n     } n   } n   cout << ans + 1; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 5; n string s, t; n int cnt[10], n, Num, tmp[10], cntT[10], m, tmpCnt[10]; n string lmao1 =   , lmao2 =   , lmao3 =   ; n int main() { n   cin.tie(0), ios_base::sync_with_stdio(0); n   cin >> s; n   cin >> t; n   m = (int)(t.length()); n   n = (int)(s.length()); n   for (int i = 0; i < m; i++) cntT[(int)(t[i] -  0 )]++; n   for (int i = 0; i < n; i++) cnt[(int)(s[i] -  0 )]++; n   if ((s ==  01  || s ==  10 ) && t ==  0 ) { n     cout <<  0 ; n     exit(0); n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 0; j < 10; j++) tmp[j] = 0; n     int x = i, sumD = 0; n     while (x) { n       tmp[x % 10]++; n       x /= 10; n       sumD++; n     } n     if (sumD + i != n) continue; n     bool ok = 1; n     for (int j = 0; j < 10; j++) ok &= (cnt[j] >= tmp[j]); n     for (int j = 0; j < 10; j++) ok &= (cnt[j] - tmp[j] >= cntT[j]); n     int digits = 0; n     for (int j = 1; j < 10; j++) digits += (cnt[j] - tmp[j] > 0); n     ok &= (digits > 0); n     if (!ok) continue; n     Num = i; n     for (int j = 0; j < 10; j++) cnt[j] -= tmp[j]; n     break; n   } n   bool containT = 0; n   int lim = 0; n   for (int j = 0; j < 10; j++) tmpCnt[j] = cnt[j]; n   string ans =   ; n   bool ok = 1; n   for (int i = 1; i <= Num; i++) { n     if (i <= lim) continue; n     bool ck = 0; n     for (int j = (i == 1); j <= 9; j++) { n       if (!cnt[j]) continue; n       cnt[j]--; n       bool uk = 1; n       if (!containT) { n         for (int k = 0; k <= 9; k++) uk &= (cnt[k] >= cntT[k]); n         if (i != 1) { n           if (j == t[0] -  0 ) { n             cnt[j]++; n             lmao1 += t; n             for (int k = 0; k <= 9; k++) cnt[k] -= cntT[k]; n             containT = 1; n             lim = i + m - 1; n             ck = 1; n             break; n           } n         } n         if (!uk) { n           cnt[j]++; n           continue; n         } n       } n       ck = 1; n       lmao1 += ( 0  + j); n       break; n     } n     ok &= ck; n   } n   if (!ok) lmao1 =   ; n   containT = 0, lim = 0; n   ok = 1; n   for (int j = 0; j < 10; j++) cnt[j] = tmpCnt[j]; n   for (int i = 1; i <= Num; i++) { n     if (i <= lim) continue; n     bool ck = 0; n     for (int j = (i == 1); j <= 9; j++) { n       if (!cnt[j]) continue; n       cnt[j]--; n       bool uk = 1; n       if (!containT) { n         for (int k = 0; k <= 9; k++) uk &= (cnt[k] >= cntT[k]); n         if (j == t[0] -  0 ) { n           cnt[j]++; n           lmao3 += t; n           for (int k = 0; k <= 9; k++) cnt[k] -= cntT[k]; n           containT = 1; n           lim = i + m - 1; n           ck = 1; n           break; n         } n         if (!uk) { n           cnt[j]++; n           continue; n         } n       } n       ck = 1; n       lmao3 += ( 0  + j); n       break; n     } n     ok &= ck; n   } n   if (!ok) lmao2 =   ; n   containT = 0, lim = 0; n   ok = 1; n   for (int j = 0; j < 10; j++) cnt[j] = tmpCnt[j]; n   for (int i = 1; i <= Num; i++) { n     if (i <= lim) continue; n     bool ck = 0; n     for (int j = (i == 1); j <= 9; j++) { n       if (!cnt[j]) continue; n       cnt[j]--; n       bool uk = 1; n       if (!containT) { n         for (int k = 0; k <= 9; k++) uk &= (cnt[k] >= cntT[k]); n         cnt[j]++; n         if (cnt[j] - cntT[j] == 0 && j == t[0] -  0 ) { n           lmao2 += t; n           for (int k = 0; k <= 9; k++) cnt[k] -= cntT[k]; n           containT = 1; n           lim = i + m - 1; n           ck = 1; n           break; n         } n         cnt[j]--; n         if (!uk) { n           cnt[j]++; n           continue; n         } n       } n       ck = 1; n       lmao2 += ( 0  + j); n       break; n     } n     ok &= ck; n   } n   if (!ok) lmao3 =   ; n   if (lmao1 !=   ) ans = lmao1; n   if (lmao2 !=   ) ans = lmao2; n   if (lmao3 !=   ) ans = lmao3; n   if (lmao1 !=   ) ans = min(ans, lmao1); n   if (lmao2 !=   ) ans = min(ans, lmao2); n   if (lmao3 !=   ) ans = min(ans, lmao3); n   cout << ans; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n #pragma GCC optimize( Ofast ) n #pragma GCC optimize( unroll-loops ) n using namespace std; n int a[510][510]; n int mi[510][510]; n int main() { n   ios_base::sync_with_stdio(0); n   int n, m, k, q; n   cin >> n >> m >> k >> q; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) { n       a[i][j] = -1; n       mi[i][j] = -1; n     } n   for (int i = 1; i <= q; i++) { n     int x, y, z; n     cin >> x >> y >> z; n     a[x][y] = z; n   } n   for (int i = 1; i <= n; i++) { n     multiset<int> st; n     for (int j = 1; j <= k; j++) { n       st.insert(a[i][j]); n     } n     for (int j = k + 1; j <= m + 1; j++) { n       auto kk = st.end(); n       kk--; n       if ((*st.begin()) != -1) mi[i][j - k] = (*kk); n       st.erase(st.find(a[i][j - k])); n       st.insert(a[i][j]); n     } n   } n   int ans = 2e9; n   for (int j = 1; j <= m - k + 1; j++) { n     multiset<int> st; n     for (int i = 1; i <= k; i++) { n       st.insert(mi[i][j]); n     } n     for (int i = k + 1; i <= n + 1; i++) { n       auto kk = st.end(); n       kk--; n       if ((*st.begin()) != -1) ans = min(ans, (*kk)); n       st.erase(st.find(mi[i - k][j])); n       st.insert(mi[i][j]); n     } n   } n   if (ans == 2e9) n     cout << -1; n   else n     cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   node* child[26]; n   priority_queue<int> pq; n   bool leaf; n   node() { n     memset(child, 0, sizeof child); n     leaf = false; n   } n }; n void insert(node* curr, const string& x) { n   for (auto c : x) { n     if (!curr->child[c -  a ]) curr->child[c -  a ] = new node(); n     curr = curr->child[c -  a ]; n   } n   curr->leaf = true; n } n void dfs(node* curr, int lev) { n   for (int i = 0; i < 26; i++) { n     if (!curr->child[i]) continue; n     dfs(curr->child[i], lev + 1); n     while (!curr->child[i]->pq.empty()) n       curr->pq.push(curr->child[i]->pq.top()), curr->child[i]->pq.pop(); n   } n   if (curr->leaf) n     curr->pq.push(lev); n   else { n     if (!curr->pq.empty() && lev) curr->pq.pop(), curr->pq.push(lev); n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n; n   cin >> n; n   node* root = new node(); n   while (n--) { n     string x; n     cin >> x; n     insert(root, x); n   } n   dfs(root, 0); n   long long ans = 0; n   while (!root->pq.empty()) ans += root->pq.top(), root->pq.pop(); n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int Get() { n   int res = 0, q = 1; n   char ch = getchar(); n   while ((ch <  0  || ch >  9 ) && ch !=  - ) ch = getchar(); n   if (ch ==  - ) q = -1, ch = getchar(); n   while (ch >=  0  && ch <=  9 ) res = res * 10 + ch -  0 , ch = getchar(); n   return res * q; n } n const double eps = 1e-12, pi = M_PI; n const int oo = (int)2e9, mod = (int)1e9 + 7; n const long long INF = (long long)1e17; n const int N = (int)1e5; n typedef int arr[N + 10]; n arr a, b, c, lstx, lsty, id, u, v, sc; n bool vs[10]; n int d[10], ord[10]; n int n, m; n bool cmp_x(const int &x, const int &y) { return a[x] < a[y]; } n bool cmp_y(const int &x, const int &y) { return b[x] < b[y]; } n struct node { n   node *ch[2]; n   int s; n } * Rt[N + 10]; n node *New() { n   node *res = new node; n   res->ch[0] = res->ch[1] = NULL, res->s = 0; n   return res; n } n node *Copy(node *x) { n   node *res = new node; n   res->ch[0] = x->ch[0], res->ch[1] = x->ch[1], res->s = x->s; n   return res; n } n node *New(node *x, int d) { n   if (!x->ch[d]) return New(); n   return Copy(x->ch[d]); n } n void Update(node *x) { n   x->s = 0; n   if (x->ch[0]) x->s += x->ch[0]->s; n   if (x->ch[1]) x->s += x->ch[1]->s; n } n void Add(int l, int r, node *&x, int pos) { n   if (l == r) { n     ++x->s; n     return; n   } n   int mid = (l + r) >> 1; n   if (pos <= mid) n     Add(l, mid, x->ch[0] = New(x, 0), pos); n   else n     Add(mid + 1, r, x->ch[1] = New(x, 1), pos); n   Update(x); n } n int Query(int l, int r, node *x, int ml, int mr) { n   if (!x || ml > mr) return 0; n   if (l >= ml && r <= mr) return x->s; n   int mid = (l + r) >> 1, res = 0; n   if (ml <= mid) res += Query(l, mid, x->ch[0], ml, mr); n   if (mr > mid) res += Query(mid + 1, r, x->ch[1], ml, mr); n   return res; n } n void Init() { n   scanf( n        %d  n         n , n       &n); n   for (int i = (1), end = (n); i <= end; ++i) n     scanf( n          %d  n          %d  n           n , n         a + i, b + i), n         u[i] = a[i], v[i] = b[i], c[i] = a[i], lstx[i] = i, lsty[i] = i; n   for (int i = (1), end = (9); i <= end; ++i) scanf( %d , d + i); n   c[n + 1] = oo; n   sort(c + 1, c + n + 1); n   int cnt = 0; n   for (int i = (1), end = (n); i <= end; ++i) n     if (c[i] != c[i + 1]) c[++cnt] = c[i]; n   for (int i = (1), end = (n); i <= end; ++i) n     a[i] = lower_bound(c + 1, c + cnt + 1, a[i]) - c; n   for (int i = (1), end = (n); i <= end; ++i) c[i] = b[i]; n   sort(c + 1, c + n + 1); n   cnt = 0; n   for (int i = (1), end = (n); i <= end; ++i) n     if (c[i] != c[i + 1]) c[++cnt] = c[i]; n   m = cnt; n   for (int i = (1), end = (n); i <= end; ++i) n     b[i] = lower_bound(c + 1, c + cnt + 1, b[i]) - c; n   sort(lstx + 1, lstx + n + 1, cmp_x); n   sort(lsty + 1, lsty + n + 1, cmp_y); n   Rt[0] = New(); n   int tot = 0; n   for (int i = (1), end = (n); i <= end; ++i) { n     int x = lstx[i]; n     if (a[x] == a[lstx[i - 1]]) n       Rt[i] = Rt[sc[tot]], id[x] = tot; n     else n       Rt[i] = Copy(Rt[sc[tot]]), sc[++tot] = i, id[x] = tot; n     Add(1, m, Rt[i], b[x]); n   } n } n void Check() { n   int x1 = lstx[ord[1] + ord[4] + ord[7]], n       x2 = lstx[ord[1] + ord[2] + ord[4] + ord[5] + ord[7] + ord[8] + 1]; n   int y1 = lsty[ord[7] + ord[8] + ord[9]], n       y2 = lsty[ord[7] + ord[8] + ord[9] + ord[4] + ord[5] + ord[6] + 1]; n   int num = Query(1, m, Rt[sc[id[x1]]], b[y2], m); n   if (num != ord[1]) return; n   num = Query(1, m, Rt[sc[id[x1]]], b[y1] + 1, b[y2] - 1); n   if (num != ord[4]) return; n   num = Query(1, m, Rt[sc[id[x1]]], 1, b[y1]); n   if (num != ord[7]) return; n   num = Query(1, m, Rt[sc[id[x2] - 1]], b[y2], m) - ord[1]; n   if (num != ord[2]) return; n   num = Query(1, m, Rt[sc[id[x2] - 1]], 1, b[y1]) - ord[7]; n   if (num != ord[8]) return; n   num = Query(1, m, Rt[n], b[y2], m) - ord[1] - ord[2]; n   if (num != ord[3]) return; n   num = Query(1, m, Rt[n], 1, b[y1]) - ord[7] - ord[8]; n   if (num != ord[9]) return; n   num = Query(1, m, Rt[n], b[y1] + 1, b[y2] - 1) - n         Query(1, m, Rt[sc[id[x2] - 1]], b[y1] + 1, b[y2] - 1); n   if (num != ord[6]) return; n   double px1 = (double)u[x1] + 0.5, px2 = (double)u[x2] - 0.5; n   double py1 = (double)v[y1] + 0.5, py2 = (double)v[y2] - 0.5; n   printf( n        %.8lf  n           n        %.8lf  n         n , n       px1, px2); n   printf( n        %.8lf  n           n        %.8lf  n         n , n       py1, py2); n   exit(0); n } n void Dfs(int x) { n   if (x > 9) { n     Check(); n     return; n   } n   for (int i = (1), end = (9); i <= end; ++i) n     if (!vs[i]) { n       vs[i] = 1, ord[x] = d[i]; n       Dfs(x + 1); n       vs[i] = 0; n     } n } n int main() { n   Init(); n   Dfs(1); n   printf( -1 n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxN = 100010; n int n, m, res, l[3][maxN], r[3][maxN], g[16 * maxN], t[16 * maxN], ans[maxN], n     con[maxN]; n bool avail[maxN]; n stack<int> s[4 * maxN]; n struct ioi { n   int v, p, t, k; n }; n ioi c[4 * maxN]; n bool cmp(ioi i, ioi j) { n   if (i.v < j.v) return true; n   if (i.v > j.v) return false; n   if (i.t < j.t) return true; n   if (i.t > j.t) return false; n   if (i.t == 1) n     return (i.k > j.k); n   else n     return (i.k < j.k); n } n void update(int k, int l, int r, int i, int x) { n   if ((i < l) || (i > r)) return; n   if (l == r) { n     t[k] += x; n     if (t[k]) n       g[k] = l; n     else n       g[k] = 0; n     return; n   } n   int mid = (l + r) >> 1; n   update(k * 2, l, mid, i, x); n   update(k * 2 + 1, mid + 1, r, i, x); n   t[k] = t[k * 2] + t[k * 2 + 1]; n   if (g[k * 2] == 0) n     g[k] = g[k * 2 + 1]; n   else if (g[k * 2 + 1] == 0) n     g[k] = g[k * 2]; n   else n     g[k] = min(g[k * 2], g[k * 2 + 1]); n } n int get(int k, int l, int r, int i) { n   if (r < i) return 0; n   if (l >= i) return g[k]; n   if (l == r) return 0; n   int mid = (l + r) >> 1; n   int tmp_1 = get(k * 2, l, mid, i); n   int tmp_2 = get(k * 2 + 1, mid + 1, r, i); n   if (!tmp_1) return tmp_2; n   if (!tmp_2) return tmp_1; n   return min(tmp_1, tmp_2); n } n int main() { n   scanf( %d , &n); n   int x, y, z, num = 0; n   for (int i = 1; i <= n; ++i) { n     scanf( %d%d , &x, &y); n     l[1][i] = x; n     r[1][i] = y; n     c[++num].v = x; n     c[num].t = 1; n     c[num].k = 1; n     c[num].p = i; n     c[++num].v = y; n     c[num].t = 2; n     c[num].k = 1; n     c[num].p = i; n   } n   scanf( %d , &m); n   for (int i = 1; i <= m; ++i) { n     scanf( %d%d%d , &x, &y, &z); n     l[2][i] = x; n     r[2][i] = y; n     con[i] = z; n     c[++num].v = x; n     c[num].t = 1; n     c[num].k = 2; n     c[num].p = i; n     c[++num].v = y; n     c[num].t = 2; n     c[num].k = 2; n     c[num].p = i; n   } n   sort(c + 1, c + num + 1, cmp); n   int val = c[1].v; n   c[1].v = 1; n   for (int i = 2; i <= num; ++i) { n     int tmp_val = c[i].v; n     if (c[i].v != val) n       c[i].v = c[i - 1].v + 1; n     else n       c[i].v = c[i - 1].v; n     if (c[i].t == 1) n       l[c[i].k][c[i].p] = c[i].v; n     else n       r[c[i].k][c[i].p] = c[i].v; n     val = tmp_val; n   } n   for (int i = 1; i <= num; ++i) { n     if (c[i].k == 1) { n       if (c[i].t == 1) { n         int u = get(1, 1, c[num].v, r[1][c[i].p]); n         if (u == 0) { n           res = -1; n           break; n         } n         while ((!s[u].empty()) && (!avail[s[u].top()])) s[u].pop(); n         if (u == 0) { n           res = -1; n           break; n         } n         u = s[u].top(); n         ans[c[i].p] = u; n         con[u]--; n         if (!con[u]) update(1, 1, c[num].v, r[2][u], -1), avail[u] = 0; n       } n     } else if (c[i].t == 1) { n       update(1, 1, c[num].v, r[2][c[i].p], 1); n       s[r[2][c[i].p]].push(c[i].p); n       avail[c[i].p] = 1; n     } else { n       update(1, 1, c[num].v, c[i].v, -1); n       avail[c[i].p] = 0; n     } n   } n   if (res == -1) n     printf( NO ); n   else { n     printf( YES n ); n     for (int i = 1; i <= n; ++i) printf( %d  , ans[i]); n   } n   fclose(stdin); n   fclose(stdout); n } n


#include <bits/stdc++.h> n using namespace std; n using INT = long long; n using pii = pair<INT, INT>; n using pi3 = pair<pii, INT>; n INT a[5010]; n bool dp[5010][5010]; n INT val[5010]; n vector<pi3> ans; n int main() { n   ios_base ::sync_with_stdio(0); n   cin.tie(0); n   INT n, k, v; n   cin >> n >> k >> v; n   for (INT i = 1; i <= n; i++) cin >> a[i]; n   INT sum = 0; n   for (INT i = 1; i <= n; i++) sum += a[i]; n   if (sum < v) { n     cout <<  NO  << endl; n     return 0; n   } n   for (INT i = 0; i < k; i++) val[i] = n + 1; n   dp[0][0] = 1; n   for (INT i = 1; i <= n; i++) { n     for (INT j = 0; j < k; j++) n       if (dp[i - 1][j]) { n         INT temp = (j + a[i]) % k; n         dp[i][temp] = 1; n         dp[i][j] = 1; n         val[temp] = min(val[temp], i); n       } n     dp[i][a[i] % k] = 1; n     val[a[i] % k] = min(val[a[i] % k], i); n   } n   INT p = v % k; n   int fff = 0; n   INT ID, sz; n   if (p == 0) { n     cout <<  YES  << endl; n     if (a[1]) cout << (a[1] + k - 1) / k <<   1 2  << endl; n     a[2] += a[1]; n     fff = 1; n     ID = 1; n     sz = 0; n   } n   if (!fff) { n     INT id = val[p]; n     if (id == n + 1) { n       cout <<  NO  << endl; n       return 0; n     } n     cout <<  YES  << endl; n     ID = id; n     p -= (a[id] % k); n     if (p < 0) p += k; n     sz = a[id]; n     id = val[p]; n     while (p != 0) { n       p -= (a[id] % k); n       ans.push_back(pi3(pii(a[id] / k + 1, id), ID)); n       sz += a[id]; n       a[id] = 0; n       if (p < 0) p += k; n       id = val[p]; n     } n   } n   INT sr = 1; n   if (ID == sr) sr = n; n   for (INT i = 1; i <= n; i++) { n     if (a[i] == 0 || i == ID || i == sr) continue; n     ans.push_back(pi3(pii((a[i] + k - 1) / k, i), sr)); n   } n   INT val = (v - sz) / k; n   if (val > 0) { n     ans.push_back(pi3(pii(val, sr), ID)); n   } n   if (val < 0) { n     ans.push_back(pi3(pii(-val, ID), sr)); n   } n   for (auto p : ans) { n     INT u = p.first.first; n     INT sr = p.first.second; n     INT ta = p.second; n     cout << u <<     << sr <<     << ta << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, k; n vector<vector<int> > g; n vector<vector<int> > revg; n int active[1000005]; n int del; n int limx, limy, limz; n unordered_set<int> visited; n void add(int a, int b) { n   if (active[a] && active[b]) { n     g[a].push_back(b); n     revg[b].push_back(a); n   } n } n int get(int a, int b, int c) { return a * m * k + b * k + c; } n bool downlimit(int v) { n   if (v == del) return false; n   int z(v % k); n   v /= k; n   int y(v % m); n   int x(v / m); n   return x <= limx && y <= limy && z <= limz; n } n void dfs(int v) { n   visited.insert(v); n   for (int i(0), _l((int)(((int)g[v].size())) - 1); i <= _l; ++i) { n     int to(g[v][i]); n     if (downlimit(to)) dfs(to); n   } n } n void solve() { n   memset((active), 0, sizeof(active)); n   scanf( %d%d%d n , &n, &m, &k); n   g.resize(n * m * k); n   revg.resize(n * m * k); n   for (int i(0), _l((int)(n)-1); i <= _l; ++i) n     for (int j(0), _l((int)(m)-1); j <= _l; ++j) { n       string s; n       getline(cin, s); n       for (int q(0), _l((int)(k)-1); q <= _l; ++q) n         active[get(i, j, q)] = (s[q] ==  1 ); n       if (j == m - 1) getline(cin, s); n     } n   for (int i(0), _l((int)(n)-1); i <= _l; ++i) n     for (int j(0), _l((int)(m)-1); j <= _l; ++j) n       for (int q(0), _l((int)(k)-1); q <= _l; ++q) { n         if (i < n - 1) add(get(i, j, q), get(i + 1, j, q)); n         if (j < m - 1) add(get(i, j, q), get(i, j + 1, q)); n         if (q < k - 1) add(get(i, j, q), get(i, j, q + 1)); n       } n   int ans(0); n   for (int x(0), _l((int)(n)-1); x <= _l; ++x) n     for (int y(0), _l((int)(m)-1); y <= _l; ++y) n       for (int z(0), _l((int)(k)-1); z <= _l; ++z) { n         int v(get(x, y, z)); n         del = v; n         limx = x + 1, limy = y + 1, limz = z + 1; n         bool frogs(false); n         for (int i(0), _l((int)(((int)revg[v].size())) - 1); i <= _l; ++i) { n           int from(revg[v][i]); n           visited.clear(); n           dfs(from); n           for (int j(0), _l((int)(((int)g[v].size())) - 1); j <= _l; ++j) { n             int to(g[v][j]); n             if (!visited.count(to)) frogs = true; n             if (frogs) break; n           } n           if (frogs) break; n         } n         ans += frogs; n       } n   printf( %d n , ans); n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int d_compare(double x, double y) { n   return (fabs(x - y) <= 1e-8) ? 0 : (x > y) ? 1 : -1; n } n inline int mod(long long x, int y) { n   if (y == 0) return x; n   if (x < 0) x = -x; n   if (x >= y) x %= y; n   return x; n } n inline int cmod(int x, int y) { n   if (y == 0) return x; n   if (x < 0) x += (abs(x) / y + 1) * y; n   if (x >= y) x = x % y; n   return x; n } n int Bcount(int mask) { n   int n = 0; n   while (mask) n += ((mask & -mask) != 0), mask &= ~(mask & -mask); n   return n; n } n inline bool Bstate(int mask, int idx) { return (mask & (1 << idx)); } n inline int B1(int mask, int idx) { return mask | (1 << idx); } n inline int B0(int mask, int idx) { return mask & ~(1 << idx); } n inline int drift(int mask, int n) { return mask & ((1 << n) - 1); } n void debugmask(int mask, int n) { n   for (int i = 0; i < n; i++) cout << Bstate(mask, i); n } n class point { n  public: n   int x, y; n   point(int i, int j) { n     x = i; n     y = j; n   } n }; n bool arr[2002][2002]; n int n, m; n bool check(point wall) { n   if (arr[wall.x + 1][wall.y] && arr[wall.x][wall.y + 1] && n       arr[wall.x + 1][wall.y + 1]) n     return 1; n   if (arr[wall.x - 1][wall.y] && arr[wall.x][wall.y - 1] && n       arr[wall.x - 1][wall.y - 1]) n     return 1; n   if (arr[wall.x + 1][wall.y] && arr[wall.x][wall.y - 1] && n       arr[wall.x + 1][wall.y - 1]) n     return 1; n   if (arr[wall.x - 1][wall.y] && arr[wall.x][wall.y + 1] && n       arr[wall.x - 1][wall.y + 1]) n     return 1; n   return 0; n } n void dfs(point wall) { n   if (wall.x > n || wall.y > m) return; n   arr[wall.x][wall.y] = 1; n   if (!arr[wall.x - 1][wall.y] && check(point(wall.x - 1, wall.y))) n     dfs(point(wall.x - 1, wall.y)); n   if (!arr[wall.x + 1][wall.y] && check(point(wall.x + 1, wall.y))) n     dfs(point(wall.x + 1, wall.y)); n   if (!arr[wall.x][wall.y - 1] && check(point(wall.x, wall.y - 1))) n     dfs(point(wall.x, wall.y - 1)); n   if (!arr[wall.x][wall.y + 1] && check(point(wall.x, wall.y + 1))) n     dfs(point(wall.x, wall.y + 1)); n   if (!arr[wall.x - 1][wall.y + 1] && check(point(wall.x - 1, wall.y + 1))) n     dfs(point(wall.x - 1, wall.y + 1)); n   if (!arr[wall.x + 1][wall.y - 1] && check(point(wall.x + 1, wall.y - 1))) n     dfs(point(wall.x + 1, wall.y - 1)); n   if (!arr[wall.x - 1][wall.y - 1] && check(point(wall.x - 1, wall.y - 1))) n     dfs(point(wall.x - 1, wall.y - 1)); n   if (!arr[wall.x + 1][wall.y + 1] && check(point(wall.x + 1, wall.y + 1))) n     dfs(point(wall.x + 1, wall.y + 1)); n } n void input() { n   memset(arr, 0, sizeof arr); n   char c; n   cin >> n >> m; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) { n       cin >> c; n       arr[i][j] = (c ==  . ); n     } n } n int main() { n   std::ios_base::sync_with_stdio(false); n   input(); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) n       if (!arr[i][j] && check(point(i, j))) dfs(point(i, j)); n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) n       if (arr[i][j]) n         cout <<  . ; n       else n         cout <<  * ; n     cout << endl; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() {} n const int maxn = (int)1e6 + 420; n const int MOD = (int)1e9 + 7; n int n; n int dp[maxn][4][4]; n void contr() { n   cout << 0 <<   n ; n   exit(0); n } n int madd(int a, int b) { n   long long sum = a + b; n   sum %= MOD; n   return sum; n } n signed main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   string s; n   cin >> s; n   n = (int)s.size(); n   s =  .  + s; n   dp[0][0][0] = 1; n   for (int i = 1; i <= n; i++) { n     for (int l = 0; l <= 3; l++) { n       for (int m = 0; m <= 3; m++) { n         for (int r = 0; r <= 3; r++) { n           if ((i == 1) and !(l == 0 and m == 0)) continue; n           if ((i == 2) and !(l == 0)) continue; n           bool ok = true; n           if (i >= 2) { n             if (m == 0 and (l == 3 or r == 3)) { n               ok = false; n               continue; n             } n             if (m == 1 and !(l == 3 ^ r == 3)) { n               ok = false; n               continue; n             } n             if (m == 2 and (l != 3 or r != 3)) { n               ok = false; n               continue; n             } n           } n           if (r == 0 and m == 3) { n             ok = false; n             continue; n           } n           if (r == 2 and m != 3) { n             ok = false; n             continue; n           } n           if (r == 1 and i == n and m != 3) { n             ok = false; n             continue; n           } n           if (r == 2 and i == n) { n             ok = false; n             continue; n           } n           vector<int> v = {r, m, l}; n           for (int j = 0; j < 3; j++) { n             if (s[i - j] ==  ? ) continue; n             if (i - j < 1) continue; n             if ((v[j] == 3)) { n               if (s[i - j] !=  * ) { n                 ok = false; n                 continue; n               } n             } else if (s[i - j] -  0  != v[j]) { n               ok = false; n               continue; n             } n           } n           if (ok) { n             dp[i][m][r] = madd(dp[i][m][r], dp[i - 1][l][m]); n           } n         } n       } n     } n   } n   int ans = 0; n   for (int i = 0; i <= 3; i++) { n     for (int j = 0; j <= 3; j++) { n       ans = madd(ans, dp[n][i][j]); n     } n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   cin >> n >> k; n   int a[n], e = 0, s = 0; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     if (a[i] == 1) n       e++; n     else n       s++; n   } n   int ans = 0; n   for (int b = 0; b < k; b++) { n     int c = b, ee = e, second = s; n     while (c < n) { n       if (a[c] == 1) n         ee--; n       else n         second--; n       c += k; n     } n     ans = max(ans, abs(ee - second)); n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n long long int gcd(long long int a, long long int b) { n   if (a == 0) n     return b; n   else n     return gcd(b % a, a); n } n long long int power(long long int a, long long int b, long long int m) { n   long long int ans = 1; n   while (b) { n     if (b & 1) ans = (ans * a) % m; n     b /= 2; n     a = (a * a) % m; n   } n   return ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long int n, k; n   cin >> n >> k; n   long long int ans = 6; n   if (n == 2) { n     cout << ans << endl; n     return 0; n   } n   if (k == 1 || k == n) { n     ans = ans + 3 * (n - 2); n   } else { n     k = min(k, n - k + 1); n     for (long long int i = 1; i < k - 1; i++) ans = ans + 3; n     ans = ans + (k - 1); n     ans = ans + 3 * (n - k); n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, a, b, c, d, s = 0; n   cin >> n; n   while (n--) { n     cin >> a >> b >> c >> d; n     s = s + (c - a + 1) * (d - b + 1); n   } n   printf( %d , s); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int T, t[200010], n; n int dp[2000][2000]; n int main() { n   scanf( %d , &T); n   while (T--) { n     scanf( %d , &n); n     for (int i = 1; i <= n; ++i) n       for (int j = 1; j <= n + n; ++j) dp[i][j] = (1 << 30); n     for (int i = 1; i <= n; ++i) scanf( %d , &t[i]); n     sort(t + 1, t + n + 1); n     for (int i = 1; i <= n; ++i) { n       for (int j = i; j <= n + n; ++j) { n         if (j == 1) { n           dp[i][j] = abs(t[i] - 1); n           continue; n         } n         for (int k = 1; k < j; ++k) { n           dp[i][j] = min(dp[i][j], dp[i - 1][k] + abs(j - t[i])); n         } n       } n     } n     int ans = (1 << 30); n     for (int i = 1; i <= n + n; ++i) ans = min(ans, dp[n][i]); n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void input(T &x) { n   char c = getchar(); n   x = 0; n   for (; (c < 48 || c > 57); c = getchar()) n     ; n   for (; c > 47 && c < 58; c = getchar()) { n     x = (x << 1) + (x << 3) + c - 48; n   } n } n inline long long bigmod(long long p, long long e, long long M) { n   long long ret = 1; n   for (; e > 0; e >>= 1) { n     if (e & 1) ret = (ret * p) % M; n     p = (p * p) % M; n   } n   return ret; n } n template <class T> n inline T gcd(T a, T b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n template <class T> n inline T modinverse(T a, T M) { n   return bigmod(a, M - 2, M); n } n const int N = 10005; n int dp[N]; n int n; n int a[N]; n int main() { n   input(n); n   for (int i = 0; i < n; i++) input(a[i]); n   long long ans = 0; n   for (int round = 0; round < n; round++) { n     int f = (n - round) % n; n     vector<pair<int, int> > v; n     v.push_back(make_pair(0, 0)); n     for (int j = 1; j < n; j++) { n       int now = (f + j) % n; n       int range = a[now]; n       int iMin = 1e8; n       for (int k = v.size() - 1; k >= 0; k--) { n         int pos = v[k].second; n         if (j - range <= pos) n           iMin = min(iMin, 1 + v[k].first); n         else n           break; n       } n       while (v.size() && v.back().first >= iMin) v.pop_back(); n       v.push_back(make_pair(iMin, j)); n     } n     ans += v.back().first; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N, M, dp[109][109][26]; n vector<pair<int, char> > v[109]; n void solve(int i, int j, int k) { n   if (dp[i][j][k] != -1) return; n   dp[i][j][k] = 0; n   for (auto e : v[i]) n     if (e.second >= k) { n       solve(j, e.first, e.second); n       if (dp[j][e.first][e.second] == 0) { n         dp[i][j][k] = 1; n         break; n       } n     } n } n int main() { n   scanf( %d %d , &N, &M); n   while (M--) { n     int x, y; n     char c; n     scanf( %d %d %c n , &x, &y, &c), c -=  a ; n     v[x].push_back({y, c}); n   } n   for (int k = 25; k >= 0; k--) n     for (int i = 1; i <= N; i++) n       for (int j = 1; j <= N; j++) dp[i][j][k] = -1; n   for (int k = 25; k >= 0; k--) n     for (int i = 1; i <= N; i++) n       for (int j = 1; j <= N; j++) solve(i, j, k); n   for (int i = 1; i <= N; i++, printf(  n )) n     for (int j = 1; j <= N; j++) { n       bool win = 0; n       for (auto e : v[i]) n         if (dp[j][e.first][e.second] == 0) { n           win = 1; n           break; n         } n       if (win) n         printf( A ); n       else n         printf( B ); n     } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   char str[999]; n   cin >> str; n   str[0] = toupper(str[0]); n   cout << str << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1000000009; n const int MAXN = 128; n const int MAXK = 4; n struct TrieNode { n   int next[MAXK], fail; n   int danger; n   void init() { n     fail = -1; n     danger = 0; n     for (int i = 0; i < MAXK; ++i) next[i] = -1; n   } n } T[MAXN]; n int root, Top; n void Init() { n   root = 0, Top = 1; n   T[root].init(); n } n int GetId(char ch) { n   switch (ch) { n     case  A : n       return 0; n     case  G : n       return 1; n     case  C : n       return 2; n     case  T : n       return 3; n   } n } n void TrieIns(char *s) { n   int i = 0; n   int p = root; n   while (s[i]) { n     int idx = GetId(s[i]); n     if (T[p].next[idx] == -1) { n       T[Top].init(); n       T[p].next[idx] = Top++; n     } n     p = T[p].next[idx]; n     i++; n   } n   T[p].danger = strlen(s); n } n void Build_AC_Automation() { n   int cur, tmp; n   queue<int> q; n   T[root].fail = root; n   T[root].danger = 0; n   q.push(root); n   while (!q.empty()) { n     cur = q.front(); n     q.pop(); n     for (int i = 0; i < MAXK; ++i) { n       if (T[cur].next[i] != -1) { n         tmp = T[cur].next[i]; n         if (cur == root) n           T[tmp].fail = root; n         else { n           T[tmp].fail = T[T[cur].fail].next[i]; n           T[tmp].danger = max(T[tmp].danger, T[T[tmp].fail].danger); n         } n         q.push(tmp); n       } else { n         if (cur == root) n           T[cur].next[i] = root; n         else n           T[cur].next[i] = T[T[cur].fail].next[i]; n       } n     } n   } n } n long long dp[1010][128][11]; n int n, m; n int main() { n   memset(dp, 0, sizeof(dp)); n   cin >> n >> m; n   Init(); n   for (int i = 0; i < m; ++i) { n     char str[20]; n     cin >> str; n     TrieIns(str); n   } n   Build_AC_Automation(); n   dp[0][0][0] = 1; n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < Top; ++j) { n       for (int k = 0; k <= 10; ++k) { n         if (dp[i][j][k] == 0) continue; n         for (int t = 0; t < MAXK; ++t) { n           int aa = T[j].next[t]; n           if (T[aa].danger > k) { n             dp[i + 1][aa][0] += dp[i][j][k]; n             dp[i + 1][aa][0] %= MOD; n           } else if (k + 1 <= 10) { n             dp[i + 1][aa][k + 1] += dp[i][j][k]; n             dp[i + 1][aa][k + 1] %= MOD; n           } n         } n       } n     } n   } n   long long ans = 0; n   for (int i = 0; i < Top; ++i) { n     ans = ans + dp[n][i][0]; n     ans %= MOD; n   } n   cout << ans % MOD << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int digit(int n) { n   int counter = 0; n   while (n != 0) { n     counter++; n     n /= 10; n   } n   return counter; n } n int main() { n   int T; n   cin >> T; n   for (int i = 0; i < T; i++) { n     int n; n     cin >> n; n     if (n == 1) { n       cout << -1 <<   n ; n     } else { n       cout << 5; n       for (int j = 0; j < n - 1; j++) { n         cout << 7; n       } n       cout <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n void base() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n } n int32_t main() { n   base(); n   int n, num; n   cin >> n >> num; n   int turn = 1; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       if (turn == j) { n         cout << num <<    ; n       } else { n         cout << 0 <<    ; n       } n     } n     cout << endl; n     turn++; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct edge { n   int v, id; n   edge *next; n } * h[233333], pool[555555]; n int top; n inline void addedge(int u, int v, int id) { n   edge *tmp = &pool[top++]; n   tmp->v = v; n   tmp->id = id; n   tmp->next = h[u]; n   h[u] = tmp; n   edge *pmt = &pool[top++]; n   pmt->v = u; n   pmt->id = -id; n   pmt->next = h[v]; n   h[v] = pmt; n } n int n, m; n int s[233333], f[233333], vis[233333], pa[233333]; n void dfs(int u) { n   vis[u] = 1; n   for (edge *tmp = h[u]; tmp; tmp = tmp->next) { n     if (tmp->v != pa[u] && !vis[tmp->v]) { n       pa[tmp->v] = u; n       dfs(tmp->v); n       if (s[tmp->v]) { n         if (tmp->id > 0) n           f[tmp->id] += s[tmp->v]; n         else n           f[-tmp->id] -= s[tmp->v]; n         s[u] += s[tmp->v]; n       } n     } n   } n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &s[i]); n   scanf( %d , &m); n   int u, v; n   for (int i = 1; i <= m; i++) { n     scanf( %d%d , &u, &v); n     addedge(u, v, i); n   } n   for (int i = 1; i <= n; i++) { n     if (!vis[i]) { n       dfs(i); n       if (s[i] != 0) { n         printf( Impossible n ); n         return 0; n       } n     } n   } n   printf( Possible n ); n   for (int i = 1; i <= m; i++) printf( %d n , f[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long n, m, count = 0; n   cin >> n >> m; n   long long a[m]; n   for (long long i = 0; i < m; i++) { n     cin >> a[i]; n     for (long long j = 0; j < i; j++) { n       if (a[j] < a[i]) count++; n     } n   } n   cout << count <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long t; n   cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n const int N = 100001; n using namespace std; n long long a[N], sum[N]; n int main() { n   int n; n   while (scanf( %d , &n) == 1) { n     for (int i = 1; i <= n; i++) scanf( %I64d , &a[i]); n     for (int i = 1, j; i < n; i++) { n       for (j = 0; (1 << j) + i <= n; j++) n         ; n       j--; n       a[i + (1 << j)] += a[i]; n     } n     long long ans = 0; n     for (int i = 1; i < n; i++) { n       ans += a[i]; n       printf( %I64d n , ans); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int main() { n   scanf( %d%d , &n, &m); n   if (n == 1 && m == 2) { n     printf( 0 n1 1 n1 2 n1 1 n ); n     return 0; n   } n   if (n == 2 && m == 1) { n     printf( 0 n1 1 n2 1 n1 1 n ); n     return 0; n   } n   if (n * m % 2 == 1 || n == 1 || m == 1) { n     printf( %d n%d %d %d %d n , 1, n, m, 1, 1); n     for (int i = 1; i <= n; ++i) { n       if (i % 2 == 1) { n         for (int j = 1; j <= m; ++j) printf( %d %d n , i, j); n       } else { n         for (int j = m; j > 0; --j) printf( %d %d n , i, j); n       } n     } n     printf( %d %d n , 1, 1); n   } else if (n % 2 == 0) { n     printf( 0 n1 1 n ); n     for (int i = 1; i <= n; ++i) { n       if (i % 2 == 1) { n         for (int j = 2; j <= m; ++j) printf( %d %d n , i, j); n       } else { n         for (int j = m; j > 1; --j) printf( %d %d n , i, j); n       } n     } n     for (int i = n; i > 0; --i) printf( %d %d n , i, 1); n   } else { n     printf( 0 n1 1 n ); n     for (int j = 1; j <= m; ++j) { n       if (j % 2 == 1) { n         for (int i = 2; i <= n; ++i) printf( %d %d n , i, j); n       } else { n         for (int i = n; i > 1; --i) printf( %d %d n , i, j); n       } n     } n     for (int j = m; j > 0; --j) printf( %d %d n , 1, j); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool b[123][123]; n int arr[123][123]; n int k[123]; n int z[123]; n int main() { n   cin.tie(0); n   ios_base::sync_with_stdio(0); n   bool valid = 0, flag = 0; n   pair<int, int> ans1, ans2; n   int n; n   cin >> n; n   string s, t; n   cin >> s >> t; n   for (int i = 0; i < s.size(); i++) { n     if (s[i] != t[i]) { n       if (b[t[i] -  a ][s[i] -  a ]) { n         ans2 = make_pair(arr[t[i] -  a ][s[i] -  a ] + 1, i + 1); n         flag = 1; n         break; n       } n       if (!valid) { n         if (z[t[i] -  a ] == 1) { n           ans1 = make_pair(k[t[i] -  a ] + 1, i + 1); n           valid = 1; n         } else if (z[s[i] -  a ] == 2) { n           ans1 = make_pair(k[s[i] -  a ] + 1, i + 1); n           valid = 1; n         } n       } n       z[s[i] -  a ] = 1; n       z[t[i] -  a ] = 2; n       k[s[i] -  a ] = i; n       k[t[i] -  a ] = i; n       b[s[i] -  a ][t[i] -  a ] = 1; n       arr[s[i] -  a ][t[i] -  a ] = i; n     } n   } n   int h = 0; n   for (int i = 0; i < s.size(); i++) { n     if (s[i] != t[i]) h++; n   } n   if (flag) { n     cout << h - 2 << endl; n     cout << ans2.first <<     << ans2.second << endl; n   } else if (valid) { n     cout << h - 1 << endl; n     cout << ans1.first <<     << ans1.second << endl; n   } else { n     cout << h << endl; n     cout <<  -1  n          <<     n          <<  -1  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m; n long long a[100]; n long long ans = 1e18; n long long po[100]; n map<long long, long long> ma; n long long fun(long long left1) { n   long long ans1 = 1e18; n   if (left1 <= 0) { n     return 0; n   } n   for (long long i = 0; i < n; i++) { n     long long left = left1; n     long long temp = 0; n     if (po[i] >= left) n       left = 0, temp = a[i]; n     else if (left % po[i] == 0) { n       temp = left / po[i]; n       temp *= a[i]; n       left = 0; n     } else { n       temp = left / po[i]; n       temp *= a[i]; n       left = left % po[i]; n     } n     if (ma[left] != 0) n       ans1 = min(ans1, temp + ma[left]); n     else { n       ma[left] = fun(left); n       ans1 = min(ans1, temp + ma[left]); n     } n   } n   return ans1; n } n int main() { n   cin >> n >> m; n   for (long long i = 0; i < n; i++) cin >> a[i]; n   po[0] = 1; n   for (long long i = 1; i <= 30; i++) { n     po[i] = po[i - 1] * 2; n   } n   for (long long i = 0; i < n; i++) { n     long long left = m; n     long long temp; n     if (po[i] >= left) n       left = 0, temp = a[i]; n     else if (left % po[i] == 0) { n       temp = left / po[i]; n       temp *= a[i]; n       left = 0; n     } else { n       temp = left / po[i]; n       temp *= a[i]; n       left = left % po[i]; n     } n     ans = min(ans, temp + fun(left)); n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long l, r; n   cin >> l >> r; n   long long temp = r; n   long long num = 1, ans = 1; n   while (temp) { n     temp /= 10; n     num *= 10; n   } n   num--; n   long long left_lim = (num) / 10; n   long long mid = (num + 1) / 2; n   if (r <= mid) { n     ans = (num - r) * r; n   } else { n     if (l <= mid) { n       ans = (num - mid) * (mid); n     } else { n       ans = (num - l) * l; n     } n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, i, j; n   cin >> n; n   cin >> m; n   int A[n], B[m]; n   for (i = 0; i < n; i++) cin >> A[i]; n   for (j = 0; j < m; j++) cin >> B[j]; n   for (j = 0; j < n; j++) { n     for (i = 0; i < m; i++) { n       if (A[j] == B[i]) cout << A[j] <<    ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, k, x, s, a[200005], b[200005], c[200005], d[200005], ans; n int bfind(int t) { n   int lo = 0, hi = k - 1, mid; n   while (lo < hi) { n     mid = lo + (hi - lo + 1) / 2; n     if (d[mid] > t) n       hi = mid - 1; n     else n       lo = mid; n   } n   return lo; n } n int main() { n   cin >> n >> m >> k >> x >> s; n   for (int i = 0; i < m; i++) scanf( %I64d , &a[i]); n   for (int i = 0; i < m; i++) scanf( %I64d , &b[i]); n   for (int i = 0; i < k; i++) scanf( %I64d , &c[i]); n   for (int i = 0; i < k; i++) scanf( %I64d , &d[i]); n   ans = x * n; n   for (int i = 0; i < m; i++) { n     if (b[i] <= s) ans = min(ans, a[i] * n); n   } n   for (int i = 0; i < k; i++) { n     if (d[i] <= s) ans = min(ans, x * (n - c[i])); n   } n   for (int i = 0; i < m; i++) { n     if (b[i] + d[0] <= s) { n       int idx = bfind(s - b[i]); n       ans = min(ans, a[i] * (n - c[idx])); n     } 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 const int maxn = 100 + 10; n int n, m; n int a[maxn], b[maxn]; n bitset<65> tt1[50000], tt2[50000]; n vector<int> v; n map<int, int> mp; n int main() { n   cin >> n >> m; n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < m; i++) cin >> b[i]; n   bitset<65> *t1 = tt1 + 25000, *t2 = tt2 + 25000; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       t1[a[i] + b[j]][i] = 1; n       t2[a[i] + b[j]][j] = 1; n       if (!mp[a[i] + b[j]]) { n         mp[a[i] + b[j]] = 1; n         v.push_back(a[i] + b[j]); n       } n     } n   } n   int mine = -1; n   for (int i = 0; i < v.size(); i++) { n     for (int j = 0; j < v.size(); j++) { n       int sum = (t1[v[i]] | t1[v[j]]).count() + (t2[v[i]] | t2[v[j]]).count(); n       if (sum > mine) mine = sum; n     } n   } n   printf( %d n , mine); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[2001000]; n int Partition(int l, int r) { n   int temp = l + rand() % (r - l); n   swap(a[l], a[temp]); n   int x = a[l], i = l - 1, j = r + 1; n   while (1) { n     do i++; n     while (a[i] < x); n     do j--; n     while (a[j] > x); n     if (i < j) n       swap(a[i], a[j]); n     else n       return j; n   } n } n void QuickSort(int l, int r) { n   if (l < r) { n     int q = Partition(l, r); n     QuickSort(l, q); n     QuickSort(q + 1, r); n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i]; n   QuickSort(0, n - 1); n   for (int i = 0, j = n - 1; i < j; i++, j--) swap(a[i], a[j]); n   long long k = 0; n   for (int i = 0; pow(4, i) <= n + 1; i++) n     for (int j = 0; j < pow(4, i); j++) k += a[j]; n   cout << k << endl; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline T sqr(const T &a) { n   return a * a; n } n template <typename T> n inline int nread(vector<T> &a) { n   int n; n   cin >> n; n   a.clear(); n   a.resize(n); n   for (int i = 0; i < n; i++) cin >> a[i]; n   return n; n } n template <typename T> n inline void nwread(int n, vector<T> &a) { n   a.clear(); n   a.resize(n); n   for (int i = 0; i < n; i++) cin >> a[i]; n } n const int N = 3001; n int gr[N][N], cg[N]; n int res[N * N]; n pair<int, int> que[N * N]; n int main() { n   int n, m, k; n   cin >> n >> m >> k; n   for (int i = 0; i < n; i++) cg[i] = 0; n   for (int i = 0; i < m; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     x--; n     y--; n     gr[x][cg[x]++] = y; n     gr[y][cg[y]++] = x; n   } n   set<pair<pair<int, int>, int> > zapr; n   for (int i = 0; i < k; i++) { n     int x, y, z; n     scanf( %d%d%d , &x, &y, &z); n     x--; n     y--; n     z--; n     zapr.insert(make_pair(make_pair(x, y), z)); n   } n   map<pair<int, int>, int> path; n   int qi = 0, qj = 1; n   que[0] = make_pair(-1, 0); n   while (qi < qj) { n     pair<int, int> tek = que[qi++]; n     int pv = tek.first, tv = tek.second; n     vector<int> nreb; n     for (int i = 0; i < cg[tv];) { n       int fv = gr[tv][i]; n       if (zapr.count(make_pair(tek, fv))) n         i++; n       else { n         que[qj++] = make_pair(tv, fv); n         path[make_pair(tv, fv)] = pv; n         if (fv == n - 1) { n           int lr = 2; n           res[0] = fv; n           res[1] = tv; n           while (tv != 0) { n             pv = path[make_pair(tv, fv)]; n             res[lr++] = pv; n             fv = tv; n             tv = pv; n           } n           reverse(res, res + lr); n           cout << lr - 1 << endl; n           for (int i = 0; i < lr; i++) printf( %d  , res[i] + 1); n           return 0; n         } n         if (cg[tv]) gr[tv][i] = gr[tv][cg[tv] - 1]; n         cg[tv]--; n       } n     } n   } n   cout << -1; n } n


#include <bits/stdc++.h> n using namespace std; n int a[210000]; n long long dp[210000][2]; n const long long INF = 1LL << 60; n int N; n void init() { n   for (int i = 0; i < 210000; i++) n     for (int j = 0; j < 2; j++) dp[i][j] = INF; n } n long long solve(int x, bool t) { n   if (x <= 0 || x > N) return 0; n   if (x == 1) return -1; n   if (dp[x][t] == -INF) return dp[x][t] = -1; n   if (dp[x][t] != INF) return dp[x][t]; n   dp[x][t] = -INF; n   int i2 = x; n   if (t) n     i2 += a[x]; n   else n     i2 -= a[x]; n   long long r = solve(i2, !t); n   long long res; n   if (r == -1) n     res = -1; n   else n     res = a[x] + r; n   return dp[x][t] = res; n } n int main() { n   cin >> N; n   for (int i = 2; i <= N; i++) cin >> a[i]; n   init(); n   for (int i = 1; i < N; i++) { n     long long ret = solve(1 + i, false); n     if (~ret) ret += i; n     cout << ret << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n #pragma GCC target( sse4 ) n using namespace std; n using ii = pair<int, int>; n using ll = long long; n const int N = 1e5 + 5; n const int mod = 1e9 + 7; n char str1[50005], str2[50005]; n int n, m; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> str1; n   n = strlen(str1); n   for (int sz = 1; sz <= n / 2; sz++) { n     m = sz; n     int cur = 0; n     for (int i = sz; i < n; i++) { n       if (str1[i] == str1[i - sz]) n         cur++; n       else n         cur = 0; n       str2[m++] = str1[i]; n       if (cur == sz) cur = 0, m -= sz; n     } n     for (int i = sz; i < m; i++) str1[i] = str2[i]; n     n = m; n   } n   for (int i = 0; i < n; i++) cout << str1[i]; 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   if (n == 1) n     printf( 1 n ); n   else { n     if (m * 2 <= n) n       printf( %d n , m + 1); n     else n       printf( %d n , m - 1); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = 3.1415926535897; n int main() { n   double d, h, v, e; n   cin >> d >> h >> v >> e; n   double s = (-1 * h) / (e - ((4 * v) / (pi * d * d))); n   if (s >= 0) n     cout <<  YES  << endl << s; n   else n     cout <<  NO ; n } n


#include <bits/stdc++.h> n using namespace std; n void per() { cerr << endl; } n template <typename Head, typename... Tail> n void per(Head H, Tail... T) { n   cerr << H <<    ; n   per(T...); n } n template <class T> n bool uin(T& a, T b) { n   return a > b ? (a = b, true) : false; n } n template <class T> n bool uax(T& a, T b) { n   return a < b ? (a = b, true) : false; n } n template <class U, class V> n ostream& operator<<(ostream& out, const pair<U, V>& a) { n   return out <<  (  << a.first <<  ,   << a.second <<  ) ; n } n template <class U, class V> n istream& operator>>(istream& in, pair<U, V>& a) { n   return in >> a.first >> a.second; n } n template <typename W, n           typename T = typename enable_if<!is_same<W, string>::value, n                                           typename W::value_type>::type> n ostream& operator<<(ostream& out, const W& v) { n   out <<  {  ; n   for (const auto& first : v) out << first <<  ,  ; n   return out <<  } ; n } n template <class T> n void readArr(T from, T to) { n   for (auto i = from; i != to; ++i) cin >> *i; n } n mt19937 mrand(1337); n unsigned int myRand32() { return mrand() & (unsigned int)(-1); } n unsigned long long myRand64() { n   return ((unsigned long long)myRand32() << 32) ^ myRand32(); n } n const int mod = 1000000007; n void add(int& a, int b) { n   a += b; n   if (a >= mod) a -= mod; n } n void dec(int& a, int b) { n   a -= b; n   if (a < 0) a += mod; n } n int mult(int a, int b) { return a * (long long)b % mod; } n int bp(int a, int b) { n   int res = 1; n   while (b > 0) { n     if (b & 1) res = mult(res, a); n     a = mult(a, a); n     b >>= 1; n   } n   return res; n } n int main() { n   int vl = 1, vr = 1000000000; n   cout <<  ? 1 1  << endl; n   int base1; n   cin >> base1; n   while (vl + 1 < vr) { n     int vm = (vl + vr) >> 1; n     cout <<  ? 1   << vm << endl; n     int first; n     cin >> first; n     if (first == base1 - (vm - 1)) n       vl = vm; n     else n       vr = vm; n   } n   int y1 = vl; n   int x1 = base1 - (y1 - 1) + 1; n   cout <<  ? 1000000000 1  << endl; n   int base2; n   cin >> base2; n   int x2 = 1000000000 - (base2 - (y1 - 1)); n   cout <<  ? 1 1000000000  << endl; n   int base3; n   cin >> base3; n   int y2 = 1000000000 - (base3 - (x1 - 1)); n   cout <<  !   << x1 <<     << y1 <<     << x2 <<     << y2 << endl; n } n


#include <bits/stdc++.h> n int main() { n   int i, j, k, n, t, c1, c2, c3, c4, c5; n   scanf( %d%d%d%d%d , &c1, &c2, &c3, &c4, &c5); n   t = c1 + c2 + c3 + c4 + c5; n   if (t == 0) n     printf( -1 n ); n   else if (t % 5 == 0) n     printf( %d n , t / 5); n   else n     printf( -1 n ); n } n


#include <bits/stdc++.h> n using namespace std; n const int BIG = 1000200; n char buf[BIG]; n int skip0[BIG], skip1[BIG]; n int vpre[BIG]; n struct E { n   int to; n   char sign; n   int pw; n }; n vector<E> vg[BIG]; n int main() { n   while (scanf(  %s , buf) != EOF) { n     string s(buf); n     s =  00  + s; n     int N = (int)((s).size()); n     int prev0 = 0, prev1 = 0; n     memset((skip0), (-1), sizeof(skip0)); n     memset((skip1), (-1), sizeof(skip1)); n     for (int i = 0; i < (int)(N); ++i) { n       skip0[i] = prev0; n       skip1[i] = prev1; n       if (s[i] ==  0 ) { n         prev0 = i; n       } n       if (s[i] ==  1 ) { n         prev1 = i; n       } n     } n     for (int i = 0; i < (int)(BIG); ++i) vg[i].clear(); n     for (int i = 0; i < (int)(N); ++i) { n       if (i == 0) continue; n       vg[i].push_back((E){skip1[i],  + , N - 1 - i}); n       vg[i].push_back((E){skip0[i],  - , N - 1 - i}); n     } n     int start = -1; n     for (int i = 0; i < (int)(N); ++i) n       if (s[N - 1 - i] ==  1 ) { n         start = N - 1 - i; n         break; n       } n     assert(start >= 0); n     queue<pair<int, int> > q; n     memset((vpre), (-1), sizeof(vpre)); n     q.push(make_pair(start, -2)); n     while (!q.empty()) { n       int curr = q.front().first; n       int prev = q.front().second; n       q.pop(); n       if (vpre[curr] != -1) continue; n       vpre[curr] = prev; n       if (curr == 0) break; n       for (__typeof((vg[curr]).begin()) e = (vg[curr]).begin(); n            e != (vg[curr]).end(); ++e) { n         q.push(make_pair(e->to, curr)); n       } n     } n     assert(vpre[0] >= 0); n     vector<E> outp; n     for (int curr = 0; curr >= 0; curr = vpre[curr]) { n       int prev = vpre[curr]; n       for (__typeof((vg[prev]).begin()) e = (vg[prev]).begin(); n            e != (vg[prev]).end(); ++e) { n         if (e->to == curr) { n           outp.push_back(*e); n           break; n         } n       } n     } n     printf( %d n , (int)((outp).size())); n     for (int i = 0; i < (int)((int)((outp).size())); ++i) n       printf( %c2^%d n , outp[i].sign, outp[i].pw); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int NMAX = 5e3; n const double eps = 1e-14; n double dp[NMAX + 5][NMAX + 5]; n int n, k; n double p[NMAX + 5]; n double np[NMAX + 5]; n int t[NMAX + 5]; n int main() { n   scanf( %d %d , &n, &k); n   for (int i = 1; i <= n; i++) { n     int x; n     scanf( %d %d , &x, &t[i]); n     p[i] = x / 100.0; n     np[i] = (100 - x) / 100.0; n   } n   dp[0][0] = 1; n   for (int i = 0; i <= n; i++) { n     double prob = 1; n     for (int j = 1; j <= t[i + 1]; j++) { n       prob *= np[i + 1]; n     } n     for (int j = i; j <= k; j++) { n       if (dp[i][j] < eps) { n         continue; n       } n       if (j < k) { n         dp[i][j + 1] += dp[i][j] * np[i]; n         dp[i + 1][j + 1] += dp[i][j] * p[i + 1]; n         if (j <= k - t[i + 1]) { n           dp[i + 1][j + t[i + 1]] += dp[i][j] * prob; n           if (j <= k - t[i + 1] - 1) { n             dp[i + 1][j + t[i + 1] + 1] -= dp[i][j] * prob; n           } n         } n       } n     } n   } n   double ans = 0; n   for (int i = 1; i < n; i++) { n     double prob = 1; n     for (int j = k; j > k - t[i + 1]; j--) { n       ans += i * dp[i][j] * prob; n       prob *= (1 - p[i + 1]); n     } n   } n   for (int j = 1; j <= k; j++) { n     ans += n * dp[n][j]; n   } n   printf( %.9f n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool cmp(long long a, long long b) { n   if (a > b) return true; n   return false; n } n long long n, dp[100010], res; n pair<long long, long long> a[100010]; n map<long long, long long> m; n map<long long, long long>::iterator it; n int main() { n   int t = 1; n   while (t--) { n     scanf( %lld , &n); n     for (int i = 0; i < n; i++) { n       scanf( %lld%lld , &a[i].first, &a[i].second); n     } n     sort(a, a + n); n     for (int i = 0; i < n; i++) { n       m[a[i].first] = i; n       it = m.lower_bound(a[i].first - a[i].second); n       if (it == m.begin()) n         dp[i] = 1; n       else { n         --it; n         dp[i] = 1 + dp[it->second]; n       } n       res = max(dp[i], res); n     } n     cout << n - res <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, i, sum1 = 0, sum2 = 0, a[200]; n   cin >> n; n   for (i = 0; i < n; i++) { n     cin >> a[i]; n     if (a[i] < 0) { n       sum2 += a[i]; n     } else n       sum1 += a[i]; n   } n   cout << sum1 - sum2; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T, typename U> n inline void smin(T &a, U b) { n   if (a > b) a = b; n } n template <typename T, typename U> n inline void smax(T &a, U b) { n   if (a < b) a = b; n } n int ans[200200], vst[200200], pos[200200], neg[200200]; n set<int> s[200200]; n priority_queue<pair<int, int> > q; n int main() { n   int n, m, k, first; n   cin >> n >> m; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &k); n     q.push(pair<int, int>(-k, i)); n     while (k--) { n       scanf( %d , &first); n       s[i].insert(first); n       if (first > 0) n         pos[first] = i; n       else n         neg[-first] = i; n     } n   } n   for (int i = 1; i <= m; i++) { n     if (!pos[i] || !neg[i]) { n       int u = pos[i] ? pos[i] : neg[i]; n       vst[u] = 1; n       ans[i] = (pos[i] == u); n     } n   } n   while (!q.empty()) { n     int u = q.top().second; n     q.pop(); n     if (vst[u]) continue; n     vst[u] = 1; n     if (s[u].empty()) { n       puts( NO ); n       return 0; n     } n     first = *s[u].begin(); n     if (first > 0) { n       ans[first] = 1; n       if (neg[first]) { n         s[neg[first]].erase(-first); n         q.push(pair<int, int>(-s[neg[first]].size(), neg[first])); n       } n     } else { n       first = -first; n       ans[first] = 0; n       if (pos[first]) { n         s[pos[first]].erase(first); n         q.push(pair<int, int>(-s[pos[first]].size(), pos[first])); n       } n     } n   } n   puts( YES ); n   for (int i = 1; i <= m; i++) putchar(ans[i] +  0 ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char s[200005]; n bool b[200005]; n int n, ans = 0; n void solve(int u) { n   if (u == 1) { n     if (u == n) { n       ans = 1; n       return; n     } n     if (s[u] ==  < ) { n       b[u] = true; n       ans++; n     } n     solve(u + 1); n     if (s[u] ==  > ) n       if (b[u + 1]) ans++; n     return; n   } n   if (u > n) return; n   if (u == n) { n     if (s[u] ==  >  | b[u - 1]) { n       b[u] = true; n       ans++; n     } n     return; n   } n   if (s[u] ==  < ) { n     if (b[u - 1]) { n       b[u] = true; n       ans++; n     } n     solve(u + 1); n   } else { n     solve(u + 1); n     if (b[u + 1]) { n       b[u] = true; n       ans++; n     } n   } n } n int main() { n   scanf( %d , &n); n   scanf( %s , s + 1); n   solve(1); n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int x[10][10]; n int main() { n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < m; i++) { n     int a, b; n     cin >> a >> b; n     x[a][b] = x[b][a] = 1; n   } n   if (n < 7) n     cout << m <<   n ; n   else { n     int sum = 30; n     for (int i = 1; i <= 7; i++) { n       for (int j = i + 1; j <= 7; j++) { n         int ans = 0; n         for (int o = 1; o <= 7; o++) { n           if (x[i][o] == 1 && x[j][o] == 1) ans++; n         } n         if (ans < sum) sum = ans; n       } n     } n     cout << m - sum <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n; n   cin >> n; n   for (long long i = 0; i < n; ++i) { n     if (i % 4 < 2) n       putchar( a ); n     else n       putchar( b ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   int l = s.length(); n   int fc = 0; n   int sc = 0; n   for (int i = 0; i < l; i++) { n     if (s[i] ==  4 ) fc++; n     if (s[i] ==  7 ) sc++; n   } n   if (!fc && !sc) n     cout <<  -1  << endl; n   else if (sc > fc) n     cout <<  7  << endl; n   else n     cout <<  4  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long int T; n   vector<long int> sweet(3); n   cin >> T; n   while (T--) { n     long int sum = 0; n     cin >> sweet[0] >> sweet[1] >> sweet[2]; n     sort(sweet.begin(), sweet.end()); n     sum = min((sweet[2] + sweet[1] + sweet[0]) / 2, n               (sweet[2] + sweet[1] + sweet[0]) - sweet[2]); n     cout << sum << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n inline bool is_palindrome(const string& s) { n   return std::equal(s.begin(), s.end(), s.rbegin()); n } n const long long MOD = 1000000007; n const long long INF = 1e9 + 5; n const double eps = 1e-7; n const double PI = acos(-1.0); n inline void debug_vi(vector<int> a) { n   for (long long i = (long long)(0); i < (long long)(a.size()); i++) n     cout << a[i] <<    ; n } n inline void debug_vll(vector<long long> a) { n   for (long long i = (long long)(0); i < (long long)(a.size()); i++) n     cout << a[i] <<    ; n } n const int N = 1e5 + 5; n int in[N]; n int main() { n   std::ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int n, s, a, b; n   cin >> n >> s; n   memset(in, 0, sizeof(in)); n   for (long long i = (long long)(0); i < (long long)(n - 1); i++) { n     cin >> a >> b; n     a--; n     b--; n     in[a]++; n     in[b]++; n   } n   int l = 0; n   for (long long i = (long long)(0); i < (long long)(n); i++) { n     if (in[i] == 1) { n       l++; n     } n   } n   double ans = 2.0 * s / l; n   cout << fixed << showpoint << setprecision(15) << ans; n   ; n   return 0; n } n