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

#include <iostream>



using namespace std;



#define fo(i,CApiTaL_N) for(int i=0; i<CApiTaL_N; i++)

#define Fo(i,k,CApiTaL_N) for(int i=k; i<CApiTaL_N; i++)

#define ll long long

#define pb push_back

#define mp make_pair

#define F first

#define S second

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

#define tr(it, a) for(auto it=a.begin(); it!=a.end(); it++)

#define PI 3.1415926535897932384626

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

typedef vector<int> vi;

typedef vector<ll> vl;

typedef vector<pii> vpii;

typedef vector<pll> vpll;

typedef vector<vi> vvi;

typedef vector<vl> vvl;



int t=1;

const int mxW=1e5, mxN=1e2, mxV=1e9;

int n,w;

vl wi(mxN+1),v(mxN+1),dp(mxW+1);



void test_case(){

    cin>>n>>w;

    Fo(i,1,n+1){

        cin>>wi[i]>>v[i];

    }

    Fo(j,1,n+1){

        for(int i=w; i>=0; i--){

            if(i-wi[j]<0)continue;

            // cout<<i<<" "<<j<<" "<<dp[i]<<" "<<i-wi[j]<<" "<<dp[i-wi[j]]<<" "<<v[j]<<endl;

            dp[i]=max(dp[i],dp[i-wi[j]]+v[j]);

        }

    }

    cout<<dp[w]<<endl;

}



int main() {

    ios_base::sync_with_stdio(false);

	cin.tie(NULL);



    // cin>>t;

    while(t--){

        test_case();

    }

    

    return 0;

}

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

#include <bits/stdc++.h>



using namespace std;



using ll=long long;

const int INF = 1e9+5;



void max_self(ll &a, ll b){

    a=max(a,b);

}



int main() {

    ios_base::sync_with_stdio(0);

    cin.tie(NULL);



    int n,w;

    cin>>n>>w;

    vector<ll>dp(w+1);

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

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

        int wei, val;

        cin>>wei>>val;

        for(int curr=w-wei; curr>=0; curr--){

            max_self(dp[curr+wei],dp[curr]+(ll)val);

        }

    }

    cout<<dp[w]<<endl;



    return 0;

}

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

#define MAX 100005

using namespace std;

 

int main(){

  int n, mn = 0, t = 0, u = 0;

  string s;

  cin >> n >> s;

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

    t += (s[i-1] == 'W') + (s[i] == 'W') - 1;

    u += (s[i] == 'E');

    mn = min(mn, t);

  }

  printf("%d\n", u+mn);

}

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

#include <algorithm>

#define MAX 300005

using namespace std;



int main(){

    int n, mn = 0, t = 0, u = 0;

    char s[MAX];

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

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

        t += (s[i-1] == 'W') + (s[i] == 'W') - 1;

        u += (s[i] == 'E');

        mn = min(mn, t);

    }

    printf("%d\n", u+mn);

}

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



const int MAX_N = 300000;



int main() {

	int N;

	std::string S;

	std::cin >> N >> S;



	std::vector<int> left(MAX_N), right(MAX_N), cost(MAX_N);

	int cnt;



	cnt = 0;

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

		left[i] = cnt;

		if(S[i] == 'W') ++cnt;

	}



	cnt = 0;

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

		right[i] = cnt;

		cost[i] = left[i] + right[i];

		if(S[i] == 'E') ++cnt;

	}



	std::sort(cost.begin(), cost.begin() + N);



	std::cout << cost[0] << std::endl;

 }


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



const int MAX_N = 300000;



// int left[MAX_N], right[MAX_N], cost[MAX_N];



int main() {

	int N;

	std::string S;

	std::cin >> N >> S;



	// std::vector<int> left(MAX_N), right(MAX_N), cost(MAX_N);

	static int left[MAX_N], right[MAX_N], cost[MAX_N];

	int cnt;



	cnt = 0;

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

		left[i] = cnt;

		if(S[i] == 'W') ++cnt;

	}



	cnt = 0;

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

		right[i] = cnt;

		cost[i] = left[i] + right[i];

		if(S[i] == 'E') ++cnt;

	}



	// std::sort(cost.begin(), cost.begin() + N);

	std::sort(cost, cost + N);



	std::cout << cost[0] << std::endl;

 }

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

#include<cmath>

using namespace std;

int main()

