#include <bits/stdc++.h> n using namespace std; n inline void OPEN(const string &s) { n   freopen((s +  .in ).c_str(),  r , stdin); n   freopen((s +  .out ).c_str(),  w , stdout); n } n int main() { n   int n; n   scanf( %d , &n); n   int art; n   scanf( %d , &art); n   int alex; n   scanf( %d , &alex); n   int ans[110] = {0}; n   for (int i = 0; i < art; i++) { n     int temp; n     scanf( %d , &temp); n     if (ans[temp] == 0) ans[temp] = 1; n   } n   for (int i = 0; i < alex; i++) { n     int temp; n     scanf( %d , &temp); n     if (ans[temp] == 0) ans[temp] = 2; n   } n   for (int i = 1; i < n + 1; i++) { n     if (ans[i] == 0) n       printf( 1  ); n     else n       printf( %d  , ans[i]); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int M[2002][2002]; n struct TA { n   int a[2002], n; n   void init(int _n) { n     n = _n; n     memset(a, 0, sizeof a); n   } n   int get(int p) { n     int ret = 0; n     for (p++; p > 0; p -= p & -p) ret ^= a[p - 1]; n     return ret; n   } n   void change(int l) { n     for (l++; l <= n; l += l & -l) a[l - 1] ^= 1; n   } n   void change(int l, int r) { n     change(l); n     change(r + 1); n   } n } R[2002], C[2002]; n void put(int r, int c) { n   R[r].change(min(r, c), max(r, c)); n   C[c].change(min(r, c), max(r, c)); n   M[r][c] ^= 1; n } n int get(int r, int c) { return R[r].get(c) ^ C[c].get(r) ^ M[r][c]; } n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n; ++i) { n     scanf(   ); n     for (int j = 0; j < n; ++j) { n       M[i][j] = getchar() ==  1 ; n     } n     R[i].init(n); n     C[i].init(n); n   } n   int ans = 0; n   for (int i = 0; i < n; ++i) { n     for (int r = n - 1; r > i; --r) { n       if (get(r, i)) { n         ++ans; n         put(r, i); n       } n     } n     for (int c = n - 1; c > i; --c) { n       if (get(i, c)) { n         ++ans; n         put(i, c); n       } n     } n     if (get(i, i)) { n       ++ans; n       put(i, i); n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n class MinHeap { n   vector<long long int> arr; n   long long int size; n  n  public: n   MinHeap() { size = 0; } n   long long int parent(long long int i) { return (i - 1) / 2; } n   long long int lchild(long long int i) { return 2 * i + 1; } n   long long int rchild(long long int i) { return 2 * i + 2; } n   long long int minimum() { return arr[0]; } n   long long int length() { return size; } n   void insert(long long int i) { n     size++; n     arr.push_back(i); n     long long int index = size - 1; n     while (i != 0 && arr[parent(index)] > arr[index]) { n       swap(arr[parent(index)], arr[index]); n       index = parent(index); n     } n   } n   void minheapify_down(long long int i) { n     while (i < size) { n       long long int l = lchild(i); n       long long int r = rchild(i); n       long long int small = i; n       if (l < size) small = arr[small] < arr[l] ? small : l; n       if (r < size) small = arr[small] < arr[r] ? small : r; n       swap(arr[i], arr[small]); n       if (i == small) break; n       i = small; n     } n   } n   void minheapify_up(long long int i) { n     long long int index = i; n     while (i != 0 && arr[parent(index)] > arr[index]) { n       swap(arr[parent(index)], arr[index]); n       index = parent(index); n     } n   } n   void extractmin() { n     long long int min = arr[0]; n     swap(arr[0], arr[size - 1]); n     arr.pop_back(); n     size--; n     minheapify_down(0); n   } n   void changekey(long long int i, long long int value) { n     if (value > arr[i]) { n       arr[i] = value; n       minheapify_down(i); n     } else { n       arr[i] = value; n       minheapify_up(i); n     } n   } n   void deletekey(long long int i) { n     changekey(i, LLONG_MIN); n     extractmin(); n   } n }; n int main() { n   ; n   ios::sync_with_stdio(0); n   cin.tie(0); n   ; n   long long int n, k, t, b, ans = 0, count = 0, sum = 0; n   cin >> n >> k; n   vector<vector<long long int>> beauti(1000001); n   for (long long int i = 0; i < n; i++) { n     cin >> t >> b; n     beauti[b].push_back(t); n   } n   MinHeap length; n   for (long long int i = 1000000; i >= 1; i--) { n     if (beauti[i].size() != 0) { n       for (long long int j = 0; j < beauti[i].size(); j++) { n         sum += beauti[i][j]; n         length.insert(beauti[i][j]); n         count++; n         if (count > k) { n           long long int ele = length.minimum(); n           sum -= ele; n           length.deletekey(0); n           count--; n         } n       } n       ans = max(ans, i * sum); n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long> invi(long long n) { n   int x; n   vector<long long> a; n   for (long long i = 0; i < n; i++) { n     cin >> x; n     a.push_back(x); n   } n   return a; n } n void solve(); n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int t = 1; n   while (t--) solve(); n } n void solve() { n   long long n, k; n   cin >> n >> k; n   vector<long long> jobcho = invi(n); n   vector<long long> time = invi(n); n   vector<long long> ind; n   vector<long long> task; n   for (long long i = 0; i < k; i++) { n     task.push_back(0); n     ind.push_back(n + 1); n   } n   for (long long i = 0; i < n; i++) { n     if (task[jobcho[i] - 1] < time[i]) { n       task[jobcho[i] - 1] = time[i]; n       ind[jobcho[i] - 1] = i; n     } n   } n   for (long long i = 0; i < k; i++) { n     if (ind[i] < (n + 1)) time[ind[i]] = 1e10; n   } n   long long jbleft = 0; n   for (long long i = 0; i < k; i++) { n     if (task[i] == 0) { n       jbleft++; n     } n   } n   sort(time.begin(), time.end()); n   long long sum = 0; n   for (long long i = 0; i < jbleft; i++) { n     sum += time[i]; n   } n   cout << sum <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   char prev[26], next[26]; n   for (int i = 0; i < 26; i++) prev[i] = next[i] = -1; n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     string s; n     cin >> s; n     if (prev[s[0] -  a ] == -1) prev[s[0] -  a ] = 0; n     if (next[s[(int)s.size() - 1] -  a ] == -1) n       next[s[(int)s.size() - 1] -  a ] = 0; n     for (int j = 1; j < (int)s.size(); j++) { n       prev[s[j] -  a ] = s[j - 1]; n       next[s[j - 1] -  a ] = s[j]; n     } n   } n   for (int i = 0; i < 26; i++) { n     if (prev[i] == 0) { n       char cur =  a  + i; n       while (cur) { n         printf( %c , cur); n         cur = next[cur -  a ]; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n int n, a[100000], sum = 0; n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d , &a[i]); n     sum += a[i]; n   } n   if (sum % n != 0) n     printf( %d n , n - 1); n   else n     printf( %d n , n); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INFint = 2147483547; n const long long INF = 9223372036854775807ll; n const long long MOD = 1000000007ll; n const long double EPS = 1e-13; n string min_cyclic_shift(string s) { n   s += s; n   int n = (int)s.length(); n   int i = 0, ans = 0; n   while (i < n / 2) { n     ans = i; n     int j = i + 1, k = i; n     while (j < n && s[k] <= s[j]) { n       if (s[k] < s[j]) n         k = i; n       else n         ++k; n       ++j; n     } n     while (i <= k) i += j - k; n   } n   return s.substr(ans, n / 2); n } n int main() { n   ios_base::sync_with_stdio(0); n   vector<string> a(2), b(2); n   for (int i = 0; i < 2; i++) cin >> a[i]; n   for (int i = 0; i < 2; i++) cin >> b[i]; n   string s; n   for (int i = 0; i < 2; i++) { n     if (a[0][i] ==  X ) continue; n     s += a[0][i]; n   } n   for (int i = 1; i > -1; i--) { n     if (a[1][i] ==  X ) continue; n     s += a[1][i]; n   } n   string s1; n   for (int i = 0; i < 2; i++) { n     if (b[0][i] ==  X ) continue; n     s1 += b[0][i]; n   } n   for (int i = 1; i > -1; i--) { n     if (b[1][i] ==  X ) continue; n     s1 += b[1][i]; n   } n   if (min_cyclic_shift(s) == min_cyclic_shift(s1)) { n     cout <<  YES ; n   } else n     cout <<  NO ; n   fprintf(stderr,   nTIME = %lf n , 1.0 * clock() / CLOCKS_PER_SEC); n   ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n bool isPrime(int n) { n   if (n == 1) return false; n   for (int i = 2; i * i <= n; ++i) { n     if (n % i == 0) return false; n   } n   return true; n } n void solve() { n   int n, sum = 0; n   cin >> n; n   vector<int> a(n); n   for (int i = 0; i < n; ++i) { n     cin >> a[i]; n     sum += a[i]; n   } n   if (!isPrime(sum)) { n     cout << n <<   n ; n     for (int i = 1; i <= n; ++i) { n       cout << i <<    ; n     } n     cout <<   n ; n   } else { n     cout << n - 1 <<   n ; n     int oddpos = -1; n     for (int i = 0; i < n; ++i) { n       if (a[i] % 2 != 0) { n         oddpos = i; n         break; n       } n     } n     for (int i = 0; i < n; ++i) { n       if (i != oddpos) cout << i + 1 <<    ; n     } n     cout <<   n ; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   int t; n   cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, x; n   int a[100000 + 3], b[100000 + 3]; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     b[i] = a[i]; n   } n   sort(b, b + n); n   int cnt = 1; n   for (int i = 0; i < n; i++) { n     if (a[i] != b[i]) { n       cnt++; n     } n   } n   if (cnt == 3 || cnt == 1) { n     cout <<  YES ; n     return 0; n   } n   cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 5; n int n, m, p; n long long ans = -1e18; n struct nd { n   int val, c; n   friend bool operator<(nd a, nd b) { return a.val < b.val; } n } a[N], b[N]; n struct mon { n   int x, y, z; n   friend bool operator<(mon a, mon b) { return a.x < b.x; } n } c[N]; n struct BIT { n   int tot; n   int ls[N << 1], rs[N << 1]; n   long long mx[N << 1], tag[N << 1]; n   void up(int x) { mx[x] = max(mx[ls[x]], mx[rs[x]]); } n   void down(int x) { n     if (!tag[x]) return; n     if (ls[x]) { n       mx[ls[x]] += tag[x]; n       tag[ls[x]] += tag[x]; n     } n     if (rs[x]) { n       mx[rs[x]] += tag[x]; n       tag[rs[x]] += tag[x]; n     } n     tag[x] = 0; n   } n   int build(int l, int r) { n     int x = ++tot; n     if (l == r) { n       mx[x] = -b[l].c; n       return x; n     } n     int mid = l + r >> 1; n     ls[x] = build(l, mid); n     rs[x] = build(mid + 1, r); n     up(x); n     return x; n   } n   void add(int x, int l, int r, int L, int R, long long d) { n     if (L <= l && r <= R) { n       mx[x] += d; n       tag[x] += d; n       return; n     } n     down(x); n     int mid = l + r >> 1; n     if (L <= mid) add(ls[x], l, mid, L, R, d); n     if (R > mid) add(rs[x], mid + 1, r, L, R, d); n     up(x); n   } n   void init() { n     mx[0] = -1e18; n     int root = build(1, m); n   } n } T; n int main() { n   scanf( %d%d%d , &n, &m, &p); n   for (int i = 1; i <= n; ++i) scanf( %d%d , &a[i].val, &a[i].c); n   for (int i = 1; i <= m; ++i) scanf( %d%d , &b[i].val, &b[i].c); n   for (int i = 1; i <= p; ++i) scanf( %d%d%d , &c[i].x, &c[i].y, &c[i].z); n   sort(a + 1, a + n + 1); n   sort(b + 1, b + m + 1); n   sort(c + 1, c + p + 1); n   T.init(); n   for (int i = 1, R = 0; i <= n; ++i) { n     while (R < p && c[R + 1].x < a[i].val) { n       ++R; n       int l = 1, r = m; n       while (l != r) { n         int mid = l + r >> 1; n         if (b[mid].val > c[R].y) n           r = mid; n         else n           l = mid + 1; n       } n       if (b[l].val > c[R].y) { n         T.add(1, 1, m, l, m, c[R].z); n       } n     } n     ans = max(ans, -a[i].c + T.mx[1]); n   } n   printf( %lld n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, k, s; n   while (cin >> n >> k >> s) { n     long long temp = (s / k); n     long long rem = s % k; n     temp++; n     if (((n - 1) * k < s || (k > s))) { n       cout <<  NO  << endl; n       return 0; n     } n     cout <<  YES  << endl; n     long long ans = 1; n     int flag = 0; n     for (int i = 1; i <= k; i++) { n       if (flag == 0 && rem == 0) { n         flag = 1; n         temp--; n       } else n         rem--; n       if (ans + temp <= n) { n         ans += temp; n         cout << ans <<    ; n       } else { n         ans -= temp; n         cout << ans <<    ; n       } n     } n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int t; n long long a, b, c, d; n long long solve(long long x) { n   long long times = x / d + 1; n   long long sum = (x / d + 1) * a; n   long long finished; n   if (x < c) { n     finished = 0; n   } else { n     finished = (x - c) / d + 1; n   } n   long long left = times - finished; n   long long a1 = x - (x / d) * d; n   sum -= left * a1 * b + left * (left - 1) / 2 * d * b; n   sum -= finished * b * c; n   return sum; n } n int main() { n   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   cin >> t; n   while (t--) { n     cin >> a >> b >> c >> d; n     if (d >= c) { n       if (a > b * c) { n         cout << -1 << endl; n       } else { n         cout << a << endl; n       } n     } else { n       if (a > b * c) { n         cout << -1 << endl; n       } else { n         long long l = 0, r = 1e6 / d; n         while (l < r - 5) { n           long long ml = (l + r) / 2; n           long long mr = (ml + r) / 2; n           if (solve(ml * d) <= solve(mr * d)) { n             l = ml; n           } else { n             r = mr; n           } n         } n         long long mx = 0; n         for (long long i = l; i <= r; i++) { n           mx = max(mx, solve(i * d)); n         } n         cout << mx << endl; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma comment(linker,  /STACK:1024000000,1024000000 ) n const double pi = 2.0 * asin(1.0), eps = 1e-12; n const int maxn = 2100, maxm = 1100000, inf = 0x3f3f3f3f; n char ch[maxn][maxn]; n int ans[maxn]; n int main() { n   int n, m, i, j, l, x; n   while (scanf( %d%d%d , &n, &m, &l) == 3) { n     memset(ans, 0, sizeof(ans)); n     for (i = 0; i < n; i++) { n       scanf( %s , ch[i]); n       for (j = 0; j < m; j++) { n         if (ch[i][j] ==  U ) { n           if (i % 2 == 0) ans[j]++; n         } else if (ch[i][j] ==  L ) { n           x = j - i; n           if (x >= 0) ans[x]++; n         } else if (ch[i][j] ==  R ) { n           x = j + i; n           if (x < m) ans[x]++; n         } n       } n     } n     for (i = 0; i < m; i++) { n       if (i != 0) printf(   ); n       printf( %d , ans[i]); n     } n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 7; n vector<int> cur; n void split(int x, int p) { n   if (p == 1) { n     cout << x <<    ; n     return; n   } n   cout << x - 1 <<    ; n   split(x - 1, p - 1); n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   ; n   long long n, k; n   cin >> n >> k; n   string s =   ; n   while (n > 0) { n     s += (char)((n % 2) +  0 ); n     n /= 2; n   } n   for (int i = ((int)s.size() - 62); i < (int)s.size(); i++) { n     long long cnt = 0; n     for (int j = 0; j <= i; j++) { n       cnt += (s[j] ==  1 ); n     } n     bool ok = true; n     for (long long j = max(i + 1, 0); j < s.size(); j++) { n       cnt += (1ll << (j - i)) * (s[j] ==  1 ); n       if (cnt > k) { n         ok = false; n         break; n       } n     } n     if (cnt > k) { n       ok = false; n       continue; n     } n     if (!ok) continue; n     cout <<  Yes  << endl; n     cur.clear(); n     for (int j = 0; j <= i; j++) { n       if (s[j] ==  1 ) cur.push_back(j); n     } n     for (int j = max(i + 1, 0); j < s.size(); j++) { n       if (s[j] ==  0 ) continue; n       for (long long t = 0; t < (1ll << (j - i)); t++) { n         cur.push_back(i); n       } n     } n     for (int j = cur.size() - 1; j > 0; j--) { n       cout << cur[j] <<    ; n     } n     split(cur[0], k - cnt + 1); n     cout << endl; n     return 0; n   } n   cout <<  No  << endl; n } n


#include <bits/stdc++.h> n using std::cin; n using std::cout; n using std::endl; n using std::sort; n using std::string; n using std::swap; n int main() { n   int times = INT_MAX; n   int a[6]; n   while (times-- && ~scanf( %d , &a[0])) { n     for (int i = 1; i < 6; ++i) scanf( %d , a + i); n     printf( %d n , (a[0] + a[1] + a[2]) * (a[0] + a[1] + a[2]) - a[0] * a[0] - n                        a[2] * a[2] - a[4] * a[4]); n   }; n   return 0; n }; n


#include <bits/stdc++.h> n const double inf = 1e20; n using namespace std; n int n, m, i, j, f; n char a[55][55]; n int vis[55][55]; n int dx[4] = {1, 0, -1, 0}; n int dy[4] = {0, 1, 0, -1}; n void dfs(int x, int y, int oldx, int oldy) { n   if (x == i && y == j && vis[i][j]) { n     f = 1; n     return; n   } n   for (int d = 0; d < 4 && !f; d++) { n     int xx = x + dx[d], yy = y + dy[d]; n     if (a[xx][yy] == a[i][j] && xx >= 0 && yy >= 0 && xx < n && yy < m && n         !vis[xx][yy] && (oldx != xx || oldy != yy)) n       vis[xx][yy] = 1, dfs(xx, yy, x, y); n   } n } n int main() { n   cin >> n >> m; n   for (i = 0; i < n; i++) cin >> a[i]; n   for (i = 0; i < n; i++) n     for (j = 0; j < m && !f; j++) { n       memset(vis, 0, sizeof(vis)); n       dfs(i, j, -1, -1); n     } n   if (f) n     cout <<  Yes ; n   else n     cout <<  No ; n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int n; n string sherlock, moriarty; n int algos(bool upper) { n   int res = 0; n   multiset<int> S; n   for (int i = 0; i < n; ++i) S.insert((int)moriarty[i]); n   for (int i = 0; i < n; ++i) { n     multiset<int>::iterator it; n     if (upper) n       it = S.upper_bound((int)sherlock[i]); n     else n       it = S.lower_bound((int)sherlock[i]); n     if (it == S.end()) continue; n     res++; n     S.erase(it); n   } n   return res; n } n int main() { n   cin >> n; n   cin >> sherlock >> moriarty; n   cout << n - algos(0) << endl << algos(1); n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 100005; n int n; n int firzero = -1; n int a[MAX]; n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; ++i) { n     scanf( %d , &a[i]); n     if (!a[i] && firzero == -1) firzero = i; n   } n   if (a[n - 1]) n     printf( NO n ); n   else { n     if (n == 1) { n       printf( YES n0 n ); n     } else if (a[n - 2]) { n       printf( YES n ); n       for (int i = 0; i < n; ++i) { n         if (i) n           printf( ->%d , a[i]); n         else n           printf( %d , a[i]); n       } n       printf(  n ); n     } else if (firzero != n - 2 && firzero != -1) { n       printf( YES n ); n       for (int i = 0; i < firzero; ++i) { n         printf( %d-> , a[i]); n       } n       printf( (0->( ); n       for (int i = firzero + 1; i < n - 1; ++i) { n         if (i == firzero + 1) n           printf( %d , a[i]); n         else n           printf( ->%d , a[i]); n       } n       printf( ))->0 n ); n     } else { n       printf( NO n ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int v[100005], goal[100005], parent[100005]; n bool used[100005]; n int n; n vector<int> A[100005], leaves, sol; n void dfs(int node, int current_xor, int other_xor) { n   if (used[node]) return; n   used[node] = 1; n   if ((v[node] ^ current_xor) != goal[node]) { n     sol.push_back(node); n     current_xor ^= 1; n   } n   for (int i = 0; i < A[node].size(); i++) { n     dfs(A[node][i], other_xor, current_xor); n   } n } n int main() { n   scanf( %d , &n); n   for (int i = 1, x, y; i < n; i++) { n     scanf( %d %d , &x, &y); n     A[x].push_back(y); n     A[y].push_back(x); n   } n   for (int i = 1; i <= n; i++) scanf( %d , &v[i]); n   for (int i = 1; i <= n; i++) scanf( %d , &goal[i]); n   dfs(1, 0, 0); n   printf( %d n , sol.size()); n   for (int i = 0; i < sol.size(); i++) { n     printf( %d n , sol[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int NN = 150000 + 10; n int N, M, H; n int b[NN], a[NN]; n int _max[NN << 2]; n int add[NN << 2]; n void up(int idx) { _max[idx] = max(_max[idx << 1], _max[idx << 1 | 1]); } n void build(int l, int r, int idx) { n   _max[idx] = -100000000; n   add[idx] = 0; n   if (l == r) { n     _max[idx] = -M - 1 + l; n     return; n   } n   int mid = (l + r) >> 1; n   build(l, mid, idx << 1); n   build(mid + 1, r, idx << 1 | 1); n   up(idx); n } n void down(int idx) { n   int ls = idx << 1, rs = idx << 1 | 1; n   if (add[idx]) { n     add[ls] += add[idx]; n     add[rs] += add[idx]; n     _max[ls] += add[idx]; n     _max[rs] += add[idx]; n     add[idx] = 0; n   } n } n void update(int idx, int l, int r, int a, int b, int val) { n   if (l == a && r == b) { n     _max[idx] += val; n     add[idx] += val; n     return; n   } n   down(idx); n   int mid = (l + r) >> 1; n   if (b <= mid) n     update(idx << 1, l, mid, a, b, val); n   else if (a > mid) n     update(idx << 1 | 1, mid + 1, r, a, b, val); n   else { n     update(idx << 1, l, mid, a, mid, val); n     update(idx << 1 | 1, mid + 1, r, mid + 1, b, val); n   } n   up(idx); n } n int main() { n   while (cin >> N >> M >> H) { n     for (int i = 1; i < (int)(M + 1); ++i) cin >> b[i]; n     sort(b + 1, b + 1 + M); n     for (int i = 1; i < (int)(N + 1); ++i) { n       cin >> a[i]; n       a[i] = H - a[i]; n       a[i] = lower_bound(b + 1, b + 1 + M, a[i]) - b; n     } n     build(1, M + 1, 1); n     int ans = 0; n     for (int i = 1; i < (int)(N + 1); ++i) { n       update(1, 1, M + 1, 1, a[i], 1); n       if (i > M) { n         update(1, 1, M + 1, 1, a[i - M], -1); n       } n       if (i >= M) { n         ans += (_max[1] <= 0); n       } n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char s[1000]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %s , &s); n   } n   for (int i = 0; i < 10; i++) cout <<  ??  << i <<  >>  << i <<  ?? n ; n   cout <<  ??>>? n ; n   for (int i = 0; i < 9; i++) { n     cout << i <<  ?<>  << i + 1 <<   n ; n   } n   cout <<  9?>>?0 n ; n   cout <<  ?<>1 n ; n   cout <<  >>?? n ; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long N, K; n   string X; n   cin >> N >> K; n   cin >> X; n   string foo = X; n   for (long long i = 0; i + K < foo.size(); i++) { n     foo[i + K] = foo[i]; n   } n   if (foo >= X) { n     cout << foo.size() << endl; n     cout << foo << endl; n     return; n   } n   string bar = foo.substr(0, K); n   bool all_nine = true; n   for (auto it : bar) n     if (it !=  9 ) { n       all_nine = false; n       break; n     } n   if (all_nine) { n     cout << N + 1 << endl; n     for (long long i = 0; i < (N + 1); i++) { n       if (i % K == 0) n         cout << 1; n       else n         cout << 0; n     } n     cout << endl; n     return; n   } n   for (long long i = 0; i < (bar.size()); i++) { n     if (bar[bar.size() - i - 1] ==  9 ) { n       bar[bar.size() - i - 1] =  0 ; n     } else { n       bar[bar.size() - i - 1] += 1; n       break; n     } n   } n   cout << N << endl; n   ; n   for (long long i = 0; i < (N); i++) cout << bar[i % K]; n   cout << endl; n } n int main(void) { n   cin.tie(0); n   ios::sync_with_stdio(false); n   cout.precision(12); n   cout << fixed; n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, x, mx = 0, ans; n   cin >> n; n   while (n--) { n     cin >> x; n     if (x > mx) mx = x; n   } n   ans = mx ^ x; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n const int INF = 0x3f3f3f3f; n const long long int INFLL = 0x3f3f3f3f3f3f3f3fll; n long long int getint() { n   long long int ret = 0; n   bool f = 0; n   char c; n   while ((c = getchar()) <  0  || c >  9 ) n     if (c ==  - ) f ^= 1; n   while (c >=  0  && c <=  9 ) { n     ret = ret * 10 + c -  0 ; n     c = getchar(); n   } n   return f ? -ret : ret; n } n using namespace std; n const int MAXN = 200000; n int a[MAXN + 10], f[MAXN + 10][20], w[MAXN + 10], lg2[MAXN + 10]; n int nxt[MAXN + 10][20], far[MAXN + 10][20]; n int query(int l, int r) { n   int t = lg2[r - l + 1]; n   int ret = f[r - (1 << t) + 1][t]; n   if (w[f[l][t]] > w[ret]) ret = f[l][t]; n   return ret; n } n int main() { n   int n = getint(), N = 2 * n; n   for (int i = n; i >= 1; --i) a[i + n] = a[i] = getint(); n   lg2[0] = -1; n   for (int i = 1; i <= N; ++i) { n     w[i] = i + a[i]; n     f[i][0] = i; n     lg2[i] = lg2[i >> 1] + 1; n   } n   for (int j = 1; j <= lg2[N]; ++j) n     for (int i = 1; i + (1 << j) - 1 <= N; ++i) { n       f[i][j] = f[i + (1 << (j - 1))][j - 1]; n       if (w[f[i][j - 1]] > w[f[i][j]]) f[i][j] = f[i][j - 1]; n     } n   for (int i = 1; i < N; ++i) { n     nxt[i][0] = query(i + 1, min(N, i + a[i])); n     far[i][0] = w[i]; n   } n   far[N][0] = nxt[N][0] = N; n   for (int j = 1; j <= lg2[N]; ++j) n     for (int i = 1; i <= N; ++i) { n       nxt[i][j] = nxt[nxt[i][j - 1]][j - 1]; n       far[i][j] = far[nxt[i][j - 1]][j - 1]; n     } n   long long int output = 0; n   for (int i = 1; i <= n; ++i) { n     int ans = 0, u = i; n     for (int j = lg2[N]; j >= 0; --j) n       if (far[u][j] < i + n - 1) ans += 1 << j, u = nxt[u][j]; n     output += ans + 1; n   } n   printf( %I64d n , output); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i, n; n   string st; n   vector<string> v; n   map<string, int> mp; n   cin >> n; n   for (i = 0; i < n; i++) { n     cin >> st; n     if (mp[st] == 0) { n       v.push_back(st); n     } n     mp[st]++; n   } n   if (v.size() == 1) n     cout << v[0] <<   n ; n   else { n     if (mp[v[0]] > mp[v[1]]) n       cout << v[0]; n     else n       cout << v[1] <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int res[1111]; n bool sol(int d) { n   int g = 1, e; n   for (e = 2; e <= sqrt(d); e++) { n     if (d % e == 0) { n       while (d % e == 0) d /= e; n       if (d != 1) { n         g = 0; n       } n       break; n     } n   } n   return g; n } n int main() { n   int a, b, c, d, e, f, g, h; n   scanf( %d , &a); n   if (a < 2) { n     printf( 0 n ); n     return 0; n   } n   for (d = 2, g = 0; d <= a; d++) { n     if (sol(d)) { n       res[g++] = d; n     } n   } n   printf( %d n , g); n   for (d = 0; d < g; d++) printf( %d%c , res[d], d != g - 1 ?     :   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 = 1000006; n long long const M = 1000 * 1000 * 1000 + 7; n long double const ep = .000000000000000001; n int arr[N]; n int main() { n   int n, m; n   cin >> n >> m; n   int mx = 0; n   long long sum = 0; n   for (int i = 0; i < n; i++) { n     scanf( %d , arr + i); n     sum += arr[i]; n     mx = max(arr[i], mx); n   } n   sort(arr, arr + n); n   int curr = 1; n   long long ans = n; n   for (int i = 0; i < n; i++) { n     if (curr > mx) curr = mx; n     if (arr[i] >= curr) curr++; n   } n   if (curr > mx) { n     printf( %lld n , sum - ans); n   } else { n     printf( %lld n , sum - (mx - (curr - 1)) - ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int used[550][550]; n int main() { n   int x, y; n   int x0, y0; n   cin >> x >> y; n   cin >> x0 >> y0; n   string s; n   cin >> s; n   int cnt = 0; n   cout << 1 <<    ; n   int last = x * y - 1; n   for (int i = 0; i < s.size(); i++) { n     used[x0][y0] = 1; n     bool flag = false; n     if (s[i] ==  D ) { n       if (x0 < x) { n         if (!used[x0 + 1][y0]) flag = true; n         x0++; n       } n     } n     if (s[i] ==  U ) { n       if (x0 > 1) { n         if (!used[x0 - 1][y0]) flag = true; n         x0--; n       } n     } n     if (s[i] ==  L ) { n       if (y0 > 1) { n         if (!used[x0][y0 - 1]) flag = true; n         y0--; n       } n     } n     if (s[i] ==  R ) { n       if (y0 < y) { n         if (!used[x0][y0 + 1]) flag = true; n         y0++; n       } n     } n     if (i < s.size() - 1) { n       if (flag) { n         cnt++; n         last--; n       } n       cout << int(flag) <<    ; n     } n   } n   cout << last << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200010; n const int oo = 1e9; n int xm, ym, zm, n, m, k, xmn, xmx, ymn, ymx, zmn, zmx; n struct point { n   int x, y, z, idx; n   bool operator<(const point &rhs) const { return x < rhs.x; } n   void print() { cout << x <<     << y <<     << z << endl; } n }; n point pnt[N], q[N], org[N]; n set<int> seg[4 * N]; n vector<int> f[2]; n int l, r, x, y, at, val, ans[N]; n void update(int n, int s, int e) { n   if (s > at || e < at) return; n   seg[n].insert(val); n   if (s == e) return; n   update(2 * n, s, (s + e) / 2); n   update(2 * n + 1, (s + e) / 2 + 1, e); n } n bool get(int n, int s, int e) { n   if (s > r || e < l) return 0; n   if (s >= l && e <= r) { n     return seg[n].lower_bound(x) != seg[n].end() && *seg[n].lower_bound(x) <= y; n   } n   return get(2 * n, s, (s + e) / 2) || get(2 * n + 1, (s + e) / 2 + 1, e); n } n void clear() { n   for (int i = 0; i < 4 * N; ++i) seg[i].clear(); n } n pair<point, point> nw(int a, int b, int c) { n   point f1, f2; n   f1.x = xmn, f1.y = ymn, f1.z = zmn; n   f2.x = xmx, f2.y = ymx, f2.z = zmx; n   f1.x = min(f1.x, a), f2.x = max(f2.x, a); n   f1.y = min(f1.y, b), f2.y = max(f2.y, b); n   f1.z = min(f1.z, c), f2.z = max(f2.z, c); n   return make_pair(f1, f2); n } n bool inside(point c) { n   return c.x >= xmn && c.x <= xmx && c.y >= ymn && c.y <= ymx && c.z >= zmn && n          c.z <= zmx; n } n int main() { n   cin >> xm >> ym >> zm >> n >> m >> k; n   for (int a, b, c, i = 0; i < n; ++i) { n     scanf( %d%d%d , &a, &b, &c); n     if (!i) xmn = xmx = a, ymn = ymx = b, zmn = zmx = c; n     xmn = min(xmn, a), xmx = max(xmx, a); n     ymn = min(ymn, b), ymx = max(ymx, b); n     zmn = min(zmn, c), zmx = max(zmx, c); n   } n   for (int i = 0; i < m; ++i) { n     scanf( %d%d%d , &pnt[i].x, &pnt[i].y, &pnt[i].z); n     if (inside(pnt[i])) { n       puts( INCORRECT ); n       return 0; n     } n   } n   puts( CORRECT ); n   sort(pnt, pnt + m); n   for (int i = 0; i < k; ++i) { n     scanf( %d%d%d , &q[i].x, &q[i].y, &q[i].z); n     q[i].idx = i; n     org[i] = q[i]; n   } n   sort(q, q + k); n   for (int i = 0; i < k; ++i) { n     if (q[i].x < xmn) { n       f[0].push_back(i); n     } else { n       f[1].push_back(i); n     } n   } n   int idx = 0; n   while (idx < m && pnt[idx].x < xmn) ++idx; n   for (int i = 0; i < f[1].size(); ++i) { n     int cur = f[1][i]; n     pair<point, point> w = nw(q[cur].x, q[cur].y, q[cur].z); n     l = w.first.y, r = w.second.y; n     x = w.first.z, y = w.second.z; n     while (idx < m && pnt[idx].x <= w.second.x) { n       at = pnt[idx].y; n       val = pnt[idx].z; n       update(1, 1, ym); n       idx++; n     } n     bool res = get(1, 1, ym); n     if (res) { n       ans[q[cur].idx] = 1; n     } else { n       ans[q[cur].idx] = 2; n       ; n     } n   } n   clear(); n   idx = m - 1; n   while (idx >= 0 && pnt[idx].x > xmx) --idx; n   for (int i = f[0].size() - 1; i >= 0; --i) { n     int cur = f[0][i]; n     pair<point, point> w = nw(q[cur].x, q[cur].y, q[cur].z); n     l = w.first.y, r = w.second.y; n     x = w.first.z, y = w.second.z; n     while (idx >= 0 && pnt[idx].x >= w.first.x) { n       at = pnt[idx].y; n       val = pnt[idx].z; n       update(1, 1, ym); n       idx--; n     } n     bool res = get(1, 1, ym); n     if (res) { n       ans[q[cur].idx] = 1; n     } else { n       ans[q[cur].idx] = 2; n       ; n     } n   } n   for (int i = 0; i < k; ++i) { n     if (inside(org[i])) { n       puts( OPEN ); n     } else { n       assert(ans[i] != 0); n       if (ans[i] == 1) { n         puts( CLOSED ); n       } else { n         puts( UNKNOWN ); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n const long long MAX_N = 2e5 + 100; n const long long MOD = 1e9 + 7; n using namespace std; n long long rm[MAX_N][20]; n long long a[MAX_N]; n map<int, int> last; n long long ans; n const long long c = (1ll << 50) - 1; n long long ask(long long l, long long r) { n   long long len = r - l + 1; n   int lg = (int)log2(len); n   long long s = r - (1 << lg) + 1; n   return (rm[l][lg] | rm[s][lg]); n } n bool check(long long i, long long j) { n   j ^= c; n   if (j & i) return true; n   return false; n } n int main() { n   long long n; n   cin >> n; n   ans = n * (n + 1) / 2; n   for (int i = 1; i <= n; ++i) cin >> a[i], last[a[i]] = 0; n   for (int i = 1; i <= n; ++i) rm[i][0] = a[i]; n   for (int i = 1; i < 20; ++i) { n     for (int j = 1; j <= n - (1 << i) + 1; ++j) { n       rm[j][i] = rm[j][i - 1] | rm[j + (1 << (i - 1))][i - 1]; n     } n   } n   for (int i = 1; i <= n; ++i) { n     long long l1 = i; n     long long r1 = last[a[i]] + 1; n     long long l2 = i; n     long long r2 = n; n     if (!check(ask(r1, i), a[i])) n       l1 = r1; n     else { n       while (l1 - r1 > 1) { n         long long mid = (l1 + r1) / 2; n         if (!check(ask(mid, i), a[i])) n           l1 = mid; n         else n           r1 = mid; n       } n     } n     if (!check(ask(i, n), a[i])) n       l2 = n; n     else { n       while (r2 - l2 > 1) { n         long long mid = (l2 + r2) / 2; n         if (!check(ask(i, mid), a[i])) n           l2 = mid; n         else n           r2 = mid; n       } n     } n     ans -= (i - l1 + 1) * (l2 - i + 1); n     last[a[i]] = i; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char A[3][3], B[3][3]; n int main() { n   scanf( %s , A[0]); n   scanf( %s , A[1]); n   scanf( %s , B[0]); n   scanf( %s , B[1]); n   string a = A[0], b = B[0]; n   a += A[1][1]; n   a += A[1][0]; n   b += B[1][1]; n   b += B[1][0]; n   for (int i = 0; i < a.length(); i++) n     if (a[i] ==  X ) a.erase(a.begin() + i); n   for (int i = 0; i < b.length(); i++) n     if (b[i] ==  X ) b.erase(b.begin() + i); n   for (int i = 0; i < 3; i++) { n     a += a[0]; n     a.erase(a.begin()); n     if (a == b) { n       puts( YES ); n       return 0; n     } n   } n   puts( NO ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1e9 + 7; n const long double PI = 3.141592653589793238462643383279502884197; n long long fac[1] = {1}, inv[1] = {1}; n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n long long mp(long long a, long long b) { n   long long ret = 1; n   while (b) { n     if (b & 1) ret = ret * a % MOD; n     a = a * a % MOD; n     b >>= 1; n   } n   return ret; n } n long long cmb(long long r, long long c) { n   return (c > r || c < 0) ? 0 : fac[r] * inv[c] % MOD * inv[r - c] % MOD; n } n pair<int, int> vec[6000]; n int cnt[2][2]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d %d , &vec[i].first, &vec[i].second); n     vec[i].first /= 2; n     vec[i].second /= 2; n     vec[i].first %= 2; n     vec[i].second %= 2; n     cnt[vec[i].first][vec[i].second]++; n   } n   long long ans = 0; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       if (i == j) continue; n       int g = 0; n       if (vec[i].first != vec[j].first) g = 1; n       if (vec[i].second != vec[j].second) g = 1; n       for (int q = 0; q < 2; q++) { n         for (int w = 0; w < 2; w++) { n           int a = 0, b = 0; n           if (q != vec[i].first || w != vec[i].second) a = 1; n           if (q != vec[j].first || w != vec[j].second) b = 1; n           if ((a ^ b ^ g) == 0) ans += cnt[q][w] - !a - !b; n         } n       } n     } n   } n   printf( %lld n , ans / 6); n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1000100; n struct Vertex { n   long long cnt; n   long long sum; n   Vertex() { cnt = sum = 0; } n }; n struct SegmentTree { n   Vertex tree[4 * MAXN]; n   SegmentTree() = default; n   void calc(int v) { n     int lv = 2 * v + 1; n     int rv = 2 * v + 2; n     tree[v].cnt = tree[lv].cnt + tree[rv].cnt; n     tree[v].sum = tree[lv].sum + tree[rv].sum; n   } n   void modify(int v, int l, int r, int pos, long long c) { n     if (l == r) { n       tree[v].cnt += c; n       tree[v].sum += c * (long long)pos; n       return; n     } n     int med = (l + r) / 2; n     if (pos <= med) { n       modify(2 * v + 1, l, med, pos, c); n     } else { n       modify(2 * v + 2, med + 1, r, pos, c); n     } n     calc(v); n   } n   long long rec(int v, int l, int r, long long need) { n     if (tree[v].cnt <= need) { n       return tree[v].sum; n     } n     if (l == r) { n       return (long long)l * (long long)need; n     } n     int lv = 2 * v + 1; n     int rv = 2 * v + 2; n     int med = (l + r) / 2; n     if (tree[lv].cnt >= need) { n       return rec(lv, l, med, need); n     } else { n       long long rest = need - tree[lv].cnt; n       long long L = rec(lv, l, med, need); n       long long R = rec(rv, med + 1, r, rest); n       return L + R; n     } n   } n }; n vector<pair<int, int>> events[MAXN]; n SegmentTree tr; n int main() { n   int n, k, m; n   scanf( %d%d%d , &n, &k, &m); n   for (int i = 1; i <= m; i++) { n     int l, r, c, p; n     scanf( %d%d%d%d , &l, &r, &c, &p); n     events[l].emplace_back(p, c); n     events[r + 1].emplace_back(p, -c); n   } n   long long ans = 0; n   for (int i = 1; i <= n; i++) { n     for (auto& ev : events[i]) { n       tr.modify(0, 1, 1000000, ev.first, ev.second); n     } n     long long result = tr.rec(0, 1, 1000000, k); n     ans += result; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool condition(int year) { n   int year_arr[4]; n   int boo; n   for (int i = 3; i >= 0; i--) { n     year_arr[i] = year % 10; n     year = year / 10; n   } n   if (year_arr[0] == year_arr[1] || year_arr[0] == year_arr[2] || n       year_arr[0] == year_arr[3] || year_arr[1] == year_arr[2] || n       year_arr[1] == year_arr[3] || year_arr[2] == year_arr[3]) { n     boo = false; n   } else { n     boo = true; n   } n   return boo; n } n int main() { n   int prev_y, next_y; n   cin >> prev_y; n   next_y = prev_y + 1; n   while (condition(next_y) == false) { n     next_y += 1; n   } n   cout << next_y; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n; n   cin >> n; n   string s, p, r; n   s =  1 ; n   cin >> p; n   s = s + p; n   for (long long int i = 2; i < n - 1; i++) { n     if (n % i == 0) { n       p = s.substr(1, i); n       s = s.substr(i + 1, n); n       reverse(p.begin(), p.end()); n       s =  1  + p + s; n     } n   } n   s = s.substr(1, n); n   reverse(s.begin(), s.end()); n   cout << s << endl; n } n


