stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;



const int N = 2e5 + 100;



queue<int> q;

vector<int> adj[N];

bool mark[N];

char a[N];

int d1[N], d2[N];

int n, m, cnt;



int main() {

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

	cin >> n >> m;

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

		cin >> a[i];

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

		int v, u;

		cin >> v >> u;

		adj[--v].push_back(--u);

		adj[u].push_back(v);

		(a[v] == 'A' ? d1[u]++ : d2[u]++);

		(a[u] == 'A' ? d1[v]++ : d2[v]++);

	}

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

		if (!d1[i] || !d2[i]) {

			q.push(i);

			mark[i] = true;

		}

	cnt = n;

	while (!q.empty()) {

		int v = q.front();

		q.pop();

		cnt--;

		for (auto u : adj[v]) {

			(a[v] == 'A' ? d1[u]-- : d2[u]--);

			if ((!d1[u] || !d2[u]) && !mark[u]) {

				mark[u] = true;

				q.push(u);

			}

		}

	}

	return cout << (cnt ? "Yes" : "No"), 0;

}

// Faster C++ solution for the same problem (measured speedup: 6.605678932960982x):
#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>

#define mp make_pair

#define pb push_back

#define fi first

#define se second

#define sz(a) int(a.size())

#define clr(a) memset(a,0,sizeof(a))

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

using namespace std;

typedef long long ll;

typedef unsigned long long ull;

typedef long double ld;

typedef pair<int,int> pii;

typedef pair<ll,int> pli;

const int inf=1e9;

const ll Inf=1e18;

const int N=2e5+10;

const int mod=0;

int gi() {

    int x=0,o=1;char ch=getchar();

    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();

    if(ch=='-') o=-1,ch=getchar();

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

    return x*o;

}

template<typename T> bool chkmax(T &a,T b) { return a<b?a=b,1:0; };

template<typename T> bool chkmin(T &a,T b) { return a>b?a=b,1:0; };

int add(int a,int b) { return a+b>=mod?a+b-mod:a+b; }

int sub(int a,int b) { return a-b<0?a-b+mod:a-b; }

void inc(int &a,int b) { a=(a+b>=mod?a+b-mod:a+b); }

void dec(int &a,int b) { a=(a-b<0?a-b+mod:a-b); }

int n,m,a[N],b[N],vis[N];

char s[N];

vector<int> E[N];

void adde(int u,int v) {

    s[v]=='A'?++a[u]:++b[u],E[v].pb(u);

    swap(u,v);

    s[v]=='A'?++a[u]:++b[u],E[v].pb(u);

}

int main() {

    n=gi(),m=gi(),scanf("%s",s+1);

    for(int i=1,u,v;i<=m;i++) u=gi(),v=gi(),adde(u,v);

    queue<int> q;

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

        //cerr<<a[i]<<" "<<b[i]<<endl;

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

    }

    while(!q.empty()) {

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

        for(int v:E[u]) {

            s[u]=='A'?--a[v]:--b[v];

            if((!a[v]||!b[v])&&!vis[v]) vis[v]=1,q.push(v);

        }

    }

    for(int i=1;i<=n;i++) if(!vis[i]) return puts("Yes"),0;

    puts("No");

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 6.552846075862845x):
#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>

typedef long long ll;

ll gi(){

	ll x=0,f=1;

	char ch=getchar();

	while(!isdigit(ch))f^=ch=='-',ch=getchar();

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

	return f?x:-x;

}

std::vector<int>G[200010];

int d[200010][2],del[200010],fa[200010];

char s[200010];

std::queue<int>que;

int hd(int x){return fa[x]==x?x:fa[x]=hd(fa[x]);}

void Union(int x,int y){

	x=hd(x),y=hd(y);

	if(x==y)puts("Yes"),exit(0);

	fa[x]=y;

}

int main(){

#ifdef XZZSB

	freopen("in.in","r",stdin);

	freopen("out.out","w",stdout);

#endif

	int n=gi(),m=gi(),a,b;

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

	while(m--)a=gi(),b=gi(),G[a].push_back(b),G[b].push_back(a),++d[a][s[b]-'A'],++d[b][s[a]-'A'];

	for(int i=1;i<=n;++i)if(!d[i][0]||!d[i][1])del[i]=1,que.push(i);

	while(!que.empty()){

		int x=que.front();que.pop();

		for(int i:G[x])if(!--d[i][s[x]-'A']&&!del[i])del[i]=1,que.push(i);

	}

	for(int i=1;i<=n;++i)if(!del[i])fa[i]=i;

	for(int i=1;i<=n;++i)if(!del[i])for(int j:G[i])if(!del[j]&&j>=i)Union(i,j);

	puts("No");

	return 0;

}




// Faster C++ solution for the same problem (measured speedup: 6.551878485615989x):
#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<cstdio>

#include<queue>

using namespace std;

const int MAXN = 200000;

const int MAXM = 2000000;

struct edge{

    int to;

    edge *nxt;

}edges[MAXM + 5], *adj[4*MAXN + 5], *ecnt = &edges[0];

char s[MAXN + 5];

void addedge(int u, int v) {

    edge *p = (++ecnt);

    p->to = v, p->nxt = adj[u], adj[u] = p;

}

int indeg[4*MAXN + 5];

int main() {

    int N, M;

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

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

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

        int a, b;

        scanf("%d%d", &a, &b);

        if( a == b ) {

            addedge(a+N, a+2*N);

            addedge(a+3*N, a);

        }

        else {

            if( s[a] == s[b] ) {

                addedge(a+N, b);

                addedge(b+N, a);

                addedge(a+3*N, b);

                addedge(b+N, a+2*N);

                addedge(b+3*N, a);

                addedge(a+N, b+2*N);

                addedge(a+3*N, b+2*N);

                addedge(b+3*N, a+2*N);

            }

            else {

                addedge(a, b+N);

                addedge(b, a+N);

                addedge(a+2*N, b+N);

                addedge(b, a+3*N);

                addedge(b+2*N, a+N);

                addedge(a+2*N, b+N);

                addedge(a+2*N, b+3*N);

                addedge(b+2*N, a+3*N);

            }

        }

    }

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

        for(edge *p=adj[i];p!=NULL;p=p->nxt)

            indeg[p->to]++;

    }

    queue<int>que;

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

        if( !indeg[i] ) que.push(i);

    int cnt = 0;

    while( !que.empty() ) {

        cnt++;

        int f = que.front(); que.pop();

        for(edge *p=adj[f];p!=NULL;p=p->nxt) {

            indeg[p->to]--;

            if( !indeg[p->to] ) que.push(p->to);

        }

    }

    if( cnt == 4*N ) puts("No");

    else puts("Yes");

}

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



const int N = 2e5 + 10;

const int M = 4e5 + 10;



int hd[N], nxt[M], to[M], cnt;

int deg[N][2];

int n, m;

char col[N];

int q[N], qhd, qtl, vis[N];



inline void adde(int x, int y) {

	cnt++;

	to[cnt] = y; nxt[cnt] = hd[x]; 

	hd[x] = cnt;

}



int main() {

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

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

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

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

		adde(x, y);

		adde(y, x);

		deg[x][col[y] == 'B']++;

		deg[y][col[x] == 'B']++;

	}

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

		if (deg[i][0] == 0 || deg[i][1] == 0) vis[q[qtl++] = i] = 1;

	}

	while (qhd != qtl) {

		int x = q[qhd++];

		// printf("%d\n", x);

		// vis[x] = 1;

		for (int i = hd[x]; i; i = nxt[i]) if (!vis[to[i]]) {

			if (--deg[to[i]][col[x] == 'B'] == 0) {

				vis[to[i]] = 1;

				q[qtl++] = to[i];

			} 

		}

	}

	if (qtl == n) puts("No");

	else puts("Yes");

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

using namespace std;



typedef pair<int, int> pii;

const int N = 2e5 + 100;



int n, m, u, v, d[N][2];

bool done[N];

string s;

queue<int> q;

vector<pii> nei[N];



int main() {

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

	cin >> n >> m >> s;

	while(m--) {

		cin >> u >> v;

		int c = (s[--u] == s[--v]);

		nei[u].push_back(pii(v, c));

		nei[v].push_back(pii(u, c));

	}

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

		for (pii p: nei[i])

			d[i][p.second]++;

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

		if(d[i][0] == 0 || d[i][1] == 0) {

			q.push(i);

			done[i] = true;

		}

	while(q.size()) {

		n--;

		v = q.front();

		q.pop();

		done[v] = true;

		for (pii p: nei[v]) {

			d[p.first][p.second]--;

			if(done[p.first] == false && (d[p.first][0] == 0 || d[p.first][1] == 0)) {

				done[p.first] = true;

				q.push(p.first);

			}

		}

	}

	cout << (n? "Yes": "No");

	return 0;

}

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

#define reg register

typedef long long ll;

using namespace std;

const int MN=2e5+5;

int deg[MN][2];

int n,m;

char ch[MN];

int to[MN<<1],nxt[MN<<1],h[MN],cnt;

inline void ins(int s,int t){

	to[++cnt]=t;nxt[cnt]=h[s];h[s]=cnt;

	to[++cnt]=s;nxt[cnt]=h[t];h[t]=cnt;

}

int que[MN],ta;

int main(){

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

	for(reg int i=1,s,t;i<=m;i++){

		scanf("%d%d",&s,&t);ins(s,t);

		deg[s][ch[t]-'A']++;deg[t][ch[s]-'A']++;

	}

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

		if(!deg[i][0]||!deg[i][1])que[++ta]=i;

	for(reg int i=1;i<=ta;i++)

		for(reg int j=h[que[i]];j;j=nxt[j])

			if(deg[to[j]][0]&&deg[to[j]][1]&&!(--deg[to[j]][ch[que[i]]-'A']))

				que[++ta]=to[j];

	puts(ta<n?"Yes":"No");

	return 0;

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

using namespace std;



const int N = 3e5 + 10;

string s;

int n, m, v, u, degA[N], degB[N], mark[N];

vector<int> adj_matrix[N], que;



int main(){

	ios::sync_with_stdio(false);

	cin.tie(0);cout.tie(0);

	

	cin >> n >> m;

	cin >> s;

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

		cin >> v >> u;

		v--;u--;

		

		if(v == u){

			adj_matrix[v].push_back(v);

			degA[v] += (s[v] == 'A');

			degB[v] += (s[v] == 'B');

		}

		else{

			adj_matrix[v].push_back(u);

			adj_matrix[u].push_back(v);

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

			degB[v] += (s[u] == 'B');

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

			degB[u] += (s[v] == 'B');

		}

		

	}

	

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

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

			que.push_back(i), mark[i] = true;

	

	int i = 0;

	while(que.size() < n && i < que.size()){

		int v = que[i];

		for (int j : adj_matrix[v]){

			if(mark[j])

				continue;

			degA[j] -= (s[v] == 'A');

			degB[j] -= (s[v] == 'B');

			

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

				que.push_back(j), mark[j] = true;

		}

		i++;

	}

	

	if(que.size() < n)

		cout << "Yes";

	else

		cout << "No";

}

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

#define reg register

typedef long long ll;

using namespace std;

const int MN=2e5+5;

int deg[MN][2];

int n,m;

char ch[MN];

int to[MN<<1],nxt[MN<<1],h[MN],cnt;

inline void ins(int s,int t){

	to[++cnt]=t;nxt[cnt]=h[s];h[s]=cnt;

	to[++cnt]=s;nxt[cnt]=h[t];h[t]=cnt;

}

int que[MN],ta;

int main(){

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

	for(reg int i=1,s,t;i<=m;i++){

		scanf("%d%d",&s,&t);ins(s,t);

		deg[s][ch[t]-'A']++;deg[t][ch[s]-'A']++;

	}

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

		if(!deg[i][0]||!deg[i][1])que[++ta]=i;

	for(reg int i=1;i<=ta;i++)

		for(reg int j=h[que[i]];j;j=nxt[j])

			if(deg[to[j]][0]&&deg[to[j]][1]&&!(--deg[to[j]][ch[que[i]]-'A']))

				que[++ta]=to[j];

	puts(ta<n?"Yes":"No");

	return 0;

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

using namespace std;

using ll = long long;



vector<int> g[212345];



int main() {

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

  int n, m; cin>>n>>m;

  string s;

  cin >> s;

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

    int a, b;

    cin >> a >> b; a--; b--;

    g[a].push_back(b);

    g[b].push_back(a);

  }

  vector<int> ok(n, 1);

  // vector<int> used(n);

  // int col = 1;

  function<void(int)> check = [&](int i) {

    if(!ok[i]) return;

    int f[2] = {};

    for(int j : g[i]) {

      if(ok[j]) f[s[j] == 'A']++;

    }

    if(!(f[0] && f[1])) ok[i] = 0;

    if(!ok[i]) {

      auto newg = g[i];

      for(int j : g[i]) {

        if(!ok[j]) continue;

        check(j);

        if(ok[j]) newg.push_back(j);

      }

      g[i] = newg;

    }

  };

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

  cout << (find((ok).begin(), (ok).end(), 1) != ok.end() ? "Yes" : "No") << endl;

  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 6.660649977037419x):
// includes {{{

#include<iostream>

#include<iomanip>

#include<algorithm>

#include<vector>

#include<stack>

#include<queue>

#include<map>

#include<set>

#include<tuple>

#include<cmath>

#include<random>

#include<cassert>

// #include<deque>

// #include<multiset>

// #include<bitset>

// #include<cstring>

// #include<bits/stdc++.h>

// }}}

using namespace std;

using ll = long long;



const int N = 2e5;

std::vector<std::vector<int>> g;

int n, m;

string s;



bool ok[N];



void check(int i) {

  if(!ok[i]) return;

  auto ng = g[i];

  ng.clear();

  int cntA = 0, cntB = 0;

  for(int j : g[i]) {

    if(ok[j]) {

      ng.push_back(j);

      if(s[j] == 'A') cntA++;

      else cntB++;

    }

  }

  g[i] = ng;

  if(!cntA || !cntB) {

    ok[i] = 0;

    for(int j : g[i]) {

      check(j);

    }

  }

}



int main() {

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

  cin >> n >> m;

  cin >> s;

  g.resize(n);

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

    int a, b; std::cin >> a >> b;

    a--; b--;

    g[a].emplace_back(b);

    g[b].emplace_back(a);

  }



  for(int i = 0; i < n; i++) ok[i] = 1;



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

    check(i);

  }



  bool ans = 0;

  for(int i = 0; i < n; i++) ans |= ok[i];



  cout << (ans ? "Yes" : "No") << endl;



  return 0;

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

#define gc() getchar()

using namespace std;

const int maxn=200010,maxm=400010;

int n,m,cnt,head[maxn];

struct edge{

    int from,to,next;

}edges[maxm];

char c[maxn];

bool sz[maxn];

inline bool check(int p){

    char hd;

    if(head[p]<0) return false;

    register int j;

    for(j=head[p];sz[edges[j].to];j=edges[j].next);

    if(j>=0) hd=c[edges[j].to];

    for(;j>=0;j=edges[j].next) if(!sz[edges[j].to]){

        if(c[edges[j].to]!=hd) return true;

    }

    return false;

}

inline void dfs(int p){

    sz[p]=true;

    for(register int j=head[p];j>=0;j=edges[j].next) if((!sz[edges[j].to])&&(!check(edges[j].to))) dfs(edges[j].to);

}

inline void gi (int &x){

    char c;

    for(c=gc();c<'0'||c>'9';c=gc());

    for(x=0;c<='9'&&c>='0';c=gc()) x=x*10+(c&15);

}

int main(){

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

    scanf("%s",c+1);int xx,yy;memset(head,-1,sizeof(head));

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

        gi(xx);gi(yy);

        edges[cnt]=(edge){xx,yy,head[xx]};

        head[xx]=cnt++;

        edges[cnt]=(edge){yy,xx,head[yy]};

        head[yy]=cnt++;

    }

    bool flag;//memset(sz,1,sizeof(sz));

    while(true){

        flag=true;

        for(register int i=1;i<=n;i++) if((!sz[i])&&(!check(i))){

            flag=false;dfs(i);

        }

        if(flag) break;

    }

    for(register int i=1;i<=n;i++) if(!sz[i]){

        printf("Yes\n");return 0;

    }

    printf("No\n");

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.8067688248092717x):
#pragma GCC optimize(3)

#include<cstdio>

#include<cstring>

#define gc() getchar()

using namespace std;

const int maxn=200010,maxm=400010;

int n,m,cnt,head[maxn];

struct edge{

    int from,to,next;

}edges[maxm];

char c[maxn];

bool sz[maxn];

inline bool check(int p){

    char hd;

    if(head[p]<0) return false;

    register int j;

    for(j=head[p];sz[edges[j].to];j=edges[j].next);

    if(j>=0) hd=c[edges[j].to];

    for(;j>=0;j=edges[j].next) if(!sz[edges[j].to]){

        if(c[edges[j].to]!=hd) return true;

    }

    return false;

}

inline void dfs(int p){

    sz[p]=true;

    for(register int j=head[p];j>=0;j=edges[j].next) if((!sz[edges[j].to])&&(!check(edges[j].to))) dfs(edges[j].to);

}

inline void gi (int &x){

    char c;

    for(c=gc();c<'0'||c>'9';c=gc());

    for(x=0;c<='9'&&c>='0';c=gc()) x=x*10+(c&15);

}

int main(){

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

    scanf("%s",c+1);int xx,yy;memset(head,-1,sizeof(head));

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

        gi(xx);gi(yy);

        edges[cnt]=(edge){xx,yy,head[xx]};

        head[xx]=cnt++;

        edges[cnt]=(edge){yy,xx,head[yy]};

        head[yy]=cnt++;

    }

    bool flag;//memset(sz,1,sizeof(sz));

    while(true){

        flag=true;

        for(register int i=1;i<=n;i++) if((!sz[i])&&(!check(i))){

            flag=false;dfs(i);

        }

        if(flag) break;

    }

    for(register int i=1;i<=n;i++) if(!sz[i]){

        printf("Yes\n");return 0;

    }

    printf("No\n");

    return 0;

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

using namespace std;



string kata;

int len;

int prefixsum[100005];

int tmp;



int main(){

	cin>>kata;

	int r = kata.length();

	len = r;

	int l = 1;

	while(l<r){

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

		

		memset(prefixsum, 0, sizeof(prefixsum));

		tmp =0;

		for(int i=0; i+mid <= len; i++){

			tmp += prefixsum[i];

			int nilpos = (kata[i] - '0') ^ (tmp & 1);

			if(nilpos){

				prefixsum[i+1] ++;

				prefixsum[i+mid] --;

			}

		}

		int sisa  = len - mid;

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

			tmp += prefixsum[i];

			int nilpos = (kata[i] - '0') ^ (tmp & 1);

			if(nilpos == 0) sisa = i;else break;

		}

		if(sisa+1 >= mid){

			l = mid;

		}else{

			r = mid -1;

		}

	}	

	cout<<l<<"\n";

}

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

#include <string.h>

#include <stdio.h>

#include <math.h>

#include <algorithm>

using namespace std;



int main()

{

   char s[2000005];

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

   int l=strlen(s+1);

   int n=l;

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

   {

       if(s[i]!=s[i+1])

       {

           n=min(n,max(i,l-i));

       }

   }

   cout<<n<<endl;

    return 0;

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

using namespace std;



string kata;

int len;

int prefixsum[100005];

int tmp;



int main(){

	cin>>kata;

	int r = kata.length();

	len = r;

	int l = 1;

	while(l<r){

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

		

		memset(prefixsum, 0, sizeof(prefixsum));

		tmp =0;

		for(int i=0; i+mid <= len; i++){

			tmp += prefixsum[i];

			int nilpos = (kata[i] - '0') ^ (tmp & 1);

			if(nilpos){

				prefixsum[i+1] ++;

				prefixsum[i+mid] --;

			}

		}

		int sisa  = len - mid;

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

			tmp += prefixsum[i];

			int nilpos = (kata[i] - '0') ^ (tmp & 1);

			if(nilpos == 0) sisa = i;else break;

		}

		if(sisa+1 >= mid){

			l = mid;

		}else{

			r = mid -1;

		}

	}	

	cout<<l<<"\n";

}

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

#include<string>

using namespace std;

int main()

{

    string S;

    cin>>S;

    int res=S.size();

    int a=S.size();

    for(int i=1; i<S.size(); i++)

    {

        if(S[i]!=S[i-1])

            res=min(res,max(i,a-i));

    }

    cout<<res<<endl;

    return 0;



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

using namespace std;



string kata;

int len;

int prefixsum[100005];

int tmp;



int main(){

	cin>>kata;

	int r = kata.length();

	len = r;

	int l = 1;

	while(l<r){

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

		

		memset(prefixsum, 0, sizeof(prefixsum));

		tmp =0;

		for(int i=0; i+mid <= len; i++){

			tmp += prefixsum[i];

			int nilpos = (kata[i] - '0') ^ (tmp & 1);

			if(nilpos){

				prefixsum[i+1] ++;

				prefixsum[i+mid] --;

			}

		}

		int sisa  = len - mid;

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

			tmp += prefixsum[i];

			int nilpos = (kata[i] - '0') ^ (tmp & 1);

			if(nilpos == 0) sisa = i;else break;

		}

		if(sisa+1 >= mid){

			l = mid;

		}else{

			r = mid -1;

		}

	}	

	cout<<l<<"\n";

}

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

#include <string>

#include <cstring>

using namespace std;



int main()

{

  char s[100000];

  cin>>s;

  int a[100000];

  int l=strlen(s);

  int ans=0;

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

  {

      if(s[i]!=s[i+1])

      {

          a[ans]=max(i+1,l-i-1);

          ans++;

      }

  }

  cout<<endl;

  int mini=l;

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

  {

    mini=min(mini,a[i]);

  }

  cout<<mini<<endl;

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

using namespace std;



string kata;

int len;

int prefixsum[100005];

int tmp;



int main(){

	cin>>kata;

	int r = kata.length();

	len = r;

	int l = 1;

	while(l<r){

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

		

		memset(prefixsum, 0, sizeof(prefixsum));

		tmp =0;

		for(int i=0; i+mid <= len; i++){

			tmp += prefixsum[i];

			int nilpos = (kata[i] - '0') ^ (tmp & 1);

			if(nilpos){

				prefixsum[i+1] ++;

				prefixsum[i+mid] --;

			}

		}

		int sisa  = len - mid;

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

			tmp += prefixsum[i];

			int nilpos = (kata[i] - '0') ^ (tmp & 1);

			if(nilpos == 0) sisa = i;else break;

		}

		if(sisa+1 >= mid){

			l = mid;

		}else{

			r = mid -1;

		}

	}	

	cout<<l<<"\n";

}

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



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



using namespace std;























int main() {

	string s;

	int ans;

	cin >> s;

	ans = sz(s);

	for (int i = 0; i < sz(s) - 1; i++)

		if (s[i] != s[i + 1])

			ans = min(ans, max(i + 1, sz(s) - i - 1));

	cout << ans;

	return 0;

}