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

#include<algorithm>

#include<cstring>

using namespace std;

const int N=4e5+10;

struct Ed{int fr,to,w;}E[N];

int f[N],n,Q,fa[N],cc;

long long Ans;

int cmp(const Ed&A,const Ed&B) {return A.w<B.w;}

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

void Work()

{

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

		f[i+1]=min(f[i+1],f[i]+2);

	f[0]=min(f[0],f[n-1]+2);

}

int main()

{

	cin>>n>>Q;

	memset(f,63,sizeof(f));

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

	{

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

		E[i]=(Ed){x,y,w};

		f[x]=min(f[x],w+1);

		f[y]=min(f[y],w+2);

	}

	cc=Q;Work();Work();

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

		E[++cc]=(Ed){i,i+1,f[i]};

	E[++cc]=(Ed){n-1,0,f[n-1]};

	sort(E+1,E+cc+1,cmp);

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

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

	{

		int fx=find(E[i].fr),fy=find(E[i].to);

		if(fx!=fy) Ans+=E[i].w,fa[fx]=fy;

	}

	cout<<Ans<<endl;

}


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

#include<set>

#include<cmath>

#include<ctime>

#include<queue>

#include<stack>

#include<cstdio>

#include<cstring>

#include<algorithm>

#define qmax(x,y) (x=max(x,y))

#define qmin(x,y) (x=min(x,y))

#define mp(x,y) make_pair(x,y)

using namespace std;

typedef long long ll;

typedef pair<int,int> pii;

inline int read(){

	int ans=0,fh=1;

	char ch=getchar();

	while(ch<'0'||ch>'9'){

		if(ch=='-') fh=-1;

		ch=getchar();

	}

	while(ch>='0'&&ch<='9')

		ans=ans*10+ch-'0',ch=getchar();

	return ans*fh;

}

const int maxn=2e5+100,inf=2e9;

struct node{

	int x,y,z;

}e[maxn<<1];

int n,a[maxn],m,q,fa[maxn];

ll Ans;

bool cmp(node x,node y){return x.z<y.z;}

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

int main(){

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

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

	n=read(),q=read();

	for(int i=0;i<n;i++) a[i]=inf;

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

		int x=read(),y=read(),z=read();

		e[++m]=(node){x,y,z};

		qmin(a[x],z+1),qmin(a[y],z+2);

	}

	for(int i=0;i<n;i++) qmin(a[i],a[(i-1+n)%n]+2);

	for(int i=0;i<n;i++) qmin(a[i],a[(i-1+n)%n]+2);

	for(int i=0;i<n;i++) e[++m]=(node){i,(i+1)%n,a[i]};

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

	sort(e+1,e+m+1,cmp);

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

		int x=getfa(e[i].x),y=getfa(e[i].y);

		if(x==y) continue;

		fa[x]=y,Ans+=e[i].z;

	}

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

	return 0;

}






















// Fastest known solution for this problem:
// Original C++ solution (slower):
// luogu-judger-enable-o2

#include<bits/stdc++.h>

using namespace std;

#define rep( i, s, t ) for( register int i = s; i <= t; ++ i )

#define re register

#define int long long

int read() {

	char cc = getchar(); int cn = 0, flus = 1;

	while(cc < '0' || cc > '9') {  if( cc == '-' ) flus = -flus;  cc = getchar();  }

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

	return cn * flus;

}

const int N = 2e5 + 5 ; 

int n, q, cnt, A[N], B[N], C[N], fa[N], b[N * 2] ; 

struct E {

	int x, y, z ; 

} e[N * 2];

bool cmp( E x, E y ) {

	return x.z < y.z ; 

} 

int fd( int x ) {

	return ( fa[x] == x ) ? x : fa[x] = fd(fa[x]) ;

}

signed main()

{

	n = read(), q = read() ; memset( b, 63, sizeof(b) ) ;

	rep( i, 1, q ) {

		A[i] = read() + 1, B[i] = read() + 1, C[i] = read() ; 

		e[++ cnt].x = A[i], e[cnt].y = B[i], e[cnt].z = C[i] ; 

		b[A[i]] = min( b[A[i]], C[i] + 1 ), b[A[i] + n] = min( C[i] + 1, b[A[i] + n] ),

		b[B[i]] = min( b[B[i]], C[i] + 2 ), b[B[i] + n] = min( C[i] + 2, b[B[i] + n] );

	}

	for( re int i = 2; i <= 2 * n; ++ i )

		b[i] = min( b[i - 1] + 2, b[i] ) ;

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

		e[++ cnt].x = i, e[cnt].y = ( i == n ) ? 1 : i + 1 , 

		e[cnt].z = min( b[i], b[i + n] ), fa[i] = i;

	sort( e + 1, e + cnt + 1, cmp ) ; int Ans = 0 ;

	rep( i, 1, cnt ) {

		int u = e[i].x, v = e[i].y ;

		u = fd(u), v = fd(v) ;

		if( u == v ) continue ; 

		Ans += e[i].z, fa[u] = v ;

	}

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

	return 0;

}


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



using namespace std;



#define ll long long

#define re register

#define gc getchar()

int read()

{

	re int x(0),f(1);re char ch(gc);

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

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

	return x*f;

}



const int N=2e5+10;



int n,q,m;



struct line {int u,v,w;}e[N<<1];

bool operator < (line a,line b){return a.w<b.w;}

int f[N],v[N];

int find(int x){return x==f[x]?x:f[x]=find(f[x]);}

ll ans;



int main()

{

    n=read(),q=read();

    memset(v,127,sizeof(v));

    while(q--)

    {

        int a=read()+1,b=read()+1,c=read();

        e[++m]=(line){a,b,c};

        v[a%n+1]=min(v[a%n+1],c+1);

        v[b%n+1]=min(v[b%n+1],c+2);

    }

    int pos(1);

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

        if(v[i]<v[pos])

            pos=i;

    for(int i=pos%n+1,j=pos;i!=pos;j=i,i=i%n+1)

        v[i]=min(v[i],v[j]+2);

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

        e[++m]=(line){i-1,i,v[i]};

    e[++m]=(line){1,n,v[1]};

    sort(e+1,e+1+m);

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

        f[i]=i;

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

    {

        int u=find(e[i].u),v=find(e[i].v);

        if(u==v) continue;

        ans+=e[i].w;f[u]=v;

    }

    cout<<ans<<'\n';

    return 0;

}

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

#include <algorithm>

#include <cctype>

#include <cstring>

#include <cstdio>



using namespace std;



#define M 800005

#define ll long long



int n, q, tot;

int fa[M];

ll ans, d[M];



struct Edge

{ int u, v; ll w; } e[M];



inline int read()

{

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

	while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }

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

	return x * f;

}



inline int findf(int x)

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



inline bool cmp1(Edge a, Edge b)

{ return a.w < b.w; }



inline void kruscal()

{

	sort(e + 1, e + 1 + tot, cmp1);

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

	{

		int uf = findf(e[i].u), vf = findf(e[i].v);

		if (uf == vf) continue;

		fa[uf] = vf; ans += e[i].w;

	}

}



int main()

{

	n = read(), q = read(); tot = q;

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

	memset(d, 0x3f3f3f3f, sizeof(d));

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

	{

		e[i].u = read(), e[i].v = read(); e[i].w = read();

		d[e[i].u] = min(d[e[i].u], e[i].w + 1);

		d[e[i].v] = min(d[e[i].v], e[i].w + 2);

	}



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

		d[i] = min(d[i], d[(i-1+n)%n] + 2);

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

		d[i] = min(d[i], d[(i-1+n)%n] + 2);



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

		e[++tot].u = i, e[tot].v = (i+1)%n, e[tot].w = d[i];



	kruscal();



	cout << ans<<endl;

	return 0;

}

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

using namespace std;



inline int read()

{

	int x=0,f=1,c=getchar();

	while(c<48) c=='-'&&(f=-1),c=getchar();

	while(c>47) x=x*10+c-'0',c=getchar();

	return x*f;

}



const int MAXN = 400005;

struct Edge {int u,v,w;} e[MAXN];

int fa[MAXN],f[MAXN];

int n,m,q;



inline int find(int x)

{return x^fa[x]?fa[x]=find(fa[x]):x;}



inline void merge(int x,int y)

{((x=find(x))^(y=find(y)))&&(fa[x]=y);}



int main(int argc,char const *argv[])

{

	n=read(); q=read();

	memset(f,0x3f,sizeof(f));

	for(int i=1,a,b,c; i<=q; ++i)

	{

		a=read()+1,b=read()+1,c=read();

		f[a%n+1]=min(f[a%n+1],c+1);

		f[b%n+1]=min(f[b%n+1],c+2);

		e[++m]=Edge{a,b,c};

	}

	int pos=1;

	for(int i=2; i<=n; ++i) if(f[i]<f[pos]) pos=i;

	for(int i=pos%n+1,j=pos; i!=pos; j=i,i=i%n+1)

		f[i]=min(f[i],f[j]+2);

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

		e[++m]=Edge{i,i+1,f[i+1]};

	e[++m]=Edge{n,1,f[1]};

	sort(e+1,e+m+1,[](Edge a,Edge b) {return a.w<b.w;});

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

	long long tot=0,ans=0;

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

	{

		int u=e[i].u,v=e[i].v,w=e[i].w;

		if(find(u)==find(v)) continue;

		++tot,ans+=w,merge(u,v);

		if(tot==n-1) break;

	}

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

	return 0;

}

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

#include <iostream>

#include <cstring>

#include <cstdlib>

#include <cstdio>

#include <vector>

#define itn int

#define reaD read

#define N 200001

using namespace std;



int n, Q, f[N], cnt, fa[N]; 

struct edge { int from, to, cost; bool operator < (const edge &p) const { return cost < p.cost; } } e[N << 2]; 



inline int read()

{

	int x = 0, w = 1; char c = getchar();

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

	while(c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); }

	return x * w;

}



inline void adde(int u, int v, int w) { e[++cnt] = (edge) { u, v, w }; }



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



long long Kruscal()

{

	sort(e + 1, e + cnt + 1); 

	long long ans = 0; 

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

	{

		int u = find(e[i].from), v = find(e[i].to), w = e[i].cost; 

		if(u == v) continue; 

		fa[u] = v; ans += w; 

	}

	return ans; 

}



int main()

{

	n = read(); Q = read();

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

	memset(f, 0x3f, sizeof(f)); 

	while(Q--)

	{

		int u = read() + 1, v = read() + 1, w = reaD();

		adde(u, v, w); 

		f[u] = min(f[u], w + 1); f[v] = min(f[v], w + 2); 

	}

	int pos = 1; 

	for(int i = 2; i <= n; i++) if(f[i] < f[pos]) pos = i; 

	for(int i = pos; i <= pos + n - 1; i++) f[i % n + 1] = min(f[i % n + 1], f[(i - 1) % n + 1] + 2); 

	for(int i = 1; i <= n; i++) adde(i, i % n + 1, f[i]);

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

	return 0;

}

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

#include<cstring>

#include<iostream>

#include<algorithm>

#define maxn 600000

#define inf 2e18

#define int long long

using namespace  std;

int newp=0,first[maxn+4]={0},st[maxn+4]={0},fa[maxn+4]={0}; 

struct edge{

	int l,r,w;

}e[maxn+4];

bool cmp(edge x,edge y){

	return x.w<y.w;

}

void add(int x,int y,int z){

	e[++newp]=(edge){y,first[x],z};

	first[x]=newp;

}

int find(int x){

	return x==fa[x]?x:fa[x]=find(fa[x]);

}

