Problem:
Problem I
  Starting a Scenic Railroad Service
Jim, working for a railroad company, is responsible for planning a new tourist train service. He is sure that the train route along a scenic valley will arise a big boom, but not quite sure how big the boom will be.
A market survey was ordered and Jim has just received an estimated list of passengers' travel sections. Based on the list, he'd like to estimate the minimum number of train seats that meets the demand.
Providing as many seats as all of the passengers may cost unreasonably high. Assigning the same seat to more than one passenger without overlapping travel sections may lead to a great cost cutback.
Two different policies are considered on seat assignments. As the views from the train windows depend on the seat positions, it would be better if passengers can choose a seat. One possible policy (named `policy-1') is to allow the passengers to choose an arbitrary seat among all the remaining seats when they make their reservations. As the order of reservations is unknown, all the possible orders must be considered on counting the required number of seats.
The other policy (named `policy-2') does not allow the passengers to choose their seats; the seat assignments are decided by the railroad operator, not by the passengers, after all the reservations are completed. This policy may reduce the number of the required seats considerably.
Your task is to let Jim know how dierent these two policies are by providing him a program that computes the numbers of seats required under the two seat reservation policies. Let us consider a case where there are four stations, S1, S2, S3, and S4, and four expected passengers $p_1$, $p_2$, $p_3$, and $p_4$ with the travel list below.
passenger
from
to
$p_1$
S1
S2
$p_2$
S2
S3
$p_3$
S1
S3
$p_4$
S3
S4
The travel sections of $p_1$ and $p_2$ do not overlap, that of $p_3$ overlaps those of $p_1$ and $p_2$, and that of $p_4$ does not overlap those of any others.
Let's check if two seats would suffice under the policy-1. If $p_1$ books a seat first, either of the two seats can be chosen. If $p_2$ books second, as the travel section does not overlap that of $p_1$, the same seat can be booked, but the other seat may look more attractive to $p_2$. If $p_2$ reserves a seat different from that of $p_1$, there will remain no available seats for $p_3$ between S1 and S3 (Figure I.1).
Figure I.1. With two seats
With three seats, $p_3$ can find a seat with any seat reservation combinations by $p_1$ and $p_2$. $p_4$ can also book a seat for there are no other passengers between S3 and S4 (Figure I.2).
Figure I.2. With three seats
For this travel list, only three seats suffice considering all the possible reservation orders and seat preferences under the policy-1.
On the other hand, deciding the seat assignments after all the reservations are completed enables a tight assignment with only two seats under the policy-2 (Figure I.3).
Figure I.3. Tight assignment to two seats
Input
The 
...(truncated)

Submitted solutions:

code_snippet: #include "bits/stdc++.h"
using namespace std;
#define FOR(i,s,t) for(int (i) = (s); (i)< (t); (i)++)
#define FORR(i,s,t) for(int (i) = (s); (i) > (t); (i)--)
#define debug(x) cout<<#x<<": "<<x<<endl;

typedef long long LL;
typedef vector<LL> VL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<VL> VVL;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
struct BIT {
	int N;
	int nn;
	vector<ll>data;
	BIT(int n) {
		N = n + 1;
		data = vector<LL>(N, 0);
		nn = 1;
		while (nn*2<=N)
		{
			nn *= 2;
		}
	}
	void add(int i, LL w) {
		for (int x = i; x <= N;x += x&-x) {
			data[x] += w;
		}
	}
	LL sum(int i) {
		LL ret = 0;
		for (int x = i;x > 0;x -= x&-x) {
			ret += data[x];
		}
		return ret;
	}
	LL sum(int l, int r) {
		if (l > r)return 0;
		return sum(r) - sum(l - 1);
	}
	void range_add(BIT& bity, int l, int r, LL val) {
		add(l, -val*(l - 1));
		bity.add(l, val);
		add(r + 1, val*r);
		bity.add(r + 1, -val);
	}
	LL range_sum(BIT& bity, int i) {
		return sum(i) + bity.sum(i)*i;
	}
	LL range_sum(BIT& bity, int l, int r) {
		return range_sum(bity, r) - range_sum(bity, l - 1);
	}

};

//struct seg {
//	int L, R;
//	seg() {}
//	seg(int l, int r) {
//		L = l;
//		R = r;
//	}
//	//bool operator <(const seg&x)const{
//	//	if (R == x.R)return L < x.L;
//	//	else return R < x.R;
//	//}
//	bool operator <(const seg&x)const {
//		if (L == x.L)return R < x.R;
//		else return L < x.L;
//	}
//};
typedef pair<int, int> seg;

int main() {
	cin.tie(0); ios::sync_with_stdio(false);

	int N;cin >> N;
	vector<pll> S(N);
	vector<seg> Seg(N);
	BIT bit(100005), bit2(100005);
	FOR(i, 0, N) {
		cin >> S[i].first >> S[i].second;
		Seg[i] = seg(S[i].second - 1,S[i].first);
		bit.range_add(bit2, S[i].first, S[i].second - 1, 1);
	}
	LL ans2 = 0;
	FOR(i, 1, 100001) {
		ans2 = max(ans2, bit.range_sum(bit2, i, i));
	}

	sort(Seg.begin(), Seg.end());
	LL ans = 0;
	priority_queue<int>pq;
	for (int i = N - 1;i >= 0;i--) {
		int nowR = Seg[i].first;
		int nowL = Seg[i].second;

	//	cout << nowL << " " << nowR << endl;

		while (!pq.empty()) {
			int T = pq.top();
			if (nowR < T) {
				pq.pop();
			}
			else {
				break;
			}
		}

		ll Rcnt = pq.size();

		ll Lcnt = i - (upper_bound(Seg.begin(), Seg.begin() + i, seg(nowL-1,INF)) - Seg.begin());

		ans = max(ans, Rcnt + Lcnt + 1);
		//cout << " ==== " << endl;
		//debug(Rcnt);
		//debug(Lcnt);
//		debug(ans);

		pq.push(nowL);
	}
//	debug(ans);
//	debug(ans2);
	cout << ans << " " << ans2 << endl;
	return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 10384
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define rep(i, n) for(ll i = 0; i < (ll)n; ++i)
#define loop(i, a, b) for(ll i = a; i <= b; ++i)
constexpr ll INF = 9009009009009009009LL;



int main() {
    ll n;
    cin >> n;
    vector<ll> policy2(100001, 0);
    vector<ll> a(n), b(n);
    vector<pair<ll,ll>> ab(n);

    rep(i, n){
        cin >> a[i] >> b[i];
        ab[i].first = a[i];
        ab[i].second = b[i];
        policy2[a[i] - 1]++;
        policy2[b[i] - 1]--;
    }

    ll sum = 0;
    ll policy2_ans = 0;

    rep(i, 100001){
        sum += policy2[i];
        policy2[i] = sum;
        policy2_ans = max(policy2_ans, sum);
    }

    // same[区間の始まり、終わり] = その区間の個数
    map<pair<ll,ll>,ll> same;
    sort(ab.begin(),ab.end(), [](pair<ll, ll> a, pair<ll, ll> b) {
        if (a.first != b.first) return a.first < b.first;
        return a.second > b.second;
    });
    
    ll nowmax = 0;
    // 右側ならす
    rep(i, n){
		// a[i]=ab[i].first;
		// b[i]=ab[i].second;
        nowmax = max(ab[i].second,nowmax);
        ab[i].second = nowmax;
        same[ab[i]]++;
    }

    
    vector<ll> policy1(100001, 0);
    rep(i, n){
        policy1[ab[i].first - 1]++;
        // マスで考えると右側が被るのでこっちもマイナス1
        policy1[ab[i].second - 1]--;
    }

    ll sum2 = 0;
    rep(i, 100001){
        sum2 += policy1[i];
        policy1[i] = sum2;
    }
    // 右側にならしたimos policy1
    // 注目する区間を決めて順番にチェック

    // 内包スキップを復活

    ll policy1_ans = 0;
    rep(i, n){
		if(i!=0&&ab[i-1].second>=ab[i].second)continue;
        ll left = ab[i].first - 1;
        ll right = ab[i].second - 2;
        policy1_ans = max(policy1_ans, policy2[left] + policy1[right] - same[ab[i]]);
    }

    cout << policy1_ans << " " << policy2_ans << endl;
    return 0;
}
accuracy: 1
time_ms: 110
memory_kb: 16040
final_rank: 15

code_snippet: // 不难发现，策略2求的值 = max{i到i+1这段路有多少乘客要经过: 1 <= i < 1e5}
// 而策略1求的值 = max{乘客pi的路程与多少人有重叠(含他自己): 1 <= i <= n}
// 因此，计算路径终点<=i的人数 及 路径起点>=i的人数，策略1与策略2无非两个max
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
using namespace std;
const int lth = 1e5 + 4;
int ed[lth], st[lth], bef[lth], aft[lth];
int main(){
	ios::sync_with_stdio(false), cin.tie(0);
	int n;
	cin >> n;
	vector<int> A(n), B(n);
	for (int i = 0, a, b; i < n && cin >> a >> b; ++i)
		A[i] = a, B[i] = b, ++ed[b], ++st[a];
	// 计算bef与aft
	bef[0] = aft[lth-1] = 0;
	FOR(i, 1, lth) bef[i] = bef[i-1] + ed[i], aft[lth-1-i] = aft[lth-i] + st[lth-1-i];
	// 求答案
	int ans1 = 0, ans2 = 0;
	FOR(i, 1, lth-1) ans2 = max(ans2, n - bef[i] - aft[i+1]);
	FOR(i, 0, n) ans1 = max(ans1, n - bef[A[i]] - aft[B[i]]);
	printf("%d %d\n", ans1, ans2);
	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 6128
final_rank: 4

code_snippet: #include <iostream>
#include <iomanip>
#include <cassert>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
// #include "Src/Utility/BinarySearch.hpp"
// #include "Src/Sequence/CompressedSequence.hpp"
// #include "Src/Sequence/RunLengthEncoding.hpp"

namespace zawa {

template <class T>
class AdditiveGroup {
public:
    using Element = T;
    static constexpr T identity() noexcept {
        return T{};
    }
    static constexpr T operation(const T& l, const T& r) noexcept {
        return l + r;
    }
    static constexpr T inverse(const T& v) noexcept {
        return -v;
    }
};

} // namespace zawa


#include <cstdint>
#include <cstddef>

namespace zawa {

using i16 = std::int16_t;
using i32 = std::int32_t;
using i64 = std::int64_t;
using i128 = __int128_t;

using u8 = std::uint8_t;
using u16 = std::uint16_t;
using u32 = std::uint32_t;
using u64 = std::uint64_t;

using usize = std::size_t;

} // namespace zawa


#include <concepts>

namespace zawa {

namespace Concept {

template <class T>
concept Monoid = requires {
    typename T::Element;
    { T::identity() } -> std::same_as<typename T::Element>;
    { T::operation(std::declval<typename T::Element>(), std::declval<typename T::Element>()) } -> std::same_as<typename T::Element>;
};

} // namespace

} // namespace zawa

namespace zawa {

namespace Concept {

template <class T>
concept Inversible = requires {
    typename T::Element;
    { T::inverse(std::declval<typename T::Element>()) } -> std::same_as<typename T::Element>;
};

template <class T>
concept Group = Monoid<T> and Inversible<T>;

} // namespace Concept

} // namespace zawa

#include <ostream>
#include <functional>
#include <type_traits>

namespace zawa {

template <Concept::Group Group>
class FenwickTree {
private:
    using Value = typename Group::Element;

    usize n_;
    u32 bitWidth_;
    std::vector<Value> a_, dat_;

    constexpr i32 lsb(i32 x) const noexcept {
        return x & -x;
    }
    
    // a[i] <- a[i] + v
    void addDat(i32 i, const Value& v) {
        assert(0 <= i and i < static_cast<i32>(n_));
        for ( i++ ; i < static_cast<i32>(dat_.size()) ; i += lsb(i)) {
            dat_[i] = Group::operation(dat_[i], v);
        }
    }

    // return a[0] + a[1] + .. + a[i - 1]
    Value product(i32 i) const {
        assert(0 <= i and i <= static_cast<i32>(n_));
        Value res{ Group::identity() };
        for ( ; i > 0 ; i -= lsb(i)) {
            res = Group::operation(res, dat_[i]);
        }
        return res;
    }

public:
    FenwickTree() : n_{}, bitWidth_{}, a_{}, dat_{} {}

    FenwickTree(usize n) : n_{ n }, bitWidth_{ std::__lg(static_cast<u32>(n)) + 1 }, a_(n), dat_(n + 1, Group::identity()) {
        dat_.shrink_to_fit();
    }

    FenwickTree(const std::vector<Value>& a) : n_{ a.size() }, bitWidth_{ std::__lg(static_cast<u32>(a.size())) + 1 }, a_(a), dat_(a.size() + 1, Group::identity()) {
        dat_.shrink_to_fit();  
        for (i32 i{} ; i < static_cast<i32>(n_) ; i++) {
            addDat(i, a[i]);
        }
    }

    // return a[i]
    const Value& get(usize i) const noexcept {
        assert(i < n_);
        return a_[i];
    }

    // return a[i]
    const Value& operator[](usize i) const noexcept {
        assert(i < n_);
        return a_[i];
    }

    usize size() const noexcept {
        return n_;
    }

    // a[i] <- a[i] + v
    void operation(usize i, const Value& v) {
        assert(i < n_);
        addDat(i, v);
        a_[i] = Group::operation(a_[i], v);
    }

    // a[i] <- v
    void set(usize i, const Value& v) {
        assert(i < n_);
        addDat(i, Group::operation(Group::inverse(a_[i]), v));
        a_[i] = v;
    }

    // return a[0] + a[1] + ... + a[r - 1]
    Value prefixProduct(usize r) const {
        assert(r <= n_);
        return product(r);
    }

    // return a[l] + a[l + 1] ... + a[r - 1]
    Value product(usize l, usize r) const {
        assert(l <= r and r <= n_);
        return Group::operation(Group::inverse(product(l)), product(r));
    }

    template <class Function>
    u32 maxRight(usize l, const Function& f) const {
        static_assert(std::is_convertible_v<decltype(f), std::function<bool(Value)>>, "maxRight's argument f must be function bool(T)");
        assert(l < n_);
        Value sum{ Group::inverse(product(l)) }; 
        u32 r{};
        for (u32 bit{ bitWidth_ } ; bit ; ) {
            bit--;
            u32 nxt{ r | (1u << bit) };
            if (nxt < dat_.size() and f(Group::operation(sum, dat_[nxt]))) {
                sum = Group::operation(sum, dat_[nxt]);
                r = std::move(nxt);
            }
        }
        assert(l <= r);
        return r;
    }

    template <class Function>
    u32 minLeft(usize r, const Function& f) const {
        static_assert(std::is_convertible_v<decltype(f), std::function<bool(Value)>>, "minLeft's argument f must be function bool(T)");
        assert(r <= n_);
        Value sum{ product(r) };
        u32 l{};
        for (u32 bit{ bitWidth_ } ; bit ; ) {
            bit--;
            u32 nxt{ l | (1u << bit) };
            if (nxt <= r and not f(Group::operation(Group::inverse(dat_[nxt]), sum))) {
                sum = Group::operation(Group::inverse(dat_[nxt]), sum);
                l = std::move(nxt);
            }
        }
        assert(l <= r);
        return l;
    }

    // debug print
    friend std::ostream& operator<<(std::ostream& os, const FenwickTree& ft) {
        for (u32 i{} ; i <= ft.size() ; i++) {
            os << ft.prefixProduct(i) << (i == ft.size() ? "" : " ");
        }
        return os;
    }
};


} // namespace zawa
using namespace zawa;
// #include "atcoder/modint"
// using mint = atcoder::modint998244353;
int N, A[200020], B[200020];
int solve1() {
    std::vector<std::pair<int, int>> RL(N);
    for (int i = 0 ; i < N ; i++) RL[i] = {B[i], A[i]};
    std::sort(RL.begin(), RL.end());
    FenwickTree<AdditiveGroup<int>> f1{100010}, f2{100010};
    for (int i = N - 1 ; i >= 0 ; i--) {
        f2.operation(RL[i].second, 1);
    }
    int ans = 0;
    for (auto [r, l] : RL) {
        f2.operation(l, -1);
        ans = std::max(ans, 1 + f1.product(l+1, r) + f2.product(l, r));
        // std::cout << l << ' ' << r << ' ' << 1 + f1.product(l+1, r) + f2.product(l, r) << std::endl;
        f1.operation(r, 1);
    }
    return ans;
}
int solve2() {
    std::vector<std::pair<int, int>> event(2 * N);
    for (int i = 0 ; i < N ; i++) {
        event[2 * i + 0] = {A[i], i};
        event[2 * i + 1] = {B[i], i+N};
    }
    std::sort(event.begin(), event.end());
    int cur = 0, ans = 0;
    for (int i = 0, j = 0 ; i < 2 * N ; i = j) {
        while (j < 2 * N and event[i].first == event[j].first) {
            if (event[j].second >= N) {
                cur--;
            }
            else {
                cur++;
            }
            j++;
        }
        ans = std::max(ans, cur);
    }
    return ans;
}
int main() {
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cin >> N;
    for (int i = 0 ; i < N ; i++) {
        std::cin >> A[i] >> B[i];
    }
    std::cout << solve1() << ' ' << solve2() << '\n';
}
accuracy: 1
time_ms: 60
memory_kb: 8116
final_rank: 9

code_snippet: #include<bits/stdc++.h>
const int MAXN=2e5+5;
int n;
int cnt[MAXN],in[MAXN],out[MAXN];
int a[MAXN],b[MAXN];
signed main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d%d",&a[i],&b[i]);;
        ++cnt[a[i]],--cnt[b[i]],++in[a[i]],++out[b[i]];
    }
    int ans1(0),ans2(0);//方案二答案为在一时刻最多人的数量，
    for(int i=1;i<=n;i++){
        ans2=std::max(ans2,cnt[i]+=cnt[i-1]);
        in[i]+=in[i-1],out[i]+=out[i-1];
    }
    for(int i=1;i<=n;i++) ans1=std::max(ans1,n-(n-in[b[i]-1])-out[a[i]]);
    printf("%d %d\n",ans1,ans2);
}
accuracy: 0.013333333333333334
time_ms: 10
memory_kb: 7460
final_rank: 20

code_snippet: #include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int ans1=0,ans2=0;
int n,a[N],b[N],cnt[N],up[N],down[N];
int main(){
    ios::sync_with_stdio(0),cin.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i]>>b[i];
        cnt[a[i]]++,cnt[b[i]]--;
        up[a[i]]++,down[b[i]]++;
    }
    for(int i=1;i<=n;i++){
        cnt[i]+=cnt[i-1];
        up[i]+=up[i-1];
        down[i]+=down[i-1];
        ans2=max(ans2,cnt[i]);
    }
    for(int i=1;i<=n;i++){
        ans1=max(ans1,up[b[i]-1]-down[a[i]]);
    }
    cout<<ans1<<" "<<ans2<<"\n";
    return 0;
}
accuracy: 0.013333333333333334
time_ms: 10
memory_kb: 7036
final_rank: 19

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main() {
    int N,a,b,x=0,y=0,k=0,s,t=0;
    cin>>N;
    s=N;
    vector<array<int,3>> P(N*2);
    rep(i,N){
        cin>>a>>b;
        P[i*2]={a,1,i},P[i*2+1]={b,0,i};
    }
    sort(P.begin(),P.end());
    vector<int> I(N,N);
    rep(i,2*N){
        if(P[i][1]==0){
            k--,t++;
            I[P[i][2]]-=s;
            x=max(x,I[P[i][2]]);
        }
        else{
            I[P[i][2]]-=t;
            s--,k++;
        }
        y=max(y,k);
    }
    cout<<x<<" "<<y<<endl;
}
accuracy: 1
time_ms: 90
memory_kb: 8516
final_rank: 13

code_snippet: #include<bits/stdc++.h>
using namespace std;

using ll = long long;
#define rep(i,n) for(int i=0;i<n;i++)
int main() {
    int N,a,b,an1=0,an2=0,k=0,s,t=0;
    cin>>N;
    s=N;
    vector<array<int,3>> P(N*2);
    rep(i,N){
        cin>>a>>b;
        P[i*2]={a,1,i};
        P[i*2+1]={b,0,i};
    }
    sort(P.begin(),P.end());
    vector<int> I(N,N);
    rep(i,2*N){
        if(P[i][1]==0){
            k--;
            t++;
            I[P[i][2]]-=s;
            an1=max(an1,I[P[i][2]]);
        }
        else{
            I[P[i][2]]-=t;
            s--;
            k++;
        }
        an2=max(an2,k);
    }
    cout<<an1<<" "<<an2<<endl;
}
accuracy: 1
time_ms: 90
memory_kb: 8524
final_rank: 14

code_snippet: #include<bits/stdc++.h>
using namespace std;

using ll = long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,s,t) for(int i=s;i<t;i++)

using vll=vector<ll>;
using vvll=vector<vll>;


int main() {

    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int N;
    cin>>N;
    vector<array<int,3>> P(N*2);
    rep(i,N){
        int a,b;
        cin>>a>>b;
        P[i*2]={a,1,i};
        P[i*2+1]={b,0,i};
    }
    sort(P.begin(),P.end());
    vector<int> I(N,N);
    int an1=0,an2=0,k=0,s=N,t=0;
    rep(i,2*N){
        if(P[i][1]==0){
            k--;
            t++;
            I[P[i][2]]-=s;
            an1=max(an1,I[P[i][2]]);
        }
        else{
            I[P[i][2]]-=t;
            s--;
            k++;
        }
        an2=max(an2,k);
    }
    cout<<an1<<" "<<an2<<endl;
}
accuracy: 1
time_ms: 50
memory_kb: 8528
final_rank: 5

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define REP(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define P pair<long double, long double>

vector<ll> o[210000], c[210000];
ll opc, cn[210000];
int main() {
  ll n, ans2 = 0, ans1 = 0;
  cin >> n;
  vector<ll> a(n), b(n), s2(101000);
  REP(i, n) {
    cin >> a[i] >> b[i];
    s2[a[i]]++;
    s2[b[i]]--;
    o[a[i]].push_back(i);
    c[b[i]].push_back(i);
  }
  REP(i, 100100) {
    s2[i + 1] += s2[i];
    ans2 = max(ans2, s2[i]);
  }
  REP(i, 100100) {
    opc -= c[i].size();
    cn[i] += c[i].size();
    cn[i + 1] += cn[i];
    REP(j, c[i].size()) {
      ll idx = c[i][j];
      ans1 = max(ans1, cn[b[idx]] - cn[a[idx]] + opc);
    }
    opc += o[i].size();
  }
  cout << ans1 << " " << ans2 << endl;
}
accuracy: 1
time_ms: 120
memory_kb: 24480
final_rank: 18

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,a,b) for(ll i = a; i < b; i++)
#define all(a) (a).begin(), (a).end()

ll sol1(int n, vector<array<ll,2>> p){
    sort(all(p));
    multiset<ll> ls;
    ll mx = 1;
    rep(i,0,n){
        ll res = 0;
        res += lower_bound(all(p), array<ll,2>{p[i][1], 0LL}) - p.begin() - i;
        while(ls.size() && *ls.begin() <= p[i][0]){
            ls.erase(ls.begin());
        }
        res += ls.size();
        ls.insert(p[i][1]);
        mx = max(mx, res);
    }
    return mx;
}
ll sol2(int n, vector<array<ll,2>> p){
    
    sort(all(p));
    multiset<ll> seat;
    seat.insert(0);
    rep(i,0,n){
        if(*seat.begin() <= p[i][0]){
            seat.erase(seat.begin());
            seat.insert(p[i][1]);
        }else{
            seat.insert(p[i][1]);
        }
    }
    return seat.size();
}

int main(){
    int n;
    cin >> n;
    vector<array<ll,2>> p(n);
    rep(i,0,n){
        cin >> p[i][0] >> p[i][1];
    }
    cout << sol1(n, p) << " " << sol2(n, p) << endl;
}
accuracy: 1
time_ms: 100
memory_kb: 22132
final_rank: 16

code_snippet: #pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define all(v) begin(v),end(v)
using namespace std;
using ll = long long;
bool chmin(auto &a, auto b){ return a > b ? a = b, 1 : 0; }
bool chmax(auto &a, auto b){ return a < b ? a = b, 1 : 0; }


