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

#include <cmath>

#include <cstring>



using namespace std;



int pedras[100100];

long long dp[100100]; ///Guardo os valores da funcao frog;



int n,k;

const int inf =1e9;



int frog2(int i,int j){



    if(dp[i] != -1){

        return dp[i];

    }



    int menor = inf;



    if(i>=j) return dp[i]=0;



    for(int x=1;x<=k;x++){ ///i=0; i=1;i=2;i=3;

        if(i+x <= j){      ///x=1, x=1;x=1;x=1;

            long long cost = (frog2(i+x,j)+ abs(pedras[i]-pedras[i+x]));



            if(cost < menor){

                menor = cost;

            }

        }

    }



    return dp[i] = menor;

}



int main(){



    memset(dp,-1,sizeof(dp));



    cin >>n>>k;



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

        cin >> pedras[i];

    }



    cout<<frog2(0,n-1)<<endl;

}


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

#include <algorithm>

#include <cmath>

#include <cstring>



using namespace std;



int pedras[100100];

int dp[100100]; ///Guardo os valores da funcao frog;



int n,k;

const int inf =1000000/*1e9*/;



int main(){



    memset(dp,inf,sizeof(dp));

    cin >>n>>k;



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

        cin >> pedras[i];

    }



    ///Comeca aki a bagaca

    dp[n-1]=0;



    for(int i=n-2;i>=0;i--){



        ///int menor=inf;



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

            if(i+j<=n-1){

                int cost = abs(pedras[i]-pedras[i+j]);

                dp[i]=min(dp[i],dp[i+j]+cost);

                /*menor = min(menor,dp[i+j]+cost);*/

            }

        }



        ///dp[i]=menor;

    }



    cout<<dp[0];



}


// Fastest known solution for this problem:
#include <iostream>

#include <array>

#include <vector>

#include <iomanip>

#include <string>

#include <cmath>

#include <array>

#include <algorithm>

#include <queue>

#include <map>

using namespace std;



typedef  pair<int,int> P;

typedef long long LL;



const LL  INF=1<<31;







int main(){

     int n,k;

     cin>>n>>k;

     int h[100000];

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

          cin>>h[i];

     }

     LL dp[100001];



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

           dp[i]=INF;

      }

            dp[0]=0;

            dp[1]=abs(h[0]-h[1]);







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

          dp[i]=dp[i-1]+abs(h[i-1]-h[i]);

          for(int j=2;j<=k;++j){



               if(j<=i)dp[i]=min(dp[i],dp[i-j]+abs(h[i-j]-h[i]));

          }

     }     



     cout<<dp[n-1]<<endl;





}
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define endl '\n'

using namespace std;



int h[100005], dp[100005], n, k;



int go(int idx){

    //cout << idx << endl;

    if(idx == n-1)return 0;

    if(dp[idx] != -1)return dp[idx];

    int ans = 1e9 + 7;

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

        if(idx + j < n){

            ans = min(ans, go(idx+j) + abs(h[idx]-h[idx+j]));

        }

    }

    return dp[idx] = ans;

}



int main(){

    ios_base::sync_with_stdio(false); cin.tie(NULL);

    cin >> n >> k;

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

        cin >> h[i];

    }

    /*

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

        dp[i] = dp[i-1] + abs(h[i] - h[i-1]);

        for(int j = 2; j <= k && (i-j) >= 0; j++){

            dp[i] = min(dp[i], dp[i-j] + abs(h[i-j] - h[j]));

        }

    }

    cout << dp[n-1] << endl;*/

    memset(dp, -1, sizeof dp);

    cout << go(0) << endl;

    return 0;

}

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

#define endl '\n'

using namespace std;



int h[100005], dp[100005], n, k;



int go(int idx){

    //cout << idx << endl;

    if(idx == n-1)return 0;

    if(dp[idx] != -1)return dp[idx];

    int ans = 1e9 + 7;

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

        if(idx + j < n){

            ans = min(ans, go(idx+j) + abs(h[idx]-h[idx+j]));

        }

    }

    return dp[idx] = ans;

}



int main(){

    ios_base::sync_with_stdio(false); cin.tie(NULL);

    cin >> n >> k;

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

        cin >> h[i];

    }

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

        dp[i] = dp[i-1] + abs(h[i] - h[i-1]);

        for(int j = 2; j <= k; j++){

            if(i-j >= 0){

                dp[i] = min(dp[i], dp[i-j] + abs(h[i-j] - h[i]));

            }

        }

    }

    cout << dp[n-1] << endl; /*

    memset(dp, -1, sizeof dp);

    cout << go(0) << endl;*/

    return 0;

}

// Fastest known solution for this problem:
#include <iostream>

#include <array>

#include <vector>

#include <iomanip>

#include <string>

#include <cmath>

#include <array>

#include <algorithm>

#include <queue>

#include <map>

using namespace std;



typedef  pair<int,int> P;

typedef long long LL;



const LL  INF=1<<31;







int main(){

     int n,k;

     cin>>n>>k;

     int h[100000];

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

          cin>>h[i];

     }

     LL dp[100001];



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

           dp[i]=INF;

      }

            dp[0]=0;

            dp[1]=abs(h[0]-h[1]);







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

          dp[i]=dp[i-1]+abs(h[i-1]-h[i]);

          for(int j=2;j<=k;++j){



               if(j<=i)dp[i]=min(dp[i],dp[i-j]+abs(h[i-j]-h[i]));

          }

     }     



     cout<<dp[n-1]<<endl;





}
// Original C++ solution (slower):
#include<iostream>

#include<algorithm>

#include<cstring>

#include<cmath>

#include<iomanip>

#include<string>

using namespace std;

int main(){

    long long int k,x,a;

    cin>>k>>x;

    for(int i=1;i<=(2*k-1);i++)

 {a=x-k+i;

 cout<<a<<" ";

 }

 cout<<endl;

    return 0;



}




// Optimized solution to the same problem (faster):
///d. one clue

#include <stdio.h>

#include <math.h>



int main()

{

    int k,x;

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



    for(int i=x-k+1;i<=x+k-1;i++){

        printf("%d ",i);

    }

    return 0;

}

// Fastest known solution for this problem:
#include <bits/stdc++.h>

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

using namespace std;



int main(void) {

	int k, x;

	cin >> k >> x;

	for (int i = x-k+1; i < x+k; i++) {

		if (i == x+k) cout << i << endl;

		else cout << i << " ";

	}

	return 0;

}
// Original C++ solution (slower):
#include<iostream>

#include<cstdio>

using namespace std;

long long a[100007];

int n,m;long long ans;

int main()

{

	cin>>n;

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

	{

	int x;

	scanf("%d",&x);

	++a[x];

	ans+=x;

	}

	cin>>m;

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

	{

		long long x,y;

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

		ans+=(y-x)*a[x];

		a[y]+=a[x];

		a[x]=0;

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

	}

	return 0;

	

}

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

#include <cstring>

#include <algorithm>

using namespace std; 

typedef long long LL;

const int MAXN=1E5+10;

int f[MAXN],sum[MAXN],tong[MAXN],a[MAXN];

long long sumans;



int main() {

	int N,K;

	scanf("%d",&N);

	sumans=0;

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

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

		sumans+=a[i];

		tong[a[i]]+=1;

	}

	scanf("%d",&K);

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

		int b,c;scanf("%d%d",&b,&c);

		sumans-=1ll*tong[b]*b;

		sumans+=1ll*tong[b]*c;

		

		tong[c]+=tong[b];

		tong[b]=0;

		

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

	}

	

	return 0;

} 

// Fastest known solution for this problem:
#include<bits/stdc++.h>

using namespace std;

#define ll long long

#include <string>

const int mxN=1e5;

const int maxN=5e3;

#define ld long double

#define pb push_back

#define mp make_pair

#define ins insert

#define vi vector<int>



int main()

{

    int n;

    cin >> n;

    int cnt[100000]={};

    ll s=0;

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

    {

        int x;

        cin >> x;

        cnt[x-1]++;

        s+=x;

    }

    int q;

    cin >> q;

    while(q--)

    {

        int b,c;

        cin >> b >> c;

        s+=cnt[b-1]*(c-b);

        cnt[c-1]+=cnt[b-1];

        cnt[b-1]=0;

        cout << s << "\n";

    }

}
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef long long int lli;

typedef long double ld;

const int oo = 1e9;

const int mod = 1e9+9;



const int yu = 1e5+103;

int n, k;

int dp[yu];

int a[yu];

int f(int i){

	if (i==n-1) return 0;

	if(dp[i]!=-1) return dp[i];

	int pqr = abs(a[i]-a[i+1])+f(i+1);

	for(int j=2; j<=k; j++){

		if(i+j<n) pqr = min(pqr, abs(a[i]-a[i+j])+f(i+j));

	}

	return dp[i]=pqr;

}

int main(){

	cin>>n>>k;

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

	memset(dp, -1, sizeof dp);

	cout<<f(0)<<endl;

	return 0;

}


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

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

#define files freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);

using namespace std;

typedef long long ll;



const int N = 1e5;



int arr[N], memo[N], n, k;



int dp() {

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

		memo[i] = 1e9;

	memo[1] = abs(arr[0] - arr[1]);

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

		for(int j = i - 1; j >= max(0, i - k); --j)

			memo[i] = min(memo[i], abs(arr[i] - arr[j]) + memo[j]);

	return memo[n - 1];

}



int main() {

    Data_Nerd



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



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

    	scanf("%d", arr + i);



    cout << dp();



    return 0;

}


// Fastest known solution for this problem:
#include <iostream>

#include <array>

#include <vector>

#include <iomanip>

#include <string>

#include <cmath>

#include <array>

#include <algorithm>

#include <queue>

#include <map>

using namespace std;



typedef  pair<int,int> P;

typedef long long LL;



const LL  INF=1<<31;







int main(){

     int n,k;

     cin>>n>>k;

     int h[100000];

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

          cin>>h[i];

     }

     LL dp[100001];



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

           dp[i]=INF;

      }

            dp[0]=0;

            dp[1]=abs(h[0]-h[1]);







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

          dp[i]=dp[i-1]+abs(h[i-1]-h[i]);

          for(int j=2;j<=k;++j){



               if(j<=i)dp[i]=min(dp[i],dp[i-j]+abs(h[i-j]-h[i]));

          }

     }     



     cout<<dp[n-1]<<endl;





}
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

#define ll long long

ll N,K;

ll h[100010];

ll dp[100010];

ll call(int i)

{

    if(i==N) return 0;

    

    if(dp[i]!=-1) return dp[i];

    

    dp[i]=abs(h[i+1]-h[i]) + call(i+1);

    for(ll j=2;j<=K;j++)

    {

        if(i+j<=N)

    dp[i]=min(dp[i],abs(h[i+j]-h[i]) + call(i+j));

        else break;

    

        

    }

    return dp[i];

}

int main()

{

    cin>>N>>K;

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

    {

        cin>>h[i];

    }

    memset(dp,-1,sizeof(dp));

    cout<<call(1);

}

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

 

using namespace std;

 

int main() {

    int N,K;

    cin>>N>>K;

    if(N==1)

    {

        cout<<0;

        return 0;

    }

    int h[N];

    

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

    {

        cin>>h[i];

    }

    

    int val[N];

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

  {

    val[i]=INT_MAX;

  }

    val[0]=0;

    

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

    {

        for(int j=i-1;j>=0 && i-j<=K;j--)

        {

          val[i]=min(val[i],abs(h[i]-h[j])+val[j]);

        }

    }

  

    cout<<val[N-1];

    return 0;

}

// Fastest known solution for this problem:
#include <iostream>

#include <array>

#include <vector>

#include <iomanip>

#include <string>

#include <cmath>

#include <array>

#include <algorithm>

#include <queue>

#include <map>

using namespace std;



typedef  pair<int,int> P;

typedef long long LL;



const LL  INF=1<<31;







int main(){

     int n,k;

     cin>>n>>k;

     int h[100000];

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

          cin>>h[i];

     }

     LL dp[100001];



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

           dp[i]=INF;

      }

            dp[0]=0;

            dp[1]=abs(h[0]-h[1]);







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

          dp[i]=dp[i-1]+abs(h[i-1]-h[i]);

          for(int j=2;j<=k;++j){



               if(j<=i)dp[i]=min(dp[i],dp[i-j]+abs(h[i-j]-h[i]));

          }

     }     



     cout<<dp[n-1]<<endl;





}
// Original C++ solution (slower):
#include<iostream>

using namespace std;

int main()

{

	string a;

	int k;

	cin>>k;

	cin>>a;

	int len=a.size();

	if(len<=k)

	 cout<<a<<endl;

	else

	{

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

		 cout<<a[i];

		cout<<"..."<<endl;

	}

	return 0;

}

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

#include<string.h>



int main()

{

	int n;

	scanf("%d",&n);

	char str[102];

	scanf("%s",&str);

	int len=strlen(str);

	if(len>n)

	{

		str[n]='.';

		str[n+1]='.';

		str[n+2]='.';

		str[n+3]='\0';

	}

	printf("%s",str);

	return 0;

}

// Fastest known solution for this problem:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int mod = 1000000007;

const double PI = acos(-1);



int main()

{

	int k;

	string s;

	cin >> k >> s;

	if (s.size() <= k) cout << s << endl;

	else cout << s.substr(0, k) + "..." << endl;

}
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define endl '\n'

using namespace std;

typedef long long ll;

const int c=1e5+5;

const ll mod=1e9+7,M=998244353;

vector<ll>sold;

vector<ll>enem;

int n,k;

ll ans=1e18;

ll arr[c];

ll dp[c];

ll solve (int i)

{

    if(i==n-1)

    {

        return 0;



    }

    if(dp[i]!=-1)

    {

        return dp[i];

    }

    ans=abs(arr[i]-arr[i+1])+solve(i+1);

    for(int j=2;j<=k;j++){

    if(i<n-j){

     ans=min(ans,abs(arr[i]-arr[i+j])+solve(i+j));



    }

}

return dp[i]=ans;

}

int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

    cin>>n>>k;

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

    {

        cin>>arr[i];

    }

    memset(dp,-1,sizeof dp);



    cout<<solve(0);

    return 0;

}


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

#define ull unsigned long long

#define ll long long

#define pb push_back

#define endl '\n'

#define line cout<<"----------------------"<<endl

#define mp make_pair

#define mod 1000000007

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)

#define filein freopen("input.txt","r",stdin)

#define fileout freopen("output.txt","w",stdout)

using namespace std;

const ll  mx=300009;

ll  ara[mx];

ll  cost[mx];

int main()

{

    ll n,k;

    cin>>n>>k;

    for(ll  i=1;i<=n;i++) cin>>ara[i];

    cost[1]=0;

    cost[2]=abs(ara[2]-ara[1]);

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

    {

        cost[i]=LLONG_MAX;

        for(ll  j=1;j<=min(i-1,k);j++)

        {

            cost[i]=min(cost[i],cost[i-j]+abs(ara[i]-ara[i-j]));

        }

    }

    cout<<cost[n]<<endl;





}


// Fastest known solution for this problem:
#include <iostream>

#include <array>

#include <vector>

#include <iomanip>

#include <string>

#include <cmath>

#include <array>

#include <algorithm>

#include <queue>

#include <map>

using namespace std;



typedef  pair<int,int> P;

typedef long long LL;



const LL  INF=1<<31;







int main(){

     int n,k;

     cin>>n>>k;

     int h[100000];

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

          cin>>h[i];

     }

     LL dp[100001];



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

           dp[i]=INF;

      }

            dp[0]=0;

            dp[1]=abs(h[0]-h[1]);







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

          dp[i]=dp[i-1]+abs(h[i-1]-h[i]);

          for(int j=2;j<=k;++j){



               if(j<=i)dp[i]=min(dp[i],dp[i-j]+abs(h[i-j]-h[i]));

          }

     }     



     cout<<dp[n-1]<<endl;





}
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const int inf=0x3f3f3f3f;

const int N=2e5+5;

ll a[N],dp[N],n,k;

int main(){

	cin>>n>>k;

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

		cin>>a[i];

	dp[1]=0;

    dp[0]=0;

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

    	dp[i]=inf;

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

     for(int j = 1;j<=k;++j)

        {

            if(i-j<1) break;

            dp[i] = min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));

        }

		cout<<dp[n];

	return 0;

} 

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

#include <cstring>



using namespace std;



const int maxn = 1e5+5;

int n,K;

int h[maxn],f[maxn];



int abs(int x,int y) {

	if (x - y < 0) return y - x;

	return x - y;

}



int min(int x,int y) {

	if (x < y) return x;

	return y;

}



int main() {

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

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

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

		scanf("%d",&h[i]);

	}

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

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

		for (int k = 1; k <= K && k < i; k++){

			f[i] = min(f[i-k]+abs(h[i],h[i-k]),f[i]);

		}

	}

	printf ("%d\n",f[n]);

	return 0;

}

// Fastest known solution for this problem:
#include <iostream>

#include <array>

#include <vector>

#include <iomanip>

#include <string>

#include <cmath>

#include <array>

#include <algorithm>

#include <queue>

#include <map>

using namespace std;



typedef  pair<int,int> P;

typedef long long LL;



const LL  INF=1<<31;







int main(){

     int n,k;

     cin>>n>>k;

     int h[100000];

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

          cin>>h[i];

     }

     LL dp[100001];



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

           dp[i]=INF;

      }

            dp[0]=0;

            dp[1]=abs(h[0]-h[1]);







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

          dp[i]=dp[i-1]+abs(h[i-1]-h[i]);

          for(int j=2;j<=k;++j){



               if(j<=i)dp[i]=min(dp[i],dp[i-j]+abs(h[i-j]-h[i]));

          }

     }     



     cout<<dp[n-1]<<endl;





}
// Original C++ solution (slower):
//by Top1

#include <bits/stdc++.h>

     

#define f first

#define s second

#define int long long

#define ld long double

#define ull unsigned long long

#define pii pair <int, int>

#define pll pair <long, long>

#define mp make_pair

#define pb push_back

#define pf push_front

#define pp pop_back

#define rev reverse

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

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

#define forn(i, a, b) for (int i = a; i <= b; i++)

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

#define nxtp next_permutation

#define pvtp prev_permutation

#define KZ return 

#define x1 x21212121

#define y1 y21212121

#define sqr(x) x * x 

 

const int inf = INT_MAX;

const int mod = 1e9 + 7;

const int maxn = 6e5 + 111;

     

using namespace std;



int n, k, a[maxn], dp[maxn], t, q;



void solve(){    

	cin >> n >> k;



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

		cin >> a[i];



	dp[2] = abs(a[2] - a[1]);



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

		dp[i] = dp[i - 1] + abs(a[i - 1] - a[i]);

		for (int j = 2; j <= k && i - j > 0; j++)

			dp[i] = min(dp[i], dp[i - j] + abs(a[i - j] - a[i]));

	}

	cout << dp[n];

}



main(){

    boost;

	    

	q = 1;



	while (q--){

		solve();

	}

}


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

#include<algorithm>

using namespace std;



#define ll long long 



#define file_io 0



ll i,t,j;

ll n,k,h[100005],dp[100005];



int main(){

	if (file_io){

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

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

	}

	

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

	

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

		scanf("%lld",&h[i]);

	}

	

	dp[1]=0;

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

		dp[i]=2e9;

		for (t=max(1ll,i-k); t<i; ++t){

			dp[i]=min(dp[t]+abs(h[i]-h[t]),dp[i]);

		}

	}

	

	printf("%lld\n",dp[n]);

	

	return 0;

}

// Fastest known solution for this problem:
#include <iostream>

#include <array>

#include <vector>

#include <iomanip>

#include <string>

#include <cmath>

#include <array>

#include <algorithm>

#include <queue>

#include <map>

using namespace std;



typedef  pair<int,int> P;

typedef long long LL;



const LL  INF=1<<31;







int main(){

     int n,k;

     cin>>n>>k;

     int h[100000];

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

          cin>>h[i];

     }

     LL dp[100001];



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

           dp[i]=INF;

      }

            dp[0]=0;

            dp[1]=abs(h[0]-h[1]);







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

          dp[i]=dp[i-1]+abs(h[i-1]-h[i]);

          for(int j=2;j<=k;++j){



               if(j<=i)dp[i]=min(dp[i],dp[i-j]+abs(h[i-j]-h[i]));

          }

     }     



     cout<<dp[n-1]<<endl;





}
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

string s;

char f[20];

int main(){

	int tot=0;

	cin>>s;

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

		if(s[i]=='B'){

			if(tot>0)tot--;

		}

		else f[++tot]=s[i];

	}

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

	cout<<f[i];

	cout<<"\n";

	return 0;

}

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

#include <string.h>



void hekerman(char x[105]);



int main() {



    char x[105];



    scanf("%s", x);



    hekerman(x);



    return 0;

}



void hekerman(char x[105]) {



    int i, cnt = 0;

    char y[105];

    

    for(i = 0; i < strlen(x); i++) {

        if(x[i] == 'B') {

            cnt--;

        } else {

            y[cnt++] = x[i];

        }



        if(cnt < 0) {

            cnt = 0;

        }

    }



    for(i=0; i<cnt; i++) {

        printf("%c", y[i]);

    }

    printf("\n");



}

// Fastest known solution for this problem:
#include <bits/stdc++.h>

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

#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};

#define pb push_back



using ll = long long;

using namespace std;

using pint = pair<int,int>;

using pll = pair<ll,ll>;

const int INFint = 1e9;

const ll INFll = 1e18;

ll MOD=1e9+7;



ll gcd(ll a, ll b) { return __gcd(a,b); } //最大公約数

ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数



// aのn乗をMODで割りながら計算する

ll modpow(ll a, ll n) {

  long long res = 1;

  while (n > 0) {

    if (n & 1) res = res * a % MOD;

    a = a * a % MOD;

    n >>= 1; // right shift

  }

  return res;

}



// MODを法としたaの逆元を計算する

ll modinv(ll a) {

  return modpow(a, MOD - 2);

}



int main(){

  string s;

  cin>>s;

  int N = int(s.size());

  string ans;

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

    //cout << ans << endl;

    if (s[i] == 'B'){

      if (int(ans.size()) != 0){

        ans = ans.substr(0,int(ans.size())-1);

      }

    }else{

      ans += s[i];

    }

  }

  cout << ans << endl;

  return 0;

}
// Original C++ solution (slower):
#include<iostream>

#include<algorithm>

#include<cstring>

#include<iomanip>

#include<cmath>

#define ll long long

using namespace std;

const int N=100010;





int main() {

    std::ios::sync_with_stdio(false);

    std::cin.tie(NULL);

    std::cout.tie(NULL);

    int n,m;

    int a[N];

    int ans=0;

    cin>>n>>m;

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

        cin>>a[i];

        if(a[i]>=m)

            ans++;

    }

     cout<<ans<<endl;



    return 0;

}




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

int main()

{

    int N,K,h[100000],n,i;

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

    for(i=0,n=0;i<N;i++){

    scanf("%d",&h[i]);

    if(h[i]>=K){

        n=n+1;

      }

    }

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

    return 0;

}

// Fastest known solution for this problem:
#include <bits/stdc++.h>

using namespace std ;

 

int main()

{

  int n , k , a , answer ;

  cin >> n >> k ;

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

  {

    cin >> a ;

    if(a >= k)

      answer++ ;

  }

  cout << answer << endl ;

}