malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long pw(long long a, long long b) {     if (b == 0) return 1;     if (b % 2 == 1)       return (a * pw(a * a, b / 2));     else       return (1 * pw(a * a, b / 2));   }   void solve() {     long long n, k;     cin >> n >> k;     long long a[n], b[k];     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     int n1 = 0;     for (int i = 0; i < k; i++) {       cin >> b[i];       if (b[i] == 1) n1++;     }     sort(b, b + k);     long long ans = 0;     for (int i = 0; i < n1; i++) ans += (a[n - 1 - i] * 2);     long long st = 0, en = n - 1 - n1;     for (long long i = k - 1; i >= n1; i--) {       if (b[i] == 1) {         ans += (a[en] * 2);         en--;       } else {         ans += a[en];         b[i]--;         en--;         ans += a[st];         st += b[i];       }     }     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     long long lvl1, lvl2, id;   };   node t[500005];   bool cmp(struct node x, struct node y) {     if (x.lvl1 < y.lvl1)       return true;     else       return false;   }   vector<node> sh;   vector<long long> adj[500005];   long long vis[500005], lvl1[500005], lvl2[500005];   void bfs1(long long n = 1) {     queue<long long> q;     q.push(n);     vis[n] = 1;     lvl1[n] = 0;     while (!q.empty()) {       long long x = q.front();       q.pop();       for (auto &cv : adj[x]) {         if (vis[cv]) continue;         q.push(cv);         vis[cv] = 1;         lvl1[cv] = lvl1[x] + 1;       }     }   }   void bfs2(long long n) {     queue<long long> q;     q.push(n);     vis[n] = 1;     lvl2[n] = 0;     while (!q.empty()) {       long long x = q.front();       q.pop();       for (auto &cv : adj[x]) {         if (vis[cv]) continue;         q.push(cv);         vis[cv] = 1;         lvl2[cv] = lvl2[x] + 1;       }     }   }   node combine(node x, node y) {     if (x.lvl2 > y.lvl2)       return x;     else       return y;   }   void build(long long n) {     for (long long i = n - 1; i > 0; --i)       t[i] = combine(t[i << 1], t[i << 1 | 1]);   }   node query(long long l, long long r, long long n) {     node res;     res.lvl2 = res.lvl1 = res.id = 0;     for (l += n, r += n; l < r; l >>= 1, r >>= 1) {       if (l & 1) res = (combine(t[l++], res));       if (r & 1) res = combine(t[--r], res);     }     return res;   }   long long arr[500005];   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long i, j, k, l, m, n, x, y;     cin >> n >> m >> k;     for (i = 0; i < k; i++) {       cin >> arr[i];     }     for (i = 0; i < m; i++) {       cin >> x;       cin >> y;       adj[x].push_back(y);       adj[y].push_back(x);     }     bfs1();     memset(vis, 0, sizeof vis);     bfs2(n);     for (i = 0; i < k; i++) {       node temp;       temp.id = arr[i];       temp.lvl1 = lvl1[arr[i]];       temp.lvl2 = lvl2[arr[i]];       sh.push_back(temp);     }     sort(sh.begin(), sh.end(), cmp);     for (i = 0; i < sh.size(); i++) {       t[i + k].lvl1 = sh[i].lvl1;       t[i + k].lvl2 = sh[i].lvl2;       t[i + k].id = sh[i].id;     }     build(k);     long long ans = 0;     for (i = 0; i + 1 < sh.size(); i++) {       long long temp;       temp = sh[i].lvl1;       temp++;       temp += query(i + 1, sh.size(), sh.size()).lvl2;       ans = max(ans, temp);     }     cout << min(lvl2[1], ans) << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma warning(disable : 4786)   #pragma comment(linker,  /STACK:102400000,102400000 )   using namespace std;   const double eps = 1e-8;   const double PI = acos(-1.0);   const int MAXN = 200005;   const int mod = 1000000007;   const long long llinf = (long long)(1e18) + 500;   const int inf = 0x3f3f3f3f;   int x[1005];   double y[1005];   int main() {     int i, j, k, m;     int n, r;     scanf( %d%d , &n, &r);     for (i = 1; i <= n; i++) {       scanf( %d , x + i);       y[i] = r * 1.0;     }     for (i = 2; i <= n; i++) {       for (j = i - 1; j >= 1; j--) {         int dx = abs(x[i] - x[j]);         if (dx > 2 * r) continue;         y[i] = max(y[i], y[j] + sqrt(4 * r * r * 1.0 - dx * 1.0 * dx));       }     }     for (i = 1; i <= n; i++) {       printf( %.10lf%c , y[i], i == n ?   n  :    );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char str[1000005 + 1];   int main() {     int ans = 0, i;     stack<int> S;     scanf( %s , str);     for (i = 0; str[i] !=   0 ; ++i) {       if (str[i] ==  ( ) S.push(i);       if (str[i] ==  )  && !S.empty()) {         S.pop();         ans += 2;       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int y, b, r;     cin >> y >> b >> r;     while (1) {       if (r - 1 <= b && r - 2 <= y) {         break;       }       --r;     }     cout << 3 * r - 3;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string n;     cin >> n;     long long even = 0;     long long odd = 0;     long long len = n.length();     long long aeven = 0;     long long aodd = 0;     long long beven = 0;     long long bodd = 0;     for (int i = 0; i < len; i++) {       if (n[i] ==  a ) {         if (i % 2 == 1) {           aodd++;           odd += aodd;           even += aeven;         } else {           aeven++;           odd += aeven;           even += aodd;         }       } else {         if (i % 2 == 1) {           bodd++;           odd += bodd;           even += beven;         } else {           beven++;           odd += beven;           even += bodd;         }       }     }     cout << even <<     << odd << endl;   }
#include <bits/stdc++.h>   using namespace std;   int const N = 100000;   long long a[N + 1];   long long f[N * 3];   inline int lc(int root) { return root << 1; }   inline int rc(int root) { return (root << 1) | 1; }   void build(int root, int l, int r) {     f[root] = -1;     if (l == r) {       f[root] = a[l];       return;     }     int mid = (l + r) >> 1;     build(lc(root), l, mid);     build(rc(root), mid + 1, r);     if (f[lc(root)] == f[rc(root)]) {       f[root] = f[lc(root)];     }   }   void update(int root, int l, int r, int fi, int la, long long val) {     if (fi == l && la == r) {       f[root] = val;       return;     }     int mid = (l + r) >> 1;     f[root] = -1;     if (fi > mid) {       update(rc(root), mid + 1, r, fi, la, val);     } else if (la <= mid) {       update(lc(root), l, mid, fi, la, val);     } else {       update(lc(root), l, mid, fi, mid, val);       update(rc(root), mid + 1, r, mid + 1, la, val);     }     if (f[lc(root)] == f[rc(root)]) {       f[root] = f[lc(root)];     }   }   long long query(int root, int l, int r, int fi, int la) {     if (f[root] != -1) {       return f[root];     }     int mid = (l + r) >> 1;     if (fi > mid) {       return query(rc(root), mid + 1, r, fi, la);     } else if (la <= mid) {       return query(lc(root), l, mid, fi, la);     } else {       return max(query(lc(root), l, mid, fi, mid),                  query(rc(root), mid + 1, r, mid + 1, la));     }   }   void work() {     int n;     int m;     long long w, h;     long long res;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %I64d , &a[i]);     }     build(1, 1, n);     scanf( %d , &m);     while (m--) {       scanf( %I64d%I64d , &w, &h);       res = query(1, 1, n, 1, w);       printf( %I64d n , res);       update(1, 1, n, 1, w, res + h);     }   }   int main() {     work();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<long long int, int> mp;   int main() {     long long int b, q, l, m, t;     scanf( %lld%lld%lld%lld , &b, &q, &l, &m);     for (int i = 0; i < m; i++) {       scanf( %lld , &t);       mp[t] = 1;     }     if (b < -l || b > l) {       printf( 0 n );       return 0;     }     if (b == 0) {       if (mp[0])         printf( 0 n );       else         printf( inf n );       return 0;     } else if (q == 0) {       if (mp[b] && mp[0])         printf( 0 n );       else if (!mp[b] && mp[0])         printf( 1 n );       else         printf( inf n );       return 0;     } else if (q == 1) {       if (mp[b])         printf( 0 n );       else         printf( inf n );       return 0;     } else if (q == -1) {       if (mp[b] && mp[-b])         printf( 0 n );       else         printf( inf n );       return 0;     } else {       long long int cont = 0;       while (b <= l && b >= -l) {         if (!mp[b]) cont++;         b *= q;       }       printf( %lld n , cont);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     string a, c;     int b, d, p;     int pos[110];     p = 0;     cin >> b >> d;     cin >> a;     cin >> c;     int t = 0, la, lc;     la = a.length();     lc = c.length();     int k = 0;     for (int i = 0; i < lc; i++) {       k = 0;       for (int j = 0; j < la; j++)         if (a[j] == c[(i + k) % lc]) k++;       pos[i] = k;     }     int sum = 0;     int j = 0;     for (int i = 0; i < b; i++) {       sum += pos[j];       j = (j + pos[j]) % lc;     }     sum /= lc;     p = sum / d;     cout << p << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, a, b;   set<pair<int, int> > s;   set<int> sc;   vector<int> ans;   int main() {     cin >> n >> m;     for (int i = 1; i <= m; ++i) {       cin >> a >> b;       s.insert(make_pair(min(a, b), max(a, b)));     }     for (int i = 1; i <= n; ++i) {       sc.insert(i);     }     for (int i = 1; i <= n; ++i) {       if (sc.find(i) != sc.end()) {         int cur = 0;         queue<int> q;         q.push(i);         sc.erase(i);         while (!q.empty()) {           cur++;           int v = q.front();           q.pop();           set<int>::iterator it;           set<int> c = sc;           for (it = c.begin(); it != c.end(); it++) {             int to = *it;             if (s.find(make_pair(min(v, to), max(v, to))) == s.end()) {               q.push(to);               sc.erase(to);             }           }         }         ans.push_back(cur);       }     }     sort(ans.begin(), ans.end());     cout << (int)ans.size() << endl;     for (int i = 0; i < (int)ans.size(); ++i) {       cout << ans[i] <<    ;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:10000000 )   using namespace std;   template <typename T>   inline T abs(T a) {     return ((a < 0) ? -a : a);   }   template <typename T>   inline T sqr(T a) {     return a * a;   }   const int INF = (int)1E9 + 7;   const long double EPS = 1E-9;   const long double PI = 3.1415926535897932384626433832795;   const int NMAX = 200 * 1000;   int a[NMAX], sza;   int t[NMAX * 4], cnt[NMAX * 4];   long long sum[NMAX * 4][5];   char buf[300];   void upd(int pos, int idx, int lf, int rg) {     if (lf == rg) {       t[idx] ^= 1;       memset(sum[idx], 0, sizeof sum[idx]);       sum[idx][0] = t[idx] * 1LL * a[pos];       cnt[idx] = t[idx];       return;     }     int mid = (lf + rg) >> 1;     if (pos <= mid)       upd(pos, 2 * idx + 1, lf, mid);     else       upd(pos, 2 * idx + 2, mid + 1, rg);     cnt[idx] = cnt[2 * idx + 1] + cnt[2 * idx + 2];     for (int i = 0; i < int(5); ++i) {       long long& ans = sum[idx][i];       int f = (cnt[2 * idx + 1]) % 5;       f = (i - f + 5) % 5;       ans = sum[2 * idx + 1][i] + sum[2 * idx + 2][f];     }   }   void change(int val) {     int pos = lower_bound(a, a + sza, val) - a;     upd(pos, 0, 0, sza - 1);   }   inline long long getSum() { return sum[0][2]; }   int main() {     int n;     scanf( %d , &n);     gets(buf);     vector<pair<int, int> > q;     for (int i = 0; i < int(n); ++i) {       gets(buf);       if (buf[0] ==  a ) {         int val;         sscanf(buf,  add %d , &val);         q.push_back(make_pair(1, val));         a[sza++] = val;       }       if (buf[0] ==  d ) {         int val;         sscanf(buf,  del %d , &val);         q.push_back(make_pair(-1, val));         a[sza++] = val;       }       if (buf[0] ==  s ) {         q.push_back(make_pair(-1, -1));       }     }     sort(a, a + sza);     sza = unique(a, a + sza) - a;     for (int i = 0; i < int(n); ++i) {       if (q[i] == pair<int, int>(-1, -1)) {         printf( %I64d n , getSum());         continue;       }       if (q[i].first == 1) {         change(q[i].second);       } else {         change(q[i].second);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[100001];   int getBound(int start, int dir, int size, int k) {     int cnt = 0;     bool seen[100001];     fill(seen, seen + 100001, false);     for (int i = start; i <= size && i > 0; i += dir) {       if (!seen[a[i]]) cnt++, seen[a[i]] = true;       if (cnt == k) return i;     }     return -1;   }   int main() {     int n, k;     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> a[i];     int right = getBound(1, 1, n, k);     if (right == -1)       cout << -1 <<     << -1 << endl;     else {       int left = getBound(right, -1, n, k);       cout << left <<     << right << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MAX = 10e5;   vector<long long> graph[MAX];   queue<long long> q;   bool visit[MAX];   long long a[MAX];   long long s[MAX];   long long parent[MAX];   int main() {     memset(visit, false, sizeof(visit));     long long nodes;     cin >> nodes;     for (auto i = 2; i <= nodes; ++i) {       long long tmp;       cin >> tmp;       parent[i] = tmp;       graph[i].push_back(tmp);       graph[tmp].push_back(i);     }     for (auto i = 1; i <= nodes; ++i) {       cin >> s[i];     }     a[1] = s[1];     q.push(1);     visit[1] = true;     while (!q.empty()) {       long long n = q.front();       q.pop();       if (n != 1) {         if (s[n] == -1) {           s[n] = s[parent[n]];           if (graph[n].size() > 1) {             long long mini = 10e9;             for (auto v : graph[n]) {               if (v == parent[n]) continue;               mini = min(mini, s[v]);             }             if (mini < s[n]) {               cout << -1;               return 0;             } else {               a[n] = mini - s[n];               s[n] = mini;             }           } else {             a[n] = 0;             s[n] = s[parent[n]];           }         } else {           a[n] = s[n] - s[parent[n]];         }       }       for (auto p : graph[n]) {         if (visit[p]) continue;         q.push(p);         visit[p] = true;       }     }     long long ans = 0;     for (auto i = 1; i <= nodes; i++) {       ans += a[i];     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     string s;     cin >> s;     string ans =   ;     int cnt(0);     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  0  && cnt == 0) {         cnt++;       } else         ans += s[i];     }     if (cnt == 0) {       for (int i = 0; i < ans.size() - 1; i++) cout << ans[i];     } else       cout << ans;   }   int main() {     long long t;     t = 1;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};   const int N = 500005;   vector<int> arr[N], cnt[N], adj[N];   int vis[N], st[N], fin[N], dep[N];   int tim;   char inp[N];   void dfs(int i, int d) {     vis[i] = 1;     dep[i] = d;     st[i] = ++tim;     arr[d].push_back(st[i]);     int no = 0;     for (int first = 0; first < (int)26; first++)       no |= (first == inp[i] -  a ) << first;     cnt[d].push_back(no);     for (int v : adj[i])       if (!vis[v]) dfs(v, d + 1);     fin[i] = ++tim;   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     for (int i = 0; i < (int)n - 1; i++) {       int first;       cin >> first;       adj[first].push_back(i + 2);       adj[i + 2].push_back(first);     }     for (int i = 0; i < (int)n; i++) cin >> inp[i + 1];     dfs(1, 0);     for (int i = 0; i < (int)N; i++) {       for (int j = 1; j < cnt[i].size(); j++) {         cnt[i][j] ^= cnt[i][j - 1];       }     }     for (int wrd = 0; wrd < (int)m; wrd++) {       int a, b;       cin >> a >> b;       b--;       int no_odds = 0;       vector<int>& v = arr[b];       int l = lower_bound((v).begin(), (v).end(), st[a]) - v.begin();       int r = upper_bound((v).begin(), (v).end(), fin[a]) - v.begin() - 1;       if (l > r) {         cout <<  Yes n ;         continue;       }       for (int first = 0; first < (int)26; first++) {         int add = (cnt[b][r] >> first) & 1;         int sub = (l == 0) ? 0 : ((cnt[b][l - 1] >> first) & 1);         no_odds += (add - sub + 2) % 2;       }       if (no_odds <= 1)         cout <<  Yes n ;       else         cout <<  No n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     while (t--) {       long long int a[3], i;       for (i = 0; i < 3; i++) cin >> a[i];       sort(a, a + 3);       if (a[2] <= a[1] + a[0] + 1)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   struct rangeincrease {     int l, r;   };   rangeincrease actions[100001];   rangeincrease inprogress[100001];   int actionL = 0;   int nums[100001];   int opened = 0;   int main() {     int n;     int i;     cin >> n;     for (i = 1; i <= n; i++) {       cin >> nums[i];     }     for (i = 1; i <= n; i++) {       while (nums[i] > opened) {         opened++;         inprogress[opened].l = i;       }       while (nums[i] < opened) {         inprogress[opened].r = i - 1;         actionL++;         actions[actionL].l = inprogress[opened].l;         actions[actionL].r = inprogress[opened].r;         opened--;       }     }     while (opened > 0) {       inprogress[opened].r = n;       actionL++;       actions[actionL].l = inprogress[opened].l;       actions[actionL].r = inprogress[opened].r;       opened--;     }     cout << actionL << endl;     for (i = 1; i <= actionL; i++) {       cout << actions[i].l <<     << actions[i].r << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 205, inf = 1e9;   int n, a[N];   int tot, lnk[N], fro[N * N * 2], nxt[N * N * 2], son[N * N * 2], c[N * N * 2],       ori[N * N * 2];   int S, T, dep[N], cur[N];   queue<int> q;   int cnt;   bool vis[N];   vector<int> ans[N];   bool isprm(int x) {     if (x == 2 || x == 3 || x == 5 || x == 7) return 1;     for (int i = 2; i <= sqrt(x); ++i)       if (x % i == 0) return 0;     return 1;   }   void add(int x, int y, int z) {     nxt[++tot] = lnk[x], lnk[x] = tot;     fro[tot] = x, son[tot] = y, c[tot] = ori[tot] = z;   }   struct Dinic {     bool bfs(int x = 0) {       memset(dep, 0, sizeof dep), dep[S] = 1;       for (; !q.empty(); q.pop())         ;       q.push(S);       for (; !q.empty();) {         x = q.front(), q.pop();         for (int j = lnk[x]; j; j = nxt[j]) {           if (!dep[son[j]] && c[j]) {             dep[son[j]] = dep[x] + 1;             q.push(son[j]);           }         }       }       return dep[T];     }     int dfs(int x, int f, int ret = 0) {       if (x == T) return f;       for (int &j = cur[x]; j; j = nxt[j]) {         if (dep[son[j]] == dep[x] + 1 && c[j]) {           int delta = dfs(son[j], min(f, c[j]));           c[j] -= delta, c[j ^ 1] += delta;           ret += delta, f -= delta;         }       }       return ret;     }     int answer(int ret = 0) {       for (; bfs();) {         for (int i = S; i <= T; ++i) cur[i] = lnk[i];         ret += dfs(S, inf);       }       return ret;     }   } network;   void dfs(int x, int s) {     vis[x] = 1, ans[cnt].push_back(x);     if (a[x] & 1) {       for (int j = lnk[x]; j; j = nxt[j]) {         if (c[j] != 0 || son[j] == S || son[j] == T) continue;         if (!vis[son[j]]) {           dfs(son[j], s);           break;         }       }     } else {       for (int j = lnk[x]; j; j = nxt[j]) {         if (c[j ^ 1] != 0 || son[j] == S || son[j] == T) continue;         if (!vis[son[j]]) {           dfs(son[j], s);           break;         }       }     }   }   int main() {     cin >> n, tot = 1, S = 0, T = n + 1;     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       if (a[i] & 1)         add(S, i, 2), add(i, S, 0);       else         add(i, T, 2), add(T, i, 0);     }     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; ++j)         if (isprm(a[i] + a[j]) && a[i] % 2 == 1 && a[j] % 2 == 0)           add(i, j, 1), add(j, i, 0);     }     int fl = network.answer();     if (fl != n) return puts( Impossible ), 0;     for (int i = 1; i <= n; ++i)       if (a[i] & 1) {         if (!vis[i]) ++cnt, dfs(i, i);       }     printf( %d n , cnt);     for (int i = 1; i <= cnt; ++i) {       printf( %d , ans[i].size());       for (int j = 0; j < ans[i].size(); ++j) printf(  %d , ans[i][j]);       puts(  );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int NMax = 1003;   enum directions { EAST, NORTH };   struct point {     int x, y;   };   point a[NMax];   int n;   int test(int searchDir, point a[], long double x, long double y) {     if (searchDir == NORTH) {       int nr = 0;       for (int i = 1; i <= n; ++i) {         if (a[i].y >= y &&             (((long double)a[i].x >= x && x <= (long double)a[i + 1].x) ||              ((long double)a[i].x <= x && x >= (long double)a[i + 1].x))) {           nr++;         }       }       return (nr & 1);     } else {       int nr = 0;       for (int i = 1; i <= n; ++i) {         if (a[i].x >= x &&             (((long double)a[i].y >= y && y <= (long double)a[i + 1].y) ||              ((long double)a[i].y <= y && y >= (long double)a[i + 1].y))) {           nr++;         }       }       return (nr & 1);     }   }   int main() {     cin >> n;     for (int i = 1; i <= n + 1; ++i) {       cin >> a[i].x >> a[i].y;     }     int ans = 0;     for (int i = 2; i <= n + 1; ++i) {       if (a[i].x == a[i - 1].x) {         if (a[i].y > a[i - 1].y) {           ans += test(EAST, a, a[i].x, a[i].y + 0.5);         } else {           ans += test(EAST, a, a[i].x, a[i].y - 0.5);         }       } else {         if (a[i].x > a[i - 1].x) {           ans += test(NORTH, a, a[i].x + 0.5, a[i].y);         } else {           ans += test(NORTH, a, a[i].x - 0.5, a[i].y);         }       }     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long px1[133000], px2[133000], py1[133000], py2[133000], sx1[133000],       sx2[133000], sy1[133000], sy2[133000];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     long long a[n + 1], b[n + 1], c[n + 1], d[n + 1];     for (unsigned long long i = 1; i < n + 1; i++)       cin >> a[i] >> b[i] >> c[i] >> d[i];     px1[0] = -9999999999, px2[0] = 9999999999, py1[0] = -9999999999,     py2[0] = 9999999999;     for (unsigned long long i = 1; i < n + 1; i++) {       px1[i] = max(a[i], px1[i - 1]);       px2[i] = min(c[i], px2[i - 1]);       py1[i] = max(b[i], py1[i - 1]);       py2[i] = min(d[i], py2[i - 1]);     }     sx1[n + 1] = -9999999999, sx2[n + 1] = 9999999999, sy1[n + 1] = -9999999999,             sy2[n + 1] = 9999999999;     for (unsigned long long i = n + 1 - 1; i >= 1; i--) {       sx1[i] = max(a[i], sx1[i + 1]);       sx2[i] = min(c[i], sx2[i + 1]);       sy1[i] = max(b[i], sy1[i + 1]);       sy2[i] = min(d[i], sy2[i + 1]);     }     long long ax1, ax2, ay1, ay2;     for (unsigned long long i = 1; i < n + 1; i++) {       ax1 = max(px1[i - 1], sx1[i + 1]);       ax2 = min(px2[i - 1], sx2[i + 1]);       ay1 = max(py1[i - 1], sy1[i + 1]);       ay2 = min(py2[i - 1], sy2[i + 1]);       if (ax1 <= ax2 && ay1 <= ay2) {         cout << ax1 <<     << ay1 << endl;         return 0;       }     }     return 0;   }