template<class S, auto op, auto e> struct segtree {
    int n, sz;
    vector<S> d;
    void upd(int k) { d[k] = op(d[2*k], d[2*k+1]); }
    segtree(int _n=0) : segtree(vector<S>(_n,e())){}
    segtree(vector<S> v) : n(v.size()) {
        sz = bit_ceil<uint32_t>(n);
        d = vector<S>(sz*2, e());
        rep(i,0,n) d[sz+i] = v[i];
        for (int i=sz-1; i>=1; i--) upd(i);
    }
    S prod(int l, int r) {
        S sml= e(), smr = e();
        l+=sz,r+=sz;
        while (l<r) {
            if (l&1)sml=op(sml,d[l++]);
            if (r&1)smr=op(d[--r],smr);
            l>>=1;r>>=1;
        }
        return op(sml, smr);
    }
    void set(int p, S x) {
        p +=sz;
        d[p]=x;
        while (p>>=1) upd(p);
    }
    S get(int p) { return d[p+sz];}
    int max_right(int l, auto f) {
        if (l ==n) return n;
        l+=sz;
        S sm=e();
        do {
            while (l%2==0)l>>=1;
            if (!f(op(sm,d[l]))) {
                while (l<sz) {
                    l<<=1;
                    if (f(op(sm,d[l]))) {sm=op(sm,d[l++]);}

                }
                return l-sz;
            }
            sm=op(sm,d[l++]);
        }while ((l&-l)!=l);
        return n;
    }
    int min_left(int r, auto f) {
        if (r==0) return 0;
        r+=sz;
        S sm=e();
        do {
            r--;
            while (r>1&&(r%2))r>>=1;
            if (!f(op(d[r],sm))) {
                while (r<sz) {
                    r=2*r+1;
                    if (f(op(d[r],sm))) {
                        sm=op(d[r--],sm);
                    }
                }
                return r+1-sz;
            }
            sm=op(d[r],sm);
        }while ((r&-r)!=r);
        return 0;
    }
};

int op(int a, int b) {
    return a + b;
}
int e() {
    return 0;
}

template<typename T> struct compress {
    vector<T> v;
    void add(T x) { v.emplace_back(x);}
    void build() {
        sort(all(v));
        v.erase(unique(all(v)),v.end());
    }
    int lb(T x) { return lower_bound(all(v), x) - v.begin();}
    int raw(int id) { return v[id];}
    int exid(T x) {
        int r = lb(x);
        return (r != (int)v.size() && v[r] == x ? r : -1);
    }
};

template<class S, auto op, auto e, class segtree> struct range_tree {
    int siz;
    compress<int> xs;
    vector<compress<int>> ys;
    vector<segtree> ds;
    range_tree(vector<pair<int,int>>ps) {
        for (auto[x,y]:ps)xs.add(x);
        xs.build();
        siz=bit_ceil(xs.v.size());
        ys.resize(siz*2);
        for (auto[x,y]:ps) {
            int xid=xs.lb(x)+siz;
            ys[xid].add(y);
            while (xid>1) {
                xid>>=1;
                ys[xid].add(y);
            }
        }
        for (int i=0;i<2*siz;i++) {
            ys[i].build();
            ds.emplace_back(ys[i].v.size());
        }


    }
    void set(int x,int y,S val) {
        int i=xs.lb(x)+siz;
        ds[i].set(ys[i].lb(y),val);
        while (i>1) {
            i>>=1;
            S lr=e();
            int i0=ys[2*i+0].exid(y),i1=ys[2*i+1].exid(y);
            if (i0!=-1)lr=op(lr,ds[2*i+0].get(i0));
            if (i1!=-1)lr=op(lr,ds[2*i+1].get(i1));
            ds[i].set(ys[i].lb(y),lr);
        }
    }
    S prod(int lx,int rx,int ly,int ry) {
        S ret=e();
        int li=xs.lb(lx),ri=xs.lb(rx);
        for (li+=siz,ri+=siz;li<ri;li>>=1,ri>>=1) {
            if (li&1)ret=op(ret,ds[li].prod(ys[li].lb(ly),ys[li].lb(ry))),li++;
            if (ri&1)--ri,ret=op(ret,ds[ri].prod(ys[ri].lb(ly),ys[ri].lb(ry)));
        }
        return ret;
    }
};



int main() {
    cin.tie(0)->sync_with_stdio(0);

    const int mx = 100050;
    int n; cin >> n;
    int policy1 = 0;
    int policy2 = 0;
    vector<int> s(n), t(n);
    vector<int> imos(mx);
    rep(i,0,n) {
        cin >> s[i] >> t[i];
        imos[s[i]]++;
        imos[t[i]]--;
    }

    rep(i,0,mx-1) {
        imos[i+1] += imos[i];
    }
    rep(i,0,mx) {
        chmax(policy2, imos[i]);
    }

    vector<pair<int,int>> points;
    map<pair<int,int>,int> mp;
    rep(i,0,n) {
        points.push_back(pair(t[i],s[i]));
        mp[pair(t[i],s[i])]++;
    }

    segtree<int,op,e> seg(mx);
    vector bucket(mx, vector<int>(0));
    vector bucket_in(mx, vector<int>(0));

    rep(i,0,n) {
       bucket[s[i]].push_back(t[i]);
       bucket_in[t[i]].push_back(s[i]);
    }

    rep(i,0,mx) {
        for (int x:bucket_in[i]) {
            chmax(policy1,seg.prod(x+1,mx));
        }
        for (auto x:bucket[i]) {
            seg.set(x, seg.get(x)+1);
        }
    }





    /*
    range_tree<int,op,e,segtree<int,op,e>> rtree(points);

    rep(i,0,n) {
        rtree.set(t[i],s[i],mp[pair(t[i],s[i])]);
    }

    rep(i,0,n) {
        chmax(policy1, rtree.prod(s[i]+1,998244,-1,t[i]) );
       // cout << rtree.prod(s[i]+1,998244,-1,t[i]) <<endl;
    }
    */



    cout << policy1 << ' ' << policy2 << endl;

}
accuracy: 1
time_ms: 80
memory_kb: 27236
final_rank: 17

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll=long long;

/*
	考察
	policy1: ある区間Piについて、Piと被りのある区間が最大幾つ存在するか。
		PASTの整地で見たやつ。余事象。
	policy2: ある時間について、その時間に乗っている乗客の最大数。
*/

int main(){
	int N; cin>>N;
	vector<pair<int,int>> P(N);
	for(auto&[a,b]:P) cin>>a>>b;
	int mx=2e5;

	{
		vector<ll> pl(mx+1),pr=pl;
		for(auto[a,b]:P) pl[a]++,pr[b]++;
		for(int i=0; i<mx; i++) pl[i+1]+=pl[i],pr[i+1]+=pr[i];
		ll ans=0;
		for(auto[a,b]:P) ans=max(ans,N-pr[a]-pl.back()+pl[b-1]);
		cout<<ans<<' ';
	}
	{
		vector<ll> I(mx);
		for(auto[a,b]:P) I[a]++,I[b]--;
		for(int i=0; i<mx-1; i++) I[i+1]+=I[i];
		ll ans=0;
		for(ll i:I) ans=max(ans,i);
		cout<<ans<<endl;
	}
}
accuracy: 1
time_ms: 60
memory_kb: 7864
final_rank: 8

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll=long long;

/*
	考察
	policy1: ある区間Piについて、Piと被りのある区間が最大幾つ存在するか。
		PASTの整地で見たやつ。余事象。
	policy2: ある時間について、その時間に乗っている乗客の最大数。
*/

struct ST{
	vector<ll> dat;
	int n;
	ST(vector<ll> v){
		int n=v.size();
		dat.resize(n*2);
		for(int i=0; i<n; i++) dat[i+n]=v[i];
		for(int i=n-1; i>0; i--) dat[i]=max(dat[i*2],dat[i*2+1]);
	}
	ll prod(int l, int r){
		l+=n, r+=n;
		ll ret=0;
		while(l<r){
			if(l&1) ret=max(ret,dat[l++]);
			if(r&1) ret=max(ret,dat[--r]);
			l/=2, r/=2;
		}
		return ret;
	}
};

int main(){
	int N; cin>>N;
	vector<pair<int,int>> P(N);
	for(auto&[a,b]:P) cin>>a>>b;
	int mx=2e5;

	{
		vector<ll> pl(mx+1),pr=pl;
		for(auto[a,b]:P) pl[a]++,pr[b]++;
		for(int i=0; i<mx; i++) pl[i+1]+=pl[i],pr[i+1]+=pr[i];
		ll ans=0;
		for(auto[a,b]:P) ans=max(ans,N-pr[a]-pl.back()+pl[b-1]);
		cout<<ans<<' ';
	}
	{
		vector<ll> I(mx);
		for(auto[a,b]:P) I[a]++,I[b]--;
		for(int i=0; i<mx-1; i++) I[i+1]+=I[i];
		ll ans=0;
		for(ll i:I) ans=max(ans,i);
		cout<<ans<<endl;
	}
}
accuracy: 1
time_ms: 60
memory_kb: 7828
final_rank: 7

code_snippet: #include <bits/stdc++.h>
using namespace std;

constexpr int MX = 100000;
constexpr int INF = 1e9;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N), B(N), smA(MX + 1, 0), smB(MX + 1, 0);
    for(int i = 0; i < N; i++) {
        cin >> A[i] >> B[i]; 
        smA[A[i]]++;
        smB[B[i]]++;
    }

    int ans1 = 0, ans2 = 0;

    for(int i = 0; i < MX; i++) {
        smA[i + 1] += smA[i];
        smB[i + 1] += smB[i];
        ans2 = max(ans2, smA[i] - smB[i]);
    }

    for(int i = 0; i < N; i++) {
        ans1 = max(ans1, smA[B[i] - 1] - smB[A[i]]);
    }

    cout << ans1 << " " << ans2 << "\n";

    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 5348
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define ALL(v) v.begin(),v.end()
#define dbg(x) cerr << #x << ": " << (x) << endl;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; ++i) cin >> a[i] >> b[i];
    for (int i = 0; i < n; ++i)
    {
        --a[i];
        --b[i];
    }
    int ans1, ans2;
    {
        vector<int> sum(1e5 + 1);
        for (int i = 0; i < n; ++i)
        {
            ++sum[a[i]];
            --sum[b[i]];
        }
        for (int i = 0; i < 1e5; ++i) sum[i + 1] += sum[i];
        ans2 = 0;
        for (int i = 0; i < 1e5; ++i) ans2 = max(ans2, sum[i]);
    }
    {
        vector<vector<int>> id(1e5);
        for (int i = 0; i < n; ++i) id[a[i]].push_back(b[i]);
        vector<int> sum(1e5 + 1), cnt(1e5);
        for (int i = 0; i < n; ++i) ++sum[a[i] + 1];
        for (int i = 0; i < n; ++i) ++cnt[b[i]];
        for (int i = 0; i < 1e5; ++i) sum[i + 1] += sum[i];
        ans1 = 0;
        int now = 0;
        for (int i = 0; i < 1e5; ++i)
        {
            now += id[i].size();
            now -= cnt[i];
            for (auto v : id[i])
            {
                int tmp = now + sum[v] - sum[i + 1];
                ans1 = max(ans1, tmp);
            }
        }
    }
    cout << ans1 << ' ' << ans2 << endl;
}
accuracy: 1
time_ms: 70
memory_kb: 10372
final_rank: 12

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

/**
 * @brief template
 */

struct UnionFind{
    vector<int> par; int n;
    UnionFind(){}
    UnionFind(int _n):par(_n,-1),n(_n){}
    int root(int x){return par[x]<0?x:par[x]=root(par[x]);}
    bool same(int x,int y){return root(x)==root(y);}
    int size(int x){return -par[root(x)];}
    bool unite(int x,int y){
        x=root(x),y=root(y); if(x==y)return false;
        if(size(x)>size(y))swap(x,y);
        par[y]+=par[x]; par[x]=y; n--; return true;
    }
};

/**
 * @brief Union Find
 */

int MAXS = 100001;

int Solve1(int N, vector<pair<int,int>> A) {
    vector<int> L(MAXS+1,0), R(MAXS+1,0);
    rep(i,0,N) L[A[i].first]++, R[A[i].second]++;
    rrep(i,0,MAXS) L[i] += L[i+1];
    rep(i,0,MAXS) R[i+1] += R[i];
    int Ret = 0;
    rep(i,0,N) chmax(Ret,N-R[A[i].first]-L[A[i].second]);
    return Ret;
}

int Solve2(int N, vector<pair<int,int>> A) {
    vector<int> Imos(MAXS+1,0);
    rep(i,0,N) Imos[A[i].first]++, Imos[A[i].second]--;
    rep(i,0,MAXS) Imos[i+1] += Imos[i];
    int Ret = 0;
    rep(i,0,MAXS+1) chmax(Ret,Imos[i]);
    return Ret;
}

int main() {
    int N;
    cin >> N;
    vector<pair<int,int>> A(N);
    rep(i,0,N) cin >> A[i].first >> A[i].second;
    cout << Solve1(N,A) << ' ' << Solve2(N,A) << endl;
}
accuracy: 1
time_ms: 60
memory_kb: 8144
final_rank: 10

code_snippet: #line 2 "cp-library/src/cp-template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull  = unsigned long long;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128_t;
template < class T > bool chmin(T& a, T b) { if(a > b) { a = b; return true; } return false; }
template < class T > bool chmax(T& a, T b) { if(a < b) { a = b; return true; } return false; }
template < class T, class U > T ceil (T x, U y) { return (x > 0 ? (x + y - 1) / y :           x / y); }
template < class T, class U > T floor(T x, U y) { return (x > 0 ?           x / y : (x - y + 1) / y); }
int popcnt(i32 x) { return __builtin_popcount(x); }
int popcnt(u32 x) { return __builtin_popcount(x); }
int popcnt(i64 x) { return __builtin_popcountll(x); }
int popcnt(u64 x) { return __builtin_popcountll(x); }

#line 2 "cp-library/src/utility/rep_itr.hpp"
template < class T > struct itr_rep {
    T i, d;
    constexpr itr_rep(const T i) noexcept : i(i), d(1) {}
    constexpr itr_rep(const T i, const T d) noexcept : i(i), d(d) {}
    void operator++() noexcept { i += d; }
    constexpr int operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr_rep x) const noexcept { return d > 0 ? i < x.i : i > x.i; }
};

template < class T > struct rep {
    const itr_rep< T > s, t;
    constexpr rep(const T t) noexcept : s(0), t(t) {}
    constexpr rep(const T s, const T t) noexcept : s(s), t(t) {}
    constexpr rep(const T s, const T t, const T d) noexcept : s(s, d), t(t, d) {}
    constexpr auto begin() const noexcept { return s; }
    constexpr auto end  () const noexcept { return t; }
};

template < class T > struct revrep {
    const itr_rep < T > s, t;
    constexpr revrep(const T t) noexcept : s(t - 1, -1), t(-1, -1) {}
    constexpr revrep(const T s, const T t) noexcept : s(t - 1, -1), t(s - 1, -1) {}
    constexpr revrep(const T s, const T t, const T d) noexcept : s(t - 1, -d), t(s - 1, -d) {}
    constexpr auto begin() const noexcept { return s; }
    constexpr auto end  () const noexcept { return t; }
};
#line 3 "cp-library/src/utility/io.hpp"

/* 128bit integer */
istream& operator>>(istream& is, i128& x) {
    std::string s; is >> s;
    int pm = (s[0] == '-');
    x = 0;
    for(int i : rep(pm, int(s.size()))) x = x * 10 + (s[i] - '0');
    if(pm) x *= -1;
    return is;
}
ostream& operator<<(ostream& os, const i128& x) {
    if(x == 0) return os << '0';
    i128 y = x;
    if(y < 0) { os << '-'; y *= -1; }
    std::vector<int> ny;
    while(y > 0) { ny.push_back(y % 10); y /= 10; }
    for(int i : revrep(ny.size())) os << ny[i];
    return os;
}

template < class S, class T > istream& operator>>(istream& is,       std::pair< S, T >& x) { is >> x.first        >> x.second; return is; }
template < class S, class T > ostream& operator<<(ostream& os, const std::pair< S, T >& x) { os << x.first << " " << x.second; return os; }

namespace scanner {
    struct sca {
        template < class T > operator T() {
            T s; std::cin >> s; return s;
        }
    };
    struct vec {
        int n;
        vec(int n) : n(n) {}
        template < class T > operator std::vector< T >() {
            std::vector< T > v(n);
            for(T& x : v) std::cin >> x;
            return v;
        }
    };
    struct mat {
        int h, w;
        mat(int h, int w) : h(h), w(w) {}
        template < class T > operator std::vector< std::vector< T > >() {
            std::vector m(h, std::vector< T >(w));
            for(std::vector< T >& v : m) for(T& x : v) std::cin >> x;
            return m;
        }
    };
    struct speedup {
        speedup() {
            std::cin.tie(0);
            std::ios::sync_with_stdio(0);
        }
    } speedup_instance;
}
scanner::sca in() { return scanner::sca(); }
scanner::vec in(int n) { return scanner::vec(n); }
scanner::mat in(int h, int w) { return scanner::mat(h, w); }

namespace printer {
    void precision(int d) { std::cout << std::fixed << std::setprecision(d); }
    void flush() { std::cout.flush(); }
}

template < class T >
ostream& operator<<(ostream& os, const std::vector< T > a) {
    int n = a.size();
    for(int i : rep(n)) { os << a[i]; if(i != n - 1) os << ' '; }
    return os;
}

int print() { std::cout << '\n'; return 0; }
template < class head, class... tail > int print(head&& h, tail&&... t) {
    std::cout << h; if(sizeof...(tail)) std::cout << ' ';
    return print(std::forward<tail>(t)...);
}
template < class T > int print_n(const std::vector< T > a) {
    int n = a.size();
    for(int i : rep(n)) std::cout << a[i] << "\n";
    return 0;
}


#line 2 "cp-library/src/utility/key_val.hpp"

template < class K, class V >
struct key_val {
    K key; V val;
    key_val() {}
    key_val(K key, V val) : key(key), val(val) {}
    template < std::size_t Index >
    std::tuple_element_t< Index, key_val >& get() {
        if constexpr (Index == 0) return key;
        if constexpr (Index == 1) return val;
    }
};

namespace std {

template < class K, class V > struct tuple_size < key_val< K, V > > : integral_constant< size_t, 2 > {};
template < class K, class V > struct tuple_element < 0, key_val< K, V > > { using type = K; };
template < class K, class V > struct tuple_element < 1, key_val< K, V > > { using type = V; };

}
#line 2 "cp-library/src/utility/vec_op.hpp"
template < class T > key_val< int, T > max_of(const vector< T >& a) {
    int i = std::max_element(a.begin(), a.end()) - a.begin();
    return {i, a[i]};
}
template < class T > key_val< int, T > min_of(const vector< T >& a) {
    int i = std::min_element(a.begin(), a.end()) - a.begin();
    return {i, a[i]};
}
template < class S, class T > S sum_of(const vector< T >& a) {
    S sum = 0;
    for(const T x : a) sum += x;
    return sum;
}
template < class S, class T > vector< S > freq_of(const vector< T >& a, T L, T R) {
    vector< S > res(R - L, S(0));
    for(const T x : a) res[x - L] += 1;
    return res;
}
template < class S, class T > struct prefix_sum {
    vector< S > s;
    prefix_sum(const vector< T >& a) : s(a) {
        s.insert(s.begin(), S(0));
        for(int i : rep(a.size())) s[i + 1] += s[i];
    }
    // [L, R)
    S sum(int L, int R) { return s[R] - s[L]; }
};
#line 3 "cp-library/src/utility/heap.hpp"

template < class T > using heap_min = std::priority_queue< T, std::vector< T >, std::greater< T > >;
template < class T > using heap_max = std::priority_queue< T, std::vector< T >, std::less< T > >;

#line 27 "cp-library/src/cp-template.hpp"

#line 1 "cp-library/src/algorithm/bin_search.hpp"
template < class T, class F >
T bin_search(T ok, T ng, F f) {
    while(abs(ng - ok) > 1) {
        T mid = (ok + ng) / 2;
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}

template < class T, class F >
T bin_search_real(T ok, T ng, F f, int step = 80) {
    while(step--) {
        T mid = (ok + ng) / 2;
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}
#line 2 "cp-library/src/algorithm/argsort.hpp"

template < class T > std::vector< int > argsort(const std::vector< T > &a) {
    std::vector< int > ids((int)a.size());
    std::iota(ids.begin(), ids.end(), 0);
    std::sort(ids.begin(), ids.end(), [&](int i, int j) {
        return a[i] < a[j] || (a[i] == a[j] && i < j);
    });
    return ids;
}
#line 1 "macro.hpp"
namespace macro {

using size_type = int;
template < class container > void  sort(container& a) { std::sort(std:: begin(a), std:: end(a)); }
template < class container > void rsort(container& a) { std::sort(std::rbegin(a), std::rend(a)); }
template < class container > void reverse(container& a) { std::reverse(std::begin(a), std::end(a)); }
template < class container > void unique(container& a) {
    std::sort(std::begin(a), std::end(a));
    a.erase(std::unique(std::begin(a), std::end(a)), std::end(a));
}
template < class container > container  sorted(const container& a) { container b = a;  sort(b); return std::move(b); }
template < class container > container rsorted(const container& a) { container b = a; rsort(b); return std::move(b); }
template < class container, class compare > void sort(container& a, const compare& cmp) { std::sort(std::begin(a), std::end(a), cmp); }
template < class container, class compare > container sorted(const container& a, const compare& cmp) { container b = a; sort(b, cmp); return std::move(b); }
template < class container, class value > size_type lower_bound(const container& a, const value& x) { return std::lower_bound(std::begin(a), std::end(a), x) - std::begin(a); }
template < class container, class value > size_type upper_bound(const container& a, const value& x) { return std::upper_bound(std::begin(a), std::end(a), x) - std::begin(a); }

const std::vector<std::pair<size_type, size_type>> dir4 = { {+1,  0}, {-1,  0}, { 0, +1}, { 0, -1} };
const std::vector<std::pair<size_type, size_type>> dir8 = { {-1, -1}, {-1,  0}, {-1, +1}, { 0, -1}, { 0, +1}, {+1, -1}, {+1,  0}, {+1, +1} };

#ifdef _DEBUG
#define debug(x) std::cout << "[" << __LINE__ << "] " << #x << ": " << x << std::endl
#else
#define debug(x)
#endif

template < class container > void concat(container& a, const container& b) {
    a.insert(std::end(a), std::begin(b), std::end(b));
}
std::vector<size_type> iota(const size_type n) {
    std::vector<size_type> I(n);
    std::iota(std::begin(I), std::end(I), 0);
    return I;
}
template < class container > std::vector<size_type> sort_idx(const container& a) {
    const size_type n = a.size();
    std::vector<size_type> I = iota(n);
    std::sort(std::begin(I), std::end(I), [&](size_type i, size_type j) { return a[i] < a[j] or (a[i] == a[j] and i < j); });
    return I;
}
template < class container, class compare > std::vector<size_type> sort_idx(const container& a, const compare& cmp) {
    const size_type n = a.size();
    std::vector<size_type> I = iota(n);
    std::sort(std::begin(I), std::end(I), [&](size_type i, size_type j) { return cmp(a[i], a[j]) or (a[i] == a[j] and i < j); });
    return std::move(I);
}

struct grid {
    using size_type = int;
    size_type H, W;
    grid(const size_type H, const size_type W) : H(H), W(W) {}
    bool contains(const size_type i, const size_type j) {
        return 0 <= i and i < H and 0 <= j and j < W;
    }
};

using f64 = long double;

} // namespace macro

using namespace macro;
#line 3 "A.cpp"

int main() {
    int n = in();
    vector<int> L(n), R(n);
    for(int i : rep(n)) L[i] = in(), R[i] = in();

    const int m = 100'100;
    int p1 = [&] {
        vector<int> prefix(m, 0), suffix(m, 0);
        for(int i : rep(n)) suffix[L[i]]++, prefix[R[i]]++;
        for(int i : rep(m - 1)) prefix[i + 1] += prefix[i];
        for(int i : revrep(m - 1)) suffix[i] += suffix[i + 1];
        int ans = 0;
        for(int i : rep(n)) chmax(ans, n - prefix[L[i]] - suffix[R[i]]);
        return ans;
    }();

    int p2 = [&] {
        vector<int> s(m, 0);
        for(int i : rep(n)) s[L[i]]++, s[R[i]]--;
        for(int i : rep(m - 1)) s[i + 1] += s[i];
        return max_of(s).val;
    }();

    print(p1, p2);
}
accuracy: 1
time_ms: 20
memory_kb: 5452
final_rank: 3

code_snippet: #line 2 "cp-library/src/cp-template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull  = unsigned long long;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128_t;
template < class T > bool chmin(T& a, T b) { if(a > b) { a = b; return true; } return false; }
template < class T > bool chmax(T& a, T b) { if(a < b) { a = b; return true; } return false; }
template < class T, class U > T ceil (T x, U y) { return (x > 0 ? (x + y - 1) / y :           x / y); }
template < class T, class U > T floor(T x, U y) { return (x > 0 ?           x / y : (x - y + 1) / y); }
int popcnt(i32 x) { return __builtin_popcount(x); }
int popcnt(u32 x) { return __builtin_popcount(x); }
int popcnt(i64 x) { return __builtin_popcountll(x); }
int popcnt(u64 x) { return __builtin_popcountll(x); }

#line 2 "cp-library/src/utility/rep_itr.hpp"
template < class T > struct itr_rep {
    T i, d;
    constexpr itr_rep(const T i) noexcept : i(i), d(1) {}
    constexpr itr_rep(const T i, const T d) noexcept : i(i), d(d) {}
    void operator++() noexcept { i += d; }
    constexpr int operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr_rep x) const noexcept { return d > 0 ? i < x.i : i > x.i; }
};

template < class T > struct rep {
    const itr_rep< T > s, t;
    constexpr rep(const T t) noexcept : s(0), t(t) {}
    constexpr rep(const T s, const T t) noexcept : s(s), t(t) {}
    constexpr rep(const T s, const T t, const T d) noexcept : s(s, d), t(t, d) {}
    constexpr auto begin() const noexcept { return s; }
    constexpr auto end  () const noexcept { return t; }
};

template < class T > struct revrep {
    const itr_rep < T > s, t;
    constexpr revrep(const T t) noexcept : s(t - 1, -1), t(-1, -1) {}
    constexpr revrep(const T s, const T t) noexcept : s(t - 1, -1), t(s - 1, -1) {}
    constexpr revrep(const T s, const T t, const T d) noexcept : s(t - 1, -d), t(s - 1, -d) {}
    constexpr auto begin() const noexcept { return s; }
    constexpr auto end  () const noexcept { return t; }
};
#line 3 "cp-library/src/utility/io.hpp"

/* 128bit integer */
istream& operator>>(istream& is, i128& x) {
    std::string s; is >> s;
    int pm = (s[0] == '-');
    x = 0;
    for(int i : rep(pm, int(s.size()))) x = x * 10 + (s[i] - '0');
    if(pm) x *= -1;
    return is;
}
ostream& operator<<(ostream& os, const i128& x) {
    if(x == 0) return os << '0';
    i128 y = x;
    if(y < 0) { os << '-'; y *= -1; }
    std::vector<int> ny;
    while(y > 0) { ny.push_back(y % 10); y /= 10; }
    for(int i : revrep(ny.size())) os << ny[i];
    return os;
}

template < class S, class T > istream& operator>>(istream& is,       std::pair< S, T >& x) { is >> x.first        >> x.second; return is; }
template < class S, class T > ostream& operator<<(ostream& os, const std::pair< S, T >& x) { os << x.first << " " << x.second; return os; }

namespace scanner {
    struct sca {
        template < class T > operator T() {
            T s; std::cin >> s; return s;
        }
    };
    struct vec {
        int n;
        vec(int n) : n(n) {}
        template < class T > operator std::vector< T >() {
            std::vector< T > v(n);
            for(T& x : v) std::cin >> x;
            return v;
        }
    };
    struct mat {
        int h, w;
        mat(int h, int w) : h(h), w(w) {}
        template < class T > operator std::vector< std::vector< T > >() {
            std::vector m(h, std::vector< T >(w));
            for(std::vector< T >& v : m) for(T& x : v) std::cin >> x;
            return m;
        }
    };
    struct speedup {
        speedup() {
            std::cin.tie(0);
            std::ios::sync_with_stdio(0);
        }
    } speedup_instance;
}
scanner::sca in() { return scanner::sca(); }
scanner::vec in(int n) { return scanner::vec(n); }
scanner::mat in(int h, int w) { return scanner::mat(h, w); }

namespace printer {
    void precision(int d) { std::cout << std::fixed << std::setprecision(d); }
    void flush() { std::cout.flush(); }
}

template < class T >
ostream& operator<<(ostream& os, const std::vector< T > a) {
    int n = a.size();
    for(int i : rep(n)) { os << a[i]; if(i != n - 1) os << ' '; }
    return os;
}

int print() { std::cout << '\n'; return 0; }
template < class head, class... tail > int print(head&& h, tail&&... t) {
    std::cout << h; if(sizeof...(tail)) std::cout << ' ';
    return print(std::forward<tail>(t)...);
}
template < class T > int print_n(const std::vector< T > a) {
    int n = a.size();
    for(int i : rep(n)) std::cout << a[i] << "\n";
    return 0;
}


#line 2 "cp-library/src/utility/key_val.hpp"

template < class K, class V >
struct key_val {
    K key; V val;
    key_val() {}
    key_val(K key, V val) : key(key), val(val) {}
    template < std::size_t Index >
    std::tuple_element_t< Index, key_val >& get() {
        if constexpr (Index == 0) return key;
        if constexpr (Index == 1) return val;
    }
};

namespace std {

template < class K, class V > struct tuple_size < key_val< K, V > > : integral_constant< size_t, 2 > {};
template < class K, class V > struct tuple_element < 0, key_val< K, V > > { using type = K; };
template < class K, class V > struct tuple_element < 1, key_val< K, V > > { using type = V; };

}
#line 2 "cp-library/src/utility/vec_op.hpp"
template < class T > key_val< int, T > max_of(const vector< T >& a) {
    int i = std::max_element(a.begin(), a.end()) - a.begin();
    return {i, a[i]};
}
template < class T > key_val< int, T > min_of(const vector< T >& a) {
    int i = std::min_element(a.begin(), a.end()) - a.begin();
    return {i, a[i]};
}
template < class S, class T > S sum_of(const vector< T >& a) {
    S sum = 0;
    for(const T x : a) sum += x;
    return sum;
}
template < class S, class T > vector< S > freq_of(const vector< T >& a, T L, T R) {
    vector< S > res(R - L, S(0));
    for(const T x : a) res[x - L] += 1;
    return res;
}
template < class S, class T > struct prefix_sum {
    vector< S > s;
    prefix_sum(const vector< T >& a) : s(a) {
        s.insert(s.begin(), S(0));
        for(int i : rep(a.size())) s[i + 1] += s[i];
    }
    // [L, R)
    S sum(int L, int R) { return s[R] - s[L]; }
};
#line 3 "cp-library/src/utility/heap.hpp"

template < class T > using heap_min = std::priority_queue< T, std::vector< T >, std::greater< T > >;
template < class T > using heap_max = std::priority_queue< T, std::vector< T >, std::less< T > >;

#line 27 "cp-library/src/cp-template.hpp"

#line 1 "cp-library/src/algorithm/bin_search.hpp"
template < class T, class F >
T bin_search(T ok, T ng, F f) {
    while(abs(ng - ok) > 1) {
        T mid = (ok + ng) / 2;
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}

template < class T, class F >
T bin_search_real(T ok, T ng, F f, int step = 80) {
    while(step--) {
        T mid = (ok + ng) / 2;
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}
#line 2 "cp-library/src/algorithm/argsort.hpp"

template < class T > std::vector< int > argsort(const std::vector< T > &a) {
    std::vector< int > ids((int)a.size());
    std::iota(ids.begin(), ids.end(), 0);
    std::sort(ids.begin(), ids.end(), [&](int i, int j) {
        return a[i] < a[j] || (a[i] == a[j] && i < j);
    });
    return ids;
}
#line 1 "macro.hpp"
namespace macro {

using size_type = int;
template < class container > void  sort(container& a) { std::sort(std:: begin(a), std:: end(a)); }
template < class container > void rsort(container& a) { std::sort(std::rbegin(a), std::rend(a)); }
template < class container > void reverse(container& a) { std::reverse(std::begin(a), std::end(a)); }
template < class container > void unique(container& a) {
    std::sort(std::begin(a), std::end(a));
    a.erase(std::unique(std::begin(a), std::end(a)), std::end(a));
}
template < class container > container  sorted(const container& a) { container b = a;  sort(b); return std::move(b); }
template < class container > container rsorted(const container& a) { container b = a; rsort(b); return std::move(b); }
template < class container, class compare > void sort(container& a, const compare& cmp) { std::sort(std::begin(a), std::end(a), cmp); }
template < class container, class compare > container sorted(const container& a, const compare& cmp) { container b = a; sort(b, cmp); return std::move(b); }
template < class container, class value > size_type lower_bound(const container& a, const value& x) { return std::lower_bound(std::begin(a), std::end(a), x) - std::begin(a); }
template < class container, class value > size_type upper_bound(const container& a, const value& x) { return std::upper_bound(std::begin(a), std::end(a), x) - std::begin(a); }

const std::vector<std::pair<size_type, size_type>> dir4 = { {+1,  0}, {-1,  0}, { 0, +1}, { 0, -1} };
const std::vector<std::pair<size_type, size_type>> dir8 = { {-1, -1}, {-1,  0}, {-1, +1}, { 0, -1}, { 0, +1}, {+1, -1}, {+1,  0}, {+1, +1} };

#ifdef _DEBUG
#define debug(x) std::cout << "[" << __LINE__ << "] " << #x << ": " << x << std::endl
#else
#define debug(x)
#endif

template < class container > void concat(container& a, const container& b) {
    a.insert(std::end(a), std::begin(b), std::end(b));
}
std::vector<size_type> iota(const size_type n) {
    std::vector<size_type> I(n);
    std::iota(std::begin(I), std::end(I), 0);
    return I;
}
template < class container > std::vector<size_type> sort_idx(const container& a) {
    const size_type n = a.size();
    std::vector<size_type> I = iota(n);
    std::sort(std::begin(I), std::end(I), [&](size_type i, size_type j) { return a[i] < a[j] or (a[i] == a[j] and i < j); });
    return I;
}
template < class container, class compare > std::vector<size_type> sort_idx(const container& a, const compare& cmp) {
    const size_type n = a.size();
    std::vector<size_type> I = iota(n);
    std::sort(std::begin(I), std::end(I), [&](size_type i, size_type j) { return cmp(a[i], a[j]) or (a[i] == a[j] and i < j); });
    return std::move(I);
}

struct grid {
    using size_type = int;
    size_type H, W;
    grid(const size_type H, const size_type W) : H(H), W(W) {}
    bool contains(const size_type i, const size_type j) {
        return 0 <= i and i < H and 0 <= j and j < W;
    }
};

using f64 = long double;

} // namespace macro

using namespace macro;
#line 3 "A.cpp"

int main() {
    int n = in();
    vector<int> L(n), R(n);
    for(int i : rep(n)) L[i] = in(), R[i] = in();

    const int m = 100'100;
    int p1 = [&] {
        vector<int> prefix(m, 0), suffix(m, 0);
        for(int i : rep(n)) suffix[L[i]]++, prefix[R[i]]++;
        for(int i : rep(m - 1)) prefix[i + 1] += prefix[i];
        for(int i : revrep(m - 1)) suffix[i] += suffix[i + 1];
        int ans = 0;
        for(int i : rep(n)) chmax(ans, n - prefix[L[i]] - suffix[R[i]]);
        return ans;
    }();

    int p2 = [&] {
        const int m = 100'100;
        vector<int> s(m, 0);
        for(int i : rep(n)) s[L[i]]++, s[R[i]]--;
        for(int i : rep(m - 1)) s[i + 1] += s[i];
        return max_of(s).val;
    }();

    print(p1, p2);
}
accuracy: 1
time_ms: 10
memory_kb: 5460
final_rank: 1

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
using ll=long long;
#define all(p) p.begin(),p.end()
int main(){
    int N;
    cin>>N;
    vector<pair<int,int>> p(N);
    rep(i,0,N) cin>>p[i].first>>p[i].second;
    sort(all(p));
    int L=100100;
    vector<int> A(L);
    rep(i,0,N) A[p[i].first]++,A[p[i].second]--;
    int ans1=0;
    rep(i,0,L-1) ans1=max(ans1,A[i]),A[i+1]+=A[i];
    vector<int> ans(N);
    rep(rprp,0,2){
        rep(i,0,L) A[i]=0;
        rep(i,0,N) A[p[i].second]++;
        rep(i,0,L-1) A[i+1]+=A[i];
        rep(i,0,N) ans[i]+=A[p[i].first];
        rep(i,0,N){
            p[i].first=L-p[i].first;
            p[i].second=L-p[i].second;
            swap(p[i].first,p[i].second);
        }
    }
    int ans2=0;
    rep(i,0,N) ans2=max(ans2,N-ans[i]);
    cout<<ans2<<" "<<ans1<<"\n";
}
accuracy: 1
time_ms: 70
memory_kb: 5720
final_rank: 6