{

	int n,ce=0,cw=0,an=1e9,a[300003];

	char c[300003];

	cin>>n;

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

	{

		cin>>c[i];

		a[i]=cw;

		if(c[i]=='W')cw++;

	}

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

	{

		an=min(an,a[i]+ce);

		if(c[i]=='E')ce++;

	}

	cout<<an<<endl;

	return 0;

}

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

int n,i,e,w,s=1e9,a[1<<19];char c[1<<19];main(){for(scanf("%d\n",&n);i<n;scanf("%c",c+i),a[i]=w,w+=c[i++]==87);for(;i>0;s=s<a[--i]+e?s:a[i]+e,e+=c[i]==69);printf("%d",s);}

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

#include<cmath>

using namespace std;

int main()

{

	int n,i=0,e=0,w=0,an=1e9,a[300003];

	char c[300003];

	cin>>n;

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

	{

		cin>>c[i];

		a[i]=w;

		w+=c[i]==87;

	}

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

	{

		an=min(an,a[i]+e);

		e+=c[i]==69;

	}

	cout<<an<<endl;

}

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

int n,i,e,w,s=1e9,a[1<<19];char c[1<<19];main(){for(scanf("%d\n",&n);i<n;scanf("%c",c+i),a[i]=w,w+=c[i++]==87);for(;i>0;s=s<a[--i]+e?s:a[i]+e,e+=c[i]==69);printf("%d",s);}

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

#include<cmath>

using namespace std;

int main()

{

	int n,i=0,e=0,w=0,an=1e9,a[300003];

	char c[300003];

	cin>>n;

	for(;i<n;)

	{

		cin>>c[i];

		a[i]=w;

		w+=c[i++]==87;

	}

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

	{

		an=min(an,a[i]+e);

		e+=c[i]==69;

	}

	cout<<an<<endl;

}

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

int n,i,e,w,s=1e9,a[1<<19];char c[1<<19];main(){for(scanf("%d\n",&n);i<n;scanf("%c",c+i),a[i]=w,w+=c[i++]==87);for(;i>0;s=s<a[--i]+e?s:a[i]+e,e+=c[i]==69);printf("%d",s);}

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

#include<cmath>

//using namespace std;

int n,i,e,w,s=1e9,a[1<<19];

char c[1<<19];

int main()

{

	for(std::cin>>n;i<n;std::cin>>c[i],a[i]=w,w+=c[i++]==87);

	for(;i>0;s=fmin(s,a[--i]+e),e+=c[i]==69);

	std::cout<<s<<std::endl;

}

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

int n,i,e,w,s=1e9,a[1<<19];char c[1<<19];main(){for(scanf("%d\n",&n);i<n;scanf("%c",c+i),a[i]=w,w+=c[i++]==87);for(;i>0;s=s<a[--i]+e?s:a[i]+e,e+=c[i]==69);printf("%d",s);}

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

#include "algorithm"

#include "string"

#include "vector"

#include "cmath"

#include "bitset"

#include "queue"

#include "functional"

#include "map"

#include "unordered_map"



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

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

#define mod 1000000007

#define sp ' '

#define intmax 2147483647

#define llmax 9223372036854775807

#define nya_n "(=^･ω･^=)"

typedef long long ll;

using namespace std;



/*

ll gcd(ll x, ll y) {

	if (y == 0) return x;

	return gcd(y, x%y);

}

ll lcm(ll x, ll y) {

	ll g = gcd(x, y);

	return x / g * y;

}*/



int h, w, pcnt;

char grid[52][52];

int cntgrid[52][52];



