malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int lbracket = s.length(), rbracket = -1, lcolon = s.length(), rcolon = -1;     for (int i = 0; i < s.length(); i++)       if (s[i] ==  [ ) {         lbracket = i;         break;       }     for (int i = lbracket; i < s.length(); i++)       if (s[i] ==  : ) {         lcolon = i;         break;       }     for (int i = s.length() - 1; i > -1; i--)       if (s[i] ==  ] ) {         rbracket = i;         break;       }     for (int i = rbracket; i > -1; i--)       if (s[i] ==  : ) {         rcolon = i;         break;       }     if (lcolon < rcolon) {       int ans = 4;       for (int i = lcolon + 1; i < rcolon; i++)         if (s[i] ==  | ) ans++;       cout << ans;     } else       cout << -1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int NMAX = 1001000;   long long a[NMAX * 2];   long long n, l, t;   long long cnt(int i, int j) {     long long v = (a[i] - a[j] + t * 2 + l) / l;     return v;   }   long double ans(int i) {     int lo = i + 2, hi = i + n;     long long tv = cnt(i, i + 1);     while (lo < hi) {       int m = (lo + hi) / 2;       if (cnt(i, m) < tv) {         hi = m;       } else {         lo = m + 1;       }     }     if (hi == i + n) {       long double v = (long double)tv * (n - 1) / 4;       return v;     }     long double v =         (long double)((tv - 1) * (i + n - hi) + tv * (hi - i - 1)) / 4;     return v;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     cin >> n >> l >> t;     for (int i = 0; i < n; ++i) {       cin >> a[i];       a[i + n] = a[i] + l;     }     long double out = 0;     for (int i = 0; i < n; ++i) {       out += ans(i);     }     cout << fixed << setprecision(5) << out << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long Mod = 1e9 + 7;   const long long maxn = 700 + 10;   long long n;   long long brac[maxn];   char s[maxn];   stack<long long> sta;   inline long long read() {     long long x = 0;     bool fopt = 1;     char ch = getchar();     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) fopt = 0;     for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + ch - 48;     return fopt ? x : -x;   }   long long f[maxn][maxn][3][3];   void dfs(long long l, long long r) {     if (r == l + 1)       return f[l][r][0][1] = f[l][r][1][0] = f[l][r][0][2] = f[l][r][2][0] = 1,              void();     if (brac[l] == r) {       dfs(l + 1, r - 1);       for (long long i = 0; i <= 2; i++)         for (long long j = 0; j <= 2; j++) {           if (i != 1)             f[l][r][1][0] = (f[l][r][1][0] + f[l + 1][r - 1][i][j]) % Mod;           if (i != 2)             f[l][r][2][0] = (f[l][r][2][0] + f[l + 1][r - 1][i][j]) % Mod;           if (j != 1)             f[l][r][0][1] = (f[l][r][0][1] + f[l + 1][r - 1][i][j]) % Mod;           if (j != 2)             f[l][r][0][2] = (f[l][r][0][2] + f[l + 1][r - 1][i][j]) % Mod;         }     } else {       dfs(l, brac[l]);       dfs(brac[l] + 1, r);       for (long long i = 0; i <= 2; i++)         for (long long j = 0; j <= 2; j++)           for (long long k = 0; k <= 2; k++)             for (long long q = 0; q <= 2; q++)               if (!(j && j == k))                 f[l][r][i][q] =                     (f[l][r][i][q] +                      f[l][brac[l]][i][j] * f[brac[l] + 1][r][k][q] % Mod) %                     Mod;     }   }   signed main() {     scanf( %s , s + 1);     n = strlen(s + 1);     for (long long i = 1; i <= n; i++) {       if (s[i] ==  ( )         sta.push(i);       else         brac[sta.top()] = i, sta.pop();     }     dfs(1, n);     long long ans = 0;     for (long long i = 0; i <= 2; i++)       for (long long j = 0; j <= 2; j++) ans = (ans + f[1][n][i][j]) % Mod;     cout << ans << endl;     return 0;   }
#include<bits/stdc++.h>   #pragma GCC optimize ( -O3 )   #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);   #define ll long long   #define double long double   #define pb push_back   #define mod 1000000007   #define int long long   #define endl   n    #define ss second   #define ff first   #define INF 1000000000   #define all(a) a.begin(),a.end()   #define gcd(a, b) __gcd((a), (b))   //ceil(a/b) is equal to (a+b-1)/b   using namespace std;         int power(int a,int n,int p)   {       int res=1;       while(n)       {           if(n%2)           {           res=(res*a)%p;           n--;}           else           {           a=(a*a)%p;           n=n/2;}       }       return res;   }          int binarySearch(int arr[],int l,int r,int x)    {        int mid;       while(l<=r)       {           mid=(l+r)/2;           if(arr[mid]==x)               return mid;           if(arr[mid]<x)               l=mid+1;           else               r=mid-1;       }       return -1;   }           int fact(int n,int k)       //for calculating nCk   {       int ans=1;       if(k>n-k)       {           k=n-k;       }       for(int i=1;i<=k;i++)       {           ans*=(n-i+1);           ans/=i;       }       return ans;   }   // cout << std::fixed;   // std::cout << std::setprecision(9);    // auto it = lower_bound(v.begin(), v.end(), n);           int32_t main()   {       IOS;       int t;       cin>>t;       while(t--)       {           int n;           cin>>n;           int a[n+1];              std::map<int, int> m;           for(int i=0;i<n;i++){               cin>>a[i];               m[a[i]]++;           }           set<int>s;           std::map<int, int> m1;           for(auto x:m)           {               s.insert(x.ss);               m1[x.ss]++;           }           int ans=INF;           for(int x:s)           {               int cnt=0;               for(auto y:m1)               {                   if(y.ff<x){                       cnt+=y.ss*y.ff;                   }                   else                   {                       cnt+=abs(y.ff-x)*y.ss;                   }               }               ans=min(ans,cnt);           }              cout<<ans<<endl;          }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 15e4 + 10;   long long a[N];   bool vis[N];   int main() {     int n;     scanf( %d , &n);     set<pair<long long, int> > se;     for (int i = 0; i < n; i++) {       scanf( %lld , a + i);       se.insert(pair<long long, int>(a[i], i));     }     int sz = n;     while (!se.empty()) {       pair<long long, int> x = *se.begin();       if (!se.empty()) {         se.erase(se.begin());         pair<long long, int> y = *se.begin();         if (x.first == y.first) {           se.erase(se.begin());           se.insert(pair<long long, int>(y.first * 2, y.second));           vis[x.second] = true;           sz--;           a[y.second] = y.first * 2;         }       } else         break;     }     printf( %d n , sz);     for (int i = 0; i < n; i++) {       if (vis[i]) continue;       printf( %lld  , a[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int Maxn = 2005;   int n;   int p[Maxn], b[Maxn];   int inb[Maxn];   int res;   int best[Maxn];   vector<pair<int, int> > seq;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &p[i]);     for (int i = 1; i <= n; i++) {       scanf( %d , &b[i]);       inb[b[i]] = i;     }     for (int i = 1; i <= n; i++) p[i] = inb[p[i]];     for (int i = 1; i <= n; i++) {       int pos = i;       while (p[pos] != i) pos++;       res += pos - i;       best[i] = p[i];       for (int j = i + 1; j < pos; j++) best[j] = max(best[j - 1], p[j]);       for (int j = pos - 1; j >= i; j--)         if (best[j] == p[j]) {           seq.push_back(pair<int, int>(j, pos));           swap(p[j], p[pos]);           pos = j;         }     }     printf( %d n , res);     printf( %d n , seq.size());     for (int i = 0; i < seq.size(); i++)       printf( %d %d n , seq[i].first, seq[i].second);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   vector<pair<int, int> > p;   set<pair<int, int> > h;   set<pair<int, int> > v;   int cut();   int cut(set<pair<int, int> >::iterator s, set<pair<int, int> >::iterator e) {     int c = 0;     vector<int> all;     while (s != e) {       all.push_back(s->second);       ++s;     }     for (int &x : all) {       h.erase(pair<int, int>(p[x].first, x));       v.erase(pair<int, int>(p[x].second, x));     }     c += cut();     h.clear();     v.clear();     for (int &x : all) {       h.insert(pair<int, int>(p[x].first, x));       v.insert(pair<int, int>(p[x].second, x));     }     c += cut();     return c;   }   int cut() {     set<pair<int, int> >::iterator xs = h.begin();     set<pair<int, int> >::iterator ys = v.begin();     set<pair<int, int> >::iterator xe = h.end();     set<pair<int, int> >::iterator ye = v.end();     --xe;     --ye;     for (int i = 0; i < (int)h.size() / 2; ++i) {       set<pair<int, int> >::iterator nxs = xs;       ++nxs;       if (xs->first + 1 < nxs->first) {         return cut(h.begin(), nxs);       }       ++xs;       set<pair<int, int> >::iterator nxe = xe;       --xe;       if (xe->first + 1 < nxe->first) {         return cut(nxe, h.end());       }       set<pair<int, int> >::iterator nys = ys;       ++nys;       if (ys->first + 1 < nys->first) {         return cut(v.begin(), nys);       }       ++ys;       set<pair<int, int> >::iterator nye = ye;       --ye;       if (ye->first + 1 < nye->first) {         return cut(nye, v.end());       }     }     return 1;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 0; i < n; ++i) {       int x, y;       cin >> x >> y;       p.push_back(pair<int, int>(x, y));       h.insert(pair<int, int>(x, i));       v.insert(pair<int, int>(y, i));     }     cout << cut() << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, ans, x, mn = 100001;   vector<int> A, B;   map<int, int> Ps1, Ps2, Mn;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x;       Ps1[x] = i;     }     for (int i = 0; i < n; i++) {       cin >> x;       Ps2[i] = Ps1[x];     }     for (int i = n - 1; i >= 0; i--) {       mn = min(mn, Ps2[i]);       Mn[i] = mn;     }     for (int i = 0; i < n; i++) {       if (Ps2[i] > Mn[i]) ans++;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int num[5005];   int rmq(int l, int r) {     int ans = 1 << 30, tmp = l;     for (int i = l; i <= r; i++) {       if (ans > num[i]) {         ans = num[i];         tmp = i;       }     }     return tmp;   }   int get(int l, int r, int h) {     if (l > r) return 0;     if (l == r) {       if (num[l] == h)         return 0;       else         return 1;     }     int tmp = rmq(l, r);     int ans = 0;     ans = min(r - l + 1, get(l, tmp - 1, num[tmp]) + get(tmp + 1, r, num[tmp]) +                              num[tmp] - h);     return ans;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &num[i]);     int ans = get(0, n - 1, 0);     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int g2[1002][1002];   int main() {     int n, m;     cin >> n >> m;     for (int i = n; i <= m; i++) {       int ind = 0;       string s = to_string(i);       string m = s;       sort(s.begin(), s.end());       for (int p = 1; p < s.size(); p++)         if (s[p] == s[p - 1]) {           ind = 1;           break;         }       if (ind == 1) continue;       cout << m;       return 0;     }     cout << -1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int c1, c2, x, y;   long long int comp(long long int t) {     long long int r1 = t / x, r2 = t / y, l = x * y, both = t / l;     long long int left = t - r1 - r2 + both;     r1 = r1 - both;     r2 = r2 - both;     long long int left1 = c1 - r2, left2 = c2 - r1;     if (left1 < 0) left1 = 0;     if (left2 < 0) left2 = 0;     if (left1 + left2 <= left)       return 1;     else       return 0;   }   long long int bs() {     long long int st = 0, en = 1e18;     while (en - st > 1) {       long long int mid = (st + en) / 2;       if (comp(mid))         en = mid;       else         st = mid;     }     return en;   }   int main() {     cin >> c1 >> c2 >> x >> y;     cout << bs();   }
#include <bits/stdc++.h>   using namespace std;   long long n, cnt;   long long arr[100000], h[100000];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (long long i = 0; i <= n - 1; i++) {       cin >> arr[i];       h[i] = arr[i];     }     sort(h, h + n);     for (long long i = 0; i <= n - 1; i++) {       if (arr[i] != h[i]) cnt++;     }     if (cnt > 2)       cout <<  NO n ;     else       cout <<  YES n ;     cin >> n;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:1608864 )   void ASS(bool b) {     if (!b) ++*(int*)0;   }   int main() {     int n, m, k;     scanf( %d %d %d , &n, &m, &k);     const int inf = 1 << 30;     vector<int> v(m, inf);     for (int i = 0; i < (int)(n); i++) {       int x, y;       scanf( %d %d , &x, &y);       x--;       v[x] = min(v[x], y);     }     int res = 0;     for (int i = 0; i < (int)(m); i++) res += v[i];     res = min(res, k);     printf( %d n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int Inf = 1000000000;   const int Maxn = 30005;   const int Maxk = 205;   const int Maxd = 6;   int n, k;   int a[Maxn];   int dp[Maxn][Maxk][2][Maxd];   int main() {     scanf( %d %d , &n, &k);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     fill((int*)dp, (int*)dp + Maxn * Maxk * 2 * Maxd, -Inf);     for (int i = 0; i < n; i++) {       dp[i][1][1][0] = dp[i][1][0][0] = -a[i];       dp[i][1][1][1] = dp[i][1][0][1] = a[i];     }     for (int i = n - 1; i >= 0; i--)       for (int j = 1; j <= k; j++) {         dp[i][j][1][0] = max(dp[i][j][1][0], dp[i + 1][j][1][0] - a[i]);         dp[i][j][1][1] = max(dp[i][j][1][1], dp[i + 1][j][1][1] + a[i]);         dp[i][j][1][2] = max(dp[i][j][1][2], dp[i + 1][j][1][2] - 2 * a[i]);         if (j) {           dp[i][j][1][2] = max(dp[i][j][1][2], dp[i + 1][j - 1][0][1] - 2 * a[i]);           dp[i][j][1][2] = max(dp[i][j][1][2], dp[i + 1][j - 1][0][3] - 2 * a[i]);         }         dp[i][j][1][3] = max(dp[i][j][1][3], dp[i + 1][j][1][3] + 2 * a[i]);         if (j) {           dp[i][j][1][3] = max(dp[i][j][1][3], dp[i + 1][j - 1][0][0] + 2 * a[i]);           dp[i][j][1][3] = max(dp[i][j][1][3], dp[i + 1][j - 1][0][2] + 2 * a[i]);         }         dp[i][j][1][4] = max(dp[i][j][1][4], dp[i + 1][j][1][4] - a[i]);         if (j) {           dp[i][j][1][4] = max(dp[i][j][1][4], dp[i + 1][j - 1][0][1] - a[i]);           dp[i][j][1][4] = max(dp[i][j][1][4], dp[i + 1][j - 1][0][3] - a[i]);         }         dp[i][j][1][5] = max(dp[i][j][1][5], dp[i + 1][j][1][5] + a[i]);         if (j) {           dp[i][j][1][5] = max(dp[i][j][1][5], dp[i + 1][j - 1][0][0] + a[i]);           dp[i][j][1][5] = max(dp[i][j][1][5], dp[i + 1][j - 1][0][2] + a[i]);         }         for (int z = 0; z < Maxd; z++) {           dp[i][j][0][z] = max(dp[i][j][1][z], dp[i + 1][j][0][z]);           if (j) dp[i][j][0][z] = max(dp[i][j][0][z], dp[i + 1][j - 1][0][z]);         }       }     printf( %d n , max(dp[0][k][0][4], dp[0][k][0][5]));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct point {     int x, y;     point(){};     point(int xx, int yy) {       x = xx;       y = yy;     }     point friend operator+(point a, point b) {       return point(a.x + b.x, a.y + b.y);     }     point friend operator-(point a, point b) {       return point(a.x - b.x, a.y - b.y);     }     long long friend operator*(point a, point b) {       return (long long)a.x * b.y - (long long)a.y * b.x;     }   } a[5050], s[5050];   int n, tot;   long long S;   bool cmp(point a, point b) {     if (a.x != b.x) return a.x < b.x;     return a.y < b.y;   }   void put(point a) { printf( %d %d n , a.x, a.y); }   long long area(int i, int j, int k) {     return abs((s[j] - s[i]) * (s[k] - s[i]));   }   int main() {     scanf( %d%I64d , &n, &S);     for (int i = 1; i <= n; i++) scanf( %d%d , &a[i].x, &a[i].y);     sort(a + 1, a + 1 + n, cmp);     for (int i = 1; i <= n; i++) {       while (tot > 1 && (a[i] - s[tot - 1]) * (s[tot] - s[tot - 1]) <= 0) tot--;       s[++tot] = a[i];     }     int k = tot;     for (int i = n - 1; i > 0; i--) {       while (tot > k && (a[i] - s[tot - 1]) * (s[tot] - s[tot - 1]) <= 0) tot--;       s[++tot] = a[i];     }     tot--;     S = 0;     int ii, jj, kk;     for (int i = 1; i < tot - 1; i++) {       int tmp = i + 2;       for (int j = i + 1; j <= tot; j++) {         while (tmp < tot && area(i, j, tmp + 1) > area(i, j, tmp)) tmp++;         if (area(i, j, tmp) > S) {           S = area(i, j, tmp);           ii = i;           jj = j;           kk = tmp;         }       }     }     put(s[ii] + s[jj] - s[kk]);     put(s[jj] + s[kk] - s[ii]);     put(s[kk] + s[ii] - s[jj]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 23333;   int aa[maxn];   int p[maxn];   int main() {     int a, b, w, x, c;     scanf( %d%d%d%d%d , &a, &b, &w, &x, &c);     c -= a;     if (c <= 0) {       printf( 0 n );       return 0;     }     int m = 0, haj;     for (int i = b; !p[i];) {       p[i] = ++m;       if (i >= x) {         i -= x;         aa[m] = 1;       } else {         i = w - x + i;       }       if (p[i]) haj = p[i];     }     for (int i = 1; i < haj; ++i) {       c -= aa[i];       if (c <= 0) {         printf( %d n , i);         return 0;       }     }     long long sum = (long long)haj - 1;     int s = 0;     for (int i = haj; i <= m; ++i) s += aa[i];     sum += (long long)((c - 1) / s) * (long long)(m - haj + 1);     c -= ((c - 1) / s) * s;     for (int i = haj; i <= m && c > 0; ++i) {       c -= aa[i];       ++sum;     }     printf( %I64d n , sum);   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 50;   int t, m, n;   long long su, s[maxn], cf[maxn];   int a[maxn], b[maxn], c[maxn], x, y;   int main() {     scanf( %d %d , &n, &m);     scanf( %d , a + 1);     for (int i = 2; i <= m; ++i) {       scanf( %d , a + i);       su += abs(a[i] - a[i - 1]);     }     for (int i = 1; i <= n; ++i) s[i] = su;     for (int i = 1; i <= m - 1; ++i) {       x = min(a[i], a[i + 1]), y = max(a[i], a[i + 1]);       if (x == y) continue;       s[x] += x - 1;       s[y] += 2 * x - y;       if (x + 1 == y) continue;       b[i] = x + 1;       c[i] = y - 1;     }     for (int i = 1; i <= m - 1; ++i) {       x = b[i];       y = c[i];       --cf[x];       ++cf[y + 1];     }     for (int i = 1; i <= n; i++) {       cf[i] = cf[i - 1] + cf[i];       s[i] += cf[i];     }     for (int i = 1; i <= n; ++i) printf( %lld  , s[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 10;   int n, m;   vector<int> g[MAXN];   int max1[MAXN], max2[MAXN];   bool vis[MAXN];   void dfs(int v) {     vis[v] = true;     for (auto to : g[v]) {       if (!vis[to]) {         dfs(to);         if (max1[v] <= max1[to] + 1) {           max2[v] = max1[v];           max1[v] = max1[to] + 1;         } else if (max2[v] < max1[to] + 1) {           max2[v] = max1[to] + 1;         }       }     }   }   int ans;   int main() {     cin >> n >> m;     while (m--) {       int u, v;       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     for (int i = 1; i <= n; i++)       if (!vis[i]) dfs(i);     for (int i = 1; i <= n; i++) ans = max(ans, max1[i] + max2[i]);     cout << ans;     return 0;   }
#include<bits/stdc++.h>   using namespace std;      #define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)   #define f first   #define s second   #define for1(i,a,b) for (int i = a; i < b; i++)   #define for2(i,a,b) for (int i = a; i > b; i--)   #define arrin(a,n) for (int i = 0; i < n; i++) cin >> a[i];   #define arrout(a,n) for (int i = 0; i < n; i++) cout << a[i] <<    ; cout <<   n ;   #define arrin2d(a,m,n) for (int i = 0; i < m; i++){for (int j = 0; j < n; j++) cin >> a[i][j];}   #define arrout2d(a,m,n) for (int i = 0; i < m; i++){for (int j = 0; j < n; j++) cout << a[i][j] <<    ; cout <<   n ;}   #define w(t) int t; cin >> t; while(t--)   #define strin(s) getline(cin,s)   #define pushb push_back   #define popb pop_back   #define pushf push_front   #define popf pop_front   #define mp make_pair   #define lower_bound lb   #define upper_bound ub   #define yes cout <<  YES n    #define no cout <<  NO n       typedef long long ll;   typedef long double ld;   typedef vector<int> vi;   typedef vector<ll> vll;   typedef vector<pair<int,int>> vp;   typedef vector<char> vch;   typedef vector<string> vstr;   typedef set<ll> sll;   typedef pair<int,int> pi;   typedef map<int,int> mi;   typedef map<int,char> mch;   //typedef __int128_t vvlint;      const int inf = 1e9 + 7;   /*   freopen( input.txt ,  r , stdin);   freopen( output.txt ,  w , stdout);   */      void tc()   {    int a1,a2,a3,a4,a5,c1,c2,c3;    cin >> c1 >> c2 >> c3;    cin >> a1 >> a2 >> a3 >> a4 >> a5;        if (a1 <= c1 && a2 <= c2 && a3 <= c3)    {        c1 -= a1;        c2 -= a2;        c3 -= a3;                a4 -= min(a4,c1);        a5 -= min(a5,c2);                if (a4 + a5 <= c3)            yes;        else            no;    }    else        no;   }      int main()   {    fastio;        w(t)    {     tc();     }        return 0;    }
#include <bits/stdc++.h>   int n;   char a[11][11], b[11][11], c[11][11];   void turn() {     int i, j, k, l;     for (i = n - 1, k = 0; i >= 0; --i, ++k)       for (j = 0, l = 0; j < n; ++j, ++l) c[k][l] = a[j][i];     for (i = 0; i < n; ++i)       for (j = 0; j < n; ++j) a[i][j] = c[i][j];   }   int same() {     int i, j;     for (i = 0; i < n; ++i)       for (j = 0; j < n; ++j)         if (a[i][j] != b[i][j]) return 0;     return 1;   }   void p() {     int i, j;     printf(  n n );     for (i = 0; i < n; ++i) {       for (j = 0; j < n; ++j) printf( %c , a[i][j]);       printf(  n );     }     printf(  n n );   }   void f() {     int i, j;     for (i = 0; i < 3; ++i) {       if (same()) {         printf( Yes n );         return;       }       turn();     }     if (same()) {       printf( Yes n );       return;     }     for (i = 0; i < n; ++i)       for (j = 0; j < n; ++j) c[i][j] = a[i][n - j - 1];     for (i = 0; i < n; ++i)       for (j = 0; j < n; ++j) a[i][j] = c[i][j];     for (i = 0; i < 3; ++i) {       if (same()) {         printf( Yes n );         return;       }       turn();     }     if (same()) {       printf( Yes n );       return;     }     printf( No n );     return;   }   int main() {     scanf( %d , &n);     int i, j;     for (i = 0; i < n; ++i) scanf( %s , a[i]);     for (i = 0; i < n; ++i) scanf( %s , b[i]);     f();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int const N = 1e6 + 6;   bool us[N], use[N];   long long a[N];   long long n, x, k, q, x1, x2, y, ibibibibbibibibiibigbabypanfewewf, y2, ans, m;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> x1;     for (int I = 0; I < x1; I++) {       cin >> n;       y = 0;       ibibibibbibibibiibigbabypanfewewf = 1e9 + 7;       for (int i = 1; i <= n; i++) {         cin >> k >> q;         y = max(y, k);         ibibibibbibibibiibigbabypanfewewf =             min(ibibibibbibibibiibigbabypanfewewf, q);       }       cout << max(0ll, y - ibibibibbibibibiibigbabypanfewewf) << endl;     }   }