stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <bits/stdc++.h>

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

using namespace std;

using ll = long long;

using P = pair<ll, ll>;

const string ln = "\n";

constexpr int INF = 1001001001;

constexpr int MOD = 1000000007;



const int mod = 1000000007;

class mint {

  long long x;



 public:

  mint(long long x = 0) : x((x % mod + mod) % mod) {}

  mint operator-() const { return mint(-x); }

  mint& operator+=(const mint& a) {

    if ((x += a.x) >= mod) x -= mod;

    return *this;

  }

  mint& operator-=(const mint& a) {

    if ((x += mod - a.x) >= mod) x -= mod;

    return *this;

  }

  mint& operator*=(const mint& a) {

    (x *= a.x) %= mod;

    return *this;

  }

  mint operator+(const mint& a) const {

    mint res(*this);

    return res += a;

  }

  mint operator-(const mint& a) const {

    mint res(*this);

    return res -= a;

  }

  mint operator*(const mint& a) const {

    mint res(*this);

    return res *= a;

  }

  mint pow(ll t) const {

    if (!t) return 1;

    mint a = pow(t >> 1);

    a *= a;

    if (t & 1) a *= *this;

    return a;

  }

  // for prime mod

  mint inv() const { return pow(mod - 2); }

  mint& operator/=(const mint& a) { return (*this) *= a.inv(); }

  mint operator/(const mint& a) const {

    mint res(*this);

    return res /= a;

  }



  friend ostream& operator<<(ostream& os, const mint& m) {

    os << m.x;

    return os;

  }

};



struct combination {

  vector<mint> fact, ifact;

  combination(int n) : fact(n + 1), ifact(n + 1) {

    assert(n < mod);

    fact[0] = 1;

    for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;

    ifact[n] = fact[n].inv();

    for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;

  }

  mint operator()(int n, int k) {

    if (k < 0 || k > n) return 0;

    return fact[n] * ifact[k] * ifact[n - k];

  }

} comb(100005);



int main() {

  cin.tie(nullptr);

  ios::sync_with_stdio(false);



  int n;

  cin >> n;



  mint ans(1);



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

    ans *= mint(i);

  }



  cout << ans << ln;



  return 0;

}

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

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

using namespace std;

using ll = long long;

using P = pair<ll, ll>;

const string ln = "\n";

constexpr int INF = 1001001001;

constexpr int MOD = 1000000007;



int main() {

  cin.tie(nullptr);

  ios::sync_with_stdio(false);



  int n;

  cin >> n;



  ll ans = 1;



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

    ans *= i % MOD;

    ans %= MOD;

  }



  cout << ans << ln;



  return 0;

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



using namespace std;



int main()

{

    int n=0;

    int h=0;

    cin>>n>>h;

    int arr[n];

    int x=0;

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

    {

        cin>>arr[i];

    }

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

    {

        if(arr[i2]>=h)

        {

            x++;

        }

    }

    cout<<x;

    return 0;

}


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



int main ()

{

	long long int N,K,c=0,i,h[100000]; 

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

	

	

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

	{

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

		if(h[i]>=K)

		{

			c++;

		}

	}

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

	return 0;

	

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

using namespace std;



int N;

const int SIZE = 100005;

int h[SIZE];

int mem[SIZE];

int K;



int dp(int i) {



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



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



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



    int ret = INT_MAX;



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

      if (i + j < N)

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

    }

    return  mem[i] = ret;

}



int main() {



    cin >> N;

    cin >> K;



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

        cin >> h[i];

    }



    memset(mem, -1, sizeof mem);



    cout << dp(0);

}

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

using namespace std;

 

#define MOD (1000000007)

#define f first

#define s second

#define pb(x) push_back(x)

#define mp(x,y) make_pair(x,y)

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

#define print(vec,l,r) for(int i = l; i <= r; i++) cout << vec[i] <<" "; cout << endl;

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

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

#define input(vec,N) for(int i = 0; i < (N); i++) cin >> vec[i];

typedef long long int ll;

#define ld long double

const int N = 2e5+30;

//https://codeforces.com/problemset/page/2?tags=1700-1700

 

 

void solve(){

   int n,k;

   cin>>n>>k;

   int a[n+3];

   int dp[n+3];

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

     dp[i] = 1e9;

   }

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

     cin>>a[i];

   }

   dp[1]  = 0;

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

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

      if(i-j>=1){

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

      }

     }

   }

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

}

 

 

int main(){

 	ios_base::sync_with_stdio(false);

  cin.tie(NULL);

	int T;

  //cin >> T;

  //cout<<prs.size()<<'\n';

	 T = 1;

  //visited[1]=1;

	while(T--){

		solve();

	}

}
// Slower C++ solution:
//AtCoder

#include <bits/stdc++.h>



using namespace std;

int dp[100000],n,arr[100000],k;

int bt(int i)

{

    if(dp[i]!=-1)

        return dp[i];

    if(i>=n)

        return 99999999;

    if(i==n-1)

        return 0;

    int &ret=dp[i];

    ret=bt(i+1)+abs(arr[i]-arr[i+1]);

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

    {

        ret=min(bt(i+s)+abs(arr[i]-arr[i+s]),ret);

    }

    return ret;

}

int main()

{

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

    cin>>n>>k;

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

    {

        cin>>arr[i];

    }

    cout<<bt(0);

}


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

using namespace std;

int n,k,dp[100009],a[100009],mx=1e9+8;

int main()

{

    cin>>n>>k;

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

    for(int i=0;i<n;i++)dp[i]=mx;

    dp[0]=0;

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

    {

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

        {

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

        }

    }

    cout<<dp[n-1];

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

#define ll long long

#define pb push_back

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

#define mp make_pair

#define ff first

#define ss second

#define MAXN  1000005

#define endl "\n"

using namespace std;

vector<ll>v;

ll dp[100003];

ll a,n,k;

ll rec(int i){

    if(i==n-1)

        return 0;

    if(dp[i]!=-1)

        return dp[i];

    ll ans=LLONG_MAX;

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

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

    }

    return dp[i]=ans;

}



int main(){

    ios::sync_with_stdio(false);

    cin.tie(0);

    cin>>n>>k;

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

        cin>>a;

        v.pb(a);

    }

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

    ll ans=rec(0);

    cout<<ans<<endl;







    return 0;

}




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

#define ll long long

#define pb push_back

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

#define mp make_pair

#define ff first

#define ss second

#define MAXN  1000005

#define endl "\n"

using namespace std;



const int INF = 1e9 + 5;



int main(){

    ios::sync_with_stdio(false);

    cin.tie(0);

    int n, k, v[100005];

    vector<int>dp(100005, INF);

    cin>>n>>k;

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

        cin>>v[i];

    }

    dp[0]=0;



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

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

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

        }

    }

    cout<<dp[n-1];



    return 0;

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

using namespace std;

int main()

{

    string s;

    int k;

    cin>>k>>s;

    if (s.size()>k)

    {

        for (int i=0;i<k;i++)cout<<s[i];

        cout<<"...";

    }

    else

        cout<<s;

    return 0;

}


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

#include<string.h>

int main(){

	int k;

	char s[105];

	scanf("%d",&k);

	getchar();

	scanf("%s",&s);

	if(strlen(s)>k){

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

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

		}

		printf("...");

		printf("\n");

	}

	else{

		int l = strlen(s);

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

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

		printf("\n");

	}

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

#include<iostream>

#define ll long long

using namespace std;

ll a[100000 +10];

ll dp[100000 +10];

ll inf = 0x3f3f3f3f3f3f3f;

int main()

{

//	cout<<inf<<endl;

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

	ll i,j;

	for(i=1;i<=n;i++) scanf("%lld",&a[i]);

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

	dp[1] =0;

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

	{

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

		{

			if(j>0)

			{

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

			} 

			else break;

		}

	}

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

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.6597102834325583x):
#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 <bits/stdc++.h>

using namespace std;



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



int fn(int i) {

    if (i <= 0) return 0;

    if (i == 1) return abs(h[1] - h[0]);

    if (~dp[i]) return dp[i];

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

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

        if (i - t >= 0) 

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

    }

    return dp[i]; 

}



int main() {

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

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

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

    }

    memset(dp, -1, sizeof dp);

    printf("%d\n", fn(n - 1));

    return 0;

}

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

#define x first

#define y second

#define pii pair<int,int>

#define ll long long

#define pll pair<ll,ll>

#define mp make_pair

#define pb push_back

#define pf push_front

#define popb pop_back

#define popf pop_front

#define xmod 100000007

using namespace std;



int n,a[100005],m,dp[100005];

int main (){

	ios::sync_with_stdio(false);

	cin >> n >> m;

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

		cin >> a[i];

	}

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

		dp[i]=1e9;

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

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

		}

	}

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

    return 0;

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

#include<stdio.h>

#include<algorithm>

#include<bits/stdc++.h>

#include<cmath>

#include<cstring>

#include<cstdio>

#include<string.h>

#include<cmath>

#define maxn 1000010

#define ll long long

#define inf 0x3f3f3f3f

using namespace std;



ll h[maxn];

ll dp[maxn];

ll n,k;



int main()

{

    memset(h,0,sizeof h);

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



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

    {

        dp[i]=inf;

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

    }

    dp[1]=0;

    dp[0]=0;

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

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

    {

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

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

    }

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

    return 0;

}


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

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

using namespace std;

#include <cstdio>

#include <string>

#include <vector>

#include <queue>

#include <algorithm>

int main()

{

	

	int k ,x;

	cin>>k>>x;

	vector<int>res;

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

	{

		res.push_back(i);

	}

	

	bool tf = false;

	for(auto &x :res)

	{

		if(tf)

		cout<<" ";

		cout<<x;

		tf=true;

	}

	

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.269401143045399x):
////sfef

#include<stdio.h>

int main(){



int k,x,i,p,q,r;

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

p=(x-(k-1));

q=(x+(k-2));

r=(x+(k-1));

if(k==1)

{

    printf("%d",x);

}

else{

    for(i=p;i<=q;i++)    

    {

        printf("%d ",i);

    }

    printf("%d",r);

}



return 0;

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

#include <cstdio>

#include <algorithm>

#include <cstring>

typedef long long ll;

using namespace std;

const int N=1e5+10;

int a[N],b[N],c[N],n,tr[N<<1];

int lowbit(int x) {return x&-x;}

void change(int x)

{

    x+=N;

    while(x < (N<<1))

    {

        tr[x]++;

        x+=lowbit(x);

    }

}

int sum(int x)

{

    x+=N;

    int ans=0;

    while(x>=1)

    {

        ans+=tr[x];

        x-=lowbit(x);

    }

    return ans;

}

bool check(int now)

{

    for(int i=1;i<=n;i++) c[i]=c[i-1]+(a[i]<=now?1:-1);

    memset(tr,0,sizeof(tr));

    change(c[0]);

    ll tot=0;

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

    {

        tot+=sum(c[r]-1);

        change(c[r]);

    }

    return tot>=ll(n+1)*n/4+1;

}

int main()

{

    scanf("%d",&n);

    for(int i=1;i<=n;i++) scanf("%d",&a[i]);

    int l=1,r=1e9,ans=-1;

    while(l<=r)

    {

        int mid=(l+r)>>1;

        if (check(mid)) ans=mid,r=mid-1;

        else l=mid+1;

    }

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

}


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

#include<cstdio>

#include<math.h>

#include<algorithm>

#include<map>

#include<set>

#include<bitset>

#include<stack>

#include<queue>

#include<string>

#include<cstring>





using namespace std;

typedef long long LL;

const int maxn=2e6+7;

LL n;

LL tot=0;

LL mn=0x3f,mx=-0x3f;

LL a[maxn];

LL bit[maxn];



struct node {

LL val,pos;

}arr[maxn];



bool cmp(node n1,node n2)

{

    return n1.val==n2.val?n1.pos<n2.pos:n1.val<n2.val;

}



void update(LL x,LL val)

{

    for(; x< maxn ;x+=(x & -x))

    {

        bit[x]+=val;

    }

}



LL getsum(LL x)

{

    LL ans=0;

    for(;x>0;x-=(x & -x))

    {

        ans += bit[x];

    }

    return ans;

}







bool check(LL x){

    memset(bit,0,sizeof(bit));

     memset(arr,0,sizeof(arr));





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

    {

        if(a[i]<=x)arr[i].val=-1;

        else arr[i].val=1;

        arr[i].pos=i+1;

    }



    arr[0].val=0;

	arr[0].pos=1;



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

	arr[i].val+=arr[i-1].val;

	sort(arr,arr+n+1,cmp);



	LL ans=0;

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

    {

        ans+=(i-getsum(arr[i].pos));

        update(arr[i].pos,1);

    }

	return ans*2 > tot;

}





int main(){

   scanf("%lld",&n);



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

    {

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

   	 mn=min(mn,a[i]);

   	 mx=max(mx,a[i]);

   	 tot+=i;

   }



   LL l=mn,r=mx;

   while(r-l>1)

    {

   	  LL mid=(l+r)/2;

   	 if(check(mid)) r=mid;

   	 else l=mid;

   	 //printf("s%d",mid);

   }

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



   return 0;

}
// Slower C++ solution:
/******

author :- Mahmoud Tarek.

*******/



#include<bits/stdc++.h>



using namespace std ;



#define rg register

#define dbg(v) cerr << #v << " " << v ;

typedef long long ll ;



int n, k;

vector<int> a ;

int mx = 0 ;

int mem[100002] ;



int solve(int i){

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

int & ret = mem[i];

if(~ret) return ret ;

ret = mx ;

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

    if(i + j < n){

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

    }

}

return ret ;

}



int main() {

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

     cin >> n >> k ;

     a.resize(n) ;



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

        cin >> a[i] ;

        if(i >= 1){

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

        }

     }



     if(mx == 0) mx = a[0] ;





     memset(mem, -1, sizeof mem) ;



     cout << solve(0);

}



/*

  Empty set of troubles.

*/


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

using namespace std;

int n,k; vector<int>v;

long long dp[100005];



int main() {

	cin >> n>>k; 

	v.resize(n + 1);

	for (int i = 1; i <= n;i++)cin >> v[i];

	fill(dp, dp + n + 1, 1e18);

	dp[1] = 0;

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

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

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

		}

	}

	cout << dp[n];

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

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>



using namespace std;

using namespace __gnu_pbds;



template <typename T>

using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



typedef long long ll;

typedef pair<ll, ll> pll;

typedef pair<int, int> pii;

typedef complex<double> point;



#define X real()

#define Y imag()

#define angle(a) (atan2((a).imag(), (a).real()))

#define vec(a, b) ((b) - (a))

#define same(p1, p2) (dp(vec(p1, p2), vec(p1, p2)) < EPS)

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

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

#define length(a) (hypot((a).imag(), (a).real()))

#define normalize(a) (a) / length(a)

#define rotateO(p, ang) ((p)*exp(point(0, ang)))

#define rotateA(p, ang, about) (rotateO(vec(about, p), ang) + about)

#define reflectO(v, m) (conj((v) / (m)) * (m))

#define clr(a, b) memset(a, b, sizeof(a));



const ll N = 100005;

const int MOD = 1e9 + 7;

const double EPS = 1e-7;

const double PI = acos(-1.0);



ll n, k, h[N];

ll memo[N];



ll solve(int i)

{

	if(i == n - 1)

		return 0;



	ll& ret = memo[i];

	if(~ret)

		return ret;



	ret = solve(i + 1) + llabs(h[i] - h[i + 1]);

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

		ret = min(ret, solve(x) + llabs(h[i] - h[x]));



	return ret;

}



int main()

{

    ios::sync_with_stdio(false);

    cin.tie(NULL), cout.tie(NULL);

    cin >> n >> k;

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

    	cin >> h[i];

    clr(memo, -1);

    cout << solve(0) << endl;

}

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



using namespace std;



typedef long long ll;

typedef pair<ll, ll> pll;

typedef pair<int, int> pii;



const ll N = 100005;

const ll INF = 1e9;

const int MOD = 1e9 + 7;

const double EPS = 1e-7;

const double PI = acos(-1.0);



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



int main() {

	ios::sync_with_stdio(false);

	cin.tie(NULL), cout.tie(NULL);

	cin >> n >> k;

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

		cin >> h[i];

	

	fill(dp, dp + n, INF);



	dp[0] = 0;

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

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

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



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

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

using namespace std;



long long n,k,a=0,arr[100005];

int main(){

	cin >>  n >> k;

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

		cin >> arr[i];

		if (arr[i]>=k){

			a++;

		}

	}

	cout << a << endl;

	

}

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

int main(){

	int i,m,k,t=0,cnt=0;

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

	int a[m];

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

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

	}

		for(i=0;i<m-1;i++){

		if(a[i]>a[i+1]){

			t=a[i+1];

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

			a[i]=t;

		}

	}

	if(a[m-1]<k){

		printf("0");

	}else{

	

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

		if(a[i]>=k)

		cnt++;

	}

	printf("%d",cnt);

}

	return 0;

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

#include <algorithm>

using namespace std;

typedef long long ll;

#define MAX_N 100000

const ll INF = 1LL << 60;

int N, K;

ll dp[MAX_N + 1];



int main() {

    cin >> N >> K;

    int h[N + 1];

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

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

    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 + j], dp[i] + abs(h[i + j] - h[i]));

        }

    }

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

}

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

using namespace std;

#define MAX_N 100100

const int INF = 1e9;

int n, k;

int h[MAX_N];

int dp[MAX_N];



int main() {

    cin >> n >> k; 

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

    fill(dp, dp + MAX_N, INF);

    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] - h[i + j]));

            }

        }

    }

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

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

#include<cstdio>

using namespace std;



typedef long long LL;

LL maxn = 1e9+7;

LL N,M;



int main()

{

    while(scanf("%lld",&N)!=EOF&&(N>=1&&N<=10e5))

    {

        M = 1;

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

        {

            M = (M%maxn)*(i%maxn)%maxn; //可以分别模除后再乘积

        }

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

    }

    return 0;

}

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

const long long MOD=1e9+7;

int n;

long long ans=1;

int main()

{

	scanf("%d",&n);

	for(int i=1;i<=n;i++) ans=(ans*i)%MOD;

	printf("%lld",ans);

}