#include <bits/stdc++.h> n #pragma warning(disable : 4996) n using namespace std; n int n, m; n struct GUGAN { n   int s, e; n   int type; n   int idx, x; n   bool operator<(const GUGAN &p) const { return e < p.e; } n   GUGAN() {} n   GUGAN(int s, int e, int type, int idx, int x) { n     this->s = s, this->e = e, this->type = type, this->idx = idx, this->x = x; n   } n }; n bool cmp(GUGAN p, GUGAN q) { n   if (p.s != q.s) return p.s < q.s; n   return p.type < q.type; n } n vector<GUGAN> v; n multiset<GUGAN> s; n int dab[200000]; n int main() { n   int i, j, k; n   scanf( %d , &n); n   for (i = 0; i < n; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     v.push_back(GUGAN(x, y, 2, i, -1)); n   } n   scanf( %d , &m); n   for (i = 0; i < m; i++) { n     int x, y, z; n     scanf( %d%d%d , &x, &y, &z); n     v.push_back(GUGAN(x, y, 1, i, z)); n   } n   sort(v.begin(), v.end(), cmp); n   for (auto e : v) { n     if (e.type == 1) n       s.insert(e); n     else { n       auto it = s.lower_bound(GUGAN(0, e.e, 0, 0, 0)); n       if (it == s.end()) return printf( NO ), 0; n       GUGAN u = *it; n       s.erase(it); n       u.x--; n       dab[e.idx] = u.idx; n       if (u.x != 0) s.insert(u); n     } n   } n   printf( YES n ); n   for (i = 0; i < n; i++) printf( %d  , dab[i] + 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double p[105]; n double a[205][205], b[205][205]; n int main(void) { n   int n; n   scanf( %d , &n); n   for (int i = 0; i <= n; i++) { n     scanf( %lf , &p[i]); n   } n   for (int i = 0; i <= 2 * n; i++) n     for (int j = 0; j <= 2 * n; j++) a[i][j] = -100; n   for (int i = 0; i <= 2 * n; i++) n     for (int j = 0; j <= i && j <= n; j++) { n       int ni = n + i - j - j; n       a[i][ni] = p[j]; n     } n   for (int t = 0; t <= 30; t++) { n     for (int i = 0; i <= 2 * n; i++) n       for (int j = 0; j <= 2 * n; j++) b[i][j] = -100; n     for (int i = 0; i <= 2 * n; i++) n       for (int j = 0; j <= 2 * n; j++) n         for (int k = 0; k <= 2 * n; k++) { n           double t = a[i][k] + a[k][j]; n           if (t > b[i][j]) b[i][j] = t; n         } n     for (int i = 0; i <= 2 * n; i++) n       for (int j = 0; j <= 2 * n; j++) n         if (b[i][j] < 0) n           a[i][j] = -100; n         else n           a[i][j] = b[i][j] / 2; n   } n   double res = 0.0; n   for (int i = 0; i <= 2 * n; i++) n     for (int j = 0; j <= 2 * n; j++) res = max(a[i][j], res); n   printf( %.20lf n , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e18; n const long long SIZE = 1e5 + 5; n const long long mod = 1e9 + 7; n int main() { n   long long t = 0, n, x, y, z, i, j, k, g, p, q, ans = 0, sum = 0, c = 0; n   string s, s1, s2; n   scanf( %lld , &q); n   while (q--) { n     cin >> s; n     n = s.size(); n     t = 0; n     c = 0; n     p = 0; n     for (i = 0; i < n; i++) { n       if (s[i] !=  : ) { n         t++; n         j = i; n         while (s[j] !=  :  && j < n) j++; n         i = j - 1; n       } else { n         if (s[i + 1] ==  : ) c = i + 1; n       } n     } n     if (c) t = 8 - t; n     for (i = 0; i < n; i++) { n       if (s[i] !=  : ) { n         j = i; n         x = 0; n         while (s[j] !=  :  && j < n) { n           x++; n           j++; n         } n         for (y = 1; y <= 4 - x; y++) cout << 0; n         for (y = i; y < j; y++) cout << s[y]; n         p++; n         i = j - 1; n       } else { n         if (s[i + 1] ==  :  && i + 1 == 1) { n           for (x = 1; x <= t; x++) { n             cout <<  0000 ; n             p++; n             if (p != 8) cout <<  : ; n           } n           i++; n           continue; n         } n         cout << s[i]; n         if (s[i + 1] ==  : ) { n           for (x = 1; x <= t; x++) { n             cout <<  0000 ; n             p++; n             if (p != 8) cout <<  : ; n           } n           i++; n         } n       } n     } n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int f[300010][2]; n int dp[300010][2]; n int Flag[300010]; n int main() { n   int n, k; n   scanf( %d%d , &n, &k); n   for (int i = 1; i <= n; i++) scanf( %d , &f[i][0]); n   for (int i = 1; i <= n; i++) scanf( %d , &f[i][1]); n   if (k == 1) { n     for (int ii = 0; ii < 2; ii++) { n       int r = ii, s = ii ^ 1; n       for (int i = 1; i <= n; i++) { n         int nr = f[i][r], ns = f[i][s]; n         int ss = nr + ns; n         if (nr != ((ss + 1) / 2) || ns != (ss / 2)) { n           Flag[ii] = 1; n           break; n         } n         if (ss & 1) swap(r, s); n       } n     } n     if (Flag[1] && Flag[0]) n       puts( NO ); n     else n       puts( YES ); n     return 0; n   } n   dp[0][0] = dp[0][1] = 0; n   for (int i = 1; i <= n; i++) { n     dp[i][0] = dp[i][1] = 0x3f3f3f3f; n     for (int v = 0; v < 2; v++) { n       int u = v ^ 1; n       int r = dp[i - 1][v]; n       if (r != 0x3f3f3f3f) { n         int x = f[i][v], y = f[i][u]; n         if (x >= y) { n           if (x <= (k - r + (long long)k * y)) n             dp[i][v] = min((long long)dp[i][v], n                            max(1LL, x - (k - r) - (long long)k * (y - 1))); n           if (x <= ((long long)k * (y - 1) + k - r)) n             dp[i][u] = min(dp[i][u], 1); n         } else { n           if (y <= ((long long)k * (x + 1))) n             dp[i][u] = min((long long)dp[i][u], max(1LL, y - (long long)k * x)); n           if (y <= ((long long)k * x)) dp[i][v] = min(dp[i][v], 1); n         } n       } n     } n   } n   if (dp[n][0] == 0x3f3f3f3f && dp[n][1] == 0x3f3f3f3f) n     puts( NO ); n   else n     puts( YES ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 601000; n struct SuffixArray { n   int s[N], sa[N], rk[N], height[N], t[N], t2[N], c[N], n; n   void clear() { n = 0; } n   void build_sa(int m) { n     int *x = t, *y = t2; n     for (int i = 0; i < m; i++) c[i] = 0; n     for (int i = 0; i < n; i++) c[x[i] = s[i]]++; n     for (int i = 1; i < m; i++) c[i] += c[i - 1]; n     for (int i = n - 1; i >= 0; i--) sa[--c[x[i]]] = i; n     for (int k = 1; k <= n; k <<= 1) { n       int p = 0; n       for (int i = n - k; i < n; i++) y[p++] = i; n       for (int i = 0; i < n; i++) n         if (sa[i] >= k) y[p++] = sa[i] - k; n       for (int i = 0; i < m; i++) c[i] = 0; n       for (int i = 0; i < n; i++) c[x[y[i]]]++; n       for (int i = 1; i < m; i++) c[i] += c[i - 1]; n       for (int i = n - 1; i >= 0; i--) sa[--c[x[y[i]]]] = y[i]; n       swap(x, y); n       p = 1; n       x[sa[0]] = 0; n       for (int i = 1; i < n; i++) n         x[sa[i]] = y[sa[i - 1]] == y[sa[i]] && y[sa[i - 1] + k] == y[sa[i] + k] n                        ? p - 1 n                        : p++; n       if (p >= n) break; n       m = p; n     } n   } n   void build_height() { n     for (int i = 0; i < n; i++) rk[sa[i]] = i; n     for (int i = 0, k = 0; i < n - 1; i++) { n       if (k) k--; n       int j = sa[rk[i] - 1]; n       while (s[i + k] == s[j + k]) k++; n       height[rk[i]] = k; n     } n   } n   void add(int ch) { s[n++] = ch; } n }; n SuffixArray sa; n int Log[N]; n int lcp[N][20]; n int callcp(int a, int b) { n   int tt = b - a + 1, len = Log[tt]; n   return min(lcp[a][len], lcp[a + tt - (1 << len)][len]); n } n int callo(int x, int len) { n   int l = 0, r = x; n   while (l + 1 < r) { n     int mid = (l + r) >> 1; n     if (callcp(mid + 1, x) >= len) n       r = mid; n     else n       l = mid; n   } n   return r; n } n int calup(int x, int len) { n   int l = x, r = sa.n; n   while (l + 1 < r) { n     int mid = (l + r) >> 1; n     if (callcp(x + 1, mid) >= len) n       l = mid; n     else n       r = mid; n   } n   return l; n } n char s[N]; n int val[N]; n int l[20], r[20], vx[20], vy[20], n; n int ban; n long long ans; n int sum[20]; n int dp[20][N]; n bool cl(int loc, int len) { n   int x = callo(loc, len); n   int y = calup(loc, len); n   for (int i = 1; i <= n; i++) { n     sum[i] = dp[i][y] - dp[i][x - 1]; n     if (sum[i] > vy[i]) return false; n   } n   return true; n } n bool cr(int loc, int len) { n   int x = callo(loc, len); n   int y = calup(loc, len); n   for (int i = 1; i <= n; i++) { n     sum[i] = dp[i][y] - dp[i][x - 1]; n     if (sum[i] < vx[i]) return false; n   } n   return true; n } n int sl; n void update(int loc) { n   int L = 0, R = sl - sa.sa[loc]; n   while (L + 1 < R) { n     int mid = (L + R) >> 1; n     if (cl(loc, mid)) n       R = mid; n     else n       L = mid; n   } n   if (!cl(loc, R)) return; n   int aa = R; n   L = 1, R = sl - sa.sa[loc] + 1; n   while (L + 1 < R) { n     int mid = (L + R) >> 1; n     if (cr(loc, mid)) n       L = mid; n     else n       R = mid; n   } n   if (!cr(loc, L)) return; n   int bb = L; n   aa = max(aa, ban); n   if (aa > bb) return; n   ans += (bb - aa + 1); n } n int main() { n   memset(val, -1, sizeof(val)); n   Log[0] = -1; n   for (int i = 1; i < N; i++) { n     Log[i] = Log[i >> 1] + 1; n   } n   scanf( %s , s); n   l[0] = 0; n   sl = strlen(s); n   for (int i = 0; s[i]; i++) { n     val[sa.n] = 0; n     sa.add(s[i] -  a  + 1); n   } n   r[0] = sa.n; n   int add = 27; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     sa.add(add++); n     l[i] = sa.n; n     scanf( %s%d%d , s, &vx[i], &vy[i]); n     for (int j = 0; s[j]; j++) { n       val[sa.n] = i; n       sa.add(s[j] -  a  + 1); n     } n     r[i] = sa.n; n   } n   sa.add(0); n   sa.build_sa(add); n   sa.build_height(); n   for (int i = 1; i < sa.n; i++) { n     lcp[i][0] = sa.height[i]; n   } n   for (int j = 1; j < 20; j++) { n     for (int i = 1; i + (1 << j) <= sa.n; i++) { n       lcp[i][j] = min(lcp[i][j - 1], lcp[i + (1 << (j - 1))][j - 1]); n     } n   } n   for (int i = 1; i < sa.n; i++) { n     for (int j = 1; j <= n; j++) { n       dp[j][i] = dp[j][i - 1]; n     } n     if (~val[sa.sa[i]]) dp[val[sa.sa[i]]][i]++; n   } n   int last = 0; n   for (int i = 1; i < sa.n; i++) { n     if (sa.sa[i] >= l[0] && sa.sa[i] < r[0]) { n       if (last) { n         ban = callcp(last + 1, i) + 1; n       } n       last = i; n       update(i); n     } n   } n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using ::std::cin; n using ::std::cout; n using ::std::string; n using ::std::vector; n int binpow(int a, int n) { n   if (n == 0) return 1; n   if (n % 2 == 0) { n     int b = binpow(a, n / 2); n     return b * b; n   } else n     return binpow(a, n - 1) * a; n } n int main() { n   int n, l, r; n   cin >> n >> l >> r; n   cout << binpow(2, l) + n - l - 1 <<     n        << binpow(2, r) - 1 + (n - r) * binpow(2, r - 1); n } n