int main(){

	cin >> h >> w;

	pcnt = 0;

	lp(w+2) {

		grid[0][i] = '#';

		grid[h + 1][i] = '#';

	}

	lp(h) {

		grid[i + 1][0] = '#';

		grid[i + 1][w + 1] = '#';

	}

	lp(h) {

		LP(w, j) {

			cin >> grid[i + 1][j + 1];

			if (grid[i + 1][j + 1] == '.') {

				pcnt++;

			}

		}

	}

	lp(h + 2) {

		LP(w + 2, j) {

			cntgrid[i][j] = 1000000;

		}

	}

	cntgrid[1][1] = 1;

	lp(pcnt) {

		LP(h, j) {

			LP(w, k) {

				if (grid[j + 1][k + 1] == '.') {

					if (grid[j][k + 1] == '.') {

						cntgrid[j][k + 1] = min(cntgrid[j + 1][k + 1] + 1, cntgrid[j][k + 1]);

					}

					if (grid[j + 1][k] == '.') {

						cntgrid[j + 1][k] = min(cntgrid[j + 1][k + 1] + 1, cntgrid[j + 1][k]);

					}

					if (grid[j + 2][k + 1] == '.') {

						cntgrid[j + 2][k + 1] = min(cntgrid[j + 1][k + 1] + 1, cntgrid[j + 2][k + 1]);

					}

					if (grid[j + 1][k + 2] == '.') {

						cntgrid[j + 1][k + 2] = min(cntgrid[j + 1][k + 1] + 1, cntgrid[j + 1][k + 2]);

					}

				}

			}

		}

	}

	if(cntgrid[h][w]==1000000)

		cout << -1 << endl;

	else cout << pcnt - cntgrid[h][w] << endl;

	return 0;

}

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

using namespace std;



int H,W,g[50][50],cntp;

const int x[4]={0,0,1,-1};

const int y[4]={1,-1,0,0};

char s[50][50];

queue<pair<int,int>>q;



int main()

{

    cin>>H>>W;

    for(int i=0;i!=H;++i){

        for(int j=0;j!=W;++j){

            cin>>s[i][j];

            if(s[i][j]=='.')++cntp;

            g[i][j]=0xe869120;

        }

    }

    q.push(make_pair(0,0));

    g[0][0]=1;

    while(!q.empty()){

        for(int i=0;i!=4;++i){

            if(q.front().first+x[i]!=-1&&q.front().first+x[i]!=H&&q.front().second+y[i]!=-1&&q.front().second+y[i]!=W&&g[q.front().first+x[i]][q.front().second+y[i]]==0xe869120&&s[q.front().first+x[i]][q.front().second+y[i]]=='.'){

                g[q.front().first+x[i]][q.front().second+y[i]]=g[q.front().first][q.front().second]+1;

                q.push(make_pair(q.front().first+x[i],q.front().second+y[i]));

            }

        }

        q.pop();

    }

    if(g[H-1][W-1]==0xe869120)cout<<-1<<endl;

    else cout<<cntp-g[H-1][W-1]<<endl;

    return 0;

}

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

using namespace std;

#define inf 1000000000

#define INF 1000000000000000

#define ll long long

#define ull unsigned long long

#define M 1000000007

#define P pair<int,int>

#define PLL pair<ll,ll>

#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)

#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)

#define rep(i,n) FOR(i,0,n)

#define rrep(i,n) RFOR(i,n,0)

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

#define IN(a,n) rep(i,n){ cin>>a[i]; }

const int vx[4] = {0,1,0,-1};

const int vy[4] = {1,0,-1,0};

#define PI 3.14159265

#define F first

#define S second

#define int ll



int n,m;

string s[1000];

int r,t;



signed main(){

  cin>>n>>m;

  rep(i,n){

    cin>>s[i];

  }



  rep(i,n){

    rep(j,m){

      if(s[i][j]=='.') r++;

      else t++;

    }

  }



  queue<P> q;

  q.push(P(0,0));

  int c[1000][1000];

  rep(i,1000){

    rep(j,1000){

      c[i][j]=inf;

    }

  }

  c[0][0]=0;

  while(q.size()){

    int a=q.front().F;

    int b=q.front().S;

    q.pop();

    rep(i,4){

      int x=a+vx[i];

      int y=b+vy[i];

      if(!(0<=x&&x<m&&0<=y&&y<n))continue;

      if(s[y][x]=='#') continue;

      if(c[y][x]>c[b][a]+1){

        c[y][x] = c[b][a]+1;

        q.push(P(x,y));

      }

    }

  }



  if(c[n-1][m-1]==inf){

    cout<<-1<<endl;

    return 0;

  }



  cout<<r-1-c[n-1][m-1]<<endl;

}

// Optimized solution to the same problem (faster):


#include<bits/stdc++.h>

using namespace std;

#define inf 1000000000

#define INF 100000000000000

#define ll long long

#define ull unsigned long long

#define M (int)(1e9+7)

#define P pair<int,int>

#define PLL pair<ll,ll>

#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)

#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)

#define rep(i,n) FOR(i,0,n)

#define rrep(i,n) RFOR(i,n,0)

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

#define IN(a,n) rep(i,n){ cin>>a[i]; }

const int vx[4] = {0,1,0,-1};

const int vy[4] = {1,0,-1,0};

#define PI 3.14159265

#define F first

#define S second

#define PB push_back

#define EB emplace_back



int h,w;

char s[100][100];

int t[100][100];

int ans=0;

int main(){

  cin>>h>>w;

  rep(i,h){

    cin>>s[i];

    rep(j,w){

      t[i][j]=inf;

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

        ans++;

    }

  }

  t[0][0]=0;

  queue<P> q;

  q.push(P(0,0));

  while(!q.empty()){

    int a=q.front().F,b=q.front().S;

    q.pop();

    rep(i,4){

      int x=a+vx[i],y=b+vy[i];

      if(!(0<=x&&x<w&&0<=y&&y<h)) continue;

      if(s[y][x]=='.'&&t[y][x]>t[b][a]+1){

        t[y][x]=t[b][a]+1;

        q.push(P(x,y));

      }

    }

  }



  if(t[h-1][w-1]==inf)

    cout<<-1<<endl;

  else

    cout<<ans-1-t[h-1][w-1]<<endl;

}


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

#include <cstdlib>

#include <vector>

#include <queue>



using namespace std;

const int INFTY = (1 << 21);



int main(void){

    int H,W;

    cin >> H >> W;



    vector<vector<int> > map(H+2, vector<int>(W+2,'#'));

    vector<vector<int> > s(H*W, vector<int>(H*W, 0));

    vector<int> d(H*W, INFTY);

    char tmp;

    int white_count = 0;



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

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

            cin >> tmp;

            map[i][j] = tmp;

            if(tmp == '.') white_count++;

        }

    }



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

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

            int I = i-1, J = j-1;

            int index  = I*W + J;

            int index_nbh[4];

            index_nbh[0] = (I-1)*W + J; // up

            index_nbh[1] = (I+1)*W + J; // down

            index_nbh[2] = I*W + J-1;   // left

            index_nbh[3] = I*W + J+1;   // right



            if(map[i-1][j] == '.') s[index][index_nbh[0]] = 1;

            if(map[i+1][j] == '.') s[index][index_nbh[1]] = 1;

            if(map[i][j-1] == '.') s[index][index_nbh[2]] = 1;

            if(map[i][j+1] == '.') s[index][index_nbh[3]] = 1;

        }

    }





    queue<int> q;

    q.push(0);

    d[0] = 1;

    int u;

    while( !q.empty()){

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

        for(int v=1;v<(H+1)*(W+1);v++){

            if(s[u][v] == 0) continue;

            if(d[v] != INFTY) continue;

            d[v] = d[u] + 1;

            q.push(v);

        }

    }

    cout << (d[W*H-1] != INFTY ? white_count-d[W*H-1] : (-1) ) << endl;



    return 0;

}

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

#include <queue>



using namespace std;



const int INFTY = 1e9;

const int HMAX = 100;

const int WMAX = 100;



char grid[HMAX][WMAX];

int dist[HMAX][WMAX];

int di[] = {0,0,1,-1};

int dj[] = {1,-1,0,0};



int H,W;



int bfs(int sx, int sy, int gx, int gy){

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

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

            dist[i][j] = INFTY;

        }

    }



    dist[sx][sy] = 1;

    queue<pair<int,int> > Q;

    Q.push(make_pair(sx,sy));



    while(!Q.empty()){

        auto p = Q.front(); Q.pop();

        int x = p.first;

        int y = p.second;

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

            int nx = x + di[i];

            int ny = y + dj[i];

            if(nx < 1 || nx > H || ny < 1 || ny > W) continue;

            if(nx == gx && ny == gy) return dist[x][y] + 1;

            if(dist[nx][ny] == INFTY && grid[nx][ny] == '.'){

                dist[nx][ny] = dist[x][y] + 1;

                Q.push(make_pair(nx,ny));

            }

        }

    }

    return -1;

}



int main(){

    cin >> H >> W;

    int count = 0;

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

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

            cin >> grid[i][j];

            if(grid[i][j] == '.') count++;

        }

    }



    int ans = bfs(1,1, H,W);



    if(ans == -1){

        cout << -1 << endl;

    }else{

        cout << count - ans << endl;

    }

    return 0;

}

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

#define re return

#define ll long long

#define ld long double

#define f first

#define s second

#define pi acos(-1)

#define oo (int)1e9

#define OO (ll)1e18

#define EPS 1e-7

#define FX(n) fixed<<setprecision(n)

#define mm(o,k) memset(o,k,sizeof o)

#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);

using namespace std;

const int maxn=105;

int dx[]={0,0,1,-1};

int dy[]={1,-1,0,0};

int n,m;

char a[maxn][maxn];

map<pair<int,int>,pair<int,int> >p;

map<pair<int,int>,bool >vis;

bool valid(int i,int j){

    re(i>=0&&i<n&&j>=0&&j<m&&a[i][j]=='.');

}

int bfs(){

    int ans=0;

    queue<pair<int,int> >q;

    q.push({0,0});

    p[{0,0}]={-1,-1};

    bool done=false;

    while(q.size()){

        int x=q.front().f;

        int y=q.front().s;

        q.pop();

        if(x==n-1&&y==m-1){done=true;break;}

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

            int xx=x+dx[i],yy=y+dy[i];

            if(vis[{xx,yy}]||!valid(xx,yy))continue;

            vis[{xx,yy}]=true;

            p[{xx,yy}]={x,y};

            q.push({xx,yy});

        }

    }

    if(!done)re -1;

    pair<int,int> temp={n-1,m-1},hna={0,0};

    while(true){

        a[temp.f][temp.s]='#';

        if(temp==hna)break;

        temp=p[temp];

    }

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

        for(int j=0;j<m;++j)

            ans+=a[i][j]=='.';

    re ans;

}

int main()

{

    IO;

    cin >> n >> m;

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

        for(int j=0;j<m;++j)

            cin >> a[i][j];

    cout<<bfs()<<endl;

    re 0;

}

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

#define re return

#define ll long long

#define ull unsigned ll

#define ld long double

#define f first

#define s second

#define pi acos(-1)

#define oo (ll)1e9

#define OO (ll)1e18

#define EPS 1e-7

#define FX(n) fixed<<setprecision(n)

#define mm(o,k) memset(o,k,sizeof o)

#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);

using namespace std;

const int maxn=55;

int n,m;

char a[maxn][maxn];

int dx[]={0,0,1,-1};

int dy[]={1,-1,0,0};

bool vis[maxn][maxn];

bool valid(int x,int y){

    re (x>=0&&y>=0&&x<n&&y<m&&!vis[x][y]&&a[x][y]=='.');

}

int dot;

int bfs(){

    queue<pair<pair<int,int>,int> > q;

    q.push({{0,0},0});

    while(q.size()){

        int x=q.front().f.f;

        int y=q.front().f.s;

        int cost=q.front().s;

        q.pop();

        if(x==n-1&&y==m-1)re dot-(cost+1);

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

            int xx=x+dx[i],yy=dy[i]+y;

            if(valid(xx,yy)){

                q.push({{xx,yy},cost+1});

                vis[xx][yy]=true;

            }

        }

    }

    re -1;

}

int main(){

    IO;

    cin >> n >> m;

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

        for(int j=0;j<m;++j)

            cin >> a[i][j],dot+=a[i][j]=='.';

    cout<<bfs()<<endl;

    re 0;

}

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

#include <cstdio>

#include <algorithm>

#include <vector>



using namespace std;

int main()

{

    int n; cin >> n;

    string s; char t;

    cin >> t;

    s.push_back(t);

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

    {

        cin >> t;

        if( t == s.back() )

            continue;

        else s.push_back(t);

    }

    cout << s.size() << endl;

}

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



int main(){

long n = 0, result=0;

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

char s[n];



for(long i = 0; i<n; i++){scanf("%c", &s[i]);}



int temp=0;

for(long i = 0; i<n; ){

    while(1){

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

        temp=1;

        i++;

    }else{

        i++;

        break;}

    }

    if(temp){result+=temp;}else{result+=1;}

}

printf("%ld", result);

return 0;

}

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

#include<algorithm>

#include<string>

#include<cstring>

using namespace std;

int n;

string str;

int main()

{

	cin >> n;

	cin >> str;

	int ans = 1;

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

	{

		if (i != 0 && str[i] != str[i - 1])

			ans++;

	}

	cout << ans << endl;

	return 0;

}


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



