#include <bits/stdc++.h> n using namespace std; n int cum[200000]; n int main() { n   int n, x, k; n   cin >> n >> x >> k; n   int arr[n + 10]; n   set<int> st; n   map<int, int> pos; n   int now = 0; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &arr[i]); n     st.insert(arr[i]); n   } n   for (set<int>::iterator it = st.begin(); it != st.end(); it++) { n     pos[*it] = ++now; n   } n   for (int i = 1; i <= n; i++) { n     cum[pos[arr[i]]]++; n   } n   for (int i = 1; i <= now; i++) { n     cum[i] += cum[i - 1]; n   } n   long long res = 0; n   for (int i = 1; i <= n; i++) { n     long long pres = arr[i]; n     long long first, lst; n     if (k > 0) { n       pres = arr[i]; n       if (arr[i] % x != 0) pres = pres + (x - (arr[i] % x)); n       pres += (k - 1) * 1LL * x; n       first = pres; n       lst = pres + x - 1; n     } else { n       pres = arr[i]; n       if (arr[i] % x != 0) pres = pres + (x - (arr[i] % x)); n       first = arr[i]; n       lst = pres - 1; n     } n     if (*st.rbegin() < lst) n       lst = *st.rbegin(); n     else { n       if (st.find(lst) == st.end()) { n         set<int>::iterator it = (st.upper_bound(lst)); n         it--; n         lst = *it; n       } n     } n     if (*st.rbegin() < first) n       first = lst + 10; n     else { n       if (st.find(first) == st.end()) { n         set<int>::iterator it = (st.upper_bound(first)); n         first = *it; n       } n     } n     if (lst >= first) { n       res += (cum[pos[lst]] - cum[pos[first] - 1]); n     } n   } n   cout << res << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int a, b, mn = 1000000009, mx; n char c[59][59]; n int ist, ien; n bool w; n int main() { n   cin >> a >> b; n   for (int i = 1; i <= a; i++) n     for (int j = 1; j <= b; j++) { n       cin >> c[i][j]; n       if (c[i][j] ==  * ) n         mn = min(j, mn), mx = max(j, mx), (w == 0 ? ist = i : ist = ist), n         ien = i, w = 1; n     } n   for (int i = ist; i <= ien; i++) { n     for (int j = mn; j <= mx; j++) cout << c[i][j]; n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     for (int i = 1; i <= n; i++) cout << i <<    ; n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int q; n   cin >> q; n   while (q--) { n     long long int b, w; n     cin >> b >> w; n     if (b >= w) { n       if (b > 3 * w + 1) { n         std::cout <<  NO  << std::endl; n         continue; n       } else { n         std::cout <<  YES  << std::endl; n         for (long long int i = 0; i < 2 * w; i += 2) { n           std::cout << 2 <<     << i + 2 << std::endl; n         } n         for (long long int i = 0; i < 2 * b && i < 2 * w; i += 2) { n           std::cout << 2 <<     << i + 3 << std::endl; n         } n         b = b - w; n         if (b > 0) { n           std::cout << 2 <<     << 1 << std::endl; n         } n         b--; n         long long int i = 0; n         while (b > 0) { n           std::cout << 1 <<     << i + 2 << std::endl; n           b--; n           if (b > 0) std::cout << 3 <<     << i + 2 << std::endl; n           b--; n           i += 2; n         } n       } n     } else { n       if (w > 3 * b + 1) { n         std::cout <<  NO  << std::endl; n         continue; n       } else { n         std::cout <<  YES  << std::endl; n         for (long long int i = 0; i < 2 * b; i += 2) { n           std::cout << 2 <<     << i + 3 << std::endl; n         } n         for (long long int i = 0; i < 2 * w && i < 2 * b; i += 2) { n           std::cout << 2 <<     << i + 4 << std::endl; n         } n         w = w - b; n         if (w > 0) std::cout << 2 <<     << 2 << std::endl; n         w--; n         long long int i = 0; n         while (w > 0) { n           std::cout << 1 <<     << i + 3 << std::endl; n           w--; n           if (w > 0) std::cout << 3 <<     << i + 3 << std::endl; n           w--; n           i += 2; n         } n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int a[100010]; n int s[100010]; n int solve() { n   int ret = 0, top = 0; n   for (int i = 0; i < n; i++) { n     while (top && a[s[top]] < a[i]) --top; n     if (top) ret = max(ret, a[s[top]] ^ a[i]); n     s[++top] = i; n   } n   return ret; n } n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i]; n   reverse(a, a + n); n   int ans = solve(); n   reverse(a, a + n); n   ans = max(ans, solve()); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n long long pw(long long a, long long b, long long p) { n   if (b == 0) return 1; n   long long t = pw(a, b / 2, p); n   if (b % 2) n     return ((a * t * t) % p); n   else n     return ((t * t) % p); n } n long long cost[100005], vis[100005], ini[100005], lb[100005]; n long long abmc = 0, abtw = 1; n vector<long long> v[100005]; n pair<long long, pair<long long, long long> > dfs(long long z, long long iniz, n                                                  long long lev) { n   if (vis[z]) { n     if (ini[z] != iniz) return {-1, {-1, 1}}; n     return {lb[z], {-1, 1}}; n   } n   vis[z] = 1; n   lb[z] = lev; n   ini[z] = iniz; n   long long cmi = -1, mc = -1, tw = 1; n   for (long long k : v[z]) { n     pair<long long, pair<long long, long long> > t = dfs(k, iniz, lev + 1); n     if (t.first == -1) continue; n     if (cmi == -1 || t.first < cmi) cmi = t.first; n     if (t.second.first == -1) continue; n     if (mc == -1 || t.second.first < mc) { n       mc = t.second.first; n       tw = t.second.second; n     } else if (mc == t.second.first) n       tw += t.second.second; n   } n   lb[z] = cmi; n   if (cmi == -1) { n     abmc += cost[z]; n   } else if (cmi <= lev) { n     if (cost[z] < mc || mc == -1) { n       mc = cost[z]; n       tw = 1; n     } else if (cost[z] == mc) n       tw++; n   } n   if (cmi == lev) { n     cmi = -1; n     abmc += mc; n     abtw = (abtw * tw) % 1000000007; n     mc = -1; n     tw = 1; n   } n   return {cmi, {mc, tw}}; n } n void solve() { n   long long n; n   cin >> n; n   for (long long i = 1; i <= n; i++) { n     cin >> cost[i]; n   } n   long long m; n   cin >> m; n   for (long long i = 0; i < m; i++) { n     long long a, b; n     cin >> a >> b; n     v[a].push_back(b); n   } n   for (long long i = 1; i <= n; i++) { n     if (!vis[i]) dfs(i, i, 0); n   } n   cout << abmc <<     << abtw; n } n signed main() { n   ios_base::sync_with_stdio(false); n   long long t = 1; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = int(1e9) + 7; n const int MX = 200500; n long long f[MX]; n long long f1[MX]; n int pow_mod(long long a, int st) { n   a %= mod; n   long long res = 1; n   while (st) { n     if (st & 1) { n       res *= a; n       res %= mod; n     } n     a *= a; n     a %= mod; n     st >>= 1; n   } n   return res; n } n void init() { n   f[0] = 1; n   for (int i = 1; i < MX; i++) { n     f[i] = f[i - 1] * i; n     f[i] %= mod; n   } n   f1[MX - 1] = pow_mod(f[MX - 1], mod - 2); n   for (int i = MX - 2; i >= 0; i--) { n     f1[i] = f1[i + 1] * (i + 1); n     f1[i] %= mod; n   } n } n int c(int n, int k) { n   long long res = f[n] * f1[k]; n   res %= mod; n   res *= f1[n - k]; n   return res % mod; n } n int go1(int, int); n int go0(int c0, int c1) { n   if (c0 < 0 || c1 < 0) return 0; n   if (c0 == 1 && c1 == 0) return 1; n   if (c0 == 0 && c1 == 1) return 0; n   int ans = 0; n   if (c1) ans = c(c0 + c1 - 1, c0); n   if (c0) ans += go1(c0 - 1, c1); n   return ans % mod; n } n int go1(int c0, int c1) { n   if (c0 == 0 && c1 == 1) return 1; n   return go0(c0 - 1, c1); n } n int main() { n   init(); n   ios_base::sync_with_stdio(false); n   int n, m, g; n   cin >> n >> m >> g; n   if (g) n     cout << go1(n, m) << endl; n   else n     cout << go0(n, m) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename TH> n void _dbg(const char* sdbg, TH h) { n   cerr << sdbg <<  =  << h <<   n ; n } n template <typename TH, typename... TA> n void _dbg(const char* sdbg, TH h, TA... t) { n   while (*sdbg !=  , ) cerr << *sdbg++; n   cerr <<  =  << h <<  , ; n   _dbg(sdbg + 1, t...); n } n template <class C> n void mini(C& a4, C b4) { n   a4 = min(a4, b4); n } n template <class C> n void maxi(C& a4, C b4) { n   a4 = max(a4, b4); 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 A, class B, class C> n struct Triple { n   A first; n   B second; n   C third; n   bool operator<(const Triple& t) const { n     if (first != t.first) return first < t.first; n     if (second != t.second) return second < t.second; n     return third < t.third; n   } n }; n template <class T> n void ResizeVec(T&, vector<long long>) {} n template <class T> n void ResizeVec(vector<T>& vec, vector<long long> sz) { n   vec.resize(sz[0]); n   sz.erase(sz.begin()); n   if (sz.empty()) { n     return; n   } n   for (T& v : vec) { n     ResizeVec(v, sz); n   } n } n template <class A, class B, class C> n ostream& operator<<(ostream& out, Triple<A, B, C> t) { n   return out <<  (  << t.first <<  ,   << t.second <<  ,   << t.third <<  ) ; 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 const long long N = 1e5 + 5; n long long par[N]; n long long rep[N]; n long long sum2[N]; n long long sz_cc[N]; n long long sz_sub[N]; n long long score[N]; n long long Find(long long x) { n   if (rep[x] == x) { n     return x; n   } n   return rep[x] = Find(rep[x]); n } n long long n; n long long res; n long long pre[N], post[N]; n long long d; n vector<long long> slo[N]; n long long IsAnc(long long a, long long b) { n   return pre[a] <= pre[b] && post[b] <= post[a]; n } n void Union(long long a, long long b) { n   a = Find(a); n   b = Find(b); n   assert(IsAnc(a, b)); n   if (a == b) { n     return; n   } n   res -= score[a]; n   res -= score[b]; n   long long lower = sz_sub[b]; n   sum2[a] -= lower * lower; n   long long upper = n - lower; n   sum2[b] -= upper * upper; n   sum2[a] += sum2[b]; n   sz_cc[a] += sz_cc[b]; n   long long s = sz_cc[a]; n   score[a] = s * (s - 1) * (s - 2) + 2 * s * (s - 1) * (n - s) + n              s * ((n - s) * (n - s) - sum2[a]); n   res += score[a]; n   rep[b] = a; n } n void Dfs(long long v) { n   sz_sub[v] = 1; n   d++; n   pre[v] = d; n   for (auto nei : slo[v]) { n     if (sz_sub[nei]) { n       continue; n     } n     par[nei] = v; n     Dfs(nei); n     sum2[v] += sz_sub[nei] * sz_sub[nei]; n     sz_sub[v] += sz_sub[nei]; n   } n   long long upper = n - sz_sub[v]; n   sum2[v] += upper * upper; n   long long s = 1; n   score[v] = s * (s - 1) * (s - 2) + 2 * s * (s - 1) * (n - s) + n              s * ((n - s) * (n - s) - sum2[v]); n   res += score[v]; n   d++; n   post[v] = d; n } n int32_t main() { n   ios_base::sync_with_stdio(0); n   cout << fixed << setprecision(10); n   if (0) cout << fixed << setprecision(10); n   cin.tie(0); n   cin >> n; n   for (long long i = (1); i <= (n); ++i) { n     rep[i] = i; n     sz_cc[i] = 1; n   } n   for (long long i = (1); i <= (n - 1); ++i) { n     long long a, b; n     cin >> a >> b; n     slo[a].push_back(b); n     slo[b].push_back(a); n   } n   Dfs(1); n   long long q; n   cin >> q; n   cout << res <<   n ; n   for (long long i = (1); i <= (q); ++i) { n     long long a, b; n     cin >> a >> b; n     a = Find(a); n     b = Find(b); n     while (!IsAnc(a, b)) { n       Union(par[a], a); n       a = Find(a); n     } n     while (!IsAnc(b, a)) { n       Union(par[b], b); n       b = Find(b); n     } n     cout << res <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dp[1 << 25]; n int n, m; n int a[30][30]; n int qi[30][30]; n int st[30][30]; n char c[30][30]; n int lowbit(int x) { return (x & (-x)); } n int main() { n   scanf( %d , &n); n   scanf( %d , &m); n   for (int i = 1; i <= n; i++) scanf( %s , c[i] + 1); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) scanf( %d , &a[i][j]); n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       int it = -2e9, sum = 0; n       for (int k = 1; k <= n; k++) { n         if (c[k][j] == c[i][j]) { n           st[i][j] |= (1 << (k - 1)); n           sum += a[k][j]; n           it = max(it, a[k][j]); n         } n       } n       sum -= it; n       qi[i][j] = sum; n     } n   } n   memset(dp, 127, sizeof(dp)); n   dp[0] = 0; n   for (int i = 0; i <= (1 << n) - 1; i++) { n     for (int k = 0; k < n; k++) n       if (!((1 << k) & i)) n         for (int j = 1; j <= m; j++) { n           dp[i | (1 << k)] = min(dp[i | (1 << k)], dp[i] + a[k + 1][j]); n           dp[i | st[k + 1][j]] = n               min(dp[i] + qi[k + 1][j], dp[i | st[k + 1][j]]); n         } n   } n   cout << dp[(1 << n) - 1] << endl; n } n


#include <bits/stdc++.h> n long long n, i, j, h, k, t, d, m, a, b, c; n using namespace std; n char s; n string ss; n int main() { n   cin >> t; n   for (h = 1; h <= t; h++) { n     cin >> n; n     ss =  . ; n     while (n > ss.length()) ss = ss +  . ; n     cin >> a >> b >> c; n     d = 0; n     for (i = 0; i < n; i++) { n       cin >> s; n       if (s ==  R  && b > 0) { n         b--; n         d++; n         ss[i] =  P ; n       } n       if (s ==  P  && c > 0) { n         c--; n         d++; n         ss[i] =  S ; n       } n       if (s ==  S  && a > 0) { n         a--; n         d++; n         ss[i] =  R ; n       } n     } n     if (d >= (n + 1) / 2) { n       i = 0; n       while (a > 0) { n         if (ss[i] ==  . ) ss[i] =  R , a--; n         i++; n       } n       while (b > 0) { n         if (ss[i] ==  . ) ss[i] =  P , b--; n         i++; n       } n       while (c > 0) { n         if (ss[i] ==  . ) ss[i] =  S , c--; n         i++; n       } n       cout <<  YES  << endl; n       for (i = 0; i < n; i++) cout << ss[i]; n       cout << endl; n     } else n       cout <<  NO  << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   string s; n   cin >> s; n   queue<int> v1; n   deque<int> v2; n   for (int i = 0; i < s.size(); i++) { n     if (s[i] ==  ( ) n       v1.push(i); n     else { n       v2.push_front(i); n     } n   } n   int k = 0; n   vector<int> res; n   while (!v1.empty() && !v2.empty()) { n     if (v1.front() > v2.front()) { n       v1.pop(); n       v2.pop_front(); n       continue; n     } n     k += 2; n     res.push_back(v2.front()); n     res.push_back(v1.front()); n     v1.pop(); n     v2.pop_front(); n   } n   sort(res.begin(), res.end()); n   if (k == 0) return cout << 0, 0; n   cout << 1 <<   n ; n   cout << k <<   n ; n   for (auto i : res) cout << i + 1 <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 5; n long long a[maxn]; n int main() { n   int n; n   scanf( %d , &n); n   priority_queue<long long, vector<long long>, greater<long long>> que; n   for (int i = 0; i < n; i++) { n     scanf( %d , &a[i]); n     que.push(a[i]); n   } n   if (n == 1) { n     cout << 0 << endl; n   } else { n     if (n % 2 == 0) que.push(0); n     long long ans = 0; n     long long sum = 0; n     while (que.size() > 2) { n       sum = que.top(); n       que.pop(); n       sum += que.top(); n       que.pop(); n       sum += que.top(); n       que.pop(); n       ans += sum; n       que.push(sum); n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a[3], b[3]; n   for (int i = 0; i < 3; i++) cin >> a[i] >> b[i]; n   bool flag = false; n   for (int i = 0; i < 2; i++) { n     for (int j = 0; j < 2; j++) { n       for (int p = 0; p < 2; p++) { n         if (max(a[1], a[2]) <= a[0] && b[1] + b[2] <= b[0]) flag = true; n         swap(a[0], b[0]); n       } n       swap(a[2], b[2]); n     } n     swap(a[1], b[1]); n   } n   if (flag) n     cout <<  YES ; n   else n     cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N, K; n void rip() { n   puts( -1 ); n   exit(0); n } n int main() { n   scanf( %d %d , &N, &K); n   if (K == 1) { n     rip(); n   } else if (K == 2) { n     if (N <= 4) n       rip(); n     else { n       printf( %d n , N - 1); n       for (int i = (1); i < (N); i++) printf( %d %d n , i, i + 1); n     } n   } else if (K == 3) { n     if (N <= 3) n       rip(); n     else { n       printf( %d n , N - 1); n       printf( 1 2 n2 3 n ); n       for (int i = (4); i < (N + 1); i++) printf( %d %d n , 3, i); n     } n   } else n     rip(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int k, l, i = 0, mod = 0; n   cin >> k; n   cin >> l; n   while (l > 1) { n     mod += l % k; n     l = l / k; n     i++; n   } n   if (mod > 0) n     cout <<  NO ; n   else n     cout <<  YES  << endl << i - 1; n   return 0; n } n


#include <bits/stdc++.h> n using std::abs; n using std::bitset; n using std::cerr; n using std::cin; n using std::cout; n using std::deque; n using std::map; n using std::max; n using std::min; n using std::pair; n using std::queue; n using std::set; n using std::sort; n using std::string; n using std::swap; n using std::unordered_map; n using std::unordered_set; n using std::vector; n void init() { n   std::iostream::sync_with_stdio(0); n   cout << std::fixed; n   cout.precision(10); n   cerr << std::fixed; n   cerr.precision(10); n   srand(time(0)); n } n const int MAXN = 1e6 + 1; n long long arr[MAXN]; n long long dp[MAXN][3]; n int n; n long long a, b; n const long long INF = 1e18; n vector<int> fact(int x) { n   vector<int> res; n   int k = x; n   for (int i = 2; i * i <= k; ++i) n     if (!(x % i)) { n       x /= i; n       res.push_back(i); n     } n   if (x > 1) res.push_back(x); n   return res; n } n long long solve(int p) { n   for (int i = 0; i <= n; ++i) n     for (int j = 0; j < 3; ++j) dp[i][j] = INF; n   for (int i = 0; i < 3; ++i) dp[0][i] = 0; n   for (int i = 1; i <= n; ++i) { n     dp[i][1] = min(dp[i - 1][0], dp[i - 1][1]) + a; n     if (arr[i] % p == 0) { n       dp[i][0] = dp[i - 1][0]; n       dp[i][2] = min(dp[i - 1][2], dp[i - 1][1]); n     } else if ((arr[i] + 1) % p == 0 || (arr[i] - 1) % p == 0) { n       dp[i][0] = dp[i - 1][0] + b; n       dp[i][2] = min(dp[i - 1][2], dp[i - 1][1]) + b; n     } n   } n   long long ans = INF; n   for (int i = 0; i < 3; ++i) ans = min(ans, dp[n][i]); n   return ans; n } n int main() { n   init(); n   cin >> n >> a >> b; n   for (int i = 1; i <= n; ++i) cin >> arr[i]; n   set<int> ma; n   for (int i = -1; i <= 1; ++i) { n     vector<int> tmp; n     tmp = fact(arr[1] + i); n     for (auto j : tmp) ma.insert(j); n     tmp = fact(arr[n] + i); n     for (auto j : tmp) ma.insert(j); n   } n   long long ans = INF; n   for (auto i : ma) ans = min(ans, solve(i)); n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void imprimirVector(vector<long long> v) { n   if (!v.empty()) { n     int p = v.size(); n     cout <<  [ ; n     for (int i = 0; i < (int)(p - 1); i++) cout << v[i] <<  , ; n     cout << v[p - 1] <<  ]  << endl; n   } else n     cout <<  []  << endl; n } n long long toNumber(string s) { n   long long Number; n   if (!(istringstream(s) >> Number)) Number = 0; n   return Number; n } n string toString(long long number) { n   ostringstream ostr; n   ostr << number; n   return ostr.str(); n } n int main() { n   ios_base::sync_with_stdio(0); n   unsigned long long n; n   cin >> n; n   cout << (n * (n - 1) * (n - 2) * (n - 3) * (n - 4) / 120) * n * (n - 1) * n               (n - 2) * (n - 3) * (n - 4) n        << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<string, long long> mp; n int main() { n   int n; n   cin >> n; n   mp.clear(); n   for (int i = 1; i <= n; ++i) { n     string tmp; n     cin >> tmp; n     mp[tmp]++; n   } n   cout << (mp[ UL ] + mp[ DR ] + mp[ ULDR ] + 1) * n               (mp[ UR ] + mp[ DL ] + mp[ ULDR ] + 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool isprime(int n) { n   if (n == 1) return false; n   if (n == 2) return true; n   for (int i = 2; i <= sqrt(n); i++) { n     if (n % i == 0) { n       return false; n     } n   } n   return true; n } n void answer(int f) { n   if (f) { n     cout <<  YES ; n   } else { n     cout <<  NO ; n   } n   cout << endl; n } n long long int countSetBits(long long int n) { n   long long int count = 0; n   while (n) { n     count += 1; n     n = n / 10; n   } n   return count; n } n long long int factorial(long long int n) { n   n = n % 1000000007; n   return (n == 1 || n == 0 || n < 0) ? 1 : n * factorial(n - 1); n } n long long int ncp(long long int n, long long int p) { n   long long int a = factorial(n); n   long long int b = factorial(p); n   long long int c = factorial(n - p); n   return (a / (b * c)); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   ; n   int t = 1; n   while (t--) { n     long long int n, m; n     cin >> n; n     long long int i, c[n]; n     vector<long long int> a, b; n     long long int sum1 = 0, sum2 = 0; n     for (i = 0; i < n; i++) { n       cin >> c[i]; n       if (c[i] > 0) { n         sum1 += c[i]; n         a.push_back(c[i]); n       } else { n         long long int df = abs(c[i]); n         sum2 += df; n         b.push_back(df); n       } n     } n     if (sum1 > sum2) { n       cout <<  first ; n       return 0; n     } else if (sum1 < sum2) { n       cout <<  second ; n       return 0; n     } n     i = 0; n     int x = min(a.size(), b.size()); n     while (i < x) { n       if (a[i] < b[i]) { n         cout <<  second ; n         return 0; n       } else if (a[i] > b[i]) { n         cout <<  first ; n         return 0; n       } n       i++; n     } n     if (c[n - 1] < 0) n       cout <<  second ; n     else n       cout <<  first ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, ans[1010], foo[1010]; n int t, l, r; n pair<pair<int, int>, int> ranges[1010]; n int main() { n   memset(foo, -1, sizeof(foo)); n   scanf( %d%d , &n, &m); n   for (int i = 0; i < m; ++i) { n     scanf( %d%d%d , &t, &l, &r); n     ranges[i] = make_pair(pair<int, int>(l, r), t); n     if (t == 1) { n       for (int j = l; j < r; ++j) foo[j] = 0; n     } n   } n   bool can = true; n   ans[1] = 10000000; n   for (int i = 0; i < m && can; ++i) { n     if (ranges[i].second == 1) { n       for (int j = ranges[i].first.first; j < ranges[i].first.second && can; n            ++j) { n         if (foo[j] != 0) can = false; n       } n     } else { n       int cnt = 0; n       for (int j = ranges[i].first.first; j < ranges[i].first.second && can; n            ++j) { n         if (foo[j] < 0) { n           cnt++; n           break; n         } n       } n       if (cnt == 0) can = false; n     } n   } n   if (!can) { n     puts( NO ); n   } else { n     puts( YES ); n     printf( %d , ans[1]); n     for (int i = 2; i <= n; ++i) { n       ans[i] = ans[i - 1] + foo[i - 1]; n       printf(  %d , ans[i]); n     } n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char s[110000]; n char res[110000]; n int main() { n   scanf( %s , s); n   int resLen = 0; n   int last = 0; n   int index = 0; n   for (int i = 0; i < 110000; i++) res[i] = 0; n   for (char c =  z ; c >=  a ; c--) n     for (int i = index; s[i]; i++) n       if (s[i] == c) { n         res[resLen] = c; n         resLen++; n         index = i + 1; n       } n   printf( %s n , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a[110][110]; n   int n, i, j; n   long long s = 0; n   cin >> n; n   if (n == 1) { n     cin >> i; n     cout << i; n     return 0; n   } n   for (i = 0; i < n; ++i) n     for (j = 0; j < n; ++j) { n       cin >> a[i][j]; n       if (i == j) s += a[i][j]; n       if (i + j == n - 1) s += a[i][j]; n       if (i == (n - 1) / 2 || j == (n - 1) / 2) s += a[i][j]; n     } n   cout << s - 2 * a[(n - 1) / 2][(n - 1) / 2]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, k; n   cin >> n >> k; n   vector<pair<long double, long double>> v; n   for (long long int i = 0; i < n; i++) { n     long double x, y; n     cin >> x >> y; n     v.push_back(make_pair(x, y)); n   } n   long double sum = 0; n   for (long long int i = 1; i < v.size(); i++) { n     long double x1 = v[i - 1].first, y1 = v[i - 1].second, x2 = v[i].first, n                 y2 = v[i].second; n     long double dis = sqrt(((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1))); n     sum = sum + dis; n   } n   long double ans = ((1.0 / 50.0) * sum) * k; n   printf( %0.9Lf n , ans); n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx ) n using namespace std; n const int MAXN = 1e3 + 3; n int n; n bool dp[MAXN][10]; n string s; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> s; n   n = (int)s.length(); n   string kek =  heidi ; n   memset(dp, 0, sizeof(dp)); n   for (auto i = 0; i != n; i++) { n     for (auto j = 0; j != 5; j++) { n       if (s[i] != kek[j]) continue; n       if (j > 0) { n         bool good = false; n         for (auto k = 0; k != i; k++) n           if (dp[k][j - 1]) { n             good = true; n             break; n           } n         if (!good) continue; n       } n       dp[i][j] = true; n     } n   } n   for (auto i = 0; i != n; i++) n     if (dp[i][4]) { n       cout <<  YES ; n       return 0; n     } n   cout <<  NO ; n   return 0; n } n


//begin #include <Core> n /* n  * Package: StandardCodeLibrary.Core n  * */ n #include <iostream> n #include <fstream> n #include <sstream> n #include <iomanip> n #include <utility> n #include <vector> n #include <list> n #include <string> n #include <stack> n #include <queue> n #include <deque> n #include <set> n #include <map> n #include <algorithm> n #include <functional> n #include <numeric> n #include <bitset> n #include <complex> n #include <cstdio> n #include <cstring> n #include <cmath> n #include <cstdlib> n #include <ctime> n #include <climits> n #if __GNUC__>=4 and __GNUC_MINOR__>=6 n #include <ext/pb_ds/assoc_container.hpp> n #include <ext/pb_ds/tree_policy.hpp> n #include <ext/pb_ds/tag_and_trait.hpp> n #endif n using namespace std; n  n #define lp for(;;) n #define repf(i,a,b) for (int i=(a);i<(b);++i) n #define rep(i,n) repf(i,0,n) n #define ft(i,a,b) for (int i=(a);i<=(b);++i) n #define fdt(i,a,b) for (int i=(a);i>=b;--i) n #define feach(e,s) for (typeof((s).begin()) e=(s).begin();e!=(s).end();++e) n #define fsubset(subset,set) for (int subset=(set)&((set)-1);subset;subset=(subset-1)&(set)) n #define forin(i,charset) for (cstr i=(charset);*i;i++) n #define whl while n #define rtn return n #define fl(x,y) memset((x),char(y),sizeof(x)) n #define clr(x) fl(x,char(0)) n #define cpy(x,y) memcpy(x,y,sizeof(x)) n #define pb push_back n #define mp make_pair n #define ins insert n #define ers erase n #define lb lower_bound n #define ub upper_bound n #define rnk order_of_key n #define sel find_by_order n #define x first n #define y second n #define sz(x) (int((x).size())) n #define all(x) (x).begin(),(x).end() n #define srt(x) sort(all(x)) n #define uniq(x) srt(x),(x).erase(unique(all(x)),(x).end()) n #define vec vector n #define pr pair n #define que queue n #define prq priority_queue n #define itr iterator n #define sf scanf n #define pf printf n #define pdb(prcs,x) (cout<<setprecision(prcs)<<fixed<<(sgn(x)?(x):0)) n #ifdef DEBUG n #define prt(x) cerr<<#x = <<(x)<<endl n #define asrtWA(s) do if(!(s))do{cerr<< assert( #s ) <<endl;}whl(0);whl(0) n #define asrtTLE(s) do if(!(s))do{cerr<< assert( #s ) <<endl;}whl(0);whl(0) n #define asrtMLE(s) do if(!(s))do{cerr<< assert( #s ) <<endl;}whl(0);whl(0) n #define asrtOLE(s) do if(!(s))do{cerr<< assert( #s ) <<endl;}whl(0);whl(0) n #define asrtRE(s) do if(!(s))do{cerr<< assert( #s ) <<endl;}whl(0);whl(0) n #define runtime() cerr<< Used:  <<db(clock())/CLOCKS_PER_SEC<< s <<endl n #define input(in) do{}whl(0) n #define output(out) do{}whl(0) n #else n #define endl (char(  n )) n #define prt(x) (cerr) n #define asrtWA(s) do if(!(s))exit(0);whl(0) n #define asrtTLE(s) do if(!(s))whl(1);whl(0) n #define asrtMLE(s) do if(!(s))whl(new int);whl(0) n #define asrtOLE(s) do if(!(s))whl(1)puts( OLE );whl(0) n #define asrtRE(s) do if(!(s))*(int*)0=0;whl(0) n #define runtime() (cerr) n #define input(in) freopen(in, r ,stdin) n #define output(out) freopen(out, w ,stdout) n #endif n  n typedef long long int lli; n typedef double db; n typedef const char* cstr; n typedef string str; n typedef vec<int> vi; n typedef vec<vi> vvi; n typedef vec<bool> vb; n typedef vec<vb> vvb; n typedef vec<str> vs; n typedef pr<int,int> pii; n typedef pr<lli,lli> pll; n typedef pr<db,db> pdd; n typedef pr<str,int> psi; n typedef map<int,int> mii; n typedef map<str,int> msi; n typedef map<char,int> mci; n typedef set<int> si; n typedef set<str> ss; n typedef que<int> qi; n typedef prq<int> pqi; n #if __GNUC__>=4 and __GNUC_MINOR__>=7 n template<typename key,typename value>class ext_map:public __gnu_pbds::tree<key,value,less<key>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>{}; n template<typename key>class ext_set:public __gnu_pbds::tree<key,__gnu_pbds::null_type,less<key>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>{}; n #elif __GNUC__>=4 and __GNUC_MINOR__>=6 n template<typename key,typename value>class ext_map:public __gnu_pbds::tree<key,value,less<key>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>{}; n template<typename key>class ext_set:public __gnu_pbds::tree<key,__gnu_pbds::null_mapped_type,less<key>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>{}; n #endif n  n const int oo=(~0u)>>1; n const lli ooll=(~0ull)>>1; n const db inf=1e+10; n const db eps=1e-10; n const db pi=acos(-1.0); n const int MOD=1000000007; n  n template<typename type>inline bool cmax(type& a,const type& b){rtn a<b?a=b,true:false;} n template<typename type>inline bool cmin(type& a,const type& b){rtn b<a?a=b,true:false;} n template<typename type>inline type sqr(const type& x){rtn x*x;} n inline int dbcmp(const db& a,const db& b){rtn (a>b+eps)-(a<b-eps);} n inline int sgn(const db& x){rtn dbcmp(x,0);} n template<typename ostream,typename type>ostream& operator<<(ostream& cout,const pr<type,type>& x){rtn cout<< ( <<x.x<< , <<x.y<< ) ;} n template<typename type>pr<type,type> operator-(const pr<type,type>& x){rtn mp(-x.x,-x.y);} n template<typename type>pr<type,type> operator+(const pr<type,type>& a,const pr<type,type>& b){rtn mp(a.x+b.x,a.y+b.y);} n template<typename type>pr<type,type> operator-(const pr<type,type>& a,const pr<type,type>& b){rtn mp(a.x-b.x,a.y-b.y);} n template<typename type>inline type cross(const pr<type,type>& a,const pr<type,type>& b,const pr<type,type>& c){rtn (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);} n template<typename type>inline type dot(const pr<type,type>& a,const pr<type,type>& b,const pr<type,type>& c){rtn (b.x-a.x)*(c.x-a.x)+(b.y-a.y)*(c.y-a.y);} n template<typename type>inline type gcd(type a,type b){if(b)whl((a%=b)&&(b%=a));rtn a+b;} n template<typename type>inline type lcm(type a,type b){rtn a*b/gcd(a,b);} n template<typename type>inline void bit_inc(vec<type>& st,int x,type inc){whl(x<sz(st))st[x]+=inc,x|=x+1;} n template<typename type>inline type bit_sum(const vec<type>& st,int x){type s=0;whl(x>=0)s+=st[x],x=(x&(x+1))-1;rtn s;} n template<typename type>inline type bit_kth(const vec<type>& st,int k){int x=0,y=0,z=0;whl((1<<(++y))<=sz(st));fdt(i,y-1,0){if((x+=1<<i)>sz(st)||z+st[x-1]>k)x-=1<<i;else z+=st[x-1];}rtn x;} n inline void make_set(vi& st){rep(i,sz(st))st[i]=i;} n inline int find_set(vi& st,int x){int y=x,z;whl(y!=st[y])y=st[y];whl(x!=st[x])z=st[x],st[x]=y,x=z;rtn y;} n inline bool union_set(vi& st,int a,int b){a=find_set(st,a),b=find_set(st,b);rtn a!=b?st[a]=b,true:false;} n template<typename type>inline void merge(type& a,type& b){if(sz(a)<sz(b))swap(a,b);whl(sz(b))a.insert(*b.begin()),b.erase(b.begin());} n template<typename type>inline void merge(prq<type>& a,prq<type>& b){if(sz(a)<sz(b))swap(a,b);whl(sz(b))a.push(b.top()),b.pop();} n  n struct Initializer{Initializer(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}~Initializer(){runtime();}}initializer; n //end #include <Core> n  n int main() n { n  int n,m; n  cin>>n>>m; n  vi u(m),v(m); n  vec<db> c(m); n  rep(i,m) cin>>u[i]>>v[i]>>c[i],--u[i],--v[i]; n  vec<vec<db > > matrix(n,vec<db >(n+1)); n  vi st(n); n  make_set(st); n  rep(i,m) n  { n   if (u[i]!=0&&u[i]!=n-1) matrix[u[i]][u[i]]+=1,matrix[u[i]][v[i]]-=1; n   if (v[i]!=0&&v[i]!=n-1) matrix[v[i]][v[i]]+=1,matrix[v[i]][u[i]]-=1; n   union_set(st,u[i],v[i]); n  } n  matrix[0][0]=1; n  rep(i,n) n  { n   repf(j,i,n) if (abs(matrix[j][i])>abs(matrix[i][i])) swap(matrix[i],matrix[j]); n   if (sgn(matrix[i][i])) n    repf(j,i+1,n) n    { n     db times=matrix[j][i]/matrix[i][i]; n     ft(k,i,n) matrix[j][k]-=matrix[i][k]*times; n    } n  } n  vec<db > x(n); n  fdt(i,n-1,0) n  { n   if (sgn(matrix[i][i])) n   { n    x[i]=matrix[i][n]; n    repf(j,i+1,n) x[i]-=matrix[i][j]*x[j]; n    x[i]/=matrix[i][i]; n   } n   else if (find_set(st,i)==find_set(st,0)) x[i]=inf; n  } n  db times=-inf; n  rep(i,m) cmax(times,abs(x[u[i]]-x[v[i]])/c[i]); n  rep(i,n) x[i]/=times; n  db ans=0; n  rep(i,m) n  { n   if (u[i]==0) ans+=x[v[i]]; n   if (v[i]==0) ans+=x[u[i]]; n  } n  pdb(10,ans)<<endl; n  rep(i,m) pdb(10,x[v[i]]-x[u[i]])<<endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long get() { n   long long x = 0; n   char s = getchar(); n   while (s <  0  || s >  9 ) s = getchar(); n   while (s >=  0  && s <=  9 ) n     x = (x << 3) + (x << 1) + (s ^ 48), s = getchar(); n   return x; n } n long long Max(const long long x, const long long y) { n   if (x > y) return x; n   return y; n } n long long pow2(const long long x) { return x * x; } n const long long M = 3e5 + 5, INF = 2e18; n long long n, a, d[M], c[M], f[M]; n struct node { n   long long d, mxf, mxans; n   node() {} n   node(const long long D, const long long MXF, const long long MXANS) { n     d = D, mxf = MXF, mxans = MXANS; n   } n }; n stack<node> s; n signed main() { n   n = get(), a = get(); n   for (long long i = 1; i <= n; ++i) n     d[i] = get(), c[i] = c[i - 1] + get(), f[i] = a * i - c[i]; n   long long ans = Max(0, a - (c[n] - c[n - 1])); n   s.push(node(0, f[n], f[n])); n   long long mxf_pre; n   for (long long l = n - 1; l; --l) { n     mxf_pre = -INF; n     while (!s.empty() && s.top().d <= d[l + 1] - d[l]) { n       mxf_pre = Max(mxf_pre, s.top().mxf); n       s.pop(); n     } n     if (mxf_pre != -INF && !s.empty()) n       s.push(node(d[l + 1] - d[l], mxf_pre, n                   Max(mxf_pre - pow2(d[l + 1] - d[l]), s.top().mxans))); n     else n       s.push(node(d[l + 1] - d[l], mxf_pre, n                   Max(mxf_pre - pow2(d[l + 1] - d[l]), -INF))); n     if (!s.empty()) n       s.push(node(0, f[l], Max(f[l], s.top().mxans))); n     else n       s.push(node(0, f[l], Max(f[l], -INF))); n     if (!s.empty()) n       ans = Max(ans, s.top().mxans - f[l - 1]); n     else n       ans = Max(ans, -INF); n   } n   printf( %lld , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 3e5 + 100; n long long n, x, y; n int a[maxn]; n vector<long long> v[maxn]; n int vis[maxn]; n int flag; n void dfs(int u) { n   int i, j; n   vis[u] = 1; n   if (u == y) { n     flag = 1; n     return; n   } n   for (i = 0; i < v[u].size(); i++) { n     int k = v[u][i]; n     if (vis[k]) continue; n     vis[k] = 1; n     if (k == y) { n       flag = 1; n       return; n     } n     dfs(k); n     if (!flag) n       vis[k] = 0; n     else n       return; n   } n } n long long cnt = 0; n void dfs2(int u) { n   int i, j; n   for (i = 0; i < v[u].size(); i++) { n     int k = v[u][i]; n     if (vis[k]) { n       continue; n     } n     vis[k] = 1; n     cnt++; n     dfs2(k); n   } n } n int main() { n   int i, j; n   cin >> n >> x >> y; n   for (i = 1; i <= n - 1; i++) { n     int l, r; n     cin >> l >> r; n     v[l].push_back(r); n     v[r].push_back(l); n   } n   if (n == 1) { n     cout << 0 << endl; n     return 0; n   } n   if (n == 2) { n     cout << 1 << endl; n     return 0; n   } n   dfs(x); n   long long ans = n * (n - 1); n   cnt = 0; n   dfs2(x); n   cnt++; n   long long x1 = cnt; n   cnt = 0; n   dfs2(y); n   cnt++; n   long long y1 = cnt; n   cout << ans - x1 * y1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n const int N = 100002; n int n, k, l[N], r[N]; n char s[N]; n bool check1() { n   if (n == k || l[n] == 1 || r[1] == n || l[n - k] == 1 || r[k + 1] == n) n     return 1; n   for (int i = 2; i <= n - k; i++) n     if (s[i - 1] == s[i + k] && l[i - 1] == 1 && r[i + k] == n) return 1; n   return 0; n } n bool check2() { n   if ((k << 1) < n) return 0; n   for (int i = 2; i <= n - k; i++) n     if (l[i - 1] != 1 || r[i + k] != n) return 0; n   return 1; n } n int main() { n   scanf( %d %d %s , &n, &k, s + 1); n   l[1] = 1; n   r[n] = n; n   for (int i = 2; i <= n; i++) l[i] = s[i] == s[i - 1] ? l[i - 1] : i; n   for (int i = n - 1; i >= 1; i--) r[i] = s[i] == s[i + 1] ? r[i + 1] : i; n   if (check1()) return !printf( tokitsukaze n ); n   if (check2()) return !printf( quailty n ); n   printf( once again n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 35050; n const int inf = 1e9; n int t[2 * N], lz[N], n, h, k; n int dp[55][N], val[N]; n pair<int, int> up[N]; n int pv[N]; n inline void carrot() { n   for (int i = int(0); i < int(n + 1); ++i) pv[i] = n; n   for (int i = int(n - 1); i >= int(0); i--) { n     up[i].first = i + 1; n     up[i].second = pv[val[i]]; n     pv[val[i]] = i + 1; n   } n } n inline void clear_trees() { n   memset(t, 0, sizeof(t)); n   memset(lz, 0, sizeof(lz)); n } n inline void build_trees(int row) { n   for (int i = int(0); i < int(n); ++i) t[i + n] = dp[row][i]; n   for (int i = int(n - 1); i >= int(1); i--) n     t[i] = max(t[i << 1], t[i << 1 | 1]); n } n inline void apply(int p, int val) { n   t[p] += val; n   if (p < n) lz[p] += val; n } n inline void build(int p) { n   while (p > 1) p >>= 1, t[p] = max(t[p << 1], t[p << 1 | 1]) + lz[p]; n } n inline void modify(int lo, int ro) { n   lo += n, ro += n; n   for (int l = lo, r = ro; l < r; l >>= 1, r >>= 1) { n     if (l & 1) apply(l++, 1); n     if (r & 1) apply(--r, 1); n   } n   build(lo); n   build(ro); n } n inline void push(int p) { n   for (int s = int(h); s >= int(1); s--) { n     int i = p >> s; n     if (lz[i] != 0) { n       apply(i << 1, lz[i]); n       apply(i << 1 | 1, lz[i]); n       lz[i] = 0; n     } n   } n } n inline int query(int l, int r) { n   push(l + n); n   push(r + n - 1); n   int res = -inf; n   for (l += n, r += n; l < r; l >>= 1, r >>= 1) { n     if (l & 1) res = max(res, t[l++]); n     if (r & 1) res = max(res, t[--r]); n   } n   return res; n } n inline int solve() { n   memset(dp, 0, sizeof(dp)); n   carrot(); n   set<int> s; n   for (int i = int(n - 1); i >= int(0); i--) { n     s.insert(val[i]); n     dp[1][i] = int(s.size()); n   } n   for (int num = int(2); num < int(k + 1); ++num) { n     clear_trees(); n     build_trees(num - 1); n     for (int i = int(n - num); i >= int(0); i--) { n       modify(up[i].first, up[i].second); n       dp[num][i] = query(i + 1, n); n     } n   } n   return dp[k][0]; n } n inline void input_random() { n   n = (rand() % 10) + 1; n   k = (rand() % n) + 1; n   for (int i = int(0); i < int(n); ++i) val[i] = (rand() % n) + 1; n } n int dp2[15][15]; n inline int brute() { n   memset(dp2, 0, sizeof(dp2)); n   for (int i = int(0); i < int(n); ++i) dp2[1][i] = dp[1][i]; n   for (int num = int(2); num < int(k + 1); ++num) { n     for (int i = int(n - num); i >= int(0); i--) { n       set<int> s; n       s.insert(val[i]); n       for (int j = int(i + 1); j < int(n); ++j) { n         if (dp[num - 1][j] == 0) continue; n         dp2[num][i] = max(dp2[num][i], dp2[num - 1][j] + int(s.size())); n         s.insert(val[j]); n       } n     } n   } n   for (int num = int(1); num < int(k + 1); ++num) { n     for (int i = int(0); i < int(n); ++i) cout << dp[num][i] <<    ; n     cout << endl; n   } n   return dp2[k][0]; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> k; n   for (int i = int(0); i < int(n); ++i) cin >> val[i]; n   h = sizeof(int) * 8 - __builtin_clz(n); n   int ans = solve(); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 300005; n int n; n int ans = 300005, pos = 1; n long long tnow, wnow; n struct node { n   long long t, w; n } a[N]; n priority_queue<long long, vector<long long>, greater<long long> > q; n bool cmp(node a, node b) { return a.t > b.t; } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %lld%lld , &a[i].t, &a[i].w); n   tnow = a[1].t; n   wnow = a[1].w; n   a[1].t = 0; n   sort(a + 1, a + 1 + n, cmp); n   while (1) { n     while (pos <= n && a[pos].t > tnow) { n       q.push(a[pos].w - a[pos].t + 1); n       pos++; n     } n     ans = min(ans, (int)q.size() + 1); n     if (!q.size() || tnow < q.top()) break; n     tnow -= q.top(); n     q.pop(); n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:102400000,102400000 ) n using namespace std; n const int inf = 2e9; n int ans[208][208]; n int n, m; n namespace MaxFlow { n struct Edge { n   int to, capacity, revid; n   Edge() : to(-1), capacity(0), revid(-1){}; n   Edge(int t, int c, int r) : to(t), capacity(c), revid(r) {} n }; n int depth[34010]; n size_t curr[34010]; n vector<Edge> g[34010]; n void buildEdge(int src, int dst, int cap) { n   g[src].push_back(Edge(dst, cap, int(g[dst].size()))); n   g[dst].push_back(Edge(src, 0, int(g[src].size()) - 1)); n } n void bfs(int src) { n   for (int i = 0; i <= 24000; i++) depth[i] = inf; n   queue<int> q; n   q.push(src); n   depth[src] = 0; n   while (!q.empty()) { n     int p = q.front(); n     q.pop(); n     for (size_t i = 0; i < g[p].size(); i++) { n       if (g[p][i].capacity == 0 || depth[g[p][i].to] <= depth[p] + 1) continue; n       q.push(g[p][i].to); n       depth[g[p][i].to] = depth[p] + 1; n     } n   } n } n int dfs(int x, int dst, int cmin) { n   if (x == dst) return cmin; n   for (size_t& i = curr[x]; i < g[x].size(); i++) { n     Edge& e = g[x][i]; n     if (e.capacity == 0 || depth[e.to] <= depth[x]) continue; n     int d = dfs(e.to, dst, min(cmin, e.capacity)); n     if (d > 0) { n       e.capacity -= d; n       int ac = x, ak = e.to; n       if (ac > n) ans[ak][ac - n] -= d; n       if (ak > n) ans[ac][ak - n] += d; n       g[e.to][e.revid].capacity += d; n       return d; n     } n   } n   return 0; n } n int solve(int src, int dst) { n   int res = 0; n   while (true) { n     bfs(src); n     if (depth[dst] == inf) return res; n     memset(curr, 0, sizeof curr); n     int d = dfs(src, dst, inf); n     while (d > 0) { n       res += d; n       d = dfs(src, dst, inf); n     } n   } n } n }  // namespace MaxFlow n int pep[108]; n int pur[108]; n int tot; n int main() { n   cin >> n >> m; n   for (int i = 1; i <= n; i++) { n     cin >> pep[i]; n     MaxFlow::buildEdge(i, n + i, inf); n     MaxFlow::buildEdge(0, i, pep[i]); n     tot += pep[i]; n   } n   int sum = 0; n   for (int i = 1; i <= n; i++) { n     cin >> pur[i]; n     sum += pur[i]; n     MaxFlow::buildEdge(i + n, 205, pur[i]); n   } n   while (m--) { n     int a, b; n     cin >> a >> b; n     MaxFlow::buildEdge(a, b + n, inf); n     MaxFlow::buildEdge(b, a + n, inf); n   } n   if (MaxFlow::solve(0, 205) != tot or tot != sum) { n     cout <<  NO ; n     return 0; n   } n   puts( YES ); n   cout <<   ; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       printf( %d  , ans[i][j]); n     } n     puts(  ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n struct s { n   long long x; n   long long y; n }; n vector<s> v; n bool cmp(s a, s b) { n   if (a.x == b.x) return a.y < b.y; n   return a.x > b.x; n } n int main() { n   long long a, b, c, d, e, i, j, k, xx, yy; n   s aa, bb; n   scanf( %lld %lld , &a, &b); n   for (i = 0; i < a; i++) { n     scanf( %lld %lld , &aa.x, &aa.y); n     v.push_back(aa); n   } n   sort(v.begin(), v.end(), cmp); n   xx = v[b - 1].x; n   yy = v[b - 1].y; n   long long count = 0; n   for (i = 0; i < a; i++) { n     if (xx == v[i].x && yy == v[i].y) { n       count++; n     } n   } n   cout << count << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int c1, c2, c3, c4, n, m; n const int maxn = 1050; n int a[maxn], b[maxn]; n int p, q, r, s; n int x, y; n int main() { n   cin >> c1 >> c2 >> c3 >> c4; n   cin >> n >> m; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     x += min(c1 * a[i], c2); n   } n   for (int i = 0; i < m; i++) { n     cin >> b[i]; n     y += min(c1 * b[i], c2); n   } n   cout << min(min(x, c3) + min(y, c3), c4) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n set<pair<int, int> > s; n int t[200000]; n int n, k, q; n int main() { n   cin >> n >> k >> q; n   for (int i = 1; i <= n; ++i) scanf( %d , t + i); n   for (int i = 0; i < q; ++i) { n     int type, id; n     pair<int, int> p; n     scanf( %d %d , &type, &id); n     p = make_pair(t[id], id); n     if (type == 1) { n       s.insert(p); n       if (s.size() > k) s.erase(s.begin()); n     } else if (type == 2) { n       if (s.count(p)) n         printf( YES n ); n       else n         printf( NO n ); n     } else { n       assert(0); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int dd = (int)1e5 + 7; n int A[dd], k[dd], j[dd], G[dd]; n int main() { n   int n, m; n   scanf( %d %d , &n, &m); n   for (int i = 0; i < n; ++i) { n     int l, r; n     scanf( %d %d , &l, &r); n     G[l - 1]++, G[r]--; n   } n   int F = 0; n   for (int i = 0; i < m; ++i) A[i] = (F += G[i]); n   vector<int> Y; n   for (int i = 0; i < m; ++i) { n     auto I = upper_bound(Y.begin(), Y.end(), A[i]); n     k[i] = I - Y.begin() + 1; n     if (I == Y.end()) n       Y.push_back(A[i]); n     else n       *I = A[i]; n   } n   Y = vector<int>(0); n   for (int i = m - 1; i >= 0; --i) { n     auto I = upper_bound(Y.begin(), Y.end(), A[i]); n     j[i] = I - Y.begin() + 1; n     if (I == Y.end()) n       Y.push_back(A[i]); n     else n       *I = A[i]; n   } n   int ans = 0; n   for (int i = 0; i < m; ++i) ans = max(ans, k[i] + j[i] - 1); n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5, M = 1e9 + 7; n int n, a[N]; n long long bigmod(long long b, long long p) { n   long long t = 1; n   for (; p; b = (b * b) % M, p >>= 1) n     if (p & 1) t = (t * b) % M; n   return t; n } n long long go(int now) { n   vector<int> div; n   for (int i = 1; i * i <= now; i++) { n     if (now % i == 0) { n       div.push_back(i); n       if (i * i != now) div.push_back(now / i); n     } n   } n   div.push_back(N); n   sort(div.begin(), div.end()); n   long long last = 1, cur = 1; n   for (int i = 0; i < div.size() - 1; i++) { n     int x = lower_bound(a, a + n, div[i]) - a; n     int y = lower_bound(a, a + n, div[i + 1]) - a; n     long long tmp = bigmod(i + 1, y - x); n     cur *= tmp; n     cur %= M; n   } n   int sz = div.size() - 2; n   div[sz] = N; n   for (int i = 0; i < div.size() - 2; i++) { n     int x = lower_bound(a, a + n, div[i]) - a; n     int y = lower_bound(a, a + n, div[i + 1]) - a; n     long long tmp = bigmod(i + 1, y - x); n     last *= tmp; n     last %= M; n   } n   return (cur - last + M) % M; n } n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i]; n   sort(a, a + n); n   long long ans = 1; n   for (int i = 1; i < N; i++) { n     ans += go(i); n     ans %= M; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n const int MX = 1e5 + 23; n const long long MOD = 998244353; n int read() { n   char k = getchar(); n   int x = 0; n   while (k <  0  || k >  9 ) k = getchar(); n   while (k >=  0  && k <=  9 ) x = x * 10 + k -  0 , k = getchar(); n   return x; n } n struct node { n   int l, r; n   int sum, mx; n   node *lch, *rch; n } * root; n void pushup(node *x) { n   x->sum = x->lch->sum + x->rch->sum; n   x->mx = std::max(x->lch->mx + x->rch->sum, x->rch->mx); n } n node *build(int l, int r) { n   node *x = new node; n   x->l = l, x->r = r; n   if (l == r) { n     x->sum = x->mx = 0; n     x->lch = x->rch = nullptr; n   } else { n     int mid = (l + r) >> 1; n     x->lch = build(l, mid); n     x->rch = build(mid + 1, r); n     pushup(x); n   } n   return x; n } n void add(node *x, int p, int v) { n   if (x->l == x->r) { n     x->sum += v; n     x->mx += v; n     return; n   } n   if (p <= x->lch->r) n     add(x->lch, p, v); n   else n     add(x->rch, p, v); n   pushup(x); n } n int query(node *x, int ex) { n   if (x->l == x->r) return x->l; n   if (x->rch->mx + ex >= 1) return query(x->rch, ex); n   return query(x->lch, ex + x->rch->sum); n } n int m, w[MX]; n int main() { n   root = build(1, 100000 + 233); n   m = read(); n   for (int i = 1, type, x, v; i <= m; ++i) { n     x = read(), type = read(); n     if (type == 0) { n       add(root, x, -1); n     } else { n       v = read(); n       w[x] = v; n       add(root, x, 1); n     } n     if (root->mx <= 0) { n       puts( -1 ); n     } else { n       printf( %d n , w[query(root, 0)]); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n long long x, y; n vector<pair<pair<long long, long long>, int> > p; n long long dx, dy; n bool dot(long long x, long long y) { n   long long x1 = x - p[0].first.first; n   long long x2 = x - p[1].first.first; n   long long y1 = y - p[0].first.second; n   long long y2 = y - p[1].first.second; n   return x1 * y2 - y1 * x2; n   return true; n } n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %I64d%I64d , &x, &y); n     p.push_back(make_pair(make_pair(x, y), i + 1)); n   } n   sort(p.begin(), p.end()); n   dx = p[0].first.first - p[1].first.first; n   dy = p[0].first.second - p[1].first.second; n   for (int i = 2; i < n; i++) { n     if (dot(p[i].first.first, p[i].first.second)) { n       printf( %d %d %d n , p[0].second, p[1].second, p[i].second); n       return 0; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n string a[55]; n long long f[(1LL << (21))]; n double fac[55]; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i]; n   int l = a[0].size(); n   fac[0] = 1; n   for (int i = 1; i <= l; i++) fac[i] = fac[i - 1] * i; n   for (int i = 0; i < n; i++) { n     for (int j = i + 1; j < n; j++) { n       int s = 0; n       for (int k = 0; k < l; k++) n         if (a[i][k] == a[j][k]) s |= (1LL << (k)); n       f[s] |= (1LL << (i)) | (1LL << (j)); n     } n   } n   double res = 0; n   for (int s = (1LL << (l)) - 1; s >= 0; s--) { n     for (int k = 0; k < l; k++) n       if (s >> k & 1) f[s ^ (1LL << (k))] |= f[s]; n   } n   for (int s = 0; s < (1LL << (l)); s++) { n     int nturn = __builtin_popcount(s); n     for (int k = 0; k < l; k++) n       if (s >> k & 1) { n         int nreveal = 0; n         long long x = f[s] ^ f[s ^ (1LL << (k))]; n         while (x) { n           x -= x & (-x); n           nreveal++; n         } n         res += (fac[nturn - 1] / fac[l] * fac[l - nturn]) * nturn * nreveal / n; n       } n   } n   printf( %.15lf , res); n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n const int N = 2 * 1e5 + 10; n ll res; n ll a[N]; n void solve() { n   ll t, x, y, ex, ey, neast = 0, nnorth = 0, nsouth = 0, nwest = 0; n   map<char, int> mp; n   cin >> t >> x >> y >> ex >> ey; n   ll k = ex - x; n   ll l = ey - y; n   string s; n   cin >> s; n   if (k > 0) { n     neast = k; n   } else { n     nwest = abs(k); n   } n   if (l > 0) { n     nnorth = l; n   } else { n     nsouth = abs(l); n   } n   for (int i = 0; i < s.size(); i++) { n     if (s[i] ==  N  and nnorth > 0) { n       nnorth--; n     } n     if (s[i] ==  E  and neast > 0) { n       neast--; n     } n     if (s[i] ==  S  and nsouth > 0) { n       nsouth--; n     } n     if (s[i] ==  W  and nwest > 0) { n       nwest--; n     } n     if (nnorth == 0 and nsouth == 0 and neast == 0 and nwest == 0) { n       cout << i + 1; n       return; n     } n   } n   cout << -1; n } n int main(int argc, char const *argv[]) { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   ll t = 1; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MN = 1000 * 100 + 100; n int arr[MN], n, s_l, s_r; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n     s_r += arr[i]; n   } n   s_r -= arr[0]; n   s_l = arr[0]; n   int cnt = 0; n   for (int i = 1; i < n; i++) { n     if (s_l == s_r) cnt++; n     s_r -= arr[i]; n     s_l += arr[i]; n   } n   cout << cnt; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = int64_t; n using ii = pair<ll, ll>; n int main() { n   cin.tie(nullptr); n   cout.tie(nullptr); n   ios::sync_with_stdio(false); n   ll n, m; n   cin >> n >> m; n   ll nn = n - 2; n   ll n1 = nn / 2; n   ll n2 = nn - n1; n   ll sm = (n1 + 1) * n1 / 2 + (n2 + 1) * n2 / 2; n   if (m == 0) { n     ll fff = ll(1e9) - 5050 * 5050; n     for (int i = (0); i < (n); i++) { n       cout << fff + i * 5050 <<    ; n     } n     cout << endl; n     return 0; n   } n   if (sm >= m) { n     if (m == 1) { n       cout << 1 <<     << 2 <<     << 3 <<    ; n       n -= 3; n       ll fff = ll(1e9) - 5050 * 5050; n       for (int i = (0); i < (n); i++) { n         cout << fff + i * 5050 <<    ; n       } n       cout << endl; n       return 0; n     } n     ll f1 = 1, f2 = 1; n     sm = 0; n     for (int i = (0); i < (n - 2); i++) { n       if (sm + f1 >= m) { n         f2 = i - 1; n         break; n       } n       sm += f1; n       if (i % 2 == 1) f1++; n     } n     ll last; n     ll ff1 = f1 - (m - sm); n     if (f2 % 2 == 0) { n       last = 2 * ff1 + 1; n     } else { n       last = 2 * ff1; n       if (ff1 == 0) last = 1; n     } n     cout << 1 <<     << 2 <<    ; n     for (int i = (0); i < (f2 + 1); i++) { n       cout << i + 3 <<    ; n       if (i == f2) { n         cout << i + 3 + last <<    ; n       } n     } n     ll kk = f2 + 4; n     kk = n - kk; n     ll fff = ll(1e9) - 5050 * 5050; n     for (int i = (0); i < (kk); i++) { n       cout << fff + i * 5050 <<    ; n     } n     cout << endl; n   } else { n     cout << -1 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int n, i, j, g, k, a[3]; n   while (~scanf( %d , &n)) { n     for (i = 0, k = 0; i < n; i++) { n       for (j = 0, g = 0; j < 3; j++) { n         scanf( %d , &a[j]); n         if (a[j] == 1) { n           g++; n         } n       } n       if (g >= 2) { n         k++; n       } n     } n     printf( %d n , k); n   } n   return 0; n } n


