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

#include<array>

using namespace std;

const int mx = 1e5+5;

int a[mx];

array<int,100005>dp;

void memo(int i,int n,int k)

{

     if(i>n) return;

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

     {

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

     }

     memo(i+1,n,k);

}

int main()

{

	int n,k;cin>>n>>k;

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

		cin>>a[i];

	dp.fill(INT_MAX);

	dp[0] = 0;

	dp[1] = 0;

	memo(1,n,k);

	cout<<dp[n]<<endl;

	return 0;

}

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

using namespace std;

long long n,h[100010],dp[100010],k;



int main()

{

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

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

	{

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

	}

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

	{

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

		{

			if(i>j)

			{

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

				else dp[i] = min(dp[i],dp[i-j]+abs(h[i-j]-h[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 <iostream>

#include <vector>

#include <string>

#include <algorithm>

#include<climits>

using namespace std;



#define ll long long

#define tc                int T;cin>>T;while(T--)

int a[100000];

int main()

{

	int n, c, b, k ; cin >> n >> k;

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

	vector<int> dp(n, INT_MAX);

	dp[0] = 0;

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

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

			if (e < n)

				if ((dp[i] + abs(a[e] - a[i])) < dp[e])

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

		}

	}

	cout << dp[n - 1] << '\n';

	return 0;

}


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

#include <vector>

#include <string>

#include <algorithm>

#include<climits>

using namespace std;



#define ll long long

#define tc                int T;cin>>T;while(T--)

int main()

{

	int n, c, b, k ; cin >> n >> k;

  vector<int> a(n);

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

	vector<int> dp(n, INT_MAX);

	dp[0] = 0;

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

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

			if (e < n)

				if ((dp[i] + abs(a[e] - a[i])) < dp[e])

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

		}

	}

	cout << dp[n - 1] << '\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>

#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 mxN=1e5, mxH=1e4;

int n,k;

vi h(mxN+1), dp(mxN+1, INT_MAX);



void test_case(){

    cin>>n>>k;

    fo(i,n)cin>>h[i+1];

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

    Fo(i,3,n+1){

        Fo(j,1,k+1){

            if(i-j<1)continue;

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

        }

    }

    cout<<dp[n]<<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;



const int INF = 1e9+5;



int main() {

    ios_base::sync_with_stdio(0);

    cin.tie(NULL);



    int n,k;

    cin>>n>>k;

    vector<int>h(n),dp(n,INF);

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

    dp[0]=0;

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

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

            if(i+step<n){

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

            }

        }

    }

    cout<<dp[n-1]<<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 <string>

#include <vector>

using namespace std;

int main()

{

    string s;

    vector<char> ch;

    while(cin>>s)

    {

        int len1=s.size();

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

        {

            if(s[i]=='0')

            {

                ch.push_back('0');

            }

            else if(s[i]=='1')

            {

                ch.push_back('1');

            }

            else if(!ch.empty())

            {

                ch.pop_back();

            }

        }

        int len2=ch.size();

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

        {

            cout<<ch[i];

        }

        cout<<endl;

    }

    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<bits/stdc++.h>

using namespace std;

typedef long long int ll;

const int mx =1e6;

bool vis[mx];

int n,a[mx],dp[mx];

int solve(int i,int k)

{

    //cout<<"now in "<<a[i]<<endl;

    if(i>=n-1)

        return 0;

   // if(i==n-2)

     //   return abs(a[n-1]-a[n-2]);

    if(vis[i])

        return dp[i];

    int ans=1e9;

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

    {

      if(i+j<n)

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

    }



    vis[i]=1;

    return dp[i]=ans;

}

int main()

{

    memset(dp,0,sizeof dp);

    int k;

    cin>>n>>k;

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

        cin>>a[i];

    cout<<solve(0,k)<<endl;

    return 0;



}




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

using namespace std;

const int inf=1e9;

int main()

{

int n,i,j,k;

cin>>n>>k;

int a[n],ans[n];

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

    {cin>>a[i];}



memset(ans,127,sizeof ans);

ans[n-1]=0;



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

{

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

    {

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

    }

}

cout<<ans[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<bits/stdc++.h>

using namespace std;

int main()

{

	int k,x,a,b;

	cin>>k>>x;

	if(k>0)

	{

		 a=x-(k-1);

		b=x+(k-1);

	}

	else

	{

		a=x;

		b=x;

	}

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

	{

		if(i!=b)

		cout<<i<<" ";

		else

		cout<<i<<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 <bits/stdc++.h>

using namespace std;

#define int long long int



int n; //number of stones

int k; //farthest the frog can jump

vector<int> h; //height of the stones

vector<int> dp; //memorize heck



int jump(int stone){

	if(dp[stone]==-1){

		if(stone == n-1){

			return 0;

		}

		else{

			dp[stone] = INT_MAX;

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

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

			}

			return dp[stone];

		}

	}

	else{

		return dp[stone];

	}

}



main(){

	cin >> n >> k;

	

	dp.assign(n, -1);

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

		int x;

		cin >> x;

		h.push_back(x);

	}



	cout << jump(0) << "\n";

}

// Optimized solution to the same problem (faster):
#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]);



}

// 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 int long long

//#pragma GCC optimize("Ofast")

//#pragma comment(linker, "/stack:200000000")

//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

 

 

#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);

#define forev(i, b, a) for(int i = (b); i >= (a); --i)

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

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

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

#define pb push_back

#define ppb pop_back

#define mp make_pair

#define s second

#define f first

 

 

using namespace std;

 

 

typedef pair < long long, long long > pll;    

typedef pair < int, int > pii;

typedef unsigned long long ull;         

typedef vector < pii > vpii;

typedef vector < int > vi;

typedef long double ldb; 

typedef long long ll;  

typedef double db;                         

 

 

const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 555;

const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);

const int inf = 1e9, N = 2e5 + 48, mod = 1e9 + 7;

const db eps = 1e-12, pi = 3.14159265359;

const ll INF = 1e18;





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



main () {

	cin >> n >> k;

	forn (i, 1, n)

		cin >> h[i];	

	forn (i, 2, n) {

		dp[i] = inf;

		forn (j, max(1, i - k), i - 1)

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

	}



	cout << dp[n];

} 

// 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;



vector<int> vec;

vector<int> dp(100001,-1);



int back(int i,int k){

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

        if(i+j==vec.size()-1) return abs(vec[i+j]-vec[i]);

    }

    // if(i+2==vec.size()-1) return abs(vec[i+2]-vec[i]);

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

    

    int ans=INT_MAX;

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

        if(i+j<vec.size()){

            ans= min(ans, abs(vec[i+j]-vec[i]) + back(i+j,k));

        }

    }



    dp[i]=ans;

    return dp[i];

}

int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

    int n,k;

    cin>>n>>k;

    

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

        int a;

        cin>>a;

        vec.push_back(a);

    }

    cout<<back(0,k);

	return 0;

}

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

using namespace std;



int main() {

    int n,K;    cin>>n>>K;

    int a[n];

    long long dp[n];

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

    

    dp[0]=0;

    

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

        long long add=1e9;

        for(int k=1;k<=K;k++)if(i-k>=0){

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

        }

        dp[i]= add; 

        

    }

    cout<<dp[n-1]<<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>

using namespace std;

int n,s,spn;

void sp(int ne,int ns,bool* flag)

{

	if (ne > n) return;

	if (ne == n && ns == s) spn++;

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

        if(!flag[i]){

            flag[i]=true;

            sp(ne+1,ns+i,flag);

			flag[i] = false;

		}

    }

}



int perm(int n)

{

	return (n ? n * perm(n - 1) : 1);

}



int main()

{

    while(1)

    {

        cin>>n>>s;if(!n)return 0;

        spn=0;

        bool flag[10]={false};

        sp(0,0,flag);

        spn /= perm(n);

        cout<<spn<<endl;

    }

    return 0;

}

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



using namespace std;



int ct(int x, int n, int s)

{

	if (x == 10){

		return (s == 0 && n == 0);

	}

	

	return (ct(x + 1, n - 1, s - x) + ct(x + 1, n, s));

}



int main()

{

	int n, s;

	

	while (scanf("%d %d", &n, &s) && n){

		printf("%d\n", ct(0, n, s));

	}

	

	return (0);

}

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

#include<algorithm>

#include<cstdio>

#include<cstdlib>

#include<vector>

#include<string>

#include<sstream>

#include<cmath>

#include<numeric>

#include<map>

#include<stack>

#include<queue>

#include<cassert>

using namespace std;

int inf = 1000000000;

int n, s;



int cnt = 0;



int func(string m, vector<bool> b, int num){

  if( m.size() == n ){

    int tmp = 0;

    for(int i=0; i<n; i++) tmp += m[i]-'0';

    if( tmp == s ) cnt++;

    // if( tmp == s ) cerr << m << endl;

    return 0;

  }



  for(int i=num+1; i<10; i++){

    if( b[i] ) continue;

    b[i] = true;

    func( m + to_string(i), b, i);

    b[i] = false;

  }

  return 0;

}



int main(void) {





  while(cin >> n >> s){

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



    vector<bool> b(10, false);

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

      b[i] = true;

      func(to_string(i), b, i);

      b[i] = false;

    }

    cout << cnt << endl;

    cnt = 0;

  }



  return 0;

}





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

#include <vector>

using namespace std;

int main(){

	int n,k;

	cin>>n>>k;

	vector <int> h(n),dp(n,INT_MAX);

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

	dp[0]=0;

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

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

			if(i+j<n){

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

			}

		}

	}

	cout<<dp[n-1];

	return 0;

} 

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

#include<algorithm>



int main(){

  int s,k;

  long long st[100001],p[100001];

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

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

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

  }

  p[0]=0;

  p[1]=0;

  p[2]=(st[2]-st[1] < 0) ? st[1]-st[2] : st[2]-st[1];

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

    p[i] = 1000000001;

  }

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

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

      if(i-j>=1){

	long long tmp;

	tmp = (st[i]-st[i-j] < 0) ? st[i-j]-st[i] : st[i]-st[i-j];

	if(p[i] > p[i-j]+tmp){

	  p[i] = p[i-j]+tmp;

	}

	if(tmp == 0) break;

      }else{

	break;

      }

    }

  }

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

  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;





}