WA 0pts求调
#include <iostream>
#include<algorithm>
using namespace std;
int n;
struct node{
int L,R;
bool operator<(node const other)const{
if(R!=other.R) return R<other.R;
else return L<other.L;
}
}a[50240];
int main(){
cin>>n;
for(int i=0;i<n;i++) {
cin >> a[i].L >> a[i].R;
}
sort(a,a+n);
for(int i=0;i<n;i++)
{
if(a[i-1].R<a[i].L or i==0)
{
cout<<a[i].L<<" ";
}
if(a[i+1].L>a[i].R or i==n-1)
{
cout<<a[i].R<<endl;
}
}
return 0;
}