stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<cstdio>

#include<algorithm>

#include<vector>

#include<string>

#include<set>

using namespace std;



#define INF ( 1 << 30 )

typedef multiset<int,int>::iterator itr;



int main()

{

  int N, Q;

  int stmp[1000000], comp[1000000], a;

  char buff[1024];

  scanf( "%d %d", &N, &Q);

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

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

    comp[i] = stmp[i];

  }

  sort( comp, comp + N);



  multiset< int > sym;

  while(Q--){

    scanf("%s %d", buff, &a);

    if(*buff == 'A'){ //ADD



      sym.insert(stmp[a - 1]);



    } else if(*buff == 'R'){ //REMOVE

      try{

        sym.erase( sym.lower_bound(stmp[a - 1]));

      }catch( ... ){}

    } else { //CHECK



      int left = 0, right = INF;

      while(left != right){

        int center = ( left + right ) / 2;

        int pre = 0, BAN = 0;

        for(itr it = sym.begin() ; it != sym.end() ; it++ ){

          int p = distance( comp,lower_bound( comp, comp + N, *it - center));

          BAN += max( p - pre, 0);

          pre = distance( comp, upper_bound( comp, comp + N, *it));

        }

        BAN += max( N - pre, 0);

        if(BAN <= a) right = center;

        else left = center + 1;

      }

      if( left != INF) printf("%d\n", left);

      else puts("NA");



    }

  }

  return false;

}

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

using namespace std;



int N, Q, s[1000000];

vector< int > Student;

multiset< int > Leader;



char Query[10];

int a;



bool Check(int value, int x)

{

  vector< int >::iterator last = Student.begin();

  int Lost = 0;

  for(multiset< int >::iterator it = Leader.begin(); it != Leader.end() && last != Student.end(); ++it) {

    Lost += lower_bound(last, Student.end(), *it - value) - last;

    last = upper_bound(last, Student.end(), *it);

  }

  Lost += Student.end() - last;

  return(Lost <= x);

}

int BinarySearch(int Lower, int Upper, int x)

{

  int Mid = (Lower + Upper) >> 1;

  if(Lower >= Upper) return(Lower);

  if(Check(Mid, x)) return(BinarySearch(Lower, Mid, x));

  return(BinarySearch(Mid + 1, Upper, x));

}

main()

{

  scanf("%d %d", &N, &Q);

  Student.resize(N);

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

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

    s[i] = Student[i];

  }

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

  while(Q--) {

    scanf("%s %d", &Query, &a);

    if(Query[0] == 'A') { // "ADD"

      Leader.insert(s[--a]);

    } else if(Query[0] == 'R') { // "REMOVE"

      Leader.erase(Leader.find(s[--a]));

    } else { // "CHECK"

      int ret = BinarySearch(0, 1 << 30, a);

      if(ret == 1 << 30) cout << "NA" << endl;

      else cout << ret << endl;

    }

  }

}
// Slower C++ solution:
#include<cstdio>

#include<algorithm>

#include<vector>

#include<string>

#include<set>

using namespace std;



#define INF ( 1 << 30 )

typedef multiset<int,int>::iterator itr;



int main()

{

  int N, Q;

  int stmp[1000000], comp[1000000], a;

  char buff[1024];

  scanf( "%d %d", &N, &Q);

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

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

    comp[i] = stmp[i];

  }

  sort( comp, comp + N);



  multiset< int > sym;

  while(Q--){

    scanf("%s %d", buff, &a);

    if(*buff == 'A'){ //ADD



      sym.insert(stmp[a - 1]);



    } else if(*buff == 'R'){ //REMOVE

      try{

        sym.erase( sym.lower_bound(stmp[a - 1]));

      }catch( ... ){}

    } else { //CHECK



      int left = 0, right = INF;

      while(left != right){

        int center = ( left + right ) / 2;

        int pre = 0, BAN = 0;

        for(itr it = sym.begin() ; it != sym.end() ; it++ ){

          int p = distance( comp,lower_bound( comp, comp + N, *it - center));

          BAN += max( p - pre, 0);

          pre = distance( comp, upper_bound( comp, comp + N, *it));

        }

        BAN += max( N - pre, 0);

        if(BAN <= a) right = center;

        else left = center + 1;

      }

      if( left != INF) printf("%d\n", left);

      else puts("NA");



    }

  }

  return false;

}

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

using namespace std;



int N, Q, s[1000000];

vector< int > Student;

multiset< int > Leader;



char Query[10];

int a;



main()

{

  scanf("%d %d", &N, &Q);

  Student.resize(N);

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

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

    s[i] = Student[i];

  }

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

  while(Q--) {

    scanf("%s %d", Query, &a);

    if(Query[0] == 'A') { // "ADD"

      Leader.insert(s[--a]);

    } else if(Query[0] == 'R') { // "REMOVE"

      Leader.erase(Leader.find(s[--a]));

    } else { // "CHECK"

      int Lower = 0, Upper = 1 << 30;

      while(Lower < Upper) {

        int Mid = Lower + Upper >> 1, Lost = 0;

        vector< int >::iterator last = Student.begin();

        for(multiset< int >::iterator it = Leader.begin(); it != Leader.end() && last != Student.end(); ++it) {

          Lost += lower_bound(last, Student.end(), *it - Mid) - last;

          last = upper_bound(last, Student.end(), *it);

        }

        Lost += Student.end() - last;

        if(Lost <= a) Upper = Mid;

        else Lower = Mid + 1;

      }

      if(Lower == 1 << 30) cout << "NA" << endl;

      else cout << Lower << endl;

    }

  }

}
// Slower C++ solution:
#include<cstdio>

#include<algorithm>

#include<vector>

#include<string>

#include<set>

using namespace std;



#define INF ( 1 << 30 )

typedef multiset<int,int>::iterator itr;



int main()

{

  int N, Q;

  int stmp[1000000], comp[1000000], a;

  char buff[1024];

  scanf( "%d %d", &N, &Q);

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

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

    comp[i] = stmp[i];

  }

  sort( comp, comp + N);



  multiset< int > sym;

  while(Q--){

    scanf("%s %d", buff, &a);

    if(*buff == 'A'){ //ADD



      sym.insert(stmp[a - 1]);



    } else if(*buff == 'R'){ //REMOVE

      try{

        sym.erase( sym.lower_bound(stmp[a - 1]));

      }catch( ... ){}

    } else { //CHECK



      int left = 0, right = INF;

      while(left != right){

        int center = ( left + right ) / 2;

        int pre = 0, BAN = 0;

        for(itr it = sym.begin() ; it != sym.end() ; it++ ){

          int p = distance( comp,lower_bound( comp, comp + N, *it - center));

          BAN += max( p - pre, 0);

          pre = distance( comp, upper_bound( comp, comp + N, *it));

        }

        BAN += max( N - pre, 0);

        if(BAN <= a) right = center;

        else left = center + 1;

      }

      if( left != INF) printf("%d\n", left);

      else puts("NA");



    }

  }

  return false;

}

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

using namespace std;

 

int N, Q, s[1000000];

vector< int > Student;

multiset< int > Leader;

 

char Query[10];

int a;

 

bool Check(int value, int x)

{

  vector< int >::iterator last = Student.begin();

  int Lost = 0;

  for(multiset< int >::iterator it = Leader.begin(); it != Leader.end() && last != Student.end(); ++it) {

    Lost += lower_bound(last, Student.end(), *it - value) - last;

    last = upper_bound(last, Student.end(), *it);

  }

  Lost += Student.end() - last;

  return(Lost <= x);

}

int BinarySearch(int Lower, int Upper, int x)

{

  int Mid = (Lower + Upper) >> 1;

  if(Lower >= Upper) return(Lower);

  if(Check(Mid, x)) return(BinarySearch(Lower, Mid, x));

  return(BinarySearch(Mid + 1, Upper, x));

}

main()

{

  scanf("%d %d", &N, &Q);

  Student.resize(N);

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

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

    s[i] = Student[i];

  }

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

  while(Q--) {

    scanf("%s %d", &Query, &a);

    if(Query[0] == 'A') { // "ADD"

      Leader.insert(s[--a]);

    } else if(Query[0] == 'R') { // "REMOVE"

      Leader.erase(Leader.find(s[--a]));

    } else { // "CHECK"

      int ret = BinarySearch(0, 1 << 30, a);

      if(ret == 1 << 30) puts("NA");

      else printf("%d\n", ret);

    }

  }

}
// Slower C++ solution:
#include<iostream>

#include<algorithm>

using namespace std;



typedef long long ll;



int main(){

  ll i,n,num,len,p,l[100000];

  while(cin >> n,n){

    num = n; len = 0;

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

      cin >> p; len += p;

    }



    for(i=0;i<n-1;i++)cin >> l[i];

    sort(l,l+n-1);



    for(i=n-2;i>=0;i--){

      if( (num-1)*(len+l[i]) < num*len )break;

      num--; len += l[i];

    }

    cout << num*len << endl;

  }

}

   

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

#include<algorithm>

using namespace std;



int main(){

  int n,p,l[100000];

  while(scanf("%d",&n),n){

    long long num = n,len = 0;

    for(int i=0;i<n;i++){ scanf("%d",&p); len += p;}



    for(int i=0;i<n-1;i++)scanf("%d",&l[i]);

    sort(l,l+n-1);

    

    for(int i=n-2;i>=0;i--){

      if( (num-1)*(len+l[i]) < num*len )break;

      num--; len += l[i];

    }

    printf("%lld\n",num*len);

  }

}
// Slower C++ solution:
#include<iostream>

#include<string>

#include<algorithm>

#include<map>

#include<set>

#include<utility>

#include<vector>

#include<cmath>

#include<cstdio>

#define loop(i,a,b) for(int i=a;i<b;i++) 

#define rep(i,a) loop(i,0,a)

#define pb push_back

#define mp make_pair

#define it ::iterator

#define all(in) in.begin(),in.end()

const double PI=acos(-1);

const double ESP=1e-10;

using namespace std;

int main(){

  int n;

  cin>>n;

  rep(i,n){

    string s;

    string ans;

    bool han=false;

    if(i==0)getline(cin,s);

    getline(cin,s);

    rep(a,27){

      rep(b,27){

	string tmp=s;

	rep(j,tmp.size())if(isalpha(tmp[j]))tmp[j]=(a*(tmp[j]-'a')+b)%26+'a';

	rep(j,tmp.size()-3){

	  if(tmp.substr(j,4)=="this"){ans=tmp;han=true;}

	  if(tmp.substr(j,4)=="that"){ans=tmp;han=true;}

	}

	if(han==true)break;

      }

      if(han==true)break;

    }

    cout<<ans<<endl;

  }





}

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

#include<string>

#include<algorithm>

#include<map>

#include<set>

#include<utility>

#include<vector>

#include<cmath>

#include<cstring>

#include<cstdio>

#include<time.h>

#define loop(i,a,b) for(int i=a;i<b;i++) 

#define rep(i,a) loop(i,0,a)

#define pb push_back

#define mp make_pair

#define all(in) in.begin(),in.end()

const double PI=acos(-1);

const double EPS=1e-10;

const int inf=1e8;

using namespace std;

typedef long long ll;

typedef vector<int> vi;

typedef vector<vi> vvi;

int main(){

	int n;

	cin>>n;

	string s;

	getline(cin,s);

	while(n--){

		getline(cin,s);

		bool h=false;

		rep(i,26){

			string tmp;

			rep(j,26){

				tmp=s;

				rep(k,tmp.size())if(isalpha(tmp[k]))tmp[k]=(i*(tmp[k]-'a')+j)%26+'a';

				rep(k,tmp.size()-3){

					string a=tmp.substr(k,4);

					if(a=="this"||a=="that"){h=true;break;}

				}

				if(h)break;

			}

			if(h){s=tmp;break;}

		}

		cout<<s<<endl;;

	}

}
// Slower C++ solution:
#include <iostream>   

#include <map>   

#include <sstream>   

#include <string.h>   

using namespace std;   

  

map<int, char> AlphabetTable;   

map<int, int> table;   

  

char decode(char a){   

       

    int z = a - 'a';   

       

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

        if(table[i] == z) return AlphabetTable[i];   

    }   

}   

  

void makeTable(int a, int b){   

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

        table[i] = (a*i+b) % 26;   

    }   

}   

  

void makeAlphabetTable(){   

  

    char c = 'a';   

  

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

        AlphabetTable[i] = c;   

        c++;   

    }   

}   

  

int main(){   

  

    string code, tmp;   

    int n;   

       

    getline (cin, code);   

    stringstream ssn(code);   

    ssn >> n;   

    makeAlphabetTable();   

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

        getline(cin, code );   

        tmp = code;   

        for(int b = 0; b < 26; b++){   

            for(int a = 1; a < 26; a+=2){   

                if(a%13 != 0){   

                    makeTable(a, b);   

                    code = tmp;   

                    for(int j = 0; j < code.length(); j++){   

                        if('a' <= code[j] && code[j] <= 'z'){   

                            code[j] = decode(code[j]);   

                        }   

                    }   

                    if(code.find("this") != -1 || code.find("that")!= -1){   

                        cout << code << endl;   

                        break;   

                    }   

                }   

            }   

        }   

    }   

       

    return 0;   

}  

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

#include <string>

#include <vector>



using namespace std;



void solve()

{

	int N;

	scanf("%d\n", &N);

	while(N--)

	{

		string s;

		getline(cin, s);

		string sbuf = s;

		sbuf += ' ';

		int n = sbuf.size();

		int start = 0;

		int end = 0;

		vector<string> Vec;

		string temp;

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

		{

			if(sbuf[i] == ' ')

			{

				if(end - start == 4)

				{

					Vec.push_back(temp);

				}

				start = end = i + 1;

				temp.clear();

				continue;

			}

			temp += sbuf[i];

			++end;

		}

		int a = 0;

		int b = 0;

		for(int i = 0; i < Vec.size(); ++i)

		{

			for(int j = 0; j < 4; ++j)

			{

				Vec[i][j] %= 26;

			}

		}

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

		{

			for(int j = 0; j < 27; ++j)

			{

				for(int k = 0; k < Vec.size(); ++k)

				{

					string check = "asdf";

					for(int l = 0; l < 4; ++l)

					{

						check[l] = (i * Vec[k][l] + j) % 26 + 'a';

					}

					if(check == "this" || check == "that")

					{

						a = i;

						b = j;

						goto END;

					}

				}

			}

		}

END:

		n = s.size();

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

		{

			if(s[i] == ' ')

			{

				cout << s[i];

				continue;

			}

			s[i] = (a * (s[i] % 26) + b) % 26 + 'a';

			cout << s[i];

		}

		cout << endl;

	}

}



int main()

{

	solve();

	return(0);

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

#include <iostream>

#include <cstdlib>

#include <cmath>

#include <cctype>

#include <string>

#include <cstring>

#include <algorithm>

#include <stack>

#include <queue>

#include <set>

#include <map>

#include <ctime>

#include <vector>

#include <fstream>

#include <list>

#include <iomanip>

#include <numeric>

using namespace std;

typedef long long ll;

typedef unsigned long long ull;

#define ms(s) memset(s, 0, sizeof(s))

const ll INF = 1e18;

inline ll read(){

	ll X = 0,w = 0 ;

	char ch = 0;

	while(!isdigit(ch)) {w |= ch == '-';ch = getchar();}

	while(isdigit(ch)) X = (X<<3) + (X<<1) + (ch ^ 48),ch = getchar();

	return w ? -X : X;

}

ll n;

ll a[100005];

ll b[100005];

vector<ll>v;

bool A[100005];

bool B[100005];

ll cnt0,cnt1;

multiset<ll> one,tmp;

multiset<ll> zero;

set<ll>final;

ll ans;

int main()

{

	cin>>n;

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

	{

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

		v.push_back(a[i]);

		v.push_back(b[i]);

	}

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

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

	{

		one.insert(v[i]);

	}

	for(ll i=n;i<2*n;i++)

	{

		zero.insert(v[i]);

	}

	tmp=one;

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

	{

		if(tmp.count(a[i]))

		{

			A[i]=1;

			tmp.erase(tmp.find(a[i]));

		}

		if(tmp.count(b[i]))

		{

			B[i]=1;

			tmp.erase(tmp.find(b[i]));

		}

		if(!A[i] and !B[i])

		{

			cnt0++;

		}

		if(A[i] and B[i])

		{

			cnt1++;

		}

	}

	for(multiset<ll>::iterator it=one.begin();it!=one.end();it++)

	{

		ans+=*it;

	}

	if(cnt0 or cnt1)

	{

		cout<<ans<<endl;

		return 0;

	}

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

	{

		final.insert(A[i]==1?1:0);

	}

	if(final.size()==1)

	{

		cout<<ans<<endl;

		return 0;

	}

	ll res=INF;

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

	{

		if(A[i])

		{

			multiset<ll>::iterator it=zero.begin();

			if(b[i]==*it)

			{

				it++;

			}

			res=min(res,ans+(*it-a[i]));

		}

		else

		{

			multiset<ll>::iterator it=zero.begin();

			if(a[i]==*it)

			{

				it++;

			}

			res=min(res,ans+(*it-b[i]));

		}

	}

	cout<<res<<endl;

	return 0;

}


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

#include<algorithm>

using namespace std;

#define N 105000

int n,a[N],b[N],v[N*2],id1[N],id2[N];

long long su1,su2,su[N*2],as=1e18;

long long solve(int i)

{

	if(id1[i]>n&&id2[i]>n)return su[n];

	else if(id1[i]>n+1||id2[i]>n+1)return su[n+1]-(id1[i]<=n+1?v[id1[i]]:0)-(id2[i]<=n+1?v[id2[i]]:0);

	else return su[n+2]-v[id1[i]]-v[id2[i]];

}

int main()

{

	scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%d%d",&a[i],&b[i]),v[i*2-1]=a[i],v[i*2]=b[i],su1+=a[i],su2+=b[i];

	sort(v+1,v+n*2+1);for(int i=1;i<=n;i++)id1[i]=lower_bound(v+1,v+n*2+1,a[i])-v,id2[i]=lower_bound(v+1,v+n*2+1,b[i])-v;

	for(int i=1;i<=n*2;i++)su[i]=su[i-1]+v[i];

	as=min(su1,su2);for(int i=1;i<=n;i++)as=min(as,solve(i));

	printf("%lld\n",as);

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

#define rep(i,a,b) for(int i=(a);i<=(b);i++)

#define per(i,a,b) for(int i=(a);i>=(b);i--)

#define REP(i,n) for(int i=(0);i<(n);i++)

#define fi first

#define se second

#define pb push_back

#define mp make_pair

using namespace std;

typedef pair<int,int> pii;

typedef vector<int> vi;

typedef long long ll;

 

template<class T> inline void read(T &x){

	int f=0;x=0;char ch=getchar();

	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');

	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';

	if(f)x=-x;

}

 

const int N=200005;

int a[N],b[N],c[N],n;

ll A,B,S,ans;

 

int main(){

	read(n);

	rep(i,1,n){

		read(a[i]),read(b[i]);

		A+=a[i],B+=b[i];

		if(a[i]>b[i])swap(a[i],b[i]);

		c[i*2-1]=a[i],c[i<<1]=b[i];

	}

	ans=min(A,B);

	sort(c+1,c+n*2+1);

	rep(i,1,n-2)S+=c[i];

	rep(i,1,n){

		ll s=S+a[i]+b[i]; int k=n-2;

		if(a[i]<=c[k]) s=s-a[i]+c[++k];

		if(b[i]<=c[k]) s=s-b[i]+c[++k];

		ans=min(ans,s);

	}

	cout<<ans<<endl;

	return 0;

}

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

#include<algorithm>

using namespace std;

#define N 105000

int n,a[N],b[N],v[N*2],id1[N],id2[N];

long long su1,su2,su[N*2],as=1e18;

long long solve(int i)

{

	if(id1[i]>n&&id2[i]>n)return su[n];

	else if(id1[i]>n+1||id2[i]>n+1)return su[n+1]-(id1[i]<=n+1?v[id1[i]]:0)-(id2[i]<=n+1?v[id2[i]]:0);

	else return su[n+2]-v[id1[i]]-v[id2[i]];

}

int main()

{

	scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%d%d",&a[i],&b[i]),v[i*2-1]=a[i],v[i*2]=b[i],su1+=a[i],su2+=b[i];

	sort(v+1,v+n*2+1);for(int i=1;i<=n;i++)id1[i]=lower_bound(v+1,v+n*2+1,a[i])-v,id2[i]=lower_bound(v+1,v+n*2+1,b[i])-v;

	for(int i=1;i<=n*2;i++)su[i]=su[i-1]+v[i];

	as=min(su1,su2);for(int i=1;i<=n;i++)as=min(as,solve(i));

	printf("%lld\n",as);

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



using namespace std;



#define lli long long int

#define REP(i,s,n) for(int i=s;i<n;i++)

#define MOD 1000000007

#define NUM 2520

#define INF (1LL<<50)

#define DEBUG 0

#define mp(a,b) make_pair(a,b)

#define SORT(V) sort(V.begin(),V.end())



lli lengthT[100100],lengthA[100100];

lli edge[100100];



signed main(){



	lli n,u,v;

	cin>>n>>u>>v;

	u--,v--;



	map<lli,vector<lli>> d;

	vector<lli> a(n-1),b(n-1);

	REP(i,0,n-1){

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

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

		d[a[i]].push_back(b[i]);

		d[b[i]].push_back(a[i]);

	}



	REP(i,0,100100){

		lengthT[i]=INF;

		lengthA[i]=INF;

		edge[i]=0;

	}

	lengthT[u]=0;

	lengthA[v]=0;



	queue<lli> qt,qa;

	qt.push(u);

	qa.push(v);



	while(qt.size()){

		lli top=qt.front();

		qt.pop();

		for(auto e:d[top]){

			if(lengthT[e]!=INF)continue;

			lengthT[e]=lengthT[top]+1;

			qt.push(e);

		}

	}



	while(qa.size()){

		lli top=qa.front();

		qa.pop();



		bool flag=false;

		for(auto e:d[top]){

			if(lengthA[e]!=INF)continue;

			lengthA[e]=lengthA[top]+1;

			qa.push(e);

			flag=true;

		}

		if(!flag)edge[top]=1;

	}



	lli ans=0;

	REP(i,0,n){

		if(edge[i]==1 && lengthT[i]<=lengthA[i]){

			if(DEBUG)cout<<"i="<<i<<" lengthA="<<lengthA[i]<<endl;

			lli tmp = lengthA[i]-1;

			ans = max(ans,tmp);

		}

	}

	cout<<ans<<endl;



	return 0;

}

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

 

using namespace std;

 

#define lli long long int

#define lld long double

#define REP(i,s,n) for(lli i=s;i<n;i++)

#define RREP(i,s,n) for(lli i=s;i>=n;i--)

#define MOD 1000000007

#define NUM 2520

#define DEBUG 0

#define mp(a,b) make_pair(a,b)

#define SORT(V) sort(V.begin(),V.end())

#define PI (3.141592653589794)

#define INF (1LL<<50)



lli n,u,v;

vector<vector<lli>> d;



lli aoki[100100];

bool visA[100100];

bool visB[100100];

lli taka[100100];



void func(lli now,lli depth,vector<lli> &v,vector<bool> &vis)

{

	if(vis[now])return;

	vis[now]=true;

	v[now]=depth;



	for(auto e:d[now]){

		func(e,depth+1,v,vis);

	}

	return ;

}



signed main(){



	cin>>n>>u>>v;

	u--,v--;

	d.resize(n);

	REP(i,0,n-1){

		lli a,b;

		cin>>a>>b;

		a--,b--;

		d[a].push_back(b);

		d[b].push_back(a);

	}

	vector<lli> aoki(100100,INF),taka(100100,INF);

	vector<bool> visA(100100,false),visTaka(100100,false);



	func(u,0,taka,visTaka);

	func(v,0,aoki,visA);



	lli ans = 0;

	REP(i,0,n){

		if(aoki[i]>taka[i]){

			ans = max(ans,aoki[i]-1);

		}

	}

	cout<<ans<<endl;





	return 0;

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

using namespace std;

typedef long long ll;

#define rep(i, a, b) for (int i = a; i < (int)b; i++)

#define all(v) v.begin(), v.end()

const int MOD = 1e9 + 7;

const int INF = 1e9;

//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122



int n;

vector<vector<int>> g(100010);



vector<int> calcdist(int s) {

    vector<int> dist(100010, -1);

    dist[s] = 0;

    queue<int> que;

    que.push(s);

    while (!que.empty()) {

        int now = que.front();

        que.pop();

        for (int next : g[now]) {

            if (dist[next] != -1) continue;

            dist[next] = dist[now] + 1;

            que.push(next);

        }

    }

    return dist;

}



int main() {

    int n, u, v;

    cin >> n >> u >> v;

    u--;

    v--;

    rep(i, 0, n - 1) {

        int a, b;

        cin >> a >> b;

        a--;

        b--;

        g[a].push_back(b);

        g[b].push_back(a);

    }



    vector<int> dist1 = calcdist(u);

    vector<int> dist2 = calcdist(v);



    int ans = 0;

    rep(i, 0, n) {

        if (dist1[i] < dist2[i]) ans = max(ans, dist2[i]);

    }

    cout << ans - 1 << endl;

    return 0;

}


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

using namespace std;

typedef long long ll;

#define rep(i, a, b) for (int i = a; i < (int)b; i++)

#define all(v) v.begin(), v.end()

const int MOD = 1e9 + 7;

const int INF = 1e9;

//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122



int n;

vector<vector<int>> g(100010);

int dist1[100010], dist2[100010];



void dfs1(int v, int p) {

    for (int nv : g[v]) {

        if (nv == p) continue;

        dist1[nv] = dist1[v] + 1;

        dfs1(nv, v);

    }

}



void dfs2(int v, int p) {

    for (int nv : g[v]) {

        if (nv == p) continue;

        dist2[nv] = dist2[v] + 1;

        dfs2(nv, v);

    }

}



int main() {

    int n, u, v;

    cin >> n >> u >> v;

    u--;

    v--;

    rep(i, 0, n - 1) {

        int a, b;

        cin >> a >> b;

        a--;

        b--;

        g[a].push_back(b);

        g[b].push_back(a);

    }



    dfs1(u, -1);

    dfs2(v, -1);



    int ans = 0;

    rep(i, 0, n) {

        if (dist1[i] < dist2[i]) ans = max(ans, dist2[i]);

    }

    cout << ans - 1 << endl;

    return 0;

}