#include <bits/stdc++.h> n const int MAX_N = 500000; n const int MAX_M = 500000; n const int MOD = 998244353; n int l[MAX_M], r[MAX_M], val[MAX_M]; n int smen[1 + MAX_N + 1], left[1 + MAX_N], dp[1 + MAX_N], _sp[1 + 1 + MAX_N], n     *sp = _sp + 1; n int solve(int n, int m, int bit) { n   int last = 0, p = 0; n   for (int i = 1; i <= n; ++i) { n     smen[i] = 0; n     left[i] = 0; n   } n   smen[n + 1] = left[n + 1] = 0; n   for (int i = 0; i < m; ++i) n     if ((1 << bit) & val[i]) { n       smen[l[i]]++; n       smen[r[i] + 1]--; n     } else n       left[r[i] + 1] = std::max(left[r[i] + 1], l[i]); n   sp[0] = 1; n   dp[0] = 1; n   for (int i = 1; i <= n + 1; ++i) { n     p += smen[i]; n     last = std::max(last, left[i]); n     if (p == 0) { n       dp[i] = (sp[i - 1] + MOD - sp[last - 1]) % MOD; n     } else n       dp[i] = 0; n     sp[i] = (sp[i - 1] + dp[i]) % MOD; n   } n   return dp[n + 1]; n } n int main() { n   int n, k, m; n   scanf( %d%d%d , &n, &k, &m); n   for (int i = 0; i < m; ++i) scanf( %d%d%d , &l[i], &r[i], &val[i]); n   int res = 1; n   for (int i = 0; i < k; ++i) res = (long long)res * solve(n, m, i) % MOD; n   printf( %d , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int d[3 * 1000001], v1[3 * 1000001], v2[3 * 1000001], a[1000001], i, n, tt, tt2, n     kq; n void BFS1(int s, int k) { n   queue<int> q; n   if (v1[s] == 0) { n     q.push(s); n     v1[s] = k; n   } n   while (q.size() > 0) { n     int u = q.front(); n     q.pop(); n     for (int i = 0; i <= 21; i++) n       if ((u >> i) & 1) { n         int v = u - (1 << i); n         if (v1[v] == 0) { n           q.push(v); n           v1[v] = k; n         } n       } n   } n } n void BFS2(int s, int k) { n   queue<int> q; n   if (v2[s] > 0) return; n   if (d[s] == 0 || d[s] > k) { n     q.push(s); n     if (d[s] == 0) n       d[s] = k; n     else n       v2[s] = k; n   } n   while (q.size() > 0) { n     int u = q.front(); n     q.pop(); n     for (int i = 0; i <= 21; i++) n       if ((u >> i) & 1) { n         int v = u - (1 << i); n         if (v2[v] > 0) continue; n         if (d[v] == 0 || d[v] > k) { n           q.push(v); n           if (d[v] == 0) n             d[v] = k; n           else n             v2[v] = k; n         } n       } n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   for (i = 1; i <= n; i++) cin >> a[i]; n   for (i = 1; i <= n; i++) BFS1(a[i], i); n   for (i = n; i >= 1; i--) BFS2(a[i], i); n   for (tt = 0; tt <= 2000000; tt++) { n     tt2 = 0; n     if (v2[tt] == 0) continue; n     for (i = 21; i >= 0; i--) { n       if ((tt >> i) & 1) continue; n       if (v1[tt2 | (1 << i)] < v2[tt] && v1[tt2 | (1 << i)] > 0) n         tt2 |= (1 << i); n     } n     kq = max(kq, tt | tt2); n   } n   cout << kq; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   vector<int> ans; n   int x[n], y[n]; n   for (int i = 0; i < n; i++) { n     cin >> x[i] >> y[i]; n     x[i] += 1e8; n     y[i] += 1e8; n   } n   while (1) { n     for (int i = 0; i < n; i++) { n       if ((x[i] + y[i]) & 1) ans.push_back(i + 1); n     } n     if (ans.size() == 0 || ans.size() == n) { n       ans.clear(); n       for (int j = 0; j < n; j++) { n         int op = (x[j] + y[j]) / 2; n         x[j] = (x[j] - y[j] + (int)1e9) / 2 - 5e8; n         y[j] = op; n       } n     } else n       break; n   } n   cout << ans.size() << endl; n   for (auto x : ans) { n     cout << x <<    ; n   } n } n


#include <bits/stdc++.h> n int n; n int mat[3][6]; n int solv[6]; n int pt[6]; n int main() { n   memset(solv, 0, sizeof solv); n   memset(mat, -1, sizeof mat); n   scanf( %d , &n); n   int i, j; n   for (i = 0; i < 2; i++) n     for (j = 0; j < 5; j++) { n       scanf( %d , &mat[i][j]); n       if (mat[i][j] != -1) solv[j]++; n     } n   for (i = 2; i < n; i++) n     for (j = 0; j < 5; j++) { n       int a; n       scanf( %d , &a); n       if (a != -1) solv[j]++; n     } n   for (i = 0; i <= 31 * n; i++) { n     for (j = 0; j < 5; j++) { n       int cur = solv[j]; n       if (mat[0][j] != -1 && mat[1][j] != -1 && mat[1][j] < mat[0][j]) cur += i; n       pt[j] = 500; n       while (pt[j] < 3000 && cur * 2 <= n + i) pt[j] += 500, cur *= 2; n     } n     int sc1 = 0, sc2 = 0; n     for (j = 0; j < 5; j++) { n       if (mat[0][j] != -1) sc1 += pt[j] / 250 * (250 - mat[0][j]); n       if (mat[1][j] != -1) sc2 += pt[j] / 250 * (250 - mat[1][j]); n     } n     if (sc1 > sc2) { n       printf( %d n , i); n       return 0; n     } n   } n   printf( -1 n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = 2.0 * acos(0.0); n const double eps = 1e-9; n template <class T> n T Abs(T x) { n   return x > 0 ? x : -x; n } n template <class T> n string toString(T n) { n   ostringstream ost; n   ost << n; n   ost.flush(); n   return ost.str(); n } n template <class T> n inline T gcd(T a, T b) { n   if (a < 0) return gcd(-a, b); n   if (b < 0) return gcd(a, -b); n   return (b == 0) ? a : gcd(b, a % b); n } n template <class T> n inline T lcm(T a, T b) { n   if (a < 0) return lcm(-a, b); n   if (b < 0) return lcm(a, -b); n   return a * (b / gcd(a, b)); n } n long long bit_set(long long k, int p) { return k = (k | (1 << p)); } n long long re_set(long long k, int p) { return k = (k & ~(1 << p)); } n template <class T> n inline T sqr(T n) { n   return n * n; n } n template <class T> n T power(T n, int p) { n   if (!p) n     return 1; n   else { n     T sum = sqr(power(n, p >> 1)); n     if (p & 1) sum = n; n     return sum; n   } n } n int main() { n   long long num; n   cin >> num; n   num = (num + 1) / 3LL; n   cout << (num / 12LL) <<     << num % 12LL << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string s[105]; n int main() { n   int n, m, cnt = 0, t, tt, temp, dis = 0, ans = 0, len; n   int row = 0, rowup = 2e9, rowdn = -1, col = 0, collft = 2e9, colrt = -1; n   int rowupcol, rowdncol, collftrow, colrtrow; n   scanf( %d %d , &n, &m); n   for (int i = 0; i < n; i++) cin >> s[i]; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (s[i][j] ==  B ) { n         cnt++; n         if (i < rowup) { n           rowup = i; n           rowupcol = j; n         } n         if (rowdn < i) { n           rowdn = i; n           rowdncol = j; n         } n         if (j < collft) { n           collft = j; n           collftrow = i; n         } n         if (colrt < j) { n           colrt = j; n           colrtrow = i; n         } n       } n     } n   } n   if (!cnt) n     printf( 1 n ); n   else if (cnt == 1) n     printf( 0 n ); n   else { n     len = max(rowdn - rowup + 1, colrt - collft + 1); n     if (len > n || len > m) n       printf( -1 n ); n     else n       printf( %d n , (len * len) - cnt); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base ::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long i, j, k, n, m, ans = 0, sum = 0, a[100005] = {0}, mn = 2e9, mx = 0, n                            cnt = 1, index = 0, x, y, z, xptr, yptr, id1, id2, n                            zptr; n   string s; n   set<int> all; n   set<int>::iterator it2; n   set<pair<int, int> > seg, tem; n   set<pair<int, int> >::iterator it1, it, it3, it4; n   cin >> s; n   n = s.size(); n   for (i = 0; i < n; i++) { n     all.insert(i); n     if (i + 1 == n || s[i] != s[i + 1]) { n       seg.insert(make_pair(index, cnt)); n       tem.insert(make_pair(index, index + cnt - 1)); n       cnt = 1; n       index = i + 1; n     } else { n       cnt++; n     } n   } n   while (seg.size() > 1) { n     ans++; n     vector<pair<int, int> > v; n     for (it = seg.begin(); it != seg.end(); it++) { n       x = it->first; n       y = it->second; n       it1 = it; n       it1++; n       if (it == seg.begin()) { n         if (y > 1) { n           v.push_back(make_pair(x, y - 1)); n         } n         it3 = tem.lower_bound(make_pair(x, -1)); n         it2 = all.upper_bound(it3->second); n         it2--; n         all.erase(it2); n         if (y == 1) { n           tem.erase(it3); n         } n       } else if (it1 == seg.end()) { n         if (y > 1) { n           v.push_back(make_pair(x, y - 1)); n         } n         it2 = all.lower_bound(x); n         all.erase(it2); n         if (y == 1) { n           it3 = tem.lower_bound(make_pair(x, -1)); n           tem.erase(it3); n         } n       } else { n         it2 = all.lower_bound(x); n         all.erase(it2); n         if (y > 1) { n           it3 = tem.lower_bound(make_pair(x, -1)); n           it2 = all.upper_bound(it3->second); n           it2--; n           all.erase(it2); n           if (y > 2) { n             v.push_back(make_pair(x, y - 2)); n           } n         } n         if (y == 1 || y == 2) { n           it3 = tem.lower_bound(make_pair(x, -1)); n           tem.erase(it3); n         } n       } n     } n     seg.clear(); n     if (v.size() != 0) { n       xptr = v[0].first; n       yptr = v[0].second; n       it3 = tem.lower_bound(make_pair(xptr, -1)); n       zptr = it3->second; n       tem.erase(it3); n     } n     for (i = 0; i < v.size(); i++) { n       z = xptr; n       it2 = all.lower_bound(z); n       id1 = *it2; n       z = v[i].first; n       it2 = all.lower_bound(z); n       id2 = *it2; n       if (s[id1] == s[id2]) { n         if (i != 0) { n           yptr = yptr + v[i].second; n           it3 = tem.lower_bound(make_pair(v[i].first, -1)); n           zptr = it3->second; n           tem.erase(it3); n         } n       } else { n         seg.insert(make_pair(xptr, yptr)); n         tem.insert(make_pair(xptr, zptr)); n         xptr = v[i].first; n         yptr = v[i].second; n         it3 = tem.lower_bound(make_pair(v[i].first, -1)); n         zptr = it3->second; n         tem.erase(it3); n       } n       if (i + 1 == v.size()) { n         seg.insert(make_pair(xptr, yptr)); n         tem.insert(make_pair(xptr, zptr)); n       } n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n using vec = vector<T>; n template <typename Iter> n ostream &_IterOutput_(ostream &o, Iter b, Iter e, const string ss =   , n                       const string se =   ) { n   o << ss; n   for (auto it = b; it != e; it++) o << (it == b ?    :  ,  ) << *it; n   return o << se; n } n template <typename T1, typename T2> n ostream &operator<<(ostream &o, const pair<T1, T2> &pair) { n   return o <<  (  << pair.first <<  ,   << pair.second <<  ) ; n } n template <typename T> n ostream &operator<<(ostream &o, const vector<T> &vec) { n   return _IterOutput_(o, begin(vec), end(vec),  [ ,  ] ); n } n template <typename T> n ostream &operator<<(ostream &o, const set<T> &st) { n   return _IterOutput_(o, begin(st), end(st),  { ,  } ); n } n template <typename T, size_t N> n ostream &operator<<(ostream &o, const array<T, N> &arr) { n   return _IterOutput_(o, begin(arr), end(arr),  | ,  | ); n } n template <typename T1, typename T2> n ostream &operator<<(ostream &o, const map<T1, T2> &mp) { n   o <<  { ; n   for (auto it = mp.begin(); it != mp.end(); it++) { n     o << (it == mp.begin() ?    :  ,  ) << it->first <<  :  << it->second; n   } n   o <<  } ; n   return o; n } n void lucky_test() { n   std::random_device rd; n   std::mt19937 gen_(rd()); n   std::normal_distribution<double> dist_(0.0, 1.0); n   if (dist_(gen_) >= 4.44444444) { n     cout <<  Not lucky  << endl; n     exit(0); n   } n } n int N; n const int MX = 131072 * 4; n const int INF = 1e9; n int ZZ = 0; n struct Seg { n   int val[MX]; n   int nl[MX], nr[MX]; n   int lz[MX]; n   void init(int id, int ql, int qr) { n     nl[id] = ql; n     nr[id] = qr; n     val[id] = -INF; n     if (ql == qr - 1) { n       return; n     } n     int md = (ql + qr) / 2; n     init(id * 2, ql, md); n     init(id * 2 + 1, md, qr); n   } n   void push(int id) { n     ZZ++; n     int l = nl[id], r = nr[id]; n     int v = lz[id]; n     lz[id] = 0; n     if (l == r - 1) { n       return; n     } n     adj(id * 2, v); n     adj(id * 2 + 1, v); n     return; n   } n   void pull(int id) { n     ZZ++; n     int l = nl[id], r = nr[id]; n     if (l == r - 1) return; n     val[id] = max(val[id * 2], val[id * 2 + 1]); n   } n   void adj(int id, int v) { n     lz[id] += v; n     val[id] += v; n   } n   void add(int id, int ql, int qr, int v) { n     push(id); n     int l = nl[id], r = nr[id]; n     if (l == ql and r == qr) { n       adj(id, v); n       return; n     } n     int md = (l + r) / 2; n     if (qr <= md) n       add(id * 2, ql, qr, v); n     else if (ql >= md) n       add(id * 2 + 1, ql, qr, v); n     else { n       add(id * 2, ql, md, v); n       add(id * 2 + 1, md, qr, v); n     } n     pull(id); n   } n   int walk(int id) { n     push(id); n     if (val[id] < 0) return -1; n     int l = nl[id], r = nr[id]; n     if (l == r - 1) { n       return val[id] >= 0 ? l : -1; n     } n     if (val[id * 2 + 1] >= 0) n       return walk(id * 2 + 1); n     else n       return walk(id * 2); n   } n } tree; n struct Hao { n   int val[MX]; n   int n; n   void init(int id, int l, int r) { n     n = r; n     for (int i = l; i < r; i++) val[i] = -INF; n   } n   void add(int id, int l, int r, int v) { n     for (int i = l; i < r; i++) val[i] += v; n   } n   int walk(int id) { n     for (int i = n - 1; i >= 0; i--) n       if (val[i] >= 0) return i; n     return -1; n   } n   void dmp() { n     for (int i = 0; i < n; i++) cout << val[i] <<    ; n     cout << endl; n   } n }; n int V[MX]; n int32_t main() { n   do { n     ios_base::sync_with_stdio(0); n     cin.tie(0); n   } while (0); n   cin >> N; n   tree.init(1, 0, N + 5); n   for (int i = 0; i < N; i++) { n     int p, t; n     cin >> p >> t; n     if (t == 0) { n       tree.add(1, 0, p, -1); n     } else { n       cin >> V[p]; n       tree.add(1, p, p + 1, INF); n       tree.add(1, 0, p, 1); n     } n     int pos = tree.walk(1); n     if (pos == -1) n       cout << -1 <<   n ; n     else n       cout << V[pos] <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0), cout.tie(0); n   int n; n   cin >> n; n   vector<int> a(n + 1), b(n + 1), p(n + 1); n   for (int i = 1; i <= n; ++i) { n     cin >> a[i]; n     p[a[i]] = 0; n   } n   for (int i = 1; i <= n; ++i) { n     cin >> b[i]; n     p[b[i]] = i; n   } n   if (p[1]) { n     int k = 1, i; n     for (i = 2; p[i] == p[1] + i - 1; ++i) { n       k++; n     } n     if (p[i - 1] == n) { n       set<int> s; n       for (auto x : a) { n         if (x) { n           s.insert(x); n         } n       } n       int f = 1; n       int ind = 1; n       for (; i <= n; ++i) { n         auto it = s.find(i); n         if (it == s.end()) { n           f = 0; n           break; n         } n         s.erase(it); n         s.insert(b[ind]); n         ind++; n       } n       if (f == 1) { n         cout << n - k; n         return 0; n       } n     } n   } n   int ans = 0; n   for (int i = 1; i <= n; ++i) { n     ans = max(ans, p[i] - i + 1 + n); n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n, t; n   cin >> n >> t; n   if (n == 1 && t == 10) { n     cout <<  -1 ; n     return 0; n   } n   if (t != 10) n     cout << t; n   else n     cout <<  1 ; n   for (int i = 1; i < n; i++) cout <<  0 ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char board[8][8]; n int main() { n   for (int i = 0; i < 8; i++) { n     for (int j = 0; j < 8; j++) scanf(  %c , &board[i][j]); n   } n   int minA = 100, minB = 100; n   for (int i = 0; i < 8; i++) { n     for (int j = 0; j < 8; j++) { n       if (board[i][j] ==  W ) { n         int k; n         for (k = i; k >= 0; k--) { n           if (k == i) continue; n           if (board[k][j] !=  . ) break; n         } n         if (k < 0 and i < minA) minA = i; n       } n       if (board[i][j] ==  B ) { n         int k; n         for (k = i; k < 8; k++) { n           if (k == i) continue; n           if (board[k][j] !=  . ) break; n         } n         if (k >= 8 and 7 - i < minB) minB = 7 - i; n       } n     } n   } n   if (minA <= minB) n     cout <<  A  << endl; n   else n     cout <<  B  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long x, y; n   cin >> x >> y; n   long long d = x * x + y * y; n   if (x == 0 || y == 0) { n     cout <<  black  << endl; n     return 0; n   } n   for (long long i = 1; i <= 10000; i++) { n     if (d < i * i) { n       bool white = (i % 2 == 0 && x * y > 0) || (i % 2 == 1 && x * y < 0); n       cout << (white ?  white  :  black ) << endl; n       return 0; n     } n     if (d == i * i) { n       cout <<  black  << endl; n       return 0; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int gcd(int f, int s) { n   if (s == 0) n     return f; n   else n     return gcd(s, f % s); n } n int const N = 1002006; n long long const M = 998244353; n long double const ep = .000000000000000001; n vector<int> G[N]; n long long pw[N]; n int od = 0, ev = 0; n int vis[N]; n bool wtf = 1; n void dfs(int node, int col) { n   if (col % 2 == 0) n     ev++; n   else n     od++; n   vis[node] = col; n   for (int i = 0; i < G[node].size(); i++) { n     int el = G[node][i]; n     if (vis[el] == -1) n       dfs(el, col ^ 1); n     else if (col == vis[el]) n       wtf = 0; n   } n } n int main() { n   pw[0] = 1; n   for (int i = 1; i < N; i++) pw[i] = (pw[i - 1] * 2) % M; n   int t; n   cin >> t; n   while (t--) { n     int n, e; n     scanf( %d%d , &n, &e); n     for (int i = 1; i <= n; i++) { n       G[i].clear(); n       vis[i] = -1; n     } n     for (int i = 0; i < e; i++) { n       int temp, temp1; n       scanf( %d%d , &temp, &temp1); n       G[temp].push_back(temp1); n       G[temp1].push_back(temp); n     } n     wtf = 1; n     long long ans = 1; n     for (int i = 1; i <= n; i++) { n       if (vis[i] == -1) { n         od = 0, ev = 0; n         dfs(i, 0); n         long long tot = pw[od] + pw[ev]; n         tot %= M; n         ans = (ans * tot) % M; n       } n     } n     ans *= wtf; n     printf( %lld n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n const int mx = 705; n long long int dp[mx][mx][3][3]; n char s[mx]; n int p[mx]; n stack<int> st; n long long int dfs(int l, int r, int lc, int rc) { n   if (l >= r) return 1; n   if (dp[l][r][lc][rc] != -1) return dp[l][r][lc][rc]; n   int x = p[l]; n   int y = p[r]; n   dp[l][r][lc][rc] = 0; n   if (x == r) { n     for (int i = 1; i <= 2; i++) n       if (i != rc) n         dp[l][r][lc][rc] = (dp[l][r][lc][rc] + dfs(l + 1, r - 1, 0, i)) % mod; n     for (int i = 1; i <= 2; i++) n       if (i != lc) n         dp[l][r][lc][rc] = (dp[l][r][lc][rc] + dfs(l + 1, r - 1, i, 0)) % mod; n   } else if (x + 1 == y) { n     for (int i = 1; i <= 2; i++) n       for (int j = 1; j <= 2; j++) n         if (i != lc && j != rc) n           dp[l][r][lc][rc] = (dp[l][r][lc][rc] + dfs(l + 1, x - 1, i, 0) * n                                                      dfs(y + 1, r - 1, 0, j)) % n                              mod; n     for (int i = 1; i <= 2; i++) n       for (int j = 1; j <= 2; j++) n         if (i != j) n           dp[l][r][lc][rc] = (dp[l][r][lc][rc] + dfs(l + 1, x - 1, 0, i) * n                                                      dfs(y + 1, r - 1, j, 0)) % n                              mod; n     for (int i = 1; i <= 2; i++) n       for (int j = 1; j <= 2; j++) n         if (i != lc) n           dp[l][r][lc][rc] = (dp[l][r][lc][rc] + dfs(l + 1, x - 1, i, 0) * n                                                      dfs(y + 1, r - 1, j, 0)) % n                              mod; n     for (int i = 1; i <= 2; i++) n       for (int j = 1; j <= 2; j++) n         if (j != rc) n           dp[l][r][lc][rc] = (dp[l][r][lc][rc] + dfs(l + 1, x - 1, 0, i) * n                                                      dfs(y + 1, r - 1, 0, j)) % n                              mod; n   } else { n     for (int i = 1; i <= 2; i++) n       for (int j = 1; j <= 2; j++) n         if (i != lc && j != rc) n           dp[l][r][lc][rc] = n               (dp[l][r][lc][rc] + dfs(l + 1, x - 1, i, 0) * n                                       dfs(x + 1, y - 1, 0, 0) % mod * n                                       dfs(y + 1, r - 1, 0, j)) % n               mod; n     for (int i = 1; i <= 2; i++) n       for (int j = 1; j <= 2; j++) n         dp[l][r][lc][rc] = (dp[l][r][lc][rc] + n                             dfs(l + 1, x - 1, 0, i) * dfs(x + 1, y - 1, i, j) % n                                 mod * dfs(y + 1, r - 1, j, 0)) % n                            mod; n     for (int i = 1; i <= 2; i++) n       for (int j = 1; j <= 2; j++) n         if (i != lc) n           dp[l][r][lc][rc] = n               (dp[l][r][lc][rc] + dfs(l + 1, x - 1, i, 0) * n                                       dfs(x + 1, y - 1, 0, j) % mod * n                                       dfs(y + 1, r - 1, j, 0)) % n               mod; n     for (int i = 1; i <= 2; i++) n       for (int j = 1; j <= 2; j++) n         if (j != rc) n           dp[l][r][lc][rc] = n               (dp[l][r][lc][rc] + dfs(l + 1, x - 1, 0, i) * n                                       dfs(x + 1, y - 1, i, 0) % mod * n                                       dfs(y + 1, r - 1, 0, j)) % n               mod; n   } n   return dp[l][r][lc][rc]; n } n int main() { n   memset(dp, -1, sizeof(dp)); n   int n; n   scanf( %s , s + 1); n   n = strlen(s + 1); n   for (int i = 1; i <= n; i++) n     if (s[i] ==  ( ) n       st.push(i); n     else { n       p[st.top()] = i; n       p[i] = st.top(); n       st.pop(); n     } n   long long int ans = dfs(1, n, 0, 0); n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 200005; n int a[maxn], cnt[maxn], n, q; n long long ans = 0; n map<pair<long long, long long>, int> mp; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0), cout.tie(0); n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     ans += a[i]; n   } n   cin >> q; n   long long s, t, u; n   while (q--) { n     cin >> s >> t >> u; n     if (mp.find(pair<long long, long long>(s, t)) != mp.end()) { n       int c = mp[pair<long long, long long>(s, t)]; n       if (cnt[c] <= a[c]) ans++; n       cnt[c]--; n       mp.erase(pair<long long, long long>(s, t)); n     } n     if (u != 0) { n       mp[pair<long long, long long>(s, t)] = u; n       if (cnt[u] < a[u]) ans--; n       cnt[u]++; n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1000000007; n long long n, i, j, pw = 1, ans1, ans2, diff = 1; n char a[100000], b[100000]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(); n   cin >> n; n   for (i = 0; i < n; i++) cin >> a[i]; n   for (i = 0; i < n; i++) cin >> b[i]; n   ans1 = ans2 = 1; n   for (i = 0; i < n; i++) { n     if (a[i] ==  ? ) pw = (pw * 10) % mod; n     if (b[i] ==  ? ) pw = (pw * 10) % mod; n     if (a[i] ==  ?  && b[i] ==  ? ) n       ans1 = (ans1 * 55) % mod, ans2 = (ans2 * 55) % mod, diff *= 10; n     else { n       if (a[i] ==  ?  || b[i] ==  ? ) { n         if (a[i] ==  ? ) n           ans1 = (ans1 * ( 9  - b[i] + 1)) % mod, n           ans2 = (ans2 * (b[i] -  0  + 1)) % mod; n         else n           ans2 = (ans2 * ( 9  - a[i] + 1)) % mod, n           ans1 = (ans1 * (a[i] -  0  + 1)) % mod; n       } else { n         if (a[i] < b[i]) ans1 = 0, diff = 0; n         if (a[i] > b[i]) ans2 = 0, diff = 0; n       } n     } n   } n   cout << (pw - ans1 - ans2 + 3 * mod + diff) % mod; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long double pi = acos(-1.0); n vector<long long> v1, v2; n long long ans = 0, x, y; n long long fact[1008], dp[1008][1008]; n void pow1(long long a[], long long i, long long end, long long sum) { n   if (i == end) { n     v1.push_back(sum); n     return; n   } n   pow1(a, i + 1, end, sum + a[i]); n   pow1(a, i + 1, end, sum); n } n void subsetSums1(long long arr[], long long l, long long r, long long sum = 0) { n   if (l > r) { n     v1.push_back(sum); n     return; n   } n   subsetSums1(arr, l + 1, r, sum + arr[l]); n   subsetSums1(arr, l + 1, r, sum); n } n void subsetSums2(long long arr[], long long l, long long r, long long sum = 0) { n   if (l > r) { n     v2.push_back(sum); n     return; n   } n   subsetSums2(arr, l + 1, r, sum + arr[l]); n   subsetSums2(arr, l + 1, r, sum); n } n void pow2(long long a[], long long i, long long end, long long sum) { n   if (i == end) { n     v2.push_back(sum); n     return; n   } n   pow1(a, i + 1, end, sum + a[i]); n   pow1(a, i + 1, end, sum); n } n string bn(long long length) { n   string s; n   s.resize(length); n   char a[length]; n   for (int i = 0; i < length; ++i) a[i] =  0 ; n   for (int i = 0; i < length; ++i) s[i] = a[i]; n   cout << s; n   return s; n   int count = length - 1; n   while (length) { n     s[count--] = (length % 2); n     length /= 2; n   } n   return s; n } n long long powm(long long a, long long b, long long m) { n   if (b == 0) return 1; n   long long t = powm(a, b / 2, m); n   if (b % 2) return a * t % m * t % m; n   return t * t % m; n } n long long modinv1(long long b, long long m) { return powm(b, m - 2, m); } n long long nck(long long n, long long k) { n   return fact[n] * modinv1(fact[n - k], 1000000007) % 1000000007 * n          modinv1(fact[k], 1000000007) % 1000000007; n } n int suffix(int l, vector<int> v) { n   int ans = 0; n   long long p = 1; n   for (int i = 0; i < max((int)v.size(), l); ++i) { n     if (i < v.size()) { n       ans = (ans + p * v[i] % 998244353) % 998244353; n       p = (p * 10) % 998244353; n     } n     if (i < l) { n       p = (p * 10) % 998244353; n     } n   } n   return ans; n } n int prefix(vector<int> v, int l) { n   int ans = 0; n   long long p = 1; n   for (int i = 0; i < max((int)v.size(), l); ++i) { n     if (i < l) { n       p = (p * 10) % 998244353; n     } n     if (i < v.size()) { n       ans = (ans + p * v[i] % 998244353) % 998244353; n       p = (p * 10) % 998244353; n     } n   } n   return ans; n } n int ct = 0; n void sum(long long n) { n   if (n / 10 == 0) return; n   long long ans = 0; n   while (n) { n     ans += n % 10; n     n /= 10; n   } n   ct++; n   sum(ans); n } n vector<long long> v; n long long string_num(string); n void perm(long long l, long long cur, long long n) { n   if (cur == l) { n     v.push_back(n); n     return; n   } n   perm(l, cur + 1, n * 10 + 4); n   perm(l, cur + 1, n * 10 + 7); n } n long long string_num(string s) { n   int x = s.size(); n   long long ans = 0, i = 0; n   while (x--) { n     ans += (pow(10, x) * (s[i++] -  0 )); n   } n   return ans; n } n void DJ() { n   long long l, r; n   cin >> l >> r; n   long long ans = 0; n   for (int i = 1; i < 11; ++i) { n     perm(i, 0, 0); n   } n   long long it = lower_bound(v.begin(), v.end(), l) - v.begin(); n   long long sum = r - l + 1; n   if (v[it] - l >= sum) { n     ans += sum * v[it]; n     sum = 0; n   } else { n     ans += v[it] * (v[it] - l + 1); n     sum -= v[it] - l + 1; n     it++; n   } n   while (sum) { n     if (v[it] - v[it - 1] >= sum) { n       ans += sum * (v[it]); n       sum = 0; n     } else { n       ans += v[it] * (v[it] - v[it - 1]); n       sum -= v[it] - v[it - 1]; n       it++; n     } n   } n   cout << ans; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long t = 1; n   while (t--) DJ(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1000 + 10; n int n, m; n int a[maxn]; n int res0, res1; n void output(int l, int r) { n   printf( ?  ); n   for (int i = 1; i < l; i++) printf( 0 ); n   for (int i = l; i <= r; i++) printf( 1 ); n   for (int i = r + 1; i <= n; i++) printf( 0 ); n   printf(  n ); n   fflush(stdout); n } n void dfs(int l, int r) { n   if (res0 && res1) return; n   if (l == r) { n     output(l, l); n     scanf( %d , &a[++m]); n     if (a[m] - a[1] == 1) n       res0 = l; n     else n       res1 = l; n     return; n   } n   if (r - l == 1) { n     output(l, l); n     scanf( %d , &a[++m]); n     if (a[m] - a[1] == 1) res0 = l; n     if (a[1] - a[m] == 1) res1 = l; n     if (res0 && res1) return; n     dfs(r, r); n     return; n   } n   int mid = (l + r) >> 1; n   output(l, mid); n   scanf( %d , &a[++m]); n   if (a[m] - a[1] == mid - l + 1) { n     res0 = l; n     if (res0 && res1) return; n     dfs(mid + 1, r); n   } else if (a[1] - a[m] == mid - l + 1) { n     res1 = l; n     if (res0 && res1) return; n     dfs(mid + 1, r); n   } else { n     if (res0 && res1) return; n     dfs(l, mid); n     if (res0 && res1) return; n     dfs(mid + 1, r); n   } n } n int main() { n   scanf( %d , &n); n   output(1, 0); n   scanf( %d , &a[++m]); n   dfs(1, n); n   printf( ! %d %d n , res0, res1); n   fflush(stdout); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mmax = 1e6 + 10; n const int eps = 1e-9; n struct node { n   string name; n } s[105]; n long long cmp(node a, node b) { n   if (a.name == b.name) return a.name < b.name; n   return a.name < b.name; n } n int main() { n   long long n; n   while (cin >> n) { n     for (int i = 0; i < n; i++) { n       cin >> s[i].name; n     } n     sort(s, s + n, cmp); n     long long ans = 0, sum = 0; n     for (int i = 0; i < n; i++) { n       if (s[i].name[0] == s[i + 1].name[0]) n         ans++; n       else { n         long long num0 = (ans + 1) / 2; n         long long num1 = ans + 1 - num0; n         long long sum0 = 0, sum1 = 0; n         for (int i = 1; i < num0; i++) sum0 += i; n         for (int i = 1; i < num1; i++) sum1 += i; n         sum += (sum0 + sum1); n         ans = 0; n       } n     } n     cout << sum << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, k, kk; n vector<int> g[10], e[10]; n int cnt = 0; n bool used[10] = {}, vis[10] = {}; n int usedCnt, visCnt; n long long cur; n int st; n int pc[1024]; n void go(int v) { n   vis[v] = true, ++visCnt; n   vector<int> &f = e[v]; n   int sz = 0; n   for (int x : g[v]) n     if (!used[x]) { n       f[sz++] = x; n     } n   for (int mask = 0; mask < (int)(1 << sz); ++mask) { n     int pcm = pc[mask]; n     for (int i = 0; i < (int)(sz); ++i) n       if (mask & (1 << i)) { n         used[f[i]] = true; n       } n     usedCnt += pcm; n     int pos = 0; n     while (pos < n && (!used[pos] || vis[pos])) ++pos; n     if (pos != n) { n       go(pos); n     } else { n       if (usedCnt == n) ++cur; n     } n     for (int i = 0; i < (int)(sz); ++i) n       if (mask & (1 << i)) { n         used[f[i]] = false; n       } n     usedCnt -= pcm; n   } n   vis[v] = false, --visCnt; n } n long long ans[15], c[15][15]; n int main() { n   for (int i = 0; i < (int)(1024); ++i) pc[i] = __builtin_popcount(i); n   scanf( %d%d%d , &n, &m, &kk); n   for (int i = 0; i < (int)(m); ++i) { n     int from, to; n     scanf( %d%d , &from, &to), --from, --to; n     g[from].push_back(to); n     g[to].push_back(from); n   } n   for (int i = 0; i < (int)(n); ++i) e[i].resize(g[i].size()); n   for (int i = 0; i < (int)(15); ++i) c[0][i] = 0; n   c[0][0] = 1; n   for (int i = 1; i < 15; ++i) { n     c[i][0] = 1; n     for (int j = 1; j < 15; ++j) { n       c[i][j] = c[i - 1][j] + c[i - 1][j - 1]; n     } n   } n   for (int k = n - 1; k >= kk; --k) { n     for (int mask = 0; mask < (int)(1 << n); ++mask) n       if (pc[mask] == k) { n         for (int i = 0; i < (int)(n); ++i) n           vis[i] = used[i] = (mask & (1 << i)) > 0; n         st = 0; n         while (used[st]) ++st; n         if (st == n) break; n         usedCnt = k + 1; n         visCnt = k; n         used[st] = true; n         cur = 0; n         go(st); n         for (int i = 0; i < (int)(n); ++i) n           if (mask & (1 << i)) { n             int mul = 0; n             for (int to : g[i]) n               if (!(mask & (1 << to))) { n                 ++mul; n               } n             cur *= mul; n           } n         ans[k] += cur; n       } n     for (int x = n - 1; x > k; --x) { n       ans[k] -= ans[x] * c[x][k]; n     } n   } n   printf( %d n , (int)ans[kk]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long s; n int main() { n   int n, a, b, c, d; n   cin >> n >> a >> b >> c >> d; n   for (int x = 1; x <= n; x++) { n     int y = x + b - c; n     int z = x + a - d; n     int w = y + a - d; n     if (y <= n && z <= n && w <= n && y > 0 && z > 0 && w > 0) s++; n   } n   s *= n; n   cout << s; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n = 0, m = 0; n   string s; n   cin >> s; n   for (int i = 0; i < s.length(); i++) n     if (s[i] ==  x ) n       n++; n     else n       m++; n   if (n > m) n     for (int i = 1; i <= n - m; i++) cout <<  x ; n   else if (n < m) n     for (int i = 1; i <= m - n; i++) cout <<  y ; n   return 0; n } n


#include <bits/stdc++.h> n const int N = 1e5 + 10; n int ri() { n   char c = getchar(); n   int x = 0, f = 1; n   for (; c <  0  || c >  9 ; c = getchar()) n     if (c ==  - ) f = -1; n   for (; c >=  0  && c <=  9 ; c = getchar()) x = (x << 1) + (x << 3) -  0  + c; n   return x * f; n } n struct Pt { n   long long x, y; n   Pt(long long _x = 0, long long _y = 0) : x(_x), y(_y) {} n   Pt operator+(Pt a) { return Pt(x + a.x, y + a.y); } n   Pt operator-(Pt a) { return Pt(x - a.x, y - a.y); } n   double operator*(Pt a) { return (double)x * a.y - (double)y * a.x; } n } A[N * 60], B[N], p[N], Ans[N * 60]; n int tpa, tpb, all, cnt, tot, n, m, sums, G, mn, lst[N], sz[N << 1]; n bool del[N << 1]; n bool cmp(Pt a, Pt b) { return a.x == b.x ? a.y > b.y : a.x < b.x; } n struct Edge { n   int pr[N << 1], to[N << 2], nx[N << 2], tp; n   Pt w[N << 2]; n   Edge() { tp = 1; } n   void add(int u, int v, Pt _w) { n     to[++tp] = v; n     nx[tp] = pr[u]; n     pr[u] = tp; n     w[tp] = _w; n   } n   void adds(int u, int v, Pt w = Pt()) { n     add(u, v, w); n     add(v, u, w); n   } n } R, T; n void Ins(int u, int v, Pt w) { n   ++tot; n   T.adds(tot, v, w); n   T.adds(tot, lst[u]); n   lst[u] = tot; n } n void Build(int u, int fa) { n   for (int i = R.pr[u], v; i; i = R.nx[i]) n     if ((v = R.to[i]) != fa) Ins(u, v, R.w[i]), Build(v, u); n } n void Dfs(int u, int fa, Pt D) { n   if (u <= n) p[++cnt] = D; n   for (int i = T.pr[u], v; i; i = T.nx[i]) n     if (!del[i >> 1] && (v = T.to[i]) != fa) Dfs(v, u, D + T.w[i]); n } n void Get(Pt *p, int &cnt, Pt *A, int &tp) { n   if (!cnt) return void(tp = 0); n   std::sort(p + 1, p + cnt + 1, cmp); n   A[tp = 1] = p[1]; n   for (int i = 2; i <= cnt; ++i) n     if (p[i].x != p[i - 1].x) { n       for (; tp > 1 && (p[i] - A[tp]) * (A[tp - 1] - A[tp]) >= 0;) --tp; n       A[++tp] = p[i]; n     } n } n void Push() { n   if (!tpa) { n     for (int i = 1; i <= tpb; ++i) Ans[++all] = B[i]; n     return; n   } n   if (!tpb) { n     for (int i = 1; i <= tpa; ++i) Ans[++all] = A[i]; n     return; n   } n   Ans[++all] = A[1] + B[1]; n   for (int i = 1, j = 1; i < tpa || j < tpb;) { n     ++all; n     if (i >= tpa) n       Ans[all] = A[i] + B[++j]; n     else if (j >= tpb) n       Ans[all] = A[++i] + B[j]; n     else { n       Pt v1 = A[i + 1] - A[i]; n       Pt v2 = B[j + 1] - B[j]; n       Ans[all] = Ans[all - 1] + (v1 * v2 < 0 ? ++i, v1 : (++j, v2)); n     } n   } n } n void Rt(int u, int fa) { n   sz[u] = 1; n   for (int i = T.pr[u], v; i; i = T.nx[i]) n     if (!del[i >> 1] && (v = T.to[i]) != fa) { n       Rt(v, u); n       sz[u] += sz[v]; n       int tmp = std::max(sz[v], sums - sz[v]); n       if (mn > tmp) mn = tmp, G = i; n     } n } n void Div(int u, int pres) { n   if (pres == 1) return; n   sums = pres; n   mn = tot + 1; n   Rt(u, 0); n   del[G >> 1] = true; n   int x = T.to[G], y = T.to[G ^ 1], sy = pres - sz[x]; n   cnt = 0; n   Dfs(x, 0, Pt()); n   Get(p, cnt, A, tpa); n   cnt = 0; n   Dfs(y, 0, T.w[G]); n   Get(p, cnt, B, tpb); n   Push(); n   Div(x, sz[x]); n   Div(y, sy); n } n long long F(int p, long long i) { return A[p].x * i + A[p].y; } n int main() { n   tot = n = ri(); n   m = ri(); n   for (int i = 1; i < n; ++i) { n     int u = ri(), v = ri(), a = ri(), b = ri(); n     R.adds(u, v, Pt(a, b)); n   } n   for (int i = 1; i <= n; ++i) lst[i] = i; n   Build(1, 0); n   Div(1, tot); n   Get(Ans, all, A, tpa); n   int r = 1; n   long long mmx = 0; n   int ps = 0; n   for (int i = 1; i <= tpa; ++i) n     if (A[i].y > mmx) mmx = A[i].y, ps = i; n   for (int i = 0; i < m; ++i) { n     for (; r < tpa && F(r + 1, i) >= F(r, i); ++r) n       ; n     if (!i && mmx != F(r, i)) { n       for (int i = 20; i <= 44; ++i) printf( %lld %lld n , A[i].x, A[i].y); n       printf( %d %d %d n , r, ps, tot); n     } n     printf( %lld  , F(r, i)); n   } n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> vc[200007]; n int main() { n   int n; n   scanf( %d , &n); n   int res = 0; n   for (auto i = (1); i <= (n); ++i) { n     int m; n     scanf( %d , &m); n     vc[i].resize(m); n     for (auto j = (0); j <= (m - 1); ++j) scanf( %d , &vc[i][j]); n     sort(vc[i].rbegin(), vc[i].rend()); n     res = max(res, vc[i][0]); n   } n   long long ans = 0LL; n   for (auto i = (1); i <= (n); ++i) n     ans += (long long)(res - vc[i][0]) * (int)vc[i].size(); n   printf( %lld n , ans); n   return 0; n } n


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


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:1024000000,1024000000 ) n using namespace std; n int n, k; n char str[100005]; n long long jie[100005]; n long long ni[100005]; n long long sum[100005]; n long long extend_gcd(long long a, long long b, long long &x, long long &y) { n   if (b == 0) { n     x = 1, y = 0; n     return a; n   } n   long long gcd = extend_gcd(b, a % b, x, y); n   long long t = x; n   x = y; n   y = t - a / b * x; n   return gcd; n } n long long Get_Inverse(long long num) { n   long long x, y; n   extend_gcd(num, 1000000007, x, y); n   return (x % 1000000007 + 1000000007) % 1000000007; n } n void init() { n   jie[0] = jie[1] = 1; n   ni[0] = ni[1] = 1; n   for (int i = 2; i <= 100000; i++) { n     jie[i] = (jie[i - 1] * i) % 1000000007; n     ni[i] = Get_Inverse(jie[i]); n   } n } n long long cal(int n, int m) { n   if (n < m) return 0; n   return jie[n] * ni[n - m] % 1000000007 * ni[m] % 1000000007; n } n int main(void) { n   init(); n   scanf( %d%d , &n, &k); n   scanf( %s , str + 1); n   long long ans = 0; n   long long ten = 1; n   for (int i = 1; i <= n; i++) { n     sum[i] = n         (sum[i - 1] + ten * cal(n - i - 1, k - 1) % 1000000007) % 1000000007; n     ten = ten * 10 % 1000000007; n   } n   ten = 1; n   for (int i = n; i >= 1; i--) { n     int c = str[i] -  0 ; n     ans += c * ten % 1000000007 * cal(i - 1, k) % 1000000007; n     ans += c * sum[n - i] % 1000000007; n     ans %= 1000000007; n     ten = ten * 10 % 1000000007; n   } n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n vector<string> s(100, string(100,  . )); n int n, k; n int solve() { n   ios::sync_with_stdio(false), cin.tie(0); n   cin >> n >> k; n   if (n - 2 == k) { n     for (int i = 1; i < n - 1; i++) { n       s[1][i] =  # ; n     } n     return 1; n   } n   if (k % 2 == 0) { n     for (int j = 0; j < n; j++) { n       for (int i = 0; i < 4; i++) { n         if (i != 0 && i != 3 && j != 0 && j != n - 1 && k) { n           s[i][j] =  # ; n           k--; n         } n       } n     } n     return 1; n   } n   if (k >= 5) { n     s[1][1] =  # ; n     s[2][1] =  # ; n     k -= 2; n     for (int i = 2; i < n - 2; i++) { n       s[1][i] =  # ; n       k--; n       if (k == 2) { n         s[1][i + 1] = s[2][i + 1] =  # ; n         return 1; n       } n     } n     s[1][n - 2] = s[2][n - 2] =  # ; n     k -= 2; n     for (int i = 2; i < n - 2; i++) { n       s[2][i] =  # ; n       k--; n       if (k == 0) return 1; n     } n   } n   if (k == 3) { n     s[1][n / 2 + 1] = s[2][n / 2] = s[1][n / 2 - 1] =  # ; n     return 1; n   } n   if (k == 1) { n     s[2][n / 2] =  # ; n     return 1; n   } n   assert(0); n } n int main() { n   int t = solve(); n   if (!solve()) return (cout <<  NO  << endl, 0); n   cout <<  YES  << endl; n   for (int i = 0; i < 4; i++) { n     for (int j = 0; j < n; j++) { n       cout << s[i][j]; n     } n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n void hashLine(int n) { n   for (int i = 0; i < n; i++) cout <<  # ; n   cout << endl; n } n void right(int n) { n   cout <<  . ; n   for (int i = 1; i < n - 1; i++) cout <<  . ; n   cout <<  # n ; n } n void left(int n) { n   cout <<  # ; n   for (int i = 1; i < n - 1; i++) cout <<  . ; n   cout <<  . n ; n } n int main() { n   int n, m, i, j, dir = 0; n   cin >> n >> m; n   for (i = 0; i < n; i++) { n     if (i % 2 == 0) n       hashLine(m); n     else { n       if (dir == 0) { n         right(m); n         dir = 1; n       } else { n         left(m); n         dir = 0; n       } n     } n   } n   return 0; n } n


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