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

#include <iostream>

#include <algorithm>



using namespace std;



const int INF = 1000000000;



int main()

{

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

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

  int dp[100200]; dp[0] = 0; for (int i = 1; i < 100200; ++i) dp[i] = INF;

  

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

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

  

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

  return 0;

}

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



using namespace std;



template<class T> inline void chmin(T &x, const T &y) {if (x > y) x = y;}



const int INF = 1e9+7;



int n, k;

int h[101000];



int dp[101000];



int main()

{

  cin >> n >> k;

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

  

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

  

  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>

#include <string>

#include <cstdlib>

using namespace std;



#define READ                freopen("in.txt", "r", stdin)

#define WRITE               freopen("out.txt", "w", stdout)



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

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

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



#define CLR(a)              memset(a, 0, sizeof(a))

#define SET(a)              memset(a, -1, sizeof(a))



#define PI                  acos(-1.0)



#define pb                  push_back

#define mp                  make_pair

#define SORT(v)             sort(v.begin(), v.end())

#define REV(v)              reverse(v.begin(), v.end())

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

#define FOR1(i, n)          for(int i=1; i<=n; i++)

#define ROF(i, n)           for(int i=n-1; i>=0; i--)

#define ROF1(i, n)          for(int i=n; i>=1; i--)

#define LOOP(i, x, y)       for(int i=x; i<=y; i++)

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





typedef long long              LL;

typedef unsigned long long     ULL;

typedef vector<int>            VI;

typedef pair<int, int>         PII;

typedef pair<string, int>      PSI;

typedef pair<char, int>        PCI;



const int MAX = 100005;

const LL LMAX = 12158598925;

const double eps = 1e-9;

const int INF = 0x3f3f3f3f;



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

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

int kx[] = {1, 1, 2, 2, -1, -1, -2, -2};

int ky[] = {2, -2, 1, -1, 2, -2, 1, -1};



LL dp[MAX], arr[MAX];





int main()

{

//    READ;

//    WRITE;



    int n, k; sii(n, k);

    FOR1(i, n) scanf("%lld", &arr[i]);



    dp[1] = 0;



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

        LL p = INT_MAX;

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

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



        dp[i] = p;

    }



    cout << dp[n] << endl;

    return 0;

}


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

int partitin(int n,int r)

{

	int x;

	int i;

	int t;

	x=a[r];

	i=n-1;

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

	{

		if(a[j]<=x)

	{	i++;

		t=a[i];

		a[i]=a[j];

		a[j]=t;

		}

	}

	t=a[i+1];a[i+1]=a[r];a[r]=t;

	return i+1;

}

int main()

{

	int n,m;

	cin>>n;

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

	{

		cin>>a[i];

	}

	m=partitin(0,n-1);

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

	{

	    if(i) cout<<" ";

		if(i==m) cout<<"[";

		cout<<a[i];

		if(i==m) cout<<"]";

    }

    cout<<endl;

    return 0;

}

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

#define MAX 100000

int A[MAX],n;

int partition(int p,int r)

{

	int x,i,j,t;

	x=A[r];

	i=p-1;

	for(j=p;j<r;j++)

	{

		if(A[j]<=x)

		{

			i++;

			t=A[j];A[j]=A[i];A[i]=t;

		}

	}

	t=A[i+1];A[i+1]=A[r];A[r]=t;

	return i+1;

}

int main()

{

	int i,q;

	scanf("%d",&n);

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

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

	q=partition(0,n-1);

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

	{

		if(i)printf(" ");

		if(i==q)printf("[");

		printf("%d",A[i]);

		if(i==q)printf("]");

	}

	printf("\n");

	return 0;

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

using namespace std;

int n, k;

int h[1000005], memo[1000005];

int f(int n) {

    if(n == 0) {

        return 1e9;

    }

    if(n == 1) {                        // bisa juga base case nya n = 0, f(0) harus tinggi, misal 1e9;

        return 0;

    }

    if(n == 2) {

        return abs(h[1] - h[2]);

    } 

    else if(memo[n] != -1) {

        return memo[n];

    }

    int minim = INT_MAX;

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

        if(n - i > 0) {

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

        }

//        printf("#%d %d\n", f(n - i), abs(h[n] - h[n - i]));

    }

    memo[n] = minim;

    return memo[n];

}



int main() {

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

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

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

    }

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

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

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

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

//    }

}

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

#define int long long

#define double long double

#define endl "\n"

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

#define pb push_back

#define mp make_pair

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

#define pii pair<int,int>

#define ff first

#define ss second

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

#define rep(i,j,k) for(int i=j;i<k;i++)

#define td(v) v.begin(),v.end()

#define inf 1000000000 // 1e9

#define M   1000000007 // 1e9 + 7

using namespace std;

inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }

int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}

int lcm(int a,int b){return (a*b)/gcd(a,b);}

int exp(int a,int b,int m){

    if(b==0) return 1LL;

    if(b==1) return mod(a,m);

    int k = mod(exp(a,b/2,m),m);

    if(b&1){

        return mod(a*mod(k*k,m),m);

    }

    else return mod(k*k,m);

}



main(){

    fastio;

    int n,k;

    cin >> n >> k;

    vector<int> dp(n,(1LL<<62));

    vector<int> h(n);

    for(int &x : h) cin >> x;

    dp[0] = 0;

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

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

            if(i+j >= n) break;

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

        }

    }

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

}
// Slower C++ solution:
/* In the name of Allah */



#include <bits/stdc++.h>

using namespace std;



// const int INF = 20000000;



#define ll long long

#define _SetBit(A, k) (A[(k / 32)] |= (1 << (k % 32)))

#define _ClearBit(A, k) (A[(k / 32)] &= ~(1 << (k % 32)))

#define _CheckBit(A, k) (A[(k / 32)] & (1 << (k % 32)))

#define SetBit(x, k) (x |= (1 << k))

#define ClearBit(x, k) (x &= ~(1 << k))

#define CheckBit(x, k) (x & (1 << k))



int vis[26];



int main()

{

  int n;

  cin >> n;

  char x[n + 1];

  ll r = 0, g = 0, b = 0;

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

  {

    cin >> x[i];

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

      r++;

    else if (x[i] == 'G')

      g++;

    else

      b++;

  }



  ll cnt = 0;

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

  {

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

    {

      if (x[i] != x[i + j] && x[i + j] != x[i + 2 * j] && x[i] != x[i + 2 * j])

        cnt++;

    }

  }



  ll res = r * g * b;

  res -= cnt;

  // cout << "**" << r << " " << g << " " << b << " " << cnt << ":\n";

  cout << res << "\n";



  return 0;

}

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

#include<algorithm>



using namespace std;



typedef long long LL;



const int N = 4010;



int r[N], g[N], b[N];

char s[N];



int main()

{

    int n;

    scanf("%d", &n);

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

    

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

    {

        r[i] = r[i - 1], g[i] = g[i - 1], b[i] = b[i - 1];

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

        else if(s[i] == 'G')  g[i] ++;

        else  b[i] ++;

    }

    

    LL res = 0;

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

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

            if(s[i] != s[j])

            {

                char c = (int)'R' + 'G' + 'B' - s[i] - s[j];

                if(c == 'R')  res += r[i - 1];

                else if(c == 'G')  res += g[i - 1];

                else  res += b[i - 1];

                if(i - (j - i) >= 1 and s[i - (j - i)] == c)  res --;

            }

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

    return 0;

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



typedef long long ll;

typedef unsigned long long ull;

typedef long double ld;

ll mod = 1e9 + 7;

#define EPS 1e-1

#define PI 3.14159265



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

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

using namespace std;



ll fastpow(ll base, ll pow)

{

    if (!base)

        return 0;

    if (!pow)

        return 1;

    if (pow == 1)

        return base;

    ll x = fastpow(base, pow / 2) % mod;

    x *= x;

    x %= mod;

    if (pow % 2)

        x *= base;

    return x % mod;

}



ll inverse(ll x)

{

    return fastpow(x, mod - 2) % mod;

}



ll fact[(int)1e6 + 5], inv[(int)1e6 + 5];

void init()

{

    fact[0] = inv[0] = 1;

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

    {

        fact[i] = (i * fact[i - 1]) % mod;

        inv[i] = inverse(fact[i]);

    }

}



void factorize(ll x, map<int, int> &ss)

{

    while (x % 2 == 0)

        ss[2]++, x /= 2;

    for (int i = 3; i <= sqrt(x); i += 2)

        while (x % i == 0)

            ss[i]++, x/= i;

    if (x > 2)

        ss[x]++;

}



ll ncr(ll n, ll r)

{

    return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod;

}



ll npr(ll n, ll r)

{

    return (fact[n] * inv[n - r]) % mod;

}



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

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



int arr[(int)1e5 + 5];

int dp[(int)1e5 + 5];

int n, k;



ll solve(int idx)

{

    if (idx >= n - 1)

        return 0;

    if (dp[idx] != -1)

        return dp[idx];

    ll res = 1e9;

    for (int i = idx + 1; i <= min(n - 1, idx + k); i++)

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

    return dp[idx] = res;

}



int main()

{

    fastio

    memset(dp, -1, sizeof dp);

    cin >> n >> k;

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

        cin >> arr[i];

    cout << solve(0);

    return 0;

}


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

using namespace std;

typedef long long ll;



const int N = 1e5 + 5;

int steps;

ll dp[N];

ll h[N];

int n;



int main() {

    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    cin >> n >> steps;

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

        cin >> h[i];

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

        ll start = max(0, i - steps), mn = 1e9;

        for (int j = start; j < i; j++)

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

        dp[i] = mn;

    }

    cout << dp[n - 1];

    return 0;

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

#include<algorithm>

#include<cmath>

#include<cstring>

using namespace std;

int n,k;

int h[100000];

int dp[100001];

int rec(int i){

  int res;

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

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

  else if(i==n-2) res=rec(i+1)+abs(h[i]-h[i+1]);

  else{

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

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

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

    }

  }

  return dp[i]=res;

}

int main(){

  cin >> n >> k;

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

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

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

  return 0;

}

  


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

#include<cstring>

#include<algorithm>

#include<cmath>

#define INF 2000000000

using namespace std;

int n,k;

int h[100000];

int dp[100001];

int main(){

  cin >> n >> k;

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

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

  dp[0]=0;

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

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

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

    }

  }

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



  return 0;

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

using namespace std;

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

#define ld long double

#define ll long long

#define pb push_back

#define pi acos(-1)

#define eps 1e-7

#define F first

#define S second

#define X real()

#define Y imag()

#define cross(a,b) (conj(a)*(b)).X

#define dot(a,b) (conj(a)*(b)).Y

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

#define allr(f) (f).rbegin(),(f).rend()

const int mod = 1e9+7 , A = 1e5 ;

typedef complex <ld> point ;

typedef vector <point> polygon ;

typedef tuple <int , int , int> line ;

//====================================

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

ll solve(ll ind)

{

	if (ind >= n)

		return 1e10 ;

	if (ind == n-1)

		return 0 ;

	if (ans[ind] != -1)

		return ans[ind] ;

	ll val = 1e10 ;

	for (int i = ind + 1 ; i <= min(ind + k , n-1) ; i++)

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

	ans[ind] = val ;

	return val ;

}

int main()

{

	_K

	cin >> n >> k ;

	memset(ans , -1 , sizeof ans) ;

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

	cout << solve(0) ;

	return 0 ;

}

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

using namespace std;

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

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

#define BiEdge(v,a,b) (v)[(a)].pb((b)),(v)[(b)].pb((a))

#define ll long long

#define ld long double

#define pb push_back

#define Pb pop_back

#define F first

#define S second

#define X real()

#define Y imag()

#define pi acos(-1)

#define eps 1e-7

#define bpc __builtin_popcount

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

#define allr(f) (f).rbegin(),(f).rend()

#define cross(a,b) (conj(a)*(b)).real()

#define dot(a,b) (conj(a)*(b)).imag()

typedef complex <ld> point ;

typedef vector <point> polygon ;

typedef tuple <ll,ll,ll> line ;

const int mod = 1e9+7 , A = 1e6+1 ;



int main()

{

	ios

	ll n , k ;

	cin >> n >> k ;

	ll dp[n] , a[n] ;

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

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

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

	{

		ll x ;

		dp[i] = 1e18 ;

		i - k < 0 ? x = 0 : x = i - k ;

		for (int j = i - 1 ; j >= x ; j--)

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

	}

	cout << dp[n-1] ;

	return 0 ;

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

#include <bits/stdc++.h>

using namespace std;



typedef vector<int> vi;

#define ll long long

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

#define loop1(i,n) for(int i=1; i<=n; i++)

#define loopi(i,s,e) for(int i=s; i < e; i++)

#define loopiRev(i,s,e) for(int i=s; i >= e; i--)

#define PI 3.14159265359

#define x first

#define y second

#define point pair<int,int>

#define len(s)   (int)s.length()

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

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

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



//you don't know math, unless you can do math!

int dp[100009];

vector<int> a;



int n,k;



int solve (int i){

    int &ret = dp[i];

    if(ret != -1) return ret;



    if(i == n - 1){

        return ret = 0;

    }



    int mn = INT_MAX;

    loop1(j, k) if(i+j < n) mn = min(mn, solve(i+j) + abs(a[i] - a[i+j]));



    return ret = mn;

}



int main() {

    //freopen("input.txt" , "r" , stdin) ;

    //freopen("output.txt" , "w" , stdout) ;



    cin.tie(0);

    cin.sync_with_stdio(0);



    clr(dp, -1);



    cin>>n>>k;

    a = vector<int> (n);

    loop(i, n) cin>>a[i];



    cout<<solve(0);

}




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

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

//cout<<fixed<<setprecision(6)<<n<<endl;

// transform(s.begin(), s.end(), s.begin(), ::tolower);

//double PI=3.14159265359,c=0;

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

#define endl '\n'

#define ll long long

//#define f(n) for(int i=;i<n;i++)

double PI = acos(-1);

using namespace std;

void fast()

{

    std::ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

}

ll arr[100000];

int main()

{

    fast();

    ll n,t,x,mn=0,k;

    cin>>n>>k;

    vector<ll>v(n,1e12);

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

        cin>>arr[i];



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

    {

        x=v[i];

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

        {

           if(i+j+1<n)

           {

                if(i==0)

                    x=0;

                mn=x+abs(arr[i]-arr[i+j+1]);

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



           }



        }

        //cout<<v[i]<<" ";

    }

    cout<<v[v.size()-1]<<endl;



    return 0;

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

#include <cstdio>

#include <cstring>

#include <algorithm>

#include <cmath>

#include <queue>

#include <stack>

#include <map>

#include <set>

#include <vector>

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

#define repd(i,x,n) for(int i=x;i<=n;i++)

#define pii pair<int,int>

#define pll pair<long long ,long long>

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

#define MS0(X) memset((X), 0, sizeof((X)))

#define MSC0(X) memset((X), '\0', sizeof((X)))

#define pb push_back

#define mp make_pair

#define fi first

#define se second

#define gg(x) getInt(&x)

using namespace std;

typedef long long ll;



const int maxn=1000010;

const int inf=0x3f3f3f3f;



ll n;

ll dp[maxn];

ll a[maxn];

ll k;

int main()

{

    gbtb;

    cin>>n>>k;

    repd(i,1,n)

    {

        cin>>a[i];

    }

    dp[1]=0;

    dp[0]=0;

    repd(i,2,n)

    {

        dp[i]=inf;

    }

    repd(i,2,n)

    {

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

        {

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

        }

    }

    cout<<dp[n];

    return 0;

}

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

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

using namespace std;

int wr;

int dp[1000001];

int a[1000001];

int it;



int fr(int p){

	if (p==it-1){

        return 0;

	}

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

        return dp[p];

	}

	int re=abs(a[p]-a[p+1])+fr(p+1);

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

		if(p+i<it){

      re=min(re,abs(a[p]-a[p+i])+fr(p+i));

    }

	}

	return dp[p]=re;

}

int main(){

	cin>>it>>wr;

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

      cin>>a[i];

    }

	memset(dp, -1, sizeof dp);

	cout<<fr(0)<<endl; //arreglar

	return 0;

}


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

#define int long long

#define ll long long

#define ld long double

#define mod ((ll)1e9+7)

#define maxx ((ll)1e6+5)

#define pb push_back

#define ins insert

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

#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define test ll t; cin>>t; while(t--)

ll exp(ll x,ll y,ll p){ ll res=1; while(y) {if(y%2) res=(res*x%p)%p; x=(x*x)%p; y/=2; } return res;}

ll expo(ll x,ll y){ ll res=1; while(y) {if(y%2) res=(res*x%mod)%mod; x=(x*x)%mod; y/=2; } return res;}

/*int sv[1000000]={0};

ll fact[1000007]={0};

void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%mod;}

void sve() {sv[0]=1;sv[1]=1;for(int i=2;i*i<=maxx;i++){if(!sv[i]){for(int j=2*i;j<=maxx;j+=i)sv[j]=1;}}}//0 hai to prime

ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(expo(fact[r],mod-2)))%mod; res=(res*(expo(fact[n-r],mod-2)))%mod; return res;}

ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(expo(fact[n-r],mod-2)))%mod; return res;}*/

int a[3][100003];

using namespace std;

signed main()

{

    int n,k,i,j;

    cin >> n >> k;

    int a[n],d[n] = {0};

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

    	cin >> a[i];

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

    {

    	int p = 1e17;

    	for(j=i-1 ; j>=i-k && j>=0 ; j--)

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

    	d[i] = p;

    }

    cout << d[n-1] <<"\n";

    return 0;

}
// Slower C++ solution:
// In the name of God



#include <bits/stdc++.h>



using namespace std;



const int N = 1e5+5;



int c[N];



int main() {

	ios_base::sync_with_stdio(false);

	cin.tie(0);



	int n;

	cin >> n;



	long long sum = 0;



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

		int x;

		cin >> x;

		c[x]++;

		sum += x;

	}



	int q;

	cin >> q;



	while(q--) {

		int a, b;

		cin >> a >> b;



		sum += 1ll * c[a] * (b - a);

		

		cout << sum << "\n";

		

		c[b] += c[a];

		c[a] = 0;

	}







	return 0;

}


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

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

using namespace std;

typedef long long int ll;

const int MAX=1e5+10;

int N,k,A[MAX],dp[MAX];

int solve(int idx)

{

    if(idx==N)return 0;

    if(idx>N)return 1e9;

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

    int res=1e9;

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

        res = min(res,solve(idx+i)+abs(A[idx+i]-A[idx]));

    }

    return dp[idx]=res;

}

int  main ()

{

    memset(dp,-1,sizeof dp);

    cin >> N >> k;

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

        cin >> A[i];

    }

    cout<<solve(1)<<endl;

    return 0;

}




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



using namespace std;

typedef long long int ll;

ll dp[100010];

ll arr[100010];



int main(){

    ll n,k;

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



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

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

    }



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

        dp[i] = 10000000000000;

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

            if(i-j >= 1){

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

            }

        }

    }





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

}