stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;



const int MAXN = 5050;



const long long P1 = 1087;

const long long P2 = 1097;

const long long MOD1 = 1e9 + 7;

const long long MOD2 = 1e9 + 123;





int N;



char ar[MAXN];



long long int hash1[MAXN];

long long int hash2[MAXN];



long long int power1[MAXN];

long long int power2[MAXN];



inline long long get_hash( int i, int len, long long P, long long MOD, long long power[], long long hash[] ) {



	long long first = (hash[i] - hash[i + len] + MOD) % MOD;



	return (first * power[i]) % MOD;

}



inline bool check( int len ) {



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

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

			if ( get_hash(i, len, P1, MOD1, power1, hash1) == get_hash(j, len, P1, MOD1, power1, hash1)

			 && get_hash(i, len, P2, MOD2, power2, hash2) == get_hash(j, len, P2, MOD2, power2, hash2) ) {

				// cerr << i << " " << j << " " << len << endl;

				return true;

			}

		}

	}



	return false;

}



int main() {



	string s;



	power1[0] = power2[0] = 1LL;



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

		power1[i] = (power1[i - 1] * P1) % MOD1;

		power2[i] = (power2[i - 1] * P2) % MOD2;

	}



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



	for( int i=N ; i ; i-- ) {

		hash1[i] = (((power1[N - i] * (ar[i] - 'a')) % MOD1) + hash1[i + 1]) % MOD1;

		hash2[i] = (((power2[N - i] * (ar[i] - 'a')) % MOD2) + hash2[i + 1]) % MOD2;

	}



	int lo = 0, hi = N, result;



	cerr << hi << endl;



	while( lo <= hi ) {



		int mi = (lo + hi) / 2;



		// cerr << mi << endl;



		if (check(mi)) {

			result = mi;

			lo = mi + 1;

		} else {

			hi = mi - 1;

		}

	}



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

	return 0;

}

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

#include<cstring>

#include<cstdlib>

#include<cstdio>

#include<map>

#define pii pair<int,int>

#define mod 1000000007

#define MOD 998244353

#define SED 233

#define N 200020

#define sed 173

using namespace std;

int has[N],pw[N];

int geth(int x,int y)

{

	return (has[y]-1ll*has[x-1]*pw[y-x+1]%mod+mod)%mod;

}

int _has[N],_pw[N];

int _geth(int x,int y)

{

	return (_has[y]-1ll*_has[x-1]*_pw[y-x+1]%MOD+MOD)%MOD;

}

int n;

char ch[N];

map<pii,bool>vis;

bool check(int len)

{

	vis.clear();

	for(int i=n-len+1;i;i--)

	{

		int j=i+len;

		if(j+len-1<=n)vis[make_pair(geth(j,j+len-1),_geth(j,j+len-1))]=1;

		pii tmp=make_pair(geth(i,i+len-1),_geth(i,i+len-1));

		if(vis[tmp])return true;

	}

	return false;

}

int main()

{

	scanf("%d%s",&n,ch+1),pw[0]=_pw[0]=1;

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

		pw[i]=1ll*pw[i-1]*sed%mod,has[i]=(1ll*has[i-1]*sed%mod+ch[i])%mod,

		_pw[i]=1ll*_pw[i-1]*SED%MOD,_has[i]=(1ll*_has[i-1]*SED%MOD+ch[i])%MOD;

	int l=1,r=n,ret=0;

	while(l<=r)

	{

		int mid=(l+r)>>1;

		if(check(mid))l=mid+1,ret=mid;

		else r=mid-1;

	}

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

}

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

#include<cstdio>

#include<vector>

using namespace std;

char s[5005];

int Next[5005];

vector<char> v[5005];

int main()

{

    int n,i,j,k,m,t,max=0;

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

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

        for(j=i;j<n;j++)

            v[i].push_back(s[j]);

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

    {

        Next[0]=-1;

        j=0;

        k=-1;

        while(j<n-i)

        {

            if(k==-1||v[i][j]==v[i][k])

                Next[++j]=++k;

            else

                k=Next[k];

        }

        for(j=0;j<=n-i;j++)

        {

            if(Next[j]<=j/2)

            {

                if(Next[j]>max) max=Next[j];

            }

            else

            {

                t=j-Next[j];

                t=t*(j/t/2);

                if(t>max) max=t;

            }

        }

    }

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

    return 0;

}

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

using namespace std;



#define N 5000 + 10

int f[N][N],n,ans;

char s[N];



int main(){

ios::sync_with_stdio(false);

cin>>n>>s;

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

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

if(s[i]==s[j])

f[i][j]=max(f[i][j],f[i+1][j+1]+1);

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

}

cout<<ans;

}

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

#include<cstdio>

#include<vector>

using namespace std;

char s[5005];

int Next[5005];

vector<char> v[5005];

int main()

{

    int n,i,j,k,t,max=0;

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

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

        for(j=i;j<n;j++)

            v[i].push_back(s[j]);

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

    {

        Next[0]=-1;

        j=0;

        k=-1;

        while(j<n-i)

        {

            if(k==-1||v[i][j]==v[i][k])

                Next[++j]=++k;

            else

                k=Next[k];

        }

        for(j=0;j<=n-i;j++)

        {

            if(Next[j]<=j/2)

            {

                if(Next[j]>max) max=Next[j];

            }

            else

            {

                t=j-Next[j];

                t=t*(j/t/2);

                if(t>max) max=t;

            }

        }

    }

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

    return 0;

}

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

using namespace std;



#define N 5000 + 10

int f[N][N],n,ans;

char s[N];



int main(){

ios::sync_with_stdio(false);

cin>>n>>s;

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

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

if(s[i]==s[j])

f[i][j]=max(f[i][j],f[i+1][j+1]+1);

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

}

cout<<ans;

}

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

#include <cctype>

#include <algorithm>

#include <cstring>

#include <set>

int read(){

	register int x = 0;

	register char ch = getchar(), f = 1;

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

	for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ '0');

	return f ? x : -x;

}

#define N 5005

const int B1 = 233, P1 = 382538579, B2 = 331, P2 = 952959323;

int pw1[N], pw2[N];

struct node{

	int H1, H2;

	node(int _H1 = 0, int _H2 = 0){ H1 = _H1, H2 = _H2; }

	bool operator < (const node &rhs) const {

		return H1 < rhs.H1 || (H1 == rhs.H1 && H2 < rhs.H2);

	}

	bool operator == (const node &rhs) const {

		return H1 == rhs.H1 && H2 == rhs.H2;

	}

	node operator + (const char ch) const {

		return node((1ll * H1 * B1 + ch) % P1, (1ll * H2 * B2 + ch) % P2);

	}

	node operator - (const node &rhs) const {

		return node((H1 - rhs.H1 + P1) % P1, (H2 - rhs.H2 + P2) % P2);

	}

	node operator << (const int x) const {

		return node(1ll * H1 * pw1[x] % P1, 1ll * H2 * pw2[x] % P2);

	}

}h[N];

int n;

char a[N];

int main(){

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

	pw1[0] = pw2[0] = 1;

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

		pw1[i] = 1ll * pw1[i - 1] * B1 % P1, pw2[i] = 1ll * pw2[i - 1] * B2 % P2;

	for (register int i = 1; i <= n; ++i) h[i] = h[i - 1] + a[i];

	for (register int len = n >> 1; len; --len){

		std :: set<node> S;

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

			S.insert(h[i - len] - (h[i - (len << 1)] << len));

			if (S.count(h[i] - (h[i - len] << len))) return printf("%d\n", len), 0;

		}

	}

	printf("0\n");

}


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

#include <cstring>

#include <algorithm>

#define N 5005

int n, ans;

char a[N];

int main(){

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

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

		int s = 0;

		for (register int j = 1; j <= n - i; ++j)

			a[j] == a[j + i] && s < i ? ++s, ans = std :: max(ans, s) : s = 0;

	}

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

}

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

#include <map>

#include <vector>

const int HASH = 131;

const int MAXN = 5005;

const int MOD = 1e9+7;

char S[MAXN];

int H[MAXN];

int N, size;



std::map<int, std::vector<int>> D;



bool compare(int a, int b) {

  for (int k = 0; k < size; ++k) {

    if (S[a-k] != S[b-k]) return false;

  }

  return true;

}



bool matches(int sum, int cur) {

  for (int pos: D.at(sum)) {

    if (pos + size > cur) break;

    if (compare(pos, cur)) {

      return true;

    }

  }

  return false;

}



bool find() {

  D.clear();

  int sum = 0;

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

    sum = (1LL * HASH * sum + S[i]) % MOD;

    if (i >= size) {

      int old = 1LL * H[size] * S[i-size] % MOD;

      sum = (sum - old + MOD) % MOD;

    }

    if (i+1 >= size) {

      if (D.count(sum) && matches(sum, i)) {

        return true;

      }

      D[sum].push_back(i);

    }

  }

  return false;

}



void init() {

  H[0] = 1;

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

    H[i] = 1LL * H[i-1] * HASH % MOD;

  }

}



int solve() {

  int lo = 0;

  int hi = N/2;

  while (lo < hi) {

    size = (lo + hi + 1) / 2;

    if (find()) {

      lo = size;

    } else {

      hi = size-1;

    }

  }

  return lo;

}



int main() {

  scanf(" %d%s", &N, S);

  init();

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

  return 0;

}

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

#include <cstdio>

const int MAXN = 5005;

char S[MAXN];

int dp[MAXN][MAXN];

int N;



int solve() {

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

    dp[i][0] = dp[0][i] = 0;

  }

  int ret = 0;

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

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

      if ((i == j) || (S[i] != S[j])) {

        dp[i][j] = 0;

      } else if (S[i] == S[j]) {

        dp[i][j] = std::min(dp[i-1][j-1] + 1, std::abs(i - j));

        ret = std::max(dp[i][j], ret);

      }

    }

  }

  return ret;

}



int main() {

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

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

  return 0;

}

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

using namespace std;

typedef long long ll;

const int N=5e3+5,mod=1e9+9;

ll hs[N],f[N],invf[N];

int n;

char s[N];

int get_hs(int l,int r)

{

    return (hs[r]-hs[l-1]+mod)%mod*invf[l-1]%mod;

}

map<int,int>vis;

bool judge(int m)

{

    if(m==0) return true;

    vis.clear();

    for(int i=n-m+1;i>=1;i--)

        vis[get_hs(i,i+m-1)]++;

    int pos=1;

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

    {

        while(pos<=i+m-1&&pos<=n-m+1)

        {

            vis[get_hs(pos,pos+m-1)]--;pos++;

        }

        if(pos>n-m+1) return false;

        if(vis[get_hs(i,i+m-1)]) return true;

    }

    return false;

}

ll qpow(ll a,ll n)

{

    ll ans=1;

    while(n)

    {

        if(n&1) ans=ans*a%mod;

        a=a*a%mod;

        n>>=1;

    }

    return ans;

}

int main()

{

    f[0]=invf[0]=1;

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

        f[i]=f[i-1]*13331%mod,invf[i]=qpow(f[i],mod-2);

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

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

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

    int l=0,r=n/2,ans;

    while(l<=r)

    {

        int m=l+r>>1;

        if(judge(m)) ans=m,l=m+1;

        else r=m-1;

    }

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

}


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

#include<cstdio>

#include<cstring>

#include<algorithm>

#include <map>

#define key 2333

#define maxn 100005

#define uLL unsigned long long

using namespace std;

uLL hsh[maxn],bas[maxn];

map<uLL,int>h;

char s[maxn];

int n;

priority_queue<int> hep;

inline int read(){

	int ret=0,f=1;char ch=getchar();

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

	while (ch>='0'&&ch<='9') ret=ret*10+ch-'0',ch=getchar();

	return ret*f;

}

uLL gethashcode(int i,int p){

    return hsh[i+p-1]-hsh[i-1]*bas[p];

}

inline bool check(int p){

	h.clear();

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

        uLL num = gethashcode(i,p);

        if(h[num]){

            if(h[num]+p<=i){

                return 1;

            }

        }

        else

            h[num]=i;

	}

	return 0;

}

int main(){

	n=read();

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

	bas[0]=1;

	for (int i=1;i<=n;i++) hsh[i]=hsh[i-1]*key+s[i]-'a',bas[i]=bas[i-1]*key;

	int L=0,R=n/2,ret=0;

	while (L<=R){

		int mid=(L+R)>>1;

		if (check(mid)) ret=mid,L=mid+1;

		else R=mid-1;

	}

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

	return 0;

}


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




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

}




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

}


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

}

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

}

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

}

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

}

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

}

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

}

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

}

// Fastest known solution for this problem: