malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000007;   const long long INF2 = 1000000000000000007;   const int MOD = 774254531;   const int MOD1 = 892237699;   const int SIZE = 150010;   const double eps = 1e-6;   long long n, m;   long long ar[1010][1010], res;   string st, b, minn;   long long gcd(long long a, long long b) {     while (b) {       a %= b;       swap(a, b);     }     return a;   }   int main() {     cin >> n;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         cin >> ar[i][j];       }     }     res = sqrt(ar[0][1] * ar[0][2] / ar[1][2]);     cout << res <<    ;     for (int i = 1; i < n; ++i) {       cout << ar[0][i] / res <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 5;   string name[maxn], s;   vector<int> G[maxn];   int tot, a[maxn], maxd, dep[maxn];   int dfs(int &p, int d) {     maxd = max(maxd, d);     int ret = ++tot;     dep[ret] = d;     while (s[p] !=  , ) {       name[ret].push_back(s[p++]);     }     ++p;     int son = 0;     while (s[p] !=  , ) {       son = son * 10 + s[p++] -  0 ;     }     ++p;     for (int i = 0; i < son; ++i) G[ret].push_back(dfs(p, d + 1));     return ret;   }   void bfs() {     queue<int> que;     cout << maxd;     int t = 0;     for (int i = 0; i < G[0].size(); ++i) que.push(G[0][i]);     while (!que.empty()) {       int p = que.front();       que.pop();       if (dep[p] != t) {         ++t;         cout << endl;       } else         cout <<    ;       cout << name[p];       for (int i = 0; i < G[p].size(); ++i) que.push(G[p][i]);     }     cout << endl;   }   int main() {     cin >> s;     s.push_back( , );     maxd = 0;     int p = 0;     while (p < s.size()) G[0].push_back(dfs(p, 1));     bfs();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long double C = 1e6;   struct cir {     int x, y, z;   } a[5];   int disf(cir x, cir y) {     return (x.x - y.x) * (x.x - y.x) + (x.y - y.y) * (x.y - y.y);   }   bool kcr(cir x, cir y) {     return disf(x, y) <= (x.z + y.z) * (x.z + y.z) &&            disf(x, y) >= (x.z - y.z) * (x.z - y.z);   }   bool cr(cir x, cir y) {     return disf(x, y) < (x.z + y.z) * (x.z + y.z) &&            disf(x, y) > (x.z - y.z) * (x.z - y.z);   }   bool in(long double x, long double y, cir _) {     return (_.x - x) * (_.x - x) + (_.y - y) * (_.y - y) < _.z * _.z;   }   pair<pair<long double, long double>, pair<long double, long double> > check(       int i, int j) {     bool flag = 0;     if (a[i].y == a[j].y) flag = 1, swap(a[i].x, a[i].y), swap(a[j].x, a[j].y);     long double k = 1. * (a[i].x - a[j].x) / (a[j].y - a[i].y);     long double g = (a[i].z * a[i].z - a[j].z * a[j].z - a[i].x * a[i].x +                      a[j].x * a[j].x - a[i].y * a[i].y + a[j].y * a[j].y) /                     (2. * (a[j].y - a[i].y));     long double aa = k * k + 1;     long double bb = 2 * ((g - a[i].y) * k - a[i].x);     long double cc =         a[i].x * a[i].x + (g - a[i].y) * (g - a[i].y) - a[i].z * a[i].z;     long double x1 =         (-bb - sqrt(max(bb * bb - 4 * aa * cc, (long double)0))) / (2 * aa);     long double x2 =         (-bb + sqrt(max(bb * bb - 4 * aa * cc, (long double)0))) / (2 * aa);     long double y1 = k * x1 + g;     long double y2 = k * x2 + g;     if (flag)       swap(x1, y1), swap(x2, y2), swap(a[i].x, a[i].y), swap(a[j].x, a[j].y);     x1 = (round(x1 * C)) / C;     x2 = (round(x2 * C)) / C;     y1 = (round(y1 * C)) / C;     y2 = (round(y2 * C)) / C;     return pair<pair<long double, long double>, pair<long double, long double> >(         pair<long double, long double>(x1, y1),         pair<long double, long double>(x2, y2));   }   int main() {     int n;     cin >> n;     if (n == 1)       return cout << 2, 0;     else if (n == 2) {       for (int i = 1; i <= 2; ++i) cin >> a[i].x >> a[i].y >> a[i].z;       if (cr(a[1], a[2]))         return cout << 4, 0;       else         return cout << 3, 0;     }     for (int i = 1; i <= 3; ++i) cin >> a[i].x >> a[i].y >> a[i].z;     set<pair<long double, long double> > g[5];     int c = 3;     for (int i = 1; i <= 3; ++i)       for (int j = i + 1; j <= 3; ++j)         if (kcr(a[i], a[j])) {           pair<pair<long double, long double>, pair<long double, long double> >               t = check(i, j);           g[0].insert(t.first);           g[0].insert(t.second);           g[i].insert(t.first);           g[i].insert(t.second);           g[j].insert(t.first);           g[j].insert(t.second);           if (c > 1) --c;         }     int e = 0, v = g[0].size() + 6;     for (int i = 1; i <= 3; ++i) e += g[i].size() + 2;     cout << e - v + c + 1;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int arr[n];     int ar[m];     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     for (int j = 0; j < m; j++) {       cin >> ar[j];     }     for (int k = 0; k < n; k++) {       for (int l = 0; l < m; l++) {         if (ar[l] == arr[k]) {           cout << arr[k] <<    ;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios::sync_with_stdio(0);     long long n, h, k;     cin >> n >> h >> k;     vector<long long> mas(n);     for (int i = 0; i < n; i++) cin >> mas[i];     long long time = 0, currVolume = 0;     bool have = false;     for (int i = 0; i < n; i++) {       long long top = mas[i];       if (currVolume + top <= h)         currVolume += top;       else {         time += (currVolume / k);         if (currVolume < k) {           ++time;           currVolume = 0;         }         currVolume = currVolume % k;         if (currVolume + top <= h) {           currVolume += top;         } else {           ++time;           currVolume = top;         }       }     }     if (currVolume % k != 0) ++time;     time += currVolume / k;     cout << time;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[200010], p[200010];   int a[200010], n, t;   bool ok(int len) {     int i = 1, j = 1;     while (i <= n) {       if (a[i] <= len) {         i++;         continue;       }       if (s[i] == p[j]) {         i++;         j++;       } else {         i++;       }       if (j == t + 1) return true;     }     return false;   }   int main() {     scanf( %s , &s[1]);     n = strlen(s + 1);     scanf( %s , &p[1]);     t = strlen(p + 1);     int l = 0, r = n, ans;     for (int i = 1; i <= n; i++) {       int b;       scanf( %d , &b);       a[b] = i;     }     while (l + 1 < r) {       int m = (l + r) >> 1;       if (ok(m)) {         l = m;       } else {         r = m;       }     }     printf( %d n , l);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s, p =    ;     cin >> s;     int i, j = 0, f = 0, start, end;     for (i = s.size() - 1; i >= 0 && f == 0; i--) {       if (s[i] !=  0 ) {         end = i;         f = 1;       }     }     f = 0;     for (i = 0; i < s.size() && f == 0; i++) {       if (s[i] !=  0 ) {         start = i;         f = 1;       }     }     j = 0;     for (i = end; i >= start; i--) {       p[j] = s[i];       j++;     }     j = 0;     f = 0;     for (i = start; i <= end && f == 0; i++) {       if (p[j] != s[i])         f = 1;       else         j++;     }     if (f)       cout <<  NO  << endl;     else       cout <<  YES  << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 15;   map<pair<int, int>, int> H;   int t[N];   vector<int> adj[N];   int sum[N];   void update(int x, int add) {     if (x == 0) return;     while (x < N) sum[x] += add, x += x & (-x);   }   int q(int x) {     int ret = 0;     while (x) ret += sum[x], x = x & (x - 1);     return ret;   }   int main() {     int n, i, p, x, y, tot, j;     scanf( %d%d , &n, &p);     for (i = 0; i < n; ++i) {       scanf( %d%d , &x, &y);       if (x > y) swap(x, y);       ++t[x], ++t[y];       if (!H.count(make_pair(x, y))) adj[x].push_back(y);       ++H[make_pair(x, y)];     }     long long ret = 0;     for (i = 1; i <= n; ++i) update(t[i], 1);     for (i = 1; i <= n; ++i) {       update(t[i], -1);       if (t[i] >= p)         ret += n - i;       else {         tot = q(n) - q(p - t[i] - 1);         ret += tot;         for (j = 0; j < adj[i].size(); ++j) {           x = adj[i][j];           if (t[i] + t[x] < p) continue;           y = H[make_pair(i, x)];           if (t[x] + t[i] - y < p) --ret;         }       }     }     cout << ret << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int ans[100100];   struct by {     int l, r, id, i, num;   } a[100100 * 2];   bool cmp(by a, by b) {     if (a.r != b.r) return a.r < b.r;     return a.id < b.id;   }   struct byy {     int i, l;     byy() {}     byy(int i, int l) : i(i), l(l) {}     bool operator<(const byy &rhs) const {       if (l != rhs.l) return l < rhs.l;       return i < rhs.i;     }   };   set<byy> s;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &a[i].l, &a[i].r);       a[i].i = i;       a[i].id = 0;     }     scanf( %d , &m);     for (int i = 1; i <= m; i++) {       scanf( %d%d%d , &a[i + n].l, &a[i + n].r, &a[i + n].num);       a[i + n].i = i;       a[i + n].id = 1;     }     sort(a + 1, a + m + n + 1, cmp);     int cnt = 0;     for (int i = 1; i <= m + n; i++) {       if (!a[i].id)         s.insert(byy(a[i].i, a[i].l));       else {         while (s.size() && a[i].num--) {           set<byy>::iterator p = s.lower_bound(byy(0, a[i].l));           if (p == s.end()) break;           byy now = *p;           s.erase(p);           ans[now.i] = a[i].i;           cnt++;         }       }     }     if (cnt == n) {       printf( YES n );       for (int i = 1; i <= n; i++) printf( %d  , ans[i]);       printf(  n );     } else       printf( NO n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double pi = 2 * acos(0);   unsigned long long int binpow(unsigned long long int b,                                 unsigned long long int n) {     if (n == 0) return 1;     if (n == 1) return b;     if (n & 1)       return binpow(b, n - 1) * b;     else       return binpow(b * b, n / 2);   }   long long int bigmod(long long int b, long long int n, long long int m) {     if (n == 0) return 1;     if (n % 2 == 0) {       long long int x = bigmod(b, n / 2, m) % m;       return (x * x) % m;     } else       return ((b % m) * bigmod(b, n - 1, m) % m) % m;   }   void start() {}   long long int to_num(string &s) {     stringstream second;     second << s;     long long int n;     second >> n;     return n;   }   long long int get(long long int n) {     long long int s = 0;     while (n) {       s += (n % 10);       n /= 10;     }     return s;   }   void solve() {     long long int n, cn = 0;     cin >> n;     string s = to_string(n), tmp =   ;     for (long long int i = 0; i < s.size() - 1; i++) {       tmp +=  9 ;     }     if (n < 10) {       cout << n <<   n ;       return;     }     cn = (s.size() - 1) * 9;     long long int left = n - to_num(tmp);     cn += get(left);     cout << cn <<   n ;   }   int main(int argc, char const *argv[]) {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     start();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e6 + 1;   const long long INF = 1e9 + 7;   const long long inf = 1e18;   vector<long long> adj[N];   long long vis[N];   long long ans[N];   long long ct;   void dfs(long long node) {     vis[node] = ct;     ans[ct]++;     for (auto it : adj[node]) {       if (!vis[it]) {         dfs(it);       }     }   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, m;     cin >> n >> m;     for (long long i = 0; i < m; i++) {       long long x;       cin >> x;       long long count = 0, temp;       while (x--) {         long long a;         cin >> a;         if (count == 0) {           temp = a;         }         if (count > 0) {           adj[temp].push_back(a);           adj[a].push_back(temp);           temp = a;         }         count++;       }       count = 0;     }     for (long long i = 1; i <= n; i++) {       if (!vis[i]) {         ct++;         dfs(i);       }       cout << ans[vis[i]] <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1 << 30;   const int maxn = 100007;   int n, m, T;   int top, k[10004], ans[maxn];   struct student {     int t, x, i;     void get(int l) {       scanf( %d%d , &t, &x);       i = l;     }     bool operator<(const student &b) const {       if (t == b.t) return x < b.x;       return t < b.t;     }   } s[maxn], bus[maxn];   inline bool cmp(const student &a, const student &b) { return a.x < b.x; }   void geton(int &st) {     top = 0;     memset(k, 0, sizeof(k));     for (int rest = m; st <= n && rest; st++, rest--) {       bus[++top] = s[st];       k[s[st].x]++;       if (s[st].t > T) T = s[st].t;     }   }   void getoff() {     int t1 = 0, t2 = 0;     sort(bus + 1, bus + top + 1, cmp);     for (int i = 1; i <= top; i++) {       if (bus[i].x != bus[i - 1].x) {         T += t1;         t1 = k[bus[i].x] / 2 + 1;       }       ans[bus[i].i] = bus[i].x + T;     }     T += bus[top].x * 2 + t1;   }   int main() {     int st = 1, ti;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) s[i].get(i);     sort(s + 1, s + n + 1);     while (st <= n) {       geton(st);       getoff();     }     for (int i = 1; i <= n - 1; i++) printf( %d  , ans[i]);     printf( %d n , ans[n]);     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   inline long long read() {     char c = getchar();     long long x = 0;     bool f = 0;     for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45);     for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);     if (f) x = -x;     return x;   }   long long res, n, m, k;   vector<pair<long long, long long> > e[200005];   vector<long long> v[13];   const long long b1 = 19491001;   unsigned long long pw[200005], sumn, sum[13][13], qwq;   void dfs(long long u) {     if (u == k + 1) {       res += (qwq == sumn);       return;     }     for (register long long i = (0); i <= (u - 1); ++i) {       qwq += sum[u][i];       dfs(u + 1);       qwq -= sum[u][i];     }   }   signed main() {     n = read(), m = read(), k = read();     pw[0] = 1;     for (register long long i = (1); i <= (n); ++i)       pw[i] = pw[i - 1] * b1, sumn += pw[i];     for (register long long i = (1); i <= (m); ++i) {       long long u = read(), v = read(), w = read();       e[u].push_back(make_pair(w, v));     }     for (register long long i = (1); i <= (n); ++i)       sort(e[i].begin(), e[i].end()), v[e[i].size()].push_back(i);     for (register long long i = (1); i <= (k); ++i)       for (register long long j = (0); j <= (i - 1); ++j) {         unsigned long long now = 0;         for (long long p = 0; p < v[i].size(); ++p)           now += pw[e[v[i][p]][j].second];         sum[i][j] = now;       }     dfs(1);     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   const long long MAX = 1e9 + 7;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     int a[n];     set<int> s;     for (int i = 0; i < n; i++) s.insert(i + 1);     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i]) s.erase(a[i]);     }     int prev = -1;     for (int i = 0; i < n; i++) {       if (a[i] == 0) {         auto it = s.begin();         while (it != s.end() && *it == (i + 1)) it++;         if (it == s.end()) {           it = s.begin();           a[i] = a[prev];           a[prev] = *it;         } else {           a[i] = *it;           s.erase(it);           prev = i;         }       }     }     for (int i = 0; i < n; i++) {       cout << a[i] <<    ;     }     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int box[300010];   bool check(int times) {     int mi = 0;     for (int i = 0; i < n; ++i) {       if (box[i] + times < m) {         if (mi > box[i] + times) return false;         mi = max(mi, box[i]);       } else {         if (mi >= box[i])           continue;         else if (box[i] + times - m >= mi)           continue;         else           mi = box[i];       }     }     return true;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; ++i) {       scanf( %d , &box[i]);     }     int l = 0, r = m, mid, ans = -1;     while (l <= r) {       mid = (l + r) / 2;       if (check(mid)) {         ans = mid;         r = mid - 1;       } else {         l = mid + 1;       }     }     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     cin >> q;     for (int i = 0; i < q; i++) {       int n;       cin >> n;       int ans = 0;       int ct_4 = n / 4;       int rem = n % 4;       if (rem == 1) {         ct_4 -= 2;         ans = ct_4 + 1;       } else if (rem == 2) {         ct_4 -= 1;         ans = ct_4 + 1;       } else if (rem == 3) {         ct_4 -= 3;         ans = ct_4 + 2;       } else {         ans = ct_4;       }       if (ct_4 < 0) {         cout << -1 << endl;       } else {         cout << ans << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(0);     cout.tie(0);     ios::sync_with_stdio(false);     int t;     cin >> t;     while (t--) {       string s;       cin >> s;       int cntR = 0, cntS = 0, cntP = 0;       for (int i = 0; i < s.size(); ++i) {         if (s[i] ==  R )           cntR += 1;         else if (s[i] ==  S )           cntS += 1;         else           cntP += 1;       }       int n = s.size();       if (cntR >= cntS && cntR >= cntP) {         cout << string(n,  P ) << endl;       } else if (cntS >= cntR && cntS >= cntP) {         cout << string(n,  R ) << endl;       } else         cout << string(n,  S ) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   int n, m;   char a[5555][5555];   int r[5555][5555];   int c[5555];   int ans = 0;   int main() {     int i, j;     cin >> n >> m;     for (i = 1; i <= n; ++i) {       getchar();       for (j = 1; j <= m; ++j) {         a[i][j] = getchar();       }     }     for (i = n; i >= 1; --i)       for (j = m; j >= 1; --j) {         if (a[i][j] ==  0 )           r[i][j] = 0;         else           r[i][j] = r[i][j + 1] + 1;       }     for (j = 1; j <= m; ++j) {       int k = 0;       for (i = 1; i <= m; ++i) {         c[i] = 0;       }       for (i = 1; i <= n; ++i) {         c[r[i][j]]++;         if (r[i][j]) k++;       }       for (i = 1; i <= m; ++i) {         if (c[i]) ans = max(ans, i * k);         k -= c[i];       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long red[210];   long long green[210];   long long blue[210];   long long dp[210][210][210];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     int r, g, b;     cin >> r >> g >> b;     for (int i = 1; i <= r; i++) cin >> red[i];     for (int i = 1; i <= g; i++) cin >> green[i];     for (int i = 1; i <= b; i++) cin >> blue[i];     sort(red, red + r + 1);     sort(green, green + g + 1);     sort(blue, blue + b + 1);     for (int i = 0; i <= r; i++) {       for (int j = 0; j <= g; j++) {         for (int k = 0; k <= b; k++) {           if (i > 0 && j > 0)             dp[i][j][k] =                 max(dp[i][j][k], dp[i - 1][j - 1][k] + red[i] * green[j]);           if (j > 0 && k > 0)             dp[i][j][k] =                 max(dp[i][j][k], dp[i][j - 1][k - 1] + green[j] * blue[k]);           if (i > 0 && k > 0)             dp[i][j][k] =                 max(dp[i][j][k], dp[i - 1][j][k - 1] + red[i] * blue[k]);         }       }     }     cout << dp[r][g][b] <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, k;     cin >> n >> m >> k;     int stol = 1;     while (k > m * 2) {       k -= m * 2;       stol++;     }     cout << stol <<    ;     int str;     str = k / 2 + k % 2;     cout << str <<    ;     if (k % 2 == 0) {       cout <<  R ;     } else {       cout <<  L ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, b, p;     cin >> n >> b >> p;     int a[10 + n], useP = 0, i, useB = 0;     for (i = 0; i < n; i++) {       cin >> a[i];     }     for (i = 0; i < n; i++) {       if (a[i] == 1)         useB++;       else {         if ((p - useP) <= 0)           useB++;         else           useP++;       }     }     b -= useB;     p -= useP;     if (b > p) {       if (p < 0)         cout << abs(p) << endl;       else         cout <<  0  << endl;     } else {       if (b < 0)         cout << abs(b) << endl;       else         cout <<  0  << endl;     }     return 0;   }
#include <bits/stdc++.h>   char s[10000];   int main() {     int n;     scanf( %d , &n);     scanf( %s , s);     int t, d;     bool succ = false;     for (t = 0; t < n && !succ; ++t) {       for (d = 1; t + 4 * d < n; ++d) {         if (s[t] ==  *  && s[t + d] ==  *  && s[t + d + d] ==  *  &&             s[t + 3 * d] ==  *  && s[t + 4 * d] ==  * ) {           succ = true;           break;         }       }     }     if (succ)       printf( yes n );     else       printf( no n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b, i, ans, p, MD = 1000000007;     cin >> a >> b;     p = ((a * (a + 1)) / 2) % MD;     p = p * b % MD;     p = (a + p) % MD;     ans = ((b * (b - 1) / 2)) % MD;     ans = (ans * p) % MD;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 4e18 + 5;   const int inf = 1e9 + 5;   const int maxn = 1e6 + 5;   int h, m, a;   int MAIN() {     scanf( %d:%d , &h, &m);     scanf( %d , &a);     int tot = h * 60 + m + a;     tot %= (24 * 60);     printf( %02d:%02d n , tot / 60, tot % 60);     return 0;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL), cout.tie(NULL);     int ret = MAIN();     return ret;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     vector<long> v(n);     long mul = 1;     for (int i = 0; i < n; ++i) cin >> v[i];     if (n > 1000) {       cout <<  0 n ;       return 0;     }     for (int i = 0; i < n - 1; ++i)       for (int j = i + 1; j < n; ++j)         mul = ((abs((v[j] - v[i])) % m) * (mul % m)) % m;     cout << mul;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e3 + 9;   bool p[N][N];   priority_queue<pair<pair<int, int>, pair<int, int> > > q;   int cu;   int n, m, si, sj, ml, mr, a, b, ti, tj;   char c;   bool valid(int i, int j) {     return i > 0 && i <= n && j > 0 && j <= m && p[i][j];   }   void add(int x, int y, int i, int j) {     p[i][j] = 0;     ++cu;     q.push({{x, y}, {i, j}});   }   int main() {     scanf( %d %d %d %d %d %d , &n, &m, &si, &sj, &mr, &ml);     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j)         p[i][j] = ((cin >> c, c) ==  .  ? true : false);     add(0, 0, si, sj);     auto cr = q.top();     while (!q.empty()) {       cr = q.top();       a = -cr.first.first;       b = -cr.first.second;       ti = cr.second.first;       tj = cr.second.second;       q.pop();       if (valid(ti + 1, tj)) add(-a, -b, ti + 1, tj);       if (valid(ti - 1, tj)) add(-a, -b, ti - 1, tj);       if (valid(ti, tj + 1) && b + 1 <= ml) add(-a, -(b + 1), ti, tj + 1);       if (valid(ti, tj - 1) && a + 1 <= mr) add(-(a + 1), -b, ti, tj - 1);     }     printf( %d n , cu);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t, n, a, b, x, l, m, e, d, s;     cin >> t;     while (t--) {       cin >> n >> x >> a >> b;       if (a > b) {         l = a;         s = b;       } else {         l = b;         s = a;       }       d = n - l;       if (x <= d) {         cout << l + x - s <<   n ;         continue;       } else         m = x - d;       e = s - 1;       if (m >= e) {         cout << n - 1 <<   n ;         continue;       } else {         s = s - m;         cout << n - s <<   n ;       }     }     return 0;   }