int main(){

long n = 0, result=0;

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

char s[n];



for(long i = 0; i<n; i++){scanf("%c", &s[i]);}



int temp=0;

for(long i = 0; i<n; ){

    while(1){

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

        temp=1;

        i++;

    }else{

        i++;

        break;}

    }

    if(temp){result+=temp;}else{result+=1;}

}

printf("%ld", result);

return 0;

}

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

#define Mod 1000000007

#define eps 1e-6

#define ll long long

#define INF 0x3f3f3f3f

#define MEM(x, y) memset(x, y, sizeof(x))

#define Maxn 1000000 + 10

using namespace std;

int N;

string S;

int result=0;

int solve(int t)

{

    char o=S[t];

    while (t<N)

    {

        t++;

        if(S[t]!=o)

        {

            /* cout<<t<<" "<<S[t]<<endl; */

            result+=1;

            return t;

        }

    }  

    return t;

}

int main()

{

    cin>>N;

    cin>>S;

    int len=0;

    while (len<N)

    {

        len=solve(len);

    }

    

    cout<<result<<endl;

}


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



int main(){

long n = 0, result=0;

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

char s[n];



for(long i = 0; i<n; i++){scanf("%c", &s[i]);}



int temp=0;

for(long i = 0; i<n; ){

    while(1){

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

        temp=1;

        i++;

    }else{

        i++;

        break;}

    }

    if(temp){result+=temp;}else{result+=1;}

}

printf("%ld", result);

return 0;

}

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

#include<cstdio>

#include<algorithm>

using namespace std;

int main()

{

	int n,m=0;

	char a[100009];

	cin>>n;

	cin>>a;

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

	{

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

		{

			m++;

		}

	}

	cout<<m<<endl;

	return 0;

 } 

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



int main(){

long n = 0, result=0;

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

char s[n];



for(long i = 0; i<n; i++){scanf("%c", &s[i]);}



int temp=0;

for(long i = 0; i<n; ){

    while(1){

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

        temp=1;

        i++;

    }else{

        i++;

        break;}

    }

    if(temp){result+=temp;}else{result+=1;}

}

printf("%ld", result);

return 0;

}

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

using namespace std;



int main()

{

    long int n;

    int i,sum=0,temp;

    string s;

    cin >> n;

    cin >> s;

    temp=s[0];

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

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

            continue;

        else

        {

            temp=s[i+1];

            sum++;

        }





    }

    cout <<sum;



    return 0;

}

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



int main(){

long n = 0, result=0;

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

char s[n];



for(long i = 0; i<n; i++){scanf("%c", &s[i]);}



int temp=0;

for(long i = 0; i<n; ){

    while(1){

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

        temp=1;

        i++;

    }else{

        i++;

        break;}

    }

    if(temp){result+=temp;}else{result+=1;}

}

printf("%ld", result);

return 0;

}

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

using namespace std;

string s;

char a;

int n,cnt;

int main(){

	cin>>n>>s;

	a=s[0];

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

		if(s[i]!=a){

			cnt++;

			a=s[i];

		}

	}

	cout<<cnt+1<<endl;

	return 0;

}

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

#include <string.h>

int main ()

{

	long long int N,i,j,l;

	char S[1000000],a[1000000];

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

	a[0]=S[0];

	for(i=1,j=1;S[j]!='\0';j++)

	{

		

		if(a[i-1]==S[j])

		{

			continue;

		}

		else

		{

			a[i]=S[j];

			i++;

		}

		

	}

	l=strlen(a);

	printf("%lld",l);

	

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

	{

		a[i]='\0';

	}

	return 0;

	

}

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

using namespace std;

int main()

{

   int i,j,n,sz,cnt=1;

   string s;

   cin>>n>>s;

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

   {

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



      cnt++;

   }

   cout<<cnt<<endl;



   return 0;

}

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

#include <string.h>

int main ()

{

	long long int N,i,j,l;

	char S[1000000],a[1000000];

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

	a[0]=S[0];

	for(i=1,j=1;S[j]!='\0';j++)

	{

		

		if(a[i-1]==S[j])

		{

			continue;

		}

		else

		{

			a[i]=S[j];

			i++;

		}

		

	}

	l=strlen(a);

	printf("%lld",l);

	

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

	{

		a[i]='\0';

	}

	return 0;

	

}

// Fastest known solution for this problem: