stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;



const int K = 18, N = 55;



vector<int> vv[1<<K];



long long C[N][N];



void pre() {

    for (int i=0; i<N; i++) C[i][0] = 1;

    for (int i=1; i<N; i++)

        for (int j=1; j<N; j++)

            C[i][j] = C[i-1][j-1] + C[i-1][j];



    for (int i=0; i<N; i++)

        for (int j=1; j<N; j++)

            C[i][j] += C[i][j-1];

}



int main() {

    ios::sync_with_stdio(0);

    cin.tie(0);

    pre();





    int n, k, S, T;

    cin>>n>>k>>S>>T;



    vector<int> v(n);

    for (int i=0; i<n; i++) cin>>v[i];

    sort(v.begin(), v.end());



    if ( (S&T) != S) {

        cout<<0<<endl;

        return 0;

    }



    for (int i=0; i<n; i++) {

        int x = v[i];



        if ((x&S) != S) continue;

        if ((x&T) != x) continue;



        for (int mask = 0; mask < (1<<K); mask++) {

            if ((mask&S) != S) continue;

            if ((mask&T) != mask) continue;

            int ans = x & (~mask);

            vv[mask].push_back(ans);

        }

    }



    long long ans = 0;

    for (int mask = 0; mask < (1<<K); mask++) {

        if ((mask&S) != S) continue;

        if ((mask&T) != mask) continue;

        sort(vv[mask].begin(), vv[mask].end());



        long long ww = 0;

        while (vv[mask].size()) {

            int last = vv[mask].back();

            int cnt = 0;

            while (vv[mask].size() && vv[mask].back() == last)  cnt++, vv[mask].pop_back();



            ww += C[cnt][k]-1;

        }



        int bc = __builtin_popcount(mask);

        if (bc%2)   ans += ww;

        else        ans -= ww;

    }

    cout<<abs(ans)<<endl;

}


// Faster C++ solution for the same problem (measured speedup: 6.119623080109617x):
#include<bits/stdc++.h>

using namespace std;



const int K = 18, N = 55;

long long C[N][N];



void pre() {

    for (int i=0; i<N; i++) C[i][0] = 1;

    for (int i=1; i<N; i++)

        for (int j=1; j<N; j++)

            C[i][j] = C[i-1][j-1] + C[i-1][j];



    for (int i=0; i<N; i++)

        for (int j=1; j<N; j++)

            C[i][j] += C[i][j-1];

}



bool between(int sub, int super, int x) {

    return (sub&x) == sub && (super&x) == x;

}



int main() {

    ios::sync_with_stdio(0);

    cin.tie(0);

    pre();



    int n, k, S, T;

    cin>>n>>k>>S>>T;



    vector<int> v(n);

    for (int i=0; i<n; i++) cin>>v[i];



    long long ans = 0;

    for (int mask = 0; mask < (1<<K); mask++) {

        if (!between(S, T, mask))  continue;



        vector<int> vv;

        for (int i=0; i<n; i++)

            if (between(S, T, v[i]))

                vv.push_back(v[i] & (~mask));



        sort(vv.begin(), vv.end());



        long long ww = 0;

        while (vv.size()) {

            int last = vv.back();

            int cnt = 0;

            while (vv.size() && vv.back() == last)  cnt++, vv.pop_back();

            ww += C[cnt][k]-1;

        }



        int bc = __builtin_popcount(mask);

        if (bc%2)   ans += ww;

        else        ans -= ww;

    }

    cout<<abs(ans)<<endl;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;



const long long K = 18, N = 55;



vector<long long> vv[1<<K];



long long C[N][N];



void pre() {

    for (long long i=0; i<N; i++) C[i][0] = 1;

    for (long long i=1; i<N; i++)

        for (long long j=1; j<N; j++)

            C[i][j] = C[i-1][j-1] + C[i-1][j];



    for (long long i=0; i<N; i++)

        for (long long j=1; j<N; j++)

            C[i][j] += C[i][j-1];

}



int main() {

    ios::sync_with_stdio(0);

    cin.tie(0);

    pre();





    long long n, k, S, T;

    cin>>n>>k>>S>>T;



    if ( (S&T) != S) {

        cout<<0<<endl;

        return 0;

    }



    for (long long i=0; i<n; i++) {

        long long x;

        cin>>x;



        if ((x&S) != S) continue;

        if ((x&T) != x) continue;



        for (long long mask = 0; mask < (1<<K); mask++) {

            if ((mask&S) != S) continue;

            if ((mask&T) != mask) continue;

            int ans = x & (~mask);

            vv[mask].push_back(ans);

        }

    }



    long long ans = 0;

    for (long long mask = 0; mask < (1<<K); mask++) {

        if ((mask&S) != S) continue;

        if ((mask&T) != mask) continue;

        sort(vv[mask].begin(), vv[mask].end());



        long long ww = 0;

        while (vv[mask].size()) {

            long long last = vv[mask].back();

            long long cnt = 0;

            while (vv[mask].size() && vv[mask].back() == last)  cnt++, vv[mask].pop_back();



            ww += C[cnt][k]-1;

        }



        long long bc = __builtin_popcount(mask);

        if (bc%2)   ans += ww;

        else        ans -= ww;

    }

    cout<<abs(ans)<<endl;

}


// Faster C++ solution for the same problem (measured speedup: 6.153253450855685x):
#include<bits/stdc++.h>

using namespace std;



const int K = 18, N = 55;

long long C[N][N];

int cnt[1<<K];



void pre() {

    for (int i=0; i<N; i++) C[i][0] = 1;

    for (int i=1; i<N; i++)

        for (int j=1; j<N; j++)

            C[i][j] = C[i-1][j-1] + C[i-1][j];



    for (int i=0; i<N; i++)

        for (int j=1; j<N; j++)

            C[i][j] += C[i][j-1];

}



int main() {

    ios::sync_with_stdio(0);

    cin.tie(0);

    pre();



    int n, k, S, T;

    cin>>n>>k>>S>>T;



    vector<int> v(n);

    for (int i=0; i<n; i++) cin>>v[i];



    long long ans = 0;

    for (int mask = 0; mask < (1<<K); mask++) {

        if ((S&mask) != S || (T&mask) != mask)  continue;



        vector<int> vv;

        for (int i=0; i<n; i++) {

            if ((S&v[i]) != S || (T&v[i]) != v[i])  continue;

            int z = v[i] & (~mask);

            cnt[z]++;

            vv.push_back(z);

        }



        long long ww = 0;

        for (int x: vv){

            ww += C[cnt[x]][k]-1;

            cnt[x] = 0;

        }



        int bc = __builtin_popcount(mask);

        if (bc%2)   ans += ww;

        else        ans -= ww;

    }

    cout<<abs(ans)<<endl;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;



const int K = 18, N = 55;



vector<int> vv[1<<K];



long long C[N][N];



void pre() {

    for (int i=0; i<N; i++) C[i][0] = 1;

    for (int i=1; i<N; i++)

        for (int j=1; j<N; j++)

            C[i][j] = C[i-1][j-1] + C[i-1][j];



    for (int i=0; i<N; i++)

        for (int j=1; j<N; j++)

            C[i][j] += C[i][j-1];

}



int main() {

    ios::sync_with_stdio(0);

    cin.tie(0);

    pre();





    int n, k, S, T;

    cin>>n>>k>>S>>T;



    if ( (S&T) != S) {

        cout<<0<<endl;

        return 0;

    }



    for (int i=0; i<n; i++) {

        int x;

        cin>>x;



        if ((x&S) != S) continue;

        if ((x&T) != x) continue;



        for (int mask = 0; mask < (1<<K); mask++) {

            if ((mask&S) != S) continue;

            if ((mask&T) != mask) continue;

            int ans = x & (~mask);

            vv[mask].push_back(ans);

        }

    }



    long long ans = 0;

    for (int mask = 0; mask < (1<<K); mask++) {

        if ((mask&S) != S) continue;

        if ((mask&T) != mask) continue;

        sort(vv[mask].begin(), vv[mask].end());



        long long ww = 0;

        while (vv[mask].size()) {

            int last = vv[mask].back();

            int cnt = 0;

            while (vv[mask].size() && vv[mask].back() == last)  cnt++, vv[mask].pop_back();



            ww += C[cnt][k]-1;

        }



        int bc = __builtin_popcount(mask);

        if (bc%2)   ans += ww;

        else        ans -= ww;

    }

    cout<<abs(ans)<<endl;

}


// Faster C++ solution for the same problem (measured speedup: 6.2045477185784526x):
#include<bits/stdc++.h>

using namespace std;



const int K = 18, N = 55;

long long C[N][N];

int cnt[1<<K];



void pre() {

    for (int i=0; i<N; i++) C[i][0] = 1;

    for (int i=1; i<N; i++)

        for (int j=1; j<N; j++)

            C[i][j] = C[i-1][j-1] + C[i-1][j];



    for (int i=0; i<N; i++)

        for (int j=1; j<N; j++)

            C[i][j] += C[i][j-1];

}



int main() {

    ios::sync_with_stdio(0);

    cin.tie(0);

    pre();



    int n, k, S, T;

    cin>>n>>k>>S>>T;



    vector<int> v(n);

    for (int i=0; i<n; i++) cin>>v[i];



    long long ans = 0;

    for (int mask = 0; mask < (1<<K); mask++) {

        if ((S&mask) != S || (T&mask) != mask)  continue;



        vector<int> vv;

        for (int i=0; i<n; i++) {

            if ((S&v[i]) != S || (T&v[i]) != v[i])  continue;

            int z = v[i] & (~mask);

            cnt[z]++;

            vv.push_back(z);

        }



        long long ww = 0;

        for (int x: vv){

            ww += C[cnt[x]][k]-1;

            cnt[x] = 0;

        }



        int bc = __builtin_popcount(mask);

        if (bc%2)   ans += ww;

        else        ans -= ww;

    }

    cout<<abs(ans)<<endl;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;



const int K = 18, N = 55;



vector<int> vv[1<<K];



long long C[N][N];



void pre() {

    for (int i=0; i<N; i++) C[i][0] = 1;

    for (int i=1; i<N; i++)

        for (int j=1; j<N; j++)

            C[i][j] = C[i-1][j-1] + C[i-1][j];



    for (int i=0; i<N; i++)

        for (int j=1; j<N; j++)

            C[i][j] += C[i][j-1];

}



int main() {

    ios::sync_with_stdio(0);

    cin.tie(0);

    pre();





    int n, k, S, T;

    cin>>n>>k>>S>>T;



    vector<int> v(n);

    for (int i=0; i<n; i++) cin>>v[i];

    sort(v.begin(), v.end());



    if ( (S&T) != S) {

        cout<<0<<endl;

        return 0;

    }



    for (int i=0; i<n; i++) {

        int x = v[i];



        if ((x&S) != S) continue;

        if ((x&T) != x) continue;



        for (int mask = 0; mask < (1<<K); mask++) {

            if ((mask&S) != S) continue;

            if ((mask&T) != mask) continue;

            int ans = x & (~mask);

            vv[mask].push_back(ans);

        }

    }



    long long ans = 0;

    for (int mask = 0; mask < (1<<K); mask++) {

        if ((mask&S) != S) continue;

        if ((mask&T) != mask) continue;

        sort(vv[mask].begin(), vv[mask].end());



        long long ww = 0;

        while (vv[mask].size()) {

            int last = vv[mask].back();

            int cnt = 0;

            while (vv[mask].size() && vv[mask].back() == last)  cnt++, vv[mask].pop_back();



            ww += C[cnt][k]-1;

        }



        int bc = __builtin_popcount(mask);

        if (bc%2)   ans += ww;

        else        ans -= ww;

    }

    cout<<abs(ans)<<endl;

}


// Faster C++ solution for the same problem (measured speedup: 6.231024176292268x):
#include<bits/stdc++.h>

using namespace std;



const int K = 18, N = 55;

long long C[N][N];

int cnt[1<<K];



void pre() {

    for (int i=0; i<N; i++) C[i][0] = 1;

    for (int i=1; i<N; i++)

        for (int j=1; j<N; j++)

            C[i][j] = C[i-1][j-1] + C[i-1][j];



    for (int i=0; i<N; i++)

        for (int j=1; j<N; j++)

            C[i][j] += C[i][j-1];

}



int main() {

    ios::sync_with_stdio(0);

    cin.tie(0);

    pre();



    int n, k, S, T;

    cin>>n>>k>>S>>T;



    vector<int> v(n);

    for (int i=0; i<n; i++) cin>>v[i];



    long long ans = 0;

    for (int mask = 0; mask < (1<<K); mask++) {

        if ((S&mask) != S || (T&mask) != mask)  continue;



        vector<int> vv;

        for (int i=0; i<n; i++) {

            if ((S&v[i]) != S || (T&v[i]) != v[i])  continue;

            int z = v[i] & (~mask);

            cnt[z]++;

            vv.push_back(z);

        }



        long long ww = 0;

        for (int x: vv){

            ww += C[cnt[x]][k]-1;

            cnt[x] = 0;

        }



        int bc = __builtin_popcount(mask);

        if (bc%2)   ans += ww;

        else        ans -= ww;

    }

    cout<<abs(ans)<<endl;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



int l[200010], r[200010], lqz[200010], rqz[200010], s[200010];



int main()

{

	int n;

	scanf("%d", &n);

	for (int i = 0; i < n; ++i)

	{

		scanf("%d%d", &l[i], &r[i]);

		lqz[l[i]]++;

		rqz[r[i]]++;

		s[l[i]]++;

		s[r[i]]--;

	}

	for (int i = 1; i <= 100000; ++i)

	{

		lqz[i] += lqz[i - 1];

		rqz[i] += rqz[i - 1];

		s[i] += s[i - 1];

	}

	int ans1(0), ans2(0);

	for (int i = 0; i < n; ++i)

		ans1 = max(ans1, lqz[r[i] - 1] - rqz[l[i]]);

	for (int i = 1; i <= 100000; ++i)

		ans2 = max(ans2, s[i]);

	printf("%d %d\n", ans1, ans2);

	

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.667801064178504x):
#include <bits/stdc++.h>

#define LL long long

#define N 200100

using namespace std;



int cnt[N],a[N],b[N];

int l[N],r[N];

int n,ans1,ans2,m;



int main()

{

	scanf("%d",&n); m=0;

	for (int i=1;i<=n;i++)

	{ 

		scanf("%d %d",&l[i],&r[i]); m=max(m,r[i]);

		cnt[l[i]]++; cnt[r[i]]--;

		a[l[i]]++;   b[r[i]]++;

	}

	for (int i=1;i<=m;i++) a[i]+=a[i-1],b[i]+=b[i-1],cnt[i]+=cnt[i-1];

	for (int i=1;i<=n;i++) ans1=max(ans1,n-(n-a[r[i]-1])-b[l[i]]);

	for (int i=1;i<=m;i++) ans2=max(ans2,cnt[i]);

	printf("%d %d\n",ans1,ans2);

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define vi vector<int>

#define pb push_back

#define LIM 210005



using namespace std;



vi lft,rgt;

int n, xx[LIM], yy[LIM];



#define MAX 200105



int arr[LIM];



int notun()

{

//    int n;

//    sf(n);

    for(int i=0; i<n; i++)

    {

//        int a,b;



//        sff(a,b);

        arr[ xx[i] ]++;

        arr[ yy[i] ]--;

    }



    int mx = INT_MIN;



    for(int i=1; i<=MAX; i++)

    {

        arr[i] += arr[i-1];

        mx = max(mx,arr[i]);

    }



    cout << " " << mx << endl;







    return 0;

}



int main() {

    scanf("%d", &n);

    for(int i=0; i<n; i++) {

        int x,y;

        scanf("%d %d", &x,&y);

        xx[i] = x; yy[i] = y;

        lft.pb(x); rgt.pb(y);

    }

    sort(lft.begin(), lft.end());

    sort(rgt.begin(), rgt.end());



    int ans = 0;

    for(int i=0; i<n; i++) {

        int pise = upper_bound(rgt.begin(), rgt.end(), xx[i])-rgt.begin();

        int samne= n-(lower_bound(lft.begin(), lft.end(), yy[i])-lft.begin());

        ans = max( ans, n - pise - samne );

//        cout << i << ' ' << pise << ' ' << samne << endl;

    }

    cout << ans ;



    notun();

}




// Faster C++ solution for the same problem (measured speedup: 2.0312653526883717x):
#include <bits/stdc++.h>

#define LL long long

#define N 200100

using namespace std;



int cnt[N],a[N],b[N];

int l[N],r[N];

int n,ans1,ans2,m;



int main()

{

	scanf("%d",&n); m=0;

	for (int i=1;i<=n;i++)

	{ 

		scanf("%d %d",&l[i],&r[i]); m=max(m,r[i]);

		cnt[l[i]]++; cnt[r[i]]--;

		a[l[i]]++;   b[r[i]]++;

	}

	for (int i=1;i<=m;i++) a[i]+=a[i-1],b[i]+=b[i-1],cnt[i]+=cnt[i-1];

	for (int i=1;i<=n;i++) ans1=max(ans1,n-(n-a[r[i]-1])-b[l[i]]);

	for (int i=1;i<=m;i++) ans2=max(ans2,cnt[i]);

	printf("%d %d\n",ans1,ans2);

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define vi vector<int>

#define pb push_back

#define LIM 210005



using namespace std;



vi lft,rgt;

int n, xx[LIM], yy[LIM];



#define MAX 200105



int arr[LIM];



int notun()

{

//    int n;

//    sf(n);

    for(int i=0; i<n; i++)

    {

//        int a,b;



//        sff(a,b);

        arr[ xx[i] ]++;

        arr[ yy[i] ]--;

    }



    int mx = INT_MIN;



    for(int i=1; i<=MAX; i++)

    {

        arr[i] += arr[i-1];

        mx = max(mx,arr[i]);

    }



    cout << " " << mx << endl;







    return 0;

}



int main() {

    scanf("%d", &n);

    for(int i=0; i<n; i++) {

        int x,y;

        scanf("%d %d", &x,&y);

        xx[i] = x; yy[i] = y;

        lft.pb(x); rgt.pb(y);

    }

    sort(lft.begin(), lft.end());

    sort(rgt.begin(), rgt.end());



    int ans = 0;

    for(int i=0; i<n; i++) {

        int pise = upper_bound(rgt.begin(), rgt.end(), xx[i])-rgt.begin();

        int samne= n-(lower_bound(lft.begin(), lft.end(), yy[i])-lft.begin());

        ans = max( ans, n - pise - samne );

//        cout << i << ' ' << pise << ' ' << samne << endl;

    }

    cout << ans ;



    notun();

}




// Faster C++ solution for the same problem (measured speedup: 1.3058169576300518x):
#include<bits/stdc++.h>

using namespace std;

const int maxn=2*1e5+100;

int a[maxn],b[maxn],s[maxn],vl[maxn],vr[maxn];

int main()

{

    int n,t,last,ans2=0,ans1=0;

    scanf("%d",&n);

    for(int i=0; i<n; i++)

    {

        scanf("%d %d",&a[i],&b[i]);

        s[a[i]]++,s[b[i]]--;

        vl[a[i]]++,vr[b[i]]++;

    }

    for(int i=1; i<=100000; i++)

    {

        ans2=max(s[i]=s[i-1]+s[i],ans2);

        vr[i]+=vr[i-1];

        vl[100001-i]+=vl[100002-i];

    }

    for(int i=0; i<n; i++)ans1=max(n-vl[b[i]]-vr[a[i]],ans1);

    printf("%d %d\n",ans1,ans2);

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

const int maxn=2*1e5+100;

int a[maxn],b[maxn],s[maxn],sum[maxn],rr[maxn],ll[maxn];

int main()

{

    //freopen("i.txt","r",stdin);

    int n,t,last,ans2=0,ans1=0;

    scanf("%d",&n);

    priority_queue<int,vector<int>,greater<int> >r;

    priority_queue<int,vector<int>,less<int> >l;

    for(int i=0; i<n; i++)

    {

        scanf("%d %d",&a[i],&b[i]);

        s[a[i]]++,s[b[i]]--;

        l.push(a[i]),r.push(b[i]);

    }

    t=r.top(),r.pop();

    rr[last=t]=1;

    while(!r.empty())

    {

        t=r.top(),r.pop();

        rr[t]=rr[last]+1;

        last=t;

    }

    t=l.top(),l.pop();

    ll[last=t]=1;

    while(!l.empty())

    {

        t=l.top(),l.pop();

        ll[t]=ll[last]+1;

        last=t;

    }

    for(int i=1; i<=100000; i++)

        if(!rr[i])rr[i]=rr[i-1];

    for(int i=100000; i>=0; i--)

        if(!ll[i])ll[i]=ll[i+1];

    for(int i=0; i<n; i++)

        ans1=max(n-ll[b[i]]-rr[a[i]],ans1);

    for(int i=1; i<=100000; i++)

        ans2=max(s[i]=s[i-1]+s[i],ans2);

    printf("%d %d\n",ans1,ans2);

}




// Faster C++ solution for the same problem (measured speedup: 1.4857941352620188x):
#include<bits/stdc++.h>

using namespace std;

const int maxn=2*1e5+100;

int a[maxn],b[maxn],s[maxn],vl[maxn],vr[maxn];

int main()

{

    int n,t,last,ans2=0,ans1=0;

    scanf("%d",&n);

    for(int i=0; i<n; i++)

    {

        scanf("%d %d",&a[i],&b[i]);

        s[a[i]]++,s[b[i]]--;

        vl[a[i]]++,vr[b[i]]++;

    }

    for(int i=1; i<=100000; i++)

    {

        ans2=max(s[i]=s[i-1]+s[i],ans2);

        vr[i]+=vr[i-1];

        vl[100001-i]+=vl[100002-i];

    }

    for(int i=0; i<n; i++)ans1=max(n-vl[b[i]]-vr[a[i]],ans1);

    printf("%d %d\n",ans1,ans2);

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



int l[200010], r[200010], lqz[200010], rqz[200010], s[200010];



int main()

{

	int n;

	scanf("%d", &n);

	for (int i = 0; i < n; ++i)

	{

		scanf("%d%d", &l[i], &r[i]);

		lqz[l[i]]++;

		rqz[r[i]]++;

		s[l[i]]++;

		s[r[i]]--;

	}

	for (int i = 1; i <= 100000; ++i)

	{

		lqz[i] += lqz[i - 1];

		rqz[i] += rqz[i - 1];

		s[i] += s[i - 1];

	}

	int ans1(0), ans2(0);

	for (int i = 0; i < n; ++i)

		ans1 = max(ans1, lqz[r[i] - 1] - rqz[l[i]]);

	for (int i = 1; i <= 100000; ++i)

		ans2 = max(ans2, s[i]);

	printf("%d %d\n", ans1, ans2);

	

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.6455918261560991x):
#include<cstdio>

#include<iostream>

#include<string>

#include<stack>

#include<algorithm>

#include<cstdio>

#include<map>

#include<cmath>

#include<queue>

#include<iomanip>

#include<cstring>

#include<list>

#include<typeinfo>

#include<vector>



using namespace std;

const int maxn = 2e5+10;

int ans1,ans2,a[maxn],b[maxn],r[maxn],MAX;

int sc[maxn];

int xc[maxn];

int main()

{

    int n;

    cin>>n;

    for(int i=1;i<=n;i++)

    {

        cin>>a[i]>>b[i];

        sc[a[i]]++;

        xc[b[i]]++;

        r[a[i]]++;

        r[b[i]]--;

        MAX = max(MAX, b[i]);

    }

    for(int i = 1;i<= MAX;i++)

    {

        sc[i]+= sc[i-1];

        xc[i]+= xc[i-1];

    }

    for(int i=1; i<=n;i++)

        ans1=max(ans1,sc[b[i]-1]-xc[a[i]]);

    for(int i=1;i<=MAX;i++)

    {

        r[i]+=r[i-1];

        ans2 = max(ans2,r[i]);

    }

    cout<<ans1<<' '<<ans2<<endl;



    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define vi vector<int>

#define pb push_back

#define LIM 210005



using namespace std;



vi lft,rgt;

int n, xx[LIM], yy[LIM];



#define MAX 200105



int arr[LIM];



int notun()

{

//    int n;

//    sf(n);

    for(int i=0; i<n; i++)

    {

//        int a,b;



//        sff(a,b);

        arr[ xx[i] ]++;

        arr[ yy[i] ]--;

    }



    int mx = INT_MIN;



    for(int i=1; i<=MAX; i++)

    {

        arr[i] += arr[i-1];

        mx = max(mx,arr[i]);

    }



    cout << " " << mx << endl;







    return 0;

}



int main() {

    scanf("%d", &n);

    for(int i=0; i<n; i++) {

        int x,y;

        scanf("%d %d", &x,&y);

        xx[i] = x; yy[i] = y;

        lft.pb(x); rgt.pb(y);

    }

    sort(lft.begin(), lft.end());

    sort(rgt.begin(), rgt.end());



    int ans = 0;

    for(int i=0; i<n; i++) {

        int pise = upper_bound(rgt.begin(), rgt.end(), xx[i])-rgt.begin();

        int samne= n-(lower_bound(lft.begin(), lft.end(), yy[i])-lft.begin());

        ans = max( ans, n - pise - samne );

//        cout << i << ' ' << pise << ' ' << samne << endl;

    }

    cout << ans ;



    notun();

}




// Faster C++ solution for the same problem (measured speedup: 2.0042160500626167x):
#include<cstdio>

#include<iostream>

#include<string>

#include<stack>

#include<algorithm>

#include<cstdio>

#include<map>

#include<cmath>

#include<queue>

#include<iomanip>

#include<cstring>

#include<list>

#include<typeinfo>

#include<vector>



using namespace std;

const int maxn = 2e5+10;

int ans1,ans2,a[maxn],b[maxn],r[maxn],MAX;

int sc[maxn];

int xc[maxn];

int main()

{

    int n;

    cin>>n;

    for(int i=1;i<=n;i++)

    {

        cin>>a[i]>>b[i];

        sc[a[i]]++;

        xc[b[i]]++;

        r[a[i]]++;

        r[b[i]]--;

        MAX = max(MAX, b[i]);

    }

    for(int i = 1;i<= MAX;i++)

    {

        sc[i]+= sc[i-1];

        xc[i]+= xc[i-1];

    }

    for(int i=1; i<=n;i++)

        ans1=max(ans1,sc[b[i]-1]-xc[a[i]]);

    for(int i=1;i<=MAX;i++)

    {

        r[i]+=r[i-1];

        ans2 = max(ans2,r[i]);

    }

    cout<<ans1<<' '<<ans2<<endl;



    return 0;

}