malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const double PI = 2.0 * acos(0.0);   inline int getInt() {     int x;     scanf( %d , &x);     return x;   }   inline long long getLL() {     long long x;     scanf( %lld , &x);     return x;   };   inline int NUM(char c) { return (int)c - 48; }   inline char CHR(int n) { return (char)(n + 48); }   template <class T>   inline T MAX(T a, T b) {     if (a > b) return a;     return b;   }   template <class T>   inline T MIN(T a, T b) {     if (a < b) return a;     return b;   }   inline void OPEN(const string &s) {     freopen((s +  .in ).c_str(),  r , stdin);     freopen((s +  .out ).c_str(),  w , stdout);   }   map<string, int> score, sco, mis;   map<string, int> times;   int main() {     vector<string> v;     for (int k = 0, _n = (5); k < _n; k++) {       string A, B, C;       cin >> A >> B;       cin >> C;       for (int i = 0, _n = ((C).size()); i < _n; i++)         if (C[i] ==  : ) C[i] =    ;       stringstream ss(C);       int s, m;       ss >> s >> m;       if (s > m)         score[A] += 3;       else if (s < m)         score[B] += 3;       else {         score[A]++;         score[B]++;       }       sco[A] += s;       mis[A] += m;       sco[B] += m;       mis[B] += s;       v.push_back(A);       v.push_back(B);       times[A]++;       times[B]++;     }     sort((v).begin(), (v).end());     v.resize(unique((v).begin(), (v).end()) - v.begin());     string OTHER;     for (int i = 0, _n = ((v).size()); i < _n; i++) {       if (times[v[i]] == 2 && v[i] !=  BERLAND ) OTHER = v[i];     }     vector<pair<int, pair<int, pair<int, string> > > > sorted;     for (int d = (1), _b = (50); d <= _b; d++) {       for (int m = (0), _b = (50); m <= _b; m++) {         int s = m + d;         string A, B;         A =  BERLAND , B = OTHER;         score[A] += 3;         sco[A] += s;         sco[B] += m;         mis[B] += s;         mis[A] += m;         sorted.clear();         for (int i = 0, _n = ((v).size()); i < _n; i++) {           sorted.push_back(make_pair(               -score[v[i]],               make_pair(-sco[v[i]] + mis[v[i]], make_pair(-sco[v[i]], v[i]))));         }         sort((sorted).begin(), (sorted).end());         if (sorted[0].second.second.second ==  BERLAND  ||             sorted[1].second.second.second ==  BERLAND ) {           cout << s <<  :  << m << endl;           return 0;         }         score[A] -= 3;         sco[A] -= s;         sco[B] -= m;         mis[B] -= s;         mis[A] -= m;       }     }     cout <<  IMPOSSIBLE  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 1 << 20, KOR = 32000;   const long long INF = 1e18;   int n;   int p[MAX];   int sito[KOR];   int bezp[MAX], sp[MAX];   int cijseg, cijprom;   vector<int> Pr;   void Eratosten() {     for (int i = 2; i < KOR; i++) {       if (!sito[i]) {         Pr.push_back(i);         for (int j = 2 * i; j < KOR; j += i) sito[j] = i;       }     }   }   vector<int> Fak(int x) {     vector<int> R;     for (int i = 0; i < (int)Pr.size(); i++) {       if (!(x % Pr[i])) R.push_back(Pr[i]);       for (; !(x % Pr[i]); x /= Pr[i])         ;     }     if (x > 1) R.push_back(x);     return R;   }   long long Rijesi(int x) {     memset(bezp, 0, sizeof bezp);     memset(sp, 0, sizeof sp);     int prvi = n, zadnji = 0;     int ukprom = 0;     for (int i = 0; i < n; i++) {       if (!(p[i] % x)) bezp[i] = 1;       if (!((p[i] + 1) % x) || !((p[i] - 1) % x)) sp[i] = 1;       if (!bezp[i] && !sp[i]) {         prvi = min(prvi, i);         zadnji = max(zadnji, i);       }       if (!bezp[i] && sp[i]) ukprom++;     }     if (!ukprom && prvi == n) return 0;     long long ret = INF;     if (prvi == n) ret = (long long)cijprom * ukprom;     long long maxx = -cijseg;     int tprom = 0;     for (int i = 0; i < n; i++) {       if (!bezp[i] && sp[i]) tprom++;       if (i >= zadnji)         ret = min(ret, (long long)i * cijseg - maxx +                            ((long long)ukprom - tprom) * cijprom);       if (i < prvi)         maxx = max(maxx, (long long)-tprom * cijprom + (long long)i * cijseg);     }     return ret;   }   int main() {     Eratosten();     scanf( %d%d%d , &n, &cijseg, &cijprom);     for (int i = 0; i < n; i++) scanf( %d , &p[i]);     long long rje = INF;     vector<int> Bitni;     for (int i = -1; i <= 1; i++) {       vector<int> T = Fak(p[0] + i);       for (int j = 0; j < (int)T.size(); j++) Bitni.push_back(T[j]);     }     for (int i = -1; i <= 1; i++) {       vector<int> T = Fak(p[n - 1] + i);       for (int j = 0; j < (int)T.size(); j++) Bitni.push_back(T[j]);     }     sort(Bitni.begin(), Bitni.end());     Bitni.resize(unique(Bitni.begin(), Bitni.end()) - Bitni.begin());     for (int i = 0; i < (int)Bitni.size(); i++) rje = min(rje, Rijesi(Bitni[i]));     printf( %lld n , rje);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1000006, MOD = 1e9 + 7, INF = 1e16;   long long a[N], b, n, m, k, g[105][105], q, x, ans, Ans, pre[N], l, r;   string s;   pair<int, int> p[N];   int main() {     ios_base::sync_with_stdio(false), cin.tie(0);     cin >> n >> m;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) cin >> g[i][j];     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (g[i][j] < 1) x = 1;     while (!x) {       Ans++;       q += min(n, m);       for (int i = 1; i <= n; i++)         for (int j = 1; j <= m; j++) {           g[i][j]--;           if (g[i][j] < 1) x = 1;         }     }     ans = 0;     x = 0;     for (int i = 1; i <= n; i++)       if (!g[i][1]) x = 1;     while (!x) {       ans++, r++;       for (int i = 1; i <= n; i++) {         g[i][1]--;         if (!g[i][1]) x = 1;       }     }     x = 0;     for (int i = 1; i <= m; i++)       if (!g[1][i]) x = 1;     while (!x) {       ans++, l++;       for (int i = 1; i <= m; i++) {         g[1][i]--;         if (!g[1][i]) x = 1;       }     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (g[i][j] != g[1][j] + g[i][1]) {           cout << -1;           return 0;         }     for (int i = 1; i <= n; i++) ans += g[i][1];     for (int i = 2; i <= m; i++) ans += g[1][i];     cout << ans + q << endl;     for (int i = 1; i <= l; i++)       cout <<  row             <<     << 1 << endl;     for (int i = 1; i <= r; i++)       cout <<  col             <<     << 1 << endl;     for (int i = 1; i <= n; i++)       for (int u = 1; u <= g[i][1]; u++)         cout <<  row               <<     << i << endl;     for (int i = 1; i <= m; i++)       for (int u = 1; u <= g[1][i]; u++)         cout <<  col               <<     << i << endl;     if (n < m)       s =  row ;     else       s =  col ;     for (int i = 0; i < min(n, m) * Ans; i++)       cout << s <<     << i % min(n, m) + 1 << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, a[100010];   long long t;   int main() {     cin >> n >> m;     a[0] = 1;     for (int i = 1; i <= m; i++) {       cin >> a[i];       if (a[i] > a[i - 1]) t += (a[i] - a[i - 1]);       if (a[i] < a[i - 1]) t += (n - a[i - 1] + a[i]);     }     cout << t;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     int n, k;     cin >> n >> k;     int i = 1;     for (i = k - 1; i > 0; i--) {       if ((n % i) == 0) break;     }     if (i == 0) i = 1;     int x = (n / i) * k;     for (; x % k != i; x++) {     }     cout << x;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const ll INF = 4e18;   const int MAXN = 1.1e5;   ll T[MAXN];   int main() {     ios::sync_with_stdio(0), cin.tie(0);     ll N, M, A, D;     cin >> N >> M >> A >> D;     for (ll i = 0; i < M; i++) {       cin >> T[i];     }     sort(T, T + M);     T[M] = INF;     auto getEmployee = [&](ll i) -> ll { return i <= N ? i * A : INF; };     ll est = 1;     ll cst = 0;     ll ans = 0;     while (est <= N || cst < M) {       ll nxt = D + min(getEmployee(est), T[cst]);       ll een = min(N + 1, (nxt / A) + 1);       ll cen = ll(upper_bound(T, T + M, nxt) - T);       ans++;       if (cst == cen) {         ll delta = een - est;         assert(delta > 0);         ll tgt = min(N + 1, T[cst] / A);         ll extra = max(tgt - een, ll(0)) / delta;         ans += extra;         een += extra * delta;       }       assert(een > est || cen > cst);       assert(est <= een && cst <= cen);       tie(est, cst) = {een, cen};     }     cout << ans <<   n ;     return 0;   }
#include <iostream>   #include <cstring>   using namespace std;   int a[10005],s[10005];   signed main() {     int T;     cin >> T;     while(T--)     {       int n;       cin >> n;       memset(s,0,sizeof s);       for(int i=1;i<=n;i++) cin >> a[i];       long long ans=0;       for(int i=1;i<=n;i++)       {         ans+=max(0,a[i]-s[i]-1);         s[i]=max(s[i],a[i]-1);         for(int j=i+2;j<=min(n,i+a[i]);j++)           ++s[j];         s[i+1]+=max(0,s[i]-a[i]+1);       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int l[51], r[51], a[51], c[51], dp[51][51][51];   void inline FilterRestrictions(int i, int j, int h, vector<int> &v) {     vector<int> u;     for (int x : v) {       if (r[x] < i || j < l[x] || a[x] >= h) {         continue;       }       u.push_back(x);     }     v = u;     u.clear();     sort(v.begin(), v.end(), [](int i, int j) { return l[i] > l[j]; });   }   int Solve(int i, int j, int h, vector<int> v) {     if (j < i) {       return 0;     }     if (dp[i][j][h] != -1) {       return dp[i][j][h];     }     FilterRestrictions(i, j, h, v);     int ans = Solve(i, j, h - 1, v), cost = h * h;     vector<vector<int> > V(51 + 1);     vector<int> v1;     for (int x = i; x <= j; ++x) {       for (; !v.empty() && l[v.back()] == x; v.pop_back()) {         int k = v.back();         cost -= c[k];         V[r[k] + 1].push_back(k);       }       for (auto k : V[x]) {         cost += c[k];         v1.push_back(k);       }       int ansx = cost + Solve(i, x - 1, h, v1) + Solve(x + 1, j, h, v);       ans = max(ans, ansx);     }     dp[i][j][h] = ans;     return ans;   }   int main() {     int n, h, m;     cin >> n >> h >> m;     for (int i = 1; i <= m; ++i) {       cin >> l[i] >> r[i] >> a[i] >> c[i];     }     vector<int> v;     for (int i = 1; i <= m; ++i) {       v.push_back(i);     }     for (int i = 1; i <= n; ++i) {       for (int j = i; j <= n; ++j) {         for (int x = 1; x <= h; ++x) {           dp[i][j][x] = -1;         }       }     }     cout << Solve(1, n, h, v) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct MinMax {     int min, max;     MinMax() : min(INT_MAX), max(INT_MIN){};     MinMax(int min, int max) : min(min), max(max){};   };   int main(int argc, char const *argv[]) {     ios_base::sync_with_stdio(false);     int n, m;     cin >> n >> m;     MinMax a[n];     for (int i = 0; i < m; i++) {       int c;       cin >> c;       a[c - 1].min = min(a[c - 1].min, i);       a[c - 1].max = max(a[c - 1].max, i);     }     int sum = 0;     for (int i = 0; i < n; i++) {       int cnt = 3;       if (i == 0 || i == n - 1) cnt--;       if (a[i].min < INT_MAX) cnt--;       if (i < n - 1) {         if (a[i].min < a[i + 1].max) cnt--;       }       if (i > 0) {         if (a[i - 1].max > a[i].min) cnt--;       }       sum += cnt;     }     if (n == 1) sum = 0;     cout << sum << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t, n, i, j, k, h = 0;     cin >> n;     long long int a[n], b[n];     for (i = 0; i < n; ++i) {       cin >> a[i] >> b[i];     }     if (n == 1) cout << a[0] << endl;     if (n > 1) {       set<long long int> s1, s, s3;       set<long long int>::iterator jt, it;       j = a[0];       while (j % 2 == 0) {         s.insert(2);         j /= 2;       }       for (k = 3; k <= sqrt(j); k = k + 2) {         while (j % k == 0) {           s.insert(k);           j /= k;         }       }       if (j > 2) s.insert(j);       j = b[0];       while (j % 2 == 0) {         s.insert(2);         j /= 2;       }       for (k = 3; k <= sqrt(j); k = k + 2) {         while (j % k == 0) {           s.insert(k);           j /= k;         }       }       if (j > 2) s.insert(j);       j = a[1];       while (j % 2 == 0) {         s1.insert(2);         j /= 2;       }       for (k = 3; k <= sqrt(j); k = k + 2) {         while (j % k == 0) {           s1.insert(k);           j /= k;         }       }       if (j > 2) s1.insert(j);       j = b[1];       while (j % 2 == 0) {         s1.insert(2);         j /= 2;       }       for (k = 3; k <= sqrt(j); k = k + 2) {         while (j % k == 0) {           s1.insert(k);           j /= k;         }       }       if (j > 2) s1.insert(j);       for (it = s.begin(); it != s.end(); ++it) {         for (jt = s1.begin(); jt != s1.end(); jt++) {           if ((*jt) % (*it) == 0) {             s3.insert(*it);           } else if ((*it) % (*jt) == 0)             s3.insert(*jt);         }       }       s.clear();       for (i = 2; i < n; ++i) {         for (it = s3.begin(); it != s3.end(); ++it) {           if (a[i] % (*it) == 0) s.insert(*it);           if (b[i] % (*it) == 0) s.insert(*it);         }         s3.clear();         for (it = s.begin(); it != s.end(); ++it) {           s3.insert(*it);         }         s.clear();       }       if (s3.size() > 0) {         for (it = s3.begin(); it != s3.end(); ++it) {           cout << *it << endl;           break;         }       } else         cout <<  -1 n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     vector<double> a(n), b(n);     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] <= 1) {         printf( -1 n );         exit(0);       }     }     for (int i = 0; i < n; i++) {       cin >> b[i];       if (b[i] <= 1) {         printf( -1 n );         exit(0);       }     }     double s = m;     s += s / (b[0] - 1);     for (int i = n - 1; i >= 1; i--) {       s += s / (a[i] - 1);       s += s / (b[i] - 1);     }     s += s / (a[0] - 1);     printf( %.10f n , s - m);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ull = unsigned long long;   const int MAX_N = 1e6 + 5;   int fen[MAX_N];   int n;   int lowbit(int x) { return x & (-x); }   void add(int x, int val) {     for (int i = x; i <= n; i += lowbit(i)) fen[i] += val;   }   int sum(int x) {     int s = 0;     for (int i = x; i; i -= lowbit(i)) s += fen[i];     return s;   }   int sum(int l, int r) { return sum(r) - sum(l); }   map<int, int> cnt;   int pre[MAX_N];   int back[MAX_N];   int arr[MAX_N];   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> arr[i];       cnt[arr[i]]++;       pre[i] = cnt[arr[i]];     }     cnt.clear();     for (int i = n - 1; i >= 0; i--) {       cnt[arr[i]]++;       back[i] = cnt[arr[i]];       add(back[i], 1);     }     ll ans = 0;     for (int i = 0; i < n; i++) {       add(back[i], -1);       ans += sum(pre[i] - 1);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 9;   bool p[N];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     vector<int> k;     for (int i = 2; i <= 1e6; i++) {       if (p[i]) continue;       k.push_back(i);       for (int j = i + i; j <= 1e6; j += i) {         p[j] = 1;       }     }     int t;     cin >> t;     while (t--) {       long long x;       cin >> x;       long long m = sqrtl(x);       long long r = upper_bound(k.begin(), k.end(), x) - k.begin();       long long l = upper_bound(k.begin(), k.end(), m) - k.begin();       cout << r - l + 1 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>      template <class T>   inline void read(T &res)   {    res = 0; bool bo = 0; char c;    while (((c = getchar()) <  0  || c >  9 ) && c !=  - );    if (c ==  - ) bo = 1; else res = c - 48;    while ((c = getchar()) >=  0  && c <=  9 )     res = (res << 3) + (res << 1) + (c - 48);    if (bo) res = ~res + 1;   }      const int N = 505;      int n, m, a[N][N];      int main()   {    read(n); read(m);    for (int i = 1; i <= n; i++)     for (int j = 1; j <= m; j++)      read(a[i][j]);    for (int i = 1; i <= n; i++)    {     for (int j = 1; j <= m; j++)      printf( %d  , i + j & 1 ? 720720 : 720720 - a[i][j]       * a[i][j] * a[i][j] * a[i][j]);     puts(  );    }    return 0;   }
#include <bits/stdc++.h>   using namespace std;   long double pi = 3.141592653589793238462643383279502884197;   vector<long long int> v(14);   void Compute() {     for (long long int i = 1; i < 14; i++) {       v[i] = pow(2, i) + v[i - 1];     }   }   void solve() {     long long int n;     cin >> n;     long long int ans = 0;     string s = to_string(n);     long long int si = s.size();     ans += v[si - 1];     for (long long int i = 0; i < s.size(); i++) {       if (s[i] ==  7 ) ans += pow(2, (si - 1 - i));     }     ans++;     cout << ans << endl;   }   int main() {     Compute();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int V = 100000 + 5;   int n, num[V];   int main() {     int i, j;     scanf( %d , &n);     for (i = 0; i < n; ++i) scanf( %d , &num[i]);     sort(num, num + n);     printf( %d  , num[n - 1]);     for (i = 1; i < n - 1; ++i) printf( %d  , num[i]);     printf( %d n , num[0]);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   const double pi = acos(-1.0);   struct Complex {     double x, y;     Complex(double x = 0.0, double y = 0.0) {       this->x = x;       this->y = y;     }     Complex operator-(const Complex &b) const {       return Complex(x - b.x, y - b.y);     }     Complex operator+(const Complex &b) const {       return Complex(x + b.x, y + b.y);     }     Complex operator*(const Complex &b) const {       return Complex(x * b.x - y * b.y, x * b.y + y * b.x);     }   };   void change(Complex y[], int len) {     for (int i = 1, j = len / 2; i < len - 1; i++) {       if (i < j) swap(y[i], y[j]);       int k = len / 2;       while (j >= k) {         j -= k;         k /= 2;       }       if (j < k) j += k;     }   }   void fft(Complex y[], int len, int on) {     change(y, len);     for (int h = 2; h <= len; h <<= 1) {       Complex wn(cos(-on * 2 * pi / h), sin(-on * 2 * pi / h));       for (int j = 0; j < len; j += h) {         Complex w(1, 0);         for (int k = j; k < j + h / 2; k++) {           Complex u = y[k];           Complex t = w * y[k + h / 2];           y[k] = u + t;           y[k + h / 2] = u - t;           w = w * wn;         }       }     }     if (on == -1)       for (int i = 0; i < len; i++) y[i].x /= len;   }   int n, m, k, i, j, p[30];   Complex A[N], B[N], C[N];   int a[N], b[N];   char sa[N], sb[N];   int main() {     for (i = 1; i <= 26; i++) scanf( %d , &p[i]);     scanf( %s %s , sa, sb);     m = strlen(sa), n = strlen(sb);     for (i = 0, j = m - 1; i < j; i++, j--) swap(sa[i], sa[j]);     for (i = 0; i < m; i++) a[i] = sa[i] -  a  + 1;     for (i = 0; i < n; i++) b[i] = sb[i] -  a  + 1;     for (k = 1; k < n; k <<= 1)       ;     for (i = 0; i < k; i++)       A[i] = Complex(2 * a[i] * p[a[i]] * (a[i] + p[a[i]]), 0),       B[i] = Complex(b[i], 0);     for (fft(A, k, 1), fft(B, k, 1), i = 0; i < k; i++) C[i] = C[i] - A[i] * B[i];     for (i = 0; i < k; i++)       A[i] = Complex(a[i] * a[i] + p[a[i]] * p[a[i]] + 4 * a[i] * p[a[i]], 0),       B[i] = Complex(b[i] * b[i], 0);     for (fft(A, k, 1), fft(B, k, 1), i = 0; i < k; i++) C[i] = C[i] + A[i] * B[i];     for (i = 0; i < k; i++)       A[i] = Complex(2 * (a[i] + p[a[i]]), 0),       B[i] = Complex(b[i] * b[i] * b[i], 0);     for (fft(A, k, 1), fft(B, k, 1), i = 0; i < k; i++) C[i] = C[i] - A[i] * B[i];     for (i = 0; i < k; i++) {       if (i < m)         A[i] = Complex(1, 0);       else         A[i] = Complex(0, 0);       B[i] = Complex(b[i] * b[i] * b[i] * b[i], 0);     }     for (fft(A, k, 1), fft(B, k, 1), i = 0; i < k; i++) C[i] = C[i] + A[i] * B[i];     for (i = 0; i < k; i++) {       A[i] = Complex(a[i] * a[i] * p[a[i]] * p[a[i]], 0);       if (i < n)         B[i] = Complex(1, 0);       else         B[i] = Complex(0, 0);     }     for (fft(A, k, 1), fft(B, k, 1), i = 0; i < k; i++) C[i] = C[i] + A[i] * B[i];     fft(C, k, -1);     for (int i = 0; i < n - m + 1; i++)       printf( %d , ((long long)(C[i + m - 1].x + 0.5) == 0));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline void read(int& n) {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 )       x = (x << 1) + (x << 3) + ch -  0 , ch = getchar();     n = x * f;   }   int outputarray[20];   inline void write(int k) {     int num = 0;     if (k < 0) putchar( - ), k = -k;     do {       outputarray[++num] = k % 10, k /= 10;     } while (k);     while (num) putchar(outputarray[num--] +  0 );     puts(  );   }   const int N = 50;   int n, m, sg[N][N][N][N][2];   char s[N][N];   int dfs(int x0, int x2, int y0, int y2, int type) {     if (sg[x0][x2][y0][y2][type] >= 0) return sg[x0][x2][y0][y2][type];     int a[N * N];     memset(a, 0, sizeof(a));     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (((i + j) & 1) == type) {           int x = i + j, y = i - j + m;           if (x >= x0 && x < x2 && y >= y0 && y < y2) {             int tmp = 0;             if (s[i][j] ==  L )               tmp = dfs(x0, x, y0, y2, type) ^ dfs(x + 1, x2, y0, y2, type);             if (s[i][j] ==  R )               tmp = dfs(x0, x2, y0, y, type) ^ dfs(x0, x2, y + 1, y2, type);             if (s[i][j] ==  X )               tmp = dfs(x0, x, y0, y, type) ^ dfs(x0, x, y + 1, y2, type) ^                     dfs(x + 1, x2, y0, y, type) ^ dfs(x + 1, x2, y + 1, y2, type);             a[tmp] = 1;           }         }     while (a[++sg[x0][x2][y0][y2][type]])       ;     return sg[x0][x2][y0][y2][type];   }   int main() {     memset(sg, -1, sizeof(sg));     read(n), read(m);     for (int i = 0; i < n; i++) scanf( %s , s[i]);     if (dfs(0, n + m, 0, n + m, 0) ^ dfs(0, n + m, 0, n + m, 1))       puts( WIN );     else       puts( LOSE );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, ans = 0;     cin >> n >> m;     while (n != m) {       if (n < m) {         if (m % 2 == 0)           m /= 2, ans++;         else           m++, ans++;       } else {         ans++;         m++;       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, q;   int matrix[52][52];   long long pref[3][52][52];   long long all[2][52][52][52][52];   void precalculate() {     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         for (int k = i; k <= n; k++) {           for (int ij = j; ij <= m; ij++) {             all[1][i][j][k][ij] = all[1][i][j][k][ij - 1] +                                   all[1][i][j][k - 1][ij] -                                   all[1][i][j][k - 1][ij - 1];             int r = ij - j + 1;             for (int c = k; c >= i && r > 0; c--) {               r = (r > pref[2][c][ij]) ? pref[2][c][ij] : r;               all[1][i][j][k][ij] += r;             }           }         }       }     }   }   int main() {     scanf( %d %d %d , &n, &m, &q);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         char c =  2 ;         while (c !=  0  && c !=  1 ) scanf( %c , &c);         matrix[i][j] = c - 48;         pref[2][i][j] = pref[2][i][j - 1];         if (matrix[i][j] == 1)           pref[2][i][j] = 0;         else           pref[2][i][j]++;       }     }     precalculate();     while (q--) {       int a, b, c, d;       cin >> a >> b >> c >> d;       cout << all[1][a][b][c][d] << endl;     }     return 0;   }