signed main(){

	int n,q;

	scanf("%lld%lld",&n,&q);

	int u,v,w;

	for(int i=0;i<n;i++)st[i]=inf;

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

		scanf("%lld%lld%lld",&u,&v,&w);

		e[++newp]=(edge){u,v,w};

		if(u==v)st[u]=min(st[u],w+1);

		st[u]=min(st[u],w+1);

		st[v]=min(st[v],w+2);

	}

	int ans=inf,re;

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

		st[i]=min(st[i],st[(i-1+n)%n]+2);

	}

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

		st[i]=min(st[i],st[(i-1+n)%n]+2);

	}

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

		if(st[i]<ans){

			ans=st[i];

			re=i;

		}

	/*for(int i=0;i<=(n-1);i++){

		int j=(re+i)%n;

		st[j]=min(st[j],ans);

		ans=min(st[j],ans);

		ans+=2;

	}*/

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

		e[++newp]=(edge){i,(i+1)%n,st[i]};

	sort(e+1,e+newp+1,cmp);

	int cnt=0,ret=0;

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

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

		int u=e[i].l,v=e[i].r;

		if(find(u)!=find(v)){

			fa[find(u)]=find(v);

			cnt++;

			ret+=e[i].w;

			if(cnt==n-1)break;

		}

	}

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

	return 0;

 }

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

# include <deque>

using namespace std;



string S;

int K;

deque<int> d;

int counter=0;

long long ans=0;

bool allsame=true;



int main()

{

    cin>>S;

    cin>>K;



    char current=S[0];



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

    {

        if (S[i]==current)

        {

            counter++;

        }



        else

        {

            d.push_back(counter);

            counter=1;

            current=S[i];

        }

    }



    d.push_back(counter);



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

    {

        if (d[i]>1)

        {

            ans=ans+(d[i]/2);

        }

    }



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

    {

        current=S[0];

        if (S[i]!=current)

        {

            allsame=false;

            break;

        }

    }



    if (allsame)

    {

        ans=1ll*K*S.size()/2;



    }



    else if (d.front()%2==1 && d.back()%2==1 && S[0]==S[S.size()-1])

    {

        ans=ans*K;

        ans=ans+K-1;

    }



    else

    {

        ans=ans*K;

    }



    cout<<ans<<endl;

}

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

#include<cstring>

using namespace std;



char s[102];

int a[101];

int main(){

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

	int n=strlen(s+1),k;

	scanf("%d",&k);

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

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

			a[++a[0]]=i-o+1;

			o=i+1;

		}

	}

	long long ans=0;

	if(s[1]==s[n]){

		if(a[0]==1)ans=1ll*n*k/2;

		else{

			for(int i=2;i<a[0];i++)

				ans+=1ll*a[i]/2*k;

			ans+=a[1]/2+a[a[0]]/2;

			ans+=1ll*(a[1]+a[a[0]])/2*(k-1);

		}

	}

	else for(int i=1;i<=a[0];i++)

		ans+=1ll*a[i]/2*k;

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

}


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

using namespace std;



int main()

{

	long long k;

	string s;

	cin >> s >> k;

	long long sum = 0;

	int slen,elen,len = s.length(),cha = 0,tmplen = 1;

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

		if(s[i] == s[i - 1]){

			tmplen++;

		}

		else{

			if(cha == 0){

				slen = tmplen;

				tmplen = 1;

				cha++;

			}

			else{

				sum = sum + (tmplen / 2);

				tmplen = 1;

			}

		}

	}

	int tmp;

	long long ans = 0;

	if(s[len - 1] == s[0]){

		if(cha == 0){

			ans = (k / 2) * (tmplen) + k % 2 * (tmplen / 2);

		}

		else if(slen %  2 == 1 || tmplen % 2 == 1){

			ans = (k - 1) * ((slen + tmplen) / 2) + k * sum + slen / 2 + tmplen / 2;

		}

		else{

			ans = k * (sum + slen / 2 + tmplen / 2);

		}

	}

	else{

		ans = k * (sum + slen / 2 + tmplen / 2);

	}

	cout << ans << endl;

	return 0;

}

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

#include <string.h>

int main()

{

	char str[102];

	long long k;

	scanf("%s %lld",str,&k);

	char c=str[0];

	int len=strlen(str);

	long long t=0;

	int pre=0;

	int jian=0;

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

	if(str[i]!=str[i+1]) jian++;

	if(jian){

	

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

	{	

		

		if(str[i]==str[i-1]) pre++;

		else {

			pre++;

			pre/2==0?pre:pre-1;

			t=t+pre/2;

			pre=0;

		}

	}

	if(str[len-1]!=str[0]) t=t*k;

	else{

		int x=0,y=0;

		for(int i=0;str[i]==str[0];i++)

		x++;

		for(int j=len-1;str[len-1]==str[j];j--)

		y++;

		if(x%2!=0&&y%2!=0) t=t*k+k-1;

		else t=t*k;

	}

}

else {

	t=len*k;

	if(t%2==0) t=t/2;

	else t=(t-1)/2;

}

	printf("%lld",t);

	return 0;

	

}

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

#include <string>

using namespace std;



long long solve(string S) {

	long long cnt = 0, ret = 0;

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

		cnt++;

		if (i == (int)S.size() - 1 || S[i] != S[i + 1]) {

			ret += cnt / 2;

			cnt = 0;

		}

	}

	return ret;

}



int main() {

	string T; cin >> T;

	long long K; cin >> K;



	bool flag = true;

	for (int i = 0; i < (int)T.size() - 1; i++) {

		if (T[i] != T[i + 1]) flag = false;

	}



	if (flag == true) {

		long long len = 1LL * (long long)(T.size()) * K;

		cout << len / 2LL << endl;

	}

	else {

		string V1 = T;

		string V2 = T + T;

		long long R1 = solve(V1);

		long long R2 = solve(V2);

		cout << R1 + (R2 - R1) * (K - 1LL) << endl;

	}

	return 0;

}

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

#include <string.h>

int main()

{

	char str[102];

	long long k;

	scanf("%s %lld",str,&k);

	char c=str[0];

	int len=strlen(str);

	long long t=0;

	int pre=0;

	int jian=0;

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

	if(str[i]!=str[i+1]) jian++;

	if(jian){

	

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

	{	

		

		if(str[i]==str[i-1]) pre++;

		else {

			pre++;

			pre/2==0?pre:pre-1;

			t=t+pre/2;

			pre=0;

		}

	}

	if(str[len-1]!=str[0]) t=t*k;

	else{

		int x=0,y=0;

		for(int i=0;str[i]==str[0];i++)

		x++;

		for(int j=len-1;str[len-1]==str[j];j--)

		y++;

		if(x%2!=0&&y%2!=0) t=t*k+k-1;

		else t=t*k;

	}

}

else {

	t=len*k;

	if(t%2==0) t=t/2;

	else t=(t-1)/2;

}

	printf("%lld",t);

	return 0;

	

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#pragma warning(disable:4996)

#include<iostream>

#include<cstdio>

#include<cmath>

#include<string>

using namespace std;



int main()

{

	string s;

	int k;

	cin >> s;

	scanf("%d", &k);

	int len = s.length();

	long long ans = 0,cnt=1,cnt1=1,flag=0;

	s += '!';

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

	{

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

		{

			cnt++;

			if (!flag)

			{

				cnt1++;

			}

		}

		else

		{

			ans += cnt / 2;

			flag = 1;

			if (i != len - 1)

			{

				cnt = 1;

			}

		}

	}

	if (cnt == len)

	{

		ans = 1ll*len*k/2;

	}

	else

	{

		ans *= k;

		if (cnt % 2 && cnt1 % 2 && s[0] == s[len - 1])

		{

			ans += k - 1;

		}

	}

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

	//system("pause");

	return 0;

}


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

#include <string.h>

int main()

{

	char str[102];

	long long k;

	scanf("%s %lld",str,&k);

	char c=str[0];

	int len=strlen(str);

	long long t=0;

	int pre=0;

	int jian=0;

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

	if(str[i]!=str[i+1]) jian++;

	if(jian){

	

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

	{	

		

		if(str[i]==str[i-1]) pre++;

		else {

			pre++;

			pre/2==0?pre:pre-1;

			t=t+pre/2;

			pre=0;

		}

	}

	if(str[len-1]!=str[0]) t=t*k;

	else{

		int x=0,y=0;

		for(int i=0;str[i]==str[0];i++)

		x++;

		for(int j=len-1;str[len-1]==str[j];j--)

		y++;

		if(x%2!=0&&y%2!=0) t=t*k+k-1;

		else t=t*k;

	}

}

else {

	t=len*k;

	if(t%2==0) t=t/2;

	else t=(t-1)/2;

}

	printf("%lld",t);

	return 0;

	

}

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

#define INF 9999999;

using namespace std;

inline int read() {

	char c = getchar(); int x = 0, f = 1;

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

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

	return x * f;

}

stack<char>Q;

string ss;

char s;

map<char,int>mp; 

int tot=0,num=0,t;

int main()

{

	cin>>ss;

	int i=0;

	int j=ss.size()-1;

	while(i<=j)

	 {

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

	 	 {

	 	 	i++;

	 	 	j--;

	 	 	continue;

		 }

		if(ss[i]=='x')

		 {

		 	i++;

		 	tot++;

		 	continue;

		 }

		if(ss[j]=='x')

		 {

		 	j--;

		 	tot++;

		 	continue;

		 }

		else{

		cout<<"-1\n";

		return 0;

	   }

	 }

	cout<<tot<<'\n';

	return 0;

}

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

#include <string.h>

#define N 100001



char s[N];



int main() 

{

	int i, j, ti, tj, ans = 0, x, y;

	

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

	i = 0, j = strlen(s + 1) + 1;

	while(i < j){

		for(ti = i + 1; ti < j && s[ti] == 'x'; ti++);

		if(ti == j) break;

		for(tj = j - 1; s[tj] == 'x'; tj--);

		if(s[ti] != s[tj]){

			puts("-1");

			return 0;

		}

		x = ti - i, y = j - tj;

		if(y > x) ans += y - x;

		else ans += x - y;

		i = ti, j = tj;

	}

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

			

	return 0;

}

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

#include <stdio.h>

#include <stdlib.h>

#include <algorithm>

#include <cmath>

#include <climits>

#include <vector>

#include <queue>

#include <cstring>

#include <iterator>

#include <list>

#include <set>

#include <map>

#include <bitset>

using namespace std;



typedef long long LL;

int main()

{

    LL N, K;

    cin >> N >> K;



    map<LL, LL> freq;

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

        LL a, b;

        cin >> a >> b;

        if(!freq.count(a))

            freq[a] = 0;

        freq[a] += b;

    }



    map<LL, LL>::iterator it;

    LL k = 1;

    for (it = freq.begin(); k <= K && it != freq.end(); it++) {

        k += it->second;

    }

    it--;

    cout << it->first << endl;

}

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

#include<stdlib.h>

struct node

{

	long long a;

	long long b;

}num[100005];

int inc(const void *a, const void *b)

{

    struct node m = *(struct node *)a;

    struct node n = *(struct node *)b;

    return m.a - n.a;

}

int main()

{

	int n;

	long long k;

	scanf("%d%lld",&n,&k);

	for(int i=0;i<n;i++)scanf("%d%d",&num[i].a,&num[i].b);

	qsort(num,n,sizeof(struct node),inc);

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

	{

		k-=num[i].b;

		if(k<=0)

		{

			printf("%lld\n",num[i].a);

			return 0;

		}

	}

}

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

#include <algorithm>

using namespace std;



typedef long long ll;

const int N = 1e5+10;

struct node{

