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

using namespace std;



	

	/* constants */

	#define inf (int)1e+9

	#define VIS 1

	#define UNVIS 0

	#define null NULL

	#define MAX (int)1e+6

	#define MIN -(int)1e+6

	

// ------------------------------------------------------------------------



int n, k;

vector<int> v;

vector<int> memo((int)1e5+5,-1);



int minCost(int pos) {



	if (memo[pos]!=-1)

		return memo[pos];



	if (pos==(n-1))

		return 0;



	if (pos>n)

		return inf;



	int answer=inf;

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

		answer=min(answer,minCost(pos+i)+abs(v[pos]-v[pos+i]));

	}



	memo[pos]=answer;

	return answer;

}





int main()

{

	

	cin.tie(NULL);

	cout.tie(NULL);



	/*Start*/

	



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

	

	

	v.resize(n);



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

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





	cout<<minCost(0)<<endl; 

    

    return 0;

}


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

using namespace std;



int main(){

	

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

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

	

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

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

		

		dp[i] = (i != 0) * 1000000000;

		

		for(int j = i - 1; j >= 0 && j >= i - k; j--) dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));

	}

	

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

	return 0;

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

#define endl '\n'

#define ll long long

using namespace std;



const int MXN = 1e5 + 5;

int n, k;

int h[MXN];

int dp[MXN];



int Dp(int idx) {

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

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

    int ans = 1e9;

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

        ans = min(ans, Dp(i) + abs(h[idx] - h[i]));

    }

    return dp[idx] = ans;

}



int main() {

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

    cin >> n >> k;

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

        cin >> h[i];

    }

    memset(dp, -1, sizeof dp);

    cout << Dp(0) << endl;

    return 0;

}

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



using namespace std;



int solve(const int stones_height[], int memo[], const int &n, const int &k){

    int ans;

    if(memo[n] != -1) ans = memo[n];

    else if(n == 1) return 0;

    else{

        ans = abs(stones_height[n] - stones_height[n - 1]) + solve(stones_height, memo, n - 1, k);

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

            ans = min(ans, abs(stones_height[n] - stones_height[n - i]) + solve(stones_height, memo, n - i, k));

        }

    }

    return memo[n] = ans;

}



int main(){

    int n, k;

    while(scanf("%d %d", &n, &k) != EOF){

        int stones_height[n + 1], memo[n + 1];

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

            scanf("%d", &stones_height[i + 1]);

            memo[i + 1] = -1;

        }

        printf("%d\n", solve(stones_height, memo, n, k));

    }

    return 0;

}
// Slower C++ solution:
#define rep(i, n) for (int i = 0; i < (n); i++)

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

using P = pair<int, int>;

const int MOD = 1000000007;



int main() {

    int A, B, C;

    cin >> A >> B >> C;



    bool isYes = false;

    rep(i, 1000) { // O(10^8)

        rep(j, 1000) {

            if ((A * i) - (B * j) == C)

                isYes = true;

        }

    }



    string ans = isYes ? "YES" : "NO";

    cout << ans << endl;



    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.8406921950679962x):
#define rep(i, n) for (int i = 0; i < (n); i++)

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

using P = pair<int, int>;

const int MOD = 1000000007;



int main() {

    int A, B, C;

    cin >> A >> B >> C;



    bool isYes = false;

    rep(i, B) {

        if (((i + 1) * A) % B == C)

            isYes = true;

    }



    string ans = isYes ? "YES" : "NO";

    cout << ans << endl;



    return 0;

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

#include<cstring>

using namespace std;

char s[1000009];

int main(){

	int a;

	cin>>a>>s;

	if(strlen(s)>a)

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

	cout<<s[i];

	cout<<"...";

	}

	else cout<<s<<endl;

	

	

}

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

using namespace std;

using ll = long long;



#define int ll

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

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



const int N = 1e5 + 5;

int dp[N];



int32_t main()

{

    IOS;

    memset(dp,9999,sizeof(dp));

    int n,k;

    cin>>n>>k;

    int a[n+1];

    FOR(i,1,n+1) cin>>a[i];

    dp[1] = 0;

    FOR(i,2,n+1)

    {

        FOR(j,1,k+1)

        {

            if(i-j > 0)

            {

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

            }

        }

    }

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

    return 0;

}

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

using namespace std;



using ll = long long;



#define int ll



const int INF = 1e9 + 5;



int32_t main()

{

	int n,k;

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

	vector<int> h(n);

	for(int& x : h)

	{

		scanf("%lld", &x);

	}

	vector<int> dp(n,INF);

	dp[0] = 0;

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

	{

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

		{

			if(j < n)

			{

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

			}

		}

	}

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

	return 0;

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

using namespace std;

typedef long long ll;

typedef long long int lli;

typedef long double ld;

const int oo = 1e9;

const int mod = 1e9+9;

/*ll gcd(ll x, ll y){return (y ? gcd(y, x%y) : x); }

*ll lcm(ll x, ll y){return x*(y/gcd(x,y));}

*void exEuclid(int a, int b){

	if(b==0){x = 1; y=0; d=a; return ;}

	exEuclid(b, a%b);

	int x1=y;

	int y1=x-(a/b)*y;

	x=x1;

	y=y1;

} 

* */

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

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;

}


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

using namespace std;

#define ll long long

#define pb push_back

#define F first

#define S second

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

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

ll table1()

{

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

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

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

	return dp[n-1];

}

ll table2()

{

	dp[0] = 0;

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

	{

		dp[i] = 1e9;

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

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

	}

	return dp[n-1];

}

int main()

{

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

	cin >> n;

	cin >> k;

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

	//cout << table1();

	cout << table2();

	return 0;

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

#include<string>

using namespace std;

int main()

{

	string s,ans;

	int i,k;

	cin>>k;

	cin>>s;

	if(s.length()>k)

	{

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

		{

			ans=ans+s[i];

		}

		ans.append(3,'.');

	}

	else

	ans.assign(s);

	cout<<ans<<endl;

	return 0;

 } 

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

	# include <string.h>

	int main () {

		int a = 0;

		int c =0;

	char name [100];

		scanf ("%d",&a);

		scanf("%s%[^\n]",&name);

		c = strlen (name);

		if (c<=a) {

			printf ("%s",name);

		} else if (c>a) {

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

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

			}

			printf("...");

		}

		return 0;

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

using namespace std;



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



int main()

{

    cin>>n>>k;

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

        cin>>h[i];

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

        c[i] = abs(h[0] - h[i]);



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

    {

        long long m = 1e10;

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

        {

            if ((c[i-j] + abs(h[i] - h[i-j])) <= m)

                m = c[i-j] + abs(h[i] - h[i-j]);

            c[i] = m;

        }

    }

    cout<<c[n-1];

}


// Faster C++ solution for the same problem (measured speedup: 5.219183305689006x):
//才不露白

//还是青蛙跳还是动态规划

//唯一的是你不知道青蛙它从哪跳到了现在的石头上 如果你知道 那就好办了

//比如从k上面跳过来

//dp[i] = dp[k] + abs(h[i] - h[k])

//关键是你k不知道啊

//有想法就好 不用先急着自我否认

//枚举

//dp[1] = 0

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

//写个函数来算看起来不错

//dp[3] = min(从1跳过来,从2跳过来)

//dp[4] = min(从1跳,从2跳，从3跳)用循环 最后求min

//差不多2层吧 先写了试试看

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <math.h>

#include <queue>

#include <stack>

#include <vector>

#include <algorithm>



using namespace std;



const int MAXN = 1e5;

int n,k;

int h[MAXN + 5],dp[MAXN + 5];//



int CHANGE(int i,int k)//

{

	if(i <= k + 1)//一跳就到

	{//从一开始选

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

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

		{

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

			{

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

			}

		}

		return min;

	}

	else

	{

		int min = dp[i - k] + abs(h[i] - h[i - k]);

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

		{

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

			{

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

			}

		}

		return min;

	}

}



int main()

{

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

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

	{

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

	}

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

	{

		if(i == 1)

		{

			dp[i] = 0;

		}

		else if(i == 2)

		{

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

		}

		else

		{

			dp[i] = CHANGE(i,k);

		}

	}

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

	return 0;

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

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

#define repr(i,a,n) for(int i=a;i>=n;i--)

#define INF 999999999

#define INF_M 2147483647

#define pb(a) push_back(a)

using namespace std;

typedef pair<int, int> pii;

typedef long long int ll;



vector<int> erat(int n) {

    vector<int> primes(n);

    for (int i = 2; i < n; ++i) primes[i] = i;

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

        if (primes[i])

            for (int j = i*i; j < n; j+=i) primes[j] = 0;

    // ?´???°?????????vector???????´?????????´????????\?????????????????? (0 ??§??????????´??????¨??????)

    primes.erase(remove(primes.begin(), primes.end(), 0), primes.end());

    return primes;

}



int main() {

	vector<int> v = erat(50000);

	int n;

	while(cin >> n) {

		if(n == 0) break;

		int ans = 0;

		rep(i,0,v.size()) {

			if(v[i] > n / 2) break;

			else if((n-v[i]) != 0 && *lower_bound(v.begin(), v.end(), n-v[i]) == n-v[i]) ans++;

		}

		cout << ans << endl;

	}

}

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

int main()

{

	int n;

	char prime[50001];

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

		prime[i] = 1;

	prime[0] = 0; prime[1] = 0;

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

		if(!prime[i]) continue;

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

			prime[j] = 0;

	}

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

		int cnt = 0;

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

			if(prime[i] && prime[n - i])

				cnt++;

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

	}

	return 0;

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

#include<string.h>

#include<iostream>

using namespace std;

const int mod = 1e9 + 7;



int main()

{

	long long ans = 1, i;

	int n;

	scanf("%d", &n);

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

		ans = (ans % mod) * (i % mod) % mod;

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



}

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

int main ()

{

    int i,n;

    long long s;

    scanf("%d", &n);

    s = 1;

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

    {

        s *= i;

        s %= (int)1e9+7;

    }

    printf ("%d", s);

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

using namespace std;



using ll = long long;

#define pb push_back

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

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

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

#define pii pair<int, int>

#define pll pair<ll, ll>



const int maxn = 1e5 + 5;

ll dp[maxn];

int n, k, arr[maxn];

ll inf = 1e11;



ll call(int i){

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

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

	ll ret = inf;

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

		if(i+j <= n-1)ret = min(ret, abs(arr[i] - arr[i+j]) + call(i+j));

	}

	return dp[i] = ret;

}



int main(){

	//file

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

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

	memset(dp, -1, sizeof dp);

	cout<<call(0)<<endl;

}

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

using namespace std;



const int maxn = 1e5 + 5; 

int a[maxn];

long long dp[maxn];



int main(){

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

	int n, k;

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

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

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

	}

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

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

			}

		}

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

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

using namespace std;

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

#define scn(n) scanf("%d",&n)

#define lscn(n) scanf("%lld",&n)

typedef long long ll;

#define pri(n) printf("%d\n",n)

#define lpri(n) printf("%lld\n",n);

#define rep(i,st,ed) for(int i=st;i<ed;i++)

#define F first

#define S second 

#define pb(n) push_back(n)

const int N=1e5+6;

const ll M=1e9+7;

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

void  rec(ll i)

{

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

	if(dp[i]!=-1)

	{

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

		return ;

	}

	

	if(i>=n-1)

	{

		dp[i]=0;

		// printf("reached here2 %d %d\n",i,n-1);

		return ;

	}

	ll ans=1e18,pos=-1;

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

	{

		rec(j);

		ll val=abs(a[i]-a[j])+dp[j];

		if(val<ans)

		{

			ans=val;

			pos=j;

		}

	}

	// printf("for i= %d and n= %lld ans 1 = %lld ans2 = %lld\n",i,n,ans1,ans2);	

	// if(i==0)

	// 	printf("pos = %lld\n",pos);

	dp[i]=ans;

}

int main()

{

	lscn(n);lscn(k);

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

		lscn(a[i]);

	

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

	

	rec(0ll);

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

	// 	printf("%lld ",dp[i]);

	lpri(dp[0]);

}

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

using namespace std;

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

#define scn(n) scanf("%d",&n)

#define lscn(n) scanf("%lld",&n)

typedef long long ll;

#define pri(n) printf("%d\n",n)

#define lpri(n) printf("%lld\n",n);

#define rep(i,st,ed) for(int i=st;i<ed;i++)

#define var(n) int n; scn(n)

#define F first

#define S second 

#define pb push_back

const int N=1e6+5;

// const ll M = 998244353;

const ll M=1e9+7;

const ll inf=1e18;







int main()

{

	var(n);var(k);

	int a[n],dp[n];

	rep(i,0,n)

	{		

		scn(a[i]);

		dp[i]=M;

	}

	dp[0]=0;

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

	{

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

		{

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

		}

	}

	pri(dp[n-1]);

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



using namespace std;



#define endl "\n"

#define ll long long

#define ld long double

#define ull unsigned long long

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

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

#define forln(i, n) for (long long i = 0; i < (long long)(n); ++i)

#define forl1n(i, n) for (long long i = 1; i < (long long)(n); ++i)





const ll maxLONG = 9223372036854775807;

const int maxINT = 2147483647;

const ll mod = 1000000007;

const ld EPS = 1e-9;

const int N = 1e5 + 9;

const ll INF = LONG_LONG_MAX;



ll GetMod(ll n, ll z) { // func to get mod for positive num and negitive nums

    return (n % z + z) % z;

}



//          U   R  D  L

int dx[] = {-1, 0, 1, 0, -1, +1, +1, -1}; // dx for the 8 adjacent places in matrix

int dy[] = {0, 1, 0, -1, +1, +1, -1, -1};// dy for the 8 adjacent places in matrix

int n, k;

vector<int> v;

int dp[N] = {};



int check(int pos) {



    if (pos == v.size() - 1)return 0;

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

    int u = 1e9;

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

        if (pos + i < v.size())

            u = min(u, abs(v[pos] - v[pos + i]) + check(pos + i));

        else

            break;

    }



    dp[pos] = u;

    return dp[pos];

}



int main() {



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

    cin >> n;

    cin >> k;

    v.resize(n);

    forn(i, n)cin >> v[i];

    fill(dp, dp + N, -1);

    cout << check(0);

}

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

#include <algorithm>

#include <vector>

using namespace std;

 

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

int main(){

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

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

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

	}

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

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

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

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

		}

	}

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

	return 0;

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

#include <cstring>

#include <cstdio>

#include <cmath>

#include <algorithm>

using namespace std;

struct node{

    double x,y;

}ver[10010];

struct Edge{

    int u,v;

    double l;

}e[1000000];

int n,m;

int pre[10010];

int Find(int x){

    if(x == pre[x])

        return x;

    else return pre[x] = Find(pre[x]);

}

int Union(int x,int y){

    int fx = Find(x),fy = Find(y);

    if(fx == fy)

        return 0;

    else{

        pre[fy] = fx;

        return 1;

    }

}

bool cmp(Edge a,Edge b){

    return a.l > b.l;

}

int main(){

    int i,j;

    cin >> n >> m;

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

        pre[i] = i;

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

        cin >> ver[i].x >> ver[i].y;

    }

    double allsum = 0.0;

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

        int u,v;

        double len;

        cin >> u >> v;

        len = sqrt((ver[u].x-ver[v].x)*(ver[u].x-ver[v].x)+(ver[u].y-ver[v].y)*(ver[u].y-ver[v].y));

        e[i].u = u;

        e[i].v = v;

        e[i].l = len;

        allsum += len;

    }

    //cout << allsum << endl;

    sort(e,e+m,cmp);

    double sum = 0.0;

    int num = 0;

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

        if(Union(e[i].u,e[i].v)){

            sum += e[i].l;

            num++;

        }

        if(num == n-1)

            break;

    }

    //cout << sum << endl;

    printf("%.3f\n",allsum-sum);

    return 0;

}

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

#include <cstring>

#include <algorithm>

#include <cmath>



using namespace std;



int n, m, f[10010], x[10010], y[10010];

double ans = 0.0;



struct edge {

	int u, v;

	double w;

	bool operator < (const edge &b) const { return w < b.w; }

}e[1000010];



double getdis(int u, int v) {

	return sqrt((double)(x[u] - x[v]) * (x[u] - x[v]) + (double)(y[u] - y[v]) * (y[u] - y[v]));

}



int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }



int main() {

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

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

		f[i] = i;

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

	}

	int u, v;

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

		scanf("%d%d", &u, &v);

		e[i].u = u;

		e[i].v = v;

		e[i].w = getdis(u, v);

	}

	sort(e + 1, e + m + 1);

	for(int i = m; i >= 1; --i) {

		int fu = find(e[i].u);

		int fv = find(e[i].v);

		if(fu != fv) f[fu] = fv;

		else ans += e[i].w;

	}

	printf("%.3lf\n", ans);

	return 0;

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

using namespace std ;

#define ll long long

inline int D(){

    int t ;

    scanf( "%d" , &t ) ;

    return t ;

}

inline ll LLD(){

    ll t ;

    scanf( "%lld" , &t ) ;

    return t ;

}

//################################################################

ll n;

ll a[1000005];

ll mem[1000005];

int k;

int main() {

    n = LLD(),k=D();

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

    mem[0]=0;

    mem[1]=abs(a[1]-a[0]);

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

        ll mn=LONG_LONG_MAX;



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

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

        }

        mem[i]=mn;

    }

    printf("%lld",mem[n-1]);



}

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

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

using namespace std;

long long int n,k,minimum[100010];

vector<long long int>v;

long long int dp(long long index)

{

    //---------------------------------------------------

    /*long long int temp1,temp2=INT_MAX;

    if(index==n-1)

        return 0;

    if(minimum[index+1]==-1)

    {

        minimum[index+1]=dp(index+1);

    }

    temp1=abs(v[index]-v[index+1])+minimum[index+1];

    if(minimum[index+2]==-1 && index<n-2)

    {

        minimum[index+2]=dp(index+2);

    }

    if(index<n-2)

        temp2=abs(v[index]-v[index+2])+minimum[index+2];

    return min(temp1,temp2);*/

    //----------------------------------------------------

    long long int temp=INT_MAX,i,flag=0;

    if(minimum[index]!=-1)

        return  minimum[index];

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

    {

        flag=1;

        if(minimum[index+i]!=-1)

        {

            temp=min(temp,abs(v[index]-v[index+i])+minimum[index+i]);

            continue;

        }

        minimum[index+i]=dp(index+i);

        temp=min(temp,abs(v[index]-v[index+i])+minimum[index+i]);

    }

    if(!flag)

        temp=0;

    minimum[index]=temp;

    return minimum[index];

}

int main()

{

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

    long long int i,j,temp;

    cin>>n>>k;

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

    {

        cin>>temp;

        v.push_back(temp);

    }

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

    cout<<dp(0);

}


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

using namespace std;



int main()

{

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

    long long int n,k;

    cin>>n>>k;

    long long int i,j,a[n],dp[n];

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

        cin>>a[i];

    dp[0]=0;

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

    {

        dp[i]=INT_MAX;

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

        {

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

        }

    }

    cout<<dp[n-1];

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

using namespace std;

typedef long long ll;

// Welcome to my source code!



static const int MAX = 1000010;



int main() {

    int s;

    cin >> s;

    int a[MAX] = {}; a[0] = s;

    bool flag = false;

    int ans;

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

        if (s % 2 == 0) s /= 2;

        else s = 3 * s + 1;

        a[i] = s;

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

            if (a[j] == a[i]) {

                ans = i + 1;

                flag = true;

                break;

            }

        }

        if (flag) break;

    }

    cout << ans << endl;

}

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

using namespace std;

typedef long long ll;

// Welcome to my source code!



int main() {

    int s;

    cin >> s;

    int ans = 1;

    while (s > 4 || s == 3) {

        s = (s % 2 == 0 ? s / 2 : s * 3 + 1 );

        ans++;

    }

    cout << ans + 3 << endl;

}