malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 200009;   const long long mod = 1e9 + 7;   char s[N]{};   long long prea[N];   long long pref[N];   long long sac[N];   long long saf[N];   long long ksm(int n, int y) {     if (y < 1) return 1;     long long x = n;     long long ret = 1;     while (y) {       if (y & 1) {         ret *= x;         ret %= mod;       }       x *= x;       x %= mod;       y /= 2;     }     return ret;   }   int main() {     int n;     cin >> n;     cin >> s + 1;     for (int i = 1; i <= n; i++) {       prea[i] = prea[i - 1];       pref[i] = pref[i - 1];       if (s[i] ==  a ) prea[i]++;       if (s[i] ==  ? ) pref[i]++;     }     for (int i = n; i >= 1; i--) {       sac[i] = sac[i + 1];       saf[i] = saf[i + 1];       if (s[i] ==  c ) sac[i]++;       if (s[i] ==  ? ) saf[i]++;     }     long long ans = 0;     for (int i = 1; i <= n; i++) {       if (s[i] ==  b  || s[i] ==  ? ) {         long long l = pref[i - 1];         long long r = saf[i + 1];         ans += (prea[i - 1] * sac[i + 1] % mod) * (ksm(3, l + r) % mod) % mod;         ans %= mod;         ans += (prea[i - 1] * saf[i + 1] % mod) * (ksm(3, l + r - 1) % mod) % mod;         ans %= mod;         ans += (pref[i - 1] * sac[i + 1] % mod) * (ksm(3, l + r - 1) % mod) % mod;         ans %= mod;         ans += (pref[i - 1] * saf[i + 1] % mod) * (ksm(3, l + r - 2) % mod) % mod;         ans %= mod;       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long n, cr;   bool f = 0;   pair<long long, long long> a[25], b[25], c[25];   void gen(long long i, long long s1, long long s2) {     if (i == n) {       if (s1 != s2) cr++;     } else {       gen(i + 1, s1 + a[i].first, s2 + c[i].first);       gen(i + 1, s1, s2);     }   }   int main() {     ios::sync_with_stdio(0);     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> a[i].first;       a[i].second = i;       c[i] = a[i];     }     sort(a, a + n);     sort(c, c + n);     for (long long k = 0; k < n; k++) {       for (long long i = 0; i < n; i++) {         b[i] = a[i];       }       a[0] = b[n - 1];       for (long long i = 1; i < n; i++) {         a[i] = b[i - 1];       }       cr = 0;       gen(0, 0, 0);       if (cr == ((1 << n) - 2)) {         f = 1;         for (long long i = 0; i < n; i++) {           c[i].first = c[i].second;           c[i].second = a[i].first;         }         break;       }     }     if (!f) {       cout << -1;       return 0;     }     sort(c, c + n);     for (long long i = 0; i < n; i++) {       cout << c[i].second <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long a, b, x, y, n;       cin >> a >> b >> x >> y >> n;       long long a1 = a, b1 = b, n1 = n;       long long an = a - x, bn = b - y;       b -= min(bn, n);       n -= min(bn, n);       a -= min(an, n);       a1 -= min(an, n1);       n1 -= min(an, n1);       b1 -= min(bn, n1);       cout << min(a1 * b1, a * b) <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   long long int cost(long long int x[], long long int a, long long int n,                      long long int r, long long int m, long long int val) {     long long int pos = 0;     long long int neg = 0;     for (int i = 0; i < n; i++) {       if (x[i] > val)         pos += x[i] - val;       else         neg += val - x[i];     }     if (a + r < m)       return a * neg + r * pos;     else {       if (pos > neg)         return neg * m + (pos - neg) * r;       else         return pos * m + (neg - pos) * a;     }   }   long long int binary(long long int x[], long long int a, long long int n,                        long long int r, long long int m, long long int min,                        long long int max) {     if (min > max)       return -1;     else {       long long int mid = (min + max) / 2;       long long int q = cost(x, a, n, r, m, mid);       long long int w = cost(x, a, n, r, m, mid - 1);       long long int e = cost(x, a, n, r, m, mid + 1);       if (q <= w && q <= e) {         return q;       } else if (w > q && q > e)         return binary(x, a, n, r, m, mid + 1, max);       else         return binary(x, a, n, r, m, min, mid - 1);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n, a, r, m;     cin >> n >> a >> r >> m;     long long int *x = new long long int[n];     long long int min = 100000001;     long long int max = 0;     for (int i = 0; i < n; i++) {       cin >> x[i];       if (x[i] > max) max = x[i];       if (x[i] < min) min = x[i];     }     long long int sum = binary(x, a, n, r, m, min, max);     cout << sum <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 5;   const int inf = 0x3f3f3f3f;   int t, n;   int a[200];   int main() {     int n, q, t, k, d;     int cnt;     int sum;     memset(a, 0, sizeof a);     cin >> n >> q;     for (int i = 0; i < q; i++) {       cnt = 0;       sum = 0;       cin >> t >> k >> d;       for (int j = 0; j < n; j++) {         if (a[j] < t) cnt++;       }       if (cnt < k)         cout <<  -1  << endl;       else {         for (int j = 0; j < n; j++) {           if (a[j] < t) {             k--;             a[j] = t + d - 1;             sum += j + 1;           }           if (k == 0) break;         }         cout << sum << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[110];   int b[110];   int main() {     string s;     getline(cin, s);     int num = 0, ten = 1;     for (int i = s.size() - 1; i >= 0; i--) {       if (s[i] ==  = ) break;       if (s[i] <=  9  && s[i] >=  0 ) {         int x = s[i] -  0 ;         num += x * ten;         ten *= 10;       }     }     int cnt = 0;     a[0] = 1;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  + ) {         a[++cnt] = 1;       } else if (s[i] ==  - ) {         a[++cnt] = 0;       }     }     int x = 0;     for (int i = 0; i <= cnt; i++) {       b[i] = 1;       if (a[i])         x += b[i];       else         x -= b[i];     }     x = num - x;     for (int i = 0; i <= cnt; i++) {       if (x < 0) {         if (a[i] == 0 && b[i] < num) {           int k = min(num - b[i], -x);           b[i] += k;           x += k;         }       } else if (x > 0) {         if (a[i] == 1 && b[i] < num) {           int k = min(num - b[i], x);           b[i] += k;           x -= k;         }       } else         break;     }     x = 0;     for (int i = 0; i <= cnt; i++) {       if (a[i])         x += b[i];       else         x -= b[i];     }     if (x != num) {       cout <<  Impossible  << endl;       return 0;     }     cout <<  Possible  << endl;     cnt = 0;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  +  || s[i] ==  -  || s[i] ==  = ) {         cout << b[cnt++] <<     << s[i] <<    ;       }     }     cout << num << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int n, x;     cin >> n >> x;     long long sum = 0;     for (int i = 0; i < n; i++) {       long long a;       cin >> a;       sum += a;     }     if (sum + n - 1 == x) return 0 * puts( YES );     puts( NO );     return 0;   }
#include <bits/stdc++.h>   #pragma GCC target( avx2 )   #pragma GCC optimize( O3 )   #pragma GCC optimize( unroll-loops )   using namespace std;   using ll = long long;   using lld = long double;   using vll = int64_t;   int main() {     map<int, pair<int, int> > hm;     int a[] = {4, 8, 15, 16, 23, 42};     for (int i = 0; i < 6; i++) {       for (int j = i + 1; j < 6; j++) hm[a[i] * a[j]] = {a[i], a[j]};     }     int ans[7];     cout <<  ?            <<  1 2 n           << flush;     int x;     cin >> x;     auto p1 = hm[x];     cout <<  ? 2 3 n  << flush;     cin >> x;     auto p2 = hm[x];     if (p1.first == p2.first || p1.first == p2.second) {       ans[2] = p1.first;       ans[1] = p1.second;       if (p1.first == p2.first) {         ans[3] = p2.second;       } else {         ans[3] = p2.first;       }     } else {       ans[2] = p1.second;       ans[1] = p1.first;       if (p1.second == p2.first)         ans[3] = p2.second;       else         ans[3] = p2.first;     }     cout <<  ? 4 5 n  << flush;     cin >> x;     p1 = hm[x];     cout <<  ? 5 6 n  << flush;     cin >> x;     p2 = hm[x];     if (p1.first == p2.first || p1.first == p2.second) {       ans[5] = p1.first;       ans[4] = p1.second;       if (p1.first == p2.first) {         ans[6] = p2.second;       } else {         ans[6] = p2.first;       }     } else {       ans[5] = p1.second;       ans[4] = p1.first;       if (p1.second == p2.first)         ans[6] = p2.second;       else         ans[6] = p2.first;     }     cout <<  !  ;     for (int i = 1; i < 7; i++) cout << ans[i] <<    ;     cout <<   n  << flush;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   string s;   int dp[111][55][222][3];   int res;   void dfs(int pos, int left, int x, int dx) {     if (dp[pos][left][x + 100][dx + 1]) return;     dp[pos][left][x + 100][dx + 1] = 1;     if (pos == s.size()) {       if (left == 0) res = max(res, abs(x));       return;     }     for (int i = 0; i <= left; i++) {       int ddx = (s[pos] ==  F );       if (i % 2 == 1) ddx = !ddx;       dfs(pos + 1, left - i, x + (ddx == 1 ? dx : 0), dx * (ddx == 0 ? -1 : 1));     }   }   int main() {     cin >> s;     cin >> n;     dfs(0, n, 0, 1);     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int hv[5];   map<string, int> dys;   string dyi[5] = { S ,  M ,  L ,  XL ,  XXL };   int order[5][5] = {{0, 1, 2, 3, 4},                      {1, 2, 0, 3, 4},                      {2, 3, 1, 4, 0},                      {3, 4, 2, 1, 0},                      {4, 3, 2, 1, 0}};   int k;   string sk;   void init() {     dys[ S ] = 0;     dys[ M ] = 1;     dys[ L ] = 2;     dys[ XL ] = 3;     dys[ XXL ] = 4;   }   int main() {     init();     for (int i = 0; i < 5; i++) scanf( %d , hv + i);     scanf( %d , &k);     for (int i = 0; i < k; i++) {       cin >> sk;       int dyk = dys[sk];       for (int j = 0; j < 5; j++)         if (hv[order[dyk][j]]) {           hv[order[dyk][j]]--;           cout << dyi[order[dyk][j]] << endl;           break;         }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, a, k = 0;     vector<int> v;     cin >> n;     for (i = 0; i < n; i++) {       cin >> a;       v.push_back(a);     }     sort(v.begin(), v.end(), greater<int>());     for (i = 0; i <= n - 3; i++) {       if (v[i] < v[i + 1] + v[i + 2]) k++;     }     if (k > 0)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     vector<int> result;     for (int i = 0; i < t; i++) {       int b, p, f, h, c;       cin >> b >> p >> f >> h >> c;       int res = 0;       b /= 2;       if (h > c) {         if (b - p > 0) {           res += p * h;           b -= p;         } else {           res += b * h;           b = 0;         }         if (b > 0) {           if (b > f) {             res += f * c;             b = 0;           } else {             res += b * c;             b = 0;           }         }       } else if (c > h) {         if (b - f > 0) {           res += f * c;           b -= f;         } else {           res += b * c;           b = 0;         }         if (b > 0) {           if (b > p) {             res += p * h;             b = 0;           } else {             res += b * h;             b = 0;           }         }       } else {         if (f + p <= b)           res += (f + p) * h;         else           res += b * h;       }       result.push_back(res);     }     for (int i = 0; i < t; i++) cout << result.at(i) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long x;   int getAdded(long long n) {     int lo = 1, hi = 10000000;     while (lo < hi) {       long long mid = (lo + hi) / 2 + (lo + hi) % 2;       long long temp = (mid * mid + mid) / 2;       if (temp == n)         return mid;       else if (temp < n)         lo = mid;       else         hi = mid - 1;     }     return lo;   }   bool isPossible(int h, int mod, long long n) {     long long temp = x + h;     return getAdded(temp) >= h * 3 + mod;   }   int main() {     long long n;     cin >> n;     int mod = (n % 3 - 3) * -1;     int lo = 0, hi = 10000000;     x = (n + mod) / 3;     while (lo < hi) {       int mid = (lo + hi) / 2 + (lo + hi) % 2;       if (isPossible(mid, mod, n))         lo = mid;       else         hi = mid - 1;     }     if (!isPossible(lo, mod, n))       cout << 0;     else       cout << lo + 1;     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:100000000000,100000000000 )   using namespace std;   const long long inf = 1e18 + 7;   const long long mod = 1e9 + 7;   const double eps = 1e-12;   const double PI = 2 * acos(0.0);   const double E = 2.71828;   int n;   long long a[1000005];   long long d[1000005], sz;   long long cnt[1000005];   long long res = 1;   long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }   void up(long long x) {     sz = 0;     for (long long i = 1; i * i <= x; ++i) {       if (x % i == 0) {         d[sz++] = i;         if (i * i != x) {           d[sz++] = x / i;         }       }     }     sort(d, d + sz);     for (long long(i) = 0; (i) < (long long)(sz); (i)++) {       cnt[i] = 0;     }     for (long long(i) = 0; (i) < (long long)(n); (i)++) {       long long cur = gcd(x, a[i]);       int num = lower_bound(d, d + sz, cur) - d;       ++cnt[num];     }     for (long long(i) = 0; (i) < (long long)(sz); (i)++) {       for (int j = i + 1; j < sz; ++j) {         if (d[j] % d[i] == 0) {           cnt[i] += cnt[j];         }       }       if (cnt[i] + cnt[i] >= n && res < d[i]) {         res = d[i];       }     }   }   int main(void) {     srand(time(NULL));     scanf( %d , &n);     for (long long(i) = 0; (i) < (long long)(n); (i)++) {       scanf( %I64d , a + i);     }     for (long long(i) = 0; (i) < (long long)(10); (i)++) {       up(a[(rand() << 16 | rand()) % n]);     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using u32 = unsigned int;   using u64 = unsigned long long;   char buf[10];   void NO() {     puts( Impossible );     exit(0);   }   ll update(ll x, ll c) {     if (x == LLONG_MAX || x == LLONG_MIN) return x;     return x + c;   }   int main() {     int n;     scanf( %d , &n);     ll max_r = LLONG_MAX;     ll min_r = LLONG_MIN;     for (int i = (0); i < (n); ++i) {       ll c_i, d_i;       scanf( %lld%lld , &c_i, &d_i);       ;       if (d_i == 2) {         if (min_r >= 1900) NO();         if (max_r >= 1900) max_r = 1899;       } else if (d_i == 1) {         if (max_r < 1900) NO();         if (min_r < 1900) min_r = 1900;       }       max_r = update(max_r, c_i);       min_r = update(min_r, c_i);     }     if (max_r == LLONG_MAX)       puts( Infinity );     else       printf( %lld , max_r);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> g[300005];   int cnt[300005];   int vis[300005];   int ans[300001][26];   int res = 0;   int main() {     queue<int> q;     int n, m;     cin >> n >> m;     string s;     cin >> s;     int x, y;     while (m--) {       scanf( %d%d , &x, &y);       x--, y--;       g[x].push_back(y);       cnt[y]++;     }     for (int i = 0; i < s.size(); i++) {       ans[i][s[i] -  a ]++;       if (!cnt[i]) q.push(i);     }     while (!q.empty()) {       int i = q.front();       q.pop();       for (auto v : g[i]) {         cnt[v]--;         for (int j = 0; j < 26; j++) {           ans[v][j] = max(ans[v][j], ans[i][j] + (s[v] == j +  a ));           res = max(res, ans[v][j]);         }         if (!cnt[v]) q.push(v);       }     }     if (*max_element(cnt, cnt + s.size())) return cout << -1, 0;     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int c[4100];   int s[4100];   vector<long long> g;   string str;   int main() {     long long a;     cin >> a;     cin >> str;     int len = str.length();     for (int i = 0; str[i]; i++) c[i + 1] = str[i] -  0 ;     for (int i = 1; i <= len; i++) {       s[i] = s[i - 1] + (long long)c[i];     }     for (int i = 0; i <= len; i++)       for (int j = i + 1; j <= len; j++) g.push_back(s[j] - s[i]);     sort(g.begin(), g.end());     int sz = g.size(), sz1;     sz1 = upper_bound(g.begin(), g.end(), 0) - lower_bound(g.begin(), g.end(), 0);     long long ans = 0;     for (int i = 0; i < sz; i++) {       if (g[i] == 0) {         if (a == 0) ans += sz;         continue;       }       if (a % g[i] == 0 &&           *lower_bound(g.begin(), g.end(), a / g[i]) == a / g[i]) {         if (a == 0) {           ans += sz1;           continue;         }         ans += upper_bound(g.begin(), g.end(), a / g[i]) -                lower_bound(g.begin(), g.end(), a / g[i]);       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int l[100005], r[100005], q[100005];   struct node {     int v, add;   };   node t[4 * 100005];   const int MX = (1LL << 31) - 1;   void Push(int v, int tl, int tm, int tr) {     if (t[v].add != 0) {       t[2 * v].add |= t[v].add;       t[2 * v].v |= t[v].add;       t[2 * v + 1].add |= t[v].add;       t[2 * v + 1].v |= t[v].add;       t[v].add = 0;     }   }   void Update(int v, int tl, int tr, int l, int r, int value) {     if (l > r) return;     if ((tl == l) && (tr == r)) {       t[v].add |= value;       t[v].v |= value;       return;     }     int tm = (tl + tr) / 2;     Push(v, tl, tm, tr);     Update(2 * v, tl, tm, l, min(tm, r), value);     Update(2 * v + 1, tm + 1, tr, max(l, tm + 1), r, value);     t[v].v &= t[2 * v].v;     t[v].v &= t[2 * v + 1].v;   }   int Get(int v, int tl, int tr, int l, int r) {     if (l > r) return MX;     if ((tl == l) && (tr == r)) return t[v].v;     int tm = (tl + tr) / 2;     Push(v, tl, tm, tr);     return Get(2 * v, tl, tm, l, min(tm, r)) &            Get(2 * v + 1, tm + 1, tr, max(l, tm + 1), r);   }   int main() {     scanf( %d %d , &n, &m);     for (int(i) = (0); (i) < int(m); ++(i)) {       scanf( %d %d %d , l + i, r + i, q + i);       Update(1, 0, n - 1, l[i] - 1, r[i] - 1, q[i]);     }     bool Ok = 1;     for (int(i) = (0); (i) < int(m); ++(i)) {       int x = Get(1, 0, n - 1, l[i] - 1, r[i] - 1);       if (x != q[i]) {         Ok = 0;         break;       }     }     if (!Ok) {       puts( NO );       cin.sync();       cin.get();       return 0;     } else {       puts( YES );       for (int(i) = (0); (i) < int(n); ++(i)) {         printf( %d  , Get(1, 0, n - 1, i, i));       }     }     cin.sync();     cin.get();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int n = s.length(), cur = 1, best = 1;     s += s;     for (size_t i = 1; i < s.size(); i++)       if (s[i] != s[i - 1])         cur++;       else {         best = max(best, cur);         cur = 1;       }     best = max(best, cur);     cout << min(n, best);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 10;   struct Segment {     int left, right;   } seg[N / 2 + 5];   map<int, bool> m;   int a[N];   int n, ans;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     m.clear();     ans = 1;     seg[ans].left = 1;     m[a[1]] = true;     int i = 2;     while (i <= n) {       if (m[a[i]]) {         seg[ans].right = i;         if (i == n) break;         ans++;         i++;         seg[ans].left = i;         m.clear();       }       m[a[i]] = true;       i++;     }     if (i > n) {       if (ans == 1) {         printf( -1 n );         return 0;       }       ans--;       seg[ans].right = n;     }     printf( %d n , ans);     for (int i = 1; i <= ans; i++) printf( %d %d n , seg[i].left, seg[i].right);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string CHECK(long long n) {     long long t, temp = n, zero = 0, ans = 0, flag = 0;     while (temp != 0) {       t = temp % 10;       if (t == 0 && flag == 0)         zero++;       else {         flag = 1;         ans *= 10;         ans += t;       }       temp /= 10;     }     if (zero != 0) {       while (zero != 0) {         ans *= 10;         zero--;       }     }     if (n == ans)       return  YES ;     else       return  NO ;   }   int main() {     long long n;     cin >> n;     cout << CHECK(n) << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int ans = 0;     string str;     cin >> str;     for (int s = 2; s <= n; s++) {       for (int i = 0; i < n - s + 1; i++) {         int u = 0, d = 0, l = 0, r = 0;         for (int j = i; j < i + s; j++) {           if (str[j] ==  U )             u++;           else if (str[j] ==  D )             d++;           else if (str[j] ==  L )             l++;           else if (str[j] ==  R )             r++;         }         if (u == d && l == r) {           ans++;         }       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   long long a[1000050];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     long long rec = 0;     long long num = a[0];     long long have = 0;     long long can = 0;     for (int i = 0; i < n; i++) {       if (num == a[i]) have++;       if (num != a[i]) {         can++;         if (a[i + 1] != a[i]) {           num = a[i];           rec += min(have, can);           have = have + can - min(have, can);           can = 0;         }       }     }     rec = n - have;     cout << rec << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       vector<vector<int>> p(n + 1, vector<int>(m + 1, 0));       vector<int> ma(m + 1);       for (int i = 1; i <= n; i++)         for (int j = 1; j <= m; j++) {           cin >> p[i][j];           if (p[i][j] > p[ma[j]][j]) ma[j] = i;         }       set<int> s;       for (int i = 1; i <= m; i++) s.insert(ma[i]);       if (s.size() == m) {         int ans = 0;         for (int i = 1; i <= m; i++) {           for (int j = 1; j <= m; j++) {             if (i == j) continue;             int tem = 0;             for (int k = 1; k <= n; k++) {               tem = max(tem, min(p[k][i], p[k][j]));             }             for (int k = 1; k <= m; k++) {               if (k == i || k == j) continue;               tem = min(tem, p[ma[k]][k]);             }             ans = max(ans, tem);           }         }         cout << ans <<   n ;       } else {         int ans = 1e9;         for (int i = 1; i <= m; i++) {           ans = min(ans, p[ma[i]][i]);         }         cout << ans <<   n ;       }     }     return 0;   }