stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <iostream>

#include <algorithm>

#include <cmath>

#include <cstdlib>

#include <cstdio>

#include <cstring>

#include <iomanip>

#include <string>

#include <set>

#include <vector>

#include <queue>

#include <stack>

#include <map>

using namespace std;

#define ms(a, x) memset(a, x, sizeof(a))

#define fore(i, a, n) for (long long i = a; i < n; i++)

#define ford(i, a, n) for (long long i = n - 1; i >= a; i--)

#define si(a) scanf("%d", &a)

#define sl(a) scanf("%lld", &a)

#define sii(a, b) scanf("%d%d", &a, &b)

#define sll(a, b) scanf("%lld%lld", &a, &b)

#define slll(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)

#define debug(a) cout << a << endl

#define pr(a) printf("%d ",a)

#define endl '\n'

#define pi acos(-1.0)

#define tr t[root]

#define lson t[root << 1]

#define rson t[root << 1 | 1]

#define IO ios::sync_with_stdio(false), cin.tie(0)

#define ull unsigned long long

const double eps = 1e-8;

inline int sgn(const double &x) { return x < -eps ? -1 : x > eps; }

typedef long long ll;

const int inf=0x3f3f3f3f;

const int MAXN = 1e5 + 10;

int n,a[MAXN],k;

ll dp[MAXN];

int main()

{

	sii(n,k);

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

	ms(dp,inf);dp[1]=0;dp[2]=abs(a[1]-a[2]);

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

	{

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

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

	}

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

 } 

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



using namespace std;



const int nax = 1e5+103;

int n, k;

int dp[nax];

int a[nax];

int f(int i){

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

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

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

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

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

	}

	return dp[i]=ans;

}

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;

}
// Slower C++ solution:
#include <iostream>

#include <cstring>

#include <utility>

#include <vector>

#include <algorithm>

using namespace std;



#define MAXSIZE 500

#define CENTER (MAXSIZE / 2)



// ?????´(= 0)????????´ (= 1)????????´ (= 2)????????´ (= 3)

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

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



int tables[MAXSIZE][MAXSIZE];



inline int index(int n){

    return n + CENTER;

}



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

    while(1){

        int n; cin >> n;

        if(!n) break;

        

        int left, right, top, bottom;

        left = right = top = bottom = CENTER;

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

        

        vector<pair<int, int> > tableIndex;

        tableIndex.push_back(make_pair(CENTER, CENTER));

        

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

            int m, d; cin >> m >> d;

            

            int x = tableIndex[m].first + dx[d];

            int y = tableIndex[m].second + dy[d];

            tableIndex.push_back(make_pair(x, y));

            

            left = min(left, x);

            right = max(right, x);

            top = min(top, y);

            bottom = max(bottom, y);

        }

        

        cout << right - left + 1 << " " << bottom - top + 1 << endl;

        

    }

}

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

#include <cstring>

#include <utility>

#include <vector>

#include <algorithm>

using namespace std;



#define MAXSIZE 500

#define CENTER (MAXSIZE / 2)



// ?????´(= 0)????????´ (= 1)????????´ (= 2)????????´ (= 3)

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

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



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

    while(1){

        int n; cin >> n;

        if(!n) break;

        

        int left, right, top, bottom;

        left = right = top = bottom = CENTER;

        

        vector<pair<int, int> > tableIndex;

        tableIndex.push_back(make_pair(CENTER, CENTER));

        

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

            int m, d; cin >> m >> d;

            

            int x = tableIndex[m].first + dx[d];

            int y = tableIndex[m].second + dy[d];

            tableIndex.push_back(make_pair(x, y));

            

            left = min(left, x);

            right = max(right, x);

            top = min(top, y);

            bottom = max(bottom, y);

        }

        

        cout << right - left + 1 << " " << bottom - top + 1 << endl;

    }

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



using namespace std;

using ll = long long;



using Field = vector<vector<int>>;

using Graph = vector<vector<int>>;

using VI = vector<int>;

using VC = vector<char>;

using PI = pair<int, int>;



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

#define ALL(x) x.begin(), x.end()



const long long INF = 1LL<<60;

const int mod = 1000000007;



template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }

template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }



int N, K;

vector<int> h(100010);

vector<int> dp(100010, INT32_MAX);





int main() {

    cin.tie(0);

    ios_base::sync_with_stdio(false);

    cin >> N >> K;

    REP(i, N) cin >> h.at(i);



    dp.at(0) = 0;



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

        for(int j = i - K; j < i; j++) {

            if (j < 0) continue;

            chmin(dp.at(i), dp.at(j) + abs(h.at(j) - h.at(i)));

        }

    }



    cout << dp.at(N - 1) << endl;



    return 0;

}

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



using namespace std;

using ll = long long;



using Field = vector<vector<int>>;

using Graph = vector<vector<int>>;

using VI = vector<int>;

using VC = vector<char>;

using PI = pair<int, int>;



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

#define ALL(x) x.begin(), x.end()



const long long INF = 1LL<<60;

const int mod = 1000000007;



template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }

template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }



int N, K;

vector<ll> h;

vector<ll> dp;



int main() {

    cin.tie(0);

    ios_base::sync_with_stdio(false);



    cin >> N >> K;

    h.resize(N + K + 10, 0);

    dp.resize(N + K + 10, INF);



    REP(i, N) cin >> h.at(i);



    dp[0] = 0;



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

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

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

        }

    }



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

    

    return 0;

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

using namespace std;

const int N=1e5+5;

int A[N];

char ans[N],ch,q;

bool ac[N];

int n,x,m;

int main(){

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

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

        scanf("%d %c%c",&x,&ch,&q);

        if(ch=='A') ac[x]=1;

        else if(!ac[x])A[x]++;

    }

    int sum=0 , sAc=0;

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

        sum+=A[i]*ac[i];

        sAc+=ac[i];

    }

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

    return 0;

}


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

using namespace std;

typedef long long int ll;

int main()

{

    ll n, m;

    cin>>n>>m;

    ll x;

    string s;

    map<ll,ll>mp1, mp2;

    ll c = 0, p = 0;

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

    {

        cin>>x;

        cin>>s;

        if(mp2[x] == 0 && s == "WA") mp1[x]++;

        if(mp2[x] == 0 && s == "AC")

        {

            mp2[x] = 1;

            p += mp1[x];

            c++;

        }

    }

    cout<<c<<" "<<p<<endl;

    return 0;

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

using namespace std;

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



int n, m;

vector<int> p0(100100); //提出番号→問題番号

vector<string> p1(100100);//提出番号→提出結果

vector<bool> q(100100); //問題ごとにacしたかを記録

vector<int> q1(100100); //いつ正解したか

int ac = 0, wa = 0;



void input(){

  cin >> n >> m;

  rep(i, m){

    cin >> p0.at(i) >> p1.at(i);

    //cout<< p0.at(i) << " "<< p1.at(i) << " ";

  }

  rep(i, 100100){

    q.at(i) = false;

  }

}

/*

void update(int i){ //提出番号→問題番号、結果→更新

  int num = p0.at(i);//問題番号

  //cout <<  num <<" "<<q.at(num) << " ";

  if(q.at(num)){

    return;

  }

  if(p1.at(i) == "AC"){

    ac++;

    q.at(num) = true;

  }else if(p1.at(i) == "WA"){

    wa++;

  }

}*/

void func1(int i){

  int num = p0.at(i);

  if(!q.at(num) && p1.at(i) == "AC"){

    ac++;

    q.at(num) = true;

    q1.at(num) = i;

  }

}

void func2(int i){

  int num = p0.at(i);

  if(q.at(num) && p1.at(i) == "WA" && q1.at(num) > i){

    wa++;

  }

} 



void solve(){

  input();

  rep( i , m ){

    func1(i);

  }

  rep( i, m ){

    func2(i);

  }

  cout << ac << " " << wa << endl;

}



int main() {

  solve();

  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 3.9770042451880987x):
/*

１つの配列で実装してみる。

ACしたかどうかは数の正負で判定する。ACするまでのWAの回数は、負の数で数える。

*/

#include <bits/stdc++.h>

using namespace std;

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

typedef long long int ll;

typedef pair<int, int> P;



int n, m;

vector<int> Q(101010, -1);



int main(){

  cin >> n >> m;

  rep(i, m){

    int p; string s;

    cin >> p >> s;

    if(s == "WA" && Q[p] < 0){

      Q[p]--;

    }else{

      Q[p] = abs(Q[p]);

    }

  }

  int ac = 0, wa = 0;

  rep(i, n + 1){

    if(Q[i] > 0){

      ac++;

      wa += Q[i] - 1;

    }

  }

  cout << ac << " " << wa << endl;

  return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cstring>

#include<algorithm>

#include<cstdio>

using namespace std;

#define MAXN 100000 + 10

#define ll long long int

ll N[MAXN];

ll dp[MAXN];

#define INF 0x3f3f3f3f;

int main()

{

    ll n,k;

    cin>>n>>k;

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

        cin>>N[i],dp[i] = INF;

    dp[0] = 0;

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

        for(int j = i - k;j <= i;++j)

            if(j >= 0)

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

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

    return 0;

}


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

#include <algorithm>

#include <cmath>

using namespace std;



int h[(int)1e5], dp[(int)1e5], K, N;





int main()

{

	K = N = 0;

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

	{

		dp[j] = 1e9;

	}

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

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

	{

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

	}

	dp[1] = 0;

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

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

	{

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

		{

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

		}

	}

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

	return 0;	

}
// Slower C++ solution:
#include<iostream>

using namespace std;



int a[110000];

int m[110000];

int n,k;



int dp(){

	m[0] = 0;

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

		int temp = 2e9;

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

			if(i-j>=0){

				temp = min(temp,

					(m[i-j] + abs(a[i] - a[i-j]))

				);

			}else{

				break;

			}

		}

		m[i] = temp;

	}

//	for(int i = 0;i<n;i++) cout<<m[i]<<" ";cout<<"\n";

	return m[n-1];

}



int main(){

	cin>>n>>k;

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

		cin>>a[i];

	}

	cout<<dp()<<"\n";

	return 0;

}

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

using namespace std;

#define MAX(a,b) (a>b?a:b)

#define MOD(a) (a>0?a:-(a))

#define custoate(i)

int main(){

  int npedras, maxpulo;

  scanf("%d %d",&npedras,&maxpulo);

  int hpedra[npedras],custoate[npedras];

  for (size_t i = 0; i < npedras; i++)

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

  custoate[0] = 0;

  int tempcost = 2147483647,k,tempcost2;

  for (size_t i = 1; i < npedras; i++,tempcost = 2147483647) {

    // printf("i = %d, tempcost = %d\n", i,tempcost);

    for (k= (maxpulo>i ? i : maxpulo); k > 0; k--) {

      // printf("k = %d ",k);

      tempcost2 = custoate[i-k] + MOD(hpedra[i-k]-hpedra[i]);

      if (tempcost > tempcost2)

        tempcost = tempcost2;

    }

    // printf("custo[%d] = %d",i,tempcost);

    custoate[i] = tempcost;

    // printf("\n\n");

  }

  printf("%d\n", custoate[npedras-1]);



}
// Slower C++ solution:
#include <functional>

#include <algorithm>

#include <iostream>

#include <numeric>

#include <iomanip>

#include <utility>

#include <cstdlib>

#include <sstream>

#include <bitset>

#include <vector>

#include <cstdio>

#include <ctime>

#include <queue>

#include <deque>

#include <cmath>

#include <stack>

#include <list>

#include <map>

#include <set>



using namespace std;



typedef vector<int> vi;

typedef pair<int,int> pii;

typedef long long ll;



#define dump(x)  cerr << #x << " = " << (x) << endl

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

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

#define pb push_back

#define sz size()



const double EPS = 1e-10;

const int INF = 100000000;





int main(){

    int n,m;

    while(cin>>n>>m){

        if(n==0 && m==0)break;

        

        int data[600][600]={};

        rep(i,600){

            rep(j,600){

                if(i==j){

                    data[i][j]=0;

                }

                else{

                    data[i][j]=INF;

                }

            }

        }

        

        rep(i,m){

            int a,b;

            cin>>a>>b;

            a--;b--;

            data[a][b]=1;

            data[b][a]=1;

        }

        

        rep(k,n){

            rep(i,n){

                rep(j,n){

                    data[i][j]=min(data[i][j],data[i][k]+data[k][j]);

                }

            }

        }

        int c=0;

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

            if(data[0][i]<=2)

                c++;

        }

        cout<<c<<endl;

    }

    return 0;

    

}

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



using namespace std;



typedef vector<int> vi;

typedef pair<int,int> pii;

typedef long long ll;



#define dump(x)  cerr << #x << " = " << (x) << endl

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

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

#define pb push_back



int main(){

    int n,m;

    int cost[600][600];

    while(cin>>n>>m){

        if(n==0&&m==0)break;

        rep(i,600)rep(j,600)cost[i][j]=999999999;

        rep(i,m){

            int a,b;

            cin>>a>>b;

            a--,b--;

            cost[a][b] = cost[b][a] = 1;

        }

        rep(k,n){

            rep(i,n){

                rep(j,n){

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

                }

            }

        }

        int sum=0;

        rep(i,600){

            if(cost[0][i]<=2&&i!=0)sum++;

        }

        cout<<sum<<endl;

    }

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

using namespace std;

const int m=110000;

int a,b,c[m],d[m];

int main()

{

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

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

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

    memset(d,0x3f,sizeof(d)),d[1]=0;

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

        for (int j = 1; j<i && j<=b; j++)

            d[i]=min(d[i],d[i-j]+abs(c[i]-c[i-j]));

    printf("%d",d[a]);

    return 0;

}

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

#include <fstream>

#define inf INFINITY

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

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

#define _3102_ main()

#define endl '\n'

typedef long long ll ;

typedef unsigned long long ull ; 

typedef long double ld ; 

using namespace std ;

const int N = 1e5+100  ; 

const ll mod = 1e9 + 7  ;







int _3102_ {

    Gamed

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

    cin >> n >> k ; 

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

        cin >> arr[i] ; 

    }

    dp[0] = 0 ;  

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

        ll ans = inf , cnt = k; 

        for ( int j = i - 1 ; j >= 0 && cnt > 0 ; j -- , cnt --){

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

        }

        dp[i] = ans ; 

    }

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

    return 0;

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

#include <string.h>

#include <algorithm>

#define MN (1<<18)

int n,a[MN+5],b[MN+5][2],c[MN+5][2],ans=0;

int cnt=0;

void xxx(int to,int frm,int p){

	if(c[to][0]==c[frm][p]||c[to][1]==c[frm][p]) return;

	if(b[to][0]<b[frm][p]){

		b[to][1]=b[to][0];  c[to][1]=c[to][0];

		b[to][0]=b[frm][p]; c[to][0]=c[frm][p];

	}else if(b[to][1]<b[frm][p]){

		b[to][1]=b[frm][p]; c[to][1]=c[frm][p];

	}

}

void work(int x){

	for(int j=1;j<(1<<18);j<<=1)

		if(x&j){

			xxx(x,x^j,0);

			xxx(x,x^j,1);

		}

}

int main(){

	scanf("%d",&n);

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

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

	memset(c,0xff,sizeof(c));

	b[0][0]=a[0]; c[0][0]=0;

	b[0][1]=-1;   c[0][1]=-1;

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

		b[i][0]=a[i]; c[i][0]=i;

		work(i);

		ans=std::max(ans,b[i][0]+b[i][1]);

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

	}

}

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

#define taskname "OrPlusMax"

#define int long long

using namespace std;



vector<int> a;

void update(int i, pair<int, int> &p)

{

    if (i == p.first || i == -1) return;

    if (p.first == -1 || a[i] > a[p.first])

    {

        swap(p.first, p.second);

        p.first = i;

    }

    else if (p.second == -1 || a[i] > a[p.second]) p.second = i;

}



main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);   cout.tie(nullptr);

    if (ifstream("test.inp"))

    {

        freopen("test.inp", "r", stdin);

        #ifdef CHECKING

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

        #else

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

        #endif //CHECKING

    }

    else if (ifstream(taskname".inp"))

    {

        freopen(taskname".inp", "r", stdin);

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

    }



    int n;  cin >> n;

    a.resize(1 << n);

    for (int &i : a) cin >> i;

    vector<pair<int, int>> v(1 << n, {-1, -1});

    vector<int> ans(1 << n, 0);

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

    {

        update(i, v[i]);

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

            if (((i >> (j - 1)) & 1) == 0)

            {

                int x = i ^ (1 << (j - 1));

                update(v[i].first, v[x]);

                update(v[i].second, v[x]);

            }

        if (i)

        {

            ans[i] = max(ans[i - 1], a[v[i].first] + a[v[i].second]);

            cout << ans[i] << '\n';

        }

    }

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

 using namespace std;

 inline int read(){

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

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

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

    return x*f;

 }

 int N,Q,a[100010],b,c,cnt[100010];

 #define LL long long

 int main(){

 	N=read();

 	LL sum = 0;

 	for (int i=1; i<=N; i++) a[i]=read(),cnt[a[i]]++,sum+=a[i];

 	Q=read();

 	while (Q--){

 		b=read(),c=read();

 		sum -= 1LL*cnt[b]*b;

 		sum += 1LL*cnt[b]*c;

 		cnt[c] += cnt[b];

 		cnt[b] = 0;

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

 	}

 	return 0;

 }

 

 

 /*

4

1 2 3 4

3

1 2

3 4

2 4

 */

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

using namespace std;



int num[100050];



int main()

{

	long long sum=0;

	int N,Q,B,C,a;

	scanf("%d",&N);

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

		num[i]=0;

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

	{

		scanf("%d",&a);

		sum+=(long long)a;

		++num[a];

	}

	scanf("%d",&Q);

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

	{

		scanf("%d%d",&B,&C);

		sum+=(long long)(C-B)*num[B];

		num[C]+=num[B];

		num[B]=0;

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

	}

return 0;

}
// Slower C++ solution:
#include<iostream>

#include<algorithm>

#include<cmath>

#include<cstring>

#include<cstdlib>

#include<ctime>

#include<cstdio>

#include<string>

//#include<string>

//#include<sstream>

using namespace std;

int main()

{

	int i,k=0;

	char a[1000],b[1000];

	scanf("%s",&a);

	int n=strlen(a);

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

	{

		if(a[i]=='0') b[k++]='0';

		else if(a[i]=='1') b[k++]='1';

		else if(a[i]=='B') 

		{

			if(k==0) continue;

			else k--;

		}

	}

	for(i=0;i<k;i++) printf("%c",b[i]);

	printf("\n");

}

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

#include<string.h>

int main(){

    char G[100], H[100];

    int A=0;

    scanf("%s", G);

    int len=strlen(G);

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

    {

        if(G[i]=='B')

        {

            A--;

            if(A<0)

                A=0;

        }

        else

            H[A++]=G[i];

    }

    H[A]='\0';

    printf("%s\n", H);

    return 0;

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

#include <vector>

#include <string>

#include <cmath>

#include <set>

#include <stdio.h>

#include <algorithm>

#include <map>

#include <queue>

#include <unordered_map>

#define ll long long

#define pii pair <int, int>

#define pll pair <long long, long long>

#define plxy pair <long long, pll>

#define INT_MAX 1e18

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

using namespace std;

using namespace std;

const int mod=1e9+7;

const int N=1e5+5;

ll n,k,arr[N];

ll dp[N];

ll solve(ll idx)

{

    if(idx==n-1)

        return 0;

    if(dp[idx]!=-1)

        return dp[idx];

    ll choice=INT_MAX;

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

    {

        if(idx+i<n)

            choice=min(choice,solve(idx+i)+abs(arr[idx+i]-arr[idx]));

    }

    dp[idx]=choice;

    return dp[idx];

}

int main()

{

     Keep_calm_You_are_still_learning

     cin>>n>>k;

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

     {

         cin>>arr[i];

     }

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

     cout<<solve(0);

    return 0;

}


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





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

using namespace std;

int n,k;

int h[100100],f[100100];

int smallest ;

int main(){

	cin>>n>>k;

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

		cin>>h[i];

	}

	f[1]=0;

	f[2]=abs(h[2]-h[1]);

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

		smallest=2147483647;

		for(int j=max(1,i-k);j<i;j++){

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

		}

		f[i]=smallest;

	}

	cout<<f[n];

}


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

#include <algorithm>

#include <cmath>

using namespace std;



int h[(int)1e5], dp[(int)1e5], K, N;





int main()

{

	K = N = 0;

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

	{

		dp[j] = 1e9;

	}

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

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

	{

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

	}

	dp[1] = 0;

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

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

	{

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

		{

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

		}

	}

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

	return 0;	

}