#include <bits/stdc++.h> n using namespace ::std; n const long long maxn = 400; n const long long mod = 1e9 + 7; n const long long inf = 1e17 + 500; n string s[maxn]; n long long a[maxn]; n string t; n long long n; n long long ger[maxn][maxn]; n long long tvi[maxn][maxn]; n long long sav[maxn][maxn]; n long long tyu[maxn][maxn]; n long long star[maxn]; n long long m; n long long f(string h) { n   long long ans = 0; n   for (long long i = 0; i < n; i++) { n     if (h.size() >= s[i].size()) { n       bool good = 1; n       for (long long j = 0; j < s[i].size(); j++) { n         if (h[j] != s[i][j]) { n           good = 0; n         } n       } n       if (good) { n         ans += a[i]; n       } n     } n   } n   return ans; n } n void tavtosav() { n   for (long long i = 0; i < m; i++) { n     for (long long j = 0; j < m; j++) { n       sav[i][j] = tvi[i][j]; n     } n   } n } n void jelosav() { n   for (long long i = 0; i < m; i++) { n     for (long long j = 0; j < m; j++) { n       long long v = -inf; n       for (long long z = 0; z < m; z++) { n         v = max(v, sav[i][z] + ger[z][j]); n       } n       tyu[i][j] = v; n     } n   } n   for (long long i = 0; i < m; i++) { n     for (long long j = 0; j < m; j++) { n       sav[i][j] = tyu[i][j]; n     } n   } n } n void tavbasavtotav() { n   for (long long i = 0; i < m; i++) { n     for (long long j = 0; j < m; j++) { n       long long v = -inf; n       for (long long z = 0; z < m; z++) { n         v = max(v, sav[i][z] + tvi[z][j]); n       } n       tyu[i][j] = v; n     } n   } n   for (long long i = 0; i < m; i++) { n     for (long long j = 0; j < m; j++) { n       tvi[i][j] = tyu[i][j]; n     } n   } n } n void tav(long long l) { n   if (l == 0) { n     for (long long i = 0; i < m; i++) { n       for (long long j = 0; j < m; j++) { n         tvi[i][j] = -inf; n       } n       tvi[i][i] = 0; n     } n     return; n   } n   tav(l / 2); n   tavtosav(); n   if (l & 1) { n     jelosav(); n   } n   tavbasavtotav(); n } n bool sub(string a, string b) { n   for (long long i = 0; i < a.size(); i++) { n     if (a[i] != b[i]) { n       return 0; n     } n   } n   return 1; n } n map<string, int> ml; n int main() { n   long long l; n   cin >> n >> l; n   for (long long i = 0; i < n; i++) { n     cin >> a[i]; n   } n   for (long long i = 0; i < n; i++) { n     cin >> s[i]; n     ml[s[i]] += a[i]; n   } n   long long np = 0; n   for (long long i = 0; i < n; i++) { n     long long v = ml[s[i]]; n     if (v != 0) { n       a[np] = v; n       s[np] = s[i]; n       np++; n       ml[s[i]] = 0; n     } n   } n   n = np; n   for (long long i = 0; i < n; i++) { n     star[i] = t.size(); n     t += s[i]; n     t +=  # ; n   } n   m = t.size(); n   for (long long i = 0; i < maxn; i++) { n     for (long long j = 0; j < maxn; j++) { n       ger[i][j] = -inf; n     } n   } n   for (int i = 0; i < t.size(); i++) { n     if (t[i] ==  # ) { n       ger[i][i] = 0; n     } else { n       string h; n       for (int j = i + 1; t[j] !=  # ; j++) { n         h += t[j]; n       } n       ger[i][i + 1] = f(t[i] + h); n       for (int j = 0; j < n; j++) { n         if (h.size() < s[j].size() && sub(h, s[j])) { n           ger[i][star[j]] = f(t[i] + s[j]); n         } n       } n     } n   } n   tav(l); n   long long ans = 0; n   for (int i = 0; i < m; i++) { n     if (t[i] ==  # ) { n       for (int j = 0; j < m; j++) { n         ans = max(ans, tvi[j][i]); n       } n     } n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n const int MN = 1000 * 100 + 1000; n const int INF = (1u << 31) - 1; n int l1[MN]; n int l2[MN]; n int b[MN]; n int p[MN]; n int n, m, _; n int main() { n   ios::sync_with_stdio(false); n   cin >> n >> m >> _ >> _; n   for (int i = 0; i < n; i++) cin >> l1[i]; n   for (int i = 0; i < m; i++) cin >> l2[i]; n   sort(l1, l1 + n); n   sort(l2, l2 + m); n   for (int i = 0; i < m; i++) b[i] = INF; n   int now = 0; n   for (int i = 0; i < n; i++) { n     while (now + 1 < m && abs(l2[now + 1] - l1[i]) < abs(l2[now] - l1[i])) n       now++; n     if (now + 1 < m && abs(l2[now + 1] - l1[i]) == abs(l2[now] - l1[i]) && n         b[now] != abs(l2[now] - l1[i]) && b[now] != INF) n       now++; n     p[i] = now; n     b[now] = min(b[now], abs(l2[now] - l1[i])); n   } n   int hung = 0; n   for (int i = 0; i < n; i++) n     if (b[p[i]] != abs(l2[p[i]] - l1[i])) hung++; n   cout << hung << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dp1[100010]; n int dp2[100010]; n int a[100010]; n int main(int argc, char const *argv[]) { n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     std::cin >> a[i]; n   } n   dp1[0] = 0; n   int sum = 0; n   for (int i = 1; i <= n; i++) { n     sum += a[i]; n     dp1[i] = dp1[i - 1] + a[i]; n     if (dp1[i] < -sum) { n       dp1[i] = -sum; n     } n   } n   dp2[n + 1] = 0; n   sum = 0; n   for (int i = n; i >= 1; --i) { n     sum += a[i]; n     dp2[i] = dp2[i + 1] + a[i]; n     if (dp2[i] < -sum) { n       dp2[i] = -sum; n     } n   } n   int ans = 0; n   for (int i = 1; i <= n + 1; i++) { n     ans = max(ans, dp1[i - 1] + dp2[i]); n   } n   std::cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ld = long double; n using ull = unsigned long long; n const double PI = acos(-1.0); n const int EPS = (1e-10); n const int N = 1e5 * 2 + 10; n const int inf = 1e9 * 2 + 10; n const ll INF = 1e18 * 2 + 10; n const int MOD = 1e9 + 7; n int nxt() { n   int x; n   cin >> x; n   return x; n } n int fcmp(double a, double b) { n   return (fabs(a - b) < EPS ? 0 : a > b ? 1 : -1); n } n bool prime[N]; n vector<int> adj[N]; n int sz[N], link[N]; n void sieve() { n   fill(&prime[0], &prime[0] + N, 1); n   prime[0] = 0; n   prime[1] = 1; n   for (int i = 2; i * i <= N; ++i) n     if (prime[i]) { n       for (int j = i * i; j < N; j += i) prime[j] = 0; n     } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   sieve(); n   string s; n   cin >> s; n   map<char, int> mp; n   for (int i = (0); i <= ((int)(s).size() - 1); ++i) mp[s[i]]++; n   s =  0  + s; n   char k = 0; n   for (int i = (0); i <= (256); ++i) n     if (mp[k] < mp[i]) k = i; n   prime[1] = 1; n   for (int i = 2; i + i <= (int)(s).size() - 1; ++i) prime[i] = 0; n   for (int i = (1); i <= ((int)(s).size() - 1); ++i) n     if (!prime[i]) { n       if (mp[k] == 0) { n         cout <<  NO n ; n         return 0; n       } n       mp[s[i] = k]--; n     } n   for (int i = (1); i <= ((int)(s).size() - 1); ++i) n     if (prime[i]) { n       bool ok = false; n       for (int j = (0); j <= (256); ++j) n         if (mp[j] > 0) { n           mp[s[i] = j]--; n           ok = true; n           break; n         } n       if (ok) n         continue; n       else { n         cout <<  NO n ; n         return 0; n       } n     } n   s.erase(0, 1); n   cout <<  YES n  << s; n   return 0; n } n


#include<bits/stdc++.h> n using namespace std; n #define ll long long int n const ll mod = 1e9+7; n  n  n void solve(){ n   int a; n   cin>>a; n   float arr[a]; n   float sum=0; n     for(int i=0;i<a;i++){ n         cin>>arr[i]; n         sum+=arr[i]; n     } n float avg = sum/(float)a; n sort(arr,arr+a); n int ans=0; n  for(int i=0;i<a;i++){ n        if(arr[i]>arr[0]) n        ans++; n     } n cout<<ans<<endl; n  n } n  n  n int main(){ n  int t; n  cin>>t; n  while(t--){ n    solve(); n  } n }


#include<iostream> n #include <math.h> n using namespace std; n  bool issquare(long int num) n  { n      long int sqrtnum=sqrt(num); n      if(num==(sqrtnum*sqrtnum)) n      { n          return true; n      } n      else{ n          return false; n      } n  } n  int main() n { n int t; n cin>>t; n  n for(int i=0;i<t;i++) n { n     int flag=0; n     long int n; n cin>>n; n if(n%2==0) n { n     long int k=n/2; n     if(issquare(k)) n         flag=1; n } n if(flag==0) n { n     if(n%4==0) n     { n         long int l=n/4; n         if(issquare(l)) n         flag=1; n     } n } n if(flag==1) n cout<< YES <<endl; n else n cout<< NO <<endl; n } n }


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:200000000 ) n using namespace std; n const long long oo = 1LL << 60; n const long long kNumMoves = 4; n const long long kMoves[kNumMoves][2] = {{1, 0}, {-1, 0}, {0, -1}, {0, 1}}; n long long GetMinMoves(long long x, long long y, long long m) { n   if (max(x, y) >= m) return 0; n   if ((x + y) <= min(x, y)) return -1; n   if (x < y) swap(x, y); n   long long cnt = 0; n   if (y < 0) { n     cnt = (-y / x); n     y += cnt * x; n   } n   if (x < y) swap(x, y); n   while (max(x, y) < m) { n     long long sum = x + y; n     long long mx = max(x, y); n     x = (sum < mx) ? mx : sum; n     y = (x == sum) ? mx : sum; n     ++cnt; n   } n   return cnt; n } n int main() { n   long long x, y, m; n   cin >> x >> y >> m; n   cout << GetMinMoves(x, y, m) << endl; n   int i; n   cin >> i; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   char a[21]; n   char b[21]; n   int s1[21]; n   int s2[21]; n   int lena; n   int lenb; n   while (scanf( %s%s , &a, &b) != EOF) { n     lena = strlen(a); n     for (int i = 0; i < lena; i += 2) { n       if (a[i] ==  [  && a[i + 1] ==  ] ) n         s1[i / 2] = 2; n       else if (a[i] ==  (  && a[i + 1] ==  ) ) n         s1[i / 2] = 1; n       else if (a[i] ==  8  && a[i + 1] ==  < ) n         s1[i / 2] = 0; n       if (b[i] ==  [  && b[i + 1] ==  ] ) n         s2[i / 2] = 2; n       else if (b[i] ==  (  && b[i + 1] ==  ) ) n         s2[i / 2] = 1; n       else if (b[i] ==  8  && b[i + 1] ==  < ) n         s2[i / 2] = 0; n     } n     int sum = 0; n     for (int i = 0; i < lena / 2; i++) { n       if (s1[i] - s2[i] == 1 || (s1[i] - s2[i] == -2)) n         sum += 1; n       else if ((s1[i] - s2[i] == -1) || (s1[i] - s2[i] == 2)) n         sum -= 1; n     } n     if (sum > 0) n       printf( TEAM 1 WINS n ); n     else if (sum < 0) n       printf( TEAM 2 WINS n ); n     else n       printf( TIE n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n const int maxn = 2 * 100000; n const int inf = 99999999; n class array { n  public: n   int num; n   int left; n   int right; n   array() { left = right = inf; } n } a[maxn + 1]; n int queue[maxn + 1]; n int head = 1, tail = 1; n int main() { n   int n; n   scanf( %d , &n); n   int nowzero = 0; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i].num); n     if (!a[i].num) { n       nowzero = i; n       a[i].left = a[i].right = 0; n       for (int j = head; j < tail; j++) { n         a[queue[j]].right = nowzero - queue[j]; n       } n       tail = head; n     } else { n       if (nowzero) a[i].left = i - nowzero; n       queue[tail++] = i; n     } n   } n   for (int i = 1; i <= n; i++) n     printf( %d%c , a[i].left > a[i].right ? a[i].right : a[i].left, n            i == n ?   n  :    ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string q1, q2, ans; n   cin >> q1 >> q2; n   int n, k = 0, c(0), p; n   n = q1.length(); n   for (int i = 0; i < n; i++) { n     if (q1[i] != q2[i]) { n       c++; n       if (c % 2 == 1) { n         ans += q1[i]; n       } else { n         ans += q2[i]; n       } n     } else { n       ans += q1[i]; n     } n   } n   if (c % 2 == 1) { n     cout <<  impossible ; n   } else { n     cout << ans; n   } n } n


#include <bits/stdc++.h> n int main() { n   int a[4], i, test, flag = 1, flag2 = 1; n   double test2, testn; n   for (i = 0; i < 4; i++) scanf( %d , &a[i]); n   test = a[1] - a[0]; n   if (a[2] - a[1] == test && a[3] - a[2] == test) { n     printf( %d , a[3] + test); n     flag = 0; n     flag2 = 0; n   } n   if (flag) { n     test2 = (double)a[1] / a[0]; n     if (fabs((double)a[2] / a[1] - test2) < 0.001 && n         fabs((double)a[3] / a[2] - test2) < 0.001) { n       testn = a[3] * test2; n       if (fabs(testn - (int)testn) < 0.001) { n         printf( %.0f , testn); n         flag2 = 0; n       } n     } n   } n   if (flag2) printf( 42 ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long int; n const ll MOD = 998244353; n const ll INF = 1e15 + 373; n template <typename T> n using vector2 = vector<vector<T>>; n template <typename T> n vector2<T> init_vector2(size_t n0, size_t n1, T e = T()) { n   return vector2<T>(n0, vector<T>(n1, e)); n } n template <typename T> n using vector3 = vector<vector<vector<T>>>; n template <typename T> n vector3<T> init_vector3(size_t n0, size_t n1, size_t n2, T e = T()) { n   return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e))); n } n template <typename T> n ostream& operator<<(ostream& os, const vector<T>& v) { n   os <<  [ ; n   for (T e : v) { n     os << e <<  ,  ; n   } n   os <<  ] ; n   return os; n } n class Point { n  public: n   ll y, x; n   Point() : y(0), x(0) {} n   Point(ll y, ll x) : y(y), x(x) {} n   bool operator==(const Point& p) { return this->y == p.y && this->x == p.x; } n   ll distance(const Point& p) { n     return abs(this->y - p.y) + abs(this->x - p.x); n   } n   friend ostream& operator<<(ostream& os, const Point& p) { n     os <<  (  << p.x <<  ,   << p.y <<  ) ; n     return os; n   } n }; n signed main() { n   ll n; n   cin >> n; n   vector<Point> ps(n + 1); n   for (ll i = 0; i < (ll)(n); ++i) { n     ll x, y; n     cin >> x >> y; n     ps[i] = Point(y, x); n   } n   ps[n] = Point(0, 0); n   vector<ll> levels(n + 1); n   for (ll i = 0; i < (ll)(n + 1); ++i) { n     levels[i] = max(ps[i].y, ps[i].x); n   } n   sort(levels.begin(), levels.end()); n   levels.erase(unique(levels.begin(), levels.end()), levels.end()); n   map<ll, ll> levelmap; n   for (ll i = 0; i < (ll)(levels.size()); ++i) { n     levelmap[levels[i]] = i; n   } n   vector<Point> minX(levels.size(), Point(0, 0)); n   vector<Point> minY(levels.size(), Point(0, 0)); n   for (ll i = 0; i < (ll)(n); ++i) { n     ll lev = levelmap[max(ps[i].y, ps[i].x)]; n     if (minX[lev] == Point(0, 0) || ps[i].x < minX[lev].x || n         (ps[i].x == minX[lev].x && ps[i].y >= minX[lev].y)) { n       minX[lev] = ps[i]; n     } n     if (minY[lev] == Point(0, 0) || ps[i].y < minY[lev].y || n         (ps[i].y == minY[lev].y && ps[i].x >= minY[lev].x)) { n       minY[lev] = ps[i]; n     } n   } n   vector<vector<ll>> dp(levels.size(), vector<ll>(2)); n   dp[levels.size() - 1][0] = n       minX[levels.size() - 1].distance(minY[levels.size() - 1]); n   dp[levels.size() - 1][1] = n       minY[levels.size() - 1].distance(minX[levels.size() - 1]); n   for (ll i = levels.size() - 2; i >= 0; i--) { n     dp[i][0] = min(minX[i].distance(minY[i]) + minY[i].distance(minX[i + 1]) + n                        dp[i + 1][0], n                    minX[i].distance(minY[i]) + minY[i].distance(minY[i + 1]) + n                        dp[i + 1][1]); n     dp[i][1] = min(minY[i].distance(minX[i]) + minX[i].distance(minX[i + 1]) + n                        dp[i + 1][0], n                    minY[i].distance(minX[i]) + minX[i].distance(minY[i + 1]) + n                        dp[i + 1][1]); n   } n   cout << dp[0][0] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 500; n int n; n long long a[maxn], ans; n long long dfs(int l, int r, int now) { n   if (l == r) { n     return 1; n   } n   long long fenge = r + 1; n   for (int i = l; i <= r; i++) { n     if (a[i] & (1 << now)) { n       fenge = i; n       break; n     } n   } n   long long ans = 0; n   if (fenge == l || fenge == r + 1) { n     ans = dfs(l, r, now - 1); n   } else { n     ans = max(dfs(l, fenge - 1, now - 1), dfs(fenge, r, now - 1)) + 1; n   } n   return ans; n } n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n   } n   sort(a + 1, a + n + 1); n   ans = dfs(1, n, 30); n   cout << n - ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int test; n   cin >> test; n   while (test--) { n     int n, m; n     cin >> n >> m; n     int array[n]; n     for (int i = 0; i < n; i++) cin >> array[i]; n     int sum = 0; n     for (int i = 0; i < n; i++) { n       sum += array[i]; n     } n     double average = sum / double(n); n     double value = m / double(n); n     if (value <= average) n       cout << m << endl; n     else n       cout << average * n << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int gcd(int a, int b) { n   int r; n   while (b) { n     r = a % b; n     a = b; n     b = r; n   } n   return a; n } n int GCD(int a, int b) { n   if (a == 0) n     return b; n   else n     return GCD(b % a, a); n } n long long int power(long long int a, long long int b) { n   long long int r = 1; n   while (b) { n     if (b & 1) { n       r = r * a; n       b--; n     } n     a = a * a; n     b >>= 1; n   } n   return r; n } n int palindrome(char *s, int len) { n   int i, j, k, count = 0, c = 0; n   for (i = 0, j = len - 1; i < len, j >= 0; i++, j--) { n     if (s[i] == s[j]) count++; n   } n   if (count == len) n     return 1; n   else n     return 0; n } n long long int binary(char *s, long long int len) { n   long long int i, j, k, r = 0, p = 0, num; n   for (i = len - 1; i >= 0; i--) { n     num = s[i] -  0 ; n     r += (num * power(2, p)); n     p++; n   } n   return r; n } n int binary_search(int *ara, int size, int n) { n   int high, mid, low; n   low = 0; n   high = size - 1; n   while (low <= high) { n     mid = (low + high) / 2; n     if (ara[mid] == n) { n       return 1; n     } else if (n > ara[mid]) n       low = mid + 1; n     else if (n < ara[mid]) n       high = mid - 1; n   } n   return -1; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   int i, j, k, n, T, q, a, b, num; n   string s1, s2; n   cin >> a >> b; n   int ara[] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6}; n   long long sum = 0; n   for (i = a; i <= b; i++) { n     num = i; n     while (num) { n       int mod = num % 10; n       sum = sum + (ara[mod]); n       num /= 10; n     } n   } n   cout << sum << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   ; n   cin >> t; n   while (t--) { n     int s; n     vector<int> v; n     cin >> s; n     for (int i = 0; i < s; i++) { n       int x; n       cin >> x; n       v.push_back(x); n     } n     int f = 0; n     for (int i = 0; i < s - 1; i++) { n       if (v[i] != v[i + 1]) f = 1; n     } n     if (f == 1) n       cout <<  1  << endl; n     else n       cout << s << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX_N = 200000; n const int MAX_L = MAX_N * 2; n vector<int> nbrs[MAX_N]; n int ps[MAX_N], cis[MAX_N], vs[MAX_L]; n bool used[MAX_N]; n int main() { n   int n, m, k; n   scanf( %d%d%d , &n, &m, &k); n   for (int i = 0; i < m; i++) { n     int u, v; n     scanf( %d%d , &u, &v); n     u--, v--; n     nbrs[u].push_back(v); n     nbrs[v].push_back(u); n   } n   ps[0] = -1; n   int l = 0; n   for (int u = 0; u >= 0;) { n     vector<int> &nbru = nbrs[u]; n     if (cis[u] == 0) { n       vs[l++] = u; n       used[u] = true; n     } n     while (cis[u] < nbru.size() && used[nbru[cis[u]]]) cis[u]++; n     if (cis[u] < nbru.size()) { n       int v = nbru[cis[u]++]; n       ps[v] = u; n       u = v; n     } else { n       int v = ps[u]; n       if (v >= 0) vs[l++] = v; n       u = v; n     } n   } n   int q = l / k, r = l % k; n   for (int i = 0, j = 0; i < k; i++) { n     int ci = q + ((i < r) ? 1 : 0); n     printf( %d , ci); n     while (ci--) printf(  %d , vs[j++] + 1); n     putchar(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int main() { n   scanf( %d , &n); n   if (n % 5 == 0) { n     cout << n / 5; n   } else n     cout << n / 5 + 1; n   return 0; n } n


#include <bits/stdc++.h> n const int INF = (int)1e9; n const int long minINF = (int)-1e9; n const int mod = (int)1e9 + 7; n const int MAXN = (int)2e6 + 5; n using namespace std; n long long arr[MAXN]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   int N; n   cin >> N; n   for (int i = 0; i < N; i++) cin >> arr[i]; n   long long f, x; n   cin >> x >> f; n   long long ans = 0; n   for (int i = 0; i < N; i++) { n     ans += arr[i] / (f + x) * f; n     if (arr[i] % (f + x) > x) { n       ans += f; n     } n   } n   cout << ans <<   n ; n } n


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


#include <bits/stdc++.h> n using namespace std; n int an = 0; n int ht; n char a[20][20][20]; n int h[20][20][20]; n int fill(int x, int y, int k) { n   if (k <= 0 || k > ht || a[k][x][y] ==  #  || h[k][x][y]) return 1; n   an++; n   h[k][x][y] = 1; n   fill(x - 1, y, k); n   fill(x, y - 1, k); n   fill(x, y + 1, k); n   fill(x + 1, y, k); n   fill(x, y, k - 1); n   fill(x, y, k + 1); n   return 1; n } n int main() { n   char s[100]; n   int x, y, i, j, k, n, m, u; n   memset(h, 0, sizeof(h)); n   scanf( %d%d%d , &k, &n, &m); n   ht = k; n   for (i = k; i > 0; i--) { n     for (j = 1; j < n + 1; j++) { n       scanf( %s , &a[i][j][1]); n     } n   } n   for (i = 1; i < k + 1; i++) { n     for (j = 0; j < m + 2; j++) { n       a[i][0][j] =  # ; n       a[i][n + 1][j] =  # ; n     } n     for (j = 0; j < n + 2; j++) { n       a[i][j][0] =  # ; n       a[i][j][m + 1] =  # ; n     } n   } n   scanf( %d%d , &x, &y); n   fill(x, y, k); n   printf( %d n , an); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, c; n vector<int> l; n vector<int> r; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> m >> c; n   while (l.size() + r.size() < n) { n     int val; n     cin >> val; n     if (val <= c / 2) { n       bool temp = 0; n       for (int i = 0; i < (int)l.size(); i++) { n         if (l[i] > val) { n           l[i] = val; n           temp = 1; n           cout << i + 1 << endl; n           break; n         } n       } n       if (!temp) { n         l.push_back(val); n         cout << l.size() << endl; n       } n     } else { n       bool temp = 0; n       for (int i = 0; i < (int)r.size(); i++) { n         if (r[i] < val) { n           r[i] = val; n           cout << n - i << endl; n           temp = 1; n           break; n         } n       } n       if (!temp) { n         r.push_back(val); n         cout << n - r.size() + 1 << endl; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1E-9; n const double Exp = 2.718281828459045; n const double Pi = 3.1415926535897932; n const int Max_Bit = 63; n const int INF = 2000000000; n const long long LINF = 1000000000000000007ll; n const int MOD = 1000000007; n const int NMAX = 100005; n const int MMAX = 505; n const int KMAX = 6; n const string CODE =  CODEFORCES ; n const int go[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; n int n, a[NMAX], l[NMAX], r[NMAX]; n int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } n int main() { n   int q, u, v; n   scanf( %d%d , &n, &q); n   for (int i = 0; i < n; ++i) { n     scanf( %d , &a[i + 1]); n   } n   for (int i = 0; i < n - 1; ++i) { n     a[i + 1] = abs(a[i + 2] - a[i + 1]); n   } n   a[0] = INF; n   a[n] = INF; n   for (int i = 1; i < n; ++i) { n     l[i] = i - 1; n     while (a[i] >= a[l[i]]) { n       l[i] = l[l[i]]; n     } n   } n   for (int i = n - 1; i > 0; i--) { n     r[i] = i + 1; n     while (a[i] > a[r[i]]) { n       r[i] = r[r[i]]; n     } n   } n   for (int i = 0; i < q; ++i) { n     long long ans = 0; n     scanf( %d%d , &u, &v); n     for (int j = u; j < v; ++j) { n       ans += (j - max(l[j], u - 1)) * 1ll * (min(r[j], v) - j) * 1ll * a[j]; n     } n     printf( %I64d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     long long dp[500005] = {0}; n     dp[3] = 8; n     long long fac = 2; n     for (long long i = 5; i <= 500000; i += 2) { n       dp[i] = dp[i - 2] + fac * (i + i + i - 2 + i - 2); n       ++fac; n     } n     cout << dp[n] << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n string str; n long long int n, k; n int main() { n   string temp; n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long int a, b, i, j, cnt = 0; n   cin >> str; n   n = str.size(); n   cin >> k; n   for (i = 0; i < k; i++) { n     cin >> temp; n     for (j = 0; j < n; j++) { n       a = 0, b = 0; n       while (j < n && (str[j] == temp[0] || str[j] == temp[1])) { n         if (str[j] == temp[0]) n           a++; n         else n           b++; n         j++; n       } n       cnt += min(a, b); n     } n   } n   cout << cnt <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int mod = 1000 * 1000 * 1000 + 7; n const double PI = 3.14159265358979323846264; n const pair<long long int, long long int> steps[] = { n     {1, 0}, {0, 1}, {-1, 0}, {0, -1}, {1, -1}, {1, 1}, {-1, -1}, {-1, 1}}; n template <typename... T> n void read(T&... args) { n   ((cin >> args), ...); n } n template <typename... T> n void write(T&&... args) { n   ((cout << args <<    ), ...); n } n void fio() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n } n void setUpLocal() {} n const long long int maxN = 2 * 1e3; n const long long int gp_size = maxN; n vector<long long int> gp[gp_size]; n long long int vis[gp_size]; n long long int cnt[gp_size]; n void dfs(long long int i) { n   vis[i] = 1; n   for (long long int child : gp[i]) n     if (!vis[child]) dfs(child); n } n long long int modPow(long long int n, long long int k) { n   long long int ret = 1; n   while (k) { n     if (k & 1) ret = ret * n % mod; n     k >>= 1; n     n = n * n % mod; n   } n   return ret; n } n void solve() { n   long long int n, m, k; n   cin >> n >> m >> k; n   for (long long int i = 1; i <= n - k + 1; i++) { n     for (long long int f = i, b = i + k - 1; f <= b; f++, b--) { n       gp[f].push_back(b); n       gp[b].push_back(f); n     } n   } n   long long int cc = 0; n   for (long long int i = 1; i <= n; i++) { n     if (!vis[i]) { n       cc++; n       dfs(i); n     } n   } n   cout << modPow(m, cc); n } n int32_t main() { n   fio(); n   setUpLocal(); n   return solve(), 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = acos(-1.0); n const double EPS = 1e-9; n const int oo = 210000000; n int n; n vector<int> p[4]; n vector<int> g[201]; n int solve(int x) { n   bool used[201]; n   for (int i = 1; i <= n; i++) used[i] = 0; n   int ans = 0, m = 0; n   while (m < n) { n     bool flag1 = 0; n     for (int i = 0; i < p[x].size(); i++) { n       int cur = p[x][i]; n       if (used[cur]) continue; n       bool flag = 1; n       for (int j = 0; j < g[cur].size(); j++) n         if (!used[g[cur][j]]) { n           flag = 0; n           break; n         } n       if (flag) { n         flag1 = 1; n         m++; n         used[cur] = 1; n       } n     } n     if (!flag1) { n       x++; n       if (x > 3) x = 1; n       ans++; n     } n   } n   return ans; n } n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) { n     int tmp; n     cin >> tmp; n     p[tmp].push_back(i); n   } n   for (int i = 1; i <= n; i++) { n     int k; n     cin >> k; n     for (int j = 0; j < k; j++) { n       int tmp1; n       cin >> tmp1; n       g[i].push_back(tmp1); n     } n   } n   int ans = oo; n   ans = min(ans, solve(1)); n   ans = min(ans, solve(2)); n   ans = min(ans, solve(3)); n   cout << ans + n << endl; n   return (0); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, c; n   cin >> a >> b >> c; n   if (a == b) n     cout <<  YES ; n   else if (b - a > 0 && c > 0) { n     if ((b - a) % c == 0) n       cout <<  YES ; n     else n       cout <<  NO ; n   } else if (b - a > 0 && c < 0) { n     cout <<  NO ; n   } else if (b - a < 0 && c > 0) { n     cout <<  NO ; n   } else if (b - a < 0 && c < 0) { n     if ((a - b) % c == 0) n       cout <<  YES ; n     else n       cout <<  NO ; n   } else if (c == 0) n     cout <<  NO ; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using db = double; n using vi = vector<int>; n const int l = 20; n const int maxn = 300006; n int e[maxn][l]; n int tote; n map<int, int> S; n int a[maxn]; n int yy[maxn]; n int rr[maxn]; n int h[maxn][1000 / l]; n int n, q; n int app[maxn]; n int sum[maxn]; n int Get(int a, int b) { return e[h[a][b / l]][b % l]; } n int main() { n   scanf( %d%d , &n, &q); n   for (int i = 1; i <= n; ++i) { n     scanf( %d , &a[i]); n     S[a[i]] = 0; n   } n   int tot = 0; n   for (auto &p : S) { n     rr[tot] = p.first; n     p.second = tot; n     tot++; n   } n   for (int i = 1; i <= n; ++i) a[i] = S[a[i]]; n   int m = (int)sqrt(n * 5) + 3; n   for (int i = 1; i <= n; ++i) app[a[i]]++; n   vi big; n   for (int i = 0; i < tot; ++i) n     if (app[i] > m / 5 - 3) { n       big.push_back(i); n       yy[i] = big.size() - 1; n     } else n       yy[i] = -1; n   int maxs = big.size() / l; n   memset(h, 0, sizeof(h)); n   memset(e, 0, sizeof(e)); n   tote = 0; n   for (int i = 1; i <= n; ++i) { n     for (int j = 0; j <= maxs; ++j) h[i][j] = h[i - 1][j]; n     if (yy[a[i]] != -1) { n       int no = yy[a[i]]; n       tote++; n       for (int j = 0; j < l; ++j) e[tote][j] = e[h[i - 1][no / l]][j]; n       e[tote][no % l]++; n       h[i][no / l] = tote; n     } n   } n   for (int i = 1; i <= q; ++i) { n     int l, r, k; n     scanf( %d%d%d , &l, &r, &k); n     int ans = -1; n     for (auto x : big) n       if (Get(r, yy[x]) - Get(l - 1, yy[x]) > (r - l + 1) / k) n         if (ans == -1 || x < ans) ans = x; n     if (r - l + 1 <= m) { n       vi tr; n       for (int i = l; i <= r; ++i) { n         tr.push_back(a[i]); n         sum[a[i]]++; n       } n       for (auto x : tr) n         if (sum[x] > (r - l + 1) / k) n           if (ans == -1 || x < ans) ans = x; n       for (auto x : tr) sum[x] = 0; n     } n     printf( %d n , (ans == -1) ? -1 : rr[ans]); n   } n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using pii = pair<int, int>; n const ll INF = 1e16 + 2; n signed main() { n   ios::sync_with_stdio(false); n   cin.tie(0), cout.tie(0); n   vector<pair<ll, ll>> pts; n   pts.emplace_back(); n   ll ax, ay, bx, by; n   cin >> pts[0].first >> pts[0].second >> ax >> ay >> bx >> by; n   ll x, y, t; n   cin >> x >> y >> t; n   while (pts.back().first < INF && pts.back().second < INF) n     pts.emplace_back(pts.back().first * ax + bx, pts.back().second * ay + by); n   int m = pts.size(); n   vector<int> dp(m); n   for (int i = 0; i < m; i++) { n     ll len; n     len = abs(pts[i].first - x) + abs(pts[i].second - y); n     ll cur_t = t; n     if (len > cur_t) { n       dp[i] = 0; n       continue; n     } n     cur_t -= len; n     dp[i] = 1; n     for (int j = i - 1; j >= 0; j--) { n       len = abs(pts[j].first - pts[j + 1].first) + n             abs(pts[j].second - pts[j + 1].second); n       if (cur_t >= len) dp[i] = i - j + 1; n       cur_t -= len; n     } n     len = abs(pts[i].first - x) + abs(pts[i].second - y); n     cur_t = t - len; n     len = abs(pts[i].first - pts[0].first) + abs(pts[i].second - pts[0].second); n     if (cur_t < 2 * len) continue; n     cur_t -= 2 * len; n     dp[i] = max(dp[i], i + 1); n     for (int j = i + 1; j < m; j++) { n       ll len = abs(pts[j].first - pts[j - 1].first) + n                abs(pts[j].second - pts[j - 1].second); n       if (cur_t >= len) dp[i] = max(dp[i], i + 1 + j - i); n       cur_t -= len; n     } n   } n   ll ans = *max_element(dp.begin(), dp.end()); n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 200005; n int n, a[maxn], tot, b[maxn], ans; n inline int read() { n   int ret = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -f; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     ret = ret * 10 + ch -  0 ; n     ch = getchar(); n   } n   return ret * f; n } n inline int BinarySearch(int l, int x) { n   int L = l, R = tot, mid; n   while (L <= R) { n     mid = L + R >> 1; n     b[mid] >= x ? R = mid - 1 : L = mid + 1; n   } n   return L; n } n int main() { n   n = read(); n   for (int i = 1; i <= n; i++) a[i] = read(); n   sort(a + 1, a + 1 + n); n   int cnt = 1; n   for (int i = 2; i <= n + 1; i++) { n     if (a[i] != a[i - 1]) { n       b[++tot] = cnt; n       cnt = 1; n     } else n       cnt++; n   } n   sort(b + 1, b + 1 + tot); n   for (int i = 1; i <= tot; i++) { n     for (int j = b[i - 1] + 1; j <= b[i]; j++) { n       int now = j, lst = j, ret = BinarySearch(i + 1, 2 * lst); n       while (ret <= tot) { n         lst *= 2; n         now += lst; n         ret = BinarySearch(ret + 1, 2 * lst); n       } n       if (now > ans) ans = now; n     } n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = (int)1E9; n int N, M, MB, LASTB; n unsigned long long LASTM; n vector<int> adj[100005]; n int LB, lb[100005], revlb[100005], tr[100005], a[100005], primes[1000], P; n class mask { n  public: n   unsigned long long v[16]; n   mask() { memset(v, 0, sizeof(v)); } n   void set(int b) { v[b / 64] |= 1ULL << (b % 64); } n   bool has(int b) { return (v[b / 64] & (1ULL << (b % 64))) > 0; } n   void add(unsigned long long v2[16], int l, int r, unsigned long long v, n            int shift) { n     int len = r - l + 1; n     l += shift; n     r += shift; n     int li, lm, ri, rm; n     bool cross = (l < M) ^ (r < M); n     if (l >= M) l -= M; n     if (r >= M) r -= M; n     li = l / 64; n     ri = r / 64; n     lm = l % 64; n     rm = r % 64; n     if (!cross) { n       if (li == ri) { n         v2[li] |= v << lm; n       } else { n         v2[li] |= v << lm; n         v2[ri] |= v >> (len - rm - 1); n       } n     } else { n       if (li == MB - 1) { n         v2[li] |= (v << lm) & LASTM; n         v2[ri] |= v >> (len - rm - 1); n       } else { n         v2[li] |= v << lm; n         v2[MB - 1] |= (v >> (64 - lm)) & LASTM; n         v2[ri] |= v >> (len - rm - 1); n       } n     } n   } n   void shift(int shift) { n     unsigned long long v2[16] = {}; n     for (int i = (0); i < (MB); i++) { n       add(v2, i * 64, min(M - 1, (i + 1) * 64 - 1), v[i], shift); n     } n     memcpy(v, v2, sizeof(v)); n   } n   void combine(const mask &ano) { n     for (int i = (0); i < (MB); i++) v[i] |= ano.v[i]; n   } n }; n mask val[1 << 20]; n int lz[1 << 20]; n void build(int k, int nl, int nr) { n   if (nl == nr) { n     val[k].set(a[revlb[nl]]); n     return; n   } n   int nm = (nl + nr) >> 1; n   build(2 * k + 1, nl, nm); n   build(2 * k + 2, nm + 1, nr); n   val[k] = val[2 * k + 1]; n   val[k].combine(val[2 * k + 2]); n } n void add(int k, int nl, int nr, int l, int r, int v); n void relax(int k, int nl, int nr) { n   int nm = (nl + nr) >> 1; n   add(2 * k + 1, nl, nm, nl, nm, lz[k]); n   add(2 * k + 2, nm + 1, nr, nm + 1, nr, lz[k]); n   lz[k] = 0; n } n void add(int k, int nl, int nr, int l, int r, int v) { n   if (r < nl || l > nr) return; n   if (l <= nl && nr <= r) { n     val[k].shift(v); n     lz[k] = (lz[k] + v) % M; n     return; n   } n   int nm = (nl + nr) >> 1; n   if (lz[k]) relax(k, nl, nr); n   add(2 * k + 1, nl, nm, l, r, v); n   add(2 * k + 2, nm + 1, nr, l, r, v); n   val[k] = val[2 * k + 1]; n   val[k].combine(val[2 * k + 2]); n } n mask get(int k, int nl, int nr, int l, int r) { n   if (r < nl || l > nr) return mask(); n   if (l <= nl && nr <= r) return val[k]; n   if (lz[k]) relax(k, nl, nr); n   int nm = (nl + nr) >> 1; n   mask ml = get(2 * k + 1, nl, nm, l, r); n   mask mr = get(2 * k + 2, nm + 1, nr, l, r); n   ml.combine(mr); n   return ml; n } n void dfs(int x, int p) { n   lb[x] = LB; n   revlb[LB] = x; n   tr[x] = LB++; n   int sz = adj[x].size(); n   for (int i = (0); i < (sz); i++) { n     int y = adj[x][i]; n     if (y == p) continue; n     dfs(y, x); n   } n   tr[x] = LB - 1; n } n int main() { n   cin >> N >> M; n   for (int p = (2); p < (M); p++) { n     bool ok = 1; n     for (int i = 2; i * i <= p; i++) { n       if (p % i == 0) { n         ok = 0; n         break; n       } n     } n     if (ok) primes[P++] = p; n   } n   MB = (M + 64 - 1) / 64; n   LASTB = M % 64 == 0 ? 64 : M % 64; n   LASTM = (1ULL << LASTB) - 1ULL; n   for (int i = (0); i < (N); i++) { n     scanf( %d , a + i); n     a[i] %= M; n   } n   for (int i = (0); i < (N - 1); i++) { n     int a, b; n     scanf( %d%d , &a, &b); n     a--; n     b--; n     adj[a].push_back(b); n     adj[b].push_back(a); n   } n   dfs(0, -1); n   build(0, 0, N - 1); n   int Q; n   cin >> Q; n   while (Q--) { n     int t, x, val; n     scanf( %d%d , &t, &x); n     x--; n     if (t == 1) { n       scanf( %d , &val); n       add(0, 0, N - 1, lb[x], tr[x], val % M); n     } else { n       mask m = get(0, 0, N - 1, lb[x], tr[x]); n       int ans = 0; n       for (int i = (0); i < (P); i++) n         if (m.has(primes[i])) ans++; n       printf( %d n , ans); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int t; n   cin >> t; n   while (t--) { n     string s; n     int n, l = 0, r = 0, u = 0, d = 0; n     cin >> s; n     for (int i = 0; i < s.size(); i++) { n       if (s[i] ==  L ) n         l++; n       else if (s[i] ==  R ) n         r++; n       else if (s[i] ==  U ) n         u++; n       else n         d++; n     } n     int a = min(l, r); n     int b = min(u, d); n     if (a == 0 && b == 0) { n       cout << 0 << endl; n     } else if (a == 0) { n       cout << 2 << endl; n       cout <<  UD  << endl; n     } else if (b == 0) { n       cout << 2 << endl; n       cout <<  LR  << endl; n     } else { n       cout << 2 * (a + b) << endl; n       for (int i = 0; i < a; i++) { n         cout <<  L ; n       } n       for (int i = 0; i < b; i++) { n         cout <<  U ; n       } n       for (int i = 0; i < a; i++) { n         cout <<  R ; n       } n       for (int i = 0; i < b; i++) { n         cout <<  D ; n       } n       cout << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string bin; n   cin >> bin; n   int i = 0; n   for (; i + 1 < bin.length(); i++) n     if (bin[i] ==  0 ) break; n   cout << bin.substr(0, i) + bin.substr(i + 1) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 2e5 + 7; n const string alpha =  abcdefghijklmnopqrstuvwxyz ; n long long power(long long x, long long y) { n   long long res = 1; n   x = x; n   while (y > 0) { n     if (y & 1) res = (res * x); n     y = y >> 1; n     x = (x * x); n   } n   return res; n } n template <typename T> n T gcd(T a, T b) { n   if (a == 0) return b; n   return gcd(b % a, a); n } n template <typename T> n T powm(T a, T b, long long m) { n   T cnt = 1; n   while (b > 0) { n     if (b % 2 == 1) cnt = (cnt * a) % m; n     b /= 2; n     a = (a * a) % m; n   } n   return cnt % m; n } n long long ncr(long long n, long long r) { n   long long res = 1; n   if (r > n) return 0; n   if (r > n - r) r = n - r; n   for (long long i = 0; i < r; i++) { n     res *= (n - i); n     res /= (i + 1); n   } n   return res; n } n long long sqr(long long x) { return x * x; } n void solve() { n   long long int n; n   cin >> n; n   vector<long long> a(n), b(n); n   for (int i = 0; i < n; ++i) { n     cin >> a[i]; n     a[i] = a[i] * (i + 1) * (n - i); n   } n   for (int i = 0; i < n; ++i) { n     cin >> b[i]; n   } n   sort((a).begin(), (a).end()); n   sort((b).rbegin(), (b).rend()); n   long long ans = 0; n   for (int i = 0; i < n; ++i) { n     a[i] %= 998244353; n     ans = (ans + a[i] * b[i]) % 998244353; n   } n   cout << ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int tc; n   tc = 1; n   while (tc--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N, M; n int main() { n   cin >> M >> N; n   if (M == N) { n     cout << N <<  1  <<     << N <<  2 ; n     return 0; n   } n   if (N - M == 1) { n     cout << M <<  9  <<     << N <<  0 ; n     return 0; n   } n   if (M == 9 && N == 1) { n     cout <<  9 10 ; n     return 0; n   } n   cout << -1; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n, ctr{}; n   cin >> n; n   string vec; n   cin >> vec; n   int likh = count(vec.begin(), vec.end(),  8 ); n   if (likh > 0) { n     int m = min(likh, n % 11); n     int len = n - m; n     len = len / 10; n     ctr = min(len, likh); n   } n   cout << ctr <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX_N = 1e5 + 5; n char s[MAX_N]; n vector<int> v; n int main() { n   scanf( %s , s + 1); n   int n = strlen(s + 1); n   int tot = 0; n   for (int i = 1; i <= n; i++) { n     if (s[i] ==  ( ) n       tot++; n     else if (s[i] ==  ) ) n       tot--; n   } n   if (tot <= 0) { n     printf( -1 n ); n     return 0; n   } n   int res = 0; n   for (int i = 1; i <= n; i++) { n     if (s[i] ==  ( ) n       res++; n     else if (s[i] ==  ) ) n       res--; n     else n       res--, v.push_back(1), tot--; n     if (res < 0) { n       printf( -1 n ); n       return 0; n     } n   } n   if (tot < 0) { n     printf( -1 n ); n     return 0; n   } n   v[v.size() - 1] += tot; n   res = 0; n   int pos = -1; n   for (int i = n; i; i--) { n     if (s[i] ==  # ) { n       pos = i; n       break; n     } n   } n   for (int i = 1; i <= n; i++) { n     if (s[i] ==  ( ) n       res++; n     else if (s[i] ==  ) ) n       res--; n     else { n       if (i == pos) n         res -= 1 + tot; n       else n         res--; n     } n     if (res < 0) { n       printf( -1 n ); n       return 0; n     } n   } n   for (int i = 0; i < v.size(); i++) printf( %d n , v[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 5; n int dis[40]; n long long adj[40]; n vector<long long> v1; n vector<long long> v2; n void bt(int l, int r, long long mask) { n   if (l == r) { n     v1.emplace_back(mask); n     return; n   } n   bt(l + 1, r, mask); n   if (adj[l] & mask) return; n   bt(l + 1, r, mask | (1ll << l)); n } n long long f[1 << 21]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   int m; n   cin >> m; n   long long ans = 1; n   for (int i = 0; i < n; ++i) ans *= 2; n   for (int i = 0; i < m; ++i) { n     int x; n     cin >> x; n     --x; n     int y; n     cin >> y; n     --y; n     adj[x] |= (1ll << y); n     adj[y] |= (1ll << x); n   } n   long long cnt1 = 1; n   long long cnt01 = 1; n   long long cnt02 = 1; n   for (int j = 0; j < n; ++j) n     if (adj[j] == 0) cnt01 *= 2; n   fill(dis, dis + n, -1); n   for (int i = 0; i < n; ++i) n     if (dis[i] < 0) { n       cnt1 *= 2; n       cnt02 *= 2; n       int S = 0; n       queue<int> qu; n       qu.push(i); n       dis[i] = 0; n       while (qu.size()) { n         int u = qu.front(); n         qu.pop(); n         S++; n         for (int v = 0; v < n; ++v) n           if (adj[u] >> v & 1) { n             if (dis[v] < 0) dis[v] = dis[u] ^ 1, qu.push(v); n             if (dis[v] == dis[u]) cnt02 = 0; n           } n       } n     } n   if (ans == cnt1) ans = 0; n   ans -= cnt1; n   ans += cnt01 * 2; n   ans += cnt02; n   m = n / 2; n   bt(m, n, 0); n   v1.swap(v2); n   bt(0, m, 0); n   for (long long x : v2) { n     int M = 0; n     for (int i = 0; i < m; ++i) { n       if (adj[i] & x) n         continue; n       else n         M |= (1 << i); n     } n     f[M]++; n   } n   for (int i = 0; i < m; ++i) n     for (int j = 0; j < (1 << m); ++j) n       if (j >> i & 1) f[j ^ (1 << i)] += f[j]; n   for (long long x : v1) ans -= f[x], ans -= f[x]; n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int32_t main() { n   long long n, m; n   cin >> n >> m; n   vector<long long> a(n), b(m); n   for (long long i = 0; i < n; ++i) cin >> a[i]; n   for (long long i = 0; i < m; ++i) cin >> b[i]; n   long long tot = 0; n   for (long long i = 0; i < n; ++i) tot ^= a[i]; n   for (long long i = 0; i < m; ++i) tot ^= b[i]; n   if (tot == 0) { n     cout <<  YES n ; n     for (long long i = 0; i < n - 1; ++i) { n       for (long long j = 0; j < m - 1; ++j) { n         cout << 0 <<    ; n       } n       cout << a[i] <<   n ; n     } n     long long last = a[n - 1]; n     for (long long j = 0; j < m - 1; ++j) { n       cout << b[j] <<    ; n       last ^= b[j]; n     } n     cout << last <<   n ; n   } else { n     cout <<  NO n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 998244353; n int sum(int a, int b) { n   int s = a + b; n   if (s >= mod) s -= mod; n   return s; n } n int sub(int a, int b) { n   int s = a - b; n   if (s < 0) s += mod; n   return s; n } n int mult(int a, int b) { return (1LL * a * b) % mod; } n int n, k; n int len; n const int maxN = (int)1e5 + 10; n const int maxK = 105; n int dp[maxN][maxK]; n int sum_pref[maxN]; n int a[maxN]; n int f[maxN][maxK]; n int all[maxN]; n bool can(int l, int r, int color) { n   return (all[r] - all[l - 1] == f[r][color] - f[l - 1][color]); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   srand(239); n   cin >> n >> k >> len; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     for (int color = 1; color <= k; color++) { n       f[i][color] = f[i - 1][color]; n       f[i][color] += (color == a[i]); n     } n     all[i] = all[i - 1] + (a[i] > 0); n   } n   if (len == 1) { n     cout << 0; n     return 0; n   } n   sum_pref[0] = 1; n   for (int i = 1; i <= n; i++) { n     for (int color = 1; color <= k; color++) { n       if (a[i] != -1 && a[i] != color) continue; n       dp[i][color] = sum_pref[i - 1]; n       if (i >= len && can(i - len + 1, i, color)) { n         dp[i][color] = n             sub(dp[i][color], sub(sum_pref[i - len], dp[i - len][color])); n       } n       sum_pref[i] = sum(sum_pref[i], dp[i][color]); n     } n   } n   cout << sum_pref[n]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main(int argc, char **argv) { n   string i, o; n   cin >> i >> o; n   sort(i.begin(), i.end()); n   if (i ==  0  && i == o) { n     cout <<  OK  << endl; n     return 0; n   } n   unsigned int z; n   for (z = 0; z < i.length() && i[z] ==  0 ; ++z) n     ; n   while (!i.empty() && i[0] ==  0 ) i = i.substr(1); n   while (z--) i.insert(i.empty() ? 0 : 1,  0 ); n   cout << ((i == o) ?  OK  :  WRONG_ANSWER ) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long k = 2; n struct node { n   vector<node*> to; n   node() { to.resize(k, 0); } n   long long cnt = 0; n }; n node* root = new node(); n inline bool getbit(long long a, long long pos) { return a & (1 << pos); } n void addstring(long long b) { n   vector<long long> a; n   for (long long i = 0; i < 30; ++i) { n     a.push_back(getbit(b, i)); n   } n   reverse(a.begin(), a.end()); n   node* cur = root; n   for (long long i = 0; i < a.size(); ++i) { n     long long c = a[i]; n     if (cur->to[c] == 0) { n       cur->to[c] = new node(); n     } n     cur = cur->to[c]; n     cur->cnt++; n   } n } n long long get(long long b) { n   vector<long long> a; n   long long ans = 0; n   for (long long i = 0; i < 30; ++i) { n     a.push_back(getbit(b, i)); n   } n   reverse(a.begin(), a.end()); n   node* cur = root; n   for (long long i = 0; i < a.size(); ++i) { n     long long bet = a[i]; n     if (cur->to[bet] && cur->to[bet]->cnt > 0) { n       cur = cur->to[bet]; n       ans += bet * (1 << (29 - i)); n       cur->cnt--; n     } else { n       cur = cur->to[1 - bet]; n       ans += (1 - bet) * (1 << (29 - i)); n       cur->cnt--; n     } n   } n   return ans; n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n; n   cin >> n; n   vector<long long> a(n); n   vector<long long> b(n); n   for (long long i = 0; i < n; ++i) { n     cin >> a[i]; n   } n   for (long long i = 0; i < n; ++i) { n     cin >> b[i]; n     addstring(b[i]); n   } n   for (long long i = 0; i < n; ++i) { n     cout << (get(a[i]) ^ a[i]) <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long k4, k7, i, l; n   char s[100]; n   long long n; n   gets(s); n   l = strlen(s); n   k4 = 0; n   k7 = 0; n   for (i = 0; i < l; i++) { n     if (s[i] ==  4 ) k4++; n     if (s[i] ==  7 ) k7++; n   } n   if (k4 == 0 && k7 == 0) n     cout << -1; n   else if (k7 > k4) n     cout << 7; n   else n     cout << 4; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int a[1000005]; n int main() { n   long long int i, j, k, l, n, m; n   cin >> n >> m; n   if (n / m < 3) { n     cout << -1; n     return 0; n   } n   j = 1; n   long long int f = 0; n   long long int x, y; n   x = 1, y = n - 1; n   while (y - x >= 4 && j < m) { n     a[x] = a[x + 1] = a[y] = j; n     j++; n     x += 2; n     y--; n   } n   while (x <= y) { n     a[x] = j; n     x++; n   } n   a[n] = j; n   for (i = 1; i <= n; i++) cout << a[i] <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n void vout(T x) { n   cout << x << endl; n   exit(0); n } n int gcd(int a, int b) { n   while (a && b) { n     if (a > b) n       a %= b; n     else n       b %= a; n   } n   return a + b; n } n const long long inf = -1e18; n const long long mod = 1e9; n long long dp[300][300], a[400]; n int n, k, x; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> k >> x; n   if (n / k > x) vout(-1); n   for (int i = 1; i <= n; ++i) cin >> a[i]; n   for (int i = 0; i < 300; ++i) { n     for (int j = 0; j < 300; ++j) dp[i][j] = inf; n   } n   dp[0][x] = 0; n   for (int i = 1; i <= n; ++i) { n     for (int j = 0; j < x; ++j) { n       for (int t = max(0, i - k); t <= i; ++t) { n         if (dp[t][j + 1] >= 0) dp[i][j] = max(dp[i][j], dp[t][j + 1] + a[i]); n       } n     } n   } n   long long ans = 0; n   for (int i = n - k + 1; i <= n; ++i) ans = max(ans, dp[i][0]); n   vout(ans); n   return 0; n } n


#include <bits/stdc++.h> n const long long INF = 0x3f3f3f3f; n using namespace std; n void sol() { n   long long n, m; n   while (cin >> n >> m) { n     string s; n     cin.ignore(); n     cin >> s; n     long long x[6][n]; n     string a[6] = { abc ,  acb ,  bca ,  bac ,  cab ,  cba }; n     memset(x, 0, sizeof(x)); n     ; n     for (long long i = 0; i < s.size(); i++) { n       if (i) { n         for (long long j = 0; j < 6; j++) { n           x[j][i] = x[j][i - 1]; n           if (s[i] != a[j][i % 3]) x[j][i]++; n         } n       } else { n         for (long long j = 0; j < 6; j++) { n           x[j][i] = 0; n           if (s[i] != a[j][i % 3]) x[j][i]++; n         } n       } n     } n     while (m--) { n       long long a, b; n       cin >> a >> b; n       long long ans = INF; n       if (a > 1) { n         for (long long i = 0; i < 6; i++) { n           ans = (x[i][b - 1] - x[i][a - 2] < ans ? x[i][b - 1] - x[i][a - 2] n                                                  : ans); n         } n       } else { n         for (long long i = 0; i < 6; i++) { n           ans = (x[i][b - 1] < ans ? x[i][b - 1] : ans); n         } n       } n       cout << ans <<   n ; n     } n   } n } n signed main() { n   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   ; n   long long t = 1; n   while (t--) { n     sol(); n     cout.flush(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-8; n const int dx[] = {1, 0, -1, 0, -1, -1, 1, 1}; n const int dy[] = {0, 1, 0, -1, -1, 1, -1, 1}; n const int OO = INT_MAX; n long long tolong(string s) { n   stringstream ss; n   ss << s; n   long long n; n   ss >> n; n   return n; n } n string toString(long long s) { n   stringstream ss; n   ss << s; n   string n; n   ss >> n; n   return n; n } n int main() { n   string x; n   cin >> x; n   long long n = tolong(x); n   if (x == toString(n)) { n     if (n >= -128 && n <= 127) { n       cout <<  byte ; n     } else if (n >= -32768 && n <= 32767) { n       cout <<  short ; n     } else if (n >= -2147483648 && n <= 2147483647) { n       cout <<  int ; n     } else { n       cout <<  long ; n     } n   } else { n     cout <<  BigInteger ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int pow1(long long int a, long long int b) { n   long long int ans = 1; n   while (b) { n     if (b & 1) ans = (ans * a) % 1000000007; n     a = (a * a) % 1000000007; n     b = b >> 1; n   } n   return ans; n } n int n, m; n pair<int, int> a[100005]; n vector<int> v[100005]; n bool vis[100005] = {0}; n void dfs(int x) { n   vis[x] = 1; n   for (int i = 0; i < v[x].size(); i++) n     if (!vis[v[x][i]]) dfs(v[x][i]); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> n >> m; n   for (int i = 0; i < n; i++) { n     cin >> a[i].first; n     a[i].second = i + 1; n   } n   sort(a, a + n); n   for (int i = 0; i < m; i++) { n     int x, y; n     cin >> x >> y; n     v[x].push_back(y); n     v[y].push_back(x); n   } n   long long int sum = 0; n   for (int i = 0; i < n; i++) { n     if (!vis[a[i].second]) { n       sum += a[i].first; n       dfs(a[i].second); n     } n   } n   cout << sum; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, r, f[60005]; n int dp[105][60005]; n struct node { n   int a, b, sign; n } pro[105]; n bool cmp(node a, node b) { n   if (a.sign == b.sign) { n     if (a.sign == 1) n       return a.a < b.a; n     else n       return a.a + a.b > b.a + b.b; n   } n   return a.sign < b.sign; n } n int main() { n   scanf( %d%d , &n, &r); n   for (register int i = 1; i <= n; i++) { n     scanf( %d%d , &pro[i].a, &pro[i].b); n     if (pro[i].b >= 0) n       pro[i].sign = 1; n     else n       pro[i].sign = 2, pro[i].a = max(pro[i].a, abs(pro[i].b)); n   } n   sort(pro + 1, pro + 1 + n, cmp); n   int s = r, sum = 0; n   vector<node> aa; n   for (register int i = 1; i <= n; i++) { n     if (pro[i].sign == 1 && s >= pro[i].a) n       s += pro[i].b, sum++; n     else n       aa.push_back(pro[i]); n   } n   dp[0][s] = sum; n   for (int i = 0; i < (int)(aa.size()); i++) n     for (register int j = 0; j <= s; j++) { n       if (j >= aa[i].a) n         dp[i + 1][j + aa[i].b] = max(dp[i + 1][j + aa[i].b], dp[i][j] + 1); n       dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]); n     } n   sum = 0; n   for (register int i = 0; i <= s; i++) sum = max(sum, dp[(int)(aa.size())][i]); n   printf( %d n , sum); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1000000000; n struct sTree { n   int pl, pr; n   int val, cnt, debt; n } tree[4000009]; n int treeSize; n int NewNode(int LL, int RR) { n   int cur = ++treeSize; n   tree[cur].cnt = RR - LL + 1; n   return cur; n } n void CalcDebt(int LL, int RR, int cur); n void Add(int L, int R, int d, int LL, int RR, int cur) { n   if (L <= LL && R >= RR) { n     tree[cur].debt += d; n     tree[cur].val += d; n     return; n   } n   int M = LL + (RR - LL) / 2; n   if (!tree[cur].pl) tree[cur].pl = NewNode(LL, M); n   if (!tree[cur].pr) tree[cur].pr = NewNode(M + 1, RR); n   CalcDebt(LL, RR, cur); n   if (L <= M && LL <= R) { n     Add(L, R, d, LL, M, tree[cur].pl); n   } n   if (L <= RR && M + 1 <= R) { n     Add(L, R, d, M + 1, RR, tree[cur].pr); n   } n   if (tree[tree[cur].pl].val < tree[tree[cur].pr].val) { n     tree[cur].val = tree[tree[cur].pl].val; n     tree[cur].cnt = tree[tree[cur].pl].cnt; n   } else if (tree[tree[cur].pl].val > tree[tree[cur].pr].val) { n     tree[cur].val = tree[tree[cur].pr].val; n     tree[cur].cnt = tree[tree[cur].pr].cnt; n   } else { n     tree[cur].val = tree[tree[cur].pl].val; n     tree[cur].cnt = tree[tree[cur].pl].cnt + tree[tree[cur].pr].cnt; n   } n } n int Get(int cur) { n   if (tree[cur].val == 0) { n     return 2 * inf + 1 - tree[cur].cnt; n   } n   return 2 * inf + 1; n } n void CalcDebt(int LL, int RR, int cur) { n   int M = LL + (RR - LL) / 2; n   Add(LL, M, tree[cur].debt, LL, M, tree[cur].pl); n   Add(M + 1, RR, tree[cur].debt, M + 1, RR, tree[cur].pr); n   tree[cur].debt = 0; n } n int n; n struct event { n   char type; n   int p, L, R; n } e[200009]; n bool operator<(event a, event b) { n   if (a.p != b.p) return a.p < b.p; n   return a.type < b.type; n } n int main() { n   ios::sync_with_stdio(false); n   cin >> n; n   for (int i = 0; i < n; i++) { n     int x1, y1, x2, y2; n     cin >> x1 >> y1 >> x2 >> y2; n     x1 += inf, y1 += inf, x2 += inf, y2 += inf; n     e[2 * i].type =  + ; n     e[2 * i].p = min(x1, x2) - 1; n     e[2 * i].L = min(y1, y2); n     e[2 * i].R = max(y1, y2); n     e[2 * i + 1].type =  - ; n     e[2 * i + 1].p = max(x1, x2); n     e[2 * i + 1].L = min(y1, y2); n     e[2 * i + 1].R = max(y1, y2); n   } n   sort(e, e + 2 * n); n   int root = NewNode(0, 2 * inf); n   long long ans = 0; n   int prev = -1; n   for (int i = 0; i < 2 * n; i++) { n     int j = i; n     while (j + 1 < 2 * n && e[j + 1].p == e[i].p) j++; n     ans += 1LL * Get(root) * (e[i].p - prev); n     for (int k = i; k <= j; k++) { n       if (e[k].type ==  + ) { n         Add(e[k].L, e[k].R, 1, 0, 2 * inf, root); n       } else { n         Add(e[k].L, e[k].R, -1, 0, 2 * inf, root); n       } n     } n     i = j; n     prev = e[i].p; n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long n, m; n   cin >> n >> m; n   map<int, int> a; n   long long x; n   for (long long i = 0; i < m; i++) { n     cin >> x; n     a[x]++; n   } n   long long mini = INT_MAX; n   for (long long i = 1; i <= n; i++) { n     if (mini > a[i]) { n       mini = a[i]; n     } n   } n   cout << mini << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int x; n   string s1, s2; n   int cnt = 0; n   cin >> x >> ws; n   for (int i = x; i; i--) { n     cin >> s1; n     cin >> s2; n     if (s2.compare( soft ) == 0) cnt++; n   } n   if (x - cnt > cnt) cnt = x - cnt; n   for (int i = 0; i < 100; ++i) { n     if (i * i / 2 + i % 2 >= cnt && i * i >= x) { n       cout << i << endl; n       return 0; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   int x = 0, f = 1, c = getchar(); n   for (; !isdigit(c); c = getchar()) n     if (c ==  - ) f ^= 1; n   for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ; n   return f ? x : -x; n } n const int N = 200005; n int n, m; n char s[N]; n struct H { n   int a, b; n }; n H h[N][26], pw[N]; n const int mul1 = 233, mod1 = 998244353; n const int mul2 = 19260817, mod2 = 1000000007; n vector<H> cal(int x, int l) { n   vector<H> ans; n   for (int i = 0; i < 26; ++i) { n     H a = (H){}; n     a.a = (h[x + l][i].a - 1LL * h[x][i].a * pw[l].a % mod1 + mod1) % mod1; n     a.b = (h[x + l][i].b - 1LL * h[x][i].b * pw[l].b % mod2 + mod2) % mod2; n     ans.push_back(a); n   } n   sort(ans.begin(), ans.end(), [&](H a, H b) { n     if (a.a != b.a) return a.a < b.a; n     return a.b < b.b; n   }); n   return ans; n } n int main() { n   n = read(), m = read(); n   scanf( %s , s); n   pw[0].a = pw[0].b = 1; n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < 26; ++j) { n       h[i + 1][j].a = 1LL * h[i][j].a * mul1 % mod1; n       h[i + 1][j].b = 1LL * h[i][j].b * mul2 % mod2; n     } n     h[i + 1][s[i] -  a ].a = (h[i + 1][s[i] -  a ].a + 1) % mod1; n     h[i + 1][s[i] -  a ].b = (h[i + 1][s[i] -  a ].b + 1) % mod2; n     pw[i + 1].a = 1LL * pw[i].a * mul1 % mod1; n     pw[i + 1].b = 1LL * pw[i].b * mul2 % mod2; n   } n   for (; m--;) { n     int x = read() - 1, y = read() - 1, l = read(); n     vector<H> a = cal(x, l), b = cal(y, l); n     bool ok = 1; n     for (int i = 0; i < 26; ++i) { n       if (a[i].a != b[i].a || a[i].b != b[i].b) ok = 0; n     } n     puts(ok ?  YES  :  NO ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   scanf( %d , &n); n   int cir = 0; n   bool ans = true; n   int now; n   for (int i = 0; i < n; i++) { n     if (!i) { n       scanf( %d , &now); n       continue; n     } n     int temp; n     scanf( %d , &temp); n     if (temp > now) { n       if (cir != 0) { n         ans = false; n       } n       now = temp; n     } else if (temp == now) { n       if (cir == 0) { n         cir = 1; n       } else if (cir == 1) { n       } else { n         ans = false; n       } n     } else { n       if (cir == 0 || cir == 1) { n         cir = 2; n       } n     } n     now = temp; n   } n   if (ans) n     printf( YES n ); n   else n     printf( NO n ); n } n


#include <bits/stdc++.h> n using namespace std; n int c[3]; n void solve() { n   int m, n; n   cin >> m >> n; n   vector<vector<int>> matrix(m, vector<int>(n)); n   for (int i = 0; i < m; i++) { n     for (int j = 0; j < n; j++) { n       cin >> matrix[i][j]; n     } n   } n   for (int i = m - 1; i >= 0; --i) { n     for (int j = n - 1; j >= 0; --j) { n       if (matrix[i][j] != 0) { n         continue; n       } else { n         int check; n         check = matrix[i][j + 1] - 1; n         if (check >= matrix[i + 1][j]) check = matrix[i + 1][j] - 1; n         matrix[i][j] = check; n       } n     } n   } n   for (int i = m - 1; i >= 0; --i) { n     for (int j = n - 1; j >= 0; --j) { n       if (i != 0 && j != 0) { n         if ((matrix[i][j] <= matrix[i][j - 1]) || n             (matrix[i][j] <= matrix[i - 1][j])) { n           cout <<  -1  << endl; n           return; n         } n       } n     } n   } n   int sum = 0; n   for (int i = 0; i < m; i++) { n     for (int j = 0; j < n; j++) { n       sum += matrix[i][j]; n     } n   } n   cout << sum << endl; n   return; n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int t, x, y, f1, f2, f3, f4, LIMH = 100000, LIML = -100000; n   cin >> t; n   while (t--) { n     int q; n     cin >> q; n     int hiX, loX, hiY, loY; n     hiX = LIMH; n     hiY = LIMH; n     loX = LIML; n     loY = LIML; n     for (int i = 0; i < q; i++) { n       cin >> x >> y >> f1 >> f2 >> f3 >> f4; n       if (!f1 && x > loX) loX = x; n       if (!f2 && y < hiY) hiY = y; n       if (!f3 && x < hiX) hiX = x; n       if (!f4 && y > loY) loY = y; n     } n     if (loX > hiX || loY > hiY) n       cout << 0 << endl; n     else n       cout << 1 <<     << loX <<     << loY << endl; n   } n   return 0; n } n


#include <iostream> n  n using namespace std; n int c1=0,c2=0,cur1=1,cur2=1,ok1=0,ok2=0; n pair<int,int> f1[105*105],f2[150*105]; n void fa1(int val){ n     cout<<val<<   ; n     cout<<f1[cur1].first<<   <<f1[cur1].second<<  n ; n     cur1++; n     if(cur1==c1+1) n         ok1=1; n } n void fa2(int val){ n     cout<<val<<   ; n     cout<<f2[cur2].first<<   <<f2[cur2].second<<  n ; n     cur2++; n     if(cur2==c2+1){ n         ok2=1; n     } n } n int main() n { n     int n,a; n     cin>>n; n     int t=n*n; n     for(int i=1;i<=n;i++){ n         for(int j=1;j<=n;j++){ n             if((i+j)%2==1){ n                 f1[++c1]=make_pair(i,j); n             } n             else{ n                 f2[++c2]=make_pair(i,j); n             } n         } n     } n     while(t--){ n         cin>>a; n         if(a==1){ n             if(ok2==1){ n                 fa1(3); n             } n             else{ n                 fa2(2); n             } n         } n         if(a==2){ n             if(ok1==1){ n                 fa2(3); n             } n             else{ n                 fa1(1); n             } n         } n         if(a==3){ n             if(ok1==1){ n                 fa2(2); n             } n             else{ n                 fa1(1); n             } n         } n         cout<<  n ; n     } n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   string str; n   for (int o = 0; o < t; o++) { n     cin >> str; n     int n = str.length(); n     int pre = 0, suf = 0, total = 0; n     if (str[0] ==  1 ) { n       pre = 0; n     } else { n       pre = 1; n       for (int i = 1; i < n; i++) { n         if (str[i] ==  0 ) { n           pre = pre + 1; n         } else { n           break; n         } n       } n     } n     if (str[n - 1] ==  1 ) { n       suf = 0; n     } else { n       suf = 1; n       for (int j = n - 2; j > 0; j--) { n         if (str[j] ==  0 ) { n           suf = suf + 1; n         } else { n           break; n         } n       } n     } n     for (int k = 0; k < n; k++) { n       if (str[k] ==  0 ) { n         total = total + 1; n       } n     } n     int ans = total - suf - pre; n     if (pre == total) { n       cout <<  0  << endl; n     } else { n       cout << ans << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100000 + 1; n int n, m, s; n int b[maxn]; n int p[maxn]; n int ansn, anst; n bool ok(int k) { n   int i = n - 1; n   int j = k - 1; n   int tansn = 0, tanst = 0; n   int ss = s; n   while (j >= 0) { n     if (i >= 0 && b[i] >= p[j]) { n       tanst += p[j]; n       tansn++; n       j--; n       i--; n     } else if (i >= 0 && p[j] > b[i] && ss >= p[j] - b[i]) { n       tanst += b[i]; n       tansn++; n       ss -= (p[j] - b[i]); n       j--; n       i--; n     } else if (i >= 0) n       i--; n     else n       j--; n   } n   if (ss > 0) tanst = max(0, tanst - ss); n   if (tansn == k && tansn > ansn) { n     ansn = tansn; n     anst = tanst; n   } n   return tansn == k; n } n int main() { n   scanf( %d %d %d , &n, &m, &s); n   for (int i = 0; i < n; i++) scanf( %d , b + i); n   for (int i = 0; i < m; i++) scanf( %d , p + i); n   sort(b, b + n); n   sort(p, p + m); n   int l = 0; n   int r = m + 1; n   int mid; n   while (l + 1 < r) { n     mid = (l + r) / 2; n     if (ok(mid)) n       l = mid; n     else n       r = mid; n   } n   printf( %d %d n , ansn, anst); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   char ch[6] =  aaaaa ; n   int ara[4] = {0}; n   cin >> s; n   map<char, int> ms, ms2; n   for (int i = 0; i < s.size(); i += 4) { n     for (int j = 0; j < 4 && (i + j) < s.size(); j++) { n       if (s[i + j] ==  ! ) { n         ara[j]++; n       } else { n         ch[j] = s[i + j]; n         if (!ms2[ch[j]]) ms2[ch[j]] = j; n       } n     } n   } n   int sz = s.size(); n   for (int i = 0; i < 4; i++) { n     if (ch[i] ==  a ) { n       if (!ms2[ R ]) { n         ch[i] =  R ; n         ms2[ R ] = 1; n       } else if (!ms2[ G ]) { n         ch[i] =  G ; n         ms2[ G ] = 1; n       } else if (!ms2[ B ]) { n         ch[i] =  B ; n         ms2[ B ] = 1; n       } else if (!ms2[ Y ]) { n         ch[i] =  Y ; n         ms2[ Y ] = 1; n       } n     } n     ms[ch[i]] = ara[i]; n   } n   cout << ms[ R ] <<     << ms[ B ] <<     << ms[ Y ] <<     << ms[ G ]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int DBG = 0, INF = int(1e9); n string toString(long long k) { n   stringstream ss; n   ss << k; n   string res; n   ss >> res; n   return res; n } n int toInt(string s) { n   stringstream ss; n   ss << s; n   int res; n   ss >> res; n   return res; n } n int main() { n   ios_base::sync_with_stdio(0); n   cout.setf(ios::fixed); n   cout << setprecision(10); n   int n, a, d; n   cin >> n >> a >> d; n   vector<pair<int, int> > V(n); n   for (int _n = (n), i = 0; i < _n; ++i) cin >> V[i].first >> V[i].second; n   double prev = -1; n   for (int _n = (n), i = 0; i < _n; ++i) { n     double accTime = double(V[i].second) / double(a); n     double accDst = double(V[i].second) * accTime * 0.5; n     if (accDst >= d) { n       double t = sqrt((2. * double(d)) / double(a)); n       prev = max(t + double(V[i].first), prev); n     } else { n       double remDst = d - accDst; n       double remTime = remDst / double(V[i].second); n       prev = max(accTime + remTime + double(V[i].first), prev); n     } n     cout << prev << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n const long long mod = 998244353; n const long long inf = 1e18 + 10; n using namespace std; n long long modpow(long long a, long long b) { n   long long res = 1; n   while (b) { n     if (b % 2) { n       res *= a; n     } n     a *= a; n     res %= mod; n     a %= mod; n     b /= 2; n   } n   return res; n } n long long nCr(long long n, long long r) { n   long long f = 1; n   for (long long i = 2; i <= n; i++) { n     f *= i; n     f %= mod; n   } n   long long q = 1; n   for (long long i = 2; i <= r; i++) { n     q *= i; n     q %= mod; n   } n   long long q2 = 1; n   for (long long i = 2; i <= n - r; i++) { n     q2 *= i; n     q2 %= mod; n   } n   q = modpow(q, mod - 2); n   q2 = modpow(q2, mod - 2); n   f *= q; n   f %= mod; n   f *= q2; n   f %= mod; n   return f; n } n int32_t main() { n   std::ios::sync_with_stdio(false); n   cin.tie(NULL); n   long long n; n   cin >> n; n   long long a[2 * n]; n   for (long long i = 0; i < 2 * n; i++) cin >> a[i]; n   sort(a, a + 2 * n); n   long long l = 0, r = 0; n   for (long long i = 0; i < n; i++) l += a[i]; n   for (long long i = n; i < 2 * n; i++) r += a[i]; n   long long ans = r - l; n   ans %= mod; n   cout << ((ans * nCr(2 * n, n)) % mod) <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const unsigned int N = 150; n unsigned int n, p, q, now[N], c[N], ans; n inline unsigned int read() { n   unsigned int x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = (x << 3) + (x << 1) + (ch ^ 48); n     ch = getchar(); n   } n   return x * f; n } n unsigned int gcd(unsigned int a, unsigned int b) { n   return !b ? a : gcd(b, a % b); n } n signed main() { n   n = read(); n   p = read(); n   q = read(); n   for (unsigned int i = 0; i <= min(p, n - 1); i++) { n     for (unsigned int j = 1; j <= i; j++) now[j] = n - j + 1; n     for (unsigned int j = 1; j <= i; j++) { n       unsigned int x = j; n       for (unsigned int k = i; k >= 1; k--) { n         unsigned int g = gcd(now[k], x); n         if (g != 1) { n           now[k] /= g; n           x /= g; n           if (x == 1) break; n         } n       } n     } n     c[i] = 1; n     for (unsigned int j = 1; j <= i; j++) c[i] = c[i] * now[j]; n   } n   for (unsigned int i = 1; i <= q; i++) { n     unsigned int res = 0, em = 1; n     for (unsigned int j = 0; j <= min(p, n - 1); j++) { n       res += em * c[j]; n       em = em * i; n     } n     ans ^= (res * i); n   } n   cout << ans << endl; n   fclose(stdin); n   fclose(stdout); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, x; n   cin >> n >> x; n   int eq = 0; n   int minPos = 1, maxPos; n   for (int i(0); i < n; i++) { n     int a; n     cin >> a; n     if (a < x) n       minPos++; n     else if (a == x) n       eq++; n   } n   int c = 0; n   if (eq == 0) { n     c++; n     maxPos = minPos; n   } else n     maxPos = minPos + eq - 1; n   while ((minPos > (n + c + 1) / 2) || (maxPos < (n + c + 1) / 2)) { n     if (maxPos < (n + c + 1) / 2) { n       minPos++; n       maxPos++; n     }; n     c++; n   } n   cout << c << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 100100; n const long long oo = 1e18; n int N; n long long P[MAX], D[MAX]; n int L[MAX], R[MAX]; n void init_L() { n   stack<int> S; n   for (int i = 0; i <= N + 1; ++i) { n     while (S.size() >= 2) { n       int x = S.top(); n       S.pop(); n       if (D[x] >= P[i] - P[S.top()]) { n         S.push(x); n         break; n       } n     } n     if (!S.empty()) L[i] = S.top(); n     S.push(i); n   } n } n void init_R() { n   stack<int> S; n   for (int i = N + 1; i >= 0; --i) { n     while (S.size() >= 2) { n       int x = S.top(); n       S.pop(); n       if (D[x] >= P[S.top()] - P[i]) { n         S.push(x); n         break; n       } n     } n     if (!S.empty()) R[i] = S.top(); n     S.push(i); n   } n } n long long low(int x) { n   if (x == N + 1) return -1e10; n   long long ret = P[R[x]] - D[x]; n   return ret < P[x] ? ret : +oo; n } n long long high(int x) { n   if (x == 0) return +1e10; n   long long ret = P[L[x]] + D[x]; n   return ret > P[x] ? ret : -oo; n } n bool check(long long W) { n   multiset<long long> S; n   for (int a = 0, b = 0; a <= N; ++a) { n     for (; b <= N + 1 && P[b] - P[a] <= W; ++b) S.insert(low(b)); n     S.erase(S.find(low(a))); n     if (!S.empty() && high(a) >= *S.begin()) return true; n   } n   return false; n } n int main() { n   scanf( %d , &N); n   for (int i = 0; i <= N + 1; ++i) scanf( %lld , P + i); n   for (int i = 1; i <= N; ++i) scanf( %lld , D + i), D[i] *= 2; n   D[0] = D[N + 1] = oo; n   init_L(); n   init_R(); n   if (R[0] != N + 1) { n     puts( 0 ); n     return 0; n   } n   long long lo = 1, hi = 1e10; n   while (lo < hi) { n     long long mid = (lo + hi) / 2; n     check(mid) ? hi = mid : lo = mid + 1; n   } n   printf( %.1lf n , lo / 2.0); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-8; n const double C = 0.57721566490153286060651209; n const double pi = acos(-1.0); n const int mod = 1e9 + 7; n const int maxn = 1e5 + 10; n int a[maxn]; n int b[maxn]; n int used[maxn]; n int main() { n   int n; n   scanf( %d , &n); n   int k = 0; n   for (int i = 1; i <= n; ++i) { n     scanf( %d , &a[i]); n     b[a[i]]++; n     if (b[a[i]] & 1) n       k++; n     else n       k--; n   } n   if (k > 1) { n     printf( 0 n ); n     return 0; n   } n   long long pos = 0; n   for (int i = 1; i <= n / 2; ++i) n     if (a[i] != a[n - i + 1]) { n       pos = i; n       break; n     } else n       b[a[i]] -= 2; n   if (!pos) { n     printf( %lld n , 1LL * n * (n + 1) / 2); n     return 0; n   } n   int len = 0; n   for (int i = pos; i <= n; ++i) { n     used[a[i]]++; n     if (used[a[i]] * 2 > b[a[i]]) { n       if (i < n - i + 1 || (i == n - i + 1 && b[a[i]] % 2 == 0) || n           a[i] != a[n - i + 1]) n         break; n     } n     len++; n   } n   memset(used, 0, sizeof used); n   for (int i = n - pos + 1; i >= 1; --i) { n     used[a[i]]++; n     if (used[a[i]] * 2 > b[a[i]]) n       if (i > n - i + 1 || (i == n - i + 1 && b[a[i]] % 2 == 0) || n           a[i] != a[n - i + 1]) n         break; n     len++; n   } n   printf( %lld n , pos * (pos + len)); n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int n, k; n long long arr[200001]; n vector<long long> v; n string s; n int find(int i) { n   int curr = v[i]; n   int num = i; n   for (int j = i + 1; j < n; j++) n     if (v[j] == curr) n       num = j; n     else n       break; n   return num; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   ; n   cin >> n >> k; n   for (int i = 0; i < n; i++) cin >> arr[i]; n   cin >> s; n   for (int i = 0; i < n; i++) { n     int a = s[i] -  a ; n     v.push_back(a); n   } n   int count = 1; n   long long d = 0; n   int prev; n   for (int i = 0; i < n; i++) { n     int nx = find(i); n     int dis = nx - i + 1; n     if (dis <= k) { n       for (int j = i; j <= nx; j++) d += arr[j]; n     } else { n       sort(arr + i, arr + nx + 1); n       for (int j = nx; j >= nx - k + 1; j--) d += arr[j]; n     } n     i = nx; n   } n   cout << d; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> adj[500010], ar; n bool vis[500010]; n int u, v, n, m, s, res = 0; n void dfs(int cur) { n   vis[cur] = true; n   for (auto i : adj[cur]) n     if (!vis[i]) dfs(i); n   ar.push_back(cur); n } n int main() { n   scanf( %d%d%d , &n, &m, &s); n   for (int i = 0; i < m; ++i) { n     scanf( %d%d , &u, &v); n     adj[u].push_back(v); n   } n   dfs(s); n   for (int i = 1; i <= n; ++i) { n     if (!vis[i]) dfs(i); n   } n   memset(vis, false, sizeof vis); n   for (int i = n - 1; i >= 0; --i) { n     if (!vis[ar[i]]) { n       if (s != ar[i]) res++; n       dfs(ar[i]); n     } n   } n   printf( %d n , res); n   return 0; n } n


#include <bits/stdc++.h> n long long a[100005]; n long long count[100005]; n int vis[100005]; n struct Element { n   long long l, r; n   Element(long long l, long long r) : l(l), r(r) {} n }; n Element getCount(long long k, int n) { n   long long lower = 0, upper = 0; n   int met = 0; n   for (int i = 1; i <= n; i++) { n     long long l = 1, r = a[i]; n     long long res = 0; n     while (l <= r) { n       long long m = (l + r) / 2; n       long long value = a[i] - 3ll * m * m + 3 * m - 1; n       if (value >= k) { n         res = m; n         l = m + 1; n       } else n         r = m - 1; n     } n     lower += res, upper += res; n     count[i] = res; n     long long value = a[i] - 3ll * res * res + 3 * res - 1; n     if (value == k) { n       vis[i] = 1; n       count[i]--; n       if (!met) n         met = 1; n       else n         lower--; n     } else n       vis[i] = 0; n   } n   return Element(lower, upper); n } n int main() { n   int n; n   long long k; n   scanf( %d%lld , &n, &k); n   for (int i = 1; i <= n; i++) scanf( %lld , &a[i]); n   long long l = -3e18, r = 1e10; n   while (l <= r) { n     long long m = (l + r) / 2; n     Element u = getCount(m, n); n     if (u.l > k) n       l = m + 1; n     else if (u.r < k) n       r = m - 1; n     else { n       break; n     } n   } n   long long need = k; n   for (int i = 1; i <= n; i++) need -= count[i]; n   for (int i = 1; i <= n; i++) { n     if (need && vis[i]) { n       need--; n       count[i]++; n     } n     printf( %lld  , count[i]); n   } n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, s, k, a[2010], b[2010], nxt[2010], sum[2010], dp[2010][2010]; n inline int read() { n   int s = 0, w = 1; n   char c = getchar(); n   for (; !isdigit(c); c = getchar()) n     if (c ==  - ) w = -1; n   for (; isdigit(c); c = getchar()) s = (s << 1) + (s << 3) + (c ^ 48); n   return s * w; n } n bool check(int mid) { n   for (int i = 1; i <= n; ++i) sum[i] = sum[i - 1] + (a[i] <= b[mid]); n   memset(dp, 0, sizeof(dp)); n   for (int i = 1; i <= s; ++i) { n     for (int j = 1; j <= n; ++j) dp[i][j] = max(dp[i][j], dp[i - 1][j]); n     for (int j = 1; j <= n; ++j) n       if (nxt[j]) n         dp[i][nxt[j]] = n             max(dp[i][nxt[j]], dp[i - 1][j - 1] + sum[nxt[j]] - sum[j - 1]); n     for (int j = 1; j <= n; ++j) dp[i][j] = max(dp[i][j - 1], dp[i][j]); n   } n   return dp[s][n] >= k; n } n int main() { n   n = read(), m = read(), s = read(), k = read(); n   for (int i = 1; i <= n; ++i) a[i] = read(), b[i] = a[i]; n   sort(b + 1, b + 1 + n); n   for (int i = 1; i <= m; ++i) { n     int l = read(), r = read(); n     for (int j = l; j <= r; ++j) nxt[j] = max(nxt[j], r); n   } n   int l = 1, r = n, ans = -1; n   while (l <= r) { n     int mid = (l + r) >> 1; n     if (check(mid)) n       ans = b[mid], r = mid - 1; n     else n       l = mid + 1; n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k; n string a; n int b[10000]; n int memo[2000][2000]; n int dp(int i, int d) { n   if (abs(d) == k && i == a.length()) return 0; n   if (i == a.length() || abs(d) == k) return 1; n   if (memo[i][d] != -1) return memo[i][d]; n   int x; n   if (a[i] ==  L ) n     x = dp(i + 1, d - 1); n   else if (a[i] ==  W ) n     x = dp(i + 1, d + 1); n   else if (a[i] ==  D ) n     x = dp(i + 1, d); n   else { n     b[i] =  W  -  A ; n     x = dp(i + 1, d + 1); n     if (x == 1) { n       b[i] =  L  -  A ; n       x = dp(i + 1, d - 1); n     } n     if (x == 1) { n       b[i] =  D  -  A ; n       x = dp(i + 1, d); n     } n   } n   return memo[i][d] = x; n } n int main() { n   memset(memo, -1, sizeof(memo)); n   cin >> n >> k >> a; n   if (dp(0, 0) == 1) n     cout <<  NO ; n   else { n     for (int i = 0; i < a.length(); i++) { n       if (a[i] !=  ? ) n         cout << a[i]; n       else n         cout << (char)(b[i] +  A ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX_N = 1e3 + 5; n const double eps = 1e-10; n struct TARGET { n   int x, y, t; n   double p; n } mp[MAX_N]; n int n; n double dis[MAX_N][MAX_N]; n double dp[MAX_N]; n bool MAP_CMP(TARGET a, TARGET b) { return a.t < b.t; } n void input() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) n     scanf( %d%d%d%lf , &mp[i].x, &mp[i].y, &mp[i].t, &mp[i].p); n } n int sqr(int x) { return x * x; } n void solve() { n   sort(mp, mp + n, MAP_CMP); n   for (int i = 0; i < n; i++) n     for (int j = 0; j < i; j++) n       dis[i][j] = dis[j][i] = sqr(mp[i].x - mp[j].x) + sqr(mp[i].y - mp[j].y); n   for (int i = 0; i < n; i++) dp[i] = mp[i].p; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < i; j++) { n       if (1ll * (mp[i].t - mp[j].t) * (mp[i].t - mp[j].t) >= dis[i][j]) n         dp[i] = max(dp[i], dp[j] + mp[i].p); n     } n   double ans = 0.0; n   for (int i = 0; i < n; i++) n     if (dp[i] > ans) ans = dp[i]; n   printf( %.6f n , ans); n } n int main() { n   input(); n   solve(); n   return 0; n } n


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


#include <bits/stdc++.h> n const int M = 1e9 + 7, N = 2 * 1e5 + 3; n using namespace std; n int main() { n   long long a, b, f, k, b0; n   cin >> a >> b >> f >> k; n   b0 = b; n   int ans = 0; n   if (b < f || b < a - f) { n     cout << -1; n     return 0; n   } n   b0 = b - f; n   if (b0 < 0) { n     cout << -1; n     return 0; n   } n   bool q = 1; n   while (k > 1) { n     if (q) { n       if (b0 < (a - f) * 2) b0 = b, ans++; n       b0 -= (a - f) * 2; n       if (b0 < 0) { n         cout << -1; n         return 0; n       } n       q = 0; n       k--; n     } else { n       if (b0 < 2 * f) b0 = b, ans++; n       b0 -= 2 * f; n       if (b0 < 0) { n         cout << -1; n         return 0; n       } n       q = 1; n       k--; n     } n   } n   if (q && b0 < a - f || !q && b0 < f) n     cout << ans + 1; n   else n     cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long maxn = 1e5 + 7; n const long long inf = 0x3f3f3f3f3f3f3f; n const long long mod = 20000311; n int n; n vector<int> a(100), b(100); n vector<int> step[100], ves[100]; n void solve(int n) { n   int st = 0; n   for (int i = 0; i < step[n].size(); i++) { n     ves[i].clear(); n     for (int j = st; j < st + step[n][i]; j++) ves[i].push_back(a[j]); n     st += step[n][i]; n   } n   a.clear(); n   for (int i = step[n].size() - 1; i >= 0; i--) n     for (auto j : ves[i]) a.push_back(j); n } n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i], b[a[i]] = i; n   if (n == 1) { n     cout << 0 <<   n ; n     return 0; n   } n   step[1].push_back(b[1]), step[1].push_back(n - b[1]); n   solve(1); n   int flag = n % 2 == 0; n   for (int go = 2; go + flag <= n; go++) { n     if (go % 2 == 0) { n       for (int i = 1; i < go; i++) step[go].push_back(1); n       int cnt = 1; n       while (a[cnt] != go) cnt++; n       if (cnt - go + 2) step[go].push_back(cnt - go + 2); n       if (n - cnt - 1) step[go].push_back(n - cnt - 1); n       solve(go); n     } else { n       int cnt = n - 1; n       while (a[cnt] != go) cnt--; n       if (cnt) step[go].push_back(cnt); n       if (n - go + 1 - cnt) step[go].push_back(n - go + 1 - cnt); n       for (int i = 1; i < go; i++) step[go].push_back(1); n       solve(go); n     } n   } n   int tot = 0, st = 1; n   if (b[1] == 0) st = 2; n   cout << n - flag - st + 1 <<   n ; n   for (int i = st; i <= n - flag; i++) { n     cout << step[i].size() <<    ; n     for (auto j : step[i]) cout << j <<    ; n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 2e5 + 3; n struct tree { n   int l, r, minn, lazy; n   long long sum; n } tre[MAXN << 2]; n int n, m; n long long a[MAXN]; n void build(int i, int l, int r) { n   tre[i].l = l, tre[i].r = r; n   tre[i].lazy = 0; n   if (l == r) { n     tre[i].minn = a[l]; n     tre[i].sum = a[l]; n     return; n   } n   int mid = l + r >> 1; n   build(i << 1, l, mid); n   build(i << 1 | 1, mid + 1, r); n   tre[i].minn = min(tre[i << 1].minn, tre[i << 1 | 1].minn); n   tre[i].sum = tre[i << 1].sum + tre[i << 1 | 1].sum; n } n void pushdown(int i) { n   if (tre[i].lazy) { n     tre[i << 1].minn = tre[i].lazy, tre[i << 1 | 1].minn = tre[i].lazy; n     tre[i << 1].lazy = tre[i << 1 | 1].lazy = tre[i].lazy; n     tre[i << 1].sum = 1ll * (tre[i << 1].r - tre[i << 1].l + 1) * tre[i].lazy; n     tre[i << 1 | 1].sum = n         1ll * (tre[i << 1 | 1].r - tre[i << 1 | 1].l + 1) * tre[i].lazy; n     tre[i].lazy = 0; n   } n } n int find_(int i, int l, int r, long long x) { n   if (tre[i].l >= l && tre[i].r <= r) { n     if (tre[i].minn > x) return 0; n     if (tre[i].l == tre[i].r) { n       if (tre[i].minn <= x) return tre[i].r; n       return 0; n     } n     pushdown(i); n     tre[i].minn = min(tre[i << 1].minn, tre[i << 1 | 1].minn); n     tre[i].sum = tre[i << 1].sum + tre[i << 1 | 1].sum; n     if (tre[i << 1].minn > x) return find_(i << 1 | 1, l, r, x); n     return find_(i << 1, l, r, x); n   } n   if (tre[i].l == tre[i].r) return 0; n   pushdown(i); n   int ans = 0; n   if (tre[i << 1].r >= l) ans = find_(i << 1, l, r, x); n   if (!ans && tre[i << 1 | 1].l <= r) { n     ans = find_(i << 1 | 1, l, r, x); n   } n   tre[i].minn = min(tre[i << 1].minn, tre[i << 1 | 1].minn); n   tre[i].sum = tre[i << 1].sum + tre[i << 1 | 1].sum; n   return ans; n } n void modify(int i, int l, int r, int delta) { n   if (tre[i].l > r || tre[i].r < l) return; n   if (tre[i].l >= l && tre[i].r <= r) { n     tre[i].lazy = delta; n     tre[i].minn = delta; n     tre[i].sum = 1ll * (tre[i].r - tre[i].l + 1) * delta; n     return; n   } n   pushdown(i); n   modify(i << 1, l, r, delta); n   modify(i << 1 | 1, l, r, delta); n   tre[i].minn = min(tre[i << 1].minn, tre[i << 1 | 1].minn); n   tre[i].sum = tre[i << 1].sum + tre[i << 1 | 1].sum; n } n bool flag; n void que(int i, long long &delta, int &tot) { n   if (tre[i].l == tre[i].r) { n     if (delta >= tre[i].sum) tot = max(tot, tre[i].r), delta -= tre[i].sum; n     return; n   } n   pushdown(i); n   tre[i].minn = min(tre[i << 1].minn, tre[i << 1 | 1].minn); n   tre[i].sum = tre[i << 1].sum + tre[i << 1 | 1].sum; n   if (tre[i << 1].sum <= delta) { n     tot = max(tot, tre[i << 1].r); n     delta -= tre[i << 1].sum; n     que(i << 1 | 1, delta, tot); n   } else { n     que(i << 1, delta, tot); n   } n } n void query(int i, int l, int r, long long &delta, int &tot) { n   if (tre[i].l > r || tre[i].r < l || flag) return; n   if (tre[i].l >= l && tre[i].r <= r) { n     if (tre[i].sum <= delta) { n       tot = max(tre[i].r, tot); n       delta -= tre[i].sum; n       return; n     } n     if (tre[i].l == tre[i].r) { n       if (tre[i].sum <= delta) { n         tot = max(tot, tre[i].r), delta -= tre[i].sum; n       } else n         flag = 1; n       return; n     } n     flag = 1; n     que(i, delta, tot); n     pushdown(i); n     tre[i].minn = min(tre[i << 1].minn, tre[i << 1 | 1].minn); n     tre[i].sum = tre[i << 1].sum + tre[i << 1 | 1].sum; n     return; n   } n   pushdown(i); n   tre[i].minn = min(tre[i << 1].minn, tre[i << 1 | 1].minn); n   tre[i].sum = tre[i << 1].sum + tre[i << 1 | 1].sum; n   query(i << 1, l, r, delta, tot); n   query(i << 1 | 1, l, r, delta, tot); n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) scanf( %lld , &a[i]); n   build(1, 1, n); n   for (int i = 1; i <= m; i++) { n     int x, op; n     long long y; n     scanf( %d%d%lld , &op, &x, &y); n     if (op == 1) { n       int tot = find_(1, 1, x, y); n       if (!tot) continue; n       modify(1, tot, x, y); n     } else { n       int an = 0; n       while (x <= n) { n         int tot = find_(1, x, n, y); n         int tot1 = 0; n         flag = 0; n         query(1, tot, n, y, tot1); n         if (tot == 0 || tot1 == 0) break; n         an += tot1 - tot + 1, x = tot1 + 1; n       } n       printf( %d n , an); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   map<pair<int, int>, int> f; n   int t, it, n, res, tmp, x, y, resr, resl, i; n   string s; n   cin >> t; n   for (it = 1; it <= t; it++) { n     cin >> n; n     cin >> s; n     s =     + s; n     x = 0; n     y = 0; n     resr = 1e8; n     resl = -1e8; n     for (i = 1; i <= n; i++) { n       if (s[i] ==  D ) { n         x--; n         if (f[{x, y}] != 0) { n           if ((i - f[{x, y}] - 1) < (resr - resl)) { n             resr = i; n             resl = f[{x, y}] + 1; n           } n         } n         if ((x == 0) && (y == 0)) { n           if ((i - 1) < (resr - resl)) { n             resr = i; n             resl = 1; n           } n         } n         f[{x, y}] = i; n       } else if (s[i] ==  U ) { n         x++; n         if (f[{x, y}] != 0) { n           if ((i - f[{x, y}] - 1) < (resr - resl)) { n             resr = i; n             resl = f[{x, y}] + 1; n           } n         } n         if ((x == 0) && (y == 0)) { n           if ((i - 1) < (resr - resl)) { n             resr = i; n             resl = 1; n           } n         } n         f[{x, y}] = i; n       } else if (s[i] ==  L ) { n         y--; n         if (f[{x, y}] != 0) { n           if ((i - f[{x, y}] - 1) < (resr - resl)) { n             resr = i; n             resl = f[{x, y}] + 1; n           } n         } n         if ((x == 0) && (y == 0)) { n           if ((i - 1) < (resr - resl)) { n             resr = i; n             resl = 1; n           } n         } n         f[{x, y}] = i; n       } else if (s[i] ==  R ) { n         y++; n         if (f[{x, y}] != 0) { n           if (((i)-f[{x, y}] - 1) < (resr - resl)) { n             resr = i; n             resl = f[{x, y}] + 1; n           } n         } n         if ((x == 0) && (y == 0)) { n           if ((i - 1) < (resr - resl)) { n             resr = i; n             resl = 1; n           } n         } n         f[{x, y}] = i; n       } n     } n     if (resr == 1e8) { n       cout << -1 <<   n ; n     } else { n       cout << resl <<     << resr <<   n ; n     } n     f.clear(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int vis[5][5]; n int ac[5][5], bc[5][5]; n pair<int, int> sum[100]; n pair<int, int> cal(int a, int b) { n   if (a == 1) { n     if (b == 1) n       return pair<int, int>(0, 0); n     else if (b == 2) n       return pair<int, int>(0, 1); n     return pair<int, int>(1, 0); n   } else if (a == 2) { n     if (b == 1) n       return pair<int, int>(1, 0); n     else if (b == 2) n       return pair<int, int>(0, 0); n     return pair<int, int>(0, 1); n   } else { n     if (b == 1) n       return pair<int, int>(0, 1); n     else if (b == 2) n       return pair<int, int>(1, 0); n     return pair<int, int>(0, 0); n   } n } n int main() { n   long long k, pa = 0, pb = 0; n   int a, b; n   scanf( %lld%d%d , &k, &a, &b); n   for (int i = 1; i <= 3; i++) n     for (int j = 1; j <= 3; j++) scanf( %d , &ac[i][j]); n   for (int i = 1; i <= 3; i++) n     for (int j = 1; j <= 3; j++) scanf( %d , &bc[i][j]); n   int sz = 1; n   vis[a][b] = sz++; n   sum[1] = cal(a, b); n   int last = 1; n   for (int i = 1; i <= k; i++) { n     int na = ac[a][b]; n     int nb = bc[a][b]; n     if (vis[na][nb]) { n       last = vis[na][nb]; n       break; n     } n     a = na, b = nb; n     vis[a][b] = sz; n     sum[sz] = pair<int, int>(sum[sz - 1].first + cal(a, b).first, n                              sum[sz - 1].second + cal(a, b).second); n     sz++; n   } n   sz--; n   if (sz == k) { n     printf( %d %d n , sum[sz].first, sum[sz].second); n     return 0; n   } n   pa += sum[last - 1].first; n   pb += sum[last - 1].second; n   k -= last - 1; n   long long dv = k / (sz - last + 1); n   pa += dv * (sum[sz].first - sum[last - 1].first); n   pb += dv * (sum[sz].second - sum[last - 1].second); n   k %= (sz - last + 1); n   if (k != 0) { n     pa += (sum[last + k - 1].first - sum[last - 1].first); n     pb += (sum[last + k - 1].second - sum[last - 1].second); n   } n   printf( %lld %lld n , pa, pb); n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, q, a[501][501], x, y, s, ans; n vector<int> v; n int main() { n   ios::sync_with_stdio(false); n   cin >> n >> m >> q; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) cin >> a[i][j]; n   for (int p = 1; p <= q; p++) { n     cin >> x >> y; n     if (a[x][y] == 1) n       a[x][y] = 0; n     else n       a[x][y] = 1; n     for (int i = 1; i <= n; i++) { n       s = 0; n       for (int j = 1; j <= m; j++) { n         if (a[i][j] == 1) n           s++; n         else n           s = 0; n         ans = max(ans, s); n       } n     } n     v.push_back(ans); n     ans = 0; n   } n   for (int i = 0; i < v.size(); i++) cout << v[i] << endl; n } n


#include <bits/stdc++.h> n class MapValue { n  public: n   std::string configuration; n   int s1; n   MapValue() {} n   MapValue(std::string configuration, int s1) n       : configuration(configuration), s1(s1) {} n }; n class PairHash { n  public: n   std::size_t operator()(const std::pair<int, int> &p) const { n     return std::hash<int>()(p.first) ^ std::hash<int>()(p.second); n   } n }; n std::unordered_map<std::pair<int, int>, MapValue, PairHash> my_map; n int A[100], B[100], C[100], q_rez = -0x3f3f3f3f; n std::string rrr =  Impossible ; n void back(int s1, int s2, int s3, int k, int max, std::string ss) { n   if (k == max + 1) { n     my_map.emplace(std::make_pair(s2 - s1, s3 - s2), MapValue(ss, s1)); n     return; n   } n   s1 += A[k]; n   s2 += B[k]; n   back(s1, s2, s3, k + 1, max, ss +  LM n ); n   s1 -= A[k]; n   s3 += C[k]; n   back(s1, s2, s3, k + 1, max, ss +  MW n ); n   s2 -= B[k]; n   s1 += A[k]; n   back(s1, s2, s3, k + 1, max, ss +  LW n ); n } n void back2(int s1, int s2, int s3, int k, int max, std::string ss) { n   if (k == max + 1) { n     std::string result; n     auto it = my_map.find(std::make_pair(s1 - s2, s2 - s3)); n     if (it != my_map.end()) { n       int q = s1 + it->second.s1; n       if (q > q_rez) { n         rrr = it->second.configuration + ss; n         q_rez = q; n       } n     } n     return; n   } n   s1 += A[k]; n   s2 += B[k]; n   back2(s1, s2, s3, k + 1, max, ss +  LM n ); n   s1 -= A[k]; n   s3 += C[k]; n   back2(s1, s2, s3, k + 1, max, ss +  MW n ); n   s2 -= B[k]; n   s1 += A[k]; n   back2(s1, s2, s3, k + 1, max, ss +  LW n ); n } n int main() { n   int N; n   std::cin >> N; n   for (int i = 1; i <= N; i++) { n     std::cin >> A[i] >> B[i] >> C[i]; n   } n   std::string ss =   ; n   back(0, 0, 0, 1, N / 2, ss); n   ss =   ; n   back2(0, 0, 0, N / 2 + 1, N, ss); n   std::cout << rrr; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2.7e5 + 5; n int m, n, k; n int mod; n int f[19][maxn]; n vector<long long> g; n int cnt[maxn]; n int upd(const int &x) { n   if (x < 0) return x + mod; n   if (x >= mod) return x - mod; n   return x; n } n void add(int &x, const int &y) { x = upd(x + y); } n int ksm(int x, int k) { n   int ans = 1; n   while (k) { n     if (k & 1) ans = 1ll * ans * x % mod; n     x = 1ll * x * x % mod; n     k >>= 1; n   } n   return ans; n } n int jc[maxn], inv[maxn]; n void init(int n) { n   jc[0] = 1; n   for (int i(1), endi(n); i <= endi; i++) jc[i] = 1ll * jc[i - 1] * i % mod; n   inv[n] = ksm(jc[n], mod - 2); n   for (int i(n - 1), endi(0); i >= endi; i--) n     inv[i] = 1ll * inv[i + 1] * (i + 1) % mod; n } n void F(int *f, int n, int h) { n   for (int p = 1; p < n; p <<= 1) n     for (int i = 0; i < n; i += p << 1) n       for (int k(i), endk(i + p - 1); k <= endk; k++) { n         add(f[k + p], h * f[k]); n       } n } n int l; n vector<long long> operator*(vector<long long> &A, vector<long long> &B) { n   static vector<long long> C; n   C.clear(); n   C.resize(l + 1); n   for (int i(0), endi(l); i <= endi; i++) n     for (int j(0), endj(l - i); j <= endj; j++) C[i + j] += A[i] * B[j]; n   for (int i(0), endi(l); i <= endi; i++) C[i] %= mod; n   return C; n } n vector<long long> pksm(vector<long long> A, int k) { n   static vector<long long> C; n   C.clear(); n   C.resize(l + 1); n   C[0] = 1; n   while (k) { n     if (k & 1) C = C * A; n     A = A * A; n     k >>= 1; n   } n   return C; n } n int main() { n   cin >> n >> k >> mod; n   init(n); n   if (n & 1) { n     cout << ksm(k, n); n     return 0; n   } n   m = 1; n   while (m <= n) m <<= 1, l++; n   for (int i(0), endi(m - 1); i <= endi; i++) cnt[i] = cnt[i >> 1] + (i & 1); n   init(m); n   for (int i(0), endi(m - 1); i <= endi; i++) { n     f[cnt[i]][i] = inv[i]; n   } n   for (int i(0), endi(l); i <= endi; i++) F(f[i], m, 1); n   g.resize(l + 1); n   for (int s(0), ends(m - 1); s <= ends; s++) { n     for (int i(0), endi(l); i <= endi; i++) g[i] = f[i][s]; n     g = pksm(g, k); n     for (int i(0), endi(l); i <= endi; i++) f[i][s] = g[i]; n   } n   F(f[cnt[n]], m, -1); n   cout << upd(ksm(k, n) - 1ll * f[cnt[n]][n] * jc[n] % mod); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool issquare(int n) { n   int sq = sqrt(n); n   if (sq * sq == n) { n     return true; n   } else { n     return false; n   } n } n int main() { n   long long int n; n   cin >> n; n   long long int ans = n; n   int f = 1; n   while (n != 1 and f == 1) { n     int sqr = ceil(sqrt((n * 1.0))); n     f = 0; n     for (int i = 2; i <= sqr; i++) { n       if (n % i == 0) { n         n = n / i; n         ans += n; n         f = 1; n         break; n       } n     } n   } n   if (n != 1) ans += 1; n   cout << ans << endl; n } n