	ll a;

	ll b;

}p[N];



bool cmp(node a,node b)

{

	return a.a<b.a;

}

int main()

{

	ll n,k;

	cin>>n>>k;

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

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

	sort(p,p+n,cmp);

	ll i;

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

		if(k<=0)

			break;

		else

			k-=p[i].b;

	cout<<p[i-1].a<<endl;

	return 0;

}

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

#include<stdlib.h>

struct node

{

	long long a;

	long long b;

}num[100005];

int inc(const void *a, const void *b)

{

    struct node m = *(struct node *)a;

    struct node n = *(struct node *)b;

    return m.a - n.a;

}

int main()

{

	int n;

	long long k;

	scanf("%d%lld",&n,&k);

	for(int i=0;i<n;i++)scanf("%d%d",&num[i].a,&num[i].b);

	qsort(num,n,sizeof(struct node),inc);

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

	{

		k-=num[i].b;

		if(k<=0)

		{

			printf("%lld\n",num[i].a);

			return 0;

		}

	}

}

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

#include<cstdio>

#include<algorithm>

#include<cmath>

#include<string.h>

using namespace std;

const int manx=1e5+5;

struct node{

	int a;

	int b;

}str[100005];

bool cmp(node x,node y)

{

	return x.a<y.a;

}

int main()

{

	long long n,k;

	long long a,b;

	long long s[100005];

	long long sum=0;

	long long flag=0;

	long long ans;

	scanf("%lld %lld",&n,&k);

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

	{

		scanf("%d %d",&str[i].a,&str[i].b);

	}

	sort(str,str+n,cmp);

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

	{

		sum+=str[i].b;

		if(sum<k)

		{

			continue;

		}

		else

		{

			if(flag)

			{

				continue;

			 } 

			ans=str[i].a;

			flag=1;

		}

	}

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

	 return 0;

 } 

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

#include<stdlib.h>

struct node

{

	long long a;

	long long b;

}num[100005];

int inc(const void *a, const void *b)

{

    struct node m = *(struct node *)a;

    struct node n = *(struct node *)b;

    return m.a - n.a;

}

int main()

{

	int n;

	long long k;

	scanf("%d%lld",&n,&k);

	for(int i=0;i<n;i++)scanf("%d%d",&num[i].a,&num[i].b);

	qsort(num,n,sizeof(struct node),inc);

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

	{

		k-=num[i].b;

		if(k<=0)

		{

			printf("%lld\n",num[i].a);

			return 0;

		}

	}

}

// Fastest known solution for this problem:
// Original C++ solution (slower):


///╔══╗

///╚╗╔╝

///╔╝╚(¯`v´¯)

///╚══╝`.¸.´farzin





#include <bits/stdc++.h>



#define int int64_t

#define pb push_back

#define ibsws ios_base::sync_with_stdio

#define gcd __gcd

#define S second

#define F first



using namespace std;



int t,x,y,n,k;

multiset<pair<int,int> > a;



int32_t main(){

	ibsws(true==false);

    cin>>n>>k;

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

        cin>>x>>y;

        a.insert({x,y});

    }

    multiset<pair<int,int> >::iterator it=a.begin();

    while(t<k){

        t+=(*it).S;

        x=(*it).F;

        it++;

    }

    cout<<x;

}


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

#include<stdlib.h>

struct node

{

	long long a;

	long long b;

}num[100005];

int inc(const void *a, const void *b)

{

    struct node m = *(struct node *)a;

    struct node n = *(struct node *)b;

    return m.a - n.a;

}

int main()

{

	int n;

	long long k;

	scanf("%d%lld",&n,&k);

	for(int i=0;i<n;i++)scanf("%d%d",&num[i].a,&num[i].b);

	qsort(num,n,sizeof(struct node),inc);

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

	{

		k-=num[i].b;

		if(k<=0)

		{

			printf("%lld\n",num[i].a);

			return 0;

		}

	}

}

// Fastest known solution for this problem: