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

#include <cstdio>

#include <algorithm>

#include <cstring>

#include <queue>

#include <map>

using namespace std;

typedef long long ll;

const ll mod = 1000000009;

const int p = 2333;

map<ll,int>has1;

ll hh[50015]={0};

ll pow1[50015]={0};

char s[50005]={0};

ll gethashcode(int i,int m){

    return (hh[i+m-1]-hh[i-1]*pow1[m]%mod+mod)%mod;

}

int n;

ll num;

int check(int m){

    has1.clear();

    for(int i=1;i+m-2<=n;i++){

        num=gethashcode(i,m);

       // cout << num <<endl;

        if(has1[num]){

            if(has1[num]+m<=i){

                return 1;

            }

        }

        else

            has1[num]=i;

    }

    return 0;

}

int main()

{

    pow1[0]=1;

    for(int i=1;i<50005;i++){

        pow1[i]=pow1[i-1]*p%mod;

    }

    scanf("%d",&n);

    scanf("%s",s+1);

    hh[0]=0;

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

        hh[i]=(hh[i-1]*p%mod+s[i]-'a')%mod;

    int ans = 0 ;

    int l=1,r=n;

    while(l<r){

        int m=(l+r)/2;

        if(check(m)){

            ans=m;

            l=m+1;

        }

        else

            r=m;

    }

    printf("%d\n",ans);

    return 0;

}

//

//13

//orangerangeao




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

#include <cstdio>

#include <algorithm>

#include <cstring>

#include <queue>

#include <map>

using namespace std;

typedef long long ll;

const int p = 13331;

map<ll,int>has1;

long long hh[5005]={0};

long long aa[5005]={0};

char s[5005]={0};

ll gethashcode(int i,int j){

    if(i==0)

        return hh[j];

    else

    return hh[j]-hh[i-1]*aa[j-i+1];

}

int n;

bool check(int m){

        has1.clear();

        ll num;

        for(int i=1;i+m-2<=n;i++){

        num=gethashcode(i,i+m-1);

        if(has1[num]){

            if(has1[num]<=i-m)

                return 1;

            //cout << i << " " << has1[num] << endl;

        }

        else

            has1[num]=i;

    }

    return 0;

}

int main()

{

    cin >> n;

    cin >> s;

    ll num;

    aa[0]=0;

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

        hh[i+1]=hh[i]*p+s[i]-'a';

    }

    aa[0]=1;

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

        aa[i]=aa[i-1]*p;

    int res=0;

    int l=0,r=n;

    int mid;

    int flag=0;

    //cout << check(5) << endl;

    while(l<r){

        mid=(l+r)/2;

        if(check(mid)){

            res=mid;

            l=mid+1;

        }

        else

            r=mid;

    }

    printf("%d\n",res);

    return 0;

}
// Slower C++ solution:
// In the name of God



#include <bits/stdc++.h>



using namespace std;



const int N = 5*1e3+5;



int n;

string s;

long long hs[N], p = 37, mod = 1e9+7, pp[N];

long long hs2[N], p2 = 31, pp2[N];



long long fast_pow(long long x, long long y) {

	long long ret = 1;

	for(;y;y>>=1) {

		if(y&1) ret=ret*x%mod;

		x=x*x%mod;

	}

	return ret;

}



long long givehs(int l, int r) {

	long long ret = hs[r];

	if(l) ret = (ret-hs[l-1]+mod)%mod;

	long long div = pp[n-1-r];

	return ret*div%mod;

}



long long givehs2(int l, int r) {

	long long ret = hs2[r];

	if(l) ret = (ret-hs2[l-1]+mod)%mod;

	long long div = pp2[n-1-r];

	return ret*div%mod;

}





bool check(int len) {

	map<pair<long long, long long>, pair<int, int> > mp;

	if(len==0) return true;

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

		if(i+len-1 >= n) break;

		long long now = givehs(i, i+len-1);

		long long now2 = givehs2(i, i+len-1);

		pair<long long, long long> go = make_pair(now, now2);

		pair<int, int> x = make_pair(1e7, -1);

		if(mp.count(go)) x = mp[go];

		x.first = min(x.first, i);

		x.second = max(x.second, i);

		mp[go] = x;

	}

	for(auto x : mp) {

		if(x.second.first+len-1<x.second.second) return true;

	}

	return false;

}





int main() {

	ios_base::sync_with_stdio(false);

	cin.tie(0);

	cin >> n;

	cin >> s;

	pp[0] = 1;

	pp2[0] = 1;

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

		pp[i] = pp[i-1]*p%mod;

		pp2[i] = pp2[i-1]*p2%mod;

	}

	long long pw = p;

	hs[0] = s[0] - 'a' + 1;

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

		hs[i] = (hs[i-1] + (s[i]-'a'+1)*pw%mod)%mod;

		pw = pw*p%mod;

	}

	pw = p2;

	hs2[0] = s[0] - 'a' + 1;

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

		hs2[i] = (hs2[i-1]+(s[i]-'a'+1)*pw%mod)%mod;

		pw=pw*p2%mod;

	}

	int l = 0, r = n;

	int ans = 0;

	while(l <= r) {

		int m = (l+r) / 2;

		if(check(m)) {

			ans = m;

			l = m + 1;

		}

		else r = m-1;

	}

	cout << ans;

	return 0;

}


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

#include<string>

using namespace std;

int setmax(int num, int len,int m) {

	int tmp;

	tmp = (num < len ? num : len);

	return (m > tmp ? m : tmp);

}

int main()

{

	string s;

	int n;

	cin >>n>>s;

	int len,left,m=0;

	for (len = 1; len <n; len++) {

		int num = 0;

		for (left = 0; left <= n - len; left++) {

			if (left == n - len|| s[left] != s[left + len]) {

				m = setmax(num, len, m);

				num = 0;

			}

			else

				num++;

		}

	}

	cout << m;

}
// Slower C++ solution:
// In the name of God



#include <bits/stdc++.h>



using namespace std;



const int N = 5*1e3+5;



int n;

string s;

long long hs[N], p = 37, mod = 1e9+7, pp[N];

long long hs2[N], p2 = 31, pp2[N];



long long fast_pow(long long x, long long y) {

	long long ret = 1;

	for(;y;y>>=1) {

		if(y&1) ret=ret*x%mod;

		x=x*x%mod;

	}

	return ret;

}



long long givehs(int l, int r) {

	long long ret = hs[r];

	if(l) ret = (ret-hs[l-1]+mod)%mod;

	long long div = pp[n-1-r];

	return ret*div%mod;

}



long long givehs2(int l, int r) {

	long long ret = hs2[r];

	if(l) ret = (ret-hs2[l-1]+mod)%mod;

	long long div = pp2[n-1-r];

	return ret*div%mod;

}





bool check(int len) {

	map<pair<long long, long long>, pair<int, int> > mp;

	if(len==0) return true;

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

		if(i+len-1 >= n) break;

		long long now = givehs(i, i+len-1);

		long long now2 = givehs2(i, i+len-1);

		pair<long long, long long> go = make_pair(now, now2);

		pair<int, int> x = make_pair(1e7, -1);

		if(mp.count(go)) x = mp[go];

		x.first = min(x.first, i);

		x.second = max(x.second, i);

		mp[go] = x;

	}

	for(auto x : mp) {

		if(x.second.first+len-1<x.second.second) return true;

	}

	return false;

}





int main() {

	ios_base::sync_with_stdio(false);

	cin.tie(0);

	cin >> n;

	cin >> s;

	pp[0] = 1;

	pp2[0] = 1;

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

		pp[i] = pp[i-1]*p%mod;

		pp2[i] = pp2[i-1]*p2%mod;

	}

	long long pw = p;

	hs[0] = s[0] - 'a' + 1;

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

		hs[i] = (hs[i-1] + (s[i]-'a'+1)*pw%mod)%mod;

		pw = pw*p%mod;

	}

	pw = p2;

	hs2[0] = s[0] - 'a' + 1;

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

		hs2[i] = (hs2[i-1]+(s[i]-'a'+1)*pw%mod)%mod;

		pw=pw*p2%mod;

	}

	int l = 0, r = n;

	int ans = 0;

	while(l <= r) {

		int m = (l+r) / 2;

		if(check(m)) {

			ans = m;

			l = m + 1;

		}

		else r = m-1;

	}

	cout << ans;

	return 0;

}


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

using namespace std; 

typedef long long ll; 

typedef vector<int> vi; 

const ll oo = 0x3f3f3f3f3f3f3f3fll; 

#define pb push_back



const int maxn = 5006; 



int n; 

string s; 

int f[maxn][maxn]; 



int main() {

	cin>>n; 

	cin>>s; 

	int ans = 0; 

	for (int i = n-1; i >= 0; --i) 

		for (int j = n-1; j > i; --j) { 

			f[i][j] = (s[i]==s[j]?f[i+1][j+1]+1:0); 

			ans = max(ans, min(f[i][j],j-i)); 

		}

	cout<<ans<<endl; 

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



using namespace std;



int main() {

  int a, b;

  cin >> a >> b;



  if(a == b) cout << a*2 << endl;

  else cout << max(a,b) + max(a,b)-1 << endl;



  return 0;

}

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

#include<stdlib.h>



int main(){

	int A,B,Soma,Soma2,Soma3;

	scanf("%d %d",&A,&B);

	

	Soma = A+B; 

	Soma2 = A+(A-1);

	Soma3 = B+(B-1); 

	

	if(Soma >= Soma2 && Soma >=  Soma3){

		printf("%d",Soma);

	}

	else{

		if(Soma2 >= Soma3){

			printf("%d",Soma2);

		}

		else{

			printf("%d",Soma3);

		}

	}

	return 0;

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

#define R register



const int MN = 8e5 + 5;



std::string s;



int n, m, d[MN];



struct Edge {

	Edge *nxt;

	int to;

	Edge(Edge *hd = nullptr, int v = 0){nxt = hd, to = v;}

}*hd[MN];



inline void ins(int u, int v) {hd[u] = new Edge(hd[u], v); ++d[v];}



int main() {

	std::ios::sync_with_stdio(false);

	

	std::cin >> n >> m >> s;

	

	for (R int i = 1, x, y; i <= m; ++i) {

		std::cin >> x >> y;

		if (x == y) {

			ins(x + n, x + n * 2);

			ins(x + n * 3, x);

			continue;

		}

		if (s[x - 1] == s[y - 1]) {

			ins(x + n, y + n * 2);

			ins(y + n, x + n * 2);

			ins(x + n * 3, y);

			ins(y + n * 3, x);

			ins(x + n, y);

			ins(y + n, x);

			ins(x + n * 3, y + n * 2);

			ins(y + n * 3, x + n * 2);

		} 

		else {

			ins(x, y + n);

			ins(x, y + 3 * n);

			ins(x + 2 * n, y + n);

			ins(x + 2 * n, y + 3 * n);

			ins(y, x + n);

			ins(y, x + 3 * n);

			ins(y + 2 * n, x + n);

			ins(y + 2 * n, x + 3 * n);

		}

	}



	std::queue<int> q;

	for (R int i = 1; i <= n * 4; ++i)

		if (!d[i]) q.push(i);

	

	while (!q.empty()) {

		R int u = q.front(); q.pop();

		for (Edge *e = hd[u]; e != nullptr; e = e -> nxt) 

			if (--d[e -> to] == 0) 

				q.push(e -> to);

	}



	for (R int i = 1; i <= n * 4; ++i) 

		if (d[i]) {

			std::cout << "Yes\n";

			return 0;

		}

	std::cout << "No\n";

	return 0;

}

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

#include <cstring>

 

int c[201000]; char s[201000];

int st[201000], top = 0, inq[201000][2], T[201000];

int h[201000], nxt[401000], to[401000], K = 0;

bool used[201000][2];

int flag = 0;



void ins(int u, int v) {nxt[++K] = h[u]; h[u] = K; to[K] = v;}



void dfs(int x, int t)

{

	if(inq[x][t]) {flag = 1; return;}

	if(used[x][t]) return;

	st[++top] = x; T[top] = t; 

	inq[st[top]][T[top]] = 1;

	used[x][t] = 1;

	for(int i = h[x]; i; i = nxt[i])

	{

		if(flag) return;

		if(c[to[i]] == (t ^ 1))

		{

			dfs(to[i], c[x]);

		}

	}

	inq[st[top]][T[top]] = 0;

	top--;

}

 

int main()

{

	int n, m; scanf("%d%d", &n, &m);

	scanf("%s", s + 1);

	for(int i = 1; i <= n; i++) c[i] = (s[i] == 'A' ? 1 : 0);

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

	{

		int u, v; scanf("%d%d", &u, &v);

		ins(u, v); ins(v, u);

	}

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

	{

		if(!used[i][0])

		{

			dfs(i, 0);

			if(flag) return 0 * puts("Yes");

		}

		if(!used[i][1])

		{

			dfs(i, 1);

			if(flag) return 0 * puts("Yes");

		}

	}

	puts("No");

	return 0;

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

#include <vector>

#include <queue>

using namespace std;



const int MAXN = 2e5 + 10;

bool a[MAXN], dl[MAXN];

int n, m, deg[MAXN][2];

vector<int> Mat[MAXN];

queue<int> del;



void ers(int v) {

	for (int i = 0; i < Mat[v].size(); i++) {

		if (dl[Mat[v][i]])

			continue;

		deg[Mat[v][i]][a[v]]--;

		if (deg[Mat[v][i]][0] == 0 || deg[Mat[v][i]][1] == 0)

			del.push(Mat[v][i]), dl[Mat[v][i]] = true;

	}

}



int main() {

	cin >> n >> m;

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

		char tmp;

		cin >> tmp;

		a[i] = (tmp == 'A');

	}

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

		int v, u;

		cin >> v >> u;

		Mat[u].push_back(v);

		Mat[v].push_back(u);

		deg[u][a[v]]++;

		deg[v][a[u]]++;

	}

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

		if (deg[i][0] == 0 || deg[i][1] == 0)

			del.push(i), dl[i] = true;

	while (!del.empty()) {

		ers(del.front());

		del.pop();

	}

	int ans = 0;

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

		ans += !dl[i];

	if (ans)

		cout << "Yes";

	else

		cout << "No";

}

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

using namespace std;



const int _ = 4e5 + 7;

struct Edge{int end , upEd;}Ed[_ << 1];

int head[_] , cntEd , N , M , du[_]; char str[_];



void addEd(int a , int b){Ed[++cntEd] = (Edge){b , head[a]}; head[a] = cntEd; ++du[b];}



int main(){

	scanf("%d %d %s" , &N , &M , str + 1);

	for(int i = 1 ; i <= M ; ++i){

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

		if(str[x] == str[y]){addEd(x , y + N); addEd(y , x + N);}

		else{addEd(x + N , y); addEd(y + N , x);}

	}

	queue < int > q; int cnt = 0;

	for(int i = 1 ; i <= 2 * N ; ++i) if(!du[i]) q.push(i);

	while(!q.empty()){

		int t = q.front(); q.pop(); ++cnt;

		for(int i = head[t] ; i ; i = Ed[i].upEd)

			if(!--du[Ed[i].end]) q.push(Ed[i].end);

	}

	puts(cnt == 2 * N ? "No" : "Yes"); return 0;

}
// Slower C++ solution:
// author: Saman Mahdanian

#include <iostream>

#include <vector>

#include <queue>



using namespace std;

const int N = 2e5 + 10;



int n, m;

vector <int> g[N];

int degA[N], degB[N];

string s;

bool mark[N];

queue <int> to_do;



int32_t main() {

	cin >> n >> m >> s;

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

		int v, u;

		cin >> v >> u;

		v--; u--;

		g[v].push_back(u);

		g[u].push_back(v);

		if (s[v] == 'A')

			degA[u]++;

		else

			degB[u]++;

		if (s[u] == 'A')

			degA[v]++;

		else

			degB[v]++;

	}



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

		int all_same = true;

		for (int u: g[v])

			all_same &= s[u] == s[g[v][0]];

		if (all_same)

			to_do.push(v);

	}



	while (!to_do.empty()) {

		int v = to_do.front();

		to_do.pop();

		if (mark[v])

			continue;

		mark[v] = true;

		for (int u: g[v]) {

			if (s[v] == 'A')

				degA[u]--;

			else 

				degB[u]--;

			if (degA[u] == 0 || degB[u] == 0)

				if (!mark[u])

					to_do.push(u);

		}

	}



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

		if (!mark[i]) {

			cout << "Yes" << endl;

			return 0;

		}

	cout << "No" << endl;

}

// SamMHD :: 21/11/2018 14:06:15 :: Another F****** graph...

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

#define LL long long



using namespace std;

const int N=2e5+10;

int rd()

{

    int x=0,w=1;char ch=0;

    while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}

    while(ch>='0'&&ch<='9'){x=x*10+(ch^48);ch=getchar();}

    return x*w;

}

int to[N<<1],nt[N<<1],hd[N],dg[N][2],tot=1;

void adde(int x,int y)

{

    ++tot,to[tot]=y,nt[tot]=hd[x],hd[x]=tot;

    ++tot,to[tot]=x,nt[tot]=hd[y],hd[y]=tot;

}

char cc[N];

int n,m,tt;

bool v[N];



int main()

{

////////////////

    n=rd(),m=rd();

    scanf("%s",cc+1);

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

    {

	int x=rd(),y=rd();

	adde(x,y);

	++dg[x][cc[y]-'A'],++dg[y][cc[x]-'A'];

    }

    queue<int> q;

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

	if(!dg[i][0]||!dg[i][1]) v[i]=1,q.push(i);

    while(!q.empty())

    {

	int x=q.front();

	q.pop();

	++tt;

	for(int i=hd[x];i;i=nt[i])

	{

	    int y=to[i];

	    --dg[y][cc[x]-'A'];

	    if(!v[y]&&!dg[y][cc[x]-'A']) v[y]=1,q.push(y);

	}

    }

    puts(tt==n?"No":"Yes");

    return 0;

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

using namespace std;

const int maxn = 2e5 + 5;



int d1[maxn], d2[maxn];

int n, m;

string s;

bool mark[maxn];

queue <int> que;

vector<int> g[maxn];



int main() {

	ios::sync_with_stdio(false);

	cin.tie(0);

	cout.tie(0);

	

	cin >> n >> m >> s;

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

		int u, v;

		cin >> u >> v;

		u--, v--;

		if(u != v) {

			g[u].push_back(v);

			g[v].push_back(u);

			if(s[v] == 'A')

				d1[u]++;

			else

				d2[u]++;

			if(s[u] == 'A')

				d1[v]++;

			else

				d2[v]++;

		}

		else {

			g[u].push_back(u);

			if(s[v] == 'A')

				d1[u]++;

			else

				d2[u]++;

		}

	}

	

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

		if(d1[i] == 0 || d2[i] == 0) {

			que.push(i);

		}

	}

	

	while(que.size()) {

		int u = que.front();

		mark[u] = true;

//		cout << "del : " << u + 1 << endl;

		

		for(int i = 0; i < g[u].size(); i++) {

			int v = g[u][i];

			if(!mark[v]) {

				if(s[u] == 'B')

					d2[v]--;

				else

					d1[v]--;

				if((d1[v] == 0 && s[u] == 'A') || (d2[v] == 0 && s[u] == 'B')) {

					que.push(v);

				}

			}

		}

		que.pop();

	}

	

	int x = 0;

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

		if(!mark[i])

			x++;//, cout << i + 1 << " ";

	}

	

	if(x != 0)

		cout << "Yes";

	else

		cout << "No";

}

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

#define LL long long



using namespace std;

const int N=2e5+10;

int rd()

{

    int x=0,w=1;char ch=0;

    while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}

    while(ch>='0'&&ch<='9'){x=x*10+(ch^48);ch=getchar();}

    return x*w;

}

int to[N<<1],nt[N<<1],hd[N],dg[N][2],tot=1;

void adde(int x,int y)

{

    ++tot,to[tot]=y,nt[tot]=hd[x],hd[x]=tot;

    ++tot,to[tot]=x,nt[tot]=hd[y],hd[y]=tot;

}

char cc[N];

int n,m,tt;

bool v[N];



int main()

{

////////////////

    n=rd(),m=rd();

    scanf("%s",cc+1);

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

    {

	int x=rd(),y=rd();

	adde(x,y);

	++dg[x][cc[y]-'A'],++dg[y][cc[x]-'A'];

    }

    queue<int> q;

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

	if(!dg[i][0]||!dg[i][1]) v[i]=1,q.push(i);

    while(!q.empty())

    {

	int x=q.front();

	q.pop();

	++tt;

	for(int i=hd[x];i;i=nt[i])

	{

	    int y=to[i];

	    --dg[y][cc[x]-'A'];

	    if(!v[y]&&!dg[y][cc[x]-'A']) v[y]=1,q.push(y);

	}

    }

    puts(tt==n?"No":"Yes");

    return 0;

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



using namespace std;



#define size(x) ((int) x.size())



const int MAXN = 2e5 + 5;



string s;



vector <int> adj[MAXN];



bool mark[MAXN];



int n, m;

int u, v;

int deg_a[MAXN];

int deg_b[MAXN];

int cnt;



queue <int> Q;



int main() {

	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

	cin >> n >> m >> s;

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

		cin >> u >> v;

		u--, v--;

		adj[u].push_back(v);

		adj[v].push_back(u);

		/*if (s[u] == 'A')

			deg_a[v]++;

		else

			deg_b[u]++;

		if (s[v] == 'A')

			deg_a[u]++;

		else

			deg_b[u]++;*/

		(s[u] == 'A' ? deg_a[v]++ : deg_b[v]++);

		(s[v] == 'A' ? deg_a[u]++ : deg_b[u]++);

	}

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

//		cout << i << " : " << deg_a[i] << " " << deg_b[i] << endl;

	cnt = n;

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

		if (!deg_a[i] || !deg_b[i]) {

			Q.push(i);

			mark[i] = true;

		}

	while (!Q.empty()) {

		int u = Q.front();

		Q.pop();

		cnt--;

		for (int i = 0; i < size(adj[u]); i++) {

			int v = adj[u][i];

			(s[u] == 'A') ? deg_a[v]-- : deg_b[v]--;

			if ((!deg_a[v] || !deg_b[v]) && !mark[v]) {

				Q.push(v);

				mark[v] = true;

			}

		}

	}

	if (cnt)

		cout << "Yes";

	else

		cout << "No";

	cout << endl;

	return 0;

}

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

#define LL long long



using namespace std;

const int N=2e5+10;

int rd()

{

    int x=0,w=1;char ch=0;

    while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}

    while(ch>='0'&&ch<='9'){x=x*10+(ch^48);ch=getchar();}

    return x*w;

}

int to[N<<1],nt[N<<1],hd[N],dg[N][2],tot=1;

void adde(int x,int y)

{

    ++tot,to[tot]=y,nt[tot]=hd[x],hd[x]=tot;

    ++tot,to[tot]=x,nt[tot]=hd[y],hd[y]=tot;

}

char cc[N];

int n,m,tt;

bool v[N];



int main()

{

////////////////

    n=rd(),m=rd();

    scanf("%s",cc+1);

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

    {

	int x=rd(),y=rd();

	adde(x,y);

	++dg[x][cc[y]-'A'],++dg[y][cc[x]-'A'];

    }

    queue<int> q;

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

	if(!dg[i][0]||!dg[i][1]) v[i]=1,q.push(i);

    while(!q.empty())

    {

	int x=q.front();

	q.pop();

	++tt;

	for(int i=hd[x];i;i=nt[i])

	{

	    int y=to[i];

	    --dg[y][cc[x]-'A'];

	    if(!v[y]&&!dg[y][cc[x]-'A']) v[y]=1,q.push(y);

	}

    }

    puts(tt==n?"No":"Yes");

    return 0;

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

#define int long long



using namespace std;



const int N = 2e5+10;

const string s = "AABBAABB";



vector<int> adj[N];

string label;

int reach[N][4];



void go(int u, int k) {

  if(reach[u][k] == 1) {

    cout << "Yes" << endl;

    exit(0);

  }

  if(reach[u][k] == 2) return;

  reach[u][k] = 1;

  for(int v : adj[u])

    if(s[k+1] == label[v])

      go(v, (k+1)%4);

  reach[u][k] = 2;

}



int32_t main() {

  ios::sync_with_stdio(false);

  cin.tie(0);

  int n, m;

  cin >> n >> m;



  cin >> label;



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

    int u, v;

    cin >> u >> v;

    --u, --v;

    adj[u].push_back(v);

    adj[v].push_back(u);

  }



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

    if(!reach[i][0])

      go(i, 0);



  cout << "No" << endl;

}




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

using namespace std;



typedef long long ll;

const int maxn = 200005;



inline int gi()

{

	char c = getchar();

	while (c < '0' || c > '9') c = getchar();

	int sum = 0;

	while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();

	return sum;

}



int n, m;

char S[maxn];



struct edge

{

	int to, next;

} e[maxn * 2];

int h[maxn], deg[maxn][2], vis[maxn], tot;

int s, t, q[maxn];



void add(int u, int v)

{

	e[++tot] = (edge) {v, h[u]}; h[u] = tot;

	e[++tot] = (edge) {u, h[v]}; h[v] = tot;

	++deg[u][S[v] - 'A']; ++deg[v][S[u] - 'A'];

}



int topo()

{

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

		if (!deg[i][0] || !deg[i][1]) q[++t] = i, vis[i] = 1;

	int cnt = 0;

	while (s < t) {

		int u = q[++s];

		++cnt;

		for (int i = h[u], v; v = e[i].to, i; i = e[i].next)

			if (!vis[v] && !(--deg[v][S[u] - 'A'])) vis[q[++t] = v] = 1;

	}

	return cnt;

}



int main()

{

	scanf("%d%d%s", &n, &m, S + 1);

	for (int i = 1; i <= m; ++i) add(gi(), gi());

	

	puts(topo() == n ? "No" : "Yes");

	

	return 0;

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



using namespace std;

#define pb push_back

const int mn=2e5+5;



int n,m;

char s[mn];



int a[mn],b[mn];

bool vis[mn];

vector<int> g[mn];

queue<int> q;



int main() {

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

    scanf("%s",s+1);

    for(int i=1; i<=m; i++) {

        int u,v;

        scanf("%d%d",&u,&v);

        g[u].pb(v);

        g[v].pb(u);

        if (s[u]=='A') a[v]++;

        else b[v]++;

        if (s[v]=='A') a[u]++;

        else b[u]++;

    }



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

        if (a[i]==0||b[i]==0) q.push(i),vis[i]=1;

    }

    while(!q.empty()) {

        int u=q.front();

        q.pop();

        for(auto &i:g[u]) {

            if (s[u]=='A') {

                a[i]--;

                if (!vis[i]&&a[i]==0) q.push(i),vis[i]=1;

            }

            else {

                b[i]--;

                if (!vis[i]&&b[i]==0) q.push(i),vis[i]=1;

            }

        }

    }

    int ans=0;

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

        if (!vis[i]) ans=1;

    if (ans) puts("Yes");

    else puts("No");



    return 0;

}


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

using namespace std;



typedef long long ll;

const int maxn = 200005;



inline int gi()

{

	char c = getchar();

	while (c < '0' || c > '9') c = getchar();

	int sum = 0;

	while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();

	return sum;

}



int n, m;

char S[maxn];



struct edge

{

	int to, next;

} e[maxn * 2];

int h[maxn], deg[maxn][2], vis[maxn], tot;

int s, t, q[maxn];



void add(int u, int v)

{

	e[++tot] = (edge) {v, h[u]}; h[u] = tot;

	e[++tot] = (edge) {u, h[v]}; h[v] = tot;

	++deg[u][S[v] - 'A']; ++deg[v][S[u] - 'A'];

}



int topo()

{

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

		if (!deg[i][0] || !deg[i][1]) q[++t] = i, vis[i] = 1;

	int cnt = 0;

	while (s < t) {

		int u = q[++s];

		++cnt;

		for (int i = h[u], v; v = e[i].to, i; i = e[i].next)

			if (!vis[v] && !(--deg[v][S[u] - 'A'])) vis[q[++t] = v] = 1;

	}

	return cnt;

}



int main()

{

	scanf("%d%d%s", &n, &m, S + 1);

	for (int i = 1; i <= m; ++i) add(gi(), gi());

	

	puts(topo() == n ? "No" : "Yes");

	

	return 0;

}