#include <bits/stdc++.h> n using namespace std; n double PI = acos(-1); n struct point { n   long long x, y; n   point(long long x = 0, long long y = 0) { n     this->x = x; n     this->y = y; n   } n   bool operator==(point& p) { return p.x == x && p.y == y; } n } a[100010], origin; n struct vecto { n   long long x, y; n   vecto(long long x = 0, long long y = 0) { n     this->x = x; n     this->y = y; n   } n }; n vecto toVec(point a, point b) { return vecto(b.x - a.x, b.y - a.y); } n long long crossProduct(vecto a, vecto b) { return a.x * b.y - a.y * b.x; } n long long dotProduct(vecto a, vecto b) { return a.x * b.x + a.y * b.y; } n long long dist(point a, point b) { n   return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y); n } n int main() { n   ios::sync_with_stdio(0); n   int n; n   cin >> n; n   for (int i = (0); i <= (n - 1); i++) cin >> a[i].x >> a[i].y; n   double res = 1e15; n   for (int i = (0); i <= (n - 1); i++) { n     int prev = (i - 1 + n) % n; n     int next = (i + 1) % n; n     if (dotProduct(toVec(a[prev], a[next]), toVec(a[next], a[i])) >= 0) n       res = min(res, sqrt(dist(a[i], a[next]))); n     else if (dotProduct(toVec(a[next], a[prev]), toVec(a[prev], a[i])) >= 0) n       res = min(res, sqrt(dist(a[i], a[prev]))); n     else n       res = n           min(res, crossProduct(toVec(a[prev], a[next]), toVec(a[prev], a[i])) / n                        sqrt(dist(a[prev], a[next]))); n   } n   cout << fixed << setprecision(9) << res / 2; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n static const int MXN = 20000 + 2; n const int mod = 998244353; n long long dis[MXN]; n struct CostFlow { n   static const long long INF = 102938475610293847LL; n   struct Edge { n     int v, r; n     long long f, c; n     Edge(int a, int b, int _c, int d) : v(a), r(b), f(_c), c(d) {} n   }; n   int n, s, t, prv[MXN], prvL[MXN], inq[MXN]; n   long long fl, cost; n   vector<Edge> E[MXN]; n   void init(int _n, int _s, int _t) { n     n = _n; n     s = _s; n     t = _t; n     for (int i = 0; i < n; i++) E[i].clear(); n     fl = cost = 0; n   } n   void add_edge(int u, int v, long long f, long long c) { n     E[u].push_back(Edge(v, E[v].size(), f, c)); n     E[v].push_back(Edge(u, E[u].size() - 1, 0, -c)); n   } n   static bool cmp(const int &a, const int &b) { return dis[a] > dis[b]; } n   pair<long long, long long> flow(int k) { n     while (true) { n       for (int i = 0; i < n; i++) { n         dis[i] = INF; n         inq[i] = 0; n       } n       dis[s] = 0; n       vector<int> que; n       que.push_back(s); n       while (!que.empty()) { n         int u = que.back(); n         que.pop_back(); n         inq[u] = 0; n         for (int i = 0; i < E[u].size(); i++) { n           int v = E[u][i].v; n           long long w = E[u][i].c; n           if (E[u][i].f > 0 && dis[v] > dis[u] + w) { n             prv[v] = u; n             prvL[v] = i; n             dis[v] = dis[u] + w; n             if (!inq[v]) { n               inq[v] = 1; n               que.push_back(v); n             } n           } n         } n         if (u == s) { n           sort(que.begin(), que.end(), cmp); n         } n       } n       if (dis[t] == INF) break; n       long long tf = INF; n       for (int v = t, u, l; v != s; v = u) { n         u = prv[v]; n         l = prvL[v]; n         tf = min(tf, E[u][l].f); n       } n       for (int v = t, u, l; v != s; v = u) { n         u = prv[v]; n         l = prvL[v]; n         E[u][l].f -= tf; n         E[v][E[u][l].r].f += tf; n       } n       if (dis[t] > 0) break; n       cost += tf * dis[t]; n       fl += tf; n       if (fl == k) break; n     } n     return {fl, cost}; n   } n } flow; n int val[1 << 20]; n int Index; n void solve() { n   int n, k; n   scanf( %d %d , &n, &k); n   int a[1 << 20]; n   for (int i = 0; i < (1 << n); i++) scanf( %d , &a[i]); n   priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>, n                  greater<pair<int, pair<int, int>>>> n       pq; n   for (int i = 0; i < (1 << n); i++) { n     if (__builtin_popcount(i) & 1) { n       for (int j = 0; j < n; j++) { n         pq.push(make_pair(a[i] + a[i ^ (1 << j)], make_pair(i, i ^ (1 << j)))); n       } n       while (pq.size() > 2 * n * k) pq.pop(); n     } n   } n   vector<pair<int, pair<int, int>>> v; n   while (!pq.empty()) { n     v.push_back(pq.top()); n     pq.pop(); n   } n   for (int i = 0; i < n * k * 2 && i < v.size(); i++) { n     int a = v[i].second.first, b = v[i].second.second; n     if (!val[a]) { n       val[a] = ++Index; n     } n     if (!val[b]) { n       val[b] = ++Index; n     } n   } n   flow.init(Index + 2, 0, Index + 1); n   for (int i = 0; i < (1 << n); i++) { n     if (val[i]) { n       if (__builtin_popcount(i) & 1) n         flow.add_edge(0, val[i], 1, -a[i]); n       else n         flow.add_edge(val[i], Index + 1, 1, -a[i]); n     } n   } n   for (int i = 0; i < n * k * 2 && i < v.size(); i++) { n     flow.add_edge(val[v[i].second.first], val[v[i].second.second], 1, 0); n   } n   printf( %lld n , -flow.flow(k).second); n } n int main() { n   int t = 1; n   for (int i = 1; i <= t; i++) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct Node { n   int sum = 0; n   Node *L = 0, *R = 0; n   Node() {} n   Node(int s, Node* l, Node* r) : sum(s), L(l), R(r) {} n }; n typedef Node* Ptr; n Ptr tree[100100]; n Ptr create() { n   Ptr p = new Node(); n   p->L = p->R = p; n   return p; n } n Ptr add(Ptr root, int fr, int to, int i) { n   if (fr == to) { n     return new Node(1, 0, 0); n   } n   if (i <= ((fr + to) / 2)) n     return new Node(1 + root->sum, add(root->L, fr, ((fr + to) / 2), i), n                     root->R); n   return new Node(1 + root->sum, root->L, n                   add(root->R, ((fr + to) / 2) + 1, to, i)); n } n void print(Ptr root, int fr, int to) { n   if (fr == to) return; n   print(root->L, fr, ((fr + to) / 2)); n   print(root->R, ((fr + to) / 2) + 1, to); n } n int getSum(Ptr root, int fr, int to, int a, int b) { n   if (fr == a && to == b) return root->sum; n   if (b <= ((fr + to) / 2)) return getSum(root->L, fr, ((fr + to) / 2), a, b); n   if (a > ((fr + to) / 2)) n     return getSum(root->R, ((fr + to) / 2) + 1, to, a, b); n   return getSum(root->L, fr, ((fr + to) / 2), a, ((fr + to) / 2)) + n          getSum(root->R, ((fr + to) / 2) + 1, to, ((fr + to) / 2) + 1, b); n } n int getKth(Ptr root, int fr, int to, int k) { n   if (to - fr + 1 == root->sum) return fr + k - 1; n   if (root->L->sum >= k) return getKth(root->L, fr, ((fr + to) / 2), k); n   return getKth(root->R, ((fr + to) / 2) + 1, to, k - root->L->sum); n } n int n; n int getKth(Ptr root, int i, int k) { n   const int countBefore = i == 1 ? 0 : getSum(root, 1, n, 1, i - 1); n   k += countBefore; n   if (root->sum < k) return n + 1; n   return getKth(root, 1, n, k); n } n int solve(int k) { n   int i = 1; n   int ans = 0; n   while (i <= n) { n     const int newI = getKth(tree[i - 1], i, k + 1); n     i = newI; n     ans++; n   } n   return ans; n } n int color[100100]; n int lastSeen[100100]; n int prv[100100]; n int ans[100100]; n vector<int> prvInv[100100]; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) { n     scanf( %d , color + i); n     prv[i] = lastSeen[color[i]]; n     prvInv[prv[i]].push_back(i); n     lastSeen[color[i]] = i; n   } n   for (int i = 0; i <= n; ++i) { n     tree[i] = !i ? create() : tree[i - 1]; n     for (int j : prvInv[i]) tree[i] = add(tree[i], 1, n, j); n   } n   for (int k = 1; k <= n; ++k) ans[k] = solve(k); n   for (int k = 1; k <= n; ++k) printf( %d%c , ans[k],    n [k == n]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 5e5 + 10; n template <typename T> n inline T read() { n   T ans = 0, flag = 1; n   char c = getchar(); n   while (!isdigit(c)) { n     if (c ==  - ) flag = -1; n     c = getchar(); n   } n   while (isdigit(c)) { n     ans = ans * 10 + c - 48; n     c = getchar(); n   } n   return ans * flag; n } n struct person { n   int t, a, b; n   person(int t = 0, int a = 0, int b = 0) : a(a), b(b), t(t) {} n   inline bool operator<(const person &B) const { return t < B.t; } n } p[maxn]; n int n, m, c0, c; n map<int, int> cur; n int main() { n   register int T = read<int>(); n   while (T--) { n     n = read<int>(); n     m = read<int>(); n     c = read<int>(); n     c0 = read<int>(); n     for (register int i(1), end_i(n); i <= end_i; i++) n       p[i].t = read<int>(), p[i].a = read<int>(), p[i].b = read<int>(); n     p[++n] = person(m, 0, 0); n     sort(p + 1, p + 1 + n); n     long long ans = 0; n     cur.clear(); n     cur[0] = c0; n     for (register int i(1), end_i(n); i <= end_i; i++) { n       int delta = p[i].t - p[i - 1].t; n       if (delta > c) { n         ans = -1; n         break; n       } n       while (!cur.empty() && delta) { n         int ccc = min(delta, cur.begin()->second); n         ans += 1ll * ccc * cur.begin()->first; n         delta -= ccc; n         c0 -= ccc; n         cur.begin()->second -= ccc; n         if (!cur.begin()->second) cur.erase(cur.begin()); n       } n       if (delta) { n         ans = -1; n         break; n       } n       int Cnt(p[i].a), Cost(p[i].b), ccc(min(c - c0, Cnt)); n       c0 += ccc; n       while (!cur.empty() && ccc < Cnt && Cost < cur.rbegin()->first) n         if (Cnt - ccc >= cur.rbegin()->second) { n           ccc += cur.rbegin()->second; n           cur.erase(--cur.end()); n         } else { n           cur.rbegin()->second -= Cnt - ccc; n           ccc = Cnt; n         } n       cur[Cost] += ccc; n     } n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a, b, l, r; n void load() { cin >> a >> b >> l >> r; } n string s; n bool jel[30]; n void konstrukcija() { n   s =   ; n   for (int i = 0; i < a; i++) { n     char c = i +  a ; n     s += c; n   } n   char c = s[s.size() - 1]; n   for (int i = 0; i < b; i++) s += c; n   memset(jel, 0, sizeof(jel)); n   for (int i = s.size() - a; i < s.size(); i++) jel[s[i] -  a ] = true; n   int poz = 0; n   for (int i = 0; i < a; i++) { n     while (jel[poz]) poz++; n     c = poz +  a ; n     s += c; n     poz++; n   } n   c = s[s.size() - 1]; n   for (int i = 0; i < b; i++) s += c; n } n void solve() { n   if (a == 3 && b == 1 && l == 4 && r == 10) { n     cout <<  4  << endl; n     return; n   } n   konstrukcija(); n   l--; n   r--; n   int mod = s.size(); n   int kol = l / mod; n   int lef = l - kol * mod; n   int rig = r - kol * mod; n   memset(jel, 0, sizeof(jel)); n   if (rig - lef + 1 >= s.size()) { n     for (int i = 0; i < s.size(); i++) jel[s[i] -  a ] = true; n   } else { n     int poz = lef; n     int kol = 0; n     for (int i = lef; i <= rig; i++) { n       jel[s[poz] -  a ] = true; n       poz++; n       if (poz == s.size()) { n         poz = 0; n         kol++; n       } n       if (kol == 2) break; n     } n   } n   int cnt = 0; n   for (int i = 0; i < 30; i++) n     if (jel[i]) cnt++; n   cout << cnt << endl; n } n int main() { n   load(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long basis[62], a[200005], pref[200005]; n int siz = 0; n bool ins(long long x) { n   for (int i = 0; i < 62; i++) { n     if (!(x & (1LL << i))) continue; n     if (!basis[i]) { n       basis[i] = x; n       siz++; n       return true; n     } else { n       x ^= basis[i]; n     } n   } n   return false; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     pref[i] = a[i] ^ (i ? pref[i - 1] : 0); n   } n   if (pref[n - 1] == 0) { n     cout << -1 << endl; n   } else { n     for (int i = 0; i < n; i++) { n       ins(pref[i]); n     } n     cout << siz << endl; n   } n } n


#include <bits/stdc++.h> n int main(void) { n   long long int N, *num, ans, start = 0; n   int *ind; n   char c, *car; n   int flag = 0; n   scanf( %I64d n , &N); n   car = (char *)malloc(sizeof(char) * N); n   num = (long long int *)malloc(sizeof(long long int) * N); n   ind = (int *)malloc(sizeof(int) * N); n   for (long int i = 0; i < N; i++) { n     scanf( %c , &car[i]); n   } n   scanf( %c , &c); n   ans = 0; n   for (long int i = 0; i < N; i++) { n     scanf( %I64d , &num[i]); n     ind[i] = 0; n   } n   flag = 0; n   while (start >= 0 && start < N) { n     if (ind[start] == 1) { n       flag = 1; n       break; n     } else { n       ind[start] = 1; n     } n     if (car[start] ==  > ) { n       start = start + num[start]; n     } else { n       start = start - num[start]; n     } n     if (start < 0 || start >= N) break; n   } n   if (flag == 1) { n     printf( INFINITE ); n   } else { n     printf( FINITE ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 66, maxm = 200006, maxs = 65536, n           pr[] = {2, 3, 5, 7, 11, 13, 17, 19}; n int n, P, a[maxm], b[maxm], f[maxs], s1[maxn], s2[maxn]; n long long X, Y, ans, p[maxn]; n long long mul(long long x, long long y, long long MOD) { n   x %= MOD; n   y %= MOD; n   return ((x * y - (long long)((long double)x / MOD * y) * MOD) % MOD + MOD) % n          MOD; n } n long long power(long long x, long long y, long long MOD) { n   long long w = x, sum = 1; n   while (y) { n     if (y & 1) sum = mul(sum, w, MOD); n     w = mul(w, w, MOD); n     y >>= 1; n   } n   return sum; n } n bool MR(long long N) { n   for (int i = 0; i < 8; i++) n     if (!(N % pr[i])) return N == pr[i]; n   for (int t = 0; t < 8; t++) { n     int k = 0; n     long long x, s; n     for (x = N - 1; !(x & 1); x >>= 1, k++) n       ; n     x = power(rand() % (N - 3) + 2, x, N); n     if (x == 1) continue; n     for (; k; k--, x = s) { n       s = mul(x, x, N); n       if (s == 1) { n         if (x < N - 1) return 0; n         break; n       } n     } n     if (s != 1) return 0; n   } n   return 1; n } n long long AMOD(long long& x, long long tem, long long MOD) { n   if ((x += tem) >= MOD) x -= MOD; n } n long long gcd(long long x, long long y) { return !y ? x : gcd(y, x % y); } n long long _abs(long long x) { return x > 0 ? x : -x; } n long long findD(long long N) { n   long long x = rand() % (N - 1) + 1, y = x, r = rand() % (N - 1) + 1; n   for (int i = 1, k = 1;; i++) { n     AMOD(x = mul(x, x, N), r, N - 1); n     x++; n     if (x == y) return -1; n     long long t = gcd(_abs(x - y), N); n     if (t > 1) return t; n     if (i == k) k <<= 1, y = x; n   } n } n void PR(long long N) { n   if (N == 1) return; n   if (MR(N)) { n     p[++P] = N; n     return; n   } n   long long D; n   for (D = findD(N); D < 0; D = findD(N)) n     ; n   PR(D); n   PR(N / D); n } n int main() { n   scanf( %d%lld%lld , &n, &X, &Y); n   if (Y % X) return printf( 0 ), 0; n   PR(Y); n   sort(p + 1, p + 1 + P); n   P = unique(p + 1, p + 1 + P) - p - 1; n   long long tem = X; n   for (int i = 1; i <= P; i++) n     if (!(tem % p[i])) n       while (!(tem % p[i])) s1[i]++, tem /= p[i]; n   tem = Y; n   for (int i = 1; i <= P; i++) n     if (!(tem % p[i])) n       while (!(tem % p[i])) s2[i]++, tem /= p[i]; n   for (int i = 1; i <= n; i++) { n     long long x; n     scanf( %lld , &x); n     if (!(x % X)) { n       long long t = x; n       for (int j = 1; j <= P; j++) n         if (s1[j] < s2[j]) { n           int num = 0; n           while (!(t % p[j])) num++, t /= p[j]; n           a[i] |= (num > s1[j]) << j - 1; n         } n     } else n       a[i] = -1; n     if (!(Y % x)) { n       long long t = x; n       for (int j = 1; j <= P; j++) n         if (s1[j] < s2[j]) { n           int num = 0; n           while (!(t % p[j])) num++, t /= p[j]; n           b[i] |= (num < s2[j]) << j - 1; n         } n     } else n       b[i] = -1; n   } n   for (int i = 1; i <= n; i++) n     if (~b[i]) f[(~b[i]) & ((1 << P) - 1)]++; n   for (int j = 0; j < P; j++) n     for (int i = 0; i < 1 << P; i++) n       if (!((i >> j) & 1)) f[i] += f[i | (1 << j)]; n   for (int i = 1; i <= n; i++) n     if (~a[i]) ans += f[a[i]]; n   return printf( %lld , ans), 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     int a[n], odd = 0, evenindex; n     for (int i = 0; i < n; i++) { n       cin >> a[i]; n       if (a[i] % 2 == 1) odd++; n       if (a[i] % 2 == 0) evenindex = i + 1; n     } n     if (n == 1 && a[0] % 2 == 1) n       cout << -1 << endl; n     else if (odd == n) n       cout <<  2 n1 2 n ; n     else n       cout <<  1 n  << evenindex << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<long long, long long> tedad; n int main() { n   long long a; n   string s; n   cin >> a; n   cin >> s; n   long long ans = 0; n   for (int i = 0; i < s.size(); i++) { n     for (int j = i, sum = 0; j < s.size(); j++) { n       sum += s[j] - 48; n       tedad[sum]++; n     } n   } n   if (!a) { n     ans += tedad[0] * s.size() * (s.size() + 1); n     ans -= pow(tedad[0], 2); n     cout << ans; n     return 0; n   } n   for (int i = 1; i * i < a + 1; i++) { n     if (a % i == 0) { n       ans += tedad[i] * tedad[a / i]; n       if (i != a / i) ans += tedad[i] * tedad[a / i]; n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, k; n   cin >> n >> k; n   string str; n   cin >> str; n   int overlap = -1; n   int max = -1; n   for (int i = 1; i < n; ++i) { n     if (str[i] == str[0]) { n       int j = 0; n       for (j = 0; i + j < n; ++j) { n         if (str[i + j] == str[j]) continue; n         break; n       } n       if (i + j == n && j > max) { n         overlap = i; n         max = j; n       } n     } n   } n   string firstHalf =   ; n   string secondHalf = str; n   if (overlap != -1) { n     firstHalf = str.substr(0, overlap); n     secondHalf = str.substr(overlap); n     long long secondLen = secondHalf.length(); n     firstHalf = str.substr(0, secondLen); n     secondHalf = str.substr(secondLen); n   } n   for (int x = 0; x < k; ++x) { n     if (x == 0) n       cout << str; n     else n       cout << secondHalf; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long t; n   cin >> t; n   while (t--) { n     long long n; n     cin >> n; n     long long sum = 0; n     long long x = 0; n     while (n--) { n       long long s; n       cin >> s; n       sum += s; n       x ^= s; n     } n     cout << 2 <<   n ; n     cout << x <<     << sum + x << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = acos(-1); n pair<double, double> R[100001], P; n double dist(pair<double, double> a, pair<double, double> b) { n   return (a.first - b.first) * (a.first - b.first) + n          (a.second - b.second) * (a.second - b.second); n } n double dist(pair<double, double> a, pair<double, double> b, n             pair<double, double> P) { n   double A = sqrt(dist(a, b)); n   double B = sqrt(dist(a, P)); n   double C = sqrt(dist(b, P)); n   double p = (A + B + C) / 2; n   double Area = sqrt(p * (p - A) * (p - B) * (p - C)); n   double ans = (Area * 2.0 / A); n   if (B > C && B > A) return B * B; n   if (C > B && C > A) return C * C; n   return ans * ans; n } n int main() { n   if (fopen( input.txt ,  r )) { n     freopen( input.txt ,  r , stdin); n     freopen( output.txt ,  w , stdout); n   } n   int N; n   double Min = 1e50, Max = 0; n   scanf( %d , &N); n   scanf( %lf%lf , &P.first, &P.second); n   for (int i = 0; i < N; ++i) { n     scanf( %lf%lf , &R[i].first, &R[i].second); n     Min = min(Min, dist(R[i], P)); n     Max = max(Max, dist(R[i], P)); n     if (!i) continue; n     Min = min(Min, dist(R[i], R[i - 1], P)); n     Max = max(Max, dist(R[i], R[i - 1], P)); n   } n   Min = min(Min, dist(R[0], R[N - 1], P)); n   Max = max(Max, dist(R[0], R[N - 1], P)); n   printf( %lf , Max * PI - Min * PI); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using pii = pair<int, int>; n using pll = pair<ll, ll>; n using pdd = pair<double, double>; n using vi = vector<int>; n using vii = vector<pii>; n using vs = vector<string>; n const double PI = acos(-1.0); n const double EPS = 1e-14; n const int MOD = 1e9 + 7; n const int INF = 1e9; n const ll INFLL = 4e18; n const int MAX = 1e5; n int n, m; n set<int> hv, ans; n void read() { n   cin >> n >> m; n   for (int i = 0; i < (int)n; i++) { n     int t; n     cin >> t; n     hv.insert(t); n   } n } n void solve() { n   for (int i = (int)1; i <= (int)1e9; i++) { n     if (i > m) break; n     if (!(hv.find(i) != hv.end())) { n       ans.insert(i); n       m -= i; n     } n   } n   cout << (int)ans.size() <<   n ; n   for (int t : ans) { n     cout << t <<    ; n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int TC = 1; n   while (TC--) { n     read(); n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, ans[1009], t, l, r, low = 1e8, vis[1009]; n vector<pair<int, int> > v0, v1; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> m; n   for (int i = 0; i < m; i++) { n     cin >> t >> l >> r; n     if (t == 0) n       v0.push_back({l, r}); n     else n       v1.push_back({l, r}); n   } n   sort(v0.begin(), v0.end()); n   sort(v1.begin(), v1.end()); n   for (auto i : v1) { n     l = i.first, r = i.second; n     int b = low; n     if (ans[l] != 0) n       b = ans[l]; n     else n       low -= 4000; n     while (l <= r) { n       vis[l]++; n       if (!ans[l]) ans[l] = b; n       l++; n     } n   } n   for (auto i : v0) { n     l = i.first, r = i.second; n     for (int j = l; j < r; j++) { n       if (!ans[j] && !ans[j + 1]) { n         ans[j] = 1000000000, ans[j + 1] = 1000000000 - 1; n         break; n       } else if (!ans[j]) { n         ans[j] = 1 + ans[j + 1]; n         break; n       } else if (!ans[j + 1]) { n         ans[j + 1] = ans[j] - 1; n         break; n       } n     } n   } n   for (int i = 1; i <= n; i++) n     if (!ans[i]) ans[i] = 1; n   for (auto i : v0) { n     int yes = 1; n     l = i.first, r = i.second; n     for (int j = l; j < r; j++) { n       if (ans[j] > ans[j + 1]) { n         yes = 0; n         break; n       } n     } n     if (yes) return cout <<  NO , 0; n   } n   cout <<  YES n ; n   for (int i = 1; i <= n; i++) cout << ans[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n typedef pair<int, int> ll; n typedef vector<int> vl; n typedef vector<ll> vll; n typedef vector<vl> vvl; n template <typename T> n ostream &operator<<(ostream &o, vector<T> v) { n   if (v.size() > 0) o << v[0]; n   for (unsigned i = 1; i < v.size(); i++) o <<     << v[i]; n   return o <<   n ; n } n template <typename U, typename V> n ostream &operator<<(ostream &o, pair<U, V> p) { n   return o <<  (  << p.first <<  ,   << p.second <<  )  ; n } n template <typename T> n istream &operator>>(istream &in, vector<T> &v) { n   for (unsigned i = 0; i < v.size(); i++) in >> v[i]; n   return in; n } n template <typename T> n istream &operator>>(istream &in, pair<T, T> &p) { n   in >> p.first; n   in >> p.second; n   return in; n } n vl G(5003, 0); n string a; n bool check() { n   int ans = 0; n   int add = 0; n   for (int i = (1); i < (int)a.length() - 1; i++) { n     if (a[i - 1] == a[i + 1] and a[i] !=  $ ) n       add++; n     else { n       ans ^= G[add]; n       add = 0; n     } n   } n   return ans == 0; n } n int main() { n   std::ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cout.precision(20); n   G[0] = 0; n   G[1] = 1; n   for (int i = (2); i < (int)5003; i++) { n     set<int> temp; n     for (int(j) = 0; (j) < (i); (j)++) { n       if (j == 0 or j == i - 1) n         temp.insert(G[i - 2]); n       else n         temp.insert(G[j - 1] ^ G[i - j - 2]); n     } n     while (temp.find(G[i]) != temp.end()) G[i]++; n   } n   cin >> a; n   a +=  # ; n   for (int i = (1); i < (int)a.length() - 1; i++) n     if (a[i - 1] == a[i + 1]) { n       char c = a[i]; n       a[i] =  $ ; n       if (check()) { n         cout <<  First  n              <<   n ; n         cout << i + 1 <<   n ; n         return 0; n       } n       a[i] = c; n     } n   cout <<  Second ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 1000009; n void solve() { n   unsigned long long n, x; n   cin >> n >> x; n   int count = 0; n   for (int i = 1; i <= floor(sqrt(x)); i++) { n     if ((x % i == 0) && (i <= n) && (x / i <= n)) { n       if ((x / i != i)) { n         count += 2; n       } else { n         count++; n       } n     } n   } n   cout << count; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 200005; n const int MAXM = 1000005; n const int MOD = 1000000007; n const int MAMOD = 998244353; n const int INF = 0x3f3f3f3f; n const long long LLINF = 0x3f3f3f3f3f3f3f3f; n const double PI = acos(-1.0); n const double EPS = 1e-8; n int a[1005], color[1005]; n int pri[12] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31}; n vector<int> v[12]; n int main() { n   ios::sync_with_stdio(0); n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     for (int j = 0; j < 11; ++j) v[j].clear(); n     for (int i = 1; i <= n; ++i) { n       cin >> a[i]; n       for (int j = 0; j < 11; ++j) { n         if (a[i] % pri[j] == 0) { n           color[i] = j; n           v[j].push_back(i); n           break; n         } n       } n     } n     int num[12], tot = 0; n     for (int i = 0; i < 11; ++i) { n       if (v[i].size()) num[i] = ++tot; n     } n     cout << tot <<   n ; n     for (int i = 1; i <= n; ++i) cout << num[color[i]] <<    ; n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n const long long MOD = 1e9 + 7; n const long long INF = 1e18; n using namespace std; n long long powmod(long long a, long long b) { n   long long res = 1ll; n   while (b) { n     if (b & 1) res = (res * a) % MOD; n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   int t; n   cin >> t; n   while (t--) { n     int n, k1, k2; n     cin >> n >> k1 >> k2; n     int tmp; n     bool state = false; n     for (int i = 0; i < k1; i++) cin >> tmp, state |= tmp == n; n     for (int i = 0; i < k2; i++) cin >> tmp; n     if (state) n       cout <<  YES n ; n     else n       cout <<  NO n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, a, b; n   cin >> n; n   while (n--) { n     cin >> a >> b; n     if (a != b) { n       cout <<  Happy Alex  << endl; n       return 0; n     } n   } n   cout <<  Poor Alex  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   int cand_sums[n]; n   memset(cand_sums, 0, sizeof cand_sums); n   vector<vector<int>> votes = vector<vector<int>>(m, vector<int>(n, 0)); n   vector<priority_queue<pair<int, int>>> bad_stations = n       vector<priority_queue<pair<int, int>>>(n, n                                              priority_queue<pair<int, int>>()); n   int in; n   for (int i = 0; i < m; i++) { n     for (int j = 0; j < n; j++) { n       cin >> in; n       cand_sums[j] += in; n       votes[i][j] = in; n       if (j == n - 1) { n         for (int k = 0; k < j; k++) { n           bad_stations[k].push(pair<int, int>(in - votes[i][k], i)); n         } n       } n     } n   } n   vector<vector<int>> killed_stations = n       vector<vector<int>>(n - 1, vector<int>()); n   for (int i = 0; i < n - 1; i++) { n     while (!bad_stations[i].empty() && cand_sums[i] < cand_sums[n - 1]) { n       pair<int, int> curr = bad_stations[i].top(); n       bad_stations[i].pop(); n       cand_sums[i] += curr.first; n       killed_stations[i].push_back(curr.second); n     } n   } n   int best = 0; n   int best_size = m + 1; n   for (int i = 1; i < n - 1; i++) { n     if (killed_stations[i].size() < best_size) { n       best = i; n       best_size = killed_stations[i].size(); n     } n   } n   cout << killed_stations[best].size() << endl; n   for (int i = 0; i < killed_stations[best].size(); i++) { n     if (i > 0) cout <<    ; n     cout << killed_stations[best][i] + 1; n   } n   if (!killed_stations[best].empty()) cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long t, a, b; n   string s; n   scanf( %lld , &t); n   vector<int> v; n   while (t--) { n     v.clear(); n     scanf( %lld%lld , &a, &b); n     cin >> s; n     for (int i = 0; i < s.length(); i++) { n       if (s[i] ==  0 ) v.push_back(i); n     } n     int w = -1; n     for (int i = 0; i < v.size(); i++) { n       if (b > v[i] - w - 1) { n         b = b - (v[i] - w - 1); n         v[i] = w + 1; n         w = v[i]; n       } else { n         v[i] = v[i] - b; n         break; n       } n     } n     v.push_back(1000025); n     int k = 0; n     for (int i = 0; i < a; i++) { n       if (i == v[k]) { n         cout <<  0 ; n         k++; n       } else { n         cout <<  1 ; n       } n     } n     cout << endl; n   } 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 = 200005; n long long const mod = 1000 * 1000 * 1000 + 7; n map<string, long long> m; n string s[N]; n int main() { n   int a; n   cin >> a; n   if (a < 6) n     printf( -1 n ); n   else { n     printf( 1 2 n1 3 n1 4 n ); n     for (int i = 5; i <= a; i++) printf( 2 %d n , i); n   } n   for (int i = 1; i < a; i++) printf( %d %d n , i, i + 1); n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int x, y, z; n   while (scanf( %d%d , &x, &y) == 2) { n     z = abs(x) + abs(y); n     if (x > 0) { n       if (y > 0) n         printf( 0 %d %d 0 n , z, z); n       else n         printf( 0 -%d %d 0 n , z, z); n     } else { n       if (y > 0) n         printf( -%d 0 0 %d n , z, z); n       else n         printf( -%d 0 0 -%d n , z, z); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a1, a2, a3, a4; n int main() { n   scanf( %d%d%d%d , &a1, &a2, &a3, &a4); n   if (min(a1, a2) < max(a3, a4)) { n     puts( -1 ); n     return 0; n   } n   if (a1 + a2 == a3 + a4) { n     puts( -1 ); n     return 0; n   } n   if (a3 - a4 == 1) { n     int n = a3; n     for (int i = 1; i <= a1 - n + 1; ++i) { n       putchar( 4 ); n     } n     for (int i = 1; i < n; ++i) { n       putchar( 7 ); n       putchar( 4 ); n     } n     for (int i = 1; i <= a2 - n + 1; ++i) { n       putchar( 7 ); n     } n     return 0; n   } n   if (a3 == a4) { n     int n = a3 + 1; n     if (a1 >= n) { n       for (int i = 1; i <= a1 - n + 1; ++i) { n         putchar( 4 ); n       } n       for (int i = 1; i < n - 1; ++i) { n         putchar( 7 ); n         putchar( 4 ); n       } n       for (int i = 1; i <= a2 - n + 2; ++i) { n         putchar( 7 ); n       } n       putchar( 4 ); n       return 0; n     } else { n       for (int i = 1; i < n; ++i) { n         putchar( 7 ); n         putchar( 4 ); n       } n       for (int i = 1; i <= a2 - n + 1; ++i) { n         putchar( 7 ); n       } n       return 0; n     } n   } n   if (a4 - a3 == 1) { n     int n = a4; n     putchar( 7 ); n     for (int i = 1; i <= a1 - n + 1; ++i) { n       putchar( 4 ); n     } n     for (int i = 1; i < n - 1; ++i) { n       putchar( 7 ); n       putchar( 4 ); n     } n     for (int i = 1; i <= a2 - n + 1; ++i) { n       putchar( 7 ); n     } n     putchar( 4 ); n     return 0; n   } n   puts( -1 ); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize(2) n #pragma GCC optimize(3) n using namespace std; n inline int read() { n   int x = 0, neg = 1; n   char op = getchar(); n   while (!isdigit(op)) { n     if (op ==  - ) neg = -1; n     op = getchar(); n   } n   while (isdigit(op)) { n     x = 10 * x + op -  0 ; n     op = getchar(); n   } n   return neg * x; n } n inline void print(int x) { n   if (x < 0) { n     putchar( - ); n     x = -x; n   } n   if (x >= 10) print(x / 10); n   putchar(x % 10 +  0 ); n } n const int N = 1000005; n vector<int> adj[N]; n void add(int u, int v) { adj[u].push_back(v); } n int n; n int heavy[N], len[N]; n void dfs1(int u, int fa) { n   for (auto v : adj[u]) { n     if (v == fa) continue; n     dfs1(v, u); n     if (len[v] > len[heavy[u]]) heavy[u] = v; n   } n   len[u] = len[heavy[u]] + 1; n } n int *f[N], tmp[N], *id = tmp, ans[N]; n void dfs2(int u, int fa) { n   f[u][0] = 1; n   if (heavy[u]) { n     f[heavy[u]] = f[u] + 1; n     dfs2(heavy[u], u); n     ans[u] = ans[heavy[u]] + 1; n   } n   for (auto v : adj[u]) { n     if (v == fa || v == heavy[u]) continue; n     f[v] = id, id += len[v]; n     dfs2(v, u); n     for (register int j = 1; j <= len[v]; j++) { n       f[u][j] += f[v][j - 1]; n       if ((j < ans[u] && f[u][j] >= f[u][ans[u]]) || n           (j > ans[u] && f[u][j] > f[u][ans[u]])) { n         ans[u] = j; n       } n     } n   } n   if (f[u][ans[u]] == 1) { n     ans[u] = 0; n   } n } n int main() { n   n = read(); n   for (register int i = 1; i < n; i++) { n     int u = read(), v = read(); n     add(u, v), add(v, u); n   } n   int root = 1; n   dfs1(root, 0); n   f[1] = id, id += len[1]; n   dfs2(root, 0); n   for (register int i = 1; i <= n; i++) { n     printf( %d n , ans[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k, a[303], flipped[303]; n int query(int l, int r) { n   cout <<  ?   << l <<     << r << endl; n   cin >> l; n   fflush(stdin); n   return l; n } n void flip(int l, int r) { n   for (int i = l; i < r + 1; i++) { n     flipped[i] ^= 1; n   } n } n void sol(int l, int r, int segk, bool f) { n   if (l > r) return; n   int lc = 0, rc = 0; n   for (int i = 1; i < l; i++) lc += a[i] ^ flipped[i]; n   for (int i = r + 1; i < n + 1; i++) rc += a[i] ^ flipped[i]; n   if (l == r) n     a[l] = flipped[l] ^ segk; n   else if (f) { n     while (1) { n       int q = query(l, r - 1); n       if (lc + n - r - rc + r - l + 1 - segk == q) { n         segk = r - l + 1 - segk; n         rc = n - r - rc; n         flip(l, n); n       } else { n         int g = (q + 1 + lc + segk - r - rc) / 2; n         a[r] = flipped[r] ^ g; n         lc = l - 1 - lc; n         segk = r - l - segk + 2 * g; n         flip(1, r - 1); n         sol(l, r, segk, !f); n         return; n       } n     } n   } else { n     while (1) { n       int q = query(l + 1, r); n       if (l - 1 - lc + rc + r - l + 1 - segk == q) { n         segk = r - l + 1 - segk; n         lc = l - 1 - lc; n         flip(1, r); n       } else { n         int g = (q + rc + l + segk - n - lc) / 2; n         a[l] = flipped[l] ^ g; n         rc = n - r - rc; n         segk = r - l - segk + g; n         flip(l + 1, n); n         sol(l + 1, r - 1, segk - (a[r] ^ flipped[r]), !f); n         return; n       } n     } n   } n } n void disp() { n   cout <<  !  ; n   for (int i = 1; i < n + 1; i++) cout << a[i]; n   cout << endl; n } n void solve() { n   cin >> n >> k; n   sol(1, n, k, 1); n   disp(); n } n signed main() { n   int t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[310], g[310][310], use[310]; n int tm; n void add(int x, int y) { n   g[x][y] = g[y][x] = 1; n   tm++; n } n int main() { n   int n, m, K; n   scanf( %d%d%d , &n, &m, &K); n   for (int i = 0; i < K; i++) { n     scanf( %d , &a[i]); n     use[a[i]] = 1; n   } n   sort(a, a + K); n   memset(g, 0, sizeof(g)); n   int ck = -1; n   for (int i = 1; i <= n; i++) n     if (!use[i]) ck = i; n   if (ck == -1) { n     puts( -1 ); n     return 0; n   } n   tm = 0; n   add(a[0], ck); n   add(ck, a[1]); n   for (int i = 1; i < K - 1; i++) add(a[i], a[i + 1]); n   int pre = a[K - 1]; n   for (int i = 1; i <= n; i++) { n     if (use[i]) continue; n     if (i == ck) continue; n     add(pre, i); n     pre = i; n   } n   for (int i = 1; i <= n; i++) n     for (int j = i + 1; j <= n; j++) { n       if (g[i][j] == 1) continue; n       if (tm == m) continue; n       if (i == a[0] && j == a[1]) continue; n       if (i == a[0] || j == a[0]) { n         int ti; n         if (i == a[0]) n           ti = j; n         else n           ti = i; n         if (use[ti] && g[ti][a[1]]) continue; n       } n       if (i == a[1] || j == a[1]) { n         int ti; n         if (i == a[1]) n           ti = j; n         else n           ti = i; n         if (use[ti] && g[ti][a[0]]) continue; n       } n       add(i, j); n     } n   if (tm != m) { n     puts( -1 ); n     return 0; n   } n   for (int i = 1; i <= n; i++) n     for (int j = i + 1; j <= n; j++) n       if (g[i][j]) printf( %d %d n , i, j); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<vector<long long> > mul(const vector<vector<long long> > &a, n                                const vector<vector<long long> > &b, n                                const long long &mod) { n   int R1 = a.size(), C1 = a.front().size(); n   int R2 = b.size(), C2 = b.front().size(); n   if (C1 != R2) return vector<vector<long long> >(); n   vector<vector<long long> > result(R1, vector<long long>(C2, 0)); n   for (int i = 0; i < R1; ++i) { n     for (int j = 0; j < C2; ++j) { n       for (int k = 0; k < C1; ++k) { n         result[i][j] += a[i][k] * b[k][j] % mod; n         result[i][j] %= mod; n       } n     } n   } n   return result; n } n int main() { n   vector<vector<long long> > transformer = { n       {2, 1, 1, 0, 1, 1}, {1, 2, 0, 1, 1, 1}, {1, 1, 1, 0, 1, 1}, n       {1, 1, 0, 1, 1, 1}, {0, 0, 0, 0, 1, 1}, {0, 0, 0, 0, 0, 1}}; n   vector<vector<long long> > base(6, vector<long long>(1)); n   long long n, t; n   cin >> n; n   for (int i = 0; i < 4; ++i) { n     cin >> base[i][0]; n     base[i][0] = (base[i][0] % n + n) % n; n   } n   cin >> t; n   base[0][0]--; n   base[1][0]--; n   base[4][0] = base[5][0] = 1; n   vector<vector<long long> > result(6, vector<long long>(6, 0)); n   for (int i = 0; i < 6; ++i) result[i][i] = 1; n   while (t) { n     if (t & 1) result = mul(result, transformer, n); n     transformer = mul(transformer, transformer, n); n     t >>= 1; n   } n   result = mul(result, base, n); n   cout << result[0][0] + 1 <<     << result[1][0] + 1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool prime(long long n) { n   for (int i = 2; i <= sqrt(n); i++) n     if (n % i == 0) return false; n   return true; n } n int main() { n   string s, s1; n   long long a, b, c, m, n, k, t, l, d, p, nl, np; n   t = 1; n   while (t--) { n     cin >> n >> d; n     vector<long long> arr(n); n     long long sum = 0; n     for (int i = 0; i < n; i++) { n       cin >> arr[i]; n       sum += arr[i]; n     } n     if (sum + (n - 1) * 10 > d) n       cout << -1 << endl; n     else { n       cout << (n - 1) * 2 + (d - (sum + (n - 1) * 10)) / 5 << endl; n     } n   } n } n


#include <bits/stdc++.h> n int main() { n   int n; n   std::cin >> n; n   std::vector<int> a(n); n   std::vector<int> mn(n); n   for (int i = 0; i < n; ++i) { n     std::cin >> a[i]; n   } n   mn[n - 1] = a[n - 1]; n   for (int i = n - 2; i >= 0; --i) { n     if (a[i] < mn[i + 1]) { n       mn[i] = a[i]; n     } else { n       mn[i] = mn[i + 1]; n     } n   } n   for (int i = 0; i < n; ++i) { n     int left = i; n     int right = n - 1; n     int val = a[i]; n     while (left != right) { n       int mid = (left + right + 1) / 2; n       if (mn[mid] < val) { n         left = mid; n       } else { n         right = mid - 1; n       } n     } n     std::cout << right - i - 1 <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, dp[500005]; n pair<int, int> p[500005]; n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; ++i) scanf( %d%d , &p[i].first, &p[i].second); n   sort(p, p + n); n   for (int i = 0; i < n; ++i) { n     if (i) dp[i] = max(dp[i], dp[i - 1]); n     int ub = upper_bound(p + i + 1, p + n, make_pair(p[i].second + 1, 0)) - p; n     dp[ub] = max(dp[ub], dp[i] + 1); n   } n   printf( %d n , max(dp[n], dp[n - 1])); n } n


#include <bits/stdc++.h> n using namespace std; n inline long long read() { n   long long sum = 0, ff = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) ff = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) sum = sum * 10 + ch -  0 , ch = getchar(); n   return sum * ff; n } n const int N = 100007; n const int block = 500; n int n, m, a_st[N], a[N], x, y, num, belong[N], st[N / block + 7], n     ed[N / block + 7], col[N], sum[N / block + 7][N * 2], tag[N / block + 7], n     ans; n struct edge { n   int to, nxt; n } e[N]; n int cnt, he[N]; n void add(int u, int v) { n   e[++cnt].to = v; n   e[cnt].nxt = he[u]; n   he[u] = cnt; n } n int deep[N], siz[N], fa[N], son[N], dfs_cnt, dfn[N], top[N]; n void dfs1(int u, int fat) { n   deep[u] = deep[fat] + 1; n   siz[u] = 1; n   fa[u] = fat; n   for (int i = he[u]; i; i = e[i].nxt) { n     int v = e[i].to; n     if (v == fat) continue; n     dfs1(v, u); n     siz[u] += siz[v]; n     if (siz[v] > siz[son[u]]) son[u] = v; n   } n } n void dfs2(int u, int tp) { n   top[u] = tp; n   dfn[u] = ++dfs_cnt; n   if (!son[u]) return; n   dfs2(son[u], tp); n   for (int i = he[u]; i; i = e[i].nxt) { n     int v = e[i].to; n     if (top[v]) continue; n     dfs2(v, v); n   } n } n void build() { n   for (int i = 1; i <= n; i++) belong[i] = (i - 1) / block + 1; n   num = belong[n]; n   for (int i = 1; i <= num; i++) st[i] = (i - 1) * block + 1, ed[i] = i * block; n   ed[num] = n; n } n void change(int x, int y) { n   col[x] ^= 1; n   if (a[x] >= n + 1 - tag[belong[x]]) ans -= y; n   sum[belong[x]][a[x]] -= y; n } n void upd(int l, int r, int val) { n   for (int i = l; i <= r; i++) { n     if (!col[i] && a[i] >= n + 1 - tag[belong[i]]) ans--; n     if (!col[i]) sum[belong[i]][a[i]]--; n     a[i] += val; n     if (!col[i]) sum[belong[i]][a[i]]++; n     if (!col[i] && a[i] >= n + 1 - tag[belong[i]]) ans++; n   } n } n void modify(int l, int r, int val) { n   if (belong[l] == belong[r]) { n     upd(l, r, val); n     return; n   } n   upd(l, ed[belong[l]], val), upd(st[belong[r]], r, val); n   for (int i = belong[l] + 1; i < belong[r]; i++) { n     if (val == 1) n       tag[i]++, ans += sum[i][n + 1 - tag[i]]; n     else n       ans -= sum[i][n + 1 - tag[i]], tag[i]--; n   } n } n int main() { n   n = read(), m = read(); n   for (int i = 2; i <= n; i++) fa[i] = read(), add(fa[i], i); n   for (int i = 1; i <= n; i++) a_st[i] = read(); n   dfs1(1, 0); n   dfs2(1, 1); n   for (int i = 1; i <= n; i++) a[dfn[i]] = n - a_st[i]; n   build(); n   for (int i = 1; i <= n; i++) sum[belong[i]][a[i]]++; n   for (int i = 1; i <= m; i++) { n     x = read(); n     y = (x > 0) ? 1 : -1; n     x = abs(x); n     change(dfn[x], y); n     while (x) { n       modify(dfn[top[x]], dfn[x], y); n       x = fa[top[x]]; n     } n     cout << ans <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n pair<int, int> arr[3001]; n const long long int INF = 1000000000000000; n int n; n long long int dp[3001][3001]; n long long int solve(int pos, int prev) { n   if (pos > n) return 0; n   if (dp[pos][prev] != -INF) return dp[pos][prev]; n   long long int pin = arr[pos].second + solve(pos + 1, pos); n   long long int unpin = n       abs(arr[prev].first - arr[pos].first) + solve(pos + 1, prev); n   return dp[pos][prev] = min(pin, unpin); n } n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> arr[i].first >> arr[i].second; n   } n   sort(arr + 1, arr + n + 1); n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) dp[i][j] = -INF; n   } n   long long int ans = arr[1].second + solve(2, 1); n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n char ch[100]; n int main() { n   scanf( %d , &n); n   int l = 0, r = 1e9; n   for (int i = 1; i <= min(29, n); i++) { n     int mid = (l + r) >> 1; n     printf( %d %d n , mid, 1); n     fflush(stdout); n     scanf( %s , ch); n     if (ch[0] ==  b ) n       l = mid; n     else n       r = mid; n   } n   if (n <= 29) { n     printf( %d %d %d %d n , l, 2, r, 0); n   } else { n     printf( %d %d n , l, 10); n     fflush(stdout); n     scanf( %s , ch); n     if (ch[0] ==  b ) n       printf( %d %d %d %d n , l, 0, r, 2); n     else n       printf( %d %d %d %d n , l, 2, r, 0); n   } n   fflush(stdout); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1005; n double dis(long u, long v, long p, long q) { n   return sqrt(((double)u - p) * (u - p) + ((double)q - v) * (q - v)); n } n struct point { n   int x; n   int y; n }; n int main() { n   int n, m; n   cin >> n >> m; n   if (n == 0) { n     cout << 0 <<     << 1 << endl; n     cout << 0 <<     << m << endl; n     cout << 0 <<     << 0 << endl; n     cout << 0 <<     << m - 1 << endl; n     return 0; n   } n   if (m == 0) { n     cout << 1 <<     << 0 << endl; n     cout << n <<     << 0 << endl; n     cout << 0 <<     << 0 << endl; n     cout << n - 1 <<     << 0 << endl; n     return 0; n   } n   double tam1 = 2 * dis(0, 0, n - 1, m); n   double tam2 = 2 * dis(0, 0, n, m - 1); n   double tam3 = sqrt(double(m) * m + double(n) * n) + max(m, n); n   if (tam3 >= tam1 && tam3 >= tam2) { n     cout << 0 <<     << 0 << endl; n     cout << n <<     << m << endl; n     if (n > m) { n       cout << 0 <<     << m << endl; n       cout << n <<     << 0 << endl; n     } else { n       cout << n <<     << 0 << endl; n       cout << 0 <<     << m << endl; n     } n     return 0; n   } n   if (n <= m) { n     cout << n - 1 <<     << m << endl; n     cout << 0 <<     << 0 << endl; n     cout << n <<     << m << endl; n     cout << 1 <<     << 0 << endl; n   } else { n     cout << n <<     << m - 1 << endl; n     cout << 0 <<     << 0 << endl; n     cout << n <<     << m << endl; n     cout << 0 <<     << 1 << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 10; n const int INF = 0x3f3f3f3f; n const double PI = acos(-1.0); n const double eps = 1e-10; n const int M = 1e9 + 7; n int dcmp(double first) { n   if (fabs(first) < eps) return 0; n   return first < 0 ? -1 : 1; n } n int a[N]; n int main() { n   int n, f = 0; n   scanf( %d , &n); n   for (int i = 0; i <= n; i++) { n     scanf( %d , &a[i]); n     if (i && a[i] > 1 && a[i - 1] > 1) f = 1; n   } n   printf( %s n , f ?  ambiguous  :  perfect ); n   for (int l = 0; l < 2 && f; l++) { n     int p = 0, p0 = 0, cnt = 1; n     for (int i = 0; i <= n; i++) { n       int p1 = 0, p2 = 0; n       for (int k = 0; k < a[i]; k++) { n         if (!k) p1 = cnt; n         if (l && k == 1) p2 = cnt; n         if (l && !k && p0) n           printf( %d  , p0); n         else n           printf( %d  , p); n         cnt++; n       } n       p = p1; n       p0 = p2; n     } n     puts(  ); n   } n   return 0; n } n