malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long maxi = LLONG_MIN;   long long mini = LLONG_MAX;   void fast() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   long long t, i, j, k, n, temp, flag, ans, m;   string s;   int main() {     int k;     cin >> k;     int f = -1;     for (int i = 5; i * i <= k; i++) {       if (k % i == 0) {         f = i;         break;       }     }     if (f == -1) {       cout << -1;     } else {       int n = f;       int m = k / n;       for (int i = 0; i < n; i++) {         if (i % 5 == 0) {           int j = 0;           for (j = 0; j < m - 4; j += 5) {             s +=  aeiou ;           }           j--;           if (m - j - 1 == 1) {             s +=  a ;           } else if (m - j - 1 == 2) {             s +=  ae ;           } else if (m - j - 1 == 3) {             s +=  aei ;           } else if (m - j - 1 == 4) {             s +=  aeio ;           }         } else if (i % 5 == 1) {           int j = 0;           for (j = 0; j < m - 4; j += 5) {             s +=  eioua ;           }           j--;           if (m - j - 1 == 1) {             s +=  e ;           } else if (m - j - 1 == 2) {             s +=  ei ;           } else if (m - j - 1 == 3) {             s +=  eio ;           } else if (m - j - 1 == 4) {             s +=  eiou ;           }         } else if (i % 5 == 2) {           int j = 0;           for (j = 0; j < m - 4; j += 5) {             s +=  iouae ;           }           j--;           if (m - j - 1 == 1) {             s +=  i ;           } else if (m - j - 1 == 2) {             s +=  io ;           } else if (m - j - 1 == 3) {             s +=  iou ;           } else if (m - j - 1 == 4) {             s +=  ioua ;           }         } else if (i % 5 == 3) {           int j = 0;           for (j = 0; j < m - 4; j += 5) {             s +=  ouaei ;           }           j--;           if (m - j - 1 == 1) {             s +=  o ;           } else if (m - j - 1 == 2) {             s +=  ou ;           } else if (m - j - 1 == 3) {             s +=  oua ;           } else if (m - j - 1 == 4) {             s +=  ouae ;           }         } else {           int j = 0;           for (j = 0; j < m - 4; j += 5) {             s +=  uaeio ;           }           j--;           if (m - j - 1 == 1) {             s +=  u ;           } else if (m - j - 1 == 2) {             s +=  ua ;           } else if (m - j - 1 == 3) {             s +=  uae ;           } else if (m - j - 1 == 4) {             s +=  uaei ;           }         }       }       cout << s;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, q, PREV, pos;   ;   int arr[200005];   long long ps[200005], x, sebelum;   long long k[200005];   bool good;   void binser() {     int ki = PREV, ka = n;     pos = 1;     x += sebelum;     while (ki <= ka) {       int mid = (ki + ka) / 2;       if (ps[mid] <= x) {         ki = mid + 1;       } else {         good = 1;         pos = mid;         ka = mid - 1;       }     }     sebelum = x;     if (!good) sebelum = 0;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> q;     for (int i = 1; i <= n; i++) {       cin >> arr[i];       ps[i] = ps[i - 1] + arr[i];     }     PREV = 1;     for (int i = 1; i <= q; i++) {       cin >> x;       good = false;       binser();       cout << n - pos + 1 << endl;       PREV = pos;     }   }
#include <bits/stdc++.h>   using namespace std;   double d = 0;   bool intersect(int, int);   bool belong(int, int);   bool none(int, int);   void solve() {     int x1, y1, r1, R1, x2, y2, r2, R2;     cin >> x1 >> y1 >> r1 >> R1;     cin >> x2 >> y2 >> r2 >> R2;     int x = abs(x1 - x2);     int y = abs(y1 - y2);     d = sqrt(x * x + y * y);     int ans = 0;     if (d <= r2 - r1 || d >= r1 + R2 || d <= r1 - R2) ++ans;     if (d <= r2 - R1 || d >= R1 + R2 || d <= R1 - R2) ++ans;     if (d <= r1 - r2 || d >= r2 + R1 || d <= r2 - R1) ++ans;     if (d <= r1 - R2 || d >= R2 + R1 || d <= R2 - R1) ++ans;     cout << ans <<   n ;   }   bool intersect(int r1, int r2) {     if (d < r1 + r2 && d > max(r1, r2) - min(r1, r2))       return true;     else       return false;   }   bool belong(int r1, int r2) {     if (d <= r2 - r1)       return true;     else       return false;   }   bool none(int r1, int r2) {     if (!belong(r1, r2) && !belong(r2, r1) && !intersect(r1, r2))       return true;     else       return false;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void read(T& num) {     char CH;     bool F = false;     for (CH = getchar(); CH <  0  || CH >  9 ; F = CH ==  - , CH = getchar())       ;     for (num = 0; CH >=  0  && CH <=  9 ;          num = num * 10 + CH -  0 , CH = getchar())       ;     F && (num = -num);   }   int stk[70], tp;   template <class T>   inline void print(T p) {     if (!p) {       puts( 0 );       return;     }     while (p) stk[++tp] = p % 10, p /= 10;     while (tp) putchar(stk[tp--] +  0 );     putchar(  n );   }   const int mod = 1e9 + 7;   const double PI = acos(-1.0);   const int inf = 1e9;   const int N = 1e6 + 20;   const int maxn = 1e5 + 110;   const double eps = 1e-12;   int main() {     int n, k;     read(n);     read(k);     cout << (n - 1) * 6 * k + 5 * k << endl;     for (int i = 1; i <= n; i++) {       int t = (i - 1) * 6 + 1;       printf( %d %d %d %d n , t * k, t * k + k, t * k + 2 * k, t * k + 4 * k);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   using min_heap = priority_queue<T, vector<T>, greater<T>>;   template <class T, class U>   inline void MAX(T &a, U b) {     if (a < b) a = b;   }   template <class T, class U>   inline void MIN(T &a, U b) {     if (a > b) a = b;   }   template <class T, class U>   inline bool ckmax(T &a, U b) {     return b > a && (a = b, true);   }   template <class T, class U>   inline bool ckmin(T &a, U b) {     return b < a && (a = b, true);   }   template <class T, class U>   inline bool INR(T i, U l, U r) {     return l <= i && i <= r;   }   const int MOD = (int)(1e9) + 7;   const int INF = 0x3f3f3f3f;   const int NINF = -0x3f3f3f40;   const long long INF_L = 0x3f3f3f3f3f3f3f3f;   const long long NINF_L = -0x3f3f3f3f3f3f3f40;   const int MAXN = 100010;   char arr[]{ A ,  C ,  Z };   bool res(int n, int i1, int j1, string &s1) {     int acc = 0;     for (int i = 1; i < n; i++) {       if (i == n - 1)         s1 += arr[i1 % 3];       else if (acc == j1)         s1 +=  Z ;       else         s1 += (s1[((int)(s1).size()) - 1] ==  C  ?  A  :  C );       if (s1[i - 1] ==  A  && s1[i] ==  C ) acc++;     }     return acc == j1;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout.precision(20);     int k, x, n, m;     cin >> k >> x >> n >> m;     for (int i1 = 0; i1 < 9; i1++) {       for (int j1 = 0; j1 <= n / 2; j1++) {         for (int i2 = 0; i2 < 9; i2++) {           for (int j2 = 0; j2 <= m / 2; j2++) {             if (n == 1 && (i1 % 4 != 0) || m == 1 && (i2 % 4 != 0)) continue;             pair<int, int> n1, n2;             n1.first = i1, n1.second = j1;             n2.first = i2, n2.second = j2;             bool bad = false;             for (int a = 0; a <= k - 3; a++) {               pair<int, int> n3;               n3.first = (n1.first / 3) * 3 + (n2.first % 3);               n3.second = n1.second + n2.second;               if (n1.first % 3 == 0 && n2.first / 3 == 1) n3.second++;               if (n3.second > x) {                 bad = true;                 break;               }               n1 = n2, n2 = n3;             }             if (bad) continue;             if (n2.second == x) {               string s1 =   , s2 =   ;               s1 += arr[i1 / 3];               if (n != 1) {                 if (!res(n, i1, j1, s1)) {                   continue;                 }               }               s2 += arr[i2 / 3];               if (m != 1) {                 if (!res(m, i2, j2, s2)) {                   continue;                 }               }               cout << s1 <<   n  << s2 <<   n ;               return 0;             }           }         }       }     }     cout <<  Happy new year!  <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   long long MOD = 998244853;   long long mpow(long long a, long long b) {     if (b == 0) return 1;     long long t1 = mpow(a, b / 2);     t1 *= t1;     t1 %= MOD;     if (b % 2) t1 *= a;     t1 %= MOD;     return t1;   }   long long mpow(long long a, long long b, long long p) {     if (b == 0) return 1;     long long t1 = mpow(a, b / 2);     t1 *= t1;     t1 %= p;     if (b % 2) t1 *= a;     t1 %= p;     return t1;   }   long long modinverse(long long a, long long m) {     long long m0 = m;     long long y = 0, x = 1;     if (m == 1) return 0;     while (a > 1) {       long long q = a / m;       long long t = m;       m = a % m, a = t;       t = y;       y = x - q * y;       x = t;     }     if (x < 0) x += m0;     return x;   }   long long range(long long l, long long r) { return l + rand() % (r - l + 1); }   void solve() {     long long n, m;     cin >> n >> m;     vector<pair<long long, long long> > s;     long long st = n + 1, en = 0;     for (long long i = 0; i < m; i++) {       pair<long long, long long> temp;       cin >> temp.first >> temp.second;       s.push_back(temp);       st = min(st, temp.first);       en = max(en, temp.first);     }     st--;     en--;     long long b[n];     for (long long i = 0; i < n; i++) cin >> b[i];     for (long long i = st; i < en + 1; i++) {       bool bo = 1;       pair<long long, long long> h[n];       for (long long i = 0; i < n; i++)         h[i] = make_pair((long long)-1, (long long)-1);       long long name = 1;       for (auto it : s) {         h[it.first - 1] = make_pair(it.second, name++);       }       for (long long j = st; j < i + 1; j++) {         pair<long long, long long> temp =             ((j == 0) ? make_pair((long long)0, (long long)0)                       : make_pair(h[j - 1].first + b[j], h[j - 1].second));         h[j] = max(h[j], temp);         if (h[j].first < 0) bo = 0;       }       for (long long j = en; j >= i; j--) {         pair<long long, long long> temp =             ((j == n - 1) ? make_pair((long long)0, (long long)0)                           : make_pair(h[j + 1].first + b[j], h[j + 1].second));         h[j] = max(h[j], temp);         if (h[j].first < 0) bo = 0;       }       if (!bo) continue;       cout << i + 1 <<   n ;       bool vis[m];       for (long long i = 0; i < m; i++) vis[i] = 0;       for (long long j = i; j >= st; j--) {         if (vis[h[j].second - 1] == 0) {           cout << h[j].second <<    ;           vis[h[j].second - 1] = 1;         }       }       for (long long j = i; j < en + 1; j++) {         if (vis[h[j].second - 1] == 0) {           cout << h[j].second <<    ;           vis[h[j].second - 1] = 1;         }       }       for (long long j = 0; j < m; j++) {         if (vis[j] == 0) {           cout << j + 1 <<    ;           vis[j] = 1;         }       }       cout <<   n ;       return;     }     cout << -1 <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t = 1;     for (long long i = 0; i < t; i++) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, d;     cin >> n >> m >> d;     vector<int> v(n * m, 0);     for (int i = 0; i < n * m; i++) cin >> v[i];     int ans = INT_MAX;     for (int i = 0; i < n * m; i++) {       int temp_ans = 0;       for (int j = 0; j < n * m; j++) {         if (abs(v[j] - v[i]) % d != 0) {           temp_ans = -1;           break;         } else {           temp_ans += abs(v[j] - v[i]) / d;         }       }       ans = min(temp_ans, ans);       if (ans == -1) break;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[100005];   struct node {     int x, op;   } a[100005];   bool cmp(node q, node w) { return q.x < w.x; }   int cnt;   bool vis[100005];   int main() {     int now, len, i;     scanf( %d , &now);     scanf( %s , s + 1);     len = strlen(s + 1);     s[0] =  + ;     for (i = 1; i <= len; i++) {       if (s[i] ==  a ) {         cnt++;         vis[i] = 1;         if (i > 2 && s[i - 1] ==  +  && s[i - 2] ==  +  && !vis[i - 1] &&             !vis[i - 2]) {           a[cnt].op = 1;           vis[i - 1] = 1;           vis[i - 2] = 1;           if (s[i - 3] ==  + )             a[cnt].x = 1;           else if (s[i - 3] ==  - )             a[cnt].x = -1;           else if (s[i - 3] ==  * ) {             a[cnt].x = 0;             int j, flg = 1;             for (j = i - 4; j >= 1; j--)               if (s[j] <  0  || s[j] >  9 ) {                 if (s[j] ==  - ) flg = -1;                 break;               }             for (j++; j <= i - 4; j++) a[cnt].x = 10 * a[cnt].x + s[j] - 48;             a[cnt].x *= flg;           }         } else if (s[i + 1] ==  +  && s[i + 2] ==  +  && !vis[i + 1] &&                    !vis[i + 2]) {           a[cnt].op = 0;           vis[i + 1] = 1;           vis[i + 2] = 1;           if (s[i - 1] ==  + )             a[cnt].x = 1;           else if (s[i - 1] ==  - )             a[cnt].x = -1;           else if (s[i - 1] ==  * ) {             a[cnt].x = 0;             int j, flg = 1;             for (j = i - 2; j >= 1; j--)               if (s[j] <  0  || s[j] >  9 ) {                 if (s[j] ==  - ) flg = -1;                 break;               }             for (j++; j <= i - 2; j++) a[cnt].x = 10 * a[cnt].x + s[j] - 48;             a[cnt].x *= flg;           }         }       }     }     sort(a + 1, a + cnt + 1, cmp);     long long ans = 0;     for (i = 1; i <= cnt; i++) {       if (a[i].op == 1) {         now++;         ans = 1ll * ans + 1ll * now * a[i].x;       } else {         ans = 1ll * ans + 1ll * now * a[i].x;         now++;       }     }     printf( %I64d , ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string s1, s2, s3;     cin >> n;     while (n--) {       cin >> s1 >> s2 >> s3;       for (int i = 0; i < s1.length(); i++) {         if (s3.at(i) != s2.at(i) && s3.at(i) != s1.at(i)) {           cout <<  NO n ;           break;         }         if (i == s1.length() - 1) cout <<  YES n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int mod1 = 1000000007;   long long int mod2 = 67280421310721;   long long int mod3 = 998244353;   long long int INF = 1e18;   long long int pow1(long long int a, long long int b) {     long long int res = 1;     while (b > 0) {       if (b & 1) res = res * a;       a = a * a;       b >>= 1;     }     return res;   }   void sieve() {     long long int n;     bool prime[n + 1];     memset(prime, true, sizeof(prime));     for (int p = 2; p * p <= n; p++) {       if (prime[p] == true) {         for (int i = p * p; i <= n; i += p) prime[i] = false;       }     }   }   long long int pow2(long long int a, long long int b, long long int m) {     a %= m;     long long int res = 1;     while (b > 0) {       if (b & 1) res = res * a % m;       a = a * a % m;       b >>= 1;     }     return res;   }   long long int ncr(long long int n, long long int k) {     long long int res = 1;     if (k > n - k) k = n - k;     for (int i = 0; i < k; ++i) {       res *= (n - i);       res /= (i + 1);     }     return res;   }   void solve() {     long long int n, m;     cin >> n >> m;     long long int a[n + 1][m + 1];     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) cin >> a[i][j];     }     long long int dp[n + 1][m + 1];     memset(dp, 0, sizeof(dp));     for (int i = 1; i <= m; i++) dp[1][i] = 1;     for (int i = 2; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (a[i][j] >= a[i - 1][j])           dp[i][j] = dp[i - 1][j] + 1;         else           dp[i][j] = 1;       }     }     long long int best[n + 1];     memset(best, 0, sizeof(best));     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         best[i] = max(best[i], dp[i][j]);       }     }     long long int q;     cin >> q;     while (q--) {       long long int l, r;       cin >> l >> r;       if (best[r] <= (r - l))         cout <<  No n ;       else         cout <<  Yes n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> a;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, x, ct, i;     cin >> n;     for (i = 0; i < n; i++) {       cin >> x;       while ((x % 2) == 0) x = x / 2;       while ((x % 3) == 0) x = x / 3;       a.push_back(x);     }     ct = 0;     for (i = 1; i < n; i++)       if (a[i] == a[0]) ct++;     if (ct == (n - 1))       cout <<  Yes n ;     else       cout <<  No n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 6;   const int MAX = 1e7 + 7;   int n, k;   int a[N];   int dp[MAX];   bool can(int x) {     memset(dp, 0, sizeof(dp));     for (int i = x; i <= MAX; i++) {       dp[i] = max(1, dp[i / 2] + dp[(i + 1) / 2]);     }     int kk = k;     for (int i = 0; i < n; i++) {       kk -= a[i] < x ? 0 : dp[a[i]];       if (kk <= 0) {         return true;       }     }     return false;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n >> k;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     int lo = 0, hi = 1e7 + 100;     while (lo + 1 < hi) {       int mid = (lo + hi) / 2;       if (!can(mid)) {         hi = mid;       } else {         lo = mid;       }     }     cout << (lo == 0 ? -1 : lo) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[200011], b[200011], q[200011][2], l, r;   long long sum[2];   char s[200011];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , a + i);     scanf( %s , s + 1);     for (int i = 1; i <= n; ++i) b[i] = (s[i] ==  L  ? -1 : 1);     sort(a + 1, a + 1 + n);     for (int i = 1; i <= n; ++i) sum[n - i + 1 & 1] += a[i];     l = 1;     r = n;     int cur = n;     while (l <= r) {       if (b[cur] == b[cur - 1]) {         q[cur][0] = a[l];         q[cur][1] = (r - l + 1 & 1 ? b[cur] : -b[cur]);         ++l;       } else {         swap(sum[1], sum[0]);         q[cur][0] = a[r];         q[cur][1] = b[cur];         --r;       }       --cur;     }     for (int i = 1; i <= n; ++i)       if (q[i][1] == -1)         printf( %d L n , q[i][0]);       else         printf( %d R n , q[i][0]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   bool mod(long double a, long double b) { return a / b - floor(a / b); }   int occurs(vector<int> v, int n) {     auto it = lower_bound(((v)).begin(), ((v)).end(), (n));     auto it1 = upper_bound(((v)).begin(), ((v)).end(), (n));     int x = it1 - it;     return x;   }   long double max(long double a, long double b) { return a < b ? b : a; }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n, x;       cin >> n >> x;       string s;       cin >> s;       int a[n];       int c = 0;       for (int(i) = 0; (i) < (n); ++(i)) {         if (s[i] ==  0 )           c++;         else           c--;         a[i] = c;       }       sort(a, a + n);       int ans = 0;       if (c == 0) {         for (int(i) = 0; (i) < (n); ++(i)) {           if (a[i] == x) {             ans = -1;             break;           }         }         if (x == 0 && ans == 0) ans = 1;         cout << ans <<   n ;       } else {         if ((x >= 0 && c > 0) || (x <= 0 && c < 0)) {           if (c > 0) {             for (int(i) = 0; (i) < (n); ++(i)) {               if ((x - a[i]) % c == 0 && (x - a[i]) >= 0) ans++;             }           } else {             for (int(i) = 0; (i) < (n); ++(i)) {               if ((x - a[i]) % c == 0 && (x - a[i]) <= 0) ans++;             }           }           if (x == 0) ans++;           cout << ans <<   n ;         } else {           if (c > 0) {             for (int(i) = 0; (i) < (n); ++(i)) {               if ((x - a[i]) % c == 0 && (x - a[i]) >= 0) ans++;             }           } else {             for (int(i) = 0; (i) < (n); ++(i)) {               if ((x - a[i]) % c == 0 && (x - a[i]) <= 0) ans++;             }           }           if (x == 0) ans++;           cout << ans <<   n ;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 10;   int d[MAXN], s[MAXN];   vector<pair<int, int> > ans;   set<pair<int, pair<int, int> > > ver;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> d[i] >> s[i];       ver.insert({d[i], {s[i], i}});     }     while (ver.size()) {       int deg = ver.begin()->first, adj = ver.begin()->second.first,           v = ver.begin()->second.second;       ver.erase(ver.begin());       if (deg == 0) continue;       ver.erase({d[adj], {s[adj], adj}});       ans.push_back({v, adj});       s[adj] ^= v;       d[adj]--;       ver.insert({d[adj], {s[adj], adj}});     }     cout << ans.size() << endl;     for (auto u : ans) cout << u.first <<     << u.second << endl;     return 0;   }
#include <bits/stdc++.h>   const int maxx = 1000001;   int x[maxx], y[maxx];   unsigned long long hash[maxx], vl[maxx], count = 0, check = 1, mul = 1;   bool compare(unsigned long long a, unsigned long long b) { return a > b; }   unsigned long long sum1ton(unsigned long long n) { return n * (n - 1) / 2; }   int main() {     int a, b;     scanf( %d %d , &a, &b);     hash[0] = 1;     for (int i = 1; i <= a; i++) {       hash[i] = hash[i - 1] * mul + 31;       mul = mul * 13 + 23;     }     for (int i = 0; i < b; i++) {       scanf( %d %d , &x[i], &y[i]);       vl[x[i]] -= hash[y[i]];       vl[y[i]] -= hash[x[i]];     }     for (int i = 0; i < b; i++) {       if (vl[x[i]] + hash[y[i]] == vl[y[i]] + hash[x[i]]) {         count++;       }     }     std::sort(vl + 1, vl + a + 1, compare);     for (int i = 1; i < a; i++) {       if (vl[i] == vl[i + 1])         check++;       else {         count += sum1ton(check);         check = 1;       }     }     count += sum1ton(check);     printf( %I64d , count);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1010;   int d[N];   int a[N][N], b[N][N], c[N][N], row[N], col[N];   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         scanf( %d , &a[i][j]);       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         d[j] = a[i][j];       }       sort(d + 1, d + m + 1);       int k = unique(d + 1, d + m + 1) - d - 1;       for (int j = 1; j <= m; j++)         b[i][j] = lower_bound(d + 1, d + k + 1, a[i][j]) - d;       row[i] = k;     }     for (int j = 1; j <= m; j++) {       for (int i = 1; i <= n; i++) d[i] = a[i][j];       sort(d + 1, d + n + 1);       int k = unique(d + 1, d + n + 1) - d - 1;       for (int i = 1; i <= n; i++)         c[i][j] = lower_bound(d + 1, d + k + 1, a[i][j]) - d;       col[j] = k;     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         int ans = 0;         if (b[i][j] >= c[i][j]) {           ans = max(ans, row[i]);           ans = max(ans, col[j] + b[i][j] - c[i][j]);         } else {           ans = max(ans, col[j]);           ans = max(ans, row[i] + c[i][j] - b[i][j]);         }         printf( %d  , ans);       }       printf(  n );     }     return 0;   }