stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#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;

  }





}

// Optimized solution to the same problem (faster):
#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;;

	}

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;   

}  

// Optimized solution to the same problem (faster):
#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);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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);

}//

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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);

}//

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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



vector<int> edge[100010];

int dist1[100010], dist2[100010];



void dfs1(int v, int p) {

    for (int nv : edge[v]) {

        if (nv == p) continue;

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

        dfs1(nv, v);

    }

}



void dfs2(int v, int p) {

    for (int nv : edge[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--;

        edge[a].push_back(b);

        edge[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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<string>

#include<vector>



using namespace std;



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





int const MAX_N = 100000;

vector<int> G[MAX_N];

int taka[MAX_N];

int ao[MAX_N];



void dfs(int e, int num, int per[]){

    rep(i, G[e].size()){

        int edge = G[e][i];

        if (per[edge] != -1) continue;

        else {

            per[edge] = num;

            dfs(edge, num + 1, per);

        }

    }

}



int main(){

    int n, u , v;

    cin >> n >> u >> v;

    u--;

    v--;

    rep(i, n - 1){

        int a, b;

        cin >> a >> b;

        a--; b--;

        G[a].push_back(b);

        G[b].push_back(a);

    }

    fill(taka, taka + n, -1);

    fill(ao, ao + n, -1);



    taka[u] = 0;

    dfs(u, 1, taka);

    ao[v] = 0;

    dfs(v, 1, ao);

    // rep(i, n) cout << taka[i] << " ";

    // cout << endl;

    int ans = 0;

    int idx;

    rep(i, n){

        if (taka[i] < ao[i] && ans < ao[i]){

            ans = ao[i];

            idx = i;

        }

    }

    cout << ans - 1 << endl;

    // if ((ao[idx] - taka[idx]) % 2 == 0){

    //     cout << ans - 1 << endl;

    // }else{

    //     cout << ans << endl;

    // }

    

}

// Optimized solution to the same problem (faster):
#include<iostream>

#include<algorithm>

#include<string>

#include<vector>

#include<cstdlib>

#include<queue>

#include<set>

#include<cstdio>

#include<map>



using namespace std;



#define ll long long

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

#define P pair<int, int>



typedef vector<int> vec;

typedef vector<vec> mat;



const ll mod = 1000000007;



int main(){

    int n, u, v;

    cin >> n >> u >> v;

    u--; v--;

    vector<vector<int> > e(n);

    rep(i, n-1) {

        int a, b;

        cin >> a >> b;

        a--; b--;

        e[a].push_back(b);

        e[b].push_back(a);

    }

    vector<int> du(n, -1), dv(n, -1);

    du[u] = 0; dv[v] = 0;

    queue<P> que_u, que_v;

    que_u.push(P(u, 0));

    que_v.push(P(v, 0));

    while(que_u.size() > 0){

        P p = que_u.front();

        que_u.pop();

        int s = p.first;

        int d = p.second;

        rep(i, e[s].size()){

            if(du[e[s][i]] != -1) continue;

            du[e[s][i]] = d + 1;

            que_u.push(P(e[s][i], d+1));

        }

    }

    while(que_v.size() > 0){

        P p = que_v.front();

        que_v.pop();

        int s = p.first;

        int d = p.second;

        rep(i, e[s].size()){

            if(dv[e[s][i]] != -1) continue;

            dv[e[s][i]] = d + 1;

            que_v.push(P(e[s][i], d+1));

        }

    }

    int ans = 0;

    rep(i, n){

        if(du[i] < dv[i]){

            ans = max(ans, dv[i]);

        }

    }

    // rep(i, n){

    //     cout << du[i] << " " ;

    // }cout << endl;

    // rep(i, n){

    //     cout << dv[i] << " " ;

    // }cout << endl;

    cout << ans - 1 << endl;



}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <algorithm>

#include <vector>

#include <queue>

#include <string>

#include <cstring>

#include <utility>

#include <set>

#include <stack>

#include <climits>

#include <cmath>



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

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

#define MEMSET(v, h) memset((v), h, sizeof(v))

typedef long long ll;



using namespace std;



struct node{

    vector<int> par;

    ll T, A, val;

};



static node c[100009];



void Aoki(int come, int cur, int depth){

    //cout<<cur<<" "<<depth<<endl;

    c[cur].A=depth;

    rep(i, c[cur].par.size()){

        if(c[cur].par[i]==come) continue;

        else Aoki(cur, c[cur].par[i], depth+1);

    }

}

void Taka(int come, int cur, int depth){

    c[cur].T=depth;

    if(c[cur].A<=depth) depth=100001;

    

    rep(i, c[cur].par.size()){

        if(c[cur].par[i]==come) continue;

        else{

           Taka(cur, c[cur].par[i], depth+1);

        }

    }

}





int main(void){

    int N, u, v, a, b;

    

    cin>>N>>u>>v;

    rep(i, N-1){

        cin>>a>>b;

        c[a-1].par.push_back(b-1);

        c[b-1].par.push_back(a-1);

    }

    Aoki(-1, v-1, 0);

    Taka(-1, u-1, 0);

    ll Maxim=0;

    rep(i, N){

        if(c[i].A>=c[i].T) Maxim=max(Maxim, c[i].A-1) /*cout<<i<<endl*/;

    }

    cout<<Maxim<<endl;

    return 0;

}


// Optimized solution to the same problem (faster):
#include <iostream>

#include <algorithm>

#include <vector>

#include <queue>

#include <string>

#include <cstring>

#include <utility>

#include <set>

#include <stack>

#include <climits>

#include <cmath>



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

#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)

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

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

#define MEMSET(v, h) memset((v), h, sizeof(v))

typedef long long ll;

const char sp = ' ';



using namespace std;



struct Node{

    ll depthT;

    ll depthA;

    vector<ll> chi;

};

Node node[100004];



void dfsT(ll loca, ll depth, ll rem){

    node[loca].depthT=depth;

    rep(i, node[loca].chi.size()){

        if(node[loca].chi[i]==rem) continue;

        dfsT(node[loca].chi[i], depth+1, loca);

    }

}



void dfsA(ll loca, ll depth, ll rem){

    node[loca].depthA=depth;

    rep(i, node[loca].chi.size()){

        if(node[loca].chi[i]==rem) continue;

        dfsA(node[loca].chi[i], depth+1, loca);

    }

}



int main(void){

    ll N, u, v;

    cin>>N>>u>>v;

    rep(i, N-1){

        ll A, B;

        cin>>A>>B;

        node[A-1].chi.push_back(B-1);

        node[B-1].chi.push_back(A-1);

    }

    dfsT(u-1, 0, -1);

    dfsA(v-1, 0, -1);

    ll Maxim=0;

    rep(i, N){

        if(node[i].depthA-node[i].depthT>=0){

            ll ans=((node[i].depthA-node[i].depthT)%2==0 ? node[i].depthA-1 : node[i].depthA-1);

            

            Maxim=max(Maxim, ans);

        }

    }

    cout<<Maxim<<endl;

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

/* typedef */

typedef long long ll;

typedef pair<int, int> pii;

/* constant */

const int INF = 1 << 30;

const ll LINF = 1LL << 50;

const int NIL = -1;

const int MAX = 100005;

const int mod = 1000000007;

const double pi = 3.141592653589;

/* global variables */

vector<vector<int> > G(MAX, vector<int>());

/* function */

void bfs(int st, vector<int>& d) {

    queue<int> q;

    q.push(st);

    d[st] = 0;

    while (!q.empty()) {

        int from = q.front(); q.pop();

        for (int to : G[from]) {

            if (d[to] != NIL) continue;

            d[to] = d[from] + 1;

            q.push(to);

        }

    }

}

/* main */

int main(){

    int N, A, T;

    cin >> N >> T >> A;

    T--, A--;

    int u, v;

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

        cin >> u >> v;

        u--, v--;

        G[v].push_back(u);

        G[u].push_back(v);

    }



    vector<int> disA(MAX, NIL), disT(MAX, NIL);

    bfs(T, disT);

    bfs(A, disA);



    int ans = 0;

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

        if (disT[i] >= disA[i]) continue;

        ans = max(ans, disT[i] + max(0, disA[i] - disT[i] - 1));

    }

    cout << ans << '\n';

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

/* typedef */

typedef long long ll;

typedef pair<int, int> pii;

/* constant */

const int INF = 1 << 30;

const ll LINF = 1LL << 50;

const int NIL = -1;

const int MAX = 100005;

const int mod = 1000000007;

const double pi = 3.141592653589;

/* global variables */

int N;

vector<vector<int>> G(MAX, vector<int>());

/* function */

vector<int> bfs(int st) {

    vector<int> dist(N, NIL);

    queue<int> q;

    q.push(st);

    dist[st] = 0;

    while (q.size()) {

        int from = q.front();

        q.pop();

        for (int to :G[from]) {

            if (dist[to] != NIL) continue;

            dist[to] = dist[from] + 1;

            q.push(to);

        }

    }

    return dist;

}

/* main */

int main(){

    int u, v;

    cin >> N >> u >> v;

    u--, v--;

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

        int s, t; cin >> s >> t;

        s--, t--;

        G[s].push_back(t);

        G[t].push_back(s);

    }

    vector<int> distTk = bfs(u);

    vector<int> distAO = bfs(v);

    int mx = 0;

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

        if (distTk[i] < distAO[i]) {

            if (mx < distAO[i]) {

                mx = distAO[i];

            }

        }

    }

    int ans = mx - 1;

    cout << ans << '\n';

}


// Fastest known solution for this problem: